nvme/pci: Provide SR-IOV support
authorKeith Busch <keith.busch@intel.com>
Mon, 20 Jun 2016 15:41:06 +0000 (09:41 -0600)
committerJens Axboe <axboe@fb.com>
Thu, 21 Jul 2016 03:29:59 +0000 (21:29 -0600)
This registers an sr-iov callback for nvme.

Signed-off-by: Keith Busch <keith.busch@intel.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@fb.com>
drivers/nvme/host/pci.c

index 8083ae8ec96d865db6cb4b5e3d80033959e3fe70..78e0048a3391eefeae36fa5cf4427faca1a1cc3f 100644 (file)
@@ -2015,6 +2015,24 @@ static void nvme_remove(struct pci_dev *pdev)
        nvme_put_ctrl(&dev->ctrl);
 }
 
+static int nvme_pci_sriov_configure(struct pci_dev *pdev, int numvfs)
+{
+       int ret = 0;
+
+       if (numvfs == 0) {
+               if (pci_vfs_assigned(pdev)) {
+                       dev_warn(&pdev->dev,
+                               "Cannot disable SR-IOV VFs while assigned\n");
+                       return -EPERM;
+               }
+               pci_disable_sriov(pdev);
+               return 0;
+       }
+
+       ret = pci_enable_sriov(pdev, numvfs);
+       return ret ? ret : numvfs;
+}
+
 #ifdef CONFIG_PM_SLEEP
 static int nvme_suspend(struct device *dev)
 {
@@ -2117,6 +2135,7 @@ static struct pci_driver nvme_driver = {
        .driver         = {
                .pm     = &nvme_dev_pm_ops,
        },
+       .sriov_configure = nvme_pci_sriov_configure,
        .err_handler    = &nvme_err_handler,
 };