drivers/net/usb/cdc_ncm.c
Source file repositories/reference/linux-study-clean/drivers/net/usb/cdc_ncm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/usb/cdc_ncm.c- Extension
.c- Size
- 65335 bytes
- Lines
- 2144
- 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/netdevice.hlinux/ctype.hlinux/etherdevice.hlinux/ethtool.hlinux/kstrtox.hlinux/workqueue.hlinux/mii.hlinux/crc32.hlinux/usb.hlinux/hrtimer.hlinux/atomic.hlinux/usb/usbnet.hlinux/usb/cdc.hlinux/usb/cdc_ncm.h
Detected Declarations
struct cdc_ncm_statsfunction cdc_ncm_get_sset_countfunction cdc_ncm_get_ethtool_statsfunction cdc_ncm_get_stringsfunction cdc_ncm_check_rx_maxfunction cdc_ncm_check_tx_maxfunction min_tx_pkt_showfunction rx_max_showfunction tx_max_showfunction tx_timer_usecs_showfunction min_tx_pkt_storefunction rx_max_storefunction tx_max_storefunction tx_timer_usecs_storefunction ndp_to_end_showfunction ndp_to_end_storefunction cdc_ncm_update_rxtx_maxfunction cdc_ncm_flagsfunction cdc_ncm_eth_hlenfunction cdc_ncm_min_dgram_sizefunction cdc_ncm_max_dgram_sizefunction cdc_ncm_initfunction cdc_ncm_set_dgram_sizefunction cdc_ncm_fix_modulusfunction cdc_ncm_setupfunction cdc_ncm_find_endpointsfunction cdc_ncm_freefunction cdc_ncm_change_mtufunction cdc_ncm_bind_commonfunction cdc_ncm_unbindfunction cdc_ncm_select_altsettingfunction cdc_ncm_bindfunction cdc_ncm_align_tailfunction cdc_ncm_fill_tx_framefunction cdc_ncm_tx_timeout_startfunction cdc_ncm_tx_timer_cbfunction cdc_ncm_txpath_bhfunction cdc_ncm_tx_fixupfunction cdc_ncm_rx_verify_nth16function cdc_ncm_rx_verify_nth32function cdc_ncm_rx_verify_ndp16function cdc_ncm_rx_verify_ndp32function cdc_ncm_rx_fixupfunction cdc_ncm_speed_changefunction cdc_ncm_statusfunction cdc_ncm_update_filterexport cdc_ncm_change_mtuexport cdc_ncm_bind_common
Annotated Snippet
static const struct net_device_ops cdc_ncm_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_get_stats64 = dev_get_tstats64,
.ndo_change_mtu = cdc_ncm_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
};
int cdc_ncm_bind_common(struct usbnet *dev, struct usb_interface *intf, u8 data_altsetting, int drvflags)
{
struct cdc_ncm_ctx *ctx;
struct usb_driver *driver;
u8 *buf;
int len;
int temp;
u8 iface_no;
struct usb_cdc_parsed_header hdr;
ctx = kzalloc_obj(*ctx);
if (!ctx)
return -ENOMEM;
ctx->dev = dev;
hrtimer_setup(&ctx->tx_timer, &cdc_ncm_tx_timer_cb, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
tasklet_setup(&ctx->bh, cdc_ncm_txpath_bh);
atomic_set(&ctx->stop, 0);
spin_lock_init(&ctx->mtx);
/* store ctx pointer in device data field */
dev->data[0] = (unsigned long)ctx;
/* only the control interface can be successfully probed */
ctx->control = intf;
/* get some pointers */
driver = driver_of(intf);
buf = intf->cur_altsetting->extra;
len = intf->cur_altsetting->extralen;
/* parse through descriptors associated with control interface */
cdc_parse_cdc_header(&hdr, intf, buf, len);
if (hdr.usb_cdc_union_desc)
ctx->data = usb_ifnum_to_if(dev->udev,
hdr.usb_cdc_union_desc->bSlaveInterface0);
ctx->ether_desc = hdr.usb_cdc_ether_desc;
ctx->func_desc = hdr.usb_cdc_ncm_desc;
ctx->mbim_desc = hdr.usb_cdc_mbim_desc;
ctx->mbim_extended_desc = hdr.usb_cdc_mbim_extended_desc;
/* some buggy devices have an IAD but no CDC Union */
if (!hdr.usb_cdc_union_desc && intf->intf_assoc && intf->intf_assoc->bInterfaceCount == 2) {
ctx->data = usb_ifnum_to_if(dev->udev, intf->cur_altsetting->desc.bInterfaceNumber + 1);
dev_dbg(&intf->dev, "CDC Union missing - got slave from IAD\n");
}
/* check if we got everything */
if (!ctx->data) {
dev_err(&intf->dev, "CDC Union missing and no IAD found\n");
goto error;
}
if (cdc_ncm_comm_intf_is_mbim(intf->cur_altsetting)) {
if (!ctx->mbim_desc) {
dev_err(&intf->dev, "MBIM functional descriptor missing\n");
goto error;
}
} else {
if (!ctx->ether_desc || !ctx->func_desc) {
dev_err(&intf->dev, "NCM or ECM functional descriptors missing\n");
goto error;
}
}
/* claim data interface, if different from control */
if (ctx->data != ctx->control) {
temp = usb_driver_claim_interface(driver, ctx->data, dev);
if (temp) {
dev_err(&intf->dev, "failed to claim data intf\n");
goto error;
}
}
if (ctx->func_desc)
ctx->filtering_supported = !!(ctx->func_desc->bmNetworkCapabilities
& USB_CDC_NCM_NCAP_ETH_FILTER);
Annotation
- Immediate include surface: `linux/module.h`, `linux/netdevice.h`, `linux/ctype.h`, `linux/etherdevice.h`, `linux/ethtool.h`, `linux/kstrtox.h`, `linux/workqueue.h`, `linux/mii.h`.
- Detected declarations: `struct cdc_ncm_stats`, `function cdc_ncm_get_sset_count`, `function cdc_ncm_get_ethtool_stats`, `function cdc_ncm_get_strings`, `function cdc_ncm_check_rx_max`, `function cdc_ncm_check_tx_max`, `function min_tx_pkt_show`, `function rx_max_show`, `function tx_max_show`, `function tx_timer_usecs_show`.
- 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.