Skip to content

Commit 61147f3

Browse files
BodongWangjgunthorpe
authored andcommitted
IB/mlx5: Packet packing enhancement for RAW QP
Enable RAW QP to be able to configure burst control by modify_qp. By using burst control with rate limiting, user can achieve best performance and accuracy. The burst control information is passed by user through udata. This patch also reports burst control capability for mlx5 related hardwares, burst control is only marked as supported when both packet_pacing_burst_bound and packet_pacing_typical_size are supported. Signed-off-by: Bodong Wang <[email protected]> Reviewed-by: Daniel Jurgens <[email protected]> Reviewed-by: Yishai Hadas <[email protected]> Signed-off-by: Leon Romanovsky <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 05d3ac9 commit 61147f3

File tree

4 files changed

+98
-21
lines changed

4 files changed

+98
-21
lines changed

drivers/infiniband/hw/mlx5/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,10 @@ static int mlx5_ib_query_device(struct ib_device *ibdev,
989989
MLX5_CAP_QOS(mdev, packet_pacing_min_rate);
990990
resp.packet_pacing_caps.supported_qpts |=
991991
1 << IB_QPT_RAW_PACKET;
992+
if (MLX5_CAP_QOS(mdev, packet_pacing_burst_bound) &&
993+
MLX5_CAP_QOS(mdev, packet_pacing_typical_size))
994+
resp.packet_pacing_caps.cap_flags |=
995+
MLX5_IB_PP_SUPPORT_BURST;
992996
}
993997
resp.response_length += sizeof(resp.packet_pacing_caps);
994998
}

