From: Shani Peretz <shperetz@nvidia.com>
To: <dev@dpdk.org>
Cc: <stephen@networkplumber.org>, <thomas@monjalon.net>,
Shani Peretz <shperetz@nvidia.com>,
Aman Singh <aman.deep.singh@intel.com>
Subject: [PATCH v8 1/1] app/testpmd: canonicalize short PCI name format
Date: Tue, 8 Jul 2025 11:37:40 +0300 [thread overview]
Message-ID: <20250708083740.128610-2-shperetz@nvidia.com> (raw)
In-Reply-To: <20250708083740.128610-1-shperetz@nvidia.com>
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@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
next prev parent reply other threads:[~2025-07-08 8:38 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-01 20:01 [PATCH] eal/common: fix inconsistent representation of PCI numbers Shani Peretz
2024-07-01 22:00 ` Stephen Hemminger
2024-07-08 16:51 ` [PATCH v3] " Shani Peretz
2024-07-12 13:49 ` David Marchand
2024-07-12 17:55 ` Thomas Monjalon
2025-01-29 8:54 ` [PATCH v4] bus: " Shani Peretz
2025-01-29 9:45 ` Bruce Richardson
2025-01-29 16:25 ` Stephen Hemminger
2025-02-05 16:36 ` Shani Peretz
2025-02-05 16:42 ` Stephen Hemminger
2025-02-05 17:37 ` Shani Peretz
2025-02-05 18:46 ` Stephen Hemminger
2025-02-05 20:16 ` Shani Peretz
2025-02-06 0:40 ` Stephen Hemminger
2025-01-29 17:17 ` Stephen Hemminger
2025-01-29 18:06 ` Bruce Richardson
2025-02-05 1:55 ` fengchengwen
2025-02-06 0:08 ` [PATCH v5 0/4] fix comparison between devices Shani Peretz
2025-02-06 0:08 ` [PATCH v5 1/4] bus/pci: fix registration of PCI device Shani Peretz
2025-02-06 11:22 ` Thomas Monjalon
2025-02-06 0:08 ` [PATCH v5 2/4] lib: fix comparison between devices Shani Peretz
2025-02-06 7:55 ` Hemant Agrawal
2025-02-06 11:25 ` Thomas Monjalon
2025-02-10 1:18 ` Xu, Rosen
2025-02-11 17:48 ` Stephen Hemminger
2025-02-11 17:54 ` Bruce Richardson
2025-02-11 18:04 ` Stephen Hemminger
2025-02-19 13:26 ` Shani Peretz
2025-02-06 0:08 ` [PATCH v5 3/4] app/test: add tests to find devices Shani Peretz
2025-02-06 1:03 ` Stephen Hemminger
2025-02-06 0:08 ` [PATCH v5 4/4] lib: change find device and cmp dev name functions Shani Peretz
2025-02-06 10:54 ` [PATCH v6 1/4] bus/pci: fix registration of PCI device Shani Peretz
2025-02-06 10:54 ` [PATCH v6 2/4] lib: fix comparison between devices Shani Peretz
2025-02-06 10:54 ` [PATCH v6 3/4] app/test: add tests to find devices Shani Peretz
2025-02-06 10:54 ` [PATCH v6 4/4] lib: change find device and cmp dev name functions Shani Peretz
2025-02-11 17:04 ` [PATCH v6 1/4] bus/pci: fix registration of PCI device Bruce Richardson
2025-02-12 0:39 ` Stephen Hemminger
2025-02-12 16:38 ` [PATCH v7 " Shani Peretz
2025-02-12 16:38 ` [PATCH v7 2/4] lib: fix comparison between devices Shani Peretz
2025-02-19 16:50 ` Stephen Hemminger
2025-02-20 18:33 ` Stephen Hemminger
2025-03-06 16:26 ` Shani Peretz
2025-03-17 14:11 ` Stephen Hemminger
2025-04-30 11:12 ` Shani Peretz
2025-04-30 15:59 ` Stephen Hemminger
2025-04-30 17:17 ` Shani Peretz
2025-07-08 8:37 ` [PATCH v8 0/1] fix inconsistent representation of PCI device name Shani Peretz
2025-07-08 8:37 ` Shani Peretz [this message]
2025-02-12 16:38 ` [PATCH v7 3/4] app/test: add tests to find devices Shani Peretz
2025-02-19 16:47 ` Stephen Hemminger
2025-04-02 14:22 ` Stephen Hemminger
2025-02-12 16:38 ` [PATCH v7 4/4] lib: change find device and cmp dev name functions Shani Peretz
2025-02-19 16:44 ` [PATCH v7 1/4] bus/pci: fix registration of PCI device Stephen Hemminger
2025-02-19 16:48 ` Stephen Hemminger
2025-02-24 20:38 ` Stephen Hemminger
2024-10-04 22:21 ` [PATCH] eal/common: fix inconsistent representation of PCI numbers Stephen Hemminger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250708083740.128610-2-shperetz@nvidia.com \
--to=shperetz@nvidia.com \
--cc=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
--cc=stephen@networkplumber.org \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).