DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support
@ 2020-04-28  9:11 talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 1/7] eal: move OS common functions to single file talshn
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

This patchset implements the EAL and PCI functions needed for probing PMDs using RTE_KDRV_NONE on Windows.

Depends-on: series-9374 ("Windows basic memory management")

v2:
	* fix style issues.
	* fix error handing flow in pci.c
	* change eal_config.c to eal_common_config.c 

Tal Shnaiderman (7):
  eal: move OS common functions to single file
  pci: build on Windows
  eal: add function finding integer in a string
  drivers: ignore pmdinfogen generation for Windows
  drivers: fix incorrect meson import folder for Windows
  bus/pci: introduce Windows support with stubs
  bus/pci: support Windows with bifurcated drivers

 drivers/baseband/meson.build                  |   4 +
 drivers/bus/ifpga/meson.build                 |   6 +
 drivers/bus/pci/meson.build                   |  14 +-
 drivers/bus/pci/pci_common.c                  |   2 -
 drivers/bus/pci/windows/pci.c                 | 516 ++++++++++++++++++++++++++
 drivers/bus/vdev/meson.build                  |   6 +
 drivers/bus/vmbus/meson.build                 |   7 +
 drivers/common/meson.build                    |   4 +
 drivers/compress/meson.build                  |   4 +
 drivers/crypto/meson.build                    |   4 +
 drivers/event/meson.build                     |   4 +
 drivers/mempool/meson.build                   |   4 +
 drivers/meson.build                           |   9 +-
 drivers/net/meson.build                       |   4 +
 drivers/raw/meson.build                       |   4 +
 drivers/vdpa/meson.build                      |   4 +
 lib/librte_eal/common/eal_common_config.c     |  34 ++
 lib/librte_eal/common/eal_common_string_fns.c |  29 ++
 lib/librte_eal/common/eal_private.h           |  11 +
 lib/librte_eal/common/meson.build             |   4 +
 lib/librte_eal/freebsd/eal.c                  |  34 --
 lib/librte_eal/include/rte_string_fns.h       |  17 +
 lib/librte_eal/linux/eal.c                    |  33 --
 lib/librte_eal/rte_eal_exports.def            |   9 +
 lib/librte_eal/windows/eal.c                  |  63 ++--
 lib/librte_eal/windows/eal_mp.c               |  14 +
 lib/librte_eal/windows/include/rte_os.h       |   1 +
 lib/librte_eal/windows/include/rte_windows.h  |   1 +
 lib/librte_pci/rte_pci.c                      |  10 +-
 lib/meson.build                               |   5 +-
 30 files changed, 739 insertions(+), 122 deletions(-)
 create mode 100644 drivers/bus/pci/windows/pci.c
 create mode 100644 lib/librte_eal/common/eal_common_config.c

-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 1/7] eal: move OS common functions to single file
  2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
