/drivers/net/usb/zaurus.c

http://github.com/mirrors/linux · C · 373 lines · 259 code · 31 blank · 83 comment · 21 complexity · dbae7a2bde25afe3848bb15384e92a77 MD5 · raw file

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