src/dpdk/drivers/net/cxgbe/cxgbevf_ethdev.c
static int eth_cxgbevf_dev_init(struct rte_eth_dev *eth_dev)
{
	struct port_info *pi = eth_dev->data->dev_private;
	struct rte_pci_device *pci_dev;
	char name[RTE_ETH_NAME_MAX_LEN];
	struct adapter *adapter = NULL;
	int err = 0;

	CXGBE_FUNC_TRACE();

	eth_dev->dev_ops = &cxgbevf_eth_dev_ops;
	eth_dev->rx_pkt_burst = &cxgbe_recv_pkts;
	eth_dev->tx_pkt_burst = &cxgbe_xmit_pkts;
	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);

	/* for secondary processes, we attach to ethdevs allocated by primary
	 * and do minimal initialization.
	 */
	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
		int i;

		for (i = 1; i < MAX_NPORTS; i++) {
			struct rte_eth_dev *rest_eth_dev;
			char namei[RTE_ETH_NAME_MAX_LEN];

			snprintf(namei, sizeof(namei), "%s_%d",
				 pci_dev->device.name, i);
			rest_eth_dev = rte_eth_dev_attach_secondary(namei);
			if (rest_eth_dev) {
				rest_eth_dev->device = &pci_dev->device;
				rest_eth_dev->dev_ops =
					eth_dev->dev_ops;
				rest_eth_dev->rx_pkt_burst =
					eth_dev->rx_pkt_burst;
				rest_eth_dev->tx_pkt_burst =
					eth_dev->tx_pkt_burst;
				rte_eth_dev_probing_finish(rest_eth_dev);
			}
		}
		return 0;
	}

	snprintf(name, sizeof(name), "cxgbevfadapter%d",
		 eth_dev->data->port_id);
	adapter = rte_zmalloc(name, sizeof(*adapter), 0);
	if (!adapter)
		return -1;

	adapter->use_unpacked_mode = 1;
	adapter->regs = (void *)pci_dev->mem_resource[0].addr;
	if (!adapter->regs) {
		dev_err(adapter, "%s: cannot map device registers\n", __func__);
		err = -ENOMEM;
		goto out_free_adapter;
	}
	adapter->pdev = pci_dev;
	adapter->eth_dev = eth_dev;
	pi->adapter = adapter;

	cxgbe_process_devargs(adapter);

	err = cxgbevf_probe(adapter);
	if (err) {
		dev_err(adapter, "%s: cxgbevf probe failed with err %d\n",
			__func__, err);
		goto out_free_adapter;
	}

	return 0;

out_free_adapter:
	rte_free(adapter);
	return err;
}
/*
 * Initialize driver
 * It returns 0 on success.
 */
Initialize driver
It returns 0 on success.
Initialize driver It returns 0 on success .
static int eth_cxgbevf_dev_init(struct rte_eth_dev *eth_dev)
{
	struct port_info *pi = eth_dev->data->dev_private;
	struct rte_pci_device *pci_dev;
	char name[RTE_ETH_NAME_MAX_LEN];
	struct adapter *adapter = NULL;
	int err = 0;
	CXGBE_FUNC_TRACE();
	eth_dev->dev_ops = &cxgbevf_eth_dev_ops;
	eth_dev->rx_pkt_burst = &cxgbe_recv_pkts;
	eth_dev->tx_pkt_burst = &cxgbe_xmit_pkts;
	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
	if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
		int i;
		for (i = 1; i < MAX_NPORTS; i++) {
			struct rte_eth_dev *rest_eth_dev;
			char namei[RTE_ETH_NAME_MAX_LEN];
			snprintf(namei, sizeof(namei), "%s_%d",
				 pci_dev->device.name, i);
			rest_eth_dev = rte_eth_dev_attach_secondary(namei);
			if (rest_eth_dev) {
				rest_eth_dev->device = &pci_dev->device;
				rest_eth_dev->dev_ops =
					eth_dev->dev_ops;
				rest_eth_dev->rx_pkt_burst =
					eth_dev->rx_pkt_burst;
				rest_eth_dev->tx_pkt_burst =
					eth_dev->tx_pkt_burst;
				rte_eth_dev_probing_finish(rest_eth_dev);
			}
		}
		return 0;
	}
	snprintf(name, sizeof(name), "cxgbevfadapter%d",
		 eth_dev->data->port_id);
	adapter = rte_zmalloc(name, sizeof(*adapter), 0);
	if (!adapter)
		return -1;
	adapter->use_unpacked_mode = 1;
	adapter->regs = (void *)pci_dev->mem_resource[0].addr;
	if (!adapter->regs) {
		dev_err(adapter, "%s: cannot map device registers\n", __func__);
		err = -ENOMEM;
		goto out_free_adapter;
	}
	adapter->pdev = pci_dev;
	adapter->eth_dev = eth_dev;
	pi->adapter = adapter;
	cxgbe_process_devargs(adapter);
	err = cxgbevf_probe(adapter);
	if (err) {
		dev_err(adapter, "%s: cxgbevf probe failed with err %d\n",
			__func__, err);
		goto out_free_adapter;
	}
	return 0;
