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