一、注册宏
1、RTE_PMD_REGISTER_PCI(net_ixgbe, rte_ixgbe_pmd)
调构造函数,在mian函数之前将rte_ixgbe_pmd驱动注册到rte_pci_bus.driver_list上,driver名为net_ixgbe; ---该链表在ret_bus_probe时触发;
2、RTE_PMD_REGISTER_PCI_TABLE(net_ixgbe, pci_id_ixgbe_map);
向PMD注册net_ixgbe驱动名上的网卡设备的id相关信息;
3、RTE_PMD_REGISTER_KMOD_DEP(net_ixgbe, "* igb_uio | uio_pci_generic | vfio-pci");
将net_ixgbe驱动名的驱动通过igb_uio绑定到PMD上;
二、实例
rte_ixgbe_pmd:
static struct rte_pci_driver rte_ixgbe_pmd = {
.id_table = pci_id_ixgbe_map, ---设置driver下的设备id信息
.drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC |
RTE_PCI_DRV_IOVA_AS_VA, ---设置driver的flag;
.probe = eth_ixgbe_pci_probe,
.remove = eth_ixgbe_pci_remove,
};
eth_ixgbe_pci_probe:
1、rte_eth_devargs_parse:若设备被传入参数,对参数字符串进行解析;
rte_eth_devargs_tokenise:解析出每个参数的key、value;
对每个参数列表,进行判断是不是representor的配置,若时候的话,获取representor的端口号
2、rte_eth_dev_create:
2.1.a、若为master CPU
2.1.a.1、rte_eth_dev_allocate:
rte_eth_dev_shared_data_prepare:获取网卡在主从CPU进行共享的内存rte_eth_dev_shared_data;
rte_eth_dev_find_free_port:若rte_eth_dev_shared_data->data[i].name[0]为0,说明该空间未被分配给网卡,返回i作为port;
eth_dev_get(port_id):根据port_id获取网卡设备的设备结构体eth_dev,执行struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id]、eth_dev->data = &rte_eth_dev_shared_data->data[port_id]将
网卡设备的data空间指向预申请的缓冲区,eth_dev指向全局的rte_eth_devices数组,返回eth_dev结构体继续对其进行初始化;
对eth_dev进行以下赋值:
strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name));
eth_dev->data->port_id = port_id;
eth_dev->data->mtu = RTE_ETHER_MTU;
返回eth_dev结构体;
2.1.a.2、若网卡设备有私有空间配置,从网卡设备绑定的cpu核申请私有空间;
2.1.b、若为slave cpu:
rte_eth_dev_attach_secondary:
strcmp(rte_eth_dev_shared_data->data[i].name, name)根据设备名,从共享空间获取设备的port,根据port获取eth_dev并返回;
2.2、获取device结构体成员eth_dev->device = &dev->device;
2.3、执行传入的ethdev_bus_specific_init回调:
rte_eth_copy_pci_info:从rte_pci_device(dpdk初始化时创建的)获取设备的中断处理回调函数、驱动的flag、io类型(UIO or VRIO)、绑定的核给eth_dev;
2.4、执行传入的ethdev_init回调:
对eth_dev收发包成员函数进行赋值;
获取网卡的mac地址等硬件信息;
注册网卡中断函数(检查网卡寄存器,根据寄存器状态执行相应的动作)、使能网卡中断;
初始化网卡过滤数据包的队列的链表;
2.5、rte_eth_dev_probing_finish:
执行_rte_eth_dev_callback_process:遍历eht_dev->link_intr_cbs链表,查找到RTE_ETH_EVENT_NEW事件类型的中断函数后进行执行;
设置eth_dev->state = RTE_ETH_DEV_ATTACHED;
3、若设备没配置representor,则退出;
4、进行representor的ent_dev创建:将主卡的物理信息、状态信息复制到representor