Path: blob/master/Documentation/PCI/pci-iov-howto.txt
10821 views
PCI Express I/O Virtualization Howto1Copyright (C) 2009 Intel Corporation2Yu Zhao <[email protected]>3451. Overview671.1 What is SR-IOV89Single Root I/O Virtualization (SR-IOV) is a PCI Express Extended10capability which makes one physical device appear as multiple virtual11devices. The physical device is referred to as Physical Function (PF)12while the virtual devices are referred to as Virtual Functions (VF).13Allocation of the VF can be dynamically controlled by the PF via14registers encapsulated in the capability. By default, this feature is15not enabled and the PF behaves as traditional PCIe device. Once it's16turned on, each VF's PCI configuration space can be accessed by its own17Bus, Device and Function Number (Routing ID). And each VF also has PCI18Memory Space, which is used to map its register set. VF device driver19operates on the register set so it can be functional and appear as a20real existing PCI device.21222. User Guide23242.1 How can I enable SR-IOV capability2526The device driver (PF driver) will control the enabling and disabling27of the capability via API provided by SR-IOV core. If the hardware28has SR-IOV capability, loading its PF driver would enable it and all29VFs associated with the PF.30312.2 How can I use the Virtual Functions3233The VF is treated as hot-plugged PCI devices in the kernel, so they34should be able to work in the same way as real PCI devices. The VF35requires device driver that is same as a normal PCI device's.36373. Developer Guide38393.1 SR-IOV API4041To enable SR-IOV capability:42int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);43'nr_virtfn' is number of VFs to be enabled.4445To disable SR-IOV capability:46void pci_disable_sriov(struct pci_dev *dev);4748To notify SR-IOV core of Virtual Function Migration:49irqreturn_t pci_sriov_migration(struct pci_dev *dev);50513.2 Usage example5253Following piece of code illustrates the usage of the SR-IOV API.5455static int __devinit dev_probe(struct pci_dev *dev, const struct pci_device_id *id)56{57pci_enable_sriov(dev, NR_VIRTFN);5859...6061return 0;62}6364static void __devexit dev_remove(struct pci_dev *dev)65{66pci_disable_sriov(dev);6768...69}7071static int dev_suspend(struct pci_dev *dev, pm_message_t state)72{73...7475return 0;76}7778static int dev_resume(struct pci_dev *dev)79{80...8182return 0;83}8485static void dev_shutdown(struct pci_dev *dev)86{87...88}8990static struct pci_driver dev_driver = {91.name = "SR-IOV Physical Function driver",92.id_table = dev_id_table,93.probe = dev_probe,94.remove = __devexit_p(dev_remove),95.suspend = dev_suspend,96.resume = dev_resume,97.shutdown = dev_shutdown,98};99100101