Skip to content

Commit 494c3b3

Browse files
wangxi11jgunthorpe
authored andcommitted
RDMA/hns: Refactor the QP context filling process related to WQE buffer configure
Split the code related to WQE buffer configure from the QPC filling process into two functions: config_qp_sq_buf() and config_qp_rq_buf(), this will make the code more readable. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Xi Wang <[email protected]> Signed-off-by: Weihang Li <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 13aa13d commit 494c3b3

File tree

1 file changed

+149
-115
lines changed

1 file changed

+149
-115
lines changed

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 149 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -3775,27 +3775,16 @@ static bool check_wqe_rq_mtt_count(struct hns_roce_dev *hr_dev,
37753775
return true;
37763776
}
37773777

3778-
static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
3779-
const struct ib_qp_attr *attr, int attr_mask,
3780-
struct hns_roce_v2_qp_context *context,
3781-
struct hns_roce_v2_qp_context *qpc_mask)
3778+
static int config_qp_rq_buf(struct hns_roce_dev *hr_dev,
3779+
struct hns_roce_qp *hr_qp,
3780+
struct hns_roce_v2_qp_context *context,
3781+
struct hns_roce_v2_qp_context *qpc_mask)
37823782
{
3783-
const struct ib_global_route *grh = rdma_ah_read_grh(&attr->ah_attr);
3784-
struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
3785-
struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
3786-
struct ib_device *ibdev = &hr_dev->ib_dev;
3783+
struct ib_qp *ibqp = &hr_qp->ibqp;
37873784
u64 mtts[MTT_MIN_COUNT] = { 0 };
3788-
dma_addr_t dma_handle_3;
3789-
dma_addr_t dma_handle_2;
37903785
u64 wqe_sge_ba;
37913786
u32 page_size;
3792-
u8 port_num;
3793-
u64 *mtts_3;
3794-
u64 *mtts_2;
37953787
int count;
3796-
u8 *dmac;
3797-
u8 *smac;
3798-
int port;
37993788

38003789
/* Search qp buf's mtts */
38013790
page_size = 1 << hr_qp->mtr.hem_cfg.buf_pg_shift;
@@ -3806,29 +3795,6 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
38063795
if (!check_wqe_rq_mtt_count(hr_dev, hr_qp, count, page_size))
38073796
return -EINVAL;
38083797

3809-
/* Search IRRL's mtts */
3810-
mtts_2 = hns_roce_table_find(hr_dev, &hr_dev->qp_table.irrl_table,
3811-
hr_qp->qpn, &dma_handle_2);
3812-
if (!mtts_2) {
3813-
ibdev_err(ibdev, "failed to find QP irrl_table\n");
3814-
return -EINVAL;
3815-
}
3816-
3817-
/* Search TRRL's mtts */
3818-
mtts_3 = hns_roce_table_find(hr_dev, &hr_dev->qp_table.trrl_table,
3819-
hr_qp->qpn, &dma_handle_3);
3820-
if (!mtts_3) {
3821-
ibdev_err(ibdev, "failed to find QP trrl_table\n");
3822-
return -EINVAL;
3823-
}
3824-
3825-
if (attr_mask & IB_QP_ALT_PATH) {
3826-
ibdev_err(ibdev, "INIT2RTR attr_mask (0x%x) error\n",
3827-
attr_mask);
3828-
return -EINVAL;
3829-
}
3830-
3831-
dmac = (u8 *)attr->ah_attr.roce.dmac;
38323798
context->wqe_sge_ba = cpu_to_le32(wqe_sge_ba >> 3);
38333799
qpc_mask->wqe_sge_ba = 0;
38343800

@@ -3907,23 +3873,154 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
39073873
V2_QPC_BYTE_104_RQ_NXT_BLK_ADDR_M,
39083874
V2_QPC_BYTE_104_RQ_NXT_BLK_ADDR_S, 0);
39093875

