Skip to contentSkip to conversation

vfio: selftests: Support DMR and GNR-D DSA devices

PATCH Superseded Yi Lai 3 participants 3 messages Mar 19 – Mar 20

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yi Lai

author
#0 lore raw

PATCH 1/1 vfio: selftests: Support DMR and GNR-D DSA devices

Currently, the VFIO DSA driver test only supports the SPR DSA device ID. Attempting to run the test on newer platforms like DMR or GNR-D results in a "No driver found" error, causing the test to be skipped.

Refactor the 'dsa_probe' function to use a switch statement for checking device IDs. This improves maintainability and makes it easier to add new device IDs in the future.

Add the following DSA device IDs to the supported list:
PCI_DEVICE_ID_INTEL_DSA_DMR (0x1212) PCI_DEVICE_ID_INTEL_DSA_GNRD (0x11fb)

---
 .../selftests/vfio/lib/drivers/dsa/dsa.c        | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +15 -2
index c75045bcab79..0cbc7606d904 100644
@@ -65,10 +65,23 @@ static bool dsa_int_handle_request_required(struct vfio_pci_device *device)
 
 static int dsa_probe(struct vfio_pci_device *device)
 {
-	if (!vfio_pci_device_match(device, PCI_VENDOR_ID_INTEL,
-				   PCI_DEVICE_ID_INTEL_DSA_SPR0))
+	u16 vendor, device_id;
+
+	vendor = vfio_pci_config_readw(device, PCI_VENDOR_ID);
+	device_id = vfio_pci_config_readw(device, PCI_DEVICE_ID);
+
+	if (vendor != PCI_VENDOR_ID_INTEL)
 		return -EINVAL;
 
+	switch (device_id) {
+	case PCI_DEVICE_ID_INTEL_DSA_SPR0:
+	case PCI_DEVICE_ID_INTEL_DSA_DMR:
+	case PCI_DEVICE_ID_INTEL_DSA_GNRD:
+		break;
+	default:
+		return -EINVAL;
+	}
+
 	if (dsa_int_handle_request_required(device)) {
 		dev_err(device, "Device requires requesting interrupt handles\n");
 		return -EINVAL;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 5 lines · Yi Lai

Currently, the VFIO DSA driver test only supports the SPR DSA device ID. Attempting to run the test on newer platforms like DMR or GNR-D results in a "No driver found" error, causing the test to be skipped.

Refactor the 'dsa_probe' function to use a switch statement for

nit: s/Refactor the 'dsa_probe' function/Refactor dsa_probe()/

If you append () to the end of function names in commit messages and comments it makes it clear you are referring to a function.

Quoted 8 lines

checking device IDs. This improves maintainability and makes it easier to add new device IDs in the future.

Add the following DSA device IDs to the supported list:
PCI_DEVICE_ID_INTEL_DSA_DMR (0x1212) PCI_DEVICE_ID_INTEL_DSA_GNRD (0x11fb)

Thanks for the patch. Looks good aside from some small nits.

Were you able to test that vfio_pci_driver_test passes with both of the new devices?

Quoted 11 lines
---
 .../selftests/vfio/lib/drivers/dsa/dsa.c        | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +0 -0
index c75045bcab79..0cbc7606d904 100644
@@ -65,10 +65,23 @@ static bool dsa_int_handle_request_required(struct vfio_pci_device *device)
 
 static int dsa_probe(struct vfio_pci_device *device)

tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c static bool dsa_int_handle_request_required(struct vfio_pci_device *device) · line 74

Quoted 10 lines
tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +6 -2
 {
-	if (!vfio_pci_device_match(device, PCI_VENDOR_ID_INTEL,
-				   PCI_DEVICE_ID_INTEL_DSA_SPR0))
+	u16 vendor, device_id;
+
+	vendor = vfio_pci_config_readw(device, PCI_VENDOR_ID);
+	device_id = vfio_pci_config_readw(device, PCI_DEVICE_ID);
+
+	if (vendor != PCI_VENDOR_ID_INTEL)
 		return -EINVAL;

nit: s/vendor/vendor_id/ to be consistent with device_id and vfio_pci_device_match().

Also you can initialized these variables when they are declared to simplify the code a bit. e.g.

tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +3 -5
index 0cbc7606d904..19d9630b24c2 100644
@@ -65,12 +65,10 @@ static bool dsa_int_handle_request_required(struct vfio_pci_device *device)
 
 static int dsa_probe(struct vfio_pci_device *device)
 {
-       u16 vendor, device_id;
+       const u16 vendor_id = vfio_pci_config_readw(device, PCI_VENDOR_ID);
+       const u16 device_id = vfio_pci_config_readw(device, PCI_DEVICE_ID);
 
-       vendor = vfio_pci_config_readw(device, PCI_VENDOR_ID);
-       device_id = vfio_pci_config_readw(device, PCI_DEVICE_ID);
-
-       if (vendor != PCI_VENDOR_ID_INTEL)
+       if (vendor_id != PCI_VENDOR_ID_INTEL)
                return -EINVAL;
 
        switch (device_id) {
Quoted 16 lines
tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +9 -0
+	switch (device_id) {
+	case PCI_DEVICE_ID_INTEL_DSA_SPR0:
+	case PCI_DEVICE_ID_INTEL_DSA_DMR:
+	case PCI_DEVICE_ID_INTEL_DSA_GNRD:
+		break;
+	default:
+		return -EINVAL;
+	}
+
 	if (dsa_int_handle_request_required(device)) {
 		dev_err(device, "Device requires requesting interrupt handles\n");
 		return -EINVAL;
Signature · 1 line
2.43.0
#2 lore raw
Quoted 15 lines · David Matlack
Quoted 5 lines · Yi Lai

Currently, the VFIO DSA driver test only supports the SPR DSA device ID. Attempting to run the test on newer platforms like DMR or GNR-D results in a "No driver found" error, causing the test to be skipped.

Refactor the 'dsa_probe' function to use a switch statement for

nit: s/Refactor the 'dsa_probe' function/Refactor dsa_probe()/

If you append () to the end of function names in commit messages and comments it makes it clear you are referring to a function.

Quoted 3 lines

checking device IDs. This improves maintainability and makes it easier to add new device IDs in the future.

Quoted 7 lines
Quoted 5 lines

Add the following DSA device IDs to the supported list:
PCI_DEVICE_ID_INTEL_DSA_DMR (0x1212) PCI_DEVICE_ID_INTEL_DSA_GNRD (0x11fb)

Thanks for the patch. Looks good aside from some small nits.

Thanks for reviewing the patch. I will send v2 adopting your comments.

Quoted 3 lines

Were you able to test that vfio_pci_driver_test passes with both of the new devices?

I tested vfio_pci_driver_test with DMR DSA device. All tests pass.

Quoted 66 lines
Quoted 12 lines
---
 .../selftests/vfio/lib/drivers/dsa/dsa.c        | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +0 -0
index c75045bcab79..0cbc7606d904 100644
@@ -65,10 +65,23 @@ static bool dsa_int_handle_request_required(struct vfio_pci_device *device)
 
 static int dsa_probe(struct vfio_pci_device *device)

tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c static bool dsa_int_handle_request_required(struct vfio_pci_device *device) · line 74

Quoted 10 lines
tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +6 -2
 {
-	if (!vfio_pci_device_match(device, PCI_VENDOR_ID_INTEL,
-				   PCI_DEVICE_ID_INTEL_DSA_SPR0))
+	u16 vendor, device_id;
+
+	vendor = vfio_pci_config_readw(device, PCI_VENDOR_ID);
+	device_id = vfio_pci_config_readw(device, PCI_DEVICE_ID);
+
+	if (vendor != PCI_VENDOR_ID_INTEL)
 		return -EINVAL;

nit: s/vendor/vendor_id/ to be consistent with device_id and vfio_pci_device_match().

Also you can initialized these variables when they are declared to simplify the code a bit. e.g.

tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +3 -5
index 0cbc7606d904..19d9630b24c2 100644
@@ -65,12 +65,10 @@ static bool dsa_int_handle_request_required(struct vfio_pci_device *device)
 
 static int dsa_probe(struct vfio_pci_device *device)
 {
-       u16 vendor, device_id;
+       const u16 vendor_id = vfio_pci_config_readw(device, PCI_VENDOR_ID);
+       const u16 device_id = vfio_pci_config_readw(device, PCI_DEVICE_ID);
 
-       vendor = vfio_pci_config_readw(device, PCI_VENDOR_ID);
-       device_id = vfio_pci_config_readw(device, PCI_DEVICE_ID);
-
-       if (vendor != PCI_VENDOR_ID_INTEL)
+       if (vendor_id != PCI_VENDOR_ID_INTEL)
                return -EINVAL;
 
        switch (device_id) {
Quoted 17 lines
tools/testing/selftests/vfio/lib/drivers/dsa/dsa.c +9 -0
+	switch (device_id) {
+	case PCI_DEVICE_ID_INTEL_DSA_SPR0:
+	case PCI_DEVICE_ID_INTEL_DSA_DMR:
+	case PCI_DEVICE_ID_INTEL_DSA_GNRD:
+		break;
+	default:
+		return -EINVAL;
+	}
+
 	if (dsa_int_handle_request_required(device)) {
 		dev_err(device, "Device requires requesting interrupt handles\n");
 		return -EINVAL;
Signature · 1 line
2.43.0