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