drivers/net/ntb_netdev.c
Source file repositories/reference/linux-study-clean/drivers/net/ntb_netdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ntb_netdev.c- Extension
.c- Size
- 16739 bytes
- Lines
- 746
- 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/etherdevice.hlinux/ethtool.hlinux/module.hlinux/pci.hlinux/ntb.hlinux/ntb_transport.hlinux/slab.h
Detected Declarations
struct ntb_netdevstruct ntb_netdev_queuestruct ntb_netdevfunction ntb_netdev_update_carrierfunction ntb_netdev_queue_rx_drainfunction ntb_netdev_queue_rx_fillfunction ntb_netdev_event_handlerfunction ntb_netdev_rx_handlerfunction __ntb_netdev_maybe_stop_txfunction ntb_netdev_maybe_stop_txfunction ntb_netdev_tx_handlerfunction ntb_netdev_start_xmitfunction ntb_netdev_tx_timerfunction ntb_netdev_openfunction ntb_netdev_closefunction ntb_netdev_change_mtufunction ntb_get_drvinfofunction ntb_get_link_ksettingsfunction ntb_get_channelsfunction ntb_inc_channelsfunction ntb_dec_channelsfunction ntb_set_channelsfunction ntb_netdev_probefunction ntb_netdev_removefunction ntb_netdev_init_modulefunction ntb_netdev_exit_module
Annotated Snippet
static const struct net_device_ops ntb_netdev_ops = {
.ndo_open = ntb_netdev_open,
.ndo_stop = ntb_netdev_close,
.ndo_start_xmit = ntb_netdev_start_xmit,
.ndo_change_mtu = ntb_netdev_change_mtu,
.ndo_set_mac_address = eth_mac_addr,
};
static void ntb_get_drvinfo(struct net_device *ndev,
struct ethtool_drvinfo *info)
{
struct ntb_netdev *dev = netdev_priv(ndev);
strscpy(info->driver, KBUILD_MODNAME, sizeof(info->driver));
strscpy(info->version, NTB_NETDEV_VER, sizeof(info->version));
strscpy(info->bus_info, pci_name(dev->pdev), sizeof(info->bus_info));
}
static int ntb_get_link_ksettings(struct net_device *dev,
struct ethtool_link_ksettings *cmd)
{
ethtool_link_ksettings_zero_link_mode(cmd, supported);
ethtool_link_ksettings_add_link_mode(cmd, supported, Backplane);
ethtool_link_ksettings_zero_link_mode(cmd, advertising);
ethtool_link_ksettings_add_link_mode(cmd, advertising, Backplane);
cmd->base.speed = SPEED_UNKNOWN;
cmd->base.duplex = DUPLEX_FULL;
cmd->base.port = PORT_OTHER;
cmd->base.phy_address = 0;
cmd->base.autoneg = AUTONEG_ENABLE;
return 0;
}
static void ntb_get_channels(struct net_device *ndev,
struct ethtool_channels *channels)
{
struct ntb_netdev *dev = netdev_priv(ndev);
channels->combined_count = dev->num_queues;
channels->max_combined = ndev->num_tx_queues;
}
static int ntb_inc_channels(struct net_device *ndev,
unsigned int old, unsigned int new)
{
struct ntb_netdev *dev = netdev_priv(ndev);
bool running = netif_running(ndev);
struct ntb_netdev_queue *queue;
unsigned int q, created;
int rc;
created = old;
for (q = old; q < new; q++) {
queue = &dev->queues[q];
queue->ntdev = dev;
queue->qid = q;
queue->qp = ntb_transport_create_queue(queue, dev->client_dev,
&ntb_netdev_handlers);
if (!queue->qp) {
rc = -ENOSPC;
goto err_new;
}
created++;
if (!running)
continue;
timer_setup(&queue->tx_timer, ntb_netdev_tx_timer, 0);
rc = ntb_netdev_queue_rx_fill(ndev, queue);
if (rc)
goto err_new;
/*
* Carrier may already be on due to other QPs. Keep the new
* subqueue stopped until we get a Link Up event for this QP.
*/
netif_stop_subqueue(ndev, q);
}
rc = netif_set_real_num_queues(ndev, new, new);
if (rc)
goto err_new;
dev->num_queues = new;
if (running)
Annotation
- Immediate include surface: `linux/etherdevice.h`, `linux/ethtool.h`, `linux/module.h`, `linux/pci.h`, `linux/ntb.h`, `linux/ntb_transport.h`, `linux/slab.h`.
- Detected declarations: `struct ntb_netdev`, `struct ntb_netdev_queue`, `struct ntb_netdev`, `function ntb_netdev_update_carrier`, `function ntb_netdev_queue_rx_drain`, `function ntb_netdev_queue_rx_fill`, `function ntb_netdev_event_handler`, `function ntb_netdev_rx_handler`, `function __ntb_netdev_maybe_stop_tx`, `function ntb_netdev_maybe_stop_tx`.
- 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.