From: talshn@mellanox.com To: dev@dpdk.org Cc: thomas@monjalon.net, pallavi.kadam@intel.com, dmitry.kozliuk@gmail.com, david.marchand@redhat.com, grive@u256.net, ranjit.menon@intel.com, navasile@linux.microsoft.com, harini.ramakrishnan@microsoft.com, ocardona@microsoft.com, anatoly.burakov@intel.com, fady@mellanox.com, bruce.richardson@intel.com, Tal Shnaiderman <talshn@mellanox.com> Subject: [dpdk-dev] [PATCH v10 09/10] bus/pci: support Windows with bifurcated drivers Date: Mon, 29 Jun 2020 15:37:40 +0300 Message-ID: <20200629123741.20716-10-talshn@mellanox.com> (raw) In-Reply-To: <20200629123741.20716-1-talshn@mellanox.com> 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. Uses SPDRP_BUSNUMBER and SPDRP_BUSNUMBER to get the BDF. scanning currently supports types RTE_KDRV_NONE. Signed-off-by: Tal Shnaiderman <talshn@mellanox.com> --- drivers/bus/pci/windows/pci.c | 263 ++++++++++++++++++++++++++- lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_eal/windows/include/rte_windows.h | 1 + 3 files changed, 261 insertions(+), 4 deletions(-) diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c index b1d34ae11c..489aa7902a 100644 --- a/drivers/bus/pci/windows/pci.c +++ b/drivers/bus/pci/windows/pci.c @@ -1,14 +1,27 @@ /* 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 <rte_eal.h> #include "private.h" +#include <devpkey.h> + +#ifdef RTE_TOOLCHAIN_GCC +#include <devpropdef.h> +DEFINE_DEVPROPKEY(DEVPKEY_Device_Numa_Node, 0x540b947e, 0x8b40, 0x45bc, + 0xa8, 0xa2, 0x6a, 0x0b, 0x89, 0x4c, 0xbd, 0xa2, 3); +#endif + +/* + * 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 */ @@ -146,7 +159,6 @@ rte_pci_ioport_write(struct rte_pci_ioport *p __rte_unused, */ } - /* remap the PCI resource of a PCI device in anonymous virtual memory */ int pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused) @@ -158,6 +170,210 @@ pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused) */ return -1; } + +static int +get_device_pci_address(HDEVINFO dev_info, + PSP_DEVINFO_DATA device_info_data, struct rte_pci_addr *addr) +{ + BOOL res; + ULONG bus_num, dev_and_func; + + res = SetupDiGetDeviceRegistryProperty(dev_info, device_info_data, + SPDRP_BUSNUMBER, NULL, (PBYTE)&bus_num, sizeof(bus_num), NULL); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDeviceRegistryProperty(SPDRP_BUSNUMBER)"); + return -1; + } + + res = SetupDiGetDeviceRegistryProperty(dev_info, device_info_data, + SPDRP_ADDRESS, NULL, (PBYTE)&dev_and_func, sizeof(dev_and_func), + NULL); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDeviceRegistryProperty(SPDRP_ADDRESS)"); + return -1; + } + + addr->domain = 0; + addr->bus = bus_num; + addr->devid = dev_and_func >> 16; + addr->function = dev_and_func & 0xffff; + return 0; +} + +static int +get_device_resource_info(HDEVINFO dev_info, + PSP_DEVINFO_DATA dev_info_data, struct rte_pci_device *dev) +{ + DEVPROPTYPE property_type; + DWORD numa_node; + BOOL res; + + switch (dev->kdrv) { + case RTE_KDRV_NONE: + /* Get NUMA node using DEVPKEY_Device_Numa_Node */ + res = SetupDiGetDevicePropertyW(dev_info, dev_info_data, + &DEVPKEY_Device_Numa_Node, &property_type, + (BYTE *)&numa_node, sizeof(numa_node), NULL, 0); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDevicePropertyW" + "(DEVPKEY_Device_Numa_Node)"); + return -1; + } + dev->device.numa_node = numa_node; + /* 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: + /* kernel driver type is unsupported */ + RTE_LOG(DEBUG, EAL, + "Kernel driver type for PCI device " PCI_PRI_FMT "," + " is unsupported", + dev->addr.domain, dev->addr.bus, + dev->addr.devid, dev->addr.function); + return -1; + } + + return ERROR_SUCCESS; +} + +/* + * get string that contains the list of hardware IDs for a device + */ +static int +get_pci_hardware_id(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data, + char *pci_device_info, size_t pci_device_info_len) +{ + BOOL res; + + /* Retrieve PCI device IDs */ + res = SetupDiGetDeviceRegistryPropertyA(dev_info, device_info_data, + SPDRP_HARDWAREID, NULL, (BYTE *)pci_device_info, + pci_device_info_len, NULL); + if (!res) { + RTE_LOG_WIN32_ERR( + "SetupDiGetDeviceRegistryPropertyA(SPDRP_HARDWAREID)"); + return -1; + } + + return 0; +} + +/* + * parse the SPDRP_HARDWAREID output and assign to rte_pci_id + */ +static int +parse_pci_hardware_id(const char *buf, struct rte_pci_id *pci_id) +{ + int ids = 0; + uint16_t vendor_id, device_id, subvendor_id = 0; + + ids = sscanf_s(buf, "PCI\\VEN_%x&DEV_%x&SUBSYS_%x", &vendor_id, + &device_id, &subvendor_id); + if (ids != 3) + return -1; + + pci_id->vendor_id = vendor_id; + pci_id->device_id = device_id; + pci_id->subsystem_vendor_id = subvendor_id >> 16; + pci_id->subsystem_device_id = subvendor_id & 0xffff; + return 0; +} + +static void +get_kernel_driver_type(struct rte_pci_device *dev) +{ + /* + * If another kernel driver is supported the relevant checking + * functions should be here + */ + dev->kdrv = RTE_KDRV_NONE; +} + +static int +pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data) +{ + struct rte_pci_device *dev; + int ret = -1; + char pci_device_info[PATH_MAX]; + struct rte_pci_addr addr; + struct rte_pci_id pci_id; + + dev = malloc(sizeof(*dev)); + if (dev == NULL) + goto end; + + memset(dev, 0, sizeof(*dev)); + + ret = get_pci_hardware_id(dev_info, device_info_data, + pci_device_info, PATH_MAX); + if (ret != 0) + goto end; + + ret = parse_pci_hardware_id((const char *)&pci_device_info, &pci_id); + if (ret != 0) { + /* + * We won't add this device, but we want to continue + * looking for supported devices + */ + ret = ERROR_CONTINUE; + goto end; + } + + ret = get_device_pci_address(dev_info, device_info_data, &addr); + if (ret != 0) + goto end; + + dev->addr = addr; + dev->id = pci_id; + dev->max_vfs = 0; /* TODO: get max_vfs */ + + pci_name_set(dev); + + get_kernel_driver_type(dev); + + /* get resources */ + if (get_device_resource_info(dev_info, device_info_data, dev) + != ERROR_SUCCESS) { + 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); + } + + return 0; +end: + if (dev) + free(dev); + return ret; +} + /* * Scan the contents of the PCI bus * and add all network class devices into the devices list. @@ -165,5 +381,44 @@ pci_uio_remap_resource(struct rte_pci_device *dev __rte_unused) int rte_pci_scan(void) { - return 0; + int ret = -1; + DWORD device_index = 0, found_device = 0; + HDEVINFO dev_info; + SP_DEVINFO_DATA device_info_data; + + /* for debug purposes, PCI can be disabled */ + if (!rte_eal_has_pci()) + return 0; + + dev_info = SetupDiGetClassDevs(&GUID_DEVCLASS_NET, TEXT("PCI"), NULL, + DIGCF_PRESENT); + if (dev_info == INVALID_HANDLE_VALUE) { + RTE_LOG_WIN32_ERR("SetupDiGetClassDevs(pci_scan)"); + RTE_LOG(ERR, EAL, "Unable to enumerate PCI devices.\n"); + goto end; + } + + device_info_data.cbSize = sizeof(SP_DEVINFO_DATA); + device_index = 0; + + while (SetupDiEnumDeviceInfo(dev_info, device_index, + &device_info_data)) { + device_index++; + ret = pci_scan_one(dev_info, &device_info_data); + if (ret == ERROR_SUCCESS) + found_device++; + else if (ret != ERROR_CONTINUE) + goto end; + + memset(&device_info_data, 0, sizeof(SP_DEVINFO_DATA)); + device_info_data.cbSize = sizeof(SP_DEVINFO_DATA); + } + + RTE_LOG(DEBUG, EAL, "PCI scan found %lu devices\n", found_device); + ret = 0; +end: + if (dev_info != INVALID_HANDLE_VALUE) + SetupDiDestroyDeviceInfoList(dev_info); + + return ret; } diff --git a/lib/librte_eal/rte_eal_exports.def b/lib/librte_eal/rte_eal_exports.def index 919a92fba9..374e654264 100644 --- a/lib/librte_eal/rte_eal_exports.def +++ b/lib/librte_eal/rte_eal_exports.def @@ -9,6 +9,7 @@ EXPORTS rte_devargs_remove rte_eal_get_configuration rte_eal_has_hugepages + rte_eal_has_pci rte_eal_init rte_eal_iova_mode rte_eal_mp_remote_launch diff --git a/lib/librte_eal/windows/include/rte_windows.h b/lib/librte_eal/windows/include/rte_windows.h index 899ed7d874..725ac4f9b2 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
next prev parent reply other threads:[~2020-06-29 12:39 UTC|newest] Thread overview: 92+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-06-09 10:31 [dpdk-dev] [PATCH v5 0/8] Windows bus/pci support talshn 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 1/8] eal: move OS common functions to single file talshn 2020-06-16 8:46 ` David Marchand 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 0/9] Windows bus/pci support talshn 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 1/9] eal: move OS common functions to single file talshn 2020-06-20 19:01 ` Dmitry Kozlyuk 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 0/9] Windows bus/pci support talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 1/9] eal: move OS common functions to single file talshn 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 0/9] Windows bus/pci support talshn 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 1/9] eal: move OS common functions to single file talshn 2020-06-22 14:54 ` Thomas Monjalon 2020-06-23 6:45 ` Tal Shnaiderman 2020-06-23 7:16 ` Thomas Monjalon 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 00/10] Windows bus/pci support talshn 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 01/10] eal: move OS common config objects talshn 2020-06-25 14:18 ` Thomas Monjalon 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 02/10] eal: move OS common options functions talshn 2020-06-25 14:29 ` Thomas Monjalon 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 03/10] pci: use OS generic memory mapping functions talshn 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 04/10] pci: build on Windows talshn 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 05/10] pci: fix format warning " talshn 2020-06-25 12:54 ` Thomas Monjalon 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 06/10] drivers: ignore pmdinfogen generation for Windows talshn 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 07/10] drivers: fix incorrect meson import folder " talshn 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 08/10] bus/pci: introduce Windows support with stubs talshn 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 09/10] bus/pci: support Windows with bifurcated drivers talshn 2020-06-27 1:46 ` Narcisa Ana Maria Vasile 2020-06-28 12:10 ` Tal Shnaiderman 2020-06-24 8:28 ` [dpdk-dev] [PATCH v9 10/10] build: generate version.map file for MinGW on Windows talshn 2020-06-27 1:54 ` [dpdk-dev] [PATCH v9 00/10] Windows bus/pci support Narcisa Ana Maria Vasile 2020-06-28 12:32 ` Tal Shnaiderman 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 " talshn 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 01/10] eal: move OS common config objects talshn 2020-06-29 15:36 ` Tal Shnaiderman 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 02/10] eal: move OS common options functions talshn 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 03/10] pci: use OS generic memory mapping functions talshn 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 04/10] pci: build on Windows talshn 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 05/10] pci: fix format warning " talshn 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 06/10] drivers: ignore pmdinfogen generation for Windows talshn 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 07/10] drivers: fix incorrect meson import folder " talshn 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 08/10] bus/pci: introduce Windows support with stubs talshn 2020-06-29 20:40 ` Thomas Monjalon 2020-06-29 12:37 ` talshn [this message] 2020-06-29 12:37 ` [dpdk-dev] [PATCH v10 10/10] build: generate version.map file for MinGW on Windows talshn 2020-06-29 22:07 ` [dpdk-dev] [PATCH v10 00/10] Windows bus/pci support Thomas Monjalon 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 2/9] pci: use OS generic memory mapping functions talshn 2020-06-22 21:54 ` Dmitry Kozlyuk 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 3/9] pci: build on Windows talshn 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 4/9] pci: fix format warning " talshn 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 5/9] drivers: ignore pmdinfogen generation for Windows talshn 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 6/9] drivers: fix incorrect meson import folder " talshn 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 7/9] bus/pci: introduce Windows support with stubs talshn 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 8/9] bus/pci: support Windows with bifurcated drivers talshn 2020-06-23 23:28 ` Dmitry Kozlyuk 2020-06-24 8:02 ` Tal Shnaiderman 2020-06-22 7:55 ` [dpdk-dev] [PATCH v8 9/9] build: generate version.map file for MinGW on Windows talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 2/9] pci: use OS generic memory mapping functions talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 3/9] pci: build on Windows talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 4/9] pci: fix format warning " talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 5/9] drivers: ignore pmdinfogen generation for Windows talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 6/9] drivers: fix incorrect meson import folder " talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 7/9] bus/pci: introduce Windows support with stubs talshn 2020-06-21 11:23 ` Fady Bader 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 8/9] bus/pci: support Windows with bifurcated drivers talshn 2020-06-21 10:26 ` [dpdk-dev] [PATCH v7 9/9] build: generate version.map file for MinGW on Windows talshn 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 2/9] pci: use OS generic memory mapping functions talshn 2020-06-18 22:44 ` Dmitry Kozlyuk 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 3/9] pci: build on Windows talshn 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 4/9] pci: fix format warning " talshn 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 5/9] drivers: ignore pmdinfogen generation for Windows talshn 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 6/9] drivers: fix incorrect meson import folder " talshn 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 7/9] bus/pci: introduce Windows support with stubs talshn 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 8/9] bus/pci: support Windows with bifurcated drivers talshn 2020-06-18 22:40 ` Dmitry Kozlyuk 2020-06-18 21:15 ` [dpdk-dev] [PATCH v6 9/9] build: generate version.map file for MingW on Windows talshn 2020-06-18 23:13 ` Dmitry Kozlyuk 2020-06-21 6:36 ` Tal Shnaiderman 2020-06-20 18:54 ` Dmitry Kozlyuk 2020-06-21 5:49 ` Tal Shnaiderman 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 2/8] pci: use OS generic memory mapping functions talshn 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 3/8] pci: build on Windows talshn 2020-06-16 8:22 ` Thomas Monjalon 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 4/8] pci: fix format warning " talshn 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 5/8] drivers: ignore pmdinfogen generation for Windows talshn 2020-06-17 20:39 ` Dmitry Kozlyuk 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 6/8] drivers: fix incorrect meson import folder " talshn 2020-06-16 8:29 ` Thomas Monjalon 2020-06-16 9:17 ` Bruce Richardson 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 7/8] bus/pci: introduce Windows support with stubs talshn 2020-06-17 20:29 ` Dmitry Kozlyuk 2020-06-09 10:31 ` [dpdk-dev] [PATCH v5 8/8] bus/pci: support Windows with bifurcated drivers talshn 2020-06-17 20:28 ` Dmitry Kozlyuk
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=20200629123741.20716-10-talshn@mellanox.com \ --to=talshn@mellanox.com \ --cc=anatoly.burakov@intel.com \ --cc=bruce.richardson@intel.com \ --cc=david.marchand@redhat.com \ --cc=dev@dpdk.org \ --cc=dmitry.kozliuk@gmail.com \ --cc=fady@mellanox.com \ --cc=grive@u256.net \ --cc=harini.ramakrishnan@microsoft.com \ --cc=navasile@linux.microsoft.com \ --cc=ocardona@microsoft.com \ --cc=pallavi.kadam@intel.com \ --cc=ranjit.menon@intel.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
DPDK patches and discussions This inbox may be cloned and mirrored by anyone: git clone --mirror https://inbox.dpdk.org/dev/0 dev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 dev dev/ https://inbox.dpdk.org/dev \ dev@dpdk.org public-inbox-index dev Example config snippet for mirrors. Newsgroup available over NNTP: nntp://inbox.dpdk.org/inbox.dpdk.dev AGPL code for this site: git clone https://public-inbox.org/public-inbox.git