drivers/net/xen-netfront.c
Source file repositories/reference/linux-study-clean/drivers/net/xen-netfront.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/xen-netfront.c- Extension
.c- Size
- 68833 bytes
- Lines
- 2721
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/kernel.hlinux/netdevice.hlinux/etherdevice.hlinux/skbuff.hlinux/ethtool.hlinux/if_ether.hnet/tcp.hlinux/udp.hlinux/moduleparam.hlinux/mm.hlinux/slab.hnet/ip.hlinux/bpf.hnet/page_pool/types.hlinux/bpf_trace.hxen/xen.hxen/xenbus.hxen/events.hxen/page.hxen/platform_pci.hxen/grant_table.hxen/interface/io/netif.hxen/interface/memory.hxen/interface/grant_table.h
Detected Declarations
struct netfront_cbstruct netfront_statsstruct netfront_infostruct netfront_queuestruct netfront_infostruct netfront_rx_infostruct xennet_gnttab_make_txreqfunction add_id_to_listfunction get_id_from_listfunction xennet_rxidxfunction xennet_get_rx_reffunction xennet_can_sgfunction rx_refill_timeoutfunction netfront_tx_slot_availablefunction xennet_maybe_wake_txfunction xennet_alloc_rx_buffersfunction unlikelyfunction xennet_openfunction xennet_tx_buf_gcfunction xennet_tx_setup_grantfunction xennet_make_one_txreqfunction xennet_make_txreqsfunction xennet_count_skb_slotsfunction xennet_select_queuefunction xennet_mark_tx_pendingfunction xennet_xdp_xmit_onefunction xennet_xdp_xmitfunction xennet_start_xmitfunction xennet_closefunction xennet_destroy_queuesfunction xennet_uninitfunction xennet_set_rx_rsp_consfunction xennet_move_rx_slotfunction xennet_get_extrasfunction xennet_run_xdpfunction xennet_get_responsesfunction xennet_set_skb_gsofunction xennet_fill_fragsfunction checksum_setupfunction handle_incoming_queuefunction xennet_pollfunction xennet_change_mtufunction xennet_get_stats64function for_each_possible_cpufunction xennet_release_tx_bufsfunction xennet_release_rx_bufsfunction xennet_fix_featuresfunction xennet_set_features
Annotated Snippet
static const struct net_device_ops xennet_netdev_ops = {
.ndo_uninit = xennet_uninit,
.ndo_open = xennet_open,
.ndo_stop = xennet_close,
.ndo_start_xmit = xennet_start_xmit,
.ndo_change_mtu = xennet_change_mtu,
.ndo_get_stats64 = xennet_get_stats64,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
.ndo_fix_features = xennet_fix_features,
.ndo_set_features = xennet_set_features,
.ndo_select_queue = xennet_select_queue,
.ndo_bpf = xennet_xdp,
.ndo_xdp_xmit = xennet_xdp_xmit,
#ifdef CONFIG_NET_POLL_CONTROLLER
.ndo_poll_controller = xennet_poll_controller,
#endif
};
static void xennet_free_netdev(struct net_device *netdev)
{
struct netfront_info *np = netdev_priv(netdev);
free_percpu(np->rx_stats);
free_percpu(np->tx_stats);
free_netdev(netdev);
}
static struct net_device *xennet_create_dev(struct xenbus_device *dev)
{
int err;
struct net_device *netdev;
struct netfront_info *np;
netdev = alloc_etherdev_mq(sizeof(struct netfront_info), xennet_max_queues);
if (!netdev)
return ERR_PTR(-ENOMEM);
np = netdev_priv(netdev);
np->xbdev = dev;
np->queues = NULL;
err = -ENOMEM;
np->rx_stats = netdev_alloc_pcpu_stats(struct netfront_stats);
if (np->rx_stats == NULL)
goto exit;
np->tx_stats = netdev_alloc_pcpu_stats(struct netfront_stats);
if (np->tx_stats == NULL)
goto exit;
netdev->netdev_ops = &xennet_netdev_ops;
netdev->features = NETIF_F_IP_CSUM | NETIF_F_RXCSUM |
NETIF_F_GSO_ROBUST;
netdev->hw_features = NETIF_F_SG |
NETIF_F_IPV6_CSUM |
NETIF_F_TSO | NETIF_F_TSO6;
/*
* Assume that all hw features are available for now. This set
* will be adjusted by the call to netdev_update_features() in
* xennet_connect() which is the earliest point where we can
* negotiate with the backend regarding supported features.
*/
netdev->features |= netdev->hw_features;
netdev->xdp_features = NETDEV_XDP_ACT_BASIC | NETDEV_XDP_ACT_REDIRECT |
NETDEV_XDP_ACT_NDO_XMIT;
netdev->ethtool_ops = &xennet_ethtool_ops;
netdev->min_mtu = ETH_MIN_MTU;
netdev->max_mtu = XEN_NETIF_MAX_TX_SIZE;
SET_NETDEV_DEV(netdev, &dev->dev);
np->netdev = netdev;
np->netfront_xdp_enabled = false;
netif_carrier_off(netdev);
do {
xenbus_switch_state(dev, XenbusStateInitialising);
err = wait_event_timeout(module_wq,
xenbus_read_driver_state(dev, dev->otherend) !=
XenbusStateClosed &&
xenbus_read_driver_state(dev, dev->otherend) !=
XenbusStateUnknown, XENNET_TIMEOUT);
} while (!err);
return netdev;
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/etherdevice.h`, `linux/skbuff.h`, `linux/ethtool.h`, `linux/if_ether.h`, `net/tcp.h`.
- Detected declarations: `struct netfront_cb`, `struct netfront_stats`, `struct netfront_info`, `struct netfront_queue`, `struct netfront_info`, `struct netfront_rx_info`, `struct xennet_gnttab_make_txreq`, `function add_id_to_list`, `function get_id_from_list`, `function xennet_rxidx`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.