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