Bob Pearson | 63fa15d | 2020-08-27 09:54:40 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. |
| 4 | * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/skbuff.h> |
yonatanc | cee2688 | 2017-04-20 20:55:55 +0300 | [diff] [blame] | 8 | #include <crypto/hash.h> |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 9 | |
| 10 | #include "rxe.h" |
| 11 | #include "rxe_loc.h" |
| 12 | #include "rxe_queue.h" |
| 13 | |
| 14 | static int next_opcode(struct rxe_qp *qp, struct rxe_send_wqe *wqe, |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 15 | u32 opcode); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 16 | |
| 17 | static inline void retry_first_write_send(struct rxe_qp *qp, |
| 18 | struct rxe_send_wqe *wqe, |
Kamal Heib | c498e82 | 2017-06-15 11:29:04 +0300 | [diff] [blame] | 19 | unsigned int mask, int npsn) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 20 | { |
| 21 | int i; |
| 22 | |
| 23 | for (i = 0; i < npsn; i++) { |
| 24 | int to_send = (wqe->dma.resid > qp->mtu) ? |
| 25 | qp->mtu : wqe->dma.resid; |
| 26 | |
| 27 | qp->req.opcode = next_opcode(qp, wqe, |
| 28 | wqe->wr.opcode); |
| 29 | |
| 30 | if (wqe->wr.send_flags & IB_SEND_INLINE) { |
| 31 | wqe->dma.resid -= to_send; |
| 32 | wqe->dma.sge_offset += to_send; |
| 33 | } else { |
| 34 | advance_dma_data(&wqe->dma, to_send); |
| 35 | } |
| 36 | if (mask & WR_WRITE_MASK) |
| 37 | wqe->iova += qp->mtu; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | static void req_retry(struct rxe_qp *qp) |
| 42 | { |
| 43 | struct rxe_send_wqe *wqe; |
| 44 | unsigned int wqe_index; |
| 45 | unsigned int mask; |
| 46 | int npsn; |
| 47 | int first = 1; |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 48 | struct rxe_queue *q = qp->sq.queue; |
| 49 | unsigned int cons; |
| 50 | unsigned int prod; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 51 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 52 | cons = queue_get_consumer(q, QUEUE_TYPE_FROM_CLIENT); |
| 53 | prod = queue_get_producer(q, QUEUE_TYPE_FROM_CLIENT); |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 54 | |
| 55 | qp->req.wqe_index = cons; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 56 | qp->req.psn = qp->comp.psn; |
| 57 | qp->req.opcode = -1; |
| 58 | |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 59 | for (wqe_index = cons; wqe_index != prod; |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 60 | wqe_index = queue_next_index(q, wqe_index)) { |
| 61 | wqe = queue_addr_from_index(qp->sq.queue, wqe_index); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 62 | mask = wr_opcode_mask(wqe->wr.opcode, qp); |
| 63 | |
| 64 | if (wqe->state == wqe_state_posted) |
| 65 | break; |
| 66 | |
| 67 | if (wqe->state == wqe_state_done) |
| 68 | continue; |
| 69 | |
| 70 | wqe->iova = (mask & WR_ATOMIC_MASK) ? |
| 71 | wqe->wr.wr.atomic.remote_addr : |
| 72 | (mask & WR_READ_OR_WRITE_MASK) ? |
| 73 | wqe->wr.wr.rdma.remote_addr : |
| 74 | 0; |
| 75 | |
| 76 | if (!first || (mask & WR_READ_MASK) == 0) { |
| 77 | wqe->dma.resid = wqe->dma.length; |
| 78 | wqe->dma.cur_sge = 0; |
| 79 | wqe->dma.sge_offset = 0; |
| 80 | } |
| 81 | |
| 82 | if (first) { |
| 83 | first = 0; |
| 84 | |
Vijay Immanuel | 030e46e | 2018-06-13 18:48:07 -0700 | [diff] [blame] | 85 | if (mask & WR_WRITE_OR_SEND_MASK) { |
| 86 | npsn = (qp->comp.psn - wqe->first_psn) & |
| 87 | BTH_PSN_MASK; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 88 | retry_first_write_send(qp, wqe, mask, npsn); |
Vijay Immanuel | 030e46e | 2018-06-13 18:48:07 -0700 | [diff] [blame] | 89 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 90 | |
Vijay Immanuel | 030e46e | 2018-06-13 18:48:07 -0700 | [diff] [blame] | 91 | if (mask & WR_READ_MASK) { |
| 92 | npsn = (wqe->dma.length - wqe->dma.resid) / |
| 93 | qp->mtu; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 94 | wqe->iova += npsn * qp->mtu; |
Vijay Immanuel | 030e46e | 2018-06-13 18:48:07 -0700 | [diff] [blame] | 95 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | wqe->state = wqe_state_posted; |
| 99 | } |
| 100 | } |
| 101 | |
Kees Cook | 3bfbea7 | 2017-10-24 03:28:27 -0700 | [diff] [blame] | 102 | void rnr_nak_timer(struct timer_list *t) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 103 | { |
Kees Cook | 3bfbea7 | 2017-10-24 03:28:27 -0700 | [diff] [blame] | 104 | struct rxe_qp *qp = from_timer(qp, t, rnr_nak_timer); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 105 | |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 106 | pr_debug("qp#%d rnr nak timer fired\n", qp_num(qp)); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 107 | rxe_run_task(&qp->req.task, 1); |
| 108 | } |
| 109 | |
| 110 | static struct rxe_send_wqe *req_next_wqe(struct rxe_qp *qp) |
| 111 | { |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 112 | struct rxe_send_wqe *wqe; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 113 | unsigned long flags; |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 114 | struct rxe_queue *q = qp->sq.queue; |
| 115 | unsigned int index = qp->req.wqe_index; |
| 116 | unsigned int cons; |
| 117 | unsigned int prod; |
| 118 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 119 | wqe = queue_head(q, QUEUE_TYPE_FROM_CLIENT); |
| 120 | cons = queue_get_consumer(q, QUEUE_TYPE_FROM_CLIENT); |
| 121 | prod = queue_get_producer(q, QUEUE_TYPE_FROM_CLIENT); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 122 | |
| 123 | if (unlikely(qp->req.state == QP_STATE_DRAIN)) { |
| 124 | /* check to see if we are drained; |
| 125 | * state_lock used by requester and completer |
| 126 | */ |
| 127 | spin_lock_irqsave(&qp->state_lock, flags); |
| 128 | do { |
| 129 | if (qp->req.state != QP_STATE_DRAIN) { |
| 130 | /* comp just finished */ |
| 131 | spin_unlock_irqrestore(&qp->state_lock, |
| 132 | flags); |
| 133 | break; |
| 134 | } |
| 135 | |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 136 | if (wqe && ((index != cons) || |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 137 | (wqe->state != wqe_state_posted))) { |
| 138 | /* comp not done yet */ |
| 139 | spin_unlock_irqrestore(&qp->state_lock, |
| 140 | flags); |
| 141 | break; |
| 142 | } |
| 143 | |
| 144 | qp->req.state = QP_STATE_DRAINED; |
| 145 | spin_unlock_irqrestore(&qp->state_lock, flags); |
| 146 | |
| 147 | if (qp->ibqp.event_handler) { |
| 148 | struct ib_event ev; |
| 149 | |
| 150 | ev.device = qp->ibqp.device; |
| 151 | ev.element.qp = &qp->ibqp; |
| 152 | ev.event = IB_EVENT_SQ_DRAINED; |
| 153 | qp->ibqp.event_handler(&ev, |
| 154 | qp->ibqp.qp_context); |
| 155 | } |
| 156 | } while (0); |
| 157 | } |
| 158 | |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 159 | if (index == prod) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 160 | return NULL; |
| 161 | |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 162 | wqe = queue_addr_from_index(q, index); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 163 | |
| 164 | if (unlikely((qp->req.state == QP_STATE_DRAIN || |
| 165 | qp->req.state == QP_STATE_DRAINED) && |
| 166 | (wqe->state != wqe_state_processing))) |
| 167 | return NULL; |
| 168 | |
| 169 | if (unlikely((wqe->wr.send_flags & IB_SEND_FENCE) && |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 170 | (index != cons))) { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 171 | qp->req.wait_fence = 1; |
| 172 | return NULL; |
| 173 | } |
| 174 | |
| 175 | wqe->mask = wr_opcode_mask(wqe->wr.opcode, qp); |
| 176 | return wqe; |
| 177 | } |
| 178 | |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 179 | static int next_opcode_rc(struct rxe_qp *qp, u32 opcode, int fits) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 180 | { |
| 181 | switch (opcode) { |
| 182 | case IB_WR_RDMA_WRITE: |
| 183 | if (qp->req.opcode == IB_OPCODE_RC_RDMA_WRITE_FIRST || |
| 184 | qp->req.opcode == IB_OPCODE_RC_RDMA_WRITE_MIDDLE) |
| 185 | return fits ? |
| 186 | IB_OPCODE_RC_RDMA_WRITE_LAST : |
| 187 | IB_OPCODE_RC_RDMA_WRITE_MIDDLE; |
| 188 | else |
| 189 | return fits ? |
| 190 | IB_OPCODE_RC_RDMA_WRITE_ONLY : |
| 191 | IB_OPCODE_RC_RDMA_WRITE_FIRST; |
| 192 | |
| 193 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 194 | if (qp->req.opcode == IB_OPCODE_RC_RDMA_WRITE_FIRST || |
| 195 | qp->req.opcode == IB_OPCODE_RC_RDMA_WRITE_MIDDLE) |
| 196 | return fits ? |
| 197 | IB_OPCODE_RC_RDMA_WRITE_LAST_WITH_IMMEDIATE : |
| 198 | IB_OPCODE_RC_RDMA_WRITE_MIDDLE; |
| 199 | else |
| 200 | return fits ? |
| 201 | IB_OPCODE_RC_RDMA_WRITE_ONLY_WITH_IMMEDIATE : |
| 202 | IB_OPCODE_RC_RDMA_WRITE_FIRST; |
| 203 | |
| 204 | case IB_WR_SEND: |
| 205 | if (qp->req.opcode == IB_OPCODE_RC_SEND_FIRST || |
| 206 | qp->req.opcode == IB_OPCODE_RC_SEND_MIDDLE) |
| 207 | return fits ? |
| 208 | IB_OPCODE_RC_SEND_LAST : |
| 209 | IB_OPCODE_RC_SEND_MIDDLE; |
| 210 | else |
| 211 | return fits ? |
| 212 | IB_OPCODE_RC_SEND_ONLY : |
| 213 | IB_OPCODE_RC_SEND_FIRST; |
| 214 | |
| 215 | case IB_WR_SEND_WITH_IMM: |
| 216 | if (qp->req.opcode == IB_OPCODE_RC_SEND_FIRST || |
| 217 | qp->req.opcode == IB_OPCODE_RC_SEND_MIDDLE) |
| 218 | return fits ? |
| 219 | IB_OPCODE_RC_SEND_LAST_WITH_IMMEDIATE : |
| 220 | IB_OPCODE_RC_SEND_MIDDLE; |
| 221 | else |
| 222 | return fits ? |
| 223 | IB_OPCODE_RC_SEND_ONLY_WITH_IMMEDIATE : |
| 224 | IB_OPCODE_RC_SEND_FIRST; |
| 225 | |
| 226 | case IB_WR_RDMA_READ: |
| 227 | return IB_OPCODE_RC_RDMA_READ_REQUEST; |
| 228 | |
| 229 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 230 | return IB_OPCODE_RC_COMPARE_SWAP; |
| 231 | |
| 232 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
| 233 | return IB_OPCODE_RC_FETCH_ADD; |
| 234 | |
| 235 | case IB_WR_SEND_WITH_INV: |
| 236 | if (qp->req.opcode == IB_OPCODE_RC_SEND_FIRST || |
| 237 | qp->req.opcode == IB_OPCODE_RC_SEND_MIDDLE) |
| 238 | return fits ? IB_OPCODE_RC_SEND_LAST_WITH_INVALIDATE : |
| 239 | IB_OPCODE_RC_SEND_MIDDLE; |
| 240 | else |
| 241 | return fits ? IB_OPCODE_RC_SEND_ONLY_WITH_INVALIDATE : |
| 242 | IB_OPCODE_RC_SEND_FIRST; |
| 243 | case IB_WR_REG_MR: |
| 244 | case IB_WR_LOCAL_INV: |
| 245 | return opcode; |
| 246 | } |
| 247 | |
| 248 | return -EINVAL; |
| 249 | } |
| 250 | |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 251 | static int next_opcode_uc(struct rxe_qp *qp, u32 opcode, int fits) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 252 | { |
| 253 | switch (opcode) { |
| 254 | case IB_WR_RDMA_WRITE: |
| 255 | if (qp->req.opcode == IB_OPCODE_UC_RDMA_WRITE_FIRST || |
| 256 | qp->req.opcode == IB_OPCODE_UC_RDMA_WRITE_MIDDLE) |
| 257 | return fits ? |
| 258 | IB_OPCODE_UC_RDMA_WRITE_LAST : |
| 259 | IB_OPCODE_UC_RDMA_WRITE_MIDDLE; |
| 260 | else |
| 261 | return fits ? |
| 262 | IB_OPCODE_UC_RDMA_WRITE_ONLY : |
| 263 | IB_OPCODE_UC_RDMA_WRITE_FIRST; |
| 264 | |
| 265 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 266 | if (qp->req.opcode == IB_OPCODE_UC_RDMA_WRITE_FIRST || |
| 267 | qp->req.opcode == IB_OPCODE_UC_RDMA_WRITE_MIDDLE) |
| 268 | return fits ? |
| 269 | IB_OPCODE_UC_RDMA_WRITE_LAST_WITH_IMMEDIATE : |
| 270 | IB_OPCODE_UC_RDMA_WRITE_MIDDLE; |
| 271 | else |
| 272 | return fits ? |
| 273 | IB_OPCODE_UC_RDMA_WRITE_ONLY_WITH_IMMEDIATE : |
| 274 | IB_OPCODE_UC_RDMA_WRITE_FIRST; |
| 275 | |
| 276 | case IB_WR_SEND: |
| 277 | if (qp->req.opcode == IB_OPCODE_UC_SEND_FIRST || |
| 278 | qp->req.opcode == IB_OPCODE_UC_SEND_MIDDLE) |
| 279 | return fits ? |
| 280 | IB_OPCODE_UC_SEND_LAST : |
| 281 | IB_OPCODE_UC_SEND_MIDDLE; |
| 282 | else |
| 283 | return fits ? |
| 284 | IB_OPCODE_UC_SEND_ONLY : |
| 285 | IB_OPCODE_UC_SEND_FIRST; |
| 286 | |
| 287 | case IB_WR_SEND_WITH_IMM: |
| 288 | if (qp->req.opcode == IB_OPCODE_UC_SEND_FIRST || |
| 289 | qp->req.opcode == IB_OPCODE_UC_SEND_MIDDLE) |
| 290 | return fits ? |
| 291 | IB_OPCODE_UC_SEND_LAST_WITH_IMMEDIATE : |
| 292 | IB_OPCODE_UC_SEND_MIDDLE; |
| 293 | else |
| 294 | return fits ? |
| 295 | IB_OPCODE_UC_SEND_ONLY_WITH_IMMEDIATE : |
| 296 | IB_OPCODE_UC_SEND_FIRST; |
| 297 | } |
| 298 | |
| 299 | return -EINVAL; |
| 300 | } |
| 301 | |
| 302 | static int next_opcode(struct rxe_qp *qp, struct rxe_send_wqe *wqe, |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 303 | u32 opcode) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 304 | { |
| 305 | int fits = (wqe->dma.resid <= qp->mtu); |
| 306 | |
| 307 | switch (qp_type(qp)) { |
| 308 | case IB_QPT_RC: |
| 309 | return next_opcode_rc(qp, opcode, fits); |
| 310 | |
| 311 | case IB_QPT_UC: |
| 312 | return next_opcode_uc(qp, opcode, fits); |
| 313 | |
| 314 | case IB_QPT_SMI: |
| 315 | case IB_QPT_UD: |
| 316 | case IB_QPT_GSI: |
| 317 | switch (opcode) { |
| 318 | case IB_WR_SEND: |
| 319 | return IB_OPCODE_UD_SEND_ONLY; |
| 320 | |
| 321 | case IB_WR_SEND_WITH_IMM: |
| 322 | return IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE; |
| 323 | } |
| 324 | break; |
| 325 | |
| 326 | default: |
| 327 | break; |
| 328 | } |
| 329 | |
| 330 | return -EINVAL; |
| 331 | } |
| 332 | |
| 333 | static inline int check_init_depth(struct rxe_qp *qp, struct rxe_send_wqe *wqe) |
| 334 | { |
| 335 | int depth; |
| 336 | |
| 337 | if (wqe->has_rd_atomic) |
| 338 | return 0; |
| 339 | |
| 340 | qp->req.need_rd_atomic = 1; |
| 341 | depth = atomic_dec_return(&qp->req.rd_atomic); |
| 342 | |
| 343 | if (depth >= 0) { |
| 344 | qp->req.need_rd_atomic = 0; |
| 345 | wqe->has_rd_atomic = 1; |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | atomic_inc(&qp->req.rd_atomic); |
| 350 | return -EAGAIN; |
| 351 | } |
| 352 | |
Bart Van Assche | 175f124 | 2017-01-10 11:15:43 -0800 | [diff] [blame] | 353 | static inline int get_mtu(struct rxe_qp *qp) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 354 | { |
| 355 | struct rxe_dev *rxe = to_rdev(qp->ibqp.device); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 356 | |
| 357 | if ((qp_type(qp) == IB_QPT_RC) || (qp_type(qp) == IB_QPT_UC)) |
| 358 | return qp->mtu; |
| 359 | |
Bart Van Assche | 175f124 | 2017-01-10 11:15:43 -0800 | [diff] [blame] | 360 | return rxe->port.mtu_cap; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static struct sk_buff *init_req_packet(struct rxe_qp *qp, |
| 364 | struct rxe_send_wqe *wqe, |
| 365 | int opcode, int payload, |
| 366 | struct rxe_pkt_info *pkt) |
| 367 | { |
| 368 | struct rxe_dev *rxe = to_rdev(qp->ibqp.device); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 369 | struct sk_buff *skb; |
| 370 | struct rxe_send_wr *ibwr = &wqe->wr; |
| 371 | struct rxe_av *av; |
| 372 | int pad = (-payload) & 0x3; |
| 373 | int paylen; |
| 374 | int solicited; |
| 375 | u16 pkey; |
| 376 | u32 qp_num; |
| 377 | int ack_req; |
| 378 | |
| 379 | /* length from start of bth to end of icrc */ |
| 380 | paylen = rxe_opcode[opcode].length + payload + pad + RXE_ICRC_SIZE; |
| 381 | |
| 382 | /* pkt->hdr, rxe, port_num and mask are initialized in ifc |
| 383 | * layer |
| 384 | */ |
| 385 | pkt->opcode = opcode; |
| 386 | pkt->qp = qp; |
| 387 | pkt->psn = qp->req.psn; |
| 388 | pkt->mask = rxe_opcode[opcode].mask; |
| 389 | pkt->paylen = paylen; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 390 | pkt->wqe = wqe; |
| 391 | |
| 392 | /* init skb */ |
| 393 | av = rxe_get_av(pkt); |
Bart Van Assche | 839f5ac | 2017-01-10 11:15:53 -0800 | [diff] [blame] | 394 | skb = rxe_init_packet(rxe, av, paylen, pkt); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 395 | if (unlikely(!skb)) |
| 396 | return NULL; |
| 397 | |
| 398 | /* init bth */ |
| 399 | solicited = (ibwr->send_flags & IB_SEND_SOLICITED) && |
| 400 | (pkt->mask & RXE_END_MASK) && |
| 401 | ((pkt->mask & (RXE_SEND_MASK)) || |
| 402 | (pkt->mask & (RXE_WRITE_MASK | RXE_IMMDT_MASK)) == |
| 403 | (RXE_WRITE_MASK | RXE_IMMDT_MASK)); |
| 404 | |
Kamal Heib | 76251e1 | 2020-07-21 13:16:18 +0300 | [diff] [blame] | 405 | pkey = IB_DEFAULT_PKEY_FULL; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 406 | |
| 407 | qp_num = (pkt->mask & RXE_DETH_MASK) ? ibwr->wr.ud.remote_qpn : |
| 408 | qp->attr.dest_qp_num; |
| 409 | |
| 410 | ack_req = ((pkt->mask & RXE_END_MASK) || |
| 411 | (qp->req.noack_pkts++ > RXE_MAX_PKT_PER_ACK)); |
| 412 | if (ack_req) |
| 413 | qp->req.noack_pkts = 0; |
| 414 | |
| 415 | bth_init(pkt, pkt->opcode, solicited, 0, pad, pkey, qp_num, |
| 416 | ack_req, pkt->psn); |
| 417 | |
| 418 | /* init optional headers */ |
| 419 | if (pkt->mask & RXE_RETH_MASK) { |
| 420 | reth_set_rkey(pkt, ibwr->wr.rdma.rkey); |
| 421 | reth_set_va(pkt, wqe->iova); |
Vijay Immanuel | 030e46e | 2018-06-13 18:48:07 -0700 | [diff] [blame] | 422 | reth_set_len(pkt, wqe->dma.resid); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | if (pkt->mask & RXE_IMMDT_MASK) |
| 426 | immdt_set_imm(pkt, ibwr->ex.imm_data); |
| 427 | |
| 428 | if (pkt->mask & RXE_IETH_MASK) |
| 429 | ieth_set_rkey(pkt, ibwr->ex.invalidate_rkey); |
| 430 | |
| 431 | if (pkt->mask & RXE_ATMETH_MASK) { |
| 432 | atmeth_set_va(pkt, wqe->iova); |
| 433 | if (opcode == IB_OPCODE_RC_COMPARE_SWAP || |
| 434 | opcode == IB_OPCODE_RD_COMPARE_SWAP) { |
| 435 | atmeth_set_swap_add(pkt, ibwr->wr.atomic.swap); |
| 436 | atmeth_set_comp(pkt, ibwr->wr.atomic.compare_add); |
| 437 | } else { |
| 438 | atmeth_set_swap_add(pkt, ibwr->wr.atomic.compare_add); |
| 439 | } |
| 440 | atmeth_set_rkey(pkt, ibwr->wr.atomic.rkey); |
| 441 | } |
| 442 | |
| 443 | if (pkt->mask & RXE_DETH_MASK) { |
| 444 | if (qp->ibqp.qp_num == 1) |
| 445 | deth_set_qkey(pkt, GSI_QKEY); |
| 446 | else |
| 447 | deth_set_qkey(pkt, ibwr->wr.ud.remote_qkey); |
| 448 | deth_set_sqp(pkt, qp->ibqp.qp_num); |
| 449 | } |
| 450 | |
| 451 | return skb; |
| 452 | } |
| 453 | |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 454 | static int finish_packet(struct rxe_qp *qp, struct rxe_send_wqe *wqe, |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 455 | struct rxe_pkt_info *pkt, struct sk_buff *skb, |
| 456 | int paylen) |
| 457 | { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 458 | int err; |
| 459 | |
Bob Pearson | 1117f26 | 2021-07-06 23:00:36 -0500 | [diff] [blame] | 460 | err = rxe_prepare(pkt, skb); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 461 | if (err) |
| 462 | return err; |
| 463 | |
Xiao Yang | 45216d6 | 2021-09-14 16:02:52 +0800 | [diff] [blame] | 464 | if (pkt->mask & RXE_WRITE_OR_SEND_MASK) { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 465 | if (wqe->wr.send_flags & IB_SEND_INLINE) { |
| 466 | u8 *tmp = &wqe->dma.inline_data[wqe->dma.sge_offset]; |
| 467 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 468 | memcpy(payload_addr(pkt), tmp, paylen); |
| 469 | |
| 470 | wqe->dma.resid -= paylen; |
| 471 | wqe->dma.sge_offset += paylen; |
| 472 | } else { |
Zhu Yanjun | e12ee8c | 2018-04-23 03:57:58 -0400 | [diff] [blame] | 473 | err = copy_data(qp->pd, 0, &wqe->dma, |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 474 | payload_addr(pkt), paylen, |
Bob Pearson | 1117f26 | 2021-07-06 23:00:36 -0500 | [diff] [blame] | 475 | RXE_FROM_MR_OBJ); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 476 | if (err) |
| 477 | return err; |
| 478 | } |
Steve Wise | 2030abd | 2019-12-02 20:03:20 -0600 | [diff] [blame] | 479 | if (bth_pad(pkt)) { |
| 480 | u8 *pad = payload_addr(pkt) + paylen; |
| 481 | |
| 482 | memset(pad, 0, bth_pad(pkt)); |
Steve Wise | 2030abd | 2019-12-02 20:03:20 -0600 | [diff] [blame] | 483 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 484 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | static void update_wqe_state(struct rxe_qp *qp, |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 490 | struct rxe_send_wqe *wqe, |
| 491 | struct rxe_pkt_info *pkt) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 492 | { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 493 | if (pkt->mask & RXE_END_MASK) { |
| 494 | if (qp_type(qp) == IB_QPT_RC) |
| 495 | wqe->state = wqe_state_pending; |
| 496 | } else { |
| 497 | wqe->state = wqe_state_processing; |
| 498 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 499 | } |
| 500 | |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 501 | static void update_wqe_psn(struct rxe_qp *qp, |
| 502 | struct rxe_send_wqe *wqe, |
| 503 | struct rxe_pkt_info *pkt, |
| 504 | int payload) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 505 | { |
| 506 | /* number of packets left to send including current one */ |
| 507 | int num_pkt = (wqe->dma.resid + payload + qp->mtu - 1) / qp->mtu; |
| 508 | |
| 509 | /* handle zero length packet case */ |
| 510 | if (num_pkt == 0) |
| 511 | num_pkt = 1; |
| 512 | |
| 513 | if (pkt->mask & RXE_START_MASK) { |
| 514 | wqe->first_psn = qp->req.psn; |
| 515 | wqe->last_psn = (qp->req.psn + num_pkt - 1) & BTH_PSN_MASK; |
| 516 | } |
| 517 | |
| 518 | if (pkt->mask & RXE_READ_MASK) |
| 519 | qp->req.psn = (wqe->first_psn + num_pkt) & BTH_PSN_MASK; |
| 520 | else |
| 521 | qp->req.psn = (qp->req.psn + 1) & BTH_PSN_MASK; |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 522 | } |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 523 | |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 524 | static void save_state(struct rxe_send_wqe *wqe, |
| 525 | struct rxe_qp *qp, |
| 526 | struct rxe_send_wqe *rollback_wqe, |
Arnd Bergmann | a0fa726 | 2016-09-19 13:57:26 +0200 | [diff] [blame] | 527 | u32 *rollback_psn) |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 528 | { |
| 529 | rollback_wqe->state = wqe->state; |
| 530 | rollback_wqe->first_psn = wqe->first_psn; |
| 531 | rollback_wqe->last_psn = wqe->last_psn; |
Arnd Bergmann | a0fa726 | 2016-09-19 13:57:26 +0200 | [diff] [blame] | 532 | *rollback_psn = qp->req.psn; |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | static void rollback_state(struct rxe_send_wqe *wqe, |
| 536 | struct rxe_qp *qp, |
| 537 | struct rxe_send_wqe *rollback_wqe, |
Arnd Bergmann | a0fa726 | 2016-09-19 13:57:26 +0200 | [diff] [blame] | 538 | u32 rollback_psn) |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 539 | { |
| 540 | wqe->state = rollback_wqe->state; |
| 541 | wqe->first_psn = rollback_wqe->first_psn; |
| 542 | wqe->last_psn = rollback_wqe->last_psn; |
Arnd Bergmann | a0fa726 | 2016-09-19 13:57:26 +0200 | [diff] [blame] | 543 | qp->req.psn = rollback_psn; |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | static void update_state(struct rxe_qp *qp, struct rxe_send_wqe *wqe, |
| 547 | struct rxe_pkt_info *pkt, int payload) |
| 548 | { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 549 | qp->req.opcode = pkt->opcode; |
| 550 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 551 | if (pkt->mask & RXE_END_MASK) |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 552 | qp->req.wqe_index = queue_next_index(qp->sq.queue, |
| 553 | qp->req.wqe_index); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 554 | |
| 555 | qp->need_req_skb = 0; |
| 556 | |
| 557 | if (qp->qp_timeout_jiffies && !timer_pending(&qp->retrans_timer)) |
| 558 | mod_timer(&qp->retrans_timer, |
| 559 | jiffies + qp->qp_timeout_jiffies); |
| 560 | } |
| 561 | |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 562 | static int rxe_do_local_ops(struct rxe_qp *qp, struct rxe_send_wqe *wqe) |
| 563 | { |
| 564 | u8 opcode = wqe->wr.opcode; |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 565 | u32 rkey; |
Bob Pearson | 32a577b | 2021-06-07 23:25:50 -0500 | [diff] [blame] | 566 | int ret; |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 567 | |
| 568 | switch (opcode) { |
| 569 | case IB_WR_LOCAL_INV: |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 570 | rkey = wqe->wr.ex.invalidate_rkey; |
Bob Pearson | 3902b42 | 2021-06-07 23:25:51 -0500 | [diff] [blame] | 571 | if (rkey_is_mw(rkey)) |
| 572 | ret = rxe_invalidate_mw(qp, rkey); |
| 573 | else |
| 574 | ret = rxe_invalidate_mr(qp, rkey); |
| 575 | |
| 576 | if (unlikely(ret)) { |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 577 | wqe->status = IB_WC_LOC_QP_OP_ERR; |
Bob Pearson | 3902b42 | 2021-06-07 23:25:51 -0500 | [diff] [blame] | 578 | return ret; |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 579 | } |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 580 | break; |
| 581 | case IB_WR_REG_MR: |
Bob Pearson | 0013453 | 2021-09-14 11:42:05 -0500 | [diff] [blame] | 582 | ret = rxe_reg_fast_mr(qp, wqe); |
| 583 | if (unlikely(ret)) { |
| 584 | wqe->status = IB_WC_LOC_QP_OP_ERR; |
| 585 | return ret; |
| 586 | } |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 587 | break; |
Bob Pearson | 32a577b | 2021-06-07 23:25:50 -0500 | [diff] [blame] | 588 | case IB_WR_BIND_MW: |
| 589 | ret = rxe_bind_mw(qp, wqe); |
| 590 | if (unlikely(ret)) { |
| 591 | wqe->status = IB_WC_MW_BIND_ERR; |
| 592 | return ret; |
| 593 | } |
| 594 | break; |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 595 | default: |
| 596 | pr_err("Unexpected send wqe opcode %d\n", opcode); |
| 597 | wqe->status = IB_WC_LOC_QP_OP_ERR; |
| 598 | return -EINVAL; |
| 599 | } |
| 600 | |
| 601 | wqe->state = wqe_state_done; |
| 602 | wqe->status = IB_WC_SUCCESS; |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 603 | qp->req.wqe_index = queue_next_index(qp->sq.queue, qp->req.wqe_index); |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 604 | |
| 605 | if ((wqe->wr.send_flags & IB_SEND_SIGNALED) || |
| 606 | qp->sq_sig_type == IB_SIGNAL_ALL_WR) |
| 607 | rxe_run_task(&qp->comp.task, 1); |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 612 | int rxe_requester(void *arg) |
| 613 | { |
| 614 | struct rxe_qp *qp = (struct rxe_qp *)arg; |
| 615 | struct rxe_pkt_info pkt; |
| 616 | struct sk_buff *skb; |
| 617 | struct rxe_send_wqe *wqe; |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 618 | enum rxe_hdr_mask mask; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 619 | int payload; |
| 620 | int mtu; |
| 621 | int opcode; |
| 622 | int ret; |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 623 | struct rxe_send_wqe rollback_wqe; |
Arnd Bergmann | a0fa726 | 2016-09-19 13:57:26 +0200 | [diff] [blame] | 624 | u32 rollback_psn; |
Bob Pearson | 5bcf5a5 | 2021-05-27 14:47:48 -0500 | [diff] [blame] | 625 | struct rxe_queue *q = qp->sq.queue; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 626 | |
Andrew Boyer | 37f69f4 | 2016-12-05 08:43:21 -0500 | [diff] [blame] | 627 | rxe_add_ref(qp); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 628 | |
| 629 | next_wqe: |
Bart Van Assche | 65567e4 | 2018-01-12 15:11:58 -0800 | [diff] [blame] | 630 | if (unlikely(!qp->valid || qp->req.state == QP_STATE_ERROR)) |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 631 | goto exit; |
Bart Van Assche | 18d3451 | 2017-01-10 11:15:50 -0800 | [diff] [blame] | 632 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 633 | if (unlikely(qp->req.state == QP_STATE_RESET)) { |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 634 | qp->req.wqe_index = queue_get_consumer(q, |
| 635 | QUEUE_TYPE_FROM_CLIENT); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 636 | qp->req.opcode = -1; |
| 637 | qp->req.need_rd_atomic = 0; |
| 638 | qp->req.wait_psn = 0; |
| 639 | qp->req.need_retry = 0; |
| 640 | goto exit; |
| 641 | } |
| 642 | |
| 643 | if (unlikely(qp->req.need_retry)) { |
| 644 | req_retry(qp); |
| 645 | qp->req.need_retry = 0; |
| 646 | } |
| 647 | |
| 648 | wqe = req_next_wqe(qp); |
| 649 | if (unlikely(!wqe)) |
| 650 | goto exit; |
| 651 | |
Bob Pearson | 886441f | 2021-06-07 23:25:48 -0500 | [diff] [blame] | 652 | if (wqe->mask & WR_LOCAL_OP_MASK) { |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 653 | ret = rxe_do_local_ops(qp, wqe); |
| 654 | if (unlikely(ret)) |
| 655 | goto err; |
| 656 | else |
| 657 | goto next_wqe; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | if (unlikely(qp_type(qp) == IB_QPT_RC && |
Bob Pearson | bb3ab29 | 2020-10-13 12:07:42 -0500 | [diff] [blame] | 661 | psn_compare(qp->req.psn, (qp->comp.psn + |
| 662 | RXE_MAX_UNACKED_PSNS)) > 0)) { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 663 | qp->req.wait_psn = 1; |
| 664 | goto exit; |
| 665 | } |
| 666 | |
| 667 | /* Limit the number of inflight SKBs per QP */ |
| 668 | if (unlikely(atomic_read(&qp->skb_out) > |
| 669 | RXE_INFLIGHT_SKBS_PER_QP_HIGH)) { |
| 670 | qp->need_req_skb = 1; |
| 671 | goto exit; |
| 672 | } |
| 673 | |
| 674 | opcode = next_opcode(qp, wqe, wqe->wr.opcode); |
| 675 | if (unlikely(opcode < 0)) { |
| 676 | wqe->status = IB_WC_LOC_QP_OP_ERR; |
| 677 | goto exit; |
| 678 | } |
| 679 | |
| 680 | mask = rxe_opcode[opcode].mask; |
Xiao Yang | 45216d6 | 2021-09-14 16:02:52 +0800 | [diff] [blame] | 681 | if (unlikely(mask & RXE_READ_OR_ATOMIC_MASK)) { |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 682 | if (check_init_depth(qp, wqe)) |
| 683 | goto exit; |
| 684 | } |
| 685 | |
Bart Van Assche | 175f124 | 2017-01-10 11:15:43 -0800 | [diff] [blame] | 686 | mtu = get_mtu(qp); |
Xiao Yang | 45216d6 | 2021-09-14 16:02:52 +0800 | [diff] [blame] | 687 | payload = (mask & RXE_WRITE_OR_SEND_MASK) ? wqe->dma.resid : 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 688 | if (payload > mtu) { |
| 689 | if (qp_type(qp) == IB_QPT_UD) { |
| 690 | /* C10-93.1.1: If the total sum of all the buffer lengths specified for a |
| 691 | * UD message exceeds the MTU of the port as returned by QueryHCA, the CI |
| 692 | * shall not emit any packets for this message. Further, the CI shall not |
| 693 | * generate an error due to this condition. |
| 694 | */ |
| 695 | |
| 696 | /* fake a successful UD send */ |
| 697 | wqe->first_psn = qp->req.psn; |
| 698 | wqe->last_psn = qp->req.psn; |
| 699 | qp->req.psn = (qp->req.psn + 1) & BTH_PSN_MASK; |
| 700 | qp->req.opcode = IB_OPCODE_UD_SEND_ONLY; |
Bob Pearson | ae6e843 | 2021-09-14 11:42:03 -0500 | [diff] [blame] | 701 | qp->req.wqe_index = queue_next_index(qp->sq.queue, |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 702 | qp->req.wqe_index); |
| 703 | wqe->state = wqe_state_done; |
| 704 | wqe->status = IB_WC_SUCCESS; |
Yonatan Cohen | 002e062 | 2016-11-16 10:39:15 +0200 | [diff] [blame] | 705 | __rxe_do_task(&qp->comp.task); |
Linus Torvalds | 4d5b57e | 2016-12-15 12:03:32 -0800 | [diff] [blame] | 706 | rxe_drop_ref(qp); |
Yonatan Cohen | 002e062 | 2016-11-16 10:39:15 +0200 | [diff] [blame] | 707 | return 0; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 708 | } |
| 709 | payload = mtu; |
| 710 | } |
| 711 | |
| 712 | skb = init_req_packet(qp, wqe, opcode, payload, &pkt); |
| 713 | if (unlikely(!skb)) { |
Parav Pandit | e404f94 | 2016-09-28 20:26:26 +0000 | [diff] [blame] | 714 | pr_err("qp#%d Failed allocating skb\n", qp_num(qp)); |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 715 | wqe->status = IB_WC_LOC_QP_OP_ERR; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 716 | goto err; |
| 717 | } |
| 718 | |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 719 | ret = finish_packet(qp, wqe, &pkt, skb, payload); |
| 720 | if (unlikely(ret)) { |
| 721 | pr_debug("qp#%d Error during finish packet\n", qp_num(qp)); |
| 722 | if (ret == -EFAULT) |
| 723 | wqe->status = IB_WC_LOC_PROT_ERR; |
| 724 | else |
| 725 | wqe->status = IB_WC_LOC_QP_OP_ERR; |
Zhu Yanjun | 828d810 | 2018-06-07 02:32:52 -0400 | [diff] [blame] | 726 | kfree_skb(skb); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 727 | goto err; |
| 728 | } |
| 729 | |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 730 | /* |
| 731 | * To prevent a race on wqe access between requester and completer, |
| 732 | * wqe members state and psn need to be set before calling |
| 733 | * rxe_xmit_packet(). |
| 734 | * Otherwise, completer might initiate an unjustified retry flow. |
| 735 | */ |
Arnd Bergmann | a0fa726 | 2016-09-19 13:57:26 +0200 | [diff] [blame] | 736 | save_state(wqe, qp, &rollback_wqe, &rollback_psn); |
Yonatan Cohen | 3050b99 | 2016-09-07 14:04:06 +0300 | [diff] [blame] | 737 | update_wqe_state(qp, wqe, &pkt); |
| 738 | update_wqe_psn(qp, wqe, &pkt, payload); |
Zhu Yanjun | a854b1e | 2018-11-03 08:13:18 -0400 | [diff] [blame] | 739 | ret = rxe_xmit_packet(qp, &pkt, skb); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 740 | if (ret) { |
| 741 | qp->need_req_skb = 1; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 742 | |
Arnd Bergmann | a0fa726 | 2016-09-19 13:57:26 +0200 | [diff] [blame] | 743 | rollback_state(wqe, qp, &rollback_wqe, rollback_psn); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 744 | |
| 745 | if (ret == -EAGAIN) { |
| 746 | rxe_run_task(&qp->req.task, 1); |
| 747 | goto exit; |
| 748 | } |
| 749 | |
Bob Pearson | c1a4112 | 2021-06-07 23:25:49 -0500 | [diff] [blame] | 750 | wqe->status = IB_WC_LOC_QP_OP_ERR; |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 751 | goto err; |
| 752 | } |
| 753 | |
| 754 | update_state(qp, wqe, &pkt, payload); |
| 755 | |
| 756 | goto next_wqe; |
| 757 | |
| 758 | err: |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 759 | wqe->state = wqe_state_error; |
Yonatan Cohen | 002e062 | 2016-11-16 10:39:15 +0200 | [diff] [blame] | 760 | __rxe_do_task(&qp->comp.task); |
Bart Van Assche | 18d3451 | 2017-01-10 11:15:50 -0800 | [diff] [blame] | 761 | |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 762 | exit: |
Andrew Boyer | 37f69f4 | 2016-12-05 08:43:21 -0500 | [diff] [blame] | 763 | rxe_drop_ref(qp); |
Moni Shoua | 8700e3e | 2016-06-16 16:45:23 +0300 | [diff] [blame] | 764 | return -EAGAIN; |
| 765 | } |