2008-06-20 08:19:32 +07:00
|
|
|
/*
|
|
|
|
* f_subset.c -- "CDC Subset" Ethernet link function driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2005,2008 David Brownell
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
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 08:19:32 +07:00
|
|
|
#include <linux/kernel.h>
|
2013-05-28 14:15:53 +07:00
|
|
|
#include <linux/module.h>
|
2008-06-20 08:19:32 +07:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
|
|
|
|
#include "u_ether.h"
|
2013-05-28 14:15:56 +07:00
|
|
|
#include "u_ether_configfs.h"
|
2013-05-28 14:15:53 +07:00
|
|
|
#include "u_gether.h"
|
2008-06-20 08:19:32 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function packages a simple "CDC Subset" Ethernet port with no real
|
|
|
|
* control mechanisms; just raw data transfer over two bulk endpoints.
|
|
|
|
* The data transfer model is exactly that of CDC Ethernet, which is
|
|
|
|
* why we call it the "CDC Subset".
|
|
|
|
*
|
|
|
|
* Because it's not standardized, this has some interoperability issues.
|
|
|
|
* They mostly relate to driver binding, since the data transfer model is
|
|
|
|
* so simple (CDC Ethernet). The original versions of this protocol used
|
|
|
|
* specific product/vendor IDs: byteswapped IDs for Digital Equipment's
|
|
|
|
* SA-1100 "Itsy" board, which could run Linux 2.4 kernels and supported
|
|
|
|
* daughtercards with USB peripheral connectors. (It was used more often
|
|
|
|
* with other boards, using the Itsy identifiers.) Linux hosts recognized
|
|
|
|
* this with CONFIG_USB_ARMLINUX; these devices have only one configuration
|
|
|
|
* and one interface.
|
|
|
|
*
|
|
|
|
* At some point, MCCI defined a (nonconformant) CDC MDLM variant called
|
|
|
|
* "SAFE", which happens to have a mode which is identical to the "CDC
|
|
|
|
* Subset" in terms of data transfer and lack of control model. This was
|
|
|
|
* adopted by later Sharp Zaurus models, and by some other software which
|
|
|
|
* Linux hosts recognize with CONFIG_USB_NET_ZAURUS.
|
|
|
|
*
|
|
|
|
* Because Microsoft's RNDIS drivers are far from robust, we added a few
|
|
|
|
* descriptors to the CDC Subset code, making this code look like a SAFE
|
|
|
|
* implementation. This lets you use MCCI's host side MS-Windows drivers
|
|
|
|
* if you get fed up with RNDIS. It also makes it easier for composite
|
|
|
|
* drivers to work, since they can use class based binding instead of
|
|
|
|
* caring about specific product and vendor IDs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct f_gether {
|
|
|
|
struct gether port;
|
|
|
|
|
|
|
|
char ethaddr[14];
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline struct f_gether *func_to_geth(struct usb_function *f)
|
|
|
|
{
|
|
|
|
return container_of(f, struct f_gether, port.func);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* "Simple" CDC-subset option is a simple vendor-neutral model that most
|
|
|
|
* full speed controllers can handle: one interface, two bulk endpoints.
|
|
|
|
* To assist host side drivers, we fancy it up a bit, and add descriptors so
|
|
|
|
* some host side drivers will understand it as a "SAFE" variant.
|
|
|
|
*
|
|
|
|
* "SAFE" loosely follows CDC WMC MDLM, violating the spec in various ways.
|
|
|
|
* Data endpoints live in the control interface, there's no data interface.
|
|
|
|
* And it's not used to talk to a cell phone radio.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* interface descriptor: */
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_interface_descriptor subset_data_intf = {
|
2008-06-20 08:19:32 +07:00
|
|
|
.bLength = sizeof subset_data_intf,
|
|
|
|
.bDescriptorType = USB_DT_INTERFACE,
|
|
|
|
|
|
|
|
/* .bInterfaceNumber = DYNAMIC */
|
|
|
|
.bAlternateSetting = 0,
|
|
|
|
.bNumEndpoints = 2,
|
|
|
|
.bInterfaceClass = USB_CLASS_COMM,
|
|
|
|
.bInterfaceSubClass = USB_CDC_SUBCLASS_MDLM,
|
|
|
|
.bInterfaceProtocol = 0,
|
|
|
|
/* .iInterface = DYNAMIC */
|
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_cdc_header_desc mdlm_header_desc = {
|
2008-08-19 07:45:07 +07:00
|
|
|
.bLength = sizeof mdlm_header_desc,
|
2008-06-20 08:19:32 +07:00
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_HEADER_TYPE,
|
|
|
|
|
2009-02-12 05:11:36 +07:00
|
|
|
.bcdCDC = cpu_to_le16(0x0110),
|
2008-06-20 08:19:32 +07:00
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_cdc_mdlm_desc mdlm_desc = {
|
2008-06-20 08:19:32 +07:00
|
|
|
.bLength = sizeof mdlm_desc,
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_MDLM_TYPE,
|
|
|
|
|
2009-02-12 05:11:36 +07:00
|
|
|
.bcdVersion = cpu_to_le16(0x0100),
|
2008-06-20 08:19:32 +07:00
|
|
|
.bGUID = {
|
|
|
|
0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
|
|
|
|
0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* since "usb_cdc_mdlm_detail_desc" is a variable length structure, we
|
|
|
|
* can't really use its struct. All we do here is say that we're using
|
|
|
|
* the submode of "SAFE" which directly matches the CDC Subset.
|
|
|
|
*/
|
2012-03-11 21:08:46 +07:00
|
|
|
static u8 mdlm_detail_desc[] = {
|
2008-06-20 08:19:32 +07:00
|
|
|
6,
|
|
|
|
USB_DT_CS_INTERFACE,
|
|
|
|
USB_CDC_MDLM_DETAIL_TYPE,
|
|
|
|
|
|
|
|
0, /* "SAFE" */
|
|
|
|
0, /* network control capabilities (none) */
|
|
|
|
0, /* network data capabilities ("raw" encapsulation) */
|
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_cdc_ether_desc ether_desc = {
|
2008-06-20 08:19:32 +07:00
|
|
|
.bLength = sizeof ether_desc,
|
|
|
|
.bDescriptorType = USB_DT_CS_INTERFACE,
|
|
|
|
.bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
|
|
|
|
|
|
|
|
/* this descriptor actually adds value, surprise! */
|
|
|
|
/* .iMACAddress = DYNAMIC */
|
2009-02-12 05:11:36 +07:00
|
|
|
.bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
|
|
|
|
.wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
|
|
|
|
.wNumberMCFilters = cpu_to_le16(0),
|
2008-06-20 08:19:32 +07:00
|
|
|
.bNumberPowerFilters = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* full speed support: */
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_endpoint_descriptor fs_subset_in_desc = {
|
2008-06-20 08:19:32 +07:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_IN,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_endpoint_descriptor fs_subset_out_desc = {
|
2008-06-20 08:19:32 +07:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bEndpointAddress = USB_DIR_OUT,
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_descriptor_header *fs_eth_function[] = {
|
2008-06-20 08:19:32 +07:00
|
|
|
(struct usb_descriptor_header *) &subset_data_intf,
|
2008-08-19 07:45:07 +07:00
|
|
|
(struct usb_descriptor_header *) &mdlm_header_desc,
|
2008-06-20 08:19:32 +07:00
|
|
|
(struct usb_descriptor_header *) &mdlm_desc,
|
|
|
|
(struct usb_descriptor_header *) &mdlm_detail_desc,
|
|
|
|
(struct usb_descriptor_header *) ðer_desc,
|
2008-08-19 07:45:07 +07:00
|
|
|
(struct usb_descriptor_header *) &fs_subset_in_desc,
|
|
|
|
(struct usb_descriptor_header *) &fs_subset_out_desc,
|
2008-06-20 08:19:32 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* high speed support: */
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_endpoint_descriptor hs_subset_in_desc = {
|
2008-06-20 08:19:32 +07:00
|
|
|
.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 08:19:32 +07:00
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_endpoint_descriptor hs_subset_out_desc = {
|
2008-06-20 08:19:32 +07:00
|
|
|
.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 08:19:32 +07:00
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_descriptor_header *hs_eth_function[] = {
|
2008-06-20 08:19:32 +07:00
|
|
|
(struct usb_descriptor_header *) &subset_data_intf,
|
2008-08-19 07:45:07 +07:00
|
|
|
(struct usb_descriptor_header *) &mdlm_header_desc,
|
2008-06-20 08:19:32 +07:00
|
|
|
(struct usb_descriptor_header *) &mdlm_desc,
|
|
|
|
(struct usb_descriptor_header *) &mdlm_detail_desc,
|
|
|
|
(struct usb_descriptor_header *) ðer_desc,
|
2008-08-19 07:45:07 +07:00
|
|
|
(struct usb_descriptor_header *) &hs_subset_in_desc,
|
|
|
|
(struct usb_descriptor_header *) &hs_subset_out_desc,
|
2008-06-20 08:19:32 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2011-06-28 04:13:18 +07:00
|
|
|
/* super speed support: */
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_endpoint_descriptor ss_subset_in_desc = {
|
2011-06-28 04:13:18 +07:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_endpoint_descriptor ss_subset_out_desc = {
|
2011-06-28 04:13:18 +07:00
|
|
|
.bLength = USB_DT_ENDPOINT_SIZE,
|
|
|
|
.bDescriptorType = USB_DT_ENDPOINT,
|
|
|
|
|
|
|
|
.bmAttributes = USB_ENDPOINT_XFER_BULK,
|
|
|
|
.wMaxPacketSize = cpu_to_le16(1024),
|
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_ss_ep_comp_descriptor ss_subset_bulk_comp_desc = {
|
2011-06-28 04:13:18 +07:00
|
|
|
.bLength = sizeof ss_subset_bulk_comp_desc,
|
|
|
|
.bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
|
|
|
|
|
|
|
|
/* the following 2 values can be tweaked if necessary */
|
|
|
|
/* .bMaxBurst = 0, */
|
|
|
|
/* .bmAttributes = 0, */
|
|
|
|
};
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static struct usb_descriptor_header *ss_eth_function[] = {
|
2011-06-28 04:13:18 +07:00
|
|
|
(struct usb_descriptor_header *) &subset_data_intf,
|
|
|
|
(struct usb_descriptor_header *) &mdlm_header_desc,
|
|
|
|
(struct usb_descriptor_header *) &mdlm_desc,
|
|
|
|
(struct usb_descriptor_header *) &mdlm_detail_desc,
|
|
|
|
(struct usb_descriptor_header *) ðer_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_subset_in_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_subset_bulk_comp_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_subset_out_desc,
|
|
|
|
(struct usb_descriptor_header *) &ss_subset_bulk_comp_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2008-06-20 08:19:32 +07:00
|
|
|
/* string descriptors: */
|
|
|
|
|
|
|
|
static struct usb_string geth_string_defs[] = {
|
|
|
|
[0].s = "CDC Ethernet Subset/SAFE",
|
2012-10-23 03:15:10 +07:00
|
|
|
[1].s = "",
|
2008-06-20 08:19:32 +07:00
|
|
|
{ } /* end of list */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings geth_string_table = {
|
|
|
|
.language = 0x0409, /* en-us */
|
|
|
|
.strings = geth_string_defs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_gadget_strings *geth_strings[] = {
|
|
|
|
&geth_string_table,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int geth_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
|
|
|
|
{
|
|
|
|
struct f_gether *geth = func_to_geth(f);
|
|
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
|
|
|
struct net_device *net;
|
|
|
|
|
|
|
|
/* we know alt == 0, so this is an activation or a reset */
|
|
|
|
|
2015-09-16 17:10:57 +07:00
|
|
|
if (geth->port.in_ep->enabled) {
|
2008-06-20 08:19:32 +07:00
|
|
|
DBG(cdev, "reset cdc subset\n");
|
|
|
|
gether_disconnect(&geth->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
DBG(cdev, "init + activate cdc subset\n");
|
2011-06-28 20:33:50 +07:00
|
|
|
if (config_ep_by_speed(cdev->gadget, f, geth->port.in_ep) ||
|
|
|
|
config_ep_by_speed(cdev->gadget, f, geth->port.out_ep)) {
|
|
|
|
geth->port.in_ep->desc = NULL;
|
|
|
|
geth->port.out_ep->desc = NULL;
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-06-20 08:19:32 +07:00
|
|
|
|
|
|
|
net = gether_connect(&geth->port);
|
2014-04-11 17:05:13 +07:00
|
|
|
return PTR_ERR_OR_ZERO(net);
|
2008-06-20 08:19:32 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void geth_disable(struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_gether *geth = func_to_geth(f);
|
|
|
|
struct usb_composite_dev *cdev = f->config->cdev;
|
|
|
|
|
|
|
|
DBG(cdev, "net deactivated\n");
|
|
|
|
gether_disconnect(&geth->port);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
/* serial function driver setup/binding */
|
|
|
|
|
2012-03-11 21:08:46 +07:00
|
|
|
static int
|
2008-06-20 08:19:32 +07:00
|
|
|
geth_bind(struct usb_configuration *c, struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct usb_composite_dev *cdev = c->cdev;
|
|
|
|
struct f_gether *geth = func_to_geth(f);
|
2013-05-28 14:15:55 +07:00
|
|
|
struct usb_string *us;
|
2008-06-20 08:19:32 +07:00
|
|
|
int status;
|
|
|
|
struct usb_ep *ep;
|
|
|
|
|
2013-05-28 14:15:53 +07:00
|
|
|
struct f_gether_opts *gether_opts;
|
|
|
|
|
|
|
|
gether_opts = container_of(f->fi, struct f_gether_opts, func_inst);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 gether_opts->bound access
|
|
|
|
*/
|
|
|
|
if (!gether_opts->bound) {
|
2013-05-28 14:15:56 +07:00
|
|
|
mutex_lock(&gether_opts->lock);
|
2013-05-28 14:15:53 +07:00
|
|
|
gether_set_gadget(gether_opts->net, cdev->gadget);
|
|
|
|
status = gether_register_netdev(gether_opts->net);
|
2013-05-28 14:15:56 +07:00
|
|
|
mutex_unlock(&gether_opts->lock);
|
2013-05-28 14:15:53 +07:00
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
gether_opts->bound = true;
|
|
|
|
}
|
2013-12-03 21:15:26 +07:00
|
|
|
|
2013-05-28 14:15:55 +07:00
|
|
|
us = usb_gstrings_attach(cdev, geth_strings,
|
|
|
|
ARRAY_SIZE(geth_string_defs));
|
|
|
|
if (IS_ERR(us))
|
|
|
|
return PTR_ERR(us);
|
|
|
|
|
|
|
|
subset_data_intf.iInterface = us[0].id;
|
|
|
|
ether_desc.iMACAddress = us[1].id;
|
2013-05-28 14:15:53 +07:00
|
|
|
|
2008-06-20 08:19:32 +07:00
|
|
|
/* allocate instance-specific interface IDs */
|
|
|
|
status = usb_interface_id(c, f);
|
|
|
|
if (status < 0)
|
|
|
|
goto fail;
|
|
|
|
subset_data_intf.bInterfaceNumber = status;
|
|
|
|
|
|
|
|
status = -ENODEV;
|
|
|
|
|
|
|
|
/* allocate instance-specific endpoints */
|
2008-08-19 07:45:07 +07:00
|
|
|
ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_in_desc);
|
2008-06-20 08:19:32 +07:00
|
|
|
if (!ep)
|
|
|
|
goto fail;
|
|
|
|
geth->port.in_ep = ep;
|
|
|
|
|
2008-08-19 07:45:07 +07:00
|
|
|
ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_out_desc);
|
2008-06-20 08:19:32 +07:00
|
|
|
if (!ep)
|
|
|
|
goto fail;
|
|
|
|
geth->port.out_ep = ep;
|
|
|
|
|
|
|
|
/* support all relevant hardware speeds... we expect that when
|
|
|
|
* hardware is dual speed, all bulk-capable endpoints work at
|
|
|
|
* both speeds
|
|
|
|
*/
|
2012-10-23 03:15:06 +07:00
|
|
|
hs_subset_in_desc.bEndpointAddress = fs_subset_in_desc.bEndpointAddress;
|
|
|
|
hs_subset_out_desc.bEndpointAddress =
|
|
|
|
fs_subset_out_desc.bEndpointAddress;
|
2011-06-28 04:13:18 +07:00
|
|
|
|
2012-10-23 03:15:06 +07:00
|
|
|
ss_subset_in_desc.bEndpointAddress = fs_subset_in_desc.bEndpointAddress;
|
|
|
|
ss_subset_out_desc.bEndpointAddress =
|
|
|
|
fs_subset_out_desc.bEndpointAddress;
|
2011-06-28 04:13:18 +07:00
|
|
|
|
2012-10-23 03:15:06 +07:00
|
|
|
status = usb_assign_descriptors(f, fs_eth_function, hs_eth_function,
|
2016-02-06 08:06:07 +07:00
|
|
|
ss_eth_function, NULL);
|
2012-10-23 03:15:06 +07:00
|
|
|
if (status)
|
|
|
|
goto fail;
|
2008-06-20 08:19:32 +07:00
|
|
|
|
|
|
|
/* NOTE: all that is done without knowing or caring about
|
|
|
|
* the network link ... which is unavailable to this code
|
|
|
|
* until we're activated via set_alt().
|
|
|
|
*/
|
|
|
|
|
|
|
|
DBG(cdev, "CDC Subset: %s speed IN/%s OUT/%s\n",
|
2011-06-28 04:13:18 +07:00
|
|
|
gadget_is_superspeed(c->cdev->gadget) ? "super" :
|
2008-06-20 08:19:32 +07:00
|
|
|
gadget_is_dualspeed(c->cdev->gadget) ? "dual" : "full",
|
|
|
|
geth->port.in_ep->name, geth->port.out_ep->name);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-05-28 14:15:56 +07:00
|
|
|
static inline struct f_gether_opts *to_f_gether_opts(struct config_item *item)
|
|
|
|
{
|
|
|
|
return container_of(to_config_group(item), struct f_gether_opts,
|
|
|
|
func_inst.group);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* f_gether_item_ops */
|
|
|
|
USB_ETHERNET_CONFIGFS_ITEM(gether);
|
|
|
|
|
|
|
|
/* f_gether_opts_dev_addr */
|
|
|
|
USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(gether);
|
|
|
|
|
|
|
|
/* f_gether_opts_host_addr */
|
|
|
|
USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(gether);
|
|
|
|
|
|
|
|
/* f_gether_opts_qmult */
|
|
|
|
USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(gether);
|
|
|
|
|
|
|
|
/* f_gether_opts_ifname */
|
|
|
|
USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(gether);
|
|
|
|
|
|
|
|
static struct configfs_attribute *gether_attrs[] = {
|
2015-10-03 20:32:42 +07:00
|
|
|
&gether_opts_attr_dev_addr,
|
|
|
|
&gether_opts_attr_host_addr,
|
|
|
|
&gether_opts_attr_qmult,
|
|
|
|
&gether_opts_attr_ifname,
|
2013-05-28 14:15:56 +07:00
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct config_item_type gether_func_type = {
|
|
|
|
.ct_item_ops = &gether_item_ops,
|
|
|
|
.ct_attrs = gether_attrs,
|
|
|
|
.ct_owner = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2013-05-28 14:15:53 +07:00
|
|
|
static void geth_free_inst(struct usb_function_instance *f)
|
|
|
|
{
|
|
|
|
struct f_gether_opts *opts;
|
|
|
|
|
|
|
|
opts = container_of(f, struct f_gether_opts, func_inst);
|
|
|
|
if (opts->bound)
|
|
|
|
gether_cleanup(netdev_priv(opts->net));
|
|
|
|
else
|
|
|
|
free_netdev(opts->net);
|
|
|
|
kfree(opts);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_function_instance *geth_alloc_inst(void)
|
|
|
|
{
|
|
|
|
struct f_gether_opts *opts;
|
|
|
|
|
|
|
|
opts = kzalloc(sizeof(*opts), GFP_KERNEL);
|
|
|
|
if (!opts)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2013-05-28 14:15:56 +07:00
|
|
|
mutex_init(&opts->lock);
|
2013-05-28 14:15:53 +07:00
|
|
|
opts->func_inst.free_func_inst = geth_free_inst;
|
|
|
|
opts->net = gether_setup_default();
|
2013-07-25 14:13:18 +07:00
|
|
|
if (IS_ERR(opts->net)) {
|
|
|
|
struct net_device *net = opts->net;
|
|
|
|
kfree(opts);
|
|
|
|
return ERR_CAST(net);
|
|
|
|
}
|
2013-05-28 14:15:53 +07:00
|
|
|
|
2013-05-28 14:15:56 +07:00
|
|
|
config_group_init_type_name(&opts->func_inst.group, "",
|
|
|
|
&gether_func_type);
|
|
|
|
|
2013-05-28 14:15:53 +07:00
|
|
|
return &opts->func_inst;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void geth_free(struct usb_function *f)
|
|
|
|
{
|
|
|
|
struct f_gether *eth;
|
|
|
|
|
|
|
|
eth = func_to_geth(f);
|
|
|
|
kfree(eth);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void geth_unbind(struct usb_configuration *c, struct usb_function *f)
|
|
|
|
{
|
|
|
|
geth_string_defs[0].id = 0;
|
|
|
|
usb_free_all_descriptors(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct usb_function *geth_alloc(struct usb_function_instance *fi)
|
|
|
|
{
|
|
|
|
struct f_gether *geth;
|
|
|
|
struct f_gether_opts *opts;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
/* allocate and initialize one new instance */
|
|
|
|
geth = kzalloc(sizeof(*geth), GFP_KERNEL);
|
|
|
|
if (!geth)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
opts = container_of(fi, struct f_gether_opts, func_inst);
|
|
|
|
|
2013-05-28 14:15:56 +07:00
|
|
|
mutex_lock(&opts->lock);
|
|
|
|
opts->refcnt++;
|
2013-05-28 14:15:53 +07:00
|
|
|
/* export host's Ethernet address in CDC format */
|
|
|
|
status = gether_get_host_addr_cdc(opts->net, geth->ethaddr,
|
|
|
|
sizeof(geth->ethaddr));
|
|
|
|
if (status < 12) {
|
|
|
|
kfree(geth);
|
2013-06-18 10:40:55 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
2013-05-28 14:15:53 +07:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
geth_string_defs[1].s = geth->ethaddr;
|
|
|
|
|
|
|
|
geth->port.ioport = netdev_priv(opts->net);
|
2013-05-28 14:15:56 +07:00
|
|
|
mutex_unlock(&opts->lock);
|
2013-05-28 14:15:53 +07:00
|
|
|
geth->port.cdc_filter = DEFAULT_FILTER;
|
|
|
|
|
|
|
|
geth->port.func.name = "cdc_subset";
|
|
|
|
geth->port.func.bind = geth_bind;
|
|
|
|
geth->port.func.unbind = geth_unbind;
|
|
|
|
geth->port.func.set_alt = geth_set_alt;
|
|
|
|
geth->port.func.disable = geth_disable;
|
|
|
|
geth->port.func.free_func = geth_free;
|
|
|
|
|
|
|
|
return &geth->port.func;
|
|
|
|
}
|
|
|
|
|
|
|
|
DECLARE_USB_FUNCTION_INIT(geth, geth_alloc_inst, geth_alloc);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("David Brownell");
|