Skip to content

Commit 594cac1

Browse files
ohartoovjgunthorpe
authored andcommitted
RDMA/mlx5: Use query_special_contexts for mkeys
Use query_sepcial_contexts to get the correct value of mkeys such as null_mkey, terminate_scatter_list_mkey and dump_fill_mkey, as FW will change them in certain configurations. Link: https://lore.kernel.org/r/000236f0a9487d48809f87bcc3620a3964b2d3d3.1673960981.git.leon@kernel.org Signed-off-by: Or Har-Toov <[email protected]> Reviewed-by: Michael Guralnik <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 1b1e486 commit 594cac1

File tree

7 files changed

+48
-44
lines changed

7 files changed

+48
-44
lines changed

drivers/infiniband/hw/mlx5/cmd.c

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,41 @@
55

66
#include "cmd.h"
77

8-
int mlx5_cmd_dump_fill_mkey(struct mlx5_core_dev *dev, u32 *mkey)
8+
int mlx5r_cmd_query_special_mkeys(struct mlx5_ib_dev *dev)
99
{
1010
u32 out[MLX5_ST_SZ_DW(query_special_contexts_out)] = {};
1111
u32 in[MLX5_ST_SZ_DW(query_special_contexts_in)] = {};
12+
bool is_terminate, is_dump, is_null;
1213
int err;
1314

14-
MLX5_SET(query_special_contexts_in, in, opcode,
15-
MLX5_CMD_OP_QUERY_SPECIAL_CONTEXTS);
16-
err = mlx5_cmd_exec_inout(dev, query_special_contexts, in, out);
17-
if (!err)
18-
*mkey = MLX5_GET(query_special_contexts_out, out,
19-
dump_fill_mkey);
20-
return err;
21-
}
15+
is_terminate = MLX5_CAP_GEN(dev->mdev, terminate_scatter_list_mkey);
16+
is_dump = MLX5_CAP_GEN(dev->mdev, dump_fill_mkey);
17+
is_null = MLX5_CAP_GEN(dev->mdev, null_mkey);
2218

23-
int mlx5_cmd_null_mkey(struct mlx5_core_dev *dev, u32 *null_mkey)
24-
{
25-
u32 out[MLX5_ST_SZ_DW(query_special_contexts_out)] = {};
26-
u32 in[MLX5_ST_SZ_DW(query_special_contexts_in)] = {};
27-
int err;
19+
dev->mkeys.terminate_scatter_list_mkey = MLX5_TERMINATE_SCATTER_LIST_LKEY;
20+
if (!is_terminate && !is_dump && !is_null)
21+
return 0;
2822

2923
MLX5_SET(query_special_contexts_in, in, opcode,
3024
MLX5_CMD_OP_QUERY_SPECIAL_CONTEXTS);
31-
err = mlx5_cmd_exec_inout(dev, query_special_contexts, in, out);
32-
if (!err)
33-
*null_mkey = MLX5_GET(query_special_contexts_out, out,
34-
null_mkey);
35-
return err;
25+
err = mlx5_cmd_exec_inout(dev->mdev, query_special_contexts, in, out);
26+
if (err)
27+
return err;
28+
29+
if (is_dump)
30+
dev->mkeys.dump_fill_mkey = MLX5_GET(query_special_contexts_out,
31+
out, dump_fill_mkey);
32+
33+
if (is_null)
34+
dev->mkeys.null_mkey = cpu_to_be32(
35+
MLX5_GET(query_special_contexts_out, out, null_mkey));
36+
37+
if (is_terminate)
38+
dev->mkeys.terminate_scatter_list_mkey =
39+
cpu_to_be32(MLX5_GET(query_special_contexts_out, out,
40+
terminate_scatter_list_mkey));
41+
42+
return 0;
3643
}
3744