@ 2020-04-28  9:11 ` talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 2/7] pci: build on Windows talshn
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

Move common functions between Unix and Windows to eal_common_config.c.

Those simple functions are getter functions for IOVA,
configuration, Multi-process.

Move rte_config and runtime_dir to be defined in a common file.

Signed-off-by: Tal Shnaiderman <talshn@mellanox.com>
---
 lib/librte_eal/common/eal_common_config.c | 34 +++++++++++++++++++++++++++++
 lib/librte_eal/common/eal_private.h       | 11 ++++++++++
 lib/librte_eal/common/meson.build         |  2 ++
 lib/librte_eal/freebsd/eal.c              | 34 -----------------------------
 lib/librte_eal/linux/eal.c                | 33 ----------------------------
 lib/librte_eal/windows/eal.c              | 36 -------------------------------
 6 files changed, 47 insertions(+), 103 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_config.c

diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
new file mode 100644
index 000000000..3a40df358
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_config.c
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2020 Mellanox Technologies, Ltd
+ */
+#include <eal_private.h>
+
+#include <rte_os.h>
+
+/* platform-specific runtime dir */
+static char runtime_dir[PATH_MAX];
+
+const char *
+rte_eal_get_runtime_dir(void)
+{
+	return runtime_dir;
+}
+
+/* Return a pointer to the configuration structure */
+struct rte_config *
+rte_eal_get_configuration(void)
+{
+	return &rte_config;
+}
+
+enum rte_iova_mode
+rte_eal_iova_mode(void)
+{
+	return rte_eal_get_configuration()->iova_mode;
+}
+
+enum rte_proc_type_t
+rte_eal_process_type(void)
+{
+	return rte_config.process_type;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index 735813d0c..dab9cac1d 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -13,6 +13,8 @@
 #include <rte_lcore.h>
 #include <rte_memory.h>
 
+#include <eal_memcfg.h>
+
 /**
  * Structure storing internal configuration (per-lcore)
  */
@@ -60,6 +62,15 @@ struct rte_config {
 	struct rte_mem_config *mem_config;
 } __rte_packed;
 
+
+/* early configuration structure, when memory config is not mmapped */
+static struct rte_mem_config early_mem_config;
+
+/* Address of global and public configuration */
+static struct rte_config rte_config = {
+		.mem_config = &early_mem_config,
+};
+
 /**
  * Get the global configuration structure.
  *
diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build
index 6dcdcc890..0d8c7462b 100644
--- a/lib/librte_eal/common/meson.build
+++ b/lib/librte_eal/common/meson.build
@@ -20,6 +20,7 @@ if is_windows
 		'eal_common_options.c',
 		'eal_common_tailqs.c',
 		'eal_common_thread.c',
+		'eal_common_config.c',
 		'malloc_elem.c',
 		'malloc_heap.c',
 		'rte_malloc.c',
@@ -52,6 +53,7 @@ sources += files(
 	'eal_common_thread.c',
 	'eal_common_timer.c',
 	'eal_common_uuid.c',
+	'eal_common_config.c',
 	'hotplug_mp.c',
 	'malloc_elem.c',
 	'malloc_heap.c',
diff --git a/lib/librte_eal/freebsd/eal.c b/lib/librte_eal/freebsd/eal.c
index 80dc9aa78..a0416a48b 100644
--- a/lib/librte_eal/freebsd/eal.c
+++ b/lib/librte_eal/freebsd/eal.c
@@ -71,11 +71,6 @@ static struct flock wr_lock = {
 		.l_len = sizeof(early_mem_config.memsegs),
 };
 
-/* Address of global and public configuration */
-static struct rte_config rte_config = {
-		.mem_config = &early_mem_config,
-};
-
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
@@ -85,9 +80,6 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
-/* platform-specific runtime dir */
-static char runtime_dir[PATH_MAX];
-
 static const char *default_runtime_dir = "/var/run";
 
 int
@@ -150,13 +142,6 @@ eal_clean_runtime_dir(void)
 	return 0;
 }
 
-
-const char *
-rte_eal_get_runtime_dir(void)
-{
-	return runtime_dir;
-}
-
 /* Return user provided mbuf pool ops name */
 const char *
 rte_eal_mbuf_user_pool_ops(void)
@@ -164,19 +149,6 @@ rte_eal_mbuf_user_pool_ops(void)
 	return internal_config.user_mbuf_pool_ops_name;
 }
 
-/* Return a pointer to the configuration structure */
-struct rte_config *
-rte_eal_get_configuration(void)
-{
-	return &rte_config;
-}
-
-enum rte_iova_mode
-rte_eal_iova_mode(void)
-{
-	return rte_eal_get_configuration()->iova_mode;
-}
-
 /* parse a sysfs (or other) file containing one integer value */
 int
 eal_parse_sysfs_value(const char *filename, unsigned long *val)
@@ -970,12 +942,6 @@ rte_eal_cleanup(void)
 	return 0;
 }
 
-enum rte_proc_type_t
-rte_eal_process_type(void)
-{
-	return rte_config.process_type;
-}
-
 int rte_eal_has_pci(void)
 {
 	return !internal_config.no_pci;
diff --git a/lib/librte_eal/linux/eal.c b/lib/librte_eal/linux/eal.c
index d1e532fc1..bc09bfcef 100644
--- a/lib/librte_eal/linux/eal.c
+++ b/lib/librte_eal/linux/eal.c
@@ -85,11 +85,6 @@ static struct flock wr_lock = {
 		.l_len = sizeof(early_mem_config.memsegs),
 };
 
-/* Address of global and public configuration */
-static struct rte_config rte_config = {
-		.mem_config = &early_mem_config,
-};
-
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
@@ -99,9 +94,6 @@ struct internal_config internal_config;
 /* used by rte_rdtsc() */
 int rte_cycles_vmware_tsc_map;
 
-/* platform-specific runtime dir */
-static char runtime_dir[PATH_MAX];
-
 static const char *default_runtime_dir = "/var/run";
 
 int
@@ -240,12 +232,6 @@ eal_clean_runtime_dir(void)
 	return -1;
 }
 
-const char *
-rte_eal_get_runtime_dir(void)
-{
-	return runtime_dir;
-}
-
 /* Return user provided mbuf pool ops name */
 const char *
 rte_eal_mbuf_user_pool_ops(void)
@@ -253,19 +239,6 @@ rte_eal_mbuf_user_pool_ops(void)
 	return internal_config.user_mbuf_pool_ops_name;
 }
 
-/* Return a pointer to the configuration structure */
-struct rte_config *
-rte_eal_get_configuration(void)
-{
-	return &rte_config;
-}
-
-enum rte_iova_mode
-rte_eal_iova_mode(void)
-{
-	return rte_eal_get_configuration()->iova_mode;
-}
-
 /* parse a sysfs (or other) file containing one integer value */
 int
 eal_parse_sysfs_value(const char *filename, unsigned long *val)
@@ -1331,12 +1304,6 @@ rte_eal_cleanup(void)
 	return 0;
 }
 
-enum rte_proc_type_t
-rte_eal_process_type(void)
-{
-	return rte_config.process_type;
-}
-
 int rte_eal_has_hugepages(void)
 {
 	return ! internal_config.no_hugetlbfs;
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 38f17f09c..57520d51c 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -31,36 +31,12 @@ static rte_usage_hook_t	rte_application_usage_hook;
  */
 static int mem_cfg_fd = -1;
 
-/* early configuration structure, when memory config is not mmapped */
-static struct rte_mem_config early_mem_config;
-
-/* Address of global and public configuration */
-static struct rte_config rte_config = {
-		.mem_config = &early_mem_config,
-};
-
 /* internal configuration (per-core) */
 struct lcore_config lcore_config[RTE_MAX_LCORE];
 
 /* internal configuration */
 struct internal_config internal_config;
 
-/* platform-specific runtime dir */
-static char runtime_dir[PATH_MAX];
-
-const char *
-rte_eal_get_runtime_dir(void)
-{
-	return runtime_dir;
-}
-
-/* Return a pointer to the configuration structure */
-struct rte_config *
-rte_eal_get_configuration(void)
-{
-	return &rte_config;
-}
-
 /* Detect if we are a primary or a secondary process */
 enum rte_proc_type_t
 eal_proc_type_detect(void)
@@ -93,24 +69,12 @@ eal_proc_type_detect(void)
 	return ptype;
 }
 
-enum rte_proc_type_t
-rte_eal_process_type(void)
-{
-	return rte_config.process_type;
-}
-
 int
 rte_eal_has_hugepages(void)
 {
 	return !internal_config.no_hugetlbfs;
 }
 
-enum rte_iova_mode
-rte_eal_iova_mode(void)
-{
-	return rte_config.iova_mode;
-}
-
 /* display usage */
 static void
 eal_usage(const char *prgname)
-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 2/7] pci: build on Windows
  2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 1/7] eal: move OS common functions to single file talshn
@ 2020-04-28  9:11 ` talshn
  2020-04-28 23:52   ` Dmitry Kozlyuk
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 3/7] eal: add function finding integer in a string talshn
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

Changing all of PCIs Unix memory mapping to the
new memory allocation API wrapper.

Added off_t in Windows header file as a supported
type since it is needed by PCI.

Signed-off-by: Tal Shnaiderman <talshn@mellanox.com>
---
 lib/librte_eal/windows/include/rte_os.h |  1 +
 lib/librte_pci/rte_pci.c                | 10 +++++-----
 lib/meson.build                         |  5 ++++-
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 62805a307..1c433b976 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h
@@ -48,6 +48,7 @@ extern "C" {
 
 /* as in <windows.h> */
 typedef long long ssize_t;
+typedef long off_t;
 
 #ifndef RTE_TOOLCHAIN_GCC
 static inline int
diff --git a/lib/librte_pci/rte_pci.c b/lib/librte_pci/rte_pci.c
index d1ab6b414..5dc8b5a6f 100644
--- a/lib/librte_pci/rte_pci.c
+++ b/lib/librte_pci/rte_pci.c
@@ -9,7 +9,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
-#include <sys/mman.h>
 
 #include <rte_errno.h>
 #include <rte_interrupts.h>
@@ -138,9 +137,10 @@ pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
 	void *mapaddr;
 
 	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
+	mapaddr = rte_mem_map(requested_addr, size,
+		RTE_PROT_READ | RTE_PROT_WRITE,
+		RTE_MAP_SHARED | additional_flags, fd, offset);
+	if (mapaddr == NULL) {
 		RTE_LOG(ERR, EAL,
 			"%s(): cannot mmap(%d, %p, 0x%zx, 0x%llx): %s (%p)\n",
 			__func__, fd, requested_addr, size,
@@ -160,7 +160,7 @@ pci_unmap_resource(void *requested_addr, size_t size)
 		return;
 
 	/* Unmap the PCI memory resource of device */
-	if (munmap(requested_addr, size)) {
+	if (rte_mem_unmap(requested_addr, size)) {
 		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, %#zx): %s\n",
 			__func__, requested_addr, size,
 			strerror(errno));
diff --git a/lib/meson.build b/lib/meson.build
index 63c17ee75..a01bcf04d 100644
--- a/lib/meson.build
+++ b/lib/meson.build
@@ -33,7 +33,10 @@ libraries = [
 	'flow_classify', 'bpf', 'telemetry']
 
 if is_windows
-	libraries = ['kvargs','eal'] # only supported libraries for windows
+	libraries = [
+		'kvargs','eal',
+		'pci',
+	] # only supported libraries for windows
 endif
 
 default_cflags = machine_args + ['-DALLOW_EXPERIMENTAL_API']
-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 3/7] eal: add function finding integer in a string
  2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 1/7] eal: move OS common functions to single file talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 2/7] pci: build on Windows talshn
@ 2020-04-28  9:11 ` talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 4/7] drivers: ignore pmdinfogen generation for Windows talshn
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

Addition of a function to skip leading chars which are not part of
the numeric base and return the number in the needed base.

This is needed to call strtoul correctly and will be used
by bus/PCI to get the BDF from a PCI output.

