[1/2] pci: Cache the VF device ID in the SR-IOV structure

Message ID 1503927530-26076-1-git-send-email-sironi@amazon.de
State Accepted
Headers show
Series
  • [1/2] pci: Cache the VF device ID in the SR-IOV structure
Related show

Commit Message

Filippo Sironi Aug. 28, 2017, 1:38 p.m.
... and use it instead of reading it over and over from the PF config
space capability.

Signed-off-by: Filippo Sironi <sironi@amazon.de>
Cc: linux-pci@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/pci/iov.c | 5 +++--
 drivers/pci/pci.h | 1 +
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Bjorn Helgaas Oct. 3, 2017, 7:33 p.m. | #1
On Mon, Aug 28, 2017 at 03:38:49PM +0200, Filippo Sironi wrote:
> ... and use it instead of reading it over and over from the PF config
> space capability.
> 
> Signed-off-by: Filippo Sironi <sironi@amazon.de>
> Cc: linux-pci@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org

Applied to pci/virtualization for v4.15.

I renamed vf_did to vf_device for consistency with other existing fields.

> ---
>  drivers/pci/iov.c | 5 +++--
>  drivers/pci/pci.h | 1 +
>  2 files changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
> index 120485d6f352..e8f7eafaba6a 100644
> --- a/drivers/pci/iov.c
> +++ b/drivers/pci/iov.c
> @@ -134,7 +134,7 @@ int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset)
>  
>  	virtfn->devfn = pci_iov_virtfn_devfn(dev, id);
>  	virtfn->vendor = dev->vendor;
> -	pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device);
> +	virtfn->device = iov->vf_did;
>  	rc = pci_setup_device(virtfn);
>  	if (rc)
>  		goto failed0;
> @@ -448,6 +448,7 @@ static int sriov_init(struct pci_dev *dev, int pos)
>  	iov->nres = nres;
>  	iov->ctrl = ctrl;
>  	iov->total_VFs = total;
> +	pci_read_config_word(dev, pos + PCI_SRIOV_VF_DID, &iov->vf_did);
>  	iov->pgsz = pgsz;
>  	iov->self = dev;
>  	iov->drivers_autoprobe = true;
> @@ -723,7 +724,7 @@ int pci_vfs_assigned(struct pci_dev *dev)
>  	 * determine the device ID for the VFs, the vendor ID will be the
>  	 * same as the PF so there is no need to check for that one
>  	 */
> -	pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_VF_DID, &dev_id);
> +	dev_id = dev->sriov->vf_did;
>  
>  	/* loop through all the VFs to see if we own any that are assigned */
>  	vfdev = pci_get_device(dev->vendor, dev_id, NULL);
> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
> index 22e061738c6f..a7270e11e1ef 100644
> --- a/drivers/pci/pci.h
> +++ b/drivers/pci/pci.h
> @@ -262,6 +262,7 @@ struct pci_sriov {
>  	u16 num_VFs;		/* number of VFs available */
>  	u16 offset;		/* first VF Routing ID offset */
>  	u16 stride;		/* following VF stride */
> +	u16 vf_did;		/* VF device ID */
>  	u32 pgsz;		/* page size for BAR alignment */
>  	u8 link;		/* Function Dependency Link */
>  	u8 max_VF_buses;	/* max buses consumed by VFs */
> -- 
> 2.7.4
>
Filippo Sironi Oct. 8, 2017, 11:09 p.m. | #2
Testing done:

$ ls -l /sys/bus/pci/devices/0000\:03\:00.0/
total 0
-rw-r--r-- 1 root root    4096 Oct  9 00:48 broken_parity_status
-r--r--r-- 1 root root    4096 Oct  9 00:48 class
-rw-r--r-- 1 root root    4096 Oct  9 00:46 config
-r--r--r-- 1 root root    4096 Oct  9 00:48 consistent_dma_mask_bits
-r--r--r-- 1 root root    4096 Oct  9 00:48 current_link_speed
-r--r--r-- 1 root root    4096 Oct  9 00:48 current_link_width
-rw-r--r-- 1 root root    4096 Oct  9 00:48 d3cold_allowed
-r--r--r-- 1 root root    4096 Oct  9 00:46 device
-r--r--r-- 1 root root    4096 Oct  9 00:48 dma_mask_bits
lrwxrwxrwx 1 root root       0 Oct  9 00:46 driver -> ../../../../bus/pci/drivers/igb
-rw-r--r-- 1 root root    4096 Oct  9 00:48 driver_override
-rw-r--r-- 1 root root    4096 Oct  9 00:48 enable
lrwxrwxrwx 1 root root       0 Oct  9 00:48 firmware_node -> ../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:4b/device:4c
-r--r--r-- 1 root root    4096 Oct  9 00:46 irq
-r--r--r-- 1 root root    4096 Oct  9 00:48 local_cpulist
-r--r--r-- 1 root root    4096 Oct  9 00:48 local_cpus
-r--r--r-- 1 root root    4096 Oct  9 00:48 max_link_speed
-r--r--r-- 1 root root    4096 Oct  9 00:48 max_link_width
-r--r--r-- 1 root root    4096 Oct  9 00:48 modalias
-rw-r--r-- 1 root root    4096 Oct  9 00:48 msi_bus
drwxr-xr-x 2 root root       0 Oct  9 00:48 msi_irqs
drwxr-xr-x 3 root root       0 Oct  9 00:46 net
-rw-r--r-- 1 root root    4096 Oct  9 00:48 numa_node
drwxr-xr-x 2 root root       0 Oct  9 00:48 power
drwxr-xr-x 3 root root       0 Oct  9 00:46 ptp
--w--w---- 1 root root    4096 Oct  9 00:48 remove
--w--w---- 1 root root    4096 Oct  9 00:48 rescan
--w------- 1 root root    4096 Oct  9 00:48 reset
-r--r--r-- 1 root root    4096 Oct  9 00:46 resource
-rw------- 1 root root  131072 Oct  9 00:48 resource0
-rw------- 1 root root 4194304 Oct  9 00:48 resource1
-rw------- 1 root root      32 Oct  9 00:48 resource2
-rw------- 1 root root   16384 Oct  9 00:48 resource3
-r--r--r-- 1 root root    4096 Oct  9 00:48 revision
-rw-rw-r-- 1 root root    4096 Oct  9 00:48 sriov_drivers_autoprobe
-rw-rw-r-- 1 root root    4096 Oct  9 00:48 sriov_numvfs
-r--r--r-- 1 root root    4096 Oct  9 00:48 sriov_offset
-r--r--r-- 1 root root    4096 Oct  9 00:48 sriov_stride
-r--r--r-- 1 root root    4096 Oct  9 00:48 sriov_totalvfs
-r--r--r-- 1 root root    4096 Oct  9 00:48 sriov_vf_device
lrwxrwxrwx 1 root root       0 Oct  9 00:46 subsystem -> ../../../../bus/pci
-r--r--r-- 1 root root    4096 Oct  9 00:48 subsystem_device
-r--r--r-- 1 root root    4096 Oct  9 00:48 subsystem_vendor
-rw-r--r-- 1 root root    4096 Oct  9 00:46 uevent
-r--r--r-- 1 root root    4096 Oct  9 00:46 vendor
$ cat /sys/bus/pci/devices/0000\:03\:00.0/sriov_offset
128
$ cat /sys/bus/pci/devices/0000\:03\:00.0/sriov_stride
2
$ cat /sys/bus/pci/devices/0000\:03\:00.0/sriov_vf_device 
10ca

Filippo Sironi (1):
  pci: Expose offset, stride, and VF device ID via sysfs

 drivers/pci/pci-sysfs.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Patch

diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 120485d6f352..e8f7eafaba6a 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -134,7 +134,7 @@  int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset)
 
 	virtfn->devfn = pci_iov_virtfn_devfn(dev, id);
 	virtfn->vendor = dev->vendor;
