From 2365f8d7f609cff766b150028372bc28d8b436f7 Mon Sep 17 00:00:00 2001 From: Dragos Tatulea Date: Wed, 30 Sep 2026 14:42:19 +0300 Subject: RDMA/mlx5: Add mlx5_data_direct_supported() helper The data direct capability FW checks are duplicated inline in mlx5_ib_data_direct_init() and mlx5_ib_data_direct_cleanup(). Wrap it in a mlx5_data_direct_supported() helper and use it in both places, in preparation for moving the data direct matching code to mlx5_core. For the same reason put it in driver.h instead of data_direct.h. No functional change. Signed-off-by: Dragos Tatulea Reviewed-by: Leon Romanovsky Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260930114227.139274-3-tariqt@nvidia.com Signed-off-by: Leon Romanovsky --- include/linux/mlx5/driver.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include/linux') diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index b1871c0821d0..ee29f95ead18 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -1395,4 +1395,10 @@ static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev) #define MLX5_SW_IMAGE_GUID_MAX_BYTES 9 +static inline bool mlx5_data_direct_supported(struct mlx5_core_dev *mdev) +{ + return MLX5_CAP_GEN(mdev, data_direct) && + MLX5_CAP_GEN_2(mdev, query_vuid); +} + #endif /* MLX5_DRIVER_H */ -- cgit v1.2.3 From ebbb9f87689998157e7310e96f585bc293f6fcb0 Mon Sep 17 00:00:00 2001 From: Dragos Tatulea Date: Wed, 30 Sep 2026 14:42:20 +0300 Subject: RDMA/mlx5: Make the data direct VUID query self-contained mlx5_cmd_query_vuid() in cmd.c is generic over the data_direct flag but its only caller is the data direct init path, which always passes data_direct=true. Move it into data_direct.c as mlx5_data_direct_query_vuid(), dropping the always-true parameter and hardcoding data_direct=1. This groups the query with the rest of the data direct code so that it travels together when the data direct matching code is relocated to mlx5_core, and lets it become static there once the query is folded into the core bind path. This function will become private in a subsequent patch. No functional change. Signed-off-by: Dragos Tatulea Reviewed-by: Leon Romanovsky Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260930114227.139274-4-tariqt@nvidia.com Signed-off-by: Leon Romanovsky --- include/linux/mlx5/data_direct.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 include/linux/mlx5/data_direct.h (limited to 'include/linux') diff --git a/include/linux/mlx5/data_direct.h b/include/linux/mlx5/data_direct.h new file mode 100644 index 000000000000..4556e58c6d03 --- /dev/null +++ b/include/linux/mlx5/data_direct.h @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* + * Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved + */ + +#ifndef _MLX5_DATA_DIRECT_H +#define _MLX5_DATA_DIRECT_H + +struct mlx5_core_dev; + +int mlx5_data_direct_query_vuid(struct mlx5_core_dev *dev, char *out_vuid); + +#endif -- cgit v1.2.3 From 1c879b1e9f2ed620523e17ca239683bc8029e143 Mon Sep 17 00:00:00 2001 From: Dragos Tatulea Date: Wed, 30 Sep 2026 14:42:23 +0300 Subject: RDMA/mlx5: Add new registration stage for data direct users For the upcoming move of data direct to mlx5_core driver, the API needs to be split into init and register stages. That's because only the core will do the init phase but both IB and netdev devices will need to register. While data direct still lives in mlx5_ib, do all steps in mlx5_ib_data_direct_init(). While at it, make mlx5_data_direct_query_vuid() private as it is no longer needed. This patch has no functional changes. It is a preparation for moving data direct infrastructure to mlx5_core. For this reason the new functions are added to the new header. Signed-off-by: Dragos Tatulea Reviewed-by: Leon Romanovsky Reviewed-by: Cosmin Ratiu Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260930114227.139274-7-tariqt@nvidia.com Signed-off-by: Leon Romanovsky --- include/linux/mlx5/data_direct.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'include/linux') diff --git a/include/linux/mlx5/data_direct.h b/include/linux/mlx5/data_direct.h index 4556e58c6d03..71f47547aebb 100644 --- a/include/linux/mlx5/data_direct.h +++ b/include/linux/mlx5/data_direct.h @@ -7,7 +7,15 @@ #define _MLX5_DATA_DIRECT_H struct mlx5_core_dev; +struct mlx5_ib_dev; +struct notifier_block; -int mlx5_data_direct_query_vuid(struct mlx5_core_dev *dev, char *out_vuid); +int mlx5_data_direct_init(struct mlx5_ib_dev *ibdev); +void mlx5_data_direct_cleanup(struct mlx5_ib_dev *ibdev); + +int mlx5_data_direct_register(struct mlx5_ib_dev *ibdev, + struct notifier_block *nb); +void mlx5_data_direct_unregister(struct mlx5_ib_dev *ibdev, + struct notifier_block *nb); #endif -- cgit v1.2.3 From f6c452b311f0e4a8fc2a0c287dde298d5492112a Mon Sep 17 00:00:00 2001 From: Dragos Tatulea Date: Wed, 30 Sep 2026 14:42:25 +0300 Subject: RDMA/mlx5: Consolidate data direct state into one object There are three per device data direct objects: mlx5_data_direct_dev, mlx5_data_direct_resources and mlx5_data_direct_registration with separate allocations. This patch consolidates all of them into the registration object. For this, a few things needed to happen: - mlx5_ib_dev keeps a pointer to mlx5_data_direct. - mlx5_data_direct_dev is now accessible from mlx5_data_direct. mlx5_data_direct_get_dev() is added as a helper to access the device pointer. - Since mlx5_data_direct is part of mlx5_data_direct_registration, getting to the registration is a simple container_of. No need for searching the list. Since mlx5_data_direct_resources no longer has an accurate name, this patch renames it. This is a preparation for the upcoming move of data_direct to mlx5_core. This patch has no functional changes. Signed-off-by: Dragos Tatulea Signed-off-by: Tariq Toukan Link: https://patch.msgid.link/20260930114227.139274-9-tariqt@nvidia.com Signed-off-by: Leon Romanovsky --- include/linux/mlx5/data_direct.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'include/linux') diff --git a/include/linux/mlx5/data_direct.h b/include/linux/mlx5/data_direct.h index 71f47547aebb..eaa2dc6bc607 100644 --- a/include/linux/mlx5/data_direct.h +++ b/include/linux/mlx5/data_direct.h @@ -6,10 +6,27 @@ #ifndef _MLX5_DATA_DIRECT_H #define _MLX5_DATA_DIRECT_H +#include + struct mlx5_core_dev; +struct mlx5_data_direct_dev; struct mlx5_ib_dev; struct notifier_block; +struct mlx5_data_direct { + struct mlx5_data_direct_dev *dev; + u32 pdn; + u32 mkey; + u32 mkey_ro; + u8 mkey_ro_valid :1; +}; + +static inline struct mlx5_data_direct_dev * +mlx5_data_direct_get_dev(struct mlx5_data_direct *dd) +{ + return dd ? READ_ONCE(dd->dev) : NULL; +} + int mlx5_data_direct_init(struct mlx5_ib_dev *ibdev); void mlx5_data_direct_cleanup(struct mlx5_ib_dev *ibdev); -- cgit v1.2.3 From 00290b9ff59ef47b990d26a6b1a8b2ea6dedf5e9 Mon Sep 17 00:00:00 2001 From: Dragos Tatulea Date: Wed, 30 Sep 2026 14:42:27 +0300 Subject: mlx5: Move data direct implementation to mlx5_core As data direct will also be used by netdev devices, move the data direct code to mlx5_core. Now mlx5_core is responsible for data direct initialization and resource creation. Now data_direct is initialized in mlx5_load() before attaching consumers and clean it up in mlx5_unload() after detaching them. The data direct PCI driver is moved and registered in mlx5_core. IB specific work stays in mlx5_ib: notifier registration, mutex initialization and MR list initialization. Failure to query the VUID is now fatal because this is done only on devices that support data direct. Other than this, this patch has no additional functional changes. Signed-off-by: Dragos Tatulea Link: https://patch.msgid.link/20260930114227.139274-11-tariqt@nvidia.com Signed-off-by: Leon Romanovsky --- include/linux/mlx5/data_direct.h | 23 ++++++++++++++++------- include/linux/mlx5/driver.h | 2 ++ 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'include/linux') diff --git a/include/linux/mlx5/data_direct.h b/include/linux/mlx5/data_direct.h index eaa2dc6bc607..4cff5ff5489d 100644 --- a/include/linux/mlx5/data_direct.h +++ b/include/linux/mlx5/data_direct.h @@ -7,11 +7,23 @@ #define _MLX5_DATA_DIRECT_H #include +#include +struct device; struct mlx5_core_dev; -struct mlx5_data_direct_dev; -struct mlx5_ib_dev; struct notifier_block; +struct pci_dev; + +enum mlx5_data_direct_event { + MLX5_DATA_DIRECT_UNBIND, +}; + +struct mlx5_data_direct_dev { + struct device *device; + struct pci_dev *pdev; + char *vuid; + struct list_head list; +}; struct mlx5_data_direct { struct mlx5_data_direct_dev *dev; @@ -27,12 +39,9 @@ mlx5_data_direct_get_dev(struct mlx5_data_direct *dd) return dd ? READ_ONCE(dd->dev) : NULL; } -int mlx5_data_direct_init(struct mlx5_ib_dev *ibdev); -void mlx5_data_direct_cleanup(struct mlx5_ib_dev *ibdev); - -int mlx5_data_direct_register(struct mlx5_ib_dev *ibdev, +int mlx5_data_direct_register(struct mlx5_core_dev *mdev, struct notifier_block *nb); -void mlx5_data_direct_unregister(struct mlx5_ib_dev *ibdev, +void mlx5_data_direct_unregister(struct mlx5_core_dev *mdev, struct notifier_block *nb); #endif diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h index ee29f95ead18..ed348a82576e 100644 --- a/include/linux/mlx5/driver.h +++ b/include/linux/mlx5/driver.h @@ -707,6 +707,7 @@ struct mlx5_rsvd_gids { struct mlx5_clock; struct mlx5_clock_dev_state; +struct mlx5_data_direct; struct mlx5_dm; struct mlx5_fw_tracer; struct mlx5_vxlan; @@ -801,6 +802,7 @@ struct mlx5_core_dev { /* sync write combining state */ struct mutex wc_state_lock; struct devlink *shd; + struct mlx5_data_direct *data_direct; }; struct mlx5_db { -- cgit v1.2.3