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