| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
|---|
| 3 | 4 | * 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. |
|---|
| 32 | 5 | */ |
|---|
| 33 | 6 | |
|---|
| 34 | 7 | #include <linux/skbuff.h> |
|---|
| 35 | 8 | #include <linux/delay.h> |
|---|
| 36 | 9 | #include <linux/sched.h> |
|---|
| 37 | 10 | #include <linux/vmalloc.h> |
|---|
| 11 | +#include <rdma/uverbs_ioctl.h> |
|---|
| 38 | 12 | |
|---|
| 39 | 13 | #include "rxe.h" |
|---|
| 40 | 14 | #include "rxe_loc.h" |
|---|
| .. | .. |
|---|
| 97 | 71 | goto err1; |
|---|
| 98 | 72 | |
|---|
| 99 | 73 | 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)) { |
|---|
| 101 | 75 | pr_warn("invalid port = %d\n", port_num); |
|---|
| 102 | 76 | goto err1; |
|---|
| 103 | 77 | } |
|---|
| .. | .. |
|---|
| 210 | 184 | spin_lock_init(&qp->grp_lock); |
|---|
| 211 | 185 | spin_lock_init(&qp->state_lock); |
|---|
| 212 | 186 | |
|---|
| 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 | + |
|---|
| 213 | 195 | atomic_set(&qp->ssn, 0); |
|---|
| 214 | 196 | atomic_set(&qp->skb_out, 0); |
|---|
| 215 | 197 | } |
|---|
| 216 | 198 | |
|---|
| 217 | 199 | 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, |
|---|
| 220 | 201 | struct rxe_create_qp_resp __user *uresp) |
|---|
| 221 | 202 | { |
|---|
| 222 | 203 | int err; |
|---|
| .. | .. |
|---|
| 227 | 208 | return err; |
|---|
| 228 | 209 | qp->sk->sk->sk_user_data = qp; |
|---|
| 229 | 210 | |
|---|
| 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); |
|---|
| 230 | 220 | 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; |
|---|
| 233 | 221 | |
|---|
| 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); |
|---|
| 238 | 229 | |
|---|
| 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); |
|---|
| 242 | 231 | if (!qp->sq.queue) |
|---|
| 243 | 232 | return -ENOMEM; |
|---|
| 244 | 233 | |
|---|
| 245 | | - err = do_mmap_info(rxe, uresp ? &uresp->sq_mi : NULL, context, |
|---|
| 234 | + err = do_mmap_info(rxe, uresp ? &uresp->sq_mi : NULL, udata, |
|---|
| 246 | 235 | qp->sq.queue->buf, qp->sq.queue->buf_size, |
|---|
| 247 | 236 | &qp->sq.queue->ip); |
|---|
| 248 | 237 | |
|---|
| .. | .. |
|---|
| 258 | 247 | qp->req.opcode = -1; |
|---|
| 259 | 248 | qp->comp.opcode = -1; |
|---|
| 260 | 249 | |
|---|
| 261 | | - spin_lock_init(&qp->sq.sq_lock); |
|---|
| 262 | 250 | skb_queue_head_init(&qp->req_pkts); |
|---|
| 263 | 251 | |
|---|
| 264 | 252 | rxe_init_task(rxe, &qp->req.task, qp, |
|---|
| .. | .. |
|---|
| 276 | 264 | |
|---|
| 277 | 265 | static int rxe_qp_init_resp(struct rxe_dev *rxe, struct rxe_qp *qp, |
|---|
| 278 | 266 | struct ib_qp_init_attr *init, |
|---|
| 279 | | - struct ib_ucontext *context, |
|---|
| 267 | + struct ib_udata *udata, |
|---|
| 280 | 268 | struct rxe_create_qp_resp __user *uresp) |
|---|
| 281 | 269 | { |
|---|
| 282 | 270 | int err; |
|---|
| .. | .. |
|---|
| 297 | 285 | if (!qp->rq.queue) |
|---|
| 298 | 286 | return -ENOMEM; |
|---|
| 299 | 287 | |
|---|
| 300 | | - err = do_mmap_info(rxe, uresp ? &uresp->rq_mi : NULL, context, |
|---|
| 288 | + err = do_mmap_info(rxe, uresp ? &uresp->rq_mi : NULL, udata, |
|---|
| 301 | 289 | qp->rq.queue->buf, qp->rq.queue->buf_size, |
|---|
| 302 | 290 | &qp->rq.queue->ip); |
|---|
| 303 | 291 | if (err) { |
|---|
| .. | .. |
|---|
| 307 | 295 | return err; |
|---|
| 308 | 296 | } |
|---|
| 309 | 297 | } |
|---|
| 310 | | - |
|---|
| 311 | | - spin_lock_init(&qp->rq.producer_lock); |
|---|
| 312 | | - spin_lock_init(&qp->rq.consumer_lock); |
|---|
| 313 | 298 | |
|---|
| 314 | 299 | skb_queue_head_init(&qp->resp_pkts); |
|---|
| 315 | 300 | |
|---|
| .. | .. |
|---|
| 327 | 312 | int rxe_qp_from_init(struct rxe_dev *rxe, struct rxe_qp *qp, struct rxe_pd *pd, |
|---|
| 328 | 313 | struct ib_qp_init_attr *init, |
|---|
| 329 | 314 | struct rxe_create_qp_resp __user *uresp, |
|---|
| 330 | | - struct ib_pd *ibpd) |
|---|
| 315 | + struct ib_pd *ibpd, |
|---|
| 316 | + struct ib_udata *udata) |
|---|
| 331 | 317 | { |
|---|
| 332 | 318 | int err; |
|---|
| 333 | 319 | struct rxe_cq *rcq = to_rcq(init->recv_cq); |
|---|
| 334 | 320 | struct rxe_cq *scq = to_rcq(init->send_cq); |
|---|
| 335 | 321 | struct rxe_srq *srq = init->srq ? to_rsrq(init->srq) : NULL; |
|---|
| 336 | | - struct ib_ucontext *context = ibpd->uobject ? ibpd->uobject->context : NULL; |
|---|
| 337 | 322 | |
|---|
| 338 | 323 | rxe_add_ref(pd); |
|---|
| 339 | 324 | rxe_add_ref(rcq); |
|---|
| .. | .. |
|---|
| 348 | 333 | |
|---|
| 349 | 334 | rxe_qp_init_misc(rxe, qp, init); |
|---|
| 350 | 335 | |
|---|
| 351 | | - err = rxe_qp_init_req(rxe, qp, init, context, uresp); |
|---|
| 336 | + err = rxe_qp_init_req(rxe, qp, init, udata, uresp); |
|---|
| 352 | 337 | if (err) |
|---|
| 353 | 338 | goto err1; |
|---|
| 354 | 339 | |
|---|
| 355 | | - err = rxe_qp_init_resp(rxe, qp, init, context, uresp); |
|---|
| 340 | + err = rxe_qp_init_resp(rxe, qp, init, udata, uresp); |
|---|
| 356 | 341 | if (err) |
|---|
| 357 | 342 | goto err2; |
|---|
| 358 | 343 | |
|---|
| .. | .. |
|---|
| 415 | 400 | enum ib_qp_state new_state = (mask & IB_QP_STATE) ? |
|---|
| 416 | 401 | attr->qp_state : cur_state; |
|---|
| 417 | 402 | |
|---|
| 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)) { |
|---|
| 420 | 404 | pr_warn("invalid mask or state for qp\n"); |
|---|
| 421 | 405 | goto err1; |
|---|
| 422 | 406 | } |
|---|
| .. | .. |
|---|
| 430 | 414 | } |
|---|
| 431 | 415 | |
|---|
| 432 | 416 | if (mask & IB_QP_PORT) { |
|---|
| 433 | | - if (attr->port_num != 1) { |
|---|
| 417 | + if (!rdma_is_port_valid(&rxe->ib_dev, attr->port_num)) { |
|---|
| 434 | 418 | pr_warn("invalid port %d\n", attr->port_num); |
|---|
| 435 | 419 | goto err1; |
|---|
| 436 | 420 | } |
|---|
| .. | .. |
|---|
| 445 | 429 | if (mask & IB_QP_ALT_PATH) { |
|---|
| 446 | 430 | if (rxe_av_chk_attr(rxe, &attr->alt_ah_attr)) |
|---|
| 447 | 431 | goto err1; |
|---|
| 448 | | - if (attr->alt_port_num != 1) { |
|---|
| 432 | + if (!rdma_is_port_valid(&rxe->ib_dev, attr->alt_port_num)) { |
|---|
| 449 | 433 | pr_warn("invalid alt port %d\n", attr->alt_port_num); |
|---|
| 450 | 434 | goto err1; |
|---|
| 451 | 435 | } |
|---|
| .. | .. |
|---|
| 627 | 611 | if (mask & IB_QP_QKEY) |
|---|
| 628 | 612 | qp->attr.qkey = attr->qkey; |
|---|
| 629 | 613 | |
|---|
| 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); |
|---|
| 634 | 616 | |
|---|
| 635 | 617 | 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); |
|---|
| 639 | 619 | qp->attr.alt_port_num = attr->alt_port_num; |
|---|
| 640 | 620 | qp->attr.alt_pkey_index = attr->alt_pkey_index; |
|---|
| 641 | 621 | qp->attr.alt_timeout = attr->alt_timeout; |
|---|
| .. | .. |
|---|
| 795 | 775 | rxe_cleanup_task(&qp->comp.task); |
|---|
| 796 | 776 | |
|---|
| 797 | 777 | /* 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 | + |
|---|
| 799 | 781 | if (qp->sq.queue) { |
|---|
| 800 | 782 | __rxe_do_task(&qp->comp.task); |
|---|
| 801 | 783 | __rxe_do_task(&qp->req.task); |
|---|
| .. | .. |
|---|
| 835 | 817 | |
|---|
| 836 | 818 | free_rd_atomic_resources(qp); |
|---|
| 837 | 819 | |
|---|
| 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 | + } |
|---|
| 840 | 824 | } |
|---|
| 841 | 825 | |
|---|
| 842 | 826 | /* called when the last reference to the qp is dropped */ |
|---|