drivers/net/netdevsim/netdev.c
Source file repositories/reference/linux-study-clean/drivers/net/netdevsim/netdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/netdevsim/netdev.c- Extension
.c- Size
- 29896 bytes
- Lines
- 1275
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/debugfs.hlinux/etherdevice.hlinux/ethtool_netlink.hlinux/kernel.hlinux/module.hlinux/netdevice.hlinux/slab.hnet/netdev_queues.hnet/netdev_rx_queue.hnet/page_pool/helpers.hnet/netlink.hnet/net_shaper.hnet/netdev_lock.hnet/pkt_cls.hnet/rtnetlink.hnet/udp_tunnel.hnet/busy_poll.hnetdevsim.h
Detected Declarations
struct nsim_queue_memfunction nsim_start_peer_tx_queuefunction nsim_stop_tx_queuefunction nsim_napi_rxfunction nsim_forward_skbfunction nsim_start_xmitfunction nsim_set_rx_modefunction nsim_change_mtufunction nsim_set_vf_macfunction nsim_set_vf_vlanfunction nsim_set_vf_ratefunction nsim_set_vf_spoofchkfunction nsim_set_vf_rss_query_enfunction nsim_set_vf_trustfunction nsim_get_vf_configfunction nsim_set_vf_link_statefunction nsim_set_featuresfunction nsim_get_iflinkfunction nsim_rcvfunction nsim_pollfunction nsim_create_page_poolfunction nsim_init_napifunction nsim_napi_schedulefunction nsim_rq_timer_initfunction nsim_enable_napifunction nsim_openfunction nsim_del_napifunction nsim_stopfunction nsim_vlan_rx_add_vidfunction nsim_vlan_rx_kill_vidfunction nsim_shaper_setfunction nsim_shaper_delfunction nsim_shaper_groupfunction nsim_shaper_capfunction nsim_get_queue_stats_rxfunction nsim_get_queue_stats_txfunction nsim_get_base_statsfunction nsim_queue_freefunction nsim_queue_mem_allocfunction nsim_queue_mem_freefunction nsim_queue_startfunction nsim_queue_stopfunction nsim_qreset_writefunction nsim_pp_hold_readfunction nsim_pp_hold_writefunction nsim_vlan_showfunction nsim_setupfunction nsim_queue_init
Annotated Snippet
static const struct net_device_ops nsim_netdev_ops = {
.ndo_start_xmit = nsim_start_xmit,
.ndo_set_rx_mode_async = nsim_set_rx_mode,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
.ndo_change_mtu = nsim_change_mtu,
.ndo_set_vf_mac = nsim_set_vf_mac,
.ndo_set_vf_vlan = nsim_set_vf_vlan,
.ndo_set_vf_rate = nsim_set_vf_rate,
.ndo_set_vf_spoofchk = nsim_set_vf_spoofchk,
.ndo_set_vf_trust = nsim_set_vf_trust,
.ndo_get_vf_config = nsim_get_vf_config,
.ndo_set_vf_link_state = nsim_set_vf_link_state,
.ndo_set_vf_rss_query_en = nsim_set_vf_rss_query_en,
.ndo_setup_tc = nsim_setup_tc,
.ndo_set_features = nsim_set_features,
.ndo_get_iflink = nsim_get_iflink,
.ndo_bpf = nsim_bpf,
.ndo_open = nsim_open,
.ndo_stop = nsim_stop,
.ndo_vlan_rx_add_vid = nsim_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = nsim_vlan_rx_kill_vid,
.net_shaper_ops = &nsim_shaper_ops,
};
static const struct net_device_ops nsim_vf_netdev_ops = {
.ndo_start_xmit = nsim_start_xmit,
.ndo_set_rx_mode_async = nsim_set_rx_mode,
.ndo_set_mac_address = eth_mac_addr,
.ndo_validate_addr = eth_validate_addr,
.ndo_change_mtu = nsim_change_mtu,
.ndo_setup_tc = nsim_setup_tc,
.ndo_set_features = nsim_set_features,
.ndo_vlan_rx_add_vid = nsim_vlan_rx_add_vid,
.ndo_vlan_rx_kill_vid = nsim_vlan_rx_kill_vid,
};
/* We don't have true per-queue stats, yet, so do some random fakery here.
* Only report stuff for queue 0.
*/
static void nsim_get_queue_stats_rx(struct net_device *dev, int idx,
struct netdev_queue_stats_rx *stats)
{
struct rtnl_link_stats64 rtstats = {};
if (!idx)
dev_get_stats(dev, &rtstats);
stats->packets = rtstats.rx_packets - !!rtstats.rx_packets;
stats->bytes = rtstats.rx_bytes;
}
static void nsim_get_queue_stats_tx(struct net_device *dev, int idx,
struct netdev_queue_stats_tx *stats)
{
struct rtnl_link_stats64 rtstats = {};
if (!idx)
dev_get_stats(dev, &rtstats);
stats->packets = rtstats.tx_packets - !!rtstats.tx_packets;
stats->bytes = rtstats.tx_bytes;
}
static void nsim_get_base_stats(struct net_device *dev,
struct netdev_queue_stats_rx *rx,
struct netdev_queue_stats_tx *tx)
{
struct rtnl_link_stats64 rtstats = {};
dev_get_stats(dev, &rtstats);
rx->packets = !!rtstats.rx_packets;
rx->bytes = 0;
tx->packets = !!rtstats.tx_packets;
tx->bytes = 0;
}
static const struct netdev_stat_ops nsim_stat_ops = {
.get_queue_stats_tx = nsim_get_queue_stats_tx,
.get_queue_stats_rx = nsim_get_queue_stats_rx,
.get_base_stats = nsim_get_base_stats,
};
static struct nsim_rq *nsim_queue_alloc(void)
{
struct nsim_rq *rq;
rq = kzalloc_obj(*rq, GFP_KERNEL_ACCOUNT);
if (!rq)
Annotation
- Immediate include surface: `linux/debugfs.h`, `linux/etherdevice.h`, `linux/ethtool_netlink.h`, `linux/kernel.h`, `linux/module.h`, `linux/netdevice.h`, `linux/slab.h`, `net/netdev_queues.h`.
- Detected declarations: `struct nsim_queue_mem`, `function nsim_start_peer_tx_queue`, `function nsim_stop_tx_queue`, `function nsim_napi_rx`, `function nsim_forward_skb`, `function nsim_start_xmit`, `function nsim_set_rx_mode`, `function nsim_change_mtu`, `function nsim_set_vf_mac`, `function nsim_set_vf_vlan`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.