drivers/net/usb/cdc_subset.c

Source file repositories/reference/linux-study-clean/drivers/net/usb/cdc_subset.c

File Facts

System
Linux kernel
Corpus path
drivers/net/usb/cdc_subset.c
Extension
.c
Size
10864 bytes
Lines
358
Domain
Driver Families
Bucket
drivers/net
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Simple "CDC Subset" USB Networking Links
 * Copyright (C) 2000-2005 by David Brownell
 */

#include <linux/module.h>
#include <linux/kmod.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/workqueue.h>
#include <linux/mii.h>
#include <linux/usb.h>
#include <linux/usb/usbnet.h>


/*
 * This supports simple USB network links that don't require any special
 * framing or hardware control operations.  The protocol used here is a
 * strict subset of CDC Ethernet, with three basic differences reflecting
 * the goal that almost any hardware should run it:
 *
 *  - Minimal runtime control:  one interface, no altsettings, and
 *    no vendor or class specific control requests.  If a device is
 *    configured, it is allowed to exchange packets with the host.
 *    Fancier models would mean not working on some hardware.
 *
 *  - Minimal manufacturing control:  no IEEE "Organizationally
 *    Unique ID" required, or an EEPROMs to store one.  Each host uses
 *    one random "locally assigned" Ethernet address instead, which can
 *    of course be overridden using standard tools like "ifconfig".
 *    (With 2^46 such addresses, same-net collisions are quite rare.)
 *
 *  - There is no additional framing data for USB.  Packets are written
 *    exactly as in CDC Ethernet, starting with an Ethernet header and
 *    terminated by a short packet.  However, the host will never send a
 *    zero length packet; some systems can't handle those robustly.
 *
 * Anything that can transmit and receive USB bulk packets can implement
 * this protocol.  That includes both smart peripherals and quite a lot
 * of "host-to-host" USB cables (which embed two devices back-to-back).
 *
 * Note that although Linux may use many of those host-to-host links
 * with this "cdc_subset" framing, that doesn't mean there may not be a
 * better approach.  Handling the "other end unplugs/replugs" scenario
 * well tends to require chip-specific vendor requests.  Also, Windows
 * peers at the other end of host-to-host cables may expect their own
 * framing to be used rather than this "cdc_subset" model.
 */

#if defined(CONFIG_USB_EPSON2888) || defined(CONFIG_USB_ARMLINUX)
/* PDA style devices are always connected if present */
static int always_connected (struct usbnet *dev)
{
	return 0;
}
#endif

#ifdef	CONFIG_USB_ALI_M5632
#define	HAVE_HARDWARE

/*-------------------------------------------------------------------------
 *
 * ALi M5632 driver ... does high speed
 *
 * NOTE that the MS-Windows drivers for this chip use some funky and
 * (naturally) undocumented 7-byte prefix to each packet, so this is a
 * case where we don't currently interoperate.  Also, once you unplug
 * one end of the cable, you need to replug the other end too ... since
 * chip docs are unavailable, there's no way to reset the relevant state
 * short of a power cycle.
 *
 *-------------------------------------------------------------------------*/

static void m5632_recover(struct usbnet *dev)
{
	struct usb_device	*udev = dev->udev;
	struct usb_interface	*intf = dev->intf;
	int r;

	r = usb_lock_device_for_reset(udev, intf);
	if (r < 0)
		return;

	usb_reset_device(udev);
	usb_unlock_device(udev);
}

static const struct driver_info	ali_m5632_info = {

Annotation

Implementation Notes