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