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