[v3] bus/pci: nvme on Windows requires class id and bus

Message ID 20210128170435.4304-1-nick.connolly@mayadata.io (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series [v3] bus/pci: nvme on Windows requires class id and bus |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-testing fail Testing issues

Commit Message

Nick Connolly Jan. 28, 2021, 5:04 p.m. UTC
  Attaching to an NVMe disk on Windows using SPDK requires the
PCI class ID and device.bus fields. Decode the class ID from the PCI
device info strings if it is present and set device.bus.

Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
---
v3:
* Put version history at top - v2 mistakenly had it after the diffs

v2:
* If only a 4-digit class ID is available, convert it to 6-digit format

 drivers/bus/pci/windows/pci.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
  

Comments

Tal Shnaiderman Jan. 31, 2021, 3:56 p.m. UTC | #1
> Subject: [PATCH v3] bus/pci: nvme on Windows requires class id and bus
> 
> External email: Use caution opening links or attachments
> 
> 
> Attaching to an NVMe disk on Windows using SPDK requires the PCI class ID
> and device.bus fields. Decode the class ID from the PCI device info strings if it
> is present and set device.bus.
> 
> Signed-off-by: Nick Connolly <nick.connolly@mayadata.io>
> ---
> v3:
> * Put version history at top - v2 mistakenly had it after the diffs
> 
> v2:
> * If only a 4-digit class ID is available, convert it to 6-digit format
> 
>  drivers/bus/pci/windows/pci.c | 15 ++++++++++++++-
>  1 file changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c
> index f66258452..d380fc1ae 100644
> --- a/drivers/bus/pci/windows/pci.c
> +++ b/drivers/bus/pci/windows/pci.c
> @@ -280,17 +280,29 @@ parse_pci_hardware_id(const char *buf, struct
> rte_pci_id *pci_id)  {
>         int ids = 0;
>         uint16_t vendor_id, device_id;
> -       uint32_t subvendor_id = 0;
> +       uint32_t subvendor_id = 0, class_id = 0;
> +       const char *cp;
> 
>         ids = sscanf_s(buf, "PCI\\VEN_%" PRIx16 "&DEV_%" PRIx16
> "&SUBSYS_%"
>                 PRIx32, &vendor_id, &device_id, &subvendor_id);
>         if (ids != 3)
>                 return -1;
> 
> +       /* Try and find PCI class ID */
> +       for (cp = buf; !(cp[0] == 0 && cp[1] == 0); cp++)
> +               if (*cp == '&' && sscanf_s(cp,
> +                               "&CC_%" PRIx32, &class_id) == 1) {
> +                       /* Convert 4-digit class IDs to 6-digit format */
> +                       if (strspn(cp + 4, "0123456789abcdefABCDEF") == 4)

Maybe we can move this format string to a define in the header, something like RTE_PCI_DRV_CLASSID_FMT?

> +                               class_id <<= 8;
> +                       break;
> +               }
> +
>         pci_id->vendor_id = vendor_id;
>         pci_id->device_id = device_id;
>         pci_id->subsystem_device_id = subvendor_id >> 16;
>         pci_id->subsystem_vendor_id = subvendor_id & 0xffff;
> +       pci_id->class_id = class_id;
>         return 0;
>  }
> 
> @@ -339,6 +351,7 @@ pci_scan_one(HDEVINFO dev_info,
> PSP_DEVINFO_DATA device_info_data)
>         if (ret != 0)
>                 goto end;
> 
> +       dev->device.bus = &rte_pci_bus.bus;
>         dev->addr = addr;
>         dev->id = pci_id;
>         dev->max_vfs = 0; /* TODO: get max_vfs */
> --
> 2.25.1
  
Nick Connolly Feb. 2, 2021, 1:07 p.m. UTC | #2
Hi Tal,

>> +                       /* Convert 4-digit class IDs to 6-digit format */
>> +                       if (strspn(cp + 4, "0123456789abcdefABCDEF") == 4)
> Maybe we can move this format string to a define in the header, something like RTE_PCI_DRV_CLASSID_FMT?
>

I'll send out a v4 with a definition at the top of pci.c

Regards,
Nick
  

Patch

diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c
index f66258452..d380fc1ae 100644
--- a/drivers/bus/pci/windows/pci.c
+++ b/drivers/bus/pci/windows/pci.c
@@ -280,17 +280,29 @@  parse_pci_hardware_id(const char *buf, struct rte_pci_id *pci_id)
 {
 	int ids = 0;
 	uint16_t vendor_id, device_id;
-	uint32_t subvendor_id = 0;
+	uint32_t subvendor_id = 0, class_id = 0;
+	const char *cp;
 
 	ids = sscanf_s(buf, "PCI\\VEN_%" PRIx16 "&DEV_%" PRIx16 "&SUBSYS_%"
 		PRIx32, &vendor_id, &device_id, &subvendor_id);
 	if (ids != 3)
 		return -1;
 
+	/* Try and find PCI class ID */
+	for (cp = buf; !(cp[0] == 0 && cp[1] == 0); cp++)
+		if (*cp == '&' && sscanf_s(cp,
+				"&CC_%" PRIx32, &class_id) == 1) {
+			/* Convert 4-digit class IDs to 6-digit format */
+			if (strspn(cp + 4, "0123456789abcdefABCDEF") == 4)
+				class_id <<= 8;
+			break;
+		}
+
 	pci_id->vendor_id = vendor_id;
 	pci_id->device_id = device_id;
 	pci_id->subsystem_device_id = subvendor_id >> 16;
 	pci_id->subsystem_vendor_id = subvendor_id & 0xffff;
+	pci_id->class_id = class_id;
 	return 0;
 }
 
@@ -339,6 +351,7 @@  pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data)
 	if (ret != 0)
 		goto end;
 
+	dev->device.bus = &rte_pci_bus.bus;
 	dev->addr = addr;
 	dev->id = pci_id;
 	dev->max_vfs = 0; /* TODO: get max_vfs */