@@ -80,15 +80,19 @@ static int hns_roce_hw_destroy_srq(struct hns_roce_dev *dev,
8080static 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)
132136err_put :
133137 hns_roce_table_put (hr_dev , & srq_table -> table , srq -> srqn );
134138err_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
160164static 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