mirror of
https://github.com/LineageOS/android_kernel_samsung_msm8226.git
synced 2026-09-29 00:00:25 +02:00
usb: gadget: f_fs: HACK: Round reads up to 512 bytes to work with dwc3 Signed-off-by: Arve Hjønnevåg <arve@android.com> USB: f_fs: Fix epfile crash during composition switch epfile's ep pointer may be NULL during adb transfer and composition switch happening in parallel. As part of composition switch, first it is set to NONE. Setting sys.usb.config to NONE stops adb and disables the composition. stop adb is not blocking call and adb still might be doing epfile read/write for some time when function unbind is ongoing making the data structures NULL. To fix this crash, call usb_ep_dequeue only if ep->ep is valid. Similarly in success case, return ep->status only if ep->ep is valid otherwise return -ENODEV. CRs-Fixed: 643663 Change-Id: Ic152fc1db31cad6f97b8d16d91350dad857a4bf9 Signed-off-by: Sujeet Kumar <ksujeet@codeaurora.org> USB: gadget: f_fs: Release endpoint upon disable Endpoints are claimed using usb_ep_autoconfig function, It will choose an unclaimed usb_ep and prevent the endpoint from being returned by a later autoconfig calls. We can mark the driver_data pointer once ep_enable is done in bind. If we cannot mark to null upon function disable the corresponding endpoint is not allocated by a later autoconfig call. The current code does not make the ep->driver_data to null upon function disable. This is leading to unclaimed endpoints for later autoconfig calls. Claim the endpoints by assigning ep->driver_data to NULL. CRs-Fixed: 633673 Change-Id: I221b98ef36cc2a60d27507a2442061a30ed410f4 Signed-off-by: ChandanaKishori Chiluveru <cchilu@codeaurora.org> USB: gagget: f_fs: Return error if TX req is queued during device offline when USB cable is disconnected during TX data transfers, endpoints will be disabled during function disable. If userspace client tries to queue requests on disabled endpoints, driver will wait till endpoints are enabled and then queues previous session requests. This results in kernel driver and userspace driver out of sync and due to this, stall will be seen. Hence fix this issue by returning error value if client tries to queue requests on TX endpoint during device offline. CRs-Fixed: 633497 Change-Id: I3e43b8a704367aff7fe8dd88159315aef811c51c Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org> USB: f_fs: Fail stale read IOs after disconnect After a USB disconnect, endpoints for adb are disabled. After this no IO is allowed on the endpoints. Since, adbd is not aware of this disconnect, it may still perform read/writes IO. For adb writes, IOs are failed, but for adb reads kernel waits untill endpoints are enabled. When a USB disconnect and adb read still queued a buffer to kernel, ffs_epfile_io simply waits for endpoint to be enabled. A next connect happens and endpoints are enabled after set_alt, the adb read stale buffer from previous session continues and queues to endpoint. All this time, adb did not close the epfile because it did not get return status on the IOs which it queued. This is an issue, because a new session is not established and both userspace and kernel goes out of sync. To fix this issue, when endpoints are disbled set epfile error. This epfile error is only cleared in epfile open. This will ensure that after a USB disconnect and connect, new session is established. Also, return ENODEV if endpoints not enabled rather than EINTR as EINTR case, and simply retries the request. Incase usb_ep_queue failed, return -EIO inspite of depend on return status from usb_ep_queue. CRs-Fixed: 633497 Change-Id: I6e677e98ec28e5462b372ed290acdde251286f48 Signed-off-by: Sujeet Kumar <ksujeet@codeaurora.org> USB: f_fs: Cutoff epfile IO before epfile could get freed epfile may get freed and accessing epfile's error flag to cut off IOs may lead to use after free. Move the epfile error flag setting above in the order so that it guaranteed to be valid. CRs-Fixed: 668046 Change-Id: I0017513393ddb4fd288cd4e1c2adf9d5ee3bc660 Signed-off-by: Sujeet Kumar <ksujeet@codeaurora.org> USB: f_fs: Check error status before doing epfile I/O Set error status before disabling endpoint during function disable and also check error status before handling I/O. If error status is set, return error status to read/write calls made by userspace. Also set file's private data to NULL during epfile release. CRs-Fixed: 671880 Change-Id: I14b5ee541dfc18a7802ef4a8033878a7729d9adb Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org> USB: f_fs: Fix disconnect check during ongoing IO F_FS function driver allocated ffs_eps and updates ffs_ep->ep to corresponding usb_ep during func->bind and never clears it. On bind it also saves ffs_ep context in epfile->ep. During func->disable, it clears only ffs_ep context in epfile->ep and on func->unbind it frees ffs_eps memory. ffs_epfile_io routine currently relies on ffs_ep->ep (which is never cleared and ffs_ep could be freed on unbind) to detect any disconnect during active IO. This can result in various issues e.g. use after free use of ffs_ep if unbind finished before epfile_io could resume or "stop adbd" trying to dequeue a freed USB request when epfile_io could execute only after F_FS got disabled as 'if (ep->ep)' check would be TRUE. Fix this by checking stored ffs_ep context against latest epfile->ep to figure out if endpoint got disabled or changed before acquiring spin_lock. Change-Id: I6bdcdf0dff0813ed7b2af8c24f544a22796b0369 Signed-off-by: Manu Gautam <mgautam@codeaurora.org> USB: f_fs: Move ep completion out of stack Allocating completion on the stack may lead to invalid access when udc irq tries to complete the request but interrupted completion returns immediately. This happens because request is not held to be dequeued anymore making the completion invalid. Move the completions in ffs data like it is for ep0. CRs-Fixed: 653761 Change-Id: I15102538d1b5bee14dfa3c7b3fa1f8e3f767cf71 Signed-off-by: Sujeet Kumar <ksujeet@codeaurora.org> usb: dwc3: gadget: Release gadget lock when handling suspend/resume gadget_driver suspend/resume operations might require some dwc3-gadget operations, such as enabling and disabling endpoints. If the lock is not released, this can cause a deadlock scenario. Change-Id: I1e12de65e40492b115ab35de78c2352730649db5 Signed-off-by: Bar Weiner <bweiner@codeaurora.org> usb: dwc3: gadget: Iterate only over valid endpoints Make dwc3_gadget_resize_tx_fifos() iterate only over IN endpoints that are actually present, based on the num_in_eps parameter. This terminates the loop so as to prevent dereferencing a potential NULL dwc->eps[i] where i >= (num_in_eps + num_out_eps). Change-Id: I07f711bfd380dce212e86b59cf417f84ca7eb006 Signed-off-by: Jack Pham <jackp@codeaurora.org> usb: dwc3: gadget: Protect against ep disabling during completion In dwc3_cleanup_done_reqs(), a potential race condition could arise when dwc3_gadget_giveback() temporarily releases the main spinlock. If during this window the very endpoint being handled becomes disabled, it would lead to a NULL pointer dereference in the code that follows. Guard against this by making sure the endpoint is still enabled after returning from the giveback call. CRs-fixed: 628972 Change-Id: Ifdb823fff12747f699217d871a5959c85b5340f7 Signed-off-by: Jack Pham <jackp@codeaurora.org> usb: dwc3: calculate the number of endpoints hwparams2 holds the number of endpoints which were selected during RTL generation, we can use that on our driver. Signed-off-by: Felipe Balbi <balbi@ti.com> usb: dwc3: gadget: use num_(in|out)_eps from HW params that way we will only tell gadget framework about the endpoints we actually have. Change-Id: Iabc6a5712b640a9f5b0310984650a4ac44e5f579 Signed-off-by: Felipe Balbi <balbi@ti.com> usb: gadget: always update HS/SS descriptors and create a copy of them HS and SS descriptors are staticaly created. They are updated during the bind process with the endpoint address, string id or interface numbers. After that, the descriptor chain is linked to struct usb_function which is used by composite in order to serve the GET_DESCRIPTOR requests, number of available configs and so on. There is no need to assign the HS descriptor only if the UDC supports HS speed because composite won't report those to the host if HS support has not been reached. The same reasoning is valid for SS. This patch makes sure each function updates HS/SS descriptors unconditionally and uses the newly introduced helper function to create a copy the descriptors for the speed which is supported by the UDC. While at that, also rename f->descriptors to f->fs_descriptors in order to make it more explicit what that means. Change-Id: Id670fcc25b0a1cb3020722cfc6eda2e1b08441f1 Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Felipe Balbi <balbi@ti.com> USB: Add super speed descriptors for android functions Update android function drivers like diag, adb, modem, rmnet, mtp and accessory to operate in super speed. The burst capability is not enabled for now. Change-Id: Ie95cbfc9444c56c8268b70e2916713190699c71a Signed-off-by: Pavankumar Kondeti <pkondeti@codeaurora.org> usb: gadget: Finish conversion to fs_descriptor change Change-Id: Iaf72d66bb5cd6b84f14c5aaeb01ffb286568c97b usb: gadget: f_fs: Add support for SuperSpeed Mode Allow userspace to pass SuperSpeed descriptors and handle them in the driver accordingly. This change doesn't modify existing desc_header and thereby keeps the ABI changes backward compatible i.e. existing userspace drivers compiled with old header (functionfs.h) would continue to work with the updated kernel. Change-Id: Ic27035fdef2a83828024348d75be1518e9f8c5c6 Signed-off-by: Manu Gautam <mgautam@codeaurora.org> USB: f_fs: Set ffs->func to NULL after disabling endpoint in set_alt() When adb root is performed, userspace will close and open ffs_epsfile. Closing this file will call ffs_functionfs_callback() which does call remove_config(). This will call ffs_function_eps_disable to disable endpoints and then calls ffs_func_unbind(). Unbind() will also call endpoint disable which might lead to disabling endpoint which is already disabled. Hence set ffs->func to NULL after disabling endpoints in set_alt(). CRs-Fixed: 557532 Change-Id: I3052bdee74a1793d4e003de4b991d353e5d699b0 Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org> usb: gadget: throttle IRQ rate for SuperSpeed There was a merge error from commit 6e0c86d12 "USB: gadget: u_ether: Fix data stall issue in RNDIS tethering mode" that resulted in the accidental removal of checking if the gadget is connected at SuperSpeed. Re-introduce this check so that IRQs on the downlink path are throttled, decreasing the load on the CPU. Change-Id: Ic2aa1d433e0fded95c6e825a760e89f726360522 Signed-off-by: Jack Pham <jackp@codeaurora.org> USB: mbim: Add super speed descriptors for MBIM function This change adds super speed descriptors which is required to get MBIM function to work with SSUSB mode. The burst capability is not enabled for now. CRs-Fixed: 626744 Change-Id: I2a492182c94265ab58014cac470448f61782625c Signed-off-by: Mayank Rana <mrana@codeaurora.org> usb: gadget: ECM: Add super speed descriptors for qc_ecm function This change adds super speed descriptors which is required to get ECM function to work with SSUSB mode. CRs-Fixed: 627063 Change-Id: I275a32f6cb957b59bfdf1c5b5377ba6e189efb6d Signed-off-by: Mayank Rana <mrana@codeaurora.org> usb: gadget: Add file for USB HID function This file the same as f_hid.c. Change-Id: I951b3067f477c3cb502c8320693ab11df90150d2 Signed-off-by: muluhe <muluhe@codeaurora.org> Signed-off-by: Aravind Asam <aasam@codeaurora.org> Signed-off-by: Ameya Thakur <ameyat@codeaurora.org> usb: gadget: Enable HID function for charging mode Provide HID function for only charging mode, in this mode device enumerated as one input device. Change-Id: I769adf76807b8a28adcc298de0536fa779176016 Signed-off-by: Mulu He <muluhe@codeaurora.org> usb: gadget: composite: Fix USB version number for L1 When usb version number is greater than 2.01 USB-CV expects to find a Super Speed USB Device Capability descriptor. When we want to enable BOS descriptor capabilities for a high-speed device the USB version number should be 2.01. CRs-Fixed: 521752 Change-Id: Ic75b5e570b3c2df8e67370389dfddc8de6fb72d4 Signed-off-by: Shimrit Malichi <smalichi@codeaurora.org> usb: gadget: Fix compilation of f_mbim driver after SS updates Change-Id: I72e7dfa5c8f3905bbe57e227ebb7e7035d8b671c [haggertk: port to samsung_msm8974, don't pick this for your own use] Signed-off-by: Kevin F. Haggerty <haggertk@lineageos.org>
400 lines
16 KiB
C
400 lines
16 KiB
C
/*
|
|
* composite.h -- framework for usb gadgets which are composite devices
|
|
*
|
|
* Copyright (C) 2006-2008 David Brownell
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef __LINUX_USB_COMPOSITE_H
|
|
#define __LINUX_USB_COMPOSITE_H
|
|
|
|
/*
|
|
* This framework is an optional layer on top of the USB Gadget interface,
|
|
* making it easier to build (a) Composite devices, supporting multiple
|
|
* functions within any single configuration, and (b) Multi-configuration
|
|
* devices, also supporting multiple functions but without necessarily
|
|
* having more than one function per configuration.
|
|
*
|
|
* Example: a device with a single configuration supporting both network
|
|
* link and mass storage functions is a composite device. Those functions
|
|
* might alternatively be packaged in individual configurations, but in
|
|
* the composite model the host can use both functions at the same time.
|
|
*/
|
|
|
|
#include <linux/usb/ch9.h>
|
|
#include <linux/usb/gadget.h>
|
|
|
|
/*
|
|
* USB function drivers should return USB_GADGET_DELAYED_STATUS if they
|
|
* wish to delay the data/status stages of the control transfer till they
|
|
* are ready. The control transfer will then be kept from completing till
|
|
* all the function drivers that requested for USB_GADGET_DELAYED_STAUS
|
|
* invoke usb_composite_setup_continue().
|
|
*/
|
|
#define USB_GADGET_DELAYED_STATUS 0x7fff /* Impossibly large value */
|
|
|
|
struct usb_configuration;
|
|
|
|
/**
|
|
* struct usb_function - describes one function of a configuration
|
|
* @name: For diagnostics, identifies the function.
|
|
* @strings: tables of strings, keyed by identifiers assigned during bind()
|
|
* and by language IDs provided in control requests
|
|
* @descriptors: Table of full (or low) speed descriptors, using interface and
|
|
* string identifiers assigned during @bind(). If this pointer is null,
|
|
* the function will not be available at full speed (or at low speed).
|
|
* @hs_descriptors: Table of high speed descriptors, using interface and
|
|
* string identifiers assigned during @bind(). If this pointer is null,
|
|
* the function will not be available at high speed.
|
|
* @ss_descriptors: Table of super speed descriptors, using interface and
|
|
* string identifiers assigned during @bind(). If this
|
|
* pointer is null after initiation, the function will not
|
|
* be available at super speed.
|
|
* @config: assigned when @usb_add_function() is called; this is the
|
|
* configuration with which this function is associated.
|
|
* @bind: Before the gadget can register, all of its functions bind() to the
|
|
* available resources including string and interface identifiers used
|
|
* in interface or class descriptors; endpoints; I/O buffers; and so on.
|
|
* @unbind: Reverses @bind; called as a side effect of unregistering the
|
|
* driver which added this function.
|
|
* @set_alt: (REQUIRED) Reconfigures altsettings; function drivers may
|
|
* initialize usb_ep.driver data at this time (when it is used).
|
|
* Note that setting an interface to its current altsetting resets
|
|
* interface state, and that all interfaces have a disabled state.
|
|
* @get_alt: Returns the active altsetting. If this is not provided,
|
|
* then only altsetting zero is supported.
|
|
* @disable: (REQUIRED) Indicates the function should be disabled. Reasons
|
|
* include host resetting or reconfiguring the gadget, and disconnection.
|
|
* @setup: Used for interface-specific control requests.
|
|
* @suspend: Notifies functions when the host stops sending USB traffic.
|
|
* @resume: Notifies functions when the host restarts USB traffic.
|
|
* @get_status: Returns function status as a reply to
|
|
* GetStatus() request when the recepient is Interface.
|
|
* @func_suspend: callback to be called when
|
|
* SetFeature(FUNCTION_SUSPEND) is reseived
|
|
*
|
|
* A single USB function uses one or more interfaces, and should in most
|
|
* cases support operation at both full and high speeds. Each function is
|
|
* associated by @usb_add_function() with a one configuration; that function
|
|
* causes @bind() to be called so resources can be allocated as part of
|
|
* setting up a gadget driver. Those resources include endpoints, which
|
|
* should be allocated using @usb_ep_autoconfig().
|
|
*
|
|
* To support dual speed operation, a function driver provides descriptors
|
|
* for both high and full speed operation. Except in rare cases that don't
|
|
* involve bulk endpoints, each speed needs different endpoint descriptors.
|
|
*
|
|
* Function drivers choose their own strategies for managing instance data.
|
|
* The simplest strategy just declares it "static', which means the function
|
|
* can only be activated once. If the function needs to be exposed in more
|
|
* than one configuration at a given speed, it needs to support multiple
|
|
* usb_function structures (one for each configuration).
|
|
*
|
|
* A more complex strategy might encapsulate a @usb_function structure inside
|
|
* a driver-specific instance structure to allows multiple activations. An
|
|
* example of multiple activations might be a CDC ACM function that supports
|
|
* two or more distinct instances within the same configuration, providing
|
|
* several independent logical data links to a USB host.
|
|
*/
|
|
struct usb_function {
|
|
const char *name;
|
|
struct usb_gadget_strings **strings;
|
|
struct usb_descriptor_header **hs_descriptors;
|
|
struct usb_descriptor_header **ss_descriptors;
|
|
struct usb_descriptor_header **fs_descriptors;
|
|
|
|
struct usb_configuration *config;
|
|
#ifdef CONFIG_USB_ANDROID_SAMSUNG_COMPOSITE
|
|
int (*set_intf_num)(struct usb_function *f,
|
|
int intf_num, int index_num);
|
|
int (*set_config_desc)(int conf_num);
|
|
#endif
|
|
/* REVISIT: bind() functions can be marked __init, which
|
|
* makes trouble for section mismatch analysis. See if
|
|
* we can't restructure things to avoid mismatching.
|
|
* Related: unbind() may kfree() but bind() won't...
|
|
*/
|
|
|
|
/* configuration management: bind/unbind */
|
|
int (*bind)(struct usb_configuration *,
|
|
struct usb_function *);
|
|
void (*unbind)(struct usb_configuration *,
|
|
struct usb_function *);
|
|
|
|
/* runtime state management */
|
|
int (*set_alt)(struct usb_function *,
|
|
unsigned interface, unsigned alt);
|
|
int (*get_alt)(struct usb_function *,
|
|
unsigned interface);
|
|
void (*disable)(struct usb_function *);
|
|
int (*setup)(struct usb_function *,
|
|
const struct usb_ctrlrequest *);
|
|
void (*suspend)(struct usb_function *);
|
|
void (*resume)(struct usb_function *);
|
|
|
|
/* USB 3.0 additions */
|
|
int (*get_status)(struct usb_function *);
|
|
int (*func_suspend)(struct usb_function *,
|
|
u8 suspend_opt);
|
|
/* private: */
|
|
/* internals */
|
|
struct list_head list;
|
|
DECLARE_BITMAP(endpoints, 32);
|
|
};
|
|
|
|
int usb_add_function(struct usb_configuration *, struct usb_function *);
|
|
|
|
int usb_function_deactivate(struct usb_function *);
|
|
int usb_function_activate(struct usb_function *);
|
|
|
|
int usb_interface_id(struct usb_configuration *, struct usb_function *);
|
|
|
|
int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f,
|
|
struct usb_ep *_ep);
|
|
|
|
#define MAX_CONFIG_INTERFACES 16 /* arbitrary; max 255 */
|
|
|
|
/**
|
|
* struct usb_configuration - represents one gadget configuration
|
|
* @label: For diagnostics, describes the configuration.
|
|
* @strings: Tables of strings, keyed by identifiers assigned during @bind()
|
|
* and by language IDs provided in control requests.
|
|
* @descriptors: Table of descriptors preceding all function descriptors.
|
|
* Examples include OTG and vendor-specific descriptors.
|
|
* @unbind: Reverses @bind; called as a side effect of unregistering the
|
|
* driver which added this configuration.
|
|
* @setup: Used to delegate control requests that aren't handled by standard
|
|
* device infrastructure or directed at a specific interface.
|
|
* @bConfigurationValue: Copied into configuration descriptor.
|
|
* @iConfiguration: Copied into configuration descriptor.
|
|
* @bmAttributes: Copied into configuration descriptor.
|
|
* @bMaxPower: Copied into configuration descriptor.
|
|
* @cdev: assigned by @usb_add_config() before calling @bind(); this is
|
|
* the device associated with this configuration.
|
|
*
|
|
* Configurations are building blocks for gadget drivers structured around
|
|
* function drivers. Simple USB gadgets require only one function and one
|
|
* configuration, and handle dual-speed hardware by always providing the same
|
|
* functionality. Slightly more complex gadgets may have more than one
|
|
* single-function configuration at a given speed; or have configurations
|
|
* that only work at one speed.
|
|
*
|
|
* Composite devices are, by definition, ones with configurations which
|
|
* include more than one function.
|
|
*
|
|
* The lifecycle of a usb_configuration includes allocation, initialization
|
|
* of the fields described above, and calling @usb_add_config() to set up
|
|
* internal data and bind it to a specific device. The configuration's
|
|
* @bind() method is then used to initialize all the functions and then
|
|
* call @usb_add_function() for them.
|
|
*
|
|
* Those functions would normally be independent of each other, but that's
|
|
* not mandatory. CDC WMC devices are an example where functions often
|
|
* depend on other functions, with some functions subsidiary to others.
|
|
* Such interdependency may be managed in any way, so long as all of the
|
|
* descriptors complete by the time the composite driver returns from
|
|
* its bind() routine.
|
|
*/
|
|
struct usb_configuration {
|
|
const char *label;
|
|
struct usb_gadget_strings **strings;
|
|
const struct usb_descriptor_header **descriptors;
|
|
|
|
/* REVISIT: bind() functions can be marked __init, which
|
|
* makes trouble for section mismatch analysis. See if
|
|
* we can't restructure things to avoid mismatching...
|
|
*/
|
|
|
|
/* configuration management: unbind/setup */
|
|
void (*unbind)(struct usb_configuration *);
|
|
int (*setup)(struct usb_configuration *,
|
|
const struct usb_ctrlrequest *);
|
|
|
|
/* fields in the config descriptor */
|
|
u8 bConfigurationValue;
|
|
u8 iConfiguration;
|
|
u8 bmAttributes;
|
|
u8 bMaxPower;
|
|
|
|
struct usb_composite_dev *cdev;
|
|
|
|
/* private: */
|
|
/* internals */
|
|
struct list_head list;
|
|
struct list_head functions;
|
|
u8 next_interface_id;
|
|
unsigned superspeed:1;
|
|
unsigned highspeed:1;
|
|
unsigned fullspeed:1;
|
|
struct usb_function *interface[MAX_CONFIG_INTERFACES];
|
|
};
|
|
|
|
int usb_add_config(struct usb_composite_dev *,
|
|
struct usb_configuration *,
|
|
int (*)(struct usb_configuration *));
|
|
|
|
int usb_remove_config(struct usb_composite_dev *,
|
|
struct usb_configuration *);
|
|
|
|
/**
|
|
* struct usb_composite_driver - groups configurations into a gadget
|
|
* @name: For diagnostics, identifies the driver.
|
|
* @iProduct: Used as iProduct override if @dev->iProduct is not set.
|
|
* If NULL value of @name is taken.
|
|
* @iManufacturer: Used as iManufacturer override if @dev->iManufacturer is
|
|
* not set. If NULL a default "<system> <release> with <udc>" value
|
|
* will be used.
|
|
* @dev: Template descriptor for the device, including default device
|
|
* identifiers.
|
|
* @strings: tables of strings, keyed by identifiers assigned during bind()
|
|
* and language IDs provided in control requests
|
|
* @max_speed: Highest speed the driver supports.
|
|
* @needs_serial: set to 1 if the gadget needs userspace to provide
|
|
* a serial number. If one is not provided, warning will be printed.
|
|
* @unbind: Reverses bind; called as a side effect of unregistering
|
|
* this driver.
|
|
* @disconnect: optional driver disconnect method
|
|
* @suspend: Notifies when the host stops sending USB traffic,
|
|
* after function notifications
|
|
* @resume: Notifies configuration when the host restarts USB traffic,
|
|
* before function notifications
|
|
*
|
|
* Devices default to reporting self powered operation. Devices which rely
|
|
* on bus powered operation should report this in their @bind() method.
|
|
*
|
|
* Before returning from bind, various fields in the template descriptor
|
|
* may be overridden. These include the idVendor/idProduct/bcdDevice values
|
|
* normally to bind the appropriate host side driver, and the three strings
|
|
* (iManufacturer, iProduct, iSerialNumber) normally used to provide user
|
|
* meaningful device identifiers. (The strings will not be defined unless
|
|
* they are defined in @dev and @strings.) The correct ep0 maxpacket size
|
|
* is also reported, as defined by the underlying controller driver.
|
|
*/
|
|
struct usb_composite_driver {
|
|
const char *name;
|
|
const char *iProduct;
|
|
const char *iManufacturer;
|
|
const struct usb_device_descriptor *dev;
|
|
struct usb_gadget_strings **strings;
|
|
enum usb_device_speed max_speed;
|
|
unsigned needs_serial:1;
|
|
|
|
int (*unbind)(struct usb_composite_dev *);
|
|
|
|
void (*disconnect)(struct usb_composite_dev *);
|
|
|
|
/* global suspend hooks */
|
|
void (*suspend)(struct usb_composite_dev *);
|
|
void (*resume)(struct usb_composite_dev *);
|
|
};
|
|
|
|
extern int usb_composite_probe(struct usb_composite_driver *driver,
|
|
int (*bind)(struct usb_composite_dev *cdev));
|
|
extern void usb_composite_unregister(struct usb_composite_driver *driver);
|
|
extern void usb_composite_setup_continue(struct usb_composite_dev *cdev);
|
|
|
|
|
|
/**
|
|
* struct usb_composite_device - represents one composite usb gadget
|
|
* @gadget: read-only, abstracts the gadget's usb peripheral controller
|
|
* @req: used for control responses; buffer is pre-allocated
|
|
* @bufsiz: size of buffer pre-allocated in @req
|
|
* @config: the currently active configuration
|
|
*
|
|
* One of these devices is allocated and initialized before the
|
|
* associated device driver's bind() is called.
|
|
*
|
|
* OPEN ISSUE: it appears that some WUSB devices will need to be
|
|
* built by combining a normal (wired) gadget with a wireless one.
|
|
* This revision of the gadget framework should probably try to make
|
|
* sure doing that won't hurt too much.
|
|
*
|
|
* One notion for how to handle Wireless USB devices involves:
|
|
* (a) a second gadget here, discovery mechanism TBD, but likely
|
|
* needing separate "register/unregister WUSB gadget" calls;
|
|
* (b) updates to usb_gadget to include flags "is it wireless",
|
|
* "is it wired", plus (presumably in a wrapper structure)
|
|
* bandgroup and PHY info;
|
|
* (c) presumably a wireless_ep wrapping a usb_ep, and reporting
|
|
* wireless-specific parameters like maxburst and maxsequence;
|
|
* (d) configurations that are specific to wireless links;
|
|
* (e) function drivers that understand wireless configs and will
|
|
* support wireless for (additional) function instances;
|
|
* (f) a function to support association setup (like CBAF), not
|
|
* necessarily requiring a wireless adapter;
|
|
* (g) composite device setup that can create one or more wireless
|
|
* configs, including appropriate association setup support;
|
|
* (h) more, TBD.
|
|
*/
|
|
struct usb_composite_dev {
|
|
struct usb_gadget *gadget;
|
|
struct usb_request *req;
|
|
unsigned bufsiz;
|
|
|
|
struct usb_configuration *config;
|
|
|
|
/* private: */
|
|
/* internals */
|
|
unsigned int suspended:1;
|
|
struct usb_device_descriptor desc;
|
|
struct list_head configs;
|
|
struct usb_composite_driver *driver;
|
|
u8 next_string_id;
|
|
u8 manufacturer_override;
|
|
u8 product_override;
|
|
u8 serial_override;
|
|
|
|
/* the gadget driver won't enable the data pullup
|
|
* while the deactivation count is nonzero.
|
|
*/
|
|
unsigned deactivations;
|
|
|
|
/* the composite driver won't complete the control transfer's
|
|
* data/status stages till delayed_status is zero.
|
|
*/
|
|
int delayed_status;
|
|
|
|
/* protects deactivations and delayed_status counts*/
|
|
spinlock_t lock;
|
|
|
|
/*
|
|
* specify the mA units for the bMaxPower field in
|
|
* the configuration descriptor. Should be 2mA for HS
|
|
* and 8mA for SS.
|
|
*/
|
|
int vbus_draw_units;
|
|
};
|
|
|
|
extern int usb_string_id(struct usb_composite_dev *c);
|
|
extern int usb_string_ids_tab(struct usb_composite_dev *c,
|
|
struct usb_string *str);
|
|
extern int usb_string_ids_n(struct usb_composite_dev *c, unsigned n);
|
|
|
|
|
|
/* messaging utils */
|
|
#define DBG(d, fmt, args...) \
|
|
dev_dbg(&(d)->gadget->dev , fmt , ## args)
|
|
#define VDBG(d, fmt, args...) \
|
|
dev_vdbg(&(d)->gadget->dev , fmt , ## args)
|
|
#define ERROR(d, fmt, args...) \
|
|
dev_err(&(d)->gadget->dev , fmt , ## args)
|
|
#define WARNING(d, fmt, args...) \
|
|
dev_warn(&(d)->gadget->dev , fmt , ## args)
|
|
#define INFO(d, fmt, args...) \
|
|
dev_info(&(d)->gadget->dev , fmt , ## args)
|
|
|
|
#endif /* __LINUX_USB_COMPOSITE_H */
|