11ccea77eSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 25b2fc499SJeff Garzik /* 35b2fc499SJeff Garzik * Simple "CDC Subset" USB Networking Links 45b2fc499SJeff Garzik * Copyright (C) 2000-2005 by David Brownell 55b2fc499SJeff Garzik */ 65b2fc499SJeff Garzik 75b2fc499SJeff Garzik #include <linux/module.h> 85b2fc499SJeff Garzik #include <linux/kmod.h> 95b2fc499SJeff Garzik #include <linux/netdevice.h> 105b2fc499SJeff Garzik #include <linux/etherdevice.h> 115b2fc499SJeff Garzik #include <linux/ethtool.h> 125b2fc499SJeff Garzik #include <linux/workqueue.h> 135b2fc499SJeff Garzik #include <linux/mii.h> 145b2fc499SJeff Garzik #include <linux/usb.h> 153692e94fSJussi Kivilinna #include <linux/usb/usbnet.h> 165b2fc499SJeff Garzik 175b2fc499SJeff Garzik 185b2fc499SJeff Garzik /* 195b2fc499SJeff Garzik * This supports simple USB network links that don't require any special 205b2fc499SJeff Garzik * framing or hardware control operations. The protocol used here is a 215b2fc499SJeff Garzik * strict subset of CDC Ethernet, with three basic differences reflecting 225b2fc499SJeff Garzik * the goal that almost any hardware should run it: 235b2fc499SJeff Garzik * 245b2fc499SJeff Garzik * - Minimal runtime control: one interface, no altsettings, and 255b2fc499SJeff Garzik * no vendor or class specific control requests. If a device is 265b2fc499SJeff Garzik * configured, it is allowed to exchange packets with the host. 275b2fc499SJeff Garzik * Fancier models would mean not working on some hardware. 285b2fc499SJeff Garzik * 295b2fc499SJeff Garzik * - Minimal manufacturing control: no IEEE "Organizationally 305b2fc499SJeff Garzik * Unique ID" required, or an EEPROMs to store one. Each host uses 315b2fc499SJeff Garzik * one random "locally assigned" Ethernet address instead, which can 325b2fc499SJeff Garzik * of course be overridden using standard tools like "ifconfig". 335b2fc499SJeff Garzik * (With 2^46 such addresses, same-net collisions are quite rare.) 345b2fc499SJeff Garzik * 355b2fc499SJeff Garzik * - There is no additional framing data for USB. Packets are written 365b2fc499SJeff Garzik * exactly as in CDC Ethernet, starting with an Ethernet header and 375b2fc499SJeff Garzik * terminated by a short packet. However, the host will never send a 385b2fc499SJeff Garzik * zero length packet; some systems can't handle those robustly. 395b2fc499SJeff Garzik * 405b2fc499SJeff Garzik * Anything that can transmit and receive USB bulk packets can implement 415b2fc499SJeff Garzik * this protocol. That includes both smart peripherals and quite a lot 425b2fc499SJeff Garzik * of "host-to-host" USB cables (which embed two devices back-to-back). 435b2fc499SJeff Garzik * 445b2fc499SJeff Garzik * Note that although Linux may use many of those host-to-host links 455b2fc499SJeff Garzik * with this "cdc_subset" framing, that doesn't mean there may not be a 465b2fc499SJeff Garzik * better approach. Handling the "other end unplugs/replugs" scenario 475b2fc499SJeff Garzik * well tends to require chip-specific vendor requests. Also, Windows 485b2fc499SJeff Garzik * peers at the other end of host-to-host cables may expect their own 495b2fc499SJeff Garzik * framing to be used rather than this "cdc_subset" model. 505b2fc499SJeff Garzik */ 515b2fc499SJeff Garzik 525b2fc499SJeff Garzik #if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX) 535b2fc499SJeff Garzik /* PDA style devices are always connected if present */ 545b2fc499SJeff Garzik static int always_connected (struct usbnet *dev) 555b2fc499SJeff Garzik { 565b2fc499SJeff Garzik return 0; 575b2fc499SJeff Garzik } 585b2fc499SJeff Garzik #endif 595b2fc499SJeff Garzik 605b2fc499SJeff Garzik #ifdef CONFIG_USB_ALI_M5632 615b2fc499SJeff Garzik #define HAVE_HARDWARE 625b2fc499SJeff Garzik 635b2fc499SJeff Garzik /*------------------------------------------------------------------------- 645b2fc499SJeff Garzik * 655b2fc499SJeff Garzik * ALi M5632 driver ... does high speed 665b2fc499SJeff Garzik * 675b2fc499SJeff Garzik * NOTE that the MS-Windows drivers for this chip use some funky and 685b2fc499SJeff Garzik * (naturally) undocumented 7-byte prefix to each packet, so this is a 695b2fc499SJeff Garzik * case where we don't currently interoperate. Also, once you unplug 705b2fc499SJeff Garzik * one end of the cable, you need to replug the other end too ... since 715b2fc499SJeff Garzik * chip docs are unavailable, there's no way to reset the relevant state 725b2fc499SJeff Garzik * short of a power cycle. 735b2fc499SJeff Garzik * 745b2fc499SJeff Garzik *-------------------------------------------------------------------------*/ 755b2fc499SJeff Garzik 76dbcdd4d5SOliver Neukum static void m5632_recover(struct usbnet *dev) 77dbcdd4d5SOliver Neukum { 78dbcdd4d5SOliver Neukum struct usb_device *udev = dev->udev; 79dbcdd4d5SOliver Neukum struct usb_interface *intf = dev->intf; 80dbcdd4d5SOliver Neukum int r; 81dbcdd4d5SOliver Neukum 82dbcdd4d5SOliver Neukum r = usb_lock_device_for_reset(udev, intf); 83dbcdd4d5SOliver Neukum if (r < 0) 84dbcdd4d5SOliver Neukum return; 85dbcdd4d5SOliver Neukum 86dbcdd4d5SOliver Neukum usb_reset_device(udev); 87dbcdd4d5SOliver Neukum usb_unlock_device(udev); 88dbcdd4d5SOliver Neukum } 89dbcdd4d5SOliver Neukum 905b2fc499SJeff Garzik static const struct driver_info ali_m5632_info = { 915b2fc499SJeff Garzik .description = "ALi M5632", 92c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 93dbcdd4d5SOliver Neukum .recover = m5632_recover, 945b2fc499SJeff Garzik }; 955b2fc499SJeff Garzik 965b2fc499SJeff Garzik #endif 975b2fc499SJeff Garzik 985b2fc499SJeff Garzik #ifdef CONFIG_USB_AN2720 995b2fc499SJeff Garzik #define HAVE_HARDWARE 1005b2fc499SJeff Garzik 1015b2fc499SJeff Garzik /*------------------------------------------------------------------------- 1025b2fc499SJeff Garzik * 1035b2fc499SJeff Garzik * AnchorChips 2720 driver ... http://www.cypress.com 1045b2fc499SJeff Garzik * 1055b2fc499SJeff Garzik * This doesn't seem to have a way to detect whether the peer is 1065b2fc499SJeff Garzik * connected, or need any reset handshaking. It's got pretty big 1075b2fc499SJeff Garzik * internal buffers (handles most of a frame's worth of data). 1085b2fc499SJeff Garzik * Chip data sheets don't describe any vendor control messages. 1095b2fc499SJeff Garzik * 1105b2fc499SJeff Garzik *-------------------------------------------------------------------------*/ 1115b2fc499SJeff Garzik 1125b2fc499SJeff Garzik static const struct driver_info an2720_info = { 1135b2fc499SJeff Garzik .description = "AnchorChips/Cypress 2720", 114c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 1155b2fc499SJeff Garzik // no reset available! 1165b2fc499SJeff Garzik // no check_connect available! 1175b2fc499SJeff Garzik 1185b2fc499SJeff Garzik .in = 2, .out = 2, // direction distinguishes these 1195b2fc499SJeff Garzik }; 1205b2fc499SJeff Garzik 1215b2fc499SJeff Garzik #endif /* CONFIG_USB_AN2720 */ 1225b2fc499SJeff Garzik 1235b2fc499SJeff Garzik 1245b2fc499SJeff Garzik #ifdef CONFIG_USB_BELKIN 1255b2fc499SJeff Garzik #define HAVE_HARDWARE 1265b2fc499SJeff Garzik 1275b2fc499SJeff Garzik /*------------------------------------------------------------------------- 1285b2fc499SJeff Garzik * 1295b2fc499SJeff Garzik * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller 1305b2fc499SJeff Garzik * 1315b2fc499SJeff Garzik * ... also two eTEK designs, including one sold as "Advance USBNET" 1325b2fc499SJeff Garzik * 1335b2fc499SJeff Garzik *-------------------------------------------------------------------------*/ 1345b2fc499SJeff Garzik 1355b2fc499SJeff Garzik static const struct driver_info belkin_info = { 1365b2fc499SJeff Garzik .description = "Belkin, eTEK, or compatible", 137c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 1385b2fc499SJeff Garzik }; 1395b2fc499SJeff Garzik 1405b2fc499SJeff Garzik #endif /* CONFIG_USB_BELKIN */ 1415b2fc499SJeff Garzik 1425b2fc499SJeff Garzik 1435b2fc499SJeff Garzik 1445b2fc499SJeff Garzik #ifdef CONFIG_USB_EPSON2888 1455b2fc499SJeff Garzik #define HAVE_HARDWARE 1465b2fc499SJeff Garzik 1475b2fc499SJeff Garzik /*------------------------------------------------------------------------- 1485b2fc499SJeff Garzik * 1495b2fc499SJeff Garzik * EPSON USB clients 1505b2fc499SJeff Garzik * 1515b2fc499SJeff Garzik * This is the same idea as Linux PDAs (below) except the firmware in the 1525b2fc499SJeff Garzik * device might not be Tux-powered. Epson provides reference firmware that 1535b2fc499SJeff Garzik * implements this interface. Product developers can reuse or modify that 1545b2fc499SJeff Garzik * code, such as by using their own product and vendor codes. 1555b2fc499SJeff Garzik * 1565b2fc499SJeff Garzik * Support was from Juro Bystricky <bystricky.juro@erd.epson.com> 1575b2fc499SJeff Garzik * 1585b2fc499SJeff Garzik *-------------------------------------------------------------------------*/ 1595b2fc499SJeff Garzik 1605b2fc499SJeff Garzik static const struct driver_info epson2888_info = { 1615b2fc499SJeff Garzik .description = "Epson USB Device", 1625b2fc499SJeff Garzik .check_connect = always_connected, 163c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 1645b2fc499SJeff Garzik 1655b2fc499SJeff Garzik .in = 4, .out = 3, 1665b2fc499SJeff Garzik }; 1675b2fc499SJeff Garzik 1685b2fc499SJeff Garzik #endif /* CONFIG_USB_EPSON2888 */ 1695b2fc499SJeff Garzik 1705b2fc499SJeff Garzik 1715b2fc499SJeff Garzik /*------------------------------------------------------------------------- 1725b2fc499SJeff Garzik * 1735b2fc499SJeff Garzik * info from Jonathan McDowell <noodles@earth.li> 1745b2fc499SJeff Garzik * 1755b2fc499SJeff Garzik *-------------------------------------------------------------------------*/ 1765b2fc499SJeff Garzik #ifdef CONFIG_USB_KC2190 1775b2fc499SJeff Garzik #define HAVE_HARDWARE 1785b2fc499SJeff Garzik static const struct driver_info kc2190_info = { 1795b2fc499SJeff Garzik .description = "KC Technology KC-190", 180c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 1815b2fc499SJeff Garzik }; 1825b2fc499SJeff Garzik #endif /* CONFIG_USB_KC2190 */ 1835b2fc499SJeff Garzik 1845b2fc499SJeff Garzik 1855b2fc499SJeff Garzik #ifdef CONFIG_USB_ARMLINUX 1865b2fc499SJeff Garzik #define HAVE_HARDWARE 1875b2fc499SJeff Garzik 1885b2fc499SJeff Garzik /*------------------------------------------------------------------------- 1895b2fc499SJeff Garzik * 1905b2fc499SJeff Garzik * Intel's SA-1100 chip integrates basic USB support, and is used 1915b2fc499SJeff Garzik * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more. 1925b2fc499SJeff Garzik * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to 1935b2fc499SJeff Garzik * network using minimal USB framing data. 1945b2fc499SJeff Garzik * 1955b2fc499SJeff Garzik * This describes the driver currently in standard ARM Linux kernels. 1965b2fc499SJeff Garzik * The Zaurus uses a different driver (see later). 1975b2fc499SJeff Garzik * 1985b2fc499SJeff Garzik * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support 1995b2fc499SJeff Garzik * and different USB endpoint numbering than the SA1100 devices. The 2005b2fc499SJeff Garzik * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100 2015b2fc499SJeff Garzik * so we rely on the endpoint descriptors. 2025b2fc499SJeff Garzik * 2035b2fc499SJeff Garzik *-------------------------------------------------------------------------*/ 2045b2fc499SJeff Garzik 2055b2fc499SJeff Garzik static const struct driver_info linuxdev_info = { 2065b2fc499SJeff Garzik .description = "Linux Device", 2075b2fc499SJeff Garzik .check_connect = always_connected, 208c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 2095b2fc499SJeff Garzik }; 2105b2fc499SJeff Garzik 2115b2fc499SJeff Garzik static const struct driver_info yopy_info = { 2125b2fc499SJeff Garzik .description = "Yopy", 2135b2fc499SJeff Garzik .check_connect = always_connected, 214c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 2155b2fc499SJeff Garzik }; 2165b2fc499SJeff Garzik 2175b2fc499SJeff Garzik static const struct driver_info blob_info = { 2185b2fc499SJeff Garzik .description = "Boot Loader OBject", 2195b2fc499SJeff Garzik .check_connect = always_connected, 220c261344dSArnd Bergmann .flags = FLAG_POINTTOPOINT, 2215b2fc499SJeff Garzik }; 2225b2fc499SJeff Garzik 2235b2fc499SJeff Garzik #endif /* CONFIG_USB_ARMLINUX */ 2245b2fc499SJeff Garzik 2255b2fc499SJeff Garzik 2265b2fc499SJeff Garzik /*-------------------------------------------------------------------------*/ 2275b2fc499SJeff Garzik 2285b2fc499SJeff Garzik #ifndef HAVE_HARDWARE 229f82b9878SIngo Molnar #warning You need to configure some hardware for this driver 2305b2fc499SJeff Garzik #endif 2315b2fc499SJeff Garzik 2325b2fc499SJeff Garzik /* 2335b2fc499SJeff Garzik * chip vendor names won't normally be on the cables, and 2345b2fc499SJeff Garzik * may not be on the device. 2355b2fc499SJeff Garzik */ 2365b2fc499SJeff Garzik 2375b2fc499SJeff Garzik static const struct usb_device_id products [] = { 2385b2fc499SJeff Garzik 2395b2fc499SJeff Garzik #ifdef CONFIG_USB_ALI_M5632 2405b2fc499SJeff Garzik { 2415b2fc499SJeff Garzik USB_DEVICE (0x0402, 0x5632), // ALi defaults 2425b2fc499SJeff Garzik .driver_info = (unsigned long) &ali_m5632_info, 2435b2fc499SJeff Garzik }, 2445b2fc499SJeff Garzik { 2455b2fc499SJeff Garzik USB_DEVICE (0x182d,0x207c), // SiteCom CN-124 2465b2fc499SJeff Garzik .driver_info = (unsigned long) &ali_m5632_info, 2475b2fc499SJeff Garzik }, 2485b2fc499SJeff Garzik #endif 2495b2fc499SJeff Garzik 2505b2fc499SJeff Garzik #ifdef CONFIG_USB_AN2720 2515b2fc499SJeff Garzik { 2525b2fc499SJeff Garzik USB_DEVICE (0x0547, 0x2720), // AnchorChips defaults 2535b2fc499SJeff Garzik .driver_info = (unsigned long) &an2720_info, 2545b2fc499SJeff Garzik }, { 2555b2fc499SJeff Garzik USB_DEVICE (0x0547, 0x2727), // Xircom PGUNET 2565b2fc499SJeff Garzik .driver_info = (unsigned long) &an2720_info, 2575b2fc499SJeff Garzik }, 2585b2fc499SJeff Garzik #endif 2595b2fc499SJeff Garzik 2605b2fc499SJeff Garzik #ifdef CONFIG_USB_BELKIN 2615b2fc499SJeff Garzik { 2625b2fc499SJeff Garzik USB_DEVICE (0x050d, 0x0004), // Belkin 2635b2fc499SJeff Garzik .driver_info = (unsigned long) &belkin_info, 2645b2fc499SJeff Garzik }, { 2655b2fc499SJeff Garzik USB_DEVICE (0x056c, 0x8100), // eTEK 2665b2fc499SJeff Garzik .driver_info = (unsigned long) &belkin_info, 2675b2fc499SJeff Garzik }, { 2685b2fc499SJeff Garzik USB_DEVICE (0x0525, 0x9901), // Advance USBNET (eTEK) 2695b2fc499SJeff Garzik .driver_info = (unsigned long) &belkin_info, 2705b2fc499SJeff Garzik }, 2715b2fc499SJeff Garzik #endif 2725b2fc499SJeff Garzik 2735b2fc499SJeff Garzik #ifdef CONFIG_USB_EPSON2888 2745b2fc499SJeff Garzik { 2755b2fc499SJeff Garzik USB_DEVICE (0x0525, 0x2888), // EPSON USB client 2765b2fc499SJeff Garzik .driver_info = (unsigned long) &epson2888_info, 2775b2fc499SJeff Garzik }, 2785b2fc499SJeff Garzik #endif 2795b2fc499SJeff Garzik 2805b2fc499SJeff Garzik #ifdef CONFIG_USB_KC2190 2815b2fc499SJeff Garzik { 2825b2fc499SJeff Garzik USB_DEVICE (0x050f, 0x0190), // KC-190 2835b2fc499SJeff Garzik .driver_info = (unsigned long) &kc2190_info, 2845b2fc499SJeff Garzik }, 2855b2fc499SJeff Garzik #endif 2865b2fc499SJeff Garzik 2875b2fc499SJeff Garzik #ifdef CONFIG_USB_ARMLINUX 2885b2fc499SJeff Garzik /* 2895b2fc499SJeff Garzik * SA-1100 using standard ARM Linux kernels, or compatible. 2905b2fc499SJeff Garzik * Often used when talking to Linux PDAs (iPaq, Yopy, etc). 2915b2fc499SJeff Garzik * The sa-1100 "usb-eth" driver handles the basic framing. 2925b2fc499SJeff Garzik * 2935b2fc499SJeff Garzik * PXA25x or PXA210 ... these use a "usb-eth" driver much like 2945b2fc499SJeff Garzik * the sa1100 one, but hardware uses different endpoint numbers. 2955b2fc499SJeff Garzik * 2965b2fc499SJeff Garzik * Or the Linux "Ethernet" gadget on hardware that can't talk 2975b2fc499SJeff Garzik * CDC Ethernet (e.g., no altsettings), in either of two modes: 2985b2fc499SJeff Garzik * - acting just like the old "usb-eth" firmware, though 2995b2fc499SJeff Garzik * the implementation is different 3005b2fc499SJeff Garzik * - supporting RNDIS as the first/default configuration for 3015b2fc499SJeff Garzik * MS-Windows interop; Linux needs to use the other config 3025b2fc499SJeff Garzik */ 3035b2fc499SJeff Garzik { 3045b2fc499SJeff Garzik // 1183 = 0x049F, both used as hex values? 3055b2fc499SJeff Garzik // Compaq "Itsy" vendor/product id 3065b2fc499SJeff Garzik USB_DEVICE (0x049F, 0x505A), // usb-eth, or compatible 3075b2fc499SJeff Garzik .driver_info = (unsigned long) &linuxdev_info, 3085b2fc499SJeff Garzik }, { 3095b2fc499SJeff Garzik USB_DEVICE (0x0E7E, 0x1001), // G.Mate "Yopy" 3105b2fc499SJeff Garzik .driver_info = (unsigned long) &yopy_info, 3115b2fc499SJeff Garzik }, { 3125b2fc499SJeff Garzik USB_DEVICE (0x8086, 0x07d3), // "blob" bootloader 3135b2fc499SJeff Garzik .driver_info = (unsigned long) &blob_info, 3145b2fc499SJeff Garzik }, { 315d4f01a77Sjing xiang USB_DEVICE (0x1286, 0x8001), // "blob" bootloader 316d4f01a77Sjing xiang .driver_info = (unsigned long) &blob_info, 317d4f01a77Sjing xiang }, { 3186be83252SDavid Brownell // Linux Ethernet/RNDIS gadget, mostly on PXA, second config 3196be83252SDavid Brownell // e.g. Gumstix, current OpenZaurus, ... or anything else 3206be83252SDavid Brownell // that just enables this gadget option. 3216be83252SDavid Brownell USB_DEVICE (0x0525, 0xa4a2), 3225b2fc499SJeff Garzik .driver_info = (unsigned long) &linuxdev_info, 3235b2fc499SJeff Garzik }, 3245b2fc499SJeff Garzik #endif 3255b2fc499SJeff Garzik 3265b2fc499SJeff Garzik { }, // END 3275b2fc499SJeff Garzik }; 3285b2fc499SJeff Garzik MODULE_DEVICE_TABLE(usb, products); 3295b2fc499SJeff Garzik 3305b2fc499SJeff Garzik /*-------------------------------------------------------------------------*/ 331dbcdd4d5SOliver Neukum static int dummy_prereset(struct usb_interface *intf) 332dbcdd4d5SOliver Neukum { 333dbcdd4d5SOliver Neukum return 0; 334dbcdd4d5SOliver Neukum } 335dbcdd4d5SOliver Neukum 336dbcdd4d5SOliver Neukum static int dummy_postreset(struct usb_interface *intf) 337dbcdd4d5SOliver Neukum { 338dbcdd4d5SOliver Neukum return 0; 339dbcdd4d5SOliver Neukum } 3405b2fc499SJeff Garzik 3415b2fc499SJeff Garzik static struct usb_driver cdc_subset_driver = { 3425b2fc499SJeff Garzik .name = "cdc_subset", 3435b2fc499SJeff Garzik .probe = usbnet_probe, 3445b2fc499SJeff Garzik .suspend = usbnet_suspend, 3455b2fc499SJeff Garzik .resume = usbnet_resume, 346dbcdd4d5SOliver Neukum .pre_reset = dummy_prereset, 347dbcdd4d5SOliver Neukum .post_reset = dummy_postreset, 3485b2fc499SJeff Garzik .disconnect = usbnet_disconnect, 3495b2fc499SJeff Garzik .id_table = products, 350e1f12eb6SSarah Sharp .disable_hub_initiated_lpm = 1, 3515b2fc499SJeff Garzik }; 3525b2fc499SJeff Garzik 353d632eb1bSGreg Kroah-Hartman module_usb_driver(cdc_subset_driver); 3545b2fc499SJeff Garzik 3555b2fc499SJeff Garzik MODULE_AUTHOR("David Brownell"); 3565b2fc499SJeff Garzik MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links"); 3575b2fc499SJeff Garzik MODULE_LICENSE("GPL"); 358