参考: https://blog.csdn.net/jeawayfox/article/details/105444104
net/hns3/hns3_ethdev.c:4918: return rte_eth_dev_pci_generic_probe(pci_dev,
rte_eal_init
rte_bus_scan
rte_pci_scan
rte_bus_probe
rte_eth_dev_pci_generic_probe(struct rte_pci_device *pci_dev, size_t private_data_size, eth_dev_pci_callback_t dev_init) { struct rte_eth_dev *eth_dev; int ret; eth_dev = rte_eth_dev_pci_allocate(pci_dev, private_data_size); if (!eth_dev) return -ENOMEM; RTE_FUNC_PTR_OR_ERR_RET(*dev_init, -EINVAL); ret = dev_init(eth_dev); if (ret) rte_eth_dev_pci_release(eth_dev); else rte_eth_dev_probing_finish(eth_dev); return ret; } rte_eth_dev_pci_allocate rte_eth_dev_allocate(name) struct rte_eth_dev * rte_eth_dev_allocated(const char *name) { struct rte_eth_dev *ethdev; rte_eth_dev_shared_data_prepare(); rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); ethdev = _rte_eth_dev_allocated(name); rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock); return ethdev; }
static struct rte_eth_dev * _rte_eth_dev_allocated(const char *name) { unsigned i; for (i = 0; i < RTE_MAX_ETHPORTS; i++) { if (rte_eth_devices[i].data != NULL && strcmp(rte_eth_devices[i].data->name, name) == 0) return &rte_eth_devices[i]; } return NULL; }
struct rte_eth_dev * rte_eth_dev_allocate(const char *name) { uint16_t port_id; struct rte_eth_dev *eth_dev = NULL; //申请进程间共享的data数据,用作挂到eth_dev->data下。 rte_eth_dev_shared_data_prepare(); /* Synchronize port creation between primary and secondary threads. */ rte_spinlock_lock(&rte_eth_dev_shared_data->ownership_lock); //check一下,此name是否已经被申请。 if (_rte_eth_dev_allocated(name) != NULL) { RTE_ETHDEV_LOG(ERR, "Ethernet device with name %s already allocated ", name); goto unlock; } //找到第一个free的port id号。 port_id = rte_eth_dev_find_free_port(); if (port_id == RTE_MAX_ETHPORTS) { RTE_ETHDEV_LOG(ERR, "Reached maximum number of Ethernet ports "); goto unlock; } //返回全局变量数组rte_eth_devices[port_id],同时把上面申请到的共享data数据,正式挂到eth_dev->data下。 eth_dev = eth_dev_get(port_id); snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name); eth_dev->data->port_id = port_id; eth_dev->data->mtu = ETHER_MTU; unlock: rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock); return eth_dev; }