X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=include%2Flinux%2Fusb.h;h=3aa2cd1f8d082fd699a5fcfb672e2dd555ea7dcc;hb=e4636d535e32768c8c500641ddb144f56e3dc5c0;hp=019ae963a9fec1f6a755fd87b4721bcb971dc474;hpb=5e60a16139c2a48b9876b0ff910671eee5fb32ec;p=safe%2Fjmp%2Flinux-2.6 diff --git a/include/linux/usb.h b/include/linux/usb.h index 019ae96..3aa2cd1 100644 --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -23,6 +23,7 @@ struct usb_device; struct usb_driver; +struct wusb_dev; /*-------------------------------------------------------------------------*/ @@ -94,10 +95,9 @@ enum usb_interface_condition { * @altsetting: array of interface structures, one for each alternate * setting that may be selected. Each one includes a set of * endpoint configurations. They will be in no particular order. - * @num_altsetting: number of altsettings defined. * @cur_altsetting: the current altsetting. + * @num_altsetting: number of altsettings defined. * @intf_assoc: interface association descriptor - * @driver: the USB driver that is bound to this interface. * @minor: the minor number assigned to this interface, if this * interface is bound to a driver that uses the USB major number. * If this interface does not use the USB major, this field should @@ -107,13 +107,25 @@ enum usb_interface_condition { * @condition: binding state of the interface: not bound, binding * (in probe()), bound to a driver, or unbinding (in disconnect()) * @is_active: flag set when the interface is bound and not suspended. + * @sysfs_files_created: sysfs attributes exist + * @ep_devs_created: endpoint child pseudo-devices exist + * @unregistering: flag set when the interface is being unregistered * @needs_remote_wakeup: flag set when the driver requires remote-wakeup * capability during autosuspend. + * @needs_altsetting0: flag set when a set-interface request for altsetting 0 + * has been deferred. + * @needs_binding: flag set when the driver should be re-probed or unbound + * following a reset or suspend operation it doesn't support. * @dev: driver model's view of this device * @usb_dev: if an interface is bound to the USB major, this will point * to the sysfs representation for that device. * @pm_usage_cnt: PM usage counter for this interface; autosuspend is not * allowed unless the counter is 0. + * @reset_ws: Used for scheduling resets from atomic context. + * @reset_running: set to 1 if the interface is currently running a + * queued reset so that usb_cancel_queued_reset() doesn't try to + * remove from the workqueue when running inside the worker + * thread. See __usb_queue_reset_device(). * * USB device drivers attach to interfaces on a physical device. Each * interface encapsulates a single high level function, such as feeding @@ -157,22 +169,29 @@ struct usb_interface { * bound to */ enum usb_interface_condition condition; /* state of binding */ unsigned is_active:1; /* the interface is not suspended */ + unsigned sysfs_files_created:1; /* the sysfs attributes exist */ + unsigned ep_devs_created:1; /* endpoint "devices" exist */ + unsigned unregistering:1; /* unregistration is in progress */ unsigned needs_remote_wakeup:1; /* driver requires remote wakeup */ + unsigned needs_altsetting0:1; /* switch to altsetting 0 is pending */ + unsigned needs_binding:1; /* needs delayed unbind/rebind */ + unsigned reset_running:1; struct device dev; /* interface specific device info */ - struct device *usb_dev; /* pointer to the usb class's device, if any */ + struct device *usb_dev; int pm_usage_cnt; /* usage counter for autosuspend */ + struct work_struct reset_ws; /* for resets in atomic context */ }; #define to_usb_interface(d) container_of(d, struct usb_interface, dev) #define interface_to_usbdev(intf) \ container_of(intf->dev.parent, struct usb_device, dev) -static inline void *usb_get_intfdata (struct usb_interface *intf) +static inline void *usb_get_intfdata(struct usb_interface *intf) { - return dev_get_drvdata (&intf->dev); + return dev_get_drvdata(&intf->dev); } -static inline void usb_set_intfdata (struct usb_interface *intf, void *data) +static inline void usb_set_intfdata(struct usb_interface *intf, void *data) { dev_set_drvdata(&intf->dev, data); } @@ -273,9 +292,10 @@ struct usb_host_config { int __usb_get_extra_descriptor(char *buffer, unsigned size, unsigned char type, void **ptr); -#define usb_get_extra_descriptor(ifpoint,type,ptr)\ - __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,\ - type,(void**)ptr) +#define usb_get_extra_descriptor(ifpoint, type, ptr) \ + __usb_get_extra_descriptor((ifpoint)->extra, \ + (ifpoint)->extralen, \ + type, (void **)ptr) /* ----------------------------------------------------------------------- */ @@ -290,7 +310,7 @@ struct usb_devmap { struct usb_bus { struct device *controller; /* host/master side hardware */ int busnum; /* Bus number (in order of reg) */ - char *bus_name; /* stable id (PCI slot_name etc) */ + const char *bus_name; /* stable id (PCI slot_name etc) */ u8 uses_dma; /* Does the host controller use DMA? */ u8 otg_port; /* 0, or number of OTG/HNP port */ unsigned is_b_host:1; /* true during some HNP roleswitches */ @@ -316,9 +336,9 @@ struct usb_bus { #ifdef CONFIG_USB_DEVICEFS struct dentry *usbfs_dentry; /* usbfs dentry entry for the bus */ #endif - struct class_device *class_dev; /* class device for this bus */ + struct device *dev; /* device for this bus */ -#if defined(CONFIG_USB_MON) +#if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE) struct mon_bus *mon_bus; /* non-null when associated */ int monitored; /* non-zero when monitored */ #endif @@ -339,89 +359,150 @@ struct usb_bus { struct usb_tt; -/* +/** * struct usb_device - kernel's representation of a USB device - * - * FIXME: Write the kerneldoc! - * + * @devnum: device number; address on a USB bus + * @devpath: device ID string for use in messages (e.g., /port/...) + * @state: device state: configured, not attached, etc. + * @speed: device speed: high/full/low (or error) + * @tt: Transaction Translator info; used with low/full speed dev, highspeed hub + * @ttport: device port on that tt hub + * @toggle: one bit for each endpoint, with ([0] = IN, [1] = OUT) endpoints + * @parent: our hub, unless we're the root + * @bus: bus we're part of + * @ep0: endpoint 0 data (default control pipe) + * @dev: generic device interface + * @descriptor: USB device descriptor + * @config: all of the device's configs + * @actconfig: the active configuration + * @ep_in: array of IN endpoints + * @ep_out: array of OUT endpoints + * @rawdescriptors: raw descriptors for each config + * @bus_mA: Current available from the bus + * @portnum: parent port number (origin 1) + * @level: number of USB hub ancestors + * @can_submit: URBs may be submitted + * @discon_suspended: disconnected while suspended + * @persist_enabled: USB_PERSIST enabled for this device + * @have_langid: whether string_langid is valid + * @authorized: policy has said we can use it; + * (user space) policy determines if we authorize this device to be + * used or not. By default, wired USB devices are authorized. + * WUSB devices are not, until we authorize them from user space. + * FIXME -- complete doc + * @authenticated: Crypto authentication passed + * @wusb: device is Wireless USB + * @string_langid: language ID for strings + * @product: iProduct string, if present (static) + * @manufacturer: iManufacturer string, if present (static) + * @serial: iSerialNumber string, if present (static) + * @filelist: usbfs files that are open to this device + * @usb_classdev: USB class device that was created for usbfs device + * access from userspace + * @usbfs_dentry: usbfs dentry entry for the device + * @maxchild: number of ports if hub + * @children: child devices - USB devices that are attached to this hub + * @pm_usage_cnt: usage counter for autosuspend + * @quirks: quirks of the whole device + * @urbnum: number of URBs submitted for the whole device + * @active_duration: total time device is not suspended + * @autosuspend: for delayed autosuspends + * @autoresume: for autoresumes requested while in_interrupt + * @pm_mutex: protects PM operations + * @last_busy: time of last use + * @autosuspend_delay: in jiffies + * @connect_time: time device was first connected + * @auto_pm: autosuspend/resume in progress + * @do_remote_wakeup: remote wakeup should be enabled + * @reset_resume: needs reset instead of resume + * @autosuspend_disabled: autosuspend disabled by the user + * @autoresume_disabled: autoresume disabled by the user + * @skip_sys_resume: skip the next system resume + * @wusb_dev: if this is a Wireless USB device, link to the WUSB + * specific data for the device. + * + * Notes: * Usbcore drivers should not set usbdev->state directly. Instead use * usb_set_device_state(). */ struct usb_device { - int devnum; /* Address on USB bus */ - char devpath [16]; /* Use in messages: /port/port/... */ - enum usb_device_state state; /* configured, not attached, etc */ - enum usb_device_speed speed; /* high/full/low (or error) */ + int devnum; + char devpath [16]; + enum usb_device_state state; + enum usb_device_speed speed; - struct usb_tt *tt; /* low/full speed dev, highspeed hub */ - int ttport; /* device port on that tt hub */ + struct usb_tt *tt; + int ttport; - unsigned int toggle[2]; /* one bit for each endpoint - * ([0] = IN, [1] = OUT) */ + unsigned int toggle[2]; - struct usb_device *parent; /* our hub, unless we're the root */ - struct usb_bus *bus; /* Bus we're part of */ + struct usb_device *parent; + struct usb_bus *bus; struct usb_host_endpoint ep0; - struct device dev; /* Generic device interface */ + struct device dev; - struct usb_device_descriptor descriptor;/* Descriptor */ - struct usb_host_config *config; /* All of the configs */ + struct usb_device_descriptor descriptor; + struct usb_host_config *config; - struct usb_host_config *actconfig;/* the active configuration */ + struct usb_host_config *actconfig; struct usb_host_endpoint *ep_in[16]; struct usb_host_endpoint *ep_out[16]; - char **rawdescriptors; /* Raw descriptors for each config */ + char **rawdescriptors; - unsigned short bus_mA; /* Current available from the bus */ - u8 portnum; /* Parent port number (origin 1) */ - u8 level; /* Number of USB hub ancestors */ + unsigned short bus_mA; + u8 portnum; + u8 level; - unsigned discon_suspended:1; /* Disconnected while suspended */ - unsigned have_langid:1; /* whether string_langid is valid */ - int string_langid; /* language ID for strings */ + unsigned can_submit:1; + unsigned discon_suspended:1; + unsigned persist_enabled:1; + unsigned have_langid:1; + unsigned authorized:1; + unsigned authenticated:1; + unsigned wusb:1; + int string_langid; /* static strings from the device */ - char *product; /* iProduct string, if present */ - char *manufacturer; /* iManufacturer string, if present */ - char *serial; /* iSerialNumber string, if present */ + char *product; + char *manufacturer; + char *serial; struct list_head filelist; #ifdef CONFIG_USB_DEVICE_CLASS struct device *usb_classdev; #endif #ifdef CONFIG_USB_DEVICEFS - struct dentry *usbfs_dentry; /* usbfs dentry entry for the device */ + struct dentry *usbfs_dentry; #endif - /* - * Child devices - these can be either new devices - * (if this is a hub device), or different instances - * of this same device. - * - * Each instance needs its own set of data structures. - */ - int maxchild; /* Number of ports if hub */ + int maxchild; struct usb_device *children[USB_MAXCHILDREN]; - int pm_usage_cnt; /* usage counter for autosuspend */ - u32 quirks; /* quirks of the whole device */ + int pm_usage_cnt; + u32 quirks; + atomic_t urbnum; + + unsigned long active_duration; #ifdef CONFIG_PM - struct delayed_work autosuspend; /* for delayed autosuspends */ - struct mutex pm_mutex; /* protects PM operations */ - - unsigned long last_busy; /* time of last use */ - int autosuspend_delay; /* in jiffies */ - - unsigned auto_pm:1; /* autosuspend/resume in progress */ - unsigned do_remote_wakeup:1; /* remote wakeup should be enabled */ - unsigned reset_resume:1; /* needs reset instead of resume */ - unsigned persist_enabled:1; /* USB_PERSIST enabled for this dev */ - unsigned autosuspend_disabled:1; /* autosuspend and autoresume */ - unsigned autoresume_disabled:1; /* disabled by the user */ + struct delayed_work autosuspend; + struct work_struct autoresume; + struct mutex pm_mutex; + + unsigned long last_busy; + int autosuspend_delay; + unsigned long connect_time; + + unsigned auto_pm:1; + unsigned do_remote_wakeup:1; + unsigned reset_resume:1; + unsigned autosuspend_disabled:1; + unsigned autoresume_disabled:1; + unsigned skip_sys_resume:1; #endif + struct wusb_dev *wusb_dev; }; #define to_usb_device(d) container_of(d, struct usb_device, dev) @@ -437,8 +518,7 @@ extern int usb_lock_device_for_reset(struct usb_device *udev, /* USB port reset for device reinitialization */ extern int usb_reset_device(struct usb_device *dev); -extern int usb_reset_composite_device(struct usb_device *dev, - struct usb_interface *iface); +extern void usb_queue_reset_device(struct usb_interface *dev); extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id); @@ -447,6 +527,8 @@ extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id); extern int usb_autopm_set_interface(struct usb_interface *intf); extern int usb_autopm_get_interface(struct usb_interface *intf); extern void usb_autopm_put_interface(struct usb_interface *intf); +extern int usb_autopm_get_interface_async(struct usb_interface *intf); +extern void usb_autopm_put_interface_async(struct usb_interface *intf); static inline void usb_autopm_enable(struct usb_interface *intf) { @@ -473,8 +555,13 @@ static inline int usb_autopm_set_interface(struct usb_interface *intf) static inline int usb_autopm_get_interface(struct usb_interface *intf) { return 0; } +static inline int usb_autopm_get_interface_async(struct usb_interface *intf) +{ return 0; } + static inline void usb_autopm_put_interface(struct usb_interface *intf) { } +static inline void usb_autopm_put_interface_async(struct usb_interface *intf) +{ } static inline void usb_autopm_enable(struct usb_interface *intf) { } static inline void usb_autopm_disable(struct usb_interface *intf) @@ -486,11 +573,11 @@ static inline void usb_mark_last_busy(struct usb_device *udev) /*-------------------------------------------------------------------------*/ /* for drivers using iso endpoints */ -extern int usb_get_current_frame_number (struct usb_device *usb_dev); +extern int usb_get_current_frame_number(struct usb_device *usb_dev); /* used these for multi-interface device registration */ extern int usb_driver_claim_interface(struct usb_driver *driver, - struct usb_interface *iface, void* priv); + struct usb_interface *iface, void *priv); /** * usb_interface_claimed - returns true iff an interface is claimed @@ -502,7 +589,8 @@ extern int usb_driver_claim_interface(struct usb_driver *driver, * may need to explicitly claim that lock. * */ -static inline int usb_interface_claimed(struct usb_interface *iface) { +static inline int usb_interface_claimed(struct usb_interface *iface) +{ return (iface->dev.driver != NULL); } @@ -545,186 +633,16 @@ extern struct usb_host_interface *usb_altnum_to_altsetting( * USB 2.0 root hubs (EHCI host controllers) will get one path ID if they are * high speed, and a different one if they are full or low speed. */ -static inline int usb_make_path (struct usb_device *dev, char *buf, - size_t size) +static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size) { int actual; - actual = snprintf (buf, size, "usb-%s-%s", dev->bus->bus_name, - dev->devpath); + actual = snprintf(buf, size, "usb-%s-%s", dev->bus->bus_name, + dev->devpath); return (actual >= (int)size) ? -1 : actual; } /*-------------------------------------------------------------------------*/ -/** - * usb_endpoint_num - get the endpoint's number - * @epd: endpoint to be checked - * - * Returns @epd's number: 0 to 15. - */ -static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd) -{ - return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; -} - -/** - * usb_endpoint_type - get the endpoint's transfer type - * @epd: endpoint to be checked - * - * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according - * to @epd's transfer type. - */ -static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd) -{ - return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; -} - -/** - * usb_endpoint_dir_in - check if the endpoint has IN direction - * @epd: endpoint to be checked - * - * Returns true if the endpoint is of type IN, otherwise it returns false. - */ -static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd) -{ - return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN); -} - -/** - * usb_endpoint_dir_out - check if the endpoint has OUT direction - * @epd: endpoint to be checked - * - * Returns true if the endpoint is of type OUT, otherwise it returns false. - */ -static inline int usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd) -{ - return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT); -} - -/** - * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type - * @epd: endpoint to be checked - * - * Returns true if the endpoint is of type bulk, otherwise it returns false. - */ -static inline int usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd) -{ - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == - USB_ENDPOINT_XFER_BULK); -} - -/** - * usb_endpoint_xfer_control - check if the endpoint has control transfer type - * @epd: endpoint to be checked - * - * Returns true if the endpoint is of type control, otherwise it returns false. - */ -static inline int usb_endpoint_xfer_control(const struct usb_endpoint_descriptor *epd) -{ - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == - USB_ENDPOINT_XFER_CONTROL); -} - -/** - * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type - * @epd: endpoint to be checked - * - * Returns true if the endpoint is of type interrupt, otherwise it returns - * false. - */ -static inline int usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd) -{ - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == - USB_ENDPOINT_XFER_INT); -} - -/** - * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type - * @epd: endpoint to be checked - * - * Returns true if the endpoint is of type isochronous, otherwise it returns - * false. - */ -static inline int usb_endpoint_xfer_isoc(const struct usb_endpoint_descriptor *epd) -{ - return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == - USB_ENDPOINT_XFER_ISOC); -} - -/** - * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN - * @epd: endpoint to be checked - * - * Returns true if the endpoint has bulk transfer type and IN direction, - * otherwise it returns false. - */ -static inline int usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd) -{ - return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd)); -} - -/** - * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT - * @epd: endpoint to be checked - * - * Returns true if the endpoint has bulk transfer type and OUT direction, - * otherwise it returns false. - */ -static inline int usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd) -{ - return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd)); -} - -/** - * usb_endpoint_is_int_in - check if the endpoint is interrupt IN - * @epd: endpoint to be checked - * - * Returns true if the endpoint has interrupt transfer type and IN direction, - * otherwise it returns false. - */ -static inline int usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd) -{ - return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd)); -} - -/** - * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT - * @epd: endpoint to be checked - * - * Returns true if the endpoint has interrupt transfer type and OUT direction, - * otherwise it returns false. - */ -static inline int usb_endpoint_is_int_out(const struct usb_endpoint_descriptor *epd) -{ - return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd)); -} - -/** - * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN - * @epd: endpoint to be checked - * - * Returns true if the endpoint has isochronous transfer type and IN direction, - * otherwise it returns false. - */ -static inline int usb_endpoint_is_isoc_in(const struct usb_endpoint_descriptor *epd) -{ - return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd)); -} - -/** - * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT - * @epd: endpoint to be checked - * - * Returns true if the endpoint has isochronous transfer type and OUT direction, - * otherwise it returns false. - */ -static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor *epd) -{ - return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd)); -} - -/*-------------------------------------------------------------------------*/ - #define USB_DEVICE_ID_MATCH_DEVICE \ (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT) #define USB_DEVICE_ID_MATCH_DEV_RANGE \ @@ -749,11 +667,11 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * specific device. */ #define USB_DEVICE(vend,prod) \ - .match_flags = USB_DEVICE_ID_MATCH_DEVICE, .idVendor = (vend), \ - .idProduct = (prod) + .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \ + .idVendor = (vend), \ + .idProduct = (prod) /** - * USB_DEVICE_VER - macro used to describe a specific usb device with a - * version range + * USB_DEVICE_VER - describe a specific usb device with a version range * @vend: the 16 bit USB Vendor ID * @prod: the 16 bit USB Product ID * @lo: the bcdDevice_lo value @@ -762,14 +680,15 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific device, with a version range. */ -#define USB_DEVICE_VER(vend,prod,lo,hi) \ +#define USB_DEVICE_VER(vend, prod, lo, hi) \ .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, \ - .idVendor = (vend), .idProduct = (prod), \ - .bcdDevice_lo = (lo), .bcdDevice_hi = (hi) + .idVendor = (vend), \ + .idProduct = (prod), \ + .bcdDevice_lo = (lo), \ + .bcdDevice_hi = (hi) /** - * USB_DEVICE_INTERFACE_PROTOCOL - macro used to describe a usb - * device with a specific interface protocol + * USB_DEVICE_INTERFACE_PROTOCOL - describe a usb device with a specific interface protocol * @vend: the 16 bit USB Vendor ID * @prod: the 16 bit USB Product ID * @pr: bInterfaceProtocol value @@ -777,8 +696,9 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific interface protocol of devices. */ -#define USB_DEVICE_INTERFACE_PROTOCOL(vend,prod,pr) \ - .match_flags = USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ +#define USB_DEVICE_INTERFACE_PROTOCOL(vend, prod, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE | \ + USB_DEVICE_ID_MATCH_INT_PROTOCOL, \ .idVendor = (vend), \ .idProduct = (prod), \ .bInterfaceProtocol = (pr) @@ -792,12 +712,14 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific class of devices. */ -#define USB_DEVICE_INFO(cl,sc,pr) \ - .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, .bDeviceClass = (cl), \ - .bDeviceSubClass = (sc), .bDeviceProtocol = (pr) +#define USB_DEVICE_INFO(cl, sc, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_DEV_INFO, \ + .bDeviceClass = (cl), \ + .bDeviceSubClass = (sc), \ + .bDeviceProtocol = (pr) /** - * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces + * USB_INTERFACE_INFO - macro used to describe a class of usb interfaces * @cl: bInterfaceClass value * @sc: bInterfaceSubClass value * @pr: bInterfaceProtocol value @@ -805,13 +727,14 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This macro is used to create a struct usb_device_id that matches a * specific class of interfaces. */ -#define USB_INTERFACE_INFO(cl,sc,pr) \ - .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, .bInterfaceClass = (cl), \ - .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr) +#define USB_INTERFACE_INFO(cl, sc, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \ + .bInterfaceClass = (cl), \ + .bInterfaceSubClass = (sc), \ + .bInterfaceProtocol = (pr) /** - * USB_DEVICE_AND_INTERFACE_INFO - macro used to describe a specific usb device - * with a class of usb interfaces + * USB_DEVICE_AND_INTERFACE_INFO - describe a specific usb device with a class of usb interfaces * @vend: the 16 bit USB Vendor ID * @prod: the 16 bit USB Product ID * @cl: bInterfaceClass value @@ -824,12 +747,14 @@ static inline int usb_endpoint_is_isoc_out(const struct usb_endpoint_descriptor * This is especially useful when explicitly matching devices that have * vendor specific bDeviceClass values, but standards-compliant interfaces. */ -#define USB_DEVICE_AND_INTERFACE_INFO(vend,prod,cl,sc,pr) \ +#define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \ .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \ | USB_DEVICE_ID_MATCH_DEVICE, \ - .idVendor = (vend), .idProduct = (prod), \ + .idVendor = (vend), \ + .idProduct = (prod), \ .bInterfaceClass = (cl), \ - .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr) + .bInterfaceSubClass = (sc), \ + .bInterfaceProtocol = (pr) /* ----------------------------------------------------------------------- */ @@ -864,10 +789,11 @@ struct usbdrv_wrap { * and should normally be the same as the module name. * @probe: Called to see if the driver is willing to manage a particular * interface on a device. If it is, probe returns zero and uses - * dev_set_drvdata() to associate driver-specific data with the + * usb_set_intfdata() to associate driver-specific data with the * interface. It may also use usb_set_interface() to specify the * appropriate altsetting. If unwilling to manage the interface, - * return a negative errno value. + * return -ENODEV, if genuine IO errors occured, an appropriate + * negative errno value. * @disconnect: Called when the interface is no longer accessible, usually * because its device has been (or is being) disconnected or the * driver module is being unloaded. @@ -879,13 +805,10 @@ struct usbdrv_wrap { * @resume: Called when the device is being resumed by the system. * @reset_resume: Called when the suspended device has been reset instead * of being resumed. - * @pre_reset: Called by usb_reset_composite_device() when the device + * @pre_reset: Called by usb_reset_device() when the device * is about to be reset. - * @post_reset: Called by usb_reset_composite_device() after the device - * has been reset, or in lieu of @resume following a reset-resume - * (i.e., the device is reset instead of being resumed, as might - * happen if power was lost). The second argument tells which is - * the reason. + * @post_reset: Called by usb_reset_device() after the device + * has been reset * @id_table: USB drivers use ID table to support hotplugging. * Export this with MODULE_DEVICE_TABLE(usb,...). This must be set * or your driver's probe function will never get called. @@ -896,6 +819,8 @@ struct usbdrv_wrap { * added to this driver by preventing the sysfs file from being created. * @supports_autosuspend: if set to 0, the USB core will not allow autosuspend * for interfaces bound to this driver. + * @soft_unbind: if set to 1, the USB core will not kill URBs and disable + * endpoints before calling the driver's disconnect method. * * USB interface drivers must provide a name, probe() and disconnect() * methods, and an id_table. Other driver fields are optional. @@ -936,6 +861,7 @@ struct usb_driver { struct usbdrv_wrap drvwrap; unsigned int no_dynamic_id:1; unsigned int supports_autosuspend:1; + unsigned int soft_unbind:1; }; #define to_usb_driver(d) container_of(d, struct usb_driver, drvwrap.driver) @@ -965,7 +891,7 @@ struct usb_device_driver { void (*disconnect) (struct usb_device *udev); int (*suspend) (struct usb_device *udev, pm_message_t message); - int (*resume) (struct usb_device *udev); + int (*resume) (struct usb_device *udev, pm_message_t message); struct usbdrv_wrap drvwrap; unsigned int supports_autosuspend:1; }; @@ -1052,6 +978,7 @@ struct usb_anchor { struct list_head urb_list; wait_queue_head_t wait; spinlock_t lock; + unsigned int poisoned:1; }; static inline void init_usb_anchor(struct usb_anchor *anchor) @@ -1107,7 +1034,7 @@ typedef void (*usb_complete_t)(struct urb *); * transferred. It will normally be the same as requested, unless * either an error was reported or a short read was performed. * The URB_SHORT_NOT_OK transfer flag may be used to make such - * short reads be reported as errors. + * short reads be reported as errors. * @setup_packet: Only used for control transfers, this points to eight bytes * of setup data. Control transfers always start by sending this data * to the device. Then transfer_buffer is read or written, if needed. @@ -1126,7 +1053,7 @@ typedef void (*usb_complete_t)(struct urb *); * @complete: Completion handler. This URB is passed as the parameter to the * completion function. The completion function may then do what * it likes with the URB, including resubmitting or freeing it. - * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to + * @iso_frame_desc: Used to provide arrays of ISO transfer buffers and to * collect the transfer status for each buffer. * * This structure identifies USB transfer requests. URBs must be allocated by @@ -1230,29 +1157,28 @@ typedef void (*usb_complete_t)(struct urb *); * when the urb is owned by the hcd, that is, since the call to * usb_submit_urb() till the entry into the completion routine. */ -struct urb -{ +struct urb { /* private: usb core and host controller only fields in the urb */ struct kref kref; /* reference count of the URB */ - spinlock_t lock; /* lock for the URB */ void *hcpriv; /* private data for host controller */ atomic_t use_count; /* concurrent submissions counter */ - u8 reject; /* submissions will fail */ + atomic_t reject; /* submissions will fail */ + int unlinked; /* unlink error code */ /* public: documented fields in the urb that can be used by drivers */ struct list_head urb_list; /* list head for use by the urb's * current owner */ - struct list_head anchor_list; /* the URB may be anchored by the driver */ + struct list_head anchor_list; /* the URB may be anchored */ struct usb_anchor *anchor; struct usb_device *dev; /* (in) pointer to associated device */ - struct usb_host_endpoint *ep; /* (internal) pointer to endpoint struct */ + struct usb_host_endpoint *ep; /* (internal) pointer to endpoint */ unsigned int pipe; /* (in) pipe information */ int status; /* (return) non-ISO status */ unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ void *transfer_buffer; /* (in) associated data buffer */ dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */ - int transfer_buffer_length; /* (in) data buffer length */ - int actual_length; /* (return) actual transfer length */ + u32 transfer_buffer_length; /* (in) data buffer length */ + u32 actual_length; /* (return) actual transfer length */ unsigned char *setup_packet; /* (in) setup packet (control only) */ dma_addr_t setup_dma; /* (in) dma addr for setup_packet */ int start_frame; /* (modify) start frame (ISO) */ @@ -1282,16 +1208,15 @@ struct urb * Initializes a control urb with the proper information needed to submit * it to a device. */ -static inline void usb_fill_control_urb (struct urb *urb, - struct usb_device *dev, - unsigned int pipe, - unsigned char *setup_packet, - void *transfer_buffer, - int buffer_length, - usb_complete_t complete_fn, - void *context) +static inline void usb_fill_control_urb(struct urb *urb, + struct usb_device *dev, + unsigned int pipe, + unsigned char *setup_packet, + void *transfer_buffer, + int buffer_length, + usb_complete_t complete_fn, + void *context) { - spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->setup_packet = setup_packet; @@ -1314,15 +1239,14 @@ static inline void usb_fill_control_urb (struct urb *urb, * Initializes a bulk urb with the proper information needed to submit it * to a device. */ -static inline void usb_fill_bulk_urb (struct urb *urb, - struct usb_device *dev, - unsigned int pipe, - void *transfer_buffer, - int buffer_length, - usb_complete_t complete_fn, - void *context) +static inline void usb_fill_bulk_urb(struct urb *urb, + struct usb_device *dev, + unsigned int pipe, + void *transfer_buffer, + int buffer_length, + usb_complete_t complete_fn, + void *context) { - spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; @@ -1349,16 +1273,15 @@ static inline void usb_fill_bulk_urb (struct urb *urb, * the endpoint interval, and express polling intervals in microframes * (eight per millisecond) rather than in frames (one per millisecond). */ -static inline void usb_fill_int_urb (struct urb *urb, - struct usb_device *dev, - unsigned int pipe, - void *transfer_buffer, - int buffer_length, - usb_complete_t complete_fn, - void *context, - int interval) +static inline void usb_fill_int_urb(struct urb *urb, + struct usb_device *dev, + unsigned int pipe, + void *transfer_buffer, + int buffer_length, + usb_complete_t complete_fn, + void *context, + int interval) { - spin_lock_init(&urb->lock); urb->dev = dev; urb->pipe = pipe; urb->transfer_buffer = transfer_buffer; @@ -1380,11 +1303,19 @@ extern struct urb *usb_get_urb(struct urb *urb); extern int usb_submit_urb(struct urb *urb, gfp_t mem_flags); extern int usb_unlink_urb(struct urb *urb); extern void usb_kill_urb(struct urb *urb); +extern void usb_poison_urb(struct urb *urb); +extern void usb_unpoison_urb(struct urb *urb); extern void usb_kill_anchored_urbs(struct usb_anchor *anchor); +extern void usb_poison_anchored_urbs(struct usb_anchor *anchor); +extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor); +extern void usb_unlink_anchored_urbs(struct usb_anchor *anchor); extern void usb_anchor_urb(struct urb *urb, struct usb_anchor *anchor); extern void usb_unanchor_urb(struct urb *urb); extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, unsigned int timeout); +extern struct urb *usb_get_from_anchor(struct usb_anchor *anchor); +extern void usb_scuttle_anchored_urbs(struct usb_anchor *anchor); +extern int usb_anchor_empty(struct usb_anchor *anchor); /** * usb_urb_dir_in - check if an URB describes an IN transfer @@ -1395,7 +1326,7 @@ extern int usb_wait_anchor_empty_timeout(struct usb_anchor *anchor, */ static inline int usb_urb_dir_in(struct urb *urb) { - return (urb->transfer_flags & URB_DIR_MASK) != URB_DIR_OUT; + return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_IN; } /** @@ -1410,15 +1341,15 @@ static inline int usb_urb_dir_out(struct urb *urb) return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT; } -void *usb_buffer_alloc (struct usb_device *dev, size_t size, +void *usb_buffer_alloc(struct usb_device *dev, size_t size, gfp_t mem_flags, dma_addr_t *dma); -void usb_buffer_free (struct usb_device *dev, size_t size, +void usb_buffer_free(struct usb_device *dev, size_t size, void *addr, dma_addr_t dma); #if 0 -struct urb *usb_buffer_map (struct urb *urb); -void usb_buffer_dmasync (struct urb *urb); -void usb_buffer_unmap (struct urb *urb); +struct urb *usb_buffer_map(struct urb *urb); +void usb_buffer_dmasync(struct urb *urb); +void usb_buffer_unmap(struct urb *urb); #endif struct scatterlist; @@ -1456,6 +1387,7 @@ extern int usb_string(struct usb_device *dev, int index, extern int usb_clear_halt(struct usb_device *dev, int pipe); extern int usb_reset_configuration(struct usb_device *dev); extern int usb_set_interface(struct usb_device *dev, int ifnum, int alternate); +extern void usb_reset_endpoint(struct usb_device *dev, unsigned int epaddr); /* this request isn't really synchronous, but it belongs with the others */ extern int usb_driver_set_configuration(struct usb_device *udev, int config); @@ -1490,7 +1422,7 @@ struct usb_sg_request { int status; size_t bytes; - /* + /* * members below are private: to usbcore, * and are not provided for driver access! */ @@ -1508,18 +1440,18 @@ struct usb_sg_request { struct completion complete; }; -int usb_sg_init ( +int usb_sg_init( struct usb_sg_request *io, struct usb_device *dev, - unsigned pipe, + unsigned pipe, unsigned period, struct scatterlist *sg, int nents, size_t length, gfp_t mem_flags ); -void usb_sg_cancel (struct usb_sg_request *io); -void usb_sg_wait (struct usb_sg_request *io); +void usb_sg_cancel(struct usb_sg_request *io); +void usb_sg_wait(struct usb_sg_request *io); /* ----------------------------------------------------------------------- */ @@ -1560,14 +1492,6 @@ void usb_sg_wait (struct usb_sg_request *io); #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL) #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK) -/* The D0/D1 toggle bits ... USE WITH CAUTION (they're almost hcd-internal) */ -#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1) -#define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << (ep))) -#define usb_settoggle(dev, ep, out, bit) \ - ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | \ - ((bit) << (ep))) - - static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int endpoint) { @@ -1576,21 +1500,21 @@ static inline unsigned int __create_pipe(struct usb_device *dev, /* Create various pipes... */ #define usb_sndctrlpipe(dev,endpoint) \ - ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint)) + ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint)) #define usb_rcvctrlpipe(dev,endpoint) \ - ((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_CONTROL << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) #define usb_sndisocpipe(dev,endpoint) \ - ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint)) + ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint)) #define usb_rcvisocpipe(dev,endpoint) \ - ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) #define usb_sndbulkpipe(dev,endpoint) \ - ((PIPE_BULK << 30) | __create_pipe(dev,endpoint)) + ((PIPE_BULK << 30) | __create_pipe(dev, endpoint)) #define usb_rcvbulkpipe(dev,endpoint) \ - ((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_BULK << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) #define usb_sndintpipe(dev,endpoint) \ - ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint)) + ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint)) #define usb_rcvintpipe(dev,endpoint) \ - ((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN) + ((PIPE_INTERRUPT << 30) | __create_pipe(dev, endpoint) | USB_DIR_IN) /*-------------------------------------------------------------------------*/ @@ -1631,13 +1555,8 @@ extern void usb_unregister_notify(struct notifier_block *nb); #define dbg(format, arg...) do {} while (0) #endif -#define err(format, arg...) printk(KERN_ERR "%s: " format "\n" , \ - __FILE__ , ## arg) -#define info(format, arg...) printk(KERN_INFO "%s: " format "\n" , \ - __FILE__ , ## arg) -#define warn(format, arg...) printk(KERN_WARNING "%s: " format "\n" , \ - __FILE__ , ## arg) - +#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \ + format "\n" , ## arg) #endif /* __KERNEL__ */