cdc_subset.c 11 KB

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