[PATCH v9 1/1] app/testpmd: canonicalize short PCI name format
Shani Peretz
shperetz at nvidia.com
Sun Jul 13 08:34:17 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 strings, 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/meson.build | 2 +-
app/test-pmd/testpmd.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build
index 000548c261..83163a5406 100644
--- a/app/test-pmd/meson.build
+++ b/app/test-pmd/meson.build
@@ -34,7 +34,7 @@ if dpdk_conf.has('RTE_HAS_JANSSON')
ext_deps += jansson_dep
endif
-deps += ['ethdev', 'cmdline']
+deps += ['ethdev', 'cmdline', 'pci']
if dpdk_conf.has('RTE_CRYPTO_SCHEDULER')
deps += 'crypto_scheduler'
endif
diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index bb88555328..569b9e3113 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,11 +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");
@@ -3420,6 +3445,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