blob: 709ef22655966764ee49350f39a3603cd6c41973 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ether.c -- Ethernet gadget driver, with CDC and non-CDC options
3 *
David Brownell0391c822008-06-19 18:20:11 -07004 * Copyright (C) 2003-2005,2008 David Brownell
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger
David Brownell0391c822008-06-19 18:20:11 -07006 * Copyright (C) 2008 Nokia Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
13
David Brownell0cf4f2d2007-08-02 00:00:38 -070014/* #define VERBOSE_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Michal Nazarewicz396cda92009-11-30 10:55:40 +010019
20#if defined USB_ETH_RNDIS
21# undef USB_ETH_RNDIS
22#endif
23#ifdef CONFIG_USB_ETH_RNDIS
24# define USB_ETH_RNDIS y
25#endif
26
David Brownell0391c822008-06-19 18:20:11 -070027#include "u_ether.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
30/*
31 * Ethernet gadget driver -- with CDC and non-CDC options
32 * Builds on hardware support for a full duplex link.
33 *
34 * CDC Ethernet is the standard USB solution for sending Ethernet frames
35 * using USB. Real hardware tends to use the same framing protocol but look
36 * different for control features. This driver strongly prefers to use
37 * this USB-IF standard as its open-systems interoperability solution;
38 * most host side USB stacks (except from Microsoft) support it.
39 *
David Brownell0391c822008-06-19 18:20:11 -070040 * This is sometimes called "CDC ECM" (Ethernet Control Model) to support
41 * TLA-soup. "CDC ACM" (Abstract Control Model) is for modems, and a new
42 * "CDC EEM" (Ethernet Emulation Model) is starting to spread.
43 *
44 * There's some hardware that can't talk CDC ECM. We make that hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 * implement a "minimalist" vendor-agnostic CDC core: same framing, but
David Brownell11d54892006-12-11 15:59:04 -080046 * link-level setup only requires activating the configuration. Only the
47 * endpoint descriptors, and product/vendor IDs, are relevant; no control
48 * operations are available. Linux supports it, but other host operating
49 * systems may not. (This is a subset of CDC Ethernet.)
50 *
51 * It turns out that if you add a few descriptors to that "CDC Subset",
52 * (Windows) host side drivers from MCCI can treat it as one submode of
53 * a proprietary scheme called "SAFE" ... without needing to know about
54 * specific product/vendor IDs. So we do that, making it easier to use
55 * those MS-Windows drivers. Those added descriptors make it resemble a
56 * CDC MDLM device, but they don't change device behavior at all. (See
57 * MCCI Engineering report 950198 "SAFE Networking Functions".)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 *
59 * A third option is also in use. Rather than CDC Ethernet, or something
60 * simpler, Microsoft pushes their own approach: RNDIS. The published
61 * RNDIS specs are ambiguous and appear to be incomplete, and are also
David Brownell0391c822008-06-19 18:20:11 -070062 * needlessly complex. They borrow more from CDC ACM than CDC ECM.
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 */
64
65#define DRIVER_DESC "Ethernet Gadget"
David Brownell0391c822008-06-19 18:20:11 -070066#define DRIVER_VERSION "Memorial Day 2008"
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Michal Nazarewicz396cda92009-11-30 10:55:40 +010068#ifdef USB_ETH_RNDIS
David Brownell0391c822008-06-19 18:20:11 -070069#define PREFIX "RNDIS/"
70#else
71#define PREFIX ""
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#endif
73
David Brownell0391c822008-06-19 18:20:11 -070074/*
75 * This driver aims for interoperability by using CDC ECM unless
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 *
David Brownell0391c822008-06-19 18:20:11 -070077 * can_support_ecm()
78 *
79 * returns false, in which case it supports the CDC Subset. By default,
80 * that returns true; most hardware has no problems with CDC ECM, that's
81 * a good default. Previous versions of this driver had no default; this
82 * version changes that, removing overhead for new controller support.
83 *
84 * IF YOUR HARDWARE CAN'T SUPPORT CDC ECM, UPDATE THAT ROUTINE!
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
David Brownell0391c822008-06-19 18:20:11 -070087static inline bool has_rndis(void)
88{
Michal Nazarewicz396cda92009-11-30 10:55:40 +010089#ifdef USB_ETH_RNDIS
David Brownell0391c822008-06-19 18:20:11 -070090 return true;
91#else
92 return false;
93#endif
94}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096/*-------------------------------------------------------------------------*/
97
David Brownell33376c12008-08-18 17:45:07 -070098/*
99 * Kbuild is not very cooperative with respect to linking separately
100 * compiled library objects into one module. So for now we won't use
101 * separate compilation ... ensuring init/exit sections work to shrink
102 * the runtime footprint, and giving us at least some parts of what
103 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
104 */
105#include "composite.c"
David Brownell33376c12008-08-18 17:45:07 -0700106
107#include "f_ecm.c"
108#include "f_subset.c"
Michal Nazarewicz396cda92009-11-30 10:55:40 +0100109#ifdef USB_ETH_RNDIS
David Brownell33376c12008-08-18 17:45:07 -0700110#include "f_rndis.c"
111#include "rndis.c"
112#endif
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500113#include "f_eem.c"
David Brownell33376c12008-08-18 17:45:07 -0700114#include "u_ether.c"
115
116/*-------------------------------------------------------------------------*/
Sebastian Andrzej Siewior7d16e8d2012-09-10 15:01:53 +0200117USB_GADGET_COMPOSITE_OPTIONS();
David Brownell33376c12008-08-18 17:45:07 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
120 * Instead: allocate your own, using normal USB-IF procedures.
121 */
122
123/* Thanks to NetChip Technologies for donating this product ID.
124 * It's for devices with only CDC Ethernet configurations.
125 */
David Brownell0391c822008-06-19 18:20:11 -0700126#define CDC_VENDOR_NUM 0x0525 /* NetChip */
127#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129/* For hardware that can't talk CDC, we use the same vendor ID that
130 * ARM Linux has used for ethernet-over-usb, both with sa1100 and
131 * with pxa250. We're protocol-compatible, if the host-side drivers
132 * use the endpoint descriptors. bcdDevice (version) is nonzero, so
133 * drivers that need to hard-wire endpoint numbers have a hook.
134 *
135 * The protocol is a minimal subset of CDC Ether, which works on any bulk
136 * hardware that's not deeply broken ... even on hardware that can't talk
137 * RNDIS (like SA-1100, with no interrupt endpoint, or anything that
138 * doesn't handle control-OUT).
139 */
140#define SIMPLE_VENDOR_NUM 0x049f
141#define SIMPLE_PRODUCT_NUM 0x505a
142
143/* For hardware that can talk RNDIS and either of the above protocols,
144 * use this ID ... the windows INF files will know it. Unless it's
145 * used with CDC Ethernet, Linux 2.4 hosts will need updates to choose
146 * the non-RNDIS configuration.
147 */
148#define RNDIS_VENDOR_NUM 0x0525 /* NetChip */
149#define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */
150
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500151/* For EEM gadgets */
Brian Niebuhr4238ef52009-10-14 12:04:33 -0500152#define EEM_VENDOR_NUM 0x1d6b /* Linux Foundation */
153#define EEM_PRODUCT_NUM 0x0102 /* EEM Gadget */
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155/*-------------------------------------------------------------------------*/
156
David Brownell0391c822008-06-19 18:20:11 -0700157static struct usb_device_descriptor device_desc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 .bLength = sizeof device_desc,
159 .bDescriptorType = USB_DT_DEVICE,
160
Harvey Harrison551509d2009-02-11 14:11:36 -0800161 .bcdUSB = cpu_to_le16 (0x0200),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 .bDeviceClass = USB_CLASS_COMM,
164 .bDeviceSubClass = 0,
165 .bDeviceProtocol = 0,
David Brownell0391c822008-06-19 18:20:11 -0700166 /* .bMaxPacketSize0 = f(hardware) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
David Brownell0391c822008-06-19 18:20:11 -0700168 /* Vendor and product id defaults change according to what configs
169 * we support. (As does bNumConfigurations.) These values can
170 * also be overridden by module parameters.
171 */
Harvey Harrison551509d2009-02-11 14:11:36 -0800172 .idVendor = cpu_to_le16 (CDC_VENDOR_NUM),
173 .idProduct = cpu_to_le16 (CDC_PRODUCT_NUM),
David Brownell0391c822008-06-19 18:20:11 -0700174 /* .bcdDevice = f(hardware) */
175 /* .iManufacturer = DYNAMIC */
176 /* .iProduct = DYNAMIC */
177 /* NO SERIAL NUMBER */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 .bNumConfigurations = 1,
179};
180
David Brownell0391c822008-06-19 18:20:11 -0700181static struct usb_otg_descriptor otg_descriptor = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 .bLength = sizeof otg_descriptor,
183 .bDescriptorType = USB_DT_OTG,
184
David Brownell0391c822008-06-19 18:20:11 -0700185 /* REVISIT SRP-only hardware is possible, although
186 * it would not be called "OTG" ...
187 */
188 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189};
190
David Brownell0391c822008-06-19 18:20:11 -0700191static const struct usb_descriptor_header *otg_desc[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 (struct usb_descriptor_header *) &otg_descriptor,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 NULL,
194};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
David Brownell0391c822008-06-19 18:20:11 -0700197/* string IDs are assigned dynamically */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
David Brownell0391c822008-06-19 18:20:11 -0700199#define STRING_MANUFACTURER_IDX 0
200#define STRING_PRODUCT_IDX 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
David Brownell0391c822008-06-19 18:20:11 -0700202static char manufacturer[50];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
David Brownell0391c822008-06-19 18:20:11 -0700204static struct usb_string strings_dev[] = {
205 [STRING_MANUFACTURER_IDX].s = manufacturer,
206 [STRING_PRODUCT_IDX].s = PREFIX DRIVER_DESC,
207 { } /* end of list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208};
209
David Brownell0391c822008-06-19 18:20:11 -0700210static struct usb_gadget_strings stringtab_dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 .language = 0x0409, /* en-us */
David Brownell0391c822008-06-19 18:20:11 -0700212 .strings = strings_dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213};
214
David Brownell0391c822008-06-19 18:20:11 -0700215static struct usb_gadget_strings *dev_strings[] = {
216 &stringtab_dev,
217 NULL,
218};
219
220static u8 hostaddr[ETH_ALEN];
221
222/*-------------------------------------------------------------------------*/
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/*
David Brownell0391c822008-06-19 18:20:11 -0700225 * We may not have an RNDIS configuration, but if we do it needs to be
226 * the first one present. That's to make Microsoft's drivers happy,
227 * and to follow DOCSIS 1.0 (cable modem standard).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 */
Michal Nazarewicze12995e2010-08-12 17:43:52 +0200229static int __init rndis_do_config(struct usb_configuration *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
David Brownell0391c822008-06-19 18:20:11 -0700231 /* FIXME alloc iConfiguration string, set it in c->strings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
David Brownell0391c822008-06-19 18:20:11 -0700233 if (gadget_is_otg(c->cdev->gadget)) {
234 c->descriptors = otg_desc;
235 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 }
237
David Brownell0391c822008-06-19 18:20:11 -0700238 return rndis_bind_config(c, hostaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239}
240
David Brownell0391c822008-06-19 18:20:11 -0700241static struct usb_configuration rndis_config_driver = {
242 .label = "RNDIS",
David Brownell0391c822008-06-19 18:20:11 -0700243 .bConfigurationValue = 2,
244 /* .iConfiguration = DYNAMIC */
245 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
David Brownell0391c822008-06-19 18:20:11 -0700246};
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/*-------------------------------------------------------------------------*/
249
Robert P. J. Dayc9188ad2009-12-28 06:31:08 -0500250#ifdef CONFIG_USB_ETH_EEM
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030251static bool use_eem = 1;
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500252#else
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030253static bool use_eem;
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500254#endif
255module_param(use_eem, bool, 0);
256MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
257
David Brownell0391c822008-06-19 18:20:11 -0700258/*
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500259 * We _always_ have an ECM, CDC Subset, or EEM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 */
Michal Nazarewicze12995e2010-08-12 17:43:52 +0200261static int __init eth_do_config(struct usb_configuration *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
David Brownell0391c822008-06-19 18:20:11 -0700263 /* FIXME alloc iConfiguration string, set it in c->strings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
David Brownell0391c822008-06-19 18:20:11 -0700265 if (gadget_is_otg(c->cdev->gadget)) {
266 c->descriptors = otg_desc;
267 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500270 if (use_eem)
271 return eem_bind_config(c);
272 else if (can_support_ecm(c->cdev->gadget))
David Brownell0391c822008-06-19 18:20:11 -0700273 return ecm_bind_config(c, hostaddr);
274 else
275 return geth_bind_config(c, hostaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
David Brownell0391c822008-06-19 18:20:11 -0700278static struct usb_configuration eth_config_driver = {
279 /* .label = f(hardware) */
David Brownell0391c822008-06-19 18:20:11 -0700280 .bConfigurationValue = 1,
281 /* .iConfiguration = DYNAMIC */
282 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
David Brownell0391c822008-06-19 18:20:11 -0700283};
284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285/*-------------------------------------------------------------------------*/
286
Michal Nazarewicze12995e2010-08-12 17:43:52 +0200287static int __init eth_bind(struct usb_composite_dev *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
David Brownell0391c822008-06-19 18:20:11 -0700289 int gcnum;
290 struct usb_gadget *gadget = cdev->gadget;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 int status;
David Brownell7e27f182006-06-13 09:54:40 -0700292
David Brownell0391c822008-06-19 18:20:11 -0700293 /* set up network link layer */
294 status = gether_setup(cdev->gadget, hostaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (status < 0)
David Brownell0391c822008-06-19 18:20:11 -0700296 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297
David Brownell0391c822008-06-19 18:20:11 -0700298 /* set up main config label and device descriptor */
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500299 if (use_eem) {
300 /* EEM */
301 eth_config_driver.label = "CDC Ethernet (EEM)";
302 device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
303 device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
304 } else if (can_support_ecm(cdev->gadget)) {
David Brownell0391c822008-06-19 18:20:11 -0700305 /* ECM */
306 eth_config_driver.label = "CDC Ethernet (ECM)";
307 } else {
308 /* CDC Subset */
309 eth_config_driver.label = "CDC Subset/SAFE";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
David Brownell4e19f222009-06-19 03:09:04 -0700311 device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM);
312 device_desc.idProduct = cpu_to_le16(SIMPLE_PRODUCT_NUM);
313 if (!has_rndis())
314 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 }
316
David Brownell0391c822008-06-19 18:20:11 -0700317 if (has_rndis()) {
318 /* RNDIS plus ECM-or-Subset */
David Brownell4e19f222009-06-19 03:09:04 -0700319 device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
320 device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM);
David Brownell0391c822008-06-19 18:20:11 -0700321 device_desc.bNumConfigurations = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 }
323
David Brownell0391c822008-06-19 18:20:11 -0700324 gcnum = usb_gadget_controller_number(gadget);
David Brownell91e79c92005-07-13 15:18:30 -0700325 if (gcnum >= 0)
David Brownell0391c822008-06-19 18:20:11 -0700326 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
David Brownell91e79c92005-07-13 15:18:30 -0700327 else {
David Brownell0391c822008-06-19 18:20:11 -0700328 /* We assume that can_support_ecm() tells the truth;
329 * but if the controller isn't recognized at all then
330 * that assumption is a bit more likely to be wrong.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 */
David Brownell33376c12008-08-18 17:45:07 -0700332 dev_warn(&gadget->dev,
333 "controller '%s' not recognized; trying %s\n",
David Brownell0391c822008-06-19 18:20:11 -0700334 gadget->name,
335 eth_config_driver.label);
336 device_desc.bcdDevice =
Harvey Harrison551509d2009-02-11 14:11:36 -0800337 cpu_to_le16(0x0300 | 0x0099);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338 }
David Brownell0391c822008-06-19 18:20:11 -0700339
340
341 /* Allocate string descriptor numbers ... note that string
342 * contents can be overridden by the composite_dev glue.
343 */
344
345 /* device descriptor strings: manufacturer, product */
346 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700347 init_utsname()->sysname, init_utsname()->release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 gadget->name);
Sebastian Andrzej Siewiore1f15cc2012-09-06 20:11:16 +0200349 status = usb_string_ids_tab(cdev, strings_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 if (status < 0)
David Brownell0391c822008-06-19 18:20:11 -0700351 goto fail;
Sebastian Andrzej Siewiore1f15cc2012-09-06 20:11:16 +0200352 device_desc.iManufacturer = strings_dev[STRING_MANUFACTURER_IDX].id;
353 device_desc.iProduct = strings_dev[STRING_PRODUCT_IDX].id;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
David Brownell0391c822008-06-19 18:20:11 -0700355 /* register our configuration(s); RNDIS first, if it's used */
356 if (has_rndis()) {
Uwe Kleine-Königc9bfff92010-08-12 17:43:55 +0200357 status = usb_add_config(cdev, &rndis_config_driver,
358 rndis_do_config);
David Brownell0391c822008-06-19 18:20:11 -0700359 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
Uwe Kleine-Königc9bfff92010-08-12 17:43:55 +0200363 status = usb_add_config(cdev, &eth_config_driver, eth_do_config);
David Brownell0391c822008-06-19 18:20:11 -0700364 if (status < 0)
365 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Sebastian Andrzej Siewior7d16e8d2012-09-10 15:01:53 +0200367 usb_composite_overwrite_options(cdev, &coverwrite);
David Brownell33376c12008-08-18 17:45:07 -0700368 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
369 DRIVER_DESC);
David Brownell0391c822008-06-19 18:20:11 -0700370
371 return 0;
372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373fail:
David Brownell0391c822008-06-19 18:20:11 -0700374 gether_cleanup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 return status;
376}
377
David Brownell0391c822008-06-19 18:20:11 -0700378static int __exit eth_unbind(struct usb_composite_dev *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
David Brownell0391c822008-06-19 18:20:11 -0700380 gether_cleanup();
381 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
Sebastian Andrzej Siewiorc2ec75c2012-09-06 20:11:03 +0200384static __refdata struct usb_composite_driver eth_driver = {
David Brownell0391c822008-06-19 18:20:11 -0700385 .name = "g_ether",
386 .dev = &device_desc,
387 .strings = dev_strings,
Paul Zimmerman04617db2011-06-27 14:13:18 -0700388 .max_speed = USB_SPEED_SUPER,
Sebastian Andrzej Siewior03e42bd2012-09-06 20:11:04 +0200389 .bind = eth_bind,
David Brownell0391c822008-06-19 18:20:11 -0700390 .unbind = __exit_p(eth_unbind),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391};
392
David Brownell0391c822008-06-19 18:20:11 -0700393MODULE_DESCRIPTION(PREFIX DRIVER_DESC);
394MODULE_AUTHOR("David Brownell, Benedikt Spanger");
395MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
David Brownell0391c822008-06-19 18:20:11 -0700397static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398{
Sebastian Andrzej Siewior03e42bd2012-09-06 20:11:04 +0200399 return usb_composite_probe(&eth_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400}
David Brownell0391c822008-06-19 18:20:11 -0700401module_init(init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
David Brownell0391c822008-06-19 18:20:11 -0700403static void __exit cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404{
David Brownell0391c822008-06-19 18:20:11 -0700405 usb_composite_unregister(&eth_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406}
David Brownell0391c822008-06-19 18:20:11 -0700407module_exit(cleanup);