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; |
Leon Romanovsky | 3ae7e66 | 2020-04-27 18:46:19 +0300 | [diff] [blame] | 763 | case IB_QPT_RAW_PACKET: return MLX5_QP_ST_RAW_ETHERTYPE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 764 | default: return -EINVAL; |
| 765 | } |
| 766 | } |
| 767 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 768 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, |
| 769 | struct mlx5_ib_cq *recv_cq); |
| 770 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, |
| 771 | struct mlx5_ib_cq *recv_cq); |
| 772 | |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 773 | int bfregn_to_uar_index(struct mlx5_ib_dev *dev, |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 774 | struct mlx5_bfreg_info *bfregi, u32 bfregn, |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 775 | bool dyn_bfreg) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 776 | { |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 777 | unsigned int bfregs_per_sys_page; |
| 778 | u32 index_of_sys_page; |
| 779 | u32 offset; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 780 | |
Yishai Hadas | 0a2fd01 | 2020-03-24 08:01:43 +0200 | [diff] [blame] | 781 | if (bfregi->lib_uar_dyn) |
| 782 | return -EINVAL; |
| 783 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 784 | bfregs_per_sys_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k) * |
| 785 | MLX5_NON_FP_BFREGS_PER_UAR; |
| 786 | index_of_sys_page = bfregn / bfregs_per_sys_page; |
| 787 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 788 | if (dyn_bfreg) { |
| 789 | index_of_sys_page += bfregi->num_static_sys_pages; |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 790 | |
| 791 | if (index_of_sys_page >= bfregi->num_sys_pages) |
| 792 | return -EINVAL; |
| 793 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 794 | if (bfregn > bfregi->num_dyn_bfregs || |
| 795 | bfregi->sys_pages[index_of_sys_page] == MLX5_IB_INVALID_UAR_INDEX) { |
| 796 | mlx5_ib_dbg(dev, "Invalid dynamic uar index\n"); |
| 797 | return -EINVAL; |
| 798 | } |
| 799 | } |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 800 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 801 | offset = bfregn % bfregs_per_sys_page / MLX5_NON_FP_BFREGS_PER_UAR; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 802 | return bfregi->sys_pages[index_of_sys_page] + offset; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 803 | } |
| 804 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 805 | 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] | 806 | unsigned long addr, size_t size, |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 807 | struct ib_umem **umem, int *npages, int *page_shift, |
| 808 | int *ncont, u32 *offset) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 809 | { |
| 810 | int err; |
| 811 | |
Moni Shoua | c320e52 | 2020-01-15 14:43:31 +0200 | [diff] [blame] | 812 | *umem = ib_umem_get(&dev->ib_dev, addr, size, 0); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 813 | if (IS_ERR(*umem)) { |
| 814 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 815 | return PTR_ERR(*umem); |
| 816 | } |
| 817 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 818 | 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] | 819 | |
| 820 | err = mlx5_ib_get_buf_offset(addr, *page_shift, offset); |
| 821 | if (err) { |
| 822 | mlx5_ib_warn(dev, "bad offset\n"); |
| 823 | goto err_umem; |
| 824 | } |
| 825 | |
| 826 | mlx5_ib_dbg(dev, "addr 0x%lx, size %zu, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 827 | addr, size, *npages, *page_shift, *ncont, *offset); |
| 828 | |
| 829 | return 0; |
| 830 | |
| 831 | err_umem: |
| 832 | ib_umem_release(*umem); |
| 833 | *umem = NULL; |
| 834 | |
| 835 | return err; |
| 836 | } |
| 837 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 838 | 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] | 839 | struct mlx5_ib_rwq *rwq, struct ib_udata *udata) |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 840 | { |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 841 | struct mlx5_ib_ucontext *context = |
| 842 | rdma_udata_to_drv_context( |
| 843 | udata, |
| 844 | struct mlx5_ib_ucontext, |
| 845 | ibucontext); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 846 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 847 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_DELAY_DROP) |
| 848 | atomic_dec(&dev->delay_drop.rqs_cnt); |
| 849 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 850 | mlx5_ib_db_unmap_user(context, &rwq->db); |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 851 | ib_umem_release(rwq->umem); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | 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] | 855 | struct ib_udata *udata, struct mlx5_ib_rwq *rwq, |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 856 | struct mlx5_ib_create_wq *ucmd) |
| 857 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 858 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 859 | udata, struct mlx5_ib_ucontext, ibucontext); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 860 | int page_shift = 0; |
| 861 | int npages; |
| 862 | u32 offset = 0; |
| 863 | int ncont = 0; |
| 864 | int err; |
| 865 | |
| 866 | if (!ucmd->buf_addr) |
| 867 | return -EINVAL; |
| 868 | |
Moni Shoua | c320e52 | 2020-01-15 14:43:31 +0200 | [diff] [blame] | 869 | 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] | 870 | if (IS_ERR(rwq->umem)) { |
| 871 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 872 | err = PTR_ERR(rwq->umem); |
| 873 | return err; |
| 874 | } |
| 875 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 876 | 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] | 877 | &ncont, NULL); |
| 878 | err = mlx5_ib_get_buf_offset(ucmd->buf_addr, page_shift, |
| 879 | &rwq->rq_page_offset); |
| 880 | if (err) { |
| 881 | mlx5_ib_warn(dev, "bad offset\n"); |
| 882 | goto err_umem; |
| 883 | } |
| 884 | |
| 885 | rwq->rq_num_pas = ncont; |
| 886 | rwq->page_shift = page_shift; |
| 887 | rwq->log_page_size = page_shift - MLX5_ADAPTER_PAGE_SHIFT; |
| 888 | rwq->wq_sig = !!(ucmd->flags & MLX5_WQ_FLAG_SIGNATURE); |
| 889 | |
| 890 | mlx5_ib_dbg(dev, "addr 0x%llx, size %zd, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 891 | (unsigned long long)ucmd->buf_addr, rwq->buf_size, |
| 892 | npages, page_shift, ncont, offset); |
| 893 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 894 | 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] | 895 | if (err) { |
| 896 | mlx5_ib_dbg(dev, "map failed\n"); |
| 897 | goto err_umem; |
| 898 | } |
| 899 | |
| 900 | rwq->create_type = MLX5_WQ_USER; |
| 901 | return 0; |
| 902 | |
| 903 | err_umem: |
| 904 | ib_umem_release(rwq->umem); |
| 905 | return err; |
| 906 | } |
| 907 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 908 | static int adjust_bfregn(struct mlx5_ib_dev *dev, |
| 909 | struct mlx5_bfreg_info *bfregi, int bfregn) |
| 910 | { |
| 911 | return bfregn / MLX5_NON_FP_BFREGS_PER_UAR * MLX5_BFREGS_PER_UAR + |
| 912 | bfregn % MLX5_NON_FP_BFREGS_PER_UAR; |
| 913 | } |
| 914 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 915 | static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 916 | struct mlx5_ib_qp *qp, struct ib_udata *udata, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 917 | struct ib_qp_init_attr *attr, |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 918 | u32 **in, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 919 | struct mlx5_ib_create_qp_resp *resp, int *inlen, |
| 920 | struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 921 | { |
| 922 | struct mlx5_ib_ucontext *context; |
| 923 | struct mlx5_ib_create_qp ucmd; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 924 | struct mlx5_ib_ubuffer *ubuffer = &base->ubuffer; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 925 | int page_shift = 0; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 926 | int uar_index = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 927 | int npages; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 928 | u32 offset = 0; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 929 | int bfregn; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 930 | int ncont = 0; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 931 | __be64 *pas; |
| 932 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 933 | int err; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 934 | u16 uid; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 935 | u32 uar_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 936 | |
| 937 | err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)); |
| 938 | if (err) { |
| 939 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 940 | return err; |
| 941 | } |
| 942 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 943 | context = rdma_udata_to_drv_context(udata, struct mlx5_ib_ucontext, |
| 944 | ibucontext); |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 945 | uar_flags = ucmd.flags & (MLX5_QP_FLAG_UAR_PAGE_INDEX | |
| 946 | MLX5_QP_FLAG_BFREG_INDEX); |
| 947 | switch (uar_flags) { |
| 948 | case MLX5_QP_FLAG_UAR_PAGE_INDEX: |
| 949 | uar_index = ucmd.bfreg_index; |
| 950 | bfregn = MLX5_IB_INVALID_BFREG; |
| 951 | break; |
| 952 | case MLX5_QP_FLAG_BFREG_INDEX: |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 953 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, |
| 954 | ucmd.bfreg_index, true); |
| 955 | if (uar_index < 0) |
| 956 | return uar_index; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 957 | bfregn = MLX5_IB_INVALID_BFREG; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 958 | break; |
| 959 | case 0: |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 960 | if (qp->flags & IB_QP_CREATE_CROSS_CHANNEL) |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 961 | return -EINVAL; |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 962 | bfregn = alloc_bfreg(dev, &context->bfregi); |
| 963 | if (bfregn < 0) |
| 964 | return bfregn; |
Yishai Hadas | ac42a5e | 2020-03-24 08:01:41 +0200 | [diff] [blame] | 965 | break; |
| 966 | default: |
| 967 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 968 | } |
| 969 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 970 | 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] | 971 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 972 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, bfregn, |
| 973 | false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 974 | |
Haggai Eran | 48fea83 | 2014-05-22 14:50:11 +0300 | [diff] [blame] | 975 | qp->rq.offset = 0; |
| 976 | qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); |
| 977 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
| 978 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 979 | err = set_user_buf_size(dev, qp, &ucmd, base, attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 980 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 981 | goto err_bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 982 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 983 | if (ucmd.buf_addr && ubuffer->buf_size) { |
| 984 | ubuffer->buf_addr = ucmd.buf_addr; |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 985 | err = mlx5_ib_umem_get(dev, udata, ubuffer->buf_addr, |
| 986 | ubuffer->buf_size, &ubuffer->umem, |
| 987 | &npages, &page_shift, &ncont, &offset); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 988 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 989 | goto err_bfreg; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 990 | } else { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 991 | ubuffer->umem = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 992 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 993 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 994 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 995 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 996 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 997 | if (!*in) { |
| 998 | err = -ENOMEM; |
| 999 | goto err_umem; |
| 1000 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1001 | |
Yishai Hadas | 7422edc | 2018-12-23 13:12:21 +0200 | [diff] [blame] | 1002 | uid = (attr->qp_type != IB_QPT_XRC_TGT && |
| 1003 | attr->qp_type != IB_QPT_XRC_INI) ? to_mpd(pd)->uid : 0; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 1004 | MLX5_SET(create_qp_in, *in, uid, uid); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1005 | pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, *in, pas); |
| 1006 | if (ubuffer->umem) |
| 1007 | mlx5_ib_populate_pas(dev, ubuffer->umem, page_shift, pas, 0); |
| 1008 | |
| 1009 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 1010 | |
| 1011 | MLX5_SET(qpc, qpc, log_page_size, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1012 | MLX5_SET(qpc, qpc, page_offset, offset); |
| 1013 | |
| 1014 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1015 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 1016 | resp->bfreg_index = adjust_bfregn(dev, &context->bfregi, bfregn); |
| 1017 | else |
| 1018 | resp->bfreg_index = MLX5_IB_INVALID_BFREG; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1019 | qp->bfregn = bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1020 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1021 | 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] | 1022 | if (err) { |
| 1023 | mlx5_ib_dbg(dev, "map failed\n"); |
| 1024 | goto err_free; |
| 1025 | } |
| 1026 | |
Jason Gunthorpe | 41d902c | 2018-04-03 10:00:53 +0300 | [diff] [blame] | 1027 | err = ib_copy_to_udata(udata, resp, min(udata->outlen, sizeof(*resp))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1028 | if (err) { |
| 1029 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1030 | goto err_unmap; |
| 1031 | } |
| 1032 | qp->create_type = MLX5_QP_USER; |
| 1033 | |
| 1034 | return 0; |
| 1035 | |
| 1036 | err_unmap: |
| 1037 | mlx5_ib_db_unmap_user(context, &qp->db); |
| 1038 | |
| 1039 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 1040 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1041 | |
| 1042 | err_umem: |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 1043 | ib_umem_release(ubuffer->umem); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1044 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1045 | err_bfreg: |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1046 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 1047 | mlx5_ib_free_bfreg(dev, &context->bfregi, bfregn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1048 | return err; |
| 1049 | } |
| 1050 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 1051 | 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] | 1052 | struct mlx5_ib_qp *qp, struct mlx5_ib_qp_base *base, |
| 1053 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1054 | { |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 1055 | struct mlx5_ib_ucontext *context = |
| 1056 | rdma_udata_to_drv_context( |
| 1057 | udata, |
| 1058 | struct mlx5_ib_ucontext, |
| 1059 | ibucontext); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1060 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1061 | mlx5_ib_db_unmap_user(context, &qp->db); |
Leon Romanovsky | 836a0fb | 2019-06-16 15:05:20 +0300 | [diff] [blame] | 1062 | ib_umem_release(base->ubuffer.umem); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 1063 | |
| 1064 | /* |
| 1065 | * Free only the BFREGs which are handled by the kernel. |
| 1066 | * BFREGs of UARs allocated dynamically are handled by user. |
| 1067 | */ |
| 1068 | if (qp->bfregn != MLX5_IB_INVALID_BFREG) |
| 1069 | mlx5_ib_free_bfreg(dev, &context->bfregi, qp->bfregn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1070 | } |
| 1071 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1072 | /* get_sq_edge - Get the next nearby edge. |
| 1073 | * |
| 1074 | * An 'edge' is defined as the first following address after the end |
| 1075 | * of the fragment or the SQ. Accordingly, during the WQE construction |
| 1076 | * which repetitively increases the pointer to write the next data, it |
| 1077 | * simply should check if it gets to an edge. |
| 1078 | * |
| 1079 | * @sq - SQ buffer. |
| 1080 | * @idx - Stride index in the SQ buffer. |
| 1081 | * |
| 1082 | * Return: |
| 1083 | * The new edge. |
| 1084 | */ |
| 1085 | static void *get_sq_edge(struct mlx5_ib_wq *sq, u32 idx) |
| 1086 | { |
| 1087 | void *fragment_end; |
| 1088 | |
| 1089 | fragment_end = mlx5_frag_buf_get_wqe |
| 1090 | (&sq->fbc, |
| 1091 | mlx5_frag_buf_get_idx_last_contig_stride(&sq->fbc, idx)); |
| 1092 | |
| 1093 | return fragment_end + MLX5_SEND_WQE_BB; |
| 1094 | } |
| 1095 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1096 | static int create_kernel_qp(struct mlx5_ib_dev *dev, |
| 1097 | struct ib_qp_init_attr *init_attr, |
| 1098 | struct mlx5_ib_qp *qp, |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1099 | u32 **in, int *inlen, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 1100 | struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1101 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1102 | int uar_index; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1103 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1104 | int err; |
| 1105 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1106 | if (init_attr->qp_type == MLX5_IB_QPT_REG_UMR) |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1107 | qp->bf.bfreg = &dev->fp_bfreg; |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1108 | else if (qp->flags & MLX5_IB_QP_CREATE_WC_TEST) |
Michael Guralnik | 11f552e | 2019-06-10 15:21:24 +0300 | [diff] [blame] | 1109 | qp->bf.bfreg = &dev->wc_bfreg; |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1110 | else |
| 1111 | qp->bf.bfreg = &dev->bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1112 | |
Eli Cohen | d8030b0 | 2017-02-09 19:31:47 +0200 | [diff] [blame] | 1113 | /* We need to divide by two since each register is comprised of |
| 1114 | * two buffers of identical size, namely odd and even |
| 1115 | */ |
| 1116 | 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] | 1117 | uar_index = qp->bf.bfreg->index; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1118 | |
| 1119 | err = calc_sq_size(dev, init_attr, qp); |
| 1120 | if (err < 0) { |
| 1121 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1122 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1123 | } |
| 1124 | |
| 1125 | qp->rq.offset = 0; |
| 1126 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 1127 | 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] | 1128 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1129 | err = mlx5_frag_buf_alloc_node(dev->mdev, base->ubuffer.buf_size, |
| 1130 | &qp->buf, dev->mdev->priv.numa_node); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1131 | if (err) { |
| 1132 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 1133 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1134 | } |
| 1135 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1136 | if (qp->rq.wqe_cnt) |
| 1137 | mlx5_init_fbc(qp->buf.frags, qp->rq.wqe_shift, |
| 1138 | ilog2(qp->rq.wqe_cnt), &qp->rq.fbc); |
| 1139 | |
| 1140 | if (qp->sq.wqe_cnt) { |
| 1141 | int sq_strides_offset = (qp->sq.offset & (PAGE_SIZE - 1)) / |
| 1142 | MLX5_SEND_WQE_BB; |
| 1143 | mlx5_init_fbc_offset(qp->buf.frags + |
| 1144 | (qp->sq.offset / PAGE_SIZE), |
| 1145 | ilog2(MLX5_SEND_WQE_BB), |
| 1146 | ilog2(qp->sq.wqe_cnt), |
| 1147 | sq_strides_offset, &qp->sq.fbc); |
| 1148 | |
| 1149 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
| 1150 | } |
| 1151 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1152 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 1153 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * qp->buf.npages; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1154 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1155 | if (!*in) { |
| 1156 | err = -ENOMEM; |
| 1157 | goto err_buf; |
| 1158 | } |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1159 | |
| 1160 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 1161 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
| 1162 | MLX5_SET(qpc, qpc, log_page_size, qp->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1163 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1164 | /* Set "fast registration enabled" for all kernel QPs */ |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1165 | MLX5_SET(qpc, qpc, fre, 1); |
| 1166 | MLX5_SET(qpc, qpc, rlky, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1167 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1168 | if (qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1169 | MLX5_SET(qpc, qpc, deth_sqpn, 1); |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 1170 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1171 | mlx5_fill_page_frag_array(&qp->buf, |
| 1172 | (__be64 *)MLX5_ADDR_OF(create_qp_in, |
| 1173 | *in, pas)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1174 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1175 | err = mlx5_db_alloc(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1176 | if (err) { |
| 1177 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1178 | goto err_free; |
| 1179 | } |
| 1180 | |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1181 | qp->sq.wrid = kvmalloc_array(qp->sq.wqe_cnt, |
| 1182 | sizeof(*qp->sq.wrid), GFP_KERNEL); |
| 1183 | qp->sq.wr_data = kvmalloc_array(qp->sq.wqe_cnt, |
| 1184 | sizeof(*qp->sq.wr_data), GFP_KERNEL); |
| 1185 | qp->rq.wrid = kvmalloc_array(qp->rq.wqe_cnt, |
| 1186 | sizeof(*qp->rq.wrid), GFP_KERNEL); |
| 1187 | qp->sq.w_list = kvmalloc_array(qp->sq.wqe_cnt, |
| 1188 | sizeof(*qp->sq.w_list), GFP_KERNEL); |
| 1189 | qp->sq.wqe_head = kvmalloc_array(qp->sq.wqe_cnt, |
| 1190 | sizeof(*qp->sq.wqe_head), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1191 | |
| 1192 | if (!qp->sq.wrid || !qp->sq.wr_data || !qp->rq.wrid || |
| 1193 | !qp->sq.w_list || !qp->sq.wqe_head) { |
| 1194 | err = -ENOMEM; |
| 1195 | goto err_wrid; |
| 1196 | } |
| 1197 | qp->create_type = MLX5_QP_KERNEL; |
| 1198 | |
| 1199 | return 0; |
| 1200 | |
| 1201 | err_wrid: |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1202 | kvfree(qp->sq.wqe_head); |
| 1203 | kvfree(qp->sq.w_list); |
| 1204 | kvfree(qp->sq.wrid); |
| 1205 | kvfree(qp->sq.wr_data); |
| 1206 | kvfree(qp->rq.wrid); |
Eli Cohen | f4044da | 2017-01-03 23:55:20 +0200 | [diff] [blame] | 1207 | mlx5_db_free(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1208 | |
| 1209 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 1210 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1211 | |
| 1212 | err_buf: |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1213 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1214 | return err; |
| 1215 | } |
| 1216 | |
| 1217 | static void destroy_qp_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 1218 | { |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1219 | kvfree(qp->sq.wqe_head); |
| 1220 | kvfree(qp->sq.w_list); |
| 1221 | kvfree(qp->sq.wrid); |
| 1222 | kvfree(qp->sq.wr_data); |
| 1223 | kvfree(qp->rq.wrid); |
Eli Cohen | f4044da | 2017-01-03 23:55:20 +0200 | [diff] [blame] | 1224 | mlx5_db_free(dev->mdev, &qp->db); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1225 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1226 | } |
| 1227 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1228 | 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] | 1229 | { |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 1230 | if (attr->srq || (qp->type == IB_QPT_XRC_TGT) || |
| 1231 | (qp->type == MLX5_IB_QPT_DCI) || (qp->type == IB_QPT_XRC_INI)) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1232 | return MLX5_SRQ_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1233 | else if (!qp->has_rq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1234 | return MLX5_ZERO_LEN_RQ; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 1235 | |
| 1236 | return MLX5_NON_ZERO_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1237 | } |
| 1238 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1239 | static int create_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1240 | struct mlx5_ib_qp *qp, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1241 | struct mlx5_ib_sq *sq, u32 tdn, |
| 1242 | struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1243 | { |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1244 | u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {}; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1245 | void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx); |
| 1246 | |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1247 | MLX5_SET(create_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1248 | MLX5_SET(tisc, tisc, transport_domain, tdn); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1249 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1250 | MLX5_SET(tisc, tisc, underlay_qpn, qp->underlay_qpn); |
| 1251 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1252 | return mlx5_core_create_tis(dev->mdev, in, &sq->tisn); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | static void destroy_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1256 | struct mlx5_ib_sq *sq, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1257 | { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1258 | 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] | 1259 | } |
| 1260 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1261 | static void destroy_flow_rule_vport_sq(struct mlx5_ib_sq *sq) |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1262 | { |
| 1263 | if (sq->flow_rule) |
| 1264 | mlx5_del_flow_rules(sq->flow_rule); |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1265 | sq->flow_rule = NULL; |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1266 | } |
| 1267 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1268 | static int create_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1269 | struct ib_udata *udata, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1270 | struct mlx5_ib_sq *sq, void *qpin, |
| 1271 | struct ib_pd *pd) |
| 1272 | { |
| 1273 | struct mlx5_ib_ubuffer *ubuffer = &sq->ubuffer; |
| 1274 | __be64 *pas; |
| 1275 | void *in; |
| 1276 | void *sqc; |
| 1277 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
| 1278 | void *wq; |
| 1279 | int inlen; |
| 1280 | int err; |
| 1281 | int page_shift = 0; |
| 1282 | int npages; |
| 1283 | int ncont = 0; |
| 1284 | u32 offset = 0; |
| 1285 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1286 | err = mlx5_ib_umem_get(dev, udata, ubuffer->buf_addr, ubuffer->buf_size, |
| 1287 | &sq->ubuffer.umem, &npages, &page_shift, &ncont, |
| 1288 | &offset); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1289 | if (err) |
| 1290 | return err; |
| 1291 | |
| 1292 | inlen = MLX5_ST_SZ_BYTES(create_sq_in) + sizeof(u64) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1293 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1294 | if (!in) { |
| 1295 | err = -ENOMEM; |
| 1296 | goto err_umem; |
| 1297 | } |
| 1298 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 1299 | MLX5_SET(create_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1300 | sqc = MLX5_ADDR_OF(create_sq_in, in, ctx); |
| 1301 | MLX5_SET(sqc, sqc, flush_in_error_en, 1); |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1302 | if (MLX5_CAP_ETH(dev->mdev, multi_pkt_send_wqe)) |
| 1303 | MLX5_SET(sqc, sqc, allow_multi_pkt_send_wqe, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1304 | MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST); |
| 1305 | MLX5_SET(sqc, sqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1306 | MLX5_SET(sqc, sqc, cqn, MLX5_GET(qpc, qpc, cqn_snd)); |
| 1307 | MLX5_SET(sqc, sqc, tis_lst_sz, 1); |
| 1308 | MLX5_SET(sqc, sqc, tis_num_0, sq->tisn); |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1309 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 1310 | MLX5_CAP_ETH(dev->mdev, swp)) |
| 1311 | MLX5_SET(sqc, sqc, allow_swp, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1312 | |
| 1313 | wq = MLX5_ADDR_OF(sqc, sqc, wq); |
| 1314 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
| 1315 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1316 | MLX5_SET(wq, wq, uar_page, MLX5_GET(qpc, qpc, uar_page)); |
| 1317 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1318 | MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB)); |
| 1319 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_sq_size)); |
| 1320 | MLX5_SET(wq, wq, log_wq_pg_sz, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1321 | MLX5_SET(wq, wq, page_offset, offset); |
| 1322 | |
| 1323 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1324 | mlx5_ib_populate_pas(dev, sq->ubuffer.umem, page_shift, pas, 0); |
| 1325 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1326 | 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] | 1327 | |
| 1328 | kvfree(in); |
| 1329 | |
| 1330 | if (err) |
| 1331 | goto err_umem; |
| 1332 | |
| 1333 | return 0; |
| 1334 | |
| 1335 | err_umem: |
| 1336 | ib_umem_release(sq->ubuffer.umem); |
| 1337 | sq->ubuffer.umem = NULL; |
| 1338 | |
| 1339 | return err; |
| 1340 | } |
| 1341 | |
| 1342 | static void destroy_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
| 1343 | struct mlx5_ib_sq *sq) |
| 1344 | { |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 1345 | destroy_flow_rule_vport_sq(sq); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1346 | mlx5_core_destroy_sq_tracked(dev, &sq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1347 | ib_umem_release(sq->ubuffer.umem); |
| 1348 | } |
| 1349 | |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1350 | static size_t get_rq_pas_size(void *qpc) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1351 | { |
| 1352 | u32 log_page_size = MLX5_GET(qpc, qpc, log_page_size) + 12; |
| 1353 | u32 log_rq_stride = MLX5_GET(qpc, qpc, log_rq_stride); |
| 1354 | u32 log_rq_size = MLX5_GET(qpc, qpc, log_rq_size); |
| 1355 | u32 page_offset = MLX5_GET(qpc, qpc, page_offset); |
| 1356 | u32 po_quanta = 1 << (log_page_size - 6); |
| 1357 | u32 rq_sz = 1 << (log_rq_size + 4 + log_rq_stride); |
| 1358 | u32 page_size = 1 << log_page_size; |
| 1359 | u32 rq_sz_po = rq_sz + (page_offset * po_quanta); |
| 1360 | u32 rq_num_pas = (rq_sz_po + page_size - 1) / page_size; |
| 1361 | |
| 1362 | return rq_num_pas * sizeof(u64); |
| 1363 | } |
| 1364 | |
| 1365 | static int create_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1366 | struct mlx5_ib_rq *rq, void *qpin, |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1367 | size_t qpinlen, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1368 | { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1369 | struct mlx5_ib_qp *mqp = rq->base.container_mibqp; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1370 | __be64 *pas; |
| 1371 | __be64 *qp_pas; |
| 1372 | void *in; |
| 1373 | void *rqc; |
| 1374 | void *wq; |
| 1375 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1376 | size_t rq_pas_size = get_rq_pas_size(qpc); |
| 1377 | size_t inlen; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1378 | int err; |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1379 | |
| 1380 | if (qpinlen < rq_pas_size + MLX5_BYTE_OFF(create_qp_in, pas)) |
| 1381 | return -EINVAL; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1382 | |
| 1383 | inlen = MLX5_ST_SZ_BYTES(create_rq_in) + rq_pas_size; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1384 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1385 | if (!in) |
| 1386 | return -ENOMEM; |
| 1387 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1388 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1389 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1390 | if (!(rq->flags & MLX5_IB_RQ_CVLAN_STRIPPING)) |
| 1391 | MLX5_SET(rqc, rqc, vsd, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1392 | MLX5_SET(rqc, rqc, mem_rq_type, MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 1393 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 1394 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 1395 | MLX5_SET(rqc, rqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1396 | MLX5_SET(rqc, rqc, cqn, MLX5_GET(qpc, qpc, cqn_rcv)); |
| 1397 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1398 | if (mqp->flags & IB_QP_CREATE_SCATTER_FCS) |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1399 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 1400 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1401 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
| 1402 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1403 | if (rq->flags & MLX5_IB_RQ_PCI_WRITE_END_PADDING) |
| 1404 | 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] | 1405 | MLX5_SET(wq, wq, page_offset, MLX5_GET(qpc, qpc, page_offset)); |
| 1406 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1407 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1408 | MLX5_SET(wq, wq, log_wq_stride, MLX5_GET(qpc, qpc, log_rq_stride) + 4); |
| 1409 | MLX5_SET(wq, wq, log_wq_pg_sz, MLX5_GET(qpc, qpc, log_page_size)); |
| 1410 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_rq_size)); |
| 1411 | |
| 1412 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1413 | qp_pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, qpin, pas); |
| 1414 | memcpy(pas, qp_pas, rq_pas_size); |
| 1415 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1416 | 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] | 1417 | |
| 1418 | kvfree(in); |
| 1419 | |
| 1420 | return err; |
| 1421 | } |
| 1422 | |
| 1423 | static void destroy_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
| 1424 | struct mlx5_ib_rq *rq) |
| 1425 | { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 1426 | mlx5_core_destroy_rq_tracked(dev, &rq->base.mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1427 | } |
| 1428 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1429 | static void destroy_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
| 1430 | struct mlx5_ib_rq *rq, |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1431 | u32 qp_flags_en, |
| 1432 | struct ib_pd *pd) |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1433 | { |
| 1434 | if (qp_flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1435 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1436 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1437 | mlx5_cmd_destroy_tir(dev->mdev, rq->tirn, to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1438 | } |
| 1439 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1440 | static int create_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1441 | struct mlx5_ib_rq *rq, u32 tdn, |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1442 | u32 *qp_flags_en, struct ib_pd *pd, |
| 1443 | u32 *out) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1444 | { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1445 | u8 lb_flag = 0; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1446 | u32 *in; |
| 1447 | void *tirc; |
| 1448 | int inlen; |
| 1449 | int err; |
| 1450 | |
| 1451 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1452 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1453 | if (!in) |
| 1454 | return -ENOMEM; |
| 1455 | |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1456 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1457 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1458 | MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_DIRECT); |
| 1459 | MLX5_SET(tirc, tirc, inline_rqn, rq->base.mqp.qpn); |
| 1460 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1461 | if (*qp_flags_en & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1462 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1463 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1464 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) |
| 1465 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1466 | |
| 1467 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) |
| 1468 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
| 1469 | |
Mark Bloch | 6a4d00b | 2019-03-28 15:27:37 +0200 | [diff] [blame] | 1470 | if (dev->is_rep) { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1471 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1472 | *qp_flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 1473 | } |
| 1474 | |
| 1475 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1476 | MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR); |
| 1477 | err = mlx5_cmd_exec_inout(dev->mdev, create_tir, in, out); |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1478 | rq->tirn = MLX5_GET(create_tir_out, out, tirn); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1479 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1480 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1481 | |
| 1482 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1483 | destroy_raw_packet_qp_tir(dev, rq, 0, pd); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1484 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1485 | kvfree(in); |
| 1486 | |
| 1487 | return err; |
| 1488 | } |
| 1489 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1490 | 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] | 1491 | u32 *in, size_t inlen, |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1492 | struct ib_pd *pd, |
| 1493 | struct ib_udata *udata, |
| 1494 | struct mlx5_ib_create_qp_resp *resp) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1495 | { |
| 1496 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1497 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1498 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1499 | struct mlx5_ib_ucontext *mucontext = rdma_udata_to_drv_context( |
| 1500 | udata, struct mlx5_ib_ucontext, ibucontext); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1501 | int err; |
| 1502 | u32 tdn = mucontext->tdn; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1503 | u16 uid = to_mpd(pd)->uid; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1504 | u32 out[MLX5_ST_SZ_DW(create_tir_out)] = {}; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1505 | |
| 1506 | if (qp->sq.wqe_cnt) { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1507 | err = create_raw_packet_qp_tis(dev, qp, sq, tdn, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1508 | if (err) |
| 1509 | return err; |
| 1510 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 1511 | err = create_raw_packet_qp_sq(dev, udata, sq, in, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1512 | if (err) |
| 1513 | goto err_destroy_tis; |
| 1514 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1515 | if (uid) { |
| 1516 | resp->tisn = sq->tisn; |
| 1517 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TISN; |
| 1518 | resp->sqn = sq->base.mqp.qpn; |
| 1519 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_SQN; |
| 1520 | } |
| 1521 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1522 | sq->base.container_mibqp = qp; |
Majd Dibbiny | 1d31e9c | 2017-08-23 08:35:41 +0300 | [diff] [blame] | 1523 | sq->base.mqp.event = mlx5_ib_qp_event; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | if (qp->rq.wqe_cnt) { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1527 | rq->base.container_mibqp = qp; |
| 1528 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1529 | if (qp->flags & IB_QP_CREATE_CVLAN_STRIPPING) |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1530 | rq->flags |= MLX5_IB_RQ_CVLAN_STRIPPING; |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1531 | if (qp->flags & IB_QP_CREATE_PCI_WRITE_END_PADDING) |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1532 | rq->flags |= MLX5_IB_RQ_PCI_WRITE_END_PADDING; |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1533 | err = create_raw_packet_qp_rq(dev, rq, in, inlen, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1534 | if (err) |
| 1535 | goto err_destroy_sq; |
| 1536 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1537 | err = create_raw_packet_qp_tir(dev, rq, tdn, &qp->flags_en, pd, |
| 1538 | out); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1539 | if (err) |
| 1540 | goto err_destroy_rq; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1541 | |
| 1542 | if (uid) { |
| 1543 | resp->rqn = rq->base.mqp.qpn; |
| 1544 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_RQN; |
| 1545 | resp->tirn = rq->tirn; |
| 1546 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1547 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner)) { |
| 1548 | resp->tir_icm_addr = MLX5_GET( |
| 1549 | create_tir_out, out, icm_address_31_0); |
| 1550 | resp->tir_icm_addr |= |
| 1551 | (u64)MLX5_GET(create_tir_out, out, |
| 1552 | icm_address_39_32) |
| 1553 | << 32; |
| 1554 | resp->tir_icm_addr |= |
| 1555 | (u64)MLX5_GET(create_tir_out, out, |
| 1556 | icm_address_63_40) |
| 1557 | << 40; |
| 1558 | resp->comp_mask |= |
| 1559 | MLX5_IB_CREATE_QP_RESP_MASK_TIR_ICM_ADDR; |
| 1560 | } |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1561 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | qp->trans_qp.base.mqp.qpn = qp->sq.wqe_cnt ? sq->base.mqp.qpn : |
| 1565 | rq->base.mqp.qpn; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1566 | err = ib_copy_to_udata(udata, resp, min(udata->outlen, sizeof(*resp))); |
| 1567 | if (err) |
| 1568 | goto err_destroy_tir; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1569 | |
| 1570 | return 0; |
| 1571 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1572 | err_destroy_tir: |
| 1573 | destroy_raw_packet_qp_tir(dev, rq, qp->flags_en, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1574 | err_destroy_rq: |
| 1575 | destroy_raw_packet_qp_rq(dev, rq); |
| 1576 | err_destroy_sq: |
| 1577 | if (!qp->sq.wqe_cnt) |
| 1578 | return err; |
| 1579 | destroy_raw_packet_qp_sq(dev, sq); |
| 1580 | err_destroy_tis: |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1581 | destroy_raw_packet_qp_tis(dev, sq, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1582 | |
| 1583 | return err; |
| 1584 | } |
| 1585 | |
| 1586 | static void destroy_raw_packet_qp(struct mlx5_ib_dev *dev, |
| 1587 | struct mlx5_ib_qp *qp) |
| 1588 | { |
| 1589 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1590 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1591 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1592 | |
| 1593 | if (qp->rq.wqe_cnt) { |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1594 | 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] | 1595 | destroy_raw_packet_qp_rq(dev, rq); |
| 1596 | } |
| 1597 | |
| 1598 | if (qp->sq.wqe_cnt) { |
| 1599 | destroy_raw_packet_qp_sq(dev, sq); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1600 | destroy_raw_packet_qp_tis(dev, sq, qp->ibqp.pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1601 | } |
| 1602 | } |
| 1603 | |
| 1604 | static void raw_packet_qp_copy_info(struct mlx5_ib_qp *qp, |
| 1605 | struct mlx5_ib_raw_packet_qp *raw_packet_qp) |
| 1606 | { |
| 1607 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1608 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1609 | |
| 1610 | sq->sq = &qp->sq; |
| 1611 | rq->rq = &qp->rq; |
| 1612 | sq->doorbell = &qp->db; |
| 1613 | rq->doorbell = &qp->db; |
| 1614 | } |
| 1615 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1616 | static void destroy_rss_raw_qp_tir(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 1617 | { |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1618 | if (qp->flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1619 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1620 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1621 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1622 | to_mpd(qp->ibqp.pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1623 | } |
| 1624 | |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 1625 | 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] | 1626 | struct ib_qp_init_attr *init_attr, |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1627 | struct mlx5_ib_create_qp_rss *ucmd, |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1628 | struct ib_udata *udata) |
| 1629 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1630 | struct mlx5_ib_ucontext *mucontext = rdma_udata_to_drv_context( |
| 1631 | udata, struct mlx5_ib_ucontext, ibucontext); |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 1632 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1633 | struct mlx5_ib_create_qp_resp resp = {}; |
| 1634 | int inlen; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1635 | int outlen; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1636 | int err; |
| 1637 | u32 *in; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1638 | u32 *out; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1639 | void *tirc; |
| 1640 | void *hfso; |
| 1641 | u32 selected_fields = 0; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1642 | u32 outer_l4; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1643 | size_t min_resp_len; |
| 1644 | u32 tdn = mucontext->tdn; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1645 | u8 lb_flag = 0; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1646 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1647 | min_resp_len = offsetof(typeof(resp), bfreg_index) + sizeof(resp.bfreg_index); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1648 | if (udata->outlen < min_resp_len) |
| 1649 | return -EINVAL; |
| 1650 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1651 | if (ucmd->comp_mask) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1652 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 1653 | return -EOPNOTSUPP; |
| 1654 | } |
| 1655 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1656 | if (ucmd->flags & ~(MLX5_QP_FLAG_TUNNEL_OFFLOADS | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1657 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1658 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) { |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1659 | mlx5_ib_dbg(dev, "invalid flags\n"); |
| 1660 | return -EOPNOTSUPP; |
| 1661 | } |
| 1662 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1663 | if (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_INNER && |
| 1664 | !(ucmd->flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS)) { |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1665 | mlx5_ib_dbg(dev, "Tunnel offloads must be set for inner RSS\n"); |
| 1666 | return -EOPNOTSUPP; |
| 1667 | } |
| 1668 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 1669 | if (dev->is_rep) |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1670 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1671 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 1672 | if (qp->flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) |
| 1673 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1674 | |
| 1675 | if (qp->flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1676 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1677 | |
Jason Gunthorpe | 41d902c | 2018-04-03 10:00:53 +0300 | [diff] [blame] | 1678 | err = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp))); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1679 | if (err) { |
| 1680 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1681 | return -EINVAL; |
| 1682 | } |
| 1683 | |
| 1684 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1685 | outlen = MLX5_ST_SZ_BYTES(create_tir_out); |
| 1686 | in = kvzalloc(inlen + outlen, GFP_KERNEL); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1687 | if (!in) |
| 1688 | return -ENOMEM; |
| 1689 | |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1690 | out = in + MLX5_ST_SZ_DW(create_tir_in); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1691 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1692 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1693 | MLX5_SET(tirc, tirc, disp_type, |
| 1694 | MLX5_TIRC_DISP_TYPE_INDIRECT); |
| 1695 | MLX5_SET(tirc, tirc, indirect_table, |
| 1696 | init_attr->rwq_ind_tbl->ind_tbl_num); |
| 1697 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
| 1698 | |
| 1699 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1700 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1701 | if (ucmd->flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1702 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
| 1703 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1704 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
| 1705 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1706 | if (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_INNER) |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1707 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_inner); |
| 1708 | else |
| 1709 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
| 1710 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1711 | switch (ucmd->rx_hash_function) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1712 | case MLX5_RX_HASH_FUNC_TOEPLITZ: |
| 1713 | { |
| 1714 | void *rss_key = MLX5_ADDR_OF(tirc, tirc, rx_hash_toeplitz_key); |
| 1715 | size_t len = MLX5_FLD_SZ_BYTES(tirc, rx_hash_toeplitz_key); |
| 1716 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1717 | if (len != ucmd->rx_key_len) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1718 | err = -EINVAL; |
| 1719 | goto err; |
| 1720 | } |
| 1721 | |
| 1722 | MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_TOEPLITZ); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1723 | memcpy(rss_key, ucmd->rx_hash_key, len); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1724 | break; |
| 1725 | } |
| 1726 | default: |
| 1727 | err = -EOPNOTSUPP; |
| 1728 | goto err; |
| 1729 | } |
| 1730 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1731 | if (!ucmd->rx_hash_fields_mask) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1732 | /* special case when this TIR serves as steering entry without hashing */ |
| 1733 | if (!init_attr->rwq_ind_tbl->log_ind_tbl_size) |
| 1734 | goto create_tir; |
| 1735 | err = -EINVAL; |
| 1736 | goto err; |
| 1737 | } |
| 1738 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1739 | if (((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1740 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) && |
| 1741 | ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1742 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6))) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1743 | err = -EINVAL; |
| 1744 | goto err; |
| 1745 | } |
| 1746 | |
| 1747 | /* If none of IPV4 & IPV6 SRC/DST was set - this bit field is ignored */ |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1748 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1749 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1750 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1751 | MLX5_L3_PROT_TYPE_IPV4); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1752 | else if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1753 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1754 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1755 | MLX5_L3_PROT_TYPE_IPV6); |
| 1756 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1757 | outer_l4 = ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1758 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) |
| 1759 | << 0 | |
| 1760 | ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1761 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
| 1762 | << 1 | |
| 1763 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) << 2; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1764 | |
| 1765 | /* Check that only one l4 protocol is set */ |
| 1766 | if (outer_l4 & (outer_l4 - 1)) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1767 | err = -EINVAL; |
| 1768 | goto err; |
| 1769 | } |
| 1770 | |
| 1771 | /* If none of TCP & UDP SRC/DST was set - this bit field is ignored */ |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1772 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1773 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1774 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1775 | MLX5_L4_PROT_TYPE_TCP); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1776 | else if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1777 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1778 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1779 | MLX5_L4_PROT_TYPE_UDP); |
| 1780 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1781 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1782 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1783 | selected_fields |= MLX5_HASH_FIELD_SEL_SRC_IP; |
| 1784 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1785 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4) || |
| 1786 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1787 | selected_fields |= MLX5_HASH_FIELD_SEL_DST_IP; |
| 1788 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1789 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1790 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1791 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_SPORT; |
| 1792 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1793 | if ((ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP) || |
| 1794 | (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1795 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_DPORT; |
| 1796 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 1797 | if (ucmd->rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1798 | selected_fields |= MLX5_HASH_FIELD_SEL_IPSEC_SPI; |
| 1799 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1800 | MLX5_SET(rx_hash_field_select, hfso, selected_fields, selected_fields); |
| 1801 | |
| 1802 | create_tir: |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 1803 | MLX5_SET(create_tir_in, in, opcode, MLX5_CMD_OP_CREATE_TIR); |
| 1804 | err = mlx5_cmd_exec_inout(dev->mdev, create_tir, in, out); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1805 | |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1806 | qp->rss_qp.tirn = MLX5_GET(create_tir_out, out, tirn); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1807 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1808 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1809 | |
| 1810 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1811 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1812 | to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1813 | } |
| 1814 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1815 | if (err) |
| 1816 | goto err; |
| 1817 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1818 | if (mucontext->devx_uid) { |
| 1819 | resp.comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
| 1820 | resp.tirn = qp->rss_qp.tirn; |
Ariel Levkovich | 1f1d6ab | 2019-03-31 19:44:50 +0300 | [diff] [blame] | 1821 | if (MLX5_CAP_FLOWTABLE_NIC_RX(dev->mdev, sw_owner)) { |
| 1822 | resp.tir_icm_addr = |
| 1823 | MLX5_GET(create_tir_out, out, icm_address_31_0); |
| 1824 | resp.tir_icm_addr |= (u64)MLX5_GET(create_tir_out, out, |
| 1825 | icm_address_39_32) |
| 1826 | << 32; |
| 1827 | resp.tir_icm_addr |= (u64)MLX5_GET(create_tir_out, out, |
| 1828 | icm_address_63_40) |
| 1829 | << 40; |
| 1830 | resp.comp_mask |= |
| 1831 | MLX5_IB_CREATE_QP_RESP_MASK_TIR_ICM_ADDR; |
| 1832 | } |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | err = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp))); |
| 1836 | if (err) |
| 1837 | goto err_copy; |
| 1838 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1839 | kvfree(in); |
| 1840 | /* qpn is reserved for that QP */ |
| 1841 | qp->trans_qp.base.mqp.qpn = 0; |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1842 | qp->is_rss = true; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1843 | return 0; |
| 1844 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1845 | err_copy: |
| 1846 | 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] | 1847 | err: |
| 1848 | kvfree(in); |
| 1849 | return err; |
| 1850 | } |
| 1851 | |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1852 | static void configure_requester_scat_cqe(struct mlx5_ib_dev *dev, |
| 1853 | struct ib_qp_init_attr *init_attr, |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1854 | struct mlx5_ib_create_qp *ucmd, |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1855 | void *qpc) |
| 1856 | { |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1857 | int scqe_sz; |
zhengbin | 2ab367a | 2019-12-24 16:40:12 +0800 | [diff] [blame] | 1858 | bool allow_scat_cqe = false; |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1859 | |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1860 | if (ucmd) |
| 1861 | allow_scat_cqe = ucmd->flags & MLX5_QP_FLAG_ALLOW_SCATTER_CQE; |
| 1862 | |
| 1863 | 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] | 1864 | return; |
| 1865 | |
| 1866 | scqe_sz = mlx5_ib_get_cqe_size(init_attr->send_cq); |
| 1867 | if (scqe_sz == 128) { |
| 1868 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA64_CQE); |
| 1869 | return; |
| 1870 | } |
| 1871 | |
| 1872 | if (init_attr->qp_type != MLX5_IB_QPT_DCI || |
| 1873 | MLX5_CAP_GEN(dev->mdev, dc_req_scat_data_cqe)) |
| 1874 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA32_CQE); |
| 1875 | } |
| 1876 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 1877 | static int atomic_size_to_mode(int size_mask) |
| 1878 | { |
| 1879 | /* driver does not support atomic_size > 256B |
| 1880 | * and does not know how to translate bigger sizes |
| 1881 | */ |
| 1882 | int supported_size_mask = size_mask & 0x1ff; |
| 1883 | int log_max_size; |
| 1884 | |
| 1885 | if (!supported_size_mask) |
| 1886 | return -EOPNOTSUPP; |
| 1887 | |
| 1888 | log_max_size = __fls(supported_size_mask); |
| 1889 | |
| 1890 | if (log_max_size > 3) |
| 1891 | return log_max_size; |
| 1892 | |
| 1893 | return MLX5_ATOMIC_MODE_8B; |
| 1894 | } |
| 1895 | |
| 1896 | static int get_atomic_mode(struct mlx5_ib_dev *dev, |
| 1897 | enum ib_qp_type qp_type) |
| 1898 | { |
| 1899 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
| 1900 | u8 atomic = MLX5_CAP_GEN(dev->mdev, atomic); |
| 1901 | int atomic_mode = -EOPNOTSUPP; |
| 1902 | int atomic_size_mask; |
| 1903 | |
| 1904 | if (!atomic) |
| 1905 | return -EOPNOTSUPP; |
| 1906 | |
| 1907 | if (qp_type == MLX5_IB_QPT_DCT) |
| 1908 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 1909 | else |
| 1910 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 1911 | |
| 1912 | if ((atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP) || |
| 1913 | (atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD)) |
| 1914 | atomic_mode = atomic_size_to_mode(atomic_size_mask); |
| 1915 | |
| 1916 | if (atomic_mode <= 0 && |
| 1917 | (atomic_operations & MLX5_ATOMIC_OPS_CMP_SWAP && |
| 1918 | atomic_operations & MLX5_ATOMIC_OPS_FETCH_ADD)) |
| 1919 | atomic_mode = MLX5_ATOMIC_MODE_IB_COMP; |
| 1920 | |
| 1921 | return atomic_mode; |
| 1922 | } |
| 1923 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1924 | static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 1925 | struct ib_qp_init_attr *init_attr, |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 1926 | struct mlx5_ib_create_qp *ucmd, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1927 | struct ib_udata *udata, struct mlx5_ib_qp *qp) |
| 1928 | { |
| 1929 | struct mlx5_ib_resources *devr = &dev->devr; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1930 | int inlen = MLX5_ST_SZ_BYTES(create_qp_in); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1931 | struct mlx5_core_dev *mdev = dev->mdev; |
Jason Gunthorpe | 0625b4b | 2018-08-14 15:33:52 -0600 | [diff] [blame] | 1932 | struct mlx5_ib_create_qp_resp resp = {}; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 1933 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 1934 | udata, struct mlx5_ib_ucontext, ibucontext); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 1935 | struct mlx5_ib_cq *send_cq; |
| 1936 | struct mlx5_ib_cq *recv_cq; |
| 1937 | unsigned long flags; |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1938 | u32 uidx = MLX5_IB_DEFAULT_UIDX; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1939 | struct mlx5_ib_qp_base *base; |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1940 | int mlx5_st; |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1941 | void *qpc; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1942 | u32 *in; |
| 1943 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1944 | |
| 1945 | mutex_init(&qp->mutex); |
| 1946 | spin_lock_init(&qp->sq.lock); |
| 1947 | spin_lock_init(&qp->rq.lock); |
| 1948 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 1949 | mlx5_st = to_mlx5_st(qp->type); |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1950 | if (mlx5_st < 0) |
| 1951 | return -EINVAL; |
| 1952 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1953 | if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) |
| 1954 | qp->sq_signal_bits = MLX5_WQE_CTRL_CQ_UPDATE; |
| 1955 | |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 1956 | if (udata) { |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 1957 | err = get_qp_user_index(ucontext, ucmd, udata->inlen, &uidx); |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1958 | if (err) |
| 1959 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1960 | } |
| 1961 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 1962 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
| 1963 | qp->underlay_qpn = init_attr->source_qpn; |
| 1964 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1965 | base = (init_attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 1966 | qp->flags & IB_QP_CREATE_SOURCE_QPN) ? |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1967 | &qp->raw_packet_qp.rq.base : |
| 1968 | &qp->trans_qp.base; |
| 1969 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1970 | qp->has_rq = qp_has_rq(init_attr); |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 1971 | 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] | 1972 | if (err) { |
| 1973 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1974 | return err; |
| 1975 | } |
| 1976 | |
| 1977 | if (pd) { |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 1978 | if (udata) { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1979 | __u32 max_wqes = |
| 1980 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 1981 | mlx5_ib_dbg(dev, "requested sq_wqe_count (%d)\n", |
| 1982 | ucmd->sq_wqe_count); |
| 1983 | if (ucmd->rq_wqe_shift != qp->rq.wqe_shift || |
| 1984 | ucmd->rq_wqe_count != qp->rq.wqe_cnt) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1985 | mlx5_ib_dbg(dev, "invalid rq params\n"); |
| 1986 | return -EINVAL; |
| 1987 | } |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 1988 | if (ucmd->sq_wqe_count > max_wqes) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1989 | 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] | 1990 | ucmd->sq_wqe_count, max_wqes); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1991 | return -EINVAL; |
| 1992 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1993 | err = create_user_qp(dev, pd, qp, udata, init_attr, &in, |
| 1994 | &resp, &inlen, base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1995 | if (err) |
| 1996 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1997 | } else { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 1998 | err = create_kernel_qp(dev, init_attr, qp, &in, &inlen, |
| 1999 | base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2000 | if (err) |
| 2001 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | if (err) |
| 2005 | return err; |
| 2006 | } else { |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2007 | in = kvzalloc(inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2008 | if (!in) |
| 2009 | return -ENOMEM; |
| 2010 | |
| 2011 | qp->create_type = MLX5_QP_EMPTY; |
| 2012 | } |
| 2013 | |
| 2014 | if (is_sqp(init_attr->qp_type)) |
| 2015 | qp->port = init_attr->port_num; |
| 2016 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2017 | qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); |
| 2018 | |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 2019 | MLX5_SET(qpc, qpc, st, mlx5_st); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2020 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2021 | |
| 2022 | if (init_attr->qp_type != MLX5_IB_QPT_REG_UMR) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2023 | MLX5_SET(qpc, qpc, pd, to_mpd(pd ? pd : devr->p0)->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2024 | else |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2025 | MLX5_SET(qpc, qpc, latency_sensitive, 1); |
| 2026 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2027 | |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 2028 | if (qp->flags_en & MLX5_QP_FLAG_SIGNATURE) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2029 | MLX5_SET(qpc, qpc, wq_signature, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2030 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2031 | if (qp->flags & IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2032 | MLX5_SET(qpc, qpc, block_lb_mc, 1); |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 2033 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2034 | if (qp->flags & IB_QP_CREATE_CROSS_CHANNEL) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2035 | MLX5_SET(qpc, qpc, cd_master, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2036 | if (qp->flags & IB_QP_CREATE_MANAGED_SEND) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2037 | MLX5_SET(qpc, qpc, cd_slave_send, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2038 | if (qp->flags & IB_QP_CREATE_MANAGED_RECV) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2039 | MLX5_SET(qpc, qpc, cd_slave_receive, 1); |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2040 | if (qp->flags_en & MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE) |
Danit Goldberg | 569c665 | 2018-11-30 13:22:05 +0200 | [diff] [blame] | 2041 | MLX5_SET(qpc, qpc, req_e2e_credit_mode, 1); |
Leon Romanovsky | 90ecb37 | 2020-04-27 18:46:16 +0300 | [diff] [blame] | 2042 | if ((qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) && |
| 2043 | (init_attr->qp_type == IB_QPT_RC || |
| 2044 | init_attr->qp_type == IB_QPT_UC)) { |
Leon Romanovsky | 8bde2c5 | 2020-04-27 18:46:09 +0300 | [diff] [blame] | 2045 | int rcqe_sz = rcqe_sz = |
| 2046 | mlx5_ib_get_cqe_size(init_attr->recv_cq); |
| 2047 | |
| 2048 | MLX5_SET(qpc, qpc, cs_res, |
| 2049 | rcqe_sz == 128 ? MLX5_RES_SCAT_DATA64_CQE : |
| 2050 | MLX5_RES_SCAT_DATA32_CQE); |
| 2051 | } |
Leon Romanovsky | 90ecb37 | 2020-04-27 18:46:16 +0300 | [diff] [blame] | 2052 | if ((qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) && |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2053 | (qp->type == MLX5_IB_QPT_DCI || qp->type == IB_QPT_RC)) |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2054 | configure_requester_scat_cqe(dev, init_attr, ucmd, qpc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2055 | |
| 2056 | if (qp->rq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2057 | MLX5_SET(qpc, qpc, log_rq_stride, qp->rq.wqe_shift - 4); |
| 2058 | MLX5_SET(qpc, qpc, log_rq_size, ilog2(qp->rq.wqe_cnt)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2059 | } |
| 2060 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2061 | MLX5_SET(qpc, qpc, rq_type, get_rx_type(qp, init_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2062 | |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2063 | if (qp->sq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2064 | MLX5_SET(qpc, qpc, log_sq_size, ilog2(qp->sq.wqe_cnt)); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2065 | } else { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2066 | MLX5_SET(qpc, qpc, no_sq, 1); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2067 | if (init_attr->srq && |
| 2068 | init_attr->srq->srq_type == IB_SRQT_TM) |
| 2069 | MLX5_SET(qpc, qpc, offload_type, |
| 2070 | MLX5_QPC_OFFLOAD_TYPE_RNDV); |
| 2071 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2072 | |
| 2073 | /* Set default resources */ |
| 2074 | switch (init_attr->qp_type) { |
| 2075 | case IB_QPT_XRC_TGT: |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2076 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
| 2077 | MLX5_SET(qpc, qpc, cqn_snd, to_mcq(devr->c0)->mcq.cqn); |
| 2078 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, to_msrq(devr->s0)->msrq.srqn); |
| 2079 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(init_attr->xrcd)->xrcdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2080 | break; |
| 2081 | case IB_QPT_XRC_INI: |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2082 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
| 2083 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x1)->xrcdn); |
| 2084 | 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] | 2085 | break; |
| 2086 | default: |
| 2087 | if (init_attr->srq) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2088 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x0)->xrcdn); |
| 2089 | 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] | 2090 | } else { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2091 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x1)->xrcdn); |
| 2092 | 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] | 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | if (init_attr->send_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2097 | 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] | 2098 | |
| 2099 | if (init_attr->recv_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2100 | 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] | 2101 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2102 | MLX5_SET64(qpc, qpc, dbr_addr, qp->db.dma); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2103 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2104 | /* 0xffffff means we ask to work with cqe version 0 */ |
| 2105 | if (MLX5_CAP_GEN(mdev, cqe_version) == MLX5_CQE_VERSION_V1) |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2106 | MLX5_SET(qpc, qpc, user_index, uidx); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2107 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 2108 | /* we use IB_QP_CREATE_IPOIB_UD_LSO to indicates ipoib qp */ |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2109 | if (qp->flags & IB_QP_CREATE_IPOIB_UD_LSO) |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 2110 | MLX5_SET(qpc, qpc, ulp_stateless_offload_mode, 1); |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2111 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2112 | if (qp->flags & IB_QP_CREATE_PCI_WRITE_END_PADDING && |
| 2113 | init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 2114 | MLX5_SET(qpc, qpc, end_padding_mode, |
| 2115 | MLX5_WQ_END_PAD_MODE_ALIGN); |
| 2116 | /* Special case to clean flag */ |
| 2117 | qp->flags &= ~IB_QP_CREATE_PCI_WRITE_END_PADDING; |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 2118 | } |
| 2119 | |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 2120 | if (inlen < 0) { |
| 2121 | err = -EINVAL; |
| 2122 | goto err; |
| 2123 | } |
| 2124 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2125 | if (init_attr->qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2126 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2127 | 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] | 2128 | raw_packet_qp_copy_info(qp, &qp->raw_packet_qp); |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 2129 | err = create_raw_packet_qp(dev, qp, in, inlen, pd, udata, |
| 2130 | &resp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2131 | } else { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2132 | err = mlx5_core_create_qp(dev, &base->mqp, in, inlen); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2133 | } |
| 2134 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2135 | if (err) { |
| 2136 | mlx5_ib_dbg(dev, "create qp failed\n"); |
| 2137 | goto err_create; |
| 2138 | } |
| 2139 | |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 2140 | kvfree(in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2141 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2142 | base->container_mibqp = qp; |
| 2143 | base->mqp.event = mlx5_ib_qp_event; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2144 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2145 | get_cqs(qp->type, init_attr->send_cq, init_attr->recv_cq, |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2146 | &send_cq, &recv_cq); |
| 2147 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2148 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2149 | /* Maintain device to QPs access, needed for further handling via reset |
| 2150 | * flow |
| 2151 | */ |
| 2152 | list_add_tail(&qp->qps_list, &dev->qp_list); |
| 2153 | /* Maintain CQ to QPs access, needed for further handling via reset flow |
| 2154 | */ |
| 2155 | if (send_cq) |
| 2156 | list_add_tail(&qp->cq_send_list, &send_cq->list_send_qp); |
| 2157 | if (recv_cq) |
| 2158 | list_add_tail(&qp->cq_recv_list, &recv_cq->list_recv_qp); |
| 2159 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2160 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 2161 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2162 | return 0; |
| 2163 | |
| 2164 | err_create: |
| 2165 | if (qp->create_type == MLX5_QP_USER) |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2166 | destroy_qp_user(dev, pd, qp, base, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2167 | else if (qp->create_type == MLX5_QP_KERNEL) |
| 2168 | destroy_qp_kernel(dev, qp); |
| 2169 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 2170 | err: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 2171 | kvfree(in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2172 | return err; |
| 2173 | } |
| 2174 | |
| 2175 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2176 | __acquires(&send_cq->lock) __acquires(&recv_cq->lock) |
| 2177 | { |
| 2178 | if (send_cq) { |
| 2179 | if (recv_cq) { |
| 2180 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2181 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2182 | spin_lock_nested(&recv_cq->lock, |
| 2183 | SINGLE_DEPTH_NESTING); |
| 2184 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2185 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2186 | __acquire(&recv_cq->lock); |
| 2187 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2188 | spin_lock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2189 | spin_lock_nested(&send_cq->lock, |
| 2190 | SINGLE_DEPTH_NESTING); |
| 2191 | } |
| 2192 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2193 | spin_lock(&send_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2194 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2195 | } |
| 2196 | } else if (recv_cq) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2197 | spin_lock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2198 | __acquire(&send_cq->lock); |
| 2199 | } else { |
| 2200 | __acquire(&send_cq->lock); |
| 2201 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2202 | } |
| 2203 | } |
| 2204 | |
| 2205 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2206 | __releases(&send_cq->lock) __releases(&recv_cq->lock) |
| 2207 | { |
| 2208 | if (send_cq) { |
| 2209 | if (recv_cq) { |
| 2210 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
| 2211 | spin_unlock(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2212 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2213 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
| 2214 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2215 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2216 | } else { |
| 2217 | spin_unlock(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2218 | spin_unlock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2219 | } |
| 2220 | } else { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2221 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2222 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2223 | } |
| 2224 | } else if (recv_cq) { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2225 | __release(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2226 | spin_unlock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2227 | } else { |
| 2228 | __release(&recv_cq->lock); |
| 2229 | __release(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | static struct mlx5_ib_pd *get_pd(struct mlx5_ib_qp *qp) |
| 2234 | { |
| 2235 | return to_mpd(qp->ibqp.pd); |
| 2236 | } |
| 2237 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2238 | static void get_cqs(enum ib_qp_type qp_type, |
| 2239 | struct ib_cq *ib_send_cq, struct ib_cq *ib_recv_cq, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2240 | struct mlx5_ib_cq **send_cq, struct mlx5_ib_cq **recv_cq) |
| 2241 | { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2242 | switch (qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2243 | case IB_QPT_XRC_TGT: |
| 2244 | *send_cq = NULL; |
| 2245 | *recv_cq = NULL; |
| 2246 | break; |
| 2247 | case MLX5_IB_QPT_REG_UMR: |
| 2248 | case IB_QPT_XRC_INI: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2249 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2250 | *recv_cq = NULL; |
| 2251 | break; |
| 2252 | |
| 2253 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2254 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2255 | case IB_QPT_RC: |
| 2256 | case IB_QPT_UC: |
| 2257 | case IB_QPT_UD: |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2258 | case IB_QPT_RAW_PACKET: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2259 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
| 2260 | *recv_cq = ib_recv_cq ? to_mcq(ib_recv_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2261 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2262 | default: |
| 2263 | *send_cq = NULL; |
| 2264 | *recv_cq = NULL; |
| 2265 | break; |
| 2266 | } |
| 2267 | } |
| 2268 | |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2269 | 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] | 2270 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 2271 | u8 lag_tx_affinity); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2272 | |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2273 | static void destroy_qp_common(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2274 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2275 | { |
| 2276 | struct mlx5_ib_cq *send_cq, *recv_cq; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2277 | struct mlx5_ib_qp_base *base; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2278 | unsigned long flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2279 | int err; |
| 2280 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 2281 | if (qp->ibqp.rwq_ind_tbl) { |
| 2282 | destroy_rss_raw_qp_tir(dev, qp); |
| 2283 | return; |
| 2284 | } |
| 2285 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2286 | base = (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2287 | qp->flags & IB_QP_CREATE_SOURCE_QPN) ? |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2288 | &qp->raw_packet_qp.rq.base : |
| 2289 | &qp->trans_qp.base; |
| 2290 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2291 | if (qp->state != IB_QPS_RESET) { |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2292 | if (qp->ibqp.qp_type != IB_QPT_RAW_PACKET && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2293 | !(qp->flags & IB_QP_CREATE_SOURCE_QPN)) { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2294 | err = mlx5_core_qp_modify(dev, MLX5_CMD_OP_2RST_QP, 0, |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 2295 | NULL, &base->mqp); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2296 | } else { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 2297 | struct mlx5_modify_raw_qp_param raw_qp_param = { |
| 2298 | .operation = MLX5_CMD_OP_2RST_QP |
| 2299 | }; |
| 2300 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2301 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, 0); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2302 | } |
| 2303 | if (err) |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 2304 | 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] | 2305 | base->mqp.qpn); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2306 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2307 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2308 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 2309 | &send_cq, &recv_cq); |
| 2310 | |
| 2311 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2312 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2313 | /* del from lists under both locks above to protect reset flow paths */ |
| 2314 | list_del(&qp->qps_list); |
| 2315 | if (send_cq) |
| 2316 | list_del(&qp->cq_send_list); |
| 2317 | |
| 2318 | if (recv_cq) |
| 2319 | list_del(&qp->cq_recv_list); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2320 | |
| 2321 | if (qp->create_type == MLX5_QP_KERNEL) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2322 | __mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2323 | qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL); |
| 2324 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2325 | __mlx5_ib_cq_clean(send_cq, base->mqp.qpn, |
| 2326 | NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2327 | } |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2328 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2329 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2330 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2331 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 2332 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2333 | destroy_raw_packet_qp(dev, qp); |
| 2334 | } else { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2335 | err = mlx5_core_destroy_qp(dev, &base->mqp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2336 | if (err) |
| 2337 | mlx5_ib_warn(dev, "failed to destroy QP 0x%x\n", |
| 2338 | base->mqp.qpn); |
| 2339 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2340 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2341 | if (qp->create_type == MLX5_QP_KERNEL) |
| 2342 | destroy_qp_kernel(dev, qp); |
| 2343 | else if (qp->create_type == MLX5_QP_USER) |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2344 | destroy_qp_user(dev, &get_pd(qp)->ibpd, qp, base, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2345 | } |
| 2346 | |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2347 | static int create_dct(struct ib_pd *pd, struct mlx5_ib_qp *qp, |
| 2348 | struct ib_qp_init_attr *attr, |
| 2349 | struct mlx5_ib_create_qp *ucmd, struct ib_udata *udata) |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2350 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 2351 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 2352 | udata, struct mlx5_ib_ucontext, ibucontext); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2353 | int err = 0; |
| 2354 | u32 uidx = MLX5_IB_DEFAULT_UIDX; |
| 2355 | void *dctc; |
| 2356 | |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 2357 | err = get_qp_user_index(ucontext, ucmd, sizeof(*ucmd), &uidx); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2358 | if (err) |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2359 | return err; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2360 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2361 | 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] | 2362 | if (!qp->dct.in) |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2363 | return -ENOMEM; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2364 | |
Yishai Hadas | a01a586 | 2018-09-20 21:39:24 +0300 | [diff] [blame] | 2365 | 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] | 2366 | 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] | 2367 | MLX5_SET(dctc, dctc, pd, to_mpd(pd)->pdn); |
| 2368 | MLX5_SET(dctc, dctc, srqn_xrqn, to_msrq(attr->srq)->msrq.srqn); |
| 2369 | MLX5_SET(dctc, dctc, cqn, to_mcq(attr->recv_cq)->mcq.cqn); |
| 2370 | MLX5_SET64(dctc, dctc, dc_access_key, ucmd->access_key); |
| 2371 | MLX5_SET(dctc, dctc, user_index, uidx); |
| 2372 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2373 | if (qp->flags_en & MLX5_QP_FLAG_SCATTER_CQE) { |
Leon Romanovsky | fd9dab7 | 2020-04-27 18:46:08 +0300 | [diff] [blame] | 2374 | int rcqe_sz = mlx5_ib_get_cqe_size(attr->recv_cq); |
| 2375 | |
| 2376 | if (rcqe_sz == 128) |
| 2377 | MLX5_SET(dctc, dctc, cs_res, MLX5_RES_SCAT_DATA64_CQE); |
| 2378 | } |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 2379 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2380 | qp->state = IB_QPS_RESET; |
| 2381 | |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2382 | return 0; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2383 | } |
| 2384 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2385 | static int check_qp_type(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr, |
| 2386 | enum ib_qp_type *type) |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2387 | { |
| 2388 | if (attr->qp_type == IB_QPT_DRIVER && !MLX5_CAP_GEN(dev->mdev, dct)) |
| 2389 | goto out; |
| 2390 | |
| 2391 | switch (attr->qp_type) { |
| 2392 | case IB_QPT_XRC_TGT: |
| 2393 | case IB_QPT_XRC_INI: |
| 2394 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
| 2395 | goto out; |
| 2396 | fallthrough; |
| 2397 | case IB_QPT_RAW_PACKET: |
| 2398 | case IB_QPT_RC: |
| 2399 | case IB_QPT_UC: |
| 2400 | case IB_QPT_UD: |
| 2401 | case IB_QPT_SMI: |
| 2402 | case MLX5_IB_QPT_HW_GSI: |
| 2403 | case MLX5_IB_QPT_REG_UMR: |
| 2404 | case IB_QPT_DRIVER: |
| 2405 | case IB_QPT_GSI: |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2406 | break; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2407 | default: |
| 2408 | goto out; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2409 | } |
| 2410 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2411 | *type = attr->qp_type; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2412 | return 0; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2413 | |
| 2414 | out: |
| 2415 | mlx5_ib_dbg(dev, "Unsupported QP type %d\n", attr->qp_type); |
| 2416 | return -EOPNOTSUPP; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2417 | } |
| 2418 | |
Leon Romanovsky | 2242cc2 | 2020-04-27 18:46:03 +0300 | [diff] [blame] | 2419 | static int check_valid_flow(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 2420 | struct ib_qp_init_attr *attr, |
| 2421 | struct ib_udata *udata) |
| 2422 | { |
| 2423 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 2424 | udata, struct mlx5_ib_ucontext, ibucontext); |
| 2425 | |
| 2426 | if (!udata) { |
| 2427 | /* Kernel create_qp callers */ |
| 2428 | if (attr->rwq_ind_tbl) |
| 2429 | return -EOPNOTSUPP; |
| 2430 | |
| 2431 | switch (attr->qp_type) { |
| 2432 | case IB_QPT_RAW_PACKET: |
| 2433 | case IB_QPT_DRIVER: |
| 2434 | return -EOPNOTSUPP; |
| 2435 | default: |
| 2436 | return 0; |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | /* Userspace create_qp callers */ |
| 2441 | if (attr->qp_type == IB_QPT_RAW_PACKET && !ucontext->cqe_version) { |
| 2442 | mlx5_ib_dbg(dev, |
| 2443 | "Raw Packet QP is only supported for CQE version > 0\n"); |
| 2444 | return -EINVAL; |
| 2445 | } |
| 2446 | |
| 2447 | if (attr->qp_type != IB_QPT_RAW_PACKET && attr->rwq_ind_tbl) { |
| 2448 | mlx5_ib_dbg(dev, |
| 2449 | "Wrong QP type %d for the RWQ indirect table\n", |
| 2450 | attr->qp_type); |
| 2451 | return -EINVAL; |
| 2452 | } |
| 2453 | |
| 2454 | switch (attr->qp_type) { |
| 2455 | case IB_QPT_SMI: |
| 2456 | case MLX5_IB_QPT_HW_GSI: |
| 2457 | case MLX5_IB_QPT_REG_UMR: |
| 2458 | case IB_QPT_GSI: |
| 2459 | mlx5_ib_dbg(dev, "Kernel doesn't support QP type %d\n", |
| 2460 | attr->qp_type); |
| 2461 | return -EINVAL; |
| 2462 | default: |
| 2463 | break; |
| 2464 | } |
| 2465 | |
| 2466 | /* |
| 2467 | * We don't need to see this warning, it means that kernel code |
| 2468 | * missing ib_pd. Placed here to catch developer's mistakes. |
| 2469 | */ |
| 2470 | WARN_ONCE(!pd && attr->qp_type != IB_QPT_XRC_TGT, |
| 2471 | "There is a missing PD pointer assignment\n"); |
| 2472 | return 0; |
| 2473 | } |
| 2474 | |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2475 | static void process_vendor_flag(struct mlx5_ib_dev *dev, int *flags, int flag, |
| 2476 | bool cond, struct mlx5_ib_qp *qp) |
| 2477 | { |
| 2478 | if (!(*flags & flag)) |
| 2479 | return; |
| 2480 | |
| 2481 | if (cond) { |
| 2482 | qp->flags_en |= flag; |
| 2483 | *flags &= ~flag; |
| 2484 | return; |
| 2485 | } |
| 2486 | |
| 2487 | if (flag == MLX5_QP_FLAG_SCATTER_CQE) { |
| 2488 | /* |
| 2489 | * We don't return error if this flag was provided, |
| 2490 | * and mlx5 doesn't have right capability. |
| 2491 | */ |
| 2492 | *flags &= ~MLX5_QP_FLAG_SCATTER_CQE; |
| 2493 | return; |
| 2494 | } |
| 2495 | mlx5_ib_dbg(dev, "Vendor create QP flag 0x%X is not supported\n", flag); |
| 2496 | } |
| 2497 | |
| 2498 | static int process_vendor_flags(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2499 | void *ucmd, struct ib_qp_init_attr *attr) |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2500 | { |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2501 | struct mlx5_core_dev *mdev = dev->mdev; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2502 | bool cond; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2503 | int flags; |
| 2504 | |
| 2505 | if (attr->rwq_ind_tbl) |
| 2506 | flags = ((struct mlx5_ib_create_qp_rss *)ucmd)->flags; |
| 2507 | else |
| 2508 | flags = ((struct mlx5_ib_create_qp *)ucmd)->flags; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2509 | |
| 2510 | switch (flags & (MLX5_QP_FLAG_TYPE_DCT | MLX5_QP_FLAG_TYPE_DCI)) { |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2511 | case MLX5_QP_FLAG_TYPE_DCI: |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2512 | qp->type = MLX5_IB_QPT_DCI; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2513 | break; |
| 2514 | case MLX5_QP_FLAG_TYPE_DCT: |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2515 | qp->type = MLX5_IB_QPT_DCT; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2516 | break; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2517 | default: |
| 2518 | if (qp->type != IB_QPT_DRIVER) |
| 2519 | break; |
| 2520 | /* |
| 2521 | * It is IB_QPT_DRIVER and or no subtype or |
| 2522 | * wrong subtype were provided. |
| 2523 | */ |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2524 | return -EINVAL; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2525 | } |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2526 | |
| 2527 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_TYPE_DCI, true, qp); |
| 2528 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_TYPE_DCT, true, qp); |
| 2529 | |
| 2530 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_SIGNATURE, true, qp); |
| 2531 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_SCATTER_CQE, |
| 2532 | MLX5_CAP_GEN(mdev, sctr_data_cqe), qp); |
| 2533 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2534 | if (qp->type == IB_QPT_RAW_PACKET) { |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2535 | cond = MLX5_CAP_ETH(mdev, tunnel_stateless_vxlan) || |
| 2536 | MLX5_CAP_ETH(mdev, tunnel_stateless_gre) || |
| 2537 | MLX5_CAP_ETH(mdev, tunnel_stateless_geneve_rx); |
| 2538 | process_vendor_flag(dev, &flags, MLX5_QP_FLAG_TUNNEL_OFFLOADS, |
| 2539 | cond, qp); |
| 2540 | process_vendor_flag(dev, &flags, |
| 2541 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC, true, |
| 2542 | qp); |
| 2543 | process_vendor_flag(dev, &flags, |
| 2544 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC, true, |
| 2545 | qp); |
| 2546 | } |
| 2547 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2548 | if (qp->type == IB_QPT_RC) |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2549 | process_vendor_flag(dev, &flags, |
| 2550 | MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE, |
| 2551 | MLX5_CAP_GEN(mdev, qp_packet_based), qp); |
| 2552 | |
| 2553 | if (flags) |
| 2554 | mlx5_ib_dbg(dev, "udata has unsupported flags 0x%X\n", flags); |
| 2555 | |
| 2556 | return (flags) ? -EINVAL : 0; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2557 | } |
| 2558 | |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2559 | static void process_create_flag(struct mlx5_ib_dev *dev, int *flags, int flag, |
| 2560 | bool cond, struct mlx5_ib_qp *qp) |
| 2561 | { |
| 2562 | if (!(*flags & flag)) |
| 2563 | return; |
| 2564 | |
| 2565 | if (cond) { |
| 2566 | qp->flags |= flag; |
| 2567 | *flags &= ~flag; |
| 2568 | return; |
| 2569 | } |
| 2570 | |
| 2571 | if (flag == MLX5_IB_QP_CREATE_WC_TEST) { |
| 2572 | /* |
| 2573 | * Special case, if condition didn't meet, it won't be error, |
| 2574 | * just different in-kernel flow. |
| 2575 | */ |
| 2576 | *flags &= ~MLX5_IB_QP_CREATE_WC_TEST; |
| 2577 | return; |
| 2578 | } |
| 2579 | mlx5_ib_dbg(dev, "Verbs create QP flag 0x%X is not supported\n", flag); |
| 2580 | } |
| 2581 | |
| 2582 | static int process_create_flags(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2583 | struct ib_qp_init_attr *attr) |
| 2584 | { |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2585 | enum ib_qp_type qp_type = qp->type; |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2586 | struct mlx5_core_dev *mdev = dev->mdev; |
| 2587 | int create_flags = attr->create_flags; |
| 2588 | bool cond; |
| 2589 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2590 | if (qp_type == MLX5_IB_QPT_DCT) |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2591 | return (create_flags) ? -EINVAL : 0; |
| 2592 | |
| 2593 | if (qp_type == IB_QPT_RAW_PACKET && attr->rwq_ind_tbl) |
| 2594 | return (create_flags) ? -EINVAL : 0; |
| 2595 | |
| 2596 | process_create_flag(dev, &create_flags, |
| 2597 | IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK, |
| 2598 | MLX5_CAP_GEN(mdev, block_lb_mc), qp); |
| 2599 | process_create_flag(dev, &create_flags, IB_QP_CREATE_CROSS_CHANNEL, |
| 2600 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2601 | process_create_flag(dev, &create_flags, IB_QP_CREATE_MANAGED_SEND, |
| 2602 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2603 | process_create_flag(dev, &create_flags, IB_QP_CREATE_MANAGED_RECV, |
| 2604 | MLX5_CAP_GEN(mdev, cd), qp); |
| 2605 | |
| 2606 | if (qp_type == IB_QPT_UD) { |
| 2607 | process_create_flag(dev, &create_flags, |
| 2608 | IB_QP_CREATE_IPOIB_UD_LSO, |
| 2609 | MLX5_CAP_GEN(mdev, ipoib_basic_offloads), |
| 2610 | qp); |
| 2611 | cond = MLX5_CAP_GEN(mdev, port_type) == MLX5_CAP_PORT_TYPE_IB; |
| 2612 | process_create_flag(dev, &create_flags, IB_QP_CREATE_SOURCE_QPN, |
| 2613 | cond, qp); |
| 2614 | } |
| 2615 | |
| 2616 | if (qp_type == IB_QPT_RAW_PACKET) { |
| 2617 | cond = MLX5_CAP_GEN(mdev, eth_net_offloads) && |
| 2618 | MLX5_CAP_ETH(mdev, scatter_fcs); |
| 2619 | process_create_flag(dev, &create_flags, |
| 2620 | IB_QP_CREATE_SCATTER_FCS, cond, qp); |
| 2621 | |
| 2622 | cond = MLX5_CAP_GEN(mdev, eth_net_offloads) && |
| 2623 | MLX5_CAP_ETH(mdev, vlan_cap); |
| 2624 | process_create_flag(dev, &create_flags, |
| 2625 | IB_QP_CREATE_CVLAN_STRIPPING, cond, qp); |
| 2626 | } |
| 2627 | |
| 2628 | process_create_flag(dev, &create_flags, |
| 2629 | IB_QP_CREATE_PCI_WRITE_END_PADDING, |
| 2630 | MLX5_CAP_GEN(mdev, end_pad), qp); |
| 2631 | |
| 2632 | process_create_flag(dev, &create_flags, MLX5_IB_QP_CREATE_WC_TEST, |
| 2633 | qp_type != MLX5_IB_QPT_REG_UMR, qp); |
| 2634 | process_create_flag(dev, &create_flags, MLX5_IB_QP_CREATE_SQPN_QP1, |
| 2635 | true, qp); |
| 2636 | |
| 2637 | if (create_flags) |
| 2638 | mlx5_ib_dbg(dev, "Create QP has unsupported flags 0x%X\n", |
| 2639 | create_flags); |
| 2640 | |
| 2641 | return (create_flags) ? -EINVAL : 0; |
| 2642 | } |
| 2643 | |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2644 | static size_t process_udata_size(struct ib_qp_init_attr *attr, |
| 2645 | struct ib_udata *udata) |
| 2646 | { |
| 2647 | size_t ucmd = sizeof(struct mlx5_ib_create_qp); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2648 | size_t inlen = udata->inlen; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2649 | |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2650 | if (attr->qp_type == IB_QPT_DRIVER) |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2651 | return (inlen < ucmd) ? 0 : ucmd; |
Leon Romanovsky | 2dfac92 | 2020-04-27 18:46:11 +0300 | [diff] [blame] | 2652 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2653 | if (!attr->rwq_ind_tbl) |
| 2654 | return ucmd; |
| 2655 | |
| 2656 | if (inlen < offsetofend(struct mlx5_ib_create_qp_rss, flags)) |
| 2657 | return 0; |
| 2658 | |
| 2659 | ucmd = sizeof(struct mlx5_ib_create_qp_rss); |
| 2660 | if (inlen > ucmd && !ib_is_udata_cleared(udata, ucmd, inlen - ucmd)) |
| 2661 | return 0; |
| 2662 | |
| 2663 | return min(ucmd, inlen); |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2664 | } |
| 2665 | |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2666 | static int create_raw_qp(struct ib_pd *pd, struct mlx5_ib_qp *qp, |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2667 | struct ib_qp_init_attr *attr, void *ucmd, |
| 2668 | struct ib_udata *udata) |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2669 | { |
| 2670 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
| 2671 | |
| 2672 | if (attr->rwq_ind_tbl) |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2673 | return create_rss_raw_qp_tir(pd, qp, attr, ucmd, udata); |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2674 | |
| 2675 | return create_qp_common(dev, pd, attr, ucmd, udata, qp); |
| 2676 | } |
| 2677 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2678 | static int check_qp_attr(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 2679 | struct ib_qp_init_attr *attr) |
| 2680 | { |
| 2681 | int ret = 0; |
| 2682 | |
| 2683 | switch (qp->type) { |
| 2684 | case MLX5_IB_QPT_DCT: |
| 2685 | ret = (!attr->srq || !attr->recv_cq) ? -EINVAL : 0; |
| 2686 | break; |
| 2687 | case MLX5_IB_QPT_DCI: |
| 2688 | ret = (attr->cap.max_recv_wr || attr->cap.max_recv_sge) ? |
| 2689 | -EINVAL : |
| 2690 | 0; |
| 2691 | break; |
Leon Romanovsky | 266424e | 2020-04-27 18:46:21 +0300 | [diff] [blame] | 2692 | case IB_QPT_RAW_PACKET: |
| 2693 | ret = (attr->rwq_ind_tbl && attr->send_cq) ? -EINVAL : 0; |
| 2694 | break; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2695 | default: |
| 2696 | break; |
| 2697 | } |
| 2698 | |
| 2699 | if (ret) |
| 2700 | mlx5_ib_dbg(dev, "QP type %d has wrong attributes\n", qp->type); |
| 2701 | |
| 2702 | return ret; |
| 2703 | } |
| 2704 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2705 | struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd, |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2706 | struct ib_qp_init_attr *init_attr, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2707 | struct ib_udata *udata) |
| 2708 | { |
| 2709 | struct mlx5_ib_dev *dev; |
| 2710 | struct mlx5_ib_qp *qp; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2711 | enum ib_qp_type type; |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2712 | void *ucmd = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2713 | u16 xrcdn = 0; |
| 2714 | int err; |
| 2715 | |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2716 | dev = pd ? to_mdev(pd->device) : |
| 2717 | to_mdev(to_mxrcd(init_attr->xrcd)->ibxrcd.device); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2718 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2719 | err = check_qp_type(dev, init_attr, &type); |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2720 | if (err) { |
| 2721 | mlx5_ib_dbg(dev, "Unsupported QP type %d\n", |
| 2722 | init_attr->qp_type); |
| 2723 | return ERR_PTR(err); |
| 2724 | } |
| 2725 | |
Leon Romanovsky | 2242cc2 | 2020-04-27 18:46:03 +0300 | [diff] [blame] | 2726 | err = check_valid_flow(dev, pd, init_attr, udata); |
| 2727 | if (err) |
| 2728 | return ERR_PTR(err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2729 | |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2730 | if (init_attr->qp_type == IB_QPT_GSI) |
| 2731 | return mlx5_ib_gsi_create_qp(pd, init_attr); |
| 2732 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2733 | if (udata) { |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2734 | size_t inlen = |
| 2735 | process_udata_size(init_attr, udata); |
| 2736 | |
| 2737 | if (!inlen) |
| 2738 | return ERR_PTR(-EINVAL); |
| 2739 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2740 | ucmd = kzalloc(inlen, GFP_KERNEL); |
| 2741 | if (!ucmd) |
| 2742 | return ERR_PTR(-ENOMEM); |
| 2743 | |
| 2744 | err = ib_copy_from_udata(ucmd, udata, inlen); |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2745 | if (err) |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2746 | goto free_ucmd; |
Leon Romanovsky | 2fdddbd | 2020-04-27 18:46:10 +0300 | [diff] [blame] | 2747 | } |
| 2748 | |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2749 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2750 | if (!qp) { |
| 2751 | err = -ENOMEM; |
| 2752 | goto free_ucmd; |
| 2753 | } |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2754 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2755 | qp->type = type; |
Leon Romanovsky | 37518fa | 2020-04-27 18:46:18 +0300 | [diff] [blame] | 2756 | if (udata) { |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2757 | err = process_vendor_flags(dev, qp, ucmd, init_attr); |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2758 | if (err) |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2759 | goto free_qp; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2760 | } |
Leon Romanovsky | 2978975 | 2020-04-27 18:46:14 +0300 | [diff] [blame] | 2761 | err = process_create_flags(dev, qp, init_attr); |
| 2762 | if (err) |
| 2763 | goto free_qp; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2764 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2765 | if (qp->type == IB_QPT_XRC_TGT) |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2766 | xrcdn = to_mxrcd(init_attr->xrcd)->xrcdn; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2767 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2768 | err = check_qp_attr(dev, qp, init_attr); |
| 2769 | if (err) |
| 2770 | goto free_qp; |
| 2771 | |
| 2772 | switch (qp->type) { |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2773 | case IB_QPT_RAW_PACKET: |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2774 | err = create_raw_qp(pd, qp, init_attr, ucmd, udata); |
Leon Romanovsky | 5d0dc3d | 2020-04-27 18:46:12 +0300 | [diff] [blame] | 2775 | break; |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2776 | case MLX5_IB_QPT_DCT: |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2777 | err = create_dct(pd, qp, init_attr, ucmd, udata); |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2778 | break; |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2779 | default: |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2780 | err = create_qp_common(dev, pd, init_attr, ucmd, udata, qp); |
Leon Romanovsky | 47c8061 | 2020-04-27 18:46:07 +0300 | [diff] [blame] | 2781 | } |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2782 | if (err) { |
| 2783 | mlx5_ib_dbg(dev, "create_qp_common failed\n"); |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2784 | goto free_qp; |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2785 | } |
| 2786 | |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2787 | kfree(ucmd); |
| 2788 | |
Leon Romanovsky | 6eb7edf | 2020-04-27 18:46:01 +0300 | [diff] [blame] | 2789 | if (is_qp0(init_attr->qp_type)) |
| 2790 | qp->ibqp.qp_num = 0; |
| 2791 | else if (is_qp1(init_attr->qp_type)) |
| 2792 | qp->ibqp.qp_num = 1; |
| 2793 | else |
| 2794 | qp->ibqp.qp_num = qp->trans_qp.base.mqp.qpn; |
| 2795 | |
| 2796 | qp->trans_qp.xrcdn = xrcdn; |
| 2797 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2798 | return &qp->ibqp; |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2799 | |
| 2800 | free_qp: |
| 2801 | kfree(qp); |
Leon Romanovsky | 5ce0592 | 2020-04-27 18:46:22 +0300 | [diff] [blame^] | 2802 | free_ucmd: |
| 2803 | kfree(ucmd); |
Leon Romanovsky | 9c2ba4e | 2020-04-27 18:46:04 +0300 | [diff] [blame] | 2804 | return ERR_PTR(err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2805 | } |
| 2806 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2807 | static int mlx5_ib_destroy_dct(struct mlx5_ib_qp *mqp) |
| 2808 | { |
| 2809 | struct mlx5_ib_dev *dev = to_mdev(mqp->ibqp.device); |
| 2810 | |
| 2811 | if (mqp->state == IB_QPS_RTR) { |
| 2812 | int err; |
| 2813 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 2814 | err = mlx5_core_destroy_dct(dev, &mqp->dct.mdct); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2815 | if (err) { |
| 2816 | mlx5_ib_warn(dev, "failed to destroy DCT %d\n", err); |
| 2817 | return err; |
| 2818 | } |
| 2819 | } |
| 2820 | |
| 2821 | kfree(mqp->dct.in); |
| 2822 | kfree(mqp); |
| 2823 | return 0; |
| 2824 | } |
| 2825 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 2826 | 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] | 2827 | { |
| 2828 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 2829 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 2830 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2831 | if (unlikely(qp->qp_type == IB_QPT_GSI)) |
| 2832 | return mlx5_ib_gsi_destroy_qp(qp); |
| 2833 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 2834 | if (mqp->type == MLX5_IB_QPT_DCT) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2835 | return mlx5_ib_destroy_dct(mqp); |
| 2836 | |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 2837 | destroy_qp_common(dev, mqp, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2838 | |
| 2839 | kfree(mqp); |
| 2840 | |
| 2841 | return 0; |
| 2842 | } |
| 2843 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2844 | static int to_mlx5_access_flags(struct mlx5_ib_qp *qp, |
| 2845 | const struct ib_qp_attr *attr, |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2846 | int attr_mask, __be32 *hw_access_flags_be) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2847 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2848 | u8 dest_rd_atomic; |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2849 | u32 access_flags, hw_access_flags = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2850 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2851 | struct mlx5_ib_dev *dev = to_mdev(qp->ibqp.device); |
| 2852 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2853 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
| 2854 | dest_rd_atomic = attr->max_dest_rd_atomic; |
| 2855 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2856 | dest_rd_atomic = qp->trans_qp.resp_depth; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2857 | |
| 2858 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
| 2859 | access_flags = attr->qp_access_flags; |
| 2860 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2861 | access_flags = qp->trans_qp.atomic_rd_en; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2862 | |
| 2863 | if (!dest_rd_atomic) |
| 2864 | access_flags &= IB_ACCESS_REMOTE_WRITE; |
| 2865 | |
| 2866 | if (access_flags & IB_ACCESS_REMOTE_READ) |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2867 | hw_access_flags |= MLX5_QP_BIT_RRE; |
Yonatan Cohen | 13f8d9c | 2018-11-21 13:48:39 +0200 | [diff] [blame] | 2868 | if (access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2869 | int atomic_mode; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2870 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2871 | atomic_mode = get_atomic_mode(dev, qp->ibqp.qp_type); |
| 2872 | if (atomic_mode < 0) |
| 2873 | return -EOPNOTSUPP; |
| 2874 | |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2875 | hw_access_flags |= MLX5_QP_BIT_RAE; |
| 2876 | hw_access_flags |= atomic_mode << MLX5_ATOMIC_MODE_OFFSET; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2877 | } |
| 2878 | |
| 2879 | if (access_flags & IB_ACCESS_REMOTE_WRITE) |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2880 | hw_access_flags |= MLX5_QP_BIT_RWE; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2881 | |
Bart Van Assche | bf3b4f0 | 2019-01-30 16:30:51 -0800 | [diff] [blame] | 2882 | *hw_access_flags_be = cpu_to_be32(hw_access_flags); |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2883 | |
| 2884 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | enum { |
| 2888 | MLX5_PATH_FLAG_FL = 1 << 0, |
| 2889 | MLX5_PATH_FLAG_FREE_AR = 1 << 1, |
| 2890 | MLX5_PATH_FLAG_COUNTER = 1 << 2, |
| 2891 | }; |
| 2892 | |
| 2893 | static int ib_rate_to_mlx5(struct mlx5_ib_dev *dev, u8 rate) |
| 2894 | { |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 2895 | if (rate == IB_RATE_PORT_CURRENT) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2896 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2897 | |
Michael Guralnik | a5a5d19 | 2018-12-09 11:49:50 +0200 | [diff] [blame] | 2898 | if (rate < IB_RATE_2_5_GBPS || rate > IB_RATE_600_GBPS) |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 2899 | return -EINVAL; |
| 2900 | |
| 2901 | while (rate != IB_RATE_PORT_CURRENT && |
| 2902 | !(1 << (rate + MLX5_STAT_RATE_OFFSET) & |
| 2903 | MLX5_CAP_GEN(dev->mdev, stat_rate_support))) |
| 2904 | --rate; |
| 2905 | |
| 2906 | return rate ? rate + MLX5_STAT_RATE_OFFSET : rate; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2907 | } |
| 2908 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2909 | static int modify_raw_packet_eth_prio(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2910 | struct mlx5_ib_sq *sq, u8 sl, |
| 2911 | struct ib_pd *pd) |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2912 | { |
| 2913 | void *in; |
| 2914 | void *tisc; |
| 2915 | int inlen; |
| 2916 | int err; |
| 2917 | |
| 2918 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2919 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2920 | if (!in) |
| 2921 | return -ENOMEM; |
| 2922 | |
| 2923 | MLX5_SET(modify_tis_in, in, bitmask.prio, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2924 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2925 | |
| 2926 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 2927 | MLX5_SET(tisc, tisc, prio, ((sl & 0x7) << 1)); |
| 2928 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 2929 | err = mlx5_core_modify_tis(dev, sq->tisn, in); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2930 | |
| 2931 | kvfree(in); |
| 2932 | |
| 2933 | return err; |
| 2934 | } |
| 2935 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2936 | static int modify_raw_packet_tx_affinity(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2937 | struct mlx5_ib_sq *sq, u8 tx_affinity, |
| 2938 | struct ib_pd *pd) |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2939 | { |
| 2940 | void *in; |
| 2941 | void *tisc; |
| 2942 | int inlen; |
| 2943 | int err; |
| 2944 | |
| 2945 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2946 | in = kvzalloc(inlen, GFP_KERNEL); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2947 | if (!in) |
| 2948 | return -ENOMEM; |
| 2949 | |
| 2950 | MLX5_SET(modify_tis_in, in, bitmask.lag_tx_port_affinity, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2951 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2952 | |
| 2953 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 2954 | MLX5_SET(tisc, tisc, lag_tx_port_affinity, tx_affinity); |
| 2955 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 2956 | err = mlx5_core_modify_tis(dev, sq->tisn, in); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2957 | |
| 2958 | kvfree(in); |
| 2959 | |
| 2960 | return err; |
| 2961 | } |
| 2962 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2963 | 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] | 2964 | const struct rdma_ah_attr *ah, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2965 | struct mlx5_qp_path *path, u8 port, int attr_mask, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 2966 | u32 path_flags, const struct ib_qp_attr *attr, |
| 2967 | bool alt) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2968 | { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2969 | const struct ib_global_route *grh = rdma_ah_read_grh(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2970 | int err; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 2971 | enum ib_gid_type gid_type; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2972 | u8 ah_flags = rdma_ah_get_ah_flags(ah); |
| 2973 | u8 sl = rdma_ah_get_sl(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2974 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2975 | if (attr_mask & IB_QP_PKEY_INDEX) |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 2976 | path->pkey_index = cpu_to_be16(alt ? attr->alt_pkey_index : |
| 2977 | attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2978 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2979 | if (ah_flags & IB_AH_GRH) { |
| 2980 | if (grh->sgid_index >= |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2981 | dev->mdev->port_caps[port - 1].gid_table_len) { |
Joe Perches | f4f01b5 | 2015-05-08 15:58:07 -0700 | [diff] [blame] | 2982 | pr_err("sgid_index (%u) too large. max is %d\n", |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2983 | grh->sgid_index, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2984 | dev->mdev->port_caps[port - 1].gid_table_len); |
Eli Cohen | f83b426 | 2014-09-14 16:47:54 +0300 | [diff] [blame] | 2985 | return -EINVAL; |
| 2986 | } |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 2987 | } |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 2988 | |
| 2989 | if (ah->type == RDMA_AH_ATTR_TYPE_ROCE) { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2990 | if (!(ah_flags & IB_AH_GRH)) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 2991 | return -EINVAL; |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 2992 | |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 2993 | memcpy(path->rmac, ah->roce.dmac, sizeof(ah->roce.dmac)); |
Majd Dibbiny | 2b62185 | 2017-10-30 14:23:14 +0200 | [diff] [blame] | 2994 | if (qp->ibqp.qp_type == IB_QPT_RC || |
| 2995 | qp->ibqp.qp_type == IB_QPT_UC || |
| 2996 | qp->ibqp.qp_type == IB_QPT_XRC_INI || |
| 2997 | qp->ibqp.qp_type == IB_QPT_XRC_TGT) |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 2998 | path->udp_sport = |
| 2999 | mlx5_get_roce_udp_sport(dev, ah->grh.sgid_attr); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3000 | path->dci_cfi_prio_sl = (sl & 0x7) << 4; |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 3001 | gid_type = ah->grh.sgid_attr->gid_type; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 3002 | if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3003 | path->ecn_dscp = (grh->traffic_class >> 2) & 0x3f; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3004 | } else { |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 3005 | path->fl_free_ar = (path_flags & MLX5_PATH_FLAG_FL) ? 0x80 : 0; |
| 3006 | path->fl_free_ar |= |
| 3007 | (path_flags & MLX5_PATH_FLAG_FREE_AR) ? 0x40 : 0; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3008 | path->rlid = cpu_to_be16(rdma_ah_get_dlid(ah)); |
| 3009 | path->grh_mlid = rdma_ah_get_path_bits(ah) & 0x7f; |
| 3010 | if (ah_flags & IB_AH_GRH) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3011 | path->grh_mlid |= 1 << 7; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3012 | path->dci_cfi_prio_sl = sl & 0xf; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3013 | } |
| 3014 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3015 | if (ah_flags & IB_AH_GRH) { |
| 3016 | path->mgid_index = grh->sgid_index; |
| 3017 | path->hop_limit = grh->hop_limit; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3018 | path->tclass_flowlabel = |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3019 | cpu_to_be32((grh->traffic_class << 20) | |
| 3020 | (grh->flow_label)); |
| 3021 | memcpy(path->rgid, grh->dgid.raw, 16); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3022 | } |
| 3023 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 3024 | err = ib_rate_to_mlx5(dev, rdma_ah_get_static_rate(ah)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3025 | if (err < 0) |
| 3026 | return err; |
| 3027 | path->static_rate = err; |
| 3028 | path->port = port; |
| 3029 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3030 | if (attr_mask & IB_QP_TIMEOUT) |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3031 | path->ackto_lt = (alt ? attr->alt_timeout : attr->timeout) << 3; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3032 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3033 | if ((qp->ibqp.qp_type == IB_QPT_RAW_PACKET) && qp->sq.wqe_cnt) |
| 3034 | return modify_raw_packet_eth_prio(dev->mdev, |
| 3035 | &qp->raw_packet_qp.sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3036 | sl & 0xf, qp->ibqp.pd); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3037 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3038 | return 0; |
| 3039 | } |
| 3040 | |
| 3041 | static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_QP_ST_MAX] = { |
| 3042 | [MLX5_QP_STATE_INIT] = { |
| 3043 | [MLX5_QP_STATE_INIT] = { |
| 3044 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 3045 | MLX5_QP_OPTPAR_RAE | |
| 3046 | MLX5_QP_OPTPAR_RWE | |
| 3047 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3048 | MLX5_QP_OPTPAR_PRI_PORT, |
| 3049 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
| 3050 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3051 | MLX5_QP_OPTPAR_PRI_PORT, |
| 3052 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3053 | MLX5_QP_OPTPAR_Q_KEY | |
| 3054 | MLX5_QP_OPTPAR_PRI_PORT, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3055 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RRE | |
| 3056 | MLX5_QP_OPTPAR_RAE | |
| 3057 | MLX5_QP_OPTPAR_RWE | |
| 3058 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3059 | MLX5_QP_OPTPAR_PRI_PORT, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3060 | }, |
| 3061 | [MLX5_QP_STATE_RTR] = { |
| 3062 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3063 | MLX5_QP_OPTPAR_RRE | |
| 3064 | MLX5_QP_OPTPAR_RAE | |
| 3065 | MLX5_QP_OPTPAR_RWE | |
| 3066 | MLX5_QP_OPTPAR_PKEY_INDEX, |
| 3067 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3068 | MLX5_QP_OPTPAR_RWE | |
| 3069 | MLX5_QP_OPTPAR_PKEY_INDEX, |
| 3070 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3071 | MLX5_QP_OPTPAR_Q_KEY, |
| 3072 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 3073 | MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 3074 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3075 | MLX5_QP_OPTPAR_RRE | |
| 3076 | MLX5_QP_OPTPAR_RAE | |
| 3077 | MLX5_QP_OPTPAR_RWE | |
| 3078 | MLX5_QP_OPTPAR_PKEY_INDEX, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3079 | }, |
| 3080 | }, |
| 3081 | [MLX5_QP_STATE_RTR] = { |
| 3082 | [MLX5_QP_STATE_RTS] = { |
| 3083 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3084 | MLX5_QP_OPTPAR_RRE | |
| 3085 | MLX5_QP_OPTPAR_RAE | |
| 3086 | MLX5_QP_OPTPAR_RWE | |
| 3087 | MLX5_QP_OPTPAR_PM_STATE | |
| 3088 | MLX5_QP_OPTPAR_RNR_TIMEOUT, |
| 3089 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3090 | MLX5_QP_OPTPAR_RWE | |
| 3091 | MLX5_QP_OPTPAR_PM_STATE, |
| 3092 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3093 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 3094 | MLX5_QP_OPTPAR_RRE | |
| 3095 | MLX5_QP_OPTPAR_RAE | |
| 3096 | MLX5_QP_OPTPAR_RWE | |
| 3097 | MLX5_QP_OPTPAR_PM_STATE | |
| 3098 | MLX5_QP_OPTPAR_RNR_TIMEOUT, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3099 | }, |
| 3100 | }, |
| 3101 | [MLX5_QP_STATE_RTS] = { |
| 3102 | [MLX5_QP_STATE_RTS] = { |
| 3103 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 3104 | MLX5_QP_OPTPAR_RAE | |
| 3105 | MLX5_QP_OPTPAR_RWE | |
| 3106 | MLX5_QP_OPTPAR_RNR_TIMEOUT | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 3107 | MLX5_QP_OPTPAR_PM_STATE | |
| 3108 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3109 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 3110 | MLX5_QP_OPTPAR_PM_STATE | |
| 3111 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3112 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY | |
| 3113 | MLX5_QP_OPTPAR_SRQN | |
| 3114 | MLX5_QP_OPTPAR_CQN_RCV, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3115 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RRE | |
| 3116 | MLX5_QP_OPTPAR_RAE | |
| 3117 | MLX5_QP_OPTPAR_RWE | |
| 3118 | MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3119 | MLX5_QP_OPTPAR_PM_STATE | |
| 3120 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3121 | }, |
| 3122 | }, |
| 3123 | [MLX5_QP_STATE_SQER] = { |
| 3124 | [MLX5_QP_STATE_RTS] = { |
| 3125 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
| 3126 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | 75959f5 | 2013-09-11 16:35:31 +0300 | [diff] [blame] | 3127 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 3128 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3129 | MLX5_QP_OPTPAR_RWE | |
| 3130 | MLX5_QP_OPTPAR_RAE | |
| 3131 | MLX5_QP_OPTPAR_RRE, |
Jack Morgenstein | 8f4426a | 2019-05-01 08:38:30 +0300 | [diff] [blame] | 3132 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 3133 | MLX5_QP_OPTPAR_RWE | |
| 3134 | MLX5_QP_OPTPAR_RAE | |
| 3135 | MLX5_QP_OPTPAR_RRE, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3136 | }, |
| 3137 | }, |
| 3138 | }; |
| 3139 | |
| 3140 | static int ib_nr_to_mlx5_nr(int ib_mask) |
| 3141 | { |
| 3142 | switch (ib_mask) { |
| 3143 | case IB_QP_STATE: |
| 3144 | return 0; |
| 3145 | case IB_QP_CUR_STATE: |
| 3146 | return 0; |
| 3147 | case IB_QP_EN_SQD_ASYNC_NOTIFY: |
| 3148 | return 0; |
| 3149 | case IB_QP_ACCESS_FLAGS: |
| 3150 | return MLX5_QP_OPTPAR_RWE | MLX5_QP_OPTPAR_RRE | |
| 3151 | MLX5_QP_OPTPAR_RAE; |
| 3152 | case IB_QP_PKEY_INDEX: |
| 3153 | return MLX5_QP_OPTPAR_PKEY_INDEX; |
| 3154 | case IB_QP_PORT: |
| 3155 | return MLX5_QP_OPTPAR_PRI_PORT; |
| 3156 | case IB_QP_QKEY: |
| 3157 | return MLX5_QP_OPTPAR_Q_KEY; |
| 3158 | case IB_QP_AV: |
| 3159 | return MLX5_QP_OPTPAR_PRIMARY_ADDR_PATH | |
| 3160 | MLX5_QP_OPTPAR_PRI_PORT; |
| 3161 | case IB_QP_PATH_MTU: |
| 3162 | return 0; |
| 3163 | case IB_QP_TIMEOUT: |
| 3164 | return MLX5_QP_OPTPAR_ACK_TIMEOUT; |
| 3165 | case IB_QP_RETRY_CNT: |
| 3166 | return MLX5_QP_OPTPAR_RETRY_COUNT; |
| 3167 | case IB_QP_RNR_RETRY: |
| 3168 | return MLX5_QP_OPTPAR_RNR_RETRY; |
| 3169 | case IB_QP_RQ_PSN: |
| 3170 | return 0; |
| 3171 | case IB_QP_MAX_QP_RD_ATOMIC: |
| 3172 | return MLX5_QP_OPTPAR_SRA_MAX; |
| 3173 | case IB_QP_ALT_PATH: |
| 3174 | return MLX5_QP_OPTPAR_ALT_ADDR_PATH; |
| 3175 | case IB_QP_MIN_RNR_TIMER: |
| 3176 | return MLX5_QP_OPTPAR_RNR_TIMEOUT; |
| 3177 | case IB_QP_SQ_PSN: |
| 3178 | return 0; |
| 3179 | case IB_QP_MAX_DEST_RD_ATOMIC: |
| 3180 | return MLX5_QP_OPTPAR_RRA_MAX | MLX5_QP_OPTPAR_RWE | |
| 3181 | MLX5_QP_OPTPAR_RRE | MLX5_QP_OPTPAR_RAE; |
| 3182 | case IB_QP_PATH_MIG_STATE: |
| 3183 | return MLX5_QP_OPTPAR_PM_STATE; |
| 3184 | case IB_QP_CAP: |
| 3185 | return 0; |
| 3186 | case IB_QP_DEST_QPN: |
| 3187 | return 0; |
| 3188 | } |
| 3189 | return 0; |
| 3190 | } |
| 3191 | |
| 3192 | static int ib_mask_to_mlx5_opt(int ib_mask) |
| 3193 | { |
| 3194 | int result = 0; |
| 3195 | int i; |
| 3196 | |
| 3197 | for (i = 0; i < 8 * sizeof(int); i++) { |
| 3198 | if ((1 << i) & ib_mask) |
| 3199 | result |= ib_nr_to_mlx5_nr(1 << i); |
| 3200 | } |
| 3201 | |
| 3202 | return result; |
| 3203 | } |
| 3204 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3205 | static int modify_raw_packet_qp_rq( |
| 3206 | struct mlx5_ib_dev *dev, struct mlx5_ib_rq *rq, int new_state, |
| 3207 | 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] | 3208 | { |
| 3209 | void *in; |
| 3210 | void *rqc; |
| 3211 | int inlen; |
| 3212 | int err; |
| 3213 | |
| 3214 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3215 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3216 | if (!in) |
| 3217 | return -ENOMEM; |
| 3218 | |
| 3219 | MLX5_SET(modify_rq_in, in, rq_state, rq->state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3220 | MLX5_SET(modify_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3221 | |
| 3222 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 3223 | MLX5_SET(rqc, rqc, state, new_state); |
| 3224 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3225 | if (raw_qp_param->set_mask & MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID) { |
| 3226 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 3227 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 3228 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3229 | MLX5_SET(rqc, rqc, counter_set_id, raw_qp_param->rq_q_ctr_id); |
| 3230 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 3231 | dev_info_once( |
| 3232 | &dev->ib_dev.dev, |
| 3233 | "RAW PACKET QP counters are not supported on current FW\n"); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3234 | } |
| 3235 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3236 | 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] | 3237 | if (err) |
| 3238 | goto out; |
| 3239 | |
| 3240 | rq->state = new_state; |
| 3241 | |
| 3242 | out: |
| 3243 | kvfree(in); |
| 3244 | return err; |
| 3245 | } |
| 3246 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3247 | static int modify_raw_packet_qp_sq( |
| 3248 | struct mlx5_core_dev *dev, struct mlx5_ib_sq *sq, int new_state, |
| 3249 | 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] | 3250 | { |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3251 | struct mlx5_ib_qp *ibqp = sq->base.container_mibqp; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3252 | struct mlx5_rate_limit old_rl = ibqp->rl; |
| 3253 | struct mlx5_rate_limit new_rl = old_rl; |
| 3254 | bool new_rate_added = false; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3255 | u16 rl_index = 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3256 | void *in; |
| 3257 | void *sqc; |
| 3258 | int inlen; |
| 3259 | int err; |
| 3260 | |
| 3261 | inlen = MLX5_ST_SZ_BYTES(modify_sq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3262 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3263 | if (!in) |
| 3264 | return -ENOMEM; |
| 3265 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3266 | MLX5_SET(modify_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3267 | MLX5_SET(modify_sq_in, in, sq_state, sq->state); |
| 3268 | |
| 3269 | sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx); |
| 3270 | MLX5_SET(sqc, sqc, state, new_state); |
| 3271 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3272 | if (raw_qp_param->set_mask & MLX5_RAW_QP_RATE_LIMIT) { |
| 3273 | if (new_state != MLX5_SQC_STATE_RDY) |
| 3274 | pr_warn("%s: Rate limit can only be changed when SQ is moving to RDY\n", |
| 3275 | __func__); |
| 3276 | else |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3277 | new_rl = raw_qp_param->rl; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3278 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3279 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3280 | if (!mlx5_rl_are_equal(&old_rl, &new_rl)) { |
| 3281 | if (new_rl.rate) { |
| 3282 | err = mlx5_rl_add_rate(dev, &rl_index, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3283 | if (err) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3284 | pr_err("Failed configuring rate limit(err %d): \ |
| 3285 | rate %u, max_burst_sz %u, typical_pkt_sz %u\n", |
| 3286 | err, new_rl.rate, new_rl.max_burst_sz, |
| 3287 | new_rl.typical_pkt_sz); |
| 3288 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3289 | goto out; |
| 3290 | } |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3291 | new_rate_added = true; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3292 | } |
| 3293 | |
| 3294 | MLX5_SET64(modify_sq_in, in, modify_bitmask, 1); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3295 | /* index 0 means no limit */ |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3296 | MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index); |
| 3297 | } |
| 3298 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 3299 | err = mlx5_core_modify_sq(dev, sq->base.mqp.qpn, in); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3300 | if (err) { |
| 3301 | /* Remove new rate from table if failed */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3302 | if (new_rate_added) |
| 3303 | mlx5_rl_remove_rate(dev, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3304 | goto out; |
| 3305 | } |
| 3306 | |
| 3307 | /* Only remove the old rate after new rate was set */ |
Rafi Wiener | c8973df | 2019-10-02 15:02:43 +0300 | [diff] [blame] | 3308 | if ((old_rl.rate && !mlx5_rl_are_equal(&old_rl, &new_rl)) || |
| 3309 | (new_state != MLX5_SQC_STATE_RDY)) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3310 | mlx5_rl_remove_rate(dev, &old_rl); |
Rafi Wiener | c8973df | 2019-10-02 15:02:43 +0300 | [diff] [blame] | 3311 | if (new_state != MLX5_SQC_STATE_RDY) |
| 3312 | memset(&new_rl, 0, sizeof(new_rl)); |
| 3313 | } |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3314 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3315 | ibqp->rl = new_rl; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3316 | sq->state = new_state; |
| 3317 | |
| 3318 | out: |
| 3319 | kvfree(in); |
| 3320 | return err; |
| 3321 | } |
| 3322 | |
| 3323 | 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] | 3324 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 3325 | u8 tx_affinity) |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3326 | { |
| 3327 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 3328 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 3329 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3330 | int modify_rq = !!qp->rq.wqe_cnt; |
| 3331 | int modify_sq = !!qp->sq.wqe_cnt; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3332 | int rq_state; |
| 3333 | int sq_state; |
| 3334 | int err; |
| 3335 | |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3336 | switch (raw_qp_param->operation) { |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3337 | case MLX5_CMD_OP_RST2INIT_QP: |
| 3338 | rq_state = MLX5_RQC_STATE_RDY; |
| 3339 | sq_state = MLX5_SQC_STATE_RDY; |
| 3340 | break; |
| 3341 | case MLX5_CMD_OP_2ERR_QP: |
| 3342 | rq_state = MLX5_RQC_STATE_ERR; |
| 3343 | sq_state = MLX5_SQC_STATE_ERR; |
| 3344 | break; |
| 3345 | case MLX5_CMD_OP_2RST_QP: |
| 3346 | rq_state = MLX5_RQC_STATE_RST; |
| 3347 | sq_state = MLX5_SQC_STATE_RST; |
| 3348 | break; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3349 | case MLX5_CMD_OP_RTR2RTS_QP: |
| 3350 | case MLX5_CMD_OP_RTS2RTS_QP: |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3351 | if (raw_qp_param->set_mask == |
| 3352 | MLX5_RAW_QP_RATE_LIMIT) { |
| 3353 | modify_rq = 0; |
| 3354 | sq_state = sq->state; |
| 3355 | } else { |
| 3356 | return raw_qp_param->set_mask ? -EINVAL : 0; |
| 3357 | } |
| 3358 | break; |
| 3359 | case MLX5_CMD_OP_INIT2INIT_QP: |
| 3360 | case MLX5_CMD_OP_INIT2RTR_QP: |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3361 | if (raw_qp_param->set_mask) |
| 3362 | return -EINVAL; |
| 3363 | else |
| 3364 | return 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3365 | default: |
| 3366 | WARN_ON(1); |
| 3367 | return -EINVAL; |
| 3368 | } |
| 3369 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3370 | if (modify_rq) { |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3371 | err = modify_raw_packet_qp_rq(dev, rq, rq_state, raw_qp_param, |
| 3372 | qp->ibqp.pd); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3373 | if (err) |
| 3374 | return err; |
| 3375 | } |
| 3376 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3377 | if (modify_sq) { |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3378 | struct mlx5_flow_handle *flow_rule; |
| 3379 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3380 | if (tx_affinity) { |
| 3381 | err = modify_raw_packet_tx_affinity(dev->mdev, sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3382 | tx_affinity, |
| 3383 | qp->ibqp.pd); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3384 | if (err) |
| 3385 | return err; |
| 3386 | } |
| 3387 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3388 | flow_rule = create_flow_rule_vport_sq(dev, sq, |
| 3389 | raw_qp_param->port); |
| 3390 | if (IS_ERR(flow_rule)) |
Colin Ian King | 1db8631 | 2019-04-12 11:40:17 +0100 | [diff] [blame] | 3391 | return PTR_ERR(flow_rule); |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3392 | |
| 3393 | err = modify_raw_packet_qp_sq(dev->mdev, sq, sq_state, |
| 3394 | raw_qp_param, qp->ibqp.pd); |
| 3395 | if (err) { |
| 3396 | if (flow_rule) |
| 3397 | mlx5_del_flow_rules(flow_rule); |
| 3398 | return err; |
| 3399 | } |
| 3400 | |
| 3401 | if (flow_rule) { |
| 3402 | destroy_flow_rule_vport_sq(sq); |
| 3403 | sq->flow_rule = flow_rule; |
| 3404 | } |
| 3405 | |
| 3406 | return err; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3407 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3408 | |
| 3409 | return 0; |
| 3410 | } |
| 3411 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3412 | static unsigned int get_tx_affinity(struct mlx5_ib_dev *dev, |
| 3413 | struct mlx5_ib_pd *pd, |
| 3414 | struct mlx5_ib_qp_base *qp_base, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3415 | u8 port_num, struct ib_udata *udata) |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3416 | { |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3417 | struct mlx5_ib_ucontext *ucontext = rdma_udata_to_drv_context( |
| 3418 | udata, struct mlx5_ib_ucontext, ibucontext); |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3419 | unsigned int tx_port_affinity; |
| 3420 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3421 | if (ucontext) { |
| 3422 | tx_port_affinity = (unsigned int)atomic_add_return( |
| 3423 | 1, &ucontext->tx_port_affinity) % |
| 3424 | MLX5_MAX_PORTS + |
| 3425 | 1; |
| 3426 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x ucontext %p\n", |
| 3427 | tx_port_affinity, qp_base->mqp.qpn, ucontext); |
| 3428 | } else { |
| 3429 | tx_port_affinity = |
| 3430 | (unsigned int)atomic_add_return( |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 3431 | 1, &dev->port[port_num].roce.tx_port_affinity) % |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3432 | MLX5_MAX_PORTS + |
| 3433 | 1; |
| 3434 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x\n", |
| 3435 | tx_port_affinity, qp_base->mqp.qpn); |
| 3436 | } |
| 3437 | |
| 3438 | return tx_port_affinity; |
| 3439 | } |
| 3440 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3441 | static int __mlx5_ib_qp_set_counter(struct ib_qp *qp, |
| 3442 | struct rdma_counter *counter) |
| 3443 | { |
| 3444 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 3445 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 3446 | struct mlx5_qp_context context = {}; |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3447 | struct mlx5_ib_qp_base *base; |
| 3448 | u32 set_id; |
| 3449 | |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3450 | if (counter) |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3451 | set_id = counter->id; |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3452 | else |
| 3453 | set_id = mlx5_ib_get_counters_id(dev, mqp->port - 1); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3454 | |
| 3455 | base = &mqp->trans_qp.base; |
| 3456 | context.qp_counter_set_usr_page &= cpu_to_be32(0xffffff); |
| 3457 | context.qp_counter_set_usr_page |= cpu_to_be32(set_id << 24); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3458 | return mlx5_core_qp_modify(dev, MLX5_CMD_OP_RTS2RTS_QP, |
| 3459 | MLX5_QP_OPTPAR_COUNTER_SET_ID, &context, |
| 3460 | &base->mqp); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3461 | } |
| 3462 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3463 | static int __mlx5_ib_modify_qp(struct ib_qp *ibqp, |
| 3464 | const struct ib_qp_attr *attr, int attr_mask, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3465 | enum ib_qp_state cur_state, |
| 3466 | enum ib_qp_state new_state, |
| 3467 | const struct mlx5_ib_modify_qp *ucmd, |
| 3468 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3469 | { |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3470 | static const u16 optab[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE] = { |
| 3471 | [MLX5_QP_STATE_RST] = { |
| 3472 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3473 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3474 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_RST2INIT_QP, |
| 3475 | }, |
| 3476 | [MLX5_QP_STATE_INIT] = { |
| 3477 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3478 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3479 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_INIT2INIT_QP, |
| 3480 | [MLX5_QP_STATE_RTR] = MLX5_CMD_OP_INIT2RTR_QP, |
| 3481 | }, |
| 3482 | [MLX5_QP_STATE_RTR] = { |
| 3483 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3484 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3485 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTR2RTS_QP, |
| 3486 | }, |
| 3487 | [MLX5_QP_STATE_RTS] = { |
| 3488 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3489 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3490 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTS2RTS_QP, |
| 3491 | }, |
| 3492 | [MLX5_QP_STATE_SQD] = { |
| 3493 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3494 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3495 | }, |
| 3496 | [MLX5_QP_STATE_SQER] = { |
| 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_SQERR2RTS_QP, |
| 3500 | }, |
| 3501 | [MLX5_QP_STATE_ERR] = { |
| 3502 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3503 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3504 | } |
| 3505 | }; |
| 3506 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3507 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3508 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3509 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3510 | struct mlx5_ib_cq *send_cq, *recv_cq; |
| 3511 | struct mlx5_qp_context *context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3512 | struct mlx5_ib_pd *pd; |
| 3513 | enum mlx5_qp_state mlx5_cur, mlx5_new; |
| 3514 | enum mlx5_qp_optpar optpar; |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3515 | u32 set_id = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3516 | int mlx5_st; |
| 3517 | int err; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3518 | u16 op; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3519 | u8 tx_affinity = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3520 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 3521 | mlx5_st = to_mlx5_st(qp->type); |
Leon Romanovsky | 55de9a7 | 2018-02-25 13:39:52 +0200 | [diff] [blame] | 3522 | if (mlx5_st < 0) |
| 3523 | return -EINVAL; |
| 3524 | |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 3525 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 3526 | if (!context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3527 | return -ENOMEM; |
| 3528 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3529 | pd = get_pd(qp); |
Leon Romanovsky | 55de9a7 | 2018-02-25 13:39:52 +0200 | [diff] [blame] | 3530 | context->flags = cpu_to_be32(mlx5_st << 16); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3531 | |
| 3532 | if (!(attr_mask & IB_QP_PATH_MIG_STATE)) { |
| 3533 | context->flags |= cpu_to_be32(MLX5_QP_PM_MIGRATED << 11); |
| 3534 | } else { |
| 3535 | switch (attr->path_mig_state) { |
| 3536 | case IB_MIG_MIGRATED: |
| 3537 | context->flags |= cpu_to_be32(MLX5_QP_PM_MIGRATED << 11); |
| 3538 | break; |
| 3539 | case IB_MIG_REARM: |
| 3540 | context->flags |= cpu_to_be32(MLX5_QP_PM_REARM << 11); |
| 3541 | break; |
| 3542 | case IB_MIG_ARMED: |
| 3543 | context->flags |= cpu_to_be32(MLX5_QP_PM_ARMED << 11); |
| 3544 | break; |
| 3545 | } |
| 3546 | } |
| 3547 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3548 | if ((cur_state == IB_QPS_RESET) && (new_state == IB_QPS_INIT)) { |
| 3549 | if ((ibqp->qp_type == IB_QPT_RC) || |
| 3550 | (ibqp->qp_type == IB_QPT_UD && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3551 | !(qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1)) || |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3552 | (ibqp->qp_type == IB_QPT_UC) || |
| 3553 | (ibqp->qp_type == IB_QPT_RAW_PACKET) || |
| 3554 | (ibqp->qp_type == IB_QPT_XRC_INI) || |
| 3555 | (ibqp->qp_type == IB_QPT_XRC_TGT)) { |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 3556 | if (dev->lag_active) { |
Mark Bloch | 95579e7 | 2019-03-28 15:27:33 +0200 | [diff] [blame] | 3557 | u8 p = mlx5_core_native_port_num(dev->mdev) - 1; |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 3558 | tx_affinity = get_tx_affinity(dev, pd, base, p, |
| 3559 | udata); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3560 | context->flags |= cpu_to_be32(tx_affinity << 24); |
| 3561 | } |
| 3562 | } |
| 3563 | } |
| 3564 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3565 | if (is_sqp(ibqp->qp_type)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3566 | context->mtu_msgmax = (IB_MTU_256 << 5) | 8; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3567 | } else if ((ibqp->qp_type == IB_QPT_UD && |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3568 | !(qp->flags & IB_QP_CREATE_SOURCE_QPN)) || |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3569 | ibqp->qp_type == MLX5_IB_QPT_REG_UMR) { |
| 3570 | context->mtu_msgmax = (IB_MTU_4096 << 5) | 12; |
| 3571 | } else if (attr_mask & IB_QP_PATH_MTU) { |
| 3572 | if (attr->path_mtu < IB_MTU_256 || |
| 3573 | attr->path_mtu > IB_MTU_4096) { |
| 3574 | mlx5_ib_warn(dev, "invalid mtu %d\n", attr->path_mtu); |
| 3575 | err = -EINVAL; |
| 3576 | goto out; |
| 3577 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3578 | context->mtu_msgmax = (attr->path_mtu << 5) | |
| 3579 | (u8)MLX5_CAP_GEN(dev->mdev, log_max_msg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | if (attr_mask & IB_QP_DEST_QPN) |
| 3583 | context->log_pg_sz_remote_qpn = cpu_to_be32(attr->dest_qp_num); |
| 3584 | |
| 3585 | if (attr_mask & IB_QP_PKEY_INDEX) |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 3586 | context->pri_path.pkey_index = cpu_to_be16(attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3587 | |
| 3588 | /* todo implement counter_index functionality */ |
| 3589 | |
| 3590 | if (is_sqp(ibqp->qp_type)) |
| 3591 | context->pri_path.port = qp->port; |
| 3592 | |
| 3593 | if (attr_mask & IB_QP_PORT) |
| 3594 | context->pri_path.port = attr->port_num; |
| 3595 | |
| 3596 | if (attr_mask & IB_QP_AV) { |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3597 | err = mlx5_set_path(dev, qp, &attr->ah_attr, &context->pri_path, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3598 | attr_mask & IB_QP_PORT ? attr->port_num : qp->port, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3599 | attr_mask, 0, attr, false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3600 | if (err) |
| 3601 | goto out; |
| 3602 | } |
| 3603 | |
| 3604 | if (attr_mask & IB_QP_TIMEOUT) |
| 3605 | context->pri_path.ackto_lt |= attr->timeout << 3; |
| 3606 | |
| 3607 | if (attr_mask & IB_QP_ALT_PATH) { |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3608 | err = mlx5_set_path(dev, qp, &attr->alt_ah_attr, |
| 3609 | &context->alt_path, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3610 | attr->alt_port_num, |
| 3611 | attr_mask | IB_QP_PKEY_INDEX | IB_QP_TIMEOUT, |
| 3612 | 0, attr, true); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3613 | if (err) |
| 3614 | goto out; |
| 3615 | } |
| 3616 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 3617 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 3618 | &send_cq, &recv_cq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3619 | |
| 3620 | context->flags_pd = cpu_to_be32(pd ? pd->pdn : to_mpd(dev->devr.p0)->pdn); |
| 3621 | context->cqn_send = send_cq ? cpu_to_be32(send_cq->mcq.cqn) : 0; |
| 3622 | context->cqn_recv = recv_cq ? cpu_to_be32(recv_cq->mcq.cqn) : 0; |
| 3623 | context->params1 = cpu_to_be32(MLX5_IB_ACK_REQ_FREQ << 28); |
| 3624 | |
| 3625 | if (attr_mask & IB_QP_RNR_RETRY) |
| 3626 | context->params1 |= cpu_to_be32(attr->rnr_retry << 13); |
| 3627 | |
| 3628 | if (attr_mask & IB_QP_RETRY_CNT) |
| 3629 | context->params1 |= cpu_to_be32(attr->retry_cnt << 16); |
| 3630 | |
| 3631 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) { |
| 3632 | if (attr->max_rd_atomic) |
| 3633 | context->params1 |= |
| 3634 | cpu_to_be32(fls(attr->max_rd_atomic - 1) << 21); |
| 3635 | } |
| 3636 | |
| 3637 | if (attr_mask & IB_QP_SQ_PSN) |
| 3638 | context->next_send_psn = cpu_to_be32(attr->sq_psn); |
| 3639 | |
| 3640 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) { |
| 3641 | if (attr->max_dest_rd_atomic) |
| 3642 | context->params2 |= |
| 3643 | cpu_to_be32(fls(attr->max_dest_rd_atomic - 1) << 21); |
| 3644 | } |
| 3645 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3646 | 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] | 3647 | __be32 access_flags; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3648 | |
| 3649 | err = to_mlx5_access_flags(qp, attr, attr_mask, &access_flags); |
| 3650 | if (err) |
| 3651 | goto out; |
| 3652 | |
| 3653 | context->params2 |= access_flags; |
| 3654 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3655 | |
| 3656 | if (attr_mask & IB_QP_MIN_RNR_TIMER) |
| 3657 | context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24); |
| 3658 | |
| 3659 | if (attr_mask & IB_QP_RQ_PSN) |
| 3660 | context->rnr_nextrecvpsn |= cpu_to_be32(attr->rq_psn); |
| 3661 | |
| 3662 | if (attr_mask & IB_QP_QKEY) |
| 3663 | context->qkey = cpu_to_be32(attr->qkey); |
| 3664 | |
| 3665 | if (qp->rq.wqe_cnt && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
| 3666 | context->db_rec_addr = cpu_to_be64(qp->db.dma); |
| 3667 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3668 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
| 3669 | u8 port_num = (attr_mask & IB_QP_PORT ? attr->port_num : |
| 3670 | qp->port) - 1; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3671 | |
| 3672 | /* Underlay port should be used - index 0 function per port */ |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3673 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3674 | port_num = 0; |
| 3675 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3676 | if (ibqp->counter) |
| 3677 | set_id = ibqp->counter->id; |
| 3678 | else |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3679 | set_id = mlx5_ib_get_counters_id(dev, port_num); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3680 | context->qp_counter_set_usr_page |= |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3681 | cpu_to_be32(set_id << 24); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3682 | } |
| 3683 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3684 | if (!ibqp->uobject && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
| 3685 | context->sq_crq_size |= cpu_to_be16(1 << 4); |
| 3686 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3687 | if (qp->flags & MLX5_IB_QP_CREATE_SQPN_QP1) |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 3688 | context->deth_sqpn = cpu_to_be32(1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3689 | |
| 3690 | mlx5_cur = to_mlx5_state(cur_state); |
| 3691 | mlx5_new = to_mlx5_state(new_state); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3692 | |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3693 | 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] | 3694 | !optab[mlx5_cur][mlx5_new]) { |
| 3695 | err = -EINVAL; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3696 | goto out; |
Dan Carpenter | 5d414b1 | 2018-03-06 13:00:31 +0300 | [diff] [blame] | 3697 | } |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3698 | |
| 3699 | op = optab[mlx5_cur][mlx5_new]; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3700 | optpar = ib_mask_to_mlx5_opt(attr_mask); |
| 3701 | optpar &= opt_mask[mlx5_cur][mlx5_new][mlx5_st]; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3702 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3703 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3704 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3705 | struct mlx5_modify_raw_qp_param raw_qp_param = {}; |
| 3706 | |
| 3707 | raw_qp_param.operation = op; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3708 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3709 | raw_qp_param.rq_q_ctr_id = set_id; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3710 | raw_qp_param.set_mask |= MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID; |
| 3711 | } |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3712 | |
Mark Bloch | d5ed8ac | 2019-03-28 15:27:38 +0200 | [diff] [blame] | 3713 | if (attr_mask & IB_QP_PORT) |
| 3714 | raw_qp_param.port = attr->port_num; |
| 3715 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3716 | if (attr_mask & IB_QP_RATE_LIMIT) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3717 | raw_qp_param.rl.rate = attr->rate_limit; |
| 3718 | |
| 3719 | if (ucmd->burst_info.max_burst_sz) { |
| 3720 | if (attr->rate_limit && |
| 3721 | MLX5_CAP_QOS(dev->mdev, packet_pacing_burst_bound)) { |
| 3722 | raw_qp_param.rl.max_burst_sz = |
| 3723 | ucmd->burst_info.max_burst_sz; |
| 3724 | } else { |
| 3725 | err = -EINVAL; |
| 3726 | goto out; |
| 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | if (ucmd->burst_info.typical_pkt_sz) { |
| 3731 | if (attr->rate_limit && |
| 3732 | MLX5_CAP_QOS(dev->mdev, packet_pacing_typical_size)) { |
| 3733 | raw_qp_param.rl.typical_pkt_sz = |
| 3734 | ucmd->burst_info.typical_pkt_sz; |
| 3735 | } else { |
| 3736 | err = -EINVAL; |
| 3737 | goto out; |
| 3738 | } |
| 3739 | } |
| 3740 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3741 | raw_qp_param.set_mask |= MLX5_RAW_QP_RATE_LIMIT; |
| 3742 | } |
| 3743 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3744 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, tx_affinity); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3745 | } else { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3746 | err = mlx5_core_qp_modify(dev, op, optpar, context, &base->mqp); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3747 | } |
| 3748 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3749 | if (err) |
| 3750 | goto out; |
| 3751 | |
| 3752 | qp->state = new_state; |
| 3753 | |
| 3754 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3755 | qp->trans_qp.atomic_rd_en = attr->qp_access_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3756 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3757 | qp->trans_qp.resp_depth = attr->max_dest_rd_atomic; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3758 | if (attr_mask & IB_QP_PORT) |
| 3759 | qp->port = attr->port_num; |
| 3760 | if (attr_mask & IB_QP_ALT_PATH) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3761 | qp->trans_qp.alt_port = attr->alt_port_num; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3762 | |
| 3763 | /* |
| 3764 | * If we moved a kernel QP to RESET, clean up all old CQ |
| 3765 | * entries and reinitialize the QP. |
| 3766 | */ |
Leon Romanovsky | 75a4598 | 2018-03-11 13:51:32 +0200 | [diff] [blame] | 3767 | if (new_state == IB_QPS_RESET && |
| 3768 | !ibqp->uobject && ibqp->qp_type != IB_QPT_XRC_TGT) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3769 | mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3770 | ibqp->srq ? to_msrq(ibqp->srq) : NULL); |
| 3771 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3772 | mlx5_ib_cq_clean(send_cq, base->mqp.qpn, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3773 | |
| 3774 | qp->rq.head = 0; |
| 3775 | qp->rq.tail = 0; |
| 3776 | qp->sq.head = 0; |
| 3777 | qp->sq.tail = 0; |
| 3778 | qp->sq.cur_post = 0; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3779 | if (qp->sq.wqe_cnt) |
| 3780 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
Leon Romanovsky | 950bf4f | 2020-03-18 11:16:40 +0200 | [diff] [blame] | 3781 | qp->sq.last_poll = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3782 | qp->db.db[MLX5_RCV_DBR] = 0; |
| 3783 | qp->db.db[MLX5_SND_DBR] = 0; |
| 3784 | } |
| 3785 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 3786 | if ((new_state == IB_QPS_RTS) && qp->counter_pending) { |
| 3787 | err = __mlx5_ib_qp_set_counter(ibqp, ibqp->counter); |
| 3788 | if (!err) |
| 3789 | qp->counter_pending = 0; |
| 3790 | } |
| 3791 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3792 | out: |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 3793 | kfree(context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3794 | return err; |
| 3795 | } |
| 3796 | |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3797 | static inline bool is_valid_mask(int mask, int req, int opt) |
| 3798 | { |
| 3799 | if ((mask & req) != req) |
| 3800 | return false; |
| 3801 | |
| 3802 | if (mask & ~(req | opt)) |
| 3803 | return false; |
| 3804 | |
| 3805 | return true; |
| 3806 | } |
| 3807 | |
| 3808 | /* check valid transition for driver QP types |
| 3809 | * for now the only QP type that this function supports is DCI |
| 3810 | */ |
| 3811 | static bool modify_dci_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state new_state, |
| 3812 | enum ib_qp_attr_mask attr_mask) |
| 3813 | { |
| 3814 | int req = IB_QP_STATE; |
| 3815 | int opt = 0; |
| 3816 | |
Moni Shoua | 99ed748 | 2018-09-12 09:33:55 +0300 | [diff] [blame] | 3817 | if (new_state == IB_QPS_RESET) { |
| 3818 | return is_valid_mask(attr_mask, req, opt); |
| 3819 | } else if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3820 | req |= IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3821 | return is_valid_mask(attr_mask, req, opt); |
| 3822 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_INIT) { |
| 3823 | opt = IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3824 | return is_valid_mask(attr_mask, req, opt); |
| 3825 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 3826 | req |= IB_QP_PATH_MTU; |
Artemy Kovalyov | 5ec0304 | 2018-11-05 08:12:07 +0200 | [diff] [blame] | 3827 | opt = IB_QP_PKEY_INDEX | IB_QP_AV; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3828 | return is_valid_mask(attr_mask, req, opt); |
| 3829 | } else if (cur_state == IB_QPS_RTR && new_state == IB_QPS_RTS) { |
| 3830 | req |= IB_QP_TIMEOUT | IB_QP_RETRY_CNT | IB_QP_RNR_RETRY | |
| 3831 | IB_QP_MAX_QP_RD_ATOMIC | IB_QP_SQ_PSN; |
| 3832 | opt = IB_QP_MIN_RNR_TIMER; |
| 3833 | return is_valid_mask(attr_mask, req, opt); |
| 3834 | } else if (cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) { |
| 3835 | opt = IB_QP_MIN_RNR_TIMER; |
| 3836 | return is_valid_mask(attr_mask, req, opt); |
| 3837 | } else if (cur_state != IB_QPS_RESET && new_state == IB_QPS_ERR) { |
| 3838 | return is_valid_mask(attr_mask, req, opt); |
| 3839 | } |
| 3840 | return false; |
| 3841 | } |
| 3842 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3843 | /* mlx5_ib_modify_dct: modify a DCT QP |
| 3844 | * valid transitions are: |
| 3845 | * RESET to INIT: must set access_flags, pkey_index and port |
| 3846 | * INIT to RTR : must set min_rnr_timer, tclass, flow_label, |
| 3847 | * mtu, gid_index and hop_limit |
| 3848 | * Other transitions and attributes are illegal |
| 3849 | */ |
| 3850 | static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 3851 | int attr_mask, struct ib_udata *udata) |
| 3852 | { |
| 3853 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 3854 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3855 | enum ib_qp_state cur_state, new_state; |
| 3856 | int err = 0; |
| 3857 | int required = IB_QP_STATE; |
| 3858 | void *dctc; |
| 3859 | |
| 3860 | if (!(attr_mask & IB_QP_STATE)) |
| 3861 | return -EINVAL; |
| 3862 | |
| 3863 | cur_state = qp->state; |
| 3864 | new_state = attr->qp_state; |
| 3865 | |
| 3866 | dctc = MLX5_ADDR_OF(create_dct_in, qp->dct.in, dct_context_entry); |
| 3867 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3868 | u16 set_id; |
| 3869 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3870 | required |= IB_QP_ACCESS_FLAGS | IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3871 | if (!is_valid_mask(attr_mask, required, 0)) |
| 3872 | return -EINVAL; |
| 3873 | |
| 3874 | if (attr->port_num == 0 || |
| 3875 | attr->port_num > MLX5_CAP_GEN(dev->mdev, num_ports)) { |
| 3876 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 3877 | attr->port_num, dev->num_ports); |
| 3878 | return -EINVAL; |
| 3879 | } |
| 3880 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_READ) |
| 3881 | MLX5_SET(dctc, dctc, rre, 1); |
| 3882 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE) |
| 3883 | MLX5_SET(dctc, dctc, rwe, 1); |
| 3884 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3885 | int atomic_mode; |
| 3886 | |
| 3887 | atomic_mode = get_atomic_mode(dev, MLX5_IB_QPT_DCT); |
| 3888 | if (atomic_mode < 0) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3889 | return -EOPNOTSUPP; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3890 | |
| 3891 | MLX5_SET(dctc, dctc, atomic_mode, atomic_mode); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3892 | MLX5_SET(dctc, dctc, rae, 1); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3893 | } |
| 3894 | MLX5_SET(dctc, dctc, pkey_index, attr->pkey_index); |
| 3895 | MLX5_SET(dctc, dctc, port, attr->port_num); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 3896 | |
| 3897 | set_id = mlx5_ib_get_counters_id(dev, attr->port_num - 1); |
| 3898 | MLX5_SET(dctc, dctc, counter_set_id, set_id); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3899 | |
| 3900 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 3901 | struct mlx5_ib_modify_qp_resp resp = {}; |
Yishai Hadas | c5ae195 | 2019-03-06 19:21:42 +0200 | [diff] [blame] | 3902 | u32 out[MLX5_ST_SZ_DW(create_dct_out)] = {0}; |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3903 | u32 min_resp_len = offsetof(typeof(resp), dctn) + |
| 3904 | sizeof(resp.dctn); |
| 3905 | |
| 3906 | if (udata->outlen < min_resp_len) |
| 3907 | return -EINVAL; |
| 3908 | resp.response_length = min_resp_len; |
| 3909 | |
| 3910 | required |= IB_QP_MIN_RNR_TIMER | IB_QP_AV | IB_QP_PATH_MTU; |
| 3911 | if (!is_valid_mask(attr_mask, required, 0)) |
| 3912 | return -EINVAL; |
| 3913 | MLX5_SET(dctc, dctc, min_rnr_nak, attr->min_rnr_timer); |
| 3914 | MLX5_SET(dctc, dctc, tclass, attr->ah_attr.grh.traffic_class); |
| 3915 | MLX5_SET(dctc, dctc, flow_label, attr->ah_attr.grh.flow_label); |
| 3916 | MLX5_SET(dctc, dctc, mtu, attr->path_mtu); |
| 3917 | MLX5_SET(dctc, dctc, my_addr_index, attr->ah_attr.grh.sgid_index); |
| 3918 | MLX5_SET(dctc, dctc, hop_limit, attr->ah_attr.grh.hop_limit); |
| 3919 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3920 | err = mlx5_core_create_dct(dev, &qp->dct.mdct, qp->dct.in, |
Yishai Hadas | c5ae195 | 2019-03-06 19:21:42 +0200 | [diff] [blame] | 3921 | MLX5_ST_SZ_BYTES(create_dct_in), out, |
| 3922 | sizeof(out)); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3923 | if (err) |
| 3924 | return err; |
| 3925 | resp.dctn = qp->dct.mdct.mqp.qpn; |
| 3926 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 3927 | if (err) { |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 3928 | mlx5_core_destroy_dct(dev, &qp->dct.mdct); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3929 | return err; |
| 3930 | } |
| 3931 | } else { |
| 3932 | mlx5_ib_warn(dev, "Modify DCT: Invalid transition from %d to %d\n", cur_state, new_state); |
| 3933 | return -EINVAL; |
| 3934 | } |
| 3935 | if (err) |
| 3936 | qp->state = IB_QPS_ERR; |
| 3937 | else |
| 3938 | qp->state = new_state; |
| 3939 | return err; |
| 3940 | } |
| 3941 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3942 | int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 3943 | int attr_mask, struct ib_udata *udata) |
| 3944 | { |
| 3945 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3946 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3947 | struct mlx5_ib_modify_qp ucmd = {}; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3948 | enum ib_qp_type qp_type; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3949 | enum ib_qp_state cur_state, new_state; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3950 | size_t required_cmd_sz; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3951 | int err = -EINVAL; |
| 3952 | int port; |
| 3953 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 3954 | if (ibqp->rwq_ind_tbl) |
| 3955 | return -ENOSYS; |
| 3956 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3957 | if (udata && udata->inlen) { |
| 3958 | required_cmd_sz = offsetof(typeof(ucmd), reserved) + |
| 3959 | sizeof(ucmd.reserved); |
| 3960 | if (udata->inlen < required_cmd_sz) |
| 3961 | return -EINVAL; |
| 3962 | |
| 3963 | if (udata->inlen > sizeof(ucmd) && |
| 3964 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 3965 | udata->inlen - sizeof(ucmd))) |
| 3966 | return -EOPNOTSUPP; |
| 3967 | |
| 3968 | if (ib_copy_from_udata(&ucmd, udata, |
| 3969 | min(udata->inlen, sizeof(ucmd)))) |
| 3970 | return -EFAULT; |
| 3971 | |
| 3972 | if (ucmd.comp_mask || |
| 3973 | memchr_inv(&ucmd.reserved, 0, sizeof(ucmd.reserved)) || |
| 3974 | memchr_inv(&ucmd.burst_info.reserved, 0, |
| 3975 | sizeof(ucmd.burst_info.reserved))) |
| 3976 | return -EOPNOTSUPP; |
| 3977 | } |
| 3978 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3979 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 3980 | return mlx5_ib_gsi_modify_qp(ibqp, attr, attr_mask); |
| 3981 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 3982 | qp_type = (unlikely(ibqp->qp_type == MLX5_IB_QPT_HW_GSI)) ? IB_QPT_GSI : |
| 3983 | qp->type; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3984 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3985 | if (qp_type == MLX5_IB_QPT_DCT) |
| 3986 | return mlx5_ib_modify_dct(ibqp, attr, attr_mask, udata); |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3987 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3988 | mutex_lock(&qp->mutex); |
| 3989 | |
| 3990 | cur_state = attr_mask & IB_QP_CUR_STATE ? attr->cur_qp_state : qp->state; |
| 3991 | new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; |
| 3992 | |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3993 | if (!(cur_state == new_state && cur_state == IB_QPS_RESET)) { |
| 3994 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3995 | } |
| 3996 | |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 3997 | if (qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3998 | if (attr_mask & ~(IB_QP_STATE | IB_QP_CUR_STATE)) { |
| 3999 | mlx5_ib_dbg(dev, "invalid attr_mask 0x%x when underlay QP is used\n", |
| 4000 | attr_mask); |
| 4001 | goto out; |
| 4002 | } |
| 4003 | } else if (qp_type != MLX5_IB_QPT_REG_UMR && |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4004 | qp_type != MLX5_IB_QPT_DCI && |
Kamal Heib | d31131b | 2018-10-02 16:11:21 +0300 | [diff] [blame] | 4005 | !ib_modify_qp_is_ok(cur_state, new_state, qp_type, |
| 4006 | attr_mask)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4007 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 4008 | cur_state, new_state, ibqp->qp_type, attr_mask); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4009 | goto out; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 4010 | } else if (qp_type == MLX5_IB_QPT_DCI && |
| 4011 | !modify_dci_qp_is_ok(cur_state, new_state, attr_mask)) { |
| 4012 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 4013 | cur_state, new_state, qp_type, attr_mask); |
| 4014 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4015 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4016 | |
| 4017 | if ((attr_mask & IB_QP_PORT) && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4018 | (attr->port_num == 0 || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 4019 | attr->port_num > dev->num_ports)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4020 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 4021 | attr->port_num, dev->num_ports); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4022 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4023 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4024 | |
| 4025 | if (attr_mask & IB_QP_PKEY_INDEX) { |
| 4026 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4027 | if (attr->pkey_index >= |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4028 | dev->mdev->port_caps[port - 1].pkey_table_len) { |
| 4029 | mlx5_ib_dbg(dev, "invalid pkey index %d\n", |
| 4030 | attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4031 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4032 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4033 | } |
| 4034 | |
| 4035 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4036 | attr->max_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4037 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_res_qp))) { |
| 4038 | mlx5_ib_dbg(dev, "invalid max_rd_atomic value %d\n", |
| 4039 | attr->max_rd_atomic); |
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_MAX_DEST_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 4044 | attr->max_dest_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4045 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_req_qp))) { |
| 4046 | mlx5_ib_dbg(dev, "invalid max_dest_rd_atomic value %d\n", |
| 4047 | attr->max_dest_rd_atomic); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4048 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 4049 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4050 | |
| 4051 | if (cur_state == new_state && cur_state == IB_QPS_RESET) { |
| 4052 | err = 0; |
| 4053 | goto out; |
| 4054 | } |
| 4055 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 4056 | err = __mlx5_ib_modify_qp(ibqp, attr, attr_mask, cur_state, |
Shamir Rabinovitch | 8994445 | 2019-02-07 18:44:49 +0200 | [diff] [blame] | 4057 | new_state, &ucmd, udata); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4058 | |
| 4059 | out: |
| 4060 | mutex_unlock(&qp->mutex); |
| 4061 | return err; |
| 4062 | } |
| 4063 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4064 | static void _handle_post_send_edge(struct mlx5_ib_wq *sq, void **seg, |
| 4065 | u32 wqe_sz, void **cur_edge) |
| 4066 | { |
| 4067 | u32 idx; |
| 4068 | |
| 4069 | idx = (sq->cur_post + (wqe_sz >> 2)) & (sq->wqe_cnt - 1); |
| 4070 | *cur_edge = get_sq_edge(sq, idx); |
| 4071 | |
| 4072 | *seg = mlx5_frag_buf_get_wqe(&sq->fbc, idx); |
| 4073 | } |
| 4074 | |
| 4075 | /* handle_post_send_edge - Check if we get to SQ edge. If yes, update to the |
| 4076 | * next nearby edge and get new address translation for current WQE position. |
| 4077 | * @sq - SQ buffer. |
| 4078 | * @seg: Current WQE position (16B aligned). |
| 4079 | * @wqe_sz: Total current WQE size [16B]. |
| 4080 | * @cur_edge: Updated current edge. |
| 4081 | */ |
| 4082 | static inline void handle_post_send_edge(struct mlx5_ib_wq *sq, void **seg, |
| 4083 | u32 wqe_sz, void **cur_edge) |
| 4084 | { |
| 4085 | if (likely(*seg != *cur_edge)) |
| 4086 | return; |
| 4087 | |
| 4088 | _handle_post_send_edge(sq, seg, wqe_sz, cur_edge); |
| 4089 | } |
| 4090 | |
| 4091 | /* memcpy_send_wqe - copy data from src to WQE and update the relevant WQ's |
| 4092 | * pointers. At the end @seg is aligned to 16B regardless the copied size. |
| 4093 | * @sq - SQ buffer. |
| 4094 | * @cur_edge: Updated current edge. |
| 4095 | * @seg: Current WQE position (16B aligned). |
| 4096 | * @wqe_sz: Total current WQE size [16B]. |
| 4097 | * @src: Pointer to copy from. |
| 4098 | * @n: Number of bytes to copy. |
| 4099 | */ |
| 4100 | static inline void memcpy_send_wqe(struct mlx5_ib_wq *sq, void **cur_edge, |
| 4101 | void **seg, u32 *wqe_sz, const void *src, |
| 4102 | size_t n) |
| 4103 | { |
| 4104 | while (likely(n)) { |
| 4105 | size_t leftlen = *cur_edge - *seg; |
| 4106 | size_t copysz = min_t(size_t, leftlen, n); |
| 4107 | size_t stride; |
| 4108 | |
| 4109 | memcpy(*seg, src, copysz); |
| 4110 | |
| 4111 | n -= copysz; |
| 4112 | src += copysz; |
| 4113 | stride = !n ? ALIGN(copysz, 16) : copysz; |
| 4114 | *seg += stride; |
| 4115 | *wqe_sz += stride >> 4; |
| 4116 | handle_post_send_edge(sq, seg, *wqe_sz, cur_edge); |
| 4117 | } |
| 4118 | } |
| 4119 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4120 | static int mlx5_wq_overflow(struct mlx5_ib_wq *wq, int nreq, struct ib_cq *ib_cq) |
| 4121 | { |
| 4122 | struct mlx5_ib_cq *cq; |
| 4123 | unsigned cur; |
| 4124 | |
| 4125 | cur = wq->head - wq->tail; |
| 4126 | if (likely(cur + nreq < wq->max_post)) |
| 4127 | return 0; |
| 4128 | |
| 4129 | cq = to_mcq(ib_cq); |
| 4130 | spin_lock(&cq->lock); |
| 4131 | cur = wq->head - wq->tail; |
| 4132 | spin_unlock(&cq->lock); |
| 4133 | |
| 4134 | return cur + nreq >= wq->max_post; |
| 4135 | } |
| 4136 | |
| 4137 | static __always_inline void set_raddr_seg(struct mlx5_wqe_raddr_seg *rseg, |
| 4138 | u64 remote_addr, u32 rkey) |
| 4139 | { |
| 4140 | rseg->raddr = cpu_to_be64(remote_addr); |
| 4141 | rseg->rkey = cpu_to_be32(rkey); |
| 4142 | rseg->reserved = 0; |
| 4143 | } |
| 4144 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4145 | static void set_eth_seg(const struct ib_send_wr *wr, struct mlx5_ib_qp *qp, |
| 4146 | void **seg, int *size, void **cur_edge) |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4147 | { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4148 | struct mlx5_wqe_eth_seg *eseg = *seg; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4149 | |
| 4150 | memset(eseg, 0, sizeof(struct mlx5_wqe_eth_seg)); |
| 4151 | |
| 4152 | if (wr->send_flags & IB_SEND_IP_CSUM) |
| 4153 | eseg->cs_flags = MLX5_ETH_WQE_L3_CSUM | |
| 4154 | MLX5_ETH_WQE_L4_CSUM; |
| 4155 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4156 | if (wr->opcode == IB_WR_LSO) { |
| 4157 | 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] | 4158 | size_t left, copysz; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4159 | void *pdata = ud_wr->header; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4160 | size_t stride; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4161 | |
| 4162 | left = ud_wr->hlen; |
| 4163 | eseg->mss = cpu_to_be16(ud_wr->mss); |
Saeed Mahameed | 2b31f7a | 2016-11-28 18:04:50 +0200 | [diff] [blame] | 4164 | eseg->inline_hdr.sz = cpu_to_be16(left); |
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 | /* memcpy_send_wqe should get a 16B align address. Hence, we |
| 4167 | * first copy up to the current edge and then, if needed, |
| 4168 | * fall-through to memcpy_send_wqe. |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4169 | */ |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4170 | copysz = min_t(u64, *cur_edge - (void *)eseg->inline_hdr.start, |
| 4171 | left); |
| 4172 | memcpy(eseg->inline_hdr.start, pdata, copysz); |
| 4173 | stride = ALIGN(sizeof(struct mlx5_wqe_eth_seg) - |
| 4174 | sizeof(eseg->inline_hdr.start) + copysz, 16); |
| 4175 | *size += stride / 16; |
| 4176 | *seg += stride; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4177 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4178 | if (copysz < left) { |
| 4179 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4180 | left -= copysz; |
| 4181 | pdata += copysz; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4182 | memcpy_send_wqe(&qp->sq, cur_edge, seg, size, pdata, |
| 4183 | left); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4184 | } |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4185 | |
| 4186 | return; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4187 | } |
| 4188 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4189 | *seg += sizeof(struct mlx5_wqe_eth_seg); |
| 4190 | *size += sizeof(struct mlx5_wqe_eth_seg) / 16; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4191 | } |
| 4192 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4193 | static void set_datagram_seg(struct mlx5_wqe_datagram_seg *dseg, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4194 | const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4195 | { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4196 | memcpy(&dseg->av, &to_mah(ud_wr(wr)->ah)->av, sizeof(struct mlx5_av)); |
| 4197 | dseg->av.dqp_dct = cpu_to_be32(ud_wr(wr)->remote_qpn | MLX5_EXTENDED_UD_AV); |
| 4198 | 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] | 4199 | } |
| 4200 | |
| 4201 | static void set_data_ptr_seg(struct mlx5_wqe_data_seg *dseg, struct ib_sge *sg) |
| 4202 | { |
| 4203 | dseg->byte_count = cpu_to_be32(sg->length); |
| 4204 | dseg->lkey = cpu_to_be32(sg->lkey); |
| 4205 | dseg->addr = cpu_to_be64(sg->addr); |
| 4206 | } |
| 4207 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4208 | static u64 get_xlt_octo(u64 bytes) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4209 | { |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4210 | return ALIGN(bytes, MLX5_IB_UMR_XLT_ALIGNMENT) / |
| 4211 | MLX5_IB_UMR_OCTOWORD; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4212 | } |
| 4213 | |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4214 | static __be64 frwr_mkey_mask(bool atomic) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4215 | { |
| 4216 | u64 result; |
| 4217 | |
| 4218 | result = MLX5_MKEY_MASK_LEN | |
| 4219 | MLX5_MKEY_MASK_PAGE_SIZE | |
| 4220 | MLX5_MKEY_MASK_START_ADDR | |
| 4221 | MLX5_MKEY_MASK_EN_RINVAL | |
| 4222 | MLX5_MKEY_MASK_KEY | |
| 4223 | MLX5_MKEY_MASK_LR | |
| 4224 | MLX5_MKEY_MASK_LW | |
| 4225 | MLX5_MKEY_MASK_RR | |
| 4226 | MLX5_MKEY_MASK_RW | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4227 | MLX5_MKEY_MASK_SMALL_FENCE | |
| 4228 | MLX5_MKEY_MASK_FREE; |
| 4229 | |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4230 | if (atomic) |
| 4231 | result |= MLX5_MKEY_MASK_A; |
| 4232 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4233 | return cpu_to_be64(result); |
| 4234 | } |
| 4235 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4236 | static __be64 sig_mkey_mask(void) |
| 4237 | { |
| 4238 | u64 result; |
| 4239 | |
| 4240 | result = MLX5_MKEY_MASK_LEN | |
| 4241 | MLX5_MKEY_MASK_PAGE_SIZE | |
| 4242 | MLX5_MKEY_MASK_START_ADDR | |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4243 | MLX5_MKEY_MASK_EN_SIGERR | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4244 | MLX5_MKEY_MASK_EN_RINVAL | |
| 4245 | MLX5_MKEY_MASK_KEY | |
| 4246 | MLX5_MKEY_MASK_LR | |
| 4247 | MLX5_MKEY_MASK_LW | |
| 4248 | MLX5_MKEY_MASK_RR | |
| 4249 | MLX5_MKEY_MASK_RW | |
| 4250 | MLX5_MKEY_MASK_SMALL_FENCE | |
| 4251 | MLX5_MKEY_MASK_FREE | |
| 4252 | MLX5_MKEY_MASK_BSF_EN; |
| 4253 | |
| 4254 | return cpu_to_be64(result); |
| 4255 | } |
| 4256 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4257 | 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] | 4258 | struct mlx5_ib_mr *mr, u8 flags, bool atomic) |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4259 | { |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4260 | int size = (mr->ndescs + mr->meta_ndescs) * mr->desc_size; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4261 | |
| 4262 | memset(umr, 0, sizeof(*umr)); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4263 | |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4264 | umr->flags = flags; |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4265 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(size)); |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4266 | umr->mkey_mask = frwr_mkey_mask(atomic); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4267 | } |
| 4268 | |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4269 | 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] | 4270 | { |
| 4271 | memset(umr, 0, sizeof(*umr)); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4272 | umr->mkey_mask = cpu_to_be64(MLX5_MKEY_MASK_FREE); |
Max Gurtovoy | 2d22158 | 2016-10-27 16:36:36 +0300 | [diff] [blame] | 4273 | umr->flags = MLX5_UMR_INLINE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4274 | } |
| 4275 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4276 | static __be64 get_umr_enable_mr_mask(void) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4277 | { |
| 4278 | u64 result; |
| 4279 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4280 | result = MLX5_MKEY_MASK_KEY | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4281 | MLX5_MKEY_MASK_FREE; |
| 4282 | |
| 4283 | return cpu_to_be64(result); |
| 4284 | } |
| 4285 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4286 | static __be64 get_umr_disable_mr_mask(void) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4287 | { |
| 4288 | u64 result; |
| 4289 | |
| 4290 | result = MLX5_MKEY_MASK_FREE; |
| 4291 | |
| 4292 | return cpu_to_be64(result); |
| 4293 | } |
| 4294 | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4295 | static __be64 get_umr_update_translation_mask(void) |
| 4296 | { |
| 4297 | u64 result; |
| 4298 | |
| 4299 | result = MLX5_MKEY_MASK_LEN | |
| 4300 | MLX5_MKEY_MASK_PAGE_SIZE | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4301 | MLX5_MKEY_MASK_START_ADDR; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4302 | |
| 4303 | return cpu_to_be64(result); |
| 4304 | } |
| 4305 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4306 | static __be64 get_umr_update_access_mask(int atomic) |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4307 | { |
| 4308 | u64 result; |
| 4309 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4310 | result = MLX5_MKEY_MASK_LR | |
| 4311 | MLX5_MKEY_MASK_LW | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4312 | MLX5_MKEY_MASK_RR | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4313 | MLX5_MKEY_MASK_RW; |
| 4314 | |
| 4315 | if (atomic) |
| 4316 | result |= MLX5_MKEY_MASK_A; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4317 | |
| 4318 | return cpu_to_be64(result); |
| 4319 | } |
| 4320 | |
| 4321 | static __be64 get_umr_update_pd_mask(void) |
| 4322 | { |
| 4323 | u64 result; |
| 4324 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4325 | result = MLX5_MKEY_MASK_PD; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4326 | |
| 4327 | return cpu_to_be64(result); |
| 4328 | } |
| 4329 | |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 4330 | static int umr_check_mkey_mask(struct mlx5_ib_dev *dev, u64 mask) |
| 4331 | { |
| 4332 | if ((mask & MLX5_MKEY_MASK_PAGE_SIZE && |
| 4333 | MLX5_CAP_GEN(dev->mdev, umr_modify_entity_size_disabled)) || |
| 4334 | (mask & MLX5_MKEY_MASK_A && |
| 4335 | MLX5_CAP_GEN(dev->mdev, umr_modify_atomic_disabled))) |
| 4336 | return -EPERM; |
| 4337 | return 0; |
| 4338 | } |
| 4339 | |
| 4340 | static int set_reg_umr_segment(struct mlx5_ib_dev *dev, |
| 4341 | struct mlx5_wqe_umr_ctrl_seg *umr, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4342 | const struct ib_send_wr *wr, int atomic) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4343 | { |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4344 | const struct mlx5_umr_wr *umrwr = umr_wr(wr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4345 | |
| 4346 | memset(umr, 0, sizeof(*umr)); |
| 4347 | |
Yishai Hadas | 6a05395 | 2019-07-23 09:57:25 +0300 | [diff] [blame] | 4348 | if (!umrwr->ignore_free_state) { |
| 4349 | if (wr->send_flags & MLX5_IB_SEND_UMR_FAIL_IF_FREE) |
| 4350 | /* fail if free */ |
| 4351 | umr->flags = MLX5_UMR_CHECK_FREE; |
| 4352 | else |
| 4353 | /* fail if not free */ |
| 4354 | umr->flags = MLX5_UMR_CHECK_NOT_FREE; |
| 4355 | } |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4356 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4357 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(umrwr->xlt_size)); |
| 4358 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_XLT) { |
| 4359 | u64 offset = get_xlt_octo(umrwr->offset); |
| 4360 | |
| 4361 | umr->xlt_offset = cpu_to_be16(offset & 0xffff); |
| 4362 | umr->xlt_offset_47_16 = cpu_to_be32(offset >> 16); |
| 4363 | umr->flags |= MLX5_UMR_TRANSLATION_OFFSET_EN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4364 | } |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4365 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_TRANSLATION) |
| 4366 | umr->mkey_mask |= get_umr_update_translation_mask(); |
| 4367 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_PD_ACCESS) { |
| 4368 | umr->mkey_mask |= get_umr_update_access_mask(atomic); |
| 4369 | umr->mkey_mask |= get_umr_update_pd_mask(); |
| 4370 | } |
| 4371 | if (wr->send_flags & MLX5_IB_SEND_UMR_ENABLE_MR) |
| 4372 | umr->mkey_mask |= get_umr_enable_mr_mask(); |
| 4373 | if (wr->send_flags & MLX5_IB_SEND_UMR_DISABLE_MR) |
| 4374 | umr->mkey_mask |= get_umr_disable_mr_mask(); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4375 | |
| 4376 | if (!wr->num_sge) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4377 | umr->flags |= MLX5_UMR_INLINE; |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 4378 | |
| 4379 | return umr_check_mkey_mask(dev, be64_to_cpu(umr->mkey_mask)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4380 | } |
| 4381 | |
| 4382 | static u8 get_umr_flags(int acc) |
| 4383 | { |
| 4384 | return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) | |
| 4385 | (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) | |
| 4386 | (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) | |
| 4387 | (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) | |
Sagi Grimberg | 2ac4593 | 2014-02-23 14:19:09 +0200 | [diff] [blame] | 4388 | MLX5_PERM_LOCAL_READ | MLX5_PERM_UMR_EN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4389 | } |
| 4390 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4391 | static void set_reg_mkey_seg(struct mlx5_mkey_seg *seg, |
| 4392 | struct mlx5_ib_mr *mr, |
| 4393 | u32 key, int access) |
| 4394 | { |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4395 | int ndescs = ALIGN(mr->ndescs + mr->meta_ndescs, 8) >> 1; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4396 | |
| 4397 | memset(seg, 0, sizeof(*seg)); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4398 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 4399 | if (mr->access_mode == MLX5_MKC_ACCESS_MODE_MTT) |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4400 | seg->log2_page_size = ilog2(mr->ibmr.page_size); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 4401 | else if (mr->access_mode == MLX5_MKC_ACCESS_MODE_KLMS) |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4402 | /* KLMs take twice the size of MTTs */ |
| 4403 | ndescs *= 2; |
| 4404 | |
| 4405 | seg->flags = get_umr_flags(access) | mr->access_mode; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4406 | seg->qpn_mkey7_0 = cpu_to_be32((key & 0xff) | 0xffffff00); |
| 4407 | seg->flags_pd = cpu_to_be32(MLX5_MKEY_REMOTE_INVAL); |
| 4408 | seg->start_addr = cpu_to_be64(mr->ibmr.iova); |
| 4409 | seg->len = cpu_to_be64(mr->ibmr.length); |
| 4410 | seg->xlt_oct_size = cpu_to_be32(ndescs); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4411 | } |
| 4412 | |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4413 | static void set_linv_mkey_seg(struct mlx5_mkey_seg *seg) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4414 | { |
| 4415 | memset(seg, 0, sizeof(*seg)); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4416 | seg->status = MLX5_MKEY_STATUS_FREE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4417 | } |
| 4418 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4419 | static void set_reg_mkey_segment(struct mlx5_mkey_seg *seg, |
| 4420 | const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4421 | { |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4422 | const struct mlx5_umr_wr *umrwr = umr_wr(wr); |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4423 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4424 | memset(seg, 0, sizeof(*seg)); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4425 | if (wr->send_flags & MLX5_IB_SEND_UMR_DISABLE_MR) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4426 | seg->status = MLX5_MKEY_STATUS_FREE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4427 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4428 | seg->flags = convert_access(umrwr->access_flags); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4429 | if (umrwr->pd) |
| 4430 | seg->flags_pd = cpu_to_be32(to_mpd(umrwr->pd)->pdn); |
| 4431 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_TRANSLATION && |
| 4432 | !umrwr->length) |
| 4433 | seg->flags_pd |= cpu_to_be32(MLX5_MKEY_LEN64); |
| 4434 | |
| 4435 | seg->start_addr = cpu_to_be64(umrwr->virt_addr); |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4436 | seg->len = cpu_to_be64(umrwr->length); |
| 4437 | seg->log2_page_size = umrwr->page_shift; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 4438 | seg->qpn_mkey7_0 = cpu_to_be32(0xffffff00 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4439 | mlx5_mkey_variant(umrwr->mkey)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4440 | } |
| 4441 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4442 | static void set_reg_data_seg(struct mlx5_wqe_data_seg *dseg, |
| 4443 | struct mlx5_ib_mr *mr, |
| 4444 | struct mlx5_ib_pd *pd) |
| 4445 | { |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4446 | int bcount = mr->desc_size * (mr->ndescs + mr->meta_ndescs); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4447 | |
| 4448 | dseg->addr = cpu_to_be64(mr->desc_map); |
| 4449 | dseg->byte_count = cpu_to_be32(ALIGN(bcount, 64)); |
| 4450 | dseg->lkey = cpu_to_be32(pd->ibpd.local_dma_lkey); |
| 4451 | } |
| 4452 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4453 | static __be32 send_ieth(const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4454 | { |
| 4455 | switch (wr->opcode) { |
| 4456 | case IB_WR_SEND_WITH_IMM: |
| 4457 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 4458 | return wr->ex.imm_data; |
| 4459 | |
| 4460 | case IB_WR_SEND_WITH_INV: |
| 4461 | return cpu_to_be32(wr->ex.invalidate_rkey); |
| 4462 | |
| 4463 | default: |
| 4464 | return 0; |
| 4465 | } |
| 4466 | } |
| 4467 | |
| 4468 | static u8 calc_sig(void *wqe, int size) |
| 4469 | { |
| 4470 | u8 *p = wqe; |
| 4471 | u8 res = 0; |
| 4472 | int i; |
| 4473 | |
| 4474 | for (i = 0; i < size; i++) |
| 4475 | res ^= p[i]; |
| 4476 | |
| 4477 | return ~res; |
| 4478 | } |
| 4479 | |
| 4480 | static u8 wq_sig(void *wqe) |
| 4481 | { |
| 4482 | return calc_sig(wqe, (*((u8 *)wqe + 8) & 0x3f) << 4); |
| 4483 | } |
| 4484 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4485 | 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] | 4486 | void **wqe, int *wqe_sz, void **cur_edge) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4487 | { |
| 4488 | struct mlx5_wqe_inline_seg *seg; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4489 | size_t offset; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4490 | int inl = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4491 | int i; |
| 4492 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4493 | seg = *wqe; |
| 4494 | *wqe += sizeof(*seg); |
| 4495 | offset = sizeof(*seg); |
| 4496 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4497 | for (i = 0; i < wr->num_sge; i++) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4498 | size_t len = wr->sg_list[i].length; |
| 4499 | void *addr = (void *)(unsigned long)(wr->sg_list[i].addr); |
| 4500 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4501 | inl += len; |
| 4502 | |
| 4503 | if (unlikely(inl > qp->max_inline_data)) |
| 4504 | return -ENOMEM; |
| 4505 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4506 | while (likely(len)) { |
| 4507 | size_t leftlen; |
| 4508 | size_t copysz; |
| 4509 | |
| 4510 | handle_post_send_edge(&qp->sq, wqe, |
| 4511 | *wqe_sz + (offset >> 4), |
| 4512 | cur_edge); |
| 4513 | |
| 4514 | leftlen = *cur_edge - *wqe; |
| 4515 | copysz = min_t(size_t, leftlen, len); |
| 4516 | |
| 4517 | memcpy(*wqe, addr, copysz); |
| 4518 | len -= copysz; |
| 4519 | addr += copysz; |
| 4520 | *wqe += copysz; |
| 4521 | offset += copysz; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4522 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | seg->byte_count = cpu_to_be32(inl | MLX5_INLINE_SEG); |
| 4526 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4527 | *wqe_sz += ALIGN(inl + sizeof(seg->byte_count), 16) / 16; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4528 | |
| 4529 | return 0; |
| 4530 | } |
| 4531 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4532 | static u16 prot_field_size(enum ib_signature_type type) |
| 4533 | { |
| 4534 | switch (type) { |
| 4535 | case IB_SIG_TYPE_T10_DIF: |
| 4536 | return MLX5_DIF_SIZE; |
| 4537 | default: |
| 4538 | return 0; |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | static u8 bs_selector(int block_size) |
| 4543 | { |
| 4544 | switch (block_size) { |
| 4545 | case 512: return 0x1; |
| 4546 | case 520: return 0x2; |
| 4547 | case 4096: return 0x3; |
| 4548 | case 4160: return 0x4; |
| 4549 | case 1073741824: return 0x5; |
| 4550 | default: return 0; |
| 4551 | } |
| 4552 | } |
| 4553 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4554 | static void mlx5_fill_inl_bsf(struct ib_sig_domain *domain, |
| 4555 | struct mlx5_bsf_inl *inl) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4556 | { |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4557 | /* Valid inline section and allow BSF refresh */ |
| 4558 | inl->vld_refresh = cpu_to_be16(MLX5_BSF_INL_VALID | |
| 4559 | MLX5_BSF_REFRESH_DIF); |
| 4560 | inl->dif_apptag = cpu_to_be16(domain->sig.dif.app_tag); |
| 4561 | inl->dif_reftag = cpu_to_be32(domain->sig.dif.ref_tag); |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4562 | /* repeating block */ |
| 4563 | inl->rp_inv_seed = MLX5_BSF_REPEAT_BLOCK; |
| 4564 | inl->sig_type = domain->sig.dif.bg_type == IB_T10DIF_CRC ? |
| 4565 | MLX5_DIF_CRC : MLX5_DIF_IPCS; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4566 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4567 | if (domain->sig.dif.ref_remap) |
| 4568 | inl->dif_inc_ref_guard_check |= MLX5_BSF_INC_REFTAG; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4569 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4570 | if (domain->sig.dif.app_escape) { |
| 4571 | if (domain->sig.dif.ref_escape) |
| 4572 | inl->dif_inc_ref_guard_check |= MLX5_BSF_APPREF_ESCAPE; |
| 4573 | else |
| 4574 | inl->dif_inc_ref_guard_check |= MLX5_BSF_APPTAG_ESCAPE; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4575 | } |
| 4576 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4577 | inl->dif_app_bitmask_check = |
| 4578 | cpu_to_be16(domain->sig.dif.apptag_check_mask); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | static int mlx5_set_bsf(struct ib_mr *sig_mr, |
| 4582 | struct ib_sig_attrs *sig_attrs, |
| 4583 | struct mlx5_bsf *bsf, u32 data_size) |
| 4584 | { |
| 4585 | struct mlx5_core_sig_ctx *msig = to_mmr(sig_mr)->sig; |
| 4586 | struct mlx5_bsf_basic *basic = &bsf->basic; |
| 4587 | struct ib_sig_domain *mem = &sig_attrs->mem; |
| 4588 | struct ib_sig_domain *wire = &sig_attrs->wire; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4589 | |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4590 | memset(bsf, 0, sizeof(*bsf)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4591 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4592 | /* Basic + Extended + Inline */ |
| 4593 | basic->bsf_size_sbs = 1 << 7; |
| 4594 | /* Input domain check byte mask */ |
| 4595 | basic->check_byte_mask = sig_attrs->check_mask; |
| 4596 | basic->raw_data_size = cpu_to_be32(data_size); |
| 4597 | |
| 4598 | /* Memory domain */ |
| 4599 | switch (sig_attrs->mem.sig_type) { |
| 4600 | case IB_SIG_TYPE_NONE: |
| 4601 | break; |
| 4602 | case IB_SIG_TYPE_T10_DIF: |
| 4603 | basic->mem.bs_selector = bs_selector(mem->sig.dif.pi_interval); |
| 4604 | basic->m_bfs_psv = cpu_to_be32(msig->psv_memory.psv_idx); |
| 4605 | mlx5_fill_inl_bsf(mem, &bsf->m_inl); |
| 4606 | break; |
| 4607 | default: |
| 4608 | return -EINVAL; |
| 4609 | } |
| 4610 | |
| 4611 | /* Wire domain */ |
| 4612 | switch (sig_attrs->wire.sig_type) { |
| 4613 | case IB_SIG_TYPE_NONE: |
| 4614 | break; |
| 4615 | case IB_SIG_TYPE_T10_DIF: |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4616 | if (mem->sig.dif.pi_interval == wire->sig.dif.pi_interval && |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4617 | mem->sig_type == wire->sig_type) { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4618 | /* Same block structure */ |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4619 | basic->bsf_size_sbs |= 1 << 4; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4620 | if (mem->sig.dif.bg_type == wire->sig.dif.bg_type) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4621 | basic->wire.copy_byte_mask |= MLX5_CPY_GRD_MASK; |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4622 | if (mem->sig.dif.app_tag == wire->sig.dif.app_tag) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4623 | basic->wire.copy_byte_mask |= MLX5_CPY_APP_MASK; |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4624 | if (mem->sig.dif.ref_tag == wire->sig.dif.ref_tag) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4625 | basic->wire.copy_byte_mask |= MLX5_CPY_REF_MASK; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4626 | } else |
| 4627 | basic->wire.bs_selector = bs_selector(wire->sig.dif.pi_interval); |
| 4628 | |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4629 | basic->w_bfs_psv = cpu_to_be32(msig->psv_wire.psv_idx); |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4630 | mlx5_fill_inl_bsf(wire, &bsf->w_inl); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4631 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4632 | default: |
| 4633 | return -EINVAL; |
| 4634 | } |
| 4635 | |
| 4636 | return 0; |
| 4637 | } |
| 4638 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4639 | static int set_sig_data_segment(const struct ib_send_wr *send_wr, |
| 4640 | struct ib_mr *sig_mr, |
| 4641 | struct ib_sig_attrs *sig_attrs, |
| 4642 | struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4643 | void **cur_edge) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4644 | { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4645 | struct mlx5_bsf *bsf; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4646 | u32 data_len; |
| 4647 | u32 data_key; |
| 4648 | u64 data_va; |
| 4649 | u32 prot_len = 0; |
| 4650 | u32 prot_key = 0; |
| 4651 | u64 prot_va = 0; |
| 4652 | bool prot = false; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4653 | int ret; |
| 4654 | int wqe_size; |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4655 | struct mlx5_ib_mr *mr = to_mmr(sig_mr); |
| 4656 | struct mlx5_ib_mr *pi_mr = mr->pi_mr; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4657 | |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4658 | data_len = pi_mr->data_length; |
| 4659 | data_key = pi_mr->ibmr.lkey; |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 4660 | data_va = pi_mr->data_iova; |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4661 | if (pi_mr->meta_ndescs) { |
| 4662 | prot_len = pi_mr->meta_length; |
| 4663 | prot_key = pi_mr->ibmr.lkey; |
Israel Rukshin | de0ae95 | 2019-06-11 18:52:55 +0300 | [diff] [blame] | 4664 | prot_va = pi_mr->pi_iova; |
Israel Rukshin | 5c171cb | 2019-06-11 18:52:54 +0300 | [diff] [blame] | 4665 | prot = true; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4666 | } |
| 4667 | |
| 4668 | if (!prot || (data_key == prot_key && data_va == prot_va && |
| 4669 | data_len == prot_len)) { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4670 | /** |
| 4671 | * Source domain doesn't contain signature information |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4672 | * or data and protection are interleaved in memory. |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4673 | * So need construct: |
| 4674 | * ------------------ |
| 4675 | * | data_klm | |
| 4676 | * ------------------ |
| 4677 | * | BSF | |
| 4678 | * ------------------ |
| 4679 | **/ |
| 4680 | struct mlx5_klm *data_klm = *seg; |
| 4681 | |
| 4682 | data_klm->bcount = cpu_to_be32(data_len); |
| 4683 | data_klm->key = cpu_to_be32(data_key); |
| 4684 | data_klm->va = cpu_to_be64(data_va); |
| 4685 | wqe_size = ALIGN(sizeof(*data_klm), 64); |
| 4686 | } else { |
| 4687 | /** |
| 4688 | * Source domain contains signature information |
| 4689 | * So need construct a strided block format: |
| 4690 | * --------------------------- |
| 4691 | * | stride_block_ctrl | |
| 4692 | * --------------------------- |
| 4693 | * | data_klm | |
| 4694 | * --------------------------- |
| 4695 | * | prot_klm | |
| 4696 | * --------------------------- |
| 4697 | * | BSF | |
| 4698 | * --------------------------- |
| 4699 | **/ |
| 4700 | struct mlx5_stride_block_ctrl_seg *sblock_ctrl; |
| 4701 | struct mlx5_stride_block_entry *data_sentry; |
| 4702 | struct mlx5_stride_block_entry *prot_sentry; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4703 | u16 block_size = sig_attrs->mem.sig.dif.pi_interval; |
| 4704 | int prot_size; |
| 4705 | |
| 4706 | sblock_ctrl = *seg; |
| 4707 | data_sentry = (void *)sblock_ctrl + sizeof(*sblock_ctrl); |
| 4708 | prot_sentry = (void *)data_sentry + sizeof(*data_sentry); |
| 4709 | |
| 4710 | prot_size = prot_field_size(sig_attrs->mem.sig_type); |
| 4711 | if (!prot_size) { |
| 4712 | pr_err("Bad block size given: %u\n", block_size); |
| 4713 | return -EINVAL; |
| 4714 | } |
| 4715 | sblock_ctrl->bcount_per_cycle = cpu_to_be32(block_size + |
| 4716 | prot_size); |
| 4717 | sblock_ctrl->op = cpu_to_be32(MLX5_STRIDE_BLOCK_OP); |
| 4718 | sblock_ctrl->repeat_count = cpu_to_be32(data_len / block_size); |
| 4719 | sblock_ctrl->num_entries = cpu_to_be16(2); |
| 4720 | |
| 4721 | data_sentry->bcount = cpu_to_be16(block_size); |
| 4722 | data_sentry->key = cpu_to_be32(data_key); |
| 4723 | data_sentry->va = cpu_to_be64(data_va); |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4724 | data_sentry->stride = cpu_to_be16(block_size); |
| 4725 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4726 | prot_sentry->bcount = cpu_to_be16(prot_size); |
| 4727 | prot_sentry->key = cpu_to_be32(prot_key); |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4728 | prot_sentry->va = cpu_to_be64(prot_va); |
| 4729 | prot_sentry->stride = cpu_to_be16(prot_size); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4730 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4731 | wqe_size = ALIGN(sizeof(*sblock_ctrl) + sizeof(*data_sentry) + |
| 4732 | sizeof(*prot_sentry), 64); |
| 4733 | } |
| 4734 | |
| 4735 | *seg += wqe_size; |
| 4736 | *size += wqe_size / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4737 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4738 | |
| 4739 | bsf = *seg; |
| 4740 | ret = mlx5_set_bsf(sig_mr, sig_attrs, bsf, data_len); |
| 4741 | if (ret) |
| 4742 | return -EINVAL; |
| 4743 | |
| 4744 | *seg += sizeof(*bsf); |
| 4745 | *size += sizeof(*bsf) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4746 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4747 | |
| 4748 | return 0; |
| 4749 | } |
| 4750 | |
| 4751 | static void set_sig_mkey_segment(struct mlx5_mkey_seg *seg, |
Max Gurtovoy | 22465bb | 2019-06-11 18:52:45 +0300 | [diff] [blame] | 4752 | struct ib_mr *sig_mr, int access_flags, |
| 4753 | u32 size, u32 length, u32 pdn) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4754 | { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4755 | u32 sig_key = sig_mr->rkey; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4756 | u8 sigerr = to_mmr(sig_mr)->sig->sigerr_count & 1; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4757 | |
| 4758 | memset(seg, 0, sizeof(*seg)); |
| 4759 | |
Max Gurtovoy | 22465bb | 2019-06-11 18:52:45 +0300 | [diff] [blame] | 4760 | seg->flags = get_umr_flags(access_flags) | MLX5_MKC_ACCESS_MODE_KLMS; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4761 | seg->qpn_mkey7_0 = cpu_to_be32((sig_key & 0xff) | 0xffffff00); |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4762 | seg->flags_pd = cpu_to_be32(MLX5_MKEY_REMOTE_INVAL | sigerr << 26 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4763 | MLX5_MKEY_BSF_EN | pdn); |
| 4764 | seg->len = cpu_to_be64(length); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4765 | seg->xlt_oct_size = cpu_to_be32(get_xlt_octo(size)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4766 | seg->bsfs_octo_size = cpu_to_be32(MLX5_MKEY_BSF_OCTO_SIZE); |
| 4767 | } |
| 4768 | |
| 4769 | 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] | 4770 | u32 size) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4771 | { |
| 4772 | memset(umr, 0, sizeof(*umr)); |
| 4773 | |
| 4774 | umr->flags = MLX5_FLAGS_INLINE | MLX5_FLAGS_CHECK_FREE; |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4775 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(size)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4776 | umr->bsf_octowords = cpu_to_be16(MLX5_MKEY_BSF_OCTO_SIZE); |
| 4777 | umr->mkey_mask = sig_mkey_mask(); |
| 4778 | } |
| 4779 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4780 | static int set_pi_umr_wr(const struct ib_send_wr *send_wr, |
| 4781 | struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4782 | void **cur_edge) |
| 4783 | { |
| 4784 | const struct ib_reg_wr *wr = reg_wr(send_wr); |
| 4785 | struct mlx5_ib_mr *sig_mr = to_mmr(wr->mr); |
| 4786 | struct mlx5_ib_mr *pi_mr = sig_mr->pi_mr; |
| 4787 | struct ib_sig_attrs *sig_attrs = sig_mr->ibmr.sig_attrs; |
| 4788 | u32 pdn = get_pd(qp)->pdn; |
| 4789 | u32 xlt_size; |
| 4790 | int region_len, ret; |
| 4791 | |
| 4792 | if (unlikely(send_wr->num_sge != 0) || |
| 4793 | unlikely(wr->access & IB_ACCESS_REMOTE_ATOMIC) || |
Max Gurtovoy | 185eddc | 2019-06-11 18:52:51 +0300 | [diff] [blame] | 4794 | unlikely(!sig_mr->sig) || unlikely(!qp->ibqp.integrity_en) || |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4795 | unlikely(!sig_mr->sig->sig_status_checked)) |
| 4796 | return -EINVAL; |
| 4797 | |
| 4798 | /* length of the protected region, data + protection */ |
| 4799 | region_len = pi_mr->ibmr.length; |
| 4800 | |
| 4801 | /** |
| 4802 | * KLM octoword size - if protection was provided |
| 4803 | * then we use strided block format (3 octowords), |
| 4804 | * else we use single KLM (1 octoword) |
| 4805 | **/ |
| 4806 | if (sig_attrs->mem.sig_type != IB_SIG_TYPE_NONE) |
| 4807 | xlt_size = 0x30; |
| 4808 | else |
| 4809 | xlt_size = sizeof(struct mlx5_klm); |
| 4810 | |
| 4811 | set_sig_umr_segment(*seg, xlt_size); |
| 4812 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4813 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
| 4814 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
| 4815 | |
| 4816 | set_sig_mkey_segment(*seg, wr->mr, wr->access, xlt_size, region_len, |
| 4817 | pdn); |
| 4818 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4819 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
| 4820 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
| 4821 | |
| 4822 | ret = set_sig_data_segment(send_wr, wr->mr, sig_attrs, qp, seg, size, |
| 4823 | cur_edge); |
| 4824 | if (ret) |
| 4825 | return ret; |
| 4826 | |
| 4827 | sig_mr->sig->sig_status_checked = false; |
| 4828 | return 0; |
| 4829 | } |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4830 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4831 | static int set_psv_wr(struct ib_sig_domain *domain, |
| 4832 | u32 psv_idx, void **seg, int *size) |
| 4833 | { |
| 4834 | struct mlx5_seg_set_psv *psv_seg = *seg; |
| 4835 | |
| 4836 | memset(psv_seg, 0, sizeof(*psv_seg)); |
| 4837 | psv_seg->psv_num = cpu_to_be32(psv_idx); |
| 4838 | switch (domain->sig_type) { |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4839 | case IB_SIG_TYPE_NONE: |
| 4840 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4841 | case IB_SIG_TYPE_T10_DIF: |
| 4842 | psv_seg->transient_sig = cpu_to_be32(domain->sig.dif.bg << 16 | |
| 4843 | domain->sig.dif.app_tag); |
| 4844 | psv_seg->ref_tag = cpu_to_be32(domain->sig.dif.ref_tag); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4845 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4846 | default: |
Leon Romanovsky | 12bbf1e | 2017-01-18 14:10:31 +0200 | [diff] [blame] | 4847 | pr_err("Bad signature type (%d) is given.\n", |
| 4848 | domain->sig_type); |
| 4849 | return -EINVAL; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4850 | } |
| 4851 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4852 | *seg += sizeof(*psv_seg); |
| 4853 | *size += sizeof(*psv_seg) / 16; |
| 4854 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4855 | return 0; |
| 4856 | } |
| 4857 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4858 | static int set_reg_wr(struct mlx5_ib_qp *qp, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4859 | const struct ib_reg_wr *wr, |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4860 | void **seg, int *size, void **cur_edge, |
| 4861 | bool check_not_free) |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4862 | { |
| 4863 | struct mlx5_ib_mr *mr = to_mmr(wr->mr); |
| 4864 | struct mlx5_ib_pd *pd = to_mpd(qp->ibqp.pd); |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4865 | struct mlx5_ib_dev *dev = to_mdev(pd->ibpd.device); |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 4866 | int mr_list_size = (mr->ndescs + mr->meta_ndescs) * mr->desc_size; |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4867 | bool umr_inline = mr_list_size <= MLX5_IB_SQ_UMR_INLINE_THRESHOLD; |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4868 | bool atomic = wr->access & IB_ACCESS_REMOTE_ATOMIC; |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4869 | u8 flags = 0; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4870 | |
Michael Guralnik | d6de0bb | 2020-01-08 20:05:40 +0200 | [diff] [blame] | 4871 | if (!mlx5_ib_can_use_umr(dev, atomic, wr->access)) { |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4872 | mlx5_ib_warn(to_mdev(qp->ibqp.device), |
| 4873 | "Fast update of %s for MR is disabled\n", |
| 4874 | (MLX5_CAP_GEN(dev->mdev, |
| 4875 | umr_modify_entity_size_disabled)) ? |
| 4876 | "entity size" : |
| 4877 | "atomic access"); |
| 4878 | return -EINVAL; |
| 4879 | } |
| 4880 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4881 | if (unlikely(wr->wr.send_flags & IB_SEND_INLINE)) { |
| 4882 | mlx5_ib_warn(to_mdev(qp->ibqp.device), |
| 4883 | "Invalid IB_SEND_INLINE send flag\n"); |
| 4884 | return -EINVAL; |
| 4885 | } |
| 4886 | |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 4887 | if (check_not_free) |
| 4888 | flags |= MLX5_UMR_CHECK_NOT_FREE; |
| 4889 | if (umr_inline) |
| 4890 | flags |= MLX5_UMR_INLINE; |
| 4891 | |
Moni Shoua | 841b07f | 2019-08-15 11:38:34 +0300 | [diff] [blame] | 4892 | set_reg_umr_seg(*seg, mr, flags, atomic); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4893 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4894 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4895 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4896 | |
| 4897 | set_reg_mkey_seg(*seg, mr, wr->key, wr->access); |
| 4898 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4899 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4900 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4901 | |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4902 | if (umr_inline) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4903 | memcpy_send_wqe(&qp->sq, cur_edge, seg, size, mr->descs, |
| 4904 | mr_list_size); |
| 4905 | *size = ALIGN(*size, MLX5_SEND_WQE_BB >> 4); |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4906 | } else { |
| 4907 | set_reg_data_seg(*seg, mr, pd); |
| 4908 | *seg += sizeof(struct mlx5_wqe_data_seg); |
| 4909 | *size += (sizeof(struct mlx5_wqe_data_seg) / 16); |
| 4910 | } |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4911 | return 0; |
| 4912 | } |
| 4913 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4914 | static void set_linv_wr(struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4915 | void **cur_edge) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4916 | { |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4917 | set_linv_umr_seg(*seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4918 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4919 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4920 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4921 | set_linv_mkey_seg(*seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4922 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4923 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4924 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4925 | } |
| 4926 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4927 | 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] | 4928 | { |
| 4929 | __be32 *p = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4930 | int i, j; |
| 4931 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4932 | pr_debug("dump WQE index %u:\n", idx); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4933 | for (i = 0, j = 0; i < size_16 * 4; i += 4, j += 4) { |
| 4934 | if ((i & 0xf) == 0) { |
Artemy Kovalyov | 1e5887b | 2019-03-19 11:24:37 +0200 | [diff] [blame] | 4935 | p = mlx5_frag_buf_get_wqe(&qp->sq.fbc, idx); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4936 | pr_debug("WQBB at %p:\n", (void *)p); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4937 | j = 0; |
Artemy Kovalyov | 1e5887b | 2019-03-19 11:24:37 +0200 | [diff] [blame] | 4938 | idx = (idx + 1) & (qp->sq.wqe_cnt - 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4939 | } |
| 4940 | pr_debug("%08x %08x %08x %08x\n", be32_to_cpu(p[j]), |
| 4941 | be32_to_cpu(p[j + 1]), be32_to_cpu(p[j + 2]), |
| 4942 | be32_to_cpu(p[j + 3])); |
| 4943 | } |
| 4944 | } |
| 4945 | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4946 | static int __begin_wqe(struct mlx5_ib_qp *qp, void **seg, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4947 | struct mlx5_wqe_ctrl_seg **ctrl, |
| 4948 | const struct ib_send_wr *wr, unsigned int *idx, |
| 4949 | int *size, void **cur_edge, int nreq, |
| 4950 | bool send_signaled, bool solicited) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4951 | { |
Leon Romanovsky | b2a232d | 2016-08-28 10:58:35 +0300 | [diff] [blame] | 4952 | if (unlikely(mlx5_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq))) |
| 4953 | return -ENOMEM; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4954 | |
| 4955 | *idx = qp->sq.cur_post & (qp->sq.wqe_cnt - 1); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4956 | *seg = mlx5_frag_buf_get_wqe(&qp->sq.fbc, *idx); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4957 | *ctrl = *seg; |
| 4958 | *(uint32_t *)(*seg + 8) = 0; |
| 4959 | (*ctrl)->imm = send_ieth(wr); |
| 4960 | (*ctrl)->fm_ce_se = qp->sq_signal_bits | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4961 | (send_signaled ? MLX5_WQE_CTRL_CQ_UPDATE : 0) | |
| 4962 | (solicited ? MLX5_WQE_CTRL_SOLICITED : 0); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4963 | |
| 4964 | *seg += sizeof(**ctrl); |
| 4965 | *size = sizeof(**ctrl) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4966 | *cur_edge = qp->sq.cur_edge; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4967 | |
Leon Romanovsky | b2a232d | 2016-08-28 10:58:35 +0300 | [diff] [blame] | 4968 | return 0; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4969 | } |
| 4970 | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4971 | static int begin_wqe(struct mlx5_ib_qp *qp, void **seg, |
| 4972 | struct mlx5_wqe_ctrl_seg **ctrl, |
| 4973 | const struct ib_send_wr *wr, unsigned *idx, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4974 | int *size, void **cur_edge, int nreq) |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4975 | { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4976 | 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] | 4977 | wr->send_flags & IB_SEND_SIGNALED, |
| 4978 | wr->send_flags & IB_SEND_SOLICITED); |
| 4979 | } |
| 4980 | |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4981 | static void finish_wqe(struct mlx5_ib_qp *qp, |
| 4982 | struct mlx5_wqe_ctrl_seg *ctrl, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4983 | void *seg, u8 size, void *cur_edge, |
| 4984 | unsigned int idx, u64 wr_id, int nreq, u8 fence, |
| 4985 | u32 mlx5_opcode) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4986 | { |
| 4987 | u8 opmod = 0; |
| 4988 | |
| 4989 | ctrl->opmod_idx_opcode = cpu_to_be32(((u32)(qp->sq.cur_post) << 8) | |
| 4990 | mlx5_opcode | ((u32)opmod << 24)); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 4991 | 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] | 4992 | ctrl->fm_ce_se |= fence; |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 4993 | if (unlikely(qp->flags_en & MLX5_QP_FLAG_SIGNATURE)) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4994 | ctrl->signature = wq_sig(ctrl); |
| 4995 | |
| 4996 | qp->sq.wrid[idx] = wr_id; |
| 4997 | qp->sq.w_list[idx].opcode = mlx5_opcode; |
| 4998 | qp->sq.wqe_head[idx] = qp->sq.head + nreq; |
| 4999 | qp->sq.cur_post += DIV_ROUND_UP(size * 16, MLX5_SEND_WQE_BB); |
| 5000 | qp->sq.w_list[idx].next = qp->sq.cur_post; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5001 | |
| 5002 | /* We save the edge which was possibly updated during the WQE |
| 5003 | * construction, into SQ's cache. |
| 5004 | */ |
| 5005 | seg = PTR_ALIGN(seg, MLX5_SEND_WQE_BB); |
| 5006 | qp->sq.cur_edge = (unlikely(seg == cur_edge)) ? |
| 5007 | get_sq_edge(&qp->sq, qp->sq.cur_post & |
| 5008 | (qp->sq.wqe_cnt - 1)) : |
| 5009 | cur_edge; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 5010 | } |
| 5011 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5012 | static int _mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 5013 | const struct ib_send_wr **bad_wr, bool drain) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5014 | { |
| 5015 | struct mlx5_wqe_ctrl_seg *ctrl = NULL; /* compiler warning */ |
| 5016 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 5017 | struct mlx5_core_dev *mdev = dev->mdev; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5018 | struct ib_reg_wr reg_pi_wr; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5019 | struct mlx5_ib_qp *qp; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 5020 | struct mlx5_ib_mr *mr; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5021 | struct mlx5_ib_mr *pi_mr; |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5022 | struct mlx5_ib_mr pa_pi_mr; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5023 | struct ib_sig_attrs *sig_attrs; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5024 | struct mlx5_wqe_xrc_seg *xrc; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5025 | struct mlx5_bf *bf; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5026 | void *cur_edge; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5027 | int uninitialized_var(size); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5028 | unsigned long flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5029 | unsigned idx; |
| 5030 | int err = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5031 | int num_sge; |
| 5032 | void *seg; |
| 5033 | int nreq; |
| 5034 | int i; |
| 5035 | u8 next_fence = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5036 | u8 fence; |
| 5037 | |
Parav Pandit | 6c75520 | 2018-08-28 14:45:29 +0300 | [diff] [blame] | 5038 | if (unlikely(mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR && |
| 5039 | !drain)) { |
| 5040 | *bad_wr = wr; |
| 5041 | return -EIO; |
| 5042 | } |
| 5043 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5044 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5045 | return mlx5_ib_gsi_post_send(ibqp, wr, bad_wr); |
| 5046 | |
| 5047 | qp = to_mqp(ibqp); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 5048 | bf = &qp->bf; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5049 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5050 | spin_lock_irqsave(&qp->sq.lock, flags); |
| 5051 | |
| 5052 | for (nreq = 0; wr; nreq++, wr = wr->next) { |
Fabian Frederick | a8f731e | 2014-08-12 19:20:08 -0400 | [diff] [blame] | 5053 | if (unlikely(wr->opcode >= ARRAY_SIZE(mlx5_ib_opcode))) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5054 | mlx5_ib_warn(dev, "\n"); |
| 5055 | err = -EINVAL; |
| 5056 | *bad_wr = wr; |
| 5057 | goto out; |
| 5058 | } |
| 5059 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5060 | num_sge = wr->num_sge; |
| 5061 | if (unlikely(num_sge > qp->sq.max_gs)) { |
| 5062 | mlx5_ib_warn(dev, "\n"); |
Chuck Lever | 24be409 | 2016-08-28 10:58:34 +0300 | [diff] [blame] | 5063 | err = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5064 | *bad_wr = wr; |
| 5065 | goto out; |
| 5066 | } |
| 5067 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5068 | err = begin_wqe(qp, &seg, &ctrl, wr, &idx, &size, &cur_edge, |
| 5069 | nreq); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 5070 | if (err) { |
| 5071 | mlx5_ib_warn(dev, "\n"); |
| 5072 | err = -ENOMEM; |
| 5073 | *bad_wr = wr; |
| 5074 | goto out; |
| 5075 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5076 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5077 | if (wr->opcode == IB_WR_REG_MR || |
| 5078 | wr->opcode == IB_WR_REG_MR_INTEGRITY) { |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5079 | fence = dev->umr_fence; |
| 5080 | next_fence = MLX5_FENCE_MODE_INITIATOR_SMALL; |
Majd Dibbiny | 074fca3 | 2018-11-05 08:07:37 +0200 | [diff] [blame] | 5081 | } else { |
| 5082 | if (wr->send_flags & IB_SEND_FENCE) { |
| 5083 | if (qp->next_fence) |
| 5084 | fence = MLX5_FENCE_MODE_SMALL_AND_FENCE; |
| 5085 | else |
| 5086 | fence = MLX5_FENCE_MODE_FENCE; |
| 5087 | } else { |
| 5088 | fence = qp->next_fence; |
| 5089 | } |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5090 | } |
| 5091 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5092 | switch (ibqp->qp_type) { |
| 5093 | case IB_QPT_XRC_INI: |
| 5094 | xrc = seg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5095 | seg += sizeof(*xrc); |
| 5096 | size += sizeof(*xrc) / 16; |
| 5097 | /* fall through */ |
| 5098 | case IB_QPT_RC: |
| 5099 | switch (wr->opcode) { |
| 5100 | case IB_WR_RDMA_READ: |
| 5101 | case IB_WR_RDMA_WRITE: |
| 5102 | case IB_WR_RDMA_WRITE_WITH_IMM: |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 5103 | set_raddr_seg(seg, rdma_wr(wr)->remote_addr, |
| 5104 | rdma_wr(wr)->rkey); |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 5105 | seg += sizeof(struct mlx5_wqe_raddr_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5106 | size += sizeof(struct mlx5_wqe_raddr_seg) / 16; |
| 5107 | break; |
| 5108 | |
| 5109 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 5110 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5111 | case IB_WR_MASKED_ATOMIC_CMP_AND_SWP: |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 5112 | mlx5_ib_warn(dev, "Atomic operations are not supported yet\n"); |
| 5113 | err = -ENOSYS; |
| 5114 | *bad_wr = wr; |
| 5115 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5116 | |
| 5117 | case IB_WR_LOCAL_INV: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5118 | qp->sq.wr_data[idx] = IB_WR_LOCAL_INV; |
| 5119 | ctrl->imm = cpu_to_be32(wr->ex.invalidate_rkey); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5120 | set_linv_wr(qp, &seg, &size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5121 | num_sge = 0; |
| 5122 | break; |
| 5123 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5124 | case IB_WR_REG_MR: |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5125 | qp->sq.wr_data[idx] = IB_WR_REG_MR; |
| 5126 | ctrl->imm = cpu_to_be32(reg_wr(wr)->key); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5127 | err = set_reg_wr(qp, reg_wr(wr), &seg, &size, |
Max Gurtovoy | 9ac7c4b | 2019-06-11 18:52:44 +0300 | [diff] [blame] | 5128 | &cur_edge, true); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 5129 | if (err) { |
| 5130 | *bad_wr = wr; |
| 5131 | goto out; |
| 5132 | } |
| 5133 | num_sge = 0; |
| 5134 | break; |
| 5135 | |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5136 | case IB_WR_REG_MR_INTEGRITY: |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5137 | qp->sq.wr_data[idx] = IB_WR_REG_MR_INTEGRITY; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5138 | |
| 5139 | mr = to_mmr(reg_wr(wr)->mr); |
| 5140 | pi_mr = mr->pi_mr; |
| 5141 | |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5142 | if (pi_mr) { |
| 5143 | memset(®_pi_wr, 0, |
| 5144 | sizeof(struct ib_reg_wr)); |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5145 | |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5146 | reg_pi_wr.mr = &pi_mr->ibmr; |
| 5147 | reg_pi_wr.access = reg_wr(wr)->access; |
| 5148 | reg_pi_wr.key = pi_mr->ibmr.rkey; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5149 | |
Max Gurtovoy | 2563e2f | 2019-06-11 18:52:56 +0300 | [diff] [blame] | 5150 | ctrl->imm = cpu_to_be32(reg_pi_wr.key); |
| 5151 | /* UMR for data + prot registration */ |
| 5152 | err = set_reg_wr(qp, ®_pi_wr, &seg, |
| 5153 | &size, &cur_edge, |
| 5154 | false); |
| 5155 | if (err) { |
| 5156 | *bad_wr = wr; |
| 5157 | goto out; |
| 5158 | } |
| 5159 | finish_wqe(qp, ctrl, seg, size, |
| 5160 | cur_edge, idx, wr->wr_id, |
| 5161 | nreq, fence, |
| 5162 | MLX5_OPCODE_UMR); |
| 5163 | |
| 5164 | err = begin_wqe(qp, &seg, &ctrl, wr, |
| 5165 | &idx, &size, &cur_edge, |
| 5166 | nreq); |
| 5167 | if (err) { |
| 5168 | mlx5_ib_warn(dev, "\n"); |
| 5169 | err = -ENOMEM; |
| 5170 | *bad_wr = wr; |
| 5171 | goto out; |
| 5172 | } |
| 5173 | } else { |
| 5174 | memset(&pa_pi_mr, 0, |
| 5175 | sizeof(struct mlx5_ib_mr)); |
| 5176 | /* No UMR, use local_dma_lkey */ |
| 5177 | pa_pi_mr.ibmr.lkey = |
| 5178 | mr->ibmr.pd->local_dma_lkey; |
| 5179 | |
| 5180 | pa_pi_mr.ndescs = mr->ndescs; |
| 5181 | pa_pi_mr.data_length = mr->data_length; |
| 5182 | pa_pi_mr.data_iova = mr->data_iova; |
| 5183 | if (mr->meta_ndescs) { |
| 5184 | pa_pi_mr.meta_ndescs = |
| 5185 | mr->meta_ndescs; |
| 5186 | pa_pi_mr.meta_length = |
| 5187 | mr->meta_length; |
| 5188 | pa_pi_mr.pi_iova = mr->pi_iova; |
| 5189 | } |
| 5190 | |
| 5191 | pa_pi_mr.ibmr.length = mr->ibmr.length; |
| 5192 | mr->pi_mr = &pa_pi_mr; |
Max Gurtovoy | 38ca87c | 2019-06-11 18:52:46 +0300 | [diff] [blame] | 5193 | } |
| 5194 | ctrl->imm = cpu_to_be32(mr->ibmr.rkey); |
| 5195 | /* UMR for sig MR */ |
| 5196 | err = set_pi_umr_wr(wr, qp, &seg, &size, |
| 5197 | &cur_edge); |
| 5198 | if (err) { |
| 5199 | mlx5_ib_warn(dev, "\n"); |
| 5200 | *bad_wr = wr; |
| 5201 | goto out; |
| 5202 | } |
| 5203 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 5204 | wr->wr_id, nreq, fence, |
| 5205 | MLX5_OPCODE_UMR); |
| 5206 | |
| 5207 | /* |
| 5208 | * SET_PSV WQEs are not signaled and solicited |
| 5209 | * on error |
| 5210 | */ |
| 5211 | sig_attrs = mr->ibmr.sig_attrs; |
| 5212 | err = __begin_wqe(qp, &seg, &ctrl, wr, &idx, |
| 5213 | &size, &cur_edge, nreq, false, |
| 5214 | true); |
| 5215 | if (err) { |
| 5216 | mlx5_ib_warn(dev, "\n"); |
| 5217 | err = -ENOMEM; |
| 5218 | *bad_wr = wr; |
| 5219 | goto out; |
| 5220 | } |
| 5221 | err = set_psv_wr(&sig_attrs->mem, |
| 5222 | mr->sig->psv_memory.psv_idx, |
| 5223 | &seg, &size); |
| 5224 | if (err) { |
| 5225 | mlx5_ib_warn(dev, "\n"); |
| 5226 | *bad_wr = wr; |
| 5227 | goto out; |
| 5228 | } |
| 5229 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 5230 | wr->wr_id, nreq, next_fence, |
| 5231 | MLX5_OPCODE_SET_PSV); |
| 5232 | |
| 5233 | err = __begin_wqe(qp, &seg, &ctrl, wr, &idx, |
| 5234 | &size, &cur_edge, nreq, false, |
| 5235 | true); |
| 5236 | if (err) { |
| 5237 | mlx5_ib_warn(dev, "\n"); |
| 5238 | err = -ENOMEM; |
| 5239 | *bad_wr = wr; |
| 5240 | goto out; |
| 5241 | } |
| 5242 | err = set_psv_wr(&sig_attrs->wire, |
| 5243 | mr->sig->psv_wire.psv_idx, |
| 5244 | &seg, &size); |
| 5245 | if (err) { |
| 5246 | mlx5_ib_warn(dev, "\n"); |
| 5247 | *bad_wr = wr; |
| 5248 | goto out; |
| 5249 | } |
| 5250 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 5251 | wr->wr_id, nreq, next_fence, |
| 5252 | MLX5_OPCODE_SET_PSV); |
| 5253 | |
| 5254 | qp->next_fence = |
| 5255 | MLX5_FENCE_MODE_INITIATOR_SMALL; |
| 5256 | num_sge = 0; |
| 5257 | goto skip_psv; |
| 5258 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5259 | default: |
| 5260 | break; |
| 5261 | } |
| 5262 | break; |
| 5263 | |
| 5264 | case IB_QPT_UC: |
| 5265 | switch (wr->opcode) { |
| 5266 | case IB_WR_RDMA_WRITE: |
| 5267 | case IB_WR_RDMA_WRITE_WITH_IMM: |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 5268 | set_raddr_seg(seg, rdma_wr(wr)->remote_addr, |
| 5269 | rdma_wr(wr)->rkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5270 | seg += sizeof(struct mlx5_wqe_raddr_seg); |
| 5271 | size += sizeof(struct mlx5_wqe_raddr_seg) / 16; |
| 5272 | break; |
| 5273 | |
| 5274 | default: |
| 5275 | break; |
| 5276 | } |
| 5277 | break; |
| 5278 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5279 | case IB_QPT_SMI: |
Maor Gottlieb | 1e0e50b | 2017-01-18 14:10:34 +0200 | [diff] [blame] | 5280 | if (unlikely(!mdev->port_caps[qp->port - 1].has_smi)) { |
| 5281 | mlx5_ib_warn(dev, "Send SMP MADs is not allowed\n"); |
| 5282 | err = -EPERM; |
| 5283 | *bad_wr = wr; |
| 5284 | goto out; |
| 5285 | } |
Bart Van Assche | f6b1ee3 | 2017-10-11 10:49:07 -0700 | [diff] [blame] | 5286 | /* fall through */ |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5287 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5288 | set_datagram_seg(seg, wr); |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 5289 | seg += sizeof(struct mlx5_wqe_datagram_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5290 | size += sizeof(struct mlx5_wqe_datagram_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5291 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
| 5292 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5293 | break; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 5294 | case IB_QPT_UD: |
| 5295 | set_datagram_seg(seg, wr); |
| 5296 | seg += sizeof(struct mlx5_wqe_datagram_seg); |
| 5297 | size += sizeof(struct mlx5_wqe_datagram_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5298 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 5299 | |
| 5300 | /* handle qp that supports ud offload */ |
| 5301 | if (qp->flags & IB_QP_CREATE_IPOIB_UD_LSO) { |
| 5302 | struct mlx5_wqe_eth_pad *pad; |
| 5303 | |
| 5304 | pad = seg; |
| 5305 | memset(pad, 0, sizeof(struct mlx5_wqe_eth_pad)); |
| 5306 | seg += sizeof(struct mlx5_wqe_eth_pad); |
| 5307 | size += sizeof(struct mlx5_wqe_eth_pad) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5308 | set_eth_seg(wr, qp, &seg, &size, &cur_edge); |
| 5309 | handle_post_send_edge(&qp->sq, &seg, size, |
| 5310 | &cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 5311 | } |
| 5312 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5313 | case MLX5_IB_QPT_REG_UMR: |
| 5314 | if (wr->opcode != MLX5_IB_WR_UMR) { |
| 5315 | err = -EINVAL; |
| 5316 | mlx5_ib_warn(dev, "bad opcode\n"); |
| 5317 | goto out; |
| 5318 | } |
| 5319 | qp->sq.wr_data[idx] = MLX5_IB_WR_UMR; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 5320 | ctrl->imm = cpu_to_be32(umr_wr(wr)->mkey); |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 5321 | err = set_reg_umr_segment(dev, seg, wr, !!(MLX5_CAP_GEN(mdev, atomic))); |
| 5322 | if (unlikely(err)) |
| 5323 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5324 | seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 5325 | size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5326 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5327 | set_reg_mkey_segment(seg, wr); |
| 5328 | seg += sizeof(struct mlx5_mkey_seg); |
| 5329 | size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5330 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5331 | break; |
| 5332 | |
| 5333 | default: |
| 5334 | break; |
| 5335 | } |
| 5336 | |
| 5337 | if (wr->send_flags & IB_SEND_INLINE && num_sge) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5338 | err = set_data_inl_seg(qp, wr, &seg, &size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5339 | if (unlikely(err)) { |
| 5340 | mlx5_ib_warn(dev, "\n"); |
| 5341 | *bad_wr = wr; |
| 5342 | goto out; |
| 5343 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5344 | } else { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5345 | for (i = 0; i < num_sge; i++) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5346 | handle_post_send_edge(&qp->sq, &seg, size, |
| 5347 | &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5348 | if (likely(wr->sg_list[i].length)) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5349 | set_data_ptr_seg |
| 5350 | ((struct mlx5_wqe_data_seg *)seg, |
| 5351 | wr->sg_list + i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5352 | size += sizeof(struct mlx5_wqe_data_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5353 | seg += sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5354 | } |
| 5355 | } |
| 5356 | } |
| 5357 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 5358 | qp->next_fence = next_fence; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5359 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, wr->wr_id, nreq, |
| 5360 | fence, mlx5_ib_opcode[wr->opcode]); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 5361 | skip_psv: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5362 | if (0) |
| 5363 | dump_wqe(qp, idx, size); |
| 5364 | } |
| 5365 | |
| 5366 | out: |
| 5367 | if (likely(nreq)) { |
| 5368 | qp->sq.head += nreq; |
| 5369 | |
| 5370 | /* Make sure that descriptors are written before |
| 5371 | * updating doorbell record and ringing the doorbell |
| 5372 | */ |
| 5373 | wmb(); |
| 5374 | |
| 5375 | qp->db.db[MLX5_SND_DBR] = cpu_to_be32(qp->sq.cur_post); |
| 5376 | |
Eli Cohen | ada388f | 2014-01-14 17:45:16 +0200 | [diff] [blame] | 5377 | /* Make sure doorbell record is visible to the HCA before |
| 5378 | * we hit doorbell */ |
| 5379 | wmb(); |
| 5380 | |
Maxim Mikityanskiy | bbf29f6 | 2019-03-29 15:37:52 -0700 | [diff] [blame] | 5381 | mlx5_write64((__be32 *)ctrl, bf->bfreg->map + bf->offset); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 5382 | /* Make sure doorbells don't leak out of SQ spinlock |
| 5383 | * and reach the HCA out of order. |
| 5384 | */ |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5385 | bf->offset ^= bf->buf_size; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5386 | } |
| 5387 | |
| 5388 | spin_unlock_irqrestore(&qp->sq.lock, flags); |
| 5389 | |
| 5390 | return err; |
| 5391 | } |
| 5392 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5393 | int mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 5394 | const struct ib_send_wr **bad_wr) |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5395 | { |
| 5396 | return _mlx5_ib_post_send(ibqp, wr, bad_wr, false); |
| 5397 | } |
| 5398 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5399 | static void set_sig_seg(struct mlx5_rwqe_sig *sig, int size) |
| 5400 | { |
| 5401 | sig->signature = calc_sig(sig, size); |
| 5402 | } |
| 5403 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5404 | static int _mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 5405 | const struct ib_recv_wr **bad_wr, bool drain) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5406 | { |
| 5407 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 5408 | struct mlx5_wqe_data_seg *scat; |
| 5409 | struct mlx5_rwqe_sig *sig; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 5410 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 5411 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5412 | unsigned long flags; |
| 5413 | int err = 0; |
| 5414 | int nreq; |
| 5415 | int ind; |
| 5416 | int i; |
| 5417 | |
Parav Pandit | 6c75520 | 2018-08-28 14:45:29 +0300 | [diff] [blame] | 5418 | if (unlikely(mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR && |
| 5419 | !drain)) { |
| 5420 | *bad_wr = wr; |
| 5421 | return -EIO; |
| 5422 | } |
| 5423 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5424 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5425 | return mlx5_ib_gsi_post_recv(ibqp, wr, bad_wr); |
| 5426 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5427 | spin_lock_irqsave(&qp->rq.lock, flags); |
| 5428 | |
| 5429 | ind = qp->rq.head & (qp->rq.wqe_cnt - 1); |
| 5430 | |
| 5431 | for (nreq = 0; wr; nreq++, wr = wr->next) { |
| 5432 | if (mlx5_wq_overflow(&qp->rq, nreq, qp->ibqp.recv_cq)) { |
| 5433 | err = -ENOMEM; |
| 5434 | *bad_wr = wr; |
| 5435 | goto out; |
| 5436 | } |
| 5437 | |
| 5438 | if (unlikely(wr->num_sge > qp->rq.max_gs)) { |
| 5439 | err = -EINVAL; |
| 5440 | *bad_wr = wr; |
| 5441 | goto out; |
| 5442 | } |
| 5443 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5444 | scat = mlx5_frag_buf_get_wqe(&qp->rq.fbc, ind); |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 5445 | if (qp->flags_en & MLX5_QP_FLAG_SIGNATURE) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5446 | scat++; |
| 5447 | |
| 5448 | for (i = 0; i < wr->num_sge; i++) |
| 5449 | set_data_ptr_seg(scat + i, wr->sg_list + i); |
| 5450 | |
| 5451 | if (i < qp->rq.max_gs) { |
| 5452 | scat[i].byte_count = 0; |
| 5453 | scat[i].lkey = cpu_to_be32(MLX5_INVALID_LKEY); |
| 5454 | scat[i].addr = 0; |
| 5455 | } |
| 5456 | |
Leon Romanovsky | c95e6d5 | 2020-04-27 18:46:15 +0300 | [diff] [blame] | 5457 | if (qp->flags_en & MLX5_QP_FLAG_SIGNATURE) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5458 | sig = (struct mlx5_rwqe_sig *)scat; |
| 5459 | set_sig_seg(sig, (qp->rq.max_gs + 1) << 2); |
| 5460 | } |
| 5461 | |
| 5462 | qp->rq.wrid[ind] = wr->wr_id; |
| 5463 | |
| 5464 | ind = (ind + 1) & (qp->rq.wqe_cnt - 1); |
| 5465 | } |
| 5466 | |
| 5467 | out: |
| 5468 | if (likely(nreq)) { |
| 5469 | qp->rq.head += nreq; |
| 5470 | |
| 5471 | /* Make sure that descriptors are written before |
| 5472 | * doorbell record. |
| 5473 | */ |
| 5474 | wmb(); |
| 5475 | |
| 5476 | *qp->db.db = cpu_to_be32(qp->rq.head & 0xffff); |
| 5477 | } |
| 5478 | |
| 5479 | spin_unlock_irqrestore(&qp->rq.lock, flags); |
| 5480 | |
| 5481 | return err; |
| 5482 | } |
| 5483 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5484 | int mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 5485 | const struct ib_recv_wr **bad_wr) |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5486 | { |
| 5487 | return _mlx5_ib_post_recv(ibqp, wr, bad_wr, false); |
| 5488 | } |
| 5489 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5490 | static inline enum ib_qp_state to_ib_qp_state(enum mlx5_qp_state mlx5_state) |
| 5491 | { |
| 5492 | switch (mlx5_state) { |
| 5493 | case MLX5_QP_STATE_RST: return IB_QPS_RESET; |
| 5494 | case MLX5_QP_STATE_INIT: return IB_QPS_INIT; |
| 5495 | case MLX5_QP_STATE_RTR: return IB_QPS_RTR; |
| 5496 | case MLX5_QP_STATE_RTS: return IB_QPS_RTS; |
| 5497 | case MLX5_QP_STATE_SQ_DRAINING: |
| 5498 | case MLX5_QP_STATE_SQD: return IB_QPS_SQD; |
| 5499 | case MLX5_QP_STATE_SQER: return IB_QPS_SQE; |
| 5500 | case MLX5_QP_STATE_ERR: return IB_QPS_ERR; |
| 5501 | default: return -1; |
| 5502 | } |
| 5503 | } |
| 5504 | |
| 5505 | static inline enum ib_mig_state to_ib_mig_state(int mlx5_mig_state) |
| 5506 | { |
| 5507 | switch (mlx5_mig_state) { |
| 5508 | case MLX5_QP_PM_ARMED: return IB_MIG_ARMED; |
| 5509 | case MLX5_QP_PM_REARM: return IB_MIG_REARM; |
| 5510 | case MLX5_QP_PM_MIGRATED: return IB_MIG_MIGRATED; |
| 5511 | default: return -1; |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | static int to_ib_qp_access_flags(int mlx5_flags) |
| 5516 | { |
| 5517 | int ib_flags = 0; |
| 5518 | |
| 5519 | if (mlx5_flags & MLX5_QP_BIT_RRE) |
| 5520 | ib_flags |= IB_ACCESS_REMOTE_READ; |
| 5521 | if (mlx5_flags & MLX5_QP_BIT_RWE) |
| 5522 | ib_flags |= IB_ACCESS_REMOTE_WRITE; |
| 5523 | if (mlx5_flags & MLX5_QP_BIT_RAE) |
| 5524 | ib_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 5525 | |
| 5526 | return ib_flags; |
| 5527 | } |
| 5528 | |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5529 | static void to_rdma_ah_attr(struct mlx5_ib_dev *ibdev, |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5530 | struct rdma_ah_attr *ah_attr, |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5531 | struct mlx5_qp_path *path) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5532 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5533 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5534 | memset(ah_attr, 0, sizeof(*ah_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5535 | |
Jason Gunthorpe | e7996a9 | 2018-01-29 13:26:40 -0700 | [diff] [blame] | 5536 | if (!path->port || path->port > ibdev->num_ports) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5537 | return; |
| 5538 | |
Leon Romanovsky | ae59c3f | 2018-01-12 07:58:39 +0200 | [diff] [blame] | 5539 | ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, path->port); |
| 5540 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5541 | rdma_ah_set_port_num(ah_attr, path->port); |
| 5542 | rdma_ah_set_sl(ah_attr, path->dci_cfi_prio_sl & 0xf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5543 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5544 | rdma_ah_set_dlid(ah_attr, be16_to_cpu(path->rlid)); |
| 5545 | rdma_ah_set_path_bits(ah_attr, path->grh_mlid & 0x7f); |
| 5546 | rdma_ah_set_static_rate(ah_attr, |
| 5547 | path->static_rate ? path->static_rate - 5 : 0); |
| 5548 | if (path->grh_mlid & (1 << 7)) { |
| 5549 | u32 tc_fl = be32_to_cpu(path->tclass_flowlabel); |
| 5550 | |
| 5551 | rdma_ah_set_grh(ah_attr, NULL, |
| 5552 | tc_fl & 0xfffff, |
| 5553 | path->mgid_index, |
| 5554 | path->hop_limit, |
| 5555 | (tc_fl >> 20) & 0xff); |
| 5556 | rdma_ah_set_dgid_raw(ah_attr, path->rgid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5557 | } |
| 5558 | } |
| 5559 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5560 | static int query_raw_packet_qp_sq_state(struct mlx5_ib_dev *dev, |
| 5561 | struct mlx5_ib_sq *sq, |
| 5562 | u8 *sq_state) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5563 | { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5564 | int err; |
| 5565 | |
Eran Ben Elisha | 2816077 | 2017-12-26 15:17:05 +0200 | [diff] [blame] | 5566 | 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] | 5567 | if (err) |
| 5568 | goto out; |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5569 | sq->state = *sq_state; |
| 5570 | |
| 5571 | out: |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5572 | return err; |
| 5573 | } |
| 5574 | |
| 5575 | static int query_raw_packet_qp_rq_state(struct mlx5_ib_dev *dev, |
| 5576 | struct mlx5_ib_rq *rq, |
| 5577 | u8 *rq_state) |
| 5578 | { |
| 5579 | void *out; |
| 5580 | void *rqc; |
| 5581 | int inlen; |
| 5582 | int err; |
| 5583 | |
| 5584 | inlen = MLX5_ST_SZ_BYTES(query_rq_out); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5585 | out = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5586 | if (!out) |
| 5587 | return -ENOMEM; |
| 5588 | |
| 5589 | err = mlx5_core_query_rq(dev->mdev, rq->base.mqp.qpn, out); |
| 5590 | if (err) |
| 5591 | goto out; |
| 5592 | |
| 5593 | rqc = MLX5_ADDR_OF(query_rq_out, out, rq_context); |
| 5594 | *rq_state = MLX5_GET(rqc, rqc, state); |
| 5595 | rq->state = *rq_state; |
| 5596 | |
| 5597 | out: |
| 5598 | kvfree(out); |
| 5599 | return err; |
| 5600 | } |
| 5601 | |
| 5602 | static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, |
| 5603 | struct mlx5_ib_qp *qp, u8 *qp_state) |
| 5604 | { |
| 5605 | static const u8 sqrq_trans[MLX5_RQ_NUM_STATE][MLX5_SQ_NUM_STATE] = { |
| 5606 | [MLX5_RQC_STATE_RST] = { |
| 5607 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 5608 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 5609 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE_BAD, |
| 5610 | [MLX5_SQ_STATE_NA] = IB_QPS_RESET, |
| 5611 | }, |
| 5612 | [MLX5_RQC_STATE_RDY] = { |
| 5613 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 5614 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 5615 | [MLX5_SQC_STATE_ERR] = IB_QPS_SQE, |
| 5616 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE, |
| 5617 | }, |
| 5618 | [MLX5_RQC_STATE_ERR] = { |
| 5619 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 5620 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 5621 | [MLX5_SQC_STATE_ERR] = IB_QPS_ERR, |
| 5622 | [MLX5_SQ_STATE_NA] = IB_QPS_ERR, |
| 5623 | }, |
| 5624 | [MLX5_RQ_STATE_NA] = { |
| 5625 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 5626 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 5627 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE, |
| 5628 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE_BAD, |
| 5629 | }, |
| 5630 | }; |
| 5631 | |
| 5632 | *qp_state = sqrq_trans[rq_state][sq_state]; |
| 5633 | |
| 5634 | if (*qp_state == MLX5_QP_STATE_BAD) { |
| 5635 | WARN(1, "Buggy Raw Packet QP state, SQ 0x%x state: 0x%x, RQ 0x%x state: 0x%x", |
| 5636 | qp->raw_packet_qp.sq.base.mqp.qpn, sq_state, |
| 5637 | qp->raw_packet_qp.rq.base.mqp.qpn, rq_state); |
| 5638 | return -EINVAL; |
| 5639 | } |
| 5640 | |
| 5641 | if (*qp_state == MLX5_QP_STATE) |
| 5642 | *qp_state = qp->state; |
| 5643 | |
| 5644 | return 0; |
| 5645 | } |
| 5646 | |
| 5647 | static int query_raw_packet_qp_state(struct mlx5_ib_dev *dev, |
| 5648 | struct mlx5_ib_qp *qp, |
| 5649 | u8 *raw_packet_qp_state) |
| 5650 | { |
| 5651 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 5652 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 5653 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 5654 | int err; |
| 5655 | u8 sq_state = MLX5_SQ_STATE_NA; |
| 5656 | u8 rq_state = MLX5_RQ_STATE_NA; |
| 5657 | |
| 5658 | if (qp->sq.wqe_cnt) { |
| 5659 | err = query_raw_packet_qp_sq_state(dev, sq, &sq_state); |
| 5660 | if (err) |
| 5661 | return err; |
| 5662 | } |
| 5663 | |
| 5664 | if (qp->rq.wqe_cnt) { |
| 5665 | err = query_raw_packet_qp_rq_state(dev, rq, &rq_state); |
| 5666 | if (err) |
| 5667 | return err; |
| 5668 | } |
| 5669 | |
| 5670 | return sqrq_state_to_qp_state(sq_state, rq_state, qp, |
| 5671 | raw_packet_qp_state); |
| 5672 | } |
| 5673 | |
| 5674 | static int query_qp_attr(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 5675 | struct ib_qp_attr *qp_attr) |
| 5676 | { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5677 | int outlen = MLX5_ST_SZ_BYTES(query_qp_out); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5678 | struct mlx5_qp_context *context; |
| 5679 | int mlx5_state; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5680 | u32 *outb; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5681 | int err = 0; |
| 5682 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5683 | outb = kzalloc(outlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5684 | if (!outb) |
| 5685 | return -ENOMEM; |
| 5686 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5687 | 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] | 5688 | if (err) |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5689 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5690 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5691 | /* FIXME: use MLX5_GET rather than mlx5_qp_context manual struct */ |
| 5692 | context = (struct mlx5_qp_context *)MLX5_ADDR_OF(query_qp_out, outb, qpc); |
| 5693 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5694 | mlx5_state = be32_to_cpu(context->flags) >> 28; |
| 5695 | |
| 5696 | qp->state = to_ib_qp_state(mlx5_state); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5697 | qp_attr->path_mtu = context->mtu_msgmax >> 5; |
| 5698 | qp_attr->path_mig_state = |
| 5699 | to_ib_mig_state((be32_to_cpu(context->flags) >> 11) & 0x3); |
| 5700 | qp_attr->qkey = be32_to_cpu(context->qkey); |
| 5701 | qp_attr->rq_psn = be32_to_cpu(context->rnr_nextrecvpsn) & 0xffffff; |
| 5702 | qp_attr->sq_psn = be32_to_cpu(context->next_send_psn) & 0xffffff; |
| 5703 | qp_attr->dest_qp_num = be32_to_cpu(context->log_pg_sz_remote_qpn) & 0xffffff; |
| 5704 | qp_attr->qp_access_flags = |
| 5705 | to_ib_qp_access_flags(be32_to_cpu(context->params2)); |
| 5706 | |
| 5707 | 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] | 5708 | to_rdma_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path); |
| 5709 | 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] | 5710 | qp_attr->alt_pkey_index = |
| 5711 | be16_to_cpu(context->alt_path.pkey_index); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5712 | qp_attr->alt_port_num = |
| 5713 | rdma_ah_get_port_num(&qp_attr->alt_ah_attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5714 | } |
| 5715 | |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 5716 | qp_attr->pkey_index = be16_to_cpu(context->pri_path.pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5717 | qp_attr->port_num = context->pri_path.port; |
| 5718 | |
| 5719 | /* qp_attr->en_sqd_async_notify is only applicable in modify qp */ |
| 5720 | qp_attr->sq_draining = mlx5_state == MLX5_QP_STATE_SQ_DRAINING; |
| 5721 | |
| 5722 | qp_attr->max_rd_atomic = 1 << ((be32_to_cpu(context->params1) >> 21) & 0x7); |
| 5723 | |
| 5724 | qp_attr->max_dest_rd_atomic = |
| 5725 | 1 << ((be32_to_cpu(context->params2) >> 21) & 0x7); |
| 5726 | qp_attr->min_rnr_timer = |
| 5727 | (be32_to_cpu(context->rnr_nextrecvpsn) >> 24) & 0x1f; |
| 5728 | qp_attr->timeout = context->pri_path.ackto_lt >> 3; |
| 5729 | qp_attr->retry_cnt = (be32_to_cpu(context->params1) >> 16) & 0x7; |
| 5730 | qp_attr->rnr_retry = (be32_to_cpu(context->params1) >> 13) & 0x7; |
| 5731 | qp_attr->alt_timeout = context->alt_path.ackto_lt >> 3; |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5732 | |
| 5733 | out: |
| 5734 | kfree(outb); |
| 5735 | return err; |
| 5736 | } |
| 5737 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5738 | static int mlx5_ib_dct_query_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *mqp, |
| 5739 | struct ib_qp_attr *qp_attr, int qp_attr_mask, |
| 5740 | struct ib_qp_init_attr *qp_init_attr) |
| 5741 | { |
| 5742 | struct mlx5_core_dct *dct = &mqp->dct.mdct; |
| 5743 | u32 *out; |
| 5744 | u32 access_flags = 0; |
| 5745 | int outlen = MLX5_ST_SZ_BYTES(query_dct_out); |
| 5746 | void *dctc; |
| 5747 | int err; |
| 5748 | int supported_mask = IB_QP_STATE | |
| 5749 | IB_QP_ACCESS_FLAGS | |
| 5750 | IB_QP_PORT | |
| 5751 | IB_QP_MIN_RNR_TIMER | |
| 5752 | IB_QP_AV | |
| 5753 | IB_QP_PATH_MTU | |
| 5754 | IB_QP_PKEY_INDEX; |
| 5755 | |
| 5756 | if (qp_attr_mask & ~supported_mask) |
| 5757 | return -EINVAL; |
| 5758 | if (mqp->state != IB_QPS_RTR) |
| 5759 | return -EINVAL; |
| 5760 | |
| 5761 | out = kzalloc(outlen, GFP_KERNEL); |
| 5762 | if (!out) |
| 5763 | return -ENOMEM; |
| 5764 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5765 | err = mlx5_core_dct_query(dev, dct, out, outlen); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5766 | if (err) |
| 5767 | goto out; |
| 5768 | |
| 5769 | dctc = MLX5_ADDR_OF(query_dct_out, out, dct_context_entry); |
| 5770 | |
| 5771 | if (qp_attr_mask & IB_QP_STATE) |
| 5772 | qp_attr->qp_state = IB_QPS_RTR; |
| 5773 | |
| 5774 | if (qp_attr_mask & IB_QP_ACCESS_FLAGS) { |
| 5775 | if (MLX5_GET(dctc, dctc, rre)) |
| 5776 | access_flags |= IB_ACCESS_REMOTE_READ; |
| 5777 | if (MLX5_GET(dctc, dctc, rwe)) |
| 5778 | access_flags |= IB_ACCESS_REMOTE_WRITE; |
| 5779 | if (MLX5_GET(dctc, dctc, rae)) |
| 5780 | access_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 5781 | qp_attr->qp_access_flags = access_flags; |
| 5782 | } |
| 5783 | |
| 5784 | if (qp_attr_mask & IB_QP_PORT) |
| 5785 | qp_attr->port_num = MLX5_GET(dctc, dctc, port); |
| 5786 | if (qp_attr_mask & IB_QP_MIN_RNR_TIMER) |
| 5787 | qp_attr->min_rnr_timer = MLX5_GET(dctc, dctc, min_rnr_nak); |
| 5788 | if (qp_attr_mask & IB_QP_AV) { |
| 5789 | qp_attr->ah_attr.grh.traffic_class = MLX5_GET(dctc, dctc, tclass); |
| 5790 | qp_attr->ah_attr.grh.flow_label = MLX5_GET(dctc, dctc, flow_label); |
| 5791 | qp_attr->ah_attr.grh.sgid_index = MLX5_GET(dctc, dctc, my_addr_index); |
| 5792 | qp_attr->ah_attr.grh.hop_limit = MLX5_GET(dctc, dctc, hop_limit); |
| 5793 | } |
| 5794 | if (qp_attr_mask & IB_QP_PATH_MTU) |
| 5795 | qp_attr->path_mtu = MLX5_GET(dctc, dctc, mtu); |
| 5796 | if (qp_attr_mask & IB_QP_PKEY_INDEX) |
| 5797 | qp_attr->pkey_index = MLX5_GET(dctc, dctc, pkey_index); |
| 5798 | out: |
| 5799 | kfree(out); |
| 5800 | return err; |
| 5801 | } |
| 5802 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5803 | int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, |
| 5804 | int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr) |
| 5805 | { |
| 5806 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 5807 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 5808 | int err = 0; |
| 5809 | u8 raw_packet_qp_state; |
| 5810 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 5811 | if (ibqp->rwq_ind_tbl) |
| 5812 | return -ENOSYS; |
| 5813 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5814 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5815 | return mlx5_ib_gsi_query_qp(ibqp, qp_attr, qp_attr_mask, |
| 5816 | qp_init_attr); |
| 5817 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 5818 | /* Not all of output fields are applicable, make sure to zero them */ |
| 5819 | memset(qp_init_attr, 0, sizeof(*qp_init_attr)); |
| 5820 | memset(qp_attr, 0, sizeof(*qp_attr)); |
| 5821 | |
Leon Romanovsky | 7aede1a2 | 2020-04-27 18:46:20 +0300 | [diff] [blame] | 5822 | if (unlikely(qp->type == MLX5_IB_QPT_DCT)) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5823 | return mlx5_ib_dct_query_qp(dev, qp, qp_attr, |
| 5824 | qp_attr_mask, qp_init_attr); |
| 5825 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5826 | mutex_lock(&qp->mutex); |
| 5827 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 5828 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
Leon Romanovsky | 2be08c3 | 2020-04-27 18:46:13 +0300 | [diff] [blame] | 5829 | qp->flags & IB_QP_CREATE_SOURCE_QPN) { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5830 | err = query_raw_packet_qp_state(dev, qp, &raw_packet_qp_state); |
| 5831 | if (err) |
| 5832 | goto out; |
| 5833 | qp->state = raw_packet_qp_state; |
| 5834 | qp_attr->port_num = 1; |
| 5835 | } else { |
| 5836 | err = query_qp_attr(dev, qp, qp_attr); |
| 5837 | if (err) |
| 5838 | goto out; |
| 5839 | } |
| 5840 | |
| 5841 | qp_attr->qp_state = qp->state; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5842 | qp_attr->cur_qp_state = qp_attr->qp_state; |
| 5843 | qp_attr->cap.max_recv_wr = qp->rq.wqe_cnt; |
| 5844 | qp_attr->cap.max_recv_sge = qp->rq.max_gs; |
| 5845 | |
| 5846 | if (!ibqp->uobject) { |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5847 | qp_attr->cap.max_send_wr = qp->sq.max_post; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5848 | qp_attr->cap.max_send_sge = qp->sq.max_gs; |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5849 | qp_init_attr->qp_context = ibqp->qp_context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5850 | } else { |
| 5851 | qp_attr->cap.max_send_wr = 0; |
| 5852 | qp_attr->cap.max_send_sge = 0; |
| 5853 | } |
| 5854 | |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5855 | qp_init_attr->qp_type = ibqp->qp_type; |
| 5856 | qp_init_attr->recv_cq = ibqp->recv_cq; |
| 5857 | qp_init_attr->send_cq = ibqp->send_cq; |
| 5858 | qp_init_attr->srq = ibqp->srq; |
| 5859 | qp_attr->cap.max_inline_data = qp->max_inline_data; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5860 | |
| 5861 | qp_init_attr->cap = qp_attr->cap; |
| 5862 | |
Leon Romanovsky | a8f3ea6 | 2020-04-27 18:46:17 +0300 | [diff] [blame] | 5863 | qp_init_attr->create_flags = qp->flags; |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 5864 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5865 | qp_init_attr->sq_sig_type = qp->sq_signal_bits & MLX5_WQE_CTRL_CQ_UPDATE ? |
| 5866 | IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR; |
| 5867 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5868 | out: |
| 5869 | mutex_unlock(&qp->mutex); |
| 5870 | return err; |
| 5871 | } |
| 5872 | |
| 5873 | struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev, |
Shamir Rabinovitch | ff23dfa | 2019-03-31 19:10:07 +0300 | [diff] [blame] | 5874 | struct ib_udata *udata) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5875 | { |
| 5876 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5877 | struct mlx5_ib_xrcd *xrcd; |
| 5878 | int err; |
| 5879 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 5880 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5881 | return ERR_PTR(-ENOSYS); |
| 5882 | |
| 5883 | xrcd = kmalloc(sizeof(*xrcd), GFP_KERNEL); |
| 5884 | if (!xrcd) |
| 5885 | return ERR_PTR(-ENOMEM); |
| 5886 | |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 5887 | err = mlx5_cmd_xrcd_alloc(dev->mdev, &xrcd->xrcdn, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5888 | if (err) { |
| 5889 | kfree(xrcd); |
| 5890 | return ERR_PTR(-ENOMEM); |
| 5891 | } |
| 5892 | |
| 5893 | return &xrcd->ibxrcd; |
| 5894 | } |
| 5895 | |
Shamir Rabinovitch | c4367a2 | 2019-03-31 19:10:05 +0300 | [diff] [blame] | 5896 | 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] | 5897 | { |
| 5898 | struct mlx5_ib_dev *dev = to_mdev(xrcd->device); |
| 5899 | u32 xrcdn = to_mxrcd(xrcd)->xrcdn; |
| 5900 | int err; |
| 5901 | |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 5902 | err = mlx5_cmd_xrcd_dealloc(dev->mdev, xrcdn, 0); |
Leon Romanovsky | b081808 | 2018-01-28 11:25:30 +0200 | [diff] [blame] | 5903 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5904 | mlx5_ib_warn(dev, "failed to dealloc xrcdn 0x%x\n", xrcdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5905 | |
| 5906 | kfree(xrcd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5907 | return 0; |
| 5908 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5909 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5910 | static void mlx5_ib_wq_event(struct mlx5_core_qp *core_qp, int type) |
| 5911 | { |
| 5912 | struct mlx5_ib_rwq *rwq = to_mibrwq(core_qp); |
| 5913 | struct mlx5_ib_dev *dev = to_mdev(rwq->ibwq.device); |
| 5914 | struct ib_event event; |
| 5915 | |
| 5916 | if (rwq->ibwq.event_handler) { |
| 5917 | event.device = rwq->ibwq.device; |
| 5918 | event.element.wq = &rwq->ibwq; |
| 5919 | switch (type) { |
| 5920 | case MLX5_EVENT_TYPE_WQ_CATAS_ERROR: |
| 5921 | event.event = IB_EVENT_WQ_FATAL; |
| 5922 | break; |
| 5923 | default: |
| 5924 | mlx5_ib_warn(dev, "Unexpected event type %d on WQ %06x\n", type, core_qp->qpn); |
| 5925 | return; |
| 5926 | } |
| 5927 | |
| 5928 | rwq->ibwq.event_handler(&event, rwq->ibwq.wq_context); |
| 5929 | } |
| 5930 | } |
| 5931 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5932 | static int set_delay_drop(struct mlx5_ib_dev *dev) |
| 5933 | { |
| 5934 | int err = 0; |
| 5935 | |
| 5936 | mutex_lock(&dev->delay_drop.lock); |
| 5937 | if (dev->delay_drop.activate) |
| 5938 | goto out; |
| 5939 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 5940 | err = mlx5_core_set_delay_drop(dev, dev->delay_drop.timeout); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5941 | if (err) |
| 5942 | goto out; |
| 5943 | |
| 5944 | dev->delay_drop.activate = true; |
| 5945 | out: |
| 5946 | mutex_unlock(&dev->delay_drop.lock); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5947 | |
| 5948 | if (!err) |
| 5949 | atomic_inc(&dev->delay_drop.rqs_cnt); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5950 | return err; |
| 5951 | } |
| 5952 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5953 | static int create_rq(struct mlx5_ib_rwq *rwq, struct ib_pd *pd, |
| 5954 | struct ib_wq_init_attr *init_attr) |
| 5955 | { |
| 5956 | struct mlx5_ib_dev *dev; |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 5957 | int has_net_offloads; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5958 | __be64 *rq_pas0; |
| 5959 | void *in; |
| 5960 | void *rqc; |
| 5961 | void *wq; |
| 5962 | int inlen; |
| 5963 | int err; |
| 5964 | |
| 5965 | dev = to_mdev(pd->device); |
| 5966 | |
| 5967 | 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] | 5968 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5969 | if (!in) |
| 5970 | return -ENOMEM; |
| 5971 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 5972 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5973 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
| 5974 | MLX5_SET(rqc, rqc, mem_rq_type, |
| 5975 | MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 5976 | MLX5_SET(rqc, rqc, user_index, rwq->user_index); |
| 5977 | MLX5_SET(rqc, rqc, cqn, to_mcq(init_attr->cq)->mcq.cqn); |
| 5978 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 5979 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 5980 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5981 | MLX5_SET(wq, wq, wq_type, |
| 5982 | rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ ? |
| 5983 | MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ : MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 5984 | if (init_attr->create_flags & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 5985 | if (!MLX5_CAP_GEN(dev->mdev, end_pad)) { |
| 5986 | mlx5_ib_dbg(dev, "Scatter end padding is not supported\n"); |
| 5987 | err = -EOPNOTSUPP; |
| 5988 | goto out; |
| 5989 | } else { |
| 5990 | MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN); |
| 5991 | } |
| 5992 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5993 | MLX5_SET(wq, wq, log_wq_stride, rwq->log_rq_stride); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5994 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ) { |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 5995 | /* |
| 5996 | * In Firmware number of strides in each WQE is: |
| 5997 | * "512 * 2^single_wqe_log_num_of_strides" |
| 5998 | * Values 3 to 8 are accepted as 10 to 15, 9 to 18 are |
| 5999 | * accepted as 0 to 9 |
| 6000 | */ |
| 6001 | static const u8 fw_map[] = { 10, 11, 12, 13, 14, 15, 0, 1, |
| 6002 | 2, 3, 4, 5, 6, 7, 8, 9 }; |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6003 | MLX5_SET(wq, wq, two_byte_shift_en, rwq->two_byte_shift_en); |
| 6004 | MLX5_SET(wq, wq, log_wqe_stride_size, |
| 6005 | rwq->single_stride_log_num_of_bytes - |
| 6006 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES); |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 6007 | MLX5_SET(wq, wq, log_wqe_num_of_strides, |
| 6008 | fw_map[rwq->log_num_strides - |
| 6009 | MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES]); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6010 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6011 | MLX5_SET(wq, wq, log_wq_sz, rwq->log_rq_size); |
| 6012 | MLX5_SET(wq, wq, pd, to_mpd(pd)->pdn); |
| 6013 | MLX5_SET(wq, wq, page_offset, rwq->rq_page_offset); |
| 6014 | MLX5_SET(wq, wq, log_wq_pg_sz, rwq->log_page_size); |
| 6015 | MLX5_SET(wq, wq, wq_signature, rwq->wq_sig); |
| 6016 | MLX5_SET64(wq, wq, dbr_addr, rwq->db.dma); |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 6017 | has_net_offloads = MLX5_CAP_GEN(dev->mdev, eth_net_offloads); |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6018 | if (init_attr->create_flags & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 6019 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6020 | mlx5_ib_dbg(dev, "VLAN offloads are not supported\n"); |
| 6021 | err = -EOPNOTSUPP; |
| 6022 | goto out; |
| 6023 | } |
| 6024 | } else { |
| 6025 | MLX5_SET(rqc, rqc, vsd, 1); |
| 6026 | } |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 6027 | if (init_attr->create_flags & IB_WQ_FLAGS_SCATTER_FCS) { |
| 6028 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, scatter_fcs))) { |
| 6029 | mlx5_ib_dbg(dev, "Scatter FCS is not supported\n"); |
| 6030 | err = -EOPNOTSUPP; |
| 6031 | goto out; |
| 6032 | } |
| 6033 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 6034 | } |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6035 | if (init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 6036 | if (!(dev->ib_dev.attrs.raw_packet_caps & |
| 6037 | IB_RAW_PACKET_CAP_DELAY_DROP)) { |
| 6038 | mlx5_ib_dbg(dev, "Delay drop is not supported\n"); |
| 6039 | err = -EOPNOTSUPP; |
| 6040 | goto out; |
| 6041 | } |
| 6042 | MLX5_SET(rqc, rqc, delay_drop_en, 1); |
| 6043 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6044 | rq_pas0 = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 6045 | 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] | 6046 | err = mlx5_core_create_rq_tracked(dev, in, inlen, &rwq->core_qp); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6047 | if (!err && init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 6048 | err = set_delay_drop(dev); |
| 6049 | if (err) { |
| 6050 | mlx5_ib_warn(dev, "Failed to enable delay drop err=%d\n", |
| 6051 | err); |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 6052 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 6053 | } else { |
| 6054 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_DELAY_DROP; |
| 6055 | } |
| 6056 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6057 | out: |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6058 | kvfree(in); |
| 6059 | return err; |
| 6060 | } |
| 6061 | |
| 6062 | static int set_user_rq_size(struct mlx5_ib_dev *dev, |
| 6063 | struct ib_wq_init_attr *wq_init_attr, |
| 6064 | struct mlx5_ib_create_wq *ucmd, |
| 6065 | struct mlx5_ib_rwq *rwq) |
| 6066 | { |
| 6067 | /* Sanity check RQ size before proceeding */ |
| 6068 | if (wq_init_attr->max_wr > (1 << MLX5_CAP_GEN(dev->mdev, log_max_wq_sz))) |
| 6069 | return -EINVAL; |
| 6070 | |
| 6071 | if (!ucmd->rq_wqe_count) |
| 6072 | return -EINVAL; |
| 6073 | |
| 6074 | rwq->wqe_count = ucmd->rq_wqe_count; |
| 6075 | rwq->wqe_shift = ucmd->rq_wqe_shift; |
Leon Romanovsky | 0dfe452 | 2018-08-01 14:25:41 -0700 | [diff] [blame] | 6076 | if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, &rwq->buf_size)) |
| 6077 | return -EINVAL; |
| 6078 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6079 | rwq->log_rq_stride = rwq->wqe_shift; |
| 6080 | rwq->log_rq_size = ilog2(rwq->wqe_count); |
| 6081 | return 0; |
| 6082 | } |
| 6083 | |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 6084 | static bool log_of_strides_valid(struct mlx5_ib_dev *dev, u32 log_num_strides) |
| 6085 | { |
| 6086 | if ((log_num_strides > MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES) || |
| 6087 | (log_num_strides < MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES)) |
| 6088 | return false; |
| 6089 | |
| 6090 | if (!MLX5_CAP_GEN(dev->mdev, ext_stride_num_range) && |
| 6091 | (log_num_strides < MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES)) |
| 6092 | return false; |
| 6093 | |
| 6094 | return true; |
| 6095 | } |
| 6096 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6097 | static int prepare_user_rq(struct ib_pd *pd, |
| 6098 | struct ib_wq_init_attr *init_attr, |
| 6099 | struct ib_udata *udata, |
| 6100 | struct mlx5_ib_rwq *rwq) |
| 6101 | { |
| 6102 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
| 6103 | struct mlx5_ib_create_wq ucmd = {}; |
| 6104 | int err; |
| 6105 | size_t required_cmd_sz; |
| 6106 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6107 | required_cmd_sz = offsetof(typeof(ucmd), single_stride_log_num_of_bytes) |
| 6108 | + sizeof(ucmd.single_stride_log_num_of_bytes); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6109 | if (udata->inlen < required_cmd_sz) { |
| 6110 | mlx5_ib_dbg(dev, "invalid inlen\n"); |
| 6111 | return -EINVAL; |
| 6112 | } |
| 6113 | |
| 6114 | if (udata->inlen > sizeof(ucmd) && |
| 6115 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 6116 | udata->inlen - sizeof(ucmd))) { |
| 6117 | mlx5_ib_dbg(dev, "inlen is not supported\n"); |
| 6118 | return -EOPNOTSUPP; |
| 6119 | } |
| 6120 | |
| 6121 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) { |
| 6122 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 6123 | return -EFAULT; |
| 6124 | } |
| 6125 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6126 | if (ucmd.comp_mask & (~MLX5_IB_CREATE_WQ_STRIDING_RQ)) { |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6127 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 6128 | return -EOPNOTSUPP; |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6129 | } else if (ucmd.comp_mask & MLX5_IB_CREATE_WQ_STRIDING_RQ) { |
| 6130 | if (!MLX5_CAP_GEN(dev->mdev, striding_rq)) { |
| 6131 | mlx5_ib_dbg(dev, "Striding RQ is not supported\n"); |
| 6132 | return -EOPNOTSUPP; |
| 6133 | } |
| 6134 | if ((ucmd.single_stride_log_num_of_bytes < |
| 6135 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES) || |
| 6136 | (ucmd.single_stride_log_num_of_bytes > |
| 6137 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES)) { |
| 6138 | mlx5_ib_dbg(dev, "Invalid log stride size (%u. Range is %u - %u)\n", |
| 6139 | ucmd.single_stride_log_num_of_bytes, |
| 6140 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES, |
| 6141 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES); |
| 6142 | return -EINVAL; |
| 6143 | } |
Mark Zhang | c16339b | 2019-11-15 17:45:55 +0200 | [diff] [blame] | 6144 | if (!log_of_strides_valid(dev, |
| 6145 | ucmd.single_wqe_log_num_of_strides)) { |
| 6146 | mlx5_ib_dbg( |
| 6147 | dev, |
| 6148 | "Invalid log num strides (%u. Range is %u - %u)\n", |
| 6149 | ucmd.single_wqe_log_num_of_strides, |
| 6150 | MLX5_CAP_GEN(dev->mdev, ext_stride_num_range) ? |
| 6151 | MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES : |
| 6152 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES, |
| 6153 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 6154 | return -EINVAL; |
| 6155 | } |
| 6156 | rwq->single_stride_log_num_of_bytes = |
| 6157 | ucmd.single_stride_log_num_of_bytes; |
| 6158 | rwq->log_num_strides = ucmd.single_wqe_log_num_of_strides; |
| 6159 | rwq->two_byte_shift_en = !!ucmd.two_byte_shift_en; |
| 6160 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_STRIDING_RQ; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6161 | } |
| 6162 | |
| 6163 | err = set_user_rq_size(dev, init_attr, &ucmd, rwq); |
| 6164 | if (err) { |
| 6165 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 6166 | return err; |
| 6167 | } |
| 6168 | |
Jason Gunthorpe | b0ea0fa | 2019-01-09 11:15:16 +0200 | [diff] [blame] | 6169 | err = create_user_rq(dev, pd, udata, rwq, &ucmd); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6170 | if (err) { |
| 6171 | mlx5_ib_dbg(dev, "err %d\n", err); |
Gal Pressman | 645ba59 | 2018-10-08 19:44:03 +0300 | [diff] [blame] | 6172 | return err; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6173 | } |
| 6174 | |
| 6175 | rwq->user_index = ucmd.user_index; |
| 6176 | return 0; |
| 6177 | } |
| 6178 | |
| 6179 | struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd, |
| 6180 | struct ib_wq_init_attr *init_attr, |
| 6181 | struct ib_udata *udata) |
| 6182 | { |
| 6183 | struct mlx5_ib_dev *dev; |
| 6184 | struct mlx5_ib_rwq *rwq; |
| 6185 | struct mlx5_ib_create_wq_resp resp = {}; |
| 6186 | size_t min_resp_len; |
| 6187 | int err; |
| 6188 | |
| 6189 | if (!udata) |
| 6190 | return ERR_PTR(-ENOSYS); |
| 6191 | |
| 6192 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 6193 | if (udata->outlen && udata->outlen < min_resp_len) |
| 6194 | return ERR_PTR(-EINVAL); |
| 6195 | |
Maor Gottlieb | ba80013 | 2020-03-22 14:49:06 +0200 | [diff] [blame] | 6196 | if (!capable(CAP_SYS_RAWIO) && |
| 6197 | init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) |
| 6198 | return ERR_PTR(-EPERM); |
| 6199 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6200 | dev = to_mdev(pd->device); |
| 6201 | switch (init_attr->wq_type) { |
| 6202 | case IB_WQT_RQ: |
| 6203 | rwq = kzalloc(sizeof(*rwq), GFP_KERNEL); |
| 6204 | if (!rwq) |
| 6205 | return ERR_PTR(-ENOMEM); |
| 6206 | err = prepare_user_rq(pd, init_attr, udata, rwq); |
| 6207 | if (err) |
| 6208 | goto err; |
| 6209 | err = create_rq(rwq, pd, init_attr); |
| 6210 | if (err) |
| 6211 | goto err_user_rq; |
| 6212 | break; |
| 6213 | default: |
| 6214 | mlx5_ib_dbg(dev, "unsupported wq type %d\n", |
| 6215 | init_attr->wq_type); |
| 6216 | return ERR_PTR(-EINVAL); |
| 6217 | } |
| 6218 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 6219 | rwq->ibwq.wq_num = rwq->core_qp.qpn; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6220 | rwq->ibwq.state = IB_WQS_RESET; |
| 6221 | if (udata->outlen) { |
| 6222 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 6223 | sizeof(resp.response_length); |
| 6224 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 6225 | if (err) |
| 6226 | goto err_copy; |
| 6227 | } |
| 6228 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 6229 | rwq->core_qp.event = mlx5_ib_wq_event; |
| 6230 | rwq->ibwq.event_handler = init_attr->event_handler; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6231 | return &rwq->ibwq; |
| 6232 | |
| 6233 | err_copy: |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 6234 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6235 | err_user_rq: |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 6236 | destroy_user_rq(dev, pd, rwq, udata); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6237 | err: |
| 6238 | kfree(rwq); |
| 6239 | return ERR_PTR(err); |
| 6240 | } |
| 6241 | |
Leon Romanovsky | a49b1dc | 2019-06-12 15:27:41 +0300 | [diff] [blame] | 6242 | 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] | 6243 | { |
| 6244 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 6245 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 6246 | |
Leon Romanovsky | 333fbaa | 2020-04-04 10:40:24 +0300 | [diff] [blame] | 6247 | mlx5_core_destroy_rq_tracked(dev, &rwq->core_qp); |
Shamir Rabinovitch | bdeacab | 2019-03-31 19:10:06 +0300 | [diff] [blame] | 6248 | destroy_user_rq(dev, wq->pd, rwq, udata); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6249 | kfree(rwq); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6250 | } |
| 6251 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6252 | struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device, |
| 6253 | struct ib_rwq_ind_table_init_attr *init_attr, |
| 6254 | struct ib_udata *udata) |
| 6255 | { |
| 6256 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 6257 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl; |
| 6258 | int sz = 1 << init_attr->log_ind_tbl_size; |
| 6259 | struct mlx5_ib_create_rwq_ind_tbl_resp resp = {}; |
| 6260 | size_t min_resp_len; |
| 6261 | int inlen; |
| 6262 | int err; |
| 6263 | int i; |
| 6264 | u32 *in; |
| 6265 | void *rqtc; |
| 6266 | |
| 6267 | if (udata->inlen > 0 && |
| 6268 | !ib_is_udata_cleared(udata, 0, |
| 6269 | udata->inlen)) |
| 6270 | return ERR_PTR(-EOPNOTSUPP); |
| 6271 | |
Maor Gottlieb | efd7f40 | 2016-10-27 16:36:40 +0300 | [diff] [blame] | 6272 | if (init_attr->log_ind_tbl_size > |
| 6273 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)) { |
| 6274 | mlx5_ib_dbg(dev, "log_ind_tbl_size = %d is bigger than supported = %d\n", |
| 6275 | init_attr->log_ind_tbl_size, |
| 6276 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)); |
| 6277 | return ERR_PTR(-EINVAL); |
| 6278 | } |
| 6279 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6280 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 6281 | if (udata->outlen && udata->outlen < min_resp_len) |
| 6282 | return ERR_PTR(-EINVAL); |
| 6283 | |
| 6284 | rwq_ind_tbl = kzalloc(sizeof(*rwq_ind_tbl), GFP_KERNEL); |
| 6285 | if (!rwq_ind_tbl) |
| 6286 | return ERR_PTR(-ENOMEM); |
| 6287 | |
| 6288 | inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 6289 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6290 | if (!in) { |
| 6291 | err = -ENOMEM; |
| 6292 | goto err; |
| 6293 | } |
| 6294 | |
| 6295 | rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context); |
| 6296 | |
| 6297 | MLX5_SET(rqtc, rqtc, rqt_actual_size, sz); |
| 6298 | MLX5_SET(rqtc, rqtc, rqt_max_size, sz); |
| 6299 | |
| 6300 | for (i = 0; i < sz; i++) |
| 6301 | MLX5_SET(rqtc, rqtc, rq_num[i], init_attr->ind_tbl[i]->wq_num); |
| 6302 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 6303 | rwq_ind_tbl->uid = to_mpd(init_attr->ind_tbl[0]->pd)->uid; |
| 6304 | MLX5_SET(create_rqt_in, in, uid, rwq_ind_tbl->uid); |
| 6305 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 6306 | err = mlx5_core_create_rqt(dev->mdev, in, inlen, &rwq_ind_tbl->rqtn); |
| 6307 | kvfree(in); |
| 6308 | |
| 6309 | if (err) |
| 6310 | goto err; |
| 6311 | |
| 6312 | rwq_ind_tbl->ib_rwq_ind_tbl.ind_tbl_num = rwq_ind_tbl->rqtn; |
| 6313 | if (udata->outlen) { |
| 6314 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 6315 | sizeof(resp.response_length); |
| 6316 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 6317 | if (err) |
| 6318 | goto err_copy; |
| 6319 | } |
| 6320 | |
| 6321 | return &rwq_ind_tbl->ib_rwq_ind_tbl; |
| 6322 | |
| 6323 | err_copy: |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 6324 | 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] | 6325 | err: |
| 6326 | kfree(rwq_ind_tbl); |
| 6327 | return ERR_PTR(err); |
| 6328 | } |
| 6329 | |
| 6330 | int mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl) |
| 6331 | { |
| 6332 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl = to_mrwq_ind_table(ib_rwq_ind_tbl); |
| 6333 | struct mlx5_ib_dev *dev = to_mdev(ib_rwq_ind_tbl->device); |
| 6334 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 6335 | 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] | 6336 | |
| 6337 | kfree(rwq_ind_tbl); |
| 6338 | return 0; |
| 6339 | } |
| 6340 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6341 | int mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, |
| 6342 | u32 wq_attr_mask, struct ib_udata *udata) |
| 6343 | { |
| 6344 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 6345 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 6346 | struct mlx5_ib_modify_wq ucmd = {}; |
| 6347 | size_t required_cmd_sz; |
| 6348 | int curr_wq_state; |
| 6349 | int wq_state; |
| 6350 | int inlen; |
| 6351 | int err; |
| 6352 | void *rqc; |
| 6353 | void *in; |
| 6354 | |
| 6355 | required_cmd_sz = offsetof(typeof(ucmd), reserved) + sizeof(ucmd.reserved); |
| 6356 | if (udata->inlen < required_cmd_sz) |
| 6357 | return -EINVAL; |
| 6358 | |
| 6359 | if (udata->inlen > sizeof(ucmd) && |
| 6360 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 6361 | udata->inlen - sizeof(ucmd))) |
| 6362 | return -EOPNOTSUPP; |
| 6363 | |
| 6364 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) |
| 6365 | return -EFAULT; |
| 6366 | |
| 6367 | if (ucmd.comp_mask || ucmd.reserved) |
| 6368 | return -EOPNOTSUPP; |
| 6369 | |
| 6370 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 6371 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6372 | if (!in) |
| 6373 | return -ENOMEM; |
| 6374 | |
| 6375 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 6376 | |
| 6377 | curr_wq_state = (wq_attr_mask & IB_WQ_CUR_STATE) ? |
| 6378 | wq_attr->curr_wq_state : wq->state; |
| 6379 | wq_state = (wq_attr_mask & IB_WQ_STATE) ? |
| 6380 | wq_attr->wq_state : curr_wq_state; |
| 6381 | if (curr_wq_state == IB_WQS_ERR) |
| 6382 | curr_wq_state = MLX5_RQC_STATE_ERR; |
| 6383 | if (wq_state == IB_WQS_ERR) |
| 6384 | wq_state = MLX5_RQC_STATE_ERR; |
| 6385 | MLX5_SET(modify_rq_in, in, rq_state, curr_wq_state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 6386 | MLX5_SET(modify_rq_in, in, uid, to_mpd(wq->pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6387 | MLX5_SET(rqc, rqc, state, wq_state); |
| 6388 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6389 | if (wq_attr_mask & IB_WQ_FLAGS) { |
| 6390 | if (wq_attr->flags_mask & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
| 6391 | if (!(MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 6392 | MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
| 6393 | mlx5_ib_dbg(dev, "VLAN offloads are not " |
| 6394 | "supported\n"); |
| 6395 | err = -EOPNOTSUPP; |
| 6396 | goto out; |
| 6397 | } |
| 6398 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 6399 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD); |
| 6400 | MLX5_SET(rqc, rqc, vsd, |
| 6401 | (wq_attr->flags & IB_WQ_FLAGS_CVLAN_STRIPPING) ? 0 : 1); |
| 6402 | } |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 6403 | |
| 6404 | if (wq_attr->flags_mask & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 6405 | mlx5_ib_dbg(dev, "Modifying scatter end padding is not supported\n"); |
| 6406 | err = -EOPNOTSUPP; |
| 6407 | goto out; |
| 6408 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6409 | } |
| 6410 | |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6411 | if (curr_wq_state == IB_WQS_RESET && wq_state == IB_WQS_RDY) { |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 6412 | u16 set_id; |
| 6413 | |
| 6414 | set_id = mlx5_ib_get_counters_id(dev, 0); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6415 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 6416 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 6417 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Parav Pandit | 3e1f000 | 2019-07-23 10:31:17 +0300 | [diff] [blame] | 6418 | MLX5_SET(rqc, rqc, counter_set_id, set_id); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6419 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 6420 | dev_info_once( |
| 6421 | &dev->ib_dev.dev, |
| 6422 | "Receive WQ counters are not supported on current FW\n"); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6423 | } |
| 6424 | |
Leon Romanovsky | e0b4b47 | 2020-04-09 21:03:33 +0300 | [diff] [blame] | 6425 | err = mlx5_core_modify_rq(dev->mdev, rwq->core_qp.qpn, in); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6426 | if (!err) |
| 6427 | rwq->ibwq.state = (wq_state == MLX5_RQC_STATE_ERR) ? IB_WQS_ERR : wq_state; |
| 6428 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6429 | out: |
| 6430 | kvfree(in); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6431 | return err; |
| 6432 | } |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6433 | |
| 6434 | struct mlx5_ib_drain_cqe { |
| 6435 | struct ib_cqe cqe; |
| 6436 | struct completion done; |
| 6437 | }; |
| 6438 | |
| 6439 | static void mlx5_ib_drain_qp_done(struct ib_cq *cq, struct ib_wc *wc) |
| 6440 | { |
| 6441 | struct mlx5_ib_drain_cqe *cqe = container_of(wc->wr_cqe, |
| 6442 | struct mlx5_ib_drain_cqe, |
| 6443 | cqe); |
| 6444 | |
| 6445 | complete(&cqe->done); |
| 6446 | } |
| 6447 | |
| 6448 | /* This function returns only once the drained WR was completed */ |
| 6449 | static void handle_drain_completion(struct ib_cq *cq, |
| 6450 | struct mlx5_ib_drain_cqe *sdrain, |
| 6451 | struct mlx5_ib_dev *dev) |
| 6452 | { |
| 6453 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6454 | |
| 6455 | if (cq->poll_ctx == IB_POLL_DIRECT) { |
| 6456 | while (wait_for_completion_timeout(&sdrain->done, HZ / 10) <= 0) |
| 6457 | ib_process_cq_direct(cq, -1); |
| 6458 | return; |
| 6459 | } |
| 6460 | |
| 6461 | if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6462 | struct mlx5_ib_cq *mcq = to_mcq(cq); |
| 6463 | bool triggered = false; |
| 6464 | unsigned long flags; |
| 6465 | |
| 6466 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 6467 | /* Make sure that the CQ handler won't run if wasn't run yet */ |
| 6468 | if (!mcq->mcq.reset_notify_added) |
| 6469 | mcq->mcq.reset_notify_added = 1; |
| 6470 | else |
| 6471 | triggered = true; |
| 6472 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 6473 | |
| 6474 | if (triggered) { |
| 6475 | /* Wait for any scheduled/running task to be ended */ |
| 6476 | switch (cq->poll_ctx) { |
| 6477 | case IB_POLL_SOFTIRQ: |
| 6478 | irq_poll_disable(&cq->iop); |
| 6479 | irq_poll_enable(&cq->iop); |
| 6480 | break; |
| 6481 | case IB_POLL_WORKQUEUE: |
| 6482 | cancel_work_sync(&cq->work); |
| 6483 | break; |
| 6484 | default: |
| 6485 | WARN_ON_ONCE(1); |
| 6486 | } |
| 6487 | } |
| 6488 | |
| 6489 | /* Run the CQ handler - this makes sure that the drain WR will |
| 6490 | * be processed if wasn't processed yet. |
| 6491 | */ |
Yishai Hadas | 4e0e2ea | 2019-06-30 19:23:27 +0300 | [diff] [blame] | 6492 | mcq->mcq.comp(&mcq->mcq, NULL); |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6493 | } |
| 6494 | |
| 6495 | wait_for_completion(&sdrain->done); |
| 6496 | } |
| 6497 | |
| 6498 | void mlx5_ib_drain_sq(struct ib_qp *qp) |
| 6499 | { |
| 6500 | struct ib_cq *cq = qp->send_cq; |
| 6501 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 6502 | struct mlx5_ib_drain_cqe sdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 6503 | const struct ib_send_wr *bad_swr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6504 | struct ib_rdma_wr swr = { |
| 6505 | .wr = { |
| 6506 | .next = NULL, |
| 6507 | { .wr_cqe = &sdrain.cqe, }, |
| 6508 | .opcode = IB_WR_RDMA_WRITE, |
| 6509 | }, |
| 6510 | }; |
| 6511 | int ret; |
| 6512 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 6513 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6514 | |
| 6515 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 6516 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6517 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 6518 | return; |
| 6519 | } |
| 6520 | |
| 6521 | sdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 6522 | init_completion(&sdrain.done); |
| 6523 | |
| 6524 | ret = _mlx5_ib_post_send(qp, &swr.wr, &bad_swr, true); |
| 6525 | if (ret) { |
| 6526 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 6527 | return; |
| 6528 | } |
| 6529 | |
| 6530 | handle_drain_completion(cq, &sdrain, dev); |
| 6531 | } |
| 6532 | |
| 6533 | void mlx5_ib_drain_rq(struct ib_qp *qp) |
| 6534 | { |
| 6535 | struct ib_cq *cq = qp->recv_cq; |
| 6536 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 6537 | struct mlx5_ib_drain_cqe rdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 6538 | struct ib_recv_wr rwr = {}; |
| 6539 | const struct ib_recv_wr *bad_rwr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6540 | int ret; |
| 6541 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 6542 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6543 | |
| 6544 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 6545 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6546 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 6547 | return; |
| 6548 | } |
| 6549 | |
| 6550 | rwr.wr_cqe = &rdrain.cqe; |
| 6551 | rdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 6552 | init_completion(&rdrain.done); |
| 6553 | |
| 6554 | ret = _mlx5_ib_post_recv(qp, &rwr, &bad_rwr, true); |
| 6555 | if (ret) { |
| 6556 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 6557 | return; |
| 6558 | } |
| 6559 | |
| 6560 | handle_drain_completion(cq, &rdrain, dev); |
| 6561 | } |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 6562 | |
| 6563 | /** |
| 6564 | * Bind a qp to a counter. If @counter is NULL then bind the qp to |
| 6565 | * the default counter |
| 6566 | */ |
| 6567 | int mlx5_ib_qp_set_counter(struct ib_qp *qp, struct rdma_counter *counter) |
| 6568 | { |
Mark Zhang | 10189e8 | 2020-01-26 19:17:08 +0200 | [diff] [blame] | 6569 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 6570 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 6571 | int err = 0; |
| 6572 | |
| 6573 | mutex_lock(&mqp->mutex); |
| 6574 | if (mqp->state == IB_QPS_RESET) { |
| 6575 | qp->counter = counter; |
| 6576 | goto out; |
| 6577 | } |
| 6578 | |
Mark Zhang | 10189e8 | 2020-01-26 19:17:08 +0200 | [diff] [blame] | 6579 | if (!MLX5_CAP_GEN(dev->mdev, rts2rts_qp_counters_set_id)) { |
| 6580 | err = -EOPNOTSUPP; |
| 6581 | goto out; |
| 6582 | } |
| 6583 | |
Mark Zhang | d14133d | 2019-07-02 13:02:36 +0300 | [diff] [blame] | 6584 | if (mqp->state == IB_QPS_RTS) { |
| 6585 | err = __mlx5_ib_qp_set_counter(qp, counter); |
| 6586 | if (!err) |
| 6587 | qp->counter = counter; |
| 6588 | |
| 6589 | goto out; |
| 6590 | } |
| 6591 | |
| 6592 | mqp->counter_pending = 1; |
| 6593 | qp->counter = counter; |
| 6594 | |
| 6595 | out: |
| 6596 | mutex_unlock(&mqp->mutex); |
| 6597 | return err; |
| 6598 | } |