| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (C) 2003-2008 Takahiro Hirofuchi | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is free software; you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation; either version 2 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software | 
					
						
							|  |  |  |  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | 
					
						
							|  |  |  |  * USA. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 22:33:43 -07:00
										 |  |  | #ifndef __USBIP_COMMON_H
 | 
					
						
							|  |  |  | #define __USBIP_COMMON_H
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #include <linux/compiler.h>
 | 
					
						
							| 
									
										
										
										
											2011-05-11 22:33:43 -07:00
										 |  |  | #include <linux/device.h>
 | 
					
						
							|  |  |  | #include <linux/interrupt.h>
 | 
					
						
							|  |  |  | #include <linux/net.h>
 | 
					
						
							|  |  |  | #include <linux/printk.h>
 | 
					
						
							|  |  |  | #include <linux/spinlock.h>
 | 
					
						
							|  |  |  | #include <linux/types.h>
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | #include <linux/usb.h>
 | 
					
						
							| 
									
										
										
										
											2011-05-11 22:33:43 -07:00
										 |  |  | #include <linux/wait.h>
 | 
					
						
							| 
									
										
										
										
											2014-08-20 07:31:00 +03:00
										 |  |  | #include <uapi/linux/usbip.h>
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 01:54:14 -07:00
										 |  |  | #define USBIP_VERSION "1.0.0"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 16:47:32 -07:00
										 |  |  | #undef pr_fmt
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 16:47:32 -07:00
										 |  |  | #ifdef DEBUG
 | 
					
						
							|  |  |  | #define pr_fmt(fmt)     KBUILD_MODNAME ": %s:%d: " fmt, __func__, __LINE__
 | 
					
						
							| 
									
										
										
										
											2011-05-11 01:54:13 -07:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2011-05-19 16:47:32 -07:00
										 |  |  | #define pr_fmt(fmt)     KBUILD_MODNAME ": " fmt
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | enum { | 
					
						
							|  |  |  | 	usbip_debug_xmit	= (1 << 0), | 
					
						
							|  |  |  | 	usbip_debug_sysfs	= (1 << 1), | 
					
						
							|  |  |  | 	usbip_debug_urb		= (1 << 2), | 
					
						
							|  |  |  | 	usbip_debug_eh		= (1 << 3), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usbip_debug_stub_cmp	= (1 << 8), | 
					
						
							|  |  |  | 	usbip_debug_stub_dev	= (1 << 9), | 
					
						
							|  |  |  | 	usbip_debug_stub_rx	= (1 << 10), | 
					
						
							|  |  |  | 	usbip_debug_stub_tx	= (1 << 11), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	usbip_debug_vhci_rh	= (1 << 8), | 
					
						
							|  |  |  | 	usbip_debug_vhci_hc	= (1 << 9), | 
					
						
							|  |  |  | 	usbip_debug_vhci_rx	= (1 << 10), | 
					
						
							|  |  |  | 	usbip_debug_vhci_tx	= (1 << 11), | 
					
						
							|  |  |  | 	usbip_debug_vhci_sysfs  = (1 << 12) | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | #define usbip_dbg_flag_xmit	(usbip_debug_flag & usbip_debug_xmit)
 | 
					
						
							|  |  |  | #define usbip_dbg_flag_vhci_rh	(usbip_debug_flag & usbip_debug_vhci_rh)
 | 
					
						
							|  |  |  | #define usbip_dbg_flag_vhci_hc	(usbip_debug_flag & usbip_debug_vhci_hc)
 | 
					
						
							|  |  |  | #define usbip_dbg_flag_vhci_rx	(usbip_debug_flag & usbip_debug_vhci_rx)
 | 
					
						
							|  |  |  | #define usbip_dbg_flag_vhci_tx	(usbip_debug_flag & usbip_debug_vhci_tx)
 | 
					
						
							|  |  |  | #define usbip_dbg_flag_stub_rx	(usbip_debug_flag & usbip_debug_stub_rx)
 | 
					
						
							|  |  |  | #define usbip_dbg_flag_stub_tx	(usbip_debug_flag & usbip_debug_stub_tx)
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:36:56 -07:00
										 |  |  | #define usbip_dbg_flag_vhci_sysfs  (usbip_debug_flag & usbip_debug_vhci_sysfs)
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | extern unsigned long usbip_debug_flag; | 
					
						
							|  |  |  | extern struct device_attribute dev_attr_usbip_debug; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | #define usbip_dbg_with_flag(flag, fmt, args...)		\
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 	do {						\ | 
					
						
							|  |  |  | 		if (flag & usbip_debug_flag)		\ | 
					
						
							| 
									
										
										
										
											2011-05-19 16:47:32 -07:00
										 |  |  | 			pr_debug(fmt, ##args);		\ | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 	} while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_sysfs(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_sysfs, fmt , ##args) | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_xmit(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_xmit, fmt , ##args) | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_urb(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_urb, fmt , ##args) | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_eh(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_eh, fmt , ##args) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define usbip_dbg_vhci_rh(fmt, args...)	\
 | 
					
						
							|  |  |  | 	usbip_dbg_with_flag(usbip_debug_vhci_rh, fmt , ##args) | 
					
						
							|  |  |  | #define usbip_dbg_vhci_hc(fmt, args...)	\
 | 
					
						
							|  |  |  | 	usbip_dbg_with_flag(usbip_debug_vhci_hc, fmt , ##args) | 
					
						
							|  |  |  | #define usbip_dbg_vhci_rx(fmt, args...)	\
 | 
					
						
							|  |  |  | 	usbip_dbg_with_flag(usbip_debug_vhci_rx, fmt , ##args) | 
					
						
							|  |  |  | #define usbip_dbg_vhci_tx(fmt, args...)	\
 | 
					
						
							|  |  |  | 	usbip_dbg_with_flag(usbip_debug_vhci_tx, fmt , ##args) | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_vhci_sysfs(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_vhci_sysfs, fmt , ##args) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_stub_cmp(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_stub_cmp, fmt , ##args) | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_stub_rx(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_stub_rx, fmt , ##args) | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | #define usbip_dbg_stub_tx(fmt, args...) \
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | 	usbip_dbg_with_flag(usbip_debug_stub_tx, fmt , ##args) | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  |  * USB/IP request headers | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  |  * Each request is transferred across the network to its counterpart, which | 
					
						
							|  |  |  |  * facilitates the normal USB communication. The values contained in the headers | 
					
						
							|  |  |  |  * are basically the same as in a URB. Currently, four request types are | 
					
						
							|  |  |  |  * defined: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *  - USBIP_CMD_SUBMIT: a USB request block, corresponds to usb_submit_urb() | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  *    (client to server) | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  *  - USBIP_RET_SUBMIT: the result of USBIP_CMD_SUBMIT | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  *    (server to client) | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  |  *  - USBIP_CMD_UNLINK: an unlink request of a pending USBIP_CMD_SUBMIT, | 
					
						
							|  |  |  |  *    corresponds to usb_unlink_urb() | 
					
						
							|  |  |  |  *    (client to server) | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  |  *  - USBIP_RET_UNLINK: the result of USBIP_CMD_UNLINK | 
					
						
							|  |  |  |  *    (server to client) | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | #define USBIP_CMD_SUBMIT	0x0001
 | 
					
						
							| 
									
										
										
										
											2011-09-19 16:56:51 +02:00
										 |  |  | #define USBIP_CMD_UNLINK	0x0002
 | 
					
						
							|  |  |  | #define USBIP_RET_SUBMIT	0x0003
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | #define USBIP_RET_UNLINK	0x0004
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-19 16:56:51 +02:00
										 |  |  | #define USBIP_DIR_OUT	0x00
 | 
					
						
							|  |  |  | #define USBIP_DIR_IN	0x01
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * struct usbip_header_basic - data pertinent to every request | 
					
						
							|  |  |  |  * @command: the usbip request type | 
					
						
							|  |  |  |  * @seqnum: sequential number that identifies requests; incremented per | 
					
						
							|  |  |  |  *	    connection | 
					
						
							|  |  |  |  * @devid: specifies a remote USB device uniquely instead of busnum and devnum; | 
					
						
							|  |  |  |  *	   in the stub driver, this value is ((busnum << 16) | devnum) | 
					
						
							|  |  |  |  * @direction: direction of the transfer | 
					
						
							|  |  |  |  * @ep: endpoint number | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | struct usbip_header_basic { | 
					
						
							|  |  |  | 	__u32 command; | 
					
						
							|  |  |  | 	__u32 seqnum; | 
					
						
							|  |  |  | 	__u32 devid; | 
					
						
							|  |  |  | 	__u32 direction; | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 	__u32 ep; | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | } __packed; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * struct usbip_header_cmd_submit - USBIP_CMD_SUBMIT packet header | 
					
						
							|  |  |  |  * @transfer_flags: URB flags | 
					
						
							|  |  |  |  * @transfer_buffer_length: the data size for (in) or (out) transfer | 
					
						
							|  |  |  |  * @start_frame: initial frame for isochronous or interrupt transfers | 
					
						
							|  |  |  |  * @number_of_packets: number of isochronous packets | 
					
						
							|  |  |  |  * @interval: maximum time for the request on the server-side host controller | 
					
						
							|  |  |  |  * @setup: setup data for a control request | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | struct usbip_header_cmd_submit { | 
					
						
							|  |  |  | 	__u32 transfer_flags; | 
					
						
							|  |  |  | 	__s32 transfer_buffer_length; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* it is difficult for usbip to sync frames (reserved only?) */ | 
					
						
							|  |  |  | 	__s32 start_frame; | 
					
						
							|  |  |  | 	__s32 number_of_packets; | 
					
						
							|  |  |  | 	__s32 interval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	unsigned char setup[8]; | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | } __packed; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * struct usbip_header_ret_submit - USBIP_RET_SUBMIT packet header | 
					
						
							|  |  |  |  * @status: return status of a non-iso request | 
					
						
							|  |  |  |  * @actual_length: number of bytes transferred | 
					
						
							|  |  |  |  * @start_frame: initial frame for isochronous or interrupt transfers | 
					
						
							|  |  |  |  * @number_of_packets: number of isochronous packets | 
					
						
							|  |  |  |  * @error_count: number of errors for isochronous transfers | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | struct usbip_header_ret_submit { | 
					
						
							|  |  |  | 	__s32 status; | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 	__s32 actual_length; | 
					
						
							|  |  |  | 	__s32 start_frame; | 
					
						
							|  |  |  | 	__s32 number_of_packets; | 
					
						
							|  |  |  | 	__s32 error_count; | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | } __packed; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * struct usbip_header_cmd_unlink - USBIP_CMD_UNLINK packet header | 
					
						
							|  |  |  |  * @seqnum: the URB seqnum to unlink | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | struct usbip_header_cmd_unlink { | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 	__u32 seqnum; | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | } __packed; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * struct usbip_header_ret_unlink - USBIP_RET_UNLINK packet header | 
					
						
							|  |  |  |  * @status: return status of the request | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | struct usbip_header_ret_unlink { | 
					
						
							|  |  |  | 	__s32 status; | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | } __packed; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * struct usbip_header - common header for all usbip packets | 
					
						
							|  |  |  |  * @base: the basic header | 
					
						
							|  |  |  |  * @u: packet type dependent header | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | struct usbip_header { | 
					
						
							|  |  |  | 	struct usbip_header_basic base; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	union { | 
					
						
							|  |  |  | 		struct usbip_header_cmd_submit	cmd_submit; | 
					
						
							|  |  |  | 		struct usbip_header_ret_submit	ret_submit; | 
					
						
							|  |  |  | 		struct usbip_header_cmd_unlink	cmd_unlink; | 
					
						
							|  |  |  | 		struct usbip_header_ret_unlink	ret_unlink; | 
					
						
							|  |  |  | 	} u; | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | } __packed; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This is the same as usb_iso_packet_descriptor but packed for pdu. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | struct usbip_iso_packet_descriptor { | 
					
						
							|  |  |  | 	__u32 offset; | 
					
						
							|  |  |  | 	__u32 length;			/* expected length */ | 
					
						
							|  |  |  | 	__u32 actual_length; | 
					
						
							|  |  |  | 	__u32 status; | 
					
						
							|  |  |  | } __packed; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | enum usbip_side { | 
					
						
							|  |  |  | 	USBIP_VHCI, | 
					
						
							|  |  |  | 	USBIP_STUB, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /* event handler */ | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | #define USBIP_EH_SHUTDOWN	(1 << 0)
 | 
					
						
							|  |  |  | #define USBIP_EH_BYE		(1 << 1)
 | 
					
						
							|  |  |  | #define USBIP_EH_RESET		(1 << 2)
 | 
					
						
							|  |  |  | #define USBIP_EH_UNUSABLE	(1 << 3)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | #define SDEV_EVENT_REMOVED   (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE)
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | #define	SDEV_EVENT_DOWN		(USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
 | 
					
						
							|  |  |  | #define	SDEV_EVENT_ERROR_TCP	(USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
 | 
					
						
							|  |  |  | #define	SDEV_EVENT_ERROR_SUBMIT	(USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
 | 
					
						
							|  |  |  | #define	SDEV_EVENT_ERROR_MALLOC	(USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	VDEV_EVENT_REMOVED	(USBIP_EH_SHUTDOWN | USBIP_EH_BYE)
 | 
					
						
							|  |  |  | #define	VDEV_EVENT_DOWN		(USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
 | 
					
						
							|  |  |  | #define	VDEV_EVENT_ERROR_TCP	(USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
 | 
					
						
							|  |  |  | #define	VDEV_EVENT_ERROR_MALLOC	(USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /* a common structure for stub_device and vhci_device */ | 
					
						
							|  |  |  | struct usbip_device { | 
					
						
							|  |  |  | 	enum usbip_side side; | 
					
						
							| 
									
										
										
										
											2014-03-03 16:38:44 -07:00
										 |  |  | 	enum usbip_device_status status; | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* lock for status */ | 
					
						
							|  |  |  | 	spinlock_t lock; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct socket *tcp_socket; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct task_struct *tcp_rx; | 
					
						
							|  |  |  | 	struct task_struct *tcp_tx; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 	unsigned long event; | 
					
						
							| 
									
										
										
										
											2011-03-02 00:13:05 +01:00
										 |  |  | 	struct task_struct *eh; | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 	wait_queue_head_t eh_waitq; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct eh_ops { | 
					
						
							|  |  |  | 		void (*shutdown)(struct usbip_device *); | 
					
						
							|  |  |  | 		void (*reset)(struct usbip_device *); | 
					
						
							|  |  |  | 		void (*unusable)(struct usbip_device *); | 
					
						
							|  |  |  | 	} eh_ops; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-13 19:07:18 +01:00
										 |  |  | #define kthread_get_run(threadfn, data, namefmt, ...)			   \
 | 
					
						
							|  |  |  | ({									   \ | 
					
						
							|  |  |  | 	struct task_struct *__k						   \ | 
					
						
							|  |  |  | 		= kthread_create(threadfn, data, namefmt, ## __VA_ARGS__); \ | 
					
						
							|  |  |  | 	if (!IS_ERR(__k)) {						   \ | 
					
						
							|  |  |  | 		get_task_struct(__k);					   \ | 
					
						
							|  |  |  | 		wake_up_process(__k);					   \ | 
					
						
							|  |  |  | 	}								   \ | 
					
						
							|  |  |  | 	__k;								   \ | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define kthread_stop_put(k)		\
 | 
					
						
							|  |  |  | 	do {				\ | 
					
						
							|  |  |  | 		kthread_stop(k);	\ | 
					
						
							|  |  |  | 		put_task_struct(k);	\ | 
					
						
							|  |  |  | 	} while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | /* usbip_common.c */ | 
					
						
							|  |  |  | void usbip_dump_urb(struct urb *purb); | 
					
						
							|  |  |  | void usbip_dump_header(struct usbip_header *pdu); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-19 17:44:11 -05:00
										 |  |  | int usbip_recv(struct socket *sock, void *buf, int size); | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, | 
					
						
							| 
									
										
										
										
											2011-05-06 03:47:45 -07:00
										 |  |  | 		    int pack); | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | void usbip_header_correct_endian(struct usbip_header *pdu, int send); | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 13:34:25 -04:00
										 |  |  | struct usbip_iso_packet_descriptor* | 
					
						
							|  |  |  | usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | /* some members of urb must be substituted before. */ | 
					
						
							|  |  |  | int usbip_recv_iso(struct usbip_device *ud, struct urb *urb); | 
					
						
							| 
									
										
										
										
											2012-01-23 10:55:46 -05:00
										 |  |  | void usbip_pad_iso(struct usbip_device *ud, struct urb *urb); | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb); | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* usbip_event.c */ | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | int usbip_start_eh(struct usbip_device *ud); | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | void usbip_stop_eh(struct usbip_device *ud); | 
					
						
							|  |  |  | void usbip_event_add(struct usbip_device *ud, unsigned long event); | 
					
						
							| 
									
										
										
										
											2009-07-21 00:46:13 -06:00
										 |  |  | int usbip_event_happened(struct usbip_device *ud); | 
					
						
							| 
									
										
										
										
											2008-07-09 14:56:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | static inline int interface_to_busnum(struct usb_interface *interface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct usb_device *udev = interface_to_usbdev(interface); | 
					
						
							| 
									
										
										
										
											2014-05-14 19:20:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 	return udev->bus->busnum; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline int interface_to_devnum(struct usb_interface *interface) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct usb_device *udev = interface_to_usbdev(interface); | 
					
						
							| 
									
										
										
										
											2014-05-14 19:20:27 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-19 21:37:02 -07:00
										 |  |  | 	return udev->devnum; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-11 22:33:43 -07:00
										 |  |  | #endif /* __USBIP_COMMON_H */
 |