2017-11-03 17:28:30 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-06-20 07:55:23 +07:00
|
|
|
/*
|
|
|
|
* f_sourcesink.c - USB peripheral source/sink configuration driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2008 David Brownell
|
|
|
|
* Copyright (C) 2008 by Nokia Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define VERBOSE_DEBUG */
|
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2008-06-20 07:55:23 +07:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
2011-07-04 03:09:31 +07:00
|
|
|
#include <linux/module.h>
|
2012-12-24 03:10:01 +07:00
|
|
|
#include <linux/usb/composite.h>
|
|
|
|
#include <linux/err.h>
|
2008-06-20 07:55:23 +07:00
|
|
|
|
|
|
|
#include "g_zero.h"
|
2013-11-07 14:41:26 +07:00
|
|
|
#include "u_f.h"
|
2008-06-20 07:55:23 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* SOURCE/SINK FUNCTION ... a primary testing vehicle for USB peripheral
|
|
|
|
* controller drivers.
|
|
|
|
*
|
|
|
|
* This just sinks bulk packets OUT to the peripheral and sources them IN
|
|
|
|
* to the host, optionally with specific data patterns for integrity tests.
|
|
|
|
* As such it supports basic functionality and load tests.
|
|
|
|
*
|
|
|
|
* In terms of control messaging, this supports all the standard requests
|
|
|
|
* plus two that support control-OUT tests. If the optional "autoresume"
|
|
|
|
* mode is enabled, it provides good functional coverage for the "USBCV"
|
|
|
|
* test harness from USB-IF.
|
|
|
|
*/
|
|
|
|
struct f_sourcesink {
|
|
|
|
struct usb_function function;
|
|
|
|
|
|
|
|
struct usb_ep *in_ep;
|
|
|
|
struct usb_ep *out_ep;
|
2012-04-17 04:19:06 +07:00
|
|
|
struct usb_ep *iso_in_ep;
|
|
|
|
struct usb_ep *iso_out_ep;
|
|
|
|
int cur_alt;
|
2015-10-14 21:07:14 +07:00
|
|
|
|
|
|
|
unsigned pattern;
|
|
|
|
unsigned isoc_interval;
|
|
|
|
unsigned isoc_maxpacket;
|
|
|
|
unsigned isoc_mult;
|
|
|
|
unsigned isoc_maxburst;
|
|
|
|
unsigned buflen;
|
2015-11-19 14:02:16 +07:00
|
|
|
unsigned bulk_qlen;
|
|
|
|
unsigned iso_qlen;
|
2008-06-20 07:55:23 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
|
|
|
|
{
|
|
|
|
return container_of(f, struct f_sourcesink, function);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
static struct usb_interface_descriptor source_sink_intf_alt0 = {
|
|
|
|
.bLength = USB_DT_INTERFACE_SIZE,
|
2008-06-20 07:55:23 +07:00
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
.bAlternateSetting = 0,
|
2008-06-20 07:55:23 +07:00
|
|
|
.bNumEndpoints = 2,
|
|
|
|
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
|
2012-04-17 04:19:06 +07:00
|
|
|
/* .iInterface = DYNAMIC */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_interface_descriptor source_sink_intf_alt1 = {
|
|
|
|
.bLength = USB_DT_INTERFACE_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
|
|
|
.bAlternateSetting = 1,
|
|
|
|
.bNumEndpoints = 4,
|
|
|
|
.bInterfaceClass = USB_CLASS_VENDOR_SPEC,
|
|
|
|
/* .iInterface = DYNAMIC */
|
2008-06-20 07:55:23 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* full speed support: */
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor fs_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor fs_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
static struct usb_endpoint_descriptor fs_iso_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1023),
|
|
|
|
.bInterval = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor fs_iso_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1023),
|
|
|
|
.bInterval = 4,
|
|
|
|
};
|
|
|
|
|
2008-06-20 07:55:23 +07:00
|
|
|
static struct usb_descriptor_header *fs_source_sink_descs[] = {
|
2012-04-17 04:19:06 +07:00
|
|
|
(struct usb_descriptor_header *) &source_sink_intf_alt0,
|
2008-06-20 07:55:23 +07:00
|
|
|
(struct usb_descriptor_header *) &fs_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &fs_source_desc,
|
2012-04-17 04:19:06 +07:00
|
|
|
(struct usb_descriptor_header *) &source_sink_intf_alt1,
|
|
|
|
#define FS_ALT_IFC_1_OFFSET 3
|
|
|
|
(struct usb_descriptor_header *) &fs_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &fs_source_desc,
|
|
|
|
(struct usb_descriptor_header *) &fs_iso_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &fs_iso_source_desc,
|
2008-06-20 07:55:23 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* high speed support: */
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor hs_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
2009-02-12 05:11:36 +07:00
|
|
|
.wMaxPacketSize = cpu_to_le16(512),
|
2008-06-20 07:55:23 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor hs_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
2009-02-12 05:11:36 +07:00
|
|
|
.wMaxPacketSize = cpu_to_le16(512),
|
2008-06-20 07:55:23 +07:00
|
|
|
};
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
static struct usb_endpoint_descriptor hs_iso_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
.bInterval = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor hs_iso_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
.bInterval = 4,
|
|
|
|
};
|
|
|
|
|
2008-06-20 07:55:23 +07:00
|
|
|
static struct usb_descriptor_header *hs_source_sink_descs[] = {
|
2012-04-17 04:19:06 +07:00
|
|
|
(struct usb_descriptor_header *) &source_sink_intf_alt0,
|
2008-06-20 07:55:23 +07:00
|
|
|
(struct usb_descriptor_header *) &hs_source_desc,
|
|
|
|
(struct usb_descriptor_header *) &hs_sink_desc,
|
2012-04-17 04:19:06 +07:00
|
|
|
(struct usb_descriptor_header *) &source_sink_intf_alt1,
|
|
|
|
#define HS_ALT_IFC_1_OFFSET 3
|
|
|
|
(struct usb_descriptor_header *) &hs_source_desc,
|
|
|
|
(struct usb_descriptor_header *) &hs_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &hs_iso_source_desc,
|
|
|
|
(struct usb_descriptor_header *) &hs_iso_sink_desc,
|
2008-06-20 07:55:23 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2011-07-03 21:29:31 +07:00
|
|
|
/* super speed support: */
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor ss_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
2013-12-16 16:44:43 +07:00
|
|
|
static struct usb_ss_ep_comp_descriptor ss_source_comp_desc = {
|
2011-07-03 21:29:31 +07:00
|
|
|
.bLength = USB_DT_SS_EP_COMP_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
|
2012-04-17 04:19:06 +07:00
|
|
|
|
2011-07-03 21:29:31 +07:00
|
|
|
.bMaxBurst = 0,
|
|
|
|
.bmAttributes = 0,
|
|
|
|
.wBytesPerInterval = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor ss_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
2013-12-16 16:44:43 +07:00
|
|
|
static struct usb_ss_ep_comp_descriptor ss_sink_comp_desc = {
|
2011-07-03 21:29:31 +07:00
|
|
|
.bLength = USB_DT_SS_EP_COMP_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
|
2012-04-17 04:19:06 +07:00
|
|
|
|
2011-07-03 21:29:31 +07:00
|
|
|
.bMaxBurst = 0,
|
|
|
|
.bmAttributes = 0,
|
|
|
|
.wBytesPerInterval = 0,
|
|
|
|
};
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
static struct usb_endpoint_descriptor ss_iso_source_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
.bInterval = 4,
|
|
|
|
};
|
|
|
|
|
2013-12-16 16:44:43 +07:00
|
|
|
static struct usb_ss_ep_comp_descriptor ss_iso_source_comp_desc = {
|
2012-04-17 04:19:06 +07:00
|
|
|
.bLength = USB_DT_SS_EP_COMP_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
|
|
|
|
|
|
|
|
.bMaxBurst = 0,
|
|
|
|
.bmAttributes = 0,
|
|
|
|
.wBytesPerInterval = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_endpoint_descriptor ss_iso_sink_desc = {
|
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_ISOC,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
.bInterval = 4,
|
|
|
|
};
|
|
|
|
|
2013-12-16 16:44:43 +07:00
|
|
|
static struct usb_ss_ep_comp_descriptor ss_iso_sink_comp_desc = {
|
2012-04-17 04:19:06 +07:00
|
|
|
.bLength = USB_DT_SS_EP_COMP_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
|
|
|
|
|
|
|
|
.bMaxBurst = 0,
|
|
|
|
.bmAttributes = 0,
|
|
|
|
.wBytesPerInterval = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
2011-07-03 21:29:31 +07:00
|
|
|
static struct usb_descriptor_header *ss_source_sink_descs[] = {
|
2012-04-17 04:19:06 +07:00
|
|
|
(struct usb_descriptor_header *) &source_sink_intf_alt0,
|
2011-07-03 21:29:31 +07:00
|
|
|
(struct usb_descriptor_header *) &ss_source_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_source_comp_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_sink_comp_desc,
|
2012-04-17 04:19:06 +07:00
|
|
|
(struct usb_descriptor_header *) &source_sink_intf_alt1,
|
|
|
|
#define SS_ALT_IFC_1_OFFSET 5
|
|
|
|
(struct usb_descriptor_header *) &ss_source_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_source_comp_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_sink_comp_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_iso_source_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_iso_source_comp_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_iso_sink_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_iso_sink_comp_desc,
|
2011-07-03 21:29:31 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2008-06-20 07:55:23 +07:00
|
|
|
/* function-specific strings: */
|
|
|
|
|
|
|
|
static struct usb_string strings_sourcesink[] = {
|
|
|
|
[0].s = "source and sink data",
|
|
|
|
{ } /* end of list */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings stringtab_sourcesink = {
|
|
|
|
.language = 0x0409, /* en-us */
|
|
|
|
.strings = strings_sourcesink,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings *sourcesink_strings[] = {
|
|
|
|
&stringtab_sourcesink,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2013-11-07 14:41:26 +07:00
|
|
|
static inline struct usb_request *ss_alloc_ep_req(struct usb_ep *ep, int len)
|
2012-12-24 03:10:01 +07:00
|
|
|
{
|
2016-08-24 00:24:49 +07:00
|
|
|
return alloc_ep_req(ep, len);
|
2012-12-24 03:10:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_ep(struct usb_composite_dev *cdev, struct usb_ep *ep)
|
|
|
|
{
|
|
|
|
int value;
|
|
|
|
|
2015-09-16 17:10:56 +07:00
|
|
|
value = usb_ep_disable(ep);
|
|
|
|
if (value < 0)
|
|
|
|
DBG(cdev, "disable %s --> %d\n", ep->name, value);
|
2012-12-24 03:10:01 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void disable_endpoints(struct usb_composite_dev *cdev,
|
|
|
|
struct usb_ep *in, struct usb_ep *out,
|
2015-03-11 22:00:05 +07:00
|
|
|
struct usb_ep *iso_in, struct usb_ep *iso_out)
|
2012-12-24 03:10:01 +07:00
|
|
|
{
|
|
|
|
disable_ep(cdev, in);
|
|
|
|
disable_ep(cdev, out);
|
|
|
|
if (iso_in)
|
|
|
|
disable_ep(cdev, iso_in);
|
|
|
|
if (iso_out)
|
|
|
|
disable_ep(cdev, iso_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2008-06-20 07:55:23 +07:00
|
|
|
sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct usb_composite_dev *cdev = c->cdev;
|
|
|
|
struct f_sourcesink *ss = func_to_ss(f);
|
|
|
|
int id;
|
2012-10-23 03:15:06 +07:00
|
|
|
int ret;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
|
|
|
/* allocate interface ID(s) */
|
|
|
|
id = usb_interface_id(c, f);
|
|
|
|
if (id < 0)
|
|
|
|
return id;
|
2012-04-17 04:19:06 +07:00
|
|
|
source_sink_intf_alt0.bInterfaceNumber = id;
|
|
|
|
source_sink_intf_alt1.bInterfaceNumber = id;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
/* allocate bulk endpoints */
|
2008-06-20 07:55:23 +07:00
|
|
|
ss->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc);
|
|
|
|
if (!ss->in_ep) {
|
|
|
|
autoconf_fail:
|
|
|
|
ERROR(cdev, "%s: can't autoconfigure on %s\n",
|
|
|
|
f->name, cdev->gadget->name);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
ss->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_sink_desc);
|
|
|
|
if (!ss->out_ep)
|
|
|
|
goto autoconf_fail;
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
/* sanity check the isoc module parameters */
|
2015-10-14 21:07:14 +07:00
|
|
|
if (ss->isoc_interval < 1)
|
|
|
|
ss->isoc_interval = 1;
|
|
|
|
if (ss->isoc_interval > 16)
|
|
|
|
ss->isoc_interval = 16;
|
|
|
|
if (ss->isoc_mult > 2)
|
|
|
|
ss->isoc_mult = 2;
|
|
|
|
if (ss->isoc_maxburst > 15)
|
|
|
|
ss->isoc_maxburst = 15;
|
2012-04-17 04:19:06 +07:00
|
|
|
|
|
|
|
/* fill in the FS isoc descriptors from the module parameters */
|
2015-10-14 21:07:14 +07:00
|
|
|
fs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
|
|
|
|
1023 : ss->isoc_maxpacket;
|
|
|
|
fs_iso_source_desc.bInterval = ss->isoc_interval;
|
|
|
|
fs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket > 1023 ?
|
|
|
|
1023 : ss->isoc_maxpacket;
|
|
|
|
fs_iso_sink_desc.bInterval = ss->isoc_interval;
|
2012-04-17 04:19:06 +07:00
|
|
|
|
|
|
|
/* allocate iso endpoints */
|
|
|
|
ss->iso_in_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_source_desc);
|
|
|
|
if (!ss->iso_in_ep)
|
|
|
|
goto no_iso;
|
|
|
|
|
|
|
|
ss->iso_out_ep = usb_ep_autoconfig(cdev->gadget, &fs_iso_sink_desc);
|
2015-09-16 17:10:56 +07:00
|
|
|
if (!ss->iso_out_ep) {
|
|
|
|
usb_ep_autoconfig_release(ss->iso_in_ep);
|
2012-04-17 04:19:06 +07:00
|
|
|
ss->iso_in_ep = NULL;
|
|
|
|
no_iso:
|
|
|
|
/*
|
|
|
|
* We still want to work even if the UDC doesn't have isoc
|
|
|
|
* endpoints, so null out the alt interface that contains
|
|
|
|
* them and continue.
|
|
|
|
*/
|
|
|
|
fs_source_sink_descs[FS_ALT_IFC_1_OFFSET] = NULL;
|
|
|
|
hs_source_sink_descs[HS_ALT_IFC_1_OFFSET] = NULL;
|
|
|
|
ss_source_sink_descs[SS_ALT_IFC_1_OFFSET] = NULL;
|
|
|
|
}
|
|
|
|
|
2015-10-14 21:07:14 +07:00
|
|
|
if (ss->isoc_maxpacket > 1024)
|
|
|
|
ss->isoc_maxpacket = 1024;
|
2012-04-17 04:19:06 +07:00
|
|
|
|
2008-06-20 07:55:23 +07:00
|
|
|
/* support high speed hardware */
|
2012-10-23 03:15:06 +07:00
|
|
|
hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
|
|
|
|
hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
|
|
|
|
|
|
|
|
/*
|
2015-03-11 22:00:05 +07:00
|
|
|
* Fill in the HS isoc descriptors from the module parameters.
|
|
|
|
* We assume that the user knows what they are doing and won't
|
|
|
|
* give parameters that their UDC doesn't support.
|
2012-10-23 03:15:06 +07:00
|
|
|
*/
|
2015-10-14 21:07:14 +07:00
|
|
|
hs_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket;
|
|
|
|
hs_iso_source_desc.wMaxPacketSize |= ss->isoc_mult << 11;
|
|
|
|
hs_iso_source_desc.bInterval = ss->isoc_interval;
|
2012-10-23 03:15:06 +07:00
|
|
|
hs_iso_source_desc.bEndpointAddress =
|
|
|
|
fs_iso_source_desc.bEndpointAddress;
|
|
|
|
|
2015-10-14 21:07:14 +07:00
|
|
|
hs_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket;
|
|
|
|
hs_iso_sink_desc.wMaxPacketSize |= ss->isoc_mult << 11;
|
|
|
|
hs_iso_sink_desc.bInterval = ss->isoc_interval;
|
2012-10-23 03:15:06 +07:00
|
|
|
hs_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2011-07-03 21:29:31 +07:00
|
|
|
/* support super speed hardware */
|
2012-10-23 03:15:06 +07:00
|
|
|
ss_source_desc.bEndpointAddress =
|
|
|
|
fs_source_desc.bEndpointAddress;
|
|
|
|
ss_sink_desc.bEndpointAddress =
|
|
|
|
fs_sink_desc.bEndpointAddress;
|
|
|
|
|
|
|
|
/*
|
2015-03-11 22:00:05 +07:00
|
|
|
* Fill in the SS isoc descriptors from the module parameters.
|
|
|
|
* We assume that the user knows what they are doing and won't
|
|
|
|
* give parameters that their UDC doesn't support.
|
2012-10-23 03:15:06 +07:00
|
|
|
*/
|
2015-10-14 21:07:14 +07:00
|
|
|
ss_iso_source_desc.wMaxPacketSize = ss->isoc_maxpacket;
|
|
|
|
ss_iso_source_desc.bInterval = ss->isoc_interval;
|
|
|
|
ss_iso_source_comp_desc.bmAttributes = ss->isoc_mult;
|
|
|
|
ss_iso_source_comp_desc.bMaxBurst = ss->isoc_maxburst;
|
|
|
|
ss_iso_source_comp_desc.wBytesPerInterval = ss->isoc_maxpacket *
|
|
|
|
(ss->isoc_mult + 1) * (ss->isoc_maxburst + 1);
|
2012-10-23 03:15:06 +07:00
|
|
|
ss_iso_source_desc.bEndpointAddress =
|
|
|
|
fs_iso_source_desc.bEndpointAddress;
|
|
|
|
|
2015-10-14 21:07:14 +07:00
|
|
|
ss_iso_sink_desc.wMaxPacketSize = ss->isoc_maxpacket;
|
|
|
|
ss_iso_sink_desc.bInterval = ss->isoc_interval;
|
|
|
|
ss_iso_sink_comp_desc.bmAttributes = ss->isoc_mult;
|
|
|
|
ss_iso_sink_comp_desc.bMaxBurst = ss->isoc_maxburst;
|
|
|
|
ss_iso_sink_comp_desc.wBytesPerInterval = ss->isoc_maxpacket *
|
|
|
|
(ss->isoc_mult + 1) * (ss->isoc_maxburst + 1);
|
2012-10-23 03:15:06 +07:00
|
|
|
ss_iso_sink_desc.bEndpointAddress = fs_iso_sink_desc.bEndpointAddress;
|
|
|
|
|
|
|
|
ret = usb_assign_descriptors(f, fs_source_sink_descs,
|
2016-02-06 08:06:07 +07:00
|
|
|
hs_source_sink_descs, ss_source_sink_descs, NULL);
|
2012-10-23 03:15:06 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-07-03 21:29:31 +07:00
|
|
|
|
2015-03-11 22:00:05 +07:00
|
|
|
DBG(cdev, "%s speed %s: IN/%s, OUT/%s, ISO-IN/%s, ISO-OUT/%s\n",
|
2011-07-03 21:29:31 +07:00
|
|
|
(gadget_is_superspeed(c->cdev->gadget) ? "super" :
|
|
|
|
(gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full")),
|
2012-04-17 04:19:06 +07:00
|
|
|
f->name, ss->in_ep->name, ss->out_ep->name,
|
|
|
|
ss->iso_in_ep ? ss->iso_in_ep->name : "<none>",
|
2015-03-11 22:00:05 +07:00
|
|
|
ss->iso_out_ep ? ss->iso_out_ep->name : "<none>");
|
2008-06-20 07:55:23 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-24 03:10:01 +07:00
|
|
|
sourcesink_free_func(struct usb_function *f)
|
2008-06-20 07:55:23 +07:00
|
|
|
{
|
2013-11-07 14:41:28 +07:00
|
|
|
struct f_ss_opts *opts;
|
|
|
|
|
|
|
|
opts = container_of(f->fi, struct f_ss_opts, func_inst);
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
opts->refcnt--;
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
2012-10-23 03:15:06 +07:00
|
|
|
usb_free_all_descriptors(f);
|
2008-06-20 07:55:23 +07:00
|
|
|
kfree(func_to_ss(f));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* optionally require specific source/sink data patterns */
|
|
|
|
static int check_read_data(struct f_sourcesink *ss, struct usb_request *req)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
u8 *buf = req->buf;
|
|
|
|
struct usb_composite_dev *cdev = ss->function.config->cdev;
|
2015-09-01 08:48:02 +07:00
|
|
|
int max_packet_size = le16_to_cpu(ss->out_ep->desc->wMaxPacketSize);
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2015-10-14 21:07:14 +07:00
|
|
|
if (ss->pattern == 2)
|
2012-04-17 04:19:06 +07:00
|
|
|
return 0;
|
|
|
|
|
2008-06-20 07:55:23 +07:00
|
|
|
for (i = 0; i < req->actual; i++, buf++) {
|
2015-10-14 21:07:14 +07:00
|
|
|
switch (ss->pattern) {
|
2008-06-20 07:55:23 +07:00
|
|
|
|
|
|
|
/* all-zeroes has no synchronization issues */
|
|
|
|
case 0:
|
|
|
|
if (*buf == 0)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* "mod63" stays in sync with short-terminated transfers,
|
|
|
|
* OR otherwise when host and gadget agree on how large
|
|
|
|
* each usb transfer request should be. Resync is done
|
|
|
|
* with set_interface or set_config. (We *WANT* it to
|
|
|
|
* get quickly out of sync if controllers or their drivers
|
2012-04-17 04:19:06 +07:00
|
|
|
* stutter for any reason, including buffer duplication...)
|
2008-06-20 07:55:23 +07:00
|
|
|
*/
|
|
|
|
case 1:
|
2015-09-01 08:48:02 +07:00
|
|
|
if (*buf == (u8)((i % max_packet_size) % 63))
|
2008-06-20 07:55:23 +07:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ERROR(cdev, "bad OUT byte, buf[%d] = %d\n", i, *buf);
|
|
|
|
usb_ep_set_halt(ss->out_ep);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void reinit_write_data(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
u8 *buf = req->buf;
|
2015-09-01 08:48:02 +07:00
|
|
|
int max_packet_size = le16_to_cpu(ep->desc->wMaxPacketSize);
|
2015-10-14 21:07:14 +07:00
|
|
|
struct f_sourcesink *ss = ep->driver_data;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2015-10-14 21:07:14 +07:00
|
|
|
switch (ss->pattern) {
|
2008-06-20 07:55:23 +07:00
|
|
|
case 0:
|
|
|
|
memset(req->buf, 0, req->length);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
for (i = 0; i < req->length; i++)
|
2015-09-01 08:48:02 +07:00
|
|
|
*buf++ = (u8) ((i % max_packet_size) % 63);
|
2008-06-20 07:55:23 +07:00
|
|
|
break;
|
2012-04-17 04:19:06 +07:00
|
|
|
case 2:
|
|
|
|
break;
|
2008-06-20 07:55:23 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void source_sink_complete(struct usb_ep *ep, struct usb_request *req)
|
|
|
|
{
|
2012-04-17 04:19:06 +07:00
|
|
|
struct usb_composite_dev *cdev;
|
|
|
|
struct f_sourcesink *ss = ep->driver_data;
|
|
|
|
int status = req->status;
|
|
|
|
|
|
|
|
/* driver_data will be null if ep has been disabled */
|
|
|
|
if (!ss)
|
|
|
|
return;
|
|
|
|
|
|
|
|
cdev = ss->function.config->cdev;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
|
|
|
switch (status) {
|
|
|
|
|
|
|
|
case 0: /* normal completion? */
|
|
|
|
if (ep == ss->out_ep) {
|
|
|
|
check_read_data(ss, req);
|
2015-10-14 21:07:14 +07:00
|
|
|
if (ss->pattern != 2)
|
2012-04-17 04:19:06 +07:00
|
|
|
memset(req->buf, 0x55, req->length);
|
2012-12-13 21:11:19 +07:00
|
|
|
}
|
2008-06-20 07:55:23 +07:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* this endpoint is normally active while we're configured */
|
|
|
|
case -ECONNABORTED: /* hardware forced ep reset */
|
|
|
|
case -ECONNRESET: /* request dequeued */
|
|
|
|
case -ESHUTDOWN: /* disconnect from host */
|
|
|
|
VDBG(cdev, "%s gone (%d), %d/%d\n", ep->name, status,
|
|
|
|
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
|
|
|
|
* we didn't provide a big enough
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
default:
|
|
|
|
#if 1
|
|
|
|
DBG(cdev, "%s complete --> %d, %d/%d\n", ep->name,
|
|
|
|
status, req->actual, req->length);
|
|
|
|
#endif
|
|
|
|
case -EREMOTEIO: /* short read */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = usb_ep_queue(ep, req, GFP_ATOMIC);
|
|
|
|
if (status) {
|
|
|
|
ERROR(cdev, "kill %s: resubmit %d bytes --> %d\n",
|
|
|
|
ep->name, req->length, status);
|
|
|
|
usb_ep_set_halt(ep);
|
|
|
|
/* FIXME recover later ... somehow */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
static int source_sink_start_ep(struct f_sourcesink *ss, bool is_in,
|
2015-03-11 22:00:05 +07:00
|
|
|
bool is_iso, int speed)
|
2008-06-20 07:55:23 +07:00
|
|
|
{
|
|
|
|
struct usb_ep *ep;
|
|
|
|
struct usb_request *req;
|
2015-11-19 14:02:16 +07:00
|
|
|
int i, size, qlen, status = 0;
|
|
|
|
|
|
|
|
if (is_iso) {
|
|
|
|
switch (speed) {
|
|
|
|
case USB_SPEED_SUPER:
|
|
|
|
size = ss->isoc_maxpacket *
|
|
|
|
(ss->isoc_mult + 1) *
|
|
|
|
(ss->isoc_maxburst + 1);
|
|
|
|
break;
|
|
|
|
case USB_SPEED_HIGH:
|
|
|
|
size = ss->isoc_maxpacket * (ss->isoc_mult + 1);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
size = ss->isoc_maxpacket > 1023 ?
|
|
|
|
1023 : ss->isoc_maxpacket;
|
|
|
|
break;
|
2012-04-17 04:19:06 +07:00
|
|
|
}
|
2015-11-19 14:02:16 +07:00
|
|
|
ep = is_in ? ss->iso_in_ep : ss->iso_out_ep;
|
|
|
|
qlen = ss->iso_qlen;
|
|
|
|
} else {
|
|
|
|
ep = is_in ? ss->in_ep : ss->out_ep;
|
|
|
|
qlen = ss->bulk_qlen;
|
2016-08-24 00:24:49 +07:00
|
|
|
size = ss->buflen;
|
2015-11-19 14:02:16 +07:00
|
|
|
}
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2015-11-19 14:02:16 +07:00
|
|
|
for (i = 0; i < qlen; i++) {
|
|
|
|
req = ss_alloc_ep_req(ep, size);
|
2012-04-17 04:19:06 +07:00
|
|
|
if (!req)
|
|
|
|
return -ENOMEM;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
req->complete = source_sink_complete;
|
|
|
|
if (is_in)
|
|
|
|
reinit_write_data(ep, req);
|
2015-10-14 21:07:14 +07:00
|
|
|
else if (ss->pattern != 2)
|
2012-04-17 04:19:06 +07:00
|
|
|
memset(req->buf, 0x55, req->length);
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
status = usb_ep_queue(ep, req, GFP_ATOMIC);
|
|
|
|
if (status) {
|
|
|
|
struct usb_composite_dev *cdev;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
cdev = ss->function.config->cdev;
|
|
|
|
ERROR(cdev, "start %s%s %s --> %d\n",
|
2015-03-11 22:00:05 +07:00
|
|
|
is_iso ? "ISO-" : "", is_in ? "IN" : "OUT",
|
|
|
|
ep->name, status);
|
2012-04-17 04:19:06 +07:00
|
|
|
free_ep_req(ep, req);
|
2015-11-19 14:02:19 +07:00
|
|
|
return status;
|
2012-04-17 04:19:06 +07:00
|
|
|
}
|
2008-06-20 07:55:23 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_source_sink(struct f_sourcesink *ss)
|
|
|
|
{
|
|
|
|
struct usb_composite_dev *cdev;
|
|
|
|
|
|
|
|
cdev = ss->function.config->cdev;
|
2012-04-17 04:19:06 +07:00
|
|
|
disable_endpoints(cdev, ss->in_ep, ss->out_ep, ss->iso_in_ep,
|
2015-03-11 22:00:05 +07:00
|
|
|
ss->iso_out_ep);
|
2008-06-20 07:55:23 +07:00
|
|
|
VDBG(cdev, "%s disabled\n", ss->function.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2012-04-17 04:19:06 +07:00
|
|
|
enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss,
|
|
|
|
int alt)
|
2008-06-20 07:55:23 +07:00
|
|
|
{
|
|
|
|
int result = 0;
|
2012-04-17 04:19:06 +07:00
|
|
|
int speed = cdev->gadget->speed;
|
2008-06-20 07:55:23 +07:00
|
|
|
struct usb_ep *ep;
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
/* one bulk endpoint writes (sources) zeroes IN (to the host) */
|
2008-06-20 07:55:23 +07:00
|
|
|
ep = ss->in_ep;
|
2011-06-28 20:33:50 +07:00
|
|
|
result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
|
|
|
|
if (result)
|
|
|
|
return result;
|
2011-06-28 20:33:48 +07:00
|
|
|
result = usb_ep_enable(ep);
|
2008-06-20 07:55:23 +07:00
|
|
|
if (result < 0)
|
|
|
|
return result;
|
|
|
|
ep->driver_data = ss;
|
|
|
|
|
2015-03-11 22:00:05 +07:00
|
|
|
result = source_sink_start_ep(ss, true, false, speed);
|
2008-06-20 07:55:23 +07:00
|
|
|
if (result < 0) {
|
|
|
|
fail:
|
|
|
|
ep = ss->in_ep;
|
|
|
|
usb_ep_disable(ep);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
/* one bulk endpoint reads (sinks) anything OUT (from the host) */
|
2008-06-20 07:55:23 +07:00
|
|
|
ep = ss->out_ep;
|
2011-06-28 20:33:50 +07:00
|
|
|
result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
|
|
|
|
if (result)
|
|
|
|
goto fail;
|
2011-06-28 20:33:48 +07:00
|
|
|
result = usb_ep_enable(ep);
|
2008-06-20 07:55:23 +07:00
|
|
|
if (result < 0)
|
|
|
|
goto fail;
|
|
|
|
ep->driver_data = ss;
|
|
|
|
|
2015-03-11 22:00:05 +07:00
|
|
|
result = source_sink_start_ep(ss, false, false, speed);
|
2008-06-20 07:55:23 +07:00
|
|
|
if (result < 0) {
|
2012-04-17 04:19:06 +07:00
|
|
|
fail2:
|
|
|
|
ep = ss->out_ep;
|
2008-06-20 07:55:23 +07:00
|
|
|
usb_ep_disable(ep);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2012-04-17 04:19:06 +07:00
|
|
|
if (alt == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* one iso endpoint writes (sources) zeroes IN (to the host) */
|
|
|
|
ep = ss->iso_in_ep;
|
|
|
|
if (ep) {
|
|
|
|
result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
|
|
|
|
if (result)
|
|
|
|
goto fail2;
|
|
|
|
result = usb_ep_enable(ep);
|
|
|
|
if (result < 0)
|
|
|
|
goto fail2;
|
|
|
|
ep->driver_data = ss;
|
|
|
|
|
2015-03-11 22:00:05 +07:00
|
|
|
result = source_sink_start_ep(ss, true, true, speed);
|
2012-04-17 04:19:06 +07:00
|
|
|
if (result < 0) {
|
|
|
|
fail3:
|
|
|
|
ep = ss->iso_in_ep;
|
2015-09-16 17:10:56 +07:00
|
|
|
if (ep)
|
2012-04-17 04:19:06 +07:00
|
|
|
usb_ep_disable(ep);
|
|
|
|
goto fail2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* one iso endpoint reads (sinks) anything OUT (from the host) */
|
|
|
|
ep = ss->iso_out_ep;
|
|
|
|
if (ep) {
|
|
|
|
result = config_ep_by_speed(cdev->gadget, &(ss->function), ep);
|
|
|
|
if (result)
|
|
|
|
goto fail3;
|
|
|
|
result = usb_ep_enable(ep);
|
|
|
|
if (result < 0)
|
|
|
|
goto fail3;
|
|
|
|
ep->driver_data = ss;
|
|
|
|
|
2015-03-11 22:00:05 +07:00
|
|
|
result = source_sink_start_ep(ss, false, true, speed);
|
2012-04-17 04:19:06 +07:00
|
|
|
if (result < 0) {
|
|
|
|
usb_ep_disable(ep);
|
|
|
|
goto fail3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
ss->cur_alt = alt;
|
|
|
|
|
|
|
|
DBG(cdev, "%s enabled, alt intf %d\n", ss->function.name, alt);
|
2008-06-20 07:55:23 +07:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sourcesink_set_alt(struct usb_function *f,
|
|
|
|
unsigned intf, unsigned alt)
|
|
|
|
{
|
2012-04-17 04:19:06 +07:00
|
|
|
struct f_sourcesink *ss = func_to_ss(f);
|
|
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
2008-06-20 07:55:23 +07:00
|
|
|
|
2015-09-16 17:10:56 +07:00
|
|
|
disable_source_sink(ss);
|
2012-04-17 04:19:06 +07:00
|
|
|
return enable_source_sink(cdev, ss, alt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sourcesink_get_alt(struct usb_function *f, unsigned intf)
|
|
|
|
{
|
|
|
|
struct f_sourcesink *ss = func_to_ss(f);
|
|
|
|
|
|
|
|
return ss->cur_alt;
|
2008-06-20 07:55:23 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sourcesink_disable(struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_sourcesink *ss = func_to_ss(f);
|
|
|
|
|
|
|
|
disable_source_sink(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
2012-12-24 03:10:01 +07:00
|
|
|
|
2012-12-24 03:09:57 +07:00
|
|
|
static int sourcesink_setup(struct usb_function *f,
|
2008-06-20 07:55:23 +07:00
|
|
|
const struct usb_ctrlrequest *ctrl)
|
|
|
|
{
|
2012-12-24 03:09:57 +07:00
|
|
|
struct usb_configuration *c = f->config;
|
2008-06-20 07:55:23 +07:00
|
|
|
struct usb_request *req = c->cdev->req;
|
|
|
|
int value = -EOPNOTSUPP;
|
|
|
|
u16 w_index = le16_to_cpu(ctrl->wIndex);
|
|
|
|
u16 w_value = le16_to_cpu(ctrl->wValue);
|
|
|
|
u16 w_length = le16_to_cpu(ctrl->wLength);
|
|
|
|
|
2012-09-10 20:01:51 +07:00
|
|
|
req->length = USB_COMP_EP0_BUFSIZ;
|
2011-06-24 04:09:49 +07:00
|
|
|
|
2008-06-20 07:55:23 +07:00
|
|
|
/* composite driver infrastructure handles everything except
|
|
|
|
* the two control test requests.
|
|
|
|
*/
|
|
|
|
switch (ctrl->bRequest) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the same vendor-specific requests supported by
|
|
|
|
* Intel's USB 2.0 compliance test devices. We exceed that
|
|
|
|
* device spec by allowing multiple-packet requests.
|
|
|
|
*
|
|
|
|
* NOTE: the Control-OUT data stays in req->buf ... better
|
|
|
|
* would be copying it into a scratch buffer, so that other
|
|
|
|
* requests may safely intervene.
|
|
|
|
*/
|
|
|
|
case 0x5b: /* control WRITE test -- fill the buffer */
|
|
|
|
if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
|
|
|
|
goto unknown;
|
|
|
|
if (w_value || w_index)
|
|
|
|
break;
|
|
|
|
/* just read that many bytes into the buffer */
|
|
|
|
if (w_length > req->length)
|
|
|
|
break;
|
|
|
|
value = w_length;
|
|
|
|
break;
|
|
|
|
case 0x5c: /* control READ test -- return the buffer */
|
|
|
|
if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
|
|
|
|
goto unknown;
|
|
|
|
if (w_value || w_index)
|
|
|
|
break;
|
|
|
|
/* expect those bytes are still in the buffer; send back */
|
|
|
|
if (w_length > req->length)
|
|
|
|
break;
|
|
|
|
value = w_length;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
unknown:
|
|
|
|
VDBG(c->cdev,
|
|
|
|
"unknown control req%02x.%02x v%04x i%04x l%d\n",
|
|
|
|
ctrl->bRequestType, ctrl->bRequest,
|
|
|
|
w_value, w_index, w_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* respond with data transfer or status phase? */
|
|
|
|
if (value >= 0) {
|
|
|
|
VDBG(c->cdev, "source/sink req%02x.%02x v%04x i%04x l%d\n",
|
|
|
|
ctrl->bRequestType, ctrl->bRequest,
|
|
|
|
w_value, w_index, w_length);
|
|
|
|
req->zero = 0;
|
|
|
|
req->length = value;
|
|
|
|
value = usb_ep_queue(c->cdev->gadget->ep0, req, GFP_ATOMIC);
|
|
|
|
if (value < 0)
|
2012-04-17 04:19:06 +07:00
|
|
|
ERROR(c->cdev, "source/sink response, err %d\n",
|
2008-06-20 07:55:23 +07:00
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* device either stalls (value < 0) or reports success */
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2012-12-24 03:10:01 +07:00
|
|
|
static struct usb_function *source_sink_alloc_func(
|
|
|
|
struct usb_function_instance *fi)
|
2012-12-24 03:09:57 +07:00
|
|
|
{
|
2012-12-24 03:10:01 +07:00
|
|
|
struct f_sourcesink *ss;
|
|
|
|
struct f_ss_opts *ss_opts;
|
2012-12-24 03:09:57 +07:00
|
|
|
|
|
|
|
ss = kzalloc(sizeof(*ss), GFP_KERNEL);
|
|
|
|
if (!ss)
|
2012-12-24 03:10:01 +07:00
|
|
|
return NULL;
|
2012-12-24 03:09:57 +07:00
|
|
|
|
2012-12-24 03:10:01 +07:00
|
|
|
ss_opts = container_of(fi, struct f_ss_opts, func_inst);
|
2013-11-07 14:41:28 +07:00
|
|
|
|
|
|
|
mutex_lock(&ss_opts->lock);
|
|
|
|
ss_opts->refcnt++;
|
|
|
|
mutex_unlock(&ss_opts->lock);
|
|
|
|
|
2015-10-14 21:07:14 +07:00
|
|
|
ss->pattern = ss_opts->pattern;
|
|
|
|
ss->isoc_interval = ss_opts->isoc_interval;
|
|
|
|
ss->isoc_maxpacket = ss_opts->isoc_maxpacket;
|
|
|
|
ss->isoc_mult = ss_opts->isoc_mult;
|
|
|
|
ss->isoc_maxburst = ss_opts->isoc_maxburst;
|
|
|
|
ss->buflen = ss_opts->bulk_buflen;
|
2015-11-19 14:02:16 +07:00
|
|
|
ss->bulk_qlen = ss_opts->bulk_qlen;
|
|
|
|
ss->iso_qlen = ss_opts->iso_qlen;
|
2012-12-24 03:09:57 +07:00
|
|
|
|
|
|
|
ss->function.name = "source/sink";
|
|
|
|
ss->function.bind = sourcesink_bind;
|
|
|
|
ss->function.set_alt = sourcesink_set_alt;
|
|
|
|
ss->function.get_alt = sourcesink_get_alt;
|
|
|
|
ss->function.disable = sourcesink_disable;
|
|
|
|
ss->function.setup = sourcesink_setup;
|
2012-12-24 03:10:01 +07:00
|
|
|
ss->function.strings = sourcesink_strings;
|
2012-12-24 03:09:57 +07:00
|
|
|
|
2012-12-24 03:10:01 +07:00
|
|
|
ss->function.free_func = sourcesink_free_func;
|
|
|
|
|
|
|
|
return &ss->function;
|
2012-12-24 03:09:57 +07:00
|
|
|
}
|
|
|
|
|
2013-11-07 14:41:28 +07:00
|
|
|
static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item)
|
|
|
|
{
|
|
|
|
return container_of(to_config_group(item), struct f_ss_opts,
|
|
|
|
func_inst.group);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ss_attr_release(struct config_item *item)
|
|
|
|
{
|
|
|
|
struct f_ss_opts *ss_opts = to_f_ss_opts(item);
|
|
|
|
|
|
|
|
usb_put_function_instance(&ss_opts->func_inst);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct configfs_item_operations ss_item_ops = {
|
|
|
|
.release = ss_attr_release,
|
|
|
|
};
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_pattern_show(struct config_item *item, char *page)
|
2013-11-07 14:41:28 +07:00
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
2015-09-22 02:51:14 +07:00
|
|
|
result = sprintf(page, "%u\n", opts->pattern);
|
2013-11-07 14:41:28 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_pattern_store(struct config_item *item,
|
2013-11-07 14:41:28 +07:00
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int ret;
|
|
|
|
u8 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou8(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (num != 0 && num != 1 && num != 2) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts->pattern = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
CONFIGFS_ATTR(f_ss_opts_, pattern);
|
2013-11-07 14:41:28 +07:00
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_interval_show(struct config_item *item, char *page)
|
2013-11-07 14:41:28 +07:00
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
2015-09-22 02:51:14 +07:00
|
|
|
result = sprintf(page, "%u\n", opts->isoc_interval);
|
2013-11-07 14:41:28 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_interval_store(struct config_item *item,
|
2013-11-07 14:41:28 +07:00
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int ret;
|
|
|
|
u8 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou8(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (num > 16) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts->isoc_interval = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
CONFIGFS_ATTR(f_ss_opts_, isoc_interval);
|
2013-11-07 14:41:28 +07:00
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_maxpacket_show(struct config_item *item, char *page)
|
2013-11-07 14:41:28 +07:00
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
2015-09-22 02:51:14 +07:00
|
|
|
result = sprintf(page, "%u\n", opts->isoc_maxpacket);
|
2013-11-07 14:41:28 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_maxpacket_store(struct config_item *item,
|
2013-11-07 14:41:28 +07:00
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int ret;
|
|
|
|
u16 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou16(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (num > 1024) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts->isoc_maxpacket = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
CONFIGFS_ATTR(f_ss_opts_, isoc_maxpacket);
|
2013-11-07 14:41:28 +07:00
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_mult_show(struct config_item *item, char *page)
|
2013-11-07 14:41:28 +07:00
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
2015-09-22 02:51:14 +07:00
|
|
|
result = sprintf(page, "%u\n", opts->isoc_mult);
|
2013-11-07 14:41:28 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_mult_store(struct config_item *item,
|
2013-11-07 14:41:28 +07:00
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int ret;
|
|
|
|
u8 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou8(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (num > 2) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts->isoc_mult = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
CONFIGFS_ATTR(f_ss_opts_, isoc_mult);
|
2013-11-07 14:41:28 +07:00
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_maxburst_show(struct config_item *item, char *page)
|
2013-11-07 14:41:28 +07:00
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
2015-09-22 02:51:14 +07:00
|
|
|
result = sprintf(page, "%u\n", opts->isoc_maxburst);
|
2013-11-07 14:41:28 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_isoc_maxburst_store(struct config_item *item,
|
2013-11-07 14:41:28 +07:00
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int ret;
|
|
|
|
u8 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou8(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (num > 15) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
opts->isoc_maxburst = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
CONFIGFS_ATTR(f_ss_opts_, isoc_maxburst);
|
2013-11-07 14:41:28 +07:00
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_bulk_buflen_show(struct config_item *item, char *page)
|
2013-11-07 14:41:28 +07:00
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
2015-09-22 02:51:14 +07:00
|
|
|
result = sprintf(page, "%u\n", opts->bulk_buflen);
|
2013-11-07 14:41:28 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
static ssize_t f_ss_opts_bulk_buflen_store(struct config_item *item,
|
2013-11-07 14:41:28 +07:00
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
2015-10-03 20:32:46 +07:00
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
2013-11-07 14:41:28 +07:00
|
|
|
int ret;
|
|
|
|
u32 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou32(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
opts->bulk_buflen = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-10-03 20:32:46 +07:00
|
|
|
CONFIGFS_ATTR(f_ss_opts_, bulk_buflen);
|
2013-11-07 14:41:28 +07:00
|
|
|
|
2015-11-19 14:02:16 +07:00
|
|
|
static ssize_t f_ss_opts_bulk_qlen_show(struct config_item *item, char *page)
|
|
|
|
{
|
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
result = sprintf(page, "%u\n", opts->bulk_qlen);
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t f_ss_opts_bulk_qlen_store(struct config_item *item,
|
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
|
|
|
int ret;
|
|
|
|
u32 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou32(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
opts->bulk_qlen = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIGFS_ATTR(f_ss_opts_, bulk_qlen);
|
|
|
|
|
|
|
|
static ssize_t f_ss_opts_iso_qlen_show(struct config_item *item, char *page)
|
|
|
|
{
|
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
|
|
|
int result;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
result = sprintf(page, "%u\n", opts->iso_qlen);
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t f_ss_opts_iso_qlen_store(struct config_item *item,
|
|
|
|
const char *page, size_t len)
|
|
|
|
{
|
|
|
|
struct f_ss_opts *opts = to_f_ss_opts(item);
|
|
|
|
int ret;
|
|
|
|
u32 num;
|
|
|
|
|
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
if (opts->refcnt) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = kstrtou32(page, 0, &num);
|
|
|
|
if (ret)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
opts->iso_qlen = num;
|
|
|
|
ret = len;
|
|
|
|
end:
|
|
|
|
mutex_unlock(&opts->lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
CONFIGFS_ATTR(f_ss_opts_, iso_qlen);
|
|
|
|
|
2013-11-07 14:41:28 +07:00
|
|
|
static struct configfs_attribute *ss_attrs[] = {
|
2015-10-03 20:32:46 +07:00
|
|
|
&f_ss_opts_attr_pattern,
|
|
|
|
&f_ss_opts_attr_isoc_interval,
|
|
|
|
&f_ss_opts_attr_isoc_maxpacket,
|
|
|
|
&f_ss_opts_attr_isoc_mult,
|
|
|
|
&f_ss_opts_attr_isoc_maxburst,
|
|
|
|
&f_ss_opts_attr_bulk_buflen,
|
2015-11-19 14:02:16 +07:00
|
|
|
&f_ss_opts_attr_bulk_qlen,
|
|
|
|
&f_ss_opts_attr_iso_qlen,
|
2013-11-07 14:41:28 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type ss_func_type = {
|
|
|
|
.ct_item_ops = &ss_item_ops,
|
|
|
|
.ct_attrs = ss_attrs,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2013-04-18 19:43:25 +07:00
|
|
|
static void source_sink_free_instance(struct usb_function_instance *fi)
|
2012-12-24 03:09:57 +07:00
|
|
|
{
|
2012-12-24 03:10:01 +07:00
|
|
|
struct f_ss_opts *ss_opts;
|
|
|
|
|
|
|
|
ss_opts = container_of(fi, struct f_ss_opts, func_inst);
|
|
|
|
kfree(ss_opts);
|
2012-12-24 03:09:57 +07:00
|
|
|
}
|
2012-12-24 03:10:01 +07:00
|
|
|
|
|
|
|
static struct usb_function_instance *source_sink_alloc_inst(void)
|
|
|
|
{
|
|
|
|
struct f_ss_opts *ss_opts;
|
|
|
|
|
|
|
|
ss_opts = kzalloc(sizeof(*ss_opts), GFP_KERNEL);
|
|
|
|
if (!ss_opts)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2013-11-07 14:41:28 +07:00
|
|
|
mutex_init(&ss_opts->lock);
|
2013-04-18 19:43:25 +07:00
|
|
|
ss_opts->func_inst.free_func_inst = source_sink_free_instance;
|
2013-11-07 14:41:28 +07:00
|
|
|
ss_opts->isoc_interval = GZERO_ISOC_INTERVAL;
|
|
|
|
ss_opts->isoc_maxpacket = GZERO_ISOC_MAXPACKET;
|
|
|
|
ss_opts->bulk_buflen = GZERO_BULK_BUFLEN;
|
2015-11-19 14:02:16 +07:00
|
|
|
ss_opts->bulk_qlen = GZERO_SS_BULK_QLEN;
|
|
|
|
ss_opts->iso_qlen = GZERO_SS_ISO_QLEN;
|
2013-11-07 14:41:28 +07:00
|
|
|
|
|
|
|
config_group_init_type_name(&ss_opts->func_inst.group, "",
|
|
|
|
&ss_func_type);
|
|
|
|
|
2012-12-24 03:10:01 +07:00
|
|
|
return &ss_opts->func_inst;
|
|
|
|
}
|
|
|
|
DECLARE_USB_FUNCTION(SourceSink, source_sink_alloc_inst,
|
|
|
|
source_sink_alloc_func);
|
|
|
|
|
|
|
|
static int __init sslb_modinit(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = usb_function_register(&SourceSinkusb_func);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
ret = lb_modinit();
|
|
|
|
if (ret)
|
|
|
|
usb_function_unregister(&SourceSinkusb_func);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
static void __exit sslb_modexit(void)
|
|
|
|
{
|
|
|
|
usb_function_unregister(&SourceSinkusb_func);
|
|
|
|
lb_modexit();
|
|
|
|
}
|
|
|
|
module_init(sslb_modinit);
|
|
|
|
module_exit(sslb_modexit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|