Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1325342 > unrolled thread
| Started by | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| First post | 2016-02-03 13:50 +0100 |
| Last post | 2016-02-03 14:00 +0100 |
| Articles | 20 on this page of 44 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH v4 00/43] usb: gadget: composite: introduce new function API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 10/43] usb: gadget: composite: handle vendor descs Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 16/43] usb: gadget: composite: add usb_function_get_ep() function Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 24/43] usb: gadget: f_rndis: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 18/43] usb: gadget: composite: usb_get_endpoint_address() function Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 06/43] usb: gadget: composite: introduce new descriptors format Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
Re: [PATCH v4 06/43] usb: gadget: composite: introduce new descriptors format kbuild test robot <lkp@intel.com> - 2016-02-04 06:20 +0100
[PATCH v4 15/43] usb: gadget: composite: handle get_alt() automatically Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 04/43] usb: gadget: configfs: fix error path Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 37/43] usb: gadget: f_mass_storage: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 23/43] usb: gadget: f_ecm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 02/43] usb: gadget: f_sourcesink: free requests in sourcesink_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 13/43] usb: gadget: composite: enable eps before calling set_alt() callback Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 32/43] usb: gadget: f_obex: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 20/43] usb: gadget: configfs: add new composite API support Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 27/43] usb: gadget: f_acm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 26/43] usb: gadget: f_hid: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 30/43] usb: gadget: f_printer: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 08/43] usb: gadget: composite: introduce new USB function ops Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 35/43] usb: gadget: f_uac1: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 31/43] usb: gadget: f_serial: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 42/43] Documentation: update uvc configfs interface description Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 43/43] usb: gadget: f_uvc: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 25/43] usb: gadget: f_hid: handle requests lifetime properly Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 03/43] usb: gadget: f_loopback: free requests in loopback_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 38/43] usb: gadget: u_serial: remove usb_ep_enable()/usb_ep_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 34/43] usb: gadget: f_subset: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 29/43] usb: gadget: f_ncm: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 22/43] usb: gadget: f_sourcesink: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 39/43] usb: gadget: u_ether: remove usb_ep_enable()/usb_ep_disable() Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 40/43] usb: gadget: uvc: fix typo in UVCG_OPTS_ATTR() macro Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 36/43] usb: gadget: f_uac2: conversion to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 41/43] usb: gadget: uvc: simplify descriptors generation Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 13:50 +0100
[PATCH v4 09/43] usb: gadget: composite: handle function bind Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
Re: [PATCH v4 09/43] usb: gadget: composite: handle function bind kbuild test robot <lkp@intel.com> - 2016-02-04 06:50 +0100
[PATCH v4 01/43] usb: gadget: f_sourcesink: make ISO altset user-selectable Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 12/43] usb: gadget: composite: disable eps before calling disable() callback Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 17/43] usb: gadget: composite: add usb_get_interface_id() function Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 19/43] usb: gadget: composite: enable adding USB functions using new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 05/43] usb: gadget: composite: fix recursive spinlock locking Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 21/43] usb: gadget: f_loopback: convert to new API Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 14/43] usb: gadget: composite: introduce clear_alt() operation Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 11/43] usb: gadget: composite: generate old descs for compatibility Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
[PATCH v4 07/43] usb: gadget: composite: add functions for descriptors handling Robert Baldyga <r.baldyga@samsung.com> - 2016-02-03 14:00 +0100
Page 1 of 3 [1] 2 3 Next page →
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 00/43] usb: gadget: composite: introduce new function API |
| Message-ID | <qY52F-212-5@gated-at.bofh.it> |
Hi Felipe,
Here is my new patch series doing a lot of changes in composite framework
and modifying USB Function API. Some of concepts changed significantly,
for example bind process is done automatically inside composite framework
after collecting descriptors from all Functions. Hence bind() operation
of USB Function has been replaced with prep_descs(). Besides the other
benefits, such as simple implementation of gadget-level autoconfig solver,
changes in API allowed to simplify code of USB Functions, which contain
lots of boilerplate code.
First five patches of this series are fixes or improvements, being
preparation for further changes. Patches from 6 to 20 add implementation
of new features. Some code allowing coexistence of both old and new API
is added. This code will be removed after converting all USB Functions
present in kernel to new API.
Last 23 patches converts Functions: loopback, sourcesink, ecm, rndis,
hid, acm, eem, ncm, printer, serial, obex, phonet, ECM subset, uac1,
uac2, mass_storage and UVC to new API. Conversion of remaining Functions
will be provided soon.
*** What has changed? ***
The main changes are listed below:
A. Introduce new descriptors format. It makes descriptors creation process
simpler plus creates good place to contain additional information such
as result of automatic bind or actually selected altsetting.
B. Split descriptors creation process into two stages, implemented by
two new operations:
- prep_descs() provide entity descriptors (interfaces, altsettings
and endpoints)
- prep_vendor_descs() provide class and vendor specific descriptors.
The first one is called before binding funciton to UDC and it's
mandatory, because it provides information needed during bind process.
The second one is optional and a Function can implement it if it wants
to attach some class or vendor specific descriptors. It's called after
bind process, so from it's context all information about interface
numbers and endpoint addresses is accessible.
C. Perform bind automatically inside composite framework after collecting
descriptors from all USB Functions. Besides removing lots of repetitive
code from USB Functions, it gives us two main advantages:
- We can have gadget-level autoconfig solver providing better endpoint
resources usage. We can choose best endpoint configuration for all
Functions in all configurations.
- We have composite driver structure creation process separated from
bind process which allows to modify configfs to operate directly
on composite driver state - both legacy gadgets and configfs can
use common composite driver creation process.
Function allowing to obtain endpoints after bind process is provided,
and it should be called in set_alt().
D. Replace disable() operation with more powerful clear_alt(). It is
called when Function is being disabled or when altsetting being
selected on interface which already has active altsetting. It makes
API more symmetric, which greatly simplifies resource management.
E. Handle endpoint enable/disable automatically, which means, that in
set_alt() we obtain set of already enabled endpoints for current
altsetting. Likewise in clear_alt() endpoints are already disabled.
F. Change meaning of second parameter of set_alt() operation. Now it
contains index of interface within desctiptors array of given USB
Function instead of bInterfaceNumber of this interface, which
simplifies altsetting handling (so far it was necessary to compare
this value with bInterfaceNumber of each interface to find out which
altsetting of which interface is being selected).
G. Handle get_alt() automatically. Currently selected altsetting number
is stored for each interface.
*** How did it work before? ***
So far USB Functions had to handle bind process manually and deal with
endpoints state explicitly, which has been making code lengthy and
bug-prone. USB Functions contained lots of repetitive code which was
usually copied while creating new USB Function module. This resulted
with lots of boilerplate code scattered across all Functions present
in Linux kernel.
BIND:
During bind process we had to obtain interface id manually and assign
it to each interface descriptor (altsetting) of given interface. We also
had to obtain endpoints manually using usb_ep_autoconfig(). Beside its
verbosity, this solution resulted with suboptimal endpoints distribution,
because autoconfig algorithm was aware of requirements of only single
endpoint at a time.
udc_bind_to_driver() {
composite_bind() {
configuration1->bind() {
function1->bind() {
intf1_id = usb_interface_id(); // Obtain intf id manually
ep1 = usb_ep_autoconfig(); // Endpoint-level autoconfig
ep2 = usb_ep_autoconfig();
intf2_id = usb_interface_id();
ep3 = usb_ep_autoconfig();
ep4 = usb_ep_autoconfig();
}
function2->bind() {
intf1_id = usb_interface_id();
ep1 = usb_ep_autoconfig();
ep2 = usb_ep_autoconfig();
ep3 = usb_ep_autoconfig();
}
function3->bind() {
intf1_id = usb_interface_id();
ep1 = usb_ep_autoconfig();
intf2_id = usb_interface_id();
ep2 = usb_ep_autoconfig();
}
}
configuration2->bind() {
function1->bind() {
intf1_id = usb_interface_id();
ep1 = usb_ep_autoconfig();
}
function2->bind() {
intf1_id = usb_interface_id();
ep1 = usb_ep_autoconfig();
}
}
}
}
SET_ALT:
In set_alt() we had to guess if any altsetting for given interface had
been selected before or not. In fact many functions have been doing this
by storing some information in driver_data field of endpoints or simply
by doing interface reset regardless of previous state. We also needed
to guess for which interface set_alt() has been called, because interface
number passed to this callback was the interface index in configuration,
not index in function descriptors. It has been making set_alt() handling
quite problematic.
function1->set_alt() {
id = detect_intf_id();
if (id == intf1_id) {
intf_specific_disable(); // Disable everything just in case
usb_ep_disable(ep1); // Disable endpoint manually
usb_ep_disable(ep2);
config_ep_by_speed(ep1); // Configure endpoint manually
config_ep_by_speed(ep2);
usb_ep_enable(ep1); // Enable endpoint manually
usb_ep_enable(ep2);
intf_specific_enable();
} else {
intf_specific_disable();
usb_ep_disable(ep3);
usb_ep_disable(ep4);
config_ep_by_speed(ep3);
config_ep_by_speed(ep4);
usb_ep_enable(ep3);
usb_ep_enable(ep4);
intf_specific_enable();
}
}
function2->set_alt() {
function_specific_disable();
usb_ep_disable(ep1);
usb_ep_disable(ep2);
config_ep_by_speed(ep1);
config_ep_by_speed(ep2);
usb_ep_enable(ep1);
usb_ep_enable(ep2);
function_specific_enable();
}
DISABLE:
The disable() callback has been called only when entire Function had
being disabled. In this function we had to deactivate all functionality
and disable all endpoints manually.
function1->disable() {
function_specific_disable();
usb_ep_disable(ep1); // Disable endpoint manually
usb_ep_disable(ep2);
usb_ep_disable(ep3);
usb_ep_disable(ep4);
}
function2->disable() {
function_specific_disable();
usb_ep_disable(ep1);
usb_ep_disable(ep2);
}
*** How does it work now? ***
BIND:
Bind process is done entirely by composite framework internals. To
achieve this, composite needs to have a knowledge about interfaces and
endpoints which the Function is comprised of. This knowledge is provided
by prep_descs() callback which assigns descriptors needed for bind process
to Function. Having all descriptors collected allows to implement
configuration-level or even gadget-level autoconfig solver. This solver
could, basing on information from descriptors and endpoint capabilities
of UDC hardware, which gadget driver is being bound to, distribute
endpoints over interfaces in much more optimal way than it has been done
so far. At the end, after binding gadget to UDC hardware,
prep_vendor_descs() callback is invoked for each Function to allow it
to provide some class and vendor specific descriptors.
udc_bind_to_driver() {
composite_bind() {
configuration1->bind() {
function1->prep_descs() { // Gather descriptors
usb_function_set_descs(); // Set descs to Function
}
function2->prep_descs() {
usb_function_set_descs();
}
function3->prep_descs() {
usb_function_set_descs();
}
}
usb_config_do_bind(); // Bind entire configuration
configuration2->bind() {
function1->prep_descs() {
usb_function_set_descs();
}
function2->prep_descs() {
usb_function_set_descs();
}
}
usb_config_do_bind();
composite_prep_vendor_descs(); // Gather class and vendor descs
}
}
SET_ALT:
In set_alt() function we have to obtain endpoints for currently selected
altsetting. Endpoints are already configured and enabled. Interface number
passed to set_alt() is its index within Function descriptors array, which
simplifies set_alt() handling. We also don't need to remember if any
altsetting has been previously selected, because in such situation
clear_alt() is called before set_alt(), to allow function to cleanup
interface state.
function1->set_alt() {
if (intf == 0) {
ep1 = usb_function_get_ep();
ep2 = usb_function_get_ep();
intf_specific_enable();
} else {
ep3 = usb_function_get_ep();
ep4 = usb_function_get_ep();
intf_specific_enable();
}
}
function2->set_alt() {
ep1 = usb_function_get_ep();
ep2 = usb_function_get_ep();
function_specific_enable();
}
CLEAR_ALT:
In clear_alt() callback function can clear interface state and free
resources allocated in set_alt(). It's called before selecting altsetting
in interface which has already selected active altsetting, or when
function is being disabled. Thanks to this clear_alt() can be used as
an enhanced replacement of disable() operation.
function1->clear_alt() {
if (intf == 0) {
intf_specific_disable();
} else {
intf_specific_disable();
}
}
function2->clear_alt() {
function_specific_disable();
}
*** What's next? ***
The next step is to convert all Functions to new API and cleanup composite
code. Then it will be possible to implement intelligent configuration-level
autoconfig solver. We can also try to implement gadget-level autoconfig
solver which could be capable to reconfigure UDC hardware according to
requirements of specific gadget driver.
Thanks to separation of bind process from composite driver creation
process (adding function to configuration doesn't involve its bind, so
it can be done before hardware is available), we can also simplify
configfs gadget implementation. We can make legacy gadgets and configfs
using common composite driver creation process.
I believe it's also possible to make descriptors creation process less
verbose by providing set of macros/functions dedicated for this purpose
(now descriptors take at average over 200 lines of code per Function).
I have some WIP version of patches in which I'm doing part of changes
mentioned above. I can send them as RFC to show what is final result
which I want to achieve.
Best regards,
Robert Baldyga
Changelog:
v4:
- Added 7 new patches
- Few minor fixes
v3: https://lkml.org/lkml/2015/12/11/311
- Fixed handling of vendor specific descriptor attached to endpoint
- Added 6 new patches converting Functions to new API
v2: https://lkml.org/lkml/2015/11/27/180
- Addressed comments from Sergei
- Added 6 new patches converting Functions to new API
v1: https://lkml.org/lkml/2015/11/3/288
Robert Baldyga (43):
usb: gadget: f_sourcesink: make ISO altset user-selectable
usb: gadget: f_sourcesink: free requests in sourcesink_disable()
usb: gadget: f_loopback: free requests in loopback_disable()
usb: gadget: configfs: fix error path
usb: gadget: composite: fix recursive spinlock locking
usb: gadget: composite: introduce new descriptors format
usb: gadget: composite: add functions for descriptors handling
usb: gadget: composite: introduce new USB function ops
usb: gadget: composite: handle function bind
usb: gadget: composite: handle vendor descs
usb: gadget: composite: generate old descs for compatibility
usb: gadget: composite: disable eps before calling disable() callback
usb: gadget: composite: enable eps before calling set_alt() callback
usb: gadget: composite: introduce clear_alt() operation
usb: gadget: composite: handle get_alt() automatically
usb: gadget: composite: add usb_function_get_ep() function
usb: gadget: composite: add usb_get_interface_id() function
usb: gadget: composite: usb_get_endpoint_address() function
usb: gadget: composite: enable adding USB functions using new API
usb: gadget: configfs: add new composite API support
usb: gadget: f_loopback: convert to new API
usb: gadget: f_sourcesink: convert to new API
usb: gadget: f_ecm: conversion to new API
usb: gadget: f_rndis: conversion to new API
usb: gadget: f_hid: handle requests lifetime properly
usb: gadget: f_hid: conversion to new API
usb: gadget: f_acm: conversion to new API
usb: gadget: f_eem: conversion to new API
usb: gadget: f_ncm: conversion to new API
usb: gadget: f_printer: conversion to new API
usb: gadget: f_serial: conversion to new API
usb: gadget: f_obex: conversion to new API
usb: gadget: f_phonet: conversion to new API
usb: gadget: f_subset: conversion to new API
usb: gadget: f_uac1: conversion to new API
usb: gadget: f_uac2: conversion to new API
usb: gadget: f_mass_storage: conversion to new API
usb: gadget: u_serial: remove usb_ep_enable()/usb_ep_disable()
usb: gadget: u_ether: remove usb_ep_enable()/usb_ep_disable()
usb: gadget: uvc: fix typo in UVCG_OPTS_ATTR() macro
usb: gadget: uvc: simplify descriptors generation
Documentation: update uvc configfs interface description
usb: gadget: f_uvc: conversion to new API
Documentation/ABI/testing/configfs-usb-gadget-uvc | 39 +-
Documentation/usb/gadget-testing.txt | 18 +-
drivers/usb/gadget/composite.c | 987 +++++++++++++++++++++-
drivers/usb/gadget/configfs.c | 24 +-
drivers/usb/gadget/function/f_acm.c | 248 ++----
drivers/usb/gadget/function/f_ecm.c | 321 ++-----
drivers/usb/gadget/function/f_eem.c | 154 +---
drivers/usb/gadget/function/f_hid.c | 307 +++----
drivers/usb/gadget/function/f_loopback.c | 218 ++---
drivers/usb/gadget/function/f_mass_storage.c | 91 +-
drivers/usb/gadget/function/f_ncm.c | 320 +++----
drivers/usb/gadget/function/f_obex.c | 188 ++---
drivers/usb/gadget/function/f_phonet.c | 225 ++---
drivers/usb/gadget/function/f_printer.c | 300 ++-----
drivers/usb/gadget/function/f_rndis.c | 321 +++----
drivers/usb/gadget/function/f_serial.c | 122 +--
drivers/usb/gadget/function/f_sourcesink.c | 415 ++++-----
drivers/usb/gadget/function/f_subset.c | 165 ++--
drivers/usb/gadget/function/f_uac1.c | 134 ++-
drivers/usb/gadget/function/f_uac2.c | 360 +++-----
drivers/usb/gadget/function/f_uvc.c | 532 ++++--------
drivers/usb/gadget/function/g_zero.h | 6 +-
drivers/usb/gadget/function/storage_common.c | 29 -
drivers/usb/gadget/function/storage_common.h | 3 -
drivers/usb/gadget/function/u_ether.c | 28 +-
drivers/usb/gadget/function/u_serial.c | 16 -
drivers/usb/gadget/function/u_uvc.h | 14 +-
drivers/usb/gadget/function/uvc.h | 10 +-
drivers/usb/gadget/function/uvc_configfs.c | 81 +-
drivers/usb/gadget/legacy/webcam.c | 43 +-
drivers/usb/gadget/legacy/zero.c | 12 +
include/linux/usb/composite.h | 204 +++++
32 files changed, 2655 insertions(+), 3280 deletions(-)
--
1.9.1
[toc] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 10/43] usb: gadget: composite: handle vendor descs |
| Message-ID | <qY52F-212-13@gated-at.bofh.it> |
| In reply to | #1325342 |
After binding all configurations in gadget, call prep_vendor_descs()
for each function which uses new API and implements this callback.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/composite.c | 31 +++++++++++++++++++++++++++++++
include/linux/usb/composite.h | 2 ++
2 files changed, 33 insertions(+)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f196bb6..4f5556b 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -2565,6 +2565,33 @@ int usb_config_do_bind(struct usb_configuration *c)
}
EXPORT_SYMBOL_GPL(usb_config_do_bind);
+/**
+ * composite_prep_vendor_descs - for each function in each configuration call
+ * prep_vendor_descs() callback.
+ * @cdev: composite device
+ */
+int composite_prep_vendor_descs(struct usb_composite_dev *cdev)
+{
+ struct usb_configuration *c;
+ struct usb_function *f;
+ int ret;
+
+ list_for_each_entry(c, &cdev->configs, list)
+ list_for_each_entry(f, &c->functions, list) {
+ if (!usb_function_is_new_api(f))
+ continue;
+ if (f->prep_vendor_descs) {
+ ret = f->prep_vendor_descs(f);
+ if (ret)
+ return ret;
+ }
+
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(composite_prep_vendor_descs);
+
static int composite_bind(struct usb_gadget *gadget,
struct usb_gadget_driver *gdriver)
{
@@ -2595,6 +2622,10 @@ static int composite_bind(struct usb_gadget *gadget,
if (status < 0)
goto fail;
+ status = composite_prep_vendor_descs(cdev);
+ if (status < 0)
+ goto fail;
+
if (cdev->use_os_string) {
status = composite_os_desc_req_prepare(cdev, gadget->ep0);
if (status)
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 0a0ff4c..0db473f 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -599,6 +599,8 @@ extern int composite_os_desc_req_prepare(struct usb_composite_dev *cdev,
struct usb_ep *ep0);
void composite_dev_cleanup(struct usb_composite_dev *cdev);
+int composite_prep_vendor_descs(struct usb_composite_dev *cdev);
+
void composite_free_descs(struct usb_composite_dev *cdev);
void composite_free_vendor_descs(struct usb_composite_dev *cdev);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 16/43] usb: gadget: composite: add usb_function_get_ep() function |
| Message-ID | <qY52F-212-15@gated-at.bofh.it> |
| In reply to | #1325342 |
Introduce function returning endpoint of given index in active altsetting
of specified interface. It's intended to be used in set_alt() callback
to obtain endpoints of currently selected altsetting.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/composite.c | 33 +++++++++++++++++++++++++++++++++
include/linux/usb/composite.h | 2 ++
2 files changed, 35 insertions(+)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index a4b5346..452294e 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -670,6 +670,39 @@ static int usb_interface_id_to_index(struct usb_function *f, u8 id)
}
/**
+ * usb_function_get_ep - obtains endpoint of given index from active
+ * altsetting of given interface
+ * @f: USB function
+ * @i: index of interface in given function
+ * @e: index of endpoint in active altsetting of given interface
+ *
+ * This function is designed to be used in set_alt() callback, when
+ * new altsetting is selected. It allows to obtain endpoints assigned
+ * to altsetting during autoconfig process.
+ *
+ * Returns pointer to endpoint on success or NULL on failure.
+ */
+struct usb_ep *usb_function_get_ep(struct usb_function *f, int i, int e)
+{
+ struct usb_composite_altset *altset;
+ int selected_altset;
+
+ if (!f->descs)
+ return NULL;
+ if (i >= f->descs->intfs_num)
+ return NULL;
+
+ selected_altset = f->descs->intfs[i]->cur_altset;
+ altset = f->descs->intfs[i]->altsets[selected_altset];
+
+ if (e >= altset->eps_num)
+ return NULL;
+
+ return altset->eps[e]->ep;
+}
+EXPORT_SYMBOL_GPL(usb_function_get_ep);
+
+/**
* usb_interface_id() - allocate an unused interface ID
* @config: configuration associated with the interface
* @function: function handling the interface
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index aa55377..2e646e3 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -425,6 +425,8 @@ int usb_ep_add_vendor_desc(struct usb_function *f, int i, int a, int e,
const struct usb_descriptor_header *desc);
+struct usb_ep *usb_function_get_ep(struct usb_function *f, int intf, int ep);
+
int usb_interface_id(struct usb_configuration *, struct usb_function *);
int config_ep_by_speed(struct usb_gadget *g, struct usb_function *f,
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 24/43] usb: gadget: f_rndis: conversion to new API |
| Message-ID | <qY52G-212-19@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Implement prep_vendor_descs() to supply class specific
descriptors. Change set_alt() implementation and implement clear_alt()
operation. Remove boilerplate code. Change USB request lifetime
management - now it's allocated in set_alt() and freed in clear_alt().
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_rndis.c | 321 ++++++++++++----------------------
1 file changed, 112 insertions(+), 209 deletions(-)
diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c
index e587767..abe11a7 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -212,24 +212,6 @@ static struct usb_endpoint_descriptor fs_out_desc = {
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
-static struct usb_descriptor_header *eth_fs_function[] = {
- (struct usb_descriptor_header *) &rndis_iad_descriptor,
-
- /* control interface matches ACM, not Ethernet */
- (struct usb_descriptor_header *) &rndis_control_intf,
- (struct usb_descriptor_header *) &header_desc,
- (struct usb_descriptor_header *) &call_mgmt_descriptor,
- (struct usb_descriptor_header *) &rndis_acm_descriptor,
- (struct usb_descriptor_header *) &rndis_union_desc,
- (struct usb_descriptor_header *) &fs_notify_desc,
-
- /* data interface has no altsetting */
- (struct usb_descriptor_header *) &rndis_data_intf,
- (struct usb_descriptor_header *) &fs_in_desc,
- (struct usb_descriptor_header *) &fs_out_desc,
- NULL,
-};
-
/* high speed support: */
static struct usb_endpoint_descriptor hs_notify_desc = {
@@ -260,24 +242,6 @@ static struct usb_endpoint_descriptor hs_out_desc = {
.wMaxPacketSize = cpu_to_le16(512),
};
-static struct usb_descriptor_header *eth_hs_function[] = {
- (struct usb_descriptor_header *) &rndis_iad_descriptor,
-
- /* control interface matches ACM, not Ethernet */
- (struct usb_descriptor_header *) &rndis_control_intf,
- (struct usb_descriptor_header *) &header_desc,
- (struct usb_descriptor_header *) &call_mgmt_descriptor,
- (struct usb_descriptor_header *) &rndis_acm_descriptor,
- (struct usb_descriptor_header *) &rndis_union_desc,
- (struct usb_descriptor_header *) &hs_notify_desc,
-
- /* data interface has no altsetting */
- (struct usb_descriptor_header *) &rndis_data_intf,
- (struct usb_descriptor_header *) &hs_in_desc,
- (struct usb_descriptor_header *) &hs_out_desc,
- NULL,
-};
-
/* super speed support: */
static struct usb_endpoint_descriptor ss_notify_desc = {
@@ -327,26 +291,20 @@ static struct usb_ss_ep_comp_descriptor ss_bulk_comp_desc = {
/* .bmAttributes = 0, */
};
-static struct usb_descriptor_header *eth_ss_function[] = {
- (struct usb_descriptor_header *) &rndis_iad_descriptor,
-
- /* control interface matches ACM, not Ethernet */
- (struct usb_descriptor_header *) &rndis_control_intf,
- (struct usb_descriptor_header *) &header_desc,
- (struct usb_descriptor_header *) &call_mgmt_descriptor,
- (struct usb_descriptor_header *) &rndis_acm_descriptor,
- (struct usb_descriptor_header *) &rndis_union_desc,
- (struct usb_descriptor_header *) &ss_notify_desc,
- (struct usb_descriptor_header *) &ss_intr_comp_desc,
-
- /* data interface has no altsetting */
- (struct usb_descriptor_header *) &rndis_data_intf,
- (struct usb_descriptor_header *) &ss_in_desc,
- (struct usb_descriptor_header *) &ss_bulk_comp_desc,
- (struct usb_descriptor_header *) &ss_out_desc,
- (struct usb_descriptor_header *) &ss_bulk_comp_desc,
- NULL,
-};
+USB_COMPOSITE_ENDPOINT(ep_notify, &fs_notify_desc, &hs_notify_desc,
+ &ss_notify_desc, &ss_intr_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_in, &fs_in_desc, &hs_in_desc,
+ &ss_in_desc, &ss_bulk_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_out, &fs_out_desc, &hs_out_desc,
+ &ss_out_desc, &ss_bulk_comp_desc);
+
+USB_COMPOSITE_ALTSETTING(intf0alt0, &rndis_control_intf, &ep_notify);
+USB_COMPOSITE_ALTSETTING(intf1alt0, &rndis_data_intf, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+USB_COMPOSITE_INTERFACE(intf1, &intf1alt0);
+
+USB_COMPOSITE_DESCRIPTORS(rndis_descs, &intf0, &intf1);
/* string descriptors: */
@@ -542,36 +500,35 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
/* we know alt == 0 */
- if (intf == rndis->ctrl_id) {
+ if (intf == 0) {
VDBG(cdev, "reset rndis control %d\n", intf);
- usb_ep_disable(rndis->notify);
- if (!rndis->notify->desc) {
- VDBG(cdev, "init rndis ctrl %d\n", intf);
- if (config_ep_by_speed(cdev->gadget, f, rndis->notify))
- goto fail;
- }
- usb_ep_enable(rndis->notify);
-
- } else if (intf == rndis->data_id) {
- struct net_device *net;
+ rndis->notify = usb_function_get_ep(f, intf, 0);
+ if (!rndis->notify)
+ return -ENODEV;
- if (rndis->port.in_ep->enabled) {
- DBG(cdev, "reset rndis\n");
- gether_disconnect(&rndis->port);
+ /* allocate notification request and buffer */
+ rndis->notify_req = usb_ep_alloc_request(rndis->notify,
+ GFP_KERNEL);
+ if (!rndis->notify_req)
+ return -ENOMEM;
+ rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
+ if (!rndis->notify_req->buf) {
+ usb_ep_free_request(rndis->notify, rndis->notify_req);
+ return -ENOMEM;
}
+ rndis->notify_req->length = STATUS_BYTECOUNT;
+ rndis->notify_req->context = rndis;
+ rndis->notify_req->complete = rndis_response_complete;
+ } else if (intf == 1) {
+ struct net_device *net;
- if (!rndis->port.in_ep->desc || !rndis->port.out_ep->desc) {
- DBG(cdev, "init rndis\n");
- if (config_ep_by_speed(cdev->gadget, f,
- rndis->port.in_ep) ||
- config_ep_by_speed(cdev->gadget, f,
- rndis->port.out_ep)) {
- rndis->port.in_ep->desc = NULL;
- rndis->port.out_ep->desc = NULL;
- goto fail;
- }
- }
+ rndis->port.in_ep = usb_function_get_ep(f, intf, 0);
+ if (!rndis->port.in_ep)
+ return -ENODEV;
+ rndis->port.out_ep = usb_function_get_ep(f, intf, 1);
+ if (!rndis->port.out_ep)
+ return -ENODEV;
/* Avoid ZLPs; they can be troublesome. */
rndis->port.is_zlp_ok = false;
@@ -597,28 +554,25 @@ static int rndis_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
rndis_set_param_dev(rndis->params, net,
&rndis->port.cdc_filter);
- } else
- goto fail;
+ }
return 0;
-fail:
- return -EINVAL;
}
-static void rndis_disable(struct usb_function *f)
+static void rndis_clear_alt(struct usb_function *f,
+ unsigned intf, unsigned alt)
{
struct f_rndis *rndis = func_to_rndis(f);
struct usb_composite_dev *cdev = f->config->cdev;
- if (!rndis->notify->enabled)
- return;
-
- DBG(cdev, "rndis deactivated\n");
-
- rndis_uninit(rndis->params);
- gether_disconnect(&rndis->port);
-
- usb_ep_disable(rndis->notify);
+ if (intf == 0) {
+ kfree(rndis->notify_req->buf);
+ usb_ep_free_request(rndis->notify, rndis->notify_req);
+ } else if (intf == 1) {
+ DBG(cdev, "rndis deactivated\n");
+ rndis_uninit(rndis->params);
+ gether_disconnect(&rndis->port);
+ }
}
/*-------------------------------------------------------------------------*/
@@ -663,22 +617,19 @@ static inline bool can_support_rndis(struct usb_configuration *c)
/* ethernet function driver setup/binding */
-static int
-rndis_bind(struct usb_configuration *c, struct usb_function *f)
+static int rndis_prep_descs(struct usb_function *f)
{
- struct usb_composite_dev *cdev = c->cdev;
struct f_rndis *rndis = func_to_rndis(f);
- struct usb_string *us;
+ struct f_rndis_opts *rndis_opts;
+ struct usb_composite_dev *cdev = f->config->cdev;
+ struct usb_string *us;
int status;
- struct usb_ep *ep;
- struct f_rndis_opts *rndis_opts;
+ rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst);
- if (!can_support_rndis(c))
+ if (!can_support_rndis(f->config))
return -EINVAL;
- rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst);
-
if (cdev->use_os_string) {
f->os_desc_table = kzalloc(sizeof(*f->os_desc_table),
GFP_KERNEL);
@@ -688,21 +639,6 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
f->os_desc_table[0].os_desc = &rndis_opts->rndis_os_desc;
}
- /*
- * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
- * configurations are bound in sequence with list_for_each_entry,
- * in each configuration its functions are bound in sequence
- * with list_for_each_entry, so we assume no race condition
- * with regard to rndis_opts->bound access
- */
- if (!rndis_opts->bound) {
- gether_set_gadget(rndis_opts->net, cdev->gadget);
- status = gether_register_netdev(rndis_opts->net);
- if (status)
- goto fail;
- rndis_opts->bound = true;
- }
-
us = usb_gstrings_attach(cdev, rndis_strings,
ARRAY_SIZE(rndis_string_defs));
if (IS_ERR(us)) {
@@ -713,79 +649,72 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
rndis_data_intf.iInterface = us[1].id;
rndis_iad_descriptor.iFunction = us[2].id;
- /* allocate instance-specific interface IDs */
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- rndis->ctrl_id = status;
- rndis_iad_descriptor.bFirstInterface = status;
-
- rndis_control_intf.bInterfaceNumber = status;
- rndis_union_desc.bMasterInterface0 = status;
+ return usb_function_set_descs(f, &rndis_descs);
- if (cdev->use_os_string)
- f->os_desc_table[0].if_id =
- rndis_iad_descriptor.bFirstInterface;
+fail:
+ kfree(f->os_desc_table);
+ f->os_desc_n = 0;
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- rndis->data_id = status;
+ if (rndis->notify_req) {
+ kfree(rndis->notify_req->buf);
+ usb_ep_free_request(rndis->notify, rndis->notify_req);
+ }
- rndis_data_intf.bInterfaceNumber = status;
- rndis_union_desc.bSlaveInterface0 = status;
+ ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
- status = -ENODEV;
+ return status;
+}
- /* allocate instance-specific endpoints */
- ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc);
- if (!ep)
- goto fail;
- rndis->port.in_ep = ep;
+static int rndis_prep_vendor_descs(struct usb_function *f)
+{
+ struct f_rndis *rndis = func_to_rndis(f);
+ struct f_rndis_opts *rndis_opts;
+ struct usb_composite_dev *cdev = f->config->cdev;
+ int status, intf0_id, intf1_id;
- ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc);
- if (!ep)
- goto fail;
- rndis->port.out_ep = ep;
+ rndis_opts = container_of(f->fi, struct f_rndis_opts, func_inst);
- /* NOTE: a status/notification endpoint is, strictly speaking,
- * optional. We don't treat it that way though! It's simpler,
- * and some newer profiles don't treat it as optional.
+ /*
+ * in drivers/usb/gadget/configfs.c:configfs_composite_bind()
+ * configurations are bound in sequence with list_for_each_entry,
+ * in each configuration its functions are bound in sequence
+ * with list_for_each_entry, so we assume no race condition
+ * with regard to rndis_opts->bound access
*/
- ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc);
- if (!ep)
- goto fail;
- rndis->notify = ep;
+ if (!rndis_opts->bound) {
+ gether_set_gadget(rndis_opts->net, cdev->gadget);
+ status = gether_register_netdev(rndis_opts->net);
+ if (status)
+ return status;
+ rndis_opts->bound = true;
+ }
- status = -ENOMEM;
+ intf0_id = usb_get_interface_id(f, 0);
+ intf1_id = usb_get_interface_id(f, 1);
- /* allocate notification request and buffer */
- rndis->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
- if (!rndis->notify_req)
- goto fail;
- rndis->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL);
- if (!rndis->notify_req->buf)
- goto fail;
- rndis->notify_req->length = STATUS_BYTECOUNT;
- rndis->notify_req->context = rndis;
- rndis->notify_req->complete = rndis_response_complete;
+ rndis->ctrl_id = intf0_id;
+ rndis->data_id = intf1_id;
- /* support all relevant hardware speeds... we expect that when
- * hardware is dual speed, all bulk-capable endpoints work at
- * both speeds
- */
- hs_in_desc.bEndpointAddress = fs_in_desc.bEndpointAddress;
- hs_out_desc.bEndpointAddress = fs_out_desc.bEndpointAddress;
- hs_notify_desc.bEndpointAddress = fs_notify_desc.bEndpointAddress;
+ rndis_iad_descriptor.bFirstInterface = intf0_id;
- ss_in_desc.bEndpointAddress = fs_in_desc.bEndpointAddress;
- ss_out_desc.bEndpointAddress = fs_out_desc.bEndpointAddress;
- ss_notify_desc.bEndpointAddress = fs_notify_desc.bEndpointAddress;
+ rndis_union_desc.bMasterInterface0 = intf0_id;
+ rndis_union_desc.bSlaveInterface0 = intf1_id;
- status = usb_assign_descriptors(f, eth_fs_function, eth_hs_function,
- eth_ss_function);
- if (status)
- goto fail;
+ if (cdev->use_os_string)
+ f->os_desc_table[0].if_id =
+ rndis_iad_descriptor.bFirstInterface;
+
+ usb_function_add_vendor_desc(f,
+ (struct usb_descriptor_header *)&rndis_iad_descriptor);
+
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&header_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&call_mgmt_descriptor);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&rndis_acm_descriptor);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&rndis_union_desc);
rndis->port.open = rndis_open;
rndis->port.close = rndis_close;
@@ -796,8 +725,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
if (rndis->manufacturer && rndis->vendorID &&
rndis_set_param_vendor(rndis->params, rndis->vendorID,
rndis->manufacturer)) {
- status = -EINVAL;
- goto fail_free_descs;
+ return -EINVAL;
}
/* NOTE: all that is done without knowing or caring about
@@ -805,27 +733,7 @@ rndis_bind(struct usb_configuration *c, struct usb_function *f)
* until we're activated via set_alt().
*/
- DBG(cdev, "RNDIS: %s speed IN/%s OUT/%s NOTIFY/%s\n",
- gadget_is_superspeed(c->cdev->gadget) ? "super" :
- gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
- rndis->port.in_ep->name, rndis->port.out_ep->name,
- rndis->notify->name);
return 0;
-
-fail_free_descs:
- usb_free_all_descriptors(f);
-fail:
- kfree(f->os_desc_table);
- f->os_desc_n = 0;
-
- if (rndis->notify_req) {
- kfree(rndis->notify_req->buf);
- usb_ep_free_request(rndis->notify, rndis->notify_req);
- }
-
- ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
-
- return status;
}
void rndis_borrow_net(struct usb_function_instance *f, struct net_device *net)
@@ -940,14 +848,8 @@ static void rndis_free(struct usb_function *f)
static void rndis_unbind(struct usb_configuration *c, struct usb_function *f)
{
- struct f_rndis *rndis = func_to_rndis(f);
-
kfree(f->os_desc_table);
f->os_desc_n = 0;
- usb_free_all_descriptors(f);
-
- kfree(rndis->notify_req->buf);
- usb_ep_free_request(rndis->notify, rndis->notify_req);
}
static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
@@ -981,11 +883,12 @@ static struct usb_function *rndis_alloc(struct usb_function_instance *fi)
rndis->port.func.name = "rndis";
/* descriptors are per-instance copies */
- rndis->port.func.bind = rndis_bind;
+ rndis->port.func.prep_descs = rndis_prep_descs;
+ rndis->port.func.prep_vendor_descs = rndis_prep_vendor_descs;
rndis->port.func.unbind = rndis_unbind;
rndis->port.func.set_alt = rndis_set_alt;
+ rndis->port.func.clear_alt = rndis_clear_alt;
rndis->port.func.setup = rndis_setup;
- rndis->port.func.disable = rndis_disable;
rndis->port.func.free_func = rndis_free;
params = rndis_register(rndis_response_available, rndis);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 18/43] usb: gadget: composite: usb_get_endpoint_address() function |
| Message-ID | <qY52G-212-17@gated-at.bofh.it> |
| In reply to | #1325342 |
Introduce function returning address of given endpoint within the function.
This value can be useful during preparation of class or vendor specific
descriptors in prep_vendor_descs() callback. It can be also necessary
to handle some class or vendor specific setup requests.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/composite.c | 20 ++++++++++++++++++++
include/linux/usb/composite.h | 2 ++
2 files changed, 22 insertions(+)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 7e3721d..417e2f9 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -688,6 +688,26 @@ int usb_get_interface_id(struct usb_function *f, int i)
}
EXPORT_SYMBOL_GPL(usb_get_interface_id);
+int usb_get_endpoint_address(struct usb_function *f, int i, int a, int e)
+{
+ struct usb_composite_ep *ep;
+
+ if (!f->descs)
+ return -ENODEV;
+ if (f->descs->intfs_num <= i)
+ return -ENODEV;
+ if (f->descs->intfs[i]->altsets_num <= a)
+ return -ENODEV;
+ if (f->descs->intfs[i]->altsets[a]->eps_num <= e)
+ return -ENODEV;
+ ep = f->descs->intfs[i]->altsets[a]->eps[e];
+ if (!ep->ep)
+ return -ENODEV;
+
+ return ep->ep->address;
+}
+EXPORT_SYMBOL_GPL(usb_get_endpoint_address);
+
/**
* usb_function_get_ep - obtains endpoint of given index from active
* altsetting of given interface
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index b2fb260..b6f1e0cc 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -427,6 +427,8 @@ int usb_ep_add_vendor_desc(struct usb_function *f, int i, int a, int e,
int usb_get_interface_id(struct usb_function *f, int i);
+int usb_get_endpoint_address(struct usb_function *f, int i, int a, int e);
+
struct usb_ep *usb_function_get_ep(struct usb_function *f, int intf, int ep);
int usb_interface_id(struct usb_configuration *, struct usb_function *);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 06/43] usb: gadget: composite: introduce new descriptors format |
| Message-ID | <qY52G-212-23@gated-at.bofh.it> |
| In reply to | #1325342 |
Introduce new structures designed to contain information about
descriptors. It splits descriptors in two categories:
1. Entity descs - interface and endpoint descriptors
2. Vendor descs - all other vendor and class specific descriptors
Entity descriptors are embedded in hierarchy of structures while vendor
descriptors are contained in linked lists. This distinction is caused
by fact, that entity descriptors are needed during gadget bind procedure,
while vendor descriptors can be supplied later, which is usually desired,
as these descriptors may need to be filled with interface numbers and
endpoint addresses which are assigned during gadget bind.
In result we can split descriptors creation process in two steps - first
collecs entity descriptors, perform the bind and then update and attach
all other descriptors. This process can be done this way not only for
each function separately, but also for entire gadget at once, which means
we can first gather descriptors from all functions in gadget, next perform
bind procedure, and then allow functions to supply additional descriptors.
It allows us to have autoconfig solver capable to better distibute ep
resources, and additionally, because we now store information about
endpoints, allows us to handle endpoint state inside composite framework,
and in result remove lots of boilerplate code from USB functions.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
include/linux/usb/composite.h | 126 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 126 insertions(+)
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 9911c29..8bb5c35 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -57,6 +57,128 @@
struct usb_configuration;
/**
+ * struct usb_composite_vendor_desc - vendor specific descriptor
+ * @desc: pointer to vendor specific descriptor
+ * @list: descriptor list element
+ *
+ * It's designed to be element of vendor specific descriptor list,
+ * which can be attached to function, interface (per altsetting) or
+ * endpoint.
+ */
+struct usb_composite_vendor_desc {
+ struct usb_descriptor_header *desc;
+ struct list_head list;
+};
+
+/**
+ * struct usb_composite_ep - representation of USB endpoint
+ * @fs.desc: FullSpeed descriptor
+ * @hs.desc: HighSpeed descriptor
+ * @ss.desc: SuperSpeed descriptor
+ * @ss_comp.desc: SuperSpeed Companion descriptor
+ * @vendor_descs: list of vendor specific descriptors
+ * @vendor_descs_num: count of vendor specific descriptors
+ * @ep: pointer to endpoint obtained during bind process
+ *
+ * We have pointer to each descriptor in union with pointer to descriptor
+ * header in order to avoid casting in many places in code, because in
+ * some situations we want to have access to fields of particular type
+ * of descriptor, while in other situations we want to treat all types
+ * of descriptors in the same way.
+ */
+struct usb_composite_ep {
+ union {
+ struct usb_descriptor_header *header;
+ struct usb_endpoint_descriptor *desc;
+ } fs;
+
+ union {
+ struct usb_descriptor_header *header;
+ struct usb_endpoint_descriptor *desc;
+ } hs;
+
+ union {
+ struct usb_descriptor_header *header;
+ struct usb_endpoint_descriptor *desc;
+ } ss;
+
+ union {
+ struct usb_descriptor_header *header;
+ struct usb_ss_ep_comp_descriptor *desc;
+ } ss_comp;
+
+ struct list_head vendor_descs;
+ int vendor_descs_num;
+
+ struct usb_ep *ep;
+};
+
+/**
+ * struct usb_composite_altset - representation of USB altsetting
+ * @alt.desc: interface (altsetting) descriptor
+ * @eps: array of endpoints in altsetting
+ * @eps_num: number of endpoints
+ * @vendor_descs: list of vendor specific descriptors
+ * @vendor_descs_num: count of vendor specific descriptors
+ *
+ * We have pointer to alt descriptor in union with pointer to descriptor
+ * header in order to avoid casting in many places in code, because in
+ * some situations we want to have access to fields of particular type
+ * of descriptor, while in other situations we want to treat all types
+ * of descriptors in the same way.
+ */
+struct usb_composite_altset {
+ union {
+ struct usb_descriptor_header *header;
+ struct usb_interface_descriptor *desc;
+ } alt;
+
+ struct usb_composite_ep **eps;
+ int eps_num;
+
+ struct list_head vendor_descs;
+ int vendor_descs_num;
+};
+
+/**
+ * struct usb_composite_intf - representation of USB interface
+ * @altsets: array of altsettings in interface
+ * @altsets_num: number of altsettings
+ * @cur_altset: number of currently selected altsetting
+ * @id: id number of interface in configuraion (value of
+ * bInterfaceNumber in interface descriptor)
+ */
+struct usb_composite_intf {
+ struct usb_composite_altset **altsets;
+ int altsets_num;
+
+ int cur_altset;
+ u8 id;
+};
+
+/**
+ * struct usb_composite_descs - representation of USB descriptors
+ * @intfs: array of interfaces in function
+ * @intfs_num: number of interfaces
+ * @vendor_descs: list of vendor specific descriptors
+ * @vendor_descs_num: count of vendor specific descriptors
+ * @fullspeed: descriptors support FullSpeed
+ * @highspeed: descriptors support HighSpeed
+ * @superspeed: descriptors support SuperSpeed
+ */
+struct usb_composite_descs {
+ struct usb_composite_intf **intfs;
+ int intfs_num;
+
+ struct list_head vendor_descs;
+ int vendor_descs_num;
+
+ unsigned fullspeed:1;
+ unsigned highspeed:1;
+ unsigned superspeed:1;
+};
+
+/**
* struct usb_os_desc_ext_prop - describes one "Extended Property"
* @entry: used to keep a list of extended properties
* @type: Extended Property type
@@ -126,6 +248,8 @@ struct usb_os_desc_table {
* string identifiers assigned during @bind(). If this
* pointer is null after initiation, the function will not
* be available at super speed.
+ * @descs: structure containing information about descriptors and endpoints
+ * assigned during gadget bind.
* @config: assigned when @usb_add_function() is called; this is the
* configuration with which this function is associated.
* @os_desc_table: Table of (interface id, os descriptors) pairs. The function
@@ -187,6 +311,8 @@ struct usb_function {
struct usb_descriptor_header **hs_descriptors;
struct usb_descriptor_header **ss_descriptors;
+ struct usb_composite_descs *descs;
+
struct usb_configuration *config;
struct usb_os_desc_table *os_desc_table;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | kbuild test robot <lkp@intel.com> |
|---|---|
| Date | 2016-02-04 06:20 +0100 |
| Subject | Re: [PATCH v4 06/43] usb: gadget: composite: introduce new descriptors format |
| Message-ID | <qYkuJ-4bg-1@gated-at.bofh.it> |
| In reply to | #1325347 |
[Multipart message — attachments visible in raw view] — view raw
Hi Robert,
[auto build test WARNING on usb/usb-testing]
[also build test WARNING on v4.5-rc2 next-20160203]
[if your patch is applied to the wrong git tree, please drop us a note to help improving the system]
url: https://github.com/0day-ci/linux/commits/Robert-Baldyga/usb-gadget-composite-introduce-new-function-API/20160203-205850
base: https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing
reproduce: make htmldocs
All warnings (new ones prefixed by >>):
include/linux/usb/gadget.h:227: warning: No description found for parameter 'claimed'
include/linux/usb/gadget.h:227: warning: No description found for parameter 'enabled'
include/linux/usb/gadget.h:652: warning: No description found for parameter 'quirk_altset_not_supp'
include/linux/usb/gadget.h:652: warning: No description found for parameter 'quirk_stall_not_supp'
include/linux/usb/gadget.h:652: warning: No description found for parameter 'quirk_zlp_not_supp'
>> include/linux/usb/composite.h:114: warning: No description found for parameter 'ss_comp'
>> include/linux/usb/composite.h:141: warning: No description found for parameter 'alt'
include/linux/usb/composite.h:628: warning: Excess struct/union/enum/typedef member 'setup_pending' description in 'usb_composite_dev'
include/linux/usb/composite.h:628: warning: Excess struct/union/enum/typedef member 'os_desc_pending' description in 'usb_composite_dev'
drivers/usb/gadget/function/f_acm.c:1: warning: no structured comments found
drivers/usb/gadget/function/f_ecm.c:1: warning: no structured comments found
drivers/usb/gadget/function/f_subset.c:1: warning: no structured comments found
drivers/usb/gadget/function/f_obex.c:1: warning: no structured comments found
drivers/usb/gadget/function/f_serial.c:1: warning: no structured comments found
vim +/ss_comp +114 include/linux/usb/composite.h
108 } ss_comp;
109
110 struct list_head vendor_descs;
111 int vendor_descs_num;
112
113 struct usb_ep *ep;
> 114 };
115
116 /**
117 * struct usb_composite_altset - representation of USB altsetting
118 * @alt.desc: interface (altsetting) descriptor
119 * @eps: array of endpoints in altsetting
120 * @eps_num: number of endpoints
121 * @vendor_descs: list of vendor specific descriptors
122 * @vendor_descs_num: count of vendor specific descriptors
123 *
124 * We have pointer to alt descriptor in union with pointer to descriptor
125 * header in order to avoid casting in many places in code, because in
126 * some situations we want to have access to fields of particular type
127 * of descriptor, while in other situations we want to treat all types
128 * of descriptors in the same way.
129 */
130 struct usb_composite_altset {
131 union {
132 struct usb_descriptor_header *header;
133 struct usb_interface_descriptor *desc;
134 } alt;
135
136 struct usb_composite_ep **eps;
137 int eps_num;
138
139 struct list_head vendor_descs;
140 int vendor_descs_num;
> 141 };
142
143 /**
144 * struct usb_composite_intf - representation of USB interface
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 15/43] usb: gadget: composite: handle get_alt() automatically |
| Message-ID | <qY52G-212-25@gated-at.bofh.it> |
| In reply to | #1325342 |
As now we store current altsetting number for each interface, we can
handle USB_REQ_GET_INTERFACE automatically.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/composite.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 1c26443..a4b5346 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -2077,7 +2077,13 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
if (!f)
break;
/* lots of interfaces only need altsetting zero... */
- value = f->get_alt ? f->get_alt(f, w_index) : 0;
+ if (usb_function_is_new_api(f)) {
+ value = usb_interface_id_to_index(f, intf);
+ if (value >= 0)
+ value = f->descs->intfs[value]->cur_altset;
+ } else {
+ value = f->get_alt ? f->get_alt(f, w_index) : 0;
+ }
if (value < 0)
break;
*((u8 *)req->buf) = value;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 04/43] usb: gadget: configfs: fix error path |
| Message-ID | <qY52H-212-27@gated-at.bofh.it> |
| In reply to | #1325342 |
As usb_gstrings_attach() failure can happen when some USB functions are
are already added to some configurations (in previous loop iterations),
we should always call purge_configs_funcs() to be sure that failure is
be handled properly.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/configfs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 590c449..fb3c9ba 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1345,7 +1345,7 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
s = usb_gstrings_attach(&gi->cdev, cfg->gstrings, 1);
if (IS_ERR(s)) {
ret = PTR_ERR(s);
- goto err_comp_cleanup;
+ goto err_purge_funcs;
}
c->iConfiguration = s[0].id;
}
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 37/43] usb: gadget: f_mass_storage: conversion to new API |
| Message-ID | <qY52H-212-29@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Change set_alt() implementation and implement clear_alt()
operation. Remove boilerplate code.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_mass_storage.c | 91 +++++++++-------------------
drivers/usb/gadget/function/storage_common.c | 29 ---------
drivers/usb/gadget/function/storage_common.h | 3 -
3 files changed, 29 insertions(+), 94 deletions(-)
diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 223ccf8..fa2326f 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -233,6 +233,17 @@ static const char fsg_string_interface[] = "Mass Storage";
#include "storage_common.h"
#include "f_mass_storage.h"
+USB_COMPOSITE_ENDPOINT(ep_in, &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
+ &fsg_ss_bulk_in_desc, &fsg_ss_bulk_in_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_out, &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
+ &fsg_ss_bulk_out_desc, &fsg_ss_bulk_out_comp_desc);
+
+USB_COMPOSITE_ALTSETTING(intf0alt0, &fsg_intf_desc, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+
+USB_COMPOSITE_DESCRIPTORS(fsg_descs, &intf0);
+
/* Static strings, in UTF-8 (for simplicity we use only ASCII characters) */
static struct usb_string fsg_strings[] = {
{FSG_STRING_INTERFACE, fsg_string_interface},
@@ -325,8 +336,6 @@ struct fsg_dev {
struct usb_gadget *gadget; /* Copy of cdev->gadget */
struct fsg_common *common;
- u16 interface_number;
-
unsigned int bulk_in_enabled:1;
unsigned int bulk_out_enabled:1;
@@ -522,7 +531,7 @@ static int fsg_setup(struct usb_function *f,
if (ctrl->bRequestType !=
(USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
break;
- if (w_index != fsg->interface_number || w_value != 0 ||
+ if (w_index != usb_get_interface_id(f, 0) || w_value != 0 ||
w_length != 0)
return -EDOM;
@@ -538,7 +547,7 @@ static int fsg_setup(struct usb_function *f,
if (ctrl->bRequestType !=
(USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE))
break;
- if (w_index != fsg->interface_number || w_value != 0 ||
+ if (w_index != usb_get_interface_id(f, 0) || w_value != 0 ||
w_length != 1)
return -EDOM;
VDBG(fsg, "get max LUN\n");
@@ -2328,19 +2337,27 @@ reset:
static int fsg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct fsg_dev *fsg = fsg_from_func(f);
+
+ fsg->bulk_in = usb_function_get_ep(f, intf, 0);
+ if (!fsg->bulk_in)
+ return -ENODEV;
+
+ fsg->bulk_out = usb_function_get_ep(f, intf, 1);
+ if (!fsg->bulk_out)
+ return -ENODEV;
+
fsg->common->new_fsg = fsg;
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
return USB_GADGET_DELAYED_STATUS;
}
-static void fsg_disable(struct usb_function *f)
+static void fsg_clear_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct fsg_dev *fsg = fsg_from_func(f);
fsg->common->new_fsg = NULL;
raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE);
}
-
/*-------------------------------------------------------------------------*/
static void handle_exception(struct fsg_common *common)
@@ -3025,13 +3042,11 @@ static void fsg_common_release(struct kref *ref)
/*-------------------------------------------------------------------------*/
-static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
+static int fsg_prep_descs(struct usb_function *f)
{
struct fsg_dev *fsg = fsg_from_func(f);
struct fsg_common *common = fsg->common;
- struct usb_gadget *gadget = c->cdev->gadget;
- int i;
- struct usb_ep *ep;
+ struct usb_gadget *gadget = f->config->cdev->gadget;
unsigned max_burst;
int ret;
struct fsg_opts *opts;
@@ -3045,7 +3060,7 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
opts = fsg_opts_from_func_inst(f->fi);
if (!opts->no_configfs) {
- ret = fsg_common_set_cdev(fsg->common, c->cdev,
+ ret = fsg_common_set_cdev(fsg->common, f->config->cdev,
fsg->common->can_stall);
if (ret)
return ret;
@@ -3057,58 +3072,12 @@ static int fsg_bind(struct usb_configuration *c, struct usb_function *f)
fsg->gadget = gadget;
- /* New interface */
- i = usb_interface_id(c, f);
- if (i < 0)
- goto fail;
- fsg_intf_desc.bInterfaceNumber = i;
- fsg->interface_number = i;
-
- /* Find all the endpoints we will use */
- ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
- if (!ep)
- goto autoconf_fail;
- fsg->bulk_in = ep;
-
- ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
- if (!ep)
- goto autoconf_fail;
- fsg->bulk_out = ep;
-
- /* Assume endpoint addresses are the same for both speeds */
- fsg_hs_bulk_in_desc.bEndpointAddress =
- fsg_fs_bulk_in_desc.bEndpointAddress;
- fsg_hs_bulk_out_desc.bEndpointAddress =
- fsg_fs_bulk_out_desc.bEndpointAddress;
-
/* Calculate bMaxBurst, we know packet size is 1024 */
max_burst = min_t(unsigned, FSG_BUFLEN / 1024, 15);
-
- fsg_ss_bulk_in_desc.bEndpointAddress =
- fsg_fs_bulk_in_desc.bEndpointAddress;
fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
-
- fsg_ss_bulk_out_desc.bEndpointAddress =
- fsg_fs_bulk_out_desc.bEndpointAddress;
fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
- ret = usb_assign_descriptors(f, fsg_fs_function, fsg_hs_function,
- fsg_ss_function);
- if (ret)
- goto autoconf_fail;
-
- return 0;
-
-autoconf_fail:
- ERROR(fsg, "unable to autoconfigure all endpoints\n");
- i = -ENOTSUPP;
-fail:
- /* terminate the thread */
- if (fsg->common->state != FSG_STATE_TERMINATED) {
- raise_exception(fsg->common, FSG_STATE_EXIT);
- wait_for_completion(&fsg->common->thread_notifier);
- }
- return i;
+ return usb_function_set_descs(f, &fsg_descs);
}
/****************************** ALLOCATE FUNCTION *************************/
@@ -3125,8 +3094,6 @@ static void fsg_unbind(struct usb_configuration *c, struct usb_function *f)
/* FIXME: make interruptible or killable somehow? */
wait_event(common->fsg_wait, common->fsg != fsg);
}
-
- usb_free_all_descriptors(&fsg->function);
}
static inline struct fsg_lun_opts *to_fsg_lun_opts(struct config_item *item)
@@ -3529,11 +3496,11 @@ static struct usb_function *fsg_alloc(struct usb_function_instance *fi)
mutex_unlock(&opts->lock);
fsg->function.name = FSG_DRIVER_DESC;
- fsg->function.bind = fsg_bind;
+ fsg->function.prep_descs = fsg_prep_descs;
fsg->function.unbind = fsg_unbind;
fsg->function.setup = fsg_setup;
fsg->function.set_alt = fsg_set_alt;
- fsg->function.disable = fsg_disable;
+ fsg->function.clear_alt = fsg_clear_alt;
fsg->function.free_func = fsg_free;
fsg->common = common;
diff --git a/drivers/usb/gadget/function/storage_common.c b/drivers/usb/gadget/function/storage_common.c
index d626830..94f23814 100644
--- a/drivers/usb/gadget/function/storage_common.c
+++ b/drivers/usb/gadget/function/storage_common.c
@@ -70,15 +70,6 @@ struct usb_endpoint_descriptor fsg_fs_bulk_out_desc = {
};
EXPORT_SYMBOL_GPL(fsg_fs_bulk_out_desc);
-struct usb_descriptor_header *fsg_fs_function[] = {
- (struct usb_descriptor_header *) &fsg_intf_desc,
- (struct usb_descriptor_header *) &fsg_fs_bulk_in_desc,
- (struct usb_descriptor_header *) &fsg_fs_bulk_out_desc,
- NULL,
-};
-EXPORT_SYMBOL_GPL(fsg_fs_function);
-
-
/*
* USB 2.0 devices need to expose both high speed and full speed
* descriptors, unless they only run at full speed.
@@ -108,15 +99,6 @@ struct usb_endpoint_descriptor fsg_hs_bulk_out_desc = {
};
EXPORT_SYMBOL_GPL(fsg_hs_bulk_out_desc);
-
-struct usb_descriptor_header *fsg_hs_function[] = {
- (struct usb_descriptor_header *) &fsg_intf_desc,
- (struct usb_descriptor_header *) &fsg_hs_bulk_in_desc,
- (struct usb_descriptor_header *) &fsg_hs_bulk_out_desc,
- NULL,
-};
-EXPORT_SYMBOL_GPL(fsg_hs_function);
-
struct usb_endpoint_descriptor fsg_ss_bulk_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
@@ -153,17 +135,6 @@ struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc = {
};
EXPORT_SYMBOL_GPL(fsg_ss_bulk_out_comp_desc);
-struct usb_descriptor_header *fsg_ss_function[] = {
- (struct usb_descriptor_header *) &fsg_intf_desc,
- (struct usb_descriptor_header *) &fsg_ss_bulk_in_desc,
- (struct usb_descriptor_header *) &fsg_ss_bulk_in_comp_desc,
- (struct usb_descriptor_header *) &fsg_ss_bulk_out_desc,
- (struct usb_descriptor_header *) &fsg_ss_bulk_out_comp_desc,
- NULL,
-};
-EXPORT_SYMBOL_GPL(fsg_ss_function);
-
-
/*-------------------------------------------------------------------------*/
/*
diff --git a/drivers/usb/gadget/function/storage_common.h b/drivers/usb/gadget/function/storage_common.h
index c3544e6..f5d9146 100644
--- a/drivers/usb/gadget/function/storage_common.h
+++ b/drivers/usb/gadget/function/storage_common.h
@@ -190,17 +190,14 @@ extern struct usb_interface_descriptor fsg_intf_desc;
extern struct usb_endpoint_descriptor fsg_fs_bulk_in_desc;
extern struct usb_endpoint_descriptor fsg_fs_bulk_out_desc;
-extern struct usb_descriptor_header *fsg_fs_function[];
extern struct usb_endpoint_descriptor fsg_hs_bulk_in_desc;
extern struct usb_endpoint_descriptor fsg_hs_bulk_out_desc;
-extern struct usb_descriptor_header *fsg_hs_function[];
extern struct usb_endpoint_descriptor fsg_ss_bulk_in_desc;
extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_in_comp_desc;
extern struct usb_endpoint_descriptor fsg_ss_bulk_out_desc;
extern struct usb_ss_ep_comp_descriptor fsg_ss_bulk_out_comp_desc;
-extern struct usb_descriptor_header *fsg_ss_function[];
void fsg_lun_close(struct fsg_lun *curlun);
int fsg_lun_open(struct fsg_lun *curlun, const char *filename);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 23/43] usb: gadget: f_ecm: conversion to new API |
| Message-ID | <qY52H-212-33@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Implement prep_vendor_descs() to supply class specific
descriptors. Change set_alt() implementation and implement clear_alt()
operation. Get rid of get_alt() which now is handled automatically.
Remove boilerplate code. Change USB request lifetime management - now
it's allocated in set_alt() and freed in clear_alt().
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_ecm.c | 321 +++++++++++-------------------------
1 file changed, 92 insertions(+), 229 deletions(-)
diff --git a/drivers/usb/gadget/function/f_ecm.c b/drivers/usb/gadget/function/f_ecm.c
index 7ad60ee..4627f20 100644
--- a/drivers/usb/gadget/function/f_ecm.c
+++ b/drivers/usb/gadget/function/f_ecm.c
@@ -214,25 +214,6 @@ static struct usb_endpoint_descriptor fs_ecm_out_desc = {
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
-static struct usb_descriptor_header *ecm_fs_function[] = {
- /* CDC ECM control descriptors */
- (struct usb_descriptor_header *) &ecm_iad_descriptor,
- (struct usb_descriptor_header *) &ecm_control_intf,
- (struct usb_descriptor_header *) &ecm_header_desc,
- (struct usb_descriptor_header *) &ecm_union_desc,
- (struct usb_descriptor_header *) &ecm_desc,
-
- /* NOTE: status endpoint might need to be removed */
- (struct usb_descriptor_header *) &fs_ecm_notify_desc,
-
- /* data interface, altsettings 0 and 1 */
- (struct usb_descriptor_header *) &ecm_data_nop_intf,
- (struct usb_descriptor_header *) &ecm_data_intf,
- (struct usb_descriptor_header *) &fs_ecm_in_desc,
- (struct usb_descriptor_header *) &fs_ecm_out_desc,
- NULL,
-};
-
/* high speed support: */
static struct usb_endpoint_descriptor hs_ecm_notify_desc = {
@@ -263,25 +244,6 @@ static struct usb_endpoint_descriptor hs_ecm_out_desc = {
.wMaxPacketSize = cpu_to_le16(512),
};
-static struct usb_descriptor_header *ecm_hs_function[] = {
- /* CDC ECM control descriptors */
- (struct usb_descriptor_header *) &ecm_iad_descriptor,
- (struct usb_descriptor_header *) &ecm_control_intf,
- (struct usb_descriptor_header *) &ecm_header_desc,
- (struct usb_descriptor_header *) &ecm_union_desc,
- (struct usb_descriptor_header *) &ecm_desc,
-
- /* NOTE: status endpoint might need to be removed */
- (struct usb_descriptor_header *) &hs_ecm_notify_desc,
-
- /* data interface, altsettings 0 and 1 */
- (struct usb_descriptor_header *) &ecm_data_nop_intf,
- (struct usb_descriptor_header *) &ecm_data_intf,
- (struct usb_descriptor_header *) &hs_ecm_in_desc,
- (struct usb_descriptor_header *) &hs_ecm_out_desc,
- NULL,
-};
-
/* super speed support: */
static struct usb_endpoint_descriptor ss_ecm_notify_desc = {
@@ -331,27 +293,21 @@ static struct usb_ss_ep_comp_descriptor ss_ecm_bulk_comp_desc = {
/* .bmAttributes = 0, */
};
-static struct usb_descriptor_header *ecm_ss_function[] = {
- /* CDC ECM control descriptors */
- (struct usb_descriptor_header *) &ecm_iad_descriptor,
- (struct usb_descriptor_header *) &ecm_control_intf,
- (struct usb_descriptor_header *) &ecm_header_desc,
- (struct usb_descriptor_header *) &ecm_union_desc,
- (struct usb_descriptor_header *) &ecm_desc,
-
- /* NOTE: status endpoint might need to be removed */
- (struct usb_descriptor_header *) &ss_ecm_notify_desc,
- (struct usb_descriptor_header *) &ss_ecm_intr_comp_desc,
-
- /* data interface, altsettings 0 and 1 */
- (struct usb_descriptor_header *) &ecm_data_nop_intf,
- (struct usb_descriptor_header *) &ecm_data_intf,
- (struct usb_descriptor_header *) &ss_ecm_in_desc,
- (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc,
- (struct usb_descriptor_header *) &ss_ecm_out_desc,
- (struct usb_descriptor_header *) &ss_ecm_bulk_comp_desc,
- NULL,
-};
+USB_COMPOSITE_ENDPOINT(ep_notify, &fs_ecm_notify_desc, &hs_ecm_notify_desc,
+ &ss_ecm_notify_desc, &ss_ecm_intr_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_in, &fs_ecm_in_desc, &hs_ecm_in_desc,
+ &ss_ecm_in_desc, &ss_ecm_bulk_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_out, &fs_ecm_out_desc, &hs_ecm_out_desc,
+ &ss_ecm_out_desc, &ss_ecm_bulk_comp_desc);
+
+USB_COMPOSITE_ALTSETTING(intf0alt0, &ecm_control_intf, &ep_notify);
+USB_COMPOSITE_ALTSETTING(intf1alt0, &ecm_data_nop_intf);
+USB_COMPOSITE_ALTSETTING(intf1alt1, &ecm_data_intf, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+USB_COMPOSITE_INTERFACE(intf1, &intf1alt0, &intf1alt1);
+
+USB_COMPOSITE_DESCRIPTORS(ecm_descs, &intf0, &intf1);
/* string descriptors: */
@@ -537,47 +493,43 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
struct usb_composite_dev *cdev = f->config->cdev;
/* Control interface has only altsetting 0 */
- if (intf == ecm->ctrl_id) {
- if (alt != 0)
- goto fail;
+ if (intf == 0) {
+ /* NOTE: a status/notification endpoint is *OPTIONAL* but we
+ * don't treat it that way. It's simpler, and some newer CDC
+ * profiles (wireless handsets) no longer treat it as optional.
+ */
VDBG(cdev, "reset ecm control %d\n", intf);
- usb_ep_disable(ecm->notify);
- if (!(ecm->notify->desc)) {
- VDBG(cdev, "init ecm ctrl %d\n", intf);
- if (config_ep_by_speed(cdev->gadget, f, ecm->notify))
- goto fail;
- }
- usb_ep_enable(ecm->notify);
-
- /* Data interface has two altsettings, 0 and 1 */
- } else if (intf == ecm->data_id) {
- if (alt > 1)
- goto fail;
- if (ecm->port.in_ep->enabled) {
- DBG(cdev, "reset ecm\n");
- gether_disconnect(&ecm->port);
+ ecm->notify = usb_function_get_ep(f, intf, 0);
+ if (!ecm->notify)
+ return -ENODEV;
+
+ /* allocate notification request and buffer */
+ ecm->notify_req = usb_ep_alloc_request(ecm->notify, GFP_KERNEL);
+ if (!ecm->notify_req)
+ return -ENOMEM;
+ ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT,
+ GFP_KERNEL);
+ if (!ecm->notify_req->buf) {
+ usb_ep_free_request(ecm->notify, ecm->notify_req);
+ return -ENOMEM;
}
-
- if (!ecm->port.in_ep->desc ||
- !ecm->port.out_ep->desc) {
- DBG(cdev, "init ecm\n");
- if (config_ep_by_speed(cdev->gadget, f,
- ecm->port.in_ep) ||
- config_ep_by_speed(cdev->gadget, f,
- ecm->port.out_ep)) {
- ecm->port.in_ep->desc = NULL;
- ecm->port.out_ep->desc = NULL;
- goto fail;
- }
- }
-
+ ecm->notify_req->context = ecm;
+ ecm->notify_req->complete = ecm_notify_complete;
+ /* Data interface has two altsettings, 0 and 1 */
+ } else if (intf == 1) {
/* CDC Ethernet only sends data in non-default altsettings.
* Changing altsettings resets filters, statistics, etc.
*/
if (alt == 1) {
struct net_device *net;
+ ecm->port.in_ep = usb_function_get_ep(f, intf, 0);
+ if (!ecm->port.in_ep)
+ return -ENODEV;
+ ecm->port.out_ep = usb_function_get_ep(f, intf, 1);
+ if (!ecm->port.out_ep)
+ return -ENODEV;
/* Enable zlps by default for ECM conformance;
* override for musb_hdrc (avoids txdma ovhead).
@@ -598,38 +550,24 @@ static int ecm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
* just guarantee that a speed notification is always sent.
*/
ecm_notify(ecm);
- } else
- goto fail;
+ }
return 0;
-fail:
- return -EINVAL;
}
-/* Because the data interface supports multiple altsettings,
- * this ECM function *MUST* implement a get_alt() method.
- */
-static int ecm_get_alt(struct usb_function *f, unsigned intf)
+static void ecm_clear_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
- struct f_ecm *ecm = func_to_ecm(f);
-
- if (intf == ecm->ctrl_id)
- return 0;
- return ecm->port.in_ep->enabled ? 1 : 0;
-}
-
-static void ecm_disable(struct usb_function *f)
-{
- struct f_ecm *ecm = func_to_ecm(f);
+ struct f_ecm *ecm = func_to_ecm(f);
struct usb_composite_dev *cdev = f->config->cdev;
DBG(cdev, "ecm deactivated\n");
- if (ecm->port.in_ep->enabled)
+ if (intf == 0) {
+ kfree(ecm->notify_req->buf);
+ usb_ep_free_request(ecm->notify, ecm->notify_req);
+ } else if (intf == 1 && alt == 1) {
gether_disconnect(&ecm->port);
-
- usb_ep_disable(ecm->notify);
- ecm->notify->desc = NULL;
+ }
}
/*-------------------------------------------------------------------------*/
@@ -676,20 +614,33 @@ static void ecm_close(struct gether *geth)
/* ethernet function driver setup/binding */
-static int
-ecm_bind(struct usb_configuration *c, struct usb_function *f)
+static int ecm_prep_descs(struct usb_function *f)
{
- struct usb_composite_dev *cdev = c->cdev;
- struct f_ecm *ecm = func_to_ecm(f);
+ struct usb_composite_dev *cdev = f->config->cdev;
struct usb_string *us;
- int status;
- struct usb_ep *ep;
-
- struct f_ecm_opts *ecm_opts;
if (!can_support_ecm(cdev->gadget))
return -EINVAL;
+ us = usb_gstrings_attach(cdev, ecm_strings,
+ ARRAY_SIZE(ecm_string_defs));
+ if (IS_ERR(us))
+ return PTR_ERR(us);
+ ecm_control_intf.iInterface = us[0].id;
+ ecm_data_intf.iInterface = us[2].id;
+ ecm_desc.iMACAddress = us[1].id;
+ ecm_iad_descriptor.iFunction = us[3].id;
+
+ return usb_function_set_descs(f, &ecm_descs);
+}
+
+static int ecm_prep_vendor_descs(struct usb_function *f)
+{
+ struct f_ecm *ecm = func_to_ecm(f);
+ struct f_ecm_opts *ecm_opts;
+ struct usb_composite_dev *cdev = f->config->cdev;
+ int status, intf0_id, intf1_id;
+
ecm_opts = container_of(f->fi, struct f_ecm_opts, func_inst);
/*
@@ -709,86 +660,26 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
ecm_opts->bound = true;
}
- us = usb_gstrings_attach(cdev, ecm_strings,
- ARRAY_SIZE(ecm_string_defs));
- if (IS_ERR(us))
- return PTR_ERR(us);
- ecm_control_intf.iInterface = us[0].id;
- ecm_data_intf.iInterface = us[2].id;
- ecm_desc.iMACAddress = us[1].id;
- ecm_iad_descriptor.iFunction = us[3].id;
+ intf0_id = usb_get_interface_id(f, 0);
+ intf1_id = usb_get_interface_id(f, 1);
- /* allocate instance-specific interface IDs */
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- ecm->ctrl_id = status;
- ecm_iad_descriptor.bFirstInterface = status;
-
- ecm_control_intf.bInterfaceNumber = status;
- ecm_union_desc.bMasterInterface0 = status;
-
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- ecm->data_id = status;
-
- ecm_data_nop_intf.bInterfaceNumber = status;
- ecm_data_intf.bInterfaceNumber = status;
- ecm_union_desc.bSlaveInterface0 = status;
-
- status = -ENODEV;
-
- /* allocate instance-specific endpoints */
- ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc);
- if (!ep)
- goto fail;
- ecm->port.in_ep = ep;
-
- ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc);
- if (!ep)
- goto fail;
- ecm->port.out_ep = ep;
-
- /* NOTE: a status/notification endpoint is *OPTIONAL* but we
- * don't treat it that way. It's simpler, and some newer CDC
- * profiles (wireless handsets) no longer treat it as optional.
- */
- ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc);
- if (!ep)
- goto fail;
- ecm->notify = ep;
-
- status = -ENOMEM;
-
- /* allocate notification request and buffer */
- ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
- if (!ecm->notify_req)
- goto fail;
- ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL);
- if (!ecm->notify_req->buf)
- goto fail;
- ecm->notify_req->context = ecm;
- ecm->notify_req->complete = ecm_notify_complete;
-
- /* support all relevant hardware speeds... we expect that when
- * hardware is dual speed, all bulk-capable endpoints work at
- * both speeds
- */
- hs_ecm_in_desc.bEndpointAddress = fs_ecm_in_desc.bEndpointAddress;
- hs_ecm_out_desc.bEndpointAddress = fs_ecm_out_desc.bEndpointAddress;
- hs_ecm_notify_desc.bEndpointAddress =
- fs_ecm_notify_desc.bEndpointAddress;
+ ecm->ctrl_id = intf0_id;
+ ecm->data_id = intf1_id;
+
+ ecm_iad_descriptor.bFirstInterface = intf0_id;
+
+ ecm_union_desc.bMasterInterface0 = intf0_id;
+ ecm_union_desc.bSlaveInterface0 = intf1_id;
- ss_ecm_in_desc.bEndpointAddress = fs_ecm_in_desc.bEndpointAddress;
- ss_ecm_out_desc.bEndpointAddress = fs_ecm_out_desc.bEndpointAddress;
- ss_ecm_notify_desc.bEndpointAddress =
- fs_ecm_notify_desc.bEndpointAddress;
+ usb_function_add_vendor_desc(f,
+ (struct usb_descriptor_header *)&ecm_iad_descriptor);
- status = usb_assign_descriptors(f, ecm_fs_function, ecm_hs_function,
- ecm_ss_function);
- if (status)
- goto fail;
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&ecm_header_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&ecm_union_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&ecm_desc);
/* NOTE: all that is done without knowing or caring about
* the network link ... which is unavailable to this code
@@ -798,22 +689,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
ecm->port.open = ecm_open;
ecm->port.close = ecm_close;
- DBG(cdev, "CDC Ethernet: %s speed IN/%s OUT/%s NOTIFY/%s\n",
- gadget_is_superspeed(c->cdev->gadget) ? "super" :
- gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
- ecm->port.in_ep->name, ecm->port.out_ep->name,
- ecm->notify->name);
return 0;
-
-fail:
- if (ecm->notify_req) {
- kfree(ecm->notify_req->buf);
- usb_ep_free_request(ecm->notify, ecm->notify_req);
- }
-
- ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
-
- return status;
}
static inline struct f_ecm_opts *to_f_ecm_opts(struct config_item *item)
@@ -897,18 +773,6 @@ static void ecm_free(struct usb_function *f)
mutex_unlock(&opts->lock);
}
-static void ecm_unbind(struct usb_configuration *c, struct usb_function *f)
-{
- struct f_ecm *ecm = func_to_ecm(f);
-
- DBG(c->cdev, "ecm unbind\n");
-
- usb_free_all_descriptors(f);
-
- kfree(ecm->notify_req->buf);
- usb_ep_free_request(ecm->notify, ecm->notify_req);
-}
-
static struct usb_function *ecm_alloc(struct usb_function_instance *fi)
{
struct f_ecm *ecm;
@@ -940,12 +804,11 @@ static struct usb_function *ecm_alloc(struct usb_function_instance *fi)
ecm->port.func.name = "cdc_ethernet";
/* descriptors are per-instance copies */
- ecm->port.func.bind = ecm_bind;
- ecm->port.func.unbind = ecm_unbind;
+ ecm->port.func.prep_descs = ecm_prep_descs;
+ ecm->port.func.prep_vendor_descs = ecm_prep_vendor_descs;
ecm->port.func.set_alt = ecm_set_alt;
- ecm->port.func.get_alt = ecm_get_alt;
+ ecm->port.func.clear_alt = ecm_clear_alt;
ecm->port.func.setup = ecm_setup;
- ecm->port.func.disable = ecm_disable;
ecm->port.func.free_func = ecm_free;
return &ecm->port.func;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 02/43] usb: gadget: f_sourcesink: free requests in sourcesink_disable() |
| Message-ID | <qY52H-212-35@gated-at.bofh.it> |
| In reply to | #1325342 |
USB requests in SourceSink function are allocated in sourcesink_get_alt()
function, so we prefer to free them rather in sourcesink_disable() than
in source_sink_complete() when request is completed with error. It provides
better symetry in resource management and improves code readability.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_sourcesink.c | 63 ++++++++++++++++++++++++------
1 file changed, 51 insertions(+), 12 deletions(-)
diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
index e950031..6193b47 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -44,6 +44,11 @@ struct f_sourcesink {
struct usb_ep *iso_out_ep;
int cur_alt;
+ struct usb_request **in_reqs;
+ struct usb_request **out_reqs;
+ struct usb_request **iso_in_reqs;
+ struct usb_request **iso_out_reqs;
+
unsigned pattern;
unsigned isoc_interval;
unsigned isoc_maxpacket;
@@ -550,7 +555,6 @@ static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
req->actual, req->length);
if (ep == ss->out_ep)
check_read_data(ss, req);
- free_ep_req(ep, req);
return;
case -EOVERFLOW: /* buffer overrun on read means that
@@ -579,7 +583,7 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
bool is_iso, int speed)
{
struct usb_ep *ep;
- struct usb_request *req;
+ struct usb_request **reqs;
int i, size, qlen, status = 0;
if (is_iso) {
@@ -604,19 +608,23 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
qlen = ss->bulk_qlen;
size = 0;
}
-
+
+ reqs = kzalloc(qlen * sizeof(*reqs), GFP_ATOMIC);
+
for (i = 0; i < qlen; i++) {
- req = ss_alloc_ep_req(ep, size);
- if (!req)
- return -ENOMEM;
+ reqs[i] = ss_alloc_ep_req(ep, size);
+ if (!reqs[i]) {
+ status = -ENOMEM;
+ goto err;
+ }
- req->complete = source_sink_complete;
+ reqs[i]->complete = source_sink_complete;
if (is_in)
- reinit_write_data(ep, req);
+ reinit_write_data(ep, reqs[i]);
else if (ss->pattern != 2)
- memset(req->buf, 0x55, req->length);
+ memset(reqs[i]->buf, 0x55, reqs[i]->length);
- status = usb_ep_queue(ep, req, GFP_ATOMIC);
+ status = usb_ep_queue(ep, reqs[i], GFP_ATOMIC);
if (status) {
struct usb_composite_dev *cdev;
@@ -624,12 +632,30 @@ static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
ERROR(cdev, "start %s%s %s --> %d\n",
is_iso ? "ISO-" : "", is_in ? "IN" : "OUT",
ep->name, status);
- free_ep_req(ep, req);
- return status;
+ free_ep_req(ep, reqs[i]);
+ goto err;
+ }
+
+ if (is_iso) {
+ if (is_in)
+ ss->iso_in_reqs = reqs;
+ else
+ ss->iso_out_reqs = reqs;
+ } else {
+ if (is_in)
+ ss->in_reqs = reqs;
+ else
+ ss->out_reqs = reqs;
}
}
return status;
+
+err:
+ while (--i)
+ free_ep_req(ep, reqs[i]);
+ kfree(reqs);
+ return status;
}
static void disable_source_sink(struct f_sourcesink *ss)
@@ -754,8 +780,21 @@ static int sourcesink_get_alt(struct usb_function *f, unsigned intf)
static void sourcesink_disable(struct usb_function *f)
{
struct f_sourcesink *ss = func_to_ss(f);
+ int i;
disable_source_sink(ss);
+
+ for (i = 0; i < ss->bulk_qlen; ++i) {
+ free_ep_req(ss->in_ep, ss->in_reqs[i]);
+ free_ep_req(ss->out_ep, ss->out_reqs[i]);
+ }
+
+ if (ss->iso_in_ep) {
+ for (i = 0; i < ss->iso_qlen; ++i) {
+ free_ep_req(ss->iso_in_ep, ss->iso_in_reqs[i]);
+ free_ep_req(ss->iso_out_ep, ss->iso_out_reqs[i]);
+ }
+ }
}
/*-------------------------------------------------------------------------*/
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 13/43] usb: gadget: composite: enable eps before calling set_alt() callback |
| Message-ID | <qY52H-212-39@gated-at.bofh.it> |
| In reply to | #1325342 |
Change set_alt() behavior for functions using new API. Before we call
set_alt() callback, we disable endpoints of previously selected altsetting,
and enable endpoints of currently selected altsetting, which reduces
amount of boilerplate code in USB functions.
We also calculate index of interface in function and pass it to set_alt()
callback instead of passing index of interface in configuration which has
to be obtained from interface descriptor. This simplifies altsetting
changes handling in code of USB functions.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/composite.c | 83 +++++++++++++++++++++++++++++++++++++++++-
1 file changed, 81 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index f2c08b3..0c962d4 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -650,6 +650,26 @@ static void usb_function_free_vendor_descs(struct usb_function *f)
}
/**
+ * usb_interface_id_to_index - if interface with a specified id belongs
+ * to given USB function, return its index within descriptors array
+ * of this function
+ * @f: USB function
+ * @id: id number of interface
+ *
+ * Returns interface index on success, else negative errno.
+ */
+static int usb_interface_id_to_index(struct usb_function *f, u8 id)
+{
+ int i;
+
+ for (i = 0; i < f->descs->intfs_num; ++i)
+ if (f->descs->intfs[i]->id == id)
+ return i;
+
+ return -EINVAL;
+}
+
+/**
* usb_interface_id() - allocate an unused interface ID
* @config: configuration associated with the interface
* @function: function handling the interface
@@ -995,6 +1015,65 @@ static void reset_config(struct usb_composite_dev *cdev)
cdev->delayed_status = 0;
}
+/**
+ * set_alt() - select specified altsetting in given interface
+ * @f: USB function
+ * @i: interface id number
+ * @a: altsetting number
+ *
+ * This function has different behavior depending on which API is used by
+ * given USB function. For functions using old API behavior stays unchanged,
+ * while for functions using new API index of interface in function is
+ * calculated and endpoints are configured and enabled before calling
+ * set_alt() callback.
+ */
+static int set_alt(struct usb_function *f, unsigned i, unsigned a)
+{
+ struct usb_composite_dev *cdev = f->config->cdev;
+ struct usb_composite_altset *alt;
+ struct usb_composite_ep *ep;
+ int e, ret = -EINVAL;
+
+ /* To be removed after switch to new API */
+ if (!usb_function_is_new_api(f))
+ return f->set_alt(f, i, a);
+
+ i = usb_interface_id_to_index(f, i);
+ if (i < 0)
+ return i;
+
+ disable_interface(f, i);
+
+ if (a >= f->descs->intfs[i]->altsets_num)
+ return -EINVAL;
+
+ alt = f->descs->intfs[i]->altsets[a];
+ for (e = 0; e < alt->eps_num; ++e) {
+ ep = alt->eps[e];
+ ret = config_ep_by_speed(cdev->gadget, f, ep->ep);
+ if (ret)
+ goto err;
+ ret = usb_ep_enable(ep->ep);
+ if (ret)
+ goto err;
+ }
+
+ f->descs->intfs[i]->cur_altset = a;
+ ret = f->set_alt(f, i, a);
+ if (ret == USB_GADGET_DELAYED_STATUS)
+ goto out;
+ if (ret < 0)
+ goto err;
+
+ return 0;
+err:
+ for (e = 0; e < alt->eps_num; ++e)
+ usb_ep_disable(alt->eps[e]->ep);
+ f->descs->intfs[i]->cur_altset = -1;
+out:
+ return ret;
+}
+
static int set_config(struct usb_composite_dev *cdev,
const struct usb_ctrlrequest *ctrl, unsigned number)
{
@@ -1074,7 +1153,7 @@ static int set_config(struct usb_composite_dev *cdev,
set_bit(addr, f->endpoints);
}
- result = f->set_alt(f, tmp, 0);
+ result = set_alt(f, tmp, 0);
if (result < 0) {
DBG(cdev, "interface %d (%s/%p) alt 0 --> %d\n",
tmp, f->name, f, result);
@@ -1975,7 +2054,7 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
break;
if (w_value && !f->set_alt)
break;
- value = f->set_alt(f, w_index, w_value);
+ value = set_alt(f, w_index, w_value);
if (value == USB_GADGET_DELAYED_STATUS) {
DBG(cdev,
"%s: interface %d (%s) requested delayed status\n",
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 32/43] usb: gadget: f_obex: conversion to new API |
| Message-ID | <qY52H-212-41@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Implement prep_vendor_descs() to supply class specific
descriptors. Change set_alt() implementation and implement clear_alt()
operation. Remove boilerplate code.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_obex.c | 188 ++++++++++-------------------------
1 file changed, 50 insertions(+), 138 deletions(-)
diff --git a/drivers/usb/gadget/function/f_obex.c b/drivers/usb/gadget/function/f_obex.c
index d6396e0..0c4b1fd 100644
--- a/drivers/usb/gadget/function/f_obex.c
+++ b/drivers/usb/gadget/function/f_obex.c
@@ -34,7 +34,6 @@ struct f_obex {
struct gserial port;
u8 ctrl_id;
u8 data_id;
- u8 cur_alt;
u8 port_num;
};
@@ -144,19 +143,6 @@ static struct usb_endpoint_descriptor obex_hs_ep_in_desc = {
.wMaxPacketSize = cpu_to_le16(512),
};
-static struct usb_descriptor_header *hs_function[] = {
- (struct usb_descriptor_header *) &obex_control_intf,
- (struct usb_descriptor_header *) &obex_cdc_header_desc,
- (struct usb_descriptor_header *) &obex_desc,
- (struct usb_descriptor_header *) &obex_cdc_union_desc,
-
- (struct usb_descriptor_header *) &obex_data_nop_intf,
- (struct usb_descriptor_header *) &obex_data_intf,
- (struct usb_descriptor_header *) &obex_hs_ep_in_desc,
- (struct usb_descriptor_header *) &obex_hs_ep_out_desc,
- NULL,
-};
-
/* Full-Speed Support */
static struct usb_endpoint_descriptor obex_fs_ep_in_desc = {
@@ -175,18 +161,19 @@ static struct usb_endpoint_descriptor obex_fs_ep_out_desc = {
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
-static struct usb_descriptor_header *fs_function[] = {
- (struct usb_descriptor_header *) &obex_control_intf,
- (struct usb_descriptor_header *) &obex_cdc_header_desc,
- (struct usb_descriptor_header *) &obex_desc,
- (struct usb_descriptor_header *) &obex_cdc_union_desc,
+USB_COMPOSITE_ENDPOINT(ep_in, &obex_fs_ep_in_desc,
+ &obex_hs_ep_in_desc, NULL, NULL);
+USB_COMPOSITE_ENDPOINT(ep_out, &obex_fs_ep_out_desc,
+ &obex_hs_ep_out_desc, NULL, NULL);
- (struct usb_descriptor_header *) &obex_data_nop_intf,
- (struct usb_descriptor_header *) &obex_data_intf,
- (struct usb_descriptor_header *) &obex_fs_ep_in_desc,
- (struct usb_descriptor_header *) &obex_fs_ep_out_desc,
- NULL,
-};
+USB_COMPOSITE_ALTSETTING(intf0alt0, &obex_control_intf);
+USB_COMPOSITE_ALTSETTING(intf1alt0, &obex_data_nop_intf);
+USB_COMPOSITE_ALTSETTING(intf1alt1, &obex_data_intf, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+USB_COMPOSITE_INTERFACE(intf1, &intf1alt0, &intf1alt1);
+
+USB_COMPOSITE_DESCRIPTORS(obex_descs, &intf0, &intf1);
/*-------------------------------------------------------------------------*/
@@ -195,67 +182,33 @@ static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
struct f_obex *obex = func_to_obex(f);
struct usb_composite_dev *cdev = f->config->cdev;
- if (intf == obex->ctrl_id) {
- if (alt != 0)
- goto fail;
+ if (intf == 0) {
/* NOP */
dev_dbg(&cdev->gadget->dev,
"reset obex ttyGS%d control\n", obex->port_num);
-
- } else if (intf == obex->data_id) {
- if (alt > 1)
- goto fail;
-
- if (obex->port.in->enabled) {
- dev_dbg(&cdev->gadget->dev,
- "reset obex ttyGS%d\n", obex->port_num);
- gserial_disconnect(&obex->port);
- }
-
- if (!obex->port.in->desc || !obex->port.out->desc) {
- dev_dbg(&cdev->gadget->dev,
- "init obex ttyGS%d\n", obex->port_num);
- if (config_ep_by_speed(cdev->gadget, f,
- obex->port.in) ||
- config_ep_by_speed(cdev->gadget, f,
- obex->port.out)) {
- obex->port.out->desc = NULL;
- obex->port.in->desc = NULL;
- goto fail;
- }
- }
-
- if (alt == 1) {
- dev_dbg(&cdev->gadget->dev,
+ } else if (intf == 1 && alt == 1) {
+ dev_dbg(&cdev->gadget->dev,
"activate obex ttyGS%d\n", obex->port_num);
- gserial_connect(&obex->port, obex->port_num);
- }
- } else
- goto fail;
+ obex->port.in = usb_function_get_ep(f, intf, 0);
+ if (!obex->port.in)
+ return -ENODEV;
+ obex->port.out = usb_function_get_ep(f, intf, 1);
+ if (!obex->port.out)
+ return -ENODEV;
- obex->cur_alt = alt;
+ gserial_connect(&obex->port, obex->port_num);
+ }
return 0;
-
-fail:
- return -EINVAL;
}
-static int obex_get_alt(struct usb_function *f, unsigned intf)
+static void obex_clear_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct f_obex *obex = func_to_obex(f);
- return obex->cur_alt;
-}
-
-static void obex_disable(struct usb_function *f)
-{
- struct f_obex *obex = func_to_obex(f);
- struct usb_composite_dev *cdev = f->config->cdev;
-
- dev_dbg(&cdev->gadget->dev, "obex ttyGS%d disable\n", obex->port_num);
- gserial_disconnect(&obex->port);
+ if (intf == 1 && alt == 1)
+ gserial_disconnect(&obex->port);
}
/*-------------------------------------------------------------------------*/
@@ -303,15 +256,12 @@ static inline bool can_support_obex(struct usb_configuration *c)
return true;
}
-static int obex_bind(struct usb_configuration *c, struct usb_function *f)
+static int obex_prep_descs(struct usb_function *f)
{
- struct usb_composite_dev *cdev = c->cdev;
- struct f_obex *obex = func_to_obex(f);
+ struct usb_composite_dev *cdev = f->config->cdev;
struct usb_string *us;
- int status;
- struct usb_ep *ep;
- if (!can_support_obex(c))
+ if (!can_support_obex(f->config))
return -EINVAL;
us = usb_gstrings_attach(cdev, obex_strings,
@@ -322,63 +272,31 @@ static int obex_bind(struct usb_configuration *c, struct usb_function *f)
obex_data_nop_intf.iInterface = us[OBEX_DATA_IDX].id;
obex_data_intf.iInterface = us[OBEX_DATA_IDX].id;
- /* allocate instance-specific interface IDs, and patch descriptors */
-
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- obex->ctrl_id = status;
-
- obex_control_intf.bInterfaceNumber = status;
- obex_cdc_union_desc.bMasterInterface0 = status;
-
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- obex->data_id = status;
-
- obex_data_nop_intf.bInterfaceNumber = status;
- obex_data_intf.bInterfaceNumber = status;
- obex_cdc_union_desc.bSlaveInterface0 = status;
-
- /* allocate instance-specific endpoints */
-
- status = -ENODEV;
- ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_in_desc);
- if (!ep)
- goto fail;
- obex->port.in = ep;
+ return usb_function_set_descs(f, &obex_descs);
+}
- ep = usb_ep_autoconfig(cdev->gadget, &obex_fs_ep_out_desc);
- if (!ep)
- goto fail;
- obex->port.out = ep;
+static int obex_prep_vendor_descs(struct usb_function *f)
+{
+ struct f_obex *obex = func_to_obex(f);
+ int intf0_id, intf1_id;
- /* support all relevant hardware speeds... we expect that when
- * hardware is dual speed, all bulk-capable endpoints work at
- * both speeds
- */
+ intf0_id = usb_get_interface_id(f, 0);
+ intf1_id = usb_get_interface_id(f, 1);
- obex_hs_ep_in_desc.bEndpointAddress =
- obex_fs_ep_in_desc.bEndpointAddress;
- obex_hs_ep_out_desc.bEndpointAddress =
- obex_fs_ep_out_desc.bEndpointAddress;
+ obex->ctrl_id = intf0_id;
+ obex->data_id = intf1_id;
- status = usb_assign_descriptors(f, fs_function, hs_function, NULL);
- if (status)
- goto fail;
+ obex_cdc_union_desc.bMasterInterface0 = intf0_id;
+ obex_cdc_union_desc.bSlaveInterface0 = intf1_id;
- dev_dbg(&cdev->gadget->dev, "obex ttyGS%d: %s speed IN/%s OUT/%s\n",
- obex->port_num,
- gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
- obex->port.in->name, obex->port.out->name);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&obex_cdc_header_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&obex_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&obex_cdc_union_desc);
return 0;
-
-fail:
- ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status);
-
- return status;
}
static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
@@ -454,11 +372,6 @@ static void obex_free(struct usb_function *f)
kfree(obex);
}
-static void obex_unbind(struct usb_configuration *c, struct usb_function *f)
-{
- usb_free_all_descriptors(f);
-}
-
static struct usb_function *obex_alloc(struct usb_function_instance *fi)
{
struct f_obex *obex;
@@ -478,11 +391,10 @@ static struct usb_function *obex_alloc(struct usb_function_instance *fi)
obex->port.func.name = "obex";
/* descriptors are per-instance copies */
- obex->port.func.bind = obex_bind;
- obex->port.func.unbind = obex_unbind;
+ obex->port.func.prep_descs = obex_prep_descs;
+ obex->port.func.prep_vendor_descs = obex_prep_vendor_descs;
obex->port.func.set_alt = obex_set_alt;
- obex->port.func.get_alt = obex_get_alt;
- obex->port.func.disable = obex_disable;
+ obex->port.func.clear_alt = obex_clear_alt;
obex->port.func.free_func = obex_free;
obex->port.func.bind_deactivated = true;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 20/43] usb: gadget: configfs: add new composite API support |
| Message-ID | <qY52H-212-45@gated-at.bofh.it> |
| In reply to | #1325342 |
Handle functions using new API properly.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/configfs.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index fb3c9ba..60c6898 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -1358,6 +1358,11 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
goto err_purge_funcs;
}
}
+
+ ret = usb_config_do_bind(c);
+ if (ret)
+ goto err_purge_funcs;
+
usb_ep_autoconfig_reset(cdev->gadget);
}
if (cdev->use_os_string) {
@@ -1366,10 +1371,23 @@ static int configfs_composite_bind(struct usb_gadget *gadget,
goto err_purge_funcs;
}
+ ret = composite_prep_vendor_descs(cdev);
+ if (ret < 0)
+ goto err_free_vendor_descs;
+
+ ret = composite_generate_old_descs(cdev);
+ if (ret < 0)
+ goto err_free_old_descs;
+
usb_ep_autoconfig_reset(cdev->gadget);
return 0;
+err_free_old_descs:
+ composite_free_old_descs(cdev);
+err_free_vendor_descs:
+ composite_free_vendor_descs(cdev);
err_purge_funcs:
+ composite_free_descs(cdev);
purge_configs_funcs(gi);
err_comp_cleanup:
composite_dev_cleanup(cdev);
@@ -1386,6 +1404,10 @@ static void configfs_composite_unbind(struct usb_gadget *gadget)
cdev = get_gadget_data(gadget);
gi = container_of(cdev, struct gadget_info, cdev);
+ composite_free_old_descs(cdev);
+ composite_free_vendor_descs(cdev);
+ composite_free_descs(cdev);
+
kfree(otg_desc[0]);
otg_desc[0] = NULL;
purge_configs_funcs(gi);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 27/43] usb: gadget: f_acm: conversion to new API |
| Message-ID | <qY52H-212-47@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Implement prep_vendor_descs() to supply class specific
descriptors. Change set_alt() implementation and implement clear_alt()
operation. Remove boilerplate code.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_acm.c | 248 ++++++++++++------------------------
1 file changed, 78 insertions(+), 170 deletions(-)
diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c
index 2fa1e80..0d3fe1a 100644
--- a/drivers/usb/gadget/function/f_acm.c
+++ b/drivers/usb/gadget/function/f_acm.c
@@ -185,20 +185,6 @@ static struct usb_endpoint_descriptor acm_fs_out_desc = {
.bmAttributes = USB_ENDPOINT_XFER_BULK,
};
-static struct usb_descriptor_header *acm_fs_function[] = {
- (struct usb_descriptor_header *) &acm_iad_descriptor,
- (struct usb_descriptor_header *) &acm_control_interface_desc,
- (struct usb_descriptor_header *) &acm_header_desc,
- (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
- (struct usb_descriptor_header *) &acm_descriptor,
- (struct usb_descriptor_header *) &acm_union_desc,
- (struct usb_descriptor_header *) &acm_fs_notify_desc,
- (struct usb_descriptor_header *) &acm_data_interface_desc,
- (struct usb_descriptor_header *) &acm_fs_in_desc,
- (struct usb_descriptor_header *) &acm_fs_out_desc,
- NULL,
-};
-
/* high speed support: */
static struct usb_endpoint_descriptor acm_hs_notify_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
@@ -223,20 +209,6 @@ static struct usb_endpoint_descriptor acm_hs_out_desc = {
.wMaxPacketSize = cpu_to_le16(512),
};
-static struct usb_descriptor_header *acm_hs_function[] = {
- (struct usb_descriptor_header *) &acm_iad_descriptor,
- (struct usb_descriptor_header *) &acm_control_interface_desc,
- (struct usb_descriptor_header *) &acm_header_desc,
- (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
- (struct usb_descriptor_header *) &acm_descriptor,
- (struct usb_descriptor_header *) &acm_union_desc,
- (struct usb_descriptor_header *) &acm_hs_notify_desc,
- (struct usb_descriptor_header *) &acm_data_interface_desc,
- (struct usb_descriptor_header *) &acm_hs_in_desc,
- (struct usb_descriptor_header *) &acm_hs_out_desc,
- NULL,
-};
-
static struct usb_endpoint_descriptor acm_ss_in_desc = {
.bLength = USB_DT_ENDPOINT_SIZE,
.bDescriptorType = USB_DT_ENDPOINT,
@@ -256,22 +228,20 @@ static struct usb_ss_ep_comp_descriptor acm_ss_bulk_comp_desc = {
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
};
-static struct usb_descriptor_header *acm_ss_function[] = {
- (struct usb_descriptor_header *) &acm_iad_descriptor,
- (struct usb_descriptor_header *) &acm_control_interface_desc,
- (struct usb_descriptor_header *) &acm_header_desc,
- (struct usb_descriptor_header *) &acm_call_mgmt_descriptor,
- (struct usb_descriptor_header *) &acm_descriptor,
- (struct usb_descriptor_header *) &acm_union_desc,
- (struct usb_descriptor_header *) &acm_hs_notify_desc,
- (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
- (struct usb_descriptor_header *) &acm_data_interface_desc,
- (struct usb_descriptor_header *) &acm_ss_in_desc,
- (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
- (struct usb_descriptor_header *) &acm_ss_out_desc,
- (struct usb_descriptor_header *) &acm_ss_bulk_comp_desc,
- NULL,
-};
+USB_COMPOSITE_ENDPOINT(ep_notify, &acm_fs_notify_desc, &acm_hs_notify_desc,
+ &acm_hs_notify_desc, &acm_ss_bulk_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_in, &acm_fs_in_desc, &acm_hs_in_desc,
+ &acm_ss_in_desc, &acm_ss_bulk_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_out, &acm_fs_out_desc, &acm_hs_out_desc,
+ &acm_ss_out_desc, &acm_ss_bulk_comp_desc);
+
+USB_COMPOSITE_ALTSETTING(intf0alt0, &acm_control_interface_desc, &ep_notify);
+USB_COMPOSITE_ALTSETTING(intf1alt0, &acm_data_interface_desc, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+USB_COMPOSITE_INTERFACE(intf1, &intf1alt0);
+
+USB_COMPOSITE_DESCRIPTORS(acm_descs, &intf0, &intf1);
/* string descriptors: */
@@ -420,6 +390,8 @@ invalid:
return value;
}
+static void acm_cdc_notify_complete(struct usb_ep *ep, struct usb_request *req);
+
static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct f_acm *acm = func_to_acm(f);
@@ -427,51 +399,49 @@ static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
/* we know alt == 0, so this is an activation or a reset */
- if (intf == acm->ctrl_id) {
+ if (intf == 0) {
dev_vdbg(&cdev->gadget->dev,
"reset acm control interface %d\n", intf);
- usb_ep_disable(acm->notify);
-
- if (!acm->notify->desc)
- if (config_ep_by_speed(cdev->gadget, f, acm->notify))
- return -EINVAL;
-
- usb_ep_enable(acm->notify);
-
- } else if (intf == acm->data_id) {
- if (acm->notify->enabled) {
- dev_dbg(&cdev->gadget->dev,
- "reset acm ttyGS%d\n", acm->port_num);
- gserial_disconnect(&acm->port);
- }
- if (!acm->port.in->desc || !acm->port.out->desc) {
- dev_dbg(&cdev->gadget->dev,
+
+ acm->notify = usb_function_get_ep(f, intf, 0);
+ if (!acm->notify)
+ return -ENODEV;
+
+ /* allocate notification */
+ acm->notify_req = gs_alloc_req(acm->notify,
+ sizeof(struct usb_cdc_notification) + 2,
+ GFP_KERNEL);
+ if (!acm->notify_req)
+ return -ENOMEM;
+
+ acm->notify_req->complete = acm_cdc_notify_complete;
+ acm->notify_req->context = acm;
+ } else if (intf == 1) {
+ dev_dbg(&cdev->gadget->dev,
"activate acm ttyGS%d\n", acm->port_num);
- if (config_ep_by_speed(cdev->gadget, f,
- acm->port.in) ||
- config_ep_by_speed(cdev->gadget, f,
- acm->port.out)) {
- acm->port.in->desc = NULL;
- acm->port.out->desc = NULL;
- return -EINVAL;
- }
- }
- gserial_connect(&acm->port, acm->port_num);
- } else
- return -EINVAL;
+ acm->port.in = usb_function_get_ep(f, intf, 0);
+ if (!acm->port.in)
+ return -ENODEV;
+ acm->port.out = usb_function_get_ep(f, intf, 1);
+ if (!acm->port.out)
+ return -ENODEV;
+
+ gserial_connect(&acm->port, acm->port_num);
+ }
return 0;
}
-static void acm_disable(struct usb_function *f)
+static void acm_clear_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct f_acm *acm = func_to_acm(f);
struct usb_composite_dev *cdev = f->config->cdev;
dev_dbg(&cdev->gadget->dev, "acm ttyGS%d deactivated\n", acm->port_num);
gserial_disconnect(&acm->port);
- usb_ep_disable(acm->notify);
+
+ gs_free_req(acm->notify, acm->notify_req);
}
/*-------------------------------------------------------------------------*/
@@ -602,15 +572,10 @@ static int acm_send_break(struct gserial *port, int duration)
/*-------------------------------------------------------------------------*/
-/* ACM function driver setup/binding */
-static int
-acm_bind(struct usb_configuration *c, struct usb_function *f)
+static int acm_prep_descs(struct usb_function *f)
{
- struct usb_composite_dev *cdev = c->cdev;
- struct f_acm *acm = func_to_acm(f);
+ struct usb_composite_dev *cdev = f->config->cdev;
struct usb_string *us;
- int status;
- struct usb_ep *ep;
/* REVISIT might want instance-specific strings to help
* distinguish instances ...
@@ -625,96 +590,39 @@ acm_bind(struct usb_configuration *c, struct usb_function *f)
acm_data_interface_desc.iInterface = us[ACM_DATA_IDX].id;
acm_iad_descriptor.iFunction = us[ACM_IAD_IDX].id;
- /* allocate instance-specific interface IDs, and patch descriptors */
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- acm->ctrl_id = status;
- acm_iad_descriptor.bFirstInterface = status;
-
- acm_control_interface_desc.bInterfaceNumber = status;
- acm_union_desc .bMasterInterface0 = status;
-
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- acm->data_id = status;
-
- acm_data_interface_desc.bInterfaceNumber = status;
- acm_union_desc.bSlaveInterface0 = status;
- acm_call_mgmt_descriptor.bDataInterface = status;
-
- status = -ENODEV;
-
- /* allocate instance-specific endpoints */
- ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_in_desc);
- if (!ep)
- goto fail;
- acm->port.in = ep;
-
- ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_out_desc);
- if (!ep)
- goto fail;
- acm->port.out = ep;
-
- ep = usb_ep_autoconfig(cdev->gadget, &acm_fs_notify_desc);
- if (!ep)
- goto fail;
- acm->notify = ep;
-
- /* allocate notification */
- acm->notify_req = gs_alloc_req(ep,
- sizeof(struct usb_cdc_notification) + 2,
- GFP_KERNEL);
- if (!acm->notify_req)
- goto fail;
-
- acm->notify_req->complete = acm_cdc_notify_complete;
- acm->notify_req->context = acm;
-
- /* support all relevant hardware speeds... we expect that when
- * hardware is dual speed, all bulk-capable endpoints work at
- * both speeds
- */
- acm_hs_in_desc.bEndpointAddress = acm_fs_in_desc.bEndpointAddress;
- acm_hs_out_desc.bEndpointAddress = acm_fs_out_desc.bEndpointAddress;
- acm_hs_notify_desc.bEndpointAddress =
- acm_fs_notify_desc.bEndpointAddress;
-
- acm_ss_in_desc.bEndpointAddress = acm_fs_in_desc.bEndpointAddress;
- acm_ss_out_desc.bEndpointAddress = acm_fs_out_desc.bEndpointAddress;
-
- status = usb_assign_descriptors(f, acm_fs_function, acm_hs_function,
- acm_ss_function);
- if (status)
- goto fail;
-
- dev_dbg(&cdev->gadget->dev,
- "acm ttyGS%d: %s speed IN/%s OUT/%s NOTIFY/%s\n",
- acm->port_num,
- gadget_is_superspeed(c->cdev->gadget) ? "super" :
- gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
- acm->port.in->name, acm->port.out->name,
- acm->notify->name);
- return 0;
-
-fail:
- if (acm->notify_req)
- gs_free_req(acm->notify, acm->notify_req);
-
- ERROR(cdev, "%s/%p: can't bind, err %d\n", f->name, f, status);
-
- return status;
+ return usb_function_set_descs(f, &acm_descs);
}
-static void acm_unbind(struct usb_configuration *c, struct usb_function *f)
+static int acm_prep_vendor_descs(struct usb_function *f)
{
struct f_acm *acm = func_to_acm(f);
+ int intf0_id, intf1_id;
+
+ intf0_id = usb_get_interface_id(f, 0);
+ intf1_id = usb_get_interface_id(f, 1);
+
+ acm->ctrl_id = intf0_id;
+ acm->data_id = intf1_id;
+
+ acm_iad_descriptor.bFirstInterface = intf0_id;
- acm_string_defs[0].id = 0;
- usb_free_all_descriptors(f);
- if (acm->notify_req)
- gs_free_req(acm->notify, acm->notify_req);
+ acm_call_mgmt_descriptor.bDataInterface = intf1_id;
+ acm_union_desc.bMasterInterface0 = intf0_id;
+ acm_union_desc.bSlaveInterface0 = intf1_id;
+
+ usb_function_add_vendor_desc(f,
+ (struct usb_descriptor_header *)&acm_iad_descriptor);
+
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&acm_header_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *) &acm_call_mgmt_descriptor);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&acm_descriptor);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&acm_union_desc);
+
+ return 0;
}
static void acm_free_func(struct usb_function *f)
@@ -742,14 +650,14 @@ static struct usb_function *acm_alloc_func(struct usb_function_instance *fi)
acm->port.func.name = "acm";
acm->port.func.strings = acm_strings;
/* descriptors are per-instance copies */
- acm->port.func.bind = acm_bind;
+ acm->port.func.prep_descs = acm_prep_descs;
+ acm->port.func.prep_vendor_descs = acm_prep_vendor_descs;
acm->port.func.set_alt = acm_set_alt;
+ acm->port.func.clear_alt = acm_clear_alt;
acm->port.func.setup = acm_setup;
- acm->port.func.disable = acm_disable;
opts = container_of(fi, struct f_serial_opts, func_inst);
acm->port_num = opts->port_num;
- acm->port.func.unbind = acm_unbind;
acm->port.func.free_func = acm_free_func;
return &acm->port.func;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 26/43] usb: gadget: f_hid: conversion to new API |
| Message-ID | <qY52I-212-51@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Implement prep_vendor_descs() to supply class specific
descriptors. Change set_alt() implementation and implement clear_alt()
operation. Move cdev initialization to hidg_alloc(). Remove boilerplate
code.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_hid.c | 305 ++++++++++++++----------------------
1 file changed, 119 insertions(+), 186 deletions(-)
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 0456a53..8770289 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -125,14 +125,6 @@ static struct usb_endpoint_descriptor hidg_hs_out_ep_desc = {
*/
};
-static struct usb_descriptor_header *hidg_hs_descriptors[] = {
- (struct usb_descriptor_header *)&hidg_interface_desc,
- (struct usb_descriptor_header *)&hidg_desc,
- (struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
- (struct usb_descriptor_header *)&hidg_hs_out_ep_desc,
- NULL,
-};
-
/* Full-Speed Support */
static struct usb_endpoint_descriptor hidg_fs_in_ep_desc = {
@@ -159,13 +151,16 @@ static struct usb_endpoint_descriptor hidg_fs_out_ep_desc = {
*/
};
-static struct usb_descriptor_header *hidg_fs_descriptors[] = {
- (struct usb_descriptor_header *)&hidg_interface_desc,
- (struct usb_descriptor_header *)&hidg_desc,
- (struct usb_descriptor_header *)&hidg_fs_in_ep_desc,
- (struct usb_descriptor_header *)&hidg_fs_out_ep_desc,
- NULL,
-};
+USB_COMPOSITE_ENDPOINT(ep_in, &hidg_fs_in_ep_desc,
+ &hidg_hs_in_ep_desc, NULL, NULL);
+USB_COMPOSITE_ENDPOINT(ep_out, &hidg_fs_out_ep_desc,
+ &hidg_hs_out_ep_desc, NULL, NULL);
+
+USB_COMPOSITE_ALTSETTING(intf0alt0, &hidg_interface_desc, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+
+USB_COMPOSITE_DESCRIPTORS(hidg_descs, &intf0);
/*-------------------------------------------------------------------------*/
/* Strings */
@@ -487,27 +482,6 @@ respond:
return status;
}
-static void hidg_disable(struct usb_function *f)
-{
- struct f_hidg *hidg = func_to_hidg(f);
- struct f_hidg_req_list *list, *next;
- int i;
-
- usb_ep_disable(hidg->in_ep);
- usb_ep_disable(hidg->out_ep);
-
- list_for_each_entry_safe(list, next, &hidg->completed_out_req, list) {
- list_del(&list->list);
- kfree(list);
- }
-
- for (i = 0; i < hidg->qlen; ++i) {
- kfree(hidg->out_reqs[i]->buf);
- kfree(hidg->out_reqs[i]);
- }
- kfree(hidg->out_reqs);
-}
-
static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct usb_composite_dev *cdev = f->config->cdev;
@@ -516,65 +490,46 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
VDBG(cdev, "hidg_set_alt intf:%d alt:%d\n", intf, alt);
- if (hidg->in_ep != NULL) {
- /* restart endpoint */
- usb_ep_disable(hidg->in_ep);
+ hidg->in_ep = usb_function_get_ep(f, intf, 0);
+ if (!hidg->in_ep)
+ return -ENODEV;
+ hidg->in_ep->driver_data = hidg;
- status = config_ep_by_speed(f->config->cdev->gadget, f,
- hidg->in_ep);
- if (status) {
- ERROR(cdev, "config_ep_by_speed FAILED!\n");
- goto fail;
- }
- status = usb_ep_enable(hidg->in_ep);
- if (status < 0) {
- ERROR(cdev, "Enable IN endpoint FAILED!\n");
- goto fail;
- }
- hidg->in_ep->driver_data = hidg;
- }
+ hidg->out_ep = usb_function_get_ep(f, intf, 1);
+ if (!hidg->out_ep)
+ return -ENODEV;
+ hidg->out_ep->driver_data = hidg;
+ /* preallocate request and buffer */
+ hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL);
+ if (!hidg->req)
+ return -ENOMEM;
- if (hidg->out_ep != NULL) {
- /* restart endpoint */
- usb_ep_disable(hidg->out_ep);
+ hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL);
+ if (!hidg->req->buf)
+ return -ENOMEM;
- status = config_ep_by_speed(f->config->cdev->gadget, f,
- hidg->out_ep);
- if (status) {
- ERROR(cdev, "config_ep_by_speed FAILED!\n");
- goto fail;
- }
- status = usb_ep_enable(hidg->out_ep);
- if (status < 0) {
- ERROR(cdev, "Enable IN endpoint FAILED!\n");
- goto fail;
- }
- hidg->out_ep->driver_data = hidg;
-
- /*
- * allocate a bunch of read buffers and queue them all at once.
- */
- hidg->out_reqs = kzalloc(hidg->qlen *
- sizeof(*hidg->out_reqs), GFP_KERNEL);
- for (i = 0; i < hidg->qlen && status == 0; i++) {
- struct usb_request *req =
- hidg_alloc_ep_req(hidg->out_ep,
- hidg->report_length);
- if (req) {
+ /*
+ * allocate a bunch of read buffers and queue them all at once.
+ */
+ hidg->out_reqs = kzalloc(hidg->qlen *
+ sizeof(*hidg->out_reqs), GFP_KERNEL);
+ for (i = 0; i < hidg->qlen && status == 0; i++) {
+ struct usb_request *req =
+ hidg_alloc_ep_req(hidg->out_ep,
+ hidg->report_length);
+ if (req) {
hidg->out_reqs[i] = req;
- req->complete = hidg_set_report_complete;
- req->context = hidg;
- status = usb_ep_queue(hidg->out_ep, req,
- GFP_ATOMIC);
- if (status)
- ERROR(cdev, "%s queue req --> %d\n",
+ req->complete = hidg_set_report_complete;
+ req->context = hidg;
+ status = usb_ep_queue(hidg->out_ep, req,
+ GFP_ATOMIC);
+ if (status)
+ ERROR(cdev, "%s queue req --> %d\n",
hidg->out_ep->name, status);
- } else {
- usb_ep_disable(hidg->out_ep);
- status = -ENOMEM;
- goto free_req;
- }
+ } else {
+ status = -ENOMEM;
+ goto free_req;
}
}
@@ -587,10 +542,31 @@ free_req:
kfree(hidg->out_reqs);
}
-fail:
return status;
}
+static void hidg_clear_alt(struct usb_function *f, unsigned intf, unsigned alt)
+{
+ struct f_hidg *hidg = func_to_hidg(f);
+ struct f_hidg_req_list *list, *next;
+ int i;
+
+ list_for_each_entry_safe(list, next, &hidg->completed_out_req, list) {
+ list_del(&list->list);
+ kfree(list);
+ }
+
+ for (i = 0; i < hidg->qlen; ++i) {
+ kfree(hidg->out_reqs[i]->buf);
+ kfree(hidg->out_reqs[i]);
+ }
+ kfree(hidg->out_reqs);
+
+ /* disable/free request and end point */
+ kfree(hidg->req->buf);
+ usb_ep_free_request(hidg->in_ep, hidg->req);
+}
+
static const struct file_operations f_hidg_fops = {
.owner = THIS_MODULE,
.open = f_hidg_open,
@@ -601,50 +577,19 @@ static const struct file_operations f_hidg_fops = {
.llseek = noop_llseek,
};
-static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
+static int hidg_prep_descs(struct usb_function *f)
{
- struct usb_ep *ep;
+ struct usb_composite_dev *cdev = f->config->cdev;
struct f_hidg *hidg = func_to_hidg(f);
struct usb_string *us;
- struct device *device;
- int status;
- dev_t dev;
/* maybe allocate device-global string IDs, and patch descriptors */
- us = usb_gstrings_attach(c->cdev, ct_func_strings,
+ us = usb_gstrings_attach(cdev, ct_func_strings,
ARRAY_SIZE(ct_func_string_defs));
if (IS_ERR(us))
return PTR_ERR(us);
hidg_interface_desc.iInterface = us[CT_FUNC_HID_IDX].id;
- /* allocate instance-specific interface IDs, and patch descriptors */
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- hidg_interface_desc.bInterfaceNumber = status;
-
- /* allocate instance-specific endpoints */
- status = -ENODEV;
- ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_in_ep_desc);
- if (!ep)
- goto fail;
- hidg->in_ep = ep;
-
- ep = usb_ep_autoconfig(c->cdev->gadget, &hidg_fs_out_ep_desc);
- if (!ep)
- goto fail;
- hidg->out_ep = ep;
-
- /* preallocate request and buffer */
- status = -ENOMEM;
- hidg->req = usb_ep_alloc_request(hidg->in_ep, GFP_KERNEL);
- if (!hidg->req)
- goto fail;
-
- hidg->req->buf = kmalloc(hidg->report_length, GFP_KERNEL);
- if (!hidg->req->buf)
- goto fail;
-
/* set descriptor dynamic values */
hidg_interface_desc.bInterfaceSubClass = hidg->bInterfaceSubClass;
hidg_interface_desc.bInterfaceProtocol = hidg->bInterfaceProtocol;
@@ -652,6 +597,14 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
hidg_fs_in_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
hidg_hs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
hidg_fs_out_ep_desc.wMaxPacketSize = cpu_to_le16(hidg->report_length);
+
+ return usb_function_set_descs(f, &hidg_descs);
+}
+
+static int hidg_prep_vendor_descs(struct usb_function *f)
+{
+ struct f_hidg *hidg = func_to_hidg(f);
+
/*
* We can use hidg_desc struct here but we should not relay
* that its content won't change after returning from this function.
@@ -660,50 +613,10 @@ static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
hidg_desc.desc[0].wDescriptorLength =
cpu_to_le16(hidg->report_desc_length);
- hidg_hs_in_ep_desc.bEndpointAddress =
- hidg_fs_in_ep_desc.bEndpointAddress;
- hidg_hs_out_ep_desc.bEndpointAddress =
- hidg_fs_out_ep_desc.bEndpointAddress;
-
- status = usb_assign_descriptors(f, hidg_fs_descriptors,
- hidg_hs_descriptors, NULL);
- if (status)
- goto fail;
-
- mutex_init(&hidg->lock);
- spin_lock_init(&hidg->spinlock);
- init_waitqueue_head(&hidg->write_queue);
- init_waitqueue_head(&hidg->read_queue);
- INIT_LIST_HEAD(&hidg->completed_out_req);
-
- /* create char device */
- cdev_init(&hidg->cdev, &f_hidg_fops);
- dev = MKDEV(major, hidg->minor);
- status = cdev_add(&hidg->cdev, dev, 1);
- if (status)
- goto fail_free_descs;
-
- device = device_create(hidg_class, NULL, dev, NULL,
- "%s%d", "hidg", hidg->minor);
- if (IS_ERR(device)) {
- status = PTR_ERR(device);
- goto del;
- }
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&hidg_desc);
return 0;
-del:
- cdev_del(&hidg->cdev);
-fail_free_descs:
- usb_free_all_descriptors(f);
-fail:
- ERROR(f->config->cdev, "hidg_bind FAILED\n");
- if (hidg->req != NULL) {
- kfree(hidg->req->buf);
- if (hidg->in_ep != NULL)
- usb_ep_free_request(hidg->in_ep, hidg->req);
- }
-
- return status;
}
static inline int hidg_get_minor(void)
@@ -914,6 +827,10 @@ static void hidg_free(struct usb_function *f)
hidg = func_to_hidg(f);
opts = container_of(f->fi, struct f_hid_opts, func_inst);
+
+ device_destroy(hidg_class, MKDEV(major, hidg->minor));
+ cdev_del(&hidg->cdev);
+
kfree(hidg->report_desc);
kfree(hidg);
mutex_lock(&opts->lock);
@@ -921,31 +838,25 @@ static void hidg_free(struct usb_function *f)
mutex_unlock(&opts->lock);
}
-static void hidg_unbind(struct usb_configuration *c, struct usb_function *f)
-{
- struct f_hidg *hidg = func_to_hidg(f);
-
- device_destroy(hidg_class, MKDEV(major, hidg->minor));
- cdev_del(&hidg->cdev);
-
- /* disable/free request and end point */
- usb_ep_disable(hidg->in_ep);
- kfree(hidg->req->buf);
- usb_ep_free_request(hidg->in_ep, hidg->req);
-
- usb_free_all_descriptors(f);
-}
-
static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
{
struct f_hidg *hidg;
struct f_hid_opts *opts;
+ struct device *device;
+ dev_t dev;
+ int ret;
/* allocate and initialize one new instance */
hidg = kzalloc(sizeof(*hidg), GFP_KERNEL);
if (!hidg)
return ERR_PTR(-ENOMEM);
+ mutex_init(&hidg->lock);
+ spin_lock_init(&hidg->spinlock);
+ init_waitqueue_head(&hidg->write_queue);
+ init_waitqueue_head(&hidg->read_queue);
+ INIT_LIST_HEAD(&hidg->completed_out_req);
+
opts = container_of(fi, struct f_hid_opts, func_inst);
mutex_lock(&opts->lock);
@@ -961,26 +872,48 @@ static struct usb_function *hidg_alloc(struct usb_function_instance *fi)
opts->report_desc_length,
GFP_KERNEL);
if (!hidg->report_desc) {
- kfree(hidg);
mutex_unlock(&opts->lock);
- return ERR_PTR(-ENOMEM);
+ ret = -ENOMEM;
+ goto err_hidg;
}
}
mutex_unlock(&opts->lock);
hidg->func.name = "hid";
- hidg->func.bind = hidg_bind;
- hidg->func.unbind = hidg_unbind;
+ hidg->func.prep_descs = hidg_prep_descs;
+ hidg->func.prep_vendor_descs = hidg_prep_vendor_descs;
hidg->func.set_alt = hidg_set_alt;
- hidg->func.disable = hidg_disable;
+ hidg->func.clear_alt = hidg_clear_alt;
hidg->func.setup = hidg_setup;
hidg->func.free_func = hidg_free;
/* this could me made configurable at some point */
hidg->qlen = 4;
+ /* create char device */
+ cdev_init(&hidg->cdev, &f_hidg_fops);
+ dev = MKDEV(major, hidg->minor);
+ ret = cdev_add(&hidg->cdev, dev, 1);
+ if (ret < 0)
+ goto err_report;
+
+ device = device_create(hidg_class, NULL, dev, NULL,
+ "%s%d", "hidg", hidg->minor);
+ if (IS_ERR(device)) {
+ ret = PTR_ERR(device);
+ goto err_cdev;
+ }
+
return &hidg->func;
+
+err_cdev:
+ cdev_del(&hidg->cdev);
+err_report:
+ kfree(hidg->report_desc);
+err_hidg:
+ kfree(hidg);
+ return ERR_PTR(ret);
}
DECLARE_USB_FUNCTION_INIT(hid, hidg_alloc_inst, hidg_alloc);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 30/43] usb: gadget: f_printer: conversion to new API |
| Message-ID | <qY52I-212-55@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Implement prep_vendor_descs() to supply class specific
descriptors. Change set_alt() implementation and implement clear_alt()
operation. Remove boilerplate code.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_printer.c | 300 ++++++++++----------------------
1 file changed, 88 insertions(+), 212 deletions(-)
diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 26ccad5..70bad43 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -135,13 +135,6 @@ static struct usb_endpoint_descriptor fs_ep_out_desc = {
.bmAttributes = USB_ENDPOINT_XFER_BULK
};
-static struct usb_descriptor_header *fs_printer_function[] = {
- (struct usb_descriptor_header *) &intf_desc,
- (struct usb_descriptor_header *) &fs_ep_in_desc,
- (struct usb_descriptor_header *) &fs_ep_out_desc,
- NULL
-};
-
/*
* usb 2.0 devices need to expose both high speed and full speed
* descriptors, unless they only run at full speed.
@@ -169,13 +162,6 @@ static struct usb_qualifier_descriptor dev_qualifier = {
.bNumConfigurations = 1
};
-static struct usb_descriptor_header *hs_printer_function[] = {
- (struct usb_descriptor_header *) &intf_desc,
- (struct usb_descriptor_header *) &hs_ep_in_desc,
- (struct usb_descriptor_header *) &hs_ep_out_desc,
- NULL
-};
-
/*
* Added endpoint descriptors for 3.0 devices
*/
@@ -204,14 +190,16 @@ static struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = {
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
};
-static struct usb_descriptor_header *ss_printer_function[] = {
- (struct usb_descriptor_header *) &intf_desc,
- (struct usb_descriptor_header *) &ss_ep_in_desc,
- (struct usb_descriptor_header *) &ss_ep_in_comp_desc,
- (struct usb_descriptor_header *) &ss_ep_out_desc,
- (struct usb_descriptor_header *) &ss_ep_out_comp_desc,
- NULL
-};
+USB_COMPOSITE_ENDPOINT(ep_in, &fs_ep_in_desc, &hs_ep_in_desc,
+ &ss_ep_in_desc, &ss_ep_in_comp_desc);
+USB_COMPOSITE_ENDPOINT(ep_out, &fs_ep_out_desc, &hs_ep_out_desc,
+ &ss_ep_out_desc, &ss_ep_out_comp_desc);
+
+USB_COMPOSITE_ALTSETTING(intf0alt0, &intf_desc, &ep_in, &ep_out);
+
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+
+USB_COMPOSITE_DESCRIPTORS(printer_descs, &intf0);
/* maxpacket and other transfer characteristics vary by speed. */
static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget,
@@ -764,86 +752,6 @@ static const struct file_operations printer_io_operations = {
/*-------------------------------------------------------------------------*/
-static int
-set_printer_interface(struct printer_dev *dev)
-{
- int result = 0;
-
- dev->in_ep->desc = ep_desc(dev->gadget, &fs_ep_in_desc, &hs_ep_in_desc,
- &ss_ep_in_desc);
- dev->in_ep->driver_data = dev;
-
- dev->out_ep->desc = ep_desc(dev->gadget, &fs_ep_out_desc,
- &hs_ep_out_desc, &ss_ep_out_desc);
- dev->out_ep->driver_data = dev;
-
- result = usb_ep_enable(dev->in_ep);
- if (result != 0) {
- DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
- goto done;
- }
-
- result = usb_ep_enable(dev->out_ep);
- if (result != 0) {
- DBG(dev, "enable %s --> %d\n", dev->in_ep->name, result);
- goto done;
- }
-
-done:
- /* on error, disable any endpoints */
- if (result != 0) {
- (void) usb_ep_disable(dev->in_ep);
- (void) usb_ep_disable(dev->out_ep);
- dev->in_ep->desc = NULL;
- dev->out_ep->desc = NULL;
- }
-
- /* caller is responsible for cleanup on error */
- return result;
-}
-
-static void printer_reset_interface(struct printer_dev *dev)
-{
- unsigned long flags;
-
- if (dev->interface < 0)
- return;
-
- DBG(dev, "%s\n", __func__);
-
- if (dev->in_ep->desc)
- usb_ep_disable(dev->in_ep);
-
- if (dev->out_ep->desc)
- usb_ep_disable(dev->out_ep);
-
- spin_lock_irqsave(&dev->lock, flags);
- dev->in_ep->desc = NULL;
- dev->out_ep->desc = NULL;
- dev->interface = -1;
- spin_unlock_irqrestore(&dev->lock, flags);
-}
-
-/* Change our operational Interface. */
-static int set_interface(struct printer_dev *dev, unsigned number)
-{
- int result = 0;
-
- /* Free the current interface */
- printer_reset_interface(dev);
-
- result = set_printer_interface(dev);
- if (result)
- printer_reset_interface(dev);
- else
- dev->interface = number;
-
- if (!result)
- INFO(dev, "Using interface %x\n", number);
-
- return result;
-}
-
static void printer_soft_reset(struct printer_dev *dev)
{
struct usb_request *req;
@@ -1008,55 +916,64 @@ unknown:
return value;
}
-static int printer_func_bind(struct usb_configuration *c,
- struct usb_function *f)
+static int printer_func_prep_descs(struct usb_function *f)
+{
+ return usb_function_set_descs(f, &printer_descs);
+}
+
+static int printer_func_prep_vendor_descs(struct usb_function *f)
{
- struct usb_gadget *gadget = c->cdev->gadget;
struct printer_dev *dev = func_to_printer(f);
struct device *pdev;
- struct usb_composite_dev *cdev = c->cdev;
- struct usb_ep *in_ep;
- struct usb_ep *out_ep = NULL;
- struct usb_request *req;
dev_t devt;
- int id;
int ret;
- u32 i;
- id = usb_interface_id(c, f);
- if (id < 0)
- return id;
- intf_desc.bInterfaceNumber = id;
+ dev->interface = usb_get_interface_id(f, 0);
- /* finish hookup to lower layer ... */
- dev->gadget = gadget;
-
- /* all we really need is bulk IN/OUT */
- in_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_in_desc);
- if (!in_ep) {
-autoconf_fail:
- dev_err(&cdev->gadget->dev, "can't autoconfigure on %s\n",
- cdev->gadget->name);
- return -ENODEV;
+ /* Setup the sysfs files for the printer gadget. */
+ devt = MKDEV(major, dev->minor);
+ pdev = device_create(usb_gadget_class, NULL, devt,
+ NULL, "g_printer%d", dev->minor);
+ if (IS_ERR(pdev)) {
+ ERROR(dev, "Failed to create device: g_printer\n");
+ return PTR_ERR(pdev);
+ }
+
+ /*
+ * Register a character device as an interface to a user mode
+ * program that handles the printer specific functionality.
+ */
+ cdev_init(&dev->printer_cdev, &printer_io_operations);
+ dev->printer_cdev.owner = THIS_MODULE;
+ ret = cdev_add(&dev->printer_cdev, devt, 1);
+ if (ret) {
+ ERROR(dev, "Failed to open char device\n");
+ device_destroy(usb_gadget_class, devt);
}
- out_ep = usb_ep_autoconfig(cdev->gadget, &fs_ep_out_desc);
- if (!out_ep)
- goto autoconf_fail;
+ return ret;
+}
- /* assumes that all endpoints are dual-speed */
- hs_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
- hs_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
- ss_ep_in_desc.bEndpointAddress = fs_ep_in_desc.bEndpointAddress;
- ss_ep_out_desc.bEndpointAddress = fs_ep_out_desc.bEndpointAddress;
+static int printer_func_set_alt(struct usb_function *f,
+ unsigned intf, unsigned alt)
+{
+ struct printer_dev *dev = func_to_printer(f);
+ struct usb_composite_dev *cdev = f->config->cdev;
+ struct usb_request *req;
+ int i, ret = -ENOTSUPP;
- ret = usb_assign_descriptors(f, fs_printer_function,
- hs_printer_function, ss_printer_function);
- if (ret)
- return ret;
+ /* finish hookup to lower layer ... */
+ dev->gadget = cdev->gadget;
+
+ dev->in_ep = usb_function_get_ep(f, intf, 0);
+ if (!dev->in_ep)
+ return -ENODEV;
+ dev->out_ep = usb_function_get_ep(f, intf, 1);
+ if (!dev->out_ep)
+ return -ENODEV;
- dev->in_ep = in_ep;
- dev->out_ep = out_ep;
+ dev->in_ep->driver_data = dev;
+ dev->out_ep->driver_data = dev;
ret = -ENOMEM;
for (i = 0; i < dev->q_len; i++) {
@@ -1073,33 +990,8 @@ autoconf_fail:
list_add(&req->list, &dev->rx_reqs);
}
- /* Setup the sysfs files for the printer gadget. */
- devt = MKDEV(major, dev->minor);
- pdev = device_create(usb_gadget_class, NULL, devt,
- NULL, "g_printer%d", dev->minor);
- if (IS_ERR(pdev)) {
- ERROR(dev, "Failed to create device: g_printer\n");
- ret = PTR_ERR(pdev);
- goto fail_rx_reqs;
- }
-
- /*
- * Register a character device as an interface to a user mode
- * program that handles the printer specific functionality.
- */
- cdev_init(&dev->printer_cdev, &printer_io_operations);
- dev->printer_cdev.owner = THIS_MODULE;
- ret = cdev_add(&dev->printer_cdev, devt, 1);
- if (ret) {
- ERROR(dev, "Failed to open char device\n");
- goto fail_cdev_add;
- }
-
return 0;
-fail_cdev_add:
- device_destroy(usb_gadget_class, devt);
-
fail_rx_reqs:
while (!list_empty(&dev->rx_reqs)) {
req = container_of(dev->rx_reqs.next, struct usb_request, list);
@@ -1115,28 +1007,44 @@ fail_tx_reqs:
}
return ret;
-
}
-static int printer_func_set_alt(struct usb_function *f,
+static void printer_func_clear_alt(struct usb_function *f,
unsigned intf, unsigned alt)
{
struct printer_dev *dev = func_to_printer(f);
- int ret = -ENOTSUPP;
+ struct usb_request *req;
+
+ DBG(dev, "%s\n", __func__);
- if (!alt)
- ret = set_interface(dev, intf);
+ /* we must already have been disconnected ... no i/o may be active */
+ WARN_ON(!list_empty(&dev->tx_reqs_active));
+ WARN_ON(!list_empty(&dev->rx_reqs_active));
- return ret;
-}
+ /* Free all memory for this driver. */
+ while (!list_empty(&dev->tx_reqs)) {
+ req = container_of(dev->tx_reqs.next, struct usb_request,
+ list);
+ list_del(&req->list);
+ printer_req_free(dev->in_ep, req);
+ }
-static void printer_func_disable(struct usb_function *f)
-{
- struct printer_dev *dev = func_to_printer(f);
+ if (dev->current_rx_req != NULL)
+ printer_req_free(dev->out_ep, dev->current_rx_req);
- DBG(dev, "%s\n", __func__);
+ while (!list_empty(&dev->rx_reqs)) {
+ req = container_of(dev->rx_reqs.next,
+ struct usb_request, list);
+ list_del(&req->list);
+ printer_req_free(dev->out_ep, req);
+ }
- printer_reset_interface(dev);
+ while (!list_empty(&dev->rx_buffers)) {
+ req = container_of(dev->rx_buffers.next,
+ struct usb_request, list);
+ list_del(&req->list);
+ printer_req_free(dev->out_ep, req);
+ }
}
static inline struct f_printer_opts
@@ -1333,45 +1241,12 @@ static void gprinter_free(struct usb_function *f)
static void printer_func_unbind(struct usb_configuration *c,
struct usb_function *f)
{
- struct printer_dev *dev;
- struct usb_request *req;
-
- dev = func_to_printer(f);
+ struct printer_dev *dev = func_to_printer(f);
device_destroy(usb_gadget_class, MKDEV(major, dev->minor));
/* Remove Character Device */
cdev_del(&dev->printer_cdev);
-
- /* we must already have been disconnected ... no i/o may be active */
- WARN_ON(!list_empty(&dev->tx_reqs_active));
- WARN_ON(!list_empty(&dev->rx_reqs_active));
-
- /* Free all memory for this driver. */
- while (!list_empty(&dev->tx_reqs)) {
- req = container_of(dev->tx_reqs.next, struct usb_request,
- list);
- list_del(&req->list);
- printer_req_free(dev->in_ep, req);
- }
-
- if (dev->current_rx_req != NULL)
- printer_req_free(dev->out_ep, dev->current_rx_req);
-
- while (!list_empty(&dev->rx_reqs)) {
- req = container_of(dev->rx_reqs.next,
- struct usb_request, list);
- list_del(&req->list);
- printer_req_free(dev->out_ep, req);
- }
-
- while (!list_empty(&dev->rx_buffers)) {
- req = container_of(dev->rx_buffers.next,
- struct usb_request, list);
- list_del(&req->list);
- printer_req_free(dev->out_ep, req);
- }
- usb_free_all_descriptors(f);
}
static struct usb_function *gprinter_alloc(struct usb_function_instance *fi)
@@ -1400,11 +1275,12 @@ static struct usb_function *gprinter_alloc(struct usb_function_instance *fi)
mutex_unlock(&opts->lock);
dev->function.name = "printer";
- dev->function.bind = printer_func_bind;
+ dev->function.prep_descs = printer_func_prep_descs;
+ dev->function.prep_vendor_descs = printer_func_prep_vendor_descs;
dev->function.setup = printer_func_setup;
dev->function.unbind = printer_func_unbind;
dev->function.set_alt = printer_func_set_alt;
- dev->function.disable = printer_func_disable;
+ dev->function.clear_alt = printer_func_clear_alt;
dev->function.req_match = gprinter_req_match;
dev->function.free_func = gprinter_free;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 08/43] usb: gadget: composite: introduce new USB function ops |
| Message-ID | <qY52I-212-59@gated-at.bofh.it> |
| In reply to | #1325342 |
Introduce two new USB function operations:
1. prep_descs() prepares and assigns entity (interface and endpoint)
descriptors to USB function. It's mandatory, in the new function API,
as each USB function should have at least minimalistic set of entity
descriptors. The minimum is single inferface with one altsetting with
no endpoins (ep0 only). Descriptors assigned to function in prep_descs()
callback are used during bind procedure.
2. prep_vendor_descs() - prepares and assigns class and vendor specific
descriptors to function. This function is called after binding function
to UDC hardware, which means that interface numbers and endpoint addresses
are already assigned so that function can use these values to prepare
class or vendor specific descriptors and attach them to function.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
include/linux/usb/composite.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 91948c7..7ede101 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -293,6 +293,10 @@ struct usb_os_desc_table {
* can expose more than one interface. If an interface is a member of
* an IAD, only the first interface of IAD has its entry in the table.
* @os_desc_n: Number of entries in os_desc_table
+ * @prep_descs: Returns standard function descriptors (interface and endpoint
+ * descritptors).
+ * @prep_vendor_descs: Attaches vendor or class specific descriptors to
+ * standard descriptors.
* @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.
@@ -361,6 +365,10 @@ struct usb_function {
* Related: unbind() may kfree() but bind() won't...
*/
+ /* new function API*/
+ int (*prep_descs)(struct usb_function *);
+ int (*prep_vendor_descs)(struct usb_function *);
+
/* configuration management: bind/unbind */
int (*bind)(struct usb_configuration *,
struct usb_function *);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Robert Baldyga <r.baldyga@samsung.com> |
|---|---|
| Date | 2016-02-03 13:50 +0100 |
| Subject | [PATCH v4 35/43] usb: gadget: f_uac1: conversion to new API |
| Message-ID | <qY52I-212-57@gated-at.bofh.it> |
| In reply to | #1325342 |
Generate descriptors in new format and attach them to USB function in
prep_descs(). Implement prep_vendor_descs() to supply class specific
descriptors. Change set_alt() implementation and implement clear_alt()
operation. Remove boilerplate code.
Signed-off-by: Robert Baldyga <r.baldyga@samsung.com>
---
drivers/usb/gadget/function/f_uac1.c | 134 +++++++++++++++--------------------
1 file changed, 58 insertions(+), 76 deletions(-)
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 6a2346b..2faf4e4 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -189,24 +189,17 @@ static struct uac_iso_endpoint_descriptor as_iso_out_desc = {
.wLockDelay = __constant_cpu_to_le16(1),
};
-static struct usb_descriptor_header *f_audio_desc[] = {
- (struct usb_descriptor_header *)&ac_interface_desc,
- (struct usb_descriptor_header *)&ac_header_desc,
+USB_COMPOSITE_ENDPOINT(ep_out, &as_out_ep_desc,
+ &as_out_ep_desc, NULL, NULL);
- (struct usb_descriptor_header *)&input_terminal_desc,
- (struct usb_descriptor_header *)&output_terminal_desc,
- (struct usb_descriptor_header *)&feature_unit_desc,
+USB_COMPOSITE_ALTSETTING(intf0alt0, &ac_interface_desc);
+USB_COMPOSITE_ALTSETTING(intf1alt0, &as_interface_alt_0_desc);
+USB_COMPOSITE_ALTSETTING(intf1alt1, &as_interface_alt_1_desc, &ep_out);
- (struct usb_descriptor_header *)&as_interface_alt_0_desc,
- (struct usb_descriptor_header *)&as_interface_alt_1_desc,
- (struct usb_descriptor_header *)&as_header_desc,
+USB_COMPOSITE_INTERFACE(intf0, &intf0alt0);
+USB_COMPOSITE_INTERFACE(intf1, &intf1alt0, &intf1alt1);
- (struct usb_descriptor_header *)&as_type_i_desc,
-
- (struct usb_descriptor_header *)&as_out_ep_desc,
- (struct usb_descriptor_header *)&as_iso_out_desc,
- NULL,
-};
+USB_COMPOSITE_DESCRIPTORS(uac1_descs, &intf0, &intf1);
enum {
STR_AC_IF,
@@ -573,7 +566,7 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
{
struct f_audio *audio = func_to_audio(f);
struct usb_composite_dev *cdev = f->config->cdev;
- struct usb_ep *out_ep = audio->out_ep;
+ struct usb_ep *out_ep;
struct usb_request *req;
struct f_uac1_opts *opts;
int req_buf_size, req_count, audio_buf_size;
@@ -588,11 +581,12 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
if (intf == 1) {
if (alt == 1) {
- err = config_ep_by_speed(cdev->gadget, f, out_ep);
- if (err)
- return err;
+ out_ep = usb_function_get_ep(f, intf, 0);
+ if (!out_ep)
+ return -ENODEV;
+
+ audio->out_ep = out_ep;
- usb_ep_enable(out_ep);
audio->copy_buf = f_audio_buffer_alloc(audio_buf_size);
if (IS_ERR(audio->copy_buf))
return -ENOMEM;
@@ -636,7 +630,8 @@ static int f_audio_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
return err;
}
-static void f_audio_disable(struct usb_function *f)
+static void f_audio_clear_alt(struct usb_function *f,
+ unsigned intf, unsigned alt)
{
return;
}
@@ -664,25 +659,11 @@ static void f_audio_build_desc(struct f_audio *audio)
}
/* audio function driver setup/binding */
-static int
-f_audio_bind(struct usb_configuration *c, struct usb_function *f)
+static int f_audio_prep_descs(struct usb_function *f)
{
- struct usb_composite_dev *cdev = c->cdev;
- struct f_audio *audio = func_to_audio(f);
+ struct usb_composite_dev *cdev = f->config->cdev;
struct usb_string *us;
- int status;
- struct usb_ep *ep = NULL;
- struct f_uac1_opts *audio_opts;
- audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst);
- audio->card.gadget = c->cdev->gadget;
- /* set up ASLA audio devices */
- if (!audio_opts->bound) {
- status = gaudio_setup(&audio->card);
- if (status < 0)
- return status;
- audio_opts->bound = true;
- }
us = usb_gstrings_attach(cdev, uac1_strings, ARRAY_SIZE(strings_uac1));
if (IS_ERR(us))
return PTR_ERR(us);
@@ -694,41 +675,47 @@ f_audio_bind(struct usb_configuration *c, struct usb_function *f)
as_interface_alt_0_desc.iInterface = us[STR_AS_IF_ALT0].id;
as_interface_alt_1_desc.iInterface = us[STR_AS_IF_ALT1].id;
+ return usb_function_set_descs(f, &uac1_descs);
+}
+
+static int f_audio_prep_vendor_descs(struct usb_function *f)
+{
+ struct usb_composite_dev *cdev = f->config->cdev;
+ struct f_audio *audio = func_to_audio(f);
+ struct f_uac1_opts *audio_opts;
+ int status;
+
+ audio_opts = container_of(f->fi, struct f_uac1_opts, func_inst);
+ audio->card.gadget = cdev->gadget;
+
+ /* set up ASLA audio devices */
+ if (!audio_opts->bound) {
+ status = gaudio_setup(&audio->card);
+ if (status < 0)
+ return status;
+ audio_opts->bound = true;
+ }
f_audio_build_desc(audio);
- /* allocate instance-specific interface IDs, and patch descriptors */
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- ac_interface_desc.bInterfaceNumber = status;
-
- status = usb_interface_id(c, f);
- if (status < 0)
- goto fail;
- as_interface_alt_0_desc.bInterfaceNumber = status;
- as_interface_alt_1_desc.bInterfaceNumber = status;
-
- status = -ENODEV;
-
- /* allocate instance-specific endpoints */
- ep = usb_ep_autoconfig(cdev->gadget, &as_out_ep_desc);
- if (!ep)
- goto fail;
- audio->out_ep = ep;
- audio->out_ep->desc = &as_out_ep_desc;
-
- status = -ENOMEM;
-
- /* copy descriptors, and track endpoint copies */
- status = usb_assign_descriptors(f, f_audio_desc, f_audio_desc, NULL);
- if (status)
- goto fail;
- return 0;
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&ac_header_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&input_terminal_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&output_terminal_desc);
+ usb_altset_add_vendor_desc(f, 0, 0,
+ (struct usb_descriptor_header *)&feature_unit_desc);
-fail:
- gaudio_cleanup(&audio->card);
- return status;
+ usb_altset_add_vendor_desc(f, 1, 1,
+ (struct usb_descriptor_header *)&as_header_desc);
+ usb_altset_add_vendor_desc(f, 1, 1,
+ (struct usb_descriptor_header *)&as_type_i_desc);
+
+ usb_ep_add_vendor_desc(f, 1, 1, 0,
+ (struct usb_descriptor_header *)&as_iso_out_desc);
+
+ return 0;
}
/*-------------------------------------------------------------------------*/
@@ -938,11 +925,6 @@ static void f_audio_free(struct usb_function *f)
mutex_unlock(&opts->lock);
}
-static void f_audio_unbind(struct usb_configuration *c, struct usb_function *f)
-{
- usb_free_all_descriptors(f);
-}
-
static struct usb_function *f_audio_alloc(struct usb_function_instance *fi)
{
struct f_audio *audio;
@@ -962,11 +944,11 @@ static struct usb_function *f_audio_alloc(struct usb_function_instance *fi)
INIT_LIST_HEAD(&audio->play_queue);
spin_lock_init(&audio->lock);
- audio->card.func.bind = f_audio_bind;
- audio->card.func.unbind = f_audio_unbind;
+ audio->card.func.prep_descs = f_audio_prep_descs;
+ audio->card.func.prep_vendor_descs = f_audio_prep_vendor_descs;
audio->card.func.set_alt = f_audio_set_alt;
+ audio->card.func.clear_alt = f_audio_clear_alt;
audio->card.func.setup = f_audio_setup;
- audio->card.func.disable = f_audio_disable;
audio->card.func.free_func = f_audio_free;
control_selector_init(audio);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | linux.kernel
csiph-web