Skip to content

Commit 8feafd9

Browse files
l00436852jgunthorpe
authored andcommitted
RDMA/hns: Use IDA interface to manage uar index
Switch uar 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 f8c549a commit 8feafd9

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

drivers/infiniband/hw/hns/hns_roce_alloc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,5 +253,5 @@ void hns_roce_cleanup_bitmap(struct hns_roce_dev *hr_dev)
253253
hns_roce_cleanup_cq_table(hr_dev);
254254
ida_destroy(&hr_dev->mr_table.mtpt_ida.ida);
255255
ida_destroy(&hr_dev->pd_ida.ida);
256-
hns_roce_cleanup_uar_table(hr_dev);
256+
ida_destroy(&hr_dev->uar_ida.ida);
257257
}

drivers/infiniband/hw/hns/hns_roce_device.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -963,7 +963,7 @@ struct hns_roce_dev {
963963
struct hns_roce_cmdq cmd;
964964
struct hns_roce_ida pd_ida;
965965
struct hns_roce_ida xrcd_ida;
966-
struct hns_roce_uar_table uar_table;
966+
struct hns_roce_ida uar_ida;
967967
struct hns_roce_mr_table mr_table;
968968
struct hns_roce_cq_table cq_table;
969969
struct hns_roce_srq_table srq_table;
@@ -1118,10 +1118,8 @@ static inline u8 get_tclass(const struct ib_global_route *grh)
11181118
grh->traffic_class >> DSCP_SHIFT : grh->traffic_class;
11191119
}
11201120

1121-
int hns_roce_init_uar_table(struct hns_roce_dev *dev);
1121+
void hns_roce_init_uar_table(struct hns_roce_dev *dev);
11221122
int hns_roce_uar_alloc(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
1123-
void hns_roce_uar_free(struct hns_roce_dev *dev, struct hns_roce_uar *uar);
1124-
void hns_roce_cleanup_uar_table(struct hns_roce_dev *dev);
11251123

11261124
int hns_roce_cmd_init(struct hns_roce_dev *hr_dev);
11271125
void hns_roce_cmd_cleanup(struct hns_roce_dev *hr_dev);

drivers/infiniband/hw/hns/hns_roce_main.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
325325
return 0;
326326

327327
error_fail_copy_to_udata:
328-
hns_roce_uar_free(hr_dev, &context->uar);
328+
ida_free(&hr_dev->uar_ida.ida, (int)context->uar.logic_idx);
329329

330330
error_fail_uar_alloc:
331331
return ret;
@@ -334,8 +334,9 @@ static int hns_roce_alloc_ucontext(struct ib_ucontext *uctx,
334334
static void hns_roce_dealloc_ucontext(struct ib_ucontext *ibcontext)
335335
{
336336
struct hns_roce_ucontext *context = to_hr_ucontext(ibcontext);
337+
struct hns_roce_dev *hr_dev = to_hr_dev(ibcontext->device);
337338

338-
hns_roce_uar_free(to_hr_dev(ibcontext->device), &context->uar);
339+
ida_free(&hr_dev->uar_ida.ida, (int)context->uar.logic_idx);
339340
}
340341

341342
static int hns_roce_mmap(struct ib_ucontext *context,
@@ -737,11 +738,7 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
737738
mutex_init(&hr_dev->pgdir_mutex);
738739
}
739740

740-
ret = hns_roce_init_uar_table(hr_dev);
741-
if (ret) {
742-
dev_err(dev, "Failed to initialize uar table. aborting\n");
743-
return ret;
744-
}
741+
hns_roce_init_uar_table(hr_dev);
745742

746743
ret = hns_roce_uar_alloc(hr_dev, &hr_dev->priv_uar);
747744
if (ret) {
@@ -780,10 +777,9 @@ static int hns_roce_setup_hca(struct hns_roce_dev *hr_dev)
780777
ida_destroy(&hr_dev->xrcd_ida.ida);
781778

782779
ida_destroy(&hr_dev->pd_ida.ida);
783-
hns_roce_uar_free(hr_dev, &hr_dev->priv_uar);
784780

785781
err_uar_table_free:
786-
hns_roce_cleanup_uar_table(hr_dev);
782+
ida_destroy(&hr_dev->uar_ida.ida);
787783
return ret;
788784
}
789785

drivers/infiniband/hw/hns/hns_roce_pd.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,18 @@ int hns_roce_dealloc_pd(struct ib_pd *pd, struct ib_udata *udata)
8585

8686
int hns_roce_uar_alloc(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar)
8787
{
88+
struct hns_roce_ida *uar_ida = &hr_dev->uar_ida;
8889
struct resource *res;
89-
int ret;
90+
int id;
9091

9192
/* Using bitmap to manager UAR index */
92-
ret = hns_roce_bitmap_alloc(&hr_dev->uar_table.bitmap, &uar->logic_idx);
93-
if (ret)
93+
id = ida_alloc_range(&uar_ida->ida, uar_ida->min, uar_ida->max,
94+
GFP_KERNEL);
95+
if (id < 0) {
96+
ibdev_err(&hr_dev->ib_dev, "failed to alloc uar id(%d).\n", id);
9497
return -ENOMEM;
98+
}
99+
uar->logic_idx = (unsigned long)id;
95100

96101
if (uar->logic_idx > 0 && hr_dev->caps.phy_num_uars > 1)
97102
uar->index = (uar->logic_idx - 1) %
@@ -102,6 +107,7 @@ int hns_roce_uar_alloc(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar)
102107
if (!dev_is_pci(hr_dev->dev)) {
103108
res = platform_get_resource(hr_dev->pdev, IORESOURCE_MEM, 0);
104109
if (!res) {
110+
ida_free(&uar_ida->ida, id);
105111
dev_err(&hr_dev->pdev->dev, "memory resource not found!\n");
106112
return -EINVAL;
107113
}
@@ -114,22 +120,13 @@ int hns_roce_uar_alloc(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar)
114120
return 0;
115121
}
116122

117-
void hns_roce_uar_free(struct hns_roce_dev *hr_dev, struct hns_roce_uar *uar)
123+
void hns_roce_init_uar_table(struct hns_roce_dev *hr_dev)
118124
{
119-
hns_roce_bitmap_free(&hr_dev->uar_table.bitmap, uar->logic_idx);
120-
}
125+
struct hns_roce_ida *uar_ida = &hr_dev->uar_ida;
121126

122-
int hns_roce_init_uar_table(struct hns_roce_dev *hr_dev)
123-
{
124-
return hns_roce_bitmap_init(&hr_dev->uar_table.bitmap,
125-
hr_dev->caps.num_uars,
126-
hr_dev->caps.num_uars - 1,
127-
hr_dev->caps.reserved_uars, 0);
128-
}
129-
130-
void hns_roce_cleanup_uar_table(struct hns_roce_dev *hr_dev)
131-
{
132-
hns_roce_bitmap_cleanup(&hr_dev->uar_table.bitmap);
127+
ida_init(&uar_ida->ida);
128+
uar_ida->max = hr_dev->caps.num_uars - 1;
129+
uar_ida->min = hr_dev->caps.reserved_uars;
133130
}
134131

135132
static int hns_roce_xrcd_alloc(struct hns_roce_dev *hr_dev, u32 *xrcdn)

0 commit comments

Comments
 (0)