cdc_subset.c 9.9 KB

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