2 * Copyright (C) 2002 Pavel Machek <pavel@ucw.cz>
3 * Copyright (C) 2002-2005 by David Brownell
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.
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.
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/>.
19 // #define DEBUG // error path messages, extra info
20 // #define VERBOSE // more; success messages
22 #include <linux/module.h>
23 #include <linux/netdevice.h>
24 #include <linux/ethtool.h>
25 #include <linux/workqueue.h>
26 #include <linux/mii.h>
27 #include <linux/crc32.h>
28 #include <linux/usb.h>
29 #include <linux/usb/cdc.h>
30 #include <linux/usb/usbnet.h>
34 * All known Zaurii lie about their standards conformance. At least
35 * the earliest SA-1100 models lie by saying they support CDC Ethernet.
36 * Some later models (especially PXA-25x and PXA-27x based ones) lie
37 * and say they support CDC MDLM (for access to cell phone modems).
39 * There are non-Zaurus products that use these same protocols too.
41 * The annoying thing is that at the same time Sharp was developing
42 * that annoying standards-breaking software, the Linux community had
43 * a simple "CDC Subset" working reliably on the same SA-1100 hardware.
44 * That is, the same functionality but not violating standards.
46 * The CDC Ethernet nonconformance points are troublesome to hosts
47 * with a true CDC Ethernet implementation:
48 * - Framing appends a CRC, which the spec says drivers "must not" do;
49 * - Transfers data in altsetting zero, instead of altsetting 1;
50 * - All these peripherals use the same ethernet address.
52 * The CDC MDLM nonconformance is less immediately troublesome, since all
53 * MDLM implementations are quasi-proprietary anyway.
56 static struct sk_buff
*
57 zaurus_tx_fixup(struct usbnet
*dev
, struct sk_buff
*skb
, gfp_t flags
)
63 if (!skb_cloned(skb
)) {
64 int tailroom
= skb_tailroom(skb
);
65 if ((padlen
+ 4) <= tailroom
)
68 skb2
= skb_copy_expand(skb
, 0, 4 + padlen
, flags
);
69 dev_kfree_skb_any(skb
);
74 fcs
= crc32_le(~0, skb
->data
, skb
->len
);
77 *skb_put (skb
, 1) = fcs
& 0xff;
78 *skb_put (skb
, 1) = (fcs
>> 8) & 0xff;
79 *skb_put (skb
, 1) = (fcs
>>16) & 0xff;
80 *skb_put (skb
, 1) = (fcs
>>24) & 0xff;
85 static int zaurus_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
87 /* Belcarra's funky framing has other options; mostly
88 * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
90 dev
->net
->hard_header_len
+= 6;
91 dev
->rx_urb_size
= dev
->net
->hard_header_len
+ dev
->net
->mtu
;
92 return usbnet_generic_cdc_bind(dev
, intf
);
95 /* PDA style devices are always connected if present */
96 static int always_connected (struct usbnet
*dev
)
101 static const struct driver_info zaurus_sl5x00_info
= {
102 .description
= "Sharp Zaurus SL-5x00",
103 .flags
= FLAG_POINTTOPOINT
| FLAG_FRAMING_Z
,
104 .check_connect
= always_connected
,
106 .unbind
= usbnet_cdc_unbind
,
107 .tx_fixup
= zaurus_tx_fixup
,
109 #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
111 static const struct driver_info zaurus_pxa_info
= {
112 .description
= "Sharp Zaurus, PXA-2xx based",
113 .flags
= FLAG_POINTTOPOINT
| FLAG_FRAMING_Z
,
114 .check_connect
= always_connected
,
116 .unbind
= usbnet_cdc_unbind
,
117 .tx_fixup
= zaurus_tx_fixup
,
119 #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
121 static const struct driver_info olympus_mxl_info
= {
122 .description
= "Olympus R1000",
123 .flags
= FLAG_POINTTOPOINT
| FLAG_FRAMING_Z
,
124 .check_connect
= always_connected
,
126 .unbind
= usbnet_cdc_unbind
,
127 .tx_fixup
= zaurus_tx_fixup
,
129 #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
132 /* Some more recent products using Lineo/Belcarra code will wrongly claim
133 * CDC MDLM conformance. They aren't conformant: data endpoints live
134 * in the control interface, there's no data interface, and it's not used
135 * to talk to a cell phone radio. But at least we can detect these two
136 * pseudo-classes, rather than growing this product list with entries for
137 * each new nonconformant product (sigh).
139 static const u8 safe_guid
[16] = {
140 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
141 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
143 static const u8 blan_guid
[16] = {
144 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
145 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
148 static int blan_mdlm_bind(struct usbnet
*dev
, struct usb_interface
*intf
)
150 u8
*buf
= intf
->cur_altsetting
->extra
;
151 int len
= intf
->cur_altsetting
->extralen
;
152 struct usb_cdc_mdlm_desc
*desc
= NULL
;
153 struct usb_cdc_mdlm_detail_desc
*detail
= NULL
;
156 if (buf
[1] != USB_DT_CS_INTERFACE
)
159 /* use bDescriptorSubType, and just verify that we get a
160 * "BLAN" (or "SAFE") descriptor.
163 case USB_CDC_MDLM_TYPE
:
165 dev_dbg(&intf
->dev
, "extra MDLM\n");
169 if (desc
->bLength
!= sizeof *desc
) {
170 dev_dbg(&intf
->dev
, "MDLM len %u\n",
174 /* expect bcdVersion 1.0, ignore */
175 if (memcmp(&desc
->bGUID
, blan_guid
, 16) &&
176 memcmp(&desc
->bGUID
, safe_guid
, 16)) {
177 /* hey, this one might _really_ be MDLM! */
178 dev_dbg(&intf
->dev
, "MDLM guid\n");
182 case USB_CDC_MDLM_DETAIL_TYPE
:
184 dev_dbg(&intf
->dev
, "extra MDLM detail\n");
187 detail
= (void *) buf
;
188 switch (detail
->bGuidDescriptorType
) {
190 if (detail
->bLength
!= (sizeof *detail
+ 2))
194 if (detail
->bLength
!= (sizeof *detail
+ 3))
201 /* assuming we either noticed BLAN already, or will
202 * find it soon, there are some data bytes here:
203 * - bmNetworkCapabilities (unused)
204 * - bmDataCapabilities (bits, see below)
205 * - bPad (ignored, for PADAFTER -- BLAN-only)
207 * - 0x01 -- Zaurus framing (add CRC)
208 * - 0x02 -- PADBEFORE (CRC includes some padding)
209 * - 0x04 -- PADAFTER (some padding after CRC)
210 * - 0x08 -- "fermat" packet mangling (for hw bugs)
211 * the PADBEFORE appears not to matter; we interop
212 * with devices that use it and those that don't.
214 if ((detail
->bDetailData
[1] & ~0x02) != 0x01) {
215 /* bmDataCapabilities == 0 would be fine too,
216 * but framing is minidriver-coupled for now.
220 "bad MDLM detail, %d %d %d\n",
222 detail
->bDetailData
[0],
223 detail
->bDetailData
[2]);
227 /* same extra framing as for non-BLAN mode */
228 dev
->net
->hard_header_len
+= 6;
229 dev
->rx_urb_size
= dev
->net
->hard_header_len
234 len
-= buf
[0]; /* bLength */
238 if (!desc
|| !detail
) {
239 dev_dbg(&intf
->dev
, "missing cdc mdlm %s%sdescriptor\n",
241 detail
? "" : "detail ");
245 /* There's probably a CDC Ethernet descriptor there, but we can't
246 * rely on the Ethernet address it provides since not all vendors
247 * bother to make it unique. Likewise there's no point in tracking
248 * of the CDC event notifications.
250 return usbnet_get_endpoints(dev
, intf
);
253 dev_info(&dev
->udev
->dev
, "unsupported MDLM descriptors\n");
257 static const struct driver_info bogus_mdlm_info
= {
258 .description
= "pseudo-MDLM (BLAN) device",
259 .flags
= FLAG_POINTTOPOINT
| FLAG_FRAMING_Z
,
260 .check_connect
= always_connected
,
261 .tx_fixup
= zaurus_tx_fixup
,
262 .bind
= blan_mdlm_bind
,
265 static const struct usb_device_id products
[] = {
266 #define ZAURUS_MASTER_INTERFACE \
267 .bInterfaceClass = USB_CLASS_COMM, \
268 .bInterfaceSubClass = USB_CDC_SUBCLASS_ETHERNET, \
269 .bInterfaceProtocol = USB_CDC_PROTO_NONE
271 /* SA-1100 based Sharp Zaurus ("collie"), or compatible. */
273 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
274 | USB_DEVICE_ID_MATCH_DEVICE
,
277 ZAURUS_MASTER_INTERFACE
,
278 .driver_info
= ZAURUS_STRONGARM_INFO
,
281 /* PXA-2xx based models are also lying-about-cdc. If you add any
282 * more devices that claim to be CDC Ethernet, make sure they get
283 * added to the blacklist in cdc_ether too.
285 * NOTE: OpenZaurus versions with 2.6 kernels won't use these entries,
286 * unlike the older ones with 2.4 "embedix" kernels.
289 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
290 | USB_DEVICE_ID_MATCH_DEVICE
,
292 .idProduct
= 0x8005, /* A-300 */
293 ZAURUS_MASTER_INTERFACE
,
294 .driver_info
= ZAURUS_PXA_INFO
,
296 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
297 | USB_DEVICE_ID_MATCH_DEVICE
,
299 .idProduct
= 0x8006, /* B-500/SL-5600 */
300 ZAURUS_MASTER_INTERFACE
,
301 .driver_info
= ZAURUS_PXA_INFO
,
303 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
304 | USB_DEVICE_ID_MATCH_DEVICE
,
306 .idProduct
= 0x8007, /* C-700 */
307 ZAURUS_MASTER_INTERFACE
,
308 .driver_info
= ZAURUS_PXA_INFO
,
310 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
311 | USB_DEVICE_ID_MATCH_DEVICE
,
313 .idProduct
= 0x9031, /* C-750 C-760 */
314 ZAURUS_MASTER_INTERFACE
,
315 .driver_info
= ZAURUS_PXA_INFO
,
317 /* C-750/C-760/C-860/SL-C3000 PDA in MDLM mode */
318 USB_DEVICE_AND_INTERFACE_INFO(0x04DD, 0x9031, USB_CLASS_COMM
,
319 USB_CDC_SUBCLASS_MDLM
, USB_CDC_PROTO_NONE
),
320 .driver_info
= (unsigned long) &bogus_mdlm_info
,
322 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
323 | USB_DEVICE_ID_MATCH_DEVICE
,
325 .idProduct
= 0x9032, /* SL-6000 */
326 ZAURUS_MASTER_INTERFACE
,
327 .driver_info
= ZAURUS_PXA_INFO
,
329 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
330 | USB_DEVICE_ID_MATCH_DEVICE
,
332 /* reported with some C860 units */
333 .idProduct
= 0x9050, /* C-860 */
334 ZAURUS_MASTER_INTERFACE
,
335 .driver_info
= ZAURUS_PXA_INFO
,
338 /* Motorola Rokr E6 */
339 USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6027, USB_CLASS_COMM
,
340 USB_CDC_SUBCLASS_MDLM
, USB_CDC_PROTO_NONE
),
341 .driver_info
= (unsigned long) &bogus_mdlm_info
,
343 /* Motorola MOTOMAGX phones */
344 USB_DEVICE_AND_INTERFACE_INFO(0x22b8, 0x6425, USB_CLASS_COMM
,
345 USB_CDC_SUBCLASS_MDLM
, USB_CDC_PROTO_NONE
),
346 .driver_info
= (unsigned long) &bogus_mdlm_info
,
349 /* Olympus has some models with a Zaurus-compatible option.
350 * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
353 .match_flags
= USB_DEVICE_ID_MATCH_INT_INFO
354 | USB_DEVICE_ID_MATCH_DEVICE
,
356 .idProduct
= 0x0F02, /* R-1000 */
357 ZAURUS_MASTER_INTERFACE
,
358 .driver_info
= OLYMPUS_MXL_INFO
,
361 /* Logitech Harmony 900 - uses the pseudo-MDLM (BLAN) driver */
363 USB_DEVICE_AND_INTERFACE_INFO(0x046d, 0xc11f, USB_CLASS_COMM
,
364 USB_CDC_SUBCLASS_MDLM
, USB_CDC_PROTO_NONE
),
365 .driver_info
= (unsigned long) &bogus_mdlm_info
,
369 MODULE_DEVICE_TABLE(usb
, products
);
371 static struct usb_driver zaurus_driver
= {
373 .id_table
= products
,
374 .probe
= usbnet_probe
,
375 .disconnect
= usbnet_disconnect
,
376 .suspend
= usbnet_suspend
,
377 .resume
= usbnet_resume
,
378 .disable_hub_initiated_lpm
= 1,
381 module_usb_driver(zaurus_driver
);
383 MODULE_AUTHOR("Pavel Machek, David Brownell");
384 MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products");
385 MODULE_LICENSE("GPL");