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