Skip to content

Commit c4f11b3

Browse files
l00436852jgunthorpe
authored andcommitted
RDMA/hns: Use IDA interface to manage srq index
Switch srq index allocation and release from hns' own bitmap interface to IDA interface. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Yangyang Li <[email protected]> Signed-off-by: Wenpeng Liang <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 8feafd9 commit c4f11b3

File tree

4 files changed

+18
-34
lines changed

4 files changed

+18
-34
lines changed

drivers/infiniband/hw/hns/hns_roce_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ void hns_roce_cleanup_bitmap(struct hns_roce_dev *hr_dev)
248248
ida_destroy(&hr_dev->xrcd_ida.ida);
249249

250250
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SRQ)
251-
hns_roce_cleanup_srq_table(hr_dev);
251+
ida_destroy(&hr_dev->srq_table.srq_ida.ida);
252252
hns_roce_cleanup_qp_table(hr_dev);
253253
hns_roce_cleanup_cq_table(hr_dev);
254254
ida_destroy(&hr_dev->mr_table.mtpt_ida.ida);

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ struct hns_roce_cq_table {
514514
};
515515

516516
struct hns_roce_srq_table {
517-
struct hns_roce_bitmap bitmap;
517+
struct hns_roce_ida srq_ida;
518518
struct xarray xa;
519519
struct hns_roce_hem_table table;
520520
};
@@ -1145,13 +1145,12 @@ void hns_roce_init_pd_table(struct hns_roce_dev *hr_dev);
11451145
void hns_roce_init_mr_table(struct hns_roce_dev *hr_dev);
11461146
void hns_roce_init_cq_table(struct hns_roce_dev *hr_dev);
11471147
void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev);
1148-
int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev);
1148+
void hns_roce_init_srq_table(struct hns_roce_dev *hr_dev);
11491149
void hns_roce_init_xrcd_table(struct hns_roce_dev *hr_dev);
11501150

11511151
void hns_roce_cleanup_eq_table(struct hns_roce_dev *hr_dev);
11521152
void hns_roce_cleanup_cq_table(struct hns_roce_dev *hr_dev);
11531153
void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev);
1154-
void hns_roce_cleanup_srq_table(struct hns_roce_dev *hr_dev);
11551154

11561155
int hns_roce_bitmap_alloc(struct hns_roce_bitmap *bitmap, unsigned long *obj);
11571156
void hns_roce_bitmap_free(struct hns_roce_bitmap *bitmap, unsigned long obj);

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -758,26 +758,11 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
758758
hns_roce_init_qp_table(hr_dev);
759759

760760
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SRQ) {
761-
ret = hns_roce_init_srq_table(hr_dev);
762-
if (ret) {
763-
dev_err(dev,
764-
"Failed to init share receive queue table.\n");
765-
goto err_qp_table_free;
766-
}
761+
hns_roce_init_srq_table(hr_dev);
767762
}
768763

769764
return 0;
770765

771-
err_qp_table_free:
772-
hns_roce_cleanup_qp_table(hr_dev);
773-
hns_roce_cleanup_cq_table(hr_dev);
774-
ida_destroy(&hr_dev->mr_table.mtpt_ida.ida);
775-
776-
if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC)
777-
ida_destroy(&hr_dev->xrcd_ida.ida);
778-
779-
ida_destroy(&hr_dev->pd_ida.ida);
780-
781766
err_uar_table_free:
782767
ida_destroy(&hr_dev->uar_ida.ida);
783768
return ret;

drivers/infiniband/hw/hns/hns_roce_srq.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,19 @@ static int hns_roce_hw_destroy_srq(struct hns_roce_dev *dev,
8080
static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
8181
{
8282
struct hns_roce_srq_table *srq_table = &hr_dev->srq_table;
83+
struct hns_roce_ida *srq_ida = &hr_dev->srq_table.srq_ida;
8384
struct ib_device *ibdev = &hr_dev->ib_dev;
8485
struct hns_roce_cmd_mailbox *mailbox;
8586
int ret;
87+
int id;
8688

87-
ret = hns_roce_bitmap_alloc(&srq_table->bitmap, &srq->srqn);
88-
if (ret) {
89-
ibdev_err(ibdev, "failed to alloc SRQ number.\n");
89+
id = ida_alloc_range(&srq_ida->ida, srq_ida->min, srq_ida->max,
90+
GFP_KERNEL);
91+
if (id < 0) {
92+
ibdev_err(ibdev, "failed to alloc srq(%d).\n", id);
9093
return -ENOMEM;
9194
}
95+
srq->srqn = (unsigned long)id;
9296

9397
ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn);
9498
if (ret) {
@@ -132,7 +136,7 @@ static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
132136
err_put:
133137
hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn);
134138
err_out:
135-
hns_roce_bitmap_free(&srq_table->bitmap, srq->srqn);
139+
ida_free(&srq_ida->ida, id);
136140

137141
return ret;
138142
}
@@ -154,7 +158,7 @@ static void free_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq)
154158
wait_for_completion(&srq->free);
155159

156160
hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn);
157-
hns_roce_bitmap_free(&srq_table->bitmap, srq->srqn);
161+
ida_free(&srq_table->srq_ida.ida, (int)srq->srqn);
158162
}
159163

160164
static int alloc_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq,
@@ -440,18 +444,14 @@ int hns_roce_destroy_srq(struct ib_srq *ibsrq, struct ib_udata *udata)
440444
return 0;
441445
}
442446

443-
int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev)
447+
void hns_roce_init_srq_table(struct hns_roce_dev *hr_dev)
444448
{
445449
struct hns_roce_srq_table *srq_table = &hr_dev->srq_table;
450+
struct hns_roce_ida *srq_ida = &srq_table->srq_ida;
446451

447452
xa_init(&srq_table->xa);
448453

449-
return hns_roce_bitmap_init(&srq_table->bitmap, hr_dev->caps.num_srqs,
450-
hr_dev->caps.num_srqs - 1,
451-
hr_dev->caps.reserved_srqs, 0);
452-
}
453-
454-
void hns_roce_cleanup_srq_table(struct hns_roce_dev *hr_dev)
455-
{
456-
hns_roce_bitmap_cleanup(&hr_dev->srq_table.bitmap);
454+
ida_init(&srq_ida->ida);
455+
srq_ida->max = hr_dev->caps.num_srqs - 1;
456+
srq_ida->min = hr_dev->caps.reserved_srqs;
457457
}

0 commit comments

Comments
 (0)