1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
3 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
4 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
7 #include <linux/vmalloc.h>
10 #include "rxe_queue.h"
12 int rxe_srq_chk_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
13 struct ib_srq_attr *attr, enum ib_srq_attr_mask mask)
15 if (srq && srq->error) {
16 pr_warn("srq in error state\n");
20 if (mask & IB_SRQ_MAX_WR) {
21 if (attr->max_wr > rxe->attr.max_srq_wr) {
22 pr_warn("max_wr(%d) > max_srq_wr(%d)\n",
23 attr->max_wr, rxe->attr.max_srq_wr);
27 if (attr->max_wr <= 0) {
28 pr_warn("max_wr(%d) <= 0\n", attr->max_wr);
32 if (srq && srq->limit && (attr->max_wr < srq->limit)) {
33 pr_warn("max_wr (%d) < srq->limit (%d)\n",
34 attr->max_wr, srq->limit);
38 if (attr->max_wr < RXE_MIN_SRQ_WR)
39 attr->max_wr = RXE_MIN_SRQ_WR;
42 if (mask & IB_SRQ_LIMIT) {
43 if (attr->srq_limit > rxe->attr.max_srq_wr) {
44 pr_warn("srq_limit(%d) > max_srq_wr(%d)\n",
45 attr->srq_limit, rxe->attr.max_srq_wr);
49 if (srq && (attr->srq_limit > srq->rq.queue->buf->index_mask)) {
50 pr_warn("srq_limit (%d) > cur limit(%d)\n",
52 srq->rq.queue->buf->index_mask);
57 if (mask == IB_SRQ_INIT_MASK) {
58 if (attr->max_sge > rxe->attr.max_srq_sge) {
59 pr_warn("max_sge(%d) > max_srq_sge(%d)\n",
60 attr->max_sge, rxe->attr.max_srq_sge);
64 if (attr->max_sge < RXE_MIN_SRQ_SGE)
65 attr->max_sge = RXE_MIN_SRQ_SGE;
74 int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
75 struct ib_srq_init_attr *init, struct ib_udata *udata,
76 struct rxe_create_srq_resp __user *uresp)
82 srq->ibsrq.event_handler = init->event_handler;
83 srq->ibsrq.srq_context = init->srq_context;
84 srq->limit = init->attr.srq_limit;
85 srq->srq_num = srq->pelem.index;
86 srq->rq.max_wr = init->attr.max_wr;
87 srq->rq.max_sge = init->attr.max_sge;
89 srq_wqe_size = rcv_wqe_size(srq->rq.max_sge);
91 spin_lock_init(&srq->rq.producer_lock);
92 spin_lock_init(&srq->rq.consumer_lock);
94 q = rxe_queue_init(rxe, &srq->rq.max_wr,
97 pr_warn("unable to allocate queue for srq\n");
103 err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, udata, q->buf,
104 q->buf_size, &q->ip);
112 if (copy_to_user(&uresp->srq_num, &srq->srq_num,
113 sizeof(uresp->srq_num))) {
114 rxe_queue_cleanup(q);
122 int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
123 struct ib_srq_attr *attr, enum ib_srq_attr_mask mask,
124 struct rxe_modify_srq_cmd *ucmd, struct ib_udata *udata)
127 struct rxe_queue *q = srq->rq.queue;
128 struct mminfo __user *mi = NULL;
130 if (mask & IB_SRQ_MAX_WR) {
132 * This is completely screwed up, the response is supposed to
133 * be in the outbuf not like this.
135 mi = u64_to_user_ptr(ucmd->mmap_info_addr);
137 err = rxe_queue_resize(q, &attr->max_wr,
138 rcv_wqe_size(srq->rq.max_sge), udata, mi,
139 &srq->rq.producer_lock,
140 &srq->rq.consumer_lock);
145 if (mask & IB_SRQ_LIMIT)
146 srq->limit = attr->srq_limit;
151 rxe_queue_cleanup(q);
152 srq->rq.queue = NULL;