lkdtm: Add Control Flow Integrity test
[linux/fpc-iii.git] / drivers / usb / usbip / vhci.h
blob5659dce1526e8ce4e94c2520bc70d05972a243b5
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2003-2008 Takahiro Hirofuchi
4 * Copyright (C) 2015 Nobuo Iwata
5 */
7 #ifndef __USBIP_VHCI_H
8 #define __USBIP_VHCI_H
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>
19 struct vhci_device {
20 struct usb_device *udev;
23 * devid specifies a remote usb device uniquely instead
24 * of combination of busnum and devnum.
26 __u32 devid;
28 /* speed of a remote device */
29 enum usb_device_speed speed;
31 /* vhci root-hub port to which this device is attached */
32 __u32 rhport;
34 struct usbip_device ud;
36 /* lock for the below link lists */
37 spinlock_t priv_lock;
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() */
52 struct vhci_priv {
53 unsigned long seqnum;
54 struct list_head list;
56 struct vhci_device *vdev;
57 struct urb *urb;
60 struct vhci_unlink {
61 /* seqnum of this request */
62 unsigned long seqnum;
64 struct list_head list;
66 /* seqnum of the unlink target */
67 unsigned long unlink_seqnum;
70 enum hub_speed {
71 HUB_SPEED_HIGH = 0,
72 HUB_SPEED_SUPER,
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
78 #else
79 #define VHCI_HC_PORTS 8
80 #endif
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
87 #else
88 #define VHCI_NR_HCS 1
89 #endif
91 #define MAX_STATUS_NAME 16
93 struct vhci {
94 spinlock_t lock;
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] */
103 struct vhci_hcd {
104 struct vhci *vhci;
106 u32 port_status[VHCI_HC_PORTS];
108 unsigned resuming:1;
109 unsigned long re_timeout;
111 atomic_t seqnum;
114 * NOTE:
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;
125 /* vhci_hcd.c */
126 void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
128 /* vhci_sysfs.c */
129 int vhci_init_attr_group(void);
130 void vhci_finish_attr_group(void);
132 /* vhci_rx.c */
133 struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
134 int vhci_rx_loop(void *data);
136 /* vhci_tx.c */
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 */