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()
80 static int alloc_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in alloc_srqc() argument
95 srq->srqn = (unsigned long)id; in alloc_srqc()
97 ret = hns_roce_table_get(hr_dev, &srq_table->table, srq->srqn); in alloc_srqc()
103 ret = xa_err(xa_store(&srq_table->xa, srq->srqn, srq, GFP_KERNEL)); in alloc_srqc()
116 ret = hr_dev->hw->write_srqc(srq, mailbox->buf); in alloc_srqc()
122 ret = hns_roce_hw_create_srq(hr_dev, mailbox, srq->srqn); in alloc_srqc()
135 xa_erase(&srq_table->xa, srq->srqn); in alloc_srqc()
137 hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn); in alloc_srqc()
144 static void free_srqc(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in free_srqc() argument
149 ret = hns_roce_hw_destroy_srq(hr_dev, NULL, srq->srqn); in free_srqc()
152 ret, srq->srqn); in free_srqc()
154 xa_erase(&srq_table->xa, srq->srqn); in free_srqc()
156 if (refcount_dec_and_test(&srq->refcount)) in free_srqc()
157 complete(&srq->free); in free_srqc()
158 wait_for_completion(&srq->free); in free_srqc()
160 hns_roce_table_put(hr_dev, &srq_table->table, srq->srqn); in free_srqc()
161 ida_free(&srq_table->srq_ida.ida, (int)srq->srqn); in free_srqc()
164 static int alloc_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq, in alloc_srq_idx() argument
167 struct hns_roce_idx_que *idx_que = &srq->idx_que; in alloc_srq_idx()
172 srq->idx_que.entry_shift = ilog2(HNS_ROCE_IDX_QUE_ENTRY_SZ); in alloc_srq_idx()
175 buf_attr.region[0].size = to_hr_hem_entries_size(srq->wqe_cnt, in alloc_srq_idx()
176 srq->idx_que.entry_shift); in alloc_srq_idx()
190 idx_que->bitmap = bitmap_zalloc(srq->wqe_cnt, GFP_KERNEL); in alloc_srq_idx()
208 static void free_srq_idx(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in free_srq_idx() argument
210 struct hns_roce_idx_que *idx_que = &srq->idx_que; in free_srq_idx()
218 struct hns_roce_srq *srq, in alloc_srq_wqe_buf() argument
225 srq->wqe_shift = ilog2(roundup_pow_of_two(max(HNS_ROCE_SGE_SIZE, in alloc_srq_wqe_buf()
227 srq->max_gs))); in alloc_srq_wqe_buf()
230 buf_attr.region[0].size = to_hr_hem_entries_size(srq->wqe_cnt, in alloc_srq_wqe_buf()
231 srq->wqe_shift); in alloc_srq_wqe_buf()
235 ret = hns_roce_mtr_create(hr_dev, &srq->buf_mtr, &buf_attr, in alloc_srq_wqe_buf()
246 struct hns_roce_srq *srq) in free_srq_wqe_buf() argument
248 hns_roce_mtr_destroy(hr_dev, &srq->buf_mtr); in free_srq_wqe_buf()
251 static int alloc_srq_wrid(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in alloc_srq_wrid() argument
253 srq->wrid = kvmalloc_array(srq->wqe_cnt, sizeof(u64), GFP_KERNEL); in alloc_srq_wrid()
254 if (!srq->wrid) in alloc_srq_wrid()
260 static void free_srq_wrid(struct hns_roce_srq *srq) in free_srq_wrid() argument
262 kvfree(srq->wrid); in free_srq_wrid()
263 srq->wrid = NULL; in free_srq_wrid()
288 static int set_srq_basic_param(struct hns_roce_srq *srq, in set_srq_basic_param() argument
292 struct hns_roce_dev *hr_dev = to_hr_dev(srq->ibsrq.device); in set_srq_basic_param()
296 max_sge = proc_srq_sge(hr_dev, srq, !!udata); in set_srq_basic_param()
306 srq->wqe_cnt = roundup_pow_of_two(attr->max_wr); in set_srq_basic_param()
307 srq->max_gs = roundup_pow_of_two(attr->max_sge + srq->rsv_sge); in set_srq_basic_param()
309 attr->max_wr = srq->wqe_cnt; in set_srq_basic_param()
310 attr->max_sge = srq->max_gs - srq->rsv_sge; in set_srq_basic_param()
316 static void set_srq_ext_param(struct hns_roce_srq *srq, in set_srq_ext_param() argument
319 srq->cqn = ib_srq_has_cq(init_attr->srq_type) ? in set_srq_ext_param()
322 srq->xrcdn = (init_attr->srq_type == IB_SRQT_XRC) ? in set_srq_ext_param()
326 static int set_srq_param(struct hns_roce_srq *srq, in set_srq_param() argument
332 ret = set_srq_basic_param(srq, init_attr, udata); in set_srq_param()
336 set_srq_ext_param(srq, init_attr); in set_srq_param()
341 static int alloc_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq, in alloc_srq_buf() argument
358 ret = alloc_srq_idx(hr_dev, srq, udata, ucmd.que_addr); in alloc_srq_buf()
362 ret = alloc_srq_wqe_buf(hr_dev, srq, udata, ucmd.buf_addr); in alloc_srq_buf()
367 ret = alloc_srq_wrid(hr_dev, srq); in alloc_srq_buf()
375 free_srq_wqe_buf(hr_dev, srq); in alloc_srq_buf()
377 free_srq_idx(hr_dev, srq); in alloc_srq_buf()
382 static void free_srq_buf(struct hns_roce_dev *hr_dev, struct hns_roce_srq *srq) in free_srq_buf() argument
384 free_srq_wrid(srq); in free_srq_buf()
385 free_srq_wqe_buf(hr_dev, srq); in free_srq_buf()
386 free_srq_idx(hr_dev, srq); in free_srq_buf()
395 struct hns_roce_srq *srq = to_hr_srq(ib_srq); in hns_roce_create_srq() local
398 mutex_init(&srq->mutex); in hns_roce_create_srq()
399 spin_lock_init(&srq->lock); in hns_roce_create_srq()
401 ret = set_srq_param(srq, init_attr, udata); in hns_roce_create_srq()
405 ret = alloc_srq_buf(hr_dev, srq, udata); in hns_roce_create_srq()
409 ret = alloc_srqc(hr_dev, srq); in hns_roce_create_srq()
414 resp.srqn = srq->srqn; in hns_roce_create_srq()
422 srq->db_reg = hr_dev->reg_base + SRQ_DB_REG; in hns_roce_create_srq()
423 srq->event = hns_roce_ib_srq_event; in hns_roce_create_srq()
424 refcount_set(&srq->refcount, 1); in hns_roce_create_srq()
425 init_completion(&srq->free); in hns_roce_create_srq()
430 free_srqc(hr_dev, srq); in hns_roce_create_srq()
432 free_srq_buf(hr_dev, srq); in hns_roce_create_srq()
440 struct hns_roce_srq *srq = to_hr_srq(ibsrq); in hns_roce_destroy_srq() local
442 free_srqc(hr_dev, srq); in hns_roce_destroy_srq()
443 free_srq_buf(hr_dev, srq); in hns_roce_destroy_srq()