[dpdk-dev,v5,4/7] pci: implement parse bus operation

Message ID 519fc66238ba3ee80b44e63547d105ca7689db16.1497999826.git.gaetan.rivet@6wind.com (mailing list archive)
State Superseded, archived
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail apply patch file failure

Commit Message

Gaëtan Rivet June 20, 2017, 11:30 p.m. UTC
  Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
 lib/librte_eal/common/eal_common_bus.c          | 16 ++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 19 +++++++++++++++++++
 lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
 5 files changed, 63 insertions(+)
  

Comments

Bruce Richardson June 27, 2017, 4:18 p.m. UTC | #1
On Wed, Jun 21, 2017 at 01:30:33AM +0200, Gaetan Rivet wrote:
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
>  lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  7 +++++++
>  lib/librte_eal/common/eal_common_bus.c          | 16 ++++++++++++++++
>  lib/librte_eal/common/eal_common_pci.c          | 19 +++++++++++++++++++
>  lib/librte_eal/common/include/rte_bus.h         | 14 ++++++++++++++
>  lib/librte_eal/linuxapp/eal/rte_eal_version.map |  7 +++++++
>  5 files changed, 63 insertions(+)
> 
> diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> index 150b0f7..3517d74 100644
> --- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> +++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
> @@ -197,3 +197,10 @@ DPDK_17.05 {
>  	vfio_get_group_no;
>  
>  } DPDK_17.02;
> +
> +DPDK_17.08 {
> +	global:
> +
> +	rte_bus_from_name;
> +
> +} DPDK_17.05;
> diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
> index b6bf57e..e69ce38 100644
> --- a/lib/librte_eal/common/eal_common_bus.c
> +++ b/lib/librte_eal/common/eal_common_bus.c
> @@ -215,3 +215,19 @@ rte_bus_find_device(const struct rte_device *start,
>  	}
>  	return dev;
>  }
> +
> +static int
> +bus_cmp_name(const struct rte_bus *bus, const void *_name)
> +{
> +	const char *name = _name;
> +
> +	return strncmp(bus->name, name,
> +		       strlen(bus->name));
> +}
> +
> +/* find a bus by its name */
> +struct rte_bus *
> +rte_bus_from_name(const char *str)
> +{
> +	return rte_bus_find(bus_cmp_name, str, NULL);
> +}

I think the rte_bus_from_name changes should go in a separate patch, as
they are not part of the PCI changes.

Content-wise, it looks good though, so keep my ack on both patches if
split.

Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index 150b0f7..3517d74 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -197,3 +197,10 @@  DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;
diff --git a/lib/librte_eal/common/eal_common_bus.c b/lib/librte_eal/common/eal_common_bus.c
index b6bf57e..e69ce38 100644
--- a/lib/librte_eal/common/eal_common_bus.c
+++ b/lib/librte_eal/common/eal_common_bus.c
@@ -215,3 +215,19 @@  rte_bus_find_device(const struct rte_device *start,
 	}
 	return dev;
 }
+
+static int
+bus_cmp_name(const struct rte_bus *bus, const void *_name)
+{
+	const char *name = _name;
+
+	return strncmp(bus->name, name,
+		       strlen(bus->name));
+}
+
+/* find a bus by its name */
+struct rte_bus *
+rte_bus_from_name(const char *str)
+{
+	return rte_bus_find(bus_cmp_name, str, NULL);
+}
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 00d48d9..0f3ecdb 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -450,6 +450,24 @@  rte_pci_dump(FILE *f)
 	}
 }
 
+/*
+ * Parse a device entry
+ * typeof(addr): (struct rte_pci_addr *)
+ */
+static int
+pci_parse(const char *name, void *addr)
+{
+	struct rte_pci_addr *out = addr;
+	struct rte_pci_addr pci_addr;
+	int parse;
+
+	parse = (eal_parse_pci_BDF(name, &pci_addr) == 0 ||
+		 eal_parse_pci_DomBDF(name, &pci_addr) == 0);
+	if (parse && addr)
+		*out = pci_addr;
+	return !parse;
+}
+
 /* register a driver */
 void
 rte_pci_register(struct rte_pci_driver *driver)
@@ -505,6 +523,7 @@  struct rte_pci_bus rte_pci_bus = {
 		.scan = rte_pci_scan,
 		.probe = rte_pci_probe,
 		.find_device = pci_find_device,
+		.parse = pci_parse,
 	},
 	.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
 	.driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h
index 05503ea..da8b8a1 100644
--- a/lib/librte_eal/common/include/rte_bus.h
+++ b/lib/librte_eal/common/include/rte_bus.h
@@ -268,6 +268,20 @@  rte_bus_find_device(const struct rte_device *start,
  */
 struct rte_bus *rte_bus_find_by_device(const struct rte_device *dev);
 
+/*
+ * Find a bus handle by its name.
+ * Compares the name of each bus up until any invalid character
+ * in the matched pattern.
+ *
+ * @param str
+ *	A null terminated character string.
+ *
+ * @return
+ *	A pointer to a bus if found.
+ *	NULL if no bus matches.
+ */
+struct rte_bus *rte_bus_from_name(const char *str);
+
 /**
  * Helper for Bus registration.
  * The constructor has higher priority than PMD constructors.
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index e0a056d..6607acc 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -201,3 +201,10 @@  DPDK_17.05 {
 	vfio_get_group_no;
 
 } DPDK_17.02;
+
+DPDK_17.08 {
+	global:
+
+	rte_bus_from_name;
+
+} DPDK_17.05;