2 * Copyright (C) 2003-2008 Takahiro Hirofuchi
3 * Copyright (C) 2015 Nobuo Iwata
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
12 #ifndef __USBIP_VHCI_H
13 #define __USBIP_VHCI_H
15 #include <linux/device.h>
16 #include <linux/list.h>
17 #include <linux/spinlock.h>
18 #include <linux/sysfs.h>
19 #include <linux/types.h>
20 #include <linux/usb.h>
21 #include <linux/usb/hcd.h>
22 #include <linux/wait.h>
25 struct usb_device *udev;
28 * devid specifies a remote usb device uniquely instead
29 * of combination of busnum and devnum.
33 /* speed of a remote device */
34 enum usb_device_speed speed;
36 /* vhci root-hub port to which this device is attached */
39 struct usbip_device ud;
41 /* lock for the below link lists */
44 /* vhci_priv is linked to one of them. */
45 struct list_head priv_tx;
46 struct list_head priv_rx;
48 /* vhci_unlink is linked to one of them */
49 struct list_head unlink_tx;
50 struct list_head unlink_rx;
52 /* vhci_tx thread sleeps for this queue */
53 wait_queue_head_t waitq_tx;
56 /* urb->hcpriv, use container_of() */
59 struct list_head list;
61 struct vhci_device *vdev;
66 /* seqnum of this request */
69 struct list_head list;
71 /* seqnum of the unlink target */
72 unsigned long unlink_seqnum;
80 /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
81 #ifdef CONFIG_USBIP_VHCI_HC_PORTS
82 #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
84 #define VHCI_HC_PORTS 8
87 /* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
88 #define VHCI_PORTS (VHCI_HC_PORTS*2)
90 #ifdef CONFIG_USBIP_VHCI_NR_HCS
91 #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
96 #define MAX_STATUS_NAME 16
101 struct platform_device *pdev;
103 struct vhci_hcd *vhci_hcd_hs;
104 struct vhci_hcd *vhci_hcd_ss;
107 /* for usb_hcd.hcd_priv[0] */
111 u32 port_status[VHCI_HC_PORTS];
114 unsigned long re_timeout;
120 * wIndex shows the port number and begins from 1.
121 * But, the index of this array begins from 0.
123 struct vhci_device vdev[VHCI_HC_PORTS];
126 extern int vhci_num_controllers;
127 extern struct vhci *vhcis;
128 extern struct attribute_group vhci_attr_group;
131 void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
134 int vhci_init_attr_group(void);
135 void vhci_finish_attr_group(void);
138 struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
139 int vhci_rx_loop(void *data);
142 int vhci_tx_loop(void *data);
144 static inline __u32 port_to_rhport(__u32 port)
146 return port % VHCI_HC_PORTS;
149 static inline int port_to_pdev_nr(__u32 port)
151 return port / VHCI_PORTS;
154 static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
156 return (struct vhci_hcd *) (hcd->hcd_priv);
159 static inline struct device *hcd_dev(struct usb_hcd *hcd)
161 return (hcd)->self.controller;
164 static inline const char *hcd_name(struct usb_hcd *hcd)
166 return (hcd)->self.bus_name;
169 static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
171 return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
174 static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
176 return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
179 #endif /* __USBIP_VHCI_H */