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.

Dependency Surface

Detected Declarations

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

Implementation Notes