cdc_subset.c 9.9 KB

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