Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ether.c -- Ethernet gadget driver, with CDC and non-CDC options |
| 3 | * |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 4 | * Copyright (C) 2003-2005,2008 David Brownell |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 6 | * Copyright (C) 2008 Nokia Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
David Brownell | 0cf4f2d | 2007-08-02 00:00:38 -0700 | [diff] [blame] | 14 | /* #define VERBOSE_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
Michal Nazarewicz | 396cda9 | 2009-11-30 10:55:40 +0100 | [diff] [blame] | 17 | |
| 18 | #if defined USB_ETH_RNDIS |
| 19 | # undef USB_ETH_RNDIS |
| 20 | #endif |
| 21 | #ifdef CONFIG_USB_ETH_RNDIS |
| 22 | # define USB_ETH_RNDIS y |
| 23 | #endif |
| 24 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 25 | #include "u_ether.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | * Ethernet gadget driver -- with CDC and non-CDC options |
| 30 | * Builds on hardware support for a full duplex link. |
| 31 | * |
| 32 | * CDC Ethernet is the standard USB solution for sending Ethernet frames |
| 33 | * using USB. Real hardware tends to use the same framing protocol but look |
| 34 | * different for control features. This driver strongly prefers to use |
| 35 | * this USB-IF standard as its open-systems interoperability solution; |
| 36 | * most host side USB stacks (except from Microsoft) support it. |
| 37 | * |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 38 | * This is sometimes called "CDC ECM" (Ethernet Control Model) to support |
| 39 | * TLA-soup. "CDC ACM" (Abstract Control Model) is for modems, and a new |
| 40 | * "CDC EEM" (Ethernet Emulation Model) is starting to spread. |
| 41 | * |
| 42 | * There's some hardware that can't talk CDC ECM. We make that hardware |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | * implement a "minimalist" vendor-agnostic CDC core: same framing, but |
David Brownell | 11d5489 | 2006-12-11 15:59:04 -0800 | [diff] [blame] | 44 | * link-level setup only requires activating the configuration. Only the |
| 45 | * endpoint descriptors, and product/vendor IDs, are relevant; no control |
| 46 | * operations are available. Linux supports it, but other host operating |
| 47 | * systems may not. (This is a subset of CDC Ethernet.) |
| 48 | * |
| 49 | * It turns out that if you add a few descriptors to that "CDC Subset", |
| 50 | * (Windows) host side drivers from MCCI can treat it as one submode of |
| 51 | * a proprietary scheme called "SAFE" ... without needing to know about |
| 52 | * specific product/vendor IDs. So we do that, making it easier to use |
| 53 | * those MS-Windows drivers. Those added descriptors make it resemble a |
| 54 | * CDC MDLM device, but they don't change device behavior at all. (See |
| 55 | * MCCI Engineering report 950198 "SAFE Networking Functions".) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | * |
| 57 | * A third option is also in use. Rather than CDC Ethernet, or something |
| 58 | * simpler, Microsoft pushes their own approach: RNDIS. The published |
| 59 | * RNDIS specs are ambiguous and appear to be incomplete, and are also |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 60 | * needlessly complex. They borrow more from CDC ACM than CDC ECM. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | */ |
| 62 | |
| 63 | #define DRIVER_DESC "Ethernet Gadget" |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 64 | #define DRIVER_VERSION "Memorial Day 2008" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Michal Nazarewicz | 396cda9 | 2009-11-30 10:55:40 +0100 | [diff] [blame] | 66 | #ifdef USB_ETH_RNDIS |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 67 | #define PREFIX "RNDIS/" |
| 68 | #else |
| 69 | #define PREFIX "" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #endif |
| 71 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 72 | /* |
| 73 | * This driver aims for interoperability by using CDC ECM unless |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | * |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 75 | * can_support_ecm() |
| 76 | * |
| 77 | * returns false, in which case it supports the CDC Subset. By default, |
| 78 | * that returns true; most hardware has no problems with CDC ECM, that's |
| 79 | * a good default. Previous versions of this driver had no default; this |
| 80 | * version changes that, removing overhead for new controller support. |
| 81 | * |
| 82 | * IF YOUR HARDWARE CAN'T SUPPORT CDC ECM, UPDATE THAT ROUTINE! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 85 | static inline bool has_rndis(void) |
| 86 | { |
Michal Nazarewicz | 396cda9 | 2009-11-30 10:55:40 +0100 | [diff] [blame] | 87 | #ifdef USB_ETH_RNDIS |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 88 | return true; |
| 89 | #else |
| 90 | return false; |
| 91 | #endif |
| 92 | } |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /*-------------------------------------------------------------------------*/ |
| 95 | |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 96 | /* |
| 97 | * Kbuild is not very cooperative with respect to linking separately |
| 98 | * compiled library objects into one module. So for now we won't use |
| 99 | * separate compilation ... ensuring init/exit sections work to shrink |
| 100 | * the runtime footprint, and giving us at least some parts of what |
| 101 | * a "gcc --combine ... part1.c part2.c part3.c ... " build would. |
| 102 | */ |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 103 | #include "f_ecm.c" |
| 104 | #include "f_subset.c" |
Michal Nazarewicz | 396cda9 | 2009-11-30 10:55:40 +0100 | [diff] [blame] | 105 | #ifdef USB_ETH_RNDIS |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 106 | #include "f_rndis.c" |
| 107 | #include "rndis.c" |
| 108 | #endif |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 109 | #include "f_eem.c" |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 110 | #include "u_ether.c" |
| 111 | |
| 112 | /*-------------------------------------------------------------------------*/ |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 113 | USB_GADGET_COMPOSITE_OPTIONS(); |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! |
| 116 | * Instead: allocate your own, using normal USB-IF procedures. |
| 117 | */ |
| 118 | |
| 119 | /* Thanks to NetChip Technologies for donating this product ID. |
| 120 | * It's for devices with only CDC Ethernet configurations. |
| 121 | */ |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 122 | #define CDC_VENDOR_NUM 0x0525 /* NetChip */ |
| 123 | #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | |
| 125 | /* For hardware that can't talk CDC, we use the same vendor ID that |
| 126 | * ARM Linux has used for ethernet-over-usb, both with sa1100 and |
| 127 | * with pxa250. We're protocol-compatible, if the host-side drivers |
| 128 | * use the endpoint descriptors. bcdDevice (version) is nonzero, so |
| 129 | * drivers that need to hard-wire endpoint numbers have a hook. |
| 130 | * |
| 131 | * The protocol is a minimal subset of CDC Ether, which works on any bulk |
| 132 | * hardware that's not deeply broken ... even on hardware that can't talk |
| 133 | * RNDIS (like SA-1100, with no interrupt endpoint, or anything that |
| 134 | * doesn't handle control-OUT). |
| 135 | */ |
| 136 | #define SIMPLE_VENDOR_NUM 0x049f |
| 137 | #define SIMPLE_PRODUCT_NUM 0x505a |
| 138 | |
| 139 | /* For hardware that can talk RNDIS and either of the above protocols, |
| 140 | * use this ID ... the windows INF files will know it. Unless it's |
| 141 | * used with CDC Ethernet, Linux 2.4 hosts will need updates to choose |
| 142 | * the non-RNDIS configuration. |
| 143 | */ |
| 144 | #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ |
| 145 | #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ |
| 146 | |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 147 | /* For EEM gadgets */ |
Brian Niebuhr | 4238ef5 | 2009-10-14 12:04:33 -0500 | [diff] [blame] | 148 | #define EEM_VENDOR_NUM 0x1d6b /* Linux Foundation */ |
| 149 | #define EEM_PRODUCT_NUM 0x0102 /* EEM Gadget */ |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | /*-------------------------------------------------------------------------*/ |
| 152 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 153 | static struct usb_device_descriptor device_desc = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | .bLength = sizeof device_desc, |
| 155 | .bDescriptorType = USB_DT_DEVICE, |
| 156 | |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 157 | .bcdUSB = cpu_to_le16 (0x0200), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | .bDeviceClass = USB_CLASS_COMM, |
| 160 | .bDeviceSubClass = 0, |
| 161 | .bDeviceProtocol = 0, |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 162 | /* .bMaxPacketSize0 = f(hardware) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 164 | /* Vendor and product id defaults change according to what configs |
| 165 | * we support. (As does bNumConfigurations.) These values can |
| 166 | * also be overridden by module parameters. |
| 167 | */ |
Harvey Harrison | 551509d | 2009-02-11 14:11:36 -0800 | [diff] [blame] | 168 | .idVendor = cpu_to_le16 (CDC_VENDOR_NUM), |
| 169 | .idProduct = cpu_to_le16 (CDC_PRODUCT_NUM), |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 170 | /* .bcdDevice = f(hardware) */ |
| 171 | /* .iManufacturer = DYNAMIC */ |
| 172 | /* .iProduct = DYNAMIC */ |
| 173 | /* NO SERIAL NUMBER */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | .bNumConfigurations = 1, |
| 175 | }; |
| 176 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 177 | static struct usb_otg_descriptor otg_descriptor = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | .bLength = sizeof otg_descriptor, |
| 179 | .bDescriptorType = USB_DT_OTG, |
| 180 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 181 | /* REVISIT SRP-only hardware is possible, although |
| 182 | * it would not be called "OTG" ... |
| 183 | */ |
| 184 | .bmAttributes = USB_OTG_SRP | USB_OTG_HNP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | }; |
| 186 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 187 | static const struct usb_descriptor_header *otg_desc[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | (struct usb_descriptor_header *) &otg_descriptor, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | NULL, |
| 190 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 192 | static struct usb_string strings_dev[] = { |
Sebastian Andrzej Siewior | cc2683c | 2012-09-10 15:01:58 +0200 | [diff] [blame] | 193 | [USB_GADGET_MANUFACTURER_IDX].s = "", |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 194 | [USB_GADGET_PRODUCT_IDX].s = PREFIX DRIVER_DESC, |
| 195 | [USB_GADGET_SERIAL_IDX].s = "", |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 196 | { } /* end of list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | }; |
| 198 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 199 | static struct usb_gadget_strings stringtab_dev = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | .language = 0x0409, /* en-us */ |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 201 | .strings = strings_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | }; |
| 203 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 204 | static struct usb_gadget_strings *dev_strings[] = { |
| 205 | &stringtab_dev, |
| 206 | NULL, |
| 207 | }; |
| 208 | |
| 209 | static u8 hostaddr[ETH_ALEN]; |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 210 | static struct eth_dev *the_dev; |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 211 | /*-------------------------------------------------------------------------*/ |
| 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | /* |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 214 | * We may not have an RNDIS configuration, but if we do it needs to be |
| 215 | * the first one present. That's to make Microsoft's drivers happy, |
| 216 | * and to follow DOCSIS 1.0 (cable modem standard). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | */ |
Michal Nazarewicz | e12995e | 2010-08-12 17:43:52 +0200 | [diff] [blame] | 218 | static int __init rndis_do_config(struct usb_configuration *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | { |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 220 | /* FIXME alloc iConfiguration string, set it in c->strings */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 222 | if (gadget_is_otg(c->cdev->gadget)) { |
| 223 | c->descriptors = otg_desc; |
| 224 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 227 | return rndis_bind_config(c, hostaddr, the_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 230 | static struct usb_configuration rndis_config_driver = { |
| 231 | .label = "RNDIS", |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 232 | .bConfigurationValue = 2, |
| 233 | /* .iConfiguration = DYNAMIC */ |
| 234 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | /*-------------------------------------------------------------------------*/ |
| 238 | |
Robert P. J. Day | c9188ad | 2009-12-28 06:31:08 -0500 | [diff] [blame] | 239 | #ifdef CONFIG_USB_ETH_EEM |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 240 | static bool use_eem = 1; |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 241 | #else |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 242 | static bool use_eem; |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 243 | #endif |
| 244 | module_param(use_eem, bool, 0); |
| 245 | MODULE_PARM_DESC(use_eem, "use CDC EEM mode"); |
| 246 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 247 | /* |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 248 | * We _always_ have an ECM, CDC Subset, or EEM configuration. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | */ |
Michal Nazarewicz | e12995e | 2010-08-12 17:43:52 +0200 | [diff] [blame] | 250 | static int __init eth_do_config(struct usb_configuration *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 252 | /* FIXME alloc iConfiguration string, set it in c->strings */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 254 | if (gadget_is_otg(c->cdev->gadget)) { |
| 255 | c->descriptors = otg_desc; |
| 256 | c->bmAttributes |= USB_CONFIG_ATT_WAKEUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 259 | if (use_eem) |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 260 | return eem_bind_config(c, the_dev); |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 261 | else if (can_support_ecm(c->cdev->gadget)) |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 262 | return ecm_bind_config(c, hostaddr, the_dev); |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 263 | else |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 264 | return geth_bind_config(c, hostaddr, the_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
| 266 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 267 | static struct usb_configuration eth_config_driver = { |
| 268 | /* .label = f(hardware) */ |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 269 | .bConfigurationValue = 1, |
| 270 | /* .iConfiguration = DYNAMIC */ |
| 271 | .bmAttributes = USB_CONFIG_ATT_SELFPOWER, |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | /*-------------------------------------------------------------------------*/ |
| 275 | |
Michal Nazarewicz | e12995e | 2010-08-12 17:43:52 +0200 | [diff] [blame] | 276 | static int __init eth_bind(struct usb_composite_dev *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 278 | struct usb_gadget *gadget = cdev->gadget; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | int status; |
David Brownell | 7e27f18 | 2006-06-13 09:54:40 -0700 | [diff] [blame] | 280 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 281 | /* set up network link layer */ |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 282 | the_dev = gether_setup(cdev->gadget, hostaddr); |
| 283 | if (IS_ERR(the_dev)) |
| 284 | return PTR_ERR(the_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 286 | /* set up main config label and device descriptor */ |
Brian Niebuhr | 9b39e9d | 2009-08-14 10:04:22 -0500 | [diff] [blame] | 287 | if (use_eem) { |
| 288 | /* EEM */ |
| 289 | eth_config_driver.label = "CDC Ethernet (EEM)"; |
| 290 | device_desc.idVendor = cpu_to_le16(EEM_VENDOR_NUM); |
| 291 | device_desc.idProduct = cpu_to_le16(EEM_PRODUCT_NUM); |
| 292 | } else if (can_support_ecm(cdev->gadget)) { |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 293 | /* ECM */ |
| 294 | eth_config_driver.label = "CDC Ethernet (ECM)"; |
| 295 | } else { |
| 296 | /* CDC Subset */ |
| 297 | eth_config_driver.label = "CDC Subset/SAFE"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
David Brownell | 4e19f22 | 2009-06-19 03:09:04 -0700 | [diff] [blame] | 299 | device_desc.idVendor = cpu_to_le16(SIMPLE_VENDOR_NUM); |
| 300 | device_desc.idProduct = cpu_to_le16(SIMPLE_PRODUCT_NUM); |
| 301 | if (!has_rndis()) |
| 302 | device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 305 | if (has_rndis()) { |
| 306 | /* RNDIS plus ECM-or-Subset */ |
David Brownell | 4e19f22 | 2009-06-19 03:09:04 -0700 | [diff] [blame] | 307 | device_desc.idVendor = cpu_to_le16(RNDIS_VENDOR_NUM); |
| 308 | device_desc.idProduct = cpu_to_le16(RNDIS_PRODUCT_NUM); |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 309 | device_desc.bNumConfigurations = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | } |
| 311 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 312 | /* Allocate string descriptor numbers ... note that string |
| 313 | * contents can be overridden by the composite_dev glue. |
| 314 | */ |
| 315 | |
Sebastian Andrzej Siewior | e1f15cc | 2012-09-06 20:11:16 +0200 | [diff] [blame] | 316 | status = usb_string_ids_tab(cdev, strings_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | if (status < 0) |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 318 | goto fail; |
Sebastian Andrzej Siewior | 276e2e4 | 2012-09-06 20:11:21 +0200 | [diff] [blame] | 319 | device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; |
| 320 | device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 322 | /* register our configuration(s); RNDIS first, if it's used */ |
| 323 | if (has_rndis()) { |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 324 | status = usb_add_config(cdev, &rndis_config_driver, |
| 325 | rndis_do_config); |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 326 | if (status < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Uwe Kleine-König | c9bfff9 | 2010-08-12 17:43:55 +0200 | [diff] [blame] | 330 | status = usb_add_config(cdev, ð_config_driver, eth_do_config); |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 331 | if (status < 0) |
| 332 | goto fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Sebastian Andrzej Siewior | 7d16e8d | 2012-09-10 15:01:53 +0200 | [diff] [blame] | 334 | usb_composite_overwrite_options(cdev, &coverwrite); |
David Brownell | 33376c1 | 2008-08-18 17:45:07 -0700 | [diff] [blame] | 335 | dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n", |
| 336 | DRIVER_DESC); |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 337 | |
| 338 | return 0; |
| 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | fail: |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 341 | gether_cleanup(the_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | return status; |
| 343 | } |
| 344 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 345 | static int __exit eth_unbind(struct usb_composite_dev *cdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
Sebastian Andrzej Siewior | d6a0143 | 2012-12-23 21:10:12 +0100 | [diff] [blame] | 347 | gether_cleanup(the_dev); |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 348 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
Sebastian Andrzej Siewior | c2ec75c | 2012-09-06 20:11:03 +0200 | [diff] [blame] | 351 | static __refdata struct usb_composite_driver eth_driver = { |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 352 | .name = "g_ether", |
| 353 | .dev = &device_desc, |
| 354 | .strings = dev_strings, |
Paul Zimmerman | 04617db | 2011-06-27 14:13:18 -0700 | [diff] [blame] | 355 | .max_speed = USB_SPEED_SUPER, |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 356 | .bind = eth_bind, |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 357 | .unbind = __exit_p(eth_unbind), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | }; |
| 359 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 360 | MODULE_DESCRIPTION(PREFIX DRIVER_DESC); |
| 361 | MODULE_AUTHOR("David Brownell, Benedikt Spanger"); |
| 362 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 364 | static int __init init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Sebastian Andrzej Siewior | 03e42bd | 2012-09-06 20:11:04 +0200 | [diff] [blame] | 366 | return usb_composite_probe(ð_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 368 | module_init(init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 370 | static void __exit cleanup(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 372 | usb_composite_unregister(ð_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
David Brownell | 0391c82 | 2008-06-19 18:20:11 -0700 | [diff] [blame] | 374 | module_exit(cleanup); |