Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2003-2008 Takahiro Hirofuchi |
Igor Kotrasinski | c7af4c2 | 2016-03-08 21:48:57 +0100 | [diff] [blame] | 3 | * Copyright (C) 2015-2016 Samsung Electronics |
| 4 | * Krzysztof Opasiak <k.opasiak@samsung.com> |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 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 | * This is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 19 | * USA. |
| 20 | */ |
| 21 | |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 22 | #ifndef __USBIP_COMMON_H |
| 23 | #define __USBIP_COMMON_H |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 24 | |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 25 | #include <linux/compiler.h> |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 26 | #include <linux/device.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/net.h> |
| 29 | #include <linux/printk.h> |
| 30 | #include <linux/spinlock.h> |
| 31 | #include <linux/types.h> |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 32 | #include <linux/usb.h> |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 33 | #include <linux/wait.h> |
Valentina Manea | 96c2737 | 2014-08-20 07:31:00 +0300 | [diff] [blame] | 34 | #include <uapi/linux/usbip.h> |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 35 | |
matt mooney | 6973c6f | 2011-05-11 01:54:14 -0700 | [diff] [blame] | 36 | #define USBIP_VERSION "1.0.0" |
| 37 | |
matt mooney | 1a4b6f6 | 2011-05-19 16:47:32 -0700 | [diff] [blame] | 38 | #undef pr_fmt |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 39 | |
matt mooney | 1a4b6f6 | 2011-05-19 16:47:32 -0700 | [diff] [blame] | 40 | #ifdef DEBUG |
| 41 | #define pr_fmt(fmt) KBUILD_MODNAME ": %s:%d: " fmt, __func__, __LINE__ |
matt mooney | 981f30c | 2011-05-11 01:54:13 -0700 | [diff] [blame] | 42 | #else |
matt mooney | 1a4b6f6 | 2011-05-19 16:47:32 -0700 | [diff] [blame] | 43 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 44 | #endif |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 45 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 46 | enum { |
| 47 | usbip_debug_xmit = (1 << 0), |
| 48 | usbip_debug_sysfs = (1 << 1), |
| 49 | usbip_debug_urb = (1 << 2), |
| 50 | usbip_debug_eh = (1 << 3), |
| 51 | |
| 52 | usbip_debug_stub_cmp = (1 << 8), |
| 53 | usbip_debug_stub_dev = (1 << 9), |
| 54 | usbip_debug_stub_rx = (1 << 10), |
| 55 | usbip_debug_stub_tx = (1 << 11), |
| 56 | |
| 57 | usbip_debug_vhci_rh = (1 << 8), |
| 58 | usbip_debug_vhci_hc = (1 << 9), |
| 59 | usbip_debug_vhci_rx = (1 << 10), |
| 60 | usbip_debug_vhci_tx = (1 << 11), |
| 61 | usbip_debug_vhci_sysfs = (1 << 12) |
| 62 | }; |
| 63 | |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 64 | #define usbip_dbg_flag_xmit (usbip_debug_flag & usbip_debug_xmit) |
| 65 | #define usbip_dbg_flag_vhci_rh (usbip_debug_flag & usbip_debug_vhci_rh) |
| 66 | #define usbip_dbg_flag_vhci_hc (usbip_debug_flag & usbip_debug_vhci_hc) |
| 67 | #define usbip_dbg_flag_vhci_rx (usbip_debug_flag & usbip_debug_vhci_rx) |
| 68 | #define usbip_dbg_flag_vhci_tx (usbip_debug_flag & usbip_debug_vhci_tx) |
| 69 | #define usbip_dbg_flag_stub_rx (usbip_debug_flag & usbip_debug_stub_rx) |
| 70 | #define usbip_dbg_flag_stub_tx (usbip_debug_flag & usbip_debug_stub_tx) |
matt mooney | 8735276 | 2011-05-19 21:36:56 -0700 | [diff] [blame] | 71 | #define usbip_dbg_flag_vhci_sysfs (usbip_debug_flag & usbip_debug_vhci_sysfs) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 72 | |
| 73 | extern unsigned long usbip_debug_flag; |
| 74 | extern struct device_attribute dev_attr_usbip_debug; |
| 75 | |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 76 | #define usbip_dbg_with_flag(flag, fmt, args...) \ |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 77 | do { \ |
| 78 | if (flag & usbip_debug_flag) \ |
matt mooney | 1a4b6f6 | 2011-05-19 16:47:32 -0700 | [diff] [blame] | 79 | pr_debug(fmt, ##args); \ |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 80 | } while (0) |
| 81 | |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 82 | #define usbip_dbg_sysfs(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 83 | usbip_dbg_with_flag(usbip_debug_sysfs, fmt , ##args) |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 84 | #define usbip_dbg_xmit(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 85 | usbip_dbg_with_flag(usbip_debug_xmit, fmt , ##args) |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 86 | #define usbip_dbg_urb(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 87 | usbip_dbg_with_flag(usbip_debug_urb, fmt , ##args) |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 88 | #define usbip_dbg_eh(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 89 | usbip_dbg_with_flag(usbip_debug_eh, fmt , ##args) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 90 | |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 91 | #define usbip_dbg_vhci_rh(fmt, args...) \ |
| 92 | usbip_dbg_with_flag(usbip_debug_vhci_rh, fmt , ##args) |
| 93 | #define usbip_dbg_vhci_hc(fmt, args...) \ |
| 94 | usbip_dbg_with_flag(usbip_debug_vhci_hc, fmt , ##args) |
| 95 | #define usbip_dbg_vhci_rx(fmt, args...) \ |
| 96 | usbip_dbg_with_flag(usbip_debug_vhci_rx, fmt , ##args) |
| 97 | #define usbip_dbg_vhci_tx(fmt, args...) \ |
| 98 | usbip_dbg_with_flag(usbip_debug_vhci_tx, fmt , ##args) |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 99 | #define usbip_dbg_vhci_sysfs(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 100 | usbip_dbg_with_flag(usbip_debug_vhci_sysfs, fmt , ##args) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 101 | |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 102 | #define usbip_dbg_stub_cmp(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 103 | usbip_dbg_with_flag(usbip_debug_stub_cmp, fmt , ##args) |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 104 | #define usbip_dbg_stub_rx(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 105 | usbip_dbg_with_flag(usbip_debug_stub_rx, fmt , ##args) |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 106 | #define usbip_dbg_stub_tx(fmt, args...) \ |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 107 | usbip_dbg_with_flag(usbip_debug_stub_tx, fmt , ##args) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 108 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 109 | /* |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 110 | * USB/IP request headers |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 111 | * |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 112 | * Each request is transferred across the network to its counterpart, which |
| 113 | * facilitates the normal USB communication. The values contained in the headers |
| 114 | * are basically the same as in a URB. Currently, four request types are |
| 115 | * defined: |
| 116 | * |
| 117 | * - USBIP_CMD_SUBMIT: a USB request block, corresponds to usb_submit_urb() |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 118 | * (client to server) |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 119 | * |
| 120 | * - USBIP_RET_SUBMIT: the result of USBIP_CMD_SUBMIT |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 121 | * (server to client) |
| 122 | * |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 123 | * - USBIP_CMD_UNLINK: an unlink request of a pending USBIP_CMD_SUBMIT, |
| 124 | * corresponds to usb_unlink_urb() |
| 125 | * (client to server) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 126 | * |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 127 | * - USBIP_RET_UNLINK: the result of USBIP_CMD_UNLINK |
| 128 | * (server to client) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 129 | * |
| 130 | */ |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 131 | #define USBIP_CMD_SUBMIT 0x0001 |
Alexander Thomas | 7518b9b | 2011-09-19 16:56:51 +0200 | [diff] [blame] | 132 | #define USBIP_CMD_UNLINK 0x0002 |
| 133 | #define USBIP_RET_SUBMIT 0x0003 |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 134 | #define USBIP_RET_UNLINK 0x0004 |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 135 | |
Alexander Thomas | 7518b9b | 2011-09-19 16:56:51 +0200 | [diff] [blame] | 136 | #define USBIP_DIR_OUT 0x00 |
| 137 | #define USBIP_DIR_IN 0x01 |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 138 | |
Malte Leip | 616ba12 | 2019-04-14 12:00:12 +0200 | [diff] [blame] | 139 | /* |
| 140 | * Arbitrary limit for the maximum number of isochronous packets in an URB, |
| 141 | * compare for example the uhci_submit_isochronous function in |
| 142 | * drivers/usb/host/uhci-q.c |
| 143 | */ |
| 144 | #define USBIP_MAX_ISO_PACKETS 1024 |
| 145 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 146 | /** |
| 147 | * struct usbip_header_basic - data pertinent to every request |
| 148 | * @command: the usbip request type |
| 149 | * @seqnum: sequential number that identifies requests; incremented per |
| 150 | * connection |
| 151 | * @devid: specifies a remote USB device uniquely instead of busnum and devnum; |
| 152 | * in the stub driver, this value is ((busnum << 16) | devnum) |
| 153 | * @direction: direction of the transfer |
| 154 | * @ep: endpoint number |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 155 | */ |
| 156 | struct usbip_header_basic { |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 157 | __u32 command; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 158 | __u32 seqnum; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 159 | __u32 devid; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 160 | __u32 direction; |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 161 | __u32 ep; |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 162 | } __packed; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 163 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 164 | /** |
| 165 | * struct usbip_header_cmd_submit - USBIP_CMD_SUBMIT packet header |
| 166 | * @transfer_flags: URB flags |
| 167 | * @transfer_buffer_length: the data size for (in) or (out) transfer |
| 168 | * @start_frame: initial frame for isochronous or interrupt transfers |
| 169 | * @number_of_packets: number of isochronous packets |
| 170 | * @interval: maximum time for the request on the server-side host controller |
| 171 | * @setup: setup data for a control request |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 172 | */ |
| 173 | struct usbip_header_cmd_submit { |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 174 | __u32 transfer_flags; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 175 | __s32 transfer_buffer_length; |
| 176 | |
| 177 | /* it is difficult for usbip to sync frames (reserved only?) */ |
| 178 | __s32 start_frame; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 179 | __s32 number_of_packets; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 180 | __s32 interval; |
| 181 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 182 | unsigned char setup[8]; |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 183 | } __packed; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 184 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 185 | /** |
| 186 | * struct usbip_header_ret_submit - USBIP_RET_SUBMIT packet header |
| 187 | * @status: return status of a non-iso request |
| 188 | * @actual_length: number of bytes transferred |
| 189 | * @start_frame: initial frame for isochronous or interrupt transfers |
| 190 | * @number_of_packets: number of isochronous packets |
| 191 | * @error_count: number of errors for isochronous transfers |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 192 | */ |
| 193 | struct usbip_header_ret_submit { |
| 194 | __s32 status; |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 195 | __s32 actual_length; |
| 196 | __s32 start_frame; |
| 197 | __s32 number_of_packets; |
| 198 | __s32 error_count; |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 199 | } __packed; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 200 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 201 | /** |
| 202 | * struct usbip_header_cmd_unlink - USBIP_CMD_UNLINK packet header |
| 203 | * @seqnum: the URB seqnum to unlink |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 204 | */ |
| 205 | struct usbip_header_cmd_unlink { |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 206 | __u32 seqnum; |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 207 | } __packed; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 208 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 209 | /** |
| 210 | * struct usbip_header_ret_unlink - USBIP_RET_UNLINK packet header |
| 211 | * @status: return status of the request |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 212 | */ |
| 213 | struct usbip_header_ret_unlink { |
| 214 | __s32 status; |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 215 | } __packed; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 216 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 217 | /** |
| 218 | * struct usbip_header - common header for all usbip packets |
| 219 | * @base: the basic header |
| 220 | * @u: packet type dependent header |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 221 | */ |
| 222 | struct usbip_header { |
| 223 | struct usbip_header_basic base; |
| 224 | |
| 225 | union { |
| 226 | struct usbip_header_cmd_submit cmd_submit; |
| 227 | struct usbip_header_ret_submit ret_submit; |
| 228 | struct usbip_header_cmd_unlink cmd_unlink; |
| 229 | struct usbip_header_ret_unlink ret_unlink; |
| 230 | } u; |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 231 | } __packed; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 232 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 233 | /* |
| 234 | * This is the same as usb_iso_packet_descriptor but packed for pdu. |
| 235 | */ |
| 236 | struct usbip_iso_packet_descriptor { |
| 237 | __u32 offset; |
| 238 | __u32 length; /* expected length */ |
| 239 | __u32 actual_length; |
| 240 | __u32 status; |
| 241 | } __packed; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 242 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 243 | enum usbip_side { |
| 244 | USBIP_VHCI, |
| 245 | USBIP_STUB, |
Igor Kotrasinski | c7af4c2 | 2016-03-08 21:48:57 +0100 | [diff] [blame] | 246 | USBIP_VUDC, |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 247 | }; |
| 248 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 249 | /* event handler */ |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 250 | #define USBIP_EH_SHUTDOWN (1 << 0) |
| 251 | #define USBIP_EH_BYE (1 << 1) |
| 252 | #define USBIP_EH_RESET (1 << 2) |
| 253 | #define USBIP_EH_UNUSABLE (1 << 3) |
| 254 | |
Alexander Popov | 134a926 | 2016-05-20 12:37:28 +0300 | [diff] [blame] | 255 | #define SDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_BYE) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 256 | #define SDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) |
| 257 | #define SDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) |
| 258 | #define SDEV_EVENT_ERROR_SUBMIT (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) |
| 259 | #define SDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) |
| 260 | |
Igor Kotrasinski | c7af4c2 | 2016-03-08 21:48:57 +0100 | [diff] [blame] | 261 | #define VUDC_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE) |
| 262 | #define VUDC_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) |
| 263 | #define VUDC_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) |
| 264 | /* catastrophic emulated usb error */ |
| 265 | #define VUDC_EVENT_ERROR_USB (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) |
| 266 | #define VUDC_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) |
| 267 | |
Shuah Khan | c0182ba | 2018-04-02 14:52:32 -0600 | [diff] [blame] | 268 | #define VDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE) |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 269 | #define VDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) |
| 270 | #define VDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET) |
| 271 | #define VDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE) |
| 272 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 273 | /* a common structure for stub_device and vhci_device */ |
| 274 | struct usbip_device { |
| 275 | enum usbip_side side; |
Shuah Khan | cd84ec9 | 2014-03-03 16:38:44 -0700 | [diff] [blame] | 276 | enum usbip_device_status status; |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 277 | |
| 278 | /* lock for status */ |
| 279 | spinlock_t lock; |
| 280 | |
Shuah Khan | ce601a0 | 2017-12-07 14:16:49 -0700 | [diff] [blame] | 281 | int sockfd; |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 282 | struct socket *tcp_socket; |
| 283 | |
| 284 | struct task_struct *tcp_rx; |
| 285 | struct task_struct *tcp_tx; |
| 286 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 287 | unsigned long event; |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 288 | wait_queue_head_t eh_waitq; |
| 289 | |
| 290 | struct eh_ops { |
| 291 | void (*shutdown)(struct usbip_device *); |
| 292 | void (*reset)(struct usbip_device *); |
| 293 | void (*unusable)(struct usbip_device *); |
| 294 | } eh_ops; |
| 295 | }; |
| 296 | |
Oleg Nesterov | ba46ce3 | 2012-03-13 19:07:18 +0100 | [diff] [blame] | 297 | #define kthread_get_run(threadfn, data, namefmt, ...) \ |
| 298 | ({ \ |
| 299 | struct task_struct *__k \ |
| 300 | = kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ |
| 301 | if (!IS_ERR(__k)) { \ |
| 302 | get_task_struct(__k); \ |
| 303 | wake_up_process(__k); \ |
| 304 | } \ |
| 305 | __k; \ |
| 306 | }) |
| 307 | |
| 308 | #define kthread_stop_put(k) \ |
| 309 | do { \ |
| 310 | kthread_stop(k); \ |
| 311 | put_task_struct(k); \ |
| 312 | } while (0) |
| 313 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 314 | /* usbip_common.c */ |
| 315 | void usbip_dump_urb(struct urb *purb); |
| 316 | void usbip_dump_header(struct usbip_header *pdu); |
| 317 | |
Bart Westgeest | 5a08c52 | 2011-12-19 17:44:11 -0500 | [diff] [blame] | 318 | int usbip_recv(struct socket *sock, void *buf, int size); |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 319 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 320 | void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, |
matt mooney | 4980d96 | 2011-05-06 03:47:45 -0700 | [diff] [blame] | 321 | int pack); |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 322 | void usbip_header_correct_endian(struct usbip_header *pdu, int send); |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 323 | |
Bart Westgeest | 36ac9b0 | 2012-10-10 13:34:25 -0400 | [diff] [blame] | 324 | struct usbip_iso_packet_descriptor* |
| 325 | usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen); |
| 326 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 327 | /* some members of urb must be substituted before. */ |
| 328 | int usbip_recv_iso(struct usbip_device *ud, struct urb *urb); |
Bart Westgeest | ac2b41a | 2012-01-23 10:55:46 -0500 | [diff] [blame] | 329 | void usbip_pad_iso(struct usbip_device *ud, struct urb *urb); |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 330 | int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb); |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 331 | |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 332 | /* usbip_event.c */ |
Nobuo Iwata | bb7871a | 2016-03-24 10:50:59 +0900 | [diff] [blame] | 333 | int usbip_init_eh(void); |
| 334 | void usbip_finish_eh(void); |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 335 | int usbip_start_eh(struct usbip_device *ud); |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 336 | void usbip_stop_eh(struct usbip_device *ud); |
| 337 | void usbip_event_add(struct usbip_device *ud, unsigned long event); |
Brian G. Merrell | b8868e4 | 2009-07-21 00:46:13 -0600 | [diff] [blame] | 338 | int usbip_event_happened(struct usbip_device *ud); |
Nobuo Iwata | bb7871a | 2016-03-24 10:50:59 +0900 | [diff] [blame] | 339 | int usbip_in_eh(struct task_struct *task); |
Takahiro Hirofuchi | 05a1f28 | 2008-07-09 14:56:51 -0600 | [diff] [blame] | 340 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 341 | static inline int interface_to_busnum(struct usb_interface *interface) |
| 342 | { |
| 343 | struct usb_device *udev = interface_to_usbdev(interface); |
Pawel Lebioda | 3eed8c0 | 2014-05-14 19:20:27 +0200 | [diff] [blame] | 344 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 345 | return udev->bus->busnum; |
| 346 | } |
| 347 | |
| 348 | static inline int interface_to_devnum(struct usb_interface *interface) |
| 349 | { |
| 350 | struct usb_device *udev = interface_to_usbdev(interface); |
Pawel Lebioda | 3eed8c0 | 2014-05-14 19:20:27 +0200 | [diff] [blame] | 351 | |
matt mooney | b7d27ea | 2011-05-19 21:37:02 -0700 | [diff] [blame] | 352 | return udev->devnum; |
| 353 | } |
| 354 | |
matt mooney | 7aaacb4 | 2011-05-11 22:33:43 -0700 | [diff] [blame] | 355 | #endif /* __USBIP_COMMON_H */ |