blob: 141372b6e7a143b9a2497a1abf5d21b5f9ca3249 [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.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
David Brownell0cf4f2d2007-08-02 00:00:38 -070023/* #define VERBOSE_DEBUG */
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/utsname.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Michal Nazarewicz396cda92009-11-30 10:55:40 +010028
29#if defined USB_ETH_RNDIS
30# undef USB_ETH_RNDIS
31#endif
32#ifdef CONFIG_USB_ETH_RNDIS
33# define USB_ETH_RNDIS y
34#endif
35
David Brownell0391c822008-06-19 18:20:11 -070036#include "u_ether.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39/*
40 * Ethernet gadget driver -- with CDC and non-CDC options
41 * Builds on hardware support for a full duplex link.
42 *
43 * CDC Ethernet is the standard USB solution for sending Ethernet frames
44 * using USB. Real hardware tends to use the same framing protocol but look
45 * different for control features. This driver strongly prefers to use
46 * this USB-IF standard as its open-systems interoperability solution;
47 * most host side USB stacks (except from Microsoft) support it.
48 *
David Brownell0391c822008-06-19 18:20:11 -070049 * This is sometimes called "CDC ECM" (Ethernet Control Model) to support
50 * TLA-soup. "CDC ACM" (Abstract Control Model) is for modems, and a new
51 * "CDC EEM" (Ethernet Emulation Model) is starting to spread.
52 *
53 * There's some hardware that can't talk CDC ECM. We make that hardware
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 * implement a "minimalist" vendor-agnostic CDC core: same framing, but
David Brownell11d54892006-12-11 15:59:04 -080055 * link-level setup only requires activating the configuration. Only the
56 * endpoint descriptors, and product/vendor IDs, are relevant; no control
57 * operations are available. Linux supports it, but other host operating
58 * systems may not. (This is a subset of CDC Ethernet.)
59 *
60 * It turns out that if you add a few descriptors to that "CDC Subset",
61 * (Windows) host side drivers from MCCI can treat it as one submode of
62 * a proprietary scheme called "SAFE" ... without needing to know about
63 * specific product/vendor IDs. So we do that, making it easier to use
64 * those MS-Windows drivers. Those added descriptors make it resemble a
65 * CDC MDLM device, but they don't change device behavior at all. (See
66 * MCCI Engineering report 950198 "SAFE Networking Functions".)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *
68 * A third option is also in use. Rather than CDC Ethernet, or something
69 * simpler, Microsoft pushes their own approach: RNDIS. The published
70 * RNDIS specs are ambiguous and appear to be incomplete, and are also
David Brownell0391c822008-06-19 18:20:11 -070071 * needlessly complex. They borrow more from CDC ACM than CDC ECM.
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 */
73
74#define DRIVER_DESC "Ethernet Gadget"
David Brownell0391c822008-06-19 18:20:11 -070075#define DRIVER_VERSION "Memorial Day 2008"
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Michal Nazarewicz396cda92009-11-30 10:55:40 +010077#ifdef USB_ETH_RNDIS
David Brownell0391c822008-06-19 18:20:11 -070078#define PREFIX "RNDIS/"
79#else
80#define PREFIX ""
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#endif
82
David Brownell0391c822008-06-19 18:20:11 -070083/*
84 * This driver aims for interoperability by using CDC ECM unless
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 *
David Brownell0391c822008-06-19 18:20:11 -070086 * can_support_ecm()
87 *
88 * returns false, in which case it supports the CDC Subset. By default,
89 * that returns true; most hardware has no problems with CDC ECM, that's
90 * a good default. Previous versions of this driver had no default; this
91 * version changes that, removing overhead for new controller support.
92 *
93 * IF YOUR HARDWARE CAN'T SUPPORT CDC ECM, UPDATE THAT ROUTINE!
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
David Brownell0391c822008-06-19 18:20:11 -070096static inline bool has_rndis(void)
97{
Michal Nazarewicz396cda92009-11-30 10:55:40 +010098#ifdef USB_ETH_RNDIS
David Brownell0391c822008-06-19 18:20:11 -070099 return true;
100#else
101 return false;
102#endif
103}
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105/*-------------------------------------------------------------------------*/
106
David Brownell33376c12008-08-18 17:45:07 -0700107/*
108 * Kbuild is not very cooperative with respect to linking separately
109 * compiled library objects into one module. So for now we won't use
110 * separate compilation ... ensuring init/exit sections work to shrink
111 * the runtime footprint, and giving us at least some parts of what
112 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
113 */
114#include "composite.c"
115#include "usbstring.c"
116#include "config.c"
117#include "epautoconf.c"
118
119#include "f_ecm.c"
120#include "f_subset.c"
Michal Nazarewicz396cda92009-11-30 10:55:40 +0100121#ifdef USB_ETH_RNDIS
David Brownell33376c12008-08-18 17:45:07 -0700122#include "f_rndis.c"
123#include "rndis.c"
124#endif
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500125#include "f_eem.c"
David Brownell33376c12008-08-18 17:45:07 -0700126#include "u_ether.c"
127
128/*-------------------------------------------------------------------------*/
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
131 * Instead: allocate your own, using normal USB-IF procedures.
132 */
133
134/* Thanks to NetChip Technologies for donating this product ID.
135 * It's for devices with only CDC Ethernet configurations.
136 */
David Brownell0391c822008-06-19 18:20:11 -0700137#define CDC_VENDOR_NUM 0x0525 /* NetChip */
138#define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140/* For hardware that can't talk CDC, we use the same vendor ID that
141 * ARM Linux has used for ethernet-over-usb, both with sa1100 and
142 * with pxa250. We're protocol-compatible, if the host-side drivers
143 * use the endpoint descriptors. bcdDevice (version) is nonzero, so
144 * drivers that need to hard-wire endpoint numbers have a hook.
145 *
146 * The protocol is a minimal subset of CDC Ether, which works on any bulk
147 * hardware that's not deeply broken ... even on hardware that can't talk
148 * RNDIS (like SA-1100, with no interrupt endpoint, or anything that
149 * doesn't handle control-OUT).
150 */
151#define SIMPLE_VENDOR_NUM 0x049f
152#define SIMPLE_PRODUCT_NUM 0x505a
153
154/* For hardware that can talk RNDIS and either of the above protocols,
155 * use this ID ... the windows INF files will know it. Unless it's
156 * used with CDC Ethernet, Linux 2.4 hosts will need updates to choose
157 * the non-RNDIS configuration.
158 */
159#define RNDIS_VENDOR_NUM 0x0525 /* NetChip */
160#define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */
161
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500162/* For EEM gadgets */
Brian Niebuhr4238ef52009-10-14 12:04:33 -0500163#define EEM_VENDOR_NUM 0x1d6b /* Linux Foundation */
164#define EEM_PRODUCT_NUM 0x0102 /* EEM Gadget */
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166/*-------------------------------------------------------------------------*/
167
David Brownell0391c822008-06-19 18:20:11 -0700168static struct usb_device_descriptor device_desc = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 .bLength = sizeof device_desc,
170 .bDescriptorType = USB_DT_DEVICE,
171
Harvey Harrison551509d2009-02-11 14:11:36 -0800172 .bcdUSB = cpu_to_le16 (0x0200),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
174 .bDeviceClass = USB_CLASS_COMM,
175 .bDeviceSubClass = 0,
176 .bDeviceProtocol = 0,
David Brownell0391c822008-06-19 18:20:11 -0700177 /* .bMaxPacketSize0 = f(hardware) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
David Brownell0391c822008-06-19 18:20:11 -0700179 /* Vendor and product id defaults change according to what configs
180 * we support. (As does bNumConfigurations.) These values can
181 * also be overridden by module parameters.
182 */
Harvey Harrison551509d2009-02-11 14:11:36 -0800183 .idVendor = cpu_to_le16 (CDC_VENDOR_NUM),
184 .idProduct = cpu_to_le16 (CDC_PRODUCT_NUM),
David Brownell0391c822008-06-19 18:20:11 -0700185 /* .bcdDevice = f(hardware) */
186 /* .iManufacturer = DYNAMIC */
187 /* .iProduct = DYNAMIC */
188 /* NO SERIAL NUMBER */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .bNumConfigurations = 1,
190};
191
David Brownell0391c822008-06-19 18:20:11 -0700192static struct usb_otg_descriptor otg_descriptor = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 .bLength = sizeof otg_descriptor,
194 .bDescriptorType = USB_DT_OTG,
195
David Brownell0391c822008-06-19 18:20:11 -0700196 /* REVISIT SRP-only hardware is possible, although
197 * it would not be called "OTG" ...
198 */
199 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200};
201
David Brownell0391c822008-06-19 18:20:11 -0700202static const struct usb_descriptor_header *otg_desc[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 (struct usb_descriptor_header *) &otg_descriptor,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 NULL,
205};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
David Brownell0391c822008-06-19 18:20:11 -0700208/* string IDs are assigned dynamically */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
David Brownell0391c822008-06-19 18:20:11 -0700210#define STRING_MANUFACTURER_IDX 0
211#define STRING_PRODUCT_IDX 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
David Brownell0391c822008-06-19 18:20:11 -0700213static char manufacturer[50];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
David Brownell0391c822008-06-19 18:20:11 -0700215static struct usb_string strings_dev[] = {
216 [STRING_MANUFACTURER_IDX].s = manufacturer,
217 [STRING_PRODUCT_IDX].s = PREFIX DRIVER_DESC,
218 { } /* end of list */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219};
220
David Brownell0391c822008-06-19 18:20:11 -0700221static struct usb_gadget_strings stringtab_dev = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 .language = 0x0409, /* en-us */
David Brownell0391c822008-06-19 18:20:11 -0700223 .strings = strings_dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224};
225
David Brownell0391c822008-06-19 18:20:11 -0700226static struct usb_gadget_strings *dev_strings[] = {
227 &stringtab_dev,
228 NULL,
229};
230
231static u8 hostaddr[ETH_ALEN];
232
233/*-------------------------------------------------------------------------*/
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235/*
David Brownell0391c822008-06-19 18:20:11 -0700236 * We may not have an RNDIS configuration, but if we do it needs to be
237 * the first one present. That's to make Microsoft's drivers happy,
238 * and to follow DOCSIS 1.0 (cable modem standard).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 */
David Brownell0391c822008-06-19 18:20:11 -0700240static int __init rndis_do_config(struct usb_configuration *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
David Brownell0391c822008-06-19 18:20:11 -0700242 /* FIXME alloc iConfiguration string, set it in c->strings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
David Brownell0391c822008-06-19 18:20:11 -0700244 if (gadget_is_otg(c->cdev->gadget)) {
245 c->descriptors = otg_desc;
246 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 }
248
David Brownell0391c822008-06-19 18:20:11 -0700249 return rndis_bind_config(c, hostaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
David Brownell0391c822008-06-19 18:20:11 -0700252static struct usb_configuration rndis_config_driver = {
253 .label = "RNDIS",
254 .bind = rndis_do_config,
255 .bConfigurationValue = 2,
256 /* .iConfiguration = DYNAMIC */
257 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
David Brownell0391c822008-06-19 18:20:11 -0700258};
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260/*-------------------------------------------------------------------------*/
261
Michal Nazarewicz396cda92009-11-30 10:55:40 +0100262#ifdef USB_ETH_EEM
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500263static int use_eem = 1;
264#else
265static int use_eem;
266#endif
267module_param(use_eem, bool, 0);
268MODULE_PARM_DESC(use_eem, "use CDC EEM mode");
269
David Brownell0391c822008-06-19 18:20:11 -0700270/*
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500271 * We _always_ have an ECM, CDC Subset, or EEM configuration.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 */
David Brownell0391c822008-06-19 18:20:11 -0700273static int __init eth_do_config(struct usb_configuration *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
David Brownell0391c822008-06-19 18:20:11 -0700275 /* FIXME alloc iConfiguration string, set it in c->strings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
David Brownell0391c822008-06-19 18:20:11 -0700277 if (gadget_is_otg(c->cdev->gadget)) {
278 c->descriptors = otg_desc;
279 c->bmAttributes |= USB_CONFIG_ATT_WAKEUP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500282 if (use_eem)
283 return eem_bind_config(c);
284 else if (can_support_ecm(c->cdev->gadget))
David Brownell0391c822008-06-19 18:20:11 -0700285 return ecm_bind_config(c, hostaddr);
286 else
287 return geth_bind_config(c, hostaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
David Brownell0391c822008-06-19 18:20:11 -0700290static struct usb_configuration eth_config_driver = {
291 /* .label = f(hardware) */
292 .bind = eth_do_config,
293 .bConfigurationValue = 1,
294 /* .iConfiguration = DYNAMIC */
295 .bmAttributes = USB_CONFIG_ATT_SELFPOWER,
David Brownell0391c822008-06-19 18:20:11 -0700296};
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298/*-------------------------------------------------------------------------*/
299
David Brownell0391c822008-06-19 18:20:11 -0700300static int __init eth_bind(struct usb_composite_dev *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
David Brownell0391c822008-06-19 18:20:11 -0700302 int gcnum;
303 struct usb_gadget *gadget = cdev->gadget;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 int status;
David Brownell7e27f182006-06-13 09:54:40 -0700305
David Brownell0391c822008-06-19 18:20:11 -0700306 /* set up network link layer */
307 status = gether_setup(cdev->gadget, hostaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 if (status < 0)
David Brownell0391c822008-06-19 18:20:11 -0700309 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
David Brownell0391c822008-06-19 18:20:11 -0700311 /* set up main config label and device descriptor */
Brian Niebuhr9b39e9d2009-08-14 10:04:22 -0500312 if (use_eem) {
313 /* EEM */
314 eth_config_driver.label = "CDC Ethernet (EEM)";
315 device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM);
316 device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM);
317 } else if (can_support_ecm(cdev->gadget)) {
David Brownell0391c822008-06-19 18:20:11 -0700318 /* ECM */
319 eth_config_driver.label = "CDC Ethernet (ECM)";
320 } else {
321 /* CDC Subset */
322 eth_config_driver.label = "CDC Subset/SAFE";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
David Brownell4e19f222009-06-19 03:09:04 -0700324 device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM);
325 device_desc.idProduct = cpu_to_le16(SIMPLE_PRODUCT_NUM);
326 if (!has_rndis())
327 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
329
David Brownell0391c822008-06-19 18:20:11 -0700330 if (has_rndis()) {
331 /* RNDIS plus ECM-or-Subset */
David Brownell4e19f222009-06-19 03:09:04 -0700332 device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM);
333 device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM);
David Brownell0391c822008-06-19 18:20:11 -0700334 device_desc.bNumConfigurations = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
336
David Brownell0391c822008-06-19 18:20:11 -0700337 gcnum = usb_gadget_controller_number(gadget);
David Brownell91e79c92005-07-13 15:18:30 -0700338 if (gcnum >= 0)
David Brownell0391c822008-06-19 18:20:11 -0700339 device_desc.bcdDevice = cpu_to_le16(0x0300 | gcnum);
David Brownell91e79c92005-07-13 15:18:30 -0700340 else {
David Brownell0391c822008-06-19 18:20:11 -0700341 /* We assume that can_support_ecm() tells the truth;
342 * but if the controller isn't recognized at all then
343 * that assumption is a bit more likely to be wrong.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 */
David Brownell33376c12008-08-18 17:45:07 -0700345 dev_warn(&gadget->dev,
346 "controller '%s' not recognized; trying %s\n",
David Brownell0391c822008-06-19 18:20:11 -0700347 gadget->name,
348 eth_config_driver.label);
349 device_desc.bcdDevice =
Harvey Harrison551509d2009-02-11 14:11:36 -0800350 cpu_to_le16(0x0300 | 0x0099);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
David Brownell0391c822008-06-19 18:20:11 -0700352
353
354 /* Allocate string descriptor numbers ... note that string
355 * contents can be overridden by the composite_dev glue.
356 */
357
358 /* device descriptor strings: manufacturer, product */
359 snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
Serge E. Hallyn96b644b2006-10-02 02:18:13 -0700360 init_utsname()->sysname, init_utsname()->release,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 gadget->name);
David Brownell0391c822008-06-19 18:20:11 -0700362 status = usb_string_id(cdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 if (status < 0)
David Brownell0391c822008-06-19 18:20:11 -0700364 goto fail;
365 strings_dev[STRING_MANUFACTURER_IDX].id = status;
366 device_desc.iManufacturer = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
David Brownell0391c822008-06-19 18:20:11 -0700368 status = usb_string_id(cdev);
369 if (status < 0)
370 goto fail;
371 strings_dev[STRING_PRODUCT_IDX].id = status;
372 device_desc.iProduct = status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
David Brownell0391c822008-06-19 18:20:11 -0700374 /* register our configuration(s); RNDIS first, if it's used */
375 if (has_rndis()) {
376 status = usb_add_config(cdev, &rndis_config_driver);
377 if (status < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
David Brownell0391c822008-06-19 18:20:11 -0700381 status = usb_add_config(cdev, &eth_config_driver);
382 if (status < 0)
383 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
David Brownell33376c12008-08-18 17:45:07 -0700385 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
386 DRIVER_DESC);
David Brownell0391c822008-06-19 18:20:11 -0700387
388 return 0;
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390fail:
David Brownell0391c822008-06-19 18:20:11 -0700391 gether_cleanup();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return status;
393}
394
David Brownell0391c822008-06-19 18:20:11 -0700395static int __exit eth_unbind(struct usb_composite_dev *cdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
David Brownell0391c822008-06-19 18:20:11 -0700397 gether_cleanup();
398 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399}
400
David Brownell0391c822008-06-19 18:20:11 -0700401static struct usb_composite_driver eth_driver = {
402 .name = "g_ether",
403 .dev = &device_desc,
404 .strings = dev_strings,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 .bind = eth_bind,
David Brownell0391c822008-06-19 18:20:11 -0700406 .unbind = __exit_p(eth_unbind),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407};
408
David Brownell0391c822008-06-19 18:20:11 -0700409MODULE_DESCRIPTION(PREFIX DRIVER_DESC);
410MODULE_AUTHOR("David Brownell, Benedikt Spanger");
411MODULE_LICENSE("GPL");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
David Brownell0391c822008-06-19 18:20:11 -0700413static int __init init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414{
David Brownell0391c822008-06-19 18:20:11 -0700415 return usb_composite_register(&eth_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
David Brownell0391c822008-06-19 18:20:11 -0700417module_init(init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
David Brownell0391c822008-06-19 18:20:11 -0700419static void __exit cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
David Brownell0391c822008-06-19 18:20:11 -0700421 usb_composite_unregister(&eth_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
David Brownell0391c822008-06-19 18:20:11 -0700423module_exit(cleanup);