Skip to content

Commit 2019d70

Browse files
paravmellanoxjgunthorpe
authored andcommitted
IB/mlx5: Avoid calling query device for reading pkey table length
Pkey table length for all the ports of the device is the same. Currently get_ports_cap() reads and stores it for each port by querying the device which reads more than just pkey table length. For representor device ports which can be in range of hundreds, it queries is for each such port and end up returning same value for all the ports. When in representor mode, modify QP accesses pkey port caps for a port index that can be outside of the port_caps table. Hence, simplify the logic to query the max pkey table length only once during device initialization sequence. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Parav Pandit <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 3ce60f4 commit 2019d70

File tree

4 files changed

+12
-33
lines changed

4 files changed

+12
-33
lines changed

drivers/infiniband/hw/mlx5/mad.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
549549
props->port_cap_flags = be32_to_cpup((__be32 *)(out_mad->data + 20));
550550
props->gid_tbl_len = out_mad->data[50];
551551
props->max_msg_sz = 1 << MLX5_CAP_GEN(mdev, log_max_msg);
552-
props->pkey_tbl_len = dev->port_caps[port - 1].pkey_table_len;
552+
props->pkey_tbl_len = dev->pkey_table_len;
553553
props->bad_pkey_cntr = be16_to_cpup((__be16 *)(out_mad->data + 46));
554554
props->qkey_viol_cntr = be16_to_cpup((__be16 *)(out_mad->data + 48));
555555
props->active_width = out_mad->data[31] & 0xf;

drivers/infiniband/hw/mlx5/main.c

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -816,9 +816,7 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
816816
if (err)
817817
return err;
818818

819-
err = mlx5_query_max_pkeys(ibdev, &props->max_pkeys);
820-
if (err)
821-
return err;
819+
props->max_pkeys = dev->pkey_table_len;
822820

823821
err = mlx5_query_vendor_id(ibdev, &props->vendor_id);
824822
if (err)
@@ -2979,40 +2977,26 @@ static void get_ext_port_caps(struct mlx5_ib_dev *dev)
29792977

29802978
static int __get_port_caps(struct mlx5_ib_dev *dev, u8 port)
29812979
{
2982-
struct ib_device_attr *dprops = NULL;
29832980
struct ib_port_attr *pprops = NULL;
29842981
int err = -ENOMEM;
29852982

29862983
pprops = kzalloc(sizeof(*pprops), GFP_KERNEL);
29872984
if (!pprops)
29882985
goto out;
29892986

2990-
dprops = kmalloc(sizeof(*dprops), GFP_KERNEL);
2991-
if (!dprops)
2992-
goto out;
2993-
2994-
err = mlx5_ib_query_device(&dev->ib_dev, dprops, NULL);
2995-
if (err) {
2996-
mlx5_ib_warn(dev, "query_device failed %d\n", err);
2997-
goto out;
2998-
}
2999-
30002987
err = mlx5_ib_query_port(&dev->ib_dev, port, pprops);
30012988
if (err) {
30022989
mlx5_ib_warn(dev, "query_port %d failed %d\n",
30032990
port, err);
30042991
goto out;
30052992
}
30062993

3007-
dev->port_caps[port - 1].pkey_table_len = dprops->max_pkeys;
30082994
dev->port_caps[port - 1].gid_table_len = pprops->gid_tbl_len;
30092995
mlx5_ib_dbg(dev, "port %d: pkey_table_len %d, gid_table_len %d\n",
3010-
port, dprops->max_pkeys, pprops->gid_tbl_len);
2996+
port, dev->pkey_table_len, pprops->gid_tbl_len);
30112997

30122998
out:
30132999
kfree(pprops);
3014-
kfree(dprops);
3015-
30163000
return err;
30173001
}
30183002

@@ -3979,6 +3963,10 @@ static int mlx5_ib_stage_init_init(struct mlx5_ib_dev *dev)
39793963
if (err)
39803964
goto err_mp;
39813965

3966+
err = mlx5_query_max_pkeys(&dev->ib_dev, &dev->pkey_table_len);
3967+
if (err)
3968+
goto err_mp;
3969+
39823970
if (mlx5_use_mad_ifc(dev))
39833971
get_ext_port_caps(dev);
39843972

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1038,7 +1038,6 @@ struct mlx5_var_table {
10381038

10391039
struct mlx5_port_caps {
10401040
int gid_table_len;
1041-
int pkey_table_len;
10421041
bool has_smi;
10431042
u8 ext_port_cap;
10441043
};
@@ -1104,6 +1103,7 @@ struct mlx5_ib_dev {
11041103

11051104
struct xarray sig_mrs;
11061105
struct mlx5_port_caps port_caps[MLX5_MAX_PORTS];
1106+
u16 pkey_table_len;
11071107
};
11081108

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

drivers/infiniband/hw/mlx5/qp.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4231,7 +4231,6 @@ int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
42314231
enum ib_qp_type qp_type;
42324232
enum ib_qp_state cur_state, new_state;
42334233
int err = -EINVAL;
4234-
int port;
42354234

42364235
if (!mlx5_ib_modify_qp_allowed(dev, qp, ibqp->qp_type))
42374236
return -EOPNOTSUPP;
@@ -4276,10 +4275,6 @@ int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
42764275
cur_state = attr_mask & IB_QP_CUR_STATE ? attr->cur_qp_state : qp->state;
42774276
new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
42784277

4279-
if (!(cur_state == new_state && cur_state == IB_QPS_RESET)) {
4280-
port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port;
4281-
}
4282-
42834278
if (qp->flags & IB_QP_CREATE_SOURCE_QPN) {
42844279
if (attr_mask & ~(IB_QP_STATE | IB_QP_CUR_STATE)) {
42854280
mlx5_ib_dbg(dev, "invalid attr_mask 0x%x when underlay QP is used\n",
@@ -4308,14 +4303,10 @@ int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
43084303
goto out;
43094304
}
43104305

4311-
if (attr_mask & IB_QP_PKEY_INDEX) {
4312-
port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port;
4313-
if (attr->pkey_index >=
4314-
dev->port_caps[port - 1].pkey_table_len) {
4315-
mlx5_ib_dbg(dev, "invalid pkey index %d\n",
4316-
attr->pkey_index);
4317-
goto out;
4318-
}
4306+
if ((attr_mask & IB_QP_PKEY_INDEX) &&
4307+
attr->pkey_index >= dev->pkey_table_len) {
4308+
mlx5_ib_dbg(dev, "invalid pkey index %d\n", attr->pkey_index);
4309+
goto out;
43194310
}
43204311

43214312
if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&

0 commit comments

Comments
 (0)