2 * Copyright (c) 2016 Hisilicon Limited.
3 * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34 #include <linux/pci.h>
35 #include <linux/platform_device.h>
36 #include <rdma/ib_addr.h>
37 #include <rdma/ib_umem.h>
38 #include <rdma/uverbs_ioctl.h>
39 #include "hns_roce_common.h"
40 #include "hns_roce_device.h"
41 #include "hns_roce_hem.h"
43 static void flush_work_handle(struct work_struct *work)
45 struct hns_roce_work *flush_work = container_of(work,
46 struct hns_roce_work, work);
47 struct hns_roce_qp *hr_qp = container_of(flush_work,
48 struct hns_roce_qp, flush_work);
49 struct device *dev = flush_work->hr_dev->dev;
50 struct ib_qp_attr attr;
54 attr_mask = IB_QP_STATE;
55 attr.qp_state = IB_QPS_ERR;
57 if (test_and_clear_bit(HNS_ROCE_FLUSH_FLAG, &hr_qp->flush_flag)) {
58 ret = hns_roce_modify_qp(&hr_qp->ibqp, &attr, attr_mask, NULL);
60 dev_err(dev, "Modify QP to error state failed(%d) during CQE flush\n",
65 * make sure we signal QP destroy leg that flush QP was completed
66 * so that it can safely proceed ahead now and destroy QP
68 if (refcount_dec_and_test(&hr_qp->refcount))
69 complete(&hr_qp->free);
72 void init_flush_work(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
74 struct hns_roce_work *flush_work = &hr_qp->flush_work;
76 flush_work->hr_dev = hr_dev;
77 INIT_WORK(&flush_work->work, flush_work_handle);
78 refcount_inc(&hr_qp->refcount);
79 queue_work(hr_dev->irq_workq, &flush_work->work);
82 void hns_roce_qp_event(struct hns_roce_dev *hr_dev, u32 qpn, int event_type)
84 struct device *dev = hr_dev->dev;
85 struct hns_roce_qp *qp;
87 xa_lock(&hr_dev->qp_table_xa);
88 qp = __hns_roce_qp_lookup(hr_dev, qpn);
90 refcount_inc(&qp->refcount);
91 xa_unlock(&hr_dev->qp_table_xa);
94 dev_warn(dev, "Async event for bogus QP %08x\n", qpn);
98 if (hr_dev->hw_rev != HNS_ROCE_HW_VER1 &&
99 (event_type == HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR ||
100 event_type == HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR ||
101 event_type == HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR ||
102 event_type == HNS_ROCE_EVENT_TYPE_XRCD_VIOLATION ||
103 event_type == HNS_ROCE_EVENT_TYPE_INVALID_XRCETH)) {
104 qp->state = IB_QPS_ERR;
105 if (!test_and_set_bit(HNS_ROCE_FLUSH_FLAG, &qp->flush_flag))
106 init_flush_work(hr_dev, qp);
109 qp->event(qp, (enum hns_roce_event)event_type);
111 if (refcount_dec_and_test(&qp->refcount))
115 static void hns_roce_ib_qp_event(struct hns_roce_qp *hr_qp,
116 enum hns_roce_event type)
118 struct ib_qp *ibqp = &hr_qp->ibqp;
119 struct ib_event event;
121 if (ibqp->event_handler) {
122 event.device = ibqp->device;
123 event.element.qp = ibqp;
125 case HNS_ROCE_EVENT_TYPE_PATH_MIG:
126 event.event = IB_EVENT_PATH_MIG;
128 case HNS_ROCE_EVENT_TYPE_COMM_EST:
129 event.event = IB_EVENT_COMM_EST;
131 case HNS_ROCE_EVENT_TYPE_SQ_DRAINED:
132 event.event = IB_EVENT_SQ_DRAINED;
134 case HNS_ROCE_EVENT_TYPE_SRQ_LAST_WQE_REACH:
135 event.event = IB_EVENT_QP_LAST_WQE_REACHED;
137 case HNS_ROCE_EVENT_TYPE_WQ_CATAS_ERROR:
138 event.event = IB_EVENT_QP_FATAL;
140 case HNS_ROCE_EVENT_TYPE_PATH_MIG_FAILED:
141 event.event = IB_EVENT_PATH_MIG_ERR;
143 case HNS_ROCE_EVENT_TYPE_INV_REQ_LOCAL_WQ_ERROR:
144 event.event = IB_EVENT_QP_REQ_ERR;
146 case HNS_ROCE_EVENT_TYPE_LOCAL_WQ_ACCESS_ERROR:
147 case HNS_ROCE_EVENT_TYPE_XRCD_VIOLATION:
148 case HNS_ROCE_EVENT_TYPE_INVALID_XRCETH:
149 event.event = IB_EVENT_QP_ACCESS_ERR;
152 dev_dbg(ibqp->device->dev.parent, "roce_ib: Unexpected event type %d on QP %06lx\n",
156 ibqp->event_handler(&event, ibqp->qp_context);
160 static u8 get_least_load_bankid_for_qp(struct hns_roce_bank *bank)
162 u32 least_load = bank[0].inuse;
167 for (i = 1; i < HNS_ROCE_QP_BANK_NUM; i++) {
168 bankcnt = bank[i].inuse;
169 if (bankcnt < least_load) {
170 least_load = bankcnt;
178 static int alloc_qpn_with_bankid(struct hns_roce_bank *bank, u8 bankid,
183 id = ida_alloc_range(&bank->ida, bank->next, bank->max, GFP_KERNEL);
185 id = ida_alloc_range(&bank->ida, bank->min, bank->max,
191 /* the QPN should keep increasing until the max value is reached. */
192 bank->next = (id + 1) > bank->max ? bank->min : id + 1;
194 /* the lower 3 bits is bankid */
195 *qpn = (id << 3) | bankid;
199 static int alloc_qpn(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
201 struct hns_roce_qp_table *qp_table = &hr_dev->qp_table;
202 unsigned long num = 0;
206 if (hr_qp->ibqp.qp_type == IB_QPT_GSI) {
207 /* when hw version is v1, the sqpn is allocated */
208 if (hr_dev->hw_rev == HNS_ROCE_HW_VER1)
209 num = HNS_ROCE_MAX_PORTS +
210 hr_dev->iboe.phy_port[hr_qp->port];
214 hr_qp->doorbell_qpn = 1;
216 mutex_lock(&qp_table->bank_mutex);
217 bankid = get_least_load_bankid_for_qp(qp_table->bank);
219 ret = alloc_qpn_with_bankid(&qp_table->bank[bankid], bankid,
222 ibdev_err(&hr_dev->ib_dev,
223 "failed to alloc QPN, ret = %d\n", ret);
224 mutex_unlock(&qp_table->bank_mutex);
228 qp_table->bank[bankid].inuse++;
229 mutex_unlock(&qp_table->bank_mutex);
231 hr_qp->doorbell_qpn = (u32)num;
239 enum hns_roce_qp_state to_hns_roce_state(enum ib_qp_state state)
243 return HNS_ROCE_QP_STATE_RST;
245 return HNS_ROCE_QP_STATE_INIT;
247 return HNS_ROCE_QP_STATE_RTR;
249 return HNS_ROCE_QP_STATE_RTS;
251 return HNS_ROCE_QP_STATE_SQD;
253 return HNS_ROCE_QP_STATE_ERR;
255 return HNS_ROCE_QP_NUM_STATE;
259 static void add_qp_to_list(struct hns_roce_dev *hr_dev,
260 struct hns_roce_qp *hr_qp,
261 struct ib_cq *send_cq, struct ib_cq *recv_cq)
263 struct hns_roce_cq *hr_send_cq, *hr_recv_cq;
266 hr_send_cq = send_cq ? to_hr_cq(send_cq) : NULL;
267 hr_recv_cq = recv_cq ? to_hr_cq(recv_cq) : NULL;
269 spin_lock_irqsave(&hr_dev->qp_list_lock, flags);
270 hns_roce_lock_cqs(hr_send_cq, hr_recv_cq);
272 list_add_tail(&hr_qp->node, &hr_dev->qp_list);
274 list_add_tail(&hr_qp->sq_node, &hr_send_cq->sq_list);
276 list_add_tail(&hr_qp->rq_node, &hr_recv_cq->rq_list);
278 hns_roce_unlock_cqs(hr_send_cq, hr_recv_cq);
279 spin_unlock_irqrestore(&hr_dev->qp_list_lock, flags);
282 static int hns_roce_qp_store(struct hns_roce_dev *hr_dev,
283 struct hns_roce_qp *hr_qp,
284 struct ib_qp_init_attr *init_attr)
286 struct xarray *xa = &hr_dev->qp_table_xa;
292 ret = xa_err(xa_store_irq(xa, hr_qp->qpn, hr_qp, GFP_KERNEL));
294 dev_err(hr_dev->dev, "Failed to xa store for QPC\n");
296 /* add QP to device's QP list for softwc */
297 add_qp_to_list(hr_dev, hr_qp, init_attr->send_cq,
303 static int alloc_qpc(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
305 struct hns_roce_qp_table *qp_table = &hr_dev->qp_table;
306 struct device *dev = hr_dev->dev;
312 /* In v1 engine, GSI QP context is saved in the RoCE hw's register */
313 if (hr_qp->ibqp.qp_type == IB_QPT_GSI &&
314 hr_dev->hw_rev == HNS_ROCE_HW_VER1)
317 /* Alloc memory for QPC */
318 ret = hns_roce_table_get(hr_dev, &qp_table->qp_table, hr_qp->qpn);
320 dev_err(dev, "Failed to get QPC table\n");
324 /* Alloc memory for IRRL */
325 ret = hns_roce_table_get(hr_dev, &qp_table->irrl_table, hr_qp->qpn);
327 dev_err(dev, "Failed to get IRRL table\n");
331 if (hr_dev->caps.trrl_entry_sz) {
332 /* Alloc memory for TRRL */
333 ret = hns_roce_table_get(hr_dev, &qp_table->trrl_table,
336 dev_err(dev, "Failed to get TRRL table\n");
341 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL) {
342 /* Alloc memory for SCC CTX */
343 ret = hns_roce_table_get(hr_dev, &qp_table->sccc_table,
346 dev_err(dev, "Failed to get SCC CTX table\n");
354 if (hr_dev->caps.trrl_entry_sz)
355 hns_roce_table_put(hr_dev, &qp_table->trrl_table, hr_qp->qpn);
358 hns_roce_table_put(hr_dev, &qp_table->irrl_table, hr_qp->qpn);
361 hns_roce_table_put(hr_dev, &qp_table->qp_table, hr_qp->qpn);
367 void hns_roce_qp_remove(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
369 struct xarray *xa = &hr_dev->qp_table_xa;
372 list_del(&hr_qp->node);
374 if (hr_qp->ibqp.qp_type != IB_QPT_XRC_TGT)
375 list_del(&hr_qp->sq_node);
377 if (hr_qp->ibqp.qp_type != IB_QPT_XRC_INI &&
378 hr_qp->ibqp.qp_type != IB_QPT_XRC_TGT)
379 list_del(&hr_qp->rq_node);
381 xa_lock_irqsave(xa, flags);
382 __xa_erase(xa, hr_qp->qpn);
383 xa_unlock_irqrestore(xa, flags);
386 static void free_qpc(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
388 struct hns_roce_qp_table *qp_table = &hr_dev->qp_table;
390 /* In v1 engine, GSI QP context is saved in the RoCE hw's register */
391 if (hr_qp->ibqp.qp_type == IB_QPT_GSI &&
392 hr_dev->hw_rev == HNS_ROCE_HW_VER1)
395 if (hr_dev->caps.trrl_entry_sz)
396 hns_roce_table_put(hr_dev, &qp_table->trrl_table, hr_qp->qpn);
397 hns_roce_table_put(hr_dev, &qp_table->irrl_table, hr_qp->qpn);
400 static inline u8 get_qp_bankid(unsigned long qpn)
402 /* The lower 3 bits of QPN are used to hash to different banks */
403 return (u8)(qpn & GENMASK(2, 0));
406 static void free_qpn(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
410 if (hr_qp->ibqp.qp_type == IB_QPT_GSI)
413 if (hr_qp->qpn < hr_dev->caps.reserved_qps)
416 bankid = get_qp_bankid(hr_qp->qpn);
418 ida_free(&hr_dev->qp_table.bank[bankid].ida, hr_qp->qpn >> 3);
420 mutex_lock(&hr_dev->qp_table.bank_mutex);
421 hr_dev->qp_table.bank[bankid].inuse--;
422 mutex_unlock(&hr_dev->qp_table.bank_mutex);
425 static u32 proc_rq_sge(struct hns_roce_dev *dev, struct hns_roce_qp *hr_qp,
428 u32 max_sge = dev->caps.max_rq_sg;
430 if (dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
433 /* Reserve SGEs only for HIP08 in kernel; The userspace driver will
434 * calculate number of max_sge with reserved SGEs when allocating wqe
435 * buf, so there is no need to do this again in kernel. But the number
436 * may exceed the capacity of SGEs recorded in the firmware, so the
437 * kernel driver should just adapt the value accordingly.
440 max_sge = roundup_pow_of_two(max_sge + 1);
442 hr_qp->rq.rsv_sge = 1;
447 static int set_rq_size(struct hns_roce_dev *hr_dev, struct ib_qp_cap *cap,
448 struct hns_roce_qp *hr_qp, int has_rq, bool user)
450 u32 max_sge = proc_rq_sge(hr_dev, hr_qp, user);
453 /* If srq exist, set zero for relative number of rq */
455 hr_qp->rq.wqe_cnt = 0;
456 hr_qp->rq.max_gs = 0;
457 hr_qp->rq_inl_buf.wqe_cnt = 0;
458 cap->max_recv_wr = 0;
459 cap->max_recv_sge = 0;
464 /* Check the validity of QP support capacity */
465 if (!cap->max_recv_wr || cap->max_recv_wr > hr_dev->caps.max_wqes ||
466 cap->max_recv_sge > max_sge) {
467 ibdev_err(&hr_dev->ib_dev,
468 "RQ config error, depth = %u, sge = %u\n",
469 cap->max_recv_wr, cap->max_recv_sge);
473 cnt = roundup_pow_of_two(max(cap->max_recv_wr, hr_dev->caps.min_wqes));
474 if (cnt > hr_dev->caps.max_wqes) {
475 ibdev_err(&hr_dev->ib_dev, "rq depth %u too large\n",
480 hr_qp->rq.max_gs = roundup_pow_of_two(max(1U, cap->max_recv_sge) +
483 if (hr_dev->caps.max_rq_sg <= HNS_ROCE_SGE_IN_WQE)
484 hr_qp->rq.wqe_shift = ilog2(hr_dev->caps.max_rq_desc_sz);
486 hr_qp->rq.wqe_shift = ilog2(hr_dev->caps.max_rq_desc_sz *
489 hr_qp->rq.wqe_cnt = cnt;
490 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_RQ_INLINE &&
491 hr_qp->ibqp.qp_type != IB_QPT_UD &&
492 hr_qp->ibqp.qp_type != IB_QPT_GSI)
493 hr_qp->rq_inl_buf.wqe_cnt = cnt;
495 hr_qp->rq_inl_buf.wqe_cnt = 0;
497 cap->max_recv_wr = cnt;
498 cap->max_recv_sge = hr_qp->rq.max_gs - hr_qp->rq.rsv_sge;
503 static u32 get_wqe_ext_sge_cnt(struct hns_roce_qp *qp)
505 /* GSI/UD QP only has extended sge */
506 if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_UD)
507 return qp->sq.max_gs;
509 if (qp->sq.max_gs > HNS_ROCE_SGE_IN_WQE)
510 return qp->sq.max_gs - HNS_ROCE_SGE_IN_WQE;
515 static void set_ext_sge_param(struct hns_roce_dev *hr_dev, u32 sq_wqe_cnt,
516 struct hns_roce_qp *hr_qp, struct ib_qp_cap *cap)
521 hr_qp->sge.sge_shift = HNS_ROCE_SGE_SHIFT;
523 if (hr_dev->hw_rev == HNS_ROCE_HW_VER1) {
524 hr_qp->sq.max_gs = HNS_ROCE_SGE_IN_WQE;
528 hr_qp->sq.max_gs = max(1U, cap->max_send_sge);
530 wqe_sge_cnt = get_wqe_ext_sge_cnt(hr_qp);
532 /* If the number of extended sge is not zero, they MUST use the
533 * space of HNS_HW_PAGE_SIZE at least.
536 total_sge_cnt = roundup_pow_of_two(sq_wqe_cnt * wqe_sge_cnt);
537 hr_qp->sge.sge_cnt = max(total_sge_cnt,
538 (u32)HNS_HW_PAGE_SIZE / HNS_ROCE_SGE_SIZE);
542 static int check_sq_size_with_integrity(struct hns_roce_dev *hr_dev,
543 struct ib_qp_cap *cap,
544 struct hns_roce_ib_create_qp *ucmd)
546 u32 roundup_sq_stride = roundup_pow_of_two(hr_dev->caps.max_sq_desc_sz);
547 u8 max_sq_stride = ilog2(roundup_sq_stride);
549 /* Sanity check SQ size before proceeding */
550 if (ucmd->log_sq_stride > max_sq_stride ||
551 ucmd->log_sq_stride < HNS_ROCE_IB_MIN_SQ_STRIDE) {
552 ibdev_err(&hr_dev->ib_dev, "failed to check SQ stride size.\n");
556 if (cap->max_send_sge > hr_dev->caps.max_sq_sg) {
557 ibdev_err(&hr_dev->ib_dev, "failed to check SQ SGE size %u.\n",
565 static int set_user_sq_size(struct hns_roce_dev *hr_dev,
566 struct ib_qp_cap *cap, struct hns_roce_qp *hr_qp,
567 struct hns_roce_ib_create_qp *ucmd)
569 struct ib_device *ibdev = &hr_dev->ib_dev;
573 if (check_shl_overflow(1, ucmd->log_sq_bb_count, &cnt) ||
574 cnt > hr_dev->caps.max_wqes)
577 ret = check_sq_size_with_integrity(hr_dev, cap, ucmd);
579 ibdev_err(ibdev, "failed to check user SQ size, ret = %d.\n",
584 set_ext_sge_param(hr_dev, cnt, hr_qp, cap);
586 hr_qp->sq.wqe_shift = ucmd->log_sq_stride;
587 hr_qp->sq.wqe_cnt = cnt;
592 static int set_wqe_buf_attr(struct hns_roce_dev *hr_dev,
593 struct hns_roce_qp *hr_qp,
594 struct hns_roce_buf_attr *buf_attr)
599 hr_qp->buff_size = 0;
602 hr_qp->sq.offset = 0;
603 buf_size = to_hr_hem_entries_size(hr_qp->sq.wqe_cnt,
604 hr_qp->sq.wqe_shift);
605 if (buf_size > 0 && idx < ARRAY_SIZE(buf_attr->region)) {
606 buf_attr->region[idx].size = buf_size;
607 buf_attr->region[idx].hopnum = hr_dev->caps.wqe_sq_hop_num;
609 hr_qp->buff_size += buf_size;
612 /* extend SGE WQE in SQ */
613 hr_qp->sge.offset = hr_qp->buff_size;
614 buf_size = to_hr_hem_entries_size(hr_qp->sge.sge_cnt,
615 hr_qp->sge.sge_shift);
616 if (buf_size > 0 && idx < ARRAY_SIZE(buf_attr->region)) {
617 buf_attr->region[idx].size = buf_size;
618 buf_attr->region[idx].hopnum = hr_dev->caps.wqe_sge_hop_num;
620 hr_qp->buff_size += buf_size;
624 hr_qp->rq.offset = hr_qp->buff_size;
625 buf_size = to_hr_hem_entries_size(hr_qp->rq.wqe_cnt,
626 hr_qp->rq.wqe_shift);
627 if (buf_size > 0 && idx < ARRAY_SIZE(buf_attr->region)) {
628 buf_attr->region[idx].size = buf_size;
629 buf_attr->region[idx].hopnum = hr_dev->caps.wqe_rq_hop_num;
631 hr_qp->buff_size += buf_size;
634 if (hr_qp->buff_size < 1)
637 buf_attr->page_shift = HNS_HW_PAGE_SHIFT + hr_dev->caps.mtt_buf_pg_sz;
638 buf_attr->region_count = idx;
643 static int set_kernel_sq_size(struct hns_roce_dev *hr_dev,
644 struct ib_qp_cap *cap, struct hns_roce_qp *hr_qp)
646 struct ib_device *ibdev = &hr_dev->ib_dev;
649 if (!cap->max_send_wr || cap->max_send_wr > hr_dev->caps.max_wqes ||
650 cap->max_send_sge > hr_dev->caps.max_sq_sg) {
651 ibdev_err(ibdev, "failed to check SQ WR or SGE num.\n");
655 cnt = roundup_pow_of_two(max(cap->max_send_wr, hr_dev->caps.min_wqes));
656 if (cnt > hr_dev->caps.max_wqes) {
657 ibdev_err(ibdev, "failed to check WQE num, WQE num = %u.\n",
662 hr_qp->sq.wqe_shift = ilog2(hr_dev->caps.max_sq_desc_sz);
663 hr_qp->sq.wqe_cnt = cnt;
665 set_ext_sge_param(hr_dev, cnt, hr_qp, cap);
667 /* sync the parameters of kernel QP to user's configuration */
668 cap->max_send_wr = cnt;
669 cap->max_send_sge = hr_qp->sq.max_gs;
674 static int hns_roce_qp_has_sq(struct ib_qp_init_attr *attr)
676 if (attr->qp_type == IB_QPT_XRC_TGT || !attr->cap.max_send_wr)
682 static int hns_roce_qp_has_rq(struct ib_qp_init_attr *attr)
684 if (attr->qp_type == IB_QPT_XRC_INI ||
685 attr->qp_type == IB_QPT_XRC_TGT || attr->srq ||
686 !attr->cap.max_recv_wr)
692 static int alloc_rq_inline_buf(struct hns_roce_qp *hr_qp,
693 struct ib_qp_init_attr *init_attr)
695 u32 max_recv_sge = init_attr->cap.max_recv_sge;
696 u32 wqe_cnt = hr_qp->rq_inl_buf.wqe_cnt;
697 struct hns_roce_rinl_wqe *wqe_list;
700 /* allocate recv inline buf */
701 wqe_list = kcalloc(wqe_cnt, sizeof(struct hns_roce_rinl_wqe),
707 /* Allocate a continuous buffer for all inline sge we need */
708 wqe_list[0].sg_list = kcalloc(wqe_cnt, (max_recv_sge *
709 sizeof(struct hns_roce_rinl_sge)),
711 if (!wqe_list[0].sg_list)
714 /* Assign buffers of sg_list to each inline wqe */
715 for (i = 1; i < wqe_cnt; i++)
716 wqe_list[i].sg_list = &wqe_list[0].sg_list[i * max_recv_sge];
718 hr_qp->rq_inl_buf.wqe_list = wqe_list;
729 static void free_rq_inline_buf(struct hns_roce_qp *hr_qp)
731 if (hr_qp->rq_inl_buf.wqe_list)
732 kfree(hr_qp->rq_inl_buf.wqe_list[0].sg_list);
733 kfree(hr_qp->rq_inl_buf.wqe_list);
736 static int alloc_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
737 struct ib_qp_init_attr *init_attr,
738 struct ib_udata *udata, unsigned long addr)
740 struct ib_device *ibdev = &hr_dev->ib_dev;
741 struct hns_roce_buf_attr buf_attr = {};
744 if (!udata && hr_qp->rq_inl_buf.wqe_cnt) {
745 ret = alloc_rq_inline_buf(hr_qp, init_attr);
748 "failed to alloc inline buf, ret = %d.\n",
753 hr_qp->rq_inl_buf.wqe_list = NULL;
756 ret = set_wqe_buf_attr(hr_dev, hr_qp, &buf_attr);
758 ibdev_err(ibdev, "failed to split WQE buf, ret = %d.\n", ret);
761 ret = hns_roce_mtr_create(hr_dev, &hr_qp->mtr, &buf_attr,
762 PAGE_SHIFT + hr_dev->caps.mtt_ba_pg_sz,
765 ibdev_err(ibdev, "failed to create WQE mtr, ret = %d.\n", ret);
771 free_rq_inline_buf(hr_qp);
776 static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
778 hns_roce_mtr_destroy(hr_dev, &hr_qp->mtr);
779 free_rq_inline_buf(hr_qp);
782 static inline bool user_qp_has_sdb(struct hns_roce_dev *hr_dev,
783 struct ib_qp_init_attr *init_attr,
784 struct ib_udata *udata,
785 struct hns_roce_ib_create_qp_resp *resp,
786 struct hns_roce_ib_create_qp *ucmd)
788 return ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) &&
789 udata->outlen >= offsetofend(typeof(*resp), cap_flags) &&
790 hns_roce_qp_has_sq(init_attr) &&
791 udata->inlen >= offsetofend(typeof(*ucmd), sdb_addr));
794 static inline bool user_qp_has_rdb(struct hns_roce_dev *hr_dev,
795 struct ib_qp_init_attr *init_attr,
796 struct ib_udata *udata,
797 struct hns_roce_ib_create_qp_resp *resp)
799 return ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) &&
800 udata->outlen >= offsetofend(typeof(*resp), cap_flags) &&
801 hns_roce_qp_has_rq(init_attr));
804 static inline bool kernel_qp_has_rdb(struct hns_roce_dev *hr_dev,
805 struct ib_qp_init_attr *init_attr)
807 return ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) &&
808 hns_roce_qp_has_rq(init_attr));
811 static int alloc_qp_db(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
812 struct ib_qp_init_attr *init_attr,
813 struct ib_udata *udata,
814 struct hns_roce_ib_create_qp *ucmd,
815 struct hns_roce_ib_create_qp_resp *resp)
817 struct hns_roce_ucontext *uctx = rdma_udata_to_drv_context(
818 udata, struct hns_roce_ucontext, ibucontext);
819 struct ib_device *ibdev = &hr_dev->ib_dev;
822 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SDI_MODE)
823 hr_qp->en_flags |= HNS_ROCE_QP_CAP_OWNER_DB;
826 if (user_qp_has_sdb(hr_dev, init_attr, udata, resp, ucmd)) {
827 ret = hns_roce_db_map_user(uctx, ucmd->sdb_addr,
831 "failed to map user SQ doorbell, ret = %d.\n",
835 hr_qp->en_flags |= HNS_ROCE_QP_CAP_SQ_RECORD_DB;
836 resp->cap_flags |= HNS_ROCE_QP_CAP_SQ_RECORD_DB;
839 if (user_qp_has_rdb(hr_dev, init_attr, udata, resp)) {
840 ret = hns_roce_db_map_user(uctx, ucmd->db_addr,
844 "failed to map user RQ doorbell, ret = %d.\n",
848 hr_qp->en_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB;
849 resp->cap_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB;
852 if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
853 hr_qp->sq.db_reg = hr_dev->mem_base +
854 HNS_ROCE_DWQE_SIZE * hr_qp->qpn;
857 hr_dev->reg_base + hr_dev->sdb_offset +
858 DB_REG_OFFSET * hr_dev->priv_uar.index;
860 hr_qp->rq.db_reg = hr_dev->reg_base + hr_dev->odb_offset +
861 DB_REG_OFFSET * hr_dev->priv_uar.index;
863 if (kernel_qp_has_rdb(hr_dev, init_attr)) {
864 ret = hns_roce_alloc_db(hr_dev, &hr_qp->rdb, 0);
867 "failed to alloc kernel RQ doorbell, ret = %d.\n",
871 *hr_qp->rdb.db_record = 0;
872 hr_qp->en_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB;
878 if (udata && hr_qp->en_flags & HNS_ROCE_QP_CAP_SQ_RECORD_DB)
879 hns_roce_db_unmap_user(uctx, &hr_qp->sdb);
884 static void free_qp_db(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
885 struct ib_udata *udata)
887 struct hns_roce_ucontext *uctx = rdma_udata_to_drv_context(
888 udata, struct hns_roce_ucontext, ibucontext);
891 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_RQ_RECORD_DB)
892 hns_roce_db_unmap_user(uctx, &hr_qp->rdb);
893 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_SQ_RECORD_DB)
894 hns_roce_db_unmap_user(uctx, &hr_qp->sdb);
896 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_RQ_RECORD_DB)
897 hns_roce_free_db(hr_dev, &hr_qp->rdb);
901 static int alloc_kernel_wrid(struct hns_roce_dev *hr_dev,
902 struct hns_roce_qp *hr_qp)
904 struct ib_device *ibdev = &hr_dev->ib_dev;
909 sq_wrid = kcalloc(hr_qp->sq.wqe_cnt, sizeof(u64), GFP_KERNEL);
910 if (ZERO_OR_NULL_PTR(sq_wrid)) {
911 ibdev_err(ibdev, "failed to alloc SQ wrid.\n");
915 if (hr_qp->rq.wqe_cnt) {
916 rq_wrid = kcalloc(hr_qp->rq.wqe_cnt, sizeof(u64), GFP_KERNEL);
917 if (ZERO_OR_NULL_PTR(rq_wrid)) {
918 ibdev_err(ibdev, "failed to alloc RQ wrid.\n");
924 hr_qp->sq.wrid = sq_wrid;
925 hr_qp->rq.wrid = rq_wrid;
933 static void free_kernel_wrid(struct hns_roce_qp *hr_qp)
935 kfree(hr_qp->rq.wrid);
936 kfree(hr_qp->sq.wrid);
939 static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
940 struct ib_qp_init_attr *init_attr,
941 struct ib_udata *udata,
942 struct hns_roce_ib_create_qp *ucmd)
944 struct ib_device *ibdev = &hr_dev->ib_dev;
947 hr_qp->ibqp.qp_type = init_attr->qp_type;
949 if (init_attr->cap.max_inline_data > hr_dev->caps.max_sq_inline)
950 init_attr->cap.max_inline_data = hr_dev->caps.max_sq_inline;
952 hr_qp->max_inline_data = init_attr->cap.max_inline_data;
954 if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
955 hr_qp->sq_signal_bits = IB_SIGNAL_ALL_WR;
957 hr_qp->sq_signal_bits = IB_SIGNAL_REQ_WR;
959 ret = set_rq_size(hr_dev, &init_attr->cap, hr_qp,
960 hns_roce_qp_has_rq(init_attr), !!udata);
962 ibdev_err(ibdev, "failed to set user RQ size, ret = %d.\n",
968 ret = ib_copy_from_udata(ucmd, udata,
969 min(udata->inlen, sizeof(*ucmd)));
972 "failed to copy QP ucmd, ret = %d\n", ret);
976 ret = set_user_sq_size(hr_dev, &init_attr->cap, hr_qp, ucmd);
979 "failed to set user SQ size, ret = %d.\n",
982 ret = set_kernel_sq_size(hr_dev, &init_attr->cap, hr_qp);
985 "failed to set kernel SQ size, ret = %d.\n",
992 static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
994 struct ib_qp_init_attr *init_attr,
995 struct ib_udata *udata,
996 struct hns_roce_qp *hr_qp)
998 struct hns_roce_ib_create_qp_resp resp = {};
999 struct ib_device *ibdev = &hr_dev->ib_dev;
1000 struct hns_roce_ib_create_qp ucmd;
1003 mutex_init(&hr_qp->mutex);
1004 spin_lock_init(&hr_qp->sq.lock);
1005 spin_lock_init(&hr_qp->rq.lock);
1007 hr_qp->state = IB_QPS_RESET;
1008 hr_qp->flush_flag = 0;
1010 if (init_attr->create_flags)
1013 ret = set_qp_param(hr_dev, hr_qp, init_attr, udata, &ucmd);
1015 ibdev_err(ibdev, "failed to set QP param, ret = %d.\n", ret);
1020 ret = alloc_kernel_wrid(hr_dev, hr_qp);
1022 ibdev_err(ibdev, "failed to alloc wrid, ret = %d.\n",
1028 ret = alloc_qp_buf(hr_dev, hr_qp, init_attr, udata, ucmd.buf_addr);
1030 ibdev_err(ibdev, "failed to alloc QP buffer, ret = %d.\n", ret);
1034 ret = alloc_qpn(hr_dev, hr_qp);
1036 ibdev_err(ibdev, "failed to alloc QPN, ret = %d.\n", ret);
1040 ret = alloc_qp_db(hr_dev, hr_qp, init_attr, udata, &ucmd, &resp);
1042 ibdev_err(ibdev, "failed to alloc QP doorbell, ret = %d.\n",
1047 ret = alloc_qpc(hr_dev, hr_qp);
1049 ibdev_err(ibdev, "failed to alloc QP context, ret = %d.\n",
1054 ret = hns_roce_qp_store(hr_dev, hr_qp, init_attr);
1056 ibdev_err(ibdev, "failed to store QP, ret = %d.\n", ret);
1061 ret = ib_copy_to_udata(udata, &resp,
1062 min(udata->outlen, sizeof(resp)));
1064 ibdev_err(ibdev, "copy qp resp failed!\n");
1069 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL) {
1070 ret = hr_dev->hw->qp_flow_control_init(hr_dev, hr_qp);
1075 hr_qp->ibqp.qp_num = hr_qp->qpn;
1076 hr_qp->event = hns_roce_ib_qp_event;
1077 refcount_set(&hr_qp->refcount, 1);
1078 init_completion(&hr_qp->free);
1083 hns_roce_qp_remove(hr_dev, hr_qp);
1085 free_qpc(hr_dev, hr_qp);
1087 free_qp_db(hr_dev, hr_qp, udata);
1089 free_qpn(hr_dev, hr_qp);
1091 free_qp_buf(hr_dev, hr_qp);
1093 free_kernel_wrid(hr_qp);
1097 void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
1098 struct ib_udata *udata)
1100 if (refcount_dec_and_test(&hr_qp->refcount))
1101 complete(&hr_qp->free);
1102 wait_for_completion(&hr_qp->free);
1104 free_qpc(hr_dev, hr_qp);
1105 free_qpn(hr_dev, hr_qp);
1106 free_qp_buf(hr_dev, hr_qp);
1107 free_kernel_wrid(hr_qp);
1108 free_qp_db(hr_dev, hr_qp, udata);
1113 static int check_qp_type(struct hns_roce_dev *hr_dev, enum ib_qp_type type,
1117 case IB_QPT_XRC_INI:
1118 case IB_QPT_XRC_TGT:
1119 if (!(hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC))
1123 if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 &&
1137 ibdev_err(&hr_dev->ib_dev, "not support QP type %d\n", type);
1142 struct ib_qp *hns_roce_create_qp(struct ib_pd *pd,
1143 struct ib_qp_init_attr *init_attr,
1144 struct ib_udata *udata)
1146 struct ib_device *ibdev = pd ? pd->device : init_attr->xrcd->device;
1147 struct hns_roce_dev *hr_dev = to_hr_dev(ibdev);
1148 struct hns_roce_qp *hr_qp;
1151 ret = check_qp_type(hr_dev, init_attr->qp_type, !!udata);
1153 return ERR_PTR(ret);
1155 hr_qp = kzalloc(sizeof(*hr_qp), GFP_KERNEL);
1157 return ERR_PTR(-ENOMEM);
1159 if (init_attr->qp_type == IB_QPT_XRC_INI)
1160 init_attr->recv_cq = NULL;
1162 if (init_attr->qp_type == IB_QPT_XRC_TGT) {
1163 hr_qp->xrcdn = to_hr_xrcd(init_attr->xrcd)->xrcdn;
1164 init_attr->recv_cq = NULL;
1165 init_attr->send_cq = NULL;
1168 if (init_attr->qp_type == IB_QPT_GSI) {
1169 hr_qp->port = init_attr->port_num - 1;
1170 hr_qp->phy_port = hr_dev->iboe.phy_port[hr_qp->port];
1173 ret = hns_roce_create_qp_common(hr_dev, pd, init_attr, udata, hr_qp);
1175 ibdev_err(ibdev, "Create QP type 0x%x failed(%d)\n",
1176 init_attr->qp_type, ret);
1179 return ERR_PTR(ret);
1182 return &hr_qp->ibqp;
1185 int to_hr_qp_type(int qp_type)
1189 return SERV_TYPE_RC;
1192 return SERV_TYPE_UD;
1193 case IB_QPT_XRC_INI:
1194 case IB_QPT_XRC_TGT:
1195 return SERV_TYPE_XRC;
1201 static int check_mtu_validate(struct hns_roce_dev *hr_dev,
1202 struct hns_roce_qp *hr_qp,
1203 struct ib_qp_attr *attr, int attr_mask)
1205 enum ib_mtu active_mtu;
1208 p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port;
1209 active_mtu = iboe_get_mtu(hr_dev->iboe.netdevs[p]->mtu);
1211 if ((hr_dev->caps.max_mtu >= IB_MTU_2048 &&
1212 attr->path_mtu > hr_dev->caps.max_mtu) ||
1213 attr->path_mtu < IB_MTU_256 || attr->path_mtu > active_mtu) {
1214 ibdev_err(&hr_dev->ib_dev,
1215 "attr path_mtu(%d)invalid while modify qp",
1223 static int hns_roce_check_qp_attr(struct ib_qp *ibqp, struct ib_qp_attr *attr,
1226 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
1227 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
1230 if ((attr_mask & IB_QP_PORT) &&
1231 (attr->port_num == 0 || attr->port_num > hr_dev->caps.num_ports)) {
1232 ibdev_err(&hr_dev->ib_dev, "invalid attr, port_num = %u.\n",
1237 if (attr_mask & IB_QP_PKEY_INDEX) {
1238 p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port;
1239 if (attr->pkey_index >= hr_dev->caps.pkey_table_len[p]) {
1240 ibdev_err(&hr_dev->ib_dev,
1241 "invalid attr, pkey_index = %u.\n",
1247 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&
1248 attr->max_rd_atomic > hr_dev->caps.max_qp_init_rdma) {
1249 ibdev_err(&hr_dev->ib_dev,
1250 "invalid attr, max_rd_atomic = %u.\n",
1251 attr->max_rd_atomic);
1255 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
1256 attr->max_dest_rd_atomic > hr_dev->caps.max_qp_dest_rdma) {
1257 ibdev_err(&hr_dev->ib_dev,
1258 "invalid attr, max_dest_rd_atomic = %u.\n",
1259 attr->max_dest_rd_atomic);
1263 if (attr_mask & IB_QP_PATH_MTU)
1264 return check_mtu_validate(hr_dev, hr_qp, attr, attr_mask);
1269 int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
1270 int attr_mask, struct ib_udata *udata)
1272 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
1273 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
1274 enum ib_qp_state cur_state, new_state;
1277 mutex_lock(&hr_qp->mutex);
1279 if (attr_mask & IB_QP_CUR_STATE && attr->cur_qp_state != hr_qp->state)
1282 cur_state = hr_qp->state;
1283 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
1285 if (ibqp->uobject &&
1286 (attr_mask & IB_QP_STATE) && new_state == IB_QPS_ERR) {
1287 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_SQ_RECORD_DB) {
1288 hr_qp->sq.head = *(int *)(hr_qp->sdb.virt_addr);
1290 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_RQ_RECORD_DB)
1291 hr_qp->rq.head = *(int *)(hr_qp->rdb.virt_addr);
1293 ibdev_warn(&hr_dev->ib_dev,
1294 "flush cqe is not supported in userspace!\n");
1299 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
1301 ibdev_err(&hr_dev->ib_dev, "ib_modify_qp_is_ok failed\n");
1305 ret = hns_roce_check_qp_attr(ibqp, attr, attr_mask);
1309 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
1310 if (hr_dev->hw_rev == HNS_ROCE_HW_VER1) {
1312 ibdev_err(&hr_dev->ib_dev,
1313 "RST2RST state is not supported\n");
1321 ret = hr_dev->hw->modify_qp(ibqp, attr, attr_mask, cur_state,
1325 mutex_unlock(&hr_qp->mutex);
1330 void hns_roce_lock_cqs(struct hns_roce_cq *send_cq, struct hns_roce_cq *recv_cq)
1331 __acquires(&send_cq->lock) __acquires(&recv_cq->lock)
1333 if (unlikely(send_cq == NULL && recv_cq == NULL)) {
1334 __acquire(&send_cq->lock);
1335 __acquire(&recv_cq->lock);
1336 } else if (unlikely(send_cq != NULL && recv_cq == NULL)) {
1337 spin_lock_irq(&send_cq->lock);
1338 __acquire(&recv_cq->lock);
1339 } else if (unlikely(send_cq == NULL && recv_cq != NULL)) {
1340 spin_lock_irq(&recv_cq->lock);
1341 __acquire(&send_cq->lock);
1342 } else if (send_cq == recv_cq) {
1343 spin_lock_irq(&send_cq->lock);
1344 __acquire(&recv_cq->lock);
1345 } else if (send_cq->cqn < recv_cq->cqn) {
1346 spin_lock_irq(&send_cq->lock);
1347 spin_lock_nested(&recv_cq->lock, SINGLE_DEPTH_NESTING);
1349 spin_lock_irq(&recv_cq->lock);
1350 spin_lock_nested(&send_cq->lock, SINGLE_DEPTH_NESTING);
1354 void hns_roce_unlock_cqs(struct hns_roce_cq *send_cq,
1355 struct hns_roce_cq *recv_cq) __releases(&send_cq->lock)
1356 __releases(&recv_cq->lock)
1358 if (unlikely(send_cq == NULL && recv_cq == NULL)) {
1359 __release(&recv_cq->lock);
1360 __release(&send_cq->lock);
1361 } else if (unlikely(send_cq != NULL && recv_cq == NULL)) {
1362 __release(&recv_cq->lock);
1363 spin_unlock(&send_cq->lock);
1364 } else if (unlikely(send_cq == NULL && recv_cq != NULL)) {
1365 __release(&send_cq->lock);
1366 spin_unlock(&recv_cq->lock);
1367 } else if (send_cq == recv_cq) {
1368 __release(&recv_cq->lock);
1369 spin_unlock_irq(&send_cq->lock);
1370 } else if (send_cq->cqn < recv_cq->cqn) {
1371 spin_unlock(&recv_cq->lock);
1372 spin_unlock_irq(&send_cq->lock);
1374 spin_unlock(&send_cq->lock);
1375 spin_unlock_irq(&recv_cq->lock);
1379 static inline void *get_wqe(struct hns_roce_qp *hr_qp, int offset)
1381 return hns_roce_buf_offset(hr_qp->mtr.kmem, offset);
1384 void *hns_roce_get_recv_wqe(struct hns_roce_qp *hr_qp, unsigned int n)
1386 return get_wqe(hr_qp, hr_qp->rq.offset + (n << hr_qp->rq.wqe_shift));
1389 void *hns_roce_get_send_wqe(struct hns_roce_qp *hr_qp, unsigned int n)
1391 return get_wqe(hr_qp, hr_qp->sq.offset + (n << hr_qp->sq.wqe_shift));
1394 void *hns_roce_get_extend_sge(struct hns_roce_qp *hr_qp, unsigned int n)
1396 return get_wqe(hr_qp, hr_qp->sge.offset + (n << hr_qp->sge.sge_shift));
1399 bool hns_roce_wq_overflow(struct hns_roce_wq *hr_wq, u32 nreq,
1400 struct ib_cq *ib_cq)
1402 struct hns_roce_cq *hr_cq;
1405 cur = hr_wq->head - hr_wq->tail;
1406 if (likely(cur + nreq < hr_wq->wqe_cnt))
1409 hr_cq = to_hr_cq(ib_cq);
1410 spin_lock(&hr_cq->lock);
1411 cur = hr_wq->head - hr_wq->tail;
1412 spin_unlock(&hr_cq->lock);
1414 return cur + nreq >= hr_wq->wqe_cnt;
1417 void hns_roce_init_qp_table(struct hns_roce_dev *hr_dev)
1419 struct hns_roce_qp_table *qp_table = &hr_dev->qp_table;
1420 unsigned int reserved_from_bot;
1423 mutex_init(&qp_table->scc_mutex);
1424 mutex_init(&qp_table->bank_mutex);
1425 xa_init(&hr_dev->qp_table_xa);
1427 reserved_from_bot = hr_dev->caps.reserved_qps;
1429 for (i = 0; i < reserved_from_bot; i++) {
1430 hr_dev->qp_table.bank[get_qp_bankid(i)].inuse++;
1431 hr_dev->qp_table.bank[get_qp_bankid(i)].min++;
1434 for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++) {
1435 ida_init(&hr_dev->qp_table.bank[i].ida);
1436 hr_dev->qp_table.bank[i].max = hr_dev->caps.num_qps /
1437 HNS_ROCE_QP_BANK_NUM - 1;
1438 hr_dev->qp_table.bank[i].next = hr_dev->qp_table.bank[i].min;
1442 void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev)
1446 for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++)
1447 ida_destroy(&hr_dev->qp_table.bank[i].ida);