Skip to content

Commit cdc1f3e

Browse files
Weihang Lijgunthorpe
authored andcommitted
RDMA/hns: Refactor hns_roce_v2_set_hem()
The parts about preparing and sending mailbox to hardware is not strongly related to other codes in hns_roce_v2_set_hem(), and can be encapsulated into a separate function. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Weihang Li <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 57005c9 commit cdc1f3e

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

drivers/infiniband/hw/hns/hns_roce_hw_v2.c

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3373,11 +3373,33 @@ static int get_op_for_set_hem(struct hns_roce_dev *hr_dev, u32 type,
33733373
return op + step_idx;
33743374
}
33753375

3376+
static int set_hem_to_hw(struct hns_roce_dev *hr_dev, int obj, u64 bt_ba,
3377+
u32 hem_type, int step_idx)
3378+
{
3379+
struct hns_roce_cmd_mailbox *mailbox;
3380+
int ret;
3381+
int op;
3382+
3383+
op = get_op_for_set_hem(hr_dev, hem_type, step_idx);
3384+
if (op < 0)
3385+
return 0;
3386+
3387+
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
3388+
if (IS_ERR(mailbox))
3389+
return PTR_ERR(mailbox);
3390+
3391+
ret = hns_roce_cmd_mbox(hr_dev, bt_ba, mailbox->dma, obj,
3392+
0, op, HNS_ROCE_CMD_TIMEOUT_MSECS);
3393+
3394+
hns_roce_free_cmd_mailbox(hr_dev, mailbox);
3395+
3396+
return ret;
3397+
}
3398+
33763399
static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev,
33773400
struct hns_roce_hem_table *table, int obj,
33783401
int step_idx)
33793402
{
3380-
struct hns_roce_cmd_mailbox *mailbox;
33813403
struct hns_roce_hem_iter iter;
33823404
struct hns_roce_hem_mhop mhop;
33833405
struct hns_roce_hem *hem;
@@ -3389,7 +3411,6 @@ static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev,
33893411
u64 bt_ba = 0;
33903412
u32 chunk_ba_num;
33913413
u32 hop_num;
3392-
int op;
33933414

33943415
if (!hns_roce_check_whether_mhop(hr_dev, table->type))
33953416
return 0;
@@ -3411,14 +3432,6 @@ static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev,
34113432
hem_idx = i;
34123433
}
34133434

3414-
op = get_op_for_set_hem(hr_dev, table->type, step_idx);
3415-
if (op == -EINVAL)
3416-
return 0;
3417-
3418-
mailbox = hns_roce_alloc_cmd_mailbox(hr_dev);
3419-
if (IS_ERR(mailbox))
3420-
return PTR_ERR(mailbox);
3421-
34223435
if (table->type == HEM_TYPE_SCCC)
34233436
obj = mhop.l0_idx;
34243437

@@ -3427,24 +3440,18 @@ static int hns_roce_v2_set_hem(struct hns_roce_dev *hr_dev,
34273440
for (hns_roce_hem_first(hem, &iter);
34283441
!hns_roce_hem_last(&iter); hns_roce_hem_next(&iter)) {
34293442
bt_ba = hns_roce_hem_addr(&iter);
3430-
3431-
/* configure the ba, tag, and op */
3432-
ret = hns_roce_cmd_mbox(hr_dev, bt_ba, mailbox->dma,
3433-
obj, 0, op,
3434-
HNS_ROCE_CMD_TIMEOUT_MSECS);
3443+
ret = set_hem_to_hw(hr_dev, obj, bt_ba, table->type,
3444+
step_idx);
34353445
}
34363446
} else {
34373447
if (step_idx == 0)
34383448
bt_ba = table->bt_l0_dma_addr[i];
34393449
else if (step_idx == 1 && hop_num == 2)
34403450
bt_ba = table->bt_l1_dma_addr[l1_idx];
34413451

3442-
/* configure the ba, tag, and op */
3443-
ret = hns_roce_cmd_mbox(hr_dev, bt_ba, mailbox->dma, obj,
3444-
0, op, HNS_ROCE_CMD_TIMEOUT_MSECS);
3452+
ret = set_hem_to_hw(hr_dev, obj, bt_ba, table->type, step_idx);
34453453
}
34463454

3447-
hns_roce_free_cmd_mailbox(hr_dev, mailbox);
34483455
return ret;
34493456
}
34503457

0 commit comments

Comments
 (0)