Skip to content

Commit 3c81907

Browse files
yishaihrleon
authored andcommitted
RDMA/mlx5: Add DMAH object support
This patch introduces support for allocating and deallocating the DMAH object. Further details: ---------------- The DMAH API is exposed to upper layers only if the underlying device supports TPH. It uses the mlx5_core steering tag (ST) APIs to get a steering tag index based on the provided input. The obtained index is stored in the device-specific mlx5_dmah structure for future use. Upcoming patches in the series will integrate the allocated DMAH into the memory region (MR) registration process. Signed-off-by: Yishai Hadas <[email protected]> Reviewed-by: Edward Srouji <[email protected]> Link: https://patch.msgid.link/778550776799d82edb4d05da249a1cff00160b50.1752752567.git.leon@kernel.org Signed-off-by: Leon Romanovsky <[email protected]>
1 parent d83edab commit 3c81907

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed

drivers/infiniband/hw/mlx5/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mlx5_ib-y := ah.o \
88
cq.o \
99
data_direct.o \
1010
dm.o \
11+
dmah.o \
1112
doorbell.o \
1213
fs.o \
1314
gsi.o \

drivers/infiniband/hw/mlx5/dmah.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2+
/*
3+
* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved
4+
*/
5+
6+
#include <rdma/uverbs_std_types.h>
7+
#include <linux/pci-tph.h>
8+
#include "dmah.h"
9+
10+
#define UVERBS_MODULE_NAME mlx5_ib
11+
#include <rdma/uverbs_named_ioctl.h>
12+
13+
static int mlx5_ib_alloc_dmah(struct ib_dmah *ibdmah,
14+
struct uverbs_attr_bundle *attrs)
15+
{
16+
struct mlx5_core_dev *mdev = to_mdev(ibdmah->device)->mdev;
17+
struct mlx5_ib_dmah *dmah = to_mdmah(ibdmah);
18+
u16 st_bits = BIT(IB_DMAH_CPU_ID_EXISTS) |
19+
BIT(IB_DMAH_MEM_TYPE_EXISTS);
20+
int err;
21+
22+
/* PH is a must for TPH following PCIe spec 6.2-1.0 */
23+
if (!(ibdmah->valid_fields & BIT(IB_DMAH_PH_EXISTS)))
24+
return -EINVAL;
25+
26+
/* ST is optional; however, partial data for it is not allowed */
27+
if (ibdmah->valid_fields & st_bits) {
28+
if ((ibdmah->valid_fields & st_bits) != st_bits)
29+
return -EINVAL;
30+
err = mlx5_st_alloc_index(mdev, ibdmah->mem_type,
31+
ibdmah->cpu_id, &dmah->st_index);
32+
if (err)
33+
return err;
34+
}
35+
36+
return 0;
37+
}
38+
39+
static int mlx5_ib_dealloc_dmah(struct ib_dmah *ibdmah,
40+
struct uverbs_attr_bundle *attrs)
41+
{
42+
struct mlx5_ib_dmah *dmah = to_mdmah(ibdmah);
43+
struct mlx5_core_dev *mdev = to_mdev(ibdmah->device)->mdev;
44+
45+
if (ibdmah->valid_fields & BIT(IB_DMAH_CPU_ID_EXISTS))
46+
return mlx5_st_dealloc_index(mdev, dmah->st_index);
47+
48+
return 0;
49+
}
50+
51+
const struct ib_device_ops mlx5_ib_dev_dmah_ops = {
52+
.alloc_dmah = mlx5_ib_alloc_dmah,
53+
.dealloc_dmah = mlx5_ib_dealloc_dmah,
54+
};

drivers/infiniband/hw/mlx5/dmah.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2+
/*
3+
* Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved
4+
*/
5+
6+
#ifndef _MLX5_IB_DMAH_H
7+
#define _MLX5_IB_DMAH_H
8+
9+
#include "mlx5_ib.h"
10+
11+
extern const struct ib_device_ops mlx5_ib_dev_dmah_ops;
12+
13+
struct mlx5_ib_dmah {
14+
struct ib_dmah ibdmah;
15+
u16 st_index;
16+
};
17+
18+
static inline struct mlx5_ib_dmah *to_mdmah(struct ib_dmah *ibdmah)
19+
{
20+
return container_of(ibdmah, struct mlx5_ib_dmah, ibdmah);
21+
}
22+
23+
#endif /* _MLX5_IB_DMAH_H */

drivers/infiniband/hw/mlx5/main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <rdma/ib_ucaps.h>
5151
#include "macsec.h"
5252
#include "data_direct.h"
53+
#include "dmah.h"
5354

5455
#define UVERBS_MODULE_NAME mlx5_ib
5556
#include <rdma/uverbs_named_ioctl.h>
@@ -4181,6 +4182,7 @@ static const struct ib_device_ops mlx5_ib_dev_ops = {
41814182
INIT_RDMA_OBJ_SIZE(ib_ah, mlx5_ib_ah, ibah),
41824183
INIT_RDMA_OBJ_SIZE(ib_counters, mlx5_ib_mcounters, ibcntrs),
41834184
INIT_RDMA_OBJ_SIZE(ib_cq, mlx5_ib_cq, ibcq),
4185+
INIT_RDMA_OBJ_SIZE(ib_dmah, mlx5_ib_dmah, ibdmah),
41844186
INIT_RDMA_OBJ_SIZE(ib_pd, mlx5_ib_pd, ibpd),
41854187
INIT_RDMA_OBJ_SIZE(ib_qp, mlx5_ib_qp, ibqp),
41864188
INIT_RDMA_OBJ_SIZE(ib_srq, mlx5_ib_srq, ibsrq),
@@ -4308,6 +4310,9 @@ static int mlx5_ib_stage_caps_init(struct mlx5_ib_dev *dev)
43084310
MLX5_GENERAL_OBJ_TYPES_CAP_SW_ICM)
43094311
ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_dm_ops);
43104312

4313+
if (mdev->st)
4314+
ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_dmah_ops);
4315+
43114316
ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_ops);
43124317

43134318
if (IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS))

0 commit comments

Comments
 (0)