cdc_subset.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. /*
  2. * Simple "CDC Subset" USB Networking Links
  3. * Copyright (C) 2000-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. #include <linux/module.h>
  19. #include <linux/kmod.h>
  20. #include <linux/netdevice.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/ethtool.h>
  23. #include <linux/workqueue.h>
  24. #include <linux/mii.h>
  25. #include <linux/usb.h>
  26. #include <linux/usb/usbnet.h>
  27. /*
  28. * This supports simple USB network links that don't require any special
  29. * framing or hardware control operations. The protocol used here is a
  30. * strict subset of CDC Ethernet, with three basic differences reflecting
  31. * the goal that almost any hardware should run it:
  32. *
  33. * - Minimal runtime control: one interface, no altsettings, and
  34. * no vendor or class specific control requests. If a device is
  35. * configured, it is allowed to exchange packets with the host.
  36. * Fancier models would mean not working on some hardware.
  37. *
  38. * - Minimal manufacturing control: no IEEE "Organizationally
  39. * Unique ID" required, or an EEPROMs to store one. Each host uses
  40. * one random "locally assigned" Ethernet address instead, which can
  41. * of course be overridden using standard tools like "ifconfig".
  42. * (With 2^46 such addresses, same-net collisions are quite rare.)
  43. *
  44. * - There is no additional framing data for USB. Packets are written
  45. * exactly as in CDC Ethernet, starting with an Ethernet header and
  46. * terminated by a short packet. However, the host will never send a
  47. * zero length packet; some systems can't handle those robustly.
  48. *
  49. * Anything that can transmit and receive USB bulk packets can implement
  50. * this protocol. That includes both smart peripherals and quite a lot
  51. * of "host-to-host" USB cables (which embed two devices back-to-back).
  52. *
  53. * Note that although Linux may use many of those host-to-host links
  54. * with this "cdc_subset" framing, that doesn't mean there may not be a
  55. * better approach. Handling the "other end unplugs/replugs" scenario
  56. * well tends to require chip-specific vendor requests. Also, Windows
  57. * peers at the other end of host-to-host cables may expect their own
  58. * framing to be used rather than this "cdc_subset" model.
  59. */
  60. #if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX)
  61. /* PDA style devices are always connected if present */
  62. static int always_connected (struct usbnet *dev)
  63. {
  64. return 0;
  65. }
  66. #endif
  67. #ifdef CONFIG_USB_ALI_M5632
  68. #define HAVE_HARDWARE
  69. /*-------------------------------------------------------------------------
  70. *
  71. * ALi M5632 driver ... does high speed
  72. *
  73. * NOTE that the MS-Windows drivers for this chip use some funky and
  74. * (naturally) undocumented 7-byte prefix to each packet, so this is a
  75. * case where we don't currently interoperate. Also, once you unplug
  76. * one end of the cable, you need to replug the other end too ... since
  77. * chip docs are unavailable, there's no way to reset the relevant state
  78. * short of a power cycle.
  79. *
  80. *-------------------------------------------------------------------------*/
  81. static void m5632_recover(struct usbnet *dev)
  82. {
  83. struct usb_device *udev = dev->udev;
  84. struct usb_interface *intf = dev->intf;
  85. int r;
  86. r = usb_lock_device_for_reset(udev, intf);
  87. if (r < 0)
  88. return;
  89. usb_reset_device(udev);
  90. usb_unlock_device(udev);
  91. }
  92. static const struct driver_info ali_m5632_info = {
  93. .description = "ALi M5632",
  94. .flags = FLAG_POINTTOPOINT,
  95. .recover = m5632_recover,
  96. };
  97. #endif
  98. #ifdef CONFIG_USB_AN2720
  99. #define HAVE_HARDWARE
  100. /*-------------------------------------------------------------------------
  101. *
  102. * AnchorChips 2720 driver ... http://www.cypress.com
  103. *
  104. * This doesn't seem to have a way to detect whether the peer is
  105. * connected, or need any reset handshaking. It's got pretty big
  106. * internal buffers (handles most of a frame's worth of data).
  107. * Chip data sheets don't describe any vendor control messages.
  108. *
  109. *-------------------------------------------------------------------------*/
  110. static const struct driver_info an2720_info = {
  111. .description = "AnchorChips/Cypress 2720",
  112. .flags = FLAG_POINTTOPOINT,
  113. // no reset available!
  114. // no check_connect available!
  115. .in = 2, .out = 2, // direction distinguishes these
  116. };
  117. #endif /* CONFIG_USB_AN2720 */
  118. #ifdef CONFIG_USB_BELKIN
  119. #define HAVE_HARDWARE
  120. /*-------------------------------------------------------------------------
  121. *
  122. * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller
  123. *
  124. * ... also two eTEK designs, including one sold as "Advance USBNET"
  125. *
  126. *-------------------------------------------------------------------------*/
  127. static const struct driver_info belkin_info = {
  128. .description = "Belkin, eTEK, or compatible",
  129. .flags = FLAG_POINTTOPOINT,
  130. };
  131. #endif /* CONFIG_USB_BELKIN */
  132. #ifdef CONFIG_USB_EPSON2888
  133. #define HAVE_HARDWARE
  134. /*-------------------------------------------------------------------------
  135. *
  136. * EPSON USB clients
  137. *
  138. * This is the same idea as Linux PDAs (below) except the firmware in the
  139. * device might not be Tux-powered. Epson provides reference firmware that
  140. * implements this interface. Product developers can reuse or modify that
  141. * code, such as by using their own product and vendor codes.
  142. *
  143. * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
  144. *
  145. *-------------------------------------------------------------------------*/
  146. static const struct driver_info epson2888_info = {
  147. .description = "Epson USB Device",
  148. .check_connect = always_connected,
  149. .flags = FLAG_POINTTOPOINT,
  150. .in = 4, .out = 3,
  151. };
  152. #endif /* CONFIG_USB_EPSON2888 */
  153. /*-------------------------------------------------------------------------
  154. *
  155. * info from Jonathan McDowell <noodles@earth.li>
  156. *
  157. *-------------------------------------------------------------------------*/
  158. #ifdef CONFIG_USB_KC2190
  159. #define HAVE_HARDWARE
  160. static const struct driver_info kc2190_info = {
  161. .description = "KC Technology KC-190",
  162. .flags = FLAG_POINTTOPOINT,
  163. };
  164. #endif /* CONFIG_USB_KC2190 */
  165. #ifdef CONFIG_USB_ARMLINUX
  166. #define HAVE_HARDWARE
  167. /*-------------------------------------------------------------------------
  168. *
  169. * Intel's SA-1100 chip integrates basic USB support, and is used
  170. * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
  171. * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
  172. * network using minimal USB framing data.
  173. *
  174. * This describes the driver currently in standard ARM Linux kernels.
  175. * The Zaurus uses a different driver (see later).
  176. *
  177. * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
  178. * and different USB endpoint numbering than the SA1100 devices. The
  179. * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
  180. * so we rely on the endpoint descriptors.
  181. *
  182. *-------------------------------------------------------------------------*/
  183. static const struct driver_info linuxdev_info = {
  184. .description = "Linux Device",
  185. .check_connect = always_connected,
  186. .flags = FLAG_POINTTOPOINT,
  187. };
  188. static const struct driver_info yopy_info = {
  189. .description = "Yopy",
  190. .check_connect = always_connected,
  191. .flags = FLAG_POINTTOPOINT,
  192. };
  193. static const struct driver_info blob_info = {
  194. .description = "Boot Loader OBject",
  195. .check_connect = always_connected,
  196. .flags = FLAG_POINTTOPOINT,
  197. };
  198. #endif /* CONFIG_USB_ARMLINUX */
  199. /*-------------------------------------------------------------------------*/
  200. #ifndef HAVE_HARDWARE
  201. #warning You need to configure some hardware for this driver
  202. #endif
  203. /*
  204. * chip vendor names won't normally be on the cables, and
  205. * may not be on the device.
  206. */
  207. static const struct usb_device_id products [] = {
  208. #ifdef CONFIG_USB_ALI_M5632
  209. {
  210. USB_DEVICE (0x0402, 0x5632), // ALi defaults
  211. .driver_info = (unsigned long) &ali_m5632_info,
  212. },
  213. {
  214. USB_DEVICE (0x182d,0x207c), // SiteCom CN-124
  215. .driver_info = (unsigned long) &ali_m5632_info,
  216. },
  217. #endif
  218. #ifdef CONFIG_USB_AN2720
  219. {
  220. USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults
  221. .driver_info = (unsigned long) &an2720_info,
  222. }, {
  223. USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET
  224. .driver_info = (unsigned long) &an2720_info,
  225. },
  226. #endif
  227. #ifdef CONFIG_USB_BELKIN
  228. {
  229. USB_DEVICE (0x050d, 0x0004), // Belkin
  230. .driver_info = (unsigned long) &belkin_info,
  231. }, {
  232. USB_DEVICE (0x056c, 0x8100), // eTEK
  233. .driver_info = (unsigned long) &belkin_info,
  234. }, {
  235. USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK)
  236. .driver_info = (unsigned long) &belkin_info,
  237. },
  238. #endif
  239. #ifdef CONFIG_USB_EPSON2888
  240. {
  241. USB_DEVICE (0x0525, 0x2888), // EPSON USB client
  242. .driver_info = (unsigned long) &epson2888_info,
  243. },
  244. #endif
  245. #ifdef CONFIG_USB_KC2190
  246. {
  247. USB_DEVICE (0x050f, 0x0190), // KC-190
  248. .driver_info = (unsigned long) &kc2190_info,
  249. },
  250. #endif
  251. #ifdef CONFIG_USB_ARMLINUX
  252. /*
  253. * SA-1100 using standard ARM Linux kernels, or compatible.
  254. * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
  255. * The sa-1100 "usb-eth" driver handles the basic framing.
  256. *
  257. * PXA25x or PXA210 ... these use a "usb-eth" driver much like
  258. * the sa1100 one, but hardware uses different endpoint numbers.
  259. *
  260. * Or the Linux "Ethernet" gadget on hardware that can't talk
  261. * CDC Ethernet (e.g., no altsettings), in either of two modes:
  262. * - acting just like the old "usb-eth" firmware, though
  263. * the implementation is different
  264. * - supporting RNDIS as the first/default configuration for
  265. * MS-Windows interop; Linux needs to use the other config
  266. */
  267. {
  268. // 1183 = 0x049F, both used as hex values?
  269. // Compaq "Itsy" vendor/product id
  270. USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible
  271. .driver_info = (unsigned long) &linuxdev_info,
  272. }, {
  273. USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy"
  274. .driver_info = (unsigned long) &yopy_info,
  275. }, {
  276. USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader
  277. .driver_info = (unsigned long) &blob_info,
  278. }, {
  279. USB_DEVICE (0x1286, 0x8001), // "blob" bootloader
  280. .driver_info = (unsigned long) &blob_info,
  281. }, {
  282. // Linux Ethernet/RNDIS gadget, mostly on PXA, second config
  283. // e.g. Gumstix, current OpenZaurus, ... or anything else
  284. // that just enables this gadget option.
  285. USB_DEVICE (0x0525, 0xa4a2),
  286. .driver_info = (unsigned long) &linuxdev_info,
  287. },
  288. #endif
  289. { }, // END
  290. };
  291. MODULE_DEVICE_TABLE(usb, products);
  292. /*-------------------------------------------------------------------------*/
  293. static int dummy_prereset(struct usb_interface *intf)
  294. {
  295. return 0;
  296. }
  297. static int dummy_postreset(struct usb_interface *intf)
  298. {
  299. return 0;
  300. }
  301. static struct usb_driver cdc_subset_driver = {
  302. .name = "cdc_subset",
  303. .probe = usbnet_probe,
  304. .suspend = usbnet_suspend,
  305. .resume = usbnet_resume,
  306. .pre_reset = dummy_prereset,
  307. .post_reset = dummy_postreset,
  308. .disconnect = usbnet_disconnect,
  309. .id_table = products,
  310. .disable_hub_initiated_lpm = 1,
  311. };
  312. module_usb_driver(cdc_subset_driver);
  313. MODULE_AUTHOR("David Brownell");
  314. MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links");
  315. MODULE_LICENSE("GPL");