Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1 | /* |
Jubin John | 05d6ac1 | 2016-02-14 20:22:17 -0800 | [diff] [blame] | 2 | * Copyright(c) 2015, 2016 Intel Corporation. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | #include <linux/io.h> |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 49 | #include <rdma/rdma_vt.h> |
| 50 | #include <rdma/rdmavt_qp.h> |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 51 | |
| 52 | #include "hfi.h" |
| 53 | #include "qp.h" |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 54 | #include "verbs_txreq.h" |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 55 | #include "trace.h" |
| 56 | |
| 57 | /* cut down ridiculously long IB macro names */ |
| 58 | #define OP(x) IB_OPCODE_RC_##x |
| 59 | |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 60 | /** |
| 61 | * hfi1_add_retry_timer - add/start a retry timer |
| 62 | * @qp - the QP |
| 63 | * |
| 64 | * add a retry timer on the QP |
| 65 | */ |
| 66 | static inline void hfi1_add_retry_timer(struct rvt_qp *qp) |
| 67 | { |
Vennila Megavannan | bfee5e3 | 2016-02-09 14:29:49 -0800 | [diff] [blame] | 68 | struct ib_qp *ibqp = &qp->ibqp; |
| 69 | struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); |
| 70 | |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 71 | qp->s_flags |= RVT_S_TIMER; |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 72 | /* 4.096 usec. * (1 << qp->timeout) */ |
Vennila Megavannan | bfee5e3 | 2016-02-09 14:29:49 -0800 | [diff] [blame] | 73 | qp->s_timer.expires = jiffies + qp->timeout_jiffies + |
| 74 | rdi->busy_jiffies; |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 75 | add_timer(&qp->s_timer); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * hfi1_add_rnr_timer - add/start an rnr timer |
| 80 | * @qp - the QP |
| 81 | * @to - timeout in usecs |
| 82 | * |
| 83 | * add an rnr timer on the QP |
| 84 | */ |
Mike Marciniszyn | 34cee28 | 2016-02-09 14:29:31 -0800 | [diff] [blame] | 85 | void hfi1_add_rnr_timer(struct rvt_qp *qp, u32 to) |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 86 | { |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 87 | struct hfi1_qp_priv *priv = qp->priv; |
| 88 | |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 89 | qp->s_flags |= RVT_S_WAIT_RNR; |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 90 | qp->s_timer.expires = jiffies + usecs_to_jiffies(to); |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 91 | add_timer(&priv->s_rnr_timer); |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /** |
| 95 | * hfi1_mod_retry_timer - mod a retry timer |
| 96 | * @qp - the QP |
| 97 | * |
| 98 | * Modify a potentially already running retry |
| 99 | * timer |
| 100 | */ |
| 101 | static inline void hfi1_mod_retry_timer(struct rvt_qp *qp) |
| 102 | { |
Vennila Megavannan | bfee5e3 | 2016-02-09 14:29:49 -0800 | [diff] [blame] | 103 | struct ib_qp *ibqp = &qp->ibqp; |
| 104 | struct rvt_dev_info *rdi = ib_to_rvt(ibqp->device); |
| 105 | |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 106 | qp->s_flags |= RVT_S_TIMER; |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 107 | /* 4.096 usec. * (1 << qp->timeout) */ |
Vennila Megavannan | bfee5e3 | 2016-02-09 14:29:49 -0800 | [diff] [blame] | 108 | mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies + |
| 109 | rdi->busy_jiffies); |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
| 113 | * hfi1_stop_retry_timer - stop a retry timer |
| 114 | * @qp - the QP |
| 115 | * |
| 116 | * stop a retry timer and return if the timer |
| 117 | * had been pending. |
| 118 | */ |
| 119 | static inline int hfi1_stop_retry_timer(struct rvt_qp *qp) |
| 120 | { |
| 121 | int rval = 0; |
| 122 | |
| 123 | /* Remove QP from retry */ |
| 124 | if (qp->s_flags & RVT_S_TIMER) { |
| 125 | qp->s_flags &= ~RVT_S_TIMER; |
| 126 | rval = del_timer(&qp->s_timer); |
| 127 | } |
| 128 | return rval; |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * hfi1_stop_rc_timers - stop all timers |
| 133 | * @qp - the QP |
| 134 | * |
| 135 | * stop any pending timers |
| 136 | */ |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 137 | void hfi1_stop_rc_timers(struct rvt_qp *qp) |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 138 | { |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 139 | struct hfi1_qp_priv *priv = qp->priv; |
| 140 | |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 141 | /* Remove QP from all timers */ |
| 142 | if (qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR)) { |
| 143 | qp->s_flags &= ~(RVT_S_TIMER | RVT_S_WAIT_RNR); |
| 144 | del_timer(&qp->s_timer); |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 145 | del_timer(&priv->s_rnr_timer); |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * hfi1_stop_rnr_timer - stop an rnr timer |
| 151 | * @qp - the QP |
| 152 | * |
| 153 | * stop an rnr timer and return if the timer |
| 154 | * had been pending. |
| 155 | */ |
| 156 | static inline int hfi1_stop_rnr_timer(struct rvt_qp *qp) |
| 157 | { |
| 158 | int rval = 0; |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 159 | struct hfi1_qp_priv *priv = qp->priv; |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 160 | |
| 161 | /* Remove QP from rnr timer */ |
| 162 | if (qp->s_flags & RVT_S_WAIT_RNR) { |
| 163 | qp->s_flags &= ~RVT_S_WAIT_RNR; |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 164 | rval = del_timer(&priv->s_rnr_timer); |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 165 | } |
| 166 | return rval; |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * hfi1_del_timers_sync - wait for any timeout routines to exit |
| 171 | * @qp - the QP |
| 172 | */ |
Mike Marciniszyn | 3c9d149 | 2016-02-04 10:59:27 -0800 | [diff] [blame] | 173 | void hfi1_del_timers_sync(struct rvt_qp *qp) |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 174 | { |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 175 | struct hfi1_qp_priv *priv = qp->priv; |
| 176 | |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 177 | del_timer_sync(&qp->s_timer); |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 178 | del_timer_sync(&priv->s_rnr_timer); |
Mike Marciniszyn | 9171bfd | 2016-02-04 10:59:01 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 181 | /* only opcode mask for adaptive pio */ |
| 182 | const u32 rc_only_opcode = |
| 183 | BIT(OP(SEND_ONLY) & 0x1f) | |
| 184 | BIT(OP(SEND_ONLY_WITH_IMMEDIATE & 0x1f)) | |
| 185 | BIT(OP(RDMA_WRITE_ONLY & 0x1f)) | |
| 186 | BIT(OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE & 0x1f)) | |
| 187 | BIT(OP(RDMA_READ_REQUEST & 0x1f)) | |
| 188 | BIT(OP(ACKNOWLEDGE & 0x1f)) | |
| 189 | BIT(OP(ATOMIC_ACKNOWLEDGE & 0x1f)) | |
| 190 | BIT(OP(COMPARE_SWAP & 0x1f)) | |
| 191 | BIT(OP(FETCH_ADD & 0x1f)); |
| 192 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 193 | static u32 restart_sge(struct rvt_sge_state *ss, struct rvt_swqe *wqe, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 194 | u32 psn, u32 pmtu) |
| 195 | { |
| 196 | u32 len; |
| 197 | |
| 198 | len = delta_psn(psn, wqe->psn) * pmtu; |
| 199 | ss->sge = wqe->sg_list[0]; |
| 200 | ss->sg_list = wqe->sg_list + 1; |
| 201 | ss->num_sge = wqe->wr.num_sge; |
| 202 | ss->total_len = wqe->length; |
| 203 | hfi1_skip_sge(ss, len, 0); |
| 204 | return wqe->length - len; |
| 205 | } |
| 206 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 207 | /** |
| 208 | * make_rc_ack - construct a response packet (ACK, NAK, or RDMA read) |
| 209 | * @dev: the device for this QP |
| 210 | * @qp: a pointer to the QP |
| 211 | * @ohdr: a pointer to the IB header being constructed |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 212 | * @ps: the xmit packet state |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 213 | * |
| 214 | * Return 1 if constructed; otherwise, return 0. |
| 215 | * Note that we are in the responder's side of the QP context. |
| 216 | * Note the QP s_lock must be held. |
| 217 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 218 | static int make_rc_ack(struct hfi1_ibdev *dev, struct rvt_qp *qp, |
Mike Marciniszyn | 1235bef8 | 2016-02-14 12:45:09 -0800 | [diff] [blame] | 219 | struct hfi1_other_headers *ohdr, |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 220 | struct hfi1_pkt_state *ps) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 221 | { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 222 | struct rvt_ack_entry *e; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 223 | u32 hwords; |
| 224 | u32 len; |
| 225 | u32 bth0; |
| 226 | u32 bth2; |
| 227 | int middle = 0; |
Mike Marciniszyn | 1235bef8 | 2016-02-14 12:45:09 -0800 | [diff] [blame] | 228 | u32 pmtu = qp->pmtu; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 229 | struct hfi1_qp_priv *priv = qp->priv; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 230 | |
| 231 | /* Don't send an ACK if we aren't supposed to. */ |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 232 | if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 233 | goto bail; |
| 234 | |
| 235 | /* header size in 32-bit words LRH+BTH = (8+12)/4. */ |
| 236 | hwords = 5; |
| 237 | |
| 238 | switch (qp->s_ack_state) { |
| 239 | case OP(RDMA_READ_RESPONSE_LAST): |
| 240 | case OP(RDMA_READ_RESPONSE_ONLY): |
| 241 | e = &qp->s_ack_queue[qp->s_tail_ack_queue]; |
| 242 | if (e->rdma_sge.mr) { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 243 | rvt_put_mr(e->rdma_sge.mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 244 | e->rdma_sge.mr = NULL; |
| 245 | } |
| 246 | /* FALLTHROUGH */ |
| 247 | case OP(ATOMIC_ACKNOWLEDGE): |
| 248 | /* |
| 249 | * We can increment the tail pointer now that the last |
| 250 | * response has been sent instead of only being |
| 251 | * constructed. |
| 252 | */ |
| 253 | if (++qp->s_tail_ack_queue > HFI1_MAX_RDMA_ATOMIC) |
| 254 | qp->s_tail_ack_queue = 0; |
| 255 | /* FALLTHROUGH */ |
| 256 | case OP(SEND_ONLY): |
| 257 | case OP(ACKNOWLEDGE): |
| 258 | /* Check for no next entry in the queue. */ |
| 259 | if (qp->r_head_ack_queue == qp->s_tail_ack_queue) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 260 | if (qp->s_flags & RVT_S_ACK_PENDING) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 261 | goto normal; |
| 262 | goto bail; |
| 263 | } |
| 264 | |
| 265 | e = &qp->s_ack_queue[qp->s_tail_ack_queue]; |
| 266 | if (e->opcode == OP(RDMA_READ_REQUEST)) { |
| 267 | /* |
| 268 | * If a RDMA read response is being resent and |
| 269 | * we haven't seen the duplicate request yet, |
| 270 | * then stop sending the remaining responses the |
| 271 | * responder has seen until the requester re-sends it. |
| 272 | */ |
| 273 | len = e->rdma_sge.sge_length; |
| 274 | if (len && !e->rdma_sge.mr) { |
| 275 | qp->s_tail_ack_queue = qp->r_head_ack_queue; |
| 276 | goto bail; |
| 277 | } |
| 278 | /* Copy SGE state in case we need to resend */ |
Mike Marciniszyn | c239a5b | 2016-02-14 12:44:52 -0800 | [diff] [blame] | 279 | ps->s_txreq->mr = e->rdma_sge.mr; |
| 280 | if (ps->s_txreq->mr) |
| 281 | rvt_get_mr(ps->s_txreq->mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 282 | qp->s_ack_rdma_sge.sge = e->rdma_sge; |
| 283 | qp->s_ack_rdma_sge.num_sge = 1; |
| 284 | qp->s_cur_sge = &qp->s_ack_rdma_sge; |
| 285 | if (len > pmtu) { |
| 286 | len = pmtu; |
| 287 | qp->s_ack_state = OP(RDMA_READ_RESPONSE_FIRST); |
| 288 | } else { |
| 289 | qp->s_ack_state = OP(RDMA_READ_RESPONSE_ONLY); |
| 290 | e->sent = 1; |
| 291 | } |
| 292 | ohdr->u.aeth = hfi1_compute_aeth(qp); |
| 293 | hwords++; |
| 294 | qp->s_ack_rdma_psn = e->psn; |
| 295 | bth2 = mask_psn(qp->s_ack_rdma_psn++); |
| 296 | } else { |
| 297 | /* COMPARE_SWAP or FETCH_ADD */ |
| 298 | qp->s_cur_sge = NULL; |
| 299 | len = 0; |
| 300 | qp->s_ack_state = OP(ATOMIC_ACKNOWLEDGE); |
| 301 | ohdr->u.at.aeth = hfi1_compute_aeth(qp); |
| 302 | ohdr->u.at.atomic_ack_eth[0] = |
| 303 | cpu_to_be32(e->atomic_data >> 32); |
| 304 | ohdr->u.at.atomic_ack_eth[1] = |
| 305 | cpu_to_be32(e->atomic_data); |
| 306 | hwords += sizeof(ohdr->u.at) / sizeof(u32); |
| 307 | bth2 = mask_psn(e->psn); |
| 308 | e->sent = 1; |
| 309 | } |
| 310 | bth0 = qp->s_ack_state << 24; |
| 311 | break; |
| 312 | |
| 313 | case OP(RDMA_READ_RESPONSE_FIRST): |
| 314 | qp->s_ack_state = OP(RDMA_READ_RESPONSE_MIDDLE); |
| 315 | /* FALLTHROUGH */ |
| 316 | case OP(RDMA_READ_RESPONSE_MIDDLE): |
| 317 | qp->s_cur_sge = &qp->s_ack_rdma_sge; |
Mike Marciniszyn | c239a5b | 2016-02-14 12:44:52 -0800 | [diff] [blame] | 318 | ps->s_txreq->mr = qp->s_ack_rdma_sge.sge.mr; |
| 319 | if (ps->s_txreq->mr) |
| 320 | rvt_get_mr(ps->s_txreq->mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 321 | len = qp->s_ack_rdma_sge.sge.sge_length; |
| 322 | if (len > pmtu) { |
| 323 | len = pmtu; |
| 324 | middle = HFI1_CAP_IS_KSET(SDMA_AHG); |
| 325 | } else { |
| 326 | ohdr->u.aeth = hfi1_compute_aeth(qp); |
| 327 | hwords++; |
| 328 | qp->s_ack_state = OP(RDMA_READ_RESPONSE_LAST); |
| 329 | e = &qp->s_ack_queue[qp->s_tail_ack_queue]; |
| 330 | e->sent = 1; |
| 331 | } |
| 332 | bth0 = qp->s_ack_state << 24; |
| 333 | bth2 = mask_psn(qp->s_ack_rdma_psn++); |
| 334 | break; |
| 335 | |
| 336 | default: |
| 337 | normal: |
| 338 | /* |
| 339 | * Send a regular ACK. |
| 340 | * Set the s_ack_state so we wait until after sending |
| 341 | * the ACK before setting s_ack_state to ACKNOWLEDGE |
| 342 | * (see above). |
| 343 | */ |
| 344 | qp->s_ack_state = OP(SEND_ONLY); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 345 | qp->s_flags &= ~RVT_S_ACK_PENDING; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 346 | qp->s_cur_sge = NULL; |
| 347 | if (qp->s_nak_state) |
| 348 | ohdr->u.aeth = |
| 349 | cpu_to_be32((qp->r_msn & HFI1_MSN_MASK) | |
| 350 | (qp->s_nak_state << |
| 351 | HFI1_AETH_CREDIT_SHIFT)); |
| 352 | else |
| 353 | ohdr->u.aeth = hfi1_compute_aeth(qp); |
| 354 | hwords++; |
| 355 | len = 0; |
| 356 | bth0 = OP(ACKNOWLEDGE) << 24; |
| 357 | bth2 = mask_psn(qp->s_ack_psn); |
| 358 | } |
| 359 | qp->s_rdma_ack_cnt++; |
| 360 | qp->s_hdrwords = hwords; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 361 | ps->s_txreq->sde = priv->s_sde; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 362 | qp->s_cur_size = len; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 363 | hfi1_make_ruc_header(qp, ohdr, bth0, bth2, middle, ps); |
Jianxin Xiong | aa0ad41 | 2016-02-26 13:33:13 -0800 | [diff] [blame] | 364 | /* pbc */ |
| 365 | ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 366 | return 1; |
| 367 | |
| 368 | bail: |
| 369 | qp->s_ack_state = OP(ACKNOWLEDGE); |
| 370 | /* |
| 371 | * Ensure s_rdma_ack_cnt changes are committed prior to resetting |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 372 | * RVT_S_RESP_PENDING |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 373 | */ |
| 374 | smp_wmb(); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 375 | qp->s_flags &= ~(RVT_S_RESP_PENDING |
| 376 | | RVT_S_ACK_PENDING |
| 377 | | RVT_S_AHG_VALID); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * hfi1_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC) |
| 383 | * @qp: a pointer to the QP |
| 384 | * |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 385 | * Assumes s_lock is held. |
| 386 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 387 | * Return 1 if constructed; otherwise, return 0. |
| 388 | */ |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 389 | int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 390 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 391 | struct hfi1_qp_priv *priv = qp->priv; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 392 | struct hfi1_ibdev *dev = to_idev(qp->ibqp.device); |
| 393 | struct hfi1_other_headers *ohdr; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 394 | struct rvt_sge_state *ss; |
| 395 | struct rvt_swqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 396 | /* header size in 32-bit words LRH+BTH = (8+12)/4. */ |
| 397 | u32 hwords = 5; |
| 398 | u32 len; |
| 399 | u32 bth0 = 0; |
| 400 | u32 bth2; |
| 401 | u32 pmtu = qp->pmtu; |
| 402 | char newreq; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 403 | int middle = 0; |
| 404 | int delta; |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame^] | 405 | int err; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 406 | |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 407 | ps->s_txreq = get_txreq(ps->dev, qp); |
| 408 | if (IS_ERR(ps->s_txreq)) |
| 409 | goto bail_no_tx; |
| 410 | |
| 411 | ohdr = &ps->s_txreq->phdr.hdr.u.oth; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 412 | if (qp->remote_ah_attr.ah_flags & IB_AH_GRH) |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 413 | ohdr = &ps->s_txreq->phdr.hdr.u.l.oth; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 414 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 415 | /* Sending responses has higher priority over sending requests. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 416 | if ((qp->s_flags & RVT_S_RESP_PENDING) && |
Mike Marciniszyn | 1235bef8 | 2016-02-14 12:45:09 -0800 | [diff] [blame] | 417 | make_rc_ack(dev, qp, ohdr, ps)) |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 418 | return 1; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 419 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 420 | if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) { |
| 421 | if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 422 | goto bail; |
| 423 | /* We are in the error state, flush the work request. */ |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 424 | smp_read_barrier_depends(); /* see post_one_send() */ |
| 425 | if (qp->s_last == ACCESS_ONCE(qp->s_head)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 426 | goto bail; |
| 427 | /* If DMAs are in progress, we can't flush immediately. */ |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 428 | if (iowait_sdma_pending(&priv->s_iowait)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 429 | qp->s_flags |= RVT_S_WAIT_DMA; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 430 | goto bail; |
| 431 | } |
| 432 | clear_ahg(qp); |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 433 | wqe = rvt_get_swqe_ptr(qp, qp->s_last); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 434 | hfi1_send_complete(qp, wqe, qp->s_last != qp->s_acked ? |
| 435 | IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR); |
| 436 | /* will get called again */ |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 437 | goto done_free_tx; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 440 | if (qp->s_flags & (RVT_S_WAIT_RNR | RVT_S_WAIT_ACK)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 441 | goto bail; |
| 442 | |
| 443 | if (cmp_psn(qp->s_psn, qp->s_sending_hpsn) <= 0) { |
| 444 | if (cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 445 | qp->s_flags |= RVT_S_WAIT_PSN; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 446 | goto bail; |
| 447 | } |
| 448 | qp->s_sending_psn = qp->s_psn; |
| 449 | qp->s_sending_hpsn = qp->s_psn - 1; |
| 450 | } |
| 451 | |
| 452 | /* Send a request. */ |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 453 | wqe = rvt_get_swqe_ptr(qp, qp->s_cur); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 454 | switch (qp->s_state) { |
| 455 | default: |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 456 | if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 457 | goto bail; |
| 458 | /* |
| 459 | * Resend an old request or start a new one. |
| 460 | * |
| 461 | * We keep track of the current SWQE so that |
| 462 | * we don't reset the "furthest progress" state |
| 463 | * if we need to back up. |
| 464 | */ |
| 465 | newreq = 0; |
| 466 | if (qp->s_cur == qp->s_tail) { |
| 467 | /* Check if send work queue is empty. */ |
| 468 | if (qp->s_tail == qp->s_head) { |
| 469 | clear_ahg(qp); |
| 470 | goto bail; |
| 471 | } |
| 472 | /* |
| 473 | * If a fence is requested, wait for previous |
| 474 | * RDMA read and atomic operations to finish. |
| 475 | */ |
| 476 | if ((wqe->wr.send_flags & IB_SEND_FENCE) && |
| 477 | qp->s_num_rd_atomic) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 478 | qp->s_flags |= RVT_S_WAIT_FENCE; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 479 | goto bail; |
| 480 | } |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame^] | 481 | /* |
| 482 | * Local operations are processed immediately |
| 483 | * after all prior requests have completed |
| 484 | */ |
| 485 | if (wqe->wr.opcode == IB_WR_REG_MR || |
| 486 | wqe->wr.opcode == IB_WR_LOCAL_INV) { |
| 487 | if (qp->s_last != qp->s_cur) |
| 488 | goto bail; |
| 489 | if (++qp->s_cur == qp->s_size) |
| 490 | qp->s_cur = 0; |
| 491 | if (++qp->s_tail == qp->s_size) |
| 492 | qp->s_tail = 0; |
| 493 | if (wqe->wr.opcode == IB_WR_REG_MR) |
| 494 | err = rvt_fast_reg_mr( |
| 495 | qp, wqe->reg_wr.mr, |
| 496 | wqe->reg_wr.key, |
| 497 | wqe->reg_wr.access); |
| 498 | else |
| 499 | err = rvt_invalidate_rkey( |
| 500 | qp, |
| 501 | wqe->wr.ex.invalidate_rkey); |
| 502 | hfi1_send_complete(qp, wqe, |
| 503 | err ? IB_WC_LOC_PROT_ERR |
| 504 | : IB_WC_SUCCESS); |
| 505 | atomic_dec(&qp->local_ops_pending); |
| 506 | qp->s_hdrwords = 0; |
| 507 | goto done_free_tx; |
| 508 | } |
| 509 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 510 | newreq = 1; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 511 | qp->s_psn = wqe->psn; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 512 | } |
| 513 | /* |
| 514 | * Note that we have to be careful not to modify the |
| 515 | * original work request since we may need to resend |
| 516 | * it. |
| 517 | */ |
| 518 | len = wqe->length; |
| 519 | ss = &qp->s_sge; |
| 520 | bth2 = mask_psn(qp->s_psn); |
| 521 | switch (wqe->wr.opcode) { |
| 522 | case IB_WR_SEND: |
| 523 | case IB_WR_SEND_WITH_IMM: |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame^] | 524 | case IB_WR_SEND_WITH_INV: |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 525 | /* If no credit, return. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 526 | if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) && |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 527 | cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 528 | qp->s_flags |= RVT_S_WAIT_SSN_CREDIT; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 529 | goto bail; |
| 530 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 531 | if (len > pmtu) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 532 | qp->s_state = OP(SEND_FIRST); |
| 533 | len = pmtu; |
| 534 | break; |
| 535 | } |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 536 | if (wqe->wr.opcode == IB_WR_SEND) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 537 | qp->s_state = OP(SEND_ONLY); |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame^] | 538 | } else if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 539 | qp->s_state = OP(SEND_ONLY_WITH_IMMEDIATE); |
| 540 | /* Immediate data comes after the BTH */ |
| 541 | ohdr->u.imm_data = wqe->wr.ex.imm_data; |
| 542 | hwords += 1; |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame^] | 543 | } else { |
| 544 | qp->s_state = OP(SEND_ONLY_WITH_INVALIDATE); |
| 545 | /* Invalidate rkey comes after the BTH */ |
| 546 | ohdr->u.ieth = cpu_to_be32( |
| 547 | wqe->wr.ex.invalidate_rkey); |
| 548 | hwords += 1; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 549 | } |
| 550 | if (wqe->wr.send_flags & IB_SEND_SOLICITED) |
| 551 | bth0 |= IB_BTH_SOLICITED; |
| 552 | bth2 |= IB_BTH_REQ_ACK; |
| 553 | if (++qp->s_cur == qp->s_size) |
| 554 | qp->s_cur = 0; |
| 555 | break; |
| 556 | |
| 557 | case IB_WR_RDMA_WRITE: |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 558 | if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 559 | qp->s_lsn++; |
| 560 | /* FALLTHROUGH */ |
| 561 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 562 | /* If no credit, return. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 563 | if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) && |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 564 | cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 565 | qp->s_flags |= RVT_S_WAIT_SSN_CREDIT; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 566 | goto bail; |
| 567 | } |
| 568 | ohdr->u.rc.reth.vaddr = |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 569 | cpu_to_be64(wqe->rdma_wr.remote_addr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 570 | ohdr->u.rc.reth.rkey = |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 571 | cpu_to_be32(wqe->rdma_wr.rkey); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 572 | ohdr->u.rc.reth.length = cpu_to_be32(len); |
| 573 | hwords += sizeof(struct ib_reth) / sizeof(u32); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 574 | if (len > pmtu) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 575 | qp->s_state = OP(RDMA_WRITE_FIRST); |
| 576 | len = pmtu; |
| 577 | break; |
| 578 | } |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 579 | if (wqe->wr.opcode == IB_WR_RDMA_WRITE) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 580 | qp->s_state = OP(RDMA_WRITE_ONLY); |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 581 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 582 | qp->s_state = |
| 583 | OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE); |
| 584 | /* Immediate data comes after RETH */ |
| 585 | ohdr->u.rc.imm_data = wqe->wr.ex.imm_data; |
| 586 | hwords += 1; |
| 587 | if (wqe->wr.send_flags & IB_SEND_SOLICITED) |
| 588 | bth0 |= IB_BTH_SOLICITED; |
| 589 | } |
| 590 | bth2 |= IB_BTH_REQ_ACK; |
| 591 | if (++qp->s_cur == qp->s_size) |
| 592 | qp->s_cur = 0; |
| 593 | break; |
| 594 | |
| 595 | case IB_WR_RDMA_READ: |
| 596 | /* |
| 597 | * Don't allow more operations to be started |
| 598 | * than the QP limits allow. |
| 599 | */ |
| 600 | if (newreq) { |
| 601 | if (qp->s_num_rd_atomic >= |
| 602 | qp->s_max_rd_atomic) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 603 | qp->s_flags |= RVT_S_WAIT_RDMAR; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 604 | goto bail; |
| 605 | } |
| 606 | qp->s_num_rd_atomic++; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 607 | if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 608 | qp->s_lsn++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 609 | } |
| 610 | ohdr->u.rc.reth.vaddr = |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 611 | cpu_to_be64(wqe->rdma_wr.remote_addr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 612 | ohdr->u.rc.reth.rkey = |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 613 | cpu_to_be32(wqe->rdma_wr.rkey); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 614 | ohdr->u.rc.reth.length = cpu_to_be32(len); |
| 615 | qp->s_state = OP(RDMA_READ_REQUEST); |
| 616 | hwords += sizeof(ohdr->u.rc.reth) / sizeof(u32); |
| 617 | ss = NULL; |
| 618 | len = 0; |
| 619 | bth2 |= IB_BTH_REQ_ACK; |
| 620 | if (++qp->s_cur == qp->s_size) |
| 621 | qp->s_cur = 0; |
| 622 | break; |
| 623 | |
| 624 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 625 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
| 626 | /* |
| 627 | * Don't allow more operations to be started |
| 628 | * than the QP limits allow. |
| 629 | */ |
| 630 | if (newreq) { |
| 631 | if (qp->s_num_rd_atomic >= |
| 632 | qp->s_max_rd_atomic) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 633 | qp->s_flags |= RVT_S_WAIT_RDMAR; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 634 | goto bail; |
| 635 | } |
| 636 | qp->s_num_rd_atomic++; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 637 | if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 638 | qp->s_lsn++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 639 | } |
| 640 | if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP) { |
| 641 | qp->s_state = OP(COMPARE_SWAP); |
| 642 | ohdr->u.atomic_eth.swap_data = cpu_to_be64( |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 643 | wqe->atomic_wr.swap); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 644 | ohdr->u.atomic_eth.compare_data = cpu_to_be64( |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 645 | wqe->atomic_wr.compare_add); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 646 | } else { |
| 647 | qp->s_state = OP(FETCH_ADD); |
| 648 | ohdr->u.atomic_eth.swap_data = cpu_to_be64( |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 649 | wqe->atomic_wr.compare_add); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 650 | ohdr->u.atomic_eth.compare_data = 0; |
| 651 | } |
| 652 | ohdr->u.atomic_eth.vaddr[0] = cpu_to_be32( |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 653 | wqe->atomic_wr.remote_addr >> 32); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 654 | ohdr->u.atomic_eth.vaddr[1] = cpu_to_be32( |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 655 | wqe->atomic_wr.remote_addr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 656 | ohdr->u.atomic_eth.rkey = cpu_to_be32( |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 657 | wqe->atomic_wr.rkey); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 658 | hwords += sizeof(struct ib_atomic_eth) / sizeof(u32); |
| 659 | ss = NULL; |
| 660 | len = 0; |
| 661 | bth2 |= IB_BTH_REQ_ACK; |
| 662 | if (++qp->s_cur == qp->s_size) |
| 663 | qp->s_cur = 0; |
| 664 | break; |
| 665 | |
| 666 | default: |
| 667 | goto bail; |
| 668 | } |
| 669 | qp->s_sge.sge = wqe->sg_list[0]; |
| 670 | qp->s_sge.sg_list = wqe->sg_list + 1; |
| 671 | qp->s_sge.num_sge = wqe->wr.num_sge; |
| 672 | qp->s_sge.total_len = wqe->length; |
| 673 | qp->s_len = wqe->length; |
| 674 | if (newreq) { |
| 675 | qp->s_tail++; |
| 676 | if (qp->s_tail >= qp->s_size) |
| 677 | qp->s_tail = 0; |
| 678 | } |
| 679 | if (wqe->wr.opcode == IB_WR_RDMA_READ) |
| 680 | qp->s_psn = wqe->lpsn + 1; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 681 | else |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 682 | qp->s_psn++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 683 | break; |
| 684 | |
| 685 | case OP(RDMA_READ_RESPONSE_FIRST): |
| 686 | /* |
| 687 | * qp->s_state is normally set to the opcode of the |
| 688 | * last packet constructed for new requests and therefore |
| 689 | * is never set to RDMA read response. |
| 690 | * RDMA_READ_RESPONSE_FIRST is used by the ACK processing |
| 691 | * thread to indicate a SEND needs to be restarted from an |
| 692 | * earlier PSN without interfering with the sending thread. |
| 693 | * See restart_rc(). |
| 694 | */ |
| 695 | qp->s_len = restart_sge(&qp->s_sge, wqe, qp->s_psn, pmtu); |
| 696 | /* FALLTHROUGH */ |
| 697 | case OP(SEND_FIRST): |
| 698 | qp->s_state = OP(SEND_MIDDLE); |
| 699 | /* FALLTHROUGH */ |
| 700 | case OP(SEND_MIDDLE): |
| 701 | bth2 = mask_psn(qp->s_psn++); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 702 | ss = &qp->s_sge; |
| 703 | len = qp->s_len; |
| 704 | if (len > pmtu) { |
| 705 | len = pmtu; |
| 706 | middle = HFI1_CAP_IS_KSET(SDMA_AHG); |
| 707 | break; |
| 708 | } |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 709 | if (wqe->wr.opcode == IB_WR_SEND) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 710 | qp->s_state = OP(SEND_LAST); |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame^] | 711 | } else if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 712 | qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE); |
| 713 | /* Immediate data comes after the BTH */ |
| 714 | ohdr->u.imm_data = wqe->wr.ex.imm_data; |
| 715 | hwords += 1; |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame^] | 716 | } else { |
| 717 | qp->s_state = OP(SEND_LAST_WITH_INVALIDATE); |
| 718 | /* invalidate data comes after the BTH */ |
| 719 | ohdr->u.ieth = cpu_to_be32(wqe->wr.ex.invalidate_rkey); |
| 720 | hwords += 1; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 721 | } |
| 722 | if (wqe->wr.send_flags & IB_SEND_SOLICITED) |
| 723 | bth0 |= IB_BTH_SOLICITED; |
| 724 | bth2 |= IB_BTH_REQ_ACK; |
| 725 | qp->s_cur++; |
| 726 | if (qp->s_cur >= qp->s_size) |
| 727 | qp->s_cur = 0; |
| 728 | break; |
| 729 | |
| 730 | case OP(RDMA_READ_RESPONSE_LAST): |
| 731 | /* |
| 732 | * qp->s_state is normally set to the opcode of the |
| 733 | * last packet constructed for new requests and therefore |
| 734 | * is never set to RDMA read response. |
| 735 | * RDMA_READ_RESPONSE_LAST is used by the ACK processing |
| 736 | * thread to indicate a RDMA write needs to be restarted from |
| 737 | * an earlier PSN without interfering with the sending thread. |
| 738 | * See restart_rc(). |
| 739 | */ |
| 740 | qp->s_len = restart_sge(&qp->s_sge, wqe, qp->s_psn, pmtu); |
| 741 | /* FALLTHROUGH */ |
| 742 | case OP(RDMA_WRITE_FIRST): |
| 743 | qp->s_state = OP(RDMA_WRITE_MIDDLE); |
| 744 | /* FALLTHROUGH */ |
| 745 | case OP(RDMA_WRITE_MIDDLE): |
| 746 | bth2 = mask_psn(qp->s_psn++); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 747 | ss = &qp->s_sge; |
| 748 | len = qp->s_len; |
| 749 | if (len > pmtu) { |
| 750 | len = pmtu; |
| 751 | middle = HFI1_CAP_IS_KSET(SDMA_AHG); |
| 752 | break; |
| 753 | } |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 754 | if (wqe->wr.opcode == IB_WR_RDMA_WRITE) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 755 | qp->s_state = OP(RDMA_WRITE_LAST); |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 756 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 757 | qp->s_state = OP(RDMA_WRITE_LAST_WITH_IMMEDIATE); |
| 758 | /* Immediate data comes after the BTH */ |
| 759 | ohdr->u.imm_data = wqe->wr.ex.imm_data; |
| 760 | hwords += 1; |
| 761 | if (wqe->wr.send_flags & IB_SEND_SOLICITED) |
| 762 | bth0 |= IB_BTH_SOLICITED; |
| 763 | } |
| 764 | bth2 |= IB_BTH_REQ_ACK; |
| 765 | qp->s_cur++; |
| 766 | if (qp->s_cur >= qp->s_size) |
| 767 | qp->s_cur = 0; |
| 768 | break; |
| 769 | |
| 770 | case OP(RDMA_READ_RESPONSE_MIDDLE): |
| 771 | /* |
| 772 | * qp->s_state is normally set to the opcode of the |
| 773 | * last packet constructed for new requests and therefore |
| 774 | * is never set to RDMA read response. |
| 775 | * RDMA_READ_RESPONSE_MIDDLE is used by the ACK processing |
| 776 | * thread to indicate a RDMA read needs to be restarted from |
| 777 | * an earlier PSN without interfering with the sending thread. |
| 778 | * See restart_rc(). |
| 779 | */ |
| 780 | len = (delta_psn(qp->s_psn, wqe->psn)) * pmtu; |
| 781 | ohdr->u.rc.reth.vaddr = |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 782 | cpu_to_be64(wqe->rdma_wr.remote_addr + len); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 783 | ohdr->u.rc.reth.rkey = |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 784 | cpu_to_be32(wqe->rdma_wr.rkey); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 785 | ohdr->u.rc.reth.length = cpu_to_be32(wqe->length - len); |
| 786 | qp->s_state = OP(RDMA_READ_REQUEST); |
| 787 | hwords += sizeof(ohdr->u.rc.reth) / sizeof(u32); |
| 788 | bth2 = mask_psn(qp->s_psn) | IB_BTH_REQ_ACK; |
| 789 | qp->s_psn = wqe->lpsn + 1; |
| 790 | ss = NULL; |
| 791 | len = 0; |
| 792 | qp->s_cur++; |
| 793 | if (qp->s_cur == qp->s_size) |
| 794 | qp->s_cur = 0; |
| 795 | break; |
| 796 | } |
| 797 | qp->s_sending_hpsn = bth2; |
| 798 | delta = delta_psn(bth2, wqe->psn); |
| 799 | if (delta && delta % HFI1_PSN_CREDIT == 0) |
| 800 | bth2 |= IB_BTH_REQ_ACK; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 801 | if (qp->s_flags & RVT_S_SEND_ONE) { |
| 802 | qp->s_flags &= ~RVT_S_SEND_ONE; |
| 803 | qp->s_flags |= RVT_S_WAIT_ACK; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 804 | bth2 |= IB_BTH_REQ_ACK; |
| 805 | } |
| 806 | qp->s_len -= len; |
| 807 | qp->s_hdrwords = hwords; |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 808 | ps->s_txreq->sde = priv->s_sde; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 809 | qp->s_cur_sge = ss; |
| 810 | qp->s_cur_size = len; |
| 811 | hfi1_make_ruc_header( |
| 812 | qp, |
| 813 | ohdr, |
| 814 | bth0 | (qp->s_state << 24), |
| 815 | bth2, |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 816 | middle, |
| 817 | ps); |
Jianxin Xiong | aa0ad41 | 2016-02-26 13:33:13 -0800 | [diff] [blame] | 818 | /* pbc */ |
| 819 | ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 820 | return 1; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 821 | |
| 822 | done_free_tx: |
| 823 | hfi1_put_txreq(ps->s_txreq); |
| 824 | ps->s_txreq = NULL; |
| 825 | return 1; |
| 826 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 827 | bail: |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 828 | hfi1_put_txreq(ps->s_txreq); |
| 829 | |
| 830 | bail_no_tx: |
| 831 | ps->s_txreq = NULL; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 832 | qp->s_flags &= ~RVT_S_BUSY; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 833 | qp->s_hdrwords = 0; |
| 834 | return 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | /** |
| 838 | * hfi1_send_rc_ack - Construct an ACK packet and send it |
| 839 | * @qp: a pointer to the QP |
| 840 | * |
| 841 | * This is called from hfi1_rc_rcv() and handle_receive_interrupt(). |
| 842 | * Note that RDMA reads and atomics are handled in the |
| 843 | * send side QP state and tasklet. |
| 844 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 845 | void hfi1_send_rc_ack(struct hfi1_ctxtdata *rcd, struct rvt_qp *qp, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 846 | int is_fecn) |
| 847 | { |
| 848 | struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); |
| 849 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
| 850 | u64 pbc, pbc_flags = 0; |
| 851 | u16 lrh0; |
| 852 | u16 sc5; |
| 853 | u32 bth0; |
| 854 | u32 hwords; |
| 855 | u32 vl, plen; |
| 856 | struct send_context *sc; |
| 857 | struct pio_buf *pbuf; |
| 858 | struct hfi1_ib_header hdr; |
| 859 | struct hfi1_other_headers *ohdr; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 860 | unsigned long flags; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 861 | |
| 862 | /* Don't send ACK or NAK if a RDMA read or atomic is pending. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 863 | if (qp->s_flags & RVT_S_RESP_PENDING) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 864 | goto queue_ack; |
| 865 | |
| 866 | /* Ensure s_rdma_ack_cnt changes are committed */ |
| 867 | smp_read_barrier_depends(); |
| 868 | if (qp->s_rdma_ack_cnt) |
| 869 | goto queue_ack; |
| 870 | |
| 871 | /* Construct the header */ |
| 872 | /* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4 */ |
| 873 | hwords = 6; |
| 874 | if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) { |
| 875 | hwords += hfi1_make_grh(ibp, &hdr.u.l.grh, |
| 876 | &qp->remote_ah_attr.grh, hwords, 0); |
| 877 | ohdr = &hdr.u.l.oth; |
| 878 | lrh0 = HFI1_LRH_GRH; |
| 879 | } else { |
| 880 | ohdr = &hdr.u.oth; |
| 881 | lrh0 = HFI1_LRH_BTH; |
| 882 | } |
| 883 | /* read pkey_index w/o lock (its atomic) */ |
| 884 | bth0 = hfi1_get_pkey(ibp, qp->s_pkey_index) | (OP(ACKNOWLEDGE) << 24); |
| 885 | if (qp->s_mig_state == IB_MIG_MIGRATED) |
| 886 | bth0 |= IB_BTH_MIG_REQ; |
| 887 | if (qp->r_nak_state) |
| 888 | ohdr->u.aeth = cpu_to_be32((qp->r_msn & HFI1_MSN_MASK) | |
| 889 | (qp->r_nak_state << |
| 890 | HFI1_AETH_CREDIT_SHIFT)); |
| 891 | else |
| 892 | ohdr->u.aeth = hfi1_compute_aeth(qp); |
| 893 | sc5 = ibp->sl_to_sc[qp->remote_ah_attr.sl]; |
| 894 | /* set PBC_DC_INFO bit (aka SC[4]) in pbc_flags */ |
| 895 | pbc_flags |= ((!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT); |
| 896 | lrh0 |= (sc5 & 0xf) << 12 | (qp->remote_ah_attr.sl & 0xf) << 4; |
| 897 | hdr.lrh[0] = cpu_to_be16(lrh0); |
| 898 | hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid); |
| 899 | hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC); |
| 900 | hdr.lrh[3] = cpu_to_be16(ppd->lid | qp->remote_ah_attr.src_path_bits); |
| 901 | ohdr->bth[0] = cpu_to_be32(bth0); |
| 902 | ohdr->bth[1] = cpu_to_be32(qp->remote_qpn); |
| 903 | ohdr->bth[1] |= cpu_to_be32((!!is_fecn) << HFI1_BECN_SHIFT); |
| 904 | ohdr->bth[2] = cpu_to_be32(mask_psn(qp->r_ack_psn)); |
| 905 | |
| 906 | /* Don't try to send ACKs if the link isn't ACTIVE */ |
| 907 | if (driver_lstate(ppd) != IB_PORT_ACTIVE) |
| 908 | return; |
| 909 | |
| 910 | sc = rcd->sc; |
| 911 | plen = 2 /* PBC */ + hwords; |
| 912 | vl = sc_to_vlt(ppd->dd, sc5); |
| 913 | pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen); |
| 914 | |
| 915 | pbuf = sc_buffer_alloc(sc, plen, NULL, NULL); |
| 916 | if (!pbuf) { |
| 917 | /* |
| 918 | * We have no room to send at the moment. Pass |
| 919 | * responsibility for sending the ACK to the send tasklet |
| 920 | * so that when enough buffer space becomes available, |
| 921 | * the ACK is sent ahead of other outgoing packets. |
| 922 | */ |
| 923 | goto queue_ack; |
| 924 | } |
| 925 | |
Mike Marciniszyn | 1db78ee | 2016-03-07 11:35:19 -0800 | [diff] [blame] | 926 | trace_ack_output_ibhdr(dd_from_ibdev(qp->ibqp.device), &hdr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 927 | |
| 928 | /* write the pbc and data */ |
| 929 | ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc, &hdr, hwords); |
| 930 | |
| 931 | return; |
| 932 | |
| 933 | queue_ack: |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 934 | this_cpu_inc(*ibp->rvp.rc_qacks); |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 935 | spin_lock_irqsave(&qp->s_lock, flags); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 936 | qp->s_flags |= RVT_S_ACK_PENDING | RVT_S_RESP_PENDING; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 937 | qp->s_nak_state = qp->r_nak_state; |
| 938 | qp->s_ack_psn = qp->r_ack_psn; |
| 939 | if (is_fecn) |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 940 | qp->s_flags |= RVT_S_ECN; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 941 | |
| 942 | /* Schedule the send tasklet. */ |
| 943 | hfi1_schedule_send(qp); |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 944 | spin_unlock_irqrestore(&qp->s_lock, flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /** |
| 948 | * reset_psn - reset the QP state to send starting from PSN |
| 949 | * @qp: the QP |
| 950 | * @psn: the packet sequence number to restart at |
| 951 | * |
| 952 | * This is called from hfi1_rc_rcv() to process an incoming RC ACK |
| 953 | * for the given QP. |
| 954 | * Called at interrupt level with the QP s_lock held. |
| 955 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 956 | static void reset_psn(struct rvt_qp *qp, u32 psn) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 957 | { |
| 958 | u32 n = qp->s_acked; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 959 | struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, n); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 960 | u32 opcode; |
| 961 | |
| 962 | qp->s_cur = n; |
| 963 | |
| 964 | /* |
| 965 | * If we are starting the request from the beginning, |
| 966 | * let the normal send code handle initialization. |
| 967 | */ |
| 968 | if (cmp_psn(psn, wqe->psn) <= 0) { |
| 969 | qp->s_state = OP(SEND_LAST); |
| 970 | goto done; |
| 971 | } |
| 972 | |
| 973 | /* Find the work request opcode corresponding to the given PSN. */ |
| 974 | opcode = wqe->wr.opcode; |
| 975 | for (;;) { |
| 976 | int diff; |
| 977 | |
| 978 | if (++n == qp->s_size) |
| 979 | n = 0; |
| 980 | if (n == qp->s_tail) |
| 981 | break; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 982 | wqe = rvt_get_swqe_ptr(qp, n); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 983 | diff = cmp_psn(psn, wqe->psn); |
| 984 | if (diff < 0) |
| 985 | break; |
| 986 | qp->s_cur = n; |
| 987 | /* |
| 988 | * If we are starting the request from the beginning, |
| 989 | * let the normal send code handle initialization. |
| 990 | */ |
| 991 | if (diff == 0) { |
| 992 | qp->s_state = OP(SEND_LAST); |
| 993 | goto done; |
| 994 | } |
| 995 | opcode = wqe->wr.opcode; |
| 996 | } |
| 997 | |
| 998 | /* |
| 999 | * Set the state to restart in the middle of a request. |
| 1000 | * Don't change the s_sge, s_cur_sge, or s_cur_size. |
| 1001 | * See hfi1_make_rc_req(). |
| 1002 | */ |
| 1003 | switch (opcode) { |
| 1004 | case IB_WR_SEND: |
| 1005 | case IB_WR_SEND_WITH_IMM: |
| 1006 | qp->s_state = OP(RDMA_READ_RESPONSE_FIRST); |
| 1007 | break; |
| 1008 | |
| 1009 | case IB_WR_RDMA_WRITE: |
| 1010 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 1011 | qp->s_state = OP(RDMA_READ_RESPONSE_LAST); |
| 1012 | break; |
| 1013 | |
| 1014 | case IB_WR_RDMA_READ: |
| 1015 | qp->s_state = OP(RDMA_READ_RESPONSE_MIDDLE); |
| 1016 | break; |
| 1017 | |
| 1018 | default: |
| 1019 | /* |
| 1020 | * This case shouldn't happen since its only |
| 1021 | * one PSN per req. |
| 1022 | */ |
| 1023 | qp->s_state = OP(SEND_LAST); |
| 1024 | } |
| 1025 | done: |
| 1026 | qp->s_psn = psn; |
| 1027 | /* |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1028 | * Set RVT_S_WAIT_PSN as rc_complete() may start the timer |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1029 | * asynchronously before the send tasklet can get scheduled. |
| 1030 | * Doing it in hfi1_make_rc_req() is too late. |
| 1031 | */ |
| 1032 | if ((cmp_psn(qp->s_psn, qp->s_sending_hpsn) <= 0) && |
| 1033 | (cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)) |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1034 | qp->s_flags |= RVT_S_WAIT_PSN; |
| 1035 | qp->s_flags &= ~RVT_S_AHG_VALID; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | /* |
| 1039 | * Back up requester to resend the last un-ACKed request. |
| 1040 | * The QP r_lock and s_lock should be held and interrupts disabled. |
| 1041 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1042 | static void restart_rc(struct rvt_qp *qp, u32 psn, int wait) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1043 | { |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1044 | struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_acked); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1045 | struct hfi1_ibport *ibp; |
| 1046 | |
| 1047 | if (qp->s_retry == 0) { |
| 1048 | if (qp->s_mig_state == IB_MIG_ARMED) { |
| 1049 | hfi1_migrate_qp(qp); |
| 1050 | qp->s_retry = qp->s_retry_cnt; |
| 1051 | } else if (qp->s_last == qp->s_acked) { |
| 1052 | hfi1_send_complete(qp, wqe, IB_WC_RETRY_EXC_ERR); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 1053 | rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1054 | return; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 1055 | } else { /* need to handle delayed completion */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1056 | return; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 1057 | } |
| 1058 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1059 | qp->s_retry--; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 1060 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1061 | |
| 1062 | ibp = to_iport(qp->ibqp.device, qp->port_num); |
| 1063 | if (wqe->wr.opcode == IB_WR_RDMA_READ) |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1064 | ibp->rvp.n_rc_resends++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1065 | else |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1066 | ibp->rvp.n_rc_resends += delta_psn(qp->s_psn, psn); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1067 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1068 | qp->s_flags &= ~(RVT_S_WAIT_FENCE | RVT_S_WAIT_RDMAR | |
| 1069 | RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_PSN | |
| 1070 | RVT_S_WAIT_ACK); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1071 | if (wait) |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1072 | qp->s_flags |= RVT_S_SEND_ONE; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1073 | reset_psn(qp, psn); |
| 1074 | } |
| 1075 | |
| 1076 | /* |
| 1077 | * This is called from s_timer for missing responses. |
| 1078 | */ |
Mike Marciniszyn | 08279d5 | 2016-02-04 10:59:36 -0800 | [diff] [blame] | 1079 | void hfi1_rc_timeout(unsigned long arg) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1080 | { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1081 | struct rvt_qp *qp = (struct rvt_qp *)arg; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1082 | struct hfi1_ibport *ibp; |
| 1083 | unsigned long flags; |
| 1084 | |
| 1085 | spin_lock_irqsave(&qp->r_lock, flags); |
| 1086 | spin_lock(&qp->s_lock); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1087 | if (qp->s_flags & RVT_S_TIMER) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1088 | ibp = to_iport(qp->ibqp.device, qp->port_num); |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1089 | ibp->rvp.n_rc_timeouts++; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1090 | qp->s_flags &= ~RVT_S_TIMER; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1091 | del_timer(&qp->s_timer); |
Sebastian Sanchez | 462b6b2 | 2016-07-01 16:01:06 -0700 | [diff] [blame] | 1092 | trace_hfi1_timeout(qp, qp->s_last_psn + 1); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1093 | restart_rc(qp, qp->s_last_psn + 1, 1); |
| 1094 | hfi1_schedule_send(qp); |
| 1095 | } |
| 1096 | spin_unlock(&qp->s_lock); |
| 1097 | spin_unlock_irqrestore(&qp->r_lock, flags); |
| 1098 | } |
| 1099 | |
| 1100 | /* |
| 1101 | * This is called from s_timer for RNR timeouts. |
| 1102 | */ |
| 1103 | void hfi1_rc_rnr_retry(unsigned long arg) |
| 1104 | { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1105 | struct rvt_qp *qp = (struct rvt_qp *)arg; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1106 | unsigned long flags; |
| 1107 | |
| 1108 | spin_lock_irqsave(&qp->s_lock, flags); |
Mike Marciniszyn | e6f8c2b | 2016-02-04 10:59:09 -0800 | [diff] [blame] | 1109 | hfi1_stop_rnr_timer(qp); |
| 1110 | hfi1_schedule_send(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1111 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 1112 | } |
| 1113 | |
| 1114 | /* |
| 1115 | * Set qp->s_sending_psn to the next PSN after the given one. |
| 1116 | * This would be psn+1 except when RDMA reads are present. |
| 1117 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1118 | static void reset_sending_psn(struct rvt_qp *qp, u32 psn) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1119 | { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1120 | struct rvt_swqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1121 | u32 n = qp->s_last; |
| 1122 | |
| 1123 | /* Find the work request corresponding to the given PSN. */ |
| 1124 | for (;;) { |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1125 | wqe = rvt_get_swqe_ptr(qp, n); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1126 | if (cmp_psn(psn, wqe->lpsn) <= 0) { |
| 1127 | if (wqe->wr.opcode == IB_WR_RDMA_READ) |
| 1128 | qp->s_sending_psn = wqe->lpsn + 1; |
| 1129 | else |
| 1130 | qp->s_sending_psn = psn + 1; |
| 1131 | break; |
| 1132 | } |
| 1133 | if (++n == qp->s_size) |
| 1134 | n = 0; |
| 1135 | if (n == qp->s_tail) |
| 1136 | break; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | /* |
| 1141 | * This should be called with the QP s_lock held and interrupts disabled. |
| 1142 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1143 | void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_ib_header *hdr) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1144 | { |
| 1145 | struct hfi1_other_headers *ohdr; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1146 | struct rvt_swqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1147 | struct ib_wc wc; |
| 1148 | unsigned i; |
| 1149 | u32 opcode; |
| 1150 | u32 psn; |
| 1151 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1152 | if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1153 | return; |
| 1154 | |
| 1155 | /* Find out where the BTH is */ |
| 1156 | if ((be16_to_cpu(hdr->lrh[0]) & 3) == HFI1_LRH_BTH) |
| 1157 | ohdr = &hdr->u.oth; |
| 1158 | else |
| 1159 | ohdr = &hdr->u.l.oth; |
| 1160 | |
| 1161 | opcode = be32_to_cpu(ohdr->bth[0]) >> 24; |
| 1162 | if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) && |
| 1163 | opcode <= OP(ATOMIC_ACKNOWLEDGE)) { |
| 1164 | WARN_ON(!qp->s_rdma_ack_cnt); |
| 1165 | qp->s_rdma_ack_cnt--; |
| 1166 | return; |
| 1167 | } |
| 1168 | |
| 1169 | psn = be32_to_cpu(ohdr->bth[2]); |
| 1170 | reset_sending_psn(qp, psn); |
| 1171 | |
| 1172 | /* |
| 1173 | * Start timer after a packet requesting an ACK has been sent and |
| 1174 | * there are still requests that haven't been acked. |
| 1175 | */ |
| 1176 | if ((psn & IB_BTH_REQ_ACK) && qp->s_acked != qp->s_tail && |
| 1177 | !(qp->s_flags & |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1178 | (RVT_S_TIMER | RVT_S_WAIT_RNR | RVT_S_WAIT_PSN)) && |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1179 | (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) |
Mike Marciniszyn | e6f8c2b | 2016-02-04 10:59:09 -0800 | [diff] [blame] | 1180 | hfi1_add_retry_timer(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1181 | |
| 1182 | while (qp->s_last != qp->s_acked) { |
Mike Marciniszyn | 6c2ab0b | 2016-02-04 11:03:19 -0800 | [diff] [blame] | 1183 | u32 s_last; |
| 1184 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1185 | wqe = rvt_get_swqe_ptr(qp, qp->s_last); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1186 | if (cmp_psn(wqe->lpsn, qp->s_sending_psn) >= 0 && |
| 1187 | cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) |
| 1188 | break; |
Mike Marciniszyn | 6c2ab0b | 2016-02-04 11:03:19 -0800 | [diff] [blame] | 1189 | s_last = qp->s_last; |
| 1190 | if (++s_last >= qp->s_size) |
| 1191 | s_last = 0; |
| 1192 | qp->s_last = s_last; |
| 1193 | /* see post_send() */ |
| 1194 | barrier(); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1195 | for (i = 0; i < wqe->wr.num_sge; i++) { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1196 | struct rvt_sge *sge = &wqe->sg_list[i]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1197 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1198 | rvt_put_mr(sge->mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1199 | } |
| 1200 | /* Post a send completion queue entry if requested. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1201 | if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) || |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1202 | (wqe->wr.send_flags & IB_SEND_SIGNALED)) { |
| 1203 | memset(&wc, 0, sizeof(wc)); |
| 1204 | wc.wr_id = wqe->wr.wr_id; |
| 1205 | wc.status = IB_WC_SUCCESS; |
| 1206 | wc.opcode = ib_hfi1_wc_opcode[wqe->wr.opcode]; |
| 1207 | wc.byte_len = wqe->length; |
| 1208 | wc.qp = &qp->ibqp; |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 1209 | rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1210 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1211 | } |
| 1212 | /* |
| 1213 | * If we were waiting for sends to complete before re-sending, |
| 1214 | * and they are now complete, restart sending. |
| 1215 | */ |
Sebastian Sanchez | 462b6b2 | 2016-07-01 16:01:06 -0700 | [diff] [blame] | 1216 | trace_hfi1_sendcomplete(qp, psn); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1217 | if (qp->s_flags & RVT_S_WAIT_PSN && |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1218 | cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) > 0) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1219 | qp->s_flags &= ~RVT_S_WAIT_PSN; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1220 | qp->s_sending_psn = qp->s_psn; |
| 1221 | qp->s_sending_hpsn = qp->s_psn - 1; |
| 1222 | hfi1_schedule_send(qp); |
| 1223 | } |
| 1224 | } |
| 1225 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1226 | static inline void update_last_psn(struct rvt_qp *qp, u32 psn) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1227 | { |
| 1228 | qp->s_last_psn = psn; |
| 1229 | } |
| 1230 | |
| 1231 | /* |
| 1232 | * Generate a SWQE completion. |
| 1233 | * This is similar to hfi1_send_complete but has to check to be sure |
| 1234 | * that the SGEs are not being referenced if the SWQE is being resent. |
| 1235 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1236 | static struct rvt_swqe *do_rc_completion(struct rvt_qp *qp, |
| 1237 | struct rvt_swqe *wqe, |
| 1238 | struct hfi1_ibport *ibp) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1239 | { |
| 1240 | struct ib_wc wc; |
| 1241 | unsigned i; |
| 1242 | |
| 1243 | /* |
| 1244 | * Don't decrement refcount and don't generate a |
| 1245 | * completion if the SWQE is being resent until the send |
| 1246 | * is finished. |
| 1247 | */ |
| 1248 | if (cmp_psn(wqe->lpsn, qp->s_sending_psn) < 0 || |
| 1249 | cmp_psn(qp->s_sending_psn, qp->s_sending_hpsn) > 0) { |
Mike Marciniszyn | 6c2ab0b | 2016-02-04 11:03:19 -0800 | [diff] [blame] | 1250 | u32 s_last; |
| 1251 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1252 | for (i = 0; i < wqe->wr.num_sge; i++) { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1253 | struct rvt_sge *sge = &wqe->sg_list[i]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1254 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1255 | rvt_put_mr(sge->mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1256 | } |
Mike Marciniszyn | 6c2ab0b | 2016-02-04 11:03:19 -0800 | [diff] [blame] | 1257 | s_last = qp->s_last; |
| 1258 | if (++s_last >= qp->s_size) |
| 1259 | s_last = 0; |
| 1260 | qp->s_last = s_last; |
| 1261 | /* see post_send() */ |
| 1262 | barrier(); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1263 | /* Post a send completion queue entry if requested. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1264 | if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) || |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1265 | (wqe->wr.send_flags & IB_SEND_SIGNALED)) { |
| 1266 | memset(&wc, 0, sizeof(wc)); |
| 1267 | wc.wr_id = wqe->wr.wr_id; |
| 1268 | wc.status = IB_WC_SUCCESS; |
| 1269 | wc.opcode = ib_hfi1_wc_opcode[wqe->wr.opcode]; |
| 1270 | wc.byte_len = wqe->length; |
| 1271 | wc.qp = &qp->ibqp; |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 1272 | rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1273 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1274 | } else { |
| 1275 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
| 1276 | |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1277 | this_cpu_inc(*ibp->rvp.rc_delayed_comp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1278 | /* |
| 1279 | * If send progress not running attempt to progress |
| 1280 | * SDMA queue. |
| 1281 | */ |
| 1282 | if (ppd->dd->flags & HFI1_HAS_SEND_DMA) { |
| 1283 | struct sdma_engine *engine; |
| 1284 | u8 sc5; |
| 1285 | |
| 1286 | /* For now use sc to find engine */ |
| 1287 | sc5 = ibp->sl_to_sc[qp->remote_ah_attr.sl]; |
| 1288 | engine = qp_to_sdma_engine(qp, sc5); |
| 1289 | sdma_engine_progress_schedule(engine); |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | qp->s_retry = qp->s_retry_cnt; |
| 1294 | update_last_psn(qp, wqe->lpsn); |
| 1295 | |
| 1296 | /* |
| 1297 | * If we are completing a request which is in the process of |
| 1298 | * being resent, we can stop re-sending it since we know the |
| 1299 | * responder has already seen it. |
| 1300 | */ |
| 1301 | if (qp->s_acked == qp->s_cur) { |
| 1302 | if (++qp->s_cur >= qp->s_size) |
| 1303 | qp->s_cur = 0; |
| 1304 | qp->s_acked = qp->s_cur; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1305 | wqe = rvt_get_swqe_ptr(qp, qp->s_cur); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1306 | if (qp->s_acked != qp->s_tail) { |
| 1307 | qp->s_state = OP(SEND_LAST); |
| 1308 | qp->s_psn = wqe->psn; |
| 1309 | } |
| 1310 | } else { |
| 1311 | if (++qp->s_acked >= qp->s_size) |
| 1312 | qp->s_acked = 0; |
| 1313 | if (qp->state == IB_QPS_SQD && qp->s_acked == qp->s_cur) |
| 1314 | qp->s_draining = 0; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1315 | wqe = rvt_get_swqe_ptr(qp, qp->s_acked); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1316 | } |
| 1317 | return wqe; |
| 1318 | } |
| 1319 | |
| 1320 | /** |
| 1321 | * do_rc_ack - process an incoming RC ACK |
| 1322 | * @qp: the QP the ACK came in on |
| 1323 | * @psn: the packet sequence number of the ACK |
| 1324 | * @opcode: the opcode of the request that resulted in the ACK |
| 1325 | * |
| 1326 | * This is called from rc_rcv_resp() to process an incoming RC ACK |
| 1327 | * for the given QP. |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 1328 | * May be called at interrupt level, with the QP s_lock held. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1329 | * Returns 1 if OK, 0 if current operation should be aborted (NAK). |
| 1330 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1331 | static int do_rc_ack(struct rvt_qp *qp, u32 aeth, u32 psn, int opcode, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1332 | u64 val, struct hfi1_ctxtdata *rcd) |
| 1333 | { |
| 1334 | struct hfi1_ibport *ibp; |
| 1335 | enum ib_wc_status status; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1336 | struct rvt_swqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1337 | int ret = 0; |
| 1338 | u32 ack_psn; |
| 1339 | int diff; |
Mike Marciniszyn | e6f8c2b | 2016-02-04 10:59:09 -0800 | [diff] [blame] | 1340 | unsigned long to; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1341 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1342 | /* |
| 1343 | * Note that NAKs implicitly ACK outstanding SEND and RDMA write |
| 1344 | * requests and implicitly NAK RDMA read and atomic requests issued |
| 1345 | * before the NAK'ed request. The MSN won't include the NAK'ed |
| 1346 | * request but will include an ACK'ed request(s). |
| 1347 | */ |
| 1348 | ack_psn = psn; |
| 1349 | if (aeth >> 29) |
| 1350 | ack_psn--; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1351 | wqe = rvt_get_swqe_ptr(qp, qp->s_acked); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1352 | ibp = to_iport(qp->ibqp.device, qp->port_num); |
| 1353 | |
| 1354 | /* |
| 1355 | * The MSN might be for a later WQE than the PSN indicates so |
| 1356 | * only complete WQEs that the PSN finishes. |
| 1357 | */ |
| 1358 | while ((diff = delta_psn(ack_psn, wqe->lpsn)) >= 0) { |
| 1359 | /* |
| 1360 | * RDMA_READ_RESPONSE_ONLY is a special case since |
| 1361 | * we want to generate completion events for everything |
| 1362 | * before the RDMA read, copy the data, then generate |
| 1363 | * the completion for the read. |
| 1364 | */ |
| 1365 | if (wqe->wr.opcode == IB_WR_RDMA_READ && |
| 1366 | opcode == OP(RDMA_READ_RESPONSE_ONLY) && |
| 1367 | diff == 0) { |
| 1368 | ret = 1; |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1369 | goto bail_stop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1370 | } |
| 1371 | /* |
| 1372 | * If this request is a RDMA read or atomic, and the ACK is |
| 1373 | * for a later operation, this ACK NAKs the RDMA read or |
| 1374 | * atomic. In other words, only a RDMA_READ_LAST or ONLY |
| 1375 | * can ACK a RDMA read and likewise for atomic ops. Note |
| 1376 | * that the NAK case can only happen if relaxed ordering is |
| 1377 | * used and requests are sent after an RDMA read or atomic |
| 1378 | * is sent but before the response is received. |
| 1379 | */ |
| 1380 | if ((wqe->wr.opcode == IB_WR_RDMA_READ && |
| 1381 | (opcode != OP(RDMA_READ_RESPONSE_LAST) || diff != 0)) || |
| 1382 | ((wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP || |
| 1383 | wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) && |
| 1384 | (opcode != OP(ATOMIC_ACKNOWLEDGE) || diff != 0))) { |
| 1385 | /* Retry this request. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1386 | if (!(qp->r_flags & RVT_R_RDMAR_SEQ)) { |
| 1387 | qp->r_flags |= RVT_R_RDMAR_SEQ; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1388 | restart_rc(qp, qp->s_last_psn + 1, 0); |
| 1389 | if (list_empty(&qp->rspwait)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1390 | qp->r_flags |= RVT_R_RSP_SEND; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1391 | atomic_inc(&qp->refcount); |
| 1392 | list_add_tail(&qp->rspwait, |
| 1393 | &rcd->qp_wait_list); |
| 1394 | } |
| 1395 | } |
| 1396 | /* |
| 1397 | * No need to process the ACK/NAK since we are |
| 1398 | * restarting an earlier request. |
| 1399 | */ |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1400 | goto bail_stop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1401 | } |
| 1402 | if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP || |
| 1403 | wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) { |
| 1404 | u64 *vaddr = wqe->sg_list[0].vaddr; |
| 1405 | *vaddr = val; |
| 1406 | } |
| 1407 | if (qp->s_num_rd_atomic && |
| 1408 | (wqe->wr.opcode == IB_WR_RDMA_READ || |
| 1409 | wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP || |
| 1410 | wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)) { |
| 1411 | qp->s_num_rd_atomic--; |
| 1412 | /* Restart sending task if fence is complete */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1413 | if ((qp->s_flags & RVT_S_WAIT_FENCE) && |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1414 | !qp->s_num_rd_atomic) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1415 | qp->s_flags &= ~(RVT_S_WAIT_FENCE | |
| 1416 | RVT_S_WAIT_ACK); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1417 | hfi1_schedule_send(qp); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1418 | } else if (qp->s_flags & RVT_S_WAIT_RDMAR) { |
| 1419 | qp->s_flags &= ~(RVT_S_WAIT_RDMAR | |
| 1420 | RVT_S_WAIT_ACK); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1421 | hfi1_schedule_send(qp); |
| 1422 | } |
| 1423 | } |
| 1424 | wqe = do_rc_completion(qp, wqe, ibp); |
| 1425 | if (qp->s_acked == qp->s_tail) |
| 1426 | break; |
| 1427 | } |
| 1428 | |
| 1429 | switch (aeth >> 29) { |
| 1430 | case 0: /* ACK */ |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1431 | this_cpu_inc(*ibp->rvp.rc_acks); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1432 | if (qp->s_acked != qp->s_tail) { |
| 1433 | /* |
| 1434 | * We are expecting more ACKs so |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1435 | * mod the retry timer. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1436 | */ |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1437 | hfi1_mod_retry_timer(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1438 | /* |
| 1439 | * We can stop re-sending the earlier packets and |
| 1440 | * continue with the next packet the receiver wants. |
| 1441 | */ |
| 1442 | if (cmp_psn(qp->s_psn, psn) <= 0) |
| 1443 | reset_psn(qp, psn + 1); |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1444 | } else { |
| 1445 | /* No more acks - kill all timers */ |
| 1446 | hfi1_stop_rc_timers(qp); |
| 1447 | if (cmp_psn(qp->s_psn, psn) <= 0) { |
| 1448 | qp->s_state = OP(SEND_LAST); |
| 1449 | qp->s_psn = psn + 1; |
| 1450 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1451 | } |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1452 | if (qp->s_flags & RVT_S_WAIT_ACK) { |
| 1453 | qp->s_flags &= ~RVT_S_WAIT_ACK; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1454 | hfi1_schedule_send(qp); |
| 1455 | } |
| 1456 | hfi1_get_credit(qp, aeth); |
| 1457 | qp->s_rnr_retry = qp->s_rnr_retry_cnt; |
| 1458 | qp->s_retry = qp->s_retry_cnt; |
| 1459 | update_last_psn(qp, psn); |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1460 | return 1; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1461 | |
| 1462 | case 1: /* RNR NAK */ |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1463 | ibp->rvp.n_rnr_naks++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1464 | if (qp->s_acked == qp->s_tail) |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1465 | goto bail_stop; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1466 | if (qp->s_flags & RVT_S_WAIT_RNR) |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1467 | goto bail_stop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1468 | if (qp->s_rnr_retry == 0) { |
| 1469 | status = IB_WC_RNR_RETRY_EXC_ERR; |
| 1470 | goto class_b; |
| 1471 | } |
| 1472 | if (qp->s_rnr_retry_cnt < 7) |
| 1473 | qp->s_rnr_retry--; |
| 1474 | |
| 1475 | /* The last valid PSN is the previous PSN. */ |
| 1476 | update_last_psn(qp, psn - 1); |
| 1477 | |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1478 | ibp->rvp.n_rc_resends += delta_psn(qp->s_psn, psn); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1479 | |
| 1480 | reset_psn(qp, psn); |
| 1481 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1482 | qp->s_flags &= ~(RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_ACK); |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1483 | hfi1_stop_rc_timers(qp); |
Mike Marciniszyn | e6f8c2b | 2016-02-04 10:59:09 -0800 | [diff] [blame] | 1484 | to = |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1485 | ib_hfi1_rnr_table[(aeth >> HFI1_AETH_CREDIT_SHIFT) & |
Mike Marciniszyn | e6f8c2b | 2016-02-04 10:59:09 -0800 | [diff] [blame] | 1486 | HFI1_AETH_CREDIT_MASK]; |
| 1487 | hfi1_add_rnr_timer(qp, to); |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1488 | return 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1489 | |
| 1490 | case 3: /* NAK */ |
| 1491 | if (qp->s_acked == qp->s_tail) |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1492 | goto bail_stop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1493 | /* The last valid PSN is the previous PSN. */ |
| 1494 | update_last_psn(qp, psn - 1); |
| 1495 | switch ((aeth >> HFI1_AETH_CREDIT_SHIFT) & |
| 1496 | HFI1_AETH_CREDIT_MASK) { |
| 1497 | case 0: /* PSN sequence error */ |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1498 | ibp->rvp.n_seq_naks++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1499 | /* |
| 1500 | * Back up to the responder's expected PSN. |
| 1501 | * Note that we might get a NAK in the middle of an |
| 1502 | * RDMA READ response which terminates the RDMA |
| 1503 | * READ. |
| 1504 | */ |
| 1505 | restart_rc(qp, psn, 0); |
| 1506 | hfi1_schedule_send(qp); |
| 1507 | break; |
| 1508 | |
| 1509 | case 1: /* Invalid Request */ |
| 1510 | status = IB_WC_REM_INV_REQ_ERR; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1511 | ibp->rvp.n_other_naks++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1512 | goto class_b; |
| 1513 | |
| 1514 | case 2: /* Remote Access Error */ |
| 1515 | status = IB_WC_REM_ACCESS_ERR; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1516 | ibp->rvp.n_other_naks++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1517 | goto class_b; |
| 1518 | |
| 1519 | case 3: /* Remote Operation Error */ |
| 1520 | status = IB_WC_REM_OP_ERR; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1521 | ibp->rvp.n_other_naks++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1522 | class_b: |
| 1523 | if (qp->s_last == qp->s_acked) { |
| 1524 | hfi1_send_complete(qp, wqe, status); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 1525 | rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1526 | } |
| 1527 | break; |
| 1528 | |
| 1529 | default: |
| 1530 | /* Ignore other reserved NAK error codes */ |
| 1531 | goto reserved; |
| 1532 | } |
| 1533 | qp->s_retry = qp->s_retry_cnt; |
| 1534 | qp->s_rnr_retry = qp->s_rnr_retry_cnt; |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1535 | goto bail_stop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1536 | |
| 1537 | default: /* 2: reserved */ |
| 1538 | reserved: |
| 1539 | /* Ignore reserved NAK codes. */ |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1540 | goto bail_stop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1541 | } |
Mike Marciniszyn | 87717f0 | 2016-04-12 11:28:56 -0700 | [diff] [blame] | 1542 | /* cannot be reached */ |
Mike Marciniszyn | 633d273 | 2016-02-04 10:59:18 -0800 | [diff] [blame] | 1543 | bail_stop: |
| 1544 | hfi1_stop_rc_timers(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1545 | return ret; |
| 1546 | } |
| 1547 | |
| 1548 | /* |
| 1549 | * We have seen an out of sequence RDMA read middle or last packet. |
| 1550 | * This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE. |
| 1551 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1552 | static void rdma_seq_err(struct rvt_qp *qp, struct hfi1_ibport *ibp, u32 psn, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1553 | struct hfi1_ctxtdata *rcd) |
| 1554 | { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1555 | struct rvt_swqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1556 | |
| 1557 | /* Remove QP from retry timer */ |
Mike Marciniszyn | e6f8c2b | 2016-02-04 10:59:09 -0800 | [diff] [blame] | 1558 | hfi1_stop_rc_timers(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1559 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1560 | wqe = rvt_get_swqe_ptr(qp, qp->s_acked); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1561 | |
| 1562 | while (cmp_psn(psn, wqe->lpsn) > 0) { |
| 1563 | if (wqe->wr.opcode == IB_WR_RDMA_READ || |
| 1564 | wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP || |
| 1565 | wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) |
| 1566 | break; |
| 1567 | wqe = do_rc_completion(qp, wqe, ibp); |
| 1568 | } |
| 1569 | |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1570 | ibp->rvp.n_rdma_seq++; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1571 | qp->r_flags |= RVT_R_RDMAR_SEQ; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1572 | restart_rc(qp, qp->s_last_psn + 1, 0); |
| 1573 | if (list_empty(&qp->rspwait)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1574 | qp->r_flags |= RVT_R_RSP_SEND; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1575 | atomic_inc(&qp->refcount); |
| 1576 | list_add_tail(&qp->rspwait, &rcd->qp_wait_list); |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | /** |
| 1581 | * rc_rcv_resp - process an incoming RC response packet |
| 1582 | * @ibp: the port this packet came in on |
| 1583 | * @ohdr: the other headers for this packet |
| 1584 | * @data: the packet data |
| 1585 | * @tlen: the packet length |
| 1586 | * @qp: the QP for this packet |
| 1587 | * @opcode: the opcode for this packet |
| 1588 | * @psn: the packet sequence number for this packet |
| 1589 | * @hdrsize: the header length |
| 1590 | * @pmtu: the path MTU |
| 1591 | * |
| 1592 | * This is called from hfi1_rc_rcv() to process an incoming RC response |
| 1593 | * packet for the given QP. |
| 1594 | * Called at interrupt level. |
| 1595 | */ |
| 1596 | static void rc_rcv_resp(struct hfi1_ibport *ibp, |
| 1597 | struct hfi1_other_headers *ohdr, |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1598 | void *data, u32 tlen, struct rvt_qp *qp, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1599 | u32 opcode, u32 psn, u32 hdrsize, u32 pmtu, |
| 1600 | struct hfi1_ctxtdata *rcd) |
| 1601 | { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1602 | struct rvt_swqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1603 | enum ib_wc_status status; |
| 1604 | unsigned long flags; |
| 1605 | int diff; |
| 1606 | u32 pad; |
| 1607 | u32 aeth; |
| 1608 | u64 val; |
| 1609 | |
| 1610 | spin_lock_irqsave(&qp->s_lock, flags); |
| 1611 | |
Sebastian Sanchez | 462b6b2 | 2016-07-01 16:01:06 -0700 | [diff] [blame] | 1612 | trace_hfi1_ack(qp, psn); |
Mike Marciniszyn | 83525b6 | 2015-10-26 10:28:48 -0400 | [diff] [blame] | 1613 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1614 | /* Ignore invalid responses. */ |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 1615 | smp_read_barrier_depends(); /* see post_one_send */ |
| 1616 | if (cmp_psn(psn, ACCESS_ONCE(qp->s_next_psn)) >= 0) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1617 | goto ack_done; |
| 1618 | |
| 1619 | /* Ignore duplicate responses. */ |
| 1620 | diff = cmp_psn(psn, qp->s_last_psn); |
| 1621 | if (unlikely(diff <= 0)) { |
| 1622 | /* Update credits for "ghost" ACKs */ |
| 1623 | if (diff == 0 && opcode == OP(ACKNOWLEDGE)) { |
| 1624 | aeth = be32_to_cpu(ohdr->u.aeth); |
| 1625 | if ((aeth >> 29) == 0) |
| 1626 | hfi1_get_credit(qp, aeth); |
| 1627 | } |
| 1628 | goto ack_done; |
| 1629 | } |
| 1630 | |
| 1631 | /* |
| 1632 | * Skip everything other than the PSN we expect, if we are waiting |
| 1633 | * for a reply to a restarted RDMA read or atomic op. |
| 1634 | */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1635 | if (qp->r_flags & RVT_R_RDMAR_SEQ) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1636 | if (cmp_psn(psn, qp->s_last_psn + 1) != 0) |
| 1637 | goto ack_done; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1638 | qp->r_flags &= ~RVT_R_RDMAR_SEQ; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | if (unlikely(qp->s_acked == qp->s_tail)) |
| 1642 | goto ack_done; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1643 | wqe = rvt_get_swqe_ptr(qp, qp->s_acked); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1644 | status = IB_WC_SUCCESS; |
| 1645 | |
| 1646 | switch (opcode) { |
| 1647 | case OP(ACKNOWLEDGE): |
| 1648 | case OP(ATOMIC_ACKNOWLEDGE): |
| 1649 | case OP(RDMA_READ_RESPONSE_FIRST): |
| 1650 | aeth = be32_to_cpu(ohdr->u.aeth); |
| 1651 | if (opcode == OP(ATOMIC_ACKNOWLEDGE)) { |
| 1652 | __be32 *p = ohdr->u.at.atomic_ack_eth; |
| 1653 | |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 1654 | val = ((u64)be32_to_cpu(p[0]) << 32) | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1655 | be32_to_cpu(p[1]); |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 1656 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1657 | val = 0; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 1658 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1659 | if (!do_rc_ack(qp, aeth, psn, opcode, val, rcd) || |
| 1660 | opcode != OP(RDMA_READ_RESPONSE_FIRST)) |
| 1661 | goto ack_done; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1662 | wqe = rvt_get_swqe_ptr(qp, qp->s_acked); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1663 | if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ)) |
| 1664 | goto ack_op_err; |
| 1665 | /* |
| 1666 | * If this is a response to a resent RDMA read, we |
| 1667 | * have to be careful to copy the data to the right |
| 1668 | * location. |
| 1669 | */ |
| 1670 | qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge, |
| 1671 | wqe, psn, pmtu); |
| 1672 | goto read_middle; |
| 1673 | |
| 1674 | case OP(RDMA_READ_RESPONSE_MIDDLE): |
| 1675 | /* no AETH, no ACK */ |
| 1676 | if (unlikely(cmp_psn(psn, qp->s_last_psn + 1))) |
| 1677 | goto ack_seq_err; |
| 1678 | if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ)) |
| 1679 | goto ack_op_err; |
| 1680 | read_middle: |
| 1681 | if (unlikely(tlen != (hdrsize + pmtu + 4))) |
| 1682 | goto ack_len_err; |
| 1683 | if (unlikely(pmtu >= qp->s_rdma_read_len)) |
| 1684 | goto ack_len_err; |
| 1685 | |
| 1686 | /* |
| 1687 | * We got a response so update the timeout. |
| 1688 | * 4.096 usec. * (1 << qp->timeout) |
| 1689 | */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1690 | qp->s_flags |= RVT_S_TIMER; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1691 | mod_timer(&qp->s_timer, jiffies + qp->timeout_jiffies); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1692 | if (qp->s_flags & RVT_S_WAIT_ACK) { |
| 1693 | qp->s_flags &= ~RVT_S_WAIT_ACK; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1694 | hfi1_schedule_send(qp); |
| 1695 | } |
| 1696 | |
| 1697 | if (opcode == OP(RDMA_READ_RESPONSE_MIDDLE)) |
| 1698 | qp->s_retry = qp->s_retry_cnt; |
| 1699 | |
| 1700 | /* |
| 1701 | * Update the RDMA receive state but do the copy w/o |
| 1702 | * holding the locks and blocking interrupts. |
| 1703 | */ |
| 1704 | qp->s_rdma_read_len -= pmtu; |
| 1705 | update_last_psn(qp, psn); |
| 1706 | spin_unlock_irqrestore(&qp->s_lock, flags); |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 1707 | hfi1_copy_sge(&qp->s_rdma_read_sge, data, pmtu, 0, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1708 | goto bail; |
| 1709 | |
| 1710 | case OP(RDMA_READ_RESPONSE_ONLY): |
| 1711 | aeth = be32_to_cpu(ohdr->u.aeth); |
| 1712 | if (!do_rc_ack(qp, aeth, psn, opcode, 0, rcd)) |
| 1713 | goto ack_done; |
| 1714 | /* Get the number of bytes the message was padded by. */ |
| 1715 | pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3; |
| 1716 | /* |
| 1717 | * Check that the data size is >= 0 && <= pmtu. |
| 1718 | * Remember to account for ICRC (4). |
| 1719 | */ |
| 1720 | if (unlikely(tlen < (hdrsize + pad + 4))) |
| 1721 | goto ack_len_err; |
| 1722 | /* |
| 1723 | * If this is a response to a resent RDMA read, we |
| 1724 | * have to be careful to copy the data to the right |
| 1725 | * location. |
| 1726 | */ |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 1727 | wqe = rvt_get_swqe_ptr(qp, qp->s_acked); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1728 | qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge, |
| 1729 | wqe, psn, pmtu); |
| 1730 | goto read_last; |
| 1731 | |
| 1732 | case OP(RDMA_READ_RESPONSE_LAST): |
| 1733 | /* ACKs READ req. */ |
| 1734 | if (unlikely(cmp_psn(psn, qp->s_last_psn + 1))) |
| 1735 | goto ack_seq_err; |
| 1736 | if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ)) |
| 1737 | goto ack_op_err; |
| 1738 | /* Get the number of bytes the message was padded by. */ |
| 1739 | pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3; |
| 1740 | /* |
| 1741 | * Check that the data size is >= 1 && <= pmtu. |
| 1742 | * Remember to account for ICRC (4). |
| 1743 | */ |
| 1744 | if (unlikely(tlen <= (hdrsize + pad + 4))) |
| 1745 | goto ack_len_err; |
| 1746 | read_last: |
| 1747 | tlen -= hdrsize + pad + 4; |
| 1748 | if (unlikely(tlen != qp->s_rdma_read_len)) |
| 1749 | goto ack_len_err; |
| 1750 | aeth = be32_to_cpu(ohdr->u.aeth); |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 1751 | hfi1_copy_sge(&qp->s_rdma_read_sge, data, tlen, 0, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1752 | WARN_ON(qp->s_rdma_read_sge.num_sge); |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 1753 | (void)do_rc_ack(qp, aeth, psn, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1754 | OP(RDMA_READ_RESPONSE_LAST), 0, rcd); |
| 1755 | goto ack_done; |
| 1756 | } |
| 1757 | |
| 1758 | ack_op_err: |
| 1759 | status = IB_WC_LOC_QP_OP_ERR; |
| 1760 | goto ack_err; |
| 1761 | |
| 1762 | ack_seq_err: |
| 1763 | rdma_seq_err(qp, ibp, psn, rcd); |
| 1764 | goto ack_done; |
| 1765 | |
| 1766 | ack_len_err: |
| 1767 | status = IB_WC_LOC_LEN_ERR; |
| 1768 | ack_err: |
| 1769 | if (qp->s_last == qp->s_acked) { |
| 1770 | hfi1_send_complete(qp, wqe, status); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 1771 | rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1772 | } |
| 1773 | ack_done: |
| 1774 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 1775 | bail: |
| 1776 | return; |
| 1777 | } |
| 1778 | |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 1779 | static inline void rc_defered_ack(struct hfi1_ctxtdata *rcd, |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1780 | struct rvt_qp *qp) |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 1781 | { |
| 1782 | if (list_empty(&qp->rspwait)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1783 | qp->r_flags |= RVT_R_RSP_NAK; |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 1784 | atomic_inc(&qp->refcount); |
| 1785 | list_add_tail(&qp->rspwait, &rcd->qp_wait_list); |
| 1786 | } |
| 1787 | } |
| 1788 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1789 | static inline void rc_cancel_ack(struct rvt_qp *qp) |
Mike Marciniszyn | 7c091e5 | 2015-11-10 09:14:01 -0500 | [diff] [blame] | 1790 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 1791 | struct hfi1_qp_priv *priv = qp->priv; |
| 1792 | |
| 1793 | priv->r_adefered = 0; |
Mike Marciniszyn | 7c091e5 | 2015-11-10 09:14:01 -0500 | [diff] [blame] | 1794 | if (list_empty(&qp->rspwait)) |
| 1795 | return; |
| 1796 | list_del_init(&qp->rspwait); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1797 | qp->r_flags &= ~RVT_R_RSP_NAK; |
Mike Marciniszyn | 7c091e5 | 2015-11-10 09:14:01 -0500 | [diff] [blame] | 1798 | if (atomic_dec_and_test(&qp->refcount)) |
| 1799 | wake_up(&qp->wait); |
| 1800 | } |
| 1801 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1802 | /** |
| 1803 | * rc_rcv_error - process an incoming duplicate or error RC packet |
| 1804 | * @ohdr: the other headers for this packet |
| 1805 | * @data: the packet data |
| 1806 | * @qp: the QP for this packet |
| 1807 | * @opcode: the opcode for this packet |
| 1808 | * @psn: the packet sequence number for this packet |
| 1809 | * @diff: the difference between the PSN and the expected PSN |
| 1810 | * |
| 1811 | * This is called from hfi1_rc_rcv() to process an unexpected |
| 1812 | * incoming RC packet for the given QP. |
| 1813 | * Called at interrupt level. |
| 1814 | * Return 1 if no more processing is needed; otherwise return 0 to |
| 1815 | * schedule a response to be sent. |
| 1816 | */ |
| 1817 | static noinline int rc_rcv_error(struct hfi1_other_headers *ohdr, void *data, |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 1818 | struct rvt_qp *qp, u32 opcode, u32 psn, |
| 1819 | int diff, struct hfi1_ctxtdata *rcd) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1820 | { |
| 1821 | struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1822 | struct rvt_ack_entry *e; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1823 | unsigned long flags; |
| 1824 | u8 i, prev; |
| 1825 | int old_req; |
| 1826 | |
Sebastian Sanchez | 462b6b2 | 2016-07-01 16:01:06 -0700 | [diff] [blame] | 1827 | trace_hfi1_rcv_error(qp, psn); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1828 | if (diff > 0) { |
| 1829 | /* |
| 1830 | * Packet sequence error. |
| 1831 | * A NAK will ACK earlier sends and RDMA writes. |
| 1832 | * Don't queue the NAK if we already sent one. |
| 1833 | */ |
| 1834 | if (!qp->r_nak_state) { |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1835 | ibp->rvp.n_rc_seqnak++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1836 | qp->r_nak_state = IB_NAK_PSN_ERROR; |
| 1837 | /* Use the expected PSN. */ |
| 1838 | qp->r_ack_psn = qp->r_psn; |
| 1839 | /* |
| 1840 | * Wait to send the sequence NAK until all packets |
| 1841 | * in the receive queue have been processed. |
| 1842 | * Otherwise, we end up propagating congestion. |
| 1843 | */ |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 1844 | rc_defered_ack(rcd, qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1845 | } |
| 1846 | goto done; |
| 1847 | } |
| 1848 | |
| 1849 | /* |
| 1850 | * Handle a duplicate request. Don't re-execute SEND, RDMA |
| 1851 | * write or atomic op. Don't NAK errors, just silently drop |
| 1852 | * the duplicate request. Note that r_sge, r_len, and |
| 1853 | * r_rcv_len may be in use so don't modify them. |
| 1854 | * |
| 1855 | * We are supposed to ACK the earliest duplicate PSN but we |
| 1856 | * can coalesce an outstanding duplicate ACK. We have to |
| 1857 | * send the earliest so that RDMA reads can be restarted at |
| 1858 | * the requester's expected PSN. |
| 1859 | * |
| 1860 | * First, find where this duplicate PSN falls within the |
| 1861 | * ACKs previously sent. |
| 1862 | * old_req is true if there is an older response that is scheduled |
| 1863 | * to be sent before sending this one. |
| 1864 | */ |
| 1865 | e = NULL; |
| 1866 | old_req = 1; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 1867 | ibp->rvp.n_rc_dupreq++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1868 | |
| 1869 | spin_lock_irqsave(&qp->s_lock, flags); |
| 1870 | |
| 1871 | for (i = qp->r_head_ack_queue; ; i = prev) { |
| 1872 | if (i == qp->s_tail_ack_queue) |
| 1873 | old_req = 0; |
| 1874 | if (i) |
| 1875 | prev = i - 1; |
| 1876 | else |
| 1877 | prev = HFI1_MAX_RDMA_ATOMIC; |
| 1878 | if (prev == qp->r_head_ack_queue) { |
| 1879 | e = NULL; |
| 1880 | break; |
| 1881 | } |
| 1882 | e = &qp->s_ack_queue[prev]; |
| 1883 | if (!e->opcode) { |
| 1884 | e = NULL; |
| 1885 | break; |
| 1886 | } |
| 1887 | if (cmp_psn(psn, e->psn) >= 0) { |
| 1888 | if (prev == qp->s_tail_ack_queue && |
| 1889 | cmp_psn(psn, e->lpsn) <= 0) |
| 1890 | old_req = 0; |
| 1891 | break; |
| 1892 | } |
| 1893 | } |
| 1894 | switch (opcode) { |
| 1895 | case OP(RDMA_READ_REQUEST): { |
| 1896 | struct ib_reth *reth; |
| 1897 | u32 offset; |
| 1898 | u32 len; |
| 1899 | |
| 1900 | /* |
| 1901 | * If we didn't find the RDMA read request in the ack queue, |
| 1902 | * we can ignore this request. |
| 1903 | */ |
| 1904 | if (!e || e->opcode != OP(RDMA_READ_REQUEST)) |
| 1905 | goto unlock_done; |
| 1906 | /* RETH comes after BTH */ |
| 1907 | reth = &ohdr->u.rc.reth; |
| 1908 | /* |
| 1909 | * Address range must be a subset of the original |
| 1910 | * request and start on pmtu boundaries. |
| 1911 | * We reuse the old ack_queue slot since the requester |
| 1912 | * should not back up and request an earlier PSN for the |
| 1913 | * same request. |
| 1914 | */ |
| 1915 | offset = delta_psn(psn, e->psn) * qp->pmtu; |
| 1916 | len = be32_to_cpu(reth->length); |
| 1917 | if (unlikely(offset + len != e->rdma_sge.sge_length)) |
| 1918 | goto unlock_done; |
| 1919 | if (e->rdma_sge.mr) { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1920 | rvt_put_mr(e->rdma_sge.mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1921 | e->rdma_sge.mr = NULL; |
| 1922 | } |
| 1923 | if (len != 0) { |
| 1924 | u32 rkey = be32_to_cpu(reth->rkey); |
| 1925 | u64 vaddr = be64_to_cpu(reth->vaddr); |
| 1926 | int ok; |
| 1927 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1928 | ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr, rkey, |
| 1929 | IB_ACCESS_REMOTE_READ); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1930 | if (unlikely(!ok)) |
| 1931 | goto unlock_done; |
| 1932 | } else { |
| 1933 | e->rdma_sge.vaddr = NULL; |
| 1934 | e->rdma_sge.length = 0; |
| 1935 | e->rdma_sge.sge_length = 0; |
| 1936 | } |
| 1937 | e->psn = psn; |
| 1938 | if (old_req) |
| 1939 | goto unlock_done; |
| 1940 | qp->s_tail_ack_queue = prev; |
| 1941 | break; |
| 1942 | } |
| 1943 | |
| 1944 | case OP(COMPARE_SWAP): |
| 1945 | case OP(FETCH_ADD): { |
| 1946 | /* |
| 1947 | * If we didn't find the atomic request in the ack queue |
| 1948 | * or the send tasklet is already backed up to send an |
| 1949 | * earlier entry, we can ignore this request. |
| 1950 | */ |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 1951 | if (!e || e->opcode != (u8)opcode || old_req) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1952 | goto unlock_done; |
| 1953 | qp->s_tail_ack_queue = prev; |
| 1954 | break; |
| 1955 | } |
| 1956 | |
| 1957 | default: |
| 1958 | /* |
| 1959 | * Ignore this operation if it doesn't request an ACK |
| 1960 | * or an earlier RDMA read or atomic is going to be resent. |
| 1961 | */ |
| 1962 | if (!(psn & IB_BTH_REQ_ACK) || old_req) |
| 1963 | goto unlock_done; |
| 1964 | /* |
| 1965 | * Resend the most recent ACK if this request is |
| 1966 | * after all the previous RDMA reads and atomics. |
| 1967 | */ |
| 1968 | if (i == qp->r_head_ack_queue) { |
| 1969 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 1970 | qp->r_nak_state = 0; |
| 1971 | qp->r_ack_psn = qp->r_psn - 1; |
| 1972 | goto send_ack; |
| 1973 | } |
| 1974 | |
| 1975 | /* |
| 1976 | * Resend the RDMA read or atomic op which |
| 1977 | * ACKs this duplicate request. |
| 1978 | */ |
| 1979 | qp->s_tail_ack_queue = i; |
| 1980 | break; |
| 1981 | } |
| 1982 | qp->s_ack_state = OP(ACKNOWLEDGE); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 1983 | qp->s_flags |= RVT_S_RESP_PENDING; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1984 | qp->r_nak_state = 0; |
| 1985 | hfi1_schedule_send(qp); |
| 1986 | |
| 1987 | unlock_done: |
| 1988 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 1989 | done: |
| 1990 | return 1; |
| 1991 | |
| 1992 | send_ack: |
| 1993 | return 0; |
| 1994 | } |
| 1995 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 1996 | void hfi1_rc_error(struct rvt_qp *qp, enum ib_wc_status err) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1997 | { |
| 1998 | unsigned long flags; |
| 1999 | int lastwqe; |
| 2000 | |
| 2001 | spin_lock_irqsave(&qp->s_lock, flags); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 2002 | lastwqe = rvt_error_qp(qp, err); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2003 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 2004 | |
| 2005 | if (lastwqe) { |
| 2006 | struct ib_event ev; |
| 2007 | |
| 2008 | ev.device = qp->ibqp.device; |
| 2009 | ev.element.qp = &qp->ibqp; |
| 2010 | ev.event = IB_EVENT_QP_LAST_WQE_REACHED; |
| 2011 | qp->ibqp.event_handler(&ev, qp->ibqp.qp_context); |
| 2012 | } |
| 2013 | } |
| 2014 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2015 | static inline void update_ack_queue(struct rvt_qp *qp, unsigned n) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2016 | { |
| 2017 | unsigned next; |
| 2018 | |
| 2019 | next = n + 1; |
| 2020 | if (next > HFI1_MAX_RDMA_ATOMIC) |
| 2021 | next = 0; |
| 2022 | qp->s_tail_ack_queue = next; |
| 2023 | qp->s_ack_state = OP(ACKNOWLEDGE); |
| 2024 | } |
| 2025 | |
| 2026 | static void log_cca_event(struct hfi1_pportdata *ppd, u8 sl, u32 rlid, |
| 2027 | u32 lqpn, u32 rqpn, u8 svc_type) |
| 2028 | { |
| 2029 | struct opa_hfi1_cong_log_event_internal *cc_event; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 2030 | unsigned long flags; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2031 | |
| 2032 | if (sl >= OPA_MAX_SLS) |
| 2033 | return; |
| 2034 | |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 2035 | spin_lock_irqsave(&ppd->cc_log_lock, flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2036 | |
Jubin John | 8638b77 | 2016-02-14 20:19:24 -0800 | [diff] [blame] | 2037 | ppd->threshold_cong_event_map[sl / 8] |= 1 << (sl % 8); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2038 | ppd->threshold_event_counter++; |
| 2039 | |
| 2040 | cc_event = &ppd->cc_events[ppd->cc_log_idx++]; |
| 2041 | if (ppd->cc_log_idx == OPA_CONG_LOG_ELEMS) |
| 2042 | ppd->cc_log_idx = 0; |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 2043 | cc_event->lqpn = lqpn & RVT_QPN_MASK; |
| 2044 | cc_event->rqpn = rqpn & RVT_QPN_MASK; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2045 | cc_event->sl = sl; |
| 2046 | cc_event->svc_type = svc_type; |
| 2047 | cc_event->rlid = rlid; |
| 2048 | /* keep timestamp in units of 1.024 usec */ |
| 2049 | cc_event->timestamp = ktime_to_ns(ktime_get()) / 1024; |
| 2050 | |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 2051 | spin_unlock_irqrestore(&ppd->cc_log_lock, flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | void process_becn(struct hfi1_pportdata *ppd, u8 sl, u16 rlid, u32 lqpn, |
| 2055 | u32 rqpn, u8 svc_type) |
| 2056 | { |
| 2057 | struct cca_timer *cca_timer; |
| 2058 | u16 ccti, ccti_incr, ccti_timer, ccti_limit; |
| 2059 | u8 trigger_threshold; |
| 2060 | struct cc_state *cc_state; |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 2061 | unsigned long flags; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2062 | |
| 2063 | if (sl >= OPA_MAX_SLS) |
| 2064 | return; |
| 2065 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2066 | cc_state = get_cc_state(ppd); |
| 2067 | |
Jubin John | d125a6c | 2016-02-14 20:19:49 -0800 | [diff] [blame] | 2068 | if (!cc_state) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2069 | return; |
| 2070 | |
| 2071 | /* |
| 2072 | * 1) increase CCTI (for this SL) |
| 2073 | * 2) select IPG (i.e., call set_link_ipg()) |
| 2074 | * 3) start timer |
| 2075 | */ |
| 2076 | ccti_limit = cc_state->cct.ccti_limit; |
| 2077 | ccti_incr = cc_state->cong_setting.entries[sl].ccti_increase; |
| 2078 | ccti_timer = cc_state->cong_setting.entries[sl].ccti_timer; |
| 2079 | trigger_threshold = |
| 2080 | cc_state->cong_setting.entries[sl].trigger_threshold; |
| 2081 | |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 2082 | spin_lock_irqsave(&ppd->cca_timer_lock, flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2083 | |
Jubin John | d35cf74 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 2084 | cca_timer = &ppd->cca_timer[sl]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2085 | if (cca_timer->ccti < ccti_limit) { |
| 2086 | if (cca_timer->ccti + ccti_incr <= ccti_limit) |
| 2087 | cca_timer->ccti += ccti_incr; |
| 2088 | else |
| 2089 | cca_timer->ccti = ccti_limit; |
| 2090 | set_link_ipg(ppd); |
| 2091 | } |
| 2092 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2093 | ccti = cca_timer->ccti; |
| 2094 | |
| 2095 | if (!hrtimer_active(&cca_timer->hrtimer)) { |
| 2096 | /* ccti_timer is in units of 1.024 usec */ |
| 2097 | unsigned long nsec = 1024 * ccti_timer; |
| 2098 | |
| 2099 | hrtimer_start(&cca_timer->hrtimer, ns_to_ktime(nsec), |
| 2100 | HRTIMER_MODE_REL); |
| 2101 | } |
| 2102 | |
Jubin John | d35cf74 | 2016-04-14 08:31:53 -0700 | [diff] [blame] | 2103 | spin_unlock_irqrestore(&ppd->cca_timer_lock, flags); |
| 2104 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2105 | if ((trigger_threshold != 0) && (ccti >= trigger_threshold)) |
| 2106 | log_cca_event(ppd, sl, rlid, lqpn, rqpn, svc_type); |
| 2107 | } |
| 2108 | |
| 2109 | /** |
| 2110 | * hfi1_rc_rcv - process an incoming RC packet |
| 2111 | * @rcd: the context pointer |
| 2112 | * @hdr: the header of this packet |
| 2113 | * @rcv_flags: flags relevant to rcv processing |
| 2114 | * @data: the packet data |
| 2115 | * @tlen: the packet length |
| 2116 | * @qp: the QP for this packet |
| 2117 | * |
| 2118 | * This is called from qp_rcv() to process an incoming RC packet |
| 2119 | * for the given QP. |
Dean Luick | b77d713 | 2015-10-26 10:28:43 -0400 | [diff] [blame] | 2120 | * May be called at interrupt level. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2121 | */ |
| 2122 | void hfi1_rc_rcv(struct hfi1_packet *packet) |
| 2123 | { |
| 2124 | struct hfi1_ctxtdata *rcd = packet->rcd; |
| 2125 | struct hfi1_ib_header *hdr = packet->hdr; |
| 2126 | u32 rcv_flags = packet->rcv_flags; |
| 2127 | void *data = packet->ebuf; |
| 2128 | u32 tlen = packet->tlen; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2129 | struct rvt_qp *qp = packet->qp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2130 | struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2131 | struct hfi1_other_headers *ohdr = packet->ohdr; |
| 2132 | u32 bth0, opcode; |
| 2133 | u32 hdrsize = packet->hlen; |
| 2134 | u32 psn; |
| 2135 | u32 pad; |
| 2136 | struct ib_wc wc; |
| 2137 | u32 pmtu = qp->pmtu; |
| 2138 | int diff; |
| 2139 | struct ib_reth *reth; |
| 2140 | unsigned long flags; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2141 | int ret, is_fecn = 0; |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 2142 | int copy_last = 0; |
Jianxin Xiong | a2df0c8 | 2016-07-25 13:38:31 -0700 | [diff] [blame] | 2143 | u32 rkey; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2144 | |
| 2145 | bth0 = be32_to_cpu(ohdr->bth[0]); |
| 2146 | if (hfi1_ruc_check_hdr(ibp, hdr, rcv_flags & HFI1_HAS_GRH, qp, bth0)) |
| 2147 | return; |
| 2148 | |
Mitko Haralanov | 5fd2b56 | 2016-07-25 13:38:07 -0700 | [diff] [blame] | 2149 | is_fecn = process_ecn(qp, packet, false); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2150 | |
| 2151 | psn = be32_to_cpu(ohdr->bth[2]); |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 2152 | opcode = (bth0 >> 24) & 0xff; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2153 | |
| 2154 | /* |
| 2155 | * Process responses (ACKs) before anything else. Note that the |
| 2156 | * packet sequence number will be for something in the send work |
| 2157 | * queue rather than the expected receive packet sequence number. |
| 2158 | * In other words, this QP is the requester. |
| 2159 | */ |
| 2160 | if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) && |
| 2161 | opcode <= OP(ATOMIC_ACKNOWLEDGE)) { |
| 2162 | rc_rcv_resp(ibp, ohdr, data, tlen, qp, opcode, psn, |
| 2163 | hdrsize, pmtu, rcd); |
| 2164 | if (is_fecn) |
| 2165 | goto send_ack; |
| 2166 | return; |
| 2167 | } |
| 2168 | |
| 2169 | /* Compute 24 bits worth of difference. */ |
| 2170 | diff = delta_psn(psn, qp->r_psn); |
| 2171 | if (unlikely(diff)) { |
| 2172 | if (rc_rcv_error(ohdr, data, qp, opcode, psn, diff, rcd)) |
| 2173 | return; |
| 2174 | goto send_ack; |
| 2175 | } |
| 2176 | |
| 2177 | /* Check for opcode sequence errors. */ |
| 2178 | switch (qp->r_state) { |
| 2179 | case OP(SEND_FIRST): |
| 2180 | case OP(SEND_MIDDLE): |
| 2181 | if (opcode == OP(SEND_MIDDLE) || |
| 2182 | opcode == OP(SEND_LAST) || |
Jianxin Xiong | a2df0c8 | 2016-07-25 13:38:31 -0700 | [diff] [blame] | 2183 | opcode == OP(SEND_LAST_WITH_IMMEDIATE) || |
| 2184 | opcode == OP(SEND_LAST_WITH_INVALIDATE)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2185 | break; |
| 2186 | goto nack_inv; |
| 2187 | |
| 2188 | case OP(RDMA_WRITE_FIRST): |
| 2189 | case OP(RDMA_WRITE_MIDDLE): |
| 2190 | if (opcode == OP(RDMA_WRITE_MIDDLE) || |
| 2191 | opcode == OP(RDMA_WRITE_LAST) || |
| 2192 | opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE)) |
| 2193 | break; |
| 2194 | goto nack_inv; |
| 2195 | |
| 2196 | default: |
| 2197 | if (opcode == OP(SEND_MIDDLE) || |
| 2198 | opcode == OP(SEND_LAST) || |
| 2199 | opcode == OP(SEND_LAST_WITH_IMMEDIATE) || |
Jianxin Xiong | a2df0c8 | 2016-07-25 13:38:31 -0700 | [diff] [blame] | 2200 | opcode == OP(SEND_LAST_WITH_INVALIDATE) || |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2201 | opcode == OP(RDMA_WRITE_MIDDLE) || |
| 2202 | opcode == OP(RDMA_WRITE_LAST) || |
| 2203 | opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE)) |
| 2204 | goto nack_inv; |
| 2205 | /* |
| 2206 | * Note that it is up to the requester to not send a new |
| 2207 | * RDMA read or atomic operation before receiving an ACK |
| 2208 | * for the previous operation. |
| 2209 | */ |
| 2210 | break; |
| 2211 | } |
| 2212 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 2213 | if (qp->state == IB_QPS_RTR && !(qp->r_flags & RVT_R_COMM_EST)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2214 | qp_comm_est(qp); |
| 2215 | |
| 2216 | /* OK, process the packet. */ |
| 2217 | switch (opcode) { |
| 2218 | case OP(SEND_FIRST): |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 2219 | ret = hfi1_rvt_get_rwqe(qp, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2220 | if (ret < 0) |
| 2221 | goto nack_op_err; |
| 2222 | if (!ret) |
| 2223 | goto rnr_nak; |
| 2224 | qp->r_rcv_len = 0; |
| 2225 | /* FALLTHROUGH */ |
| 2226 | case OP(SEND_MIDDLE): |
| 2227 | case OP(RDMA_WRITE_MIDDLE): |
| 2228 | send_middle: |
| 2229 | /* Check for invalid length PMTU or posted rwqe len. */ |
| 2230 | if (unlikely(tlen != (hdrsize + pmtu + 4))) |
| 2231 | goto nack_inv; |
| 2232 | qp->r_rcv_len += pmtu; |
| 2233 | if (unlikely(qp->r_rcv_len > qp->r_len)) |
| 2234 | goto nack_inv; |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 2235 | hfi1_copy_sge(&qp->r_sge, data, pmtu, 1, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2236 | break; |
| 2237 | |
| 2238 | case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE): |
| 2239 | /* consume RWQE */ |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 2240 | ret = hfi1_rvt_get_rwqe(qp, 1); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2241 | if (ret < 0) |
| 2242 | goto nack_op_err; |
| 2243 | if (!ret) |
| 2244 | goto rnr_nak; |
| 2245 | goto send_last_imm; |
| 2246 | |
| 2247 | case OP(SEND_ONLY): |
| 2248 | case OP(SEND_ONLY_WITH_IMMEDIATE): |
Jianxin Xiong | a2df0c8 | 2016-07-25 13:38:31 -0700 | [diff] [blame] | 2249 | case OP(SEND_ONLY_WITH_INVALIDATE): |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 2250 | ret = hfi1_rvt_get_rwqe(qp, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2251 | if (ret < 0) |
| 2252 | goto nack_op_err; |
| 2253 | if (!ret) |
| 2254 | goto rnr_nak; |
| 2255 | qp->r_rcv_len = 0; |
| 2256 | if (opcode == OP(SEND_ONLY)) |
| 2257 | goto no_immediate_data; |
Jianxin Xiong | a2df0c8 | 2016-07-25 13:38:31 -0700 | [diff] [blame] | 2258 | if (opcode == OP(SEND_ONLY_WITH_INVALIDATE)) |
| 2259 | goto send_last_inv; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2260 | /* FALLTHROUGH for SEND_ONLY_WITH_IMMEDIATE */ |
| 2261 | case OP(SEND_LAST_WITH_IMMEDIATE): |
| 2262 | send_last_imm: |
| 2263 | wc.ex.imm_data = ohdr->u.imm_data; |
| 2264 | wc.wc_flags = IB_WC_WITH_IMM; |
| 2265 | goto send_last; |
Jianxin Xiong | a2df0c8 | 2016-07-25 13:38:31 -0700 | [diff] [blame] | 2266 | case OP(SEND_LAST_WITH_INVALIDATE): |
| 2267 | send_last_inv: |
| 2268 | rkey = be32_to_cpu(ohdr->u.ieth); |
| 2269 | if (rvt_invalidate_rkey(qp, rkey)) |
| 2270 | goto no_immediate_data; |
| 2271 | wc.ex.invalidate_rkey = rkey; |
| 2272 | wc.wc_flags = IB_WC_WITH_INVALIDATE; |
| 2273 | goto send_last; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2274 | case OP(RDMA_WRITE_LAST): |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 2275 | copy_last = ibpd_to_rvtpd(qp->ibqp.pd)->user; |
| 2276 | /* fall through */ |
| 2277 | case OP(SEND_LAST): |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2278 | no_immediate_data: |
| 2279 | wc.wc_flags = 0; |
| 2280 | wc.ex.imm_data = 0; |
| 2281 | send_last: |
| 2282 | /* Get the number of bytes the message was padded by. */ |
| 2283 | pad = (bth0 >> 20) & 3; |
| 2284 | /* Check for invalid length. */ |
| 2285 | /* LAST len should be >= 1 */ |
| 2286 | if (unlikely(tlen < (hdrsize + pad + 4))) |
| 2287 | goto nack_inv; |
| 2288 | /* Don't count the CRC. */ |
| 2289 | tlen -= (hdrsize + pad + 4); |
| 2290 | wc.byte_len = tlen + qp->r_rcv_len; |
| 2291 | if (unlikely(wc.byte_len > qp->r_len)) |
| 2292 | goto nack_inv; |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 2293 | hfi1_copy_sge(&qp->r_sge, data, tlen, 1, copy_last); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 2294 | rvt_put_ss(&qp->r_sge); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2295 | qp->r_msn++; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 2296 | if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2297 | break; |
| 2298 | wc.wr_id = qp->r_wr_id; |
| 2299 | wc.status = IB_WC_SUCCESS; |
| 2300 | if (opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE) || |
| 2301 | opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE)) |
| 2302 | wc.opcode = IB_WC_RECV_RDMA_WITH_IMM; |
| 2303 | else |
| 2304 | wc.opcode = IB_WC_RECV; |
| 2305 | wc.qp = &qp->ibqp; |
| 2306 | wc.src_qp = qp->remote_qpn; |
| 2307 | wc.slid = qp->remote_ah_attr.dlid; |
| 2308 | /* |
| 2309 | * It seems that IB mandates the presence of an SL in a |
| 2310 | * work completion only for the UD transport (see section |
| 2311 | * 11.4.2 of IBTA Vol. 1). |
| 2312 | * |
| 2313 | * However, the way the SL is chosen below is consistent |
| 2314 | * with the way that IB/qib works and is trying avoid |
| 2315 | * introducing incompatibilities. |
| 2316 | * |
| 2317 | * See also OPA Vol. 1, section 9.7.6, and table 9-17. |
| 2318 | */ |
| 2319 | wc.sl = qp->remote_ah_attr.sl; |
| 2320 | /* zero fields that are N/A */ |
| 2321 | wc.vendor_err = 0; |
| 2322 | wc.pkey_index = 0; |
| 2323 | wc.dlid_path_bits = 0; |
| 2324 | wc.port_num = 0; |
| 2325 | /* Signal completion event if the solicited bit is set. */ |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 2326 | rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, |
| 2327 | (bth0 & IB_BTH_SOLICITED) != 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2328 | break; |
| 2329 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2330 | case OP(RDMA_WRITE_ONLY): |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 2331 | copy_last = 1; |
| 2332 | /* fall through */ |
| 2333 | case OP(RDMA_WRITE_FIRST): |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2334 | case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE): |
| 2335 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) |
| 2336 | goto nack_inv; |
| 2337 | /* consume RWQE */ |
| 2338 | reth = &ohdr->u.rc.reth; |
| 2339 | qp->r_len = be32_to_cpu(reth->length); |
| 2340 | qp->r_rcv_len = 0; |
| 2341 | qp->r_sge.sg_list = NULL; |
| 2342 | if (qp->r_len != 0) { |
| 2343 | u32 rkey = be32_to_cpu(reth->rkey); |
| 2344 | u64 vaddr = be64_to_cpu(reth->vaddr); |
| 2345 | int ok; |
| 2346 | |
| 2347 | /* Check rkey & NAK */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2348 | ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, vaddr, |
| 2349 | rkey, IB_ACCESS_REMOTE_WRITE); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2350 | if (unlikely(!ok)) |
| 2351 | goto nack_acc; |
| 2352 | qp->r_sge.num_sge = 1; |
| 2353 | } else { |
| 2354 | qp->r_sge.num_sge = 0; |
| 2355 | qp->r_sge.sge.mr = NULL; |
| 2356 | qp->r_sge.sge.vaddr = NULL; |
| 2357 | qp->r_sge.sge.length = 0; |
| 2358 | qp->r_sge.sge.sge_length = 0; |
| 2359 | } |
| 2360 | if (opcode == OP(RDMA_WRITE_FIRST)) |
| 2361 | goto send_middle; |
| 2362 | else if (opcode == OP(RDMA_WRITE_ONLY)) |
| 2363 | goto no_immediate_data; |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 2364 | ret = hfi1_rvt_get_rwqe(qp, 1); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2365 | if (ret < 0) |
| 2366 | goto nack_op_err; |
| 2367 | if (!ret) |
| 2368 | goto rnr_nak; |
| 2369 | wc.ex.imm_data = ohdr->u.rc.imm_data; |
| 2370 | wc.wc_flags = IB_WC_WITH_IMM; |
| 2371 | goto send_last; |
| 2372 | |
| 2373 | case OP(RDMA_READ_REQUEST): { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2374 | struct rvt_ack_entry *e; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2375 | u32 len; |
| 2376 | u8 next; |
| 2377 | |
| 2378 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) |
| 2379 | goto nack_inv; |
| 2380 | next = qp->r_head_ack_queue + 1; |
| 2381 | /* s_ack_queue is size HFI1_MAX_RDMA_ATOMIC+1 so use > not >= */ |
| 2382 | if (next > HFI1_MAX_RDMA_ATOMIC) |
| 2383 | next = 0; |
| 2384 | spin_lock_irqsave(&qp->s_lock, flags); |
| 2385 | if (unlikely(next == qp->s_tail_ack_queue)) { |
| 2386 | if (!qp->s_ack_queue[next].sent) |
| 2387 | goto nack_inv_unlck; |
| 2388 | update_ack_queue(qp, next); |
| 2389 | } |
| 2390 | e = &qp->s_ack_queue[qp->r_head_ack_queue]; |
| 2391 | if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2392 | rvt_put_mr(e->rdma_sge.mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2393 | e->rdma_sge.mr = NULL; |
| 2394 | } |
| 2395 | reth = &ohdr->u.rc.reth; |
| 2396 | len = be32_to_cpu(reth->length); |
| 2397 | if (len) { |
| 2398 | u32 rkey = be32_to_cpu(reth->rkey); |
| 2399 | u64 vaddr = be64_to_cpu(reth->vaddr); |
| 2400 | int ok; |
| 2401 | |
| 2402 | /* Check rkey & NAK */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2403 | ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr, |
| 2404 | rkey, IB_ACCESS_REMOTE_READ); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2405 | if (unlikely(!ok)) |
| 2406 | goto nack_acc_unlck; |
| 2407 | /* |
| 2408 | * Update the next expected PSN. We add 1 later |
| 2409 | * below, so only add the remainder here. |
| 2410 | */ |
| 2411 | if (len > pmtu) |
| 2412 | qp->r_psn += (len - 1) / pmtu; |
| 2413 | } else { |
| 2414 | e->rdma_sge.mr = NULL; |
| 2415 | e->rdma_sge.vaddr = NULL; |
| 2416 | e->rdma_sge.length = 0; |
| 2417 | e->rdma_sge.sge_length = 0; |
| 2418 | } |
| 2419 | e->opcode = opcode; |
| 2420 | e->sent = 0; |
| 2421 | e->psn = psn; |
| 2422 | e->lpsn = qp->r_psn; |
| 2423 | /* |
| 2424 | * We need to increment the MSN here instead of when we |
| 2425 | * finish sending the result since a duplicate request would |
| 2426 | * increment it more than once. |
| 2427 | */ |
| 2428 | qp->r_msn++; |
| 2429 | qp->r_psn++; |
| 2430 | qp->r_state = opcode; |
| 2431 | qp->r_nak_state = 0; |
| 2432 | qp->r_head_ack_queue = next; |
| 2433 | |
| 2434 | /* Schedule the send tasklet. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 2435 | qp->s_flags |= RVT_S_RESP_PENDING; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2436 | hfi1_schedule_send(qp); |
| 2437 | |
| 2438 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 2439 | if (is_fecn) |
| 2440 | goto send_ack; |
| 2441 | return; |
| 2442 | } |
| 2443 | |
| 2444 | case OP(COMPARE_SWAP): |
| 2445 | case OP(FETCH_ADD): { |
| 2446 | struct ib_atomic_eth *ateth; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2447 | struct rvt_ack_entry *e; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2448 | u64 vaddr; |
| 2449 | atomic64_t *maddr; |
| 2450 | u64 sdata; |
| 2451 | u32 rkey; |
| 2452 | u8 next; |
| 2453 | |
| 2454 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) |
| 2455 | goto nack_inv; |
| 2456 | next = qp->r_head_ack_queue + 1; |
| 2457 | if (next > HFI1_MAX_RDMA_ATOMIC) |
| 2458 | next = 0; |
| 2459 | spin_lock_irqsave(&qp->s_lock, flags); |
| 2460 | if (unlikely(next == qp->s_tail_ack_queue)) { |
| 2461 | if (!qp->s_ack_queue[next].sent) |
| 2462 | goto nack_inv_unlck; |
| 2463 | update_ack_queue(qp, next); |
| 2464 | } |
| 2465 | e = &qp->s_ack_queue[qp->r_head_ack_queue]; |
| 2466 | if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2467 | rvt_put_mr(e->rdma_sge.mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2468 | e->rdma_sge.mr = NULL; |
| 2469 | } |
| 2470 | ateth = &ohdr->u.atomic_eth; |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 2471 | vaddr = ((u64)be32_to_cpu(ateth->vaddr[0]) << 32) | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2472 | be32_to_cpu(ateth->vaddr[1]); |
| 2473 | if (unlikely(vaddr & (sizeof(u64) - 1))) |
| 2474 | goto nack_inv_unlck; |
| 2475 | rkey = be32_to_cpu(ateth->rkey); |
| 2476 | /* Check rkey & NAK */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2477 | if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), |
| 2478 | vaddr, rkey, |
| 2479 | IB_ACCESS_REMOTE_ATOMIC))) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2480 | goto nack_acc_unlck; |
| 2481 | /* Perform atomic OP and save result. */ |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 2482 | maddr = (atomic64_t *)qp->r_sge.sge.vaddr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2483 | sdata = be64_to_cpu(ateth->swap_data); |
| 2484 | e->atomic_data = (opcode == OP(FETCH_ADD)) ? |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 2485 | (u64)atomic64_add_return(sdata, maddr) - sdata : |
| 2486 | (u64)cmpxchg((u64 *)qp->r_sge.sge.vaddr, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2487 | be64_to_cpu(ateth->compare_data), |
| 2488 | sdata); |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2489 | rvt_put_mr(qp->r_sge.sge.mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2490 | qp->r_sge.num_sge = 0; |
| 2491 | e->opcode = opcode; |
| 2492 | e->sent = 0; |
| 2493 | e->psn = psn; |
| 2494 | e->lpsn = psn; |
| 2495 | qp->r_msn++; |
| 2496 | qp->r_psn++; |
| 2497 | qp->r_state = opcode; |
| 2498 | qp->r_nak_state = 0; |
| 2499 | qp->r_head_ack_queue = next; |
| 2500 | |
| 2501 | /* Schedule the send tasklet. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 2502 | qp->s_flags |= RVT_S_RESP_PENDING; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2503 | hfi1_schedule_send(qp); |
| 2504 | |
| 2505 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 2506 | if (is_fecn) |
| 2507 | goto send_ack; |
| 2508 | return; |
| 2509 | } |
| 2510 | |
| 2511 | default: |
| 2512 | /* NAK unknown opcodes. */ |
| 2513 | goto nack_inv; |
| 2514 | } |
| 2515 | qp->r_psn++; |
| 2516 | qp->r_state = opcode; |
| 2517 | qp->r_ack_psn = psn; |
| 2518 | qp->r_nak_state = 0; |
| 2519 | /* Send an ACK if requested or required. */ |
Mike Marciniszyn | 7c091e5 | 2015-11-10 09:14:01 -0500 | [diff] [blame] | 2520 | if (psn & IB_BTH_REQ_ACK) { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 2521 | struct hfi1_qp_priv *priv = qp->priv; |
| 2522 | |
Mike Marciniszyn | 7c091e5 | 2015-11-10 09:14:01 -0500 | [diff] [blame] | 2523 | if (packet->numpkt == 0) { |
| 2524 | rc_cancel_ack(qp); |
| 2525 | goto send_ack; |
| 2526 | } |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 2527 | if (priv->r_adefered >= HFI1_PSN_CREDIT) { |
Mike Marciniszyn | 7c091e5 | 2015-11-10 09:14:01 -0500 | [diff] [blame] | 2528 | rc_cancel_ack(qp); |
| 2529 | goto send_ack; |
| 2530 | } |
| 2531 | if (unlikely(is_fecn)) { |
| 2532 | rc_cancel_ack(qp); |
| 2533 | goto send_ack; |
| 2534 | } |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 2535 | priv->r_adefered++; |
Mike Marciniszyn | 7c091e5 | 2015-11-10 09:14:01 -0500 | [diff] [blame] | 2536 | rc_defered_ack(rcd, qp); |
| 2537 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2538 | return; |
| 2539 | |
| 2540 | rnr_nak: |
Harish Chegondi | bf64009 | 2016-03-05 08:49:29 -0800 | [diff] [blame] | 2541 | qp->r_nak_state = qp->r_min_rnr_timer | IB_RNR_NAK; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2542 | qp->r_ack_psn = qp->r_psn; |
| 2543 | /* Queue RNR NAK for later */ |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 2544 | rc_defered_ack(rcd, qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2545 | return; |
| 2546 | |
| 2547 | nack_op_err: |
| 2548 | hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR); |
| 2549 | qp->r_nak_state = IB_NAK_REMOTE_OPERATIONAL_ERROR; |
| 2550 | qp->r_ack_psn = qp->r_psn; |
| 2551 | /* Queue NAK for later */ |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 2552 | rc_defered_ack(rcd, qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2553 | return; |
| 2554 | |
| 2555 | nack_inv_unlck: |
| 2556 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 2557 | nack_inv: |
| 2558 | hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR); |
| 2559 | qp->r_nak_state = IB_NAK_INVALID_REQUEST; |
| 2560 | qp->r_ack_psn = qp->r_psn; |
| 2561 | /* Queue NAK for later */ |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 2562 | rc_defered_ack(rcd, qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2563 | return; |
| 2564 | |
| 2565 | nack_acc_unlck: |
| 2566 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 2567 | nack_acc: |
| 2568 | hfi1_rc_error(qp, IB_WC_LOC_PROT_ERR); |
| 2569 | qp->r_nak_state = IB_NAK_REMOTE_ACCESS_ERROR; |
| 2570 | qp->r_ack_psn = qp->r_psn; |
| 2571 | send_ack: |
| 2572 | hfi1_send_rc_ack(rcd, qp, is_fecn); |
| 2573 | } |
| 2574 | |
| 2575 | void hfi1_rc_hdrerr( |
| 2576 | struct hfi1_ctxtdata *rcd, |
| 2577 | struct hfi1_ib_header *hdr, |
| 2578 | u32 rcv_flags, |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 2579 | struct rvt_qp *qp) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2580 | { |
| 2581 | int has_grh = rcv_flags & HFI1_HAS_GRH; |
| 2582 | struct hfi1_other_headers *ohdr; |
| 2583 | struct hfi1_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num); |
| 2584 | int diff; |
Nicolas Iooss | 49c3203 | 2015-09-20 16:07:15 +0200 | [diff] [blame] | 2585 | u32 opcode; |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 2586 | u32 psn, bth0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2587 | |
| 2588 | /* Check for GRH */ |
| 2589 | ohdr = &hdr->u.oth; |
| 2590 | if (has_grh) |
| 2591 | ohdr = &hdr->u.l.oth; |
| 2592 | |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 2593 | bth0 = be32_to_cpu(ohdr->bth[0]); |
| 2594 | if (hfi1_ruc_check_hdr(ibp, hdr, has_grh, qp, bth0)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2595 | return; |
| 2596 | |
| 2597 | psn = be32_to_cpu(ohdr->bth[2]); |
Arthur Kepner | 977940b | 2015-11-04 21:10:10 -0500 | [diff] [blame] | 2598 | opcode = (bth0 >> 24) & 0xff; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2599 | |
| 2600 | /* Only deal with RDMA Writes for now */ |
| 2601 | if (opcode < IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) { |
| 2602 | diff = delta_psn(psn, qp->r_psn); |
| 2603 | if (!qp->r_nak_state && diff >= 0) { |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 2604 | ibp->rvp.n_rc_seqnak++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2605 | qp->r_nak_state = IB_NAK_PSN_ERROR; |
| 2606 | /* Use the expected PSN. */ |
| 2607 | qp->r_ack_psn = qp->r_psn; |
| 2608 | /* |
| 2609 | * Wait to send the sequence |
| 2610 | * NAK until all packets |
| 2611 | * in the receive queue have |
| 2612 | * been processed. |
| 2613 | * Otherwise, we end up |
| 2614 | * propagating congestion. |
| 2615 | */ |
Mike Marciniszyn | 2fd3686 | 2015-11-10 09:13:55 -0500 | [diff] [blame] | 2616 | rc_defered_ack(rcd, qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 2617 | } /* Out of sequence NAK */ |
| 2618 | } /* QP Request NAKs */ |
| 2619 | } |