1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2003-2008 Takahiro Hirofuchi
4 * Copyright (C) 2015 Nobuo Iwata
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>
16 #include <linux/usb/hcd.h>
17 #include <linux/wait.h>
20 struct usb_device
*udev
;
23 * devid specifies a remote usb device uniquely instead
24 * of combination of busnum and devnum.
28 /* speed of a remote device */
29 enum usb_device_speed speed
;
31 /* vhci root-hub port to which this device is attached */
34 struct usbip_device ud
;
36 /* lock for the below link lists */
39 /* vhci_priv is linked to one of them. */
40 struct list_head priv_tx
;
41 struct list_head priv_rx
;
43 /* vhci_unlink is linked to one of them */
44 struct list_head unlink_tx
;
45 struct list_head unlink_rx
;
47 /* vhci_tx thread sleeps for this queue */
48 wait_queue_head_t waitq_tx
;
51 /* urb->hcpriv, use container_of() */
54 struct list_head list
;
56 struct vhci_device
*vdev
;
61 /* seqnum of this request */
64 struct list_head list
;
66 /* seqnum of the unlink target */
67 unsigned long unlink_seqnum
;
75 /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
76 #ifdef CONFIG_USBIP_VHCI_HC_PORTS
77 #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
79 #define VHCI_HC_PORTS 8
82 /* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
83 #define VHCI_PORTS (VHCI_HC_PORTS*2)
85 #ifdef CONFIG_USBIP_VHCI_NR_HCS
86 #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
91 #define MAX_STATUS_NAME 16
96 struct platform_device
*pdev
;
98 struct vhci_hcd
*vhci_hcd_hs
;
99 struct vhci_hcd
*vhci_hcd_ss
;
102 /* for usb_hcd.hcd_priv[0] */
106 u32 port_status
[VHCI_HC_PORTS
];
109 unsigned long re_timeout
;
115 * wIndex shows the port number and begins from 1.
116 * But, the index of this array begins from 0.
118 struct vhci_device vdev
[VHCI_HC_PORTS
];
121 extern int vhci_num_controllers
;
122 extern struct vhci
*vhcis
;
123 extern struct attribute_group vhci_attr_group
;
126 void rh_port_connect(struct vhci_device
*vdev
, enum usb_device_speed speed
);
129 int vhci_init_attr_group(void);
130 void vhci_finish_attr_group(void);
133 struct urb
*pickup_urb_and_free_priv(struct vhci_device
*vdev
, __u32 seqnum
);
134 int vhci_rx_loop(void *data
);
137 int vhci_tx_loop(void *data
);
139 static inline __u32
port_to_rhport(__u32 port
)
141 return port
% VHCI_HC_PORTS
;
144 static inline int port_to_pdev_nr(__u32 port
)
146 return port
/ VHCI_PORTS
;
149 static inline struct vhci_hcd
*hcd_to_vhci_hcd(struct usb_hcd
*hcd
)
151 return (struct vhci_hcd
*) (hcd
->hcd_priv
);
154 static inline struct device
*hcd_dev(struct usb_hcd
*hcd
)
156 return (hcd
)->self
.controller
;
159 static inline const char *hcd_name(struct usb_hcd
*hcd
)
161 return (hcd
)->self
.bus_name
;
164 static inline struct usb_hcd
*vhci_hcd_to_hcd(struct vhci_hcd
*vhci_hcd
)
166 return container_of((void *) vhci_hcd
, struct usb_hcd
, hcd_priv
);
169 static inline struct vhci_hcd
*vdev_to_vhci_hcd(struct vhci_device
*vdev
)
171 return container_of((void *)(vdev
- vdev
->rhport
), struct vhci_hcd
, vdev
);
174 #endif /* __USBIP_VHCI_H */