drivers/net/usb/ipheth.c
Source file repositories/reference/linux-study-clean/drivers/net/usb/ipheth.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/usb/ipheth.c- Extension
.c- Size
- 18717 bytes
- Lines
- 696
- 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.
- 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/kernel.hlinux/errno.hlinux/slab.hlinux/module.hlinux/netdevice.hlinux/etherdevice.hlinux/ethtool.hlinux/usb.hlinux/workqueue.hlinux/usb/cdc.h
Detected Declarations
struct ipheth_devicefunction ipheth_alloc_urbsfunction ipheth_free_urbsfunction ipheth_kill_urbsfunction ipheth_consume_skbfunction ipheth_rcvbulk_callback_legacyfunction Blocksfunction ipheth_rcvbulk_callbackfunction ipheth_sndbulk_callbackfunction ipheth_carrier_setfunction ipheth_carrier_check_workfunction ipheth_get_macaddrfunction ipheth_enable_ncmfunction ipheth_rx_submitfunction ipheth_openfunction ipheth_closefunction ipheth_txfunction ipheth_tx_timeoutfunction ipheth_ethtool_op_get_linkfunction ipheth_probefunction ipheth_disconnect
Annotated Snippet
static const struct net_device_ops ipheth_netdev_ops = {
.ndo_open = ipheth_open,
.ndo_stop = ipheth_close,
.ndo_start_xmit = ipheth_tx,
.ndo_tx_timeout = ipheth_tx_timeout,
};
static int ipheth_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev = interface_to_usbdev(intf);
struct usb_endpoint_descriptor *ep_in, *ep_out;
struct usb_host_interface *hintf;
struct ipheth_device *dev;
struct net_device *netdev;
int retval;
netdev = alloc_etherdev(sizeof(struct ipheth_device));
if (!netdev)
return -ENOMEM;
netdev->netdev_ops = &ipheth_netdev_ops;
netdev->watchdog_timeo = IPHETH_TX_TIMEOUT;
strscpy(netdev->name, "eth%d", sizeof(netdev->name));
dev = netdev_priv(netdev);
dev->udev = udev;
dev->net = netdev;
dev->intf = intf;
dev->confirmed_pairing = false;
dev->rx_buf_len = IPHETH_RX_BUF_SIZE_LEGACY;
dev->rcvbulk_callback = ipheth_rcvbulk_callback_legacy;
/* Set up endpoints */
hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM);
if (hintf == NULL) {
retval = -ENODEV;
dev_err(&intf->dev, "Unable to find alternate settings interface\n");
goto err_endpoints;
}
retval = usb_find_common_endpoints_reverse(hintf, &ep_in, &ep_out,
NULL, NULL);
if (retval) {
dev_err(&intf->dev, "Unable to find endpoints\n");
goto err_endpoints;
}
dev->bulk_in = ep_in->bEndpointAddress;
dev->bulk_out = ep_out->bEndpointAddress;
dev->ctrl_buf = kmalloc(IPHETH_CTRL_BUF_SIZE, GFP_KERNEL);
if (dev->ctrl_buf == NULL) {
retval = -ENOMEM;
goto err_alloc_ctrl_buf;
}
retval = ipheth_get_macaddr(dev);
if (retval)
goto err_get_macaddr;
retval = ipheth_enable_ncm(dev);
if (!retval) {
dev->rx_buf_len = IPHETH_RX_BUF_SIZE_NCM;
dev->rcvbulk_callback = ipheth_rcvbulk_callback_ncm;
}
INIT_DELAYED_WORK(&dev->carrier_work, ipheth_carrier_check_work);
retval = ipheth_alloc_urbs(dev);
if (retval) {
dev_err(&intf->dev, "error allocating urbs: %d\n", retval);
goto err_alloc_urbs;
}
usb_set_intfdata(intf, dev);
SET_NETDEV_DEV(netdev, &intf->dev);
netdev->ethtool_ops = &ops;
retval = register_netdev(netdev);
if (retval) {
dev_err(&intf->dev, "error registering netdev: %d\n", retval);
retval = -EIO;
goto err_register_netdev;
}
// carrier down and transmit queues stopped until packet from device
netif_carrier_off(netdev);
netif_tx_stop_all_queues(netdev);
dev_info(&intf->dev, "Apple iPhone USB Ethernet device attached\n");
return 0;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/slab.h`, `linux/module.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/ethtool.h`, `linux/usb.h`.
- Detected declarations: `struct ipheth_device`, `function ipheth_alloc_urbs`, `function ipheth_free_urbs`, `function ipheth_kill_urbs`, `function ipheth_consume_skb`, `function ipheth_rcvbulk_callback_legacy`, `function Blocks`, `function ipheth_rcvbulk_callback`, `function ipheth_sndbulk_callback`, `function ipheth_carrier_set`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
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.