blob: 5659dce1526e8ce4e94c2520bc70d05972a243b5 [file] [log] [blame]
Greg Kroah-Hartman5fd54ac2017-11-03 11:28:30 +01001// SPDX-License-Identifier: GPL-2.0+
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -06002/*
3 * Copyright (C) 2003-2008 Takahiro Hirofuchi
Nobuo Iwata0775a9c2016-06-13 11:33:40 +09004 * Copyright (C) 2015 Nobuo Iwata
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -06005 */
6
Tobias Klauser306dac62011-08-22 08:53:28 +02007#ifndef __USBIP_VHCI_H
8#define __USBIP_VHCI_H
9
matt mooney7aaacb42011-05-11 22:33:43 -070010#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 Lescouet27729aa2010-04-24 23:21:52 +020016#include <linux/usb/hcd.h>
matt mooney7aaacb42011-05-11 22:33:43 -070017#include <linux/wait.h>
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -060018
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -060019struct 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 mooneyddbc9bc2011-05-06 03:47:49 -070031 /* vhci root-hub port to which this device is attached */
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -060032 __u32 rhport;
33
34 struct usbip_device ud;
35
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -060036 /* 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 Hirofuchi04679b32008-07-09 14:56:51 -060051/* urb->hcpriv, use container_of() */
52struct vhci_priv {
53 unsigned long seqnum;
54 struct list_head list;
55
56 struct vhci_device *vdev;
57 struct urb *urb;
58};
59
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -060060struct 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 Du1c9de5b2017-06-08 13:04:10 +080070enum hub_speed {
71 HUB_SPEED_HIGH = 0,
72 HUB_SPEED_SUPER,
73};
74
Bart Westgeest1132b9a2012-06-11 16:57:30 -040075/* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
Nobuo Iwata0775a9c2016-06-13 11:33:40 +090076#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 Dub8912452017-06-08 13:04:13 +080082/* Each VHCI has 2 hubs (USB2 and USB3), each has VHCI_HC_PORTS ports */
83#define VHCI_PORTS (VHCI_HC_PORTS*2)
84
Nobuo Iwata0775a9c2016-06-13 11:33:40 +090085#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 Hirofuchi04679b32008-07-09 14:56:51 -060092
Yuyang Du559e9c02017-06-08 13:04:06 +080093struct vhci {
94 spinlock_t lock;
95
Yuyang Du89a73d22017-06-08 13:04:07 +080096 struct platform_device *pdev;
97
Yuyang Du559e9c02017-06-08 13:04:06 +080098 struct vhci_hcd *vhci_hcd_hs;
99 struct vhci_hcd *vhci_hcd_ss;
100};
101
102/* for usb_hcd.hcd_priv[0] */
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600103struct vhci_hcd {
Yuyang Du559e9c02017-06-08 13:04:06 +0800104 struct vhci *vhci;
105
Nobuo Iwata0775a9c2016-06-13 11:33:40 +0900106 u32 port_status[VHCI_HC_PORTS];
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600107
matt mooneyddbc9bc2011-05-06 03:47:49 -0700108 unsigned resuming:1;
109 unsigned long re_timeout;
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600110
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 Iwata0775a9c2016-06-13 11:33:40 +0900118 struct vhci_device vdev[VHCI_HC_PORTS];
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600119};
120
Nobuo Iwata0775a9c2016-06-13 11:33:40 +0900121extern int vhci_num_controllers;
Yuyang Du559e9c02017-06-08 13:04:06 +0800122extern struct vhci *vhcis;
Nobuo Iwata0775a9c2016-06-13 11:33:40 +0900123extern struct attribute_group vhci_attr_group;
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600124
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600125/* vhci_hcd.c */
Nobuo Iwata0775a9c2016-06-13 11:33:40 +0900126void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed);
127
128/* vhci_sysfs.c */
129int vhci_init_attr_group(void);
130void vhci_finish_attr_group(void);
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600131
matt mooneyfc184a32011-05-11 01:54:23 -0700132/* vhci_rx.c */
matt mooneyddbc9bc2011-05-06 03:47:49 -0700133struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum);
matt mooneyfc184a32011-05-11 01:54:23 -0700134int vhci_rx_loop(void *data);
Max Vozelerb92a5e22011-01-12 15:02:01 +0200135
matt mooneyfc184a32011-05-11 01:54:23 -0700136/* vhci_tx.c */
137int vhci_tx_loop(void *data);
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600138
Nobuo Iwata0775a9c2016-06-13 11:33:40 +0900139static inline __u32 port_to_rhport(__u32 port)
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600140{
Nobuo Iwata0775a9c2016-06-13 11:33:40 +0900141 return port % VHCI_HC_PORTS;
142}
143
144static inline int port_to_pdev_nr(__u32 port)
145{
Yuyang Dub8912452017-06-08 13:04:13 +0800146 return port / VHCI_PORTS;
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600147}
148
Yuyang Du5ec0edc2017-06-08 13:04:05 +0800149static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd)
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600150{
151 return (struct vhci_hcd *) (hcd->hcd_priv);
152}
153
Nobuo Iwata0775a9c2016-06-13 11:33:40 +0900154static inline struct device *hcd_dev(struct usb_hcd *hcd)
155{
156 return (hcd)->self.controller;
157}
158
159static inline const char *hcd_name(struct usb_hcd *hcd)
160{
161 return (hcd)->self.bus_name;
162}
163
Yuyang Du5ec0edc2017-06-08 13:04:05 +0800164static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd)
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600165{
Yuyang Du5ec0edc2017-06-08 13:04:05 +0800166 return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv);
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600167}
168
Yuyang Du5ec0edc2017-06-08 13:04:05 +0800169static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev)
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600170{
Yuyang Du5ec0edc2017-06-08 13:04:05 +0800171 return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev);
Takahiro Hirofuchi04679b32008-07-09 14:56:51 -0600172}
Tobias Klauser306dac62011-08-22 08:53:28 +0200173
174#endif /* __USBIP_VHCI_H */