Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1 | /* |
Mike Marciniszyn | b6eac93 | 2017-04-09 10:16:35 -0700 | [diff] [blame] | 2 | * Copyright(c) 2015 - 2017 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/spinlock.h> |
| 49 | |
| 50 | #include "hfi.h" |
| 51 | #include "mad.h" |
| 52 | #include "qp.h" |
Mike Marciniszyn | 45842ab | 2016-02-14 12:44:34 -0800 | [diff] [blame] | 53 | #include "verbs_txreq.h" |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 54 | #include "trace.h" |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 55 | |
| 56 | /* |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 57 | * Validate a RWQE and fill in the SGE state. |
| 58 | * Return 1 if OK. |
| 59 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 60 | static int init_sge(struct rvt_qp *qp, struct rvt_rwqe *wqe) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 61 | { |
| 62 | int i, j, ret; |
| 63 | struct ib_wc wc; |
Dennis Dalessandro | cd4ceee | 2016-01-19 14:41:55 -0800 | [diff] [blame] | 64 | struct rvt_lkey_table *rkt; |
Dennis Dalessandro | 4f87ccf | 2016-01-19 14:41:50 -0800 | [diff] [blame] | 65 | struct rvt_pd *pd; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 66 | struct rvt_sge_state *ss; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 67 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 68 | rkt = &to_idev(qp->ibqp.device)->rdi.lkey_table; |
Dennis Dalessandro | 4f87ccf | 2016-01-19 14:41:50 -0800 | [diff] [blame] | 69 | pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 70 | ss = &qp->r_sge; |
| 71 | ss->sg_list = qp->r_sg_list; |
| 72 | qp->r_len = 0; |
| 73 | for (i = j = 0; i < wqe->num_sge; i++) { |
| 74 | if (wqe->sg_list[i].length == 0) |
| 75 | continue; |
| 76 | /* Check LKEY */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 77 | if (!rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge, |
| 78 | &wqe->sg_list[i], IB_ACCESS_LOCAL_WRITE)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 79 | goto bad_lkey; |
| 80 | qp->r_len += wqe->sg_list[i].length; |
| 81 | j++; |
| 82 | } |
| 83 | ss->num_sge = j; |
| 84 | ss->total_len = qp->r_len; |
| 85 | ret = 1; |
| 86 | goto bail; |
| 87 | |
| 88 | bad_lkey: |
| 89 | while (j) { |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 90 | struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 91 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 92 | rvt_put_mr(sge->mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 93 | } |
| 94 | ss->num_sge = 0; |
| 95 | memset(&wc, 0, sizeof(wc)); |
| 96 | wc.wr_id = wqe->wr_id; |
| 97 | wc.status = IB_WC_LOC_PROT_ERR; |
| 98 | wc.opcode = IB_WC_RECV; |
| 99 | wc.qp = &qp->ibqp; |
| 100 | /* Signal solicited completion event. */ |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 101 | rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 102 | ret = 0; |
| 103 | bail: |
| 104 | return ret; |
| 105 | } |
| 106 | |
| 107 | /** |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 108 | * hfi1_rvt_get_rwqe - copy the next RWQE into the QP's RWQE |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 109 | * @qp: the QP |
| 110 | * @wr_id_only: update qp->r_wr_id only, not qp->r_sge |
| 111 | * |
| 112 | * Return -1 if there is a local error, 0 if no RWQE is available, |
| 113 | * otherwise return 1. |
| 114 | * |
| 115 | * Can be called from interrupt level. |
| 116 | */ |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 117 | int hfi1_rvt_get_rwqe(struct rvt_qp *qp, int wr_id_only) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 118 | { |
| 119 | unsigned long flags; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 120 | struct rvt_rq *rq; |
| 121 | struct rvt_rwq *wq; |
Dennis Dalessandro | 39db3e6 | 2016-01-19 14:42:33 -0800 | [diff] [blame] | 122 | struct rvt_srq *srq; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 123 | struct rvt_rwqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 124 | void (*handler)(struct ib_event *, void *); |
| 125 | u32 tail; |
| 126 | int ret; |
| 127 | |
| 128 | if (qp->ibqp.srq) { |
Dennis Dalessandro | 39db3e6 | 2016-01-19 14:42:33 -0800 | [diff] [blame] | 129 | srq = ibsrq_to_rvtsrq(qp->ibqp.srq); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 130 | handler = srq->ibsrq.event_handler; |
| 131 | rq = &srq->rq; |
| 132 | } else { |
| 133 | srq = NULL; |
| 134 | handler = NULL; |
| 135 | rq = &qp->r_rq; |
| 136 | } |
| 137 | |
| 138 | spin_lock_irqsave(&rq->lock, flags); |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 139 | if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 140 | ret = 0; |
| 141 | goto unlock; |
| 142 | } |
| 143 | |
| 144 | wq = rq->wq; |
| 145 | tail = wq->tail; |
| 146 | /* Validate tail before using it since it is user writable. */ |
| 147 | if (tail >= rq->size) |
| 148 | tail = 0; |
| 149 | if (unlikely(tail == wq->head)) { |
| 150 | ret = 0; |
| 151 | goto unlock; |
| 152 | } |
| 153 | /* Make sure entry is read after head index is read. */ |
| 154 | smp_rmb(); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 155 | wqe = rvt_get_rwqe_ptr(rq, tail); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 156 | /* |
| 157 | * Even though we update the tail index in memory, the verbs |
| 158 | * consumer is not supposed to post more entries until a |
| 159 | * completion is generated. |
| 160 | */ |
| 161 | if (++tail >= rq->size) |
| 162 | tail = 0; |
| 163 | wq->tail = tail; |
| 164 | if (!wr_id_only && !init_sge(qp, wqe)) { |
| 165 | ret = -1; |
| 166 | goto unlock; |
| 167 | } |
| 168 | qp->r_wr_id = wqe->wr_id; |
| 169 | |
| 170 | ret = 1; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 171 | set_bit(RVT_R_WRID_VALID, &qp->r_aflags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 172 | if (handler) { |
| 173 | u32 n; |
| 174 | |
| 175 | /* |
| 176 | * Validate head pointer value and compute |
| 177 | * the number of remaining WQEs. |
| 178 | */ |
| 179 | n = wq->head; |
| 180 | if (n >= rq->size) |
| 181 | n = 0; |
| 182 | if (n < tail) |
| 183 | n += rq->size - tail; |
| 184 | else |
| 185 | n -= tail; |
| 186 | if (n < srq->limit) { |
| 187 | struct ib_event ev; |
| 188 | |
| 189 | srq->limit = 0; |
| 190 | spin_unlock_irqrestore(&rq->lock, flags); |
| 191 | ev.device = qp->ibqp.device; |
| 192 | ev.element.srq = qp->ibqp.srq; |
| 193 | ev.event = IB_EVENT_SRQ_LIMIT_REACHED; |
| 194 | handler(&ev, srq->ibsrq.srq_context); |
| 195 | goto bail; |
| 196 | } |
| 197 | } |
| 198 | unlock: |
| 199 | spin_unlock_irqrestore(&rq->lock, flags); |
| 200 | bail: |
| 201 | return ret; |
| 202 | } |
| 203 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 204 | static int gid_ok(union ib_gid *gid, __be64 gid_prefix, __be64 id) |
| 205 | { |
| 206 | return (gid->global.interface_id == id && |
| 207 | (gid->global.subnet_prefix == gid_prefix || |
| 208 | gid->global.subnet_prefix == IB_DEFAULT_GID_PREFIX)); |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | * |
| 213 | * This should be called with the QP r_lock held. |
| 214 | * |
| 215 | * The s_lock will be acquired around the hfi1_migrate_qp() call. |
| 216 | */ |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 217 | int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct ib_header *hdr, |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 218 | int has_grh, struct rvt_qp *qp, u32 bth0) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 219 | { |
| 220 | __be64 guid; |
| 221 | unsigned long flags; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 222 | u8 sc5 = ibp->sl_to_sc[rdma_ah_get_sl(&qp->remote_ah_attr)]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 223 | |
| 224 | if (qp->s_mig_state == IB_MIG_ARMED && (bth0 & IB_BTH_MIG_REQ)) { |
| 225 | if (!has_grh) { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 226 | if (rdma_ah_get_ah_flags(&qp->alt_ah_attr) & |
| 227 | IB_AH_GRH) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 228 | goto err; |
| 229 | } else { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 230 | const struct ib_global_route *grh; |
| 231 | |
| 232 | if (!(rdma_ah_get_ah_flags(&qp->alt_ah_attr) & |
| 233 | IB_AH_GRH)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 234 | goto err; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 235 | grh = rdma_ah_read_grh(&qp->alt_ah_attr); |
| 236 | guid = get_sguid(ibp, grh->sgid_index); |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 237 | if (!gid_ok(&hdr->u.l.grh.dgid, ibp->rvp.gid_prefix, |
| 238 | guid)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 239 | goto err; |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 240 | if (!gid_ok( |
| 241 | &hdr->u.l.grh.sgid, |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 242 | grh->dgid.global.subnet_prefix, |
| 243 | grh->dgid.global.interface_id)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 244 | goto err; |
| 245 | } |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 246 | if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0, sc5, |
| 247 | ib_get_slid(hdr)))) { |
Erik E. Kahn | 5cd2411 | 2015-12-10 09:59:40 -0500 | [diff] [blame] | 248 | hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 249 | (u16)bth0, |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 250 | ib_get_sl(hdr), |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 251 | 0, qp->ibqp.qp_num, |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 252 | ib_get_slid(hdr), |
| 253 | ib_get_dlid(hdr)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 254 | goto err; |
| 255 | } |
| 256 | /* Validate the SLID. See Ch. 9.6.1.5 and 17.2.8 */ |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 257 | if (ib_get_slid(hdr) != |
| 258 | rdma_ah_get_dlid(&qp->alt_ah_attr) || |
| 259 | ppd_from_ibp(ibp)->port != |
| 260 | rdma_ah_get_port_num(&qp->alt_ah_attr)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 261 | goto err; |
| 262 | spin_lock_irqsave(&qp->s_lock, flags); |
| 263 | hfi1_migrate_qp(qp); |
| 264 | spin_unlock_irqrestore(&qp->s_lock, flags); |
| 265 | } else { |
| 266 | if (!has_grh) { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 267 | if (rdma_ah_get_ah_flags(&qp->remote_ah_attr) & |
| 268 | IB_AH_GRH) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 269 | goto err; |
| 270 | } else { |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 271 | const struct ib_global_route *grh; |
| 272 | |
| 273 | if (!(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & |
| 274 | IB_AH_GRH)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 275 | goto err; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 276 | grh = rdma_ah_read_grh(&qp->remote_ah_attr); |
| 277 | guid = get_sguid(ibp, grh->sgid_index); |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 278 | if (!gid_ok(&hdr->u.l.grh.dgid, ibp->rvp.gid_prefix, |
| 279 | guid)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 280 | goto err; |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 281 | if (!gid_ok( |
| 282 | &hdr->u.l.grh.sgid, |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 283 | grh->dgid.global.subnet_prefix, |
| 284 | grh->dgid.global.interface_id)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 285 | goto err; |
| 286 | } |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 287 | if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), (u16)bth0, sc5, |
| 288 | ib_get_slid(hdr)))) { |
Erik E. Kahn | 5cd2411 | 2015-12-10 09:59:40 -0500 | [diff] [blame] | 289 | hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 290 | (u16)bth0, |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 291 | ib_get_sl(hdr), |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 292 | 0, qp->ibqp.qp_num, |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 293 | ib_get_slid(hdr), |
| 294 | ib_get_dlid(hdr)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 295 | goto err; |
| 296 | } |
| 297 | /* Validate the SLID. See Ch. 9.6.1.5 */ |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 298 | if (ib_get_slid(hdr) != |
| 299 | rdma_ah_get_dlid(&qp->remote_ah_attr) || |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 300 | ppd_from_ibp(ibp)->port != qp->port_num) |
| 301 | goto err; |
| 302 | if (qp->s_mig_state == IB_MIG_REARM && |
| 303 | !(bth0 & IB_BTH_MIG_REQ)) |
| 304 | qp->s_mig_state = IB_MIG_ARMED; |
| 305 | } |
| 306 | |
| 307 | return 0; |
| 308 | |
| 309 | err: |
| 310 | return 1; |
| 311 | } |
| 312 | |
| 313 | /** |
| 314 | * ruc_loopback - handle UC and RC loopback requests |
| 315 | * @sqp: the sending QP |
| 316 | * |
| 317 | * This is called from hfi1_do_send() to |
| 318 | * forward a WQE addressed to the same HFI. |
Dennis Dalessandro | ca00c62 | 2016-09-25 07:42:08 -0700 | [diff] [blame] | 319 | * Note that although we are single threaded due to the send engine, we still |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 320 | * have to protect against post_send(). We don't have to worry about |
| 321 | * receive interrupts since this is a connected protocol and all packets |
| 322 | * will pass through here. |
| 323 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 324 | static void ruc_loopback(struct rvt_qp *sqp) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 325 | { |
| 326 | struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num); |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 327 | struct rvt_qp *qp; |
| 328 | struct rvt_swqe *wqe; |
| 329 | struct rvt_sge *sge; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 330 | unsigned long flags; |
| 331 | struct ib_wc wc; |
| 332 | u64 sdata; |
| 333 | atomic64_t *maddr; |
| 334 | enum ib_wc_status send_status; |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 335 | bool release; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 336 | int ret; |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 337 | bool copy_last = false; |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame] | 338 | int local_ops = 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 339 | |
| 340 | rcu_read_lock(); |
| 341 | |
| 342 | /* |
| 343 | * Note that we check the responder QP state after |
| 344 | * checking the requester's state. |
| 345 | */ |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 346 | qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp, |
| 347 | sqp->remote_qpn); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 348 | |
| 349 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 350 | |
| 351 | /* Return if we are already busy processing a work request. */ |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 352 | if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) || |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 353 | !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 354 | goto unlock; |
| 355 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 356 | sqp->s_flags |= RVT_S_BUSY; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 357 | |
| 358 | again: |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 359 | smp_read_barrier_depends(); /* see post_one_send() */ |
| 360 | if (sqp->s_last == ACCESS_ONCE(sqp->s_head)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 361 | goto clr_busy; |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 362 | wqe = rvt_get_swqe_ptr(sqp, sqp->s_last); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 363 | |
| 364 | /* Return if it is not OK to start a new work request. */ |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 365 | if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) { |
| 366 | if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 367 | goto clr_busy; |
| 368 | /* We are in the error state, flush the work request. */ |
| 369 | send_status = IB_WC_WR_FLUSH_ERR; |
| 370 | goto flush_send; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * We can rely on the entry not changing without the s_lock |
| 375 | * being held until we update s_last. |
| 376 | * We increment s_cur to indicate s_last is in progress. |
| 377 | */ |
| 378 | if (sqp->s_last == sqp->s_cur) { |
| 379 | if (++sqp->s_cur >= sqp->s_size) |
| 380 | sqp->s_cur = 0; |
| 381 | } |
| 382 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 383 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 384 | if (!qp || !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) || |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 385 | qp->ibqp.qp_type != sqp->ibqp.qp_type) { |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 386 | ibp->rvp.n_pkt_drops++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 387 | /* |
| 388 | * For RC, the requester would timeout and retry so |
| 389 | * shortcut the timeouts and just signal too many retries. |
| 390 | */ |
| 391 | if (sqp->ibqp.qp_type == IB_QPT_RC) |
| 392 | send_status = IB_WC_RETRY_EXC_ERR; |
| 393 | else |
| 394 | send_status = IB_WC_SUCCESS; |
| 395 | goto serr; |
| 396 | } |
| 397 | |
| 398 | memset(&wc, 0, sizeof(wc)); |
| 399 | send_status = IB_WC_SUCCESS; |
| 400 | |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 401 | release = true; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 402 | sqp->s_sge.sge = wqe->sg_list[0]; |
| 403 | sqp->s_sge.sg_list = wqe->sg_list + 1; |
| 404 | sqp->s_sge.num_sge = wqe->wr.num_sge; |
| 405 | sqp->s_len = wqe->length; |
| 406 | switch (wqe->wr.opcode) { |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame] | 407 | case IB_WR_REG_MR: |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame] | 408 | goto send_comp; |
| 409 | |
| 410 | case IB_WR_LOCAL_INV: |
Jianxin Xiong | d9b13c2 | 2016-07-25 13:39:45 -0700 | [diff] [blame] | 411 | if (!(wqe->wr.send_flags & RVT_SEND_COMPLETION_ONLY)) { |
| 412 | if (rvt_invalidate_rkey(sqp, |
| 413 | wqe->wr.ex.invalidate_rkey)) |
| 414 | send_status = IB_WC_LOC_PROT_ERR; |
| 415 | local_ops = 1; |
| 416 | } |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame] | 417 | goto send_comp; |
| 418 | |
| 419 | case IB_WR_SEND_WITH_INV: |
| 420 | if (!rvt_invalidate_rkey(qp, wqe->wr.ex.invalidate_rkey)) { |
| 421 | wc.wc_flags = IB_WC_WITH_INVALIDATE; |
| 422 | wc.ex.invalidate_rkey = wqe->wr.ex.invalidate_rkey; |
| 423 | } |
| 424 | goto send; |
| 425 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 426 | case IB_WR_SEND_WITH_IMM: |
| 427 | wc.wc_flags = IB_WC_WITH_IMM; |
| 428 | wc.ex.imm_data = wqe->wr.ex.imm_data; |
| 429 | /* FALLTHROUGH */ |
| 430 | case IB_WR_SEND: |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame] | 431 | send: |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 432 | ret = hfi1_rvt_get_rwqe(qp, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 433 | if (ret < 0) |
| 434 | goto op_err; |
| 435 | if (!ret) |
| 436 | goto rnr_nak; |
| 437 | break; |
| 438 | |
| 439 | case IB_WR_RDMA_WRITE_WITH_IMM: |
| 440 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) |
| 441 | goto inv_err; |
| 442 | wc.wc_flags = IB_WC_WITH_IMM; |
| 443 | wc.ex.imm_data = wqe->wr.ex.imm_data; |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 444 | ret = hfi1_rvt_get_rwqe(qp, 1); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 445 | if (ret < 0) |
| 446 | goto op_err; |
| 447 | if (!ret) |
| 448 | goto rnr_nak; |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 449 | /* skip copy_last set and qp_access_flags recheck */ |
| 450 | goto do_write; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 451 | case IB_WR_RDMA_WRITE: |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 452 | copy_last = rvt_is_user_qp(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 453 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE))) |
| 454 | goto inv_err; |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 455 | do_write: |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 456 | if (wqe->length == 0) |
Harish Chegondi | 42d6ec1 | 2016-03-05 08:49:24 -0800 | [diff] [blame] | 457 | break; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 458 | if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length, |
| 459 | wqe->rdma_wr.remote_addr, |
| 460 | wqe->rdma_wr.rkey, |
| 461 | IB_ACCESS_REMOTE_WRITE))) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 462 | goto acc_err; |
| 463 | qp->r_sge.sg_list = NULL; |
| 464 | qp->r_sge.num_sge = 1; |
| 465 | qp->r_sge.total_len = wqe->length; |
| 466 | break; |
| 467 | |
| 468 | case IB_WR_RDMA_READ: |
| 469 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ))) |
| 470 | goto inv_err; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 471 | if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length, |
| 472 | wqe->rdma_wr.remote_addr, |
| 473 | wqe->rdma_wr.rkey, |
| 474 | IB_ACCESS_REMOTE_READ))) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 475 | goto acc_err; |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 476 | release = false; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 477 | sqp->s_sge.sg_list = NULL; |
| 478 | sqp->s_sge.num_sge = 1; |
| 479 | qp->r_sge.sge = wqe->sg_list[0]; |
| 480 | qp->r_sge.sg_list = wqe->sg_list + 1; |
| 481 | qp->r_sge.num_sge = wqe->wr.num_sge; |
| 482 | qp->r_sge.total_len = wqe->length; |
| 483 | break; |
| 484 | |
| 485 | case IB_WR_ATOMIC_CMP_AND_SWP: |
| 486 | case IB_WR_ATOMIC_FETCH_AND_ADD: |
| 487 | if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC))) |
| 488 | goto inv_err; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 489 | if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64), |
| 490 | wqe->atomic_wr.remote_addr, |
| 491 | wqe->atomic_wr.rkey, |
| 492 | IB_ACCESS_REMOTE_ATOMIC))) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 493 | goto acc_err; |
| 494 | /* Perform atomic OP and save result. */ |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 495 | maddr = (atomic64_t *)qp->r_sge.sge.vaddr; |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 496 | sdata = wqe->atomic_wr.compare_add; |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 497 | *(u64 *)sqp->s_sge.sge.vaddr = |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 498 | (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ? |
Jubin John | 50e5dcb | 2016-02-14 20:19:41 -0800 | [diff] [blame] | 499 | (u64)atomic64_add_return(sdata, maddr) - sdata : |
| 500 | (u64)cmpxchg((u64 *)qp->r_sge.sge.vaddr, |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 501 | sdata, wqe->atomic_wr.swap); |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 502 | rvt_put_mr(qp->r_sge.sge.mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 503 | qp->r_sge.num_sge = 0; |
| 504 | goto send_comp; |
| 505 | |
| 506 | default: |
| 507 | send_status = IB_WC_LOC_QP_OP_ERR; |
| 508 | goto serr; |
| 509 | } |
| 510 | |
| 511 | sge = &sqp->s_sge.sge; |
| 512 | while (sqp->s_len) { |
| 513 | u32 len = sqp->s_len; |
| 514 | |
| 515 | if (len > sge->length) |
| 516 | len = sge->length; |
| 517 | if (len > sge->sge_length) |
| 518 | len = sge->sge_length; |
| 519 | WARN_ON_ONCE(len == 0); |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 520 | hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, release, copy_last); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 521 | sge->vaddr += len; |
| 522 | sge->length -= len; |
| 523 | sge->sge_length -= len; |
| 524 | if (sge->sge_length == 0) { |
| 525 | if (!release) |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 526 | rvt_put_mr(sge->mr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 527 | if (--sqp->s_sge.num_sge) |
| 528 | *sge = *sqp->s_sge.sg_list++; |
| 529 | } else if (sge->length == 0 && sge->mr->lkey) { |
Dennis Dalessandro | cd4ceee | 2016-01-19 14:41:55 -0800 | [diff] [blame] | 530 | if (++sge->n >= RVT_SEGSZ) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 531 | if (++sge->m >= sge->mr->mapsz) |
| 532 | break; |
| 533 | sge->n = 0; |
| 534 | } |
| 535 | sge->vaddr = |
| 536 | sge->mr->map[sge->m]->segs[sge->n].vaddr; |
| 537 | sge->length = |
| 538 | sge->mr->map[sge->m]->segs[sge->n].length; |
| 539 | } |
| 540 | sqp->s_len -= len; |
| 541 | } |
| 542 | if (release) |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 543 | rvt_put_ss(&qp->r_sge); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 544 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 545 | if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 546 | goto send_comp; |
| 547 | |
| 548 | if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM) |
| 549 | wc.opcode = IB_WC_RECV_RDMA_WITH_IMM; |
| 550 | else |
| 551 | wc.opcode = IB_WC_RECV; |
| 552 | wc.wr_id = qp->r_wr_id; |
| 553 | wc.status = IB_WC_SUCCESS; |
| 554 | wc.byte_len = wqe->length; |
| 555 | wc.qp = &qp->ibqp; |
| 556 | wc.src_qp = qp->remote_qpn; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 557 | wc.slid = rdma_ah_get_dlid(&qp->remote_ah_attr); |
| 558 | wc.sl = rdma_ah_get_sl(&qp->remote_ah_attr); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 559 | wc.port_num = 1; |
| 560 | /* Signal completion event if the solicited bit is set. */ |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 561 | rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, |
| 562 | wqe->wr.send_flags & IB_SEND_SOLICITED); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 563 | |
| 564 | send_comp: |
| 565 | spin_lock_irqsave(&sqp->s_lock, flags); |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 566 | ibp->rvp.n_loop_pkts++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 567 | flush_send: |
| 568 | sqp->s_rnr_retry = sqp->s_rnr_retry_cnt; |
| 569 | hfi1_send_complete(sqp, wqe, send_status); |
Jianxin Xiong | 0db3dfa | 2016-07-25 13:38:37 -0700 | [diff] [blame] | 570 | if (local_ops) { |
| 571 | atomic_dec(&sqp->local_ops_pending); |
| 572 | local_ops = 0; |
| 573 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 574 | goto again; |
| 575 | |
| 576 | rnr_nak: |
| 577 | /* Handle RNR NAK */ |
| 578 | if (qp->ibqp.qp_type == IB_QPT_UC) |
| 579 | goto send_comp; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 580 | ibp->rvp.n_rnr_naks++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 581 | /* |
| 582 | * Note: we don't need the s_lock held since the BUSY flag |
| 583 | * makes this single threaded. |
| 584 | */ |
| 585 | if (sqp->s_rnr_retry == 0) { |
| 586 | send_status = IB_WC_RNR_RETRY_EXC_ERR; |
| 587 | goto serr; |
| 588 | } |
| 589 | if (sqp->s_rnr_retry_cnt < 7) |
| 590 | sqp->s_rnr_retry--; |
| 591 | spin_lock_irqsave(&sqp->s_lock, flags); |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 592 | if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 593 | goto clr_busy; |
Venkata Sandeep Dhanalakota | 56acbbf | 2017-02-08 05:27:19 -0800 | [diff] [blame] | 594 | rvt_add_rnr_timer(sqp, qp->r_min_rnr_timer << |
Don Hiatt | 832666c | 2017-02-08 05:28:25 -0800 | [diff] [blame] | 595 | IB_AETH_CREDIT_SHIFT); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 596 | goto clr_busy; |
| 597 | |
| 598 | op_err: |
| 599 | send_status = IB_WC_REM_OP_ERR; |
| 600 | wc.status = IB_WC_LOC_QP_OP_ERR; |
| 601 | goto err; |
| 602 | |
| 603 | inv_err: |
| 604 | send_status = IB_WC_REM_INV_REQ_ERR; |
| 605 | wc.status = IB_WC_LOC_QP_OP_ERR; |
| 606 | goto err; |
| 607 | |
| 608 | acc_err: |
| 609 | send_status = IB_WC_REM_ACCESS_ERR; |
| 610 | wc.status = IB_WC_LOC_PROT_ERR; |
| 611 | err: |
| 612 | /* responder goes to error state */ |
Brian Welty | beb5a04 | 2017-02-08 05:27:01 -0800 | [diff] [blame] | 613 | rvt_rc_error(qp, wc.status); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 614 | |
| 615 | serr: |
| 616 | spin_lock_irqsave(&sqp->s_lock, flags); |
| 617 | hfi1_send_complete(sqp, wqe, send_status); |
| 618 | if (sqp->ibqp.qp_type == IB_QPT_RC) { |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 619 | int lastwqe = rvt_error_qp(sqp, IB_WC_WR_FLUSH_ERR); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 620 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 621 | sqp->s_flags &= ~RVT_S_BUSY; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 622 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 623 | if (lastwqe) { |
| 624 | struct ib_event ev; |
| 625 | |
| 626 | ev.device = sqp->ibqp.device; |
| 627 | ev.element.qp = &sqp->ibqp; |
| 628 | ev.event = IB_EVENT_QP_LAST_WQE_REACHED; |
| 629 | sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context); |
| 630 | } |
| 631 | goto done; |
| 632 | } |
| 633 | clr_busy: |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 634 | sqp->s_flags &= ~RVT_S_BUSY; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 635 | unlock: |
| 636 | spin_unlock_irqrestore(&sqp->s_lock, flags); |
| 637 | done: |
| 638 | rcu_read_unlock(); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * hfi1_make_grh - construct a GRH header |
| 643 | * @ibp: a pointer to the IB port |
| 644 | * @hdr: a pointer to the GRH header being constructed |
| 645 | * @grh: the global route address to send to |
| 646 | * @hwords: the number of 32 bit words of header being sent |
| 647 | * @nwords: the number of 32 bit words of data being sent |
| 648 | * |
| 649 | * Return the size of the header in 32 bit words. |
| 650 | */ |
| 651 | u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr, |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 652 | const struct ib_global_route *grh, u32 hwords, u32 nwords) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 653 | { |
| 654 | hdr->version_tclass_flow = |
| 655 | cpu_to_be32((IB_GRH_VERSION << IB_GRH_VERSION_SHIFT) | |
| 656 | (grh->traffic_class << IB_GRH_TCLASS_SHIFT) | |
| 657 | (grh->flow_label << IB_GRH_FLOW_SHIFT)); |
| 658 | hdr->paylen = cpu_to_be16((hwords - 2 + nwords + SIZE_OF_CRC) << 2); |
| 659 | /* next_hdr is defined by C8-7 in ch. 8.4.1 */ |
| 660 | hdr->next_hdr = IB_GRH_NEXT_HDR; |
| 661 | hdr->hop_limit = grh->hop_limit; |
| 662 | /* The SGID is 32-bit aligned. */ |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 663 | hdr->sgid.global.subnet_prefix = ibp->rvp.gid_prefix; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 664 | hdr->sgid.global.interface_id = |
Jakub Pawlak | a6cd5f0 | 2016-10-17 04:19:30 -0700 | [diff] [blame] | 665 | grh->sgid_index < HFI1_GUIDS_PER_PORT ? |
| 666 | get_sguid(ibp, grh->sgid_index) : |
| 667 | get_sguid(ibp, HFI1_PORT_GUID_INDEX); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 668 | hdr->dgid = grh->dgid; |
| 669 | |
| 670 | /* GRH header size in 32-bit words. */ |
| 671 | return sizeof(struct ib_grh) / sizeof(u32); |
| 672 | } |
| 673 | |
Don Hiatt | d4d602e | 2016-07-25 13:40:22 -0700 | [diff] [blame] | 674 | #define BTH2_OFFSET (offsetof(struct hfi1_sdma_header, hdr.u.oth.bth[2]) / 4) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 675 | |
| 676 | /** |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 677 | * build_ahg - create ahg in s_ahg |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 678 | * @qp: a pointer to QP |
| 679 | * @npsn: the next PSN for the request/response |
| 680 | * |
| 681 | * This routine handles the AHG by allocating an ahg entry and causing the |
| 682 | * copy of the first middle. |
| 683 | * |
| 684 | * Subsequent middles use the copied entry, editing the |
| 685 | * PSN with 1 or 2 edits. |
| 686 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 687 | static inline void build_ahg(struct rvt_qp *qp, u32 npsn) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 688 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 689 | struct hfi1_qp_priv *priv = qp->priv; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 690 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 691 | if (unlikely(qp->s_flags & RVT_S_AHG_CLEAR)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 692 | clear_ahg(qp); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 693 | if (!(qp->s_flags & RVT_S_AHG_VALID)) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 694 | /* first middle that needs copy */ |
Mike Marciniszyn | d7b8ba5 | 2015-11-09 19:13:59 -0500 | [diff] [blame] | 695 | if (qp->s_ahgidx < 0) |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 696 | qp->s_ahgidx = sdma_ahg_alloc(priv->s_sde); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 697 | if (qp->s_ahgidx >= 0) { |
| 698 | qp->s_ahgpsn = npsn; |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 699 | priv->s_ahg->tx_flags |= SDMA_TXREQ_F_AHG_COPY; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 700 | /* save to protect a change in another thread */ |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 701 | priv->s_ahg->ahgidx = qp->s_ahgidx; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 702 | qp->s_flags |= RVT_S_AHG_VALID; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 703 | } |
| 704 | } else { |
| 705 | /* subsequent middle after valid */ |
| 706 | if (qp->s_ahgidx >= 0) { |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 707 | priv->s_ahg->tx_flags |= SDMA_TXREQ_F_USE_AHG; |
| 708 | priv->s_ahg->ahgidx = qp->s_ahgidx; |
| 709 | priv->s_ahg->ahgcount++; |
| 710 | priv->s_ahg->ahgdesc[0] = |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 711 | sdma_build_ahg_descriptor( |
| 712 | (__force u16)cpu_to_be16((u16)npsn), |
| 713 | BTH2_OFFSET, |
| 714 | 16, |
| 715 | 16); |
| 716 | if ((npsn & 0xffff0000) != |
| 717 | (qp->s_ahgpsn & 0xffff0000)) { |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 718 | priv->s_ahg->ahgcount++; |
| 719 | priv->s_ahg->ahgdesc[1] = |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 720 | sdma_build_ahg_descriptor( |
| 721 | (__force u16)cpu_to_be16( |
| 722 | (u16)(npsn >> 16)), |
| 723 | BTH2_OFFSET, |
| 724 | 0, |
| 725 | 16); |
| 726 | } |
| 727 | } |
| 728 | } |
| 729 | } |
| 730 | |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 731 | void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr, |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 732 | u32 bth0, u32 bth2, int middle, |
| 733 | struct hfi1_pkt_state *ps) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 734 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 735 | struct hfi1_qp_priv *priv = qp->priv; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 736 | struct hfi1_ibport *ibp = ps->ibp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 737 | u16 lrh0; |
| 738 | u32 nwords; |
| 739 | u32 extra_bytes; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 740 | u32 bth1; |
| 741 | |
| 742 | /* Construct the header. */ |
Don Hiatt | e922ae0 | 2016-12-07 19:33:00 -0800 | [diff] [blame] | 743 | extra_bytes = -ps->s_txreq->s_cur_size & 3; |
| 744 | nwords = (ps->s_txreq->s_cur_size + extra_bytes) >> 2; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 745 | lrh0 = HFI1_LRH_BTH; |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 746 | if (unlikely(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH)) { |
| 747 | qp->s_hdrwords += |
| 748 | hfi1_make_grh(ibp, |
| 749 | &ps->s_txreq->phdr.hdr.u.l.grh, |
| 750 | rdma_ah_read_grh(&qp->remote_ah_attr), |
| 751 | qp->s_hdrwords, nwords); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 752 | lrh0 = HFI1_LRH_GRH; |
| 753 | middle = 0; |
| 754 | } |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 755 | lrh0 |= (priv->s_sc & 0xf) << 12 | |
| 756 | (rdma_ah_get_sl(&qp->remote_ah_attr) & 0xf) << 4; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 757 | /* |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 758 | * reset s_ahg/AHG fields |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 759 | * |
| 760 | * This insures that the ahgentry/ahgcount |
| 761 | * are at a non-AHG default to protect |
| 762 | * build_verbs_tx_desc() from using |
| 763 | * an include ahgidx. |
| 764 | * |
| 765 | * build_ahg() will modify as appropriate |
| 766 | * to use the AHG feature. |
| 767 | */ |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 768 | priv->s_ahg->tx_flags = 0; |
| 769 | priv->s_ahg->ahgcount = 0; |
| 770 | priv->s_ahg->ahgidx = 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 771 | if (qp->s_mig_state == IB_MIG_MIGRATED) |
| 772 | bth0 |= IB_BTH_MIG_REQ; |
| 773 | else |
| 774 | middle = 0; |
| 775 | if (middle) |
| 776 | build_ahg(qp, bth2); |
| 777 | else |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 778 | qp->s_flags &= ~RVT_S_AHG_VALID; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 779 | ps->s_txreq->phdr.hdr.lrh[0] = cpu_to_be16(lrh0); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 780 | ps->s_txreq->phdr.hdr.lrh[1] = |
| 781 | cpu_to_be16(rdma_ah_get_dlid(&qp->remote_ah_attr)); |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 782 | ps->s_txreq->phdr.hdr.lrh[2] = |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 783 | cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 784 | ps->s_txreq->phdr.hdr.lrh[3] = |
| 785 | cpu_to_be16(ppd_from_ibp(ibp)->lid | |
| 786 | rdma_ah_get_path_bits(&qp->remote_ah_attr)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 787 | bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index); |
| 788 | bth0 |= extra_bytes << 20; |
| 789 | ohdr->bth[0] = cpu_to_be32(bth0); |
| 790 | bth1 = qp->remote_qpn; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 791 | if (qp->s_flags & RVT_S_ECN) { |
| 792 | qp->s_flags &= ~RVT_S_ECN; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 793 | /* we recently received a FECN, so return a BECN */ |
Don Hiatt | 3d59109 | 2017-04-09 10:16:28 -0700 | [diff] [blame] | 794 | bth1 |= (IB_BECN_MASK << IB_BECN_SHIFT); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 795 | } |
| 796 | ohdr->bth[1] = cpu_to_be32(bth1); |
| 797 | ohdr->bth[2] = cpu_to_be32(bth2); |
| 798 | } |
| 799 | |
Dean Luick | b421922 | 2015-10-26 10:28:35 -0400 | [diff] [blame] | 800 | /* when sending, force a reschedule every one of these periods */ |
| 801 | #define SEND_RESCHED_TIMEOUT (5 * HZ) /* 5s in jiffies */ |
| 802 | |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 803 | /** |
| 804 | * schedule_send_yield - test for a yield required for QP send engine |
| 805 | * @timeout: Final time for timeout slice for jiffies |
| 806 | * @qp: a pointer to QP |
| 807 | * @ps: a pointer to a structure with commonly lookup values for |
| 808 | * the the send engine progress |
| 809 | * |
| 810 | * This routine checks if the time slice for the QP has expired |
| 811 | * for RC QPs, if so an additional work entry is queued. At this |
| 812 | * point, other QPs have an opportunity to be scheduled. It |
| 813 | * returns true if a yield is required, otherwise, false |
| 814 | * is returned. |
| 815 | */ |
| 816 | static bool schedule_send_yield(struct rvt_qp *qp, |
| 817 | struct hfi1_pkt_state *ps) |
| 818 | { |
| 819 | if (unlikely(time_after(jiffies, ps->timeout))) { |
| 820 | if (!ps->in_thread || |
| 821 | workqueue_congested(ps->cpu, ps->ppd->hfi1_wq)) { |
| 822 | spin_lock_irqsave(&qp->s_lock, ps->flags); |
| 823 | qp->s_flags &= ~RVT_S_BUSY; |
| 824 | hfi1_schedule_send(qp); |
| 825 | spin_unlock_irqrestore(&qp->s_lock, ps->flags); |
| 826 | this_cpu_inc(*ps->ppd->dd->send_schedule); |
| 827 | trace_hfi1_rc_expired_time_slice(qp, true); |
| 828 | return true; |
| 829 | } |
| 830 | |
| 831 | cond_resched(); |
| 832 | this_cpu_inc(*ps->ppd->dd->send_schedule); |
| 833 | ps->timeout = jiffies + ps->timeout_int; |
| 834 | } |
| 835 | |
| 836 | trace_hfi1_rc_expired_time_slice(qp, false); |
| 837 | return false; |
| 838 | } |
| 839 | |
Mike Marciniszyn | b6eac93 | 2017-04-09 10:16:35 -0700 | [diff] [blame] | 840 | void hfi1_do_send_from_rvt(struct rvt_qp *qp) |
| 841 | { |
| 842 | hfi1_do_send(qp, false); |
| 843 | } |
| 844 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 845 | void _hfi1_do_send(struct work_struct *work) |
| 846 | { |
| 847 | struct iowait *wait = container_of(work, struct iowait, iowork); |
| 848 | struct rvt_qp *qp = iowait_to_qp(wait); |
| 849 | |
Mike Marciniszyn | b6eac93 | 2017-04-09 10:16:35 -0700 | [diff] [blame] | 850 | hfi1_do_send(qp, true); |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 851 | } |
| 852 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 853 | /** |
| 854 | * hfi1_do_send - perform a send on a QP |
| 855 | * @work: contains a pointer to the QP |
Mike Marciniszyn | b6eac93 | 2017-04-09 10:16:35 -0700 | [diff] [blame] | 856 | * @in_thread: true if in a workqueue thread |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 857 | * |
| 858 | * Process entries in the send work queue until credit or queue is |
Dennis Dalessandro | ca00c62 | 2016-09-25 07:42:08 -0700 | [diff] [blame] | 859 | * exhausted. Only allow one CPU to send a packet per QP. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 860 | * Otherwise, two threads could send packets out of order. |
| 861 | */ |
Mike Marciniszyn | b6eac93 | 2017-04-09 10:16:35 -0700 | [diff] [blame] | 862 | void hfi1_do_send(struct rvt_qp *qp, bool in_thread) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 863 | { |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 864 | struct hfi1_pkt_state ps; |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 865 | struct hfi1_qp_priv *priv = qp->priv; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 866 | int (*make_req)(struct rvt_qp *qp, struct hfi1_pkt_state *ps); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 867 | |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 868 | ps.dev = to_idev(qp->ibqp.device); |
| 869 | ps.ibp = to_iport(qp->ibqp.device, qp->port_num); |
| 870 | ps.ppd = ppd_from_ibp(ps.ibp); |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 871 | ps.in_thread = in_thread; |
| 872 | |
| 873 | trace_hfi1_rc_do_send(qp, in_thread); |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 874 | |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 875 | switch (qp->ibqp.qp_type) { |
| 876 | case IB_QPT_RC: |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 877 | if (!loopback && ((rdma_ah_get_dlid(&qp->remote_ah_attr) & |
| 878 | ~((1 << ps.ppd->lmc) - 1)) == |
| 879 | ps.ppd->lid)) { |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 880 | ruc_loopback(qp); |
| 881 | return; |
| 882 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 883 | make_req = hfi1_make_rc_req; |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 884 | ps.timeout_int = qp->timeout_jiffies; |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 885 | break; |
| 886 | case IB_QPT_UC: |
Dasaratharaman Chandramouli | d8966fc | 2017-04-29 14:41:28 -0400 | [diff] [blame] | 887 | if (!loopback && ((rdma_ah_get_dlid(&qp->remote_ah_attr) & |
| 888 | ~((1 << ps.ppd->lmc) - 1)) == |
| 889 | ps.ppd->lid)) { |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 890 | ruc_loopback(qp); |
| 891 | return; |
| 892 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 893 | make_req = hfi1_make_uc_req; |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 894 | ps.timeout_int = SEND_RESCHED_TIMEOUT; |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 895 | break; |
| 896 | default: |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 897 | make_req = hfi1_make_ud_req; |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 898 | ps.timeout_int = SEND_RESCHED_TIMEOUT; |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 899 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 900 | |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 901 | spin_lock_irqsave(&qp->s_lock, ps.flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 902 | |
| 903 | /* Return if we are already busy processing a work request. */ |
| 904 | if (!hfi1_send_ok(qp)) { |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 905 | spin_unlock_irqrestore(&qp->s_lock, ps.flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 906 | return; |
| 907 | } |
| 908 | |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 909 | qp->s_flags |= RVT_S_BUSY; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 910 | |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 911 | ps.timeout_int = ps.timeout_int / 8; |
| 912 | ps.timeout = jiffies + ps.timeout_int; |
| 913 | ps.cpu = priv->s_sde ? priv->s_sde->cpu : |
Vennila Megavannan | 23cd471 | 2016-02-03 14:34:23 -0800 | [diff] [blame] | 914 | cpumask_first(cpumask_of_node(ps.ppd->dd->node)); |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 915 | |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 916 | /* insure a pre-built packet is handled */ |
| 917 | ps.s_txreq = get_waiting_verbs_txreq(qp); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 918 | do { |
| 919 | /* Check for a constructed packet to be sent. */ |
| 920 | if (qp->s_hdrwords != 0) { |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 921 | spin_unlock_irqrestore(&qp->s_lock, ps.flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 922 | /* |
| 923 | * If the packet cannot be sent now, return and |
Dennis Dalessandro | ca00c62 | 2016-09-25 07:42:08 -0700 | [diff] [blame] | 924 | * the send engine will be woken up later. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 925 | */ |
Dennis Dalessandro | d46e514 | 2015-11-11 00:34:37 -0500 | [diff] [blame] | 926 | if (hfi1_verbs_send(qp, &ps)) |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 927 | return; |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 928 | /* Record that s_ahg is empty. */ |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 929 | qp->s_hdrwords = 0; |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 930 | /* allow other tasks to run */ |
Mike Marciniszyn | dd1ed10 | 2017-05-04 05:14:10 -0700 | [diff] [blame] | 931 | if (schedule_send_yield(qp, &ps)) |
| 932 | return; |
| 933 | |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 934 | spin_lock_irqsave(&qp->s_lock, ps.flags); |
Dean Luick | b421922 | 2015-10-26 10:28:35 -0400 | [diff] [blame] | 935 | } |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 936 | } while (make_req(qp, &ps)); |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 937 | |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 938 | spin_unlock_irqrestore(&qp->s_lock, ps.flags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 939 | } |
| 940 | |
| 941 | /* |
| 942 | * This should be called with s_lock held. |
| 943 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 944 | void hfi1_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 945 | enum ib_wc_status status) |
| 946 | { |
| 947 | u32 old_last, last; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 948 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 949 | if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 950 | return; |
| 951 | |
Mike Marciniszyn | 6c2ab0b | 2016-02-04 11:03:19 -0800 | [diff] [blame] | 952 | last = qp->s_last; |
| 953 | old_last = last; |
Mike Marciniszyn | 9260b35 | 2017-03-20 17:25:23 -0700 | [diff] [blame] | 954 | trace_hfi1_qp_send_completion(qp, wqe, last); |
Mike Marciniszyn | 6c2ab0b | 2016-02-04 11:03:19 -0800 | [diff] [blame] | 955 | if (++last >= qp->s_size) |
| 956 | last = 0; |
Mike Marciniszyn | 9260b35 | 2017-03-20 17:25:23 -0700 | [diff] [blame] | 957 | trace_hfi1_qp_send_completion(qp, wqe, last); |
Mike Marciniszyn | 6c2ab0b | 2016-02-04 11:03:19 -0800 | [diff] [blame] | 958 | qp->s_last = last; |
| 959 | /* See post_send() */ |
| 960 | barrier(); |
Mike Marciniszyn | c64607a | 2016-12-07 19:34:31 -0800 | [diff] [blame] | 961 | rvt_put_swqe(wqe); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 962 | if (qp->ibqp.qp_type == IB_QPT_UD || |
| 963 | qp->ibqp.qp_type == IB_QPT_SMI || |
| 964 | qp->ibqp.qp_type == IB_QPT_GSI) |
Dennis Dalessandro | 15723f0 | 2016-01-19 14:42:17 -0800 | [diff] [blame] | 965 | atomic_dec(&ibah_to_rvtah(wqe->ud_wr.ah)->refcount); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 966 | |
Mike Marciniszyn | 43a474a | 2017-03-20 17:25:04 -0700 | [diff] [blame] | 967 | rvt_qp_swqe_complete(qp, |
| 968 | wqe, |
| 969 | ib_hfi1_wc_opcode[wqe->wr.opcode], |
| 970 | status); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 971 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 972 | if (qp->s_acked == old_last) |
| 973 | qp->s_acked = last; |
| 974 | if (qp->s_cur == old_last) |
| 975 | qp->s_cur = last; |
| 976 | if (qp->s_tail == old_last) |
| 977 | qp->s_tail = last; |
| 978 | if (qp->state == IB_QPS_SQD && last == qp->s_cur) |
| 979 | qp->s_draining = 0; |
| 980 | } |