3876+
roce_set_field(context->byte_84_rq_ci_pi,
3877+
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_M,
3878+
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_S, hr_qp->rq.head);
3879+
roce_set_field(qpc_mask->byte_84_rq_ci_pi,
3880+
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_M,
3881+
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_S, 0);
3882+
3883+
roce_set_field(qpc_mask->byte_84_rq_ci_pi,
3884+
V2_QPC_BYTE_84_RQ_CONSUMER_IDX_M,
3885+
V2_QPC_BYTE_84_RQ_CONSUMER_IDX_S, 0);
3886+
3887+
return 0;
3888+
}
3889+
3890+
static int config_qp_sq_buf(struct hns_roce_dev *hr_dev,
3891+
struct hns_roce_qp *hr_qp,
3892+
struct hns_roce_v2_qp_context *context,
3893+
struct hns_roce_v2_qp_context *qpc_mask)
3894+
{
3895+
struct ib_device *ibdev = &hr_dev->ib_dev;
3896+
u64 sge_cur_blk = 0;
3897+
u64 sq_cur_blk = 0;
3898+
u32 page_size;
3899+
int count;
3900+
3901+
/* search qp buf's mtts */
3902+
count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr, 0, &sq_cur_blk, 1, NULL);
3903+
if (count < 1) {
3904+
ibdev_err(ibdev, "failed to find QP(0x%lx) SQ buf.\n",
3905+
hr_qp->qpn);
3906+
return -EINVAL;
3907+
}
3908+
if (hr_qp->sge.sge_cnt > 0) {
3909+
page_size = 1 << hr_qp->mtr.hem_cfg.buf_pg_shift;
3910+
count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr,
3911+
hr_qp->sge.offset / page_size,
3912+
&sge_cur_blk, 1, NULL);
3913+
if (count < 1) {
3914+
ibdev_err(ibdev, "failed to find QP(0x%lx) SGE buf.\n",
3915+
hr_qp->qpn);
3916+
return -EINVAL;
3917+
}
3918+
}
3919+
3920+
/*
3921+
* In v2 engine, software pass context and context mask to hardware
3922+
* when modifying qp. If software need modify some fields in context,
3923+
* we should set all bits of the relevant fields in context mask to
3924+
* 0 at the same time, else set them to 0x1.
3925+
*/
3926+
context->sq_cur_blk_addr = cpu_to_le32(to_hr_hw_page_addr(sq_cur_blk));
3927+
roce_set_field(context->byte_168_irrl_idx,
3928+
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_M,
3929+
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_S,
3930+
upper_32_bits(to_hr_hw_page_addr(sq_cur_blk)));
3931+
qpc_mask->sq_cur_blk_addr = 0;
3932+
roce_set_field(qpc_mask->byte_168_irrl_idx,
3933+
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_M,
3934+
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_S, 0);
3935+
3936+
context->sq_cur_sge_blk_addr =
3937+
cpu_to_le32(to_hr_hw_page_addr(sge_cur_blk));
3938+
roce_set_field(context->byte_184_irrl_idx,
3939+
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_M,
3940+
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_S,
3941+
upper_32_bits(to_hr_hw_page_addr(sge_cur_blk)));
3942+
qpc_mask->sq_cur_sge_blk_addr = 0;
3943+
roce_set_field(qpc_mask->byte_184_irrl_idx,
3944+
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_M,
3945+
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_S, 0);
3946+
3947+
context->rx_sq_cur_blk_addr =
3948+
cpu_to_le32(to_hr_hw_page_addr(sq_cur_blk));
3949+
roce_set_field(context->byte_232_irrl_sge,
3950+
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_M,
3951+
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_S,
3952+
upper_32_bits(to_hr_hw_page_addr(sq_cur_blk)));
3953+
qpc_mask->rx_sq_cur_blk_addr = 0;
3954+
roce_set_field(qpc_mask->byte_232_irrl_sge,
3955+
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_M,
3956+
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_S, 0);
3957+
3958+
return 0;
3959+
}
3960+
3961+
static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
3962+
const struct ib_qp_attr *attr, int attr_mask,
3963+
struct hns_roce_v2_qp_context *context,
3964+
struct hns_roce_v2_qp_context *qpc_mask)
3965+
{
3966+
const struct ib_global_route *grh = rdma_ah_read_grh(&attr->ah_attr);
3967+
struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
3968+
struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
3969+
struct ib_device *ibdev = &hr_dev->ib_dev;
3970+
dma_addr_t trrl_ba;
3971+
dma_addr_t irrl_ba;
3972+
u8 port_num;
3973+
u64 *mtts;
3974+
u8 *dmac;
3975+
u8 *smac;
3976+
int port;
3977+
int ret;
3978+
3979+
ret = config_qp_rq_buf(hr_dev, hr_qp, context, qpc_mask);
3980+
if (ret) {
3981+
ibdev_err(ibdev, "failed to config rq buf, ret = %d.\n", ret);
3982+
return ret;
3983+
}
3984+
3985+
/* Search IRRL's mtts */
3986+
mtts = hns_roce_table_find(hr_dev, &hr_dev->qp_table.irrl_table,
3987+
hr_qp->qpn, &irrl_ba);
3988+
if (!mtts) {
3989+
ibdev_err(ibdev, "failed to find qp irrl_table.\n");
3990+
return -EINVAL;
3991+
}
3992+
3993+
/* Search TRRL's mtts */
3994+
mtts = hns_roce_table_find(hr_dev, &hr_dev->qp_table.trrl_table,
3995+
hr_qp->qpn, &trrl_ba);
3996+
if (!mtts) {
3997+
ibdev_err(ibdev, "failed to find qp trrl_table.\n");
3998+
return -EINVAL;
3999+
}
4000+
4001+
if (attr_mask & IB_QP_ALT_PATH) {
4002+
ibdev_err(ibdev, "INIT2RTR attr_mask (0x%x) error.\n",
4003+
attr_mask);
4004+
return -EINVAL;
4005+
}
4006+
39104007
roce_set_field(context->byte_132_trrl, V2_QPC_BYTE_132_TRRL_BA_M,
3911-
V2_QPC_BYTE_132_TRRL_BA_S, dma_handle_3 >> 4);
4008+
V2_QPC_BYTE_132_TRRL_BA_S, trrl_ba >> 4);
39124009
roce_set_field(qpc_mask->byte_132_trrl, V2_QPC_BYTE_132_TRRL_BA_M,
39134010
V2_QPC_BYTE_132_TRRL_BA_S, 0);
3914-
context->trrl_ba = cpu_to_le32(dma_handle_3 >> (16 + 4));
4011+
context->trrl_ba = cpu_to_le32(trrl_ba >> (16 + 4));
39154012
qpc_mask->trrl_ba = 0;
39164013
roce_set_field(context->byte_140_raq, V2_QPC_BYTE_140_TRRL_BA_M,
39174014
V2_QPC_BYTE_140_TRRL_BA_S,
3918-
(u32)(dma_handle_3 >> (32 + 16 + 4)));
4015+
(u32)(trrl_ba >> (32 + 16 + 4)));
39194016
roce_set_field(qpc_mask->byte_140_raq, V2_QPC_BYTE_140_TRRL_BA_M,
39204017
V2_QPC_BYTE_140_TRRL_BA_S, 0);
39214018