-	pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device);
+	virtfn->device = iov->vf_did;
 	rc = pci_setup_device(virtfn);
 	if (rc)
 		goto failed0;
@@ -448,6 +448,7 @@  static int sriov_init(struct pci_dev *dev, int pos)
 	iov->nres = nres;
 	iov->ctrl = ctrl;
 	iov->total_VFs = total;
+	pci_read_config_word(dev, pos + PCI_SRIOV_VF_DID, &iov->vf_did);
 	iov->pgsz = pgsz;
 	iov->self = dev;
 	iov->drivers_autoprobe = true;
@@ -723,7 +724,7 @@  int pci_vfs_assigned(struct pci_dev *dev)
 	 * determine the device ID for the VFs, the vendor ID will be the
 	 * same as the PF so there is no need to check for that one
 	 */
-	pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_VF_DID, &dev_id);
+	dev_id = dev->sriov->vf_did;
 
 	/* loop through all the VFs to see if we own any that are assigned */
 	vfdev = pci_get_device(dev->vendor, dev_id, NULL);
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 22e061738c6f..a7270e11e1ef 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -262,6 +262,7 @@  struct pci_sriov {
 	u16 num_VFs;		/* number of VFs available */
 	u16 offset;		/* first VF Routing ID offset */
 	u16 stride;		/* following VF stride */
+	u16 vf_did;		/* VF device ID */
 	u32 pgsz;		/* page size for BAR alignment */
 	u8 link;		/* Function Dependency Link */
 	u8 max_VF_buses;	/* max buses consumed by VFs */