drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c

Source file repositories/reference/linux-study-clean/drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c

File Facts

System
Linux kernel
Corpus path
drivers/net/ethernet/wangxun/ngbevf/ngbevf_main.c
Extension
.c
Size
7228 bytes
Lines
267
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 ngbevf_netdev_ops = {
	.ndo_open               = wxvf_open,
	.ndo_stop               = wxvf_close,
	.ndo_start_xmit         = wx_xmit_frame,
	.ndo_validate_addr      = eth_validate_addr,
	.ndo_set_mac_address    = wx_set_mac_vf,
};

static void ngbevf_set_num_queues(struct wx *wx)
{
	/* Start with base case */
	wx->num_rx_queues = 1;
	wx->num_tx_queues = 1;
}

static int ngbevf_sw_init(struct wx *wx)
{
	struct net_device *netdev = wx->netdev;
	struct pci_dev *pdev = wx->pdev;
	int err;

	/* Initialize pcie info and common capability flags */
	err = wx_sw_init(wx);
	if (err < 0)
		goto err_wx_sw_init;

	/* Initialize the mailbox */
	err = wx_init_mbx_params_vf(wx);
	if (err)
		goto err_init_mbx_params;

	/* Initialize the device type */
	wx->mac.type = wx_mac_em;
	wx->mac.max_msix_vectors = NGBEVF_MAX_MSIX_VECTORS;
	/* lock to protect mailbox accesses */
	spin_lock_init(&wx->mbx.mbx_lock);

	err = wx_reset_hw_vf(wx);
	if (err) {
		wx_err(wx, "PF still in reset state. Is the PF interface up?\n");
		goto err_reset_hw;
	}
	wx_init_hw_vf(wx);
	wx_negotiate_api_vf(wx);
	if (is_zero_ether_addr(wx->mac.addr))
		dev_info(&pdev->dev,
			 "MAC address not assigned by administrator.\n");
	eth_hw_addr_set(netdev, wx->mac.addr);

	if (!is_valid_ether_addr(netdev->dev_addr)) {
		dev_info(&pdev->dev, "Assigning random MAC address\n");
		eth_hw_addr_random(netdev);
		ether_addr_copy(wx->mac.addr, netdev->dev_addr);
		ether_addr_copy(wx->mac.perm_addr, netdev->dev_addr);
	}

	wx->mac.max_tx_queues = NGBEVF_MAX_TX_QUEUES;
	wx->mac.max_rx_queues = NGBEVF_MAX_RX_QUEUES;
	/* Enable dynamic interrupt throttling rates */
	wx->adaptive_itr = true;
	wx->rx_itr_setting = 1;
	wx->tx_itr_setting = 1;
	/* set default ring sizes */
	wx->tx_ring_count = NGBEVF_DEFAULT_TXD;
	wx->rx_ring_count = NGBEVF_DEFAULT_RXD;
	/* set default work limits */
	wx->tx_work_limit = NGBEVF_DEFAULT_TX_WORK;
	wx->rx_work_limit = NGBEVF_DEFAULT_RX_WORK;
	wx->set_num_queues = ngbevf_set_num_queues;

	return 0;
err_reset_hw:
	kfree(wx->vfinfo);
err_init_mbx_params:
	kfree(wx->rss_key);
	kfree(wx->mac_table);
err_wx_sw_init:
	return err;
}

/**
 * ngbevf_probe - Device Initialization Routine
 * @pdev: PCI device information struct
 * @ent: entry in ngbevf_pci_tbl
 *
 * Return: return 0 on success, negative on failure
 *
 * ngbevf_probe initializes an adapter identified by a pci_dev structure.
 * The OS initialization, configuring of the adapter private structure,
 * and a hardware reset occur.

Annotation

Implementation Notes