]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/usb/usbip/vhci.h
USB: add SPDX identifiers to all remaining files in drivers/usb/
[mirror_ubuntu-jammy-kernel.git] / drivers / usb / usbip / vhci.h
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2003-2008 Takahiro Hirofuchi
4 * Copyright (C) 2015 Nobuo Iwata
5 *
6 * This is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 */
12
13 #ifndef __USBIP_VHCI_H
14 #define __USBIP_VHCI_H
15
16 #include <linux/device.h>
17 #include <linux/list.h>
18 #include <linux/spinlock.h>
19 #include <linux/sysfs.h>
20 #include <linux/types.h>
21 #include <linux/usb.h>
22 #include <linux/usb/hcd.h>
23 #include <linux/wait.h>
24
25 struct vhci_device {
26 struct usb_device *udev;
27
28 /*
29 * devid specifies a remote usb device uniquely instead
30 * of combination of busnum and devnum.
31 */
32 __u32 devid;
33
34 /* speed of a remote device */
35 enum usb_device_speed speed;
36
37 /* vhci root-hub port to which this device is attached */
38 __u32 rhport;
39
40 struct usbip_device ud;
41
42 /* lock for the below link lists */
43 spinlock_t priv_lock;
44
45 /* vhci_priv is linked to one of them. */
46 struct list_head priv_tx;
47 struct list_head priv_rx;
48
49 /* vhci_unlink is linked to one of them */
50 struct list_head unlink_tx;
51 struct list_head unlink_rx;
52
53 /* vhci_tx thread sleeps for this queue */
54 wait_queue_head_t waitq_tx;
55 };
56
57 /* urb->hcpriv, use container_of() */
58 struct vhci_priv {
59 unsigned long seqnum;
60 struct list_head list;
61
62 struct vhci_device *vdev;
63 struct urb *urb;
64 };
65
66 struct vhci_unlink {
67 /* seqnum of this request */
68 unsigned long seqnum;
69
70 struct list_head list;
71
72 /* seqnum of the unlink target */
73 unsigned long unlink_seqnum;
74 };
75
76 enum hub_speed {
77 HUB_SPEED_HIGH = 0,
78 HUB_SPEED_SUPER,
79 };
80
81 /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
82 #ifdef CONFIG_USBIP_VHCI_HC_PORTS
83 #define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
84 #else
85 #define VHCI_HC_PORTS 8
86 #endif
87
88 /* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
89 #define VHCI_PORTS (VHCI_HC_PORTS*2)
90
91 #ifdef CONFIG_USBIP_VHCI_NR_HCS
92 #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
93 #else
94 #define VHCI_NR_HCS 1
95 #endif
96
97 #define MAX_STATUS_NAME 16
98
99 struct vhci {
100 spinlock_t lock;
101
102 struct platform_device *pdev;
103
104 struct vhci_hcd *vhci_hcd_hs;
105 struct vhci_hcd *vhci_hcd_ss;
106 };
107
108 /* for usb_hcd.hcd_priv[0] */
109 struct vhci_hcd {
110 struct vhci *vhci;
111
112 u32 port_status[VHCI_HC_PORTS];
113
114 unsigned resuming:1;
115 unsigned long re_timeout;
116
117 atomic_t seqnum;
118
119 /*
120 * NOTE:
121 * wIndex shows the port number and begins from 1.
122 * But, the index of this array begins from 0.
123 */
124 struct vhci_device vdev[VHCI_HC_PORTS];
125 };
126
127 extern int vhci_num_controllers;
128 extern struct vhci *vhcis;
129 extern struct attribute_group vhci_attr_group;
130
131 /* vhci_hcd.c */
132 void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
133
134 /* vhci_sysfs.c */
135 int vhci_init_attr_group(void);
136 void vhci_finish_attr_group(void);
137
138 /* vhci_rx.c */
139 struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
140 int vhci_rx_loop(void *data);
141
142 /* vhci_tx.c */
143 int vhci_tx_loop(void *data);
144
145 static inline __u32 port_to_rhport(__u32 port)
146 {
147 return port % VHCI_HC_PORTS;
148 }
149
150 static inline int port_to_pdev_nr(__u32 port)
151 {
152 return port / VHCI_PORTS;
153 }
154
155 static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
156 {
157 return (struct vhci_hcd *) (hcd->hcd_priv);
158 }
159
160 static inline struct device *hcd_dev(struct usb_hcd *hcd)
161 {
162 return (hcd)->self.controller;
163 }
164
165 static inline const char *hcd_name(struct usb_hcd *hcd)
166 {
167 return (hcd)->self.bus_name;
168 }
169
170 static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
171 {
172 return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
173 }
174
175 static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
176 {
177 return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
178 }
179
180 #endif /* __USBIP_VHCI_H */