Make compress and crypto drivers register to the common driver. Remove (unneeded) include_directories().
Signed-off-by: David Marchand <david.march...@redhat.com> --- drivers/common/nitrox/meson.build | 3 -- drivers/common/nitrox/nitrox_device.c | 75 ++++++++++----------------- drivers/common/nitrox/nitrox_device.h | 16 ++++++ drivers/common/nitrox/version.map | 1 + drivers/compress/nitrox/meson.build | 2 - drivers/compress/nitrox/nitrox_comp.c | 6 +++ drivers/crypto/nitrox/meson.build | 2 - drivers/crypto/nitrox/nitrox_sym.c | 6 +++ 8 files changed, 57 insertions(+), 54 deletions(-) diff --git a/drivers/common/nitrox/meson.build b/drivers/common/nitrox/meson.build index f3cb42f006..115dd8de4d 100644 --- a/drivers/common/nitrox/meson.build +++ b/drivers/common/nitrox/meson.build @@ -14,6 +14,3 @@ sources += files( 'nitrox_logs.c', 'nitrox_qp.c', ) - -includes += include_directories('../../crypto/nitrox') -includes += include_directories('../../compress/nitrox') diff --git a/drivers/common/nitrox/nitrox_device.c b/drivers/common/nitrox/nitrox_device.c index 39edc440a7..6cd57faaa4 100644 --- a/drivers/common/nitrox/nitrox_device.c +++ b/drivers/common/nitrox/nitrox_device.c @@ -6,8 +6,6 @@ #include "nitrox_device.h" #include "nitrox_hal.h" -#include "nitrox_sym.h" -#include "nitrox_comp.h" #define PCI_VENDOR_ID_CAVIUM 0x177d #define NITROX_V_PCI_VF_DEV_ID 0x13 @@ -63,11 +61,21 @@ ndev_release(struct nitrox_device *ndev) rte_free(ndev); } +TAILQ_HEAD(ndrv_list, nitrox_driver); +static struct ndrv_list ndrv_list = TAILQ_HEAD_INITIALIZER(ndrv_list); + +void +nitrox_register_driver(struct nitrox_driver *ndrv) +{ + TAILQ_INSERT_TAIL(&ndrv_list, ndrv, next); +} + static int nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, struct rte_pci_device *pdev) { struct nitrox_device *ndev; + struct nitrox_driver *ndrv; int err = -1; /* Nitrox CSR space */ @@ -79,19 +87,21 @@ nitrox_pci_probe(struct rte_pci_driver *pci_drv __rte_unused, return -ENOMEM; ndev_init(ndev, pdev); - err = nitrox_sym_pmd_create(ndev); - if (err) - goto sym_pmd_err; - - err = nitrox_comp_pmd_create(ndev); - if (err) - goto comp_pmd_err; + TAILQ_FOREACH(ndrv, &ndrv_list, next) { + err = ndrv->create(ndev); + if (err) + goto drv_err; + } return 0; -comp_pmd_err: - nitrox_sym_pmd_destroy(ndev); -sym_pmd_err: +drv_err: + ndrv = TAILQ_PREV(ndrv, ndrv_list, next); + while (ndrv != NULL) { + ndrv->destroy(ndev); + ndrv = TAILQ_PREV(ndrv, ndrv_list, next); + } + ndev_release(ndev); return err; } @@ -100,19 +110,18 @@ static int nitrox_pci_remove(struct rte_pci_device *pdev) { struct nitrox_device *ndev; + struct nitrox_driver *ndrv; int err; ndev = find_ndev(pdev); if (!ndev) return -ENODEV; - err = nitrox_sym_pmd_destroy(ndev); - if (err) - return err; - - err = nitrox_comp_pmd_destroy(ndev); - if (err) - return err; + TAILQ_FOREACH(ndrv, &ndrv_list, next) { + err = ndrv->destroy(ndev); + if (err) + return err; + } ndev_release(ndev); return 0; @@ -133,33 +142,5 @@ static struct rte_pci_driver nitrox_pmd = { .remove = nitrox_pci_remove, }; -__rte_weak int -nitrox_sym_pmd_create(struct nitrox_device *ndev) -{ - RTE_SET_USED(ndev); - return 0; -} - -__rte_weak int -nitrox_sym_pmd_destroy(struct nitrox_device *ndev) -{ - RTE_SET_USED(ndev); - return 0; -} - -__rte_weak int -nitrox_comp_pmd_create(struct nitrox_device *ndev) -{ - RTE_SET_USED(ndev); - return 0; -} - -__rte_weak int -nitrox_comp_pmd_destroy(struct nitrox_device *ndev) -{ - RTE_SET_USED(ndev); - return 0; -} - RTE_PMD_REGISTER_PCI(nitrox, nitrox_pmd); RTE_PMD_REGISTER_PCI_TABLE(nitrox, pci_id_nitrox_map); diff --git a/drivers/common/nitrox/nitrox_device.h b/drivers/common/nitrox/nitrox_device.h index 877bccb321..b74b71808e 100644 --- a/drivers/common/nitrox/nitrox_device.h +++ b/drivers/common/nitrox/nitrox_device.h @@ -6,6 +6,7 @@ #define _NITROX_DEVICE_H_ #include <bus_pci_driver.h> +#include <rte_compat.h> struct nitrox_sym_device; struct nitrox_comp_device; @@ -21,4 +22,19 @@ struct nitrox_device { uint16_t nr_queues; }; +struct nitrox_driver { + TAILQ_ENTRY(nitrox_driver) next; + int (*create)(struct nitrox_device *ndev); + int (*destroy)(struct nitrox_device *ndev); +}; + +__rte_internal +void nitrox_register_driver(struct nitrox_driver *ndrv); + +#define NITROX_REGISTER_DRIVER(ndrv) \ +RTE_INIT(ndrv ## _register) \ +{ \ + nitrox_register_driver(&ndrv); \ +} + #endif /* _NITROX_DEVICE_H_ */ diff --git a/drivers/common/nitrox/version.map b/drivers/common/nitrox/version.map index 43295171e4..f58c044fc5 100644 --- a/drivers/common/nitrox/version.map +++ b/drivers/common/nitrox/version.map @@ -4,6 +4,7 @@ INTERNAL { nitrox_logtype; nitrox_qp_release; nitrox_qp_setup; + nitrox_register_driver; local: *; }; diff --git a/drivers/compress/nitrox/meson.build b/drivers/compress/nitrox/meson.build index 1becc66912..5cecc2ad66 100644 --- a/drivers/compress/nitrox/meson.build +++ b/drivers/compress/nitrox/meson.build @@ -12,5 +12,3 @@ sources += files( 'nitrox_comp.c', 'nitrox_comp_reqmgr.c', ) - -includes += include_directories('../../common/nitrox') diff --git a/drivers/compress/nitrox/nitrox_comp.c b/drivers/compress/nitrox/nitrox_comp.c index 1b2054c61a..41a3ee0de8 100644 --- a/drivers/compress/nitrox/nitrox_comp.c +++ b/drivers/compress/nitrox/nitrox_comp.c @@ -602,3 +602,9 @@ nitrox_comp_pmd_destroy(struct nitrox_device *ndev) ndev->comp_dev = NULL; return 0; } + +static struct nitrox_driver comp_drv = { + .create = nitrox_comp_pmd_create, + .destroy = nitrox_comp_pmd_destroy, +}; +NITROX_REGISTER_DRIVER(comp_drv); diff --git a/drivers/crypto/nitrox/meson.build b/drivers/crypto/nitrox/meson.build index f8887713d2..cbe2b7d6dc 100644 --- a/drivers/crypto/nitrox/meson.build +++ b/drivers/crypto/nitrox/meson.build @@ -13,5 +13,3 @@ sources += files( 'nitrox_sym_capabilities.c', 'nitrox_sym_reqmgr.c', ) - -includes += include_directories('../../common/nitrox') diff --git a/drivers/crypto/nitrox/nitrox_sym.c b/drivers/crypto/nitrox/nitrox_sym.c index da70121d91..7c2dc98a4b 100644 --- a/drivers/crypto/nitrox/nitrox_sym.c +++ b/drivers/crypto/nitrox/nitrox_sym.c @@ -798,6 +798,12 @@ nitrox_sym_pmd_destroy(struct nitrox_device *ndev) return rte_cryptodev_pmd_destroy(ndev->sym_dev->cdev); } +static struct nitrox_driver sym_drv = { + .create = nitrox_sym_pmd_create, + .destroy = nitrox_sym_pmd_destroy, +}; +NITROX_REGISTER_DRIVER(sym_drv); + static struct cryptodev_driver nitrox_crypto_drv; RTE_PMD_REGISTER_CRYPTO_DRIVER(nitrox_crypto_drv, nitrox_rte_sym_drv, -- 2.48.1