Signed-off-by: Tal Shnaiderman <talshn@mellanox.com>
---
 lib/librte_eal/common/eal_common_string_fns.c | 29 +++++++++++++++++++++++++++
 lib/librte_eal/include/rte_string_fns.h       | 17 ++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/lib/librte_eal/common/eal_common_string_fns.c b/lib/librte_eal/common/eal_common_string_fns.c
index 60c5dd66f..29d1539da 100644
--- a/lib/librte_eal/common/eal_common_string_fns.c
+++ b/lib/librte_eal/common/eal_common_string_fns.c
@@ -8,6 +8,7 @@
 #include <errno.h>
 
 #include <rte_string_fns.h>
+#include <rte_errno.h>
 
 /* split string into tokens */
 int
@@ -64,3 +65,31 @@ rte_strscpy(char *dst, const char *src, size_t dsize)
 		dst[res - 1] = '\0';
 	return -E2BIG;
 }
+
+/* Skip leading chars to return the number in the needed base
+ *
+ * Return 0 and rte_errno if no number found,
+ * Otherwise return the number in the needed base
+ */
+unsigned long
+rte_find_numerical_value(char *str, int base)
+{
+	unsigned int num = 0;
+	uint8_t i = 0;
+
+	if (str == NULL)
+		goto einval_error;
+
+	while (str[i]) {
+		if ((base == 10 && isdigit(str[i])) ||
+			(base == 16 && isxdigit(str[i]))) {
+			num = strtoul(&str[i], NULL, base);
+			goto end;
+		}
+		i++;
+	}
+einval_error:
+	rte_errno = EINVAL;
+end:
+	return num;
+}
diff --git a/lib/librte_eal/include/rte_string_fns.h b/lib/librte_eal/include/rte_string_fns.h
index 8bac8243c..df6e07dd3 100644
--- a/lib/librte_eal/include/rte_string_fns.h
+++ b/lib/librte_eal/include/rte_string_fns.h
@@ -50,6 +50,23 @@ int
 rte_strsplit(char *string, int stringlen,
              char **tokens, int maxtokens, char delim);
 
+/**
+ * Skips leading characters to return a number in the needed base
+ *
+ * @param str
+ *   The input string to search upon
+ *
+ * @param base
+ *   The base of the needed number.
+ *   (currently supports bases 10 and 16)
+ *
+ * @return
+ *   - the number in the correct base if found
+ *   - zero and rte_errno = EINVAL if no number was found
+ */
+unsigned long
+rte_find_numerical_value(char *str, int base);
+
 /**
  * @internal
  * DPDK-specific version of strlcpy for systems without
-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 4/7] drivers: ignore pmdinfogen generation for Windows
  2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
                   ` (2 preceding siblings ...)
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 3/7] eal: add function finding integer in a string talshn
@ 2020-04-28  9:11 ` talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 5/7] drivers: fix incorrect meson import folder " talshn
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

pmdinfogen generation is currently unsupported for Windows.
The relevant part in meson.build is skipped.

Signed-off-by: Tal Shnaiderman <talshn@mellanox.com>
---
 drivers/meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/meson.build b/drivers/meson.build
index 4d8f842ab..a540117b6 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -107,6 +107,7 @@ foreach class:dpdk_driver_classes
 
 			dpdk_extra_ldflags += pkgconfig_extra_libs
 
+			if host_machine.system() != 'windows'
 			# generate pmdinfo sources by building a temporary
 			# lib and then running pmdinfogen on the contents of
 			# that lib. The final lib reuses the object files and
@@ -123,7 +124,7 @@ foreach class:dpdk_driver_classes
 						'@OUTPUT@', pmdinfogen],
 					output: out_filename,
 					depends: [pmdinfogen, tmp_lib])
-
+			endif
 			version_map = '@0@/@1@/@2@_version.map'.format(
 					meson.current_source_dir(),
 					drv_path, lib_name)
-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 5/7] drivers: fix incorrect meson import folder for Windows
  2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
                   ` (3 preceding siblings ...)
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 4/7] drivers: ignore pmdinfogen generation for Windows talshn
@ 2020-04-28  9:11 ` talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 6/7] bus/pci: introduce Windows support with stubs talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 7/7] bus/pci: support Windows with bifurcated drivers talshn
  6 siblings, 0 replies; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

import library (/IMPLIB) in meson.build should use
the 'drivers' and not 'libs' folder.

The error is: fatal error LNK1149: output filename matches input filename.
The fix uses the correct folder.

Fixes: 5ed3766981 ("drivers: process shared link dependencies as for libs")

Signed-off-by: Tal Shnaiderman <talshn@mellanox.com>
---
 drivers/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/meson.build b/drivers/meson.build
index a540117b6..d07360d27 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -162,7 +162,7 @@ foreach class:dpdk_driver_classes
 			lk_deps = [version_map, def_file]
 			if is_windows
 				lk_args = ['-Wl,/def:' + def_file.full_path(),
-					'-Wl,/implib:lib\\' + implib]
+					'-Wl,/implib:drivers\\' + implib]
 			else
 				lk_args = ['-Wl,--version-script=' + version_map]
 				# on unix systems check the output of the
-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 6/7] bus/pci: introduce Windows support with stubs
  2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
                   ` (4 preceding siblings ...)
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 5/7] drivers: fix incorrect meson import folder " talshn
@ 2020-04-28  9:11 ` talshn
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 7/7] bus/pci: support Windows with bifurcated drivers talshn
  6 siblings, 0 replies; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

Addition of stub eal and bus/pci functions to compile
bus/pci for Windows.

Signed-off-by: Tal Shnaiderman <talshn@mellanox.com>
---
 drivers/baseband/meson.build       |   4 +
 drivers/bus/ifpga/meson.build      |   6 ++
 drivers/bus/pci/meson.build        |  14 ++-
 drivers/bus/pci/pci_common.c       |   2 -
 drivers/bus/pci/windows/pci.c      | 178 +++++++++++++++++++++++++++++++++++++
 drivers/bus/vdev/meson.build       |   6 ++
 drivers/bus/vmbus/meson.build      |   7 ++
 drivers/common/meson.build         |   4 +
 drivers/compress/meson.build       |   4 +
 drivers/crypto/meson.build         |   4 +
 drivers/event/meson.build          |   4 +
 drivers/mempool/meson.build        |   4 +
 drivers/meson.build                |   4 -
 drivers/net/meson.build            |   4 +
 drivers/raw/meson.build            |   4 +
 drivers/vdpa/meson.build           |   4 +
 lib/librte_eal/common/meson.build  |   2 +
 lib/librte_eal/rte_eal_exports.def |   8 ++
 lib/librte_eal/windows/eal.c       |  27 +++++-
 lib/librte_eal/windows/eal_mp.c    |  14 +++
 20 files changed, 293 insertions(+), 11 deletions(-)
 create mode 100644 drivers/bus/pci/windows/pci.c

diff --git a/drivers/baseband/meson.build b/drivers/baseband/meson.build
index 4d909f9a6..b299c3a06 100644
--- a/drivers/baseband/meson.build
+++ b/drivers/baseband/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Luca Boccassi <bluca@debian.org>
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['null', 'turbo_sw', 'fpga_lte_fec', 'fpga_5gnr_fec']
 
 config_flag_fmt = 'RTE_LIBRTE_PMD_BBDEV_@0@'
diff --git a/drivers/bus/ifpga/meson.build b/drivers/bus/ifpga/meson.build
index 4ea31f174..15339e065 100644
--- a/drivers/bus/ifpga/meson.build
+++ b/drivers/bus/ifpga/meson.build
@@ -1,6 +1,12 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2010-2018 Intel Corporation
 
+if host_machine.system() == 'windows'
+	build = false
+	reason = 'not supported on Windows'
+	subdir_done()
+endif
+
 deps += ['pci', 'kvargs', 'rawdev']
 install_headers('rte_bus_ifpga.h')
 sources = files('ifpga_common.c', 'ifpga_bus.c')
diff --git a/drivers/bus/pci/meson.build b/drivers/bus/pci/meson.build
index b520bdfc1..31c492021 100644
--- a/drivers/bus/pci/meson.build
+++ b/drivers/bus/pci/meson.build
@@ -4,16 +4,22 @@
 deps += ['pci']
 install_headers('rte_bus_pci.h')
 sources = files('pci_common.c',
-	'pci_common_uio.c',
 	'pci_params.c')
 if is_linux
-	sources += files('linux/pci.c',
+	sources += files('pci_common_uio.c',
+			'linux/pci.c',
 			'linux/pci_uio.c',
 			'linux/pci_vfio.c')
 	includes += include_directories('linux')
-else
-	sources += files('bsd/pci.c')
+endif
+if host_machine.system() == 'bsd'
+	sources += files('pci_common_uio.c',
+			'bsd/pci.c')
 	includes += include_directories('bsd')
 endif
+if host_machine.system() == 'windows'
+	sources += files('windows/pci.c')
+	includes += include_directories('windows')
+endif
 
 deps += ['kvargs']
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 3f5542076..1cc8d6c0f 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -10,8 +10,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
-#include <sys/mman.h>
-
 #include <rte_errno.h>
 #include <rte_interrupts.h>
 #include <rte_log.h>
diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c
new file mode 100644
index 000000000..d02bfce36
--- /dev/null
+++ b/drivers/bus/pci/windows/pci.c
@@ -0,0 +1,178 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright 2020 Mellanox Technologies, Ltd
+ */
+#include <rte_errno.h>
+#include <rte_log.h>
+
+#include <rte_string_fns.h>
+#include <rte_eal_memconfig.h>
+
+#include "private.h"
+
+/* The functions below are not implemented on Windows,
+ * but need to be defined for compilation purposes
+ */
+
+/* unbind kernel driver for this device */
+int
+pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
+{
+	RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag"
+		" is not implemented presently in Windows\n");
+	return -ENOTSUP;
+}
+
+/* Map pci device */
+int
+rte_pci_map_device(struct rte_pci_device *dev __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return 0;
+}
+
+/* Unmap pci device */
+void
+rte_pci_unmap_device(struct rte_pci_device *dev __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+}
+
+int
+pci_update_device(const struct rte_pci_addr *addr __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return 0;
+}
+
+/* Read PCI config space. */
+int
+rte_pci_read_config(const struct rte_pci_device *dev __rte_unused,
+	void *buf __rte_unused, size_t len __rte_unused,
+	off_t offset __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return 0;
+}
+
+/* Write PCI config space. */
+int
+rte_pci_write_config(const struct rte_pci_device *dev __rte_unused,
+	const void *buf __rte_unused, size_t len __rte_unused,
+	off_t offset __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return 0;
+}
+
+enum rte_iova_mode
+pci_device_iova_mode(const struct rte_pci_driver *pdrv __rte_unused,
+		const struct rte_pci_device *pdev __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return RTE_IOVA_DC;
+}
+
+int
+rte_pci_ioport_map(struct rte_pci_device *dev __rte_unused,
+	int bar __rte_unused, struct rte_pci_ioport *p __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return -1;
+}
+
+
+void
+rte_pci_ioport_read(struct rte_pci_ioport *p __rte_unused,
+	void *data __rte_unused, size_t len __rte_unused,
+	off_t offset __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+}
+
+int
+rte_pci_ioport_unmap(struct rte_pci_ioport *p __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return -1;
+}
+
+bool
+pci_device_iommu_support_va(const struct rte_pci_device *dev __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return false;
+}
+
+void
+rte_pci_ioport_write(struct rte_pci_ioport *p __rte_unused,
+		const void *data __rte_unused, size_t len __rte_unused,
+		off_t offset __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+}
+
+
+/* remap the PCI resource of a PCI device in anonymous virtual memory */
+int
+pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused)
+{
+	/* This function is not implemented on Windows.
+	 * We really should short-circuit the call to these functions by
+	 * clearing the RTE_PCI_DRV_NEED_MAPPING flag
+	 * in the rte_pci_driver flags.
+	 */
+	return -1;
+}
+/*
+ * Scan the contents of the PCI bus
+ * and add all network class devices into the devices list.
+ */
+int
+rte_pci_scan(void)
+{
+	return 0;
+}
diff --git a/drivers/bus/vdev/meson.build b/drivers/bus/vdev/meson.build
index 967d54e4f..abaf36f1d 100644
--- a/drivers/bus/vdev/meson.build
+++ b/drivers/bus/vdev/meson.build
@@ -1,6 +1,12 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+if host_machine.system() == 'windows'
+	build = false
+	reason = 'not supported on Windows'
+	subdir_done()
+endif
+
 sources = files('vdev.c',
 	'vdev_params.c')
 install_headers('rte_bus_vdev.h')
diff --git a/drivers/bus/vmbus/meson.build b/drivers/bus/vmbus/meson.build
index a68a1de9d..7c9865fe8 100644
--- a/drivers/bus/vmbus/meson.build
+++ b/drivers/bus/vmbus/meson.build
@@ -1,5 +1,12 @@
 # SPDX-License-Identifier: BSD-3-Clause
 
