[dpdk-dev,v2] pci: pad vendor and device ID to 4 digits

Message ID 20170623182032.28734-1-daniel.verkamp@intel.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Daniel Verkamp June 23, 2017, 6:20 p.m. UTC
  Some PCI vendor and device IDs have leading zeros.

Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
---

v2: added #define for format string, use %.4 style and PRIx16

 lib/librte_eal/common/eal_common_pci.c  | 8 ++++----
 lib/librte_eal/common/include/rte_pci.h | 3 +++
 2 files changed, 7 insertions(+), 4 deletions(-)
  

Comments

Thomas Monjalon July 5, 2017, 1:16 p.m. UTC | #1
23/06/2017 20:20, Daniel Verkamp:
> Some PCI vendor and device IDs have leading zeros.
> 
> Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
> ---
> --- a/lib/librte_eal/common/include/rte_pci.h
> +++ b/lib/librte_eal/common/include/rte_pci.h
> @@ -68,6 +68,9 @@ const char *pci_get_sysfs_path(void);
>  /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */
>  #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
>  
> +/** Formatting string for PCI vendor and device ID: Ex: 1234:5678 */
> +#define PCI_ID_PRI_FMT "%.4" PRIx16 ":%.4" PRIx16

Why not printing the whole PCI infos with domain and function?

Note: public macros should be prefixed with RTE_
  

Patch

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 78b097e..7924509 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -203,8 +203,8 @@  rte_pci_probe_one_driver(struct rte_pci_driver *dr,
 		return 1;
 	}
 
-	RTE_LOG(INFO, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-		dev->id.device_id, dr->driver.name);
+	RTE_LOG(INFO, EAL, "  probe driver: " PCI_ID_PRI_FMT " %s\n",
+		dev->id.vendor_id, dev->id.device_id, dr->driver.name);
 
 	if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
 		/* map resources for devices that use igb_uio */
@@ -253,8 +253,8 @@  rte_pci_detach_dev(struct rte_pci_device *dev)
 			loc->domain, loc->bus, loc->devid,
 			loc->function, dev->device.numa_node);
 
-	RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
-			dev->id.device_id, dr->driver.name);
+	RTE_LOG(DEBUG, EAL, "  remove driver: " PCI_ID_PRI_FMT " %s\n",
+			dev->id.vendor_id, dev->id.device_id, dr->driver.name);
 
 	if (dr->remove && (dr->remove(dev) < 0))
 		return -1;	/* negative value is an error */
diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h
index 0284a62..66edccb 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -68,6 +68,9 @@  const char *pci_get_sysfs_path(void);
 /** Short formatting string, without domain, for PCI device: Ex: 00:01.0 */
 #define PCI_SHORT_PRI_FMT "%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8
 
+/** Formatting string for PCI vendor and device ID: Ex: 1234:5678 */
+#define PCI_ID_PRI_FMT "%.4" PRIx16 ":%.4" PRIx16
+
 /** Nb. of values in PCI device identifier format string. */
 #define PCI_FMT_NVAL 4