Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1 | /* |
Saeed Mahameed | 6cf0a15 | 2015-04-02 17:07:30 +0300 | [diff] [blame] | 2 | * Copyright (c) 2013-2015, Mellanox Technologies. All rights reserved. |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3 | * |
| 4 | * This software is available to you under a choice of one of two |
| 5 | * licenses. You may choose to be licensed under the terms of the GNU |
| 6 | * General Public License (GPL) Version 2, available from the file |
| 7 | * COPYING in the main directory of this source tree, or the |
| 8 | * OpenIB.org BSD license below: |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or |
| 11 | * without modification, are permitted provided that the following |
| 12 | * conditions are met: |
| 13 | * |
| 14 | * - Redistributions of source code must retain the above |
| 15 | * copyright notice, this list of conditions and the following |
| 16 | * disclaimer. |
| 17 | * |
| 18 | * - Redistributions in binary form must reproduce the above |
| 19 | * copyright notice, this list of conditions and the following |
| 20 | * disclaimer in the documentation and/or other materials |
| 21 | * provided with the distribution. |
| 22 | * |
| 23 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 24 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 25 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 26 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 27 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 28 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 29 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 30 | * SOFTWARE. |
| 31 | */ |
| 32 | |
| 33 | #include <linux/module.h> |
| 34 | #include <rdma/ib_umem.h> |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 35 | #include <rdma/ib_cache.h> |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 36 | #include <rdma/ib_user_verbs.h> |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 37 | #include <rdma/rdma_counter.h> |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 38 | #include <linux/mlx5/fs.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 39 | #include "mlx5_ib.h" |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 40 | #include "ib_rep.h" |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 41 | #include "cmd.h" |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 42 | #include "qp.h" |
Leon Romanovsky | 029e88f | 2020-05-06 09:55:13 +0300 | [diff] [blame] | 43 | #include "wr.h" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 44 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 45 | enum { |
| 46 | MLX5_IB_ACK_REQ_FREQ = 8, |
| 47 | }; |
| 48 | |
| 49 | enum { |
| 50 | MLX5_IB_DEFAULT_SCHED_QUEUE = 0x83, |
| 51 | MLX5_IB_DEFAULT_QP0_SCHED_QUEUE = 0x3f, |
| 52 | MLX5_IB_LINK_TYPE_IB = 0, |
| 53 | MLX5_IB_LINK_TYPE_ETH = 1 |
| 54 | }; |
| 55 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 56 | enum raw_qp_set_mask_map { |
| 57 | MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID = 1UL << 0, |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 58 | MLX5_RAW_QP_RATE_LIMIT = 1UL << 1, |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 59 | }; |
| 60 | |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 61 | struct mlx5_modify_raw_qp_param { |
| 62 | u16 operation; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 63 | |
| 64 | u32 set_mask; /* raw_qp_set_mask_map */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 65 | |
| 66 | struct mlx5_rate_limit rl; |
| 67 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 68 | u8 rq_q_ctr_id; |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 69 | u16 port; |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 70 | }; |
| 71 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 72 | static void get_cqs(enum ib_qp_type qp_type, |
| 73 | struct ib_cq *ib_send_cq, struct ib_cq *ib_recv_cq, |
| 74 | struct mlx5_ib_cq **send_cq, struct mlx5_ib_cq **recv_cq); |
| 75 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 76 | static int is_qp0(enum ib_qp_type qp_type) |
| 77 | { |
| 78 | return qp_type == IB_QPT_SMI; |
| 79 | } |
| 80 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 81 | static int is_sqp(enum ib_qp_type qp_type) |
| 82 | { |
| 83 | return is_qp0(qp_type) || is_qp1(qp_type); |
| 84 | } |
| 85 | |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 86 | /** |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 87 | * mlx5_ib_read_user_wqe_common() - Copy a WQE (or part of) from user WQ |
| 88 | * to kernel buffer |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 89 | * |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 90 | * @umem: User space memory where the WQ is |
| 91 | * @buffer: buffer to copy to |
| 92 | * @buflen: buffer length |
| 93 | * @wqe_index: index of WQE to copy from |
| 94 | * @wq_offset: offset to start of WQ |
| 95 | * @wq_wqe_cnt: number of WQEs in WQ |
| 96 | * @wq_wqe_shift: log2 of WQE size |
| 97 | * @bcnt: number of bytes to copy |
| 98 | * @bytes_copied: number of bytes to copy (return value) |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 99 | * |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 100 | * Copies from start of WQE bcnt or less bytes. |
| 101 | * Does not gurantee to copy the entire WQE. |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 102 | * |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 103 | * Return: zero on success, or an error code. |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 104 | */ |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 105 | static int mlx5_ib_read_user_wqe_common(struct ib_umem *umem, void *buffer, |
| 106 | size_t buflen, int wqe_index, |
| 107 | int wq_offset, int wq_wqe_cnt, |
| 108 | int wq_wqe_shift, int bcnt, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 109 | size_t *bytes_copied) |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 110 | { |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 111 | size_t offset = wq_offset + ((wqe_index % wq_wqe_cnt) << wq_wqe_shift); |
| 112 | size_t wq_end = wq_offset + (wq_wqe_cnt << wq_wqe_shift); |
| 113 | size_t copy_length; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 114 | int ret; |
| 115 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 116 | /* don't copy more than requested, more than buffer length or |
| 117 | * beyond WQ end |
| 118 | */ |
| 119 | copy_length = min_t(u32, buflen, wq_end - offset); |
| 120 | copy_length = min_t(u32, copy_length, bcnt); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 121 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 122 | ret = ib_umem_copy_from(buffer, umem, offset, copy_length); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 123 | if (ret) |
| 124 | return ret; |
| 125 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 126 | if (!ret && bytes_copied) |
| 127 | *bytes_copied = copy_length; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 128 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 129 | return 0; |
| 130 | } |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 131 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 132 | static int mlx5_ib_read_kernel_wqe_sq(struct mlx5_ib_qp *qp, int wqe_index, |
| 133 | void *buffer, size_t buflen, size_t *bc) |
| 134 | { |
| 135 | struct mlx5_wqe_ctrl_seg *ctrl; |
| 136 | size_t bytes_copied = 0; |
| 137 | size_t wqe_length; |
| 138 | void *p; |
| 139 | int ds; |
| 140 | |
| 141 | wqe_index = wqe_index & qp->sq.fbc.sz_m1; |
| 142 | |
| 143 | /* read the control segment first */ |
| 144 | p = mlx5_frag_buf_get_wqe(&qp->sq.fbc, wqe_index); |
| 145 | ctrl = p; |
| 146 | ds = be32_to_cpu(ctrl->qpn_ds) & MLX5_WQE_CTRL_DS_MASK; |
| 147 | wqe_length = ds * MLX5_WQE_DS_UNITS; |
| 148 | |
| 149 | /* read rest of WQE if it spreads over more than one stride */ |
| 150 | while (bytes_copied < wqe_length) { |
| 151 | size_t copy_length = |
| 152 | min_t(size_t, buflen - bytes_copied, MLX5_SEND_WQE_BB); |
| 153 | |
| 154 | if (!copy_length) |
| 155 | break; |
| 156 | |
| 157 | memcpy(buffer + bytes_copied, p, copy_length); |
| 158 | bytes_copied += copy_length; |
| 159 | |
| 160 | wqe_index = (wqe_index + 1) & qp->sq.fbc.sz_m1; |
| 161 | p = mlx5_frag_buf_get_wqe(&qp->sq.fbc, wqe_index); |
| 162 | } |
| 163 | *bc = bytes_copied; |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | static int mlx5_ib_read_user_wqe_sq(struct mlx5_ib_qp *qp, int wqe_index, |
| 168 | void *buffer, size_t buflen, size_t *bc) |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 169 | { |
| 170 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 171 | struct ib_umem *umem = base->ubuffer.umem; |
| 172 | struct mlx5_ib_wq *wq = &qp->sq; |
| 173 | struct mlx5_wqe_ctrl_seg *ctrl; |
| 174 | size_t bytes_copied; |
| 175 | size_t bytes_copied2; |
| 176 | size_t wqe_length; |
| 177 | int ret; |
| 178 | int ds; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 179 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 180 | /* at first read as much as possible */ |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 181 | ret = mlx5_ib_read_user_wqe_common(umem, buffer, buflen, wqe_index, |
| 182 | wq->offset, wq->wqe_cnt, |
| 183 | wq->wqe_shift, buflen, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 184 | &bytes_copied); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 185 | if (ret) |
| 186 | return ret; |
| 187 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 188 | /* we need at least control segment size to proceed */ |
| 189 | if (bytes_copied < sizeof(*ctrl)) |
| 190 | return -EINVAL; |
| 191 | |
| 192 | ctrl = buffer; |
| 193 | ds = be32_to_cpu(ctrl->qpn_ds) & MLX5_WQE_CTRL_DS_MASK; |
| 194 | wqe_length = ds * MLX5_WQE_DS_UNITS; |
| 195 | |
| 196 | /* if we copied enough then we are done */ |
| 197 | if (bytes_copied >= wqe_length) { |
| 198 | *bc = bytes_copied; |
| 199 | return 0; |
| 200 | } |
| 201 | |
| 202 | /* otherwise this a wrapped around wqe |
| 203 | * so read the remaining bytes starting |
| 204 | * from wqe_index 0 |
| 205 | */ |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 206 | ret = mlx5_ib_read_user_wqe_common(umem, buffer + bytes_copied, |
| 207 | buflen - bytes_copied, 0, wq->offset, |
| 208 | wq->wqe_cnt, wq->wqe_shift, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 209 | wqe_length - bytes_copied, |
| 210 | &bytes_copied2); |
| 211 | |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | *bc = bytes_copied + bytes_copied2; |
| 215 | return 0; |
| 216 | } |
| 217 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 218 | int mlx5_ib_read_wqe_sq(struct mlx5_ib_qp *qp, int wqe_index, void *buffer, |
| 219 | size_t buflen, size_t *bc) |
| 220 | { |
| 221 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 222 | struct ib_umem *umem = base->ubuffer.umem; |
| 223 | |
| 224 | if (buflen < sizeof(struct mlx5_wqe_ctrl_seg)) |
| 225 | return -EINVAL; |
| 226 | |
| 227 | if (!umem) |
| 228 | return mlx5_ib_read_kernel_wqe_sq(qp, wqe_index, buffer, |
| 229 | buflen, bc); |
| 230 | |
| 231 | return mlx5_ib_read_user_wqe_sq(qp, wqe_index, buffer, buflen, bc); |
| 232 | } |
| 233 | |
| 234 | static int mlx5_ib_read_user_wqe_rq(struct mlx5_ib_qp *qp, int wqe_index, |
| 235 | void *buffer, size_t buflen, size_t *bc) |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 236 | { |
| 237 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 238 | struct ib_umem *umem = base->ubuffer.umem; |
| 239 | struct mlx5_ib_wq *wq = &qp->rq; |
| 240 | size_t bytes_copied; |
| 241 | int ret; |
| 242 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 243 | ret = mlx5_ib_read_user_wqe_common(umem, buffer, buflen, wqe_index, |
| 244 | wq->offset, wq->wqe_cnt, |
| 245 | wq->wqe_shift, buflen, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 246 | &bytes_copied); |
| 247 | |
| 248 | if (ret) |
| 249 | return ret; |
| 250 | *bc = bytes_copied; |
| 251 | return 0; |
| 252 | } |
| 253 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 254 | int mlx5_ib_read_wqe_rq(struct mlx5_ib_qp *qp, int wqe_index, void *buffer, |
| 255 | size_t buflen, size_t *bc) |
| 256 | { |
| 257 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 258 | struct ib_umem *umem = base->ubuffer.umem; |
| 259 | struct mlx5_ib_wq *wq = &qp->rq; |
| 260 | size_t wqe_size = 1 << wq->wqe_shift; |
| 261 | |
| 262 | if (buflen < wqe_size) |
| 263 | return -EINVAL; |
| 264 | |
| 265 | if (!umem) |
| 266 | return -EOPNOTSUPP; |
| 267 | |
| 268 | return mlx5_ib_read_user_wqe_rq(qp, wqe_index, buffer, buflen, bc); |
| 269 | } |
| 270 | |
| 271 | static int mlx5_ib_read_user_wqe_srq(struct mlx5_ib_srq *srq, int wqe_index, |
| 272 | void *buffer, size_t buflen, size_t *bc) |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 273 | { |
| 274 | struct ib_umem *umem = srq->umem; |
| 275 | size_t bytes_copied; |
| 276 | int ret; |
| 277 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 278 | ret = mlx5_ib_read_user_wqe_common(umem, buffer, buflen, wqe_index, 0, |
| 279 | srq->msrq.max, srq->msrq.wqe_shift, |
| 280 | buflen, &bytes_copied); |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 281 | |
| 282 | if (ret) |
| 283 | return ret; |
| 284 | *bc = bytes_copied; |
| 285 | return 0; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 286 | } |
| 287 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 288 | int mlx5_ib_read_wqe_srq(struct mlx5_ib_srq *srq, int wqe_index, void *buffer, |
| 289 | size_t buflen, size_t *bc) |
| 290 | { |
| 291 | struct ib_umem *umem = srq->umem; |
| 292 | size_t wqe_size = 1 << srq->msrq.wqe_shift; |
| 293 | |
| 294 | if (buflen < wqe_size) |
| 295 | return -EINVAL; |
| 296 | |
| 297 | if (!umem) |
| 298 | return -EOPNOTSUPP; |
| 299 | |
| 300 | return mlx5_ib_read_user_wqe_srq(srq, wqe_index, buffer, buflen, bc); |
| 301 | } |
| 302 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 303 | static void mlx5_ib_qp_event(struct mlx5_core_qp *qp, int type) |
| 304 | { |
| 305 | struct ib_qp *ibqp = &to_mibqp(qp)->ibqp; |
| 306 | struct ib_event event; |
| 307 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 308 | if (type == MLX5_EVENT_TYPE_PATH_MIG) { |
| 309 | /* This event is only valid for trans_qps */ |
| 310 | to_mibqp(qp)->port = to_mibqp(qp)->trans_qp.alt_port; |
| 311 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 312 | |
| 313 | if (ibqp->event_handler) { |
| 314 | event.device = ibqp->device; |
| 315 | event.element.qp = ibqp; |
| 316 | switch (type) { |
| 317 | case MLX5_EVENT_TYPE_PATH_MIG: |
| 318 | event.event = IB_EVENT_PATH_MIG; |
| 319 | break; |
| 320 | case MLX5_EVENT_TYPE_COMM_EST: |
| 321 | event.event = IB_EVENT_COMM_EST; |
| 322 | break; |
| 323 | case MLX5_EVENT_TYPE_SQ_DRAINED: |
| 324 | event.event = IB_EVENT_SQ_DRAINED; |
| 325 | break; |
| 326 | case MLX5_EVENT_TYPE_SRQ_LAST_WQE: |
| 327 | event.event = IB_EVENT_QP_LAST_WQE_REACHED; |
| 328 | break; |
| 329 | case MLX5_EVENT_TYPE_WQ_CATAS_ERROR: |
| 330 | event.event = IB_EVENT_QP_FATAL; |
| 331 | break; |
| 332 | case MLX5_EVENT_TYPE_PATH_MIG_FAILED: |
| 333 | event.event = IB_EVENT_PATH_MIG_ERR; |
| 334 | break; |
| 335 | case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR: |
| 336 | event.event = IB_EVENT_QP_REQ_ERR; |
| 337 | break; |
| 338 | case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR: |
| 339 | event.event = IB_EVENT_QP_ACCESS_ERR; |
| 340 | break; |
| 341 | default: |
| 342 | pr_warn("mlx5_ib: Unexpected event type %d on QP %06x\n", type, qp->qpn); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | ibqp->event_handler(&event, ibqp->qp_context); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | static int set_rq_size(struct mlx5_ib_dev *dev, struct ib_qp_cap *cap, |
| 351 | int has_rq, struct mlx5_ib_qp *qp, struct mlx5_ib_create_qp *ucmd) |
| 352 | { |
| 353 | int wqe_size; |
| 354 | int wq_size; |
| 355 | |
| 356 | /* Sanity check RQ size before proceeding */ |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 357 | if (cap->max_recv_wr > (1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz))) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 358 | return -EINVAL; |
| 359 | |
| 360 | if (!has_rq) { |
| 361 | qp->rq.max_gs = 0; |
| 362 | qp->rq.wqe_cnt = 0; |
| 363 | qp->rq.wqe_shift = 0; |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 364 | cap->max_recv_wr = 0; |
| 365 | cap->max_recv_sge = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 366 | } else { |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 367 | int wq_sig = !!(qp->flags_en & MLX5_QP_FLAG_SIGNATURE); |
| 368 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 369 | if (ucmd) { |
| 370 | qp->rq.wqe_cnt = ucmd->rq_wqe_count; |
Leon Romanovsky | 002bf22 | 2018-04-23 17:01:53 +0300 | [diff] [blame] | 371 | if (ucmd->rq_wqe_shift > BITS_PER_BYTE * sizeof(ucmd->rq_wqe_shift)) |
| 372 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 373 | qp->rq.wqe_shift = ucmd->rq_wqe_shift; |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 374 | if ((1 << qp->rq.wqe_shift) / |
| 375 | sizeof(struct mlx5_wqe_data_seg) < |
| 376 | wq_sig) |
Leon Romanovsky | 002bf22 | 2018-04-23 17:01:53 +0300 | [diff] [blame] | 377 | return -EINVAL; |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 378 | qp->rq.max_gs = |
| 379 | (1 << qp->rq.wqe_shift) / |
| 380 | sizeof(struct mlx5_wqe_data_seg) - |
| 381 | wq_sig; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 382 | qp->rq.max_post = qp->rq.wqe_cnt; |
| 383 | } else { |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 384 | wqe_size = |
| 385 | wq_sig ? sizeof(struct mlx5_wqe_signature_seg) : |
| 386 | 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 387 | wqe_size += cap->max_recv_sge * sizeof(struct mlx5_wqe_data_seg); |
| 388 | wqe_size = roundup_pow_of_two(wqe_size); |
| 389 | wq_size = roundup_pow_of_two(cap->max_recv_wr) * wqe_size; |
| 390 | wq_size = max_t(int, wq_size, MLX5_SEND_WQE_BB); |
| 391 | qp->rq.wqe_cnt = wq_size / wqe_size; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 392 | if (wqe_size > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 393 | mlx5_ib_dbg(dev, "wqe_size %d, max %d\n", |
| 394 | wqe_size, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 395 | MLX5_CAP_GEN(dev->mdev, |
| 396 | max_wqe_sz_rq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 397 | return -EINVAL; |
| 398 | } |
| 399 | qp->rq.wqe_shift = ilog2(wqe_size); |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 400 | qp->rq.max_gs = |
| 401 | (1 << qp->rq.wqe_shift) / |
| 402 | sizeof(struct mlx5_wqe_data_seg) - |
| 403 | wq_sig; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 404 | qp->rq.max_post = qp->rq.wqe_cnt; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 411 | static int sq_overhead(struct ib_qp_init_attr *attr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 412 | { |
Andi Shyti | 618af38 | 2013-07-16 15:35:01 +0200 | [diff] [blame] | 413 | int size = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 414 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 415 | switch (attr->qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 416 | case IB_QPT_XRC_INI: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 417 | size += sizeof(struct mlx5_wqe_xrc_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 418 | /* fall through */ |
| 419 | case IB_QPT_RC: |
| 420 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Leon Romanovsky | 75c1657e | 2016-02-11 21:09:57 +0200 | [diff] [blame] | 421 | max(sizeof(struct mlx5_wqe_atomic_seg) + |
| 422 | sizeof(struct mlx5_wqe_raddr_seg), |
| 423 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 424 | sizeof(struct mlx5_mkey_seg) + |
| 425 | MLX5_IB_SQ_UMR_INLINE_THRESHOLD / |
| 426 | MLX5_IB_UMR_OCTOWORD); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 427 | break; |
| 428 | |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 429 | case IB_QPT_XRC_TGT: |
| 430 | return 0; |
| 431 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 432 | case IB_QPT_UC: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 433 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Leon Romanovsky | 75c1657e | 2016-02-11 21:09:57 +0200 | [diff] [blame] | 434 | max(sizeof(struct mlx5_wqe_raddr_seg), |
| 435 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
| 436 | sizeof(struct mlx5_mkey_seg)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 437 | break; |
| 438 | |
| 439 | case IB_QPT_UD: |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 440 | if (attr->create_flags & IB_QP_CREATE_IPOIB_UD_LSO) |
| 441 | size += sizeof(struct mlx5_wqe_eth_pad) + |
| 442 | sizeof(struct mlx5_wqe_eth_seg); |
| 443 | /* fall through */ |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 444 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 445 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 446 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 447 | sizeof(struct mlx5_wqe_datagram_seg); |
| 448 | break; |
| 449 | |
| 450 | case MLX5_IB_QPT_REG_UMR: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 451 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 452 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
| 453 | sizeof(struct mlx5_mkey_seg); |
| 454 | break; |
| 455 | |
| 456 | default: |
| 457 | return -EINVAL; |
| 458 | } |
| 459 | |
| 460 | return size; |
| 461 | } |
| 462 | |
| 463 | static int calc_send_wqe(struct ib_qp_init_attr *attr) |
| 464 | { |
| 465 | int inl_size = 0; |
| 466 | int size; |
| 467 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 468 | size = sq_overhead(attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 469 | if (size < 0) |
| 470 | return size; |
| 471 | |
| 472 | if (attr->cap.max_inline_data) { |
| 473 | inl_size = size + sizeof(struct mlx5_wqe_inline_seg) + |
| 474 | attr->cap.max_inline_data; |
| 475 | } |
| 476 | |
| 477 | size += attr->cap.max_send_sge * sizeof(struct mlx5_wqe_data_seg); |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 478 | if (attr->create_flags & IB_QP_CREATE_INTEGRITY_EN && |
Sagi Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 479 | ALIGN(max_t(int, inl_size, size), MLX5_SEND_WQE_BB) < MLX5_SIG_WQE_SIZE) |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 480 | return MLX5_SIG_WQE_SIZE; |
Sagi Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 481 | else |
| 482 | return ALIGN(max_t(int, inl_size, size), MLX5_SEND_WQE_BB); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 483 | } |
| 484 | |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 485 | static int get_send_sge(struct ib_qp_init_attr *attr, int wqe_size) |
| 486 | { |
| 487 | int max_sge; |
| 488 | |
| 489 | if (attr->qp_type == IB_QPT_RC) |
| 490 | max_sge = (min_t(int, wqe_size, 512) - |
| 491 | sizeof(struct mlx5_wqe_ctrl_seg) - |
| 492 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 493 | sizeof(struct mlx5_wqe_data_seg); |
| 494 | else if (attr->qp_type == IB_QPT_XRC_INI) |
| 495 | max_sge = (min_t(int, wqe_size, 512) - |
| 496 | sizeof(struct mlx5_wqe_ctrl_seg) - |
| 497 | sizeof(struct mlx5_wqe_xrc_seg) - |
| 498 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 499 | sizeof(struct mlx5_wqe_data_seg); |
| 500 | else |
| 501 | max_sge = (wqe_size - sq_overhead(attr)) / |
| 502 | sizeof(struct mlx5_wqe_data_seg); |
| 503 | |
| 504 | return min_t(int, max_sge, wqe_size - sq_overhead(attr) / |
| 505 | sizeof(struct mlx5_wqe_data_seg)); |
| 506 | } |
| 507 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 508 | static int calc_sq_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr, |
| 509 | struct mlx5_ib_qp *qp) |
| 510 | { |
| 511 | int wqe_size; |
| 512 | int wq_size; |
| 513 | |
| 514 | if (!attr->cap.max_send_wr) |
| 515 | return 0; |
| 516 | |
| 517 | wqe_size = calc_send_wqe(attr); |
| 518 | mlx5_ib_dbg(dev, "wqe_size %d\n", wqe_size); |
| 519 | if (wqe_size < 0) |
| 520 | return wqe_size; |
| 521 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 522 | if (wqe_size > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)) { |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 523 | mlx5_ib_dbg(dev, "wqe_size(%d) > max_sq_desc_sz(%d)\n", |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 524 | wqe_size, MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 525 | return -EINVAL; |
| 526 | } |
| 527 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 528 | qp->max_inline_data = wqe_size - sq_overhead(attr) - |
| 529 | sizeof(struct mlx5_wqe_inline_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 530 | attr->cap.max_inline_data = qp->max_inline_data; |
| 531 | |
| 532 | wq_size = roundup_pow_of_two(attr->cap.max_send_wr * wqe_size); |
| 533 | qp->sq.wqe_cnt = wq_size / MLX5_SEND_WQE_BB; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 534 | if (qp->sq.wqe_cnt > (1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz))) { |
Bart Van Assche | 1974ab9 | 2016-12-05 17:19:52 -0800 | [diff] [blame] | 535 | mlx5_ib_dbg(dev, "send queue size (%d * %d / %d -> %d) exceeds limits(%d)\n", |
| 536 | attr->cap.max_send_wr, wqe_size, MLX5_SEND_WQE_BB, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 537 | qp->sq.wqe_cnt, |
| 538 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz)); |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 539 | return -ENOMEM; |
| 540 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 541 | qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 542 | qp->sq.max_gs = get_send_sge(attr, wqe_size); |
| 543 | if (qp->sq.max_gs < attr->cap.max_send_sge) |
| 544 | return -ENOMEM; |
| 545 | |
| 546 | attr->cap.max_send_sge = qp->sq.max_gs; |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 547 | qp->sq.max_post = wq_size / wqe_size; |
| 548 | attr->cap.max_send_wr = qp->sq.max_post; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 549 | |
| 550 | return wq_size; |
| 551 | } |
| 552 | |
| 553 | static int set_user_buf_size(struct mlx5_ib_dev *dev, |
| 554 | struct mlx5_ib_qp *qp, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 555 | struct mlx5_ib_create_qp *ucmd, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 556 | struct mlx5_ib_qp_base *base, |
| 557 | struct ib_qp_init_attr *attr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 558 | { |
| 559 | int desc_sz = 1 << qp->sq.wqe_shift; |
| 560 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 561 | if (desc_sz > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 562 | mlx5_ib_warn(dev, "desc_sz %d, max_sq_desc_sz %d\n", |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 563 | desc_sz, MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 564 | return -EINVAL; |
| 565 | } |
| 566 | |
Gal Pressman | af8b38e | 2019-02-06 15:45:35 +0200 | [diff] [blame] | 567 | if (ucmd->sq_wqe_count && !is_power_of_2(ucmd->sq_wqe_count)) { |
| 568 | mlx5_ib_warn(dev, "sq_wqe_count %d is not a power of two\n", |
| 569 | ucmd->sq_wqe_count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 570 | return -EINVAL; |
| 571 | } |
| 572 | |
| 573 | qp->sq.wqe_cnt = ucmd->sq_wqe_count; |
| 574 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 575 | if (qp->sq.wqe_cnt > (1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz))) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 576 | mlx5_ib_warn(dev, "wqe_cnt %d, max_wqes %d\n", |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 577 | qp->sq.wqe_cnt, |
| 578 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 579 | return -EINVAL; |
| 580 | } |
| 581 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 582 | if (attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 583 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 584 | base->ubuffer.buf_size = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
| 585 | qp->raw_packet_qp.sq.ubuffer.buf_size = qp->sq.wqe_cnt << 6; |
| 586 | } else { |
| 587 | base->ubuffer.buf_size = (qp->rq.wqe_cnt << qp->rq.wqe_shift) + |
| 588 | (qp->sq.wqe_cnt << 6); |
| 589 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 590 | |
| 591 | return 0; |
| 592 | } |
| 593 | |
| 594 | static int qp_has_rq(struct ib_qp_init_attr *attr) |
| 595 | { |
| 596 | if (attr->qp_type == IB_QPT_XRC_INI || |
| 597 | attr->qp_type == IB_QPT_XRC_TGT || attr->srq || |
| 598 | attr->qp_type == MLX5_IB_QPT_REG_UMR || |
| 599 | !attr->cap.max_recv_wr) |
| 600 | return 0; |
| 601 | |
| 602 | return 1; |
| 603 | } |
| 604 | |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 605 | enum { |
| 606 | /* this is the first blue flame register in the array of bfregs assigned |
| 607 | * to a processes. Since we do not use it for blue flame but rather |
| 608 | * regular 64 bit doorbells, we do not need a lock for maintaiing |
| 609 | * "odd/even" order |
| 610 | */ |
| 611 | NUM_NON_BLUE_FLAME_BFREGS = 1, |
| 612 | }; |
| 613 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 614 | static int max_bfregs(struct mlx5_ib_dev *dev, struct mlx5_bfreg_info *bfregi) |
| 615 | { |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 616 | return get_num_static_uars(dev, bfregi) * MLX5_NON_FP_BFREGS_PER_UAR; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | static int num_med_bfreg(struct mlx5_ib_dev *dev, |
| 620 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 621 | { |
| 622 | int n; |
| 623 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 624 | n = max_bfregs(dev, bfregi) - bfregi->num_low_latency_bfregs - |
| 625 | NUM_NON_BLUE_FLAME_BFREGS; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 626 | |
| 627 | return n >= 0 ? n : 0; |
| 628 | } |
| 629 | |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 630 | static int first_med_bfreg(struct mlx5_ib_dev *dev, |
| 631 | struct mlx5_bfreg_info *bfregi) |
| 632 | { |
| 633 | return num_med_bfreg(dev, bfregi) ? 1 : -ENOMEM; |
| 634 | } |
| 635 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 636 | static int first_hi_bfreg(struct mlx5_ib_dev *dev, |
| 637 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 638 | { |
| 639 | int med; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 640 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 641 | med = num_med_bfreg(dev, bfregi); |
| 642 | return ++med; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 643 | } |
| 644 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 645 | static int alloc_high_class_bfreg(struct mlx5_ib_dev *dev, |
| 646 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 647 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 648 | int i; |
| 649 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 650 | for (i = first_hi_bfreg(dev, bfregi); i < max_bfregs(dev, bfregi); i++) { |
| 651 | if (!bfregi->count[i]) { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 652 | bfregi->count[i]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 653 | return i; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | return -ENOMEM; |
| 658 | } |
| 659 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 660 | static int alloc_med_class_bfreg(struct mlx5_ib_dev *dev, |
| 661 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 662 | { |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 663 | int minidx = first_med_bfreg(dev, bfregi); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 664 | int i; |
| 665 | |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 666 | if (minidx < 0) |
| 667 | return minidx; |
| 668 | |
| 669 | for (i = minidx; i < first_hi_bfreg(dev, bfregi); i++) { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 670 | if (bfregi->count[i] < bfregi->count[minidx]) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 671 | minidx = i; |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 672 | if (!bfregi->count[minidx]) |
| 673 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 674 | } |
| 675 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 676 | bfregi->count[minidx]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 677 | return minidx; |
| 678 | } |
| 679 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 680 | static int alloc_bfreg(struct mlx5_ib_dev *dev, |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 681 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 682 | { |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 683 | int bfregn = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 684 | |
Yishai Hadas | 0a2fd01 | 2020-03-24 08:01:43 +0200 | [diff] [blame] | 685 | if (bfregi->lib_uar_dyn) |
| 686 | return -EINVAL; |
| 687 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 688 | mutex_lock(&bfregi->lock); |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 689 | if (bfregi->ver >= 2) { |
| 690 | bfregn = alloc_high_class_bfreg(dev, bfregi); |
| 691 | if (bfregn < 0) |
| 692 | bfregn = alloc_med_class_bfreg(dev, bfregi); |
| 693 | } |
| 694 | |
| 695 | if (bfregn < 0) { |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 696 | BUILD_BUG_ON(NUM_NON_BLUE_FLAME_BFREGS != 1); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 697 | bfregn = 0; |
| 698 | bfregi->count[bfregn]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 699 | } |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 700 | mutex_unlock(&bfregi->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 701 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 702 | return bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 703 | } |
| 704 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 705 | void mlx5_ib_free_bfreg(struct mlx5_ib_dev *dev, struct mlx5_bfreg_info *bfregi, int bfregn) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 706 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 707 | mutex_lock(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 708 | bfregi->count[bfregn]--; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 709 | mutex_unlock(&bfregi->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | static enum mlx5_qp_state to_mlx5_state(enum ib_qp_state state) |
| 713 | { |
| 714 | switch (state) { |
| 715 | case IB_QPS_RESET: return MLX5_QP_STATE_RST; |
| 716 | case IB_QPS_INIT: return MLX5_QP_STATE_INIT; |
| 717 | case IB_QPS_RTR: return MLX5_QP_STATE_RTR; |
| 718 | case IB_QPS_RTS: return MLX5_QP_STATE_RTS; |
| 719 | case IB_QPS_SQD: return MLX5_QP_STATE_SQD; |
| 720 | case IB_QPS_SQE: return MLX5_QP_STATE_SQER; |
| 721 | case IB_QPS_ERR: return MLX5_QP_STATE_ERR; |
| 722 | default: return -1; |
| 723 | } |
| 724 | } |
| 725 | |
| 726 | static int to_mlx5_st(enum ib_qp_type type) |
| 727 | { |
| 728 | switch (type) { |
| 729 | case IB_QPT_RC: return MLX5_QP_ST_RC; |
| 730 | case IB_QPT_UC: return MLX5_QP_ST_UC; |
| 731 | case IB_QPT_UD: return MLX5_QP_ST_UD; |
| 732 | case MLX5_IB_QPT_REG_UMR: return MLX5_QP_ST_REG_UMR; |
| 733 | case IB_QPT_XRC_INI: |
| 734 | case IB_QPT_XRC_TGT: return MLX5_QP_ST_XRC; |
| 735 | case IB_QPT_SMI: return MLX5_QP_ST_QP0; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 736 | case MLX5_IB_QPT_HW_GSI: return MLX5_QP_ST_QP1; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 737 | case MLX5_IB_QPT_DCI: return MLX5_QP_ST_DCI; |
Leon Romanovsky | 3ae7e66 | 2020-04-27 18:46:19 +0300 | [diff] [blame] | 738 | case IB_QPT_RAW_PACKET: return MLX5_QP_ST_RAW_ETHERTYPE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 739 | default: return -EINVAL; |
| 740 | } |
| 741 | } |
| 742 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 743 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, |
| 744 | struct mlx5_ib_cq *recv_cq); |
| 745 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, |
| 746 | struct mlx5_ib_cq *recv_cq); |
| 747 | |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 748 | int bfregn_to_uar_index(struct mlx5_ib_dev *dev, |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 749 | struct mlx5_bfreg_info *bfregi, u32 bfregn, |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 750 | bool dyn_bfreg) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 751 | { |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 752 | unsigned int bfregs_per_sys_page; |
| 753 | u32 index_of_sys_page; |
| 754 | u32 offset; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 755 | |
Yishai Hadas | 0a2fd01 | 2020-03-24 08:01:43 +0200 | [diff] [blame] | 756 | if (bfregi->lib_uar_dyn) |
| 757 | return -EINVAL; |
| 758 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 759 | bfregs_per_sys_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k) * |
| 760 | MLX5_NON_FP_BFREGS_PER_UAR; |
| 761 | index_of_sys_page = bfregn / bfregs_per_sys_page; |
| 762 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 763 | if (dyn_bfreg) { |
| 764 | index_of_sys_page += bfregi->num_static_sys_pages; |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 765 | |
| 766 | if (index_of_sys_page >= bfregi->num_sys_pages) |
| 767 | return -EINVAL; |
| 768 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 769 | if (bfregn > bfregi->num_dyn_bfregs || |
| 770 | bfregi->sys_pages[index_of_sys_page] == MLX5_IB_INVALID_UAR_INDEX) { |
| 771 | mlx5_ib_dbg(dev, "Invalid dynamic uar index\n"); |
| 772 | return -EINVAL; |
| 773 | } |
| 774 | } |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 775 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 776 | offset = bfregn % bfregs_per_sys_page / MLX5_NON_FP_BFREGS_PER_UAR; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 777 | return bfregi->sys_pages[index_of_sys_page] + offset; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 778 | } |
| 779 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 780 | static int mlx5_ib_umem_get(struct mlx5_ib_dev *dev, struct ib_udata *udata, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 781 | unsigned long addr, size_t size, |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 782 | struct ib_umem **umem, int *npages, int *page_shift, |
| 783 | int *ncont, u32 *offset) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 784 | { |
| 785 | int err; |
| 786 | |
Moni Shoua | c320e52 | 2020-01-15 14:43:31 +0200 | [diff] [blame] | 787 | *umem = ib_umem_get(&dev->ib_dev, addr, size, 0); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 788 | if (IS_ERR(*umem)) { |
| 789 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 790 | return PTR_ERR(*umem); |
| 791 | } |
| 792 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 793 | mlx5_ib_cont_pages(*umem, addr, 0, npages, page_shift, ncont, NULL); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 794 | |
| 795 | err = mlx5_ib_get_buf_offset(addr, *page_shift, offset); |
| 796 | if (err) { |
| 797 | mlx5_ib_warn(dev, "bad offset\n"); |
| 798 | goto err_umem; |
| 799 | } |
| 800 | |
| 801 | mlx5_ib_dbg(dev, "addr 0x%lx, size %zu, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 802 | addr, size, *npages, *page_shift, *ncont, *offset); |
| 803 | |
| 804 | return 0; |
| 805 | |
| 806 | err_umem: |
| 807 | ib_umem_release(*umem); |
| 808 | *umem = NULL; |
| 809 | |
| 810 | return err; |
| 811 | } |
| 812 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 813 | static void destroy_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 814 | struct mlx5_ib_rwq *rwq, struct ib_udata *udata) |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 815 | { |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 816 | struct mlx5_ib_ucontext *context = |
| 817 | rdma_udata_to_drv_context( |
| 818 | udata, |
| 819 | struct mlx5_ib_ucontext, |
| 820 | ibucontext); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 821 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 822 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_DELAY_DROP) |
| 823 | atomic_dec(&dev->delay_drop.rqs_cnt); |
| 824 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 825 | mlx5_ib_db_unmap_user(context, &rwq->db); |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 826 | ib_umem_release(rwq->umem); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | static int create_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 830 | struct ib_udata *udata, struct mlx5_ib_rwq *rwq, |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 831 | struct mlx5_ib_create_wq *ucmd) |
| 832 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 833 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 834 | udata, struct mlx5_ib_ucontext, ibucontext); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 835 | int page_shift = 0; |
| 836 | int npages; |
| 837 | u32 offset = 0; |
| 838 | int ncont = 0; |
| 839 | int err; |
| 840 | |
| 841 | if (!ucmd->buf_addr) |
| 842 | return -EINVAL; |
| 843 | |
Moni Shoua | c320e52 | 2020-01-15 14:43:31 +0200 | [diff] [blame] | 844 | rwq->umem = ib_umem_get(&dev->ib_dev, ucmd->buf_addr, rwq->buf_size, 0); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 845 | if (IS_ERR(rwq->umem)) { |
| 846 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 847 | err = PTR_ERR(rwq->umem); |
| 848 | return err; |
| 849 | } |
| 850 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 851 | mlx5_ib_cont_pages(rwq->umem, ucmd->buf_addr, 0, &npages, &page_shift, |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 852 | &ncont, NULL); |
| 853 | err = mlx5_ib_get_buf_offset(ucmd->buf_addr, page_shift, |
| 854 | &rwq->rq_page_offset); |
| 855 | if (err) { |
| 856 | mlx5_ib_warn(dev, "bad offset\n"); |
| 857 | goto err_umem; |
| 858 | } |
| 859 | |
| 860 | rwq->rq_num_pas = ncont; |
| 861 | rwq->page_shift = page_shift; |
| 862 | rwq->log_page_size = page_shift - MLX5_ADAPTER_PAGE_SHIFT; |
| 863 | rwq->wq_sig = !!(ucmd->flags & MLX5_WQ_FLAG_SIGNATURE); |
| 864 | |
| 865 | mlx5_ib_dbg(dev, "addr 0x%llx, size %zd, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 866 | (unsigned long long)ucmd->buf_addr, rwq->buf_size, |
| 867 | npages, page_shift, ncont, offset); |
| 868 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 869 | err = mlx5_ib_db_map_user(ucontext, udata, ucmd->db_addr, &rwq->db); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 870 | if (err) { |
| 871 | mlx5_ib_dbg(dev, "map failed\n"); |
| 872 | goto err_umem; |
| 873 | } |
| 874 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 875 | return 0; |
| 876 | |
| 877 | err_umem: |
| 878 | ib_umem_release(rwq->umem); |
| 879 | return err; |
| 880 | } |
| 881 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 882 | static int adjust_bfregn(struct mlx5_ib_dev *dev, |
| 883 | struct mlx5_bfreg_info *bfregi, int bfregn) |
| 884 | { |
| 885 | return bfregn / MLX5_NON_FP_BFREGS_PER_UAR * MLX5_BFREGS_PER_UAR + |
| 886 | bfregn % MLX5_NON_FP_BFREGS_PER_UAR; |
| 887 | } |
| 888 | |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 889 | static int _create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 890 | struct mlx5_ib_qp *qp, struct ib_udata *udata, |
| 891 | struct ib_qp_init_attr *attr, u32 **in, |
| 892 | struct mlx5_ib_create_qp_resp *resp, int *inlen, |
| 893 | struct mlx5_ib_qp_base *base, |
| 894 | struct mlx5_ib_create_qp *ucmd) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 895 | { |
| 896 | struct mlx5_ib_ucontext *context; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 897 | struct mlx5_ib_ubuffer *ubuffer = &base->ubuffer; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 898 | int page_shift = 0; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 899 | int uar_index = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 900 | int npages; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 901 | u32 offset = 0; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 902 | int bfregn; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 903 | int ncont = 0; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 904 | __be64 *pas; |
| 905 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 906 | int err; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 907 | u16 uid; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 908 | u32 uar_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 909 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 910 | context = rdma_udata_to_drv_context(udata, struct mlx5_ib_ucontext, |
| 911 | ibucontext); |
Leon Romanovsky | 76883a6 | 2020-04-27 18:46:23 +0300 | [diff] [blame] | 912 | uar_flags = qp->flags_en & |
| 913 | (MLX5_QP_FLAG_UAR_PAGE_INDEX | MLX5_QP_FLAG_BFREG_INDEX); |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 914 | switch (uar_flags) { |
| 915 | case MLX5_QP_FLAG_UAR_PAGE_INDEX: |
Leon Romanovsky | 76883a6 | 2020-04-27 18:46:23 +0300 | [diff] [blame] | 916 | uar_index = ucmd->bfreg_index; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 917 | bfregn = MLX5_IB_INVALID_BFREG; |
| 918 | break; |
| 919 | case MLX5_QP_FLAG_BFREG_INDEX: |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 920 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, |
Leon Romanovsky | 76883a6 | 2020-04-27 18:46:23 +0300 | [diff] [blame] | 921 | ucmd->bfreg_index, true); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 922 | if (uar_index < 0) |
| 923 | return uar_index; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 924 | bfregn = MLX5_IB_INVALID_BFREG; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 925 | break; |
| 926 | case 0: |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 927 | if (qp->flags & IB_QP_CREATE_CROSS_CHANNEL) |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 928 | return -EINVAL; |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 929 | bfregn = alloc_bfreg(dev, &context->bfregi); |
| 930 | if (bfregn < 0) |
| 931 | return bfregn; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 932 | break; |
| 933 | default: |
| 934 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 935 | } |
| 936 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 937 | mlx5_ib_dbg(dev, "bfregn 0x%x, uar_index 0x%x\n", bfregn, uar_index); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 938 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 939 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, bfregn, |
| 940 | false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 941 | |
Haggai Eran | 48fea83 | 2014-05-22 14:50:11 +0300 | [diff] [blame] | 942 | qp->rq.offset = 0; |
| 943 | qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); |
| 944 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
| 945 | |
Leon Romanovsky | 76883a6 | 2020-04-27 18:46:23 +0300 | [diff] [blame] | 946 | err = set_user_buf_size(dev, qp, ucmd, base, attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 947 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 948 | goto err_bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 949 | |
Leon Romanovsky | 76883a6 | 2020-04-27 18:46:23 +0300 | [diff] [blame] | 950 | if (ucmd->buf_addr && ubuffer->buf_size) { |
| 951 | ubuffer->buf_addr = ucmd->buf_addr; |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 952 | err = mlx5_ib_umem_get(dev, udata, ubuffer->buf_addr, |
| 953 | ubuffer->buf_size, &ubuffer->umem, |
| 954 | &npages, &page_shift, &ncont, &offset); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 955 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 956 | goto err_bfreg; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 957 | } else { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 958 | ubuffer->umem = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 959 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 960 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 961 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 962 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 963 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 964 | if (!*in) { |
| 965 | err = -ENOMEM; |
| 966 | goto err_umem; |
| 967 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 968 | |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 969 | uid = (attr->qp_type != IB_QPT_XRC_INI) ? to_mpd(pd)->uid : 0; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 970 | MLX5_SET(create_qp_in, *in, uid, uid); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 971 | pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, *in, pas); |
| 972 | if (ubuffer->umem) |
| 973 | mlx5_ib_populate_pas(dev, ubuffer->umem, page_shift, pas, 0); |
| 974 | |
| 975 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 976 | |
| 977 | MLX5_SET(qpc, qpc, log_page_size, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 978 | MLX5_SET(qpc, qpc, page_offset, offset); |
| 979 | |
| 980 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 981 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 982 | resp->bfreg_index = adjust_bfregn(dev, &context->bfregi, bfregn); |
| 983 | else |
| 984 | resp->bfreg_index = MLX5_IB_INVALID_BFREG; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 985 | qp->bfregn = bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 986 | |
Leon Romanovsky | 76883a6 | 2020-04-27 18:46:23 +0300 | [diff] [blame] | 987 | err = mlx5_ib_db_map_user(context, udata, ucmd->db_addr, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 988 | if (err) { |
| 989 | mlx5_ib_dbg(dev, "map failed\n"); |
| 990 | goto err_free; |
| 991 | } |
| 992 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 993 | return 0; |
| 994 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 995 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 996 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 997 | |
| 998 | err_umem: |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 999 | ib_umem_release(ubuffer->umem); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1000 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1001 | err_bfreg: |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1002 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 1003 | mlx5_ib_free_bfreg(dev, &context->bfregi, bfregn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1004 | return err; |
| 1005 | } |
| 1006 | |
Leon Romanovsky | 747c519 | 2020-04-27 18:46:29 +0300 | [diff] [blame] | 1007 | static void destroy_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 1008 | struct mlx5_ib_qp_base *base, struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1009 | { |
Leon Romanovsky | 747c519 | 2020-04-27 18:46:29 +0300 | [diff] [blame] | 1010 | struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context( |
| 1011 | udata, struct mlx5_ib_ucontext, ibucontext); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1012 | |
Leon Romanovsky | 747c519 | 2020-04-27 18:46:29 +0300 | [diff] [blame] | 1013 | if (udata) { |
| 1014 | /* User QP */ |
| 1015 | mlx5_ib_db_unmap_user(context, &qp->db); |
| 1016 | ib_umem_release(base->ubuffer.umem); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1017 | |
Leon Romanovsky | 747c519 | 2020-04-27 18:46:29 +0300 | [diff] [blame] | 1018 | /* |
| 1019 | * Free only the BFREGs which are handled by the kernel. |
| 1020 | * BFREGs of UARs allocated dynamically are handled by user. |
| 1021 | */ |
| 1022 | if (qp->bfregn != MLX5_IB_INVALID_BFREG) |
| 1023 | mlx5_ib_free_bfreg(dev, &context->bfregi, qp->bfregn); |
| 1024 | return; |
| 1025 | } |
| 1026 | |
| 1027 | /* Kernel QP */ |
| 1028 | kvfree(qp->sq.wqe_head); |
| 1029 | kvfree(qp->sq.w_list); |
| 1030 | kvfree(qp->sq.wrid); |
| 1031 | kvfree(qp->sq.wr_data); |
| 1032 | kvfree(qp->rq.wrid); |
| 1033 | if (qp->db.db) |
| 1034 | mlx5_db_free(dev->mdev, &qp->db); |
| 1035 | if (qp->buf.frags) |
| 1036 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1037 | } |
| 1038 | |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 1039 | static int _create_kernel_qp(struct mlx5_ib_dev *dev, |
| 1040 | struct ib_qp_init_attr *init_attr, |
| 1041 | struct mlx5_ib_qp *qp, u32 **in, int *inlen, |
| 1042 | struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1043 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1044 | int uar_index; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1045 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1046 | int err; |
| 1047 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1048 | if (init_attr->qp_type == MLX5_IB_QPT_REG_UMR) |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1049 | qp->bf.bfreg = &dev->fp_bfreg; |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1050 | else if (qp->flags & MLX5_IB_QP_CREATE_WC_TEST) |
Michael Guralnik | 11f552e | 2019-06-10 15:21:24 +0300 | [diff] [blame] | 1051 | qp->bf.bfreg = &dev->wc_bfreg; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1052 | else |
| 1053 | qp->bf.bfreg = &dev->bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1054 | |
Eli Cohen | d8030b0 | 2017-02-09 19:31:47 +0200 | [diff] [blame] | 1055 | /* We need to divide by two since each register is comprised of |
| 1056 | * two buffers of identical size, namely odd and even |
| 1057 | */ |
| 1058 | qp->bf.buf_size = (1 << MLX5_CAP_GEN(dev->mdev, log_bf_reg_size)) / 2; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1059 | uar_index = qp->bf.bfreg->index; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1060 | |
| 1061 | err = calc_sq_size(dev, init_attr, qp); |
| 1062 | if (err < 0) { |
| 1063 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1064 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | qp->rq.offset = 0; |
| 1068 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 1069 | base->ubuffer.buf_size = err + (qp->rq.wqe_cnt << qp->rq.wqe_shift); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1070 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1071 | err = mlx5_frag_buf_alloc_node(dev->mdev, base->ubuffer.buf_size, |
| 1072 | &qp->buf, dev->mdev->priv.numa_node); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1073 | if (err) { |
| 1074 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1075 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1076 | } |
| 1077 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1078 | if (qp->rq.wqe_cnt) |
| 1079 | mlx5_init_fbc(qp->buf.frags, qp->rq.wqe_shift, |
| 1080 | ilog2(qp->rq.wqe_cnt), &qp->rq.fbc); |
| 1081 | |
| 1082 | if (qp->sq.wqe_cnt) { |
| 1083 | int sq_strides_offset = (qp->sq.offset & (PAGE_SIZE - 1)) / |
| 1084 | MLX5_SEND_WQE_BB; |
| 1085 | mlx5_init_fbc_offset(qp->buf.frags + |
| 1086 | (qp->sq.offset / PAGE_SIZE), |
| 1087 | ilog2(MLX5_SEND_WQE_BB), |
| 1088 | ilog2(qp->sq.wqe_cnt), |
| 1089 | sq_strides_offset, &qp->sq.fbc); |
| 1090 | |
| 1091 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
| 1092 | } |
| 1093 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1094 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 1095 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * qp->buf.npages; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1096 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1097 | if (!*in) { |
| 1098 | err = -ENOMEM; |
| 1099 | goto err_buf; |
| 1100 | } |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1101 | |
| 1102 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 1103 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
| 1104 | MLX5_SET(qpc, qpc, log_page_size, qp->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1105 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1106 | /* Set "fast registration enabled" for all kernel QPs */ |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1107 | MLX5_SET(qpc, qpc, fre, 1); |
| 1108 | MLX5_SET(qpc, qpc, rlky, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1109 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1110 | if (qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1111 | MLX5_SET(qpc, qpc, deth_sqpn, 1); |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 1112 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1113 | mlx5_fill_page_frag_array(&qp->buf, |
| 1114 | (__be64 *)MLX5_ADDR_OF(create_qp_in, |
| 1115 | *in, pas)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1116 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1117 | err = mlx5_db_alloc(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1118 | if (err) { |
| 1119 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1120 | goto err_free; |
| 1121 | } |
| 1122 | |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1123 | qp->sq.wrid = kvmalloc_array(qp->sq.wqe_cnt, |
| 1124 | sizeof(*qp->sq.wrid), GFP_KERNEL); |
| 1125 | qp->sq.wr_data = kvmalloc_array(qp->sq.wqe_cnt, |
| 1126 | sizeof(*qp->sq.wr_data), GFP_KERNEL); |
| 1127 | qp->rq.wrid = kvmalloc_array(qp->rq.wqe_cnt, |
| 1128 | sizeof(*qp->rq.wrid), GFP_KERNEL); |
| 1129 | qp->sq.w_list = kvmalloc_array(qp->sq.wqe_cnt, |
| 1130 | sizeof(*qp->sq.w_list), GFP_KERNEL); |
| 1131 | qp->sq.wqe_head = kvmalloc_array(qp->sq.wqe_cnt, |
| 1132 | sizeof(*qp->sq.wqe_head), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1133 | |
| 1134 | if (!qp->sq.wrid || !qp->sq.wr_data || !qp->rq.wrid || |
| 1135 | !qp->sq.w_list || !qp->sq.wqe_head) { |
| 1136 | err = -ENOMEM; |
| 1137 | goto err_wrid; |
| 1138 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1139 | |
| 1140 | return 0; |
| 1141 | |
| 1142 | err_wrid: |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1143 | kvfree(qp->sq.wqe_head); |
| 1144 | kvfree(qp->sq.w_list); |
| 1145 | kvfree(qp->sq.wrid); |
| 1146 | kvfree(qp->sq.wr_data); |
| 1147 | kvfree(qp->rq.wrid); |
Eli Cohen | f4044da | 2017-01-03 23:55:20 +0200 | [diff] [blame] | 1148 | mlx5_db_free(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1149 | |
| 1150 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 1151 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1152 | |
| 1153 | err_buf: |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1154 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1155 | return err; |
| 1156 | } |
| 1157 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1158 | static u32 get_rx_type(struct mlx5_ib_qp *qp, struct ib_qp_init_attr *attr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1159 | { |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 1160 | if (attr->srq || (qp->type == IB_QPT_XRC_TGT) || |
| 1161 | (qp->type == MLX5_IB_QPT_DCI) || (qp->type == IB_QPT_XRC_INI)) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1162 | return MLX5_SRQ_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1163 | else if (!qp->has_rq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1164 | return MLX5_ZERO_LEN_RQ; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 1165 | |
| 1166 | return MLX5_NON_ZERO_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1167 | } |
| 1168 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1169 | static int create_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1170 | struct mlx5_ib_qp *qp, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1171 | struct mlx5_ib_sq *sq, u32 tdn, |
| 1172 | struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1173 | { |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1174 | u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {}; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1175 | void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx); |
| 1176 | |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1177 | MLX5_SET(create_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1178 | MLX5_SET(tisc, tisc, transport_domain, tdn); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1179 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1180 | MLX5_SET(tisc, tisc, underlay_qpn, qp->underlay_qpn); |
| 1181 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1182 | return mlx5_core_create_tis(dev->mdev, in, &sq->tisn); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | static void destroy_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1186 | struct mlx5_ib_sq *sq, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1187 | { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1188 | mlx5_cmd_destroy_tis(dev->mdev, sq->tisn, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1189 | } |
| 1190 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1191 | static void destroy_flow_rule_vport_sq(struct mlx5_ib_sq *sq) |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1192 | { |
| 1193 | if (sq->flow_rule) |
| 1194 | mlx5_del_flow_rules(sq->flow_rule); |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1195 | sq->flow_rule = NULL; |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1198 | static int create_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1199 | struct ib_udata *udata, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1200 | struct mlx5_ib_sq *sq, void *qpin, |
| 1201 | struct ib_pd *pd) |
| 1202 | { |
| 1203 | struct mlx5_ib_ubuffer *ubuffer = &sq->ubuffer; |
| 1204 | __be64 *pas; |
| 1205 | void *in; |
| 1206 | void *sqc; |
| 1207 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
| 1208 | void *wq; |
| 1209 | int inlen; |
| 1210 | int err; |
| 1211 | int page_shift = 0; |
| 1212 | int npages; |
| 1213 | int ncont = 0; |
| 1214 | u32 offset = 0; |
| 1215 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1216 | err = mlx5_ib_umem_get(dev, udata, ubuffer->buf_addr, ubuffer->buf_size, |
| 1217 | &sq->ubuffer.umem, &npages, &page_shift, &ncont, |
| 1218 | &offset); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1219 | if (err) |
| 1220 | return err; |
| 1221 | |
| 1222 | inlen = MLX5_ST_SZ_BYTES(create_sq_in) + sizeof(u64) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1223 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1224 | if (!in) { |
| 1225 | err = -ENOMEM; |
| 1226 | goto err_umem; |
| 1227 | } |
| 1228 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 1229 | MLX5_SET(create_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1230 | sqc = MLX5_ADDR_OF(create_sq_in, in, ctx); |
| 1231 | MLX5_SET(sqc, sqc, flush_in_error_en, 1); |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1232 | if (MLX5_CAP_ETH(dev->mdev, multi_pkt_send_wqe)) |
| 1233 | MLX5_SET(sqc, sqc, allow_multi_pkt_send_wqe, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1234 | MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST); |
| 1235 | MLX5_SET(sqc, sqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1236 | MLX5_SET(sqc, sqc, cqn, MLX5_GET(qpc, qpc, cqn_snd)); |
| 1237 | MLX5_SET(sqc, sqc, tis_lst_sz, 1); |
| 1238 | MLX5_SET(sqc, sqc, tis_num_0, sq->tisn); |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1239 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 1240 | MLX5_CAP_ETH(dev->mdev, swp)) |
| 1241 | MLX5_SET(sqc, sqc, allow_swp, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1242 | |
| 1243 | wq = MLX5_ADDR_OF(sqc, sqc, wq); |
| 1244 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
| 1245 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1246 | MLX5_SET(wq, wq, uar_page, MLX5_GET(qpc, qpc, uar_page)); |
| 1247 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1248 | MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB)); |
| 1249 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_sq_size)); |
| 1250 | MLX5_SET(wq, wq, log_wq_pg_sz, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1251 | MLX5_SET(wq, wq, page_offset, offset); |
| 1252 | |
| 1253 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1254 | mlx5_ib_populate_pas(dev, sq->ubuffer.umem, page_shift, pas, 0); |
| 1255 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1256 | err = mlx5_core_create_sq_tracked(dev, in, inlen, &sq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1257 | |
| 1258 | kvfree(in); |
| 1259 | |
| 1260 | if (err) |
| 1261 | goto err_umem; |
| 1262 | |
| 1263 | return 0; |
| 1264 | |
| 1265 | err_umem: |
| 1266 | ib_umem_release(sq->ubuffer.umem); |
| 1267 | sq->ubuffer.umem = NULL; |
| 1268 | |
| 1269 | return err; |
| 1270 | } |
| 1271 | |
| 1272 | static void destroy_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
| 1273 | struct mlx5_ib_sq *sq) |
| 1274 | { |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1275 | destroy_flow_rule_vport_sq(sq); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1276 | mlx5_core_destroy_sq_tracked(dev, &sq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1277 | ib_umem_release(sq->ubuffer.umem); |
| 1278 | } |
| 1279 | |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1280 | static size_t get_rq_pas_size(void *qpc) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1281 | { |
| 1282 | u32 log_page_size = MLX5_GET(qpc, qpc, log_page_size) + 12; |
| 1283 | u32 log_rq_stride = MLX5_GET(qpc, qpc, log_rq_stride); |
| 1284 | u32 log_rq_size = MLX5_GET(qpc, qpc, log_rq_size); |
| 1285 | u32 page_offset = MLX5_GET(qpc, qpc, page_offset); |
| 1286 | u32 po_quanta = 1 << (log_page_size - 6); |
| 1287 | u32 rq_sz = 1 << (log_rq_size + 4 + log_rq_stride); |
| 1288 | u32 page_size = 1 << log_page_size; |
| 1289 | u32 rq_sz_po = rq_sz + (page_offset * po_quanta); |
| 1290 | u32 rq_num_pas = (rq_sz_po + page_size - 1) / page_size; |
| 1291 | |
| 1292 | return rq_num_pas * sizeof(u64); |
| 1293 | } |
| 1294 | |
| 1295 | static int create_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1296 | struct mlx5_ib_rq *rq, void *qpin, |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1297 | size_t qpinlen, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1298 | { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1299 | struct mlx5_ib_qp *mqp = rq->base.container_mibqp; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1300 | __be64 *pas; |
| 1301 | __be64 *qp_pas; |
| 1302 | void *in; |
| 1303 | void *rqc; |
| 1304 | void *wq; |
| 1305 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1306 | size_t rq_pas_size = get_rq_pas_size(qpc); |
| 1307 | size_t inlen; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1308 | int err; |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1309 | |
| 1310 | if (qpinlen < rq_pas_size + MLX5_BYTE_OFF(create_qp_in, pas)) |
| 1311 | return -EINVAL; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1312 | |
| 1313 | inlen = MLX5_ST_SZ_BYTES(create_rq_in) + rq_pas_size; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1314 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1315 | if (!in) |
| 1316 | return -ENOMEM; |
| 1317 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1318 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1319 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1320 | if (!(rq->flags & MLX5_IB_RQ_CVLAN_STRIPPING)) |
| 1321 | MLX5_SET(rqc, rqc, vsd, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1322 | MLX5_SET(rqc, rqc, mem_rq_type, MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 1323 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 1324 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 1325 | MLX5_SET(rqc, rqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1326 | MLX5_SET(rqc, rqc, cqn, MLX5_GET(qpc, qpc, cqn_rcv)); |
| 1327 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1328 | if (mqp->flags & IB_QP_CREATE_SCATTER_FCS) |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1329 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 1330 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1331 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
| 1332 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1333 | if (rq->flags & MLX5_IB_RQ_PCI_WRITE_END_PADDING) |
| 1334 | MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1335 | MLX5_SET(wq, wq, page_offset, MLX5_GET(qpc, qpc, page_offset)); |
| 1336 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1337 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1338 | MLX5_SET(wq, wq, log_wq_stride, MLX5_GET(qpc, qpc, log_rq_stride) + 4); |
| 1339 | MLX5_SET(wq, wq, log_wq_pg_sz, MLX5_GET(qpc, qpc, log_page_size)); |
| 1340 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_rq_size)); |
| 1341 | |
| 1342 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1343 | qp_pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, qpin, pas); |
| 1344 | memcpy(pas, qp_pas, rq_pas_size); |
| 1345 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1346 | err = mlx5_core_create_rq_tracked(dev, in, inlen, &rq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1347 | |
| 1348 | kvfree(in); |
| 1349 | |
| 1350 | return err; |
| 1351 | } |
| 1352 | |
| 1353 | static void destroy_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
| 1354 | struct mlx5_ib_rq *rq) |
| 1355 | { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1356 | mlx5_core_destroy_rq_tracked(dev, &rq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1357 | } |
| 1358 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1359 | static void destroy_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
| 1360 | struct mlx5_ib_rq *rq, |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1361 | u32 qp_flags_en, |
| 1362 | struct ib_pd *pd) |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1363 | { |
| 1364 | if (qp_flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1365 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1366 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1367 | mlx5_cmd_destroy_tir(dev->mdev, rq->tirn, to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1368 | } |
| 1369 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1370 | static int create_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1371 | struct mlx5_ib_rq *rq, u32 tdn, |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1372 | u32 *qp_flags_en, struct ib_pd *pd, |
| 1373 | u32 *out) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1374 | { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1375 | u8 lb_flag = 0; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1376 | u32 *in; |
| 1377 | void *tirc; |
| 1378 | int inlen; |
| 1379 | int err; |
| 1380 | |
| 1381 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1382 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1383 | if (!in) |
| 1384 | return -ENOMEM; |
| 1385 | |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1386 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1387 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1388 | MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_DIRECT); |
| 1389 | MLX5_SET(tirc, tirc, inline_rqn, rq->base.mqp.qpn); |
| 1390 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1391 | if (*qp_flags_en & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1392 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1393 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1394 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) |
| 1395 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1396 | |
| 1397 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) |
| 1398 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
| 1399 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 1400 | if (dev->is_rep) { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1401 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1402 | *qp_flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 1403 | } |
| 1404 | |
| 1405 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1406 | MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR); |
| 1407 | err = mlx5_cmd_exec_inout(dev->mdev, create_tir, in, out); |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1408 | rq->tirn = MLX5_GET(create_tir_out, out, tirn); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1409 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1410 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1411 | |
| 1412 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1413 | destroy_raw_packet_qp_tir(dev, rq, 0, pd); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1414 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1415 | kvfree(in); |
| 1416 | |
| 1417 | return err; |
| 1418 | } |
| 1419 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1420 | static int create_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1421 | u32 *in, size_t inlen, |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1422 | struct ib_pd *pd, |
| 1423 | struct ib_udata *udata, |
| 1424 | struct mlx5_ib_create_qp_resp *resp) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1425 | { |
| 1426 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1427 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1428 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1429 | struct mlx5_ib_ucontext *mucontext = rdma_udata_to_drv_context( |
| 1430 | udata, struct mlx5_ib_ucontext, ibucontext); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1431 | int err; |
| 1432 | u32 tdn = mucontext->tdn; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1433 | u16 uid = to_mpd(pd)->uid; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1434 | u32 out[MLX5_ST_SZ_DW(create_tir_out)] = {}; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1435 | |
Aharon Landau | 0eacc57 | 2020-04-27 18:46:36 +0300 | [diff] [blame] | 1436 | if (!qp->sq.wqe_cnt && !qp->rq.wqe_cnt) |
| 1437 | return -EINVAL; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1438 | if (qp->sq.wqe_cnt) { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1439 | err = create_raw_packet_qp_tis(dev, qp, sq, tdn, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1440 | if (err) |
| 1441 | return err; |
| 1442 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1443 | err = create_raw_packet_qp_sq(dev, udata, sq, in, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1444 | if (err) |
| 1445 | goto err_destroy_tis; |
| 1446 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1447 | if (uid) { |
| 1448 | resp->tisn = sq->tisn; |
| 1449 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TISN; |
| 1450 | resp->sqn = sq->base.mqp.qpn; |
| 1451 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_SQN; |
| 1452 | } |
| 1453 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1454 | sq->base.container_mibqp = qp; |
Majd Dibbiny | 1d31e9c | 2017-08-23 08:35:41 +0300 | [diff] [blame] | 1455 | sq->base.mqp.event = mlx5_ib_qp_event; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | if (qp->rq.wqe_cnt) { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1459 | rq->base.container_mibqp = qp; |
| 1460 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1461 | if (qp->flags & IB_QP_CREATE_CVLAN_STRIPPING) |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1462 | rq->flags |= MLX5_IB_RQ_CVLAN_STRIPPING; |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1463 | if (qp->flags & IB_QP_CREATE_PCI_WRITE_END_PADDING) |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1464 | rq->flags |= MLX5_IB_RQ_PCI_WRITE_END_PADDING; |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1465 | err = create_raw_packet_qp_rq(dev, rq, in, inlen, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1466 | if (err) |
| 1467 | goto err_destroy_sq; |
| 1468 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1469 | err = create_raw_packet_qp_tir(dev, rq, tdn, &qp->flags_en, pd, |
| 1470 | out); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1471 | if (err) |
| 1472 | goto err_destroy_rq; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1473 | |
| 1474 | if (uid) { |
| 1475 | resp->rqn = rq->base.mqp.qpn; |
| 1476 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_RQN; |
| 1477 | resp->tirn = rq->tirn; |
| 1478 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1479 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner)) { |
| 1480 | resp->tir_icm_addr = MLX5_GET( |
| 1481 | create_tir_out, out, icm_address_31_0); |
| 1482 | resp->tir_icm_addr |= |
| 1483 | (u64)MLX5_GET(create_tir_out, out, |
| 1484 | icm_address_39_32) |
| 1485 | << 32; |
| 1486 | resp->tir_icm_addr |= |
| 1487 | (u64)MLX5_GET(create_tir_out, out, |
| 1488 | icm_address_63_40) |
| 1489 | << 40; |
| 1490 | resp->comp_mask |= |
| 1491 | MLX5_IB_CREATE_QP_RESP_MASK_TIR_ICM_ADDR; |
| 1492 | } |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1493 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | qp->trans_qp.base.mqp.qpn = qp->sq.wqe_cnt ? sq->base.mqp.qpn : |
| 1497 | rq->base.mqp.qpn; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1498 | return 0; |
| 1499 | |
| 1500 | err_destroy_rq: |
| 1501 | destroy_raw_packet_qp_rq(dev, rq); |
| 1502 | err_destroy_sq: |
| 1503 | if (!qp->sq.wqe_cnt) |
| 1504 | return err; |
| 1505 | destroy_raw_packet_qp_sq(dev, sq); |
| 1506 | err_destroy_tis: |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1507 | destroy_raw_packet_qp_tis(dev, sq, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1508 | |
| 1509 | return err; |
| 1510 | } |
| 1511 | |
| 1512 | static void destroy_raw_packet_qp(struct mlx5_ib_dev *dev, |
| 1513 | struct mlx5_ib_qp *qp) |
| 1514 | { |
| 1515 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1516 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1517 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1518 | |
| 1519 | if (qp->rq.wqe_cnt) { |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1520 | destroy_raw_packet_qp_tir(dev, rq, qp->flags_en, qp->ibqp.pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1521 | destroy_raw_packet_qp_rq(dev, rq); |
| 1522 | } |
| 1523 | |
| 1524 | if (qp->sq.wqe_cnt) { |
| 1525 | destroy_raw_packet_qp_sq(dev, sq); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1526 | destroy_raw_packet_qp_tis(dev, sq, qp->ibqp.pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | static void raw_packet_qp_copy_info(struct mlx5_ib_qp *qp, |
| 1531 | struct mlx5_ib_raw_packet_qp *raw_packet_qp) |
| 1532 | { |
| 1533 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1534 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1535 | |
| 1536 | sq->sq = &qp->sq; |
| 1537 | rq->rq = &qp->rq; |
| 1538 | sq->doorbell = &qp->db; |
| 1539 | rq->doorbell = &qp->db; |
| 1540 | } |
| 1541 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1542 | static void destroy_rss_raw_qp_tir(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 1543 | { |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1544 | if (qp->flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1545 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1546 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1547 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1548 | to_mpd(qp->ibqp.pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1549 | } |
| 1550 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1551 | struct mlx5_create_qp_params { |
| 1552 | struct ib_udata *udata; |
| 1553 | size_t inlen; |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 1554 | size_t outlen; |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 1555 | size_t ucmd_size; |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1556 | void *ucmd; |
| 1557 | u8 is_rss_raw : 1; |
| 1558 | struct ib_qp_init_attr *attr; |
| 1559 | u32 uidx; |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 1560 | struct mlx5_ib_create_qp_resp resp; |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1561 | }; |
| 1562 | |
| 1563 | static int create_rss_raw_qp_tir(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 1564 | struct mlx5_ib_qp *qp, |
| 1565 | struct mlx5_create_qp_params *params) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1566 | { |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1567 | struct ib_qp_init_attr *init_attr = params->attr; |
| 1568 | struct mlx5_ib_create_qp_rss *ucmd = params->ucmd; |
| 1569 | struct ib_udata *udata = params->udata; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1570 | struct mlx5_ib_ucontext *mucontext = rdma_udata_to_drv_context( |
| 1571 | udata, struct mlx5_ib_ucontext, ibucontext); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1572 | int inlen; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1573 | int outlen; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1574 | int err; |
| 1575 | u32 *in; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1576 | u32 *out; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1577 | void *tirc; |
| 1578 | void *hfso; |
| 1579 | u32 selected_fields = 0; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1580 | u32 outer_l4; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1581 | u32 tdn = mucontext->tdn; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1582 | u8 lb_flag = 0; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1583 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1584 | if (ucmd->comp_mask) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1585 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 1586 | return -EOPNOTSUPP; |
| 1587 | } |
| 1588 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1589 | if (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_INNER && |
| 1590 | !(ucmd->flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS)) { |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1591 | mlx5_ib_dbg(dev, "Tunnel offloads must be set for inner RSS\n"); |
| 1592 | return -EOPNOTSUPP; |
| 1593 | } |
| 1594 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 1595 | if (dev->is_rep) |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1596 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1597 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 1598 | if (qp->flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) |
| 1599 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1600 | |
| 1601 | if (qp->flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1602 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1603 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1604 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1605 | outlen = MLX5_ST_SZ_BYTES(create_tir_out); |
| 1606 | in = kvzalloc(inlen + outlen, GFP_KERNEL); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1607 | if (!in) |
| 1608 | return -ENOMEM; |
| 1609 | |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1610 | out = in + MLX5_ST_SZ_DW(create_tir_in); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1611 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1612 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1613 | MLX5_SET(tirc, tirc, disp_type, |
| 1614 | MLX5_TIRC_DISP_TYPE_INDIRECT); |
| 1615 | MLX5_SET(tirc, tirc, indirect_table, |
| 1616 | init_attr->rwq_ind_tbl->ind_tbl_num); |
| 1617 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
| 1618 | |
| 1619 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1620 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1621 | if (ucmd->flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1622 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
| 1623 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1624 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
| 1625 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1626 | if (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_INNER) |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1627 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_inner); |
| 1628 | else |
| 1629 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
| 1630 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1631 | switch (ucmd->rx_hash_function) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1632 | case MLX5_RX_HASH_FUNC_TOEPLITZ: |
| 1633 | { |
| 1634 | void *rss_key = MLX5_ADDR_OF(tirc, tirc, rx_hash_toeplitz_key); |
| 1635 | size_t len = MLX5_FLD_SZ_BYTES(tirc, rx_hash_toeplitz_key); |
| 1636 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1637 | if (len != ucmd->rx_key_len) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1638 | err = -EINVAL; |
| 1639 | goto err; |
| 1640 | } |
| 1641 | |
| 1642 | MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_TOEPLITZ); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1643 | memcpy(rss_key, ucmd->rx_hash_key, len); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1644 | break; |
| 1645 | } |
| 1646 | default: |
| 1647 | err = -EOPNOTSUPP; |
| 1648 | goto err; |
| 1649 | } |
| 1650 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1651 | if (!ucmd->rx_hash_fields_mask) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1652 | /* special case when this TIR serves as steering entry without hashing */ |
| 1653 | if (!init_attr->rwq_ind_tbl->log_ind_tbl_size) |
| 1654 | goto create_tir; |
| 1655 | err = -EINVAL; |
| 1656 | goto err; |
| 1657 | } |
| 1658 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1659 | if (((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1660 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) && |
| 1661 | ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1662 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6))) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1663 | err = -EINVAL; |
| 1664 | goto err; |
| 1665 | } |
| 1666 | |
| 1667 | /* If none of IPV4 & IPV6 SRC/DST was set - this bit field is ignored */ |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1668 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1669 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1670 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1671 | MLX5_L3_PROT_TYPE_IPV4); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1672 | else if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1673 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1674 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1675 | MLX5_L3_PROT_TYPE_IPV6); |
| 1676 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1677 | outer_l4 = ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1678 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) |
| 1679 | << 0 | |
| 1680 | ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1681 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
| 1682 | << 1 | |
| 1683 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) << 2; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1684 | |
| 1685 | /* Check that only one l4 protocol is set */ |
| 1686 | if (outer_l4 & (outer_l4 - 1)) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1687 | err = -EINVAL; |
| 1688 | goto err; |
| 1689 | } |
| 1690 | |
| 1691 | /* If none of TCP & UDP SRC/DST was set - this bit field is ignored */ |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1692 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1693 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1694 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1695 | MLX5_L4_PROT_TYPE_TCP); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1696 | else if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1697 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1698 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1699 | MLX5_L4_PROT_TYPE_UDP); |
| 1700 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1701 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1702 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1703 | selected_fields |= MLX5_HASH_FIELD_SEL_SRC_IP; |
| 1704 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1705 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4) || |
| 1706 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1707 | selected_fields |= MLX5_HASH_FIELD_SEL_DST_IP; |
| 1708 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1709 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1710 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1711 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_SPORT; |
| 1712 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1713 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP) || |
| 1714 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1715 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_DPORT; |
| 1716 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 1717 | if (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1718 | selected_fields |= MLX5_HASH_FIELD_SEL_IPSEC_SPI; |
| 1719 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1720 | MLX5_SET(rx_hash_field_select, hfso, selected_fields, selected_fields); |
| 1721 | |
| 1722 | create_tir: |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1723 | MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR); |
| 1724 | err = mlx5_cmd_exec_inout(dev->mdev, create_tir, in, out); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1725 | |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1726 | qp->rss_qp.tirn = MLX5_GET(create_tir_out, out, tirn); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1727 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1728 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1729 | |
| 1730 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1731 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1732 | to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1733 | } |
| 1734 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1735 | if (err) |
| 1736 | goto err; |
| 1737 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1738 | if (mucontext->devx_uid) { |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 1739 | params->resp.comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
| 1740 | params->resp.tirn = qp->rss_qp.tirn; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1741 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner)) { |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 1742 | params->resp.tir_icm_addr = |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1743 | MLX5_GET(create_tir_out, out, icm_address_31_0); |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 1744 | params->resp.tir_icm_addr |= |
| 1745 | (u64)MLX5_GET(create_tir_out, out, |
| 1746 | icm_address_39_32) |
| 1747 | << 32; |
| 1748 | params->resp.tir_icm_addr |= |
| 1749 | (u64)MLX5_GET(create_tir_out, out, |
| 1750 | icm_address_63_40) |
| 1751 | << 40; |
| 1752 | params->resp.comp_mask |= |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1753 | MLX5_IB_CREATE_QP_RESP_MASK_TIR_ICM_ADDR; |
| 1754 | } |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1755 | } |
| 1756 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1757 | kvfree(in); |
| 1758 | /* qpn is reserved for that QP */ |
| 1759 | qp->trans_qp.base.mqp.qpn = 0; |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1760 | qp->is_rss = true; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1761 | return 0; |
| 1762 | |
| 1763 | err: |
| 1764 | kvfree(in); |
| 1765 | return err; |
| 1766 | } |
| 1767 | |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1768 | static void configure_requester_scat_cqe(struct mlx5_ib_dev *dev, |
| 1769 | struct ib_qp_init_attr *init_attr, |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1770 | struct mlx5_ib_create_qp *ucmd, |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1771 | void *qpc) |
| 1772 | { |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1773 | int scqe_sz; |
zhengbin | 2ab367a | 2019-12-24 16:40:12 +0800 | [diff] [blame] | 1774 | bool allow_scat_cqe = false; |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1775 | |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1776 | if (ucmd) |
| 1777 | allow_scat_cqe = ucmd->flags & MLX5_QP_FLAG_ALLOW_SCATTER_CQE; |
| 1778 | |
| 1779 | if (!allow_scat_cqe && init_attr->sq_sig_type != IB_SIGNAL_ALL_WR) |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1780 | return; |
| 1781 | |
| 1782 | scqe_sz = mlx5_ib_get_cqe_size(init_attr->send_cq); |
| 1783 | if (scqe_sz == 128) { |
| 1784 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA64_CQE); |
| 1785 | return; |
| 1786 | } |
| 1787 | |
| 1788 | if (init_attr->qp_type != MLX5_IB_QPT_DCI || |
| 1789 | MLX5_CAP_GEN(dev->mdev, dc_req_scat_data_cqe)) |
| 1790 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA32_CQE); |
| 1791 | } |
| 1792 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 1793 | static int atomic_size_to_mode(int size_mask) |
| 1794 | { |
| 1795 | /* driver does not support atomic_size > 256B |
| 1796 | * and does not know how to translate bigger sizes |
| 1797 | */ |
| 1798 | int supported_size_mask = size_mask & 0x1ff; |
| 1799 | int log_max_size; |
| 1800 | |
| 1801 | if (!supported_size_mask) |
| 1802 | return -EOPNOTSUPP; |
| 1803 | |
| 1804 | log_max_size = __fls(supported_size_mask); |
| 1805 | |
| 1806 | if (log_max_size > 3) |
| 1807 | return log_max_size; |
| 1808 | |
| 1809 | return MLX5_ATOMIC_MODE_8B; |
| 1810 | } |
| 1811 | |
| 1812 | static int get_atomic_mode(struct mlx5_ib_dev *dev, |
| 1813 | enum ib_qp_type qp_type) |
| 1814 | { |
| 1815 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
| 1816 | u8 atomic = MLX5_CAP_GEN(dev->mdev, atomic); |
| 1817 | int atomic_mode = -EOPNOTSUPP; |
| 1818 | int atomic_size_mask; |
| 1819 | |
| 1820 | if (!atomic) |
| 1821 | return -EOPNOTSUPP; |
| 1822 | |
| 1823 | if (qp_type == MLX5_IB_QPT_DCT) |
| 1824 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 1825 | else |
| 1826 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 1827 | |
| 1828 | if ((atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP) || |
| 1829 | (atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD)) |
| 1830 | atomic_mode = atomic_size_to_mode(atomic_size_mask); |
| 1831 | |
| 1832 | if (atomic_mode <= 0 && |
| 1833 | (atomic_operations & MLX5_ATOMIC_OPS_CMP_SWAP && |
| 1834 | atomic_operations & MLX5_ATOMIC_OPS_FETCH_ADD)) |
| 1835 | atomic_mode = MLX5_ATOMIC_MODE_IB_COMP; |
| 1836 | |
| 1837 | return atomic_mode; |
| 1838 | } |
| 1839 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1840 | static int create_xrc_tgt_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 1841 | struct mlx5_create_qp_params *params) |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1842 | { |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 1843 | struct mlx5_ib_create_qp *ucmd = params->ucmd; |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1844 | struct ib_qp_init_attr *attr = params->attr; |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1845 | u32 uidx = params->uidx; |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1846 | struct mlx5_ib_resources *devr = &dev->devr; |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 1847 | u32 out[MLX5_ST_SZ_DW(create_qp_out)] = {}; |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1848 | int inlen = MLX5_ST_SZ_BYTES(create_qp_in); |
| 1849 | struct mlx5_core_dev *mdev = dev->mdev; |
| 1850 | struct mlx5_ib_qp_base *base; |
| 1851 | unsigned long flags; |
| 1852 | void *qpc; |
| 1853 | u32 *in; |
| 1854 | int err; |
| 1855 | |
| 1856 | mutex_init(&qp->mutex); |
| 1857 | |
| 1858 | if (attr->sq_sig_type == IB_SIGNAL_ALL_WR) |
| 1859 | qp->sq_signal_bits = MLX5_WQE_CTRL_CQ_UPDATE; |
| 1860 | |
| 1861 | in = kvzalloc(inlen, GFP_KERNEL); |
| 1862 | if (!in) |
| 1863 | return -ENOMEM; |
| 1864 | |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 1865 | if (MLX5_CAP_GEN(mdev, ece_support)) |
| 1866 | MLX5_SET(create_qp_in, in, ece, ucmd->ece_options); |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1867 | qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); |
| 1868 | |
| 1869 | MLX5_SET(qpc, qpc, st, MLX5_QP_ST_XRC); |
| 1870 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
| 1871 | MLX5_SET(qpc, qpc, pd, to_mpd(devr->p0)->pdn); |
| 1872 | |
| 1873 | if (qp->flags & IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) |
| 1874 | MLX5_SET(qpc, qpc, block_lb_mc, 1); |
| 1875 | if (qp->flags & IB_QP_CREATE_CROSS_CHANNEL) |
| 1876 | MLX5_SET(qpc, qpc, cd_master, 1); |
| 1877 | if (qp->flags & IB_QP_CREATE_MANAGED_SEND) |
| 1878 | MLX5_SET(qpc, qpc, cd_slave_send, 1); |
| 1879 | if (qp->flags & IB_QP_CREATE_MANAGED_RECV) |
| 1880 | MLX5_SET(qpc, qpc, cd_slave_receive, 1); |
| 1881 | |
| 1882 | MLX5_SET(qpc, qpc, rq_type, MLX5_SRQ_RQ); |
| 1883 | MLX5_SET(qpc, qpc, no_sq, 1); |
| 1884 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
| 1885 | MLX5_SET(qpc, qpc, cqn_snd, to_mcq(devr->c0)->mcq.cqn); |
| 1886 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, to_msrq(devr->s0)->msrq.srqn); |
| 1887 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(attr->xrcd)->xrcdn); |
| 1888 | MLX5_SET64(qpc, qpc, dbr_addr, qp->db.dma); |
| 1889 | |
| 1890 | /* 0xffffff means we ask to work with cqe version 0 */ |
| 1891 | if (MLX5_CAP_GEN(mdev, cqe_version) == MLX5_CQE_VERSION_V1) |
| 1892 | MLX5_SET(qpc, qpc, user_index, uidx); |
| 1893 | |
| 1894 | if (qp->flags & IB_QP_CREATE_PCI_WRITE_END_PADDING) { |
| 1895 | MLX5_SET(qpc, qpc, end_padding_mode, |
| 1896 | MLX5_WQ_END_PAD_MODE_ALIGN); |
| 1897 | /* Special case to clean flag */ |
| 1898 | qp->flags &= ~IB_QP_CREATE_PCI_WRITE_END_PADDING; |
| 1899 | } |
| 1900 | |
| 1901 | base = &qp->trans_qp.base; |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 1902 | err = mlx5_qpc_create_qp(dev, &base->mqp, in, inlen, out); |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1903 | kvfree(in); |
Leon Romanovsky | 6367da4 | 2020-04-27 18:46:34 +0300 | [diff] [blame] | 1904 | if (err) |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1905 | return err; |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1906 | |
| 1907 | base->container_mibqp = qp; |
| 1908 | base->mqp.event = mlx5_ib_qp_event; |
Leon Romanovsky | 92cd667 | 2020-06-02 15:55:47 +0300 | [diff] [blame] | 1909 | if (MLX5_CAP_GEN(mdev, ece_support)) |
| 1910 | params->resp.ece_options = MLX5_GET(create_qp_out, out, ece); |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1911 | |
| 1912 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 1913 | list_add_tail(&qp->qps_list, &dev->qp_list); |
| 1914 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 1915 | |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 1916 | qp->trans_qp.xrcdn = to_mxrcd(attr->xrcd)->xrcdn; |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1917 | return 0; |
| 1918 | } |
| 1919 | |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 1920 | static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1921 | struct mlx5_ib_qp *qp, |
| 1922 | struct mlx5_create_qp_params *params) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1923 | { |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1924 | struct ib_qp_init_attr *init_attr = params->attr; |
| 1925 | struct mlx5_ib_create_qp *ucmd = params->ucmd; |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 1926 | u32 out[MLX5_ST_SZ_DW(create_qp_out)] = {}; |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 1927 | struct ib_udata *udata = params->udata; |
| 1928 | u32 uidx = params->uidx; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1929 | struct mlx5_ib_resources *devr = &dev->devr; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1930 | int inlen = MLX5_ST_SZ_BYTES(create_qp_in); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1931 | struct mlx5_core_dev *mdev = dev->mdev; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 1932 | struct mlx5_ib_cq *send_cq; |
| 1933 | struct mlx5_ib_cq *recv_cq; |
| 1934 | unsigned long flags; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1935 | struct mlx5_ib_qp_base *base; |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1936 | int mlx5_st; |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1937 | void *qpc; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1938 | u32 *in; |
| 1939 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1940 | |
| 1941 | mutex_init(&qp->mutex); |
| 1942 | spin_lock_init(&qp->sq.lock); |
| 1943 | spin_lock_init(&qp->rq.lock); |
| 1944 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 1945 | mlx5_st = to_mlx5_st(qp->type); |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1946 | if (mlx5_st < 0) |
| 1947 | return -EINVAL; |
| 1948 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1949 | if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) |
| 1950 | qp->sq_signal_bits = MLX5_WQE_CTRL_CQ_UPDATE; |
| 1951 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1952 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
| 1953 | qp->underlay_qpn = init_attr->source_qpn; |
| 1954 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1955 | base = (init_attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1956 | qp->flags & IB_QP_CREATE_SOURCE_QPN) ? |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1957 | &qp->raw_packet_qp.rq.base : |
| 1958 | &qp->trans_qp.base; |
| 1959 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1960 | qp->has_rq = qp_has_rq(init_attr); |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 1961 | err = set_rq_size(dev, &init_attr->cap, qp->has_rq, qp, ucmd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1962 | if (err) { |
| 1963 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1964 | return err; |
| 1965 | } |
| 1966 | |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 1967 | if (ucmd->rq_wqe_shift != qp->rq.wqe_shift || |
| 1968 | ucmd->rq_wqe_count != qp->rq.wqe_cnt) |
| 1969 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1970 | |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 1971 | if (ucmd->sq_wqe_count > (1 << MLX5_CAP_GEN(mdev, log_max_qp_sz))) |
| 1972 | return -EINVAL; |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1973 | |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 1974 | err = _create_user_qp(dev, pd, qp, udata, init_attr, &in, ¶ms->resp, |
| 1975 | &inlen, base, ucmd); |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 1976 | if (err) |
| 1977 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1978 | |
| 1979 | if (is_sqp(init_attr->qp_type)) |
| 1980 | qp->port = init_attr->port_num; |
| 1981 | |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 1982 | if (MLX5_CAP_GEN(mdev, ece_support)) |
| 1983 | MLX5_SET(create_qp_in, in, ece, ucmd->ece_options); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1984 | qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); |
| 1985 | |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1986 | MLX5_SET(qpc, qpc, st, mlx5_st); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1987 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 1988 | MLX5_SET(qpc, qpc, pd, to_mpd(pd)->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1989 | |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 1990 | if (qp->flags_en & MLX5_QP_FLAG_SIGNATURE) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1991 | MLX5_SET(qpc, qpc, wq_signature, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1992 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1993 | if (qp->flags & IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1994 | MLX5_SET(qpc, qpc, block_lb_mc, 1); |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 1995 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1996 | if (qp->flags & IB_QP_CREATE_CROSS_CHANNEL) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1997 | MLX5_SET(qpc, qpc, cd_master, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1998 | if (qp->flags & IB_QP_CREATE_MANAGED_SEND) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1999 | MLX5_SET(qpc, qpc, cd_slave_send, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2000 | if (qp->flags & IB_QP_CREATE_MANAGED_RECV) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2001 | MLX5_SET(qpc, qpc, cd_slave_receive, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2002 | if (qp->flags_en & MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE) |
Danit Goldberg | 569c665 | 2018-11-30 13:22:05 +0200 | [diff] [blame] | 2003 | MLX5_SET(qpc, qpc, req_e2e_credit_mode, 1); |
Leon Romanovsky | 90ecb37 | 2020-04-27 18:46:16 +0300 | [diff] [blame] | 2004 | if ((qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) && |
| 2005 | (init_attr->qp_type == IB_QPT_RC || |
| 2006 | init_attr->qp_type == IB_QPT_UC)) { |
Colin Ian King | 52c81f4 | 2020-05-07 16:16:10 +0100 | [diff] [blame] | 2007 | int rcqe_sz = mlx5_ib_get_cqe_size(init_attr->recv_cq); |
Leon Romanovsky | 8bde2c5 | 2020-04-27 18:46:09 +0300 | [diff] [blame] | 2008 | |
| 2009 | MLX5_SET(qpc, qpc, cs_res, |
| 2010 | rcqe_sz == 128 ? MLX5_RES_SCAT_DATA64_CQE : |
| 2011 | MLX5_RES_SCAT_DATA32_CQE); |
| 2012 | } |
Leon Romanovsky | 90ecb37 | 2020-04-27 18:46:16 +0300 | [diff] [blame] | 2013 | if ((qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) && |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2014 | (qp->type == MLX5_IB_QPT_DCI || qp->type == IB_QPT_RC)) |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2015 | configure_requester_scat_cqe(dev, init_attr, ucmd, qpc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2016 | |
| 2017 | if (qp->rq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2018 | MLX5_SET(qpc, qpc, log_rq_stride, qp->rq.wqe_shift - 4); |
| 2019 | MLX5_SET(qpc, qpc, log_rq_size, ilog2(qp->rq.wqe_cnt)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2020 | } |
| 2021 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2022 | MLX5_SET(qpc, qpc, rq_type, get_rx_type(qp, init_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2023 | |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2024 | if (qp->sq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2025 | MLX5_SET(qpc, qpc, log_sq_size, ilog2(qp->sq.wqe_cnt)); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2026 | } else { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2027 | MLX5_SET(qpc, qpc, no_sq, 1); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2028 | if (init_attr->srq && |
| 2029 | init_attr->srq->srq_type == IB_SRQT_TM) |
| 2030 | MLX5_SET(qpc, qpc, offload_type, |
| 2031 | MLX5_QPC_OFFLOAD_TYPE_RNDV); |
| 2032 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2033 | |
| 2034 | /* Set default resources */ |
| 2035 | switch (init_attr->qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2036 | case IB_QPT_XRC_INI: |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2037 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
Leon Romanovsky | f437544 | 2020-07-06 15:27:14 +0300 | [diff] [blame] | 2038 | MLX5_SET(qpc, qpc, xrcd, devr->xrcdn1); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2039 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, to_msrq(devr->s0)->msrq.srqn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2040 | break; |
| 2041 | default: |
| 2042 | if (init_attr->srq) { |
Leon Romanovsky | f437544 | 2020-07-06 15:27:14 +0300 | [diff] [blame] | 2043 | MLX5_SET(qpc, qpc, xrcd, devr->xrcdn0); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2044 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, to_msrq(init_attr->srq)->msrq.srqn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2045 | } else { |
Leon Romanovsky | f437544 | 2020-07-06 15:27:14 +0300 | [diff] [blame] | 2046 | MLX5_SET(qpc, qpc, xrcd, devr->xrcdn1); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2047 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, to_msrq(devr->s1)->msrq.srqn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | if (init_attr->send_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2052 | MLX5_SET(qpc, qpc, cqn_snd, to_mcq(init_attr->send_cq)->mcq.cqn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2053 | |
| 2054 | if (init_attr->recv_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2055 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(init_attr->recv_cq)->mcq.cqn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2056 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2057 | MLX5_SET64(qpc, qpc, dbr_addr, qp->db.dma); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2058 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2059 | /* 0xffffff means we ask to work with cqe version 0 */ |
| 2060 | if (MLX5_CAP_GEN(mdev, cqe_version) == MLX5_CQE_VERSION_V1) |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2061 | MLX5_SET(qpc, qpc, user_index, uidx); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2062 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2063 | if (qp->flags & IB_QP_CREATE_PCI_WRITE_END_PADDING && |
| 2064 | init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 2065 | MLX5_SET(qpc, qpc, end_padding_mode, |
| 2066 | MLX5_WQ_END_PAD_MODE_ALIGN); |
| 2067 | /* Special case to clean flag */ |
| 2068 | qp->flags &= ~IB_QP_CREATE_PCI_WRITE_END_PADDING; |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 2069 | } |
| 2070 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2071 | if (init_attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2072 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2073 | qp->raw_packet_qp.sq.ubuffer.buf_addr = ucmd->sq_buf_addr; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2074 | raw_packet_qp_copy_info(qp, &qp->raw_packet_qp); |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 2075 | err = create_raw_packet_qp(dev, qp, in, inlen, pd, udata, |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 2076 | ¶ms->resp); |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 2077 | } else |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 2078 | err = mlx5_qpc_create_qp(dev, &base->mqp, in, inlen, out); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2079 | |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 2080 | kvfree(in); |
Leon Romanovsky | 04bcc1c | 2020-04-27 18:46:27 +0300 | [diff] [blame] | 2081 | if (err) |
| 2082 | goto err_create; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2083 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2084 | base->container_mibqp = qp; |
| 2085 | base->mqp.event = mlx5_ib_qp_event; |
Leon Romanovsky | 92cd667 | 2020-06-02 15:55:47 +0300 | [diff] [blame] | 2086 | if (MLX5_CAP_GEN(mdev, ece_support)) |
| 2087 | params->resp.ece_options = MLX5_GET(create_qp_out, out, ece); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2088 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2089 | get_cqs(qp->type, init_attr->send_cq, init_attr->recv_cq, |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2090 | &send_cq, &recv_cq); |
| 2091 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2092 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2093 | /* Maintain device to QPs access, needed for further handling via reset |
| 2094 | * flow |
| 2095 | */ |
| 2096 | list_add_tail(&qp->qps_list, &dev->qp_list); |
| 2097 | /* Maintain CQ to QPs access, needed for further handling via reset flow |
| 2098 | */ |
| 2099 | if (send_cq) |
| 2100 | list_add_tail(&qp->cq_send_list, &send_cq->list_send_qp); |
| 2101 | if (recv_cq) |
| 2102 | list_add_tail(&qp->cq_recv_list, &recv_cq->list_recv_qp); |
| 2103 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2104 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 2105 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2106 | return 0; |
| 2107 | |
| 2108 | err_create: |
Leon Romanovsky | 747c519 | 2020-04-27 18:46:29 +0300 | [diff] [blame] | 2109 | destroy_qp(dev, qp, base, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2110 | return err; |
| 2111 | } |
| 2112 | |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2113 | static int create_kernel_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2114 | struct mlx5_ib_qp *qp, |
| 2115 | struct mlx5_create_qp_params *params) |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2116 | { |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2117 | struct ib_qp_init_attr *attr = params->attr; |
| 2118 | u32 uidx = params->uidx; |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2119 | struct mlx5_ib_resources *devr = &dev->devr; |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 2120 | u32 out[MLX5_ST_SZ_DW(create_qp_out)] = {}; |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2121 | int inlen = MLX5_ST_SZ_BYTES(create_qp_in); |
| 2122 | struct mlx5_core_dev *mdev = dev->mdev; |
| 2123 | struct mlx5_ib_cq *send_cq; |
| 2124 | struct mlx5_ib_cq *recv_cq; |
| 2125 | unsigned long flags; |
| 2126 | struct mlx5_ib_qp_base *base; |
| 2127 | int mlx5_st; |
| 2128 | void *qpc; |
| 2129 | u32 *in; |
| 2130 | int err; |
| 2131 | |
| 2132 | mutex_init(&qp->mutex); |
| 2133 | spin_lock_init(&qp->sq.lock); |
| 2134 | spin_lock_init(&qp->rq.lock); |
| 2135 | |
| 2136 | mlx5_st = to_mlx5_st(qp->type); |
| 2137 | if (mlx5_st < 0) |
| 2138 | return -EINVAL; |
| 2139 | |
| 2140 | if (attr->sq_sig_type == IB_SIGNAL_ALL_WR) |
| 2141 | qp->sq_signal_bits = MLX5_WQE_CTRL_CQ_UPDATE; |
| 2142 | |
| 2143 | base = &qp->trans_qp.base; |
| 2144 | |
| 2145 | qp->has_rq = qp_has_rq(attr); |
| 2146 | err = set_rq_size(dev, &attr->cap, qp->has_rq, qp, NULL); |
| 2147 | if (err) { |
| 2148 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 2149 | return err; |
| 2150 | } |
| 2151 | |
| 2152 | err = _create_kernel_qp(dev, attr, qp, &in, &inlen, base); |
| 2153 | if (err) |
| 2154 | return err; |
| 2155 | |
| 2156 | if (is_sqp(attr->qp_type)) |
| 2157 | qp->port = attr->port_num; |
| 2158 | |
| 2159 | qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); |
| 2160 | |
| 2161 | MLX5_SET(qpc, qpc, st, mlx5_st); |
| 2162 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
| 2163 | |
| 2164 | if (attr->qp_type != MLX5_IB_QPT_REG_UMR) |
| 2165 | MLX5_SET(qpc, qpc, pd, to_mpd(pd ? pd : devr->p0)->pdn); |
| 2166 | else |
| 2167 | MLX5_SET(qpc, qpc, latency_sensitive, 1); |
| 2168 | |
| 2169 | |
| 2170 | if (qp->flags & IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) |
| 2171 | MLX5_SET(qpc, qpc, block_lb_mc, 1); |
| 2172 | |
| 2173 | if (qp->rq.wqe_cnt) { |
| 2174 | MLX5_SET(qpc, qpc, log_rq_stride, qp->rq.wqe_shift - 4); |
| 2175 | MLX5_SET(qpc, qpc, log_rq_size, ilog2(qp->rq.wqe_cnt)); |
| 2176 | } |
| 2177 | |
| 2178 | MLX5_SET(qpc, qpc, rq_type, get_rx_type(qp, attr)); |
| 2179 | |
| 2180 | if (qp->sq.wqe_cnt) |
| 2181 | MLX5_SET(qpc, qpc, log_sq_size, ilog2(qp->sq.wqe_cnt)); |
| 2182 | else |
| 2183 | MLX5_SET(qpc, qpc, no_sq, 1); |
| 2184 | |
| 2185 | if (attr->srq) { |
Leon Romanovsky | f437544 | 2020-07-06 15:27:14 +0300 | [diff] [blame] | 2186 | MLX5_SET(qpc, qpc, xrcd, devr->xrcdn0); |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2187 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, |
| 2188 | to_msrq(attr->srq)->msrq.srqn); |
| 2189 | } else { |
Leon Romanovsky | f437544 | 2020-07-06 15:27:14 +0300 | [diff] [blame] | 2190 | MLX5_SET(qpc, qpc, xrcd, devr->xrcdn1); |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2191 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, |
| 2192 | to_msrq(devr->s1)->msrq.srqn); |
| 2193 | } |
| 2194 | |
| 2195 | if (attr->send_cq) |
| 2196 | MLX5_SET(qpc, qpc, cqn_snd, to_mcq(attr->send_cq)->mcq.cqn); |
| 2197 | |
| 2198 | if (attr->recv_cq) |
| 2199 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(attr->recv_cq)->mcq.cqn); |
| 2200 | |
| 2201 | MLX5_SET64(qpc, qpc, dbr_addr, qp->db.dma); |
| 2202 | |
| 2203 | /* 0xffffff means we ask to work with cqe version 0 */ |
| 2204 | if (MLX5_CAP_GEN(mdev, cqe_version) == MLX5_CQE_VERSION_V1) |
| 2205 | MLX5_SET(qpc, qpc, user_index, uidx); |
| 2206 | |
| 2207 | /* we use IB_QP_CREATE_IPOIB_UD_LSO to indicates ipoib qp */ |
| 2208 | if (qp->flags & IB_QP_CREATE_IPOIB_UD_LSO) |
| 2209 | MLX5_SET(qpc, qpc, ulp_stateless_offload_mode, 1); |
| 2210 | |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 2211 | err = mlx5_qpc_create_qp(dev, &base->mqp, in, inlen, out); |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2212 | kvfree(in); |
| 2213 | if (err) |
| 2214 | goto err_create; |
| 2215 | |
| 2216 | base->container_mibqp = qp; |
| 2217 | base->mqp.event = mlx5_ib_qp_event; |
| 2218 | |
| 2219 | get_cqs(qp->type, attr->send_cq, attr->recv_cq, |
| 2220 | &send_cq, &recv_cq); |
| 2221 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2222 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2223 | /* Maintain device to QPs access, needed for further handling via reset |
| 2224 | * flow |
| 2225 | */ |
| 2226 | list_add_tail(&qp->qps_list, &dev->qp_list); |
| 2227 | /* Maintain CQ to QPs access, needed for further handling via reset flow |
| 2228 | */ |
| 2229 | if (send_cq) |
| 2230 | list_add_tail(&qp->cq_send_list, &send_cq->list_send_qp); |
| 2231 | if (recv_cq) |
| 2232 | list_add_tail(&qp->cq_recv_list, &recv_cq->list_recv_qp); |
| 2233 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2234 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 2235 | |
| 2236 | return 0; |
| 2237 | |
| 2238 | err_create: |
Leon Romanovsky | 747c519 | 2020-04-27 18:46:29 +0300 | [diff] [blame] | 2239 | destroy_qp(dev, qp, base, NULL); |
Leon Romanovsky | 98fc112 | 2020-04-27 18:46:28 +0300 | [diff] [blame] | 2240 | return err; |
| 2241 | } |
| 2242 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2243 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2244 | __acquires(&send_cq->lock) __acquires(&recv_cq->lock) |
| 2245 | { |
| 2246 | if (send_cq) { |
| 2247 | if (recv_cq) { |
| 2248 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2249 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2250 | spin_lock_nested(&recv_cq->lock, |
| 2251 | SINGLE_DEPTH_NESTING); |
| 2252 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2253 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2254 | __acquire(&recv_cq->lock); |
| 2255 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2256 | spin_lock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2257 | spin_lock_nested(&send_cq->lock, |
| 2258 | SINGLE_DEPTH_NESTING); |
| 2259 | } |
| 2260 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2261 | spin_lock(&send_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2262 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2263 | } |
| 2264 | } else if (recv_cq) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2265 | spin_lock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2266 | __acquire(&send_cq->lock); |
| 2267 | } else { |
| 2268 | __acquire(&send_cq->lock); |
| 2269 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2270 | } |
| 2271 | } |
| 2272 | |
| 2273 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2274 | __releases(&send_cq->lock) __releases(&recv_cq->lock) |
| 2275 | { |
| 2276 | if (send_cq) { |
| 2277 | if (recv_cq) { |
| 2278 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
| 2279 | spin_unlock(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2280 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2281 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
| 2282 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2283 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2284 | } else { |
| 2285 | spin_unlock(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2286 | spin_unlock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2287 | } |
| 2288 | } else { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2289 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2290 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2291 | } |
| 2292 | } else if (recv_cq) { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2293 | __release(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2294 | spin_unlock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2295 | } else { |
| 2296 | __release(&recv_cq->lock); |
| 2297 | __release(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2301 | static void get_cqs(enum ib_qp_type qp_type, |
| 2302 | struct ib_cq *ib_send_cq, struct ib_cq *ib_recv_cq, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2303 | struct mlx5_ib_cq **send_cq, struct mlx5_ib_cq **recv_cq) |
| 2304 | { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2305 | switch (qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2306 | case IB_QPT_XRC_TGT: |
| 2307 | *send_cq = NULL; |
| 2308 | *recv_cq = NULL; |
| 2309 | break; |
| 2310 | case MLX5_IB_QPT_REG_UMR: |
| 2311 | case IB_QPT_XRC_INI: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2312 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2313 | *recv_cq = NULL; |
| 2314 | break; |
| 2315 | |
| 2316 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2317 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2318 | case IB_QPT_RC: |
| 2319 | case IB_QPT_UC: |
| 2320 | case IB_QPT_UD: |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2321 | case IB_QPT_RAW_PACKET: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2322 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
| 2323 | *recv_cq = ib_recv_cq ? to_mcq(ib_recv_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2324 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2325 | default: |
| 2326 | *send_cq = NULL; |
| 2327 | *recv_cq = NULL; |
| 2328 | break; |
| 2329 | } |
| 2330 | } |
| 2331 | |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2332 | static int modify_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2333 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 2334 | u8 lag_tx_affinity); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2335 | |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2336 | static void destroy_qp_common(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2337 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2338 | { |
| 2339 | struct mlx5_ib_cq *send_cq, *recv_cq; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2340 | struct mlx5_ib_qp_base *base; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2341 | unsigned long flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2342 | int err; |
| 2343 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 2344 | if (qp->ibqp.rwq_ind_tbl) { |
| 2345 | destroy_rss_raw_qp_tir(dev, qp); |
| 2346 | return; |
| 2347 | } |
| 2348 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2349 | base = (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2350 | qp->flags & IB_QP_CREATE_SOURCE_QPN) ? |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2351 | &qp->raw_packet_qp.rq.base : |
| 2352 | &qp->trans_qp.base; |
| 2353 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2354 | if (qp->state != IB_QPS_RESET) { |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2355 | if (qp->ibqp.qp_type != IB_QPT_RAW_PACKET && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2356 | !(qp->flags & IB_QP_CREATE_SOURCE_QPN)) { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2357 | err = mlx5_core_qp_modify(dev, MLX5_CMD_OP_2RST_QP, 0, |
Leon Romanovsky | 5f62a52 | 2020-05-26 14:54:39 +0300 | [diff] [blame] | 2358 | NULL, &base->mqp, NULL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2359 | } else { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 2360 | struct mlx5_modify_raw_qp_param raw_qp_param = { |
| 2361 | .operation = MLX5_CMD_OP_2RST_QP |
| 2362 | }; |
| 2363 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2364 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, 0); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2365 | } |
| 2366 | if (err) |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 2367 | mlx5_ib_warn(dev, "mlx5_ib: modify QP 0x%06x to RESET failed\n", |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2368 | base->mqp.qpn); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2369 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2370 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2371 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 2372 | &send_cq, &recv_cq); |
| 2373 | |
| 2374 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2375 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2376 | /* del from lists under both locks above to protect reset flow paths */ |
| 2377 | list_del(&qp->qps_list); |
| 2378 | if (send_cq) |
| 2379 | list_del(&qp->cq_send_list); |
| 2380 | |
| 2381 | if (recv_cq) |
| 2382 | list_del(&qp->cq_recv_list); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2383 | |
Leon Romanovsky | 03c4077 | 2020-04-27 18:46:24 +0300 | [diff] [blame] | 2384 | if (!udata) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2385 | __mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2386 | qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL); |
| 2387 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2388 | __mlx5_ib_cq_clean(send_cq, base->mqp.qpn, |
| 2389 | NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2390 | } |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2391 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2392 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2393 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2394 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2395 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2396 | destroy_raw_packet_qp(dev, qp); |
| 2397 | } else { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2398 | err = mlx5_core_destroy_qp(dev, &base->mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2399 | if (err) |
| 2400 | mlx5_ib_warn(dev, "failed to destroy QP 0x%x\n", |
| 2401 | base->mqp.qpn); |
| 2402 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2403 | |
Leon Romanovsky | 747c519 | 2020-04-27 18:46:29 +0300 | [diff] [blame] | 2404 | destroy_qp(dev, qp, base, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2405 | } |
| 2406 | |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 2407 | static int create_dct(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 2408 | struct mlx5_ib_qp *qp, |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2409 | struct mlx5_create_qp_params *params) |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2410 | { |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2411 | struct ib_qp_init_attr *attr = params->attr; |
| 2412 | struct mlx5_ib_create_qp *ucmd = params->ucmd; |
| 2413 | u32 uidx = params->uidx; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2414 | void *dctc; |
| 2415 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2416 | qp->dct.in = kzalloc(MLX5_ST_SZ_BYTES(create_dct_in), GFP_KERNEL); |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2417 | if (!qp->dct.in) |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2418 | return -ENOMEM; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2419 | |
Yishai Hadas | a01a586 | 2018-09-20 21:39:24 +0300 | [diff] [blame] | 2420 | MLX5_SET(create_dct_in, qp->dct.in, uid, to_mpd(pd)->uid); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2421 | dctc = MLX5_ADDR_OF(create_dct_in, qp->dct.in, dct_context_entry); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2422 | MLX5_SET(dctc, dctc, pd, to_mpd(pd)->pdn); |
| 2423 | MLX5_SET(dctc, dctc, srqn_xrqn, to_msrq(attr->srq)->msrq.srqn); |
| 2424 | MLX5_SET(dctc, dctc, cqn, to_mcq(attr->recv_cq)->mcq.cqn); |
| 2425 | MLX5_SET64(dctc, dctc, dc_access_key, ucmd->access_key); |
| 2426 | MLX5_SET(dctc, dctc, user_index, uidx); |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 2427 | if (MLX5_CAP_GEN(dev->mdev, ece_support)) |
| 2428 | MLX5_SET(dctc, dctc, ece, ucmd->ece_options); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2429 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2430 | if (qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) { |
Leon Romanovsky | fd9dab7 | 2020-04-27 18:46:08 +0300 | [diff] [blame] | 2431 | int rcqe_sz = mlx5_ib_get_cqe_size(attr->recv_cq); |
| 2432 | |
| 2433 | if (rcqe_sz == 128) |
| 2434 | MLX5_SET(dctc, dctc, cs_res, MLX5_RES_SCAT_DATA64_CQE); |
| 2435 | } |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 2436 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2437 | qp->state = IB_QPS_RESET; |
| 2438 | |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2439 | return 0; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2440 | } |
| 2441 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2442 | static int check_qp_type(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr, |
| 2443 | enum ib_qp_type *type) |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2444 | { |
| 2445 | if (attr->qp_type == IB_QPT_DRIVER && !MLX5_CAP_GEN(dev->mdev, dct)) |
| 2446 | goto out; |
| 2447 | |
| 2448 | switch (attr->qp_type) { |
| 2449 | case IB_QPT_XRC_TGT: |
| 2450 | case IB_QPT_XRC_INI: |
| 2451 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
| 2452 | goto out; |
| 2453 | fallthrough; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2454 | case IB_QPT_RC: |
| 2455 | case IB_QPT_UC: |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2456 | case IB_QPT_SMI: |
| 2457 | case MLX5_IB_QPT_HW_GSI: |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2458 | case IB_QPT_DRIVER: |
| 2459 | case IB_QPT_GSI: |
Mark Bloch | 42caf9c | 2020-05-06 10:16:02 +0300 | [diff] [blame] | 2460 | if (dev->profile == &raw_eth_profile) |
| 2461 | goto out; |
| 2462 | case IB_QPT_RAW_PACKET: |
| 2463 | case IB_QPT_UD: |
| 2464 | case MLX5_IB_QPT_REG_UMR: |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2465 | break; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2466 | default: |
| 2467 | goto out; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2468 | } |
| 2469 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2470 | *type = attr->qp_type; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2471 | return 0; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2472 | |
| 2473 | out: |
| 2474 | mlx5_ib_dbg(dev, "Unsupported QP type %d\n", attr->qp_type); |
| 2475 | return -EOPNOTSUPP; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2476 | } |
| 2477 | |
Leon Romanovsky | 2242cc2 | 2020-04-27 18:46:03 +0300 | [diff] [blame] | 2478 | static int check_valid_flow(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 2479 | struct ib_qp_init_attr *attr, |
| 2480 | struct ib_udata *udata) |
| 2481 | { |
| 2482 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 2483 | udata, struct mlx5_ib_ucontext, ibucontext); |
| 2484 | |
| 2485 | if (!udata) { |
| 2486 | /* Kernel create_qp callers */ |
| 2487 | if (attr->rwq_ind_tbl) |
| 2488 | return -EOPNOTSUPP; |
| 2489 | |
| 2490 | switch (attr->qp_type) { |
| 2491 | case IB_QPT_RAW_PACKET: |
| 2492 | case IB_QPT_DRIVER: |
| 2493 | return -EOPNOTSUPP; |
| 2494 | default: |
| 2495 | return 0; |
| 2496 | } |
| 2497 | } |
| 2498 | |
| 2499 | /* Userspace create_qp callers */ |
| 2500 | if (attr->qp_type == IB_QPT_RAW_PACKET && !ucontext->cqe_version) { |
| 2501 | mlx5_ib_dbg(dev, |
| 2502 | "Raw Packet QP is only supported for CQE version > 0\n"); |
| 2503 | return -EINVAL; |
| 2504 | } |
| 2505 | |
| 2506 | if (attr->qp_type != IB_QPT_RAW_PACKET && attr->rwq_ind_tbl) { |
| 2507 | mlx5_ib_dbg(dev, |
| 2508 | "Wrong QP type %d for the RWQ indirect table\n", |
| 2509 | attr->qp_type); |
| 2510 | return -EINVAL; |
| 2511 | } |
| 2512 | |
| 2513 | switch (attr->qp_type) { |
| 2514 | case IB_QPT_SMI: |
| 2515 | case MLX5_IB_QPT_HW_GSI: |
| 2516 | case MLX5_IB_QPT_REG_UMR: |
| 2517 | case IB_QPT_GSI: |
| 2518 | mlx5_ib_dbg(dev, "Kernel doesn't support QP type %d\n", |
| 2519 | attr->qp_type); |
| 2520 | return -EINVAL; |
| 2521 | default: |
| 2522 | break; |
| 2523 | } |
| 2524 | |
| 2525 | /* |
| 2526 | * We don't need to see this warning, it means that kernel code |
| 2527 | * missing ib_pd. Placed here to catch developer's mistakes. |
| 2528 | */ |
| 2529 | WARN_ONCE(!pd && attr->qp_type != IB_QPT_XRC_TGT, |
| 2530 | "There is a missing PD pointer assignment\n"); |
| 2531 | return 0; |
| 2532 | } |
| 2533 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2534 | static void process_vendor_flag(struct mlx5_ib_dev *dev, int *flags, int flag, |
| 2535 | bool cond, struct mlx5_ib_qp *qp) |
| 2536 | { |
| 2537 | if (!(*flags & flag)) |
| 2538 | return; |
| 2539 | |
| 2540 | if (cond) { |
| 2541 | qp->flags_en |= flag; |
| 2542 | *flags &= ~flag; |
| 2543 | return; |
| 2544 | } |
| 2545 | |
| 2546 | if (flag == MLX5_QP_FLAG_SCATTER_CQE) { |
| 2547 | /* |
| 2548 | * We don't return error if this flag was provided, |
| 2549 | * and mlx5 doesn't have right capability. |
| 2550 | */ |
| 2551 | *flags &= ~MLX5_QP_FLAG_SCATTER_CQE; |
| 2552 | return; |
| 2553 | } |
| 2554 | mlx5_ib_dbg(dev, "Vendor create QP flag 0x%X is not supported\n", flag); |
| 2555 | } |
| 2556 | |
| 2557 | static int process_vendor_flags(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2558 | void *ucmd, struct ib_qp_init_attr *attr) |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2559 | { |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2560 | struct mlx5_core_dev *mdev = dev->mdev; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2561 | bool cond; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2562 | int flags; |
| 2563 | |
| 2564 | if (attr->rwq_ind_tbl) |
| 2565 | flags = ((struct mlx5_ib_create_qp_rss *)ucmd)->flags; |
| 2566 | else |
| 2567 | flags = ((struct mlx5_ib_create_qp *)ucmd)->flags; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2568 | |
| 2569 | switch (flags & (MLX5_QP_FLAG_TYPE_DCT | MLX5_QP_FLAG_TYPE_DCI)) { |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2570 | case MLX5_QP_FLAG_TYPE_DCI: |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2571 | qp->type = MLX5_IB_QPT_DCI; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2572 | break; |
| 2573 | case MLX5_QP_FLAG_TYPE_DCT: |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2574 | qp->type = MLX5_IB_QPT_DCT; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2575 | break; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2576 | default: |
| 2577 | if (qp->type != IB_QPT_DRIVER) |
| 2578 | break; |
| 2579 | /* |
| 2580 | * It is IB_QPT_DRIVER and or no subtype or |
| 2581 | * wrong subtype were provided. |
| 2582 | */ |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2583 | return -EINVAL; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2584 | } |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2585 | |
| 2586 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_TYPE_DCI, true, qp); |
| 2587 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_TYPE_DCT, true, qp); |
| 2588 | |
| 2589 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_SIGNATURE, true, qp); |
| 2590 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_SCATTER_CQE, |
| 2591 | MLX5_CAP_GEN(mdev, sctr_data_cqe), qp); |
| 2592 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2593 | if (qp->type == IB_QPT_RAW_PACKET) { |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2594 | cond = MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan) || |
| 2595 | MLX5_CAP_ETH(mdev, tunnel_stateless_gre) || |
| 2596 | MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx); |
| 2597 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_TUNNEL_OFFLOADS, |
| 2598 | cond, qp); |
| 2599 | process_vendor_flag(dev, &flags, |
| 2600 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC, true, |
| 2601 | qp); |
| 2602 | process_vendor_flag(dev, &flags, |
| 2603 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC, true, |
| 2604 | qp); |
| 2605 | } |
| 2606 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2607 | if (qp->type == IB_QPT_RC) |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2608 | process_vendor_flag(dev, &flags, |
| 2609 | MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE, |
| 2610 | MLX5_CAP_GEN(mdev, qp_packet_based), qp); |
| 2611 | |
Leon Romanovsky | 76883a6 | 2020-04-27 18:46:23 +0300 | [diff] [blame] | 2612 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_BFREG_INDEX, true, qp); |
| 2613 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_UAR_PAGE_INDEX, true, qp); |
| 2614 | |
Leon Romanovsky | 5d6fffe | 2020-04-27 18:46:31 +0300 | [diff] [blame] | 2615 | cond = qp->flags_en & ~(MLX5_QP_FLAG_TUNNEL_OFFLOADS | |
| 2616 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 2617 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC); |
| 2618 | if (attr->rwq_ind_tbl && cond) { |
| 2619 | mlx5_ib_dbg(dev, "RSS RAW QP has unsupported flags 0x%X\n", |
| 2620 | cond); |
| 2621 | return -EINVAL; |
| 2622 | } |
| 2623 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2624 | if (flags) |
| 2625 | mlx5_ib_dbg(dev, "udata has unsupported flags 0x%X\n", flags); |
| 2626 | |
| 2627 | return (flags) ? -EINVAL : 0; |
Leon Romanovsky | 5d6fffe | 2020-04-27 18:46:31 +0300 | [diff] [blame] | 2628 | } |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2629 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2630 | static void process_create_flag(struct mlx5_ib_dev *dev, int *flags, int flag, |
| 2631 | bool cond, struct mlx5_ib_qp *qp) |
| 2632 | { |
| 2633 | if (!(*flags & flag)) |
| 2634 | return; |
| 2635 | |
| 2636 | if (cond) { |
| 2637 | qp->flags |= flag; |
| 2638 | *flags &= ~flag; |
| 2639 | return; |
| 2640 | } |
| 2641 | |
| 2642 | if (flag == MLX5_IB_QP_CREATE_WC_TEST) { |
| 2643 | /* |
| 2644 | * Special case, if condition didn't meet, it won't be error, |
| 2645 | * just different in-kernel flow. |
| 2646 | */ |
| 2647 | *flags &= ~MLX5_IB_QP_CREATE_WC_TEST; |
| 2648 | return; |
| 2649 | } |
| 2650 | mlx5_ib_dbg(dev, "Verbs create QP flag 0x%X is not supported\n", flag); |
| 2651 | } |
| 2652 | |
| 2653 | static int process_create_flags(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2654 | struct ib_qp_init_attr *attr) |
| 2655 | { |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2656 | enum ib_qp_type qp_type = qp->type; |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2657 | struct mlx5_core_dev *mdev = dev->mdev; |
| 2658 | int create_flags = attr->create_flags; |
| 2659 | bool cond; |
| 2660 | |
Mark Bloch | 42caf9c | 2020-05-06 10:16:02 +0300 | [diff] [blame] | 2661 | if (qp->type == IB_QPT_UD && dev->profile == &raw_eth_profile) |
| 2662 | if (create_flags & ~MLX5_IB_QP_CREATE_WC_TEST) |
| 2663 | return -EINVAL; |
| 2664 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2665 | if (qp_type == MLX5_IB_QPT_DCT) |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2666 | return (create_flags) ? -EINVAL : 0; |
| 2667 | |
| 2668 | if (qp_type == IB_QPT_RAW_PACKET && attr->rwq_ind_tbl) |
| 2669 | return (create_flags) ? -EINVAL : 0; |
| 2670 | |
| 2671 | process_create_flag(dev, &create_flags, |
| 2672 | IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK, |
| 2673 | MLX5_CAP_GEN(mdev, block_lb_mc), qp); |
| 2674 | process_create_flag(dev, &create_flags, IB_QP_CREATE_CROSS_CHANNEL, |
| 2675 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2676 | process_create_flag(dev, &create_flags, IB_QP_CREATE_MANAGED_SEND, |
| 2677 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2678 | process_create_flag(dev, &create_flags, IB_QP_CREATE_MANAGED_RECV, |
| 2679 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2680 | |
| 2681 | if (qp_type == IB_QPT_UD) { |
| 2682 | process_create_flag(dev, &create_flags, |
| 2683 | IB_QP_CREATE_IPOIB_UD_LSO, |
| 2684 | MLX5_CAP_GEN(mdev, ipoib_basic_offloads), |
| 2685 | qp); |
| 2686 | cond = MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_IB; |
| 2687 | process_create_flag(dev, &create_flags, IB_QP_CREATE_SOURCE_QPN, |
| 2688 | cond, qp); |
| 2689 | } |
| 2690 | |
| 2691 | if (qp_type == IB_QPT_RAW_PACKET) { |
| 2692 | cond = MLX5_CAP_GEN(mdev, eth_net_offloads) && |
| 2693 | MLX5_CAP_ETH(mdev, scatter_fcs); |
| 2694 | process_create_flag(dev, &create_flags, |
| 2695 | IB_QP_CREATE_SCATTER_FCS, cond, qp); |
| 2696 | |
| 2697 | cond = MLX5_CAP_GEN(mdev, eth_net_offloads) && |
| 2698 | MLX5_CAP_ETH(mdev, vlan_cap); |
| 2699 | process_create_flag(dev, &create_flags, |
| 2700 | IB_QP_CREATE_CVLAN_STRIPPING, cond, qp); |
| 2701 | } |
| 2702 | |
| 2703 | process_create_flag(dev, &create_flags, |
| 2704 | IB_QP_CREATE_PCI_WRITE_END_PADDING, |
| 2705 | MLX5_CAP_GEN(mdev, end_pad), qp); |
| 2706 | |
| 2707 | process_create_flag(dev, &create_flags, MLX5_IB_QP_CREATE_WC_TEST, |
| 2708 | qp_type != MLX5_IB_QPT_REG_UMR, qp); |
| 2709 | process_create_flag(dev, &create_flags, MLX5_IB_QP_CREATE_SQPN_QP1, |
| 2710 | true, qp); |
| 2711 | |
| 2712 | if (create_flags) |
| 2713 | mlx5_ib_dbg(dev, "Create QP has unsupported flags 0x%X\n", |
| 2714 | create_flags); |
| 2715 | |
| 2716 | return (create_flags) ? -EINVAL : 0; |
| 2717 | } |
| 2718 | |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2719 | static int process_udata_size(struct mlx5_ib_dev *dev, |
| 2720 | struct mlx5_create_qp_params *params) |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2721 | { |
| 2722 | size_t ucmd = sizeof(struct mlx5_ib_create_qp); |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2723 | struct ib_udata *udata = params->udata; |
| 2724 | size_t outlen = udata->outlen; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2725 | size_t inlen = udata->inlen; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2726 | |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2727 | params->outlen = min(outlen, sizeof(struct mlx5_ib_create_qp_resp)); |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2728 | params->ucmd_size = ucmd; |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2729 | if (!params->is_rss_raw) { |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2730 | /* User has old rdma-core, which doesn't support ECE */ |
| 2731 | size_t min_inlen = |
| 2732 | offsetof(struct mlx5_ib_create_qp, ece_options); |
| 2733 | |
| 2734 | /* |
| 2735 | * We will check in check_ucmd_data() that user |
| 2736 | * cleared everything after inlen. |
| 2737 | */ |
| 2738 | params->inlen = (inlen < min_inlen) ? 0 : min(inlen, ucmd); |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2739 | goto out; |
| 2740 | } |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2741 | |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2742 | /* RSS RAW QP */ |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2743 | if (inlen < offsetofend(struct mlx5_ib_create_qp_rss, flags)) |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2744 | return -EINVAL; |
| 2745 | |
| 2746 | if (outlen < offsetofend(struct mlx5_ib_create_qp_resp, bfreg_index)) |
| 2747 | return -EINVAL; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2748 | |
| 2749 | ucmd = sizeof(struct mlx5_ib_create_qp_rss); |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2750 | params->ucmd_size = ucmd; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2751 | if (inlen > ucmd && !ib_is_udata_cleared(udata, ucmd, inlen - ucmd)) |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2752 | return -EINVAL; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2753 | |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2754 | params->inlen = min(ucmd, inlen); |
| 2755 | out: |
| 2756 | if (!params->inlen) |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2757 | mlx5_ib_dbg(dev, "udata is too small\n"); |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2758 | |
| 2759 | return (params->inlen) ? 0 : -EINVAL; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2760 | } |
| 2761 | |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 2762 | static int create_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 2763 | struct mlx5_ib_qp *qp, |
| 2764 | struct mlx5_create_qp_params *params) |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2765 | { |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 2766 | int err; |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2767 | |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 2768 | if (params->is_rss_raw) { |
| 2769 | err = create_rss_raw_qp_tir(dev, pd, qp, params); |
| 2770 | goto out; |
| 2771 | } |
| 2772 | |
| 2773 | if (qp->type == MLX5_IB_QPT_DCT) { |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 2774 | err = create_dct(dev, pd, qp, params); |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 2775 | goto out; |
| 2776 | } |
| 2777 | |
| 2778 | if (qp->type == IB_QPT_XRC_TGT) { |
| 2779 | err = create_xrc_tgt_qp(dev, qp, params); |
| 2780 | goto out; |
| 2781 | } |
| 2782 | |
| 2783 | if (params->udata) |
| 2784 | err = create_user_qp(dev, pd, qp, params); |
| 2785 | else |
| 2786 | err = create_kernel_qp(dev, pd, qp, params); |
| 2787 | |
| 2788 | out: |
| 2789 | if (err) { |
| 2790 | mlx5_ib_err(dev, "Create QP type %d failed\n", qp->type); |
| 2791 | return err; |
| 2792 | } |
| 2793 | |
| 2794 | if (is_qp0(qp->type)) |
| 2795 | qp->ibqp.qp_num = 0; |
| 2796 | else if (is_qp1(qp->type)) |
| 2797 | qp->ibqp.qp_num = 1; |
| 2798 | else |
| 2799 | qp->ibqp.qp_num = qp->trans_qp.base.mqp.qpn; |
| 2800 | |
| 2801 | mlx5_ib_dbg(dev, |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 2802 | "QP type %d, ib qpn 0x%X, mlx qpn 0x%x, rcqn 0x%x, scqn 0x%x, ece 0x%x\n", |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 2803 | qp->type, qp->ibqp.qp_num, qp->trans_qp.base.mqp.qpn, |
| 2804 | params->attr->recv_cq ? to_mcq(params->attr->recv_cq)->mcq.cqn : |
| 2805 | -1, |
| 2806 | params->attr->send_cq ? to_mcq(params->attr->send_cq)->mcq.cqn : |
Leon Romanovsky | 3e09a42 | 2020-05-26 14:54:34 +0300 | [diff] [blame] | 2807 | -1, |
| 2808 | params->resp.ece_options); |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 2809 | |
| 2810 | return 0; |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2811 | } |
| 2812 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2813 | static int check_qp_attr(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2814 | struct ib_qp_init_attr *attr) |
| 2815 | { |
| 2816 | int ret = 0; |
| 2817 | |
| 2818 | switch (qp->type) { |
| 2819 | case MLX5_IB_QPT_DCT: |
| 2820 | ret = (!attr->srq || !attr->recv_cq) ? -EINVAL : 0; |
| 2821 | break; |
| 2822 | case MLX5_IB_QPT_DCI: |
| 2823 | ret = (attr->cap.max_recv_wr || attr->cap.max_recv_sge) ? |
| 2824 | -EINVAL : |
| 2825 | 0; |
| 2826 | break; |
Leon Romanovsky | 266424e | 2020-04-27 18:46:21 +0300 | [diff] [blame] | 2827 | case IB_QPT_RAW_PACKET: |
| 2828 | ret = (attr->rwq_ind_tbl && attr->send_cq) ? -EINVAL : 0; |
| 2829 | break; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2830 | default: |
| 2831 | break; |
| 2832 | } |
| 2833 | |
| 2834 | if (ret) |
| 2835 | mlx5_ib_dbg(dev, "QP type %d has wrong attributes\n", qp->type); |
| 2836 | |
| 2837 | return ret; |
| 2838 | } |
| 2839 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2840 | static int get_qp_uidx(struct mlx5_ib_qp *qp, |
| 2841 | struct mlx5_create_qp_params *params) |
Leon Romanovsky | 21aad80 | 2020-04-27 18:46:26 +0300 | [diff] [blame] | 2842 | { |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2843 | struct mlx5_ib_create_qp *ucmd = params->ucmd; |
| 2844 | struct ib_udata *udata = params->udata; |
Leon Romanovsky | 21aad80 | 2020-04-27 18:46:26 +0300 | [diff] [blame] | 2845 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 2846 | udata, struct mlx5_ib_ucontext, ibucontext); |
| 2847 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2848 | if (params->is_rss_raw) |
Leon Romanovsky | 21aad80 | 2020-04-27 18:46:26 +0300 | [diff] [blame] | 2849 | return 0; |
| 2850 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2851 | return get_qp_user_index(ucontext, ucmd, sizeof(*ucmd), ¶ms->uidx); |
Leon Romanovsky | 21aad80 | 2020-04-27 18:46:26 +0300 | [diff] [blame] | 2852 | } |
| 2853 | |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 2854 | static int mlx5_ib_destroy_dct(struct mlx5_ib_qp *mqp) |
| 2855 | { |
| 2856 | struct mlx5_ib_dev *dev = to_mdev(mqp->ibqp.device); |
| 2857 | |
| 2858 | if (mqp->state == IB_QPS_RTR) { |
| 2859 | int err; |
| 2860 | |
| 2861 | err = mlx5_core_destroy_dct(dev, &mqp->dct.mdct); |
| 2862 | if (err) { |
| 2863 | mlx5_ib_warn(dev, "failed to destroy DCT %d\n", err); |
| 2864 | return err; |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | kfree(mqp->dct.in); |
| 2869 | kfree(mqp); |
| 2870 | return 0; |
| 2871 | } |
| 2872 | |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2873 | static int check_ucmd_data(struct mlx5_ib_dev *dev, |
| 2874 | struct mlx5_create_qp_params *params) |
| 2875 | { |
| 2876 | struct ib_qp_init_attr *attr = params->attr; |
| 2877 | struct ib_udata *udata = params->udata; |
| 2878 | size_t size, last; |
| 2879 | int ret; |
| 2880 | |
| 2881 | if (params->is_rss_raw) |
| 2882 | /* |
| 2883 | * These QPs don't have "reserved" field in their |
| 2884 | * create_qp input struct, so their data is always valid. |
| 2885 | */ |
| 2886 | last = sizeof(struct mlx5_ib_create_qp_rss); |
| 2887 | else |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 2888 | /* IB_QPT_RAW_PACKET doesn't have ECE data */ |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2889 | switch (attr->qp_type) { |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2890 | case IB_QPT_RAW_PACKET: |
| 2891 | last = offsetof(struct mlx5_ib_create_qp, ece_options); |
| 2892 | break; |
| 2893 | default: |
| 2894 | last = offsetof(struct mlx5_ib_create_qp, reserved); |
| 2895 | } |
| 2896 | |
| 2897 | if (udata->inlen <= last) |
| 2898 | return 0; |
| 2899 | |
| 2900 | /* |
| 2901 | * User provides different create_qp structures based on the |
| 2902 | * flow and we need to know if he cleared memory after our |
| 2903 | * struct create_qp ends. |
| 2904 | */ |
| 2905 | size = udata->inlen - last; |
| 2906 | ret = ib_is_udata_cleared(params->udata, last, size); |
| 2907 | if (!ret) |
| 2908 | mlx5_ib_dbg( |
| 2909 | dev, |
| 2910 | "udata is not cleared, inlen = %lu, ucmd = %lu, last = %lu, size = %lu\n", |
| 2911 | udata->inlen, params->ucmd_size, last, size); |
| 2912 | return ret ? 0 : -EINVAL; |
| 2913 | } |
| 2914 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2915 | struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd, struct ib_qp_init_attr *attr, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2916 | struct ib_udata *udata) |
| 2917 | { |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2918 | struct mlx5_create_qp_params params = {}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2919 | struct mlx5_ib_dev *dev; |
| 2920 | struct mlx5_ib_qp *qp; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2921 | enum ib_qp_type type; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2922 | int err; |
| 2923 | |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2924 | dev = pd ? to_mdev(pd->device) : |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2925 | to_mdev(to_mxrcd(attr->xrcd)->ibxrcd.device); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2926 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2927 | err = check_qp_type(dev, attr, &type); |
Leon Romanovsky | 2242cc2 | 2020-04-27 18:46:03 +0300 | [diff] [blame] | 2928 | if (err) |
| 2929 | return ERR_PTR(err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2930 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2931 | err = check_valid_flow(dev, pd, attr, udata); |
| 2932 | if (err) |
| 2933 | return ERR_PTR(err); |
| 2934 | |
| 2935 | if (attr->qp_type == IB_QPT_GSI) |
| 2936 | return mlx5_ib_gsi_create_qp(pd, attr); |
| 2937 | |
| 2938 | params.udata = udata; |
| 2939 | params.uidx = MLX5_IB_DEFAULT_UIDX; |
| 2940 | params.attr = attr; |
| 2941 | params.is_rss_raw = !!attr->rwq_ind_tbl; |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2942 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2943 | if (udata) { |
Leon Romanovsky | 6f2cf76 | 2020-04-27 18:46:32 +0300 | [diff] [blame] | 2944 | err = process_udata_size(dev, ¶ms); |
| 2945 | if (err) |
| 2946 | return ERR_PTR(err); |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2947 | |
Leon Romanovsky | e383085 | 2020-05-26 14:54:35 +0300 | [diff] [blame] | 2948 | err = check_ucmd_data(dev, ¶ms); |
| 2949 | if (err) |
| 2950 | return ERR_PTR(err); |
| 2951 | |
| 2952 | params.ucmd = kzalloc(params.ucmd_size, GFP_KERNEL); |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2953 | if (!params.ucmd) |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2954 | return ERR_PTR(-ENOMEM); |
| 2955 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2956 | err = ib_copy_from_udata(params.ucmd, udata, params.inlen); |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2957 | if (err) |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2958 | goto free_ucmd; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2959 | } |
| 2960 | |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2961 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2962 | if (!qp) { |
| 2963 | err = -ENOMEM; |
| 2964 | goto free_ucmd; |
| 2965 | } |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2966 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2967 | qp->type = type; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2968 | if (udata) { |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2969 | err = process_vendor_flags(dev, qp, params.ucmd, attr); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2970 | if (err) |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2971 | goto free_qp; |
Leon Romanovsky | 21aad80 | 2020-04-27 18:46:26 +0300 | [diff] [blame] | 2972 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2973 | err = get_qp_uidx(qp, ¶ms); |
Leon Romanovsky | 21aad80 | 2020-04-27 18:46:26 +0300 | [diff] [blame] | 2974 | if (err) |
| 2975 | goto free_qp; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2976 | } |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2977 | err = process_create_flags(dev, qp, attr); |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2978 | if (err) |
| 2979 | goto free_qp; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2980 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2981 | err = check_qp_attr(dev, qp, attr); |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2982 | if (err) |
| 2983 | goto free_qp; |
| 2984 | |
Leon Romanovsky | 968f0b6 | 2020-04-27 18:46:35 +0300 | [diff] [blame] | 2985 | err = create_qp(dev, pd, qp, ¶ms); |
| 2986 | if (err) |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2987 | goto free_qp; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2988 | |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 2989 | kfree(params.ucmd); |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 2990 | params.ucmd = NULL; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 2991 | |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 2992 | if (udata) |
| 2993 | /* |
| 2994 | * It is safe to copy response for all user create QP flows, |
| 2995 | * including MLX5_IB_QPT_DCT, which doesn't need it. |
| 2996 | * In that case, resp will be filled with zeros. |
| 2997 | */ |
| 2998 | err = ib_copy_to_udata(udata, ¶ms.resp, params.outlen); |
| 2999 | if (err) |
| 3000 | goto destroy_qp; |
| 3001 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3002 | return &qp->ibqp; |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 3003 | |
Leon Romanovsky | 08d53976 | 2020-04-27 18:46:33 +0300 | [diff] [blame] | 3004 | destroy_qp: |
| 3005 | if (qp->type == MLX5_IB_QPT_DCT) |
| 3006 | mlx5_ib_destroy_dct(qp); |
| 3007 | else |
| 3008 | destroy_qp_common(dev, qp, udata); |
| 3009 | qp = NULL; |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 3010 | free_qp: |
| 3011 | kfree(qp); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame] | 3012 | free_ucmd: |
Leon Romanovsky | f78d358 | 2020-04-27 18:46:30 +0300 | [diff] [blame] | 3013 | kfree(params.ucmd); |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 3014 | return ERR_PTR(err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3015 | } |
| 3016 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 3017 | int mlx5_ib_destroy_qp(struct ib_qp *qp, struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3018 | { |
| 3019 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 3020 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 3021 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3022 | if (unlikely(qp->qp_type == IB_QPT_GSI)) |
| 3023 | return mlx5_ib_gsi_destroy_qp(qp); |
| 3024 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 3025 | if (mqp->type == MLX5_IB_QPT_DCT) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3026 | return mlx5_ib_destroy_dct(mqp); |
| 3027 | |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 3028 | destroy_qp_common(dev, mqp, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3029 | |
| 3030 | kfree(mqp); |
| 3031 | |
| 3032 | return 0; |
| 3033 | } |
| 3034 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3035 | static int set_qpc_atomic_flags(struct mlx5_ib_qp *qp, |
| 3036 | const struct ib_qp_attr *attr, int attr_mask, |
| 3037 | void *qpc) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3038 | { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3039 | struct mlx5_ib_dev *dev = to_mdev(qp->ibqp.device); |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3040 | u8 dest_rd_atomic; |
| 3041 | u32 access_flags; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3042 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3043 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
| 3044 | dest_rd_atomic = attr->max_dest_rd_atomic; |
| 3045 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3046 | dest_rd_atomic = qp->trans_qp.resp_depth; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3047 | |
| 3048 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
| 3049 | access_flags = attr->qp_access_flags; |
| 3050 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3051 | access_flags = qp->trans_qp.atomic_rd_en; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3052 | |
| 3053 | if (!dest_rd_atomic) |
| 3054 | access_flags &= IB_ACCESS_REMOTE_WRITE; |
| 3055 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3056 | MLX5_SET(qpc, qpc, rre, !!(access_flags & IB_ACCESS_REMOTE_READ)); |
| 3057 | |
Yonatan Cohen | 13f8d9c | 2018-11-21 13:48:39 +0200 | [diff] [blame] | 3058 | if (access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3059 | int atomic_mode; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3060 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3061 | atomic_mode = get_atomic_mode(dev, qp->ibqp.qp_type); |
| 3062 | if (atomic_mode < 0) |
| 3063 | return -EOPNOTSUPP; |
| 3064 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3065 | MLX5_SET(qpc, qpc, rae, 1); |
| 3066 | MLX5_SET(qpc, qpc, atomic_mode, atomic_mode); |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3067 | } |
| 3068 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3069 | MLX5_SET(qpc, qpc, rwe, !!(access_flags & IB_ACCESS_REMOTE_WRITE)); |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3070 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3071 | } |
| 3072 | |
| 3073 | enum { |
| 3074 | MLX5_PATH_FLAG_FL = 1 << 0, |
| 3075 | MLX5_PATH_FLAG_FREE_AR = 1 << 1, |
| 3076 | MLX5_PATH_FLAG_COUNTER = 1 << 2, |
| 3077 | }; |
| 3078 | |
| 3079 | static int ib_rate_to_mlx5(struct mlx5_ib_dev *dev, u8 rate) |
| 3080 | { |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 3081 | if (rate == IB_RATE_PORT_CURRENT) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3082 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3083 | |
Michael Guralnik | a5a5d19 | 2018-12-09 11:49:50 +0200 | [diff] [blame] | 3084 | if (rate < IB_RATE_2_5_GBPS || rate > IB_RATE_600_GBPS) |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 3085 | return -EINVAL; |
| 3086 | |
| 3087 | while (rate != IB_RATE_PORT_CURRENT && |
| 3088 | !(1 << (rate + MLX5_STAT_RATE_OFFSET) & |
| 3089 | MLX5_CAP_GEN(dev->mdev, stat_rate_support))) |
| 3090 | --rate; |
| 3091 | |
| 3092 | return rate ? rate + MLX5_STAT_RATE_OFFSET : rate; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3093 | } |
| 3094 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3095 | static int modify_raw_packet_eth_prio(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3096 | struct mlx5_ib_sq *sq, u8 sl, |
| 3097 | struct ib_pd *pd) |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3098 | { |
| 3099 | void *in; |
| 3100 | void *tisc; |
| 3101 | int inlen; |
| 3102 | int err; |
| 3103 | |
| 3104 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3105 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3106 | if (!in) |
| 3107 | return -ENOMEM; |
| 3108 | |
| 3109 | MLX5_SET(modify_tis_in, in, bitmask.prio, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3110 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3111 | |
| 3112 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 3113 | MLX5_SET(tisc, tisc, prio, ((sl & 0x7) << 1)); |
| 3114 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3115 | err = mlx5_core_modify_tis(dev, sq->tisn, in); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3116 | |
| 3117 | kvfree(in); |
| 3118 | |
| 3119 | return err; |
| 3120 | } |
| 3121 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3122 | static int modify_raw_packet_tx_affinity(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3123 | struct mlx5_ib_sq *sq, u8 tx_affinity, |
| 3124 | struct ib_pd *pd) |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3125 | { |
| 3126 | void *in; |
| 3127 | void *tisc; |
| 3128 | int inlen; |
| 3129 | int err; |
| 3130 | |
| 3131 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3132 | in = kvzalloc(inlen, GFP_KERNEL); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3133 | if (!in) |
| 3134 | return -ENOMEM; |
| 3135 | |
| 3136 | MLX5_SET(modify_tis_in, in, bitmask.lag_tx_port_affinity, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3137 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3138 | |
| 3139 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 3140 | MLX5_SET(tisc, tisc, lag_tx_port_affinity, tx_affinity); |
| 3141 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3142 | err = mlx5_core_modify_tis(dev, sq->tisn, in); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3143 | |
| 3144 | kvfree(in); |
| 3145 | |
| 3146 | return err; |
| 3147 | } |
| 3148 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3149 | static void mlx5_set_path_udp_sport(void *path, const struct rdma_ah_attr *ah, |
Mark Zhang | 2b880b2e | 2020-05-04 08:19:33 +0300 | [diff] [blame] | 3150 | u32 lqpn, u32 rqpn) |
| 3151 | |
| 3152 | { |
| 3153 | u32 fl = ah->grh.flow_label; |
Mark Zhang | 2b880b2e | 2020-05-04 08:19:33 +0300 | [diff] [blame] | 3154 | |
| 3155 | if (!fl) |
| 3156 | fl = rdma_calc_flow_label(lqpn, rqpn); |
| 3157 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3158 | MLX5_SET(ads, path, udp_sport, rdma_flow_label_to_udp_sport(fl)); |
Mark Zhang | 2b880b2e | 2020-05-04 08:19:33 +0300 | [diff] [blame] | 3159 | } |
| 3160 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3161 | static int mlx5_set_path(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3162 | const struct rdma_ah_attr *ah, void *path, u8 port, |
| 3163 | int attr_mask, u32 path_flags, |
| 3164 | const struct ib_qp_attr *attr, bool alt) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3165 | { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3166 | const struct ib_global_route *grh = rdma_ah_read_grh(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3167 | int err; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 3168 | enum ib_gid_type gid_type; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3169 | u8 ah_flags = rdma_ah_get_ah_flags(ah); |
| 3170 | u8 sl = rdma_ah_get_sl(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3171 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3172 | if (attr_mask & IB_QP_PKEY_INDEX) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3173 | MLX5_SET(ads, path, pkey_index, |
| 3174 | alt ? attr->alt_pkey_index : attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3175 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3176 | if (ah_flags & IB_AH_GRH) { |
| 3177 | if (grh->sgid_index >= |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3178 | dev->mdev->port_caps[port - 1].gid_table_len) { |
Joe Perches | f4f01b5 | 2015-05-08 15:58:07 -0700 | [diff] [blame] | 3179 | pr_err("sgid_index (%u) too large. max is %d\n", |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3180 | grh->sgid_index, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3181 | dev->mdev->port_caps[port - 1].gid_table_len); |
Eli Cohen | f83b426 | 2014-09-14 16:47:54 +0300 | [diff] [blame] | 3182 | return -EINVAL; |
| 3183 | } |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3184 | } |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 3185 | |
| 3186 | if (ah->type == RDMA_AH_ATTR_TYPE_ROCE) { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3187 | if (!(ah_flags & IB_AH_GRH)) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3188 | return -EINVAL; |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 3189 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3190 | ether_addr_copy(MLX5_ADDR_OF(ads, path, rmac_47_32), |
| 3191 | ah->roce.dmac); |
Mark Zhang | 2b880b2e | 2020-05-04 08:19:33 +0300 | [diff] [blame] | 3192 | if ((qp->ibqp.qp_type == IB_QPT_RC || |
| 3193 | qp->ibqp.qp_type == IB_QPT_UC || |
| 3194 | qp->ibqp.qp_type == IB_QPT_XRC_INI || |
| 3195 | qp->ibqp.qp_type == IB_QPT_XRC_TGT) && |
| 3196 | (grh->sgid_attr->gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) && |
| 3197 | (attr_mask & IB_QP_DEST_QPN)) |
| 3198 | mlx5_set_path_udp_sport(path, ah, |
| 3199 | qp->ibqp.qp_num, |
| 3200 | attr->dest_qp_num); |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3201 | MLX5_SET(ads, path, eth_prio, sl & 0x7); |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 3202 | gid_type = ah->grh.sgid_attr->gid_type; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 3203 | if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3204 | MLX5_SET(ads, path, dscp, grh->traffic_class >> 2); |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3205 | } else { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3206 | MLX5_SET(ads, path, fl, !!(path_flags & MLX5_PATH_FLAG_FL)); |
| 3207 | MLX5_SET(ads, path, free_ar, |
| 3208 | !!(path_flags & MLX5_PATH_FLAG_FREE_AR)); |
| 3209 | MLX5_SET(ads, path, rlid, rdma_ah_get_dlid(ah)); |
| 3210 | MLX5_SET(ads, path, mlid, rdma_ah_get_path_bits(ah)); |
| 3211 | MLX5_SET(ads, path, grh, !!(ah_flags & IB_AH_GRH)); |
| 3212 | MLX5_SET(ads, path, sl, sl); |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3213 | } |
| 3214 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3215 | if (ah_flags & IB_AH_GRH) { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3216 | MLX5_SET(ads, path, src_addr_index, grh->sgid_index); |
| 3217 | MLX5_SET(ads, path, hop_limit, grh->hop_limit); |
| 3218 | MLX5_SET(ads, path, tclass, grh->traffic_class); |
| 3219 | MLX5_SET(ads, path, flow_label, grh->flow_label); |
| 3220 | memcpy(MLX5_ADDR_OF(ads, path, rgid_rip), grh->dgid.raw, |
| 3221 | sizeof(grh->dgid.raw)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3222 | } |
| 3223 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3224 | err = ib_rate_to_mlx5(dev, rdma_ah_get_static_rate(ah)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3225 | if (err < 0) |
| 3226 | return err; |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3227 | MLX5_SET(ads, path, stat_rate, err); |
| 3228 | MLX5_SET(ads, path, vhca_port_num, port); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3229 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3230 | if (attr_mask & IB_QP_TIMEOUT) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3231 | MLX5_SET(ads, path, ack_timeout, |
| 3232 | alt ? attr->alt_timeout : attr->timeout); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3233 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3234 | if ((qp->ibqp.qp_type == IB_QPT_RAW_PACKET) && qp->sq.wqe_cnt) |
| 3235 | return modify_raw_packet_eth_prio(dev->mdev, |
| 3236 | &qp->raw_packet_qp.sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3237 | sl & 0xf, qp->ibqp.pd); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3238 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3239 | return 0; |
| 3240 | } |
| 3241 | |
| 3242 | static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_QP_ST_MAX] = { |
| 3243 | [MLX5_QP_STATE_INIT] = { |
| 3244 | [MLX5_QP_STATE_INIT] = { |
| 3245 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 3246 | MLX5_QP_OPTPAR_RAE | |
| 3247 | MLX5_QP_OPTPAR_RWE | |
| 3248 | MLX5_QP_OPTPAR_PKEY_INDEX | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3249 | MLX5_QP_OPTPAR_PRI_PORT | |
| 3250 | MLX5_QP_OPTPAR_LAG_TX_AFF, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3251 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
| 3252 | MLX5_QP_OPTPAR_PKEY_INDEX | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3253 | MLX5_QP_OPTPAR_PRI_PORT | |
| 3254 | MLX5_QP_OPTPAR_LAG_TX_AFF, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3255 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3256 | MLX5_QP_OPTPAR_Q_KEY | |
| 3257 | MLX5_QP_OPTPAR_PRI_PORT, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3258 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RRE | |
| 3259 | MLX5_QP_OPTPAR_RAE | |
| 3260 | MLX5_QP_OPTPAR_RWE | |
| 3261 | MLX5_QP_OPTPAR_PKEY_INDEX | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3262 | MLX5_QP_OPTPAR_PRI_PORT | |
| 3263 | MLX5_QP_OPTPAR_LAG_TX_AFF, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3264 | }, |
| 3265 | [MLX5_QP_STATE_RTR] = { |
| 3266 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3267 | MLX5_QP_OPTPAR_RRE | |
| 3268 | MLX5_QP_OPTPAR_RAE | |
| 3269 | MLX5_QP_OPTPAR_RWE | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3270 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3271 | MLX5_QP_OPTPAR_LAG_TX_AFF, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3272 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3273 | MLX5_QP_OPTPAR_RWE | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3274 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3275 | MLX5_QP_OPTPAR_LAG_TX_AFF, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3276 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3277 | MLX5_QP_OPTPAR_Q_KEY, |
| 3278 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3279 | MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 3280 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3281 | MLX5_QP_OPTPAR_RRE | |
| 3282 | MLX5_QP_OPTPAR_RAE | |
| 3283 | MLX5_QP_OPTPAR_RWE | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3284 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3285 | MLX5_QP_OPTPAR_LAG_TX_AFF, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3286 | }, |
| 3287 | }, |
| 3288 | [MLX5_QP_STATE_RTR] = { |
| 3289 | [MLX5_QP_STATE_RTS] = { |
| 3290 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3291 | MLX5_QP_OPTPAR_RRE | |
| 3292 | MLX5_QP_OPTPAR_RAE | |
| 3293 | MLX5_QP_OPTPAR_RWE | |
| 3294 | MLX5_QP_OPTPAR_PM_STATE | |
| 3295 | MLX5_QP_OPTPAR_RNR_TIMEOUT, |
| 3296 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3297 | MLX5_QP_OPTPAR_RWE | |
| 3298 | MLX5_QP_OPTPAR_PM_STATE, |
| 3299 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3300 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3301 | MLX5_QP_OPTPAR_RRE | |
| 3302 | MLX5_QP_OPTPAR_RAE | |
| 3303 | MLX5_QP_OPTPAR_RWE | |
| 3304 | MLX5_QP_OPTPAR_PM_STATE | |
| 3305 | MLX5_QP_OPTPAR_RNR_TIMEOUT, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3306 | }, |
| 3307 | }, |
| 3308 | [MLX5_QP_STATE_RTS] = { |
| 3309 | [MLX5_QP_STATE_RTS] = { |
| 3310 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 3311 | MLX5_QP_OPTPAR_RAE | |
| 3312 | MLX5_QP_OPTPAR_RWE | |
| 3313 | MLX5_QP_OPTPAR_RNR_TIMEOUT | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 3314 | MLX5_QP_OPTPAR_PM_STATE | |
| 3315 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3316 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 3317 | MLX5_QP_OPTPAR_PM_STATE | |
| 3318 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3319 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY | |
| 3320 | MLX5_QP_OPTPAR_SRQN | |
| 3321 | MLX5_QP_OPTPAR_CQN_RCV, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3322 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RRE | |
| 3323 | MLX5_QP_OPTPAR_RAE | |
| 3324 | MLX5_QP_OPTPAR_RWE | |
| 3325 | MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3326 | MLX5_QP_OPTPAR_PM_STATE | |
| 3327 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3328 | }, |
| 3329 | }, |
| 3330 | [MLX5_QP_STATE_SQER] = { |
| 3331 | [MLX5_QP_STATE_RTS] = { |
| 3332 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
| 3333 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | 75959f5 | 2013-09-11 16:35:31 +0300 | [diff] [blame] | 3334 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 3335 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3336 | MLX5_QP_OPTPAR_RWE | |
| 3337 | MLX5_QP_OPTPAR_RAE | |
| 3338 | MLX5_QP_OPTPAR_RRE, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3339 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3340 | MLX5_QP_OPTPAR_RWE | |
| 3341 | MLX5_QP_OPTPAR_RAE | |
| 3342 | MLX5_QP_OPTPAR_RRE, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3343 | }, |
| 3344 | }, |
| 3345 | }; |
| 3346 | |
| 3347 | static int ib_nr_to_mlx5_nr(int ib_mask) |
| 3348 | { |
| 3349 | switch (ib_mask) { |
| 3350 | case IB_QP_STATE: |
| 3351 | return 0; |
| 3352 | case IB_QP_CUR_STATE: |
| 3353 | return 0; |
| 3354 | case IB_QP_EN_SQD_ASYNC_NOTIFY: |
| 3355 | return 0; |
| 3356 | case IB_QP_ACCESS_FLAGS: |
| 3357 | return MLX5_QP_OPTPAR_RWE | MLX5_QP_OPTPAR_RRE | |
| 3358 | MLX5_QP_OPTPAR_RAE; |
| 3359 | case IB_QP_PKEY_INDEX: |
| 3360 | return MLX5_QP_OPTPAR_PKEY_INDEX; |
| 3361 | case IB_QP_PORT: |
| 3362 | return MLX5_QP_OPTPAR_PRI_PORT; |
| 3363 | case IB_QP_QKEY: |
| 3364 | return MLX5_QP_OPTPAR_Q_KEY; |
| 3365 | case IB_QP_AV: |
| 3366 | return MLX5_QP_OPTPAR_PRIMARY_ADDR_PATH | |
| 3367 | MLX5_QP_OPTPAR_PRI_PORT; |
| 3368 | case IB_QP_PATH_MTU: |
| 3369 | return 0; |
| 3370 | case IB_QP_TIMEOUT: |
| 3371 | return MLX5_QP_OPTPAR_ACK_TIMEOUT; |
| 3372 | case IB_QP_RETRY_CNT: |
| 3373 | return MLX5_QP_OPTPAR_RETRY_COUNT; |
| 3374 | case IB_QP_RNR_RETRY: |
| 3375 | return MLX5_QP_OPTPAR_RNR_RETRY; |
| 3376 | case IB_QP_RQ_PSN: |
| 3377 | return 0; |
| 3378 | case IB_QP_MAX_QP_RD_ATOMIC: |
| 3379 | return MLX5_QP_OPTPAR_SRA_MAX; |
| 3380 | case IB_QP_ALT_PATH: |
| 3381 | return MLX5_QP_OPTPAR_ALT_ADDR_PATH; |
| 3382 | case IB_QP_MIN_RNR_TIMER: |
| 3383 | return MLX5_QP_OPTPAR_RNR_TIMEOUT; |
| 3384 | case IB_QP_SQ_PSN: |
| 3385 | return 0; |
| 3386 | case IB_QP_MAX_DEST_RD_ATOMIC: |
| 3387 | return MLX5_QP_OPTPAR_RRA_MAX | MLX5_QP_OPTPAR_RWE | |
| 3388 | MLX5_QP_OPTPAR_RRE | MLX5_QP_OPTPAR_RAE; |
| 3389 | case IB_QP_PATH_MIG_STATE: |
| 3390 | return MLX5_QP_OPTPAR_PM_STATE; |
| 3391 | case IB_QP_CAP: |
| 3392 | return 0; |
| 3393 | case IB_QP_DEST_QPN: |
| 3394 | return 0; |
| 3395 | } |
| 3396 | return 0; |
| 3397 | } |
| 3398 | |
| 3399 | static int ib_mask_to_mlx5_opt(int ib_mask) |
| 3400 | { |
| 3401 | int result = 0; |
| 3402 | int i; |
| 3403 | |
| 3404 | for (i = 0; i < 8 * sizeof(int); i++) { |
| 3405 | if ((1 << i) & ib_mask) |
| 3406 | result |= ib_nr_to_mlx5_nr(1 << i); |
| 3407 | } |
| 3408 | |
| 3409 | return result; |
| 3410 | } |
| 3411 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3412 | static int modify_raw_packet_qp_rq( |
| 3413 | struct mlx5_ib_dev *dev, struct mlx5_ib_rq *rq, int new_state, |
| 3414 | const struct mlx5_modify_raw_qp_param *raw_qp_param, struct ib_pd *pd) |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3415 | { |
| 3416 | void *in; |
| 3417 | void *rqc; |
| 3418 | int inlen; |
| 3419 | int err; |
| 3420 | |
| 3421 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3422 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3423 | if (!in) |
| 3424 | return -ENOMEM; |
| 3425 | |
| 3426 | MLX5_SET(modify_rq_in, in, rq_state, rq->state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3427 | MLX5_SET(modify_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3428 | |
| 3429 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 3430 | MLX5_SET(rqc, rqc, state, new_state); |
| 3431 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3432 | if (raw_qp_param->set_mask & MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID) { |
| 3433 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 3434 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 3435 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3436 | MLX5_SET(rqc, rqc, counter_set_id, raw_qp_param->rq_q_ctr_id); |
| 3437 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 3438 | dev_info_once( |
| 3439 | &dev->ib_dev.dev, |
| 3440 | "RAW PACKET QP counters are not supported on current FW\n"); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3441 | } |
| 3442 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3443 | err = mlx5_core_modify_rq(dev->mdev, rq->base.mqp.qpn, in); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3444 | if (err) |
| 3445 | goto out; |
| 3446 | |
| 3447 | rq->state = new_state; |
| 3448 | |
| 3449 | out: |
| 3450 | kvfree(in); |
| 3451 | return err; |
| 3452 | } |
| 3453 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3454 | static int modify_raw_packet_qp_sq( |
| 3455 | struct mlx5_core_dev *dev, struct mlx5_ib_sq *sq, int new_state, |
| 3456 | const struct mlx5_modify_raw_qp_param *raw_qp_param, struct ib_pd *pd) |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3457 | { |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3458 | struct mlx5_ib_qp *ibqp = sq->base.container_mibqp; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3459 | struct mlx5_rate_limit old_rl = ibqp->rl; |
| 3460 | struct mlx5_rate_limit new_rl = old_rl; |
| 3461 | bool new_rate_added = false; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3462 | u16 rl_index = 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3463 | void *in; |
| 3464 | void *sqc; |
| 3465 | int inlen; |
| 3466 | int err; |
| 3467 | |
| 3468 | inlen = MLX5_ST_SZ_BYTES(modify_sq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3469 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3470 | if (!in) |
| 3471 | return -ENOMEM; |
| 3472 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3473 | MLX5_SET(modify_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3474 | MLX5_SET(modify_sq_in, in, sq_state, sq->state); |
| 3475 | |
| 3476 | sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx); |
| 3477 | MLX5_SET(sqc, sqc, state, new_state); |
| 3478 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3479 | if (raw_qp_param->set_mask & MLX5_RAW_QP_RATE_LIMIT) { |
| 3480 | if (new_state != MLX5_SQC_STATE_RDY) |
| 3481 | pr_warn("%s: Rate limit can only be changed when SQ is moving to RDY\n", |
| 3482 | __func__); |
| 3483 | else |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3484 | new_rl = raw_qp_param->rl; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3485 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3486 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3487 | if (!mlx5_rl_are_equal(&old_rl, &new_rl)) { |
| 3488 | if (new_rl.rate) { |
| 3489 | err = mlx5_rl_add_rate(dev, &rl_index, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3490 | if (err) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3491 | pr_err("Failed configuring rate limit(err %d): \ |
| 3492 | rate %u, max_burst_sz %u, typical_pkt_sz %u\n", |
| 3493 | err, new_rl.rate, new_rl.max_burst_sz, |
| 3494 | new_rl.typical_pkt_sz); |
| 3495 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3496 | goto out; |
| 3497 | } |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3498 | new_rate_added = true; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3499 | } |
| 3500 | |
| 3501 | MLX5_SET64(modify_sq_in, in, modify_bitmask, 1); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3502 | /* index 0 means no limit */ |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3503 | MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index); |
| 3504 | } |
| 3505 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3506 | err = mlx5_core_modify_sq(dev, sq->base.mqp.qpn, in); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3507 | if (err) { |
| 3508 | /* Remove new rate from table if failed */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3509 | if (new_rate_added) |
| 3510 | mlx5_rl_remove_rate(dev, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3511 | goto out; |
| 3512 | } |
| 3513 | |
| 3514 | /* Only remove the old rate after new rate was set */ |
Rafi Wiener | c8973df | 2019-10-02 15:02:43 +0300 | [diff] [blame] | 3515 | if ((old_rl.rate && !mlx5_rl_are_equal(&old_rl, &new_rl)) || |
| 3516 | (new_state != MLX5_SQC_STATE_RDY)) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3517 | mlx5_rl_remove_rate(dev, &old_rl); |
Rafi Wiener | c8973df | 2019-10-02 15:02:43 +0300 | [diff] [blame] | 3518 | if (new_state != MLX5_SQC_STATE_RDY) |
| 3519 | memset(&new_rl, 0, sizeof(new_rl)); |
| 3520 | } |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3521 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3522 | ibqp->rl = new_rl; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3523 | sq->state = new_state; |
| 3524 | |
| 3525 | out: |
| 3526 | kvfree(in); |
| 3527 | return err; |
| 3528 | } |
| 3529 | |
| 3530 | static int modify_raw_packet_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3531 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 3532 | u8 tx_affinity) |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3533 | { |
| 3534 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 3535 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 3536 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3537 | int modify_rq = !!qp->rq.wqe_cnt; |
| 3538 | int modify_sq = !!qp->sq.wqe_cnt; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3539 | int rq_state; |
| 3540 | int sq_state; |
| 3541 | int err; |
| 3542 | |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3543 | switch (raw_qp_param->operation) { |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3544 | case MLX5_CMD_OP_RST2INIT_QP: |
| 3545 | rq_state = MLX5_RQC_STATE_RDY; |
| 3546 | sq_state = MLX5_SQC_STATE_RDY; |
| 3547 | break; |
| 3548 | case MLX5_CMD_OP_2ERR_QP: |
| 3549 | rq_state = MLX5_RQC_STATE_ERR; |
| 3550 | sq_state = MLX5_SQC_STATE_ERR; |
| 3551 | break; |
| 3552 | case MLX5_CMD_OP_2RST_QP: |
| 3553 | rq_state = MLX5_RQC_STATE_RST; |
| 3554 | sq_state = MLX5_SQC_STATE_RST; |
| 3555 | break; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3556 | case MLX5_CMD_OP_RTR2RTS_QP: |
| 3557 | case MLX5_CMD_OP_RTS2RTS_QP: |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3558 | if (raw_qp_param->set_mask == |
| 3559 | MLX5_RAW_QP_RATE_LIMIT) { |
| 3560 | modify_rq = 0; |
| 3561 | sq_state = sq->state; |
| 3562 | } else { |
| 3563 | return raw_qp_param->set_mask ? -EINVAL : 0; |
| 3564 | } |
| 3565 | break; |
| 3566 | case MLX5_CMD_OP_INIT2INIT_QP: |
| 3567 | case MLX5_CMD_OP_INIT2RTR_QP: |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3568 | if (raw_qp_param->set_mask) |
| 3569 | return -EINVAL; |
| 3570 | else |
| 3571 | return 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3572 | default: |
| 3573 | WARN_ON(1); |
| 3574 | return -EINVAL; |
| 3575 | } |
| 3576 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3577 | if (modify_rq) { |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3578 | err = modify_raw_packet_qp_rq(dev, rq, rq_state, raw_qp_param, |
| 3579 | qp->ibqp.pd); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3580 | if (err) |
| 3581 | return err; |
| 3582 | } |
| 3583 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3584 | if (modify_sq) { |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3585 | struct mlx5_flow_handle *flow_rule; |
| 3586 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3587 | if (tx_affinity) { |
| 3588 | err = modify_raw_packet_tx_affinity(dev->mdev, sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3589 | tx_affinity, |
| 3590 | qp->ibqp.pd); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3591 | if (err) |
| 3592 | return err; |
| 3593 | } |
| 3594 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3595 | flow_rule = create_flow_rule_vport_sq(dev, sq, |
| 3596 | raw_qp_param->port); |
| 3597 | if (IS_ERR(flow_rule)) |
Colin Ian King | 1db8631 | 2019-04-12 11:40:17 +0100 | [diff] [blame] | 3598 | return PTR_ERR(flow_rule); |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3599 | |
| 3600 | err = modify_raw_packet_qp_sq(dev->mdev, sq, sq_state, |
| 3601 | raw_qp_param, qp->ibqp.pd); |
| 3602 | if (err) { |
| 3603 | if (flow_rule) |
| 3604 | mlx5_del_flow_rules(flow_rule); |
| 3605 | return err; |
| 3606 | } |
| 3607 | |
| 3608 | if (flow_rule) { |
| 3609 | destroy_flow_rule_vport_sq(sq); |
| 3610 | sq->flow_rule = flow_rule; |
| 3611 | } |
| 3612 | |
| 3613 | return err; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3614 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3615 | |
| 3616 | return 0; |
| 3617 | } |
| 3618 | |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3619 | static unsigned int get_tx_affinity_rr(struct mlx5_ib_dev *dev, |
| 3620 | struct ib_udata *udata) |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3621 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3622 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 3623 | udata, struct mlx5_ib_ucontext, ibucontext); |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3624 | u8 port_num = mlx5_core_native_port_num(dev->mdev) - 1; |
| 3625 | atomic_t *tx_port_affinity; |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3626 | |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3627 | if (ucontext) |
| 3628 | tx_port_affinity = &ucontext->tx_port_affinity; |
| 3629 | else |
| 3630 | tx_port_affinity = &dev->port[port_num].roce.tx_port_affinity; |
| 3631 | |
| 3632 | return (unsigned int)atomic_add_return(1, tx_port_affinity) % |
| 3633 | MLX5_MAX_PORTS + 1; |
| 3634 | } |
| 3635 | |
| 3636 | static bool qp_supports_affinity(struct ib_qp *qp) |
| 3637 | { |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3638 | if ((qp->qp_type == IB_QPT_RC) || |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3639 | (qp->qp_type == IB_QPT_UD) || |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3640 | (qp->qp_type == IB_QPT_UC) || |
| 3641 | (qp->qp_type == IB_QPT_RAW_PACKET) || |
| 3642 | (qp->qp_type == IB_QPT_XRC_INI) || |
| 3643 | (qp->qp_type == IB_QPT_XRC_TGT)) |
| 3644 | return true; |
| 3645 | return false; |
| 3646 | } |
| 3647 | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3648 | static unsigned int get_tx_affinity(struct ib_qp *qp, |
| 3649 | const struct ib_qp_attr *attr, |
| 3650 | int attr_mask, u8 init, |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3651 | struct ib_udata *udata) |
| 3652 | { |
| 3653 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 3654 | udata, struct mlx5_ib_ucontext, ibucontext); |
| 3655 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 3656 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 3657 | struct mlx5_ib_qp_base *qp_base; |
| 3658 | unsigned int tx_affinity; |
| 3659 | |
Mark Zhang | 802dcc7 | 2020-05-27 08:50:14 +0300 | [diff] [blame] | 3660 | if (!(mlx5_ib_lag_should_assign_affinity(dev) && |
| 3661 | qp_supports_affinity(qp))) |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3662 | return 0; |
| 3663 | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3664 | if (mqp->flags & MLX5_IB_QP_CREATE_SQPN_QP1) |
| 3665 | tx_affinity = mqp->gsi_lag_port; |
| 3666 | else if (init) |
| 3667 | tx_affinity = get_tx_affinity_rr(dev, udata); |
| 3668 | else if ((attr_mask & IB_QP_AV) && attr->xmit_slave) |
| 3669 | tx_affinity = |
| 3670 | mlx5_lag_get_slave_port(dev->mdev, attr->xmit_slave); |
| 3671 | else |
| 3672 | return 0; |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3673 | |
| 3674 | qp_base = &mqp->trans_qp.base; |
| 3675 | if (ucontext) |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3676 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x ucontext %p\n", |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3677 | tx_affinity, qp_base->mqp.qpn, ucontext); |
| 3678 | else |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3679 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x\n", |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3680 | tx_affinity, qp_base->mqp.qpn); |
| 3681 | return tx_affinity; |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3682 | } |
| 3683 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3684 | static int __mlx5_ib_qp_set_counter(struct ib_qp *qp, |
| 3685 | struct rdma_counter *counter) |
| 3686 | { |
| 3687 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Leon Romanovsky | 64bae2d | 2020-05-26 14:54:36 +0300 | [diff] [blame] | 3688 | u32 in[MLX5_ST_SZ_DW(rts2rts_qp_in)] = {}; |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3689 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3690 | struct mlx5_ib_qp_base *base; |
| 3691 | u32 set_id; |
Leon Romanovsky | 64bae2d | 2020-05-26 14:54:36 +0300 | [diff] [blame] | 3692 | u32 *qpc; |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3693 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3694 | if (counter) |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3695 | set_id = counter->id; |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3696 | else |
| 3697 | set_id = mlx5_ib_get_counters_id(dev, mqp->port - 1); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3698 | |
| 3699 | base = &mqp->trans_qp.base; |
Leon Romanovsky | 64bae2d | 2020-05-26 14:54:36 +0300 | [diff] [blame] | 3700 | MLX5_SET(rts2rts_qp_in, in, opcode, MLX5_CMD_OP_RTS2RTS_QP); |
| 3701 | MLX5_SET(rts2rts_qp_in, in, qpn, base->mqp.qpn); |
| 3702 | MLX5_SET(rts2rts_qp_in, in, uid, base->mqp.uid); |
| 3703 | MLX5_SET(rts2rts_qp_in, in, opt_param_mask, |
| 3704 | MLX5_QP_OPTPAR_COUNTER_SET_ID); |
| 3705 | |
| 3706 | qpc = MLX5_ADDR_OF(rts2rts_qp_in, in, qpc); |
| 3707 | MLX5_SET(qpc, qpc, counter_set_id, set_id); |
| 3708 | return mlx5_cmd_exec_in(dev->mdev, rts2rts_qp, in); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3709 | } |
| 3710 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3711 | static int __mlx5_ib_modify_qp(struct ib_qp *ibqp, |
| 3712 | const struct ib_qp_attr *attr, int attr_mask, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3713 | enum ib_qp_state cur_state, |
| 3714 | enum ib_qp_state new_state, |
| 3715 | const struct mlx5_ib_modify_qp *ucmd, |
Leon Romanovsky | 50aec2c | 2020-05-26 14:54:40 +0300 | [diff] [blame] | 3716 | struct mlx5_ib_modify_qp_resp *resp, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3717 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3718 | { |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3719 | static const u16 optab[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE] = { |
| 3720 | [MLX5_QP_STATE_RST] = { |
| 3721 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3722 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3723 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_RST2INIT_QP, |
| 3724 | }, |
| 3725 | [MLX5_QP_STATE_INIT] = { |
| 3726 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3727 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3728 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_INIT2INIT_QP, |
| 3729 | [MLX5_QP_STATE_RTR] = MLX5_CMD_OP_INIT2RTR_QP, |
| 3730 | }, |
| 3731 | [MLX5_QP_STATE_RTR] = { |
| 3732 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3733 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3734 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTR2RTS_QP, |
| 3735 | }, |
| 3736 | [MLX5_QP_STATE_RTS] = { |
| 3737 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3738 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3739 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTS2RTS_QP, |
| 3740 | }, |
| 3741 | [MLX5_QP_STATE_SQD] = { |
| 3742 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3743 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3744 | }, |
| 3745 | [MLX5_QP_STATE_SQER] = { |
| 3746 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3747 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3748 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_SQERR2RTS_QP, |
| 3749 | }, |
| 3750 | [MLX5_QP_STATE_ERR] = { |
| 3751 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3752 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3753 | } |
| 3754 | }; |
| 3755 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3756 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3757 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3758 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3759 | struct mlx5_ib_cq *send_cq, *recv_cq; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3760 | struct mlx5_ib_pd *pd; |
| 3761 | enum mlx5_qp_state mlx5_cur, mlx5_new; |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3762 | void *qpc, *pri_path, *alt_path; |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3763 | enum mlx5_qp_optpar optpar = 0; |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3764 | u32 set_id = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3765 | int mlx5_st; |
| 3766 | int err; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3767 | u16 op; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3768 | u8 tx_affinity = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3769 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 3770 | mlx5_st = to_mlx5_st(qp->type); |
Leon Romanovsky | 55de9a7 | 2018-02-25 13:39:52 +0200 | [diff] [blame] | 3771 | if (mlx5_st < 0) |
| 3772 | return -EINVAL; |
| 3773 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3774 | qpc = kzalloc(MLX5_ST_SZ_BYTES(qpc), GFP_KERNEL); |
| 3775 | if (!qpc) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3776 | return -ENOMEM; |
| 3777 | |
Leon Romanovsky | 029e88f | 2020-05-06 09:55:13 +0300 | [diff] [blame] | 3778 | pd = to_mpd(qp->ibqp.pd); |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3779 | MLX5_SET(qpc, qpc, st, mlx5_st); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3780 | |
| 3781 | if (!(attr_mask & IB_QP_PATH_MIG_STATE)) { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3782 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3783 | } else { |
| 3784 | switch (attr->path_mig_state) { |
| 3785 | case IB_MIG_MIGRATED: |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3786 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3787 | break; |
| 3788 | case IB_MIG_REARM: |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3789 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_REARM); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3790 | break; |
| 3791 | case IB_MIG_ARMED: |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3792 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_ARMED); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3793 | break; |
| 3794 | } |
| 3795 | } |
| 3796 | |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3797 | tx_affinity = get_tx_affinity(ibqp, attr, attr_mask, |
Maor Gottlieb | 5163b27 | 2020-04-30 22:21:45 +0300 | [diff] [blame] | 3798 | cur_state == IB_QPS_RESET && |
| 3799 | new_state == IB_QPS_INIT, udata); |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3800 | |
| 3801 | MLX5_SET(qpc, qpc, lag_tx_port_affinity, tx_affinity); |
| 3802 | if (tx_affinity && new_state == IB_QPS_RTR && |
| 3803 | MLX5_CAP_GEN(dev->mdev, init2_lag_tx_port_affinity)) |
| 3804 | optpar |= MLX5_QP_OPTPAR_LAG_TX_AFF; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3805 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3806 | if (is_sqp(ibqp->qp_type)) { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3807 | MLX5_SET(qpc, qpc, mtu, IB_MTU_256); |
| 3808 | MLX5_SET(qpc, qpc, log_msg_max, 8); |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3809 | } else if ((ibqp->qp_type == IB_QPT_UD && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3810 | !(qp->flags & IB_QP_CREATE_SOURCE_QPN)) || |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3811 | ibqp->qp_type == MLX5_IB_QPT_REG_UMR) { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3812 | MLX5_SET(qpc, qpc, mtu, IB_MTU_4096); |
| 3813 | MLX5_SET(qpc, qpc, log_msg_max, 12); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3814 | } else if (attr_mask & IB_QP_PATH_MTU) { |
| 3815 | if (attr->path_mtu < IB_MTU_256 || |
| 3816 | attr->path_mtu > IB_MTU_4096) { |
| 3817 | mlx5_ib_warn(dev, "invalid mtu %d\n", attr->path_mtu); |
| 3818 | err = -EINVAL; |
| 3819 | goto out; |
| 3820 | } |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3821 | MLX5_SET(qpc, qpc, mtu, attr->path_mtu); |
| 3822 | MLX5_SET(qpc, qpc, log_msg_max, |
| 3823 | MLX5_CAP_GEN(dev->mdev, log_max_msg)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | if (attr_mask & IB_QP_DEST_QPN) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3827 | MLX5_SET(qpc, qpc, remote_qpn, attr->dest_qp_num); |
| 3828 | |
| 3829 | pri_path = MLX5_ADDR_OF(qpc, qpc, primary_address_path); |
| 3830 | alt_path = MLX5_ADDR_OF(qpc, qpc, secondary_address_path); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3831 | |
| 3832 | if (attr_mask & IB_QP_PKEY_INDEX) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3833 | MLX5_SET(ads, pri_path, pkey_index, attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3834 | |
| 3835 | /* todo implement counter_index functionality */ |
| 3836 | |
| 3837 | if (is_sqp(ibqp->qp_type)) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3838 | MLX5_SET(ads, pri_path, vhca_port_num, qp->port); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3839 | |
| 3840 | if (attr_mask & IB_QP_PORT) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3841 | MLX5_SET(ads, pri_path, vhca_port_num, attr->port_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3842 | |
| 3843 | if (attr_mask & IB_QP_AV) { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3844 | err = mlx5_set_path(dev, qp, &attr->ah_attr, pri_path, |
| 3845 | attr_mask & IB_QP_PORT ? attr->port_num : |
| 3846 | qp->port, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3847 | attr_mask, 0, attr, false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3848 | if (err) |
| 3849 | goto out; |
| 3850 | } |
| 3851 | |
| 3852 | if (attr_mask & IB_QP_TIMEOUT) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3853 | MLX5_SET(ads, pri_path, ack_timeout, attr->timeout); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3854 | |
| 3855 | if (attr_mask & IB_QP_ALT_PATH) { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3856 | err = mlx5_set_path(dev, qp, &attr->alt_ah_attr, alt_path, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3857 | attr->alt_port_num, |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3858 | attr_mask | IB_QP_PKEY_INDEX | |
| 3859 | IB_QP_TIMEOUT, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3860 | 0, attr, true); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3861 | if (err) |
| 3862 | goto out; |
| 3863 | } |
| 3864 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 3865 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 3866 | &send_cq, &recv_cq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3867 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3868 | MLX5_SET(qpc, qpc, pd, pd ? pd->pdn : to_mpd(dev->devr.p0)->pdn); |
| 3869 | if (send_cq) |
| 3870 | MLX5_SET(qpc, qpc, cqn_snd, send_cq->mcq.cqn); |
| 3871 | if (recv_cq) |
| 3872 | MLX5_SET(qpc, qpc, cqn_rcv, recv_cq->mcq.cqn); |
| 3873 | |
| 3874 | MLX5_SET(qpc, qpc, log_ack_req_freq, MLX5_IB_ACK_REQ_FREQ); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3875 | |
| 3876 | if (attr_mask & IB_QP_RNR_RETRY) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3877 | MLX5_SET(qpc, qpc, rnr_retry, attr->rnr_retry); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3878 | |
| 3879 | if (attr_mask & IB_QP_RETRY_CNT) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3880 | MLX5_SET(qpc, qpc, retry_count, attr->retry_cnt); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3881 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3882 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC && attr->max_rd_atomic) |
| 3883 | MLX5_SET(qpc, qpc, log_sra_max, ilog2(attr->max_rd_atomic)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3884 | |
| 3885 | if (attr_mask & IB_QP_SQ_PSN) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3886 | MLX5_SET(qpc, qpc, next_send_psn, attr->sq_psn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3887 | |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3888 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC && attr->max_dest_rd_atomic) |
| 3889 | MLX5_SET(qpc, qpc, log_rra_max, |
| 3890 | ilog2(attr->max_dest_rd_atomic)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3891 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3892 | if (attr_mask & (IB_QP_ACCESS_FLAGS | IB_QP_MAX_DEST_RD_ATOMIC)) { |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3893 | err = set_qpc_atomic_flags(qp, attr, attr_mask, qpc); |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3894 | if (err) |
| 3895 | goto out; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3896 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3897 | |
| 3898 | if (attr_mask & IB_QP_MIN_RNR_TIMER) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3899 | MLX5_SET(qpc, qpc, min_rnr_nak, attr->min_rnr_timer); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3900 | |
| 3901 | if (attr_mask & IB_QP_RQ_PSN) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3902 | MLX5_SET(qpc, qpc, next_rcv_psn, attr->rq_psn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3903 | |
| 3904 | if (attr_mask & IB_QP_QKEY) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3905 | MLX5_SET(qpc, qpc, q_key, attr->qkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3906 | |
| 3907 | if (qp->rq.wqe_cnt && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3908 | MLX5_SET64(qpc, qpc, dbr_addr, qp->db.dma); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3909 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3910 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
| 3911 | u8 port_num = (attr_mask & IB_QP_PORT ? attr->port_num : |
| 3912 | qp->port) - 1; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3913 | |
| 3914 | /* Underlay port should be used - index 0 function per port */ |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3915 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3916 | port_num = 0; |
| 3917 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3918 | if (ibqp->counter) |
| 3919 | set_id = ibqp->counter->id; |
| 3920 | else |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3921 | set_id = mlx5_ib_get_counters_id(dev, port_num); |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3922 | MLX5_SET(qpc, qpc, counter_set_id, set_id); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3923 | } |
| 3924 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3925 | if (!ibqp->uobject && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3926 | MLX5_SET(qpc, qpc, rlky, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3927 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3928 | if (qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1) |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 3929 | MLX5_SET(qpc, qpc, deth_sqpn, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3930 | |
| 3931 | mlx5_cur = to_mlx5_state(cur_state); |
| 3932 | mlx5_new = to_mlx5_state(new_state); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3933 | |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3934 | if (mlx5_cur >= MLX5_QP_NUM_STATE || mlx5_new >= MLX5_QP_NUM_STATE || |
Dan Carpenter | 5d414b1 | 2018-03-06 13:00:31 +0300 | [diff] [blame] | 3935 | !optab[mlx5_cur][mlx5_new]) { |
| 3936 | err = -EINVAL; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3937 | goto out; |
Dan Carpenter | 5d414b1 | 2018-03-06 13:00:31 +0300 | [diff] [blame] | 3938 | } |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3939 | |
| 3940 | op = optab[mlx5_cur][mlx5_new]; |
Maor Gottlieb | cfc1a89 | 2020-04-30 22:21:46 +0300 | [diff] [blame] | 3941 | optpar |= ib_mask_to_mlx5_opt(attr_mask); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3942 | optpar &= opt_mask[mlx5_cur][mlx5_new][mlx5_st]; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3943 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3944 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3945 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3946 | struct mlx5_modify_raw_qp_param raw_qp_param = {}; |
| 3947 | |
| 3948 | raw_qp_param.operation = op; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3949 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3950 | raw_qp_param.rq_q_ctr_id = set_id; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3951 | raw_qp_param.set_mask |= MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID; |
| 3952 | } |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3953 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3954 | if (attr_mask & IB_QP_PORT) |
| 3955 | raw_qp_param.port = attr->port_num; |
| 3956 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3957 | if (attr_mask & IB_QP_RATE_LIMIT) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3958 | raw_qp_param.rl.rate = attr->rate_limit; |
| 3959 | |
| 3960 | if (ucmd->burst_info.max_burst_sz) { |
| 3961 | if (attr->rate_limit && |
| 3962 | MLX5_CAP_QOS(dev->mdev, packet_pacing_burst_bound)) { |
| 3963 | raw_qp_param.rl.max_burst_sz = |
| 3964 | ucmd->burst_info.max_burst_sz; |
| 3965 | } else { |
| 3966 | err = -EINVAL; |
| 3967 | goto out; |
| 3968 | } |
| 3969 | } |
| 3970 | |
| 3971 | if (ucmd->burst_info.typical_pkt_sz) { |
| 3972 | if (attr->rate_limit && |
| 3973 | MLX5_CAP_QOS(dev->mdev, packet_pacing_typical_size)) { |
| 3974 | raw_qp_param.rl.typical_pkt_sz = |
| 3975 | ucmd->burst_info.typical_pkt_sz; |
| 3976 | } else { |
| 3977 | err = -EINVAL; |
| 3978 | goto out; |
| 3979 | } |
| 3980 | } |
| 3981 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3982 | raw_qp_param.set_mask |= MLX5_RAW_QP_RATE_LIMIT; |
| 3983 | } |
| 3984 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3985 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, tx_affinity); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3986 | } else { |
Leon Romanovsky | 50aec2c | 2020-05-26 14:54:40 +0300 | [diff] [blame] | 3987 | if (udata) { |
| 3988 | /* For the kernel flows, the resp will stay zero */ |
| 3989 | resp->ece_options = |
| 3990 | MLX5_CAP_GEN(dev->mdev, ece_support) ? |
| 3991 | ucmd->ece_options : 0; |
| 3992 | resp->response_length = sizeof(*resp); |
| 3993 | } |
Leon Romanovsky | 5f62a52 | 2020-05-26 14:54:39 +0300 | [diff] [blame] | 3994 | err = mlx5_core_qp_modify(dev, op, optpar, qpc, &base->mqp, |
Leon Romanovsky | 50aec2c | 2020-05-26 14:54:40 +0300 | [diff] [blame] | 3995 | &resp->ece_options); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3996 | } |
| 3997 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3998 | if (err) |
| 3999 | goto out; |
| 4000 | |
| 4001 | qp->state = new_state; |
| 4002 | |
| 4003 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 4004 | qp->trans_qp.atomic_rd_en = attr->qp_access_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4005 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 4006 | qp->trans_qp.resp_depth = attr->max_dest_rd_atomic; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4007 | if (attr_mask & IB_QP_PORT) |
| 4008 | qp->port = attr->port_num; |
| 4009 | if (attr_mask & IB_QP_ALT_PATH) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 4010 | qp->trans_qp.alt_port = attr->alt_port_num; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4011 | |
| 4012 | /* |
| 4013 | * If we moved a kernel QP to RESET, clean up all old CQ |
| 4014 | * entries and reinitialize the QP. |
| 4015 | */ |
Leon Romanovsky | 75a4598 | 2018-03-11 13:51:32 +0200 | [diff] [blame] | 4016 | if (new_state == IB_QPS_RESET && |
| 4017 | !ibqp->uobject && ibqp->qp_type != IB_QPT_XRC_TGT) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 4018 | mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4019 | ibqp->srq ? to_msrq(ibqp->srq) : NULL); |
| 4020 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 4021 | mlx5_ib_cq_clean(send_cq, base->mqp.qpn, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4022 | |
| 4023 | qp->rq.head = 0; |
| 4024 | qp->rq.tail = 0; |
| 4025 | qp->sq.head = 0; |
| 4026 | qp->sq.tail = 0; |
| 4027 | qp->sq.cur_post = 0; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4028 | if (qp->sq.wqe_cnt) |
| 4029 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
Leon Romanovsky | 950bf4f | 2020-03-18 11:16:40 +0200 | [diff] [blame] | 4030 | qp->sq.last_poll = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4031 | qp->db.db[MLX5_RCV_DBR] = 0; |
| 4032 | qp->db.db[MLX5_SND_DBR] = 0; |
| 4033 | } |
| 4034 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 4035 | if ((new_state == IB_QPS_RTS) && qp->counter_pending) { |
| 4036 | err = __mlx5_ib_qp_set_counter(ibqp, ibqp->counter); |
| 4037 | if (!err) |
| 4038 | qp->counter_pending = 0; |
| 4039 | } |
| 4040 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4041 | out: |
Leon Romanovsky | f18e26a | 2020-05-26 14:54:38 +0300 | [diff] [blame] | 4042 | kfree(qpc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4043 | return err; |
| 4044 | } |
| 4045 | |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4046 | static inline bool is_valid_mask(int mask, int req, int opt) |
| 4047 | { |
| 4048 | if ((mask & req) != req) |
| 4049 | return false; |
| 4050 | |
| 4051 | if (mask & ~(req | opt)) |
| 4052 | return false; |
| 4053 | |
| 4054 | return true; |
| 4055 | } |
| 4056 | |
| 4057 | /* check valid transition for driver QP types |
| 4058 | * for now the only QP type that this function supports is DCI |
| 4059 | */ |
| 4060 | static bool modify_dci_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state new_state, |
| 4061 | enum ib_qp_attr_mask attr_mask) |
| 4062 | { |
| 4063 | int req = IB_QP_STATE; |
| 4064 | int opt = 0; |
| 4065 | |
Moni Shoua | 99ed748 | 2018-09-12 09:33:55 +0300 | [diff] [blame] | 4066 | if (new_state == IB_QPS_RESET) { |
| 4067 | return is_valid_mask(attr_mask, req, opt); |
| 4068 | } else if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4069 | req |= IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 4070 | return is_valid_mask(attr_mask, req, opt); |
| 4071 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_INIT) { |
| 4072 | opt = IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 4073 | return is_valid_mask(attr_mask, req, opt); |
| 4074 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 4075 | req |= IB_QP_PATH_MTU; |
Artemy Kovalyov | 5ec0304 | 2018-11-05 08:12:07 +0200 | [diff] [blame] | 4076 | opt = IB_QP_PKEY_INDEX | IB_QP_AV; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4077 | return is_valid_mask(attr_mask, req, opt); |
| 4078 | } else if (cur_state == IB_QPS_RTR && new_state == IB_QPS_RTS) { |
| 4079 | req |= IB_QP_TIMEOUT | IB_QP_RETRY_CNT | IB_QP_RNR_RETRY | |
| 4080 | IB_QP_MAX_QP_RD_ATOMIC | IB_QP_SQ_PSN; |
| 4081 | opt = IB_QP_MIN_RNR_TIMER; |
| 4082 | return is_valid_mask(attr_mask, req, opt); |
| 4083 | } else if (cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) { |
| 4084 | opt = IB_QP_MIN_RNR_TIMER; |
| 4085 | return is_valid_mask(attr_mask, req, opt); |
| 4086 | } else if (cur_state != IB_QPS_RESET && new_state == IB_QPS_ERR) { |
| 4087 | return is_valid_mask(attr_mask, req, opt); |
| 4088 | } |
| 4089 | return false; |
| 4090 | } |
| 4091 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4092 | /* mlx5_ib_modify_dct: modify a DCT QP |
| 4093 | * valid transitions are: |
| 4094 | * RESET to INIT: must set access_flags, pkey_index and port |
| 4095 | * INIT to RTR : must set min_rnr_timer, tclass, flow_label, |
| 4096 | * mtu, gid_index and hop_limit |
| 4097 | * Other transitions and attributes are illegal |
| 4098 | */ |
| 4099 | static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 4100 | int attr_mask, struct mlx5_ib_modify_qp *ucmd, |
| 4101 | struct ib_udata *udata) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4102 | { |
| 4103 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 4104 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4105 | enum ib_qp_state cur_state, new_state; |
| 4106 | int err = 0; |
| 4107 | int required = IB_QP_STATE; |
| 4108 | void *dctc; |
| 4109 | |
| 4110 | if (!(attr_mask & IB_QP_STATE)) |
| 4111 | return -EINVAL; |
| 4112 | |
| 4113 | cur_state = qp->state; |
| 4114 | new_state = attr->qp_state; |
| 4115 | |
| 4116 | dctc = MLX5_ADDR_OF(create_dct_in, qp->dct.in, dct_context_entry); |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 4117 | if (MLX5_CAP_GEN(dev->mdev, ece_support) && ucmd->ece_options) |
| 4118 | /* |
| 4119 | * DCT doesn't initialize QP till modify command is executed, |
| 4120 | * so we need to overwrite previously set ECE field if user |
| 4121 | * provided any value except zero, which means not set/not |
| 4122 | * valid. |
| 4123 | */ |
| 4124 | MLX5_SET(dctc, dctc, ece, ucmd->ece_options); |
| 4125 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4126 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 4127 | u16 set_id; |
| 4128 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4129 | required |= IB_QP_ACCESS_FLAGS | IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 4130 | if (!is_valid_mask(attr_mask, required, 0)) |
| 4131 | return -EINVAL; |
| 4132 | |
| 4133 | if (attr->port_num == 0 || |
| 4134 | attr->port_num > MLX5_CAP_GEN(dev->mdev, num_ports)) { |
| 4135 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 4136 | attr->port_num, dev->num_ports); |
| 4137 | return -EINVAL; |
| 4138 | } |
| 4139 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_READ) |
| 4140 | MLX5_SET(dctc, dctc, rre, 1); |
| 4141 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE) |
| 4142 | MLX5_SET(dctc, dctc, rwe, 1); |
| 4143 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 4144 | int atomic_mode; |
| 4145 | |
| 4146 | atomic_mode = get_atomic_mode(dev, MLX5_IB_QPT_DCT); |
| 4147 | if (atomic_mode < 0) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4148 | return -EOPNOTSUPP; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 4149 | |
| 4150 | MLX5_SET(dctc, dctc, atomic_mode, atomic_mode); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4151 | MLX5_SET(dctc, dctc, rae, 1); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4152 | } |
| 4153 | MLX5_SET(dctc, dctc, pkey_index, attr->pkey_index); |
| 4154 | MLX5_SET(dctc, dctc, port, attr->port_num); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 4155 | |
| 4156 | set_id = mlx5_ib_get_counters_id(dev, attr->port_num - 1); |
| 4157 | MLX5_SET(dctc, dctc, counter_set_id, set_id); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4158 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 4159 | struct mlx5_ib_modify_qp_resp resp = {}; |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 4160 | u32 out[MLX5_ST_SZ_DW(create_dct_out)] = {}; |
| 4161 | u32 min_resp_len = offsetofend(typeof(resp), dctn); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4162 | |
| 4163 | if (udata->outlen < min_resp_len) |
| 4164 | return -EINVAL; |
| 4165 | resp.response_length = min_resp_len; |
| 4166 | |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 4167 | /* |
| 4168 | * If we don't have enough space for the ECE options, |
| 4169 | * simply indicate it with resp.response_length. |
| 4170 | */ |
| 4171 | resp.response_length = (udata->outlen < sizeof(resp)) ? |
| 4172 | min_resp_len : |
| 4173 | sizeof(resp); |
| 4174 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4175 | required |= IB_QP_MIN_RNR_TIMER | IB_QP_AV | IB_QP_PATH_MTU; |
| 4176 | if (!is_valid_mask(attr_mask, required, 0)) |
| 4177 | return -EINVAL; |
| 4178 | MLX5_SET(dctc, dctc, min_rnr_nak, attr->min_rnr_timer); |
| 4179 | MLX5_SET(dctc, dctc, tclass, attr->ah_attr.grh.traffic_class); |
| 4180 | MLX5_SET(dctc, dctc, flow_label, attr->ah_attr.grh.flow_label); |
| 4181 | MLX5_SET(dctc, dctc, mtu, attr->path_mtu); |
| 4182 | MLX5_SET(dctc, dctc, my_addr_index, attr->ah_attr.grh.sgid_index); |
| 4183 | MLX5_SET(dctc, dctc, hop_limit, attr->ah_attr.grh.hop_limit); |
| 4184 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 4185 | err = mlx5_core_create_dct(dev, &qp->dct.mdct, qp->dct.in, |
Yishai Hadas | c5ae195 | 2019-03-06 19:21:42 +0200 | [diff] [blame] | 4186 | MLX5_ST_SZ_BYTES(create_dct_in), out, |
| 4187 | sizeof(out)); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4188 | if (err) |
| 4189 | return err; |
| 4190 | resp.dctn = qp->dct.mdct.mqp.qpn; |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 4191 | if (MLX5_CAP_GEN(dev->mdev, ece_support)) |
| 4192 | resp.ece_options = MLX5_GET(create_dct_out, out, ece); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4193 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 4194 | if (err) { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 4195 | mlx5_core_destroy_dct(dev, &qp->dct.mdct); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4196 | return err; |
| 4197 | } |
| 4198 | } else { |
| 4199 | mlx5_ib_warn(dev, "Modify DCT: Invalid transition from %d to %d\n", cur_state, new_state); |
| 4200 | return -EINVAL; |
| 4201 | } |
| 4202 | if (err) |
| 4203 | qp->state = IB_QPS_ERR; |
| 4204 | else |
| 4205 | qp->state = new_state; |
| 4206 | return err; |
| 4207 | } |
| 4208 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4209 | int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 4210 | int attr_mask, struct ib_udata *udata) |
| 4211 | { |
| 4212 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Leon Romanovsky | 50aec2c | 2020-05-26 14:54:40 +0300 | [diff] [blame] | 4213 | struct mlx5_ib_modify_qp_resp resp = {}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4214 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4215 | struct mlx5_ib_modify_qp ucmd = {}; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4216 | enum ib_qp_type qp_type; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4217 | enum ib_qp_state cur_state, new_state; |
| 4218 | int err = -EINVAL; |
| 4219 | int port; |
| 4220 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 4221 | if (ibqp->rwq_ind_tbl) |
| 4222 | return -ENOSYS; |
| 4223 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4224 | if (udata && udata->inlen) { |
Leon Romanovsky | 5f62a52 | 2020-05-26 14:54:39 +0300 | [diff] [blame] | 4225 | if (udata->inlen < offsetofend(typeof(ucmd), ece_options)) |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4226 | return -EINVAL; |
| 4227 | |
| 4228 | if (udata->inlen > sizeof(ucmd) && |
| 4229 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 4230 | udata->inlen - sizeof(ucmd))) |
| 4231 | return -EOPNOTSUPP; |
| 4232 | |
| 4233 | if (ib_copy_from_udata(&ucmd, udata, |
| 4234 | min(udata->inlen, sizeof(ucmd)))) |
| 4235 | return -EFAULT; |
| 4236 | |
| 4237 | if (ucmd.comp_mask || |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4238 | memchr_inv(&ucmd.burst_info.reserved, 0, |
| 4239 | sizeof(ucmd.burst_info.reserved))) |
| 4240 | return -EOPNOTSUPP; |
Leon Romanovsky | 5f62a52 | 2020-05-26 14:54:39 +0300 | [diff] [blame] | 4241 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4242 | } |
| 4243 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4244 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 4245 | return mlx5_ib_gsi_modify_qp(ibqp, attr, attr_mask); |
| 4246 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 4247 | qp_type = (unlikely(ibqp->qp_type == MLX5_IB_QPT_HW_GSI)) ? IB_QPT_GSI : |
| 4248 | qp->type; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4249 | |
Leon Romanovsky | a645a89 | 2020-06-02 15:55:48 +0300 | [diff] [blame] | 4250 | if (qp_type == MLX5_IB_QPT_DCT) |
| 4251 | return mlx5_ib_modify_dct(ibqp, attr, attr_mask, &ucmd, udata); |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4252 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4253 | mutex_lock(&qp->mutex); |
| 4254 | |
| 4255 | cur_state = attr_mask & IB_QP_CUR_STATE ? attr->cur_qp_state : qp->state; |
| 4256 | new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; |
| 4257 | |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 4258 | if (!(cur_state == new_state && cur_state == IB_QPS_RESET)) { |
| 4259 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 4260 | } |
| 4261 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 4262 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 4263 | if (attr_mask & ~(IB_QP_STATE | IB_QP_CUR_STATE)) { |
| 4264 | mlx5_ib_dbg(dev, "invalid attr_mask 0x%x when underlay QP is used\n", |
| 4265 | attr_mask); |
| 4266 | goto out; |
| 4267 | } |
| 4268 | } else if (qp_type != MLX5_IB_QPT_REG_UMR && |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4269 | qp_type != MLX5_IB_QPT_DCI && |
Kamal Heib | d31131b | 2018-10-02 16:11:21 +0300 | [diff] [blame] | 4270 | !ib_modify_qp_is_ok(cur_state, new_state, qp_type, |
| 4271 | attr_mask)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4272 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 4273 | cur_state, new_state, ibqp->qp_type, attr_mask); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4274 | goto out; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4275 | } else if (qp_type == MLX5_IB_QPT_DCI && |
| 4276 | !modify_dci_qp_is_ok(cur_state, new_state, attr_mask)) { |
| 4277 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 4278 | cur_state, new_state, qp_type, attr_mask); |
| 4279 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4280 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4281 | |
| 4282 | if ((attr_mask & IB_QP_PORT) && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4283 | (attr->port_num == 0 || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4284 | attr->port_num > dev->num_ports)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4285 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 4286 | attr->port_num, dev->num_ports); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4287 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4288 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4289 | |
| 4290 | if (attr_mask & IB_QP_PKEY_INDEX) { |
| 4291 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4292 | if (attr->pkey_index >= |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4293 | dev->mdev->port_caps[port - 1].pkey_table_len) { |
| 4294 | mlx5_ib_dbg(dev, "invalid pkey index %d\n", |
| 4295 | attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4296 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4297 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4301 | attr->max_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4302 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_res_qp))) { |
| 4303 | mlx5_ib_dbg(dev, "invalid max_rd_atomic value %d\n", |
| 4304 | attr->max_rd_atomic); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4305 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4306 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4307 | |
| 4308 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4309 | attr->max_dest_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4310 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_req_qp))) { |
| 4311 | mlx5_ib_dbg(dev, "invalid max_dest_rd_atomic value %d\n", |
| 4312 | attr->max_dest_rd_atomic); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4313 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4314 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4315 | |
| 4316 | if (cur_state == new_state && cur_state == IB_QPS_RESET) { |
| 4317 | err = 0; |
| 4318 | goto out; |
| 4319 | } |
| 4320 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4321 | err = __mlx5_ib_modify_qp(ibqp, attr, attr_mask, cur_state, |
Leon Romanovsky | 50aec2c | 2020-05-26 14:54:40 +0300 | [diff] [blame] | 4322 | new_state, &ucmd, &resp, udata); |
| 4323 | |
| 4324 | /* resp.response_length is set in ECE supported flows only */ |
| 4325 | if (!err && resp.response_length && |
| 4326 | udata->outlen >= resp.response_length) |
Leon Romanovsky | 6512f11 | 2020-06-02 15:55:46 +0300 | [diff] [blame] | 4327 | /* Return -EFAULT to the user and expect him to destroy QP. */ |
| 4328 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4329 | |
| 4330 | out: |
| 4331 | mutex_unlock(&qp->mutex); |
| 4332 | return err; |
| 4333 | } |
| 4334 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4335 | static inline enum ib_qp_state to_ib_qp_state(enum mlx5_qp_state mlx5_state) |
| 4336 | { |
| 4337 | switch (mlx5_state) { |
| 4338 | case MLX5_QP_STATE_RST: return IB_QPS_RESET; |
| 4339 | case MLX5_QP_STATE_INIT: return IB_QPS_INIT; |
| 4340 | case MLX5_QP_STATE_RTR: return IB_QPS_RTR; |
| 4341 | case MLX5_QP_STATE_RTS: return IB_QPS_RTS; |
| 4342 | case MLX5_QP_STATE_SQ_DRAINING: |
| 4343 | case MLX5_QP_STATE_SQD: return IB_QPS_SQD; |
| 4344 | case MLX5_QP_STATE_SQER: return IB_QPS_SQE; |
| 4345 | case MLX5_QP_STATE_ERR: return IB_QPS_ERR; |
| 4346 | default: return -1; |
| 4347 | } |
| 4348 | } |
| 4349 | |
| 4350 | static inline enum ib_mig_state to_ib_mig_state(int mlx5_mig_state) |
| 4351 | { |
| 4352 | switch (mlx5_mig_state) { |
| 4353 | case MLX5_QP_PM_ARMED: return IB_MIG_ARMED; |
| 4354 | case MLX5_QP_PM_REARM: return IB_MIG_REARM; |
| 4355 | case MLX5_QP_PM_MIGRATED: return IB_MIG_MIGRATED; |
| 4356 | default: return -1; |
| 4357 | } |
| 4358 | } |
| 4359 | |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 4360 | static void to_rdma_ah_attr(struct mlx5_ib_dev *ibdev, |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4361 | struct rdma_ah_attr *ah_attr, void *path) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4362 | { |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4363 | int port = MLX5_GET(ads, path, vhca_port_num); |
| 4364 | int static_rate; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4365 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 4366 | memset(ah_attr, 0, sizeof(*ah_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4367 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4368 | if (!port || port > ibdev->num_ports) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4369 | return; |
| 4370 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4371 | ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, port); |
Leon Romanovsky | ae59c3f | 2018-01-12 07:58:39 +0200 | [diff] [blame] | 4372 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4373 | rdma_ah_set_port_num(ah_attr, port); |
| 4374 | rdma_ah_set_sl(ah_attr, MLX5_GET(ads, path, sl)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4375 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4376 | rdma_ah_set_dlid(ah_attr, MLX5_GET(ads, path, rlid)); |
| 4377 | rdma_ah_set_path_bits(ah_attr, MLX5_GET(ads, path, mlid)); |
Aharon Landau | 2d7e3ff | 2020-04-13 16:20:28 +0300 | [diff] [blame] | 4378 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4379 | static_rate = MLX5_GET(ads, path, stat_rate); |
| 4380 | rdma_ah_set_static_rate(ah_attr, static_rate ? static_rate - 5 : 0); |
| 4381 | if (MLX5_GET(ads, path, grh) || |
Aharon Landau | 2d7e3ff | 2020-04-13 16:20:28 +0300 | [diff] [blame] | 4382 | ah_attr->type == RDMA_AH_ATTR_TYPE_ROCE) { |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4383 | rdma_ah_set_grh(ah_attr, NULL, MLX5_GET(ads, path, flow_label), |
| 4384 | MLX5_GET(ads, path, src_addr_index), |
| 4385 | MLX5_GET(ads, path, hop_limit), |
| 4386 | MLX5_GET(ads, path, tclass)); |
| 4387 | memcpy(ah_attr, MLX5_ADDR_OF(ads, path, rgid_rip), |
| 4388 | MLX5_FLD_SZ_BYTES(ads, rgid_rip)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4389 | } |
| 4390 | } |
| 4391 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4392 | static int query_raw_packet_qp_sq_state(struct mlx5_ib_dev *dev, |
| 4393 | struct mlx5_ib_sq *sq, |
| 4394 | u8 *sq_state) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4395 | { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4396 | int err; |
| 4397 | |
Eran Ben Elisha | 2816077 | 2017-12-26 15:17:05 +0200 | [diff] [blame] | 4398 | err = mlx5_core_query_sq_state(dev->mdev, sq->base.mqp.qpn, sq_state); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4399 | if (err) |
| 4400 | goto out; |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4401 | sq->state = *sq_state; |
| 4402 | |
| 4403 | out: |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4404 | return err; |
| 4405 | } |
| 4406 | |
| 4407 | static int query_raw_packet_qp_rq_state(struct mlx5_ib_dev *dev, |
| 4408 | struct mlx5_ib_rq *rq, |
| 4409 | u8 *rq_state) |
| 4410 | { |
| 4411 | void *out; |
| 4412 | void *rqc; |
| 4413 | int inlen; |
| 4414 | int err; |
| 4415 | |
| 4416 | inlen = MLX5_ST_SZ_BYTES(query_rq_out); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 4417 | out = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4418 | if (!out) |
| 4419 | return -ENOMEM; |
| 4420 | |
| 4421 | err = mlx5_core_query_rq(dev->mdev, rq->base.mqp.qpn, out); |
| 4422 | if (err) |
| 4423 | goto out; |
| 4424 | |
| 4425 | rqc = MLX5_ADDR_OF(query_rq_out, out, rq_context); |
| 4426 | *rq_state = MLX5_GET(rqc, rqc, state); |
| 4427 | rq->state = *rq_state; |
| 4428 | |
| 4429 | out: |
| 4430 | kvfree(out); |
| 4431 | return err; |
| 4432 | } |
| 4433 | |
| 4434 | static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, |
| 4435 | struct mlx5_ib_qp *qp, u8 *qp_state) |
| 4436 | { |
| 4437 | static const u8 sqrq_trans[MLX5_RQ_NUM_STATE][MLX5_SQ_NUM_STATE] = { |
| 4438 | [MLX5_RQC_STATE_RST] = { |
| 4439 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 4440 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 4441 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE_BAD, |
| 4442 | [MLX5_SQ_STATE_NA] = IB_QPS_RESET, |
| 4443 | }, |
| 4444 | [MLX5_RQC_STATE_RDY] = { |
| 4445 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 4446 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 4447 | [MLX5_SQC_STATE_ERR] = IB_QPS_SQE, |
| 4448 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE, |
| 4449 | }, |
| 4450 | [MLX5_RQC_STATE_ERR] = { |
| 4451 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 4452 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 4453 | [MLX5_SQC_STATE_ERR] = IB_QPS_ERR, |
| 4454 | [MLX5_SQ_STATE_NA] = IB_QPS_ERR, |
| 4455 | }, |
| 4456 | [MLX5_RQ_STATE_NA] = { |
| 4457 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 4458 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 4459 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE, |
| 4460 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE_BAD, |
| 4461 | }, |
| 4462 | }; |
| 4463 | |
| 4464 | *qp_state = sqrq_trans[rq_state][sq_state]; |
| 4465 | |
| 4466 | if (*qp_state == MLX5_QP_STATE_BAD) { |
| 4467 | WARN(1, "Buggy Raw Packet QP state, SQ 0x%x state: 0x%x, RQ 0x%x state: 0x%x", |
| 4468 | qp->raw_packet_qp.sq.base.mqp.qpn, sq_state, |
| 4469 | qp->raw_packet_qp.rq.base.mqp.qpn, rq_state); |
| 4470 | return -EINVAL; |
| 4471 | } |
| 4472 | |
| 4473 | if (*qp_state == MLX5_QP_STATE) |
| 4474 | *qp_state = qp->state; |
| 4475 | |
| 4476 | return 0; |
| 4477 | } |
| 4478 | |
| 4479 | static int query_raw_packet_qp_state(struct mlx5_ib_dev *dev, |
| 4480 | struct mlx5_ib_qp *qp, |
| 4481 | u8 *raw_packet_qp_state) |
| 4482 | { |
| 4483 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 4484 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 4485 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 4486 | int err; |
| 4487 | u8 sq_state = MLX5_SQ_STATE_NA; |
| 4488 | u8 rq_state = MLX5_RQ_STATE_NA; |
| 4489 | |
| 4490 | if (qp->sq.wqe_cnt) { |
| 4491 | err = query_raw_packet_qp_sq_state(dev, sq, &sq_state); |
| 4492 | if (err) |
| 4493 | return err; |
| 4494 | } |
| 4495 | |
| 4496 | if (qp->rq.wqe_cnt) { |
| 4497 | err = query_raw_packet_qp_rq_state(dev, rq, &rq_state); |
| 4498 | if (err) |
| 4499 | return err; |
| 4500 | } |
| 4501 | |
| 4502 | return sqrq_state_to_qp_state(sq_state, rq_state, qp, |
| 4503 | raw_packet_qp_state); |
| 4504 | } |
| 4505 | |
| 4506 | static int query_qp_attr(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 4507 | struct ib_qp_attr *qp_attr) |
| 4508 | { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 4509 | int outlen = MLX5_ST_SZ_BYTES(query_qp_out); |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4510 | void *qpc, *pri_path, *alt_path; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 4511 | u32 *outb; |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4512 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4513 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 4514 | outb = kzalloc(outlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4515 | if (!outb) |
| 4516 | return -ENOMEM; |
| 4517 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 4518 | err = mlx5_core_qp_query(dev, &qp->trans_qp.base.mqp, outb, outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4519 | if (err) |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4520 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4521 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4522 | qpc = MLX5_ADDR_OF(query_qp_out, outb, qpc); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 4523 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4524 | qp->state = to_ib_qp_state(MLX5_GET(qpc, qpc, state)); |
| 4525 | if (MLX5_GET(qpc, qpc, state) == MLX5_QP_STATE_SQ_DRAINING) |
| 4526 | qp_attr->sq_draining = 1; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4527 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4528 | qp_attr->path_mtu = MLX5_GET(qpc, qpc, mtu); |
| 4529 | qp_attr->path_mig_state = to_ib_mig_state(MLX5_GET(qpc, qpc, pm_state)); |
| 4530 | qp_attr->qkey = MLX5_GET(qpc, qpc, q_key); |
| 4531 | qp_attr->rq_psn = MLX5_GET(qpc, qpc, next_rcv_psn); |
| 4532 | qp_attr->sq_psn = MLX5_GET(qpc, qpc, next_send_psn); |
| 4533 | qp_attr->dest_qp_num = MLX5_GET(qpc, qpc, remote_qpn); |
| 4534 | |
| 4535 | if (MLX5_GET(qpc, qpc, rre)) |
| 4536 | qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_READ; |
| 4537 | if (MLX5_GET(qpc, qpc, rwe)) |
| 4538 | qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_WRITE; |
| 4539 | if (MLX5_GET(qpc, qpc, rae)) |
| 4540 | qp_attr->qp_access_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 4541 | |
| 4542 | qp_attr->max_rd_atomic = 1 << MLX5_GET(qpc, qpc, log_sra_max); |
| 4543 | qp_attr->max_dest_rd_atomic = 1 << MLX5_GET(qpc, qpc, log_rra_max); |
| 4544 | qp_attr->min_rnr_timer = MLX5_GET(qpc, qpc, min_rnr_nak); |
| 4545 | qp_attr->retry_cnt = MLX5_GET(qpc, qpc, retry_count); |
| 4546 | qp_attr->rnr_retry = MLX5_GET(qpc, qpc, rnr_retry); |
| 4547 | |
| 4548 | pri_path = MLX5_ADDR_OF(qpc, qpc, primary_address_path); |
| 4549 | alt_path = MLX5_ADDR_OF(qpc, qpc, secondary_address_path); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4550 | |
| 4551 | if (qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC) { |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4552 | to_rdma_ah_attr(dev, &qp_attr->ah_attr, pri_path); |
| 4553 | to_rdma_ah_attr(dev, &qp_attr->alt_ah_attr, alt_path); |
| 4554 | qp_attr->alt_pkey_index = MLX5_GET(ads, alt_path, pkey_index); |
| 4555 | qp_attr->alt_port_num = MLX5_GET(ads, alt_path, vhca_port_num); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4556 | } |
| 4557 | |
Leon Romanovsky | 70bd7fb | 2020-05-26 14:54:37 +0300 | [diff] [blame] | 4558 | qp_attr->pkey_index = MLX5_GET(ads, pri_path, pkey_index); |
| 4559 | qp_attr->port_num = MLX5_GET(ads, pri_path, vhca_port_num); |
| 4560 | qp_attr->timeout = MLX5_GET(ads, pri_path, ack_timeout); |
| 4561 | qp_attr->alt_timeout = MLX5_GET(ads, alt_path, ack_timeout); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4562 | |
| 4563 | out: |
| 4564 | kfree(outb); |
| 4565 | return err; |
| 4566 | } |
| 4567 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4568 | static int mlx5_ib_dct_query_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *mqp, |
| 4569 | struct ib_qp_attr *qp_attr, int qp_attr_mask, |
| 4570 | struct ib_qp_init_attr *qp_init_attr) |
| 4571 | { |
| 4572 | struct mlx5_core_dct *dct = &mqp->dct.mdct; |
| 4573 | u32 *out; |
| 4574 | u32 access_flags = 0; |
| 4575 | int outlen = MLX5_ST_SZ_BYTES(query_dct_out); |
| 4576 | void *dctc; |
| 4577 | int err; |
| 4578 | int supported_mask = IB_QP_STATE | |
| 4579 | IB_QP_ACCESS_FLAGS | |
| 4580 | IB_QP_PORT | |
| 4581 | IB_QP_MIN_RNR_TIMER | |
| 4582 | IB_QP_AV | |
| 4583 | IB_QP_PATH_MTU | |
| 4584 | IB_QP_PKEY_INDEX; |
| 4585 | |
| 4586 | if (qp_attr_mask & ~supported_mask) |
| 4587 | return -EINVAL; |
| 4588 | if (mqp->state != IB_QPS_RTR) |
| 4589 | return -EINVAL; |
| 4590 | |
| 4591 | out = kzalloc(outlen, GFP_KERNEL); |
| 4592 | if (!out) |
| 4593 | return -ENOMEM; |
| 4594 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 4595 | err = mlx5_core_dct_query(dev, dct, out, outlen); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4596 | if (err) |
| 4597 | goto out; |
| 4598 | |
| 4599 | dctc = MLX5_ADDR_OF(query_dct_out, out, dct_context_entry); |
| 4600 | |
| 4601 | if (qp_attr_mask & IB_QP_STATE) |
| 4602 | qp_attr->qp_state = IB_QPS_RTR; |
| 4603 | |
| 4604 | if (qp_attr_mask & IB_QP_ACCESS_FLAGS) { |
| 4605 | if (MLX5_GET(dctc, dctc, rre)) |
| 4606 | access_flags |= IB_ACCESS_REMOTE_READ; |
| 4607 | if (MLX5_GET(dctc, dctc, rwe)) |
| 4608 | access_flags |= IB_ACCESS_REMOTE_WRITE; |
| 4609 | if (MLX5_GET(dctc, dctc, rae)) |
| 4610 | access_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 4611 | qp_attr->qp_access_flags = access_flags; |
| 4612 | } |
| 4613 | |
| 4614 | if (qp_attr_mask & IB_QP_PORT) |
| 4615 | qp_attr->port_num = MLX5_GET(dctc, dctc, port); |
| 4616 | if (qp_attr_mask & IB_QP_MIN_RNR_TIMER) |
| 4617 | qp_attr->min_rnr_timer = MLX5_GET(dctc, dctc, min_rnr_nak); |
| 4618 | if (qp_attr_mask & IB_QP_AV) { |
| 4619 | qp_attr->ah_attr.grh.traffic_class = MLX5_GET(dctc, dctc, tclass); |
| 4620 | qp_attr->ah_attr.grh.flow_label = MLX5_GET(dctc, dctc, flow_label); |
| 4621 | qp_attr->ah_attr.grh.sgid_index = MLX5_GET(dctc, dctc, my_addr_index); |
| 4622 | qp_attr->ah_attr.grh.hop_limit = MLX5_GET(dctc, dctc, hop_limit); |
| 4623 | } |
| 4624 | if (qp_attr_mask & IB_QP_PATH_MTU) |
| 4625 | qp_attr->path_mtu = MLX5_GET(dctc, dctc, mtu); |
| 4626 | if (qp_attr_mask & IB_QP_PKEY_INDEX) |
| 4627 | qp_attr->pkey_index = MLX5_GET(dctc, dctc, pkey_index); |
| 4628 | out: |
| 4629 | kfree(out); |
| 4630 | return err; |
| 4631 | } |
| 4632 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4633 | int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, |
| 4634 | int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr) |
| 4635 | { |
| 4636 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 4637 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 4638 | int err = 0; |
| 4639 | u8 raw_packet_qp_state; |
| 4640 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 4641 | if (ibqp->rwq_ind_tbl) |
| 4642 | return -ENOSYS; |
| 4643 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4644 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 4645 | return mlx5_ib_gsi_query_qp(ibqp, qp_attr, qp_attr_mask, |
| 4646 | qp_init_attr); |
| 4647 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 4648 | /* Not all of output fields are applicable, make sure to zero them */ |
| 4649 | memset(qp_init_attr, 0, sizeof(*qp_init_attr)); |
| 4650 | memset(qp_attr, 0, sizeof(*qp_attr)); |
| 4651 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 4652 | if (unlikely(qp->type == MLX5_IB_QPT_DCT)) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4653 | return mlx5_ib_dct_query_qp(dev, qp, qp_attr, |
| 4654 | qp_attr_mask, qp_init_attr); |
| 4655 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4656 | mutex_lock(&qp->mutex); |
| 4657 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 4658 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 4659 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 4660 | err = query_raw_packet_qp_state(dev, qp, &raw_packet_qp_state); |
| 4661 | if (err) |
| 4662 | goto out; |
| 4663 | qp->state = raw_packet_qp_state; |
| 4664 | qp_attr->port_num = 1; |
| 4665 | } else { |
| 4666 | err = query_qp_attr(dev, qp, qp_attr); |
| 4667 | if (err) |
| 4668 | goto out; |
| 4669 | } |
| 4670 | |
| 4671 | qp_attr->qp_state = qp->state; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4672 | qp_attr->cur_qp_state = qp_attr->qp_state; |
| 4673 | qp_attr->cap.max_recv_wr = qp->rq.wqe_cnt; |
| 4674 | qp_attr->cap.max_recv_sge = qp->rq.max_gs; |
| 4675 | |
| 4676 | if (!ibqp->uobject) { |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 4677 | qp_attr->cap.max_send_wr = qp->sq.max_post; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4678 | qp_attr->cap.max_send_sge = qp->sq.max_gs; |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 4679 | qp_init_attr->qp_context = ibqp->qp_context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4680 | } else { |
| 4681 | qp_attr->cap.max_send_wr = 0; |
| 4682 | qp_attr->cap.max_send_sge = 0; |
| 4683 | } |
| 4684 | |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 4685 | qp_init_attr->qp_type = ibqp->qp_type; |
| 4686 | qp_init_attr->recv_cq = ibqp->recv_cq; |
| 4687 | qp_init_attr->send_cq = ibqp->send_cq; |
| 4688 | qp_init_attr->srq = ibqp->srq; |
| 4689 | qp_attr->cap.max_inline_data = qp->max_inline_data; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4690 | |
| 4691 | qp_init_attr->cap = qp_attr->cap; |
| 4692 | |
Leon Romanovsky | a8f3ea6 | 2020-04-27 18:46:17 +0300 | [diff] [blame] | 4693 | qp_init_attr->create_flags = qp->flags; |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 4694 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4695 | qp_init_attr->sq_sig_type = qp->sq_signal_bits & MLX5_WQE_CTRL_CQ_UPDATE ? |
| 4696 | IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR; |
| 4697 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4698 | out: |
| 4699 | mutex_unlock(&qp->mutex); |
| 4700 | return err; |
| 4701 | } |
| 4702 | |
Leon Romanovsky | 28ad5f65 | 2020-06-30 13:18:54 +0300 | [diff] [blame^] | 4703 | int mlx5_ib_alloc_xrcd(struct ib_xrcd *ibxrcd, struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4704 | { |
Leon Romanovsky | 28ad5f65 | 2020-06-30 13:18:54 +0300 | [diff] [blame^] | 4705 | struct mlx5_ib_dev *dev = to_mdev(ibxrcd->device); |
| 4706 | struct mlx5_ib_xrcd *xrcd = to_mxrcd(ibxrcd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4707 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4708 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
Leon Romanovsky | 28ad5f65 | 2020-06-30 13:18:54 +0300 | [diff] [blame^] | 4709 | return -EOPNOTSUPP; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4710 | |
Leon Romanovsky | 28ad5f65 | 2020-06-30 13:18:54 +0300 | [diff] [blame^] | 4711 | return mlx5_cmd_xrcd_alloc(dev->mdev, &xrcd->xrcdn, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4712 | } |
| 4713 | |
Leon Romanovsky | 28ad5f65 | 2020-06-30 13:18:54 +0300 | [diff] [blame^] | 4714 | void mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4715 | { |
| 4716 | struct mlx5_ib_dev *dev = to_mdev(xrcd->device); |
| 4717 | u32 xrcdn = to_mxrcd(xrcd)->xrcdn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4718 | |
Leon Romanovsky | 28ad5f65 | 2020-06-30 13:18:54 +0300 | [diff] [blame^] | 4719 | mlx5_cmd_xrcd_dealloc(dev->mdev, xrcdn, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4720 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4721 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 4722 | static void mlx5_ib_wq_event(struct mlx5_core_qp *core_qp, int type) |
| 4723 | { |
| 4724 | struct mlx5_ib_rwq *rwq = to_mibrwq(core_qp); |
| 4725 | struct mlx5_ib_dev *dev = to_mdev(rwq->ibwq.device); |
| 4726 | struct ib_event event; |
| 4727 | |
| 4728 | if (rwq->ibwq.event_handler) { |
| 4729 | event.device = rwq->ibwq.device; |
| 4730 | event.element.wq = &rwq->ibwq; |
| 4731 | switch (type) { |
| 4732 | case MLX5_EVENT_TYPE_WQ_CATAS_ERROR: |
| 4733 | event.event = IB_EVENT_WQ_FATAL; |
| 4734 | break; |
| 4735 | default: |
| 4736 | mlx5_ib_warn(dev, "Unexpected event type %d on WQ %06x\n", type, core_qp->qpn); |
| 4737 | return; |
| 4738 | } |
| 4739 | |
| 4740 | rwq->ibwq.event_handler(&event, rwq->ibwq.wq_context); |
| 4741 | } |
| 4742 | } |
| 4743 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4744 | static int set_delay_drop(struct mlx5_ib_dev *dev) |
| 4745 | { |
| 4746 | int err = 0; |
| 4747 | |
| 4748 | mutex_lock(&dev->delay_drop.lock); |
| 4749 | if (dev->delay_drop.activate) |
| 4750 | goto out; |
| 4751 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 4752 | err = mlx5_core_set_delay_drop(dev, dev->delay_drop.timeout); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4753 | if (err) |
| 4754 | goto out; |
| 4755 | |
| 4756 | dev->delay_drop.activate = true; |
| 4757 | out: |
| 4758 | mutex_unlock(&dev->delay_drop.lock); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 4759 | |
| 4760 | if (!err) |
| 4761 | atomic_inc(&dev->delay_drop.rqs_cnt); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4762 | return err; |
| 4763 | } |
| 4764 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4765 | static int create_rq(struct mlx5_ib_rwq *rwq, struct ib_pd *pd, |
| 4766 | struct ib_wq_init_attr *init_attr) |
| 4767 | { |
| 4768 | struct mlx5_ib_dev *dev; |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 4769 | int has_net_offloads; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4770 | __be64 *rq_pas0; |
| 4771 | void *in; |
| 4772 | void *rqc; |
| 4773 | void *wq; |
| 4774 | int inlen; |
| 4775 | int err; |
| 4776 | |
| 4777 | dev = to_mdev(pd->device); |
| 4778 | |
| 4779 | inlen = MLX5_ST_SZ_BYTES(create_rq_in) + sizeof(u64) * rwq->rq_num_pas; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 4780 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4781 | if (!in) |
| 4782 | return -ENOMEM; |
| 4783 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 4784 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4785 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
| 4786 | MLX5_SET(rqc, rqc, mem_rq_type, |
| 4787 | MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 4788 | MLX5_SET(rqc, rqc, user_index, rwq->user_index); |
| 4789 | MLX5_SET(rqc, rqc, cqn, to_mcq(init_attr->cq)->mcq.cqn); |
| 4790 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 4791 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 4792 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4793 | MLX5_SET(wq, wq, wq_type, |
| 4794 | rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ ? |
| 4795 | MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ : MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 4796 | if (init_attr->create_flags & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 4797 | if (!MLX5_CAP_GEN(dev->mdev, end_pad)) { |
| 4798 | mlx5_ib_dbg(dev, "Scatter end padding is not supported\n"); |
| 4799 | err = -EOPNOTSUPP; |
| 4800 | goto out; |
| 4801 | } else { |
| 4802 | MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN); |
| 4803 | } |
| 4804 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4805 | MLX5_SET(wq, wq, log_wq_stride, rwq->log_rq_stride); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4806 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ) { |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 4807 | /* |
| 4808 | * In Firmware number of strides in each WQE is: |
| 4809 | * "512 * 2^single_wqe_log_num_of_strides" |
| 4810 | * Values 3 to 8 are accepted as 10 to 15, 9 to 18 are |
| 4811 | * accepted as 0 to 9 |
| 4812 | */ |
| 4813 | static const u8 fw_map[] = { 10, 11, 12, 13, 14, 15, 0, 1, |
| 4814 | 2, 3, 4, 5, 6, 7, 8, 9 }; |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4815 | MLX5_SET(wq, wq, two_byte_shift_en, rwq->two_byte_shift_en); |
| 4816 | MLX5_SET(wq, wq, log_wqe_stride_size, |
| 4817 | rwq->single_stride_log_num_of_bytes - |
| 4818 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES); |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 4819 | MLX5_SET(wq, wq, log_wqe_num_of_strides, |
| 4820 | fw_map[rwq->log_num_strides - |
| 4821 | MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES]); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4822 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4823 | MLX5_SET(wq, wq, log_wq_sz, rwq->log_rq_size); |
| 4824 | MLX5_SET(wq, wq, pd, to_mpd(pd)->pdn); |
| 4825 | MLX5_SET(wq, wq, page_offset, rwq->rq_page_offset); |
| 4826 | MLX5_SET(wq, wq, log_wq_pg_sz, rwq->log_page_size); |
| 4827 | MLX5_SET(wq, wq, wq_signature, rwq->wq_sig); |
| 4828 | MLX5_SET64(wq, wq, dbr_addr, rwq->db.dma); |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 4829 | has_net_offloads = MLX5_CAP_GEN(dev->mdev, eth_net_offloads); |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 4830 | if (init_attr->create_flags & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 4831 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 4832 | mlx5_ib_dbg(dev, "VLAN offloads are not supported\n"); |
| 4833 | err = -EOPNOTSUPP; |
| 4834 | goto out; |
| 4835 | } |
| 4836 | } else { |
| 4837 | MLX5_SET(rqc, rqc, vsd, 1); |
| 4838 | } |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 4839 | if (init_attr->create_flags & IB_WQ_FLAGS_SCATTER_FCS) { |
| 4840 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, scatter_fcs))) { |
| 4841 | mlx5_ib_dbg(dev, "Scatter FCS is not supported\n"); |
| 4842 | err = -EOPNOTSUPP; |
| 4843 | goto out; |
| 4844 | } |
| 4845 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 4846 | } |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4847 | if (init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 4848 | if (!(dev->ib_dev.attrs.raw_packet_caps & |
| 4849 | IB_RAW_PACKET_CAP_DELAY_DROP)) { |
| 4850 | mlx5_ib_dbg(dev, "Delay drop is not supported\n"); |
| 4851 | err = -EOPNOTSUPP; |
| 4852 | goto out; |
| 4853 | } |
| 4854 | MLX5_SET(rqc, rqc, delay_drop_en, 1); |
| 4855 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4856 | rq_pas0 = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 4857 | mlx5_ib_populate_pas(dev, rwq->umem, rwq->page_shift, rq_pas0, 0); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 4858 | err = mlx5_core_create_rq_tracked(dev, in, inlen, &rwq->core_qp); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4859 | if (!err && init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 4860 | err = set_delay_drop(dev); |
| 4861 | if (err) { |
| 4862 | mlx5_ib_warn(dev, "Failed to enable delay drop err=%d\n", |
| 4863 | err); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 4864 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 4865 | } else { |
| 4866 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_DELAY_DROP; |
| 4867 | } |
| 4868 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 4869 | out: |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4870 | kvfree(in); |
| 4871 | return err; |
| 4872 | } |
| 4873 | |
| 4874 | static int set_user_rq_size(struct mlx5_ib_dev *dev, |
| 4875 | struct ib_wq_init_attr *wq_init_attr, |
| 4876 | struct mlx5_ib_create_wq *ucmd, |
| 4877 | struct mlx5_ib_rwq *rwq) |
| 4878 | { |
| 4879 | /* Sanity check RQ size before proceeding */ |
| 4880 | if (wq_init_attr->max_wr > (1 << MLX5_CAP_GEN(dev->mdev, log_max_wq_sz))) |
| 4881 | return -EINVAL; |
| 4882 | |
| 4883 | if (!ucmd->rq_wqe_count) |
| 4884 | return -EINVAL; |
| 4885 | |
| 4886 | rwq->wqe_count = ucmd->rq_wqe_count; |
| 4887 | rwq->wqe_shift = ucmd->rq_wqe_shift; |
Leon Romanovsky | 0dfe452 | 2018-08-01 14:25:41 -0700 | [diff] [blame] | 4888 | if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, &rwq->buf_size)) |
| 4889 | return -EINVAL; |
| 4890 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4891 | rwq->log_rq_stride = rwq->wqe_shift; |
| 4892 | rwq->log_rq_size = ilog2(rwq->wqe_count); |
| 4893 | return 0; |
| 4894 | } |
| 4895 | |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 4896 | static bool log_of_strides_valid(struct mlx5_ib_dev *dev, u32 log_num_strides) |
| 4897 | { |
| 4898 | if ((log_num_strides > MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES) || |
| 4899 | (log_num_strides < MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES)) |
| 4900 | return false; |
| 4901 | |
| 4902 | if (!MLX5_CAP_GEN(dev->mdev, ext_stride_num_range) && |
| 4903 | (log_num_strides < MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES)) |
| 4904 | return false; |
| 4905 | |
| 4906 | return true; |
| 4907 | } |
| 4908 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4909 | static int prepare_user_rq(struct ib_pd *pd, |
| 4910 | struct ib_wq_init_attr *init_attr, |
| 4911 | struct ib_udata *udata, |
| 4912 | struct mlx5_ib_rwq *rwq) |
| 4913 | { |
| 4914 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
| 4915 | struct mlx5_ib_create_wq ucmd = {}; |
| 4916 | int err; |
| 4917 | size_t required_cmd_sz; |
| 4918 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4919 | required_cmd_sz = offsetof(typeof(ucmd), single_stride_log_num_of_bytes) |
| 4920 | + sizeof(ucmd.single_stride_log_num_of_bytes); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4921 | if (udata->inlen < required_cmd_sz) { |
| 4922 | mlx5_ib_dbg(dev, "invalid inlen\n"); |
| 4923 | return -EINVAL; |
| 4924 | } |
| 4925 | |
| 4926 | if (udata->inlen > sizeof(ucmd) && |
| 4927 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 4928 | udata->inlen - sizeof(ucmd))) { |
| 4929 | mlx5_ib_dbg(dev, "inlen is not supported\n"); |
| 4930 | return -EOPNOTSUPP; |
| 4931 | } |
| 4932 | |
| 4933 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) { |
| 4934 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 4935 | return -EFAULT; |
| 4936 | } |
| 4937 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4938 | if (ucmd.comp_mask & (~MLX5_IB_CREATE_WQ_STRIDING_RQ)) { |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4939 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 4940 | return -EOPNOTSUPP; |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4941 | } else if (ucmd.comp_mask & MLX5_IB_CREATE_WQ_STRIDING_RQ) { |
| 4942 | if (!MLX5_CAP_GEN(dev->mdev, striding_rq)) { |
| 4943 | mlx5_ib_dbg(dev, "Striding RQ is not supported\n"); |
| 4944 | return -EOPNOTSUPP; |
| 4945 | } |
| 4946 | if ((ucmd.single_stride_log_num_of_bytes < |
| 4947 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES) || |
| 4948 | (ucmd.single_stride_log_num_of_bytes > |
| 4949 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES)) { |
| 4950 | mlx5_ib_dbg(dev, "Invalid log stride size (%u. Range is %u - %u)\n", |
| 4951 | ucmd.single_stride_log_num_of_bytes, |
| 4952 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES, |
| 4953 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES); |
| 4954 | return -EINVAL; |
| 4955 | } |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 4956 | if (!log_of_strides_valid(dev, |
| 4957 | ucmd.single_wqe_log_num_of_strides)) { |
| 4958 | mlx5_ib_dbg( |
| 4959 | dev, |
| 4960 | "Invalid log num strides (%u. Range is %u - %u)\n", |
| 4961 | ucmd.single_wqe_log_num_of_strides, |
| 4962 | MLX5_CAP_GEN(dev->mdev, ext_stride_num_range) ? |
| 4963 | MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES : |
| 4964 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES, |
| 4965 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 4966 | return -EINVAL; |
| 4967 | } |
| 4968 | rwq->single_stride_log_num_of_bytes = |
| 4969 | ucmd.single_stride_log_num_of_bytes; |
| 4970 | rwq->log_num_strides = ucmd.single_wqe_log_num_of_strides; |
| 4971 | rwq->two_byte_shift_en = !!ucmd.two_byte_shift_en; |
| 4972 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_STRIDING_RQ; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4973 | } |
| 4974 | |
| 4975 | err = set_user_rq_size(dev, init_attr, &ucmd, rwq); |
| 4976 | if (err) { |
| 4977 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 4978 | return err; |
| 4979 | } |
| 4980 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 4981 | err = create_user_rq(dev, pd, udata, rwq, &ucmd); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4982 | if (err) { |
| 4983 | mlx5_ib_dbg(dev, "err %d\n", err); |
Gal Pressman | 645ba59 | 2018-10-08 19:44:03 +0300 | [diff] [blame] | 4984 | return err; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 4985 | } |
| 4986 | |
| 4987 | rwq->user_index = ucmd.user_index; |
| 4988 | return 0; |
| 4989 | } |
| 4990 | |
| 4991 | struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd, |
| 4992 | struct ib_wq_init_attr *init_attr, |
| 4993 | struct ib_udata *udata) |
| 4994 | { |
| 4995 | struct mlx5_ib_dev *dev; |
| 4996 | struct mlx5_ib_rwq *rwq; |
| 4997 | struct mlx5_ib_create_wq_resp resp = {}; |
| 4998 | size_t min_resp_len; |
| 4999 | int err; |
| 5000 | |
| 5001 | if (!udata) |
| 5002 | return ERR_PTR(-ENOSYS); |
| 5003 | |
| 5004 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 5005 | if (udata->outlen && udata->outlen < min_resp_len) |
| 5006 | return ERR_PTR(-EINVAL); |
| 5007 | |
Maor Gottlieb | ba80013 | 2020-03-22 14:49:06 +0200 | [diff] [blame] | 5008 | if (!capable(CAP_SYS_RAWIO) && |
| 5009 | init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) |
| 5010 | return ERR_PTR(-EPERM); |
| 5011 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5012 | dev = to_mdev(pd->device); |
| 5013 | switch (init_attr->wq_type) { |
| 5014 | case IB_WQT_RQ: |
| 5015 | rwq = kzalloc(sizeof(*rwq), GFP_KERNEL); |
| 5016 | if (!rwq) |
| 5017 | return ERR_PTR(-ENOMEM); |
| 5018 | err = prepare_user_rq(pd, init_attr, udata, rwq); |
| 5019 | if (err) |
| 5020 | goto err; |
| 5021 | err = create_rq(rwq, pd, init_attr); |
| 5022 | if (err) |
| 5023 | goto err_user_rq; |
| 5024 | break; |
| 5025 | default: |
| 5026 | mlx5_ib_dbg(dev, "unsupported wq type %d\n", |
| 5027 | init_attr->wq_type); |
| 5028 | return ERR_PTR(-EINVAL); |
| 5029 | } |
| 5030 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5031 | rwq->ibwq.wq_num = rwq->core_qp.qpn; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5032 | rwq->ibwq.state = IB_WQS_RESET; |
| 5033 | if (udata->outlen) { |
| 5034 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 5035 | sizeof(resp.response_length); |
| 5036 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 5037 | if (err) |
| 5038 | goto err_copy; |
| 5039 | } |
| 5040 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5041 | rwq->core_qp.event = mlx5_ib_wq_event; |
| 5042 | rwq->ibwq.event_handler = init_attr->event_handler; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5043 | return &rwq->ibwq; |
| 5044 | |
| 5045 | err_copy: |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5046 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5047 | err_user_rq: |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 5048 | destroy_user_rq(dev, pd, rwq, udata); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5049 | err: |
| 5050 | kfree(rwq); |
| 5051 | return ERR_PTR(err); |
| 5052 | } |
| 5053 | |
Leon Romanovsky | a49b1dc | 2019-06-12 15:27:41 +0300 | [diff] [blame] | 5054 | void mlx5_ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata) |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5055 | { |
| 5056 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 5057 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 5058 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5059 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 5060 | destroy_user_rq(dev, wq->pd, rwq, udata); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5061 | kfree(rwq); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5062 | } |
| 5063 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5064 | struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device, |
| 5065 | struct ib_rwq_ind_table_init_attr *init_attr, |
| 5066 | struct ib_udata *udata) |
| 5067 | { |
| 5068 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 5069 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl; |
| 5070 | int sz = 1 << init_attr->log_ind_tbl_size; |
| 5071 | struct mlx5_ib_create_rwq_ind_tbl_resp resp = {}; |
| 5072 | size_t min_resp_len; |
| 5073 | int inlen; |
| 5074 | int err; |
| 5075 | int i; |
| 5076 | u32 *in; |
| 5077 | void *rqtc; |
| 5078 | |
| 5079 | if (udata->inlen > 0 && |
| 5080 | !ib_is_udata_cleared(udata, 0, |
| 5081 | udata->inlen)) |
| 5082 | return ERR_PTR(-EOPNOTSUPP); |
| 5083 | |
Maor Gottlieb | efd7f40 | 2016-10-27 16:36:40 +0300 | [diff] [blame] | 5084 | if (init_attr->log_ind_tbl_size > |
| 5085 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)) { |
| 5086 | mlx5_ib_dbg(dev, "log_ind_tbl_size = %d is bigger than supported = %d\n", |
| 5087 | init_attr->log_ind_tbl_size, |
| 5088 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)); |
| 5089 | return ERR_PTR(-EINVAL); |
| 5090 | } |
| 5091 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5092 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 5093 | if (udata->outlen && udata->outlen < min_resp_len) |
| 5094 | return ERR_PTR(-EINVAL); |
| 5095 | |
| 5096 | rwq_ind_tbl = kzalloc(sizeof(*rwq_ind_tbl), GFP_KERNEL); |
| 5097 | if (!rwq_ind_tbl) |
| 5098 | return ERR_PTR(-ENOMEM); |
| 5099 | |
| 5100 | inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5101 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5102 | if (!in) { |
| 5103 | err = -ENOMEM; |
| 5104 | goto err; |
| 5105 | } |
| 5106 | |
| 5107 | rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context); |
| 5108 | |
| 5109 | MLX5_SET(rqtc, rqtc, rqt_actual_size, sz); |
| 5110 | MLX5_SET(rqtc, rqtc, rqt_max_size, sz); |
| 5111 | |
| 5112 | for (i = 0; i < sz; i++) |
| 5113 | MLX5_SET(rqtc, rqtc, rq_num[i], init_attr->ind_tbl[i]->wq_num); |
| 5114 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 5115 | rwq_ind_tbl->uid = to_mpd(init_attr->ind_tbl[0]->pd)->uid; |
| 5116 | MLX5_SET(create_rqt_in, in, uid, rwq_ind_tbl->uid); |
| 5117 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5118 | err = mlx5_core_create_rqt(dev->mdev, in, inlen, &rwq_ind_tbl->rqtn); |
| 5119 | kvfree(in); |
| 5120 | |
| 5121 | if (err) |
| 5122 | goto err; |
| 5123 | |
| 5124 | rwq_ind_tbl->ib_rwq_ind_tbl.ind_tbl_num = rwq_ind_tbl->rqtn; |
| 5125 | if (udata->outlen) { |
| 5126 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 5127 | sizeof(resp.response_length); |
| 5128 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 5129 | if (err) |
| 5130 | goto err_copy; |
| 5131 | } |
| 5132 | |
| 5133 | return &rwq_ind_tbl->ib_rwq_ind_tbl; |
| 5134 | |
| 5135 | err_copy: |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 5136 | mlx5_cmd_destroy_rqt(dev->mdev, rwq_ind_tbl->rqtn, rwq_ind_tbl->uid); |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5137 | err: |
| 5138 | kfree(rwq_ind_tbl); |
| 5139 | return ERR_PTR(err); |
| 5140 | } |
| 5141 | |
| 5142 | int mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl) |
| 5143 | { |
| 5144 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl = to_mrwq_ind_table(ib_rwq_ind_tbl); |
| 5145 | struct mlx5_ib_dev *dev = to_mdev(ib_rwq_ind_tbl->device); |
| 5146 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 5147 | mlx5_cmd_destroy_rqt(dev->mdev, rwq_ind_tbl->rqtn, rwq_ind_tbl->uid); |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5148 | |
| 5149 | kfree(rwq_ind_tbl); |
| 5150 | return 0; |
| 5151 | } |
| 5152 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5153 | int mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, |
| 5154 | u32 wq_attr_mask, struct ib_udata *udata) |
| 5155 | { |
| 5156 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 5157 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 5158 | struct mlx5_ib_modify_wq ucmd = {}; |
| 5159 | size_t required_cmd_sz; |
| 5160 | int curr_wq_state; |
| 5161 | int wq_state; |
| 5162 | int inlen; |
| 5163 | int err; |
| 5164 | void *rqc; |
| 5165 | void *in; |
| 5166 | |
| 5167 | required_cmd_sz = offsetof(typeof(ucmd), reserved) + sizeof(ucmd.reserved); |
| 5168 | if (udata->inlen < required_cmd_sz) |
| 5169 | return -EINVAL; |
| 5170 | |
| 5171 | if (udata->inlen > sizeof(ucmd) && |
| 5172 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 5173 | udata->inlen - sizeof(ucmd))) |
| 5174 | return -EOPNOTSUPP; |
| 5175 | |
| 5176 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) |
| 5177 | return -EFAULT; |
| 5178 | |
| 5179 | if (ucmd.comp_mask || ucmd.reserved) |
| 5180 | return -EOPNOTSUPP; |
| 5181 | |
| 5182 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5183 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5184 | if (!in) |
| 5185 | return -ENOMEM; |
| 5186 | |
| 5187 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 5188 | |
| 5189 | curr_wq_state = (wq_attr_mask & IB_WQ_CUR_STATE) ? |
| 5190 | wq_attr->curr_wq_state : wq->state; |
| 5191 | wq_state = (wq_attr_mask & IB_WQ_STATE) ? |
| 5192 | wq_attr->wq_state : curr_wq_state; |
| 5193 | if (curr_wq_state == IB_WQS_ERR) |
| 5194 | curr_wq_state = MLX5_RQC_STATE_ERR; |
| 5195 | if (wq_state == IB_WQS_ERR) |
| 5196 | wq_state = MLX5_RQC_STATE_ERR; |
| 5197 | MLX5_SET(modify_rq_in, in, rq_state, curr_wq_state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 5198 | MLX5_SET(modify_rq_in, in, uid, to_mpd(wq->pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5199 | MLX5_SET(rqc, rqc, state, wq_state); |
| 5200 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 5201 | if (wq_attr_mask & IB_WQ_FLAGS) { |
| 5202 | if (wq_attr->flags_mask & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
| 5203 | if (!(MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 5204 | MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
| 5205 | mlx5_ib_dbg(dev, "VLAN offloads are not " |
| 5206 | "supported\n"); |
| 5207 | err = -EOPNOTSUPP; |
| 5208 | goto out; |
| 5209 | } |
| 5210 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 5211 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD); |
| 5212 | MLX5_SET(rqc, rqc, vsd, |
| 5213 | (wq_attr->flags & IB_WQ_FLAGS_CVLAN_STRIPPING) ? 0 : 1); |
| 5214 | } |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 5215 | |
| 5216 | if (wq_attr->flags_mask & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 5217 | mlx5_ib_dbg(dev, "Modifying scatter end padding is not supported\n"); |
| 5218 | err = -EOPNOTSUPP; |
| 5219 | goto out; |
| 5220 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 5221 | } |
| 5222 | |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 5223 | if (curr_wq_state == IB_WQS_RESET && wq_state == IB_WQS_RDY) { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5224 | u16 set_id; |
| 5225 | |
| 5226 | set_id = mlx5_ib_get_counters_id(dev, 0); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 5227 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 5228 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 5229 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 5230 | MLX5_SET(rqc, rqc, counter_set_id, set_id); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 5231 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 5232 | dev_info_once( |
| 5233 | &dev->ib_dev.dev, |
| 5234 | "Receive WQ counters are not supported on current FW\n"); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 5235 | } |
| 5236 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 5237 | err = mlx5_core_modify_rq(dev->mdev, rwq->core_qp.qpn, in); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5238 | if (!err) |
| 5239 | rwq->ibwq.state = (wq_state == MLX5_RQC_STATE_ERR) ? IB_WQS_ERR : wq_state; |
| 5240 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 5241 | out: |
| 5242 | kvfree(in); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5243 | return err; |
| 5244 | } |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5245 | |
| 5246 | struct mlx5_ib_drain_cqe { |
| 5247 | struct ib_cqe cqe; |
| 5248 | struct completion done; |
| 5249 | }; |
| 5250 | |
| 5251 | static void mlx5_ib_drain_qp_done(struct ib_cq *cq, struct ib_wc *wc) |
| 5252 | { |
| 5253 | struct mlx5_ib_drain_cqe *cqe = container_of(wc->wr_cqe, |
| 5254 | struct mlx5_ib_drain_cqe, |
| 5255 | cqe); |
| 5256 | |
| 5257 | complete(&cqe->done); |
| 5258 | } |
| 5259 | |
| 5260 | /* This function returns only once the drained WR was completed */ |
| 5261 | static void handle_drain_completion(struct ib_cq *cq, |
| 5262 | struct mlx5_ib_drain_cqe *sdrain, |
| 5263 | struct mlx5_ib_dev *dev) |
| 5264 | { |
| 5265 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5266 | |
| 5267 | if (cq->poll_ctx == IB_POLL_DIRECT) { |
| 5268 | while (wait_for_completion_timeout(&sdrain->done, HZ / 10) <= 0) |
| 5269 | ib_process_cq_direct(cq, -1); |
| 5270 | return; |
| 5271 | } |
| 5272 | |
| 5273 | if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 5274 | struct mlx5_ib_cq *mcq = to_mcq(cq); |
| 5275 | bool triggered = false; |
| 5276 | unsigned long flags; |
| 5277 | |
| 5278 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 5279 | /* Make sure that the CQ handler won't run if wasn't run yet */ |
| 5280 | if (!mcq->mcq.reset_notify_added) |
| 5281 | mcq->mcq.reset_notify_added = 1; |
| 5282 | else |
| 5283 | triggered = true; |
| 5284 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 5285 | |
| 5286 | if (triggered) { |
| 5287 | /* Wait for any scheduled/running task to be ended */ |
| 5288 | switch (cq->poll_ctx) { |
| 5289 | case IB_POLL_SOFTIRQ: |
| 5290 | irq_poll_disable(&cq->iop); |
| 5291 | irq_poll_enable(&cq->iop); |
| 5292 | break; |
| 5293 | case IB_POLL_WORKQUEUE: |
| 5294 | cancel_work_sync(&cq->work); |
| 5295 | break; |
| 5296 | default: |
| 5297 | WARN_ON_ONCE(1); |
| 5298 | } |
| 5299 | } |
| 5300 | |
| 5301 | /* Run the CQ handler - this makes sure that the drain WR will |
| 5302 | * be processed if wasn't processed yet. |
| 5303 | */ |
Yishai Hadas | 4e0e2ea | 2019-06-30 19:23:27 +0300 | [diff] [blame] | 5304 | mcq->mcq.comp(&mcq->mcq, NULL); |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | wait_for_completion(&sdrain->done); |
| 5308 | } |
| 5309 | |
| 5310 | void mlx5_ib_drain_sq(struct ib_qp *qp) |
| 5311 | { |
| 5312 | struct ib_cq *cq = qp->send_cq; |
| 5313 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 5314 | struct mlx5_ib_drain_cqe sdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5315 | const struct ib_send_wr *bad_swr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5316 | struct ib_rdma_wr swr = { |
| 5317 | .wr = { |
| 5318 | .next = NULL, |
| 5319 | { .wr_cqe = &sdrain.cqe, }, |
| 5320 | .opcode = IB_WR_RDMA_WRITE, |
| 5321 | }, |
| 5322 | }; |
| 5323 | int ret; |
| 5324 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 5325 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5326 | |
| 5327 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 5328 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 5329 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 5330 | return; |
| 5331 | } |
| 5332 | |
| 5333 | sdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 5334 | init_completion(&sdrain.done); |
| 5335 | |
Leon Romanovsky | 029e88f | 2020-05-06 09:55:13 +0300 | [diff] [blame] | 5336 | ret = mlx5_ib_post_send_drain(qp, &swr.wr, &bad_swr); |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5337 | if (ret) { |
| 5338 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 5339 | return; |
| 5340 | } |
| 5341 | |
| 5342 | handle_drain_completion(cq, &sdrain, dev); |
| 5343 | } |
| 5344 | |
| 5345 | void mlx5_ib_drain_rq(struct ib_qp *qp) |
| 5346 | { |
| 5347 | struct ib_cq *cq = qp->recv_cq; |
| 5348 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 5349 | struct mlx5_ib_drain_cqe rdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5350 | struct ib_recv_wr rwr = {}; |
| 5351 | const struct ib_recv_wr *bad_rwr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5352 | int ret; |
| 5353 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 5354 | struct mlx5_core_dev *mdev = dev->mdev; |
| 5355 | |
| 5356 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 5357 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 5358 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 5359 | return; |
| 5360 | } |
| 5361 | |
| 5362 | rwr.wr_cqe = &rdrain.cqe; |
| 5363 | rdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 5364 | init_completion(&rdrain.done); |
| 5365 | |
Leon Romanovsky | 029e88f | 2020-05-06 09:55:13 +0300 | [diff] [blame] | 5366 | ret = mlx5_ib_post_recv_drain(qp, &rwr, &bad_rwr); |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5367 | if (ret) { |
| 5368 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 5369 | return; |
| 5370 | } |
| 5371 | |
| 5372 | handle_drain_completion(cq, &rdrain, dev); |
| 5373 | } |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 5374 | |
| 5375 | /** |
| 5376 | * Bind a qp to a counter. If @counter is NULL then bind the qp to |
| 5377 | * the default counter |
| 5378 | */ |
| 5379 | int mlx5_ib_qp_set_counter(struct ib_qp *qp, struct rdma_counter *counter) |
| 5380 | { |
Mark Zhang | 10189e8 | 2020-01-26 19:17:08 +0200 | [diff] [blame] | 5381 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 5382 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 5383 | int err = 0; |
| 5384 | |
| 5385 | mutex_lock(&mqp->mutex); |
| 5386 | if (mqp->state == IB_QPS_RESET) { |
| 5387 | qp->counter = counter; |
| 5388 | goto out; |
| 5389 | } |
| 5390 | |
Mark Zhang | 10189e8 | 2020-01-26 19:17:08 +0200 | [diff] [blame] | 5391 | if (!MLX5_CAP_GEN(dev->mdev, rts2rts_qp_counters_set_id)) { |
| 5392 | err = -EOPNOTSUPP; |
| 5393 | goto out; |
| 5394 | } |
| 5395 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 5396 | if (mqp->state == IB_QPS_RTS) { |
| 5397 | err = __mlx5_ib_qp_set_counter(qp, counter); |
| 5398 | if (!err) |
| 5399 | qp->counter = counter; |
| 5400 | |
| 5401 | goto out; |
| 5402 | } |
| 5403 | |
| 5404 | mqp->counter_pending = 1; |
| 5405 | qp->counter = counter; |
| 5406 | |
| 5407 | out: |
| 5408 | mutex_unlock(&mqp->mutex); |
| 5409 | return err; |
| 5410 | } |