zaurus.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. // #define DEBUG // error path messages, extra info
  20. // #define VERBOSE // more; success messages
  21. #include <linux/config.h>
  22. #include <linux/module.h>
  23. #include <linux/sched.h>
  24. #include <linux/init.h>
  25. #include <linux/netdevice.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/workqueue.h>
  28. #include <linux/mii.h>
  29. #include <linux/crc32.h>
  30. #include <linux/usb.h>
  31. #include <linux/usb_cdc.h>
  32. #include "usbnet.h"
  33. /*
  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).
  38. *
  39. * There are non-Zaurus products that use these same protocols too.
  40. *
  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.
  45. *
  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.
  51. *
  52. * The CDC MDLM nonconformance is less immediately troublesome, since all
  53. * MDLM implementations are quasi-proprietary anyway.
  54. */
  55. static struct sk_buff *
  56. zaurus_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags)
  57. {
  58. int padlen;
  59. struct sk_buff *skb2;
  60. padlen = 2;
  61. if (!skb_cloned(skb)) {
  62. int tailroom = skb_tailroom(skb);
  63. if ((padlen + 4) <= tailroom)
  64. goto done;
  65. }
  66. skb2 = skb_copy_expand(skb, 0, 4 + padlen, flags);
  67. dev_kfree_skb_any(skb);
  68. skb = skb2;
  69. if (skb) {
  70. u32 fcs;
  71. done:
  72. fcs = crc32_le(~0, skb->data, skb->len);
  73. fcs = ~fcs;
  74. *skb_put (skb, 1) = fcs & 0xff;
  75. *skb_put (skb, 1) = (fcs>> 8) & 0xff;
  76. *skb_put (skb, 1) = (fcs>>16) & 0xff;
  77. *skb_put (skb, 1) = (fcs>>24) & 0xff;
  78. }
  79. return skb;
  80. }
  81. static int zaurus_bind(struct usbnet *dev, struct usb_interface *intf)
  82. {
  83. /* Belcarra's funky framing has other options; mostly
  84. * TRAILERS (!) with 4 bytes CRC, and maybe 2 pad bytes.
  85. */
  86. dev->net->hard_header_len += 6;
  87. dev->rx_urb_size = dev->net->hard_header_len + dev->net->mtu;
  88. return usbnet_generic_cdc_bind(dev, intf);
  89. }
  90. /* PDA style devices are always connected if present */
  91. static int always_connected (struct usbnet *dev)
  92. {
  93. return 0;
  94. }
  95. static const struct driver_info zaurus_sl5x00_info = {
  96. .description = "Sharp Zaurus SL-5x00",
  97. .flags = FLAG_FRAMING_Z,
  98. .check_connect = always_connected,
  99. .bind = zaurus_bind,
  100. .unbind = usbnet_cdc_unbind,
  101. .tx_fixup = zaurus_tx_fixup,
  102. };
  103. #define ZAURUS_STRONGARM_INFO ((unsigned long)&zaurus_sl5x00_info)
  104. static const struct driver_info zaurus_pxa_info = {
  105. .description = "Sharp Zaurus, PXA-2xx based",
  106. .flags = FLAG_FRAMING_Z,
  107. .check_connect = always_connected,
  108. .bind = zaurus_bind,
  109. .unbind = usbnet_cdc_unbind,
  110. .tx_fixup = zaurus_tx_fixup,
  111. };
  112. #define ZAURUS_PXA_INFO ((unsigned long)&zaurus_pxa_info)
  113. static const struct driver_info olympus_mxl_info = {
  114. .description = "Olympus R1000",
  115. .flags = FLAG_FRAMING_Z,
  116. .check_connect = always_connected,
  117. .bind = zaurus_bind,
  118. .unbind = usbnet_cdc_unbind,
  119. .tx_fixup = zaurus_tx_fixup,
  120. };
  121. #define OLYMPUS_MXL_INFO ((unsigned long)&olympus_mxl_info)
  122. /* Some more recent products using Lineo/Belcarra code will wrongly claim
  123. * CDC MDLM conformance. They aren't conformant: data endpoints live
  124. * in the control interface, there's no data interface, and it's not used
  125. * to talk to a cell phone radio. But at least we can detect these two
  126. * pseudo-classes, rather than growing this product list with entries for
  127. * each new nonconformant product (sigh).
  128. */
  129. static const u8 safe_guid[16] = {
  130. 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
  131. 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
  132. };
  133. static const u8 blan_guid[16] = {
  134. 0x74, 0xf0, 0x3d, 0xbd, 0x1e, 0xc1, 0x44, 0x70,
  135. 0xa3, 0x67, 0x71, 0x34, 0xc9, 0xf5, 0x54, 0x37,
  136. };
  137. static int blan_mdlm_bind(struct usbnet *dev, struct usb_interface *intf)
  138. {
  139. u8 *buf = intf->cur_altsetting->extra;
  140. int len = intf->cur_altsetting->extralen;
  141. struct usb_cdc_mdlm_desc *desc = NULL;
  142. struct usb_cdc_mdlm_detail_desc *detail = NULL;
  143. while (len > 3) {
  144. if (buf [1] != USB_DT_CS_INTERFACE)
  145. goto next_desc;
  146. /* use bDescriptorSubType, and just verify that we get a
  147. * "BLAN" (or "SAFE") descriptor.
  148. */
  149. switch (buf [2]) {
  150. case USB_CDC_MDLM_TYPE:
  151. if (desc) {
  152. dev_dbg(&intf->dev, "extra MDLM\n");
  153. goto bad_desc;
  154. }
  155. desc = (void *) buf;
  156. if (desc->bLength != sizeof *desc) {
  157. dev_dbg(&intf->dev, "MDLM len %u\n",
  158. desc->bLength);
  159. goto bad_desc;
  160. }
  161. /* expect bcdVersion 1.0, ignore */
  162. if (memcmp(&desc->bGUID, blan_guid, 16)
  163. && memcmp(&desc->bGUID, safe_guid, 16) ) {
  164. /* hey, this one might _really_ be MDLM! */
  165. dev_dbg(&intf->dev, "MDLM guid\n");
  166. goto bad_desc;
  167. }
  168. break;
  169. case USB_CDC_MDLM_DETAIL_TYPE:
  170. if (detail) {
  171. dev_dbg(&intf->dev, "extra MDLM detail\n");
  172. goto bad_desc;
  173. }
  174. detail = (void *) buf;
  175. switch (detail->bGuidDescriptorType) {
  176. case 0: /* "SAFE" */
  177. if (detail->bLength != (sizeof *detail + 2))
  178. goto bad_detail;
  179. break;
  180. case 1: /* "BLAN" */
  181. if (detail->bLength != (sizeof *detail + 3))
  182. goto bad_detail;
  183. break;
  184. default:
  185. goto bad_detail;
  186. }
  187. /* assuming we either noticed BLAN already, or will
  188. * find it soon, there are some data bytes here:
  189. * - bmNetworkCapabilities (unused)
  190. * - bmDataCapabilities (bits, see below)
  191. * - bPad (ignored, for PADAFTER -- BLAN-only)
  192. * bits are:
  193. * - 0x01 -- Zaurus framing (add CRC)
  194. * - 0x02 -- PADBEFORE (CRC includes some padding)
  195. * - 0x04 -- PADAFTER (some padding after CRC)
  196. * - 0x08 -- "fermat" packet mangling (for hw bugs)
  197. * the PADBEFORE appears not to matter; we interop
  198. * with devices that use it and those that don't.
  199. */
  200. if ((detail->bDetailData[1] & ~0x02) != 0x01) {
  201. /* bmDataCapabilities == 0 would be fine too,
  202. * but framing is minidriver-coupled for now.
  203. */
  204. bad_detail:
  205. dev_dbg(&intf->dev,
  206. "bad MDLM detail, %d %d %d\n",
  207. detail->bLength,
  208. detail->bDetailData[0],
  209. detail->bDetailData[2]);
  210. goto bad_desc;
  211. }
  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_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. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  292. | USB_DEVICE_ID_MATCH_DEVICE,
  293. .idVendor = 0x04DD,
  294. .idProduct = 0x9032, /* SL-6000 */
  295. ZAURUS_MASTER_INTERFACE,
  296. .driver_info = ZAURUS_PXA_INFO,
  297. }, {
  298. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  299. | USB_DEVICE_ID_MATCH_DEVICE,
  300. .idVendor = 0x04DD,
  301. /* reported with some C860 units */
  302. .idProduct = 0x9050, /* C-860 */
  303. ZAURUS_MASTER_INTERFACE,
  304. .driver_info = ZAURUS_PXA_INFO,
  305. },
  306. /* At least some of the newest PXA units have very different lies about
  307. * their standards support: they claim to be cell phones offering
  308. * direct access to their radios! (No, they don't conform to CDC MDLM.)
  309. */
  310. {
  311. USB_INTERFACE_INFO(USB_CLASS_COMM, USB_CDC_SUBCLASS_MDLM,
  312. USB_CDC_PROTO_NONE),
  313. .driver_info = (unsigned long) &bogus_mdlm_info,
  314. },
  315. /* Olympus has some models with a Zaurus-compatible option.
  316. * R-1000 uses a FreeScale i.MXL cpu (ARMv4T)
  317. */
  318. {
  319. .match_flags = USB_DEVICE_ID_MATCH_INT_INFO
  320. | USB_DEVICE_ID_MATCH_DEVICE,
  321. .idVendor = 0x07B4,
  322. .idProduct = 0x0F02, /* R-1000 */
  323. ZAURUS_MASTER_INTERFACE,
  324. .driver_info = OLYMPUS_MXL_INFO,
  325. },
  326. { }, // END
  327. };
  328. MODULE_DEVICE_TABLE(usb, products);
  329. static struct usb_driver zaurus_driver = {
  330. .name = "zaurus",
  331. .id_table = products,
  332. .probe = usbnet_probe,
  333. .disconnect = usbnet_disconnect,
  334. .suspend = usbnet_suspend,
  335. .resume = usbnet_resume,
  336. };
  337. static int __init zaurus_init(void)
  338. {
  339. return usb_register(&zaurus_driver);
  340. }
  341. module_init(zaurus_init);
  342. static void __exit zaurus_exit(void)
  343. {
  344. usb_deregister(&zaurus_driver);
  345. }
  346. module_exit(zaurus_exit);
  347. MODULE_AUTHOR("Pavel Machek, David Brownell");
  348. MODULE_DESCRIPTION("Sharp Zaurus PDA, and compatible products");
  349. MODULE_LICENSE("GPL");