Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003-2008 Takahiro Hirofuchi |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 3 | * Copyright (C) 2015 Nobuo Iwata |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 4 | * |
| 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. |
| 9 | * |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 10 | */ |
| 11 | |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 12 | #ifndef __USBIP_VHCI_H |
| 13 | #define __USBIP_VHCI_H |
| 14 | |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 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> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 21 | #include <linux/usb/hcd.h> |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 22 | #include <linux/wait.h> |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 23 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 24 | struct vhci_device { |
| 25 | struct usb_device *udev; |
| 26 | |
| 27 | /* |
| 28 | * devid specifies a remote usb device uniquely instead |
| 29 | * of combination of busnum and devnum. |
| 30 | */ |
| 31 | __u32 devid; |
| 32 | |
| 33 | /* speed of a remote device */ |
| 34 | enum usb_device_speed speed; |
| 35 | |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 36 | /* vhci root-hub port to which this device is attached */ |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 37 | __u32 rhport; |
| 38 | |
| 39 | struct usbip_device ud; |
| 40 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 41 | /* lock for the below link lists */ |
| 42 | spinlock_t priv_lock; |
| 43 | |
| 44 | /* vhci_priv is linked to one of them. */ |
| 45 | struct list_head priv_tx; |
| 46 | struct list_head priv_rx; |
| 47 | |
| 48 | /* vhci_unlink is linked to one of them */ |
| 49 | struct list_head unlink_tx; |
| 50 | struct list_head unlink_rx; |
| 51 | |
| 52 | /* vhci_tx thread sleeps for this queue */ |
| 53 | wait_queue_head_t waitq_tx; |
| 54 | }; |
| 55 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 56 | /* urb->hcpriv, use container_of() */ |
| 57 | struct vhci_priv { |
| 58 | unsigned long seqnum; |
| 59 | struct list_head list; |
| 60 | |
| 61 | struct vhci_device *vdev; |
| 62 | struct urb *urb; |
| 63 | }; |
| 64 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 65 | struct vhci_unlink { |
| 66 | /* seqnum of this request */ |
| 67 | unsigned long seqnum; |
| 68 | |
| 69 | struct list_head list; |
| 70 | |
| 71 | /* seqnum of the unlink target */ |
| 72 | unsigned long unlink_seqnum; |
| 73 | }; |
| 74 | |
Bart Westgeest | 1132b9a | 2012-06-11 16:57:30 -0400 | [diff] [blame] | 75 | /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */ |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 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 |
| 81 | |
| 82 | #ifdef CONFIG_USBIP_VHCI_NR_HCS |
| 83 | #define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS |
| 84 | #else |
| 85 | #define VHCI_NR_HCS 1 |
| 86 | #endif |
| 87 | |
| 88 | #define MAX_STATUS_NAME 16 |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 89 | |
| 90 | /* for usb_bus.hcpriv */ |
| 91 | struct vhci_hcd { |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 92 | spinlock_t lock; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 93 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 94 | u32 port_status[VHCI_HC_PORTS]; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 95 | |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 96 | unsigned resuming:1; |
| 97 | unsigned long re_timeout; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 98 | |
| 99 | atomic_t seqnum; |
| 100 | |
| 101 | /* |
| 102 | * NOTE: |
| 103 | * wIndex shows the port number and begins from 1. |
| 104 | * But, the index of this array begins from 0. |
| 105 | */ |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 106 | struct vhci_device vdev[VHCI_HC_PORTS]; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 107 | }; |
| 108 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 109 | extern int vhci_num_controllers; |
| 110 | extern struct platform_device **vhci_pdevs; |
| 111 | extern struct attribute_group vhci_attr_group; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 112 | |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 113 | /* vhci_hcd.c */ |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 114 | void rh_port_connect(struct vhci_device *vdev, enum usb_device_speed speed); |
| 115 | |
| 116 | /* vhci_sysfs.c */ |
| 117 | int vhci_init_attr_group(void); |
| 118 | void vhci_finish_attr_group(void); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 119 | |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 120 | /* vhci_rx.c */ |
matt mooney | ddbc9bc | 2011-05-06 03:47:49 -0700 | [diff] [blame] | 121 | struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum); |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 122 | int vhci_rx_loop(void *data); |
Max Vozeler | b92a5e2 | 2011-01-12 15:02:01 +0200 | [diff] [blame] | 123 | |
matt mooney | fc184a3 | 2011-05-11 01:54:23 -0700 | [diff] [blame] | 124 | /* vhci_tx.c */ |
| 125 | int vhci_tx_loop(void *data); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 126 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 127 | static inline __u32 port_to_rhport(__u32 port) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 128 | { |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 129 | return port % VHCI_HC_PORTS; |
| 130 | } |
| 131 | |
| 132 | static inline int port_to_pdev_nr(__u32 port) |
| 133 | { |
| 134 | return port / VHCI_HC_PORTS; |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 135 | } |
| 136 | |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame^] | 137 | static inline struct vhci_hcd *hcd_to_vhci_hcd(struct usb_hcd *hcd) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 138 | { |
| 139 | return (struct vhci_hcd *) (hcd->hcd_priv); |
| 140 | } |
| 141 | |
Nobuo Iwata | 0775a9c | 2016-06-13 11:33:40 +0900 | [diff] [blame] | 142 | static inline struct device *hcd_dev(struct usb_hcd *hcd) |
| 143 | { |
| 144 | return (hcd)->self.controller; |
| 145 | } |
| 146 | |
| 147 | static inline const char *hcd_name(struct usb_hcd *hcd) |
| 148 | { |
| 149 | return (hcd)->self.bus_name; |
| 150 | } |
| 151 | |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame^] | 152 | static inline struct usb_hcd *vhci_hcd_to_hcd(struct vhci_hcd *vhci_hcd) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 153 | { |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame^] | 154 | return container_of((void *) vhci_hcd, struct usb_hcd, hcd_priv); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 155 | } |
| 156 | |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame^] | 157 | static inline struct vhci_hcd *vdev_to_vhci_hcd(struct vhci_device *vdev) |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 158 | { |
Yuyang Du | 5ec0edc | 2017-06-08 13:04:05 +0800 | [diff] [blame^] | 159 | return container_of((void *)(vdev - vdev->rhport), struct vhci_hcd, vdev); |
Takahiro Hirofuchi | 04679b3 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 160 | } |
Tobias Klauser | 306dac6 | 2011-08-22 08:53:28 +0200 | [diff] [blame] | 161 | |
| 162 | #endif /* __USBIP_VHCI_H */ |