zaurus.c 12 KB

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