]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/net/usb/cdc_subset.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
[karo-tx-linux.git] / drivers / net / usb / cdc_subset.c
1 /*
2  * Simple "CDC Subset" USB Networking Links
3  * Copyright (C) 2000-2005 by David Brownell
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include <linux/module.h>
20 #include <linux/kmod.h>
21 #include <linux/netdevice.h>
22 #include <linux/etherdevice.h>
23 #include <linux/ethtool.h>
24 #include <linux/workqueue.h>
25 #include <linux/mii.h>
26 #include <linux/usb.h>
27 #include <linux/usb/usbnet.h>
28
29
30 /*
31  * This supports simple USB network links that don't require any special
32  * framing or hardware control operations.  The protocol used here is a
33  * strict subset of CDC Ethernet, with three basic differences reflecting
34  * the goal that almost any hardware should run it:
35  *
36  *  - Minimal runtime control:  one interface, no altsettings, and
37  *    no vendor or class specific control requests.  If a device is
38  *    configured, it is allowed to exchange packets with the host.
39  *    Fancier models would mean not working on some hardware.
40  *
41  *  - Minimal manufacturing control:  no IEEE "Organizationally
42  *    Unique ID" required, or an EEPROMs to store one.  Each host uses
43  *    one random "locally assigned" Ethernet address instead, which can
44  *    of course be overridden using standard tools like "ifconfig".
45  *    (With 2^46 such addresses, same-net collisions are quite rare.)
46  *
47  *  - There is no additional framing data for USB.  Packets are written
48  *    exactly as in CDC Ethernet, starting with an Ethernet header and
49  *    terminated by a short packet.  However, the host will never send a
50  *    zero length packet; some systems can't handle those robustly.
51  *
52  * Anything that can transmit and receive USB bulk packets can implement
53  * this protocol.  That includes both smart peripherals and quite a lot
54  * of "host-to-host" USB cables (which embed two devices back-to-back).
55  *
56  * Note that although Linux may use many of those host-to-host links
57  * with this "cdc_subset" framing, that doesn't mean there may not be a
58  * better approach.  Handling the "other end unplugs/replugs" scenario
59  * well tends to require chip-specific vendor requests.  Also, Windows
60  * peers at the other end of host-to-host cables may expect their own
61  * framing to be used rather than this "cdc_subset" model.
62  */
63
64 #if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX)
65 /* PDA style devices are always connected if present */
66 static int always_connected (struct usbnet *dev)
67 {
68         return 0;
69 }
70 #endif
71
72 #ifdef  CONFIG_USB_ALI_M5632
73 #define HAVE_HARDWARE
74
75 /*-------------------------------------------------------------------------
76  *
77  * ALi M5632 driver ... does high speed
78  *
79  * NOTE that the MS-Windows drivers for this chip use some funky and
80  * (naturally) undocumented 7-byte prefix to each packet, so this is a
81  * case where we don't currently interoperate.  Also, once you unplug
82  * one end of the cable, you need to replug the other end too ... since
83  * chip docs are unavailable, there's no way to reset the relevant state
84  * short of a power cycle.
85  *
86  *-------------------------------------------------------------------------*/
87
88 static void m5632_recover(struct usbnet *dev)
89 {
90         struct usb_device       *udev = dev->udev;
91         struct usb_interface    *intf = dev->intf;
92         int r;
93
94         r = usb_lock_device_for_reset(udev, intf);
95         if (r < 0)
96                 return;
97
98         usb_reset_device(udev);
99         usb_unlock_device(udev);
100 }
101
102 static int dummy_prereset(struct usb_interface *intf)
103 {
104         return 0;
105 }
106
107 static int dummy_postreset(struct usb_interface *intf)
108 {
109         return 0;
110 }
111
112 static const struct driver_info ali_m5632_info = {
113         .description =  "ALi M5632",
114         .flags       = FLAG_POINTTOPOINT,
115         .recover     = m5632_recover,
116 };
117
118 #endif
119
120 \f
121 #ifdef  CONFIG_USB_AN2720
122 #define HAVE_HARDWARE
123
124 /*-------------------------------------------------------------------------
125  *
126  * AnchorChips 2720 driver ... http://www.cypress.com
127  *
128  * This doesn't seem to have a way to detect whether the peer is
129  * connected, or need any reset handshaking.  It's got pretty big
130  * internal buffers (handles most of a frame's worth of data).
131  * Chip data sheets don't describe any vendor control messages.
132  *
133  *-------------------------------------------------------------------------*/
134
135 static const struct driver_info an2720_info = {
136         .description =  "AnchorChips/Cypress 2720",
137         .flags       = FLAG_POINTTOPOINT,
138         // no reset available!
139         // no check_connect available!
140
141         .in = 2, .out = 2,              // direction distinguishes these
142 };
143
144 #endif  /* CONFIG_USB_AN2720 */
145
146 \f
147 #ifdef  CONFIG_USB_BELKIN
148 #define HAVE_HARDWARE
149
150 /*-------------------------------------------------------------------------
151  *
152  * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller
153  *
154  * ... also two eTEK designs, including one sold as "Advance USBNET"
155  *
156  *-------------------------------------------------------------------------*/
157
158 static const struct driver_info belkin_info = {
159         .description =  "Belkin, eTEK, or compatible",
160         .flags       = FLAG_POINTTOPOINT,
161 };
162
163 #endif  /* CONFIG_USB_BELKIN */
164
165
166 \f
167 #ifdef  CONFIG_USB_EPSON2888
168 #define HAVE_HARDWARE
169
170 /*-------------------------------------------------------------------------
171  *
172  * EPSON USB clients
173  *
174  * This is the same idea as Linux PDAs (below) except the firmware in the
175  * device might not be Tux-powered.  Epson provides reference firmware that
176  * implements this interface.  Product developers can reuse or modify that
177  * code, such as by using their own product and vendor codes.
178  *
179  * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
180  *
181  *-------------------------------------------------------------------------*/
182
183 static const struct driver_info epson2888_info = {
184         .description =  "Epson USB Device",
185         .check_connect = always_connected,
186         .flags = FLAG_POINTTOPOINT,
187
188         .in = 4, .out = 3,
189 };
190
191 #endif  /* CONFIG_USB_EPSON2888 */
192
193 \f
194 /*-------------------------------------------------------------------------
195  *
196  * info from Jonathan McDowell <noodles@earth.li>
197  *
198  *-------------------------------------------------------------------------*/
199 #ifdef CONFIG_USB_KC2190
200 #define HAVE_HARDWARE
201 static const struct driver_info kc2190_info = {
202         .description =  "KC Technology KC-190",
203         .flags = FLAG_POINTTOPOINT,
204 };
205 #endif /* CONFIG_USB_KC2190 */
206
207 \f
208 #ifdef  CONFIG_USB_ARMLINUX
209 #define HAVE_HARDWARE
210
211 /*-------------------------------------------------------------------------
212  *
213  * Intel's SA-1100 chip integrates basic USB support, and is used
214  * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
215  * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
216  * network using minimal USB framing data.
217  *
218  * This describes the driver currently in standard ARM Linux kernels.
219  * The Zaurus uses a different driver (see later).
220  *
221  * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
222  * and different USB endpoint numbering than the SA1100 devices.  The
223  * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
224  * so we rely on the endpoint descriptors.
225  *
226  *-------------------------------------------------------------------------*/
227
228 static const struct driver_info linuxdev_info = {
229         .description =  "Linux Device",
230         .check_connect = always_connected,
231         .flags = FLAG_POINTTOPOINT,
232 };
233
234 static const struct driver_info yopy_info = {
235         .description =  "Yopy",
236         .check_connect = always_connected,
237         .flags = FLAG_POINTTOPOINT,
238 };
239
240 static const struct driver_info blob_info = {
241         .description =  "Boot Loader OBject",
242         .check_connect = always_connected,
243         .flags = FLAG_POINTTOPOINT,
244 };
245
246 #endif  /* CONFIG_USB_ARMLINUX */
247
248 \f
249 /*-------------------------------------------------------------------------*/
250
251 #ifndef HAVE_HARDWARE
252 #warning You need to configure some hardware for this driver
253 #endif
254
255 /*
256  * chip vendor names won't normally be on the cables, and
257  * may not be on the device.
258  */
259
260 static const struct usb_device_id       products [] = {
261
262 #ifdef  CONFIG_USB_ALI_M5632
263 {
264         USB_DEVICE (0x0402, 0x5632),    // ALi defaults
265         .driver_info =  (unsigned long) &ali_m5632_info,
266 },
267 {
268         USB_DEVICE (0x182d,0x207c),     // SiteCom CN-124
269         .driver_info =  (unsigned long) &ali_m5632_info,
270 },
271 #endif
272
273 #ifdef  CONFIG_USB_AN2720
274 {
275         USB_DEVICE (0x0547, 0x2720),    // AnchorChips defaults
276         .driver_info =  (unsigned long) &an2720_info,
277 }, {
278         USB_DEVICE (0x0547, 0x2727),    // Xircom PGUNET
279         .driver_info =  (unsigned long) &an2720_info,
280 },
281 #endif
282
283 #ifdef  CONFIG_USB_BELKIN
284 {
285         USB_DEVICE (0x050d, 0x0004),    // Belkin
286         .driver_info =  (unsigned long) &belkin_info,
287 }, {
288         USB_DEVICE (0x056c, 0x8100),    // eTEK
289         .driver_info =  (unsigned long) &belkin_info,
290 }, {
291         USB_DEVICE (0x0525, 0x9901),    // Advance USBNET (eTEK)
292         .driver_info =  (unsigned long) &belkin_info,
293 },
294 #endif
295
296 #ifdef  CONFIG_USB_EPSON2888
297 {
298         USB_DEVICE (0x0525, 0x2888),    // EPSON USB client
299         .driver_info    = (unsigned long) &epson2888_info,
300 },
301 #endif
302
303 #ifdef CONFIG_USB_KC2190
304 {
305         USB_DEVICE (0x050f, 0x0190),    // KC-190
306         .driver_info =  (unsigned long) &kc2190_info,
307 },
308 #endif
309
310 #ifdef  CONFIG_USB_ARMLINUX
311 /*
312  * SA-1100 using standard ARM Linux kernels, or compatible.
313  * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
314  * The sa-1100 "usb-eth" driver handles the basic framing.
315  *
316  * PXA25x or PXA210 ...  these use a "usb-eth" driver much like
317  * the sa1100 one, but hardware uses different endpoint numbers.
318  *
319  * Or the Linux "Ethernet" gadget on hardware that can't talk
320  * CDC Ethernet (e.g., no altsettings), in either of two modes:
321  *  - acting just like the old "usb-eth" firmware, though
322  *    the implementation is different
323  *  - supporting RNDIS as the first/default configuration for
324  *    MS-Windows interop; Linux needs to use the other config
325  */
326 {
327         // 1183 = 0x049F, both used as hex values?
328         // Compaq "Itsy" vendor/product id
329         USB_DEVICE (0x049F, 0x505A),    // usb-eth, or compatible
330         .driver_info =  (unsigned long) &linuxdev_info,
331 }, {
332         USB_DEVICE (0x0E7E, 0x1001),    // G.Mate "Yopy"
333         .driver_info =  (unsigned long) &yopy_info,
334 }, {
335         USB_DEVICE (0x8086, 0x07d3),    // "blob" bootloader
336         .driver_info =  (unsigned long) &blob_info,
337 }, {
338         USB_DEVICE (0x1286, 0x8001),    // "blob" bootloader
339         .driver_info =  (unsigned long) &blob_info,
340 }, {
341         // Linux Ethernet/RNDIS gadget, mostly on PXA, second config
342         // e.g. Gumstix, current OpenZaurus, ... or anything else
343         // that just enables this gadget option.
344         USB_DEVICE (0x0525, 0xa4a2),
345         .driver_info =  (unsigned long) &linuxdev_info,
346 },
347 #endif
348
349         { },            // END
350 };
351 MODULE_DEVICE_TABLE(usb, products);
352
353 /*-------------------------------------------------------------------------*/
354
355 static struct usb_driver cdc_subset_driver = {
356         .name =         "cdc_subset",
357         .probe =        usbnet_probe,
358         .suspend =      usbnet_suspend,
359         .resume =       usbnet_resume,
360         .pre_reset =    dummy_prereset,
361         .post_reset =   dummy_postreset,
362         .disconnect =   usbnet_disconnect,
363         .id_table =     products,
364         .disable_hub_initiated_lpm = 1,
365 };
366
367 module_usb_driver(cdc_subset_driver);
368
369 MODULE_AUTHOR("David Brownell");
370 MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links");
371 MODULE_LICENSE("GPL");