* [PATCH v2 10/23] bus: consolidate device iteration
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Parav Pandit, Xueming Li,
Nipun Gupta, Nikhil Agarwal, Hemant Agrawal, Sachin Saxena,
Chenbo Xia, Tomasz Duszynski, Chengwen Feng, Andrew Rybchenko
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
Many buses (auxiliary, cdx, dpaa, fslmc, platform, uacce, vdev...) had
nearly identical dev_iterate implementations using name-based matching:
- Parse kvargs with "name" parameter
- Match device name via strcmp
- Call rte_bus_find_device()
Extend bus device iterator callback and introduce
rte_bus_generic_dev_iterate() generic helper in EAL.
Only the PCI bus is left with its matching on PCI address criteria.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/auxiliary/auxiliary_common.c | 2 +-
drivers/bus/auxiliary/auxiliary_params.c | 63 -----------------------
drivers/bus/auxiliary/meson.build | 5 +-
drivers/bus/auxiliary/private.h | 6 ---
drivers/bus/cdx/cdx.c | 52 +------------------
drivers/bus/dpaa/dpaa_bus.c | 46 +----------------
drivers/bus/fslmc/fslmc_bus.c | 46 +----------------
drivers/bus/pci/pci_params.c | 3 +-
drivers/bus/pci/private.h | 6 ++-
drivers/bus/platform/meson.build | 5 +-
drivers/bus/platform/platform.c | 2 +-
drivers/bus/platform/platform_params.c | 65 ------------------------
drivers/bus/platform/private.h | 7 ---
drivers/bus/uacce/uacce.c | 48 +----------------
drivers/bus/vdev/meson.build | 5 +-
drivers/bus/vdev/vdev.c | 20 +++++---
drivers/bus/vdev/vdev_logs.h | 16 ------
drivers/bus/vdev/vdev_params.c | 64 -----------------------
drivers/bus/vdev/vdev_private.h | 29 -----------
lib/eal/common/eal_common_bus.c | 41 +++++++++++++++
lib/eal/common/eal_common_dev.c | 4 +-
lib/eal/include/bus_driver.h | 51 ++++++++++++++++++-
lib/ethdev/rte_ethdev.c | 2 +-
23 files changed, 123 insertions(+), 465 deletions(-)
delete mode 100644 drivers/bus/auxiliary/auxiliary_params.c
delete mode 100644 drivers/bus/platform/platform_params.c
delete mode 100644 drivers/bus/vdev/vdev_logs.h
delete mode 100644 drivers/bus/vdev/vdev_params.c
delete mode 100644 drivers/bus/vdev/vdev_private.h
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index eb0a27cc11..05299db8fe 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -346,7 +346,7 @@ struct rte_auxiliary_bus auxiliary_bus = {
.dma_map = auxiliary_dma_map,
.dma_unmap = auxiliary_dma_unmap,
.get_iommu_class = auxiliary_get_iommu_class,
- .dev_iterate = auxiliary_dev_iterate,
+ .dev_iterate = rte_bus_generic_dev_iterate,
},
};
diff --git a/drivers/bus/auxiliary/auxiliary_params.c b/drivers/bus/auxiliary/auxiliary_params.c
deleted file mode 100644
index 1a76155c67..0000000000
--- a/drivers/bus/auxiliary/auxiliary_params.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2021 NVIDIA Corporation & Affiliates
- */
-
-#include <string.h>
-
-#include <bus_driver.h>
-#include <dev_driver.h>
-#include <rte_errno.h>
-#include <rte_kvargs.h>
-
-#include "private.h"
-
-enum auxiliary_params {
- RTE_AUXILIARY_PARAM_NAME,
-};
-
-static const char * const auxiliary_params_keys[] = {
- [RTE_AUXILIARY_PARAM_NAME] = "name",
- NULL,
-};
-
-static int
-auxiliary_dev_match(const struct rte_device *dev,
- const void *_kvlist)
-{
- const struct rte_kvargs *kvlist = _kvlist;
- const char *key = auxiliary_params_keys[RTE_AUXILIARY_PARAM_NAME];
- const char *name;
-
- /* no kvlist arg, all devices match */
- if (kvlist == NULL)
- return 0;
-
- /* if key is present in kvlist and does not match, filter device */
- name = rte_kvargs_get(kvlist, key);
- if (name != NULL && strcmp(name, dev->name))
- return -1;
-
- return 0;
-}
-
-void *
-auxiliary_dev_iterate(const void *start,
- const char *str,
- const struct rte_dev_iterator *it __rte_unused)
-{
- struct rte_kvargs *kvargs = NULL;
- struct rte_device *dev;
-
- if (str != NULL) {
- kvargs = rte_kvargs_parse(str, auxiliary_params_keys);
- if (kvargs == NULL) {
- AUXILIARY_LOG(ERR, "cannot parse argument list %s",
- str);
- rte_errno = EINVAL;
- return NULL;
- }
- }
- dev = rte_bus_generic_find_device(&auxiliary_bus.bus, start, auxiliary_dev_match, kvargs);
- rte_kvargs_free(kvargs);
- return dev;
-}
diff --git a/drivers/bus/auxiliary/meson.build b/drivers/bus/auxiliary/meson.build
index 38d2f05d4b..846b714e2a 100644
--- a/drivers/bus/auxiliary/meson.build
+++ b/drivers/bus/auxiliary/meson.build
@@ -2,10 +2,7 @@
# Copyright (c) 2021 NVIDIA Corporation & Affiliates
driver_sdk_headers += files('bus_auxiliary_driver.h')
-sources = files(
- 'auxiliary_common.c',
- 'auxiliary_params.c',
-)
+sources = files('auxiliary_common.c')
if is_linux
cflags += '-DAUXILIARY_OS_SUPPORTED'
sources += files(
diff --git a/drivers/bus/auxiliary/private.h b/drivers/bus/auxiliary/private.h
index 0b3d73a08d..659d798cd6 100644
--- a/drivers/bus/auxiliary/private.h
+++ b/drivers/bus/auxiliary/private.h
@@ -50,10 +50,4 @@ void auxiliary_on_scan(struct rte_auxiliary_device *aux_dev);
bool auxiliary_match(const struct rte_auxiliary_driver *aux_drv,
const struct rte_auxiliary_device *aux_dev);
-/*
- * Iterate over devices, matching any device against the provided string.
- */
-void *auxiliary_dev_iterate(const void *start, const char *str,
- const struct rte_dev_iterator *it);
-
#endif /* BUS_AUXILIARY_PRIVATE_H */
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 45c6e8335d..d6f83e2e80 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -86,15 +86,6 @@
struct rte_cdx_bus rte_cdx_bus;
-enum cdx_params {
- RTE_CDX_PARAM_NAME,
-};
-
-static const char * const cdx_params_keys[] = {
- [RTE_CDX_PARAM_NAME] = "name",
- NULL,
-};
-
static int
cdx_get_kernel_driver_by_path(const char *filename, char *driver_name,
size_t len)
@@ -528,47 +519,6 @@ cdx_get_iommu_class(void)
return RTE_IOVA_VA;
}
-static int
-cdx_dev_match(const struct rte_device *dev,
- const void *_kvlist)
-{
- const struct rte_kvargs *kvlist = _kvlist;
- const char *key = cdx_params_keys[RTE_CDX_PARAM_NAME];
- const char *name;
-
- /* no kvlist arg, all devices match */
- if (kvlist == NULL)
- return 0;
-
- /* if key is present in kvlist and does not match, filter device */
- name = rte_kvargs_get(kvlist, key);
- if (name != NULL && strcmp(name, dev->name))
- return -1;
-
- return 0;
-}
-
-static void *
-cdx_dev_iterate(const void *start,
- const char *str,
- const struct rte_dev_iterator *it __rte_unused)
-{
- struct rte_kvargs *kvargs = NULL;
- struct rte_device *dev;
-
- if (str != NULL) {
- kvargs = rte_kvargs_parse(str, cdx_params_keys);
- if (kvargs == NULL) {
- CDX_BUS_ERR("cannot parse argument list %s", str);
- rte_errno = EINVAL;
- return NULL;
- }
- }
- dev = rte_bus_generic_find_device(&rte_cdx_bus.bus, start, cdx_dev_match, kvargs);
- rte_kvargs_free(kvargs);
- return dev;
-}
-
struct rte_cdx_bus rte_cdx_bus = {
.bus = {
.scan = cdx_scan,
@@ -580,7 +530,7 @@ struct rte_cdx_bus rte_cdx_bus = {
.dma_map = cdx_dma_map,
.dma_unmap = cdx_dma_unmap,
.get_iommu_class = cdx_get_iommu_class,
- .dev_iterate = cdx_dev_iterate,
+ .dev_iterate = rte_bus_generic_dev_iterate,
},
};
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index 0bacc0e9d5..b3a754cbf4 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -845,50 +845,6 @@ dpaa_bus_unplug(struct rte_device *dev __rte_unused)
return 0;
}
-static void *
-dpaa_bus_dev_iterate(const void *start, const char *str,
- const struct rte_dev_iterator *it __rte_unused)
-{
- char *dup, *dev_name = NULL;
- struct rte_device *dev;
-
- if (str == NULL) {
- DPAA_BUS_DEBUG("No device string");
- return NULL;
- }
-
- /* Expectation is that device would be name=device_name */
- if (strncmp(str, "name=", 5) != 0) {
- DPAA_BUS_DEBUG("Invalid device string (%s)", str);
- return NULL;
- }
-
- /* Now that name=device_name format is available, split */
- dup = strdup(str);
- if (dup == NULL) {
- DPAA_BUS_DEBUG("Dup string (%s) failed!", str);
- return NULL;
- }
- dev_name = dup + strlen("name=");
-
- if (start != NULL) {
- dev = TAILQ_NEXT((const struct rte_device *)start, next);
- } else {
- dev = TAILQ_FIRST(&rte_dpaa_bus.bus.device_list);
- }
-
- while (dev != NULL) {
- if (strcmp(dev->name, dev_name) == 0) {
- free(dup);
- return dev;
- }
- dev = TAILQ_NEXT(dev, next);
- }
-
- free(dup);
- return NULL;
-}
-
static int
dpaa_bus_cleanup(void)
{
@@ -948,7 +904,7 @@ static struct rte_dpaa_bus rte_dpaa_bus = {
.get_iommu_class = rte_dpaa_get_iommu_class,
.plug = dpaa_bus_plug,
.unplug = dpaa_bus_unplug,
- .dev_iterate = dpaa_bus_dev_iterate,
+ .dev_iterate = rte_bus_generic_dev_iterate,
.cleanup = dpaa_bus_cleanup,
},
.max_push_rxq_num = DPAA_DEFAULT_PUSH_MODE_QUEUE,
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 312145b712..716f0178b5 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -593,50 +593,6 @@ fslmc_bus_unplug(struct rte_device *rte_dev)
return -ENODEV;
}
-static void *
-fslmc_bus_dev_iterate(const void *start, const char *str,
- const struct rte_dev_iterator *it __rte_unused)
-{
- char *dup, *dev_name = NULL;
- struct rte_device *dev;
-
- if (str == NULL) {
- DPAA2_BUS_DEBUG("No device string");
- return NULL;
- }
-
- /* Expectation is that device would be name=device_name */
- if (strncmp(str, "name=", 5) != 0) {
- DPAA2_BUS_DEBUG("Invalid device string (%s)", str);
- return NULL;
- }
-
- /* Now that name=device_name format is available, split */
- dup = strdup(str);
- if (dup == NULL) {
- DPAA2_BUS_DEBUG("Dup string (%s) failed!", str);
- return NULL;
- }
- dev_name = dup + strlen("name=");
-
- if (start != NULL) {
- dev = TAILQ_NEXT(RTE_CAST_PTR(struct rte_device *, start), next);
- } else {
- dev = TAILQ_FIRST(&rte_fslmc_bus.bus.device_list);
- }
-
- while (dev != NULL) {
- if (strcmp(dev->name, dev_name) == 0) {
- free(dup);
- return dev;
- }
- dev = TAILQ_NEXT(dev, next);
- }
-
- free(dup);
- return NULL;
-}
-
struct rte_fslmc_bus rte_fslmc_bus = {
.bus = {
.scan = rte_fslmc_scan,
@@ -648,7 +604,7 @@ struct rte_fslmc_bus rte_fslmc_bus = {
.get_iommu_class = rte_dpaa2_get_iommu_class,
.plug = fslmc_bus_plug,
.unplug = fslmc_bus_unplug,
- .dev_iterate = fslmc_bus_dev_iterate,
+ .dev_iterate = rte_bus_generic_dev_iterate,
},
.device_count = {0},
};
diff --git a/drivers/bus/pci/pci_params.c b/drivers/bus/pci/pci_params.c
index d596c3bba8..e308c85ed2 100644
--- a/drivers/bus/pci/pci_params.c
+++ b/drivers/bus/pci/pci_params.c
@@ -59,7 +59,8 @@ pci_dev_match(const struct rte_device *dev,
}
void *
-rte_pci_dev_iterate(const void *start,
+rte_pci_dev_iterate(const struct rte_bus *bus __rte_unused,
+ const void *start,
const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index 52fa6b0f76..21637882f8 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -258,6 +258,9 @@ rte_pci_get_iommu_class(void);
* matching any device against the provided
* string.
*
+ * @param bus
+ * A pointer to the bus structure.
+ *
* @param start
* Iteration starting point.
*
@@ -272,7 +275,8 @@ rte_pci_get_iommu_class(void);
* NULL otherwise.
*/
void *
-rte_pci_dev_iterate(const void *start,
+rte_pci_dev_iterate(const struct rte_bus *bus,
+ const void *start,
const char *str,
const struct rte_dev_iterator *it);
diff --git a/drivers/bus/platform/meson.build b/drivers/bus/platform/meson.build
index 8633cc4e75..9b1f55c3bb 100644
--- a/drivers/bus/platform/meson.build
+++ b/drivers/bus/platform/meson.build
@@ -11,8 +11,5 @@ endif
require_iova_in_mbuf = false
deps += ['kvargs']
-sources = files(
- 'platform_params.c',
- 'platform.c',
-)
+sources = files('platform.c')
driver_sdk_headers += files('bus_platform_driver.h')
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index c795bd4b9c..636f051049 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -562,7 +562,7 @@ struct rte_platform_bus platform_bus = {
.dma_map = platform_bus_dma_map,
.dma_unmap = platform_bus_dma_unmap,
.get_iommu_class = platform_bus_get_iommu_class,
- .dev_iterate = platform_bus_dev_iterate,
+ .dev_iterate = rte_bus_generic_dev_iterate,
.cleanup = platform_bus_cleanup,
},
};
diff --git a/drivers/bus/platform/platform_params.c b/drivers/bus/platform/platform_params.c
deleted file mode 100644
index f8538a1d84..0000000000
--- a/drivers/bus/platform/platform_params.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(C) 2023 Marvell.
- */
-
-#include <string.h>
-#include <errno.h>
-
-#include <rte_bus.h>
-#include <rte_common.h>
-#include <rte_dev.h>
-#include <rte_errno.h>
-#include <rte_kvargs.h>
-
-#include "bus_platform_driver.h"
-#include "private.h"
-
-enum platform_params {
- RTE_PLATFORM_PARAM_NAME,
-};
-
-static const char * const platform_params_keys[] = {
- [RTE_PLATFORM_PARAM_NAME] = "name",
- NULL
-};
-
-static int
-platform_dev_match(const struct rte_device *dev, const void *_kvlist)
-{
- const char *key = platform_params_keys[RTE_PLATFORM_PARAM_NAME];
- const struct rte_kvargs *kvlist = _kvlist;
- const char *name;
-
- /* no kvlist arg, all devices match */
- if (kvlist == NULL)
- return 0;
-
- /* if key is present in kvlist and does not match, filter device */
- name = rte_kvargs_get(kvlist, key);
- if (name != NULL && strcmp(name, dev->name))
- return -1;
-
- return 0;
-}
-
-void *
-platform_bus_dev_iterate(const void *start, const char *str,
- const struct rte_dev_iterator *it __rte_unused)
-{
- struct rte_kvargs *kvargs = NULL;
- struct rte_device *dev;
-
- if (str != NULL) {
- kvargs = rte_kvargs_parse(str, platform_params_keys);
- if (!kvargs) {
- PLATFORM_LOG_LINE(ERR, "cannot parse argument list %s", str);
- rte_errno = EINVAL;
- return NULL;
- }
- }
-
- dev = rte_bus_generic_find_device(&platform_bus.bus, start, platform_dev_match, kvargs);
- rte_kvargs_free(kvargs);
-
- return dev;
-}
diff --git a/drivers/bus/platform/private.h b/drivers/bus/platform/private.h
index 81a8984052..bf5d75df03 100644
--- a/drivers/bus/platform/private.h
+++ b/drivers/bus/platform/private.h
@@ -28,11 +28,4 @@ extern int platform_bus_logtype;
#define PLATFORM_LOG_LINE(level, ...) \
RTE_LOG_LINE(level, PLATFORM_BUS, __VA_ARGS__)
-/*
- * Iterate registered platform devices and find one that matches provided string.
- */
-void *
-platform_bus_dev_iterate(const void *start, const char *str,
- const struct rte_dev_iterator *it __rte_unused);
-
#endif /* PLATFORM_PRIVATE_H */
diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c
index ef133a6ae7..153ebc5eea 100644
--- a/drivers/bus/uacce/uacce.c
+++ b/drivers/bus/uacce/uacce.c
@@ -44,14 +44,6 @@ struct rte_uacce_bus {
/* Forward declaration of UACCE bus. */
static struct rte_uacce_bus uacce_bus;
-enum uacce_params {
- RTE_UACCE_PARAM_NAME,
-};
-
-static const char *const uacce_params_keys[] = {
- [RTE_UACCE_PARAM_NAME] = "name",
- NULL,
-};
extern int uacce_bus_logtype;
#define RTE_LOGTYPE_UACCE_BUS uacce_bus_logtype
@@ -522,44 +514,6 @@ uacce_parse(const char *name, void *addr)
return ret;
}
-static int
-uacce_dev_match(const struct rte_device *dev, const void *_kvlist)
-{
- const char *key = uacce_params_keys[RTE_UACCE_PARAM_NAME];
- const struct rte_kvargs *kvlist = _kvlist;
- const char *name;
-
- /* no kvlist arg, all devices match. */
- if (kvlist == NULL)
- return 0;
-
- /* if key is present in kvlist and does not match, filter device. */
- name = rte_kvargs_get(kvlist, key);
- if (name != NULL && strcmp(name, dev->name))
- return -1;
-
- return 0;
-}
-
-static void *
-uacce_dev_iterate(const void *start, const char *str,
- const struct rte_dev_iterator *it __rte_unused)
-{
- struct rte_kvargs *kvargs = NULL;
- struct rte_device *dev;
-
- if (str != NULL) {
- kvargs = rte_kvargs_parse(str, uacce_params_keys);
- if (kvargs == NULL) {
- UACCE_BUS_ERR("cannot parse argument list %s", str);
- return NULL;
- }
- }
- dev = rte_bus_generic_find_device(&uacce_bus.bus, start, uacce_dev_match, kvargs);
- rte_kvargs_free(kvargs);
- return dev;
-}
-
RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_avail_queues)
int
rte_uacce_avail_queues(struct rte_uacce_device *dev)
@@ -676,7 +630,7 @@ static struct rte_uacce_bus uacce_bus = {
.unplug = uacce_unplug,
.find_device = rte_bus_generic_find_device,
.parse = uacce_parse,
- .dev_iterate = uacce_dev_iterate,
+ .dev_iterate = rte_bus_generic_dev_iterate,
},
};
diff --git a/drivers/bus/vdev/meson.build b/drivers/bus/vdev/meson.build
index 50f0c8918d..6487b0d672 100644
--- a/drivers/bus/vdev/meson.build
+++ b/drivers/bus/vdev/meson.build
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2017 Intel Corporation
-sources = files(
- 'vdev.c',
- 'vdev_params.c',
-)
+sources = files('vdev.c')
headers = files('rte_bus_vdev.h')
driver_sdk_headers = files('bus_vdev_driver.h')
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 9b88df8bdc..3e610bd780 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -10,12 +10,14 @@
#include <stdbool.h>
#include <sys/queue.h>
+#include <rte_os_shim.h>
#include <eal_export.h>
#include <rte_eal.h>
#include <dev_driver.h>
#include <bus_driver.h>
#include <rte_common.h>
#include <rte_devargs.h>
+#include <rte_log.h>
#include <rte_memory.h>
#include <rte_tailq.h>
#include <rte_spinlock.h>
@@ -23,11 +25,15 @@
#include <rte_errno.h>
#include "bus_vdev_driver.h"
-#include "vdev_logs.h"
-#include "vdev_private.h"
#define VDEV_MP_KEY "bus_vdev_mp"
+int vdev_logtype_bus;
+#define RTE_LOGTYPE_VDEV_BUS vdev_logtype_bus
+
+#define VDEV_LOG(level, ...) \
+ RTE_LOG_LINE_PREFIX(level, VDEV_BUS, "%s(): ", __func__, __VA_ARGS__)
+
/* Forward declare to access virtual bus name */
static struct rte_bus rte_vdev_bus;
@@ -576,9 +582,9 @@ vdev_cleanup(void)
return error;
}
-struct rte_device *
-rte_vdev_find_device(const struct rte_bus *bus __rte_unused, const struct rte_device *start,
- rte_dev_cmp_t cmp, const void *data)
+static struct rte_device *
+vdev_find_device(const struct rte_bus *bus __rte_unused, const struct rte_device *start,
+ rte_dev_cmp_t cmp, const void *data)
{
struct rte_device *dev;
@@ -633,14 +639,14 @@ static struct rte_bus rte_vdev_bus = {
.scan = vdev_scan,
.probe = vdev_probe,
.cleanup = vdev_cleanup,
- .find_device = rte_vdev_find_device,
+ .find_device = vdev_find_device,
.plug = vdev_plug,
.unplug = vdev_unplug,
.parse = vdev_parse,
.dma_map = vdev_dma_map,
.dma_unmap = vdev_dma_unmap,
.get_iommu_class = vdev_get_iommu_class,
- .dev_iterate = rte_vdev_dev_iterate,
+ .dev_iterate = rte_bus_generic_dev_iterate,
};
RTE_REGISTER_BUS(vdev, rte_vdev_bus);
diff --git a/drivers/bus/vdev/vdev_logs.h b/drivers/bus/vdev/vdev_logs.h
deleted file mode 100644
index 38859ae4b7..0000000000
--- a/drivers/bus/vdev/vdev_logs.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright(c) 2017 Intel Corporation
- */
-
-#ifndef _VDEV_LOGS_H_
-#define _VDEV_LOGS_H_
-
-#include <rte_log.h>
-
-extern int vdev_logtype_bus;
-#define RTE_LOGTYPE_VDEV_BUS vdev_logtype_bus
-
-#define VDEV_LOG(level, ...) \
- RTE_LOG_LINE_PREFIX(level, VDEV_BUS, "%s(): ", __func__, __VA_ARGS__)
-
-#endif /* _VDEV_LOGS_H_ */
diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c
deleted file mode 100644
index fedd82b25d..0000000000
--- a/drivers/bus/vdev/vdev_params.c
+++ /dev/null
@@ -1,64 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2018 Gaëtan Rivet
- */
-
-#include <errno.h>
-#include <string.h>
-
-#include <dev_driver.h>
-#include <rte_kvargs.h>
-#include <rte_errno.h>
-
-#include "vdev_logs.h"
-#include "vdev_private.h"
-
-enum vdev_params {
- RTE_VDEV_PARAM_NAME,
- RTE_VDEV_PARAM_MAX,
-};
-
-static const char * const vdev_params_keys[] = {
- [RTE_VDEV_PARAM_NAME] = "name",
- [RTE_VDEV_PARAM_MAX] = NULL,
-};
-
-static int
-vdev_dev_match(const struct rte_device *dev,
- const void *_kvlist)
-{
- const struct rte_kvargs *kvlist = _kvlist;
- const char *key = vdev_params_keys[RTE_VDEV_PARAM_NAME];
- const char *name;
-
- /* no kvlist arg, all devices match */
- if (kvlist == NULL)
- return 0;
-
- /* if key is present in kvlist and does not match, filter device */
- name = rte_kvargs_get(kvlist, key);
- if (name != NULL && strcmp(name, dev->name))
- return -1;
-
- return 0;
-}
-
-void *
-rte_vdev_dev_iterate(const void *start,
- const char *str,
- const struct rte_dev_iterator *it __rte_unused)
-{
- struct rte_kvargs *kvargs = NULL;
- struct rte_device *dev;
-
- if (str != NULL) {
- kvargs = rte_kvargs_parse(str, vdev_params_keys);
- if (kvargs == NULL) {
- VDEV_LOG(ERR, "cannot parse argument list");
- rte_errno = EINVAL;
- return NULL;
- }
- }
- dev = rte_vdev_find_device(NULL, start, vdev_dev_match, kvargs);
- rte_kvargs_free(kvargs);
- return dev;
-}
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
deleted file mode 100644
index ac036693d8..0000000000
--- a/drivers/bus/vdev/vdev_private.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2018 Gaëtan Rivet
- */
-
-#ifndef _VDEV_PRIVATE_H_
-#define _VDEV_PRIVATE_H_
-
-#include <rte_os_shim.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct rte_device *
-rte_vdev_find_device(const struct rte_bus *bus,
- const struct rte_device *start,
- rte_dev_cmp_t cmp,
- const void *data);
-
-void *
-rte_vdev_dev_iterate(const void *start,
- const char *str,
- const struct rte_dev_iterator *it);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _VDEV_PRIVATE_H_ */
diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c
index f81d13e7d0..46a8e68532 100644
--- a/lib/eal/common/eal_common_bus.c
+++ b/lib/eal/common/eal_common_bus.c
@@ -9,6 +9,7 @@
#include <bus_driver.h>
#include <rte_debug.h>
#include <rte_devargs.h>
+#include <rte_kvargs.h>
#include <rte_string_fns.h>
#include <rte_errno.h>
@@ -432,3 +433,43 @@ rte_bus_remove_driver(struct rte_bus *bus, struct rte_driver *driver)
TAILQ_REMOVE(&bus->driver_list, driver, next);
driver->bus = NULL;
}
+
+static int
+bus_dev_match_by_name(const struct rte_device *dev, const void *_kvlist)
+{
+ const struct rte_kvargs *kvlist = _kvlist;
+ const char *name;
+
+ if (kvlist == NULL)
+ return 0;
+
+ name = rte_kvargs_get(kvlist, "name");
+ if (name != NULL && strcmp(name, dev->name))
+ return -1;
+
+ return 0;
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_generic_dev_iterate)
+void *
+rte_bus_generic_dev_iterate(const struct rte_bus *bus,
+ const void *start,
+ const char *str,
+ const struct rte_dev_iterator *it __rte_unused)
+{
+ static const char * const params_keys[] = { "name", NULL };
+ struct rte_kvargs *kvargs = NULL;
+ struct rte_device *dev;
+
+ if (str != NULL) {
+ kvargs = rte_kvargs_parse(str, params_keys);
+ if (kvargs == NULL) {
+ rte_errno = EINVAL;
+ return NULL;
+ }
+ }
+
+ dev = rte_bus_generic_find_device(bus, start, bus_dev_match_by_name, kvargs);
+ rte_kvargs_free(kvargs);
+ return dev;
+}
diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c
index e08a0f9dbc..17e8901546 100644
--- a/lib/eal/common/eal_common_dev.c
+++ b/lib/eal/common/eal_common_dev.c
@@ -756,13 +756,13 @@ bus_next_dev_cmp(const struct rte_bus *bus,
if (rte_errno != 0)
return -1;
if (it->cls_str == NULL) {
- dev = bus->dev_iterate(dev, bus_str, it);
+ dev = bus->dev_iterate(bus, dev, bus_str, it);
goto end;
}
/* cls_str != NULL */
if (dev == NULL) {
next_dev_on_bus:
- dev = bus->dev_iterate(dev, bus_str, it);
+ dev = bus->dev_iterate(bus, dev, bus_str, it);
it->device = dev;
}
if (dev == NULL)
diff --git a/lib/eal/include/bus_driver.h b/lib/eal/include/bus_driver.h
index 31c9586a33..e3e52928f4 100644
--- a/lib/eal/include/bus_driver.h
+++ b/lib/eal/include/bus_driver.h
@@ -262,6 +262,32 @@ struct rte_bus_conf {
*/
typedef enum rte_iova_mode (*rte_bus_get_iommu_class_t)(void);
+/**
+ * Per bus, device iteration function.
+ *
+ * Similar to rte_dev_iterate_t but also pass along the bus pointer.
+ *
+ * @param bus
+ * A pointer to the bus structure.
+ *
+ * @param start
+ * Starting iteration context.
+ *
+ * @param devstr
+ * Device description string.
+ *
+ * @param it
+ * Device iterator.
+ *
+ * @return
+ * The address of the current element matching the device description
+ * string.
+ */
+typedef void *(*rte_bus_dev_iterate_t)(const struct rte_bus *bus,
+ const void *start,
+ const char *devstr,
+ const struct rte_dev_iterator *it);
+
/**
* A structure describing a generic bus.
*/
@@ -280,7 +306,7 @@ struct rte_bus {
rte_dev_dma_unmap_t dma_unmap; /**< DMA unmap for device in the bus */
struct rte_bus_conf conf; /**< Bus configuration */
rte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */
- rte_dev_iterate_t dev_iterate; /**< Device iterator. */
+ rte_bus_dev_iterate_t dev_iterate; /**< Bus device iterator. */
rte_bus_hot_unplug_handler_t hot_unplug_handler;
/**< handle hot-unplug failure on the bus */
rte_bus_sigbus_handler_t sigbus_handler;
@@ -321,6 +347,29 @@ struct rte_devargs *rte_bus_find_devargs(const struct rte_bus *bus, const char *
__rte_internal
bool rte_bus_device_is_ignored(const struct rte_bus *bus, const char *dev_name);
+/**
+ * Generic device iterator for buses using name-based matching.
+ *
+ * This helper implements the standard name-based device iteration pattern
+ * using kvargs parsing. Buses that only support "name" parameter matching
+ * can use this instead of implementing their own dev_iterate function.
+ *
+ * @param bus
+ * A pointer to the bus structure.
+ * @param start
+ * The starting device (NULL to start from the beginning).
+ * @param str
+ * The device filter string (e.g., "name=eth0").
+ *
+ * @return
+ * Pointer to the matching device, or NULL if not found.
+ */
+__rte_internal
+void *rte_bus_generic_dev_iterate(const struct rte_bus *bus,
+ const void *start,
+ const char *str,
+ const struct rte_dev_iterator *it);
+
/**
* Helper for Bus registration.
* The constructor has higher priority than PMD constructors.
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 2edc7a362e..43475bace9 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -313,7 +313,7 @@ rte_eth_iterator_next(struct rte_dev_iterator *iter)
iter->class_device == NULL) {
/* get next rte_device to try. */
iter->device = iter->bus->dev_iterate(
- iter->device, iter->bus_str, iter);
+ iter->bus, iter->device, iter->bus_str, iter);
if (iter->device == NULL)
break; /* no more rte_device candidate */
}
--
2.53.0
^ permalink raw reply related
* [PATCH v2 09/23] bus: consolidate device lookup
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Parav Pandit, Xueming Li,
Nipun Gupta, Nikhil Agarwal, Hemant Agrawal, Sachin Saxena,
Rosen Xu, Chenbo Xia, Tomasz Duszynski, Chengwen Feng, Long Li,
Wei Hu, Kevin Laatz, Chas Williams, Min Hu (Connor), Matan Azrad
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
A majority of bus drivers are repeating the pattern of looping on the
bus device_list and simply passing the device to the cmp callback.
Extend rte_bus_find_device_t so it takes a reference to the bus object
and add rte_bus_generic_find_device() to achieve the same.
Leave the vdev bus alone, as it has an internal locking requirement.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
app/test/test_vdev.c | 6 ++---
drivers/bus/auxiliary/auxiliary_common.c | 21 +---------------
drivers/bus/auxiliary/auxiliary_params.c | 4 +--
drivers/bus/cdx/cdx.c | 25 ++----------------
drivers/bus/dpaa/dpaa_bus.c | 30 +---------------------
drivers/bus/fslmc/fslmc_bus.c | 32 +-----------------------
drivers/bus/ifpga/ifpga_bus.c | 19 +-------------
drivers/bus/pci/pci_common.c | 21 +---------------
drivers/bus/pci/pci_params.c | 4 +--
drivers/bus/platform/platform.c | 22 +---------------
drivers/bus/platform/platform_params.c | 9 +------
drivers/bus/uacce/uacce.c | 26 ++-----------------
drivers/bus/vdev/vdev.c | 4 +--
drivers/bus/vdev/vdev_params.c | 2 +-
drivers/bus/vdev/vdev_private.h | 3 ++-
drivers/bus/vmbus/vmbus_common.c | 21 +---------------
drivers/dma/idxd/idxd_bus.c | 20 +--------------
drivers/net/bonding/rte_eth_bond_args.c | 2 +-
drivers/net/vdev_netvsc/vdev_netvsc.c | 2 +-
drivers/raw/ifpga/ifpga_rawdev.c | 2 +-
lib/eal/common/eal_common_bus.c | 21 +++++++++++++++-
lib/eal/common/eal_common_dev.c | 4 +--
lib/eal/common/hotplug_mp.c | 4 +--
lib/eal/include/bus_driver.h | 24 ++++++++++++++++--
lib/eal/linux/eal_dev.c | 3 +--
25 files changed, 73 insertions(+), 258 deletions(-)
diff --git a/app/test/test_vdev.c b/app/test/test_vdev.c
index 49286194c3..c82d996404 100644
--- a/app/test/test_vdev.c
+++ b/app/test/test_vdev.c
@@ -60,7 +60,7 @@ get_matching_vdev(const char *match_str)
}
}
- dev = vdev_bus->find_device(NULL, cmp_dev_match, kvargs);
+ dev = vdev_bus->find_device(vdev_bus, NULL, cmp_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
@@ -82,7 +82,7 @@ test_vdev_bus(void)
printf("Failed to create vdev net_null_test0\n");
goto fail;
}
- dev0 = vdev_bus->find_device(NULL, cmp_dev_name, "net_null_test0");
+ dev0 = vdev_bus->find_device(vdev_bus, NULL, cmp_dev_name, "net_null_test0");
if (dev0 == NULL) {
printf("Cannot find net_null_test0 vdev\n");
goto fail;
@@ -93,7 +93,7 @@ test_vdev_bus(void)
printf("Failed to create vdev net_null_test1\n");
goto fail;
}
- dev1 = vdev_bus->find_device(NULL, cmp_dev_name, "net_null_test1");
+ dev1 = vdev_bus->find_device(vdev_bus, NULL, cmp_dev_name, "net_null_test1");
if (dev1 == NULL) {
printf("Cannot find net_null_test1 vdev\n");
goto fail;
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index a1a3a747a5..eb0a27cc11 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -251,25 +251,6 @@ rte_auxiliary_unregister(struct rte_auxiliary_driver *driver)
rte_bus_remove_driver(&auxiliary_bus.bus, &driver->driver);
}
-static struct rte_device *
-auxiliary_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
-{
- struct rte_device *dev;
-
- if (start != NULL) {
- dev = TAILQ_NEXT(start, next);
- } else {
- dev = TAILQ_FIRST(&auxiliary_bus.bus.device_list);
- }
- while (dev != NULL) {
- if (cmp(dev, data) == 0)
- return dev;
- dev = TAILQ_NEXT(dev, next);
- }
- return NULL;
-}
-
static int
auxiliary_plug(struct rte_device *dev)
{
@@ -358,7 +339,7 @@ struct rte_auxiliary_bus auxiliary_bus = {
.scan = auxiliary_scan,
.probe = auxiliary_probe,
.cleanup = auxiliary_cleanup,
- .find_device = auxiliary_find_device,
+ .find_device = rte_bus_generic_find_device,
.plug = auxiliary_plug,
.unplug = auxiliary_unplug,
.parse = auxiliary_parse,
diff --git a/drivers/bus/auxiliary/auxiliary_params.c b/drivers/bus/auxiliary/auxiliary_params.c
index e4c7ee0c3b..1a76155c67 100644
--- a/drivers/bus/auxiliary/auxiliary_params.c
+++ b/drivers/bus/auxiliary/auxiliary_params.c
@@ -45,7 +45,6 @@ auxiliary_dev_iterate(const void *start,
const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
- rte_bus_find_device_t find_device;
struct rte_kvargs *kvargs = NULL;
struct rte_device *dev;
@@ -58,8 +57,7 @@ auxiliary_dev_iterate(const void *start,
return NULL;
}
}
- find_device = auxiliary_bus.bus.find_device;
- dev = find_device(start, auxiliary_dev_match, kvargs);
+ dev = rte_bus_generic_find_device(&auxiliary_bus.bus, start, auxiliary_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
}
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index bc221a4d00..45c6e8335d 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -449,25 +449,6 @@ rte_cdx_unregister(struct rte_cdx_driver *driver)
rte_bus_remove_driver(&rte_cdx_bus.bus, &driver->driver);
}
-static struct rte_device *
-cdx_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
-{
- struct rte_device *dev;
-
- if (start != NULL) {
- dev = TAILQ_NEXT(start, next);
- } else {
- dev = TAILQ_FIRST(&rte_cdx_bus.bus.device_list);
- }
- while (dev != NULL) {
- if (cmp(dev, data) == 0)
- return dev;
- dev = TAILQ_NEXT(dev, next);
- }
- return NULL;
-}
-
/*
* If vendor/device ID match, call the remove() function of the
* driver.
@@ -572,7 +553,6 @@ cdx_dev_iterate(const void *start,
const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
- rte_bus_find_device_t find_device;
struct rte_kvargs *kvargs = NULL;
struct rte_device *dev;
@@ -584,8 +564,7 @@ cdx_dev_iterate(const void *start,
return NULL;
}
}
- find_device = rte_cdx_bus.bus.find_device;
- dev = find_device(start, cdx_dev_match, kvargs);
+ dev = rte_bus_generic_find_device(&rte_cdx_bus.bus, start, cdx_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
}
@@ -594,7 +573,7 @@ struct rte_cdx_bus rte_cdx_bus = {
.bus = {
.scan = cdx_scan,
.probe = cdx_probe,
- .find_device = cdx_find_device,
+ .find_device = rte_bus_generic_find_device,
.plug = cdx_plug,
.unplug = cdx_unplug,
.parse = cdx_parse,
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index 8305f8cb23..0bacc0e9d5 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -818,34 +818,6 @@ rte_dpaa_bus_probe(void)
return 0;
}
-static struct rte_device *
-rte_dpaa_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
-{
- struct rte_device *dev;
-
- /* find_device is called with 'data' as an opaque object - just call
- * cmp with this and each device object on bus.
- */
-
- if (start != NULL) {
- dev = TAILQ_NEXT(start, next);
- } else {
- dev = TAILQ_FIRST(&rte_dpaa_bus.bus.device_list);
- }
-
- while (dev != NULL) {
- if (cmp(dev, data) == 0) {
- DPAA_BUS_DEBUG("Found dev=(%s)", dev->name);
- return dev;
- }
- dev = TAILQ_NEXT(dev, next);
- }
-
- DPAA_BUS_DEBUG("Unable to find any device");
- return NULL;
-}
-
/*
* Get iommu class of DPAA2 devices on the bus.
*/
@@ -972,7 +944,7 @@ static struct rte_dpaa_bus rte_dpaa_bus = {
.probe = rte_dpaa_bus_probe,
.parse = rte_dpaa_bus_parse,
.dev_compare = dpaa_bus_dev_compare,
- .find_device = rte_dpaa_find_device,
+ .find_device = rte_bus_generic_find_device,
.get_iommu_class = rte_dpaa_get_iommu_class,
.plug = dpaa_bus_plug,
.unplug = dpaa_bus_unplug,
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 3e7f03375a..312145b712 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -479,36 +479,6 @@ rte_fslmc_probe(void)
return 0;
}
-static struct rte_device *
-rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
-{
- struct rte_device *dev;
-
- DPAA2_BUS_DEBUG("Finding a device named %s", (const char *)data);
-
- /* find_device is always called with an opaque object which should be
- * passed along to the 'cmp' function iterating over all device obj
- * on the bus.
- */
-
- if (start != NULL) {
- dev = TAILQ_NEXT(start, next);
- } else {
- dev = TAILQ_FIRST(&rte_fslmc_bus.bus.device_list);
- }
- while (dev != NULL) {
- if (cmp(dev, data) == 0) {
- DPAA2_BUS_DEBUG("Found device (%s)",
- dev->name);
- return dev;
- }
- dev = TAILQ_NEXT(dev, next);
- }
-
- return NULL;
-}
-
/*register a fslmc bus based dpaa2 driver */
RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_register)
void
@@ -674,7 +644,7 @@ struct rte_fslmc_bus rte_fslmc_bus = {
.cleanup = rte_fslmc_close,
.parse = rte_fslmc_parse,
.dev_compare = fslmc_dev_compare,
- .find_device = rte_fslmc_find_device,
+ .find_device = rte_bus_generic_find_device,
.get_iommu_class = rte_dpaa2_get_iommu_class,
.plug = fslmc_bus_plug,
.unplug = fslmc_bus_unplug,
diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 4edff5efd4..7d3331fe7e 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -403,23 +403,6 @@ ifpga_unplug(struct rte_device *dev)
}
-static struct rte_device *
-ifpga_find_device(const struct rte_device *start,
- rte_dev_cmp_t cmp, const void *data)
-{
- struct rte_device *dev;
-
- TAILQ_FOREACH(dev, &rte_ifpga_bus.device_list, next) {
- if (start && dev == start) {
- start = NULL;
- continue;
- }
- if (cmp(dev, data) == 0)
- return dev;
- }
-
- return NULL;
-}
static int
ifpga_parse(const char *name, void *addr)
{
@@ -468,7 +451,7 @@ static struct rte_bus rte_ifpga_bus = {
.scan = ifpga_scan,
.probe = ifpga_probe,
.cleanup = ifpga_cleanup,
- .find_device = ifpga_find_device,
+ .find_device = rte_bus_generic_find_device,
.plug = ifpga_plug,
.unplug = ifpga_unplug,
.parse = ifpga_parse,
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 94dc63d865..70ce63eac7 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -512,25 +512,6 @@ rte_pci_unregister(struct rte_pci_driver *driver)
rte_bus_remove_driver(&rte_pci_bus.bus, &driver->driver);
}
-static struct rte_device *
-pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
-{
- struct rte_device *dev;
-
- if (start != NULL) {
- dev = TAILQ_NEXT(start, next);
- } else {
- dev = TAILQ_FIRST(&rte_pci_bus.bus.device_list);
- }
- while (dev != NULL) {
- if (cmp(dev, data) == 0)
- return dev;
- dev = TAILQ_NEXT(dev, next);
- }
- return NULL;
-}
-
/*
* find the device which encounter the failure, by iterate over all device on
* PCI bus to check if the memory failure address is located in the range
@@ -879,7 +860,7 @@ struct rte_pci_bus rte_pci_bus = {
.scan = rte_pci_scan,
.probe = pci_probe,
.cleanup = pci_cleanup,
- .find_device = pci_find_device,
+ .find_device = rte_bus_generic_find_device,
.plug = pci_plug,
.unplug = pci_unplug,
.parse = pci_parse,
diff --git a/drivers/bus/pci/pci_params.c b/drivers/bus/pci/pci_params.c
index d771d8d1ba..d596c3bba8 100644
--- a/drivers/bus/pci/pci_params.c
+++ b/drivers/bus/pci/pci_params.c
@@ -63,7 +63,6 @@ rte_pci_dev_iterate(const void *start,
const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
- rte_bus_find_device_t find_device;
struct rte_kvargs *kvargs = NULL;
struct rte_device *dev;
@@ -75,8 +74,7 @@ rte_pci_dev_iterate(const void *start,
return NULL;
}
}
- find_device = rte_pci_bus.bus.find_device;
- dev = find_device(start, pci_dev_match, kvargs);
+ dev = rte_bus_generic_find_device(&rte_pci_bus.bus, start, pci_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
}
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index 0c23e5d9b6..c795bd4b9c 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -437,26 +437,6 @@ platform_bus_probe(void)
return 0;
}
-static struct rte_device *
-platform_bus_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data)
-{
- struct rte_device *dev;
-
- if (start != NULL) {
- dev = TAILQ_NEXT(start, next);
- } else {
- dev = RTE_TAILQ_FIRST(&platform_bus.bus.device_list);
- }
- while (dev) {
- if (cmp(dev, data) == 0)
- return dev;
-
- dev = RTE_TAILQ_NEXT(dev, next);
- }
-
- return NULL;
-}
-
static int
platform_bus_plug(struct rte_device *dev)
{
@@ -575,7 +555,7 @@ struct rte_platform_bus platform_bus = {
.bus = {
.scan = platform_bus_scan,
.probe = platform_bus_probe,
- .find_device = platform_bus_find_device,
+ .find_device = rte_bus_generic_find_device,
.plug = platform_bus_plug,
.unplug = platform_bus_unplug,
.parse = platform_bus_parse,
diff --git a/drivers/bus/platform/platform_params.c b/drivers/bus/platform/platform_params.c
index 65b20d121f..f8538a1d84 100644
--- a/drivers/bus/platform/platform_params.c
+++ b/drivers/bus/platform/platform_params.c
@@ -46,7 +46,6 @@ void *
platform_bus_dev_iterate(const void *start, const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
- rte_bus_find_device_t find_device;
struct rte_kvargs *kvargs = NULL;
struct rte_device *dev;
@@ -59,13 +58,7 @@ platform_bus_dev_iterate(const void *start, const char *str,
}
}
- find_device = platform_bus.bus.find_device;
- if (find_device == NULL) {
- rte_kvargs_free(kvargs);
- return NULL;
- }
-
- dev = platform_bus.bus.find_device(start, platform_dev_match, kvargs);
+ dev = rte_bus_generic_find_device(&platform_bus.bus, start, platform_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c
index 199517442d..ef133a6ae7 100644
--- a/drivers/bus/uacce/uacce.c
+++ b/drivers/bus/uacce/uacce.c
@@ -508,26 +508,6 @@ uacce_unplug(struct rte_device *dev)
return ret;
}
-static struct rte_device *
-uacce_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data)
-{
- struct rte_device *dev;
-
- if (start != NULL) {
- dev = TAILQ_NEXT(start, next);
- } else {
- dev = TAILQ_FIRST(&uacce_bus.bus.device_list);
- }
-
- while (dev != NULL) {
- if (cmp(dev, data) == 0)
- return dev;
- dev = TAILQ_NEXT(dev, next);
- }
-
- return NULL;
-}
-
static int
uacce_parse(const char *name, void *addr)
{
@@ -565,7 +545,6 @@ static void *
uacce_dev_iterate(const void *start, const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
- rte_bus_find_device_t find_device;
struct rte_kvargs *kvargs = NULL;
struct rte_device *dev;
@@ -576,8 +555,7 @@ uacce_dev_iterate(const void *start, const char *str,
return NULL;
}
}
- find_device = uacce_bus.bus.find_device;
- dev = find_device(start, uacce_dev_match, kvargs);
+ dev = rte_bus_generic_find_device(&uacce_bus.bus, start, uacce_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
}
@@ -696,7 +674,7 @@ static struct rte_uacce_bus uacce_bus = {
.cleanup = uacce_cleanup,
.plug = uacce_plug,
.unplug = uacce_unplug,
- .find_device = uacce_find_device,
+ .find_device = rte_bus_generic_find_device,
.parse = uacce_parse,
.dev_iterate = uacce_dev_iterate,
},
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index db73b08c38..9b88df8bdc 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -577,8 +577,8 @@ vdev_cleanup(void)
}
struct rte_device *
-rte_vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
+rte_vdev_find_device(const struct rte_bus *bus __rte_unused, const struct rte_device *start,
+ rte_dev_cmp_t cmp, const void *data)
{
struct rte_device *dev;
diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c
index 68ae09e2e9..fedd82b25d 100644
--- a/drivers/bus/vdev/vdev_params.c
+++ b/drivers/bus/vdev/vdev_params.c
@@ -58,7 +58,7 @@ rte_vdev_dev_iterate(const void *start,
return NULL;
}
}
- dev = rte_vdev_find_device(start, vdev_dev_match, kvargs);
+ dev = rte_vdev_find_device(NULL, start, vdev_dev_match, kvargs);
rte_kvargs_free(kvargs);
return dev;
}
diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h
index e683f5f133..ac036693d8 100644
--- a/drivers/bus/vdev/vdev_private.h
+++ b/drivers/bus/vdev/vdev_private.h
@@ -12,7 +12,8 @@ extern "C" {
#endif
struct rte_device *
-rte_vdev_find_device(const struct rte_device *start,
+rte_vdev_find_device(const struct rte_bus *bus,
+ const struct rte_device *start,
rte_dev_cmp_t cmp,
const void *data);
diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
index 889b9347d7..3260bd5395 100644
--- a/drivers/bus/vmbus/vmbus_common.c
+++ b/drivers/bus/vmbus/vmbus_common.c
@@ -275,31 +275,12 @@ rte_vmbus_unregister(struct rte_vmbus_driver *driver)
}
/* VMBUS doesn't support hotplug */
-static struct rte_device *
-vmbus_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
-{
- struct rte_device *dev;
-
- TAILQ_FOREACH(dev, &rte_vmbus_bus.bus.device_list, next) {
- if (start && dev == start) {
- start = NULL;
- continue;
- }
- if (cmp(dev, data) == 0)
- return dev;
- }
-
- return NULL;
-}
-
-
struct rte_vmbus_bus rte_vmbus_bus = {
.bus = {
.scan = rte_vmbus_scan,
.probe = rte_vmbus_probe,
.cleanup = rte_vmbus_cleanup,
- .find_device = vmbus_find_device,
+ .find_device = rte_bus_generic_find_device,
.parse = vmbus_parse,
.dev_compare = vmbus_dev_compare,
},
diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
index b3e691a2bd..1c203e1288 100644
--- a/drivers/dma/idxd/idxd_bus.c
+++ b/drivers/dma/idxd/idxd_bus.c
@@ -44,8 +44,6 @@ struct rte_dsa_device {
struct dsa_bus;
static int dsa_scan(void);
static int dsa_probe(void);
-static struct rte_device *dsa_find_device(const struct rte_device *start,
- rte_dev_cmp_t cmp, const void *data);
static enum rte_iova_mode dsa_get_iommu_class(void);
static int dsa_addr_parse(const char *name, void *addr);
@@ -61,7 +59,7 @@ struct dsa_bus dsa_bus = {
.bus = {
.scan = dsa_scan,
.probe = dsa_probe,
- .find_device = dsa_find_device,
+ .find_device = rte_bus_generic_find_device,
.get_iommu_class = dsa_get_iommu_class,
.parse = dsa_addr_parse,
},
@@ -340,22 +338,6 @@ dsa_scan(void)
return 0;
}
-static struct rte_device *
-dsa_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data)
-{
- struct rte_device *dev = TAILQ_FIRST(&dsa_bus.bus.device_list);
-
- if (start != NULL) /* jump to start point if given */
- dev = TAILQ_NEXT(start, next);
- while (dev != NULL) {
- if (cmp(dev, data) == 0)
- return dev;
- dev = TAILQ_NEXT(dev, next);
- }
- return NULL;
-}
-
static enum rte_iova_mode
dsa_get_iommu_class(void)
{
diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c
index 4fbd25cd33..823ed80f07 100644
--- a/drivers/net/bonding/rte_eth_bond_args.c
+++ b/drivers/net/bonding/rte_eth_bond_args.c
@@ -45,7 +45,7 @@ find_port_id_by_pci_addr(const struct rte_pci_addr *pci_addr)
return -1;
}
- dev = pci_bus->find_device(NULL, bond_pci_addr_cmp, pci_addr);
+ dev = pci_bus->find_device(pci_bus, NULL, bond_pci_addr_cmp, pci_addr);
if (dev == NULL) {
RTE_BOND_LOG(ERR, "unable to find PCI device");
return -1;
diff --git a/drivers/net/vdev_netvsc/vdev_netvsc.c b/drivers/net/vdev_netvsc/vdev_netvsc.c
index f4a84783ce..d70da6c7c1 100644
--- a/drivers/net/vdev_netvsc/vdev_netvsc.c
+++ b/drivers/net/vdev_netvsc/vdev_netvsc.c
@@ -794,7 +794,7 @@ vdev_netvsc_scan_callback(__rte_unused void *arg)
VDEV_NETVSC_DRIVER_NAME_LEN))
return;
- dev = vbus->find_device(NULL, vdev_netvsc_cmp_rte_device,
+ dev = vbus->find_device(vbus, NULL, vdev_netvsc_cmp_rte_device,
VDEV_NETVSC_DRIVER_NAME);
if (dev)
return;
diff --git a/drivers/raw/ifpga/ifpga_rawdev.c b/drivers/raw/ifpga/ifpga_rawdev.c
index 5b9b596435..d1d54e9065 100644
--- a/drivers/raw/ifpga/ifpga_rawdev.c
+++ b/drivers/raw/ifpga/ifpga_rawdev.c
@@ -1874,7 +1874,7 @@ ifpga_cfg_remove(struct rte_vdev_device *vdev)
args.port, args.bdf);
bus = rte_bus_find_by_name(RTE_STR(IFPGA_BUS_NAME));
if (bus) {
- if (bus->find_device(NULL, cmp_dev_name, dev_name)) {
+ if (bus->find_device(bus, NULL, cmp_dev_name, dev_name)) {
ret = rte_eal_hotplug_remove(RTE_STR(IFPGA_BUS_NAME),
dev_name);
}
diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c
index 2748e99826..f81d13e7d0 100644
--- a/lib/eal/common/eal_common_bus.c
+++ b/lib/eal/common/eal_common_bus.c
@@ -182,7 +182,7 @@ bus_find_device(const struct rte_bus *bus, const void *_dev)
{
struct rte_device *dev;
- dev = bus->find_device(NULL, cmp_rte_device, _dev);
+ dev = bus->find_device(bus, NULL, cmp_rte_device, _dev);
return dev == NULL;
}
@@ -398,6 +398,25 @@ rte_bus_insert_device(struct rte_bus *bus,
new_dev->bus = bus;
}
+RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_generic_find_device)
+struct rte_device *
+rte_bus_generic_find_device(const struct rte_bus *bus, const struct rte_device *start,
+ rte_dev_cmp_t cmp, const void *data)
+{
+ struct rte_device *dev;
+
+ if (start != NULL)
+ dev = TAILQ_NEXT(start, next);
+ else
+ dev = TAILQ_FIRST(&bus->device_list);
+ while (dev != NULL) {
+ if (cmp(dev, data) == 0)
+ return dev;
+ dev = TAILQ_NEXT(dev, next);
+ }
+ return NULL;
+}
+
RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_add_driver)
void
rte_bus_add_driver(struct rte_bus *bus, struct rte_driver *driver)
diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c
index fceca75223..e08a0f9dbc 100644
--- a/lib/eal/common/eal_common_dev.c
+++ b/lib/eal/common/eal_common_dev.c
@@ -207,7 +207,7 @@ local_dev_probe(const char *devargs, struct rte_device **new_dev)
if (ret)
goto err_devarg;
- dev = da->bus->find_device(NULL, cmp_dev_name, da->name);
+ dev = da->bus->find_device(da->bus, NULL, cmp_dev_name, da->name);
if (dev == NULL) {
EAL_LOG(ERR, "Cannot find device (%s)",
da->name);
@@ -347,7 +347,7 @@ rte_eal_hotplug_remove(const char *busname, const char *devname)
return -ENOENT;
}
- dev = bus->find_device(NULL, cmp_dev_name, devname);
+ dev = bus->find_device(bus, NULL, cmp_dev_name, devname);
if (dev == NULL) {
EAL_LOG(ERR, "Cannot find plugged device (%s)", devname);
return -EINVAL;
diff --git a/lib/eal/common/hotplug_mp.c b/lib/eal/common/hotplug_mp.c
index 17089ca3db..57a5c0bdfe 100644
--- a/lib/eal/common/hotplug_mp.c
+++ b/lib/eal/common/hotplug_mp.c
@@ -135,7 +135,7 @@ __handle_secondary_request(void *param)
goto finish;
}
- dev = bus->find_device(NULL, cmp_dev_name, da.name);
+ dev = bus->find_device(bus, NULL, cmp_dev_name, da.name);
if (dev == NULL) {
EAL_LOG(ERR, "Cannot find plugged device (%s)", da.name);
ret = -ENOENT;
@@ -262,7 +262,7 @@ static void __handle_primary_request(void *param)
goto quit;
}
- dev = bus->find_device(NULL, cmp_dev_name, da->name);
+ dev = bus->find_device(bus, NULL, cmp_dev_name, da->name);
if (dev == NULL) {
EAL_LOG(ERR, "Cannot find plugged device (%s)", da->name);
ret = -ENOENT;
diff --git a/lib/eal/include/bus_driver.h b/lib/eal/include/bus_driver.h
index 5b40fcd606..31c9586a33 100644
--- a/lib/eal/include/bus_driver.h
+++ b/lib/eal/include/bus_driver.h
@@ -69,8 +69,8 @@ typedef int (*rte_bus_probe_t)(void);
* The first device matching the data, NULL if none exists.
*/
typedef struct rte_device *
-(*rte_bus_find_device_t)(const struct rte_device *start, rte_dev_cmp_t cmp,
- const void *data);
+(*rte_bus_find_device_t)(const struct rte_bus *bus, const struct rte_device *start,
+ rte_dev_cmp_t cmp, const void *data);
/**
* Implementation specific probe function which is responsible for linking
@@ -430,6 +430,26 @@ void rte_bus_insert_device(struct rte_bus *bus,
struct rte_device *exist_dev,
struct rte_device *new_dev);
+/**
+ * Find a device on a bus.
+ *
+ * @param bus
+ * A pointer to a rte_bus structure.
+ * @param start
+ * Starting point for the search. If NULL, search from the beginning.
+ * @param cmp
+ * Comparison function to match devices.
+ * @param data
+ * Data to pass to the comparison function.
+ * @return
+ * The first matching device, or NULL if not found.
+ */
+__rte_internal
+struct rte_device *rte_bus_generic_find_device(const struct rte_bus *bus,
+ const struct rte_device *start,
+ rte_dev_cmp_t cmp,
+ const void *data);
+
/**
* Helper macro to iterate over all drivers on a bus.
*
diff --git a/lib/eal/linux/eal_dev.c b/lib/eal/linux/eal_dev.c
index 33b78464d5..ec408649d0 100644
--- a/lib/eal/linux/eal_dev.c
+++ b/lib/eal/linux/eal_dev.c
@@ -278,8 +278,7 @@ dev_uev_handler(__rte_unused void *param)
goto failure_handle_err;
}
- dev = bus->find_device(NULL, cmp_dev_name,
- uevent.devname);
+ dev = bus->find_device(bus, NULL, cmp_dev_name, uevent.devname);
if (dev == NULL) {
EAL_LOG(ERR, "Cannot find device (%s) on "
"bus (%s)", uevent.devname, busname);
--
2.53.0
^ permalink raw reply related
* [PATCH v2 08/23] bus: factorize device list
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Parav Pandit, Xueming Li,
Nipun Gupta, Nikhil Agarwal, Hemant Agrawal, Sachin Saxena,
Rosen Xu, Chenbo Xia, Tomasz Duszynski, Chengwen Feng, Long Li,
Wei Hu, Kevin Laatz
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
Move device list from bus-specific structures to the common rte_bus
structure and remove unnecessary wrapper functions. This eliminates
code duplication across bus drivers.
Remove device_list from bus-specific structures and their wrapper
functions (e.g., rte_pci_add_device), using EAL helpers
(rte_bus_add_device, rte_bus_remove_device, rte_bus_insert_device)
directly instead. Remove custom iteration macros (FOREACH_DEVICE_ON_*)
and use standard TAILQ_FOREACH with rte_device* and RTE_BUS_DEVICE
macro.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/auxiliary/auxiliary_common.c | 47 ++++------------
drivers/bus/auxiliary/bus_auxiliary_driver.h | 1 -
drivers/bus/auxiliary/linux/auxiliary.c | 7 +--
drivers/bus/auxiliary/private.h | 20 -------
drivers/bus/cdx/bus_cdx_driver.h | 1 -
drivers/bus/cdx/cdx.c | 44 ++++-----------
drivers/bus/cdx/private.h | 1 -
drivers/bus/dpaa/bus_dpaa_driver.h | 1 -
drivers/bus/dpaa/dpaa_bus.c | 51 +++++++----------
drivers/bus/fslmc/bus_fslmc_driver.h | 1 -
drivers/bus/fslmc/fslmc_bus.c | 52 ++++++++---------
drivers/bus/fslmc/fslmc_vfio.c | 45 +++++++--------
drivers/bus/fslmc/portal/dpaa2_hw_dprc.c | 4 +-
drivers/bus/fslmc/private.h | 2 -
drivers/bus/ifpga/bus_ifpga_driver.h | 1 -
drivers/bus/ifpga/ifpga_bus.c | 28 ++++------
drivers/bus/pci/bsd/pci.c | 12 ++--
drivers/bus/pci/bus_pci_driver.h | 1 -
drivers/bus/pci/linux/pci.c | 12 ++--
drivers/bus/pci/pci_common.c | 55 +++++-------------
drivers/bus/pci/private.h | 30 ----------
drivers/bus/pci/windows/pci.c | 12 ++--
drivers/bus/platform/bus_platform_driver.h | 1 -
drivers/bus/platform/platform.c | 32 +++++------
drivers/bus/platform/private.h | 5 --
drivers/bus/uacce/bus_uacce_driver.h | 1 -
drivers/bus/uacce/uacce.c | 34 +++++------
drivers/bus/vdev/bus_vdev_driver.h | 1 -
drivers/bus/vdev/vdev.c | 45 +++++++--------
drivers/bus/vmbus/bus_vmbus_driver.h | 1 -
drivers/bus/vmbus/linux/vmbus_bus.c | 7 +--
drivers/bus/vmbus/private.h | 10 ----
drivers/bus/vmbus/vmbus_common.c | 41 +++-----------
drivers/dma/idxd/idxd_bus.c | 21 ++-----
lib/eal/common/eal_common_bus.c | 27 +++++++++
lib/eal/include/bus_driver.h | 59 ++++++++++++++++++++
36 files changed, 286 insertions(+), 427 deletions(-)
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index 7e2d832dda..a1a3a747a5 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -198,7 +198,7 @@ auxiliary_probe(void)
size_t probed = 0, failed = 0;
int ret = 0;
- FOREACH_DEVICE_ON_AUXILIARY_BUS(dev) {
+ RTE_BUS_FOREACH_DEV(dev, &auxiliary_bus.bus) {
probed++;
ret = auxiliary_probe_all_drivers(dev);
@@ -251,45 +251,21 @@ rte_auxiliary_unregister(struct rte_auxiliary_driver *driver)
rte_bus_remove_driver(&auxiliary_bus.bus, &driver->driver);
}
-/* Add a device to auxiliary bus */
-void
-auxiliary_add_device(struct rte_auxiliary_device *aux_dev)
-{
- TAILQ_INSERT_TAIL(&auxiliary_bus.device_list, aux_dev, next);
-}
-
-/* Insert a device into a predefined position in auxiliary bus */
-void
-auxiliary_insert_device(struct rte_auxiliary_device *exist_aux_dev,
- struct rte_auxiliary_device *new_aux_dev)
-{
- TAILQ_INSERT_BEFORE(exist_aux_dev, new_aux_dev, next);
-}
-
-/* Remove a device from auxiliary bus */
-static void
-rte_auxiliary_remove_device(struct rte_auxiliary_device *auxiliary_dev)
-{
- TAILQ_REMOVE(&auxiliary_bus.device_list, auxiliary_dev, next);
-}
-
static struct rte_device *
auxiliary_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- const struct rte_auxiliary_device *pstart;
- struct rte_auxiliary_device *adev;
+ struct rte_device *dev;
if (start != NULL) {
- pstart = RTE_BUS_DEVICE(start, *pstart);
- adev = TAILQ_NEXT(pstart, next);
+ dev = TAILQ_NEXT(start, next);
} else {
- adev = TAILQ_FIRST(&auxiliary_bus.device_list);
+ dev = TAILQ_FIRST(&auxiliary_bus.bus.device_list);
}
- while (adev != NULL) {
- if (cmp(&adev->device, data) == 0)
- return &adev->device;
- adev = TAILQ_NEXT(adev, next);
+ while (dev != NULL) {
+ if (cmp(dev, data) == 0)
+ return dev;
+ dev = TAILQ_NEXT(dev, next);
}
return NULL;
}
@@ -310,7 +286,7 @@ auxiliary_unplug(struct rte_device *dev)
ret = rte_auxiliary_driver_remove_dev(adev);
if (ret == 0) {
- rte_auxiliary_remove_device(adev);
+ rte_bus_remove_device(&auxiliary_bus.bus, &adev->device);
rte_devargs_remove(dev->devargs);
rte_intr_instance_free(adev->intr_handle);
free(adev);
@@ -321,10 +297,10 @@ auxiliary_unplug(struct rte_device *dev)
static int
auxiliary_cleanup(void)
{
- struct rte_auxiliary_device *dev, *tmp_dev;
+ struct rte_auxiliary_device *dev;
int error = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &auxiliary_bus.device_list, next, tmp_dev) {
+ RTE_BUS_FOREACH_DEV(dev, &auxiliary_bus.bus) {
int ret;
if (!rte_dev_is_probed(&dev->device))
@@ -391,7 +367,6 @@ struct rte_auxiliary_bus auxiliary_bus = {
.get_iommu_class = auxiliary_get_iommu_class,
.dev_iterate = auxiliary_dev_iterate,
},
- .device_list = TAILQ_HEAD_INITIALIZER(auxiliary_bus.device_list),
};
RTE_REGISTER_BUS(auxiliary, auxiliary_bus.bus);
diff --git a/drivers/bus/auxiliary/bus_auxiliary_driver.h b/drivers/bus/auxiliary/bus_auxiliary_driver.h
index 59c46e08a0..165145b15e 100644
--- a/drivers/bus/auxiliary/bus_auxiliary_driver.h
+++ b/drivers/bus/auxiliary/bus_auxiliary_driver.h
@@ -110,7 +110,6 @@ typedef int (rte_auxiliary_dma_unmap_t)(struct rte_auxiliary_device *dev,
* A structure describing an auxiliary device.
*/
struct rte_auxiliary_device {
- RTE_TAILQ_ENTRY(rte_auxiliary_device) next; /**< Next probed device. */
struct rte_device device; /**< Inherit core device */
char name[RTE_DEV_NAME_MAX_LEN + 1]; /**< ASCII device name */
struct rte_intr_handle *intr_handle; /**< Interrupt handle */
diff --git a/drivers/bus/auxiliary/linux/auxiliary.c b/drivers/bus/auxiliary/linux/auxiliary.c
index 7c430629d0..c65bbc8fcc 100644
--- a/drivers/bus/auxiliary/linux/auxiliary.c
+++ b/drivers/bus/auxiliary/linux/auxiliary.c
@@ -35,7 +35,6 @@ auxiliary_scan_one(const char *dirname, const char *name)
return -1;
}
dev->device.name = dev->name;
- dev->device.bus = &auxiliary_bus.bus;
/* Get NUMA node, default to 0 if not present */
snprintf(filename, sizeof(filename), "%s/%s/numa_node",
@@ -49,12 +48,12 @@ auxiliary_scan_one(const char *dirname, const char *name)
auxiliary_on_scan(dev);
/* Device is valid, add in list (sorted) */
- TAILQ_FOREACH(dev2, &auxiliary_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev2, &auxiliary_bus.bus) {
ret = strcmp(dev->name, dev2->name);
if (ret > 0)
continue;
if (ret < 0) {
- auxiliary_insert_device(dev2, dev);
+ rte_bus_insert_device(&auxiliary_bus.bus, &dev2->device, &dev->device);
} else { /* already registered */
if (rte_dev_is_probed(&dev2->device) &&
dev2->device.devargs != dev->device.devargs) {
@@ -66,7 +65,7 @@ auxiliary_scan_one(const char *dirname, const char *name)
}
return 0;
}
- auxiliary_add_device(dev);
+ rte_bus_add_device(&auxiliary_bus.bus, &dev->device);
return 0;
}
diff --git a/drivers/bus/auxiliary/private.h b/drivers/bus/auxiliary/private.h
index 66ba97b946..0b3d73a08d 100644
--- a/drivers/bus/auxiliary/private.h
+++ b/drivers/bus/auxiliary/private.h
@@ -24,15 +24,10 @@ extern int auxiliary_bus_logtype;
*/
struct rte_auxiliary_bus {
struct rte_bus bus; /* Inherit the generic class */
- TAILQ_HEAD(, rte_auxiliary_device) device_list; /* List of devices */
};
extern struct rte_auxiliary_bus auxiliary_bus;
-/* Auxiliary bus iterators */
-#define FOREACH_DEVICE_ON_AUXILIARY_BUS(p) \
- TAILQ_FOREACH(p, &(auxiliary_bus.device_list), next)
-
/*
* Test whether the auxiliary device exist.
*/
@@ -49,21 +44,6 @@ int auxiliary_scan(void);
*/
void auxiliary_on_scan(struct rte_auxiliary_device *aux_dev);
-/*
- * Add an auxiliary device to the auxiliary bus (append to auxiliary device
- * list). This function also updates the bus references of the auxiliary
- * device and the generic device object embedded within.
- */
-void auxiliary_add_device(struct rte_auxiliary_device *aux_dev);
-
-/*
- * Insert an auxiliary device in the auxiliary bus at a particular location
- * in the device list. It also updates the auxiliary bus reference of the
- * new devices to be inserted.
- */
-void auxiliary_insert_device(struct rte_auxiliary_device *exist_aux_dev,
- struct rte_auxiliary_device *new_aux_dev);
-
/*
* Match the auxiliary driver and device by driver function.
*/
diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index 823a5b1be3..cee6c4a8d6 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -53,7 +53,6 @@ struct rte_cdx_id {
* A structure describing a CDX device.
*/
struct rte_cdx_device {
- RTE_TAILQ_ENTRY(rte_cdx_device) next; /**< Next probed CDX device. */
struct rte_device device; /**< Inherit core device */
struct rte_cdx_driver *driver; /**< CDX driver used in probing */
char name[RTE_DEV_NAME_MAX_LEN]; /**< Device name */
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 5973f75be2..bc221a4d00 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -84,10 +84,6 @@
#define CDX_DEV_PREFIX "cdx-"
-/* CDX Bus iterators */
-#define FOREACH_DEVICE_ON_CDXBUS(p) \
- RTE_TAILQ_FOREACH(p, &rte_cdx_bus.device_list, next)
-
struct rte_cdx_bus rte_cdx_bus;
enum cdx_params {
@@ -99,13 +95,6 @@ static const char * const cdx_params_keys[] = {
NULL,
};
-/* Add a device to CDX bus */
-static void
-cdx_add_device(struct rte_cdx_device *cdx_dev)
-{
- TAILQ_INSERT_TAIL(&rte_cdx_bus.device_list, cdx_dev, next);
-}
-
static int
cdx_get_kernel_driver_by_path(const char *filename, char *driver_name,
size_t len)
@@ -167,7 +156,6 @@ cdx_scan_one(const char *dirname, const char *dev_name)
if (!dev)
return -ENOMEM;
- dev->device.bus = &rte_cdx_bus.bus;
memcpy(dev->name, dev_name, RTE_DEV_NAME_MAX_LEN);
dev->device.name = dev->name;
@@ -215,7 +203,7 @@ cdx_scan_one(const char *dirname, const char *dev_name)
}
dev->id.device_id = (uint16_t)tmp;
- cdx_add_device(dev);
+ rte_bus_add_device(&rte_cdx_bus.bus, &dev->device);
return 0;
@@ -416,7 +404,7 @@ cdx_probe(void)
size_t probed = 0, failed = 0;
int ret = 0;
- FOREACH_DEVICE_ON_CDXBUS(dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_cdx_bus.bus) {
probed++;
ret = cdx_probe_all_drivers(dev);
@@ -465,30 +453,21 @@ static struct rte_device *
cdx_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- const struct rte_cdx_device *cdx_start;
- struct rte_cdx_device *cdx_dev;
+ struct rte_device *dev;
if (start != NULL) {
- cdx_start = RTE_BUS_DEVICE(start, *cdx_start);
- cdx_dev = TAILQ_NEXT(cdx_start, next);
+ dev = TAILQ_NEXT(start, next);
} else {
- cdx_dev = TAILQ_FIRST(&rte_cdx_bus.device_list);
+ dev = TAILQ_FIRST(&rte_cdx_bus.bus.device_list);
}
- while (cdx_dev != NULL) {
- if (cmp(&cdx_dev->device, data) == 0)
- return &cdx_dev->device;
- cdx_dev = TAILQ_NEXT(cdx_dev, next);
+ while (dev != NULL) {
+ if (cmp(dev, data) == 0)
+ return dev;
+ dev = TAILQ_NEXT(dev, next);
}
return NULL;
}
-/* Remove a device from CDX bus */
-static void
-cdx_remove_device(struct rte_cdx_device *cdx_dev)
-{
- TAILQ_REMOVE(&rte_cdx_bus.device_list, cdx_dev, next);
-}
-
/*
* If vendor/device ID match, call the remove() function of the
* driver.
@@ -534,7 +513,7 @@ cdx_unplug(struct rte_device *dev)
ret = cdx_detach_dev(cdx_dev);
if (ret == 0) {
- cdx_remove_device(cdx_dev);
+ rte_bus_remove_device(&rte_cdx_bus.bus, &cdx_dev->device);
rte_devargs_remove(dev->devargs);
free(cdx_dev);
}
@@ -562,7 +541,7 @@ cdx_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
static enum rte_iova_mode
cdx_get_iommu_class(void)
{
- if (TAILQ_EMPTY(&rte_cdx_bus.device_list))
+ if (TAILQ_EMPTY(&rte_cdx_bus.bus.device_list))
return RTE_IOVA_DC;
return RTE_IOVA_VA;
@@ -624,7 +603,6 @@ struct rte_cdx_bus rte_cdx_bus = {
.get_iommu_class = cdx_get_iommu_class,
.dev_iterate = cdx_dev_iterate,
},
- .device_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.device_list),
};
RTE_REGISTER_BUS(cdx, rte_cdx_bus.bus);
diff --git a/drivers/bus/cdx/private.h b/drivers/bus/cdx/private.h
index 3807a17bfb..f69673aaab 100644
--- a/drivers/bus/cdx/private.h
+++ b/drivers/bus/cdx/private.h
@@ -12,7 +12,6 @@
*/
struct rte_cdx_bus {
struct rte_bus bus; /**< Inherit the generic class */
- RTE_TAILQ_HEAD(, rte_cdx_device) device_list; /**< List of CDX devices */
};
/**
diff --git a/drivers/bus/dpaa/bus_dpaa_driver.h b/drivers/bus/dpaa/bus_dpaa_driver.h
index 1575ed19e7..7e5e9b2126 100644
--- a/drivers/bus/dpaa/bus_dpaa_driver.h
+++ b/drivers/bus/dpaa/bus_dpaa_driver.h
@@ -79,7 +79,6 @@ struct dpaa_device_id {
};
struct rte_dpaa_device {
- TAILQ_ENTRY(rte_dpaa_device) next;
struct rte_device device;
union {
struct rte_eth_dev *eth_dev;
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index f9f902cbd6..8305f8cb23 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -59,7 +59,6 @@
struct rte_dpaa_bus {
struct rte_bus bus;
- TAILQ_HEAD(, rte_dpaa_device) device_list;
int device_count;
int detected;
uint32_t svr_ver;
@@ -164,19 +163,18 @@ dpaa_add_to_device_list(struct rte_dpaa_device *newdev)
{
int comp, inserted = 0;
struct rte_dpaa_device *dev = NULL;
- struct rte_dpaa_device *tdev = NULL;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_dpaa_bus.device_list, next, tdev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus.bus) {
comp = compare_dpaa_devices(newdev, dev);
if (comp < 0) {
- TAILQ_INSERT_BEFORE(dev, newdev, next);
+ rte_bus_insert_device(&rte_dpaa_bus.bus, &dev->device, &newdev->device);
inserted = 1;
break;
}
}
if (!inserted)
- TAILQ_INSERT_TAIL(&rte_dpaa_bus.device_list, newdev, next);
+ rte_bus_add_device(&rte_dpaa_bus.bus, &newdev->device);
}
/*
@@ -217,7 +215,6 @@ dpaa_create_device_list(void)
goto cleanup;
}
- dev->device.bus = &rte_dpaa_bus.bus;
dev->device.numa_node = SOCKET_ID_ANY;
/* Allocate interrupt handle instance */
@@ -347,10 +344,9 @@ static void
dpaa_clean_device_list(void)
{
struct rte_dpaa_device *dev = NULL;
- struct rte_dpaa_device *tdev = NULL;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_dpaa_bus.device_list, next, tdev) {
- TAILQ_REMOVE(&rte_dpaa_bus.device_list, dev, next);
+ RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus.bus) {
+ rte_bus_remove_device(&rte_dpaa_bus.bus, &dev->device);
rte_intr_instance_free(dev->intr_handle);
free(dev);
dev = NULL;
@@ -775,7 +771,7 @@ rte_dpaa_bus_probe(void)
process_once = 1;
/* If no device present on DPAA bus nothing needs to be done */
- if (TAILQ_EMPTY(&rte_dpaa_bus.device_list))
+ if (TAILQ_EMPTY(&rte_dpaa_bus.bus.device_list))
return 0;
/* Register DPAA mempool ops only if any DPAA device has
@@ -783,7 +779,7 @@ rte_dpaa_bus_probe(void)
*/
rte_mbuf_set_platform_mempool_ops(DPAA_MEMPOOL_OPS_NAME);
- TAILQ_FOREACH(dev, &rte_dpaa_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus.bus) {
if (dev->device_type == FSL_DPAA_ETH) {
ret = rte_dpaa_setup_intr(dev->intr_handle);
if (ret)
@@ -795,7 +791,7 @@ rte_dpaa_bus_probe(void)
dpaax_iova_table_populate();
/* For each registered driver, and device, call the driver->probe */
- TAILQ_FOREACH(dev, &rte_dpaa_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus.bus) {
RTE_BUS_FOREACH_DRV(drv, &rte_dpaa_bus.bus) {
ret = rte_dpaa_device_match(drv, dev);
if (ret)
@@ -826,24 +822,22 @@ static struct rte_device *
rte_dpaa_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- struct rte_dpaa_device *dev;
- const struct rte_dpaa_device *dstart;
+ struct rte_device *dev;
/* find_device is called with 'data' as an opaque object - just call
* cmp with this and each device object on bus.
*/
if (start != NULL) {
- dstart = RTE_BUS_DEVICE(start, *dstart);
- dev = TAILQ_NEXT(dstart, next);
+ dev = TAILQ_NEXT(start, next);
} else {
- dev = TAILQ_FIRST(&rte_dpaa_bus.device_list);
+ dev = TAILQ_FIRST(&rte_dpaa_bus.bus.device_list);
}
while (dev != NULL) {
- if (cmp(&dev->device, data) == 0) {
- DPAA_BUS_DEBUG("Found dev=(%s)", dev->device.name);
- return &dev->device;
+ if (cmp(dev, data) == 0) {
+ DPAA_BUS_DEBUG("Found dev=(%s)", dev->name);
+ return dev;
}
dev = TAILQ_NEXT(dev, next);
}
@@ -883,9 +877,8 @@ static void *
dpaa_bus_dev_iterate(const void *start, const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
- const struct rte_dpaa_device *dstart;
- struct rte_dpaa_device *dev;
char *dup, *dev_name = NULL;
+ struct rte_device *dev;
if (str == NULL) {
DPAA_BUS_DEBUG("No device string");
@@ -907,16 +900,15 @@ dpaa_bus_dev_iterate(const void *start, const char *str,
dev_name = dup + strlen("name=");
if (start != NULL) {
- dstart = RTE_BUS_DEVICE(start, *dstart);
- dev = TAILQ_NEXT(dstart, next);
+ dev = TAILQ_NEXT((const struct rte_device *)start, next);
} else {
- dev = TAILQ_FIRST(&rte_dpaa_bus.device_list);
+ dev = TAILQ_FIRST(&rte_dpaa_bus.bus.device_list);
}
while (dev != NULL) {
- if (strcmp(dev->device.name, dev_name) == 0) {
+ if (strcmp(dev->name, dev_name) == 0) {
free(dup);
- return &dev->device;
+ return dev;
}
dev = TAILQ_NEXT(dev, next);
}
@@ -928,10 +920,10 @@ dpaa_bus_dev_iterate(const void *start, const char *str,
static int
dpaa_bus_cleanup(void)
{
- struct rte_dpaa_device *dev, *tmp_dev;
+ struct rte_dpaa_device *dev;
BUS_INIT_FUNC_TRACE();
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_dpaa_bus.device_list, next, tmp_dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_dpaa_bus.bus) {
struct rte_dpaa_driver *drv = dev->driver;
int ret = 0;
@@ -988,7 +980,6 @@ static struct rte_dpaa_bus rte_dpaa_bus = {
.cleanup = dpaa_bus_cleanup,
},
.max_push_rxq_num = DPAA_DEFAULT_PUSH_MODE_QUEUE,
- .device_list = TAILQ_HEAD_INITIALIZER(rte_dpaa_bus.device_list),
.device_count = 0,
};
diff --git a/drivers/bus/fslmc/bus_fslmc_driver.h b/drivers/bus/fslmc/bus_fslmc_driver.h
index c82b182720..ab8bc1c41d 100644
--- a/drivers/bus/fslmc/bus_fslmc_driver.h
+++ b/drivers/bus/fslmc/bus_fslmc_driver.h
@@ -93,7 +93,6 @@ enum rte_dpaa2_dev_type {
* A structure describing a DPAA2 device.
*/
struct rte_dpaa2_device {
- TAILQ_ENTRY(rte_dpaa2_device) next; /**< Next probed DPAA2 device. */
struct rte_device device; /**< Inherit core device */
enum rte_dpaa2_dev_type dev_type; /**< Device Type */
uint16_t object_id; /**< DPAA2 Object ID */
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 36ec018785..3e7f03375a 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -46,10 +46,9 @@ static void
cleanup_fslmc_device_list(void)
{
struct rte_dpaa2_device *dev;
- struct rte_dpaa2_device *t_dev;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, t_dev) {
- TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
+ rte_bus_remove_device(&rte_fslmc_bus.bus, &dev->device);
rte_intr_instance_free(dev->intr_handle);
free(dev);
dev = NULL;
@@ -84,19 +83,18 @@ insert_in_device_list(struct rte_dpaa2_device *newdev)
{
int comp, inserted = 0;
struct rte_dpaa2_device *dev = NULL;
- struct rte_dpaa2_device *tdev = NULL;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, tdev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
comp = compare_dpaa2_devname(newdev, dev);
if (comp < 0) {
- TAILQ_INSERT_BEFORE(dev, newdev, next);
+ rte_bus_insert_device(&rte_fslmc_bus.bus, &dev->device, &newdev->device);
inserted = 1;
break;
}
}
if (!inserted)
- TAILQ_INSERT_TAIL(&rte_fslmc_bus.device_list, newdev, next);
+ rte_bus_add_device(&rte_fslmc_bus.bus, &newdev->device);
}
static void
@@ -107,7 +105,7 @@ dump_device_list(void)
/* Only if the log level has been set to Debugging, print list */
if (rte_log_can_log(dpaa2_logtype_bus, RTE_LOG_DEBUG)) {
DPAA2_BUS_LOG(DEBUG, "List of devices scanned on bus:");
- TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
DPAA2_BUS_LOG(DEBUG, "\t\t%s", dev->device.name);
}
}
@@ -142,7 +140,6 @@ scan_one_fslmc_device(char *dev_name)
return -ENOMEM;
}
- dev->device.bus = &rte_fslmc_bus.bus;
dev->device.numa_node = SOCKET_ID_ANY;
/* Allocate interrupt instance */
@@ -319,7 +316,7 @@ rte_fslmc_scan(void)
struct rte_dpaa2_device *dev;
DPAA2_BUS_DEBUG("Fslmc bus already scanned. Not rescanning");
- TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
dev->device.devargs = rte_bus_find_devargs(&rte_fslmc_bus.bus,
dev->device.name);
}
@@ -420,7 +417,7 @@ rte_fslmc_probe(void)
.align = alignof(dpaa2_seqn_t),
};
- if (TAILQ_EMPTY(&rte_fslmc_bus.device_list))
+ if (TAILQ_EMPTY(&rte_fslmc_bus.bus.device_list))
return 0;
dpaa2_seqn_dynfield_offset =
@@ -456,7 +453,7 @@ rte_fslmc_probe(void)
return 0;
}
- TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
RTE_BUS_FOREACH_DRV(drv, &rte_fslmc_bus.bus) {
ret = rte_fslmc_match(drv, dev);
if (ret)
@@ -486,8 +483,7 @@ static struct rte_device *
rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- const struct rte_dpaa2_device *dstart;
- struct rte_dpaa2_device *dev;
+ struct rte_device *dev;
DPAA2_BUS_DEBUG("Finding a device named %s", (const char *)data);
@@ -497,16 +493,15 @@ rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
*/
if (start != NULL) {
- dstart = RTE_BUS_DEVICE(start, *dstart);
- dev = TAILQ_NEXT(dstart, next);
+ dev = TAILQ_NEXT(start, next);
} else {
- dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
+ dev = TAILQ_FIRST(&rte_fslmc_bus.bus.device_list);
}
while (dev != NULL) {
- if (cmp(&dev->device, data) == 0) {
+ if (cmp(dev, data) == 0) {
DPAA2_BUS_DEBUG("Found device (%s)",
- dev->device.name);
- return &dev->device;
+ dev->name);
+ return dev;
}
dev = TAILQ_NEXT(dev, next);
}
@@ -543,7 +538,7 @@ fslmc_all_device_support_iova(void)
struct rte_dpaa2_device *dev;
struct rte_dpaa2_driver *drv;
- TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
RTE_BUS_FOREACH_DRV(drv, &rte_fslmc_bus.bus) {
ret = rte_fslmc_match(drv, dev);
if (ret)
@@ -565,7 +560,7 @@ rte_dpaa2_get_iommu_class(void)
if (rte_eal_iova_mode() == RTE_IOVA_PA)
return RTE_IOVA_PA;
- if (TAILQ_EMPTY(&rte_fslmc_bus.device_list))
+ if (TAILQ_EMPTY(&rte_fslmc_bus.bus.device_list))
return RTE_IOVA_DC;
/* check if all devices on the bus support Virtual addressing or not */
@@ -632,9 +627,8 @@ static void *
fslmc_bus_dev_iterate(const void *start, const char *str,
const struct rte_dev_iterator *it __rte_unused)
{
- const struct rte_dpaa2_device *dstart;
- struct rte_dpaa2_device *dev;
char *dup, *dev_name = NULL;
+ struct rte_device *dev;
if (str == NULL) {
DPAA2_BUS_DEBUG("No device string");
@@ -656,16 +650,15 @@ fslmc_bus_dev_iterate(const void *start, const char *str,
dev_name = dup + strlen("name=");
if (start != NULL) {
- dstart = RTE_BUS_DEVICE(start, *dstart);
- dev = TAILQ_NEXT(dstart, next);
+ dev = TAILQ_NEXT(RTE_CAST_PTR(struct rte_device *, start), next);
} else {
- dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
+ dev = TAILQ_FIRST(&rte_fslmc_bus.bus.device_list);
}
while (dev != NULL) {
- if (strcmp(dev->device.name, dev_name) == 0) {
+ if (strcmp(dev->name, dev_name) == 0) {
free(dup);
- return &dev->device;
+ return dev;
}
dev = TAILQ_NEXT(dev, next);
}
@@ -687,7 +680,6 @@ struct rte_fslmc_bus rte_fslmc_bus = {
.unplug = fslmc_bus_unplug,
.dev_iterate = fslmc_bus_dev_iterate,
},
- .device_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.device_list),
.device_count = {0},
};
diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c
index 7daa18d850..e38f3e9fe7 100644
--- a/drivers/bus/fslmc/fslmc_vfio.c
+++ b/drivers/bus/fslmc/fslmc_vfio.c
@@ -1539,7 +1539,7 @@ fslmc_process_mcp(struct rte_dpaa2_device *dev)
int
fslmc_vfio_close_group(void)
{
- struct rte_dpaa2_device *dev, *dev_temp;
+ struct rte_dpaa2_device *dev;
int vfio_group_fd;
const char *group_name = fslmc_vfio_get_group_name();
@@ -1552,12 +1552,12 @@ fslmc_vfio_close_group(void)
return -EIO;
}
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_temp) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
if (dev->device.devargs &&
dev->device.devargs->policy == RTE_DEV_BLOCKED) {
DPAA2_BUS_LOG(DEBUG, "%s Blacklisted, skipping",
dev->device.name);
- TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus, &dev->device);
continue;
}
switch (dev->dev_type) {
@@ -1593,12 +1593,11 @@ fslmc_vfio_process_group(void)
{
int ret;
int found_mportal = 0;
- struct rte_dpaa2_device *dev, *dev_temp;
+ struct rte_dpaa2_device *dev;
bool is_dpmcp_in_blocklist = false, is_dpio_in_blocklist = false;
int dpmcp_count = 0, dpio_count = 0, current_device;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next,
- dev_temp) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
if (dev->dev_type == DPAA2_MPORTAL) {
dpmcp_count++;
if (dev->device.devargs &&
@@ -1615,16 +1614,15 @@ fslmc_vfio_process_group(void)
/* Search the MCP as that should be initialized first. */
current_device = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next,
- dev_temp) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
if (dev->dev_type == DPAA2_MPORTAL) {
current_device++;
if (dev->device.devargs &&
dev->device.devargs->policy == RTE_DEV_BLOCKED) {
DPAA2_BUS_LOG(DEBUG, "%s Blocked, skipping",
dev->device.name);
- TAILQ_REMOVE(&rte_fslmc_bus.device_list,
- dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus,
+ &dev->device);
continue;
}
@@ -1632,8 +1630,8 @@ fslmc_vfio_process_group(void)
!is_dpmcp_in_blocklist) {
if (dpmcp_count == 1 ||
current_device != dpmcp_count) {
- TAILQ_REMOVE(&rte_fslmc_bus.device_list,
- dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus,
+ &dev->device);
continue;
}
}
@@ -1647,7 +1645,7 @@ fslmc_vfio_process_group(void)
found_mportal = 1;
}
- TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus, &dev->device);
free(dev);
dev = NULL;
/* Ideally there is only a single dpmcp, but in case
@@ -1666,27 +1664,26 @@ fslmc_vfio_process_group(void)
* other devices.
*/
current_device = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_temp) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
if (dev->dev_type == DPAA2_DPRC) {
ret = fslmc_process_iodevices(dev);
if (ret) {
DPAA2_BUS_ERR("Unable to process dprc");
return ret;
}
- TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus, &dev->device);
}
}
current_device = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next,
- dev_temp) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
if (dev->dev_type == DPAA2_IO)
current_device++;
if (dev->device.devargs &&
dev->device.devargs->policy == RTE_DEV_BLOCKED) {
DPAA2_BUS_LOG(DEBUG, "%s Blocked, skipping",
dev->device.name);
- TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus, &dev->device);
continue;
}
if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
@@ -1694,7 +1691,7 @@ fslmc_vfio_process_group(void)
dev->dev_type != DPAA2_CRYPTO &&
dev->dev_type != DPAA2_QDMA &&
dev->dev_type != DPAA2_IO) {
- TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus, &dev->device);
continue;
}
switch (dev->dev_type) {
@@ -1736,14 +1733,14 @@ fslmc_vfio_process_group(void)
if (!is_dpio_in_blocklist && dpio_count > 1) {
if (rte_eal_process_type() == RTE_PROC_SECONDARY
&& current_device != dpio_count) {
- TAILQ_REMOVE(&rte_fslmc_bus.device_list,
- dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus,
+ &dev->device);
break;
}
if (rte_eal_process_type() == RTE_PROC_PRIMARY
&& current_device == dpio_count) {
- TAILQ_REMOVE(&rte_fslmc_bus.device_list,
- dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus,
+ &dev->device);
break;
}
}
@@ -1761,7 +1758,7 @@ fslmc_vfio_process_group(void)
/* Unknown - ignore */
DPAA2_BUS_DEBUG("Found unknown device (%s)",
dev->device.name);
- TAILQ_REMOVE(&rte_fslmc_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_fslmc_bus.bus, &dev->device);
free(dev);
dev = NULL;
}
diff --git a/drivers/bus/fslmc/portal/dpaa2_hw_dprc.c b/drivers/bus/fslmc/portal/dpaa2_hw_dprc.c
index a057cb1309..a66e55a456 100644
--- a/drivers/bus/fslmc/portal/dpaa2_hw_dprc.c
+++ b/drivers/bus/fslmc/portal/dpaa2_hw_dprc.c
@@ -28,7 +28,7 @@ rte_dpaa2_create_dprc_device(int vdev_fd __rte_unused,
{
struct dpaa2_dprc_dev *dprc_node;
struct dprc_endpoint endpoint1, endpoint2;
- struct rte_dpaa2_device *dev, *dev_tmp;
+ struct rte_dpaa2_device *dev;
int ret, dprc_id = obj->object_id;
/* Allocate DPAA2 dprc handle */
@@ -49,7 +49,7 @@ rte_dpaa2_create_dprc_device(int vdev_fd __rte_unused,
return ret;
}
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_fslmc_bus.device_list, next, dev_tmp) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_fslmc_bus.bus) {
/** DPRC is always created before it's children are created.*/
dev->container = dprc_node;
if (dev->dev_type == DPAA2_ETH) {
diff --git a/drivers/bus/fslmc/private.h b/drivers/bus/fslmc/private.h
index 338f55b094..2fe592f24d 100644
--- a/drivers/bus/fslmc/private.h
+++ b/drivers/bus/fslmc/private.h
@@ -14,8 +14,6 @@
*/
struct rte_fslmc_bus {
struct rte_bus bus; /**< Generic Bus object */
- TAILQ_HEAD(, rte_dpaa2_device) device_list;
- /**< FSLMC DPAA2 Device list */
int device_count[DPAA2_DEVTYPE_MAX];
/**< Count of all devices scanned */
};
diff --git a/drivers/bus/ifpga/bus_ifpga_driver.h b/drivers/bus/ifpga/bus_ifpga_driver.h
index 7d724dc1a0..c1ff38bdb2 100644
--- a/drivers/bus/ifpga/bus_ifpga_driver.h
+++ b/drivers/bus/ifpga/bus_ifpga_driver.h
@@ -67,7 +67,6 @@ struct rte_afu_shared {
* A structure describing a AFU device.
*/
struct rte_afu_device {
- RTE_TAILQ_ENTRY(rte_afu_device) next; /**< Next in device list. */
struct rte_device device; /**< Inherit core device */
struct rte_rawdev *rawdev; /**< Point Rawdev */
struct rte_afu_id id; /**< AFU id within FPGA. */
diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index c038144ebd..4edff5efd4 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -38,9 +38,6 @@
*/
static struct rte_bus rte_ifpga_bus;
-static TAILQ_HEAD(, rte_afu_device) ifpga_afu_dev_list =
- TAILQ_HEAD_INITIALIZER(ifpga_afu_dev_list);
-
/* register a ifpga bus based driver */
RTE_EXPORT_INTERNAL_SYMBOL(rte_ifpga_driver_register)
void rte_ifpga_driver_register(struct rte_afu_driver *driver)
@@ -63,7 +60,7 @@ ifpga_find_afu_dev(const struct rte_rawdev *rdev,
{
struct rte_afu_device *afu_dev = NULL;
- TAILQ_FOREACH(afu_dev, &ifpga_afu_dev_list, next) {
+ RTE_BUS_FOREACH_DEV(afu_dev, &rte_ifpga_bus) {
if (afu_dev->rawdev == rdev &&
!ifpga_afu_id_cmp(&afu_dev->id, afu_id))
return afu_dev;
@@ -139,7 +136,6 @@ ifpga_scan_one(struct rte_rawdev *rawdev,
if (!afu_dev)
goto end;
- afu_dev->device.bus = &rte_ifpga_bus;
afu_dev->device.devargs = devargs;
afu_dev->device.numa_node = SOCKET_ID_ANY;
afu_dev->device.name = devargs->name;
@@ -236,7 +232,7 @@ ifpga_scan(void)
afu_dev = ifpga_scan_one(rawdev, devargs);
if (afu_dev != NULL)
- TAILQ_INSERT_TAIL(&ifpga_afu_dev_list, afu_dev, next);
+ rte_bus_add_device(&rte_ifpga_bus, &afu_dev->device);
}
end:
@@ -333,7 +329,7 @@ ifpga_probe(void)
struct rte_afu_device *afu_dev = NULL;
int ret = 0;
- TAILQ_FOREACH(afu_dev, &ifpga_afu_dev_list, next) {
+ RTE_BUS_FOREACH_DEV(afu_dev, &rte_ifpga_bus) {
ret = ifpga_probe_all_drivers(afu_dev);
if (ret == -EEXIST)
continue;
@@ -352,10 +348,10 @@ ifpga_probe(void)
static int
ifpga_cleanup(void)
{
- struct rte_afu_device *afu_dev, *tmp_dev;
+ struct rte_afu_device *afu_dev;
int error = 0;
- RTE_TAILQ_FOREACH_SAFE(afu_dev, &ifpga_afu_dev_list, next, tmp_dev) {
+ RTE_BUS_FOREACH_DEV(afu_dev, &rte_ifpga_bus) {
struct rte_afu_driver *drv = afu_dev->driver;
int ret = 0;
@@ -373,7 +369,7 @@ ifpga_cleanup(void)
afu_dev->device.driver = NULL;
free:
- TAILQ_REMOVE(&ifpga_afu_dev_list, afu_dev, next);
+ rte_bus_remove_device(&rte_ifpga_bus, &afu_dev->device);
rte_devargs_remove(afu_dev->device.devargs);
rte_intr_instance_free(afu_dev->intr_handle);
free(afu_dev);
@@ -398,7 +394,7 @@ ifpga_unplug(struct rte_device *dev)
if (ret)
return ret;
- TAILQ_REMOVE(&ifpga_afu_dev_list, afu_dev, next);
+ rte_bus_remove_device(&rte_ifpga_bus, &afu_dev->device);
rte_devargs_remove(dev->devargs);
rte_intr_instance_free(afu_dev->intr_handle);
@@ -411,15 +407,15 @@ static struct rte_device *
ifpga_find_device(const struct rte_device *start,
rte_dev_cmp_t cmp, const void *data)
{
- struct rte_afu_device *afu_dev;
+ struct rte_device *dev;
- TAILQ_FOREACH(afu_dev, &ifpga_afu_dev_list, next) {
- if (start && &afu_dev->device == start) {
+ TAILQ_FOREACH(dev, &rte_ifpga_bus.device_list, next) {
+ if (start && dev == start) {
start = NULL;
continue;
}
- if (cmp(&afu_dev->device, data) == 0)
- return &afu_dev->device;
+ if (cmp(dev, data) == 0)
+ return dev;
}
return NULL;
diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c
index aba44492e0..78d14ab3ae 100644
--- a/drivers/bus/pci/bsd/pci.c
+++ b/drivers/bus/pci/bsd/pci.c
@@ -233,7 +233,6 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
memset(pdev, 0, sizeof(*pdev));
dev = &pdev->device;
- dev->device.bus = &rte_pci_bus.bus;
dev->addr.domain = conf->pc_sel.pc_domain;
dev->addr.bus = conf->pc_sel.pc_bus;
@@ -298,19 +297,20 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
}
/* device is valid, add in list (sorted) */
- if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
- rte_pci_add_device(dev);
+ if (TAILQ_EMPTY(&rte_pci_bus.bus.device_list)) {
+ rte_bus_add_device(&rte_pci_bus.bus, &dev->device);
}
else {
struct rte_pci_device *dev2 = NULL;
int ret;
- TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev2, &rte_pci_bus.bus) {
ret = rte_pci_addr_cmp(&dev->addr, &dev2->addr);
if (ret > 0)
continue;
else if (ret < 0) {
- rte_pci_insert_device(dev2, dev);
+ rte_bus_insert_device(&rte_pci_bus.bus, &dev2->device,
+ &dev->device);
} else { /* already registered */
dev2->kdrv = dev->kdrv;
dev2->max_vfs = dev->max_vfs;
@@ -322,7 +322,7 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
}
return 0;
}
- rte_pci_add_device(dev);
+ rte_bus_add_device(&rte_pci_bus.bus, &dev->device);
}
return 0;
diff --git a/drivers/bus/pci/bus_pci_driver.h b/drivers/bus/pci/bus_pci_driver.h
index 993d690f96..b0e5428e64 100644
--- a/drivers/bus/pci/bus_pci_driver.h
+++ b/drivers/bus/pci/bus_pci_driver.h
@@ -33,7 +33,6 @@ enum rte_pci_kernel_driver {
* A structure describing a PCI device.
*/
struct rte_pci_device {
- RTE_TAILQ_ENTRY(rte_pci_device) next; /**< Next probed PCI device. */
struct rte_device device; /**< Inherit core device */
struct rte_pci_addr addr; /**< PCI location. */
struct rte_pci_id id; /**< PCI ID. */
diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 5f263f8b28..cf8a60313b 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -218,7 +218,6 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
memset(pdev, 0, sizeof(*pdev));
dev = &pdev->device;
- dev->device.bus = &rte_pci_bus.bus;
dev->addr = *addr;
/* get vendor id */
@@ -322,18 +321,19 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
return 0;
}
/* device is valid, add in list (sorted) */
- if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
- rte_pci_add_device(dev);
+ if (TAILQ_EMPTY(&rte_pci_bus.bus.device_list)) {
+ rte_bus_add_device(&rte_pci_bus.bus, &dev->device);
} else {
struct rte_pci_device *dev2;
- TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev2, &rte_pci_bus.bus) {
ret = rte_pci_addr_cmp(&dev->addr, &dev2->addr);
if (ret > 0)
continue;
if (ret < 0) {
- rte_pci_insert_device(dev2, dev);
+ rte_bus_insert_device(&rte_pci_bus.bus, &dev2->device,
+ &dev->device);
} else { /* already registered */
if (!rte_dev_is_probed(&dev2->device)) {
dev2->kdrv = dev->kdrv;
@@ -377,7 +377,7 @@ pci_scan_one(const char *dirname, const struct rte_pci_addr *addr)
return 0;
}
- rte_pci_add_device(dev);
+ rte_bus_add_device(&rte_pci_bus.bus, &dev->device);
}
return 0;
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 79cc14a6dd..94dc63d865 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -383,7 +383,7 @@ pci_probe(void)
size_t probed = 0, failed = 0;
int ret = 0;
- FOREACH_DEVICE_ON_PCIBUS(dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_pci_bus.bus) {
probed++;
ret = pci_probe_all_drivers(dev);
@@ -405,10 +405,10 @@ pci_probe(void)
static int
pci_cleanup(void)
{
- struct rte_pci_device *dev, *tmp_dev;
+ struct rte_pci_device *dev;
int error = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_pci_bus.device_list, next, tmp_dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_pci_bus.bus) {
struct rte_pci_driver *drv = dev->driver;
int ret = 0;
@@ -432,7 +432,7 @@ pci_cleanup(void)
rte_intr_instance_free(dev->vfio_req_intr_handle);
dev->vfio_req_intr_handle = NULL;
- TAILQ_REMOVE(&rte_pci_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_pci_bus.bus, &dev->device);
pci_free(RTE_PCI_DEVICE_INTERNAL(dev));
}
@@ -466,7 +466,7 @@ rte_pci_dump(FILE *f)
{
struct rte_pci_device *dev = NULL;
- FOREACH_DEVICE_ON_PCIBUS(dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_pci_bus.bus) {
pci_dump_one_device(f, dev);
}
}
@@ -512,45 +512,21 @@ rte_pci_unregister(struct rte_pci_driver *driver)
rte_bus_remove_driver(&rte_pci_bus.bus, &driver->driver);
}
-/* Add a device to PCI bus */
-void
-rte_pci_add_device(struct rte_pci_device *pci_dev)
-{
- TAILQ_INSERT_TAIL(&rte_pci_bus.device_list, pci_dev, next);
-}
-
-/* Insert a device into a predefined position in PCI bus */
-void
-rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
- struct rte_pci_device *new_pci_dev)
-{
- TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next);
-}
-
-/* Remove a device from PCI bus */
-static void
-rte_pci_remove_device(struct rte_pci_device *pci_dev)
-{
- TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next);
-}
-
static struct rte_device *
pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- const struct rte_pci_device *pstart;
- struct rte_pci_device *pdev;
+ struct rte_device *dev;
if (start != NULL) {
- pstart = RTE_BUS_DEVICE(start, *pstart);
- pdev = TAILQ_NEXT(pstart, next);
+ dev = TAILQ_NEXT(start, next);
} else {
- pdev = TAILQ_FIRST(&rte_pci_bus.device_list);
+ dev = TAILQ_FIRST(&rte_pci_bus.bus.device_list);
}
- while (pdev != NULL) {
- if (cmp(&pdev->device, data) == 0)
- return &pdev->device;
- pdev = TAILQ_NEXT(pdev, next);
+ while (dev != NULL) {
+ if (cmp(dev, data) == 0)
+ return dev;
+ dev = TAILQ_NEXT(dev, next);
}
return NULL;
}
@@ -569,7 +545,7 @@ pci_find_device_by_addr(const void *failure_addr)
check_point = (uint64_t)(uintptr_t)failure_addr;
- FOREACH_DEVICE_ON_PCIBUS(pdev) {
+ RTE_BUS_FOREACH_DEV(pdev, &rte_pci_bus.bus) {
for (i = 0; i != RTE_DIM(pdev->mem_resource); i++) {
start = (uint64_t)(uintptr_t)pdev->mem_resource[i].addr;
len = pdev->mem_resource[i].len;
@@ -653,7 +629,7 @@ pci_unplug(struct rte_device *dev)
ret = rte_pci_detach_dev(pdev);
if (ret == 0) {
- rte_pci_remove_device(pdev);
+ rte_bus_remove_device(&rte_pci_bus.bus, &pdev->device);
rte_devargs_remove(dev->devargs);
pci_free(RTE_PCI_DEVICE_INTERNAL(pdev));
}
@@ -708,7 +684,7 @@ rte_pci_get_iommu_class(void)
bool devices_want_pa = false;
int iommu_no_va = -1;
- FOREACH_DEVICE_ON_PCIBUS(dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_pci_bus.bus) {
/*
* We can check this only once, because the IOMMU hardware is
* the same for all of them.
@@ -916,7 +892,6 @@ struct rte_pci_bus rte_pci_bus = {
.hot_unplug_handler = pci_hot_unplug_handler,
.sigbus_handler = pci_sigbus_handler,
},
- .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
};
RTE_REGISTER_BUS(pci, rte_pci_bus.bus);
diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index 8b5f563dc3..52fa6b0f76 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -34,15 +34,10 @@ extern int pci_bus_logtype;
*/
struct rte_pci_bus {
struct rte_bus bus; /**< Inherit the generic class */
- RTE_TAILQ_HEAD(, rte_pci_device) device_list; /**< List of PCI devices */
};
extern struct rte_pci_bus rte_pci_bus;
-/* PCI Bus iterators */
-#define FOREACH_DEVICE_ON_PCIBUS(p) \
- RTE_TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
-
struct rte_pci_driver;
struct rte_pci_device;
@@ -78,31 +73,6 @@ pci_common_set(struct rte_pci_device *dev);
void
pci_free(struct rte_pci_device_internal *pdev);
-/**
- * Add a PCI device to the PCI Bus (append to PCI Device list). This function
- * also updates the bus references of the PCI Device (and the generic device
- * object embedded within.
- *
- * @param pci_dev
- * PCI device to add
- * @return void
- */
-void rte_pci_add_device(struct rte_pci_device *pci_dev);
-
-/**
- * Insert a PCI device in the PCI Bus at a particular location in the device
- * list. It also updates the PCI Bus reference of the new devices to be
- * inserted.
- *
- * @param exist_pci_dev
- * Existing PCI device in PCI Bus
- * @param new_pci_dev
- * PCI device to be added before exist_pci_dev
- * @return void
- */
-void rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
- struct rte_pci_device *new_pci_dev);
-
/**
* A structure describing a PCI mapping.
*/
diff --git a/drivers/bus/pci/windows/pci.c b/drivers/bus/pci/windows/pci.c
index 549319ad5b..3b3f97da27 100644
--- a/drivers/bus/pci/windows/pci.c
+++ b/drivers/bus/pci/windows/pci.c
@@ -415,7 +415,6 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data)
memset(pdev, 0, sizeof(*pdev));
dev = &pdev->device;
- dev->device.bus = &rte_pci_bus.bus;
dev->addr = addr;
dev->id = pci_id;
dev->max_vfs = 0; /* TODO: get max_vfs */
@@ -431,17 +430,18 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data)
}
/* device is valid, add in list (sorted) */
- if (TAILQ_EMPTY(&rte_pci_bus.device_list)) {
- rte_pci_add_device(dev);
+ if (TAILQ_EMPTY(&rte_pci_bus.bus.device_list)) {
+ rte_bus_add_device(&rte_pci_bus.bus, &dev->device);
} else {
struct rte_pci_device *dev2 = NULL;
- TAILQ_FOREACH(dev2, &rte_pci_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev2, &rte_pci_bus.bus) {
ret = rte_pci_addr_cmp(&dev->addr, &dev2->addr);
if (ret > 0) {
continue;
} else if (ret < 0) {
- rte_pci_insert_device(dev2, dev);
+ rte_bus_insert_device(&rte_pci_bus.bus, &dev2->device,
+ &dev->device);
} else { /* already registered */
dev2->kdrv = dev->kdrv;
dev2->max_vfs = dev->max_vfs;
@@ -451,7 +451,7 @@ pci_scan_one(HDEVINFO dev_info, PSP_DEVINFO_DATA device_info_data)
}
return 0;
}
- rte_pci_add_device(dev);
+ rte_bus_add_device(&rte_pci_bus.bus, &dev->device);
}
return 0;
diff --git a/drivers/bus/platform/bus_platform_driver.h b/drivers/bus/platform/bus_platform_driver.h
index a72d5c00a3..3912ed5b85 100644
--- a/drivers/bus/platform/bus_platform_driver.h
+++ b/drivers/bus/platform/bus_platform_driver.h
@@ -94,7 +94,6 @@ struct rte_platform_resource {
* A structure describing a platform device.
*/
struct rte_platform_device {
- RTE_TAILQ_ENTRY(rte_platform_device) next; /**< Next attached platform device */
struct rte_device device; /**< Core device */
struct rte_platform_driver *driver; /**< Matching device driver */
char name[RTE_DEV_NAME_MAX_LEN]; /**< Device name */
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index 9d3c4877b0..0c23e5d9b6 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -57,11 +57,10 @@ dev_add(const char *dev_name)
rte_strscpy(pdev->name, dev_name, sizeof(pdev->name));
pdev->device.name = pdev->name;
pdev->device.devargs = rte_bus_find_devargs(&platform_bus.bus, dev_name);
- pdev->device.bus = &platform_bus.bus;
snprintf(path, sizeof(path), PLATFORM_BUS_DEVICES_PATH "/%s/numa_node", dev_name);
pdev->device.numa_node = eal_parse_sysfs_value(path, &val) ? rte_socket_id() : val;
- FOREACH_DEVICE_ON_PLATFORM_BUS(tmp) {
+ RTE_BUS_FOREACH_DEV(tmp, &platform_bus.bus) {
if (!strcmp(tmp->name, pdev->name)) {
PLATFORM_LOG_LINE(INFO, "device %s already added", pdev->name);
@@ -73,7 +72,7 @@ dev_add(const char *dev_name)
}
}
- TAILQ_INSERT_HEAD(&platform_bus.device_list, pdev, next);
+ rte_bus_add_device(&platform_bus.bus, &pdev->device);
PLATFORM_LOG_LINE(INFO, "adding device %s to the list", dev_name);
@@ -425,7 +424,7 @@ platform_bus_probe(void)
struct rte_platform_device *pdev;
int ret;
- FOREACH_DEVICE_ON_PLATFORM_BUS(pdev) {
+ RTE_BUS_FOREACH_DEV(pdev, &platform_bus.bus) {
ret = device_attach(pdev);
if (ret == -EBUSY) {
PLATFORM_LOG_LINE(DEBUG, "device %s already probed", pdev->name);
@@ -441,20 +440,18 @@ platform_bus_probe(void)
static struct rte_device *
platform_bus_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data)
{
- const struct rte_platform_device *pstart;
- struct rte_platform_device *pdev;
+ struct rte_device *dev;
if (start != NULL) {
- pstart = RTE_BUS_DEVICE(start, *pstart);
- pdev = TAILQ_NEXT(pstart, next);
+ dev = TAILQ_NEXT(start, next);
} else {
- pdev = RTE_TAILQ_FIRST(&platform_bus.device_list);
+ dev = RTE_TAILQ_FIRST(&platform_bus.bus.device_list);
}
- while (pdev) {
- if (cmp(&pdev->device, data) == 0)
- return &pdev->device;
+ while (dev) {
+ if (cmp(dev, data) == 0)
+ return dev;
- pdev = RTE_TAILQ_NEXT(pdev, next);
+ dev = RTE_TAILQ_NEXT(dev, next);
}
return NULL;
@@ -550,7 +547,7 @@ platform_bus_get_iommu_class(void)
struct rte_platform_driver *pdrv;
struct rte_platform_device *pdev;
- FOREACH_DEVICE_ON_PLATFORM_BUS(pdev) {
+ RTE_BUS_FOREACH_DEV(pdev, &platform_bus.bus) {
pdrv = pdev->driver;
if (pdrv != NULL && pdrv->drv_flags & RTE_PLATFORM_DRV_NEED_IOVA_AS_VA)
return RTE_IOVA_VA;
@@ -562,10 +559,10 @@ platform_bus_get_iommu_class(void)
static int
platform_bus_cleanup(void)
{
- struct rte_platform_device *pdev, *tmp;
+ struct rte_platform_device *pdev;
- RTE_TAILQ_FOREACH_SAFE(pdev, &platform_bus.device_list, next, tmp) {
- TAILQ_REMOVE(&platform_bus.device_list, pdev, next);
+ RTE_BUS_FOREACH_DEV(pdev, &platform_bus.bus) {
+ rte_bus_remove_device(&platform_bus.bus, &pdev->device);
if (!rte_dev_is_probed(&pdev->device))
continue;
platform_bus_unplug(&pdev->device);
@@ -588,7 +585,6 @@ struct rte_platform_bus platform_bus = {
.dev_iterate = platform_bus_dev_iterate,
.cleanup = platform_bus_cleanup,
},
- .device_list = TAILQ_HEAD_INITIALIZER(platform_bus.device_list),
};
RTE_REGISTER_BUS(platform, platform_bus.bus);
diff --git a/drivers/bus/platform/private.h b/drivers/bus/platform/private.h
index f7ee80f3ac..81a8984052 100644
--- a/drivers/bus/platform/private.h
+++ b/drivers/bus/platform/private.h
@@ -16,16 +16,11 @@
extern struct rte_platform_bus platform_bus;
-/* Platform bus iterators. */
-#define FOREACH_DEVICE_ON_PLATFORM_BUS(p) \
- RTE_TAILQ_FOREACH(p, &(platform_bus.device_list), next)
-
/*
* Structure describing platform bus.
*/
struct rte_platform_bus {
struct rte_bus bus; /* Core bus */
- RTE_TAILQ_HEAD(, rte_platform_device) device_list; /* List of bus devices */
};
extern int platform_bus_logtype;
diff --git a/drivers/bus/uacce/bus_uacce_driver.h b/drivers/bus/uacce/bus_uacce_driver.h
index 051e1736cf..04ced912c9 100644
--- a/drivers/bus/uacce/bus_uacce_driver.h
+++ b/drivers/bus/uacce/bus_uacce_driver.h
@@ -43,7 +43,6 @@ struct rte_uacce_driver;
* A structure describing a UACCE device.
*/
struct rte_uacce_device {
- RTE_TAILQ_ENTRY(rte_uacce_device) next; /**< Next in device list. */
struct rte_device device; /**< Inherit core device. */
struct rte_uacce_driver *driver; /**< Driver used in probing. */
char name[RTE_DEV_NAME_MAX_LEN]; /**< Device name. */
diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c
index c0a1e1d8ec..199517442d 100644
--- a/drivers/bus/uacce/uacce.c
+++ b/drivers/bus/uacce/uacce.c
@@ -39,7 +39,6 @@
*/
struct rte_uacce_bus {
struct rte_bus bus; /* Inherit the generic class. */
- TAILQ_HEAD(, rte_uacce_device) device_list; /* List of devices. */
};
/* Forward declaration of UACCE bus. */
@@ -54,9 +53,6 @@ static const char *const uacce_params_keys[] = {
NULL,
};
-#define FOREACH_DEVICE_ON_UACCEBUS(p) \
- RTE_TAILQ_FOREACH(p, &uacce_bus.device_list, next)
-
extern int uacce_bus_logtype;
#define RTE_LOGTYPE_UACCE_BUS uacce_bus_logtype
#define UACCE_BUS_LOG(level, ...) \
@@ -217,7 +213,6 @@ uacce_scan_one(const char *dev_name)
if (!dev)
return -ENOMEM;
- dev->device.bus = &uacce_bus.bus;
dev->device.name = dev->name;
dev->device.devargs = rte_bus_find_devargs(&uacce_bus.bus, dev_name);
snprintf(dev->name, sizeof(dev->name), "%s", dev_name);
@@ -243,7 +238,7 @@ uacce_scan_one(const char *dev_name)
if (ret != 0)
goto err;
- TAILQ_INSERT_TAIL(&uacce_bus.device_list, dev, next);
+ rte_bus_add_device(&uacce_bus.bus, &dev->device);
return 0;
err:
@@ -425,7 +420,7 @@ uacce_probe(void)
struct rte_uacce_device *dev;
int ret;
- FOREACH_DEVICE_ON_UACCEBUS(dev) {
+ RTE_BUS_FOREACH_DEV(dev, &uacce_bus.bus) {
probed++;
ret = uacce_probe_all_drivers(dev);
@@ -443,10 +438,10 @@ uacce_probe(void)
static int
uacce_cleanup(void)
{
- struct rte_uacce_device *dev, *tmp_dev;
+ struct rte_uacce_device *dev;
int error = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &uacce_bus.device_list, next, tmp_dev) {
+ RTE_BUS_FOREACH_DEV(dev, &uacce_bus.bus) {
struct rte_uacce_driver *dr = dev->driver;
int ret = 0;
@@ -464,7 +459,7 @@ uacce_cleanup(void)
dev->device.driver = NULL;
free:
- TAILQ_REMOVE(&uacce_bus.device_list, dev, next);
+ rte_bus_remove_device(&uacce_bus.bus, &dev->device);
free(dev);
}
@@ -505,7 +500,7 @@ uacce_unplug(struct rte_device *dev)
ret = uacce_detach_dev(uacce_dev);
if (ret == 0) {
- TAILQ_REMOVE(&uacce_bus.device_list, uacce_dev, next);
+ rte_bus_remove_device(&uacce_bus.bus, &uacce_dev->device);
rte_devargs_remove(dev->devargs);
free(uacce_dev);
}
@@ -516,20 +511,18 @@ uacce_unplug(struct rte_device *dev)
static struct rte_device *
uacce_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data)
{
- const struct rte_uacce_device *uacce_start;
- struct rte_uacce_device *uacce_dev;
+ struct rte_device *dev;
if (start != NULL) {
- uacce_start = RTE_BUS_DEVICE(start, *uacce_start);
- uacce_dev = TAILQ_NEXT(uacce_start, next);
+ dev = TAILQ_NEXT(start, next);
} else {
- uacce_dev = TAILQ_FIRST(&uacce_bus.device_list);
+ dev = TAILQ_FIRST(&uacce_bus.bus.device_list);
}
- while (uacce_dev != NULL) {
- if (cmp(&uacce_dev->device, data) == 0)
- return &uacce_dev->device;
- uacce_dev = TAILQ_NEXT(uacce_dev, next);
+ while (dev != NULL) {
+ if (cmp(dev, data) == 0)
+ return dev;
+ dev = TAILQ_NEXT(dev, next);
}
return NULL;
@@ -707,7 +700,6 @@ static struct rte_uacce_bus uacce_bus = {
.parse = uacce_parse,
.dev_iterate = uacce_dev_iterate,
},
- .device_list = TAILQ_HEAD_INITIALIZER(uacce_bus.device_list),
};
RTE_REGISTER_BUS(uacce, uacce_bus.bus);
diff --git a/drivers/bus/vdev/bus_vdev_driver.h b/drivers/bus/vdev/bus_vdev_driver.h
index eceaa56696..8d114e4b3b 100644
--- a/drivers/bus/vdev/bus_vdev_driver.h
+++ b/drivers/bus/vdev/bus_vdev_driver.h
@@ -16,7 +16,6 @@ extern "C" {
#endif
struct rte_vdev_device {
- RTE_TAILQ_ENTRY(rte_vdev_device) next; /**< Next attached vdev */
struct rte_device device; /**< Inherit core device */
};
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index c360c38ed5..db73b08c38 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -31,9 +31,6 @@
/* Forward declare to access virtual bus name */
static struct rte_bus rte_vdev_bus;
-
-static TAILQ_HEAD(, rte_vdev_device) vdev_device_list =
- TAILQ_HEAD_INITIALIZER(vdev_device_list);
/* The lock needs to be recursive because a vdev can manage another vdev. */
static rte_spinlock_recursive_t vdev_device_list_lock =
RTE_SPINLOCK_RECURSIVE_INITIALIZER;
@@ -198,7 +195,7 @@ find_vdev(const char *name)
if (!name)
return NULL;
- TAILQ_FOREACH(dev, &vdev_device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_vdev_bus) {
const char *devname = rte_vdev_device_name(dev);
if (!strcmp(devname, name))
@@ -262,7 +259,6 @@ insert_vdev(const char *name, const char *args,
goto fail;
}
- dev->device.bus = &rte_vdev_bus;
dev->device.numa_node = SOCKET_ID_ANY;
if (find_vdev(name)) {
@@ -279,7 +275,7 @@ insert_vdev(const char *name, const char *args,
rte_devargs_insert(&devargs);
dev->device.devargs = devargs;
dev->device.name = devargs->name;
- TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+ rte_bus_add_device(&rte_vdev_bus, &dev->device);
if (p_dev)
*p_dev = dev;
@@ -307,7 +303,7 @@ rte_vdev_init(const char *name, const char *args)
if (ret > 0)
VDEV_LOG(ERR, "no driver found for %s", name);
/* If fails, remove it from vdev list */
- TAILQ_REMOVE(&vdev_device_list, dev, next);
+ rte_bus_remove_device(&rte_vdev_bus, &dev->device);
rte_devargs_remove(dev->device.devargs);
free(dev);
}
@@ -354,7 +350,7 @@ rte_vdev_uninit(const char *name)
if (ret)
goto unlock;
- TAILQ_REMOVE(&vdev_device_list, dev, next);
+ rte_bus_remove_device(&rte_vdev_bus, &dev->device);
rte_devargs_remove(dev->device.devargs);
free(dev);
@@ -405,7 +401,7 @@ vdev_action(const struct rte_mp_msg *mp_msg, const void *peer)
num = 0;
rte_spinlock_recursive_lock(&vdev_device_list_lock);
- TAILQ_FOREACH(dev, &vdev_device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_vdev_bus) {
devname = rte_vdev_device_name(dev);
if (strlen(devname) == 0) {
VDEV_LOG(INFO, "vdev with no name is not sent");
@@ -511,12 +507,11 @@ vdev_scan(void)
continue;
}
- dev->device.bus = &rte_vdev_bus;
dev->device.devargs = devargs;
dev->device.numa_node = SOCKET_ID_ANY;
dev->device.name = devargs->name;
- TAILQ_INSERT_TAIL(&vdev_device_list, dev, next);
+ rte_bus_add_device(&rte_vdev_bus, &dev->device);
rte_spinlock_recursive_unlock(&vdev_device_list_lock);
}
@@ -531,7 +526,7 @@ vdev_probe(void)
int r, ret = 0;
/* call the init function for each virtual device */
- TAILQ_FOREACH(dev, &vdev_device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_vdev_bus) {
/* we don't use the vdev lock here, as it's only used in DPDK
* initialization; and we don't want to hold such a lock when
* we call each driver probe.
@@ -553,10 +548,10 @@ vdev_probe(void)
static int
vdev_cleanup(void)
{
- struct rte_vdev_device *dev, *tmp_dev;
+ struct rte_vdev_device *dev;
int error = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &vdev_device_list, next, tmp_dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_vdev_bus) {
const struct rte_vdev_driver *drv;
int ret;
@@ -574,7 +569,7 @@ vdev_cleanup(void)
dev->device.driver = NULL;
free:
- TAILQ_REMOVE(&vdev_device_list, dev, next);
+ rte_bus_remove_device(&rte_vdev_bus, &dev->device);
free(dev);
}
@@ -585,24 +580,22 @@ struct rte_device *
rte_vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- const struct rte_vdev_device *vstart;
- struct rte_vdev_device *dev;
+ struct rte_device *dev;
rte_spinlock_recursive_lock(&vdev_device_list_lock);
- if (start != NULL) {
- vstart = RTE_BUS_DEVICE(start, *vstart);
- dev = TAILQ_NEXT(vstart, next);
- } else {
- dev = TAILQ_FIRST(&vdev_device_list);
- }
+ if (start != NULL)
+ dev = TAILQ_NEXT(start, next);
+ else
+ dev = TAILQ_FIRST(&rte_vdev_bus.device_list);
+
while (dev != NULL) {
- if (cmp(&dev->device, data) == 0)
+ if (cmp(dev, data) == 0)
break;
dev = TAILQ_NEXT(dev, next);
}
rte_spinlock_recursive_unlock(&vdev_device_list_lock);
- return dev ? &dev->device : NULL;
+ return dev;
}
static int
@@ -624,7 +617,7 @@ vdev_get_iommu_class(void)
struct rte_vdev_device *dev;
struct rte_vdev_driver *driver;
- TAILQ_FOREACH(dev, &vdev_device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_vdev_bus) {
name = rte_vdev_device_name(dev);
if (vdev_parse(name, &driver))
continue;
diff --git a/drivers/bus/vmbus/bus_vmbus_driver.h b/drivers/bus/vmbus/bus_vmbus_driver.h
index 4a06ff8e66..d53bda2340 100644
--- a/drivers/bus/vmbus/bus_vmbus_driver.h
+++ b/drivers/bus/vmbus/bus_vmbus_driver.h
@@ -37,7 +37,6 @@ enum hv_uio_map {
* A structure describing a VMBUS device.
*/
struct rte_vmbus_device {
- RTE_TAILQ_ENTRY(rte_vmbus_device) next; /**< Next probed VMBUS device */
const struct rte_vmbus_driver *driver; /**< Associated driver */
struct rte_device device; /**< Inherit core device */
rte_uuid_t device_id; /**< VMBUS device id */
diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c b/drivers/bus/vmbus/linux/vmbus_bus.c
index 5958b97077..6268a14d40 100644
--- a/drivers/bus/vmbus/linux/vmbus_bus.c
+++ b/drivers/bus/vmbus/linux/vmbus_bus.c
@@ -288,7 +288,6 @@ vmbus_scan_one(const char *name)
if (dev == NULL)
return -1;
- dev->device.bus = &rte_vmbus_bus.bus;
dev->device.name = dev_name = strdup(name);
if (!dev->device.name)
goto error;
@@ -357,7 +356,7 @@ vmbus_scan_one(const char *name)
/* device is valid, add in list (sorted) */
VMBUS_LOG(DEBUG, "Adding vmbus device %s", name);
- TAILQ_FOREACH(dev2, &rte_vmbus_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev2, &rte_vmbus_bus.bus) {
int ret;
ret = rte_uuid_compare(dev->device_id, dev2->device_id);
@@ -365,7 +364,7 @@ vmbus_scan_one(const char *name)
continue;
if (ret < 0) {
- vmbus_insert_device(dev2, dev);
+ rte_bus_insert_device(&rte_vmbus_bus.bus, &dev2->device, &dev->device);
} else { /* already registered */
VMBUS_LOG(NOTICE,
"%s already registered", name);
@@ -375,7 +374,7 @@ vmbus_scan_one(const char *name)
return 0;
}
- vmbus_add_device(dev);
+ rte_bus_add_device(&rte_vmbus_bus.bus, &dev->device);
return 0;
error:
VMBUS_LOG(DEBUG, "failed");
diff --git a/drivers/bus/vmbus/private.h b/drivers/bus/vmbus/private.h
index bd1151385c..6abb97c607 100644
--- a/drivers/bus/vmbus/private.h
+++ b/drivers/bus/vmbus/private.h
@@ -20,15 +20,10 @@
*/
struct rte_vmbus_bus {
struct rte_bus bus; /**< Inherit the generic class */
- RTE_TAILQ_HEAD(, rte_vmbus_device) device_list; /**< List of devices */
};
extern struct rte_vmbus_bus rte_vmbus_bus;
-/* VMBus iterators */
-#define FOREACH_DEVICE_ON_VMBUS(p) \
- RTE_TAILQ_FOREACH(p, &(rte_vmbus_bus.device_list), next)
-
extern int vmbus_logtype_bus;
#define RTE_LOGTYPE_VMBUS_BUS vmbus_logtype_bus
#define VMBUS_LOG(level, ...) \
@@ -98,11 +93,6 @@ int vmbus_chan_create(const struct rte_vmbus_device *device,
uint16_t relid, uint16_t subid, uint8_t monitor_id,
struct vmbus_channel **new_chan);
-void vmbus_add_device(struct rte_vmbus_device *vmbus_dev);
-void vmbus_insert_device(struct rte_vmbus_device *exist_vmbus_dev,
- struct rte_vmbus_device *new_vmbus_dev);
-void vmbus_remove_device(struct rte_vmbus_device *vmbus_device);
-
void vmbus_uio_irq_control(const struct rte_vmbus_device *dev, int32_t onoff);
int vmbus_uio_irq_read(struct rte_vmbus_device *dev);
diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
index a414f0a892..889b9347d7 100644
--- a/drivers/bus/vmbus/vmbus_common.c
+++ b/drivers/bus/vmbus/vmbus_common.c
@@ -181,7 +181,7 @@ rte_vmbus_probe(void)
size_t probed = 0, failed = 0;
char ubuf[RTE_UUID_STRLEN];
- FOREACH_DEVICE_ON_VMBUS(dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_vmbus_bus.bus) {
probed++;
rte_uuid_unparse(dev->device_id, ubuf, sizeof(ubuf));
@@ -203,10 +203,10 @@ rte_vmbus_probe(void)
static int
rte_vmbus_cleanup(void)
{
- struct rte_vmbus_device *dev, *tmp_dev;
+ struct rte_vmbus_device *dev;
int error = 0;
- RTE_TAILQ_FOREACH_SAFE(dev, &rte_vmbus_bus.device_list, next, tmp_dev) {
+ RTE_BUS_FOREACH_DEV(dev, &rte_vmbus_bus.bus) {
const struct rte_vmbus_driver *drv = dev->driver;
int ret;
@@ -223,7 +223,7 @@ rte_vmbus_cleanup(void)
dev->driver = NULL;
dev->device.driver = NULL;
- TAILQ_REMOVE(&rte_vmbus_bus.device_list, dev, next);
+ rte_bus_remove_device(&rte_vmbus_bus.bus, &dev->device);
free(dev);
}
@@ -274,42 +274,20 @@ rte_vmbus_unregister(struct rte_vmbus_driver *driver)
rte_bus_remove_driver(&rte_vmbus_bus.bus, &driver->driver);
}
-/* Add a device to VMBUS bus */
-void
-vmbus_add_device(struct rte_vmbus_device *vmbus_dev)
-{
- TAILQ_INSERT_TAIL(&rte_vmbus_bus.device_list, vmbus_dev, next);
-}
-
-/* Insert a device into a predefined position in VMBUS bus */
-void
-vmbus_insert_device(struct rte_vmbus_device *exist_vmbus_dev,
- struct rte_vmbus_device *new_vmbus_dev)
-{
- TAILQ_INSERT_BEFORE(exist_vmbus_dev, new_vmbus_dev, next);
-}
-
-/* Remove a device from VMBUS bus */
-void
-vmbus_remove_device(struct rte_vmbus_device *vmbus_dev)
-{
- TAILQ_REMOVE(&rte_vmbus_bus.device_list, vmbus_dev, next);
-}
-
/* VMBUS doesn't support hotplug */
static struct rte_device *
vmbus_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- struct rte_vmbus_device *dev;
+ struct rte_device *dev;
- FOREACH_DEVICE_ON_VMBUS(dev) {
- if (start && &dev->device == start) {
+ TAILQ_FOREACH(dev, &rte_vmbus_bus.bus.device_list, next) {
+ if (start && dev == start) {
start = NULL;
continue;
}
- if (cmp(&dev->device, data) == 0)
- return &dev->device;
+ if (cmp(dev, data) == 0)
+ return dev;
}
return NULL;
@@ -325,7 +303,6 @@ struct rte_vmbus_bus rte_vmbus_bus = {
.parse = vmbus_parse,
.dev_compare = vmbus_dev_compare,
},
- .device_list = TAILQ_HEAD_INITIALIZER(rte_vmbus_bus.device_list),
};
RTE_REGISTER_BUS(vmbus, rte_vmbus_bus.bus);
diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
index 7f4920b274..b3e691a2bd 100644
--- a/drivers/dma/idxd/idxd_bus.c
+++ b/drivers/dma/idxd/idxd_bus.c
@@ -49,16 +49,12 @@ static struct rte_device *dsa_find_device(const struct rte_device *start,
static enum rte_iova_mode dsa_get_iommu_class(void);
static int dsa_addr_parse(const char *name, void *addr);
-/** List of devices */
-TAILQ_HEAD(dsa_device_list, rte_dsa_device);
-
/**
* Structure describing the DSA bus
*/
struct dsa_bus {
struct rte_bus bus; /**< Inherit the generic class */
struct rte_driver driver; /**< Driver struct for devices to point to */
- struct dsa_device_list device_list; /**< List of PCI devices */
};
struct dsa_bus dsa_bus = {
@@ -72,7 +68,6 @@ struct dsa_bus dsa_bus = {
.driver = {
.name = "dmadev_idxd",
},
- .device_list = TAILQ_HEAD_INITIALIZER(dsa_bus.device_list),
};
static inline const char *
@@ -274,7 +269,7 @@ dsa_probe(void)
{
struct rte_dsa_device *dev;
- TAILQ_FOREACH(dev, &dsa_bus.device_list, next) {
+ RTE_BUS_FOREACH_DEV(dev, &dsa_bus.bus) {
char type[64], name[64];
if (read_wq_string(dev, "type", type, sizeof(type)) < 0 ||
@@ -332,9 +327,8 @@ dsa_scan(void)
free(dev);
continue;
}
- dev->device.bus = &dsa_bus.bus;
strlcpy(dev->wq_name, wq->d_name, sizeof(dev->wq_name));
- TAILQ_INSERT_TAIL(&dsa_bus.device_list, dev, next);
+ rte_bus_add_device(&dsa_bus.bus, &dev->device);
devcount++;
read_device_int(dev, "numa_node", &numa_node);
@@ -350,16 +344,13 @@ static struct rte_device *
dsa_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
const void *data)
{
- struct rte_dsa_device *dev = TAILQ_FIRST(&dsa_bus.device_list);
-
- /* the rte_device struct must be at start of dsa structure */
- RTE_BUILD_BUG_ON(offsetof(struct rte_dsa_device, device) != 0);
+ struct rte_device *dev = TAILQ_FIRST(&dsa_bus.bus.device_list);
if (start != NULL) /* jump to start point if given */
- dev = TAILQ_NEXT((const struct rte_dsa_device *)start, next);
+ dev = TAILQ_NEXT(start, next);
while (dev != NULL) {
- if (cmp(&dev->device, data) == 0)
- return &dev->device;
+ if (cmp(dev, data) == 0)
+ return dev;
dev = TAILQ_NEXT(dev, next);
}
return NULL;
diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c
index e155936014..2748e99826 100644
--- a/lib/eal/common/eal_common_bus.c
+++ b/lib/eal/common/eal_common_bus.c
@@ -38,6 +38,7 @@ rte_bus_register(struct rte_bus *bus)
/* Buses supporting driver plug also require unplug. */
RTE_VERIFY(!bus->plug || bus->unplug);
+ TAILQ_INIT(&bus->device_list);
TAILQ_INIT(&bus->driver_list);
TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
EAL_LOG(DEBUG, "Registered [%s] bus.", rte_bus_name(bus));
@@ -371,6 +372,32 @@ rte_bus_sigbus_handler(const void *failure_addr)
return ret;
}
+RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_add_device)
+void
+rte_bus_add_device(struct rte_bus *bus, struct rte_device *dev)
+{
+ TAILQ_INSERT_TAIL(&bus->device_list, dev, next);
+ dev->bus = bus;
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_remove_device)
+void
+rte_bus_remove_device(struct rte_bus *bus, struct rte_device *dev)
+{
+ TAILQ_REMOVE(&bus->device_list, dev, next);
+ dev->bus = NULL;
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_insert_device)
+void
+rte_bus_insert_device(struct rte_bus *bus,
+ struct rte_device *exist_dev,
+ struct rte_device *new_dev)
+{
+ TAILQ_INSERT_BEFORE(exist_dev, new_dev, next);
+ new_dev->bus = bus;
+}
+
RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_add_driver)
void
rte_bus_add_driver(struct rte_bus *bus, struct rte_driver *driver)
diff --git a/lib/eal/include/bus_driver.h b/lib/eal/include/bus_driver.h
index 3c8f661a17..5b40fcd606 100644
--- a/lib/eal/include/bus_driver.h
+++ b/lib/eal/include/bus_driver.h
@@ -286,6 +286,7 @@ struct rte_bus {
rte_bus_sigbus_handler_t sigbus_handler;
/**< handle sigbus error on the bus */
rte_bus_cleanup_t cleanup; /**< Cleanup devices on bus */
+ RTE_TAILQ_HEAD(, rte_device) device_list; /**< List of devices on the bus */
RTE_TAILQ_HEAD(, rte_driver) driver_list; /**< List of drivers on the bus */
};
@@ -371,6 +372,64 @@ void rte_bus_unregister(struct rte_bus *bus);
#define RTE_BUS_DRIVER(drv, bus_drv_type) \
container_of(drv, typeof(bus_drv_type), driver)
+/**
+ * Helper macro to iterate over all devices on a bus.
+ *
+ * @param dev
+ * Variable name for the bus-specific device pointer.
+ * @param bus
+ * Pointer to the bus structure.
+ *
+ * Example:
+ * struct rte_pci_device *pci_dev;
+ * RTE_BUS_FOREACH_DEV(pci_dev, &pci_bus.bus) {
+ * // Use pci_dev here
+ * }
+ */
+#define RTE_BUS_FOREACH_DEV(dev, bus) \
+ for (struct rte_device *__rte_dev = TAILQ_FIRST(&(bus)->device_list), *__rte_dev_tmp; \
+ (__rte_dev != NULL && ((dev) = RTE_BUS_DEVICE(__rte_dev, *dev), \
+ __rte_dev_tmp = TAILQ_NEXT(__rte_dev, next), 1)) || \
+ (dev = NULL, 0); \
+ __rte_dev = __rte_dev_tmp)
+
+/**
+ * Add a device to the bus device list.
+ *
+ * @param bus
+ * A pointer to a rte_bus structure.
+ * @param dev
+ * A pointer to a rte_device structure to add.
+ */
+__rte_internal
+void rte_bus_add_device(struct rte_bus *bus, struct rte_device *dev);
+
+/**
+ * Remove a device from the bus device list.
+ *
+ * @param bus
+ * A pointer to a rte_bus structure.
+ * @param dev
+ * A pointer to a rte_device structure to remove.
+ */
+__rte_internal
+void rte_bus_remove_device(struct rte_bus *bus, struct rte_device *dev);
+
+/**
+ * Insert a device before another in the bus device list.
+ *
+ * @param bus
+ * A pointer to a rte_bus structure.
+ * @param exist_dev
+ * Existing device in the list.
+ * @param new_dev
+ * New device to insert before exist_dev.
+ */
+__rte_internal
+void rte_bus_insert_device(struct rte_bus *bus,
+ struct rte_device *exist_dev,
+ struct rte_device *new_dev);
+
/**
* Helper macro to iterate over all drivers on a bus.
*
--
2.53.0
^ permalink raw reply related
* [PATCH v2 07/23] bus: factorize driver list
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Parav Pandit, Xueming Li,
Nipun Gupta, Nikhil Agarwal, Hemant Agrawal, Sachin Saxena,
Rosen Xu, Chenbo Xia, Tomasz Duszynski, Chengwen Feng, Long Li,
Wei Hu, Kevin Laatz
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
Move driver_list management from individual bus implementations to
common EAL bus code. This eliminates duplication and provides a
consistent API for driver registration across all buses.
Introduce rte_bus_add_driver() and rte_bus_remove_driver() helpers that
manage a per-bus driver list internally in EAL. Update all buses to use
these common helpers and remove bus-specific driver_list fields and
iteration macros.
Store a reference to the bus object in the generic driver.
Also update the dma/idxd code that has only one hardcoded driver.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/auxiliary/auxiliary_common.c | 11 +++--
drivers/bus/auxiliary/bus_auxiliary_driver.h | 1 -
drivers/bus/auxiliary/linux/auxiliary.c | 3 +-
drivers/bus/auxiliary/private.h | 4 --
drivers/bus/cdx/bus_cdx_driver.h | 2 -
drivers/bus/cdx/cdx.c | 12 ++----
drivers/bus/cdx/private.h | 1 -
drivers/bus/dpaa/bus_dpaa_driver.h | 1 -
drivers/bus/dpaa/dpaa_bus.c | 8 ++--
drivers/bus/fslmc/bus_fslmc_driver.h | 1 -
drivers/bus/fslmc/fslmc_bus.c | 11 +++--
drivers/bus/fslmc/private.h | 2 -
drivers/bus/ifpga/bus_ifpga_driver.h | 3 +-
drivers/bus/ifpga/ifpga_bus.c | 9 ++--
drivers/bus/pci/bus_pci_driver.h | 1 -
drivers/bus/pci/pci_common.c | 9 ++--
drivers/bus/pci/private.h | 4 --
drivers/bus/platform/bus_platform_driver.h | 1 -
drivers/bus/platform/platform.c | 9 ++--
drivers/bus/platform/private.h | 4 --
drivers/bus/uacce/bus_uacce_driver.h | 2 -
drivers/bus/uacce/uacce.c | 12 ++----
drivers/bus/vdev/bus_vdev_driver.h | 1 -
drivers/bus/vdev/vdev.c | 9 ++--
drivers/bus/vmbus/bus_vmbus_driver.h | 1 -
drivers/bus/vmbus/private.h | 4 --
drivers/bus/vmbus/vmbus_common.c | 7 ++--
drivers/dma/idxd/idxd_bus.c | 6 ++-
lib/eal/common/eal_common_bus.c | 17 ++++++++
lib/eal/include/bus_driver.h | 44 ++++++++++++++++++++
lib/eal/include/dev_driver.h | 1 +
31 files changed, 106 insertions(+), 95 deletions(-)
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index afb4a7ce1b..7e2d832dda 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -171,7 +171,7 @@ auxiliary_probe_all_drivers(struct rte_auxiliary_device *dev)
struct rte_auxiliary_driver *drv;
int rc;
- FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) {
+ RTE_BUS_FOREACH_DRV(drv, &auxiliary_bus.bus) {
if (!drv->match(dev->name))
continue;
@@ -226,7 +226,7 @@ auxiliary_parse(const char *name, void *addr)
if (strlen(name) == 0)
return 0;
- FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) {
+ RTE_BUS_FOREACH_DRV(drv, &auxiliary_bus.bus) {
if (drv->match(name))
break;
}
@@ -240,7 +240,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_auxiliary_register)
void
rte_auxiliary_register(struct rte_auxiliary_driver *driver)
{
- TAILQ_INSERT_TAIL(&auxiliary_bus.driver_list, driver, next);
+ rte_bus_add_driver(&auxiliary_bus.bus, &driver->driver);
}
/* Unregister a driver */
@@ -248,7 +248,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_auxiliary_unregister)
void
rte_auxiliary_unregister(struct rte_auxiliary_driver *driver)
{
- TAILQ_REMOVE(&auxiliary_bus.driver_list, driver, next);
+ rte_bus_remove_driver(&auxiliary_bus.bus, &driver->driver);
}
/* Add a device to auxiliary bus */
@@ -369,7 +369,7 @@ auxiliary_get_iommu_class(void)
{
const struct rte_auxiliary_driver *drv;
- FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) {
+ RTE_BUS_FOREACH_DRV(drv, &auxiliary_bus.bus) {
if ((drv->drv_flags & RTE_AUXILIARY_DRV_NEED_IOVA_AS_VA) > 0)
return RTE_IOVA_VA;
}
@@ -392,7 +392,6 @@ struct rte_auxiliary_bus auxiliary_bus = {
.dev_iterate = auxiliary_dev_iterate,
},
.device_list = TAILQ_HEAD_INITIALIZER(auxiliary_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(auxiliary_bus.driver_list),
};
RTE_REGISTER_BUS(auxiliary, auxiliary_bus.bus);
diff --git a/drivers/bus/auxiliary/bus_auxiliary_driver.h b/drivers/bus/auxiliary/bus_auxiliary_driver.h
index 5c14592f6f..59c46e08a0 100644
--- a/drivers/bus/auxiliary/bus_auxiliary_driver.h
+++ b/drivers/bus/auxiliary/bus_auxiliary_driver.h
@@ -121,7 +121,6 @@ struct rte_auxiliary_device {
* A structure describing an auxiliary driver.
*/
struct rte_auxiliary_driver {
- RTE_TAILQ_ENTRY(rte_auxiliary_driver) next; /**< Next in list. */
struct rte_driver driver; /**< Inherit core driver. */
rte_auxiliary_match_t *match; /**< Device match function. */
rte_auxiliary_probe_t *probe; /**< Device probe function. */
diff --git a/drivers/bus/auxiliary/linux/auxiliary.c b/drivers/bus/auxiliary/linux/auxiliary.c
index 4cfd0a266c..7c430629d0 100644
--- a/drivers/bus/auxiliary/linux/auxiliary.c
+++ b/drivers/bus/auxiliary/linux/auxiliary.c
@@ -117,7 +117,8 @@ auxiliary_scan(void)
AUXILIARY_SYSFS_PATH, e->d_name);
/* Ignore if no driver can handle. */
- FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) {
+ drv = NULL;
+ RTE_BUS_FOREACH_DRV(drv, &auxiliary_bus.bus) {
if (drv->match(e->d_name))
break;
}
diff --git a/drivers/bus/auxiliary/private.h b/drivers/bus/auxiliary/private.h
index 6e61a5f494..66ba97b946 100644
--- a/drivers/bus/auxiliary/private.h
+++ b/drivers/bus/auxiliary/private.h
@@ -25,7 +25,6 @@ extern int auxiliary_bus_logtype;
struct rte_auxiliary_bus {
struct rte_bus bus; /* Inherit the generic class */
TAILQ_HEAD(, rte_auxiliary_device) device_list; /* List of devices */
- TAILQ_HEAD(, rte_auxiliary_driver) driver_list; /* List of drivers */
};
extern struct rte_auxiliary_bus auxiliary_bus;
@@ -34,9 +33,6 @@ extern struct rte_auxiliary_bus auxiliary_bus;
#define FOREACH_DEVICE_ON_AUXILIARY_BUS(p) \
TAILQ_FOREACH(p, &(auxiliary_bus.device_list), next)
-#define FOREACH_DRIVER_ON_AUXILIARY_BUS(p) \
- TAILQ_FOREACH(p, &(auxiliary_bus.driver_list), next)
-
/*
* Test whether the auxiliary device exist.
*/
diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index 935e37158a..823a5b1be3 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -91,9 +91,7 @@ typedef int (rte_cdx_remove_t)(struct rte_cdx_device *);
* A structure describing a CDX driver.
*/
struct rte_cdx_driver {
- RTE_TAILQ_ENTRY(rte_cdx_driver) next; /**< Next in list. */
struct rte_driver driver; /**< Inherit core driver. */
- struct rte_cdx_bus *bus; /**< CDX bus reference. */
rte_cdx_probe_t *probe; /**< Device probe function. */
rte_cdx_remove_t *remove; /**< Device remove function. */
const struct rte_cdx_id *id_table; /**< ID table, NULL terminated. */
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 267c7598c7..5973f75be2 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -88,9 +88,6 @@
#define FOREACH_DEVICE_ON_CDXBUS(p) \
RTE_TAILQ_FOREACH(p, &rte_cdx_bus.device_list, next)
-#define FOREACH_DRIVER_ON_CDXBUS(p) \
- RTE_TAILQ_FOREACH(p, &rte_cdx_bus.driver_list, next)
-
struct rte_cdx_bus rte_cdx_bus;
enum cdx_params {
@@ -394,7 +391,7 @@ cdx_probe_all_drivers(struct rte_cdx_device *dev)
struct rte_cdx_driver *dr = NULL;
int rc = 0;
- FOREACH_DRIVER_ON_CDXBUS(dr) {
+ RTE_BUS_FOREACH_DRV(dr, &rte_cdx_bus.bus) {
rc = cdx_probe_one_driver(dr, dev);
if (rc < 0)
/* negative value is an error */
@@ -453,8 +450,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_cdx_register)
void
rte_cdx_register(struct rte_cdx_driver *driver)
{
- TAILQ_INSERT_TAIL(&rte_cdx_bus.driver_list, driver, next);
- driver->bus = &rte_cdx_bus;
+ rte_bus_add_driver(&rte_cdx_bus.bus, &driver->driver);
}
/* unregister a driver */
@@ -462,8 +458,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_cdx_unregister)
void
rte_cdx_unregister(struct rte_cdx_driver *driver)
{
- TAILQ_REMOVE(&rte_cdx_bus.driver_list, driver, next);
- driver->bus = NULL;
+ rte_bus_remove_driver(&rte_cdx_bus.bus, &driver->driver);
}
static struct rte_device *
@@ -630,7 +625,6 @@ struct rte_cdx_bus rte_cdx_bus = {
.dev_iterate = cdx_dev_iterate,
},
.device_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(rte_cdx_bus.driver_list),
};
RTE_REGISTER_BUS(cdx, rte_cdx_bus.bus);
diff --git a/drivers/bus/cdx/private.h b/drivers/bus/cdx/private.h
index 81987d0cfe..3807a17bfb 100644
--- a/drivers/bus/cdx/private.h
+++ b/drivers/bus/cdx/private.h
@@ -13,7 +13,6 @@
struct rte_cdx_bus {
struct rte_bus bus; /**< Inherit the generic class */
RTE_TAILQ_HEAD(, rte_cdx_device) device_list; /**< List of CDX devices */
- RTE_TAILQ_HEAD(, rte_cdx_driver) driver_list; /**< List of CDX drivers */
};
/**
diff --git a/drivers/bus/dpaa/bus_dpaa_driver.h b/drivers/bus/dpaa/bus_dpaa_driver.h
index 64cbfd8e92..1575ed19e7 100644
--- a/drivers/bus/dpaa/bus_dpaa_driver.h
+++ b/drivers/bus/dpaa/bus_dpaa_driver.h
@@ -98,7 +98,6 @@ typedef int (*rte_dpaa_probe_t)(struct rte_dpaa_driver *dpaa_drv,
typedef int (*rte_dpaa_remove_t)(struct rte_dpaa_device *dpaa_dev);
struct rte_dpaa_driver {
- TAILQ_ENTRY(rte_dpaa_driver) next;
struct rte_driver driver;
enum rte_dpaa_type drv_type;
rte_dpaa_probe_t probe;
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index ca6fd06ac0..f9f902cbd6 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -60,7 +60,6 @@
struct rte_dpaa_bus {
struct rte_bus bus;
TAILQ_HEAD(, rte_dpaa_device) device_list;
- TAILQ_HEAD(, rte_dpaa_driver) driver_list;
int device_count;
int detected;
uint32_t svr_ver;
@@ -618,7 +617,7 @@ rte_dpaa_driver_register(struct rte_dpaa_driver *driver)
BUS_INIT_FUNC_TRACE();
- TAILQ_INSERT_TAIL(&rte_dpaa_bus.driver_list, driver, next);
+ rte_bus_add_driver(&rte_dpaa_bus.bus, &driver->driver);
}
/* un-register a dpaa bus based dpaa driver */
@@ -628,7 +627,7 @@ rte_dpaa_driver_unregister(struct rte_dpaa_driver *driver)
{
BUS_INIT_FUNC_TRACE();
- TAILQ_REMOVE(&rte_dpaa_bus.driver_list, driver, next);
+ rte_bus_remove_driver(&rte_dpaa_bus.bus, &driver->driver);
}
static int
@@ -797,7 +796,7 @@ rte_dpaa_bus_probe(void)
/* For each registered driver, and device, call the driver->probe */
TAILQ_FOREACH(dev, &rte_dpaa_bus.device_list, next) {
- TAILQ_FOREACH(drv, &rte_dpaa_bus.driver_list, next) {
+ RTE_BUS_FOREACH_DRV(drv, &rte_dpaa_bus.bus) {
ret = rte_dpaa_device_match(drv, dev);
if (ret)
continue;
@@ -990,7 +989,6 @@ static struct rte_dpaa_bus rte_dpaa_bus = {
},
.max_push_rxq_num = DPAA_DEFAULT_PUSH_MODE_QUEUE,
.device_list = TAILQ_HEAD_INITIALIZER(rte_dpaa_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(rte_dpaa_bus.driver_list),
.device_count = 0,
};
diff --git a/drivers/bus/fslmc/bus_fslmc_driver.h b/drivers/bus/fslmc/bus_fslmc_driver.h
index 51bca8a6ef..c82b182720 100644
--- a/drivers/bus/fslmc/bus_fslmc_driver.h
+++ b/drivers/bus/fslmc/bus_fslmc_driver.h
@@ -138,7 +138,6 @@ rte_fslmc_vfio_mem_dmaunmap(uint64_t iova, uint64_t size);
* A structure describing a DPAA2 driver.
*/
struct rte_dpaa2_driver {
- TAILQ_ENTRY(rte_dpaa2_driver) next; /**< Next in list. */
struct rte_driver driver; /**< Inherit core driver. */
uint32_t drv_flags; /**< Flags for controlling device.*/
enum rte_dpaa2_dev_type drv_type; /**< Driver Type */
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 59c9d85bb8..36ec018785 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -457,7 +457,7 @@ rte_fslmc_probe(void)
}
TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
- TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
+ RTE_BUS_FOREACH_DRV(drv, &rte_fslmc_bus.bus) {
ret = rte_fslmc_match(drv, dev);
if (ret)
continue;
@@ -522,7 +522,7 @@ rte_fslmc_driver_register(struct rte_dpaa2_driver *driver)
RTE_VERIFY(driver);
RTE_VERIFY(driver->probe != NULL);
- TAILQ_INSERT_TAIL(&rte_fslmc_bus.driver_list, driver, next);
+ rte_bus_add_driver(&rte_fslmc_bus.bus, &driver->driver);
}
/*un-register a fslmc bus based dpaa2 driver */
@@ -530,7 +530,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_fslmc_driver_unregister)
void
rte_fslmc_driver_unregister(struct rte_dpaa2_driver *driver)
{
- TAILQ_REMOVE(&rte_fslmc_bus.driver_list, driver, next);
+ rte_bus_remove_driver(&rte_fslmc_bus.bus, &driver->driver);
}
/*
@@ -544,7 +544,7 @@ fslmc_all_device_support_iova(void)
struct rte_dpaa2_driver *drv;
TAILQ_FOREACH(dev, &rte_fslmc_bus.device_list, next) {
- TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
+ RTE_BUS_FOREACH_DRV(drv, &rte_fslmc_bus.bus) {
ret = rte_fslmc_match(drv, dev);
if (ret)
continue;
@@ -582,7 +582,7 @@ fslmc_bus_plug(struct rte_device *rte_dev)
struct rte_dpaa2_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
struct rte_dpaa2_driver *drv;
- TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
+ RTE_BUS_FOREACH_DRV(drv, &rte_fslmc_bus.bus) {
ret = rte_fslmc_match(drv, dev);
if (ret)
continue;
@@ -688,7 +688,6 @@ struct rte_fslmc_bus rte_fslmc_bus = {
.dev_iterate = fslmc_bus_dev_iterate,
},
.device_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(rte_fslmc_bus.driver_list),
.device_count = {0},
};
diff --git a/drivers/bus/fslmc/private.h b/drivers/bus/fslmc/private.h
index 6f14085d98..338f55b094 100644
--- a/drivers/bus/fslmc/private.h
+++ b/drivers/bus/fslmc/private.h
@@ -16,8 +16,6 @@ struct rte_fslmc_bus {
struct rte_bus bus; /**< Generic Bus object */
TAILQ_HEAD(, rte_dpaa2_device) device_list;
/**< FSLMC DPAA2 Device list */
- TAILQ_HEAD(, rte_dpaa2_driver) driver_list;
- /**< FSLMC DPAA2 Driver list */
int device_count[DPAA2_DEVTYPE_MAX];
/**< Count of all devices scanned */
};
diff --git a/drivers/bus/ifpga/bus_ifpga_driver.h b/drivers/bus/ifpga/bus_ifpga_driver.h
index b0ba8c9e64..7d724dc1a0 100644
--- a/drivers/bus/ifpga/bus_ifpga_driver.h
+++ b/drivers/bus/ifpga/bus_ifpga_driver.h
@@ -91,10 +91,9 @@ typedef int (afu_probe_t)(struct rte_afu_device *);
typedef int (afu_remove_t)(struct rte_afu_device *);
/**
- * A structure describing a AFU device.
+ * A structure describing a AFU driver.
*/
struct rte_afu_driver {
- RTE_TAILQ_ENTRY(rte_afu_driver) next; /**< Next afu driver. */
struct rte_driver driver; /**< Inherit core driver. */
afu_probe_t *probe; /**< Device Probe function. */
afu_remove_t *remove; /**< Device Remove function. */
diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 63f6a01cde..c038144ebd 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -40,9 +40,6 @@ static struct rte_bus rte_ifpga_bus;
static TAILQ_HEAD(, rte_afu_device) ifpga_afu_dev_list =
TAILQ_HEAD_INITIALIZER(ifpga_afu_dev_list);
-static TAILQ_HEAD(, rte_afu_driver) ifpga_afu_drv_list =
- TAILQ_HEAD_INITIALIZER(ifpga_afu_drv_list);
-
/* register a ifpga bus based driver */
RTE_EXPORT_INTERNAL_SYMBOL(rte_ifpga_driver_register)
@@ -50,14 +47,14 @@ void rte_ifpga_driver_register(struct rte_afu_driver *driver)
{
RTE_VERIFY(driver);
- TAILQ_INSERT_TAIL(&ifpga_afu_drv_list, driver, next);
+ rte_bus_add_driver(&rte_ifpga_bus, &driver->driver);
}
/* un-register a fpga bus based driver */
RTE_EXPORT_INTERNAL_SYMBOL(rte_ifpga_driver_unregister)
void rte_ifpga_driver_unregister(struct rte_afu_driver *driver)
{
- TAILQ_REMOVE(&ifpga_afu_drv_list, driver, next);
+ rte_bus_remove_driver(&rte_ifpga_bus, &driver->driver);
}
static struct rte_afu_device *
@@ -309,7 +306,7 @@ ifpga_probe_all_drivers(struct rte_afu_device *afu_dev)
return -EEXIST;
}
- TAILQ_FOREACH(drv, &ifpga_afu_drv_list, next) {
+ RTE_BUS_FOREACH_DRV(drv, &rte_ifpga_bus) {
ret = ifpga_probe_one_driver(drv, afu_dev);
if (ret < 0)
/* negative value is an error */
diff --git a/drivers/bus/pci/bus_pci_driver.h b/drivers/bus/pci/bus_pci_driver.h
index 22ab962f05..993d690f96 100644
--- a/drivers/bus/pci/bus_pci_driver.h
+++ b/drivers/bus/pci/bus_pci_driver.h
@@ -122,7 +122,6 @@ typedef int (pci_dma_unmap_t)(struct rte_pci_device *dev, void *addr,
* A structure describing a PCI driver.
*/
struct rte_pci_driver {
- RTE_TAILQ_ENTRY(rte_pci_driver) next; /**< Next in list. */
struct rte_driver driver; /**< Inherit core driver. */
rte_pci_probe_t *probe; /**< Device probe function. */
rte_pci_remove_t *remove; /**< Device remove function. */
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index f3d7878966..79cc14a6dd 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -358,7 +358,7 @@ pci_probe_all_drivers(struct rte_pci_device *dev)
if (dev == NULL)
return -EINVAL;
- FOREACH_DRIVER_ON_PCIBUS(dr) {
+ RTE_BUS_FOREACH_DRV(dr, &rte_pci_bus.bus) {
rc = rte_pci_probe_one_driver(dr, dev);
if (rc < 0)
/* negative value is an error */
@@ -501,7 +501,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_register)
void
rte_pci_register(struct rte_pci_driver *driver)
{
- TAILQ_INSERT_TAIL(&rte_pci_bus.driver_list, driver, next);
+ rte_bus_add_driver(&rte_pci_bus.bus, &driver->driver);
}
/* unregister a driver */
@@ -509,7 +509,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_pci_unregister)
void
rte_pci_unregister(struct rte_pci_driver *driver)
{
- TAILQ_REMOVE(&rte_pci_bus.driver_list, driver, next);
+ rte_bus_remove_driver(&rte_pci_bus.bus, &driver->driver);
}
/* Add a device to PCI bus */
@@ -720,7 +720,7 @@ rte_pci_get_iommu_class(void)
if (dev->kdrv == RTE_PCI_KDRV_UNKNOWN ||
dev->kdrv == RTE_PCI_KDRV_NONE)
continue;
- FOREACH_DRIVER_ON_PCIBUS(drv) {
+ RTE_BUS_FOREACH_DRV(drv, &rte_pci_bus.bus) {
enum rte_iova_mode dev_iova_mode;
if (!rte_pci_match(drv, dev))
@@ -917,7 +917,6 @@ struct rte_pci_bus rte_pci_bus = {
.sigbus_handler = pci_sigbus_handler,
},
.device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
};
RTE_REGISTER_BUS(pci, rte_pci_bus.bus);
diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h
index 8591c4a0a7..8b5f563dc3 100644
--- a/drivers/bus/pci/private.h
+++ b/drivers/bus/pci/private.h
@@ -35,7 +35,6 @@ extern int pci_bus_logtype;
struct rte_pci_bus {
struct rte_bus bus; /**< Inherit the generic class */
RTE_TAILQ_HEAD(, rte_pci_device) device_list; /**< List of PCI devices */
- RTE_TAILQ_HEAD(, rte_pci_driver) driver_list; /**< List of PCI drivers */
};
extern struct rte_pci_bus rte_pci_bus;
@@ -44,9 +43,6 @@ extern struct rte_pci_bus rte_pci_bus;
#define FOREACH_DEVICE_ON_PCIBUS(p) \
RTE_TAILQ_FOREACH(p, &(rte_pci_bus.device_list), next)
-#define FOREACH_DRIVER_ON_PCIBUS(p) \
- RTE_TAILQ_FOREACH(p, &(rte_pci_bus.driver_list), next)
-
struct rte_pci_driver;
struct rte_pci_device;
diff --git a/drivers/bus/platform/bus_platform_driver.h b/drivers/bus/platform/bus_platform_driver.h
index 09eb08e347..a72d5c00a3 100644
--- a/drivers/bus/platform/bus_platform_driver.h
+++ b/drivers/bus/platform/bus_platform_driver.h
@@ -107,7 +107,6 @@ struct rte_platform_device {
* A structure describing a platform device driver.
*/
struct rte_platform_driver {
- RTE_TAILQ_ENTRY(rte_platform_driver) next; /**< Next available platform driver */
struct rte_driver driver; /**< Core driver */
rte_platform_probe_t *probe; /**< Device probe function */
rte_platform_remove_t *remove; /**< Device remove function */
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index 0e57473f25..9d3c4877b0 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -33,14 +33,14 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_platform_register)
void
rte_platform_register(struct rte_platform_driver *pdrv)
{
- TAILQ_INSERT_TAIL(&platform_bus.driver_list, pdrv, next);
+ rte_bus_add_driver(&platform_bus.bus, &pdrv->driver);
}
RTE_EXPORT_INTERNAL_SYMBOL(rte_platform_unregister)
void
rte_platform_unregister(struct rte_platform_driver *pdrv)
{
- TAILQ_REMOVE(&platform_bus.driver_list, pdrv, next);
+ rte_bus_remove_driver(&platform_bus.bus, &pdrv->driver);
}
static int
@@ -408,7 +408,7 @@ device_attach(struct rte_platform_device *pdev)
{
struct rte_platform_driver *pdrv;
- FOREACH_DRIVER_ON_PLATFORM_BUS(pdrv) {
+ RTE_BUS_FOREACH_DRV(pdrv, &platform_bus.bus) {
if (driver_match_device(pdrv, pdev))
break;
}
@@ -510,7 +510,7 @@ platform_bus_parse(const char *name, void *addr)
rte_strscpy(pdev.name, name, sizeof(pdev.name));
- FOREACH_DRIVER_ON_PLATFORM_BUS(pdrv) {
+ RTE_BUS_FOREACH_DRV(pdrv, &platform_bus.bus) {
if (driver_match_device(pdrv, &pdev))
break;
}
@@ -589,7 +589,6 @@ struct rte_platform_bus platform_bus = {
.cleanup = platform_bus_cleanup,
},
.device_list = TAILQ_HEAD_INITIALIZER(platform_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(platform_bus.driver_list),
};
RTE_REGISTER_BUS(platform, platform_bus.bus);
diff --git a/drivers/bus/platform/private.h b/drivers/bus/platform/private.h
index d89ba0e4a5..f7ee80f3ac 100644
--- a/drivers/bus/platform/private.h
+++ b/drivers/bus/platform/private.h
@@ -20,16 +20,12 @@ extern struct rte_platform_bus platform_bus;
#define FOREACH_DEVICE_ON_PLATFORM_BUS(p) \
RTE_TAILQ_FOREACH(p, &(platform_bus.device_list), next)
-#define FOREACH_DRIVER_ON_PLATFORM_BUS(p) \
- RTE_TAILQ_FOREACH(p, &(platform_bus.driver_list), next)
-
/*
* Structure describing platform bus.
*/
struct rte_platform_bus {
struct rte_bus bus; /* Core bus */
RTE_TAILQ_HEAD(, rte_platform_device) device_list; /* List of bus devices */
- RTE_TAILQ_HEAD(, rte_platform_driver) driver_list; /* List of bus drivers */
};
extern int platform_bus_logtype;
diff --git a/drivers/bus/uacce/bus_uacce_driver.h b/drivers/bus/uacce/bus_uacce_driver.h
index 476afbc857..051e1736cf 100644
--- a/drivers/bus/uacce/bus_uacce_driver.h
+++ b/drivers/bus/uacce/bus_uacce_driver.h
@@ -85,9 +85,7 @@ typedef int (rte_uacce_remove_t)(struct rte_uacce_device *);
* A structure describing a UACCE driver.
*/
struct rte_uacce_driver {
- RTE_TAILQ_ENTRY(rte_uacce_driver) next; /**< Next in list. */
struct rte_driver driver; /**< Inherit core driver. */
- struct rte_uacce_bus *bus; /**< UACCE bus reference. */
rte_uacce_probe_t *probe; /**< Device probe function. */
rte_uacce_remove_t *remove; /**< Device remove function. */
const struct rte_uacce_id *id_table; /**< ID table, NULL terminated. */
diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c
index 6e1eb73e68..c0a1e1d8ec 100644
--- a/drivers/bus/uacce/uacce.c
+++ b/drivers/bus/uacce/uacce.c
@@ -40,7 +40,6 @@
struct rte_uacce_bus {
struct rte_bus bus; /* Inherit the generic class. */
TAILQ_HEAD(, rte_uacce_device) device_list; /* List of devices. */
- TAILQ_HEAD(, rte_uacce_driver) driver_list; /* List of drivers. */
};
/* Forward declaration of UACCE bus. */
@@ -57,8 +56,6 @@ static const char *const uacce_params_keys[] = {
#define FOREACH_DEVICE_ON_UACCEBUS(p) \
RTE_TAILQ_FOREACH(p, &uacce_bus.device_list, next)
-#define FOREACH_DRIVER_ON_UACCEBUS(p) \
- RTE_TAILQ_FOREACH(p, &uacce_bus.driver_list, next)
extern int uacce_bus_logtype;
#define RTE_LOGTYPE_UACCE_BUS uacce_bus_logtype
@@ -407,7 +404,7 @@ uacce_probe_all_drivers(struct rte_uacce_device *dev)
struct rte_uacce_driver *dr;
int rc;
- FOREACH_DRIVER_ON_UACCEBUS(dr) {
+ RTE_BUS_FOREACH_DRV(dr, &uacce_bus.bus) {
rc = uacce_probe_one_driver(dr, dev);
if (rc < 0)
/* negative value is an error */
@@ -689,16 +686,14 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_register)
void
rte_uacce_register(struct rte_uacce_driver *driver)
{
- TAILQ_INSERT_TAIL(&uacce_bus.driver_list, driver, next);
- driver->bus = &uacce_bus;
+ rte_bus_add_driver(&uacce_bus.bus, &driver->driver);
}
RTE_EXPORT_INTERNAL_SYMBOL(rte_uacce_unregister)
void
rte_uacce_unregister(struct rte_uacce_driver *driver)
{
- TAILQ_REMOVE(&uacce_bus.driver_list, driver, next);
- driver->bus = NULL;
+ rte_bus_remove_driver(&uacce_bus.bus, &driver->driver);
}
static struct rte_uacce_bus uacce_bus = {
@@ -713,7 +708,6 @@ static struct rte_uacce_bus uacce_bus = {
.dev_iterate = uacce_dev_iterate,
},
.device_list = TAILQ_HEAD_INITIALIZER(uacce_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(uacce_bus.driver_list),
};
RTE_REGISTER_BUS(uacce, uacce_bus.bus);
diff --git a/drivers/bus/vdev/bus_vdev_driver.h b/drivers/bus/vdev/bus_vdev_driver.h
index f352daabda..eceaa56696 100644
--- a/drivers/bus/vdev/bus_vdev_driver.h
+++ b/drivers/bus/vdev/bus_vdev_driver.h
@@ -91,7 +91,6 @@ typedef int (rte_vdev_dma_unmap_t)(struct rte_vdev_device *dev, void *addr,
* A virtual device driver abstraction.
*/
struct rte_vdev_driver {
- RTE_TAILQ_ENTRY(rte_vdev_driver) next; /**< Next in list. */
struct rte_driver driver; /**< Inherited general driver. */
rte_vdev_probe_t *probe; /**< Virtual device probe function. */
rte_vdev_remove_t *remove; /**< Virtual device remove function. */
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index ea81b755e3..c360c38ed5 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -38,9 +38,6 @@ static TAILQ_HEAD(, rte_vdev_device) vdev_device_list =
static rte_spinlock_recursive_t vdev_device_list_lock =
RTE_SPINLOCK_RECURSIVE_INITIALIZER;
-static TAILQ_HEAD(, rte_vdev_driver) vdev_driver_list =
- TAILQ_HEAD_INITIALIZER(vdev_driver_list);
-
struct vdev_custom_scan {
TAILQ_ENTRY(vdev_custom_scan) next;
rte_vdev_scan_callback callback;
@@ -56,7 +53,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_vdev_register)
void
rte_vdev_register(struct rte_vdev_driver *driver)
{
- TAILQ_INSERT_TAIL(&vdev_driver_list, driver, next);
+ rte_bus_add_driver(&rte_vdev_bus, &driver->driver);
}
/* unregister a driver */
@@ -64,7 +61,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_vdev_unregister)
void
rte_vdev_unregister(struct rte_vdev_driver *driver)
{
- TAILQ_REMOVE(&vdev_driver_list, driver, next);
+ rte_bus_remove_driver(&rte_vdev_bus, &driver->driver);
}
RTE_EXPORT_SYMBOL(rte_vdev_add_custom_scan)
@@ -123,7 +120,7 @@ vdev_parse(const char *name, void *addr)
struct rte_vdev_driver **out = addr;
struct rte_vdev_driver *driver = NULL;
- TAILQ_FOREACH(driver, &vdev_driver_list, next) {
+ RTE_BUS_FOREACH_DRV(driver, &rte_vdev_bus) {
if (strncmp(driver->driver.name, name,
strlen(driver->driver.name)) == 0)
break;
diff --git a/drivers/bus/vmbus/bus_vmbus_driver.h b/drivers/bus/vmbus/bus_vmbus_driver.h
index fca512db31..4a06ff8e66 100644
--- a/drivers/bus/vmbus/bus_vmbus_driver.h
+++ b/drivers/bus/vmbus/bus_vmbus_driver.h
@@ -68,7 +68,6 @@ typedef int (vmbus_remove_t)(struct rte_vmbus_device *);
* A structure describing a VMBUS driver.
*/
struct rte_vmbus_driver {
- RTE_TAILQ_ENTRY(rte_vmbus_driver) next; /**< Next in list. */
struct rte_driver driver;
vmbus_probe_t *probe; /**< Device Probe function. */
vmbus_remove_t *remove; /**< Device Remove function. */
diff --git a/drivers/bus/vmbus/private.h b/drivers/bus/vmbus/private.h
index 8ac6119ef2..bd1151385c 100644
--- a/drivers/bus/vmbus/private.h
+++ b/drivers/bus/vmbus/private.h
@@ -21,7 +21,6 @@
struct rte_vmbus_bus {
struct rte_bus bus; /**< Inherit the generic class */
RTE_TAILQ_HEAD(, rte_vmbus_device) device_list; /**< List of devices */
- RTE_TAILQ_HEAD(, rte_vmbus_driver) driver_list; /**< List of drivers */
};
extern struct rte_vmbus_bus rte_vmbus_bus;
@@ -30,9 +29,6 @@ extern struct rte_vmbus_bus rte_vmbus_bus;
#define FOREACH_DEVICE_ON_VMBUS(p) \
RTE_TAILQ_FOREACH(p, &(rte_vmbus_bus.device_list), next)
-#define FOREACH_DRIVER_ON_VMBUS(p) \
- RTE_TAILQ_FOREACH(p, &(rte_vmbus_bus.driver_list), next)
-
extern int vmbus_logtype_bus;
#define RTE_LOGTYPE_VMBUS_BUS vmbus_logtype_bus
#define VMBUS_LOG(level, ...) \
diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
index d38c75d597..a414f0a892 100644
--- a/drivers/bus/vmbus/vmbus_common.c
+++ b/drivers/bus/vmbus/vmbus_common.c
@@ -155,7 +155,7 @@ vmbus_probe_all_drivers(struct rte_vmbus_device *dev)
return 0;
}
- FOREACH_DRIVER_ON_VMBUS(dr) {
+ RTE_BUS_FOREACH_DRV(dr, &rte_vmbus_bus.bus) {
rc = vmbus_probe_one_driver(dr, dev);
if (rc < 0) /* negative is an error */
return -1;
@@ -263,7 +263,7 @@ rte_vmbus_register(struct rte_vmbus_driver *driver)
VMBUS_LOG(DEBUG,
"Registered driver %s", driver->driver.name);
- TAILQ_INSERT_TAIL(&rte_vmbus_bus.driver_list, driver, next);
+ rte_bus_add_driver(&rte_vmbus_bus.bus, &driver->driver);
}
/* unregister vmbus driver */
@@ -271,7 +271,7 @@ RTE_EXPORT_INTERNAL_SYMBOL(rte_vmbus_unregister)
void
rte_vmbus_unregister(struct rte_vmbus_driver *driver)
{
- TAILQ_REMOVE(&rte_vmbus_bus.driver_list, driver, next);
+ rte_bus_remove_driver(&rte_vmbus_bus.bus, &driver->driver);
}
/* Add a device to VMBUS bus */
@@ -326,7 +326,6 @@ struct rte_vmbus_bus rte_vmbus_bus = {
.dev_compare = vmbus_dev_compare,
},
.device_list = TAILQ_HEAD_INITIALIZER(rte_vmbus_bus.device_list),
- .driver_list = TAILQ_HEAD_INITIALIZER(rte_vmbus_bus.driver_list),
};
RTE_REGISTER_BUS(vmbus, rte_vmbus_bus.bus);
diff --git a/drivers/dma/idxd/idxd_bus.c b/drivers/dma/idxd/idxd_bus.c
index 291cd6c707..7f4920b274 100644
--- a/drivers/dma/idxd/idxd_bus.c
+++ b/drivers/dma/idxd/idxd_bus.c
@@ -70,7 +70,7 @@ struct dsa_bus dsa_bus = {
.parse = dsa_addr_parse,
},
.driver = {
- .name = "dmadev_idxd"
+ .name = "dmadev_idxd",
},
.device_list = TAILQ_HEAD_INITIALIZER(dsa_bus.device_list),
};
@@ -392,3 +392,7 @@ dsa_addr_parse(const char *name, void *addr)
}
RTE_REGISTER_BUS(dsa, dsa_bus.bus);
+RTE_INIT(dsa_bus_init)
+{
+ rte_bus_add_driver(&dsa_bus.bus, &dsa_bus.driver);
+}
diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c
index b33f5b4bf4..e155936014 100644
--- a/lib/eal/common/eal_common_bus.c
+++ b/lib/eal/common/eal_common_bus.c
@@ -38,6 +38,7 @@ rte_bus_register(struct rte_bus *bus)
/* Buses supporting driver plug also require unplug. */
RTE_VERIFY(!bus->plug || bus->unplug);
+ TAILQ_INIT(&bus->driver_list);
TAILQ_INSERT_TAIL(&rte_bus_list, bus, next);
EAL_LOG(DEBUG, "Registered [%s] bus.", rte_bus_name(bus));
}
@@ -369,3 +370,19 @@ rte_bus_sigbus_handler(const void *failure_addr)
return ret;
}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_add_driver)
+void
+rte_bus_add_driver(struct rte_bus *bus, struct rte_driver *driver)
+{
+ TAILQ_INSERT_TAIL(&bus->driver_list, driver, next);
+ driver->bus = bus;
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(rte_bus_remove_driver)
+void
+rte_bus_remove_driver(struct rte_bus *bus, struct rte_driver *driver)
+{
+ TAILQ_REMOVE(&bus->driver_list, driver, next);
+ driver->bus = NULL;
+}
diff --git a/lib/eal/include/bus_driver.h b/lib/eal/include/bus_driver.h
index 71346fb8b2..3c8f661a17 100644
--- a/lib/eal/include/bus_driver.h
+++ b/lib/eal/include/bus_driver.h
@@ -286,6 +286,7 @@ struct rte_bus {
rte_bus_sigbus_handler_t sigbus_handler;
/**< handle sigbus error on the bus */
rte_bus_cleanup_t cleanup; /**< Cleanup devices on bus */
+ RTE_TAILQ_HEAD(, rte_driver) driver_list; /**< List of drivers on the bus */
};
/**
@@ -370,6 +371,49 @@ void rte_bus_unregister(struct rte_bus *bus);
#define RTE_BUS_DRIVER(drv, bus_drv_type) \
container_of(drv, typeof(bus_drv_type), driver)
+/**
+ * Helper macro to iterate over all drivers on a bus.
+ *
+ * @param drv
+ * Variable name for the bus-specific driver pointer.
+ * @param bus
+ * Pointer to the bus structure.
+ *
+ * Example:
+ * struct rte_pci_driver *pci_drv;
+ * RTE_BUS_FOREACH_DRV(pci_drv, &pci_bus.bus) {
+ * // Use pci_drv here
+ * }
+ */
+#define RTE_BUS_FOREACH_DRV(drv, bus) \
+ for (struct rte_driver *__rte_drv = TAILQ_FIRST(&(bus)->driver_list), *__rte_drv_tmp; \
+ (__rte_drv != NULL && ((drv) = RTE_BUS_DRIVER(__rte_drv, *drv), \
+ __rte_drv_tmp = TAILQ_NEXT(__rte_drv, next), 1)) || \
+ (drv = NULL, 0); \
+ __rte_drv = __rte_drv_tmp)
+
+/**
+ * Add a driver to the bus driver list.
+ *
+ * @param bus
+ * A pointer to a rte_bus structure.
+ * @param driver
+ * A pointer to a rte_driver structure to add.
+ */
+__rte_internal
+void rte_bus_add_driver(struct rte_bus *bus, struct rte_driver *driver);
+
+/**
+ * Remove a driver from the bus driver list.
+ *
+ * @param bus
+ * A pointer to a rte_bus structure.
+ * @param driver
+ * A pointer to a rte_driver structure to remove.
+ */
+__rte_internal
+void rte_bus_remove_driver(struct rte_bus *bus, struct rte_driver *driver);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/eal/include/dev_driver.h b/lib/eal/include/dev_driver.h
index a2517ac1d4..2052e3ecb2 100644
--- a/lib/eal/include/dev_driver.h
+++ b/lib/eal/include/dev_driver.h
@@ -15,6 +15,7 @@ struct rte_driver {
RTE_TAILQ_ENTRY(rte_driver) next; /**< Next in list. */
const char *name; /**< Driver name. */
const char *alias; /**< Driver alias. */
+ const struct rte_bus *bus; /**< Bus reference. */
};
/**
--
2.53.0
^ permalink raw reply related
* [PATCH v2 06/23] bus: add bus conversion macros
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Nicolas Chautru, Parav Pandit,
Xueming Li, Nipun Gupta, Nikhil Agarwal, Hemant Agrawal,
Sachin Saxena, Rosen Xu, Chenbo Xia, Tomasz Duszynski,
Chengwen Feng, Dariusz Sosnowski, Viacheslav Ovsiienko, Bing Zhao,
Ori Kam, Suanming Mou, Matan Azrad, Ashish Gupta, Fan Zhang,
Ankur Dwivedi, Anoob Joseph, Tejasree Kondoj, Gagandeep Singh,
Pavan Nikhilesh, Shijith Thotton, Tirthendu Sarkar, Jerin Jacob,
Selwin Sebastian, Julien Aube, Kishore Padmanabha, Ajit Khaparde,
Chas Williams, Min Hu (Connor), Jeroen de Borst,
Joshua Washington, Xingui Yang, Praveen Shetty, Anatoly Burakov,
Jingjing Wu, Long Li, Wei Hu, Devendra Singh Rawat, Alok Prasad,
Wenbo Cao
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
Introduce two generic macros to replace all bus-specific device and
driver conversion macros:
- RTE_BUS_DEVICE(dev, bus_dev_type): Converts a generic rte_device
pointer to a bus-specific device structure using typeof() to infer
the correct type. The second parameter can be either a struct type
(e.g., struct rte_pci_device) or a dereferenced pointer variable
(e.g., *pdev) for automatic type inference.
- RTE_BUS_DRIVER(drv, bus_drv_type): Converts a generic rte_driver
pointer to a bus-specific driver structure using the same approach.
All bus drivers and device class drivers have been updated to use
these generic macros instead of their bus-specific conversion macros
(RTE_DEV_TO_*, DEV_TO_*) or direct container_of() calls.
Ethernet device convenience macros (RTE_ETH_DEV_TO_*) have been updated
to use RTE_BUS_DEVICE internally.
Usage patterns:
- For pre-existing variables: pdev = RTE_BUS_DEVICE(dev, *pdev);
- For new declarations:
struct rte_pci_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
- For inline conversions: foo(RTE_BUS_DEVICE(dev, struct rte_pci_device));
- For const conversions: RTE_BUS_DEVICE(dev, const struct rte_pci_device);
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v1:
- fix build on Windows,
---
drivers/baseband/acc/rte_acc100_pmd.c | 4 +--
drivers/baseband/acc/rte_vrb_pmd.c | 2 +-
.../fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 4 +--
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c | 2 +-
drivers/bus/auxiliary/auxiliary_common.c | 10 +++----
drivers/bus/auxiliary/bus_auxiliary_driver.h | 13 ++------
drivers/bus/cdx/bus_cdx_driver.h | 10 -------
drivers/bus/cdx/cdx.c | 6 ++--
drivers/bus/dpaa/bus_dpaa_driver.h | 7 +----
drivers/bus/dpaa/dpaa_bus.c | 4 +--
drivers/bus/fslmc/bus_fslmc_driver.h | 4 +--
drivers/bus/fslmc/fslmc_bus.c | 10 +++----
drivers/bus/ifpga/bus_ifpga_driver.h | 8 +----
drivers/bus/ifpga/ifpga_bus.c | 4 +--
drivers/bus/pci/bus_pci_driver.h | 13 ++------
drivers/bus/pci/pci_common.c | 12 ++++----
drivers/bus/pci/pci_params.c | 2 +-
drivers/bus/platform/bus_platform_driver.h | 10 -------
drivers/bus/platform/platform.c | 17 +++++++----
drivers/bus/uacce/bus_uacce_driver.h | 10 -------
drivers/bus/uacce/uacce.c | 6 ++--
drivers/bus/vdev/bus_vdev_driver.h | 14 ++-------
drivers/bus/vdev/vdev.c | 24 ++++++---------
drivers/common/mlx5/linux/mlx5_common_os.c | 5 ++--
drivers/common/mlx5/mlx5_common.c | 2 +-
drivers/common/mlx5/mlx5_common_pci.c | 2 +-
drivers/common/mlx5/windows/mlx5_common_os.c | 2 +-
drivers/compress/octeontx/otx_zip.c | 2 +-
drivers/crypto/cnxk/cnxk_cryptodev_ops.c | 2 +-
drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 2 +-
drivers/crypto/octeontx/otx_cryptodev_ops.c | 4 +--
drivers/event/cnxk/cnxk_eventdev.c | 2 +-
drivers/event/dlb2/pf/dlb2_pf.c | 2 +-
drivers/event/skeleton/skeleton_eventdev.c | 2 +-
drivers/net/axgbe/axgbe_ethdev.c | 4 +--
drivers/net/bnx2x/bnx2x_ethdev.c | 2 +-
drivers/net/bnxt/bnxt_ethdev.c | 2 +-
drivers/net/bnxt/tf_ulp/bnxt_ulp.c | 4 +--
drivers/net/bonding/rte_eth_bond_args.c | 2 +-
drivers/net/dpaa/dpaa_ethdev.c | 13 ++++----
drivers/net/dpaa2/dpaa2_ethdev.c | 6 ++--
drivers/net/dpaa2/dpaa2_recycle.c | 6 ++--
drivers/net/gve/gve_ethdev.c | 2 +-
drivers/net/hns3/hns3_ethdev.c | 4 +--
drivers/net/hns3/hns3_rxtx.c | 2 +-
drivers/net/intel/cpfl/cpfl_ethdev.c | 4 +--
drivers/net/intel/cpfl/cpfl_ethdev.h | 2 +-
drivers/net/intel/i40e/i40e_ethdev.h | 2 +-
drivers/net/intel/ice/ice_ethdev.c | 4 +--
drivers/net/intel/ice/ice_ethdev.h | 2 +-
drivers/net/intel/idpf/idpf_ethdev.h | 2 +-
drivers/net/intel/ipn3ke/ipn3ke_ethdev.h | 12 +-------
drivers/net/mlx5/linux/mlx5_os.c | 9 +++---
drivers/net/mlx5/windows/mlx5_os.c | 4 +--
drivers/net/netvsc/hn_ethdev.c | 2 +-
drivers/net/qede/qede_ethdev.c | 2 +-
drivers/net/rnp/rnp_ethdev.c | 6 ++--
drivers/raw/ifpga/afu_pmd_n3000.c | 4 +--
lib/eal/include/bus_driver.h | 30 +++++++++++++++++++
59 files changed, 152 insertions(+), 203 deletions(-)
diff --git a/drivers/baseband/acc/rte_acc100_pmd.c b/drivers/baseband/acc/rte_acc100_pmd.c
index b7f02f56e1..061f595a98 100644
--- a/drivers/baseband/acc/rte_acc100_pmd.c
+++ b/drivers/baseband/acc/rte_acc100_pmd.c
@@ -3993,7 +3993,7 @@ acc100_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
static void
acc100_bbdev_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
dev->dev_ops = &acc100_bbdev_ops;
dev->enqueue_enc_ops = acc100_enqueue_enc;
@@ -4646,7 +4646,7 @@ rte_acc_configure(const char *dev_name, struct rte_acc_conf *conf)
dev_name);
return -ENODEV;
}
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(bbdev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(bbdev->device, *pci_dev);
rte_bbdev_log(INFO, "Configure dev id %x", pci_dev->id.device_id);
if (pci_dev->id.device_id == ACC100_PF_DEVICE_ID)
return acc100_configure(dev_name, conf);
diff --git a/drivers/baseband/acc/rte_vrb_pmd.c b/drivers/baseband/acc/rte_vrb_pmd.c
index c5161e6502..fe23c01b5c 100644
--- a/drivers/baseband/acc/rte_vrb_pmd.c
+++ b/drivers/baseband/acc/rte_vrb_pmd.c
@@ -4353,7 +4353,7 @@ vrb2_dequeue_mldts(struct rte_bbdev_queue_data *q_data,
static void
vrb_bbdev_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
struct acc_device *d = dev->data->dev_private;
dev->dev_ops = &vrb_bbdev_ops;
diff --git a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
index 82cf98da5d..cb805a1732 100644
--- a/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
+++ b/drivers/baseband/fpga_5gnr_fec/rte_fpga_5gnr_fec.c
@@ -2873,7 +2873,7 @@ fpga_5gnr_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
static void
fpga_5gnr_fec_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
dev->dev_ops = &fpga_5gnr_ops;
dev->enqueue_ldpc_enc_ops = fpga_5gnr_enqueue_ldpc_enc;
@@ -3376,7 +3376,7 @@ int rte_fpga_5gnr_fec_configure(const char *dev_name, const struct rte_fpga_5gnr
dev_name);
return -ENODEV;
}
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(bbdev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(bbdev->device, *pci_dev);
rte_bbdev_log(INFO, "Configure dev id %x", pci_dev->id.device_id);
if (pci_dev->id.device_id == VC_5GNR_PF_DEVICE_ID)
return vc_5gnr_configure(dev_name, conf);
diff --git a/drivers/baseband/fpga_lte_fec/fpga_lte_fec.c b/drivers/baseband/fpga_lte_fec/fpga_lte_fec.c
index 4723a51dcf..d27164c6f4 100644
--- a/drivers/baseband/fpga_lte_fec/fpga_lte_fec.c
+++ b/drivers/baseband/fpga_lte_fec/fpga_lte_fec.c
@@ -2316,7 +2316,7 @@ fpga_dequeue_dec(struct rte_bbdev_queue_data *q_data,
static void
fpga_lte_fec_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
dev->dev_ops = &fpga_ops;
dev->enqueue_enc_ops = fpga_enqueue_enc;
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index 314361643c..afb4a7ce1b 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -281,7 +281,7 @@ auxiliary_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
struct rte_auxiliary_device *adev;
if (start != NULL) {
- pstart = RTE_DEV_TO_AUXILIARY_CONST(start);
+ pstart = RTE_BUS_DEVICE(start, *pstart);
adev = TAILQ_NEXT(pstart, next);
} else {
adev = TAILQ_FIRST(&auxiliary_bus.device_list);
@@ -299,13 +299,13 @@ auxiliary_plug(struct rte_device *dev)
{
if (!auxiliary_dev_exists(dev->name))
return -ENOENT;
- return auxiliary_probe_all_drivers(RTE_DEV_TO_AUXILIARY(dev));
+ return auxiliary_probe_all_drivers(RTE_BUS_DEVICE(dev, struct rte_auxiliary_device));
}
static int
auxiliary_unplug(struct rte_device *dev)
{
- struct rte_auxiliary_device *adev = RTE_DEV_TO_AUXILIARY(dev);
+ struct rte_auxiliary_device *adev = RTE_BUS_DEVICE(dev, *adev);
int ret;
ret = rte_auxiliary_driver_remove_dev(adev);
@@ -342,7 +342,7 @@ auxiliary_cleanup(void)
static int
auxiliary_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev);
+ struct rte_auxiliary_device *aux_dev = RTE_BUS_DEVICE(dev, *aux_dev);
if (aux_dev->driver->dma_map == NULL) {
rte_errno = ENOTSUP;
@@ -355,7 +355,7 @@ static int
auxiliary_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,
size_t len)
{
- struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev);
+ struct rte_auxiliary_device *aux_dev = RTE_BUS_DEVICE(dev, *aux_dev);
if (aux_dev->driver->dma_unmap == NULL) {
rte_errno = ENOTSUP;
diff --git a/drivers/bus/auxiliary/bus_auxiliary_driver.h b/drivers/bus/auxiliary/bus_auxiliary_driver.h
index 8450d56583..5c14592f6f 100644
--- a/drivers/bus/auxiliary/bus_auxiliary_driver.h
+++ b/drivers/bus/auxiliary/bus_auxiliary_driver.h
@@ -22,6 +22,7 @@
#include <rte_debug.h>
#include <rte_interrupts.h>
#include <dev_driver.h>
+#include <bus_driver.h>
#include <rte_kvargs.h>
#ifdef __cplusplus
@@ -130,18 +131,8 @@ struct rte_auxiliary_driver {
uint32_t drv_flags; /**< Flags RTE_AUXILIARY_DRV_*. */
};
-/**
- * @internal
- * Helper macro for drivers that need to convert to struct rte_auxiliary_device.
- */
-#define RTE_DEV_TO_AUXILIARY(ptr) \
- container_of(ptr, struct rte_auxiliary_device, device)
-
-#define RTE_DEV_TO_AUXILIARY_CONST(ptr) \
- container_of(ptr, const struct rte_auxiliary_device, device)
-
#define RTE_ETH_DEV_TO_AUXILIARY(eth_dev) \
- RTE_DEV_TO_AUXILIARY((eth_dev)->device)
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_auxiliary_device)
/** Device driver needs IOVA as VA and cannot work with IOVA as PA */
#define RTE_AUXILIARY_DRV_NEED_IOVA_AS_VA 0x002
diff --git a/drivers/bus/cdx/bus_cdx_driver.h b/drivers/bus/cdx/bus_cdx_driver.h
index f0780a84ad..935e37158a 100644
--- a/drivers/bus/cdx/bus_cdx_driver.h
+++ b/drivers/bus/cdx/bus_cdx_driver.h
@@ -63,16 +63,6 @@ struct rte_cdx_device {
struct rte_intr_handle *intr_handle; /**< Interrupt handle */
};
-/**
- * @internal
- * Helper macro for drivers that need to convert to struct rte_cdx_device.
- */
-#define RTE_DEV_TO_CDX_DEV(ptr) \
- container_of(ptr, struct rte_cdx_device, device)
-
-#define RTE_DEV_TO_CDX_DEV_CONST(ptr) \
- container_of(ptr, const struct rte_cdx_device, device)
-
#define RTE_ETH_DEV_TO_CDX_DEV(eth_dev) RTE_DEV_TO_CDX_DEV((eth_dev)->device)
#ifdef __cplusplus
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index f498b747e2..267c7598c7 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -474,7 +474,7 @@ cdx_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
struct rte_cdx_device *cdx_dev;
if (start != NULL) {
- cdx_start = RTE_DEV_TO_CDX_DEV_CONST(start);
+ cdx_start = RTE_BUS_DEVICE(start, *cdx_start);
cdx_dev = TAILQ_NEXT(cdx_start, next);
} else {
cdx_dev = TAILQ_FIRST(&rte_cdx_bus.device_list);
@@ -528,13 +528,13 @@ cdx_detach_dev(struct rte_cdx_device *dev)
static int
cdx_plug(struct rte_device *dev)
{
- return cdx_probe_all_drivers(RTE_DEV_TO_CDX_DEV(dev));
+ return cdx_probe_all_drivers(RTE_BUS_DEVICE(dev, struct rte_cdx_device));
}
static int
cdx_unplug(struct rte_device *dev)
{
- struct rte_cdx_device *cdx_dev = RTE_DEV_TO_CDX_DEV(dev);
+ struct rte_cdx_device *cdx_dev = RTE_BUS_DEVICE(dev, *cdx_dev);
int ret;
ret = cdx_detach_dev(cdx_dev);
diff --git a/drivers/bus/dpaa/bus_dpaa_driver.h b/drivers/bus/dpaa/bus_dpaa_driver.h
index cca0543432..64cbfd8e92 100644
--- a/drivers/bus/dpaa/bus_dpaa_driver.h
+++ b/drivers/bus/dpaa/bus_dpaa_driver.h
@@ -8,6 +8,7 @@
#include <rte_compat.h>
#include <dev_driver.h>
+#include <bus_driver.h>
#include <rte_mbuf_dyn.h>
#include <rte_mempool.h>
@@ -49,9 +50,6 @@ dpaa_seqn(struct rte_mbuf *mbuf)
#define DPAA_MEMPOOL_OPS_NAME "dpaa"
-#define DEV_TO_DPAA_DEVICE(ptr) \
- container_of(ptr, struct rte_dpaa_device, device)
-
/* DPAA SoC identifier; If this is not available, it can be concluded
* that board is non-DPAA. Single slot is currently supported.
*/
@@ -65,9 +63,6 @@ dpaa_seqn(struct rte_mbuf *mbuf)
/** Number of supported QDMA devices */
#define RTE_DPAA_QDMA_DEVICES 1
-#define RTE_DEV_TO_DPAA_CONST(ptr) \
- container_of(ptr, const struct rte_dpaa_device, device)
-
struct rte_dpaa_device;
struct rte_dpaa_driver;
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index 1bfc44155d..ca6fd06ac0 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -835,7 +835,7 @@ rte_dpaa_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
*/
if (start != NULL) {
- dstart = RTE_DEV_TO_DPAA_CONST(start);
+ dstart = RTE_BUS_DEVICE(start, *dstart);
dev = TAILQ_NEXT(dstart, next);
} else {
dev = TAILQ_FIRST(&rte_dpaa_bus.device_list);
@@ -908,7 +908,7 @@ dpaa_bus_dev_iterate(const void *start, const char *str,
dev_name = dup + strlen("name=");
if (start != NULL) {
- dstart = RTE_DEV_TO_DPAA_CONST(start);
+ dstart = RTE_BUS_DEVICE(start, *dstart);
dev = TAILQ_NEXT(dstart, next);
} else {
dev = TAILQ_FIRST(&rte_dpaa_bus.device_list);
diff --git a/drivers/bus/fslmc/bus_fslmc_driver.h b/drivers/bus/fslmc/bus_fslmc_driver.h
index 89abc3c486..51bca8a6ef 100644
--- a/drivers/bus/fslmc/bus_fslmc_driver.h
+++ b/drivers/bus/fslmc/bus_fslmc_driver.h
@@ -25,6 +25,7 @@
#include <rte_debug.h>
#include <rte_interrupts.h>
#include <dev_driver.h>
+#include <bus_driver.h>
#include <rte_tailq.h>
#include <rte_devargs.h>
#include <rte_mbuf.h>
@@ -67,9 +68,6 @@ dpaa2_seqn(struct rte_mbuf *mbuf)
struct rte_dpaa2_driver;
-#define RTE_DEV_TO_FSLMC_CONST(ptr) \
- container_of(ptr, const struct rte_dpaa2_device, device)
-
enum rte_dpaa2_dev_type {
/* Devices backed by DPDK driver */
DPAA2_ETH, /**< DPNI type device*/
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index 7e5a3e947e..59c9d85bb8 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -497,7 +497,7 @@ rte_fslmc_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
*/
if (start != NULL) {
- dstart = RTE_DEV_TO_FSLMC_CONST(start);
+ dstart = RTE_BUS_DEVICE(start, *dstart);
dev = TAILQ_NEXT(dstart, next);
} else {
dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
@@ -579,8 +579,7 @@ static int
fslmc_bus_plug(struct rte_device *rte_dev)
{
int ret = 0;
- struct rte_dpaa2_device *dev = container_of(rte_dev,
- struct rte_dpaa2_device, device);
+ struct rte_dpaa2_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
struct rte_dpaa2_driver *drv;
TAILQ_FOREACH(drv, &rte_fslmc_bus.driver_list, next) {
@@ -615,8 +614,7 @@ fslmc_bus_plug(struct rte_device *rte_dev)
static int
fslmc_bus_unplug(struct rte_device *rte_dev)
{
- struct rte_dpaa2_device *dev = container_of(rte_dev,
- struct rte_dpaa2_device, device);
+ struct rte_dpaa2_device *dev = RTE_BUS_DEVICE(rte_dev, *dev);
struct rte_dpaa2_driver *drv = dev->driver;
if (drv->remove != NULL) {
@@ -658,7 +656,7 @@ fslmc_bus_dev_iterate(const void *start, const char *str,
dev_name = dup + strlen("name=");
if (start != NULL) {
- dstart = RTE_DEV_TO_FSLMC_CONST(start);
+ dstart = RTE_BUS_DEVICE(start, *dstart);
dev = TAILQ_NEXT(dstart, next);
} else {
dev = TAILQ_FIRST(&rte_fslmc_bus.device_list);
diff --git a/drivers/bus/ifpga/bus_ifpga_driver.h b/drivers/bus/ifpga/bus_ifpga_driver.h
index c0f5fb5b85..b0ba8c9e64 100644
--- a/drivers/bus/ifpga/bus_ifpga_driver.h
+++ b/drivers/bus/ifpga/bus_ifpga_driver.h
@@ -13,6 +13,7 @@
#include <rte_compat.h>
#include <dev_driver.h>
+#include <bus_driver.h>
#include <rte_pci.h>
#include <rte_interrupts.h>
#include <rte_spinlock.h>
@@ -79,13 +80,6 @@ struct rte_afu_device {
char path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
};
-/**
- * @internal
- * Helper macro for drivers that need to convert to struct rte_afu_device.
- */
-#define RTE_DEV_TO_AFU(ptr) \
- container_of(ptr, struct rte_afu_device, device)
-
/**
* Initialization function for the driver called during FPGA BUS probing.
*/
diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 0f331fa6dd..63f6a01cde 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -388,13 +388,13 @@ ifpga_cleanup(void)
static int
ifpga_plug(struct rte_device *dev)
{
- return ifpga_probe_all_drivers(RTE_DEV_TO_AFU(dev));
+ return ifpga_probe_all_drivers(RTE_BUS_DEVICE(dev, struct rte_afu_device));
}
static int
ifpga_unplug(struct rte_device *dev)
{
- struct rte_afu_device *afu_dev = RTE_DEV_TO_AFU(dev);
+ struct rte_afu_device *afu_dev = RTE_BUS_DEVICE(dev, *afu_dev);
int ret;
ret = afu_dev->driver->remove(afu_dev);
diff --git a/drivers/bus/pci/bus_pci_driver.h b/drivers/bus/pci/bus_pci_driver.h
index 54e25c8c2a..22ab962f05 100644
--- a/drivers/bus/pci/bus_pci_driver.h
+++ b/drivers/bus/pci/bus_pci_driver.h
@@ -8,6 +8,7 @@
#include <rte_bus_pci.h>
#include <dev_driver.h>
+#include <bus_driver.h>
#include <rte_compat.h>
#ifdef __cplusplus
@@ -48,16 +49,8 @@ struct rte_pci_device {
/**< Handler of VFIO request interrupt */
};
-/**
- * @internal
- * Helper macro for drivers that need to convert to struct rte_pci_device.
- */
-#define RTE_DEV_TO_PCI(ptr) container_of(ptr, struct rte_pci_device, device)
-
-#define RTE_DEV_TO_PCI_CONST(ptr) \
- container_of(ptr, const struct rte_pci_device, device)
-
-#define RTE_ETH_DEV_TO_PCI(eth_dev) RTE_DEV_TO_PCI((eth_dev)->device)
+#define RTE_ETH_DEV_TO_PCI(eth_dev) \
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_pci_device)
#ifdef __cplusplus
/** C++ macro used to help building up tables of device IDs */
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 1385b0c959..f3d7878966 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -542,7 +542,7 @@ pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
struct rte_pci_device *pdev;
if (start != NULL) {
- pstart = RTE_DEV_TO_PCI_CONST(start);
+ pstart = RTE_BUS_DEVICE(start, *pstart);
pdev = TAILQ_NEXT(pstart, next);
} else {
pdev = TAILQ_FIRST(&rte_pci_bus.device_list);
@@ -588,7 +588,7 @@ pci_find_device_by_addr(const void *failure_addr)
static int
pci_hot_unplug_handler(struct rte_device *dev)
{
- struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
+ struct rte_pci_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
int ret = 0;
switch (pdev->kdrv) {
@@ -642,13 +642,13 @@ pci_sigbus_handler(const void *failure_addr)
static int
pci_plug(struct rte_device *dev)
{
- return pci_probe_all_drivers(RTE_DEV_TO_PCI(dev));
+ return pci_probe_all_drivers(RTE_BUS_DEVICE(dev, struct rte_pci_device));
}
static int
pci_unplug(struct rte_device *dev)
{
- struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
+ struct rte_pci_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
int ret;
ret = rte_pci_detach_dev(pdev);
@@ -663,7 +663,7 @@ pci_unplug(struct rte_device *dev)
static int
pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
+ struct rte_pci_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
if (pdev->driver->dma_map != NULL)
return pdev->driver->dma_map(pdev, addr, iova, len);
@@ -682,7 +682,7 @@ pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
static int
pci_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
+ struct rte_pci_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
if (pdev->driver->dma_unmap != NULL)
return pdev->driver->dma_unmap(pdev, addr, iova, len);
diff --git a/drivers/bus/pci/pci_params.c b/drivers/bus/pci/pci_params.c
index 087ec38bb9..d771d8d1ba 100644
--- a/drivers/bus/pci/pci_params.c
+++ b/drivers/bus/pci/pci_params.c
@@ -49,7 +49,7 @@ pci_dev_match(const struct rte_device *dev,
if (kvlist == NULL)
/* Empty string matches everything. */
return 0;
- pdev = RTE_DEV_TO_PCI_CONST(dev);
+ pdev = RTE_BUS_DEVICE(dev, *pdev);
/* if any field does not match. */
if (rte_kvargs_process(kvlist, pci_params_keys[RTE_PCI_PARAM_ADDR],
&pci_addr_kv_cmp,
diff --git a/drivers/bus/platform/bus_platform_driver.h b/drivers/bus/platform/bus_platform_driver.h
index 76403043c1..09eb08e347 100644
--- a/drivers/bus/platform/bus_platform_driver.h
+++ b/drivers/bus/platform/bus_platform_driver.h
@@ -119,16 +119,6 @@ struct rte_platform_driver {
/** Device driver needs IOVA as VA and cannot work with IOVA as PA */
#define RTE_PLATFORM_DRV_NEED_IOVA_AS_VA 0x0001
-/**
- * @internal
- * Helper macros used to convert core device to platform device.
- */
-#define RTE_DEV_TO_PLATFORM_DEV(ptr) \
- container_of(ptr, struct rte_platform_device, device)
-
-#define RTE_DEV_TO_PLATFORM_DEV_CONST(ptr) \
- container_of(ptr, const struct rte_platform_device, device)
-
/** Helper for platform driver registration. */
#define RTE_PMD_REGISTER_PLATFORM(nm, platform_drv) \
static const char *pdrvinit_ ## nm ## _alias; \
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index 5cc0d69209..0e57473f25 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -441,10 +441,15 @@ platform_bus_probe(void)
static struct rte_device *
platform_bus_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void *data)
{
+ const struct rte_platform_device *pstart;
struct rte_platform_device *pdev;
- pdev = start ? RTE_TAILQ_NEXT(RTE_DEV_TO_PLATFORM_DEV_CONST(start), next) :
- RTE_TAILQ_FIRST(&platform_bus.device_list);
+ if (start != NULL) {
+ pstart = RTE_BUS_DEVICE(start, *pstart);
+ pdev = TAILQ_NEXT(pstart, next);
+ } else {
+ pdev = RTE_TAILQ_FIRST(&platform_bus.device_list);
+ }
while (pdev) {
if (cmp(&pdev->device, data) == 0)
return &pdev->device;
@@ -464,7 +469,7 @@ platform_bus_plug(struct rte_device *dev)
if (!dev_is_bound_vfio_platform(dev->name))
return -EPERM;
- return device_attach(RTE_DEV_TO_PLATFORM_DEV(dev));
+ return device_attach(RTE_BUS_DEVICE(dev, struct rte_platform_device));
}
static void
@@ -486,7 +491,7 @@ device_release_driver(struct rte_platform_device *pdev)
static int
platform_bus_unplug(struct rte_device *dev)
{
- struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
+ struct rte_platform_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
device_release_driver(pdev);
device_cleanup(pdev);
@@ -519,7 +524,7 @@ platform_bus_parse(const char *name, void *addr)
static int
platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
+ struct rte_platform_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
if (pdev->driver->dma_map != NULL)
return pdev->driver->dma_map(pdev, addr, iova, len);
@@ -530,7 +535,7 @@ platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t l
static int
platform_bus_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
+ struct rte_platform_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
if (pdev->driver->dma_unmap != NULL)
return pdev->driver->dma_unmap(pdev, addr, iova, len);
diff --git a/drivers/bus/uacce/bus_uacce_driver.h b/drivers/bus/uacce/bus_uacce_driver.h
index c7445778a6..476afbc857 100644
--- a/drivers/bus/uacce/bus_uacce_driver.h
+++ b/drivers/bus/uacce/bus_uacce_driver.h
@@ -57,16 +57,6 @@ struct rte_uacce_device {
uint32_t qfrt_sz[RTE_UACCE_QFRT_BUTT]; /**< Queue file region type's size. */
};
-/**
- * @internal
- * Helper macro for drivers that need to convert to struct rte_uacce_device.
- */
-#define RTE_DEV_TO_UACCE_DEV(ptr) \
- container_of(ptr, struct rte_uacce_device, device)
-
-#define RTE_DEV_TO_UACCE_DEV_CONST(ptr) \
- container_of(ptr, const struct rte_uacce_device, device)
-
/**
* A structure describing an ID for a UACCE driver. Each driver provides a
* table of these IDs for each device that it supports.
diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c
index d0ea454911..6e1eb73e68 100644
--- a/drivers/bus/uacce/uacce.c
+++ b/drivers/bus/uacce/uacce.c
@@ -477,7 +477,7 @@ uacce_cleanup(void)
static int
uacce_plug(struct rte_device *dev)
{
- return uacce_probe_all_drivers(RTE_DEV_TO_UACCE_DEV(dev));
+ return uacce_probe_all_drivers(RTE_BUS_DEVICE(dev, struct rte_uacce_device));
}
static int
@@ -503,7 +503,7 @@ uacce_detach_dev(struct rte_uacce_device *dev)
static int
uacce_unplug(struct rte_device *dev)
{
- struct rte_uacce_device *uacce_dev = RTE_DEV_TO_UACCE_DEV(dev);
+ struct rte_uacce_device *uacce_dev = RTE_BUS_DEVICE(dev, *uacce_dev);
int ret;
ret = uacce_detach_dev(uacce_dev);
@@ -523,7 +523,7 @@ uacce_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, const void
struct rte_uacce_device *uacce_dev;
if (start != NULL) {
- uacce_start = RTE_DEV_TO_UACCE_DEV_CONST(start);
+ uacce_start = RTE_BUS_DEVICE(start, *uacce_start);
uacce_dev = TAILQ_NEXT(uacce_start, next);
} else {
uacce_dev = TAILQ_FIRST(&uacce_bus.device_list);
diff --git a/drivers/bus/vdev/bus_vdev_driver.h b/drivers/bus/vdev/bus_vdev_driver.h
index 17efec51a3..f352daabda 100644
--- a/drivers/bus/vdev/bus_vdev_driver.h
+++ b/drivers/bus/vdev/bus_vdev_driver.h
@@ -8,6 +8,7 @@
#include <rte_bus_vdev.h>
#include <rte_compat.h>
#include <dev_driver.h>
+#include <bus_driver.h>
#include <rte_devargs.h>
#ifdef __cplusplus
@@ -19,17 +20,8 @@ struct rte_vdev_device {
struct rte_device device; /**< Inherit core device */
};
-/**
- * @internal
- * Helper macro for drivers that need to convert to struct rte_vdev_device.
- */
-#define RTE_DEV_TO_VDEV(ptr) \
- container_of(ptr, struct rte_vdev_device, device)
-
-#define RTE_DEV_TO_VDEV_CONST(ptr) \
- container_of(ptr, const struct rte_vdev_device, device)
-
-#define RTE_ETH_DEV_TO_VDEV(eth_dev) RTE_DEV_TO_VDEV((eth_dev)->device)
+#define RTE_ETH_DEV_TO_VDEV(eth_dev) \
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_vdev_device)
static inline const char *
rte_vdev_device_name(const struct rte_vdev_device *dev)
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index 906e9dbe08..ea81b755e3 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -141,11 +141,8 @@ vdev_parse(const char *name, void *addr)
static int
vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
- const struct rte_vdev_driver *driver;
-
- driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
- driver);
+ struct rte_vdev_device *vdev = RTE_BUS_DEVICE(dev, *vdev);
+ const struct rte_vdev_driver *driver = RTE_BUS_DRIVER(vdev->device.driver, *driver);
if (driver->dma_map != NULL)
return driver->dma_map(vdev, addr, iova, len);
@@ -156,11 +153,8 @@ vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
static int
vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
- const struct rte_vdev_driver *driver;
-
- driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
- driver);
+ struct rte_vdev_device *vdev = RTE_BUS_DEVICE(dev, *vdev);
+ const struct rte_vdev_driver *driver = RTE_BUS_DRIVER(vdev->device.driver, *driver);
if (driver->dma_unmap != NULL)
return driver->dma_unmap(vdev, addr, iova, len);
@@ -336,8 +330,8 @@ vdev_remove_driver(struct rte_vdev_device *dev)
return 1;
}
- driver = container_of(dev->device.driver, const struct rte_vdev_driver,
- driver);
+ driver = RTE_BUS_DRIVER(dev->device.driver, *driver);
+
return driver->remove(dev);
}
@@ -572,7 +566,7 @@ vdev_cleanup(void)
if (!rte_dev_is_probed(&dev->device))
goto free;
- drv = container_of(dev->device.driver, const struct rte_vdev_driver, driver);
+ drv = RTE_BUS_DRIVER(dev->device.driver, *drv);
if (drv->remove == NULL)
goto free;
@@ -599,7 +593,7 @@ rte_vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
rte_spinlock_recursive_lock(&vdev_device_list_lock);
if (start != NULL) {
- vstart = RTE_DEV_TO_VDEV_CONST(start);
+ vstart = RTE_BUS_DEVICE(start, *vstart);
dev = TAILQ_NEXT(vstart, next);
} else {
dev = TAILQ_FIRST(&vdev_device_list);
@@ -617,7 +611,7 @@ rte_vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
static int
vdev_plug(struct rte_device *dev)
{
- return vdev_probe_all_drivers(RTE_DEV_TO_VDEV(dev));
+ return vdev_probe_all_drivers(RTE_BUS_DEVICE(dev, struct rte_vdev_device));
}
static int
diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c
index fc7e9ecddc..e3db6c4124 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.c
+++ b/drivers/common/mlx5/linux/mlx5_common_os.c
@@ -719,9 +719,10 @@ mlx5_os_get_ibv_dev(const struct rte_device *dev)
struct ibv_device *ibv;
if (mlx5_dev_is_pci(dev))
- ibv = mlx5_os_get_ibv_device(RTE_DEV_TO_PCI_CONST(dev));
+ ibv = mlx5_os_get_ibv_device(RTE_BUS_DEVICE(dev, const struct rte_pci_device));
else
- ibv = mlx5_get_aux_ibv_device(RTE_DEV_TO_AUXILIARY_CONST(dev));
+ ibv = mlx5_get_aux_ibv_device(RTE_BUS_DEVICE(dev,
+ const struct rte_auxiliary_device));
if (ibv == NULL) {
rte_errno = ENODEV;
DRV_LOG(ERR, "Verbs device not found: %s", dev->name);
diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c
index f71dbe4637..f87dc9d773 100644
--- a/drivers/common/mlx5/mlx5_common.c
+++ b/drivers/common/mlx5/mlx5_common.c
@@ -491,7 +491,7 @@ mlx5_dev_to_pci_str(const struct rte_device *dev, char *addr, size_t size)
return 0;
}
#ifdef RTE_EXEC_ENV_LINUX
- return mlx5_auxiliary_get_pci_str(RTE_DEV_TO_AUXILIARY_CONST(dev),
+ return mlx5_auxiliary_get_pci_str(RTE_BUS_DEVICE(dev, const struct rte_auxiliary_device),
addr, size);
#else
rte_errno = ENODEV;
diff --git a/drivers/common/mlx5/mlx5_common_pci.c b/drivers/common/mlx5/mlx5_common_pci.c
index 8bd43bc166..f99e57f9f6 100644
--- a/drivers/common/mlx5/mlx5_common_pci.c
+++ b/drivers/common/mlx5/mlx5_common_pci.c
@@ -138,7 +138,7 @@ mlx5_dev_pci_match(const struct mlx5_class_driver *drv,
if (!mlx5_dev_is_pci(dev))
return false;
- pci_dev = RTE_DEV_TO_PCI_CONST(dev);
+ pci_dev = RTE_BUS_DEVICE(dev, *pci_dev);
for (id_table = drv->id_table; id_table->vendor_id != 0;
id_table++) {
/* Check if device's ids match the class driver's ids. */
diff --git a/drivers/common/mlx5/windows/mlx5_common_os.c b/drivers/common/mlx5/windows/mlx5_common_os.c
index 16fcc5f9fc..a3033f5305 100644
--- a/drivers/common/mlx5/windows/mlx5_common_os.c
+++ b/drivers/common/mlx5/windows/mlx5_common_os.c
@@ -180,7 +180,7 @@ mlx5_os_get_devx_device(struct rte_device *dev,
struct devx_device_bdf *devx_list, int n)
{
struct devx_device_bdf *devx_match = NULL;
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev, *pci_dev);
struct rte_pci_addr *addr = &pci_dev->addr;
while (n-- > 0) {
diff --git a/drivers/compress/octeontx/otx_zip.c b/drivers/compress/octeontx/otx_zip.c
index 331d2d9475..8673561a81 100644
--- a/drivers/compress/octeontx/otx_zip.c
+++ b/drivers/compress/octeontx/otx_zip.c
@@ -142,7 +142,7 @@ zipvf_push_command(struct zipvf_qp *qp, union zip_inst_s *cmd)
int
zipvf_create(struct rte_compressdev *compressdev)
{
- struct rte_pci_device *pdev = RTE_DEV_TO_PCI(compressdev->device);
+ struct rte_pci_device *pdev = RTE_BUS_DEVICE(compressdev->device, *pdev);
struct zip_vf *zipvf = NULL;
char *dev_name = compressdev->data->name;
void *vbar0;
diff --git a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
index 2f9eb322dc..f437350539 100644
--- a/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
+++ b/drivers/crypto/cnxk/cnxk_cryptodev_ops.c
@@ -481,7 +481,7 @@ cnxk_cpt_queue_pair_setup(struct rte_cryptodev *dev, uint16_t qp_id,
if (dev->data->queue_pairs[qp_id] != NULL)
cnxk_cpt_queue_pair_release(dev, qp_id);
- pci_dev = RTE_DEV_TO_PCI(dev->device);
+ pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
if (pci_dev->mem_resource[2].addr == NULL) {
plt_err("Invalid PCI mem address");
diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index 995e375fb5..d7b53723e7 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -4392,7 +4392,7 @@ dpaa2_sec_dev_init(struct rte_cryptodev *cryptodev)
int retcode, hw_id;
PMD_INIT_FUNC_TRACE();
- dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
+ dpaa2_dev = RTE_BUS_DEVICE(dev, *dpaa2_dev);
hw_id = dpaa2_dev->object_id;
cryptodev->driver_id = cryptodev_driver_id;
diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c
index 88657f49cc..a499c8d0bc 100644
--- a/drivers/crypto/octeontx/otx_cryptodev_ops.c
+++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c
@@ -156,7 +156,7 @@ otx_cpt_que_pair_setup(struct rte_cryptodev *dev,
DEFAULT_CMD_QLEN);
}
- pci_dev = RTE_DEV_TO_PCI(dev->device);
+ pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
if (pci_dev->mem_resource[0].addr == NULL) {
CPT_LOG_ERR("PCI mem address null");
@@ -1001,7 +1001,7 @@ static struct rte_cryptodev_ops cptvf_ops = {
int
otx_cpt_dev_create(struct rte_cryptodev *c_dev)
{
- struct rte_pci_device *pdev = RTE_DEV_TO_PCI(c_dev->device);
+ struct rte_pci_device *pdev = RTE_BUS_DEVICE(c_dev->device, *pdev);
struct cpt_vf *cptvf = NULL;
void *reg_base;
char dev_name[32];
diff --git a/drivers/event/cnxk/cnxk_eventdev.c b/drivers/event/cnxk/cnxk_eventdev.c
index be6a487b59..8eff2ba8e0 100644
--- a/drivers/event/cnxk/cnxk_eventdev.c
+++ b/drivers/event/cnxk/cnxk_eventdev.c
@@ -654,7 +654,7 @@ cnxk_sso_init(struct rte_eventdev *event_dev)
return -ENOMEM;
}
- pci_dev = container_of(event_dev->dev, struct rte_pci_device, device);
+ pci_dev = RTE_BUS_DEVICE(event_dev->dev, *pci_dev);
dev->sso.pci_dev = pci_dev;
*(uint64_t *)mz->addr = (uint64_t)dev;
diff --git a/drivers/event/dlb2/pf/dlb2_pf.c b/drivers/event/dlb2/pf/dlb2_pf.c
index edcdfb319f..a498ba8c41 100644
--- a/drivers/event/dlb2/pf/dlb2_pf.c
+++ b/drivers/event/dlb2/pf/dlb2_pf.c
@@ -784,7 +784,7 @@ dlb2_eventdev_pci_init(struct rte_eventdev *eventdev)
dlb2_pf_iface_fn_ptrs_init();
- pci_dev = RTE_DEV_TO_PCI(eventdev->dev);
+ pci_dev = RTE_BUS_DEVICE(eventdev->dev, *pci_dev);
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
dlb2 = dlb2_pmd_priv(eventdev); /* rte_zmalloc_socket mem */
diff --git a/drivers/event/skeleton/skeleton_eventdev.c b/drivers/event/skeleton/skeleton_eventdev.c
index 73a1e4e008..e07744d2f1 100644
--- a/drivers/event/skeleton/skeleton_eventdev.c
+++ b/drivers/event/skeleton/skeleton_eventdev.c
@@ -332,7 +332,7 @@ skeleton_eventdev_init(struct rte_eventdev *eventdev)
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
return 0;
- pci_dev = RTE_DEV_TO_PCI(eventdev->dev);
+ pci_dev = RTE_BUS_DEVICE(eventdev->dev, *pci_dev);
skel->reg_base = (uintptr_t)pci_dev->mem_resource[0].addr;
if (!skel->reg_base) {
diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
index cfcd880961..c14d04a11d 100644
--- a/drivers/net/axgbe/axgbe_ethdev.c
+++ b/drivers/net/axgbe/axgbe_ethdev.c
@@ -2230,7 +2230,7 @@ eth_axgbe_dev_init(struct rte_eth_dev *eth_dev)
rte_bit_relaxed_set32(AXGBE_STOPPED, &pdata->dev_state);
pdata->eth_dev = eth_dev;
- pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
+ pci_dev = RTE_BUS_DEVICE(eth_dev->device, *pci_dev);
pdata->pci_dev = pci_dev;
pdata->xgmac_regs =
@@ -2453,7 +2453,7 @@ axgbe_dev_close(struct rte_eth_dev *eth_dev)
return 0;
pdata = eth_dev->data->dev_private;
- pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
+ pci_dev = RTE_BUS_DEVICE(eth_dev->device, *pci_dev);
axgbe_dev_clear_queues(eth_dev);
/* disable uio intr before callback unregister */
diff --git a/drivers/net/bnx2x/bnx2x_ethdev.c b/drivers/net/bnx2x/bnx2x_ethdev.c
index 5e2e555525..7b96e1acee 100644
--- a/drivers/net/bnx2x/bnx2x_ethdev.c
+++ b/drivers/net/bnx2x/bnx2x_ethdev.c
@@ -639,7 +639,7 @@ bnx2x_common_dev_init(struct rte_eth_dev *eth_dev, int is_vf)
/* Extract key data structures */
sc = eth_dev->data->dev_private;
- pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
+ pci_dev = RTE_BUS_DEVICE(eth_dev->device, *pci_dev);
pci_addr = pci_dev->addr;
snprintf(sc->devinfo.name, NAME_SIZE, PCI_SHORT_PRI_FMT ":dpdk-port-%u",
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index b677f9491d..071093aabc 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -1167,7 +1167,7 @@ uint64_t bnxt_eth_rss_support(struct bnxt *bp)
static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
struct rte_eth_dev_info *dev_info)
{
- struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
+ struct rte_pci_device *pdev = RTE_BUS_DEVICE(eth_dev->device, *pdev);
struct bnxt *bp = eth_dev->data->dev_private;
uint16_t max_vnics, i, j, vpool, vrxq;
unsigned int max_rx_rings;
diff --git a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
index 0c03ae7a83..e1e2c0e878 100644
--- a/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
+++ b/drivers/net/bnxt/tf_ulp/bnxt_ulp.c
@@ -192,7 +192,7 @@ ulp_session_init(struct bnxt *bp,
if (!bp)
return NULL;
- pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
+ pci_dev = RTE_BUS_DEVICE(bp->eth_dev->device, *pci_dev);
pci_addr = &pci_dev->addr;
pthread_mutex_lock(&bnxt_ulp_global_mutex);
@@ -556,7 +556,7 @@ bnxt_ulp_port_deinit(struct bnxt *bp)
bp->eth_dev->data->port_id);
/* Get the session details */
- pci_dev = RTE_DEV_TO_PCI(bp->eth_dev->device);
+ pci_dev = RTE_BUS_DEVICE(bp->eth_dev->device, *pci_dev);
pci_addr = &pci_dev->addr;
pthread_mutex_lock(&bnxt_ulp_global_mutex);
session = ulp_get_session(bp, pci_addr);
diff --git a/drivers/net/bonding/rte_eth_bond_args.c b/drivers/net/bonding/rte_eth_bond_args.c
index bdec5d61d4..4fbd25cd33 100644
--- a/drivers/net/bonding/rte_eth_bond_args.c
+++ b/drivers/net/bonding/rte_eth_bond_args.c
@@ -26,7 +26,7 @@ const char *pmd_bond_init_valid_arguments[] = {
static inline int
bond_pci_addr_cmp(const struct rte_device *dev, const void *_pci_addr)
{
- const struct rte_pci_device *pdev = RTE_DEV_TO_PCI_CONST(dev);
+ const struct rte_pci_device *pdev = RTE_BUS_DEVICE(dev, *pdev);
const struct rte_pci_addr *paddr = _pci_addr;
return rte_pci_addr_cmp(&pdev->addr, paddr);
diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index dcde3ba2c7..d4b4793f16 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -230,7 +230,7 @@ dpaa_eth_dev_configure(struct rte_eth_dev *dev)
PMD_INIT_FUNC_TRACE();
- dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
+ dpaa_dev = RTE_BUS_DEVICE(rdev, *dpaa_dev);
intr_handle = dpaa_dev->intr_handle;
__fif = container_of(fif, struct __fman_if, __if);
@@ -432,7 +432,7 @@ static void dpaa_interrupt_handler(void *param)
uint64_t buf;
int bytes_read;
- dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
+ dpaa_dev = RTE_BUS_DEVICE(rdev, *dpaa_dev);
intr_handle = dpaa_dev->intr_handle;
if (rte_intr_fd_get(intr_handle) < 0)
@@ -530,7 +530,7 @@ static int dpaa_eth_dev_close(struct rte_eth_dev *dev)
}
}
- dpaa_dev = container_of(rdev, struct rte_dpaa_device, device);
+ dpaa_dev = RTE_BUS_DEVICE(rdev, *dpaa_dev);
intr_handle = dpaa_dev->intr_handle;
__fif = container_of(fif, struct __fman_if, __if);
@@ -1269,8 +1269,7 @@ int dpaa_eth_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
struct rte_dpaa_device *dpaa_dev;
struct rte_device *rdev = dev->device;
- dpaa_dev = container_of(rdev, struct rte_dpaa_device,
- device);
+ dpaa_dev = RTE_BUS_DEVICE(rdev, *dpaa_dev);
dev->intr_handle = dpaa_dev->intr_handle;
if (rte_intr_vec_list_alloc(dev->intr_handle,
NULL, dpaa_push_queue_max_num())) {
@@ -2120,7 +2119,7 @@ dpaa_dev_init_secondary(struct rte_eth_dev *eth_dev)
PMD_INIT_FUNC_TRACE();
- dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
+ dpaa_device = RTE_BUS_DEVICE(eth_dev->device, *dpaa_device);
dev_id = dpaa_device->id.dev_id;
cfg = dpaa_get_eth_port_cfg(dev_id);
fman_intf = cfg->fman_if;
@@ -2237,7 +2236,7 @@ dpaa_dev_init(struct rte_eth_dev *eth_dev)
PMD_INIT_FUNC_TRACE();
- dpaa_device = DEV_TO_DPAA_DEVICE(eth_dev->device);
+ dpaa_device = RTE_BUS_DEVICE(eth_dev->device, *dpaa_device);
dev_id = dpaa_device->id.dev_id;
dpaa_intf = eth_dev->data->dev_private;
cfg = dpaa_get_eth_port_cfg(dev_id);
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index 9cc81f7a47..dc9ea700ac 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -1351,7 +1351,7 @@ dpaa2_dev_start(struct rte_eth_dev *dev)
int ret, i;
struct rte_intr_handle *intr_handle;
- dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
+ dpaa2_dev = RTE_BUS_DEVICE(rdev, *dpaa2_dev);
intr_handle = dpaa2_dev->intr_handle;
PMD_INIT_FUNC_TRACE();
@@ -1463,7 +1463,7 @@ dpaa2_dev_stop(struct rte_eth_dev *dev)
struct rte_dpaa2_device *dpaa2_dev;
uint16_t i;
- dpaa2_dev = container_of(rdev, struct rte_dpaa2_device, device);
+ dpaa2_dev = RTE_BUS_DEVICE(rdev, *dpaa2_dev);
intr_handle = dpaa2_dev->intr_handle;
PMD_INIT_FUNC_TRACE();
@@ -2918,7 +2918,7 @@ dpaa2_dev_init(struct rte_eth_dev *eth_dev)
return 0;
}
- dpaa2_dev = container_of(dev, struct rte_dpaa2_device, device);
+ dpaa2_dev = RTE_BUS_DEVICE(dev, *dpaa2_dev);
hw_id = dpaa2_dev->object_id;
ret = dpni_open(dpni_dev, CMD_PRI_LOW, hw_id, &priv->token);
diff --git a/drivers/net/dpaa2/dpaa2_recycle.c b/drivers/net/dpaa2/dpaa2_recycle.c
index 1893979748..14416c41d0 100644
--- a/drivers/net/dpaa2/dpaa2_recycle.c
+++ b/drivers/net/dpaa2/dpaa2_recycle.c
@@ -609,8 +609,7 @@ dpaa2_dev_recycle_config(struct rte_eth_dev *eth_dev)
{
struct rte_device *dev = eth_dev->device;
struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
- struct rte_dpaa2_device *dpaa2_dev =
- container_of(dev, struct rte_dpaa2_device, device);
+ struct rte_dpaa2_device *dpaa2_dev = RTE_BUS_DEVICE(dev, *dpaa2_dev);
struct fsl_mc_io *dpni_dev = eth_dev->process_private;
struct dpni_port_cfg port_cfg;
int ret;
@@ -677,8 +676,7 @@ dpaa2_dev_recycle_deconfig(struct rte_eth_dev *eth_dev)
{
struct rte_device *dev = eth_dev->device;
struct dpaa2_dev_priv *priv = eth_dev->data->dev_private;
- struct rte_dpaa2_device *dpaa2_dev =
- container_of(dev, struct rte_dpaa2_device, device);
+ struct rte_dpaa2_device *dpaa2_dev = RTE_BUS_DEVICE(dev, *dpaa2_dev);
struct fsl_mc_io *dpni_dev = eth_dev->process_private;
struct dpni_port_cfg port_cfg;
int ret = 0;
diff --git a/drivers/net/gve/gve_ethdev.c b/drivers/net/gve/gve_ethdev.c
index 6ce3ef3938..73f4935b1f 100644
--- a/drivers/net/gve/gve_ethdev.c
+++ b/drivers/net/gve/gve_ethdev.c
@@ -1410,7 +1410,7 @@ gve_dev_init(struct rte_eth_dev *eth_dev)
return 0;
}
- pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
+ pci_dev = RTE_BUS_DEVICE(eth_dev->device, *pci_dev);
reg_bar = pci_dev->mem_resource[GVE_REG_BAR].addr;
if (!reg_bar) {
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index b2eab7e1c5..a66fc5d81a 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -4527,7 +4527,7 @@ static int
hns3_init_pf(struct rte_eth_dev *eth_dev)
{
struct rte_device *dev = eth_dev->device;
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev, *pci_dev);
struct hns3_adapter *hns = eth_dev->data->dev_private;
struct hns3_hw *hw = &hns->hw;
int ret;
@@ -4657,7 +4657,7 @@ hns3_uninit_pf(struct rte_eth_dev *eth_dev)
{
struct hns3_adapter *hns = eth_dev->data->dev_private;
struct rte_device *dev = eth_dev->device;
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev, *pci_dev);
struct hns3_hw *hw = &hns->hw;
PMD_INIT_FUNC_TRACE();
diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c
index 573604b0cd..3528fda8a5 100644
--- a/drivers/net/hns3/hns3_rxtx.c
+++ b/drivers/net/hns3/hns3_rxtx.c
@@ -3066,7 +3066,7 @@ hns3_tx_push_get_queue_tail_reg(struct rte_eth_dev *dev, uint16_t queue_id)
#define HNS3_TX_PUSH_QUICK_DOORBELL_OFFSET 64
#define HNS3_TX_PUSH_PCI_BAR_INDEX 4
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
uint8_t bar_id = HNS3_TX_PUSH_PCI_BAR_INDEX;
/*
diff --git a/drivers/net/intel/cpfl/cpfl_ethdev.c b/drivers/net/intel/cpfl/cpfl_ethdev.c
index 617b823f5a..03599e6432 100644
--- a/drivers/net/intel/cpfl/cpfl_ethdev.c
+++ b/drivers/net/intel/cpfl/cpfl_ethdev.c
@@ -2764,7 +2764,7 @@ cpfl_dev_vport_init(struct rte_eth_dev *dev, void *init_params)
uint8_t p2p_q_vc_out_info[IDPF_DFLT_MBX_BUF_SIZE] = {0};
struct cpfl_vport_id vi;
struct cpchnl2_vport_id v_id;
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
int ret = 0;
dev->dev_ops = &cpfl_eth_dev_ops;
@@ -2836,7 +2836,7 @@ cpfl_dev_vport_init(struct rte_eth_dev *dev, void *init_params)
}
/* get the vport info */
if (adapter->base.hw.device_id == IXD_DEV_ID_VCPF) {
- pci_dev = RTE_DEV_TO_PCI(dev->device);
+ pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
vi.func_type = VCPF_CPCHNL2_FTYPE_LAN_VF;
vi.pf_id = CPFL_HOST0_CPF_ID;
vi.vf_id = pci_dev->addr.function;
diff --git a/drivers/net/intel/cpfl/cpfl_ethdev.h b/drivers/net/intel/cpfl/cpfl_ethdev.h
index e05a0901d5..56f8f39829 100644
--- a/drivers/net/intel/cpfl/cpfl_ethdev.h
+++ b/drivers/net/intel/cpfl/cpfl_ethdev.h
@@ -298,7 +298,7 @@ int vcpf_add_queues(struct cpfl_adapter_ext *adapter);
int vcpf_del_queues(struct cpfl_adapter_ext *adapter);
#define CPFL_DEV_TO_PCI(eth_dev) \
- RTE_DEV_TO_PCI((eth_dev)->device)
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_pci_device)
#define CPFL_ADAPTER_TO_EXT(p) \
container_of((p), struct cpfl_adapter_ext, base)
#define CPFL_DEV_TO_VPORT(dev) \
diff --git a/drivers/net/intel/i40e/i40e_ethdev.h b/drivers/net/intel/i40e/i40e_ethdev.h
index d57c53f661..dcbdf65047 100644
--- a/drivers/net/intel/i40e/i40e_ethdev.h
+++ b/drivers/net/intel/i40e/i40e_ethdev.h
@@ -1467,7 +1467,7 @@ int i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params);
int i40e_vf_representor_uninit(struct rte_eth_dev *ethdev);
#define I40E_DEV_TO_PCI(eth_dev) \
- RTE_DEV_TO_PCI((eth_dev)->device)
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_pci_device)
/* I40E_DEV_PRIVATE_TO */
#define I40E_DEV_PRIVATE_TO_PF(adapter) \
diff --git a/drivers/net/intel/ice/ice_ethdev.c b/drivers/net/intel/ice/ice_ethdev.c
index 0f2e7aee14..715d1522f9 100644
--- a/drivers/net/intel/ice/ice_ethdev.c
+++ b/drivers/net/intel/ice/ice_ethdev.c
@@ -2623,7 +2623,7 @@ ice_dev_init(struct rte_eth_dev *dev)
}
ice_set_default_ptype_table(dev);
- pci_dev = RTE_DEV_TO_PCI(dev->device);
+ pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
intr_handle = pci_dev->intr_handle;
pf->adapter = ICE_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
@@ -4520,7 +4520,7 @@ ice_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
struct ice_hw *hw = ICE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
struct ice_vsi *vsi = pf->main_vsi;
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(dev->device, *pci_dev);
bool is_safe_mode = pf->adapter->is_safe_mode;
u64 phy_type_low;
u64 phy_type_high;
diff --git a/drivers/net/intel/ice/ice_ethdev.h b/drivers/net/intel/ice/ice_ethdev.h
index 4b3718f715..ea73f8bcb3 100644
--- a/drivers/net/intel/ice/ice_ethdev.h
+++ b/drivers/net/intel/ice/ice_ethdev.h
@@ -708,7 +708,7 @@ struct ice_vsi_vlan_pvid_info {
};
#define ICE_DEV_TO_PCI(eth_dev) \
- RTE_DEV_TO_PCI((eth_dev)->device)
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_pci_device)
/* ICE_DEV_PRIVATE_TO */
#define ICE_DEV_PRIVATE_TO_PF(adapter) \
diff --git a/drivers/net/intel/idpf/idpf_ethdev.h b/drivers/net/intel/idpf/idpf_ethdev.h
index 3c2c932438..5105eea1c5 100644
--- a/drivers/net/intel/idpf/idpf_ethdev.h
+++ b/drivers/net/intel/idpf/idpf_ethdev.h
@@ -85,7 +85,7 @@ struct idpf_adapter_ext {
TAILQ_HEAD(idpf_adapter_list, idpf_adapter_ext);
#define IDPF_DEV_TO_PCI(eth_dev) \
- RTE_DEV_TO_PCI((eth_dev)->device)
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_pci_device)
#define IDPF_ADAPTER_TO_EXT(p) \
container_of((p), struct idpf_adapter_ext, base)
diff --git a/drivers/net/intel/ipn3ke/ipn3ke_ethdev.h b/drivers/net/intel/ipn3ke/ipn3ke_ethdev.h
index 4b93d2649e..6d531120b8 100644
--- a/drivers/net/intel/ipn3ke/ipn3ke_ethdev.h
+++ b/drivers/net/intel/ipn3ke/ipn3ke_ethdev.h
@@ -310,18 +310,8 @@ struct ipn3ke_hw {
uint8_t *hw_addr;
};
-/**
- * @internal
- * Helper macro for drivers that need to convert to struct rte_afu_device.
- */
-#define RTE_DEV_TO_AFU(ptr) \
- container_of(ptr, struct rte_afu_device, device)
-
-#define RTE_DEV_TO_AFU_CONST(ptr) \
- container_of(ptr, const struct rte_afu_device, device)
-
#define RTE_ETH_DEV_TO_AFU(eth_dev) \
- RTE_DEV_TO_AFU((eth_dev)->device)
+ RTE_BUS_DEVICE((eth_dev)->device, struct rte_afu_device)
/**
* PCIe MMIO Access
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index a717191002..d9923e327c 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -171,7 +171,8 @@ mlx5_os_capabilities_prepare(struct mlx5_dev_ctx_shared *sh)
}
memset(&sh->dev_cap, 0, sizeof(struct mlx5_dev_cap));
if (mlx5_dev_is_pci(cdev->dev))
- sh->dev_cap.vf = mlx5_dev_is_vf_pci(RTE_DEV_TO_PCI(cdev->dev));
+ sh->dev_cap.vf = mlx5_dev_is_vf_pci(RTE_BUS_DEVICE(cdev->dev,
+ struct rte_pci_device));
else
sh->dev_cap.sf = 1;
sh->dev_cap.max_qp_wr = attr_ex.orig_attr.max_qp_wr;
@@ -2504,7 +2505,7 @@ mlx5_os_pci_probe_pf(struct mlx5_common_device *cdev,
* >= 0 - MPESW device. Value is the port index of the MPESW owner.
*/
int mpesw = MLX5_MPESW_PORT_INVALID;
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(cdev->dev, *pci_dev);
struct mlx5_dev_spawn_data *list = NULL;
struct rte_eth_devargs eth_da = *req_eth_da;
struct rte_pci_addr owner_pci = pci_dev->addr; /* Owner PF. */
@@ -3067,7 +3068,7 @@ static int
mlx5_os_pci_probe(struct mlx5_common_device *cdev,
struct mlx5_kvargs_ctrl *mkvlist)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(cdev->dev, *pci_dev);
struct rte_eth_devargs eth_da = { .nb_ports = 0 };
int ret = 0;
uint16_t p;
@@ -3109,7 +3110,7 @@ mlx5_os_auxiliary_probe(struct mlx5_common_device *cdev,
.mpesw_port = MLX5_MPESW_PORT_INVALID,
};
struct rte_device *dev = cdev->dev;
- struct rte_auxiliary_device *adev = RTE_DEV_TO_AUXILIARY(dev);
+ struct rte_auxiliary_device *adev = RTE_BUS_DEVICE(dev, *adev);
struct rte_eth_dev *eth_dev;
int ret = 0;
diff --git a/drivers/net/mlx5/windows/mlx5_os.c b/drivers/net/mlx5/windows/mlx5_os.c
index 4952b674c0..9acfa8ec84 100644
--- a/drivers/net/mlx5/windows/mlx5_os.c
+++ b/drivers/net/mlx5/windows/mlx5_os.c
@@ -168,7 +168,7 @@ mlx5_os_capabilities_prepare(struct mlx5_dev_ctx_shared *sh)
return -rte_errno;
}
memset(&sh->dev_cap, 0, sizeof(struct mlx5_dev_cap));
- sh->dev_cap.vf = mlx5_dev_is_vf_pci(RTE_DEV_TO_PCI(sh->cdev->dev));
+ sh->dev_cap.vf = mlx5_dev_is_vf_pci(RTE_BUS_DEVICE(sh->cdev->dev, struct rte_pci_device));
sh->dev_cap.max_cq = 1 << hca_attr->log_max_cq;
sh->dev_cap.max_qp = 1 << hca_attr->log_max_qp;
sh->dev_cap.max_qp_wr = 1 << hca_attr->log_max_qp_sz;
@@ -846,7 +846,7 @@ int
mlx5_os_net_probe(struct mlx5_common_device *cdev,
struct mlx5_kvargs_ctrl *mkvlist)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(cdev->dev);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(cdev->dev, *pci_dev);
struct mlx5_dev_spawn_data spawn = {
.pf_bond = -1,
.max_port = 1,
diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c
index b8880edb4c..fa936cfde7 100644
--- a/drivers/net/netvsc/hn_ethdev.c
+++ b/drivers/net/netvsc/hn_ethdev.c
@@ -1536,7 +1536,7 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev)
rte_spinlock_init(&hv->hotadd_lock);
LIST_INIT(&hv->hotadd_list);
- vmbus = container_of(device, struct rte_vmbus_device, device);
+ vmbus = RTE_BUS_DEVICE(device, *vmbus);
eth_dev->dev_ops = &hn_eth_dev_ops;
eth_dev->rx_queue_count = hn_dev_rx_queue_count;
eth_dev->rx_descriptor_status = hn_dev_rx_queue_status;
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index e1c28a0ac2..c676c6fa75 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -1231,7 +1231,7 @@ static int qede_args_check(const char *key, const char *val, void *opaque)
static int qede_args(struct rte_eth_dev *eth_dev)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE(eth_dev->device, *pci_dev);
struct rte_kvargs *kvlist;
struct rte_devargs *devargs;
int ret;
diff --git a/drivers/net/rnp/rnp_ethdev.c b/drivers/net/rnp/rnp_ethdev.c
index bb5a0cabb1..15a976ac85 100644
--- a/drivers/net/rnp/rnp_ethdev.c
+++ b/drivers/net/rnp/rnp_ethdev.c
@@ -728,7 +728,7 @@ static int rnp_dev_close(struct rte_eth_dev *eth_dev)
if (adapter->intr_registered && adapter->eth_dev == eth_dev)
rnp_change_manage_port(adapter);
if (adapter->closed_ports == adapter->inited_ports) {
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI((void *)eth_dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE((void *)eth_dev->device, *pci_dev);
if (adapter->intr_registered) {
/* disable uio irq before callback unregister */
rte_intr_disable(pci_dev->intr_handle);
@@ -1667,7 +1667,7 @@ rnp_rx_reset_pool_setup(struct rnp_eth_adapter *adapter)
static int
rnp_eth_dev_init(struct rte_eth_dev *eth_dev)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI((void *)eth_dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE((void *)eth_dev->device, *pci_dev);
struct rte_intr_handle *intr_handle = pci_dev->intr_handle;
struct rnp_eth_port *port = RNP_DEV_TO_PORT(eth_dev);
char name[RTE_ETH_NAME_MAX_LEN] = " ";
@@ -1798,7 +1798,7 @@ rnp_eth_dev_init(struct rte_eth_dev *eth_dev)
static int
rnp_eth_dev_uninit(struct rte_eth_dev *eth_dev)
{
- struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI((void *)eth_dev->device);
+ struct rte_pci_device *pci_dev = RTE_BUS_DEVICE((void *)eth_dev->device, *pci_dev);
uint16_t port_id;
int err = 0;
diff --git a/drivers/raw/ifpga/afu_pmd_n3000.c b/drivers/raw/ifpga/afu_pmd_n3000.c
index b4c2f0d0a8..f092ee2dec 100644
--- a/drivers/raw/ifpga/afu_pmd_n3000.c
+++ b/drivers/raw/ifpga/afu_pmd_n3000.c
@@ -1467,11 +1467,11 @@ static struct rte_pci_device *n3000_afu_get_pci_dev(struct afu_rawdev *dev)
if (!dev || !dev->rawdev || !dev->rawdev->device)
return NULL;
- afudev = RTE_DEV_TO_AFU(dev->rawdev->device);
+ afudev = RTE_BUS_DEVICE(dev->rawdev->device, *afudev);
if (!afudev->rawdev || !afudev->rawdev->device)
return NULL;
- return RTE_DEV_TO_PCI(afudev->rawdev->device);
+ return RTE_BUS_DEVICE(afudev->rawdev->device, struct rte_pci_device);
}
static int dma_afu_set_irqs(struct afu_rawdev *dev, uint32_t vec_start,
diff --git a/lib/eal/include/bus_driver.h b/lib/eal/include/bus_driver.h
index 72783de59c..71346fb8b2 100644
--- a/lib/eal/include/bus_driver.h
+++ b/lib/eal/include/bus_driver.h
@@ -340,6 +340,36 @@ RTE_INIT_PRIO(businitfn_ ##nm, BUS) \
__rte_internal
void rte_bus_unregister(struct rte_bus *bus);
+/**
+ * Helper macro to convert a generic device pointer to a bus-specific device type.
+ * Uses typeof to automatically determine the bus-specific type from the second argument.
+ *
+ * @param dev
+ * Generic rte_device pointer to convert
+ * @param bus_dev_type
+ * Type expression: either a struct type (e.g., struct rte_pci_device) or
+ * a dereferenced pointer (e.g., *pdev) for type inference
+ * @return
+ * Pointer to the bus-specific device structure containing this rte_device
+ */
+#define RTE_BUS_DEVICE(dev, bus_dev_type) \
+ container_of(dev, typeof(bus_dev_type), device)
+
+/**
+ * Helper macro to convert a generic driver pointer to a bus-specific driver type.
+ * Uses typeof to automatically determine the bus-specific type from the second argument.
+ *
+ * @param drv
+ * Generic rte_driver pointer to convert
+ * @param bus_drv_type
+ * Type expression: either a struct type (e.g., struct rte_pci_driver) or
+ * a dereferenced pointer (e.g., *pdrv) for type inference
+ * @return
+ * Pointer to the bus-specific driver structure containing this rte_driver
+ */
+#define RTE_BUS_DRIVER(drv, bus_drv_type) \
+ container_of(drv, typeof(bus_drv_type), driver)
+
#ifdef __cplusplus
}
#endif
--
2.53.0
^ permalink raw reply related
* [PATCH v2 04/23] drivers/bus: remove device and driver checks in unplug
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Parav Pandit, Xueming Li,
Nipun Gupta, Nikhil Agarwal, Hemant Agrawal, Sachin Saxena,
Rosen Xu, Chenbo Xia, Tomasz Duszynski, Chengwen Feng, Long Li,
Wei Hu
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
rte_dev_remove() checks if a device is probed before calling the bus
unplug operation. Individual bus detach/remove functions checking that
dev->driver is non-NULL are therefore redundant.
However, when the unplug operation is called at bus cleanup, care must
be taken that devices are in probed state, so some check on
rte_dev_is_probed() must be added.
The device parameter passed to bus unplug operations cannot be NULL as
the caller already dereferenced the bus structure to invoke these
operations.
The driver reference in the bus-specific device cannot be NULL since
calling the .unplug is done after dereferencing this pointer.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/auxiliary/auxiliary_common.c | 14 ++++--------
drivers/bus/cdx/cdx.c | 12 +++-------
drivers/bus/dpaa/dpaa_bus.c | 2 +-
drivers/bus/fslmc/fslmc_bus.c | 2 +-
drivers/bus/ifpga/ifpga_bus.c | 29 ++++--------------------
drivers/bus/pci/pci_common.c | 19 +++++-----------
drivers/bus/platform/platform.c | 13 ++++-------
drivers/bus/uacce/uacce.c | 13 +++++------
drivers/bus/vdev/vdev.c | 4 ++--
drivers/bus/vmbus/vmbus_common.c | 4 +++-
10 files changed, 36 insertions(+), 76 deletions(-)
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index 9690687600..1fe0cb4d78 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -144,16 +144,9 @@ rte_auxiliary_probe_one_driver(struct rte_auxiliary_driver *drv,
static int
rte_auxiliary_driver_remove_dev(struct rte_auxiliary_device *dev)
{
- struct rte_auxiliary_driver *drv;
+ struct rte_auxiliary_driver *drv = dev->driver;
int ret = 0;
- if (dev == NULL)
- return -EINVAL;
-
- drv = dev->driver;
- if (drv == NULL)
- return 0;
-
AUXILIARY_LOG(DEBUG, "Driver %s remove auxiliary device %s on NUMA node %i",
drv->driver.name, dev->name, dev->device.numa_node);
@@ -318,10 +311,9 @@ auxiliary_plug(struct rte_device *dev)
static int
auxiliary_unplug(struct rte_device *dev)
{
- struct rte_auxiliary_device *adev;
+ struct rte_auxiliary_device *adev = RTE_DEV_TO_AUXILIARY(dev);
int ret;
- adev = RTE_DEV_TO_AUXILIARY(dev);
ret = rte_auxiliary_driver_remove_dev(adev);
if (ret == 0) {
rte_auxiliary_remove_device(adev);
@@ -341,6 +333,8 @@ auxiliary_cleanup(void)
RTE_TAILQ_FOREACH_SAFE(dev, &auxiliary_bus.device_list, next, tmp_dev) {
int ret;
+ if (!rte_dev_is_probed(&dev->device))
+ continue;
ret = auxiliary_unplug(&dev->device);
if (ret < 0) {
rte_errno = errno;
diff --git a/drivers/bus/cdx/cdx.c b/drivers/bus/cdx/cdx.c
index 9bc41d9980..f498b747e2 100644
--- a/drivers/bus/cdx/cdx.c
+++ b/drivers/bus/cdx/cdx.c
@@ -501,18 +501,13 @@ cdx_remove_device(struct rte_cdx_device *cdx_dev)
static int
cdx_detach_dev(struct rte_cdx_device *dev)
{
- struct rte_cdx_driver *dr;
+ struct rte_cdx_driver *dr = dev->driver;
int ret = 0;
- if (dev == NULL)
- return -EINVAL;
-
- dr = dev->driver;
-
CDX_BUS_DEBUG("detach device %s using driver: %s",
dev->device.name, dr->driver.name);
- if (dr->remove) {
+ if (dr->remove != NULL) {
ret = dr->remove(dev);
if (ret < 0)
return ret;
@@ -539,10 +534,9 @@ cdx_plug(struct rte_device *dev)
static int
cdx_unplug(struct rte_device *dev)
{
- struct rte_cdx_device *cdx_dev;
+ struct rte_cdx_device *cdx_dev = RTE_DEV_TO_CDX_DEV(dev);
int ret;
- cdx_dev = RTE_DEV_TO_CDX_DEV(dev);
ret = cdx_detach_dev(cdx_dev);
if (ret == 0) {
cdx_remove_device(cdx_dev);
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index 1d12f2dceb..1bfc44155d 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -938,7 +938,7 @@ dpaa_bus_cleanup(void)
if (!rte_dev_is_probed(&dev->device))
continue;
- if (!drv || !drv->remove)
+ if (drv->remove == NULL)
continue;
ret = drv->remove(dev);
if (ret < 0) {
diff --git a/drivers/bus/fslmc/fslmc_bus.c b/drivers/bus/fslmc/fslmc_bus.c
index cf881b3eec..7e5a3e947e 100644
--- a/drivers/bus/fslmc/fslmc_bus.c
+++ b/drivers/bus/fslmc/fslmc_bus.c
@@ -619,7 +619,7 @@ fslmc_bus_unplug(struct rte_device *rte_dev)
struct rte_dpaa2_device, device);
struct rte_dpaa2_driver *drv = dev->driver;
- if (drv && drv->remove) {
+ if (drv->remove != NULL) {
drv->remove(dev);
dev->driver = NULL;
dev->device.driver = NULL;
diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index 5cc1207c46..fc5308b6f4 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -365,7 +365,9 @@ ifpga_cleanup(void)
struct rte_afu_driver *drv = afu_dev->driver;
int ret = 0;
- if (drv == NULL || drv->remove == NULL)
+ if (!rte_dev_is_probed(&afu_dev->device))
+ goto free;
+ if (drv->remove == NULL)
goto free;
ret = drv->remove(afu_dev);
@@ -392,34 +394,13 @@ ifpga_plug(struct rte_device *dev)
return ifpga_probe_all_drivers(RTE_DEV_TO_AFU(dev));
}
-static int
-ifpga_remove_driver(struct rte_afu_device *afu_dev)
-{
- const char *name;
-
- name = rte_ifpga_device_name(afu_dev);
- if (afu_dev->driver == NULL) {
- IFPGA_BUS_DEBUG("no driver attach to device %s", name);
- return 1;
- }
-
- return afu_dev->driver->remove(afu_dev);
-}
-
static int
ifpga_unplug(struct rte_device *dev)
{
- struct rte_afu_device *afu_dev = NULL;
+ struct rte_afu_device *afu_dev = RTE_DEV_TO_AFU(dev);
int ret;
- if (dev == NULL)
- return -EINVAL;
-
- afu_dev = RTE_DEV_TO_AFU(dev);
- if (!afu_dev)
- return -ENOENT;
-
- ret = ifpga_remove_driver(afu_dev);
+ ret = afu_dev->driver->remove(afu_dev);
if (ret)
return ret;
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index d7f028e365..1385b0c959 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -310,13 +310,9 @@ static int
rte_pci_detach_dev(struct rte_pci_device *dev)
{
struct rte_pci_addr *loc;
- struct rte_pci_driver *dr;
+ struct rte_pci_driver *dr = dev->driver;
int ret = 0;
- if (dev == NULL)
- return -EINVAL;
-
- dr = dev->driver;
loc = &dev->addr;
PCI_LOG(DEBUG, "PCI device "PCI_PRI_FMT" on NUMA socket %i",
@@ -416,7 +412,9 @@ pci_cleanup(void)
struct rte_pci_driver *drv = dev->driver;
int ret = 0;
- if (drv == NULL || drv->remove == NULL)
+ if (!rte_dev_is_probed(&dev->device))
+ goto free;
+ if (drv->remove == NULL)
goto free;
ret = drv->remove(dev);
@@ -590,13 +588,9 @@ pci_find_device_by_addr(const void *failure_addr)
static int
pci_hot_unplug_handler(struct rte_device *dev)
{
- struct rte_pci_device *pdev = NULL;
+ struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
int ret = 0;
- pdev = RTE_DEV_TO_PCI(dev);
- if (!pdev)
- return -1;
-
switch (pdev->kdrv) {
case RTE_PCI_KDRV_VFIO:
/*
@@ -654,10 +648,9 @@ pci_plug(struct rte_device *dev)
static int
pci_unplug(struct rte_device *dev)
{
- struct rte_pci_device *pdev;
+ struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
int ret;
- pdev = RTE_DEV_TO_PCI(dev);
ret = rte_pci_detach_dev(pdev);
if (ret == 0) {
rte_pci_remove_device(pdev);
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index 8a89a3cad8..0345f1daf7 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -476,11 +476,10 @@ platform_bus_plug(struct rte_device *dev)
static void
device_release_driver(struct rte_platform_device *pdev)
{
- struct rte_platform_driver *pdrv;
+ struct rte_platform_driver *pdrv = pdev->driver;
int ret;
- pdrv = pdev->driver;
- if (pdrv != NULL && pdrv->remove != NULL) {
+ if (pdrv->remove != NULL) {
ret = pdrv->remove(pdev);
if (ret)
PLATFORM_LOG_LINE(WARNING, "failed to remove %s", pdev->name);
@@ -493,11 +492,7 @@ device_release_driver(struct rte_platform_device *pdev)
static int
platform_bus_unplug(struct rte_device *dev)
{
- struct rte_platform_device *pdev;
-
- pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
- if (pdev == NULL)
- return -EINVAL;
+ struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
device_release_driver(pdev);
device_cleanup(pdev);
@@ -572,6 +567,8 @@ platform_bus_cleanup(void)
RTE_TAILQ_FOREACH_SAFE(pdev, &platform_bus.device_list, next, tmp) {
TAILQ_REMOVE(&platform_bus.device_list, pdev, next);
+ if (!rte_dev_is_probed(&pdev->device))
+ continue;
platform_bus_unplug(&pdev->device);
}
diff --git a/drivers/bus/uacce/uacce.c b/drivers/bus/uacce/uacce.c
index ade2452ad5..d0ea454911 100644
--- a/drivers/bus/uacce/uacce.c
+++ b/drivers/bus/uacce/uacce.c
@@ -453,7 +453,9 @@ uacce_cleanup(void)
struct rte_uacce_driver *dr = dev->driver;
int ret = 0;
- if (dr == NULL || dr->remove == NULL)
+ if (!rte_dev_is_probed(&dev->device))
+ goto free;
+ if (dr->remove == NULL)
goto free;
ret = dr->remove(dev);
@@ -481,14 +483,12 @@ uacce_plug(struct rte_device *dev)
static int
uacce_detach_dev(struct rte_uacce_device *dev)
{
- struct rte_uacce_driver *dr;
+ struct rte_uacce_driver *dr = dev->driver;
int ret = 0;
- dr = dev->driver;
-
UACCE_BUS_DEBUG("detach device %s using driver: %s", dev->device.name, dr->driver.name);
- if (dr->remove) {
+ if (dr->remove != NULL) {
ret = dr->remove(dev);
if (ret < 0)
return ret;
@@ -503,10 +503,9 @@ uacce_detach_dev(struct rte_uacce_device *dev)
static int
uacce_unplug(struct rte_device *dev)
{
- struct rte_uacce_device *uacce_dev;
+ struct rte_uacce_device *uacce_dev = RTE_DEV_TO_UACCE_DEV(dev);
int ret;
- uacce_dev = RTE_DEV_TO_UACCE_DEV(dev);
ret = uacce_detach_dev(uacce_dev);
if (ret == 0) {
TAILQ_REMOVE(&uacce_bus.device_list, uacce_dev, next);
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index a200a67847..906e9dbe08 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -567,9 +567,9 @@ vdev_cleanup(void)
RTE_TAILQ_FOREACH_SAFE(dev, &vdev_device_list, next, tmp_dev) {
const struct rte_vdev_driver *drv;
- int ret = 0;
+ int ret;
- if (dev->device.driver == NULL)
+ if (!rte_dev_is_probed(&dev->device))
goto free;
drv = container_of(dev->device.driver, const struct rte_vdev_driver, driver);
diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
index bdc0fbb62d..d38c75d597 100644
--- a/drivers/bus/vmbus/vmbus_common.c
+++ b/drivers/bus/vmbus/vmbus_common.c
@@ -210,7 +210,9 @@ rte_vmbus_cleanup(void)
const struct rte_vmbus_driver *drv = dev->driver;
int ret;
- if (drv == NULL || drv->remove == NULL)
+ if (!rte_dev_is_probed(&dev->device))
+ continue;
+ if (drv->remove == NULL)
continue;
ret = drv->remove(dev);
--
2.53.0
^ permalink raw reply related
* [PATCH v2 05/23] drivers/bus: remove device and driver checks in plug
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Parav Pandit, Xueming Li,
Rosen Xu, Tomasz Duszynski
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
The bus-specific device conversion macros all use container_of()
to convert from a generic rte_device pointer to a bus-specific
device structure.
A key property of container_of() is that it does NOT return NULL when
given a NULL pointer as input. Instead, it returns (NULL - offset),
which is a small non-NULL pointer value. This means NULL checks on
container_of() results cannot work as intended.
The device parameter passed to bus probe or plug operations cannot be NULL
as the caller already dereferenced the bus structure to invoke these
operations. Remove redundant NULL checks on the device parameter and
derived device pointers.
The driver reference in the bus-specific device cannot be NULL since
calling the .plug op is done after dereferencing this pointer.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/auxiliary/auxiliary_common.c | 6 ------
drivers/bus/ifpga/ifpga_bus.c | 3 ---
drivers/bus/platform/platform.c | 8 +-------
3 files changed, 1 insertion(+), 16 deletions(-)
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index 1fe0cb4d78..314361643c 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -81,9 +81,6 @@ rte_auxiliary_probe_one_driver(struct rte_auxiliary_driver *drv,
enum rte_iova_mode iova_mode;
int ret;
- if (drv == NULL || dev == NULL)
- return -EINVAL;
-
/* Check if driver supports it. */
if (!auxiliary_match(drv, dev))
/* Match of device and driver failed */
@@ -174,9 +171,6 @@ auxiliary_probe_all_drivers(struct rte_auxiliary_device *dev)
struct rte_auxiliary_driver *drv;
int rc;
- if (dev == NULL)
- return -EINVAL;
-
FOREACH_DRIVER_ON_AUXILIARY_BUS(drv) {
if (!drv->match(dev->name))
continue;
diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index fc5308b6f4..0f331fa6dd 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -302,9 +302,6 @@ ifpga_probe_all_drivers(struct rte_afu_device *afu_dev)
struct rte_afu_driver *drv = NULL;
int ret = 0;
- if (afu_dev == NULL)
- return -1;
-
/* Check if a driver is already loaded */
if (rte_dev_is_probed(&afu_dev->device)) {
IFPGA_BUS_DEBUG("Device %s is already probed",
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index 0345f1daf7..5cc0d69209 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -458,19 +458,13 @@ platform_bus_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, cons
static int
platform_bus_plug(struct rte_device *dev)
{
- struct rte_platform_device *pdev;
-
if (rte_bus_device_is_ignored(&platform_bus.bus, dev->name))
return -EPERM;
if (!dev_is_bound_vfio_platform(dev->name))
return -EPERM;
- pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
- if (pdev == NULL)
- return -EINVAL;
-
- return device_attach(pdev);
+ return device_attach(RTE_DEV_TO_PLATFORM_DEV(dev));
}
static void
--
2.53.0
^ permalink raw reply related
* [PATCH v2 03/23] bus: remove device and driver checks in DMA map/unmap
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev
Cc: thomas, stephen, bruce.richardson, Parav Pandit, Xueming Li,
Chenbo Xia, Nipun Gupta, Tomasz Duszynski
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
Add rte_dev_is_probed() check in rte_dev_dma_map() and
rte_dev_dma_unmap() before calling bus-specific implementations.
The device parameter passed to bus DMA map/unmap operations cannot be
NULL as the caller already dereferenced the bus structure to invoke
these operations.
The driver reference in the bus-specific device cannot be NULL since
calling the .dma_map is done after dereferencing this pointer.
Remove redundant checks on probed device, and NULL checks on the
device/driver parameter and derived device/driver pointers.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/auxiliary/auxiliary_common.c | 8 --------
drivers/bus/pci/pci_common.c | 12 ++----------
drivers/bus/platform/platform.c | 16 ++--------------
drivers/bus/vdev/vdev.c | 24 ++----------------------
lib/eal/common/eal_common_dev.c | 8 ++++++++
5 files changed, 14 insertions(+), 54 deletions(-)
diff --git a/drivers/bus/auxiliary/auxiliary_common.c b/drivers/bus/auxiliary/auxiliary_common.c
index 8f3e90eaf0..9690687600 100644
--- a/drivers/bus/auxiliary/auxiliary_common.c
+++ b/drivers/bus/auxiliary/auxiliary_common.c
@@ -356,10 +356,6 @@ auxiliary_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev);
- if (dev == NULL || aux_dev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
if (aux_dev->driver->dma_map == NULL) {
rte_errno = ENOTSUP;
return -1;
@@ -373,10 +369,6 @@ auxiliary_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,
{
struct rte_auxiliary_device *aux_dev = RTE_DEV_TO_AUXILIARY(dev);
- if (dev == NULL || aux_dev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
if (aux_dev->driver->dma_unmap == NULL) {
rte_errno = ENOTSUP;
return -1;
diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c
index 51fd8c80e4..d7f028e365 100644
--- a/drivers/bus/pci/pci_common.c
+++ b/drivers/bus/pci/pci_common.c
@@ -672,11 +672,7 @@ pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
- if (!pdev || !pdev->driver) {
- rte_errno = EINVAL;
- return -1;
- }
- if (pdev->driver->dma_map)
+ if (pdev->driver->dma_map != NULL)
return pdev->driver->dma_map(pdev, addr, iova, len);
/**
* In case driver don't provides any specific mapping
@@ -695,11 +691,7 @@ pci_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
- if (!pdev || !pdev->driver) {
- rte_errno = EINVAL;
- return -1;
- }
- if (pdev->driver->dma_unmap)
+ if (pdev->driver->dma_unmap != NULL)
return pdev->driver->dma_unmap(pdev, addr, iova, len);
/**
* In case driver don't provides any specific mapping
diff --git a/drivers/bus/platform/platform.c b/drivers/bus/platform/platform.c
index e54098d04f..8a89a3cad8 100644
--- a/drivers/bus/platform/platform.c
+++ b/drivers/bus/platform/platform.c
@@ -530,13 +530,7 @@ platform_bus_parse(const char *name, void *addr)
static int
platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_platform_device *pdev;
-
- pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
- if (pdev == NULL || pdev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
+ struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
if (pdev->driver->dma_map != NULL)
return pdev->driver->dma_map(pdev, addr, iova, len);
@@ -547,13 +541,7 @@ platform_bus_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t l
static int
platform_bus_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
{
- struct rte_platform_device *pdev;
-
- pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
- if (pdev == NULL || pdev->driver == NULL) {
- rte_errno = EINVAL;
- return -1;
- }
+ struct rte_platform_device *pdev = RTE_DEV_TO_PLATFORM_DEV(dev);
if (pdev->driver->dma_unmap != NULL)
return pdev->driver->dma_unmap(pdev, addr, iova, len);
diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c
index eb1de0186e..a200a67847 100644
--- a/drivers/bus/vdev/vdev.c
+++ b/drivers/bus/vdev/vdev.c
@@ -144,20 +144,10 @@ vdev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
const struct rte_vdev_driver *driver;
- if (!vdev) {
- rte_errno = EINVAL;
- return -1;
- }
-
- if (!vdev->device.driver) {
- VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
- return 1;
- }
-
driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
driver);
- if (driver->dma_map)
+ if (driver->dma_map != NULL)
return driver->dma_map(vdev, addr, iova, len);
return 0;
@@ -169,20 +159,10 @@ vdev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
struct rte_vdev_device *vdev = RTE_DEV_TO_VDEV(dev);
const struct rte_vdev_driver *driver;
- if (!vdev) {
- rte_errno = EINVAL;
- return -1;
- }
-
- if (!vdev->device.driver) {
- VDEV_LOG(DEBUG, "no driver attach to device %s", dev->name);
- return 1;
- }
-
driver = container_of(vdev->device.driver, const struct rte_vdev_driver,
driver);
- if (driver->dma_unmap)
+ if (driver->dma_unmap != NULL)
return driver->dma_unmap(vdev, addr, iova, len);
return 0;
diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c
index 7185de0cb9..fceca75223 100644
--- a/lib/eal/common/eal_common_dev.c
+++ b/lib/eal/common/eal_common_dev.c
@@ -829,6 +829,10 @@ int
rte_dev_dma_map(struct rte_device *dev, void *addr, uint64_t iova,
size_t len)
{
+ if (!rte_dev_is_probed(dev)) {
+ rte_errno = EINVAL;
+ return -1;
+ }
if (dev->bus->dma_map == NULL || len == 0) {
rte_errno = ENOTSUP;
return -1;
@@ -847,6 +851,10 @@ int
rte_dev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,
size_t len)
{
+ if (!rte_dev_is_probed(dev)) {
+ rte_errno = EINVAL;
+ return -1;
+ }
if (dev->bus->dma_unmap == NULL || len == 0) {
rte_errno = ENOTSUP;
return -1;
--
2.53.0
^ permalink raw reply related
* [PATCH v2 01/23] bus/ifpga: remove unused AFU lookup helper
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev; +Cc: thomas, stephen, bruce.richardson, Rosen Xu, Andy Pei
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
This helper got left behind after another cleanup.
Fixes: 8418c92811b4 ("net/ipn3ke: remove configuration for i40e port bonding")
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/bus/ifpga/bus_ifpga_driver.h | 10 ----------
drivers/bus/ifpga/ifpga_bus.c | 13 -------------
2 files changed, 23 deletions(-)
diff --git a/drivers/bus/ifpga/bus_ifpga_driver.h b/drivers/bus/ifpga/bus_ifpga_driver.h
index d34ab8cec1..c0f5fb5b85 100644
--- a/drivers/bus/ifpga/bus_ifpga_driver.h
+++ b/drivers/bus/ifpga/bus_ifpga_driver.h
@@ -116,16 +116,6 @@ rte_ifpga_device_name(const struct rte_afu_device *afu)
return NULL;
}
-/**
- * Find AFU by AFU name.
- *
- * @param name
- * A pointer to AFU name string.
- */
-__rte_internal
-struct rte_afu_device *
-rte_ifpga_find_afu_by_name(const char *name);
-
/**
* Register a ifpga afu device driver.
*
diff --git a/drivers/bus/ifpga/ifpga_bus.c b/drivers/bus/ifpga/ifpga_bus.c
index ca2812a960..5cc1207c46 100644
--- a/drivers/bus/ifpga/ifpga_bus.c
+++ b/drivers/bus/ifpga/ifpga_bus.c
@@ -74,19 +74,6 @@ ifpga_find_afu_dev(const struct rte_rawdev *rdev,
return NULL;
}
-RTE_EXPORT_INTERNAL_SYMBOL(rte_ifpga_find_afu_by_name)
-struct rte_afu_device *
-rte_ifpga_find_afu_by_name(const char *name)
-{
- struct rte_afu_device *afu_dev = NULL;
-
- TAILQ_FOREACH(afu_dev, &ifpga_afu_dev_list, next) {
- if (!strcmp(afu_dev->device.name, name))
- return afu_dev;
- }
- return NULL;
-}
-
static const char * const valid_args[] = {
#define IFPGA_ARG_NAME "ifpga"
IFPGA_ARG_NAME,
--
2.53.0
^ permalink raw reply related
* [PATCH v2 02/23] crypto/octeontx: remove check on driver in remove
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev; +Cc: thomas, stephen, bruce.richardson, Anoob Joseph
In-Reply-To: <20260506155201.2709810-1-david.marchand@redhat.com>
The driver reference in the bus-specific device cannot be NULL since
calling the .remove is done after dereferencing this pointer.
Signed-off-by: David Marchand <david.marchand@redhat.com>
Acked-by: Anoob Joseph <anoobj@marvell.com>
---
drivers/crypto/octeontx/otx_cryptodev.c | 3 ---
1 file changed, 3 deletions(-)
diff --git a/drivers/crypto/octeontx/otx_cryptodev.c b/drivers/crypto/octeontx/otx_cryptodev.c
index b5ab937c3a..b2f6f53ee3 100644
--- a/drivers/crypto/octeontx/otx_cryptodev.c
+++ b/drivers/crypto/octeontx/otx_cryptodev.c
@@ -87,9 +87,6 @@ otx_cpt_pci_remove(struct rte_pci_device *pci_dev)
if (cryptodev == NULL)
return -ENODEV;
- if (pci_dev->driver == NULL)
- return -ENODEV;
-
dev_priv = cryptodev->data->dev_private;
/* free crypto device */
--
2.53.0
^ permalink raw reply related
* [PATCH v2 00/23] Consolidate bus driver infrastructure
From: David Marchand @ 2026-05-06 15:51 UTC (permalink / raw)
To: dev; +Cc: thomas, stephen, bruce.richardson
In-Reply-To: <20260429114503.932575-1-david.marchand@redhat.com>
This is a continuation of the work I started on the bus infrastructure,
but this time, a lot of the changes were done by a AI "friend".
It is still an unfinished topic as the current series focuses on probing
only. The detaching/cleanup aspect is postponed to another release/time.
My AI "friend" really *sucked* at git and at separating unrelated changes,
so it required quite a lot of massage/polishing afterwards.
But it seems good enough now for upstream submission.
I would like to see this series merged in 26.07, so that we have enough
time to stabilize it before the next LTS.
And seeing how it affects drivers, it is probably better to merge it
the sooner possible (so Thomas does not have to solve too many conflicts
when pulling next-* subtrees after, especially wrt the last patch).
This series refactors the DPDK bus infrastructure to consolidate common
operations and reduce code duplication across all bus drivers.
Currently, each bus implements its own specific device/driver lists,
probe logic, and lookup functions.
This series moves these common patterns into the EAL bus layer,
providing generic helpers that all buses can use.
The refactoring removes approximately 1,400 lines of duplicated code across
the codebase while maintaining full functional equivalence.
Key changes:
- Factorize device and driver lists into struct rte_bus
- Implement generic probe, device/driver lookup, and iteration helpers in EAL
- Introduce conversion macros (RTE_BUS_DEVICE, RTE_BUS_DRIVER, RTE_CLASS_TO_BUS_DEVICE)
to safely convert between generic and bus-specific types
- Remove bus-specific device/driver types from most driver code
- Move probe logic from individual buses to rte_bus_generic_probe()
- Separate NXP-specific metadata from generic bus structures
Benefits:
- Significant code reduction (~1,400 lines removed)
- Consistent behavior across all bus types
- Simplified bus driver implementation
- Easier maintenance and future enhancements
The series is structured as a progressive refactoring:
- Remove redundant checks and helpers (patches 1-5)
- Add conversion macros and factorize lists (patches 6-8)
- Consolidate device/driver lookup and iteration (patches 9-11)
- Refactor probe logic (patches 12-15)
- Remove bus-specific types from drivers (patches 16-23)
Note on ABI:
This series breaks the ABI for drivers (changes to rte_pci_device,
rte_pci_driver, and similar structures for other buses). However, the DPDK
ABI policy does not provide guarantees for driver-level interfaces.
--
David Marchand
Changes since v1:
- fix typo in Windows code for net/mlx5,
David Marchand (23):
bus/ifpga: remove unused AFU lookup helper
crypto/octeontx: remove check on driver in remove
bus: remove device and driver checks in DMA map/unmap
drivers/bus: remove device and driver checks in unplug
drivers/bus: remove device and driver checks in plug
bus: add bus conversion macros
bus: factorize driver list
bus: factorize device list
bus: consolidate device lookup
bus: consolidate device iteration
bus: factorize driver lookup
bus: refactor device probe
bus: support multiple probe
drivers/bus: initialize NXP bus specifics in scan
bus: implement probe in EAL
bus: factorize driver reference
drivers: rely on generic driver
drivers/bus: remove bus-specific driver references
dma/idxd: remove specific bus type
drivers/bus: separate specific bus metadata for NXP drivers
drivers/bus: remove specific bus types
eventdev: rename dev field to device
bus: add class device conversion macro
app/test/test_vdev.c | 6 +-
drivers/baseband/acc/rte_acc100_pmd.c | 4 +-
drivers/baseband/acc/rte_vrb_pmd.c | 2 +-
.../fpga_5gnr_fec/rte_fpga_5gnr_fec.c | 4 +-
drivers/baseband/fpga_lte_fec/fpga_lte_fec.c | 2 +-
drivers/bus/auxiliary/auxiliary_common.c | 256 +++-----------
drivers/bus/auxiliary/auxiliary_params.c | 65 ----
drivers/bus/auxiliary/bus_auxiliary_driver.h | 17 +-
drivers/bus/auxiliary/linux/auxiliary.c | 12 +-
drivers/bus/auxiliary/meson.build | 5 +-
drivers/bus/auxiliary/private.h | 45 +--
drivers/bus/cdx/bus_cdx_driver.h | 17 -
drivers/bus/cdx/cdx.c | 259 +++-----------
drivers/bus/cdx/private.h | 9 -
drivers/bus/dpaa/bus_dpaa_driver.h | 10 +-
drivers/bus/dpaa/dpaa_bus.c | 317 ++++++-----------
drivers/bus/fslmc/bus_fslmc_driver.h | 7 +-
drivers/bus/fslmc/fslmc_bus.c | 330 ++++++-----------
drivers/bus/fslmc/fslmc_vfio.c | 55 ++-
drivers/bus/fslmc/portal/dpaa2_hw_dprc.c | 4 +-
drivers/bus/fslmc/private.h | 15 +-
drivers/bus/ifpga/bus_ifpga_driver.h | 32 +-
drivers/bus/ifpga/ifpga_bus.c | 188 ++--------
drivers/bus/pci/bsd/pci.c | 14 +-
drivers/bus/pci/bus_pci_driver.h | 15 +-
drivers/bus/pci/linux/pci.c | 11 +-
drivers/bus/pci/linux/pci_uio.c | 6 +-
drivers/bus/pci/pci_common.c | 331 +++++-------------
drivers/bus/pci/pci_params.c | 9 +-
drivers/bus/pci/private.h | 64 +---
drivers/bus/pci/windows/pci.c | 11 +-
drivers/bus/platform/bus_platform_driver.h | 14 -
drivers/bus/platform/meson.build | 5 +-
drivers/bus/platform/platform.c | 191 +++-------
drivers/bus/platform/platform_params.c | 72 ----
drivers/bus/platform/private.h | 25 --
drivers/bus/uacce/bus_uacce_driver.h | 14 -
drivers/bus/uacce/uacce.c | 241 +++----------
drivers/bus/vdev/bus_vdev_driver.h | 15 +-
drivers/bus/vdev/meson.build | 5 +-
drivers/bus/vdev/vdev.c | 212 +++++------
drivers/bus/vdev/vdev_logs.h | 16 -
drivers/bus/vdev/vdev_params.c | 64 ----
drivers/bus/vdev/vdev_private.h | 28 --
drivers/bus/vmbus/bus_vmbus_driver.h | 3 -
drivers/bus/vmbus/linux/vmbus_bus.c | 11 +-
drivers/bus/vmbus/private.h | 23 +-
drivers/bus/vmbus/vmbus_common.c | 190 +++-------
drivers/common/mlx5/linux/mlx5_common_os.c | 5 +-
drivers/common/mlx5/mlx5_common.c | 2 +-
drivers/common/mlx5/mlx5_common_pci.c | 2 +-
drivers/common/mlx5/windows/mlx5_common_os.c | 2 +-
drivers/common/qat/qat_qp.c | 4 +-
drivers/common/zsda/zsda_qp.c | 4 +-
drivers/compress/octeontx/otx_zip.c | 2 +-
drivers/crypto/cnxk/cnxk_cryptodev_ops.c | 2 +-
drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 3 +-
drivers/crypto/octeontx/otx_cryptodev.c | 3 -
drivers/crypto/octeontx/otx_cryptodev_ops.c | 4 +-
drivers/dma/idxd/idxd_bus.c | 114 ++----
drivers/event/cnxk/cn10k_eventdev.c | 8 +-
drivers/event/cnxk/cn20k_eventdev.c | 8 +-
drivers/event/cnxk/cn9k_eventdev.c | 6 +-
drivers/event/cnxk/cnxk_eventdev.c | 2 +-
drivers/event/dlb2/pf/dlb2_pf.c | 2 +-
drivers/event/skeleton/skeleton_eventdev.c | 2 +-
drivers/net/ark/ark_ethdev.c | 2 +-
drivers/net/atlantic/atl_ethdev.c | 12 +-
drivers/net/avp/avp_ethdev.c | 22 +-
drivers/net/axgbe/axgbe_ethdev.c | 4 +-
drivers/net/bnx2x/bnx2x_ethdev.c | 2 +-
drivers/net/bnxt/bnxt_ethdev.c | 12 +-
drivers/net/bnxt/tf_ulp/bnxt_ulp.c | 4 +-
drivers/net/bonding/rte_eth_bond_args.c | 4 +-
drivers/net/cnxk/cnxk_ethdev.c | 2 +-
drivers/net/cnxk/cnxk_ethdev_ops.c | 2 +-
drivers/net/cxgbe/cxgbe_ethdev.c | 4 +-
drivers/net/cxgbe/cxgbevf_ethdev.c | 4 +-
drivers/net/dpaa/dpaa_ethdev.c | 17 +-
drivers/net/dpaa2/dpaa2_ethdev.c | 8 +-
drivers/net/dpaa2/dpaa2_recycle.c | 8 +-
drivers/net/ena/ena_ethdev.c | 10 +-
drivers/net/enetc/enetc4_ethdev.c | 4 +-
drivers/net/enetc/enetc4_vf.c | 4 +-
drivers/net/enetc/enetc_ethdev.c | 2 +-
drivers/net/enic/enic_ethdev.c | 4 +-
drivers/net/enic/enic_fm_flow.c | 6 +-
drivers/net/enic/enic_vf_representor.c | 2 +-
drivers/net/gve/gve_ethdev.c | 2 +-
drivers/net/hinic/hinic_pmd_ethdev.c | 8 +-
drivers/net/hinic3/base/hinic3_hwdev.c | 7 +-
drivers/net/hinic3/hinic3_ethdev.c | 16 +-
drivers/net/hns3/hns3_cmd.c | 2 +-
drivers/net/hns3/hns3_common.c | 8 +-
drivers/net/hns3/hns3_ethdev.c | 6 +-
drivers/net/hns3/hns3_ethdev_vf.c | 6 +-
drivers/net/hns3/hns3_rxtx.c | 4 +-
drivers/net/intel/cpfl/cpfl_ethdev.c | 4 +-
drivers/net/intel/cpfl/cpfl_ethdev.h | 2 +-
drivers/net/intel/e1000/em_ethdev.c | 12 +-
drivers/net/intel/e1000/em_rxtx.c | 2 +-
drivers/net/intel/e1000/igb_ethdev.c | 30 +-
drivers/net/intel/e1000/igb_pf.c | 2 +-
drivers/net/intel/e1000/igc_ethdev.c | 22 +-
drivers/net/intel/fm10k/fm10k_ethdev.c | 16 +-
drivers/net/intel/i40e/i40e_ethdev.c | 28 +-
drivers/net/intel/i40e/i40e_ethdev.h | 2 +-
drivers/net/intel/iavf/iavf_ethdev.c | 8 +-
drivers/net/intel/ice/ice_dcf.c | 6 +-
drivers/net/intel/ice/ice_ethdev.c | 6 +-
drivers/net/intel/ice/ice_ethdev.h | 2 +-
drivers/net/intel/idpf/idpf_ethdev.h | 2 +-
drivers/net/intel/ipn3ke/ipn3ke_ethdev.h | 13 -
drivers/net/intel/ipn3ke/ipn3ke_representor.c | 6 +-
drivers/net/intel/ixgbe/ixgbe_ethdev.c | 40 +--
drivers/net/intel/ixgbe/ixgbe_flow.c | 4 +-
drivers/net/intel/ixgbe/ixgbe_pf.c | 2 +-
drivers/net/intel/ixgbe/ixgbe_tm.c | 2 +-
.../net/intel/ixgbe/ixgbe_vf_representor.c | 2 +-
drivers/net/intel/ixgbe/rte_pmd_ixgbe.c | 20 +-
drivers/net/mlx5/linux/mlx5_os.c | 9 +-
drivers/net/mlx5/windows/mlx5_os.c | 4 +-
drivers/net/nbl/nbl_core.c | 2 +-
drivers/net/nbl/nbl_dev/nbl_dev.c | 6 +-
drivers/net/netvsc/hn_ethdev.c | 3 +-
drivers/net/nfp/nfp_ethdev.c | 8 +-
drivers/net/nfp/nfp_ethdev_vf.c | 6 +-
drivers/net/nfp/nfp_net_common.c | 8 +-
drivers/net/ngbe/ngbe_ethdev.c | 20 +-
drivers/net/ngbe/ngbe_ethdev_vf.c | 16 +-
drivers/net/ngbe/ngbe_pf.c | 2 +-
drivers/net/ntnic/ntnic_ethdev.c | 8 +-
drivers/net/octeon_ep/otx_ep_ethdev.c | 2 +-
drivers/net/octeon_ep/otx_ep_mbox.c | 6 +-
drivers/net/qede/qede_ethdev.c | 6 +-
drivers/net/r8169/r8169_ethdev.c | 6 +-
drivers/net/rnp/rnp_ethdev.c | 6 +-
drivers/net/sfc/sfc.c | 4 +-
drivers/net/sfc/sfc_ethdev.c | 2 +-
drivers/net/sfc/sfc_intr.c | 10 +-
drivers/net/sfc/sfc_rx.c | 3 +-
drivers/net/sfc/sfc_sriov.c | 2 +-
drivers/net/sfc/sfc_tx.c | 3 +-
drivers/net/thunderx/nicvf_ethdev.c | 4 +-
drivers/net/txgbe/txgbe_ethdev.c | 26 +-
drivers/net/txgbe/txgbe_ethdev_vf.c | 16 +-
drivers/net/txgbe/txgbe_flow.c | 4 +-
drivers/net/txgbe/txgbe_pf.c | 2 +-
drivers/net/txgbe/txgbe_tm.c | 2 +-
drivers/net/vdev_netvsc/vdev_netvsc.c | 2 +-
drivers/net/virtio/virtio_pci_ethdev.c | 11 +-
drivers/net/vmxnet3/vmxnet3_ethdev.c | 4 +-
drivers/net/xsc/xsc_ethdev.c | 2 +-
drivers/net/zxdh/zxdh_ethdev.c | 8 +-
drivers/raw/cnxk_bphy/cnxk_bphy.c | 2 +-
drivers/raw/cnxk_bphy/cnxk_bphy_cgx.c | 2 +-
drivers/raw/cnxk_rvu_lf/cnxk_rvu_lf.c | 2 +-
drivers/raw/ifpga/afu_pmd_core.c | 2 +-
drivers/raw/ifpga/afu_pmd_n3000.c | 4 +-
drivers/raw/ifpga/ifpga_rawdev.c | 4 +-
drivers/raw/ntb/ntb.c | 2 +-
lib/eal/common/eal_common_bus.c | 186 +++++++++-
lib/eal/common/eal_common_dev.c | 45 ++-
lib/eal/common/hotplug_mp.c | 4 +-
lib/eal/include/bus_driver.h | 305 +++++++++++++++-
lib/eal/include/dev_driver.h | 1 +
lib/eal/linux/eal_dev.c | 3 +-
lib/ethdev/ethdev_pci.h | 7 +-
lib/ethdev/rte_ethdev.c | 2 +-
lib/eventdev/eventdev_pmd.h | 2 +-
lib/eventdev/eventdev_pmd_pci.h | 4 +-
lib/eventdev/eventdev_pmd_vdev.h | 2 +-
lib/eventdev/rte_eventdev.c | 14 +-
173 files changed, 1661 insertions(+), 3012 deletions(-)
delete mode 100644 drivers/bus/auxiliary/auxiliary_params.c
delete mode 100644 drivers/bus/platform/platform_params.c
delete mode 100644 drivers/bus/vdev/vdev_logs.h
delete mode 100644 drivers/bus/vdev/vdev_params.c
delete mode 100644 drivers/bus/vdev/vdev_private.h
--
2.53.0
^ permalink raw reply
* Re: [RFC 1/3] flow_compile: introduce textual flow rule compiler
From: Stephen Hemminger @ 2026-05-06 15:46 UTC (permalink / raw)
To: Bruce Richardson; +Cc: dev
In-Reply-To: <afr2frTWMC3kGKxq@bricha3-mobl1.ger.corp.intel.com>
On Wed, 6 May 2026 09:06:22 +0100
Bruce Richardson <bruce.richardson@intel.com> wrote:
> >
> > Dependencies are limited to rte_ethdev and rte_net; no
> > librte_cmdline, no flex/bison, no platform-specific headers.
> > The grammar follows testpmd's syntax so familiar rules carry
> > over and is documented in the programmer's guide.
> >
> Was there a particular reason to avoid using flex/bison here, or did their
> use just not make sense? In general I would prefer using code-generation
> tools where possible rather than maintaining (metaphorically) hand-written code.
>
> /Bruce
As long as we are willing to accept flex/bison as build dependency,
it would make sense to use it.
^ permalink raw reply
* Re: [RFC v5 0/6] introduce PTP protocol library and software relay
From: Stephen Hemminger @ 2026-05-06 15:45 UTC (permalink / raw)
To: Rajesh Kumar; +Cc: dev, bruce.richardson, aman.deep.singh
In-Reply-To: <20260506154131.2496072-1-rajesh3.kumar@intel.com>
On Wed, 6 May 2026 21:11:22 +0530
Rajesh Kumar <rajesh3.kumar@intel.com> wrote:
> - Fixed checkpatch warnings: removed unnecessary #include <stdio.h>
PS. spelling error complaints about stdio.h are bogus
^ permalink raw reply
* Re: [PATCH 2/2] net/ice: fix shaper profile reference count tracking
From: Bruce Richardson @ 2026-05-06 15:40 UTC (permalink / raw)
To: Ciara Loftus; +Cc: dev, stable
In-Reply-To: <20260501105755.1136087-2-ciara.loftus@intel.com>
On Fri, May 01, 2026 at 10:57:55AM +0000, Ciara Loftus wrote:
> Currently, when a TM node is added with a shaper profile assigned,
> the profile's reference count is not incremented. Equally, when a node
> is deleted, the count is not decremented. As a result, the guard that
> blocks deletion of an in-use profile never triggers, allowing the profile
> to be freed while nodes still hold a pointer to it.
>
> Fix by maintaining the reference count correctly when nodes take or
> release a shaper profile, so that deletion of an in-use profile is
> properly rejected.
>
> Fixes: 8c481c3bb65b ("net/ice: support queue and queue group bandwidth limit")
> Cc: stable@dpdk.org
>
> Signed-off-by: Ciara Loftus <ciara.loftus@intel.com>
> ---
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
^ permalink raw reply
* Re: [PATCH v1 1/1] net/iavf: remove RAW flow item support from fsub
From: Bruce Richardson @ 2026-05-06 15:10 UTC (permalink / raw)
To: Anatoly Burakov; +Cc: dev, Vladimir Medvedkin
In-Reply-To: <34827309e49eaba498cfe41500ee8de1fd3a2bb5.1777542270.git.anatoly.burakov@intel.com>
On Thu, Apr 30, 2026 at 10:44:38AM +0100, Anatoly Burakov wrote:
> Currently, no kernel driver implements support for RAW items, so having
> this support in our parser is extra work for no value. Remove the support
> for RAW flow items until such time as there is kernel driver support.
>
> Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
> ---
> drivers/net/intel/iavf/iavf_fsub.c | 75 ------------------------------
> 1 file changed, 75 deletions(-)
>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Just to clarify, this is removing raw item support from the flow
subscription part of the driver. Raw flow support remains elsewhere.
With patch description reworded to clarify this,
applied to dpdk-next-net-intel.
Thanks,
/Bruce
> diff --git a/drivers/net/intel/iavf/iavf_fsub.c b/drivers/net/intel/iavf/iavf_fsub.c
> index bfb34695de..a00d02ded5 100644
> --- a/drivers/net/intel/iavf/iavf_fsub.c
> +++ b/drivers/net/intel/iavf/iavf_fsub.c
> @@ -57,7 +57,6 @@ static struct iavf_flow_parser iavf_fsub_parser;
>
> static struct
> iavf_pattern_match_item iavf_fsub_pattern_list[] = {
> - {iavf_pattern_raw, IAVF_INSET_NONE, IAVF_INSET_NONE},
> {iavf_pattern_ethertype, IAVF_SW_INSET_ETHER, IAVF_INSET_NONE},
> {iavf_pattern_eth_ipv4, IAVF_SW_INSET_MAC_IPV4, IAVF_INSET_NONE},
> {iavf_pattern_eth_vlan_ipv4, IAVF_SW_INSET_MAC_VLAN_IPV4, IAVF_INSET_NONE},
> @@ -154,7 +153,6 @@ iavf_fsub_parse_pattern(const struct rte_flow_item pattern[],
> {
> struct virtchnl_proto_hdrs *hdrs = &filter->sub_fltr.proto_hdrs;
> enum rte_flow_item_type item_type;
> - const struct rte_flow_item_raw *raw_spec, *raw_mask;
> const struct rte_flow_item_eth *eth_spec, *eth_mask;
> const struct rte_flow_item_ipv4 *ipv4_spec, *ipv4_mask;
> const struct rte_flow_item_ipv6 *ipv6_spec, *ipv6_mask;
> @@ -166,7 +164,6 @@ iavf_fsub_parse_pattern(const struct rte_flow_item pattern[],
> uint64_t outer_input_set = IAVF_INSET_NONE;
> uint64_t *input = NULL;
> uint16_t input_set_byte = 0;
> - uint8_t item_num = 0;
> uint32_t layer = 0;
>
> for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
> @@ -178,79 +175,7 @@ iavf_fsub_parse_pattern(const struct rte_flow_item pattern[],
> }
>
> item_type = item->type;
> - item_num++;
> -
> switch (item_type) {
> - case RTE_FLOW_ITEM_TYPE_RAW: {
> - raw_spec = item->spec;
> - raw_mask = item->mask;
> -
> - if (!raw_spec || !raw_mask) {
> - PMD_DRV_LOG(ERR, "NULL RAW spec/mask");
> - rte_flow_error_set(error, EINVAL,
> - RTE_FLOW_ERROR_TYPE_ITEM,
> - item, "NULL RAW spec/mask");
> - return -rte_errno;
> - }
> -
> - if (item_num != 1)
> - return -rte_errno;
> -
> - if (raw_spec->length != raw_mask->length)
> - return -rte_errno;
> -
> - uint16_t pkt_len = 0;
> - uint16_t tmp_val = 0;
> - uint8_t tmp = 0;
> - int i, j;
> -
> - pkt_len = raw_spec->length;
> -
> - for (i = 0, j = 0; i < pkt_len; i += 2, j++) {
> - tmp = raw_spec->pattern[i];
> - if (tmp >= 'a' && tmp <= 'f')
> - tmp_val = tmp - 'a' + 10;
> - if (tmp >= 'A' && tmp <= 'F')
> - tmp_val = tmp - 'A' + 10;
> - if (tmp >= '0' && tmp <= '9')
> - tmp_val = tmp - '0';
> -
> - tmp_val *= 16;
> - tmp = raw_spec->pattern[i + 1];
> - if (tmp >= 'a' && tmp <= 'f')
> - tmp_val += (tmp - 'a' + 10);
> - if (tmp >= 'A' && tmp <= 'F')
> - tmp_val += (tmp - 'A' + 10);
> - if (tmp >= '0' && tmp <= '9')
> - tmp_val += (tmp - '0');
> -
> - hdrs->raw.spec[j] = tmp_val;
> -
> - tmp = raw_mask->pattern[i];
> - if (tmp >= 'a' && tmp <= 'f')
> - tmp_val = tmp - 'a' + 10;
> - if (tmp >= 'A' && tmp <= 'F')
> - tmp_val = tmp - 'A' + 10;
> - if (tmp >= '0' && tmp <= '9')
> - tmp_val = tmp - '0';
> -
> - tmp_val *= 16;
> - tmp = raw_mask->pattern[i + 1];
> - if (tmp >= 'a' && tmp <= 'f')
> - tmp_val += (tmp - 'a' + 10);
> - if (tmp >= 'A' && tmp <= 'F')
> - tmp_val += (tmp - 'A' + 10);
> - if (tmp >= '0' && tmp <= '9')
> - tmp_val += (tmp - '0');
> -
> - hdrs->raw.mask[j] = tmp_val;
> - }
> -
> - hdrs->raw.pkt_len = pkt_len / 2;
> - hdrs->tunnel_level = 0;
> - hdrs->count = 0;
> - return 0;
> - }
> case RTE_FLOW_ITEM_TYPE_ETH:
> eth_spec = item->spec;
> eth_mask = item->mask;
> --
> 2.47.3
>
^ permalink raw reply
* Re: [PATCH] net/iavf: add support for QinQ insertion
From: Bruce Richardson @ 2026-05-06 14:38 UTC (permalink / raw)
To: Anurag Mandal; +Cc: dev, vladimir.medvedkin
In-Reply-To: <20260430085813.230798-1-anurag.mandal@intel.com>
On Thu, Apr 30, 2026 at 08:58:13AM +0000, Anurag Mandal wrote:
> QinQ insertion with VLAN TPID 0x88a8 support is absent.
>
> This patch adds support for QinQ insertion for both
> Outer VLAN TPIDs 0x88a8 (802.1ad) & 0x8100 (802.1Q).
> VLAN Extend should be enabled for the same and Outer
> VLAN TPID should be set properly for TPID 0x88a8.
>
> Signed-off-by: Anurag Mandal <anurag.mandal@intel.com>
> ---
> doc/guides/nics/intel_vf.rst | 19 ++++++++++
> drivers/net/intel/iavf/iavf.h | 1 +
> drivers/net/intel/iavf/iavf_vchnl.c | 56 +++++++++++++++++++++++++++--
> 3 files changed, 74 insertions(+), 2 deletions(-)
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
Applied to dpdk-next-net-intel.
Thanks,
/Bruce
^ permalink raw reply
* [PATCH v1 1/1] net/iavf: fix large VF IRQ mapping
From: Anatoly Burakov @ 2026-05-06 14:07 UTC (permalink / raw)
To: dev, Vladimir Medvedkin, Bruce Richardson
The PF will check buffer size for being too big, and the chunk sizing code
correctly calls that out. However, the size was actually still too big
because `struct virtchnl_queue_vector_maps` already had one queue vector
as part of its definition, so `chunk_sz` was too big by 1.
Fixes: 292d3b781ac4 ("net/iavf: replace unnecessary hugepage memory allocations")
Signed-off-by: Anatoly Burakov <anatoly.burakov@intel.com>
---
drivers/net/intel/iavf/iavf_vchnl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/intel/iavf/iavf_vchnl.c b/drivers/net/intel/iavf/iavf_vchnl.c
index c2f340db81..dd09b0fa61 100644
--- a/drivers/net/intel/iavf/iavf_vchnl.c
+++ b/drivers/net/intel/iavf/iavf_vchnl.c
@@ -1528,7 +1528,7 @@ iavf_config_irq_map_lv_chunk(struct iavf_adapter *adapter,
/* for some reason PF side checks for buffer being too big, so adjust it down */
buf_len = sizeof(struct virtchnl_queue_vector_maps) +
- sizeof(struct virtchnl_queue_vector) * chunk_sz;
+ sizeof(struct virtchnl_queue_vector) * (chunk_sz - 1);
args.ops = VIRTCHNL_OP_MAP_QUEUE_VECTOR;
args.in_args = (u8 *)map_info;
--
2.47.3
^ permalink raw reply related
* Re: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
From: Reema Sharma @ 2026-05-06 7:17 UTC (permalink / raw)
To: Thomas Monjalon
Cc: dev@dpdk.org, gakhil@marvell.com, david.marchand@redhat.com,
stephen@networkplumber.org, anatoly.burakov@intel.com,
jack.bond-preston@foss.arm.com, fanzhang.oss@gmail.com,
kai.ji@intel.com, Prakash Durgapal, Pratap Rana,
Vijay Kumar Mahto, Jaydipkumar Dhameliya, Liu1, Kai,
Zhang, Liheng, Xiong, Tanghong, Mattias Rönnblom
In-Reply-To: <DS0PR08MB9465E290C821A7DB32822DA08656A@DS0PR08MB9465.namprd08.prod.outlook.com>
[-- Attachment #1: Type: text/plain, Size: 12750 bytes --]
Hi Thomas Monjalon<mailto:thomas@monjalon.net> and Team,
I hope you are doing well.
I wanted to follow up on my earlier request regarding the review of the fix for the DPDK 24.11 and 25.11 compilation issues, which was expected to be available in a future DPDK release.
Could you please confirm when the fix is likely to be available and in which upcoming release, we can expect it?
Thanks & Regards,
Reema Sharma
________________________________
From: Reema Sharma <Reema.Sharma@radisys.com>
Sent: Thursday, March 26, 2026 2:16 PM
To: Thomas Monjalon <thomas@monjalon.net>
Cc: dev@dpdk.org <dev@dpdk.org>; gakhil@marvell.com <gakhil@marvell.com>; david.marchand@redhat.com <david.marchand@redhat.com>; stephen@networkplumber.org <stephen@networkplumber.org>; anatoly.burakov@intel.com <anatoly.burakov@intel.com>; jack.bond-preston@foss.arm.com <jack.bond-preston@foss.arm.com>; gakhil@marvell.com <gakhil@marvell.com>; fanzhang.oss@gmail.com <fanzhang.oss@gmail.com>; kai.ji@intel.com <kai.ji@intel.com>; Prakash Durgapal <Prakash.Durgapal@radisys.com>; Pratap Rana <Pratap.Rana@radisys.com>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com>; Liu1, Kai <kai.liu1@intel.com>; Zhang, Liheng <liheng.zhang@intel.com>; Xiong, Tanghong <tanghong.xiong@intel.com>; Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Subject: Re: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
Hi Thomas Monjalon<mailto:thomas@monjalon.net>,
Thanks for the quick response.
Yes, you understood correctly. I encountered two issues while compiling a C++ application(Radisys CU module) linked with DPDK.
Compiler Version: gcc version 11.4.0 (ubuntu 22.04.3)
Regarding rte_bitops.h:
Disabling the macros works for my current use case, so I can proceed with that approach for now.
I agree that the behaviour of the __RTE_BIT_OVERLOAD macros needs further analysis, It will be great if fix for this will be available in next DPDK release. Please find the error details for your reference:
dpdk/dpdk-25.11/x86_64-native-linuxapp-gcc/include/rte_bitops.h:1468:1: error: conflicting declaration of C function ‘bool rte_bit_test(const volatile uint32_t*, unsigned int)’
1468 | rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_name) \
| ^~~~~~~~
dpdk/dpdk-25.11/x86_64-native-linuxapp-gcc/include/rte_bitops.h:1468:1: note: in definition of macro ‘__RTE_BIT_OVERLOAD_V_2R’
1468 | rte_bit_ ## family ## fun(qualifier uint ## size ## _t *addr, arg1_type arg1_name) \
| ^~~~~~~~
dpdk/dpdk-25.11/x86_64-native-linuxapp-gcc/include/rte_bitops.h:1479:9: note: in expansion of macro ‘__RTE_BIT_OVERLOAD_SZ_2R’
1479 | __RTE_BIT_OVERLOAD_SZ_2R(family, fun, qualifier, 32, ret_type, arg1_type, arg1_name) \
| ^~~~~~~~~~~~~~~~~~~~~~~~
Regarding rte_cryptodev.h:
This issue is not observed with DPDK 25.11. Please disregard the earlier report.
Thanks & Regards,
Reema Sharma
________________________________
From: Thomas Monjalon <thomas@monjalon.net>
Sent: Wednesday, March 25, 2026 1:47 PM
To: Reema Sharma <Reema.Sharma@radisys.com>
Cc: dev@dpdk.org <dev@dpdk.org>; gakhil@marvell.com <gakhil@marvell.com>; david.marchand@redhat.com <david.marchand@redhat.com>; stephen@networkplumber.org <stephen@networkplumber.org>; anatoly.burakov@intel.com <anatoly.burakov@intel.com>; jack.bond-preston@foss.arm.com <jack.bond-preston@foss.arm.com>; gakhil@marvell.com <gakhil@marvell.com>; fanzhang.oss@gmail.com <fanzhang.oss@gmail.com>; kai.ji@intel.com <kai.ji@intel.com>; Prakash Durgapal <Prakash.Durgapal@radisys.com>; Pratap Rana <Pratap.Rana@radisys.com>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com>; Liu1, Kai <kai.liu1@intel.com>; Zhang, Liheng <liheng.zhang@intel.com>; Xiong, Tanghong <tanghong.xiong@intel.com>; Mattias Rönnblom <mattias.ronnblom@ericsson.com>
Subject: Re: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
Hello,
If I understand well, you hit 2 issues while compiling a C++ app linked with DPDK?
Could you share the exact version of your compiler?
For rte_bitops.h, if disabling these macros is OK for you, go with it for now.
We will need to understand what happens exactly with __RTE_BIT_OVERLOAD macros.
For rte_cryptodev.h, it may be hiding an issue somewhere else.
Please could you share the exact error message?
25/03/2026 07:55, Reema Sharma:
> Hi Team,
>
> Could you please review the attached DPDK patch (dpdk-24.11_patch_for_crypto.patch) and confirm whether the applied fixes are acceptable from the DPDK perspective?
> Your guidance on the correct fix, if any changes are needed, would help us proceed with CU compilation.
> Kindly share an update at your earliest convenience.
> Thanks & Regards,
> Reema Sharma
> ________________________________
> From: Xiong, Tanghong <tanghong.xiong@intel.com>
> Sent: Friday, March 6, 2026 3:26 PM
> To: Zhang, Liheng <liheng.zhang@intel.com>; Reema Sharma <Reema.Sharma@radisys.com>; Liu1, Kai <kai.liu1@intel.com>
> Cc: Prakash Durgapal <Prakash.Durgapal@radisys.com>; Pratap Rana <Pratap.Rana@radisys.com>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com>
> Subject: RE: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
>
>
> Thanks Liheng,
>
> Just got other info that, you can contact DPDK directly through this mail: dev@dpdk.org<mailto:dev@dpdk.org>, but the response may be slow.
>
>
>
> BRs,
>
> Tanghong
>
>
>
> From: Zhang, Liheng <liheng.zhang@intel.com>
> Sent: Friday, March 6, 2026 5:51 PM
> To: Reema Sharma <Reema.Sharma@radisys.com>; Xiong, Tanghong <tanghong.xiong@intel.com>; Liu1, Kai <kai.liu1@intel.com>
> Cc: Durgapal, Prakash <prakash.durgapal@radisys.com>; Pratap Rana <Pratap.Rana@radisys.com>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com>
> Subject: RE: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
>
>
>
> Yes, there is a file “MAINTAINERS” in the DPDK root path.
>
> The file list all the contactor for all dpdk libraries.
>
> You can search and contact the person for crypto issue.
>
> If you can’t find it, please let me know, I can forward to you.
>
>
>
> From: Reema Sharma <Reema.Sharma@radisys.com<mailto:Reema.Sharma@radisys.com>>
> Sent: Friday, March 6, 2026 5:45 PM
> To: Zhang, Liheng <liheng.zhang@intel.com<mailto:liheng.zhang@intel.com>>; Xiong, Tanghong <tanghong.xiong@intel.com<mailto:tanghong.xiong@intel.com>>; Liu1, Kai <kai.liu1@intel.com<mailto:kai.liu1@intel.com>>
> Cc: Durgapal, Prakash <prakash.durgapal@radisys.com<mailto:prakash.durgapal@radisys.com>>; Pratap Rana <Pratap.Rana@radisys.com<mailto:Pratap.Rana@radisys.com>>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com<mailto:Vijay.Mahto@radisys.com>>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com<mailto:Jaydipkumar.Dhameliya@radisys.com>>
> Subject: Re: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
>
>
>
> Hi Zhang, Liheng<mailto:liheng.zhang@intel.com>,
>
> We have verified the behaviour on CU side and confirmed that this is not caused by our code. The issue appears to be related to a DPDK bug.
>
> At the moment, we do not have any contact information for the DPDK maintainers.
> Could you please check internally and share the relevant maintainer details or forward this issue on behalf of Radisys?
>
> Thanks & Regards,
>
> Reema Sharma
>
> ________________________________
>
> From: Zhang, Liheng <liheng.zhang@intel.com<mailto:liheng.zhang@intel.com>>
> Sent: Friday, March 6, 2026 2:49 PM
> To: Xiong, Tanghong <tanghong.xiong@intel.com<mailto:tanghong.xiong@intel.com>>; Reema Sharma <Reema.Sharma@radisys.com<mailto:Reema.Sharma@radisys.com>>; Liu1, Kai <kai.liu1@intel.com<mailto:kai.liu1@intel.com>>
> Cc: Prakash Durgapal <Prakash.Durgapal@radisys.com<mailto:Prakash.Durgapal@radisys.com>>; Pratap Rana <Pratap.Rana@radisys.com<mailto:Pratap.Rana@radisys.com>>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com<mailto:Vijay.Mahto@radisys.com>>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com<mailto:Jaydipkumar.Dhameliya@radisys.com>>
> Subject: RE: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
>
>
>
> The e-mail below is from an external source. Please do not open attachments or click links from an unknown or suspicious origin.
>
> Hi Reema
>
> Looks the changes are ok, but you need verify them by compiling your code.
>
> As I know, the following are the better procedures for DPDK bug fix:
>
> 1. Please first confirm the error are not related to your own code before changing DPDK code;
> 2. If it is real DPDK bug, you need contact the according DPDK maintainer to fix it;
> 3. Finally DPDK maintainer will provide an official patch;
>
>
>
> From: Xiong, Tanghong <tanghong.xiong@intel.com<mailto:tanghong.xiong@intel.com>>
> Sent: Friday, March 6, 2026 3:52 PM
> To: Reema Sharma <Reema.Sharma@radisys.com<mailto:Reema.Sharma@radisys.com>>; Liu1, Kai <kai.liu1@intel.com<mailto:kai.liu1@intel.com>>; Zhang, Liheng <liheng.zhang@intel.com<mailto:liheng.zhang@intel.com>>
> Cc: Durgapal, Prakash <prakash.durgapal@radisys.com<mailto:prakash.durgapal@radisys.com>>; Pratap Rana <Pratap.Rana@radisys.com<mailto:Pratap.Rana@radisys.com>>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com<mailto:Vijay.Mahto@radisys.com>>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com<mailto:Jaydipkumar.Dhameliya@radisys.com>>
> Subject: RE: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
>
>
>
> Hello Reema,
>
>
>
> Sorry for late reply, copy @Zhang, Liheng<mailto:liheng.zhang@intel.com> here for comment, thanks Liheng in advance.
>
>
>
> BRs,
>
> Tanghong
>
>
>
> From: Reema Sharma <Reema.Sharma@radisys.com<mailto:Reema.Sharma@radisys.com>>
> Sent: Friday, March 6, 2026 1:41 PM
> To: Xiong, Tanghong <tanghong.xiong@intel.com<mailto:tanghong.xiong@intel.com>>; Liu1, Kai <kai.liu1@intel.com<mailto:kai.liu1@intel.com>>
> Cc: Durgapal, Prakash <prakash.durgapal@radisys.com<mailto:prakash.durgapal@radisys.com>>; Pratap Rana <Pratap.Rana@radisys.com<mailto:Pratap.Rana@radisys.com>>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com<mailto:Vijay.Mahto@radisys.com>>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com<mailto:Jaydipkumar.Dhameliya@radisys.com>>
> Subject: Re: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
>
>
>
> Hi Xiong, Tanghong<mailto:tanghong.xiong@intel.com>/ Liu1, Kai<mailto:kai.liu1@intel.com>,
>
> Hope you are doing well.
>
> I am writing to check if there is any update on the pending DPDK issue raised in this mail.
> Could you please share the latest status, or let me know if any additional inputs are required from my side to help move this forward?
>
> Looking forward to your response.
>
> Thanks & Regards,
>
> Reema Sharma
>
> ________________________________
>
> From: Reema Sharma
> Sent: Wednesday, February 11, 2026 11:27 AM
> To: Xiong, Tanghong <tanghong.xiong@intel.com<mailto:tanghong.xiong@intel.com>>; Liu1, Kai <kai.liu1@intel.com<mailto:kai.liu1@intel.com>>
> Cc: Prakash Durgapal <Prakash.Durgapal@radisys.com<mailto:Prakash.Durgapal@radisys.com>>; Pratap Rana <Pratap.Rana@radisys.com<mailto:Pratap.Rana@radisys.com>>; Vijay Kumar Mahto <Vijay.Mahto@radisys.com<mailto:Vijay.Mahto@radisys.com>>; Jaydipkumar Dhameliya <Jaydipkumar.Dhameliya@radisys.com<mailto:Jaydipkumar.Dhameliya@radisys.com>>
> Subject: Request for Review of Fixes Applied for DPDK 24.11 and 25.11 Compilation Errors
>
>
>
> Hi Xiong, Tanghong<mailto:tanghong.xiong@intel.com>/ Liu1, Kai<mailto:kai.liu1@intel.com>,
>
> While compiling the CU with DPDK 24.11 and DPDK 25.11, we encountered the following two errors:
>
> 1. Conflicting type definitions in the DPDK header file rte_bitops.h
>
> [cid:image001.png@01DCAD92.9C6111F0]
>
> 1. “template with C linkage” error in the DPDK header file rte_cryptodev.h
>
> To proceed with our CU compilation, we applied the required fixes in the respective DPDK include files and generated a patch named dpdk-24.11_patch_for_crypto.patch. The updated changes are included in the attached patch file for your review.
>
> Could you please review these changes from the DPDK side and confirm whether they are acceptable, or advise on the correct fix if modifications are required?
>
> Thanks & Regards,
> Reema Sharma
>
[-- Attachment #2: Type: text/html, Size: 22073 bytes --]
^ permalink raw reply
* [PATCH v2 5/5] net/iavf: fix duplicate MAC addresses install
From: David Marchand @ 2026-05-06 12:35 UTC (permalink / raw)
To: dev; +Cc: stable, Vladimir Medvedkin, Bruce Richardson
In-Reply-To: <20260506123554.2524136-1-david.marchand@redhat.com>
On port restart, all MAC addresses get pushed *twice* to the hardware,
once by the driver and once by the eth_dev_mac_restore() in ethdev.
On the other hand, MAC address filters are reset in the hardware
by the PF only when a VF reset is triggered.
Strictly speaking, the mac restore on port (re)start is unneeded,
if no VF reset happened, so we can announce to ethdev that no mac
restoration is needed via a get_restore_flags callback.
Then, move the mac restoration to the VF reset handler.
Fixes: 3d42086def30 ("net/iavf: preserve MAC address with i40e PF Linux driver")
Cc: stable@dpdk.org
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/net/intel/iavf/iavf_ethdev.c | 31 ++++++++++++++++++++--------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/drivers/net/intel/iavf/iavf_ethdev.c b/drivers/net/intel/iavf/iavf_ethdev.c
index c69a012d50..5871ed3539 100644
--- a/drivers/net/intel/iavf/iavf_ethdev.c
+++ b/drivers/net/intel/iavf/iavf_ethdev.c
@@ -126,6 +126,8 @@ static void iavf_dev_del_mac_addr(struct rte_eth_dev *dev, uint32_t index);
static int iavf_dev_vlan_filter_set(struct rte_eth_dev *dev,
uint16_t vlan_id, int on);
static int iavf_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
+static uint64_t iavf_get_restore_flags(struct rte_eth_dev *dev,
+ enum rte_eth_dev_operation op);
static int iavf_dev_rss_reta_update(struct rte_eth_dev *dev,
struct rte_eth_rss_reta_entry64 *reta_conf,
uint16_t reta_size);
@@ -249,6 +251,7 @@ static const struct eth_dev_ops iavf_eth_dev_ops = {
.tx_done_cleanup = iavf_dev_tx_done_cleanup,
.get_monitor_addr = iavf_get_monitor_addr,
.tm_ops_get = iavf_tm_ops_get,
+ .get_restore_flags = iavf_get_restore_flags,
};
static int
@@ -269,6 +272,13 @@ iavf_tm_ops_get(struct rte_eth_dev *dev,
return 0;
}
+static uint64_t
+iavf_get_restore_flags(__rte_unused struct rte_eth_dev *dev,
+ __rte_unused enum rte_eth_dev_operation op)
+{
+ return RTE_ETH_RESTORE_ALL & ~RTE_ETH_RESTORE_MAC_ADDR;
+}
+
__rte_unused
static int
iavf_vfr_inprogress(struct iavf_hw *hw)
@@ -1039,15 +1049,14 @@ iavf_dev_start(struct rte_eth_dev *dev)
rte_intr_enable(intr_handle);
}
- /* Set all mac addrs */
- iavf_add_del_all_mac_addr(adapter, true);
-
- if (!adapter->mac_primary_set)
- adapter->mac_primary_set = true;
-
- /* Set all multicast addresses */
- iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num,
- true);
+ if (!adapter->mac_primary_set) {
+ if (iavf_add_del_eth_addr(adapter, &dev->data->mac_addrs[0], true,
+ VIRTCHNL_ETHER_ADDR_PRIMARY) != 0)
+ PMD_DRV_LOG(ERR, "failed to add primary MAC:" RTE_ETHER_ADDR_PRT_FMT,
+ RTE_ETHER_ADDR_BYTES(&dev->data->mac_addrs[0]));
+ else
+ adapter->mac_primary_set = true;
+ }
rte_spinlock_init(&vf->phc_time_aq_lock);
@@ -3144,6 +3153,10 @@ iavf_handle_hw_reset(struct rte_eth_dev *dev, bool vf_initiated_reset)
if (ret)
goto error;
+ /* after a VF reset, all mac addresses got flushed, restore them */
+ iavf_add_del_all_mac_addr(adapter, true);
+ iavf_add_del_mc_addr_list(adapter, vf->mc_addrs, vf->mc_addrs_num, true);
+
dev->data->dev_started = 1;
}
goto exit;
--
2.53.0
^ permalink raw reply related
* [PATCH v2 4/5] net/iavf: accept up to 32k unicast MAC addresses
From: David Marchand @ 2026-05-06 12:35 UTC (permalink / raw)
To: dev; +Cc: Vladimir Medvedkin
In-Reply-To: <20260506123554.2524136-1-david.marchand@redhat.com>
E810 hardware provides 32k switch lookups.
Thanks to this, it is possible to allow a lot more secondary mac
addresses than what is possible today.
In practice, the maximum number of macs available per port may be lower
and depends on usage by other (trusted?) VFs on the same PF.
There is no way to figure out this limit but to try adding a mac address
and get an error from the PF driver.
Mailbox exchanges are limited to IAVF_AQ_BUF_SZ, segment messages
accordingly.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v1:
- fixed buffer overflow on mailbox messages during port restart/VF reset,
---
drivers/net/intel/iavf/iavf.h | 5 +-
drivers/net/intel/iavf/iavf_ethdev.c | 10 +--
drivers/net/intel/iavf/iavf_vchnl.c | 117 +++++++++++++++++++--------
3 files changed, 93 insertions(+), 39 deletions(-)
diff --git a/drivers/net/intel/iavf/iavf.h b/drivers/net/intel/iavf/iavf.h
index 403c61e2e8..f1dede0694 100644
--- a/drivers/net/intel/iavf/iavf.h
+++ b/drivers/net/intel/iavf/iavf.h
@@ -31,7 +31,8 @@
#define IAVF_IRQ_MAP_NUM_PER_BUF 128
#define IAVF_RXTX_QUEUE_CHUNKS_NUM 2
-#define IAVF_NUM_MACADDR_MAX 64
+#define IAVF_UC_MACADDR_MAX 32768
+#define IAVF_MC_MACADDR_MAX 64
#define IAVF_DEV_WATCHDOG_PERIOD 2000 /* microseconds, set 0 to disable*/
@@ -253,7 +254,7 @@ struct iavf_info {
uint32_t link_speed;
/* Multicast addrs */
- struct rte_ether_addr mc_addrs[IAVF_NUM_MACADDR_MAX];
+ struct rte_ether_addr mc_addrs[IAVF_MC_MACADDR_MAX];
uint16_t mc_addrs_num; /* Multicast mac addresses number */
struct iavf_vsi vsi;
diff --git a/drivers/net/intel/iavf/iavf_ethdev.c b/drivers/net/intel/iavf/iavf_ethdev.c
index 1eca20bc9a..c69a012d50 100644
--- a/drivers/net/intel/iavf/iavf_ethdev.c
+++ b/drivers/net/intel/iavf/iavf_ethdev.c
@@ -379,10 +379,10 @@ iavf_set_mc_addr_list(struct rte_eth_dev *dev,
IAVF_DEV_PRIVATE_TO_ADAPTER(dev->data->dev_private);
int err, ret;
- if (mc_addrs_num > IAVF_NUM_MACADDR_MAX) {
+ if (mc_addrs_num > IAVF_MC_MACADDR_MAX) {
PMD_DRV_LOG(ERR,
"can't add more than a limited number (%u) of addresses.",
- (uint32_t)IAVF_NUM_MACADDR_MAX);
+ (uint32_t)IAVF_MC_MACADDR_MAX);
return -EINVAL;
}
@@ -1120,7 +1120,7 @@ iavf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->hash_key_size = vf->vf_res->rss_key_size;
dev_info->reta_size = vf->vf_res->rss_lut_size;
dev_info->flow_type_rss_offloads = IAVF_RSS_OFFLOAD_ALL;
- dev_info->max_mac_addrs = IAVF_NUM_MACADDR_MAX;
+ dev_info->max_mac_addrs = IAVF_UC_MACADDR_MAX;
dev_info->dev_capa =
RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
@@ -2822,11 +2822,11 @@ iavf_dev_init(struct rte_eth_dev *eth_dev)
/* copy mac addr */
eth_dev->data->mac_addrs = rte_zmalloc(
- "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX, 0);
+ "iavf_mac", RTE_ETHER_ADDR_LEN * IAVF_UC_MACADDR_MAX, 0);
if (!eth_dev->data->mac_addrs) {
PMD_INIT_LOG(ERR, "Failed to allocate %d bytes needed to"
" store MAC addresses",
- RTE_ETHER_ADDR_LEN * IAVF_NUM_MACADDR_MAX);
+ RTE_ETHER_ADDR_LEN * IAVF_UC_MACADDR_MAX);
ret = -ENOMEM;
goto init_vf_err;
}
diff --git a/drivers/net/intel/iavf/iavf_vchnl.c b/drivers/net/intel/iavf/iavf_vchnl.c
index 08dd6f2d7f..144968db35 100644
--- a/drivers/net/intel/iavf/iavf_vchnl.c
+++ b/drivers/net/intel/iavf/iavf_vchnl.c
@@ -1437,48 +1437,101 @@ iavf_config_irq_map_lv(struct iavf_adapter *adapter, uint16_t num)
return 0;
}
-void
-iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
+static int
+iavf_add_del_uc_addr_bulk(struct iavf_adapter *adapter, struct rte_ether_addr *addrs,
+ uint32_t nb_addrs, bool add)
{
+#define IAVF_ETH_ADDR_PER_REQ \
+ ((IAVF_AQ_BUF_SZ - sizeof(struct virtchnl_ether_addr_list)) / \
+ sizeof(struct virtchnl_ether_addr))
struct {
struct virtchnl_ether_addr_list list;
- struct virtchnl_ether_addr addr[IAVF_NUM_MACADDR_MAX];
- } list_req = {0};
- struct virtchnl_ether_addr_list *list = &list_req.list;
+ struct virtchnl_ether_addr addr[IAVF_ETH_ADDR_PER_REQ];
+ } cmd_buffer;
+#undef IAVF_ETH_ADDR_PER_REQ
+ struct virtchnl_ether_addr_list *list = &cmd_buffer.list;
struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
- struct iavf_cmd_info args = {0};
- int err, i;
- size_t buf_len;
- for (i = 0; i < IAVF_NUM_MACADDR_MAX; i++) {
- struct rte_ether_addr *addr = &adapter->dev_data->mac_addrs[i];
- struct virtchnl_ether_addr *vc_addr = &list->list[list->num_elements];
+ for (uint32_t i = 0; i < nb_addrs; i++) {
+ size_t buf_len = sizeof(struct virtchnl_ether_addr_list) +
+ sizeof(struct virtchnl_ether_addr) * list->num_elements;
+ struct iavf_cmd_info args;
+ uint32_t batch;
+ int err;
- /* ignore empty addresses */
- if (rte_is_zero_ether_addr(addr))
- continue;
+ batch = i % RTE_DIM(cmd_buffer.addr);
+
+ if (batch == 0) {
+ memset(&cmd_buffer, 0, sizeof(cmd_buffer));
+ list->vsi_id = vf->vsi_res->vsi_id;
+ list->num_elements = 0;
+ }
+
+ rte_memcpy(list->list[batch].addr, addrs[i].addr_bytes,
+ sizeof(list->list[batch].addr));
+ list->list[batch].type = VIRTCHNL_ETHER_ADDR_EXTRA;
list->num_elements++;
- memcpy(vc_addr->addr, addr->addr_bytes, sizeof(addr->addr_bytes));
- vc_addr->type = (list->num_elements == 1) ?
- VIRTCHNL_ETHER_ADDR_PRIMARY :
- VIRTCHNL_ETHER_ADDR_EXTRA;
+ if (batch != RTE_DIM(cmd_buffer.addr) - 1 && i != nb_addrs - 1)
+ continue;
+
+ buf_len = sizeof(struct virtchnl_ether_addr_list) +
+ sizeof(struct virtchnl_ether_addr) * list->num_elements;
+
+ memset(&args, 0, sizeof(args));
+ args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
+ args.in_args = (uint8_t *)list;
+ args.in_args_size = buf_len;
+ args.out_buffer = vf->aq_resp;
+ args.out_size = IAVF_AQ_BUF_SZ;
+ err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
+ if (err != 0) {
+ PMD_DRV_LOG(ERR, "fail to execute command %s for %u macs",
+ add ? "VIRTCHNL_OP_ADD_ETH_ADDR" : "VIRTCHNL_OP_DEL_ETH_ADDR",
+ list->num_elements);
+ return err;
+ }
+
+ PMD_DRV_LOG(DEBUG, "executed command %s for %u macs",
+ add ? "VIRTCHNL_OP_ADD_ETH_ADDR" : "VIRTCHNL_OP_DEL_ETH_ADDR",
+ list->num_elements);
}
- /* for some reason PF side checks for buffer being too big, so adjust it down */
- buf_len = sizeof(struct virtchnl_ether_addr_list) +
- sizeof(struct virtchnl_ether_addr) * list->num_elements;
+ return 0;
+}
- list->vsi_id = vf->vsi_res->vsi_id;
- args.ops = add ? VIRTCHNL_OP_ADD_ETH_ADDR : VIRTCHNL_OP_DEL_ETH_ADDR;
- args.in_args = (uint8_t *)list;
- args.in_args_size = buf_len;
- args.out_buffer = vf->aq_resp;
- args.out_size = IAVF_AQ_BUF_SZ;
- err = iavf_execute_vf_cmd_safe(adapter, &args, 0);
- if (err)
- PMD_DRV_LOG(ERR, "fail to execute command %s",
- add ? "OP_ADD_ETHER_ADDRESS" : "OP_DEL_ETHER_ADDRESS");
+void
+iavf_add_del_all_mac_addr(struct iavf_adapter *adapter, bool add)
+{
+ int start = -1;
+ int i;
+
+ /* Handle primary address (index 0) separately */
+ if (!rte_is_zero_ether_addr(&adapter->dev_data->mac_addrs[0]))
+ iavf_add_del_eth_addr(adapter, &adapter->dev_data->mac_addrs[0], add,
+ VIRTCHNL_ETHER_ADDR_PRIMARY);
+
+ /* Process secondary addresses in contiguous blocks */
+ for (i = 1; i < IAVF_UC_MACADDR_MAX; i++) {
+ struct rte_ether_addr *addr = &adapter->dev_data->mac_addrs[i];
+
+ if (!rte_is_zero_ether_addr(addr)) {
+ if (start == -1)
+ start = i;
+ continue;
+ }
+
+ if (start != -1) {
+ iavf_add_del_uc_addr_bulk(adapter, &adapter->dev_data->mac_addrs[start],
+ i - start, add);
+ start = -1;
+ }
+ }
+
+ if (start != -1) {
+ iavf_add_del_uc_addr_bulk(adapter, &adapter->dev_data->mac_addrs[start],
+ i - start, add);
+ }
}
int
@@ -2060,7 +2113,7 @@ iavf_add_del_mc_addr_list(struct iavf_adapter *adapter,
{
struct iavf_info *vf = IAVF_DEV_PRIVATE_TO_VF(adapter);
uint8_t cmd_buffer[sizeof(struct virtchnl_ether_addr_list) +
- (IAVF_NUM_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
+ (IAVF_MC_MACADDR_MAX * sizeof(struct virtchnl_ether_addr))];
struct virtchnl_ether_addr_list *list;
struct iavf_cmd_info args;
uint32_t i;
--
2.53.0
^ permalink raw reply related
* [PATCH v2 3/5] ethdev: hide VMDq internal sizes
From: David Marchand @ 2026-05-06 12:35 UTC (permalink / raw)
To: dev; +Cc: Thomas Monjalon, Andrew Rybchenko
In-Reply-To: <20260506123554.2524136-1-david.marchand@redhat.com>
Hide RTE_ETH_NUM_RECEIVE_MAC_ADDR and RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY
in the driver API as those (ambiguous) macros are only a driver concern.
In practice, this is only used by the bnxt and ixgbe (+ clones) drivers.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
lib/ethdev/ethdev_driver.h | 8 +++++++-
lib/ethdev/rte_ethdev.h | 6 ------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/lib/ethdev/ethdev_driver.h b/lib/ethdev/ethdev_driver.h
index 1255cd6f2c..a4e9cf5b90 100644
--- a/lib/ethdev/ethdev_driver.h
+++ b/lib/ethdev/ethdev_driver.h
@@ -119,6 +119,12 @@ struct __rte_cache_aligned rte_eth_dev {
struct rte_eth_dev_sriov;
struct rte_eth_dev_owner;
+/* Definitions used for receive MAC address */
+#define RTE_ETH_NUM_RECEIVE_MAC_ADDR 128 /**< Maximum nb. of receive mac addr. */
+
+/* Definitions used for unicast hash */
+#define RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY 128 /**< Maximum nb. of UC hash array. */
+
/**
* @internal
* The data part, with no function pointers, associated with each Ethernet
@@ -153,7 +159,7 @@ struct __rte_cache_aligned rte_eth_dev_data {
* The first entry (index zero) is the default address.
*/
struct rte_ether_addr *mac_addrs;
- /** Bitmap associating MAC addresses to pools */
+ /** Bitmap associating MAC addresses to VMDq pools */
uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR];
/**
* Device Ethernet MAC addresses of hash filtering.
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 62c72de0e5..6c1984e679 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -903,12 +903,6 @@ rte_eth_rss_hf_refine(uint64_t rss_hf)
#define RTE_ETH_VLAN_ID_MAX 0x0FFF /**< VLAN ID is in lower 12 bits*/
/**@}*/
-/* Definitions used for receive MAC address */
-#define RTE_ETH_NUM_RECEIVE_MAC_ADDR 128 /**< Maximum nb. of receive mac addr. */
-
-/* Definitions used for unicast hash */
-#define RTE_ETH_VMDQ_NUM_UC_HASH_ARRAY 128 /**< Maximum nb. of UC hash array. */
-
/**@{@name VMDq Rx mode
* @see rte_eth_vmdq_rx_conf.rx_mode
*/
--
2.53.0
^ permalink raw reply related
* [PATCH v2 2/5] ethdev: announce VMDq capability
From: David Marchand @ 2026-05-06 12:35 UTC (permalink / raw)
To: dev
Cc: Kishore Padmanabha, Ajit Khaparde, Bruce Richardson,
Anatoly Burakov, Vladimir Medvedkin, Jiawen Wu, Zaiyu Wang,
Thomas Monjalon, Andrew Rybchenko
In-Reply-To: <20260506123554.2524136-1-david.marchand@redhat.com>
Let's mark VMDq feature availability as a per device capability.
We can then enforce API calls related to this feature are done on device
with such capability.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
Changes since v1:
- dropped incorrect VMDq feature announce for bnxt representors, em,
i40e representors, ipn3ke representors,
---
drivers/net/bnxt/bnxt_ethdev.c | 3 ++-
drivers/net/intel/e1000/igb_ethdev.c | 1 +
drivers/net/intel/fm10k/fm10k_ethdev.c | 1 +
drivers/net/intel/i40e/i40e_ethdev.c | 3 ++-
drivers/net/intel/ixgbe/ixgbe_ethdev.c | 2 ++
drivers/net/txgbe/txgbe_ethdev.c | 1 +
drivers/net/txgbe/txgbe_ethdev_vf.c | 1 +
lib/ethdev/rte_ethdev.c | 17 +++++++++++++++++
lib/ethdev/rte_ethdev.h | 2 ++
9 files changed, 29 insertions(+), 2 deletions(-)
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index b677f9491d..0f783b9e98 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -1214,7 +1214,8 @@ static int bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
dev_info->speed_capa = bnxt_get_speed_capabilities(bp);
dev_info->dev_capa = RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
- RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
+ RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP |
+ RTE_ETH_DEV_CAPA_VMDQ;
dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
dev_info->default_rxconf = (struct rte_eth_rxconf) {
diff --git a/drivers/net/intel/e1000/igb_ethdev.c b/drivers/net/intel/e1000/igb_ethdev.c
index ef1599ac38..fe68c18417 100644
--- a/drivers/net/intel/e1000/igb_ethdev.c
+++ b/drivers/net/intel/e1000/igb_ethdev.c
@@ -2324,6 +2324,7 @@ eth_igb_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->tx_queue_offload_capa = igb_get_tx_queue_offloads_capa(dev);
dev_info->tx_offload_capa = igb_get_tx_port_offloads_capa(dev) |
dev_info->tx_queue_offload_capa;
+ dev_info->dev_capa = RTE_ETH_DEV_CAPA_VMDQ;
dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
switch (hw->mac.type) {
diff --git a/drivers/net/intel/fm10k/fm10k_ethdev.c b/drivers/net/intel/fm10k/fm10k_ethdev.c
index 97f61afec2..037d2206fd 100644
--- a/drivers/net/intel/fm10k/fm10k_ethdev.c
+++ b/drivers/net/intel/fm10k/fm10k_ethdev.c
@@ -1444,6 +1444,7 @@ fm10k_dev_infos_get(struct rte_eth_dev *dev,
dev_info->speed_capa = RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_2_5G |
RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_25G |
RTE_ETH_LINK_SPEED_40G | RTE_ETH_LINK_SPEED_100G;
+ dev_info->dev_capa = RTE_ETH_DEV_CAPA_VMDQ;
return 0;
}
diff --git a/drivers/net/intel/i40e/i40e_ethdev.c b/drivers/net/intel/i40e/i40e_ethdev.c
index 100a751225..64c29c6e85 100644
--- a/drivers/net/intel/i40e/i40e_ethdev.c
+++ b/drivers/net/intel/i40e/i40e_ethdev.c
@@ -3878,7 +3878,8 @@ i40e_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->dev_capa =
RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP |
- RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP;
+ RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP |
+ RTE_ETH_DEV_CAPA_VMDQ;
dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
dev_info->hash_key_size = (I40E_PFQF_HKEY_MAX_INDEX + 1) *
diff --git a/drivers/net/intel/ixgbe/ixgbe_ethdev.c b/drivers/net/intel/ixgbe/ixgbe_ethdev.c
index 57d929cf2c..5d886b3e28 100644
--- a/drivers/net/intel/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/intel/ixgbe/ixgbe_ethdev.c
@@ -3997,6 +3997,7 @@ ixgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->max_mtu = dev_info->max_rx_pktlen - IXGBE_ETH_OVERHEAD;
dev_info->min_mtu = RTE_ETHER_MIN_MTU;
dev_info->vmdq_queue_num = dev_info->max_rx_queues;
+ dev_info->dev_capa = RTE_ETH_DEV_CAPA_VMDQ;
dev_info->rx_queue_offload_capa = ixgbe_get_rx_queue_offloads(dev);
dev_info->rx_offload_capa = (ixgbe_get_rx_port_offloads(dev) |
dev_info->rx_queue_offload_capa);
@@ -4115,6 +4116,7 @@ ixgbevf_dev_info_get(struct rte_eth_dev *dev,
dev_info->max_vmdq_pools = RTE_ETH_16_POOLS;
else
dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
+ dev_info->dev_capa = RTE_ETH_DEV_CAPA_VMDQ;
dev_info->rx_queue_offload_capa = ixgbe_get_rx_queue_offloads(dev);
dev_info->rx_offload_capa = (ixgbe_get_rx_port_offloads(dev) |
dev_info->rx_queue_offload_capa);
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index 5d360f8305..bd818e8269 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -2836,6 +2836,7 @@ txgbe_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
dev_info->max_vfs = pci_dev->max_vfs;
dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
dev_info->vmdq_queue_num = dev_info->max_rx_queues;
+ dev_info->dev_capa = RTE_ETH_DEV_CAPA_VMDQ;
dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index 39a5fff65c..934763574c 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -572,6 +572,7 @@ txgbevf_dev_info_get(struct rte_eth_dev *dev,
dev_info->max_hash_mac_addrs = TXGBE_VMDQ_NUM_UC_MAC;
dev_info->max_vfs = pci_dev->max_vfs;
dev_info->max_vmdq_pools = RTE_ETH_64_POOLS;
+ dev_info->dev_capa = RTE_ETH_DEV_CAPA_VMDQ;
dev_info->dev_capa &= ~RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP;
dev_info->rx_queue_offload_capa = txgbe_get_rx_queue_offloads(dev);
dev_info->rx_offload_capa = (txgbe_get_rx_port_offloads(dev) |
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 9577b7d848..7ba539e796 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -158,6 +158,7 @@ static const struct {
{RTE_ETH_DEV_CAPA_RXQ_SHARE, "RXQ_SHARE"},
{RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP, "FLOW_RULE_KEEP"},
{RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP, "FLOW_SHARED_OBJECT_KEEP"},
+ {RTE_ETH_DEV_CAPA_VMDQ, "VMDQ"},
};
enum {
@@ -1581,6 +1582,22 @@ rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
goto rollback;
}
+ if (!(dev_info.dev_capa & RTE_ETH_DEV_CAPA_VMDQ)) {
+ if ((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0) {
+ RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support VMDq rx mode",
+ port_id);
+ ret = -EINVAL;
+ goto rollback;
+ }
+ if (dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_DCB ||
+ dev_conf->txmode.mq_mode == RTE_ETH_MQ_TX_VMDQ_ONLY) {
+ RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support VMDq tx mode",
+ port_id);
+ ret = -EINVAL;
+ goto rollback;
+ }
+ }
+
/*
* Setup new number of Rx/Tx queues and reconfigure device.
*/
diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h
index 0d8e2d0236..62c72de0e5 100644
--- a/lib/ethdev/rte_ethdev.h
+++ b/lib/ethdev/rte_ethdev.h
@@ -1696,6 +1696,8 @@ struct rte_eth_conf {
#define RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP RTE_BIT64(3)
/** Device supports keeping shared flow objects across restart. */
#define RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP RTE_BIT64(4)
+/** Device supports VMDq. */
+#define RTE_ETH_DEV_CAPA_VMDQ RTE_BIT64(5)
/**@}*/
/*
--
2.53.0
^ permalink raw reply related
* [PATCH v2 1/5] ethdev: skip VMDq pools unless configured
From: David Marchand @ 2026-05-06 12:35 UTC (permalink / raw)
To: dev
Cc: Nithin Dabilpuram, Kiran Kumar K, Sunil Kumar Kori, Satha Rao,
Harman Kalra, Thomas Monjalon, Andrew Rybchenko
In-Reply-To: <20260506123554.2524136-1-david.marchand@redhat.com>
The mac_addr_add API describes that only the 0 pool should be passed
unless VMDq has been enabled, though there was no validation so far.
Add such a check, then cleanup the related operations (adding, removing,
restoring).
As a side effect, the net/cnxk does not need to manually reset the
mac_pool_sel[] array.
Signed-off-by: David Marchand <david.marchand@redhat.com>
---
drivers/net/cnxk/cnxk_ethdev_ops.c | 1 -
lib/ethdev/rte_ethdev.c | 28 +++++++++++++++++++++-------
2 files changed, 21 insertions(+), 8 deletions(-)
diff --git a/drivers/net/cnxk/cnxk_ethdev_ops.c b/drivers/net/cnxk/cnxk_ethdev_ops.c
index 49e77e49a6..75decf7098 100644
--- a/drivers/net/cnxk/cnxk_ethdev_ops.c
+++ b/drivers/net/cnxk/cnxk_ethdev_ops.c
@@ -1240,7 +1240,6 @@ cnxk_nix_mc_addr_list_configure(struct rte_eth_dev *eth_dev, struct rte_ether_ad
/* Update address in NIC data structure */
rte_ether_addr_copy(&mc_addr_set[i], &data->mac_addrs[j]);
rte_ether_addr_copy(&mc_addr_set[i], &dev->dmac_addrs[j]);
- data->mac_pool_sel[j] = RTE_BIT64(0);
}
roc_nix_npc_promisc_ena_dis(nix, true);
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 2edc7a362e..9577b7d848 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -1680,7 +1680,10 @@ eth_dev_mac_restore(struct rte_eth_dev *dev,
continue;
pool = 0;
- pool_mask = dev->data->mac_pool_sel[i];
+ if ((dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0)
+ pool_mask = dev->data->mac_pool_sel[i];
+ else
+ pool_mask = 1;
do {
if (pool_mask & UINT64_C(1))
@@ -5390,8 +5393,9 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
uint32_t pool)
{
struct rte_eth_dev *dev;
- int index;
uint64_t pool_mask;
+ bool vmdq;
+ int index;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
@@ -5416,6 +5420,12 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
RTE_ETHDEV_LOG_LINE(ERR, "Pool ID must be 0-%d", RTE_ETH_64_POOLS - 1);
return -EINVAL;
}
+ vmdq = (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0;
+ if (!vmdq && pool != 0) {
+ RTE_ETHDEV_LOG_LINE(ERR, "Port %u: VMDq is not configured (pool %d)",
+ port_id, pool);
+ return -EINVAL;
+ }
index = eth_dev_get_mac_addr_index(port_id, addr);
if (index < 0) {
@@ -5425,7 +5435,7 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
port_id);
return -ENOSPC;
}
- } else {
+ } else if (vmdq) {
pool_mask = dev->data->mac_pool_sel[index];
/* Check if both MAC address and pool is already there, and do nothing */
@@ -5440,8 +5450,10 @@ rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
/* Update address in NIC data structure */
rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
- /* Update pool bitmap in NIC data structure */
- dev->data->mac_pool_sel[index] |= RTE_BIT64(pool);
+ if (vmdq) {
+ /* Update pool bitmap in NIC data structure */
+ dev->data->mac_pool_sel[index] |= RTE_BIT64(pool);
+ }
}
ret = eth_err(port_id, ret);
@@ -5486,8 +5498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
/* Update address in NIC data structure */
rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
- /* reset pool bitmap */
- dev->data->mac_pool_sel[index] = 0;
+ if ((dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_VMDQ_FLAG) != 0) {
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0;
+ }
rte_ethdev_trace_mac_addr_remove(port_id, addr);
--
2.53.0
^ permalink raw reply related
* [PATCH v2 0/5] Remove limitations coming from legacy VMDq
From: David Marchand @ 2026-05-06 12:35 UTC (permalink / raw)
To: dev
In-Reply-To: <20260403091836.1073484-1-david.marchand@redhat.com>
Since the commit 88ac4396ad29 ("ethdev: add VMDq support"),
VMDq has been imposing a maximum number of mac addresses in the
mac_addr_add/del API.
Nowadays, new Intel drivers do not support the feature and few other
drivers implement this feature.
This series proposes to flag drivers that support the feature, and
remove the limit of number of mac addresses for others.
Next step could be to remove the VMDq pool notion from the generic API.
However I have some concern about this, as changing the quite stable
mac_addr_add/del API now seems a lot of noise for not much benefit.
--
David Marchand
Changes since v1:
- dropped incorrect VMDq feature announce for bnxt representors, em,
i40e representors, ipn3ke representors,
- fixed buffer overflow on mailbox messages during port restart/VF reset,
- fixed duplicate MAC address installation on port start/restart,
David Marchand (5):
ethdev: skip VMDq pools unless configured
ethdev: announce VMDq capability
ethdev: hide VMDq internal sizes
net/iavf: accept up to 32k unicast MAC addresses
net/iavf: fix duplicate MAC addresses install
drivers/net/bnxt/bnxt_ethdev.c | 3 +-
drivers/net/cnxk/cnxk_ethdev_ops.c | 1 -
drivers/net/intel/e1000/igb_ethdev.c | 1 +
drivers/net/intel/fm10k/fm10k_ethdev.c | 1 +
drivers/net/intel/i40e/i40e_ethdev.c | 3 +-
drivers/net/intel/iavf/iavf.h | 5 +-
drivers/net/intel/iavf/iavf_ethdev.c | 41 ++++++---
drivers/net/intel/iavf/iavf_vchnl.c | 117 ++++++++++++++++++-------
drivers/net/intel/ixgbe/ixgbe_ethdev.c | 2 +
drivers/net/txgbe/txgbe_ethdev.c | 1 +
drivers/net/txgbe/txgbe_ethdev_vf.c | 1 +
lib/ethdev/ethdev_driver.h | 8 +-
lib/ethdev/rte_ethdev.c | 45 ++++++++--
lib/ethdev/rte_ethdev.h | 8 +-
14 files changed, 172 insertions(+), 65 deletions(-)
--
2.53.0
^ permalink raw reply
* [PATCH v10 09/10] drivers: add data path for Rx and Tx
From: liujie5 @ 2026-05-06 11:35 UTC (permalink / raw)
To: stephen; +Cc: dev, Jie Liu
In-Reply-To: <20260506113557.1151250-1-liujie5@linkdatatechnology.com>
From: Jie Liu <liujie5@linkdatatechnology.com>
Implement receive and transmit burst functions for sxe2 PMD.
Add sxe2_recv_pkts and sxe2_xmit_pkts as the primary data path
interfaces.
The implementation includes:
- Efficient descriptor fetching and mbuf allocation for Rx.
- Descriptor setup and checksum offload handling for Tx.
- Buffer recycling and hardware tail pointer updates.
- Performance-oriented loop unrolling and prefetching where applicable.
Signed-off-by: Jie Liu <liujie5@linkdatatechnology.com>
---
drivers/common/sxe2/sxe2_common.c | 13 +-
drivers/common/sxe2/sxe2_common_log.h | 105 ----
drivers/common/sxe2/sxe2_errno.h | 3 -
drivers/common/sxe2/sxe2_ioctl_chnl.c | 20 +-
drivers/common/sxe2/sxe2_osal.h | 4 +-
drivers/common/sxe2/sxe2_type.h | 1 -
drivers/net/sxe2/meson.build | 2 +
drivers/net/sxe2/sxe2_ethdev.c | 15 +-
drivers/net/sxe2/sxe2_txrx.c | 249 ++++++++
drivers/net/sxe2/sxe2_txrx.h | 21 +
drivers/net/sxe2/sxe2_txrx_poll.c | 782 ++++++++++++++++++++++++++
11 files changed, 1082 insertions(+), 133 deletions(-)
create mode 100644 drivers/net/sxe2/sxe2_txrx.c
create mode 100644 drivers/net/sxe2/sxe2_txrx.h
create mode 100644 drivers/net/sxe2/sxe2_txrx_poll.c
diff --git a/drivers/common/sxe2/sxe2_common.c b/drivers/common/sxe2/sxe2_common.c
index 537d4e9f6a..d2ed1460a3 100644
--- a/drivers/common/sxe2/sxe2_common.c
+++ b/drivers/common/sxe2/sxe2_common.c
@@ -28,7 +28,7 @@ static TAILQ_HEAD(sxe2_class_drivers, sxe2_class_driver) sxe2_class_drivers_list
static TAILQ_HEAD(sxe2_common_devices, sxe2_common_device) sxe2_common_devices_list =
TAILQ_HEAD_INITIALIZER(sxe2_common_devices_list);
-static pthread_mutex_t sxe2_common_devices_list_lock;
+static rte_spinlock_t sxe2_common_devices_list_lock;
static struct rte_pci_id *sxe2_common_pci_id_table;
@@ -223,9 +223,9 @@ static struct sxe2_common_device *sxe2_common_device_alloc(
cdev->config.kernel_reset = false;
rte_ticketlock_init(&cdev->config.lock);
- (void)pthread_mutex_lock(&sxe2_common_devices_list_lock);
+ rte_spinlock_lock(&sxe2_common_devices_list_lock);
TAILQ_INSERT_TAIL(&sxe2_common_devices_list, cdev, next);
- (void)pthread_mutex_unlock(&sxe2_common_devices_list_lock);
+ rte_spinlock_unlock(&sxe2_common_devices_list_lock);
l_end:
return cdev;
@@ -233,10 +233,9 @@ static struct sxe2_common_device *sxe2_common_device_alloc(
static void sxe2_common_device_free(struct sxe2_common_device *cdev)
{
-
- (void)pthread_mutex_lock(&sxe2_common_devices_list_lock);
+ rte_spinlock_lock(&sxe2_common_devices_list_lock);
TAILQ_REMOVE(&sxe2_common_devices_list, cdev, next);
- (void)pthread_mutex_unlock(&sxe2_common_devices_list_lock);
+ rte_spinlock_unlock(&sxe2_common_devices_list_lock);
rte_free(cdev);
}
@@ -662,7 +661,7 @@ sxe2_common_init(void)
if (sxe2_commoin_inited)
goto l_end;
- pthread_mutex_init(&sxe2_common_devices_list_lock, NULL);
+ rte_spinlock_init(&sxe2_common_devices_list_lock);
#ifdef SXE2_DPDK_DEBUG
sxe2_common_log_stream_init();
#endif
diff --git a/drivers/common/sxe2/sxe2_common_log.h b/drivers/common/sxe2/sxe2_common_log.h
index 8ade49d020..14074fcc4f 100644
--- a/drivers/common/sxe2/sxe2_common_log.h
+++ b/drivers/common/sxe2/sxe2_common_log.h
@@ -260,109 +260,4 @@ sxe2_common_log_stream_init(void);
#define PMD_INIT_FUNC_TRACE() PMD_LOG_DEBUG(INIT, " >>")
-#ifdef SXE2_DPDK_DEBUG
-
-#define LOG_DEBUG(fmt, ...) \
- PMD_LOG_DEBUG(DRV, fmt, ##__VA_ARGS__)
-
-#define LOG_INFO(fmt, ...) \
- PMD_LOG_INFO(DRV, fmt, ##__VA_ARGS__)
-
-#define LOG_WARN(fmt, ...) \
- PMD_LOG_WARN(DRV, fmt, ##__VA_ARGS__)
-
-#define LOG_ERROR(fmt, ...) \
- PMD_LOG_ERR(DRV, fmt, ##__VA_ARGS__)
-
-#define LOG_DEBUG_BDF(dev_name, fmt, ...) \
- PMD_LOG_DEBUG(HW, fmt, ##__VA_ARGS__)
-
-#define LOG_INFO_BDF(dev_name, fmt, ...) \
- PMD_LOG_INFO(HW, fmt, ##__VA_ARGS__)
-
-#define LOG_WARN_BDF(dev_name, fmt, ...) \
- PMD_LOG_WARN(HW, fmt, ##__VA_ARGS__)
-
-#define LOG_ERROR_BDF(dev_name, fmt, ...) \
- PMD_LOG_ERR(HW, fmt, ##__VA_ARGS__)
-
-#else
-#define LOG_DEBUG(fmt, ...)
-#define LOG_INFO(fmt, ...)
-#define LOG_WARN(fmt, ...)
-#define LOG_ERROR(fmt, ...)
-#define LOG_DEBUG_BDF(dev_name, fmt, ...) \
- PMD_LOG_DEBUG(HW, fmt, ##__VA_ARGS__)
-
-#define LOG_INFO_BDF(dev_name, fmt, ...) \
- PMD_LOG_INFO(HW, fmt, ##__VA_ARGS__)
-
-#define LOG_WARN_BDF(dev_name, fmt, ...) \
- PMD_LOG_WARN(HW, fmt, ##__VA_ARGS__)
-
-#define LOG_ERROR_BDF(dev_name, fmt, ...) \
- PMD_LOG_ERR(HW, fmt, ##__VA_ARGS__)
-#endif
-
-#ifdef SXE2_DPDK_DEBUG
-#define LOG_DEV_DEBUG(fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_DEBUG_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define LOG_DEV_INFO(fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_INFO_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define LOG_DEV_WARN(fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_WARN_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define LOG_DEV_ERR(fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_ERROR_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define LOG_MSG_DEBUG(msglvl, fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_DEBUG_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define LOG_MSG_INFO(msglvl, fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_INFO_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define LOG_MSG_WARN(msglvl, fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_WARN_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#define LOG_MSG_ERR(msglvl, fmt, ...) \
- do { \
- RTE_SET_USED(adapter); \
- LOG_ERROR_BDF(fmt, ##__VA_ARGS__); \
- } while (0)
-
-#else
-
-#define LOG_DEV_DEBUG(fmt, ...) RTE_SET_USED(adapter)
-#define LOG_DEV_INFO(fmt, ...) RTE_SET_USED(adapter)
-#define LOG_DEV_WARN(fmt, ...) RTE_SET_USED(adapter)
-#define LOG_DEV_ERR(fmt, ...) RTE_SET_USED(adapter)
-#define LOG_MSG_DEBUG(msglvl, fmt, ...) RTE_SET_USED(adapter)
-#define LOG_MSG_INFO(msglvl, fmt, ...) RTE_SET_USED(adapter)
-#define LOG_MSG_WARN(msglvl, fmt, ...) RTE_SET_USED(adapter)
-#define LOG_MSG_ERR(msglvl, fmt, ...) RTE_SET_USED(adapter)
-#endif
-
#endif /* SXE2_COMMON_LOG_H__ */
diff --git a/drivers/common/sxe2/sxe2_errno.h b/drivers/common/sxe2/sxe2_errno.h
index 89a715eaef..1257319edf 100644
--- a/drivers/common/sxe2/sxe2_errno.h
+++ b/drivers/common/sxe2/sxe2_errno.h
@@ -50,9 +50,6 @@ enum sxe2_status {
SXE2_ERR_NOLCK = -ENOLCK,
SXE2_ERR_NOSYS = -ENOSYS,
SXE2_ERR_NOTEMPTY = -ENOTEMPTY,
- SXE2_ERR_ILSEQ = -EILSEQ,
- SXE2_ERR_NODATA = -ENODATA,
- SXE2_ERR_CANCELED = -ECANCELED,
SXE2_ERR_TIMEDOUT = -ETIMEDOUT,
SXE2_ERROR = -150,
diff --git a/drivers/common/sxe2/sxe2_ioctl_chnl.c b/drivers/common/sxe2/sxe2_ioctl_chnl.c
index 1a14d401e7..cb83fb837d 100644
--- a/drivers/common/sxe2/sxe2_ioctl_chnl.c
+++ b/drivers/common/sxe2/sxe2_ioctl_chnl.c
@@ -37,7 +37,7 @@ sxe2_drv_cmd_exec(struct sxe2_common_device *cdev,
if (cdev->config.kernel_reset) {
ret = SXE2_ERR_PERM;
- PMD_LOG_WARN(COM, "kernel reseted, need restart app.");
+ PMD_LOG_WARN(COM, "kernel reset, need restart app.");
goto l_end;
}
@@ -123,7 +123,7 @@ sxe2_drv_dev_handshark(struct sxe2_common_device *cdev)
if (cdev->config.kernel_reset) {
ret = SXE2_ERR_PERM;
- PMD_LOG_WARN(COM, "kernel reseted, need restart app.");
+ PMD_LOG_WARN(COM, "kernel reset, need restart app.");
goto l_end;
}
@@ -168,7 +168,7 @@ void
void *virt = NULL;
if (cdev->config.kernel_reset) {
- PMD_LOG_WARN(COM, "kernel reseted, need restart app.");
+ PMD_LOG_WARN(COM, "kernel reset, need restart app.");
goto l_err;
}
@@ -178,13 +178,13 @@ void
goto l_err;
}
- PMD_LOG_DEBUG(COM, "fd=%d, bar idx=%d, len=0x%zx, src=0x%"PRIx64", offset=0x%"PRIx64"",
+ PMD_LOG_DEBUG(COM, "fd=%d, bar idx=%d, len=%"PRIu64", src=0x%"PRIx64", offset=0x%"PRIx64"",
bar_idx, cmd_fd, len, offset, SXE2_COM_PCI_OFFSET_GEN(bar_idx, offset));
virt = mmap(NULL, len, PROT_READ | PROT_WRITE,
MAP_SHARED, cmd_fd, SXE2_COM_PCI_OFFSET_GEN(bar_idx, offset));
if (virt == MAP_FAILED) {
- PMD_LOG_ERR(COM, "Failed mmap, cmd_fd=%d, len=0x%zx, offset=0x%"PRIx64", err:%s",
+ PMD_LOG_ERR(COM, "Failed mmap, cmd_fd=%d, len=%"PRIu64", offset=0x%"PRIx64", err:%s",
cmd_fd, len, offset, strerror(errno));
goto l_err;
}
@@ -206,12 +206,12 @@ sxe2_drv_dev_munmap(struct sxe2_common_device *cdev, void *virt, u64 len)
goto l_end;
}
- PMD_LOG_DEBUG(COM, "Munmap virt=%p, len=0x%zx",
+ PMD_LOG_DEBUG(COM, "Munmap virt=%p, len=0x%"PRIx64"",
virt, len);
ret = munmap(virt, len);
if (ret < 0) {
- PMD_LOG_ERR(COM, "Failed to munmap, virt=%p, len=0x%zx, err:%s",
+ PMD_LOG_ERR(COM, "Failed to munmap, virt=%p, len=%"PRIu64", err:%s",
virt, len, strerror(errno));
ret = SXE2_ERR_IO;
goto l_end;
@@ -233,7 +233,7 @@ sxe2_drv_dev_dma_map(struct sxe2_common_device *cdev, u64 vaddr,
if (cdev->config.kernel_reset) {
ret = SXE2_ERR_PERM;
- PMD_LOG_WARN(COM, "kernel reseted, need restart app.");
+ PMD_LOG_WARN(COM, "kernel reset, need restart app.");
goto l_end;
}
@@ -246,7 +246,7 @@ sxe2_drv_dev_dma_map(struct sxe2_common_device *cdev, u64 vaddr,
goto l_end;
} else if (iova_mode == RTE_IOVA_VA) {
if (!cdev->config.support_iommu) {
- PMD_LOG_ERR(COM, "no iommu not support va mode, plese use pa mode.");
+ PMD_LOG_ERR(COM, "no iommu not support va mode, please use pa mode.");
ret = SXE2_ERR_IO;
goto l_end;
}
@@ -289,7 +289,7 @@ sxe2_drv_dev_dma_unmap(struct sxe2_common_device *cdev, u64 iova)
if (cdev->config.kernel_reset) {
ret = SXE2_ERR_PERM;
- PMD_LOG_WARN(COM, "kernel reseted, need restart app.");
+ PMD_LOG_WARN(COM, "kernel reset, need restart app.");
goto l_end;
}
diff --git a/drivers/common/sxe2/sxe2_osal.h b/drivers/common/sxe2/sxe2_osal.h
index fd6823fe98..23882f3f52 100644
--- a/drivers/common/sxe2/sxe2_osal.h
+++ b/drivers/common/sxe2/sxe2_osal.h
@@ -29,8 +29,6 @@
#define BIT_ULL(a) (1ULL << (a))
#endif
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-
#define BITS_PER_BYTE 8
#define IS_UNICAST_ETHER_ADDR(addr) \
@@ -88,7 +86,7 @@
(((n) + (typeof(n))(d) - (typeof(n))1) / (typeof(n))(d))
#endif
-#define usleep_range(min, max) msleep(DIV_ROUND_UP(min, 1000))
+#define usleep_range(min) msleep(DIV_ROUND_UP(min, 1000))
#define __bf_shf(x) ((uint32_t)rte_bsf64(x))
diff --git a/drivers/common/sxe2/sxe2_type.h b/drivers/common/sxe2/sxe2_type.h
index 56d0a11f48..fbf4a6674f 100644
--- a/drivers/common/sxe2/sxe2_type.h
+++ b/drivers/common/sxe2/sxe2_type.h
@@ -8,7 +8,6 @@
#include <sys/time.h>
#include <stdlib.h>
-#include <stdio.h>
#include <errno.h>
#include <stdarg.h>
#include <unistd.h>
diff --git a/drivers/net/sxe2/meson.build b/drivers/net/sxe2/meson.build
index 61467a4e31..b331451160 100644
--- a/drivers/net/sxe2/meson.build
+++ b/drivers/net/sxe2/meson.build
@@ -25,6 +25,8 @@ sources += files(
'sxe2_queue.c',
'sxe2_tx.c',
'sxe2_rx.c',
+ 'sxe2_txrx_poll.c',
+ 'sxe2_txrx.c',
)
allow_internal_get_api = true
diff --git a/drivers/net/sxe2/sxe2_ethdev.c b/drivers/net/sxe2/sxe2_ethdev.c
index c1a65f25ce..68d7e36cf1 100644
--- a/drivers/net/sxe2/sxe2_ethdev.c
+++ b/drivers/net/sxe2/sxe2_ethdev.c
@@ -26,6 +26,7 @@
#include "sxe2_cmd_chnl.h"
#include "sxe2_tx.h"
#include "sxe2_rx.h"
+#include "sxe2_txrx.h"
#include "sxe2_common.h"
#include "sxe2_common_log.h"
#include "sxe2_host_regs.h"
@@ -131,6 +132,9 @@ static s32 sxe2_dev_start(struct rte_eth_dev *dev)
goto l_end;
}
+ sxe2_rx_mode_func_set(dev);
+ sxe2_tx_mode_func_set(dev);
+
ret = sxe2_queues_start(dev);
if (ret) {
PMD_LOG_ERR(INIT, "enable queues failed");
@@ -363,8 +367,8 @@ void __iomem *sxe2_pci_map_addr_get(struct sxe2_adapter *adapter,
for (i = 0; i < bar_info->map_cnt; i++) {
seg_info = &bar_info->seg_info[i];
if (res_type == seg_info->type) {
- addr = (void __iomem *)((uintptr_t)seg_info->addr +
- seg_info->page_inner_offset + reg_width * idx_in_func);
+ addr = (uint8_t __iomem *)seg_info->addr +
+ seg_info->page_inner_offset + reg_width * idx_in_func;
goto l_end;
}
}
@@ -475,8 +479,9 @@ s32 sxe2_dev_pci_seg_map(struct sxe2_adapter *adapter,
map_addr = sxe2_drv_dev_mmap(adapter->cdev, bar_info->bar_idx, aligned_len, aligned_offset);
if (!map_addr) {
- PMD_LOG_ERR(INIT, "Failed to mmap BAR space, type=%d, len=%zu, page_size=%zu",
- res_type, org_len, page_size);
+ PMD_LOG_ERR(INIT, "Failed to mmap BAR space, type=%d, len=%" PRIu64
+ ", offset=%" PRIu64 ", page_size=%zu",
+ res_type, org_len, org_offset, page_size);
ret = SXE2_ERR_FAULT;
goto l_end;
}
@@ -760,6 +765,8 @@ static s32 sxe2_dev_init(struct rte_eth_dev *dev, struct sxe2_dev_kvargs_info *k
PMD_INIT_FUNC_TRACE();
+ sxe2_set_common_function(dev);
+
dev->dev_ops = &sxe2_eth_dev_ops;
ret = sxe2_hw_init(dev);
diff --git a/drivers/net/sxe2/sxe2_txrx.c b/drivers/net/sxe2/sxe2_txrx.c
new file mode 100644
index 0000000000..3e88ab5241
--- /dev/null
+++ b/drivers/net/sxe2/sxe2_txrx.c
@@ -0,0 +1,249 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
+ */
+
+#include <rte_common.h>
+#include <rte_net.h>
+#include <rte_vect.h>
+#include <rte_malloc.h>
+#include <rte_memzone.h>
+#include <ethdev_driver.h>
+#include <unistd.h>
+
+#include "sxe2_txrx.h"
+#include "sxe2_txrx_common.h"
+#include "sxe2_txrx_poll.h"
+#include "sxe2_ethdev.h"
+
+#include "sxe2_common_log.h"
+#include "sxe2_errno.h"
+#include "sxe2_osal.h"
+#include "sxe2_cmd_chnl.h"
+#if defined(RTE_ARCH_ARM64)
+#include <rte_cpuflags.h>
+#endif
+
+static s32 sxe2_tx_desciptor_status(void *tx_queue, u16 offset)
+{
+ struct sxe2_tx_queue *txq = (struct sxe2_tx_queue *)tx_queue;
+ s32 ret;
+ u16 desc_idx;
+
+ if (unlikely(offset >= txq->ring_depth)) {
+ ret = SXE2_ERR_INVAL;
+ goto l_end;
+ }
+
+ desc_idx = txq->next_use + offset;
+ desc_idx = DIV_ROUND_UP(desc_idx, txq->rs_thresh) * (txq->rs_thresh);
+ if (desc_idx >= txq->ring_depth) {
+ desc_idx -= txq->ring_depth;
+ if (desc_idx >= txq->ring_depth)
+ desc_idx -= txq->ring_depth;
+ }
+
+ if (desc_idx == 0)
+ desc_idx = txq->rs_thresh - 1;
+ else
+ desc_idx -= 1;
+
+ if (rte_cpu_to_le_64(SXE2_TX_DESC_DTYPE_DESC_DONE) ==
+ (txq->desc_ring[desc_idx].wb.dd &
+ rte_cpu_to_le_64(SXE2_TX_DESC_DTYPE_DESC_MASK)))
+ ret = RTE_ETH_TX_DESC_DONE;
+ else
+ ret = RTE_ETH_TX_DESC_FULL;
+
+l_end:
+ return ret;
+}
+
+static inline s32 sxe2_tx_mbuf_empty_check(struct rte_mbuf *mbuf)
+{
+ struct rte_mbuf *m_seg = mbuf;
+
+ while (m_seg != NULL) {
+ if (m_seg->data_len == 0)
+ return SXE2_ERR_INVAL;
+ m_seg = m_seg->next;
+ }
+
+ return SXE2_SUCCESS;
+}
+
+u16 sxe2_tx_pkts_prepare(__rte_unused void *tx_queue,
+ struct rte_mbuf **tx_pkts, u16 nb_pkts)
+{
+ struct sxe2_tx_queue *txq = tx_queue;
+ struct rte_mbuf *mbuf;
+ u64 ol_flags = 0;
+ s32 ret = SXE2_SUCCESS;
+ s32 i = 0;
+
+ for (i = 0; i < nb_pkts; i++) {
+ mbuf = tx_pkts[i];
+ if (!mbuf)
+ continue;
+ ol_flags = mbuf->ol_flags;
+ if (!(ol_flags & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))) {
+ if (mbuf->nb_segs > SXE2_TX_MTU_SEG_MAX ||
+ mbuf->pkt_len > SXE2_FRAME_SIZE_MAX) {
+ rte_errno = -SXE2_ERR_INVAL;
+ goto l_end;
+ }
+ } else if ((mbuf->tso_segsz < SXE2_MIN_TSO_MSS) ||
+ (mbuf->tso_segsz > SXE2_MAX_TSO_MSS) ||
+ (mbuf->nb_segs > txq->ring_depth) ||
+ (mbuf->pkt_len > SXE2_TX_TSO_PKTLEN_MAX)) {
+ rte_errno = -SXE2_ERR_INVAL;
+ goto l_end;
+ }
+
+ if (mbuf->pkt_len < SXE2_TX_MIN_PKT_LEN) {
+ rte_errno = -SXE2_ERR_INVAL;
+ goto l_end;
+ }
+
+#ifdef RTE_ETHDEV_DEBUG_TX
+ ret = rte_validate_tx_offload(mbuf);
+ if (ret != SXE2_SUCCESS) {
+ rte_errno = -ret;
+ goto l_end;
+ }
+#endif
+ ret = rte_net_intel_cksum_prepare(mbuf);
+ if (ret != SXE2_SUCCESS) {
+ rte_errno = -ret;
+ goto l_end;
+ }
+
+ ret = sxe2_tx_mbuf_empty_check(mbuf);
+ if (ret != SXE2_SUCCESS) {
+ rte_errno = -ret;
+ goto l_end;
+ }
+ }
+
+l_end:
+ return i;
+}
+
+void sxe2_tx_mode_func_set(struct rte_eth_dev *dev)
+{
+ struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
+ u32 tx_mode_flags = 0;
+
+ PMD_INIT_FUNC_TRACE();
+
+ dev->tx_pkt_prepare = sxe2_tx_pkts_prepare;
+ dev->tx_pkt_burst = sxe2_tx_pkts;
+ adapter->q_ctxt.tx_mode_flags = tx_mode_flags;
+ PMD_LOG_DEBUG(TX, "Tx mode flags:0x%016x port_id:%u.",
+ tx_mode_flags, dev->data->port_id);
+}
+
+static s32 sxe2_rx_desciptor_status(void *rx_queue, u16 offset)
+{
+ struct sxe2_rx_queue *rxq = (struct sxe2_rx_queue *)rx_queue;
+ volatile union sxe2_rx_desc *desc;
+ s32 ret;
+
+ if (unlikely(offset >= rxq->ring_depth)) {
+ ret = SXE2_ERR_INVAL;
+ goto l_end;
+ }
+
+ if (offset >= rxq->ring_depth - rxq->hold_num) {
+ ret = RTE_ETH_RX_DESC_UNAVAIL;
+ goto l_end;
+ }
+
+ if (rxq->processing_idx + offset >= rxq->ring_depth)
+ desc = &rxq->desc_ring[rxq->processing_idx + offset - rxq->ring_depth];
+ else
+ desc = &rxq->desc_ring[rxq->processing_idx + offset];
+
+ if (rte_le_to_cpu_64(desc->wb.status_err_ptype_len) & SXE2_RX_DESC_STATUS_DD_MASK)
+ ret = RTE_ETH_RX_DESC_DONE;
+ else
+ ret = RTE_ETH_RX_DESC_AVAIL;
+
+l_end:
+ PMD_LOG_DEBUG(RX, "Rx queue desc[%u] status:%d queue_id:%u port_id:%u",
+ offset, ret, rxq->queue_id, rxq->port_id);
+ return ret;
+}
+
+static s32 sxe2_rx_queue_count(void *rx_queue)
+{
+ struct sxe2_rx_queue *rxq = (struct sxe2_rx_queue *)rx_queue;
+ volatile union sxe2_rx_desc *desc;
+ u16 done_num = 0;
+
+ desc = &rxq->desc_ring[rxq->processing_idx];
+ while ((done_num < rxq->ring_depth) &&
+ (rte_le_to_cpu_64(desc->wb.status_err_ptype_len) &
+ SXE2_RX_DESC_STATUS_DD_MASK)) {
+ done_num += SXE2_RX_QUEUE_CHECK_INTERVAL_NUM;
+ if (rxq->processing_idx + done_num >= rxq->ring_depth)
+ desc = &rxq->desc_ring[rxq->processing_idx + done_num - rxq->ring_depth];
+ else
+ desc += SXE2_RX_QUEUE_CHECK_INTERVAL_NUM;
+ }
+
+ PMD_LOG_DEBUG(RX, "Rx queue done desc count:%u queue_id:%u port_id:%u",
+ done_num, rxq->queue_id, rxq->port_id);
+
+ return done_num;
+}
+
+static bool __rte_cold sxe2_rx_offload_en_check(struct rte_eth_dev *dev, u64 offload)
+{
+ struct sxe2_rx_queue *rxq;
+ bool en = false;
+ u16 i;
+
+ for (i = 0; i < dev->data->nb_rx_queues; ++i) {
+ rxq = (struct sxe2_rx_queue *)dev->data->rx_queues[i];
+ if (rxq == NULL)
+ continue;
+
+ if (0 != (rxq->offloads & offload)) {
+ en = true;
+ goto l_end;
+ }
+ }
+
+l_end:
+ return en;
+}
+
+void sxe2_rx_mode_func_set(struct rte_eth_dev *dev)
+{
+ struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
+ u32 rx_mode_flags = 0;
+
+ PMD_INIT_FUNC_TRACE();
+
+ if (sxe2_rx_offload_en_check(dev, RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT))
+ dev->rx_pkt_burst = sxe2_rx_pkts_scattered_split;
+ else
+ dev->rx_pkt_burst = sxe2_rx_pkts_scattered;
+
+ PMD_LOG_DEBUG(RX, "Rx mode flags:0x%016x port_id:%u.",
+ rx_mode_flags, dev->data->port_id);
+ adapter->q_ctxt.rx_mode_flags = rx_mode_flags;
+}
+
+void sxe2_set_common_function(struct rte_eth_dev *dev)
+{
+ PMD_INIT_FUNC_TRACE();
+
+ dev->rx_queue_count = sxe2_rx_queue_count;
+ dev->rx_descriptor_status = sxe2_rx_desciptor_status;
+ dev->rx_pkt_burst = sxe2_rx_pkts_scattered;
+
+ dev->tx_descriptor_status = sxe2_tx_desciptor_status;
+ dev->tx_pkt_prepare = sxe2_tx_pkts_prepare;
+ dev->tx_pkt_burst = sxe2_tx_pkts;
+}
diff --git a/drivers/net/sxe2/sxe2_txrx.h b/drivers/net/sxe2/sxe2_txrx.h
new file mode 100644
index 0000000000..cd9ebfa32f
--- /dev/null
+++ b/drivers/net/sxe2/sxe2_txrx.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
+ */
+
+#ifndef SXE2_TXRX_H
+#define SXE2_TXRX_H
+#include <ethdev_driver.h>
+#include "sxe2_queue.h"
+
+void sxe2_set_common_function(struct rte_eth_dev *dev);
+
+u16 sxe2_tx_pkts_prepare(__rte_unused void *tx_queue,
+ struct rte_mbuf **tx_pkts, u16 nb_pkts);
+
+void sxe2_tx_mode_func_set(struct rte_eth_dev *dev);
+
+void __rte_cold sxe2_rx_queue_reset(struct sxe2_rx_queue *rxq);
+
+void sxe2_rx_mode_func_set(struct rte_eth_dev *dev);
+
+#endif
diff --git a/drivers/net/sxe2/sxe2_txrx_poll.c b/drivers/net/sxe2/sxe2_txrx_poll.c
new file mode 100644
index 0000000000..55bea8b74c
--- /dev/null
+++ b/drivers/net/sxe2/sxe2_txrx_poll.c
@@ -0,0 +1,782 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
+ */
+
+#include <rte_common.h>
+#include <rte_net.h>
+#include <rte_vect.h>
+#include <rte_malloc.h>
+#include <rte_memzone.h>
+#include <ethdev_driver.h>
+#include <unistd.h>
+
+#include "sxe2_osal.h"
+#include "sxe2_txrx_common.h"
+#include "sxe2_txrx_poll.h"
+#include "sxe2_txrx.h"
+#include "sxe2_queue.h"
+#include "sxe2_ethdev.h"
+#include "sxe2_common_log.h"
+#include "sxe2_errno.h"
+
+static inline s32 sxe2_tx_cleanup(struct sxe2_tx_queue *txq)
+{
+ s32 ret = SXE2_SUCCESS;
+ volatile union sxe2_tx_data_desc *desc_ring = txq->desc_ring;
+ struct sxe2_tx_buffer *buffer_ring = txq->buffer_ring;
+ u16 ring_depth = txq->ring_depth;
+ u16 next_clean = txq->next_clean;
+ u16 clean_last;
+ u16 clean_num;
+
+ clean_last = next_clean + txq->rs_thresh;
+ if (clean_last >= ring_depth)
+ clean_last = clean_last - ring_depth;
+
+ clean_last = buffer_ring[clean_last].last_id;
+ if (rte_cpu_to_le_64(SXE2_TX_DESC_DTYPE_DESC_DONE) !=
+ (txq->desc_ring[clean_last].wb.dd & rte_cpu_to_le_64(SXE2_TX_DESC_DTYPE_MASK))) {
+ PMD_LOG_TX_DEBUG("desc[%u] is not done.port_id=%u queue_id=%u val=0x%" PRIx64,
+ clean_last, txq->port_id,
+ txq->queue_id, txq->desc_ring[clean_last].wb.dd);
+ SXE2_TX_STATS_CNT(txq, tx_desc_not_done, 1);
+ ret = SXE2_ERR_DESC_NO_DONE;
+ goto l_end;
+ }
+
+ if (clean_last > next_clean)
+ clean_num = clean_last - next_clean;
+ else
+ clean_num = ring_depth - next_clean + clean_last;
+
+ desc_ring[clean_last].wb.dd = 0;
+
+ txq->next_clean = clean_last;
+ txq->desc_free_num += clean_num;
+
+ ret = SXE2_SUCCESS;
+
+l_end:
+ return ret;
+}
+
+static __rte_always_inline u16
+sxe2_tx_pkt_data_desc_count(struct rte_mbuf *tx_pkt)
+{
+ struct rte_mbuf *m_seg = tx_pkt;
+ u16 count = 0;
+
+ while (m_seg != NULL) {
+ count += DIV_ROUND_UP(m_seg->data_len,
+ SXE2_TX_MAX_DATA_NUM_PER_DESC);
+ m_seg = m_seg->next;
+ }
+
+ return count;
+}
+
+static __rte_always_inline void
+sxe2_tx_desc_checksum_fill(u64 offloads, u32 *desc_cmd, u32 *desc_offset,
+ union sxe2_tx_offload_info ol_info)
+{
+ if (offloads & RTE_MBUF_F_TX_IP_CKSUM) {
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_IIPT_IPV4_CSUM;
+ *desc_offset |= SXE2_TX_DATA_DESC_IPLEN_VAL(ol_info.l3_len);
+ } else if (offloads & RTE_MBUF_F_TX_IPV4) {
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_IIPT_IPV4;
+ *desc_offset |= SXE2_TX_DATA_DESC_IPLEN_VAL(ol_info.l3_len);
+ } else if (offloads & RTE_MBUF_F_TX_IPV6) {
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_IIPT_IPV6;
+ *desc_offset |= SXE2_TX_DATA_DESC_IPLEN_VAL(ol_info.l3_len);
+ }
+
+ if (offloads & RTE_MBUF_F_TX_TCP_SEG) {
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_L4T_EOFT_TCP;
+ *desc_offset |= SXE2_TX_DATA_DESC_L4LEN_VAL(ol_info.l4_len);
+ goto l_end;
+ }
+
+ if (offloads & RTE_MBUF_F_TX_UDP_SEG) {
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_L4T_EOFT_UDP;
+ *desc_offset |= SXE2_TX_DATA_DESC_L4LEN_VAL(ol_info.l4_len);
+ goto l_end;
+ }
+
+ switch (offloads & RTE_MBUF_F_TX_L4_MASK) {
+ case RTE_MBUF_F_TX_TCP_CKSUM:
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_L4T_EOFT_TCP;
+ *desc_offset |= SXE2_TX_DATA_DESC_L4LEN_VAL(ol_info.l4_len);
+ break;
+ case RTE_MBUF_F_TX_SCTP_CKSUM:
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_L4T_EOFT_SCTP;
+ *desc_offset |= SXE2_TX_DATA_DESC_L4LEN_VAL(ol_info.l4_len);
+ break;
+ case RTE_MBUF_F_TX_UDP_CKSUM:
+ *desc_cmd |= SXE2_TX_DATA_DESC_CMD_L4T_EOFT_UDP;
+ *desc_offset |= SXE2_TX_DATA_DESC_L4LEN_VAL(ol_info.l4_len);
+ break;
+ default:
+
+ break;
+ }
+
+l_end:
+ return;
+}
+
+static __rte_always_inline u64
+sxe2_tx_data_desc_build_cobt(u32 cmd, u32 offset, u16 buf_size, u16 l2tag)
+{
+ return rte_cpu_to_le_64(SXE2_TX_DESC_DTYPE_DATA |
+ (((u64)cmd) << SXE2_TX_DATA_DESC_CMD_SHIFT) |
+ (((u64)offset) << SXE2_TX_DATA_DESC_OFFSET_SHIFT) |
+ (((u64)buf_size) << SXE2_TX_DATA_DESC_BUF_SZ_SHIFT) |
+ (((u64)l2tag) << SXE2_TX_DATA_DESC_L2TAG1_SHIFT));
+}
+
+u16 sxe2_tx_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, u16 nb_pkts)
+{
+ struct sxe2_tx_queue *txq = tx_queue;
+ struct sxe2_tx_buffer *buffer_ring;
+ struct sxe2_tx_buffer *buffer;
+ struct sxe2_tx_buffer *next_buffer;
+ struct rte_mbuf *tx_pkt;
+ struct rte_mbuf *m_seg;
+ volatile union sxe2_tx_data_desc *desc_ring;
+ volatile union sxe2_tx_data_desc *desc;
+ volatile struct sxe2_tx_context_desc *ctxt_desc;
+ union sxe2_tx_offload_info ol_info;
+ struct sxe2_vsi *vsi = txq->vsi;
+ rte_iova_t buf_dma_addr;
+ u64 offloads;
+ u64 desc_type_cmd_tso_mss;
+ u32 desc_cmd;
+ u32 desc_offset;
+ u32 desc_tag;
+ u32 desc_tunneling_params;
+ u16 ipsec_offset;
+ u16 ctxt_desc_num;
+ u16 desc_sum_num;
+ u16 tx_num;
+ u16 seg_len;
+ u16 next_use;
+ u16 last_use;
+ u16 desc_l2tag2;
+
+ buffer_ring = txq->buffer_ring;
+ desc_ring = txq->desc_ring;
+ next_use = txq->next_use;
+ buffer = &buffer_ring[next_use];
+
+ if (txq->desc_free_num < txq->free_thresh)
+ (void)sxe2_tx_cleanup(txq);
+
+ for (tx_num = 0; tx_num < nb_pkts; tx_num++) {
+ tx_pkt = *tx_pkts++;
+ desc_cmd = 0;
+ desc_offset = 0;
+ desc_tag = 0;
+ desc_tunneling_params = 0;
+ ipsec_offset = 0;
+ offloads = tx_pkt->ol_flags;
+ ol_info.l2_len = tx_pkt->l2_len;
+ ol_info.l3_len = tx_pkt->l3_len;
+ ol_info.l4_len = tx_pkt->l4_len;
+ ol_info.tso_segsz = tx_pkt->tso_segsz;
+ ol_info.outer_l2_len = tx_pkt->outer_l2_len;
+ ol_info.outer_l3_len = tx_pkt->outer_l3_len;
+
+ ctxt_desc_num = (offloads &
+ SXE2_TX_OFFLOAD_CTXT_NEEDCK_MASK) ? 1 : 0;
+ if (unlikely(vsi->vsi_type == SXE2_VSI_T_DPDK_ESW))
+ ctxt_desc_num = 1;
+
+ if (offloads & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG))
+ desc_sum_num = sxe2_tx_pkt_data_desc_count(tx_pkt) + ctxt_desc_num;
+ else
+ desc_sum_num = tx_pkt->nb_segs + ctxt_desc_num;
+
+ last_use = next_use + desc_sum_num - 1;
+ if (last_use >= txq->ring_depth)
+ last_use = last_use - txq->ring_depth;
+
+ if (desc_sum_num > txq->desc_free_num) {
+ if (unlikely(sxe2_tx_cleanup(txq) != 0))
+ goto l_exit_logic;
+
+ if (unlikely(desc_sum_num > txq->rs_thresh)) {
+ while (desc_sum_num > txq->desc_free_num)
+ if (unlikely(sxe2_tx_cleanup(txq) != 0))
+ goto l_exit_logic;
+ }
+ }
+
+ desc_offset |= SXE2_TX_DATA_DESC_MACLEN_VAL(ol_info.l2_len);
+
+ if (offloads & SXE2_TX_OFFLOAD_CKSUM_MASK) {
+ sxe2_tx_desc_checksum_fill(offloads, &desc_cmd,
+ &desc_offset, ol_info);
+ }
+
+ if (offloads & (RTE_MBUF_F_TX_VLAN | RTE_MBUF_F_TX_QINQ)) {
+ desc_cmd |= SXE2_TX_DATA_DESC_CMD_IL2TAG1;
+ desc_tag = tx_pkt->vlan_tci;
+ }
+
+ if (ctxt_desc_num) {
+ ctxt_desc = (volatile struct sxe2_tx_context_desc *)
+ &desc_ring[next_use];
+ desc_l2tag2 = 0;
+ desc_type_cmd_tso_mss = SXE2_TX_DESC_DTYPE_CTXT;
+
+ next_buffer = &buffer_ring[buffer->next_id];
+ RTE_MBUF_PREFETCH_TO_FREE(next_buffer->mbuf);
+
+ if (buffer->mbuf) {
+ rte_pktmbuf_free_seg(buffer->mbuf);
+ buffer->mbuf = NULL;
+ }
+
+ if (offloads & RTE_MBUF_F_TX_QINQ) {
+ desc_l2tag2 = tx_pkt->vlan_tci_outer;
+ desc_type_cmd_tso_mss |= SXE2_TX_CTXT_DESC_CMD_IL2TAG2_MASK;
+ }
+
+ ctxt_desc->tunneling_params =
+ rte_cpu_to_le_32(desc_tunneling_params);
+ ctxt_desc->l2tag2 = rte_cpu_to_le_16(desc_l2tag2);
+ ctxt_desc->type_cmd_tso_mss = rte_cpu_to_le_64(desc_type_cmd_tso_mss);
+ ctxt_desc->ipsec_offset = rte_cpu_to_le_64(ipsec_offset);
+
+ buffer->last_id = last_use;
+ next_use = buffer->next_id;
+ buffer = next_buffer;
+ }
+
+ m_seg = tx_pkt;
+
+ do {
+ desc = &desc_ring[next_use];
+ next_buffer = &buffer_ring[buffer->next_id];
+ RTE_MBUF_PREFETCH_TO_FREE(next_buffer->mbuf);
+ if (buffer->mbuf) {
+ rte_pktmbuf_free_seg(buffer->mbuf);
+ buffer->mbuf = NULL;
+ }
+
+ buffer->mbuf = m_seg;
+ seg_len = m_seg->data_len;
+ buf_dma_addr = rte_mbuf_data_iova(m_seg);
+ while ((offloads & (RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG)) &&
+ unlikely(seg_len > SXE2_TX_MAX_DATA_NUM_PER_DESC)) {
+ desc->read.buf_addr = rte_cpu_to_le_64(buf_dma_addr);
+ desc->read.type_cmd_off_bsz_l2t =
+ sxe2_tx_data_desc_build_cobt(desc_cmd, desc_offset,
+ SXE2_TX_MAX_DATA_NUM_PER_DESC,
+ desc_tag);
+ buf_dma_addr += SXE2_TX_MAX_DATA_NUM_PER_DESC;
+ seg_len -= SXE2_TX_MAX_DATA_NUM_PER_DESC;
+ buffer->last_id = last_use;
+ next_use = buffer->next_id;
+ buffer = next_buffer;
+ desc = &desc_ring[next_use];
+ next_buffer = &buffer_ring[buffer->next_id];
+ RTE_MBUF_PREFETCH_TO_FREE(next_buffer->mbuf);
+ }
+
+ desc->read.buf_addr = rte_cpu_to_le_64(buf_dma_addr);
+ desc->read.type_cmd_off_bsz_l2t =
+ sxe2_tx_data_desc_build_cobt(desc_cmd,
+ desc_offset, seg_len, desc_tag);
+
+ buffer->last_id = last_use;
+ next_use = buffer->next_id;
+ buffer = next_buffer;
+
+ m_seg = m_seg->next;
+ } while (m_seg);
+
+ desc_cmd |= SXE2_TX_DATA_DESC_CMD_EOP;
+ txq->desc_used_num += desc_sum_num;
+ txq->desc_free_num -= desc_sum_num;
+
+ if (txq->desc_used_num >= txq->rs_thresh) {
+ PMD_LOG_TX_DEBUG("Tx pkts set RS bit."
+ "last_use=%u port_id=%u, queue_id=%u",
+ last_use, txq->port_id, txq->queue_id);
+ desc_cmd |= SXE2_TX_DATA_DESC_CMD_RS;
+
+ txq->desc_used_num = 0;
+ }
+
+ desc->read.type_cmd_off_bsz_l2t |=
+ rte_cpu_to_le_64(((u64)desc_cmd) << SXE2_TX_DATA_DESC_CMD_SHIFT);
+ }
+
+l_exit_logic:
+ if (tx_num == 0)
+ goto l_end;
+ goto l_end_of_tx;
+
+l_end_of_tx:
+ SXE2_PCI_REG_WRITE_WC(txq->tdt_reg_addr, next_use);
+ PMD_LOG_TX_DEBUG("port_id=%u queue_id=%u next_use=%u send_pkts=%u",
+ txq->port_id, txq->queue_id, next_use, tx_num);
+ SXE2_TX_STATS_CNT(txq, tx_pkts_num, tx_num);
+
+ txq->next_use = next_use;
+
+l_end:
+ return tx_num;
+}
+
+static inline void
+sxe2_update_rx_tail(struct sxe2_rx_queue *rxq, u16 hold_num, u16 rx_id)
+{
+ hold_num += rxq->hold_num;
+
+ if (hold_num > rxq->rx_free_thresh) {
+ rx_id = (u16)((rx_id == 0) ? (rxq->ring_depth - 1) : (rx_id - 1));
+ SXE2_PCI_REG_WRITE_WC(rxq->rdt_reg_addr, rx_id);
+ hold_num = 0;
+ }
+ rxq->hold_num = hold_num;
+}
+
+static inline u64
+sxe2_rx_desc_error_para(__rte_unused struct sxe2_rx_queue *rxq,
+ union sxe2_rx_desc *desc)
+{
+ u64 flags = 0;
+ u64 desc_qw1 = rte_le_to_cpu_64(desc->wb.status_err_ptype_len);
+
+ if (unlikely(0 == (desc_qw1 & SXE2_RX_DESC_STATUS_L3L4_P_MASK)))
+ goto l_end;
+
+ if (likely(0 == (desc->wb.rxdid_src & SXE2_RX_DESC_EUDPE_MASK))) {
+ flags = RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD;
+ } else {
+ flags = RTE_MBUF_F_RX_OUTER_L4_CKSUM_BAD;
+ SXE2_RX_STATS_CNT(rxq, outer_l4_csum_err, 1);
+ }
+
+ if (likely(0 == (desc_qw1 & SXE2_RX_DESC_QW1_ERRORS_MASK))) {
+ flags |= (RTE_MBUF_F_RX_IP_CKSUM_GOOD |
+ RTE_MBUF_F_RX_L4_CKSUM_GOOD |
+ RTE_MBUF_F_RX_OUTER_L4_CKSUM_GOOD);
+ goto l_end;
+ }
+
+ if (likely(0 == (desc_qw1 & SXE2_RX_DESC_ERROR_CSUM_IPE_MASK))) {
+ flags |= RTE_MBUF_F_RX_IP_CKSUM_GOOD;
+ } else {
+ flags |= RTE_MBUF_F_RX_IP_CKSUM_BAD;
+ SXE2_RX_STATS_CNT(rxq, ip_csum_err, 1);
+ }
+
+ if (likely(0 == (desc_qw1 & SXE2_RX_DESC_ERROR_CSUM_L4_MASK))) {
+ flags |= RTE_MBUF_F_RX_L4_CKSUM_GOOD;
+ } else {
+ flags |= RTE_MBUF_F_RX_L4_CKSUM_BAD;
+ SXE2_RX_STATS_CNT(rxq, l4_csum_err, 1);
+ }
+
+ if (unlikely(0 != (desc_qw1 & SXE2_RX_DESC_ERROR_CSUM_EIP_MASK))) {
+ flags |= RTE_MBUF_F_RX_OUTER_IP_CKSUM_BAD;
+ SXE2_RX_STATS_CNT(rxq, outer_ip_csum_err, 1);
+ }
+
+l_end:
+ return flags;
+}
+
+static __rte_always_inline void
+sxe2_rx_mbuf_common_fields_fill(struct sxe2_rx_queue *rxq, struct rte_mbuf *mbuf,
+ union sxe2_rx_desc *rxd)
+{
+ u32 *ptype_tbl = rxq->vsi->adapter->ptype_tbl;
+ u64 qword1;
+ u64 pkt_flags;
+ qword1 = rte_le_to_cpu_64(rxd->wb.status_err_ptype_len);
+
+ mbuf->ol_flags = 0;
+ mbuf->packet_type = ptype_tbl[SXE2_RX_DESC_PTYPE_VAL_GET(qword1)];
+
+ pkt_flags = sxe2_rx_desc_error_para(rxq, rxd);
+
+ SXE2_RX_STATS_CNT(rxq, ptype_pkts[SXE2_RX_DESC_PTYPE_VAL_GET(qword1)], 1);
+ SXE2_RX_STATS_CNT(rxq, rx_pkts_num, 1);
+ mbuf->ol_flags |= pkt_flags;
+}
+
+static __rte_always_inline void
+sxe2_rx_sw_stats_update(struct sxe2_rx_queue *rxq, struct rte_mbuf *mbuf,
+ union sxe2_rx_desc *rxd)
+{
+ u64 qword1 = rte_le_to_cpu_64(rxd->wb.status_err_ptype_len);
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.pkts, 1,
+ rte_memory_order_relaxed);
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.bytes,
+ mbuf->pkt_len + RTE_ETHER_CRC_LEN,
+ rte_memory_order_relaxed);
+ switch (SXE2_RX_DESC_STATUS_UMBCAST_VAL_GET(qword1)) {
+ case SXE2_RX_DESC_STATUS_UNICAST:
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.unicast_pkts, 1,
+ rte_memory_order_relaxed);
+ break;
+ case SXE2_RX_DESC_STATUS_MUTICAST:
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.multicast_pkts, 1,
+ rte_memory_order_relaxed);
+ break;
+ case SXE2_RX_DESC_STATUS_BOARDCAST:
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.broadcast_pkts, 1,
+ rte_memory_order_relaxed);
+ break;
+ default:
+ break;
+ }
+}
+
+u16 sxe2_rx_pkts_scattered(void *rx_queue, struct rte_mbuf **rx_pkts, u16 nb_pkts)
+{
+ struct sxe2_rx_queue *rxq = (struct sxe2_rx_queue *)rx_queue;
+ volatile union sxe2_rx_desc *desc_ring;
+ volatile union sxe2_rx_desc *desc;
+ union sxe2_rx_desc desc_tmp;
+ struct rte_mbuf **buffer_ring;
+ struct rte_mbuf **cur_buffer;
+ struct rte_mbuf *cur_mbuf;
+ struct rte_mbuf *new_mbuf;
+ struct rte_mbuf *first_seg;
+ struct rte_mbuf *last_seg;
+ u64 qword1;
+ u16 done_num;
+ u16 hold_num;
+ u16 cur_idx;
+ u16 pkt_len;
+
+ desc_ring = rxq->desc_ring;
+ buffer_ring = rxq->buffer_ring;
+ cur_idx = rxq->processing_idx;
+ first_seg = rxq->pkt_first_seg;
+ last_seg = rxq->pkt_last_seg;
+ done_num = 0;
+ hold_num = 0;
+ while (done_num < nb_pkts) {
+ desc = &desc_ring[cur_idx];
+ qword1 = rte_le_to_cpu_64(desc->wb.status_err_ptype_len);
+ if (0 == (SXE2_RX_DESC_STATUS_DD_MASK & qword1))
+ break;
+
+ new_mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
+ if (unlikely(new_mbuf == NULL)) {
+ rxq->vsi->adapter->dev_info.dev_data->rx_mbuf_alloc_failed++;
+ PMD_LOG_INFO(RX, "Rx new_mbuf alloc failed port_id:%u "
+ "queue_id:%u", rxq->port_id, rxq->queue_id);
+ break;
+ }
+
+ hold_num++;
+ desc_tmp = *desc;
+ cur_buffer = &buffer_ring[cur_idx];
+ cur_idx++;
+ if (unlikely(cur_idx == rxq->ring_depth))
+ cur_idx = 0;
+
+ rte_prefetch0(buffer_ring[cur_idx]);
+
+ if (0 == (cur_idx & 0x3)) {
+ rte_prefetch0(&desc_ring[cur_idx]);
+ rte_prefetch0(&buffer_ring[cur_idx]);
+ }
+
+ cur_mbuf = *cur_buffer;
+
+ *cur_buffer = new_mbuf;
+
+ desc->read.hdr_addr = 0;
+ desc->read.pkt_addr =
+ rte_cpu_to_le_64(rte_mbuf_data_iova_default(new_mbuf));
+
+ pkt_len = SXE2_RX_DESC_PKT_LEN_VAL_GET(qword1);
+ cur_mbuf->data_len = pkt_len;
+ cur_mbuf->data_off = RTE_PKTMBUF_HEADROOM;
+
+ if (first_seg == NULL) {
+ first_seg = cur_mbuf;
+ first_seg->nb_segs = 1;
+ first_seg->pkt_len = pkt_len;
+ } else {
+ first_seg->pkt_len += pkt_len;
+ first_seg->nb_segs++;
+ last_seg->next = cur_mbuf;
+ }
+
+ if (0 == (qword1 & SXE2_RX_DESC_STATUS_EOP_MASK)) {
+ last_seg = cur_mbuf;
+ continue;
+ }
+
+ if (unlikely(qword1 & SXE2_RX_DESC_ERROR_RXE_MASK) ||
+ unlikely(qword1 & SXE2_RX_DESC_ERROR_OVERSIZE_MASK)) {
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.drop_pkts, 1,
+ rte_memory_order_relaxed);
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.drop_bytes,
+ first_seg->pkt_len - rxq->crc_len + RTE_ETHER_CRC_LEN,
+ rte_memory_order_relaxed);
+ rte_pktmbuf_free(first_seg);
+ first_seg = NULL;
+ continue;
+ }
+
+ cur_mbuf->next = NULL;
+ if (unlikely(rxq->crc_len > 0)) {
+ first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
+
+ if (pkt_len <= RTE_ETHER_CRC_LEN) {
+ rte_pktmbuf_free_seg(cur_mbuf);
+ first_seg->nb_segs--;
+ last_seg->data_len = last_seg->data_len + pkt_len -
+ RTE_ETHER_CRC_LEN;
+ last_seg->next = NULL;
+ } else {
+ cur_mbuf->data_len = pkt_len - RTE_ETHER_CRC_LEN;
+ }
+
+ } else if (pkt_len == 0) {
+ rte_pktmbuf_free_seg(cur_mbuf);
+ first_seg->nb_segs--;
+ last_seg->next = NULL;
+ }
+
+ rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr, first_seg->data_off));
+ first_seg->port = rxq->port_id;
+
+ sxe2_rx_mbuf_common_fields_fill(rxq, first_seg, &desc_tmp);
+
+ if (rxq->vsi->adapter->devargs.sw_stats_en)
+ sxe2_rx_sw_stats_update(rxq, first_seg, &desc_tmp);
+
+ rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr, first_seg->data_off));
+
+ rx_pkts[done_num] = first_seg;
+ done_num++;
+
+ first_seg = NULL;
+ }
+
+ rxq->processing_idx = cur_idx;
+ rxq->pkt_first_seg = first_seg;
+ rxq->pkt_last_seg = last_seg;
+
+ sxe2_update_rx_tail(rxq, hold_num, cur_idx);
+
+ return done_num;
+}
+
+u16 sxe2_rx_pkts_scattered_split(void *rx_queue, struct rte_mbuf **rx_pkts, u16 nb_pkts)
+{
+ struct sxe2_rx_queue *rxq = (struct sxe2_rx_queue *)rx_queue;
+ volatile union sxe2_rx_desc *desc_ring;
+ volatile union sxe2_rx_desc *desc;
+ union sxe2_rx_desc desc_tmp;
+ struct rte_mbuf **buffer_ring;
+ struct rte_mbuf **cur_buffer;
+ struct rte_mbuf *cur_mbuf;
+ struct rte_mbuf *cur_mbuf_pay;
+ struct rte_mbuf *new_mbuf;
+ struct rte_mbuf *new_mbuf_pay;
+ struct rte_mbuf *first_seg;
+ struct rte_mbuf *last_seg;
+ u64 qword1;
+ u16 done_num;
+ u16 hold_num;
+ u16 cur_idx;
+ u16 pkt_len;
+ u16 hdr_len;
+
+ desc_ring = rxq->desc_ring;
+ buffer_ring = rxq->buffer_ring;
+ cur_idx = rxq->processing_idx;
+ first_seg = rxq->pkt_first_seg;
+ last_seg = rxq->pkt_last_seg;
+ done_num = 0;
+ hold_num = 0;
+ new_mbuf = NULL;
+
+ while (done_num < nb_pkts) {
+ desc = &desc_ring[cur_idx];
+ qword1 = rte_le_to_cpu_64(desc->wb.status_err_ptype_len);
+
+ if (0 == (SXE2_RX_DESC_STATUS_DD_MASK & qword1))
+ break;
+
+ if ((rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) == 0 ||
+ first_seg == NULL) {
+ new_mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
+ if (unlikely(new_mbuf == NULL)) {
+ rxq->vsi->adapter->dev_info.dev_data->rx_mbuf_alloc_failed++;
+ PMD_LOG_RX_INFO("Rx new_mbuf alloc failed port_id=%u "
+ "queue_id=%u", rxq->port_id,
+ rxq->idx_in_pf);
+ break;
+ }
+ }
+
+ if (rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
+ new_mbuf_pay = rte_mbuf_raw_alloc(rxq->rx_seg[1].mp);
+ if (unlikely(new_mbuf_pay == NULL)) {
+ rxq->vsi->adapter->dev_info.dev_data->rx_mbuf_alloc_failed++;
+ PMD_LOG_RX_INFO("Rx new_mbuf_pay alloc failed port_id=%u "
+ "queue_id=%u", rxq->port_id,
+ rxq->idx_in_pf);
+ if (new_mbuf != NULL)
+ rte_pktmbuf_free(new_mbuf);
+ new_mbuf = NULL;
+ break;
+ }
+ }
+
+ hold_num++;
+ desc_tmp = *desc;
+ cur_buffer = &buffer_ring[cur_idx];
+ cur_idx++;
+ if (unlikely(cur_idx == rxq->ring_depth))
+ cur_idx = 0;
+ rte_prefetch0(buffer_ring[cur_idx]);
+ if (0 == (cur_idx & 0x3)) {
+ rte_prefetch0(&desc_ring[cur_idx]);
+ rte_prefetch0(&buffer_ring[cur_idx]);
+ }
+ cur_mbuf = *cur_buffer;
+ if (0 == (rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
+ *cur_buffer = new_mbuf;
+ desc->read.hdr_addr = 0;
+ desc->read.pkt_addr =
+ rte_cpu_to_le_64(rte_mbuf_data_iova_default(new_mbuf));
+ } else {
+ if (first_seg == NULL) {
+ *cur_buffer = new_mbuf;
+ new_mbuf->next = new_mbuf_pay;
+ new_mbuf->data_off = RTE_PKTMBUF_HEADROOM;
+ new_mbuf_pay->next = NULL;
+ new_mbuf_pay->data_off = RTE_PKTMBUF_HEADROOM;
+ desc->read.hdr_addr =
+ rte_cpu_to_le_64(rte_mbuf_data_iova_default(new_mbuf));
+ desc->read.pkt_addr =
+ rte_cpu_to_le_64(rte_mbuf_data_iova_default(new_mbuf_pay));
+ } else {
+ cur_mbuf_pay = cur_mbuf->next;
+ cur_mbuf->next = new_mbuf_pay;
+ new_mbuf_pay->next = NULL;
+ new_mbuf_pay->data_off = RTE_PKTMBUF_HEADROOM;
+ desc->read.hdr_addr =
+ rte_cpu_to_le_64(rte_mbuf_data_iova_default(cur_mbuf));
+ desc->read.pkt_addr =
+ rte_cpu_to_le_64(rte_mbuf_data_iova_default(new_mbuf_pay));
+ cur_mbuf = cur_mbuf_pay;
+ }
+ }
+
+ if (0 == (rxq->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT)) {
+ pkt_len = SXE2_RX_DESC_PKT_LEN_VAL_GET(qword1);
+ cur_mbuf->data_len = pkt_len;
+ cur_mbuf->data_off = RTE_PKTMBUF_HEADROOM;
+ if (first_seg == NULL) {
+ first_seg = cur_mbuf;
+ first_seg->nb_segs = 1;
+ first_seg->pkt_len = pkt_len;
+ } else {
+ first_seg->pkt_len += pkt_len;
+ first_seg->nb_segs++;
+ last_seg->next = cur_mbuf;
+ }
+ } else {
+ if (first_seg == NULL) {
+ cur_mbuf->nb_segs = 2;
+ cur_mbuf->next->next = NULL;
+ pkt_len = SXE2_RX_DESC_PKT_LEN_VAL_GET(qword1);
+ hdr_len = SXE2_RX_DESC_HDR_LEN_VAL_GET(qword1);
+ cur_mbuf->data_len = hdr_len;
+ cur_mbuf->pkt_len = hdr_len + pkt_len;
+ cur_mbuf->next->data_len = pkt_len;
+ first_seg = cur_mbuf;
+ cur_mbuf = cur_mbuf->next;
+ last_seg = cur_mbuf;
+ } else {
+ cur_mbuf->nb_segs = 1;
+ cur_mbuf->next = NULL;
+ pkt_len = SXE2_RX_DESC_PKT_LEN_VAL_GET(qword1);
+ cur_mbuf->data_len = pkt_len;
+
+ first_seg->pkt_len += pkt_len;
+ first_seg->nb_segs++;
+ last_seg->next = cur_mbuf;
+ }
+ }
+
+#ifdef RTE_ETHDEV_DEBUG_RX
+
+ rte_pktmbuf_dump(stdout, first_seg, rte_pktmbuf_pkt_len(first_seg));
+#endif
+
+ if (0 == (rte_le_to_cpu_64(desc_tmp.wb.status_err_ptype_len) &
+ SXE2_RX_DESC_STATUS_EOP_MASK)) {
+ last_seg = cur_mbuf;
+ continue;
+ }
+
+ if (unlikely(qword1 & SXE2_RX_DESC_ERROR_RXE_MASK) ||
+ unlikely(qword1 & SXE2_RX_DESC_ERROR_OVERSIZE_MASK)) {
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.drop_pkts, 1,
+ rte_memory_order_relaxed);
+ rte_atomic_fetch_add_explicit(&rxq->sw_stats.drop_bytes,
+ first_seg->pkt_len - rxq->crc_len + RTE_ETHER_CRC_LEN,
+ rte_memory_order_relaxed);
+ rte_pktmbuf_free(first_seg);
+ first_seg = NULL;
+ continue;
+ }
+
+ cur_mbuf->next = NULL;
+ if (unlikely(rxq->crc_len > 0)) {
+ first_seg->pkt_len -= RTE_ETHER_CRC_LEN;
+ if (pkt_len <= RTE_ETHER_CRC_LEN) {
+ rte_pktmbuf_free_seg(cur_mbuf);
+ cur_mbuf = NULL;
+ first_seg->nb_segs--;
+ last_seg->data_len = last_seg->data_len +
+ pkt_len - RTE_ETHER_CRC_LEN;
+ last_seg->next = NULL;
+ } else {
+ cur_mbuf->data_len = pkt_len - RTE_ETHER_CRC_LEN;
+ }
+ } else if (pkt_len == 0) {
+ rte_pktmbuf_free_seg(cur_mbuf);
+ cur_mbuf = NULL;
+ first_seg->nb_segs--;
+ last_seg->next = NULL;
+ }
+
+ first_seg->port = rxq->port_id;
+ sxe2_rx_mbuf_common_fields_fill(rxq, first_seg, &desc_tmp);
+
+ if (rxq->vsi->adapter->devargs.sw_stats_en)
+ sxe2_rx_sw_stats_update(rxq, first_seg, &desc_tmp);
+
+ rte_prefetch0(RTE_PTR_ADD(first_seg->buf_addr, first_seg->data_off));
+
+ rx_pkts[done_num] = first_seg;
+ done_num++;
+
+ first_seg = NULL;
+ }
+
+ rxq->processing_idx = cur_idx;
+ rxq->pkt_first_seg = first_seg;
+ rxq->pkt_last_seg = last_seg;
+
+ sxe2_update_rx_tail(rxq, hold_num, cur_idx);
+
+ return done_num;
+}
--
2.47.3
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox