drivers/net/ifb.c
Source file repositories/reference/linux-study-clean/drivers/net/ifb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ifb.c- Extension
.c- Size
- 11197 bytes
- Lines
- 459
- 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/kernel.hlinux/netdevice.hlinux/ethtool.hlinux/etherdevice.hlinux/init.hlinux/interrupt.hlinux/moduleparam.hlinux/netfilter_netdev.hnet/pkt_sched.hnet/net_namespace.h
Detected Declarations
struct ifb_q_statsstruct ifb_q_privatestruct ifb_dev_privatestruct ifb_q_stats_descfunction ifb_update_q_statsfunction ifb_ri_taskletfunction ifb_stats64function ifb_dev_initfunction ifb_get_stringsfunction ifb_get_sset_countfunction ifb_fill_stats_datafunction ifb_get_ethtool_statsfunction ifb_dev_freefunction ifb_setupfunction ifb_xmitfunction ifb_closefunction ifb_openfunction ifb_validatefunction ifb_init_onefunction ifb_init_modulefunction ifb_cleanup_modulemodule init ifb_init_module
Annotated Snippet
static const struct net_device_ops ifb_netdev_ops = {
.ndo_open = ifb_open,
.ndo_stop = ifb_close,
.ndo_get_stats64 = ifb_stats64,
.ndo_start_xmit = ifb_xmit,
.ndo_validate_addr = eth_validate_addr,
.ndo_init = ifb_dev_init,
};
static const struct ethtool_ops ifb_ethtool_ops = {
.get_strings = ifb_get_strings,
.get_sset_count = ifb_get_sset_count,
.get_ethtool_stats = ifb_get_ethtool_stats,
};
#define IFB_FEATURES (NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_FRAGLIST | \
NETIF_F_GSO_SOFTWARE | NETIF_F_GSO_ENCAP_ALL | \
NETIF_F_HIGHDMA | NETIF_F_HW_VLAN_CTAG_TX | \
NETIF_F_HW_VLAN_STAG_TX)
static void ifb_dev_free(struct net_device *dev)
{
struct ifb_dev_private *dp = netdev_priv(dev);
struct ifb_q_private *txp = dp->tx_private;
int i;
for (i = 0; i < dev->num_tx_queues; i++,txp++) {
tasklet_kill(&txp->ifb_tasklet);
__skb_queue_purge(&txp->rq);
__skb_queue_purge(&txp->tq);
}
kfree(dp->tx_private);
}
static void ifb_setup(struct net_device *dev)
{
/* Initialize the device structure. */
dev->netdev_ops = &ifb_netdev_ops;
dev->ethtool_ops = &ifb_ethtool_ops;
/* Fill in device structure with ethernet-generic values. */
ether_setup(dev);
dev->tx_queue_len = TX_Q_LIMIT;
dev->features |= IFB_FEATURES;
dev->hw_features |= dev->features;
dev->hw_enc_features |= dev->features;
dev->vlan_features |= IFB_FEATURES & ~(NETIF_F_HW_VLAN_CTAG_TX |
NETIF_F_HW_VLAN_STAG_TX);
dev->flags |= IFF_NOARP;
dev->flags &= ~IFF_MULTICAST;
dev->priv_flags &= ~IFF_TX_SKB_SHARING;
netif_keep_dst(dev);
eth_hw_addr_random(dev);
dev->needs_free_netdev = true;
dev->priv_destructor = ifb_dev_free;
dev->min_mtu = 0;
dev->max_mtu = 0;
netif_set_tso_max_size(dev, GSO_MAX_SIZE);
}
static netdev_tx_t ifb_xmit(struct sk_buff *skb, struct net_device *dev)
{
struct ifb_dev_private *dp = netdev_priv(dev);
struct ifb_q_private *txp = dp->tx_private + skb_get_queue_mapping(skb);
ifb_update_q_stats(&txp->rx_stats, skb->len);
if (!skb->redirected || !skb->skb_iif) {
dev_kfree_skb(skb);
dev->stats.rx_dropped++;
return NETDEV_TX_OK;
}
if (skb_queue_len(&txp->rq) >= dev->tx_queue_len)
netif_tx_stop_queue(netdev_get_tx_queue(dev, txp->txqnum));
__skb_queue_tail(&txp->rq, skb);
if (!txp->tasklet_pending) {
txp->tasklet_pending = 1;
tasklet_schedule(&txp->ifb_tasklet);
}
return NETDEV_TX_OK;
}
static int ifb_close(struct net_device *dev)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/netdevice.h`, `linux/ethtool.h`, `linux/etherdevice.h`, `linux/init.h`, `linux/interrupt.h`, `linux/moduleparam.h`.
- Detected declarations: `struct ifb_q_stats`, `struct ifb_q_private`, `struct ifb_dev_private`, `struct ifb_q_stats_desc`, `function ifb_update_q_stats`, `function ifb_ri_tasklet`, `function ifb_stats64`, `function ifb_dev_init`, `function ifb_get_strings`, `function ifb_get_sset_count`.
- 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.