vf和pf一样,都有device和driver。pf的device是从bios中通过dsdt表传递过来的,但是vf的device却是在ixgbe的probe函数ixgbe_probe中会调用下面的code来增加vf的device
#ifdef CONFIG_PCI_IOV
/* SR-IOV not supported on the 82598 */
if (adapter->hw.mac.type == ixgbe_mac_82598EB)
goto skip_sriov;
/* Mailbox */
ixgbe_init_mbx_params_pf(hw);
hw->mbx.ops = ii->mbx_ops;
pci_sriov_set_totalvfs(pdev, IXGBE_MAX_VFS_DRV_LIMIT);
ixgbe_enable_sriov(adapter, max_vfs);
#endif
核心函数是ixgbe_enable_sriov->pci_enable_sriov->pci_iov_add_virtfn
int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset)
{
int i;
int rc = -ENOMEM;
u64 size;
char buf[VIRTFN_ID_LEN];
struct pci_dev *virtfn;
struct resource *res;
struct pci_sriov *iov = dev->sriov;
struct pci_bus *bus;
bus = virtfn_add_bus(dev->bus, pci_iov_virtfn_bus(dev, id));
if (!bus)
goto failed;
//申请struct pci_dev *virtfn;
virtfn = pci_alloc_dev(bus);
if (!virtfn)
goto failed0;
virtfn->devfn = pci_iov_virtfn_devfn(dev, id);
virtfn->vendor = dev->vendor;
pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device);
rc = pci_setup_device(virtfn);
if (rc)
goto failed0;
virtfn->dev.parent = dev->dev.parent;
virtfn->physfn = pci_dev_get(dev);
virtfn->is_virtfn = 1;
virtfn->multifunction = 0;
//添加device,最终在pci_device_add中调用device_add来添加device
pci_device_add(virtfn, virtfn->bus);
pci_bus_add_device(virtfn);
sprintf(buf, "virtfn%u", id);
rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
if (rc)
goto failed1;
rc = sysfs_create_link(&virtfn->dev.kobj, &dev->dev.kobj, "physfn");
if (rc)
goto failed2;
kobject_uevent(&virtfn->dev.kobj, KOBJ_CHANGE);
return 0;
return rc;
}
到这里vf的device 已经有了,vf的driver是在net/ethernet/intel/ixgbevf中,其入口函数是在ixgbevf_main.c中
前面添加device后,就会触发ixgbevf_driver的probe函数
static int __init ixgbevf_init_module(void)
{
pr_info("%s - version %s\n", ixgbevf_driver_string,
ixgbevf_driver_version);
pr_info("%s\n", ixgbevf_copyright);
ixgbevf_wq = create_singlethread_workqueue(ixgbevf_driver_name);
if (!ixgbevf_wq) {
pr_err("%s: Failed to create workqueue\n", ixgbevf_driver_name);
return -ENOMEM;
}
return pci_register_driver(&ixgbevf_driver);
}
ixgbevf_probe 函数就和正常的probe函数类似
vf的device和driver的匹配
最新推荐文章于 2023-05-07 10:50:18 发布