xref: /openbmc/linux/drivers/net/usb/cdc_subset.c (revision 3692e94f)
15b2fc499SJeff Garzik /*
25b2fc499SJeff Garzik  * Simple "CDC Subset" USB Networking Links
35b2fc499SJeff Garzik  * Copyright (C) 2000-2005 by David Brownell
45b2fc499SJeff Garzik  *
55b2fc499SJeff Garzik  * This program is free software; you can redistribute it and/or modify
65b2fc499SJeff Garzik  * it under the terms of the GNU General Public License as published by
75b2fc499SJeff Garzik  * the Free Software Foundation; either version 2 of the License, or
85b2fc499SJeff Garzik  * (at your option) any later version.
95b2fc499SJeff Garzik  *
105b2fc499SJeff Garzik  * This program is distributed in the hope that it will be useful,
115b2fc499SJeff Garzik  * but WITHOUT ANY WARRANTY; without even the implied warranty of
125b2fc499SJeff Garzik  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
135b2fc499SJeff Garzik  * GNU General Public License for more details.
145b2fc499SJeff Garzik  *
155b2fc499SJeff Garzik  * You should have received a copy of the GNU General Public License
165b2fc499SJeff Garzik  * along with this program; if not, write to the Free Software
175b2fc499SJeff Garzik  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
185b2fc499SJeff Garzik  */
195b2fc499SJeff Garzik 
205b2fc499SJeff Garzik #include <linux/module.h>
215b2fc499SJeff Garzik #include <linux/kmod.h>
225b2fc499SJeff Garzik #include <linux/init.h>
235b2fc499SJeff Garzik #include <linux/netdevice.h>
245b2fc499SJeff Garzik #include <linux/etherdevice.h>
255b2fc499SJeff Garzik #include <linux/ethtool.h>
265b2fc499SJeff Garzik #include <linux/workqueue.h>
275b2fc499SJeff Garzik #include <linux/mii.h>
285b2fc499SJeff Garzik #include <linux/usb.h>
293692e94fSJussi Kivilinna #include <linux/usb/usbnet.h>
305b2fc499SJeff Garzik 
315b2fc499SJeff Garzik 
325b2fc499SJeff Garzik /*
335b2fc499SJeff Garzik  * This supports simple USB network links that don't require any special
345b2fc499SJeff Garzik  * framing or hardware control operations.  The protocol used here is a
355b2fc499SJeff Garzik  * strict subset of CDC Ethernet, with three basic differences reflecting
365b2fc499SJeff Garzik  * the goal that almost any hardware should run it:
375b2fc499SJeff Garzik  *
385b2fc499SJeff Garzik  *  - Minimal runtime control:  one interface, no altsettings, and
395b2fc499SJeff Garzik  *    no vendor or class specific control requests.  If a device is
405b2fc499SJeff Garzik  *    configured, it is allowed to exchange packets with the host.
415b2fc499SJeff Garzik  *    Fancier models would mean not working on some hardware.
425b2fc499SJeff Garzik  *
435b2fc499SJeff Garzik  *  - Minimal manufacturing control:  no IEEE "Organizationally
445b2fc499SJeff Garzik  *    Unique ID" required, or an EEPROMs to store one.  Each host uses
455b2fc499SJeff Garzik  *    one random "locally assigned" Ethernet address instead, which can
465b2fc499SJeff Garzik  *    of course be overridden using standard tools like "ifconfig".
475b2fc499SJeff Garzik  *    (With 2^46 such addresses, same-net collisions are quite rare.)
485b2fc499SJeff Garzik  *
495b2fc499SJeff Garzik  *  - There is no additional framing data for USB.  Packets are written
505b2fc499SJeff Garzik  *    exactly as in CDC Ethernet, starting with an Ethernet header and
515b2fc499SJeff Garzik  *    terminated by a short packet.  However, the host will never send a
525b2fc499SJeff Garzik  *    zero length packet; some systems can't handle those robustly.
535b2fc499SJeff Garzik  *
545b2fc499SJeff Garzik  * Anything that can transmit and receive USB bulk packets can implement
555b2fc499SJeff Garzik  * this protocol.  That includes both smart peripherals and quite a lot
565b2fc499SJeff Garzik  * of "host-to-host" USB cables (which embed two devices back-to-back).
575b2fc499SJeff Garzik  *
585b2fc499SJeff Garzik  * Note that although Linux may use many of those host-to-host links
595b2fc499SJeff Garzik  * with this "cdc_subset" framing, that doesn't mean there may not be a
605b2fc499SJeff Garzik  * better approach.  Handling the "other end unplugs/replugs" scenario
615b2fc499SJeff Garzik  * well tends to require chip-specific vendor requests.  Also, Windows
625b2fc499SJeff Garzik  * peers at the other end of host-to-host cables may expect their own
635b2fc499SJeff Garzik  * framing to be used rather than this "cdc_subset" model.
645b2fc499SJeff Garzik  */
655b2fc499SJeff Garzik 
665b2fc499SJeff Garzik #if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX)
675b2fc499SJeff Garzik /* PDA style devices are always connected if present */
685b2fc499SJeff Garzik static int always_connected (struct usbnet *dev)
695b2fc499SJeff Garzik {
705b2fc499SJeff Garzik 	return 0;
715b2fc499SJeff Garzik }
725b2fc499SJeff Garzik #endif
735b2fc499SJeff Garzik 
745b2fc499SJeff Garzik #ifdef	CONFIG_USB_ALI_M5632
755b2fc499SJeff Garzik #define	HAVE_HARDWARE
765b2fc499SJeff Garzik 
775b2fc499SJeff Garzik /*-------------------------------------------------------------------------
785b2fc499SJeff Garzik  *
795b2fc499SJeff Garzik  * ALi M5632 driver ... does high speed
805b2fc499SJeff Garzik  *
815b2fc499SJeff Garzik  * NOTE that the MS-Windows drivers for this chip use some funky and
825b2fc499SJeff Garzik  * (naturally) undocumented 7-byte prefix to each packet, so this is a
835b2fc499SJeff Garzik  * case where we don't currently interoperate.  Also, once you unplug
845b2fc499SJeff Garzik  * one end of the cable, you need to replug the other end too ... since
855b2fc499SJeff Garzik  * chip docs are unavailable, there's no way to reset the relevant state
865b2fc499SJeff Garzik  * short of a power cycle.
875b2fc499SJeff Garzik  *
885b2fc499SJeff Garzik  *-------------------------------------------------------------------------*/
895b2fc499SJeff Garzik 
905b2fc499SJeff Garzik static const struct driver_info	ali_m5632_info = {
915b2fc499SJeff Garzik 	.description =	"ALi M5632",
925b2fc499SJeff Garzik };
935b2fc499SJeff Garzik 
945b2fc499SJeff Garzik #endif
955b2fc499SJeff Garzik 
965b2fc499SJeff Garzik 
975b2fc499SJeff Garzik #ifdef	CONFIG_USB_AN2720
985b2fc499SJeff Garzik #define	HAVE_HARDWARE
995b2fc499SJeff Garzik 
1005b2fc499SJeff Garzik /*-------------------------------------------------------------------------
1015b2fc499SJeff Garzik  *
1025b2fc499SJeff Garzik  * AnchorChips 2720 driver ... http://www.cypress.com
1035b2fc499SJeff Garzik  *
1045b2fc499SJeff Garzik  * This doesn't seem to have a way to detect whether the peer is
1055b2fc499SJeff Garzik  * connected, or need any reset handshaking.  It's got pretty big
1065b2fc499SJeff Garzik  * internal buffers (handles most of a frame's worth of data).
1075b2fc499SJeff Garzik  * Chip data sheets don't describe any vendor control messages.
1085b2fc499SJeff Garzik  *
1095b2fc499SJeff Garzik  *-------------------------------------------------------------------------*/
1105b2fc499SJeff Garzik 
1115b2fc499SJeff Garzik static const struct driver_info	an2720_info = {
1125b2fc499SJeff Garzik 	.description =	"AnchorChips/Cypress 2720",
1135b2fc499SJeff Garzik 	// no reset available!
1145b2fc499SJeff Garzik 	// no check_connect available!
1155b2fc499SJeff Garzik 
1165b2fc499SJeff Garzik 	.in = 2, .out = 2,		// direction distinguishes these
1175b2fc499SJeff Garzik };
1185b2fc499SJeff Garzik 
1195b2fc499SJeff Garzik #endif	/* CONFIG_USB_AN2720 */
1205b2fc499SJeff Garzik 
1215b2fc499SJeff Garzik 
1225b2fc499SJeff Garzik #ifdef	CONFIG_USB_BELKIN
1235b2fc499SJeff Garzik #define	HAVE_HARDWARE
1245b2fc499SJeff Garzik 
1255b2fc499SJeff Garzik /*-------------------------------------------------------------------------
1265b2fc499SJeff Garzik  *
1275b2fc499SJeff Garzik  * Belkin F5U104 ... two NetChip 2280 devices + Atmel AVR microcontroller
1285b2fc499SJeff Garzik  *
1295b2fc499SJeff Garzik  * ... also two eTEK designs, including one sold as "Advance USBNET"
1305b2fc499SJeff Garzik  *
1315b2fc499SJeff Garzik  *-------------------------------------------------------------------------*/
1325b2fc499SJeff Garzik 
1335b2fc499SJeff Garzik static const struct driver_info	belkin_info = {
1345b2fc499SJeff Garzik 	.description =	"Belkin, eTEK, or compatible",
1355b2fc499SJeff Garzik };
1365b2fc499SJeff Garzik 
1375b2fc499SJeff Garzik #endif	/* CONFIG_USB_BELKIN */
1385b2fc499SJeff Garzik 
1395b2fc499SJeff Garzik 
1405b2fc499SJeff Garzik 
1415b2fc499SJeff Garzik #ifdef	CONFIG_USB_EPSON2888
1425b2fc499SJeff Garzik #define	HAVE_HARDWARE
1435b2fc499SJeff Garzik 
1445b2fc499SJeff Garzik /*-------------------------------------------------------------------------
1455b2fc499SJeff Garzik  *
1465b2fc499SJeff Garzik  * EPSON USB clients
1475b2fc499SJeff Garzik  *
1485b2fc499SJeff Garzik  * This is the same idea as Linux PDAs (below) except the firmware in the
1495b2fc499SJeff Garzik  * device might not be Tux-powered.  Epson provides reference firmware that
1505b2fc499SJeff Garzik  * implements this interface.  Product developers can reuse or modify that
1515b2fc499SJeff Garzik  * code, such as by using their own product and vendor codes.
1525b2fc499SJeff Garzik  *
1535b2fc499SJeff Garzik  * Support was from Juro Bystricky <bystricky.juro@erd.epson.com>
1545b2fc499SJeff Garzik  *
1555b2fc499SJeff Garzik  *-------------------------------------------------------------------------*/
1565b2fc499SJeff Garzik 
1575b2fc499SJeff Garzik static const struct driver_info	epson2888_info = {
1585b2fc499SJeff Garzik 	.description =	"Epson USB Device",
1595b2fc499SJeff Garzik 	.check_connect = always_connected,
1605b2fc499SJeff Garzik 
1615b2fc499SJeff Garzik 	.in = 4, .out = 3,
1625b2fc499SJeff Garzik };
1635b2fc499SJeff Garzik 
1645b2fc499SJeff Garzik #endif	/* CONFIG_USB_EPSON2888 */
1655b2fc499SJeff Garzik 
1665b2fc499SJeff Garzik 
1675b2fc499SJeff Garzik /*-------------------------------------------------------------------------
1685b2fc499SJeff Garzik  *
1695b2fc499SJeff Garzik  * info from Jonathan McDowell <noodles@earth.li>
1705b2fc499SJeff Garzik  *
1715b2fc499SJeff Garzik  *-------------------------------------------------------------------------*/
1725b2fc499SJeff Garzik #ifdef CONFIG_USB_KC2190
1735b2fc499SJeff Garzik #define HAVE_HARDWARE
1745b2fc499SJeff Garzik static const struct driver_info kc2190_info = {
1755b2fc499SJeff Garzik 	.description =  "KC Technology KC-190",
1765b2fc499SJeff Garzik };
1775b2fc499SJeff Garzik #endif /* CONFIG_USB_KC2190 */
1785b2fc499SJeff Garzik 
1795b2fc499SJeff Garzik 
1805b2fc499SJeff Garzik #ifdef	CONFIG_USB_ARMLINUX
1815b2fc499SJeff Garzik #define	HAVE_HARDWARE
1825b2fc499SJeff Garzik 
1835b2fc499SJeff Garzik /*-------------------------------------------------------------------------
1845b2fc499SJeff Garzik  *
1855b2fc499SJeff Garzik  * Intel's SA-1100 chip integrates basic USB support, and is used
1865b2fc499SJeff Garzik  * in PDAs like some iPaqs, the Yopy, some Zaurus models, and more.
1875b2fc499SJeff Garzik  * When they run Linux, arch/arm/mach-sa1100/usb-eth.c may be used to
1885b2fc499SJeff Garzik  * network using minimal USB framing data.
1895b2fc499SJeff Garzik  *
1905b2fc499SJeff Garzik  * This describes the driver currently in standard ARM Linux kernels.
1915b2fc499SJeff Garzik  * The Zaurus uses a different driver (see later).
1925b2fc499SJeff Garzik  *
1935b2fc499SJeff Garzik  * PXA25x and PXA210 use XScale cores (ARM v5TE) with better USB support
1945b2fc499SJeff Garzik  * and different USB endpoint numbering than the SA1100 devices.  The
1955b2fc499SJeff Garzik  * mach-pxa/usb-eth.c driver re-uses the device ids from mach-sa1100
1965b2fc499SJeff Garzik  * so we rely on the endpoint descriptors.
1975b2fc499SJeff Garzik  *
1985b2fc499SJeff Garzik  *-------------------------------------------------------------------------*/
1995b2fc499SJeff Garzik 
2005b2fc499SJeff Garzik static const struct driver_info	linuxdev_info = {
2015b2fc499SJeff Garzik 	.description =	"Linux Device",
2025b2fc499SJeff Garzik 	.check_connect = always_connected,
2035b2fc499SJeff Garzik };
2045b2fc499SJeff Garzik 
2055b2fc499SJeff Garzik static const struct driver_info	yopy_info = {
2065b2fc499SJeff Garzik 	.description =	"Yopy",
2075b2fc499SJeff Garzik 	.check_connect = always_connected,
2085b2fc499SJeff Garzik };
2095b2fc499SJeff Garzik 
2105b2fc499SJeff Garzik static const struct driver_info	blob_info = {
2115b2fc499SJeff Garzik 	.description =	"Boot Loader OBject",
2125b2fc499SJeff Garzik 	.check_connect = always_connected,
2135b2fc499SJeff Garzik };
2145b2fc499SJeff Garzik 
2155b2fc499SJeff Garzik #endif	/* CONFIG_USB_ARMLINUX */
2165b2fc499SJeff Garzik 
2175b2fc499SJeff Garzik 
2185b2fc499SJeff Garzik /*-------------------------------------------------------------------------*/
2195b2fc499SJeff Garzik 
2205b2fc499SJeff Garzik #ifndef	HAVE_HARDWARE
2215b2fc499SJeff Garzik #error You need to configure some hardware for this driver
2225b2fc499SJeff Garzik #endif
2235b2fc499SJeff Garzik 
2245b2fc499SJeff Garzik /*
2255b2fc499SJeff Garzik  * chip vendor names won't normally be on the cables, and
2265b2fc499SJeff Garzik  * may not be on the device.
2275b2fc499SJeff Garzik  */
2285b2fc499SJeff Garzik 
2295b2fc499SJeff Garzik static const struct usb_device_id	products [] = {
2305b2fc499SJeff Garzik 
2315b2fc499SJeff Garzik #ifdef	CONFIG_USB_ALI_M5632
2325b2fc499SJeff Garzik {
2335b2fc499SJeff Garzik 	USB_DEVICE (0x0402, 0x5632),	// ALi defaults
2345b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &ali_m5632_info,
2355b2fc499SJeff Garzik },
2365b2fc499SJeff Garzik {
2375b2fc499SJeff Garzik 	USB_DEVICE (0x182d,0x207c),	// SiteCom CN-124
2385b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &ali_m5632_info,
2395b2fc499SJeff Garzik },
2405b2fc499SJeff Garzik #endif
2415b2fc499SJeff Garzik 
2425b2fc499SJeff Garzik #ifdef	CONFIG_USB_AN2720
2435b2fc499SJeff Garzik {
2445b2fc499SJeff Garzik 	USB_DEVICE (0x0547, 0x2720),	// AnchorChips defaults
2455b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &an2720_info,
2465b2fc499SJeff Garzik }, {
2475b2fc499SJeff Garzik 	USB_DEVICE (0x0547, 0x2727),	// Xircom PGUNET
2485b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &an2720_info,
2495b2fc499SJeff Garzik },
2505b2fc499SJeff Garzik #endif
2515b2fc499SJeff Garzik 
2525b2fc499SJeff Garzik #ifdef	CONFIG_USB_BELKIN
2535b2fc499SJeff Garzik {
2545b2fc499SJeff Garzik 	USB_DEVICE (0x050d, 0x0004),	// Belkin
2555b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &belkin_info,
2565b2fc499SJeff Garzik }, {
2575b2fc499SJeff Garzik 	USB_DEVICE (0x056c, 0x8100),	// eTEK
2585b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &belkin_info,
2595b2fc499SJeff Garzik }, {
2605b2fc499SJeff Garzik 	USB_DEVICE (0x0525, 0x9901),	// Advance USBNET (eTEK)
2615b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &belkin_info,
2625b2fc499SJeff Garzik },
2635b2fc499SJeff Garzik #endif
2645b2fc499SJeff Garzik 
2655b2fc499SJeff Garzik #ifdef	CONFIG_USB_EPSON2888
2665b2fc499SJeff Garzik {
2675b2fc499SJeff Garzik 	USB_DEVICE (0x0525, 0x2888),	// EPSON USB client
2685b2fc499SJeff Garzik 	.driver_info	= (unsigned long) &epson2888_info,
2695b2fc499SJeff Garzik },
2705b2fc499SJeff Garzik #endif
2715b2fc499SJeff Garzik 
2725b2fc499SJeff Garzik #ifdef CONFIG_USB_KC2190
2735b2fc499SJeff Garzik {
2745b2fc499SJeff Garzik 	USB_DEVICE (0x050f, 0x0190),	// KC-190
2755b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &kc2190_info,
2765b2fc499SJeff Garzik },
2775b2fc499SJeff Garzik #endif
2785b2fc499SJeff Garzik 
2795b2fc499SJeff Garzik #ifdef	CONFIG_USB_ARMLINUX
2805b2fc499SJeff Garzik /*
2815b2fc499SJeff Garzik  * SA-1100 using standard ARM Linux kernels, or compatible.
2825b2fc499SJeff Garzik  * Often used when talking to Linux PDAs (iPaq, Yopy, etc).
2835b2fc499SJeff Garzik  * The sa-1100 "usb-eth" driver handles the basic framing.
2845b2fc499SJeff Garzik  *
2855b2fc499SJeff Garzik  * PXA25x or PXA210 ...  these use a "usb-eth" driver much like
2865b2fc499SJeff Garzik  * the sa1100 one, but hardware uses different endpoint numbers.
2875b2fc499SJeff Garzik  *
2885b2fc499SJeff Garzik  * Or the Linux "Ethernet" gadget on hardware that can't talk
2895b2fc499SJeff Garzik  * CDC Ethernet (e.g., no altsettings), in either of two modes:
2905b2fc499SJeff Garzik  *  - acting just like the old "usb-eth" firmware, though
2915b2fc499SJeff Garzik  *    the implementation is different
2925b2fc499SJeff Garzik  *  - supporting RNDIS as the first/default configuration for
2935b2fc499SJeff Garzik  *    MS-Windows interop; Linux needs to use the other config
2945b2fc499SJeff Garzik  */
2955b2fc499SJeff Garzik {
2965b2fc499SJeff Garzik 	// 1183 = 0x049F, both used as hex values?
2975b2fc499SJeff Garzik 	// Compaq "Itsy" vendor/product id
2985b2fc499SJeff Garzik 	USB_DEVICE (0x049F, 0x505A),	// usb-eth, or compatible
2995b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &linuxdev_info,
3005b2fc499SJeff Garzik }, {
3015b2fc499SJeff Garzik 	USB_DEVICE (0x0E7E, 0x1001),	// G.Mate "Yopy"
3025b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &yopy_info,
3035b2fc499SJeff Garzik }, {
3045b2fc499SJeff Garzik 	USB_DEVICE (0x8086, 0x07d3),	// "blob" bootloader
3055b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &blob_info,
3065b2fc499SJeff Garzik }, {
307d4f01a77Sjing xiang 	USB_DEVICE (0x1286, 0x8001),    // "blob" bootloader
308d4f01a77Sjing xiang 	.driver_info =  (unsigned long) &blob_info,
309d4f01a77Sjing xiang }, {
3105b2fc499SJeff Garzik 	// Linux Ethernet/RNDIS gadget on pxa210/25x/26x, second config
3115b2fc499SJeff Garzik 	// e.g. Gumstix, current OpenZaurus, ...
3125b2fc499SJeff Garzik 	USB_DEVICE_VER (0x0525, 0xa4a2, 0x0203, 0x0203),
3135b2fc499SJeff Garzik 	.driver_info =	(unsigned long) &linuxdev_info,
3145b2fc499SJeff Garzik },
3155b2fc499SJeff Garzik #endif
3165b2fc499SJeff Garzik 
3175b2fc499SJeff Garzik 	{ },		// END
3185b2fc499SJeff Garzik };
3195b2fc499SJeff Garzik MODULE_DEVICE_TABLE(usb, products);
3205b2fc499SJeff Garzik 
3215b2fc499SJeff Garzik /*-------------------------------------------------------------------------*/
3225b2fc499SJeff Garzik 
3235b2fc499SJeff Garzik static struct usb_driver cdc_subset_driver = {
3245b2fc499SJeff Garzik 	.name =		"cdc_subset",
3255b2fc499SJeff Garzik 	.probe =	usbnet_probe,
3265b2fc499SJeff Garzik 	.suspend =	usbnet_suspend,
3275b2fc499SJeff Garzik 	.resume =	usbnet_resume,
3285b2fc499SJeff Garzik 	.disconnect =	usbnet_disconnect,
3295b2fc499SJeff Garzik 	.id_table =	products,
3305b2fc499SJeff Garzik };
3315b2fc499SJeff Garzik 
3325b2fc499SJeff Garzik static int __init cdc_subset_init(void)
3335b2fc499SJeff Garzik {
3345b2fc499SJeff Garzik 	return usb_register(&cdc_subset_driver);
3355b2fc499SJeff Garzik }
3365b2fc499SJeff Garzik module_init(cdc_subset_init);
3375b2fc499SJeff Garzik 
3385b2fc499SJeff Garzik static void __exit cdc_subset_exit(void)
3395b2fc499SJeff Garzik {
3405b2fc499SJeff Garzik 	usb_deregister(&cdc_subset_driver);
3415b2fc499SJeff Garzik }
3425b2fc499SJeff Garzik module_exit(cdc_subset_exit);
3435b2fc499SJeff Garzik 
3445b2fc499SJeff Garzik MODULE_AUTHOR("David Brownell");
3455b2fc499SJeff Garzik MODULE_DESCRIPTION("Simple 'CDC Subset' USB networking links");
3465b2fc499SJeff Garzik MODULE_LICENSE("GPL");
347