Guest User

before

a guest
Dec 17th, 2012
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.89 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 its 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 num_vfs_enabled = 0;
  14.         int num_vfs;
  15.         int ret = 0;
  16.         u16 total;
  17.  
  18.         if (kstrtoint(buf, 0, &num_vfs) < 0)
  19.                 return -EINVAL;
  20.  
  21.         /* is PF driver loaded w/callback */
  22.         if (!pdev->driver || !pdev->driver->sriov_configure) {
  23.                 dev_info(&pdev->dev,
  24.                          "Driver doesn't support SRIOV configuration via sysfs\n");
  25.                 return -ENOSYS;
  26.         }
  27.  
  28.         /* if enabling vf's ... */
  29.         total = pci_sriov_get_totalvfs(pdev);
  30.         /* Requested VFs to enable < totalvfs and none enabled already */
  31.         if ((num_vfs > 0) && (num_vfs <= total)) {
  32.                 if (pdev->sriov->num_VFs == 0) {
  33.                         num_vfs_enabled =
  34.                                 pdev->driver->sriov_configure(pdev, num_vfs);
  35.                         if ((num_vfs_enabled >= 0) &&
  36.                             (num_vfs_enabled != num_vfs)) {
  37.                                 dev_warn(&pdev->dev,
  38.                                          "Only %d VFs enabled\n",
  39.                                          num_vfs_enabled);
  40.                                 return count;
  41.                         } else if (num_vfs_enabled < 0)
  42.                                 /* error code from driver callback */
  43.                                 return num_vfs_enabled;
  44.                 } else if (num_vfs == pdev->sriov->num_VFs) {
  45.                         dev_warn(&pdev->dev,
  46.                                  "%d VFs already enabled; no enable action taken\n",
  47.                                  num_vfs);
  48.                         return count;
  49.                 } else {
  50.                         dev_warn(&pdev->dev,
  51.                                  "%d VFs already enabled. Disable before enabling %d VFs\n",
  52.                                  pdev->sriov->num_VFs, num_vfs);
  53.                         return -EINVAL;
  54.                 }
  55.         }
  56.  
  57.         /* disable vfs */
  58.         if (num_vfs == 0) {
  59.                 if (pdev->sriov->num_VFs != 0) {
  60.                         ret = pdev->driver->sriov_configure(pdev, 0);
  61.                         return ret ? ret : count;
  62.                 } else {
  63.                         dev_warn(&pdev->dev,
  64.                                  "All VFs disabled; no disable action taken\n");
  65.                         return count;
  66.                 }
  67.         }
  68.  
  69.         dev_err(&pdev->dev,
  70.                 "Invalid value for number of VFs to enable: %d\n", num_vfs);
  71.  
  72.         return -EINVAL;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment