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>
11 int rxe_srq_chk_init(struct rxe_dev *rxe, struct ib_srq_init_attr *init)
13 struct ib_srq_attr *attr = &init->attr;
15 if (attr->max_wr > rxe->attr.max_srq_wr) {
16 rxe_dbg_dev(rxe, "max_wr(%d) > max_srq_wr(%d)\n",
17 attr->max_wr, rxe->attr.max_srq_wr);
21 if (attr->max_wr <= 0) {
22 rxe_dbg_dev(rxe, "max_wr(%d) <= 0\n", attr->max_wr);
26 if (attr->max_wr < RXE_MIN_SRQ_WR)
27 attr->max_wr = RXE_MIN_SRQ_WR;
29 if (attr->max_sge > rxe->attr.max_srq_sge) {
30 rxe_dbg_dev(rxe, "max_sge(%d) > max_srq_sge(%d)\n",
31 attr->max_sge, rxe->attr.max_srq_sge);
35 if (attr->max_sge < RXE_MIN_SRQ_SGE)
36 attr->max_sge = RXE_MIN_SRQ_SGE;
44 int rxe_srq_from_init(struct rxe_dev *rxe, struct rxe_srq *srq,
45 struct ib_srq_init_attr *init, struct ib_udata *udata,
46 struct rxe_create_srq_resp __user *uresp)
52 srq->ibsrq.event_handler = init->event_handler;
53 srq->ibsrq.srq_context = init->srq_context;
54 srq->limit = init->attr.srq_limit;
55 srq->srq_num = srq->elem.index;
56 srq->rq.max_wr = init->attr.max_wr;
57 srq->rq.max_sge = init->attr.max_sge;
59 wqe_size = sizeof(struct rxe_recv_wqe) +
60 srq->rq.max_sge*sizeof(struct ib_sge);
62 spin_lock_init(&srq->rq.producer_lock);
63 spin_lock_init(&srq->rq.consumer_lock);
65 q = rxe_queue_init(rxe, &srq->rq.max_wr, wqe_size,
66 QUEUE_TYPE_FROM_CLIENT);
68 rxe_dbg_srq(srq, "Unable to allocate queue\n");
73 err = do_mmap_info(rxe, uresp ? &uresp->mi : NULL, udata, q->buf,
76 rxe_dbg_srq(srq, "Unable to init mmap info for caller\n");
81 init->attr.max_wr = srq->rq.max_wr;
84 if (copy_to_user(&uresp->srq_num, &srq->srq_num,
85 sizeof(uresp->srq_num))) {
100 int rxe_srq_chk_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
101 struct ib_srq_attr *attr, enum ib_srq_attr_mask mask)
104 rxe_dbg_srq(srq, "in error state\n");
108 if (mask & IB_SRQ_MAX_WR) {
109 if (attr->max_wr > rxe->attr.max_srq_wr) {
110 rxe_dbg_srq(srq, "max_wr(%d) > max_srq_wr(%d)\n",
111 attr->max_wr, rxe->attr.max_srq_wr);
115 if (attr->max_wr <= 0) {
116 rxe_dbg_srq(srq, "max_wr(%d) <= 0\n", attr->max_wr);
120 if (srq->limit && (attr->max_wr < srq->limit)) {
121 rxe_dbg_srq(srq, "max_wr (%d) < srq->limit (%d)\n",
122 attr->max_wr, srq->limit);
126 if (attr->max_wr < RXE_MIN_SRQ_WR)
127 attr->max_wr = RXE_MIN_SRQ_WR;
130 if (mask & IB_SRQ_LIMIT) {
131 if (attr->srq_limit > rxe->attr.max_srq_wr) {
132 rxe_dbg_srq(srq, "srq_limit(%d) > max_srq_wr(%d)\n",
133 attr->srq_limit, rxe->attr.max_srq_wr);
137 if (attr->srq_limit > srq->rq.queue->buf->index_mask) {
138 rxe_dbg_srq(srq, "srq_limit (%d) > cur limit(%d)\n",
140 srq->rq.queue->buf->index_mask);
151 int rxe_srq_from_attr(struct rxe_dev *rxe, struct rxe_srq *srq,
152 struct ib_srq_attr *attr, enum ib_srq_attr_mask mask,
153 struct rxe_modify_srq_cmd *ucmd, struct ib_udata *udata)
155 struct rxe_queue *q = srq->rq.queue;
156 struct mminfo __user *mi = NULL;
160 if (mask & IB_SRQ_MAX_WR) {
162 * This is completely screwed up, the response is supposed to
163 * be in the outbuf not like this.
165 mi = u64_to_user_ptr(ucmd->mmap_info_addr);
167 wqe_size = sizeof(struct rxe_recv_wqe) +
168 srq->rq.max_sge*sizeof(struct ib_sge);
170 err = rxe_queue_resize(q, &attr->max_wr, wqe_size,
171 udata, mi, &srq->rq.producer_lock,
172 &srq->rq.consumer_lock);
176 srq->rq.max_wr = attr->max_wr;
179 if (mask & IB_SRQ_LIMIT)
180 srq->limit = attr->srq_limit;
185 rxe_queue_cleanup(q);
186 srq->rq.queue = NULL;
190 void rxe_srq_cleanup(struct rxe_pool_elem *elem)
192 struct rxe_srq *srq = container_of(elem, typeof(*srq), elem);
198 rxe_queue_cleanup(srq->rq.queue);