2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* ether.c -- Ethernet gadget driver, with CDC and non-CDC options
|
|
|
|
*
|
2008-06-20 08:20:11 +07:00
|
|
|
* Copyright (C) 2003-2005,2008 David Brownell
|
2005-04-17 05:20:36 +07:00
|
|
|
* Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
|
2008-06-20 08:20:11 +07:00
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2007-08-02 14:00:38 +07:00
|
|
|
/* #define VERBOSE_DEBUG */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2013-05-28 14:15:54 +07:00
|
|
|
#include <linux/netdevice.h>
|
2009-11-30 16:55:40 +07:00
|
|
|
|
|
|
|
#if defined USB_ETH_RNDIS
|
|
|
|
# undef USB_ETH_RNDIS
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_USB_ETH_RNDIS
|
|
|
|
# define USB_ETH_RNDIS y
|
|
|
|
#endif
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
#include "u_ether.h"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ethernet gadget driver -- with CDC and non-CDC options
|
|
|
|
* Builds on hardware support for a full duplex link.
|
|
|
|
*
|
|
|
|
* CDC Ethernet is the standard USB solution for sending Ethernet frames
|
|
|
|
* using USB. Real hardware tends to use the same framing protocol but look
|
|
|
|
* different for control features. This driver strongly prefers to use
|
|
|
|
* this USB-IF standard as its open-systems interoperability solution;
|
|
|
|
* most host side USB stacks (except from Microsoft) support it.
|
|
|
|
*
|
2008-06-20 08:20:11 +07:00
|
|
|
* This is sometimes called "CDC ECM" (Ethernet Control Model) to support
|
|
|
|
* TLA-soup. "CDC ACM" (Abstract Control Model) is for modems, and a new
|
|
|
|
* "CDC EEM" (Ethernet Emulation Model) is starting to spread.
|
|
|
|
*
|
|
|
|
* There's some hardware that can't talk CDC ECM. We make that hardware
|
2005-04-17 05:20:36 +07:00
|
|
|
* implement a "minimalist" vendor-agnostic CDC core: same framing, but
|
2006-12-12 06:59:04 +07:00
|
|
|
* link-level setup only requires activating the configuration. Only the
|
|
|
|
* endpoint descriptors, and product/vendor IDs, are relevant; no control
|
|
|
|
* operations are available. Linux supports it, but other host operating
|
|
|
|
* systems may not. (This is a subset of CDC Ethernet.)
|
|
|
|
*
|
|
|
|
* It turns out that if you add a few descriptors to that "CDC Subset",
|
|
|
|
* (Windows) host side drivers from MCCI can treat it as one submode of
|
|
|
|
* a proprietary scheme called "SAFE" ... without needing to know about
|
|
|
|
* specific product/vendor IDs. So we do that, making it easier to use
|
|
|
|
* those MS-Windows drivers. Those added descriptors make it resemble a
|
|
|
|
* CDC MDLM device, but they don't change device behavior at all. (See
|
|
|
|
* MCCI Engineering report 950198 "SAFE Networking Functions".)
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* A third option is also in use. Rather than CDC Ethernet, or something
|
|
|
|
* simpler, Microsoft pushes their own approach: RNDIS. The published
|
|
|
|
* RNDIS specs are ambiguous and appear to be incomplete, and are also
|
2008-06-20 08:20:11 +07:00
|
|
|
* needlessly complex. They borrow more from CDC ACM than CDC ECM.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define DRIVER_DESC "Ethernet Gadget"
|
2008-06-20 08:20:11 +07:00
|
|
|
#define DRIVER_VERSION "Memorial Day 2008"
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-11-30 16:55:40 +07:00
|
|
|
#ifdef USB_ETH_RNDIS
|
2008-06-20 08:20:11 +07:00
|
|
|
#define PREFIX "RNDIS/"
|
|
|
|
#else
|
|
|
|
#define PREFIX ""
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/*
|
|
|
|
* This driver aims for interoperability by using CDC ECM unless
|
|
|
|
*
|
|
|
|
* can_support_ecm()
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
2008-06-20 08:20:11 +07:00
|
|
|
* returns false, in which case it supports the CDC Subset. By default,
|
|
|
|
* that returns true; most hardware has no problems with CDC ECM, that's
|
|
|
|
* a good default. Previous versions of this driver had no default; this
|
|
|
|
* version changes that, removing overhead for new controller support.
|
|
|
|
*
|
|
|
|
* IF YOUR HARDWARE CAN'T SUPPORT CDC ECM, UPDATE THAT ROUTINE!
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
static inline bool has_rndis(void)
|
|
|
|
{
|
2009-11-30 16:55:40 +07:00
|
|
|
#ifdef USB_ETH_RNDIS
|
2008-06-20 08:20:11 +07:00
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-24 15:23:02 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
|
2013-05-28 14:15:46 +07:00
|
|
|
#include "u_ecm.h"
|
2013-05-28 14:15:54 +07:00
|
|
|
#include "u_gether.h"
|
2009-11-30 16:55:40 +07:00
|
|
|
#ifdef USB_ETH_RNDIS
|
2013-05-28 14:15:58 +07:00
|
|
|
#include "u_rndis.h"
|
2013-05-24 15:23:02 +07:00
|
|
|
#include "rndis.h"
|
2013-05-28 14:15:58 +07:00
|
|
|
#else
|
|
|
|
#define rndis_borrow_net(...) do {} while (0)
|
2008-08-19 07:45:07 +07:00
|
|
|
#endif
|
2013-05-28 14:15:48 +07:00
|
|
|
#include "u_eem.h"
|
2008-08-19 07:45:07 +07:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------*/
|
2012-09-10 20:01:53 +07:00
|
|
|
USB_GADGET_COMPOSITE_OPTIONS();
|
2008-08-19 07:45:07 +07:00
|
|
|
|
usb: gadget: u_ether: convert into module
u_ether.c has been #include'd by all gadgets which implement
USB Ethernet functions. In order to add configfs support,
the f_ecm.c, f_eem.c, f_ncm.c, f_subset.c, f_rndis.c need to be
converted into modules and must not be #include'd. Consequently,
the u_ether.c needs to be a module too, in a manner similar
to u_serial.c. The resulting module should not take any parameters,
so they are pushed to the current users of it, that is ether.c,
g_ffs.c, multi.c, ncm.c, nokia.c.
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
2013-05-23 14:22:03 +07:00
|
|
|
USB_ETHERNET_MODULE_PARAMETERS();
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
|
|
|
|
* Instead: allocate your own, using normal USB-IF procedures.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Thanks to NetChip Technologies for donating this product ID.
|
|
|
|
* It's for devices with only CDC Ethernet configurations.
|
|
|
|
*/
|
2008-06-20 08:20:11 +07:00
|
|
|
#define CDC_VENDOR_NUM 0x0525 /* NetChip */
|
|
|
|
#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* For hardware that can't talk CDC, we use the same vendor ID that
|
|
|
|
* ARM Linux has used for ethernet-over-usb, both with sa1100 and
|
|
|
|
* with pxa250. We're protocol-compatible, if the host-side drivers
|
|
|
|
* use the endpoint descriptors. bcdDevice (version) is nonzero, so
|
|
|
|
* drivers that need to hard-wire endpoint numbers have a hook.
|
|
|
|
*
|
|
|
|
* The protocol is a minimal subset of CDC Ether, which works on any bulk
|
|
|
|
* hardware that's not deeply broken ... even on hardware that can't talk
|
|
|
|
* RNDIS (like SA-1100, with no interrupt endpoint, or anything that
|
|
|
|
* doesn't handle control-OUT).
|
|
|
|
*/
|
|
|
|
#define SIMPLE_VENDOR_NUM 0x049f
|
|
|
|
#define SIMPLE_PRODUCT_NUM 0x505a
|
|
|
|
|
|
|
|
/* For hardware that can talk RNDIS and either of the above protocols,
|
|
|
|
* use this ID ... the windows INF files will know it. Unless it's
|
|
|
|
* used with CDC Ethernet, Linux 2.4 hosts will need updates to choose
|
|
|
|
* the non-RNDIS configuration.
|
|
|
|
*/
|
|
|
|
#define RNDIS_VENDOR_NUM 0x0525 /* NetChip */
|
|
|
|
#define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */
|
|
|
|
|
2009-08-14 22:04:22 +07:00
|
|
|
/* For EEM gadgets */
|
2009-10-15 00:04:33 +07:00
|
|
|
#define EEM_VENDOR_NUM 0x1d6b /* Linux Foundation */
|
|
|
|
#define EEM_PRODUCT_NUM 0x0102 /* EEM Gadget */
|
2009-08-14 22:04:22 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*-------------------------------------------------------------------------*/
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
static struct usb_device_descriptor device_desc = {
|
2005-04-17 05:20:36 +07:00
|
|
|
.bLength = sizeof device_desc,
|
|
|
|
.bDescriptorType = USB_DT_DEVICE,
|
|
|
|
|
2015-10-20 23:33:13 +07:00
|
|
|
/* .bcdUSB = DYNAMIC */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
.bDeviceClass = USB_CLASS_COMM,
|
|
|
|
.bDeviceSubClass = 0,
|
|
|
|
.bDeviceProtocol = 0,
|
2008-06-20 08:20:11 +07:00
|
|
|
/* .bMaxPacketSize0 = f(hardware) */
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/* Vendor and product id defaults change according to what configs
|
|
|
|
* we support. (As does bNumConfigurations.) These values can
|
|
|
|
* also be overridden by module parameters.
|
|
|
|
*/
|
2009-02-12 05:11:36 +07:00
|
|
|
.idVendor = cpu_to_le16 (CDC_VENDOR_NUM),
|
|
|
|
.idProduct = cpu_to_le16 (CDC_PRODUCT_NUM),
|
2008-06-20 08:20:11 +07:00
|
|
|
/* .bcdDevice = f(hardware) */
|
|
|
|
/* .iManufacturer = DYNAMIC */
|
|
|
|
/* .iProduct = DYNAMIC */
|
|
|
|
/* NO SERIAL NUMBER */
|
2005-04-17 05:20:36 +07:00
|
|
|
.bNumConfigurations = 1,
|
|
|
|
};
|
|
|
|
|
2015-07-09 14:18:49 +07:00
|
|
|
static const struct usb_descriptor_header *otg_desc[2];
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
static struct usb_string strings_dev[] = {
|
2012-09-10 20:01:58 +07:00
|
|
|
[USB_GADGET_MANUFACTURER_IDX].s = "",
|
2012-09-07 01:11:21 +07:00
|
|
|
[USB_GADGET_PRODUCT_IDX].s = PREFIX DRIVER_DESC,
|
|
|
|
[USB_GADGET_SERIAL_IDX].s = "",
|
2008-06-20 08:20:11 +07:00
|
|
|
{ } /* end of list */
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
static struct usb_gadget_strings stringtab_dev = {
|
|
|
|
.language = 0x0409, /* en-us */
|
|
|
|
.strings = strings_dev,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
static struct usb_gadget_strings *dev_strings[] = {
|
|
|
|
&stringtab_dev,
|
|
|
|
NULL,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2013-05-28 14:15:46 +07:00
|
|
|
static struct usb_function_instance *fi_ecm;
|
|
|
|
static struct usb_function *f_ecm;
|
|
|
|
|
2013-05-28 14:15:48 +07:00
|
|
|
static struct usb_function_instance *fi_eem;
|
|
|
|
static struct usb_function *f_eem;
|
|
|
|
|
2013-05-28 14:15:54 +07:00
|
|
|
static struct usb_function_instance *fi_geth;
|
|
|
|
static struct usb_function *f_geth;
|
|
|
|
|
2013-05-28 14:15:58 +07:00
|
|
|
static struct usb_function_instance *fi_rndis;
|
|
|
|
static struct usb_function *f_rndis;
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/*-------------------------------------------------------------------------*/
|
2006-12-12 06:59:04 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/*
|
|
|
|
* We may not have an RNDIS configuration, but if we do it needs to be
|
|
|
|
* the first one present. That's to make Microsoft's drivers happy,
|
|
|
|
* and to follow DOCSIS 1.0 (cable modem standard).
|
2006-12-12 06:59:04 +07:00
|
|
|
*/
|
2015-04-11 05:14:21 +07:00
|
|
|
static int rndis_do_config(struct usb_configuration *c)
|
2008-06-20 08:20:11 +07:00
|
|
|
{
|
2013-05-28 14:15:58 +07:00
|
|
|
int status;
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/* FIXME alloc iConfiguration string, set it in c->strings */
|
2006-12-12 06:59:04 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
if (gadget_is_otg(c->cdev->gadget)) {
|
|
|
|
c->descriptors = otg_desc;
|
|
|
|
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-05-28 14:15:58 +07:00
|
|
|
f_rndis = usb_get_function(fi_rndis);
|
|
|
|
if (IS_ERR(f_rndis))
|
|
|
|
return PTR_ERR(f_rndis);
|
|
|
|
|
|
|
|
status = usb_add_function(c, f_rndis);
|
|
|
|
if (status < 0)
|
|
|
|
usb_put_function(f_rndis);
|
|
|
|
|
|
|
|
return status;
|
2008-06-20 08:20:11 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
static struct usb_configuration rndis_config_driver = {
|
|
|
|
.label = "RNDIS",
|
|
|
|
.bConfigurationValue = 2,
|
|
|
|
/* .iConfiguration = DYNAMIC */
|
|
|
|
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/*-------------------------------------------------------------------------*/
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-12-28 18:31:08 +07:00
|
|
|
#ifdef CONFIG_USB_ETH_EEM
|
2012-01-13 06:02:20 +07:00
|
|
|
static bool use_eem = 1;
|
2009-08-14 22:04:22 +07:00
|
|
|
#else
|
2012-01-13 06:02:20 +07:00
|
|
|
static bool use_eem;
|
2009-08-14 22:04:22 +07:00
|
|
|
#endif
|
|
|
|
module_param(use_eem, bool, 0);
|
|
|
|
MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/*
|
2009-08-14 22:04:22 +07:00
|
|
|
* We _always_ have an ECM, CDC Subset, or EEM configuration.
|
2005-04-17 05:20:36 +07:00
|
|
|
*/
|
2015-04-11 05:14:21 +07:00
|
|
|
static int eth_do_config(struct usb_configuration *c)
|
2008-06-20 08:20:11 +07:00
|
|
|
{
|
2013-05-28 14:15:46 +07:00
|
|
|
int status = 0;
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/* FIXME alloc iConfiguration string, set it in c->strings */
|
2006-06-13 23:54:40 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
if (gadget_is_otg(c->cdev->gadget)) {
|
|
|
|
c->descriptors = otg_desc;
|
|
|
|
c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-05-28 14:15:48 +07:00
|
|
|
if (use_eem) {
|
|
|
|
f_eem = usb_get_function(fi_eem);
|
|
|
|
if (IS_ERR(f_eem))
|
|
|
|
return PTR_ERR(f_eem);
|
|
|
|
|
|
|
|
status = usb_add_function(c, f_eem);
|
|
|
|
if (status < 0)
|
|
|
|
usb_put_function(f_eem);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
} else if (can_support_ecm(c->cdev->gadget)) {
|
2013-05-28 14:15:46 +07:00
|
|
|
f_ecm = usb_get_function(fi_ecm);
|
|
|
|
if (IS_ERR(f_ecm))
|
|
|
|
return PTR_ERR(f_ecm);
|
|
|
|
|
|
|
|
status = usb_add_function(c, f_ecm);
|
|
|
|
if (status < 0)
|
|
|
|
usb_put_function(f_ecm);
|
|
|
|
|
|
|
|
return status;
|
2013-05-28 14:15:54 +07:00
|
|
|
} else {
|
|
|
|
f_geth = usb_get_function(fi_geth);
|
|
|
|
if (IS_ERR(f_geth))
|
|
|
|
return PTR_ERR(f_geth);
|
|
|
|
|
|
|
|
status = usb_add_function(c, f_geth);
|
|
|
|
if (status < 0)
|
|
|
|
usb_put_function(f_geth);
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2013-05-28 14:15:46 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
static struct usb_configuration eth_config_driver = {
|
|
|
|
/* .label = f(hardware) */
|
|
|
|
.bConfigurationValue = 1,
|
|
|
|
/* .iConfiguration = DYNAMIC */
|
|
|
|
.bmAttributes = USB_CONFIG_ATT_SELFPOWER,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/*-------------------------------------------------------------------------*/
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-04-11 05:14:21 +07:00
|
|
|
static int eth_bind(struct usb_composite_dev *cdev)
|
2008-06-20 08:20:11 +07:00
|
|
|
{
|
|
|
|
struct usb_gadget *gadget = cdev->gadget;
|
2013-05-28 14:15:48 +07:00
|
|
|
struct f_eem_opts *eem_opts = NULL;
|
2013-05-28 14:15:46 +07:00
|
|
|
struct f_ecm_opts *ecm_opts = NULL;
|
2013-05-28 14:15:54 +07:00
|
|
|
struct f_gether_opts *geth_opts = NULL;
|
|
|
|
struct net_device *net;
|
2008-06-20 08:20:11 +07:00
|
|
|
int status;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/* set up main config label and device descriptor */
|
2009-08-14 22:04:22 +07:00
|
|
|
if (use_eem) {
|
|
|
|
/* EEM */
|
2013-05-28 14:15:48 +07:00
|
|
|
fi_eem = usb_get_function_instance("eem");
|
|
|
|
if (IS_ERR(fi_eem))
|
|
|
|
return PTR_ERR(fi_eem);
|
|
|
|
|
|
|
|
eem_opts = container_of(fi_eem, struct f_eem_opts, func_inst);
|
|
|
|
|
2013-05-28 14:15:54 +07:00
|
|
|
net = eem_opts->net;
|
2013-05-28 14:15:48 +07:00
|
|
|
|
2009-08-14 22:04:22 +07:00
|
|
|
eth_config_driver.label = "CDC Ethernet (EEM)";
|
|
|
|
device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
|
|
|
|
device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
|
2013-05-28 14:15:46 +07:00
|
|
|
} else if (can_support_ecm(gadget)) {
|
2008-06-20 08:20:11 +07:00
|
|
|
/* ECM */
|
2013-05-28 14:15:46 +07:00
|
|
|
|
|
|
|
fi_ecm = usb_get_function_instance("ecm");
|
|
|
|
if (IS_ERR(fi_ecm))
|
|
|
|
return PTR_ERR(fi_ecm);
|
|
|
|
|
|
|
|
ecm_opts = container_of(fi_ecm, struct f_ecm_opts, func_inst);
|
|
|
|
|
2013-05-28 14:15:54 +07:00
|
|
|
net = ecm_opts->net;
|
2013-05-28 14:15:46 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
eth_config_driver.label = "CDC Ethernet (ECM)";
|
|
|
|
} else {
|
|
|
|
/* CDC Subset */
|
2013-05-28 14:15:54 +07:00
|
|
|
|
|
|
|
fi_geth = usb_get_function_instance("geth");
|
|
|
|
if (IS_ERR(fi_geth))
|
|
|
|
return PTR_ERR(fi_geth);
|
|
|
|
|
|
|
|
geth_opts = container_of(fi_geth, struct f_gether_opts,
|
|
|
|
func_inst);
|
|
|
|
|
|
|
|
net = geth_opts->net;
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
eth_config_driver.label = "CDC Subset/SAFE";
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2009-06-19 17:09:04 +07:00
|
|
|
device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM);
|
|
|
|
device_desc.idProduct = cpu_to_le16(SIMPLE_PRODUCT_NUM);
|
|
|
|
if (!has_rndis())
|
|
|
|
device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
|
2008-06-20 08:20:11 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-05-28 14:15:54 +07:00
|
|
|
gether_set_qmult(net, qmult);
|
|
|
|
if (!gether_set_host_addr(net, host_addr))
|
|
|
|
pr_info("using host ethernet address: %s", host_addr);
|
|
|
|
if (!gether_set_dev_addr(net, dev_addr))
|
|
|
|
pr_info("using self ethernet address: %s", dev_addr);
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
if (has_rndis()) {
|
|
|
|
/* RNDIS plus ECM-or-Subset */
|
2013-05-28 14:15:54 +07:00
|
|
|
gether_set_gadget(net, cdev->gadget);
|
|
|
|
status = gether_register_netdev(net);
|
|
|
|
if (status)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (use_eem)
|
2013-05-28 14:15:48 +07:00
|
|
|
eem_opts->bound = true;
|
2013-05-28 14:15:54 +07:00
|
|
|
else if (can_support_ecm(gadget))
|
2013-05-28 14:15:46 +07:00
|
|
|
ecm_opts->bound = true;
|
2013-05-28 14:15:54 +07:00
|
|
|
else
|
|
|
|
geth_opts->bound = true;
|
2013-05-28 14:15:46 +07:00
|
|
|
|
2013-05-28 14:15:58 +07:00
|
|
|
fi_rndis = usb_get_function_instance("rndis");
|
|
|
|
if (IS_ERR(fi_rndis)) {
|
|
|
|
status = PTR_ERR(fi_rndis);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
rndis_borrow_net(fi_rndis, net);
|
|
|
|
|
2009-06-19 17:09:04 +07:00
|
|
|
device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
|
|
|
|
device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM);
|
2008-06-20 08:20:11 +07:00
|
|
|
device_desc.bNumConfigurations = 2;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/* Allocate string descriptor numbers ... note that string
|
|
|
|
* contents can be overridden by the composite_dev glue.
|
|
|
|
*/
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-09-07 01:11:16 +07:00
|
|
|
status = usb_string_ids_tab(cdev, strings_dev);
|
2008-06-20 08:20:11 +07:00
|
|
|
if (status < 0)
|
2013-05-28 14:15:58 +07:00
|
|
|
goto fail1;
|
2012-09-07 01:11:21 +07:00
|
|
|
device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id;
|
|
|
|
device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-07-09 14:18:49 +07:00
|
|
|
if (gadget_is_otg(gadget) && !otg_desc[0]) {
|
|
|
|
struct usb_descriptor_header *usb_desc;
|
|
|
|
|
|
|
|
usb_desc = usb_otg_descriptor_alloc(gadget);
|
|
|
|
if (!usb_desc)
|
|
|
|
goto fail1;
|
|
|
|
usb_otg_descriptor_init(gadget, usb_desc);
|
|
|
|
otg_desc[0] = usb_desc;
|
|
|
|
otg_desc[1] = NULL;
|
|
|
|
}
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
/* register our configuration(s); RNDIS first, if it's used */
|
|
|
|
if (has_rndis()) {
|
2010-08-12 22:43:55 +07:00
|
|
|
status = usb_add_config(cdev, &rndis_config_driver,
|
|
|
|
rndis_do_config);
|
2008-06-20 08:20:11 +07:00
|
|
|
if (status < 0)
|
2015-07-09 14:18:49 +07:00
|
|
|
goto fail2;
|
2008-06-20 08:20:11 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2010-08-12 22:43:55 +07:00
|
|
|
status = usb_add_config(cdev, ð_config_driver, eth_do_config);
|
2008-06-20 08:20:11 +07:00
|
|
|
if (status < 0)
|
2015-07-09 14:18:49 +07:00
|
|
|
goto fail2;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-09-10 20:01:53 +07:00
|
|
|
usb_composite_overwrite_options(cdev, &coverwrite);
|
2008-08-19 07:45:07 +07:00
|
|
|
dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
|
|
|
|
DRIVER_DESC);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
return 0;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-07-09 14:18:49 +07:00
|
|
|
fail2:
|
|
|
|
kfree(otg_desc[0]);
|
|
|
|
otg_desc[0] = NULL;
|
2013-05-28 14:15:58 +07:00
|
|
|
fail1:
|
|
|
|
if (has_rndis())
|
|
|
|
usb_put_function_instance(fi_rndis);
|
2008-06-20 08:20:11 +07:00
|
|
|
fail:
|
2013-05-28 14:15:54 +07:00
|
|
|
if (use_eem)
|
2013-05-28 14:15:48 +07:00
|
|
|
usb_put_function_instance(fi_eem);
|
2013-05-28 14:15:54 +07:00
|
|
|
else if (can_support_ecm(gadget))
|
2013-05-28 14:15:46 +07:00
|
|
|
usb_put_function_instance(fi_ecm);
|
2013-05-28 14:15:54 +07:00
|
|
|
else
|
|
|
|
usb_put_function_instance(fi_geth);
|
2008-06-20 08:20:11 +07:00
|
|
|
return status;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-04-11 05:14:21 +07:00
|
|
|
static int eth_unbind(struct usb_composite_dev *cdev)
|
2008-06-20 08:20:11 +07:00
|
|
|
{
|
2013-07-24 17:47:46 +07:00
|
|
|
if (has_rndis()) {
|
|
|
|
usb_put_function(f_rndis);
|
2013-05-28 14:15:58 +07:00
|
|
|
usb_put_function_instance(fi_rndis);
|
2013-07-24 17:47:46 +07:00
|
|
|
}
|
|
|
|
if (use_eem) {
|
|
|
|
usb_put_function(f_eem);
|
2013-05-28 14:15:48 +07:00
|
|
|
usb_put_function_instance(fi_eem);
|
2013-07-24 17:47:46 +07:00
|
|
|
} else if (can_support_ecm(cdev->gadget)) {
|
|
|
|
usb_put_function(f_ecm);
|
2013-05-28 14:15:46 +07:00
|
|
|
usb_put_function_instance(fi_ecm);
|
2013-07-24 17:47:46 +07:00
|
|
|
} else {
|
|
|
|
usb_put_function(f_geth);
|
2013-05-28 14:15:54 +07:00
|
|
|
usb_put_function_instance(fi_geth);
|
2013-07-24 17:47:46 +07:00
|
|
|
}
|
2015-07-09 14:18:49 +07:00
|
|
|
kfree(otg_desc[0]);
|
|
|
|
otg_desc[0] = NULL;
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2015-04-11 05:14:21 +07:00
|
|
|
static struct usb_composite_driver eth_driver = {
|
2008-06-20 08:20:11 +07:00
|
|
|
.name = "g_ether",
|
|
|
|
.dev = &device_desc,
|
|
|
|
.strings = dev_strings,
|
2011-06-28 04:13:18 +07:00
|
|
|
.max_speed = USB_SPEED_SUPER,
|
2012-09-07 01:11:04 +07:00
|
|
|
.bind = eth_bind,
|
2015-04-11 05:14:21 +07:00
|
|
|
.unbind = eth_unbind,
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
2014-07-09 23:09:56 +07:00
|
|
|
module_usb_composite_driver(eth_driver);
|
|
|
|
|
2008-06-20 08:20:11 +07:00
|
|
|
MODULE_DESCRIPTION(PREFIX DRIVER_DESC);
|
|
|
|
MODULE_AUTHOR("David Brownell, Benedikt Spanger");
|
|
|
|
MODULE_LICENSE("GPL");
|