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