[PATCH v8 1/1] app/testpmd: canonicalize short PCI name format
Shani Peretz
shperetz at nvidia.com
Tue Jul 8 10:37:40 CEST 2025
when providing short format PCI device names in devargs
(e.g. "08:00:0") it is converted and stored as long format.
however when attach_port is called from testpmd, the user might
provide a short format, which will be passed to find_device with
a comparison function that simply compare stings, which will
cause find_device not to find any device.
This fix canonicalize the user provided string before it is being
passed to find_device.
Signed-off-by: Shani Peretz <shperetz at nvidia.com>
---
app/test-pmd/testpmd.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index bb88555328..f8d67f2c64 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -47,6 +47,7 @@
#include <rte_ethdev.h>
#include <rte_dev.h>
#include <rte_string_fns.h>
+#include <rte_pci.h>
#ifdef RTE_NET_IXGBE
#include <rte_pmd_ixgbe.h>
#endif
@@ -3407,12 +3408,35 @@ reset_port(portid_t pid)
printf("Done\n");
}
+static char *
+convert_pci_address_format(const char *identifier, char *pci_buffer, size_t buf_size)
+{
+ struct rte_devargs da;
+ struct rte_pci_addr pci_addr;
+
+ if (rte_devargs_parse(&da, identifier) != 0)
+ return NULL;
+
+ if (da.bus == NULL)
+ return NULL;
+
+ if (strcmp(rte_bus_name(da.bus), "pci") != 0)
+ return NULL;
+
+ if (rte_pci_addr_parse(da.name, &pci_addr) != 0)
+ return NULL;
+
+ rte_pci_device_name(&pci_addr, pci_buffer, buf_size);
+ return pci_buffer;
+}
+
void
attach_port(char *identifier)
{
portid_t pi;
struct rte_dev_iterator iterator;
-
+ char *long_identifier;
+ char long_format[PCI_PRI_STR_SIZE];
printf("Attaching a new port...\n");
if (identifier == NULL) {
@@ -3420,6 +3444,11 @@ attach_port(char *identifier)
return;
}
+ /* For PCI device convert to canonical format */
+ long_identifier = convert_pci_address_format(identifier, long_format, sizeof(long_format));
+ if (long_identifier != NULL)
+ identifier = long_identifier;
+
if (rte_dev_probe(identifier) < 0) {
TESTPMD_LOG(ERR, "Failed to attach port %s\n", identifier);
return;
--
2.34.1
More information about the dev
mailing list