3845
int mlx5_cmd_query_cong_params(struct mlx5_core_dev *dev, int cong_point,

drivers/infiniband/hw/mlx5/cmd.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
#include <linux/kernel.h>
3838
#include <linux/mlx5/driver.h>
3939

40-
int mlx5_cmd_dump_fill_mkey(struct mlx5_core_dev *dev, u32 *mkey);
41-
int mlx5_cmd_null_mkey(struct mlx5_core_dev *dev, u32 *null_mkey);
40+
int mlx5r_cmd_query_special_mkeys(struct mlx5_ib_dev *dev);
4241
int mlx5_cmd_query_cong_params(struct mlx5_core_dev *dev, int cong_point,
4342
void *out);
4443
int mlx5_cmd_dealloc_pd(struct mlx5_core_dev *dev, u32 pdn, u16 uid);

drivers/infiniband/hw/mlx5/main.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,13 +1756,9 @@ static int set_ucontext_resp(struct ib_ucontext *uctx,
17561756
struct mlx5_ib_dev *dev = to_mdev(ibdev);
17571757
struct mlx5_ib_ucontext *context = to_mucontext(uctx);
17581758
struct mlx5_bfreg_info *bfregi = &context->bfregi;
1759-
int err;
17601759

17611760
if (MLX5_CAP_GEN(dev->mdev, dump_fill_mkey)) {
1762-
err = mlx5_cmd_dump_fill_mkey(dev->mdev,
1763-
&resp->dump_fill_mkey);
1764-
if (err)
1765-
return err;
1761+
resp->dump_fill_mkey = dev->mkeys.dump_fill_mkey;
17661762
resp->comp_mask |=
17671763
MLX5_IB_ALLOC_UCONTEXT_RESP_MASK_DUMP_FILL_MKEY;
17681764
}
@@ -3666,6 +3662,10 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
36663662
dev->port[i].roce.last_port_state = IB_PORT_DOWN;
36673663
}
36683664

3665+
err = mlx5r_cmd_query_special_mkeys(dev);
3666+
if (err)
3667+
return err;
3668+
36693669
err = mlx5_ib_init_multiport_master(dev);
36703670
if (err)
36713671
return err;

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,13 @@ struct mlx5_port_caps {
10541054
u8 ext_port_cap;
10551055
};
10561056

1057+
1058+
struct mlx5_special_mkeys {
1059+
u32 dump_fill_mkey;
1060+
__be32 null_mkey;
1061+
__be32 terminate_scatter_list_mkey;
1062+
};
1063+
10571064
struct mlx5_ib_dev {
10581065
struct ib_device ib_dev;
10591066
struct mlx5_core_dev *mdev;
@@ -1084,7 +1091,6 @@ struct mlx5_ib_dev {
10841091

10851092
struct xarray odp_mkeys;
10861093

1087-
u32 null_mkey;
10881094
struct mlx5_ib_flow_db *flow_db;
10891095
/* protect resources needed as part of reset flow */
10901096
spinlock_t reset_flow_resource_lock;
@@ -1113,6 +1119,7 @@ struct mlx5_ib_dev {
11131119
struct mlx5_port_caps port_caps[MLX5_MAX_PORTS];
11141120
u16 pkey_table_len;
11151121
u8 lag_ports;
1122+
struct mlx5_special_mkeys mkeys;
11161123
};
11171124

11181125
static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)

drivers/infiniband/hw/mlx5/odp.c

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ static void populate_klm(struct mlx5_klm *pklm, size_t idx, size_t nentries,
104104
if (flags & MLX5_IB_UPD_XLT_ZAP) {
105105
for (; pklm != end; pklm++, idx++) {
106106
pklm->bcount = cpu_to_be32(MLX5_IMR_MTT_SIZE);
107-
pklm->key = cpu_to_be32(mr_to_mdev(imr)->null_mkey);
107+
pklm->key = mr_to_mdev(imr)->mkeys.null_mkey;
108108
pklm->va = 0;
109109
}
110110
return;
@@ -137,7 +137,7 @@ static void populate_klm(struct mlx5_klm *pklm, size_t idx, size_t nentries,
137137
pklm->key = cpu_to_be32(mtt->ibmr.lkey);
138138
pklm->va = cpu_to_be64(idx * MLX5_IMR_MTT_SIZE);
139139
} else {
140-
pklm->key = cpu_to_be32(mr_to_mdev(imr)->null_mkey);
140+
pklm->key = mr_to_mdev(imr)->mkeys.null_mkey;
141141
pklm->va = 0;
142142
}
143143
}
@@ -1015,7 +1015,8 @@ static int pagefault_data_segments(struct mlx5_ib_dev *dev,
10151015

10161016
/* receive WQE end of sg list. */
10171017
if (receive_queue && bcnt == 0 &&
1018-
key == MLX5_TERMINATE_SCATTER_LIST_LKEY && io_virt == 0)
1018+
key == dev->mkeys.terminate_scatter_list_mkey &&
1019+
io_virt == 0)
10191020
break;
10201021

10211022
if (!inline_segment && total_wqe_bytes) {
@@ -1615,25 +1616,15 @@ static const struct ib_device_ops mlx5_ib_dev_odp_ops = {
16151616

16161617
int mlx5_ib_odp_init_one(struct mlx5_ib_dev *dev)
16171618
{
1618-
int ret = 0;
1619-
16201619
internal_fill_odp_caps(dev);
16211620

16221621
if (!(dev->odp_caps.general_caps & IB_ODP_SUPPORT))
1623-
return ret;
1622+
return 0;
16241623

16251624
ib_set_device_ops(&dev->ib_dev, &mlx5_ib_dev_odp_ops);
16261625

1627-
if (dev->odp_caps.general_caps & IB_ODP_SUPPORT_IMPLICIT) {
1628-
ret = mlx5_cmd_null_mkey(dev->mdev, &dev->null_mkey);
1629-
if (ret) {
1630-
mlx5_ib_err(dev, "Error getting null_mkey %d\n", ret);
1631-
return ret;
1632-
}
1633-
}
1634-
16351626
mutex_init(&dev->odp_eq_mutex);
1636-
return ret;
1627+
return 0;
16371628
}
16381629

16391630
void mlx5_ib_odp_cleanup_one(struct mlx5_ib_dev *dev)

drivers/infiniband/hw/mlx5/srq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
447447

448448
if (i < srq->msrq.max_avail_gather) {
449449
scat[i].byte_count = 0;
450-
scat[i].lkey = MLX5_TERMINATE_SCATTER_LIST_LKEY;
450+
scat[i].lkey = dev->mkeys.terminate_scatter_list_mkey;
451451
scat[i].addr = 0;
452452
}
453453
}

drivers/infiniband/hw/mlx5/wr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ int mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
12521252

12531253
if (i < qp->rq.max_gs) {
12541254
scat[i].byte_count = 0;
1255-
scat[i].lkey = MLX5_TERMINATE_SCATTER_LIST_LKEY;
1255+
scat[i].lkey = dev->mkeys.terminate_scatter_list_mkey;
12561256
scat[i].addr = 0;
12571257
}
12581258

0 commit comments

Comments
 (0)