1 From 05a1f28e879e3b4d6a9c08e30b1898943f77b6e7 Mon Sep 17 00:00:00 2001
2 From: Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>
3 Date: Wed, 9 Jul 2008 14:56:51 -0600
4 Subject: [PATCH 11/23] Staging: USB/IP: add common functions needed
7 This adds the common functions needed by both the host and client side
10 Brian Merrell cleaned up a lot of this code and submitted it for
11 inclusion. Greg also did a lot of cleanup.
13 Signed-off-by: Brian G. Merrell <bgmerrell@novell.com>
14 Cc: Takahiro Hirofuchi <hirofuchi@users.sourceforge.net>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
17 drivers/staging/Kconfig | 2 +
18 drivers/staging/Makefile | 1 +
19 drivers/staging/usbip/Kconfig | 14 +
20 drivers/staging/usbip/Makefile | 6 +
21 drivers/staging/usbip/README | 6 +
22 drivers/staging/usbip/usbip_common.c | 997 ++++++++++++++++++++++++++++++++++
23 drivers/staging/usbip/usbip_common.h | 406 ++++++++++++++
24 drivers/staging/usbip/usbip_event.c | 141 +++++
25 8 files changed, 1573 insertions(+), 0 deletions(-)
26 create mode 100644 drivers/staging/usbip/Kconfig
27 create mode 100644 drivers/staging/usbip/Makefile
28 create mode 100644 drivers/staging/usbip/README
29 create mode 100644 drivers/staging/usbip/usbip_common.c
30 create mode 100644 drivers/staging/usbip/usbip_common.h
31 create mode 100644 drivers/staging/usbip/usbip_event.c
33 diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
34 index f16bc9c..4dbf795 100644
35 --- a/drivers/staging/Kconfig
36 +++ b/drivers/staging/Kconfig
37 @@ -33,4 +33,6 @@ source "drivers/staging/me4000/Kconfig"
39 source "drivers/staging/go7007/Kconfig"
41 +source "drivers/staging/usbip/Kconfig"
44 diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
45 index aa61662..be42c0d 100644
46 --- a/drivers/staging/Makefile
47 +++ b/drivers/staging/Makefile
48 @@ -5,3 +5,4 @@ obj-$(CONFIG_SLICOSS) += slicoss/
49 obj-$(CONFIG_SXG) += sxg/
50 obj-$(CONFIG_ME4000) += me4000/
51 obj-$(CONFIG_VIDEO_GO7007) += go7007/
52 +obj-$(CONFIG_USB_IP_COMMON) += usbip/
53 diff --git a/drivers/staging/usbip/Kconfig b/drivers/staging/usbip/Kconfig
55 index 0000000..37efb5e
57 +++ b/drivers/staging/usbip/Kconfig
60 + tristate "USB IP support (EXPERIMENTAL)"
61 + depends on USB && EXPERIMENTAL
64 + This enables pushing USB packets over IP to allow remote
65 + machines access to USB devices directly. For more details,
66 + and links to the userspace utility programs to let this work
67 + properly, see http://usbip.naist.jp/
69 + To compile this driver as a module, choose M here: the
70 + module will be called usbip_common_mod.
73 diff --git a/drivers/staging/usbip/Makefile b/drivers/staging/usbip/Makefile
75 index 0000000..ce925ca
77 +++ b/drivers/staging/usbip/Makefile
79 +obj-$(CONFIG_USB_IP_COMMON) += usbip_common_mod.o
80 +usbip_common_mod-objs := usbip_common.o usbip_event.o
82 +ifeq ($(CONFIG_USB_DEBUG),y)
83 + EXTRA_CFLAGS += -DDEBUG
85 diff --git a/drivers/staging/usbip/README b/drivers/staging/usbip/README
87 index 0000000..c11be57
89 +++ b/drivers/staging/usbip/README
92 + - more discussion about the protocol
94 + - review of the userspace interface
96 +Please send patches for this code to Greg Kroah-Hartman <greg@kroah.com>
97 diff --git a/drivers/staging/usbip/usbip_common.c b/drivers/staging/usbip/usbip_common.c
99 index 0000000..e64918f
101 +++ b/drivers/staging/usbip/usbip_common.c
104 + * Copyright (C) 2003-2008 Takahiro Hirofuchi
106 + * This is free software; you can redistribute it and/or modify
107 + * it under the terms of the GNU General Public License as published by
108 + * the Free Software Foundation; either version 2 of the License, or
109 + * (at your option) any later version.
111 + * This is distributed in the hope that it will be useful,
112 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
113 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
114 + * GNU General Public License for more details.
116 + * You should have received a copy of the GNU General Public License
117 + * along with this program; if not, write to the Free Software
118 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
122 +#include <linux/kernel.h>
123 +#include <linux/file.h>
124 +#include <linux/tcp.h>
125 +#include <linux/in.h>
126 +#include "usbip_common.h"
128 +/* version information */
129 +#define DRIVER_VERSION "1.0"
130 +#define DRIVER_AUTHOR "Takahiro Hirofuchi <hirofuchi _at_ users.sourceforge.net>"
131 +#define DRIVER_DESC "usbip common driver"
133 +/*-------------------------------------------------------------------------*/
134 +/* debug routines */
136 +#ifdef CONFIG_USB_DEBUG
137 +unsigned long usbip_debug_flag = 0xffffffff;
139 +unsigned long usbip_debug_flag;
141 +EXPORT_SYMBOL_GPL(usbip_debug_flag);
145 +struct device_attribute dev_attr_usbip_debug;
146 +EXPORT_SYMBOL_GPL(dev_attr_usbip_debug);
149 +static ssize_t show_flag(struct device *dev, struct device_attribute *attr,
152 + return sprintf(buf, "%lx\n", usbip_debug_flag);
155 +static ssize_t store_flag(struct device *dev, struct device_attribute *attr,
156 + const char *buf, size_t count)
158 + unsigned long flag;
160 + sscanf(buf, "%lx", &flag);
161 + usbip_debug_flag = flag;
165 +DEVICE_ATTR(usbip_debug, (S_IRUGO | S_IWUSR), show_flag, store_flag);
167 +static void usbip_dump_buffer(char *buff, int bufflen)
171 + if (bufflen > 128) {
172 + for (i = 0; i < 128; i++) {
175 + printk("%02x ", (unsigned char) buff[i]);
181 + printk("... (%d byte)\n", bufflen);
185 + for (i = 0; i < bufflen; i++) {
188 + printk("%02x ", (unsigned char) buff[i]);
198 +static void usbip_dump_pipe(unsigned int p)
200 + unsigned char type = usb_pipetype(p);
201 + unsigned char ep = usb_pipeendpoint(p);
202 + unsigned char dev = usb_pipedevice(p);
203 + unsigned char dir = usb_pipein(p);
205 + printk("dev(%d) ", dev);
206 + printk("ep(%d) ", ep);
207 + printk("%s ", dir ? "IN" : "OUT");
210 + case PIPE_ISOCHRONOUS:
211 + printk("%s ", "ISO");
213 + case PIPE_INTERRUPT:
214 + printk("%s ", "INT");
217 + printk("%s ", "CTL");
220 + printk("%s ", "BLK");
230 +static void usbip_dump_usb_device(struct usb_device *udev)
232 + struct device *dev = &udev->dev;
235 + dev_dbg(dev, " devnum(%d) devpath(%s)",
236 + udev->devnum, udev->devpath);
238 + switch (udev->speed) {
239 + case USB_SPEED_HIGH:
240 + printk(" SPD_HIGH");
242 + case USB_SPEED_FULL:
243 + printk(" SPD_FULL");
245 + case USB_SPEED_LOW:
246 + printk(" SPD_LOW");
248 + case USB_SPEED_UNKNOWN:
249 + printk(" SPD_UNKNOWN");
252 + printk(" SPD_ERROR");
255 + printk(" tt %p, ttport %d", udev->tt, udev->ttport);
259 + for (i = 0; i < 16; i++)
263 + dev_dbg(dev, " toggle0(IN) :");
264 + for (i = 0; i < 16; i++)
265 + printk(" %2u", (udev->toggle[0] & (1 << i)) ? 1 : 0);
268 + dev_dbg(dev, " toggle1(OUT):");
269 + for (i = 0; i < 16; i++)
270 + printk(" %2u", (udev->toggle[1] & (1 << i)) ? 1 : 0);
274 + dev_dbg(dev, " epmaxp_in :");
275 + for (i = 0; i < 16; i++) {
276 + if (udev->ep_in[i])
278 + le16_to_cpu(udev->ep_in[i]->desc.wMaxPacketSize));
282 + dev_dbg(dev, " epmaxp_out :");
283 + for (i = 0; i < 16; i++) {
284 + if (udev->ep_out[i])
286 + le16_to_cpu(udev->ep_out[i]->desc.wMaxPacketSize));
290 + dev_dbg(dev, "parent %p, bus %p\n", udev->parent, udev->bus);
292 + dev_dbg(dev, "descriptor %p, config %p, actconfig %p, "
293 + "rawdescriptors %p\n", &udev->descriptor, udev->config,
294 + udev->actconfig, udev->rawdescriptors);
296 + dev_dbg(dev, "have_langid %d, string_langid %d\n",
297 + udev->have_langid, udev->string_langid);
299 + dev_dbg(dev, "maxchild %d, children %p\n",
300 + udev->maxchild, udev->children);
303 +static void usbip_dump_request_type(__u8 rt)
305 + switch (rt & USB_RECIP_MASK) {
306 + case USB_RECIP_DEVICE:
309 + case USB_RECIP_INTERFACE:
312 + case USB_RECIP_ENDPOINT:
315 + case USB_RECIP_OTHER:
323 +static void usbip_dump_usb_ctrlrequest(struct usb_ctrlrequest *cmd)
326 + printk(" %s : null pointer\n", __FUNCTION__);
331 + printk("bRequestType(%02X) ", cmd->bRequestType);
332 + printk("bRequest(%02X) " , cmd->bRequest);
333 + printk("wValue(%04X) ", cmd->wValue);
334 + printk("wIndex(%04X) ", cmd->wIndex);
335 + printk("wLength(%04X) ", cmd->wLength);
339 + if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) {
340 + printk("STANDARD ");
341 + switch (cmd->bRequest) {
342 + case USB_REQ_GET_STATUS:
343 + printk("GET_STATUS");
345 + case USB_REQ_CLEAR_FEATURE:
346 + printk("CLEAR_FEAT");
348 + case USB_REQ_SET_FEATURE:
349 + printk("SET_FEAT ");
351 + case USB_REQ_SET_ADDRESS:
352 + printk("SET_ADDRRS");
354 + case USB_REQ_GET_DESCRIPTOR:
355 + printk("GET_DESCRI");
357 + case USB_REQ_SET_DESCRIPTOR:
358 + printk("SET_DESCRI");
360 + case USB_REQ_GET_CONFIGURATION:
361 + printk("GET_CONFIG");
363 + case USB_REQ_SET_CONFIGURATION:
364 + printk("SET_CONFIG");
366 + case USB_REQ_GET_INTERFACE:
367 + printk("GET_INTERF");
369 + case USB_REQ_SET_INTERFACE:
370 + printk("SET_INTERF");
372 + case USB_REQ_SYNCH_FRAME:
373 + printk("SYNC_FRAME");
376 + printk("REQ(%02X) ", cmd->bRequest);
380 + usbip_dump_request_type(cmd->bRequestType);
382 + } else if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
385 + else if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_VENDOR)
388 + else if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_RESERVED)
389 + printk("RESERVED");
394 +void usbip_dump_urb(struct urb *urb)
396 + struct device *dev;
399 + printk(KERN_DEBUG KBUILD_MODNAME
400 + ":%s: urb: null pointer!!\n", __func__);
405 + printk(KERN_DEBUG KBUILD_MODNAME
406 + ":%s: urb->dev: null pointer!!\n", __func__);
409 + dev = &urb->dev->dev;
411 + dev_dbg(dev, " urb :%p\n", urb);
412 + dev_dbg(dev, " dev :%p\n", urb->dev);
414 + usbip_dump_usb_device(urb->dev);
416 + dev_dbg(dev, " pipe :%08x ", urb->pipe);
418 + usbip_dump_pipe(urb->pipe);
420 + dev_dbg(dev, " status :%d\n", urb->status);
421 + dev_dbg(dev, " transfer_flags :%08X\n", urb->transfer_flags);
422 + dev_dbg(dev, " transfer_buffer :%p\n", urb->transfer_buffer);
423 + dev_dbg(dev, " transfer_buffer_length:%d\n", urb->transfer_buffer_length);
424 + dev_dbg(dev, " actual_length :%d\n", urb->actual_length);
425 + dev_dbg(dev, " setup_packet :%p\n", urb->setup_packet);
427 + if (urb->setup_packet && usb_pipetype(urb->pipe) == PIPE_CONTROL)
428 + usbip_dump_usb_ctrlrequest(
429 + (struct usb_ctrlrequest *)urb->setup_packet);
431 + dev_dbg(dev, " start_frame :%d\n", urb->start_frame);
432 + dev_dbg(dev, " number_of_packets :%d\n", urb->number_of_packets);
433 + dev_dbg(dev, " interval :%d\n", urb->interval);
434 + dev_dbg(dev, " error_count :%d\n", urb->error_count);
435 + dev_dbg(dev, " context :%p\n", urb->context);
436 + dev_dbg(dev, " complete :%p\n", urb->complete);
438 +EXPORT_SYMBOL_GPL(usbip_dump_urb);
440 +void usbip_dump_header(struct usbip_header *pdu)
442 + udbg("BASE: cmd %u seq %u devid %u dir %u ep %u\n",
446 + pdu->base.direction,
449 + switch (pdu->base.command) {
450 + case USBIP_CMD_SUBMIT:
451 + udbg("CMD_SUBMIT: x_flags %u x_len %u sf %u #p %u iv %u\n",
452 + pdu->u.cmd_submit.transfer_flags,
453 + pdu->u.cmd_submit.transfer_buffer_length,
454 + pdu->u.cmd_submit.start_frame,
455 + pdu->u.cmd_submit.number_of_packets,
456 + pdu->u.cmd_submit.interval);
458 + case USBIP_CMD_UNLINK:
459 + udbg("CMD_UNLINK: seq %u\n", pdu->u.cmd_unlink.seqnum);
461 + case USBIP_RET_SUBMIT:
462 + udbg("RET_SUBMIT: st %d al %u sf %d ec %d\n",
463 + pdu->u.ret_submit.status,
464 + pdu->u.ret_submit.actual_length,
465 + pdu->u.ret_submit.start_frame,
466 + pdu->u.ret_submit.error_count);
467 + case USBIP_RET_UNLINK:
468 + udbg("RET_UNLINK: status %d\n", pdu->u.ret_unlink.status);
475 +EXPORT_SYMBOL_GPL(usbip_dump_header);
478 +/*-------------------------------------------------------------------------*/
479 +/* thread routines */
481 +int usbip_thread(void *param)
483 + struct usbip_task *ut = param;
489 + daemonize(ut->name);
490 + allow_signal(SIGKILL);
491 + ut->thread = current;
494 + /* srv.rb must wait for rx_thread starting */
495 + complete(&ut->thread_done);
497 + /* start of while loop */
503 + complete_and_exit(&ut->thread_done, 0);
506 +void usbip_start_threads(struct usbip_device *ud)
509 + * threads are invoked per one device (per one connection).
511 + kernel_thread(usbip_thread, (void *)&ud->tcp_rx, 0);
512 + kernel_thread(usbip_thread, (void *)&ud->tcp_tx, 0);
514 + /* confirm threads are starting */
515 + wait_for_completion(&ud->tcp_rx.thread_done);
516 + wait_for_completion(&ud->tcp_tx.thread_done);
518 +EXPORT_SYMBOL_GPL(usbip_start_threads);
520 +void usbip_stop_threads(struct usbip_device *ud)
522 + /* kill threads related to this sdev, if v.c. exists */
523 + if (ud->tcp_rx.thread != NULL) {
524 + send_sig(SIGKILL, ud->tcp_rx.thread, 1);
525 + wait_for_completion(&ud->tcp_rx.thread_done);
526 + udbg("rx_thread for ud %p has finished\n", ud);
529 + if (ud->tcp_tx.thread != NULL) {
530 + send_sig(SIGKILL, ud->tcp_tx.thread, 1);
531 + wait_for_completion(&ud->tcp_tx.thread_done);
532 + udbg("tx_thread for ud %p has finished\n", ud);
535 +EXPORT_SYMBOL_GPL(usbip_stop_threads);
537 +void usbip_task_init(struct usbip_task *ut, char *name,
538 + void (*loop_ops)(struct usbip_task *))
541 + init_completion(&ut->thread_done);
543 + ut->loop_ops = loop_ops;
545 +EXPORT_SYMBOL_GPL(usbip_task_init);
548 +/*-------------------------------------------------------------------------*/
549 +/* socket routines */
551 + /* Send/receive messages over TCP/IP. I refer drivers/block/nbd.c */
552 +int usbip_xmit(int send, struct socket *sock, char *buf,
553 + int size, int msg_flags)
560 + /* for blocks of if (dbg_flag_xmit) */
564 + dbg_xmit("enter\n");
566 + if (!sock || !buf || !size) {
567 + printk(KERN_ERR "%s: invalid arg, sock %p buff %p size %d\n",
568 + __func__, sock, buf, size);
573 + if (dbg_flag_xmit) {
575 + if (!in_interrupt())
576 + printk(KERN_DEBUG "%-10s:", current->comm);
578 + printk(KERN_DEBUG "interupt :");
580 + printk("%s: sending... , sock %p, buf %p, "
581 + "size %d, msg_flags %d\n", __func__,
582 + sock, buf, size, msg_flags);
583 + usbip_dump_buffer(buf, size);
589 + sock->sk->sk_allocation = GFP_NOIO;
590 + iov.iov_base = buf;
591 + iov.iov_len = size;
592 + msg.msg_name = NULL;
593 + msg.msg_namelen = 0;
594 + msg.msg_control = NULL;
595 + msg.msg_controllen = 0;
596 + msg.msg_namelen = 0;
597 + msg.msg_flags = msg_flags | MSG_NOSIGNAL;
600 + result = kernel_sendmsg(sock, &msg, &iov, 1, size);
602 + result = kernel_recvmsg(sock, &msg, &iov, 1, size,
606 + udbg("usbip_xmit: %s sock %p buf %p size %u ret %d"
608 + send ? "send" : "receive", sock, buf,
609 + size, result, total);
617 + } while (size > 0);
620 + if (dbg_flag_xmit) {
622 + if (!in_interrupt())
623 + printk(KERN_DEBUG "%-10s:", current->comm);
625 + printk(KERN_DEBUG "interupt :");
627 + printk("usbip_xmit: receiving....\n");
628 + usbip_dump_buffer(bp, osize);
629 + printk("usbip_xmit: received, osize %d ret %d size %d "
630 + "total %d\n", osize, result, size,
635 + printk("usbip_xmit: send, total %d\n", total);
643 +EXPORT_SYMBOL_GPL(usbip_xmit);
646 +/* now a usrland utility should set options. */
648 +int setquickack(struct socket *socket)
650 + mm_segment_t oldfs;
656 + ret = socket->ops->setsockopt(socket, SOL_TCP, TCP_QUICKACK,
657 + (char __user *) &val, sizeof(ret));
663 +int setnodelay(struct socket *socket)
665 + mm_segment_t oldfs;
671 + ret = socket->ops->setsockopt(socket, SOL_TCP, TCP_NODELAY,
672 + (char __user *) &val, sizeof(ret));
678 +int setkeepalive(struct socket *socket)
680 + mm_segment_t oldfs;
686 + ret = socket->ops->setsockopt(socket, SOL_SOCKET, SO_KEEPALIVE,
687 + (char __user *) &val, sizeof(ret));
693 +void setreuse(struct socket *socket)
695 + socket->sk->sk_reuse = 1;
699 +struct socket *sockfd_to_socket(unsigned int sockfd)
701 + struct socket *socket;
703 + struct inode *inode;
705 + file = fget(sockfd);
707 + printk(KERN_ERR "%s: invalid sockfd\n", __func__);
711 + inode = file->f_dentry->d_inode;
713 + if (!inode || !S_ISSOCK(inode->i_mode))
716 + socket = SOCKET_I(inode);
720 +EXPORT_SYMBOL_GPL(sockfd_to_socket);
724 +/*-------------------------------------------------------------------------*/
727 +/* there may be more cases to tweak the flags. */
728 +static unsigned int tweak_transfer_flags(unsigned int flags)
731 + if (flags & URB_NO_TRANSFER_DMA_MAP)
733 + * vhci_hcd does not provide DMA-mapped I/O. The upper
734 + * driver does not need to set this flag. The remote
735 + * usbip.ko does not still perform DMA-mapped I/O for
736 + * DMA-caplable host controllers. So, clear this flag.
738 + flags &= ~URB_NO_TRANSFER_DMA_MAP;
740 + if (flags & URB_NO_SETUP_DMA_MAP)
741 + flags &= ~URB_NO_SETUP_DMA_MAP;
746 +static void usbip_pack_cmd_submit(struct usbip_header *pdu, struct urb *urb,
749 + struct usbip_header_cmd_submit *spdu = &pdu->u.cmd_submit;
752 + * Some members are not still implemented in usbip. I hope this issue
753 + * will be discussed when usbip is ported to other operating systems.
757 + spdu->transfer_flags =
758 + tweak_transfer_flags(urb->transfer_flags);
759 + spdu->transfer_buffer_length = urb->transfer_buffer_length;
760 + spdu->start_frame = urb->start_frame;
761 + spdu->number_of_packets = urb->number_of_packets;
762 + spdu->interval = urb->interval;
765 + urb->transfer_flags = spdu->transfer_flags;
767 + urb->transfer_buffer_length = spdu->transfer_buffer_length;
768 + urb->start_frame = spdu->start_frame;
769 + urb->number_of_packets = spdu->number_of_packets;
770 + urb->interval = spdu->interval;
774 +static void usbip_pack_ret_submit(struct usbip_header *pdu, struct urb *urb,
777 + struct usbip_header_ret_submit *rpdu = &pdu->u.ret_submit;
782 + rpdu->status = urb->status;
783 + rpdu->actual_length = urb->actual_length;
784 + rpdu->start_frame = urb->start_frame;
785 + rpdu->error_count = urb->error_count;
789 + urb->status = rpdu->status;
790 + urb->actual_length = rpdu->actual_length;
791 + urb->start_frame = rpdu->start_frame;
792 + urb->error_count = rpdu->error_count;
797 +void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
801 + case USBIP_CMD_SUBMIT:
802 + usbip_pack_cmd_submit(pdu, urb, pack);
804 + case USBIP_RET_SUBMIT:
805 + usbip_pack_ret_submit(pdu, urb, pack);
808 + err("unknown command");
813 +EXPORT_SYMBOL_GPL(usbip_pack_pdu);
816 +static void correct_endian_basic(struct usbip_header_basic *base, int send)
819 + base->command = cpu_to_be32(base->command);
820 + base->seqnum = cpu_to_be32(base->seqnum);
821 + base->devid = cpu_to_be32(base->devid);
822 + base->direction = cpu_to_be32(base->direction);
823 + base->ep = cpu_to_be32(base->ep);
825 + base->command = be32_to_cpu(base->command);
826 + base->seqnum = be32_to_cpu(base->seqnum);
827 + base->devid = be32_to_cpu(base->devid);
828 + base->direction = be32_to_cpu(base->direction);
829 + base->ep = be32_to_cpu(base->ep);
833 +static void correct_endian_cmd_submit(struct usbip_header_cmd_submit *pdu,
837 + pdu->transfer_flags = cpu_to_be32(pdu->transfer_flags);
839 + cpu_to_be32s(&pdu->transfer_buffer_length);
840 + cpu_to_be32s(&pdu->start_frame);
841 + cpu_to_be32s(&pdu->number_of_packets);
842 + cpu_to_be32s(&pdu->interval);
844 + pdu->transfer_flags = be32_to_cpu(pdu->transfer_flags);
846 + be32_to_cpus(&pdu->transfer_buffer_length);
847 + be32_to_cpus(&pdu->start_frame);
848 + be32_to_cpus(&pdu->number_of_packets);
849 + be32_to_cpus(&pdu->interval);
853 +static void correct_endian_ret_submit(struct usbip_header_ret_submit *pdu,
857 + cpu_to_be32s(&pdu->status);
858 + cpu_to_be32s(&pdu->actual_length);
859 + cpu_to_be32s(&pdu->start_frame);
860 + cpu_to_be32s(&pdu->error_count);
862 + be32_to_cpus(&pdu->status);
863 + be32_to_cpus(&pdu->actual_length);
864 + be32_to_cpus(&pdu->start_frame);
865 + be32_to_cpus(&pdu->error_count);
869 +static void correct_endian_cmd_unlink(struct usbip_header_cmd_unlink *pdu,
873 + pdu->seqnum = cpu_to_be32(pdu->seqnum);
875 + pdu->seqnum = be32_to_cpu(pdu->seqnum);
878 +static void correct_endian_ret_unlink(struct usbip_header_ret_unlink *pdu,
882 + cpu_to_be32s(&pdu->status);
884 + be32_to_cpus(&pdu->status);
887 +void usbip_header_correct_endian(struct usbip_header *pdu, int send)
892 + cmd = pdu->base.command;
894 + correct_endian_basic(&pdu->base, send);
897 + cmd = pdu->base.command;
900 + case USBIP_CMD_SUBMIT:
901 + correct_endian_cmd_submit(&pdu->u.cmd_submit, send);
903 + case USBIP_RET_SUBMIT:
904 + correct_endian_ret_submit(&pdu->u.ret_submit, send);
906 + case USBIP_CMD_UNLINK:
907 + correct_endian_cmd_unlink(&pdu->u.cmd_unlink, send);
909 + case USBIP_RET_UNLINK:
910 + correct_endian_ret_unlink(&pdu->u.ret_unlink, send);
914 + err("unknown command in pdu header: %d", cmd);
918 +EXPORT_SYMBOL_GPL(usbip_header_correct_endian);
920 +static void usbip_iso_pakcet_correct_endian(
921 + struct usbip_iso_packet_descriptor *iso,
924 + /* does not need all members. but copy all simply. */
926 + iso->offset = cpu_to_be32(iso->offset);
927 + iso->length = cpu_to_be32(iso->length);
928 + iso->status = cpu_to_be32(iso->status);
929 + iso->actual_length = cpu_to_be32(iso->actual_length);
931 + iso->offset = be32_to_cpu(iso->offset);
932 + iso->length = be32_to_cpu(iso->length);
933 + iso->status = be32_to_cpu(iso->status);
934 + iso->actual_length = be32_to_cpu(iso->actual_length);
938 +static void usbip_pack_iso(struct usbip_iso_packet_descriptor *iso,
939 + struct usb_iso_packet_descriptor *uiso, int pack)
942 + iso->offset = uiso->offset;
943 + iso->length = uiso->length;
944 + iso->status = uiso->status;
945 + iso->actual_length = uiso->actual_length;
947 + uiso->offset = iso->offset;
948 + uiso->length = iso->length;
949 + uiso->status = iso->status;
950 + uiso->actual_length = iso->actual_length;
955 +/* must free buffer */
956 +void *usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen)
959 + struct usbip_iso_packet_descriptor *iso;
960 + int np = urb->number_of_packets;
961 + ssize_t size = np * sizeof(*iso);
964 + buff = kzalloc(size, GFP_KERNEL);
968 + for (i = 0; i < np; i++) {
969 + iso = buff + (i * sizeof(*iso));
971 + usbip_pack_iso(iso, &urb->iso_frame_desc[i], 1);
972 + usbip_iso_pakcet_correct_endian(iso, 1);
979 +EXPORT_SYMBOL_GPL(usbip_alloc_iso_desc_pdu);
981 +/* some members of urb must be substituted before. */
982 +int usbip_recv_iso(struct usbip_device *ud, struct urb *urb)
985 + struct usbip_iso_packet_descriptor *iso;
986 + int np = urb->number_of_packets;
987 + int size = np * sizeof(*iso);
991 + if (!usb_pipeisoc(urb->pipe))
994 + /* my Bluetooth dongle gets ISO URBs which are np = 0 */
996 + /* uinfo("iso np == 0\n"); */
997 + /* usbip_dump_urb(urb); */
1001 + buff = kzalloc(size, GFP_KERNEL);
1005 + ret = usbip_xmit(0, ud->tcp_socket, buff, size, 0);
1006 + if (ret != size) {
1007 + dev_err(&urb->dev->dev, "recv iso_frame_descriptor, %d\n",
1011 + if (ud->side == USBIP_STUB)
1012 + usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
1014 + usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
1019 + for (i = 0; i < np; i++) {
1020 + iso = buff + (i * sizeof(*iso));
1022 + usbip_iso_pakcet_correct_endian(iso, 0);
1023 + usbip_pack_iso(iso, &urb->iso_frame_desc[i], 0);
1031 +EXPORT_SYMBOL_GPL(usbip_recv_iso);
1034 +/* some members of urb must be substituted before. */
1035 +int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb)
1040 + if (ud->side == USBIP_STUB) {
1042 + /* the direction of urb must be OUT. */
1043 + if (usb_pipein(urb->pipe))
1046 + size = urb->transfer_buffer_length;
1049 + /* the direction of urb must be IN. */
1050 + if (usb_pipeout(urb->pipe))
1053 + size = urb->actual_length;
1056 + /* no need to recv xbuff */
1060 + ret = usbip_xmit(0, ud->tcp_socket, (char *)urb->transfer_buffer,
1062 + if (ret != size) {
1063 + dev_err(&urb->dev->dev, "recv xbuf, %d\n", ret);
1064 + if (ud->side == USBIP_STUB) {
1065 + usbip_event_add(ud, SDEV_EVENT_ERROR_TCP);
1067 + usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
1074 +EXPORT_SYMBOL_GPL(usbip_recv_xbuff);
1077 +/*-------------------------------------------------------------------------*/
1079 +static int __init usbip_common_init(void)
1081 + printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "" DRIVER_VERSION);
1086 +static void __exit usbip_common_exit(void)
1094 +module_init(usbip_common_init);
1095 +module_exit(usbip_common_exit);
1097 +MODULE_AUTHOR(DRIVER_AUTHOR);
1098 +MODULE_DESCRIPTION(DRIVER_DESC);
1099 +MODULE_LICENSE("GPL");
1100 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
1101 new file mode 100644
1102 index 0000000..b0186b7
1104 +++ b/drivers/staging/usbip/usbip_common.h
1107 + * Copyright (C) 2003-2008 Takahiro Hirofuchi
1109 + * This is free software; you can redistribute it and/or modify
1110 + * it under the terms of the GNU General Public License as published by
1111 + * the Free Software Foundation; either version 2 of the License, or
1112 + * (at your option) any later version.
1114 + * This is distributed in the hope that it will be useful,
1115 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1116 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1117 + * GNU General Public License for more details.
1119 + * You should have received a copy of the GNU General Public License
1120 + * along with this program; if not, write to the Free Software
1121 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1125 +#ifndef __VHCI_COMMON_H
1126 +#define __VHCI_COMMON_H
1129 +#include <linux/version.h>
1130 +#include <linux/usb.h>
1131 +#include <asm/byteorder.h>
1132 +#include <net/sock.h>
1134 +/*-------------------------------------------------------------------------*/
1137 + * define macros to print messages
1141 + * udbg - print debug messages if CONFIG_USB_DEBUG is defined
1146 +#ifdef CONFIG_USB_DEBUG
1148 +#define udbg(fmt, args...) \
1150 + printk(KERN_DEBUG "%-10s:(%s,%d) %s: " fmt, \
1151 + (in_interrupt() ? "interrupt" : (current)->comm),\
1152 + __FILE__, __LINE__, __func__, ##args); \
1155 +#else /* CONFIG_USB_DEBUG */
1157 +#define udbg(fmt, args...) do { } while (0)
1159 +#endif /* CONFIG_USB_DEBUG */
1163 + usbip_debug_xmit = (1 << 0),
1164 + usbip_debug_sysfs = (1 << 1),
1165 + usbip_debug_urb = (1 << 2),
1166 + usbip_debug_eh = (1 << 3),
1168 + usbip_debug_stub_cmp = (1 << 8),
1169 + usbip_debug_stub_dev = (1 << 9),
1170 + usbip_debug_stub_rx = (1 << 10),
1171 + usbip_debug_stub_tx = (1 << 11),
1173 + usbip_debug_vhci_rh = (1 << 8),
1174 + usbip_debug_vhci_hc = (1 << 9),
1175 + usbip_debug_vhci_rx = (1 << 10),
1176 + usbip_debug_vhci_tx = (1 << 11),
1177 + usbip_debug_vhci_sysfs = (1 << 12)
1180 +#define dbg_flag_xmit (usbip_debug_flag & usbip_debug_xmit)
1181 +#define dbg_flag_vhci_rh (usbip_debug_flag & usbip_debug_vhci_rh)
1182 +#define dbg_flag_vhci_hc (usbip_debug_flag & usbip_debug_vhci_hc)
1183 +#define dbg_flag_vhci_rx (usbip_debug_flag & usbip_debug_vhci_rx)
1184 +#define dbg_flag_vhci_tx (usbip_debug_flag & usbip_debug_vhci_tx)
1185 +#define dbg_flag_vhci_sysfs (usbip_debug_flag & usbip_debug_vhci_sysfs)
1186 +#define dbg_flag_stub_rx (usbip_debug_flag & usbip_debug_stub_rx)
1187 +#define dbg_flag_stub_tx (usbip_debug_flag & usbip_debug_stub_tx)
1189 +extern unsigned long usbip_debug_flag;
1190 +extern struct device_attribute dev_attr_usbip_debug;
1192 +#define dbg_with_flag(flag, fmt, args...) \
1194 + if (flag & usbip_debug_flag) \
1195 + udbg(fmt , ##args); \
1198 +#define dbg_sysfs(fmt, args...) \
1199 + dbg_with_flag(usbip_debug_sysfs, fmt , ##args)
1200 +#define dbg_xmit(fmt, args...) \
1201 + dbg_with_flag(usbip_debug_xmit, fmt , ##args)
1202 +#define dbg_urb(fmt, args...) \
1203 + dbg_with_flag(usbip_debug_urb, fmt , ##args)
1204 +#define dbg_eh(fmt, args...) \
1205 + dbg_with_flag(usbip_debug_eh, fmt , ##args)
1207 +#define dbg_vhci_rh(fmt, args...) \
1208 + dbg_with_flag(usbip_debug_vhci_rh, fmt , ##args)
1209 +#define dbg_vhci_hc(fmt, args...) \
1210 + dbg_with_flag(usbip_debug_vhci_hc, fmt , ##args)
1211 +#define dbg_vhci_rx(fmt, args...) \
1212 + dbg_with_flag(usbip_debug_vhci_rx, fmt , ##args)
1213 +#define dbg_vhci_tx(fmt, args...) \
1214 + dbg_with_flag(usbip_debug_vhci_tx, fmt , ##args)
1215 +#define dbg_vhci_sysfs(fmt, args...) \
1216 + dbg_with_flag(usbip_debug_vhci_sysfs, fmt , ##args)
1218 +#define dbg_stub_cmp(fmt, args...) \
1219 + dbg_with_flag(usbip_debug_stub_cmp, fmt , ##args)
1220 +#define dbg_stub_rx(fmt, args...) \
1221 + dbg_with_flag(usbip_debug_stub_rx, fmt , ##args)
1222 +#define dbg_stub_tx(fmt, args...) \
1223 + dbg_with_flag(usbip_debug_stub_tx, fmt , ##args)
1227 + * uerr - print error messages
1231 +#define uerr(fmt, args...) \
1233 + printk(KERN_ERR "%-10s: ***ERROR*** (%s,%d) %s: " fmt, \
1234 + (in_interrupt() ? "interrupt" : (current)->comm),\
1235 + __FILE__, __LINE__, __func__, ##args); \
1239 + * uinfo - print information messages
1243 +#define uinfo(fmt, args...) \
1245 + printk(KERN_INFO "usbip: " fmt , ## args); \
1249 +/*-------------------------------------------------------------------------*/
1252 + * USB/IP request headers.
1253 + * Currently, we define 4 request types:
1255 + * - CMD_SUBMIT transfers a USB request, corresponding to usb_submit_urb().
1256 + * (client to server)
1257 + * - RET_RETURN transfers the result of CMD_SUBMIT.
1258 + * (server to client)
1259 + * - CMD_UNLINK transfers an unlink request of a pending USB request.
1260 + * (client to server)
1261 + * - RET_UNLINK transfers the result of CMD_UNLINK.
1262 + * (server to client)
1264 + * Note: The below request formats are based on the USB subsystem of Linux. Its
1265 + * details will be defined when other implementations come.
1271 + * A basic header followed by other additional headers.
1273 +struct usbip_header_basic {
1274 +#define USBIP_CMD_SUBMIT 0x0001
1275 +#define USBIP_CMD_UNLINK 0x0002
1276 +#define USBIP_RET_SUBMIT 0x0003
1277 +#define USBIP_RET_UNLINK 0x0004
1280 + /* sequencial number which identifies requests.
1281 + * incremented per connections */
1284 + /* devid is used to specify a remote USB device uniquely instead
1285 + * of busnum and devnum in Linux. In the case of Linux stub_driver,
1286 + * this value is ((busnum << 16) | devnum) */
1289 +#define USBIP_DIR_OUT 0
1290 +#define USBIP_DIR_IN 1
1292 + __u32 ep; /* endpoint number */
1293 +} __attribute__ ((packed));
1296 + * An additional header for a CMD_SUBMIT packet.
1298 +struct usbip_header_cmd_submit {
1299 + /* these values are basically the same as in a URB. */
1301 + /* the same in a URB. */
1302 + __u32 transfer_flags;
1304 + /* set the following data size (out),
1305 + * or expected reading data size (in) */
1306 + __s32 transfer_buffer_length;
1308 + /* it is difficult for usbip to sync frames (reserved only?) */
1309 + __s32 start_frame;
1311 + /* the number of iso descriptors that follows this header */
1312 + __s32 number_of_packets;
1314 + /* the maximum time within which this request works in a host
1315 + * controller of a server side */
1318 + /* set setup packet data for a CTRL request */
1319 + unsigned char setup[8];
1320 +} __attribute__ ((packed));
1323 + * An additional header for a RET_SUBMIT packet.
1325 +struct usbip_header_ret_submit {
1327 + __s32 actual_length; /* returned data length */
1328 + __s32 start_frame; /* ISO and INT */
1329 + __s32 number_of_packets; /* ISO only */
1330 + __s32 error_count; /* ISO only */
1331 +} __attribute__ ((packed));
1334 + * An additional header for a CMD_UNLINK packet.
1336 +struct usbip_header_cmd_unlink {
1337 + __u32 seqnum; /* URB's seqnum which will be unlinked */
1338 +} __attribute__ ((packed));
1342 + * An additional header for a RET_UNLINK packet.
1344 +struct usbip_header_ret_unlink {
1346 +} __attribute__ ((packed));
1349 +/* the same as usb_iso_packet_descriptor but packed for pdu */
1350 +struct usbip_iso_packet_descriptor {
1352 + __u32 length; /* expected length */
1353 + __u32 actual_length;
1355 +} __attribute__ ((packed));
1359 + * All usbip packets use a common header to keep code simple.
1361 +struct usbip_header {
1362 + struct usbip_header_basic base;
1365 + struct usbip_header_cmd_submit cmd_submit;
1366 + struct usbip_header_ret_submit ret_submit;
1367 + struct usbip_header_cmd_unlink cmd_unlink;
1368 + struct usbip_header_ret_unlink ret_unlink;
1370 +} __attribute__ ((packed));
1375 +/*-------------------------------------------------------------------------*/
1378 +int usbip_xmit(int, struct socket *, char *, int, int);
1379 +int usbip_sendmsg(struct socket *, struct msghdr *, int);
1382 +static inline int interface_to_busnum(struct usb_interface *interface)
1384 + struct usb_device *udev = interface_to_usbdev(interface);
1385 + return udev->bus->busnum;
1388 +static inline int interface_to_devnum(struct usb_interface *interface)
1390 + struct usb_device *udev = interface_to_usbdev(interface);
1391 + return udev->devnum;
1394 +static inline int interface_to_infnum(struct usb_interface *interface)
1396 + return interface->cur_altsetting->desc.bInterfaceNumber;
1400 +int setnodelay(struct socket *);
1401 +int setquickack(struct socket *);
1402 +int setkeepalive(struct socket *socket);
1403 +void setreuse(struct socket *);
1406 +struct socket *sockfd_to_socket(unsigned int);
1407 +int set_sockaddr(struct socket *socket, struct sockaddr_storage *ss);
1409 +void usbip_dump_urb(struct urb *purb);
1410 +void usbip_dump_header(struct usbip_header *pdu);
1413 +struct usbip_device;
1415 +struct usbip_task {
1416 + struct task_struct *thread;
1417 + struct completion thread_done;
1419 + void (*loop_ops)(struct usbip_task *);
1427 +enum usbip_status {
1428 + /* sdev is available. */
1429 + SDEV_ST_AVAILABLE = 0x01,
1430 + /* sdev is now used. */
1432 + /* sdev is unusable because of a fatal error. */
1435 + /* vdev does not connect a remote device. */
1437 + /* vdev is used, but the USB address is not assigned yet */
1438 + VDEV_ST_NOTASSIGNED,
1443 +/* a common structure for stub_device and vhci_device */
1444 +struct usbip_device {
1445 + enum usbip_side side;
1447 + enum usbip_status status;
1449 + /* lock for status */
1452 + struct socket *tcp_socket;
1454 + struct usbip_task tcp_rx;
1455 + struct usbip_task tcp_tx;
1457 + /* event handler */
1458 +#define USBIP_EH_SHUTDOWN (1 << 0)
1459 +#define USBIP_EH_BYE (1 << 1)
1460 +#define USBIP_EH_RESET (1 << 2)
1461 +#define USBIP_EH_UNUSABLE (1 << 3)
1463 +#define SDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE)
1464 +#define SDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
1465 +#define SDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
1466 +#define SDEV_EVENT_ERROR_SUBMIT (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
1467 +#define SDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
1469 +#define VDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_BYE)
1470 +#define VDEV_EVENT_DOWN (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
1471 +#define VDEV_EVENT_ERROR_TCP (USBIP_EH_SHUTDOWN | USBIP_EH_RESET)
1472 +#define VDEV_EVENT_ERROR_MALLOC (USBIP_EH_SHUTDOWN | USBIP_EH_UNUSABLE)
1474 + unsigned long event;
1475 + struct usbip_task eh;
1476 + wait_queue_head_t eh_waitq;
1479 + void (*shutdown)(struct usbip_device *);
1480 + void (*reset)(struct usbip_device *);
1481 + void (*unusable)(struct usbip_device *);
1486 +void usbip_task_init(struct usbip_task *ut, char *,
1487 + void (*loop_ops)(struct usbip_task *));
1489 +void usbip_start_threads(struct usbip_device *ud);
1490 +void usbip_stop_threads(struct usbip_device *ud);
1491 +int usbip_thread(void *param);
1493 +void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd,
1496 +void usbip_header_correct_endian(struct usbip_header *pdu, int send);
1497 +/* some members of urb must be substituted before. */
1498 +int usbip_recv_xbuff(struct usbip_device *ud, struct urb *urb);
1499 +/* some members of urb must be substituted before. */
1500 +int usbip_recv_iso(struct usbip_device *ud, struct urb *urb);
1501 +void *usbip_alloc_iso_desc_pdu(struct urb *urb, ssize_t *bufflen);
1504 +/* usbip_event.c */
1505 +void usbip_start_eh(struct usbip_device *ud);
1506 +void usbip_stop_eh(struct usbip_device *ud);
1507 +void usbip_event_add(struct usbip_device *ud, unsigned long event);
1508 +int usbip_event_happend(struct usbip_device *ud);
1512 diff --git a/drivers/staging/usbip/usbip_event.c b/drivers/staging/usbip/usbip_event.c
1513 new file mode 100644
1514 index 0000000..4318553
1516 +++ b/drivers/staging/usbip/usbip_event.c
1519 + * Copyright (C) 2003-2008 Takahiro Hirofuchi
1521 + * This is free software; you can redistribute it and/or modify
1522 + * it under the terms of the GNU General Public License as published by
1523 + * the Free Software Foundation; either version 2 of the License, or
1524 + * (at your option) any later version.
1526 + * This is distributed in the hope that it will be useful,
1527 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1528 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1529 + * GNU General Public License for more details.
1531 + * You should have received a copy of the GNU General Public License
1532 + * along with this program; if not, write to the Free Software
1533 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1537 +#include "usbip_common.h"
1539 +static int event_handler(struct usbip_device *ud)
1541 + dbg_eh("enter\n");
1544 + * Events are handled by only this thread.
1546 + while (usbip_event_happend(ud)) {
1547 + dbg_eh("pending event %lx\n", ud->event);
1550 + * NOTE: shutdown must come first.
1551 + * Shutdown the device.
1553 + if (ud->event & USBIP_EH_SHUTDOWN) {
1554 + ud->eh_ops.shutdown(ud);
1556 + ud->event &= ~USBIP_EH_SHUTDOWN;
1561 + /* Stop the error handler. */
1562 + if (ud->event & USBIP_EH_BYE)
1565 + /* Reset the device. */
1566 + if (ud->event & USBIP_EH_RESET) {
1567 + ud->eh_ops.reset(ud);
1569 + ud->event &= ~USBIP_EH_RESET;
1574 + /* Mark the device as unusable. */
1575 + if (ud->event & USBIP_EH_UNUSABLE) {
1576 + ud->eh_ops.unusable(ud);
1578 + ud->event &= ~USBIP_EH_UNUSABLE;
1584 + printk(KERN_ERR "%s: unknown event\n", __func__);
1591 +static void event_handler_loop(struct usbip_task *ut)
1593 + struct usbip_device *ud = container_of(ut, struct usbip_device, eh);
1596 + if (signal_pending(current)) {
1597 + dbg_eh("signal catched!\n");
1601 + if (event_handler(ud) < 0)
1604 + wait_event_interruptible(ud->eh_waitq, usbip_event_happend(ud));
1605 + dbg_eh("wakeup\n");
1609 +void usbip_start_eh(struct usbip_device *ud)
1611 + struct usbip_task *eh = &ud->eh;
1613 + init_waitqueue_head(&ud->eh_waitq);
1616 + usbip_task_init(eh, "usbip_eh", event_handler_loop);
1618 + kernel_thread(usbip_thread, (void *)eh, 0);
1620 + wait_for_completion(&eh->thread_done);
1622 +EXPORT_SYMBOL_GPL(usbip_start_eh);
1624 +void usbip_stop_eh(struct usbip_device *ud)
1626 + struct usbip_task *eh = &ud->eh;
1628 + wait_for_completion(&eh->thread_done);
1629 + dbg_eh("usbip_eh has finished\n");
1631 +EXPORT_SYMBOL_GPL(usbip_stop_eh);
1633 +void usbip_event_add(struct usbip_device *ud, unsigned long event)
1635 + spin_lock(&ud->lock);
1637 + ud->event |= event;
1639 + wake_up(&ud->eh_waitq);
1641 + spin_unlock(&ud->lock);
1643 +EXPORT_SYMBOL_GPL(usbip_event_add);
1645 +int usbip_event_happend(struct usbip_device *ud)
1649 + spin_lock(&ud->lock);
1651 + if (ud->event != 0)
1654 + spin_unlock(&ud->lock);
1658 +EXPORT_SYMBOL_GPL(usbip_event_happend);