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