aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/iov.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/iov.c')
-rw-r--r--drivers/pci/iov.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index de8ffacf9c9b..21a7182dccd4 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -286,7 +286,6 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
286 (!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial))) 286 (!(iov->cap & PCI_SRIOV_CAP_VFM) && (nr_virtfn > initial)))
287 return -EINVAL; 287 return -EINVAL;
288 288
289 pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, nr_virtfn);
290 pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_OFFSET, &offset); 289 pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_OFFSET, &offset);
291 pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_STRIDE, &stride); 290 pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_STRIDE, &stride);
292 if (!offset || (nr_virtfn > 1 && !stride)) 291 if (!offset || (nr_virtfn > 1 && !stride))
@@ -324,7 +323,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
324 323
325 if (!pdev->is_physfn) { 324 if (!pdev->is_physfn) {
326 pci_dev_put(pdev); 325 pci_dev_put(pdev);
327 return -ENODEV; 326 return -ENOSYS;
328 } 327 }
329 328
330 rc = sysfs_create_link(&dev->dev.kobj, 329 rc = sysfs_create_link(&dev->dev.kobj,
@@ -334,6 +333,7 @@ static int sriov_enable(struct pci_dev *dev, int nr_virtfn)
334 return rc; 333 return rc;
335 } 334 }
336 335
336 pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, nr_virtfn);
337 iov->ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE; 337 iov->ctrl |= PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE;
338 pci_cfg_access_lock(dev); 338 pci_cfg_access_lock(dev);
339 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); 339 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
@@ -368,6 +368,7 @@ failed:
368 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE); 368 iov->ctrl &= ~(PCI_SRIOV_CTRL_VFE | PCI_SRIOV_CTRL_MSE);
369 pci_cfg_access_lock(dev); 369 pci_cfg_access_lock(dev);
370 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl); 370 pci_write_config_word(dev, iov->pos + PCI_SRIOV_CTRL, iov->ctrl);
371 pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, 0);
371 ssleep(1); 372 ssleep(1);
372 pci_cfg_access_unlock(dev); 373 pci_cfg_access_unlock(dev);
373 374
@@ -401,6 +402,7 @@ static void sriov_disable(struct pci_dev *dev)
401 sysfs_remove_link(&dev->dev.kobj, "dep_link"); 402 sysfs_remove_link(&dev->dev.kobj, "dep_link");
402 403
403 iov->num_VFs = 0; 404 iov->num_VFs = 0;
405 pci_write_config_word(dev, iov->pos + PCI_SRIOV_NUM_VF, 0);
404} 406}
405 407
406static int sriov_init(struct pci_dev *dev, int pos) 408static int sriov_init(struct pci_dev *dev, int pos)
@@ -662,7 +664,7 @@ int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
662 might_sleep(); 664 might_sleep();
663 665
664 if (!dev->is_physfn) 666 if (!dev->is_physfn)
665 return -ENODEV; 667 return -ENOSYS;
666 668
667 return sriov_enable(dev, nr_virtfn); 669 return sriov_enable(dev, nr_virtfn);
668} 670}
@@ -722,7 +724,7 @@ EXPORT_SYMBOL_GPL(pci_num_vf);
722 * @dev: the PCI device 724 * @dev: the PCI device
723 * 725 *
724 * Returns number of VFs belonging to this device that are assigned to a guest. 726 * Returns number of VFs belonging to this device that are assigned to a guest.
725 * If device is not a physical function returns -ENODEV. 727 * If device is not a physical function returns 0.
726 */ 728 */
727int pci_vfs_assigned(struct pci_dev *dev) 729int pci_vfs_assigned(struct pci_dev *dev)
728{ 730{
@@ -767,12 +769,15 @@ EXPORT_SYMBOL_GPL(pci_vfs_assigned);
767 * device's mutex held. 769 * device's mutex held.
768 * 770 *
769 * Returns 0 if PF is an SRIOV-capable device and 771 * Returns 0 if PF is an SRIOV-capable device and
770 * value of numvfs valid. If not a PF with VFS, return -EINVAL; 772 * value of numvfs valid. If not a PF return -ENOSYS;
773 * if numvfs is invalid return -EINVAL;
771 * if VFs already enabled, return -EBUSY. 774 * if VFs already enabled, return -EBUSY.
772 */ 775 */
773int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs) 776int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
774{ 777{
775 if (!dev->is_physfn || (numvfs > dev->sriov->total_VFs)) 778 if (!dev->is_physfn)
779 return -ENOSYS;
780 if (numvfs > dev->sriov->total_VFs)
776 return -EINVAL; 781 return -EINVAL;
777 782
778 /* Shouldn't change if VFs already enabled */ 783 /* Shouldn't change if VFs already enabled */
@@ -786,17 +791,17 @@ int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
786EXPORT_SYMBOL_GPL(pci_sriov_set_totalvfs); 791EXPORT_SYMBOL_GPL(pci_sriov_set_totalvfs);
787 792
788/** 793/**
789 * pci_sriov_get_totalvfs -- get total VFs supported on this devic3 794 * pci_sriov_get_totalvfs -- get total VFs supported on this device
790 * @dev: the PCI PF device 795 * @dev: the PCI PF device
791 * 796 *
792 * For a PCIe device with SRIOV support, return the PCIe 797 * For a PCIe device with SRIOV support, return the PCIe
793 * SRIOV capability value of TotalVFs or the value of driver_max_VFs 798 * SRIOV capability value of TotalVFs or the value of driver_max_VFs
794 * if the driver reduced it. Otherwise, -EINVAL. 799 * if the driver reduced it. Otherwise 0.
795 */ 800 */
796int pci_sriov_get_totalvfs(struct pci_dev *dev) 801int pci_sriov_get_totalvfs(struct pci_dev *dev)
797{ 802{
798 if (!dev->is_physfn) 803 if (!dev->is_physfn)
799 return -EINVAL; 804 return 0;
800 805
801 if (dev->sriov->driver_max_VFs) 806 if (dev->sriov->driver_max_VFs)
802 return dev->sriov->driver_max_VFs; 807 return dev->sriov->driver_max_VFs;