From: Xueming Li <xuemingl@nvidia.com>
To: Thomas Monjalon <thomas@monjalon.net>, Gaetan Rivet <gaetanr@nvidia.com>
Cc: dev@dpdk.org, xuemingl@nvidia.com, Asaf Penso <asafp@nvidia.com>
Subject: [dpdk-dev] [PATCH v5 4/5] bus: add device arguments name parsing API
Date: Tue, 13 Apr 2021 03:14:11 +0000 [thread overview]
Message-ID: <1618283653-16510-5-git-send-email-xuemingl@nvidia.com> (raw)
In-Reply-To: <1618283653-16510-1-git-send-email-xuemingl@nvidia.com>
In-Reply-To: <1608304614-13908-2-git-send-email-xuemingl@nvidia.com>
For device probe and iterator, devargs name was key information,
parsed by rte_devargs_parse. In legacy parser, devargs name was
extracted after bus name:
bus:name,kv_arguments,,,
Example:
pci:83:00.0,arguments,...
vdev:pcap0,...
To be compatible with legacy parser, this patch introduces new
bus driver API devargs_parse to parse devargs and update devargs name.
If devargs_parse not implemented by bus driver, the new syntax parser
rte_devargs_layers_parse default will resolve devargs name from bus's
"name" argument.
Different bus driver might choose different keys from arguments with
unified format. The PCI bus implementation fills the devargs name with
the "addr" argument, example:
-a bus=pci,addr=83:00.0/class=eth/driver=mlx5,...
name: 0000:03:00.0
-a bus=vdev,name=pcap0/class=eth/driver=pcap,...
name:pcap0
Signed-off-by: Xueming Li <xuemingl@nvidia.com>
Reviewed-by: Gaetan Rivet <grive@u256.net>
---
drivers/bus/pci/pci_common.c | 1 +
drivers/bus/pci/pci_params.c | 47 ++++++++++++++++++++++
drivers/bus/pci/private.h | 14 +++++++
lib/librte_eal/common/eal_common_devargs.c | 31 ++++++++++++++
lib/librte_eal/include/rte_bus.h | 17 ++++++++
5 files changed, 110 insertions(+)
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index ee7f966358..30630809bb 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -760,6 +760,7 @@ struct rte_pci_bus rte_pci_bus = {
.dev_iterate = rte_pci_dev_iterate,
.hot_unplug_handler = pci_hot_unplug_handler,
.sigbus_handler = pci_sigbus_handler,
+ .devargs_parse = rte_pci_devargs_parse,
},
.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
diff --git a/drivers/bus/pci/pci_params.c b/drivers/bus/pci/pci_params.c
index 3192e9c967..c0c282e948 100644
--- a/drivers/bus/pci/pci_params.c
+++ b/drivers/bus/pci/pci_params.c
@@ -8,6 +8,8 @@
#include <rte_errno.h>
#include <rte_kvargs.h>
#include <rte_pci.h>
+#include <rte_devargs.h>
+#include <rte_debug.h>
#include "private.h"
@@ -76,3 +78,48 @@ rte_pci_dev_iterate(const void *start,
rte_kvargs_free(kvargs);
return dev;
}
+
+int
+rte_pci_devargs_parse(struct rte_devargs *da)
+{
+ struct rte_kvargs *kvargs;
+ const char *addr_str;
+ struct rte_pci_addr addr;
+ int ret;
+
+ if (da == NULL)
+ return 0;
+ RTE_ASSERT(da->bus_str != NULL);
+
+ kvargs = rte_kvargs_parse(da->bus_str, NULL);
+ if (kvargs == NULL) {
+ RTE_LOG(ERR, EAL, "cannot parse argument list: %s\n",
+ da->bus_str);
+ ret = -ENODEV;
+ goto out;
+ }
+
+ addr_str = rte_kvargs_get(kvargs, pci_params_keys[RTE_PCI_PARAM_ADDR]);
+ if (addr_str == NULL) {
+ RTE_LOG(ERR, EAL, "No PCI address specified using '%s=<id>' in: %s\n",
+ pci_params_keys[RTE_PCI_PARAM_ADDR], da->bus_str);
+ ret = -ENODEV;
+ goto out;
+ }
+
+ ret = rte_pci_addr_parse(addr_str, &addr);
+ if (ret != 0) {
+ RTE_LOG(ERR, EAL, "PCI address invalid: %s\n", da->bus_str);
+ ret = -EINVAL;
+ goto out;
+ }
+
+ rte_pci_device_name(&addr, da->name, sizeof(da->name));
+
+out:
+ if (kvargs != NULL)
+ rte_kvargs_free(kvargs);
+ if (ret != 0)
+ rte_errno = -ret;
+ return ret;
+}
diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index f566943f5e..8bc5140e97 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -267,4 +267,18 @@ rte_pci_dev_iterate(const void *start,
const char *str,
const struct rte_dev_iterator *it);
+/*
+ * Parse device arguments and update name.
+ *
+ * @param da
+ * device arguments to parse.
+ *
+ * @return
+ * 0 on success.
+ * -EINVAL: kvargs string is invalid and cannot be parsed.
+ * -ENODEV: no key matching a device ID is found in the kv list.
+ */
+int
+rte_pci_devargs_parse(struct rte_devargs *da);
+
#endif /* _PCI_PRIVATE_H_ */
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index e40b91ea66..2d87e63d2a 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -19,6 +19,7 @@
#include <rte_kvargs.h>
#include <rte_log.h>
#include <rte_tailq.h>
+#include <rte_string_fns.h>
#include "eal_private.h"
/** user device double-linked queue type definition */
@@ -40,6 +41,28 @@ devargs_layer_count(const char *s)
return i;
}
+/* Resolve devargs name from bus arguments. */
+static int
+devargs_bus_parse_default(struct rte_devargs *devargs,
+ struct rte_kvargs *bus_args)
+{
+ const char *name;
+
+ /* Parse devargs name from bus key-value list. */
+ name = rte_kvargs_get(bus_args, "name");
+ if (name == NULL) {
+ RTE_LOG(INFO, EAL, "devargs name not found: %s\n",
+ devargs->data);
+ return 0;
+ }
+ if (rte_strscpy(devargs->name, name, sizeof(devargs->name)) < 0) {
+ RTE_LOG(ERR, EAL, "devargs name too long: %s\n",
+ devargs->data);
+ return -E2BIG;
+ }
+ return 0;
+}
+
int
rte_devargs_layers_parse(struct rte_devargs *devargs,
const char *devstr)
@@ -118,6 +141,8 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
if (layers[i].kvlist == NULL)
continue;
kv = &layers[i].kvlist->pairs[0];
+ if (kv->key == NULL)
+ continue;
if (strcmp(kv->key, "bus") == 0) {
bus = rte_bus_find_by_name(kv->value);
if (bus == NULL) {
@@ -160,6 +185,12 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
}
}
+ /* Resolve devargs name. */
+ if (bus != NULL && bus->devargs_parse != NULL)
+ ret = bus->devargs_parse(devargs);
+ else if (layers[0].kvlist != NULL)
+ ret = devargs_bus_parse_default(devargs, layers[0].kvlist);
+
get_out:
for (i = 0; i < RTE_DIM(layers); i++) {
if (layers[i].kvlist)
diff --git a/lib/librte_eal/include/rte_bus.h b/lib/librte_eal/include/rte_bus.h
index 80b154fb98..bfa8dc0200 100644
--- a/lib/librte_eal/include/rte_bus.h
+++ b/lib/librte_eal/include/rte_bus.h
@@ -210,6 +210,22 @@ typedef int (*rte_bus_hot_unplug_handler_t)(struct rte_device *dev);
*/
typedef int (*rte_bus_sigbus_handler_t)(const void *failure_addr);
+/**
+ * Parse bus part of the device arguments.
+ *
+ * The field name of the struct rte_devargs will be set.
+ *
+ * @param da
+ * Pointer to the devargs to parse.
+ *
+ * @return
+ * 0 on successful parsing, otherwise rte_errno is set.
+ * -EINVAL: on parsing error.
+ * -ENODEV: if no key matching a device argument is specified.
+ * -E2BIG: device name is too long.
+ */
+typedef int (*rte_bus_devargs_parse_t)(struct rte_devargs *da);
+
/**
* Bus scan policies
*/
@@ -267,6 +283,7 @@ struct rte_bus {
/**< handle hot-unplug failure on the bus */
rte_bus_sigbus_handler_t sigbus_handler;
/**< handle sigbus error on the bus */
+ rte_bus_devargs_parse_t devargs_parse; /**< Parse bus devargs */
};
--
2.25.1
next prev parent reply other threads:[~2021-04-13 3:15 UTC|newest]
Thread overview: 126+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-18 15:16 [dpdk-dev] [RFC 0/9] support global syntax Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 1/9] devargs: fix data buffer storage type Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 0/7] eal: support global syntax Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 1/7] devargs: fix data buffer storage type Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 2/7] devargs: fix memory leak on parsing error Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 3/7] devargs: fix memory leak in legacy parser Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 4/7] devargs: fix buffer data memory leak Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 5/7] kvargs: add get by key function Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 6/7] devargs: support new global device syntax Xueming Li
2021-01-08 14:54 ` [dpdk-dev] [PATCH v1 7/7] bus/pci: add new global device syntax support Xueming Li
2021-01-08 15:14 ` [dpdk-dev] [PATCH v1 0/2] mlx5: support global syntax Xueming Li
2021-01-08 15:14 ` [dpdk-dev] [PATCH v1 1/2] common/mlx5: support device " Xueming Li
2021-01-08 15:15 ` [dpdk-dev] [PATCH v1 2/2] net/mlx5: support new " Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 0/9] net/mlx5: support SubFunction representor Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 1/9] common/mlx5: update representor name parsing Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 2/9] net/mlx5: support representor of sub function Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 3/9] net/mlx5: revert setting bonding representor to first PF Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 4/9] net/mlx5: refactor bonding representor probe Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 5/9] net/mlx5: support representor from multiple PFs Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 6/9] net/mlx5: save bonding member ports information Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 7/9] " Xueming Li
2021-01-18 16:17 ` Slava Ovsiienko
2021-01-18 23:05 ` Xueming(Steven) Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 8/9] net/mlx5: fix setting VF default MAC through representor Xueming Li
2021-01-18 11:29 ` [dpdk-dev] [PATCH v3 9/9] net/mlx5: improve bonding xstats Xueming Li
2021-01-18 15:16 ` [dpdk-dev] [PATCH v2 0/5] eal: enable global device syntax Xueming Li
2021-01-18 15:16 ` [dpdk-dev] [PATCH v2 1/5] devargs: fix memory leak on parsing error Xueming Li
2021-03-18 9:12 ` Thomas Monjalon
2021-01-18 15:16 ` [dpdk-dev] [PATCH v2 2/5] devargs: refactor scratch buffer storage Xueming Li
2021-03-18 9:14 ` Thomas Monjalon
2021-01-18 15:16 ` [dpdk-dev] [PATCH v2 3/5] kvargs: add get by key function Xueming Li
2021-01-18 15:16 ` [dpdk-dev] [PATCH v2 4/5] devargs: parse name from global device syntax Xueming Li
2021-01-18 15:16 ` [dpdk-dev] [PATCH v2 5/5] devargs: enable global device syntax devargs Xueming Li
2021-01-18 15:26 ` [dpdk-dev] [PATCH v2 0/2] mlx5: support global device syntax Xueming Li
2021-09-20 8:07 ` Thomas Monjalon
2021-09-23 6:47 ` Xueming(Steven) Li
2021-09-23 6:45 ` [dpdk-dev] [PATCH v3] net/mlx5: support new " Xueming Li
2021-09-29 19:37 ` Thomas Monjalon
2021-01-18 15:26 ` [dpdk-dev] [PATCH v2 1/2] common/mlx5: support device global syntax Xueming Li
2021-04-05 10:54 ` Slava Ovsiienko
2021-04-08 12:24 ` Raslan Darawsheh
2021-04-08 14:04 ` Raslan Darawsheh
2021-04-08 14:08 ` Xueming(Steven) Li
2021-04-08 14:13 ` Raslan Darawsheh
2021-04-19 9:29 ` Raslan Darawsheh
2021-04-19 10:36 ` Raslan Darawsheh
2021-01-18 15:26 ` [dpdk-dev] [PATCH v2 2/2] net/mlx5: support new global device syntax Xueming Li
2021-04-05 10:56 ` Slava Ovsiienko
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 0/8] net/mlx5: support SubFunction representor Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 1/8] common/mlx5: update representor name parsing Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 2/8] net/mlx5: support representor of sub function Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 3/8] net/mlx5: revert setting bonding representor to first PF Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 4/8] net/mlx5: refactor bonding representor probe Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 5/8] net/mlx5: support representor from multiple PFs Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 6/8] net/mlx5: save bonding member ports information Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 7/8] net/mlx5: fix setting VF default MAC through representor Xueming Li
2021-01-19 7:28 ` [dpdk-dev] [PATCH v4 8/8] net/mlx5: improve bonding xstats Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 0/9] net/mlx5: support SubFunction representor Xueming Li
2021-03-31 7:20 ` Raslan Darawsheh
2021-03-31 7:27 ` Xueming(Steven) Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 1/9] common/mlx5: sub-function representor port name parsing Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 2/9] net/mlx5: support representor of sub function Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 3/9] net/mlx5: revert setting bonding representor to first PF Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 4/9] net/mlx5: refactor bonding representor probe Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 5/9] net/mlx5: support list value of representor PF Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 6/9] net/mlx5: save bonding member ports information Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 7/9] net/mlx5: fix setting VF default MAC through representor Xueming Li
2021-03-31 7:46 ` Raslan Darawsheh
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 8/9] net/mlx5: improve xstats of bonding port Xueming Li
2021-03-28 13:48 ` [dpdk-dev] [PATCH v5 9/9] net/mlx5: probe host PF representor with SubFunction Xueming Li
2021-03-30 7:37 ` Slava Ovsiienko
2021-03-30 12:15 ` [dpdk-dev] [PATCH v3 0/5] eal: enable global device syntax by default Xueming Li
2021-03-31 8:23 ` Gaëtan Rivet
2021-03-30 12:15 ` [dpdk-dev] [PATCH v3 1/5] devargs: unify scratch buffer storage Xueming Li
2021-04-01 9:04 ` Kinsella, Ray
2021-03-30 12:15 ` [dpdk-dev] [PATCH v3 2/5] devargs: fix memory leak on parsing error Xueming Li
2021-03-30 12:15 ` [dpdk-dev] [PATCH v3 3/5] kvargs: add get by key function Xueming Li
2021-04-01 9:06 ` Kinsella, Ray
2021-04-01 9:10 ` Xueming(Steven) Li
2021-03-30 12:15 ` [dpdk-dev] [PATCH v3 4/5] bus: add device arguments name parsing API Xueming Li
2021-03-31 10:19 ` Thomas Monjalon
2021-04-01 15:13 ` Xueming(Steven) Li
2021-04-08 23:49 ` Thomas Monjalon
2021-03-30 12:15 ` [dpdk-dev] [PATCH v3 5/5] devargs: parse global device syntax Xueming Li
2021-04-10 14:23 ` [dpdk-dev] [PATCH v4 0/5] eal: enable global device syntax by default Xueming Li
2021-04-10 14:23 ` [dpdk-dev] [PATCH v4 1/5] devargs: unify scratch buffer storage Xueming Li
2021-04-10 19:59 ` Tal Shnaiderman
2021-04-12 12:07 ` Xueming(Steven) Li
2021-04-10 14:23 ` [dpdk-dev] [PATCH v4 2/5] devargs: fix memory leak on parsing error Xueming Li
2021-04-10 14:23 ` [dpdk-dev] [PATCH v4 3/5] kvargs: add get by key function Xueming Li
2021-04-12 6:52 ` Olivier Matz
2021-04-12 12:07 ` Xueming(Steven) Li
2021-04-12 21:18 ` Thomas Monjalon
2021-04-10 14:23 ` [dpdk-dev] [PATCH v4 4/5] bus: add device arguments name parsing API Xueming Li
2021-04-12 21:16 ` Thomas Monjalon
2021-04-12 23:37 ` Xueming(Steven) Li
2021-04-10 14:23 ` [dpdk-dev] [PATCH v4 5/5] devargs: parse global device syntax Xueming Li
2021-04-12 21:24 ` Thomas Monjalon
2021-04-12 23:47 ` Xueming(Steven) Li
2021-04-13 3:14 ` [dpdk-dev] [PATCH v5 0/5] eal: enable global device syntax by default Xueming Li
2021-04-14 19:49 ` Thomas Monjalon
2021-04-23 11:06 ` Kinsella, Ray
2021-04-23 11:39 ` Gaëtan Rivet
2021-04-23 12:35 ` Kinsella, Ray
2021-09-02 14:46 ` Thomas Monjalon
2021-04-13 3:14 ` [dpdk-dev] [PATCH v5 1/5] devargs: unify scratch buffer storage Xueming Li
2021-04-16 7:00 ` David Marchand
2021-04-16 12:32 ` Aaron Conole
2021-04-16 12:43 ` [dpdk-dev] [dpdklab] " Lincoln Lavoie
2021-04-16 12:58 ` Thomas Monjalon
2021-04-16 13:14 ` Lincoln Lavoie
2021-04-13 3:14 ` [dpdk-dev] [PATCH v5 2/5] devargs: fix memory leak on parsing error Xueming Li
2021-04-13 3:14 ` [dpdk-dev] [PATCH v5 3/5] kvargs: add get by key function Xueming Li
2021-04-13 3:14 ` Xueming Li [this message]
2021-04-13 3:14 ` [dpdk-dev] [PATCH v5 5/5] devargs: parse global device syntax Xueming Li
2021-09-28 8:29 ` David Marchand
2021-09-28 9:04 ` Thomas Monjalon
2021-10-03 10:51 ` Xueming(Steven) Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 2/9] devargs: fix memory leak on parsing error Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 3/9] devargs: fix memory leak in legacy parser Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 4/9] devargs: fix buffer data memory leak Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 5/9] kvargs: add get by key function Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 6/9] devargs: support new global device syntax Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 7/9] bus/pci: add new global device syntax support Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 8/9] common/mlx5: support device global syntax Xueming Li
2020-12-18 15:16 ` [dpdk-dev] [RFC 9/9] net/mlx5: support new " Xueming Li
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=1618283653-16510-5-git-send-email-xuemingl@nvidia.com \
--to=xuemingl@nvidia.com \
--cc=asafp@nvidia.com \
--cc=dev@dpdk.org \
--cc=gaetanr@nvidia.com \
--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).