Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2003-2008 Takahiro Hirofuchi |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 4 | * Copyright (C) 2015 Nobuo Iwata |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 7 | #ifndef __USBIP_VHCI_H |
| 8 | #define __USBIP_VHCI_H |
| 9 | |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 10 | #include <linux/device.h> |
| 11 | #include <linux/list.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/sysfs.h> |
| 14 | #include <linux/types.h> |
| 15 | #include <linux/usb.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 16 | #include <linux/usb/hcd.h> |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 17 | #include <linux/wait.h> |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 18 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 19 | struct vhci_device { |
| 20 | struct usb_device *udev; |
| 21 | |
| 22 | /* |
| 23 | * devid specifies a remote usb device uniquely instead |
| 24 | * of combination of busnum and devnum. |
| 25 | */ |
| 26 | __u32 devid; |
| 27 | |
| 28 | /* speed of a remote device */ |
| 29 | enum usb_device_speed speed; |
| 30 | |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 31 | /* vhci root-hub port to which this device is attached */ |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 32 | __u32 rhport; |
| 33 | |
| 34 | struct usbip_device ud; |
| 35 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 36 | /* lock for the below link lists */ |
| 37 | spinlock_t priv_lock; |
| 38 | |
| 39 | /* vhci_priv is linked to one of them. */ |
| 40 | struct list_head priv_tx; |
| 41 | struct list_head priv_rx; |
| 42 | |
| 43 | /* vhci_unlink is linked to one of them */ |
| 44 | struct list_head unlink_tx; |
| 45 | struct list_head unlink_rx; |
| 46 | |
| 47 | /* vhci_tx thread sleeps for this queue */ |
| 48 | wait_queue_head_t waitq_tx; |
| 49 | }; |
| 50 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 51 | /* urb->hcpriv, use container_of() */ |
| 52 | struct vhci_priv { |
| 53 | unsigned long seqnum; |
| 54 | struct list_head list; |
| 55 | |
| 56 | struct vhci_device *vdev; |
| 57 | struct urb *urb; |
| 58 | }; |
| 59 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 60 | struct vhci_unlink { |
| 61 | /* seqnum of this request */ |
| 62 | unsigned long seqnum; |
| 63 | |
| 64 | struct list_head list; |
| 65 | |
| 66 | /* seqnum of the unlink target */ |
| 67 | unsigned long unlink_seqnum; |
| 68 | }; |
| 69 | |
Yuyang Du | 1c9de5b | 2017-06-08 13:04:10 +0800 | [diff] [blame] | 70 | enum hub_speed { |
| 71 | HUB_SPEED_HIGH = 0, |
| 72 | HUB_SPEED_SUPER, |
| 73 | }; |
| 74 | |
Bart Westgeest | 1132b9a | 2012-06-11 16:57:30 -0400 | [diff] [blame] | 75 | /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */ |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 76 | #ifdef CONFIG_USBIP_VHCI_HC_PORTS |
| 77 | #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS |
| 78 | #else |
| 79 | #define VHCI_HC_PORTS 8 |
| 80 | #endif |
| 81 | |
Yuyang Du | b891245 | 2017-06-08 13:04:13 +0800 | [diff] [blame] | 82 | /* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */ |
| 83 | #define VHCI_PORTS (VHCI_HC_PORTS*2) |
| 84 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 85 | #ifdef CONFIG_USBIP_VHCI_NR_HCS |
| 86 | #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS |
| 87 | #else |
| 88 | #define VHCI_NR_HCS 1 |
| 89 | #endif |
| 90 | |
| 91 | #define MAX_STATUS_NAME 16 |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 92 | |
Yuyang Du | 559e9c0 | 2017-06-08 13:04:06 +0800 | [diff] [blame] | 93 | struct vhci { |
| 94 | spinlock_t lock; |
| 95 | |
Yuyang Du | 89a73d2 | 2017-06-08 13:04:07 +0800 | [diff] [blame] | 96 | struct platform_device *pdev; |
| 97 | |
Yuyang Du | 559e9c0 | 2017-06-08 13:04:06 +0800 | [diff] [blame] | 98 | struct vhci_hcd *vhci_hcd_hs; |
| 99 | struct vhci_hcd *vhci_hcd_ss; |
| 100 | }; |
| 101 | |
| 102 | /* for usb_hcd.hcd_priv[0] */ |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 103 | struct vhci_hcd { |
Yuyang Du | 559e9c0 | 2017-06-08 13:04:06 +0800 | [diff] [blame] | 104 | struct vhci *vhci; |
| 105 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 106 | u32 port_status[VHCI_HC_PORTS]; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 107 | |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 108 | unsigned resuming:1; |
| 109 | unsigned long re_timeout; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 110 | |
| 111 | atomic_t seqnum; |
| 112 | |
| 113 | /* |
| 114 | * NOTE: |
| 115 | * wIndex shows the port number and begins from 1. |
| 116 | * But, the index of this array begins from 0. |
| 117 | */ |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 118 | struct vhci_device vdev[VHCI_HC_PORTS]; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 119 | }; |
| 120 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 121 | extern int vhci_num_controllers; |
Yuyang Du | 559e9c0 | 2017-06-08 13:04:06 +0800 | [diff] [blame] | 122 | extern struct vhci *vhcis; |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 123 | extern struct attribute_group vhci_attr_group; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 124 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 125 | /* vhci_hcd.c */ |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 126 | void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed); |
| 127 | |
| 128 | /* vhci_sysfs.c */ |
| 129 | int vhci_init_attr_group(void); |
| 130 | void vhci_finish_attr_group(void); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 131 | |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 132 | /* vhci_rx.c */ |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 133 | struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum); |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 134 | int vhci_rx_loop(void *data); |
Max Vozeler | b92a5e2 | 2011-01-12 15:02:01 +0200 | [diff] [blame] | 135 | |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 136 | /* vhci_tx.c */ |
| 137 | int vhci_tx_loop(void *data); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 138 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 139 | static inline __u32 port_to_rhport(__u32 port) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 140 | { |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 141 | return port % VHCI_HC_PORTS; |
| 142 | } |
| 143 | |
| 144 | static inline int port_to_pdev_nr(__u32 port) |
| 145 | { |
Yuyang Du | b891245 | 2017-06-08 13:04:13 +0800 | [diff] [blame] | 146 | return port / VHCI_PORTS; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 147 | } |
| 148 | |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame] | 149 | static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 150 | { |
| 151 | return (struct vhci_hcd *) (hcd->hcd_priv); |
| 152 | } |
| 153 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 154 | static inline struct device *hcd_dev(struct usb_hcd *hcd) |
| 155 | { |
| 156 | return (hcd)->self.controller; |
| 157 | } |
| 158 | |
| 159 | static inline const char *hcd_name(struct usb_hcd *hcd) |
| 160 | { |
| 161 | return (hcd)->self.bus_name; |
| 162 | } |
| 163 | |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame] | 164 | static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 165 | { |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame] | 166 | return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 167 | } |
| 168 | |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame] | 169 | static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 170 | { |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame] | 171 | return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 172 | } |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 173 | |
| 174 | #endif /* __USBIP_VHCI_H */ |