Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

RDMA/hns: Use IDA interface to manage xrcd index

Switch xrcd index allocation and release from hns own bitmap interface
to IDA interface.

Link: https://lore.kernel.org/r/1623325814-55737-7-git-send-email-liweihang@huawei.com
Signed-off-by: Yangyang Li <liyangyang20@huawei.com>
Signed-off-by: Weihang Li <liweihang@huawei.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Yangyang Li and committed by
Jason Gunthorpe
da43b7be 645f0593

+25 -41
+1 -1
drivers/infiniband/hw/hns/hns_roce_alloc.c
··· 245 245 void hns_roce_cleanup_bitmap(struct hns_roce_dev *hr_dev) 246 246 { 247 247 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC) 248 - hns_roce_cleanup_xrcd_table(hr_dev); 248 + ida_destroy(&hr_dev->xrcd_ida.ida); 249 249 250 250 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SRQ) 251 251 hns_roce_cleanup_srq_table(hr_dev);
+2 -3
drivers/infiniband/hw/hns/hns_roce_device.h
··· 962 962 963 963 struct hns_roce_cmdq cmd; 964 964 struct hns_roce_ida pd_ida; 965 - struct hns_roce_bitmap xrcd_bitmap; 965 + struct hns_roce_ida xrcd_ida; 966 966 struct hns_roce_uar_table uar_table; 967 967 struct hns_roce_mr_table mr_table; 968 968 struct hns_roce_cq_table cq_table; ··· 1148 1148 void hns_roce_init_cq_table(struct hns_roce_dev *hr_dev); 1149 1149 int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev); 1150 1150 int hns_roce_init_srq_table(struct hns_roce_dev *hr_dev); 1151 - int hns_roce_init_xrcd_table(struct hns_roce_dev *hr_dev); 1151 + void hns_roce_init_xrcd_table(struct hns_roce_dev *hr_dev); 1152 1152 1153 1153 void hns_roce_cleanup_eq_table(struct hns_roce_dev *hr_dev); 1154 1154 void hns_roce_cleanup_cq_table(struct hns_roce_dev *hr_dev); 1155 1155 void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev); 1156 1156 void hns_roce_cleanup_srq_table(struct hns_roce_dev *hr_dev); 1157 - void hns_roce_cleanup_xrcd_table(struct hns_roce_dev *hr_dev); 1158 1157 1159 1158 int hns_roce_bitmap_alloc(struct hns_roce_bitmap *bitmap, unsigned long *obj); 1160 1159 void hns_roce_bitmap_free(struct hns_roce_bitmap *bitmap, unsigned long obj);
+3 -10
drivers/infiniband/hw/hns/hns_roce_main.c
··· 750 750 751 751 hns_roce_init_pd_table(hr_dev); 752 752 753 - if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC) { 754 - ret = hns_roce_init_xrcd_table(hr_dev); 755 - if (ret) { 756 - dev_err(dev, "failed to init xrcd table, ret = %d.\n", 757 - ret); 758 - goto err_pd_table_free; 759 - } 760 - } 753 + if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC) 754 + hns_roce_init_xrcd_table(hr_dev); 761 755 762 756 hns_roce_init_mr_table(hr_dev); 763 757 ··· 782 788 ida_destroy(&hr_dev->mr_table.mtpt_ida.ida); 783 789 784 790 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC) 785 - hns_roce_cleanup_xrcd_table(hr_dev); 791 + ida_destroy(&hr_dev->xrcd_ida.ida); 786 792 787 - err_pd_table_free: 788 793 ida_destroy(&hr_dev->pd_ida.ida); 789 794 hns_roce_uar_free(hr_dev, &hr_dev->priv_uar); 790 795
+19 -27
drivers/infiniband/hw/hns/hns_roce_pd.c
··· 134 134 135 135 static int hns_roce_xrcd_alloc(struct hns_roce_dev *hr_dev, u32 *xrcdn) 136 136 { 137 - unsigned long obj; 138 - int ret; 137 + struct hns_roce_ida *xrcd_ida = &hr_dev->xrcd_ida; 138 + int id; 139 139 140 - ret = hns_roce_bitmap_alloc(&hr_dev->xrcd_bitmap, &obj); 141 - if (ret) 142 - return ret; 143 - 144 - *xrcdn = obj; 140 + id = ida_alloc_range(&xrcd_ida->ida, xrcd_ida->min, xrcd_ida->max, 141 + GFP_KERNEL); 142 + if (id < 0) { 143 + ibdev_err(&hr_dev->ib_dev, "failed to alloc xrcdn(%d).\n", id); 144 + return -ENOMEM; 145 + } 146 + *xrcdn = (u32)id; 145 147 146 148 return 0; 147 149 } 148 150 149 - static void hns_roce_xrcd_free(struct hns_roce_dev *hr_dev, 150 - u32 xrcdn) 151 + void hns_roce_init_xrcd_table(struct hns_roce_dev *hr_dev) 151 152 { 152 - hns_roce_bitmap_free(&hr_dev->xrcd_bitmap, xrcdn); 153 - } 153 + struct hns_roce_ida *xrcd_ida = &hr_dev->xrcd_ida; 154 154 155 - int hns_roce_init_xrcd_table(struct hns_roce_dev *hr_dev) 156 - { 157 - return hns_roce_bitmap_init(&hr_dev->xrcd_bitmap, 158 - hr_dev->caps.num_xrcds, 159 - hr_dev->caps.num_xrcds - 1, 160 - hr_dev->caps.reserved_xrcds, 0); 161 - } 162 - 163 - void hns_roce_cleanup_xrcd_table(struct hns_roce_dev *hr_dev) 164 - { 165 - hns_roce_bitmap_cleanup(&hr_dev->xrcd_bitmap); 155 + ida_init(&xrcd_ida->ida); 156 + xrcd_ida->max = hr_dev->caps.num_xrcds - 1; 157 + xrcd_ida->min = hr_dev->caps.reserved_xrcds; 166 158 } 167 159 168 160 int hns_roce_alloc_xrcd(struct ib_xrcd *ib_xrcd, struct ib_udata *udata) ··· 167 175 return -EINVAL; 168 176 169 177 ret = hns_roce_xrcd_alloc(hr_dev, &xrcd->xrcdn); 170 - if (ret) { 171 - dev_err(hr_dev->dev, "failed to alloc xrcdn, ret = %d.\n", ret); 178 + if (ret) 172 179 return ret; 173 - } 174 180 175 181 return 0; 176 182 } 177 183 178 184 int hns_roce_dealloc_xrcd(struct ib_xrcd *ib_xrcd, struct ib_udata *udata) 179 185 { 180 - hns_roce_xrcd_free(to_hr_dev(ib_xrcd->device), 181 - to_hr_xrcd(ib_xrcd)->xrcdn); 186 + struct hns_roce_dev *hr_dev = to_hr_dev(ib_xrcd->device); 187 + u32 xrcdn = to_hr_xrcd(ib_xrcd)->xrcdn; 188 + 189 + ida_free(&hr_dev->xrcd_ida.ida, (int)xrcdn); 182 190 183 191 return 0; 184 192 }