out_free_adapter:
	rte_free(adapter);
	return err;
}
static int eth_cxgbevf_dev_init ( struct rte_eth_dev * eth_dev ) { struct port_info * pi = eth_dev -> data -> dev_private ; struct rte_pci_device * pci_dev ; char name [ RTE_ETH_NAME_MAX_LEN ] ; struct adapter * adapter = NULL ; int err = 0 ; CXGBE_FUNC_TRACE ( ) ; eth_dev -> dev_ops = & cxgbevf_eth_dev_ops ; eth_dev -> rx_pkt_burst = & cxgbe_recv_pkts ; eth_dev -> tx_pkt_burst = & cxgbe_xmit_pkts ; pci_dev = RTE_ETH_DEV_TO_PCI ( eth_dev ) ; if ( rte_eal_process_type ( ) != RTE_PROC_PRIMARY ) { int i ; for ( i = 1 ; i < MAX_NPORTS ; i ++ ) { struct rte_eth_dev * rest_eth_dev ; char namei [ RTE_ETH_NAME_MAX_LEN ] ; snprintf ( namei , sizeof ( namei ) , " " , pci_dev -> device . name , i ) ; rest_eth_dev = rte_eth_dev_attach_secondary ( namei ) ; if ( rest_eth_dev ) { rest_eth_dev -> device = & pci_dev -> device ; rest_eth_dev -> dev_ops = eth_dev -> dev_ops ; rest_eth_dev -> rx_pkt_burst = eth_dev -> rx_pkt_burst ; rest_eth_dev -> tx_pkt_burst = eth_dev -> tx_pkt_burst ; rte_eth_dev_probing_finish ( rest_eth_dev ) ; } } return 0 ; } snprintf ( name , sizeof ( name ) , " " , eth_dev -> data -> port_id ) ; adapter = rte_zmalloc ( name , sizeof ( * adapter ) , 0 ) ; if ( ! adapter ) return -1 ; adapter -> use_unpacked_mode = 1 ; adapter -> regs = ( void * ) pci_dev -> mem_resource [ 0 ] . addr ; if ( ! adapter -> regs ) { dev_err ( adapter , " \n " , __func__ ) ; err = - ENOMEM ; goto out_free_adapter ; } adapter -> pdev = pci_dev ; adapter -> eth_dev = eth_dev ; pi -> adapter = adapter ; cxgbe_process_devargs ( adapter ) ; err = cxgbevf_probe ( adapter ) ; if ( err ) { dev_err ( adapter , " \n " , __func__ , err ) ; goto out_free_adapter ; } return 0 ; out_free_adapter : rte_free ( adapter ) ; return err ; }
Initialize driver
 It returns 0 on success.
Initialize driver It returns 0 on success .
/* for secondary processes, we attach to ethdevs allocated by primary
	 * and do minimal initialization.
	 */