drivers/infiniband/hw/mlx5/mlx5_ib.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ struct mlx5_ib_qp {
403403
struct list_head qps_list;
404404
struct list_head cq_recv_list;
405405
struct list_head cq_send_list;
406-
u32 rate_limit;
406+
struct mlx5_rate_limit rl;
407407
u32 underlay_qpn;
408408
bool tunnel_offload_en;
409409
/* storage for qp sub type when core qp type is IB_QPT_DRIVER */

drivers/infiniband/hw/mlx5/qp.c

Lines changed: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ struct mlx5_modify_raw_qp_param {
8686
u16 operation;
8787

8888
u32 set_mask; /* raw_qp_set_mask_map */
89-
u32 rate_limit;
89+
90+
struct mlx5_rate_limit rl;
91+
9092
u8 rq_q_ctr_id;
9193
};
9294

@@ -2774,8 +2776,9 @@ static int modify_raw_packet_qp_sq(struct mlx5_core_dev *dev,
27742776
const struct mlx5_modify_raw_qp_param *raw_qp_param)
27752777
{
27762778
struct mlx5_ib_qp *ibqp = sq->base.container_mibqp;
2777-
u32 old_rate = ibqp->rate_limit;
2778-
u32 new_rate = old_rate;
2779+
struct mlx5_rate_limit old_rl = ibqp->rl;
2780+
struct mlx5_rate_limit new_rl = old_rl;
2781+
bool new_rate_added = false;
27792782
u16 rl_index = 0;
27802783
void *in;
27812784
void *sqc;
@@ -2797,39 +2800,43 @@ static int modify_raw_packet_qp_sq(struct mlx5_core_dev *dev,
27972800
pr_warn("%s: Rate limit can only be changed when SQ is moving to RDY\n",
27982801
__func__);
27992802
else
2800-
new_rate = raw_qp_param->rate_limit;
2803+
new_rl = raw_qp_param->rl;
28012804
}
28022805

2803-
if (old_rate != new_rate) {
2804-
if (new_rate) {
2805-
err = mlx5_rl_add_rate(dev, new_rate, &rl_index);
2806+
if (!mlx5_rl_are_equal(&old_rl, &new_rl)) {
2807+
if (new_rl.rate) {
2808+
err = mlx5_rl_add_rate(dev, &rl_index, &new_rl);
28062809
if (err) {
2807-
pr_err("Failed configuring rate %u: %d\n",
2808-
new_rate, err);
2810+
pr_err("Failed configuring rate limit(err %d): \
2811+
rate %u, max_burst_sz %u, typical_pkt_sz %u\n",
2812+
err, new_rl.rate, new_rl.max_burst_sz,
2813+
new_rl.typical_pkt_sz);
2814+
28092815
goto out;
28102816
}
2817+
new_rate_added = true;
28112818
}
28122819

28132820
MLX5_SET64(modify_sq_in, in, modify_bitmask, 1);
2821+
/* index 0 means no limit */
28142822
MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index);
28152823
}
28162824

28172825
err = mlx5_core_modify_sq(dev, sq->base.mqp.qpn, in, inlen);
28182826
if (err) {
28192827
/* Remove new rate from table if failed */
2820-
if (new_rate &&
2821-
old_rate != new_rate)
2822-
mlx5_rl_remove_rate(dev, new_rate);
2828+
if (new_rate_added)
2829+
mlx5_rl_remove_rate(dev, &new_rl);
28232830
goto out;
28242831
}
28252832

28262833
/* Only remove the old rate after new rate was set */
2827-
if ((old_rate &&
2828-
(old_rate != new_rate)) ||
2834+
if ((old_rl.rate &&
2835+
!mlx5_rl_are_equal(&old_rl, &new_rl)) ||
28292836
(new_state != MLX5_SQC_STATE_RDY))
2830-
mlx5_rl_remove_rate(dev, old_rate);
2837+
mlx5_rl_remove_rate(dev, &old_rl);
28312838

2832-
ibqp->rate_limit = new_rate;
2839+
ibqp->rl = new_rl;
28332840
sq->state = new_state;
28342841

28352842
out:
@@ -2906,7 +2913,8 @@ static int modify_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp,
29062913

29072914
static int __mlx5_ib_modify_qp(struct ib_qp *ibqp,
29082915
const struct ib_qp_attr *attr, int attr_mask,
2909-
enum ib_qp_state cur_state, enum ib_qp_state new_state)
2916+
enum ib_qp_state cur_state, enum ib_qp_state new_state,
2917+
const struct mlx5_ib_modify_qp *ucmd)
29102918
{
29112919
static const u16 optab[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE] = {
29122920
[MLX5_QP_STATE_RST] = {
@@ -3144,7 +3152,30 @@ static int __mlx5_ib_modify_qp(struct ib_qp *ibqp,
31443152
}
31453153

31463154
if (attr_mask & IB_QP_RATE_LIMIT) {
3147-
raw_qp_param.rate_limit = attr->rate_limit;
3155+
raw_qp_param.rl.rate = attr->rate_limit;
3156+
3157+
if (ucmd->burst_info.max_burst_sz) {
3158+
if (attr->rate_limit &&
3159+
MLX5_CAP_QOS(dev->mdev, packet_pacing_burst_bound)) {
3160+
raw_qp_param.rl.max_burst_sz =
3161+
ucmd->burst_info.max_burst_sz;
3162+
} else {
3163+
err = -EINVAL;
3164+
goto out;
3165+
}
3166+
}
3167+
3168+
if (ucmd->burst_info.typical_pkt_sz) {
3169+
if (attr->rate_limit &&
3170+
MLX5_CAP_QOS(dev->mdev, packet_pacing_typical_size)) {
3171+
raw_qp_param.rl.typical_pkt_sz =
3172+
ucmd->burst_info.typical_pkt_sz;
3173+
} else {
3174+
err = -EINVAL;
3175+
goto out;
3176+
}
3177+
}
3178+
31483179
raw_qp_param.set_mask |= MLX5_RAW_QP_RATE_LIMIT;
31493180
}
31503181

@@ -3332,15 +3363,39 @@ int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
33323363
{
33333364
struct mlx5_ib_dev *dev = to_mdev(ibqp->device);
33343365
struct mlx5_ib_qp *qp = to_mqp(ibqp);
3366+
struct mlx5_ib_modify_qp ucmd = {};
33353367
enum ib_qp_type qp_type;
33363368
enum ib_qp_state cur_state, new_state;
3369+
size_t required_cmd_sz;
33373370
int err = -EINVAL;
33383371
int port;
33393372
enum rdma_link_layer ll = IB_LINK_LAYER_UNSPECIFIED;
33403373

33413374
if (ibqp->rwq_ind_tbl)
33423375
return -ENOSYS;
33433376

3377+
if (udata && udata->inlen) {
3378+
required_cmd_sz = offsetof(typeof(ucmd), reserved) +
3379+
sizeof(ucmd.reserved);
3380+
if (udata->inlen < required_cmd_sz)
3381+
return -EINVAL;
3382+
3383+
if (udata->inlen > sizeof(ucmd) &&
3384+
!ib_is_udata_cleared(udata, sizeof(ucmd),
3385+
udata->inlen - sizeof(ucmd)))
3386+
return -EOPNOTSUPP;
3387+
3388+
if (ib_copy_from_udata(&ucmd, udata,
3389+
min(udata->inlen, sizeof(ucmd))))
3390+
return -EFAULT;
3391+
3392+
if (ucmd.comp_mask ||
3393+
memchr_inv(&ucmd.reserved, 0, sizeof(ucmd.reserved)) ||
3394+
memchr_inv(&ucmd.burst_info.reserved, 0,
3395+
sizeof(ucmd.burst_info.reserved)))
3396+
return -EOPNOTSUPP;
3397+
}
3398+
33443399
if (unlikely(ibqp->qp_type == IB_QPT_GSI))
33453400
return mlx5_ib_gsi_modify_qp(ibqp, attr, attr_mask);
33463401

@@ -3421,7 +3476,8 @@ int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
34213476
goto out;
34223477
}
34233478

3424-
err = __mlx5_ib_modify_qp(ibqp, attr, attr_mask, cur_state, new_state);
3479+
err = __mlx5_ib_modify_qp(ibqp, attr, attr_mask, cur_state,
3480+
new_state, &ucmd);
34253481

34263482
out:
34273483
mutex_unlock(&qp->mutex);

include/uapi/rdma/mlx5-abi.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ struct mlx5_ib_cqe_comp_caps {
163163
__u32 supported_format; /* enum mlx5_ib_cqe_comp_res_format */
164164
};
165165

166+
enum mlx5_ib_packet_pacing_cap_flags {
167+
MLX5_IB_PP_SUPPORT_BURST = 1 << 0,
168+
};
169+
166170
struct mlx5_packet_pacing_caps {
167171
__u32 qp_rate_limit_min;
168172
__u32 qp_rate_limit_max; /* In kpbs */
@@ -172,7 +176,8 @@ struct mlx5_packet_pacing_caps {
172176
* supported_qpts |= 1 << IB_QPT_RAW_PACKET
173177
*/
174178
__u32 supported_qpts;
175-
__u32 reserved;
179+
__u8 cap_flags; /* enum mlx5_ib_packet_pacing_cap_flags */
180+
__u8 reserved[3];
176181
};
177182

178183
enum mlx5_ib_mpw_caps {
@@ -362,6 +367,18 @@ struct mlx5_ib_create_ah_resp {
362367
__u8 reserved[6];
363368
};
364369

370+
struct mlx5_ib_burst_info {
371+
__u32 max_burst_sz;
372+
__u16 typical_pkt_sz;
373+
__u16 reserved;
374+
};
375+
376+
struct mlx5_ib_modify_qp {
377+
__u32 comp_mask;
378+
struct mlx5_ib_burst_info burst_info;
379+
__u32 reserved;
380+
};
381+
365382
struct mlx5_ib_modify_qp_resp {
366383
__u32 response_length;
367384
__u32 dctn;

0 commit comments

Comments
 (0)