From 23cd138503f90ff6af109c0096727ba641942614 Mon Sep 17 00:00:00 2001 From: Remy Bohmer Date: Wed, 29 Jul 2009 18:18:43 +0200 Subject: Integrate USB gadget layer and USB CDC driver layer Derived from Linux kernel 2.6.27 Signed-off-by: Thomas Smits Signed-off-by: Remy Bohmer --- include/linux/usb/gadget.h | 871 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 871 insertions(+) create mode 100644 include/linux/usb/gadget.h (limited to 'include/linux/usb/gadget.h') diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h new file mode 100644 index 000000000..344fc787c --- /dev/null +++ b/include/linux/usb/gadget.h @@ -0,0 +1,871 @@ +/* + * + * + * We call the USB code inside a Linux-based peripheral device a "gadget" + * driver, except for the hardware-specific bus glue. One USB host can + * master many USB gadgets, but the gadgets are only slaved to one host. + * + * + * (C) Copyright 2002-2004 by David Brownell + * All Rights Reserved. + * + * This software is licensed under the GNU GPL version 2. + * + * Ported to U-boot by: Thomas Smits and + * Remy Bohmer + */ + +#ifndef __LINUX_USB_GADGET_H +#define __LINUX_USB_GADGET_H + +#include + +struct usb_ep; + +/** + * struct usb_request - describes one i/o request + * @buf: Buffer used for data. Always provide this; some controllers + * only use PIO, or don't use DMA for some endpoints. + * @dma: DMA address corresponding to 'buf'. If you don't set this + * field, and the usb controller needs one, it is responsible + * for mapping and unmapping the buffer. + * @length: Length of that data + * @no_interrupt: If true, hints that no completion irq is needed. + * Helpful sometimes with deep request queues that are handled + * directly by DMA controllers. + * @zero: If true, when writing data, makes the last packet be "short" + * by adding a zero length packet as needed; + * @short_not_ok: When reading data, makes short packets be + * treated as errors (queue stops advancing till cleanup). + * @complete: Function called when request completes, so this request and + * its buffer may be re-used. + * Reads terminate with a short packet, or when the buffer fills, + * whichever comes first. When writes terminate, some data bytes + * will usually still be in flight (often in a hardware fifo). + * Errors (for reads or writes) stop the queue from advancing + * until the completion function returns, so that any transfers + * invalidated by the error may first be dequeued. + * @context: For use by the completion callback + * @list: For use by the gadget driver. + * @status: Reports completion code, zero or a negative errno. + * Normally, faults block the transfer queue from advancing until + * the completion callback returns. + * Code "-ESHUTDOWN" indicates completion caused by device disconnect, + * or when the driver disabled the endpoint. + * @actual: Reports bytes transferred to/from the buffer. For reads (OUT + * transfers) this may be less than the requested length. If the + * short_not_ok flag is set, short reads are treated as errors + * even when status otherwise indicates successful completion. + * Note that for writes (IN transfers) some data bytes may still + * reside in a device-side FIFO when the request is reported as + * complete. + * + * These are allocated/freed through the endpoint they're used with. The + * hardware's driver can add extra per-request data to the memory it returns, + * which often avoids separate memory allocations (potential failures), + * later when the request is queued. + * + * Request flags affect request handling, such as whether a zero length + * packet is written (the "zero" flag), whether a short read should be + * treated as an error (blocking request queue advance, the "short_not_ok" + * flag), or hinting that an interrupt is not required (the "no_interrupt" + * flag, for use with deep request queues). + * + * Bulk endpoints can use any size buffers, and can also be used for interrupt + * transfers. interrupt-only endpoints can be much less functional. + */ + // NOTE this is analagous to 'struct urb' on the host side, + // except that it's thinner and promotes more pre-allocation. + +struct usb_request { + void *buf; + unsigned length; + dma_addr_t dma; + + unsigned no_interrupt:1; + unsigned zero:1; + unsigned short_not_ok:1; + + void (*complete)(struct usb_ep *ep, + struct usb_request *req); + void *context; + struct list_head list; + + int status; + unsigned actual; +}; + +/*-------------------------------------------------------------------------*/ + +/* endpoint-specific parts of the api to the usb controller hardware. + * unlike the urb model, (de)multiplexing layers are not required. + * (so this api could slash overhead if used on the host side...) + * + * note that device side usb controllers commonly differ in how many + * endpoints they support, as well as their capabilities. + */ +struct usb_ep_ops { + int (*enable) (struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc); + int (*disable) (struct usb_ep *ep); + + struct usb_request *(*alloc_request) (struct usb_ep *ep, + gfp_t gfp_flags); + void (*free_request) (struct usb_ep *ep, struct usb_request *req); + + int (*queue) (struct usb_ep *ep, struct usb_request *req, + gfp_t gfp_flags); + int (*dequeue) (struct usb_ep *ep, struct usb_request *req); + + int (*set_halt) (struct usb_ep *ep, int value); + int (*fifo_status) (struct usb_ep *ep); + void (*fifo_flush) (struct usb_ep *ep); +}; + +/** + * struct usb_ep - device side representation of USB endpoint + * @name:identifier for the endpoint, such as "ep-a" or "ep9in-bulk" + * @ops: Function pointers used to access hardware-specific operations. + * @ep_list:the gadget's ep_list holds all of its endpoints + * @maxpacket:The maximum packet size used on this endpoint. The initial + * value can sometimes be reduced (hardware allowing), according to + * the endpoint descriptor used to configure the endpoint. + * @driver_data:for use by the gadget driver. all other fields are + * read-only to gadget drivers. + * + * the bus controller driver lists all the general purpose endpoints in + * gadget->ep_list. the control endpoint (gadget->ep0) is not in that list, + * and is accessed only in response to a driver setup() callback. + */ +struct usb_ep { + void *driver_data; + const char *name; + const struct usb_ep_ops *ops; + struct list_head ep_list; + unsigned maxpacket:16; +}; + +/*-------------------------------------------------------------------------*/ + +/** + * usb_ep_enable - configure endpoint, making it usable + * @ep:the endpoint being configured. may not be the endpoint named "ep0". + * drivers discover endpoints through the ep_list of a usb_gadget. + * @desc:descriptor for desired behavior. caller guarantees this pointer + * remains valid until the endpoint is disabled; the data byte order + * is little-endian (usb-standard). + * + * when configurations are set, or when interface settings change, the driver + * will enable or disable the relevant endpoints. while it is enabled, an + * endpoint may be used for i/o until the driver receives a disconnect() from + * the host or until the endpoint is disabled. + * + * the ep0 implementation (which calls this routine) must ensure that the + * hardware capabilities of each endpoint match the descriptor provided + * for it. for example, an endpoint named "ep2in-bulk" would be usable + * for interrupt transfers as well as bulk, but it likely couldn't be used + * for iso transfers or for endpoint 14. some endpoints are fully + * configurable, with more generic names like "ep-a". (remember that for + * USB, "in" means "towards the USB master".) + * + * returns zero, or a negative error code. + */ +static inline int +usb_ep_enable (struct usb_ep *ep, const struct usb_endpoint_descriptor *desc) +{ + return ep->ops->enable (ep, desc); +} + +/** + * usb_ep_disable - endpoint is no longer usable + * @ep:the endpoint being unconfigured. may not be the endpoint named "ep0". + * + * no other task may be using this endpoint when this is called. + * any pending and uncompleted requests will complete with status + * indicating disconnect (-ESHUTDOWN) before this call returns. + * gadget drivers must call usb_ep_enable() again before queueing + * requests to the endpoint. + * + * returns zero, or a negative error code. + */ +static inline int +usb_ep_disable (struct usb_ep *ep) +{ + return ep->ops->disable (ep); +} + +/** + * usb_ep_alloc_request - allocate a request object to use with this endpoint + * @ep:the endpoint to be used with with the request + * @gfp_flags:GFP_* flags to use + * + * Request objects must be allocated with this call, since they normally + * need controller-specific setup and may even need endpoint-specific + * resources such as allocation of DMA descriptors. + * Requests may be submitted with usb_ep_queue(), and receive a single + * completion callback. Free requests with usb_ep_free_request(), when + * they are no longer needed. + * + * Returns the request, or null if one could not be allocated. + */ +static inline struct usb_request * +usb_ep_alloc_request (struct usb_ep *ep, gfp_t gfp_flags) +{ + return ep->ops->alloc_request (ep, gfp_flags); +} + +/** + * usb_ep_free_request - frees a request object + * @ep:the endpoint associated with the request + * @req:the request being freed + * + * Reverses the effect of usb_ep_alloc_request(). + * Caller guarantees the request is not queued, and that it will + * no longer be requeued (or otherwise used). + */ +static inline void +usb_ep_free_request (struct usb_ep *ep, struct usb_request *req) +{ + ep->ops->free_request (ep, req); +} + +/** + * usb_ep_queue - queues (submits) an I/O request to an endpoint. + * @ep:the endpoint associated with the request + * @req:the request being submitted + * @gfp_flags: GFP_* flags to use in case the lower level driver couldn't + * pre-allocate all necessary memory with the request. + * + * This tells the device controller to perform the specified request through + * that endpoint (reading or writing a buffer). When the request completes, + * including being canceled by usb_ep_dequeue(), the request's completion + * routine is called to return the request to the driver. Any endpoint + * (except control endpoints like ep0) may have more than one transfer + * request queued; they complete in FIFO order. Once a gadget driver + * submits a request, that request may not be examined or modified until it + * is given back to that driver through the completion callback. + * + * Each request is turned into one or more packets. The controller driver + * never merges adjacent requests into the same packet. OUT transfers + * will sometimes use data that's already buffered in the hardware. + * Drivers can rely on the fact that the first byte of the request's buffer + * always corresponds to the first byte of some USB packet, for both + * IN and OUT transfers. + * + * Bulk endpoints can queue any amount of data; the transfer is packetized + * automatically. The last packet will be short if the request doesn't fill it + * out completely. Zero length packets (ZLPs) should be avoided in portable + * protocols since not all usb hardware can successfully handle zero length + * packets. (ZLPs may be explicitly written, and may be implicitly written if + * the request 'zero' flag is set.) Bulk endpoints may also be used + * for interrupt transfers; but the reverse is not true, and some endpoints + * won't support every interrupt transfer. (Such as 768 byte packets.) + * + * Interrupt-only endpoints are less functional than bulk endpoints, for + * example by not supporting queueing or not handling buffers that are + * larger than the endpoint's maxpacket size. They may also treat data + * toggle differently. + * + * Control endpoints ... after getting a setup() callback, the driver queues + * one response (even if it would be zero length). That enables the + * status ack, after transfering data as specified in the response. Setup + * functions may return negative error codes to generate protocol stalls. + * (Note that some USB device controllers disallow protocol stall responses + * in some cases.) When control responses are deferred (the response is + * written after the setup callback returns), then usb_ep_set_halt() may be + * used on ep0 to trigger protocol stalls. + * + * For periodic endpoints, like interrupt or isochronous ones, the usb host + * arranges to poll once per interval, and the gadget driver usually will + * have queued some data to transfer at that time. + * + * Returns zero, or a negative error code. Endpoints that are not enabled + * report errors; errors will also be + * reported when the usb peripheral is disconnected. + */ +static inline int +usb_ep_queue (struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) +{ + return ep->ops->queue (ep, req, gfp_flags); +} + +/** + * usb_ep_dequeue - dequeues (cancels, unlinks) an I/O request from an endpoint + * @ep:the endpoint associated with the request + * @req:the request being canceled + * + * if the request is still active on the endpoint, it is dequeued and its + * completion routine is called (with status -ECONNRESET); else a negative + * error code is returned. + * + * note that some hardware can't clear out write fifos (to unlink the request + * at the head of the queue) except as part of disconnecting from usb. such + * restrictions prevent drivers from supporting configuration changes, + * even to configuration zero (a "chapter 9" requirement). + */ +static inline int usb_ep_dequeue (struct usb_ep *ep, struct usb_request *req) +{ + return ep->ops->dequeue (ep, req); +} + +/** + * usb_ep_set_halt - sets the endpoint halt feature. + * @ep: the non-isochronous endpoint being stalled + * + * Use this to stall an endpoint, perhaps as an error report. + * Except for control endpoints, + * the endpoint stays halted (will not stream any data) until the host + * clears this feature; drivers may need to empty the endpoint's request + * queue first, to make sure no inappropriate transfers happen. + * + * Note that while an endpoint CLEAR_FEATURE will be invisible to the + * gadget driver, a SET_INTERFACE will not be. To reset endpoints for the + * current altsetting, see usb_ep_clear_halt(). When switching altsettings, + * it's simplest to use usb_ep_enable() or usb_ep_disable() for the endpoints. + * + * Returns zero, or a negative error code. On success, this call sets + * underlying hardware state that blocks data transfers. + * Attempts to halt IN endpoints will fail (returning -EAGAIN) if any + * transfer requests are still queued, or if the controller hardware + * (usually a FIFO) still holds bytes that the host hasn't collected. + */ +static inline int +usb_ep_set_halt (struct usb_ep *ep) +{ + return ep->ops->set_halt (ep, 1); +} + +/** + * usb_ep_clear_halt - clears endpoint halt, and resets toggle + * @ep:the bulk or interrupt endpoint being reset + * + * Use this when responding to the standard usb "set interface" request, + * for endpoints that aren't reconfigured, after clearing any other state + * in the endpoint's i/o queue. + * + * Returns zero, or a negative error code. On success, this call clears + * the underlying hardware state reflecting endpoint halt and data toggle. + * Note that some hardware can't support this request (like pxa2xx_udc), + * and accordingly can't correctly implement interface altsettings. + */ +static inline int +usb_ep_clear_halt (struct usb_ep *ep) +{ + return ep->ops->set_halt (ep, 0); +} + +/** + * usb_ep_fifo_status - returns number of bytes in fifo, or error + * @ep: the endpoint whose fifo status is being checked. + * + * FIFO endpoints may have "unclaimed data" in them in certain cases, + * such as after aborted transfers. Hosts may not have collected all + * the IN data written by the gadget driver (and reported by a request + * completion). The gadget driver may not have collected all the data + * written OUT to it by the host. Drivers that need precise handling for + * fault reporting or recovery may need to use this call. + * + * This returns the number of such bytes in the fifo, or a negative + * errno if the endpoint doesn't use a FIFO or doesn't support such + * precise handling. + */ +static inline int +usb_ep_fifo_status (struct usb_ep *ep) +{ + if (ep->ops->fifo_status) + return ep->ops->fifo_status (ep); + else + return -EOPNOTSUPP; +} + +/** + * usb_ep_fifo_flush - flushes contents of a fifo + * @ep: the endpoint whose fifo is being flushed. + * + * This call may be used to flush the "unclaimed data" that may exist in + * an endpoint fifo after abnormal transaction terminations. The call + * must never be used except when endpoint is not being used for any + * protocol translation. + */ +static inline void +usb_ep_fifo_flush (struct usb_ep *ep) +{ + if (ep->ops->fifo_flush) + ep->ops->fifo_flush (ep); +} + + +/*-------------------------------------------------------------------------*/ + +struct usb_gadget; + +/* the rest of the api to the controller hardware: device operations, + * which don't involve endpoints (or i/o). + */ +struct usb_gadget_ops { + int (*get_frame)(struct usb_gadget *); + int (*wakeup)(struct usb_gadget *); + int (*set_selfpowered) (struct usb_gadget *, int is_selfpowered); + int (*vbus_session) (struct usb_gadget *, int is_active); + int (*vbus_draw) (struct usb_gadget *, unsigned mA); + int (*pullup) (struct usb_gadget *, int is_on); + int (*ioctl)(struct usb_gadget *, + unsigned code, unsigned long param); +}; + +struct device { + void *driver_data; /* data private to the driver */ +}; + +/** + * struct usb_gadget - represents a usb slave device + * @ops: Function pointers used to access hardware-specific operations. + * @ep0: Endpoint zero, used when reading or writing responses to + * driver setup() requests + * @ep_list: List of other endpoints supported by the device. + * @speed: Speed of current connection to USB host. + * @is_dualspeed: True if the controller supports both high and full speed + * operation. If it does, the gadget driver must also support both. + * @is_otg: True if the USB device port uses a Mini-AB jack, so that the + * gadget driver must provide a USB OTG descriptor. + * @is_a_peripheral: False unless is_otg, the "A" end of a USB cable + * is in the Mini-AB jack, and HNP has been used to switch roles + * so that the "A" device currently acts as A-Peripheral, not A-Host. + * @a_hnp_support: OTG device feature flag, indicating that the A-Host + * supports HNP at this port. + * @a_alt_hnp_support: OTG device feature flag, indicating that the A-Host + * only supports HNP on a different root port. + * @b_hnp_enable: OTG device feature flag, indicating that the A-Host + * enabled HNP support. + * @name: Identifies the controller hardware type. Used in diagnostics + * and sometimes configuration. + * @dev: Driver model state for this abstract device. + * + * Gadgets have a mostly-portable "gadget driver" implementing device + * functions, handling all usb configurations and interfaces. Gadget + * drivers talk to hardware-specific code indirectly, through ops vectors. + * That insulates the gadget driver from hardware details, and packages + * the hardware endpoints through generic i/o queues. The "usb_gadget" + * and "usb_ep" interfaces provide that insulation from the hardware. + * + * Except for the driver data, all fields in this structure are + * read-only to the gadget driver. That driver data is part of the + * "driver model" infrastructure in 2.6 (and later) kernels, and for + * earlier systems is grouped in a similar structure that's not known + * to the rest of the kernel. + * + * Values of the three OTG device feature flags are updated before the + * setup() call corresponding to USB_REQ_SET_CONFIGURATION, and before + * driver suspend() calls. They are valid only when is_otg, and when the + * device is acting as a B-Peripheral (so is_a_peripheral is false). + */ +struct usb_gadget { + /* readonly to gadget driver */ + const struct usb_gadget_ops *ops; + struct usb_ep *ep0; + struct list_head ep_list; /* of usb_ep */ + enum usb_device_speed speed; + unsigned is_dualspeed:1; + unsigned is_otg:1; + unsigned is_a_peripheral:1; + unsigned b_hnp_enable:1; + unsigned a_hnp_support:1; + unsigned a_alt_hnp_support:1; + const char *name; + struct device dev; +}; + +static inline void set_gadget_data (struct usb_gadget *gadget, void *data) +{ + gadget->dev.driver_data = data; +} + +static inline void *get_gadget_data (struct usb_gadget *gadget) +{ + return gadget->dev.driver_data; +} + +/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ +#define gadget_for_each_ep(tmp,gadget) \ + list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) + + +/** + * gadget_is_dualspeed - return true iff the hardware handles high speed + * @g: controller that might support both high and full speeds + */ +static inline int gadget_is_dualspeed(struct usb_gadget *g) +{ +#ifdef CONFIG_USB_GADGET_DUALSPEED + /* runtime test would check "g->is_dualspeed" ... that might be + * useful to work around hardware bugs, but is mostly pointless + */ + return 1; +#else + return 0; +#endif +} + +/** + * gadget_is_otg - return true iff the hardware is OTG-ready + * @g: controller that might have a Mini-AB connector + * + * This is a runtime test, since kernels with a USB-OTG stack sometimes + * run on boards which only have a Mini-B (or Mini-A) connector. + */ +static inline int gadget_is_otg(struct usb_gadget *g) +{ +#ifdef CONFIG_USB_OTG + return g->is_otg; +#else + return 0; +#endif +} + + +/** + * usb_gadget_frame_number - returns the current frame number + * @gadget: controller that reports the frame number + * + * Returns the usb frame number, normally eleven bits from a SOF packet, + * or negative errno if this device doesn't support this capability. + */ +static inline int usb_gadget_frame_number (struct usb_gadget *gadget) +{ + return gadget->ops->get_frame (gadget); +} + +/** + * usb_gadget_wakeup - tries to wake up the host connected to this gadget + * @gadget: controller used to wake up the host + * + * Returns zero on success, else negative error code if the hardware + * doesn't support such attempts, or its support has not been enabled + * by the usb host. Drivers must return device descriptors that report + * their ability to support this, or hosts won't enable it. + * + * This may also try to use SRP to wake the host and start enumeration, + * even if OTG isn't otherwise in use. OTG devices may also start + * remote wakeup even when hosts don't explicitly enable it. + */ +static inline int usb_gadget_wakeup (struct usb_gadget *gadget) +{ + if (!gadget->ops->wakeup) + return -EOPNOTSUPP; + return gadget->ops->wakeup (gadget); +} + +/** + * usb_gadget_set_selfpowered - sets the device selfpowered feature. + * @gadget:the device being declared as self-powered + * + * this affects the device status reported by the hardware driver + * to reflect that it now has a local power supply. + * + * returns zero on success, else negative errno. + */ +static inline int +usb_gadget_set_selfpowered (struct usb_gadget *gadget) +{ + if (!gadget->ops->set_selfpowered) + return -EOPNOTSUPP; + return gadget->ops->set_selfpowered (gadget, 1); +} + +/** + * usb_gadget_clear_selfpowered - clear the device selfpowered feature. + * @gadget:the device being declared as bus-powered + * + * this affects the device status reported by the hardware driver. + * some hardware may not support bus-powered operation, in which + * case this feature's value can never change. + * + * returns zero on success, else negative errno. + */ +static inline int +usb_gadget_clear_selfpowered (struct usb_gadget *gadget) +{ + if (!gadget->ops->set_selfpowered) + return -EOPNOTSUPP; + return gadget->ops->set_selfpowered (gadget, 0); +} + +/** + * usb_gadget_vbus_connect - Notify controller that VBUS is powered + * @gadget:The device which now has VBUS power. + * + * This call is used by a driver for an external transceiver (or GPIO) + * that detects a VBUS power session starting. Common responses include + * resuming the controller, activating the D+ (or D-) pullup to let the + * host detect that a USB device is attached, and starting to draw power + * (8mA or possibly more, especially after SET_CONFIGURATION). + * + * Returns zero on success, else negative errno. + */ +static inline int +usb_gadget_vbus_connect(struct usb_gadget *gadget) +{ + if (!gadget->ops->vbus_session) + return -EOPNOTSUPP; + return gadget->ops->vbus_session (gadget, 1); +} + +/** + * usb_gadget_vbus_draw - constrain controller's VBUS power usage + * @gadget:The device whose VBUS usage is being described + * @mA:How much current to draw, in milliAmperes. This should be twice + * the value listed in the configuration descriptor bMaxPower field. + * + * This call is used by gadget drivers during SET_CONFIGURATION calls, + * reporting how much power the device may consume. For example, this + * could affect how quickly batteries are recharged. + * + * Returns zero on success, else negative errno. + */ +static inline int +usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) +{ + if (!gadget->ops->vbus_draw) + return -EOPNOTSUPP; + return gadget->ops->vbus_draw (gadget, mA); +} + +/** + * usb_gadget_vbus_disconnect - notify controller about VBUS session end + * @gadget:the device whose VBUS supply is being described + * + * This call is used by a driver for an external transceiver (or GPIO) + * that detects a VBUS power session ending. Common responses include + * reversing everything done in usb_gadget_vbus_connect(). + * + * Returns zero on success, else negative errno. + */ +static inline int +usb_gadget_vbus_disconnect(struct usb_gadget *gadget) +{ + if (!gadget->ops->vbus_session) + return -EOPNOTSUPP; + return gadget->ops->vbus_session (gadget, 0); +} + +/** + * usb_gadget_connect - software-controlled connect to USB host + * @gadget:the peripheral being connected + * + * Enables the D+ (or potentially D-) pullup. The host will start + * enumerating this gadget when the pullup is active and a VBUS session + * is active (the link is powered). This pullup is always enabled unless + * usb_gadget_disconnect() has been used to disable it. + * + * Returns zero on success, else negative errno. + */ +static inline int +usb_gadget_connect (struct usb_gadget *gadget) +{ + if (!gadget->ops->pullup) + return -EOPNOTSUPP; + return gadget->ops->pullup (gadget, 1); +} + +/** + * usb_gadget_disconnect - software-controlled disconnect from USB host + * @gadget:the peripheral being disconnected + * + * Disables the D+ (or potentially D-) pullup, which the host may see + * as a disconnect (when a VBUS session is active). Not all systems + * support software pullup controls. + * + * This routine may be used during the gadget driver bind() call to prevent + * the peripheral from ever being visible to the USB host, unless later + * usb_gadget_connect() is called. For example, user mode components may + * need to be activated before the system can talk to hosts. + * + * Returns zero on success, else negative errno. + */ +static inline int +usb_gadget_disconnect (struct usb_gadget *gadget) +{ + if (!gadget->ops->pullup) + return -EOPNOTSUPP; + return gadget->ops->pullup (gadget, 0); +} + + + +/*-------------------------------------------------------------------------*/ + +/** + * struct usb_gadget_driver - driver for usb 'slave' devices + * @speed: Highest speed the driver handles. + * @bind: Invoked when the driver is bound to a gadget, usually + * after registering the driver. + * At that point, ep0 is fully initialized, and ep_list holds + * the currently-available endpoints. + * Called in a context that permits sleeping. + * @setup: Invoked for ep0 control requests that aren't handled by + * the hardware level driver. Most calls must be handled by + * the gadget driver, including descriptor and configuration + * management. The 16 bit members of the setup data are in + * USB byte order. Called in_interrupt; this may not sleep. Driver + * queues a response to ep0, or returns negative to stall. + * @disconnect: Invoked after all transfers have been stopped, + * when the host is disconnected. May be called in_interrupt; this + * may not sleep. Some devices can't detect disconnect, so this might + * not be called except as part of controller shutdown. + * @unbind: Invoked when the driver is unbound from a gadget, + * usually from rmmod (after a disconnect is reported). + * Called in a context that permits sleeping. + * @suspend: Invoked on USB suspend. May be called in_interrupt. + * @resume: Invoked on USB resume. May be called in_interrupt. + * + * Devices are disabled till a gadget driver successfully bind()s, which + * means the driver will handle setup() requests needed to enumerate (and + * meet "chapter 9" requirements) then do some useful work. + * + * If gadget->is_otg is true, the gadget driver must provide an OTG + * descriptor during enumeration, or else fail the bind() call. In such + * cases, no USB traffic may flow until both bind() returns without + * having called usb_gadget_disconnect(), and the USB host stack has + * initialized. + * + * Drivers use hardware-specific knowledge to configure the usb hardware. + * endpoint addressing is only one of several hardware characteristics that + * are in descriptors the ep0 implementation returns from setup() calls. + * + * Except for ep0 implementation, most driver code shouldn't need change to + * run on top of different usb controllers. It'll use endpoints set up by + * that ep0 implementation. + * + * The usb controller driver handles a few standard usb requests. Those + * include set_address, and feature flags for devices, interfaces, and + * endpoints (the get_status, set_feature, and clear_feature requests). + * + * Accordingly, the driver's setup() callback must always implement all + * get_descriptor requests, returning at least a device descriptor and + * a configuration descriptor. Drivers must make sure the endpoint + * descriptors match any hardware constraints. Some hardware also constrains + * other descriptors. (The pxa250 allows only configurations 1, 2, or 3). + * + * The driver's setup() callback must also implement set_configuration, + * and should also implement set_interface, get_configuration, and + * get_interface. Setting a configuration (or interface) is where + * endpoints should be activated or (config 0) shut down. + * + * (Note that only the default control endpoint is supported. Neither + * hosts nor devices generally support control traffic except to ep0.) + * + * Most devices will ignore USB suspend/resume operations, and so will + * not provide those callbacks. However, some may need to change modes + * when the host is not longer directing those activities. For example, + * local controls (buttons, dials, etc) may need to be re-enabled since + * the (remote) host can't do that any longer; or an error state might + * be cleared, to make the device behave identically whether or not + * power is maintained. + */ +struct usb_gadget_driver { + enum usb_device_speed speed; + int (*bind)(struct usb_gadget *); + void (*unbind)(struct usb_gadget *); + int (*setup)(struct usb_gadget *, + const struct usb_ctrlrequest *); + void (*disconnect)(struct usb_gadget *); + void (*suspend)(struct usb_gadget *); + void (*resume)(struct usb_gadget *); +}; + + + +/*-------------------------------------------------------------------------*/ + +/* driver modules register and unregister, as usual. + * these calls must be made in a context that can sleep. + * + * these will usually be implemented directly by the hardware-dependent + * usb bus interface driver, which will only support a single driver. + */ + +/** + * usb_gadget_register_driver - register a gadget driver + * @driver:the driver being registered + * + * Call this in your gadget driver's module initialization function, + * to tell the underlying usb controller driver about your driver. + * The driver's bind() function will be called to bind it to a + * gadget before this registration call returns. It's expected that + * the bind() functions will be in init sections. + * This function must be called in a context that can sleep. + */ +int usb_gadget_register_driver (struct usb_gadget_driver *driver); + +/** + * usb_gadget_unregister_driver - unregister a gadget driver + * @driver:the driver being unregistered + * + * Call this in your gadget driver's module cleanup function, + * to tell the underlying usb controller that your driver is + * going away. If the controller is connected to a USB host, + * it will first disconnect(). The driver is also requested + * to unbind() and clean up any device state, before this procedure + * finally returns. It's expected that the unbind() functions + * will in in exit sections, so may not be linked in some kernels. + * This function must be called in a context that can sleep. + */ +int usb_gadget_unregister_driver (struct usb_gadget_driver *driver); + +/*-------------------------------------------------------------------------*/ + +/* utility to simplify dealing with string descriptors */ + +/** + * struct usb_string - wraps a C string and its USB id + * @id:the (nonzero) ID for this string + * @s:the string, in UTF-8 encoding + * + * If you're using usb_gadget_get_string(), use this to wrap a string + * together with its ID. + */ +struct usb_string { + u8 id; + const char *s; +}; + +/** + * struct usb_gadget_strings - a set of USB strings in a given language + * @language:identifies the strings' language (0x0409 for en-us) + * @strings:array of strings with their ids + * + * If you're using usb_gadget_get_string(), use this to wrap all the + * strings for a given language. + */ +struct usb_gadget_strings { + u16 language; /* 0x0409 for en-us */ + struct usb_string *strings; +}; + +/* put descriptor for string with that id into buf (buflen >= 256) */ +int usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf); + +/*-------------------------------------------------------------------------*/ + +/* utility to simplify managing config descriptors */ + +/* write vector of descriptors into buffer */ +int usb_descriptor_fillbuf(void *, unsigned, + const struct usb_descriptor_header **); + +/* build config descriptor from single descriptor vector */ +int usb_gadget_config_buf(const struct usb_config_descriptor *config, + void *buf, unsigned buflen, const struct usb_descriptor_header **desc); + +/*-------------------------------------------------------------------------*/ + +/* utility wrapping a simple endpoint selection policy */ + +extern struct usb_ep *usb_ep_autoconfig (struct usb_gadget *, + struct usb_endpoint_descriptor *); + +extern void usb_ep_autoconfig_reset (struct usb_gadget *); + +extern int usb_gadget_handle_interrupts(void); + +#endif /* __LINUX_USB_GADGET_H */ -- cgit v1.2.3-70-g09d2 From 6142e0ae0fcf8bf5a7a8d785061197ace8955cb6 Mon Sep 17 00:00:00 2001 From: Vitaly Kuzmichev Date: Mon, 13 Sep 2010 18:37:11 +0400 Subject: USB-CDC: Fix coding style issues Fixes most of checkpatch warnings and errors in USB gadget stack. The most frequently encountered problems are: 1) "(foo*)", "foo * bar", "foo* bar" 2) C99 // comments 3) No spaces before/after/around '?', ':', '=', '==', ',', '&', '(' 4) Spaces before '[' 5) Spaces between function names and '(' 6) Block braces in wrong places 7) Spaces before tabs 8) Macros with complex values not enclosed in parenthesis 9) Multiline comments start just after /* Signed-off-by: Vitaly Kuzmichev --- drivers/usb/gadget/config.c | 2 +- drivers/usb/gadget/epautoconf.c | 73 +++--- drivers/usb/gadget/ether.c | 513 ++++++++++++++++++++------------------ drivers/usb/gadget/gadget_chips.h | 51 ++-- drivers/usb/gadget/usbstring.c | 48 ++-- include/linux/usb/cdc.h | 16 +- include/linux/usb/ch9.h | 4 +- include/linux/usb/gadget.h | 120 ++++----- 8 files changed, 420 insertions(+), 407 deletions(-) (limited to 'include/linux/usb/gadget.h') diff --git a/drivers/usb/gadget/config.c b/drivers/usb/gadget/config.c index 84c90f0dc..cf22629b9 100644 --- a/drivers/usb/gadget/config.c +++ b/drivers/usb/gadget/config.c @@ -101,7 +101,7 @@ int usb_gadget_config_buf( *cp = *config; /* then interface/endpoint/class/vendor/... */ - len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf, + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8 *)buf, length - USB_DT_CONFIG_SIZE, desc); if (len < 0) return len; diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c index e11cc204b..7cf3c673d 100644 --- a/drivers/usb/gadget/epautoconf.c +++ b/drivers/usb/gadget/epautoconf.c @@ -32,7 +32,7 @@ /* we must assign addresses for configurable endpoints (like net2280) */ static unsigned epnum; -// #define MANY_ENDPOINTS +/* #define MANY_ENDPOINTS */ #ifdef MANY_ENDPOINTS /* more than 15 configurable endpoints */ static unsigned in_epnum; @@ -55,8 +55,7 @@ static unsigned in_epnum; * NOTE: each endpoint is unidirectional, as specified by its USB * descriptor; and isn't specific to a configuration or altsetting. */ -static int -ep_matches ( +static int ep_matches( struct usb_gadget *gadget, struct usb_ep *ep, struct usb_endpoint_descriptor *desc @@ -83,37 +82,37 @@ ep_matches ( * direction-restriction: "in", "out". */ if ('-' != ep->name[2]) { - tmp = strrchr (ep->name, '-'); + tmp = strrchr(ep->name, '-'); if (tmp) { switch (type) { case USB_ENDPOINT_XFER_INT: /* bulk endpoints handle interrupt transfers, * except the toggle-quirky iso-synch kind */ - if ('s' == tmp[2]) // == "-iso" + if ('s' == tmp[2]) /* == "-iso" */ return 0; /* for now, avoid PXA "interrupt-in"; * it's documented as never using DATA1. */ - if (gadget_is_pxa (gadget) - && 'i' == tmp [1]) + if (gadget_is_pxa(gadget) + && 'i' == tmp[1]) return 0; break; case USB_ENDPOINT_XFER_BULK: - if ('b' != tmp[1]) // != "-bulk" + if ('b' != tmp[1]) /* != "-bulk" */ return 0; break; case USB_ENDPOINT_XFER_ISOC: - if ('s' != tmp[2]) // != "-iso" + if ('s' != tmp[2]) /* != "-iso" */ return 0; } } else { - tmp = ep->name + strlen (ep->name); + tmp = ep->name + strlen(ep->name); } /* direction-restriction: "..in-..", "out-.." */ tmp--; - if (!isdigit (*tmp)) { + if (!isdigit(*tmp)) { if (desc->bEndpointAddress & USB_DIR_IN) { if ('n' != *tmp) return 0; @@ -155,8 +154,8 @@ ep_matches ( /* MATCH!! */ /* report address */ - if (isdigit (ep->name [2])) { - u8 num = simple_strtoul (&ep->name [2], NULL, 10); + if (isdigit(ep->name[2])) { + u8 num = simple_strtoul(&ep->name[2], NULL, 10); desc->bEndpointAddress |= num; #ifdef MANY_ENDPOINTS } else if (desc->bEndpointAddress & USB_DIR_IN) { @@ -183,12 +182,12 @@ ep_matches ( } static struct usb_ep * -find_ep (struct usb_gadget *gadget, const char *name) +find_ep(struct usb_gadget *gadget, const char *name) { struct usb_ep *ep; - list_for_each_entry (ep, &gadget->ep_list, ep_list) { - if (0 == strcmp (ep->name, name)) + list_for_each_entry(ep, &gadget->ep_list, ep_list) { + if (0 == strcmp(ep->name, name)) return ep; } return NULL; @@ -224,7 +223,7 @@ find_ep (struct usb_gadget *gadget, const char *name) * * On failure, this returns a null endpoint descriptor. */ -struct usb_ep * usb_ep_autoconfig ( +struct usb_ep *usb_ep_autoconfig( struct usb_gadget *gadget, struct usb_endpoint_descriptor *desc ) @@ -237,44 +236,44 @@ struct usb_ep * usb_ep_autoconfig ( /* First, apply chip-specific "best usage" knowledge. * This might make a good usb_gadget_ops hook ... */ - if (gadget_is_net2280 (gadget) && type == USB_ENDPOINT_XFER_INT) { + if (gadget_is_net2280(gadget) && type == USB_ENDPOINT_XFER_INT) { /* ep-e, ep-f are PIO with only 64 byte fifos */ - ep = find_ep (gadget, "ep-e"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep-e"); + if (ep && ep_matches(gadget, ep, desc)) return ep; - ep = find_ep (gadget, "ep-f"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep-f"); + if (ep && ep_matches(gadget, ep, desc)) return ep; - } else if (gadget_is_goku (gadget)) { + } else if (gadget_is_goku(gadget)) { if (USB_ENDPOINT_XFER_INT == type) { /* single buffering is enough */ - ep = find_ep (gadget, "ep3-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep3-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; } else if (USB_ENDPOINT_XFER_BULK == type && (USB_DIR_IN & desc->bEndpointAddress)) { /* DMA may be available */ - ep = find_ep (gadget, "ep2-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep2-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; } - } else if (gadget_is_sh (gadget) && USB_ENDPOINT_XFER_INT == type) { + } else if (gadget_is_sh(gadget) && USB_ENDPOINT_XFER_INT == type) { /* single buffering is enough; maybe 8 byte fifo is too */ - ep = find_ep (gadget, "ep3in-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + ep = find_ep(gadget, "ep3in-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; - } else if (gadget_is_mq11xx (gadget) && USB_ENDPOINT_XFER_INT == type) { - ep = find_ep (gadget, "ep1-bulk"); - if (ep && ep_matches (gadget, ep, desc)) + } else if (gadget_is_mq11xx(gadget) && USB_ENDPOINT_XFER_INT == type) { + ep = find_ep(gadget, "ep1-bulk"); + if (ep && ep_matches(gadget, ep, desc)) return ep; } /* Second, look at endpoints until an unclaimed one looks usable */ - list_for_each_entry (ep, &gadget->ep_list, ep_list) { - if (ep_matches (gadget, ep, desc)) + list_for_each_entry(ep, &gadget->ep_list, ep_list) { + if (ep_matches(gadget, ep, desc)) return ep; } @@ -291,11 +290,11 @@ struct usb_ep * usb_ep_autoconfig ( * state such as ep->driver_data and the record of assigned endpoints * used by usb_ep_autoconfig(). */ -void usb_ep_autoconfig_reset (struct usb_gadget *gadget) +void usb_ep_autoconfig_reset(struct usb_gadget *gadget) { struct usb_ep *ep; - list_for_each_entry (ep, &gadget->ep_list, ep_list) { + list_for_each_entry(ep, &gadget->ep_list, ep_list) { ep->driver_data = NULL; } #ifdef MANY_ENDPOINTS diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c index 296529947..bc6480c78 100644 --- a/drivers/usb/gadget/ether.c +++ b/drivers/usb/gadget/ether.c @@ -89,8 +89,8 @@ unsigned packet_received, packet_sent; /* Based on linux 2.6.27 version */ #define DRIVER_VERSION "May Day 2005" -static const char shortname [] = "ether"; -static const char driver_desc [] = DRIVER_DESC; +static const char shortname[] = "ether"; +static const char driver_desc[] = DRIVER_DESC; #define RX_EXTRA 20 /* guard against rx overflows */ @@ -114,7 +114,7 @@ static inline int is_cdc(struct eth_dev *dev) { #if !defined(DEV_CONFIG_SUBSET) return 1; /* only cdc possible */ -#elif !defined (DEV_CONFIG_CDC) +#elif !defined(DEV_CONFIG_CDC) return 0; /* only subset possible */ #else return dev->cdc; /* depends on what hardware we found */ @@ -122,7 +122,7 @@ static inline int is_cdc(struct eth_dev *dev) } #define subset_active(dev) (!is_cdc(dev)) -#define cdc_active(dev) ( is_cdc(dev)) +#define cdc_active(dev) (is_cdc(dev)) #define DEFAULT_QLEN 2 /* double buffering by default */ @@ -180,15 +180,16 @@ struct eth_dev { unsigned zlp:1; unsigned cdc:1; unsigned suspended:1; - unsigned network_started:1; + unsigned network_started:1; u16 cdc_filter; unsigned long todo; - int mtu; + int mtu; #define WORK_RX_MEMORY 0 - u8 host_mac [ETH_ALEN]; + u8 host_mac[ETH_ALEN]; }; -/* This version autoconfigures as much as possible at run-time. +/* + * This version autoconfigures as much as possible at run-time. * * It also ASSUMES a self-powered device, without remote wakeup, * although remote wakeup support would make sense. @@ -196,17 +197,20 @@ struct eth_dev { /*-------------------------------------------------------------------------*/ -/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! +/* + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! * Instead: allocate your own, using normal USB-IF procedures. */ -/* Thanks to NetChip Technologies for donating this product ID. +/* + * Thanks to NetChip Technologies for donating this product ID. * It's for devices with only CDC Ethernet configurations. */ #define CDC_VENDOR_NUM 0x0525 /* NetChip */ #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ -/* For hardware that can't talk CDC, we use the same vendor ID that +/* + * For hardware that can't talk CDC, we use the same vendor ID that * ARM Linux has used for ethernet-over-usb, both with sa1100 and * with pxa250. We're protocol-compatible, if the host-side drivers * use the endpoint descriptors. bcdDevice (version) is nonzero, so @@ -220,7 +224,8 @@ struct eth_dev { #define SIMPLE_VENDOR_NUM 0x049f #define SIMPLE_PRODUCT_NUM 0x505a -/* Some systems will want different product identifers published in the +/* + * Some systems will want different product identifers published in the * device descriptor, either numbers or strings or both. These string * parameters are in UTF-8 (superset of ASCII's 7 bit characters). */ @@ -238,7 +243,8 @@ static char host_addr[18]; /*-------------------------------------------------------------------------*/ -/* USB DRIVER HOOKUP (to the hardware driver, below us), mostly +/* + * USB DRIVER HOOKUP (to the hardware driver, below us), mostly * ep0 implementation: descriptors, config management, setup(). * also optional class-specific notification interrupt transfer. */ @@ -276,14 +282,14 @@ device_desc = { .bLength = sizeof device_desc, .bDescriptorType = USB_DT_DEVICE, - .bcdUSB = __constant_cpu_to_le16 (0x0200), + .bcdUSB = __constant_cpu_to_le16(0x0200), .bDeviceClass = USB_CLASS_COMM, .bDeviceSubClass = 0, .bDeviceProtocol = 0, - .idVendor = __constant_cpu_to_le16 (CDC_VENDOR_NUM), - .idProduct = __constant_cpu_to_le16 (CDC_PRODUCT_NUM), + .idVendor = __constant_cpu_to_le16(CDC_VENDOR_NUM), + .idProduct = __constant_cpu_to_le16(CDC_PRODUCT_NUM), .iManufacturer = STRING_MANUFACTURER, .iProduct = STRING_PRODUCT, .bNumConfigurations = 1, @@ -338,7 +344,7 @@ static const struct usb_cdc_header_desc header_desc = { .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubType = USB_CDC_HEADER_TYPE, - .bcdCDC = __constant_cpu_to_le16 (0x0110), + .bcdCDC = __constant_cpu_to_le16(0x0110), }; #if defined(DEV_CONFIG_CDC) @@ -356,7 +362,8 @@ static const struct usb_cdc_union_desc union_desc = { #ifndef DEV_CONFIG_CDC -/* "SAFE" loosely follows CDC WMC MDLM, violating the spec in various +/* + * "SAFE" loosely follows CDC WMC MDLM, violating the spec in various * ways: data endpoints live in the control interface, there's no data * interface, and it's not used to talk to a cell phone radio. */ @@ -373,7 +380,8 @@ static const struct usb_cdc_mdlm_desc mdlm_desc = { }, }; -/* since "usb_cdc_mdlm_detail_desc" is a variable length structure, we +/* + * since "usb_cdc_mdlm_detail_desc" is a variable length structure, we * can't really use its struct. All we do here is say that we're using * the submode of "SAFE" which directly matches the CDC Subset. */ @@ -389,24 +397,23 @@ static const u8 mdlm_detail_desc[] = { #endif - static const struct usb_cdc_ether_desc ether_desc = { - .bLength = sizeof (ether_desc), + .bLength = sizeof(ether_desc), .bDescriptorType = USB_DT_CS_INTERFACE, .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, /* this descriptor actually adds value, surprise! */ .iMACAddress = STRING_ETHADDR, - .bmEthernetStatistics = __constant_cpu_to_le32 (0), /* no statistics */ - .wMaxSegmentSize = __constant_cpu_to_le16 (ETH_FRAME_LEN), - .wNumberMCFilters = __constant_cpu_to_le16 (0), + .bmEthernetStatistics = __constant_cpu_to_le32(0), /* no statistics */ + .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN), + .wNumberMCFilters = __constant_cpu_to_le16(0), .bNumberPowerFilters = 0, }; - #if defined(DEV_CONFIG_CDC) -/* include the status endpoint if we can, even where it's optional. +/* + * include the status endpoint if we can, even where it's optional. * use wMaxPacketSize big enough to fit CDC_NOTIFY_SPEED_CHANGE in one * packet, to simplify cancellation; and a big transfer interval, to * waste less bandwidth. @@ -427,7 +434,7 @@ fs_status_desc = { .bEndpointAddress = USB_DIR_IN, .bmAttributes = USB_ENDPOINT_XFER_INT, - .wMaxPacketSize = __constant_cpu_to_le16 (STATUS_BYTECOUNT), + .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, }; #endif @@ -493,7 +500,6 @@ subset_data_intf = { #endif /* SUBSET */ - static struct usb_endpoint_descriptor fs_source_desc = { .bLength = USB_DT_ENDPOINT_SIZE, @@ -512,7 +518,7 @@ fs_sink_desc = { .bmAttributes = USB_ENDPOINT_XFER_BULK, }; -static const struct usb_descriptor_header *fs_eth_function [11] = { +static const struct usb_descriptor_header *fs_eth_function[11] = { (struct usb_descriptor_header *) &otg_descriptor, #ifdef DEV_CONFIG_CDC /* "cdc" mode descriptors */ @@ -560,7 +566,7 @@ hs_status_desc = { .bDescriptorType = USB_DT_ENDPOINT, .bmAttributes = USB_ENDPOINT_XFER_INT, - .wMaxPacketSize = __constant_cpu_to_le16 (STATUS_BYTECOUNT), + .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, }; #endif /* DEV_CONFIG_CDC */ @@ -571,7 +577,7 @@ hs_source_desc = { .bDescriptorType = USB_DT_ENDPOINT, .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = __constant_cpu_to_le16 (512), + .wMaxPacketSize = __constant_cpu_to_le16(512), }; static struct usb_endpoint_descriptor @@ -580,7 +586,7 @@ hs_sink_desc = { .bDescriptorType = USB_DT_ENDPOINT, .bmAttributes = USB_ENDPOINT_XFER_BULK, - .wMaxPacketSize = __constant_cpu_to_le16 (512), + .wMaxPacketSize = __constant_cpu_to_le16(512), }; static struct usb_qualifier_descriptor @@ -588,13 +594,13 @@ dev_qualifier = { .bLength = sizeof dev_qualifier, .bDescriptorType = USB_DT_DEVICE_QUALIFIER, - .bcdUSB = __constant_cpu_to_le16 (0x0200), + .bcdUSB = __constant_cpu_to_le16(0x0200), .bDeviceClass = USB_CLASS_COMM, .bNumConfigurations = 1, }; -static const struct usb_descriptor_header *hs_eth_function [11] = { +static const struct usb_descriptor_header *hs_eth_function[11] = { (struct usb_descriptor_header *) &otg_descriptor, #ifdef DEV_CONFIG_CDC /* "cdc" mode descriptors */ @@ -640,20 +646,19 @@ ep_desc(struct usb_gadget *g, struct usb_endpoint_descriptor *hs, return fs; } - /*-------------------------------------------------------------------------*/ /* descriptors that are built on-demand */ -static char manufacturer [50]; -static char product_desc [40] = DRIVER_DESC; -static char serial_number [20]; +static char manufacturer[50]; +static char product_desc[40] = DRIVER_DESC; +static char serial_number[20]; /* address that the host will use ... usually assigned at random */ -static char ethaddr [2 * ETH_ALEN + 1]; +static char ethaddr[2 * ETH_ALEN + 1]; /* static strings, in UTF-8 */ -static struct usb_string strings [] = { +static struct usb_string strings[] = { { STRING_MANUFACTURER, manufacturer, }, { STRING_PRODUCT, product_desc, }, { STRING_SERIALNUMBER, serial_number, }, @@ -674,13 +679,11 @@ static struct usb_gadget_strings stringtab = { .strings = strings, }; - /*============================================================================*/ static u8 control_req[USB_BUFSIZ]; static u8 status_req[STATUS_BYTECOUNT] __attribute__ ((aligned(4))); - /** * strlcpy - Copy a %NUL terminated string into a sized buffer * @dest: Where to copy the string to @@ -704,7 +707,6 @@ size_t strlcpy(char *dest, const char *src, size_t size) return ret; } - /*============================================================================*/ /* @@ -730,13 +732,13 @@ config_buf(struct usb_gadget *g, u8 *buf, u8 type, unsigned index, int is_otg) return -EINVAL; config = ð_config; - function = which_fn (eth); + function = which_fn(eth); /* for now, don't advertise srp-only devices */ if (!is_otg) function++; - len = usb_gadget_config_buf (config, buf, USB_BUFSIZ, function); + len = usb_gadget_config_buf(config, buf, USB_BUFSIZ, function); if (len < 0) return len; ((struct usb_config_descriptor *) buf)->bDescriptorType = type; @@ -745,10 +747,10 @@ config_buf(struct usb_gadget *g, u8 *buf, u8 type, unsigned index, int is_otg) /*-------------------------------------------------------------------------*/ -static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags); +static int alloc_requests(struct eth_dev *dev, unsigned n, gfp_t gfp_flags); static int -set_ether_config (struct eth_dev *dev, gfp_t gfp_flags) +set_ether_config(struct eth_dev *dev, gfp_t gfp_flags) { int result = 0; struct usb_gadget *gadget = dev->gadget; @@ -756,11 +758,11 @@ set_ether_config (struct eth_dev *dev, gfp_t gfp_flags) #if defined(DEV_CONFIG_CDC) /* status endpoint used for (optionally) CDC */ if (!subset_active(dev) && dev->status_ep) { - dev->status = ep_desc (gadget, &hs_status_desc, + dev->status = ep_desc(gadget, &hs_status_desc, &fs_status_desc); dev->status_ep->driver_data = dev; - result = usb_ep_enable (dev->status_ep, dev->status); + result = usb_ep_enable(dev->status_ep, dev->status); if (result != 0) { debug("enable %s --> %d\n", dev->status_ep->name, result); @@ -775,19 +777,20 @@ set_ether_config (struct eth_dev *dev, gfp_t gfp_flags) dev->out = ep_desc(gadget, &hs_sink_desc, &fs_sink_desc); dev->out_ep->driver_data = dev; - /* With CDC, the host isn't allowed to use these two data + /* + * With CDC, the host isn't allowed to use these two data * endpoints in the default altsetting for the interface. * so we don't activate them yet. Reset from SET_INTERFACE. */ if (!cdc_active(dev)) { - result = usb_ep_enable (dev->in_ep, dev->in); + result = usb_ep_enable(dev->in_ep, dev->in); if (result != 0) { debug("enable %s --> %d\n", dev->in_ep->name, result); goto done; } - result = usb_ep_enable (dev->out_ep, dev->out); + result = usb_ep_enable(dev->out_ep, dev->out); if (result != 0) { debug("enable %s --> %d\n", dev->out_ep->name, result); @@ -797,15 +800,15 @@ set_ether_config (struct eth_dev *dev, gfp_t gfp_flags) done: if (result == 0) - result = alloc_requests (dev, qlen (gadget), gfp_flags); + result = alloc_requests(dev, qlen(gadget), gfp_flags); /* on error, disable any endpoints */ if (result < 0) { if (!subset_active(dev) && dev->status_ep) - (void) usb_ep_disable (dev->status_ep); + (void) usb_ep_disable(dev->status_ep); dev->status = NULL; - (void) usb_ep_disable (dev->in_ep); - (void) usb_ep_disable (dev->out_ep); + (void) usb_ep_disable(dev->in_ep); + (void) usb_ep_disable(dev->out_ep); dev->in = NULL; dev->out = NULL; } @@ -814,59 +817,61 @@ done: return result; } - -static void eth_reset_config (struct eth_dev *dev) +static void eth_reset_config(struct eth_dev *dev) { if (dev->config == 0) return; debug("%s\n", __func__); - /* disable endpoints, forcing (synchronous) completion of + /* + * disable endpoints, forcing (synchronous) completion of * pending i/o. then free the requests. */ if (dev->in) { - usb_ep_disable (dev->in_ep); + usb_ep_disable(dev->in_ep); if (dev->tx_req) { - usb_ep_free_request (dev->in_ep, dev->tx_req); - dev->tx_req=NULL; + usb_ep_free_request(dev->in_ep, dev->tx_req); + dev->tx_req = NULL; } } if (dev->out) { - usb_ep_disable (dev->out_ep); + usb_ep_disable(dev->out_ep); if (dev->rx_req) { - usb_ep_free_request (dev->out_ep, dev->rx_req); - dev->rx_req=NULL; + usb_ep_free_request(dev->out_ep, dev->rx_req); + dev->rx_req = NULL; } } - if (dev->status) { - usb_ep_disable (dev->status_ep); - } + if (dev->status) + usb_ep_disable(dev->status_ep); + dev->cdc_filter = 0; dev->config = 0; } -/* change our operational config. must agree with the code +/* + * change our operational config. must agree with the code * that returns config descriptors, and altsetting code. */ -static int eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags) +static int eth_set_config(struct eth_dev *dev, unsigned number, + gfp_t gfp_flags) { int result = 0; struct usb_gadget *gadget = dev->gadget; - if (gadget_is_sa1100 (gadget) + if (gadget_is_sa1100(gadget) && dev->config && dev->tx_qlen != 0) { /* tx fifo is full, but we can't clear it...*/ error("can't change configurations"); return -ESPIPE; } - eth_reset_config (dev); + eth_reset_config(dev); switch (number) { case DEV_CONFIG_VALUE: - result = set_ether_config (dev, gfp_flags); + result = set_ether_config(dev, gfp_flags); break; default: result = -EINVAL; @@ -877,7 +882,7 @@ static int eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags if (result) { if (number) - eth_reset_config (dev); + eth_reset_config(dev); usb_gadget_vbus_draw(dev->gadget, gadget_is_otg(dev->gadget) ? 8 : 100); } else { @@ -888,17 +893,20 @@ static int eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags usb_gadget_vbus_draw(dev->gadget, power); switch (gadget->speed) { - case USB_SPEED_FULL: speed = "full"; break; + case USB_SPEED_FULL: + speed = "full"; break; #ifdef CONFIG_USB_GADGET_DUALSPEED - case USB_SPEED_HIGH: speed = "high"; break; + case USB_SPEED_HIGH: + speed = "high"; break; #endif - default: speed = "?"; break; + default: + speed = "?"; break; } dev->config = number; printf("%s speed config #%d: %d mA, %s, using %s\n", speed, number, power, driver_desc, - (cdc_active(dev)? "CDC Ethernet" + (cdc_active(dev) ? "CDC Ethernet" : "CDC Ethernet Subset")); } return result; @@ -908,13 +916,14 @@ static int eth_set_config (struct eth_dev *dev, unsigned number, gfp_t gfp_flags #ifdef DEV_CONFIG_CDC -/* The interrupt endpoint is used in CDC networking models (Ethernet, ATM) +/* + * The interrupt endpoint is used in CDC networking models (Ethernet, ATM) * only to notify the host about link status changes (which we support) or * report completion of some encapsulated command. Since * we want this CDC Ethernet code to be vendor-neutral, we don't use that * command mechanism; and only one status request is ever queued. */ -static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) +static void eth_status_complete(struct usb_ep *ep, struct usb_request *req) { struct usb_cdc_notification *event = req->buf; int value = req->status; @@ -927,38 +936,38 @@ static void eth_status_complete (struct usb_ep *ep, struct usb_request *req) event->bmRequestType = 0xA1; event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; - event->wValue = __constant_cpu_to_le16 (0); - event->wIndex = __constant_cpu_to_le16 (1); - event->wLength = __constant_cpu_to_le16 (8); + event->wValue = __constant_cpu_to_le16(0); + event->wIndex = __constant_cpu_to_le16(1); + event->wLength = __constant_cpu_to_le16(8); /* SPEED_CHANGE data is up/down speeds in bits/sec */ - data [0] = data [1] = cpu_to_le32 (BITRATE (dev->gadget)); + data[0] = data[1] = cpu_to_le32(BITRATE(dev->gadget)); req->length = STATUS_BYTECOUNT; - value = usb_ep_queue (ep, req, GFP_ATOMIC); + value = usb_ep_queue(ep, req, GFP_ATOMIC); debug("send SPEED_CHANGE --> %d\n", value); if (value == 0) return; } else if (value != -ECONNRESET) { debug("event %02x --> %d\n", event->bNotificationType, value); - if (event->bNotificationType== - USB_CDC_NOTIFY_SPEED_CHANGE) - { - l_ethdev.network_started=1; + if (event->bNotificationType == + USB_CDC_NOTIFY_SPEED_CHANGE) { + l_ethdev.network_started = 1; printf("USB network up!\n"); } } req->context = NULL; } -static void issue_start_status (struct eth_dev *dev) +static void issue_start_status(struct eth_dev *dev) { struct usb_request *req = dev->stat_req; struct usb_cdc_notification *event; int value; - /* flush old status + /* + * flush old status * * FIXME ugly idiom, maybe we'd be better with just * a "cancel the whole queue" primitive since any @@ -967,24 +976,25 @@ static void issue_start_status (struct eth_dev *dev) * * FIXME iff req->context != null just dequeue it */ - usb_ep_disable (dev->status_ep); - usb_ep_enable (dev->status_ep, dev->status); + usb_ep_disable(dev->status_ep); + usb_ep_enable(dev->status_ep, dev->status); - /* 3.8.1 says to issue first NETWORK_CONNECTION, then + /* + * 3.8.1 says to issue first NETWORK_CONNECTION, then * a SPEED_CHANGE. could be useful in some configs. */ event = req->buf; event->bmRequestType = 0xA1; event->bNotificationType = USB_CDC_NOTIFY_NETWORK_CONNECTION; - event->wValue = __constant_cpu_to_le16 (1); /* connected */ - event->wIndex = __constant_cpu_to_le16 (1); + event->wValue = __constant_cpu_to_le16(1); /* connected */ + event->wIndex = __constant_cpu_to_le16(1); event->wLength = 0; req->length = sizeof *event; req->complete = eth_status_complete; req->context = dev; - value = usb_ep_queue (dev->status_ep, req, GFP_ATOMIC); + value = usb_ep_queue(dev->status_ep, req, GFP_ATOMIC); if (value < 0) debug("status buf queue --> %d\n", value); } @@ -993,7 +1003,7 @@ static void issue_start_status (struct eth_dev *dev) /*-------------------------------------------------------------------------*/ -static void eth_setup_complete (struct usb_ep *ep, struct usb_request *req) +static void eth_setup_complete(struct usb_ep *ep, struct usb_request *req) { if (req->status || req->actual != req->length) debug("setup complete --> %d, %d/%d\n", @@ -1010,16 +1020,17 @@ static void eth_setup_complete (struct usb_ep *ep, struct usb_request *req) * - class-specific control requests */ static int -eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) +eth_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) { - struct eth_dev *dev = get_gadget_data (gadget); + struct eth_dev *dev = get_gadget_data(gadget); struct usb_request *req = dev->req; int value = -EOPNOTSUPP; u16 wIndex = le16_to_cpu(ctrl->wIndex); u16 wValue = le16_to_cpu(ctrl->wValue); u16 wLength = le16_to_cpu(ctrl->wLength); - /* descriptors just go into the pre-allocated ep0 buffer, + /* + * descriptors just go into the pre-allocated ep0 buffer, * while config change events may enable network traffic. */ @@ -1034,14 +1045,14 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) switch (wValue >> 8) { case USB_DT_DEVICE: - value = min (wLength, (u16) sizeof device_desc); - memcpy (req->buf, &device_desc, value); + value = min(wLength, (u16) sizeof device_desc); + memcpy(req->buf, &device_desc, value); break; case USB_DT_DEVICE_QUALIFIER: if (!gadget_is_dualspeed(gadget)) break; - value = min (wLength, (u16) sizeof dev_qualifier); - memcpy (req->buf, &dev_qualifier, value); + value = min(wLength, (u16) sizeof dev_qualifier); + memcpy(req->buf, &dev_qualifier, value); break; case USB_DT_OTHER_SPEED_CONFIG: @@ -1054,15 +1065,15 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) wValue & 0xff, gadget_is_otg(gadget)); if (value >= 0) - value = min (wLength, (u16) value); + value = min(wLength, (u16) value); break; case USB_DT_STRING: - value = usb_gadget_get_string (&stringtab, + value = usb_gadget_get_string(&stringtab, wValue & 0xff, req->buf); if (value >= 0) - value = min (wLength, (u16) value); + value = min(wLength, (u16) value); break; } @@ -1075,13 +1086,13 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) debug("HNP available\n"); else if (gadget->a_alt_hnp_support) debug("HNP needs a different root port\n"); - value = eth_set_config (dev, wValue, GFP_ATOMIC); + value = eth_set_config(dev, wValue, GFP_ATOMIC); break; case USB_REQ_GET_CONFIGURATION: if (ctrl->bRequestType != USB_DIR_IN) break; *(u8 *)req->buf = dev->config; - value = min (wLength, (u16) 1); + value = min(wLength, (u16) 1); break; case USB_REQ_SET_INTERFACE: @@ -1092,11 +1103,12 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) if (!cdc_active(dev) && wIndex != 0) break; - /* PXA hardware partially handles SET_INTERFACE; + /* + * PXA hardware partially handles SET_INTERFACE; * we need to kluge around that interference. */ - if (gadget_is_pxa (gadget)) { - value = eth_set_config (dev, DEV_CONFIG_VALUE, + if (gadget_is_pxa(gadget)) { + value = eth_set_config(dev, DEV_CONFIG_VALUE, GFP_ATOMIC); goto done_set_intf; } @@ -1107,36 +1119,38 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) if (wValue != 0) break; if (dev->status) { - usb_ep_disable (dev->status_ep); - usb_ep_enable (dev->status_ep, dev->status); + usb_ep_disable(dev->status_ep); + usb_ep_enable(dev->status_ep, dev->status); } value = 0; break; case 1: /* data intf */ if (wValue > 1) break; - usb_ep_disable (dev->in_ep); - usb_ep_disable (dev->out_ep); + usb_ep_disable(dev->in_ep); + usb_ep_disable(dev->out_ep); - /* CDC requires the data transfers not be done from + /* + * CDC requires the data transfers not be done from * the default interface setting ... also, setting * the non-default interface resets filters etc. */ if (wValue == 1) { - if (!cdc_active (dev)) + if (!cdc_active(dev)) break; - usb_ep_enable (dev->in_ep, dev->in); - usb_ep_enable (dev->out_ep, dev->out); + usb_ep_enable(dev->in_ep, dev->in); + usb_ep_enable(dev->out_ep, dev->out); dev->cdc_filter = DEFAULT_FILTER; if (dev->status) - issue_start_status (dev); + issue_start_status(dev); } value = 0; break; } #else - /* FIXME this is wrong, as is the assumption that + /* + * FIXME this is wrong, as is the assumption that * all non-PXA hardware talks real CDC ... */ debug("set_interface ignored!\n"); @@ -1160,12 +1174,13 @@ done_set_intf: /* carrier always ok ...*/ *(u8 *)req->buf = 1 ; } - value = min (wLength, (u16) 1); + value = min(wLength, (u16) 1); break; #ifdef DEV_CONFIG_CDC case USB_CDC_SET_ETHERNET_PACKET_FILTER: - /* see 6.2.30: no data, wIndex = interface, + /* + * see 6.2.30: no data, wIndex = interface, * wValue = packet filter bitmap */ if (ctrl->bRequestType != (USB_TYPE_CLASS|USB_RECIP_INTERFACE) @@ -1178,7 +1193,8 @@ done_set_intf: value = 0; break; - /* and potentially: + /* + * and potentially: * case USB_CDC_SET_ETHERNET_MULTICAST_FILTERS: * case USB_CDC_SET_ETHERNET_PM_PATTERN_FILTER: * case USB_CDC_GET_ETHERNET_PM_PATTERN_FILTER: @@ -1199,11 +1215,11 @@ done_set_intf: req->length = value; req->zero = value < wLength && (value % gadget->ep0->maxpacket) == 0; - value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC); + value = usb_ep_queue(gadget->ep0, req, GFP_ATOMIC); if (value < 0) { debug("ep_queue --> %d\n", value); req->status = 0; - eth_setup_complete (gadget->ep0, req); + eth_setup_complete(gadget->ep0, req); } } @@ -1211,18 +1227,18 @@ done_set_intf: return value; } - /*-------------------------------------------------------------------------*/ -static void rx_complete (struct usb_ep *ep, struct usb_request *req); +static void rx_complete(struct usb_ep *ep, struct usb_request *req); -static int rx_submit ( struct eth_dev *dev, struct usb_request *req, \ +static int rx_submit(struct eth_dev *dev, struct usb_request *req, gfp_t gfp_flags) { int retval = -ENOMEM; size_t size; - /* Padding up to RX_EXTRA handles minor disagreements with host. + /* + * Padding up to RX_EXTRA handles minor disagreements with host. * Normally we use the USB "terminate on short read" convention; * so allow up to (N*maxpacket), since that memory is normally * already allocated. Some hardware doesn't deal well with short @@ -1236,8 +1252,8 @@ static int rx_submit ( struct eth_dev *dev, struct usb_request *req, \ size += dev->out_ep->maxpacket - 1; size -= size % dev->out_ep->maxpacket; - - /* Some platforms perform better when IP packets are aligned, + /* + * Some platforms perform better when IP packets are aligned, * but on at least one, checksumming fails otherwise. */ @@ -1245,37 +1261,35 @@ static int rx_submit ( struct eth_dev *dev, struct usb_request *req, \ req->length = size; req->complete = rx_complete; - retval = usb_ep_queue (dev->out_ep, req, gfp_flags); + retval = usb_ep_queue(dev->out_ep, req, gfp_flags); - if (retval) { + if (retval) error("rx submit --> %d", retval); - } + return retval; } - -static void rx_complete (struct usb_ep *ep, struct usb_request *req) +static void rx_complete(struct usb_ep *ep, struct usb_request *req) { struct eth_dev *dev = ep->driver_data; debug("%s: status %d\n", __func__, req->status); - packet_received=1; + packet_received = 1; if (req) - dev->rx_req=req; + dev->rx_req = req; } - -static int alloc_requests (struct eth_dev *dev, unsigned n, gfp_t gfp_flags) +static int alloc_requests(struct eth_dev *dev, unsigned n, gfp_t gfp_flags) { - dev->tx_req = usb_ep_alloc_request (dev->in_ep, 0); + dev->tx_req = usb_ep_alloc_request(dev->in_ep, 0); if (!dev->tx_req) goto fail; - dev->rx_req = usb_ep_alloc_request (dev->out_ep, 0); + dev->rx_req = usb_ep_alloc_request(dev->out_ep, 0); if (!dev->rx_req) goto fail; @@ -1287,17 +1301,16 @@ fail: return -1; } - -static void tx_complete (struct usb_ep *ep, struct usb_request *req) +static void tx_complete(struct usb_ep *ep, struct usb_request *req) { - debug("%s: status %s\n", __func__, (req->status)?"failed":"ok"); - packet_sent=1; + debug("%s: status %s\n", __func__, (req->status) ? "failed" : "ok"); + packet_sent = 1; } -static inline int eth_is_promisc (struct eth_dev *dev) +static inline int eth_is_promisc(struct eth_dev *dev) { /* no filters for the CDC subset; always promisc */ - if (subset_active (dev)) + if (subset_active(dev)) return 1; return dev->cdc_filter & USB_CDC_PACKET_TYPE_PROMISCUOUS; } @@ -1415,49 +1428,49 @@ drop: /*-------------------------------------------------------------------------*/ #endif -static void eth_unbind (struct usb_gadget *gadget) +static void eth_unbind(struct usb_gadget *gadget) { - struct eth_dev *dev = get_gadget_data (gadget); + struct eth_dev *dev = get_gadget_data(gadget); debug("%s...\n", __func__); /* we've already been disconnected ... no i/o is active */ if (dev->req) { - usb_ep_free_request (gadget->ep0, dev->req); + usb_ep_free_request(gadget->ep0, dev->req); dev->req = NULL; } if (dev->stat_req) { - usb_ep_free_request (dev->status_ep, dev->stat_req); + usb_ep_free_request(dev->status_ep, dev->stat_req); dev->stat_req = NULL; } if (dev->tx_req) { - usb_ep_free_request (dev->in_ep, dev->tx_req); - dev->tx_req=NULL; + usb_ep_free_request(dev->in_ep, dev->tx_req); + dev->tx_req = NULL; } if (dev->rx_req) { - usb_ep_free_request (dev->out_ep, dev->rx_req); - dev->rx_req=NULL; + usb_ep_free_request(dev->out_ep, dev->rx_req); + dev->rx_req = NULL; } /* unregister_netdev (dev->net);*/ /* free_netdev(dev->net);*/ - set_gadget_data (gadget, NULL); + set_gadget_data(gadget, NULL); } -static void eth_disconnect (struct usb_gadget *gadget) +static void eth_disconnect(struct usb_gadget *gadget) { - eth_reset_config (get_gadget_data (gadget)); + eth_reset_config(get_gadget_data(gadget)); } -static void eth_suspend (struct usb_gadget *gadget) +static void eth_suspend(struct usb_gadget *gadget) { /* Not used */ } -static void eth_resume (struct usb_gadget *gadget) +static void eth_resume(struct usb_gadget *gadget) { /* Not used */ } @@ -1492,12 +1505,12 @@ static int is_eth_addr_valid(char *str) return 0; } -static u8 nibble (unsigned char c) +static u8 nibble(unsigned char c) { - if (likely (isdigit (c))) + if (likely(isdigit(c))) return c - '0'; - c = toupper (c); - if (likely (isxdigit (c))) + c = toupper(c); + if (likely(isxdigit(c))) return 10 + c - 'A'; return 0; } @@ -1510,13 +1523,13 @@ static int get_ether_addr(const char *str, u8 *dev_addr) for (i = 0; i < 6; i++) { unsigned char num; - if((*str == '.') || (*str == ':')) + if ((*str == '.') || (*str == ':')) str++; num = nibble(*str++) << 4; num |= (nibble(*str++)); - dev_addr [i] = num; + dev_addr[i] = num; } - if (is_valid_ether_addr (dev_addr)) + if (is_valid_ether_addr(dev_addr)) return 0; } return 1; @@ -1528,17 +1541,18 @@ static int eth_bind(struct usb_gadget *gadget) u8 cdc = 1, zlp = 1; struct usb_ep *in_ep, *out_ep, *status_ep = NULL; int gcnum; - u8 tmp[7]; + u8 tmp[7]; /* these flags are only ever cleared; compiler take note */ #ifndef DEV_CONFIG_CDC cdc = 0; #endif - /* Because most host side USB stacks handle CDC Ethernet, that + /* + * Because most host side USB stacks handle CDC Ethernet, that * standard protocol is _strongly_ preferred for interop purposes. * (By everyone except Microsoft.) */ - if (gadget_is_pxa (gadget)) { + if (gadget_is_pxa(gadget)) { /* pxa doesn't support altsettings */ cdc = 0; } else if (gadget_is_musbhdrc(gadget)) { @@ -1547,20 +1561,22 @@ static int eth_bind(struct usb_gadget *gadget) } else if (gadget_is_sh(gadget)) { /* sh doesn't support multiple interfaces or configs */ cdc = 0; - } else if (gadget_is_sa1100 (gadget)) { + } else if (gadget_is_sa1100(gadget)) { /* hardware can't write zlps */ zlp = 0; - /* sa1100 CAN do CDC, without status endpoint ... we use + /* + * sa1100 CAN do CDC, without status endpoint ... we use * non-CDC to be compatible with ARM Linux-2.4 "usb-eth". */ cdc = 0; } - gcnum = usb_gadget_controller_number (gadget); + gcnum = usb_gadget_controller_number(gadget); if (gcnum >= 0) - device_desc.bcdDevice = cpu_to_le16 (0x0300 + gcnum); + device_desc.bcdDevice = cpu_to_le16(0x0300 + gcnum); else { - /* can't assume CDC works. don't want to default to + /* + * can't assume CDC works. don't want to default to * anything less functional on CDC-capable hardware, * so we fail in this case. */ @@ -1569,7 +1585,8 @@ static int eth_bind(struct usb_gadget *gadget) return -ENODEV; } - /* CDC subset ... recognized by Linux since 2.4.10, but Windows + /* + * CDC subset ... recognized by Linux since 2.4.10, but Windows * drivers aren't widely available. (That may be improved by * supporting one submode of the "SAFE" variant of MDLM.) */ @@ -1588,17 +1605,17 @@ static int eth_bind(struct usb_gadget *gadget) if (bcdDevice) device_desc.bcdDevice = cpu_to_le16(bcdDevice); if (iManufacturer) - strlcpy (manufacturer, iManufacturer, sizeof manufacturer); + strlcpy(manufacturer, iManufacturer, sizeof manufacturer); if (iProduct) - strlcpy (product_desc, iProduct, sizeof product_desc); + strlcpy(product_desc, iProduct, sizeof product_desc); if (iSerialNumber) { device_desc.iSerialNumber = STRING_SERIALNUMBER, strlcpy(serial_number, iSerialNumber, sizeof serial_number); } /* all we really need is bulk IN/OUT */ - usb_ep_autoconfig_reset (gadget); - in_ep = usb_ep_autoconfig (gadget, &fs_source_desc); + usb_ep_autoconfig_reset(gadget); + in_ep = usb_ep_autoconfig(gadget, &fs_source_desc); if (!in_ep) { autoconf_fail: error("can't autoconfigure on %s\n", @@ -1607,17 +1624,18 @@ autoconf_fail: } in_ep->driver_data = in_ep; /* claim */ - out_ep = usb_ep_autoconfig (gadget, &fs_sink_desc); + out_ep = usb_ep_autoconfig(gadget, &fs_sink_desc); if (!out_ep) goto autoconf_fail; out_ep->driver_data = out_ep; /* claim */ #if defined(DEV_CONFIG_CDC) - /* CDC Ethernet control interface doesn't require a status endpoint. + /* + * CDC Ethernet control interface doesn't require a status endpoint. * Since some hosts expect one, try to allocate one anyway. */ if (cdc) { - status_ep = usb_ep_autoconfig (gadget, &fs_status_desc); + status_ep = usb_ep_autoconfig(gadget, &fs_status_desc); if (status_ep) { status_ep->driver_data = status_ep; /* claim */ } else if (cdc) { @@ -1632,7 +1650,8 @@ autoconf_fail: eth_config.bNumInterfaces = 1; eth_config.iConfiguration = STRING_SUBSET; - /* use functions to set these up, in case we're built to work + /* + * use functions to set these up, in case we're built to work * with multiple controllers and must override CDC Ethernet. */ fs_subset_descriptors(); @@ -1640,7 +1659,7 @@ autoconf_fail: } device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket; - usb_gadget_set_selfpowered (gadget); + usb_gadget_set_selfpowered(gadget); if (gadget_is_dualspeed(gadget)) { if (!cdc) @@ -1668,7 +1687,7 @@ autoconf_fail: } dev->net = &l_netdev; - strcpy (dev->net->name, USB_NET_NAME); + strcpy(dev->net->name, USB_NET_NAME); dev->cdc = cdc; dev->zlp = zlp; @@ -1677,7 +1696,8 @@ autoconf_fail: dev->out_ep = out_ep; dev->status_ep = status_ep; - /* Module params for these addresses should come from ID proms. + /* + * Module params for these addresses should come from ID proms. * The host side address is used with CDC, and commonly * ends up in a persistent config database. It's not clear if * host side code for the SAFE thing cares -- its original BLAN @@ -1690,10 +1710,10 @@ autoconf_fail: get_ether_addr(host_addr, dev->host_mac); - sprintf (ethaddr, "%02X%02X%02X%02X%02X%02X", - dev->host_mac [0], dev->host_mac [1], - dev->host_mac [2], dev->host_mac [3], - dev->host_mac [4], dev->host_mac [5]); + sprintf(ethaddr, "%02X%02X%02X%02X%02X%02X", + dev->host_mac[0], dev->host_mac[1], + dev->host_mac[2], dev->host_mac[3], + dev->host_mac[4], dev->host_mac[5]); printf("using %s, OUT %s IN %s%s%s\n", gadget->name, out_ep->name, in_ep->name, @@ -1701,23 +1721,25 @@ autoconf_fail: status_ep ? status_ep->name : "" ); printf("MAC %02x:%02x:%02x:%02x:%02x:%02x\n", - dev->net->enetaddr [0], dev->net->enetaddr [1], - dev->net->enetaddr [2], dev->net->enetaddr [3], - dev->net->enetaddr [4], dev->net->enetaddr [5]); + dev->net->enetaddr[0], dev->net->enetaddr[1], + dev->net->enetaddr[2], dev->net->enetaddr[3], + dev->net->enetaddr[4], dev->net->enetaddr[5]); if (cdc) { printf("HOST MAC %02x:%02x:%02x:%02x:%02x:%02x\n", - dev->host_mac [0], dev->host_mac [1], - dev->host_mac [2], dev->host_mac [3], - dev->host_mac [4], dev->host_mac [5]); + dev->host_mac[0], dev->host_mac[1], + dev->host_mac[2], dev->host_mac[3], + dev->host_mac[4], dev->host_mac[5]); } - /* use PKTSIZE (or aligned... from u-boot) and set - * wMaxSegmentSize accordingly*/ + /* + * use PKTSIZE (or aligned... from u-boot) and set + * wMaxSegmentSize accordingly + */ dev->mtu = PKTSIZE_ALIGN; /* RNDIS does not like this, only 1514, TODO*/ /* preallocate control message data and buffer */ - dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL); + dev->req = usb_ep_alloc_request(gadget->ep0, GFP_KERNEL); if (!dev->req) goto fail; dev->req->buf = control_req; @@ -1726,9 +1748,10 @@ autoconf_fail: /* ... and maybe likewise for status transfer */ #if defined(DEV_CONFIG_CDC) if (dev->status_ep) { - dev->stat_req = usb_ep_alloc_request(dev->status_ep, GFP_KERNEL); + dev->stat_req = usb_ep_alloc_request(dev->status_ep, + GFP_KERNEL); if (!dev->stat_req) { - usb_ep_free_request (dev->status_ep, dev->req); + usb_ep_free_request(dev->status_ep, dev->req); goto fail; } @@ -1739,10 +1762,11 @@ autoconf_fail: /* finish hookup to lower layer ... */ dev->gadget = gadget; - set_gadget_data (gadget, dev); + set_gadget_data(gadget, dev); gadget->ep0->driver_data = dev; - /* two kinds of host-initiated state changes: + /* + * two kinds of host-initiated state changes: * - iff DATA transfer is active, carrier is "on" * - tx queueing enabled if open *and* carrier is "on" */ @@ -1750,13 +1774,13 @@ autoconf_fail: fail: error("%s failed", __func__); - eth_unbind (gadget); + eth_unbind(gadget); return -ENOMEM; } -static int usb_eth_init(struct eth_device* netdev, bd_t* bd) +static int usb_eth_init(struct eth_device *netdev, bd_t *bd) { - struct eth_dev *dev=&l_ethdev; + struct eth_dev *dev = &l_ethdev; struct usb_gadget *gadget; unsigned long ts; unsigned long timeout = USB_CONNECT_TIMEOUT; @@ -1780,8 +1804,7 @@ static int usb_eth_init(struct eth_device* netdev, bd_t* bd) timeout = simple_strtoul(getenv("cdc_connect_timeout"), NULL, 10) * CONFIG_SYS_HZ; ts = get_timer(0); - while (!l_ethdev.network_started) - { + while (!l_ethdev.network_started) { /* Handle control-c and timeouts */ if (ctrlc() || (get_timer(ts) > timeout)) { error("The remote end did not respond in time."); @@ -1790,19 +1813,20 @@ static int usb_eth_init(struct eth_device* netdev, bd_t* bd) usb_gadget_handle_interrupts(); } - rx_submit (dev, dev->rx_req, 0); + rx_submit(dev, dev->rx_req, 0); return 0; fail: return -1; } -static int usb_eth_send(struct eth_device* netdev, volatile void* packet, int length) +static int usb_eth_send(struct eth_device *netdev, + volatile void *packet, int length) { int retval; struct usb_request *req = NULL; struct eth_dev *dev = &l_ethdev; - unsigned long ts; - unsigned long timeout = USB_CONNECT_TIMEOUT; + unsigned long ts; + unsigned long timeout = USB_CONNECT_TIMEOUT; debug("%s:...\n", __func__); @@ -1812,7 +1836,8 @@ static int usb_eth_send(struct eth_device* netdev, volatile void* packet, int le req->context = NULL; req->complete = tx_complete; - /* use zlp framing on tx for strict CDC-Ether conformance, + /* + * use zlp framing on tx for strict CDC-Ether conformance, * though any robust network rx path ignores extra padding. * and some hardware doesn't like to write zlps. */ @@ -1827,54 +1852,50 @@ static int usb_eth_send(struct eth_device* netdev, volatile void* packet, int le req->no_interrupt = (dev->gadget->speed == USB_SPEED_HIGH) ? ((dev->tx_qlen % qmult) != 0) : 0; #endif - dev->tx_qlen=1; - ts = get_timer(0); - packet_sent = 0; + dev->tx_qlen = 1; + ts = get_timer(0); + packet_sent = 0; - retval = usb_ep_queue (dev->in_ep, req, GFP_ATOMIC); + retval = usb_ep_queue(dev->in_ep, req, GFP_ATOMIC); if (!retval) debug("%s: packet queued\n", __func__); - while(!packet_sent) - { - if (get_timer(ts) > timeout) { - printf("timeout sending packets to usb ethernet\n"); - return -1; - } - usb_gadget_handle_interrupts(); + while (!packet_sent) { + if (get_timer(ts) > timeout) { + printf("timeout sending packets to usb ethernet\n"); + return -1; + } + usb_gadget_handle_interrupts(); } return 0; } -static int usb_eth_recv(struct eth_device* netdev) +static int usb_eth_recv(struct eth_device *netdev) { struct eth_dev *dev = &l_ethdev; usb_gadget_handle_interrupts(); - if (packet_received) - { - debug("%s: packet received \n", __func__); - if (dev->rx_req) - { - NetReceive(NetRxPackets[0],dev->rx_req->length); - packet_received=0; + if (packet_received) { + debug("%s: packet received\n", __func__); + if (dev->rx_req) { + NetReceive(NetRxPackets[0], dev->rx_req->length); + packet_received = 0; if (dev->rx_req) - rx_submit (dev, dev->rx_req, 0); - } - else error("dev->rx_req invalid"); + rx_submit(dev, dev->rx_req, 0); + } else + error("dev->rx_req invalid"); } return 0; } -void usb_eth_halt(struct eth_device* netdev) +void usb_eth_halt(struct eth_device *netdev) { - struct eth_dev *dev =&l_ethdev; + struct eth_dev *dev = &l_ethdev; - if (!netdev) - { + if (!netdev) { error("received NULL ptr"); return; } @@ -1898,9 +1919,9 @@ static struct usb_gadget_driver eth_driver = { int usb_eth_initialize(bd_t *bi) { int status = 0; - struct eth_device *netdev=&l_netdev; + struct eth_device *netdev = &l_netdev; - sprintf(netdev->name,"usb_ether"); + sprintf(netdev->name, "usb_ether"); netdev->init = usb_eth_init; netdev->send = usb_eth_send; diff --git a/drivers/usb/gadget/gadget_chips.h b/drivers/usb/gadget/gadget_chips.h index 480bc8769..9bb7e2e77 100644 --- a/drivers/usb/gadget/gadget_chips.h +++ b/drivers/usb/gadget/gadget_chips.h @@ -15,109 +15,109 @@ * Remy Bohmer */ #ifdef CONFIG_USB_GADGET_NET2280 -#define gadget_is_net2280(g) !strcmp("net2280", (g)->name) +#define gadget_is_net2280(g) (!strcmp("net2280", (g)->name)) #else #define gadget_is_net2280(g) 0 #endif #ifdef CONFIG_USB_GADGET_AMD5536UDC -#define gadget_is_amd5536udc(g) !strcmp("amd5536udc", (g)->name) +#define gadget_is_amd5536udc(g) (!strcmp("amd5536udc", (g)->name)) #else #define gadget_is_amd5536udc(g) 0 #endif #ifdef CONFIG_USB_GADGET_DUMMY_HCD -#define gadget_is_dummy(g) !strcmp("dummy_udc", (g)->name) +#define gadget_is_dummy(g) (!strcmp("dummy_udc", (g)->name)) #else #define gadget_is_dummy(g) 0 #endif #ifdef CONFIG_USB_GADGET_PXA2XX -#define gadget_is_pxa(g) !strcmp("pxa2xx_udc", (g)->name) +#define gadget_is_pxa(g) (!strcmp("pxa2xx_udc", (g)->name)) #else #define gadget_is_pxa(g) 0 #endif #ifdef CONFIG_USB_GADGET_GOKU -#define gadget_is_goku(g) !strcmp("goku_udc", (g)->name) +#define gadget_is_goku(g) (!strcmp("goku_udc", (g)->name)) #else #define gadget_is_goku(g) 0 #endif /* SH3 UDC -- not yet ported 2.4 --> 2.6 */ #ifdef CONFIG_USB_GADGET_SUPERH -#define gadget_is_sh(g) !strcmp("sh_udc", (g)->name) +#define gadget_is_sh(g) (!strcmp("sh_udc", (g)->name)) #else #define gadget_is_sh(g) 0 #endif /* not yet stable on 2.6 (would help "original Zaurus") */ #ifdef CONFIG_USB_GADGET_SA1100 -#define gadget_is_sa1100(g) !strcmp("sa1100_udc", (g)->name) +#define gadget_is_sa1100(g) (!strcmp("sa1100_udc", (g)->name)) #else #define gadget_is_sa1100(g) 0 #endif #ifdef CONFIG_USB_GADGET_LH7A40X -#define gadget_is_lh7a40x(g) !strcmp("lh7a40x_udc", (g)->name) +#define gadget_is_lh7a40x(g) (!strcmp("lh7a40x_udc", (g)->name)) #else #define gadget_is_lh7a40x(g) 0 #endif /* handhelds.org tree (?) */ #ifdef CONFIG_USB_GADGET_MQ11XX -#define gadget_is_mq11xx(g) !strcmp("mq11xx_udc", (g)->name) +#define gadget_is_mq11xx(g) (!strcmp("mq11xx_udc", (g)->name)) #else #define gadget_is_mq11xx(g) 0 #endif #ifdef CONFIG_USB_GADGET_OMAP -#define gadget_is_omap(g) !strcmp("omap_udc", (g)->name) +#define gadget_is_omap(g) (!strcmp("omap_udc", (g)->name)) #else #define gadget_is_omap(g) 0 #endif /* not yet ported 2.4 --> 2.6 */ #ifdef CONFIG_USB_GADGET_N9604 -#define gadget_is_n9604(g) !strcmp("n9604_udc", (g)->name) +#define gadget_is_n9604(g) (!strcmp("n9604_udc", (g)->name)) #else #define gadget_is_n9604(g) 0 #endif /* various unstable versions available */ #ifdef CONFIG_USB_GADGET_PXA27X -#define gadget_is_pxa27x(g) !strcmp("pxa27x_udc", (g)->name) +#define gadget_is_pxa27x(g) (!strcmp("pxa27x_udc", (g)->name)) #else #define gadget_is_pxa27x(g) 0 #endif #ifdef CONFIG_USB_GADGET_ATMEL_USBA -#define gadget_is_atmel_usba(g) !strcmp("atmel_usba_udc", (g)->name) +#define gadget_is_atmel_usba(g) (!strcmp("atmel_usba_udc", (g)->name)) #else #define gadget_is_atmel_usba(g) 0 #endif #ifdef CONFIG_USB_GADGET_S3C2410 -#define gadget_is_s3c2410(g) !strcmp("s3c2410_udc", (g)->name) +#define gadget_is_s3c2410(g) (!strcmp("s3c2410_udc", (g)->name)) #else #define gadget_is_s3c2410(g) 0 #endif #ifdef CONFIG_USB_GADGET_AT91 -#define gadget_is_at91(g) !strcmp("at91_udc", (g)->name) +#define gadget_is_at91(g) (!strcmp("at91_udc", (g)->name)) #else #define gadget_is_at91(g) 0 #endif /* status unclear */ #ifdef CONFIG_USB_GADGET_IMX -#define gadget_is_imx(g) !strcmp("imx_udc", (g)->name) +#define gadget_is_imx(g) (!strcmp("imx_udc", (g)->name)) #else #define gadget_is_imx(g) 0 #endif #ifdef CONFIG_USB_GADGET_FSL_USB2 -#define gadget_is_fsl_usb2(g) !strcmp("fsl-usb2-udc", (g)->name) +#define gadget_is_fsl_usb2(g) (!strcmp("fsl-usb2-udc", (g)->name)) #else #define gadget_is_fsl_usb2(g) 0 #endif @@ -125,36 +125,37 @@ /* Mentor high speed function controller */ /* from Montavista kernel (?) */ #ifdef CONFIG_USB_GADGET_MUSBHSFC -#define gadget_is_musbhsfc(g) !strcmp("musbhsfc_udc", (g)->name) +#define gadget_is_musbhsfc(g) (!strcmp("musbhsfc_udc", (g)->name)) #else #define gadget_is_musbhsfc(g) 0 #endif /* Mentor high speed "dual role" controller, in peripheral role */ #ifdef CONFIG_USB_GADGET_MUSB_HDRC -#define gadget_is_musbhdrc(g) !strcmp("musb_hdrc", (g)->name) +#define gadget_is_musbhdrc(g) (!strcmp("musb_hdrc", (g)->name)) #else #define gadget_is_musbhdrc(g) 0 #endif /* from Montavista kernel (?) */ #ifdef CONFIG_USB_GADGET_MPC8272 -#define gadget_is_mpc8272(g) !strcmp("mpc8272_udc", (g)->name) +#define gadget_is_mpc8272(g) (!strcmp("mpc8272_udc", (g)->name)) #else #define gadget_is_mpc8272(g) 0 #endif #ifdef CONFIG_USB_GADGET_M66592 -#define gadget_is_m66592(g) !strcmp("m66592_udc", (g)->name) +#define gadget_is_m66592(g) (!strcmp("m66592_udc", (g)->name)) #else #define gadget_is_m66592(g) 0 #endif -// CONFIG_USB_GADGET_SX2 -// CONFIG_USB_GADGET_AU1X00 -// ... - +/* + * CONFIG_USB_GADGET_SX2 + * CONFIG_USB_GADGET_AU1X00 + * ... + */ /** * usb_gadget_controller_number - support bcdDevice id convention diff --git a/drivers/usb/gadget/usbstring.c b/drivers/usb/gadget/usbstring.c index 168f75f7a..6e9d1bf0f 100644 --- a/drivers/usb/gadget/usbstring.c +++ b/drivers/usb/gadget/usbstring.c @@ -24,14 +24,17 @@ static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len) u8 c; u16 uchar; - /* this insists on correct encodings, though not minimal ones. + /* + * this insists on correct encodings, though not minimal ones. * BUT it currently rejects legit 4-byte UTF-8 code points, * which need surrogate pairs. (Unicode 3.1 can use them.) */ while (len != 0 && (c = (u8) *s++) != 0) { if ((c & 0x80)) { - // 2-byte sequence: - // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx + /* + * 2-byte sequence: + * 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx + */ if ((c & 0xe0) == 0xc0) { uchar = (c & 0x1f) << 6; @@ -41,8 +44,10 @@ static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len) c &= 0x3f; uchar |= c; - // 3-byte sequence (most CJKV characters): - // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx + /* + * 3-byte sequence (most CJKV characters): + * zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx + */ } else if ((c & 0xf0) == 0xe0) { uchar = (c & 0x0f) << 12; @@ -62,12 +67,13 @@ static int utf8_to_utf16le(const char *s, __le16 *cp, unsigned len) if (0xd800 <= uchar && uchar <= 0xdfff) goto fail; - // 4-byte sequence (surrogate pairs, currently rare): - // 11101110wwwwzzzzyy + 110111yyyyxxxxxx - // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx - // (uuuuu = wwww + 1) - // FIXME accept the surrogate code points (only) - + /* + * 4-byte sequence (surrogate pairs, currently rare): + * 11101110wwwwzzzzyy + 110111yyyyxxxxxx + * = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx + * (uuuuu = wwww + 1) + * FIXME accept the surrogate code points (only) + */ } else goto fail; } else @@ -100,17 +106,17 @@ fail: * characters (which are also widely used in C strings). */ int -usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf) +usb_gadget_get_string(struct usb_gadget_strings *table, int id, u8 *buf) { struct usb_string *s; int len; /* descriptor 0 has the language id */ if (id == 0) { - buf [0] = 4; - buf [1] = USB_DT_STRING; - buf [2] = (u8) table->language; - buf [3] = (u8) (table->language >> 8); + buf[0] = 4; + buf[1] = USB_DT_STRING; + buf[2] = (u8) table->language; + buf[3] = (u8) (table->language >> 8); return 4; } for (s = table->strings; s && s->s; s++) @@ -122,13 +128,13 @@ usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf) return -EINVAL; /* string descriptors have length, tag, then UTF16-LE text */ - len = min ((size_t) 126, strlen (s->s)); - memset (buf + 2, 0, 2 * len); /* zero all the bytes */ + len = min((size_t) 126, strlen(s->s)); + memset(buf + 2, 0, 2 * len); /* zero all the bytes */ len = utf8_to_utf16le(s->s, (__le16 *)&buf[2], len); if (len < 0) return -EINVAL; - buf [0] = (len + 1) * 2; - buf [1] = USB_DT_STRING; - return buf [0]; + buf[0] = (len + 1) * 2; + buf[1] = USB_DT_STRING; + return buf[0]; } diff --git a/include/linux/usb/cdc.h b/include/linux/usb/cdc.h index 9b129c9ed..03541cbf2 100644 --- a/include/linux/usb/cdc.h +++ b/include/linux/usb/cdc.h @@ -34,16 +34,16 @@ * Class-Specific descriptors ... there are a couple dozen of them */ -#define USB_CDC_HEADER_TYPE 0x00 /* header_desc */ -#define USB_CDC_CALL_MANAGEMENT_TYPE 0x01 /* call_mgmt_descriptor */ -#define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */ -#define USB_CDC_UNION_TYPE 0x06 /* union_desc */ +#define USB_CDC_HEADER_TYPE 0x00 /* header_desc */ +#define USB_CDC_CALL_MANAGEMENT_TYPE 0x01 /* call_mgmt_descriptor */ +#define USB_CDC_ACM_TYPE 0x02 /* acm_descriptor */ +#define USB_CDC_UNION_TYPE 0x06 /* union_desc */ #define USB_CDC_COUNTRY_TYPE 0x07 -#define USB_CDC_NETWORK_TERMINAL_TYPE 0x0a /* network_terminal_desc */ -#define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */ +#define USB_CDC_NETWORK_TERMINAL_TYPE 0x0a /* network_terminal_desc */ +#define USB_CDC_ETHERNET_TYPE 0x0f /* ether_desc */ #define USB_CDC_WHCM_TYPE 0x11 -#define USB_CDC_MDLM_TYPE 0x12 /* mdlm_desc */ -#define USB_CDC_MDLM_DETAIL_TYPE 0x13 /* mdlm_detail_desc */ +#define USB_CDC_MDLM_TYPE 0x12 /* mdlm_desc */ +#define USB_CDC_MDLM_DETAIL_TYPE 0x13 /* mdlm_detail_desc */ #define USB_CDC_DMM_TYPE 0x14 #define USB_CDC_OBEX_TYPE 0x15 diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h index 1091692e9..49b748337 100644 --- a/include/linux/usb/ch9.h +++ b/include/linux/usb/ch9.h @@ -69,8 +69,8 @@ #define USB_RECIP_ENDPOINT 0x02 #define USB_RECIP_OTHER 0x03 /* From Wireless USB 1.0 */ -#define USB_RECIP_PORT 0x04 -#define USB_RECIP_RPIPE 0x05 +#define USB_RECIP_PORT 0x04 +#define USB_RECIP_RPIPE 0x05 /* * Standard requests, for the bRequest field of a SETUP packet. diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index 344fc787c..275cb5fe1 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -73,9 +73,10 @@ struct usb_ep; * * Bulk endpoints can use any size buffers, and can also be used for interrupt * transfers. interrupt-only endpoints can be much less functional. + * + * NOTE: this is analagous to 'struct urb' on the host side, except that + * it's thinner and promotes more pre-allocation. */ - // NOTE this is analagous to 'struct urb' on the host side, - // except that it's thinner and promotes more pre-allocation. struct usb_request { void *buf; @@ -170,10 +171,10 @@ struct usb_ep { * * returns zero, or a negative error code. */ -static inline int -usb_ep_enable (struct usb_ep *ep, const struct usb_endpoint_descriptor *desc) +static inline int usb_ep_enable(struct usb_ep *ep, + const struct usb_endpoint_descriptor *desc) { - return ep->ops->enable (ep, desc); + return ep->ops->enable(ep, desc); } /** @@ -188,10 +189,9 @@ usb_ep_enable (struct usb_ep *ep, const struct usb_endpoint_descriptor *desc) * * returns zero, or a negative error code. */ -static inline int -usb_ep_disable (struct usb_ep *ep) +static inline int usb_ep_disable(struct usb_ep *ep) { - return ep->ops->disable (ep); + return ep->ops->disable(ep); } /** @@ -208,10 +208,10 @@ usb_ep_disable (struct usb_ep *ep) * * Returns the request, or null if one could not be allocated. */ -static inline struct usb_request * -usb_ep_alloc_request (struct usb_ep *ep, gfp_t gfp_flags) +static inline struct usb_request *usb_ep_alloc_request(struct usb_ep *ep, + gfp_t gfp_flags) { - return ep->ops->alloc_request (ep, gfp_flags); + return ep->ops->alloc_request(ep, gfp_flags); } /** @@ -223,10 +223,10 @@ usb_ep_alloc_request (struct usb_ep *ep, gfp_t gfp_flags) * Caller guarantees the request is not queued, and that it will * no longer be requeued (or otherwise used). */ -static inline void -usb_ep_free_request (struct usb_ep *ep, struct usb_request *req) +static inline void usb_ep_free_request(struct usb_ep *ep, + struct usb_request *req) { - ep->ops->free_request (ep, req); + ep->ops->free_request(ep, req); } /** @@ -283,10 +283,10 @@ usb_ep_free_request (struct usb_ep *ep, struct usb_request *req) * report errors; errors will also be * reported when the usb peripheral is disconnected. */ -static inline int -usb_ep_queue (struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) +static inline int usb_ep_queue(struct usb_ep *ep, + struct usb_request *req, gfp_t gfp_flags) { - return ep->ops->queue (ep, req, gfp_flags); + return ep->ops->queue(ep, req, gfp_flags); } /** @@ -303,9 +303,9 @@ usb_ep_queue (struct usb_ep *ep, struct usb_request *req, gfp_t gfp_flags) * restrictions prevent drivers from supporting configuration changes, * even to configuration zero (a "chapter 9" requirement). */ -static inline int usb_ep_dequeue (struct usb_ep *ep, struct usb_request *req) +static inline int usb_ep_dequeue(struct usb_ep *ep, struct usb_request *req) { - return ep->ops->dequeue (ep, req); + return ep->ops->dequeue(ep, req); } /** @@ -329,10 +329,9 @@ static inline int usb_ep_dequeue (struct usb_ep *ep, struct usb_request *req) * transfer requests are still queued, or if the controller hardware * (usually a FIFO) still holds bytes that the host hasn't collected. */ -static inline int -usb_ep_set_halt (struct usb_ep *ep) +static inline int usb_ep_set_halt(struct usb_ep *ep) { - return ep->ops->set_halt (ep, 1); + return ep->ops->set_halt(ep, 1); } /** @@ -348,10 +347,9 @@ usb_ep_set_halt (struct usb_ep *ep) * Note that some hardware can't support this request (like pxa2xx_udc), * and accordingly can't correctly implement interface altsettings. */ -static inline int -usb_ep_clear_halt (struct usb_ep *ep) +static inline int usb_ep_clear_halt(struct usb_ep *ep) { - return ep->ops->set_halt (ep, 0); + return ep->ops->set_halt(ep, 0); } /** @@ -369,11 +367,10 @@ usb_ep_clear_halt (struct usb_ep *ep) * errno if the endpoint doesn't use a FIFO or doesn't support such * precise handling. */ -static inline int -usb_ep_fifo_status (struct usb_ep *ep) +static inline int usb_ep_fifo_status(struct usb_ep *ep) { if (ep->ops->fifo_status) - return ep->ops->fifo_status (ep); + return ep->ops->fifo_status(ep); else return -EOPNOTSUPP; } @@ -387,11 +384,10 @@ usb_ep_fifo_status (struct usb_ep *ep) * must never be used except when endpoint is not being used for any * protocol translation. */ -static inline void -usb_ep_fifo_flush (struct usb_ep *ep) +static inline void usb_ep_fifo_flush(struct usb_ep *ep) { if (ep->ops->fifo_flush) - ep->ops->fifo_flush (ep); + ep->ops->fifo_flush(ep); } @@ -475,18 +471,18 @@ struct usb_gadget { struct device dev; }; -static inline void set_gadget_data (struct usb_gadget *gadget, void *data) +static inline void set_gadget_data(struct usb_gadget *gadget, void *data) { gadget->dev.driver_data = data; } -static inline void *get_gadget_data (struct usb_gadget *gadget) +static inline void *get_gadget_data(struct usb_gadget *gadget) { return gadget->dev.driver_data; } /* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ -#define gadget_for_each_ep(tmp,gadget) \ +#define gadget_for_each_ep(tmp, gadget) \ list_for_each_entry(tmp, &(gadget)->ep_list, ep_list) @@ -522,7 +518,6 @@ static inline int gadget_is_otg(struct usb_gadget *g) #endif } - /** * usb_gadget_frame_number - returns the current frame number * @gadget: controller that reports the frame number @@ -530,9 +525,9 @@ static inline int gadget_is_otg(struct usb_gadget *g) * Returns the usb frame number, normally eleven bits from a SOF packet, * or negative errno if this device doesn't support this capability. */ -static inline int usb_gadget_frame_number (struct usb_gadget *gadget) +static inline int usb_gadget_frame_number(struct usb_gadget *gadget) { - return gadget->ops->get_frame (gadget); + return gadget->ops->get_frame(gadget); } /** @@ -548,11 +543,11 @@ static inline int usb_gadget_frame_number (struct usb_gadget *gadget) * even if OTG isn't otherwise in use. OTG devices may also start * remote wakeup even when hosts don't explicitly enable it. */ -static inline int usb_gadget_wakeup (struct usb_gadget *gadget) +static inline int usb_gadget_wakeup(struct usb_gadget *gadget) { if (!gadget->ops->wakeup) return -EOPNOTSUPP; - return gadget->ops->wakeup (gadget); + return gadget->ops->wakeup(gadget); } /** @@ -564,12 +559,11 @@ static inline int usb_gadget_wakeup (struct usb_gadget *gadget) * * returns zero on success, else negative errno. */ -static inline int -usb_gadget_set_selfpowered (struct usb_gadget *gadget) +static inline int usb_gadget_set_selfpowered(struct usb_gadget *gadget) { if (!gadget->ops->set_selfpowered) return -EOPNOTSUPP; - return gadget->ops->set_selfpowered (gadget, 1); + return gadget->ops->set_selfpowered(gadget, 1); } /** @@ -582,12 +576,11 @@ usb_gadget_set_selfpowered (struct usb_gadget *gadget) * * returns zero on success, else negative errno. */ -static inline int -usb_gadget_clear_selfpowered (struct usb_gadget *gadget) +static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget) { if (!gadget->ops->set_selfpowered) return -EOPNOTSUPP; - return gadget->ops->set_selfpowered (gadget, 0); + return gadget->ops->set_selfpowered(gadget, 0); } /** @@ -602,12 +595,11 @@ usb_gadget_clear_selfpowered (struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_vbus_connect(struct usb_gadget *gadget) +static inline int usb_gadget_vbus_connect(struct usb_gadget *gadget) { if (!gadget->ops->vbus_session) return -EOPNOTSUPP; - return gadget->ops->vbus_session (gadget, 1); + return gadget->ops->vbus_session(gadget, 1); } /** @@ -622,12 +614,11 @@ usb_gadget_vbus_connect(struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) +static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) { if (!gadget->ops->vbus_draw) return -EOPNOTSUPP; - return gadget->ops->vbus_draw (gadget, mA); + return gadget->ops->vbus_draw(gadget, mA); } /** @@ -640,12 +631,11 @@ usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_vbus_disconnect(struct usb_gadget *gadget) +static inline int usb_gadget_vbus_disconnect(struct usb_gadget *gadget) { if (!gadget->ops->vbus_session) return -EOPNOTSUPP; - return gadget->ops->vbus_session (gadget, 0); + return gadget->ops->vbus_session(gadget, 0); } /** @@ -659,12 +649,11 @@ usb_gadget_vbus_disconnect(struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_connect (struct usb_gadget *gadget) +static inline int usb_gadget_connect(struct usb_gadget *gadget) { if (!gadget->ops->pullup) return -EOPNOTSUPP; - return gadget->ops->pullup (gadget, 1); + return gadget->ops->pullup(gadget, 1); } /** @@ -682,16 +671,14 @@ usb_gadget_connect (struct usb_gadget *gadget) * * Returns zero on success, else negative errno. */ -static inline int -usb_gadget_disconnect (struct usb_gadget *gadget) +static inline int usb_gadget_disconnect(struct usb_gadget *gadget) { if (!gadget->ops->pullup) return -EOPNOTSUPP; - return gadget->ops->pullup (gadget, 0); + return gadget->ops->pullup(gadget, 0); } - /*-------------------------------------------------------------------------*/ /** @@ -774,7 +761,6 @@ struct usb_gadget_driver { }; - /*-------------------------------------------------------------------------*/ /* driver modules register and unregister, as usual. @@ -795,7 +781,7 @@ struct usb_gadget_driver { * the bind() functions will be in init sections. * This function must be called in a context that can sleep. */ -int usb_gadget_register_driver (struct usb_gadget_driver *driver); +int usb_gadget_register_driver(struct usb_gadget_driver *driver); /** * usb_gadget_unregister_driver - unregister a gadget driver @@ -810,7 +796,7 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver); * will in in exit sections, so may not be linked in some kernels. * This function must be called in a context that can sleep. */ -int usb_gadget_unregister_driver (struct usb_gadget_driver *driver); +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); /*-------------------------------------------------------------------------*/ @@ -843,7 +829,7 @@ struct usb_gadget_strings { }; /* put descriptor for string with that id into buf (buflen >= 256) */ -int usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf); +int usb_gadget_get_string(struct usb_gadget_strings *table, int id, u8 *buf); /*-------------------------------------------------------------------------*/ @@ -861,10 +847,10 @@ int usb_gadget_config_buf(const struct usb_config_descriptor *config, /* utility wrapping a simple endpoint selection policy */ -extern struct usb_ep *usb_ep_autoconfig (struct usb_gadget *, +extern struct usb_ep *usb_ep_autoconfig(struct usb_gadget *, struct usb_endpoint_descriptor *); -extern void usb_ep_autoconfig_reset (struct usb_gadget *); +extern void usb_ep_autoconfig_reset(struct usb_gadget *); extern int usb_gadget_handle_interrupts(void); -- cgit v1.2.3-70-g09d2