pci-iov-howto.txt 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. PCI Express I/O Virtualization Howto
  2. Copyright (C) 2009 Intel Corporation
  3. Yu Zhao <yu.zhao@intel.com>
  4. 1. Overview
  5. 1.1 What is SR-IOV
  6. Single Root I/O Virtualization (SR-IOV) is a PCI Express Extended
  7. capability which makes one physical device appear as multiple virtual
  8. devices. The physical device is referred to as Physical Function (PF)
  9. while the virtual devices are referred to as Virtual Functions (VF).
  10. Allocation of the VF can be dynamically controlled by the PF via
  11. registers encapsulated in the capability. By default, this feature is
  12. not enabled and the PF behaves as traditional PCIe device. Once it's
  13. turned on, each VF's PCI configuration space can be accessed by its own
  14. Bus, Device and Function Number (Routing ID). And each VF also has PCI
  15. Memory Space, which is used to map its register set. VF device driver
  16. operates on the register set so it can be functional and appear as a
  17. real existing PCI device.
  18. 2. User Guide
  19. 2.1 How can I enable SR-IOV capability
  20. The device driver (PF driver) will control the enabling and disabling
  21. of the capability via API provided by SR-IOV core. If the hardware
  22. has SR-IOV capability, loading its PF driver would enable it and all
  23. VFs associated with the PF.
  24. 2.2 How can I use the Virtual Functions
  25. The VF is treated as hot-plugged PCI devices in the kernel, so they
  26. should be able to work in the same way as real PCI devices. The VF
  27. requires device driver that is same as a normal PCI device's.
  28. 3. Developer Guide
  29. 3.1 SR-IOV API
  30. To enable SR-IOV capability:
  31. int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
  32. 'nr_virtfn' is number of VFs to be enabled.
  33. To disable SR-IOV capability:
  34. void pci_disable_sriov(struct pci_dev *dev);
  35. To notify SR-IOV core of Virtual Function Migration:
  36. irqreturn_t pci_sriov_migration(struct pci_dev *dev);
  37. 3.2 Usage example
  38. Following piece of code illustrates the usage of the SR-IOV API.
  39. static int __devinit dev_probe(struct pci_dev *dev, const struct pci_device_id *id)
  40. {
  41. pci_enable_sriov(dev, NR_VIRTFN);
  42. ...
  43. return 0;
  44. }
  45. static void __devexit dev_remove(struct pci_dev *dev)
  46. {
  47. pci_disable_sriov(dev);
  48. ...
  49. }
  50. static int dev_suspend(struct pci_dev *dev, pm_message_t state)
  51. {
  52. ...
  53. return 0;
  54. }
  55. static int dev_resume(struct pci_dev *dev)
  56. {
  57. ...
  58. return 0;
  59. }
  60. static void dev_shutdown(struct pci_dev *dev)
  61. {
  62. ...
  63. }
  64. static struct pci_driver dev_driver = {
  65. .name = "SR-IOV Physical Function driver",
  66. .id_table = dev_id_table,
  67. .probe = dev_probe,
  68. .remove = __devexit_p(dev_remove),
  69. .suspend = dev_suspend,
  70. .resume = dev_resume,
  71. .shutdown = dev_shutdown,
  72. };