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