drivers/net/usb/usbnet.c
Source file repositories/reference/linux-study-clean/drivers/net/usb/usbnet.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/usb/usbnet.c- Extension
.c- Size
- 61395 bytes
- Lines
- 2294
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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.
- 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/hex.hlinux/init.hlinux/netdevice.hlinux/etherdevice.hlinux/ctype.hlinux/ethtool.hlinux/workqueue.hlinux/mii.hlinux/usb.hlinux/usb/usbnet.hlinux/slab.hlinux/kernel.hlinux/pm_runtime.h
Detected Declarations
function usbnet_get_endpointsfunction usbnet_get_ethernet_addrfunction usbnet_needs_usb_name_formatfunction intr_completefunction init_statusfunction usbnet_status_startfunction __usbnet_status_start_forcefunction usbnet_status_stopfunction __usbnet_status_stop_forcefunction usbnet_skb_returnfunction usbnet_update_max_qlenfunction Driverfunction __usbnet_queue_skbfunction defer_bhfunction tasklet_schedulefunction rx_submitfunction rx_processfunction rx_completefunction usbnet_pause_rxfunction usbnet_resume_rxfunction usbnet_purge_paused_rxqfunction unlink_urbsfunction skb_queue_walkfunction usbnet_unlink_rx_urbsfunction wait_skb_queue_emptyfunction usbnet_terminate_urbsfunction usbnet_stopfunction usbnet_openfunction usbnet_get_link_ksettings_miifunction usbnet_get_link_ksettings_internalfunction usbnet_set_link_ksettings_miifunction usbnet_get_linkfunction usbnet_nway_resetfunction usbnet_mii_ioctlfunction usbnet_get_drvinfofunction usbnet_get_msglevelfunction usbnet_set_msglevelfunction __handle_link_changefunction usbnet_set_rx_modefunction __handle_set_rx_modefunction usbnet_deferred_keventfunction tx_completefunction usbnet_tx_timeoutfunction build_dma_sgfunction usbnet_start_xmitfunction rx_alloc_submitfunction usb_free_skbfunction usbnet_bh
Annotated Snippet
static const struct net_device_ops usbnet_netdev_ops = {
.ndo_open = usbnet_open,
.ndo_stop = usbnet_stop,
.ndo_start_xmit = usbnet_start_xmit,
.ndo_tx_timeout = usbnet_tx_timeout,
.ndo_set_rx_mode = usbnet_set_rx_mode,
.ndo_change_mtu = usbnet_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
};
/*-------------------------------------------------------------------------*/
// precondition: never called in_interrupt
static const struct device_type wlan_type = {
.name = "wlan",
};
static const struct device_type wwan_type = {
.name = "wwan",
};
int
usbnet_probe(struct usb_interface *udev, const struct usb_device_id *prod)
{
struct usbnet *dev;
struct net_device *net;
struct usb_host_interface *interface;
const struct driver_info *info;
struct usb_device *xdev;
int status;
const char *name;
struct usb_driver *driver = to_usb_driver(udev->dev.driver);
/* usbnet already took usb runtime pm, so have to enable the feature
* for usb interface, otherwise usb_autopm_get_interface may return
* failure if RUNTIME_PM is enabled.
*/
if (!driver->supports_autosuspend) {
driver->supports_autosuspend = 1;
pm_runtime_enable(&udev->dev);
}
name = udev->dev.driver->name;
info = (const struct driver_info *) prod->driver_info;
if (!info) {
dev_dbg (&udev->dev, "blacklisted by %s\n", name);
return -ENODEV;
}
xdev = interface_to_usbdev(udev);
interface = udev->cur_altsetting;
status = -ENOMEM;
// set up our own records
net = alloc_etherdev(sizeof(*dev));
if (!net)
goto out;
/* netdev_printk() needs this so do it as early as possible */
SET_NETDEV_DEV(net, &udev->dev);
dev = netdev_priv(net);
dev->udev = xdev;
dev->intf = udev;
dev->driver_info = info;
dev->driver_name = name;
dev->rx_speed = SPEED_UNSET;
dev->tx_speed = SPEED_UNSET;
dev->msg_enable = netif_msg_init (msg_level, NETIF_MSG_DRV
| NETIF_MSG_PROBE | NETIF_MSG_LINK);
init_waitqueue_head(&dev->wait);
skb_queue_head_init (&dev->rxq);
skb_queue_head_init (&dev->txq);
skb_queue_head_init (&dev->done);
skb_queue_head_init(&dev->rxq_pause);
spin_lock_init(&dev->bql_spinlock);
INIT_WORK(&dev->bh_work, usbnet_bh_work);
INIT_WORK(&dev->kevent, usbnet_deferred_kevent);
init_usb_anchor(&dev->deferred);
timer_setup(&dev->delay, usbnet_bh, 0);
mutex_init(&dev->phy_mutex);
mutex_init(&dev->interrupt_mutex);
dev->interrupt_count = 0;
dev->net = net;
strscpy(net->name, "usb%d", sizeof(net->name));
Annotation
- Immediate include surface: `linux/module.h`, `linux/hex.h`, `linux/init.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/ctype.h`, `linux/ethtool.h`, `linux/workqueue.h`.
- Detected declarations: `function usbnet_get_endpoints`, `function usbnet_get_ethernet_addr`, `function usbnet_needs_usb_name_format`, `function intr_complete`, `function init_status`, `function usbnet_status_start`, `function __usbnet_status_start_force`, `function usbnet_status_stop`, `function __usbnet_status_stop_force`, `function usbnet_skb_return`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.