Lines Matching refs:srq
15 struct hns_roce_srq *srq; in hns_roce_srq_event() local
18 srq = xa_load(&srq_table->xa, srqn & (hr_dev->caps.num_srqs - 1)); in hns_roce_srq_event()
19 if (srq) in hns_roce_srq_event()
20 refcount_inc(&srq->refcount); in hns_roce_srq_event()
23 if (!srq) { in hns_roce_srq_event()
28 srq->event(srq, event_type); in hns_roce_srq_event()
30 if (refcount_dec_and_test(&srq->refcount)) in hns_roce_srq_event()
31 complete(&srq->free); in hns_roce_srq_event()
34 static void hns_roce_ib_srq_event(struct hns_roce_srq *srq, in hns_roce_ib_srq_event() argument
37 struct hns_roce_dev *hr_dev = to_hr_dev(srq->ibsrq.device); in hns_roce_ib_srq_event()
38 struct ib_srq *ibsrq = &srq->ibsrq; in hns_roce_ib_srq_event()
43 event.element.srq = ibsrq; in hns_roce_ib_srq_event()
54 event_type, srq->srqn); in hns_roce_ib_srq_event()
62 static int alloc_srqn(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in alloc_srqn() argument
74 srq->srqn = id; in alloc_srqn()
79 static void free_srqn(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in free_srqn() argument
81 ida_free(&hr_dev->srq_table.srq_ida.ida, (int)srq->srqn); in free_srqn()
85 struct hns_roce_srq *srq) in hns_roce_create_srqc() argument
97 ret = hr_dev->hw->write_srqc(srq, mailbox->buf); in hns_roce_create_srqc()
104 srq->srqn); in hns_roce_create_srqc()
113 static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in alloc_srqc() argument
119 ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn); in alloc_srqc()
125 ret = xa_err(xa_store(&srq_table->xa, srq->srqn, srq, GFP_KERNEL)); in alloc_srqc()
131 ret = hns_roce_create_srqc(hr_dev, srq); in alloc_srqc()
138 xa_erase(&srq_table->xa, srq->srqn); in alloc_srqc()
140 hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn); in alloc_srqc()
145 static void free_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in free_srqc() argument
151 srq->srqn); in free_srqc()
154 ret, srq->srqn); in free_srqc()
156 xa_erase(&srq_table->xa, srq->srqn); in free_srqc()
158 if (refcount_dec_and_test(&srq->refcount)) in free_srqc()
159 complete(&srq->free); in free_srqc()
160 wait_for_completion(&srq->free); in free_srqc()
162 hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn); in free_srqc()
165 static int alloc_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq, in alloc_srq_idx() argument
168 struct hns_roce_idx_que *idx_que = &srq->idx_que; in alloc_srq_idx()
173 srq->idx_que.entry_shift = ilog2(HNS_ROCE_IDX_QUE_ENTRY_SZ); in alloc_srq_idx()
176 buf_attr.region[0].size = to_hr_hem_entries_size(srq->wqe_cnt, in alloc_srq_idx()
177 srq->idx_que.entry_shift); in alloc_srq_idx()
191 idx_que->bitmap = bitmap_zalloc(srq->wqe_cnt, GFP_KERNEL); in alloc_srq_idx()
209 static void free_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in free_srq_idx() argument
211 struct hns_roce_idx_que *idx_que = &srq->idx_que; in free_srq_idx()
219 struct hns_roce_srq *srq, in alloc_srq_wqe_buf() argument
226 srq->wqe_shift = ilog2(roundup_pow_of_two(max(HNS_ROCE_SGE_SIZE, in alloc_srq_wqe_buf()
228 srq->max_gs))); in alloc_srq_wqe_buf()
231 buf_attr.region[0].size = to_hr_hem_entries_size(srq->wqe_cnt, in alloc_srq_wqe_buf()
232 srq->wqe_shift); in alloc_srq_wqe_buf()
236 ret = hns_roce_mtr_create(hr_dev, &srq->buf_mtr, &buf_attr, in alloc_srq_wqe_buf()
247 struct hns_roce_srq *srq) in free_srq_wqe_buf() argument
249 hns_roce_mtr_destroy(hr_dev, &srq->buf_mtr); in free_srq_wqe_buf()
252 static int alloc_srq_wrid(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in alloc_srq_wrid() argument
254 srq->wrid = kvmalloc_array(srq->wqe_cnt, sizeof(u64), GFP_KERNEL); in alloc_srq_wrid()
255 if (!srq->wrid) in alloc_srq_wrid()
261 static void free_srq_wrid(struct hns_roce_srq *srq) in free_srq_wrid() argument
263 kvfree(srq->wrid); in free_srq_wrid()
264 srq->wrid = NULL; in free_srq_wrid()
289 static int set_srq_basic_param(struct hns_roce_srq *srq, in set_srq_basic_param() argument
293 struct hns_roce_dev *hr_dev = to_hr_dev(srq->ibsrq.device); in set_srq_basic_param()
297 max_sge = proc_srq_sge(hr_dev, srq, !!udata); in set_srq_basic_param()
307 srq->wqe_cnt = roundup_pow_of_two(attr->max_wr); in set_srq_basic_param()
308 srq->max_gs = roundup_pow_of_two(attr->max_sge + srq->rsv_sge); in set_srq_basic_param()
310 attr->max_wr = srq->wqe_cnt; in set_srq_basic_param()
311 attr->max_sge = srq->max_gs - srq->rsv_sge; in set_srq_basic_param()
317 static void set_srq_ext_param(struct hns_roce_srq *srq, in set_srq_ext_param() argument
320 srq->cqn = ib_srq_has_cq(init_attr->srq_type) ? in set_srq_ext_param()
323 srq->xrcdn = (init_attr->srq_type == IB_SRQT_XRC) ? in set_srq_ext_param()
327 static int set_srq_param(struct hns_roce_srq *srq, in set_srq_param() argument
333 ret = set_srq_basic_param(srq, init_attr, udata); in set_srq_param()
337 set_srq_ext_param(srq, init_attr); in set_srq_param()
342 static int alloc_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq, in alloc_srq_buf() argument
359 ret = alloc_srq_idx(hr_dev, srq, udata, ucmd.que_addr); in alloc_srq_buf()
363 ret = alloc_srq_wqe_buf(hr_dev, srq, udata, ucmd.buf_addr); in alloc_srq_buf()
368 ret = alloc_srq_wrid(hr_dev, srq); in alloc_srq_buf()
376 free_srq_wqe_buf(hr_dev, srq); in alloc_srq_buf()
378 free_srq_idx(hr_dev, srq); in alloc_srq_buf()
383 static void free_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in free_srq_buf() argument
385 free_srq_wrid(srq); in free_srq_buf()
386 free_srq_wqe_buf(hr_dev, srq); in free_srq_buf()
387 free_srq_idx(hr_dev, srq); in free_srq_buf()
396 struct hns_roce_srq *srq = to_hr_srq(ib_srq); in hns_roce_create_srq() local
399 mutex_init(&srq->mutex); in hns_roce_create_srq()
400 spin_lock_init(&srq->lock); in hns_roce_create_srq()
402 ret = set_srq_param(srq, init_attr, udata); in hns_roce_create_srq()
406 ret = alloc_srq_buf(hr_dev, srq, udata); in hns_roce_create_srq()
410 ret = alloc_srqn(hr_dev, srq); in hns_roce_create_srq()
414 ret = alloc_srqc(hr_dev, srq); in hns_roce_create_srq()
419 resp.srqn = srq->srqn; in hns_roce_create_srq()
427 srq->db_reg = hr_dev->reg_base + SRQ_DB_REG; in hns_roce_create_srq()
428 srq->event = hns_roce_ib_srq_event; in hns_roce_create_srq()
429 refcount_set(&srq->refcount, 1); in hns_roce_create_srq()
430 init_completion(&srq->free); in hns_roce_create_srq()
435 free_srqc(hr_dev, srq); in hns_roce_create_srq()
437 free_srqn(hr_dev, srq); in hns_roce_create_srq()
439 free_srq_buf(hr_dev, srq); in hns_roce_create_srq()
447 struct hns_roce_srq *srq = to_hr_srq(ibsrq); in hns_roce_destroy_srq() local
449 free_srqc(hr_dev, srq); in hns_roce_destroy_srq()
450 free_srqn(hr_dev, srq); in hns_roce_destroy_srq()
451 free_srq_buf(hr_dev, srq); in hns_roce_destroy_srq()