PCI: Expose SR-IOV offset, stride, and VF device ID via sysfs
authorFilippo Sironi <sironi@amazon.de>
Sun, 8 Oct 2017 23:09:11 +0000 (01:09 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 11 Oct 2017 00:12:12 +0000 (19:12 -0500)
Expose the SR-IOV device offset, stride, and VF device ID via sysfs to make
it easier for userspace applications to consume them.

Signed-off-by: Filippo Sironi <sironi@amazon.de>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/pci-sysfs.c

index 8e075ea2743ef41b4ed08065f502527cbe804c82..3ea7a62a5d4f12c1ecccd2f6ef8a9c8ec3acd251 100644 (file)
@@ -648,6 +648,33 @@ exit:
        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)
@@ -676,6 +703,9 @@ static struct device_attribute sriov_totalvfs_attr = __ATTR_RO(sriov_totalvfs);
 static struct device_attribute sriov_numvfs_attr =
                __ATTR(sriov_numvfs, (S_IRUGO|S_IWUSR|S_IWGRP),
                       sriov_numvfs_show, sriov_numvfs_store);
+static struct device_attribute sriov_offset_attr = __ATTR_RO(sriov_offset);
+static struct device_attribute sriov_stride_attr = __ATTR_RO(sriov_stride);
+static struct device_attribute sriov_vf_device_attr = __ATTR_RO(sriov_vf_device);
 static struct device_attribute sriov_drivers_autoprobe_attr =
                __ATTR(sriov_drivers_autoprobe, (S_IRUGO|S_IWUSR|S_IWGRP),
                       sriov_drivers_autoprobe_show, sriov_drivers_autoprobe_store);
@@ -1748,6 +1778,9 @@ static const struct attribute_group pci_dev_hp_attr_group = {
 static struct attribute *sriov_dev_attrs[] = {
        &sriov_totalvfs_attr.attr,
        &sriov_numvfs_attr.attr,
+       &sriov_offset_attr.attr,
+       &sriov_stride_attr.attr,
+       &sriov_vf_device_attr.attr,
        &sriov_drivers_autoprobe_attr.attr,
        NULL,
 };