hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
kernel/drivers/infiniband/sw/rxe/rxe_qp.c
....@@ -1,40 +1,14 @@
1
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
12 /*
23 * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
34 * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
4
- *
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:
10
- *
11
- * Redistribution and use in source and binary forms, with or
12
- * without modification, are permitted provided that the following
13
- * conditions are met:
14
- *
15
- * - Redistributions of source code must retain the above
16
- * copyright notice, this list of conditions and the following
17
- * disclaimer.
18
- *
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.
23
- *
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
31
- * SOFTWARE.
325 */
336
347 #include <linux/skbuff.h>
358 #include <linux/delay.h>
369 #include <linux/sched.h>
3710 #include <linux/vmalloc.h>
11
+#include <rdma/uverbs_ioctl.h>
3812
3913 #include "rxe.h"
4014 #include "rxe_loc.h"
....@@ -97,7 +71,7 @@
9771 goto err1;
9872
9973 if (init->qp_type == IB_QPT_SMI || init->qp_type == IB_QPT_GSI) {
100
- if (port_num != 1) {
74
+ if (!rdma_is_port_valid(&rxe->ib_dev, port_num)) {
10175 pr_warn("invalid port = %d\n", port_num);
10276 goto err1;
10377 }
....@@ -210,13 +184,20 @@
210184 spin_lock_init(&qp->grp_lock);
211185 spin_lock_init(&qp->state_lock);
212186
187
+ spin_lock_init(&qp->req.task.state_lock);
188
+ spin_lock_init(&qp->resp.task.state_lock);
189
+ spin_lock_init(&qp->comp.task.state_lock);
190
+
191
+ spin_lock_init(&qp->sq.sq_lock);
192
+ spin_lock_init(&qp->rq.producer_lock);
193
+ spin_lock_init(&qp->rq.consumer_lock);
194
+
213195 atomic_set(&qp->ssn, 0);
214196 atomic_set(&qp->skb_out, 0);
215197 }
216198
217199 static int rxe_qp_init_req(struct rxe_dev *rxe, struct rxe_qp *qp,
218
- struct ib_qp_init_attr *init,
219
- struct ib_ucontext *context,
200
+ struct ib_qp_init_attr *init, struct ib_udata *udata,
220201 struct rxe_create_qp_resp __user *uresp)
221202 {
222203 int err;
....@@ -227,22 +208,30 @@
227208 return err;
228209 qp->sk->sk->sk_user_data = qp;
229210
211
+ /* pick a source UDP port number for this QP based on
212
+ * the source QPN. this spreads traffic for different QPs
213
+ * across different NIC RX queues (while using a single
214
+ * flow for a given QP to maintain packet order).
215
+ * the port number must be in the Dynamic Ports range
216
+ * (0xc000 - 0xffff).
217
+ */
218
+ qp->src_port = RXE_ROCE_V2_SPORT +
219
+ (hash_32_generic(qp_num(qp), 14) & 0x3fff);
230220 qp->sq.max_wr = init->cap.max_send_wr;
231
- qp->sq.max_sge = init->cap.max_send_sge;
232
- qp->sq.max_inline = init->cap.max_inline_data;
233221
234
- wqe_size = max_t(int, sizeof(struct rxe_send_wqe) +
235
- qp->sq.max_sge * sizeof(struct ib_sge),
236
- sizeof(struct rxe_send_wqe) +
237
- qp->sq.max_inline);
222
+ /* These caps are limited by rxe_qp_chk_cap() done by the caller */
223
+ wqe_size = max_t(int, init->cap.max_send_sge * sizeof(struct ib_sge),
224
+ init->cap.max_inline_data);
225
+ qp->sq.max_sge = init->cap.max_send_sge =
226
+ wqe_size / sizeof(struct ib_sge);
227
+ qp->sq.max_inline = init->cap.max_inline_data = wqe_size;
228
+ wqe_size += sizeof(struct rxe_send_wqe);
238229
239
- qp->sq.queue = rxe_queue_init(rxe,
240
- &qp->sq.max_wr,
241
- wqe_size);
230
+ qp->sq.queue = rxe_queue_init(rxe, &qp->sq.max_wr, wqe_size);
242231 if (!qp->sq.queue)
243232 return -ENOMEM;
244233
245
- err = do_mmap_info(rxe, uresp ? &uresp->sq_mi : NULL, context,
234
+ err = do_mmap_info(rxe, uresp ? &uresp->sq_mi : NULL, udata,
246235 qp->sq.queue->buf, qp->sq.queue->buf_size,
247236 &qp->sq.queue->ip);
248237
....@@ -258,7 +247,6 @@
258247 qp->req.opcode = -1;
259248 qp->comp.opcode = -1;
260249
261
- spin_lock_init(&qp->sq.sq_lock);
262250 skb_queue_head_init(&qp->req_pkts);
263251
264252 rxe_init_task(rxe, &qp->req.task, qp,
....@@ -276,7 +264,7 @@
276264
277265 static int rxe_qp_init_resp(struct rxe_dev *rxe, struct rxe_qp *qp,
278266 struct ib_qp_init_attr *init,
279
- struct ib_ucontext *context,
267
+ struct ib_udata *udata,
280268 struct rxe_create_qp_resp __user *uresp)
281269 {
282270 int err;
....@@ -297,7 +285,7 @@
297285 if (!qp->rq.queue)
298286 return -ENOMEM;
299287
300
- err = do_mmap_info(rxe, uresp ? &uresp->rq_mi : NULL, context,
288
+ err = do_mmap_info(rxe, uresp ? &uresp->rq_mi : NULL, udata,
301289 qp->rq.queue->buf, qp->rq.queue->buf_size,
302290 &qp->rq.queue->ip);
303291 if (err) {
....@@ -307,9 +295,6 @@
307295 return err;
308296 }
309297 }
310
-
311
- spin_lock_init(&qp->rq.producer_lock);
312
- spin_lock_init(&qp->rq.consumer_lock);
313298
314299 skb_queue_head_init(&qp->resp_pkts);
315300
....@@ -327,13 +312,13 @@
327312 int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd,
328313 struct ib_qp_init_attr *init,
329314 struct rxe_create_qp_resp __user *uresp,
330
- struct ib_pd *ibpd)
315
+ struct ib_pd *ibpd,
316
+ struct ib_udata *udata)
331317 {
332318 int err;
333319 struct rxe_cq *rcq = to_rcq(init->recv_cq);
334320 struct rxe_cq *scq = to_rcq(init->send_cq);
335321 struct rxe_srq *srq = init->srq ? to_rsrq(init->srq) : NULL;
336
- struct ib_ucontext *context = ibpd->uobject ? ibpd->uobject->context : NULL;
337322
338323 rxe_add_ref(pd);
339324 rxe_add_ref(rcq);
....@@ -348,11 +333,11 @@
348333
349334 rxe_qp_init_misc(rxe, qp, init);
350335
351
- err = rxe_qp_init_req(rxe, qp, init, context, uresp);
336
+ err = rxe_qp_init_req(rxe, qp, init, udata, uresp);
352337 if (err)
353338 goto err1;
354339
355
- err = rxe_qp_init_resp(rxe, qp, init, context, uresp);
340
+ err = rxe_qp_init_resp(rxe, qp, init, udata, uresp);
356341 if (err)
357342 goto err2;
358343
....@@ -415,8 +400,7 @@
415400 enum ib_qp_state new_state = (mask & IB_QP_STATE) ?
416401 attr->qp_state : cur_state;
417402
418
- if (!ib_modify_qp_is_ok(cur_state, new_state, qp_type(qp), mask,
419
- IB_LINK_LAYER_ETHERNET)) {
403
+ if (!ib_modify_qp_is_ok(cur_state, new_state, qp_type(qp), mask)) {
420404 pr_warn("invalid mask or state for qp\n");
421405 goto err1;
422406 }
....@@ -430,7 +414,7 @@
430414 }
431415
432416 if (mask & IB_QP_PORT) {
433
- if (attr->port_num != 1) {
417
+ if (!rdma_is_port_valid(&rxe->ib_dev, attr->port_num)) {
434418 pr_warn("invalid port %d\n", attr->port_num);
435419 goto err1;
436420 }
....@@ -445,7 +429,7 @@
445429 if (mask & IB_QP_ALT_PATH) {
446430 if (rxe_av_chk_attr(rxe, &attr->alt_ah_attr))
447431 goto err1;
448
- if (attr->alt_port_num != 1) {
432
+ if (!rdma_is_port_valid(&rxe->ib_dev, attr->alt_port_num)) {
449433 pr_warn("invalid alt port %d\n", attr->alt_port_num);
450434 goto err1;
451435 }
....@@ -627,15 +611,11 @@
627611 if (mask & IB_QP_QKEY)
628612 qp->attr.qkey = attr->qkey;
629613
630
- if (mask & IB_QP_AV) {
631
- rxe_av_from_attr(attr->port_num, &qp->pri_av, &attr->ah_attr);
632
- rxe_av_fill_ip_info(&qp->pri_av, &attr->ah_attr);
633
- }
614
+ if (mask & IB_QP_AV)
615
+ rxe_init_av(&attr->ah_attr, &qp->pri_av);
634616
635617 if (mask & IB_QP_ALT_PATH) {
636
- rxe_av_from_attr(attr->alt_port_num, &qp->alt_av,
637
- &attr->alt_ah_attr);
638
- rxe_av_fill_ip_info(&qp->alt_av, &attr->alt_ah_attr);
618
+ rxe_init_av(&attr->alt_ah_attr, &qp->alt_av);
639619 qp->attr.alt_port_num = attr->alt_port_num;
640620 qp->attr.alt_pkey_index = attr->alt_pkey_index;
641621 qp->attr.alt_timeout = attr->alt_timeout;
....@@ -795,7 +775,9 @@
795775 rxe_cleanup_task(&qp->comp.task);
796776
797777 /* flush out any receive wr's or pending requests */
798
- __rxe_do_task(&qp->req.task);
778
+ if (qp->req.task.func)
779
+ __rxe_do_task(&qp->req.task);
780
+
799781 if (qp->sq.queue) {
800782 __rxe_do_task(&qp->comp.task);
801783 __rxe_do_task(&qp->req.task);
....@@ -835,8 +817,10 @@
835817
836818 free_rd_atomic_resources(qp);
837819
838
- kernel_sock_shutdown(qp->sk, SHUT_RDWR);
839
- sock_release(qp->sk);
820
+ if (qp->sk) {
821
+ kernel_sock_shutdown(qp->sk, SHUT_RDWR);
822
+ sock_release(qp->sk);
823
+ }
840824 }
841825
842826 /* called when the last reference to the qp is dropped */