PCI/IOV: Move sysfs SR-IOV functions to iov.c
authorKelsey Skunberg <skunberg.kelsey@gmail.com>
Tue, 13 Aug 2019 20:45:13 +0000 (14:45 -0600)
committerBjorn Helgaas <bhelgaas@google.com>
Tue, 20 Aug 2019 19:05:05 +0000 (14:05 -0500)
The sysfs SR-IOV functions are only needed when the kernel is built with
SR-IOV support.  Rather than put them in pci-sysfs.c under #ifdef
CONFIG_PCI_IOV, move them to iov.c, which is only compiled when
CONFIG_PCI_IOV=y.

Link: https://lore.kernel.org/r/20190813204513.4790-4-skunberg.kelsey@gmail.com
Signed-off-by: Kelsey Skunberg <skunberg.kelsey@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Donald Dutile <ddutile@redhat.com>
Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
drivers/pci/iov.c
drivers/pci/pci-sysfs.c
drivers/pci/pci.h

index 525fd3f272b3c1f35dbd1f0c2d380a734cca2e37..05305436224795570cae0a05194b19b2d1df57d8 100644 (file)
@@ -240,6 +240,174 @@ void pci_iov_remove_virtfn(struct pci_dev *dev, int id)
        pci_dev_put(dev);
 }
 
+static ssize_t sriov_totalvfs_show(struct device *dev,
+                                  struct device_attribute *attr,
+                                  char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
+}
+
+static ssize_t sriov_numvfs_show(struct device *dev,
+                                struct device_attribute *attr,
+                                char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
+}
+
+/*
+ * num_vfs > 0; number of VFs to enable
+ * num_vfs = 0; disable all VFs
+ *
+ * Note: SRIOV spec does not allow partial VF
+ *      disable, so it's all or none.
+ */
+static ssize_t sriov_numvfs_store(struct device *dev,
+                                 struct device_attribute *attr,
+                                 const char *buf, size_t count)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       int ret;
+       u16 num_vfs;
+
+       ret = kstrtou16(buf, 0, &num_vfs);
+       if (ret < 0)
+               return ret;
+
+       if (num_vfs > pci_sriov_get_totalvfs(pdev))
+               return -ERANGE;
+
+       device_lock(&pdev->dev);
+
+       if (num_vfs == pdev->sriov->num_VFs)
+               goto exit;
+
+       /* is PF driver loaded w/callback */
+       if (!pdev->driver || !pdev->driver->sriov_configure) {
+               pci_info(pdev, "Driver does not support SRIOV configuration via sysfs\n");
+               ret = -ENOENT;
+               goto exit;
+       }
+
+       if (num_vfs == 0) {
+               /* disable VFs */
+               ret = pdev->driver->sriov_configure(pdev, 0);
+               goto exit;
+       }
+
+       /* enable VFs */
+       if (pdev->sriov->num_VFs) {
+               pci_warn(pdev, "%d VFs already enabled. Disable before enabling %d VFs\n",
+                        pdev->sriov->num_VFs, num_vfs);
+               ret = -EBUSY;
+               goto exit;
+       }
+
+       ret = pdev->driver->sriov_configure(pdev, num_vfs);
+       if (ret < 0)
+               goto exit;
+
+       if (ret != num_vfs)
+               pci_warn(pdev, "%d VFs requested; only %d enabled\n",
+                        num_vfs, ret);
+
+exit:
+       device_unlock(&pdev->dev);
+
+       if (ret < 0)
+               return ret;
+
+       return count;
+}
+
+static ssize_t sriov_offset_show(struct device *dev,
+                                struct device_attribute *attr,
+                                char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       return sprintf(buf, "%u\n", pdev->sriov->offset);
+}
+
+static ssize_t sriov_stride_show(struct device *dev,
+                                struct device_attribute *attr,
+                                char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       return sprintf(buf, "%u\n", pdev->sriov->stride);
+}
+
+static ssize_t sriov_vf_device_show(struct device *dev,
+                                   struct device_attribute *attr,
+                                   char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       return sprintf(buf, "%x\n", pdev->sriov->vf_device);
+}
+
+static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
+                                           struct device_attribute *attr,
+                                           char *buf)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+
+       return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
+}
+
+static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
+                                            struct device_attribute *attr,
+                                            const char *buf, size_t count)
+{
+       struct pci_dev *pdev = to_pci_dev(dev);
+       bool drivers_autoprobe;
+
+       if (kstrtobool(buf, &drivers_autoprobe) < 0)
+               return -EINVAL;
+
+       pdev->sriov->drivers_autoprobe = drivers_autoprobe;
+
+       return count;
+}
+
+static DEVICE_ATTR_RO(sriov_totalvfs);
+static DEVICE_ATTR(sriov_numvfs, 0664, sriov_numvfs_show, sriov_numvfs_store);
+static DEVICE_ATTR_RO(sriov_offset);
+static DEVICE_ATTR_RO(sriov_stride);
+static DEVICE_ATTR_RO(sriov_vf_device);
+static DEVICE_ATTR(sriov_drivers_autoprobe, 0664, sriov_drivers_autoprobe_show,
+                  sriov_drivers_autoprobe_store);
+
+static struct attribute *sriov_dev_attrs[] = {
+       &dev_attr_sriov_totalvfs.attr,
+       &dev_attr_sriov_numvfs.attr,
+       &dev_attr_sriov_offset.attr,
+       &dev_attr_sriov_stride.attr,
+       &dev_attr_sriov_vf_device.attr,
+       &dev_attr_sriov_drivers_autoprobe.attr,
+       NULL,
+};
+
+static umode_t sriov_attrs_are_visible(struct kobject *kobj,
+                                      struct attribute *a, int n)
+{
+       struct device *dev = kobj_to_dev(kobj);
+
+       if (!dev_is_pf(dev))
+               return 0;
+
+       return a->mode;
+}
+
+const struct attribute_group sriov_dev_attr_group = {
+       .attrs = sriov_dev_attrs,
+       .is_visible = sriov_attrs_are_visible,
+};
+
 int __weak pcibios_sriov_enable(struct pci_dev *pdev, u16 num_vfs)
 {
        return 0;
index 5bb301efec986af8c3e555ee6e34515cdb4c4243..868e351092844f8bf63f3c730cf50226833efea7 100644 (file)
@@ -548,151 +548,6 @@ static ssize_t devspec_show(struct device *dev,
 static DEVICE_ATTR_RO(devspec);
 #endif
 
-#ifdef CONFIG_PCI_IOV
-static ssize_t sriov_totalvfs_show(struct device *dev,
-                                  struct device_attribute *attr,
-                                  char *buf)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-
-       return sprintf(buf, "%u\n", pci_sriov_get_totalvfs(pdev));
-}
-
-
-static ssize_t sriov_numvfs_show(struct device *dev,
-                                struct device_attribute *attr,
-                                char *buf)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-
-       return sprintf(buf, "%u\n", pdev->sriov->num_VFs);
-}
-
-/*
- * num_vfs > 0; number of VFs to enable
- * num_vfs = 0; disable all VFs
- *
- * Note: SRIOV spec doesn't allow partial VF
- *       disable, so it's all or none.
- */
-static ssize_t sriov_numvfs_store(struct device *dev,
-                                 struct device_attribute *attr,
-                                 const char *buf, size_t count)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-       int ret;
-       u16 num_vfs;
-
-       ret = kstrtou16(buf, 0, &num_vfs);
-       if (ret < 0)
-               return ret;
-
-       if (num_vfs > pci_sriov_get_totalvfs(pdev))
-               return -ERANGE;
-
-       device_lock(&pdev->dev);
-
-       if (num_vfs == pdev->sriov->num_VFs)
-               goto exit;
-
-       /* is PF driver loaded w/callback */
-       if (!pdev->driver || !pdev->driver->sriov_configure) {
-               pci_info(pdev, "Driver doesn't support SRIOV configuration via sysfs\n");
-               ret = -ENOENT;
-               goto exit;
-       }
-
-       if (num_vfs == 0) {
-               /* disable VFs */
-               ret = pdev->driver->sriov_configure(pdev, 0);
-               goto exit;
-       }
-
-       /* enable VFs */
-       if (pdev->sriov->num_VFs) {
-               pci_warn(pdev, "%d VFs already enabled. Disable before enabling %d VFs\n",
-                        pdev->sriov->num_VFs, num_vfs);
-               ret = -EBUSY;
-               goto exit;
-       }
-
-       ret = pdev->driver->sriov_configure(pdev, num_vfs);
-       if (ret < 0)
-               goto exit;
-
-       if (ret != num_vfs)
-               pci_warn(pdev, "%d VFs requested; only %d enabled\n",
-                        num_vfs, ret);
-
-exit:
-       device_unlock(&pdev->dev);
-
-       if (ret < 0)
-               return ret;
-
-       return count;
-}
-
-static ssize_t sriov_offset_show(struct device *dev,
-                                struct device_attribute *attr,
-                                char *buf)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-
-       return sprintf(buf, "%u\n", pdev->sriov->offset);
-}
-
-static ssize_t sriov_stride_show(struct device *dev,
-                                struct device_attribute *attr,
-                                char *buf)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-
-       return sprintf(buf, "%u\n", pdev->sriov->stride);
-}
-
-static ssize_t sriov_vf_device_show(struct device *dev,
-                                   struct device_attribute *attr,
-                                   char *buf)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-
-       return sprintf(buf, "%x\n", pdev->sriov->vf_device);
-}
-
-static ssize_t sriov_drivers_autoprobe_show(struct device *dev,
-                                           struct device_attribute *attr,
-                                           char *buf)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-
-       return sprintf(buf, "%u\n", pdev->sriov->drivers_autoprobe);
-}
-
-static ssize_t sriov_drivers_autoprobe_store(struct device *dev,
-                                            struct device_attribute *attr,
-                                            const char *buf, size_t count)
-{
-       struct pci_dev *pdev = to_pci_dev(dev);
-       bool drivers_autoprobe;
-
-       if (kstrtobool(buf, &drivers_autoprobe) < 0)
-               return -EINVAL;
-
-       pdev->sriov->drivers_autoprobe = drivers_autoprobe;
-
-       return count;
-}
-
-static DEVICE_ATTR_RO(sriov_totalvfs);
-static DEVICE_ATTR(sriov_numvfs, 0664, sriov_numvfs_show, sriov_numvfs_store);
-static DEVICE_ATTR_RO(sriov_offset);
-static DEVICE_ATTR_RO(sriov_stride);
-static DEVICE_ATTR_RO(sriov_vf_device);
-static DEVICE_ATTR(sriov_drivers_autoprobe, 0664, sriov_drivers_autoprobe_show,
-                  sriov_drivers_autoprobe_store);
-#endif /* CONFIG_PCI_IOV */
-
 static ssize_t driver_override_store(struct device *dev,
                                     struct device_attribute *attr,
                                     const char *buf, size_t count)
@@ -1691,34 +1546,6 @@ static const struct attribute_group pci_dev_hp_attr_group = {
        .is_visible = pci_dev_hp_attrs_are_visible,
 };
 
-#ifdef CONFIG_PCI_IOV
-static struct attribute *sriov_dev_attrs[] = {
-       &dev_attr_sriov_totalvfs.attr,
-       &dev_attr_sriov_numvfs.attr,
-       &dev_attr_sriov_offset.attr,
-       &dev_attr_sriov_stride.attr,
-       &dev_attr_sriov_vf_device.attr,
-       &dev_attr_sriov_drivers_autoprobe.attr,
-       NULL,
-};
-
-static umode_t sriov_attrs_are_visible(struct kobject *kobj,
-                                      struct attribute *a, int n)
-{
-       struct device *dev = kobj_to_dev(kobj);
-
-       if (!dev_is_pf(dev))
-               return 0;
-
-       return a->mode;
-}
-
-static const struct attribute_group sriov_dev_attr_group = {
-       .attrs = sriov_dev_attrs,
-       .is_visible = sriov_attrs_are_visible,
-};
-#endif /* CONFIG_PCI_IOV */
-
 static const struct attribute_group pci_dev_attr_group = {
        .attrs = pci_dev_dev_attrs,
        .is_visible = pci_dev_attrs_are_visible,
index 1be03a97cb92c1ce9486a4b6ea0f037f7c18067f..061a935ac18e3896a057752b46e24a2d9baf753a 100644 (file)
@@ -433,7 +433,7 @@ void pci_iov_update_resource(struct pci_dev *dev, int resno);
 resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
 void pci_restore_iov_state(struct pci_dev *dev);
 int pci_iov_bus_range(struct pci_bus *bus);
-
+extern const struct attribute_group sriov_dev_attr_group;
 #else
 static inline int pci_iov_init(struct pci_dev *dev)
 {