Guest User

after

a guest
Dec 17th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.75 KB | None | 0 0
  1. /*
  2.  * num_vfs > 0; number of VFs to enable
  3.  * num_vfs = 0; disable all VFs
  4.  *
  5.  * Note: SRIOV spec doesn't allow partial VF
  6.  *       disable, so it's all or none.
  7.  */
  8. static ssize_t sriov_numvfs_store(struct device *dev,
  9.                                   struct device_attribute *attr,
  10.                                   const char *buf, size_t count)
  11. {
  12.         struct pci_dev *pdev = to_pci_dev(dev);
  13.         int ret;
  14.         u16 num_vfs;
  15.  
  16.         ret = kstrtou16(buf, 0, &num_vfs);
  17.         if (ret < 0)
  18.                 return ret;
  19.  
  20.         if (num_vfs > pci_sriov_get_totalvfs(pdev))
  21.                 return -ERANGE;
  22.  
  23.         if (num_vfs == pdev->sriov->num_VFs)
  24.                 return count;           /* no change */
  25.  
  26.         /* is PF driver loaded w/callback */
  27.         if (!pdev->driver || !pdev->driver->sriov_configure) {
  28.                 dev_info(&pdev->dev, "Driver doesn't support SRIOV configuration via sysfs\n");
  29.                 return -ENOSYS;
  30.         }
  31.  
  32.         if (num_vfs == 0) {
  33.                 /* disable VFs */
  34.                 ret = pdev->driver->sriov_configure(pdev, 0);
  35.                 if (ret < 0)
  36.                         return ret;
  37.                 return count;
  38.         }
  39.  
  40.         /* enable VFs */
  41.         if (pdev->sriov->num_VFs) {
  42.                 dev_warn(&pdev->dev, "%d VFs already enabled. Disable before enabling %d VFs\n",
  43.                          pdev->sriov->num_VFs, num_vfs);
  44.                 return -EINVAL;
  45.         }
  46.  
  47.         ret = pdev->driver->sriov_configure(pdev, num_vfs);
  48.         if (ret < 0)
  49.                 return ret;
  50.  
  51.         if (ret != num_vfs)
  52.                 dev_warn(&pdev->dev, "%d VFs requested; only %d enabled\n",
  53.                          num_vfs, ret);
  54.  
  55.         return count;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment