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" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 43 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 44 | enum { |
| 45 | MLX5_IB_ACK_REQ_FREQ = 8, |
| 46 | }; |
| 47 | |
| 48 | enum { |
| 49 | MLX5_IB_DEFAULT_SCHED_QUEUE = 0x83, |
| 50 | MLX5_IB_DEFAULT_QP0_SCHED_QUEUE = 0x3f, |
| 51 | MLX5_IB_LINK_TYPE_IB = 0, |
| 52 | MLX5_IB_LINK_TYPE_ETH = 1 |
| 53 | }; |
| 54 | |
| 55 | enum { |
| 56 | MLX5_IB_SQ_STRIDE = 6, |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 57 | MLX5_IB_SQ_UMR_INLINE_THRESHOLD = 64, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static const u32 mlx5_ib_opcode[] = { |
| 61 | [IB_WR_SEND] = MLX5_OPCODE_SEND, |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 62 | [IB_WR_LSO] = MLX5_OPCODE_LSO, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 63 | [IB_WR_SEND_WITH_IMM] = MLX5_OPCODE_SEND_IMM, |
| 64 | [IB_WR_RDMA_WRITE] = MLX5_OPCODE_RDMA_WRITE, |
| 65 | [IB_WR_RDMA_WRITE_WITH_IMM] = MLX5_OPCODE_RDMA_WRITE_IMM, |
| 66 | [IB_WR_RDMA_READ] = MLX5_OPCODE_RDMA_READ, |
| 67 | [IB_WR_ATOMIC_CMP_AND_SWP] = MLX5_OPCODE_ATOMIC_CS, |
| 68 | [IB_WR_ATOMIC_FETCH_AND_ADD] = MLX5_OPCODE_ATOMIC_FA, |
| 69 | [IB_WR_SEND_WITH_INV] = MLX5_OPCODE_SEND_INVAL, |
| 70 | [IB_WR_LOCAL_INV] = MLX5_OPCODE_UMR, |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 71 | [IB_WR_REG_MR] = MLX5_OPCODE_UMR, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 72 | [IB_WR_MASKED_ATOMIC_CMP_AND_SWP] = MLX5_OPCODE_ATOMIC_MASKED_CS, |
| 73 | [IB_WR_MASKED_ATOMIC_FETCH_AND_ADD] = MLX5_OPCODE_ATOMIC_MASKED_FA, |
| 74 | [MLX5_IB_WR_UMR] = MLX5_OPCODE_UMR, |
| 75 | }; |
| 76 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 77 | struct mlx5_wqe_eth_pad { |
| 78 | u8 rsvd0[16]; |
| 79 | }; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 80 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 81 | enum raw_qp_set_mask_map { |
| 82 | MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID = 1UL << 0, |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 83 | MLX5_RAW_QP_RATE_LIMIT = 1UL << 1, |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 84 | }; |
| 85 | |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 86 | struct mlx5_modify_raw_qp_param { |
| 87 | u16 operation; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 88 | |
| 89 | u32 set_mask; /* raw_qp_set_mask_map */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 90 | |
| 91 | struct mlx5_rate_limit rl; |
| 92 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 93 | u8 rq_q_ctr_id; |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 94 | u16 port; |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 95 | }; |
| 96 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 97 | static void get_cqs(enum ib_qp_type qp_type, |
| 98 | struct ib_cq *ib_send_cq, struct ib_cq *ib_recv_cq, |
| 99 | struct mlx5_ib_cq **send_cq, struct mlx5_ib_cq **recv_cq); |
| 100 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 101 | static int is_qp0(enum ib_qp_type qp_type) |
| 102 | { |
| 103 | return qp_type == IB_QPT_SMI; |
| 104 | } |
| 105 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 106 | static int is_sqp(enum ib_qp_type qp_type) |
| 107 | { |
| 108 | return is_qp0(qp_type) || is_qp1(qp_type); |
| 109 | } |
| 110 | |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 111 | /** |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 112 | * mlx5_ib_read_user_wqe_common() - Copy a WQE (or part of) from user WQ |
| 113 | * to kernel buffer |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 114 | * |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 115 | * @umem: User space memory where the WQ is |
| 116 | * @buffer: buffer to copy to |
| 117 | * @buflen: buffer length |
| 118 | * @wqe_index: index of WQE to copy from |
| 119 | * @wq_offset: offset to start of WQ |
| 120 | * @wq_wqe_cnt: number of WQEs in WQ |
| 121 | * @wq_wqe_shift: log2 of WQE size |
| 122 | * @bcnt: number of bytes to copy |
| 123 | * @bytes_copied: number of bytes to copy (return value) |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 124 | * |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 125 | * Copies from start of WQE bcnt or less bytes. |
| 126 | * Does not gurantee to copy the entire WQE. |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 127 | * |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 128 | * Return: zero on success, or an error code. |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 129 | */ |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 130 | static int mlx5_ib_read_user_wqe_common(struct ib_umem *umem, void *buffer, |
| 131 | size_t buflen, int wqe_index, |
| 132 | int wq_offset, int wq_wqe_cnt, |
| 133 | int wq_wqe_shift, int bcnt, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 134 | size_t *bytes_copied) |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 135 | { |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 136 | size_t offset = wq_offset + ((wqe_index % wq_wqe_cnt) << wq_wqe_shift); |
| 137 | size_t wq_end = wq_offset + (wq_wqe_cnt << wq_wqe_shift); |
| 138 | size_t copy_length; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 139 | int ret; |
| 140 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 141 | /* don't copy more than requested, more than buffer length or |
| 142 | * beyond WQ end |
| 143 | */ |
| 144 | copy_length = min_t(u32, buflen, wq_end - offset); |
| 145 | copy_length = min_t(u32, copy_length, bcnt); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 146 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 147 | ret = ib_umem_copy_from(buffer, umem, offset, copy_length); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 148 | if (ret) |
| 149 | return ret; |
| 150 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 151 | if (!ret && bytes_copied) |
| 152 | *bytes_copied = copy_length; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 153 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 154 | return 0; |
| 155 | } |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 156 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 157 | static int mlx5_ib_read_kernel_wqe_sq(struct mlx5_ib_qp *qp, int wqe_index, |
| 158 | void *buffer, size_t buflen, size_t *bc) |
| 159 | { |
| 160 | struct mlx5_wqe_ctrl_seg *ctrl; |
| 161 | size_t bytes_copied = 0; |
| 162 | size_t wqe_length; |
| 163 | void *p; |
| 164 | int ds; |
| 165 | |
| 166 | wqe_index = wqe_index & qp->sq.fbc.sz_m1; |
| 167 | |
| 168 | /* read the control segment first */ |
| 169 | p = mlx5_frag_buf_get_wqe(&qp->sq.fbc, wqe_index); |
| 170 | ctrl = p; |
| 171 | ds = be32_to_cpu(ctrl->qpn_ds) & MLX5_WQE_CTRL_DS_MASK; |
| 172 | wqe_length = ds * MLX5_WQE_DS_UNITS; |
| 173 | |
| 174 | /* read rest of WQE if it spreads over more than one stride */ |
| 175 | while (bytes_copied < wqe_length) { |
| 176 | size_t copy_length = |
| 177 | min_t(size_t, buflen - bytes_copied, MLX5_SEND_WQE_BB); |
| 178 | |
| 179 | if (!copy_length) |
| 180 | break; |
| 181 | |
| 182 | memcpy(buffer + bytes_copied, p, copy_length); |
| 183 | bytes_copied += copy_length; |
| 184 | |
| 185 | wqe_index = (wqe_index + 1) & qp->sq.fbc.sz_m1; |
| 186 | p = mlx5_frag_buf_get_wqe(&qp->sq.fbc, wqe_index); |
| 187 | } |
| 188 | *bc = bytes_copied; |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | static int mlx5_ib_read_user_wqe_sq(struct mlx5_ib_qp *qp, int wqe_index, |
| 193 | void *buffer, size_t buflen, size_t *bc) |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 194 | { |
| 195 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 196 | struct ib_umem *umem = base->ubuffer.umem; |
| 197 | struct mlx5_ib_wq *wq = &qp->sq; |
| 198 | struct mlx5_wqe_ctrl_seg *ctrl; |
| 199 | size_t bytes_copied; |
| 200 | size_t bytes_copied2; |
| 201 | size_t wqe_length; |
| 202 | int ret; |
| 203 | int ds; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 204 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 205 | /* at first read as much as possible */ |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 206 | ret = mlx5_ib_read_user_wqe_common(umem, buffer, buflen, wqe_index, |
| 207 | wq->offset, wq->wqe_cnt, |
| 208 | wq->wqe_shift, buflen, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 209 | &bytes_copied); |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 210 | if (ret) |
| 211 | return ret; |
| 212 | |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 213 | /* we need at least control segment size to proceed */ |
| 214 | if (bytes_copied < sizeof(*ctrl)) |
| 215 | return -EINVAL; |
| 216 | |
| 217 | ctrl = buffer; |
| 218 | ds = be32_to_cpu(ctrl->qpn_ds) & MLX5_WQE_CTRL_DS_MASK; |
| 219 | wqe_length = ds * MLX5_WQE_DS_UNITS; |
| 220 | |
| 221 | /* if we copied enough then we are done */ |
| 222 | if (bytes_copied >= wqe_length) { |
| 223 | *bc = bytes_copied; |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | /* otherwise this a wrapped around wqe |
| 228 | * so read the remaining bytes starting |
| 229 | * from wqe_index 0 |
| 230 | */ |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 231 | ret = mlx5_ib_read_user_wqe_common(umem, buffer + bytes_copied, |
| 232 | buflen - bytes_copied, 0, wq->offset, |
| 233 | wq->wqe_cnt, wq->wqe_shift, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 234 | wqe_length - bytes_copied, |
| 235 | &bytes_copied2); |
| 236 | |
| 237 | if (ret) |
| 238 | return ret; |
| 239 | *bc = bytes_copied + bytes_copied2; |
| 240 | return 0; |
| 241 | } |
| 242 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 243 | int mlx5_ib_read_wqe_sq(struct mlx5_ib_qp *qp, int wqe_index, void *buffer, |
| 244 | size_t buflen, size_t *bc) |
| 245 | { |
| 246 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 247 | struct ib_umem *umem = base->ubuffer.umem; |
| 248 | |
| 249 | if (buflen < sizeof(struct mlx5_wqe_ctrl_seg)) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | if (!umem) |
| 253 | return mlx5_ib_read_kernel_wqe_sq(qp, wqe_index, buffer, |
| 254 | buflen, bc); |
| 255 | |
| 256 | return mlx5_ib_read_user_wqe_sq(qp, wqe_index, buffer, buflen, bc); |
| 257 | } |
| 258 | |
| 259 | static int mlx5_ib_read_user_wqe_rq(struct mlx5_ib_qp *qp, int wqe_index, |
| 260 | void *buffer, size_t buflen, size_t *bc) |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 261 | { |
| 262 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 263 | struct ib_umem *umem = base->ubuffer.umem; |
| 264 | struct mlx5_ib_wq *wq = &qp->rq; |
| 265 | size_t bytes_copied; |
| 266 | int ret; |
| 267 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 268 | ret = mlx5_ib_read_user_wqe_common(umem, buffer, buflen, wqe_index, |
| 269 | wq->offset, wq->wqe_cnt, |
| 270 | wq->wqe_shift, buflen, |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 271 | &bytes_copied); |
| 272 | |
| 273 | if (ret) |
| 274 | return ret; |
| 275 | *bc = bytes_copied; |
| 276 | return 0; |
| 277 | } |
| 278 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 279 | int mlx5_ib_read_wqe_rq(struct mlx5_ib_qp *qp, int wqe_index, void *buffer, |
| 280 | size_t buflen, size_t *bc) |
| 281 | { |
| 282 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
| 283 | struct ib_umem *umem = base->ubuffer.umem; |
| 284 | struct mlx5_ib_wq *wq = &qp->rq; |
| 285 | size_t wqe_size = 1 << wq->wqe_shift; |
| 286 | |
| 287 | if (buflen < wqe_size) |
| 288 | return -EINVAL; |
| 289 | |
| 290 | if (!umem) |
| 291 | return -EOPNOTSUPP; |
| 292 | |
| 293 | return mlx5_ib_read_user_wqe_rq(qp, wqe_index, buffer, buflen, bc); |
| 294 | } |
| 295 | |
| 296 | static int mlx5_ib_read_user_wqe_srq(struct mlx5_ib_srq *srq, int wqe_index, |
| 297 | void *buffer, size_t buflen, size_t *bc) |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 298 | { |
| 299 | struct ib_umem *umem = srq->umem; |
| 300 | size_t bytes_copied; |
| 301 | int ret; |
| 302 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 303 | ret = mlx5_ib_read_user_wqe_common(umem, buffer, buflen, wqe_index, 0, |
| 304 | srq->msrq.max, srq->msrq.wqe_shift, |
| 305 | buflen, &bytes_copied); |
Moni Shoua | fbeb407 | 2019-01-22 08:48:46 +0200 | [diff] [blame] | 306 | |
| 307 | if (ret) |
| 308 | return ret; |
| 309 | *bc = bytes_copied; |
| 310 | return 0; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Moni Shoua | da9ee9d | 2020-01-15 14:43:34 +0200 | [diff] [blame] | 313 | int mlx5_ib_read_wqe_srq(struct mlx5_ib_srq *srq, int wqe_index, void *buffer, |
| 314 | size_t buflen, size_t *bc) |
| 315 | { |
| 316 | struct ib_umem *umem = srq->umem; |
| 317 | size_t wqe_size = 1 << srq->msrq.wqe_shift; |
| 318 | |
| 319 | if (buflen < wqe_size) |
| 320 | return -EINVAL; |
| 321 | |
| 322 | if (!umem) |
| 323 | return -EOPNOTSUPP; |
| 324 | |
| 325 | return mlx5_ib_read_user_wqe_srq(srq, wqe_index, buffer, buflen, bc); |
| 326 | } |
| 327 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 328 | static void mlx5_ib_qp_event(struct mlx5_core_qp *qp, int type) |
| 329 | { |
| 330 | struct ib_qp *ibqp = &to_mibqp(qp)->ibqp; |
| 331 | struct ib_event event; |
| 332 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 333 | if (type == MLX5_EVENT_TYPE_PATH_MIG) { |
| 334 | /* This event is only valid for trans_qps */ |
| 335 | to_mibqp(qp)->port = to_mibqp(qp)->trans_qp.alt_port; |
| 336 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 337 | |
| 338 | if (ibqp->event_handler) { |
| 339 | event.device = ibqp->device; |
| 340 | event.element.qp = ibqp; |
| 341 | switch (type) { |
| 342 | case MLX5_EVENT_TYPE_PATH_MIG: |
| 343 | event.event = IB_EVENT_PATH_MIG; |
| 344 | break; |
| 345 | case MLX5_EVENT_TYPE_COMM_EST: |
| 346 | event.event = IB_EVENT_COMM_EST; |
| 347 | break; |
| 348 | case MLX5_EVENT_TYPE_SQ_DRAINED: |
| 349 | event.event = IB_EVENT_SQ_DRAINED; |
| 350 | break; |
| 351 | case MLX5_EVENT_TYPE_SRQ_LAST_WQE: |
| 352 | event.event = IB_EVENT_QP_LAST_WQE_REACHED; |
| 353 | break; |
| 354 | case MLX5_EVENT_TYPE_WQ_CATAS_ERROR: |
| 355 | event.event = IB_EVENT_QP_FATAL; |
| 356 | break; |
| 357 | case MLX5_EVENT_TYPE_PATH_MIG_FAILED: |
| 358 | event.event = IB_EVENT_PATH_MIG_ERR; |
| 359 | break; |
| 360 | case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR: |
| 361 | event.event = IB_EVENT_QP_REQ_ERR; |
| 362 | break; |
| 363 | case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR: |
| 364 | event.event = IB_EVENT_QP_ACCESS_ERR; |
| 365 | break; |
| 366 | default: |
| 367 | pr_warn("mlx5_ib: Unexpected event type %d on QP %06x\n", type, qp->qpn); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | ibqp->event_handler(&event, ibqp->qp_context); |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | static int set_rq_size(struct mlx5_ib_dev *dev, struct ib_qp_cap *cap, |
| 376 | int has_rq, struct mlx5_ib_qp *qp, struct mlx5_ib_create_qp *ucmd) |
| 377 | { |
| 378 | int wqe_size; |
| 379 | int wq_size; |
| 380 | |
| 381 | /* Sanity check RQ size before proceeding */ |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 382 | 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] | 383 | return -EINVAL; |
| 384 | |
| 385 | if (!has_rq) { |
| 386 | qp->rq.max_gs = 0; |
| 387 | qp->rq.wqe_cnt = 0; |
| 388 | qp->rq.wqe_shift = 0; |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 389 | cap->max_recv_wr = 0; |
| 390 | cap->max_recv_sge = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 391 | } else { |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 392 | int wq_sig = !!(qp->flags_en & MLX5_QP_FLAG_SIGNATURE); |
| 393 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 394 | if (ucmd) { |
| 395 | qp->rq.wqe_cnt = ucmd->rq_wqe_count; |
Leon Romanovsky | 002bf22 | 2018-04-23 17:01:53 +0300 | [diff] [blame] | 396 | if (ucmd->rq_wqe_shift > BITS_PER_BYTE * sizeof(ucmd->rq_wqe_shift)) |
| 397 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 398 | qp->rq.wqe_shift = ucmd->rq_wqe_shift; |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 399 | if ((1 << qp->rq.wqe_shift) / |
| 400 | sizeof(struct mlx5_wqe_data_seg) < |
| 401 | wq_sig) |
Leon Romanovsky | 002bf22 | 2018-04-23 17:01:53 +0300 | [diff] [blame] | 402 | return -EINVAL; |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 403 | qp->rq.max_gs = |
| 404 | (1 << qp->rq.wqe_shift) / |
| 405 | sizeof(struct mlx5_wqe_data_seg) - |
| 406 | wq_sig; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 407 | qp->rq.max_post = qp->rq.wqe_cnt; |
| 408 | } else { |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 409 | wqe_size = |
| 410 | wq_sig ? sizeof(struct mlx5_wqe_signature_seg) : |
| 411 | 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 412 | wqe_size += cap->max_recv_sge * sizeof(struct mlx5_wqe_data_seg); |
| 413 | wqe_size = roundup_pow_of_two(wqe_size); |
| 414 | wq_size = roundup_pow_of_two(cap->max_recv_wr) * wqe_size; |
| 415 | wq_size = max_t(int, wq_size, MLX5_SEND_WQE_BB); |
| 416 | qp->rq.wqe_cnt = wq_size / wqe_size; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 417 | if (wqe_size > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 418 | mlx5_ib_dbg(dev, "wqe_size %d, max %d\n", |
| 419 | wqe_size, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 420 | MLX5_CAP_GEN(dev->mdev, |
| 421 | max_wqe_sz_rq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 422 | return -EINVAL; |
| 423 | } |
| 424 | qp->rq.wqe_shift = ilog2(wqe_size); |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 425 | qp->rq.max_gs = |
| 426 | (1 << qp->rq.wqe_shift) / |
| 427 | sizeof(struct mlx5_wqe_data_seg) - |
| 428 | wq_sig; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 429 | qp->rq.max_post = qp->rq.wqe_cnt; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | return 0; |
| 434 | } |
| 435 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 436 | static int sq_overhead(struct ib_qp_init_attr *attr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 437 | { |
Andi Shyti | 618af38 | 2013-07-16 15:35:01 +0200 | [diff] [blame] | 438 | int size = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 439 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 440 | switch (attr->qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 441 | case IB_QPT_XRC_INI: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 442 | size += sizeof(struct mlx5_wqe_xrc_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 443 | /* fall through */ |
| 444 | case IB_QPT_RC: |
| 445 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Leon Romanovsky | 75c1657e | 2016-02-11 21:09:57 +0200 | [diff] [blame] | 446 | max(sizeof(struct mlx5_wqe_atomic_seg) + |
| 447 | sizeof(struct mlx5_wqe_raddr_seg), |
| 448 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 449 | sizeof(struct mlx5_mkey_seg) + |
| 450 | MLX5_IB_SQ_UMR_INLINE_THRESHOLD / |
| 451 | MLX5_IB_UMR_OCTOWORD); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 452 | break; |
| 453 | |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 454 | case IB_QPT_XRC_TGT: |
| 455 | return 0; |
| 456 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 457 | case IB_QPT_UC: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 458 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Leon Romanovsky | 75c1657e | 2016-02-11 21:09:57 +0200 | [diff] [blame] | 459 | max(sizeof(struct mlx5_wqe_raddr_seg), |
| 460 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
| 461 | sizeof(struct mlx5_mkey_seg)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 462 | break; |
| 463 | |
| 464 | case IB_QPT_UD: |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 465 | if (attr->create_flags & IB_QP_CREATE_IPOIB_UD_LSO) |
| 466 | size += sizeof(struct mlx5_wqe_eth_pad) + |
| 467 | sizeof(struct mlx5_wqe_eth_seg); |
| 468 | /* fall through */ |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 469 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 470 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 471 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 472 | sizeof(struct mlx5_wqe_datagram_seg); |
| 473 | break; |
| 474 | |
| 475 | case MLX5_IB_QPT_REG_UMR: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 476 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 477 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
| 478 | sizeof(struct mlx5_mkey_seg); |
| 479 | break; |
| 480 | |
| 481 | default: |
| 482 | return -EINVAL; |
| 483 | } |
| 484 | |
| 485 | return size; |
| 486 | } |
| 487 | |
| 488 | static int calc_send_wqe(struct ib_qp_init_attr *attr) |
| 489 | { |
| 490 | int inl_size = 0; |
| 491 | int size; |
| 492 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 493 | size = sq_overhead(attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 494 | if (size < 0) |
| 495 | return size; |
| 496 | |
| 497 | if (attr->cap.max_inline_data) { |
| 498 | inl_size = size + sizeof(struct mlx5_wqe_inline_seg) + |
| 499 | attr->cap.max_inline_data; |
| 500 | } |
| 501 | |
| 502 | size += attr->cap.max_send_sge * sizeof(struct mlx5_wqe_data_seg); |
Israel Rukshin | c0a6cbb | 2019-06-11 18:52:50 +0300 | [diff] [blame] | 503 | if (attr->create_flags & IB_QP_CREATE_INTEGRITY_EN && |
Sagi Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 504 | 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] | 505 | return MLX5_SIG_WQE_SIZE; |
Sagi Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 506 | else |
| 507 | return ALIGN(max_t(int, inl_size, size), MLX5_SEND_WQE_BB); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 508 | } |
| 509 | |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 510 | static int get_send_sge(struct ib_qp_init_attr *attr, int wqe_size) |
| 511 | { |
| 512 | int max_sge; |
| 513 | |
| 514 | if (attr->qp_type == IB_QPT_RC) |
| 515 | max_sge = (min_t(int, wqe_size, 512) - |
| 516 | sizeof(struct mlx5_wqe_ctrl_seg) - |
| 517 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 518 | sizeof(struct mlx5_wqe_data_seg); |
| 519 | else if (attr->qp_type == IB_QPT_XRC_INI) |
| 520 | max_sge = (min_t(int, wqe_size, 512) - |
| 521 | sizeof(struct mlx5_wqe_ctrl_seg) - |
| 522 | sizeof(struct mlx5_wqe_xrc_seg) - |
| 523 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 524 | sizeof(struct mlx5_wqe_data_seg); |
| 525 | else |
| 526 | max_sge = (wqe_size - sq_overhead(attr)) / |
| 527 | sizeof(struct mlx5_wqe_data_seg); |
| 528 | |
| 529 | return min_t(int, max_sge, wqe_size - sq_overhead(attr) / |
| 530 | sizeof(struct mlx5_wqe_data_seg)); |
| 531 | } |
| 532 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 533 | static int calc_sq_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr, |
| 534 | struct mlx5_ib_qp *qp) |
| 535 | { |
| 536 | int wqe_size; |
| 537 | int wq_size; |
| 538 | |
| 539 | if (!attr->cap.max_send_wr) |
| 540 | return 0; |
| 541 | |
| 542 | wqe_size = calc_send_wqe(attr); |
| 543 | mlx5_ib_dbg(dev, "wqe_size %d\n", wqe_size); |
| 544 | if (wqe_size < 0) |
| 545 | return wqe_size; |
| 546 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 547 | if (wqe_size > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)) { |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 548 | 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] | 549 | wqe_size, MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 550 | return -EINVAL; |
| 551 | } |
| 552 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 553 | qp->max_inline_data = wqe_size - sq_overhead(attr) - |
| 554 | sizeof(struct mlx5_wqe_inline_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 555 | attr->cap.max_inline_data = qp->max_inline_data; |
| 556 | |
| 557 | wq_size = roundup_pow_of_two(attr->cap.max_send_wr * wqe_size); |
| 558 | qp->sq.wqe_cnt = wq_size / MLX5_SEND_WQE_BB; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 559 | 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] | 560 | mlx5_ib_dbg(dev, "send queue size (%d * %d / %d -> %d) exceeds limits(%d)\n", |
| 561 | attr->cap.max_send_wr, wqe_size, MLX5_SEND_WQE_BB, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 562 | qp->sq.wqe_cnt, |
| 563 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz)); |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 564 | return -ENOMEM; |
| 565 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 566 | qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 567 | qp->sq.max_gs = get_send_sge(attr, wqe_size); |
| 568 | if (qp->sq.max_gs < attr->cap.max_send_sge) |
| 569 | return -ENOMEM; |
| 570 | |
| 571 | attr->cap.max_send_sge = qp->sq.max_gs; |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 572 | qp->sq.max_post = wq_size / wqe_size; |
| 573 | attr->cap.max_send_wr = qp->sq.max_post; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 574 | |
| 575 | return wq_size; |
| 576 | } |
| 577 | |
| 578 | static int set_user_buf_size(struct mlx5_ib_dev *dev, |
| 579 | struct mlx5_ib_qp *qp, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 580 | struct mlx5_ib_create_qp *ucmd, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 581 | struct mlx5_ib_qp_base *base, |
| 582 | struct ib_qp_init_attr *attr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 583 | { |
| 584 | int desc_sz = 1 << qp->sq.wqe_shift; |
| 585 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 586 | if (desc_sz > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 587 | 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] | 588 | desc_sz, MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 589 | return -EINVAL; |
| 590 | } |
| 591 | |
Gal Pressman | af8b38e | 2019-02-06 15:45:35 +0200 | [diff] [blame] | 592 | if (ucmd->sq_wqe_count && !is_power_of_2(ucmd->sq_wqe_count)) { |
| 593 | mlx5_ib_warn(dev, "sq_wqe_count %d is not a power of two\n", |
| 594 | ucmd->sq_wqe_count); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 595 | return -EINVAL; |
| 596 | } |
| 597 | |
| 598 | qp->sq.wqe_cnt = ucmd->sq_wqe_count; |
| 599 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 600 | 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] | 601 | mlx5_ib_warn(dev, "wqe_cnt %d, max_wqes %d\n", |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 602 | qp->sq.wqe_cnt, |
| 603 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 604 | return -EINVAL; |
| 605 | } |
| 606 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 607 | if (attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 608 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 609 | base->ubuffer.buf_size = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
| 610 | qp->raw_packet_qp.sq.ubuffer.buf_size = qp->sq.wqe_cnt << 6; |
| 611 | } else { |
| 612 | base->ubuffer.buf_size = (qp->rq.wqe_cnt << qp->rq.wqe_shift) + |
| 613 | (qp->sq.wqe_cnt << 6); |
| 614 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static int qp_has_rq(struct ib_qp_init_attr *attr) |
| 620 | { |
| 621 | if (attr->qp_type == IB_QPT_XRC_INI || |
| 622 | attr->qp_type == IB_QPT_XRC_TGT || attr->srq || |
| 623 | attr->qp_type == MLX5_IB_QPT_REG_UMR || |
| 624 | !attr->cap.max_recv_wr) |
| 625 | return 0; |
| 626 | |
| 627 | return 1; |
| 628 | } |
| 629 | |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 630 | enum { |
| 631 | /* this is the first blue flame register in the array of bfregs assigned |
| 632 | * to a processes. Since we do not use it for blue flame but rather |
| 633 | * regular 64 bit doorbells, we do not need a lock for maintaiing |
| 634 | * "odd/even" order |
| 635 | */ |
| 636 | NUM_NON_BLUE_FLAME_BFREGS = 1, |
| 637 | }; |
| 638 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 639 | static int max_bfregs(struct mlx5_ib_dev *dev, struct mlx5_bfreg_info *bfregi) |
| 640 | { |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 641 | 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] | 642 | } |
| 643 | |
| 644 | static int num_med_bfreg(struct mlx5_ib_dev *dev, |
| 645 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 646 | { |
| 647 | int n; |
| 648 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 649 | n = max_bfregs(dev, bfregi) - bfregi->num_low_latency_bfregs - |
| 650 | NUM_NON_BLUE_FLAME_BFREGS; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 651 | |
| 652 | return n >= 0 ? n : 0; |
| 653 | } |
| 654 | |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 655 | static int first_med_bfreg(struct mlx5_ib_dev *dev, |
| 656 | struct mlx5_bfreg_info *bfregi) |
| 657 | { |
| 658 | return num_med_bfreg(dev, bfregi) ? 1 : -ENOMEM; |
| 659 | } |
| 660 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 661 | static int first_hi_bfreg(struct mlx5_ib_dev *dev, |
| 662 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 663 | { |
| 664 | int med; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 665 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 666 | med = num_med_bfreg(dev, bfregi); |
| 667 | return ++med; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 668 | } |
| 669 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 670 | static int alloc_high_class_bfreg(struct mlx5_ib_dev *dev, |
| 671 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 672 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 673 | int i; |
| 674 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 675 | for (i = first_hi_bfreg(dev, bfregi); i < max_bfregs(dev, bfregi); i++) { |
| 676 | if (!bfregi->count[i]) { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 677 | bfregi->count[i]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 678 | return i; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | return -ENOMEM; |
| 683 | } |
| 684 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 685 | static int alloc_med_class_bfreg(struct mlx5_ib_dev *dev, |
| 686 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 687 | { |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 688 | int minidx = first_med_bfreg(dev, bfregi); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 689 | int i; |
| 690 | |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 691 | if (minidx < 0) |
| 692 | return minidx; |
| 693 | |
| 694 | for (i = minidx; i < first_hi_bfreg(dev, bfregi); i++) { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 695 | if (bfregi->count[i] < bfregi->count[minidx]) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 696 | minidx = i; |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 697 | if (!bfregi->count[minidx]) |
| 698 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 699 | } |
| 700 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 701 | bfregi->count[minidx]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 702 | return minidx; |
| 703 | } |
| 704 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 705 | static int alloc_bfreg(struct mlx5_ib_dev *dev, |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 706 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 707 | { |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 708 | int bfregn = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 709 | |
Yishai Hadas | 0a2fd01 | 2020-03-24 08:01:43 +0200 | [diff] [blame] | 710 | if (bfregi->lib_uar_dyn) |
| 711 | return -EINVAL; |
| 712 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 713 | mutex_lock(&bfregi->lock); |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 714 | if (bfregi->ver >= 2) { |
| 715 | bfregn = alloc_high_class_bfreg(dev, bfregi); |
| 716 | if (bfregn < 0) |
| 717 | bfregn = alloc_med_class_bfreg(dev, bfregi); |
| 718 | } |
| 719 | |
| 720 | if (bfregn < 0) { |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 721 | BUILD_BUG_ON(NUM_NON_BLUE_FLAME_BFREGS != 1); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 722 | bfregn = 0; |
| 723 | bfregi->count[bfregn]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 724 | } |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 725 | mutex_unlock(&bfregi->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 726 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 727 | return bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 728 | } |
| 729 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 730 | 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] | 731 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 732 | mutex_lock(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 733 | bfregi->count[bfregn]--; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 734 | mutex_unlock(&bfregi->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | static enum mlx5_qp_state to_mlx5_state(enum ib_qp_state state) |
| 738 | { |
| 739 | switch (state) { |
| 740 | case IB_QPS_RESET: return MLX5_QP_STATE_RST; |
| 741 | case IB_QPS_INIT: return MLX5_QP_STATE_INIT; |
| 742 | case IB_QPS_RTR: return MLX5_QP_STATE_RTR; |
| 743 | case IB_QPS_RTS: return MLX5_QP_STATE_RTS; |
| 744 | case IB_QPS_SQD: return MLX5_QP_STATE_SQD; |
| 745 | case IB_QPS_SQE: return MLX5_QP_STATE_SQER; |
| 746 | case IB_QPS_ERR: return MLX5_QP_STATE_ERR; |
| 747 | default: return -1; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | static int to_mlx5_st(enum ib_qp_type type) |
| 752 | { |
| 753 | switch (type) { |
| 754 | case IB_QPT_RC: return MLX5_QP_ST_RC; |
| 755 | case IB_QPT_UC: return MLX5_QP_ST_UC; |
| 756 | case IB_QPT_UD: return MLX5_QP_ST_UD; |
| 757 | case MLX5_IB_QPT_REG_UMR: return MLX5_QP_ST_REG_UMR; |
| 758 | case IB_QPT_XRC_INI: |
| 759 | case IB_QPT_XRC_TGT: return MLX5_QP_ST_XRC; |
| 760 | case IB_QPT_SMI: return MLX5_QP_ST_QP0; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 761 | case MLX5_IB_QPT_HW_GSI: return MLX5_QP_ST_QP1; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 762 | case MLX5_IB_QPT_DCI: return MLX5_QP_ST_DCI; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 763 | case IB_QPT_RAW_IPV6: return MLX5_QP_ST_RAW_IPV6; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 764 | case IB_QPT_RAW_PACKET: |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 765 | case IB_QPT_RAW_ETHERTYPE: return MLX5_QP_ST_RAW_ETHERTYPE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 766 | case IB_QPT_MAX: |
| 767 | default: return -EINVAL; |
| 768 | } |
| 769 | } |
| 770 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 771 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, |
| 772 | struct mlx5_ib_cq *recv_cq); |
| 773 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, |
| 774 | struct mlx5_ib_cq *recv_cq); |
| 775 | |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 776 | int bfregn_to_uar_index(struct mlx5_ib_dev *dev, |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 777 | struct mlx5_bfreg_info *bfregi, u32 bfregn, |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 778 | bool dyn_bfreg) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 779 | { |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 780 | unsigned int bfregs_per_sys_page; |
| 781 | u32 index_of_sys_page; |
| 782 | u32 offset; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 783 | |
Yishai Hadas | 0a2fd01 | 2020-03-24 08:01:43 +0200 | [diff] [blame] | 784 | if (bfregi->lib_uar_dyn) |
| 785 | return -EINVAL; |
| 786 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 787 | bfregs_per_sys_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k) * |
| 788 | MLX5_NON_FP_BFREGS_PER_UAR; |
| 789 | index_of_sys_page = bfregn / bfregs_per_sys_page; |
| 790 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 791 | if (dyn_bfreg) { |
| 792 | index_of_sys_page += bfregi->num_static_sys_pages; |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 793 | |
| 794 | if (index_of_sys_page >= bfregi->num_sys_pages) |
| 795 | return -EINVAL; |
| 796 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 797 | if (bfregn > bfregi->num_dyn_bfregs || |
| 798 | bfregi->sys_pages[index_of_sys_page] == MLX5_IB_INVALID_UAR_INDEX) { |
| 799 | mlx5_ib_dbg(dev, "Invalid dynamic uar index\n"); |
| 800 | return -EINVAL; |
| 801 | } |
| 802 | } |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 803 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 804 | offset = bfregn % bfregs_per_sys_page / MLX5_NON_FP_BFREGS_PER_UAR; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 805 | return bfregi->sys_pages[index_of_sys_page] + offset; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 806 | } |
| 807 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 808 | 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] | 809 | unsigned long addr, size_t size, |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 810 | struct ib_umem **umem, int *npages, int *page_shift, |
| 811 | int *ncont, u32 *offset) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 812 | { |
| 813 | int err; |
| 814 | |
Moni Shoua | c320e52 | 2020-01-15 14:43:31 +0200 | [diff] [blame] | 815 | *umem = ib_umem_get(&dev->ib_dev, addr, size, 0); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 816 | if (IS_ERR(*umem)) { |
| 817 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 818 | return PTR_ERR(*umem); |
| 819 | } |
| 820 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 821 | 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] | 822 | |
| 823 | err = mlx5_ib_get_buf_offset(addr, *page_shift, offset); |
| 824 | if (err) { |
| 825 | mlx5_ib_warn(dev, "bad offset\n"); |
| 826 | goto err_umem; |
| 827 | } |
| 828 | |
| 829 | mlx5_ib_dbg(dev, "addr 0x%lx, size %zu, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 830 | addr, size, *npages, *page_shift, *ncont, *offset); |
| 831 | |
| 832 | return 0; |
| 833 | |
| 834 | err_umem: |
| 835 | ib_umem_release(*umem); |
| 836 | *umem = NULL; |
| 837 | |
| 838 | return err; |
| 839 | } |
| 840 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 841 | 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] | 842 | struct mlx5_ib_rwq *rwq, struct ib_udata *udata) |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 843 | { |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 844 | struct mlx5_ib_ucontext *context = |
| 845 | rdma_udata_to_drv_context( |
| 846 | udata, |
| 847 | struct mlx5_ib_ucontext, |
| 848 | ibucontext); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 849 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 850 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_DELAY_DROP) |
| 851 | atomic_dec(&dev->delay_drop.rqs_cnt); |
| 852 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 853 | mlx5_ib_db_unmap_user(context, &rwq->db); |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 854 | ib_umem_release(rwq->umem); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | 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] | 858 | struct ib_udata *udata, struct mlx5_ib_rwq *rwq, |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 859 | struct mlx5_ib_create_wq *ucmd) |
| 860 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 861 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 862 | udata, struct mlx5_ib_ucontext, ibucontext); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 863 | int page_shift = 0; |
| 864 | int npages; |
| 865 | u32 offset = 0; |
| 866 | int ncont = 0; |
| 867 | int err; |
| 868 | |
| 869 | if (!ucmd->buf_addr) |
| 870 | return -EINVAL; |
| 871 | |
Moni Shoua | c320e52 | 2020-01-15 14:43:31 +0200 | [diff] [blame] | 872 | 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] | 873 | if (IS_ERR(rwq->umem)) { |
| 874 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 875 | err = PTR_ERR(rwq->umem); |
| 876 | return err; |
| 877 | } |
| 878 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 879 | 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] | 880 | &ncont, NULL); |
| 881 | err = mlx5_ib_get_buf_offset(ucmd->buf_addr, page_shift, |
| 882 | &rwq->rq_page_offset); |
| 883 | if (err) { |
| 884 | mlx5_ib_warn(dev, "bad offset\n"); |
| 885 | goto err_umem; |
| 886 | } |
| 887 | |
| 888 | rwq->rq_num_pas = ncont; |
| 889 | rwq->page_shift = page_shift; |
| 890 | rwq->log_page_size = page_shift - MLX5_ADAPTER_PAGE_SHIFT; |
| 891 | rwq->wq_sig = !!(ucmd->flags & MLX5_WQ_FLAG_SIGNATURE); |
| 892 | |
| 893 | mlx5_ib_dbg(dev, "addr 0x%llx, size %zd, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 894 | (unsigned long long)ucmd->buf_addr, rwq->buf_size, |
| 895 | npages, page_shift, ncont, offset); |
| 896 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 897 | 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] | 898 | if (err) { |
| 899 | mlx5_ib_dbg(dev, "map failed\n"); |
| 900 | goto err_umem; |
| 901 | } |
| 902 | |
| 903 | rwq->create_type = MLX5_WQ_USER; |
| 904 | return 0; |
| 905 | |
| 906 | err_umem: |
| 907 | ib_umem_release(rwq->umem); |
| 908 | return err; |
| 909 | } |
| 910 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 911 | static int adjust_bfregn(struct mlx5_ib_dev *dev, |
| 912 | struct mlx5_bfreg_info *bfregi, int bfregn) |
| 913 | { |
| 914 | return bfregn / MLX5_NON_FP_BFREGS_PER_UAR * MLX5_BFREGS_PER_UAR + |
| 915 | bfregn % MLX5_NON_FP_BFREGS_PER_UAR; |
| 916 | } |
| 917 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 918 | static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 919 | struct mlx5_ib_qp *qp, struct ib_udata *udata, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 920 | struct ib_qp_init_attr *attr, |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 921 | u32 **in, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 922 | struct mlx5_ib_create_qp_resp *resp, int *inlen, |
| 923 | struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 924 | { |
| 925 | struct mlx5_ib_ucontext *context; |
| 926 | struct mlx5_ib_create_qp ucmd; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 927 | struct mlx5_ib_ubuffer *ubuffer = &base->ubuffer; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 928 | int page_shift = 0; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 929 | int uar_index = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 930 | int npages; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 931 | u32 offset = 0; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 932 | int bfregn; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 933 | int ncont = 0; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 934 | __be64 *pas; |
| 935 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 936 | int err; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 937 | u16 uid; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 938 | u32 uar_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 939 | |
| 940 | err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)); |
| 941 | if (err) { |
| 942 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 943 | return err; |
| 944 | } |
| 945 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 946 | context = rdma_udata_to_drv_context(udata, struct mlx5_ib_ucontext, |
| 947 | ibucontext); |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 948 | uar_flags = ucmd.flags & (MLX5_QP_FLAG_UAR_PAGE_INDEX | |
| 949 | MLX5_QP_FLAG_BFREG_INDEX); |
| 950 | switch (uar_flags) { |
| 951 | case MLX5_QP_FLAG_UAR_PAGE_INDEX: |
| 952 | uar_index = ucmd.bfreg_index; |
| 953 | bfregn = MLX5_IB_INVALID_BFREG; |
| 954 | break; |
| 955 | case MLX5_QP_FLAG_BFREG_INDEX: |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 956 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, |
| 957 | ucmd.bfreg_index, true); |
| 958 | if (uar_index < 0) |
| 959 | return uar_index; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 960 | bfregn = MLX5_IB_INVALID_BFREG; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 961 | break; |
| 962 | case 0: |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 963 | if (qp->flags & IB_QP_CREATE_CROSS_CHANNEL) |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 964 | return -EINVAL; |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 965 | bfregn = alloc_bfreg(dev, &context->bfregi); |
| 966 | if (bfregn < 0) |
| 967 | return bfregn; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 968 | break; |
| 969 | default: |
| 970 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 971 | } |
| 972 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 973 | 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] | 974 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 975 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, bfregn, |
| 976 | false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 977 | |
Haggai Eran | 48fea83 | 2014-05-22 14:50:11 +0300 | [diff] [blame] | 978 | qp->rq.offset = 0; |
| 979 | qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); |
| 980 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
| 981 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 982 | err = set_user_buf_size(dev, qp, &ucmd, base, attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 983 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 984 | goto err_bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 985 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 986 | if (ucmd.buf_addr && ubuffer->buf_size) { |
| 987 | ubuffer->buf_addr = ucmd.buf_addr; |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 988 | err = mlx5_ib_umem_get(dev, udata, ubuffer->buf_addr, |
| 989 | ubuffer->buf_size, &ubuffer->umem, |
| 990 | &npages, &page_shift, &ncont, &offset); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 991 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 992 | goto err_bfreg; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 993 | } else { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 994 | ubuffer->umem = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 995 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 996 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 997 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 998 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 999 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1000 | if (!*in) { |
| 1001 | err = -ENOMEM; |
| 1002 | goto err_umem; |
| 1003 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1004 | |
Yishai Hadas | 7422edc | 2018-12-23 13:12:21 +0200 | [diff] [blame] | 1005 | uid = (attr->qp_type != IB_QPT_XRC_TGT && |
| 1006 | attr->qp_type != IB_QPT_XRC_INI) ? to_mpd(pd)->uid : 0; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 1007 | MLX5_SET(create_qp_in, *in, uid, uid); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1008 | pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, *in, pas); |
| 1009 | if (ubuffer->umem) |
| 1010 | mlx5_ib_populate_pas(dev, ubuffer->umem, page_shift, pas, 0); |
| 1011 | |
| 1012 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 1013 | |
| 1014 | MLX5_SET(qpc, qpc, log_page_size, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1015 | MLX5_SET(qpc, qpc, page_offset, offset); |
| 1016 | |
| 1017 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1018 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 1019 | resp->bfreg_index = adjust_bfregn(dev, &context->bfregi, bfregn); |
| 1020 | else |
| 1021 | resp->bfreg_index = MLX5_IB_INVALID_BFREG; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1022 | qp->bfregn = bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1023 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1024 | 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] | 1025 | if (err) { |
| 1026 | mlx5_ib_dbg(dev, "map failed\n"); |
| 1027 | goto err_free; |
| 1028 | } |
| 1029 | |
Jason Gunthorpe | 41d902c | 2018-04-03 10:00:53 +0300 | [diff] [blame] | 1030 | err = ib_copy_to_udata(udata, resp, min(udata->outlen, sizeof(*resp))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1031 | if (err) { |
| 1032 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1033 | goto err_unmap; |
| 1034 | } |
| 1035 | qp->create_type = MLX5_QP_USER; |
| 1036 | |
| 1037 | return 0; |
| 1038 | |
| 1039 | err_unmap: |
| 1040 | mlx5_ib_db_unmap_user(context, &qp->db); |
| 1041 | |
| 1042 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 1043 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1044 | |
| 1045 | err_umem: |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 1046 | ib_umem_release(ubuffer->umem); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1047 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1048 | err_bfreg: |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1049 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 1050 | mlx5_ib_free_bfreg(dev, &context->bfregi, bfregn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1051 | return err; |
| 1052 | } |
| 1053 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1054 | static void destroy_qp_user(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 1055 | struct mlx5_ib_qp *qp, struct mlx5_ib_qp_base *base, |
| 1056 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1057 | { |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 1058 | struct mlx5_ib_ucontext *context = |
| 1059 | rdma_udata_to_drv_context( |
| 1060 | udata, |
| 1061 | struct mlx5_ib_ucontext, |
| 1062 | ibucontext); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1063 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1064 | mlx5_ib_db_unmap_user(context, &qp->db); |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 1065 | ib_umem_release(base->ubuffer.umem); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1066 | |
| 1067 | /* |
| 1068 | * Free only the BFREGs which are handled by the kernel. |
| 1069 | * BFREGs of UARs allocated dynamically are handled by user. |
| 1070 | */ |
| 1071 | if (qp->bfregn != MLX5_IB_INVALID_BFREG) |
| 1072 | mlx5_ib_free_bfreg(dev, &context->bfregi, qp->bfregn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1073 | } |
| 1074 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1075 | /* get_sq_edge - Get the next nearby edge. |
| 1076 | * |
| 1077 | * An 'edge' is defined as the first following address after the end |
| 1078 | * of the fragment or the SQ. Accordingly, during the WQE construction |
| 1079 | * which repetitively increases the pointer to write the next data, it |
| 1080 | * simply should check if it gets to an edge. |
| 1081 | * |
| 1082 | * @sq - SQ buffer. |
| 1083 | * @idx - Stride index in the SQ buffer. |
| 1084 | * |
| 1085 | * Return: |
| 1086 | * The new edge. |
| 1087 | */ |
| 1088 | static void *get_sq_edge(struct mlx5_ib_wq *sq, u32 idx) |
| 1089 | { |
| 1090 | void *fragment_end; |
| 1091 | |
| 1092 | fragment_end = mlx5_frag_buf_get_wqe |
| 1093 | (&sq->fbc, |
| 1094 | mlx5_frag_buf_get_idx_last_contig_stride(&sq->fbc, idx)); |
| 1095 | |
| 1096 | return fragment_end + MLX5_SEND_WQE_BB; |
| 1097 | } |
| 1098 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1099 | static int create_kernel_qp(struct mlx5_ib_dev *dev, |
| 1100 | struct ib_qp_init_attr *init_attr, |
| 1101 | struct mlx5_ib_qp *qp, |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1102 | u32 **in, int *inlen, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 1103 | struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1104 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1105 | int uar_index; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1106 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1107 | int err; |
| 1108 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1109 | if (init_attr->qp_type == MLX5_IB_QPT_REG_UMR) |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1110 | qp->bf.bfreg = &dev->fp_bfreg; |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1111 | else if (qp->flags & MLX5_IB_QP_CREATE_WC_TEST) |
Michael Guralnik | 11f552e | 2019-06-10 15:21:24 +0300 | [diff] [blame] | 1112 | qp->bf.bfreg = &dev->wc_bfreg; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1113 | else |
| 1114 | qp->bf.bfreg = &dev->bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1115 | |
Eli Cohen | d8030b0 | 2017-02-09 19:31:47 +0200 | [diff] [blame] | 1116 | /* We need to divide by two since each register is comprised of |
| 1117 | * two buffers of identical size, namely odd and even |
| 1118 | */ |
| 1119 | 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] | 1120 | uar_index = qp->bf.bfreg->index; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1121 | |
| 1122 | err = calc_sq_size(dev, init_attr, qp); |
| 1123 | if (err < 0) { |
| 1124 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1125 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | qp->rq.offset = 0; |
| 1129 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 1130 | 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] | 1131 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1132 | err = mlx5_frag_buf_alloc_node(dev->mdev, base->ubuffer.buf_size, |
| 1133 | &qp->buf, dev->mdev->priv.numa_node); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1134 | if (err) { |
| 1135 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1136 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1137 | } |
| 1138 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1139 | if (qp->rq.wqe_cnt) |
| 1140 | mlx5_init_fbc(qp->buf.frags, qp->rq.wqe_shift, |
| 1141 | ilog2(qp->rq.wqe_cnt), &qp->rq.fbc); |
| 1142 | |
| 1143 | if (qp->sq.wqe_cnt) { |
| 1144 | int sq_strides_offset = (qp->sq.offset & (PAGE_SIZE - 1)) / |
| 1145 | MLX5_SEND_WQE_BB; |
| 1146 | mlx5_init_fbc_offset(qp->buf.frags + |
| 1147 | (qp->sq.offset / PAGE_SIZE), |
| 1148 | ilog2(MLX5_SEND_WQE_BB), |
| 1149 | ilog2(qp->sq.wqe_cnt), |
| 1150 | sq_strides_offset, &qp->sq.fbc); |
| 1151 | |
| 1152 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
| 1153 | } |
| 1154 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1155 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 1156 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * qp->buf.npages; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1157 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1158 | if (!*in) { |
| 1159 | err = -ENOMEM; |
| 1160 | goto err_buf; |
| 1161 | } |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1162 | |
| 1163 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 1164 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
| 1165 | MLX5_SET(qpc, qpc, log_page_size, qp->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1166 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1167 | /* Set "fast registration enabled" for all kernel QPs */ |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1168 | MLX5_SET(qpc, qpc, fre, 1); |
| 1169 | MLX5_SET(qpc, qpc, rlky, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1170 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1171 | if (qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1172 | MLX5_SET(qpc, qpc, deth_sqpn, 1); |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 1173 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1174 | mlx5_fill_page_frag_array(&qp->buf, |
| 1175 | (__be64 *)MLX5_ADDR_OF(create_qp_in, |
| 1176 | *in, pas)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1177 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1178 | err = mlx5_db_alloc(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1179 | if (err) { |
| 1180 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1181 | goto err_free; |
| 1182 | } |
| 1183 | |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1184 | qp->sq.wrid = kvmalloc_array(qp->sq.wqe_cnt, |
| 1185 | sizeof(*qp->sq.wrid), GFP_KERNEL); |
| 1186 | qp->sq.wr_data = kvmalloc_array(qp->sq.wqe_cnt, |
| 1187 | sizeof(*qp->sq.wr_data), GFP_KERNEL); |
| 1188 | qp->rq.wrid = kvmalloc_array(qp->rq.wqe_cnt, |
| 1189 | sizeof(*qp->rq.wrid), GFP_KERNEL); |
| 1190 | qp->sq.w_list = kvmalloc_array(qp->sq.wqe_cnt, |
| 1191 | sizeof(*qp->sq.w_list), GFP_KERNEL); |
| 1192 | qp->sq.wqe_head = kvmalloc_array(qp->sq.wqe_cnt, |
| 1193 | sizeof(*qp->sq.wqe_head), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1194 | |
| 1195 | if (!qp->sq.wrid || !qp->sq.wr_data || !qp->rq.wrid || |
| 1196 | !qp->sq.w_list || !qp->sq.wqe_head) { |
| 1197 | err = -ENOMEM; |
| 1198 | goto err_wrid; |
| 1199 | } |
| 1200 | qp->create_type = MLX5_QP_KERNEL; |
| 1201 | |
| 1202 | return 0; |
| 1203 | |
| 1204 | err_wrid: |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1205 | kvfree(qp->sq.wqe_head); |
| 1206 | kvfree(qp->sq.w_list); |
| 1207 | kvfree(qp->sq.wrid); |
| 1208 | kvfree(qp->sq.wr_data); |
| 1209 | kvfree(qp->rq.wrid); |
Eli Cohen | f4044da | 2017-01-03 23:55:20 +0200 | [diff] [blame] | 1210 | mlx5_db_free(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1211 | |
| 1212 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 1213 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1214 | |
| 1215 | err_buf: |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1216 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1217 | return err; |
| 1218 | } |
| 1219 | |
| 1220 | static void destroy_qp_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 1221 | { |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1222 | kvfree(qp->sq.wqe_head); |
| 1223 | kvfree(qp->sq.w_list); |
| 1224 | kvfree(qp->sq.wrid); |
| 1225 | kvfree(qp->sq.wr_data); |
| 1226 | kvfree(qp->rq.wrid); |
Eli Cohen | f4044da | 2017-01-03 23:55:20 +0200 | [diff] [blame] | 1227 | mlx5_db_free(dev->mdev, &qp->db); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1228 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1229 | } |
| 1230 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1231 | 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] | 1232 | { |
| 1233 | if (attr->srq || (attr->qp_type == IB_QPT_XRC_TGT) || |
Leon Romanovsky | 8bde2c5 | 2020-04-27 18:46:09 +0300 | [diff] [blame] | 1234 | (qp->qp_sub_type == MLX5_IB_QPT_DCI) || |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1235 | (attr->qp_type == IB_QPT_XRC_INI)) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1236 | return MLX5_SRQ_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1237 | else if (!qp->has_rq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1238 | return MLX5_ZERO_LEN_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1239 | else |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1240 | return MLX5_NON_ZERO_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1241 | } |
| 1242 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1243 | static int create_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1244 | struct mlx5_ib_qp *qp, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1245 | struct mlx5_ib_sq *sq, u32 tdn, |
| 1246 | struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1247 | { |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1248 | u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {}; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1249 | void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx); |
| 1250 | |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1251 | MLX5_SET(create_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1252 | MLX5_SET(tisc, tisc, transport_domain, tdn); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1253 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1254 | MLX5_SET(tisc, tisc, underlay_qpn, qp->underlay_qpn); |
| 1255 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1256 | return mlx5_core_create_tis(dev->mdev, in, &sq->tisn); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static void destroy_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1260 | struct mlx5_ib_sq *sq, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1261 | { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1262 | 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] | 1263 | } |
| 1264 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1265 | static void destroy_flow_rule_vport_sq(struct mlx5_ib_sq *sq) |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1266 | { |
| 1267 | if (sq->flow_rule) |
| 1268 | mlx5_del_flow_rules(sq->flow_rule); |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1269 | sq->flow_rule = NULL; |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1270 | } |
| 1271 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1272 | static int create_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1273 | struct ib_udata *udata, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1274 | struct mlx5_ib_sq *sq, void *qpin, |
| 1275 | struct ib_pd *pd) |
| 1276 | { |
| 1277 | struct mlx5_ib_ubuffer *ubuffer = &sq->ubuffer; |
| 1278 | __be64 *pas; |
| 1279 | void *in; |
| 1280 | void *sqc; |
| 1281 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
| 1282 | void *wq; |
| 1283 | int inlen; |
| 1284 | int err; |
| 1285 | int page_shift = 0; |
| 1286 | int npages; |
| 1287 | int ncont = 0; |
| 1288 | u32 offset = 0; |
| 1289 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1290 | err = mlx5_ib_umem_get(dev, udata, ubuffer->buf_addr, ubuffer->buf_size, |
| 1291 | &sq->ubuffer.umem, &npages, &page_shift, &ncont, |
| 1292 | &offset); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1293 | if (err) |
| 1294 | return err; |
| 1295 | |
| 1296 | inlen = MLX5_ST_SZ_BYTES(create_sq_in) + sizeof(u64) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1297 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1298 | if (!in) { |
| 1299 | err = -ENOMEM; |
| 1300 | goto err_umem; |
| 1301 | } |
| 1302 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 1303 | MLX5_SET(create_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1304 | sqc = MLX5_ADDR_OF(create_sq_in, in, ctx); |
| 1305 | MLX5_SET(sqc, sqc, flush_in_error_en, 1); |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1306 | if (MLX5_CAP_ETH(dev->mdev, multi_pkt_send_wqe)) |
| 1307 | MLX5_SET(sqc, sqc, allow_multi_pkt_send_wqe, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1308 | MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST); |
| 1309 | MLX5_SET(sqc, sqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1310 | MLX5_SET(sqc, sqc, cqn, MLX5_GET(qpc, qpc, cqn_snd)); |
| 1311 | MLX5_SET(sqc, sqc, tis_lst_sz, 1); |
| 1312 | MLX5_SET(sqc, sqc, tis_num_0, sq->tisn); |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1313 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 1314 | MLX5_CAP_ETH(dev->mdev, swp)) |
| 1315 | MLX5_SET(sqc, sqc, allow_swp, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1316 | |
| 1317 | wq = MLX5_ADDR_OF(sqc, sqc, wq); |
| 1318 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
| 1319 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1320 | MLX5_SET(wq, wq, uar_page, MLX5_GET(qpc, qpc, uar_page)); |
| 1321 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1322 | MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB)); |
| 1323 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_sq_size)); |
| 1324 | MLX5_SET(wq, wq, log_wq_pg_sz, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1325 | MLX5_SET(wq, wq, page_offset, offset); |
| 1326 | |
| 1327 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1328 | mlx5_ib_populate_pas(dev, sq->ubuffer.umem, page_shift, pas, 0); |
| 1329 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1330 | 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] | 1331 | |
| 1332 | kvfree(in); |
| 1333 | |
| 1334 | if (err) |
| 1335 | goto err_umem; |
| 1336 | |
| 1337 | return 0; |
| 1338 | |
| 1339 | err_umem: |
| 1340 | ib_umem_release(sq->ubuffer.umem); |
| 1341 | sq->ubuffer.umem = NULL; |
| 1342 | |
| 1343 | return err; |
| 1344 | } |
| 1345 | |
| 1346 | static void destroy_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
| 1347 | struct mlx5_ib_sq *sq) |
| 1348 | { |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1349 | destroy_flow_rule_vport_sq(sq); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1350 | mlx5_core_destroy_sq_tracked(dev, &sq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1351 | ib_umem_release(sq->ubuffer.umem); |
| 1352 | } |
| 1353 | |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1354 | static size_t get_rq_pas_size(void *qpc) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1355 | { |
| 1356 | u32 log_page_size = MLX5_GET(qpc, qpc, log_page_size) + 12; |
| 1357 | u32 log_rq_stride = MLX5_GET(qpc, qpc, log_rq_stride); |
| 1358 | u32 log_rq_size = MLX5_GET(qpc, qpc, log_rq_size); |
| 1359 | u32 page_offset = MLX5_GET(qpc, qpc, page_offset); |
| 1360 | u32 po_quanta = 1 << (log_page_size - 6); |
| 1361 | u32 rq_sz = 1 << (log_rq_size + 4 + log_rq_stride); |
| 1362 | u32 page_size = 1 << log_page_size; |
| 1363 | u32 rq_sz_po = rq_sz + (page_offset * po_quanta); |
| 1364 | u32 rq_num_pas = (rq_sz_po + page_size - 1) / page_size; |
| 1365 | |
| 1366 | return rq_num_pas * sizeof(u64); |
| 1367 | } |
| 1368 | |
| 1369 | static int create_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1370 | struct mlx5_ib_rq *rq, void *qpin, |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1371 | size_t qpinlen, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1372 | { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1373 | struct mlx5_ib_qp *mqp = rq->base.container_mibqp; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1374 | __be64 *pas; |
| 1375 | __be64 *qp_pas; |
| 1376 | void *in; |
| 1377 | void *rqc; |
| 1378 | void *wq; |
| 1379 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1380 | size_t rq_pas_size = get_rq_pas_size(qpc); |
| 1381 | size_t inlen; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1382 | int err; |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1383 | |
| 1384 | if (qpinlen < rq_pas_size + MLX5_BYTE_OFF(create_qp_in, pas)) |
| 1385 | return -EINVAL; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1386 | |
| 1387 | inlen = MLX5_ST_SZ_BYTES(create_rq_in) + rq_pas_size; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1388 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1389 | if (!in) |
| 1390 | return -ENOMEM; |
| 1391 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1392 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1393 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1394 | if (!(rq->flags & MLX5_IB_RQ_CVLAN_STRIPPING)) |
| 1395 | MLX5_SET(rqc, rqc, vsd, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1396 | MLX5_SET(rqc, rqc, mem_rq_type, MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 1397 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 1398 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 1399 | MLX5_SET(rqc, rqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1400 | MLX5_SET(rqc, rqc, cqn, MLX5_GET(qpc, qpc, cqn_rcv)); |
| 1401 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1402 | if (mqp->flags & IB_QP_CREATE_SCATTER_FCS) |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1403 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 1404 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1405 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
| 1406 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1407 | if (rq->flags & MLX5_IB_RQ_PCI_WRITE_END_PADDING) |
| 1408 | 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] | 1409 | MLX5_SET(wq, wq, page_offset, MLX5_GET(qpc, qpc, page_offset)); |
| 1410 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1411 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1412 | MLX5_SET(wq, wq, log_wq_stride, MLX5_GET(qpc, qpc, log_rq_stride) + 4); |
| 1413 | MLX5_SET(wq, wq, log_wq_pg_sz, MLX5_GET(qpc, qpc, log_page_size)); |
| 1414 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_rq_size)); |
| 1415 | |
| 1416 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1417 | qp_pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, qpin, pas); |
| 1418 | memcpy(pas, qp_pas, rq_pas_size); |
| 1419 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1420 | 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] | 1421 | |
| 1422 | kvfree(in); |
| 1423 | |
| 1424 | return err; |
| 1425 | } |
| 1426 | |
| 1427 | static void destroy_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
| 1428 | struct mlx5_ib_rq *rq) |
| 1429 | { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1430 | mlx5_core_destroy_rq_tracked(dev, &rq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1431 | } |
| 1432 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1433 | static bool tunnel_offload_supported(struct mlx5_core_dev *dev) |
| 1434 | { |
| 1435 | return (MLX5_CAP_ETH(dev, tunnel_stateless_vxlan) || |
| 1436 | MLX5_CAP_ETH(dev, tunnel_stateless_gre) || |
| 1437 | MLX5_CAP_ETH(dev, tunnel_stateless_geneve_rx)); |
| 1438 | } |
| 1439 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1440 | static void destroy_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
| 1441 | struct mlx5_ib_rq *rq, |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1442 | u32 qp_flags_en, |
| 1443 | struct ib_pd *pd) |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1444 | { |
| 1445 | if (qp_flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1446 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1447 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1448 | mlx5_cmd_destroy_tir(dev->mdev, rq->tirn, to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1449 | } |
| 1450 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1451 | static int create_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1452 | struct mlx5_ib_rq *rq, u32 tdn, |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1453 | u32 *qp_flags_en, struct ib_pd *pd, |
| 1454 | u32 *out) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1455 | { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1456 | u8 lb_flag = 0; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1457 | u32 *in; |
| 1458 | void *tirc; |
| 1459 | int inlen; |
| 1460 | int err; |
| 1461 | |
| 1462 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1463 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1464 | if (!in) |
| 1465 | return -ENOMEM; |
| 1466 | |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1467 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1468 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1469 | MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_DIRECT); |
| 1470 | MLX5_SET(tirc, tirc, inline_rqn, rq->base.mqp.qpn); |
| 1471 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1472 | if (*qp_flags_en & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1473 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1474 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1475 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) |
| 1476 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1477 | |
| 1478 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) |
| 1479 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
| 1480 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 1481 | if (dev->is_rep) { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1482 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1483 | *qp_flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 1484 | } |
| 1485 | |
| 1486 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1487 | MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR); |
| 1488 | err = mlx5_cmd_exec_inout(dev->mdev, create_tir, in, out); |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1489 | rq->tirn = MLX5_GET(create_tir_out, out, tirn); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1490 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1491 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1492 | |
| 1493 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1494 | destroy_raw_packet_qp_tir(dev, rq, 0, pd); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1495 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1496 | kvfree(in); |
| 1497 | |
| 1498 | return err; |
| 1499 | } |
| 1500 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1501 | 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] | 1502 | u32 *in, size_t inlen, |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1503 | struct ib_pd *pd, |
| 1504 | struct ib_udata *udata, |
| 1505 | struct mlx5_ib_create_qp_resp *resp) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1506 | { |
| 1507 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1508 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1509 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1510 | struct mlx5_ib_ucontext *mucontext = rdma_udata_to_drv_context( |
| 1511 | udata, struct mlx5_ib_ucontext, ibucontext); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1512 | int err; |
| 1513 | u32 tdn = mucontext->tdn; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1514 | u16 uid = to_mpd(pd)->uid; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1515 | u32 out[MLX5_ST_SZ_DW(create_tir_out)] = {}; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1516 | |
| 1517 | if (qp->sq.wqe_cnt) { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1518 | err = create_raw_packet_qp_tis(dev, qp, sq, tdn, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1519 | if (err) |
| 1520 | return err; |
| 1521 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1522 | err = create_raw_packet_qp_sq(dev, udata, sq, in, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1523 | if (err) |
| 1524 | goto err_destroy_tis; |
| 1525 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1526 | if (uid) { |
| 1527 | resp->tisn = sq->tisn; |
| 1528 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TISN; |
| 1529 | resp->sqn = sq->base.mqp.qpn; |
| 1530 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_SQN; |
| 1531 | } |
| 1532 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1533 | sq->base.container_mibqp = qp; |
Majd Dibbiny | 1d31e9c | 2017-08-23 08:35:41 +0300 | [diff] [blame] | 1534 | sq->base.mqp.event = mlx5_ib_qp_event; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | if (qp->rq.wqe_cnt) { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1538 | rq->base.container_mibqp = qp; |
| 1539 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1540 | if (qp->flags & IB_QP_CREATE_CVLAN_STRIPPING) |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1541 | rq->flags |= MLX5_IB_RQ_CVLAN_STRIPPING; |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1542 | if (qp->flags & IB_QP_CREATE_PCI_WRITE_END_PADDING) |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1543 | rq->flags |= MLX5_IB_RQ_PCI_WRITE_END_PADDING; |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1544 | err = create_raw_packet_qp_rq(dev, rq, in, inlen, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1545 | if (err) |
| 1546 | goto err_destroy_sq; |
| 1547 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1548 | err = create_raw_packet_qp_tir(dev, rq, tdn, &qp->flags_en, pd, |
| 1549 | out); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1550 | if (err) |
| 1551 | goto err_destroy_rq; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1552 | |
| 1553 | if (uid) { |
| 1554 | resp->rqn = rq->base.mqp.qpn; |
| 1555 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_RQN; |
| 1556 | resp->tirn = rq->tirn; |
| 1557 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1558 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner)) { |
| 1559 | resp->tir_icm_addr = MLX5_GET( |
| 1560 | create_tir_out, out, icm_address_31_0); |
| 1561 | resp->tir_icm_addr |= |
| 1562 | (u64)MLX5_GET(create_tir_out, out, |
| 1563 | icm_address_39_32) |
| 1564 | << 32; |
| 1565 | resp->tir_icm_addr |= |
| 1566 | (u64)MLX5_GET(create_tir_out, out, |
| 1567 | icm_address_63_40) |
| 1568 | << 40; |
| 1569 | resp->comp_mask |= |
| 1570 | MLX5_IB_CREATE_QP_RESP_MASK_TIR_ICM_ADDR; |
| 1571 | } |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1572 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | qp->trans_qp.base.mqp.qpn = qp->sq.wqe_cnt ? sq->base.mqp.qpn : |
| 1576 | rq->base.mqp.qpn; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1577 | err = ib_copy_to_udata(udata, resp, min(udata->outlen, sizeof(*resp))); |
| 1578 | if (err) |
| 1579 | goto err_destroy_tir; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1580 | |
| 1581 | return 0; |
| 1582 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1583 | err_destroy_tir: |
| 1584 | destroy_raw_packet_qp_tir(dev, rq, qp->flags_en, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1585 | err_destroy_rq: |
| 1586 | destroy_raw_packet_qp_rq(dev, rq); |
| 1587 | err_destroy_sq: |
| 1588 | if (!qp->sq.wqe_cnt) |
| 1589 | return err; |
| 1590 | destroy_raw_packet_qp_sq(dev, sq); |
| 1591 | err_destroy_tis: |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1592 | destroy_raw_packet_qp_tis(dev, sq, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1593 | |
| 1594 | return err; |
| 1595 | } |
| 1596 | |
| 1597 | static void destroy_raw_packet_qp(struct mlx5_ib_dev *dev, |
| 1598 | struct mlx5_ib_qp *qp) |
| 1599 | { |
| 1600 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1601 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1602 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1603 | |
| 1604 | if (qp->rq.wqe_cnt) { |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1605 | 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] | 1606 | destroy_raw_packet_qp_rq(dev, rq); |
| 1607 | } |
| 1608 | |
| 1609 | if (qp->sq.wqe_cnt) { |
| 1610 | destroy_raw_packet_qp_sq(dev, sq); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1611 | destroy_raw_packet_qp_tis(dev, sq, qp->ibqp.pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | static void raw_packet_qp_copy_info(struct mlx5_ib_qp *qp, |
| 1616 | struct mlx5_ib_raw_packet_qp *raw_packet_qp) |
| 1617 | { |
| 1618 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1619 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1620 | |
| 1621 | sq->sq = &qp->sq; |
| 1622 | rq->rq = &qp->rq; |
| 1623 | sq->doorbell = &qp->db; |
| 1624 | rq->doorbell = &qp->db; |
| 1625 | } |
| 1626 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1627 | static void destroy_rss_raw_qp_tir(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 1628 | { |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1629 | if (qp->flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1630 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1631 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1632 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1633 | to_mpd(qp->ibqp.pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1634 | } |
| 1635 | |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 1636 | static int create_rss_raw_qp_tir(struct ib_pd *pd, struct mlx5_ib_qp *qp, |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1637 | struct ib_qp_init_attr *init_attr, |
| 1638 | struct ib_udata *udata) |
| 1639 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1640 | struct mlx5_ib_ucontext *mucontext = rdma_udata_to_drv_context( |
| 1641 | udata, struct mlx5_ib_ucontext, ibucontext); |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 1642 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1643 | struct mlx5_ib_create_qp_resp resp = {}; |
| 1644 | int inlen; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1645 | int outlen; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1646 | int err; |
| 1647 | u32 *in; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1648 | u32 *out; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1649 | void *tirc; |
| 1650 | void *hfso; |
| 1651 | u32 selected_fields = 0; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1652 | u32 outer_l4; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1653 | size_t min_resp_len; |
| 1654 | u32 tdn = mucontext->tdn; |
| 1655 | struct mlx5_ib_create_qp_rss ucmd = {}; |
| 1656 | size_t required_cmd_sz; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1657 | u8 lb_flag = 0; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1658 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1659 | if (init_attr->send_cq) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1660 | return -EINVAL; |
| 1661 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1662 | min_resp_len = offsetof(typeof(resp), bfreg_index) + sizeof(resp.bfreg_index); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1663 | if (udata->outlen < min_resp_len) |
| 1664 | return -EINVAL; |
| 1665 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1666 | required_cmd_sz = offsetof(typeof(ucmd), flags) + sizeof(ucmd.flags); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1667 | if (udata->inlen < required_cmd_sz) { |
| 1668 | mlx5_ib_dbg(dev, "invalid inlen\n"); |
| 1669 | return -EINVAL; |
| 1670 | } |
| 1671 | |
| 1672 | if (udata->inlen > sizeof(ucmd) && |
| 1673 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 1674 | udata->inlen - sizeof(ucmd))) { |
| 1675 | mlx5_ib_dbg(dev, "inlen is not supported\n"); |
| 1676 | return -EOPNOTSUPP; |
| 1677 | } |
| 1678 | |
| 1679 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) { |
| 1680 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1681 | return -EFAULT; |
| 1682 | } |
| 1683 | |
| 1684 | if (ucmd.comp_mask) { |
| 1685 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 1686 | return -EOPNOTSUPP; |
| 1687 | } |
| 1688 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1689 | if (ucmd.flags & ~(MLX5_QP_FLAG_TUNNEL_OFFLOADS | |
| 1690 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1691 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) { |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1692 | mlx5_ib_dbg(dev, "invalid flags\n"); |
| 1693 | return -EOPNOTSUPP; |
| 1694 | } |
| 1695 | |
| 1696 | if (ucmd.flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS && |
| 1697 | !tunnel_offload_supported(dev->mdev)) { |
| 1698 | mlx5_ib_dbg(dev, "tunnel offloads isn't supported\n"); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1699 | return -EOPNOTSUPP; |
| 1700 | } |
| 1701 | |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1702 | if (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_INNER && |
| 1703 | !(ucmd.flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS)) { |
| 1704 | mlx5_ib_dbg(dev, "Tunnel offloads must be set for inner RSS\n"); |
| 1705 | return -EOPNOTSUPP; |
| 1706 | } |
| 1707 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 1708 | if (ucmd.flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC || dev->is_rep) { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1709 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1710 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 1711 | } |
| 1712 | |
| 1713 | if (ucmd.flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) { |
| 1714 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
| 1715 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC; |
| 1716 | } |
| 1717 | |
Jason Gunthorpe | 41d902c | 2018-04-03 10:00:53 +0300 | [diff] [blame] | 1718 | err = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp))); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1719 | if (err) { |
| 1720 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1721 | return -EINVAL; |
| 1722 | } |
| 1723 | |
| 1724 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1725 | outlen = MLX5_ST_SZ_BYTES(create_tir_out); |
| 1726 | in = kvzalloc(inlen + outlen, GFP_KERNEL); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1727 | if (!in) |
| 1728 | return -ENOMEM; |
| 1729 | |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1730 | out = in + MLX5_ST_SZ_DW(create_tir_in); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1731 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1732 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1733 | MLX5_SET(tirc, tirc, disp_type, |
| 1734 | MLX5_TIRC_DISP_TYPE_INDIRECT); |
| 1735 | MLX5_SET(tirc, tirc, indirect_table, |
| 1736 | init_attr->rwq_ind_tbl->ind_tbl_num); |
| 1737 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
| 1738 | |
| 1739 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1740 | |
| 1741 | if (ucmd.flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
| 1742 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
| 1743 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1744 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
| 1745 | |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1746 | if (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_INNER) |
| 1747 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_inner); |
| 1748 | else |
| 1749 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
| 1750 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1751 | switch (ucmd.rx_hash_function) { |
| 1752 | case MLX5_RX_HASH_FUNC_TOEPLITZ: |
| 1753 | { |
| 1754 | void *rss_key = MLX5_ADDR_OF(tirc, tirc, rx_hash_toeplitz_key); |
| 1755 | size_t len = MLX5_FLD_SZ_BYTES(tirc, rx_hash_toeplitz_key); |
| 1756 | |
| 1757 | if (len != ucmd.rx_key_len) { |
| 1758 | err = -EINVAL; |
| 1759 | goto err; |
| 1760 | } |
| 1761 | |
| 1762 | MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_TOEPLITZ); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1763 | memcpy(rss_key, ucmd.rx_hash_key, len); |
| 1764 | break; |
| 1765 | } |
| 1766 | default: |
| 1767 | err = -EOPNOTSUPP; |
| 1768 | goto err; |
| 1769 | } |
| 1770 | |
| 1771 | if (!ucmd.rx_hash_fields_mask) { |
| 1772 | /* special case when this TIR serves as steering entry without hashing */ |
| 1773 | if (!init_attr->rwq_ind_tbl->log_ind_tbl_size) |
| 1774 | goto create_tir; |
| 1775 | err = -EINVAL; |
| 1776 | goto err; |
| 1777 | } |
| 1778 | |
| 1779 | if (((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1780 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) && |
| 1781 | ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1782 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6))) { |
| 1783 | err = -EINVAL; |
| 1784 | goto err; |
| 1785 | } |
| 1786 | |
| 1787 | /* If none of IPV4 & IPV6 SRC/DST was set - this bit field is ignored */ |
| 1788 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1789 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) |
| 1790 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1791 | MLX5_L3_PROT_TYPE_IPV4); |
| 1792 | else if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1793 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
| 1794 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1795 | MLX5_L3_PROT_TYPE_IPV6); |
| 1796 | |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1797 | outer_l4 = ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1798 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) << 0 | |
| 1799 | ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1800 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) << 1 | |
| 1801 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) << 2; |
| 1802 | |
| 1803 | /* Check that only one l4 protocol is set */ |
| 1804 | if (outer_l4 & (outer_l4 - 1)) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1805 | err = -EINVAL; |
| 1806 | goto err; |
| 1807 | } |
| 1808 | |
| 1809 | /* If none of TCP & UDP SRC/DST was set - this bit field is ignored */ |
| 1810 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1811 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) |
| 1812 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1813 | MLX5_L4_PROT_TYPE_TCP); |
| 1814 | else if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1815 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
| 1816 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1817 | MLX5_L4_PROT_TYPE_UDP); |
| 1818 | |
| 1819 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1820 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6)) |
| 1821 | selected_fields |= MLX5_HASH_FIELD_SEL_SRC_IP; |
| 1822 | |
| 1823 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4) || |
| 1824 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
| 1825 | selected_fields |= MLX5_HASH_FIELD_SEL_DST_IP; |
| 1826 | |
| 1827 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1828 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP)) |
| 1829 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_SPORT; |
| 1830 | |
| 1831 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP) || |
| 1832 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
| 1833 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_DPORT; |
| 1834 | |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1835 | if (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) |
| 1836 | selected_fields |= MLX5_HASH_FIELD_SEL_IPSEC_SPI; |
| 1837 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1838 | MLX5_SET(rx_hash_field_select, hfso, selected_fields, selected_fields); |
| 1839 | |
| 1840 | create_tir: |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1841 | MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR); |
| 1842 | err = mlx5_cmd_exec_inout(dev->mdev, create_tir, in, out); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1843 | |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1844 | qp->rss_qp.tirn = MLX5_GET(create_tir_out, out, tirn); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1845 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1846 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1847 | |
| 1848 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1849 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1850 | to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1851 | } |
| 1852 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1853 | if (err) |
| 1854 | goto err; |
| 1855 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1856 | if (mucontext->devx_uid) { |
| 1857 | resp.comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
| 1858 | resp.tirn = qp->rss_qp.tirn; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1859 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner)) { |
| 1860 | resp.tir_icm_addr = |
| 1861 | MLX5_GET(create_tir_out, out, icm_address_31_0); |
| 1862 | resp.tir_icm_addr |= (u64)MLX5_GET(create_tir_out, out, |
| 1863 | icm_address_39_32) |
| 1864 | << 32; |
| 1865 | resp.tir_icm_addr |= (u64)MLX5_GET(create_tir_out, out, |
| 1866 | icm_address_63_40) |
| 1867 | << 40; |
| 1868 | resp.comp_mask |= |
| 1869 | MLX5_IB_CREATE_QP_RESP_MASK_TIR_ICM_ADDR; |
| 1870 | } |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | err = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp))); |
| 1874 | if (err) |
| 1875 | goto err_copy; |
| 1876 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1877 | kvfree(in); |
| 1878 | /* qpn is reserved for that QP */ |
| 1879 | qp->trans_qp.base.mqp.qpn = 0; |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1880 | qp->is_rss = true; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1881 | return 0; |
| 1882 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1883 | err_copy: |
| 1884 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, mucontext->devx_uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1885 | err: |
| 1886 | kvfree(in); |
| 1887 | return err; |
| 1888 | } |
| 1889 | |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1890 | static void configure_requester_scat_cqe(struct mlx5_ib_dev *dev, |
| 1891 | struct ib_qp_init_attr *init_attr, |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1892 | struct mlx5_ib_create_qp *ucmd, |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1893 | void *qpc) |
| 1894 | { |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1895 | int scqe_sz; |
zhengbin | 2ab367a | 2019-12-24 16:40:12 +0800 | [diff] [blame] | 1896 | bool allow_scat_cqe = false; |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1897 | |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1898 | if (ucmd) |
| 1899 | allow_scat_cqe = ucmd->flags & MLX5_QP_FLAG_ALLOW_SCATTER_CQE; |
| 1900 | |
| 1901 | 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] | 1902 | return; |
| 1903 | |
| 1904 | scqe_sz = mlx5_ib_get_cqe_size(init_attr->send_cq); |
| 1905 | if (scqe_sz == 128) { |
| 1906 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA64_CQE); |
| 1907 | return; |
| 1908 | } |
| 1909 | |
| 1910 | if (init_attr->qp_type != MLX5_IB_QPT_DCI || |
| 1911 | MLX5_CAP_GEN(dev->mdev, dc_req_scat_data_cqe)) |
| 1912 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA32_CQE); |
| 1913 | } |
| 1914 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 1915 | static int atomic_size_to_mode(int size_mask) |
| 1916 | { |
| 1917 | /* driver does not support atomic_size > 256B |
| 1918 | * and does not know how to translate bigger sizes |
| 1919 | */ |
| 1920 | int supported_size_mask = size_mask & 0x1ff; |
| 1921 | int log_max_size; |
| 1922 | |
| 1923 | if (!supported_size_mask) |
| 1924 | return -EOPNOTSUPP; |
| 1925 | |
| 1926 | log_max_size = __fls(supported_size_mask); |
| 1927 | |
| 1928 | if (log_max_size > 3) |
| 1929 | return log_max_size; |
| 1930 | |
| 1931 | return MLX5_ATOMIC_MODE_8B; |
| 1932 | } |
| 1933 | |
| 1934 | static int get_atomic_mode(struct mlx5_ib_dev *dev, |
| 1935 | enum ib_qp_type qp_type) |
| 1936 | { |
| 1937 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
| 1938 | u8 atomic = MLX5_CAP_GEN(dev->mdev, atomic); |
| 1939 | int atomic_mode = -EOPNOTSUPP; |
| 1940 | int atomic_size_mask; |
| 1941 | |
| 1942 | if (!atomic) |
| 1943 | return -EOPNOTSUPP; |
| 1944 | |
| 1945 | if (qp_type == MLX5_IB_QPT_DCT) |
| 1946 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 1947 | else |
| 1948 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 1949 | |
| 1950 | if ((atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP) || |
| 1951 | (atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD)) |
| 1952 | atomic_mode = atomic_size_to_mode(atomic_size_mask); |
| 1953 | |
| 1954 | if (atomic_mode <= 0 && |
| 1955 | (atomic_operations & MLX5_ATOMIC_OPS_CMP_SWAP && |
| 1956 | atomic_operations & MLX5_ATOMIC_OPS_FETCH_ADD)) |
| 1957 | atomic_mode = MLX5_ATOMIC_MODE_IB_COMP; |
| 1958 | |
| 1959 | return atomic_mode; |
| 1960 | } |
| 1961 | |
Yonatan Cohen | 2e43bb3 | 2018-10-09 12:05:14 +0300 | [diff] [blame] | 1962 | static inline bool check_flags_mask(uint64_t input, uint64_t supported) |
| 1963 | { |
| 1964 | return (input & ~supported) == 0; |
| 1965 | } |
| 1966 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1967 | static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 1968 | struct ib_qp_init_attr *init_attr, |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 1969 | struct mlx5_ib_create_qp *ucmd, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1970 | struct ib_udata *udata, struct mlx5_ib_qp *qp) |
| 1971 | { |
| 1972 | struct mlx5_ib_resources *devr = &dev->devr; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1973 | int inlen = MLX5_ST_SZ_BYTES(create_qp_in); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1974 | struct mlx5_core_dev *mdev = dev->mdev; |
Jason Gunthorpe | 0625b4b | 2018-08-14 15:33:52 -0600 | [diff] [blame] | 1975 | struct mlx5_ib_create_qp_resp resp = {}; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1976 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 1977 | udata, struct mlx5_ib_ucontext, ibucontext); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 1978 | struct mlx5_ib_cq *send_cq; |
| 1979 | struct mlx5_ib_cq *recv_cq; |
| 1980 | unsigned long flags; |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1981 | u32 uidx = MLX5_IB_DEFAULT_UIDX; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1982 | struct mlx5_ib_qp_base *base; |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1983 | int mlx5_st; |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1984 | void *qpc; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1985 | u32 *in; |
| 1986 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1987 | |
| 1988 | mutex_init(&qp->mutex); |
| 1989 | spin_lock_init(&qp->sq.lock); |
| 1990 | spin_lock_init(&qp->rq.lock); |
| 1991 | |
Leon Romanovsky | 8bde2c5 | 2020-04-27 18:46:09 +0300 | [diff] [blame] | 1992 | mlx5_st = to_mlx5_st((init_attr->qp_type != IB_QPT_DRIVER) ? |
| 1993 | init_attr->qp_type : |
| 1994 | qp->qp_sub_type); |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1995 | if (mlx5_st < 0) |
| 1996 | return -EINVAL; |
| 1997 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1998 | if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) |
| 1999 | qp->sq_signal_bits = MLX5_WQE_CTRL_CQ_UPDATE; |
| 2000 | |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 2001 | if (udata) { |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2002 | if (!check_flags_mask(ucmd->flags, |
Mark Bloch | 8af526e | 2019-01-15 16:45:32 +0200 | [diff] [blame] | 2003 | MLX5_QP_FLAG_ALLOW_SCATTER_CQE | |
| 2004 | MLX5_QP_FLAG_BFREG_INDEX | |
| 2005 | MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE | |
| 2006 | MLX5_QP_FLAG_SCATTER_CQE | |
Yonatan Cohen | 2e43bb3 | 2018-10-09 12:05:14 +0300 | [diff] [blame] | 2007 | MLX5_QP_FLAG_SIGNATURE | |
Mark Bloch | 8af526e | 2019-01-15 16:45:32 +0200 | [diff] [blame] | 2008 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC | |
| 2009 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 2010 | MLX5_QP_FLAG_TUNNEL_OFFLOADS | |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 2011 | MLX5_QP_FLAG_UAR_PAGE_INDEX | |
Mark Bloch | 8af526e | 2019-01-15 16:45:32 +0200 | [diff] [blame] | 2012 | MLX5_QP_FLAG_TYPE_DCI | |
| 2013 | MLX5_QP_FLAG_TYPE_DCT)) |
Yonatan Cohen | 2e43bb3 | 2018-10-09 12:05:14 +0300 | [diff] [blame] | 2014 | return -EINVAL; |
| 2015 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2016 | err = get_qp_user_index(ucontext, ucmd, udata->inlen, &uidx); |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2017 | if (err) |
| 2018 | return err; |
| 2019 | |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 2020 | if (ucmd->flags & MLX5_QP_FLAG_SIGNATURE) |
| 2021 | qp->flags_en |= MLX5_QP_FLAG_SIGNATURE; |
Leon Romanovsky | 90ecb37 | 2020-04-27 18:46:16 +0300 | [diff] [blame] | 2022 | if (ucmd->flags & MLX5_QP_FLAG_SCATTER_CQE && |
| 2023 | MLX5_CAP_GEN(dev->mdev, sctr_data_cqe)) |
| 2024 | qp->flags_en |= MLX5_QP_FLAG_SCATTER_CQE; |
| 2025 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2026 | if (ucmd->flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS) { |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 2027 | if (init_attr->qp_type != IB_QPT_RAW_PACKET || |
| 2028 | !tunnel_offload_supported(mdev)) { |
| 2029 | mlx5_ib_dbg(dev, "Tunnel offload isn't supported\n"); |
| 2030 | return -EOPNOTSUPP; |
| 2031 | } |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 2032 | qp->flags_en |= MLX5_QP_FLAG_TUNNEL_OFFLOADS; |
| 2033 | } |
| 2034 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2035 | if (ucmd->flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 2036 | if (init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 2037 | mlx5_ib_dbg(dev, "Self-LB UC isn't supported\n"); |
| 2038 | return -EOPNOTSUPP; |
| 2039 | } |
| 2040 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 2041 | } |
| 2042 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2043 | if (ucmd->flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 2044 | if (init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 2045 | mlx5_ib_dbg(dev, "Self-LB UM isn't supported\n"); |
| 2046 | return -EOPNOTSUPP; |
| 2047 | } |
| 2048 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 2049 | } |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2050 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2051 | if (ucmd->flags & MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE) { |
Danit Goldberg | 569c665 | 2018-11-30 13:22:05 +0200 | [diff] [blame] | 2052 | if (init_attr->qp_type != IB_QPT_RC || |
| 2053 | !MLX5_CAP_GEN(dev->mdev, qp_packet_based)) { |
| 2054 | mlx5_ib_dbg(dev, "packet based credit mode isn't supported\n"); |
| 2055 | return -EOPNOTSUPP; |
| 2056 | } |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2057 | qp->flags_en |= MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE; |
Danit Goldberg | 569c665 | 2018-11-30 13:22:05 +0200 | [diff] [blame] | 2058 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2059 | } |
| 2060 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2061 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
| 2062 | qp->underlay_qpn = init_attr->source_qpn; |
| 2063 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2064 | base = (init_attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2065 | qp->flags & IB_QP_CREATE_SOURCE_QPN) ? |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2066 | &qp->raw_packet_qp.rq.base : |
| 2067 | &qp->trans_qp.base; |
| 2068 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2069 | qp->has_rq = qp_has_rq(init_attr); |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2070 | 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] | 2071 | if (err) { |
| 2072 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 2073 | return err; |
| 2074 | } |
| 2075 | |
| 2076 | if (pd) { |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 2077 | if (udata) { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2078 | __u32 max_wqes = |
| 2079 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2080 | mlx5_ib_dbg(dev, "requested sq_wqe_count (%d)\n", |
| 2081 | ucmd->sq_wqe_count); |
| 2082 | if (ucmd->rq_wqe_shift != qp->rq.wqe_shift || |
| 2083 | ucmd->rq_wqe_count != qp->rq.wqe_cnt) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2084 | mlx5_ib_dbg(dev, "invalid rq params\n"); |
| 2085 | return -EINVAL; |
| 2086 | } |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2087 | if (ucmd->sq_wqe_count > max_wqes) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2088 | mlx5_ib_dbg(dev, "requested sq_wqe_count (%d) > max allowed (%d)\n", |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2089 | ucmd->sq_wqe_count, max_wqes); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2090 | return -EINVAL; |
| 2091 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2092 | err = create_user_qp(dev, pd, qp, udata, init_attr, &in, |
| 2093 | &resp, &inlen, base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2094 | if (err) |
| 2095 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 2096 | } else { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2097 | err = create_kernel_qp(dev, init_attr, qp, &in, &inlen, |
| 2098 | base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2099 | if (err) |
| 2100 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | if (err) |
| 2104 | return err; |
| 2105 | } else { |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2106 | in = kvzalloc(inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2107 | if (!in) |
| 2108 | return -ENOMEM; |
| 2109 | |
| 2110 | qp->create_type = MLX5_QP_EMPTY; |
| 2111 | } |
| 2112 | |
| 2113 | if (is_sqp(init_attr->qp_type)) |
| 2114 | qp->port = init_attr->port_num; |
| 2115 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2116 | qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); |
| 2117 | |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 2118 | MLX5_SET(qpc, qpc, st, mlx5_st); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2119 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2120 | |
| 2121 | if (init_attr->qp_type != MLX5_IB_QPT_REG_UMR) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2122 | MLX5_SET(qpc, qpc, pd, to_mpd(pd ? pd : devr->p0)->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2123 | else |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2124 | MLX5_SET(qpc, qpc, latency_sensitive, 1); |
| 2125 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2126 | |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 2127 | if (qp->flags_en & MLX5_QP_FLAG_SIGNATURE) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2128 | MLX5_SET(qpc, qpc, wq_signature, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2129 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2130 | if (qp->flags & IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2131 | MLX5_SET(qpc, qpc, block_lb_mc, 1); |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 2132 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2133 | if (qp->flags & IB_QP_CREATE_CROSS_CHANNEL) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2134 | MLX5_SET(qpc, qpc, cd_master, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2135 | if (qp->flags & IB_QP_CREATE_MANAGED_SEND) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2136 | MLX5_SET(qpc, qpc, cd_slave_send, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2137 | if (qp->flags & IB_QP_CREATE_MANAGED_RECV) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2138 | MLX5_SET(qpc, qpc, cd_slave_receive, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2139 | if (qp->flags_en & MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE) |
Danit Goldberg | 569c665 | 2018-11-30 13:22:05 +0200 | [diff] [blame] | 2140 | MLX5_SET(qpc, qpc, req_e2e_credit_mode, 1); |
Leon Romanovsky | 90ecb37 | 2020-04-27 18:46:16 +0300 | [diff] [blame] | 2141 | if ((qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) && |
| 2142 | (init_attr->qp_type == IB_QPT_RC || |
| 2143 | init_attr->qp_type == IB_QPT_UC)) { |
Leon Romanovsky | 8bde2c5 | 2020-04-27 18:46:09 +0300 | [diff] [blame] | 2144 | int rcqe_sz = rcqe_sz = |
| 2145 | mlx5_ib_get_cqe_size(init_attr->recv_cq); |
| 2146 | |
| 2147 | MLX5_SET(qpc, qpc, cs_res, |
| 2148 | rcqe_sz == 128 ? MLX5_RES_SCAT_DATA64_CQE : |
| 2149 | MLX5_RES_SCAT_DATA32_CQE); |
| 2150 | } |
Leon Romanovsky | 90ecb37 | 2020-04-27 18:46:16 +0300 | [diff] [blame] | 2151 | if ((qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) && |
| 2152 | (qp->qp_sub_type == MLX5_IB_QPT_DCI || |
| 2153 | init_attr->qp_type == IB_QPT_RC)) |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2154 | configure_requester_scat_cqe(dev, init_attr, ucmd, qpc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2155 | |
| 2156 | if (qp->rq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2157 | MLX5_SET(qpc, qpc, log_rq_stride, qp->rq.wqe_shift - 4); |
| 2158 | MLX5_SET(qpc, qpc, log_rq_size, ilog2(qp->rq.wqe_cnt)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2159 | } |
| 2160 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2161 | MLX5_SET(qpc, qpc, rq_type, get_rx_type(qp, init_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2162 | |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2163 | if (qp->sq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2164 | MLX5_SET(qpc, qpc, log_sq_size, ilog2(qp->sq.wqe_cnt)); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2165 | } else { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2166 | MLX5_SET(qpc, qpc, no_sq, 1); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2167 | if (init_attr->srq && |
| 2168 | init_attr->srq->srq_type == IB_SRQT_TM) |
| 2169 | MLX5_SET(qpc, qpc, offload_type, |
| 2170 | MLX5_QPC_OFFLOAD_TYPE_RNDV); |
| 2171 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2172 | |
| 2173 | /* Set default resources */ |
| 2174 | switch (init_attr->qp_type) { |
| 2175 | case IB_QPT_XRC_TGT: |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2176 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
| 2177 | MLX5_SET(qpc, qpc, cqn_snd, to_mcq(devr->c0)->mcq.cqn); |
| 2178 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, to_msrq(devr->s0)->msrq.srqn); |
| 2179 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(init_attr->xrcd)->xrcdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2180 | break; |
| 2181 | case IB_QPT_XRC_INI: |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2182 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
| 2183 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x1)->xrcdn); |
| 2184 | 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] | 2185 | break; |
| 2186 | default: |
| 2187 | if (init_attr->srq) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2188 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x0)->xrcdn); |
| 2189 | 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] | 2190 | } else { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2191 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x1)->xrcdn); |
| 2192 | 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] | 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | if (init_attr->send_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2197 | 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] | 2198 | |
| 2199 | if (init_attr->recv_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2200 | 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] | 2201 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2202 | MLX5_SET64(qpc, qpc, dbr_addr, qp->db.dma); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2203 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2204 | /* 0xffffff means we ask to work with cqe version 0 */ |
| 2205 | if (MLX5_CAP_GEN(mdev, cqe_version) == MLX5_CQE_VERSION_V1) |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2206 | MLX5_SET(qpc, qpc, user_index, uidx); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2207 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 2208 | /* we use IB_QP_CREATE_IPOIB_UD_LSO to indicates ipoib qp */ |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2209 | if (qp->flags & IB_QP_CREATE_IPOIB_UD_LSO) |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 2210 | MLX5_SET(qpc, qpc, ulp_stateless_offload_mode, 1); |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2211 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2212 | if (qp->flags & IB_QP_CREATE_PCI_WRITE_END_PADDING && |
| 2213 | init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 2214 | MLX5_SET(qpc, qpc, end_padding_mode, |
| 2215 | MLX5_WQ_END_PAD_MODE_ALIGN); |
| 2216 | /* Special case to clean flag */ |
| 2217 | qp->flags &= ~IB_QP_CREATE_PCI_WRITE_END_PADDING; |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 2218 | } |
| 2219 | |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 2220 | if (inlen < 0) { |
| 2221 | err = -EINVAL; |
| 2222 | goto err; |
| 2223 | } |
| 2224 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2225 | if (init_attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2226 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2227 | 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] | 2228 | raw_packet_qp_copy_info(qp, &qp->raw_packet_qp); |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 2229 | err = create_raw_packet_qp(dev, qp, in, inlen, pd, udata, |
| 2230 | &resp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2231 | } else { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2232 | err = mlx5_core_create_qp(dev, &base->mqp, in, inlen); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2233 | } |
| 2234 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2235 | if (err) { |
| 2236 | mlx5_ib_dbg(dev, "create qp failed\n"); |
| 2237 | goto err_create; |
| 2238 | } |
| 2239 | |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 2240 | kvfree(in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2241 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2242 | base->container_mibqp = qp; |
| 2243 | base->mqp.event = mlx5_ib_qp_event; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2244 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2245 | get_cqs(init_attr->qp_type, init_attr->send_cq, init_attr->recv_cq, |
| 2246 | &send_cq, &recv_cq); |
| 2247 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2248 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2249 | /* Maintain device to QPs access, needed for further handling via reset |
| 2250 | * flow |
| 2251 | */ |
| 2252 | list_add_tail(&qp->qps_list, &dev->qp_list); |
| 2253 | /* Maintain CQ to QPs access, needed for further handling via reset flow |
| 2254 | */ |
| 2255 | if (send_cq) |
| 2256 | list_add_tail(&qp->cq_send_list, &send_cq->list_send_qp); |
| 2257 | if (recv_cq) |
| 2258 | list_add_tail(&qp->cq_recv_list, &recv_cq->list_recv_qp); |
| 2259 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2260 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 2261 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2262 | return 0; |
| 2263 | |
| 2264 | err_create: |
| 2265 | if (qp->create_type == MLX5_QP_USER) |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2266 | destroy_qp_user(dev, pd, qp, base, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2267 | else if (qp->create_type == MLX5_QP_KERNEL) |
| 2268 | destroy_qp_kernel(dev, qp); |
| 2269 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 2270 | err: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 2271 | kvfree(in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2272 | return err; |
| 2273 | } |
| 2274 | |
| 2275 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2276 | __acquires(&send_cq->lock) __acquires(&recv_cq->lock) |
| 2277 | { |
| 2278 | if (send_cq) { |
| 2279 | if (recv_cq) { |
| 2280 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2281 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2282 | spin_lock_nested(&recv_cq->lock, |
| 2283 | SINGLE_DEPTH_NESTING); |
| 2284 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2285 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2286 | __acquire(&recv_cq->lock); |
| 2287 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2288 | spin_lock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2289 | spin_lock_nested(&send_cq->lock, |
| 2290 | SINGLE_DEPTH_NESTING); |
| 2291 | } |
| 2292 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2293 | spin_lock(&send_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2294 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2295 | } |
| 2296 | } else if (recv_cq) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2297 | spin_lock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2298 | __acquire(&send_cq->lock); |
| 2299 | } else { |
| 2300 | __acquire(&send_cq->lock); |
| 2301 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2302 | } |
| 2303 | } |
| 2304 | |
| 2305 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2306 | __releases(&send_cq->lock) __releases(&recv_cq->lock) |
| 2307 | { |
| 2308 | if (send_cq) { |
| 2309 | if (recv_cq) { |
| 2310 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
| 2311 | spin_unlock(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2312 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2313 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
| 2314 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2315 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2316 | } else { |
| 2317 | spin_unlock(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2318 | spin_unlock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2319 | } |
| 2320 | } else { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2321 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2322 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2323 | } |
| 2324 | } else if (recv_cq) { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2325 | __release(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2326 | spin_unlock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2327 | } else { |
| 2328 | __release(&recv_cq->lock); |
| 2329 | __release(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2330 | } |
| 2331 | } |
| 2332 | |
| 2333 | static struct mlx5_ib_pd *get_pd(struct mlx5_ib_qp *qp) |
| 2334 | { |
| 2335 | return to_mpd(qp->ibqp.pd); |
| 2336 | } |
| 2337 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2338 | static void get_cqs(enum ib_qp_type qp_type, |
| 2339 | struct ib_cq *ib_send_cq, struct ib_cq *ib_recv_cq, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2340 | struct mlx5_ib_cq **send_cq, struct mlx5_ib_cq **recv_cq) |
| 2341 | { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2342 | switch (qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2343 | case IB_QPT_XRC_TGT: |
| 2344 | *send_cq = NULL; |
| 2345 | *recv_cq = NULL; |
| 2346 | break; |
| 2347 | case MLX5_IB_QPT_REG_UMR: |
| 2348 | case IB_QPT_XRC_INI: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2349 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2350 | *recv_cq = NULL; |
| 2351 | break; |
| 2352 | |
| 2353 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2354 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2355 | case IB_QPT_RC: |
| 2356 | case IB_QPT_UC: |
| 2357 | case IB_QPT_UD: |
| 2358 | case IB_QPT_RAW_IPV6: |
| 2359 | case IB_QPT_RAW_ETHERTYPE: |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2360 | case IB_QPT_RAW_PACKET: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2361 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
| 2362 | *recv_cq = ib_recv_cq ? to_mcq(ib_recv_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2363 | break; |
| 2364 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2365 | case IB_QPT_MAX: |
| 2366 | default: |
| 2367 | *send_cq = NULL; |
| 2368 | *recv_cq = NULL; |
| 2369 | break; |
| 2370 | } |
| 2371 | } |
| 2372 | |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2373 | 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] | 2374 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 2375 | u8 lag_tx_affinity); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2376 | |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2377 | static void destroy_qp_common(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2378 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2379 | { |
| 2380 | struct mlx5_ib_cq *send_cq, *recv_cq; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2381 | struct mlx5_ib_qp_base *base; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2382 | unsigned long flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2383 | int err; |
| 2384 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 2385 | if (qp->ibqp.rwq_ind_tbl) { |
| 2386 | destroy_rss_raw_qp_tir(dev, qp); |
| 2387 | return; |
| 2388 | } |
| 2389 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2390 | base = (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2391 | qp->flags & IB_QP_CREATE_SOURCE_QPN) ? |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2392 | &qp->raw_packet_qp.rq.base : |
| 2393 | &qp->trans_qp.base; |
| 2394 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2395 | if (qp->state != IB_QPS_RESET) { |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2396 | if (qp->ibqp.qp_type != IB_QPT_RAW_PACKET && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2397 | !(qp->flags & IB_QP_CREATE_SOURCE_QPN)) { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2398 | err = mlx5_core_qp_modify(dev, MLX5_CMD_OP_2RST_QP, 0, |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 2399 | NULL, &base->mqp); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2400 | } else { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 2401 | struct mlx5_modify_raw_qp_param raw_qp_param = { |
| 2402 | .operation = MLX5_CMD_OP_2RST_QP |
| 2403 | }; |
| 2404 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2405 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, 0); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2406 | } |
| 2407 | if (err) |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 2408 | 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] | 2409 | base->mqp.qpn); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2410 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2411 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2412 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 2413 | &send_cq, &recv_cq); |
| 2414 | |
| 2415 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2416 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2417 | /* del from lists under both locks above to protect reset flow paths */ |
| 2418 | list_del(&qp->qps_list); |
| 2419 | if (send_cq) |
| 2420 | list_del(&qp->cq_send_list); |
| 2421 | |
| 2422 | if (recv_cq) |
| 2423 | list_del(&qp->cq_recv_list); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2424 | |
| 2425 | if (qp->create_type == MLX5_QP_KERNEL) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2426 | __mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2427 | qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL); |
| 2428 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2429 | __mlx5_ib_cq_clean(send_cq, base->mqp.qpn, |
| 2430 | NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2431 | } |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2432 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2433 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2434 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2435 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2436 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2437 | destroy_raw_packet_qp(dev, qp); |
| 2438 | } else { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2439 | err = mlx5_core_destroy_qp(dev, &base->mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2440 | if (err) |
| 2441 | mlx5_ib_warn(dev, "failed to destroy QP 0x%x\n", |
| 2442 | base->mqp.qpn); |
| 2443 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2444 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2445 | if (qp->create_type == MLX5_QP_KERNEL) |
| 2446 | destroy_qp_kernel(dev, qp); |
| 2447 | else if (qp->create_type == MLX5_QP_USER) |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2448 | destroy_qp_user(dev, &get_pd(qp)->ibpd, qp, base, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2449 | } |
| 2450 | |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2451 | static int create_dct(struct ib_pd *pd, struct mlx5_ib_qp *qp, |
| 2452 | struct ib_qp_init_attr *attr, |
| 2453 | struct mlx5_ib_create_qp *ucmd, struct ib_udata *udata) |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2454 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 2455 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 2456 | udata, struct mlx5_ib_ucontext, ibucontext); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2457 | int err = 0; |
| 2458 | u32 uidx = MLX5_IB_DEFAULT_UIDX; |
| 2459 | void *dctc; |
| 2460 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 2461 | err = get_qp_user_index(ucontext, ucmd, sizeof(*ucmd), &uidx); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2462 | if (err) |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2463 | return err; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2464 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2465 | 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] | 2466 | if (!qp->dct.in) |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2467 | return -ENOMEM; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2468 | |
Yishai Hadas | a01a586 | 2018-09-20 21:39:24 +0300 | [diff] [blame] | 2469 | 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] | 2470 | 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] | 2471 | MLX5_SET(dctc, dctc, pd, to_mpd(pd)->pdn); |
| 2472 | MLX5_SET(dctc, dctc, srqn_xrqn, to_msrq(attr->srq)->msrq.srqn); |
| 2473 | MLX5_SET(dctc, dctc, cqn, to_mcq(attr->recv_cq)->mcq.cqn); |
| 2474 | MLX5_SET64(dctc, dctc, dc_access_key, ucmd->access_key); |
| 2475 | MLX5_SET(dctc, dctc, user_index, uidx); |
| 2476 | |
Leon Romanovsky | fd9dab7 | 2020-04-27 18:46:08 +0300 | [diff] [blame] | 2477 | if (ucmd->flags & MLX5_QP_FLAG_SCATTER_CQE) { |
| 2478 | int rcqe_sz = mlx5_ib_get_cqe_size(attr->recv_cq); |
| 2479 | |
| 2480 | if (rcqe_sz == 128) |
| 2481 | MLX5_SET(dctc, dctc, cs_res, MLX5_RES_SCAT_DATA64_CQE); |
| 2482 | } |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 2483 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2484 | qp->state = IB_QPS_RESET; |
| 2485 | |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2486 | return 0; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2487 | } |
| 2488 | |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2489 | static int check_qp_type(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr) |
| 2490 | { |
| 2491 | if (attr->qp_type == IB_QPT_DRIVER && !MLX5_CAP_GEN(dev->mdev, dct)) |
| 2492 | goto out; |
| 2493 | |
| 2494 | switch (attr->qp_type) { |
| 2495 | case IB_QPT_XRC_TGT: |
| 2496 | case IB_QPT_XRC_INI: |
| 2497 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
| 2498 | goto out; |
| 2499 | fallthrough; |
| 2500 | case IB_QPT_RAW_PACKET: |
| 2501 | case IB_QPT_RC: |
| 2502 | case IB_QPT_UC: |
| 2503 | case IB_QPT_UD: |
| 2504 | case IB_QPT_SMI: |
| 2505 | case MLX5_IB_QPT_HW_GSI: |
| 2506 | case MLX5_IB_QPT_REG_UMR: |
| 2507 | case IB_QPT_DRIVER: |
| 2508 | case IB_QPT_GSI: |
| 2509 | return 0; |
| 2510 | case IB_QPT_RAW_IPV6: |
| 2511 | case IB_QPT_RAW_ETHERTYPE: |
| 2512 | case IB_QPT_MAX: |
| 2513 | default: |
| 2514 | goto out; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | return 0; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2518 | |
| 2519 | out: |
| 2520 | mlx5_ib_dbg(dev, "Unsupported QP type %d\n", attr->qp_type); |
| 2521 | return -EOPNOTSUPP; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2522 | } |
| 2523 | |
Leon Romanovsky | 2242cc2 | 2020-04-27 18:46:03 +0300 | [diff] [blame] | 2524 | static int check_valid_flow(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 2525 | struct ib_qp_init_attr *attr, |
| 2526 | struct ib_udata *udata) |
| 2527 | { |
| 2528 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 2529 | udata, struct mlx5_ib_ucontext, ibucontext); |
| 2530 | |
| 2531 | if (!udata) { |
| 2532 | /* Kernel create_qp callers */ |
| 2533 | if (attr->rwq_ind_tbl) |
| 2534 | return -EOPNOTSUPP; |
| 2535 | |
| 2536 | switch (attr->qp_type) { |
| 2537 | case IB_QPT_RAW_PACKET: |
| 2538 | case IB_QPT_DRIVER: |
| 2539 | return -EOPNOTSUPP; |
| 2540 | default: |
| 2541 | return 0; |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | /* Userspace create_qp callers */ |
| 2546 | if (attr->qp_type == IB_QPT_RAW_PACKET && !ucontext->cqe_version) { |
| 2547 | mlx5_ib_dbg(dev, |
| 2548 | "Raw Packet QP is only supported for CQE version > 0\n"); |
| 2549 | return -EINVAL; |
| 2550 | } |
| 2551 | |
| 2552 | if (attr->qp_type != IB_QPT_RAW_PACKET && attr->rwq_ind_tbl) { |
| 2553 | mlx5_ib_dbg(dev, |
| 2554 | "Wrong QP type %d for the RWQ indirect table\n", |
| 2555 | attr->qp_type); |
| 2556 | return -EINVAL; |
| 2557 | } |
| 2558 | |
| 2559 | switch (attr->qp_type) { |
| 2560 | case IB_QPT_SMI: |
| 2561 | case MLX5_IB_QPT_HW_GSI: |
| 2562 | case MLX5_IB_QPT_REG_UMR: |
| 2563 | case IB_QPT_GSI: |
| 2564 | mlx5_ib_dbg(dev, "Kernel doesn't support QP type %d\n", |
| 2565 | attr->qp_type); |
| 2566 | return -EINVAL; |
| 2567 | default: |
| 2568 | break; |
| 2569 | } |
| 2570 | |
| 2571 | /* |
| 2572 | * We don't need to see this warning, it means that kernel code |
| 2573 | * missing ib_pd. Placed here to catch developer's mistakes. |
| 2574 | */ |
| 2575 | WARN_ONCE(!pd && attr->qp_type != IB_QPT_XRC_TGT, |
| 2576 | "There is a missing PD pointer assignment\n"); |
| 2577 | return 0; |
| 2578 | } |
| 2579 | |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2580 | static int process_vendor_flags(struct mlx5_ib_qp *qp, |
| 2581 | struct ib_qp_init_attr *attr, |
| 2582 | struct mlx5_ib_create_qp *ucmd) |
| 2583 | { |
| 2584 | switch (ucmd->flags & (MLX5_QP_FLAG_TYPE_DCT | MLX5_QP_FLAG_TYPE_DCI)) { |
| 2585 | case MLX5_QP_FLAG_TYPE_DCI: |
| 2586 | qp->qp_sub_type = MLX5_IB_QPT_DCI; |
| 2587 | break; |
| 2588 | case MLX5_QP_FLAG_TYPE_DCT: |
| 2589 | qp->qp_sub_type = MLX5_IB_QPT_DCT; |
| 2590 | break; |
| 2591 | default: |
| 2592 | return -EINVAL; |
| 2593 | } |
| 2594 | |
| 2595 | return 0; |
| 2596 | } |
| 2597 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2598 | static void process_create_flag(struct mlx5_ib_dev *dev, int *flags, int flag, |
| 2599 | bool cond, struct mlx5_ib_qp *qp) |
| 2600 | { |
| 2601 | if (!(*flags & flag)) |
| 2602 | return; |
| 2603 | |
| 2604 | if (cond) { |
| 2605 | qp->flags |= flag; |
| 2606 | *flags &= ~flag; |
| 2607 | return; |
| 2608 | } |
| 2609 | |
| 2610 | if (flag == MLX5_IB_QP_CREATE_WC_TEST) { |
| 2611 | /* |
| 2612 | * Special case, if condition didn't meet, it won't be error, |
| 2613 | * just different in-kernel flow. |
| 2614 | */ |
| 2615 | *flags &= ~MLX5_IB_QP_CREATE_WC_TEST; |
| 2616 | return; |
| 2617 | } |
| 2618 | mlx5_ib_dbg(dev, "Verbs create QP flag 0x%X is not supported\n", flag); |
| 2619 | } |
| 2620 | |
| 2621 | static int process_create_flags(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2622 | struct ib_qp_init_attr *attr) |
| 2623 | { |
| 2624 | enum ib_qp_type qp_type = attr->qp_type; |
| 2625 | struct mlx5_core_dev *mdev = dev->mdev; |
| 2626 | int create_flags = attr->create_flags; |
| 2627 | bool cond; |
| 2628 | |
| 2629 | if (qp->qp_sub_type == MLX5_IB_QPT_DCT) |
| 2630 | return (create_flags) ? -EINVAL : 0; |
| 2631 | |
| 2632 | if (qp_type == IB_QPT_RAW_PACKET && attr->rwq_ind_tbl) |
| 2633 | return (create_flags) ? -EINVAL : 0; |
| 2634 | |
| 2635 | process_create_flag(dev, &create_flags, |
| 2636 | IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK, |
| 2637 | MLX5_CAP_GEN(mdev, block_lb_mc), qp); |
| 2638 | process_create_flag(dev, &create_flags, IB_QP_CREATE_CROSS_CHANNEL, |
| 2639 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2640 | process_create_flag(dev, &create_flags, IB_QP_CREATE_MANAGED_SEND, |
| 2641 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2642 | process_create_flag(dev, &create_flags, IB_QP_CREATE_MANAGED_RECV, |
| 2643 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2644 | |
| 2645 | if (qp_type == IB_QPT_UD) { |
| 2646 | process_create_flag(dev, &create_flags, |
| 2647 | IB_QP_CREATE_IPOIB_UD_LSO, |
| 2648 | MLX5_CAP_GEN(mdev, ipoib_basic_offloads), |
| 2649 | qp); |
| 2650 | cond = MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_IB; |
| 2651 | process_create_flag(dev, &create_flags, IB_QP_CREATE_SOURCE_QPN, |
| 2652 | cond, qp); |
| 2653 | } |
| 2654 | |
| 2655 | if (qp_type == IB_QPT_RAW_PACKET) { |
| 2656 | cond = MLX5_CAP_GEN(mdev, eth_net_offloads) && |
| 2657 | MLX5_CAP_ETH(mdev, scatter_fcs); |
| 2658 | process_create_flag(dev, &create_flags, |
| 2659 | IB_QP_CREATE_SCATTER_FCS, cond, qp); |
| 2660 | |
| 2661 | cond = MLX5_CAP_GEN(mdev, eth_net_offloads) && |
| 2662 | MLX5_CAP_ETH(mdev, vlan_cap); |
| 2663 | process_create_flag(dev, &create_flags, |
| 2664 | IB_QP_CREATE_CVLAN_STRIPPING, cond, qp); |
| 2665 | } |
| 2666 | |
| 2667 | process_create_flag(dev, &create_flags, |
| 2668 | IB_QP_CREATE_PCI_WRITE_END_PADDING, |
| 2669 | MLX5_CAP_GEN(mdev, end_pad), qp); |
| 2670 | |
| 2671 | process_create_flag(dev, &create_flags, MLX5_IB_QP_CREATE_WC_TEST, |
| 2672 | qp_type != MLX5_IB_QPT_REG_UMR, qp); |
| 2673 | process_create_flag(dev, &create_flags, MLX5_IB_QP_CREATE_SQPN_QP1, |
| 2674 | true, qp); |
| 2675 | |
| 2676 | if (create_flags) |
| 2677 | mlx5_ib_dbg(dev, "Create QP has unsupported flags 0x%X\n", |
| 2678 | create_flags); |
| 2679 | |
| 2680 | return (create_flags) ? -EINVAL : 0; |
| 2681 | } |
| 2682 | |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2683 | static int create_driver_qp(struct ib_pd *pd, struct mlx5_ib_qp *qp, |
| 2684 | struct ib_qp_init_attr *attr, |
| 2685 | struct mlx5_ib_create_qp *ucmd, |
| 2686 | struct ib_udata *udata) |
| 2687 | { |
| 2688 | struct mlx5_ib_dev *mdev = to_mdev(pd->device); |
| 2689 | int ret = -EINVAL; |
| 2690 | |
| 2691 | switch (qp->qp_sub_type) { |
| 2692 | case MLX5_IB_QPT_DCT: |
| 2693 | if (!attr->srq || !attr->recv_cq) |
| 2694 | goto out; |
| 2695 | |
| 2696 | ret = create_dct(pd, qp, attr, ucmd, udata); |
| 2697 | break; |
| 2698 | case MLX5_IB_QPT_DCI: |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2699 | if (attr->cap.max_recv_wr || attr->cap.max_recv_sge) |
| 2700 | goto out; |
| 2701 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2702 | ret = create_qp_common(mdev, pd, attr, ucmd, udata, qp); |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2703 | break; |
| 2704 | default: |
| 2705 | return -EINVAL; |
| 2706 | } |
| 2707 | |
| 2708 | out: return ret; |
| 2709 | } |
| 2710 | |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2711 | static size_t process_udata_size(struct ib_qp_init_attr *attr, |
| 2712 | struct ib_udata *udata) |
| 2713 | { |
| 2714 | size_t ucmd = sizeof(struct mlx5_ib_create_qp); |
| 2715 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2716 | if (attr->qp_type == IB_QPT_DRIVER) |
| 2717 | return (udata->inlen < ucmd) ? 0 : ucmd; |
| 2718 | |
| 2719 | return ucmd; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2720 | } |
| 2721 | |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2722 | static int create_raw_qp(struct ib_pd *pd, struct mlx5_ib_qp *qp, |
| 2723 | struct ib_qp_init_attr *attr, |
| 2724 | struct mlx5_ib_create_qp *ucmd, struct ib_udata *udata) |
| 2725 | { |
| 2726 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
| 2727 | |
| 2728 | if (attr->rwq_ind_tbl) |
| 2729 | return create_rss_raw_qp_tir(pd, qp, attr, udata); |
| 2730 | |
| 2731 | return create_qp_common(dev, pd, attr, ucmd, udata, qp); |
| 2732 | } |
| 2733 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2734 | struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd, |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2735 | struct ib_qp_init_attr *init_attr, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2736 | struct ib_udata *udata) |
| 2737 | { |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2738 | struct mlx5_ib_create_qp ucmd = {}; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2739 | struct mlx5_ib_dev *dev; |
| 2740 | struct mlx5_ib_qp *qp; |
| 2741 | u16 xrcdn = 0; |
| 2742 | int err; |
| 2743 | |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2744 | dev = pd ? to_mdev(pd->device) : |
| 2745 | to_mdev(to_mxrcd(init_attr->xrcd)->ibxrcd.device); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2746 | |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2747 | err = check_qp_type(dev, init_attr); |
| 2748 | if (err) { |
| 2749 | mlx5_ib_dbg(dev, "Unsupported QP type %d\n", |
| 2750 | init_attr->qp_type); |
| 2751 | return ERR_PTR(err); |
| 2752 | } |
| 2753 | |
Leon Romanovsky | 2242cc2 | 2020-04-27 18:46:03 +0300 | [diff] [blame] | 2754 | err = check_valid_flow(dev, pd, init_attr, udata); |
| 2755 | if (err) |
| 2756 | return ERR_PTR(err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2757 | |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2758 | if (init_attr->qp_type == IB_QPT_GSI) |
| 2759 | return mlx5_ib_gsi_create_qp(pd, init_attr); |
| 2760 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2761 | if (udata && !init_attr->rwq_ind_tbl) { |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2762 | size_t inlen = |
| 2763 | process_udata_size(init_attr, udata); |
| 2764 | |
| 2765 | if (!inlen) |
| 2766 | return ERR_PTR(-EINVAL); |
| 2767 | |
| 2768 | err = ib_copy_from_udata(&ucmd, udata, inlen); |
| 2769 | if (err) |
| 2770 | return ERR_PTR(err); |
| 2771 | } |
| 2772 | |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2773 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); |
| 2774 | if (!qp) |
| 2775 | return ERR_PTR(-ENOMEM); |
| 2776 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2777 | if (init_attr->qp_type == IB_QPT_DRIVER) { |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2778 | err = process_vendor_flags(qp, init_attr, &ucmd); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2779 | if (err) |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2780 | goto free_qp; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2781 | } |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2782 | err = process_create_flags(dev, qp, init_attr); |
| 2783 | if (err) |
| 2784 | goto free_qp; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2785 | |
Leon Romanovsky | c86936e | 2020-04-27 18:46:05 +0300 | [diff] [blame] | 2786 | if (init_attr->qp_type == IB_QPT_XRC_TGT) |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2787 | xrcdn = to_mxrcd(init_attr->xrcd)->xrcdn; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2788 | |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2789 | switch (init_attr->qp_type) { |
| 2790 | case IB_QPT_DRIVER: |
| 2791 | err = create_driver_qp(pd, qp, init_attr, &ucmd, udata); |
| 2792 | break; |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2793 | case IB_QPT_RAW_PACKET: |
| 2794 | err = create_raw_qp(pd, qp, init_attr, &ucmd, udata); |
| 2795 | break; |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2796 | default: |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2797 | err = create_qp_common(dev, pd, init_attr, |
| 2798 | (udata) ? &ucmd : NULL, udata, qp); |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2799 | } |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2800 | if (err) { |
| 2801 | mlx5_ib_dbg(dev, "create_qp_common failed\n"); |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2802 | goto free_qp; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | if (is_qp0(init_attr->qp_type)) |
| 2806 | qp->ibqp.qp_num = 0; |
| 2807 | else if (is_qp1(init_attr->qp_type)) |
| 2808 | qp->ibqp.qp_num = 1; |
| 2809 | else |
| 2810 | qp->ibqp.qp_num = qp->trans_qp.base.mqp.qpn; |
| 2811 | |
| 2812 | qp->trans_qp.xrcdn = xrcdn; |
| 2813 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2814 | return &qp->ibqp; |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2815 | |
| 2816 | free_qp: |
| 2817 | kfree(qp); |
| 2818 | return ERR_PTR(err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2819 | } |
| 2820 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2821 | static int mlx5_ib_destroy_dct(struct mlx5_ib_qp *mqp) |
| 2822 | { |
| 2823 | struct mlx5_ib_dev *dev = to_mdev(mqp->ibqp.device); |
| 2824 | |
| 2825 | if (mqp->state == IB_QPS_RTR) { |
| 2826 | int err; |
| 2827 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2828 | err = mlx5_core_destroy_dct(dev, &mqp->dct.mdct); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2829 | if (err) { |
| 2830 | mlx5_ib_warn(dev, "failed to destroy DCT %d\n", err); |
| 2831 | return err; |
| 2832 | } |
| 2833 | } |
| 2834 | |
| 2835 | kfree(mqp->dct.in); |
| 2836 | kfree(mqp); |
| 2837 | return 0; |
| 2838 | } |
| 2839 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2840 | 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] | 2841 | { |
| 2842 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 2843 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 2844 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2845 | if (unlikely(qp->qp_type == IB_QPT_GSI)) |
| 2846 | return mlx5_ib_gsi_destroy_qp(qp); |
| 2847 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2848 | if (mqp->qp_sub_type == MLX5_IB_QPT_DCT) |
| 2849 | return mlx5_ib_destroy_dct(mqp); |
| 2850 | |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2851 | destroy_qp_common(dev, mqp, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2852 | |
| 2853 | kfree(mqp); |
| 2854 | |
| 2855 | return 0; |
| 2856 | } |
| 2857 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2858 | static int to_mlx5_access_flags(struct mlx5_ib_qp *qp, |
| 2859 | const struct ib_qp_attr *attr, |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2860 | int attr_mask, __be32 *hw_access_flags_be) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2861 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2862 | u8 dest_rd_atomic; |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2863 | u32 access_flags, hw_access_flags = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2864 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2865 | struct mlx5_ib_dev *dev = to_mdev(qp->ibqp.device); |
| 2866 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2867 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
| 2868 | dest_rd_atomic = attr->max_dest_rd_atomic; |
| 2869 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2870 | dest_rd_atomic = qp->trans_qp.resp_depth; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2871 | |
| 2872 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
| 2873 | access_flags = attr->qp_access_flags; |
| 2874 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2875 | access_flags = qp->trans_qp.atomic_rd_en; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2876 | |
| 2877 | if (!dest_rd_atomic) |
| 2878 | access_flags &= IB_ACCESS_REMOTE_WRITE; |
| 2879 | |
| 2880 | if (access_flags & IB_ACCESS_REMOTE_READ) |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2881 | hw_access_flags |= MLX5_QP_BIT_RRE; |
Yonatan Cohen | 13f8d9c | 2018-11-21 13:48:39 +0200 | [diff] [blame] | 2882 | if (access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2883 | int atomic_mode; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2884 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2885 | atomic_mode = get_atomic_mode(dev, qp->ibqp.qp_type); |
| 2886 | if (atomic_mode < 0) |
| 2887 | return -EOPNOTSUPP; |
| 2888 | |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2889 | hw_access_flags |= MLX5_QP_BIT_RAE; |
| 2890 | hw_access_flags |= atomic_mode << MLX5_ATOMIC_MODE_OFFSET; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2891 | } |
| 2892 | |
| 2893 | if (access_flags & IB_ACCESS_REMOTE_WRITE) |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2894 | hw_access_flags |= MLX5_QP_BIT_RWE; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2895 | |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2896 | *hw_access_flags_be = cpu_to_be32(hw_access_flags); |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2897 | |
| 2898 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | enum { |
| 2902 | MLX5_PATH_FLAG_FL = 1 << 0, |
| 2903 | MLX5_PATH_FLAG_FREE_AR = 1 << 1, |
| 2904 | MLX5_PATH_FLAG_COUNTER = 1 << 2, |
| 2905 | }; |
| 2906 | |
| 2907 | static int ib_rate_to_mlx5(struct mlx5_ib_dev *dev, u8 rate) |
| 2908 | { |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 2909 | if (rate == IB_RATE_PORT_CURRENT) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2910 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2911 | |
Michael Guralnik | a5a5d19 | 2018-12-09 11:49:50 +0200 | [diff] [blame] | 2912 | if (rate < IB_RATE_2_5_GBPS || rate > IB_RATE_600_GBPS) |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 2913 | return -EINVAL; |
| 2914 | |
| 2915 | while (rate != IB_RATE_PORT_CURRENT && |
| 2916 | !(1 << (rate + MLX5_STAT_RATE_OFFSET) & |
| 2917 | MLX5_CAP_GEN(dev->mdev, stat_rate_support))) |
| 2918 | --rate; |
| 2919 | |
| 2920 | return rate ? rate + MLX5_STAT_RATE_OFFSET : rate; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2921 | } |
| 2922 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2923 | static int modify_raw_packet_eth_prio(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2924 | struct mlx5_ib_sq *sq, u8 sl, |
| 2925 | struct ib_pd *pd) |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2926 | { |
| 2927 | void *in; |
| 2928 | void *tisc; |
| 2929 | int inlen; |
| 2930 | int err; |
| 2931 | |
| 2932 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2933 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2934 | if (!in) |
| 2935 | return -ENOMEM; |
| 2936 | |
| 2937 | MLX5_SET(modify_tis_in, in, bitmask.prio, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2938 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2939 | |
| 2940 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 2941 | MLX5_SET(tisc, tisc, prio, ((sl & 0x7) << 1)); |
| 2942 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 2943 | err = mlx5_core_modify_tis(dev, sq->tisn, in); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2944 | |
| 2945 | kvfree(in); |
| 2946 | |
| 2947 | return err; |
| 2948 | } |
| 2949 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2950 | static int modify_raw_packet_tx_affinity(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2951 | struct mlx5_ib_sq *sq, u8 tx_affinity, |
| 2952 | struct ib_pd *pd) |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2953 | { |
| 2954 | void *in; |
| 2955 | void *tisc; |
| 2956 | int inlen; |
| 2957 | int err; |
| 2958 | |
| 2959 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2960 | in = kvzalloc(inlen, GFP_KERNEL); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2961 | if (!in) |
| 2962 | return -ENOMEM; |
| 2963 | |
| 2964 | MLX5_SET(modify_tis_in, in, bitmask.lag_tx_port_affinity, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2965 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2966 | |
| 2967 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 2968 | MLX5_SET(tisc, tisc, lag_tx_port_affinity, tx_affinity); |
| 2969 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 2970 | err = mlx5_core_modify_tis(dev, sq->tisn, in); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2971 | |
| 2972 | kvfree(in); |
| 2973 | |
| 2974 | return err; |
| 2975 | } |
| 2976 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2977 | static int mlx5_set_path(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 2978 | const struct rdma_ah_attr *ah, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2979 | struct mlx5_qp_path *path, u8 port, int attr_mask, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 2980 | u32 path_flags, const struct ib_qp_attr *attr, |
| 2981 | bool alt) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2982 | { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2983 | const struct ib_global_route *grh = rdma_ah_read_grh(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2984 | int err; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 2985 | enum ib_gid_type gid_type; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2986 | u8 ah_flags = rdma_ah_get_ah_flags(ah); |
| 2987 | u8 sl = rdma_ah_get_sl(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2988 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2989 | if (attr_mask & IB_QP_PKEY_INDEX) |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 2990 | path->pkey_index = cpu_to_be16(alt ? attr->alt_pkey_index : |
| 2991 | attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2992 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2993 | if (ah_flags & IB_AH_GRH) { |
| 2994 | if (grh->sgid_index >= |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2995 | dev->mdev->port_caps[port - 1].gid_table_len) { |
Joe Perches | f4f01b5 | 2015-05-08 15:58:07 -0700 | [diff] [blame] | 2996 | pr_err("sgid_index (%u) too large. max is %d\n", |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2997 | grh->sgid_index, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2998 | dev->mdev->port_caps[port - 1].gid_table_len); |
Eli Cohen | f83b426 | 2014-09-14 16:47:54 +0300 | [diff] [blame] | 2999 | return -EINVAL; |
| 3000 | } |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3001 | } |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 3002 | |
| 3003 | if (ah->type == RDMA_AH_ATTR_TYPE_ROCE) { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3004 | if (!(ah_flags & IB_AH_GRH)) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3005 | return -EINVAL; |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 3006 | |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 3007 | memcpy(path->rmac, ah->roce.dmac, sizeof(ah->roce.dmac)); |
Majd Dibbiny | 2b62185 | 2017-10-30 14:23:14 +0200 | [diff] [blame] | 3008 | if (qp->ibqp.qp_type == IB_QPT_RC || |
| 3009 | qp->ibqp.qp_type == IB_QPT_UC || |
| 3010 | qp->ibqp.qp_type == IB_QPT_XRC_INI || |
| 3011 | qp->ibqp.qp_type == IB_QPT_XRC_TGT) |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 3012 | path->udp_sport = |
| 3013 | mlx5_get_roce_udp_sport(dev, ah->grh.sgid_attr); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3014 | path->dci_cfi_prio_sl = (sl & 0x7) << 4; |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 3015 | gid_type = ah->grh.sgid_attr->gid_type; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 3016 | if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3017 | path->ecn_dscp = (grh->traffic_class >> 2) & 0x3f; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3018 | } else { |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 3019 | path->fl_free_ar = (path_flags & MLX5_PATH_FLAG_FL) ? 0x80 : 0; |
| 3020 | path->fl_free_ar |= |
| 3021 | (path_flags & MLX5_PATH_FLAG_FREE_AR) ? 0x40 : 0; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3022 | path->rlid = cpu_to_be16(rdma_ah_get_dlid(ah)); |
| 3023 | path->grh_mlid = rdma_ah_get_path_bits(ah) & 0x7f; |
| 3024 | if (ah_flags & IB_AH_GRH) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3025 | path->grh_mlid |= 1 << 7; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3026 | path->dci_cfi_prio_sl = sl & 0xf; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3027 | } |
| 3028 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3029 | if (ah_flags & IB_AH_GRH) { |
| 3030 | path->mgid_index = grh->sgid_index; |
| 3031 | path->hop_limit = grh->hop_limit; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3032 | path->tclass_flowlabel = |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3033 | cpu_to_be32((grh->traffic_class << 20) | |
| 3034 | (grh->flow_label)); |
| 3035 | memcpy(path->rgid, grh->dgid.raw, 16); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3036 | } |
| 3037 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3038 | err = ib_rate_to_mlx5(dev, rdma_ah_get_static_rate(ah)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3039 | if (err < 0) |
| 3040 | return err; |
| 3041 | path->static_rate = err; |
| 3042 | path->port = port; |
| 3043 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3044 | if (attr_mask & IB_QP_TIMEOUT) |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3045 | path->ackto_lt = (alt ? attr->alt_timeout : attr->timeout) << 3; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3046 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3047 | if ((qp->ibqp.qp_type == IB_QPT_RAW_PACKET) && qp->sq.wqe_cnt) |
| 3048 | return modify_raw_packet_eth_prio(dev->mdev, |
| 3049 | &qp->raw_packet_qp.sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3050 | sl & 0xf, qp->ibqp.pd); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3051 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3052 | return 0; |
| 3053 | } |
| 3054 | |
| 3055 | static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_QP_ST_MAX] = { |
| 3056 | [MLX5_QP_STATE_INIT] = { |
| 3057 | [MLX5_QP_STATE_INIT] = { |
| 3058 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 3059 | MLX5_QP_OPTPAR_RAE | |
| 3060 | MLX5_QP_OPTPAR_RWE | |
| 3061 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3062 | MLX5_QP_OPTPAR_PRI_PORT, |
| 3063 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
| 3064 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3065 | MLX5_QP_OPTPAR_PRI_PORT, |
| 3066 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3067 | MLX5_QP_OPTPAR_Q_KEY | |
| 3068 | MLX5_QP_OPTPAR_PRI_PORT, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3069 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RRE | |
| 3070 | MLX5_QP_OPTPAR_RAE | |
| 3071 | MLX5_QP_OPTPAR_RWE | |
| 3072 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3073 | MLX5_QP_OPTPAR_PRI_PORT, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3074 | }, |
| 3075 | [MLX5_QP_STATE_RTR] = { |
| 3076 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3077 | MLX5_QP_OPTPAR_RRE | |
| 3078 | MLX5_QP_OPTPAR_RAE | |
| 3079 | MLX5_QP_OPTPAR_RWE | |
| 3080 | MLX5_QP_OPTPAR_PKEY_INDEX, |
| 3081 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3082 | MLX5_QP_OPTPAR_RWE | |
| 3083 | MLX5_QP_OPTPAR_PKEY_INDEX, |
| 3084 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3085 | MLX5_QP_OPTPAR_Q_KEY, |
| 3086 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3087 | MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 3088 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3089 | MLX5_QP_OPTPAR_RRE | |
| 3090 | MLX5_QP_OPTPAR_RAE | |
| 3091 | MLX5_QP_OPTPAR_RWE | |
| 3092 | MLX5_QP_OPTPAR_PKEY_INDEX, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3093 | }, |
| 3094 | }, |
| 3095 | [MLX5_QP_STATE_RTR] = { |
| 3096 | [MLX5_QP_STATE_RTS] = { |
| 3097 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3098 | MLX5_QP_OPTPAR_RRE | |
| 3099 | MLX5_QP_OPTPAR_RAE | |
| 3100 | MLX5_QP_OPTPAR_RWE | |
| 3101 | MLX5_QP_OPTPAR_PM_STATE | |
| 3102 | MLX5_QP_OPTPAR_RNR_TIMEOUT, |
| 3103 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3104 | MLX5_QP_OPTPAR_RWE | |
| 3105 | MLX5_QP_OPTPAR_PM_STATE, |
| 3106 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3107 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3108 | MLX5_QP_OPTPAR_RRE | |
| 3109 | MLX5_QP_OPTPAR_RAE | |
| 3110 | MLX5_QP_OPTPAR_RWE | |
| 3111 | MLX5_QP_OPTPAR_PM_STATE | |
| 3112 | MLX5_QP_OPTPAR_RNR_TIMEOUT, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3113 | }, |
| 3114 | }, |
| 3115 | [MLX5_QP_STATE_RTS] = { |
| 3116 | [MLX5_QP_STATE_RTS] = { |
| 3117 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 3118 | MLX5_QP_OPTPAR_RAE | |
| 3119 | MLX5_QP_OPTPAR_RWE | |
| 3120 | MLX5_QP_OPTPAR_RNR_TIMEOUT | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 3121 | MLX5_QP_OPTPAR_PM_STATE | |
| 3122 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3123 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 3124 | MLX5_QP_OPTPAR_PM_STATE | |
| 3125 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3126 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY | |
| 3127 | MLX5_QP_OPTPAR_SRQN | |
| 3128 | MLX5_QP_OPTPAR_CQN_RCV, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3129 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RRE | |
| 3130 | MLX5_QP_OPTPAR_RAE | |
| 3131 | MLX5_QP_OPTPAR_RWE | |
| 3132 | MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3133 | MLX5_QP_OPTPAR_PM_STATE | |
| 3134 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3135 | }, |
| 3136 | }, |
| 3137 | [MLX5_QP_STATE_SQER] = { |
| 3138 | [MLX5_QP_STATE_RTS] = { |
| 3139 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
| 3140 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | 75959f5 | 2013-09-11 16:35:31 +0300 | [diff] [blame] | 3141 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 3142 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3143 | MLX5_QP_OPTPAR_RWE | |
| 3144 | MLX5_QP_OPTPAR_RAE | |
| 3145 | MLX5_QP_OPTPAR_RRE, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3146 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3147 | MLX5_QP_OPTPAR_RWE | |
| 3148 | MLX5_QP_OPTPAR_RAE | |
| 3149 | MLX5_QP_OPTPAR_RRE, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3150 | }, |
| 3151 | }, |
| 3152 | }; |
| 3153 | |
| 3154 | static int ib_nr_to_mlx5_nr(int ib_mask) |
| 3155 | { |
| 3156 | switch (ib_mask) { |
| 3157 | case IB_QP_STATE: |
| 3158 | return 0; |
| 3159 | case IB_QP_CUR_STATE: |
| 3160 | return 0; |
| 3161 | case IB_QP_EN_SQD_ASYNC_NOTIFY: |
| 3162 | return 0; |
| 3163 | case IB_QP_ACCESS_FLAGS: |
| 3164 | return MLX5_QP_OPTPAR_RWE | MLX5_QP_OPTPAR_RRE | |
| 3165 | MLX5_QP_OPTPAR_RAE; |
| 3166 | case IB_QP_PKEY_INDEX: |
| 3167 | return MLX5_QP_OPTPAR_PKEY_INDEX; |
| 3168 | case IB_QP_PORT: |
| 3169 | return MLX5_QP_OPTPAR_PRI_PORT; |
| 3170 | case IB_QP_QKEY: |
| 3171 | return MLX5_QP_OPTPAR_Q_KEY; |
| 3172 | case IB_QP_AV: |
| 3173 | return MLX5_QP_OPTPAR_PRIMARY_ADDR_PATH | |
| 3174 | MLX5_QP_OPTPAR_PRI_PORT; |
| 3175 | case IB_QP_PATH_MTU: |
| 3176 | return 0; |
| 3177 | case IB_QP_TIMEOUT: |
| 3178 | return MLX5_QP_OPTPAR_ACK_TIMEOUT; |
| 3179 | case IB_QP_RETRY_CNT: |
| 3180 | return MLX5_QP_OPTPAR_RETRY_COUNT; |
| 3181 | case IB_QP_RNR_RETRY: |
| 3182 | return MLX5_QP_OPTPAR_RNR_RETRY; |
| 3183 | case IB_QP_RQ_PSN: |
| 3184 | return 0; |
| 3185 | case IB_QP_MAX_QP_RD_ATOMIC: |
| 3186 | return MLX5_QP_OPTPAR_SRA_MAX; |
| 3187 | case IB_QP_ALT_PATH: |
| 3188 | return MLX5_QP_OPTPAR_ALT_ADDR_PATH; |
| 3189 | case IB_QP_MIN_RNR_TIMER: |
| 3190 | return MLX5_QP_OPTPAR_RNR_TIMEOUT; |
| 3191 | case IB_QP_SQ_PSN: |
| 3192 | return 0; |
| 3193 | case IB_QP_MAX_DEST_RD_ATOMIC: |
| 3194 | return MLX5_QP_OPTPAR_RRA_MAX | MLX5_QP_OPTPAR_RWE | |
| 3195 | MLX5_QP_OPTPAR_RRE | MLX5_QP_OPTPAR_RAE; |
| 3196 | case IB_QP_PATH_MIG_STATE: |
| 3197 | return MLX5_QP_OPTPAR_PM_STATE; |
| 3198 | case IB_QP_CAP: |
| 3199 | return 0; |
| 3200 | case IB_QP_DEST_QPN: |
| 3201 | return 0; |
| 3202 | } |
| 3203 | return 0; |
| 3204 | } |
| 3205 | |
| 3206 | static int ib_mask_to_mlx5_opt(int ib_mask) |
| 3207 | { |
| 3208 | int result = 0; |
| 3209 | int i; |
| 3210 | |
| 3211 | for (i = 0; i < 8 * sizeof(int); i++) { |
| 3212 | if ((1 << i) & ib_mask) |
| 3213 | result |= ib_nr_to_mlx5_nr(1 << i); |
| 3214 | } |
| 3215 | |
| 3216 | return result; |
| 3217 | } |
| 3218 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3219 | static int modify_raw_packet_qp_rq( |
| 3220 | struct mlx5_ib_dev *dev, struct mlx5_ib_rq *rq, int new_state, |
| 3221 | 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] | 3222 | { |
| 3223 | void *in; |
| 3224 | void *rqc; |
| 3225 | int inlen; |
| 3226 | int err; |
| 3227 | |
| 3228 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3229 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3230 | if (!in) |
| 3231 | return -ENOMEM; |
| 3232 | |
| 3233 | MLX5_SET(modify_rq_in, in, rq_state, rq->state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3234 | MLX5_SET(modify_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3235 | |
| 3236 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 3237 | MLX5_SET(rqc, rqc, state, new_state); |
| 3238 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3239 | if (raw_qp_param->set_mask & MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID) { |
| 3240 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 3241 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 3242 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3243 | MLX5_SET(rqc, rqc, counter_set_id, raw_qp_param->rq_q_ctr_id); |
| 3244 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 3245 | dev_info_once( |
| 3246 | &dev->ib_dev.dev, |
| 3247 | "RAW PACKET QP counters are not supported on current FW\n"); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3248 | } |
| 3249 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3250 | 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] | 3251 | if (err) |
| 3252 | goto out; |
| 3253 | |
| 3254 | rq->state = new_state; |
| 3255 | |
| 3256 | out: |
| 3257 | kvfree(in); |
| 3258 | return err; |
| 3259 | } |
| 3260 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3261 | static int modify_raw_packet_qp_sq( |
| 3262 | struct mlx5_core_dev *dev, struct mlx5_ib_sq *sq, int new_state, |
| 3263 | 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] | 3264 | { |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3265 | struct mlx5_ib_qp *ibqp = sq->base.container_mibqp; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3266 | struct mlx5_rate_limit old_rl = ibqp->rl; |
| 3267 | struct mlx5_rate_limit new_rl = old_rl; |
| 3268 | bool new_rate_added = false; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3269 | u16 rl_index = 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3270 | void *in; |
| 3271 | void *sqc; |
| 3272 | int inlen; |
| 3273 | int err; |
| 3274 | |
| 3275 | inlen = MLX5_ST_SZ_BYTES(modify_sq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3276 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3277 | if (!in) |
| 3278 | return -ENOMEM; |
| 3279 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3280 | MLX5_SET(modify_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3281 | MLX5_SET(modify_sq_in, in, sq_state, sq->state); |
| 3282 | |
| 3283 | sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx); |
| 3284 | MLX5_SET(sqc, sqc, state, new_state); |
| 3285 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3286 | if (raw_qp_param->set_mask & MLX5_RAW_QP_RATE_LIMIT) { |
| 3287 | if (new_state != MLX5_SQC_STATE_RDY) |
| 3288 | pr_warn("%s: Rate limit can only be changed when SQ is moving to RDY\n", |
| 3289 | __func__); |
| 3290 | else |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3291 | new_rl = raw_qp_param->rl; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3292 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3293 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3294 | if (!mlx5_rl_are_equal(&old_rl, &new_rl)) { |
| 3295 | if (new_rl.rate) { |
| 3296 | err = mlx5_rl_add_rate(dev, &rl_index, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3297 | if (err) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3298 | pr_err("Failed configuring rate limit(err %d): \ |
| 3299 | rate %u, max_burst_sz %u, typical_pkt_sz %u\n", |
| 3300 | err, new_rl.rate, new_rl.max_burst_sz, |
| 3301 | new_rl.typical_pkt_sz); |
| 3302 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3303 | goto out; |
| 3304 | } |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3305 | new_rate_added = true; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3306 | } |
| 3307 | |
| 3308 | MLX5_SET64(modify_sq_in, in, modify_bitmask, 1); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3309 | /* index 0 means no limit */ |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3310 | MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index); |
| 3311 | } |
| 3312 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3313 | err = mlx5_core_modify_sq(dev, sq->base.mqp.qpn, in); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3314 | if (err) { |
| 3315 | /* Remove new rate from table if failed */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3316 | if (new_rate_added) |
| 3317 | mlx5_rl_remove_rate(dev, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3318 | goto out; |
| 3319 | } |
| 3320 | |
| 3321 | /* Only remove the old rate after new rate was set */ |
Rafi Wiener | c8973df | 2019-10-02 15:02:43 +0300 | [diff] [blame] | 3322 | if ((old_rl.rate && !mlx5_rl_are_equal(&old_rl, &new_rl)) || |
| 3323 | (new_state != MLX5_SQC_STATE_RDY)) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3324 | mlx5_rl_remove_rate(dev, &old_rl); |
Rafi Wiener | c8973df | 2019-10-02 15:02:43 +0300 | [diff] [blame] | 3325 | if (new_state != MLX5_SQC_STATE_RDY) |
| 3326 | memset(&new_rl, 0, sizeof(new_rl)); |
| 3327 | } |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3328 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3329 | ibqp->rl = new_rl; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3330 | sq->state = new_state; |
| 3331 | |
| 3332 | out: |
| 3333 | kvfree(in); |
| 3334 | return err; |
| 3335 | } |
| 3336 | |
| 3337 | 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] | 3338 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 3339 | u8 tx_affinity) |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3340 | { |
| 3341 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 3342 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 3343 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3344 | int modify_rq = !!qp->rq.wqe_cnt; |
| 3345 | int modify_sq = !!qp->sq.wqe_cnt; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3346 | int rq_state; |
| 3347 | int sq_state; |
| 3348 | int err; |
| 3349 | |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3350 | switch (raw_qp_param->operation) { |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3351 | case MLX5_CMD_OP_RST2INIT_QP: |
| 3352 | rq_state = MLX5_RQC_STATE_RDY; |
| 3353 | sq_state = MLX5_SQC_STATE_RDY; |
| 3354 | break; |
| 3355 | case MLX5_CMD_OP_2ERR_QP: |
| 3356 | rq_state = MLX5_RQC_STATE_ERR; |
| 3357 | sq_state = MLX5_SQC_STATE_ERR; |
| 3358 | break; |
| 3359 | case MLX5_CMD_OP_2RST_QP: |
| 3360 | rq_state = MLX5_RQC_STATE_RST; |
| 3361 | sq_state = MLX5_SQC_STATE_RST; |
| 3362 | break; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3363 | case MLX5_CMD_OP_RTR2RTS_QP: |
| 3364 | case MLX5_CMD_OP_RTS2RTS_QP: |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3365 | if (raw_qp_param->set_mask == |
| 3366 | MLX5_RAW_QP_RATE_LIMIT) { |
| 3367 | modify_rq = 0; |
| 3368 | sq_state = sq->state; |
| 3369 | } else { |
| 3370 | return raw_qp_param->set_mask ? -EINVAL : 0; |
| 3371 | } |
| 3372 | break; |
| 3373 | case MLX5_CMD_OP_INIT2INIT_QP: |
| 3374 | case MLX5_CMD_OP_INIT2RTR_QP: |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3375 | if (raw_qp_param->set_mask) |
| 3376 | return -EINVAL; |
| 3377 | else |
| 3378 | return 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3379 | default: |
| 3380 | WARN_ON(1); |
| 3381 | return -EINVAL; |
| 3382 | } |
| 3383 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3384 | if (modify_rq) { |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3385 | err = modify_raw_packet_qp_rq(dev, rq, rq_state, raw_qp_param, |
| 3386 | qp->ibqp.pd); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3387 | if (err) |
| 3388 | return err; |
| 3389 | } |
| 3390 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3391 | if (modify_sq) { |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3392 | struct mlx5_flow_handle *flow_rule; |
| 3393 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3394 | if (tx_affinity) { |
| 3395 | err = modify_raw_packet_tx_affinity(dev->mdev, sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3396 | tx_affinity, |
| 3397 | qp->ibqp.pd); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3398 | if (err) |
| 3399 | return err; |
| 3400 | } |
| 3401 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3402 | flow_rule = create_flow_rule_vport_sq(dev, sq, |
| 3403 | raw_qp_param->port); |
| 3404 | if (IS_ERR(flow_rule)) |
Colin Ian King | 1db8631 | 2019-04-12 11:40:17 +0100 | [diff] [blame] | 3405 | return PTR_ERR(flow_rule); |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3406 | |
| 3407 | err = modify_raw_packet_qp_sq(dev->mdev, sq, sq_state, |
| 3408 | raw_qp_param, qp->ibqp.pd); |
| 3409 | if (err) { |
| 3410 | if (flow_rule) |
| 3411 | mlx5_del_flow_rules(flow_rule); |
| 3412 | return err; |
| 3413 | } |
| 3414 | |
| 3415 | if (flow_rule) { |
| 3416 | destroy_flow_rule_vport_sq(sq); |
| 3417 | sq->flow_rule = flow_rule; |
| 3418 | } |
| 3419 | |
| 3420 | return err; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3421 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3422 | |
| 3423 | return 0; |
| 3424 | } |
| 3425 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3426 | static unsigned int get_tx_affinity(struct mlx5_ib_dev *dev, |
| 3427 | struct mlx5_ib_pd *pd, |
| 3428 | struct mlx5_ib_qp_base *qp_base, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3429 | u8 port_num, struct ib_udata *udata) |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3430 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3431 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 3432 | udata, struct mlx5_ib_ucontext, ibucontext); |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3433 | unsigned int tx_port_affinity; |
| 3434 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3435 | if (ucontext) { |
| 3436 | tx_port_affinity = (unsigned int)atomic_add_return( |
| 3437 | 1, &ucontext->tx_port_affinity) % |
| 3438 | MLX5_MAX_PORTS + |
| 3439 | 1; |
| 3440 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x ucontext %p\n", |
| 3441 | tx_port_affinity, qp_base->mqp.qpn, ucontext); |
| 3442 | } else { |
| 3443 | tx_port_affinity = |
| 3444 | (unsigned int)atomic_add_return( |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 3445 | 1, &dev->port[port_num].roce.tx_port_affinity) % |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3446 | MLX5_MAX_PORTS + |
| 3447 | 1; |
| 3448 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x\n", |
| 3449 | tx_port_affinity, qp_base->mqp.qpn); |
| 3450 | } |
| 3451 | |
| 3452 | return tx_port_affinity; |
| 3453 | } |
| 3454 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3455 | static int __mlx5_ib_qp_set_counter(struct ib_qp *qp, |
| 3456 | struct rdma_counter *counter) |
| 3457 | { |
| 3458 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 3459 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 3460 | struct mlx5_qp_context context = {}; |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3461 | struct mlx5_ib_qp_base *base; |
| 3462 | u32 set_id; |
| 3463 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3464 | if (counter) |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3465 | set_id = counter->id; |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3466 | else |
| 3467 | set_id = mlx5_ib_get_counters_id(dev, mqp->port - 1); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3468 | |
| 3469 | base = &mqp->trans_qp.base; |
| 3470 | context.qp_counter_set_usr_page &= cpu_to_be32(0xffffff); |
| 3471 | context.qp_counter_set_usr_page |= cpu_to_be32(set_id << 24); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3472 | return mlx5_core_qp_modify(dev, MLX5_CMD_OP_RTS2RTS_QP, |
| 3473 | MLX5_QP_OPTPAR_COUNTER_SET_ID, &context, |
| 3474 | &base->mqp); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3475 | } |
| 3476 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3477 | static int __mlx5_ib_modify_qp(struct ib_qp *ibqp, |
| 3478 | const struct ib_qp_attr *attr, int attr_mask, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3479 | enum ib_qp_state cur_state, |
| 3480 | enum ib_qp_state new_state, |
| 3481 | const struct mlx5_ib_modify_qp *ucmd, |
| 3482 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3483 | { |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3484 | static const u16 optab[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE] = { |
| 3485 | [MLX5_QP_STATE_RST] = { |
| 3486 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3487 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3488 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_RST2INIT_QP, |
| 3489 | }, |
| 3490 | [MLX5_QP_STATE_INIT] = { |
| 3491 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3492 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3493 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_INIT2INIT_QP, |
| 3494 | [MLX5_QP_STATE_RTR] = MLX5_CMD_OP_INIT2RTR_QP, |
| 3495 | }, |
| 3496 | [MLX5_QP_STATE_RTR] = { |
| 3497 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3498 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3499 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTR2RTS_QP, |
| 3500 | }, |
| 3501 | [MLX5_QP_STATE_RTS] = { |
| 3502 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3503 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3504 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTS2RTS_QP, |
| 3505 | }, |
| 3506 | [MLX5_QP_STATE_SQD] = { |
| 3507 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3508 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3509 | }, |
| 3510 | [MLX5_QP_STATE_SQER] = { |
| 3511 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3512 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3513 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_SQERR2RTS_QP, |
| 3514 | }, |
| 3515 | [MLX5_QP_STATE_ERR] = { |
| 3516 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3517 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3518 | } |
| 3519 | }; |
| 3520 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3521 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3522 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3523 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3524 | struct mlx5_ib_cq *send_cq, *recv_cq; |
| 3525 | struct mlx5_qp_context *context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3526 | struct mlx5_ib_pd *pd; |
| 3527 | enum mlx5_qp_state mlx5_cur, mlx5_new; |
| 3528 | enum mlx5_qp_optpar optpar; |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3529 | u32 set_id = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3530 | int mlx5_st; |
| 3531 | int err; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3532 | u16 op; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3533 | u8 tx_affinity = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3534 | |
Leon Romanovsky | 55de9a7 | 2018-02-25 13:39:52 +0200 | [diff] [blame] | 3535 | mlx5_st = to_mlx5_st(ibqp->qp_type == IB_QPT_DRIVER ? |
| 3536 | qp->qp_sub_type : ibqp->qp_type); |
| 3537 | if (mlx5_st < 0) |
| 3538 | return -EINVAL; |
| 3539 | |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 3540 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 3541 | if (!context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3542 | return -ENOMEM; |
| 3543 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3544 | pd = get_pd(qp); |
Leon Romanovsky | 55de9a7 | 2018-02-25 13:39:52 +0200 | [diff] [blame] | 3545 | context->flags = cpu_to_be32(mlx5_st << 16); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3546 | |
| 3547 | if (!(attr_mask & IB_QP_PATH_MIG_STATE)) { |
| 3548 | context->flags |= cpu_to_be32(MLX5_QP_PM_MIGRATED << 11); |
| 3549 | } else { |
| 3550 | switch (attr->path_mig_state) { |
| 3551 | case IB_MIG_MIGRATED: |
| 3552 | context->flags |= cpu_to_be32(MLX5_QP_PM_MIGRATED << 11); |
| 3553 | break; |
| 3554 | case IB_MIG_REARM: |
| 3555 | context->flags |= cpu_to_be32(MLX5_QP_PM_REARM << 11); |
| 3556 | break; |
| 3557 | case IB_MIG_ARMED: |
| 3558 | context->flags |= cpu_to_be32(MLX5_QP_PM_ARMED << 11); |
| 3559 | break; |
| 3560 | } |
| 3561 | } |
| 3562 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3563 | if ((cur_state == IB_QPS_RESET) && (new_state == IB_QPS_INIT)) { |
| 3564 | if ((ibqp->qp_type == IB_QPT_RC) || |
| 3565 | (ibqp->qp_type == IB_QPT_UD && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3566 | !(qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1)) || |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3567 | (ibqp->qp_type == IB_QPT_UC) || |
| 3568 | (ibqp->qp_type == IB_QPT_RAW_PACKET) || |
| 3569 | (ibqp->qp_type == IB_QPT_XRC_INI) || |
| 3570 | (ibqp->qp_type == IB_QPT_XRC_TGT)) { |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 3571 | if (dev->lag_active) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 3572 | u8 p = mlx5_core_native_port_num(dev->mdev) - 1; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3573 | tx_affinity = get_tx_affinity(dev, pd, base, p, |
| 3574 | udata); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3575 | context->flags |= cpu_to_be32(tx_affinity << 24); |
| 3576 | } |
| 3577 | } |
| 3578 | } |
| 3579 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3580 | if (is_sqp(ibqp->qp_type)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3581 | context->mtu_msgmax = (IB_MTU_256 << 5) | 8; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3582 | } else if ((ibqp->qp_type == IB_QPT_UD && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3583 | !(qp->flags & IB_QP_CREATE_SOURCE_QPN)) || |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3584 | ibqp->qp_type == MLX5_IB_QPT_REG_UMR) { |
| 3585 | context->mtu_msgmax = (IB_MTU_4096 << 5) | 12; |
| 3586 | } else if (attr_mask & IB_QP_PATH_MTU) { |
| 3587 | if (attr->path_mtu < IB_MTU_256 || |
| 3588 | attr->path_mtu > IB_MTU_4096) { |
| 3589 | mlx5_ib_warn(dev, "invalid mtu %d\n", attr->path_mtu); |
| 3590 | err = -EINVAL; |
| 3591 | goto out; |
| 3592 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3593 | context->mtu_msgmax = (attr->path_mtu << 5) | |
| 3594 | (u8)MLX5_CAP_GEN(dev->mdev, log_max_msg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | if (attr_mask & IB_QP_DEST_QPN) |
| 3598 | context->log_pg_sz_remote_qpn = cpu_to_be32(attr->dest_qp_num); |
| 3599 | |
| 3600 | if (attr_mask & IB_QP_PKEY_INDEX) |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 3601 | context->pri_path.pkey_index = cpu_to_be16(attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3602 | |
| 3603 | /* todo implement counter_index functionality */ |
| 3604 | |
| 3605 | if (is_sqp(ibqp->qp_type)) |
| 3606 | context->pri_path.port = qp->port; |
| 3607 | |
| 3608 | if (attr_mask & IB_QP_PORT) |
| 3609 | context->pri_path.port = attr->port_num; |
| 3610 | |
| 3611 | if (attr_mask & IB_QP_AV) { |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3612 | err = mlx5_set_path(dev, qp, &attr->ah_attr, &context->pri_path, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3613 | attr_mask & IB_QP_PORT ? attr->port_num : qp->port, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3614 | attr_mask, 0, attr, false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3615 | if (err) |
| 3616 | goto out; |
| 3617 | } |
| 3618 | |
| 3619 | if (attr_mask & IB_QP_TIMEOUT) |
| 3620 | context->pri_path.ackto_lt |= attr->timeout << 3; |
| 3621 | |
| 3622 | if (attr_mask & IB_QP_ALT_PATH) { |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3623 | err = mlx5_set_path(dev, qp, &attr->alt_ah_attr, |
| 3624 | &context->alt_path, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3625 | attr->alt_port_num, |
| 3626 | attr_mask | IB_QP_PKEY_INDEX | IB_QP_TIMEOUT, |
| 3627 | 0, attr, true); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3628 | if (err) |
| 3629 | goto out; |
| 3630 | } |
| 3631 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 3632 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 3633 | &send_cq, &recv_cq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3634 | |
| 3635 | context->flags_pd = cpu_to_be32(pd ? pd->pdn : to_mpd(dev->devr.p0)->pdn); |
| 3636 | context->cqn_send = send_cq ? cpu_to_be32(send_cq->mcq.cqn) : 0; |
| 3637 | context->cqn_recv = recv_cq ? cpu_to_be32(recv_cq->mcq.cqn) : 0; |
| 3638 | context->params1 = cpu_to_be32(MLX5_IB_ACK_REQ_FREQ << 28); |
| 3639 | |
| 3640 | if (attr_mask & IB_QP_RNR_RETRY) |
| 3641 | context->params1 |= cpu_to_be32(attr->rnr_retry << 13); |
| 3642 | |
| 3643 | if (attr_mask & IB_QP_RETRY_CNT) |
| 3644 | context->params1 |= cpu_to_be32(attr->retry_cnt << 16); |
| 3645 | |
| 3646 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) { |
| 3647 | if (attr->max_rd_atomic) |
| 3648 | context->params1 |= |
| 3649 | cpu_to_be32(fls(attr->max_rd_atomic - 1) << 21); |
| 3650 | } |
| 3651 | |
| 3652 | if (attr_mask & IB_QP_SQ_PSN) |
| 3653 | context->next_send_psn = cpu_to_be32(attr->sq_psn); |
| 3654 | |
| 3655 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) { |
| 3656 | if (attr->max_dest_rd_atomic) |
| 3657 | context->params2 |= |
| 3658 | cpu_to_be32(fls(attr->max_dest_rd_atomic - 1) << 21); |
| 3659 | } |
| 3660 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3661 | if (attr_mask & (IB_QP_ACCESS_FLAGS | IB_QP_MAX_DEST_RD_ATOMIC)) { |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 3662 | __be32 access_flags; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3663 | |
| 3664 | err = to_mlx5_access_flags(qp, attr, attr_mask, &access_flags); |
| 3665 | if (err) |
| 3666 | goto out; |
| 3667 | |
| 3668 | context->params2 |= access_flags; |
| 3669 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3670 | |
| 3671 | if (attr_mask & IB_QP_MIN_RNR_TIMER) |
| 3672 | context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24); |
| 3673 | |
| 3674 | if (attr_mask & IB_QP_RQ_PSN) |
| 3675 | context->rnr_nextrecvpsn |= cpu_to_be32(attr->rq_psn); |
| 3676 | |
| 3677 | if (attr_mask & IB_QP_QKEY) |
| 3678 | context->qkey = cpu_to_be32(attr->qkey); |
| 3679 | |
| 3680 | if (qp->rq.wqe_cnt && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
| 3681 | context->db_rec_addr = cpu_to_be64(qp->db.dma); |
| 3682 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3683 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
| 3684 | u8 port_num = (attr_mask & IB_QP_PORT ? attr->port_num : |
| 3685 | qp->port) - 1; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3686 | |
| 3687 | /* Underlay port should be used - index 0 function per port */ |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3688 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3689 | port_num = 0; |
| 3690 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3691 | if (ibqp->counter) |
| 3692 | set_id = ibqp->counter->id; |
| 3693 | else |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3694 | set_id = mlx5_ib_get_counters_id(dev, port_num); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3695 | context->qp_counter_set_usr_page |= |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3696 | cpu_to_be32(set_id << 24); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3697 | } |
| 3698 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3699 | if (!ibqp->uobject && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
| 3700 | context->sq_crq_size |= cpu_to_be16(1 << 4); |
| 3701 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3702 | if (qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1) |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 3703 | context->deth_sqpn = cpu_to_be32(1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3704 | |
| 3705 | mlx5_cur = to_mlx5_state(cur_state); |
| 3706 | mlx5_new = to_mlx5_state(new_state); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3707 | |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3708 | 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] | 3709 | !optab[mlx5_cur][mlx5_new]) { |
| 3710 | err = -EINVAL; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3711 | goto out; |
Dan Carpenter | 5d414b1 | 2018-03-06 13:00:31 +0300 | [diff] [blame] | 3712 | } |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3713 | |
| 3714 | op = optab[mlx5_cur][mlx5_new]; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3715 | optpar = ib_mask_to_mlx5_opt(attr_mask); |
| 3716 | optpar &= opt_mask[mlx5_cur][mlx5_new][mlx5_st]; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3717 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3718 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3719 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3720 | struct mlx5_modify_raw_qp_param raw_qp_param = {}; |
| 3721 | |
| 3722 | raw_qp_param.operation = op; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3723 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3724 | raw_qp_param.rq_q_ctr_id = set_id; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3725 | raw_qp_param.set_mask |= MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID; |
| 3726 | } |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3727 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3728 | if (attr_mask & IB_QP_PORT) |
| 3729 | raw_qp_param.port = attr->port_num; |
| 3730 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3731 | if (attr_mask & IB_QP_RATE_LIMIT) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3732 | raw_qp_param.rl.rate = attr->rate_limit; |
| 3733 | |
| 3734 | if (ucmd->burst_info.max_burst_sz) { |
| 3735 | if (attr->rate_limit && |
| 3736 | MLX5_CAP_QOS(dev->mdev, packet_pacing_burst_bound)) { |
| 3737 | raw_qp_param.rl.max_burst_sz = |
| 3738 | ucmd->burst_info.max_burst_sz; |
| 3739 | } else { |
| 3740 | err = -EINVAL; |
| 3741 | goto out; |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | if (ucmd->burst_info.typical_pkt_sz) { |
| 3746 | if (attr->rate_limit && |
| 3747 | MLX5_CAP_QOS(dev->mdev, packet_pacing_typical_size)) { |
| 3748 | raw_qp_param.rl.typical_pkt_sz = |
| 3749 | ucmd->burst_info.typical_pkt_sz; |
| 3750 | } else { |
| 3751 | err = -EINVAL; |
| 3752 | goto out; |
| 3753 | } |
| 3754 | } |
| 3755 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3756 | raw_qp_param.set_mask |= MLX5_RAW_QP_RATE_LIMIT; |
| 3757 | } |
| 3758 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3759 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, tx_affinity); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3760 | } else { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3761 | err = mlx5_core_qp_modify(dev, op, optpar, context, &base->mqp); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3762 | } |
| 3763 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3764 | if (err) |
| 3765 | goto out; |
| 3766 | |
| 3767 | qp->state = new_state; |
| 3768 | |
| 3769 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3770 | qp->trans_qp.atomic_rd_en = attr->qp_access_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3771 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3772 | qp->trans_qp.resp_depth = attr->max_dest_rd_atomic; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3773 | if (attr_mask & IB_QP_PORT) |
| 3774 | qp->port = attr->port_num; |
| 3775 | if (attr_mask & IB_QP_ALT_PATH) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3776 | qp->trans_qp.alt_port = attr->alt_port_num; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3777 | |
| 3778 | /* |
| 3779 | * If we moved a kernel QP to RESET, clean up all old CQ |
| 3780 | * entries and reinitialize the QP. |
| 3781 | */ |
Leon Romanovsky | 75a4598 | 2018-03-11 13:51:32 +0200 | [diff] [blame] | 3782 | if (new_state == IB_QPS_RESET && |
| 3783 | !ibqp->uobject && ibqp->qp_type != IB_QPT_XRC_TGT) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3784 | mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3785 | ibqp->srq ? to_msrq(ibqp->srq) : NULL); |
| 3786 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3787 | mlx5_ib_cq_clean(send_cq, base->mqp.qpn, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3788 | |
| 3789 | qp->rq.head = 0; |
| 3790 | qp->rq.tail = 0; |
| 3791 | qp->sq.head = 0; |
| 3792 | qp->sq.tail = 0; |
| 3793 | qp->sq.cur_post = 0; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3794 | if (qp->sq.wqe_cnt) |
| 3795 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
Leon Romanovsky | 950bf4f | 2020-03-18 11:16:40 +0200 | [diff] [blame] | 3796 | qp->sq.last_poll = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3797 | qp->db.db[MLX5_RCV_DBR] = 0; |
| 3798 | qp->db.db[MLX5_SND_DBR] = 0; |
| 3799 | } |
| 3800 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3801 | if ((new_state == IB_QPS_RTS) && qp->counter_pending) { |
| 3802 | err = __mlx5_ib_qp_set_counter(ibqp, ibqp->counter); |
| 3803 | if (!err) |
| 3804 | qp->counter_pending = 0; |
| 3805 | } |
| 3806 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3807 | out: |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 3808 | kfree(context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3809 | return err; |
| 3810 | } |
| 3811 | |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3812 | static inline bool is_valid_mask(int mask, int req, int opt) |
| 3813 | { |
| 3814 | if ((mask & req) != req) |
| 3815 | return false; |
| 3816 | |
| 3817 | if (mask & ~(req | opt)) |
| 3818 | return false; |
| 3819 | |
| 3820 | return true; |
| 3821 | } |
| 3822 | |
| 3823 | /* check valid transition for driver QP types |
| 3824 | * for now the only QP type that this function supports is DCI |
| 3825 | */ |
| 3826 | static bool modify_dci_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state new_state, |
| 3827 | enum ib_qp_attr_mask attr_mask) |
| 3828 | { |
| 3829 | int req = IB_QP_STATE; |
| 3830 | int opt = 0; |
| 3831 | |
Moni Shoua | 99ed748 | 2018-09-12 09:33:55 +0300 | [diff] [blame] | 3832 | if (new_state == IB_QPS_RESET) { |
| 3833 | return is_valid_mask(attr_mask, req, opt); |
| 3834 | } else if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3835 | req |= IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3836 | return is_valid_mask(attr_mask, req, opt); |
| 3837 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_INIT) { |
| 3838 | opt = IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3839 | return is_valid_mask(attr_mask, req, opt); |
| 3840 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 3841 | req |= IB_QP_PATH_MTU; |
Artemy Kovalyov | 5ec0304 | 2018-11-05 08:12:07 +0200 | [diff] [blame] | 3842 | opt = IB_QP_PKEY_INDEX | IB_QP_AV; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3843 | return is_valid_mask(attr_mask, req, opt); |
| 3844 | } else if (cur_state == IB_QPS_RTR && new_state == IB_QPS_RTS) { |
| 3845 | req |= IB_QP_TIMEOUT | IB_QP_RETRY_CNT | IB_QP_RNR_RETRY | |
| 3846 | IB_QP_MAX_QP_RD_ATOMIC | IB_QP_SQ_PSN; |
| 3847 | opt = IB_QP_MIN_RNR_TIMER; |
| 3848 | return is_valid_mask(attr_mask, req, opt); |
| 3849 | } else if (cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) { |
| 3850 | opt = IB_QP_MIN_RNR_TIMER; |
| 3851 | return is_valid_mask(attr_mask, req, opt); |
| 3852 | } else if (cur_state != IB_QPS_RESET && new_state == IB_QPS_ERR) { |
| 3853 | return is_valid_mask(attr_mask, req, opt); |
| 3854 | } |
| 3855 | return false; |
| 3856 | } |
| 3857 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3858 | /* mlx5_ib_modify_dct: modify a DCT QP |
| 3859 | * valid transitions are: |
| 3860 | * RESET to INIT: must set access_flags, pkey_index and port |
| 3861 | * INIT to RTR : must set min_rnr_timer, tclass, flow_label, |
| 3862 | * mtu, gid_index and hop_limit |
| 3863 | * Other transitions and attributes are illegal |
| 3864 | */ |
| 3865 | static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 3866 | int attr_mask, struct ib_udata *udata) |
| 3867 | { |
| 3868 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 3869 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3870 | enum ib_qp_state cur_state, new_state; |
| 3871 | int err = 0; |
| 3872 | int required = IB_QP_STATE; |
| 3873 | void *dctc; |
| 3874 | |
| 3875 | if (!(attr_mask & IB_QP_STATE)) |
| 3876 | return -EINVAL; |
| 3877 | |
| 3878 | cur_state = qp->state; |
| 3879 | new_state = attr->qp_state; |
| 3880 | |
| 3881 | dctc = MLX5_ADDR_OF(create_dct_in, qp->dct.in, dct_context_entry); |
| 3882 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3883 | u16 set_id; |
| 3884 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3885 | required |= IB_QP_ACCESS_FLAGS | IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3886 | if (!is_valid_mask(attr_mask, required, 0)) |
| 3887 | return -EINVAL; |
| 3888 | |
| 3889 | if (attr->port_num == 0 || |
| 3890 | attr->port_num > MLX5_CAP_GEN(dev->mdev, num_ports)) { |
| 3891 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 3892 | attr->port_num, dev->num_ports); |
| 3893 | return -EINVAL; |
| 3894 | } |
| 3895 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_READ) |
| 3896 | MLX5_SET(dctc, dctc, rre, 1); |
| 3897 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE) |
| 3898 | MLX5_SET(dctc, dctc, rwe, 1); |
| 3899 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3900 | int atomic_mode; |
| 3901 | |
| 3902 | atomic_mode = get_atomic_mode(dev, MLX5_IB_QPT_DCT); |
| 3903 | if (atomic_mode < 0) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3904 | return -EOPNOTSUPP; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3905 | |
| 3906 | MLX5_SET(dctc, dctc, atomic_mode, atomic_mode); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3907 | MLX5_SET(dctc, dctc, rae, 1); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3908 | } |
| 3909 | MLX5_SET(dctc, dctc, pkey_index, attr->pkey_index); |
| 3910 | MLX5_SET(dctc, dctc, port, attr->port_num); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3911 | |
| 3912 | set_id = mlx5_ib_get_counters_id(dev, attr->port_num - 1); |
| 3913 | MLX5_SET(dctc, dctc, counter_set_id, set_id); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3914 | |
| 3915 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 3916 | struct mlx5_ib_modify_qp_resp resp = {}; |
Yishai Hadas | c5ae195 | 2019-03-06 19:21:42 +0200 | [diff] [blame] | 3917 | u32 out[MLX5_ST_SZ_DW(create_dct_out)] = {0}; |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3918 | u32 min_resp_len = offsetof(typeof(resp), dctn) + |
| 3919 | sizeof(resp.dctn); |
| 3920 | |
| 3921 | if (udata->outlen < min_resp_len) |
| 3922 | return -EINVAL; |
| 3923 | resp.response_length = min_resp_len; |
| 3924 | |
| 3925 | required |= IB_QP_MIN_RNR_TIMER | IB_QP_AV | IB_QP_PATH_MTU; |
| 3926 | if (!is_valid_mask(attr_mask, required, 0)) |
| 3927 | return -EINVAL; |
| 3928 | MLX5_SET(dctc, dctc, min_rnr_nak, attr->min_rnr_timer); |
| 3929 | MLX5_SET(dctc, dctc, tclass, attr->ah_attr.grh.traffic_class); |
| 3930 | MLX5_SET(dctc, dctc, flow_label, attr->ah_attr.grh.flow_label); |
| 3931 | MLX5_SET(dctc, dctc, mtu, attr->path_mtu); |
| 3932 | MLX5_SET(dctc, dctc, my_addr_index, attr->ah_attr.grh.sgid_index); |
| 3933 | MLX5_SET(dctc, dctc, hop_limit, attr->ah_attr.grh.hop_limit); |
| 3934 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3935 | err = mlx5_core_create_dct(dev, &qp->dct.mdct, qp->dct.in, |
Yishai Hadas | c5ae195 | 2019-03-06 19:21:42 +0200 | [diff] [blame] | 3936 | MLX5_ST_SZ_BYTES(create_dct_in), out, |
| 3937 | sizeof(out)); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3938 | if (err) |
| 3939 | return err; |
| 3940 | resp.dctn = qp->dct.mdct.mqp.qpn; |
| 3941 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 3942 | if (err) { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3943 | mlx5_core_destroy_dct(dev, &qp->dct.mdct); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3944 | return err; |
| 3945 | } |
| 3946 | } else { |
| 3947 | mlx5_ib_warn(dev, "Modify DCT: Invalid transition from %d to %d\n", cur_state, new_state); |
| 3948 | return -EINVAL; |
| 3949 | } |
| 3950 | if (err) |
| 3951 | qp->state = IB_QPS_ERR; |
| 3952 | else |
| 3953 | qp->state = new_state; |
| 3954 | return err; |
| 3955 | } |
| 3956 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3957 | int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 3958 | int attr_mask, struct ib_udata *udata) |
| 3959 | { |
| 3960 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3961 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3962 | struct mlx5_ib_modify_qp ucmd = {}; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3963 | enum ib_qp_type qp_type; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3964 | enum ib_qp_state cur_state, new_state; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3965 | size_t required_cmd_sz; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3966 | int err = -EINVAL; |
| 3967 | int port; |
| 3968 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 3969 | if (ibqp->rwq_ind_tbl) |
| 3970 | return -ENOSYS; |
| 3971 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3972 | if (udata && udata->inlen) { |
| 3973 | required_cmd_sz = offsetof(typeof(ucmd), reserved) + |
| 3974 | sizeof(ucmd.reserved); |
| 3975 | if (udata->inlen < required_cmd_sz) |
| 3976 | return -EINVAL; |
| 3977 | |
| 3978 | if (udata->inlen > sizeof(ucmd) && |
| 3979 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 3980 | udata->inlen - sizeof(ucmd))) |
| 3981 | return -EOPNOTSUPP; |
| 3982 | |
| 3983 | if (ib_copy_from_udata(&ucmd, udata, |
| 3984 | min(udata->inlen, sizeof(ucmd)))) |
| 3985 | return -EFAULT; |
| 3986 | |
| 3987 | if (ucmd.comp_mask || |
| 3988 | memchr_inv(&ucmd.reserved, 0, sizeof(ucmd.reserved)) || |
| 3989 | memchr_inv(&ucmd.burst_info.reserved, 0, |
| 3990 | sizeof(ucmd.burst_info.reserved))) |
| 3991 | return -EOPNOTSUPP; |
| 3992 | } |
| 3993 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3994 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 3995 | return mlx5_ib_gsi_modify_qp(ibqp, attr, attr_mask); |
| 3996 | |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3997 | if (ibqp->qp_type == IB_QPT_DRIVER) |
| 3998 | qp_type = qp->qp_sub_type; |
| 3999 | else |
| 4000 | qp_type = (unlikely(ibqp->qp_type == MLX5_IB_QPT_HW_GSI)) ? |
| 4001 | IB_QPT_GSI : ibqp->qp_type; |
| 4002 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 4003 | if (qp_type == MLX5_IB_QPT_DCT) |
| 4004 | return mlx5_ib_modify_dct(ibqp, attr, attr_mask, udata); |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4005 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4006 | mutex_lock(&qp->mutex); |
| 4007 | |
| 4008 | cur_state = attr_mask & IB_QP_CUR_STATE ? attr->cur_qp_state : qp->state; |
| 4009 | new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; |
| 4010 | |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 4011 | if (!(cur_state == new_state && cur_state == IB_QPS_RESET)) { |
| 4012 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 4013 | } |
| 4014 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 4015 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 4016 | if (attr_mask & ~(IB_QP_STATE | IB_QP_CUR_STATE)) { |
| 4017 | mlx5_ib_dbg(dev, "invalid attr_mask 0x%x when underlay QP is used\n", |
| 4018 | attr_mask); |
| 4019 | goto out; |
| 4020 | } |
| 4021 | } else if (qp_type != MLX5_IB_QPT_REG_UMR && |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4022 | qp_type != MLX5_IB_QPT_DCI && |
Kamal Heib | d31131b | 2018-10-02 16:11:21 +0300 | [diff] [blame] | 4023 | !ib_modify_qp_is_ok(cur_state, new_state, qp_type, |
| 4024 | attr_mask)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4025 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 4026 | cur_state, new_state, ibqp->qp_type, attr_mask); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4027 | goto out; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4028 | } else if (qp_type == MLX5_IB_QPT_DCI && |
| 4029 | !modify_dci_qp_is_ok(cur_state, new_state, attr_mask)) { |
| 4030 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 4031 | cur_state, new_state, qp_type, attr_mask); |
| 4032 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4033 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4034 | |
| 4035 | if ((attr_mask & IB_QP_PORT) && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4036 | (attr->port_num == 0 || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4037 | attr->port_num > dev->num_ports)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4038 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 4039 | attr->port_num, dev->num_ports); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4040 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4041 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4042 | |
| 4043 | if (attr_mask & IB_QP_PKEY_INDEX) { |
| 4044 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4045 | if (attr->pkey_index >= |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4046 | dev->mdev->port_caps[port - 1].pkey_table_len) { |
| 4047 | mlx5_ib_dbg(dev, "invalid pkey index %d\n", |
| 4048 | attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4049 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4050 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4054 | attr->max_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4055 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_res_qp))) { |
| 4056 | mlx5_ib_dbg(dev, "invalid max_rd_atomic value %d\n", |
| 4057 | attr->max_rd_atomic); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4058 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4059 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4060 | |
| 4061 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4062 | attr->max_dest_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4063 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_req_qp))) { |
| 4064 | mlx5_ib_dbg(dev, "invalid max_dest_rd_atomic value %d\n", |
| 4065 | attr->max_dest_rd_atomic); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4066 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4067 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4068 | |
| 4069 | if (cur_state == new_state && cur_state == IB_QPS_RESET) { |
| 4070 | err = 0; |
| 4071 | goto out; |
| 4072 | } |
| 4073 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4074 | err = __mlx5_ib_modify_qp(ibqp, attr, attr_mask, cur_state, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 4075 | new_state, &ucmd, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4076 | |
| 4077 | out: |
| 4078 | mutex_unlock(&qp->mutex); |
| 4079 | return err; |
| 4080 | } |
| 4081 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4082 | static void _handle_post_send_edge(struct mlx5_ib_wq *sq, void **seg, |
| 4083 | u32 wqe_sz, void **cur_edge) |
| 4084 | { |
| 4085 | u32 idx; |
| 4086 | |
| 4087 | idx = (sq->cur_post + (wqe_sz >> 2)) & (sq->wqe_cnt - 1); |
| 4088 | *cur_edge = get_sq_edge(sq, idx); |
| 4089 | |
| 4090 | *seg = mlx5_frag_buf_get_wqe(&sq->fbc, idx); |
| 4091 | } |
| 4092 | |
| 4093 | /* handle_post_send_edge - Check if we get to SQ edge. If yes, update to the |
| 4094 | * next nearby edge and get new address translation for current WQE position. |
| 4095 | * @sq - SQ buffer. |
| 4096 | * @seg: Current WQE position (16B aligned). |
| 4097 | * @wqe_sz: Total current WQE size [16B]. |
| 4098 | * @cur_edge: Updated current edge. |
| 4099 | */ |
| 4100 | static inline void handle_post_send_edge(struct mlx5_ib_wq *sq, void **seg, |
| 4101 | u32 wqe_sz, void **cur_edge) |
| 4102 | { |
| 4103 | if (likely(*seg != *cur_edge)) |
| 4104 | return; |
| 4105 | |
| 4106 | _handle_post_send_edge(sq, seg, wqe_sz, cur_edge); |
| 4107 | } |
| 4108 | |
| 4109 | /* memcpy_send_wqe - copy data from src to WQE and update the relevant WQ's |
| 4110 | * pointers. At the end @seg is aligned to 16B regardless the copied size. |
| 4111 | * @sq - SQ buffer. |
| 4112 | * @cur_edge: Updated current edge. |
| 4113 | * @seg: Current WQE position (16B aligned). |
| 4114 | * @wqe_sz: Total current WQE size [16B]. |
| 4115 | * @src: Pointer to copy from. |
| 4116 | * @n: Number of bytes to copy. |
| 4117 | */ |
| 4118 | static inline void memcpy_send_wqe(struct mlx5_ib_wq *sq, void **cur_edge, |
| 4119 | void **seg, u32 *wqe_sz, const void *src, |
| 4120 | size_t n) |
| 4121 | { |
| 4122 | while (likely(n)) { |
| 4123 | size_t leftlen = *cur_edge - *seg; |
| 4124 | size_t copysz = min_t(size_t, leftlen, n); |
| 4125 | size_t stride; |
| 4126 | |
| 4127 | memcpy(*seg, src, copysz); |
| 4128 | |
| 4129 | n -= copysz; |
| 4130 | src += copysz; |
| 4131 | stride = !n ? ALIGN(copysz, 16) : copysz; |
| 4132 | *seg += stride; |
| 4133 | *wqe_sz += stride >> 4; |
| 4134 | handle_post_send_edge(sq, seg, *wqe_sz, cur_edge); |
| 4135 | } |
| 4136 | } |
| 4137 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4138 | static int mlx5_wq_overflow(struct mlx5_ib_wq *wq, int nreq, struct ib_cq *ib_cq) |
| 4139 | { |
| 4140 | struct mlx5_ib_cq *cq; |
| 4141 | unsigned cur; |
| 4142 | |
| 4143 | cur = wq->head - wq->tail; |
| 4144 | if (likely(cur + nreq < wq->max_post)) |
| 4145 | return 0; |
| 4146 | |
| 4147 | cq = to_mcq(ib_cq); |
| 4148 | spin_lock(&cq->lock); |
| 4149 | cur = wq->head - wq->tail; |
| 4150 | spin_unlock(&cq->lock); |
| 4151 | |
| 4152 | return cur + nreq >= wq->max_post; |
| 4153 | } |
| 4154 | |
| 4155 | static __always_inline void set_raddr_seg(struct mlx5_wqe_raddr_seg *rseg, |
| 4156 | u64 remote_addr, u32 rkey) |
| 4157 | { |
| 4158 | rseg->raddr = cpu_to_be64(remote_addr); |
| 4159 | rseg->rkey = cpu_to_be32(rkey); |
| 4160 | rseg->reserved = 0; |
| 4161 | } |
| 4162 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4163 | static void set_eth_seg(const struct ib_send_wr *wr, struct mlx5_ib_qp *qp, |
| 4164 | void **seg, int *size, void **cur_edge) |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4165 | { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4166 | struct mlx5_wqe_eth_seg *eseg = *seg; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4167 | |
| 4168 | memset(eseg, 0, sizeof(struct mlx5_wqe_eth_seg)); |
| 4169 | |
| 4170 | if (wr->send_flags & IB_SEND_IP_CSUM) |
| 4171 | eseg->cs_flags = MLX5_ETH_WQE_L3_CSUM | |
| 4172 | MLX5_ETH_WQE_L4_CSUM; |
| 4173 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4174 | if (wr->opcode == IB_WR_LSO) { |
| 4175 | struct ib_ud_wr *ud_wr = container_of(wr, struct ib_ud_wr, wr); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4176 | size_t left, copysz; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4177 | void *pdata = ud_wr->header; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4178 | size_t stride; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4179 | |
| 4180 | left = ud_wr->hlen; |
| 4181 | eseg->mss = cpu_to_be16(ud_wr->mss); |
Saeed Mahameed | 2b31f7a | 2016-11-28 18:04:50 +0200 | [diff] [blame] | 4182 | eseg->inline_hdr.sz = cpu_to_be16(left); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4183 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4184 | /* memcpy_send_wqe should get a 16B align address. Hence, we |
| 4185 | * first copy up to the current edge and then, if needed, |
| 4186 | * fall-through to memcpy_send_wqe. |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4187 | */ |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4188 | copysz = min_t(u64, *cur_edge - (void *)eseg->inline_hdr.start, |
| 4189 | left); |
| 4190 | memcpy(eseg->inline_hdr.start, pdata, copysz); |
| 4191 | stride = ALIGN(sizeof(struct mlx5_wqe_eth_seg) - |
| 4192 | sizeof(eseg->inline_hdr.start) + copysz, 16); |
| 4193 | *size += stride / 16; |
| 4194 | *seg += stride; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4195 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4196 | if (copysz < left) { |
| 4197 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4198 | left -= copysz; |
| 4199 | pdata += copysz; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4200 | memcpy_send_wqe(&qp->sq, cur_edge, seg, size, pdata, |
| 4201 | left); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4202 | } |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4203 | |
| 4204 | return; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4205 | } |
| 4206 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4207 | *seg += sizeof(struct mlx5_wqe_eth_seg); |
| 4208 | *size += sizeof(struct mlx5_wqe_eth_seg) / 16; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4209 | } |
| 4210 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4211 | static void set_datagram_seg(struct mlx5_wqe_datagram_seg *dseg, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4212 | const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4213 | { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4214 | memcpy(&dseg->av, &to_mah(ud_wr(wr)->ah)->av, sizeof(struct mlx5_av)); |
| 4215 | dseg->av.dqp_dct = cpu_to_be32(ud_wr(wr)->remote_qpn | MLX5_EXTENDED_UD_AV); |
| 4216 | dseg->av.key.qkey.qkey = cpu_to_be32(ud_wr(wr)->remote_qkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4217 | } |
| 4218 | |
| 4219 | static void set_data_ptr_seg(struct mlx5_wqe_data_seg *dseg, struct ib_sge *sg) |
| 4220 | { |
| 4221 | dseg->byte_count = cpu_to_be32(sg->length); |
| 4222 | dseg->lkey = cpu_to_be32(sg->lkey); |
| 4223 | dseg->addr = cpu_to_be64(sg->addr); |
| 4224 | } |
| 4225 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4226 | static u64 get_xlt_octo(u64 bytes) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4227 | { |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4228 | return ALIGN(bytes, MLX5_IB_UMR_XLT_ALIGNMENT) / |
| 4229 | MLX5_IB_UMR_OCTOWORD; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4230 | } |
| 4231 | |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4232 | static __be64 frwr_mkey_mask(bool atomic) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4233 | { |
| 4234 | u64 result; |
| 4235 | |
| 4236 | result = MLX5_MKEY_MASK_LEN | |
| 4237 | MLX5_MKEY_MASK_PAGE_SIZE | |
| 4238 | MLX5_MKEY_MASK_START_ADDR | |
| 4239 | MLX5_MKEY_MASK_EN_RINVAL | |
| 4240 | MLX5_MKEY_MASK_KEY | |
| 4241 | MLX5_MKEY_MASK_LR | |
| 4242 | MLX5_MKEY_MASK_LW | |
| 4243 | MLX5_MKEY_MASK_RR | |
| 4244 | MLX5_MKEY_MASK_RW | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4245 | MLX5_MKEY_MASK_SMALL_FENCE | |
| 4246 | MLX5_MKEY_MASK_FREE; |
| 4247 | |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4248 | if (atomic) |
| 4249 | result |= MLX5_MKEY_MASK_A; |
| 4250 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4251 | return cpu_to_be64(result); |
| 4252 | } |
| 4253 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4254 | static __be64 sig_mkey_mask(void) |
| 4255 | { |
| 4256 | u64 result; |
| 4257 | |
| 4258 | result = MLX5_MKEY_MASK_LEN | |
| 4259 | MLX5_MKEY_MASK_PAGE_SIZE | |
| 4260 | MLX5_MKEY_MASK_START_ADDR | |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4261 | MLX5_MKEY_MASK_EN_SIGERR | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4262 | MLX5_MKEY_MASK_EN_RINVAL | |
| 4263 | MLX5_MKEY_MASK_KEY | |
| 4264 | MLX5_MKEY_MASK_LR | |
| 4265 | MLX5_MKEY_MASK_LW | |
| 4266 | MLX5_MKEY_MASK_RR | |
| 4267 | MLX5_MKEY_MASK_RW | |
| 4268 | MLX5_MKEY_MASK_SMALL_FENCE | |
| 4269 | MLX5_MKEY_MASK_FREE | |
| 4270 | MLX5_MKEY_MASK_BSF_EN; |
| 4271 | |
| 4272 | return cpu_to_be64(result); |
| 4273 | } |
| 4274 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4275 | static void set_reg_umr_seg(struct mlx5_wqe_umr_ctrl_seg *umr, |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4276 | struct mlx5_ib_mr *mr, u8 flags, bool atomic) |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4277 | { |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4278 | int size = (mr->ndescs + mr->meta_ndescs) * mr->desc_size; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4279 | |
| 4280 | memset(umr, 0, sizeof(*umr)); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4281 | |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4282 | umr->flags = flags; |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4283 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(size)); |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4284 | umr->mkey_mask = frwr_mkey_mask(atomic); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4285 | } |
| 4286 | |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4287 | static void set_linv_umr_seg(struct mlx5_wqe_umr_ctrl_seg *umr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4288 | { |
| 4289 | memset(umr, 0, sizeof(*umr)); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4290 | umr->mkey_mask = cpu_to_be64(MLX5_MKEY_MASK_FREE); |
Max Gurtovoy | 2d22158 | 2016-10-27 16:36:36 +0300 | [diff] [blame] | 4291 | umr->flags = MLX5_UMR_INLINE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4292 | } |
| 4293 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4294 | static __be64 get_umr_enable_mr_mask(void) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4295 | { |
| 4296 | u64 result; |
| 4297 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4298 | result = MLX5_MKEY_MASK_KEY | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4299 | MLX5_MKEY_MASK_FREE; |
| 4300 | |
| 4301 | return cpu_to_be64(result); |
| 4302 | } |
| 4303 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4304 | static __be64 get_umr_disable_mr_mask(void) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4305 | { |
| 4306 | u64 result; |
| 4307 | |
| 4308 | result = MLX5_MKEY_MASK_FREE; |
| 4309 | |
| 4310 | return cpu_to_be64(result); |
| 4311 | } |
| 4312 | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4313 | static __be64 get_umr_update_translation_mask(void) |
| 4314 | { |
| 4315 | u64 result; |
| 4316 | |
| 4317 | result = MLX5_MKEY_MASK_LEN | |
| 4318 | MLX5_MKEY_MASK_PAGE_SIZE | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4319 | MLX5_MKEY_MASK_START_ADDR; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4320 | |
| 4321 | return cpu_to_be64(result); |
| 4322 | } |
| 4323 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4324 | static __be64 get_umr_update_access_mask(int atomic) |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4325 | { |
| 4326 | u64 result; |
| 4327 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4328 | result = MLX5_MKEY_MASK_LR | |
| 4329 | MLX5_MKEY_MASK_LW | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4330 | MLX5_MKEY_MASK_RR | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4331 | MLX5_MKEY_MASK_RW; |
| 4332 | |
| 4333 | if (atomic) |
| 4334 | result |= MLX5_MKEY_MASK_A; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4335 | |
| 4336 | return cpu_to_be64(result); |
| 4337 | } |
| 4338 | |
| 4339 | static __be64 get_umr_update_pd_mask(void) |
| 4340 | { |
| 4341 | u64 result; |
| 4342 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4343 | result = MLX5_MKEY_MASK_PD; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4344 | |
| 4345 | return cpu_to_be64(result); |
| 4346 | } |
| 4347 | |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 4348 | static int umr_check_mkey_mask(struct mlx5_ib_dev *dev, u64 mask) |
| 4349 | { |
| 4350 | if ((mask & MLX5_MKEY_MASK_PAGE_SIZE && |
| 4351 | MLX5_CAP_GEN(dev->mdev, umr_modify_entity_size_disabled)) || |
| 4352 | (mask & MLX5_MKEY_MASK_A && |
| 4353 | MLX5_CAP_GEN(dev->mdev, umr_modify_atomic_disabled))) |
| 4354 | return -EPERM; |
| 4355 | return 0; |
| 4356 | } |
| 4357 | |
| 4358 | static int set_reg_umr_segment(struct mlx5_ib_dev *dev, |
| 4359 | struct mlx5_wqe_umr_ctrl_seg *umr, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4360 | const struct ib_send_wr *wr, int atomic) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4361 | { |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4362 | const struct mlx5_umr_wr *umrwr = umr_wr(wr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4363 | |
| 4364 | memset(umr, 0, sizeof(*umr)); |
| 4365 | |
Yishai Hadas | 6a05395 | 2019-07-23 09:57:25 +0300 | [diff] [blame] | 4366 | if (!umrwr->ignore_free_state) { |
| 4367 | if (wr->send_flags & MLX5_IB_SEND_UMR_FAIL_IF_FREE) |
| 4368 | /* fail if free */ |
| 4369 | umr->flags = MLX5_UMR_CHECK_FREE; |
| 4370 | else |
| 4371 | /* fail if not free */ |
| 4372 | umr->flags = MLX5_UMR_CHECK_NOT_FREE; |
| 4373 | } |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4374 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4375 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(umrwr->xlt_size)); |
| 4376 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_XLT) { |
| 4377 | u64 offset = get_xlt_octo(umrwr->offset); |
| 4378 | |
| 4379 | umr->xlt_offset = cpu_to_be16(offset & 0xffff); |
| 4380 | umr->xlt_offset_47_16 = cpu_to_be32(offset >> 16); |
| 4381 | umr->flags |= MLX5_UMR_TRANSLATION_OFFSET_EN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4382 | } |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4383 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_TRANSLATION) |
| 4384 | umr->mkey_mask |= get_umr_update_translation_mask(); |
| 4385 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_PD_ACCESS) { |
| 4386 | umr->mkey_mask |= get_umr_update_access_mask(atomic); |
| 4387 | umr->mkey_mask |= get_umr_update_pd_mask(); |
| 4388 | } |
| 4389 | if (wr->send_flags & MLX5_IB_SEND_UMR_ENABLE_MR) |
| 4390 | umr->mkey_mask |= get_umr_enable_mr_mask(); |
| 4391 | if (wr->send_flags & MLX5_IB_SEND_UMR_DISABLE_MR) |
| 4392 | umr->mkey_mask |= get_umr_disable_mr_mask(); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4393 | |
| 4394 | if (!wr->num_sge) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4395 | umr->flags |= MLX5_UMR_INLINE; |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 4396 | |
| 4397 | return umr_check_mkey_mask(dev, be64_to_cpu(umr->mkey_mask)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | static u8 get_umr_flags(int acc) |
| 4401 | { |
| 4402 | return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) | |
| 4403 | (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) | |
| 4404 | (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) | |
| 4405 | (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) | |
Sagi Grimberg | 2ac4593 | 2014-02-23 14:19:09 +0200 | [diff] [blame] | 4406 | MLX5_PERM_LOCAL_READ | MLX5_PERM_UMR_EN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4407 | } |
| 4408 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4409 | static void set_reg_mkey_seg(struct mlx5_mkey_seg *seg, |
| 4410 | struct mlx5_ib_mr *mr, |
| 4411 | u32 key, int access) |
| 4412 | { |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4413 | int ndescs = ALIGN(mr->ndescs + mr->meta_ndescs, 8) >> 1; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4414 | |
| 4415 | memset(seg, 0, sizeof(*seg)); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4416 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 4417 | if (mr->access_mode == MLX5_MKC_ACCESS_MODE_MTT) |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4418 | seg->log2_page_size = ilog2(mr->ibmr.page_size); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 4419 | else if (mr->access_mode == MLX5_MKC_ACCESS_MODE_KLMS) |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4420 | /* KLMs take twice the size of MTTs */ |
| 4421 | ndescs *= 2; |
| 4422 | |
| 4423 | seg->flags = get_umr_flags(access) | mr->access_mode; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4424 | seg->qpn_mkey7_0 = cpu_to_be32((key & 0xff) | 0xffffff00); |
| 4425 | seg->flags_pd = cpu_to_be32(MLX5_MKEY_REMOTE_INVAL); |
| 4426 | seg->start_addr = cpu_to_be64(mr->ibmr.iova); |
| 4427 | seg->len = cpu_to_be64(mr->ibmr.length); |
| 4428 | seg->xlt_oct_size = cpu_to_be32(ndescs); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4429 | } |
| 4430 | |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4431 | static void set_linv_mkey_seg(struct mlx5_mkey_seg *seg) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4432 | { |
| 4433 | memset(seg, 0, sizeof(*seg)); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4434 | seg->status = MLX5_MKEY_STATUS_FREE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4435 | } |
| 4436 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4437 | static void set_reg_mkey_segment(struct mlx5_mkey_seg *seg, |
| 4438 | const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4439 | { |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4440 | const struct mlx5_umr_wr *umrwr = umr_wr(wr); |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4441 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4442 | memset(seg, 0, sizeof(*seg)); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4443 | if (wr->send_flags & MLX5_IB_SEND_UMR_DISABLE_MR) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4444 | seg->status = MLX5_MKEY_STATUS_FREE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4445 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4446 | seg->flags = convert_access(umrwr->access_flags); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4447 | if (umrwr->pd) |
| 4448 | seg->flags_pd = cpu_to_be32(to_mpd(umrwr->pd)->pdn); |
| 4449 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_TRANSLATION && |
| 4450 | !umrwr->length) |
| 4451 | seg->flags_pd |= cpu_to_be32(MLX5_MKEY_LEN64); |
| 4452 | |
| 4453 | seg->start_addr = cpu_to_be64(umrwr->virt_addr); |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4454 | seg->len = cpu_to_be64(umrwr->length); |
| 4455 | seg->log2_page_size = umrwr->page_shift; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 4456 | seg->qpn_mkey7_0 = cpu_to_be32(0xffffff00 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4457 | mlx5_mkey_variant(umrwr->mkey)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4458 | } |
| 4459 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4460 | static void set_reg_data_seg(struct mlx5_wqe_data_seg *dseg, |
| 4461 | struct mlx5_ib_mr *mr, |
| 4462 | struct mlx5_ib_pd *pd) |
| 4463 | { |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4464 | int bcount = mr->desc_size * (mr->ndescs + mr->meta_ndescs); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4465 | |
| 4466 | dseg->addr = cpu_to_be64(mr->desc_map); |
| 4467 | dseg->byte_count = cpu_to_be32(ALIGN(bcount, 64)); |
| 4468 | dseg->lkey = cpu_to_be32(pd->ibpd.local_dma_lkey); |
| 4469 | } |
| 4470 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4471 | static __be32 send_ieth(const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4472 | { |
| 4473 | switch (wr->opcode) { |
| 4474 | case IB_WR_SEND_WITH_IMM: |
| 4475 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 4476 | return wr->ex.imm_data; |
| 4477 | |
| 4478 | case IB_WR_SEND_WITH_INV: |
| 4479 | return cpu_to_be32(wr->ex.invalidate_rkey); |
| 4480 | |
| 4481 | default: |
| 4482 | return 0; |
| 4483 | } |
| 4484 | } |
| 4485 | |
| 4486 | static u8 calc_sig(void *wqe, int size) |
| 4487 | { |
| 4488 | u8 *p = wqe; |
| 4489 | u8 res = 0; |
| 4490 | int i; |
| 4491 | |
| 4492 | for (i = 0; i < size; i++) |
| 4493 | res ^= p[i]; |
| 4494 | |
| 4495 | return ~res; |
| 4496 | } |
| 4497 | |
| 4498 | static u8 wq_sig(void *wqe) |
| 4499 | { |
| 4500 | return calc_sig(wqe, (*((u8 *)wqe + 8) & 0x3f) << 4); |
| 4501 | } |
| 4502 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4503 | static int set_data_inl_seg(struct mlx5_ib_qp *qp, const struct ib_send_wr *wr, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4504 | void **wqe, int *wqe_sz, void **cur_edge) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4505 | { |
| 4506 | struct mlx5_wqe_inline_seg *seg; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4507 | size_t offset; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4508 | int inl = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4509 | int i; |
| 4510 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4511 | seg = *wqe; |
| 4512 | *wqe += sizeof(*seg); |
| 4513 | offset = sizeof(*seg); |
| 4514 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4515 | for (i = 0; i < wr->num_sge; i++) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4516 | size_t len = wr->sg_list[i].length; |
| 4517 | void *addr = (void *)(unsigned long)(wr->sg_list[i].addr); |
| 4518 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4519 | inl += len; |
| 4520 | |
| 4521 | if (unlikely(inl > qp->max_inline_data)) |
| 4522 | return -ENOMEM; |
| 4523 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4524 | while (likely(len)) { |
| 4525 | size_t leftlen; |
| 4526 | size_t copysz; |
| 4527 | |
| 4528 | handle_post_send_edge(&qp->sq, wqe, |
| 4529 | *wqe_sz + (offset >> 4), |
| 4530 | cur_edge); |
| 4531 | |
| 4532 | leftlen = *cur_edge - *wqe; |
| 4533 | copysz = min_t(size_t, leftlen, len); |
| 4534 | |
| 4535 | memcpy(*wqe, addr, copysz); |
| 4536 | len -= copysz; |
| 4537 | addr += copysz; |
| 4538 | *wqe += copysz; |
| 4539 | offset += copysz; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4540 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4541 | } |
| 4542 | |
| 4543 | seg->byte_count = cpu_to_be32(inl | MLX5_INLINE_SEG); |
| 4544 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4545 | *wqe_sz += ALIGN(inl + sizeof(seg->byte_count), 16) / 16; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4546 | |
| 4547 | return 0; |
| 4548 | } |
| 4549 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4550 | static u16 prot_field_size(enum ib_signature_type type) |
| 4551 | { |
| 4552 | switch (type) { |
| 4553 | case IB_SIG_TYPE_T10_DIF: |
| 4554 | return MLX5_DIF_SIZE; |
| 4555 | default: |
| 4556 | return 0; |
| 4557 | } |
| 4558 | } |
| 4559 | |
| 4560 | static u8 bs_selector(int block_size) |
| 4561 | { |
| 4562 | switch (block_size) { |
| 4563 | case 512: return 0x1; |
| 4564 | case 520: return 0x2; |
| 4565 | case 4096: return 0x3; |
| 4566 | case 4160: return 0x4; |
| 4567 | case 1073741824: return 0x5; |
| 4568 | default: return 0; |
| 4569 | } |
| 4570 | } |
| 4571 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4572 | static void mlx5_fill_inl_bsf(struct ib_sig_domain *domain, |
| 4573 | struct mlx5_bsf_inl *inl) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4574 | { |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4575 | /* Valid inline section and allow BSF refresh */ |
| 4576 | inl->vld_refresh = cpu_to_be16(MLX5_BSF_INL_VALID | |
| 4577 | MLX5_BSF_REFRESH_DIF); |
| 4578 | inl->dif_apptag = cpu_to_be16(domain->sig.dif.app_tag); |
| 4579 | inl->dif_reftag = cpu_to_be32(domain->sig.dif.ref_tag); |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4580 | /* repeating block */ |
| 4581 | inl->rp_inv_seed = MLX5_BSF_REPEAT_BLOCK; |
| 4582 | inl->sig_type = domain->sig.dif.bg_type == IB_T10DIF_CRC ? |
| 4583 | MLX5_DIF_CRC : MLX5_DIF_IPCS; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4584 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4585 | if (domain->sig.dif.ref_remap) |
| 4586 | inl->dif_inc_ref_guard_check |= MLX5_BSF_INC_REFTAG; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4587 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4588 | if (domain->sig.dif.app_escape) { |
| 4589 | if (domain->sig.dif.ref_escape) |
| 4590 | inl->dif_inc_ref_guard_check |= MLX5_BSF_APPREF_ESCAPE; |
| 4591 | else |
| 4592 | inl->dif_inc_ref_guard_check |= MLX5_BSF_APPTAG_ESCAPE; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4593 | } |
| 4594 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4595 | inl->dif_app_bitmask_check = |
| 4596 | cpu_to_be16(domain->sig.dif.apptag_check_mask); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | static int mlx5_set_bsf(struct ib_mr *sig_mr, |
| 4600 | struct ib_sig_attrs *sig_attrs, |
| 4601 | struct mlx5_bsf *bsf, u32 data_size) |
| 4602 | { |
| 4603 | struct mlx5_core_sig_ctx *msig = to_mmr(sig_mr)->sig; |
| 4604 | struct mlx5_bsf_basic *basic = &bsf->basic; |
| 4605 | struct ib_sig_domain *mem = &sig_attrs->mem; |
| 4606 | struct ib_sig_domain *wire = &sig_attrs->wire; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4607 | |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4608 | memset(bsf, 0, sizeof(*bsf)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4609 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4610 | /* Basic + Extended + Inline */ |
| 4611 | basic->bsf_size_sbs = 1 << 7; |
| 4612 | /* Input domain check byte mask */ |
| 4613 | basic->check_byte_mask = sig_attrs->check_mask; |
| 4614 | basic->raw_data_size = cpu_to_be32(data_size); |
| 4615 | |
| 4616 | /* Memory domain */ |
| 4617 | switch (sig_attrs->mem.sig_type) { |
| 4618 | case IB_SIG_TYPE_NONE: |
| 4619 | break; |
| 4620 | case IB_SIG_TYPE_T10_DIF: |
| 4621 | basic->mem.bs_selector = bs_selector(mem->sig.dif.pi_interval); |
| 4622 | basic->m_bfs_psv = cpu_to_be32(msig->psv_memory.psv_idx); |
| 4623 | mlx5_fill_inl_bsf(mem, &bsf->m_inl); |
| 4624 | break; |
| 4625 | default: |
| 4626 | return -EINVAL; |
| 4627 | } |
| 4628 | |
| 4629 | /* Wire domain */ |
| 4630 | switch (sig_attrs->wire.sig_type) { |
| 4631 | case IB_SIG_TYPE_NONE: |
| 4632 | break; |
| 4633 | case IB_SIG_TYPE_T10_DIF: |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4634 | if (mem->sig.dif.pi_interval == wire->sig.dif.pi_interval && |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4635 | mem->sig_type == wire->sig_type) { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4636 | /* Same block structure */ |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4637 | basic->bsf_size_sbs |= 1 << 4; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4638 | if (mem->sig.dif.bg_type == wire->sig.dif.bg_type) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4639 | basic->wire.copy_byte_mask |= MLX5_CPY_GRD_MASK; |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4640 | if (mem->sig.dif.app_tag == wire->sig.dif.app_tag) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4641 | basic->wire.copy_byte_mask |= MLX5_CPY_APP_MASK; |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4642 | if (mem->sig.dif.ref_tag == wire->sig.dif.ref_tag) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4643 | basic->wire.copy_byte_mask |= MLX5_CPY_REF_MASK; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4644 | } else |
| 4645 | basic->wire.bs_selector = bs_selector(wire->sig.dif.pi_interval); |
| 4646 | |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4647 | basic->w_bfs_psv = cpu_to_be32(msig->psv_wire.psv_idx); |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4648 | mlx5_fill_inl_bsf(wire, &bsf->w_inl); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4649 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4650 | default: |
| 4651 | return -EINVAL; |
| 4652 | } |
| 4653 | |
| 4654 | return 0; |
| 4655 | } |
| 4656 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4657 | static int set_sig_data_segment(const struct ib_send_wr *send_wr, |
| 4658 | struct ib_mr *sig_mr, |
| 4659 | struct ib_sig_attrs *sig_attrs, |
| 4660 | struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4661 | void **cur_edge) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4662 | { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4663 | struct mlx5_bsf *bsf; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4664 | u32 data_len; |
| 4665 | u32 data_key; |
| 4666 | u64 data_va; |
| 4667 | u32 prot_len = 0; |
| 4668 | u32 prot_key = 0; |
| 4669 | u64 prot_va = 0; |
| 4670 | bool prot = false; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4671 | int ret; |
| 4672 | int wqe_size; |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4673 | struct mlx5_ib_mr *mr = to_mmr(sig_mr); |
| 4674 | struct mlx5_ib_mr *pi_mr = mr->pi_mr; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4675 | |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4676 | data_len = pi_mr->data_length; |
| 4677 | data_key = pi_mr->ibmr.lkey; |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 4678 | data_va = pi_mr->data_iova; |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4679 | if (pi_mr->meta_ndescs) { |
| 4680 | prot_len = pi_mr->meta_length; |
| 4681 | prot_key = pi_mr->ibmr.lkey; |
Israel Rukshin | de0ae95 | 2019-06-11 18:52:55 +0300 | [diff] [blame] | 4682 | prot_va = pi_mr->pi_iova; |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4683 | prot = true; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4684 | } |
| 4685 | |
| 4686 | if (!prot || (data_key == prot_key && data_va == prot_va && |
| 4687 | data_len == prot_len)) { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4688 | /** |
| 4689 | * Source domain doesn't contain signature information |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4690 | * or data and protection are interleaved in memory. |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4691 | * So need construct: |
| 4692 | * ------------------ |
| 4693 | * | data_klm | |
| 4694 | * ------------------ |
| 4695 | * | BSF | |
| 4696 | * ------------------ |
| 4697 | **/ |
| 4698 | struct mlx5_klm *data_klm = *seg; |
| 4699 | |
| 4700 | data_klm->bcount = cpu_to_be32(data_len); |
| 4701 | data_klm->key = cpu_to_be32(data_key); |
| 4702 | data_klm->va = cpu_to_be64(data_va); |
| 4703 | wqe_size = ALIGN(sizeof(*data_klm), 64); |
| 4704 | } else { |
| 4705 | /** |
| 4706 | * Source domain contains signature information |
| 4707 | * So need construct a strided block format: |
| 4708 | * --------------------------- |
| 4709 | * | stride_block_ctrl | |
| 4710 | * --------------------------- |
| 4711 | * | data_klm | |
| 4712 | * --------------------------- |
| 4713 | * | prot_klm | |
| 4714 | * --------------------------- |
| 4715 | * | BSF | |
| 4716 | * --------------------------- |
| 4717 | **/ |
| 4718 | struct mlx5_stride_block_ctrl_seg *sblock_ctrl; |
| 4719 | struct mlx5_stride_block_entry *data_sentry; |
| 4720 | struct mlx5_stride_block_entry *prot_sentry; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4721 | u16 block_size = sig_attrs->mem.sig.dif.pi_interval; |
| 4722 | int prot_size; |
| 4723 | |
| 4724 | sblock_ctrl = *seg; |
| 4725 | data_sentry = (void *)sblock_ctrl + sizeof(*sblock_ctrl); |
| 4726 | prot_sentry = (void *)data_sentry + sizeof(*data_sentry); |
| 4727 | |
| 4728 | prot_size = prot_field_size(sig_attrs->mem.sig_type); |
| 4729 | if (!prot_size) { |
| 4730 | pr_err("Bad block size given: %u\n", block_size); |
| 4731 | return -EINVAL; |
| 4732 | } |
| 4733 | sblock_ctrl->bcount_per_cycle = cpu_to_be32(block_size + |
| 4734 | prot_size); |
| 4735 | sblock_ctrl->op = cpu_to_be32(MLX5_STRIDE_BLOCK_OP); |
| 4736 | sblock_ctrl->repeat_count = cpu_to_be32(data_len / block_size); |
| 4737 | sblock_ctrl->num_entries = cpu_to_be16(2); |
| 4738 | |
| 4739 | data_sentry->bcount = cpu_to_be16(block_size); |
| 4740 | data_sentry->key = cpu_to_be32(data_key); |
| 4741 | data_sentry->va = cpu_to_be64(data_va); |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4742 | data_sentry->stride = cpu_to_be16(block_size); |
| 4743 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4744 | prot_sentry->bcount = cpu_to_be16(prot_size); |
| 4745 | prot_sentry->key = cpu_to_be32(prot_key); |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4746 | prot_sentry->va = cpu_to_be64(prot_va); |
| 4747 | prot_sentry->stride = cpu_to_be16(prot_size); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4748 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4749 | wqe_size = ALIGN(sizeof(*sblock_ctrl) + sizeof(*data_sentry) + |
| 4750 | sizeof(*prot_sentry), 64); |
| 4751 | } |
| 4752 | |
| 4753 | *seg += wqe_size; |
| 4754 | *size += wqe_size / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4755 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4756 | |
| 4757 | bsf = *seg; |
| 4758 | ret = mlx5_set_bsf(sig_mr, sig_attrs, bsf, data_len); |
| 4759 | if (ret) |
| 4760 | return -EINVAL; |
| 4761 | |
| 4762 | *seg += sizeof(*bsf); |
| 4763 | *size += sizeof(*bsf) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4764 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4765 | |
| 4766 | return 0; |
| 4767 | } |
| 4768 | |
| 4769 | static void set_sig_mkey_segment(struct mlx5_mkey_seg *seg, |
Max Gurtovoy | 22465bb | 2019-06-11 18:52:45 +0300 | [diff] [blame] | 4770 | struct ib_mr *sig_mr, int access_flags, |
| 4771 | u32 size, u32 length, u32 pdn) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4772 | { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4773 | u32 sig_key = sig_mr->rkey; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4774 | u8 sigerr = to_mmr(sig_mr)->sig->sigerr_count & 1; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4775 | |
| 4776 | memset(seg, 0, sizeof(*seg)); |
| 4777 | |
Max Gurtovoy | 22465bb | 2019-06-11 18:52:45 +0300 | [diff] [blame] | 4778 | seg->flags = get_umr_flags(access_flags) | MLX5_MKC_ACCESS_MODE_KLMS; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4779 | seg->qpn_mkey7_0 = cpu_to_be32((sig_key & 0xff) | 0xffffff00); |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4780 | seg->flags_pd = cpu_to_be32(MLX5_MKEY_REMOTE_INVAL | sigerr << 26 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4781 | MLX5_MKEY_BSF_EN | pdn); |
| 4782 | seg->len = cpu_to_be64(length); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4783 | seg->xlt_oct_size = cpu_to_be32(get_xlt_octo(size)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4784 | seg->bsfs_octo_size = cpu_to_be32(MLX5_MKEY_BSF_OCTO_SIZE); |
| 4785 | } |
| 4786 | |
| 4787 | static void set_sig_umr_segment(struct mlx5_wqe_umr_ctrl_seg *umr, |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4788 | u32 size) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4789 | { |
| 4790 | memset(umr, 0, sizeof(*umr)); |
| 4791 | |
| 4792 | umr->flags = MLX5_FLAGS_INLINE | MLX5_FLAGS_CHECK_FREE; |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4793 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(size)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4794 | umr->bsf_octowords = cpu_to_be16(MLX5_MKEY_BSF_OCTO_SIZE); |
| 4795 | umr->mkey_mask = sig_mkey_mask(); |
| 4796 | } |
| 4797 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4798 | static int set_pi_umr_wr(const struct ib_send_wr *send_wr, |
| 4799 | struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4800 | void **cur_edge) |
| 4801 | { |
| 4802 | const struct ib_reg_wr *wr = reg_wr(send_wr); |
| 4803 | struct mlx5_ib_mr *sig_mr = to_mmr(wr->mr); |
| 4804 | struct mlx5_ib_mr *pi_mr = sig_mr->pi_mr; |
| 4805 | struct ib_sig_attrs *sig_attrs = sig_mr->ibmr.sig_attrs; |
| 4806 | u32 pdn = get_pd(qp)->pdn; |
| 4807 | u32 xlt_size; |
| 4808 | int region_len, ret; |
| 4809 | |
| 4810 | if (unlikely(send_wr->num_sge != 0) || |
| 4811 | unlikely(wr->access & IB_ACCESS_REMOTE_ATOMIC) || |
Max Gurtovoy | 185eddc | 2019-06-11 18:52:51 +0300 | [diff] [blame] | 4812 | unlikely(!sig_mr->sig) || unlikely(!qp->ibqp.integrity_en) || |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4813 | unlikely(!sig_mr->sig->sig_status_checked)) |
| 4814 | return -EINVAL; |
| 4815 | |
| 4816 | /* length of the protected region, data + protection */ |
| 4817 | region_len = pi_mr->ibmr.length; |
| 4818 | |
| 4819 | /** |
| 4820 | * KLM octoword size - if protection was provided |
| 4821 | * then we use strided block format (3 octowords), |
| 4822 | * else we use single KLM (1 octoword) |
| 4823 | **/ |
| 4824 | if (sig_attrs->mem.sig_type != IB_SIG_TYPE_NONE) |
| 4825 | xlt_size = 0x30; |
| 4826 | else |
| 4827 | xlt_size = sizeof(struct mlx5_klm); |
| 4828 | |
| 4829 | set_sig_umr_segment(*seg, xlt_size); |
| 4830 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4831 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
| 4832 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
| 4833 | |
| 4834 | set_sig_mkey_segment(*seg, wr->mr, wr->access, xlt_size, region_len, |
| 4835 | pdn); |
| 4836 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4837 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
| 4838 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
| 4839 | |
| 4840 | ret = set_sig_data_segment(send_wr, wr->mr, sig_attrs, qp, seg, size, |
| 4841 | cur_edge); |
| 4842 | if (ret) |
| 4843 | return ret; |
| 4844 | |
| 4845 | sig_mr->sig->sig_status_checked = false; |
| 4846 | return 0; |
| 4847 | } |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4848 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4849 | static int set_psv_wr(struct ib_sig_domain *domain, |
| 4850 | u32 psv_idx, void **seg, int *size) |
| 4851 | { |
| 4852 | struct mlx5_seg_set_psv *psv_seg = *seg; |
| 4853 | |
| 4854 | memset(psv_seg, 0, sizeof(*psv_seg)); |
| 4855 | psv_seg->psv_num = cpu_to_be32(psv_idx); |
| 4856 | switch (domain->sig_type) { |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4857 | case IB_SIG_TYPE_NONE: |
| 4858 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4859 | case IB_SIG_TYPE_T10_DIF: |
| 4860 | psv_seg->transient_sig = cpu_to_be32(domain->sig.dif.bg << 16 | |
| 4861 | domain->sig.dif.app_tag); |
| 4862 | psv_seg->ref_tag = cpu_to_be32(domain->sig.dif.ref_tag); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4863 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4864 | default: |
Leon Romanovsky | 12bbf1e | 2017-01-18 14:10:31 +0200 | [diff] [blame] | 4865 | pr_err("Bad signature type (%d) is given.\n", |
| 4866 | domain->sig_type); |
| 4867 | return -EINVAL; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4868 | } |
| 4869 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4870 | *seg += sizeof(*psv_seg); |
| 4871 | *size += sizeof(*psv_seg) / 16; |
| 4872 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4873 | return 0; |
| 4874 | } |
| 4875 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4876 | static int set_reg_wr(struct mlx5_ib_qp *qp, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4877 | const struct ib_reg_wr *wr, |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4878 | void **seg, int *size, void **cur_edge, |
| 4879 | bool check_not_free) |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4880 | { |
| 4881 | struct mlx5_ib_mr *mr = to_mmr(wr->mr); |
| 4882 | struct mlx5_ib_pd *pd = to_mpd(qp->ibqp.pd); |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4883 | struct mlx5_ib_dev *dev = to_mdev(pd->ibpd.device); |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4884 | int mr_list_size = (mr->ndescs + mr->meta_ndescs) * mr->desc_size; |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4885 | bool umr_inline = mr_list_size <= MLX5_IB_SQ_UMR_INLINE_THRESHOLD; |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4886 | bool atomic = wr->access & IB_ACCESS_REMOTE_ATOMIC; |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4887 | u8 flags = 0; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4888 | |
Michael Guralnik | d6de0bb | 2020-01-08 20:05:40 +0200 | [diff] [blame] | 4889 | if (!mlx5_ib_can_use_umr(dev, atomic, wr->access)) { |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4890 | mlx5_ib_warn(to_mdev(qp->ibqp.device), |
| 4891 | "Fast update of %s for MR is disabled\n", |
| 4892 | (MLX5_CAP_GEN(dev->mdev, |
| 4893 | umr_modify_entity_size_disabled)) ? |
| 4894 | "entity size" : |
| 4895 | "atomic access"); |
| 4896 | return -EINVAL; |
| 4897 | } |
| 4898 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4899 | if (unlikely(wr->wr.send_flags & IB_SEND_INLINE)) { |
| 4900 | mlx5_ib_warn(to_mdev(qp->ibqp.device), |
| 4901 | "Invalid IB_SEND_INLINE send flag\n"); |
| 4902 | return -EINVAL; |
| 4903 | } |
| 4904 | |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4905 | if (check_not_free) |
| 4906 | flags |= MLX5_UMR_CHECK_NOT_FREE; |
| 4907 | if (umr_inline) |
| 4908 | flags |= MLX5_UMR_INLINE; |
| 4909 | |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4910 | set_reg_umr_seg(*seg, mr, flags, atomic); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4911 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4912 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4913 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4914 | |
| 4915 | set_reg_mkey_seg(*seg, mr, wr->key, wr->access); |
| 4916 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4917 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4918 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4919 | |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4920 | if (umr_inline) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4921 | memcpy_send_wqe(&qp->sq, cur_edge, seg, size, mr->descs, |
| 4922 | mr_list_size); |
| 4923 | *size = ALIGN(*size, MLX5_SEND_WQE_BB >> 4); |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4924 | } else { |
| 4925 | set_reg_data_seg(*seg, mr, pd); |
| 4926 | *seg += sizeof(struct mlx5_wqe_data_seg); |
| 4927 | *size += (sizeof(struct mlx5_wqe_data_seg) / 16); |
| 4928 | } |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4929 | return 0; |
| 4930 | } |
| 4931 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4932 | static void set_linv_wr(struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4933 | void **cur_edge) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4934 | { |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4935 | set_linv_umr_seg(*seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4936 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4937 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4938 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4939 | set_linv_mkey_seg(*seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4940 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4941 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4942 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4943 | } |
| 4944 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4945 | static void dump_wqe(struct mlx5_ib_qp *qp, u32 idx, int size_16) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4946 | { |
| 4947 | __be32 *p = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4948 | int i, j; |
| 4949 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4950 | pr_debug("dump WQE index %u:\n", idx); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4951 | for (i = 0, j = 0; i < size_16 * 4; i += 4, j += 4) { |
| 4952 | if ((i & 0xf) == 0) { |
Artemy Kovalyov | 1e5887b | 2019-03-19 11:24:37 +0200 | [diff] [blame] | 4953 | p = mlx5_frag_buf_get_wqe(&qp->sq.fbc, idx); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4954 | pr_debug("WQBB at %p:\n", (void *)p); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4955 | j = 0; |
Artemy Kovalyov | 1e5887b | 2019-03-19 11:24:37 +0200 | [diff] [blame] | 4956 | idx = (idx + 1) & (qp->sq.wqe_cnt - 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4957 | } |
| 4958 | pr_debug("%08x %08x %08x %08x\n", be32_to_cpu(p[j]), |
| 4959 | be32_to_cpu(p[j + 1]), be32_to_cpu(p[j + 2]), |
| 4960 | be32_to_cpu(p[j + 3])); |
| 4961 | } |
| 4962 | } |
| 4963 | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4964 | static int __begin_wqe(struct mlx5_ib_qp *qp, void **seg, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4965 | struct mlx5_wqe_ctrl_seg **ctrl, |
| 4966 | const struct ib_send_wr *wr, unsigned int *idx, |
| 4967 | int *size, void **cur_edge, int nreq, |
| 4968 | bool send_signaled, bool solicited) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4969 | { |
Leon Romanovsky | b2a232d | 2016-08-28 10:58:35 +0300 | [diff] [blame] | 4970 | if (unlikely(mlx5_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq))) |
| 4971 | return -ENOMEM; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4972 | |
| 4973 | *idx = qp->sq.cur_post & (qp->sq.wqe_cnt - 1); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4974 | *seg = mlx5_frag_buf_get_wqe(&qp->sq.fbc, *idx); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4975 | *ctrl = *seg; |
| 4976 | *(uint32_t *)(*seg + 8) = 0; |
| 4977 | (*ctrl)->imm = send_ieth(wr); |
| 4978 | (*ctrl)->fm_ce_se = qp->sq_signal_bits | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4979 | (send_signaled ? MLX5_WQE_CTRL_CQ_UPDATE : 0) | |
| 4980 | (solicited ? MLX5_WQE_CTRL_SOLICITED : 0); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4981 | |
| 4982 | *seg += sizeof(**ctrl); |
| 4983 | *size = sizeof(**ctrl) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4984 | *cur_edge = qp->sq.cur_edge; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4985 | |
Leon Romanovsky | b2a232d | 2016-08-28 10:58:35 +0300 | [diff] [blame] | 4986 | return 0; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4987 | } |
| 4988 | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4989 | static int begin_wqe(struct mlx5_ib_qp *qp, void **seg, |
| 4990 | struct mlx5_wqe_ctrl_seg **ctrl, |
| 4991 | const struct ib_send_wr *wr, unsigned *idx, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4992 | int *size, void **cur_edge, int nreq) |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4993 | { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4994 | return __begin_wqe(qp, seg, ctrl, wr, idx, size, cur_edge, nreq, |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4995 | wr->send_flags & IB_SEND_SIGNALED, |
| 4996 | wr->send_flags & IB_SEND_SOLICITED); |
| 4997 | } |
| 4998 | |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4999 | static void finish_wqe(struct mlx5_ib_qp *qp, |
| 5000 | struct mlx5_wqe_ctrl_seg *ctrl, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5001 | void *seg, u8 size, void *cur_edge, |
| 5002 | unsigned int idx, u64 wr_id, int nreq, u8 fence, |
| 5003 | u32 mlx5_opcode) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 5004 | { |
| 5005 | u8 opmod = 0; |
| 5006 | |
| 5007 | ctrl->opmod_idx_opcode = cpu_to_be32(((u32)(qp->sq.cur_post) << 8) | |
| 5008 | mlx5_opcode | ((u32)opmod << 24)); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 5009 | ctrl->qpn_ds = cpu_to_be32(size | (qp->trans_qp.base.mqp.qpn << 8)); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 5010 | ctrl->fm_ce_se |= fence; |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 5011 | if (unlikely(qp->flags_en & MLX5_QP_FLAG_SIGNATURE)) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 5012 | ctrl->signature = wq_sig(ctrl); |
| 5013 | |
| 5014 | qp->sq.wrid[idx] = wr_id; |
| 5015 | qp->sq.w_list[idx].opcode = mlx5_opcode; |
| 5016 | qp->sq.wqe_head[idx] = qp->sq.head + nreq; |
| 5017 | qp->sq.cur_post += DIV_ROUND_UP(size * 16, MLX5_SEND_WQE_BB); |
| 5018 | qp->sq.w_list[idx].next = qp->sq.cur_post; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5019 | |
| 5020 | /* We save the edge which was possibly updated during the WQE |
| 5021 | * construction, into SQ's cache. |
| 5022 | */ |
| 5023 | seg = PTR_ALIGN(seg, MLX5_SEND_WQE_BB); |
| 5024 | qp->sq.cur_edge = (unlikely(seg == cur_edge)) ? |
| 5025 | get_sq_edge(&qp->sq, qp->sq.cur_post & |
| 5026 | (qp->sq.wqe_cnt - 1)) : |
| 5027 | cur_edge; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 5028 | } |
| 5029 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5030 | static int _mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 5031 | const struct ib_send_wr **bad_wr, bool drain) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5032 | { |
| 5033 | struct mlx5_wqe_ctrl_seg *ctrl = NULL; /* compiler warning */ |
| 5034 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 5035 | struct mlx5_core_dev *mdev = dev->mdev; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5036 | struct ib_reg_wr reg_pi_wr; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5037 | struct mlx5_ib_qp *qp; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 5038 | struct mlx5_ib_mr *mr; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5039 | struct mlx5_ib_mr *pi_mr; |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5040 | struct mlx5_ib_mr pa_pi_mr; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5041 | struct ib_sig_attrs *sig_attrs; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5042 | struct mlx5_wqe_xrc_seg *xrc; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5043 | struct mlx5_bf *bf; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5044 | void *cur_edge; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5045 | int uninitialized_var(size); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5046 | unsigned long flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5047 | unsigned idx; |
| 5048 | int err = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5049 | int num_sge; |
| 5050 | void *seg; |
| 5051 | int nreq; |
| 5052 | int i; |
| 5053 | u8 next_fence = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5054 | u8 fence; |
| 5055 | |
Parav Pandit | 6c75520 | 2018-08-28 14:45:29 +0300 | [diff] [blame] | 5056 | if (unlikely(mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR && |
| 5057 | !drain)) { |
| 5058 | *bad_wr = wr; |
| 5059 | return -EIO; |
| 5060 | } |
| 5061 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5062 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5063 | return mlx5_ib_gsi_post_send(ibqp, wr, bad_wr); |
| 5064 | |
| 5065 | qp = to_mqp(ibqp); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 5066 | bf = &qp->bf; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5067 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5068 | spin_lock_irqsave(&qp->sq.lock, flags); |
| 5069 | |
| 5070 | for (nreq = 0; wr; nreq++, wr = wr->next) { |
Fabian Frederick | a8f731e | 2014-08-12 19:20:08 -0400 | [diff] [blame] | 5071 | if (unlikely(wr->opcode >= ARRAY_SIZE(mlx5_ib_opcode))) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5072 | mlx5_ib_warn(dev, "\n"); |
| 5073 | err = -EINVAL; |
| 5074 | *bad_wr = wr; |
| 5075 | goto out; |
| 5076 | } |
| 5077 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5078 | num_sge = wr->num_sge; |
| 5079 | if (unlikely(num_sge > qp->sq.max_gs)) { |
| 5080 | mlx5_ib_warn(dev, "\n"); |
Chuck Lever | 24be409 | 2016-08-28 10:58:34 +0300 | [diff] [blame] | 5081 | err = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5082 | *bad_wr = wr; |
| 5083 | goto out; |
| 5084 | } |
| 5085 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5086 | err = begin_wqe(qp, &seg, &ctrl, wr, &idx, &size, &cur_edge, |
| 5087 | nreq); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 5088 | if (err) { |
| 5089 | mlx5_ib_warn(dev, "\n"); |
| 5090 | err = -ENOMEM; |
| 5091 | *bad_wr = wr; |
| 5092 | goto out; |
| 5093 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5094 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5095 | if (wr->opcode == IB_WR_REG_MR || |
| 5096 | wr->opcode == IB_WR_REG_MR_INTEGRITY) { |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5097 | fence = dev->umr_fence; |
| 5098 | next_fence = MLX5_FENCE_MODE_INITIATOR_SMALL; |
Majd Dibbiny | 074fca3 | 2018-11-05 08:07:37 +0200 | [diff] [blame] | 5099 | } else { |
| 5100 | if (wr->send_flags & IB_SEND_FENCE) { |
| 5101 | if (qp->next_fence) |
| 5102 | fence = MLX5_FENCE_MODE_SMALL_AND_FENCE; |
| 5103 | else |
| 5104 | fence = MLX5_FENCE_MODE_FENCE; |
| 5105 | } else { |
| 5106 | fence = qp->next_fence; |
| 5107 | } |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5108 | } |
| 5109 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5110 | switch (ibqp->qp_type) { |
| 5111 | case IB_QPT_XRC_INI: |
| 5112 | xrc = seg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5113 | seg += sizeof(*xrc); |
| 5114 | size += sizeof(*xrc) / 16; |
| 5115 | /* fall through */ |
| 5116 | case IB_QPT_RC: |
| 5117 | switch (wr->opcode) { |
| 5118 | case IB_WR_RDMA_READ: |
| 5119 | case IB_WR_RDMA_WRITE: |
| 5120 | case IB_WR_RDMA_WRITE_WITH_IMM: |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 5121 | set_raddr_seg(seg, rdma_wr(wr)->remote_addr, |
| 5122 | rdma_wr(wr)->rkey); |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 5123 | seg += sizeof(struct mlx5_wqe_raddr_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5124 | size += sizeof(struct mlx5_wqe_raddr_seg) / 16; |
| 5125 | break; |
| 5126 | |
| 5127 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 5128 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5129 | case IB_WR_MASKED_ATOMIC_CMP_AND_SWP: |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 5130 | mlx5_ib_warn(dev, "Atomic operations are not supported yet\n"); |
| 5131 | err = -ENOSYS; |
| 5132 | *bad_wr = wr; |
| 5133 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5134 | |
| 5135 | case IB_WR_LOCAL_INV: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5136 | qp->sq.wr_data[idx] = IB_WR_LOCAL_INV; |
| 5137 | ctrl->imm = cpu_to_be32(wr->ex.invalidate_rkey); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5138 | set_linv_wr(qp, &seg, &size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5139 | num_sge = 0; |
| 5140 | break; |
| 5141 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5142 | case IB_WR_REG_MR: |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5143 | qp->sq.wr_data[idx] = IB_WR_REG_MR; |
| 5144 | ctrl->imm = cpu_to_be32(reg_wr(wr)->key); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5145 | err = set_reg_wr(qp, reg_wr(wr), &seg, &size, |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 5146 | &cur_edge, true); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5147 | if (err) { |
| 5148 | *bad_wr = wr; |
| 5149 | goto out; |
| 5150 | } |
| 5151 | num_sge = 0; |
| 5152 | break; |
| 5153 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5154 | case IB_WR_REG_MR_INTEGRITY: |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5155 | qp->sq.wr_data[idx] = IB_WR_REG_MR_INTEGRITY; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5156 | |
| 5157 | mr = to_mmr(reg_wr(wr)->mr); |
| 5158 | pi_mr = mr->pi_mr; |
| 5159 | |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5160 | if (pi_mr) { |
| 5161 | memset(®_pi_wr, 0, |
| 5162 | sizeof(struct ib_reg_wr)); |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5163 | |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5164 | reg_pi_wr.mr = &pi_mr->ibmr; |
| 5165 | reg_pi_wr.access = reg_wr(wr)->access; |
| 5166 | reg_pi_wr.key = pi_mr->ibmr.rkey; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5167 | |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5168 | ctrl->imm = cpu_to_be32(reg_pi_wr.key); |
| 5169 | /* UMR for data + prot registration */ |
| 5170 | err = set_reg_wr(qp, ®_pi_wr, &seg, |
| 5171 | &size, &cur_edge, |
| 5172 | false); |
| 5173 | if (err) { |
| 5174 | *bad_wr = wr; |
| 5175 | goto out; |
| 5176 | } |
| 5177 | finish_wqe(qp, ctrl, seg, size, |
| 5178 | cur_edge, idx, wr->wr_id, |
| 5179 | nreq, fence, |
| 5180 | MLX5_OPCODE_UMR); |
| 5181 | |
| 5182 | err = begin_wqe(qp, &seg, &ctrl, wr, |
| 5183 | &idx, &size, &cur_edge, |
| 5184 | nreq); |
| 5185 | if (err) { |
| 5186 | mlx5_ib_warn(dev, "\n"); |
| 5187 | err = -ENOMEM; |
| 5188 | *bad_wr = wr; |
| 5189 | goto out; |
| 5190 | } |
| 5191 | } else { |
| 5192 | memset(&pa_pi_mr, 0, |
| 5193 | sizeof(struct mlx5_ib_mr)); |
| 5194 | /* No UMR, use local_dma_lkey */ |
| 5195 | pa_pi_mr.ibmr.lkey = |
| 5196 | mr->ibmr.pd->local_dma_lkey; |
| 5197 | |
| 5198 | pa_pi_mr.ndescs = mr->ndescs; |
| 5199 | pa_pi_mr.data_length = mr->data_length; |
| 5200 | pa_pi_mr.data_iova = mr->data_iova; |
| 5201 | if (mr->meta_ndescs) { |
| 5202 | pa_pi_mr.meta_ndescs = |
| 5203 | mr->meta_ndescs; |
| 5204 | pa_pi_mr.meta_length = |
| 5205 | mr->meta_length; |
| 5206 | pa_pi_mr.pi_iova = mr->pi_iova; |
| 5207 | } |
| 5208 | |
| 5209 | pa_pi_mr.ibmr.length = mr->ibmr.length; |
| 5210 | mr->pi_mr = &pa_pi_mr; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5211 | } |
| 5212 | ctrl->imm = cpu_to_be32(mr->ibmr.rkey); |
| 5213 | /* UMR for sig MR */ |
| 5214 | err = set_pi_umr_wr(wr, qp, &seg, &size, |
| 5215 | &cur_edge); |
| 5216 | if (err) { |
| 5217 | mlx5_ib_warn(dev, "\n"); |
| 5218 | *bad_wr = wr; |
| 5219 | goto out; |
| 5220 | } |
| 5221 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 5222 | wr->wr_id, nreq, fence, |
| 5223 | MLX5_OPCODE_UMR); |
| 5224 | |
| 5225 | /* |
| 5226 | * SET_PSV WQEs are not signaled and solicited |
| 5227 | * on error |
| 5228 | */ |
| 5229 | sig_attrs = mr->ibmr.sig_attrs; |
| 5230 | err = __begin_wqe(qp, &seg, &ctrl, wr, &idx, |
| 5231 | &size, &cur_edge, nreq, false, |
| 5232 | true); |
| 5233 | if (err) { |
| 5234 | mlx5_ib_warn(dev, "\n"); |
| 5235 | err = -ENOMEM; |
| 5236 | *bad_wr = wr; |
| 5237 | goto out; |
| 5238 | } |
| 5239 | err = set_psv_wr(&sig_attrs->mem, |
| 5240 | mr->sig->psv_memory.psv_idx, |
| 5241 | &seg, &size); |
| 5242 | if (err) { |
| 5243 | mlx5_ib_warn(dev, "\n"); |
| 5244 | *bad_wr = wr; |
| 5245 | goto out; |
| 5246 | } |
| 5247 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 5248 | wr->wr_id, nreq, next_fence, |
| 5249 | MLX5_OPCODE_SET_PSV); |
| 5250 | |
| 5251 | err = __begin_wqe(qp, &seg, &ctrl, wr, &idx, |
| 5252 | &size, &cur_edge, nreq, false, |
| 5253 | true); |
| 5254 | if (err) { |
| 5255 | mlx5_ib_warn(dev, "\n"); |
| 5256 | err = -ENOMEM; |
| 5257 | *bad_wr = wr; |
| 5258 | goto out; |
| 5259 | } |
| 5260 | err = set_psv_wr(&sig_attrs->wire, |
| 5261 | mr->sig->psv_wire.psv_idx, |
| 5262 | &seg, &size); |
| 5263 | if (err) { |
| 5264 | mlx5_ib_warn(dev, "\n"); |
| 5265 | *bad_wr = wr; |
| 5266 | goto out; |
| 5267 | } |
| 5268 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 5269 | wr->wr_id, nreq, next_fence, |
| 5270 | MLX5_OPCODE_SET_PSV); |
| 5271 | |
| 5272 | qp->next_fence = |
| 5273 | MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 5274 | num_sge = 0; |
| 5275 | goto skip_psv; |
| 5276 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5277 | default: |
| 5278 | break; |
| 5279 | } |
| 5280 | break; |
| 5281 | |
| 5282 | case IB_QPT_UC: |
| 5283 | switch (wr->opcode) { |
| 5284 | case IB_WR_RDMA_WRITE: |
| 5285 | case IB_WR_RDMA_WRITE_WITH_IMM: |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 5286 | set_raddr_seg(seg, rdma_wr(wr)->remote_addr, |
| 5287 | rdma_wr(wr)->rkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5288 | seg += sizeof(struct mlx5_wqe_raddr_seg); |
| 5289 | size += sizeof(struct mlx5_wqe_raddr_seg) / 16; |
| 5290 | break; |
| 5291 | |
| 5292 | default: |
| 5293 | break; |
| 5294 | } |
| 5295 | break; |
| 5296 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5297 | case IB_QPT_SMI: |
Maor Gottlieb | 1e0e50b | 2017-01-18 14:10:34 +0200 | [diff] [blame] | 5298 | if (unlikely(!mdev->port_caps[qp->port - 1].has_smi)) { |
| 5299 | mlx5_ib_warn(dev, "Send SMP MADs is not allowed\n"); |
| 5300 | err = -EPERM; |
| 5301 | *bad_wr = wr; |
| 5302 | goto out; |
| 5303 | } |
Bart Van Assche | f6b1ee3 | 2017-10-11 10:49:07 -0700 | [diff] [blame] | 5304 | /* fall through */ |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5305 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5306 | set_datagram_seg(seg, wr); |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 5307 | seg += sizeof(struct mlx5_wqe_datagram_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5308 | size += sizeof(struct mlx5_wqe_datagram_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5309 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
| 5310 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5311 | break; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 5312 | case IB_QPT_UD: |
| 5313 | set_datagram_seg(seg, wr); |
| 5314 | seg += sizeof(struct mlx5_wqe_datagram_seg); |
| 5315 | size += sizeof(struct mlx5_wqe_datagram_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5316 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 5317 | |
| 5318 | /* handle qp that supports ud offload */ |
| 5319 | if (qp->flags & IB_QP_CREATE_IPOIB_UD_LSO) { |
| 5320 | struct mlx5_wqe_eth_pad *pad; |
| 5321 | |
| 5322 | pad = seg; |
| 5323 | memset(pad, 0, sizeof(struct mlx5_wqe_eth_pad)); |
| 5324 | seg += sizeof(struct mlx5_wqe_eth_pad); |
| 5325 | size += sizeof(struct mlx5_wqe_eth_pad) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5326 | set_eth_seg(wr, qp, &seg, &size, &cur_edge); |
| 5327 | handle_post_send_edge(&qp->sq, &seg, size, |
| 5328 | &cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 5329 | } |
| 5330 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5331 | case MLX5_IB_QPT_REG_UMR: |
| 5332 | if (wr->opcode != MLX5_IB_WR_UMR) { |
| 5333 | err = -EINVAL; |
| 5334 | mlx5_ib_warn(dev, "bad opcode\n"); |
| 5335 | goto out; |
| 5336 | } |
| 5337 | qp->sq.wr_data[idx] = MLX5_IB_WR_UMR; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 5338 | ctrl->imm = cpu_to_be32(umr_wr(wr)->mkey); |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 5339 | err = set_reg_umr_segment(dev, seg, wr, !!(MLX5_CAP_GEN(mdev, atomic))); |
| 5340 | if (unlikely(err)) |
| 5341 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5342 | seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 5343 | size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5344 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5345 | set_reg_mkey_segment(seg, wr); |
| 5346 | seg += sizeof(struct mlx5_mkey_seg); |
| 5347 | size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5348 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5349 | break; |
| 5350 | |
| 5351 | default: |
| 5352 | break; |
| 5353 | } |
| 5354 | |
| 5355 | if (wr->send_flags & IB_SEND_INLINE && num_sge) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5356 | err = set_data_inl_seg(qp, wr, &seg, &size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5357 | if (unlikely(err)) { |
| 5358 | mlx5_ib_warn(dev, "\n"); |
| 5359 | *bad_wr = wr; |
| 5360 | goto out; |
| 5361 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5362 | } else { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5363 | for (i = 0; i < num_sge; i++) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5364 | handle_post_send_edge(&qp->sq, &seg, size, |
| 5365 | &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5366 | if (likely(wr->sg_list[i].length)) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5367 | set_data_ptr_seg |
| 5368 | ((struct mlx5_wqe_data_seg *)seg, |
| 5369 | wr->sg_list + i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5370 | size += sizeof(struct mlx5_wqe_data_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5371 | seg += sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5372 | } |
| 5373 | } |
| 5374 | } |
| 5375 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5376 | qp->next_fence = next_fence; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5377 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, wr->wr_id, nreq, |
| 5378 | fence, mlx5_ib_opcode[wr->opcode]); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 5379 | skip_psv: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5380 | if (0) |
| 5381 | dump_wqe(qp, idx, size); |
| 5382 | } |
| 5383 | |
| 5384 | out: |
| 5385 | if (likely(nreq)) { |
| 5386 | qp->sq.head += nreq; |
| 5387 | |
| 5388 | /* Make sure that descriptors are written before |
| 5389 | * updating doorbell record and ringing the doorbell |
| 5390 | */ |
| 5391 | wmb(); |
| 5392 | |
| 5393 | qp->db.db[MLX5_SND_DBR] = cpu_to_be32(qp->sq.cur_post); |
| 5394 | |
Eli Cohen | ada388f | 2014-01-14 17:45:16 +0200 | [diff] [blame] | 5395 | /* Make sure doorbell record is visible to the HCA before |
| 5396 | * we hit doorbell */ |
| 5397 | wmb(); |
| 5398 | |
Maxim Mikityanskiy | bbf29f6 | 2019-03-29 15:37:52 -0700 | [diff] [blame] | 5399 | mlx5_write64((__be32 *)ctrl, bf->bfreg->map + bf->offset); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 5400 | /* Make sure doorbells don't leak out of SQ spinlock |
| 5401 | * and reach the HCA out of order. |
| 5402 | */ |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5403 | bf->offset ^= bf->buf_size; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | spin_unlock_irqrestore(&qp->sq.lock, flags); |
| 5407 | |
| 5408 | return err; |
| 5409 | } |
| 5410 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5411 | int mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 5412 | const struct ib_send_wr **bad_wr) |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5413 | { |
| 5414 | return _mlx5_ib_post_send(ibqp, wr, bad_wr, false); |
| 5415 | } |
| 5416 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5417 | static void set_sig_seg(struct mlx5_rwqe_sig *sig, int size) |
| 5418 | { |
| 5419 | sig->signature = calc_sig(sig, size); |
| 5420 | } |
| 5421 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5422 | static int _mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 5423 | const struct ib_recv_wr **bad_wr, bool drain) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5424 | { |
| 5425 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 5426 | struct mlx5_wqe_data_seg *scat; |
| 5427 | struct mlx5_rwqe_sig *sig; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 5428 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 5429 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5430 | unsigned long flags; |
| 5431 | int err = 0; |
| 5432 | int nreq; |
| 5433 | int ind; |
| 5434 | int i; |
| 5435 | |
Parav Pandit | 6c75520 | 2018-08-28 14:45:29 +0300 | [diff] [blame] | 5436 | if (unlikely(mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR && |
| 5437 | !drain)) { |
| 5438 | *bad_wr = wr; |
| 5439 | return -EIO; |
| 5440 | } |
| 5441 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5442 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5443 | return mlx5_ib_gsi_post_recv(ibqp, wr, bad_wr); |
| 5444 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5445 | spin_lock_irqsave(&qp->rq.lock, flags); |
| 5446 | |
| 5447 | ind = qp->rq.head & (qp->rq.wqe_cnt - 1); |
| 5448 | |
| 5449 | for (nreq = 0; wr; nreq++, wr = wr->next) { |
| 5450 | if (mlx5_wq_overflow(&qp->rq, nreq, qp->ibqp.recv_cq)) { |
| 5451 | err = -ENOMEM; |
| 5452 | *bad_wr = wr; |
| 5453 | goto out; |
| 5454 | } |
| 5455 | |
| 5456 | if (unlikely(wr->num_sge > qp->rq.max_gs)) { |
| 5457 | err = -EINVAL; |
| 5458 | *bad_wr = wr; |
| 5459 | goto out; |
| 5460 | } |
| 5461 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5462 | scat = mlx5_frag_buf_get_wqe(&qp->rq.fbc, ind); |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 5463 | if (qp->flags_en & MLX5_QP_FLAG_SIGNATURE) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5464 | scat++; |
| 5465 | |
| 5466 | for (i = 0; i < wr->num_sge; i++) |
| 5467 | set_data_ptr_seg(scat + i, wr->sg_list + i); |
| 5468 | |
| 5469 | if (i < qp->rq.max_gs) { |
| 5470 | scat[i].byte_count = 0; |
| 5471 | scat[i].lkey = cpu_to_be32(MLX5_INVALID_LKEY); |
| 5472 | scat[i].addr = 0; |
| 5473 | } |
| 5474 | |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 5475 | if (qp->flags_en & MLX5_QP_FLAG_SIGNATURE) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5476 | sig = (struct mlx5_rwqe_sig *)scat; |
| 5477 | set_sig_seg(sig, (qp->rq.max_gs + 1) << 2); |
| 5478 | } |
| 5479 | |
| 5480 | qp->rq.wrid[ind] = wr->wr_id; |
| 5481 | |
| 5482 | ind = (ind + 1) & (qp->rq.wqe_cnt - 1); |
| 5483 | } |
| 5484 | |
| 5485 | out: |
| 5486 | if (likely(nreq)) { |
| 5487 | qp->rq.head += nreq; |
| 5488 | |
| 5489 | /* Make sure that descriptors are written before |
| 5490 | * doorbell record. |
| 5491 | */ |
| 5492 | wmb(); |
| 5493 | |
| 5494 | *qp->db.db = cpu_to_be32(qp->rq.head & 0xffff); |
| 5495 | } |
| 5496 | |
| 5497 | spin_unlock_irqrestore(&qp->rq.lock, flags); |
| 5498 | |
| 5499 | return err; |
| 5500 | } |
| 5501 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5502 | int mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 5503 | const struct ib_recv_wr **bad_wr) |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5504 | { |
| 5505 | return _mlx5_ib_post_recv(ibqp, wr, bad_wr, false); |
| 5506 | } |
| 5507 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5508 | static inline enum ib_qp_state to_ib_qp_state(enum mlx5_qp_state mlx5_state) |
| 5509 | { |
| 5510 | switch (mlx5_state) { |
| 5511 | case MLX5_QP_STATE_RST: return IB_QPS_RESET; |
| 5512 | case MLX5_QP_STATE_INIT: return IB_QPS_INIT; |
| 5513 | case MLX5_QP_STATE_RTR: return IB_QPS_RTR; |
| 5514 | case MLX5_QP_STATE_RTS: return IB_QPS_RTS; |
| 5515 | case MLX5_QP_STATE_SQ_DRAINING: |
| 5516 | case MLX5_QP_STATE_SQD: return IB_QPS_SQD; |
| 5517 | case MLX5_QP_STATE_SQER: return IB_QPS_SQE; |
| 5518 | case MLX5_QP_STATE_ERR: return IB_QPS_ERR; |
| 5519 | default: return -1; |
| 5520 | } |
| 5521 | } |
| 5522 | |
| 5523 | static inline enum ib_mig_state to_ib_mig_state(int mlx5_mig_state) |
| 5524 | { |
| 5525 | switch (mlx5_mig_state) { |
| 5526 | case MLX5_QP_PM_ARMED: return IB_MIG_ARMED; |
| 5527 | case MLX5_QP_PM_REARM: return IB_MIG_REARM; |
| 5528 | case MLX5_QP_PM_MIGRATED: return IB_MIG_MIGRATED; |
| 5529 | default: return -1; |
| 5530 | } |
| 5531 | } |
| 5532 | |
| 5533 | static int to_ib_qp_access_flags(int mlx5_flags) |
| 5534 | { |
| 5535 | int ib_flags = 0; |
| 5536 | |
| 5537 | if (mlx5_flags & MLX5_QP_BIT_RRE) |
| 5538 | ib_flags |= IB_ACCESS_REMOTE_READ; |
| 5539 | if (mlx5_flags & MLX5_QP_BIT_RWE) |
| 5540 | ib_flags |= IB_ACCESS_REMOTE_WRITE; |
| 5541 | if (mlx5_flags & MLX5_QP_BIT_RAE) |
| 5542 | ib_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 5543 | |
| 5544 | return ib_flags; |
| 5545 | } |
| 5546 | |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5547 | static void to_rdma_ah_attr(struct mlx5_ib_dev *ibdev, |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5548 | struct rdma_ah_attr *ah_attr, |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5549 | struct mlx5_qp_path *path) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5550 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5551 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5552 | memset(ah_attr, 0, sizeof(*ah_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5553 | |
Jason Gunthorpe | e7996a9 | 2018-01-29 13:26:40 -0700 | [diff] [blame] | 5554 | if (!path->port || path->port > ibdev->num_ports) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5555 | return; |
| 5556 | |
Leon Romanovsky | ae59c3f | 2018-01-12 07:58:39 +0200 | [diff] [blame] | 5557 | ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, path->port); |
| 5558 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5559 | rdma_ah_set_port_num(ah_attr, path->port); |
| 5560 | rdma_ah_set_sl(ah_attr, path->dci_cfi_prio_sl & 0xf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5561 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5562 | rdma_ah_set_dlid(ah_attr, be16_to_cpu(path->rlid)); |
| 5563 | rdma_ah_set_path_bits(ah_attr, path->grh_mlid & 0x7f); |
| 5564 | rdma_ah_set_static_rate(ah_attr, |
| 5565 | path->static_rate ? path->static_rate - 5 : 0); |
| 5566 | if (path->grh_mlid & (1 << 7)) { |
| 5567 | u32 tc_fl = be32_to_cpu(path->tclass_flowlabel); |
| 5568 | |
| 5569 | rdma_ah_set_grh(ah_attr, NULL, |
| 5570 | tc_fl & 0xfffff, |
| 5571 | path->mgid_index, |
| 5572 | path->hop_limit, |
| 5573 | (tc_fl >> 20) & 0xff); |
| 5574 | rdma_ah_set_dgid_raw(ah_attr, path->rgid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5575 | } |
| 5576 | } |
| 5577 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5578 | static int query_raw_packet_qp_sq_state(struct mlx5_ib_dev *dev, |
| 5579 | struct mlx5_ib_sq *sq, |
| 5580 | u8 *sq_state) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5581 | { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5582 | int err; |
| 5583 | |
Eran Ben Elisha | 2816077 | 2017-12-26 15:17:05 +0200 | [diff] [blame] | 5584 | 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] | 5585 | if (err) |
| 5586 | goto out; |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5587 | sq->state = *sq_state; |
| 5588 | |
| 5589 | out: |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5590 | return err; |
| 5591 | } |
| 5592 | |
| 5593 | static int query_raw_packet_qp_rq_state(struct mlx5_ib_dev *dev, |
| 5594 | struct mlx5_ib_rq *rq, |
| 5595 | u8 *rq_state) |
| 5596 | { |
| 5597 | void *out; |
| 5598 | void *rqc; |
| 5599 | int inlen; |
| 5600 | int err; |
| 5601 | |
| 5602 | inlen = MLX5_ST_SZ_BYTES(query_rq_out); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5603 | out = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5604 | if (!out) |
| 5605 | return -ENOMEM; |
| 5606 | |
| 5607 | err = mlx5_core_query_rq(dev->mdev, rq->base.mqp.qpn, out); |
| 5608 | if (err) |
| 5609 | goto out; |
| 5610 | |
| 5611 | rqc = MLX5_ADDR_OF(query_rq_out, out, rq_context); |
| 5612 | *rq_state = MLX5_GET(rqc, rqc, state); |
| 5613 | rq->state = *rq_state; |
| 5614 | |
| 5615 | out: |
| 5616 | kvfree(out); |
| 5617 | return err; |
| 5618 | } |
| 5619 | |
| 5620 | static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, |
| 5621 | struct mlx5_ib_qp *qp, u8 *qp_state) |
| 5622 | { |
| 5623 | static const u8 sqrq_trans[MLX5_RQ_NUM_STATE][MLX5_SQ_NUM_STATE] = { |
| 5624 | [MLX5_RQC_STATE_RST] = { |
| 5625 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 5626 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 5627 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE_BAD, |
| 5628 | [MLX5_SQ_STATE_NA] = IB_QPS_RESET, |
| 5629 | }, |
| 5630 | [MLX5_RQC_STATE_RDY] = { |
| 5631 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 5632 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 5633 | [MLX5_SQC_STATE_ERR] = IB_QPS_SQE, |
| 5634 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE, |
| 5635 | }, |
| 5636 | [MLX5_RQC_STATE_ERR] = { |
| 5637 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 5638 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 5639 | [MLX5_SQC_STATE_ERR] = IB_QPS_ERR, |
| 5640 | [MLX5_SQ_STATE_NA] = IB_QPS_ERR, |
| 5641 | }, |
| 5642 | [MLX5_RQ_STATE_NA] = { |
| 5643 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 5644 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 5645 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE, |
| 5646 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE_BAD, |
| 5647 | }, |
| 5648 | }; |
| 5649 | |
| 5650 | *qp_state = sqrq_trans[rq_state][sq_state]; |
| 5651 | |
| 5652 | if (*qp_state == MLX5_QP_STATE_BAD) { |
| 5653 | WARN(1, "Buggy Raw Packet QP state, SQ 0x%x state: 0x%x, RQ 0x%x state: 0x%x", |
| 5654 | qp->raw_packet_qp.sq.base.mqp.qpn, sq_state, |
| 5655 | qp->raw_packet_qp.rq.base.mqp.qpn, rq_state); |
| 5656 | return -EINVAL; |
| 5657 | } |
| 5658 | |
| 5659 | if (*qp_state == MLX5_QP_STATE) |
| 5660 | *qp_state = qp->state; |
| 5661 | |
| 5662 | return 0; |
| 5663 | } |
| 5664 | |
| 5665 | static int query_raw_packet_qp_state(struct mlx5_ib_dev *dev, |
| 5666 | struct mlx5_ib_qp *qp, |
| 5667 | u8 *raw_packet_qp_state) |
| 5668 | { |
| 5669 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 5670 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 5671 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 5672 | int err; |
| 5673 | u8 sq_state = MLX5_SQ_STATE_NA; |
| 5674 | u8 rq_state = MLX5_RQ_STATE_NA; |
| 5675 | |
| 5676 | if (qp->sq.wqe_cnt) { |
| 5677 | err = query_raw_packet_qp_sq_state(dev, sq, &sq_state); |
| 5678 | if (err) |
| 5679 | return err; |
| 5680 | } |
| 5681 | |
| 5682 | if (qp->rq.wqe_cnt) { |
| 5683 | err = query_raw_packet_qp_rq_state(dev, rq, &rq_state); |
| 5684 | if (err) |
| 5685 | return err; |
| 5686 | } |
| 5687 | |
| 5688 | return sqrq_state_to_qp_state(sq_state, rq_state, qp, |
| 5689 | raw_packet_qp_state); |
| 5690 | } |
| 5691 | |
| 5692 | static int query_qp_attr(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 5693 | struct ib_qp_attr *qp_attr) |
| 5694 | { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5695 | int outlen = MLX5_ST_SZ_BYTES(query_qp_out); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5696 | struct mlx5_qp_context *context; |
| 5697 | int mlx5_state; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5698 | u32 *outb; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5699 | int err = 0; |
| 5700 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5701 | outb = kzalloc(outlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5702 | if (!outb) |
| 5703 | return -ENOMEM; |
| 5704 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5705 | 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] | 5706 | if (err) |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5707 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5708 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5709 | /* FIXME: use MLX5_GET rather than mlx5_qp_context manual struct */ |
| 5710 | context = (struct mlx5_qp_context *)MLX5_ADDR_OF(query_qp_out, outb, qpc); |
| 5711 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5712 | mlx5_state = be32_to_cpu(context->flags) >> 28; |
| 5713 | |
| 5714 | qp->state = to_ib_qp_state(mlx5_state); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5715 | qp_attr->path_mtu = context->mtu_msgmax >> 5; |
| 5716 | qp_attr->path_mig_state = |
| 5717 | to_ib_mig_state((be32_to_cpu(context->flags) >> 11) & 0x3); |
| 5718 | qp_attr->qkey = be32_to_cpu(context->qkey); |
| 5719 | qp_attr->rq_psn = be32_to_cpu(context->rnr_nextrecvpsn) & 0xffffff; |
| 5720 | qp_attr->sq_psn = be32_to_cpu(context->next_send_psn) & 0xffffff; |
| 5721 | qp_attr->dest_qp_num = be32_to_cpu(context->log_pg_sz_remote_qpn) & 0xffffff; |
| 5722 | qp_attr->qp_access_flags = |
| 5723 | to_ib_qp_access_flags(be32_to_cpu(context->params2)); |
| 5724 | |
| 5725 | if (qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC) { |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5726 | to_rdma_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path); |
| 5727 | to_rdma_ah_attr(dev, &qp_attr->alt_ah_attr, &context->alt_path); |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 5728 | qp_attr->alt_pkey_index = |
| 5729 | be16_to_cpu(context->alt_path.pkey_index); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5730 | qp_attr->alt_port_num = |
| 5731 | rdma_ah_get_port_num(&qp_attr->alt_ah_attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5732 | } |
| 5733 | |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 5734 | qp_attr->pkey_index = be16_to_cpu(context->pri_path.pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5735 | qp_attr->port_num = context->pri_path.port; |
| 5736 | |
| 5737 | /* qp_attr->en_sqd_async_notify is only applicable in modify qp */ |
| 5738 | qp_attr->sq_draining = mlx5_state == MLX5_QP_STATE_SQ_DRAINING; |
| 5739 | |
| 5740 | qp_attr->max_rd_atomic = 1 << ((be32_to_cpu(context->params1) >> 21) & 0x7); |
| 5741 | |
| 5742 | qp_attr->max_dest_rd_atomic = |
| 5743 | 1 << ((be32_to_cpu(context->params2) >> 21) & 0x7); |
| 5744 | qp_attr->min_rnr_timer = |
| 5745 | (be32_to_cpu(context->rnr_nextrecvpsn) >> 24) & 0x1f; |
| 5746 | qp_attr->timeout = context->pri_path.ackto_lt >> 3; |
| 5747 | qp_attr->retry_cnt = (be32_to_cpu(context->params1) >> 16) & 0x7; |
| 5748 | qp_attr->rnr_retry = (be32_to_cpu(context->params1) >> 13) & 0x7; |
| 5749 | qp_attr->alt_timeout = context->alt_path.ackto_lt >> 3; |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5750 | |
| 5751 | out: |
| 5752 | kfree(outb); |
| 5753 | return err; |
| 5754 | } |
| 5755 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5756 | static int mlx5_ib_dct_query_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *mqp, |
| 5757 | struct ib_qp_attr *qp_attr, int qp_attr_mask, |
| 5758 | struct ib_qp_init_attr *qp_init_attr) |
| 5759 | { |
| 5760 | struct mlx5_core_dct *dct = &mqp->dct.mdct; |
| 5761 | u32 *out; |
| 5762 | u32 access_flags = 0; |
| 5763 | int outlen = MLX5_ST_SZ_BYTES(query_dct_out); |
| 5764 | void *dctc; |
| 5765 | int err; |
| 5766 | int supported_mask = IB_QP_STATE | |
| 5767 | IB_QP_ACCESS_FLAGS | |
| 5768 | IB_QP_PORT | |
| 5769 | IB_QP_MIN_RNR_TIMER | |
| 5770 | IB_QP_AV | |
| 5771 | IB_QP_PATH_MTU | |
| 5772 | IB_QP_PKEY_INDEX; |
| 5773 | |
| 5774 | if (qp_attr_mask & ~supported_mask) |
| 5775 | return -EINVAL; |
| 5776 | if (mqp->state != IB_QPS_RTR) |
| 5777 | return -EINVAL; |
| 5778 | |
| 5779 | out = kzalloc(outlen, GFP_KERNEL); |
| 5780 | if (!out) |
| 5781 | return -ENOMEM; |
| 5782 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5783 | err = mlx5_core_dct_query(dev, dct, out, outlen); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5784 | if (err) |
| 5785 | goto out; |
| 5786 | |
| 5787 | dctc = MLX5_ADDR_OF(query_dct_out, out, dct_context_entry); |
| 5788 | |
| 5789 | if (qp_attr_mask & IB_QP_STATE) |
| 5790 | qp_attr->qp_state = IB_QPS_RTR; |
| 5791 | |
| 5792 | if (qp_attr_mask & IB_QP_ACCESS_FLAGS) { |
| 5793 | if (MLX5_GET(dctc, dctc, rre)) |
| 5794 | access_flags |= IB_ACCESS_REMOTE_READ; |
| 5795 | if (MLX5_GET(dctc, dctc, rwe)) |
| 5796 | access_flags |= IB_ACCESS_REMOTE_WRITE; |
| 5797 | if (MLX5_GET(dctc, dctc, rae)) |
| 5798 | access_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 5799 | qp_attr->qp_access_flags = access_flags; |
| 5800 | } |
| 5801 | |
| 5802 | if (qp_attr_mask & IB_QP_PORT) |
| 5803 | qp_attr->port_num = MLX5_GET(dctc, dctc, port); |
| 5804 | if (qp_attr_mask & IB_QP_MIN_RNR_TIMER) |
| 5805 | qp_attr->min_rnr_timer = MLX5_GET(dctc, dctc, min_rnr_nak); |
| 5806 | if (qp_attr_mask & IB_QP_AV) { |
| 5807 | qp_attr->ah_attr.grh.traffic_class = MLX5_GET(dctc, dctc, tclass); |
| 5808 | qp_attr->ah_attr.grh.flow_label = MLX5_GET(dctc, dctc, flow_label); |
| 5809 | qp_attr->ah_attr.grh.sgid_index = MLX5_GET(dctc, dctc, my_addr_index); |
| 5810 | qp_attr->ah_attr.grh.hop_limit = MLX5_GET(dctc, dctc, hop_limit); |
| 5811 | } |
| 5812 | if (qp_attr_mask & IB_QP_PATH_MTU) |
| 5813 | qp_attr->path_mtu = MLX5_GET(dctc, dctc, mtu); |
| 5814 | if (qp_attr_mask & IB_QP_PKEY_INDEX) |
| 5815 | qp_attr->pkey_index = MLX5_GET(dctc, dctc, pkey_index); |
| 5816 | out: |
| 5817 | kfree(out); |
| 5818 | return err; |
| 5819 | } |
| 5820 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5821 | int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, |
| 5822 | int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr) |
| 5823 | { |
| 5824 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 5825 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 5826 | int err = 0; |
| 5827 | u8 raw_packet_qp_state; |
| 5828 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 5829 | if (ibqp->rwq_ind_tbl) |
| 5830 | return -ENOSYS; |
| 5831 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5832 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5833 | return mlx5_ib_gsi_query_qp(ibqp, qp_attr, qp_attr_mask, |
| 5834 | qp_init_attr); |
| 5835 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 5836 | /* Not all of output fields are applicable, make sure to zero them */ |
| 5837 | memset(qp_init_attr, 0, sizeof(*qp_init_attr)); |
| 5838 | memset(qp_attr, 0, sizeof(*qp_attr)); |
| 5839 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5840 | if (unlikely(qp->qp_sub_type == MLX5_IB_QPT_DCT)) |
| 5841 | return mlx5_ib_dct_query_qp(dev, qp, qp_attr, |
| 5842 | qp_attr_mask, qp_init_attr); |
| 5843 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5844 | mutex_lock(&qp->mutex); |
| 5845 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 5846 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 5847 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5848 | err = query_raw_packet_qp_state(dev, qp, &raw_packet_qp_state); |
| 5849 | if (err) |
| 5850 | goto out; |
| 5851 | qp->state = raw_packet_qp_state; |
| 5852 | qp_attr->port_num = 1; |
| 5853 | } else { |
| 5854 | err = query_qp_attr(dev, qp, qp_attr); |
| 5855 | if (err) |
| 5856 | goto out; |
| 5857 | } |
| 5858 | |
| 5859 | qp_attr->qp_state = qp->state; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5860 | qp_attr->cur_qp_state = qp_attr->qp_state; |
| 5861 | qp_attr->cap.max_recv_wr = qp->rq.wqe_cnt; |
| 5862 | qp_attr->cap.max_recv_sge = qp->rq.max_gs; |
| 5863 | |
| 5864 | if (!ibqp->uobject) { |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5865 | qp_attr->cap.max_send_wr = qp->sq.max_post; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5866 | qp_attr->cap.max_send_sge = qp->sq.max_gs; |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5867 | qp_init_attr->qp_context = ibqp->qp_context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5868 | } else { |
| 5869 | qp_attr->cap.max_send_wr = 0; |
| 5870 | qp_attr->cap.max_send_sge = 0; |
| 5871 | } |
| 5872 | |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5873 | qp_init_attr->qp_type = ibqp->qp_type; |
| 5874 | qp_init_attr->recv_cq = ibqp->recv_cq; |
| 5875 | qp_init_attr->send_cq = ibqp->send_cq; |
| 5876 | qp_init_attr->srq = ibqp->srq; |
| 5877 | qp_attr->cap.max_inline_data = qp->max_inline_data; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5878 | |
| 5879 | qp_init_attr->cap = qp_attr->cap; |
| 5880 | |
Leon Romanovsky | a8f3ea6 | 2020-04-27 18:46:17 +0300 | [diff] [blame^] | 5881 | qp_init_attr->create_flags = qp->flags; |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 5882 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5883 | qp_init_attr->sq_sig_type = qp->sq_signal_bits & MLX5_WQE_CTRL_CQ_UPDATE ? |
| 5884 | IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR; |
| 5885 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5886 | out: |
| 5887 | mutex_unlock(&qp->mutex); |
| 5888 | return err; |
| 5889 | } |
| 5890 | |
| 5891 | struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev, |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 5892 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5893 | { |
| 5894 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5895 | struct mlx5_ib_xrcd *xrcd; |
| 5896 | int err; |
| 5897 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 5898 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5899 | return ERR_PTR(-ENOSYS); |
| 5900 | |
| 5901 | xrcd = kmalloc(sizeof(*xrcd), GFP_KERNEL); |
| 5902 | if (!xrcd) |
| 5903 | return ERR_PTR(-ENOMEM); |
| 5904 | |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 5905 | err = mlx5_cmd_xrcd_alloc(dev->mdev, &xrcd->xrcdn, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5906 | if (err) { |
| 5907 | kfree(xrcd); |
| 5908 | return ERR_PTR(-ENOMEM); |
| 5909 | } |
| 5910 | |
| 5911 | return &xrcd->ibxrcd; |
| 5912 | } |
| 5913 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5914 | int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5915 | { |
| 5916 | struct mlx5_ib_dev *dev = to_mdev(xrcd->device); |
| 5917 | u32 xrcdn = to_mxrcd(xrcd)->xrcdn; |
| 5918 | int err; |
| 5919 | |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 5920 | err = mlx5_cmd_xrcd_dealloc(dev->mdev, xrcdn, 0); |
Leon Romanovsky | b081808 | 2018-01-28 11:25:30 +0200 | [diff] [blame] | 5921 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5922 | mlx5_ib_warn(dev, "failed to dealloc xrcdn 0x%x\n", xrcdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5923 | |
| 5924 | kfree(xrcd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5925 | return 0; |
| 5926 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5927 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5928 | static void mlx5_ib_wq_event(struct mlx5_core_qp *core_qp, int type) |
| 5929 | { |
| 5930 | struct mlx5_ib_rwq *rwq = to_mibrwq(core_qp); |
| 5931 | struct mlx5_ib_dev *dev = to_mdev(rwq->ibwq.device); |
| 5932 | struct ib_event event; |
| 5933 | |
| 5934 | if (rwq->ibwq.event_handler) { |
| 5935 | event.device = rwq->ibwq.device; |
| 5936 | event.element.wq = &rwq->ibwq; |
| 5937 | switch (type) { |
| 5938 | case MLX5_EVENT_TYPE_WQ_CATAS_ERROR: |
| 5939 | event.event = IB_EVENT_WQ_FATAL; |
| 5940 | break; |
| 5941 | default: |
| 5942 | mlx5_ib_warn(dev, "Unexpected event type %d on WQ %06x\n", type, core_qp->qpn); |
| 5943 | return; |
| 5944 | } |
| 5945 | |
| 5946 | rwq->ibwq.event_handler(&event, rwq->ibwq.wq_context); |
| 5947 | } |
| 5948 | } |
| 5949 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5950 | static int set_delay_drop(struct mlx5_ib_dev *dev) |
| 5951 | { |
| 5952 | int err = 0; |
| 5953 | |
| 5954 | mutex_lock(&dev->delay_drop.lock); |
| 5955 | if (dev->delay_drop.activate) |
| 5956 | goto out; |
| 5957 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5958 | err = mlx5_core_set_delay_drop(dev, dev->delay_drop.timeout); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5959 | if (err) |
| 5960 | goto out; |
| 5961 | |
| 5962 | dev->delay_drop.activate = true; |
| 5963 | out: |
| 5964 | mutex_unlock(&dev->delay_drop.lock); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5965 | |
| 5966 | if (!err) |
| 5967 | atomic_inc(&dev->delay_drop.rqs_cnt); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5968 | return err; |
| 5969 | } |
| 5970 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5971 | static int create_rq(struct mlx5_ib_rwq *rwq, struct ib_pd *pd, |
| 5972 | struct ib_wq_init_attr *init_attr) |
| 5973 | { |
| 5974 | struct mlx5_ib_dev *dev; |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 5975 | int has_net_offloads; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5976 | __be64 *rq_pas0; |
| 5977 | void *in; |
| 5978 | void *rqc; |
| 5979 | void *wq; |
| 5980 | int inlen; |
| 5981 | int err; |
| 5982 | |
| 5983 | dev = to_mdev(pd->device); |
| 5984 | |
| 5985 | 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] | 5986 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5987 | if (!in) |
| 5988 | return -ENOMEM; |
| 5989 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 5990 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5991 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
| 5992 | MLX5_SET(rqc, rqc, mem_rq_type, |
| 5993 | MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 5994 | MLX5_SET(rqc, rqc, user_index, rwq->user_index); |
| 5995 | MLX5_SET(rqc, rqc, cqn, to_mcq(init_attr->cq)->mcq.cqn); |
| 5996 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 5997 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 5998 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5999 | MLX5_SET(wq, wq, wq_type, |
| 6000 | rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ ? |
| 6001 | MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ : MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 6002 | if (init_attr->create_flags & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 6003 | if (!MLX5_CAP_GEN(dev->mdev, end_pad)) { |
| 6004 | mlx5_ib_dbg(dev, "Scatter end padding is not supported\n"); |
| 6005 | err = -EOPNOTSUPP; |
| 6006 | goto out; |
| 6007 | } else { |
| 6008 | MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN); |
| 6009 | } |
| 6010 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6011 | MLX5_SET(wq, wq, log_wq_stride, rwq->log_rq_stride); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6012 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ) { |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 6013 | /* |
| 6014 | * In Firmware number of strides in each WQE is: |
| 6015 | * "512 * 2^single_wqe_log_num_of_strides" |
| 6016 | * Values 3 to 8 are accepted as 10 to 15, 9 to 18 are |
| 6017 | * accepted as 0 to 9 |
| 6018 | */ |
| 6019 | static const u8 fw_map[] = { 10, 11, 12, 13, 14, 15, 0, 1, |
| 6020 | 2, 3, 4, 5, 6, 7, 8, 9 }; |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6021 | MLX5_SET(wq, wq, two_byte_shift_en, rwq->two_byte_shift_en); |
| 6022 | MLX5_SET(wq, wq, log_wqe_stride_size, |
| 6023 | rwq->single_stride_log_num_of_bytes - |
| 6024 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES); |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 6025 | MLX5_SET(wq, wq, log_wqe_num_of_strides, |
| 6026 | fw_map[rwq->log_num_strides - |
| 6027 | MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES]); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6028 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6029 | MLX5_SET(wq, wq, log_wq_sz, rwq->log_rq_size); |
| 6030 | MLX5_SET(wq, wq, pd, to_mpd(pd)->pdn); |
| 6031 | MLX5_SET(wq, wq, page_offset, rwq->rq_page_offset); |
| 6032 | MLX5_SET(wq, wq, log_wq_pg_sz, rwq->log_page_size); |
| 6033 | MLX5_SET(wq, wq, wq_signature, rwq->wq_sig); |
| 6034 | MLX5_SET64(wq, wq, dbr_addr, rwq->db.dma); |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 6035 | has_net_offloads = MLX5_CAP_GEN(dev->mdev, eth_net_offloads); |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6036 | if (init_attr->create_flags & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 6037 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6038 | mlx5_ib_dbg(dev, "VLAN offloads are not supported\n"); |
| 6039 | err = -EOPNOTSUPP; |
| 6040 | goto out; |
| 6041 | } |
| 6042 | } else { |
| 6043 | MLX5_SET(rqc, rqc, vsd, 1); |
| 6044 | } |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 6045 | if (init_attr->create_flags & IB_WQ_FLAGS_SCATTER_FCS) { |
| 6046 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, scatter_fcs))) { |
| 6047 | mlx5_ib_dbg(dev, "Scatter FCS is not supported\n"); |
| 6048 | err = -EOPNOTSUPP; |
| 6049 | goto out; |
| 6050 | } |
| 6051 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 6052 | } |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6053 | if (init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 6054 | if (!(dev->ib_dev.attrs.raw_packet_caps & |
| 6055 | IB_RAW_PACKET_CAP_DELAY_DROP)) { |
| 6056 | mlx5_ib_dbg(dev, "Delay drop is not supported\n"); |
| 6057 | err = -EOPNOTSUPP; |
| 6058 | goto out; |
| 6059 | } |
| 6060 | MLX5_SET(rqc, rqc, delay_drop_en, 1); |
| 6061 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6062 | rq_pas0 = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 6063 | 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] | 6064 | err = mlx5_core_create_rq_tracked(dev, in, inlen, &rwq->core_qp); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6065 | if (!err && init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 6066 | err = set_delay_drop(dev); |
| 6067 | if (err) { |
| 6068 | mlx5_ib_warn(dev, "Failed to enable delay drop err=%d\n", |
| 6069 | err); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 6070 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6071 | } else { |
| 6072 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_DELAY_DROP; |
| 6073 | } |
| 6074 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6075 | out: |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6076 | kvfree(in); |
| 6077 | return err; |
| 6078 | } |
| 6079 | |
| 6080 | static int set_user_rq_size(struct mlx5_ib_dev *dev, |
| 6081 | struct ib_wq_init_attr *wq_init_attr, |
| 6082 | struct mlx5_ib_create_wq *ucmd, |
| 6083 | struct mlx5_ib_rwq *rwq) |
| 6084 | { |
| 6085 | /* Sanity check RQ size before proceeding */ |
| 6086 | if (wq_init_attr->max_wr > (1 << MLX5_CAP_GEN(dev->mdev, log_max_wq_sz))) |
| 6087 | return -EINVAL; |
| 6088 | |
| 6089 | if (!ucmd->rq_wqe_count) |
| 6090 | return -EINVAL; |
| 6091 | |
| 6092 | rwq->wqe_count = ucmd->rq_wqe_count; |
| 6093 | rwq->wqe_shift = ucmd->rq_wqe_shift; |
Leon Romanovsky | 0dfe452 | 2018-08-01 14:25:41 -0700 | [diff] [blame] | 6094 | if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, &rwq->buf_size)) |
| 6095 | return -EINVAL; |
| 6096 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6097 | rwq->log_rq_stride = rwq->wqe_shift; |
| 6098 | rwq->log_rq_size = ilog2(rwq->wqe_count); |
| 6099 | return 0; |
| 6100 | } |
| 6101 | |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 6102 | static bool log_of_strides_valid(struct mlx5_ib_dev *dev, u32 log_num_strides) |
| 6103 | { |
| 6104 | if ((log_num_strides > MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES) || |
| 6105 | (log_num_strides < MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES)) |
| 6106 | return false; |
| 6107 | |
| 6108 | if (!MLX5_CAP_GEN(dev->mdev, ext_stride_num_range) && |
| 6109 | (log_num_strides < MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES)) |
| 6110 | return false; |
| 6111 | |
| 6112 | return true; |
| 6113 | } |
| 6114 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6115 | static int prepare_user_rq(struct ib_pd *pd, |
| 6116 | struct ib_wq_init_attr *init_attr, |
| 6117 | struct ib_udata *udata, |
| 6118 | struct mlx5_ib_rwq *rwq) |
| 6119 | { |
| 6120 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
| 6121 | struct mlx5_ib_create_wq ucmd = {}; |
| 6122 | int err; |
| 6123 | size_t required_cmd_sz; |
| 6124 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6125 | required_cmd_sz = offsetof(typeof(ucmd), single_stride_log_num_of_bytes) |
| 6126 | + sizeof(ucmd.single_stride_log_num_of_bytes); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6127 | if (udata->inlen < required_cmd_sz) { |
| 6128 | mlx5_ib_dbg(dev, "invalid inlen\n"); |
| 6129 | return -EINVAL; |
| 6130 | } |
| 6131 | |
| 6132 | if (udata->inlen > sizeof(ucmd) && |
| 6133 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 6134 | udata->inlen - sizeof(ucmd))) { |
| 6135 | mlx5_ib_dbg(dev, "inlen is not supported\n"); |
| 6136 | return -EOPNOTSUPP; |
| 6137 | } |
| 6138 | |
| 6139 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) { |
| 6140 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 6141 | return -EFAULT; |
| 6142 | } |
| 6143 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6144 | if (ucmd.comp_mask & (~MLX5_IB_CREATE_WQ_STRIDING_RQ)) { |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6145 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 6146 | return -EOPNOTSUPP; |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6147 | } else if (ucmd.comp_mask & MLX5_IB_CREATE_WQ_STRIDING_RQ) { |
| 6148 | if (!MLX5_CAP_GEN(dev->mdev, striding_rq)) { |
| 6149 | mlx5_ib_dbg(dev, "Striding RQ is not supported\n"); |
| 6150 | return -EOPNOTSUPP; |
| 6151 | } |
| 6152 | if ((ucmd.single_stride_log_num_of_bytes < |
| 6153 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES) || |
| 6154 | (ucmd.single_stride_log_num_of_bytes > |
| 6155 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES)) { |
| 6156 | mlx5_ib_dbg(dev, "Invalid log stride size (%u. Range is %u - %u)\n", |
| 6157 | ucmd.single_stride_log_num_of_bytes, |
| 6158 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES, |
| 6159 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES); |
| 6160 | return -EINVAL; |
| 6161 | } |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 6162 | if (!log_of_strides_valid(dev, |
| 6163 | ucmd.single_wqe_log_num_of_strides)) { |
| 6164 | mlx5_ib_dbg( |
| 6165 | dev, |
| 6166 | "Invalid log num strides (%u. Range is %u - %u)\n", |
| 6167 | ucmd.single_wqe_log_num_of_strides, |
| 6168 | MLX5_CAP_GEN(dev->mdev, ext_stride_num_range) ? |
| 6169 | MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES : |
| 6170 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES, |
| 6171 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6172 | return -EINVAL; |
| 6173 | } |
| 6174 | rwq->single_stride_log_num_of_bytes = |
| 6175 | ucmd.single_stride_log_num_of_bytes; |
| 6176 | rwq->log_num_strides = ucmd.single_wqe_log_num_of_strides; |
| 6177 | rwq->two_byte_shift_en = !!ucmd.two_byte_shift_en; |
| 6178 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_STRIDING_RQ; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6179 | } |
| 6180 | |
| 6181 | err = set_user_rq_size(dev, init_attr, &ucmd, rwq); |
| 6182 | if (err) { |
| 6183 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 6184 | return err; |
| 6185 | } |
| 6186 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 6187 | err = create_user_rq(dev, pd, udata, rwq, &ucmd); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6188 | if (err) { |
| 6189 | mlx5_ib_dbg(dev, "err %d\n", err); |
Gal Pressman | 645ba59 | 2018-10-08 19:44:03 +0300 | [diff] [blame] | 6190 | return err; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6191 | } |
| 6192 | |
| 6193 | rwq->user_index = ucmd.user_index; |
| 6194 | return 0; |
| 6195 | } |
| 6196 | |
| 6197 | struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd, |
| 6198 | struct ib_wq_init_attr *init_attr, |
| 6199 | struct ib_udata *udata) |
| 6200 | { |
| 6201 | struct mlx5_ib_dev *dev; |
| 6202 | struct mlx5_ib_rwq *rwq; |
| 6203 | struct mlx5_ib_create_wq_resp resp = {}; |
| 6204 | size_t min_resp_len; |
| 6205 | int err; |
| 6206 | |
| 6207 | if (!udata) |
| 6208 | return ERR_PTR(-ENOSYS); |
| 6209 | |
| 6210 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 6211 | if (udata->outlen && udata->outlen < min_resp_len) |
| 6212 | return ERR_PTR(-EINVAL); |
| 6213 | |
Maor Gottlieb | ba80013 | 2020-03-22 14:49:06 +0200 | [diff] [blame] | 6214 | if (!capable(CAP_SYS_RAWIO) && |
| 6215 | init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) |
| 6216 | return ERR_PTR(-EPERM); |
| 6217 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6218 | dev = to_mdev(pd->device); |
| 6219 | switch (init_attr->wq_type) { |
| 6220 | case IB_WQT_RQ: |
| 6221 | rwq = kzalloc(sizeof(*rwq), GFP_KERNEL); |
| 6222 | if (!rwq) |
| 6223 | return ERR_PTR(-ENOMEM); |
| 6224 | err = prepare_user_rq(pd, init_attr, udata, rwq); |
| 6225 | if (err) |
| 6226 | goto err; |
| 6227 | err = create_rq(rwq, pd, init_attr); |
| 6228 | if (err) |
| 6229 | goto err_user_rq; |
| 6230 | break; |
| 6231 | default: |
| 6232 | mlx5_ib_dbg(dev, "unsupported wq type %d\n", |
| 6233 | init_attr->wq_type); |
| 6234 | return ERR_PTR(-EINVAL); |
| 6235 | } |
| 6236 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 6237 | rwq->ibwq.wq_num = rwq->core_qp.qpn; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6238 | rwq->ibwq.state = IB_WQS_RESET; |
| 6239 | if (udata->outlen) { |
| 6240 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 6241 | sizeof(resp.response_length); |
| 6242 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 6243 | if (err) |
| 6244 | goto err_copy; |
| 6245 | } |
| 6246 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 6247 | rwq->core_qp.event = mlx5_ib_wq_event; |
| 6248 | rwq->ibwq.event_handler = init_attr->event_handler; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6249 | return &rwq->ibwq; |
| 6250 | |
| 6251 | err_copy: |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 6252 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6253 | err_user_rq: |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 6254 | destroy_user_rq(dev, pd, rwq, udata); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6255 | err: |
| 6256 | kfree(rwq); |
| 6257 | return ERR_PTR(err); |
| 6258 | } |
| 6259 | |
Leon Romanovsky | a49b1dc | 2019-06-12 15:27:41 +0300 | [diff] [blame] | 6260 | 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] | 6261 | { |
| 6262 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 6263 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 6264 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 6265 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 6266 | destroy_user_rq(dev, wq->pd, rwq, udata); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6267 | kfree(rwq); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6268 | } |
| 6269 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6270 | struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device, |
| 6271 | struct ib_rwq_ind_table_init_attr *init_attr, |
| 6272 | struct ib_udata *udata) |
| 6273 | { |
| 6274 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 6275 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl; |
| 6276 | int sz = 1 << init_attr->log_ind_tbl_size; |
| 6277 | struct mlx5_ib_create_rwq_ind_tbl_resp resp = {}; |
| 6278 | size_t min_resp_len; |
| 6279 | int inlen; |
| 6280 | int err; |
| 6281 | int i; |
| 6282 | u32 *in; |
| 6283 | void *rqtc; |
| 6284 | |
| 6285 | if (udata->inlen > 0 && |
| 6286 | !ib_is_udata_cleared(udata, 0, |
| 6287 | udata->inlen)) |
| 6288 | return ERR_PTR(-EOPNOTSUPP); |
| 6289 | |
Maor Gottlieb | efd7f40 | 2016-10-27 16:36:40 +0300 | [diff] [blame] | 6290 | if (init_attr->log_ind_tbl_size > |
| 6291 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)) { |
| 6292 | mlx5_ib_dbg(dev, "log_ind_tbl_size = %d is bigger than supported = %d\n", |
| 6293 | init_attr->log_ind_tbl_size, |
| 6294 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)); |
| 6295 | return ERR_PTR(-EINVAL); |
| 6296 | } |
| 6297 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6298 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 6299 | if (udata->outlen && udata->outlen < min_resp_len) |
| 6300 | return ERR_PTR(-EINVAL); |
| 6301 | |
| 6302 | rwq_ind_tbl = kzalloc(sizeof(*rwq_ind_tbl), GFP_KERNEL); |
| 6303 | if (!rwq_ind_tbl) |
| 6304 | return ERR_PTR(-ENOMEM); |
| 6305 | |
| 6306 | inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 6307 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6308 | if (!in) { |
| 6309 | err = -ENOMEM; |
| 6310 | goto err; |
| 6311 | } |
| 6312 | |
| 6313 | rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context); |
| 6314 | |
| 6315 | MLX5_SET(rqtc, rqtc, rqt_actual_size, sz); |
| 6316 | MLX5_SET(rqtc, rqtc, rqt_max_size, sz); |
| 6317 | |
| 6318 | for (i = 0; i < sz; i++) |
| 6319 | MLX5_SET(rqtc, rqtc, rq_num[i], init_attr->ind_tbl[i]->wq_num); |
| 6320 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 6321 | rwq_ind_tbl->uid = to_mpd(init_attr->ind_tbl[0]->pd)->uid; |
| 6322 | MLX5_SET(create_rqt_in, in, uid, rwq_ind_tbl->uid); |
| 6323 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6324 | err = mlx5_core_create_rqt(dev->mdev, in, inlen, &rwq_ind_tbl->rqtn); |
| 6325 | kvfree(in); |
| 6326 | |
| 6327 | if (err) |
| 6328 | goto err; |
| 6329 | |
| 6330 | rwq_ind_tbl->ib_rwq_ind_tbl.ind_tbl_num = rwq_ind_tbl->rqtn; |
| 6331 | if (udata->outlen) { |
| 6332 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 6333 | sizeof(resp.response_length); |
| 6334 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 6335 | if (err) |
| 6336 | goto err_copy; |
| 6337 | } |
| 6338 | |
| 6339 | return &rwq_ind_tbl->ib_rwq_ind_tbl; |
| 6340 | |
| 6341 | err_copy: |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 6342 | 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] | 6343 | err: |
| 6344 | kfree(rwq_ind_tbl); |
| 6345 | return ERR_PTR(err); |
| 6346 | } |
| 6347 | |
| 6348 | int mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl) |
| 6349 | { |
| 6350 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl = to_mrwq_ind_table(ib_rwq_ind_tbl); |
| 6351 | struct mlx5_ib_dev *dev = to_mdev(ib_rwq_ind_tbl->device); |
| 6352 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 6353 | 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] | 6354 | |
| 6355 | kfree(rwq_ind_tbl); |
| 6356 | return 0; |
| 6357 | } |
| 6358 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6359 | int mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, |
| 6360 | u32 wq_attr_mask, struct ib_udata *udata) |
| 6361 | { |
| 6362 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 6363 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 6364 | struct mlx5_ib_modify_wq ucmd = {}; |
| 6365 | size_t required_cmd_sz; |
| 6366 | int curr_wq_state; |
| 6367 | int wq_state; |
| 6368 | int inlen; |
| 6369 | int err; |
| 6370 | void *rqc; |
| 6371 | void *in; |
| 6372 | |
| 6373 | required_cmd_sz = offsetof(typeof(ucmd), reserved) + sizeof(ucmd.reserved); |
| 6374 | if (udata->inlen < required_cmd_sz) |
| 6375 | return -EINVAL; |
| 6376 | |
| 6377 | if (udata->inlen > sizeof(ucmd) && |
| 6378 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 6379 | udata->inlen - sizeof(ucmd))) |
| 6380 | return -EOPNOTSUPP; |
| 6381 | |
| 6382 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) |
| 6383 | return -EFAULT; |
| 6384 | |
| 6385 | if (ucmd.comp_mask || ucmd.reserved) |
| 6386 | return -EOPNOTSUPP; |
| 6387 | |
| 6388 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 6389 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6390 | if (!in) |
| 6391 | return -ENOMEM; |
| 6392 | |
| 6393 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 6394 | |
| 6395 | curr_wq_state = (wq_attr_mask & IB_WQ_CUR_STATE) ? |
| 6396 | wq_attr->curr_wq_state : wq->state; |
| 6397 | wq_state = (wq_attr_mask & IB_WQ_STATE) ? |
| 6398 | wq_attr->wq_state : curr_wq_state; |
| 6399 | if (curr_wq_state == IB_WQS_ERR) |
| 6400 | curr_wq_state = MLX5_RQC_STATE_ERR; |
| 6401 | if (wq_state == IB_WQS_ERR) |
| 6402 | wq_state = MLX5_RQC_STATE_ERR; |
| 6403 | MLX5_SET(modify_rq_in, in, rq_state, curr_wq_state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 6404 | MLX5_SET(modify_rq_in, in, uid, to_mpd(wq->pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6405 | MLX5_SET(rqc, rqc, state, wq_state); |
| 6406 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6407 | if (wq_attr_mask & IB_WQ_FLAGS) { |
| 6408 | if (wq_attr->flags_mask & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
| 6409 | if (!(MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 6410 | MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
| 6411 | mlx5_ib_dbg(dev, "VLAN offloads are not " |
| 6412 | "supported\n"); |
| 6413 | err = -EOPNOTSUPP; |
| 6414 | goto out; |
| 6415 | } |
| 6416 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 6417 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD); |
| 6418 | MLX5_SET(rqc, rqc, vsd, |
| 6419 | (wq_attr->flags & IB_WQ_FLAGS_CVLAN_STRIPPING) ? 0 : 1); |
| 6420 | } |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 6421 | |
| 6422 | if (wq_attr->flags_mask & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 6423 | mlx5_ib_dbg(dev, "Modifying scatter end padding is not supported\n"); |
| 6424 | err = -EOPNOTSUPP; |
| 6425 | goto out; |
| 6426 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6427 | } |
| 6428 | |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6429 | if (curr_wq_state == IB_WQS_RESET && wq_state == IB_WQS_RDY) { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 6430 | u16 set_id; |
| 6431 | |
| 6432 | set_id = mlx5_ib_get_counters_id(dev, 0); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6433 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 6434 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 6435 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 6436 | MLX5_SET(rqc, rqc, counter_set_id, set_id); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6437 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 6438 | dev_info_once( |
| 6439 | &dev->ib_dev.dev, |
| 6440 | "Receive WQ counters are not supported on current FW\n"); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6441 | } |
| 6442 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 6443 | err = mlx5_core_modify_rq(dev->mdev, rwq->core_qp.qpn, in); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6444 | if (!err) |
| 6445 | rwq->ibwq.state = (wq_state == MLX5_RQC_STATE_ERR) ? IB_WQS_ERR : wq_state; |
| 6446 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6447 | out: |
| 6448 | kvfree(in); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6449 | return err; |
| 6450 | } |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6451 | |
| 6452 | struct mlx5_ib_drain_cqe { |
| 6453 | struct ib_cqe cqe; |
| 6454 | struct completion done; |
| 6455 | }; |
| 6456 | |
| 6457 | static void mlx5_ib_drain_qp_done(struct ib_cq *cq, struct ib_wc *wc) |
| 6458 | { |
| 6459 | struct mlx5_ib_drain_cqe *cqe = container_of(wc->wr_cqe, |
| 6460 | struct mlx5_ib_drain_cqe, |
| 6461 | cqe); |
| 6462 | |
| 6463 | complete(&cqe->done); |
| 6464 | } |
| 6465 | |
| 6466 | /* This function returns only once the drained WR was completed */ |
| 6467 | static void handle_drain_completion(struct ib_cq *cq, |
| 6468 | struct mlx5_ib_drain_cqe *sdrain, |
| 6469 | struct mlx5_ib_dev *dev) |
| 6470 | { |
| 6471 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6472 | |
| 6473 | if (cq->poll_ctx == IB_POLL_DIRECT) { |
| 6474 | while (wait_for_completion_timeout(&sdrain->done, HZ / 10) <= 0) |
| 6475 | ib_process_cq_direct(cq, -1); |
| 6476 | return; |
| 6477 | } |
| 6478 | |
| 6479 | if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6480 | struct mlx5_ib_cq *mcq = to_mcq(cq); |
| 6481 | bool triggered = false; |
| 6482 | unsigned long flags; |
| 6483 | |
| 6484 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 6485 | /* Make sure that the CQ handler won't run if wasn't run yet */ |
| 6486 | if (!mcq->mcq.reset_notify_added) |
| 6487 | mcq->mcq.reset_notify_added = 1; |
| 6488 | else |
| 6489 | triggered = true; |
| 6490 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 6491 | |
| 6492 | if (triggered) { |
| 6493 | /* Wait for any scheduled/running task to be ended */ |
| 6494 | switch (cq->poll_ctx) { |
| 6495 | case IB_POLL_SOFTIRQ: |
| 6496 | irq_poll_disable(&cq->iop); |
| 6497 | irq_poll_enable(&cq->iop); |
| 6498 | break; |
| 6499 | case IB_POLL_WORKQUEUE: |
| 6500 | cancel_work_sync(&cq->work); |
| 6501 | break; |
| 6502 | default: |
| 6503 | WARN_ON_ONCE(1); |
| 6504 | } |
| 6505 | } |
| 6506 | |
| 6507 | /* Run the CQ handler - this makes sure that the drain WR will |
| 6508 | * be processed if wasn't processed yet. |
| 6509 | */ |
Yishai Hadas | 4e0e2ea | 2019-06-30 19:23:27 +0300 | [diff] [blame] | 6510 | mcq->mcq.comp(&mcq->mcq, NULL); |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6511 | } |
| 6512 | |
| 6513 | wait_for_completion(&sdrain->done); |
| 6514 | } |
| 6515 | |
| 6516 | void mlx5_ib_drain_sq(struct ib_qp *qp) |
| 6517 | { |
| 6518 | struct ib_cq *cq = qp->send_cq; |
| 6519 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 6520 | struct mlx5_ib_drain_cqe sdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 6521 | const struct ib_send_wr *bad_swr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6522 | struct ib_rdma_wr swr = { |
| 6523 | .wr = { |
| 6524 | .next = NULL, |
| 6525 | { .wr_cqe = &sdrain.cqe, }, |
| 6526 | .opcode = IB_WR_RDMA_WRITE, |
| 6527 | }, |
| 6528 | }; |
| 6529 | int ret; |
| 6530 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 6531 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6532 | |
| 6533 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 6534 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6535 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 6536 | return; |
| 6537 | } |
| 6538 | |
| 6539 | sdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 6540 | init_completion(&sdrain.done); |
| 6541 | |
| 6542 | ret = _mlx5_ib_post_send(qp, &swr.wr, &bad_swr, true); |
| 6543 | if (ret) { |
| 6544 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 6545 | return; |
| 6546 | } |
| 6547 | |
| 6548 | handle_drain_completion(cq, &sdrain, dev); |
| 6549 | } |
| 6550 | |
| 6551 | void mlx5_ib_drain_rq(struct ib_qp *qp) |
| 6552 | { |
| 6553 | struct ib_cq *cq = qp->recv_cq; |
| 6554 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 6555 | struct mlx5_ib_drain_cqe rdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 6556 | struct ib_recv_wr rwr = {}; |
| 6557 | const struct ib_recv_wr *bad_rwr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6558 | int ret; |
| 6559 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 6560 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6561 | |
| 6562 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 6563 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6564 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 6565 | return; |
| 6566 | } |
| 6567 | |
| 6568 | rwr.wr_cqe = &rdrain.cqe; |
| 6569 | rdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 6570 | init_completion(&rdrain.done); |
| 6571 | |
| 6572 | ret = _mlx5_ib_post_recv(qp, &rwr, &bad_rwr, true); |
| 6573 | if (ret) { |
| 6574 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 6575 | return; |
| 6576 | } |
| 6577 | |
| 6578 | handle_drain_completion(cq, &rdrain, dev); |
| 6579 | } |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 6580 | |
| 6581 | /** |
| 6582 | * Bind a qp to a counter. If @counter is NULL then bind the qp to |
| 6583 | * the default counter |
| 6584 | */ |
| 6585 | int mlx5_ib_qp_set_counter(struct ib_qp *qp, struct rdma_counter *counter) |
| 6586 | { |
Mark Zhang | 10189e8 | 2020-01-26 19:17:08 +0200 | [diff] [blame] | 6587 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 6588 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 6589 | int err = 0; |
| 6590 | |
| 6591 | mutex_lock(&mqp->mutex); |
| 6592 | if (mqp->state == IB_QPS_RESET) { |
| 6593 | qp->counter = counter; |
| 6594 | goto out; |
| 6595 | } |
| 6596 | |
Mark Zhang | 10189e8 | 2020-01-26 19:17:08 +0200 | [diff] [blame] | 6597 | if (!MLX5_CAP_GEN(dev->mdev, rts2rts_qp_counters_set_id)) { |
| 6598 | err = -EOPNOTSUPP; |
| 6599 | goto out; |
| 6600 | } |
| 6601 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 6602 | if (mqp->state == IB_QPS_RTS) { |
| 6603 | err = __mlx5_ib_qp_set_counter(qp, counter); |
| 6604 | if (!err) |
| 6605 | qp->counter = counter; |
| 6606 | |
| 6607 | goto out; |
| 6608 | } |
| 6609 | |
| 6610 | mqp->counter_pending = 1; |
| 6611 | qp->counter = counter; |
| 6612 | |
| 6613 | out: |
| 6614 | mutex_unlock(&mqp->mutex); |
| 6615 | return err; |
| 6616 | } |