Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * ether.c -- Ethernet gadget driver, with CDC and non-CDC options | |
3 | * | |
4 | * Copyright (C) 2003-2005 David Brownell | |
5 | * Copyright (C) 2003-2004 Robert Schwebel, Benedikt Spranger | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 | */ | |
21 | ||
0cf4f2de | 22 | /* #define VERBOSE_DEBUG */ |
1da177e4 | 23 | |
1da177e4 | 24 | #include <linux/kernel.h> |
1da177e4 LT |
25 | #include <linux/utsname.h> |
26 | #include <linux/device.h> | |
1da177e4 | 27 | #include <linux/ctype.h> |
0cf4f2de DB |
28 | #include <linux/etherdevice.h> |
29 | #include <linux/ethtool.h> | |
1da177e4 | 30 | |
5f848137 | 31 | #include <linux/usb/ch9.h> |
a8c28f23 | 32 | #include <linux/usb/cdc.h> |
9454a57a | 33 | #include <linux/usb/gadget.h> |
1da177e4 | 34 | |
1da177e4 LT |
35 | #include "gadget_chips.h" |
36 | ||
37 | /*-------------------------------------------------------------------------*/ | |
38 | ||
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 | * | |
49 | * There's some hardware that can't talk CDC. We make that hardware | |
50 | * implement a "minimalist" vendor-agnostic CDC core: same framing, but | |
11d54898 DB |
51 | * link-level setup only requires activating the configuration. Only the |
52 | * endpoint descriptors, and product/vendor IDs, are relevant; no control | |
53 | * operations are available. Linux supports it, but other host operating | |
54 | * systems may not. (This is a subset of CDC Ethernet.) | |
55 | * | |
56 | * It turns out that if you add a few descriptors to that "CDC Subset", | |
57 | * (Windows) host side drivers from MCCI can treat it as one submode of | |
58 | * a proprietary scheme called "SAFE" ... without needing to know about | |
59 | * specific product/vendor IDs. So we do that, making it easier to use | |
60 | * those MS-Windows drivers. Those added descriptors make it resemble a | |
61 | * CDC MDLM device, but they don't change device behavior at all. (See | |
62 | * MCCI Engineering report 950198 "SAFE Networking Functions".) | |
1da177e4 LT |
63 | * |
64 | * A third option is also in use. Rather than CDC Ethernet, or something | |
65 | * simpler, Microsoft pushes their own approach: RNDIS. The published | |
66 | * RNDIS specs are ambiguous and appear to be incomplete, and are also | |
67 | * needlessly complex. | |
68 | */ | |
69 | ||
70 | #define DRIVER_DESC "Ethernet Gadget" | |
907cba35 | 71 | #define DRIVER_VERSION "May Day 2005" |
1da177e4 LT |
72 | |
73 | static const char shortname [] = "ether"; | |
74 | static const char driver_desc [] = DRIVER_DESC; | |
75 | ||
76 | #define RX_EXTRA 20 /* guard against rx overflows */ | |
77 | ||
1da177e4 | 78 | #include "rndis.h" |
45e45ab4 DB |
79 | |
80 | #ifndef CONFIG_USB_ETH_RNDIS | |
81 | #define rndis_uninit(x) do{}while(0) | |
82 | #define rndis_deregister(c) do{}while(0) | |
83 | #define rndis_exit() do{}while(0) | |
1da177e4 LT |
84 | #endif |
85 | ||
86 | /* CDC and RNDIS support the same host-chosen outgoing packet filters. */ | |
87 | #define DEFAULT_FILTER (USB_CDC_PACKET_TYPE_BROADCAST \ | |
7e27f18c DB |
88 | |USB_CDC_PACKET_TYPE_ALL_MULTICAST \ |
89 | |USB_CDC_PACKET_TYPE_PROMISCUOUS \ | |
90 | |USB_CDC_PACKET_TYPE_DIRECTED) | |
1da177e4 LT |
91 | |
92 | ||
93 | /*-------------------------------------------------------------------------*/ | |
94 | ||
95 | struct eth_dev { | |
96 | spinlock_t lock; | |
97 | struct usb_gadget *gadget; | |
98 | struct usb_request *req; /* for control responses */ | |
99 | struct usb_request *stat_req; /* for cdc & rndis status */ | |
100 | ||
101 | u8 config; | |
102 | struct usb_ep *in_ep, *out_ep, *status_ep; | |
103 | const struct usb_endpoint_descriptor | |
104 | *in, *out, *status; | |
789851cf DB |
105 | |
106 | spinlock_t req_lock; | |
1da177e4 LT |
107 | struct list_head tx_reqs, rx_reqs; |
108 | ||
109 | struct net_device *net; | |
110 | struct net_device_stats stats; | |
111 | atomic_t tx_qlen; | |
112 | ||
113 | struct work_struct work; | |
114 | unsigned zlp:1; | |
115 | unsigned cdc:1; | |
116 | unsigned rndis:1; | |
117 | unsigned suspended:1; | |
118 | u16 cdc_filter; | |
119 | unsigned long todo; | |
120 | #define WORK_RX_MEMORY 0 | |
121 | int rndis_config; | |
122 | u8 host_mac [ETH_ALEN]; | |
123 | }; | |
124 | ||
125 | /* This version autoconfigures as much as possible at run-time. | |
126 | * | |
127 | * It also ASSUMES a self-powered device, without remote wakeup, | |
128 | * although remote wakeup support would make sense. | |
129 | */ | |
1da177e4 LT |
130 | |
131 | /*-------------------------------------------------------------------------*/ | |
132 | ||
133 | /* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! | |
134 | * Instead: allocate your own, using normal USB-IF procedures. | |
135 | */ | |
136 | ||
137 | /* Thanks to NetChip Technologies for donating this product ID. | |
138 | * It's for devices with only CDC Ethernet configurations. | |
139 | */ | |
140 | #define CDC_VENDOR_NUM 0x0525 /* NetChip */ | |
141 | #define CDC_PRODUCT_NUM 0xa4a1 /* Linux-USB Ethernet Gadget */ | |
142 | ||
143 | /* For hardware that can't talk CDC, we use the same vendor ID that | |
144 | * ARM Linux has used for ethernet-over-usb, both with sa1100 and | |
145 | * with pxa250. We're protocol-compatible, if the host-side drivers | |
146 | * use the endpoint descriptors. bcdDevice (version) is nonzero, so | |
147 | * drivers that need to hard-wire endpoint numbers have a hook. | |
148 | * | |
149 | * The protocol is a minimal subset of CDC Ether, which works on any bulk | |
150 | * hardware that's not deeply broken ... even on hardware that can't talk | |
151 | * RNDIS (like SA-1100, with no interrupt endpoint, or anything that | |
152 | * doesn't handle control-OUT). | |
153 | */ | |
154 | #define SIMPLE_VENDOR_NUM 0x049f | |
155 | #define SIMPLE_PRODUCT_NUM 0x505a | |
156 | ||
157 | /* For hardware that can talk RNDIS and either of the above protocols, | |
158 | * use this ID ... the windows INF files will know it. Unless it's | |
159 | * used with CDC Ethernet, Linux 2.4 hosts will need updates to choose | |
160 | * the non-RNDIS configuration. | |
161 | */ | |
162 | #define RNDIS_VENDOR_NUM 0x0525 /* NetChip */ | |
163 | #define RNDIS_PRODUCT_NUM 0xa4a2 /* Ethernet/RNDIS Gadget */ | |
164 | ||
165 | ||
166 | /* Some systems will want different product identifers published in the | |
167 | * device descriptor, either numbers or strings or both. These string | |
168 | * parameters are in UTF-8 (superset of ASCII's 7 bit characters). | |
169 | */ | |
170 | ||
1afc64a3 | 171 | static ushort idVendor; |
1da177e4 LT |
172 | module_param(idVendor, ushort, S_IRUGO); |
173 | MODULE_PARM_DESC(idVendor, "USB Vendor ID"); | |
174 | ||
1afc64a3 | 175 | static ushort idProduct; |
1da177e4 LT |
176 | module_param(idProduct, ushort, S_IRUGO); |
177 | MODULE_PARM_DESC(idProduct, "USB Product ID"); | |
178 | ||
1afc64a3 | 179 | static ushort bcdDevice; |
1da177e4 LT |
180 | module_param(bcdDevice, ushort, S_IRUGO); |
181 | MODULE_PARM_DESC(bcdDevice, "USB Device version (BCD)"); | |
182 | ||
1afc64a3 | 183 | static char *iManufacturer; |
1da177e4 LT |
184 | module_param(iManufacturer, charp, S_IRUGO); |
185 | MODULE_PARM_DESC(iManufacturer, "USB Manufacturer string"); | |
186 | ||
1afc64a3 | 187 | static char *iProduct; |
1da177e4 LT |
188 | module_param(iProduct, charp, S_IRUGO); |
189 | MODULE_PARM_DESC(iProduct, "USB Product string"); | |
190 | ||
1afc64a3 AV |
191 | static char *iSerialNumber; |
192 | module_param(iSerialNumber, charp, S_IRUGO); | |
193 | MODULE_PARM_DESC(iSerialNumber, "SerialNumber"); | |
194 | ||
1da177e4 | 195 | /* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */ |
1afc64a3 | 196 | static char *dev_addr; |
1da177e4 LT |
197 | module_param(dev_addr, charp, S_IRUGO); |
198 | MODULE_PARM_DESC(dev_addr, "Device Ethernet Address"); | |
199 | ||
200 | /* this address is invisible to ifconfig */ | |
1afc64a3 | 201 | static char *host_addr; |
1da177e4 LT |
202 | module_param(host_addr, charp, S_IRUGO); |
203 | MODULE_PARM_DESC(host_addr, "Host Ethernet Address"); | |
204 | ||
205 | ||
206 | /*-------------------------------------------------------------------------*/ | |
207 | ||
208 | /* Include CDC support if we could run on CDC-capable hardware. */ | |
209 | ||
210 | #ifdef CONFIG_USB_GADGET_NET2280 | |
211 | #define DEV_CONFIG_CDC | |
212 | #endif | |
213 | ||
214 | #ifdef CONFIG_USB_GADGET_DUMMY_HCD | |
215 | #define DEV_CONFIG_CDC | |
216 | #endif | |
217 | ||
218 | #ifdef CONFIG_USB_GADGET_GOKU | |
219 | #define DEV_CONFIG_CDC | |
220 | #endif | |
221 | ||
222 | #ifdef CONFIG_USB_GADGET_LH7A40X | |
223 | #define DEV_CONFIG_CDC | |
224 | #endif | |
225 | ||
226 | #ifdef CONFIG_USB_GADGET_MQ11XX | |
227 | #define DEV_CONFIG_CDC | |
228 | #endif | |
229 | ||
230 | #ifdef CONFIG_USB_GADGET_OMAP | |
231 | #define DEV_CONFIG_CDC | |
232 | #endif | |
233 | ||
234 | #ifdef CONFIG_USB_GADGET_N9604 | |
235 | #define DEV_CONFIG_CDC | |
236 | #endif | |
237 | ||
238 | #ifdef CONFIG_USB_GADGET_PXA27X | |
239 | #define DEV_CONFIG_CDC | |
240 | #endif | |
241 | ||
11d54898 DB |
242 | #ifdef CONFIG_USB_GADGET_S3C2410 |
243 | #define DEV_CONFIG_CDC | |
244 | #endif | |
245 | ||
1da177e4 LT |
246 | #ifdef CONFIG_USB_GADGET_AT91 |
247 | #define DEV_CONFIG_CDC | |
248 | #endif | |
249 | ||
1c05ad44 DB |
250 | #ifdef CONFIG_USB_GADGET_MUSBHSFC |
251 | #define DEV_CONFIG_CDC | |
252 | #endif | |
253 | ||
bfb2c965 | 254 | #ifdef CONFIG_USB_GADGET_MUSB_HDRC |
1c05ad44 DB |
255 | #define DEV_CONFIG_CDC |
256 | #endif | |
257 | ||
55b3fd41 | 258 | #ifdef CONFIG_USB_GADGET_ATMEL_USBA |