--- usbip-0.1.7.orig/NEWS +++ usbip-0.1.7/NEWS @@ -1,6 +1,13 @@ # vim:tw=78:ts=4:expandtab:ai:sw=4 # $Id: NEWS 86 2009-01-13 18:04:21Z hirofuchi $ +unreleased + - Cleanup: bind_driver to usbip_bind_driver + - Add: make the location of the vhci's status file configurable + - Fix: install binaries into sbin + - Add: add manpages + - Add: add --list2 option to bind_driver. + usbip-0.1.7 - Remove: temporarily contributed auto-import-daemon code - Add: info about linux-staging --- usbip-0.1.7.orig/debian/changelog +++ usbip-0.1.7/debian/changelog @@ -0,0 +1,32 @@ +usbip (0.1.7-3) unstable; urgency=low + + * Install new manpages + * Executables now live in /usr/sbin + * Import upstreamed patches + + Adding --list2 option to bind_driver. + + Respect --with-usbids-dir in cmd/ (closes: #523641) + + Typo 'CLFAGS' in lib/Makefile.am + + Add man page for usbip_bind_driver(8) + + Replace /tmp/vhci_hcd/ with VHCI_STATE_PATH + + Add man pages for usbip(8), usbipd(8) + + Install executables into $PREFIX/sbin + + Rename 'bind_driver' to more specific 'usbip_bind_driver' + + -- Max Vozeler Thu, 30 Apr 2009 23:30:45 +0200 + +usbip (0.1.7-2) unstable; urgency=low + + [ Max Vozeler ] + * Add Vcs-Git/Vcs-Browser entries. + + [ Mario Izquierdo (mariodebian) ] + * Update drivers/head with 2.6.28 sources + * Generate usbip-source package (module-assistant) + + -- Max Vozeler Tue, 03 Feb 2009 00:39:39 +0100 + +usbip (0.1.7-1) unstable; urgency=low + + * Initial release, closes: #511937. + + -- Max Vozeler Sat, 17 Jan 2009 00:29:19 +0100 --- usbip-0.1.7.orig/debian/rules +++ usbip-0.1.7/debian/rules @@ -0,0 +1,65 @@ +#!/usr/bin/make -f + +modsrcpkg:=usbip-source +modname:=usbip + +DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) +DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) + +ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE)) + confflags = --build $(DEB_HOST_GNU_TYPE) +else + confflags = --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE) +endif + +build: build-stamp +build-stamp: + dh build --before configure + cd src && ./autogen.sh + cd src && ./configure \ + $(confflags) \ + --prefix=/usr \ + --with-tcp-wrappers=no \ + --with-usbids-dir=/usr/share/misc \ + --enable-usbids-install=no + cd src && make + dh build --after configure + touch build-stamp + +clean: + -cd src && make maintainer-clean + cd src && rm -f configure config.sub config.guess missing install-sh depcomp + dh clean + +install: build install-stamp +install-stamp: + dh install --before dh_install + cd src && make install DESTDIR=$(CURDIR)/debian/tmp + + # Create usbip-source + dh_installdirs -p$(modsrcpkg) usr/src/modules/$(modname)/debian + dh_installdirs -p$(modsrcpkg) usr/src/modules/$(modname)/src + + cp -ra drivers/head/* drivers/README debian/headers \ + $(CURDIR)/debian/$(modsrcpkg)/usr/src/modules/$(modname)/src/ + + cp debian/modules/* debian/changelog debian/copyright debian/compat \ + $(CURDIR)/debian/$(modsrcpkg)/usr/src/modules/$(modname)/debian/ + + dh_fixperms -p$(modsrcpkg) + chmod +x $(CURDIR)/debian/$(modsrcpkg)/usr/src/modules/$(modname)/debian/rules + + cd debian/$(modsrcpkg)/usr/src && tar -f- -c modules | bzip2 -9 > $(modname).tar.bz2 && rm -rf modules + + dh install --remaining + touch install-stamp + +binary-arch: install + dh binary-arch + +binary-indep: install + dh binary-indep + +binary: binary-arch binary-indep + +.PHONY: build clean install binary binary-arch binary-indep --- usbip-0.1.7.orig/debian/compat +++ usbip-0.1.7/debian/compat @@ -0,0 +1 @@ +7 --- usbip-0.1.7.orig/debian/libusbip-dev.install +++ usbip-0.1.7/debian/libusbip-dev.install @@ -0,0 +1,4 @@ +usr/lib/libusbip.so +usr/lib/libusbip.la +usr/lib/libusbip.a +usr/include/usbip/* --- usbip-0.1.7.orig/debian/usbip.manpages +++ usbip-0.1.7/debian/usbip.manpages @@ -0,0 +1,3 @@ +src/cmd/usbip.8 +src/cmd/usbipd.8 +src/cmd/usbip_bind_driver.8 --- usbip-0.1.7.orig/debian/watch +++ usbip-0.1.7/debian/watch @@ -0,0 +1,2 @@ +version=3 +http://sf.net/usbip/usbip-(\d+\.\d+\.\d+)\.tar\.gz --- usbip-0.1.7.orig/debian/control +++ usbip-0.1.7/debian/control @@ -0,0 +1,62 @@ +Source: usbip +Section: admin +Priority: optional +Maintainer: Max Vozeler +Build-Depends: debhelper (>= 7), autoconf, automake, libtool, libglib2.0-dev, libsysfs-dev +Standards-Version: 3.8.0 +Homepage: http://usbip.sourceforge.net/ +Vcs-Browser: http://git.debian.org/?p=users/xam/usbip.git +Vcs-Git: git://git.debian.org/~xam/usbip.git + +Package: usbip +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, usbutils +Description: USB device sharing system over IP network + USB/IP is a system for sharing USB devices over the network. + . + To share USB devices between computers with their full + functionality, USB/IP encapsulates "USB requests" into IP + packets and transmits them between computers. + . + Original USB device drivers and applications can be used + for remote USB devices without any modification of them. A + computer can use remote USB devices as if they were + directly attached. + . + Currently USB/IP provides no access control or encryption. + It should only be used in trusted environments. + . + USB/IP requires kernel support which is included in Linux + kernels 2.6.28 or newer. + . + This package provides the server component 'usbipd' and the + client tool 'usbip'. + +Package: libusbip0 +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Section: libs +Description: USB device sharing system over IP network (shared library) + USB/IP is a system for sharing USB devices over the network. + . + This package provides the shared library libusbip0. + +Package: libusbip-dev +Architecture: any +Depends: ${misc:Depends}, libusbip0 (= ${binary:Version}) +Section: libdevel +Description: USB device sharing system over IP network (development files) + USB/IP is a system for sharing USB devices over the network. + . + This package provides headers for the libusbip0 library and + the library itself for static linking. + +Package: usbip-source +Architecture: all +Recommends: usbip +Depends: ${misc:Depends}, module-assistant, debhelper (>= 5), make, bzip2 +Description: USB device sharing system over IP network (kernel module source) + USB/IP is a system for sharing USB devices over the network. + . + This package provides kernel module sources used by module-assistant + to build USBIP modules. --- usbip-0.1.7.orig/debian/libusbip0.install +++ usbip-0.1.7/debian/libusbip0.install @@ -0,0 +1 @@ +usr/lib/libusbip.so.* --- usbip-0.1.7.orig/debian/docs +++ usbip-0.1.7/debian/docs @@ -0,0 +1,2 @@ +README +src/README --- usbip-0.1.7.orig/debian/usbip.install +++ usbip-0.1.7/debian/usbip.install @@ -0,0 +1,3 @@ +usr/sbin/usbip +usr/sbin/usbipd +usr/sbin/usbip_bind_driver --- usbip-0.1.7.orig/debian/copyright +++ usbip-0.1.7/debian/copyright @@ -0,0 +1,38 @@ +This is a Debian prepackaged version of USB/IP. + +This package was put together by Max Vozeler +using sources from + + http://usbip.sourceforge.net/ + +Copyright: + + - debian/headers/*: + hcd.h and hub.h are from linux source (2.6.26) + Copyright (c) 2001-2002 by David Brownell + + - USB/IP: + Copyright (C) 2003-2008 Takahiro Hirofuchi + Copyright (C) 1999, 2000 Thomas Sailer (sailer@ife.ee.ethz.ch) + +License: + + This program 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 program 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., 51 + Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. + + On Debian systems, the complete text of the GNU General Public License + can be found in "/usr/share/common-licenses/GPL". + +The Debian packaging is copyright 2009, Max Vozeler +and is licensed under the GPL, see `/usr/share/common-licenses/GPL'. --- usbip-0.1.7.orig/debian/headers/hcd.h +++ usbip-0.1.7/debian/headers/hcd.h @@ -0,0 +1,480 @@ +/* + * Copyright (c) 2001-2002 by David Brownell + * + * This program 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 program 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., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + + +#ifdef __KERNEL__ + +#include + +/* This file contains declarations of usbcore internals that are mostly + * used or exposed by Host Controller Drivers. + */ + +/* + * USB Packet IDs (PIDs) + */ +#define USB_PID_UNDEF_0 0xf0 +#define USB_PID_OUT 0xe1 +#define USB_PID_ACK 0xd2 +#define USB_PID_DATA0 0xc3 +#define USB_PID_PING 0xb4 /* USB 2.0 */ +#define USB_PID_SOF 0xa5 +#define USB_PID_NYET 0x96 /* USB 2.0 */ +#define USB_PID_DATA2 0x87 /* USB 2.0 */ +#define USB_PID_SPLIT 0x78 /* USB 2.0 */ +#define USB_PID_IN 0x69 +#define USB_PID_NAK 0x5a +#define USB_PID_DATA1 0x4b +#define USB_PID_PREAMBLE 0x3c /* Token mode */ +#define USB_PID_ERR 0x3c /* USB 2.0: handshake mode */ +#define USB_PID_SETUP 0x2d +#define USB_PID_STALL 0x1e +#define USB_PID_MDATA 0x0f /* USB 2.0 */ + +/*-------------------------------------------------------------------------*/ + +/* + * USB Host Controller Driver (usb_hcd) framework + * + * Since "struct usb_bus" is so thin, you can't share much code in it. + * This framework is a layer over that, and should be more sharable. + * + * @authorized_default: Specifies if new devices are authorized to + * connect by default or they require explicit + * user space authorization; this bit is settable + * through /sys/class/usb_host/X/authorized_default. + * For the rest is RO, so we don't lock to r/w it. + */ + +/*-------------------------------------------------------------------------*/ + +struct usb_hcd { + + /* + * housekeeping + */ + struct usb_bus self; /* hcd is-a bus */ + struct kref kref; /* reference counter */ + + const char *product_desc; /* product/vendor string */ + char irq_descr[24]; /* driver + bus # */ + + struct timer_list rh_timer; /* drives root-hub polling */ + struct urb *status_urb; /* the current status urb */ +#ifdef CONFIG_PM + struct work_struct wakeup_work; /* for remote wakeup */ +#endif + + /* + * hardware info/state + */ + const struct hc_driver *driver; /* hw-specific hooks */ + + /* Flags that need to be manipulated atomically */ + unsigned long flags; +#define HCD_FLAG_HW_ACCESSIBLE 0x00000001 +#define HCD_FLAG_SAW_IRQ 0x00000002 + + unsigned rh_registered:1;/* is root hub registered? */ + + /* The next flag is a stopgap, to be removed when all the HCDs + * support the new root-hub polling mechanism. */ + unsigned uses_new_polling:1; + unsigned poll_rh:1; /* poll for rh status? */ + unsigned poll_pending:1; /* status has changed? */ + unsigned wireless:1; /* Wireless USB HCD */ + unsigned authorized_default:1; + + int irq; /* irq allocated */ + void __iomem *regs; /* device memory/io */ + u64 rsrc_start; /* memory/io resource start */ + u64 rsrc_len; /* memory/io resource length */ + unsigned power_budget; /* in mA, 0 = no limit */ + +#define HCD_BUFFER_POOLS 4 + struct dma_pool *pool [HCD_BUFFER_POOLS]; + + int state; +# define __ACTIVE 0x01 +# define __SUSPEND 0x04 +# define __TRANSIENT 0x80 + +# define HC_STATE_HALT 0 +# define HC_STATE_RUNNING (__ACTIVE) +# define HC_STATE_QUIESCING (__SUSPEND|__TRANSIENT|__ACTIVE) +# define HC_STATE_RESUMING (__SUSPEND|__TRANSIENT) +# define HC_STATE_SUSPENDED (__SUSPEND) + +#define HC_IS_RUNNING(state) ((state) & __ACTIVE) +#define HC_IS_SUSPENDED(state) ((state) & __SUSPEND) + + /* more shared queuing code would be good; it should support + * smarter scheduling, handle transaction translators, etc; + * input size of periodic table to an interrupt scheduler. + * (ohci 32, uhci 1024, ehci 256/512/1024). + */ + + /* The HC driver's private data is stored at the end of + * this structure. + */ + unsigned long hcd_priv[0] + __attribute__ ((aligned (sizeof(unsigned long)))); +}; + +/* 2.4 does this a bit differently ... */ +static inline struct usb_bus *hcd_to_bus (struct usb_hcd *hcd) +{ + return &hcd->self; +} + +static inline struct usb_hcd *bus_to_hcd (struct usb_bus *bus) +{ + return container_of(bus, struct usb_hcd, self); +} + +struct hcd_timeout { /* timeouts we allocate */ + struct list_head timeout_list; + struct timer_list timer; +}; + +/*-------------------------------------------------------------------------*/ + + +struct hc_driver { + const char *description; /* "ehci-hcd" etc */ + const char *product_desc; /* product/vendor string */ + size_t hcd_priv_size; /* size of private data */ + + /* irq handler */ + irqreturn_t (*irq) (struct usb_hcd *hcd); + + int flags; +#define HCD_MEMORY 0x0001 /* HC regs use memory (else I/O) */ +#define HCD_USB11 0x0010 /* USB 1.1 */ +#define HCD_USB2 0x0020 /* USB 2.0 */ + + /* called to init HCD and root hub */ + int (*reset) (struct usb_hcd *hcd); + int (*start) (struct usb_hcd *hcd); + + /* NOTE: these suspend/resume calls relate to the HC as + * a whole, not just the root hub; they're for PCI bus glue. + */ + /* called after suspending the hub, before entering D3 etc */ + int (*suspend) (struct usb_hcd *hcd, pm_message_t message); + + /* called after entering D0 (etc), before resuming the hub */ + int (*resume) (struct usb_hcd *hcd); + + /* cleanly make HCD stop writing memory and doing I/O */ + void (*stop) (struct usb_hcd *hcd); + + /* shutdown HCD */ + void (*shutdown) (struct usb_hcd *hcd); + + /* return current frame number */ + int (*get_frame_number) (struct usb_hcd *hcd); + + /* manage i/o requests, device state */ + int (*urb_enqueue)(struct usb_hcd *hcd, + struct urb *urb, gfp_t mem_flags); + int (*urb_dequeue)(struct usb_hcd *hcd, + struct urb *urb, int status); + + /* hw synch, freeing endpoint resources that urb_dequeue can't */ + void (*endpoint_disable)(struct usb_hcd *hcd, + struct usb_host_endpoint *ep); + + /* root hub support */ + int (*hub_status_data) (struct usb_hcd *hcd, char *buf); + int (*hub_control) (struct usb_hcd *hcd, + u16 typeReq, u16 wValue, u16 wIndex, + char *buf, u16 wLength); + int (*bus_suspend)(struct usb_hcd *); + int (*bus_resume)(struct usb_hcd *); + int (*start_port_reset)(struct usb_hcd *, unsigned port_num); + void (*hub_irq_enable)(struct usb_hcd *); + /* Needed only if port-change IRQs are level-triggered */ +}; + +extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb); +extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, + int status); +extern void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb); + +extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags); +extern int usb_hcd_unlink_urb (struct urb *urb, int status); +extern void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, + int status); +extern void usb_hcd_flush_endpoint(struct usb_device *udev, + struct usb_host_endpoint *ep); +extern void usb_hcd_disable_endpoint(struct usb_device *udev, + struct usb_host_endpoint *ep); +extern int usb_hcd_get_frame_number (struct usb_device *udev); + +extern struct usb_hcd *usb_create_hcd (const struct hc_driver *driver, + struct device *dev, char *bus_name); +extern struct usb_hcd *usb_get_hcd (struct usb_hcd *hcd); +extern void usb_put_hcd (struct usb_hcd *hcd); +extern int usb_add_hcd(struct usb_hcd *hcd, + unsigned int irqnum, unsigned long irqflags); +extern void usb_remove_hcd(struct usb_hcd *hcd); + +struct platform_device; +extern void usb_hcd_platform_shutdown(struct platform_device* dev); + +#ifdef CONFIG_PCI +struct pci_dev; +struct pci_device_id; +extern int usb_hcd_pci_probe (struct pci_dev *dev, + const struct pci_device_id *id); +extern void usb_hcd_pci_remove (struct pci_dev *dev); + +#ifdef CONFIG_PM +extern int usb_hcd_pci_suspend (struct pci_dev *dev, pm_message_t state); +extern int usb_hcd_pci_resume (struct pci_dev *dev); +#endif /* CONFIG_PM */ + +extern void usb_hcd_pci_shutdown (struct pci_dev *dev); + +#endif /* CONFIG_PCI */ + +/* pci-ish (pdev null is ok) buffer alloc/mapping support */ +int hcd_buffer_create (struct usb_hcd *hcd); +void hcd_buffer_destroy (struct usb_hcd *hcd); + +void *hcd_buffer_alloc (struct usb_bus *bus, size_t size, + gfp_t mem_flags, dma_addr_t *dma); +void hcd_buffer_free (struct usb_bus *bus, size_t size, + void *addr, dma_addr_t dma); + +/* generic bus glue, needed for host controllers that don't use PCI */ +extern irqreturn_t usb_hcd_irq (int irq, void *__hcd); + +extern void usb_hc_died (struct usb_hcd *hcd); +extern void usb_hcd_poll_rh_status(struct usb_hcd *hcd); + +/* -------------------------------------------------------------------------- */ + +/* Enumeration is only for the hub driver, or HCD virtual root hubs */ +extern struct usb_device *usb_alloc_dev(struct usb_device *parent, + struct usb_bus *, unsigned port); +extern int usb_new_device(struct usb_device *dev); +extern void usb_disconnect(struct usb_device **); + +extern int usb_get_configuration(struct usb_device *dev); +extern void usb_destroy_configuration(struct usb_device *dev); + +/*-------------------------------------------------------------------------*/ + +/* + * HCD Root Hub support + */ + +#include "hub.h" + +/* (shifted) direction/type/recipient from the USB 2.0 spec, table 9.2 */ +#define DeviceRequest \ + ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8) +#define DeviceOutRequest \ + ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8) + +#define InterfaceRequest \ + ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8) + +#define EndpointRequest \ + ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8) +#define EndpointOutRequest \ + ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8) + +/* class requests from the USB 2.0 hub spec, table 11-15 */ +/* GetBusState and SetHubDescriptor are optional, omitted */ +#define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE) +#define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE) +#define GetHubDescriptor (0xa000 | USB_REQ_GET_DESCRIPTOR) +#define GetHubStatus (0xa000 | USB_REQ_GET_STATUS) +#define GetPortStatus (0xa300 | USB_REQ_GET_STATUS) +#define SetHubFeature (0x2000 | USB_REQ_SET_FEATURE) +#define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE) + + +/*-------------------------------------------------------------------------*/ + +/* + * Generic bandwidth allocation constants/support + */ +#define FRAME_TIME_USECS 1000L +#define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */ + /* Trying not to use worst-case bit-stuffing + of (7/6 * 8 * bytecount) = 9.33 * bytecount */ + /* bytecount = data payload byte count */ + +#define NS_TO_US(ns) ((ns + 500L) / 1000L) + /* convert & round nanoseconds to microseconds */ + + +/* + * Full/low speed bandwidth allocation constants/support. + */ +#define BW_HOST_DELAY 1000L /* nanoseconds */ +#define BW_HUB_LS_SETUP 333L /* nanoseconds */ + /* 4 full-speed bit times (est.) */ + +#define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */ +#define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L) +#define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L) + +/* + * Ceiling [nano/micro]seconds (typical) for that many bytes at high speed + * ISO is a bit less, no ACK ... from USB 2.0 spec, 5.11.3 (and needed + * to preallocate bandwidth) + */ +#define USB2_HOST_DELAY 5 /* nsec, guess */ +#define HS_NSECS(bytes) ( ((55 * 8 * 2083) \ + + (2083UL * (3 + BitTime(bytes))))/1000 \ + + USB2_HOST_DELAY) +#define HS_NSECS_ISO(bytes) ( ((38 * 8 * 2083) \ + + (2083UL * (3 + BitTime(bytes))))/1000 \ + + USB2_HOST_DELAY) +#define HS_USECS(bytes) NS_TO_US (HS_NSECS(bytes)) +#define HS_USECS_ISO(bytes) NS_TO_US (HS_NSECS_ISO(bytes)) + +extern long usb_calc_bus_time (int speed, int is_input, + int isoc, int bytecount); + +/*-------------------------------------------------------------------------*/ + +extern void usb_set_device_state(struct usb_device *udev, + enum usb_device_state new_state); + +/*-------------------------------------------------------------------------*/ + +/* exported only within usbcore */ + +extern struct list_head usb_bus_list; +extern struct mutex usb_bus_list_lock; +extern wait_queue_head_t usb_kill_urb_queue; + +extern void usb_enable_root_hub_irq (struct usb_bus *bus); + +extern int usb_find_interface_driver (struct usb_device *dev, + struct usb_interface *interface); + +#define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN)) + +#ifdef CONFIG_PM +extern void usb_hcd_resume_root_hub (struct usb_hcd *hcd); +extern void usb_root_hub_lost_power (struct usb_device *rhdev); +extern int hcd_bus_suspend(struct usb_device *rhdev); +extern int hcd_bus_resume(struct usb_device *rhdev); +#else +static inline void usb_hcd_resume_root_hub(struct usb_hcd *hcd) +{ + return; +} +#endif /* CONFIG_PM */ + +/* + * USB device fs stuff + */ + +#ifdef CONFIG_USB_DEVICEFS + +/* + * these are expected to be called from the USB core/hub thread + * with the kernel lock held + */ +extern void usbfs_update_special (void); +extern int usbfs_init(void); +extern void usbfs_cleanup(void); + +#else /* CONFIG_USB_DEVICEFS */ + +static inline void usbfs_update_special (void) {} +static inline int usbfs_init(void) { return 0; } +static inline void usbfs_cleanup(void) { } + +#endif /* CONFIG_USB_DEVICEFS */ + +/*-------------------------------------------------------------------------*/ + +#if defined(CONFIG_USB_MON) + +struct usb_mon_operations { + void (*urb_submit)(struct usb_bus *bus, struct urb *urb); + void (*urb_submit_error)(struct usb_bus *bus, struct urb *urb, int err); + void (*urb_complete)(struct usb_bus *bus, struct urb *urb, int status); + /* void (*urb_unlink)(struct usb_bus *bus, struct urb *urb); */ +}; + +extern struct usb_mon_operations *mon_ops; + +static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb) +{ + if (bus->monitored) + (*mon_ops->urb_submit)(bus, urb); +} + +static inline void usbmon_urb_submit_error(struct usb_bus *bus, struct urb *urb, + int error) +{ + if (bus->monitored) + (*mon_ops->urb_submit_error)(bus, urb, error); +} + +static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb, + int status) +{ + if (bus->monitored) + (*mon_ops->urb_complete)(bus, urb, status); +} + +int usb_mon_register(struct usb_mon_operations *ops); +void usb_mon_deregister(void); + +#else + +static inline void usbmon_urb_submit(struct usb_bus *bus, struct urb *urb) {} +static inline void usbmon_urb_submit_error(struct usb_bus *bus, struct urb *urb, + int error) {} +static inline void usbmon_urb_complete(struct usb_bus *bus, struct urb *urb, + int status) {} + +#endif /* CONFIG_USB_MON */ + +/*-------------------------------------------------------------------------*/ + +/* hub.h ... DeviceRemovable in 2.4.2-ac11, gone in 2.4.10 */ +// bleech -- resurfaced in 2.4.11 or 2.4.12 +#define bitmap DeviceRemovable + + +/*-------------------------------------------------------------------------*/ + +/* random stuff */ + +#define RUN_CONTEXT (in_irq () ? "in_irq" \ + : (in_interrupt () ? "in_interrupt" : "can sleep")) + + +/* This rwsem is for use only by the hub driver and ehci-hcd. + * Nobody else should touch it. + */ +extern struct rw_semaphore ehci_cf_port_reset_rwsem; + +#endif /* __KERNEL__ */ --- usbip-0.1.7.orig/debian/headers/hub.h +++ usbip-0.1.7/debian/headers/hub.h @@ -0,0 +1,195 @@ +#ifndef __LINUX_HUB_H +#define __LINUX_HUB_H + +/* + * Hub protocol and driver data structures. + * + * Some of these are known to the "virtual root hub" code + * in host controller drivers. + */ + +#include +#include +#include /* likely()/unlikely() */ + +/* + * Hub request types + */ + +#define USB_RT_HUB (USB_TYPE_CLASS | USB_RECIP_DEVICE) +#define USB_RT_PORT (USB_TYPE_CLASS | USB_RECIP_OTHER) + +/* + * Hub class requests + * See USB 2.0 spec Table 11-16 + */ +#define HUB_CLEAR_TT_BUFFER 8 +#define HUB_RESET_TT 9 +#define HUB_GET_TT_STATE 10 +#define HUB_STOP_TT 11 + +/* + * Hub Class feature numbers + * See USB 2.0 spec Table 11-17 + */ +#define C_HUB_LOCAL_POWER 0 +#define C_HUB_OVER_CURRENT 1 + +/* + * Port feature numbers + * See USB 2.0 spec Table 11-17 + */ +#define USB_PORT_FEAT_CONNECTION 0 +#define USB_PORT_FEAT_ENABLE 1 +#define USB_PORT_FEAT_SUSPEND 2 +#define USB_PORT_FEAT_OVER_CURRENT 3 +#define USB_PORT_FEAT_RESET 4 +#define USB_PORT_FEAT_POWER 8 +#define USB_PORT_FEAT_LOWSPEED 9 +#define USB_PORT_FEAT_HIGHSPEED 10 +#define USB_PORT_FEAT_C_CONNECTION 16 +#define USB_PORT_FEAT_C_ENABLE 17 +#define USB_PORT_FEAT_C_SUSPEND 18 +#define USB_PORT_FEAT_C_OVER_CURRENT 19 +#define USB_PORT_FEAT_C_RESET 20 +#define USB_PORT_FEAT_TEST 21 +#define USB_PORT_FEAT_INDICATOR 22 + +/* + * Hub Status and Hub Change results + * See USB 2.0 spec Table 11-19 and Table 11-20 + */ +struct usb_port_status { + __le16 wPortStatus; + __le16 wPortChange; +} __attribute__ ((packed)); + +/* + * wPortStatus bit field + * See USB 2.0 spec Table 11-21 + */ +#define USB_PORT_STAT_CONNECTION 0x0001 +#define USB_PORT_STAT_ENABLE 0x0002 +#define USB_PORT_STAT_SUSPEND 0x0004 +#define USB_PORT_STAT_OVERCURRENT 0x0008 +#define USB_PORT_STAT_RESET 0x0010 +/* bits 5 to 7 are reserved */ +#define USB_PORT_STAT_POWER 0x0100 +#define USB_PORT_STAT_LOW_SPEED 0x0200 +#define USB_PORT_STAT_HIGH_SPEED 0x0400 +#define USB_PORT_STAT_TEST 0x0800 +#define USB_PORT_STAT_INDICATOR 0x1000 +/* bits 13 to 15 are reserved */ + +/* + * wPortChange bit field + * See USB 2.0 spec Table 11-22 + * Bits 0 to 4 shown, bits 5 to 15 are reserved + */ +#define USB_PORT_STAT_C_CONNECTION 0x0001 +#define USB_PORT_STAT_C_ENABLE 0x0002 +#define USB_PORT_STAT_C_SUSPEND 0x0004 +#define USB_PORT_STAT_C_OVERCURRENT 0x0008 +#define USB_PORT_STAT_C_RESET 0x0010 + +/* + * wHubCharacteristics (masks) + * See USB 2.0 spec Table 11-13, offset 3 + */ +#define HUB_CHAR_LPSM 0x0003 /* D1 .. D0 */ +#define HUB_CHAR_COMPOUND 0x0004 /* D2 */ +#define HUB_CHAR_OCPM 0x0018 /* D4 .. D3 */ +#define HUB_CHAR_TTTT 0x0060 /* D6 .. D5 */ +#define HUB_CHAR_PORTIND 0x0080 /* D7 */ + +struct usb_hub_status { + __le16 wHubStatus; + __le16 wHubChange; +} __attribute__ ((packed)); + +/* + * Hub Status & Hub Change bit masks + * See USB 2.0 spec Table 11-19 and Table 11-20 + * Bits 0 and 1 for wHubStatus and wHubChange + * Bits 2 to 15 are reserved for both + */ +#define HUB_STATUS_LOCAL_POWER 0x0001 +#define HUB_STATUS_OVERCURRENT 0x0002 +#define HUB_CHANGE_LOCAL_POWER 0x0001 +#define HUB_CHANGE_OVERCURRENT 0x0002 + + +/* + * Hub descriptor + * See USB 2.0 spec Table 11-13 + */ + +#define USB_DT_HUB (USB_TYPE_CLASS | 0x09) +#define USB_DT_HUB_NONVAR_SIZE 7 + +struct usb_hub_descriptor { + __u8 bDescLength; + __u8 bDescriptorType; + __u8 bNbrPorts; + __le16 wHubCharacteristics; + __u8 bPwrOn2PwrGood; + __u8 bHubContrCurrent; + /* add 1 bit for hub status change; round to bytes */ + __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8]; + __u8 PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8]; +} __attribute__ ((packed)); + + +/* port indicator status selectors, tables 11-7 and 11-25 */ +#define HUB_LED_AUTO 0 +#define HUB_LED_AMBER 1 +#define HUB_LED_GREEN 2 +#define HUB_LED_OFF 3 + +enum hub_led_mode { + INDICATOR_AUTO = 0, + INDICATOR_CYCLE, + /* software blinks for attention: software, hardware, reserved */ + INDICATOR_GREEN_BLINK, INDICATOR_GREEN_BLINK_OFF, + INDICATOR_AMBER_BLINK, INDICATOR_AMBER_BLINK_OFF, + INDICATOR_ALT_BLINK, INDICATOR_ALT_BLINK_OFF +} __attribute__ ((packed)); + +struct usb_device; + +/* Transaction Translator Think Times, in bits */ +#define HUB_TTTT_8_BITS 0x00 +#define HUB_TTTT_16_BITS 0x20 +#define HUB_TTTT_24_BITS 0x40 +#define HUB_TTTT_32_BITS 0x60 + +/* + * As of USB 2.0, full/low speed devices are segregated into trees. + * One type grows from USB 1.1 host controllers (OHCI, UHCI etc). + * The other type grows from high speed hubs when they connect to + * full/low speed devices using "Transaction Translators" (TTs). + * + * TTs should only be known to the hub driver, and high speed bus + * drivers (only EHCI for now). They affect periodic scheduling and + * sometimes control/bulk error recovery. + */ +struct usb_tt { + struct usb_device *hub; /* upstream highspeed hub */ + int multi; /* true means one TT per port */ + unsigned think_time; /* think time in ns */ + + /* for control/bulk error recovery (CLEAR_TT_BUFFER) */ + spinlock_t lock; + struct list_head clear_list; /* of usb_tt_clear */ + struct work_struct kevent; +}; + +struct usb_tt_clear { + struct list_head clear_list; + unsigned tt; + u16 devinfo; +}; + +extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe); + +#endif /* __LINUX_HUB_H */ --- usbip-0.1.7.orig/debian/modules/postrm.modules.in +++ usbip-0.1.7/debian/modules/postrm.modules.in @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +if [ -e /boot/System.map-_KVERS_ ]; then + depmod -a -F /boot/System.map-_KVERS_ _KVERS_ || true +fi + +#DEBHELPER# --- usbip-0.1.7.orig/debian/modules/rules +++ usbip-0.1.7/debian/modules/rules @@ -0,0 +1,46 @@ +#!/usr/bin/make -f + +####### module-assistant ########## +PACKAGE=usbip-modules + +MA_DIR ?= /usr/share/modass +-include $(MA_DIR)/include/generic.make +-include $(MA_DIR)/include/common-rules.make +####### module-assistant ########## + +kdist_configure: prep-deb-files + +kdist_clean: + $(MAKE) $(MFLAGS) -f debian/rules clean + +binary-modules: prep-deb-files + dh_testroot + dh_clean + + # Build the module + cd src && $(MAKE) KSOURCE=$(KSRC) HCD_HEADER=$(CURDIR)/src/headers/hcd.h KBUILD_VERBOSE=0 + + # Install the modules ( usbip_common_mod.ko, vhci-hcd.ko and usbip.ko) + install -d $(CURDIR)/debian/$(PACKAGE)-$(KVERS)/lib/modules/$(KVERS)/updates/usbip + install -m 0644 src/usbip_common_mod.ko debian/$(PACKAGE)-$(KVERS)/lib/modules/$(KVERS)/updates/usbip/ + install -m 0644 src/vhci-hcd.ko debian/$(PACKAGE)-$(KVERS)/lib/modules/$(KVERS)/updates/usbip/ + install -m 0644 src/usbip.ko debian/$(PACKAGE)-$(KVERS)/lib/modules/$(KVERS)/updates/usbip/ + + dh_installdocs src/README + dh_installchangelogs + dh_compress + dh_fixperms + dh_installmodules + dh_installdeb + dh_gencontrol -- -v$(VERSION) + dh_md5sums + dh_builddeb --destdir=$(DEB_DESTDIR) + dh_clean + +clean: + dh_testdir + dh_testroot + cd src && make clean KSOURCE=$(KSRC) + dh_clean + +.PHONY: kdist_configure binary-modules kdist_clean clean --- usbip-0.1.7.orig/debian/modules/postinst.modules.in +++ usbip-0.1.7/debian/modules/postinst.modules.in @@ -0,0 +1,10 @@ +#!/bin/sh +set -e + +if [ "$1" = "configure" ]; then + if [ -e /boot/System.map-_KVERS_ ]; then + depmod -a -F /boot/System.map-_KVERS_ _KVERS_ || true + fi +fi + +#DEBHELPER# --- usbip-0.1.7.orig/debian/modules/control.modules.in +++ usbip-0.1.7/debian/modules/control.modules.in @@ -0,0 +1,19 @@ +Source: usbip +Section: admin +Priority: optional +Maintainer: Max Vozeler +Build-Depends: debhelper (>= 7) +Standards-Version: 3.8.0 +Homepage: http://usbip.sourceforge.net/ +Vcs-Browser: http://git.debian.org/?p=users/xam/usbip.git +Vcs-Git: git://git.debian.org/~xam/usbip.git + +Package: usbip-modules-_KVERS_ +Architecture: any +Depends: linux-modules-_KVERS_ | linux-image-_KVERS_ +Provides: usbip-modules +Description: USB device sharing system over IP network (kernel module) + USB/IP is a system for sharing USB devices over the network. + . + This package provides kernel modules for Linux _KVERS_. + --- usbip-0.1.7.orig/debian/modules/control +++ usbip-0.1.7/debian/modules/control @@ -0,0 +1,9 @@ +Source: usbip +Section: admin +Priority: optional +Maintainer: Max Vozeler +Build-Depends: debhelper (>= 7) +Standards-Version: 3.8.0 +Homepage: http://usbip.sourceforge.net/ +Vcs-Browser: http://git.debian.org/?p=users/xam/usbip.git +Vcs-Git: git://git.debian.org/~xam/usbip.git --- usbip-0.1.7.orig/debian/modules/docs +++ usbip-0.1.7/debian/modules/docs @@ -0,0 +1 @@ +src/README --- usbip-0.1.7.orig/src/README +++ usbip-0.1.7/src/README @@ -41,13 +41,13 @@ server:# usbipd -D - Start usbip daemon. - server:# bind_driver --list + server:# usbip_bind_driver --list - List driver assignments for usb devices. - server:# bind_driver --usbip 1-2 + server:# usbip_bind_driver --usbip 1-2 - Bind usbip.ko to the device of busid 1-2. - A usb device 1-2 is now exportable to other hosts! - - Use 'bind_driver --other 1-2' when you want to shutdown exporting + - Use 'usbip_bind_driver --other 1-2' when you want to shutdown exporting and use the device locally. @@ -83,7 +83,7 @@ "exportable"; the device is bound to usbip driver. Please remember you can not export a usb hub. - trois:# bind_driver --list + trois:# usbip_bind_driver --list List USB devices - busid 3-3.2 (04bb:0206) 3-3.2:1.0 -> usb-storage @@ -112,12 +112,12 @@ -------------------------------------------------------------------------------------------------------- Mark the device of busid 3-3.2 as exportable. - trois:# bind_driver --usbip 3-3.2 + trois:# usbip_bind_driver --usbip 3-3.2 ** (process:24621): DEBUG: 3-3.2:1.0 -> none ** (process:24621): DEBUG: write "add 3-3.2" to /sys/bus/usb/drivers/usbip/match_busid ** Message: bind 3-3.2 to usbip, complete! - trois:# bind_driver --list + trois:# usbip_bind_driver --list List USB devices - busid 3-3.2 (04bb:0206) 3-3.2:1.0 -> usbip --- usbip-0.1.7.orig/src/cmd/vhci_attach.c +++ usbip-0.1.7/src/cmd/vhci_attach.c @@ -84,9 +84,9 @@ char buff[MAX_BUFF+1]; int ret; - mkdir("/tmp/vhci_hcd", 0700); + mkdir(VHCI_STATE_PATH, 0700); - snprintf(path, PATH_MAX, "/tmp/vhci_hcd/port%d", rhport); + snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport); fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU); if (fd < 0) @@ -111,7 +111,7 @@ FILE *file; char path[PATH_MAX+1]; - snprintf(path, PATH_MAX, "/tmp/vhci_hcd/port%d", rhport); + snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport); file = fopen(path, "r"); if (!file) { --- usbip-0.1.7.orig/src/cmd/usbip.8 +++ usbip-0.1.7/src/cmd/usbip.8 @@ -0,0 +1,71 @@ +.TH USBIP "8" "February 2009" "usbip" "System Administration Utilities" +.SH NAME +usbip \- manage USB/IP devices +.SH SYNOPSIS +.B usbip +[\fIoptions\fR] + +.SH DESCRIPTION +Devices exported by USB/IP servers can be listed, attached and +detached using this program. + +.SH OPTIONS +.HP +\fB\-a\fR, \fB\-\-attach\fR +.IP +Attach a remote USB device. +.PP + +.HP +\fB\-x\fR, \fB\-\-attachall\fR +.IP +Attach all remote USB devices on the specific host. +.PP + +.HP +\fB\-d\fR, \fB\-\-detach\fR +.IP +Detach an imported USB device. +.PP + +.HP +\fB\-l\fR, \fB\-\-list\fR +.IP +List exported USB devices. +.PP + +.HP +\fB\-p\fR, \fB\-\-port\fR +.IP +List virtual USB port status. +.PP + +.HP +\fB\-D\fR, \fB\-\-debug\fR +.IP +Print debugging information. +.PP + +.HP +\fB\-v\fR, \fB\-\-version\fR +.IP +Show version. +.PP + +.SH EXAMPLES + + client:# usbip --list server + - List exportable usb devices on the server. + + client:# usbip --attach server 1-2 + - Connect the remote USB device. + + client:# usbip --port + - Show virtual port status. + + client:# usbip --detach 0 + - Detach the usb device. + +.SH "SEE ALSO" +\fBusbipd\fP\fB(8)\fB\fP, +\fBusbip_attach_driver\fP\fB(8)\fB\fP --- usbip-0.1.7.orig/src/cmd/bind-driver.c +++ usbip-0.1.7/src/cmd/bind-driver.c @@ -16,6 +16,7 @@ {"usbip", required_argument, NULL, 'u'}, {"other", required_argument, NULL, 'o'}, {"list", no_argument, NULL, 'l'}, + {"list2", no_argument, NULL, 'L'}, {"help", no_argument, NULL, 'h'}, #if 0 {"allusbip", no_argument, NULL, 'a'}, @@ -32,11 +33,12 @@ static void show_help(void) { - printf("Usage: bind-driver [OPTION]\n"); + printf("Usage: usbip_bind_driver [OPTION]\n"); printf("Change driver binding for USB/IP.\n"); printf(" --usbip busid make a device exportable\n"); printf(" --other busid use a device by a local driver\n"); printf(" --list print usb devices and their drivers\n"); + printf(" --list2 print usb devices and their drivers in parseable mode\n"); printf(" --allusbip make all devices exportable\n"); #if 0 @@ -378,6 +380,50 @@ return 0; } +static int show_devices2(void) +{ + DIR *dir; + + dir = opendir("/sys/bus/usb/devices/"); + if (!dir) + g_error("opendir: %s", strerror(errno)); + + for (;;) { + struct dirent *dirent; + char *busid; + + dirent = readdir(dir); + if (!dirent) + break; + + busid = dirent->d_name; + + if (is_usb_device(busid)) { + char name[100] = {'\0'}; + char driver[100] = {'\0'}; + int conf, ninf = 0; + int i; + + conf = read_bConfigurationValue(busid); + ninf = read_bNumInterfaces(busid); + + getdevicename(busid, name, sizeof(name)); + + printf("busid=%s#usbid=%s#", busid, name); + + for (i = 0; i < ninf; i++) { + getdriver(busid, conf, i, driver, sizeof(driver)); + printf("%s:%d.%d=%s#", busid, conf, i, driver); + } + printf("\n"); + } + } + + closedir(dir); + + return 0; +} + #if 0 static int export_to(char *host, char *busid) { @@ -504,6 +550,7 @@ cmd_use_by_usbip, cmd_use_by_other, cmd_list, + cmd_list2, cmd_allusbip, cmd_export_to, cmd_unexport, @@ -517,7 +564,7 @@ int c; int index = 0; - c = getopt_long(argc, argv, "u:o:hlae:x:b:", longopts, &index); + c = getopt_long(argc, argv, "u:o:hlLae:x:b:", longopts, &index); if (c == -1) break; @@ -533,6 +580,9 @@ case 'l' : cmd = cmd_list; break; + case 'L' : + cmd = cmd_list2; + break; case 'a' : cmd = cmd_allusbip; break; @@ -569,6 +619,9 @@ case cmd_list: show_devices(); break; + case cmd_list2: + show_devices2(); + break; #if 0 case cmd_allusbip: allusbip(); --- usbip-0.1.7.orig/src/cmd/usbip_bind_driver.8 +++ usbip-0.1.7/src/cmd/usbip_bind_driver.8 @@ -0,0 +1,42 @@ +.TH USBIP_BIND_DRIVER "8" "February 2009" "usbip" "System Administration Utilities" +.SH NAME +usbip_bind_driver \- change driver binding for USB/IP + +.SH SYNOPSIS +.B usbip_bind_driver +[\fIoptions\fR] + +.SH DESCRIPTION +Driver bindings for USB devices can be changed using +this program. It is used to export and unexport USB +devices over USB/IP. + +.SH OPTIONS +.TP +\fB\-u\fR, \fB\-\-usbip\fR +Make a device exportable +.TP +\fB\-o\fR, \fB\-\-other\fR +Use a device by a local driver +.TP +\fB\-l\fR, \fB\-\-list\fR +Print usb devices and their drivers +.TP +\fB\-L\fR, \fB\-\-list2\fR +Print usb devices and their drivers in parseable mode + +.SH EXAMPLES + + server:# usbip_bind_driver --list + - List driver assignments for usb devices. + + server:# usbip_bind_driver --usbip 1-2 + - Bind usbip.ko to the device of busid 1-2. + - A usb device 1-2 is now exportable to other hosts! + + server:# usbip_bind_driver --other 1-2 + - Shutdown exporting and use the device locally. + +.SH "SEE ALSO" +\fBusbip\fP\fB(8)\fB\fP, +\fBusbipd\fP\fB(8)\fB\fP --- usbip-0.1.7.orig/src/cmd/usbipd.8 +++ usbip-0.1.7/src/cmd/usbipd.8 @@ -0,0 +1,62 @@ +.TH USBIP "8" "February 2009" "usbip" "System Administration Utilities" +.SH NAME +usbipd \- USB/IP server daemon +.SH SYNOPSIS +.B usbipd +[\fIoptions\fR] + +.SH DESCRIPTION +.B usbipd +provides USB/IP clients access to exported USB devices. + +Devices have to explicitly be exported using +.B usbip_bind_driver +before usbipd makes them available to other hosts. + +The daemon accepts connections from USB/IP clients +on TCP port 3240. + +.SH OPTIONS +.HP +\fB\-D\fR, \fB\-\-daemon\fR +.IP +Run as a daemon process. +.PP + +.HP +\fB\-d\fR, \fB\-\-debug\fR +.IP +Print debugging information. +.PP + +.HP +\fB\-v\fR, \fB\-\-version\fR +.IP +Show version. +.PP + +.SH LIMITATIONS + +.B usbipd +offers no authentication or authorization for USB/IP. Any +USB/IP client can connect and use exported devices. + +.SH EXAMPLES + + server:# modprobe usbip + + server:# usbipd -D + - Start usbip daemon. + + server:# usbip_bind_driver --list + - List driver assignments for usb devices. + + server:# usbip_bind_driver --usbip 1-2 + - Bind usbip.ko to the device of busid 1-2. + - A usb device 1-2 is now exportable to other hosts! + - Use 'usbip_bind_driver --other 1-2' when you want to shutdown exporting and use the device locally. + +.SH "SEE ALSO" +\fBusbip\fP\fB(8)\fB\fP, +\fBusbip_attach_driver\fP\fB(8)\fB\fP + --- usbip-0.1.7.orig/src/cmd/Makefile.am +++ usbip-0.1.7/src/cmd/Makefile.am @@ -1,19 +1,21 @@ # $Id: Makefile.am 85 2009-01-13 17:10:51Z hirofuchi $ -bin_PROGRAMS = usbip usbipd bind_driver +sbin_PROGRAMS = usbip usbipd usbip_bind_driver + +dist_man_MANS = usbip.8 usbipd.8 usbip_bind_driver.8 usbip_SOURCES = vhci_attach.c usbip_network.c usbip_network.h usbipd_SOURCES = stub_server.c usbip_network.c usbip_network.h -bind_driver_SOURCES = bind-driver.c \ +usbip_bind_driver_SOURCES = bind-driver.c \ utils.c utils.h \ usbip_network.h usbip_network.c -#bind_driver_CFLAGS = -Wall -W -Wstrict-prototypes @PACKAGE_CFLAGS@ -#bind_driver_LDADD = @PACKAGE_LIBS@ +#usbip_bind_driver_CFLAGS = -Wall -W -Wstrict-prototypes @PACKAGE_CFLAGS@ +#usbip_bind_driver_LDADD = @PACKAGE_LIBS@ #AM_CPPFLAGS = -I../include -Wall -std=gnu99 INCLUDES = -I$(top_srcdir)/lib LDADD = ../lib/libusbip.la @PACKAGE_LIBS@ EXTRA_CFLAGS = @EXTRA_CFLAGS@ -AM_CFLAGS = -Wall -W -Wstrict-prototypes -std=gnu99 $(EXTRA_CFLAGS) @PACKAGE_CFLAGS@ +AM_CFLAGS = -Wall -W -Wstrict-prototypes -std=gnu99 $(EXTRA_CFLAGS) @PACKAGE_CFLAGS@ -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' --- usbip-0.1.7.orig/src/lib/Makefile.am +++ usbip-0.1.7/src/lib/Makefile.am @@ -5,6 +5,6 @@ #INCLUDES = -I../include #AM_CPPFLAGS = -I../include -Wall -std=gnu99 libusbip_la_LDFLAGS = -version-info 0:1:0 -EXTRA_CFLAGS = @EXTRA_CLFAGS@ -libusbip_la_CFLAGS = -Wall -W -Wstrict-prototypes -std=gnu99 $(EXTRA_CLFAGS) -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' +EXTRA_CFLAGS = @EXTRA_CFLAGS@ +libusbip_la_CFLAGS = -Wall -W -Wstrict-prototypes -std=gnu99 $(EXTRA_CFLAGS) -DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"' --- usbip-0.1.7.orig/src/lib/usbip_common.h +++ usbip-0.1.7/src/lib/usbip_common.h @@ -22,6 +22,9 @@ #define USBIDS_FILE "/usr/share/hwdata/usb.ids" #endif +#ifndef VHCI_STATE_PATH +#define VHCI_STATE_PATH "/var/run/vhci_hcd" +#endif //#include enum usb_device_speed { --- usbip-0.1.7.orig/drivers/head/vhci_rx.c +++ usbip-0.1.7/drivers/head/vhci_rx.c @@ -1,9 +1,6 @@ /* - * $Id: vhci_rx.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -24,50 +21,53 @@ #include "vhci.h" - /* get URB from transmitted urb queue */ -static struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum) +static struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, + __u32 seqnum) { struct vhci_priv *priv, *tmp; struct urb *urb = NULL; - + int status; spin_lock(&vdev->priv_lock); - list_for_each_entry_safe(priv, tmp, &vdev->priv_rx, list) { if (priv->seqnum == seqnum) { urb = priv->urb; - dbg_vhci_rx("find urb %p vurb %p seqnum %u\n", urb, priv, seqnum); + status = urb->status; + dbg_vhci_rx("find urb %p vurb %p seqnum %u\n", + urb, priv, seqnum); - if (urb->status != -EINPROGRESS) { - if (urb->status == -ENOENT || urb->status == -ECONNRESET) { - uinfo("urb %p was unlinked %ssynchronuously.\n", - urb, urb->status == -ENOENT ? "" : "a"); - } else { - uinfo("urb %p may be in a error, status %d\n", - urb, urb->status); - } + /* TODO: fix logic here to improve indent situtation */ + if (status != -EINPROGRESS) { + if (status == -ENOENT || + status == -ECONNRESET) + dev_info(&urb->dev->dev, + "urb %p was unlinked " + "%ssynchronuously.\n", urb, + status == -ENOENT ? "" : "a"); + else + dev_info(&urb->dev->dev, + "urb %p may be in a error, " + "status %d\n", urb, status); } - list_del(&priv->list); kfree(priv); urb->hcpriv = NULL; - break; } } spin_unlock(&vdev->priv_lock); - return urb; } -static void vhci_recv_ret_submit(struct vhci_device *vdev, struct usbip_header *pdu) +static void vhci_recv_ret_submit(struct vhci_device *vdev, + struct usbip_header *pdu) { struct usbip_device *ud = &vdev->ud; struct urb *urb; @@ -127,7 +127,8 @@ list_for_each_entry_safe(unlink, tmp, &vdev->unlink_rx, list) { uinfo("unlink->seqnum %lu\n", unlink->seqnum); if (unlink->seqnum == pdu->base.seqnum) { - dbg_vhci_rx("found pending unlink, %lu\n", unlink->seqnum); + dbg_vhci_rx("found pending unlink, %lu\n", + unlink->seqnum); list_del(&unlink->list); spin_unlock(&vdev->priv_lock); @@ -141,7 +142,8 @@ } -static void vhci_recv_ret_unlink(struct vhci_device *vdev, struct usbip_header *pdu) +static void vhci_recv_ret_unlink(struct vhci_device *vdev, + struct usbip_header *pdu) { struct vhci_unlink *unlink; struct urb *urb; @@ -161,7 +163,8 @@ * already received the result of its submit result and gave * back the URB. */ - uinfo("the urb (seqnum %d) was already given backed\n", pdu->base.seqnum); + uinfo("the urb (seqnum %d) was already given backed\n", + pdu->base.seqnum); } else { dbg_vhci_rx("now giveback urb %p\n", urb); @@ -173,7 +176,8 @@ usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); spin_unlock(&the_controller->lock); - usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); + usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, + urb->status); } kfree(unlink); @@ -195,10 +199,10 @@ /* 1. receive a pdu header */ - ret = usbip_xmit(0, ud->tcp_socket, (char *) &pdu, sizeof(pdu),0); + ret = usbip_xmit(0, ud->tcp_socket, (char *) &pdu, sizeof(pdu), 0); if (ret != sizeof(pdu)) { uerr("receiving pdu failed! size is %d, should be %d\n", - ret, sizeof(pdu)); + ret, (unsigned int)sizeof(pdu)); usbip_event_add(ud, VDEV_EVENT_ERROR_TCP); return; } @@ -208,19 +212,18 @@ if (dbg_flag_vhci_rx) usbip_dump_header(&pdu); - switch(pdu.base.command) { - case USBIP_RET_SUBMIT: - vhci_recv_ret_submit(vdev, &pdu); - break; - - case USBIP_RET_UNLINK: - vhci_recv_ret_unlink(vdev, &pdu); - break; - default: - /* NOTREACHED */ - uerr("unknown pdu %u\n", pdu.base.command); - usbip_dump_header(&pdu); - usbip_event_add(ud, VDEV_EVENT_ERROR_TCP); + switch (pdu.base.command) { + case USBIP_RET_SUBMIT: + vhci_recv_ret_submit(vdev, &pdu); + break; + case USBIP_RET_UNLINK: + vhci_recv_ret_unlink(vdev, &pdu); + break; + default: + /* NOTREACHED */ + uerr("unknown pdu %u\n", pdu.base.command); + usbip_dump_header(&pdu); + usbip_event_add(ud, VDEV_EVENT_ERROR_TCP); } } @@ -239,7 +242,8 @@ } - if (usbip_event_happend(ud)) break; + if (usbip_event_happend(ud)) + break; vhci_rx_pdu(ud); } --- usbip-0.1.7.orig/drivers/head/usbip_common.c +++ usbip-0.1.7/drivers/head/usbip_common.c @@ -1,9 +1,6 @@ /* - * $Id: usbip_common.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -27,7 +24,7 @@ #include "usbip_common.h" /* version information */ -#define DRIVER_VERSION "$Id: usbip_common.c 66 2008-04-20 13:19:42Z hirofuchi $" +#define DRIVER_VERSION "1.0" #define DRIVER_AUTHOR "Takahiro Hirofuchi " #define DRIVER_DESC "usbip common driver" @@ -37,17 +34,18 @@ #ifdef CONFIG_USB_DEBUG unsigned long usbip_debug_flag = 0xffffffff; #else -unsigned long usbip_debug_flag = 0; +unsigned long usbip_debug_flag; #endif -EXPORT_SYMBOL(usbip_debug_flag); +EXPORT_SYMBOL_GPL(usbip_debug_flag); /* FIXME */ struct device_attribute dev_attr_usbip_debug; -EXPORT_SYMBOL(dev_attr_usbip_debug); +EXPORT_SYMBOL_GPL(dev_attr_usbip_debug); -static ssize_t show_flag(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t show_flag(struct device *dev, struct device_attribute *attr, + char *buf) { return sprintf(buf, "%lx\n", usbip_debug_flag); } @@ -69,21 +67,23 @@ int i; if (bufflen > 128) { - for (i = 0; i< 128; i++) { + for (i = 0; i < 128; i++) { if (i%24 == 0) printk(" "); - printk("%02x ", (unsigned char ) buff[i]); - if (i%4 == 3) printk("| "); - if (i%24 == 23) printk("\n"); + printk("%02x ", (unsigned char) buff[i]); + if (i%4 == 3) + printk("| "); + if (i%24 == 23) + printk("\n"); } printk("... (%d byte)\n", bufflen); return; } - for (i = 0; i< bufflen; i++) { + for (i = 0; i < bufflen; i++) { if (i%24 == 0) printk(" "); - printk("%02x ", (unsigned char ) buff[i]); + printk("%02x ", (unsigned char) buff[i]); if (i%4 == 3) printk("| "); if (i%24 == 23) @@ -104,135 +104,124 @@ printk("ep(%d) ", ep); printk("%s ", dir ? "IN" : "OUT"); - switch(type) { - case PIPE_ISOCHRONOUS : - printk("%s ", "ISO"); - break; - case PIPE_INTERRUPT : - printk("%s ", "INT"); - break; - case PIPE_CONTROL : - printk("%s ", "CTL"); - break; - case PIPE_BULK : - printk("%s ", "BLK"); - break; - default : - printk("ERR"); + switch (type) { + case PIPE_ISOCHRONOUS: + printk("%s ", "ISO"); + break; + case PIPE_INTERRUPT: + printk("%s ", "INT"); + break; + case PIPE_CONTROL: + printk("%s ", "CTL"); + break; + case PIPE_BULK: + printk("%s ", "BLK"); + break; + default: + printk("ERR"); } printk("\n"); } -static void usbip_dump_usb_device(struct usb_device *dev) +static void usbip_dump_usb_device(struct usb_device *udev) { + struct device *dev = &udev->dev; int i; - if (!dev) { - printk(" dump usb dev: null pointer!!\n"); - return; - } - - printk(" devnum(%d) devpath(%s)", dev->devnum, dev->devpath); + dev_dbg(dev, " devnum(%d) devpath(%s)", + udev->devnum, udev->devpath); - switch(dev->speed) { - case USB_SPEED_HIGH : - printk(" SPD_HIGH"); - break; - case USB_SPEED_FULL : - printk(" SPD_FULL"); - break; - case USB_SPEED_LOW : - printk(" SPD_LOW"); - break; - case USB_SPEED_UNKNOWN : - printk(" SPD_UNKNOWN"); - break; - default : - printk(" SPD_ERROR"); + switch (udev->speed) { + case USB_SPEED_HIGH: + printk(" SPD_HIGH"); + break; + case USB_SPEED_FULL: + printk(" SPD_FULL"); + break; + case USB_SPEED_LOW: + printk(" SPD_LOW"); + break; + case USB_SPEED_UNKNOWN: + printk(" SPD_UNKNOWN"); + break; + default: + printk(" SPD_ERROR"); } - printk(" tt %p, ttport %d", dev->tt, dev->ttport); + printk(" tt %p, ttport %d", udev->tt, udev->ttport); printk("\n"); - printk(" "); - for (i = 0; i < 16; i++) { + dev_dbg(dev, " "); + for (i = 0; i < 16; i++) printk(" %2u", i); - } - printk("\n"); - printk(" toggle0(IN) :"); - for (i = 0; i< 16; i++) { - printk(" %2u", ( dev->toggle[0] & (1 << i) ) ? 1 : 0); - } - + dev_dbg(dev, " toggle0(IN) :"); + for (i = 0; i < 16; i++) + printk(" %2u", (udev->toggle[0] & (1 << i)) ? 1 : 0); printk("\n"); - printk(" toggle1(OUT):"); - for (i = 0; i< 16; i++) { - printk(" %2u", ( dev->toggle[1] & (1 << i) ) ? 1 : 0); - } - + dev_dbg(dev, " toggle1(OUT):"); + for (i = 0; i < 16; i++) + printk(" %2u", (udev->toggle[1] & (1 << i)) ? 1 : 0); printk("\n"); - printk(" epmaxp_in :"); + dev_dbg(dev, " epmaxp_in :"); for (i = 0; i < 16; i++) { - if (dev->ep_in[i]) - printk(" %2u", dev->ep_in[i]->desc.wMaxPacketSize); + if (udev->ep_in[i]) + printk(" %2u", + le16_to_cpu(udev->ep_in[i]->desc.wMaxPacketSize)); } - printk("\n"); - printk(" epmaxp_out :"); + dev_dbg(dev, " epmaxp_out :"); for (i = 0; i < 16; i++) { - if (dev->ep_out[i]) - printk(" %2u", dev->ep_out[i]->desc.wMaxPacketSize); + if (udev->ep_out[i]) + printk(" %2u", + le16_to_cpu(udev->ep_out[i]->desc.wMaxPacketSize)); } + printk("\n"); - printk("\n "); - - printk("parent %p, bus %p", dev->parent, dev->bus); - printk("\n "); - - printk("descriptor %p, config %p, actconfig %p, rawdescriptors %p", - &dev->descriptor, dev->config, dev->actconfig, dev->rawdescriptors); - printk("\n "); + dev_dbg(dev, "parent %p, bus %p\n", udev->parent, udev->bus); - printk("have_langid %d, string_langid %d", dev->have_langid, dev->string_langid); - printk("\n "); + dev_dbg(dev, "descriptor %p, config %p, actconfig %p, " + "rawdescriptors %p\n", &udev->descriptor, udev->config, + udev->actconfig, udev->rawdescriptors); - printk("maxchild %d, children %p", dev->maxchild, dev->children); + dev_dbg(dev, "have_langid %d, string_langid %d\n", + udev->have_langid, udev->string_langid); - printk("\n"); + dev_dbg(dev, "maxchild %d, children %p\n", + udev->maxchild, udev->children); } static void usbip_dump_request_type(__u8 rt) { - switch(rt & USB_RECIP_MASK) { - case USB_RECIP_DEVICE: - printk("DEVICE"); - break; - case USB_RECIP_INTERFACE: - printk("INTERF"); - break; - case USB_RECIP_ENDPOINT: - printk("ENDPOI"); - break; - case USB_RECIP_OTHER: - printk("OTHER "); - break; - default: - printk("------"); + switch (rt & USB_RECIP_MASK) { + case USB_RECIP_DEVICE: + printk("DEVICE"); + break; + case USB_RECIP_INTERFACE: + printk("INTERF"); + break; + case USB_RECIP_ENDPOINT: + printk("ENDPOI"); + break; + case USB_RECIP_OTHER: + printk("OTHER "); + break; + default: + printk("------"); } } static void usbip_dump_usb_ctrlrequest(struct usb_ctrlrequest *cmd) { if (!cmd) { - printk(" %s : null pointer\n", __FUNCTION__); + printk(" %s : null pointer\n", __func__); return; } @@ -247,42 +236,42 @@ if ((cmd->bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) { printk("STANDARD "); - switch(cmd->bRequest) { - case USB_REQ_GET_STATUS: - printk("GET_STATUS"); - break; - case USB_REQ_CLEAR_FEATURE: - printk("CLEAR_FEAT"); - break; - case USB_REQ_SET_FEATURE: - printk("SET_FEAT "); - break; - case USB_REQ_SET_ADDRESS: - printk("SET_ADDRRS"); - break; - case USB_REQ_GET_DESCRIPTOR: - printk("GET_DESCRI"); - break; - case USB_REQ_SET_DESCRIPTOR: - printk("SET_DESCRI"); - break; - case USB_REQ_GET_CONFIGURATION: - printk("GET_CONFIG"); - break; - case USB_REQ_SET_CONFIGURATION: - printk("SET_CONFIG"); - break; - case USB_REQ_GET_INTERFACE: - printk("GET_INTERF"); - break; - case USB_REQ_SET_INTERFACE: - printk("SET_INTERF"); - break; - case USB_REQ_SYNCH_FRAME: - printk("SYNC_FRAME"); - break; - default: - printk("REQ(%02X) ", cmd->bRequest); + switch (cmd->bRequest) { + case USB_REQ_GET_STATUS: + printk("GET_STATUS"); + break; + case USB_REQ_CLEAR_FEATURE: + printk("CLEAR_FEAT"); + break; + case USB_REQ_SET_FEATURE: + printk("SET_FEAT "); + break; + case USB_REQ_SET_ADDRESS: + printk("SET_ADDRRS"); + break; + case USB_REQ_GET_DESCRIPTOR: + printk("GET_DESCRI"); + break; + case USB_REQ_SET_DESCRIPTOR: + printk("SET_DESCRI"); + break; + case USB_REQ_GET_CONFIGURATION: + printk("GET_CONFIG"); + break; + case USB_REQ_SET_CONFIGURATION: + printk("SET_CONFIG"); + break; + case USB_REQ_GET_INTERFACE: + printk("GET_INTERF"); + break; + case USB_REQ_SET_INTERFACE: + printk("SET_INTERF"); + break; + case USB_REQ_SYNCH_FRAME: + printk("SYNC_FRAME"); + break; + default: + printk("REQ(%02X) ", cmd->bRequest); } printk(" "); @@ -300,40 +289,51 @@ printk("\n"); } -void usbip_dump_urb (struct urb *purb) +void usbip_dump_urb(struct urb *urb) { - if (!purb) { - printk(" dump urb: null pointer!!\n"); + struct device *dev; + + if (!urb) { + printk(KERN_DEBUG KBUILD_MODNAME + ":%s: urb: null pointer!!\n", __func__); + return; + } + + if (!urb->dev) { + printk(KERN_DEBUG KBUILD_MODNAME + ":%s: urb->dev: null pointer!!\n", __func__); return; } + dev = &urb->dev->dev; - printk(" urb :%p\n", purb); - printk(" dev :%p\n", purb->dev); + dev_dbg(dev, " urb :%p\n", urb); + dev_dbg(dev, " dev :%p\n", urb->dev); - usbip_dump_usb_device(purb->dev); + usbip_dump_usb_device(urb->dev); - printk(" pipe :%08x ", purb->pipe); + dev_dbg(dev, " pipe :%08x ", urb->pipe); - usbip_dump_pipe(purb->pipe); + usbip_dump_pipe(urb->pipe); - printk(" status :%d\n", purb->status); - printk(" transfer_flags :%08X\n", purb->transfer_flags); - printk(" transfer_buffer :%p\n", purb->transfer_buffer); - printk(" transfer_buffer_length:%d\n", purb->transfer_buffer_length); - printk(" actual_length :%d\n", purb->actual_length); - printk(" setup_packet :%p\n", purb->setup_packet); + dev_dbg(dev, " status :%d\n", urb->status); + dev_dbg(dev, " transfer_flags :%08X\n", urb->transfer_flags); + dev_dbg(dev, " transfer_buffer :%p\n", urb->transfer_buffer); + dev_dbg(dev, " transfer_buffer_length:%d\n", urb->transfer_buffer_length); + dev_dbg(dev, " actual_length :%d\n", urb->actual_length); + dev_dbg(dev, " setup_packet :%p\n", urb->setup_packet); - if (purb->setup_packet && usb_pipetype(purb->pipe) == PIPE_CONTROL) - usbip_dump_usb_ctrlrequest((struct usb_ctrlrequest *) purb->setup_packet); + if (urb->setup_packet && usb_pipetype(urb->pipe) == PIPE_CONTROL) + usbip_dump_usb_ctrlrequest( + (struct usb_ctrlrequest *)urb->setup_packet); - printk(" start_frame :%d\n", purb->start_frame); - printk(" number_of_packets :%d\n", purb->number_of_packets); - printk(" interval :%d\n", purb->interval); - printk(" error_count :%d\n", purb->error_count); - printk(" context :%p\n", purb->context); - printk(" complete :%p\n", purb->complete); + dev_dbg(dev, " start_frame :%d\n", urb->start_frame); + dev_dbg(dev, " number_of_packets :%d\n", urb->number_of_packets); + dev_dbg(dev, " interval :%d\n", urb->interval); + dev_dbg(dev, " error_count :%d\n", urb->error_count); + dev_dbg(dev, " context :%p\n", urb->context); + dev_dbg(dev, " complete :%p\n", urb->complete); } -EXPORT_SYMBOL(usbip_dump_urb); +EXPORT_SYMBOL_GPL(usbip_dump_urb); void usbip_dump_header(struct usbip_header *pdu) { @@ -344,33 +344,33 @@ pdu->base.direction, pdu->base.ep); - switch(pdu->base.command) { - case USBIP_CMD_SUBMIT: - udbg("CMD_SUBMIT: x_flags %u x_len %u sf %u #p %u iv %u\n", - pdu->u.cmd_submit.transfer_flags, - pdu->u.cmd_submit.transfer_buffer_length, - pdu->u.cmd_submit.start_frame, - pdu->u.cmd_submit.number_of_packets, - pdu->u.cmd_submit.interval); - break; - case USBIP_CMD_UNLINK: - udbg("CMD_UNLINK: seq %u\n", pdu->u.cmd_unlink.seqnum); - break; - case USBIP_RET_SUBMIT: - udbg("RET_SUBMIT: st %d al %u sf %d ec %d\n", - pdu->u.ret_submit.status, - pdu->u.ret_submit.actual_length, - pdu->u.ret_submit.start_frame, - pdu->u.ret_submit.error_count); - case USBIP_RET_UNLINK: - udbg("RET_UNLINK: status %d\n", pdu->u.ret_unlink.status); - break; - default: - /* NOT REACHED */ - udbg("UNKNOWN\n"); + switch (pdu->base.command) { + case USBIP_CMD_SUBMIT: + udbg("CMD_SUBMIT: x_flags %u x_len %u sf %u #p %u iv %u\n", + pdu->u.cmd_submit.transfer_flags, + pdu->u.cmd_submit.transfer_buffer_length, + pdu->u.cmd_submit.start_frame, + pdu->u.cmd_submit.number_of_packets, + pdu->u.cmd_submit.interval); + break; + case USBIP_CMD_UNLINK: + udbg("CMD_UNLINK: seq %u\n", pdu->u.cmd_unlink.seqnum); + break; + case USBIP_RET_SUBMIT: + udbg("RET_SUBMIT: st %d al %u sf %d ec %d\n", + pdu->u.ret_submit.status, + pdu->u.ret_submit.actual_length, + pdu->u.ret_submit.start_frame, + pdu->u.ret_submit.error_count); + case USBIP_RET_UNLINK: + udbg("RET_UNLINK: status %d\n", pdu->u.ret_unlink.status); + break; + default: + /* NOT REACHED */ + udbg("UNKNOWN\n"); } } -EXPORT_SYMBOL(usbip_dump_header); +EXPORT_SYMBOL_GPL(usbip_dump_header); /*-------------------------------------------------------------------------*/ @@ -378,7 +378,7 @@ int usbip_thread(void *param) { - struct usbip_task *ut = (struct usbip_task *) param; + struct usbip_task *ut = param; if (!ut) return -EINVAL; @@ -406,18 +406,18 @@ /* * threads are invoked per one device (per one connection). */ - kernel_thread((int(*)(void *))usbip_thread, (void *)&ud->tcp_rx, 0); - kernel_thread((int(*)(void *))usbip_thread, (void *)&ud->tcp_tx, 0); + kernel_thread(usbip_thread, (void *)&ud->tcp_rx, 0); + kernel_thread(usbip_thread, (void *)&ud->tcp_tx, 0); /* confirm threads are starting */ wait_for_completion(&ud->tcp_rx.thread_done); wait_for_completion(&ud->tcp_tx.thread_done); } -EXPORT_SYMBOL(usbip_start_threads); +EXPORT_SYMBOL_GPL(usbip_start_threads); void usbip_stop_threads(struct usbip_device *ud) { - /* kill threads related to this sdev, if v.c. exists */ + /* kill threads related to this sdev, if v.c. exists */ if (ud->tcp_rx.thread != NULL) { send_sig(SIGKILL, ud->tcp_rx.thread, 1); wait_for_completion(&ud->tcp_rx.thread_done); @@ -430,7 +430,7 @@ udbg("tx_thread for ud %p has finished\n", ud); } } -EXPORT_SYMBOL(usbip_stop_threads); +EXPORT_SYMBOL_GPL(usbip_stop_threads); void usbip_task_init(struct usbip_task *ut, char *name, void (*loop_ops)(struct usbip_task *)) @@ -440,14 +440,15 @@ ut->name = name; ut->loop_ops = loop_ops; } -EXPORT_SYMBOL(usbip_task_init); +EXPORT_SYMBOL_GPL(usbip_task_init); /*-------------------------------------------------------------------------*/ /* socket routines */ /* Send/receive messages over TCP/IP. I refer drivers/block/nbd.c */ -int usbip_xmit(int send, struct socket *sock, char *buf, int size, int msg_flags) +int usbip_xmit(int send, struct socket *sock, char *buf, + int size, int msg_flags) { int result; struct msghdr msg; @@ -456,13 +457,13 @@ /* for blocks of if (dbg_flag_xmit) */ char *bp = buf; - int osize= size; + int osize = size; dbg_xmit("enter\n"); if (!sock || !buf || !size) { - uerr("usbip_xmit: invalid arg, sock %p buff %p size %d\n", - sock, buf, size); + printk(KERN_ERR "%s: invalid arg, sock %p buff %p size %d\n", + __func__, sock, buf, size); return -EINVAL; } @@ -474,8 +475,9 @@ else printk(KERN_DEBUG "interupt :"); - printk("usbip_xmit: sending... , sock %p, buf %p, size %d, msg_flags %d\n", - sock, buf, size, msg_flags); + printk("%s: sending... , sock %p, buf %p, " + "size %d, msg_flags %d\n", __func__, + sock, buf, size, msg_flags); usbip_dump_buffer(buf, size); } } @@ -495,11 +497,14 @@ if (send) result = kernel_sendmsg(sock, &msg, &iov, 1, size); else - result = kernel_recvmsg(sock, &msg, &iov, 1, size, MSG_WAITALL); + result = kernel_recvmsg(sock, &msg, &iov, 1, size, + MSG_WAITALL); if (result <= 0) { - udbg("usbip_xmit: %s sock %p buf %p size %u ret %d total %d\n", - send ? "send" : "receive", sock, buf, size, result, total); + udbg("usbip_xmit: %s sock %p buf %p size %u ret %d" + " total %d\n", + send ? "send" : "receive", sock, buf, + size, result, total); goto err; } @@ -519,13 +524,13 @@ printk("usbip_xmit: receiving....\n"); usbip_dump_buffer(bp, osize); - printk("usbip_xmit: received, osize %d ret %d size %d total %d\n", - osize, result, size, total); + printk("usbip_xmit: received, osize %d ret %d size %d " + "total %d\n", osize, result, size, + total); } - if (send) { + if (send) printk("usbip_xmit: send, total %d\n", total); - } } return total; @@ -533,7 +538,7 @@ err: return result; } -EXPORT_SYMBOL(usbip_xmit); +EXPORT_SYMBOL_GPL(usbip_xmit); /* now a usrland utility should set options. */ @@ -597,7 +602,7 @@ file = fget(sockfd); if (!file) { - uerr("invalid sockfd\n"); + printk(KERN_ERR "%s: invalid sockfd\n", __func__); return NULL; } @@ -610,7 +615,7 @@ return socket; } -EXPORT_SYMBOL(sockfd_to_socket); +EXPORT_SYMBOL_GPL(sockfd_to_socket); @@ -636,7 +641,8 @@ return flags; } -static void usbip_pack_cmd_submit(struct usbip_header *pdu, struct urb *urb, int pack) +static void usbip_pack_cmd_submit(struct usbip_header *pdu, struct urb *urb, + int pack) { struct usbip_header_cmd_submit *spdu = &pdu->u.cmd_submit; @@ -646,8 +652,8 @@ */ if (pack) { /* vhci_tx.c */ - spdu->transfer_flags = tweak_transfer_flags(urb->transfer_flags); - + spdu->transfer_flags = + tweak_transfer_flags(urb->transfer_flags); spdu->transfer_buffer_length = urb->transfer_buffer_length; spdu->start_frame = urb->start_frame; spdu->number_of_packets = urb->number_of_packets; @@ -663,7 +669,8 @@ } } -static void usbip_pack_ret_submit(struct usbip_header *pdu, struct urb *urb, int pack) +static void usbip_pack_ret_submit(struct usbip_header *pdu, struct urb *urb, + int pack) { struct usbip_header_ret_submit *rpdu = &pdu->u.ret_submit; @@ -685,22 +692,23 @@ } -void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, int pack) +void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, + int pack) { - switch(cmd) { - case USBIP_CMD_SUBMIT: - usbip_pack_cmd_submit(pdu, urb, pack); - break; - case USBIP_RET_SUBMIT: - usbip_pack_ret_submit(pdu, urb, pack); - break; - default: - err("unknown command"); - /* NOTREACHED */ - //BUG(); + switch (cmd) { + case USBIP_CMD_SUBMIT: + usbip_pack_cmd_submit(pdu, urb, pack); + break; + case USBIP_RET_SUBMIT: + usbip_pack_ret_submit(pdu, urb, pack); + break; + default: + err("unknown command"); + /* NOTREACHED */ + /* BUG(); */ } } -EXPORT_SYMBOL(usbip_pack_pdu); +EXPORT_SYMBOL_GPL(usbip_pack_pdu); static void correct_endian_basic(struct usbip_header_basic *base, int send) @@ -720,7 +728,8 @@ } } -static void correct_endian_cmd_submit(struct usbip_header_cmd_submit *pdu, int send) +static void correct_endian_cmd_submit(struct usbip_header_cmd_submit *pdu, + int send) { if (send) { pdu->transfer_flags = cpu_to_be32(pdu->transfer_flags); @@ -739,7 +748,8 @@ } } -static void correct_endian_ret_submit(struct usbip_header_ret_submit *pdu, int send) +static void correct_endian_ret_submit(struct usbip_header_ret_submit *pdu, + int send) { if (send) { cpu_to_be32s(&pdu->status); @@ -754,7 +764,8 @@ } } -static void correct_endian_cmd_unlink(struct usbip_header_cmd_unlink *pdu, int send) +static void correct_endian_cmd_unlink(struct usbip_header_cmd_unlink *pdu, + int send) { if (send) pdu->seqnum = cpu_to_be32(pdu->seqnum); @@ -762,7 +773,8 @@ pdu->seqnum = be32_to_cpu(pdu->seqnum); } -static void correct_endian_ret_unlink(struct usbip_header_ret_unlink *pdu, int send) +static void correct_endian_ret_unlink(struct usbip_header_ret_unlink *pdu, + int send) { if (send) cpu_to_be32s(&pdu->status); @@ -783,29 +795,29 @@ cmd = pdu->base.command; switch (cmd) { - case USBIP_CMD_SUBMIT: - correct_endian_cmd_submit(&pdu->u.cmd_submit, send); - break; - case USBIP_RET_SUBMIT: - correct_endian_ret_submit(&pdu->u.ret_submit, send); - break; - - case USBIP_CMD_UNLINK: - correct_endian_cmd_unlink(&pdu->u.cmd_unlink, send); - break; - case USBIP_RET_UNLINK: - correct_endian_ret_unlink(&pdu->u.ret_unlink, send); - break; - - default: - /* NOTREACHED */ - err("unknown command in pdu header: %d", cmd); - //BUG(); - } -} -EXPORT_SYMBOL(usbip_header_correct_endian); - -static void usbip_iso_pakcet_correct_endian(struct usbip_iso_packet_descriptor *iso, int send) + case USBIP_CMD_SUBMIT: + correct_endian_cmd_submit(&pdu->u.cmd_submit, send); + break; + case USBIP_RET_SUBMIT: + correct_endian_ret_submit(&pdu->u.ret_submit, send); + break; + case USBIP_CMD_UNLINK: + correct_endian_cmd_unlink(&pdu->u.cmd_unlink, send); + break; + case USBIP_RET_UNLINK: + correct_endian_ret_unlink(&pdu->u.ret_unlink, send); + break; + default: + /* NOTREACHED */ + err("unknown command in pdu header: %d", cmd); + /* BUG(); */ + } +} +EXPORT_SYMBOL_GPL(usbip_header_correct_endian); + +static void usbip_iso_pakcet_correct_endian( + struct usbip_iso_packet_descriptor *iso, + int send) { /* does not need all members. but copy all simply. */ if (send) { @@ -862,7 +874,7 @@ return buff; } -EXPORT_SYMBOL(usbip_alloc_iso_desc_pdu); +EXPORT_SYMBOL_GPL(usbip_alloc_iso_desc_pdu); /* some members of urb must be substituted before. */ int usbip_recv_iso(struct usbip_device *ud, struct urb *urb) @@ -879,8 +891,8 @@ /* my Bluetooth dongle gets ISO URBs which are np = 0 */ if (np == 0) { - //uinfo("iso np == 0\n"); - //usbip_dump_urb(urb); + /* uinfo("iso np == 0\n"); */ + /* usbip_dump_urb(urb); */ return 0; } @@ -890,7 +902,8 @@ ret = usbip_xmit(0, ud->tcp_socket, buff, size, 0); if (ret != size) { - uerr("recv iso_frame_descriptor, %d\n", ret); + dev_err(&urb->dev->dev, "recv iso_frame_descriptor, %d\n", + ret); kfree(buff); if (ud->side == USBIP_STUB) @@ -913,7 +926,7 @@ return ret; } -EXPORT_SYMBOL(usbip_recv_iso); +EXPORT_SYMBOL_GPL(usbip_recv_iso); /* some members of urb must be substituted before. */ @@ -942,9 +955,10 @@ if (!(size > 0)) return 0; - ret = usbip_xmit(0, ud->tcp_socket, (char *) urb->transfer_buffer, size, 0); + ret = usbip_xmit(0, ud->tcp_socket, (char *)urb->transfer_buffer, + size, 0); if (ret != size) { - uerr("recv xbuf, %d\n", ret); + dev_err(&urb->dev->dev, "recv xbuf, %d\n", ret); if (ud->side == USBIP_STUB) { usbip_event_add(ud, SDEV_EVENT_ERROR_TCP); } else { @@ -955,14 +969,14 @@ return ret; } -EXPORT_SYMBOL(usbip_recv_xbuff); +EXPORT_SYMBOL_GPL(usbip_recv_xbuff); /*-------------------------------------------------------------------------*/ static int __init usbip_common_init(void) { - info(DRIVER_DESC "" DRIVER_VERSION); + printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "" DRIVER_VERSION); return 0; } --- usbip-0.1.7.orig/drivers/head/stub_main.c +++ usbip-0.1.7/drivers/head/stub_main.c @@ -1,9 +1,6 @@ /* - * $Id: stub_main.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -25,15 +22,12 @@ #include "stub.h" /* Version Information */ -#define DRIVER_VERSION "$Id: stub_main.c 66 2008-04-20 13:19:42Z hirofuchi $" +#define DRIVER_VERSION "1.0" #define DRIVER_AUTHOR "Takahiro Hirofuchi" #define DRIVER_DESC "Stub Driver for USB/IP" - - /* stub_priv is allocated from stub_priv_cache */ -struct kmem_cache *stub_priv_cache = NULL; - +struct kmem_cache *stub_priv_cache; /*-------------------------------------------------------------------------*/ @@ -164,7 +158,8 @@ return -EINVAL; } -static DRIVER_ATTR(match_busid, S_IRUSR|S_IWUSR, show_match_busid, store_match_busid); +static DRIVER_ATTR(match_busid, S_IRUSR|S_IWUSR, show_match_busid, + store_match_busid); @@ -244,41 +239,49 @@ { int ret; - stub_priv_cache = kmem_cache_create("stub_priv", sizeof(struct stub_priv), - 0, SLAB_HWCACHE_ALIGN, NULL); + stub_priv_cache = kmem_cache_create("stub_priv", + sizeof(struct stub_priv), 0, + SLAB_HWCACHE_ALIGN, NULL); if (!stub_priv_cache) { - uerr("create stub_priv_cache\n"); + printk(KERN_ERR KBUILD_MODNAME + ": create stub_priv_cache error\n"); return -ENOMEM; } ret = usb_register(&stub_driver); if (ret) { - uerr("usb_register failed %d\n", ret); - return ret; + printk(KERN_ERR KBUILD_MODNAME ": usb_register failed %d\n", + ret); + goto error_usb_register; } - - info(DRIVER_DESC "" DRIVER_VERSION); + printk(KERN_INFO KBUILD_MODNAME ":" + DRIVER_DESC ":" DRIVER_VERSION "\n"); memset(busid_table, 0, sizeof(busid_table)); spin_lock_init(&busid_table_lock); - ret = driver_create_file(&stub_driver.drvwrap.driver, &driver_attr_match_busid); + ret = driver_create_file(&stub_driver.drvwrap.driver, + &driver_attr_match_busid); if (ret) { - uerr("create driver sysfs\n"); - return ret; + printk(KERN_ERR KBUILD_MODNAME ": create driver sysfs\n"); + goto error_create_file; } return ret; +error_create_file: + usb_deregister(&stub_driver); +error_usb_register: + kmem_cache_destroy(stub_priv_cache); + return ret; } static void __exit usb_stub_exit(void) { - udbg("enter\n"); - - driver_remove_file(&stub_driver.drvwrap.driver, &driver_attr_match_busid); + driver_remove_file(&stub_driver.drvwrap.driver, + &driver_attr_match_busid); /* * deregister() calls stub_disconnect() for all devices. Device @@ -287,15 +290,10 @@ usb_deregister(&stub_driver); kmem_cache_destroy(stub_priv_cache); - - udbg("bye\n"); } - - - -module_init (usb_stub_init); -module_exit (usb_stub_exit); +module_init(usb_stub_init); +module_exit(usb_stub_exit); MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); --- usbip-0.1.7.orig/drivers/head/vhci_hcd.c +++ usbip-0.1.7/drivers/head/vhci_hcd.c @@ -1,9 +1,6 @@ /* - * $Id: vhci_hcd.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -24,7 +21,7 @@ #include "usbip_common.h" #include "vhci.h" -#define DRIVER_VERSION " $Id: vhci_hcd.c 66 2008-04-20 13:19:42Z hirofuchi $ " +#define DRIVER_VERSION "1.0" #define DRIVER_AUTHOR "Takahiro Hirofuchi" #define DRIVER_DESC "Virtual Host Controller Interface Driver for USB/IP" #define DRIVER_LICENCE "GPL" @@ -48,10 +45,11 @@ /* See usb gadget dummy hcd */ -static int vhci_hub_status (struct usb_hcd *hcd, char *buff); +static int vhci_hub_status(struct usb_hcd *hcd, char *buff); static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buff, u16 wLength); -static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags); +static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, + gfp_t mem_flags); static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status); static int vhci_start(struct usb_hcd *vhci_hcd); static void vhci_stop(struct usb_hcd *hcd); @@ -60,11 +58,7 @@ static const char driver_name[] = "vhci_hcd"; static const char driver_desc[] = "USB/IP Virtual Host Contoroller"; - - - -struct vhci_hcd *the_controller = NULL; - +struct vhci_hcd *the_controller; static const char *bit_desc[] = { "CONNECTION", /*0*/ @@ -106,11 +100,10 @@ { int i = 0; - printk("status %08x:", status); + printk(KERN_DEBUG "status %08x:", status); for (i = 0; i < 32; i++) { - if (status & (1 << i)) { + if (status & (1 << i)) printk(" %s", bit_desc[i]); - } } printk("\n"); @@ -130,19 +123,19 @@ | (1 << USB_PORT_FEAT_C_CONNECTION); switch (speed) { - case USB_SPEED_HIGH: - the_controller->port_status[rhport] |= USB_PORT_STAT_HIGH_SPEED; - break; - case USB_SPEED_LOW: - the_controller->port_status[rhport] |= USB_PORT_STAT_LOW_SPEED; - break; - default: - break; + case USB_SPEED_HIGH: + the_controller->port_status[rhport] |= USB_PORT_STAT_HIGH_SPEED; + break; + case USB_SPEED_LOW: + the_controller->port_status[rhport] |= USB_PORT_STAT_LOW_SPEED; + break; + default: + break; } - //spin_lock(&the_controller->vdev[rhport].ud.lock); - //the_controller->vdev[rhport].ud.status = VDEV_CONNECT; - //spin_unlock(&the_controller->vdev[rhport].ud.lock); + /* spin_lock(&the_controller->vdev[rhport].ud.lock); + * the_controller->vdev[rhport].ud.status = VDEV_CONNECT; + * spin_unlock(&the_controller->vdev[rhport].ud.lock); */ the_controller->pending_port = rhport; @@ -157,18 +150,19 @@ dbg_vhci_rh("rh_port_disconnect %d\n", rhport); - spin_lock_irqsave (&the_controller->lock, flags); - //stop_activity (dum, driver); + spin_lock_irqsave(&the_controller->lock, flags); + /* stop_activity(dum, driver); */ the_controller->port_status[rhport] &= ~USB_PORT_STAT_CONNECTION; - the_controller->port_status[rhport] |= (1 << USB_PORT_FEAT_C_CONNECTION); + the_controller->port_status[rhport] |= + (1 << USB_PORT_FEAT_C_CONNECTION); - /* not yet complete the disconnection */ - //spin_lock(&vdev->ud.lock); - //vdev->ud.status = VHC_ST_DISCONNECT; - //spin_unlock(&vdev->ud.lock); + /* not yet complete the disconnection + * spin_lock(&vdev->ud.lock); + * vdev->ud.status = VHC_ST_DISCONNECT; + * spin_unlock(&vdev->ud.lock); */ - spin_unlock_irqrestore (&the_controller->lock, flags); + spin_unlock_irqrestore(&the_controller->lock, flags); } @@ -219,19 +213,19 @@ vhci = hcd_to_vhci(hcd); - spin_lock_irqsave (&vhci->lock, flags); + spin_lock_irqsave(&vhci->lock, flags); if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { dbg_vhci_rh("hw accessible flag in on?\n"); goto done; } /* check pseudo status register for each port */ - for(rhport = 0; rhport < VHCI_NPORTS; rhport++) { + for (rhport = 0; rhport < VHCI_NPORTS; rhport++) { if ((vhci->port_status[rhport] & PORT_C_MASK)) { /* The status of a port has been changed, */ dbg_vhci_rh("port %d is changed\n", rhport); - *event_bits |= 1 << ( rhport + 1); + *event_bits |= 1 << (rhport + 1); changed = 1; } } @@ -247,7 +241,7 @@ retval = 0; done: - spin_unlock_irqrestore (&vhci->lock, flags); + spin_unlock_irqrestore(&vhci->lock, flags); return retval; } @@ -258,14 +252,14 @@ desc->bDescriptorType = 0x29; desc->bDescLength = 9; desc->wHubCharacteristics = (__force __u16) - (__constant_cpu_to_le16 (0x0001)); + (__constant_cpu_to_le16(0x0001)); desc->bNbrPorts = VHCI_NPORTS; - desc->bitmap [0] = 0xff; - desc->bitmap [1] = 0xff; + desc->bitmap[0] = 0xff; + desc->bitmap[1] = 0xff; } - -static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength) +static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue, + u16 wIndex, char *buf, u16 wLength) { struct vhci_hcd *dum; int retval = 0; @@ -281,14 +275,15 @@ * NOTE: * wIndex shows the port number and begins from 1. */ - dbg_vhci_rh("typeReq %x wValue %x wIndex %x\n", typeReq, wValue, wIndex); + dbg_vhci_rh("typeReq %x wValue %x wIndex %x\n", typeReq, wValue, + wIndex); if (wIndex > VHCI_NPORTS) - uerr("invalid port number %d\n", wIndex); - rhport = ((__u8 ) (wIndex & 0x00ff)) -1; + printk(KERN_ERR "%s: invalid port number %d\n", __func__, wIndex); + rhport = ((__u8)(wIndex & 0x00ff)) - 1; dum = hcd_to_vhci(hcd); - spin_lock_irqsave (&dum->lock, flags); + spin_lock_irqsave(&dum->lock, flags); /* store old status and compare now and old later */ if (dbg_flag_vhci_rh) { @@ -298,177 +293,196 @@ } switch (typeReq) { - case ClearHubFeature: - dbg_vhci_rh(" ClearHubFeature\n"); - break; - case ClearPortFeature: - switch (wValue) { - case USB_PORT_FEAT_SUSPEND: - if (dum->port_status[rhport] & USB_PORT_STAT_SUSPEND) { - /* 20msec signaling */ - dum->resuming = 1; - dum->re_timeout = jiffies + msecs_to_jiffies(20); - } - break; - case USB_PORT_FEAT_POWER: - dbg_vhci_rh(" ClearPortFeature: USB_PORT_FEAT_POWER\n"); - dum->port_status[rhport] = 0; - //dum->address = 0; - //dum->hdev = 0; - dum->resuming = 0; - break; - case USB_PORT_FEAT_C_RESET: - dbg_vhci_rh(" ClearPortFeature: USB_PORT_FEAT_C_RESET\n"); - switch (dum->vdev[rhport].speed) { - case USB_SPEED_HIGH: - dum->port_status[rhport] |= USB_PORT_STAT_HIGH_SPEED; - break; - case USB_SPEED_LOW: - dum->port_status[rhport] |= USB_PORT_STAT_LOW_SPEED; - break; - default: - break; - } - default: - dbg_vhci_rh(" ClearPortFeature: default %x\n", wValue); - dum->port_status[rhport] &= ~(1 << wValue); + case ClearHubFeature: + dbg_vhci_rh(" ClearHubFeature\n"); + break; + case ClearPortFeature: + switch (wValue) { + case USB_PORT_FEAT_SUSPEND: + if (dum->port_status[rhport] & USB_PORT_STAT_SUSPEND) { + /* 20msec signaling */ + dum->resuming = 1; + dum->re_timeout = + jiffies + msecs_to_jiffies(20); } break; - case GetHubDescriptor: - dbg_vhci_rh(" GetHubDescriptor\n"); - hub_descriptor ((struct usb_hub_descriptor *) buf); - break; - case GetHubStatus: - dbg_vhci_rh(" GetHubStatus\n"); - *(__le32 *) buf = __constant_cpu_to_le32 (0); + case USB_PORT_FEAT_POWER: + dbg_vhci_rh(" ClearPortFeature: USB_PORT_FEAT_POWER\n"); + dum->port_status[rhport] = 0; + /* dum->address = 0; */ + /* dum->hdev = 0; */ + dum->resuming = 0; break; - case GetPortStatus: - dbg_vhci_rh(" GetPortStatus port %x\n", wIndex); - if (wIndex > VHCI_NPORTS || wIndex < 1) { - uerr(" invalid port number %d\n", wIndex); - retval = -EPIPE; + case USB_PORT_FEAT_C_RESET: + dbg_vhci_rh(" ClearPortFeature: " + "USB_PORT_FEAT_C_RESET\n"); + switch (dum->vdev[rhport].speed) { + case USB_SPEED_HIGH: + dum->port_status[rhport] |= + USB_PORT_STAT_HIGH_SPEED; + break; + case USB_SPEED_LOW: + dum->port_status[rhport] |= + USB_PORT_STAT_LOW_SPEED; + break; + default: + break; } + default: + dbg_vhci_rh(" ClearPortFeature: default %x\n", wValue); + dum->port_status[rhport] &= ~(1 << wValue); + } + break; + case GetHubDescriptor: + dbg_vhci_rh(" GetHubDescriptor\n"); + hub_descriptor((struct usb_hub_descriptor *) buf); + break; + case GetHubStatus: + dbg_vhci_rh(" GetHubStatus\n"); + *(__le32 *) buf = __constant_cpu_to_le32(0); + break; + case GetPortStatus: + dbg_vhci_rh(" GetPortStatus port %x\n", wIndex); + if (wIndex > VHCI_NPORTS || wIndex < 1) { + printk(KERN_ERR "%s: invalid port number %d\n", + __func__, wIndex); + retval = -EPIPE; + } - /* we do no care of resume. */ + /* we do no care of resume. */ - /* whoever resets or resumes must GetPortStatus to - * complete it!! - * */ - if (dum->resuming && time_after (jiffies, dum->re_timeout)) { - uerr(" not yet\n"); - dum->port_status[rhport] |= (1 << USB_PORT_FEAT_C_SUSPEND); - dum->port_status[rhport] &= ~(1 << USB_PORT_FEAT_SUSPEND); - dum->resuming = 0; - dum->re_timeout = 0; - //if (dum->driver && dum->driver->resume) { - // spin_unlock (&dum->lock); - // dum->driver->resume (&dum->gadget); - // spin_lock (&dum->lock); - //} - } + /* whoever resets or resumes must GetPortStatus to + * complete it!! + * */ + if (dum->resuming && time_after(jiffies, dum->re_timeout)) { + printk(KERN_ERR "%s: not yet\n", __func__); + dum->port_status[rhport] |= + (1 << USB_PORT_FEAT_C_SUSPEND); + dum->port_status[rhport] &= + ~(1 << USB_PORT_FEAT_SUSPEND); + dum->resuming = 0; + dum->re_timeout = 0; + /* if (dum->driver && dum->driver->resume) { + * spin_unlock (&dum->lock); + * dum->driver->resume (&dum->gadget); + * spin_lock (&dum->lock); + * } */ + } - if ((dum->port_status[rhport] & (1 << USB_PORT_FEAT_RESET)) != 0 - && time_after (jiffies, dum->re_timeout)) { - dum->port_status[rhport] |= (1 << USB_PORT_FEAT_C_RESET); - dum->port_status[rhport] &= ~(1 << USB_PORT_FEAT_RESET); - dum->re_timeout = 0; - - if (dum->vdev[rhport].ud.status == VDEV_ST_NOTASSIGNED) { - dbg_vhci_rh(" enable rhport %d (status %u)\n", rhport, dum->vdev[rhport].ud.status); - dum->port_status[rhport] |= USB_PORT_STAT_ENABLE; - } + if ((dum->port_status[rhport] & (1 << USB_PORT_FEAT_RESET)) != + 0 && time_after(jiffies, dum->re_timeout)) { + dum->port_status[rhport] |= + (1 << USB_PORT_FEAT_C_RESET); + dum->port_status[rhport] &= + ~(1 << USB_PORT_FEAT_RESET); + dum->re_timeout = 0; + + if (dum->vdev[rhport].ud.status == + VDEV_ST_NOTASSIGNED) { + dbg_vhci_rh(" enable rhport %d (status %u)\n", + rhport, + dum->vdev[rhport].ud.status); + dum->port_status[rhport] |= + USB_PORT_STAT_ENABLE; + } #if 0 - if (dum->driver) { + if (dum->driver) { - dum->port_status[rhport] |= USB_PORT_STAT_ENABLE; - /* give it the best speed we agree on */ - dum->gadget.speed = dum->driver->speed; - dum->gadget.ep0->maxpacket = 64; - switch (dum->gadget.speed) { - case USB_SPEED_HIGH: - dum->port_status[rhport] |= - USB_PORT_STAT_HIGH_SPEED; - break; - case USB_SPEED_LOW: - dum->gadget.ep0->maxpacket = 8; - dum->port_status[rhport] |= - USB_PORT_STAT_LOW_SPEED; - break; - default: - dum->gadget.speed = USB_SPEED_FULL; - break; - } + dum->port_status[rhport] |= + USB_PORT_STAT_ENABLE; + /* give it the best speed we agree on */ + dum->gadget.speed = dum->driver->speed; + dum->gadget.ep0->maxpacket = 64; + switch (dum->gadget.speed) { + case USB_SPEED_HIGH: + dum->port_status[rhport] |= + USB_PORT_STAT_HIGH_SPEED; + break; + case USB_SPEED_LOW: + dum->gadget.ep0->maxpacket = 8; + dum->port_status[rhport] |= + USB_PORT_STAT_LOW_SPEED; + break; + default: + dum->gadget.speed = USB_SPEED_FULL; + break; } -#endif - } - ((u16 *) buf)[0] = cpu_to_le16 (dum->port_status[rhport]); - ((u16 *) buf)[1] = cpu_to_le16 (dum->port_status[rhport] >> 16); +#endif - dbg_vhci_rh(" GetPortStatus bye %x %x\n", ((u16 *)buf)[0], ((u16 *)buf)[1] ); - break; - case SetHubFeature: - dbg_vhci_rh(" SetHubFeature\n"); - retval = -EPIPE; - break; - case SetPortFeature: - switch (wValue) { - case USB_PORT_FEAT_SUSPEND: - dbg_vhci_rh(" SetPortFeature: USB_PORT_FEAT_SUSPEND\n"); - uerr(" not yet\n"); + } + ((u16 *) buf)[0] = cpu_to_le16(dum->port_status[rhport]); + ((u16 *) buf)[1] = + cpu_to_le16(dum->port_status[rhport] >> 16); + + dbg_vhci_rh(" GetPortStatus bye %x %x\n", ((u16 *)buf)[0], + ((u16 *)buf)[1]); + break; + case SetHubFeature: + dbg_vhci_rh(" SetHubFeature\n"); + retval = -EPIPE; + break; + case SetPortFeature: + switch (wValue) { + case USB_PORT_FEAT_SUSPEND: + dbg_vhci_rh(" SetPortFeature: " + "USB_PORT_FEAT_SUSPEND\n"); + printk(KERN_ERR "%s: not yet\n", __func__); #if 0 - dum->port_status[rhport] |= (1 << USB_PORT_FEAT_SUSPEND); - if (dum->driver->suspend) { - spin_unlock (&dum->lock); - dum->driver->suspend (&dum->gadget); - spin_lock (&dum->lock); - } + dum->port_status[rhport] |= + (1 << USB_PORT_FEAT_SUSPEND); + if (dum->driver->suspend) { + spin_unlock(&dum->lock); + dum->driver->suspend(&dum->gadget); + spin_lock(&dum->lock); + } #endif - break; - case USB_PORT_FEAT_RESET: - dbg_vhci_rh(" SetPortFeature: USB_PORT_FEAT_RESET\n"); - /* if it's already running, disconnect first */ - if (dum->port_status[rhport] & USB_PORT_STAT_ENABLE) { - dum->port_status[rhport] &= ~(USB_PORT_STAT_ENABLE - | USB_PORT_STAT_LOW_SPEED - | USB_PORT_STAT_HIGH_SPEED); + break; + case USB_PORT_FEAT_RESET: + dbg_vhci_rh(" SetPortFeature: USB_PORT_FEAT_RESET\n"); + /* if it's already running, disconnect first */ + if (dum->port_status[rhport] & USB_PORT_STAT_ENABLE) { + dum->port_status[rhport] &= + ~(USB_PORT_STAT_ENABLE | + USB_PORT_STAT_LOW_SPEED | + USB_PORT_STAT_HIGH_SPEED); #if 0 - if (dum->driver) { - dev_dbg (hardware, "disconnect\n"); - stop_activity (dum, dum->driver); - } + if (dum->driver) { + dev_dbg(hardware, "disconnect\n"); + stop_activity(dum, dum->driver); + } #endif - /* FIXME test that code path! */ - } - /* 50msec reset signaling */ - dum->re_timeout = jiffies + msecs_to_jiffies(50); - - /* FALLTHROUGH */ - default: - dbg_vhci_rh(" SetPortFeature: default %d\n", wValue); - dum->port_status[rhport] |= (1 << wValue); + /* FIXME test that code path! */ } - break; + /* 50msec reset signaling */ + dum->re_timeout = jiffies + msecs_to_jiffies(50); + /* FALLTHROUGH */ default: - uerr(" default: no such request\n"); - //dev_dbg (hardware, - // "hub control req%04x v%04x i%04x l%d\n", - // typeReq, wValue, wIndex, wLength); + dbg_vhci_rh(" SetPortFeature: default %d\n", wValue); + dum->port_status[rhport] |= (1 << wValue); + } + break; - /* "protocol stall" on error */ - retval = -EPIPE; + default: + printk(KERN_ERR "%s: default: no such request\n", __func__); + /* dev_dbg (hardware, + * "hub control req%04x v%04x i%04x l%d\n", + * typeReq, wValue, wIndex, wLength); */ + + /* "protocol stall" on error */ + retval = -EPIPE; } if (dbg_flag_vhci_rh) { - printk("port %d\n", rhport); + printk(KERN_DEBUG "port %d\n", rhport); dump_port_status(prev_port_status[rhport]); dump_port_status(dum->port_status[rhport]); } dbg_vhci_rh(" bye\n"); - spin_unlock_irqrestore (&dum->lock, flags); + spin_unlock_irqrestore(&dum->lock, flags); return retval; } @@ -484,7 +498,7 @@ if (!udev) return NULL; - for (i=0; i < VHCI_NPORTS; i++) + for (i = 0; i < VHCI_NPORTS; i++) if (the_controller->vdev[i].udev == udev) return port_to_vdev(i); @@ -499,7 +513,7 @@ if (!vdev) { err("could not get virtual device"); - //BUG(); + /* BUG(); */ return; } @@ -507,7 +521,7 @@ priv = kzalloc(sizeof(struct vhci_priv), GFP_ATOMIC); if (!priv) { - uerr("malloc vhci_priv\n"); + dev_err(&urb->dev->dev, "malloc vhci_priv\n"); spin_unlock_irqrestore(&vdev->priv_lock, flag); usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC); return; @@ -529,29 +543,30 @@ spin_unlock_irqrestore(&vdev->priv_lock, flag); } -static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) +static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, + gfp_t mem_flags) { + struct device *dev = &urb->dev->dev; int ret = 0; unsigned long flags; - dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n", hcd, urb, mem_flags); - - + dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n", + hcd, urb, mem_flags); /* patch to usb_sg_init() is in 2.5.60 */ - BUG_ON (!urb->transfer_buffer && urb->transfer_buffer_length); + BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length); - spin_lock_irqsave (&the_controller->lock, flags); + spin_lock_irqsave(&the_controller->lock, flags); /* check HC is active or not */ if (!HC_IS_RUNNING(hcd->state)) { - uerr("HC is not running\n"); + dev_err(dev, "HC is not running\n"); spin_unlock_irqrestore(&the_controller->lock, flags); - return -ENODEV; + return -ENODEV; } if (urb->status != -EINPROGRESS) { - uerr("URB already unlinked!, status %d\n", urb->status); + dev_err(dev, "URB already unlinked!, status %d\n", urb->status); spin_unlock_irqrestore(&the_controller->lock, flags); return urb->status; } @@ -572,65 +587,65 @@ if (usb_pipedevice(urb->pipe) == 0) { __u8 type = usb_pipetype(urb->pipe); - struct usb_ctrlrequest *ctrlreq = (struct usb_ctrlrequest *) urb->setup_packet; - struct vhci_device *vdev = port_to_vdev(the_controller->pending_port); + struct usb_ctrlrequest *ctrlreq = + (struct usb_ctrlrequest *) urb->setup_packet; + struct vhci_device *vdev = + port_to_vdev(the_controller->pending_port); - if (type != PIPE_CONTROL || !ctrlreq ) { - uerr("invalid request to devnum 0\n"); + if (type != PIPE_CONTROL || !ctrlreq) { + dev_err(dev, "invalid request to devnum 0\n"); ret = EINVAL; goto no_need_xmit; } switch (ctrlreq->bRequest) { + case USB_REQ_SET_ADDRESS: + /* set_address may come when a device is reset */ + dev_info(dev, "SetAddress Request (%d) to port %d\n", + ctrlreq->wValue, vdev->rhport); + + vdev->udev = urb->dev; + + spin_lock(&vdev->ud.lock); + vdev->ud.status = VDEV_ST_USED; + spin_unlock(&vdev->ud.lock); + + if (urb->status == -EINPROGRESS) { + /* This request is successfully completed. */ + /* If not -EINPROGRESS, possibly unlinked. */ + urb->status = 0; + } - case USB_REQ_SET_ADDRESS: - /* set_address may come when a device is reset */ - uinfo("SetAddress Request (%d) to port %d\n", - ctrlreq->wValue, vdev->rhport); - - vdev->udev = urb->dev; - - spin_lock(&vdev->ud.lock); - vdev->ud.status = VDEV_ST_USED; - spin_unlock(&vdev->ud.lock); - - if (urb->status == -EINPROGRESS) { - /* This request is successfully completed. */ - /* If not -EINPROGRESS, possibly unlinked. */ - urb->status = 0; - } - - goto no_need_xmit; + goto no_need_xmit; - case USB_REQ_GET_DESCRIPTOR: - if (ctrlreq->wValue == (USB_DT_DEVICE << 8)) - dbg_vhci_hc("Not yet?: Get_Descriptor to device 0 (get max pipe size)\n"); - - /* FIXME: reference count? (usb_get_dev()) */ - vdev->udev = urb->dev; - goto out; + case USB_REQ_GET_DESCRIPTOR: + if (ctrlreq->wValue == (USB_DT_DEVICE << 8)) + dbg_vhci_hc("Not yet?: " + "Get_Descriptor to device 0 " + "(get max pipe size)\n"); + + /* FIXME: reference count? (usb_get_dev()) */ + vdev->udev = urb->dev; + goto out; - default: - /* NOT REACHED */ - uerr("invalid request to devnum 0 bRequest %u, wValue %u\n", - ctrlreq->bRequest, ctrlreq->wValue); - ret = -EINVAL; - goto no_need_xmit; + default: + /* NOT REACHED */ + dev_err(dev, "invalid request to devnum 0 bRequest %u, " + "wValue %u\n", ctrlreq->bRequest, + ctrlreq->wValue); + ret = -EINVAL; + goto no_need_xmit; } } out: - - vhci_tx_urb(urb); - spin_unlock_irqrestore(&the_controller->lock, flags); return 0; - no_need_xmit: usb_hcd_unlink_urb_from_ep(hcd, urb); no_need_unlink: @@ -638,11 +653,9 @@ usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); - return 0; } - /* * vhci_rx gives back the urb after receiving the reply of the urb. If an * unlink pdu is sent or not, vhci_rx receives a normal return pdu and gives @@ -702,7 +715,8 @@ priv = urb->hcpriv; if (!priv) { - /* URB was never linked! or will be soon given back by vhci_rx. */ + /* URB was never linked! or will be soon given back by + * vhci_rx. */ spin_unlock_irqrestore(&the_controller->lock, flags); return 0; } @@ -755,9 +769,11 @@ unlink->unlink_seqnum = priv->seqnum; - uinfo("vhci_hcd: device %p seems to be still connected\n", vdev); + uinfo("vhci_hcd: device %p seems to be still connected\n", + vdev); - /* send cmd_unlink and try to cancel the pending URB in the peer */ + /* send cmd_unlink and try to cancel the pending URB in the + * peer */ list_add_tail(&unlink->list, &vdev->unlink_tx); wake_up(&vdev->waitq_tx); @@ -777,7 +793,8 @@ usb_hcd_unlink_urb_from_ep(hcd, urb); spin_unlock_irqrestore(&the_controller->lock, flags); - usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); + usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, + urb->status); spin_lock_irqsave(&the_controller->lock, flags); } @@ -876,7 +893,7 @@ spin_unlock(&ud->lock); } -static void vhci_device_unusable(struct usbip_device* ud) +static void vhci_device_unusable(struct usbip_device *ud) { spin_lock(&ud->lock); @@ -894,21 +911,21 @@ vdev->ud.side = USBIP_VHCI; vdev->ud.status = VDEV_ST_NULL; - // vdev->ud.lock = SPIN_LOCK_UNLOCKED; + /* vdev->ud.lock = SPIN_LOCK_UNLOCKED; */ spin_lock_init(&vdev->ud.lock); INIT_LIST_HEAD(&vdev->priv_rx); INIT_LIST_HEAD(&vdev->priv_tx); INIT_LIST_HEAD(&vdev->unlink_tx); INIT_LIST_HEAD(&vdev->unlink_rx); - // vdev->priv_lock = SPIN_LOCK_UNLOCKED; + /* vdev->priv_lock = SPIN_LOCK_UNLOCKED; */ spin_lock_init(&vdev->priv_lock); init_waitqueue_head(&vdev->waitq_tx); vdev->ud.eh_ops.shutdown = vhci_shutdown_connection; vdev->ud.eh_ops.reset = vhci_device_reset; - vdev->ud.eh_ops.unusable= vhci_device_unusable; + vdev->ud.eh_ops.unusable = vhci_device_unusable; usbip_start_eh(&vdev->ud); } @@ -927,7 +944,7 @@ /* initialize private data of usb_hcd */ - for(rhport=0; rhport < VHCI_NPORTS; rhport++) { + for (rhport = 0; rhport < VHCI_NPORTS; rhport++) { struct vhci_device *vdev = &vhci->vdev[rhport]; vhci_device_init(vdev); vdev->rhport = rhport; @@ -965,7 +982,7 @@ sysfs_remove_group(&vhci_dev(vhci)->kobj, &dev_attr_group); /* 2. shutdown all the ports of vhci_hcd */ - for(rhport = 0 ; rhport < VHCI_NPORTS; rhport++) { + for (rhport = 0 ; rhport < VHCI_NPORTS; rhport++) { struct vhci_device *vdev = &vhci->vdev[rhport]; usbip_event_add(&vdev->ud, VDEV_EVENT_REMOVED); @@ -985,20 +1002,20 @@ } -#ifdef CONFIG_PM +#ifdef CONFIG_PM /* FIXME: suspend/resume */ static int vhci_bus_suspend(struct usb_hcd *hcd) { struct vhci_hcd *vhci = hcd_to_vhci(hcd); - dev_dbg(&hcd->self.root_hub->dev, "%s\n", __FUNCTION__); + dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); spin_lock_irq(&vhci->lock); - //vhci->rh_state = DUMMY_RH_SUSPENDED; - //set_link_state(vhci); + /* vhci->rh_state = DUMMY_RH_SUSPENDED; + * set_link_state(vhci); */ hcd->state = HC_STATE_SUSPENDED; - spin_unlock_irq (&vhci->lock); + spin_unlock_irq(&vhci->lock); return 0; } @@ -1008,19 +1025,19 @@ struct vhci_hcd *vhci = hcd_to_vhci(hcd); int rc = 0; - dev_dbg (&hcd->self.root_hub->dev, "%s\n", __FUNCTION__); + dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__); - spin_lock_irq (&vhci->lock); + spin_lock_irq(&vhci->lock); if (!test_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags)) { rc = -ESHUTDOWN; } else { - //vhci->rh_state = DUMMY_RH_RUNNING; - //set_link_state (vhci); - //if (!list_empty(&vhci->urbp_list)) - // mod_timer (&vhci->timer, jiffies); + /* vhci->rh_state = DUMMY_RH_RUNNING; + * set_link_state(vhci); + * if (!list_empty(&vhci->urbp_list)) + * mod_timer(&vhci->timer, jiffies); */ hcd->state = HC_STATE_RUNNING; } - spin_unlock_irq (&vhci->lock); + spin_unlock_irq(&vhci->lock); return rc; return 0; @@ -1064,14 +1081,12 @@ dbg_vhci_hc("name %s id %d\n", pdev->name, pdev->id); - /* will be removed */ if (pdev->dev.dma_mask) { - info("vhci_hcd DMA not supported\n"); + dev_info(&pdev->dev, "vhci_hcd DMA not supported\n"); return -EINVAL; } - /* * Allocate and initialize hcd. * Our private data is also allocated automatically. @@ -1108,9 +1123,8 @@ { struct usb_hcd *hcd; - hcd = platform_get_drvdata(pdev); - if(!hcd) + if (!hcd) return 0; /* @@ -1138,14 +1152,15 @@ int connected = 0; int ret = 0; - dev_dbg(&pdev->dev, "%s\n", __FUNCTION__); + dev_dbg(&pdev->dev, "%s\n", __func__); hcd = platform_get_drvdata(pdev); spin_lock(&the_controller->lock); for (rhport = 0; rhport < VHCI_NPORTS; rhport++) - if (the_controller->port_status[rhport] & USB_PORT_STAT_CONNECTION) + if (the_controller->port_status[rhport] & + USB_PORT_STAT_CONNECTION) connected += 1; spin_unlock(&the_controller->lock); @@ -1166,11 +1181,11 @@ { struct usb_hcd *hcd; - dev_dbg(&pdev->dev, "%s\n", __FUNCTION__); + dev_dbg(&pdev->dev, "%s\n", __func__); - hcd = platform_get_drvdata (pdev); + hcd = platform_get_drvdata(pdev); set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); - usb_hcd_poll_rh_status (hcd); + usb_hcd_poll_rh_status(hcd); return 0; } @@ -1211,7 +1226,7 @@ .name = (char *) driver_name, .id = -1, .dev = { - //.driver = &vhci_driver, + /* .driver = &vhci_driver, */ .release = the_pdev_release, }, }; @@ -1224,7 +1239,8 @@ if (usb_disabled()) return -ENODEV; - info("driver %s, %s\n", driver_name, DRIVER_VERSION); + printk(KERN_INFO KBUILD_MODNAME ": %s, %s\n", driver_name, + DRIVER_VERSION); ret = platform_driver_register(&vhci_driver); if (ret < 0) @@ -1234,25 +1250,19 @@ if (ret < 0) goto err_platform_device_register; - dbg_vhci_hc("bye\n"); return ret; - - /* error occurred */ - err_platform_device_register: platform_driver_unregister(&vhci_driver); err_driver_register: - dbg_vhci_hc("bye\n"); return ret; } module_init(vhci_init); - static void __exit vhci_cleanup(void) { dbg_vhci_hc("enter\n"); --- usbip-0.1.7.orig/drivers/head/stub_tx.c +++ usbip-0.1.7/drivers/head/stub_tx.c @@ -1,9 +1,6 @@ /* - * $Id: stub_tx.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -28,26 +25,22 @@ { struct urb *urb = priv->urb; - if (urb->setup_packet) - kfree(urb->setup_packet); - - if (urb->transfer_buffer) - kfree(urb->transfer_buffer); - + kfree(urb->setup_packet); + kfree(urb->transfer_buffer); list_del(&priv->list); kmem_cache_free(stub_priv_cache, priv); - usb_free_urb(urb); } /* be in spin_lock_irqsave(&sdev->priv_lock, flags) */ -void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum, __u32 status) +void stub_enqueue_ret_unlink(struct stub_device *sdev, __u32 seqnum, + __u32 status) { struct stub_unlink *unlink; unlink = kzalloc(sizeof(struct stub_unlink), GFP_ATOMIC); if (!unlink) { - uerr("alloc stub_unlink\n"); + dev_err(&sdev->interface->dev, "alloc stub_unlink\n"); usbip_event_add(&sdev->ud, VDEV_EVENT_ERROR_MALLOC); return; } @@ -78,24 +71,24 @@ switch (urb->status) { - case 0: - /* OK */ - break; - case -ENOENT: - uinfo("stopped by a call of usb_kill_urb()" - "because of cleaning up a virtual connection\n"); - return; - case -ECONNRESET: - uinfo("unlinked by a call of usb_unlink_urb()\n"); - break; - case -EPIPE: - uinfo("endpoint %d is stalled\n", usb_pipeendpoint(urb->pipe)); - break; - case -ESHUTDOWN: - uinfo("device removed?\n"); - break; - default: - uinfo("urb completion with non-zero status %d\n", urb->status); + case 0: + /* OK */ + break; + case -ENOENT: + uinfo("stopped by a call of usb_kill_urb() because of" + "cleaning up a virtual connection\n"); + return; + case -ECONNRESET: + uinfo("unlinked by a call of usb_unlink_urb()\n"); + break; + case -EPIPE: + uinfo("endpoint %d is stalled\n", usb_pipeendpoint(urb->pipe)); + break; + case -ESHUTDOWN: + uinfo("device removed?\n"); + break; + default: + uinfo("urb completion with non-zero status %d\n", urb->status); } /* link a urb to the queue of tx. */ @@ -213,7 +206,8 @@ iso_buffer = usbip_alloc_iso_desc_pdu(urb, &len); if (!iso_buffer) { - usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_MALLOC); + usbip_event_add(&sdev->ud, + SDEV_EVENT_ERROR_MALLOC); return -1; } @@ -222,18 +216,18 @@ txsize += len; } - ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg, iov, 3, txsize); + ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg, iov, + 3, txsize); if (ret != txsize) { - uerr("sendmsg failed!, retval %d for %zd\n", ret, txsize); - if (iso_buffer) - kfree(iso_buffer); + dev_err(&sdev->interface->dev, + "sendmsg failed!, retval %d for %zd\n", + ret, txsize); + kfree(iso_buffer); usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_TCP); return -1; } - if (iso_buffer) - kfree(iso_buffer); - + kfree(iso_buffer); dbg_stub_tx("send txdata\n"); total_size += txsize; @@ -304,9 +298,12 @@ iov[0].iov_len = sizeof(pdu_header); txsize += sizeof(pdu_header); - ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg, iov, 1, txsize); + ret = kernel_sendmsg(sdev->ud.tcp_socket, &msg, iov, + 1, txsize); if (ret != txsize) { - uerr("sendmsg failed!, retval %d for %zd\n", ret, txsize); + dev_err(&sdev->interface->dev, + "sendmsg failed!, retval %d for %zd\n", + ret, txsize); usbip_event_add(&sdev->ud, SDEV_EVENT_ERROR_TCP); return -1; } --- usbip-0.1.7.orig/drivers/head/vhci.h +++ usbip-0.1.7/drivers/head/vhci.h @@ -1,9 +1,6 @@ /* - * $Id: vhci.h 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -21,7 +18,7 @@ */ #include -#include HCD_HEADER +#include "headers/hcd.h" struct vhci_device { --- usbip-0.1.7.orig/drivers/head/stub.h +++ usbip-0.1.7/drivers/head/stub.h @@ -1,9 +1,6 @@ /* - * $Id: stub.h 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 --- usbip-0.1.7.orig/drivers/head/vhci_sysfs.c +++ usbip-0.1.7/drivers/head/vhci_sysfs.c @@ -1,9 +1,6 @@ /* - * $Id: vhci_sysfs.c 67 2008-04-24 11:51:43Z hirofuchi $ - * * 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 @@ -27,70 +24,9 @@ /* TODO: refine locking ?*/ - -/*-------------------------------------------------------------------------*/ - -/* client address can be retrieved from /proc/net/tcp with a socket value in - * vhci's sysfs status */ -#if 0 -/* FIXME: ipv4 only code */ -static int print_client_ip(struct device *dev, - struct device_attribute *attr, - char *out) -{ - int i; - int ret; - int size; - __u32 ip; - char *s = out; - - if (!the_controller || !out) - BUG(); - - spin_lock(&the_controller->lock); - - for (i=0; i < VHCI_NPORTS; i++) { - struct socket *sock; - struct sockaddr_in inaddr; - struct vhci_device *vdev = port_to_vdev(i); - - spin_lock(&vdev->ud.lock); - if( vdev->ud.status != VDEV_ST_USED ) { - out += snprintf(out, 15, "%d -\n", i ); - spin_unlock(&vdev->ud.lock); - continue; - } - - sock = vdev->ud.tcp_socket; - size = sizeof(struct sockaddr); - ret = sock->ops->getname(sock, - (struct sockaddr *)&inaddr, - &size, - 0); - if( ! ret ) { - spin_unlock(&vdev->ud.lock); - spin_unlock(&the_controller->lock); - return -ENODEV; - } - - ip = ntohl(inaddr.sin_addr.s_addr); - out += snprintf( out, 15, "%d %u\n", i, ip ); - spin_unlock(&vdev->ud.lock); - } - - spin_unlock(&the_controller->lock); - - return out-s; -} - -static DEVICE_ATTR(client_ip, S_IRUGO, print_client_ip, NULL ); -#endif - - - /* Sysfs entry to show port status */ static ssize_t show_status(struct device *dev, struct device_attribute *attr, - char *out) + char *out) { char *s = out; int i = 0; @@ -110,9 +46,10 @@ * up /proc/net/{tcp,tcp6}. Also, a userland program may remember a * port number and its peer IP address. */ - out += sprintf(out, "prt sta spd bus dev socket local_busid\n"); + out += sprintf(out, "prt sta spd bus dev socket " + "local_busid\n"); - for (i=0; i < VHCI_NPORTS; i++) { + for (i = 0; i < VHCI_NPORTS; i++) { struct vhci_device *vdev = port_to_vdev(i); spin_lock(&vdev->ud.lock); @@ -135,17 +72,11 @@ spin_unlock(&the_controller->lock); - return out - s ; + return out - s; } - static DEVICE_ATTR(status, S_IRUGO, show_status, NULL); - - -/*-------------------------------------------------------------------------*/ - /* Sysfs entry to shutdown a virtual connection */ - static int vhci_port_disconnect(__u32 rhport) { struct vhci_device *vdev; @@ -178,7 +109,8 @@ } static ssize_t store_detach(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) { + const char *buf, size_t count) +{ int err; __u32 rhport = 0; @@ -191,22 +123,15 @@ } err = vhci_port_disconnect(rhport); - if (err < 0) { + if (err < 0) return -EINVAL; - } dbg_vhci_sysfs("Leave\n"); return count; } - static DEVICE_ATTR(detach, S_IWUSR, NULL, store_detach); - - -/*-------------------------------------------------------------------------*/ - /* Sysfs entry to establish a virtual connection */ - static int valid_args(__u32 rhport, enum usb_device_speed speed) { /* check rhport */ @@ -216,16 +141,15 @@ } /* check speed */ - switch(speed) { - case USB_SPEED_LOW: - case USB_SPEED_FULL: - case USB_SPEED_HIGH: - case USB_SPEED_VARIABLE: - break; - - default: - uerr("speed %d\n", speed); - return -EINVAL; + switch (speed) { + case USB_SPEED_LOW: + case USB_SPEED_FULL: + case USB_SPEED_HIGH: + case USB_SPEED_VARIABLE: + break; + default: + uerr("speed %d\n", speed); + return -EINVAL; } return 0; @@ -243,14 +167,13 @@ * write() returns 0 on success, else negative errno. */ static ssize_t store_attach(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count) + const char *buf, size_t count) { struct vhci_device *vdev; struct socket *socket; int sockfd = 0; __u32 rhport = 0, devid = 0, speed = 0; - /* * @rhport: port number of vhci_hcd * @sockfd: socket descriptor of an established TCP connection @@ -272,7 +195,6 @@ if (!socket) return -EINVAL; - /* now need lock until setting vdev status as used */ /* begin a lock */ @@ -313,19 +235,13 @@ return count; } - static DEVICE_ATTR(attach, S_IWUSR, NULL, store_attach); - - -/*-------------------------------------------------------------------------*/ - static struct attribute *dev_attrs[] = { &dev_attr_status.attr, &dev_attr_detach.attr, &dev_attr_attach.attr, &dev_attr_usbip_debug.attr, - // &dev_attr_client_ip.attr, NULL, }; --- usbip-0.1.7.orig/drivers/head/vhci_tx.c +++ usbip-0.1.7/drivers/head/vhci_tx.c @@ -1,9 +1,6 @@ /* - * $Id: vhci_tx.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -30,7 +27,7 @@ struct vhci_device *vdev = priv->vdev; dbg_vhci_tx("URB, local devnum %u, remote devid %u\n", - usb_pipedevice(urb->pipe), vdev->devid); + usb_pipedevice(urb->pipe), vdev->devid); pdup->base.command = USBIP_CMD_SUBMIT; pdup->base.seqnum = priv->seqnum; @@ -112,7 +109,8 @@ iso_buffer = usbip_alloc_iso_desc_pdu(urb, &len); if (!iso_buffer) { - usbip_event_add(&vdev->ud, SDEV_EVENT_ERROR_MALLOC); + usbip_event_add(&vdev->ud, + SDEV_EVENT_ERROR_MALLOC); return -1; } @@ -123,17 +121,14 @@ ret = kernel_sendmsg(vdev->ud.tcp_socket, &msg, iov, 3, txsize); if (ret != txsize) { - uerr("sendmsg failed!, retval %d for %zd\n", ret, txsize); - if (iso_buffer) - kfree(iso_buffer); + uerr("sendmsg failed!, retval %d for %zd\n", ret, + txsize); + kfree(iso_buffer); usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_TCP); return -1; } - - if (iso_buffer) - kfree(iso_buffer); - + kfree(iso_buffer); dbg_vhci_tx("send txdata\n"); total_size += txsize; @@ -200,7 +195,8 @@ ret = kernel_sendmsg(vdev->ud.tcp_socket, &msg, iov, 1, txsize); if (ret != txsize) { - uerr("sendmsg failed!, retval %d for %zd\n", ret, txsize); + uerr("sendmsg failed!, retval %d for %zd\n", ret, + txsize); usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_TCP); return -1; } --- usbip-0.1.7.orig/drivers/head/stub_dev.c +++ usbip-0.1.7/drivers/head/stub_dev.c @@ -1,9 +1,6 @@ /* - * $Id: stub_dev.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -25,7 +22,8 @@ -static int stub_probe(struct usb_interface *interface, const struct usb_device_id *id); +static int stub_probe(struct usb_interface *interface, + const struct usb_device_id *id); static void stub_disconnect(struct usb_interface *interface); @@ -52,23 +50,18 @@ #endif /* magic for wild card */ { .driver_info = 1 }, - { } /* Terminating entry */ + { 0, } /* Terminating entry */ }; - MODULE_DEVICE_TABLE(usb, stub_table); - struct usb_driver stub_driver = { .name = "usbip", - .probe = stub_probe, .disconnect = stub_disconnect, - .id_table = stub_table, }; - /*-------------------------------------------------------------------------*/ /* Define sysfs entries for a usbip-bound device */ @@ -85,7 +78,7 @@ int status; if (!sdev) { - uerr("sdev is null\n"); + dev_err(dev, "sdev is null\n"); return -ENODEV; } @@ -97,7 +90,6 @@ } static DEVICE_ATTR(usbip_status, S_IRUGO, show_status, NULL); - /* * usbip_sockfd gets a socket descriptor of an established TCP connection that * is used to transfer usbip requests by kernel threads. -1 is a magic number @@ -111,19 +103,19 @@ struct socket *socket; if (!sdev) { - uerr("sdev is null\n"); + dev_err(dev, "sdev is null\n"); return -ENODEV; } sscanf(buf, "%d", &sockfd); if (sockfd != -1) { - uinfo("stub up\n"); + dev_info(dev, "stub up\n"); spin_lock(&sdev->ud.lock); if (sdev->ud.status != SDEV_ST_AVAILABLE) { - uerr("not ready\n"); + dev_err(dev, "not ready\n"); spin_unlock(&sdev->ud.lock); return -EINVAL; } @@ -151,7 +143,7 @@ spin_unlock(&sdev->ud.lock); } else { - uinfo("stub down\n"); + dev_info(dev, "stub down\n"); spin_lock(&sdev->ud.lock); if (sdev->ud.status != SDEV_ST_USED) { @@ -220,12 +212,7 @@ */ if (ud->tcp_socket) { udbg("shutdown tcp_socket %p\n", ud->tcp_socket); -#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) - /* in /usr/include/sys/socket.c, SHUT_RDWR is defined as 2. */ - ud->tcp_socket->ops->shutdown(ud->tcp_socket, 2); -#else kernel_sock_shutdown(ud->tcp_socket, SHUT_RDWR); -#endif } /* 1. stop threads */ @@ -256,7 +243,8 @@ kfree(unlink); } - list_for_each_entry_safe(unlink, tmp, &sdev->unlink_free, list) { + list_for_each_entry_safe(unlink, tmp, + &sdev->unlink_free, list) { list_del(&unlink->list); kfree(unlink); } @@ -274,7 +262,7 @@ udbg("device reset"); ret = usb_lock_device_for_reset(udev, sdev->interface); if (ret < 0) { - uerr("lock for reset\n"); + dev_err(&udev->dev, "lock for reset\n"); spin_lock(&ud->lock); ud->status = SDEV_ST_ERROR; @@ -290,11 +278,11 @@ spin_lock(&ud->lock); if (ret) { - uerr("device reset\n"); + dev_err(&udev->dev, "device reset\n"); ud->status = SDEV_ST_ERROR; } else { - uinfo("device reset\n"); + dev_info(&udev->dev, "device reset\n"); ud->status = SDEV_ST_AVAILABLE; } @@ -319,17 +307,18 @@ * * Allocates and initializes a new stub_device struct. */ -static struct stub_device * stub_device_alloc(struct usb_interface *interface) +static struct stub_device *stub_device_alloc(struct usb_interface *interface) { struct stub_device *sdev; int busnum = interface_to_busnum(interface); int devnum = interface_to_devnum(interface); - udbg("allocating stub device"); + dev_dbg(&interface->dev, "allocating stub device"); + /* yes, it's a new device */ - sdev = (struct stub_device *) kzalloc(sizeof(struct stub_device), GFP_KERNEL); + sdev = kzalloc(sizeof(struct stub_device), GFP_KERNEL); if (!sdev) { - uerr("no memory for stub_device\n"); + dev_err(&interface->dev, "no memory for stub_device\n"); return NULL; } @@ -347,7 +336,7 @@ sdev->ud.side = USBIP_STUB; sdev->ud.status = SDEV_ST_AVAILABLE; - // sdev->ud.lock = SPIN_LOCK_UNLOCKED; + /* sdev->ud.lock = SPIN_LOCK_UNLOCKED; */ spin_lock_init(&sdev->ud.lock); sdev->ud.tcp_socket = NULL; @@ -356,7 +345,7 @@ INIT_LIST_HEAD(&sdev->priv_free); INIT_LIST_HEAD(&sdev->unlink_free); INIT_LIST_HEAD(&sdev->unlink_tx); - // sdev->priv_lock = SPIN_LOCK_UNLOCKED; + /* sdev->priv_lock = SPIN_LOCK_UNLOCKED; */ spin_lock_init(&sdev->priv_lock); init_waitqueue_head(&sdev->tx_waitq); @@ -392,20 +381,24 @@ * looks at the usbip's sysfs entries of only the first active interface. * * TODO: use "struct usb_device_driver" to bind a usb device. - * However, it seems it is not fully supported in mainline kernel yet (2.6.19.2). + * However, it seems it is not fully supported in mainline kernel yet + * (2.6.19.2). */ -static int stub_probe(struct usb_interface *interface, const struct usb_device_id *id) +static int stub_probe(struct usb_interface *interface, + const struct usb_device_id *id) { struct usb_device *udev = interface_to_usbdev(interface); struct stub_device *sdev = NULL; char *udev_busid = interface->dev.parent->bus_id; int err = 0; - udbg("Enter\n"); + dev_dbg(&interface->dev, "Enter\n"); /* check we should claim or not by busid_table */ if (match_busid(udev_busid)) { - uinfo("this device %s is not in match_busid table. skip!\n", udev_busid); + dev_info(&interface->dev, + "this device %s is not in match_busid table. skip!\n", + udev_busid); /* * Return value should be ENODEV or ENOXIO to continue trying @@ -416,32 +409,33 @@ } if (udev->descriptor.bDeviceClass == USB_CLASS_HUB) { - udbg("this device %s is a usb hub device. skip!\n", udev_busid); + udbg("this device %s is a usb hub device. skip!\n", + udev_busid); return -ENODEV; } if (!strcmp(udev->bus->bus_name, "vhci_hcd")) { - udbg("this device %s is attached on vhci_hcd. skip!\n", udev_busid); + udbg("this device %s is attached on vhci_hcd. skip!\n", + udev_busid); return -ENODEV; } /* ok. this is my device. */ - - if ((sdev = stub_device_alloc(interface))) { - struct usb_device *udev = interface_to_usbdev(interface); - - uinfo("USB/IP Stub: register a new interface (bus %u dev %u ifn %u)\n", - udev->bus->busnum, udev->devnum, - interface->cur_altsetting->desc.bInterfaceNumber); - } else + sdev = stub_device_alloc(interface); + if (!sdev) return -ENOMEM; + dev_info(&interface->dev, "USB/IP Stub: register a new interface " + "(bus %u dev %u ifn %u)\n", udev->bus->busnum, udev->devnum, + interface->cur_altsetting->desc.bInterfaceNumber); + /* set private data to usb_interface */ usb_set_intfdata(interface, sdev); err = stub_add_files(&interface->dev); if (err) { - uerr("create sysfs files for %s\n", udev_busid); + dev_err(&interface->dev, "create sysfs files for %s\n", + udev_busid); return err; } @@ -462,7 +456,7 @@ /* get stub_device */ if (!sdev) { err(" could not get device from inteface data"); - //BUG(); + /* BUG(); */ return; } --- usbip-0.1.7.orig/drivers/head/Makefile +++ usbip-0.1.7/drivers/head/Makefile @@ -1,8 +1,8 @@ # Makefile for the USB/IP driver # -# $Id: Makefile 66 2008-04-20 13:19:42Z hirofuchi $ +# $Id: Makefile 14 2007-06-18 12:20:03Z hirofuchi $ # -# Copyright (C) 2003-2008 Takahiro Hirofuchi +# Copyright (C) 2003-2007 Takahiro Hirofuchi # # # This is free software; you can redistribute it and/or modify --- usbip-0.1.7.orig/drivers/head/usbip_event.c +++ usbip-0.1.7/drivers/head/usbip_event.c @@ -1,9 +1,6 @@ /* - * $Id: usbip_event.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -22,74 +19,14 @@ #include "usbip_common.h" - - - -static void event_handler_loop(struct usbip_task *eh); - -void usbip_start_eh(struct usbip_device *ud) -{ - struct usbip_task *eh = &ud->eh; - - init_waitqueue_head(&ud->eh_waitq); - ud->event = 0; - - usbip_task_init(eh, "usbip_eh", event_handler_loop); - - kernel_thread((int(*)(void *)) usbip_thread, (void *) eh, 0); - - wait_for_completion(&eh->thread_done); -} -EXPORT_SYMBOL(usbip_start_eh); - -void usbip_stop_eh(struct usbip_device *ud) -{ - struct usbip_task *eh = &ud->eh; - - wait_for_completion(&eh->thread_done); - dbg_eh("usbip_eh has finished\n"); -} -EXPORT_SYMBOL(usbip_stop_eh); - - -void usbip_event_add(struct usbip_device *ud, unsigned long event) -{ - spin_lock(&ud->lock); - - ud->event |= event; - - wake_up(&ud->eh_waitq); - - spin_unlock(&ud->lock); -} -EXPORT_SYMBOL(usbip_event_add); - -int usbip_event_happend(struct usbip_device *ud) -{ - int happend = 0; - - spin_lock(&ud->lock); - - if (ud->event != 0) - happend = 1; - - spin_unlock(&ud->lock); - - return happend; -} -EXPORT_SYMBOL(usbip_event_happend); - - static int event_handler(struct usbip_device *ud) { - dbg_eh("enter\n"); - /* * Events are handled by only this thread. */ - while ( usbip_event_happend(ud) ) { + while (usbip_event_happend(ud)) { dbg_eh("pending event %lx\n", ud->event); /* @@ -127,16 +64,13 @@ } /* NOTREACHED */ - uerr("unknown event\n"); + printk(KERN_ERR "%s: unknown event\n", __func__); return -1; } return 0; } - - - static void event_handler_loop(struct usbip_task *ut) { struct usbip_device *ud = container_of(ut, struct usbip_device, eh); @@ -155,3 +89,53 @@ } } +void usbip_start_eh(struct usbip_device *ud) +{ + struct usbip_task *eh = &ud->eh; + + init_waitqueue_head(&ud->eh_waitq); + ud->event = 0; + + usbip_task_init(eh, "usbip_eh", event_handler_loop); + + kernel_thread(usbip_thread, (void *)eh, 0); + + wait_for_completion(&eh->thread_done); +} +EXPORT_SYMBOL_GPL(usbip_start_eh); + +void usbip_stop_eh(struct usbip_device *ud) +{ + struct usbip_task *eh = &ud->eh; + + wait_for_completion(&eh->thread_done); + dbg_eh("usbip_eh has finished\n"); +} +EXPORT_SYMBOL_GPL(usbip_stop_eh); + +void usbip_event_add(struct usbip_device *ud, unsigned long event) +{ + spin_lock(&ud->lock); + + ud->event |= event; + + wake_up(&ud->eh_waitq); + + spin_unlock(&ud->lock); +} +EXPORT_SYMBOL_GPL(usbip_event_add); + +int usbip_event_happend(struct usbip_device *ud) +{ + int happend = 0; + + spin_lock(&ud->lock); + + if (ud->event != 0) + happend = 1; + + spin_unlock(&ud->lock); + + return happend; +} +EXPORT_SYMBOL_GPL(usbip_event_happend); --- usbip-0.1.7.orig/drivers/head/stub_rx.c +++ usbip-0.1.7/drivers/head/stub_rx.c @@ -1,9 +1,6 @@ /* - * $Id: stub_rx.c 66 2008-04-20 13:19:42Z hirofuchi $ - * * 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 @@ -22,8 +19,7 @@ #include "usbip_common.h" #include "stub.h" - -#include HCD_HEADER +#include "headers/hcd.h" static int is_clear_halt_cmd(struct urb *urb) @@ -68,11 +64,11 @@ index = le16_to_cpu(req->wIndex); if ((req->bRequest == USB_REQ_SET_FEATURE) && - (req->bRequestType == USB_RT_PORT) && - (value = USB_PORT_FEAT_RESET)) { + (req->bRequestType == USB_RT_PORT) && + (value = USB_PORT_FEAT_RESET)) { dbg_stub_rx("reset_device_cmd, port %u\n", index); return 1; - } else + } else return 0; } @@ -93,7 +89,7 @@ */ target_endp = le16_to_cpu(req->wIndex) & 0x000f; - /* the stalled endpoint direction is IN or OUT?. USB_DIR_IN is 0x80. */ + /* the stalled endpoint direction is IN or OUT?. USB_DIR_IN is 0x80. */ target_dir = le16_to_cpu(req->wIndex) & 0x0080; if (target_dir) @@ -130,7 +126,9 @@ uinfo("set_interface error: inf %u alt %u, %d\n", interface, alternate, ret); else - uinfo("set_interface done: inf %u alt %u\n", interface, alternate); + uinfo("set_interface done: inf %u alt %u\n", + interface, + alternate); return ret; } @@ -163,7 +161,7 @@ uinfo("but, skip!\n"); return 0; - //return usb_driver_set_configuration(urb->dev, config); + /* return usb_driver_set_configuration(urb->dev, config); */ } static int tweak_reset_device_cmd(struct urb *urb) @@ -179,17 +177,17 @@ uinfo("reset_device (port %d) to %s\n", index, urb->dev->dev.bus_id); - /* all interfaces should be owned by usbip driver, so just reset it. */ + /* all interfaces should be owned by usbip driver, so just reset it. */ ret = usb_lock_device_for_reset(urb->dev, NULL); if (ret < 0) { - uerr("lock for reset\n"); + dev_err(&urb->dev->dev, "lock for reset\n"); return ret; } /* try to reset the device */ - ret = usb_reset_composite_device(urb->dev, NULL); + ret = usb_reset_device(urb->dev); if (ret < 0) - uerr("device reset\n"); + dev_err(&urb->dev->dev, "device reset\n"); usb_unlock_device(urb->dev); @@ -233,7 +231,8 @@ * * See also comments about unlinking strategy in vhci_hcd.c. */ -static int stub_recv_cmd_unlink(struct stub_device *sdev, struct usbip_header *pdu) +static int stub_recv_cmd_unlink(struct stub_device *sdev, + struct usbip_header *pdu) { struct list_head *listhead = &sdev->priv_init; struct list_head *ptr; @@ -249,7 +248,8 @@ if (priv->seqnum == pdu->u.cmd_unlink.seqnum) { int ret; - uinfo("unlink urb %p\n", priv->urb); + dev_info(&priv->urb->dev->dev, "unlink urb %p\n", + priv->urb); /* * This matched urb is not completed yet (i.e., be in @@ -288,8 +288,9 @@ */ ret = usb_unlink_urb(priv->urb); if (ret != -EINPROGRESS) - uerr("faild to unlink a urb %p, ret %d\n", priv->urb, ret); - + dev_err(&priv->urb->dev->dev, + "failed to unlink a urb %p, ret %d\n", + priv->urb, ret); return 0; } } @@ -328,7 +329,7 @@ } static struct stub_priv *stub_priv_alloc(struct stub_device *sdev, - struct usbip_header *pdu) + struct usbip_header *pdu) { struct stub_priv *priv; struct usbip_device *ud = &sdev->ud; @@ -338,7 +339,7 @@ priv = kmem_cache_alloc(stub_priv_cache, GFP_ATOMIC); if (!priv) { - uerr("alloc stub_priv\n"); + dev_err(&sdev->interface->dev, "alloc stub_priv\n"); spin_unlock_irqrestore(&sdev->priv_lock, flags); usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC); return NULL; @@ -387,7 +388,7 @@ epnum = (ep->desc.bEndpointAddress & 0x7f); if (epnum == epnum0) { - //uinfo("found epnum %d\n", epnum0); + /* uinfo("found epnum %d\n", epnum0); */ found = 1; break; } @@ -409,7 +410,8 @@ ep = get_ep_from_epnum(udev, epnum); if (!ep) { - uerr("no such endpoint?, %d", epnum); + dev_err(&sdev->interface->dev, "no such endpoint?, %d\n", + epnum); BUG(); } @@ -455,12 +457,12 @@ } /* NOT REACHED */ - uerr("get pipe, epnum %d\n", epnum); + dev_err(&sdev->interface->dev, "get pipe, epnum %d\n", epnum); return 0; } - -static void stub_recv_cmd_submit(struct stub_device *sdev, struct usbip_header *pdu) +static void stub_recv_cmd_submit(struct stub_device *sdev, + struct usbip_header *pdu) { int ret; struct stub_priv *priv; @@ -475,12 +477,13 @@ /* setup a urb */ if (usb_pipeisoc(pipe)) - priv->urb = usb_alloc_urb(pdu->u.cmd_submit.number_of_packets, GFP_KERNEL); + priv->urb = usb_alloc_urb(pdu->u.cmd_submit.number_of_packets, + GFP_KERNEL); else priv->urb = usb_alloc_urb(0, GFP_KERNEL); if (!priv->urb) { - uerr("malloc urb\n"); + dev_err(&sdev->interface->dev, "malloc urb\n"); usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC); return; } @@ -488,9 +491,10 @@ /* set priv->urb->transfer_buffer */ if (pdu->u.cmd_submit.transfer_buffer_length > 0) { priv->urb->transfer_buffer = - kzalloc(pdu->u.cmd_submit.transfer_buffer_length, GFP_KERNEL); + kzalloc(pdu->u.cmd_submit.transfer_buffer_length, + GFP_KERNEL); if (!priv->urb->transfer_buffer) { - uerr("malloc x_buff\n"); + dev_err(&sdev->interface->dev, "malloc x_buff\n"); usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC); return; } @@ -499,7 +503,7 @@ /* set priv->urb->setup_packet */ priv->urb->setup_packet = kzalloc(8, GFP_KERNEL); if (!priv->urb->setup_packet) { - uerr("allocate setup_packet\n"); + dev_err(&sdev->interface->dev, "allocate setup_packet\n"); usbip_event_add(ud, SDEV_EVENT_ERROR_MALLOC); return; } @@ -529,7 +533,7 @@ if (ret == 0) dbg_stub_rx("submit urb ok, seqnum %u\n", pdu->base.seqnum); else { - uerr("submit_urb error, %d\n", ret); + dev_err(&sdev->interface->dev, "submit_urb error, %d\n", ret); usbip_dump_header(pdu); usbip_dump_urb(priv->urb); @@ -550,17 +554,16 @@ int ret; struct usbip_header pdu; struct stub_device *sdev = container_of(ud, struct stub_device, ud); - + struct device *dev = &sdev->interface->dev; dbg_stub_rx("Enter\n"); memset(&pdu, 0, sizeof(pdu)); - /* 1. receive a pdu header */ - ret = usbip_xmit(0, ud->tcp_socket, (char *) &pdu, sizeof(pdu),0); + ret = usbip_xmit(0, ud->tcp_socket, (char *) &pdu, sizeof(pdu), 0); if (ret != sizeof(pdu)) { - uerr("recv a header, %d\n", ret); + dev_err(dev, "recv a header, %d\n", ret); usbip_event_add(ud, SDEV_EVENT_ERROR_TCP); return; } @@ -571,25 +574,25 @@ usbip_dump_header(&pdu); if (!valid_request(sdev, &pdu)) { - uerr("recv invalid request\n"); + dev_err(dev, "recv invalid request\n"); usbip_event_add(ud, SDEV_EVENT_ERROR_TCP); return; } switch (pdu.base.command) { - case USBIP_CMD_UNLINK: - stub_recv_cmd_unlink(sdev, &pdu); - break; - - case USBIP_CMD_SUBMIT: - stub_recv_cmd_submit(sdev, &pdu); - break; - - default: - /* NOTREACHED */ - uerr("unknown pdu\n"); - usbip_event_add(ud, SDEV_EVENT_ERROR_TCP); - return; + case USBIP_CMD_UNLINK: + stub_recv_cmd_unlink(sdev, &pdu); + break; + + case USBIP_CMD_SUBMIT: + stub_recv_cmd_submit(sdev, &pdu); + break; + + default: + /* NOTREACHED */ + dev_err(dev, "unknown pdu\n"); + usbip_event_add(ud, SDEV_EVENT_ERROR_TCP); + return; } } @@ -610,4 +613,3 @@ stub_rx_pdu(ud); } } - --- usbip-0.1.7.orig/drivers/head/usbip_common.h +++ usbip-0.1.7/drivers/head/usbip_common.h @@ -1,9 +1,6 @@ /* - * $Id: usbip_common.h 68 2008-04-29 03:31:43Z hirofuchi $ - * * 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 @@ -20,14 +17,14 @@ * USA. */ -#ifndef __VHCI_COMMON_H -#define __VHCI_COMMON_H +#ifndef __VHCI_COMMON_H +#define __VHCI_COMMON_H #include #include -#include #include +#include /*-------------------------------------------------------------------------*/ @@ -47,12 +44,12 @@ do { \ printk(KERN_DEBUG "%-10s:(%s,%d) %s: " fmt, \ (in_interrupt() ? "interrupt" : (current)->comm),\ - __FILE__, __LINE__, __FUNCTION__ , ##args); \ - } while(0) + __FILE__, __LINE__, __func__, ##args); \ + } while (0) #else /* CONFIG_USB_DEBUG */ -#define udbg(fmt, args...) do{ }while(0) +#define udbg(fmt, args...) do { } while (0) #endif /* CONFIG_USB_DEBUG */ @@ -89,24 +86,36 @@ #define dbg_with_flag(flag, fmt, args...) \ do { \ - if(flag & usbip_debug_flag) \ + if (flag & usbip_debug_flag) \ udbg(fmt , ##args); \ - } while(0) + } while (0) -#define dbg_sysfs(fmt, args...) dbg_with_flag(usbip_debug_sysfs, fmt , ##args) -#define dbg_xmit(fmt, args...) dbg_with_flag(usbip_debug_xmit, fmt , ##args) -#define dbg_urb(fmt, args...) dbg_with_flag(usbip_debug_urb, fmt , ##args) -#define dbg_eh(fmt, args...) dbg_with_flag(usbip_debug_eh, fmt , ##args) - -#define dbg_vhci_rh(fmt, args...) dbg_with_flag(usbip_debug_vhci_rh, fmt , ##args) -#define dbg_vhci_hc(fmt, args...) dbg_with_flag(usbip_debug_vhci_hc, fmt , ##args) -#define dbg_vhci_rx(fmt, args...) dbg_with_flag(usbip_debug_vhci_rx, fmt , ##args) -#define dbg_vhci_tx(fmt, args...) dbg_with_flag(usbip_debug_vhci_tx, fmt , ##args) -#define dbg_vhci_sysfs(fmt, args...) dbg_with_flag(usbip_debug_vhci_sysfs, fmt , ##args) - -#define dbg_stub_cmp(fmt, args...) dbg_with_flag(usbip_debug_stub_cmp, fmt , ##args) -#define dbg_stub_rx(fmt, args...) dbg_with_flag(usbip_debug_stub_rx, fmt , ##args) -#define dbg_stub_tx(fmt, args...) dbg_with_flag(usbip_debug_stub_tx, fmt , ##args) +#define dbg_sysfs(fmt, args...) \ + dbg_with_flag(usbip_debug_sysfs, fmt , ##args) +#define dbg_xmit(fmt, args...) \ + dbg_with_flag(usbip_debug_xmit, fmt , ##args) +#define dbg_urb(fmt, args...) \ + dbg_with_flag(usbip_debug_urb, fmt , ##args) +#define dbg_eh(fmt, args...) \ + dbg_with_flag(usbip_debug_eh, fmt , ##args) + +#define dbg_vhci_rh(fmt, args...) \ + dbg_with_flag(usbip_debug_vhci_rh, fmt , ##args) +#define dbg_vhci_hc(fmt, args...) \ + dbg_with_flag(usbip_debug_vhci_hc, fmt , ##args) +#define dbg_vhci_rx(fmt, args...) \ + dbg_with_flag(usbip_debug_vhci_rx, fmt , ##args) +#define dbg_vhci_tx(fmt, args...) \ + dbg_with_flag(usbip_debug_vhci_tx, fmt , ##args) +#define dbg_vhci_sysfs(fmt, args...) \ + dbg_with_flag(usbip_debug_vhci_sysfs, fmt , ##args) + +#define dbg_stub_cmp(fmt, args...) \ + dbg_with_flag(usbip_debug_stub_cmp, fmt , ##args) +#define dbg_stub_rx(fmt, args...) \ + dbg_with_flag(usbip_debug_stub_rx, fmt , ##args) +#define dbg_stub_tx(fmt, args...) \ + dbg_with_flag(usbip_debug_stub_tx, fmt , ##args) /** @@ -118,8 +127,8 @@ do { \ printk(KERN_ERR "%-10s: ***ERROR*** (%s,%d) %s: " fmt, \ (in_interrupt() ? "interrupt" : (current)->comm),\ - __FILE__, __LINE__, __FUNCTION__ , ##args); \ - } while(0) + __FILE__, __LINE__, __func__, ##args); \ + } while (0) /** * uinfo - print information messages @@ -129,7 +138,7 @@ #define uinfo(fmt, args...) \ do { \ printk(KERN_INFO "usbip: " fmt , ## args); \ - } while(0) + } while (0) /*-------------------------------------------------------------------------*/ @@ -170,7 +179,7 @@ /* devid is used to specify a remote USB device uniquely instead * of busnum and devnum in Linux. In the case of Linux stub_driver, * this value is ((busnum << 16) | devnum) */ - __u32 devid; + __u32 devid; #define USBIP_DIR_OUT 0 #define USBIP_DIR_IN 1 @@ -203,7 +212,7 @@ /* set setup packet data for a CTRL request */ unsigned char setup[8]; -}__attribute__ ((packed)); +} __attribute__ ((packed)); /* * An additional header for a RET_SUBMIT packet. @@ -214,14 +223,14 @@ __s32 start_frame; /* ISO and INT */ __s32 number_of_packets; /* ISO only */ __s32 error_count; /* ISO only */ -}__attribute__ ((packed)); +} __attribute__ ((packed)); /* * An additional header for a CMD_UNLINK packet. */ struct usbip_header_cmd_unlink { __u32 seqnum; /* URB's seqnum which will be unlinked */ -}__attribute__ ((packed)); +} __attribute__ ((packed)); /* @@ -229,7 +238,7 @@ */ struct usbip_header_ret_unlink { __s32 status; -}__attribute__ ((packed)); +} __attribute__ ((packed)); /* the same as usb_iso_packet_descriptor but packed for pdu */ @@ -238,7 +247,7 @@ __u32 length; /* expected length */ __u32 actual_length; __u32 status; -}__attribute__ ((packed)); +} __attribute__ ((packed)); /* @@ -253,7 +262,7 @@ struct usbip_header_cmd_unlink cmd_unlink; struct usbip_header_ret_unlink ret_unlink; } u; -}__attribute__ ((packed)); +} __attribute__ ((packed)); @@ -261,8 +270,8 @@ /*-------------------------------------------------------------------------*/ -int usbip_xmit(int , struct socket *, char *, int , int ); -int usbip_sendmsg(struct socket *, struct msghdr *, int ); +int usbip_xmit(int, struct socket *, char *, int, int); +int usbip_sendmsg(struct socket *, struct msghdr *, int); static inline int interface_to_busnum(struct usb_interface *interface) @@ -292,7 +301,7 @@ struct socket *sockfd_to_socket(unsigned int); int set_sockaddr(struct socket *socket, struct sockaddr_storage *ss); -void usbip_dump_urb (struct urb *purb); +void usbip_dump_urb(struct urb *purb); void usbip_dump_header(struct usbip_header *pdu); @@ -327,7 +336,7 @@ }; /* a common structure for stub_device and vhci_device */ -struct usbip_device{ +struct usbip_device { enum usbip_side side; enum usbip_status status; @@ -346,16 +355,16 @@ #define USBIP_EH_RESET (1 << 2) #define USBIP_EH_UNUSABLE (1 << 3) -#define SDEV_EVENT_REMOVED ( USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE ) -#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) +#define SDEV_EVENT_REMOVED (USBIP_EH_SHUTDOWN | USBIP_EH_RESET | USBIP_EH_BYE) +#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) unsigned long event; struct usbip_task eh; @@ -369,13 +378,15 @@ }; -void usbip_task_init(struct usbip_task *ut, char *, void (*loop_ops)(struct usbip_task *)); +void usbip_task_init(struct usbip_task *ut, char *, + void (*loop_ops)(struct usbip_task *)); void usbip_start_threads(struct usbip_device *ud); void usbip_stop_threads(struct usbip_device *ud); int usbip_thread(void *param); -void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, int pack); +void usbip_pack_pdu(struct usbip_header *pdu, struct urb *urb, int cmd, + int pack); void usbip_header_correct_endian(struct usbip_header *pdu, int send); /* some members of urb must be substituted before. */