diff options
author | David Brownell <david-b@pacbell.net> | 2005-08-31 12:53:58 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-09-08 19:28:32 -0400 |
commit | 0aa599c5644fddd3052433c5335260108a8a39a2 (patch) | |
tree | 53ff1eadd9d5386e7b9912b1d2728d150ad8567f /drivers/usb/net/zaurus.c | |
parent | 47ee3051c856cc2aa95d35d577a8cb37279d540f (diff) |
[PATCH] USB: usbnet (6/9) module for Zaurii and compatibles
This moves usbnet support for Zaurus and compatibles into its own module.
Other than exporting a couple of helper functions, this just involved
shuffling some code and updating the comments.
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/net/zaurus.c')
-rw-r--r-- | drivers/usb/net/zaurus.c | 386 |
1 files changed, 386 insertions, 0 deletions
diff --git a/drivers/usb/net/zaurus.c b/drivers/usb/net/zaurus.c new file mode 100644 index 000000000000..ee3b892aeabc --- /dev/null +++ b/drivers/usb/net/zaurus.c | |||
@@ -0,0 +1,386 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz> | ||
3 | * Copyright (C) 2002-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 | // #define DEBUG // error path messages, extra info | ||
21 | // #define VERBOSE // more; success messages | ||
22 | |||
23 | #include <linux/config.h> | ||
24 | #ifdef CONFIG_USB_DEBUG | ||
25 | # define DEBUG | ||
26 | #endif | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/sched.h> | ||
29 | #include <linux/init.h> | ||
30 | #include <linux/netdevice.h> | ||
31 | #include <linux/ethtool.h> | ||
32 | #include <linux/workqueue.h> | ||
33 | #include <linux/mii.h> | ||
34 | #include <linux/crc32.h> | ||
35 | #include <linux/usb.h> | ||
36 | #include <linux/usb_cdc.h> | ||
37 | |||
38 | #include "usbnet.h" | ||
39 | |||
40 | |||
41 | /* | ||
42 | * All known Zaurii lie about their standards conformance. At least | ||
43 | * the earliest SA-1100 models lie by saying they support CDC Ethernet. | ||
44 | * Some later models (especially PXA-25x and PXA-27x based ones) lie | ||
45 | * and say they support CDC MDLM (for access to cell phone modems). | ||
46 | * | ||
47 | * There are non-Zaurus products that use these same protocols too. | ||
48 | * | ||
49 | * The annoying thing is that at the same time Sharp was developing | ||
50 | * that annoying standards-breaking software, the Linux community had | ||
51 | * a simple "CDC Subset" working reliably on the same SA-1100 hardware. | ||
52 | * That is, the same functionality but not violating standards. | ||
53 | * | ||
54 | * The CDC Ethernet nonconformance points are troublesome to hosts | ||
55 | * with a true CDC Ethernet implementation: | ||
56 | * - Framing appends a CRC, which the spec says drivers "must not" do; | ||
57 | * - Transfers data in altsetting zero, instead of altsetting 1; | ||
58 | * - All these peripherals use the same ethernet address. | ||
59 | * | ||
60 | * The CDC MDLM nonconformance is less immediately troublesome, since all | ||
61 | * MDLM implementations are quasi-proprietary anyway. | ||
62 | */ | ||
63 | |||
64 | static struct sk_buff * | ||
65 | zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, unsigned flags) | ||
66 | { | ||
67 | int padlen; | ||
68 | struct sk_buff *skb2; | ||
69 | |||
70 | padlen = 2; | ||
71 | if (!skb_cloned(skb)) { | ||
72 | int tailroom = skb_tailroom(skb); | ||
73 | if ((padlen + 4) <= tailroom) | ||
74 | goto done; | ||
75 | } | ||
76 | skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags); | ||
77 | dev_kfree_skb_any(skb); | ||
78 | skb = skb2; | ||
79 | if (skb) { | ||
80 | u32 fcs; | ||
81 | done: | ||
82 | fcs = crc32_le(~0, skb->data, skb->len); | ||
83 | fcs = ~fcs; | ||
84 | |||
85 | *skb_put (skb, 1) = fcs & 0xff; | ||
86 | *skb_put (skb, 1) = (fcs>> 8) & 0xff; | ||
87 | *skb_put (skb, 1) = (fcs>>16) & 0xff; | ||
88 | *skb_put (skb, 1) = (fcs>>24) & 0xff; | ||
89 | } | ||
90 | return skb; | ||
91 | } | ||
92 | |||
93 | static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf) | ||
94 | { | ||
95 | /* Belcarra's funky framing has other options; mostly | ||
96 | * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes. | ||
97 | */ | ||
98 | dev->net->hard_header_len += 6; | ||
99 | dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu; | ||
100 | return usbnet_generic_cdc_bind(dev, intf); | ||
101 | } | ||
102 | |||
103 | /* PDA style devices are always connected if present */ | ||
104 | static int always_connected (struct usbnet *dev) | ||
105 | { | ||
106 | return 0; | ||
107 | } | ||
108 | |||
109 | static const struct driver_info zaurus_sl5x00_info = { | ||
110 | .description = "Sharp Zaurus SL-5x00", | ||
111 | .flags = FLAG_FRAMING_Z, | ||
112 | .check_connect = always_connected, | ||
113 | .bind = zaurus_bind, | ||
114 | .unbind = usbnet_cdc_unbind, | ||
115 | .tx_fixup = zaurus_tx_fixup, | ||
116 | }; | ||
117 | #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info) | ||
118 | |||
119 | static const struct driver_info zaurus_pxa_info = { | ||
120 | .description = "Sharp Zaurus, PXA-2xx based", | ||
121 | .flags = FLAG_FRAMING_Z, | ||
122 | .check_connect = always_connected, | ||
123 | .bind = zaurus_bind, | ||
124 | .unbind = usbnet_cdc_unbind, | ||
125 | .tx_fixup = zaurus_tx_fixup, | ||
126 | }; | ||
127 | #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info) | ||
128 | |||
129 | static const struct driver_info olympus_mxl_info = { | ||
130 | .description = "Olympus R1000", | ||
131 | .flags = FLAG_FRAMING_Z, | ||
132 | .check_connect = always_connected, | ||
133 | .bind = zaurus_bind, | ||
134 | .unbind = usbnet_cdc_unbind, | ||
135 | .tx_fixup = zaurus_tx_fixup, | ||
136 | }; | ||
137 | #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info) | ||
138 | |||
139 | |||
140 | /* Some more recent products using Lineo/Belcarra code will wrongly claim | ||
141 | * CDC MDLM conformance. They aren't conformant: data endpoints live | ||
142 | * in the control interface, there's no data interface, and it's not used | ||
143 | * to talk to a cell phone radio. But at least we can detect these two | ||
144 | * pseudo-classes, rather than growing this product list with entries for | ||
145 | * each new nonconformant product (sigh). | ||
146 | */ | ||
147 | static const u8 safe_guid[16] = { | ||
148 | 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6, | ||
149 | 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f, | ||
150 | }; | ||
151 | static const u8 blan_guid[16] = { | ||
152 | 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70, | ||
153 | 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37, | ||
154 | }; | ||
155 | |||
156 | static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf) | ||
157 | { | ||
158 | u8 *buf = intf->cur_altsetting->extra; | ||
159 | int len = intf->cur_altsetting->extralen; | ||
160 | struct usb_cdc_mdlm_desc *desc = NULL; | ||
161 | struct usb_cdc_mdlm_detail_desc *detail = NULL; | ||
162 | |||
163 | while (len > 3) { | ||
164 | if (buf [1] != USB_DT_CS_INTERFACE) | ||
165 | goto next_desc; | ||
166 | |||
167 | /* use bDescriptorSubType, and just verify that we get a | ||
168 | * "BLAN" (or "SAFE") descriptor. | ||
169 | */ | ||
170 | switch (buf [2]) { | ||
171 | case USB_CDC_MDLM_TYPE: | ||
172 | if (desc) { | ||
173 | dev_dbg(&intf->dev, "extra MDLM\n"); | ||
174 | goto bad_desc; | ||
175 | } | ||
176 | desc = (void *) buf; | ||
177 | if (desc->bLength != sizeof *desc) { | ||
178 | dev_dbg(&intf->dev, "MDLM len %u\n", | ||
179 | desc->bLength); | ||
180 | goto bad_desc; | ||
181 | } | ||
182 | /* expect bcdVersion 1.0, ignore */ | ||
183 | if (memcmp(&desc->bGUID, blan_guid, 16) | ||
184 | && memcmp(&desc->bGUID, safe_guid, 16) ) { | ||
185 | /* hey, this one might _really_ be MDLM! */ | ||
186 | dev_dbg(&intf->dev, "MDLM guid\n"); | ||
187 | goto bad_desc; | ||
188 | } | ||
189 | break; | ||
190 | case USB_CDC_MDLM_DETAIL_TYPE: | ||
191 | if (detail) { | ||
192 | dev_dbg(&intf->dev, "extra MDLM detail\n"); | ||
193 | goto bad_desc; | ||
194 | } | ||
195 | detail = (void *) buf; | ||
196 | switch (detail->bGuidDescriptorType) { | ||
197 | case 0: /* "SAFE" */ | ||
198 | if (detail->bLength != (sizeof *detail + 2)) | ||
199 | goto bad_detail; | ||
200 | break; | ||
201 | case 1: /* "BLAN" */ | ||
202 | if (detail->bLength != (sizeof *detail + 3)) | ||
203 | goto bad_detail; | ||
204 | break; | ||
205 | default: | ||
206 | goto bad_detail; | ||
207 | } | ||
208 | |||
209 | /* assuming we either noticed BLAN already, or will | ||
210 | * find it soon, there are some data bytes here: | ||
211 | * - bmNetworkCapabilities (unused) | ||
212 | * - bmDataCapabilities (bits, see below) | ||
213 | * - bPad (ignored, for PADAFTER -- BLAN-only) | ||
214 | * bits are: | ||
215 | * - 0x01 -- Zaurus framing (add CRC) | ||
216 | * - 0x02 -- PADBEFORE (CRC includes some padding) | ||
217 | * - 0x04 -- PADAFTER (some padding after CRC) | ||
218 | * - 0x08 -- "fermat" packet mangling (for hw bugs) | ||
219 | * the PADBEFORE appears not to matter; we interop | ||
220 | * with devices that use it and those that don't. | ||
221 | */ | ||
222 | if ((detail->bDetailData[1] & ~0x02) != 0x01) { | ||
223 | /* bmDataCapabilites == 0 would be fine too, | ||
224 | * but framing is minidriver-coupled for now. | ||
225 | */ | ||
226 | bad_detail: | ||
227 | dev_dbg(&intf->dev, | ||
228 | "bad MDLM detail, %d %d %d\n", | ||
229 | detail->bLength, | ||
230 | detail->bDetailData[0], | ||
231 | detail->bDetailData[2]); | ||
232 | goto bad_desc; | ||
233 | } | ||
234 | break; | ||
235 | } | ||
236 | next_desc: | ||
237 | len -= buf [0]; /* bLength */ | ||
238 | buf += buf [0]; | ||
239 | } | ||
240 | |||
241 | if (!desc || !detail) { | ||
242 | dev_dbg(&intf->dev, "missing cdc mdlm %s%sdescriptor\n", | ||
243 | desc ? "" : "func ", | ||
244 | detail ? "" : "detail "); | ||
245 | goto bad_desc; | ||
246 | } | ||
247 | |||
248 | /* There's probably a CDC Ethernet descriptor there, but we can't | ||
249 | * rely on the Ethernet address it provides since not all vendors | ||
250 | * bother to make it unique. Likewise there's no point in tracking | ||
251 | * of the CDC event notifications. | ||
252 | */ | ||
253 | return usbnet_get_endpoints(dev, intf); | ||
254 | |||
255 | bad_desc: | ||
256 | dev_info(&dev->udev->dev, "unsupported MDLM descriptors\n"); | ||
257 | return -ENODEV; | ||
258 | } | ||
259 | |||
260 | static const struct driver_info bogus_mdlm_info = { | ||
261 | .description = "pseudo-MDLM (BLAN) device", | ||
262 | .flags = FLAG_FRAMING_Z, | ||
263 | .check_connect = always_connected, | ||
264 | .tx_fixup = zaurus_tx_fixup, | ||
265 | .bind = blan_mdlm_bind, | ||
266 | }; | ||
267 | |||
268 | static const struct usb_device_id products [] = { | ||
269 | #define ZAURUS_MASTER_INTERFACE \ | ||
270 | .bInterfaceClass = USB_CLASS_COMM, \ | ||
271 | .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \ | ||
272 | .bInterfaceProtocol = USB_CDC_PROTO_NONE | ||
273 | |||
274 | /* SA-1100 based Sharp Zaurus ("collie"), or compatible. */ | ||
275 | { | ||
276 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
277 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
278 | .idVendor = 0x04DD, | ||
279 | .idProduct = 0x8004, | ||
280 | ZAURUS_MASTER_INTERFACE, | ||
281 | .driver_info = ZAURUS_STRONGARM_INFO, | ||
282 | }, | ||
283 | |||
284 | /* PXA-2xx based models are also lying-about-cdc. If you add any | ||
285 | * more devices that claim to be CDC Ethernet, make sure they get | ||
286 | * added to the blacklist in cdc_ether too. | ||
287 | * | ||
288 | * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries, | ||
289 | * unlike the older ones with 2.4 "embedix" kernels. | ||
290 | */ | ||
291 | { | ||
292 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
293 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
294 | .idVendor = 0x04DD, | ||
295 | .idProduct = 0x8005, /* A-300 */ | ||
296 | ZAURUS_MASTER_INTERFACE, | ||
297 | .driver_info = ZAURUS_PXA_INFO, | ||
298 | }, { | ||
299 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
300 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
301 | .idVendor = 0x04DD, | ||
302 | .idProduct = 0x8006, /* B-500/SL-5600 */ | ||
303 | ZAURUS_MASTER_INTERFACE, | ||
304 | .driver_info = ZAURUS_PXA_INFO, | ||
305 | }, { | ||
306 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
307 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
308 | .idVendor = 0x04DD, | ||
309 | .idProduct = 0x8007, /* C-700 */ | ||
310 | ZAURUS_MASTER_INTERFACE, | ||
311 | .driver_info = ZAURUS_PXA_INFO, | ||
312 | }, { | ||
313 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
314 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
315 | .idVendor = 0x04DD, | ||
316 | .idProduct = 0x9031, /* C-750 C-760 */ | ||
317 | ZAURUS_MASTER_INTERFACE, | ||
318 | .driver_info = ZAURUS_PXA_INFO, | ||
319 | }, { | ||
320 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
321 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
322 | .idVendor = 0x04DD, | ||
323 | .idProduct = 0x9032, /* SL-6000 */ | ||
324 | ZAURUS_MASTER_INTERFACE, | ||
325 | .driver_info = ZAURUS_PXA_INFO, | ||
326 | }, { | ||
327 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
328 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
329 | .idVendor = 0x04DD, | ||
330 | /* reported with some C860 units */ | ||
331 | .idProduct = 0x9050, /* C-860 */ | ||
332 | ZAURUS_MASTER_INTERFACE, | ||
333 | .driver_info = ZAURUS_PXA_INFO, | ||
334 | }, | ||
335 | |||
336 | |||
337 | /* At least some of the newest PXA units have very different lies about | ||
338 | * their standards support: they claim to be cell phones offering | ||
339 | * direct access to their radios! (No, they don't conform to CDC MDLM.) | ||
340 | */ | ||
341 | { | ||
342 | USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM, | ||
343 | USB_CDC_PROTO_NONE), | ||
344 | .driver_info = (unsigned long) &bogus_mdlm_info, | ||
345 | }, | ||
346 | |||
347 | /* Olympus has some models with a Zaurus-compatible option. | ||
348 | * R-1000 uses a FreeScale i.MXL cpu (ARMv4T) | ||
349 | */ | ||
350 | { | ||
351 | .match_flags = USB_DEVICE_ID_MATCH_INT_INFO | ||
352 | | USB_DEVICE_ID_MATCH_DEVICE, | ||
353 | .idVendor = 0x07B4, | ||
354 | .idProduct = 0x0F02, /* R-1000 */ | ||
355 | ZAURUS_MASTER_INTERFACE, | ||
356 | .driver_info = OLYMPUS_MXL_INFO, | ||
357 | }, | ||
358 | { }, // END | ||
359 | }; | ||
360 | MODULE_DEVICE_TABLE(usb, products); | ||
361 | |||
362 | static struct usb_driver zaurus_driver = { | ||
363 | .owner = THIS_MODULE, | ||
364 | .name = "zaurus", | ||
365 | .id_table = products, | ||
366 | .probe = usbnet_probe, | ||
367 | .disconnect = usbnet_disconnect, | ||
368 | .suspend = usbnet_suspend, | ||
369 | .resume = usbnet_resume, | ||
370 | }; | ||
371 | |||
372 | static int __init zaurus_init(void) | ||
373 | { | ||
374 | return usb_register(&zaurus_driver); | ||
375 | } | ||
376 | module_init(zaurus_init); | ||
377 | |||
378 | static void __exit zaurus_exit(void) | ||
379 | { | ||
380 | usb_deregister(&zaurus_driver); | ||
381 | } | ||
382 | module_exit(zaurus_exit); | ||
383 | |||
384 | MODULE_AUTHOR("Pavel Machek, David Brownell"); | ||
385 | MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products"); | ||
386 | MODULE_LICENSE("GPL"); | ||