drivers/net/mctp/mctp-usb.c
Source file repositories/reference/linux-study-clean/drivers/net/mctp/mctp-usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/mctp/mctp-usb.c- Extension
.c- Size
- 8931 bytes
- Lines
- 398
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/netdevice.hlinux/usb.hlinux/usb/mctp-usb.hnet/mctp.hnet/mctpdevice.hnet/pkt_sched.huapi/linux/if_arp.h
Detected Declarations
struct mctp_usbfunction mctp_usb_out_completefunction mctp_usb_start_xmitfunction mctp_usb_rx_queuefunction mctp_usb_in_completefunction mctp_usb_rx_retry_workfunction mctp_usb_openfunction mctp_usb_stopfunction mctp_usb_netdev_setupfunction mctp_usb_probefunction mctp_usb_disconnect
Annotated Snippet
static const struct net_device_ops mctp_usb_netdev_ops = {
.ndo_start_xmit = mctp_usb_start_xmit,
.ndo_open = mctp_usb_open,
.ndo_stop = mctp_usb_stop,
};
static void mctp_usb_netdev_setup(struct net_device *dev)
{
dev->type = ARPHRD_MCTP;
dev->mtu = MCTP_USB_MTU_MIN;
dev->min_mtu = MCTP_USB_MTU_MIN;
dev->max_mtu = MCTP_USB_MTU_MAX;
dev->hard_header_len = sizeof(struct mctp_usb_hdr);
dev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
dev->flags = IFF_NOARP;
dev->netdev_ops = &mctp_usb_netdev_ops;
dev->pcpu_stat_type = NETDEV_PCPU_STAT_DSTATS;
}
static int mctp_usb_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_endpoint_descriptor *ep_in, *ep_out;
struct usb_host_interface *iface_desc;
struct net_device *netdev;
struct mctp_usb *dev;
int rc;
/* only one alternate */
iface_desc = intf->cur_altsetting;
rc = usb_find_common_endpoints(iface_desc, &ep_in, &ep_out, NULL, NULL);
if (rc) {
dev_err(&intf->dev, "invalid endpoints on device?\n");
return rc;
}
netdev = alloc_netdev(sizeof(*dev), "mctpusb%d", NET_NAME_ENUM,
mctp_usb_netdev_setup);
if (!netdev)
return -ENOMEM;
SET_NETDEV_DEV(netdev, &intf->dev);
dev = netdev_priv(netdev);
dev->netdev = netdev;
dev->usbdev = interface_to_usbdev(intf);
dev->intf = intf;
spin_lock_init(&dev->rx_lock);
usb_set_intfdata(intf, dev);
dev->ep_in = ep_in->bEndpointAddress;
dev->ep_out = ep_out->bEndpointAddress;
dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!dev->tx_urb || !dev->rx_urb) {
rc = -ENOMEM;
goto err_free_urbs;
}
INIT_DELAYED_WORK(&dev->rx_retry_work, mctp_usb_rx_retry_work);
rc = mctp_register_netdev(netdev, NULL, MCTP_PHYS_BINDING_USB);
if (rc)
goto err_free_urbs;
return 0;
err_free_urbs:
usb_free_urb(dev->tx_urb);
usb_free_urb(dev->rx_urb);
free_netdev(netdev);
return rc;
}
static void mctp_usb_disconnect(struct usb_interface *intf)
{
struct mctp_usb *dev = usb_get_intfdata(intf);
mctp_unregister_netdev(dev->netdev);
usb_free_urb(dev->tx_urb);
usb_free_urb(dev->rx_urb);
free_netdev(dev->netdev);
}
static const struct usb_device_id mctp_usb_devices[] = {
{ USB_INTERFACE_INFO(USB_CLASS_MCTP, 0x0, 0x1) },
{ 0 },
Annotation
- Immediate include surface: `linux/module.h`, `linux/netdevice.h`, `linux/usb.h`, `linux/usb/mctp-usb.h`, `net/mctp.h`, `net/mctpdevice.h`, `net/pkt_sched.h`, `uapi/linux/if_arp.h`.
- Detected declarations: `struct mctp_usb`, `function mctp_usb_out_complete`, `function mctp_usb_start_xmit`, `function mctp_usb_rx_queue`, `function mctp_usb_in_complete`, `function mctp_usb_rx_retry_work`, `function mctp_usb_open`, `function mctp_usb_stop`, `function mctp_usb_netdev_setup`, `function mctp_usb_probe`.
- 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.