3922-
context->irrl_ba = cpu_to_le32(dma_handle_2 >> 6);
4019+
context->irrl_ba = cpu_to_le32(irrl_ba >> 6);
39234020
qpc_mask->irrl_ba = 0;
39244021
roce_set_field(context->byte_208_irrl, V2_QPC_BYTE_208_IRRL_BA_M,
39254022
V2_QPC_BYTE_208_IRRL_BA_S,
3926-
dma_handle_2 >> (32 + 6));
4023+
irrl_ba >> (32 + 6));
39274024
roce_set_field(qpc_mask->byte_208_irrl, V2_QPC_BYTE_208_IRRL_BA_M,
39284025
V2_QPC_BYTE_208_IRRL_BA_S, 0);
39294026

@@ -3960,6 +4057,8 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
39604057
grh->sgid_index));
39614058
roce_set_field(qpc_mask->byte_20_smac_sgid_idx,
39624059
V2_QPC_BYTE_20_SGID_IDX_M, V2_QPC_BYTE_20_SGID_IDX_S, 0);
4060+
4061+
dmac = (u8 *)attr->ah_attr.roce.dmac;
39634062
memcpy(&(context->dmac), dmac, sizeof(u32));
39644063
roce_set_field(context->byte_52_udpspn_dmac, V2_QPC_BYTE_52_DMAC_M,
39654064
V2_QPC_BYTE_52_DMAC_S, *((u16 *)(&dmac[4])));
@@ -3984,16 +4083,6 @@ static int modify_qp_init_to_rtr(struct ib_qp *ibqp,
39844083
roce_set_field(qpc_mask->byte_24_mtu_tc, V2_QPC_BYTE_24_MTU_M,
39854084
V2_QPC_BYTE_24_MTU_S, 0);
39864085

3987-
roce_set_field(context->byte_84_rq_ci_pi,
3988-
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_M,
3989-
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_S, hr_qp->rq.head);
3990-
roce_set_field(qpc_mask->byte_84_rq_ci_pi,
3991-
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_M,
3992-
V2_QPC_BYTE_84_RQ_PRODUCER_IDX_S, 0);
3993-
3994-
roce_set_field(qpc_mask->byte_84_rq_ci_pi,
3995-
V2_QPC_BYTE_84_RQ_CONSUMER_IDX_M,
3996-
V2_QPC_BYTE_84_RQ_CONSUMER_IDX_S, 0);
39974086
roce_set_bit(qpc_mask->byte_108_rx_reqepsn,
39984087
V2_QPC_BYTE_108_RX_REQ_PSN_ERR_S, 0);
39994088
roce_set_field(qpc_mask->byte_96_rx_reqmsn, V2_QPC_BYTE_96_RX_REQ_MSN_M,
@@ -4029,74 +4118,19 @@ static int modify_qp_rtr_to_rts(struct ib_qp *ibqp,
40294118
struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
40304119
struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
40314120
struct ib_device *ibdev = &hr_dev->ib_dev;
4032-
u64 sge_cur_blk = 0;
4033-
u64 sq_cur_blk = 0;
4034-
u32 page_size;
4035-
int count;
4036-
4037-
/* Search qp buf's mtts */
4038-
count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr, 0, &sq_cur_blk, 1, NULL);
4039-
if (count < 1) {
4040-
ibdev_err(ibdev, "failed to find QP(0x%lx) SQ buf\n",
4041-
hr_qp->qpn);
4042-
return -EINVAL;
4043-
}
4044-
4045-
if (hr_qp->sge.sge_cnt > 0) {
4046-
page_size = 1 << hr_qp->mtr.hem_cfg.buf_pg_shift;
4047-
count = hns_roce_mtr_find(hr_dev, &hr_qp->mtr,
4048-
hr_qp->sge.offset / page_size,
4049-
&sge_cur_blk, 1, NULL);
4050-
if (count < 1) {
4051-
ibdev_err(ibdev, "failed to find QP(0x%lx) SGE buf\n",
4052-
hr_qp->qpn);
4053-
return -EINVAL;
4054-
}
4055-
}
4121+
int ret;
40564122

40574123
/* Not support alternate path and path migration */
40584124
if (attr_mask & (IB_QP_ALT_PATH | IB_QP_PATH_MIG_STATE)) {
40594125
ibdev_err(ibdev, "RTR2RTS attr_mask (0x%x)error\n", attr_mask);
40604126
return -EINVAL;
40614127
}
40624128

4063-
/*
4064-
* In v2 engine, software pass context and context mask to hardware
4065-
* when modifying qp. If software need modify some fields in context,
4066-
* we should set all bits of the relevant fields in context mask to
4067-
* 0 at the same time, else set them to 0x1.
4068-
*/
4069-
context->sq_cur_blk_addr = cpu_to_le32(to_hr_hw_page_addr(sq_cur_blk));
4070-
roce_set_field(context->byte_168_irrl_idx,
4071-
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_M,
4072-
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_S,
4073-
upper_32_bits(to_hr_hw_page_addr(sq_cur_blk)));
4074-
qpc_mask->sq_cur_blk_addr = 0;
4075-
roce_set_field(qpc_mask->byte_168_irrl_idx,
4076-
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_M,
4077-
V2_QPC_BYTE_168_SQ_CUR_BLK_ADDR_S, 0);
4078-
4079-
context->sq_cur_sge_blk_addr =
4080-
cpu_to_le32(to_hr_hw_page_addr(sge_cur_blk));
4081-
roce_set_field(context->byte_184_irrl_idx,
4082-
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_M,
4083-
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_S,
4084-
upper_32_bits(to_hr_hw_page_addr(sge_cur_blk)));
4085-
qpc_mask->sq_cur_sge_blk_addr = 0;
4086-
roce_set_field(qpc_mask->byte_184_irrl_idx,
4087-
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_M,
4088-
V2_QPC_BYTE_184_SQ_CUR_SGE_BLK_ADDR_S, 0);
4089-
4090-
context->rx_sq_cur_blk_addr =
4091-
cpu_to_le32(to_hr_hw_page_addr(sq_cur_blk));
4092-
roce_set_field(context->byte_232_irrl_sge,
4093-
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_M,
4094-
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_S,
4095-
upper_32_bits(to_hr_hw_page_addr(sq_cur_blk)));
4096-
qpc_mask->rx_sq_cur_blk_addr = 0;
4097-
roce_set_field(qpc_mask->byte_232_irrl_sge,
4098-
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_M,
4099-
V2_QPC_BYTE_232_RX_SQ_CUR_BLK_ADDR_S, 0);
4129+
ret = config_qp_sq_buf(hr_dev, hr_qp, context, qpc_mask);
4130+
if (ret) {
4131+
ibdev_err(ibdev, "failed to config sq buf, ret %d\n", ret);
4132+
return ret;
4133+
}
41004134

41014135
/*
41024136
* Set some fields in context to zero, Because the default values

0 commit comments

Comments
 (0)