Add a common function for checking whether given device is managed by any mlx5 driver.
Signed-off-by: Dariusz Sosnowski <[email protected]> Acked-by: Viacheslav Ovsiienko <[email protected]> --- drivers/common/mlx5/mlx5_common.c | 11 +++++++++++ drivers/common/mlx5/mlx5_common.h | 14 ++++++++++++++ drivers/net/mlx5/mlx5.c | 8 +------- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/common/mlx5/mlx5_common.c b/drivers/common/mlx5/mlx5_common.c index 57f484fcb7..46da81ebd8 100644 --- a/drivers/common/mlx5/mlx5_common.c +++ b/drivers/common/mlx5/mlx5_common.c @@ -1516,6 +1516,17 @@ mlx5_devx_uar_prepare(struct mlx5_common_device *cdev, struct mlx5_uar *uar) return 0; } +RTE_EXPORT_INTERNAL_SYMBOL(mlx5_dev_is_managed) +bool +mlx5_dev_is_managed(const struct rte_device *dev) +{ + if (dev == NULL || dev->driver == NULL || dev->driver->name == NULL) + return false; + + return strcmp(dev->driver->name, MLX5_PCI_DRIVER_NAME) == 0 || + strcmp(dev->driver->name, MLX5_AUXILIARY_DRIVER_NAME) == 0; +} + RTE_EXPORT_INTERNAL_SYMBOL(mlx5_dev_matches) bool mlx5_dev_matches(const struct rte_device *dev, diff --git a/drivers/common/mlx5/mlx5_common.h b/drivers/common/mlx5/mlx5_common.h index 0d940b1fdf..548f0c887b 100644 --- a/drivers/common/mlx5/mlx5_common.h +++ b/drivers/common/mlx5/mlx5_common.h @@ -601,6 +601,20 @@ __rte_internal void mlx5_class_driver_register(struct mlx5_class_driver *driver); +/** + * Check if given EAL device is managed by any mlx5 driver. + * + * @param dev + * Pointer to device. + * + * @return + * - True if device is managed by mlx5 driver. + * - False otherwise. + */ +__rte_internal +bool +mlx5_dev_is_managed(const struct rte_device *dev); + /** * Test device is a PCI bus device. * diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index 19491b9dc9..7093eefa15 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -3499,13 +3499,7 @@ mlx5_eth_find_next(uint16_t port_id, struct rte_device *odev) if (dev->state != RTE_ETH_DEV_UNUSED && dev->device && - (dev->device == odev || - (dev->device->driver && - dev->device->driver->name && - ((strcmp(dev->device->driver->name, - MLX5_PCI_DRIVER_NAME) == 0) || - (strcmp(dev->device->driver->name, - MLX5_AUXILIARY_DRIVER_NAME) == 0))))) + (dev->device == odev || mlx5_dev_is_managed(dev->device))) break; port_id++; } -- 2.43.0