+if host_machine.system() == 'windows'
+	build = false
+	reason = 'not supported on Windows'
+	subdir_done()
+endif
+
+
 install_headers('rte_bus_vmbus.h','rte_vmbus_reg.h')
 
 sources = files('vmbus_common.c',
diff --git a/drivers/common/meson.build b/drivers/common/meson.build
index ffd06e2c3..1cdcd95d6 100644
--- a/drivers/common/meson.build
+++ b/drivers/common/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Cavium, Inc
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 std_deps = ['eal']
 drivers = ['cpt', 'dpaax', 'iavf', 'mlx5', 'mvep', 'octeontx', 'octeontx2', 'qat']
 config_flag_fmt = 'RTE_LIBRTE_@0@_COMMON'
diff --git a/drivers/compress/meson.build b/drivers/compress/meson.build
index 817ef3be4..e6c7d564e 100644
--- a/drivers/compress/meson.build
+++ b/drivers/compress/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2018 Intel Corporation
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['isal', 'octeontx', 'qat', 'zlib']
 
 std_deps = ['compressdev'] # compressdev pulls in all other needed deps
diff --git a/drivers/crypto/meson.build b/drivers/crypto/meson.build
index 7fa1fbe26..2c591eaf0 100644
--- a/drivers/crypto/meson.build
+++ b/drivers/crypto/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['aesni_gcm',
 	   'aesni_mb',
 	   'armv8',
diff --git a/drivers/event/meson.build b/drivers/event/meson.build
index 50d30c53f..264d4887f 100644
--- a/drivers/event/meson.build
+++ b/drivers/event/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['dpaa', 'dpaa2', 'octeontx2', 'opdl', 'skeleton', 'sw', 'dsw']
 if not (toolchain == 'gcc' and cc.version().version_compare('<4.8.6') and
 	dpdk_conf.has('RTE_ARCH_ARM64'))
diff --git a/drivers/mempool/meson.build b/drivers/mempool/meson.build
index 7520e489f..0c6e70082 100644
--- a/drivers/mempool/meson.build
+++ b/drivers/mempool/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['bucket', 'dpaa', 'dpaa2', 'octeontx', 'octeontx2', 'ring', 'stack']
 std_deps = ['mempool']
 config_flag_fmt = 'RTE_LIBRTE_@0@_MEMPOOL'
diff --git a/drivers/meson.build b/drivers/meson.build
index d07360d27..d37f58e5e 100644
--- a/drivers/meson.build
+++ b/drivers/meson.build
@@ -1,10 +1,6 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017-2019 Intel Corporation
 
-if is_windows
-	subdir_done()
-endif
-
 # Defines the order in which the drivers are buit.
 dpdk_driver_classes = ['common',
 	       'bus',
diff --git a/drivers/net/meson.build b/drivers/net/meson.build
index b0ea8fede..c3570d6b7 100644
--- a/drivers/net/meson.build
+++ b/drivers/net/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright(c) 2017 Intel Corporation
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['af_packet',
 	'af_xdp',
 	'ark',
diff --git a/drivers/raw/meson.build b/drivers/raw/meson.build
index bb5797760..334b14ac3 100644
--- a/drivers/raw/meson.build
+++ b/drivers/raw/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright 2018 NXP
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['dpaa2_cmdif', 'dpaa2_qdma',
 	'ifpga', 'ioat', 'ntb',
 	'octeontx2_dma',
diff --git a/drivers/vdpa/meson.build b/drivers/vdpa/meson.build
index e3ed54a25..7eedf826d 100644
--- a/drivers/vdpa/meson.build
+++ b/drivers/vdpa/meson.build
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: BSD-3-Clause
 # Copyright 2019 Mellanox Technologies, Ltd
 
+if host_machine.system() == 'windows'
+	subdir_done()
+endif
+
 drivers = ['ifc',
 	   'mlx5',]
 std_deps = ['bus_pci', 'kvargs']
diff --git a/lib/librte_eal/common/meson.build b/lib/librte_eal/common/meson.build
index 0d8c7462b..51a1bbb78 100644
--- a/lib/librte_eal/common/meson.build
+++ b/lib/librte_eal/common/meson.build
@@ -7,6 +7,7 @@ if is_windows
 	sources += files(
 		'eal_common_bus.c',
 		'eal_common_class.c',
+		'eal_common_dev.c',
 		'eal_common_devargs.c',
 		'eal_common_errno.c',
 		'eal_common_fbarray.c',
@@ -18,6 +19,7 @@ if is_windows
 		'eal_common_memory.c',
 		'eal_common_memzone.c',
 		'eal_common_options.c',
+		'eal_common_string_fns.c',
 		'eal_common_tailqs.c',
 		'eal_common_thread.c',
 		'eal_common_config.c',
diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def
index 854b83bcd..edbb6b277 100644
--- a/lib/librte_eal/rte_eal_exports.def
+++ b/lib/librte_eal/rte_eal_exports.def
@@ -2,6 +2,11 @@ EXPORTS
 	__rte_panic
 	rte_calloc
 	rte_calloc_socket
+	per_lcore__rte_errno
+	rte_bus_register
+	rte_dev_is_probed
+	rte_devargs_next
+	rte_devargs_remove
 	rte_eal_get_configuration
 	rte_eal_has_hugepages
 	rte_eal_init
@@ -46,6 +51,9 @@ EXPORTS
 	rte_memzone_reserve_aligned
 	rte_memzone_reserve_bounded
 	rte_memzone_walk
+	rte_strsplit
+	rte_vfio_container_dma_map
+	rte_vfio_container_dma_unmap
 	rte_vlog
 	rte_realloc
 	rte_zmalloc
diff --git a/lib/librte_eal/windows/eal.c b/lib/librte_eal/windows/eal.c
index 57520d51c..474517730 100644
--- a/lib/librte_eal/windows/eal.c
+++ b/lib/librte_eal/windows/eal.c
@@ -293,7 +293,7 @@ eal_file_lock(int fd, enum eal_flock_op op, enum eal_flock_mode mode)
 int
 rte_eal_init(int argc, char **argv)
 {
-	int i, fctret;
+	int i, fctret, bscan;
 
 	eal_log_level_parse(argc, argv);
 
@@ -366,6 +366,13 @@ rte_eal_init(int argc, char **argv)
 
 	eal_thread_init_master(rte_config.master_lcore);
 
+	bscan = rte_bus_scan();
+	if (bscan < 0) {
+		rte_eal_init_alert("Cannot init PCI");
+		rte_errno = ENODEV;
+		return -1;
+	}
+
 	RTE_LCORE_FOREACH_SLAVE(i) {
 
 		/*
@@ -394,3 +401,21 @@ rte_eal_init(int argc, char **argv)
 	rte_eal_mp_wait_lcore();
 	return fctret;
 }
+
+int
+rte_vfio_container_dma_map(__rte_unused int container_fd,
+			__rte_unused uint64_t vaddr,
+			__rte_unused uint64_t iova,
+			__rte_unused uint64_t len)
+{
+	return -1;
+}
+
+int
+rte_vfio_container_dma_unmap(__rte_unused int container_fd,
+			__rte_unused uint64_t vaddr,
+			__rte_unused uint64_t iova,
+			__rte_unused uint64_t len)
+{
+	return -1;
+}
diff --git a/lib/librte_eal/windows/eal_mp.c b/lib/librte_eal/windows/eal_mp.c
index 16a5e8ba0..70061bea0 100644
--- a/lib/librte_eal/windows/eal_mp.c
+++ b/lib/librte_eal/windows/eal_mp.c
@@ -101,3 +101,17 @@ request_sync(void)
 	EAL_LOG_STUB();
 	return 0;
 }
+
+int
+eal_dev_hotplug_request_to_primary(struct eal_dev_mp_req *req)
+{
+	RTE_SET_USED(req);
+	return 0;
+}
+
+int
+eal_dev_hotplug_request_to_secondary(struct eal_dev_mp_req *req)
+{
+	RTE_SET_USED(req);
+	return 0;
+}
-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [dpdk-dev] [PATCH v2 7/7] bus/pci: support Windows with bifurcated drivers
  2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
                   ` (5 preceding siblings ...)
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 6/7] bus/pci: introduce Windows support with stubs talshn
@ 2020-04-28  9:11 ` talshn
  2020-04-29  0:01   ` Dmitry Kozlyuk
  6 siblings, 1 reply; 11+ messages in thread
From: talshn @ 2020-04-28  9:11 UTC (permalink / raw)
  To: dev
  Cc: thomas, pallavi.kadam, dmitry.kozliuk, david.marchand, grive,
	ranjit.menon, navasile, Tal Shnaiderman

From: Tal Shnaiderman <talshn@mellanox.com>

Uses SetupAPI.h functions to scan PCI tree.
Uses DEVPKEY_Device_Numa_Node to get the PCI Numa node.
scanning currently supports types RTE_KDRV_NONE.

Signed-off-by: Tal Shnaiderman <talshn@mellanox.com>
---
 drivers/bus/pci/windows/pci.c                | 342 ++++++++++++++++++++++++++-
 lib/librte_eal/rte_eal_exports.def           |   1 +
 lib/librte_eal/windows/include/rte_windows.h |   1 +
 3 files changed, 342 insertions(+), 2 deletions(-)

diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c
index d02bfce36..238312637 100644
--- a/drivers/bus/pci/windows/pci.c
+++ b/drivers/bus/pci/windows/pci.c
@@ -1,14 +1,24 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright 2020 Mellanox Technologies, Ltd
  */
+#include <rte_windows.h>
 #include <rte_errno.h>
 #include <rte_log.h>
-
 #include <rte_string_fns.h>
 #include <rte_eal_memconfig.h>
 
 #include "private.h"
 
+#include <devpkey.h>
+
+#define  MAX_STR_TOKENS		8
+#define  DEC			10
+#define  HEX			16
+/*
+ * This code is used to simulate a PCI probe by parsing information in
+ * the registry hive for PCI devices.
+ */
+
 /* The functions below are not implemented on Windows,
  * but need to be defined for compilation purposes
  */
@@ -167,6 +177,300 @@ pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused)
 	 */
 	return -1;
 }
+
+static
+int get_device_resource_info(HDEVINFO hDevInfo,
+	PSP_DEVINFO_DATA pDeviceInfoData, struct rte_pci_device *dev)
+{
+	int  ret = -1;
+	DEVPROPTYPE uPropertyType;
+	DWORD uNumaNode;
+	BOOL  bResult;
+
+	switch (dev->kdrv) {
+	case RTE_KDRV_NONE:
+		/* Get NUMA node using DEVPKEY_Device_Numa_Node */
+		bResult = SetupDiGetDevicePropertyW(hDevInfo, pDeviceInfoData,
+			&DEVPKEY_Device_Numa_Node, &uPropertyType,
+			(BYTE *)&uNumaNode, sizeof(uNumaNode), NULL, 0);
+		if (!bResult) {
+			ret = GetLastError();
+			goto end;
+		}
+		dev->device.numa_node = uNumaNode;
+		/* mem_resource - Unneeded for RTE_KDRV_NONE */
+		dev->mem_resource[0].phys_addr = 0;
+		dev->mem_resource[0].len = 0;
+		dev->mem_resource[0].addr = NULL;
+		break;
+	default:
+		ret = ERROR_NOT_SUPPORTED;
+		goto end;
+	}
+
+	ret = ERROR_SUCCESS;
+end:
+	return ret;
+}
+
+
+/*
+ * split up a pci address into its constituent parts.
+ */
+static int
+parse_pci_addr_format(const char *buf, int bufsize, struct rte_pci_addr *addr)
+{
+	int ret = -1;
+
+	char *str[MAX_STR_TOKENS] = { 0 };
+
+	char *buf_copy = _strdup(buf);
+	if (buf_copy == NULL)
+		goto end;
+
+	/* PCI Addr format string is delimited by ',' */
+	/* eg: "PCI bus 5, device 35, function 0" */
+	if (rte_strsplit(buf_copy, bufsize, str, MAX_STR_TOKENS, ',')
+			 > MAX_STR_TOKENS - 1) {
+		goto end;
+	}
+
+	/* Bus, device and function values tokens in the str[] */
+	/* Convert to numerical values */
+	addr->domain = 0;
+	addr->bus = (uint8_t)rte_find_numerical_value(str[0], DEC);
+	addr->devid = (uint8_t)rte_find_numerical_value(str[1], DEC);
+	addr->function = (uint8_t)rte_find_numerical_value(str[2], DEC);
+
+	if (rte_errno != 0)
+		goto end;
+
+	ret = 0;
+end:
+	/* free the copy made (if any) with _tcsdup */
+	if (buf_copy)
+		free(buf_copy);
+	return ret;
+}
+
+static int
+parse_hardware_ids(char *str, unsigned int strlength, uint16_t *val1,
+		uint16_t *val2)
+{
+	int ret = -1;
+	char *strID[MAX_STR_TOKENS] = { 0 };
+
+	if (rte_strsplit(str, strlength, strID, MAX_STR_TOKENS, '_')
+		 > MAX_STR_TOKENS - 1) {
+		goto end;
+	}
+
+	/* check if string combined ID value (eg: subdeviceID+subvendorID) */
+	if (strlen(strID[1]) == 8) {
+		char strval1[8];
+		char strval2[8];
+		memset(strval1, 0, sizeof(strval1));
+		memset(strval2, 0, sizeof(strval2));
+
+		memcpy_s(strval1, sizeof(strval1), strID[1], 4);
+		memcpy_s(strval2, sizeof(strval2), strID[1]+4, 4);
+
+		if (val1)
+			*val1 = (uint16_t)rte_find_numerical_value(
+					strval1, HEX);
+		if (val2)
+			*val2 = (uint16_t)rte_find_numerical_value(
+					strval2, HEX);
+	} else {
+		if (val1)
+			*val1 = (uint16_t)rte_find_numerical_value(
+					strID[1], HEX);
+	}
+
+	if (rte_errno != 0)
+		goto end;
+
+	ret = 0;
+end:
+	return ret;
+}
+
+/*
+ * split up hardware ID into its constituent parts.
+ */
+static int
+parse_pci_hardware_id_format(const char *buf, int bufsize, uint16_t *vendorID,
+	uint16_t *deviceID, uint16_t *subvendorID, uint16_t *subdeviceID)
+{
+	int ret = -1;
+
+	char *str[MAX_STR_TOKENS] = { 0 };
+
+	char *buf_copy = _strdup(buf);
+	if (buf_copy == NULL)
+		goto end;
+
+	/* PCI Hardware ID format string is first delimited by '\\' */
+	/* eg: "PCI\VEN_8086&DEV_153A&SUBSYS_00008086&REV_04" */
+	if (rte_strsplit(buf_copy, bufsize, str, MAX_STR_TOKENS, '\\') >
+			MAX_STR_TOKENS - 1) {
+		goto end;
+	}
+	char *buf_copy_stripped = _strdup(str[1]);
+	if (buf_copy_stripped == NULL)
+		goto end;
+	/* The remaining string is delimited by '&' */
+	if (rte_strsplit(buf_copy_stripped, bufsize, str, MAX_STR_TOKENS, '&')
+			> MAX_STR_TOKENS - 1) {
+		goto end;
+	}
+	/* We now have the various hw IDs in tokens in the str[] array */
+	/* Isolate the numerical IDs - '_' as the delimiter */
+	if (parse_hardware_ids(str[0], strlen(str[0]), vendorID, NULL))
+		goto end;
+
+	if (parse_hardware_ids(str[1], strlen(str[1]), deviceID, NULL))
+		goto end;
+
+	if (parse_hardware_ids(str[2], strlen(str[2]), subdeviceID,
+		subvendorID)) {
+		goto end;
+	}
+
+	ret = 0;
+end:
+	/* free the copy made (if any) with _tcsdup */
+	if (buf_copy)
+		free(buf_copy);
+	if (buf_copy_stripped)
+		free(buf_copy_stripped);
+	return ret;
+}
+
+static void
+get_kernel_driver_type(struct rte_pci_device *dev __rte_unused)
+{
+	/*
+	 * If another kernel driver is supported the relevant checking
+	 * functions should be here
+	 */
+	dev->kdrv = RTE_KDRV_NONE;
+}
+
+static int
+pci_scan_one(HDEVINFO hDevInfo, PSP_DEVINFO_DATA pDeviceInfoData)
+{
+	struct rte_pci_device *dev;
+	int    ret = -1;
+
+	dev = malloc(sizeof(struct rte_pci_device));
+	if (dev == NULL) {
+		ret = -1;
+		goto end;
+	}
+
+	memset(dev, 0, sizeof(*dev));
+
+	char  strPCIDeviceInfo[PATH_MAX];
+	BOOL  bResult;
+
+	bResult = SetupDiGetDeviceRegistryPropertyA(hDevInfo, pDeviceInfoData,
+		SPDRP_LOCATION_INFORMATION, NULL, (BYTE *)&strPCIDeviceInfo,
+		sizeof(strPCIDeviceInfo), NULL);
+
+	/* Some devices don't have location information - simply return 0 */
+	/* Also, if we don't find 'PCI' in the description, we'll skip it */
+	if (!bResult) {
+		ret = (GetLastError() == ERROR_INVALID_DATA) ? ERROR_CONTINUE
+			: -1;
+		goto end;
+	} else if (!strstr(strPCIDeviceInfo, "PCI")) {
+		ret = ERROR_CONTINUE;
+		goto end;
+	}
+
+	struct rte_pci_addr addr;
+
+	if (parse_pci_addr_format((const char *)&strPCIDeviceInfo,
+			sizeof(strPCIDeviceInfo), &addr) != 0) {
+		ret = -1;
+		goto end;
+	}
+
+	dev->addr.domain = addr.domain;
+	dev->addr.bus = addr.bus;
+	dev->addr.devid = addr.devid;
+	dev->addr.function = addr.function;
+
+	/* Retrieve PCI device IDs */
+	bResult = SetupDiGetDeviceRegistryPropertyA(hDevInfo, pDeviceInfoData,
+			SPDRP_HARDWAREID, NULL, (BYTE *)&strPCIDeviceInfo,
+			sizeof(strPCIDeviceInfo), NULL);
+
+	/* parse hardware ID string */
+	uint16_t vendorID, deviceID, subvendorID, subdeviceID = 0;
+	if (parse_pci_hardware_id_format((const char *)&strPCIDeviceInfo,
+		sizeof(strPCIDeviceInfo), &vendorID, &deviceID, &subvendorID,
+		&subdeviceID) != 0) {
+		ret = -1;
+		goto end;
+	}
+
+	dev->id.vendor_id = vendorID;
+	dev->id.device_id = deviceID;
+	dev->id.subsystem_vendor_id = subvendorID;
+	dev->id.subsystem_device_id = subdeviceID;
+
+	dev->max_vfs = 0; /* TODO: get max_vfs */
+
+	pci_name_set(dev);
+
+	get_kernel_driver_type(dev);
+
+	/* parse resources */
+	if (get_device_resource_info(hDevInfo, pDeviceInfoData, dev)
+			!= ERROR_SUCCESS) {
+		/*
+		 * We won't add this device, but we want to continue
+		 * looking forsupported devices
+		 */
+		ret = ERROR_CONTINUE;
+		goto end;
+	}
+
+	/* device is valid, add in list (sorted) */
+	if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
+		rte_pci_add_device(dev);
+	} else {
+		struct rte_pci_device *dev2 = NULL;
+		int ret;
+
+		TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
+			ret = rte_pci_addr_cmp(&dev->addr, &dev2->addr);
+			if (ret > 0) {
+				continue;
+			} else if (ret < 0) {
+				rte_pci_insert_device(dev2, dev);
+			} else { /* already registered */
+				dev2->kdrv = dev->kdrv;
+				dev2->max_vfs = dev->max_vfs;
+				memmove(dev2->mem_resource, dev->mem_resource,
+					sizeof(dev->mem_resource));
+				free(dev);
+			}
+			return 0;
+		}
+		rte_pci_add_device(dev);
+	}
+
+	ret = 0;
+	return ret;
+end:
+	if (dev)
+		free(dev);
+	return ret;
+}
+
 /*
  * Scan the contents of the PCI bus
  * and add all network class devices into the devices list.
@@ -174,5 +478,39 @@ pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused)
 int
 rte_pci_scan(void)
 {
-	return 0;
+	DWORD			DeviceIndex = 0, FoundDevice = 0;
+	HDEVINFO		hDevInfo = NULL;
+	SP_DEVINFO_DATA	DeviceInfoData = { 0 };
+	int				ret = -1;
+
+	hDevInfo = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, NULL, NULL,
+				DIGCF_PRESENT);
+	if (hDevInfo == INVALID_HANDLE_VALUE) {
+		RTE_LOG(ERR, EAL,
+			"Unable to enumerate PCI devices.\n", __func__);
+		goto end;
+	}
+
+	DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+	DeviceIndex = 0;
+
+	while (SetupDiEnumDeviceInfo(hDevInfo, DeviceIndex, &DeviceInfoData)) {
+		DeviceIndex++;
+		ret = pci_scan_one(hDevInfo, &DeviceInfoData);
+		if (ret == ERROR_SUCCESS)
+			FoundDevice++;
+		else if (ret != ERROR_CONTINUE)
+			goto end;
+
+		memset(&DeviceInfoData, 0, sizeof(SP_DEVINFO_DATA));
+		DeviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
+	}
+
+	RTE_LOG(ERR, EAL, "PCI scan found %u devices\n", FoundDevice);
+	ret = (FoundDevice != 0) ? 0 : -1;
+end:
+	if (hDevInfo != INVALID_HANDLE_VALUE)
+		SetupDiDestroyDeviceInfoList(hDevInfo);
+
+	return ret;
 }
diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def
index edbb6b277..7a0468a02 100644
--- a/lib/librte_eal/rte_eal_exports.def
+++ b/lib/librte_eal/rte_eal_exports.def
@@ -18,6 +18,7 @@ EXPORTS
 	rte_eal_tailq_lookup
 	rte_eal_tailq_register
 	rte_eal_using_phys_addrs
+	rte_find_numerical_value
 	rte_free
 	rte_log
 	rte_malloc
diff --git a/lib/librte_eal/windows/include/rte_windows.h b/lib/librte_eal/windows/include/rte_windows.h
index 899ed7d87..725ac4f9b 100644
--- a/lib/librte_eal/windows/include/rte_windows.h
+++ b/lib/librte_eal/windows/include/rte_windows.h
@@ -25,6 +25,7 @@
 #include <psapi.h>
 #include <setupapi.h>
 #include <winioctl.h>
+#include <devguid.h>
 
 /* Have GUIDs defined. */
 #ifndef INITGUID
-- 
2.16.1.windows.4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/7] pci: build on Windows
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 2/7] pci: build on Windows talshn
@ 2020-04-28 23:52   ` Dmitry Kozlyuk
  0 siblings, 0 replies; 11+ messages in thread
From: Dmitry Kozlyuk @ 2020-04-28 23:52 UTC (permalink / raw)
  To: talshn
  Cc: dev, thomas, pallavi.kadam, david.marchand, grive, ranjit.menon,
	navasile

This patch misses two things:

1. Documentation on pci_map_resource() mentions MAP_FAILED,
   while rte_mem_map() returns NULL on failure.

2. Code in drivers/bus/pci/linux passes MAP_FIXED to pci_map_resource(),
   which should be changed to corresponding RTE_MAP_FORCE_ADDRESS flag
   (it is renamed in v4 of MM patch series).

On 2020-04-28 12:11 GMT+0300 talshn@mellanox.com wrote:
[snip]
> +	if (mapaddr == NULL) {
>  		RTE_LOG(ERR, EAL,
>  			"%s(): cannot mmap(%d, %p, 0x%zx, 0x%llx): %s (%p)\n",
>  			__func__, fd, requested_addr, size,
> @@ -160,7 +160,7 @@ pci_unmap_resource(void *requested_addr, size_t size)
>  		return;
>  
>  	/* Unmap the PCI memory resource of device */
> -	if (munmap(requested_addr, size)) {
> +	if (rte_mem_unmap(requested_addr, size)) {
>  		RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, %#zx): %s\n",
>  			__func__, requested_addr, size,
>  			strerror(errno));

Logging can be removed here if ERR level is not a requirement: rte_mem_map()
and rte_mem_unmap() already log OS errors on debug level.

-- 
Dmitry Kozlyuk

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v2 7/7] bus/pci: support Windows with bifurcated drivers
  2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 7/7] bus/pci: support Windows with bifurcated drivers talshn
@ 2020-04-29  0:01   ` Dmitry Kozlyuk
  2020-05-03 11:53     ` Tal Shnaiderman
  0 siblings, 1 reply; 11+ messages in thread
From: Dmitry Kozlyuk @ 2020-04-29  0:01 UTC (permalink / raw)
  To: talshn
  Cc: dev, thomas, pallavi.kadam, david.marchand, grive, ranjit.menon,
	navasile

On 2020-04-28 12:11 GMT+0300 talshn@mellanox.com wrote:
[snip]
> +	switch (dev->kdrv) {
> +	case RTE_KDRV_NONE:
> +		/* Get NUMA node using DEVPKEY_Device_Numa_Node */
> +		bResult = SetupDiGetDevicePropertyW(hDevInfo, pDeviceInfoData,
> +			&DEVPKEY_Device_Numa_Node, &uPropertyType,
> +			(BYTE *)&uNumaNode, sizeof(uNumaNode), NULL, 0);
> +		if (!bResult) {
> +			ret = GetLastError();
> +			goto end;
> +		}
> +		dev->device.numa_node = uNumaNode;

Note: NUMA node != socket ID, but this field is used as socket ID by PMDs.
I suggest adding Windows-only EAL API to do the translation.

[snip]
> +	/* We now have the various hw IDs in tokens in the str[] array */
> +	/* Isolate the numerical IDs - '_' as the delimiter */
> +	if (parse_hardware_ids(str[0], strlen(str[0]), vendorID, NULL))
> +		goto end;
> +
> +	if (parse_hardware_ids(str[1], strlen(str[1]), deviceID, NULL))
> +		goto end;
> +
> +	if (parse_hardware_ids(str[2], strlen(str[2]), subdeviceID,
> +		subvendorID)) {
> +		goto end;
> +	}

You could avoid hand-written string parsing by using sscanf(), because
hardware ID formats are fixed, limited, and documented:

	https://docs.microsoft.com/en-us/windows-hardware/drivers/install/identifiers-for-pci-devices

[snip]
> +
> +	bResult = SetupDiGetDeviceRegistryPropertyA(hDevInfo, pDeviceInfoData,
> +		SPDRP_LOCATION_INFORMATION, NULL, (BYTE *)&strPCIDeviceInfo,
> +		sizeof(strPCIDeviceInfo), NULL);

> +
> +	/* Some devices don't have location information - simply return 0 */
> +	/* Also, if we don't find 'PCI' in the description, we'll skip it */
> +	if (!bResult) {
> +		ret = (GetLastError() == ERROR_INVALID_DATA) ? ERROR_CONTINUE
> +			: -1;
> +		goto end;
> +	} else if (!strstr(strPCIDeviceInfo, "PCI")) {
> +		ret = ERROR_CONTINUE;
> +		goto end;
> +	}

You could get PCI address without parsing strings with SPDRP_BUSNUMBER and
SPDRP_ADDRESS.

> +
> +	struct rte_pci_addr addr;
> +
> +	if (parse_pci_addr_format((const char *)&strPCIDeviceInfo,
> +			sizeof(strPCIDeviceInfo), &addr) != 0) {
> +		ret = -1;
> +		goto end;
> +	}
> +
> +	dev->addr.domain = addr.domain;
> +	dev->addr.bus = addr.bus;
> +	dev->addr.devid = addr.devid;
> +	dev->addr.function = addr.function;

Why not dev->addr = addr?

[snip]
> diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def
> index edbb6b277..7a0468a02 100644
> --- a/lib/librte_eal/rte_eal_exports.def
> +++ b/lib/librte_eal/rte_eal_exports.def
> @@ -18,6 +18,7 @@ EXPORTS
>  	rte_eal_tailq_lookup
>  	rte_eal_tailq_register
>  	rte_eal_using_phys_addrs
> +	rte_find_numerical_value
>  	rte_free
>  	rte_log
>  	rte_malloc

This belongs to the patch that added the API, doesn't it?

-- 
Dmitry Kozlyuk

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [dpdk-dev] [PATCH v2 7/7] bus/pci: support Windows with bifurcated drivers
  2020-04-29  0:01   ` Dmitry Kozlyuk
@ 2020-05-03 11:53     ` Tal Shnaiderman
  0 siblings, 0 replies; 11+ messages in thread
From: Tal Shnaiderman @ 2020-05-03 11:53 UTC (permalink / raw)
  To: Dmitry Kozlyuk
  Cc: dev, Thomas Monjalon, pallavi.kadam, david.marchand, grive,
	ranjit.menon, navasile

> Subject: Re: [PATCH v2 7/7] bus/pci: support Windows with bifurcated
> drivers
> 
> On 2020-04-28 12:11 GMT+0300 talshn@mellanox.com wrote:
> [snip]
> > +	switch (dev->kdrv) {
> > +	case RTE_KDRV_NONE:
> > +		/* Get NUMA node using DEVPKEY_Device_Numa_Node */
> > +		bResult = SetupDiGetDevicePropertyW(hDevInfo,
> pDeviceInfoData,
> > +			&DEVPKEY_Device_Numa_Node, &uPropertyType,
> > +			(BYTE *)&uNumaNode, sizeof(uNumaNode), NULL,
> 0);
> > +		if (!bResult) {
> > +			ret = GetLastError();
> > +			goto end;
> > +		}
> > +		dev->device.numa_node = uNumaNode;
> 
> Note: NUMA node != socket ID, but this field is used as socket ID by PMDs.
> I suggest adding Windows-only EAL API to do the translation.

Thank you for the review and notes Dmitry, will apply in v3.

Regarding numa node and socket id, AFAIK in x86 processors numa node == socket id
In other processors that is not the case but of the current Windows support of DPDK the
Implementation above should be sufficient.

> [snip]


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-03 11:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-28  9:11 [dpdk-dev] [PATCH v2 0/7] Windows bus/pci support talshn
2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 1/7] eal: move OS common functions to single file talshn
2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 2/7] pci: build on Windows talshn
2020-04-28 23:52   ` Dmitry Kozlyuk
2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 3/7] eal: add function finding integer in a string talshn
2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 4/7] drivers: ignore pmdinfogen generation for Windows talshn
2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 5/7] drivers: fix incorrect meson import folder " talshn
2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 6/7] bus/pci: introduce Windows support with stubs talshn
2020-04-28  9:11 ` [dpdk-dev] [PATCH v2 7/7] bus/pci: support Windows with bifurcated drivers talshn
2020-04-29  0:01   ` Dmitry Kozlyuk
2020-05-03 11:53     ` Tal Shnaiderman

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).