]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
RDMA/mlx5: Add support for TLP VAR allocation
authorMaher Sanalla <msanalla@nvidia.com>
Wed, 25 Feb 2026 14:19:35 +0000 (16:19 +0200)
committerLeon Romanovsky <leonro@nvidia.com>
Thu, 5 Mar 2026 10:42:01 +0000 (05:42 -0500)
Extend the VAR allocation UAPI to accept an optional flags attribute,
allowing userspace to request TLP VAR allocation via the
MLX5_IB_UAPI_VAR_ALLOC_FLAG_TLP flag.

When the TLP flag "MLX5_IB_UAPI_VAR_ALLOC_FLAG_TLP" is specified,
the driver selects the TLP VAR region for allocation instead of the
regular VirtIO VAR region.

Signed-off-by: Maher Sanalla <msanalla@nvidia.com>
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
drivers/infiniband/hw/mlx5/main.c
include/uapi/rdma/mlx5_user_ioctl_cmds.h
include/uapi/rdma/mlx5_user_ioctl_verbs.h

index 64708a97f26c2e1ee3acc6b03926f62b53804afe..ff2c02c85625ceb5486a46fb8073662c0e21345f 100644 (file)
@@ -4151,7 +4151,7 @@ static int mlx5_rdma_user_mmap_entry_insert(struct mlx5_ib_ucontext *c,
 }
 
 static struct mlx5_user_mmap_entry *
-alloc_var_entry(struct mlx5_ib_ucontext *c)
+alloc_var_entry(struct mlx5_ib_ucontext *c, u32 flags)
 {
        struct mlx5_user_mmap_entry *entry;
        struct mlx5_var_region *var_region;
@@ -4160,7 +4160,11 @@ alloc_var_entry(struct mlx5_ib_ucontext *c)
        int err;
 
        var_table = &to_mdev(c->ibucontext.device)->var_table;
-       var_region = &var_table->var_region;
+       if (flags & MLX5_IB_UAPI_VAR_ALLOC_FLAG_TLP)
+               var_region = &var_table->tlp_var_region;
+       else
+               var_region = &var_table->var_region;
+
        entry = kzalloc_obj(*entry);
        if (!entry)
                return ERR_PTR(-ENOMEM);
@@ -4180,7 +4184,9 @@ alloc_var_entry(struct mlx5_ib_ucontext *c)
        entry->address = var_region->hw_start_addr +
                                (page_idx * var_region->stride_size);
        entry->page_idx = page_idx;
-       entry->mmap_flag = MLX5_IB_MMAP_TYPE_VAR;
+       entry->mmap_flag = flags & MLX5_IB_UAPI_VAR_ALLOC_FLAG_TLP ?
+                                  MLX5_IB_MMAP_TYPE_TLP_VAR :
+                                  MLX5_IB_MMAP_TYPE_VAR;
 
        err = mlx5_rdma_user_mmap_entry_insert(c, entry,
                                               var_region->stride_size);
@@ -4203,9 +4209,10 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_VAR_OBJ_ALLOC)(
 {
        struct ib_uobject *uobj = uverbs_attr_get_uobject(
                attrs, MLX5_IB_ATTR_VAR_OBJ_ALLOC_HANDLE);
-       struct mlx5_ib_ucontext *c;
        struct mlx5_user_mmap_entry *entry;
+       struct mlx5_ib_ucontext *c;
        u64 mmap_offset;
+       u32 flags = 0;
        u32 length;
        int err;
 
@@ -4213,7 +4220,24 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_VAR_OBJ_ALLOC)(
        if (IS_ERR(c))
                return PTR_ERR(c);
 
-       entry = alloc_var_entry(c);
+       err = uverbs_get_flags32(&flags, attrs,
+                                MLX5_IB_ATTR_VAR_OBJ_ALLOC_FLAGS,
+                                MLX5_IB_UAPI_VAR_ALLOC_FLAG_TLP);
+       if (err)
+               return err;
+
+       if (flags & MLX5_IB_UAPI_VAR_ALLOC_FLAG_TLP) {
+               if (!MLX5_CAP_GEN(to_mdev(c->ibucontext.device)->mdev,
+                                 tlp_device_emulation_manager))
+                       return -EOPNOTSUPP;
+       } else {
+               if (!(MLX5_CAP_GEN_64(to_mdev(c->ibucontext.device)->mdev,
+                                     general_obj_types) &
+                     MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q))
+                       return -EOPNOTSUPP;
+       }
+
+       entry = alloc_var_entry(c, flags);
        if (IS_ERR(entry))
                return PTR_ERR(entry);
 
@@ -4243,6 +4267,9 @@ DECLARE_UVERBS_NAMED_METHOD(
                        MLX5_IB_OBJECT_VAR,
                        UVERBS_ACCESS_NEW,
                        UA_MANDATORY),
+       UVERBS_ATTR_FLAGS_IN(MLX5_IB_ATTR_VAR_OBJ_ALLOC_FLAGS,
+                            enum mlx5_ib_uapi_var_alloc_flags,
+                            UA_OPTIONAL),
        UVERBS_ATTR_PTR_OUT(MLX5_IB_ATTR_VAR_OBJ_ALLOC_PAGE_ID,
                           UVERBS_ATTR_TYPE(u32),
                           UA_MANDATORY),
@@ -4270,7 +4297,8 @@ static bool var_is_supported(struct ib_device *device)
        struct mlx5_ib_dev *dev = to_mdev(device);
 
        return (MLX5_CAP_GEN_64(dev->mdev, general_obj_types) &
-                       MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q);
+                       MLX5_GENERAL_OBJ_TYPES_CAP_VIRTIO_NET_Q) ||
+               MLX5_CAP_GEN(dev->mdev, tlp_device_emulation_manager);
 }
 
 static struct mlx5_user_mmap_entry *
index 18f9fe07021325109a7a86f130d469a90fc109cc..01a2a050e4689f31024ba7df75de86072c2b97af 100644 (file)
@@ -139,6 +139,7 @@ enum mlx5_ib_var_alloc_attrs {
        MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_OFFSET,
        MLX5_IB_ATTR_VAR_OBJ_ALLOC_MMAP_LENGTH,
        MLX5_IB_ATTR_VAR_OBJ_ALLOC_PAGE_ID,
+       MLX5_IB_ATTR_VAR_OBJ_ALLOC_FLAGS,
 };
 
 enum mlx5_ib_var_obj_destroy_attrs {
index 8f86e79d78a5fa0f35ae829ef2547ede06c5b8df..ef295b38a1cfb371922eb99ffb6c44886fb4f7be 100644 (file)
@@ -100,6 +100,10 @@ enum mlx5_ib_uapi_query_port_flags {
        MLX5_IB_UAPI_QUERY_PORT_ESW_OWNER_VHCA_ID       = 1 << 5,
 };
 
+enum mlx5_ib_uapi_var_alloc_flags {
+       MLX5_IB_UAPI_VAR_ALLOC_FLAG_TLP = 1 << 0,
+};
+
 struct mlx5_ib_uapi_reg {
        __u32 value;
        __u32 mask;