From 936726f8473ecf5381c363eed1837683bd381f5d Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Thu, 22 Sep 2022 01:04:36 +0000 Subject: [PATCH] env_dpdk: add dpdk_pci_init() This checks the current version to make sure we have a dpdk_fn_table that supports it. This is easy for now, since the DPDK PCI API is public. Moving forward, DPDK 22.11 will likely make these APIs private, requiring us to carry header file copies for different DPDK versions so that we can not only build against DPDK but also use the correct data strucures and APIs to interact with those private DPDK interfaces. We will also need to consider minor (i.e. stable or point) releases since they could technically change PCI ABI as well - the current year + month checks won't be sufficient. Signed-off-by: Jim Harris Change-Id: Ic9f41d9d13778f3d078b20b08da48d8d16362b11 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14637 Reviewed-by: Ben Walker Reviewed-by: Changpeng Liu Reviewed-by: Aleksey Marchuk Tested-by: SPDK CI Jenkins --- lib/env_dpdk/pci.c | 6 ++++++ lib/env_dpdk/pci_dpdk.c | 27 ++++++++++++++++++++++++++- lib/env_dpdk/pci_dpdk.h | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/env_dpdk/pci.c b/lib/env_dpdk/pci.c index fb206dcdf..71c0d8fc3 100644 --- a/lib/env_dpdk/pci.c +++ b/lib/env_dpdk/pci.c @@ -300,6 +300,12 @@ int pci_env_init(void) { struct spdk_pci_driver *driver; + int rc; + + rc = dpdk_pci_init(); + if (rc) { + return rc; + } TAILQ_FOREACH(driver, &g_pci_drivers, tailq) { dpdk_pci_driver_register(driver, pci_device_init, pci_device_fini); diff --git a/lib/env_dpdk/pci_dpdk.c b/lib/env_dpdk/pci_dpdk.c index 8c286b839..b14b1315b 100644 --- a/lib/env_dpdk/pci_dpdk.c +++ b/lib/env_dpdk/pci_dpdk.c @@ -6,10 +6,35 @@ #include #include #include "pci_dpdk.h" +#include "spdk/log.h" extern struct dpdk_fn_table fn_table_2207; -static struct dpdk_fn_table *g_dpdk_fn_table = &fn_table_2207; +static struct dpdk_fn_table *g_dpdk_fn_table; + +int +dpdk_pci_init(void) +{ + uint32_t year = rte_version_year(); + uint32_t month = rte_version_month(); + uint32_t minor = rte_version_minor(); + + /* Anything 23.x or higher is not supported. */ + if (year > 22) { + SPDK_ERRLOG("DPDK version %d.%02d.%d not supported.\n", year, month, minor); + return -EINVAL; + } + + /* Anything greater than 22.07 is not supported. */ + if (year == 22 && month > 7) { + SPDK_ERRLOG("DPDK version %d.%02d.%d not supported.\n", year, month, minor); + return -EINVAL; + } + + /* Everything else we use the 22.07 implementation. */ + g_dpdk_fn_table = &fn_table_2207; + return 0; +} uint64_t dpdk_pci_device_vtophys(struct rte_pci_device *dev, uint64_t vaddr) diff --git a/lib/env_dpdk/pci_dpdk.h b/lib/env_dpdk/pci_dpdk.h index b939bb61f..414ea6709 100644 --- a/lib/env_dpdk/pci_dpdk.h +++ b/lib/env_dpdk/pci_dpdk.h @@ -50,6 +50,8 @@ struct dpdk_fn_table { bool (*device_scan_allowed)(struct rte_device *dev); }; +int dpdk_pci_init(void); + uint64_t dpdk_pci_device_vtophys(struct rte_pci_device *dev, uint64_t vaddr); const char *dpdk_pci_device_get_name(struct rte_pci_device *); struct rte_devargs *dpdk_pci_device_get_devargs(struct rte_pci_device *);