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> |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 37 | #include <linux/mlx5/fs.h> |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 38 | #include "mlx5_ib.h" |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 39 | #include "ib_rep.h" |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 40 | #include "cmd.h" |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 41 | |
| 42 | /* not supported currently */ |
| 43 | static int wq_signature; |
| 44 | |
| 45 | enum { |
| 46 | MLX5_IB_ACK_REQ_FREQ = 8, |
| 47 | }; |
| 48 | |
| 49 | enum { |
| 50 | MLX5_IB_DEFAULT_SCHED_QUEUE = 0x83, |
| 51 | MLX5_IB_DEFAULT_QP0_SCHED_QUEUE = 0x3f, |
| 52 | MLX5_IB_LINK_TYPE_IB = 0, |
| 53 | MLX5_IB_LINK_TYPE_ETH = 1 |
| 54 | }; |
| 55 | |
| 56 | enum { |
| 57 | MLX5_IB_SQ_STRIDE = 6, |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 58 | MLX5_IB_SQ_UMR_INLINE_THRESHOLD = 64, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | static const u32 mlx5_ib_opcode[] = { |
| 62 | [IB_WR_SEND] = MLX5_OPCODE_SEND, |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 63 | [IB_WR_LSO] = MLX5_OPCODE_LSO, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 64 | [IB_WR_SEND_WITH_IMM] = MLX5_OPCODE_SEND_IMM, |
| 65 | [IB_WR_RDMA_WRITE] = MLX5_OPCODE_RDMA_WRITE, |
| 66 | [IB_WR_RDMA_WRITE_WITH_IMM] = MLX5_OPCODE_RDMA_WRITE_IMM, |
| 67 | [IB_WR_RDMA_READ] = MLX5_OPCODE_RDMA_READ, |
| 68 | [IB_WR_ATOMIC_CMP_AND_SWP] = MLX5_OPCODE_ATOMIC_CS, |
| 69 | [IB_WR_ATOMIC_FETCH_AND_ADD] = MLX5_OPCODE_ATOMIC_FA, |
| 70 | [IB_WR_SEND_WITH_INV] = MLX5_OPCODE_SEND_INVAL, |
| 71 | [IB_WR_LOCAL_INV] = MLX5_OPCODE_UMR, |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 72 | [IB_WR_REG_MR] = MLX5_OPCODE_UMR, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 73 | [IB_WR_MASKED_ATOMIC_CMP_AND_SWP] = MLX5_OPCODE_ATOMIC_MASKED_CS, |
| 74 | [IB_WR_MASKED_ATOMIC_FETCH_AND_ADD] = MLX5_OPCODE_ATOMIC_MASKED_FA, |
| 75 | [MLX5_IB_WR_UMR] = MLX5_OPCODE_UMR, |
| 76 | }; |
| 77 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 78 | struct mlx5_wqe_eth_pad { |
| 79 | u8 rsvd0[16]; |
| 80 | }; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 81 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 82 | enum raw_qp_set_mask_map { |
| 83 | MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID = 1UL << 0, |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 84 | MLX5_RAW_QP_RATE_LIMIT = 1UL << 1, |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 85 | }; |
| 86 | |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 87 | struct mlx5_modify_raw_qp_param { |
| 88 | u16 operation; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 89 | |
| 90 | u32 set_mask; /* raw_qp_set_mask_map */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 91 | |
| 92 | struct mlx5_rate_limit rl; |
| 93 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 94 | u8 rq_q_ctr_id; |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 95 | }; |
| 96 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 97 | static void get_cqs(enum ib_qp_type qp_type, |
| 98 | struct ib_cq *ib_send_cq, struct ib_cq *ib_recv_cq, |
| 99 | struct mlx5_ib_cq **send_cq, struct mlx5_ib_cq **recv_cq); |
| 100 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 101 | static int is_qp0(enum ib_qp_type qp_type) |
| 102 | { |
| 103 | return qp_type == IB_QPT_SMI; |
| 104 | } |
| 105 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 106 | static int is_sqp(enum ib_qp_type qp_type) |
| 107 | { |
| 108 | return is_qp0(qp_type) || is_qp1(qp_type); |
| 109 | } |
| 110 | |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 111 | /** |
| 112 | * mlx5_ib_read_user_wqe() - Copy a user-space WQE to kernel space. |
| 113 | * |
| 114 | * @qp: QP to copy from. |
| 115 | * @send: copy from the send queue when non-zero, use the receive queue |
| 116 | * otherwise. |
| 117 | * @wqe_index: index to start copying from. For send work queues, the |
| 118 | * wqe_index is in units of MLX5_SEND_WQE_BB. |
| 119 | * For receive work queue, it is the number of work queue |
| 120 | * element in the queue. |
| 121 | * @buffer: destination buffer. |
| 122 | * @length: maximum number of bytes to copy. |
| 123 | * |
| 124 | * Copies at least a single WQE, but may copy more data. |
| 125 | * |
| 126 | * Return: the number of bytes copied, or an error code. |
| 127 | */ |
| 128 | int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 129 | void *buffer, u32 length, |
| 130 | struct mlx5_ib_qp_base *base) |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 131 | { |
| 132 | struct ib_device *ibdev = qp->ibqp.device; |
| 133 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 134 | struct mlx5_ib_wq *wq = send ? &qp->sq : &qp->rq; |
| 135 | size_t offset; |
| 136 | size_t wq_end; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 137 | struct ib_umem *umem = base->ubuffer.umem; |
Haggai Eran | c1395a2 | 2014-12-11 17:04:14 +0200 | [diff] [blame] | 138 | u32 first_copy_length; |
| 139 | int wqe_length; |
| 140 | int ret; |
| 141 | |
| 142 | if (wq->wqe_cnt == 0) { |
| 143 | mlx5_ib_dbg(dev, "mlx5_ib_read_user_wqe for a QP with wqe_cnt == 0. qp_type: 0x%x\n", |
| 144 | qp->ibqp.qp_type); |
| 145 | return -EINVAL; |
| 146 | } |
| 147 | |
| 148 | offset = wq->offset + ((wqe_index % wq->wqe_cnt) << wq->wqe_shift); |
| 149 | wq_end = wq->offset + (wq->wqe_cnt << wq->wqe_shift); |
| 150 | |
| 151 | if (send && length < sizeof(struct mlx5_wqe_ctrl_seg)) |
| 152 | return -EINVAL; |
| 153 | |
| 154 | if (offset > umem->length || |
| 155 | (send && offset + sizeof(struct mlx5_wqe_ctrl_seg) > umem->length)) |
| 156 | return -EINVAL; |
| 157 | |
| 158 | first_copy_length = min_t(u32, offset + length, wq_end) - offset; |
| 159 | ret = ib_umem_copy_from(buffer, umem, offset, first_copy_length); |
| 160 | if (ret) |
| 161 | return ret; |
| 162 | |
| 163 | if (send) { |
| 164 | struct mlx5_wqe_ctrl_seg *ctrl = buffer; |
| 165 | int ds = be32_to_cpu(ctrl->qpn_ds) & MLX5_WQE_CTRL_DS_MASK; |
| 166 | |
| 167 | wqe_length = ds * MLX5_WQE_DS_UNITS; |
| 168 | } else { |
| 169 | wqe_length = 1 << wq->wqe_shift; |
| 170 | } |
| 171 | |
| 172 | if (wqe_length <= first_copy_length) |
| 173 | return first_copy_length; |
| 174 | |
| 175 | ret = ib_umem_copy_from(buffer + first_copy_length, umem, wq->offset, |
| 176 | wqe_length - first_copy_length); |
| 177 | if (ret) |
| 178 | return ret; |
| 179 | |
| 180 | return wqe_length; |
| 181 | } |
| 182 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 183 | static void mlx5_ib_qp_event(struct mlx5_core_qp *qp, int type) |
| 184 | { |
| 185 | struct ib_qp *ibqp = &to_mibqp(qp)->ibqp; |
| 186 | struct ib_event event; |
| 187 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 188 | if (type == MLX5_EVENT_TYPE_PATH_MIG) { |
| 189 | /* This event is only valid for trans_qps */ |
| 190 | to_mibqp(qp)->port = to_mibqp(qp)->trans_qp.alt_port; |
| 191 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 192 | |
| 193 | if (ibqp->event_handler) { |
| 194 | event.device = ibqp->device; |
| 195 | event.element.qp = ibqp; |
| 196 | switch (type) { |
| 197 | case MLX5_EVENT_TYPE_PATH_MIG: |
| 198 | event.event = IB_EVENT_PATH_MIG; |
| 199 | break; |
| 200 | case MLX5_EVENT_TYPE_COMM_EST: |
| 201 | event.event = IB_EVENT_COMM_EST; |
| 202 | break; |
| 203 | case MLX5_EVENT_TYPE_SQ_DRAINED: |
| 204 | event.event = IB_EVENT_SQ_DRAINED; |
| 205 | break; |
| 206 | case MLX5_EVENT_TYPE_SRQ_LAST_WQE: |
| 207 | event.event = IB_EVENT_QP_LAST_WQE_REACHED; |
| 208 | break; |
| 209 | case MLX5_EVENT_TYPE_WQ_CATAS_ERROR: |
| 210 | event.event = IB_EVENT_QP_FATAL; |
| 211 | break; |
| 212 | case MLX5_EVENT_TYPE_PATH_MIG_FAILED: |
| 213 | event.event = IB_EVENT_PATH_MIG_ERR; |
| 214 | break; |
| 215 | case MLX5_EVENT_TYPE_WQ_INVAL_REQ_ERROR: |
| 216 | event.event = IB_EVENT_QP_REQ_ERR; |
| 217 | break; |
| 218 | case MLX5_EVENT_TYPE_WQ_ACCESS_ERROR: |
| 219 | event.event = IB_EVENT_QP_ACCESS_ERR; |
| 220 | break; |
| 221 | default: |
| 222 | pr_warn("mlx5_ib: Unexpected event type %d on QP %06x\n", type, qp->qpn); |
| 223 | return; |
| 224 | } |
| 225 | |
| 226 | ibqp->event_handler(&event, ibqp->qp_context); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | static int set_rq_size(struct mlx5_ib_dev *dev, struct ib_qp_cap *cap, |
| 231 | int has_rq, struct mlx5_ib_qp *qp, struct mlx5_ib_create_qp *ucmd) |
| 232 | { |
| 233 | int wqe_size; |
| 234 | int wq_size; |
| 235 | |
| 236 | /* Sanity check RQ size before proceeding */ |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 237 | 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] | 238 | return -EINVAL; |
| 239 | |
| 240 | if (!has_rq) { |
| 241 | qp->rq.max_gs = 0; |
| 242 | qp->rq.wqe_cnt = 0; |
| 243 | qp->rq.wqe_shift = 0; |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 244 | cap->max_recv_wr = 0; |
| 245 | cap->max_recv_sge = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 246 | } else { |
| 247 | if (ucmd) { |
| 248 | qp->rq.wqe_cnt = ucmd->rq_wqe_count; |
Leon Romanovsky | 002bf22 | 2018-04-23 17:01:53 +0300 | [diff] [blame] | 249 | if (ucmd->rq_wqe_shift > BITS_PER_BYTE * sizeof(ucmd->rq_wqe_shift)) |
| 250 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 251 | qp->rq.wqe_shift = ucmd->rq_wqe_shift; |
Leon Romanovsky | 002bf22 | 2018-04-23 17:01:53 +0300 | [diff] [blame] | 252 | if ((1 << qp->rq.wqe_shift) / sizeof(struct mlx5_wqe_data_seg) < qp->wq_sig) |
| 253 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 254 | qp->rq.max_gs = (1 << qp->rq.wqe_shift) / sizeof(struct mlx5_wqe_data_seg) - qp->wq_sig; |
| 255 | qp->rq.max_post = qp->rq.wqe_cnt; |
| 256 | } else { |
| 257 | wqe_size = qp->wq_sig ? sizeof(struct mlx5_wqe_signature_seg) : 0; |
| 258 | wqe_size += cap->max_recv_sge * sizeof(struct mlx5_wqe_data_seg); |
| 259 | wqe_size = roundup_pow_of_two(wqe_size); |
| 260 | wq_size = roundup_pow_of_two(cap->max_recv_wr) * wqe_size; |
| 261 | wq_size = max_t(int, wq_size, MLX5_SEND_WQE_BB); |
| 262 | qp->rq.wqe_cnt = wq_size / wqe_size; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 263 | if (wqe_size > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_rq)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 264 | mlx5_ib_dbg(dev, "wqe_size %d, max %d\n", |
| 265 | wqe_size, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 266 | MLX5_CAP_GEN(dev->mdev, |
| 267 | max_wqe_sz_rq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 268 | return -EINVAL; |
| 269 | } |
| 270 | qp->rq.wqe_shift = ilog2(wqe_size); |
| 271 | qp->rq.max_gs = (1 << qp->rq.wqe_shift) / sizeof(struct mlx5_wqe_data_seg) - qp->wq_sig; |
| 272 | qp->rq.max_post = qp->rq.wqe_cnt; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 279 | static int sq_overhead(struct ib_qp_init_attr *attr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 280 | { |
Andi Shyti | 618af38 | 2013-07-16 15:35:01 +0200 | [diff] [blame] | 281 | int size = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 282 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 283 | switch (attr->qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 284 | case IB_QPT_XRC_INI: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 285 | size += sizeof(struct mlx5_wqe_xrc_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 286 | /* fall through */ |
| 287 | case IB_QPT_RC: |
| 288 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Leon Romanovsky | 75c1657e | 2016-02-11 21:09:57 +0200 | [diff] [blame] | 289 | max(sizeof(struct mlx5_wqe_atomic_seg) + |
| 290 | sizeof(struct mlx5_wqe_raddr_seg), |
| 291 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 292 | sizeof(struct mlx5_mkey_seg) + |
| 293 | MLX5_IB_SQ_UMR_INLINE_THRESHOLD / |
| 294 | MLX5_IB_UMR_OCTOWORD); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 295 | break; |
| 296 | |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 297 | case IB_QPT_XRC_TGT: |
| 298 | return 0; |
| 299 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 300 | case IB_QPT_UC: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 301 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Leon Romanovsky | 75c1657e | 2016-02-11 21:09:57 +0200 | [diff] [blame] | 302 | max(sizeof(struct mlx5_wqe_raddr_seg), |
| 303 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
| 304 | sizeof(struct mlx5_mkey_seg)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 305 | break; |
| 306 | |
| 307 | case IB_QPT_UD: |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 308 | if (attr->create_flags & IB_QP_CREATE_IPOIB_UD_LSO) |
| 309 | size += sizeof(struct mlx5_wqe_eth_pad) + |
| 310 | sizeof(struct mlx5_wqe_eth_seg); |
| 311 | /* fall through */ |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 312 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 313 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 314 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 315 | sizeof(struct mlx5_wqe_datagram_seg); |
| 316 | break; |
| 317 | |
| 318 | case MLX5_IB_QPT_REG_UMR: |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 319 | size += sizeof(struct mlx5_wqe_ctrl_seg) + |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 320 | sizeof(struct mlx5_wqe_umr_ctrl_seg) + |
| 321 | sizeof(struct mlx5_mkey_seg); |
| 322 | break; |
| 323 | |
| 324 | default: |
| 325 | return -EINVAL; |
| 326 | } |
| 327 | |
| 328 | return size; |
| 329 | } |
| 330 | |
| 331 | static int calc_send_wqe(struct ib_qp_init_attr *attr) |
| 332 | { |
| 333 | int inl_size = 0; |
| 334 | int size; |
| 335 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 336 | size = sq_overhead(attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 337 | if (size < 0) |
| 338 | return size; |
| 339 | |
| 340 | if (attr->cap.max_inline_data) { |
| 341 | inl_size = size + sizeof(struct mlx5_wqe_inline_seg) + |
| 342 | attr->cap.max_inline_data; |
| 343 | } |
| 344 | |
| 345 | size += attr->cap.max_send_sge * sizeof(struct mlx5_wqe_data_seg); |
Sagi Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 346 | if (attr->create_flags & IB_QP_CREATE_SIGNATURE_EN && |
| 347 | ALIGN(max_t(int, inl_size, size), MLX5_SEND_WQE_BB) < MLX5_SIG_WQE_SIZE) |
| 348 | return MLX5_SIG_WQE_SIZE; |
| 349 | else |
| 350 | return ALIGN(max_t(int, inl_size, size), MLX5_SEND_WQE_BB); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 351 | } |
| 352 | |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 353 | static int get_send_sge(struct ib_qp_init_attr *attr, int wqe_size) |
| 354 | { |
| 355 | int max_sge; |
| 356 | |
| 357 | if (attr->qp_type == IB_QPT_RC) |
| 358 | max_sge = (min_t(int, wqe_size, 512) - |
| 359 | sizeof(struct mlx5_wqe_ctrl_seg) - |
| 360 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 361 | sizeof(struct mlx5_wqe_data_seg); |
| 362 | else if (attr->qp_type == IB_QPT_XRC_INI) |
| 363 | max_sge = (min_t(int, wqe_size, 512) - |
| 364 | sizeof(struct mlx5_wqe_ctrl_seg) - |
| 365 | sizeof(struct mlx5_wqe_xrc_seg) - |
| 366 | sizeof(struct mlx5_wqe_raddr_seg)) / |
| 367 | sizeof(struct mlx5_wqe_data_seg); |
| 368 | else |
| 369 | max_sge = (wqe_size - sq_overhead(attr)) / |
| 370 | sizeof(struct mlx5_wqe_data_seg); |
| 371 | |
| 372 | return min_t(int, max_sge, wqe_size - sq_overhead(attr) / |
| 373 | sizeof(struct mlx5_wqe_data_seg)); |
| 374 | } |
| 375 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 376 | static int calc_sq_size(struct mlx5_ib_dev *dev, struct ib_qp_init_attr *attr, |
| 377 | struct mlx5_ib_qp *qp) |
| 378 | { |
| 379 | int wqe_size; |
| 380 | int wq_size; |
| 381 | |
| 382 | if (!attr->cap.max_send_wr) |
| 383 | return 0; |
| 384 | |
| 385 | wqe_size = calc_send_wqe(attr); |
| 386 | mlx5_ib_dbg(dev, "wqe_size %d\n", wqe_size); |
| 387 | if (wqe_size < 0) |
| 388 | return wqe_size; |
| 389 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 390 | if (wqe_size > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)) { |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 391 | 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] | 392 | wqe_size, MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 393 | return -EINVAL; |
| 394 | } |
| 395 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 396 | qp->max_inline_data = wqe_size - sq_overhead(attr) - |
| 397 | sizeof(struct mlx5_wqe_inline_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 398 | attr->cap.max_inline_data = qp->max_inline_data; |
| 399 | |
Sagi Grimberg | e1e66cc | 2014-02-23 14:19:07 +0200 | [diff] [blame] | 400 | if (attr->create_flags & IB_QP_CREATE_SIGNATURE_EN) |
| 401 | qp->signature_en = true; |
| 402 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 403 | wq_size = roundup_pow_of_two(attr->cap.max_send_wr * wqe_size); |
| 404 | qp->sq.wqe_cnt = wq_size / MLX5_SEND_WQE_BB; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 405 | 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] | 406 | mlx5_ib_dbg(dev, "send queue size (%d * %d / %d -> %d) exceeds limits(%d)\n", |
| 407 | attr->cap.max_send_wr, wqe_size, MLX5_SEND_WQE_BB, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 408 | qp->sq.wqe_cnt, |
| 409 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz)); |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 410 | return -ENOMEM; |
| 411 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 412 | qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); |
Eli Cohen | 288c01b | 2016-10-27 16:36:45 +0300 | [diff] [blame] | 413 | qp->sq.max_gs = get_send_sge(attr, wqe_size); |
| 414 | if (qp->sq.max_gs < attr->cap.max_send_sge) |
| 415 | return -ENOMEM; |
| 416 | |
| 417 | attr->cap.max_send_sge = qp->sq.max_gs; |
Eli Cohen | b125a54 | 2013-09-11 16:35:22 +0300 | [diff] [blame] | 418 | qp->sq.max_post = wq_size / wqe_size; |
| 419 | attr->cap.max_send_wr = qp->sq.max_post; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 420 | |
| 421 | return wq_size; |
| 422 | } |
| 423 | |
| 424 | static int set_user_buf_size(struct mlx5_ib_dev *dev, |
| 425 | struct mlx5_ib_qp *qp, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 426 | struct mlx5_ib_create_qp *ucmd, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 427 | struct mlx5_ib_qp_base *base, |
| 428 | struct ib_qp_init_attr *attr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 429 | { |
| 430 | int desc_sz = 1 << qp->sq.wqe_shift; |
| 431 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 432 | if (desc_sz > MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 433 | 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] | 434 | desc_sz, MLX5_CAP_GEN(dev->mdev, max_wqe_sz_sq)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 435 | return -EINVAL; |
| 436 | } |
| 437 | |
| 438 | if (ucmd->sq_wqe_count && ((1 << ilog2(ucmd->sq_wqe_count)) != ucmd->sq_wqe_count)) { |
| 439 | mlx5_ib_warn(dev, "sq_wqe_count %d, sq_wqe_count %d\n", |
| 440 | ucmd->sq_wqe_count, ucmd->sq_wqe_count); |
| 441 | return -EINVAL; |
| 442 | } |
| 443 | |
| 444 | qp->sq.wqe_cnt = ucmd->sq_wqe_count; |
| 445 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 446 | 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] | 447 | mlx5_ib_warn(dev, "wqe_cnt %d, max_wqes %d\n", |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 448 | qp->sq.wqe_cnt, |
| 449 | 1 << MLX5_CAP_GEN(dev->mdev, log_max_qp_sz)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 450 | return -EINVAL; |
| 451 | } |
| 452 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 453 | if (attr->qp_type == IB_QPT_RAW_PACKET || |
| 454 | qp->flags & MLX5_IB_QP_UNDERLAY) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 455 | base->ubuffer.buf_size = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
| 456 | qp->raw_packet_qp.sq.ubuffer.buf_size = qp->sq.wqe_cnt << 6; |
| 457 | } else { |
| 458 | base->ubuffer.buf_size = (qp->rq.wqe_cnt << qp->rq.wqe_shift) + |
| 459 | (qp->sq.wqe_cnt << 6); |
| 460 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | static int qp_has_rq(struct ib_qp_init_attr *attr) |
| 466 | { |
| 467 | if (attr->qp_type == IB_QPT_XRC_INI || |
| 468 | attr->qp_type == IB_QPT_XRC_TGT || attr->srq || |
| 469 | attr->qp_type == MLX5_IB_QPT_REG_UMR || |
| 470 | !attr->cap.max_recv_wr) |
| 471 | return 0; |
| 472 | |
| 473 | return 1; |
| 474 | } |
| 475 | |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 476 | enum { |
| 477 | /* this is the first blue flame register in the array of bfregs assigned |
| 478 | * to a processes. Since we do not use it for blue flame but rather |
| 479 | * regular 64 bit doorbells, we do not need a lock for maintaiing |
| 480 | * "odd/even" order |
| 481 | */ |
| 482 | NUM_NON_BLUE_FLAME_BFREGS = 1, |
| 483 | }; |
| 484 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 485 | static int max_bfregs(struct mlx5_ib_dev *dev, struct mlx5_bfreg_info *bfregi) |
| 486 | { |
Yishai Hadas | 31a78a5 | 2017-12-24 16:31:34 +0200 | [diff] [blame] | 487 | 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] | 488 | } |
| 489 | |
| 490 | static int num_med_bfreg(struct mlx5_ib_dev *dev, |
| 491 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 492 | { |
| 493 | int n; |
| 494 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 495 | n = max_bfregs(dev, bfregi) - bfregi->num_low_latency_bfregs - |
| 496 | NUM_NON_BLUE_FLAME_BFREGS; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 497 | |
| 498 | return n >= 0 ? n : 0; |
| 499 | } |
| 500 | |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 501 | static int first_med_bfreg(struct mlx5_ib_dev *dev, |
| 502 | struct mlx5_bfreg_info *bfregi) |
| 503 | { |
| 504 | return num_med_bfreg(dev, bfregi) ? 1 : -ENOMEM; |
| 505 | } |
| 506 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 507 | static int first_hi_bfreg(struct mlx5_ib_dev *dev, |
| 508 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 509 | { |
| 510 | int med; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 511 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 512 | med = num_med_bfreg(dev, bfregi); |
| 513 | return ++med; |
Eli Cohen | c1be523 | 2014-01-14 17:45:12 +0200 | [diff] [blame] | 514 | } |
| 515 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 516 | static int alloc_high_class_bfreg(struct mlx5_ib_dev *dev, |
| 517 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 518 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 519 | int i; |
| 520 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 521 | for (i = first_hi_bfreg(dev, bfregi); i < max_bfregs(dev, bfregi); i++) { |
| 522 | if (!bfregi->count[i]) { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 523 | bfregi->count[i]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 524 | return i; |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | return -ENOMEM; |
| 529 | } |
| 530 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 531 | static int alloc_med_class_bfreg(struct mlx5_ib_dev *dev, |
| 532 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 533 | { |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 534 | int minidx = first_med_bfreg(dev, bfregi); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 535 | int i; |
| 536 | |
Yishai Hadas | 18b0362 | 2018-05-07 10:20:01 +0300 | [diff] [blame] | 537 | if (minidx < 0) |
| 538 | return minidx; |
| 539 | |
| 540 | for (i = minidx; i < first_hi_bfreg(dev, bfregi); i++) { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 541 | if (bfregi->count[i] < bfregi->count[minidx]) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 542 | minidx = i; |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 543 | if (!bfregi->count[minidx]) |
| 544 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 545 | } |
| 546 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 547 | bfregi->count[minidx]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 548 | return minidx; |
| 549 | } |
| 550 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 551 | static int alloc_bfreg(struct mlx5_ib_dev *dev, |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 552 | struct mlx5_bfreg_info *bfregi) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 553 | { |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 554 | int bfregn = -ENOMEM; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 555 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 556 | mutex_lock(&bfregi->lock); |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 557 | if (bfregi->ver >= 2) { |
| 558 | bfregn = alloc_high_class_bfreg(dev, bfregi); |
| 559 | if (bfregn < 0) |
| 560 | bfregn = alloc_med_class_bfreg(dev, bfregi); |
| 561 | } |
| 562 | |
| 563 | if (bfregn < 0) { |
Eli Cohen | 0b80c14f0 | 2017-01-03 23:55:22 +0200 | [diff] [blame] | 564 | BUILD_BUG_ON(NUM_NON_BLUE_FLAME_BFREGS != 1); |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 565 | bfregn = 0; |
| 566 | bfregi->count[bfregn]++; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 567 | } |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 568 | mutex_unlock(&bfregi->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 569 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 570 | return bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 571 | } |
| 572 | |
Yishai Hadas | 4ed131d | 2017-12-24 16:31:35 +0200 | [diff] [blame] | 573 | 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] | 574 | { |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 575 | mutex_lock(&bfregi->lock); |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 576 | bfregi->count[bfregn]--; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 577 | mutex_unlock(&bfregi->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static enum mlx5_qp_state to_mlx5_state(enum ib_qp_state state) |
| 581 | { |
| 582 | switch (state) { |
| 583 | case IB_QPS_RESET: return MLX5_QP_STATE_RST; |
| 584 | case IB_QPS_INIT: return MLX5_QP_STATE_INIT; |
| 585 | case IB_QPS_RTR: return MLX5_QP_STATE_RTR; |
| 586 | case IB_QPS_RTS: return MLX5_QP_STATE_RTS; |
| 587 | case IB_QPS_SQD: return MLX5_QP_STATE_SQD; |
| 588 | case IB_QPS_SQE: return MLX5_QP_STATE_SQER; |
| 589 | case IB_QPS_ERR: return MLX5_QP_STATE_ERR; |
| 590 | default: return -1; |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | static int to_mlx5_st(enum ib_qp_type type) |
| 595 | { |
| 596 | switch (type) { |
| 597 | case IB_QPT_RC: return MLX5_QP_ST_RC; |
| 598 | case IB_QPT_UC: return MLX5_QP_ST_UC; |
| 599 | case IB_QPT_UD: return MLX5_QP_ST_UD; |
| 600 | case MLX5_IB_QPT_REG_UMR: return MLX5_QP_ST_REG_UMR; |
| 601 | case IB_QPT_XRC_INI: |
| 602 | case IB_QPT_XRC_TGT: return MLX5_QP_ST_XRC; |
| 603 | case IB_QPT_SMI: return MLX5_QP_ST_QP0; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 604 | case MLX5_IB_QPT_HW_GSI: return MLX5_QP_ST_QP1; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 605 | case MLX5_IB_QPT_DCI: return MLX5_QP_ST_DCI; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 606 | case IB_QPT_RAW_IPV6: return MLX5_QP_ST_RAW_IPV6; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 607 | case IB_QPT_RAW_PACKET: |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 608 | case IB_QPT_RAW_ETHERTYPE: return MLX5_QP_ST_RAW_ETHERTYPE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 609 | case IB_QPT_MAX: |
| 610 | default: return -EINVAL; |
| 611 | } |
| 612 | } |
| 613 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 614 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, |
| 615 | struct mlx5_ib_cq *recv_cq); |
| 616 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, |
| 617 | struct mlx5_ib_cq *recv_cq); |
| 618 | |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 619 | int bfregn_to_uar_index(struct mlx5_ib_dev *dev, |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 620 | struct mlx5_bfreg_info *bfregi, u32 bfregn, |
Yishai Hadas | 7c043e9 | 2018-06-17 13:00:03 +0300 | [diff] [blame] | 621 | bool dyn_bfreg) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 622 | { |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 623 | unsigned int bfregs_per_sys_page; |
| 624 | u32 index_of_sys_page; |
| 625 | u32 offset; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 626 | |
| 627 | bfregs_per_sys_page = get_uars_per_sys_page(dev, bfregi->lib_uar_4k) * |
| 628 | MLX5_NON_FP_BFREGS_PER_UAR; |
| 629 | index_of_sys_page = bfregn / bfregs_per_sys_page; |
| 630 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 631 | if (dyn_bfreg) { |
| 632 | index_of_sys_page += bfregi->num_static_sys_pages; |
Leon Romanovsky | 05f58ce | 2018-07-08 13:50:21 +0300 | [diff] [blame] | 633 | |
| 634 | if (index_of_sys_page >= bfregi->num_sys_pages) |
| 635 | return -EINVAL; |
| 636 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 637 | if (bfregn > bfregi->num_dyn_bfregs || |
| 638 | bfregi->sys_pages[index_of_sys_page] == MLX5_IB_INVALID_UAR_INDEX) { |
| 639 | mlx5_ib_dbg(dev, "Invalid dynamic uar index\n"); |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | } |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 643 | |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 644 | offset = bfregn % bfregs_per_sys_page / MLX5_NON_FP_BFREGS_PER_UAR; |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 645 | return bfregi->sys_pages[index_of_sys_page] + offset; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 646 | } |
| 647 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 648 | static int mlx5_ib_umem_get(struct mlx5_ib_dev *dev, |
| 649 | struct ib_pd *pd, |
| 650 | unsigned long addr, size_t size, |
| 651 | struct ib_umem **umem, |
| 652 | int *npages, int *page_shift, int *ncont, |
| 653 | u32 *offset) |
| 654 | { |
| 655 | int err; |
| 656 | |
| 657 | *umem = ib_umem_get(pd->uobject->context, addr, size, 0, 0); |
| 658 | if (IS_ERR(*umem)) { |
| 659 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 660 | return PTR_ERR(*umem); |
| 661 | } |
| 662 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 663 | 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] | 664 | |
| 665 | err = mlx5_ib_get_buf_offset(addr, *page_shift, offset); |
| 666 | if (err) { |
| 667 | mlx5_ib_warn(dev, "bad offset\n"); |
| 668 | goto err_umem; |
| 669 | } |
| 670 | |
| 671 | mlx5_ib_dbg(dev, "addr 0x%lx, size %zu, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 672 | addr, size, *npages, *page_shift, *ncont, *offset); |
| 673 | |
| 674 | return 0; |
| 675 | |
| 676 | err_umem: |
| 677 | ib_umem_release(*umem); |
| 678 | *umem = NULL; |
| 679 | |
| 680 | return err; |
| 681 | } |
| 682 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 683 | static void destroy_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 684 | struct mlx5_ib_rwq *rwq) |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 685 | { |
| 686 | struct mlx5_ib_ucontext *context; |
| 687 | |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 688 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_DELAY_DROP) |
| 689 | atomic_dec(&dev->delay_drop.rqs_cnt); |
| 690 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 691 | context = to_mucontext(pd->uobject->context); |
| 692 | mlx5_ib_db_unmap_user(context, &rwq->db); |
| 693 | if (rwq->umem) |
| 694 | ib_umem_release(rwq->umem); |
| 695 | } |
| 696 | |
| 697 | static int create_user_rq(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 698 | struct mlx5_ib_rwq *rwq, |
| 699 | struct mlx5_ib_create_wq *ucmd) |
| 700 | { |
| 701 | struct mlx5_ib_ucontext *context; |
| 702 | int page_shift = 0; |
| 703 | int npages; |
| 704 | u32 offset = 0; |
| 705 | int ncont = 0; |
| 706 | int err; |
| 707 | |
| 708 | if (!ucmd->buf_addr) |
| 709 | return -EINVAL; |
| 710 | |
| 711 | context = to_mucontext(pd->uobject->context); |
| 712 | rwq->umem = ib_umem_get(pd->uobject->context, ucmd->buf_addr, |
| 713 | rwq->buf_size, 0, 0); |
| 714 | if (IS_ERR(rwq->umem)) { |
| 715 | mlx5_ib_dbg(dev, "umem_get failed\n"); |
| 716 | err = PTR_ERR(rwq->umem); |
| 717 | return err; |
| 718 | } |
| 719 | |
Majd Dibbiny | 762f899 | 2016-10-27 16:36:47 +0300 | [diff] [blame] | 720 | 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] | 721 | &ncont, NULL); |
| 722 | err = mlx5_ib_get_buf_offset(ucmd->buf_addr, page_shift, |
| 723 | &rwq->rq_page_offset); |
| 724 | if (err) { |
| 725 | mlx5_ib_warn(dev, "bad offset\n"); |
| 726 | goto err_umem; |
| 727 | } |
| 728 | |
| 729 | rwq->rq_num_pas = ncont; |
| 730 | rwq->page_shift = page_shift; |
| 731 | rwq->log_page_size = page_shift - MLX5_ADAPTER_PAGE_SHIFT; |
| 732 | rwq->wq_sig = !!(ucmd->flags & MLX5_WQ_FLAG_SIGNATURE); |
| 733 | |
| 734 | mlx5_ib_dbg(dev, "addr 0x%llx, size %zd, npages %d, page_shift %d, ncont %d, offset %d\n", |
| 735 | (unsigned long long)ucmd->buf_addr, rwq->buf_size, |
| 736 | npages, page_shift, ncont, offset); |
| 737 | |
| 738 | err = mlx5_ib_db_map_user(context, ucmd->db_addr, &rwq->db); |
| 739 | if (err) { |
| 740 | mlx5_ib_dbg(dev, "map failed\n"); |
| 741 | goto err_umem; |
| 742 | } |
| 743 | |
| 744 | rwq->create_type = MLX5_WQ_USER; |
| 745 | return 0; |
| 746 | |
| 747 | err_umem: |
| 748 | ib_umem_release(rwq->umem); |
| 749 | return err; |
| 750 | } |
| 751 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 752 | static int adjust_bfregn(struct mlx5_ib_dev *dev, |
| 753 | struct mlx5_bfreg_info *bfregi, int bfregn) |
| 754 | { |
| 755 | return bfregn / MLX5_NON_FP_BFREGS_PER_UAR * MLX5_BFREGS_PER_UAR + |
| 756 | bfregn % MLX5_NON_FP_BFREGS_PER_UAR; |
| 757 | } |
| 758 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 759 | static int create_user_qp(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 760 | struct mlx5_ib_qp *qp, struct ib_udata *udata, |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 761 | struct ib_qp_init_attr *attr, |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 762 | u32 **in, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 763 | struct mlx5_ib_create_qp_resp *resp, int *inlen, |
| 764 | struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 765 | { |
| 766 | struct mlx5_ib_ucontext *context; |
| 767 | struct mlx5_ib_create_qp ucmd; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 768 | struct mlx5_ib_ubuffer *ubuffer = &base->ubuffer; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 769 | int page_shift = 0; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 770 | int uar_index = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 771 | int npages; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 772 | u32 offset = 0; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 773 | int bfregn; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 774 | int ncont = 0; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 775 | __be64 *pas; |
| 776 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 777 | int err; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 778 | u16 uid; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 779 | |
| 780 | err = ib_copy_from_udata(&ucmd, udata, sizeof(ucmd)); |
| 781 | if (err) { |
| 782 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 783 | return err; |
| 784 | } |
| 785 | |
| 786 | context = to_mucontext(pd->uobject->context); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 787 | if (ucmd.flags & MLX5_QP_FLAG_BFREG_INDEX) { |
| 788 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, |
| 789 | ucmd.bfreg_index, true); |
| 790 | if (uar_index < 0) |
| 791 | return uar_index; |
| 792 | |
| 793 | bfregn = MLX5_IB_INVALID_BFREG; |
| 794 | } else if (qp->flags & MLX5_IB_QP_CROSS_CHANNEL) { |
| 795 | /* |
| 796 | * TBD: should come from the verbs when we have the API |
| 797 | */ |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 798 | /* In CROSS_CHANNEL CQ and QP must use the same UAR */ |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 799 | bfregn = MLX5_CROSS_CHANNEL_BFREG; |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 800 | } |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 801 | else { |
Leon Romanovsky | ffaf58d | 2018-07-08 13:50:20 +0300 | [diff] [blame] | 802 | bfregn = alloc_bfreg(dev, &context->bfregi); |
| 803 | if (bfregn < 0) |
| 804 | return bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 805 | } |
| 806 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 807 | 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] | 808 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 809 | uar_index = bfregn_to_uar_index(dev, &context->bfregi, bfregn, |
| 810 | false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 811 | |
Haggai Eran | 48fea83 | 2014-05-22 14:50:11 +0300 | [diff] [blame] | 812 | qp->rq.offset = 0; |
| 813 | qp->sq.wqe_shift = ilog2(MLX5_SEND_WQE_BB); |
| 814 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
| 815 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 816 | err = set_user_buf_size(dev, qp, &ucmd, base, attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 817 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 818 | goto err_bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 819 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 820 | if (ucmd.buf_addr && ubuffer->buf_size) { |
| 821 | ubuffer->buf_addr = ucmd.buf_addr; |
| 822 | err = mlx5_ib_umem_get(dev, pd, ubuffer->buf_addr, |
| 823 | ubuffer->buf_size, |
| 824 | &ubuffer->umem, &npages, &page_shift, |
| 825 | &ncont, &offset); |
| 826 | if (err) |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 827 | goto err_bfreg; |
Eli Cohen | 9e9c47d | 2014-01-14 17:45:21 +0200 | [diff] [blame] | 828 | } else { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 829 | ubuffer->umem = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 830 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 831 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 832 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 833 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 834 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 835 | if (!*in) { |
| 836 | err = -ENOMEM; |
| 837 | goto err_umem; |
| 838 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 839 | |
Yishai Hadas | 7422edc | 2018-12-23 13:12:21 +0200 | [diff] [blame] | 840 | uid = (attr->qp_type != IB_QPT_XRC_TGT && |
| 841 | attr->qp_type != IB_QPT_XRC_INI) ? to_mpd(pd)->uid : 0; |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 842 | MLX5_SET(create_qp_in, *in, uid, uid); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 843 | pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, *in, pas); |
| 844 | if (ubuffer->umem) |
| 845 | mlx5_ib_populate_pas(dev, ubuffer->umem, page_shift, pas, 0); |
| 846 | |
| 847 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 848 | |
| 849 | MLX5_SET(qpc, qpc, log_page_size, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 850 | MLX5_SET(qpc, qpc, page_offset, offset); |
| 851 | |
| 852 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 853 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 854 | resp->bfreg_index = adjust_bfregn(dev, &context->bfregi, bfregn); |
| 855 | else |
| 856 | resp->bfreg_index = MLX5_IB_INVALID_BFREG; |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 857 | qp->bfregn = bfregn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 858 | |
| 859 | err = mlx5_ib_db_map_user(context, ucmd.db_addr, &qp->db); |
| 860 | if (err) { |
| 861 | mlx5_ib_dbg(dev, "map failed\n"); |
| 862 | goto err_free; |
| 863 | } |
| 864 | |
Jason Gunthorpe | 41d902c | 2018-04-03 10:00:53 +0300 | [diff] [blame] | 865 | err = ib_copy_to_udata(udata, resp, min(udata->outlen, sizeof(*resp))); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 866 | if (err) { |
| 867 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 868 | goto err_unmap; |
| 869 | } |
| 870 | qp->create_type = MLX5_QP_USER; |
| 871 | |
| 872 | return 0; |
| 873 | |
| 874 | err_unmap: |
| 875 | mlx5_ib_db_unmap_user(context, &qp->db); |
| 876 | |
| 877 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 878 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 879 | |
| 880 | err_umem: |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 881 | if (ubuffer->umem) |
| 882 | ib_umem_release(ubuffer->umem); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 883 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 884 | err_bfreg: |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 885 | if (bfregn != MLX5_IB_INVALID_BFREG) |
| 886 | mlx5_ib_free_bfreg(dev, &context->bfregi, bfregn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 887 | return err; |
| 888 | } |
| 889 | |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 890 | static void destroy_qp_user(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 891 | struct mlx5_ib_qp *qp, struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 892 | { |
| 893 | struct mlx5_ib_ucontext *context; |
| 894 | |
| 895 | context = to_mucontext(pd->uobject->context); |
| 896 | mlx5_ib_db_unmap_user(context, &qp->db); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 897 | if (base->ubuffer.umem) |
| 898 | ib_umem_release(base->ubuffer.umem); |
Yishai Hadas | 1ee47ab | 2017-12-24 16:31:36 +0200 | [diff] [blame] | 899 | |
| 900 | /* |
| 901 | * Free only the BFREGs which are handled by the kernel. |
| 902 | * BFREGs of UARs allocated dynamically are handled by user. |
| 903 | */ |
| 904 | if (qp->bfregn != MLX5_IB_INVALID_BFREG) |
| 905 | mlx5_ib_free_bfreg(dev, &context->bfregi, qp->bfregn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 906 | } |
| 907 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 908 | /* get_sq_edge - Get the next nearby edge. |
| 909 | * |
| 910 | * An 'edge' is defined as the first following address after the end |
| 911 | * of the fragment or the SQ. Accordingly, during the WQE construction |
| 912 | * which repetitively increases the pointer to write the next data, it |
| 913 | * simply should check if it gets to an edge. |
| 914 | * |
| 915 | * @sq - SQ buffer. |
| 916 | * @idx - Stride index in the SQ buffer. |
| 917 | * |
| 918 | * Return: |
| 919 | * The new edge. |
| 920 | */ |
| 921 | static void *get_sq_edge(struct mlx5_ib_wq *sq, u32 idx) |
| 922 | { |
| 923 | void *fragment_end; |
| 924 | |
| 925 | fragment_end = mlx5_frag_buf_get_wqe |
| 926 | (&sq->fbc, |
| 927 | mlx5_frag_buf_get_idx_last_contig_stride(&sq->fbc, idx)); |
| 928 | |
| 929 | return fragment_end + MLX5_SEND_WQE_BB; |
| 930 | } |
| 931 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 932 | static int create_kernel_qp(struct mlx5_ib_dev *dev, |
| 933 | struct ib_qp_init_attr *init_attr, |
| 934 | struct mlx5_ib_qp *qp, |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 935 | u32 **in, int *inlen, |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 936 | struct mlx5_ib_qp_base *base) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 937 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 938 | int uar_index; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 939 | void *qpc; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 940 | int err; |
| 941 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 942 | if (init_attr->create_flags & ~(IB_QP_CREATE_SIGNATURE_EN | |
| 943 | IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK | |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 944 | IB_QP_CREATE_IPOIB_UD_LSO | |
Erez Shitrit | 93d576a | 2017-04-13 06:37:06 +0300 | [diff] [blame] | 945 | IB_QP_CREATE_NETIF_QP | |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 946 | mlx5_ib_create_qp_sqpn_qp1())) |
Eli Cohen | 1a4c3a3 | 2014-02-06 17:41:25 +0200 | [diff] [blame] | 947 | return -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 948 | |
| 949 | if (init_attr->qp_type == MLX5_IB_QPT_REG_UMR) |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 950 | qp->bf.bfreg = &dev->fp_bfreg; |
| 951 | else |
| 952 | qp->bf.bfreg = &dev->bfreg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 953 | |
Eli Cohen | d8030b0 | 2017-02-09 19:31:47 +0200 | [diff] [blame] | 954 | /* We need to divide by two since each register is comprised of |
| 955 | * two buffers of identical size, namely odd and even |
| 956 | */ |
| 957 | 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] | 958 | uar_index = qp->bf.bfreg->index; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 959 | |
| 960 | err = calc_sq_size(dev, init_attr, qp); |
| 961 | if (err < 0) { |
| 962 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 963 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | qp->rq.offset = 0; |
| 967 | qp->sq.offset = qp->rq.wqe_cnt << qp->rq.wqe_shift; |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 968 | 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] | 969 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 970 | err = mlx5_frag_buf_alloc_node(dev->mdev, base->ubuffer.buf_size, |
| 971 | &qp->buf, dev->mdev->priv.numa_node); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 972 | if (err) { |
| 973 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 974 | return err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 975 | } |
| 976 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 977 | if (qp->rq.wqe_cnt) |
| 978 | mlx5_init_fbc(qp->buf.frags, qp->rq.wqe_shift, |
| 979 | ilog2(qp->rq.wqe_cnt), &qp->rq.fbc); |
| 980 | |
| 981 | if (qp->sq.wqe_cnt) { |
| 982 | int sq_strides_offset = (qp->sq.offset & (PAGE_SIZE - 1)) / |
| 983 | MLX5_SEND_WQE_BB; |
| 984 | mlx5_init_fbc_offset(qp->buf.frags + |
| 985 | (qp->sq.offset / PAGE_SIZE), |
| 986 | ilog2(MLX5_SEND_WQE_BB), |
| 987 | ilog2(qp->sq.wqe_cnt), |
| 988 | sq_strides_offset, &qp->sq.fbc); |
| 989 | |
| 990 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
| 991 | } |
| 992 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 993 | *inlen = MLX5_ST_SZ_BYTES(create_qp_in) + |
| 994 | MLX5_FLD_SZ_BYTES(create_qp_in, pas[0]) * qp->buf.npages; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 995 | *in = kvzalloc(*inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 996 | if (!*in) { |
| 997 | err = -ENOMEM; |
| 998 | goto err_buf; |
| 999 | } |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1000 | |
| 1001 | qpc = MLX5_ADDR_OF(create_qp_in, *in, qpc); |
| 1002 | MLX5_SET(qpc, qpc, uar_page, uar_index); |
| 1003 | MLX5_SET(qpc, qpc, log_page_size, qp->buf.page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1004 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1005 | /* Set "fast registration enabled" for all kernel QPs */ |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1006 | MLX5_SET(qpc, qpc, fre, 1); |
| 1007 | MLX5_SET(qpc, qpc, rlky, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1008 | |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 1009 | if (init_attr->create_flags & mlx5_ib_create_qp_sqpn_qp1()) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1010 | MLX5_SET(qpc, qpc, deth_sqpn, 1); |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 1011 | qp->flags |= MLX5_IB_QP_SQPN_QP1; |
| 1012 | } |
| 1013 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1014 | mlx5_fill_page_frag_array(&qp->buf, |
| 1015 | (__be64 *)MLX5_ADDR_OF(create_qp_in, |
| 1016 | *in, pas)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1017 | |
Jack Morgenstein | 9603b61 | 2014-07-28 23:30:22 +0300 | [diff] [blame] | 1018 | err = mlx5_db_alloc(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1019 | if (err) { |
| 1020 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1021 | goto err_free; |
| 1022 | } |
| 1023 | |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1024 | qp->sq.wrid = kvmalloc_array(qp->sq.wqe_cnt, |
| 1025 | sizeof(*qp->sq.wrid), GFP_KERNEL); |
| 1026 | qp->sq.wr_data = kvmalloc_array(qp->sq.wqe_cnt, |
| 1027 | sizeof(*qp->sq.wr_data), GFP_KERNEL); |
| 1028 | qp->rq.wrid = kvmalloc_array(qp->rq.wqe_cnt, |
| 1029 | sizeof(*qp->rq.wrid), GFP_KERNEL); |
| 1030 | qp->sq.w_list = kvmalloc_array(qp->sq.wqe_cnt, |
| 1031 | sizeof(*qp->sq.w_list), GFP_KERNEL); |
| 1032 | qp->sq.wqe_head = kvmalloc_array(qp->sq.wqe_cnt, |
| 1033 | sizeof(*qp->sq.wqe_head), GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1034 | |
| 1035 | if (!qp->sq.wrid || !qp->sq.wr_data || !qp->rq.wrid || |
| 1036 | !qp->sq.w_list || !qp->sq.wqe_head) { |
| 1037 | err = -ENOMEM; |
| 1038 | goto err_wrid; |
| 1039 | } |
| 1040 | qp->create_type = MLX5_QP_KERNEL; |
| 1041 | |
| 1042 | return 0; |
| 1043 | |
| 1044 | err_wrid: |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1045 | kvfree(qp->sq.wqe_head); |
| 1046 | kvfree(qp->sq.w_list); |
| 1047 | kvfree(qp->sq.wrid); |
| 1048 | kvfree(qp->sq.wr_data); |
| 1049 | kvfree(qp->rq.wrid); |
Eli Cohen | f4044da | 2017-01-03 23:55:20 +0200 | [diff] [blame] | 1050 | mlx5_db_free(dev->mdev, &qp->db); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1051 | |
| 1052 | err_free: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 1053 | kvfree(*in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1054 | |
| 1055 | err_buf: |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1056 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1057 | return err; |
| 1058 | } |
| 1059 | |
| 1060 | static void destroy_qp_kernel(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 1061 | { |
Li Dongyang | b588300 | 2017-08-16 23:31:22 +1000 | [diff] [blame] | 1062 | kvfree(qp->sq.wqe_head); |
| 1063 | kvfree(qp->sq.w_list); |
| 1064 | kvfree(qp->sq.wrid); |
| 1065 | kvfree(qp->sq.wr_data); |
| 1066 | kvfree(qp->rq.wrid); |
Eli Cohen | f4044da | 2017-01-03 23:55:20 +0200 | [diff] [blame] | 1067 | mlx5_db_free(dev->mdev, &qp->db); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 1068 | mlx5_frag_buf_free(dev->mdev, &qp->buf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1069 | } |
| 1070 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1071 | 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] | 1072 | { |
| 1073 | if (attr->srq || (attr->qp_type == IB_QPT_XRC_TGT) || |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 1074 | (attr->qp_type == MLX5_IB_QPT_DCI) || |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1075 | (attr->qp_type == IB_QPT_XRC_INI)) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1076 | return MLX5_SRQ_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1077 | else if (!qp->has_rq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1078 | return MLX5_ZERO_LEN_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1079 | else |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1080 | return MLX5_NON_ZERO_RQ; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | static int is_connected(enum ib_qp_type qp_type) |
| 1084 | { |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1085 | if (qp_type == IB_QPT_RC || qp_type == IB_QPT_UC || |
| 1086 | qp_type == MLX5_IB_QPT_DCI) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1087 | return 1; |
| 1088 | |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1092 | static int create_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1093 | struct mlx5_ib_qp *qp, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1094 | struct mlx5_ib_sq *sq, u32 tdn, |
| 1095 | struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1096 | { |
Saeed Mahameed | c4f287c | 2016-07-19 20:17:12 +0300 | [diff] [blame] | 1097 | u32 in[MLX5_ST_SZ_DW(create_tis_in)] = {0}; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1098 | void *tisc = MLX5_ADDR_OF(create_tis_in, in, ctx); |
| 1099 | |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1100 | MLX5_SET(create_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1101 | MLX5_SET(tisc, tisc, transport_domain, tdn); |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1102 | if (qp->flags & MLX5_IB_QP_UNDERLAY) |
| 1103 | MLX5_SET(tisc, tisc, underlay_qpn, qp->underlay_qpn); |
| 1104 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1105 | return mlx5_core_create_tis(dev->mdev, in, sizeof(in), &sq->tisn); |
| 1106 | } |
| 1107 | |
| 1108 | static void destroy_raw_packet_qp_tis(struct mlx5_ib_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1109 | struct mlx5_ib_sq *sq, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1110 | { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1111 | 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] | 1112 | } |
| 1113 | |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1114 | static void destroy_flow_rule_vport_sq(struct mlx5_ib_dev *dev, |
| 1115 | struct mlx5_ib_sq *sq) |
| 1116 | { |
| 1117 | if (sq->flow_rule) |
| 1118 | mlx5_del_flow_rules(sq->flow_rule); |
| 1119 | } |
| 1120 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1121 | static int create_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
| 1122 | struct mlx5_ib_sq *sq, void *qpin, |
| 1123 | struct ib_pd *pd) |
| 1124 | { |
| 1125 | struct mlx5_ib_ubuffer *ubuffer = &sq->ubuffer; |
| 1126 | __be64 *pas; |
| 1127 | void *in; |
| 1128 | void *sqc; |
| 1129 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
| 1130 | void *wq; |
| 1131 | int inlen; |
| 1132 | int err; |
| 1133 | int page_shift = 0; |
| 1134 | int npages; |
| 1135 | int ncont = 0; |
| 1136 | u32 offset = 0; |
| 1137 | |
| 1138 | err = mlx5_ib_umem_get(dev, pd, ubuffer->buf_addr, ubuffer->buf_size, |
| 1139 | &sq->ubuffer.umem, &npages, &page_shift, |
| 1140 | &ncont, &offset); |
| 1141 | if (err) |
| 1142 | return err; |
| 1143 | |
| 1144 | inlen = MLX5_ST_SZ_BYTES(create_sq_in) + sizeof(u64) * ncont; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1145 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1146 | if (!in) { |
| 1147 | err = -ENOMEM; |
| 1148 | goto err_umem; |
| 1149 | } |
| 1150 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 1151 | MLX5_SET(create_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1152 | sqc = MLX5_ADDR_OF(create_sq_in, in, ctx); |
| 1153 | MLX5_SET(sqc, sqc, flush_in_error_en, 1); |
Bodong Wang | 795b609 | 2017-08-17 15:52:34 +0300 | [diff] [blame] | 1154 | if (MLX5_CAP_ETH(dev->mdev, multi_pkt_send_wqe)) |
| 1155 | MLX5_SET(sqc, sqc, allow_multi_pkt_send_wqe, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1156 | MLX5_SET(sqc, sqc, state, MLX5_SQC_STATE_RST); |
| 1157 | MLX5_SET(sqc, sqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1158 | MLX5_SET(sqc, sqc, cqn, MLX5_GET(qpc, qpc, cqn_snd)); |
| 1159 | MLX5_SET(sqc, sqc, tis_lst_sz, 1); |
| 1160 | MLX5_SET(sqc, sqc, tis_num_0, sq->tisn); |
Noa Osherovich | 96dc3fc | 2017-08-17 15:52:28 +0300 | [diff] [blame] | 1161 | if (MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 1162 | MLX5_CAP_ETH(dev->mdev, swp)) |
| 1163 | MLX5_SET(sqc, sqc, allow_swp, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1164 | |
| 1165 | wq = MLX5_ADDR_OF(sqc, sqc, wq); |
| 1166 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
| 1167 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1168 | MLX5_SET(wq, wq, uar_page, MLX5_GET(qpc, qpc, uar_page)); |
| 1169 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1170 | MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB)); |
| 1171 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_sq_size)); |
| 1172 | MLX5_SET(wq, wq, log_wq_pg_sz, page_shift - MLX5_ADAPTER_PAGE_SHIFT); |
| 1173 | MLX5_SET(wq, wq, page_offset, offset); |
| 1174 | |
| 1175 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1176 | mlx5_ib_populate_pas(dev, sq->ubuffer.umem, page_shift, pas, 0); |
| 1177 | |
| 1178 | err = mlx5_core_create_sq_tracked(dev->mdev, in, inlen, &sq->base.mqp); |
| 1179 | |
| 1180 | kvfree(in); |
| 1181 | |
| 1182 | if (err) |
| 1183 | goto err_umem; |
| 1184 | |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1185 | err = create_flow_rule_vport_sq(dev, sq); |
| 1186 | if (err) |
| 1187 | goto err_flow; |
| 1188 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1189 | return 0; |
| 1190 | |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1191 | err_flow: |
| 1192 | mlx5_core_destroy_sq_tracked(dev->mdev, &sq->base.mqp); |
| 1193 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1194 | err_umem: |
| 1195 | ib_umem_release(sq->ubuffer.umem); |
| 1196 | sq->ubuffer.umem = NULL; |
| 1197 | |
| 1198 | return err; |
| 1199 | } |
| 1200 | |
| 1201 | static void destroy_raw_packet_qp_sq(struct mlx5_ib_dev *dev, |
| 1202 | struct mlx5_ib_sq *sq) |
| 1203 | { |
Mark Bloch | b96c9dd | 2018-01-29 10:40:37 +0000 | [diff] [blame] | 1204 | destroy_flow_rule_vport_sq(dev, sq); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1205 | mlx5_core_destroy_sq_tracked(dev->mdev, &sq->base.mqp); |
| 1206 | ib_umem_release(sq->ubuffer.umem); |
| 1207 | } |
| 1208 | |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1209 | static size_t get_rq_pas_size(void *qpc) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1210 | { |
| 1211 | u32 log_page_size = MLX5_GET(qpc, qpc, log_page_size) + 12; |
| 1212 | u32 log_rq_stride = MLX5_GET(qpc, qpc, log_rq_stride); |
| 1213 | u32 log_rq_size = MLX5_GET(qpc, qpc, log_rq_size); |
| 1214 | u32 page_offset = MLX5_GET(qpc, qpc, page_offset); |
| 1215 | u32 po_quanta = 1 << (log_page_size - 6); |
| 1216 | u32 rq_sz = 1 << (log_rq_size + 4 + log_rq_stride); |
| 1217 | u32 page_size = 1 << log_page_size; |
| 1218 | u32 rq_sz_po = rq_sz + (page_offset * po_quanta); |
| 1219 | u32 rq_num_pas = (rq_sz_po + page_size - 1) / page_size; |
| 1220 | |
| 1221 | return rq_num_pas * sizeof(u64); |
| 1222 | } |
| 1223 | |
| 1224 | static int create_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1225 | struct mlx5_ib_rq *rq, void *qpin, |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1226 | size_t qpinlen, struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1227 | { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1228 | struct mlx5_ib_qp *mqp = rq->base.container_mibqp; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1229 | __be64 *pas; |
| 1230 | __be64 *qp_pas; |
| 1231 | void *in; |
| 1232 | void *rqc; |
| 1233 | void *wq; |
| 1234 | void *qpc = MLX5_ADDR_OF(create_qp_in, qpin, qpc); |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1235 | size_t rq_pas_size = get_rq_pas_size(qpc); |
| 1236 | size_t inlen; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1237 | int err; |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 1238 | |
| 1239 | if (qpinlen < rq_pas_size + MLX5_BYTE_OFF(create_qp_in, pas)) |
| 1240 | return -EINVAL; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1241 | |
| 1242 | inlen = MLX5_ST_SZ_BYTES(create_rq_in) + rq_pas_size; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1243 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1244 | if (!in) |
| 1245 | return -ENOMEM; |
| 1246 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1247 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1248 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1249 | if (!(rq->flags & MLX5_IB_RQ_CVLAN_STRIPPING)) |
| 1250 | MLX5_SET(rqc, rqc, vsd, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1251 | MLX5_SET(rqc, rqc, mem_rq_type, MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 1252 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 1253 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 1254 | MLX5_SET(rqc, rqc, user_index, MLX5_GET(qpc, qpc, user_index)); |
| 1255 | MLX5_SET(rqc, rqc, cqn, MLX5_GET(qpc, qpc, cqn_rcv)); |
| 1256 | |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1257 | if (mqp->flags & MLX5_IB_QP_CAP_SCATTER_FCS) |
| 1258 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 1259 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1260 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
| 1261 | MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1262 | if (rq->flags & MLX5_IB_RQ_PCI_WRITE_END_PADDING) |
| 1263 | 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] | 1264 | MLX5_SET(wq, wq, page_offset, MLX5_GET(qpc, qpc, page_offset)); |
| 1265 | MLX5_SET(wq, wq, pd, MLX5_GET(qpc, qpc, pd)); |
| 1266 | MLX5_SET64(wq, wq, dbr_addr, MLX5_GET64(qpc, qpc, dbr_addr)); |
| 1267 | MLX5_SET(wq, wq, log_wq_stride, MLX5_GET(qpc, qpc, log_rq_stride) + 4); |
| 1268 | MLX5_SET(wq, wq, log_wq_pg_sz, MLX5_GET(qpc, qpc, log_page_size)); |
| 1269 | MLX5_SET(wq, wq, log_wq_sz, MLX5_GET(qpc, qpc, log_rq_size)); |
| 1270 | |
| 1271 | pas = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 1272 | qp_pas = (__be64 *)MLX5_ADDR_OF(create_qp_in, qpin, pas); |
| 1273 | memcpy(pas, qp_pas, rq_pas_size); |
| 1274 | |
| 1275 | err = mlx5_core_create_rq_tracked(dev->mdev, in, inlen, &rq->base.mqp); |
| 1276 | |
| 1277 | kvfree(in); |
| 1278 | |
| 1279 | return err; |
| 1280 | } |
| 1281 | |
| 1282 | static void destroy_raw_packet_qp_rq(struct mlx5_ib_dev *dev, |
| 1283 | struct mlx5_ib_rq *rq) |
| 1284 | { |
| 1285 | mlx5_core_destroy_rq_tracked(dev->mdev, &rq->base.mqp); |
| 1286 | } |
| 1287 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1288 | static bool tunnel_offload_supported(struct mlx5_core_dev *dev) |
| 1289 | { |
| 1290 | return (MLX5_CAP_ETH(dev, tunnel_stateless_vxlan) || |
| 1291 | MLX5_CAP_ETH(dev, tunnel_stateless_gre) || |
| 1292 | MLX5_CAP_ETH(dev, tunnel_stateless_geneve_rx)); |
| 1293 | } |
| 1294 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1295 | static void destroy_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
| 1296 | struct mlx5_ib_rq *rq, |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1297 | u32 qp_flags_en, |
| 1298 | struct ib_pd *pd) |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1299 | { |
| 1300 | if (qp_flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1301 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1302 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1303 | mlx5_cmd_destroy_tir(dev->mdev, rq->tirn, to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1304 | } |
| 1305 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1306 | static int create_raw_packet_qp_tir(struct mlx5_ib_dev *dev, |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1307 | struct mlx5_ib_rq *rq, u32 tdn, |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1308 | u32 *qp_flags_en, |
| 1309 | struct ib_pd *pd) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1310 | { |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1311 | u8 lb_flag = 0; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1312 | u32 *in; |
| 1313 | void *tirc; |
| 1314 | int inlen; |
| 1315 | int err; |
| 1316 | |
| 1317 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1318 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1319 | if (!in) |
| 1320 | return -ENOMEM; |
| 1321 | |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1322 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1323 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1324 | MLX5_SET(tirc, tirc, disp_type, MLX5_TIRC_DISP_TYPE_DIRECT); |
| 1325 | MLX5_SET(tirc, tirc, inline_rqn, rq->base.mqp.qpn); |
| 1326 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1327 | if (*qp_flags_en & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1328 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1329 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1330 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) |
| 1331 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1332 | |
| 1333 | if (*qp_flags_en & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) |
| 1334 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
| 1335 | |
| 1336 | if (dev->rep) { |
| 1337 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1338 | *qp_flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 1339 | } |
| 1340 | |
| 1341 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
Mark Bloch | ec9c2fb | 2018-01-15 13:11:37 +0000 | [diff] [blame] | 1342 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1343 | err = mlx5_core_create_tir(dev->mdev, in, inlen, &rq->tirn); |
| 1344 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1345 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1346 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1347 | |
| 1348 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1349 | destroy_raw_packet_qp_tir(dev, rq, 0, pd); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1350 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1351 | kvfree(in); |
| 1352 | |
| 1353 | return err; |
| 1354 | } |
| 1355 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1356 | 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] | 1357 | u32 *in, size_t inlen, |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1358 | struct ib_pd *pd, |
| 1359 | struct ib_udata *udata, |
| 1360 | struct mlx5_ib_create_qp_resp *resp) |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1361 | { |
| 1362 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1363 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1364 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1365 | struct ib_uobject *uobj = pd->uobject; |
| 1366 | struct ib_ucontext *ucontext = uobj->context; |
| 1367 | struct mlx5_ib_ucontext *mucontext = to_mucontext(ucontext); |
| 1368 | int err; |
| 1369 | u32 tdn = mucontext->tdn; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1370 | u16 uid = to_mpd(pd)->uid; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1371 | |
| 1372 | if (qp->sq.wqe_cnt) { |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1373 | err = create_raw_packet_qp_tis(dev, qp, sq, tdn, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1374 | if (err) |
| 1375 | return err; |
| 1376 | |
| 1377 | err = create_raw_packet_qp_sq(dev, sq, in, pd); |
| 1378 | if (err) |
| 1379 | goto err_destroy_tis; |
| 1380 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1381 | if (uid) { |
| 1382 | resp->tisn = sq->tisn; |
| 1383 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TISN; |
| 1384 | resp->sqn = sq->base.mqp.qpn; |
| 1385 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_SQN; |
| 1386 | } |
| 1387 | |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1388 | sq->base.container_mibqp = qp; |
Majd Dibbiny | 1d31e9c | 2017-08-23 08:35:41 +0300 | [diff] [blame] | 1389 | sq->base.mqp.event = mlx5_ib_qp_event; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | if (qp->rq.wqe_cnt) { |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1393 | rq->base.container_mibqp = qp; |
| 1394 | |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1395 | if (qp->flags & MLX5_IB_QP_CVLAN_STRIPPING) |
| 1396 | rq->flags |= MLX5_IB_RQ_CVLAN_STRIPPING; |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 1397 | if (qp->flags & MLX5_IB_QP_PCI_WRITE_END_PADDING) |
| 1398 | rq->flags |= MLX5_IB_RQ_PCI_WRITE_END_PADDING; |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 1399 | err = create_raw_packet_qp_rq(dev, rq, in, inlen, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1400 | if (err) |
| 1401 | goto err_destroy_sq; |
| 1402 | |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1403 | err = create_raw_packet_qp_tir(dev, rq, tdn, &qp->flags_en, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1404 | if (err) |
| 1405 | goto err_destroy_rq; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1406 | |
| 1407 | if (uid) { |
| 1408 | resp->rqn = rq->base.mqp.qpn; |
| 1409 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_RQN; |
| 1410 | resp->tirn = rq->tirn; |
| 1411 | resp->comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
| 1412 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | qp->trans_qp.base.mqp.qpn = qp->sq.wqe_cnt ? sq->base.mqp.qpn : |
| 1416 | rq->base.mqp.qpn; |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1417 | err = ib_copy_to_udata(udata, resp, min(udata->outlen, sizeof(*resp))); |
| 1418 | if (err) |
| 1419 | goto err_destroy_tir; |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1420 | |
| 1421 | return 0; |
| 1422 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1423 | err_destroy_tir: |
| 1424 | destroy_raw_packet_qp_tir(dev, rq, qp->flags_en, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1425 | err_destroy_rq: |
| 1426 | destroy_raw_packet_qp_rq(dev, rq); |
| 1427 | err_destroy_sq: |
| 1428 | if (!qp->sq.wqe_cnt) |
| 1429 | return err; |
| 1430 | destroy_raw_packet_qp_sq(dev, sq); |
| 1431 | err_destroy_tis: |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1432 | destroy_raw_packet_qp_tis(dev, sq, pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1433 | |
| 1434 | return err; |
| 1435 | } |
| 1436 | |
| 1437 | static void destroy_raw_packet_qp(struct mlx5_ib_dev *dev, |
| 1438 | struct mlx5_ib_qp *qp) |
| 1439 | { |
| 1440 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 1441 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1442 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1443 | |
| 1444 | if (qp->rq.wqe_cnt) { |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1445 | 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] | 1446 | destroy_raw_packet_qp_rq(dev, rq); |
| 1447 | } |
| 1448 | |
| 1449 | if (qp->sq.wqe_cnt) { |
| 1450 | destroy_raw_packet_qp_sq(dev, sq); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 1451 | destroy_raw_packet_qp_tis(dev, sq, qp->ibqp.pd); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | static void raw_packet_qp_copy_info(struct mlx5_ib_qp *qp, |
| 1456 | struct mlx5_ib_raw_packet_qp *raw_packet_qp) |
| 1457 | { |
| 1458 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 1459 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 1460 | |
| 1461 | sq->sq = &qp->sq; |
| 1462 | rq->rq = &qp->rq; |
| 1463 | sq->doorbell = &qp->db; |
| 1464 | rq->doorbell = &qp->db; |
| 1465 | } |
| 1466 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1467 | static void destroy_rss_raw_qp_tir(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 1468 | { |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1469 | if (qp->flags_en & (MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1470 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) |
| 1471 | mlx5_ib_disable_lb(dev, false, true); |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1472 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1473 | to_mpd(qp->ibqp.pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | static int create_rss_raw_qp_tir(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 1477 | struct ib_pd *pd, |
| 1478 | struct ib_qp_init_attr *init_attr, |
| 1479 | struct ib_udata *udata) |
| 1480 | { |
| 1481 | struct ib_uobject *uobj = pd->uobject; |
| 1482 | struct ib_ucontext *ucontext = uobj->context; |
| 1483 | struct mlx5_ib_ucontext *mucontext = to_mucontext(ucontext); |
| 1484 | struct mlx5_ib_create_qp_resp resp = {}; |
| 1485 | int inlen; |
| 1486 | int err; |
| 1487 | u32 *in; |
| 1488 | void *tirc; |
| 1489 | void *hfso; |
| 1490 | u32 selected_fields = 0; |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1491 | u32 outer_l4; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1492 | size_t min_resp_len; |
| 1493 | u32 tdn = mucontext->tdn; |
| 1494 | struct mlx5_ib_create_qp_rss ucmd = {}; |
| 1495 | size_t required_cmd_sz; |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1496 | u8 lb_flag = 0; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1497 | |
| 1498 | if (init_attr->qp_type != IB_QPT_RAW_PACKET) |
| 1499 | return -EOPNOTSUPP; |
| 1500 | |
| 1501 | if (init_attr->create_flags || init_attr->send_cq) |
| 1502 | return -EINVAL; |
| 1503 | |
Eli Cohen | 2f5ff26 | 2017-01-03 23:55:21 +0200 | [diff] [blame] | 1504 | min_resp_len = offsetof(typeof(resp), bfreg_index) + sizeof(resp.bfreg_index); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1505 | if (udata->outlen < min_resp_len) |
| 1506 | return -EINVAL; |
| 1507 | |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1508 | required_cmd_sz = offsetof(typeof(ucmd), flags) + sizeof(ucmd.flags); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1509 | if (udata->inlen < required_cmd_sz) { |
| 1510 | mlx5_ib_dbg(dev, "invalid inlen\n"); |
| 1511 | return -EINVAL; |
| 1512 | } |
| 1513 | |
| 1514 | if (udata->inlen > sizeof(ucmd) && |
| 1515 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 1516 | udata->inlen - sizeof(ucmd))) { |
| 1517 | mlx5_ib_dbg(dev, "inlen is not supported\n"); |
| 1518 | return -EOPNOTSUPP; |
| 1519 | } |
| 1520 | |
| 1521 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) { |
| 1522 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1523 | return -EFAULT; |
| 1524 | } |
| 1525 | |
| 1526 | if (ucmd.comp_mask) { |
| 1527 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 1528 | return -EOPNOTSUPP; |
| 1529 | } |
| 1530 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1531 | if (ucmd.flags & ~(MLX5_QP_FLAG_TUNNEL_OFFLOADS | |
| 1532 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1533 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC)) { |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1534 | mlx5_ib_dbg(dev, "invalid flags\n"); |
| 1535 | return -EOPNOTSUPP; |
| 1536 | } |
| 1537 | |
| 1538 | if (ucmd.flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS && |
| 1539 | !tunnel_offload_supported(dev->mdev)) { |
| 1540 | mlx5_ib_dbg(dev, "tunnel offloads isn't supported\n"); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1541 | return -EOPNOTSUPP; |
| 1542 | } |
| 1543 | |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1544 | if (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_INNER && |
| 1545 | !(ucmd.flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS)) { |
| 1546 | mlx5_ib_dbg(dev, "Tunnel offloads must be set for inner RSS\n"); |
| 1547 | return -EOPNOTSUPP; |
| 1548 | } |
| 1549 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1550 | if (ucmd.flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC || dev->rep) { |
| 1551 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST; |
| 1552 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 1553 | } |
| 1554 | |
| 1555 | if (ucmd.flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) { |
| 1556 | lb_flag |= MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST; |
| 1557 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC; |
| 1558 | } |
| 1559 | |
Jason Gunthorpe | 41d902c | 2018-04-03 10:00:53 +0300 | [diff] [blame] | 1560 | err = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp))); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1561 | if (err) { |
| 1562 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1563 | return -EINVAL; |
| 1564 | } |
| 1565 | |
| 1566 | inlen = MLX5_ST_SZ_BYTES(create_tir_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 1567 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1568 | if (!in) |
| 1569 | return -ENOMEM; |
| 1570 | |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1571 | MLX5_SET(create_tir_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1572 | tirc = MLX5_ADDR_OF(create_tir_in, in, ctx); |
| 1573 | MLX5_SET(tirc, tirc, disp_type, |
| 1574 | MLX5_TIRC_DISP_TYPE_INDIRECT); |
| 1575 | MLX5_SET(tirc, tirc, indirect_table, |
| 1576 | init_attr->rwq_ind_tbl->ind_tbl_num); |
| 1577 | MLX5_SET(tirc, tirc, transport_domain, tdn); |
| 1578 | |
| 1579 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1580 | |
| 1581 | if (ucmd.flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS) |
| 1582 | MLX5_SET(tirc, tirc, tunneled_offload_en, 1); |
| 1583 | |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1584 | MLX5_SET(tirc, tirc, self_lb_block, lb_flag); |
| 1585 | |
Maor Gottlieb | 309fa34 | 2017-10-19 08:25:56 +0300 | [diff] [blame] | 1586 | if (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_INNER) |
| 1587 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_inner); |
| 1588 | else |
| 1589 | hfso = MLX5_ADDR_OF(tirc, tirc, rx_hash_field_selector_outer); |
| 1590 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1591 | switch (ucmd.rx_hash_function) { |
| 1592 | case MLX5_RX_HASH_FUNC_TOEPLITZ: |
| 1593 | { |
| 1594 | void *rss_key = MLX5_ADDR_OF(tirc, tirc, rx_hash_toeplitz_key); |
| 1595 | size_t len = MLX5_FLD_SZ_BYTES(tirc, rx_hash_toeplitz_key); |
| 1596 | |
| 1597 | if (len != ucmd.rx_key_len) { |
| 1598 | err = -EINVAL; |
| 1599 | goto err; |
| 1600 | } |
| 1601 | |
| 1602 | MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_TOEPLITZ); |
| 1603 | MLX5_SET(tirc, tirc, rx_hash_symmetric, 1); |
| 1604 | memcpy(rss_key, ucmd.rx_hash_key, len); |
| 1605 | break; |
| 1606 | } |
| 1607 | default: |
| 1608 | err = -EOPNOTSUPP; |
| 1609 | goto err; |
| 1610 | } |
| 1611 | |
| 1612 | if (!ucmd.rx_hash_fields_mask) { |
| 1613 | /* special case when this TIR serves as steering entry without hashing */ |
| 1614 | if (!init_attr->rwq_ind_tbl->log_ind_tbl_size) |
| 1615 | goto create_tir; |
| 1616 | err = -EINVAL; |
| 1617 | goto err; |
| 1618 | } |
| 1619 | |
| 1620 | if (((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1621 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) && |
| 1622 | ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1623 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6))) { |
| 1624 | err = -EINVAL; |
| 1625 | goto err; |
| 1626 | } |
| 1627 | |
| 1628 | /* If none of IPV4 & IPV6 SRC/DST was set - this bit field is ignored */ |
| 1629 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1630 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4)) |
| 1631 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1632 | MLX5_L3_PROT_TYPE_IPV4); |
| 1633 | else if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6) || |
| 1634 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
| 1635 | MLX5_SET(rx_hash_field_select, hfso, l3_prot_type, |
| 1636 | MLX5_L3_PROT_TYPE_IPV6); |
| 1637 | |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1638 | outer_l4 = ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1639 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) << 0 | |
| 1640 | ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1641 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) << 1 | |
| 1642 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) << 2; |
| 1643 | |
| 1644 | /* Check that only one l4 protocol is set */ |
| 1645 | if (outer_l4 & (outer_l4 - 1)) { |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1646 | err = -EINVAL; |
| 1647 | goto err; |
| 1648 | } |
| 1649 | |
| 1650 | /* If none of TCP & UDP SRC/DST was set - this bit field is ignored */ |
| 1651 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1652 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP)) |
| 1653 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1654 | MLX5_L4_PROT_TYPE_TCP); |
| 1655 | else if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP) || |
| 1656 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
| 1657 | MLX5_SET(rx_hash_field_select, hfso, l4_prot_type, |
| 1658 | MLX5_L4_PROT_TYPE_UDP); |
| 1659 | |
| 1660 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV4) || |
| 1661 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_IPV6)) |
| 1662 | selected_fields |= MLX5_HASH_FIELD_SEL_SRC_IP; |
| 1663 | |
| 1664 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV4) || |
| 1665 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_IPV6)) |
| 1666 | selected_fields |= MLX5_HASH_FIELD_SEL_DST_IP; |
| 1667 | |
| 1668 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_TCP) || |
| 1669 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_SRC_PORT_UDP)) |
| 1670 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_SPORT; |
| 1671 | |
| 1672 | if ((ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_TCP) || |
| 1673 | (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_DST_PORT_UDP)) |
| 1674 | selected_fields |= MLX5_HASH_FIELD_SEL_L4_DPORT; |
| 1675 | |
Matan Barak | 2d93fc8 | 2018-03-28 09:27:55 +0300 | [diff] [blame] | 1676 | if (ucmd.rx_hash_fields_mask & MLX5_RX_HASH_IPSEC_SPI) |
| 1677 | selected_fields |= MLX5_HASH_FIELD_SEL_IPSEC_SPI; |
| 1678 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1679 | MLX5_SET(rx_hash_field_select, hfso, selected_fields, selected_fields); |
| 1680 | |
| 1681 | create_tir: |
| 1682 | err = mlx5_core_create_tir(dev->mdev, in, inlen, &qp->rss_qp.tirn); |
| 1683 | |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1684 | if (!err && MLX5_GET(tirc, tirc, self_lb_block)) { |
| 1685 | err = mlx5_ib_enable_lb(dev, false, true); |
| 1686 | |
| 1687 | if (err) |
Yishai Hadas | 443c1cf | 2018-09-20 21:39:26 +0300 | [diff] [blame] | 1688 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, |
| 1689 | to_mpd(pd)->uid); |
Mark Bloch | 0042f9e | 2018-09-17 13:30:49 +0300 | [diff] [blame] | 1690 | } |
| 1691 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1692 | if (err) |
| 1693 | goto err; |
| 1694 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1695 | if (mucontext->devx_uid) { |
| 1696 | resp.comp_mask |= MLX5_IB_CREATE_QP_RESP_MASK_TIRN; |
| 1697 | resp.tirn = qp->rss_qp.tirn; |
| 1698 | } |
| 1699 | |
| 1700 | err = ib_copy_to_udata(udata, &resp, min(udata->outlen, sizeof(resp))); |
| 1701 | if (err) |
| 1702 | goto err_copy; |
| 1703 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1704 | kvfree(in); |
| 1705 | /* qpn is reserved for that QP */ |
| 1706 | qp->trans_qp.base.mqp.qpn = 0; |
Yishai Hadas | d9f88e5 | 2016-08-28 10:58:37 +0300 | [diff] [blame] | 1707 | qp->flags |= MLX5_IB_QP_RSS; |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1708 | return 0; |
| 1709 | |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 1710 | err_copy: |
| 1711 | mlx5_cmd_destroy_tir(dev->mdev, qp->rss_qp.tirn, mucontext->devx_uid); |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1712 | err: |
| 1713 | kvfree(in); |
| 1714 | return err; |
| 1715 | } |
| 1716 | |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1717 | static void configure_responder_scat_cqe(struct ib_qp_init_attr *init_attr, |
| 1718 | void *qpc) |
| 1719 | { |
| 1720 | int rcqe_sz; |
| 1721 | |
| 1722 | if (init_attr->qp_type == MLX5_IB_QPT_DCI) |
| 1723 | return; |
| 1724 | |
| 1725 | rcqe_sz = mlx5_ib_get_cqe_size(init_attr->recv_cq); |
| 1726 | |
| 1727 | if (rcqe_sz == 128) { |
| 1728 | MLX5_SET(qpc, qpc, cs_res, MLX5_RES_SCAT_DATA64_CQE); |
| 1729 | return; |
| 1730 | } |
| 1731 | |
| 1732 | if (init_attr->qp_type != MLX5_IB_QPT_DCT) |
| 1733 | MLX5_SET(qpc, qpc, cs_res, MLX5_RES_SCAT_DATA32_CQE); |
| 1734 | } |
| 1735 | |
| 1736 | static void configure_requester_scat_cqe(struct mlx5_ib_dev *dev, |
| 1737 | struct ib_qp_init_attr *init_attr, |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1738 | struct mlx5_ib_create_qp *ucmd, |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1739 | void *qpc) |
| 1740 | { |
| 1741 | enum ib_qp_type qpt = init_attr->qp_type; |
| 1742 | int scqe_sz; |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1743 | bool allow_scat_cqe = 0; |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1744 | |
| 1745 | if (qpt == IB_QPT_UC || qpt == IB_QPT_UD) |
| 1746 | return; |
| 1747 | |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 1748 | if (ucmd) |
| 1749 | allow_scat_cqe = ucmd->flags & MLX5_QP_FLAG_ALLOW_SCATTER_CQE; |
| 1750 | |
| 1751 | 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] | 1752 | return; |
| 1753 | |
| 1754 | scqe_sz = mlx5_ib_get_cqe_size(init_attr->send_cq); |
| 1755 | if (scqe_sz == 128) { |
| 1756 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA64_CQE); |
| 1757 | return; |
| 1758 | } |
| 1759 | |
| 1760 | if (init_attr->qp_type != MLX5_IB_QPT_DCI || |
| 1761 | MLX5_CAP_GEN(dev->mdev, dc_req_scat_data_cqe)) |
| 1762 | MLX5_SET(qpc, qpc, cs_req, MLX5_REQ_SCAT_DATA32_CQE); |
| 1763 | } |
| 1764 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 1765 | static int atomic_size_to_mode(int size_mask) |
| 1766 | { |
| 1767 | /* driver does not support atomic_size > 256B |
| 1768 | * and does not know how to translate bigger sizes |
| 1769 | */ |
| 1770 | int supported_size_mask = size_mask & 0x1ff; |
| 1771 | int log_max_size; |
| 1772 | |
| 1773 | if (!supported_size_mask) |
| 1774 | return -EOPNOTSUPP; |
| 1775 | |
| 1776 | log_max_size = __fls(supported_size_mask); |
| 1777 | |
| 1778 | if (log_max_size > 3) |
| 1779 | return log_max_size; |
| 1780 | |
| 1781 | return MLX5_ATOMIC_MODE_8B; |
| 1782 | } |
| 1783 | |
| 1784 | static int get_atomic_mode(struct mlx5_ib_dev *dev, |
| 1785 | enum ib_qp_type qp_type) |
| 1786 | { |
| 1787 | u8 atomic_operations = MLX5_CAP_ATOMIC(dev->mdev, atomic_operations); |
| 1788 | u8 atomic = MLX5_CAP_GEN(dev->mdev, atomic); |
| 1789 | int atomic_mode = -EOPNOTSUPP; |
| 1790 | int atomic_size_mask; |
| 1791 | |
| 1792 | if (!atomic) |
| 1793 | return -EOPNOTSUPP; |
| 1794 | |
| 1795 | if (qp_type == MLX5_IB_QPT_DCT) |
| 1796 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_dc); |
| 1797 | else |
| 1798 | atomic_size_mask = MLX5_CAP_ATOMIC(dev->mdev, atomic_size_qp); |
| 1799 | |
| 1800 | if ((atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_CMP_SWAP) || |
| 1801 | (atomic_operations & MLX5_ATOMIC_OPS_EXTENDED_FETCH_ADD)) |
| 1802 | atomic_mode = atomic_size_to_mode(atomic_size_mask); |
| 1803 | |
| 1804 | if (atomic_mode <= 0 && |
| 1805 | (atomic_operations & MLX5_ATOMIC_OPS_CMP_SWAP && |
| 1806 | atomic_operations & MLX5_ATOMIC_OPS_FETCH_ADD)) |
| 1807 | atomic_mode = MLX5_ATOMIC_MODE_IB_COMP; |
| 1808 | |
| 1809 | return atomic_mode; |
| 1810 | } |
| 1811 | |
Yonatan Cohen | 2e43bb3 | 2018-10-09 12:05:14 +0300 | [diff] [blame] | 1812 | static inline bool check_flags_mask(uint64_t input, uint64_t supported) |
| 1813 | { |
| 1814 | return (input & ~supported) == 0; |
| 1815 | } |
| 1816 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1817 | static int create_qp_common(struct mlx5_ib_dev *dev, struct ib_pd *pd, |
| 1818 | struct ib_qp_init_attr *init_attr, |
| 1819 | struct ib_udata *udata, struct mlx5_ib_qp *qp) |
| 1820 | { |
| 1821 | struct mlx5_ib_resources *devr = &dev->devr; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1822 | int inlen = MLX5_ST_SZ_BYTES(create_qp_in); |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1823 | struct mlx5_core_dev *mdev = dev->mdev; |
Jason Gunthorpe | 0625b4b | 2018-08-14 15:33:52 -0600 | [diff] [blame] | 1824 | struct mlx5_ib_create_qp_resp resp = {}; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 1825 | struct mlx5_ib_cq *send_cq; |
| 1826 | struct mlx5_ib_cq *recv_cq; |
| 1827 | unsigned long flags; |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1828 | u32 uidx = MLX5_IB_DEFAULT_UIDX; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1829 | struct mlx5_ib_create_qp ucmd; |
| 1830 | struct mlx5_ib_qp_base *base; |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1831 | int mlx5_st; |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1832 | void *qpc; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 1833 | u32 *in; |
| 1834 | int err; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1835 | |
| 1836 | mutex_init(&qp->mutex); |
| 1837 | spin_lock_init(&qp->sq.lock); |
| 1838 | spin_lock_init(&qp->rq.lock); |
| 1839 | |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 1840 | mlx5_st = to_mlx5_st(init_attr->qp_type); |
| 1841 | if (mlx5_st < 0) |
| 1842 | return -EINVAL; |
| 1843 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 1844 | if (init_attr->rwq_ind_tbl) { |
| 1845 | if (!udata) |
| 1846 | return -ENOSYS; |
| 1847 | |
| 1848 | err = create_rss_raw_qp_tir(dev, qp, pd, init_attr, udata); |
| 1849 | return err; |
| 1850 | } |
| 1851 | |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 1852 | if (init_attr->create_flags & IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK) { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 1853 | if (!MLX5_CAP_GEN(mdev, block_lb_mc)) { |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 1854 | mlx5_ib_dbg(dev, "block multicast loopback isn't supported\n"); |
| 1855 | return -EINVAL; |
| 1856 | } else { |
| 1857 | qp->flags |= MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK; |
| 1858 | } |
| 1859 | } |
| 1860 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 1861 | if (init_attr->create_flags & |
| 1862 | (IB_QP_CREATE_CROSS_CHANNEL | |
| 1863 | IB_QP_CREATE_MANAGED_SEND | |
| 1864 | IB_QP_CREATE_MANAGED_RECV)) { |
| 1865 | if (!MLX5_CAP_GEN(mdev, cd)) { |
| 1866 | mlx5_ib_dbg(dev, "cross-channel isn't supported\n"); |
| 1867 | return -EINVAL; |
| 1868 | } |
| 1869 | if (init_attr->create_flags & IB_QP_CREATE_CROSS_CHANNEL) |
| 1870 | qp->flags |= MLX5_IB_QP_CROSS_CHANNEL; |
| 1871 | if (init_attr->create_flags & IB_QP_CREATE_MANAGED_SEND) |
| 1872 | qp->flags |= MLX5_IB_QP_MANAGED_SEND; |
| 1873 | if (init_attr->create_flags & IB_QP_CREATE_MANAGED_RECV) |
| 1874 | qp->flags |= MLX5_IB_QP_MANAGED_RECV; |
| 1875 | } |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 1876 | |
| 1877 | if (init_attr->qp_type == IB_QPT_UD && |
| 1878 | (init_attr->create_flags & IB_QP_CREATE_IPOIB_UD_LSO)) |
| 1879 | if (!MLX5_CAP_GEN(mdev, ipoib_basic_offloads)) { |
| 1880 | mlx5_ib_dbg(dev, "ipoib UD lso qp isn't supported\n"); |
| 1881 | return -EOPNOTSUPP; |
| 1882 | } |
| 1883 | |
Majd Dibbiny | 358e42e | 2016-04-17 17:19:37 +0300 | [diff] [blame] | 1884 | if (init_attr->create_flags & IB_QP_CREATE_SCATTER_FCS) { |
| 1885 | if (init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 1886 | mlx5_ib_dbg(dev, "Scatter FCS is supported only for Raw Packet QPs"); |
| 1887 | return -EOPNOTSUPP; |
| 1888 | } |
| 1889 | if (!MLX5_CAP_GEN(dev->mdev, eth_net_offloads) || |
| 1890 | !MLX5_CAP_ETH(dev->mdev, scatter_fcs)) { |
| 1891 | mlx5_ib_dbg(dev, "Scatter FCS isn't supported\n"); |
| 1892 | return -EOPNOTSUPP; |
| 1893 | } |
| 1894 | qp->flags |= MLX5_IB_QP_CAP_SCATTER_FCS; |
| 1895 | } |
| 1896 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1897 | if (init_attr->sq_sig_type == IB_SIGNAL_ALL_WR) |
| 1898 | qp->sq_signal_bits = MLX5_WQE_CTRL_CQ_UPDATE; |
| 1899 | |
Noa Osherovich | e4cc4fa | 2017-01-18 15:40:03 +0200 | [diff] [blame] | 1900 | if (init_attr->create_flags & IB_QP_CREATE_CVLAN_STRIPPING) { |
| 1901 | if (!(MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 1902 | MLX5_CAP_ETH(dev->mdev, vlan_cap)) || |
| 1903 | (init_attr->qp_type != IB_QPT_RAW_PACKET)) |
| 1904 | return -EOPNOTSUPP; |
| 1905 | qp->flags |= MLX5_IB_QP_CVLAN_STRIPPING; |
| 1906 | } |
| 1907 | |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 1908 | if (udata) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1909 | if (ib_copy_from_udata(&ucmd, udata, sizeof(ucmd))) { |
| 1910 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 1911 | return -EFAULT; |
| 1912 | } |
| 1913 | |
Yonatan Cohen | 2e43bb3 | 2018-10-09 12:05:14 +0300 | [diff] [blame] | 1914 | if (!check_flags_mask(ucmd.flags, |
Mark Bloch | 8af526e | 2019-01-15 16:45:32 +0200 | [diff] [blame^] | 1915 | MLX5_QP_FLAG_ALLOW_SCATTER_CQE | |
| 1916 | MLX5_QP_FLAG_BFREG_INDEX | |
| 1917 | MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE | |
| 1918 | MLX5_QP_FLAG_SCATTER_CQE | |
Yonatan Cohen | 2e43bb3 | 2018-10-09 12:05:14 +0300 | [diff] [blame] | 1919 | MLX5_QP_FLAG_SIGNATURE | |
Mark Bloch | 8af526e | 2019-01-15 16:45:32 +0200 | [diff] [blame^] | 1920 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC | |
| 1921 | MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC | |
| 1922 | MLX5_QP_FLAG_TUNNEL_OFFLOADS | |
| 1923 | MLX5_QP_FLAG_TYPE_DCI | |
| 1924 | MLX5_QP_FLAG_TYPE_DCT)) |
Yonatan Cohen | 2e43bb3 | 2018-10-09 12:05:14 +0300 | [diff] [blame] | 1925 | return -EINVAL; |
| 1926 | |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 1927 | err = get_qp_user_index(to_mucontext(pd->uobject->context), |
| 1928 | &ucmd, udata->inlen, &uidx); |
| 1929 | if (err) |
| 1930 | return err; |
| 1931 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1932 | qp->wq_sig = !!(ucmd.flags & MLX5_QP_FLAG_SIGNATURE); |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 1933 | if (MLX5_CAP_GEN(dev->mdev, sctr_data_cqe)) |
| 1934 | qp->scat_cqe = !!(ucmd.flags & MLX5_QP_FLAG_SCATTER_CQE); |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1935 | if (ucmd.flags & MLX5_QP_FLAG_TUNNEL_OFFLOADS) { |
| 1936 | if (init_attr->qp_type != IB_QPT_RAW_PACKET || |
| 1937 | !tunnel_offload_supported(mdev)) { |
| 1938 | mlx5_ib_dbg(dev, "Tunnel offload isn't supported\n"); |
| 1939 | return -EOPNOTSUPP; |
| 1940 | } |
Mark Bloch | 175edba | 2018-09-17 13:30:48 +0300 | [diff] [blame] | 1941 | qp->flags_en |= MLX5_QP_FLAG_TUNNEL_OFFLOADS; |
| 1942 | } |
| 1943 | |
| 1944 | if (ucmd.flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC) { |
| 1945 | if (init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 1946 | mlx5_ib_dbg(dev, "Self-LB UC isn't supported\n"); |
| 1947 | return -EOPNOTSUPP; |
| 1948 | } |
| 1949 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_UC; |
| 1950 | } |
| 1951 | |
| 1952 | if (ucmd.flags & MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC) { |
| 1953 | if (init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 1954 | mlx5_ib_dbg(dev, "Self-LB UM isn't supported\n"); |
| 1955 | return -EOPNOTSUPP; |
| 1956 | } |
| 1957 | qp->flags_en |= MLX5_QP_FLAG_TIR_ALLOW_SELF_LB_MC; |
Maor Gottlieb | f95ef6c | 2017-10-19 08:25:55 +0300 | [diff] [blame] | 1958 | } |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1959 | |
Danit Goldberg | 569c665 | 2018-11-30 13:22:05 +0200 | [diff] [blame] | 1960 | if (ucmd.flags & MLX5_QP_FLAG_PACKET_BASED_CREDIT_MODE) { |
| 1961 | if (init_attr->qp_type != IB_QPT_RC || |
| 1962 | !MLX5_CAP_GEN(dev->mdev, qp_packet_based)) { |
| 1963 | mlx5_ib_dbg(dev, "packet based credit mode isn't supported\n"); |
| 1964 | return -EOPNOTSUPP; |
| 1965 | } |
| 1966 | qp->flags |= MLX5_IB_QP_PACKET_BASED_CREDIT; |
| 1967 | } |
| 1968 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1969 | if (init_attr->create_flags & IB_QP_CREATE_SOURCE_QPN) { |
| 1970 | if (init_attr->qp_type != IB_QPT_UD || |
| 1971 | (MLX5_CAP_GEN(dev->mdev, port_type) != |
| 1972 | MLX5_CAP_PORT_TYPE_IB) || |
| 1973 | !mlx5_get_flow_namespace(dev->mdev, MLX5_FLOW_NAMESPACE_BYPASS)) { |
| 1974 | mlx5_ib_dbg(dev, "Source QP option isn't supported\n"); |
| 1975 | return -EOPNOTSUPP; |
| 1976 | } |
| 1977 | |
| 1978 | qp->flags |= MLX5_IB_QP_UNDERLAY; |
| 1979 | qp->underlay_qpn = init_attr->source_qpn; |
| 1980 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1981 | } else { |
| 1982 | qp->wq_sig = !!wq_signature; |
| 1983 | } |
| 1984 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 1985 | base = (init_attr->qp_type == IB_QPT_RAW_PACKET || |
| 1986 | qp->flags & MLX5_IB_QP_UNDERLAY) ? |
| 1987 | &qp->raw_packet_qp.rq.base : |
| 1988 | &qp->trans_qp.base; |
| 1989 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1990 | qp->has_rq = qp_has_rq(init_attr); |
| 1991 | err = set_rq_size(dev, &init_attr->cap, qp->has_rq, |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 1992 | qp, udata ? &ucmd : NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 1993 | if (err) { |
| 1994 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 1995 | return err; |
| 1996 | } |
| 1997 | |
| 1998 | if (pd) { |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 1999 | if (udata) { |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2000 | __u32 max_wqes = |
| 2001 | 1 << MLX5_CAP_GEN(mdev, log_max_qp_sz); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2002 | mlx5_ib_dbg(dev, "requested sq_wqe_count (%d)\n", ucmd.sq_wqe_count); |
| 2003 | if (ucmd.rq_wqe_shift != qp->rq.wqe_shift || |
| 2004 | ucmd.rq_wqe_count != qp->rq.wqe_cnt) { |
| 2005 | mlx5_ib_dbg(dev, "invalid rq params\n"); |
| 2006 | return -EINVAL; |
| 2007 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2008 | if (ucmd.sq_wqe_count > max_wqes) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2009 | mlx5_ib_dbg(dev, "requested sq_wqe_count (%d) > max allowed (%d)\n", |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2010 | ucmd.sq_wqe_count, max_wqes); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2011 | return -EINVAL; |
| 2012 | } |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 2013 | if (init_attr->create_flags & |
| 2014 | mlx5_ib_create_qp_sqpn_qp1()) { |
| 2015 | mlx5_ib_dbg(dev, "user-space is not allowed to create UD QPs spoofing as QP1\n"); |
| 2016 | return -EINVAL; |
| 2017 | } |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2018 | err = create_user_qp(dev, pd, qp, udata, init_attr, &in, |
| 2019 | &resp, &inlen, base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2020 | if (err) |
| 2021 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 2022 | } else { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2023 | err = create_kernel_qp(dev, init_attr, qp, &in, &inlen, |
| 2024 | base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2025 | if (err) |
| 2026 | mlx5_ib_dbg(dev, "err %d\n", err); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | if (err) |
| 2030 | return err; |
| 2031 | } else { |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2032 | in = kvzalloc(inlen, GFP_KERNEL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2033 | if (!in) |
| 2034 | return -ENOMEM; |
| 2035 | |
| 2036 | qp->create_type = MLX5_QP_EMPTY; |
| 2037 | } |
| 2038 | |
| 2039 | if (is_sqp(init_attr->qp_type)) |
| 2040 | qp->port = init_attr->port_num; |
| 2041 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2042 | qpc = MLX5_ADDR_OF(create_qp_in, in, qpc); |
| 2043 | |
Noa Osherovich | e7b169f | 2018-02-25 13:39:51 +0200 | [diff] [blame] | 2044 | MLX5_SET(qpc, qpc, st, mlx5_st); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2045 | MLX5_SET(qpc, qpc, pm_state, MLX5_QP_PM_MIGRATED); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2046 | |
| 2047 | if (init_attr->qp_type != MLX5_IB_QPT_REG_UMR) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2048 | MLX5_SET(qpc, qpc, pd, to_mpd(pd ? pd : devr->p0)->pdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2049 | else |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2050 | MLX5_SET(qpc, qpc, latency_sensitive, 1); |
| 2051 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2052 | |
| 2053 | if (qp->wq_sig) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2054 | MLX5_SET(qpc, qpc, wq_signature, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2055 | |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 2056 | if (qp->flags & MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2057 | MLX5_SET(qpc, qpc, block_lb_mc, 1); |
Eli Cohen | f360d88 | 2014-04-02 00:10:16 +0300 | [diff] [blame] | 2058 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 2059 | if (qp->flags & MLX5_IB_QP_CROSS_CHANNEL) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2060 | MLX5_SET(qpc, qpc, cd_master, 1); |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 2061 | if (qp->flags & MLX5_IB_QP_MANAGED_SEND) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2062 | MLX5_SET(qpc, qpc, cd_slave_send, 1); |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 2063 | if (qp->flags & MLX5_IB_QP_MANAGED_RECV) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2064 | MLX5_SET(qpc, qpc, cd_slave_receive, 1); |
Danit Goldberg | 569c665 | 2018-11-30 13:22:05 +0200 | [diff] [blame] | 2065 | if (qp->flags & MLX5_IB_QP_PACKET_BASED_CREDIT) |
| 2066 | MLX5_SET(qpc, qpc, req_e2e_credit_mode, 1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2067 | if (qp->scat_cqe && is_connected(init_attr->qp_type)) { |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 2068 | configure_responder_scat_cqe(init_attr, qpc); |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 2069 | configure_requester_scat_cqe(dev, init_attr, |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 2070 | udata ? &ucmd : NULL, |
Yonatan Cohen | 6f4bc0e | 2018-10-09 12:05:15 +0300 | [diff] [blame] | 2071 | qpc); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | if (qp->rq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2075 | MLX5_SET(qpc, qpc, log_rq_stride, qp->rq.wqe_shift - 4); |
| 2076 | MLX5_SET(qpc, qpc, log_rq_size, ilog2(qp->rq.wqe_cnt)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2077 | } |
| 2078 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2079 | MLX5_SET(qpc, qpc, rq_type, get_rx_type(qp, init_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2080 | |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2081 | if (qp->sq.wqe_cnt) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2082 | MLX5_SET(qpc, qpc, log_sq_size, ilog2(qp->sq.wqe_cnt)); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2083 | } else { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2084 | MLX5_SET(qpc, qpc, no_sq, 1); |
Artemy Kovalyov | 3fd3307 | 2017-08-17 15:52:11 +0300 | [diff] [blame] | 2085 | if (init_attr->srq && |
| 2086 | init_attr->srq->srq_type == IB_SRQT_TM) |
| 2087 | MLX5_SET(qpc, qpc, offload_type, |
| 2088 | MLX5_QPC_OFFLOAD_TYPE_RNDV); |
| 2089 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2090 | |
| 2091 | /* Set default resources */ |
| 2092 | switch (init_attr->qp_type) { |
| 2093 | case IB_QPT_XRC_TGT: |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2094 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
| 2095 | MLX5_SET(qpc, qpc, cqn_snd, to_mcq(devr->c0)->mcq.cqn); |
| 2096 | MLX5_SET(qpc, qpc, srqn_rmpn_xrqn, to_msrq(devr->s0)->msrq.srqn); |
| 2097 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(init_attr->xrcd)->xrcdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2098 | break; |
| 2099 | case IB_QPT_XRC_INI: |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2100 | MLX5_SET(qpc, qpc, cqn_rcv, to_mcq(devr->c0)->mcq.cqn); |
| 2101 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x1)->xrcdn); |
| 2102 | 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] | 2103 | break; |
| 2104 | default: |
| 2105 | if (init_attr->srq) { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2106 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x0)->xrcdn); |
| 2107 | 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] | 2108 | } else { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2109 | MLX5_SET(qpc, qpc, xrcd, to_mxrcd(devr->x1)->xrcdn); |
| 2110 | 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] | 2111 | } |
| 2112 | } |
| 2113 | |
| 2114 | if (init_attr->send_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2115 | 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] | 2116 | |
| 2117 | if (init_attr->recv_cq) |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2118 | 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] | 2119 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2120 | MLX5_SET64(qpc, qpc, dbr_addr, qp->db.dma); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2121 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2122 | /* 0xffffff means we ask to work with cqe version 0 */ |
| 2123 | if (MLX5_CAP_GEN(mdev, cqe_version) == MLX5_CQE_VERSION_V1) |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2124 | MLX5_SET(qpc, qpc, user_index, uidx); |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 2125 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 2126 | /* we use IB_QP_CREATE_IPOIB_UD_LSO to indicates ipoib qp */ |
| 2127 | if (init_attr->qp_type == IB_QPT_UD && |
| 2128 | (init_attr->create_flags & IB_QP_CREATE_IPOIB_UD_LSO)) { |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 2129 | MLX5_SET(qpc, qpc, ulp_stateless_offload_mode, 1); |
| 2130 | qp->flags |= MLX5_IB_QP_LSO; |
| 2131 | } |
Haggai Abramovsky | cfb5e08 | 2016-01-14 19:12:57 +0200 | [diff] [blame] | 2132 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 2133 | if (init_attr->create_flags & IB_QP_CREATE_PCI_WRITE_END_PADDING) { |
| 2134 | if (!MLX5_CAP_GEN(dev->mdev, end_pad)) { |
| 2135 | mlx5_ib_dbg(dev, "scatter end padding is not supported\n"); |
| 2136 | err = -EOPNOTSUPP; |
| 2137 | goto err; |
| 2138 | } else if (init_attr->qp_type != IB_QPT_RAW_PACKET) { |
| 2139 | MLX5_SET(qpc, qpc, end_padding_mode, |
| 2140 | MLX5_WQ_END_PAD_MODE_ALIGN); |
| 2141 | } else { |
| 2142 | qp->flags |= MLX5_IB_QP_PCI_WRITE_END_PADDING; |
| 2143 | } |
| 2144 | } |
| 2145 | |
Boris Pismenny | 2c292db | 2018-03-08 15:51:40 +0200 | [diff] [blame] | 2146 | if (inlen < 0) { |
| 2147 | err = -EINVAL; |
| 2148 | goto err; |
| 2149 | } |
| 2150 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2151 | if (init_attr->qp_type == IB_QPT_RAW_PACKET || |
| 2152 | qp->flags & MLX5_IB_QP_UNDERLAY) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2153 | qp->raw_packet_qp.sq.ubuffer.buf_addr = ucmd.sq_buf_addr; |
| 2154 | raw_packet_qp_copy_info(qp, &qp->raw_packet_qp); |
Yishai Hadas | 7f72052 | 2018-09-20 21:45:18 +0300 | [diff] [blame] | 2155 | err = create_raw_packet_qp(dev, qp, in, inlen, pd, udata, |
| 2156 | &resp); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2157 | } else { |
| 2158 | err = mlx5_core_create_qp(dev->mdev, &base->mqp, in, inlen); |
| 2159 | } |
| 2160 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2161 | if (err) { |
| 2162 | mlx5_ib_dbg(dev, "create qp failed\n"); |
| 2163 | goto err_create; |
| 2164 | } |
| 2165 | |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 2166 | kvfree(in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2167 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2168 | base->container_mibqp = qp; |
| 2169 | base->mqp.event = mlx5_ib_qp_event; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2170 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2171 | get_cqs(init_attr->qp_type, init_attr->send_cq, init_attr->recv_cq, |
| 2172 | &send_cq, &recv_cq); |
| 2173 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2174 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2175 | /* Maintain device to QPs access, needed for further handling via reset |
| 2176 | * flow |
| 2177 | */ |
| 2178 | list_add_tail(&qp->qps_list, &dev->qp_list); |
| 2179 | /* Maintain CQ to QPs access, needed for further handling via reset flow |
| 2180 | */ |
| 2181 | if (send_cq) |
| 2182 | list_add_tail(&qp->cq_send_list, &send_cq->list_send_qp); |
| 2183 | if (recv_cq) |
| 2184 | list_add_tail(&qp->cq_recv_list, &recv_cq->list_recv_qp); |
| 2185 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2186 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 2187 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2188 | return 0; |
| 2189 | |
| 2190 | err_create: |
| 2191 | if (qp->create_type == MLX5_QP_USER) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2192 | destroy_qp_user(dev, pd, qp, base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2193 | else if (qp->create_type == MLX5_QP_KERNEL) |
| 2194 | destroy_qp_kernel(dev, qp); |
| 2195 | |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 2196 | err: |
Al Viro | 479163f | 2014-11-20 08:13:57 +0000 | [diff] [blame] | 2197 | kvfree(in); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2198 | return err; |
| 2199 | } |
| 2200 | |
| 2201 | static void mlx5_ib_lock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2202 | __acquires(&send_cq->lock) __acquires(&recv_cq->lock) |
| 2203 | { |
| 2204 | if (send_cq) { |
| 2205 | if (recv_cq) { |
| 2206 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2207 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2208 | spin_lock_nested(&recv_cq->lock, |
| 2209 | SINGLE_DEPTH_NESTING); |
| 2210 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2211 | spin_lock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2212 | __acquire(&recv_cq->lock); |
| 2213 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2214 | spin_lock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2215 | spin_lock_nested(&send_cq->lock, |
| 2216 | SINGLE_DEPTH_NESTING); |
| 2217 | } |
| 2218 | } else { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2219 | spin_lock(&send_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2220 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2221 | } |
| 2222 | } else if (recv_cq) { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2223 | spin_lock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2224 | __acquire(&send_cq->lock); |
| 2225 | } else { |
| 2226 | __acquire(&send_cq->lock); |
| 2227 | __acquire(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | |
| 2231 | static void mlx5_ib_unlock_cqs(struct mlx5_ib_cq *send_cq, struct mlx5_ib_cq *recv_cq) |
| 2232 | __releases(&send_cq->lock) __releases(&recv_cq->lock) |
| 2233 | { |
| 2234 | if (send_cq) { |
| 2235 | if (recv_cq) { |
| 2236 | if (send_cq->mcq.cqn < recv_cq->mcq.cqn) { |
| 2237 | spin_unlock(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2238 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2239 | } else if (send_cq->mcq.cqn == recv_cq->mcq.cqn) { |
| 2240 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2241 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2242 | } else { |
| 2243 | spin_unlock(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2244 | spin_unlock(&recv_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2245 | } |
| 2246 | } else { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2247 | __release(&recv_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2248 | spin_unlock(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2249 | } |
| 2250 | } else if (recv_cq) { |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2251 | __release(&send_cq->lock); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2252 | spin_unlock(&recv_cq->lock); |
Eli Cohen | 6a4f139 | 2014-12-02 12:26:18 +0200 | [diff] [blame] | 2253 | } else { |
| 2254 | __release(&recv_cq->lock); |
| 2255 | __release(&send_cq->lock); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | static struct mlx5_ib_pd *get_pd(struct mlx5_ib_qp *qp) |
| 2260 | { |
| 2261 | return to_mpd(qp->ibqp.pd); |
| 2262 | } |
| 2263 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2264 | static void get_cqs(enum ib_qp_type qp_type, |
| 2265 | struct ib_cq *ib_send_cq, struct ib_cq *ib_recv_cq, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2266 | struct mlx5_ib_cq **send_cq, struct mlx5_ib_cq **recv_cq) |
| 2267 | { |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2268 | switch (qp_type) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2269 | case IB_QPT_XRC_TGT: |
| 2270 | *send_cq = NULL; |
| 2271 | *recv_cq = NULL; |
| 2272 | break; |
| 2273 | case MLX5_IB_QPT_REG_UMR: |
| 2274 | case IB_QPT_XRC_INI: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2275 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2276 | *recv_cq = NULL; |
| 2277 | break; |
| 2278 | |
| 2279 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2280 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2281 | case IB_QPT_RC: |
| 2282 | case IB_QPT_UC: |
| 2283 | case IB_QPT_UD: |
| 2284 | case IB_QPT_RAW_IPV6: |
| 2285 | case IB_QPT_RAW_ETHERTYPE: |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2286 | case IB_QPT_RAW_PACKET: |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2287 | *send_cq = ib_send_cq ? to_mcq(ib_send_cq) : NULL; |
| 2288 | *recv_cq = ib_recv_cq ? to_mcq(ib_recv_cq) : NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2289 | break; |
| 2290 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2291 | case IB_QPT_MAX: |
| 2292 | default: |
| 2293 | *send_cq = NULL; |
| 2294 | *recv_cq = NULL; |
| 2295 | break; |
| 2296 | } |
| 2297 | } |
| 2298 | |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2299 | 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] | 2300 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 2301 | u8 lag_tx_affinity); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2302 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2303 | static void destroy_qp_common(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp) |
| 2304 | { |
| 2305 | struct mlx5_ib_cq *send_cq, *recv_cq; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2306 | struct mlx5_ib_qp_base *base; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2307 | unsigned long flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2308 | int err; |
| 2309 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 2310 | if (qp->ibqp.rwq_ind_tbl) { |
| 2311 | destroy_rss_raw_qp_tir(dev, qp); |
| 2312 | return; |
| 2313 | } |
| 2314 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2315 | base = (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
| 2316 | qp->flags & MLX5_IB_QP_UNDERLAY) ? |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2317 | &qp->raw_packet_qp.rq.base : |
| 2318 | &qp->trans_qp.base; |
| 2319 | |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2320 | if (qp->state != IB_QPS_RESET) { |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2321 | if (qp->ibqp.qp_type != IB_QPT_RAW_PACKET && |
| 2322 | !(qp->flags & MLX5_IB_QP_UNDERLAY)) { |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2323 | err = mlx5_core_qp_modify(dev->mdev, |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 2324 | MLX5_CMD_OP_2RST_QP, 0, |
| 2325 | NULL, &base->mqp); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2326 | } else { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 2327 | struct mlx5_modify_raw_qp_param raw_qp_param = { |
| 2328 | .operation = MLX5_CMD_OP_2RST_QP |
| 2329 | }; |
| 2330 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2331 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, 0); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 2332 | } |
| 2333 | if (err) |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 2334 | 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] | 2335 | base->mqp.qpn); |
Haggai Eran | 6aec21f | 2014-12-11 17:04:23 +0200 | [diff] [blame] | 2336 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2337 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2338 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 2339 | &send_cq, &recv_cq); |
| 2340 | |
| 2341 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 2342 | mlx5_ib_lock_cqs(send_cq, recv_cq); |
| 2343 | /* del from lists under both locks above to protect reset flow paths */ |
| 2344 | list_del(&qp->qps_list); |
| 2345 | if (send_cq) |
| 2346 | list_del(&qp->cq_send_list); |
| 2347 | |
| 2348 | if (recv_cq) |
| 2349 | list_del(&qp->cq_recv_list); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2350 | |
| 2351 | if (qp->create_type == MLX5_QP_KERNEL) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2352 | __mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2353 | qp->ibqp.srq ? to_msrq(qp->ibqp.srq) : NULL); |
| 2354 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2355 | __mlx5_ib_cq_clean(send_cq, base->mqp.qpn, |
| 2356 | NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2357 | } |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 2358 | mlx5_ib_unlock_cqs(send_cq, recv_cq); |
| 2359 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2360 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 2361 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
| 2362 | qp->flags & MLX5_IB_QP_UNDERLAY) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2363 | destroy_raw_packet_qp(dev, qp); |
| 2364 | } else { |
| 2365 | err = mlx5_core_destroy_qp(dev->mdev, &base->mqp); |
| 2366 | if (err) |
| 2367 | mlx5_ib_warn(dev, "failed to destroy QP 0x%x\n", |
| 2368 | base->mqp.qpn); |
| 2369 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2370 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2371 | if (qp->create_type == MLX5_QP_KERNEL) |
| 2372 | destroy_qp_kernel(dev, qp); |
| 2373 | else if (qp->create_type == MLX5_QP_USER) |
Eli Cohen | b037c29 | 2017-01-03 23:55:26 +0200 | [diff] [blame] | 2374 | destroy_qp_user(dev, &get_pd(qp)->ibpd, qp, base); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | static const char *ib_qp_type_str(enum ib_qp_type type) |
| 2378 | { |
| 2379 | switch (type) { |
| 2380 | case IB_QPT_SMI: |
| 2381 | return "IB_QPT_SMI"; |
| 2382 | case IB_QPT_GSI: |
| 2383 | return "IB_QPT_GSI"; |
| 2384 | case IB_QPT_RC: |
| 2385 | return "IB_QPT_RC"; |
| 2386 | case IB_QPT_UC: |
| 2387 | return "IB_QPT_UC"; |
| 2388 | case IB_QPT_UD: |
| 2389 | return "IB_QPT_UD"; |
| 2390 | case IB_QPT_RAW_IPV6: |
| 2391 | return "IB_QPT_RAW_IPV6"; |
| 2392 | case IB_QPT_RAW_ETHERTYPE: |
| 2393 | return "IB_QPT_RAW_ETHERTYPE"; |
| 2394 | case IB_QPT_XRC_INI: |
| 2395 | return "IB_QPT_XRC_INI"; |
| 2396 | case IB_QPT_XRC_TGT: |
| 2397 | return "IB_QPT_XRC_TGT"; |
| 2398 | case IB_QPT_RAW_PACKET: |
| 2399 | return "IB_QPT_RAW_PACKET"; |
| 2400 | case MLX5_IB_QPT_REG_UMR: |
| 2401 | return "MLX5_IB_QPT_REG_UMR"; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2402 | case IB_QPT_DRIVER: |
| 2403 | return "IB_QPT_DRIVER"; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2404 | case IB_QPT_MAX: |
| 2405 | default: |
| 2406 | return "Invalid QP type"; |
| 2407 | } |
| 2408 | } |
| 2409 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2410 | static struct ib_qp *mlx5_ib_create_dct(struct ib_pd *pd, |
| 2411 | struct ib_qp_init_attr *attr, |
| 2412 | struct mlx5_ib_create_qp *ucmd) |
| 2413 | { |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2414 | struct mlx5_ib_qp *qp; |
| 2415 | int err = 0; |
| 2416 | u32 uidx = MLX5_IB_DEFAULT_UIDX; |
| 2417 | void *dctc; |
| 2418 | |
| 2419 | if (!attr->srq || !attr->recv_cq) |
| 2420 | return ERR_PTR(-EINVAL); |
| 2421 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2422 | err = get_qp_user_index(to_mucontext(pd->uobject->context), |
| 2423 | ucmd, sizeof(*ucmd), &uidx); |
| 2424 | if (err) |
| 2425 | return ERR_PTR(err); |
| 2426 | |
| 2427 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); |
| 2428 | if (!qp) |
| 2429 | return ERR_PTR(-ENOMEM); |
| 2430 | |
| 2431 | qp->dct.in = kzalloc(MLX5_ST_SZ_BYTES(create_dct_in), GFP_KERNEL); |
| 2432 | if (!qp->dct.in) { |
| 2433 | err = -ENOMEM; |
| 2434 | goto err_free; |
| 2435 | } |
| 2436 | |
Yishai Hadas | a01a586 | 2018-09-20 21:39:24 +0300 | [diff] [blame] | 2437 | 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] | 2438 | dctc = MLX5_ADDR_OF(create_dct_in, qp->dct.in, dct_context_entry); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2439 | qp->qp_sub_type = MLX5_IB_QPT_DCT; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2440 | MLX5_SET(dctc, dctc, pd, to_mpd(pd)->pdn); |
| 2441 | MLX5_SET(dctc, dctc, srqn_xrqn, to_msrq(attr->srq)->msrq.srqn); |
| 2442 | MLX5_SET(dctc, dctc, cqn, to_mcq(attr->recv_cq)->mcq.cqn); |
| 2443 | MLX5_SET64(dctc, dctc, dc_access_key, ucmd->access_key); |
| 2444 | MLX5_SET(dctc, dctc, user_index, uidx); |
| 2445 | |
Yonatan Cohen | 5d6ff1b | 2018-10-09 12:05:13 +0300 | [diff] [blame] | 2446 | if (ucmd->flags & MLX5_QP_FLAG_SCATTER_CQE) |
| 2447 | configure_responder_scat_cqe(attr, dctc); |
| 2448 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2449 | qp->state = IB_QPS_RESET; |
| 2450 | |
| 2451 | return &qp->ibqp; |
| 2452 | err_free: |
| 2453 | kfree(qp); |
| 2454 | return ERR_PTR(err); |
| 2455 | } |
| 2456 | |
| 2457 | static int set_mlx_qp_type(struct mlx5_ib_dev *dev, |
| 2458 | struct ib_qp_init_attr *init_attr, |
| 2459 | struct mlx5_ib_create_qp *ucmd, |
| 2460 | struct ib_udata *udata) |
| 2461 | { |
| 2462 | enum { MLX_QP_FLAGS = MLX5_QP_FLAG_TYPE_DCT | MLX5_QP_FLAG_TYPE_DCI }; |
| 2463 | int err; |
| 2464 | |
| 2465 | if (!udata) |
| 2466 | return -EINVAL; |
| 2467 | |
| 2468 | if (udata->inlen < sizeof(*ucmd)) { |
| 2469 | mlx5_ib_dbg(dev, "create_qp user command is smaller than expected\n"); |
| 2470 | return -EINVAL; |
| 2471 | } |
| 2472 | err = ib_copy_from_udata(ucmd, udata, sizeof(*ucmd)); |
| 2473 | if (err) |
| 2474 | return err; |
| 2475 | |
| 2476 | if ((ucmd->flags & MLX_QP_FLAGS) == MLX5_QP_FLAG_TYPE_DCI) { |
| 2477 | init_attr->qp_type = MLX5_IB_QPT_DCI; |
| 2478 | } else { |
| 2479 | if ((ucmd->flags & MLX_QP_FLAGS) == MLX5_QP_FLAG_TYPE_DCT) { |
| 2480 | init_attr->qp_type = MLX5_IB_QPT_DCT; |
| 2481 | } else { |
| 2482 | mlx5_ib_dbg(dev, "Invalid QP flags\n"); |
| 2483 | return -EINVAL; |
| 2484 | } |
| 2485 | } |
| 2486 | |
| 2487 | if (!MLX5_CAP_GEN(dev->mdev, dct)) { |
| 2488 | mlx5_ib_dbg(dev, "DC transport is not supported\n"); |
| 2489 | return -EOPNOTSUPP; |
| 2490 | } |
| 2491 | |
| 2492 | return 0; |
| 2493 | } |
| 2494 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2495 | struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd, |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2496 | struct ib_qp_init_attr *verbs_init_attr, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2497 | struct ib_udata *udata) |
| 2498 | { |
| 2499 | struct mlx5_ib_dev *dev; |
| 2500 | struct mlx5_ib_qp *qp; |
| 2501 | u16 xrcdn = 0; |
| 2502 | int err; |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2503 | struct ib_qp_init_attr mlx_init_attr; |
| 2504 | struct ib_qp_init_attr *init_attr = verbs_init_attr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2505 | |
| 2506 | if (pd) { |
| 2507 | dev = to_mdev(pd->device); |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2508 | |
| 2509 | if (init_attr->qp_type == IB_QPT_RAW_PACKET) { |
Shamir Rabinovitch | e00b64f | 2018-12-17 17:15:18 +0200 | [diff] [blame] | 2510 | if (!udata) { |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2511 | mlx5_ib_dbg(dev, "Raw Packet QP is not supported for kernel consumers\n"); |
| 2512 | return ERR_PTR(-EINVAL); |
| 2513 | } else if (!to_mucontext(pd->uobject->context)->cqe_version) { |
| 2514 | mlx5_ib_dbg(dev, "Raw Packet QP is only supported for CQE version > 0\n"); |
| 2515 | return ERR_PTR(-EINVAL); |
| 2516 | } |
| 2517 | } |
Majd Dibbiny | 09f16cf | 2016-01-28 17:51:48 +0200 | [diff] [blame] | 2518 | } else { |
| 2519 | /* being cautious here */ |
| 2520 | if (init_attr->qp_type != IB_QPT_XRC_TGT && |
| 2521 | init_attr->qp_type != MLX5_IB_QPT_REG_UMR) { |
| 2522 | pr_warn("%s: no PD for transport %s\n", __func__, |
| 2523 | ib_qp_type_str(init_attr->qp_type)); |
| 2524 | return ERR_PTR(-EINVAL); |
| 2525 | } |
| 2526 | dev = to_mdev(to_mxrcd(init_attr->xrcd)->ibxrcd.device); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2527 | } |
| 2528 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2529 | if (init_attr->qp_type == IB_QPT_DRIVER) { |
| 2530 | struct mlx5_ib_create_qp ucmd; |
| 2531 | |
| 2532 | init_attr = &mlx_init_attr; |
| 2533 | memcpy(init_attr, verbs_init_attr, sizeof(*verbs_init_attr)); |
| 2534 | err = set_mlx_qp_type(dev, init_attr, &ucmd, udata); |
| 2535 | if (err) |
| 2536 | return ERR_PTR(err); |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 2537 | |
| 2538 | if (init_attr->qp_type == MLX5_IB_QPT_DCI) { |
| 2539 | if (init_attr->cap.max_recv_wr || |
| 2540 | init_attr->cap.max_recv_sge) { |
| 2541 | mlx5_ib_dbg(dev, "DCI QP requires zero size receive queue\n"); |
| 2542 | return ERR_PTR(-EINVAL); |
| 2543 | } |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2544 | } else { |
| 2545 | return mlx5_ib_create_dct(pd, init_attr, &ucmd); |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 2546 | } |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2547 | } |
| 2548 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2549 | switch (init_attr->qp_type) { |
| 2550 | case IB_QPT_XRC_TGT: |
| 2551 | case IB_QPT_XRC_INI: |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2552 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2553 | mlx5_ib_dbg(dev, "XRC not supported\n"); |
| 2554 | return ERR_PTR(-ENOSYS); |
| 2555 | } |
| 2556 | init_attr->recv_cq = NULL; |
| 2557 | if (init_attr->qp_type == IB_QPT_XRC_TGT) { |
| 2558 | xrcdn = to_mxrcd(init_attr->xrcd)->xrcdn; |
| 2559 | init_attr->send_cq = NULL; |
| 2560 | } |
| 2561 | |
| 2562 | /* fall through */ |
majd@mellanox.com | 0fb2ed6 | 2016-01-14 19:13:04 +0200 | [diff] [blame] | 2563 | case IB_QPT_RAW_PACKET: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2564 | case IB_QPT_RC: |
| 2565 | case IB_QPT_UC: |
| 2566 | case IB_QPT_UD: |
| 2567 | case IB_QPT_SMI: |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2568 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2569 | case MLX5_IB_QPT_REG_UMR: |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 2570 | case MLX5_IB_QPT_DCI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2571 | qp = kzalloc(sizeof(*qp), GFP_KERNEL); |
| 2572 | if (!qp) |
| 2573 | return ERR_PTR(-ENOMEM); |
| 2574 | |
| 2575 | err = create_qp_common(dev, pd, init_attr, udata, qp); |
| 2576 | if (err) { |
| 2577 | mlx5_ib_dbg(dev, "create_qp_common failed\n"); |
| 2578 | kfree(qp); |
| 2579 | return ERR_PTR(err); |
| 2580 | } |
| 2581 | |
| 2582 | if (is_qp0(init_attr->qp_type)) |
| 2583 | qp->ibqp.qp_num = 0; |
| 2584 | else if (is_qp1(init_attr->qp_type)) |
| 2585 | qp->ibqp.qp_num = 1; |
| 2586 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2587 | qp->ibqp.qp_num = qp->trans_qp.base.mqp.qpn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2588 | |
| 2589 | mlx5_ib_dbg(dev, "ib qpnum 0x%x, mlx qpn 0x%x, rcqn 0x%x, scqn 0x%x\n", |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2590 | qp->ibqp.qp_num, qp->trans_qp.base.mqp.qpn, |
Eli Cohen | a1ab840 | 2016-10-27 16:36:46 +0300 | [diff] [blame] | 2591 | init_attr->recv_cq ? to_mcq(init_attr->recv_cq)->mcq.cqn : -1, |
| 2592 | init_attr->send_cq ? to_mcq(init_attr->send_cq)->mcq.cqn : -1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2593 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2594 | qp->trans_qp.xrcdn = xrcdn; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2595 | |
| 2596 | break; |
| 2597 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2598 | case IB_QPT_GSI: |
| 2599 | return mlx5_ib_gsi_create_qp(pd, init_attr); |
| 2600 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2601 | case IB_QPT_RAW_IPV6: |
| 2602 | case IB_QPT_RAW_ETHERTYPE: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2603 | case IB_QPT_MAX: |
| 2604 | default: |
| 2605 | mlx5_ib_dbg(dev, "unsupported qp type %d\n", |
| 2606 | init_attr->qp_type); |
| 2607 | /* Don't support raw QPs */ |
| 2608 | return ERR_PTR(-EINVAL); |
| 2609 | } |
| 2610 | |
Moni Shoua | b4aaa1f | 2018-01-02 16:19:31 +0200 | [diff] [blame] | 2611 | if (verbs_init_attr->qp_type == IB_QPT_DRIVER) |
| 2612 | qp->qp_sub_type = init_attr->qp_type; |
| 2613 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2614 | return &qp->ibqp; |
| 2615 | } |
| 2616 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2617 | static int mlx5_ib_destroy_dct(struct mlx5_ib_qp *mqp) |
| 2618 | { |
| 2619 | struct mlx5_ib_dev *dev = to_mdev(mqp->ibqp.device); |
| 2620 | |
| 2621 | if (mqp->state == IB_QPS_RTR) { |
| 2622 | int err; |
| 2623 | |
| 2624 | err = mlx5_core_destroy_dct(dev->mdev, &mqp->dct.mdct); |
| 2625 | if (err) { |
| 2626 | mlx5_ib_warn(dev, "failed to destroy DCT %d\n", err); |
| 2627 | return err; |
| 2628 | } |
| 2629 | } |
| 2630 | |
| 2631 | kfree(mqp->dct.in); |
| 2632 | kfree(mqp); |
| 2633 | return 0; |
| 2634 | } |
| 2635 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2636 | int mlx5_ib_destroy_qp(struct ib_qp *qp) |
| 2637 | { |
| 2638 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 2639 | struct mlx5_ib_qp *mqp = to_mqp(qp); |
| 2640 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 2641 | if (unlikely(qp->qp_type == IB_QPT_GSI)) |
| 2642 | return mlx5_ib_gsi_destroy_qp(qp); |
| 2643 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 2644 | if (mqp->qp_sub_type == MLX5_IB_QPT_DCT) |
| 2645 | return mlx5_ib_destroy_dct(mqp); |
| 2646 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2647 | destroy_qp_common(dev, mqp); |
| 2648 | |
| 2649 | kfree(mqp); |
| 2650 | |
| 2651 | return 0; |
| 2652 | } |
| 2653 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2654 | static int to_mlx5_access_flags(struct mlx5_ib_qp *qp, |
| 2655 | const struct ib_qp_attr *attr, |
| 2656 | int attr_mask, __be32 *hw_access_flags) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2657 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2658 | u8 dest_rd_atomic; |
| 2659 | u32 access_flags; |
| 2660 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2661 | struct mlx5_ib_dev *dev = to_mdev(qp->ibqp.device); |
| 2662 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2663 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
| 2664 | dest_rd_atomic = attr->max_dest_rd_atomic; |
| 2665 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2666 | dest_rd_atomic = qp->trans_qp.resp_depth; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2667 | |
| 2668 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
| 2669 | access_flags = attr->qp_access_flags; |
| 2670 | else |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 2671 | access_flags = qp->trans_qp.atomic_rd_en; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2672 | |
| 2673 | if (!dest_rd_atomic) |
| 2674 | access_flags &= IB_ACCESS_REMOTE_WRITE; |
| 2675 | |
| 2676 | if (access_flags & IB_ACCESS_REMOTE_READ) |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2677 | *hw_access_flags |= MLX5_QP_BIT_RRE; |
Yonatan Cohen | 13f8d9c | 2018-11-21 13:48:39 +0200 | [diff] [blame] | 2678 | if (access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2679 | int atomic_mode; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2680 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 2681 | atomic_mode = get_atomic_mode(dev, qp->ibqp.qp_type); |
| 2682 | if (atomic_mode < 0) |
| 2683 | return -EOPNOTSUPP; |
| 2684 | |
| 2685 | *hw_access_flags |= MLX5_QP_BIT_RAE; |
| 2686 | *hw_access_flags |= atomic_mode << MLX5_ATOMIC_MODE_OFFSET; |
| 2687 | } |
| 2688 | |
| 2689 | if (access_flags & IB_ACCESS_REMOTE_WRITE) |
| 2690 | *hw_access_flags |= MLX5_QP_BIT_RWE; |
| 2691 | |
| 2692 | *hw_access_flags = cpu_to_be32(*hw_access_flags); |
| 2693 | |
| 2694 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | enum { |
| 2698 | MLX5_PATH_FLAG_FL = 1 << 0, |
| 2699 | MLX5_PATH_FLAG_FREE_AR = 1 << 1, |
| 2700 | MLX5_PATH_FLAG_COUNTER = 1 << 2, |
| 2701 | }; |
| 2702 | |
| 2703 | static int ib_rate_to_mlx5(struct mlx5_ib_dev *dev, u8 rate) |
| 2704 | { |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 2705 | if (rate == IB_RATE_PORT_CURRENT) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2706 | return 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2707 | |
Michael Guralnik | a5a5d19 | 2018-12-09 11:49:50 +0200 | [diff] [blame] | 2708 | if (rate < IB_RATE_2_5_GBPS || rate > IB_RATE_600_GBPS) |
Danit Goldberg | 4f32ac2 | 2018-04-23 17:01:54 +0300 | [diff] [blame] | 2709 | return -EINVAL; |
| 2710 | |
| 2711 | while (rate != IB_RATE_PORT_CURRENT && |
| 2712 | !(1 << (rate + MLX5_STAT_RATE_OFFSET) & |
| 2713 | MLX5_CAP_GEN(dev->mdev, stat_rate_support))) |
| 2714 | --rate; |
| 2715 | |
| 2716 | return rate ? rate + MLX5_STAT_RATE_OFFSET : rate; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2717 | } |
| 2718 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2719 | static int modify_raw_packet_eth_prio(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2720 | struct mlx5_ib_sq *sq, u8 sl, |
| 2721 | struct ib_pd *pd) |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2722 | { |
| 2723 | void *in; |
| 2724 | void *tisc; |
| 2725 | int inlen; |
| 2726 | int err; |
| 2727 | |
| 2728 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2729 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2730 | if (!in) |
| 2731 | return -ENOMEM; |
| 2732 | |
| 2733 | MLX5_SET(modify_tis_in, in, bitmask.prio, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2734 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2735 | |
| 2736 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 2737 | MLX5_SET(tisc, tisc, prio, ((sl & 0x7) << 1)); |
| 2738 | |
| 2739 | err = mlx5_core_modify_tis(dev, sq->tisn, in, inlen); |
| 2740 | |
| 2741 | kvfree(in); |
| 2742 | |
| 2743 | return err; |
| 2744 | } |
| 2745 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2746 | static int modify_raw_packet_tx_affinity(struct mlx5_core_dev *dev, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2747 | struct mlx5_ib_sq *sq, u8 tx_affinity, |
| 2748 | struct ib_pd *pd) |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2749 | { |
| 2750 | void *in; |
| 2751 | void *tisc; |
| 2752 | int inlen; |
| 2753 | int err; |
| 2754 | |
| 2755 | inlen = MLX5_ST_SZ_BYTES(modify_tis_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 2756 | in = kvzalloc(inlen, GFP_KERNEL); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2757 | if (!in) |
| 2758 | return -ENOMEM; |
| 2759 | |
| 2760 | MLX5_SET(modify_tis_in, in, bitmask.lag_tx_port_affinity, 1); |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2761 | MLX5_SET(modify_tis_in, in, uid, to_mpd(pd)->uid); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 2762 | |
| 2763 | tisc = MLX5_ADDR_OF(modify_tis_in, in, ctx); |
| 2764 | MLX5_SET(tisc, tisc, lag_tx_port_affinity, tx_affinity); |
| 2765 | |
| 2766 | err = mlx5_core_modify_tis(dev, sq->tisn, in, inlen); |
| 2767 | |
| 2768 | kvfree(in); |
| 2769 | |
| 2770 | return err; |
| 2771 | } |
| 2772 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2773 | static int mlx5_set_path(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
Dasaratharaman Chandramouli | 9089885 | 2017-04-29 14:41:18 -0400 | [diff] [blame] | 2774 | const struct rdma_ah_attr *ah, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2775 | struct mlx5_qp_path *path, u8 port, int attr_mask, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 2776 | u32 path_flags, const struct ib_qp_attr *attr, |
| 2777 | bool alt) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2778 | { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2779 | const struct ib_global_route *grh = rdma_ah_read_grh(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2780 | int err; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 2781 | enum ib_gid_type gid_type; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2782 | u8 ah_flags = rdma_ah_get_ah_flags(ah); |
| 2783 | u8 sl = rdma_ah_get_sl(ah); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2784 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2785 | if (attr_mask & IB_QP_PKEY_INDEX) |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 2786 | path->pkey_index = cpu_to_be16(alt ? attr->alt_pkey_index : |
| 2787 | attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2788 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2789 | if (ah_flags & IB_AH_GRH) { |
| 2790 | if (grh->sgid_index >= |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2791 | dev->mdev->port_caps[port - 1].gid_table_len) { |
Joe Perches | f4f01b5 | 2015-05-08 15:58:07 -0700 | [diff] [blame] | 2792 | pr_err("sgid_index (%u) too large. max is %d\n", |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2793 | grh->sgid_index, |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 2794 | dev->mdev->port_caps[port - 1].gid_table_len); |
Eli Cohen | f83b426 | 2014-09-14 16:47:54 +0300 | [diff] [blame] | 2795 | return -EINVAL; |
| 2796 | } |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 2797 | } |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 2798 | |
| 2799 | if (ah->type == RDMA_AH_ATTR_TYPE_ROCE) { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2800 | if (!(ah_flags & IB_AH_GRH)) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 2801 | return -EINVAL; |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 2802 | |
Dasaratharaman Chandramouli | 44c5848 | 2017-04-29 14:41:29 -0400 | [diff] [blame] | 2803 | memcpy(path->rmac, ah->roce.dmac, sizeof(ah->roce.dmac)); |
Majd Dibbiny | 2b62185 | 2017-10-30 14:23:14 +0200 | [diff] [blame] | 2804 | if (qp->ibqp.qp_type == IB_QPT_RC || |
| 2805 | qp->ibqp.qp_type == IB_QPT_UC || |
| 2806 | qp->ibqp.qp_type == IB_QPT_XRC_INI || |
| 2807 | qp->ibqp.qp_type == IB_QPT_XRC_TGT) |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 2808 | path->udp_sport = |
| 2809 | mlx5_get_roce_udp_sport(dev, ah->grh.sgid_attr); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2810 | path->dci_cfi_prio_sl = (sl & 0x7) << 4; |
Parav Pandit | 47ec386 | 2018-06-13 10:22:06 +0300 | [diff] [blame] | 2811 | gid_type = ah->grh.sgid_attr->gid_type; |
Majd Dibbiny | ed88451 | 2017-01-18 14:10:35 +0200 | [diff] [blame] | 2812 | if (gid_type == IB_GID_TYPE_ROCE_UDP_ENCAP) |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2813 | path->ecn_dscp = (grh->traffic_class >> 2) & 0x3f; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 2814 | } else { |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 2815 | path->fl_free_ar = (path_flags & MLX5_PATH_FLAG_FL) ? 0x80 : 0; |
| 2816 | path->fl_free_ar |= |
| 2817 | (path_flags & MLX5_PATH_FLAG_FREE_AR) ? 0x40 : 0; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2818 | path->rlid = cpu_to_be16(rdma_ah_get_dlid(ah)); |
| 2819 | path->grh_mlid = rdma_ah_get_path_bits(ah) & 0x7f; |
| 2820 | if (ah_flags & IB_AH_GRH) |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 2821 | path->grh_mlid |= 1 << 7; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2822 | path->dci_cfi_prio_sl = sl & 0xf; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 2823 | } |
| 2824 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2825 | if (ah_flags & IB_AH_GRH) { |
| 2826 | path->mgid_index = grh->sgid_index; |
| 2827 | path->hop_limit = grh->hop_limit; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2828 | path->tclass_flowlabel = |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2829 | cpu_to_be32((grh->traffic_class << 20) | |
| 2830 | (grh->flow_label)); |
| 2831 | memcpy(path->rgid, grh->dgid.raw, 16); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2832 | } |
| 2833 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 2834 | err = ib_rate_to_mlx5(dev, rdma_ah_get_static_rate(ah)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2835 | if (err < 0) |
| 2836 | return err; |
| 2837 | path->static_rate = err; |
| 2838 | path->port = port; |
| 2839 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2840 | if (attr_mask & IB_QP_TIMEOUT) |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 2841 | path->ackto_lt = (alt ? attr->alt_timeout : attr->timeout) << 3; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2842 | |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2843 | if ((qp->ibqp.qp_type == IB_QPT_RAW_PACKET) && qp->sq.wqe_cnt) |
| 2844 | return modify_raw_packet_eth_prio(dev->mdev, |
| 2845 | &qp->raw_packet_qp.sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 2846 | sl & 0xf, qp->ibqp.pd); |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 2847 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2848 | return 0; |
| 2849 | } |
| 2850 | |
| 2851 | static enum mlx5_qp_optpar opt_mask[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE][MLX5_QP_ST_MAX] = { |
| 2852 | [MLX5_QP_STATE_INIT] = { |
| 2853 | [MLX5_QP_STATE_INIT] = { |
| 2854 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 2855 | MLX5_QP_OPTPAR_RAE | |
| 2856 | MLX5_QP_OPTPAR_RWE | |
| 2857 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 2858 | MLX5_QP_OPTPAR_PRI_PORT, |
| 2859 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
| 2860 | MLX5_QP_OPTPAR_PKEY_INDEX | |
| 2861 | MLX5_QP_OPTPAR_PRI_PORT, |
| 2862 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 2863 | MLX5_QP_OPTPAR_Q_KEY | |
| 2864 | MLX5_QP_OPTPAR_PRI_PORT, |
| 2865 | }, |
| 2866 | [MLX5_QP_STATE_RTR] = { |
| 2867 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 2868 | MLX5_QP_OPTPAR_RRE | |
| 2869 | MLX5_QP_OPTPAR_RAE | |
| 2870 | MLX5_QP_OPTPAR_RWE | |
| 2871 | MLX5_QP_OPTPAR_PKEY_INDEX, |
| 2872 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 2873 | MLX5_QP_OPTPAR_RWE | |
| 2874 | MLX5_QP_OPTPAR_PKEY_INDEX, |
| 2875 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 2876 | MLX5_QP_OPTPAR_Q_KEY, |
| 2877 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_PKEY_INDEX | |
| 2878 | MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 2879 | [MLX5_QP_ST_XRC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 2880 | MLX5_QP_OPTPAR_RRE | |
| 2881 | MLX5_QP_OPTPAR_RAE | |
| 2882 | MLX5_QP_OPTPAR_RWE | |
| 2883 | MLX5_QP_OPTPAR_PKEY_INDEX, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2884 | }, |
| 2885 | }, |
| 2886 | [MLX5_QP_STATE_RTR] = { |
| 2887 | [MLX5_QP_STATE_RTS] = { |
| 2888 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 2889 | MLX5_QP_OPTPAR_RRE | |
| 2890 | MLX5_QP_OPTPAR_RAE | |
| 2891 | MLX5_QP_OPTPAR_RWE | |
| 2892 | MLX5_QP_OPTPAR_PM_STATE | |
| 2893 | MLX5_QP_OPTPAR_RNR_TIMEOUT, |
| 2894 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_ALT_ADDR_PATH | |
| 2895 | MLX5_QP_OPTPAR_RWE | |
| 2896 | MLX5_QP_OPTPAR_PM_STATE, |
| 2897 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
| 2898 | }, |
| 2899 | }, |
| 2900 | [MLX5_QP_STATE_RTS] = { |
| 2901 | [MLX5_QP_STATE_RTS] = { |
| 2902 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RRE | |
| 2903 | MLX5_QP_OPTPAR_RAE | |
| 2904 | MLX5_QP_OPTPAR_RWE | |
| 2905 | MLX5_QP_OPTPAR_RNR_TIMEOUT | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 2906 | MLX5_QP_OPTPAR_PM_STATE | |
| 2907 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2908 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE | |
Eli Cohen | c2a3431 | 2013-10-24 12:01:02 +0300 | [diff] [blame] | 2909 | MLX5_QP_OPTPAR_PM_STATE | |
| 2910 | MLX5_QP_OPTPAR_ALT_ADDR_PATH, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2911 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY | |
| 2912 | MLX5_QP_OPTPAR_SRQN | |
| 2913 | MLX5_QP_OPTPAR_CQN_RCV, |
| 2914 | }, |
| 2915 | }, |
| 2916 | [MLX5_QP_STATE_SQER] = { |
| 2917 | [MLX5_QP_STATE_RTS] = { |
| 2918 | [MLX5_QP_ST_UD] = MLX5_QP_OPTPAR_Q_KEY, |
| 2919 | [MLX5_QP_ST_MLX] = MLX5_QP_OPTPAR_Q_KEY, |
Eli Cohen | 75959f5 | 2013-09-11 16:35:31 +0300 | [diff] [blame] | 2920 | [MLX5_QP_ST_UC] = MLX5_QP_OPTPAR_RWE, |
Eli Cohen | a4774e9 | 2013-09-11 16:35:32 +0300 | [diff] [blame] | 2921 | [MLX5_QP_ST_RC] = MLX5_QP_OPTPAR_RNR_TIMEOUT | |
| 2922 | MLX5_QP_OPTPAR_RWE | |
| 2923 | MLX5_QP_OPTPAR_RAE | |
| 2924 | MLX5_QP_OPTPAR_RRE, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 2925 | }, |
| 2926 | }, |
| 2927 | }; |
| 2928 | |
| 2929 | static int ib_nr_to_mlx5_nr(int ib_mask) |
| 2930 | { |
| 2931 | switch (ib_mask) { |
| 2932 | case IB_QP_STATE: |
| 2933 | return 0; |
| 2934 | case IB_QP_CUR_STATE: |
| 2935 | return 0; |
| 2936 | case IB_QP_EN_SQD_ASYNC_NOTIFY: |
| 2937 | return 0; |
| 2938 | case IB_QP_ACCESS_FLAGS: |
| 2939 | return MLX5_QP_OPTPAR_RWE | MLX5_QP_OPTPAR_RRE | |
| 2940 | MLX5_QP_OPTPAR_RAE; |
| 2941 | case IB_QP_PKEY_INDEX: |
| 2942 | return MLX5_QP_OPTPAR_PKEY_INDEX; |
| 2943 | case IB_QP_PORT: |
| 2944 | return MLX5_QP_OPTPAR_PRI_PORT; |
| 2945 | case IB_QP_QKEY: |
| 2946 | return MLX5_QP_OPTPAR_Q_KEY; |
| 2947 | case IB_QP_AV: |
| 2948 | return MLX5_QP_OPTPAR_PRIMARY_ADDR_PATH | |
| 2949 | MLX5_QP_OPTPAR_PRI_PORT; |
| 2950 | case IB_QP_PATH_MTU: |
| 2951 | return 0; |
| 2952 | case IB_QP_TIMEOUT: |
| 2953 | return MLX5_QP_OPTPAR_ACK_TIMEOUT; |
| 2954 | case IB_QP_RETRY_CNT: |
| 2955 | return MLX5_QP_OPTPAR_RETRY_COUNT; |
| 2956 | case IB_QP_RNR_RETRY: |
| 2957 | return MLX5_QP_OPTPAR_RNR_RETRY; |
| 2958 | case IB_QP_RQ_PSN: |
| 2959 | return 0; |
| 2960 | case IB_QP_MAX_QP_RD_ATOMIC: |
| 2961 | return MLX5_QP_OPTPAR_SRA_MAX; |
| 2962 | case IB_QP_ALT_PATH: |
| 2963 | return MLX5_QP_OPTPAR_ALT_ADDR_PATH; |
| 2964 | case IB_QP_MIN_RNR_TIMER: |
| 2965 | return MLX5_QP_OPTPAR_RNR_TIMEOUT; |
| 2966 | case IB_QP_SQ_PSN: |
| 2967 | return 0; |
| 2968 | case IB_QP_MAX_DEST_RD_ATOMIC: |
| 2969 | return MLX5_QP_OPTPAR_RRA_MAX | MLX5_QP_OPTPAR_RWE | |
| 2970 | MLX5_QP_OPTPAR_RRE | MLX5_QP_OPTPAR_RAE; |
| 2971 | case IB_QP_PATH_MIG_STATE: |
| 2972 | return MLX5_QP_OPTPAR_PM_STATE; |
| 2973 | case IB_QP_CAP: |
| 2974 | return 0; |
| 2975 | case IB_QP_DEST_QPN: |
| 2976 | return 0; |
| 2977 | } |
| 2978 | return 0; |
| 2979 | } |
| 2980 | |
| 2981 | static int ib_mask_to_mlx5_opt(int ib_mask) |
| 2982 | { |
| 2983 | int result = 0; |
| 2984 | int i; |
| 2985 | |
| 2986 | for (i = 0; i < 8 * sizeof(int); i++) { |
| 2987 | if ((1 << i) & ib_mask) |
| 2988 | result |= ib_nr_to_mlx5_nr(1 << i); |
| 2989 | } |
| 2990 | |
| 2991 | return result; |
| 2992 | } |
| 2993 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 2994 | static int modify_raw_packet_qp_rq( |
| 2995 | struct mlx5_ib_dev *dev, struct mlx5_ib_rq *rq, int new_state, |
| 2996 | 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] | 2997 | { |
| 2998 | void *in; |
| 2999 | void *rqc; |
| 3000 | int inlen; |
| 3001 | int err; |
| 3002 | |
| 3003 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3004 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3005 | if (!in) |
| 3006 | return -ENOMEM; |
| 3007 | |
| 3008 | MLX5_SET(modify_rq_in, in, rq_state, rq->state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3009 | MLX5_SET(modify_rq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3010 | |
| 3011 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 3012 | MLX5_SET(rqc, rqc, state, new_state); |
| 3013 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3014 | if (raw_qp_param->set_mask & MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID) { |
| 3015 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 3016 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 3017 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3018 | MLX5_SET(rqc, rqc, counter_set_id, raw_qp_param->rq_q_ctr_id); |
| 3019 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 3020 | dev_info_once( |
| 3021 | &dev->ib_dev.dev, |
| 3022 | "RAW PACKET QP counters are not supported on current FW\n"); |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | err = mlx5_core_modify_rq(dev->mdev, rq->base.mqp.qpn, in, inlen); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3026 | if (err) |
| 3027 | goto out; |
| 3028 | |
| 3029 | rq->state = new_state; |
| 3030 | |
| 3031 | out: |
| 3032 | kvfree(in); |
| 3033 | return err; |
| 3034 | } |
| 3035 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3036 | static int modify_raw_packet_qp_sq( |
| 3037 | struct mlx5_core_dev *dev, struct mlx5_ib_sq *sq, int new_state, |
| 3038 | 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] | 3039 | { |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3040 | struct mlx5_ib_qp *ibqp = sq->base.container_mibqp; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3041 | struct mlx5_rate_limit old_rl = ibqp->rl; |
| 3042 | struct mlx5_rate_limit new_rl = old_rl; |
| 3043 | bool new_rate_added = false; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3044 | u16 rl_index = 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3045 | void *in; |
| 3046 | void *sqc; |
| 3047 | int inlen; |
| 3048 | int err; |
| 3049 | |
| 3050 | inlen = MLX5_ST_SZ_BYTES(modify_sq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 3051 | in = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3052 | if (!in) |
| 3053 | return -ENOMEM; |
| 3054 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3055 | MLX5_SET(modify_sq_in, in, uid, to_mpd(pd)->uid); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3056 | MLX5_SET(modify_sq_in, in, sq_state, sq->state); |
| 3057 | |
| 3058 | sqc = MLX5_ADDR_OF(modify_sq_in, in, ctx); |
| 3059 | MLX5_SET(sqc, sqc, state, new_state); |
| 3060 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3061 | if (raw_qp_param->set_mask & MLX5_RAW_QP_RATE_LIMIT) { |
| 3062 | if (new_state != MLX5_SQC_STATE_RDY) |
| 3063 | pr_warn("%s: Rate limit can only be changed when SQ is moving to RDY\n", |
| 3064 | __func__); |
| 3065 | else |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3066 | new_rl = raw_qp_param->rl; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3067 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3068 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3069 | if (!mlx5_rl_are_equal(&old_rl, &new_rl)) { |
| 3070 | if (new_rl.rate) { |
| 3071 | err = mlx5_rl_add_rate(dev, &rl_index, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3072 | if (err) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3073 | pr_err("Failed configuring rate limit(err %d): \ |
| 3074 | rate %u, max_burst_sz %u, typical_pkt_sz %u\n", |
| 3075 | err, new_rl.rate, new_rl.max_burst_sz, |
| 3076 | new_rl.typical_pkt_sz); |
| 3077 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3078 | goto out; |
| 3079 | } |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3080 | new_rate_added = true; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3081 | } |
| 3082 | |
| 3083 | MLX5_SET64(modify_sq_in, in, modify_bitmask, 1); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3084 | /* index 0 means no limit */ |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3085 | MLX5_SET(sqc, sqc, packet_pacing_rate_limit_index, rl_index); |
| 3086 | } |
| 3087 | |
| 3088 | err = mlx5_core_modify_sq(dev, sq->base.mqp.qpn, in, inlen); |
| 3089 | if (err) { |
| 3090 | /* Remove new rate from table if failed */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3091 | if (new_rate_added) |
| 3092 | mlx5_rl_remove_rate(dev, &new_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3093 | goto out; |
| 3094 | } |
| 3095 | |
| 3096 | /* Only remove the old rate after new rate was set */ |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3097 | if ((old_rl.rate && |
| 3098 | !mlx5_rl_are_equal(&old_rl, &new_rl)) || |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3099 | (new_state != MLX5_SQC_STATE_RDY)) |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3100 | mlx5_rl_remove_rate(dev, &old_rl); |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3101 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3102 | ibqp->rl = new_rl; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3103 | sq->state = new_state; |
| 3104 | |
| 3105 | out: |
| 3106 | kvfree(in); |
| 3107 | return err; |
| 3108 | } |
| 3109 | |
| 3110 | 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] | 3111 | const struct mlx5_modify_raw_qp_param *raw_qp_param, |
| 3112 | u8 tx_affinity) |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3113 | { |
| 3114 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 3115 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 3116 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3117 | int modify_rq = !!qp->rq.wqe_cnt; |
| 3118 | int modify_sq = !!qp->sq.wqe_cnt; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3119 | int rq_state; |
| 3120 | int sq_state; |
| 3121 | int err; |
| 3122 | |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3123 | switch (raw_qp_param->operation) { |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3124 | case MLX5_CMD_OP_RST2INIT_QP: |
| 3125 | rq_state = MLX5_RQC_STATE_RDY; |
| 3126 | sq_state = MLX5_SQC_STATE_RDY; |
| 3127 | break; |
| 3128 | case MLX5_CMD_OP_2ERR_QP: |
| 3129 | rq_state = MLX5_RQC_STATE_ERR; |
| 3130 | sq_state = MLX5_SQC_STATE_ERR; |
| 3131 | break; |
| 3132 | case MLX5_CMD_OP_2RST_QP: |
| 3133 | rq_state = MLX5_RQC_STATE_RST; |
| 3134 | sq_state = MLX5_SQC_STATE_RST; |
| 3135 | break; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3136 | case MLX5_CMD_OP_RTR2RTS_QP: |
| 3137 | case MLX5_CMD_OP_RTS2RTS_QP: |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3138 | if (raw_qp_param->set_mask == |
| 3139 | MLX5_RAW_QP_RATE_LIMIT) { |
| 3140 | modify_rq = 0; |
| 3141 | sq_state = sq->state; |
| 3142 | } else { |
| 3143 | return raw_qp_param->set_mask ? -EINVAL : 0; |
| 3144 | } |
| 3145 | break; |
| 3146 | case MLX5_CMD_OP_INIT2INIT_QP: |
| 3147 | case MLX5_CMD_OP_INIT2RTR_QP: |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3148 | if (raw_qp_param->set_mask) |
| 3149 | return -EINVAL; |
| 3150 | else |
| 3151 | return 0; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3152 | default: |
| 3153 | WARN_ON(1); |
| 3154 | return -EINVAL; |
| 3155 | } |
| 3156 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3157 | if (modify_rq) { |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 3158 | err = modify_raw_packet_qp_rq(dev, rq, rq_state, raw_qp_param, |
| 3159 | qp->ibqp.pd); |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3160 | if (err) |
| 3161 | return err; |
| 3162 | } |
| 3163 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3164 | if (modify_sq) { |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3165 | if (tx_affinity) { |
| 3166 | err = modify_raw_packet_tx_affinity(dev->mdev, sq, |
Yishai Hadas | 1cd6dbd | 2018-09-20 21:39:27 +0300 | [diff] [blame] | 3167 | tx_affinity, |
| 3168 | qp->ibqp.pd); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3169 | if (err) |
| 3170 | return err; |
| 3171 | } |
| 3172 | |
Yishai Hadas | c14003f | 2018-09-20 21:39:22 +0300 | [diff] [blame] | 3173 | return modify_raw_packet_qp_sq(dev->mdev, sq, sq_state, |
| 3174 | raw_qp_param, qp->ibqp.pd); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3175 | } |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3176 | |
| 3177 | return 0; |
| 3178 | } |
| 3179 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3180 | static unsigned int get_tx_affinity(struct mlx5_ib_dev *dev, |
| 3181 | struct mlx5_ib_pd *pd, |
| 3182 | struct mlx5_ib_qp_base *qp_base, |
| 3183 | u8 port_num) |
| 3184 | { |
| 3185 | struct mlx5_ib_ucontext *ucontext = NULL; |
| 3186 | unsigned int tx_port_affinity; |
| 3187 | |
| 3188 | if (pd && pd->ibpd.uobject && pd->ibpd.uobject->context) |
| 3189 | ucontext = to_mucontext(pd->ibpd.uobject->context); |
| 3190 | |
| 3191 | if (ucontext) { |
| 3192 | tx_port_affinity = (unsigned int)atomic_add_return( |
| 3193 | 1, &ucontext->tx_port_affinity) % |
| 3194 | MLX5_MAX_PORTS + |
| 3195 | 1; |
| 3196 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x ucontext %p\n", |
| 3197 | tx_port_affinity, qp_base->mqp.qpn, ucontext); |
| 3198 | } else { |
| 3199 | tx_port_affinity = |
| 3200 | (unsigned int)atomic_add_return( |
| 3201 | 1, &dev->roce[port_num].tx_port_affinity) % |
| 3202 | MLX5_MAX_PORTS + |
| 3203 | 1; |
| 3204 | mlx5_ib_dbg(dev, "Set tx affinity 0x%x to qpn 0x%x\n", |
| 3205 | tx_port_affinity, qp_base->mqp.qpn); |
| 3206 | } |
| 3207 | |
| 3208 | return tx_port_affinity; |
| 3209 | } |
| 3210 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3211 | static int __mlx5_ib_modify_qp(struct ib_qp *ibqp, |
| 3212 | const struct ib_qp_attr *attr, int attr_mask, |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3213 | enum ib_qp_state cur_state, enum ib_qp_state new_state, |
| 3214 | const struct mlx5_ib_modify_qp *ucmd) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3215 | { |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3216 | static const u16 optab[MLX5_QP_NUM_STATE][MLX5_QP_NUM_STATE] = { |
| 3217 | [MLX5_QP_STATE_RST] = { |
| 3218 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3219 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3220 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_RST2INIT_QP, |
| 3221 | }, |
| 3222 | [MLX5_QP_STATE_INIT] = { |
| 3223 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3224 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3225 | [MLX5_QP_STATE_INIT] = MLX5_CMD_OP_INIT2INIT_QP, |
| 3226 | [MLX5_QP_STATE_RTR] = MLX5_CMD_OP_INIT2RTR_QP, |
| 3227 | }, |
| 3228 | [MLX5_QP_STATE_RTR] = { |
| 3229 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3230 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3231 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTR2RTS_QP, |
| 3232 | }, |
| 3233 | [MLX5_QP_STATE_RTS] = { |
| 3234 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3235 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3236 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_RTS2RTS_QP, |
| 3237 | }, |
| 3238 | [MLX5_QP_STATE_SQD] = { |
| 3239 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3240 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3241 | }, |
| 3242 | [MLX5_QP_STATE_SQER] = { |
| 3243 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3244 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3245 | [MLX5_QP_STATE_RTS] = MLX5_CMD_OP_SQERR2RTS_QP, |
| 3246 | }, |
| 3247 | [MLX5_QP_STATE_ERR] = { |
| 3248 | [MLX5_QP_STATE_RST] = MLX5_CMD_OP_2RST_QP, |
| 3249 | [MLX5_QP_STATE_ERR] = MLX5_CMD_OP_2ERR_QP, |
| 3250 | } |
| 3251 | }; |
| 3252 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3253 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3254 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3255 | struct mlx5_ib_qp_base *base = &qp->trans_qp.base; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3256 | struct mlx5_ib_cq *send_cq, *recv_cq; |
| 3257 | struct mlx5_qp_context *context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3258 | struct mlx5_ib_pd *pd; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3259 | struct mlx5_ib_port *mibport = NULL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3260 | enum mlx5_qp_state mlx5_cur, mlx5_new; |
| 3261 | enum mlx5_qp_optpar optpar; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3262 | int mlx5_st; |
| 3263 | int err; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3264 | u16 op; |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3265 | u8 tx_affinity = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3266 | |
Leon Romanovsky | 55de9a7 | 2018-02-25 13:39:52 +0200 | [diff] [blame] | 3267 | mlx5_st = to_mlx5_st(ibqp->qp_type == IB_QPT_DRIVER ? |
| 3268 | qp->qp_sub_type : ibqp->qp_type); |
| 3269 | if (mlx5_st < 0) |
| 3270 | return -EINVAL; |
| 3271 | |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 3272 | context = kzalloc(sizeof(*context), GFP_KERNEL); |
| 3273 | if (!context) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3274 | return -ENOMEM; |
| 3275 | |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3276 | pd = get_pd(qp); |
Leon Romanovsky | 55de9a7 | 2018-02-25 13:39:52 +0200 | [diff] [blame] | 3277 | context->flags = cpu_to_be32(mlx5_st << 16); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3278 | |
| 3279 | if (!(attr_mask & IB_QP_PATH_MIG_STATE)) { |
| 3280 | context->flags |= cpu_to_be32(MLX5_QP_PM_MIGRATED << 11); |
| 3281 | } else { |
| 3282 | switch (attr->path_mig_state) { |
| 3283 | case IB_MIG_MIGRATED: |
| 3284 | context->flags |= cpu_to_be32(MLX5_QP_PM_MIGRATED << 11); |
| 3285 | break; |
| 3286 | case IB_MIG_REARM: |
| 3287 | context->flags |= cpu_to_be32(MLX5_QP_PM_REARM << 11); |
| 3288 | break; |
| 3289 | case IB_MIG_ARMED: |
| 3290 | context->flags |= cpu_to_be32(MLX5_QP_PM_ARMED << 11); |
| 3291 | break; |
| 3292 | } |
| 3293 | } |
| 3294 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3295 | if ((cur_state == IB_QPS_RESET) && (new_state == IB_QPS_INIT)) { |
| 3296 | if ((ibqp->qp_type == IB_QPT_RC) || |
| 3297 | (ibqp->qp_type == IB_QPT_UD && |
| 3298 | !(qp->flags & MLX5_IB_QP_SQPN_QP1)) || |
| 3299 | (ibqp->qp_type == IB_QPT_UC) || |
| 3300 | (ibqp->qp_type == IB_QPT_RAW_PACKET) || |
| 3301 | (ibqp->qp_type == IB_QPT_XRC_INI) || |
| 3302 | (ibqp->qp_type == IB_QPT_XRC_TGT)) { |
Aviv Heller | 7c34ec1 | 2018-08-23 13:47:53 +0300 | [diff] [blame] | 3303 | if (dev->lag_active) { |
Daniel Jurgens | 7fd8aef | 2018-01-04 17:25:35 +0200 | [diff] [blame] | 3304 | u8 p = mlx5_core_native_port_num(dev->mdev); |
Majd Dibbiny | c6a21c3 | 2018-08-28 14:29:05 +0300 | [diff] [blame] | 3305 | tx_affinity = get_tx_affinity(dev, pd, base, p); |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3306 | context->flags |= cpu_to_be32(tx_affinity << 24); |
| 3307 | } |
| 3308 | } |
| 3309 | } |
| 3310 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3311 | if (is_sqp(ibqp->qp_type)) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3312 | context->mtu_msgmax = (IB_MTU_256 << 5) | 8; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3313 | } else if ((ibqp->qp_type == IB_QPT_UD && |
| 3314 | !(qp->flags & MLX5_IB_QP_UNDERLAY)) || |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3315 | ibqp->qp_type == MLX5_IB_QPT_REG_UMR) { |
| 3316 | context->mtu_msgmax = (IB_MTU_4096 << 5) | 12; |
| 3317 | } else if (attr_mask & IB_QP_PATH_MTU) { |
| 3318 | if (attr->path_mtu < IB_MTU_256 || |
| 3319 | attr->path_mtu > IB_MTU_4096) { |
| 3320 | mlx5_ib_warn(dev, "invalid mtu %d\n", attr->path_mtu); |
| 3321 | err = -EINVAL; |
| 3322 | goto out; |
| 3323 | } |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3324 | context->mtu_msgmax = (attr->path_mtu << 5) | |
| 3325 | (u8)MLX5_CAP_GEN(dev->mdev, log_max_msg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | if (attr_mask & IB_QP_DEST_QPN) |
| 3329 | context->log_pg_sz_remote_qpn = cpu_to_be32(attr->dest_qp_num); |
| 3330 | |
| 3331 | if (attr_mask & IB_QP_PKEY_INDEX) |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 3332 | context->pri_path.pkey_index = cpu_to_be16(attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3333 | |
| 3334 | /* todo implement counter_index functionality */ |
| 3335 | |
| 3336 | if (is_sqp(ibqp->qp_type)) |
| 3337 | context->pri_path.port = qp->port; |
| 3338 | |
| 3339 | if (attr_mask & IB_QP_PORT) |
| 3340 | context->pri_path.port = attr->port_num; |
| 3341 | |
| 3342 | if (attr_mask & IB_QP_AV) { |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3343 | err = mlx5_set_path(dev, qp, &attr->ah_attr, &context->pri_path, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3344 | attr_mask & IB_QP_PORT ? attr->port_num : qp->port, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3345 | attr_mask, 0, attr, false); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3346 | if (err) |
| 3347 | goto out; |
| 3348 | } |
| 3349 | |
| 3350 | if (attr_mask & IB_QP_TIMEOUT) |
| 3351 | context->pri_path.ackto_lt |= attr->timeout << 3; |
| 3352 | |
| 3353 | if (attr_mask & IB_QP_ALT_PATH) { |
majd@mellanox.com | 75850d0 | 2016-01-14 19:13:06 +0200 | [diff] [blame] | 3354 | err = mlx5_set_path(dev, qp, &attr->alt_ah_attr, |
| 3355 | &context->alt_path, |
Achiad Shochat | f879ee8 | 2016-06-04 15:15:37 +0300 | [diff] [blame] | 3356 | attr->alt_port_num, |
| 3357 | attr_mask | IB_QP_PKEY_INDEX | IB_QP_TIMEOUT, |
| 3358 | 0, attr, true); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3359 | if (err) |
| 3360 | goto out; |
| 3361 | } |
| 3362 | |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 3363 | get_cqs(qp->ibqp.qp_type, qp->ibqp.send_cq, qp->ibqp.recv_cq, |
| 3364 | &send_cq, &recv_cq); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3365 | |
| 3366 | context->flags_pd = cpu_to_be32(pd ? pd->pdn : to_mpd(dev->devr.p0)->pdn); |
| 3367 | context->cqn_send = send_cq ? cpu_to_be32(send_cq->mcq.cqn) : 0; |
| 3368 | context->cqn_recv = recv_cq ? cpu_to_be32(recv_cq->mcq.cqn) : 0; |
| 3369 | context->params1 = cpu_to_be32(MLX5_IB_ACK_REQ_FREQ << 28); |
| 3370 | |
| 3371 | if (attr_mask & IB_QP_RNR_RETRY) |
| 3372 | context->params1 |= cpu_to_be32(attr->rnr_retry << 13); |
| 3373 | |
| 3374 | if (attr_mask & IB_QP_RETRY_CNT) |
| 3375 | context->params1 |= cpu_to_be32(attr->retry_cnt << 16); |
| 3376 | |
| 3377 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC) { |
| 3378 | if (attr->max_rd_atomic) |
| 3379 | context->params1 |= |
| 3380 | cpu_to_be32(fls(attr->max_rd_atomic - 1) << 21); |
| 3381 | } |
| 3382 | |
| 3383 | if (attr_mask & IB_QP_SQ_PSN) |
| 3384 | context->next_send_psn = cpu_to_be32(attr->sq_psn); |
| 3385 | |
| 3386 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) { |
| 3387 | if (attr->max_dest_rd_atomic) |
| 3388 | context->params2 |= |
| 3389 | cpu_to_be32(fls(attr->max_dest_rd_atomic - 1) << 21); |
| 3390 | } |
| 3391 | |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3392 | if (attr_mask & (IB_QP_ACCESS_FLAGS | IB_QP_MAX_DEST_RD_ATOMIC)) { |
| 3393 | __be32 access_flags = 0; |
| 3394 | |
| 3395 | err = to_mlx5_access_flags(qp, attr, attr_mask, &access_flags); |
| 3396 | if (err) |
| 3397 | goto out; |
| 3398 | |
| 3399 | context->params2 |= access_flags; |
| 3400 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3401 | |
| 3402 | if (attr_mask & IB_QP_MIN_RNR_TIMER) |
| 3403 | context->rnr_nextrecvpsn |= cpu_to_be32(attr->min_rnr_timer << 24); |
| 3404 | |
| 3405 | if (attr_mask & IB_QP_RQ_PSN) |
| 3406 | context->rnr_nextrecvpsn |= cpu_to_be32(attr->rq_psn); |
| 3407 | |
| 3408 | if (attr_mask & IB_QP_QKEY) |
| 3409 | context->qkey = cpu_to_be32(attr->qkey); |
| 3410 | |
| 3411 | if (qp->rq.wqe_cnt && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
| 3412 | context->db_rec_addr = cpu_to_be64(qp->db.dma); |
| 3413 | |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3414 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
| 3415 | u8 port_num = (attr_mask & IB_QP_PORT ? attr->port_num : |
| 3416 | qp->port) - 1; |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3417 | |
| 3418 | /* Underlay port should be used - index 0 function per port */ |
| 3419 | if (qp->flags & MLX5_IB_QP_UNDERLAY) |
| 3420 | port_num = 0; |
| 3421 | |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3422 | mibport = &dev->port[port_num]; |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3423 | context->qp_counter_set_usr_page |= |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 3424 | cpu_to_be32((u32)(mibport->cnts.set_id) << 24); |
Mark Bloch | 0837e86 | 2016-06-17 15:10:55 +0300 | [diff] [blame] | 3425 | } |
| 3426 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3427 | if (!ibqp->uobject && cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) |
| 3428 | context->sq_crq_size |= cpu_to_be16(1 << 4); |
| 3429 | |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 3430 | if (qp->flags & MLX5_IB_QP_SQPN_QP1) |
| 3431 | context->deth_sqpn = cpu_to_be32(1); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3432 | |
| 3433 | mlx5_cur = to_mlx5_state(cur_state); |
| 3434 | mlx5_new = to_mlx5_state(new_state); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3435 | |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3436 | 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] | 3437 | !optab[mlx5_cur][mlx5_new]) { |
| 3438 | err = -EINVAL; |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3439 | goto out; |
Dan Carpenter | 5d414b1 | 2018-03-06 13:00:31 +0300 | [diff] [blame] | 3440 | } |
majd@mellanox.com | 427c1e7 | 2016-01-14 19:13:07 +0200 | [diff] [blame] | 3441 | |
| 3442 | op = optab[mlx5_cur][mlx5_new]; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3443 | optpar = ib_mask_to_mlx5_opt(attr_mask); |
| 3444 | optpar &= opt_mask[mlx5_cur][mlx5_new][mlx5_st]; |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3445 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3446 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
| 3447 | qp->flags & MLX5_IB_QP_UNDERLAY) { |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3448 | struct mlx5_modify_raw_qp_param raw_qp_param = {}; |
| 3449 | |
| 3450 | raw_qp_param.operation = op; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3451 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 3452 | raw_qp_param.rq_q_ctr_id = mibport->cnts.set_id; |
Alex Vesker | eb49ab0 | 2016-08-28 12:25:53 +0300 | [diff] [blame] | 3453 | raw_qp_param.set_mask |= MLX5_RAW_QP_MOD_SET_RQ_Q_CTR_ID; |
| 3454 | } |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3455 | |
| 3456 | if (attr_mask & IB_QP_RATE_LIMIT) { |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3457 | raw_qp_param.rl.rate = attr->rate_limit; |
| 3458 | |
| 3459 | if (ucmd->burst_info.max_burst_sz) { |
| 3460 | if (attr->rate_limit && |
| 3461 | MLX5_CAP_QOS(dev->mdev, packet_pacing_burst_bound)) { |
| 3462 | raw_qp_param.rl.max_burst_sz = |
| 3463 | ucmd->burst_info.max_burst_sz; |
| 3464 | } else { |
| 3465 | err = -EINVAL; |
| 3466 | goto out; |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | if (ucmd->burst_info.typical_pkt_sz) { |
| 3471 | if (attr->rate_limit && |
| 3472 | MLX5_CAP_QOS(dev->mdev, packet_pacing_typical_size)) { |
| 3473 | raw_qp_param.rl.typical_pkt_sz = |
| 3474 | ucmd->burst_info.typical_pkt_sz; |
| 3475 | } else { |
| 3476 | err = -EINVAL; |
| 3477 | goto out; |
| 3478 | } |
| 3479 | } |
| 3480 | |
Bodong Wang | 7d29f34 | 2016-12-01 13:43:16 +0200 | [diff] [blame] | 3481 | raw_qp_param.set_mask |= MLX5_RAW_QP_RATE_LIMIT; |
| 3482 | } |
| 3483 | |
Aviv Heller | 13eab21 | 2016-09-18 20:48:04 +0300 | [diff] [blame] | 3484 | err = modify_raw_packet_qp(dev, qp, &raw_qp_param, tx_affinity); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3485 | } else { |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 3486 | err = mlx5_core_qp_modify(dev->mdev, op, optpar, context, |
majd@mellanox.com | ad5f8e9 | 2016-01-14 19:13:08 +0200 | [diff] [blame] | 3487 | &base->mqp); |
Alex Vesker | 0680efa | 2016-08-28 12:25:52 +0300 | [diff] [blame] | 3488 | } |
| 3489 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3490 | if (err) |
| 3491 | goto out; |
| 3492 | |
| 3493 | qp->state = new_state; |
| 3494 | |
| 3495 | if (attr_mask & IB_QP_ACCESS_FLAGS) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3496 | qp->trans_qp.atomic_rd_en = attr->qp_access_flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3497 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3498 | qp->trans_qp.resp_depth = attr->max_dest_rd_atomic; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3499 | if (attr_mask & IB_QP_PORT) |
| 3500 | qp->port = attr->port_num; |
| 3501 | if (attr_mask & IB_QP_ALT_PATH) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3502 | qp->trans_qp.alt_port = attr->alt_port_num; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3503 | |
| 3504 | /* |
| 3505 | * If we moved a kernel QP to RESET, clean up all old CQ |
| 3506 | * entries and reinitialize the QP. |
| 3507 | */ |
Leon Romanovsky | 75a4598 | 2018-03-11 13:51:32 +0200 | [diff] [blame] | 3508 | if (new_state == IB_QPS_RESET && |
| 3509 | !ibqp->uobject && ibqp->qp_type != IB_QPT_XRC_TGT) { |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3510 | mlx5_ib_cq_clean(recv_cq, base->mqp.qpn, |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3511 | ibqp->srq ? to_msrq(ibqp->srq) : NULL); |
| 3512 | if (send_cq != recv_cq) |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 3513 | mlx5_ib_cq_clean(send_cq, base->mqp.qpn, NULL); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3514 | |
| 3515 | qp->rq.head = 0; |
| 3516 | qp->rq.tail = 0; |
| 3517 | qp->sq.head = 0; |
| 3518 | qp->sq.tail = 0; |
| 3519 | qp->sq.cur_post = 0; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3520 | if (qp->sq.wqe_cnt) |
| 3521 | qp->sq.cur_edge = get_sq_edge(&qp->sq, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3522 | qp->db.db[MLX5_RCV_DBR] = 0; |
| 3523 | qp->db.db[MLX5_SND_DBR] = 0; |
| 3524 | } |
| 3525 | |
| 3526 | out: |
Saeed Mahameed | 1a412fb | 2016-07-19 18:03:21 +0300 | [diff] [blame] | 3527 | kfree(context); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3528 | return err; |
| 3529 | } |
| 3530 | |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3531 | static inline bool is_valid_mask(int mask, int req, int opt) |
| 3532 | { |
| 3533 | if ((mask & req) != req) |
| 3534 | return false; |
| 3535 | |
| 3536 | if (mask & ~(req | opt)) |
| 3537 | return false; |
| 3538 | |
| 3539 | return true; |
| 3540 | } |
| 3541 | |
| 3542 | /* check valid transition for driver QP types |
| 3543 | * for now the only QP type that this function supports is DCI |
| 3544 | */ |
| 3545 | static bool modify_dci_qp_is_ok(enum ib_qp_state cur_state, enum ib_qp_state new_state, |
| 3546 | enum ib_qp_attr_mask attr_mask) |
| 3547 | { |
| 3548 | int req = IB_QP_STATE; |
| 3549 | int opt = 0; |
| 3550 | |
Moni Shoua | 99ed748 | 2018-09-12 09:33:55 +0300 | [diff] [blame] | 3551 | if (new_state == IB_QPS_RESET) { |
| 3552 | return is_valid_mask(attr_mask, req, opt); |
| 3553 | } else if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3554 | req |= IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3555 | return is_valid_mask(attr_mask, req, opt); |
| 3556 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_INIT) { |
| 3557 | opt = IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3558 | return is_valid_mask(attr_mask, req, opt); |
| 3559 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 3560 | req |= IB_QP_PATH_MTU; |
Artemy Kovalyov | 5ec0304 | 2018-11-05 08:12:07 +0200 | [diff] [blame] | 3561 | opt = IB_QP_PKEY_INDEX | IB_QP_AV; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3562 | return is_valid_mask(attr_mask, req, opt); |
| 3563 | } else if (cur_state == IB_QPS_RTR && new_state == IB_QPS_RTS) { |
| 3564 | req |= IB_QP_TIMEOUT | IB_QP_RETRY_CNT | IB_QP_RNR_RETRY | |
| 3565 | IB_QP_MAX_QP_RD_ATOMIC | IB_QP_SQ_PSN; |
| 3566 | opt = IB_QP_MIN_RNR_TIMER; |
| 3567 | return is_valid_mask(attr_mask, req, opt); |
| 3568 | } else if (cur_state == IB_QPS_RTS && new_state == IB_QPS_RTS) { |
| 3569 | opt = IB_QP_MIN_RNR_TIMER; |
| 3570 | return is_valid_mask(attr_mask, req, opt); |
| 3571 | } else if (cur_state != IB_QPS_RESET && new_state == IB_QPS_ERR) { |
| 3572 | return is_valid_mask(attr_mask, req, opt); |
| 3573 | } |
| 3574 | return false; |
| 3575 | } |
| 3576 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3577 | /* mlx5_ib_modify_dct: modify a DCT QP |
| 3578 | * valid transitions are: |
| 3579 | * RESET to INIT: must set access_flags, pkey_index and port |
| 3580 | * INIT to RTR : must set min_rnr_timer, tclass, flow_label, |
| 3581 | * mtu, gid_index and hop_limit |
| 3582 | * Other transitions and attributes are illegal |
| 3583 | */ |
| 3584 | static int mlx5_ib_modify_dct(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 3585 | int attr_mask, struct ib_udata *udata) |
| 3586 | { |
| 3587 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 3588 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3589 | enum ib_qp_state cur_state, new_state; |
| 3590 | int err = 0; |
| 3591 | int required = IB_QP_STATE; |
| 3592 | void *dctc; |
| 3593 | |
| 3594 | if (!(attr_mask & IB_QP_STATE)) |
| 3595 | return -EINVAL; |
| 3596 | |
| 3597 | cur_state = qp->state; |
| 3598 | new_state = attr->qp_state; |
| 3599 | |
| 3600 | dctc = MLX5_ADDR_OF(create_dct_in, qp->dct.in, dct_context_entry); |
| 3601 | if (cur_state == IB_QPS_RESET && new_state == IB_QPS_INIT) { |
| 3602 | required |= IB_QP_ACCESS_FLAGS | IB_QP_PKEY_INDEX | IB_QP_PORT; |
| 3603 | if (!is_valid_mask(attr_mask, required, 0)) |
| 3604 | return -EINVAL; |
| 3605 | |
| 3606 | if (attr->port_num == 0 || |
| 3607 | attr->port_num > MLX5_CAP_GEN(dev->mdev, num_ports)) { |
| 3608 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 3609 | attr->port_num, dev->num_ports); |
| 3610 | return -EINVAL; |
| 3611 | } |
| 3612 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_READ) |
| 3613 | MLX5_SET(dctc, dctc, rre, 1); |
| 3614 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_WRITE) |
| 3615 | MLX5_SET(dctc, dctc, rwe, 1); |
| 3616 | if (attr->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC) { |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3617 | int atomic_mode; |
| 3618 | |
| 3619 | atomic_mode = get_atomic_mode(dev, MLX5_IB_QPT_DCT); |
| 3620 | if (atomic_mode < 0) |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3621 | return -EOPNOTSUPP; |
Yonatan Cohen | a60109d | 2018-10-10 09:25:16 +0300 | [diff] [blame] | 3622 | |
| 3623 | MLX5_SET(dctc, dctc, atomic_mode, atomic_mode); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3624 | MLX5_SET(dctc, dctc, rae, 1); |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3625 | } |
| 3626 | MLX5_SET(dctc, dctc, pkey_index, attr->pkey_index); |
| 3627 | MLX5_SET(dctc, dctc, port, attr->port_num); |
| 3628 | MLX5_SET(dctc, dctc, counter_set_id, dev->port[attr->port_num - 1].cnts.set_id); |
| 3629 | |
| 3630 | } else if (cur_state == IB_QPS_INIT && new_state == IB_QPS_RTR) { |
| 3631 | struct mlx5_ib_modify_qp_resp resp = {}; |
| 3632 | u32 min_resp_len = offsetof(typeof(resp), dctn) + |
| 3633 | sizeof(resp.dctn); |
| 3634 | |
| 3635 | if (udata->outlen < min_resp_len) |
| 3636 | return -EINVAL; |
| 3637 | resp.response_length = min_resp_len; |
| 3638 | |
| 3639 | required |= IB_QP_MIN_RNR_TIMER | IB_QP_AV | IB_QP_PATH_MTU; |
| 3640 | if (!is_valid_mask(attr_mask, required, 0)) |
| 3641 | return -EINVAL; |
| 3642 | MLX5_SET(dctc, dctc, min_rnr_nak, attr->min_rnr_timer); |
| 3643 | MLX5_SET(dctc, dctc, tclass, attr->ah_attr.grh.traffic_class); |
| 3644 | MLX5_SET(dctc, dctc, flow_label, attr->ah_attr.grh.flow_label); |
| 3645 | MLX5_SET(dctc, dctc, mtu, attr->path_mtu); |
| 3646 | MLX5_SET(dctc, dctc, my_addr_index, attr->ah_attr.grh.sgid_index); |
| 3647 | MLX5_SET(dctc, dctc, hop_limit, attr->ah_attr.grh.hop_limit); |
| 3648 | |
| 3649 | err = mlx5_core_create_dct(dev->mdev, &qp->dct.mdct, qp->dct.in, |
| 3650 | MLX5_ST_SZ_BYTES(create_dct_in)); |
| 3651 | if (err) |
| 3652 | return err; |
| 3653 | resp.dctn = qp->dct.mdct.mqp.qpn; |
| 3654 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 3655 | if (err) { |
| 3656 | mlx5_core_destroy_dct(dev->mdev, &qp->dct.mdct); |
| 3657 | return err; |
| 3658 | } |
| 3659 | } else { |
| 3660 | mlx5_ib_warn(dev, "Modify DCT: Invalid transition from %d to %d\n", cur_state, new_state); |
| 3661 | return -EINVAL; |
| 3662 | } |
| 3663 | if (err) |
| 3664 | qp->state = IB_QPS_ERR; |
| 3665 | else |
| 3666 | qp->state = new_state; |
| 3667 | return err; |
| 3668 | } |
| 3669 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3670 | int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, |
| 3671 | int attr_mask, struct ib_udata *udata) |
| 3672 | { |
| 3673 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 3674 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3675 | struct mlx5_ib_modify_qp ucmd = {}; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3676 | enum ib_qp_type qp_type; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3677 | enum ib_qp_state cur_state, new_state; |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3678 | size_t required_cmd_sz; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3679 | int err = -EINVAL; |
| 3680 | int port; |
| 3681 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 3682 | if (ibqp->rwq_ind_tbl) |
| 3683 | return -ENOSYS; |
| 3684 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3685 | if (udata && udata->inlen) { |
| 3686 | required_cmd_sz = offsetof(typeof(ucmd), reserved) + |
| 3687 | sizeof(ucmd.reserved); |
| 3688 | if (udata->inlen < required_cmd_sz) |
| 3689 | return -EINVAL; |
| 3690 | |
| 3691 | if (udata->inlen > sizeof(ucmd) && |
| 3692 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 3693 | udata->inlen - sizeof(ucmd))) |
| 3694 | return -EOPNOTSUPP; |
| 3695 | |
| 3696 | if (ib_copy_from_udata(&ucmd, udata, |
| 3697 | min(udata->inlen, sizeof(ucmd)))) |
| 3698 | return -EFAULT; |
| 3699 | |
| 3700 | if (ucmd.comp_mask || |
| 3701 | memchr_inv(&ucmd.reserved, 0, sizeof(ucmd.reserved)) || |
| 3702 | memchr_inv(&ucmd.burst_info.reserved, 0, |
| 3703 | sizeof(ucmd.burst_info.reserved))) |
| 3704 | return -EOPNOTSUPP; |
| 3705 | } |
| 3706 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3707 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 3708 | return mlx5_ib_gsi_modify_qp(ibqp, attr, attr_mask); |
| 3709 | |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3710 | if (ibqp->qp_type == IB_QPT_DRIVER) |
| 3711 | qp_type = qp->qp_sub_type; |
| 3712 | else |
| 3713 | qp_type = (unlikely(ibqp->qp_type == MLX5_IB_QPT_HW_GSI)) ? |
| 3714 | IB_QPT_GSI : ibqp->qp_type; |
| 3715 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 3716 | if (qp_type == MLX5_IB_QPT_DCT) |
| 3717 | return mlx5_ib_modify_dct(ibqp, attr, attr_mask, udata); |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 3718 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3719 | mutex_lock(&qp->mutex); |
| 3720 | |
| 3721 | cur_state = attr_mask & IB_QP_CUR_STATE ? attr->cur_qp_state : qp->state; |
| 3722 | new_state = attr_mask & IB_QP_STATE ? attr->qp_state : cur_state; |
| 3723 | |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3724 | if (!(cur_state == new_state && cur_state == IB_QPS_RESET)) { |
| 3725 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Achiad Shochat | 2811ba5 | 2015-12-23 18:47:24 +0200 | [diff] [blame] | 3726 | } |
| 3727 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 3728 | if (qp->flags & MLX5_IB_QP_UNDERLAY) { |
| 3729 | if (attr_mask & ~(IB_QP_STATE | IB_QP_CUR_STATE)) { |
| 3730 | mlx5_ib_dbg(dev, "invalid attr_mask 0x%x when underlay QP is used\n", |
| 3731 | attr_mask); |
| 3732 | goto out; |
| 3733 | } |
| 3734 | } else if (qp_type != MLX5_IB_QPT_REG_UMR && |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3735 | qp_type != MLX5_IB_QPT_DCI && |
Kamal Heib | d31131b | 2018-10-02 16:11:21 +0300 | [diff] [blame] | 3736 | !ib_modify_qp_is_ok(cur_state, new_state, qp_type, |
| 3737 | attr_mask)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3738 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 3739 | cur_state, new_state, ibqp->qp_type, attr_mask); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3740 | goto out; |
Moni Shoua | c32a4f2 | 2018-01-02 16:19:32 +0200 | [diff] [blame] | 3741 | } else if (qp_type == MLX5_IB_QPT_DCI && |
| 3742 | !modify_dci_qp_is_ok(cur_state, new_state, attr_mask)) { |
| 3743 | mlx5_ib_dbg(dev, "invalid QP state transition from %d to %d, qp_type %d, attr_mask 0x%x\n", |
| 3744 | cur_state, new_state, qp_type, attr_mask); |
| 3745 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3746 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3747 | |
| 3748 | if ((attr_mask & IB_QP_PORT) && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3749 | (attr->port_num == 0 || |
Daniel Jurgens | 508562d | 2018-01-04 17:25:34 +0200 | [diff] [blame] | 3750 | attr->port_num > dev->num_ports)) { |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3751 | mlx5_ib_dbg(dev, "invalid port number %d. number of ports is %d\n", |
| 3752 | attr->port_num, dev->num_ports); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3753 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3754 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3755 | |
| 3756 | if (attr_mask & IB_QP_PKEY_INDEX) { |
| 3757 | port = attr_mask & IB_QP_PORT ? attr->port_num : qp->port; |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3758 | if (attr->pkey_index >= |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3759 | dev->mdev->port_caps[port - 1].pkey_table_len) { |
| 3760 | mlx5_ib_dbg(dev, "invalid pkey index %d\n", |
| 3761 | attr->pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3762 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3763 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3764 | } |
| 3765 | |
| 3766 | if (attr_mask & IB_QP_MAX_QP_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3767 | attr->max_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3768 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_res_qp))) { |
| 3769 | mlx5_ib_dbg(dev, "invalid max_rd_atomic value %d\n", |
| 3770 | attr->max_rd_atomic); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3771 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3772 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3773 | |
| 3774 | if (attr_mask & IB_QP_MAX_DEST_RD_ATOMIC && |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 3775 | attr->max_dest_rd_atomic > |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3776 | (1 << MLX5_CAP_GEN(dev->mdev, log_max_ra_req_qp))) { |
| 3777 | mlx5_ib_dbg(dev, "invalid max_dest_rd_atomic value %d\n", |
| 3778 | attr->max_dest_rd_atomic); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3779 | goto out; |
Haggai Eran | 158abf8 | 2016-02-29 15:45:04 +0200 | [diff] [blame] | 3780 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3781 | |
| 3782 | if (cur_state == new_state && cur_state == IB_QPS_RESET) { |
| 3783 | err = 0; |
| 3784 | goto out; |
| 3785 | } |
| 3786 | |
Bodong Wang | 61147f3 | 2018-03-19 15:10:30 +0200 | [diff] [blame] | 3787 | err = __mlx5_ib_modify_qp(ibqp, attr, attr_mask, cur_state, |
| 3788 | new_state, &ucmd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3789 | |
| 3790 | out: |
| 3791 | mutex_unlock(&qp->mutex); |
| 3792 | return err; |
| 3793 | } |
| 3794 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3795 | static void _handle_post_send_edge(struct mlx5_ib_wq *sq, void **seg, |
| 3796 | u32 wqe_sz, void **cur_edge) |
| 3797 | { |
| 3798 | u32 idx; |
| 3799 | |
| 3800 | idx = (sq->cur_post + (wqe_sz >> 2)) & (sq->wqe_cnt - 1); |
| 3801 | *cur_edge = get_sq_edge(sq, idx); |
| 3802 | |
| 3803 | *seg = mlx5_frag_buf_get_wqe(&sq->fbc, idx); |
| 3804 | } |
| 3805 | |
| 3806 | /* handle_post_send_edge - Check if we get to SQ edge. If yes, update to the |
| 3807 | * next nearby edge and get new address translation for current WQE position. |
| 3808 | * @sq - SQ buffer. |
| 3809 | * @seg: Current WQE position (16B aligned). |
| 3810 | * @wqe_sz: Total current WQE size [16B]. |
| 3811 | * @cur_edge: Updated current edge. |
| 3812 | */ |
| 3813 | static inline void handle_post_send_edge(struct mlx5_ib_wq *sq, void **seg, |
| 3814 | u32 wqe_sz, void **cur_edge) |
| 3815 | { |
| 3816 | if (likely(*seg != *cur_edge)) |
| 3817 | return; |
| 3818 | |
| 3819 | _handle_post_send_edge(sq, seg, wqe_sz, cur_edge); |
| 3820 | } |
| 3821 | |
| 3822 | /* memcpy_send_wqe - copy data from src to WQE and update the relevant WQ's |
| 3823 | * pointers. At the end @seg is aligned to 16B regardless the copied size. |
| 3824 | * @sq - SQ buffer. |
| 3825 | * @cur_edge: Updated current edge. |
| 3826 | * @seg: Current WQE position (16B aligned). |
| 3827 | * @wqe_sz: Total current WQE size [16B]. |
| 3828 | * @src: Pointer to copy from. |
| 3829 | * @n: Number of bytes to copy. |
| 3830 | */ |
| 3831 | static inline void memcpy_send_wqe(struct mlx5_ib_wq *sq, void **cur_edge, |
| 3832 | void **seg, u32 *wqe_sz, const void *src, |
| 3833 | size_t n) |
| 3834 | { |
| 3835 | while (likely(n)) { |
| 3836 | size_t leftlen = *cur_edge - *seg; |
| 3837 | size_t copysz = min_t(size_t, leftlen, n); |
| 3838 | size_t stride; |
| 3839 | |
| 3840 | memcpy(*seg, src, copysz); |
| 3841 | |
| 3842 | n -= copysz; |
| 3843 | src += copysz; |
| 3844 | stride = !n ? ALIGN(copysz, 16) : copysz; |
| 3845 | *seg += stride; |
| 3846 | *wqe_sz += stride >> 4; |
| 3847 | handle_post_send_edge(sq, seg, *wqe_sz, cur_edge); |
| 3848 | } |
| 3849 | } |
| 3850 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3851 | static int mlx5_wq_overflow(struct mlx5_ib_wq *wq, int nreq, struct ib_cq *ib_cq) |
| 3852 | { |
| 3853 | struct mlx5_ib_cq *cq; |
| 3854 | unsigned cur; |
| 3855 | |
| 3856 | cur = wq->head - wq->tail; |
| 3857 | if (likely(cur + nreq < wq->max_post)) |
| 3858 | return 0; |
| 3859 | |
| 3860 | cq = to_mcq(ib_cq); |
| 3861 | spin_lock(&cq->lock); |
| 3862 | cur = wq->head - wq->tail; |
| 3863 | spin_unlock(&cq->lock); |
| 3864 | |
| 3865 | return cur + nreq >= wq->max_post; |
| 3866 | } |
| 3867 | |
| 3868 | static __always_inline void set_raddr_seg(struct mlx5_wqe_raddr_seg *rseg, |
| 3869 | u64 remote_addr, u32 rkey) |
| 3870 | { |
| 3871 | rseg->raddr = cpu_to_be64(remote_addr); |
| 3872 | rseg->rkey = cpu_to_be32(rkey); |
| 3873 | rseg->reserved = 0; |
| 3874 | } |
| 3875 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3876 | static void set_eth_seg(const struct ib_send_wr *wr, struct mlx5_ib_qp *qp, |
| 3877 | void **seg, int *size, void **cur_edge) |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3878 | { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3879 | struct mlx5_wqe_eth_seg *eseg = *seg; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3880 | |
| 3881 | memset(eseg, 0, sizeof(struct mlx5_wqe_eth_seg)); |
| 3882 | |
| 3883 | if (wr->send_flags & IB_SEND_IP_CSUM) |
| 3884 | eseg->cs_flags = MLX5_ETH_WQE_L3_CSUM | |
| 3885 | MLX5_ETH_WQE_L4_CSUM; |
| 3886 | |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3887 | if (wr->opcode == IB_WR_LSO) { |
| 3888 | struct ib_ud_wr *ud_wr = container_of(wr, struct ib_ud_wr, wr); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3889 | size_t left, copysz; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3890 | void *pdata = ud_wr->header; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3891 | size_t stride; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3892 | |
| 3893 | left = ud_wr->hlen; |
| 3894 | eseg->mss = cpu_to_be16(ud_wr->mss); |
Saeed Mahameed | 2b31f7a | 2016-11-28 18:04:50 +0200 | [diff] [blame] | 3895 | eseg->inline_hdr.sz = cpu_to_be16(left); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3896 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3897 | /* memcpy_send_wqe should get a 16B align address. Hence, we |
| 3898 | * first copy up to the current edge and then, if needed, |
| 3899 | * fall-through to memcpy_send_wqe. |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3900 | */ |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3901 | copysz = min_t(u64, *cur_edge - (void *)eseg->inline_hdr.start, |
| 3902 | left); |
| 3903 | memcpy(eseg->inline_hdr.start, pdata, copysz); |
| 3904 | stride = ALIGN(sizeof(struct mlx5_wqe_eth_seg) - |
| 3905 | sizeof(eseg->inline_hdr.start) + copysz, 16); |
| 3906 | *size += stride / 16; |
| 3907 | *seg += stride; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3908 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3909 | if (copysz < left) { |
| 3910 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3911 | left -= copysz; |
| 3912 | pdata += copysz; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3913 | memcpy_send_wqe(&qp->sq, cur_edge, seg, size, pdata, |
| 3914 | left); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3915 | } |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3916 | |
| 3917 | return; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3918 | } |
| 3919 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 3920 | *seg += sizeof(struct mlx5_wqe_eth_seg); |
| 3921 | *size += sizeof(struct mlx5_wqe_eth_seg) / 16; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 3922 | } |
| 3923 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3924 | static void set_datagram_seg(struct mlx5_wqe_datagram_seg *dseg, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 3925 | const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3926 | { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 3927 | memcpy(&dseg->av, &to_mah(ud_wr(wr)->ah)->av, sizeof(struct mlx5_av)); |
| 3928 | dseg->av.dqp_dct = cpu_to_be32(ud_wr(wr)->remote_qpn | MLX5_EXTENDED_UD_AV); |
| 3929 | dseg->av.key.qkey.qkey = cpu_to_be32(ud_wr(wr)->remote_qkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | static void set_data_ptr_seg(struct mlx5_wqe_data_seg *dseg, struct ib_sge *sg) |
| 3933 | { |
| 3934 | dseg->byte_count = cpu_to_be32(sg->length); |
| 3935 | dseg->lkey = cpu_to_be32(sg->lkey); |
| 3936 | dseg->addr = cpu_to_be64(sg->addr); |
| 3937 | } |
| 3938 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 3939 | static u64 get_xlt_octo(u64 bytes) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3940 | { |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 3941 | return ALIGN(bytes, MLX5_IB_UMR_XLT_ALIGNMENT) / |
| 3942 | MLX5_IB_UMR_OCTOWORD; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | static __be64 frwr_mkey_mask(void) |
| 3946 | { |
| 3947 | u64 result; |
| 3948 | |
| 3949 | result = MLX5_MKEY_MASK_LEN | |
| 3950 | MLX5_MKEY_MASK_PAGE_SIZE | |
| 3951 | MLX5_MKEY_MASK_START_ADDR | |
| 3952 | MLX5_MKEY_MASK_EN_RINVAL | |
| 3953 | MLX5_MKEY_MASK_KEY | |
| 3954 | MLX5_MKEY_MASK_LR | |
| 3955 | MLX5_MKEY_MASK_LW | |
| 3956 | MLX5_MKEY_MASK_RR | |
| 3957 | MLX5_MKEY_MASK_RW | |
| 3958 | MLX5_MKEY_MASK_A | |
| 3959 | MLX5_MKEY_MASK_SMALL_FENCE | |
| 3960 | MLX5_MKEY_MASK_FREE; |
| 3961 | |
| 3962 | return cpu_to_be64(result); |
| 3963 | } |
| 3964 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 3965 | static __be64 sig_mkey_mask(void) |
| 3966 | { |
| 3967 | u64 result; |
| 3968 | |
| 3969 | result = MLX5_MKEY_MASK_LEN | |
| 3970 | MLX5_MKEY_MASK_PAGE_SIZE | |
| 3971 | MLX5_MKEY_MASK_START_ADDR | |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 3972 | MLX5_MKEY_MASK_EN_SIGERR | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 3973 | MLX5_MKEY_MASK_EN_RINVAL | |
| 3974 | MLX5_MKEY_MASK_KEY | |
| 3975 | MLX5_MKEY_MASK_LR | |
| 3976 | MLX5_MKEY_MASK_LW | |
| 3977 | MLX5_MKEY_MASK_RR | |
| 3978 | MLX5_MKEY_MASK_RW | |
| 3979 | MLX5_MKEY_MASK_SMALL_FENCE | |
| 3980 | MLX5_MKEY_MASK_FREE | |
| 3981 | MLX5_MKEY_MASK_BSF_EN; |
| 3982 | |
| 3983 | return cpu_to_be64(result); |
| 3984 | } |
| 3985 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 3986 | static void set_reg_umr_seg(struct mlx5_wqe_umr_ctrl_seg *umr, |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 3987 | struct mlx5_ib_mr *mr, bool umr_inline) |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 3988 | { |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 3989 | int size = mr->ndescs * mr->desc_size; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 3990 | |
| 3991 | memset(umr, 0, sizeof(*umr)); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 3992 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 3993 | umr->flags = MLX5_UMR_CHECK_NOT_FREE; |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 3994 | if (umr_inline) |
| 3995 | umr->flags |= MLX5_UMR_INLINE; |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 3996 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(size)); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 3997 | umr->mkey_mask = frwr_mkey_mask(); |
| 3998 | } |
| 3999 | |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4000 | static void set_linv_umr_seg(struct mlx5_wqe_umr_ctrl_seg *umr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4001 | { |
| 4002 | memset(umr, 0, sizeof(*umr)); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4003 | umr->mkey_mask = cpu_to_be64(MLX5_MKEY_MASK_FREE); |
Max Gurtovoy | 2d22158 | 2016-10-27 16:36:36 +0300 | [diff] [blame] | 4004 | umr->flags = MLX5_UMR_INLINE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4005 | } |
| 4006 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4007 | static __be64 get_umr_enable_mr_mask(void) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4008 | { |
| 4009 | u64 result; |
| 4010 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4011 | result = MLX5_MKEY_MASK_KEY | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4012 | MLX5_MKEY_MASK_FREE; |
| 4013 | |
| 4014 | return cpu_to_be64(result); |
| 4015 | } |
| 4016 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4017 | static __be64 get_umr_disable_mr_mask(void) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4018 | { |
| 4019 | u64 result; |
| 4020 | |
| 4021 | result = MLX5_MKEY_MASK_FREE; |
| 4022 | |
| 4023 | return cpu_to_be64(result); |
| 4024 | } |
| 4025 | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4026 | static __be64 get_umr_update_translation_mask(void) |
| 4027 | { |
| 4028 | u64 result; |
| 4029 | |
| 4030 | result = MLX5_MKEY_MASK_LEN | |
| 4031 | MLX5_MKEY_MASK_PAGE_SIZE | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4032 | MLX5_MKEY_MASK_START_ADDR; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4033 | |
| 4034 | return cpu_to_be64(result); |
| 4035 | } |
| 4036 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4037 | static __be64 get_umr_update_access_mask(int atomic) |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4038 | { |
| 4039 | u64 result; |
| 4040 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4041 | result = MLX5_MKEY_MASK_LR | |
| 4042 | MLX5_MKEY_MASK_LW | |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4043 | MLX5_MKEY_MASK_RR | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4044 | MLX5_MKEY_MASK_RW; |
| 4045 | |
| 4046 | if (atomic) |
| 4047 | result |= MLX5_MKEY_MASK_A; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4048 | |
| 4049 | return cpu_to_be64(result); |
| 4050 | } |
| 4051 | |
| 4052 | static __be64 get_umr_update_pd_mask(void) |
| 4053 | { |
| 4054 | u64 result; |
| 4055 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4056 | result = MLX5_MKEY_MASK_PD; |
Noa Osherovich | 56e11d6 | 2016-02-29 16:46:51 +0200 | [diff] [blame] | 4057 | |
| 4058 | return cpu_to_be64(result); |
| 4059 | } |
| 4060 | |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 4061 | static int umr_check_mkey_mask(struct mlx5_ib_dev *dev, u64 mask) |
| 4062 | { |
| 4063 | if ((mask & MLX5_MKEY_MASK_PAGE_SIZE && |
| 4064 | MLX5_CAP_GEN(dev->mdev, umr_modify_entity_size_disabled)) || |
| 4065 | (mask & MLX5_MKEY_MASK_A && |
| 4066 | MLX5_CAP_GEN(dev->mdev, umr_modify_atomic_disabled))) |
| 4067 | return -EPERM; |
| 4068 | return 0; |
| 4069 | } |
| 4070 | |
| 4071 | static int set_reg_umr_segment(struct mlx5_ib_dev *dev, |
| 4072 | struct mlx5_wqe_umr_ctrl_seg *umr, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4073 | const struct ib_send_wr *wr, int atomic) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4074 | { |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4075 | const struct mlx5_umr_wr *umrwr = umr_wr(wr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4076 | |
| 4077 | memset(umr, 0, sizeof(*umr)); |
| 4078 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4079 | if (wr->send_flags & MLX5_IB_SEND_UMR_FAIL_IF_FREE) |
| 4080 | umr->flags = MLX5_UMR_CHECK_FREE; /* fail if free */ |
| 4081 | else |
| 4082 | umr->flags = MLX5_UMR_CHECK_NOT_FREE; /* fail if not free */ |
| 4083 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4084 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(umrwr->xlt_size)); |
| 4085 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_XLT) { |
| 4086 | u64 offset = get_xlt_octo(umrwr->offset); |
| 4087 | |
| 4088 | umr->xlt_offset = cpu_to_be16(offset & 0xffff); |
| 4089 | umr->xlt_offset_47_16 = cpu_to_be32(offset >> 16); |
| 4090 | umr->flags |= MLX5_UMR_TRANSLATION_OFFSET_EN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4091 | } |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4092 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_TRANSLATION) |
| 4093 | umr->mkey_mask |= get_umr_update_translation_mask(); |
| 4094 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_PD_ACCESS) { |
| 4095 | umr->mkey_mask |= get_umr_update_access_mask(atomic); |
| 4096 | umr->mkey_mask |= get_umr_update_pd_mask(); |
| 4097 | } |
| 4098 | if (wr->send_flags & MLX5_IB_SEND_UMR_ENABLE_MR) |
| 4099 | umr->mkey_mask |= get_umr_enable_mr_mask(); |
| 4100 | if (wr->send_flags & MLX5_IB_SEND_UMR_DISABLE_MR) |
| 4101 | umr->mkey_mask |= get_umr_disable_mr_mask(); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4102 | |
| 4103 | if (!wr->num_sge) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4104 | umr->flags |= MLX5_UMR_INLINE; |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 4105 | |
| 4106 | return umr_check_mkey_mask(dev, be64_to_cpu(umr->mkey_mask)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4107 | } |
| 4108 | |
| 4109 | static u8 get_umr_flags(int acc) |
| 4110 | { |
| 4111 | return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC : 0) | |
| 4112 | (acc & IB_ACCESS_REMOTE_WRITE ? MLX5_PERM_REMOTE_WRITE : 0) | |
| 4113 | (acc & IB_ACCESS_REMOTE_READ ? MLX5_PERM_REMOTE_READ : 0) | |
| 4114 | (acc & IB_ACCESS_LOCAL_WRITE ? MLX5_PERM_LOCAL_WRITE : 0) | |
Sagi Grimberg | 2ac4593 | 2014-02-23 14:19:09 +0200 | [diff] [blame] | 4115 | MLX5_PERM_LOCAL_READ | MLX5_PERM_UMR_EN; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4116 | } |
| 4117 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4118 | static void set_reg_mkey_seg(struct mlx5_mkey_seg *seg, |
| 4119 | struct mlx5_ib_mr *mr, |
| 4120 | u32 key, int access) |
| 4121 | { |
| 4122 | int ndescs = ALIGN(mr->ndescs, 8) >> 1; |
| 4123 | |
| 4124 | memset(seg, 0, sizeof(*seg)); |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4125 | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 4126 | if (mr->access_mode == MLX5_MKC_ACCESS_MODE_MTT) |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4127 | seg->log2_page_size = ilog2(mr->ibmr.page_size); |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 4128 | else if (mr->access_mode == MLX5_MKC_ACCESS_MODE_KLMS) |
Sagi Grimberg | b005d31 | 2016-02-29 19:07:33 +0200 | [diff] [blame] | 4129 | /* KLMs take twice the size of MTTs */ |
| 4130 | ndescs *= 2; |
| 4131 | |
| 4132 | seg->flags = get_umr_flags(access) | mr->access_mode; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4133 | seg->qpn_mkey7_0 = cpu_to_be32((key & 0xff) | 0xffffff00); |
| 4134 | seg->flags_pd = cpu_to_be32(MLX5_MKEY_REMOTE_INVAL); |
| 4135 | seg->start_addr = cpu_to_be64(mr->ibmr.iova); |
| 4136 | seg->len = cpu_to_be64(mr->ibmr.length); |
| 4137 | seg->xlt_oct_size = cpu_to_be32(ndescs); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4138 | } |
| 4139 | |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4140 | static void set_linv_mkey_seg(struct mlx5_mkey_seg *seg) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4141 | { |
| 4142 | memset(seg, 0, sizeof(*seg)); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4143 | seg->status = MLX5_MKEY_STATUS_FREE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4144 | } |
| 4145 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4146 | static void set_reg_mkey_segment(struct mlx5_mkey_seg *seg, |
| 4147 | const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4148 | { |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4149 | const struct mlx5_umr_wr *umrwr = umr_wr(wr); |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4150 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4151 | memset(seg, 0, sizeof(*seg)); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4152 | if (wr->send_flags & MLX5_IB_SEND_UMR_DISABLE_MR) |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4153 | seg->status = MLX5_MKEY_STATUS_FREE; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4154 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4155 | seg->flags = convert_access(umrwr->access_flags); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4156 | if (umrwr->pd) |
| 4157 | seg->flags_pd = cpu_to_be32(to_mpd(umrwr->pd)->pdn); |
| 4158 | if (wr->send_flags & MLX5_IB_SEND_UMR_UPDATE_TRANSLATION && |
| 4159 | !umrwr->length) |
| 4160 | seg->flags_pd |= cpu_to_be32(MLX5_MKEY_LEN64); |
| 4161 | |
| 4162 | seg->start_addr = cpu_to_be64(umrwr->virt_addr); |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4163 | seg->len = cpu_to_be64(umrwr->length); |
| 4164 | seg->log2_page_size = umrwr->page_shift; |
Eli Cohen | 746b558 | 2013-10-23 09:53:14 +0300 | [diff] [blame] | 4165 | seg->qpn_mkey7_0 = cpu_to_be32(0xffffff00 | |
Haggai Eran | 968e78d | 2014-12-11 17:04:11 +0200 | [diff] [blame] | 4166 | mlx5_mkey_variant(umrwr->mkey)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4167 | } |
| 4168 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4169 | static void set_reg_data_seg(struct mlx5_wqe_data_seg *dseg, |
| 4170 | struct mlx5_ib_mr *mr, |
| 4171 | struct mlx5_ib_pd *pd) |
| 4172 | { |
| 4173 | int bcount = mr->desc_size * mr->ndescs; |
| 4174 | |
| 4175 | dseg->addr = cpu_to_be64(mr->desc_map); |
| 4176 | dseg->byte_count = cpu_to_be32(ALIGN(bcount, 64)); |
| 4177 | dseg->lkey = cpu_to_be32(pd->ibpd.local_dma_lkey); |
| 4178 | } |
| 4179 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4180 | static __be32 send_ieth(const struct ib_send_wr *wr) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4181 | { |
| 4182 | switch (wr->opcode) { |
| 4183 | case IB_WR_SEND_WITH_IMM: |
| 4184 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 4185 | return wr->ex.imm_data; |
| 4186 | |
| 4187 | case IB_WR_SEND_WITH_INV: |
| 4188 | return cpu_to_be32(wr->ex.invalidate_rkey); |
| 4189 | |
| 4190 | default: |
| 4191 | return 0; |
| 4192 | } |
| 4193 | } |
| 4194 | |
| 4195 | static u8 calc_sig(void *wqe, int size) |
| 4196 | { |
| 4197 | u8 *p = wqe; |
| 4198 | u8 res = 0; |
| 4199 | int i; |
| 4200 | |
| 4201 | for (i = 0; i < size; i++) |
| 4202 | res ^= p[i]; |
| 4203 | |
| 4204 | return ~res; |
| 4205 | } |
| 4206 | |
| 4207 | static u8 wq_sig(void *wqe) |
| 4208 | { |
| 4209 | return calc_sig(wqe, (*((u8 *)wqe + 8) & 0x3f) << 4); |
| 4210 | } |
| 4211 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4212 | static int set_data_inl_seg(struct mlx5_ib_qp *qp, const struct ib_send_wr *wr, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4213 | void **wqe, int *wqe_sz, void **cur_edge) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4214 | { |
| 4215 | struct mlx5_wqe_inline_seg *seg; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4216 | size_t offset; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4217 | int inl = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4218 | int i; |
| 4219 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4220 | seg = *wqe; |
| 4221 | *wqe += sizeof(*seg); |
| 4222 | offset = sizeof(*seg); |
| 4223 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4224 | for (i = 0; i < wr->num_sge; i++) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4225 | size_t len = wr->sg_list[i].length; |
| 4226 | void *addr = (void *)(unsigned long)(wr->sg_list[i].addr); |
| 4227 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4228 | inl += len; |
| 4229 | |
| 4230 | if (unlikely(inl > qp->max_inline_data)) |
| 4231 | return -ENOMEM; |
| 4232 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4233 | while (likely(len)) { |
| 4234 | size_t leftlen; |
| 4235 | size_t copysz; |
| 4236 | |
| 4237 | handle_post_send_edge(&qp->sq, wqe, |
| 4238 | *wqe_sz + (offset >> 4), |
| 4239 | cur_edge); |
| 4240 | |
| 4241 | leftlen = *cur_edge - *wqe; |
| 4242 | copysz = min_t(size_t, leftlen, len); |
| 4243 | |
| 4244 | memcpy(*wqe, addr, copysz); |
| 4245 | len -= copysz; |
| 4246 | addr += copysz; |
| 4247 | *wqe += copysz; |
| 4248 | offset += copysz; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4249 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | seg->byte_count = cpu_to_be32(inl | MLX5_INLINE_SEG); |
| 4253 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4254 | *wqe_sz += ALIGN(inl + sizeof(seg->byte_count), 16) / 16; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4255 | |
| 4256 | return 0; |
| 4257 | } |
| 4258 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4259 | static u16 prot_field_size(enum ib_signature_type type) |
| 4260 | { |
| 4261 | switch (type) { |
| 4262 | case IB_SIG_TYPE_T10_DIF: |
| 4263 | return MLX5_DIF_SIZE; |
| 4264 | default: |
| 4265 | return 0; |
| 4266 | } |
| 4267 | } |
| 4268 | |
| 4269 | static u8 bs_selector(int block_size) |
| 4270 | { |
| 4271 | switch (block_size) { |
| 4272 | case 512: return 0x1; |
| 4273 | case 520: return 0x2; |
| 4274 | case 4096: return 0x3; |
| 4275 | case 4160: return 0x4; |
| 4276 | case 1073741824: return 0x5; |
| 4277 | default: return 0; |
| 4278 | } |
| 4279 | } |
| 4280 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4281 | static void mlx5_fill_inl_bsf(struct ib_sig_domain *domain, |
| 4282 | struct mlx5_bsf_inl *inl) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4283 | { |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4284 | /* Valid inline section and allow BSF refresh */ |
| 4285 | inl->vld_refresh = cpu_to_be16(MLX5_BSF_INL_VALID | |
| 4286 | MLX5_BSF_REFRESH_DIF); |
| 4287 | inl->dif_apptag = cpu_to_be16(domain->sig.dif.app_tag); |
| 4288 | inl->dif_reftag = cpu_to_be32(domain->sig.dif.ref_tag); |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4289 | /* repeating block */ |
| 4290 | inl->rp_inv_seed = MLX5_BSF_REPEAT_BLOCK; |
| 4291 | inl->sig_type = domain->sig.dif.bg_type == IB_T10DIF_CRC ? |
| 4292 | MLX5_DIF_CRC : MLX5_DIF_IPCS; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4293 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4294 | if (domain->sig.dif.ref_remap) |
| 4295 | inl->dif_inc_ref_guard_check |= MLX5_BSF_INC_REFTAG; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4296 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4297 | if (domain->sig.dif.app_escape) { |
| 4298 | if (domain->sig.dif.ref_escape) |
| 4299 | inl->dif_inc_ref_guard_check |= MLX5_BSF_APPREF_ESCAPE; |
| 4300 | else |
| 4301 | inl->dif_inc_ref_guard_check |= MLX5_BSF_APPTAG_ESCAPE; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4302 | } |
| 4303 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4304 | inl->dif_app_bitmask_check = |
| 4305 | cpu_to_be16(domain->sig.dif.apptag_check_mask); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | static int mlx5_set_bsf(struct ib_mr *sig_mr, |
| 4309 | struct ib_sig_attrs *sig_attrs, |
| 4310 | struct mlx5_bsf *bsf, u32 data_size) |
| 4311 | { |
| 4312 | struct mlx5_core_sig_ctx *msig = to_mmr(sig_mr)->sig; |
| 4313 | struct mlx5_bsf_basic *basic = &bsf->basic; |
| 4314 | struct ib_sig_domain *mem = &sig_attrs->mem; |
| 4315 | struct ib_sig_domain *wire = &sig_attrs->wire; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4316 | |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4317 | memset(bsf, 0, sizeof(*bsf)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4318 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4319 | /* Basic + Extended + Inline */ |
| 4320 | basic->bsf_size_sbs = 1 << 7; |
| 4321 | /* Input domain check byte mask */ |
| 4322 | basic->check_byte_mask = sig_attrs->check_mask; |
| 4323 | basic->raw_data_size = cpu_to_be32(data_size); |
| 4324 | |
| 4325 | /* Memory domain */ |
| 4326 | switch (sig_attrs->mem.sig_type) { |
| 4327 | case IB_SIG_TYPE_NONE: |
| 4328 | break; |
| 4329 | case IB_SIG_TYPE_T10_DIF: |
| 4330 | basic->mem.bs_selector = bs_selector(mem->sig.dif.pi_interval); |
| 4331 | basic->m_bfs_psv = cpu_to_be32(msig->psv_memory.psv_idx); |
| 4332 | mlx5_fill_inl_bsf(mem, &bsf->m_inl); |
| 4333 | break; |
| 4334 | default: |
| 4335 | return -EINVAL; |
| 4336 | } |
| 4337 | |
| 4338 | /* Wire domain */ |
| 4339 | switch (sig_attrs->wire.sig_type) { |
| 4340 | case IB_SIG_TYPE_NONE: |
| 4341 | break; |
| 4342 | case IB_SIG_TYPE_T10_DIF: |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4343 | if (mem->sig.dif.pi_interval == wire->sig.dif.pi_interval && |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4344 | mem->sig_type == wire->sig_type) { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4345 | /* Same block structure */ |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4346 | basic->bsf_size_sbs |= 1 << 4; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4347 | if (mem->sig.dif.bg_type == wire->sig.dif.bg_type) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4348 | basic->wire.copy_byte_mask |= MLX5_CPY_GRD_MASK; |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4349 | if (mem->sig.dif.app_tag == wire->sig.dif.app_tag) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4350 | basic->wire.copy_byte_mask |= MLX5_CPY_APP_MASK; |
Sagi Grimberg | c7f44fb | 2014-05-18 18:32:40 +0300 | [diff] [blame] | 4351 | if (mem->sig.dif.ref_tag == wire->sig.dif.ref_tag) |
Sagi Grimberg | fd22f78 | 2014-08-13 19:54:29 +0300 | [diff] [blame] | 4352 | basic->wire.copy_byte_mask |= MLX5_CPY_REF_MASK; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4353 | } else |
| 4354 | basic->wire.bs_selector = bs_selector(wire->sig.dif.pi_interval); |
| 4355 | |
Sagi Grimberg | 142537f | 2014-08-13 19:54:32 +0300 | [diff] [blame] | 4356 | basic->w_bfs_psv = cpu_to_be32(msig->psv_wire.psv_idx); |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4357 | mlx5_fill_inl_bsf(wire, &bsf->w_inl); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4358 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4359 | default: |
| 4360 | return -EINVAL; |
| 4361 | } |
| 4362 | |
| 4363 | return 0; |
| 4364 | } |
| 4365 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4366 | static int set_sig_data_segment(const struct ib_sig_handover_wr *wr, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4367 | struct mlx5_ib_qp *qp, void **seg, |
| 4368 | int *size, void **cur_edge) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4369 | { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4370 | struct ib_sig_attrs *sig_attrs = wr->sig_attrs; |
| 4371 | struct ib_mr *sig_mr = wr->sig_mr; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4372 | struct mlx5_bsf *bsf; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4373 | u32 data_len = wr->wr.sg_list->length; |
| 4374 | u32 data_key = wr->wr.sg_list->lkey; |
| 4375 | u64 data_va = wr->wr.sg_list->addr; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4376 | int ret; |
| 4377 | int wqe_size; |
| 4378 | |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4379 | if (!wr->prot || |
| 4380 | (data_key == wr->prot->lkey && |
| 4381 | data_va == wr->prot->addr && |
| 4382 | data_len == wr->prot->length)) { |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4383 | /** |
| 4384 | * Source domain doesn't contain signature information |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4385 | * or data and protection are interleaved in memory. |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4386 | * So need construct: |
| 4387 | * ------------------ |
| 4388 | * | data_klm | |
| 4389 | * ------------------ |
| 4390 | * | BSF | |
| 4391 | * ------------------ |
| 4392 | **/ |
| 4393 | struct mlx5_klm *data_klm = *seg; |
| 4394 | |
| 4395 | data_klm->bcount = cpu_to_be32(data_len); |
| 4396 | data_klm->key = cpu_to_be32(data_key); |
| 4397 | data_klm->va = cpu_to_be64(data_va); |
| 4398 | wqe_size = ALIGN(sizeof(*data_klm), 64); |
| 4399 | } else { |
| 4400 | /** |
| 4401 | * Source domain contains signature information |
| 4402 | * So need construct a strided block format: |
| 4403 | * --------------------------- |
| 4404 | * | stride_block_ctrl | |
| 4405 | * --------------------------- |
| 4406 | * | data_klm | |
| 4407 | * --------------------------- |
| 4408 | * | prot_klm | |
| 4409 | * --------------------------- |
| 4410 | * | BSF | |
| 4411 | * --------------------------- |
| 4412 | **/ |
| 4413 | struct mlx5_stride_block_ctrl_seg *sblock_ctrl; |
| 4414 | struct mlx5_stride_block_entry *data_sentry; |
| 4415 | struct mlx5_stride_block_entry *prot_sentry; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4416 | u32 prot_key = wr->prot->lkey; |
| 4417 | u64 prot_va = wr->prot->addr; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4418 | u16 block_size = sig_attrs->mem.sig.dif.pi_interval; |
| 4419 | int prot_size; |
| 4420 | |
| 4421 | sblock_ctrl = *seg; |
| 4422 | data_sentry = (void *)sblock_ctrl + sizeof(*sblock_ctrl); |
| 4423 | prot_sentry = (void *)data_sentry + sizeof(*data_sentry); |
| 4424 | |
| 4425 | prot_size = prot_field_size(sig_attrs->mem.sig_type); |
| 4426 | if (!prot_size) { |
| 4427 | pr_err("Bad block size given: %u\n", block_size); |
| 4428 | return -EINVAL; |
| 4429 | } |
| 4430 | sblock_ctrl->bcount_per_cycle = cpu_to_be32(block_size + |
| 4431 | prot_size); |
| 4432 | sblock_ctrl->op = cpu_to_be32(MLX5_STRIDE_BLOCK_OP); |
| 4433 | sblock_ctrl->repeat_count = cpu_to_be32(data_len / block_size); |
| 4434 | sblock_ctrl->num_entries = cpu_to_be16(2); |
| 4435 | |
| 4436 | data_sentry->bcount = cpu_to_be16(block_size); |
| 4437 | data_sentry->key = cpu_to_be32(data_key); |
| 4438 | data_sentry->va = cpu_to_be64(data_va); |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4439 | data_sentry->stride = cpu_to_be16(block_size); |
| 4440 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4441 | prot_sentry->bcount = cpu_to_be16(prot_size); |
| 4442 | prot_sentry->key = cpu_to_be32(prot_key); |
Sagi Grimberg | 5c273b1 | 2014-05-18 18:32:39 +0300 | [diff] [blame] | 4443 | prot_sentry->va = cpu_to_be64(prot_va); |
| 4444 | prot_sentry->stride = cpu_to_be16(prot_size); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4445 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4446 | wqe_size = ALIGN(sizeof(*sblock_ctrl) + sizeof(*data_sentry) + |
| 4447 | sizeof(*prot_sentry), 64); |
| 4448 | } |
| 4449 | |
| 4450 | *seg += wqe_size; |
| 4451 | *size += wqe_size / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4452 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4453 | |
| 4454 | bsf = *seg; |
| 4455 | ret = mlx5_set_bsf(sig_mr, sig_attrs, bsf, data_len); |
| 4456 | if (ret) |
| 4457 | return -EINVAL; |
| 4458 | |
| 4459 | *seg += sizeof(*bsf); |
| 4460 | *size += sizeof(*bsf) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4461 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4462 | |
| 4463 | return 0; |
| 4464 | } |
| 4465 | |
| 4466 | static void set_sig_mkey_segment(struct mlx5_mkey_seg *seg, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4467 | const struct ib_sig_handover_wr *wr, u32 size, |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4468 | u32 length, u32 pdn) |
| 4469 | { |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4470 | struct ib_mr *sig_mr = wr->sig_mr; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4471 | u32 sig_key = sig_mr->rkey; |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4472 | u8 sigerr = to_mmr(sig_mr)->sig->sigerr_count & 1; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4473 | |
| 4474 | memset(seg, 0, sizeof(*seg)); |
| 4475 | |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4476 | seg->flags = get_umr_flags(wr->access_flags) | |
Saeed Mahameed | ec22eb5 | 2016-07-16 06:28:36 +0300 | [diff] [blame] | 4477 | MLX5_MKC_ACCESS_MODE_KLMS; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4478 | seg->qpn_mkey7_0 = cpu_to_be32((sig_key & 0xff) | 0xffffff00); |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4479 | seg->flags_pd = cpu_to_be32(MLX5_MKEY_REMOTE_INVAL | sigerr << 26 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4480 | MLX5_MKEY_BSF_EN | pdn); |
| 4481 | seg->len = cpu_to_be64(length); |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4482 | seg->xlt_oct_size = cpu_to_be32(get_xlt_octo(size)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4483 | seg->bsfs_octo_size = cpu_to_be32(MLX5_MKEY_BSF_OCTO_SIZE); |
| 4484 | } |
| 4485 | |
| 4486 | static void set_sig_umr_segment(struct mlx5_wqe_umr_ctrl_seg *umr, |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4487 | u32 size) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4488 | { |
| 4489 | memset(umr, 0, sizeof(*umr)); |
| 4490 | |
| 4491 | umr->flags = MLX5_FLAGS_INLINE | MLX5_FLAGS_CHECK_FREE; |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4492 | umr->xlt_octowords = cpu_to_be16(get_xlt_octo(size)); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4493 | umr->bsf_octowords = cpu_to_be16(MLX5_MKEY_BSF_OCTO_SIZE); |
| 4494 | umr->mkey_mask = sig_mkey_mask(); |
| 4495 | } |
| 4496 | |
| 4497 | |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4498 | static int set_sig_umr_wr(const struct ib_send_wr *send_wr, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4499 | struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4500 | void **cur_edge) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4501 | { |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4502 | const struct ib_sig_handover_wr *wr = sig_handover_wr(send_wr); |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4503 | struct mlx5_ib_mr *sig_mr = to_mmr(wr->sig_mr); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4504 | u32 pdn = get_pd(qp)->pdn; |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4505 | u32 xlt_size; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4506 | int region_len, ret; |
| 4507 | |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4508 | if (unlikely(wr->wr.num_sge != 1) || |
| 4509 | unlikely(wr->access_flags & IB_ACCESS_REMOTE_ATOMIC) || |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4510 | unlikely(!sig_mr->sig) || unlikely(!qp->signature_en) || |
| 4511 | unlikely(!sig_mr->sig->sig_status_checked)) |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4512 | return -EINVAL; |
| 4513 | |
| 4514 | /* length of the protected region, data + protection */ |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4515 | region_len = wr->wr.sg_list->length; |
| 4516 | if (wr->prot && |
| 4517 | (wr->prot->lkey != wr->wr.sg_list->lkey || |
| 4518 | wr->prot->addr != wr->wr.sg_list->addr || |
| 4519 | wr->prot->length != wr->wr.sg_list->length)) |
| 4520 | region_len += wr->prot->length; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4521 | |
| 4522 | /** |
| 4523 | * KLM octoword size - if protection was provided |
| 4524 | * then we use strided block format (3 octowords), |
| 4525 | * else we use single KLM (1 octoword) |
| 4526 | **/ |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4527 | xlt_size = wr->prot ? 0x30 : sizeof(struct mlx5_klm); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4528 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4529 | set_sig_umr_segment(*seg, xlt_size); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4530 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4531 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4532 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4533 | |
Artemy Kovalyov | 3161625 | 2017-01-02 11:37:42 +0200 | [diff] [blame] | 4534 | set_sig_mkey_segment(*seg, wr, xlt_size, region_len, pdn); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4535 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4536 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4537 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4538 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4539 | ret = set_sig_data_segment(wr, qp, seg, size, cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4540 | if (ret) |
| 4541 | return ret; |
| 4542 | |
Sagi Grimberg | d5436ba | 2014-02-23 14:19:12 +0200 | [diff] [blame] | 4543 | sig_mr->sig->sig_status_checked = false; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4544 | return 0; |
| 4545 | } |
| 4546 | |
| 4547 | static int set_psv_wr(struct ib_sig_domain *domain, |
| 4548 | u32 psv_idx, void **seg, int *size) |
| 4549 | { |
| 4550 | struct mlx5_seg_set_psv *psv_seg = *seg; |
| 4551 | |
| 4552 | memset(psv_seg, 0, sizeof(*psv_seg)); |
| 4553 | psv_seg->psv_num = cpu_to_be32(psv_idx); |
| 4554 | switch (domain->sig_type) { |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4555 | case IB_SIG_TYPE_NONE: |
| 4556 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4557 | case IB_SIG_TYPE_T10_DIF: |
| 4558 | psv_seg->transient_sig = cpu_to_be32(domain->sig.dif.bg << 16 | |
| 4559 | domain->sig.dif.app_tag); |
| 4560 | psv_seg->ref_tag = cpu_to_be32(domain->sig.dif.ref_tag); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4561 | break; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4562 | default: |
Leon Romanovsky | 12bbf1e | 2017-01-18 14:10:31 +0200 | [diff] [blame] | 4563 | pr_err("Bad signature type (%d) is given.\n", |
| 4564 | domain->sig_type); |
| 4565 | return -EINVAL; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4566 | } |
| 4567 | |
Sagi Grimberg | 78eda2b | 2014-08-13 19:54:35 +0300 | [diff] [blame] | 4568 | *seg += sizeof(*psv_seg); |
| 4569 | *size += sizeof(*psv_seg) / 16; |
| 4570 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4571 | return 0; |
| 4572 | } |
| 4573 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4574 | static int set_reg_wr(struct mlx5_ib_qp *qp, |
Bart Van Assche | f696bf6 | 2018-07-18 09:25:14 -0700 | [diff] [blame] | 4575 | const struct ib_reg_wr *wr, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4576 | void **seg, int *size, void **cur_edge) |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4577 | { |
| 4578 | struct mlx5_ib_mr *mr = to_mmr(wr->mr); |
| 4579 | struct mlx5_ib_pd *pd = to_mpd(qp->ibqp.pd); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4580 | size_t mr_list_size = mr->ndescs * mr->desc_size; |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4581 | bool umr_inline = mr_list_size <= MLX5_IB_SQ_UMR_INLINE_THRESHOLD; |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4582 | |
| 4583 | if (unlikely(wr->wr.send_flags & IB_SEND_INLINE)) { |
| 4584 | mlx5_ib_warn(to_mdev(qp->ibqp.device), |
| 4585 | "Invalid IB_SEND_INLINE send flag\n"); |
| 4586 | return -EINVAL; |
| 4587 | } |
| 4588 | |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4589 | set_reg_umr_seg(*seg, mr, umr_inline); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4590 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4591 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4592 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4593 | |
| 4594 | set_reg_mkey_seg(*seg, mr, wr->key, wr->access); |
| 4595 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4596 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4597 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4598 | |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4599 | if (umr_inline) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4600 | memcpy_send_wqe(&qp->sq, cur_edge, seg, size, mr->descs, |
| 4601 | mr_list_size); |
| 4602 | *size = ALIGN(*size, MLX5_SEND_WQE_BB >> 4); |
Idan Burstein | 064e526 | 2018-05-02 13:16:39 +0300 | [diff] [blame] | 4603 | } else { |
| 4604 | set_reg_data_seg(*seg, mr, pd); |
| 4605 | *seg += sizeof(struct mlx5_wqe_data_seg); |
| 4606 | *size += (sizeof(struct mlx5_wqe_data_seg) / 16); |
| 4607 | } |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4608 | return 0; |
| 4609 | } |
| 4610 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4611 | static void set_linv_wr(struct mlx5_ib_qp *qp, void **seg, int *size, |
| 4612 | void **cur_edge) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4613 | { |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4614 | set_linv_umr_seg(*seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4615 | *seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4616 | *size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4617 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Sagi Grimberg | dd01e66 | 2015-10-13 19:11:42 +0300 | [diff] [blame] | 4618 | set_linv_mkey_seg(*seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4619 | *seg += sizeof(struct mlx5_mkey_seg); |
| 4620 | *size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4621 | handle_post_send_edge(&qp->sq, seg, *size, cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4622 | } |
| 4623 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4624 | static void dump_wqe(struct mlx5_ib_qp *qp, u32 idx, int size_16) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4625 | { |
| 4626 | __be32 *p = NULL; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4627 | u32 tidx = idx; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4628 | int i, j; |
| 4629 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4630 | pr_debug("dump WQE index %u:\n", idx); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4631 | for (i = 0, j = 0; i < size_16 * 4; i += 4, j += 4) { |
| 4632 | if ((i & 0xf) == 0) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4633 | tidx = (tidx + 1) & (qp->sq.wqe_cnt - 1); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4634 | p = mlx5_frag_buf_get_wqe(&qp->sq.fbc, tidx); |
| 4635 | pr_debug("WQBB at %p:\n", (void *)p); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4636 | j = 0; |
| 4637 | } |
| 4638 | pr_debug("%08x %08x %08x %08x\n", be32_to_cpu(p[j]), |
| 4639 | be32_to_cpu(p[j + 1]), be32_to_cpu(p[j + 2]), |
| 4640 | be32_to_cpu(p[j + 3])); |
| 4641 | } |
| 4642 | } |
| 4643 | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4644 | static int __begin_wqe(struct mlx5_ib_qp *qp, void **seg, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4645 | struct mlx5_wqe_ctrl_seg **ctrl, |
| 4646 | const struct ib_send_wr *wr, unsigned int *idx, |
| 4647 | int *size, void **cur_edge, int nreq, |
| 4648 | bool send_signaled, bool solicited) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4649 | { |
Leon Romanovsky | b2a232d | 2016-08-28 10:58:35 +0300 | [diff] [blame] | 4650 | if (unlikely(mlx5_wq_overflow(&qp->sq, nreq, qp->ibqp.send_cq))) |
| 4651 | return -ENOMEM; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4652 | |
| 4653 | *idx = qp->sq.cur_post & (qp->sq.wqe_cnt - 1); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4654 | *seg = mlx5_frag_buf_get_wqe(&qp->sq.fbc, *idx); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4655 | *ctrl = *seg; |
| 4656 | *(uint32_t *)(*seg + 8) = 0; |
| 4657 | (*ctrl)->imm = send_ieth(wr); |
| 4658 | (*ctrl)->fm_ce_se = qp->sq_signal_bits | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4659 | (send_signaled ? MLX5_WQE_CTRL_CQ_UPDATE : 0) | |
| 4660 | (solicited ? MLX5_WQE_CTRL_SOLICITED : 0); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4661 | |
| 4662 | *seg += sizeof(**ctrl); |
| 4663 | *size = sizeof(**ctrl) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4664 | *cur_edge = qp->sq.cur_edge; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4665 | |
Leon Romanovsky | b2a232d | 2016-08-28 10:58:35 +0300 | [diff] [blame] | 4666 | return 0; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4667 | } |
| 4668 | |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4669 | static int begin_wqe(struct mlx5_ib_qp *qp, void **seg, |
| 4670 | struct mlx5_wqe_ctrl_seg **ctrl, |
| 4671 | const struct ib_send_wr *wr, unsigned *idx, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4672 | int *size, void **cur_edge, int nreq) |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4673 | { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4674 | return __begin_wqe(qp, seg, ctrl, wr, idx, size, cur_edge, nreq, |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4675 | wr->send_flags & IB_SEND_SIGNALED, |
| 4676 | wr->send_flags & IB_SEND_SOLICITED); |
| 4677 | } |
| 4678 | |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4679 | static void finish_wqe(struct mlx5_ib_qp *qp, |
| 4680 | struct mlx5_wqe_ctrl_seg *ctrl, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4681 | void *seg, u8 size, void *cur_edge, |
| 4682 | unsigned int idx, u64 wr_id, int nreq, u8 fence, |
| 4683 | u32 mlx5_opcode) |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4684 | { |
| 4685 | u8 opmod = 0; |
| 4686 | |
| 4687 | ctrl->opmod_idx_opcode = cpu_to_be32(((u32)(qp->sq.cur_post) << 8) | |
| 4688 | mlx5_opcode | ((u32)opmod << 24)); |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 4689 | ctrl->qpn_ds = cpu_to_be32(size | (qp->trans_qp.base.mqp.qpn << 8)); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4690 | ctrl->fm_ce_se |= fence; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4691 | if (unlikely(qp->wq_sig)) |
| 4692 | ctrl->signature = wq_sig(ctrl); |
| 4693 | |
| 4694 | qp->sq.wrid[idx] = wr_id; |
| 4695 | qp->sq.w_list[idx].opcode = mlx5_opcode; |
| 4696 | qp->sq.wqe_head[idx] = qp->sq.head + nreq; |
| 4697 | qp->sq.cur_post += DIV_ROUND_UP(size * 16, MLX5_SEND_WQE_BB); |
| 4698 | qp->sq.w_list[idx].next = qp->sq.cur_post; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4699 | |
| 4700 | /* We save the edge which was possibly updated during the WQE |
| 4701 | * construction, into SQ's cache. |
| 4702 | */ |
| 4703 | seg = PTR_ALIGN(seg, MLX5_SEND_WQE_BB); |
| 4704 | qp->sq.cur_edge = (unlikely(seg == cur_edge)) ? |
| 4705 | get_sq_edge(&qp->sq, qp->sq.cur_post & |
| 4706 | (qp->sq.wqe_cnt - 1)) : |
| 4707 | cur_edge; |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4708 | } |
| 4709 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 4710 | static int _mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 4711 | const struct ib_send_wr **bad_wr, bool drain) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4712 | { |
| 4713 | struct mlx5_wqe_ctrl_seg *ctrl = NULL; /* compiler warning */ |
| 4714 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 4715 | struct mlx5_core_dev *mdev = dev->mdev; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4716 | struct mlx5_ib_qp *qp; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4717 | struct mlx5_ib_mr *mr; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4718 | struct mlx5_wqe_xrc_seg *xrc; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4719 | struct mlx5_bf *bf; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4720 | void *cur_edge; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4721 | int uninitialized_var(size); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4722 | unsigned long flags; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4723 | unsigned idx; |
| 4724 | int err = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4725 | int num_sge; |
| 4726 | void *seg; |
| 4727 | int nreq; |
| 4728 | int i; |
| 4729 | u8 next_fence = 0; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4730 | u8 fence; |
| 4731 | |
Parav Pandit | 6c75520 | 2018-08-28 14:45:29 +0300 | [diff] [blame] | 4732 | if (unlikely(mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR && |
| 4733 | !drain)) { |
| 4734 | *bad_wr = wr; |
| 4735 | return -EIO; |
| 4736 | } |
| 4737 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4738 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 4739 | return mlx5_ib_gsi_post_send(ibqp, wr, bad_wr); |
| 4740 | |
| 4741 | qp = to_mqp(ibqp); |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 4742 | bf = &qp->bf; |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4743 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4744 | spin_lock_irqsave(&qp->sq.lock, flags); |
| 4745 | |
| 4746 | for (nreq = 0; wr; nreq++, wr = wr->next) { |
Fabian Frederick | a8f731e | 2014-08-12 19:20:08 -0400 | [diff] [blame] | 4747 | if (unlikely(wr->opcode >= ARRAY_SIZE(mlx5_ib_opcode))) { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4748 | mlx5_ib_warn(dev, "\n"); |
| 4749 | err = -EINVAL; |
| 4750 | *bad_wr = wr; |
| 4751 | goto out; |
| 4752 | } |
| 4753 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4754 | num_sge = wr->num_sge; |
| 4755 | if (unlikely(num_sge > qp->sq.max_gs)) { |
| 4756 | mlx5_ib_warn(dev, "\n"); |
Chuck Lever | 24be409 | 2016-08-28 10:58:34 +0300 | [diff] [blame] | 4757 | err = -EINVAL; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4758 | *bad_wr = wr; |
| 4759 | goto out; |
| 4760 | } |
| 4761 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4762 | err = begin_wqe(qp, &seg, &ctrl, wr, &idx, &size, &cur_edge, |
| 4763 | nreq); |
Sagi Grimberg | 6e5eadace | 2014-02-23 14:19:08 +0200 | [diff] [blame] | 4764 | if (err) { |
| 4765 | mlx5_ib_warn(dev, "\n"); |
| 4766 | err = -ENOMEM; |
| 4767 | *bad_wr = wr; |
| 4768 | goto out; |
| 4769 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4770 | |
Majd Dibbiny | 074fca3 | 2018-11-05 08:07:37 +0200 | [diff] [blame] | 4771 | if (wr->opcode == IB_WR_REG_MR) { |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4772 | fence = dev->umr_fence; |
| 4773 | next_fence = MLX5_FENCE_MODE_INITIATOR_SMALL; |
Majd Dibbiny | 074fca3 | 2018-11-05 08:07:37 +0200 | [diff] [blame] | 4774 | } else { |
| 4775 | if (wr->send_flags & IB_SEND_FENCE) { |
| 4776 | if (qp->next_fence) |
| 4777 | fence = MLX5_FENCE_MODE_SMALL_AND_FENCE; |
| 4778 | else |
| 4779 | fence = MLX5_FENCE_MODE_FENCE; |
| 4780 | } else { |
| 4781 | fence = qp->next_fence; |
| 4782 | } |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4783 | } |
| 4784 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4785 | switch (ibqp->qp_type) { |
| 4786 | case IB_QPT_XRC_INI: |
| 4787 | xrc = seg; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4788 | seg += sizeof(*xrc); |
| 4789 | size += sizeof(*xrc) / 16; |
| 4790 | /* fall through */ |
| 4791 | case IB_QPT_RC: |
| 4792 | switch (wr->opcode) { |
| 4793 | case IB_WR_RDMA_READ: |
| 4794 | case IB_WR_RDMA_WRITE: |
| 4795 | case IB_WR_RDMA_WRITE_WITH_IMM: |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4796 | set_raddr_seg(seg, rdma_wr(wr)->remote_addr, |
| 4797 | rdma_wr(wr)->rkey); |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 4798 | seg += sizeof(struct mlx5_wqe_raddr_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4799 | size += sizeof(struct mlx5_wqe_raddr_seg) / 16; |
| 4800 | break; |
| 4801 | |
| 4802 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 4803 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4804 | case IB_WR_MASKED_ATOMIC_CMP_AND_SWP: |
Eli Cohen | 81bea28 | 2013-09-11 16:35:30 +0300 | [diff] [blame] | 4805 | mlx5_ib_warn(dev, "Atomic operations are not supported yet\n"); |
| 4806 | err = -ENOSYS; |
| 4807 | *bad_wr = wr; |
| 4808 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4809 | |
| 4810 | case IB_WR_LOCAL_INV: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4811 | qp->sq.wr_data[idx] = IB_WR_LOCAL_INV; |
| 4812 | ctrl->imm = cpu_to_be32(wr->ex.invalidate_rkey); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4813 | set_linv_wr(qp, &seg, &size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4814 | num_sge = 0; |
| 4815 | break; |
| 4816 | |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4817 | case IB_WR_REG_MR: |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4818 | qp->sq.wr_data[idx] = IB_WR_REG_MR; |
| 4819 | ctrl->imm = cpu_to_be32(reg_wr(wr)->key); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4820 | err = set_reg_wr(qp, reg_wr(wr), &seg, &size, |
| 4821 | &cur_edge); |
Sagi Grimberg | 8a187ee | 2015-10-13 19:11:26 +0300 | [diff] [blame] | 4822 | if (err) { |
| 4823 | *bad_wr = wr; |
| 4824 | goto out; |
| 4825 | } |
| 4826 | num_sge = 0; |
| 4827 | break; |
| 4828 | |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4829 | case IB_WR_REG_SIG_MR: |
| 4830 | qp->sq.wr_data[idx] = IB_WR_REG_SIG_MR; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4831 | mr = to_mmr(sig_handover_wr(wr)->sig_mr); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4832 | |
| 4833 | ctrl->imm = cpu_to_be32(mr->ibmr.rkey); |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4834 | err = set_sig_umr_wr(wr, qp, &seg, &size, |
| 4835 | &cur_edge); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4836 | if (err) { |
| 4837 | mlx5_ib_warn(dev, "\n"); |
| 4838 | *bad_wr = wr; |
| 4839 | goto out; |
| 4840 | } |
| 4841 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4842 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 4843 | wr->wr_id, nreq, fence, |
| 4844 | MLX5_OPCODE_UMR); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4845 | /* |
| 4846 | * SET_PSV WQEs are not signaled and solicited |
| 4847 | * on error |
| 4848 | */ |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4849 | err = __begin_wqe(qp, &seg, &ctrl, wr, &idx, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4850 | &size, &cur_edge, nreq, false, |
| 4851 | true); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4852 | if (err) { |
| 4853 | mlx5_ib_warn(dev, "\n"); |
| 4854 | err = -ENOMEM; |
| 4855 | *bad_wr = wr; |
| 4856 | goto out; |
| 4857 | } |
| 4858 | |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4859 | err = set_psv_wr(&sig_handover_wr(wr)->sig_attrs->mem, |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4860 | mr->sig->psv_memory.psv_idx, &seg, |
| 4861 | &size); |
| 4862 | if (err) { |
| 4863 | mlx5_ib_warn(dev, "\n"); |
| 4864 | *bad_wr = wr; |
| 4865 | goto out; |
| 4866 | } |
| 4867 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4868 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 4869 | wr->wr_id, nreq, fence, |
| 4870 | MLX5_OPCODE_SET_PSV); |
Bart Van Assche | 7bb1faf | 2018-07-18 09:25:15 -0700 | [diff] [blame] | 4871 | err = __begin_wqe(qp, &seg, &ctrl, wr, &idx, |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4872 | &size, &cur_edge, nreq, false, |
| 4873 | true); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4874 | if (err) { |
| 4875 | mlx5_ib_warn(dev, "\n"); |
| 4876 | err = -ENOMEM; |
| 4877 | *bad_wr = wr; |
| 4878 | goto out; |
| 4879 | } |
| 4880 | |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4881 | err = set_psv_wr(&sig_handover_wr(wr)->sig_attrs->wire, |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4882 | mr->sig->psv_wire.psv_idx, &seg, |
| 4883 | &size); |
| 4884 | if (err) { |
| 4885 | mlx5_ib_warn(dev, "\n"); |
| 4886 | *bad_wr = wr; |
| 4887 | goto out; |
| 4888 | } |
| 4889 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4890 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, |
| 4891 | wr->wr_id, nreq, fence, |
| 4892 | MLX5_OPCODE_SET_PSV); |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4893 | qp->next_fence = MLX5_FENCE_MODE_INITIATOR_SMALL; |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4894 | num_sge = 0; |
| 4895 | goto skip_psv; |
| 4896 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4897 | default: |
| 4898 | break; |
| 4899 | } |
| 4900 | break; |
| 4901 | |
| 4902 | case IB_QPT_UC: |
| 4903 | switch (wr->opcode) { |
| 4904 | case IB_WR_RDMA_WRITE: |
| 4905 | case IB_WR_RDMA_WRITE_WITH_IMM: |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4906 | set_raddr_seg(seg, rdma_wr(wr)->remote_addr, |
| 4907 | rdma_wr(wr)->rkey); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4908 | seg += sizeof(struct mlx5_wqe_raddr_seg); |
| 4909 | size += sizeof(struct mlx5_wqe_raddr_seg) / 16; |
| 4910 | break; |
| 4911 | |
| 4912 | default: |
| 4913 | break; |
| 4914 | } |
| 4915 | break; |
| 4916 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4917 | case IB_QPT_SMI: |
Maor Gottlieb | 1e0e50b | 2017-01-18 14:10:34 +0200 | [diff] [blame] | 4918 | if (unlikely(!mdev->port_caps[qp->port - 1].has_smi)) { |
| 4919 | mlx5_ib_warn(dev, "Send SMP MADs is not allowed\n"); |
| 4920 | err = -EPERM; |
| 4921 | *bad_wr = wr; |
| 4922 | goto out; |
| 4923 | } |
Bart Van Assche | f6b1ee3 | 2017-10-11 10:49:07 -0700 | [diff] [blame] | 4924 | /* fall through */ |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 4925 | case MLX5_IB_QPT_HW_GSI: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4926 | set_datagram_seg(seg, wr); |
Jack Morgenstein | f241e74 | 2014-07-28 23:30:23 +0300 | [diff] [blame] | 4927 | seg += sizeof(struct mlx5_wqe_datagram_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4928 | size += sizeof(struct mlx5_wqe_datagram_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4929 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
| 4930 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4931 | break; |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4932 | case IB_QPT_UD: |
| 4933 | set_datagram_seg(seg, wr); |
| 4934 | seg += sizeof(struct mlx5_wqe_datagram_seg); |
| 4935 | size += sizeof(struct mlx5_wqe_datagram_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4936 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4937 | |
| 4938 | /* handle qp that supports ud offload */ |
| 4939 | if (qp->flags & IB_QP_CREATE_IPOIB_UD_LSO) { |
| 4940 | struct mlx5_wqe_eth_pad *pad; |
| 4941 | |
| 4942 | pad = seg; |
| 4943 | memset(pad, 0, sizeof(struct mlx5_wqe_eth_pad)); |
| 4944 | seg += sizeof(struct mlx5_wqe_eth_pad); |
| 4945 | size += sizeof(struct mlx5_wqe_eth_pad) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4946 | set_eth_seg(wr, qp, &seg, &size, &cur_edge); |
| 4947 | handle_post_send_edge(&qp->sq, &seg, size, |
| 4948 | &cur_edge); |
Erez Shitrit | f031396 | 2016-02-21 16:27:17 +0200 | [diff] [blame] | 4949 | } |
| 4950 | break; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4951 | case MLX5_IB_QPT_REG_UMR: |
| 4952 | if (wr->opcode != MLX5_IB_WR_UMR) { |
| 4953 | err = -EINVAL; |
| 4954 | mlx5_ib_warn(dev, "bad opcode\n"); |
| 4955 | goto out; |
| 4956 | } |
| 4957 | qp->sq.wr_data[idx] = MLX5_IB_WR_UMR; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 4958 | ctrl->imm = cpu_to_be32(umr_wr(wr)->mkey); |
Majd Dibbiny | c8d75a9 | 2018-03-22 15:34:04 +0200 | [diff] [blame] | 4959 | err = set_reg_umr_segment(dev, seg, wr, !!(MLX5_CAP_GEN(mdev, atomic))); |
| 4960 | if (unlikely(err)) |
| 4961 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4962 | seg += sizeof(struct mlx5_wqe_umr_ctrl_seg); |
| 4963 | size += sizeof(struct mlx5_wqe_umr_ctrl_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4964 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4965 | set_reg_mkey_segment(seg, wr); |
| 4966 | seg += sizeof(struct mlx5_mkey_seg); |
| 4967 | size += sizeof(struct mlx5_mkey_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4968 | handle_post_send_edge(&qp->sq, &seg, size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4969 | break; |
| 4970 | |
| 4971 | default: |
| 4972 | break; |
| 4973 | } |
| 4974 | |
| 4975 | if (wr->send_flags & IB_SEND_INLINE && num_sge) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4976 | err = set_data_inl_seg(qp, wr, &seg, &size, &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4977 | if (unlikely(err)) { |
| 4978 | mlx5_ib_warn(dev, "\n"); |
| 4979 | *bad_wr = wr; |
| 4980 | goto out; |
| 4981 | } |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4982 | } else { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4983 | for (i = 0; i < num_sge; i++) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4984 | handle_post_send_edge(&qp->sq, &seg, size, |
| 4985 | &cur_edge); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4986 | if (likely(wr->sg_list[i].length)) { |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4987 | set_data_ptr_seg |
| 4988 | ((struct mlx5_wqe_data_seg *)seg, |
| 4989 | wr->sg_list + i); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4990 | size += sizeof(struct mlx5_wqe_data_seg) / 16; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4991 | seg += sizeof(struct mlx5_wqe_data_seg); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 4992 | } |
| 4993 | } |
| 4994 | } |
| 4995 | |
Max Gurtovoy | 6e8484c | 2017-05-28 10:53:11 +0300 | [diff] [blame] | 4996 | qp->next_fence = next_fence; |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 4997 | finish_wqe(qp, ctrl, seg, size, cur_edge, idx, wr->wr_id, nreq, |
| 4998 | fence, mlx5_ib_opcode[wr->opcode]); |
Sagi Grimberg | e663181 | 2014-02-23 14:19:11 +0200 | [diff] [blame] | 4999 | skip_psv: |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5000 | if (0) |
| 5001 | dump_wqe(qp, idx, size); |
| 5002 | } |
| 5003 | |
| 5004 | out: |
| 5005 | if (likely(nreq)) { |
| 5006 | qp->sq.head += nreq; |
| 5007 | |
| 5008 | /* Make sure that descriptors are written before |
| 5009 | * updating doorbell record and ringing the doorbell |
| 5010 | */ |
| 5011 | wmb(); |
| 5012 | |
| 5013 | qp->db.db[MLX5_SND_DBR] = cpu_to_be32(qp->sq.cur_post); |
| 5014 | |
Eli Cohen | ada388f | 2014-01-14 17:45:16 +0200 | [diff] [blame] | 5015 | /* Make sure doorbell record is visible to the HCA before |
| 5016 | * we hit doorbell */ |
| 5017 | wmb(); |
| 5018 | |
Eli Cohen | 5fe9dec | 2017-01-03 23:55:25 +0200 | [diff] [blame] | 5019 | /* currently we support only regular doorbells */ |
| 5020 | mlx5_write64((__be32 *)ctrl, bf->bfreg->map + bf->offset, NULL); |
| 5021 | /* Make sure doorbells don't leak out of SQ spinlock |
| 5022 | * and reach the HCA out of order. |
| 5023 | */ |
| 5024 | mmiowb(); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5025 | bf->offset ^= bf->buf_size; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | spin_unlock_irqrestore(&qp->sq.lock, flags); |
| 5029 | |
| 5030 | return err; |
| 5031 | } |
| 5032 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5033 | int mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr, |
| 5034 | const struct ib_send_wr **bad_wr) |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5035 | { |
| 5036 | return _mlx5_ib_post_send(ibqp, wr, bad_wr, false); |
| 5037 | } |
| 5038 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5039 | static void set_sig_seg(struct mlx5_rwqe_sig *sig, int size) |
| 5040 | { |
| 5041 | sig->signature = calc_sig(sig, size); |
| 5042 | } |
| 5043 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5044 | static int _mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 5045 | const struct ib_recv_wr **bad_wr, bool drain) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5046 | { |
| 5047 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 5048 | struct mlx5_wqe_data_seg *scat; |
| 5049 | struct mlx5_rwqe_sig *sig; |
Maor Gottlieb | 89ea94a7 | 2016-06-17 15:01:38 +0300 | [diff] [blame] | 5050 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 5051 | struct mlx5_core_dev *mdev = dev->mdev; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5052 | unsigned long flags; |
| 5053 | int err = 0; |
| 5054 | int nreq; |
| 5055 | int ind; |
| 5056 | int i; |
| 5057 | |
Parav Pandit | 6c75520 | 2018-08-28 14:45:29 +0300 | [diff] [blame] | 5058 | if (unlikely(mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR && |
| 5059 | !drain)) { |
| 5060 | *bad_wr = wr; |
| 5061 | return -EIO; |
| 5062 | } |
| 5063 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5064 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5065 | return mlx5_ib_gsi_post_recv(ibqp, wr, bad_wr); |
| 5066 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5067 | spin_lock_irqsave(&qp->rq.lock, flags); |
| 5068 | |
| 5069 | ind = qp->rq.head & (qp->rq.wqe_cnt - 1); |
| 5070 | |
| 5071 | for (nreq = 0; wr; nreq++, wr = wr->next) { |
| 5072 | if (mlx5_wq_overflow(&qp->rq, nreq, qp->ibqp.recv_cq)) { |
| 5073 | err = -ENOMEM; |
| 5074 | *bad_wr = wr; |
| 5075 | goto out; |
| 5076 | } |
| 5077 | |
| 5078 | if (unlikely(wr->num_sge > qp->rq.max_gs)) { |
| 5079 | err = -EINVAL; |
| 5080 | *bad_wr = wr; |
| 5081 | goto out; |
| 5082 | } |
| 5083 | |
Guy Levi | 34f4c95 | 2018-11-26 08:15:50 +0200 | [diff] [blame] | 5084 | scat = mlx5_frag_buf_get_wqe(&qp->rq.fbc, ind); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5085 | if (qp->wq_sig) |
| 5086 | scat++; |
| 5087 | |
| 5088 | for (i = 0; i < wr->num_sge; i++) |
| 5089 | set_data_ptr_seg(scat + i, wr->sg_list + i); |
| 5090 | |
| 5091 | if (i < qp->rq.max_gs) { |
| 5092 | scat[i].byte_count = 0; |
| 5093 | scat[i].lkey = cpu_to_be32(MLX5_INVALID_LKEY); |
| 5094 | scat[i].addr = 0; |
| 5095 | } |
| 5096 | |
| 5097 | if (qp->wq_sig) { |
| 5098 | sig = (struct mlx5_rwqe_sig *)scat; |
| 5099 | set_sig_seg(sig, (qp->rq.max_gs + 1) << 2); |
| 5100 | } |
| 5101 | |
| 5102 | qp->rq.wrid[ind] = wr->wr_id; |
| 5103 | |
| 5104 | ind = (ind + 1) & (qp->rq.wqe_cnt - 1); |
| 5105 | } |
| 5106 | |
| 5107 | out: |
| 5108 | if (likely(nreq)) { |
| 5109 | qp->rq.head += nreq; |
| 5110 | |
| 5111 | /* Make sure that descriptors are written before |
| 5112 | * doorbell record. |
| 5113 | */ |
| 5114 | wmb(); |
| 5115 | |
| 5116 | *qp->db.db = cpu_to_be32(qp->rq.head & 0xffff); |
| 5117 | } |
| 5118 | |
| 5119 | spin_unlock_irqrestore(&qp->rq.lock, flags); |
| 5120 | |
| 5121 | return err; |
| 5122 | } |
| 5123 | |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 5124 | int mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr, |
| 5125 | const struct ib_recv_wr **bad_wr) |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 5126 | { |
| 5127 | return _mlx5_ib_post_recv(ibqp, wr, bad_wr, false); |
| 5128 | } |
| 5129 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5130 | static inline enum ib_qp_state to_ib_qp_state(enum mlx5_qp_state mlx5_state) |
| 5131 | { |
| 5132 | switch (mlx5_state) { |
| 5133 | case MLX5_QP_STATE_RST: return IB_QPS_RESET; |
| 5134 | case MLX5_QP_STATE_INIT: return IB_QPS_INIT; |
| 5135 | case MLX5_QP_STATE_RTR: return IB_QPS_RTR; |
| 5136 | case MLX5_QP_STATE_RTS: return IB_QPS_RTS; |
| 5137 | case MLX5_QP_STATE_SQ_DRAINING: |
| 5138 | case MLX5_QP_STATE_SQD: return IB_QPS_SQD; |
| 5139 | case MLX5_QP_STATE_SQER: return IB_QPS_SQE; |
| 5140 | case MLX5_QP_STATE_ERR: return IB_QPS_ERR; |
| 5141 | default: return -1; |
| 5142 | } |
| 5143 | } |
| 5144 | |
| 5145 | static inline enum ib_mig_state to_ib_mig_state(int mlx5_mig_state) |
| 5146 | { |
| 5147 | switch (mlx5_mig_state) { |
| 5148 | case MLX5_QP_PM_ARMED: return IB_MIG_ARMED; |
| 5149 | case MLX5_QP_PM_REARM: return IB_MIG_REARM; |
| 5150 | case MLX5_QP_PM_MIGRATED: return IB_MIG_MIGRATED; |
| 5151 | default: return -1; |
| 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | static int to_ib_qp_access_flags(int mlx5_flags) |
| 5156 | { |
| 5157 | int ib_flags = 0; |
| 5158 | |
| 5159 | if (mlx5_flags & MLX5_QP_BIT_RRE) |
| 5160 | ib_flags |= IB_ACCESS_REMOTE_READ; |
| 5161 | if (mlx5_flags & MLX5_QP_BIT_RWE) |
| 5162 | ib_flags |= IB_ACCESS_REMOTE_WRITE; |
| 5163 | if (mlx5_flags & MLX5_QP_BIT_RAE) |
| 5164 | ib_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 5165 | |
| 5166 | return ib_flags; |
| 5167 | } |
| 5168 | |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5169 | static void to_rdma_ah_attr(struct mlx5_ib_dev *ibdev, |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5170 | struct rdma_ah_attr *ah_attr, |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5171 | struct mlx5_qp_path *path) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5172 | { |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5173 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5174 | memset(ah_attr, 0, sizeof(*ah_attr)); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5175 | |
Jason Gunthorpe | e7996a9 | 2018-01-29 13:26:40 -0700 | [diff] [blame] | 5176 | if (!path->port || path->port > ibdev->num_ports) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5177 | return; |
| 5178 | |
Leon Romanovsky | ae59c3f | 2018-01-12 07:58:39 +0200 | [diff] [blame] | 5179 | ah_attr->type = rdma_ah_find_type(&ibdev->ib_dev, path->port); |
| 5180 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5181 | rdma_ah_set_port_num(ah_attr, path->port); |
| 5182 | rdma_ah_set_sl(ah_attr, path->dci_cfi_prio_sl & 0xf); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5183 | |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5184 | rdma_ah_set_dlid(ah_attr, be16_to_cpu(path->rlid)); |
| 5185 | rdma_ah_set_path_bits(ah_attr, path->grh_mlid & 0x7f); |
| 5186 | rdma_ah_set_static_rate(ah_attr, |
| 5187 | path->static_rate ? path->static_rate - 5 : 0); |
| 5188 | if (path->grh_mlid & (1 << 7)) { |
| 5189 | u32 tc_fl = be32_to_cpu(path->tclass_flowlabel); |
| 5190 | |
| 5191 | rdma_ah_set_grh(ah_attr, NULL, |
| 5192 | tc_fl & 0xfffff, |
| 5193 | path->mgid_index, |
| 5194 | path->hop_limit, |
| 5195 | (tc_fl >> 20) & 0xff); |
| 5196 | rdma_ah_set_dgid_raw(ah_attr, path->rgid); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5197 | } |
| 5198 | } |
| 5199 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5200 | static int query_raw_packet_qp_sq_state(struct mlx5_ib_dev *dev, |
| 5201 | struct mlx5_ib_sq *sq, |
| 5202 | u8 *sq_state) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5203 | { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5204 | int err; |
| 5205 | |
Eran Ben Elisha | 2816077 | 2017-12-26 15:17:05 +0200 | [diff] [blame] | 5206 | 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] | 5207 | if (err) |
| 5208 | goto out; |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5209 | sq->state = *sq_state; |
| 5210 | |
| 5211 | out: |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5212 | return err; |
| 5213 | } |
| 5214 | |
| 5215 | static int query_raw_packet_qp_rq_state(struct mlx5_ib_dev *dev, |
| 5216 | struct mlx5_ib_rq *rq, |
| 5217 | u8 *rq_state) |
| 5218 | { |
| 5219 | void *out; |
| 5220 | void *rqc; |
| 5221 | int inlen; |
| 5222 | int err; |
| 5223 | |
| 5224 | inlen = MLX5_ST_SZ_BYTES(query_rq_out); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5225 | out = kvzalloc(inlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5226 | if (!out) |
| 5227 | return -ENOMEM; |
| 5228 | |
| 5229 | err = mlx5_core_query_rq(dev->mdev, rq->base.mqp.qpn, out); |
| 5230 | if (err) |
| 5231 | goto out; |
| 5232 | |
| 5233 | rqc = MLX5_ADDR_OF(query_rq_out, out, rq_context); |
| 5234 | *rq_state = MLX5_GET(rqc, rqc, state); |
| 5235 | rq->state = *rq_state; |
| 5236 | |
| 5237 | out: |
| 5238 | kvfree(out); |
| 5239 | return err; |
| 5240 | } |
| 5241 | |
| 5242 | static int sqrq_state_to_qp_state(u8 sq_state, u8 rq_state, |
| 5243 | struct mlx5_ib_qp *qp, u8 *qp_state) |
| 5244 | { |
| 5245 | static const u8 sqrq_trans[MLX5_RQ_NUM_STATE][MLX5_SQ_NUM_STATE] = { |
| 5246 | [MLX5_RQC_STATE_RST] = { |
| 5247 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 5248 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 5249 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE_BAD, |
| 5250 | [MLX5_SQ_STATE_NA] = IB_QPS_RESET, |
| 5251 | }, |
| 5252 | [MLX5_RQC_STATE_RDY] = { |
| 5253 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 5254 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 5255 | [MLX5_SQC_STATE_ERR] = IB_QPS_SQE, |
| 5256 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE, |
| 5257 | }, |
| 5258 | [MLX5_RQC_STATE_ERR] = { |
| 5259 | [MLX5_SQC_STATE_RST] = MLX5_QP_STATE_BAD, |
| 5260 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE_BAD, |
| 5261 | [MLX5_SQC_STATE_ERR] = IB_QPS_ERR, |
| 5262 | [MLX5_SQ_STATE_NA] = IB_QPS_ERR, |
| 5263 | }, |
| 5264 | [MLX5_RQ_STATE_NA] = { |
| 5265 | [MLX5_SQC_STATE_RST] = IB_QPS_RESET, |
| 5266 | [MLX5_SQC_STATE_RDY] = MLX5_QP_STATE, |
| 5267 | [MLX5_SQC_STATE_ERR] = MLX5_QP_STATE, |
| 5268 | [MLX5_SQ_STATE_NA] = MLX5_QP_STATE_BAD, |
| 5269 | }, |
| 5270 | }; |
| 5271 | |
| 5272 | *qp_state = sqrq_trans[rq_state][sq_state]; |
| 5273 | |
| 5274 | if (*qp_state == MLX5_QP_STATE_BAD) { |
| 5275 | WARN(1, "Buggy Raw Packet QP state, SQ 0x%x state: 0x%x, RQ 0x%x state: 0x%x", |
| 5276 | qp->raw_packet_qp.sq.base.mqp.qpn, sq_state, |
| 5277 | qp->raw_packet_qp.rq.base.mqp.qpn, rq_state); |
| 5278 | return -EINVAL; |
| 5279 | } |
| 5280 | |
| 5281 | if (*qp_state == MLX5_QP_STATE) |
| 5282 | *qp_state = qp->state; |
| 5283 | |
| 5284 | return 0; |
| 5285 | } |
| 5286 | |
| 5287 | static int query_raw_packet_qp_state(struct mlx5_ib_dev *dev, |
| 5288 | struct mlx5_ib_qp *qp, |
| 5289 | u8 *raw_packet_qp_state) |
| 5290 | { |
| 5291 | struct mlx5_ib_raw_packet_qp *raw_packet_qp = &qp->raw_packet_qp; |
| 5292 | struct mlx5_ib_sq *sq = &raw_packet_qp->sq; |
| 5293 | struct mlx5_ib_rq *rq = &raw_packet_qp->rq; |
| 5294 | int err; |
| 5295 | u8 sq_state = MLX5_SQ_STATE_NA; |
| 5296 | u8 rq_state = MLX5_RQ_STATE_NA; |
| 5297 | |
| 5298 | if (qp->sq.wqe_cnt) { |
| 5299 | err = query_raw_packet_qp_sq_state(dev, sq, &sq_state); |
| 5300 | if (err) |
| 5301 | return err; |
| 5302 | } |
| 5303 | |
| 5304 | if (qp->rq.wqe_cnt) { |
| 5305 | err = query_raw_packet_qp_rq_state(dev, rq, &rq_state); |
| 5306 | if (err) |
| 5307 | return err; |
| 5308 | } |
| 5309 | |
| 5310 | return sqrq_state_to_qp_state(sq_state, rq_state, qp, |
| 5311 | raw_packet_qp_state); |
| 5312 | } |
| 5313 | |
| 5314 | static int query_qp_attr(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *qp, |
| 5315 | struct ib_qp_attr *qp_attr) |
| 5316 | { |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5317 | int outlen = MLX5_ST_SZ_BYTES(query_qp_out); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5318 | struct mlx5_qp_context *context; |
| 5319 | int mlx5_state; |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5320 | u32 *outb; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5321 | int err = 0; |
| 5322 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5323 | outb = kzalloc(outlen, GFP_KERNEL); |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5324 | if (!outb) |
| 5325 | return -ENOMEM; |
| 5326 | |
majd@mellanox.com | 19098df | 2016-01-14 19:13:03 +0200 | [diff] [blame] | 5327 | err = mlx5_core_qp_query(dev->mdev, &qp->trans_qp.base.mqp, outb, |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5328 | outlen); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5329 | if (err) |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5330 | goto out; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5331 | |
Saeed Mahameed | 09a7d9e | 2016-07-19 01:17:59 +0300 | [diff] [blame] | 5332 | /* FIXME: use MLX5_GET rather than mlx5_qp_context manual struct */ |
| 5333 | context = (struct mlx5_qp_context *)MLX5_ADDR_OF(query_qp_out, outb, qpc); |
| 5334 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5335 | mlx5_state = be32_to_cpu(context->flags) >> 28; |
| 5336 | |
| 5337 | qp->state = to_ib_qp_state(mlx5_state); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5338 | qp_attr->path_mtu = context->mtu_msgmax >> 5; |
| 5339 | qp_attr->path_mig_state = |
| 5340 | to_ib_mig_state((be32_to_cpu(context->flags) >> 11) & 0x3); |
| 5341 | qp_attr->qkey = be32_to_cpu(context->qkey); |
| 5342 | qp_attr->rq_psn = be32_to_cpu(context->rnr_nextrecvpsn) & 0xffffff; |
| 5343 | qp_attr->sq_psn = be32_to_cpu(context->next_send_psn) & 0xffffff; |
| 5344 | qp_attr->dest_qp_num = be32_to_cpu(context->log_pg_sz_remote_qpn) & 0xffffff; |
| 5345 | qp_attr->qp_access_flags = |
| 5346 | to_ib_qp_access_flags(be32_to_cpu(context->params2)); |
| 5347 | |
| 5348 | if (qp->ibqp.qp_type == IB_QPT_RC || qp->ibqp.qp_type == IB_QPT_UC) { |
Dasaratharaman Chandramouli | 3834938 | 2017-04-29 14:41:24 -0400 | [diff] [blame] | 5349 | to_rdma_ah_attr(dev, &qp_attr->ah_attr, &context->pri_path); |
| 5350 | to_rdma_ah_attr(dev, &qp_attr->alt_ah_attr, &context->alt_path); |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 5351 | qp_attr->alt_pkey_index = |
| 5352 | be16_to_cpu(context->alt_path.pkey_index); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 5353 | qp_attr->alt_port_num = |
| 5354 | rdma_ah_get_port_num(&qp_attr->alt_ah_attr); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5355 | } |
| 5356 | |
Noa Osherovich | d3ae2bd | 2016-06-04 15:15:36 +0300 | [diff] [blame] | 5357 | qp_attr->pkey_index = be16_to_cpu(context->pri_path.pkey_index); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5358 | qp_attr->port_num = context->pri_path.port; |
| 5359 | |
| 5360 | /* qp_attr->en_sqd_async_notify is only applicable in modify qp */ |
| 5361 | qp_attr->sq_draining = mlx5_state == MLX5_QP_STATE_SQ_DRAINING; |
| 5362 | |
| 5363 | qp_attr->max_rd_atomic = 1 << ((be32_to_cpu(context->params1) >> 21) & 0x7); |
| 5364 | |
| 5365 | qp_attr->max_dest_rd_atomic = |
| 5366 | 1 << ((be32_to_cpu(context->params2) >> 21) & 0x7); |
| 5367 | qp_attr->min_rnr_timer = |
| 5368 | (be32_to_cpu(context->rnr_nextrecvpsn) >> 24) & 0x1f; |
| 5369 | qp_attr->timeout = context->pri_path.ackto_lt >> 3; |
| 5370 | qp_attr->retry_cnt = (be32_to_cpu(context->params1) >> 16) & 0x7; |
| 5371 | qp_attr->rnr_retry = (be32_to_cpu(context->params1) >> 13) & 0x7; |
| 5372 | qp_attr->alt_timeout = context->alt_path.ackto_lt >> 3; |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5373 | |
| 5374 | out: |
| 5375 | kfree(outb); |
| 5376 | return err; |
| 5377 | } |
| 5378 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5379 | static int mlx5_ib_dct_query_qp(struct mlx5_ib_dev *dev, struct mlx5_ib_qp *mqp, |
| 5380 | struct ib_qp_attr *qp_attr, int qp_attr_mask, |
| 5381 | struct ib_qp_init_attr *qp_init_attr) |
| 5382 | { |
| 5383 | struct mlx5_core_dct *dct = &mqp->dct.mdct; |
| 5384 | u32 *out; |
| 5385 | u32 access_flags = 0; |
| 5386 | int outlen = MLX5_ST_SZ_BYTES(query_dct_out); |
| 5387 | void *dctc; |
| 5388 | int err; |
| 5389 | int supported_mask = IB_QP_STATE | |
| 5390 | IB_QP_ACCESS_FLAGS | |
| 5391 | IB_QP_PORT | |
| 5392 | IB_QP_MIN_RNR_TIMER | |
| 5393 | IB_QP_AV | |
| 5394 | IB_QP_PATH_MTU | |
| 5395 | IB_QP_PKEY_INDEX; |
| 5396 | |
| 5397 | if (qp_attr_mask & ~supported_mask) |
| 5398 | return -EINVAL; |
| 5399 | if (mqp->state != IB_QPS_RTR) |
| 5400 | return -EINVAL; |
| 5401 | |
| 5402 | out = kzalloc(outlen, GFP_KERNEL); |
| 5403 | if (!out) |
| 5404 | return -ENOMEM; |
| 5405 | |
| 5406 | err = mlx5_core_dct_query(dev->mdev, dct, out, outlen); |
| 5407 | if (err) |
| 5408 | goto out; |
| 5409 | |
| 5410 | dctc = MLX5_ADDR_OF(query_dct_out, out, dct_context_entry); |
| 5411 | |
| 5412 | if (qp_attr_mask & IB_QP_STATE) |
| 5413 | qp_attr->qp_state = IB_QPS_RTR; |
| 5414 | |
| 5415 | if (qp_attr_mask & IB_QP_ACCESS_FLAGS) { |
| 5416 | if (MLX5_GET(dctc, dctc, rre)) |
| 5417 | access_flags |= IB_ACCESS_REMOTE_READ; |
| 5418 | if (MLX5_GET(dctc, dctc, rwe)) |
| 5419 | access_flags |= IB_ACCESS_REMOTE_WRITE; |
| 5420 | if (MLX5_GET(dctc, dctc, rae)) |
| 5421 | access_flags |= IB_ACCESS_REMOTE_ATOMIC; |
| 5422 | qp_attr->qp_access_flags = access_flags; |
| 5423 | } |
| 5424 | |
| 5425 | if (qp_attr_mask & IB_QP_PORT) |
| 5426 | qp_attr->port_num = MLX5_GET(dctc, dctc, port); |
| 5427 | if (qp_attr_mask & IB_QP_MIN_RNR_TIMER) |
| 5428 | qp_attr->min_rnr_timer = MLX5_GET(dctc, dctc, min_rnr_nak); |
| 5429 | if (qp_attr_mask & IB_QP_AV) { |
| 5430 | qp_attr->ah_attr.grh.traffic_class = MLX5_GET(dctc, dctc, tclass); |
| 5431 | qp_attr->ah_attr.grh.flow_label = MLX5_GET(dctc, dctc, flow_label); |
| 5432 | qp_attr->ah_attr.grh.sgid_index = MLX5_GET(dctc, dctc, my_addr_index); |
| 5433 | qp_attr->ah_attr.grh.hop_limit = MLX5_GET(dctc, dctc, hop_limit); |
| 5434 | } |
| 5435 | if (qp_attr_mask & IB_QP_PATH_MTU) |
| 5436 | qp_attr->path_mtu = MLX5_GET(dctc, dctc, mtu); |
| 5437 | if (qp_attr_mask & IB_QP_PKEY_INDEX) |
| 5438 | qp_attr->pkey_index = MLX5_GET(dctc, dctc, pkey_index); |
| 5439 | out: |
| 5440 | kfree(out); |
| 5441 | return err; |
| 5442 | } |
| 5443 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5444 | int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, |
| 5445 | int qp_attr_mask, struct ib_qp_init_attr *qp_init_attr) |
| 5446 | { |
| 5447 | struct mlx5_ib_dev *dev = to_mdev(ibqp->device); |
| 5448 | struct mlx5_ib_qp *qp = to_mqp(ibqp); |
| 5449 | int err = 0; |
| 5450 | u8 raw_packet_qp_state; |
| 5451 | |
Yishai Hadas | 28d6137 | 2016-05-23 15:20:56 +0300 | [diff] [blame] | 5452 | if (ibqp->rwq_ind_tbl) |
| 5453 | return -ENOSYS; |
| 5454 | |
Haggai Eran | d16e91d | 2016-02-29 15:45:05 +0200 | [diff] [blame] | 5455 | if (unlikely(ibqp->qp_type == IB_QPT_GSI)) |
| 5456 | return mlx5_ib_gsi_query_qp(ibqp, qp_attr, qp_attr_mask, |
| 5457 | qp_init_attr); |
| 5458 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 5459 | /* Not all of output fields are applicable, make sure to zero them */ |
| 5460 | memset(qp_init_attr, 0, sizeof(*qp_init_attr)); |
| 5461 | memset(qp_attr, 0, sizeof(*qp_attr)); |
| 5462 | |
Moni Shoua | 776a390 | 2018-01-02 16:19:33 +0200 | [diff] [blame] | 5463 | if (unlikely(qp->qp_sub_type == MLX5_IB_QPT_DCT)) |
| 5464 | return mlx5_ib_dct_query_qp(dev, qp, qp_attr, |
| 5465 | qp_attr_mask, qp_init_attr); |
| 5466 | |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5467 | mutex_lock(&qp->mutex); |
| 5468 | |
Yishai Hadas | c2e53b2 | 2017-06-08 16:15:08 +0300 | [diff] [blame] | 5469 | if (qp->ibqp.qp_type == IB_QPT_RAW_PACKET || |
| 5470 | qp->flags & MLX5_IB_QP_UNDERLAY) { |
majd@mellanox.com | 6d2f89df | 2016-01-14 19:13:05 +0200 | [diff] [blame] | 5471 | err = query_raw_packet_qp_state(dev, qp, &raw_packet_qp_state); |
| 5472 | if (err) |
| 5473 | goto out; |
| 5474 | qp->state = raw_packet_qp_state; |
| 5475 | qp_attr->port_num = 1; |
| 5476 | } else { |
| 5477 | err = query_qp_attr(dev, qp, qp_attr); |
| 5478 | if (err) |
| 5479 | goto out; |
| 5480 | } |
| 5481 | |
| 5482 | qp_attr->qp_state = qp->state; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5483 | qp_attr->cur_qp_state = qp_attr->qp_state; |
| 5484 | qp_attr->cap.max_recv_wr = qp->rq.wqe_cnt; |
| 5485 | qp_attr->cap.max_recv_sge = qp->rq.max_gs; |
| 5486 | |
| 5487 | if (!ibqp->uobject) { |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5488 | qp_attr->cap.max_send_wr = qp->sq.max_post; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5489 | qp_attr->cap.max_send_sge = qp->sq.max_gs; |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5490 | qp_init_attr->qp_context = ibqp->qp_context; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5491 | } else { |
| 5492 | qp_attr->cap.max_send_wr = 0; |
| 5493 | qp_attr->cap.max_send_sge = 0; |
| 5494 | } |
| 5495 | |
Noa Osherovich | 0540d81 | 2016-06-04 15:15:32 +0300 | [diff] [blame] | 5496 | qp_init_attr->qp_type = ibqp->qp_type; |
| 5497 | qp_init_attr->recv_cq = ibqp->recv_cq; |
| 5498 | qp_init_attr->send_cq = ibqp->send_cq; |
| 5499 | qp_init_attr->srq = ibqp->srq; |
| 5500 | qp_attr->cap.max_inline_data = qp->max_inline_data; |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5501 | |
| 5502 | qp_init_attr->cap = qp_attr->cap; |
| 5503 | |
| 5504 | qp_init_attr->create_flags = 0; |
| 5505 | if (qp->flags & MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK) |
| 5506 | qp_init_attr->create_flags |= IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK; |
| 5507 | |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 5508 | if (qp->flags & MLX5_IB_QP_CROSS_CHANNEL) |
| 5509 | qp_init_attr->create_flags |= IB_QP_CREATE_CROSS_CHANNEL; |
| 5510 | if (qp->flags & MLX5_IB_QP_MANAGED_SEND) |
| 5511 | qp_init_attr->create_flags |= IB_QP_CREATE_MANAGED_SEND; |
| 5512 | if (qp->flags & MLX5_IB_QP_MANAGED_RECV) |
| 5513 | qp_init_attr->create_flags |= IB_QP_CREATE_MANAGED_RECV; |
Haggai Eran | b11a4f9 | 2016-02-29 15:45:03 +0200 | [diff] [blame] | 5514 | if (qp->flags & MLX5_IB_QP_SQPN_QP1) |
| 5515 | qp_init_attr->create_flags |= mlx5_ib_create_qp_sqpn_qp1(); |
Leon Romanovsky | 051f263 | 2015-12-20 12:16:11 +0200 | [diff] [blame] | 5516 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5517 | qp_init_attr->sq_sig_type = qp->sq_signal_bits & MLX5_WQE_CTRL_CQ_UPDATE ? |
| 5518 | IB_SIGNAL_ALL_WR : IB_SIGNAL_REQ_WR; |
| 5519 | |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5520 | out: |
| 5521 | mutex_unlock(&qp->mutex); |
| 5522 | return err; |
| 5523 | } |
| 5524 | |
| 5525 | struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev, |
| 5526 | struct ib_ucontext *context, |
| 5527 | struct ib_udata *udata) |
| 5528 | { |
| 5529 | struct mlx5_ib_dev *dev = to_mdev(ibdev); |
| 5530 | struct mlx5_ib_xrcd *xrcd; |
| 5531 | int err; |
| 5532 | |
Saeed Mahameed | 938fe83 | 2015-05-28 22:28:41 +0300 | [diff] [blame] | 5533 | if (!MLX5_CAP_GEN(dev->mdev, xrc)) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5534 | return ERR_PTR(-ENOSYS); |
| 5535 | |
| 5536 | xrcd = kmalloc(sizeof(*xrcd), GFP_KERNEL); |
| 5537 | if (!xrcd) |
| 5538 | return ERR_PTR(-ENOMEM); |
| 5539 | |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 5540 | err = mlx5_cmd_xrcd_alloc(dev->mdev, &xrcd->xrcdn, 0); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5541 | if (err) { |
| 5542 | kfree(xrcd); |
| 5543 | return ERR_PTR(-ENOMEM); |
| 5544 | } |
| 5545 | |
| 5546 | return &xrcd->ibxrcd; |
| 5547 | } |
| 5548 | |
| 5549 | int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd) |
| 5550 | { |
| 5551 | struct mlx5_ib_dev *dev = to_mdev(xrcd->device); |
| 5552 | u32 xrcdn = to_mxrcd(xrcd)->xrcdn; |
| 5553 | int err; |
| 5554 | |
Yishai Hadas | 5aa3771 | 2018-11-26 08:28:38 +0200 | [diff] [blame] | 5555 | err = mlx5_cmd_xrcd_dealloc(dev->mdev, xrcdn, 0); |
Leon Romanovsky | b081808 | 2018-01-28 11:25:30 +0200 | [diff] [blame] | 5556 | if (err) |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5557 | mlx5_ib_warn(dev, "failed to dealloc xrcdn 0x%x\n", xrcdn); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5558 | |
| 5559 | kfree(xrcd); |
Eli Cohen | e126ba9 | 2013-07-07 17:25:49 +0300 | [diff] [blame] | 5560 | return 0; |
| 5561 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5562 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5563 | static void mlx5_ib_wq_event(struct mlx5_core_qp *core_qp, int type) |
| 5564 | { |
| 5565 | struct mlx5_ib_rwq *rwq = to_mibrwq(core_qp); |
| 5566 | struct mlx5_ib_dev *dev = to_mdev(rwq->ibwq.device); |
| 5567 | struct ib_event event; |
| 5568 | |
| 5569 | if (rwq->ibwq.event_handler) { |
| 5570 | event.device = rwq->ibwq.device; |
| 5571 | event.element.wq = &rwq->ibwq; |
| 5572 | switch (type) { |
| 5573 | case MLX5_EVENT_TYPE_WQ_CATAS_ERROR: |
| 5574 | event.event = IB_EVENT_WQ_FATAL; |
| 5575 | break; |
| 5576 | default: |
| 5577 | mlx5_ib_warn(dev, "Unexpected event type %d on WQ %06x\n", type, core_qp->qpn); |
| 5578 | return; |
| 5579 | } |
| 5580 | |
| 5581 | rwq->ibwq.event_handler(&event, rwq->ibwq.wq_context); |
| 5582 | } |
| 5583 | } |
| 5584 | |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5585 | static int set_delay_drop(struct mlx5_ib_dev *dev) |
| 5586 | { |
| 5587 | int err = 0; |
| 5588 | |
| 5589 | mutex_lock(&dev->delay_drop.lock); |
| 5590 | if (dev->delay_drop.activate) |
| 5591 | goto out; |
| 5592 | |
| 5593 | err = mlx5_core_set_delay_drop(dev->mdev, dev->delay_drop.timeout); |
| 5594 | if (err) |
| 5595 | goto out; |
| 5596 | |
| 5597 | dev->delay_drop.activate = true; |
| 5598 | out: |
| 5599 | mutex_unlock(&dev->delay_drop.lock); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5600 | |
| 5601 | if (!err) |
| 5602 | atomic_inc(&dev->delay_drop.rqs_cnt); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5603 | return err; |
| 5604 | } |
| 5605 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5606 | static int create_rq(struct mlx5_ib_rwq *rwq, struct ib_pd *pd, |
| 5607 | struct ib_wq_init_attr *init_attr) |
| 5608 | { |
| 5609 | struct mlx5_ib_dev *dev; |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 5610 | int has_net_offloads; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5611 | __be64 *rq_pas0; |
| 5612 | void *in; |
| 5613 | void *rqc; |
| 5614 | void *wq; |
| 5615 | int inlen; |
| 5616 | int err; |
| 5617 | |
| 5618 | dev = to_mdev(pd->device); |
| 5619 | |
| 5620 | 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] | 5621 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5622 | if (!in) |
| 5623 | return -ENOMEM; |
| 5624 | |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 5625 | MLX5_SET(create_rq_in, in, uid, to_mpd(pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5626 | rqc = MLX5_ADDR_OF(create_rq_in, in, ctx); |
| 5627 | MLX5_SET(rqc, rqc, mem_rq_type, |
| 5628 | MLX5_RQC_MEM_RQ_TYPE_MEMORY_RQ_INLINE); |
| 5629 | MLX5_SET(rqc, rqc, user_index, rwq->user_index); |
| 5630 | MLX5_SET(rqc, rqc, cqn, to_mcq(init_attr->cq)->mcq.cqn); |
| 5631 | MLX5_SET(rqc, rqc, state, MLX5_RQC_STATE_RST); |
| 5632 | MLX5_SET(rqc, rqc, flush_in_error_en, 1); |
| 5633 | wq = MLX5_ADDR_OF(rqc, rqc, wq); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5634 | MLX5_SET(wq, wq, wq_type, |
| 5635 | rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ ? |
| 5636 | MLX5_WQ_TYPE_CYCLIC_STRIDING_RQ : MLX5_WQ_TYPE_CYCLIC); |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 5637 | if (init_attr->create_flags & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 5638 | if (!MLX5_CAP_GEN(dev->mdev, end_pad)) { |
| 5639 | mlx5_ib_dbg(dev, "Scatter end padding is not supported\n"); |
| 5640 | err = -EOPNOTSUPP; |
| 5641 | goto out; |
| 5642 | } else { |
| 5643 | MLX5_SET(wq, wq, end_padding_mode, MLX5_WQ_END_PAD_MODE_ALIGN); |
| 5644 | } |
| 5645 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5646 | MLX5_SET(wq, wq, log_wq_stride, rwq->log_rq_stride); |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5647 | if (rwq->create_flags & MLX5_IB_WQ_FLAGS_STRIDING_RQ) { |
| 5648 | MLX5_SET(wq, wq, two_byte_shift_en, rwq->two_byte_shift_en); |
| 5649 | MLX5_SET(wq, wq, log_wqe_stride_size, |
| 5650 | rwq->single_stride_log_num_of_bytes - |
| 5651 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES); |
| 5652 | MLX5_SET(wq, wq, log_wqe_num_of_strides, rwq->log_num_strides - |
| 5653 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES); |
| 5654 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5655 | MLX5_SET(wq, wq, log_wq_sz, rwq->log_rq_size); |
| 5656 | MLX5_SET(wq, wq, pd, to_mpd(pd)->pdn); |
| 5657 | MLX5_SET(wq, wq, page_offset, rwq->rq_page_offset); |
| 5658 | MLX5_SET(wq, wq, log_wq_pg_sz, rwq->log_page_size); |
| 5659 | MLX5_SET(wq, wq, wq_signature, rwq->wq_sig); |
| 5660 | MLX5_SET64(wq, wq, dbr_addr, rwq->db.dma); |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 5661 | has_net_offloads = MLX5_CAP_GEN(dev->mdev, eth_net_offloads); |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 5662 | if (init_attr->create_flags & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 5663 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 5664 | mlx5_ib_dbg(dev, "VLAN offloads are not supported\n"); |
| 5665 | err = -EOPNOTSUPP; |
| 5666 | goto out; |
| 5667 | } |
| 5668 | } else { |
| 5669 | MLX5_SET(rqc, rqc, vsd, 1); |
| 5670 | } |
Noa Osherovich | 4be6da1 | 2017-01-18 15:40:04 +0200 | [diff] [blame] | 5671 | if (init_attr->create_flags & IB_WQ_FLAGS_SCATTER_FCS) { |
| 5672 | if (!(has_net_offloads && MLX5_CAP_ETH(dev->mdev, scatter_fcs))) { |
| 5673 | mlx5_ib_dbg(dev, "Scatter FCS is not supported\n"); |
| 5674 | err = -EOPNOTSUPP; |
| 5675 | goto out; |
| 5676 | } |
| 5677 | MLX5_SET(rqc, rqc, scatter_fcs, 1); |
| 5678 | } |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5679 | if (init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 5680 | if (!(dev->ib_dev.attrs.raw_packet_caps & |
| 5681 | IB_RAW_PACKET_CAP_DELAY_DROP)) { |
| 5682 | mlx5_ib_dbg(dev, "Delay drop is not supported\n"); |
| 5683 | err = -EOPNOTSUPP; |
| 5684 | goto out; |
| 5685 | } |
| 5686 | MLX5_SET(rqc, rqc, delay_drop_en, 1); |
| 5687 | } |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5688 | rq_pas0 = (__be64 *)MLX5_ADDR_OF(wq, wq, pas); |
| 5689 | mlx5_ib_populate_pas(dev, rwq->umem, rwq->page_shift, rq_pas0, 0); |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5690 | err = mlx5_core_create_rq_tracked(dev->mdev, in, inlen, &rwq->core_qp); |
Maor Gottlieb | 03404e8 | 2017-05-30 10:29:13 +0300 | [diff] [blame] | 5691 | if (!err && init_attr->create_flags & IB_WQ_FLAGS_DELAY_DROP) { |
| 5692 | err = set_delay_drop(dev); |
| 5693 | if (err) { |
| 5694 | mlx5_ib_warn(dev, "Failed to enable delay drop err=%d\n", |
| 5695 | err); |
| 5696 | mlx5_core_destroy_rq_tracked(dev->mdev, &rwq->core_qp); |
| 5697 | } else { |
| 5698 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_DELAY_DROP; |
| 5699 | } |
| 5700 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 5701 | out: |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5702 | kvfree(in); |
| 5703 | return err; |
| 5704 | } |
| 5705 | |
| 5706 | static int set_user_rq_size(struct mlx5_ib_dev *dev, |
| 5707 | struct ib_wq_init_attr *wq_init_attr, |
| 5708 | struct mlx5_ib_create_wq *ucmd, |
| 5709 | struct mlx5_ib_rwq *rwq) |
| 5710 | { |
| 5711 | /* Sanity check RQ size before proceeding */ |
| 5712 | if (wq_init_attr->max_wr > (1 << MLX5_CAP_GEN(dev->mdev, log_max_wq_sz))) |
| 5713 | return -EINVAL; |
| 5714 | |
| 5715 | if (!ucmd->rq_wqe_count) |
| 5716 | return -EINVAL; |
| 5717 | |
| 5718 | rwq->wqe_count = ucmd->rq_wqe_count; |
| 5719 | rwq->wqe_shift = ucmd->rq_wqe_shift; |
Leon Romanovsky | 0dfe452 | 2018-08-01 14:25:41 -0700 | [diff] [blame] | 5720 | if (check_shl_overflow(rwq->wqe_count, rwq->wqe_shift, &rwq->buf_size)) |
| 5721 | return -EINVAL; |
| 5722 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5723 | rwq->log_rq_stride = rwq->wqe_shift; |
| 5724 | rwq->log_rq_size = ilog2(rwq->wqe_count); |
| 5725 | return 0; |
| 5726 | } |
| 5727 | |
| 5728 | static int prepare_user_rq(struct ib_pd *pd, |
| 5729 | struct ib_wq_init_attr *init_attr, |
| 5730 | struct ib_udata *udata, |
| 5731 | struct mlx5_ib_rwq *rwq) |
| 5732 | { |
| 5733 | struct mlx5_ib_dev *dev = to_mdev(pd->device); |
| 5734 | struct mlx5_ib_create_wq ucmd = {}; |
| 5735 | int err; |
| 5736 | size_t required_cmd_sz; |
| 5737 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5738 | required_cmd_sz = offsetof(typeof(ucmd), single_stride_log_num_of_bytes) |
| 5739 | + sizeof(ucmd.single_stride_log_num_of_bytes); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5740 | if (udata->inlen < required_cmd_sz) { |
| 5741 | mlx5_ib_dbg(dev, "invalid inlen\n"); |
| 5742 | return -EINVAL; |
| 5743 | } |
| 5744 | |
| 5745 | if (udata->inlen > sizeof(ucmd) && |
| 5746 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 5747 | udata->inlen - sizeof(ucmd))) { |
| 5748 | mlx5_ib_dbg(dev, "inlen is not supported\n"); |
| 5749 | return -EOPNOTSUPP; |
| 5750 | } |
| 5751 | |
| 5752 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) { |
| 5753 | mlx5_ib_dbg(dev, "copy failed\n"); |
| 5754 | return -EFAULT; |
| 5755 | } |
| 5756 | |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5757 | if (ucmd.comp_mask & (~MLX5_IB_CREATE_WQ_STRIDING_RQ)) { |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5758 | mlx5_ib_dbg(dev, "invalid comp mask\n"); |
| 5759 | return -EOPNOTSUPP; |
Noa Osherovich | ccc8708 | 2017-10-17 18:01:13 +0300 | [diff] [blame] | 5760 | } else if (ucmd.comp_mask & MLX5_IB_CREATE_WQ_STRIDING_RQ) { |
| 5761 | if (!MLX5_CAP_GEN(dev->mdev, striding_rq)) { |
| 5762 | mlx5_ib_dbg(dev, "Striding RQ is not supported\n"); |
| 5763 | return -EOPNOTSUPP; |
| 5764 | } |
| 5765 | if ((ucmd.single_stride_log_num_of_bytes < |
| 5766 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES) || |
| 5767 | (ucmd.single_stride_log_num_of_bytes > |
| 5768 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES)) { |
| 5769 | mlx5_ib_dbg(dev, "Invalid log stride size (%u. Range is %u - %u)\n", |
| 5770 | ucmd.single_stride_log_num_of_bytes, |
| 5771 | MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES, |
| 5772 | MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES); |
| 5773 | return -EINVAL; |
| 5774 | } |
| 5775 | if ((ucmd.single_wqe_log_num_of_strides > |
| 5776 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES) || |
| 5777 | (ucmd.single_wqe_log_num_of_strides < |
| 5778 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES)) { |
| 5779 | mlx5_ib_dbg(dev, "Invalid log num strides (%u. Range is %u - %u)\n", |
| 5780 | ucmd.single_wqe_log_num_of_strides, |
| 5781 | MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES, |
| 5782 | MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES); |
| 5783 | return -EINVAL; |
| 5784 | } |
| 5785 | rwq->single_stride_log_num_of_bytes = |
| 5786 | ucmd.single_stride_log_num_of_bytes; |
| 5787 | rwq->log_num_strides = ucmd.single_wqe_log_num_of_strides; |
| 5788 | rwq->two_byte_shift_en = !!ucmd.two_byte_shift_en; |
| 5789 | rwq->create_flags |= MLX5_IB_WQ_FLAGS_STRIDING_RQ; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5790 | } |
| 5791 | |
| 5792 | err = set_user_rq_size(dev, init_attr, &ucmd, rwq); |
| 5793 | if (err) { |
| 5794 | mlx5_ib_dbg(dev, "err %d\n", err); |
| 5795 | return err; |
| 5796 | } |
| 5797 | |
| 5798 | err = create_user_rq(dev, pd, rwq, &ucmd); |
| 5799 | if (err) { |
| 5800 | mlx5_ib_dbg(dev, "err %d\n", err); |
Gal Pressman | 645ba59 | 2018-10-08 19:44:03 +0300 | [diff] [blame] | 5801 | return err; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5802 | } |
| 5803 | |
| 5804 | rwq->user_index = ucmd.user_index; |
| 5805 | return 0; |
| 5806 | } |
| 5807 | |
| 5808 | struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd, |
| 5809 | struct ib_wq_init_attr *init_attr, |
| 5810 | struct ib_udata *udata) |
| 5811 | { |
| 5812 | struct mlx5_ib_dev *dev; |
| 5813 | struct mlx5_ib_rwq *rwq; |
| 5814 | struct mlx5_ib_create_wq_resp resp = {}; |
| 5815 | size_t min_resp_len; |
| 5816 | int err; |
| 5817 | |
| 5818 | if (!udata) |
| 5819 | return ERR_PTR(-ENOSYS); |
| 5820 | |
| 5821 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 5822 | if (udata->outlen && udata->outlen < min_resp_len) |
| 5823 | return ERR_PTR(-EINVAL); |
| 5824 | |
| 5825 | dev = to_mdev(pd->device); |
| 5826 | switch (init_attr->wq_type) { |
| 5827 | case IB_WQT_RQ: |
| 5828 | rwq = kzalloc(sizeof(*rwq), GFP_KERNEL); |
| 5829 | if (!rwq) |
| 5830 | return ERR_PTR(-ENOMEM); |
| 5831 | err = prepare_user_rq(pd, init_attr, udata, rwq); |
| 5832 | if (err) |
| 5833 | goto err; |
| 5834 | err = create_rq(rwq, pd, init_attr); |
| 5835 | if (err) |
| 5836 | goto err_user_rq; |
| 5837 | break; |
| 5838 | default: |
| 5839 | mlx5_ib_dbg(dev, "unsupported wq type %d\n", |
| 5840 | init_attr->wq_type); |
| 5841 | return ERR_PTR(-EINVAL); |
| 5842 | } |
| 5843 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5844 | rwq->ibwq.wq_num = rwq->core_qp.qpn; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5845 | rwq->ibwq.state = IB_WQS_RESET; |
| 5846 | if (udata->outlen) { |
| 5847 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 5848 | sizeof(resp.response_length); |
| 5849 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 5850 | if (err) |
| 5851 | goto err_copy; |
| 5852 | } |
| 5853 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5854 | rwq->core_qp.event = mlx5_ib_wq_event; |
| 5855 | rwq->ibwq.event_handler = init_attr->event_handler; |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5856 | return &rwq->ibwq; |
| 5857 | |
| 5858 | err_copy: |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5859 | mlx5_core_destroy_rq_tracked(dev->mdev, &rwq->core_qp); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5860 | err_user_rq: |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5861 | destroy_user_rq(dev, pd, rwq); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5862 | err: |
| 5863 | kfree(rwq); |
| 5864 | return ERR_PTR(err); |
| 5865 | } |
| 5866 | |
| 5867 | int mlx5_ib_destroy_wq(struct ib_wq *wq) |
| 5868 | { |
| 5869 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 5870 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 5871 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 5872 | mlx5_core_destroy_rq_tracked(dev->mdev, &rwq->core_qp); |
Maor Gottlieb | fe248c3 | 2017-05-30 10:29:14 +0300 | [diff] [blame] | 5873 | destroy_user_rq(dev, wq->pd, rwq); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5874 | kfree(rwq); |
| 5875 | |
| 5876 | return 0; |
| 5877 | } |
| 5878 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5879 | struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device, |
| 5880 | struct ib_rwq_ind_table_init_attr *init_attr, |
| 5881 | struct ib_udata *udata) |
| 5882 | { |
| 5883 | struct mlx5_ib_dev *dev = to_mdev(device); |
| 5884 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl; |
| 5885 | int sz = 1 << init_attr->log_ind_tbl_size; |
| 5886 | struct mlx5_ib_create_rwq_ind_tbl_resp resp = {}; |
| 5887 | size_t min_resp_len; |
| 5888 | int inlen; |
| 5889 | int err; |
| 5890 | int i; |
| 5891 | u32 *in; |
| 5892 | void *rqtc; |
| 5893 | |
| 5894 | if (udata->inlen > 0 && |
| 5895 | !ib_is_udata_cleared(udata, 0, |
| 5896 | udata->inlen)) |
| 5897 | return ERR_PTR(-EOPNOTSUPP); |
| 5898 | |
Maor Gottlieb | efd7f40 | 2016-10-27 16:36:40 +0300 | [diff] [blame] | 5899 | if (init_attr->log_ind_tbl_size > |
| 5900 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)) { |
| 5901 | mlx5_ib_dbg(dev, "log_ind_tbl_size = %d is bigger than supported = %d\n", |
| 5902 | init_attr->log_ind_tbl_size, |
| 5903 | MLX5_CAP_GEN(dev->mdev, log_max_rqt_size)); |
| 5904 | return ERR_PTR(-EINVAL); |
| 5905 | } |
| 5906 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5907 | min_resp_len = offsetof(typeof(resp), reserved) + sizeof(resp.reserved); |
| 5908 | if (udata->outlen && udata->outlen < min_resp_len) |
| 5909 | return ERR_PTR(-EINVAL); |
| 5910 | |
| 5911 | rwq_ind_tbl = kzalloc(sizeof(*rwq_ind_tbl), GFP_KERNEL); |
| 5912 | if (!rwq_ind_tbl) |
| 5913 | return ERR_PTR(-ENOMEM); |
| 5914 | |
| 5915 | inlen = MLX5_ST_SZ_BYTES(create_rqt_in) + sizeof(u32) * sz; |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5916 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5917 | if (!in) { |
| 5918 | err = -ENOMEM; |
| 5919 | goto err; |
| 5920 | } |
| 5921 | |
| 5922 | rqtc = MLX5_ADDR_OF(create_rqt_in, in, rqt_context); |
| 5923 | |
| 5924 | MLX5_SET(rqtc, rqtc, rqt_actual_size, sz); |
| 5925 | MLX5_SET(rqtc, rqtc, rqt_max_size, sz); |
| 5926 | |
| 5927 | for (i = 0; i < sz; i++) |
| 5928 | MLX5_SET(rqtc, rqtc, rq_num[i], init_attr->ind_tbl[i]->wq_num); |
| 5929 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 5930 | rwq_ind_tbl->uid = to_mpd(init_attr->ind_tbl[0]->pd)->uid; |
| 5931 | MLX5_SET(create_rqt_in, in, uid, rwq_ind_tbl->uid); |
| 5932 | |
Yishai Hadas | c5f9092 | 2016-05-23 15:20:53 +0300 | [diff] [blame] | 5933 | err = mlx5_core_create_rqt(dev->mdev, in, inlen, &rwq_ind_tbl->rqtn); |
| 5934 | kvfree(in); |
| 5935 | |
| 5936 | if (err) |
| 5937 | goto err; |
| 5938 | |
| 5939 | rwq_ind_tbl->ib_rwq_ind_tbl.ind_tbl_num = rwq_ind_tbl->rqtn; |
| 5940 | if (udata->outlen) { |
| 5941 | resp.response_length = offsetof(typeof(resp), response_length) + |
| 5942 | sizeof(resp.response_length); |
| 5943 | err = ib_copy_to_udata(udata, &resp, resp.response_length); |
| 5944 | if (err) |
| 5945 | goto err_copy; |
| 5946 | } |
| 5947 | |
| 5948 | return &rwq_ind_tbl->ib_rwq_ind_tbl; |
| 5949 | |
| 5950 | err_copy: |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 5951 | 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] | 5952 | err: |
| 5953 | kfree(rwq_ind_tbl); |
| 5954 | return ERR_PTR(err); |
| 5955 | } |
| 5956 | |
| 5957 | int mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl) |
| 5958 | { |
| 5959 | struct mlx5_ib_rwq_ind_table *rwq_ind_tbl = to_mrwq_ind_table(ib_rwq_ind_tbl); |
| 5960 | struct mlx5_ib_dev *dev = to_mdev(ib_rwq_ind_tbl->device); |
| 5961 | |
Yishai Hadas | 5deba86 | 2018-09-20 21:39:28 +0300 | [diff] [blame] | 5962 | 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] | 5963 | |
| 5964 | kfree(rwq_ind_tbl); |
| 5965 | return 0; |
| 5966 | } |
| 5967 | |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5968 | int mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr, |
| 5969 | u32 wq_attr_mask, struct ib_udata *udata) |
| 5970 | { |
| 5971 | struct mlx5_ib_dev *dev = to_mdev(wq->device); |
| 5972 | struct mlx5_ib_rwq *rwq = to_mrwq(wq); |
| 5973 | struct mlx5_ib_modify_wq ucmd = {}; |
| 5974 | size_t required_cmd_sz; |
| 5975 | int curr_wq_state; |
| 5976 | int wq_state; |
| 5977 | int inlen; |
| 5978 | int err; |
| 5979 | void *rqc; |
| 5980 | void *in; |
| 5981 | |
| 5982 | required_cmd_sz = offsetof(typeof(ucmd), reserved) + sizeof(ucmd.reserved); |
| 5983 | if (udata->inlen < required_cmd_sz) |
| 5984 | return -EINVAL; |
| 5985 | |
| 5986 | if (udata->inlen > sizeof(ucmd) && |
| 5987 | !ib_is_udata_cleared(udata, sizeof(ucmd), |
| 5988 | udata->inlen - sizeof(ucmd))) |
| 5989 | return -EOPNOTSUPP; |
| 5990 | |
| 5991 | if (ib_copy_from_udata(&ucmd, udata, min(sizeof(ucmd), udata->inlen))) |
| 5992 | return -EFAULT; |
| 5993 | |
| 5994 | if (ucmd.comp_mask || ucmd.reserved) |
| 5995 | return -EOPNOTSUPP; |
| 5996 | |
| 5997 | inlen = MLX5_ST_SZ_BYTES(modify_rq_in); |
Leon Romanovsky | 1b9a07e | 2017-05-10 21:32:18 +0300 | [diff] [blame] | 5998 | in = kvzalloc(inlen, GFP_KERNEL); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 5999 | if (!in) |
| 6000 | return -ENOMEM; |
| 6001 | |
| 6002 | rqc = MLX5_ADDR_OF(modify_rq_in, in, ctx); |
| 6003 | |
| 6004 | curr_wq_state = (wq_attr_mask & IB_WQ_CUR_STATE) ? |
| 6005 | wq_attr->curr_wq_state : wq->state; |
| 6006 | wq_state = (wq_attr_mask & IB_WQ_STATE) ? |
| 6007 | wq_attr->wq_state : curr_wq_state; |
| 6008 | if (curr_wq_state == IB_WQS_ERR) |
| 6009 | curr_wq_state = MLX5_RQC_STATE_ERR; |
| 6010 | if (wq_state == IB_WQS_ERR) |
| 6011 | wq_state = MLX5_RQC_STATE_ERR; |
| 6012 | MLX5_SET(modify_rq_in, in, rq_state, curr_wq_state); |
Yishai Hadas | 34d5758 | 2018-09-20 21:39:21 +0300 | [diff] [blame] | 6013 | MLX5_SET(modify_rq_in, in, uid, to_mpd(wq->pd)->uid); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6014 | MLX5_SET(rqc, rqc, state, wq_state); |
| 6015 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6016 | if (wq_attr_mask & IB_WQ_FLAGS) { |
| 6017 | if (wq_attr->flags_mask & IB_WQ_FLAGS_CVLAN_STRIPPING) { |
| 6018 | if (!(MLX5_CAP_GEN(dev->mdev, eth_net_offloads) && |
| 6019 | MLX5_CAP_ETH(dev->mdev, vlan_cap))) { |
| 6020 | mlx5_ib_dbg(dev, "VLAN offloads are not " |
| 6021 | "supported\n"); |
| 6022 | err = -EOPNOTSUPP; |
| 6023 | goto out; |
| 6024 | } |
| 6025 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 6026 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_VSD); |
| 6027 | MLX5_SET(rqc, rqc, vsd, |
| 6028 | (wq_attr->flags & IB_WQ_FLAGS_CVLAN_STRIPPING) ? 0 : 1); |
| 6029 | } |
Noa Osherovich | b1383aa | 2017-10-29 13:59:45 +0200 | [diff] [blame] | 6030 | |
| 6031 | if (wq_attr->flags_mask & IB_WQ_FLAGS_PCI_WRITE_END_PADDING) { |
| 6032 | mlx5_ib_dbg(dev, "Modifying scatter end padding is not supported\n"); |
| 6033 | err = -EOPNOTSUPP; |
| 6034 | goto out; |
| 6035 | } |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6036 | } |
| 6037 | |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6038 | if (curr_wq_state == IB_WQS_RESET && wq_state == IB_WQS_RDY) { |
| 6039 | if (MLX5_CAP_GEN(dev->mdev, modify_rq_counter_set_id)) { |
| 6040 | MLX5_SET64(modify_rq_in, in, modify_bitmask, |
| 6041 | MLX5_MODIFY_RQ_IN_MODIFY_BITMASK_RQ_COUNTER_SET_ID); |
Parav Pandit | e1f24a7 | 2017-04-16 07:29:29 +0300 | [diff] [blame] | 6042 | MLX5_SET(rqc, rqc, counter_set_id, |
| 6043 | dev->port->cnts.set_id); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6044 | } else |
Jason Gunthorpe | 5a738b5 | 2018-09-20 16:42:24 -0600 | [diff] [blame] | 6045 | dev_info_once( |
| 6046 | &dev->ib_dev.dev, |
| 6047 | "Receive WQ counters are not supported on current FW\n"); |
Majd Dibbiny | 23a6964 | 2017-01-18 15:25:10 +0200 | [diff] [blame] | 6048 | } |
| 6049 | |
Yishai Hadas | 350d0e4 | 2016-08-28 14:58:18 +0300 | [diff] [blame] | 6050 | err = mlx5_core_modify_rq(dev->mdev, rwq->core_qp.qpn, in, inlen); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6051 | if (!err) |
| 6052 | rwq->ibwq.state = (wq_state == MLX5_RQC_STATE_ERR) ? IB_WQS_ERR : wq_state; |
| 6053 | |
Noa Osherovich | b1f74a8 | 2017-01-18 15:40:02 +0200 | [diff] [blame] | 6054 | out: |
| 6055 | kvfree(in); |
Yishai Hadas | 79b20a6 | 2016-05-23 15:20:50 +0300 | [diff] [blame] | 6056 | return err; |
| 6057 | } |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6058 | |
| 6059 | struct mlx5_ib_drain_cqe { |
| 6060 | struct ib_cqe cqe; |
| 6061 | struct completion done; |
| 6062 | }; |
| 6063 | |
| 6064 | static void mlx5_ib_drain_qp_done(struct ib_cq *cq, struct ib_wc *wc) |
| 6065 | { |
| 6066 | struct mlx5_ib_drain_cqe *cqe = container_of(wc->wr_cqe, |
| 6067 | struct mlx5_ib_drain_cqe, |
| 6068 | cqe); |
| 6069 | |
| 6070 | complete(&cqe->done); |
| 6071 | } |
| 6072 | |
| 6073 | /* This function returns only once the drained WR was completed */ |
| 6074 | static void handle_drain_completion(struct ib_cq *cq, |
| 6075 | struct mlx5_ib_drain_cqe *sdrain, |
| 6076 | struct mlx5_ib_dev *dev) |
| 6077 | { |
| 6078 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6079 | |
| 6080 | if (cq->poll_ctx == IB_POLL_DIRECT) { |
| 6081 | while (wait_for_completion_timeout(&sdrain->done, HZ / 10) <= 0) |
| 6082 | ib_process_cq_direct(cq, -1); |
| 6083 | return; |
| 6084 | } |
| 6085 | |
| 6086 | if (mdev->state == MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6087 | struct mlx5_ib_cq *mcq = to_mcq(cq); |
| 6088 | bool triggered = false; |
| 6089 | unsigned long flags; |
| 6090 | |
| 6091 | spin_lock_irqsave(&dev->reset_flow_resource_lock, flags); |
| 6092 | /* Make sure that the CQ handler won't run if wasn't run yet */ |
| 6093 | if (!mcq->mcq.reset_notify_added) |
| 6094 | mcq->mcq.reset_notify_added = 1; |
| 6095 | else |
| 6096 | triggered = true; |
| 6097 | spin_unlock_irqrestore(&dev->reset_flow_resource_lock, flags); |
| 6098 | |
| 6099 | if (triggered) { |
| 6100 | /* Wait for any scheduled/running task to be ended */ |
| 6101 | switch (cq->poll_ctx) { |
| 6102 | case IB_POLL_SOFTIRQ: |
| 6103 | irq_poll_disable(&cq->iop); |
| 6104 | irq_poll_enable(&cq->iop); |
| 6105 | break; |
| 6106 | case IB_POLL_WORKQUEUE: |
| 6107 | cancel_work_sync(&cq->work); |
| 6108 | break; |
| 6109 | default: |
| 6110 | WARN_ON_ONCE(1); |
| 6111 | } |
| 6112 | } |
| 6113 | |
| 6114 | /* Run the CQ handler - this makes sure that the drain WR will |
| 6115 | * be processed if wasn't processed yet. |
| 6116 | */ |
| 6117 | mcq->mcq.comp(&mcq->mcq); |
| 6118 | } |
| 6119 | |
| 6120 | wait_for_completion(&sdrain->done); |
| 6121 | } |
| 6122 | |
| 6123 | void mlx5_ib_drain_sq(struct ib_qp *qp) |
| 6124 | { |
| 6125 | struct ib_cq *cq = qp->send_cq; |
| 6126 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 6127 | struct mlx5_ib_drain_cqe sdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 6128 | const struct ib_send_wr *bad_swr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6129 | struct ib_rdma_wr swr = { |
| 6130 | .wr = { |
| 6131 | .next = NULL, |
| 6132 | { .wr_cqe = &sdrain.cqe, }, |
| 6133 | .opcode = IB_WR_RDMA_WRITE, |
| 6134 | }, |
| 6135 | }; |
| 6136 | int ret; |
| 6137 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 6138 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6139 | |
| 6140 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 6141 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6142 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 6143 | return; |
| 6144 | } |
| 6145 | |
| 6146 | sdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 6147 | init_completion(&sdrain.done); |
| 6148 | |
| 6149 | ret = _mlx5_ib_post_send(qp, &swr.wr, &bad_swr, true); |
| 6150 | if (ret) { |
| 6151 | WARN_ONCE(ret, "failed to drain send queue: %d\n", ret); |
| 6152 | return; |
| 6153 | } |
| 6154 | |
| 6155 | handle_drain_completion(cq, &sdrain, dev); |
| 6156 | } |
| 6157 | |
| 6158 | void mlx5_ib_drain_rq(struct ib_qp *qp) |
| 6159 | { |
| 6160 | struct ib_cq *cq = qp->recv_cq; |
| 6161 | struct ib_qp_attr attr = { .qp_state = IB_QPS_ERR }; |
| 6162 | struct mlx5_ib_drain_cqe rdrain; |
Bart Van Assche | d34ac5c | 2018-07-18 09:25:32 -0700 | [diff] [blame] | 6163 | struct ib_recv_wr rwr = {}; |
| 6164 | const struct ib_recv_wr *bad_rwr; |
Yishai Hadas | d0e84c0 | 2018-06-19 10:43:55 +0300 | [diff] [blame] | 6165 | int ret; |
| 6166 | struct mlx5_ib_dev *dev = to_mdev(qp->device); |
| 6167 | struct mlx5_core_dev *mdev = dev->mdev; |
| 6168 | |
| 6169 | ret = ib_modify_qp(qp, &attr, IB_QP_STATE); |
| 6170 | if (ret && mdev->state != MLX5_DEVICE_STATE_INTERNAL_ERROR) { |
| 6171 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 6172 | return; |
| 6173 | } |
| 6174 | |
| 6175 | rwr.wr_cqe = &rdrain.cqe; |
| 6176 | rdrain.cqe.done = mlx5_ib_drain_qp_done; |
| 6177 | init_completion(&rdrain.done); |
| 6178 | |
| 6179 | ret = _mlx5_ib_post_recv(qp, &rwr, &bad_rwr, true); |
| 6180 | if (ret) { |
| 6181 | WARN_ONCE(ret, "failed to drain recv queue: %d\n", ret); |
| 6182 | return; |
| 6183 | } |
| 6184 | |
| 6185 | handle_drain_completion(cq, &rdrain, dev); |
| 6186 | } |