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 (atomic_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 atomic_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 atomic_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 (atomic_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 & (hr_dev->caps.num_qps - 1));
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) {
652 "failed to check SQ WR or SGE num, ret = %d.\n",
657 cnt = roundup_pow_of_two(max(cap->max_send_wr, hr_dev->caps.min_wqes));
658 if (cnt > hr_dev->caps.max_wqes) {
659 ibdev_err(ibdev, "failed to check WQE num, WQE num = %u.\n",
664 hr_qp->sq.wqe_shift = ilog2(hr_dev->caps.max_sq_desc_sz);
665 hr_qp->sq.wqe_cnt = cnt;
667 set_ext_sge_param(hr_dev, cnt, hr_qp, cap);
669 /* sync the parameters of kernel QP to user's configuration */
670 cap->max_send_wr = cnt;
671 cap->max_send_sge = hr_qp->sq.max_gs;
676 static int hns_roce_qp_has_sq(struct ib_qp_init_attr *attr)
678 if (attr->qp_type == IB_QPT_XRC_TGT || !attr->cap.max_send_wr)
684 static int hns_roce_qp_has_rq(struct ib_qp_init_attr *attr)
686 if (attr->qp_type == IB_QPT_XRC_INI ||
687 attr->qp_type == IB_QPT_XRC_TGT || attr->srq ||
688 !attr->cap.max_recv_wr)
694 static int alloc_rq_inline_buf(struct hns_roce_qp *hr_qp,
695 struct ib_qp_init_attr *init_attr)
697 u32 max_recv_sge = init_attr->cap.max_recv_sge;
698 u32 wqe_cnt = hr_qp->rq_inl_buf.wqe_cnt;
699 struct hns_roce_rinl_wqe *wqe_list;
702 /* allocate recv inline buf */
703 wqe_list = kcalloc(wqe_cnt, sizeof(struct hns_roce_rinl_wqe),
709 /* Allocate a continuous buffer for all inline sge we need */
710 wqe_list[0].sg_list = kcalloc(wqe_cnt, (max_recv_sge *
711 sizeof(struct hns_roce_rinl_sge)),
713 if (!wqe_list[0].sg_list)
716 /* Assign buffers of sg_list to each inline wqe */
717 for (i = 1; i < wqe_cnt; i++)
718 wqe_list[i].sg_list = &wqe_list[0].sg_list[i * max_recv_sge];
720 hr_qp->rq_inl_buf.wqe_list = wqe_list;
731 static void free_rq_inline_buf(struct hns_roce_qp *hr_qp)
733 if (hr_qp->rq_inl_buf.wqe_list)
734 kfree(hr_qp->rq_inl_buf.wqe_list[0].sg_list);
735 kfree(hr_qp->rq_inl_buf.wqe_list);
738 static int alloc_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
739 struct ib_qp_init_attr *init_attr,
740 struct ib_udata *udata, unsigned long addr)
742 struct ib_device *ibdev = &hr_dev->ib_dev;
743 struct hns_roce_buf_attr buf_attr = {};
746 if (!udata && hr_qp->rq_inl_buf.wqe_cnt) {
747 ret = alloc_rq_inline_buf(hr_qp, init_attr);
750 "failed to alloc inline buf, ret = %d.\n",
755 hr_qp->rq_inl_buf.wqe_list = NULL;
758 ret = set_wqe_buf_attr(hr_dev, hr_qp, &buf_attr);
760 ibdev_err(ibdev, "failed to split WQE buf, ret = %d.\n", ret);
763 ret = hns_roce_mtr_create(hr_dev, &hr_qp->mtr, &buf_attr,
764 HNS_HW_PAGE_SHIFT + hr_dev->caps.mtt_ba_pg_sz,
767 ibdev_err(ibdev, "failed to create WQE mtr, ret = %d.\n", ret);
773 free_rq_inline_buf(hr_qp);
778 static void free_qp_buf(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp)
780 hns_roce_mtr_destroy(hr_dev, &hr_qp->mtr);
781 free_rq_inline_buf(hr_qp);
784 static inline bool user_qp_has_sdb(struct hns_roce_dev *hr_dev,
785 struct ib_qp_init_attr *init_attr,
786 struct ib_udata *udata,
787 struct hns_roce_ib_create_qp_resp *resp,
788 struct hns_roce_ib_create_qp *ucmd)
790 return ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) &&
791 udata->outlen >= offsetofend(typeof(*resp), cap_flags) &&
792 hns_roce_qp_has_sq(init_attr) &&
793 udata->inlen >= offsetofend(typeof(*ucmd), sdb_addr));
796 static inline bool user_qp_has_rdb(struct hns_roce_dev *hr_dev,
797 struct ib_qp_init_attr *init_attr,
798 struct ib_udata *udata,
799 struct hns_roce_ib_create_qp_resp *resp)
801 return ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) &&
802 udata->outlen >= offsetofend(typeof(*resp), cap_flags) &&
803 hns_roce_qp_has_rq(init_attr));
806 static inline bool kernel_qp_has_rdb(struct hns_roce_dev *hr_dev,
807 struct ib_qp_init_attr *init_attr)
809 return ((hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_RECORD_DB) &&
810 hns_roce_qp_has_rq(init_attr));
813 static int alloc_qp_db(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
814 struct ib_qp_init_attr *init_attr,
815 struct ib_udata *udata,
816 struct hns_roce_ib_create_qp *ucmd,
817 struct hns_roce_ib_create_qp_resp *resp)
819 struct hns_roce_ucontext *uctx = rdma_udata_to_drv_context(
820 udata, struct hns_roce_ucontext, ibucontext);
821 struct ib_device *ibdev = &hr_dev->ib_dev;
824 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_SDI_MODE)
825 hr_qp->en_flags |= HNS_ROCE_QP_CAP_OWNER_DB;
828 if (user_qp_has_sdb(hr_dev, init_attr, udata, resp, ucmd)) {
829 ret = hns_roce_db_map_user(uctx, udata, ucmd->sdb_addr,
833 "failed to map user SQ doorbell, ret = %d.\n",
837 hr_qp->en_flags |= HNS_ROCE_QP_CAP_SQ_RECORD_DB;
838 resp->cap_flags |= HNS_ROCE_QP_CAP_SQ_RECORD_DB;
841 if (user_qp_has_rdb(hr_dev, init_attr, udata, resp)) {
842 ret = hns_roce_db_map_user(uctx, udata, ucmd->db_addr,
846 "failed to map user RQ doorbell, ret = %d.\n",
850 hr_qp->en_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB;
851 resp->cap_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB;
854 if (hr_dev->pci_dev->revision >= PCI_REVISION_ID_HIP09)
855 hr_qp->sq.db_reg = hr_dev->mem_base +
856 HNS_ROCE_DWQE_SIZE * hr_qp->qpn;
859 hr_dev->reg_base + hr_dev->sdb_offset +
860 DB_REG_OFFSET * hr_dev->priv_uar.index;
862 hr_qp->rq.db_reg = hr_dev->reg_base + hr_dev->odb_offset +
863 DB_REG_OFFSET * hr_dev->priv_uar.index;
865 if (kernel_qp_has_rdb(hr_dev, init_attr)) {
866 ret = hns_roce_alloc_db(hr_dev, &hr_qp->rdb, 0);
869 "failed to alloc kernel RQ doorbell, ret = %d.\n",
873 *hr_qp->rdb.db_record = 0;
874 hr_qp->en_flags |= HNS_ROCE_QP_CAP_RQ_RECORD_DB;
880 if (udata && hr_qp->en_flags & HNS_ROCE_QP_CAP_SQ_RECORD_DB)
881 hns_roce_db_unmap_user(uctx, &hr_qp->sdb);
886 static void free_qp_db(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
887 struct ib_udata *udata)
889 struct hns_roce_ucontext *uctx = rdma_udata_to_drv_context(
890 udata, struct hns_roce_ucontext, ibucontext);
893 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_RQ_RECORD_DB)
894 hns_roce_db_unmap_user(uctx, &hr_qp->rdb);
895 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_SQ_RECORD_DB)
896 hns_roce_db_unmap_user(uctx, &hr_qp->sdb);
898 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_RQ_RECORD_DB)
899 hns_roce_free_db(hr_dev, &hr_qp->rdb);
903 static int alloc_kernel_wrid(struct hns_roce_dev *hr_dev,
904 struct hns_roce_qp *hr_qp)
906 struct ib_device *ibdev = &hr_dev->ib_dev;
911 sq_wrid = kcalloc(hr_qp->sq.wqe_cnt, sizeof(u64), GFP_KERNEL);
912 if (ZERO_OR_NULL_PTR(sq_wrid)) {
913 ibdev_err(ibdev, "failed to alloc SQ wrid.\n");
917 if (hr_qp->rq.wqe_cnt) {
918 rq_wrid = kcalloc(hr_qp->rq.wqe_cnt, sizeof(u64), GFP_KERNEL);
919 if (ZERO_OR_NULL_PTR(rq_wrid)) {
920 ibdev_err(ibdev, "failed to alloc RQ wrid.\n");
926 hr_qp->sq.wrid = sq_wrid;
927 hr_qp->rq.wrid = rq_wrid;
935 static void free_kernel_wrid(struct hns_roce_qp *hr_qp)
937 kfree(hr_qp->rq.wrid);
938 kfree(hr_qp->sq.wrid);
941 static int set_qp_param(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
942 struct ib_qp_init_attr *init_attr,
943 struct ib_udata *udata,
944 struct hns_roce_ib_create_qp *ucmd)
946 struct ib_device *ibdev = &hr_dev->ib_dev;
949 hr_qp->ibqp.qp_type = init_attr->qp_type;
951 if (init_attr->cap.max_inline_data > hr_dev->caps.max_sq_inline)
952 init_attr->cap.max_inline_data = hr_dev->caps.max_sq_inline;
954 hr_qp->max_inline_data = init_attr->cap.max_inline_data;
956 if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR)
957 hr_qp->sq_signal_bits = IB_SIGNAL_ALL_WR;
959 hr_qp->sq_signal_bits = IB_SIGNAL_REQ_WR;
961 ret = set_rq_size(hr_dev, &init_attr->cap, hr_qp,
962 hns_roce_qp_has_rq(init_attr), !!udata);
964 ibdev_err(ibdev, "failed to set user RQ size, ret = %d.\n",
970 ret = ib_copy_from_udata(ucmd, udata,
971 min(udata->inlen, sizeof(*ucmd)));
974 "failed to copy QP ucmd, ret = %d\n", ret);
978 ret = set_user_sq_size(hr_dev, &init_attr->cap, hr_qp, ucmd);
981 "failed to set user SQ size, ret = %d.\n",
984 ret = set_kernel_sq_size(hr_dev, &init_attr->cap, hr_qp);
987 "failed to set kernel SQ size, ret = %d.\n",
994 static int hns_roce_create_qp_common(struct hns_roce_dev *hr_dev,
996 struct ib_qp_init_attr *init_attr,
997 struct ib_udata *udata,
998 struct hns_roce_qp *hr_qp)
1000 struct hns_roce_ib_create_qp_resp resp = {};
1001 struct ib_device *ibdev = &hr_dev->ib_dev;
1002 struct hns_roce_ib_create_qp ucmd;
1005 mutex_init(&hr_qp->mutex);
1006 spin_lock_init(&hr_qp->sq.lock);
1007 spin_lock_init(&hr_qp->rq.lock);
1009 hr_qp->state = IB_QPS_RESET;
1010 hr_qp->flush_flag = 0;
1012 if (init_attr->create_flags)
1015 ret = set_qp_param(hr_dev, hr_qp, init_attr, udata, &ucmd);
1017 ibdev_err(ibdev, "failed to set QP param, ret = %d.\n", ret);
1022 ret = alloc_kernel_wrid(hr_dev, hr_qp);
1024 ibdev_err(ibdev, "failed to alloc wrid, ret = %d.\n",
1030 ret = alloc_qp_buf(hr_dev, hr_qp, init_attr, udata, ucmd.buf_addr);
1032 ibdev_err(ibdev, "failed to alloc QP buffer, ret = %d.\n", ret);
1036 ret = alloc_qpn(hr_dev, hr_qp);
1038 ibdev_err(ibdev, "failed to alloc QPN, ret = %d.\n", ret);
1042 ret = alloc_qp_db(hr_dev, hr_qp, init_attr, udata, &ucmd, &resp);
1044 ibdev_err(ibdev, "failed to alloc QP doorbell, ret = %d.\n",
1049 ret = alloc_qpc(hr_dev, hr_qp);
1051 ibdev_err(ibdev, "failed to alloc QP context, ret = %d.\n",
1056 ret = hns_roce_qp_store(hr_dev, hr_qp, init_attr);
1058 ibdev_err(ibdev, "failed to store QP, ret = %d.\n", ret);
1063 ret = ib_copy_to_udata(udata, &resp,
1064 min(udata->outlen, sizeof(resp)));
1066 ibdev_err(ibdev, "copy qp resp failed!\n");
1071 if (hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_QP_FLOW_CTRL) {
1072 ret = hr_dev->hw->qp_flow_control_init(hr_dev, hr_qp);
1077 hr_qp->ibqp.qp_num = hr_qp->qpn;
1078 hr_qp->event = hns_roce_ib_qp_event;
1079 atomic_set(&hr_qp->refcount, 1);
1080 init_completion(&hr_qp->free);
1085 hns_roce_qp_remove(hr_dev, hr_qp);
1087 free_qpc(hr_dev, hr_qp);
1089 free_qp_db(hr_dev, hr_qp, udata);
1091 free_qpn(hr_dev, hr_qp);
1093 free_qp_buf(hr_dev, hr_qp);
1095 free_kernel_wrid(hr_qp);
1099 void hns_roce_qp_destroy(struct hns_roce_dev *hr_dev, struct hns_roce_qp *hr_qp,
1100 struct ib_udata *udata)
1102 if (atomic_dec_and_test(&hr_qp->refcount))
1103 complete(&hr_qp->free);
1104 wait_for_completion(&hr_qp->free);
1106 free_qpc(hr_dev, hr_qp);
1107 free_qpn(hr_dev, hr_qp);
1108 free_qp_buf(hr_dev, hr_qp);
1109 free_kernel_wrid(hr_qp);
1110 free_qp_db(hr_dev, hr_qp, udata);
1115 static int check_qp_type(struct hns_roce_dev *hr_dev, enum ib_qp_type type,
1119 case IB_QPT_XRC_INI:
1120 case IB_QPT_XRC_TGT:
1121 if (!(hr_dev->caps.flags & HNS_ROCE_CAP_FLAG_XRC))
1125 if (hr_dev->pci_dev->revision <= PCI_REVISION_ID_HIP08 &&
1139 ibdev_err(&hr_dev->ib_dev, "not support QP type %d\n", type);
1144 struct ib_qp *hns_roce_create_qp(struct ib_pd *pd,
1145 struct ib_qp_init_attr *init_attr,
1146 struct ib_udata *udata)
1148 struct ib_device *ibdev = pd ? pd->device : init_attr->xrcd->device;
1149 struct hns_roce_dev *hr_dev = to_hr_dev(ibdev);
1150 struct hns_roce_qp *hr_qp;
1153 ret = check_qp_type(hr_dev, init_attr->qp_type, !!udata);
1155 return ERR_PTR(ret);
1157 hr_qp = kzalloc(sizeof(*hr_qp), GFP_KERNEL);
1159 return ERR_PTR(-ENOMEM);
1161 if (init_attr->qp_type == IB_QPT_XRC_INI)
1162 init_attr->recv_cq = NULL;
1164 if (init_attr->qp_type == IB_QPT_XRC_TGT) {
1165 hr_qp->xrcdn = to_hr_xrcd(init_attr->xrcd)->xrcdn;
1166 init_attr->recv_cq = NULL;
1167 init_attr->send_cq = NULL;
1170 if (init_attr->qp_type == IB_QPT_GSI) {
1171 hr_qp->port = init_attr->port_num - 1;
1172 hr_qp->phy_port = hr_dev->iboe.phy_port[hr_qp->port];
1175 ret = hns_roce_create_qp_common(hr_dev, pd, init_attr, udata, hr_qp);
1177 ibdev_err(ibdev, "Create QP type 0x%x failed(%d)\n",
1178 init_attr->qp_type, ret);
1181 return ERR_PTR(ret);
1184 return &hr_qp->ibqp;
1187 int to_hr_qp_type(int qp_type)
1191 return SERV_TYPE_RC;
1194 return SERV_TYPE_UD;
1195 case IB_QPT_XRC_INI:
1196 case IB_QPT_XRC_TGT:
1197 return SERV_TYPE_XRC;
1203 static int check_mtu_validate(struct hns_roce_dev *hr_dev,
1204 struct hns_roce_qp *hr_qp,
1205 struct ib_qp_attr *attr, int attr_mask)
1207 enum ib_mtu active_mtu;
1210 p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port;
1211 active_mtu = iboe_get_mtu(hr_dev->iboe.netdevs[p]->mtu);
1213 if ((hr_dev->caps.max_mtu >= IB_MTU_2048 &&
1214 attr->path_mtu > hr_dev->caps.max_mtu) ||
1215 attr->path_mtu < IB_MTU_256 || attr->path_mtu > active_mtu) {
1216 ibdev_err(&hr_dev->ib_dev,
1217 "attr path_mtu(%d)invalid while modify qp",
1225 static int hns_roce_check_qp_attr(struct ib_qp *ibqp, struct ib_qp_attr *attr,
1228 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
1229 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
1232 if ((attr_mask & IB_QP_PORT) &&
1233 (attr->port_num == 0 || attr->port_num > hr_dev->caps.num_ports)) {
1234 ibdev_err(&hr_dev->ib_dev, "invalid attr, port_num = %u.\n",
1239 if (attr_mask & IB_QP_PKEY_INDEX) {
1240 p = attr_mask & IB_QP_PORT ? (attr->port_num - 1) : hr_qp->port;
1241 if (attr->pkey_index >= hr_dev->caps.pkey_table_len[p]) {
1242 ibdev_err(&hr_dev->ib_dev,
1243 "invalid attr, pkey_index = %u.\n",
1249 if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC &&
1250 attr->max_rd_atomic > hr_dev->caps.max_qp_init_rdma) {
1251 ibdev_err(&hr_dev->ib_dev,
1252 "invalid attr, max_rd_atomic = %u.\n",
1253 attr->max_rd_atomic);
1257 if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC &&
1258 attr->max_dest_rd_atomic > hr_dev->caps.max_qp_dest_rdma) {
1259 ibdev_err(&hr_dev->ib_dev,
1260 "invalid attr, max_dest_rd_atomic = %u.\n",
1261 attr->max_dest_rd_atomic);
1265 if (attr_mask & IB_QP_PATH_MTU)
1266 return check_mtu_validate(hr_dev, hr_qp, attr, attr_mask);
1271 int hns_roce_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
1272 int attr_mask, struct ib_udata *udata)
1274 struct hns_roce_dev *hr_dev = to_hr_dev(ibqp->device);
1275 struct hns_roce_qp *hr_qp = to_hr_qp(ibqp);
1276 enum ib_qp_state cur_state, new_state;
1279 mutex_lock(&hr_qp->mutex);
1281 if (attr_mask & IB_QP_CUR_STATE && attr->cur_qp_state != hr_qp->state)
1284 cur_state = hr_qp->state;
1285 new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state;
1287 if (ibqp->uobject &&
1288 (attr_mask & IB_QP_STATE) && new_state == IB_QPS_ERR) {
1289 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_SQ_RECORD_DB) {
1290 hr_qp->sq.head = *(int *)(hr_qp->sdb.virt_addr);
1292 if (hr_qp->en_flags & HNS_ROCE_QP_CAP_RQ_RECORD_DB)
1293 hr_qp->rq.head = *(int *)(hr_qp->rdb.virt_addr);
1295 ibdev_warn(&hr_dev->ib_dev,
1296 "flush cqe is not supported in userspace!\n");
1301 if (!ib_modify_qp_is_ok(cur_state, new_state, ibqp->qp_type,
1303 ibdev_err(&hr_dev->ib_dev, "ib_modify_qp_is_ok failed\n");
1307 ret = hns_roce_check_qp_attr(ibqp, attr, attr_mask);
1311 if (cur_state == new_state && cur_state == IB_QPS_RESET) {
1312 if (hr_dev->hw_rev == HNS_ROCE_HW_VER1) {
1314 ibdev_err(&hr_dev->ib_dev,
1315 "RST2RST state is not supported\n");
1323 ret = hr_dev->hw->modify_qp(ibqp, attr, attr_mask, cur_state,
1327 mutex_unlock(&hr_qp->mutex);
1332 void hns_roce_lock_cqs(struct hns_roce_cq *send_cq, struct hns_roce_cq *recv_cq)
1333 __acquires(&send_cq->lock) __acquires(&recv_cq->lock)
1335 if (unlikely(send_cq == NULL && recv_cq == NULL)) {
1336 __acquire(&send_cq->lock);
1337 __acquire(&recv_cq->lock);
1338 } else if (unlikely(send_cq != NULL && recv_cq == NULL)) {
1339 spin_lock_irq(&send_cq->lock);
1340 __acquire(&recv_cq->lock);
1341 } else if (unlikely(send_cq == NULL && recv_cq != NULL)) {
1342 spin_lock_irq(&recv_cq->lock);
1343 __acquire(&send_cq->lock);
1344 } else if (send_cq == recv_cq) {
1345 spin_lock_irq(&send_cq->lock);
1346 __acquire(&recv_cq->lock);
1347 } else if (send_cq->cqn < recv_cq->cqn) {
1348 spin_lock_irq(&send_cq->lock);
1349 spin_lock_nested(&recv_cq->lock, SINGLE_DEPTH_NESTING);
1351 spin_lock_irq(&recv_cq->lock);
1352 spin_lock_nested(&send_cq->lock, SINGLE_DEPTH_NESTING);
1356 void hns_roce_unlock_cqs(struct hns_roce_cq *send_cq,
1357 struct hns_roce_cq *recv_cq) __releases(&send_cq->lock)
1358 __releases(&recv_cq->lock)
1360 if (unlikely(send_cq == NULL && recv_cq == NULL)) {
1361 __release(&recv_cq->lock);
1362 __release(&send_cq->lock);
1363 } else if (unlikely(send_cq != NULL && recv_cq == NULL)) {
1364 __release(&recv_cq->lock);
1365 spin_unlock(&send_cq->lock);
1366 } else if (unlikely(send_cq == NULL && recv_cq != NULL)) {
1367 __release(&send_cq->lock);
1368 spin_unlock(&recv_cq->lock);
1369 } else if (send_cq == recv_cq) {
1370 __release(&recv_cq->lock);
1371 spin_unlock_irq(&send_cq->lock);
1372 } else if (send_cq->cqn < recv_cq->cqn) {
1373 spin_unlock(&recv_cq->lock);
1374 spin_unlock_irq(&send_cq->lock);
1376 spin_unlock(&send_cq->lock);
1377 spin_unlock_irq(&recv_cq->lock);
1381 static inline void *get_wqe(struct hns_roce_qp *hr_qp, int offset)
1383 return hns_roce_buf_offset(hr_qp->mtr.kmem, offset);
1386 void *hns_roce_get_recv_wqe(struct hns_roce_qp *hr_qp, unsigned int n)
1388 return get_wqe(hr_qp, hr_qp->rq.offset + (n << hr_qp->rq.wqe_shift));
1391 void *hns_roce_get_send_wqe(struct hns_roce_qp *hr_qp, unsigned int n)
1393 return get_wqe(hr_qp, hr_qp->sq.offset + (n << hr_qp->sq.wqe_shift));
1396 void *hns_roce_get_extend_sge(struct hns_roce_qp *hr_qp, unsigned int n)
1398 return get_wqe(hr_qp, hr_qp->sge.offset + (n << hr_qp->sge.sge_shift));
1401 bool hns_roce_wq_overflow(struct hns_roce_wq *hr_wq, u32 nreq,
1402 struct ib_cq *ib_cq)
1404 struct hns_roce_cq *hr_cq;
1407 cur = hr_wq->head - hr_wq->tail;
1408 if (likely(cur + nreq < hr_wq->wqe_cnt))
1411 hr_cq = to_hr_cq(ib_cq);
1412 spin_lock(&hr_cq->lock);
1413 cur = hr_wq->head - hr_wq->tail;
1414 spin_unlock(&hr_cq->lock);
1416 return cur + nreq >= hr_wq->wqe_cnt;
1419 int hns_roce_init_qp_table(struct hns_roce_dev *hr_dev)
1421 struct hns_roce_qp_table *qp_table = &hr_dev->qp_table;
1422 unsigned int reserved_from_bot;
1425 mutex_init(&qp_table->scc_mutex);
1426 mutex_init(&qp_table->bank_mutex);
1427 xa_init(&hr_dev->qp_table_xa);
1429 reserved_from_bot = hr_dev->caps.reserved_qps;
1431 for (i = 0; i < reserved_from_bot; i++) {
1432 hr_dev->qp_table.bank[get_qp_bankid(i)].inuse++;
1433 hr_dev->qp_table.bank[get_qp_bankid(i)].min++;
1436 for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++) {
1437 ida_init(&hr_dev->qp_table.bank[i].ida);
1438 hr_dev->qp_table.bank[i].max = hr_dev->caps.num_qps /
1439 HNS_ROCE_QP_BANK_NUM - 1;
1440 hr_dev->qp_table.bank[i].next = hr_dev->qp_table.bank[i].min;
1446 void hns_roce_cleanup_qp_table(struct hns_roce_dev *hr_dev)
1450 for (i = 0; i < HNS_ROCE_QP_BANK_NUM; i++)
1451 ida_destroy(&hr_dev->qp_table.bank[i].ida);