Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 1 | /* |
Jubin John | 05d6ac1 | 2016-02-14 20:22:17 -0800 | [diff] [blame] | 2 | * Copyright(c) 2015, 2016 Intel Corporation. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 3 | * |
| 4 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 5 | * redistributing this file, you may do so under either license. |
| 6 | * |
| 7 | * GPL LICENSE SUMMARY |
| 8 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of version 2 of the GNU General Public License as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, but |
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * General Public License for more details. |
| 17 | * |
| 18 | * BSD LICENSE |
| 19 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 20 | * Redistribution and use in source and binary forms, with or without |
| 21 | * modification, are permitted provided that the following conditions |
| 22 | * are met: |
| 23 | * |
| 24 | * - Redistributions of source code must retain the above copyright |
| 25 | * notice, this list of conditions and the following disclaimer. |
| 26 | * - Redistributions in binary form must reproduce the above copyright |
| 27 | * notice, this list of conditions and the following disclaimer in |
| 28 | * the documentation and/or other materials provided with the |
| 29 | * distribution. |
| 30 | * - Neither the name of Intel Corporation nor the names of its |
| 31 | * contributors may be used to endorse or promote products derived |
| 32 | * from this software without specific prior written permission. |
| 33 | * |
| 34 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 35 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 36 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 37 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 38 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 39 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 40 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 41 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 42 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 43 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 44 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 45 | * |
| 46 | */ |
| 47 | |
| 48 | #include <linux/net.h> |
| 49 | #include <rdma/ib_smi.h> |
| 50 | |
| 51 | #include "hfi.h" |
| 52 | #include "mad.h" |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 53 | #include "verbs_txreq.h" |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 54 | #include "qp.h" |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 55 | |
| 56 | /** |
| 57 | * ud_loopback - handle send on loopback QPs |
| 58 | * @sqp: the sending QP |
| 59 | * @swqe: the send work request |
| 60 | * |
| 61 | * This is called from hfi1_make_ud_req() to forward a WQE addressed |
| 62 | * to the same HFI. |
| 63 | * Note that the receive interrupt handler may be calling hfi1_ud_rcv() |
| 64 | * while this is being called. |
| 65 | */ |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 66 | static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 67 | { |
| 68 | struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num); |
| 69 | struct hfi1_pportdata *ppd; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 70 | struct rvt_qp *qp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 71 | struct ib_ah_attr *ah_attr; |
| 72 | unsigned long flags; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 73 | struct rvt_sge_state ssge; |
| 74 | struct rvt_sge *sge; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 75 | struct ib_wc wc; |
| 76 | u32 length; |
| 77 | enum ib_qp_type sqptype, dqptype; |
| 78 | |
| 79 | rcu_read_lock(); |
| 80 | |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 81 | qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp, |
| 82 | swqe->ud_wr.remote_qpn); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 83 | if (!qp) { |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 84 | ibp->rvp.n_pkt_drops++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 85 | rcu_read_unlock(); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | sqptype = sqp->ibqp.qp_type == IB_QPT_GSI ? |
| 90 | IB_QPT_UD : sqp->ibqp.qp_type; |
| 91 | dqptype = qp->ibqp.qp_type == IB_QPT_GSI ? |
| 92 | IB_QPT_UD : qp->ibqp.qp_type; |
| 93 | |
| 94 | if (dqptype != sqptype || |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 95 | !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) { |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 96 | ibp->rvp.n_pkt_drops++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 97 | goto drop; |
| 98 | } |
| 99 | |
Dennis Dalessandro | 15723f0 | 2016-01-19 14:42:17 -0800 | [diff] [blame] | 100 | ah_attr = &ibah_to_rvtah(swqe->ud_wr.ah)->attr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 101 | ppd = ppd_from_ibp(ibp); |
| 102 | |
| 103 | if (qp->ibqp.qp_num > 1) { |
| 104 | u16 pkey; |
| 105 | u16 slid; |
| 106 | u8 sc5 = ibp->sl_to_sc[ah_attr->sl]; |
| 107 | |
| 108 | pkey = hfi1_get_pkey(ibp, sqp->s_pkey_index); |
| 109 | slid = ppd->lid | (ah_attr->src_path_bits & |
| 110 | ((1 << ppd->lmc) - 1)); |
| 111 | if (unlikely(ingress_pkey_check(ppd, pkey, sc5, |
| 112 | qp->s_pkey_index, slid))) { |
Erik E. Kahn | 5cd2411 | 2015-12-10 09:59:40 -0500 | [diff] [blame] | 113 | hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, pkey, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 114 | ah_attr->sl, |
| 115 | sqp->ibqp.qp_num, qp->ibqp.qp_num, |
Erik E. Kahn | 5cd2411 | 2015-12-10 09:59:40 -0500 | [diff] [blame] | 116 | slid, ah_attr->dlid); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 117 | goto drop; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * Check that the qkey matches (except for QP0, see 9.6.1.4.1). |
| 123 | * Qkeys with the high order bit set mean use the |
| 124 | * qkey from the QP context instead of the WR (see 10.2.5). |
| 125 | */ |
| 126 | if (qp->ibqp.qp_num) { |
| 127 | u32 qkey; |
| 128 | |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 129 | qkey = (int)swqe->ud_wr.remote_qkey < 0 ? |
| 130 | sqp->qkey : swqe->ud_wr.remote_qkey; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 131 | if (unlikely(qkey != qp->qkey)) { |
| 132 | u16 lid; |
| 133 | |
| 134 | lid = ppd->lid | (ah_attr->src_path_bits & |
| 135 | ((1 << ppd->lmc) - 1)); |
Erik E. Kahn | 5cd2411 | 2015-12-10 09:59:40 -0500 | [diff] [blame] | 136 | hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 137 | ah_attr->sl, |
| 138 | sqp->ibqp.qp_num, qp->ibqp.qp_num, |
Erik E. Kahn | 5cd2411 | 2015-12-10 09:59:40 -0500 | [diff] [blame] | 139 | lid, |
| 140 | ah_attr->dlid); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 141 | goto drop; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /* |
| 146 | * A GRH is expected to precede the data even if not |
| 147 | * present on the wire. |
| 148 | */ |
| 149 | length = swqe->length; |
| 150 | memset(&wc, 0, sizeof(wc)); |
| 151 | wc.byte_len = length + sizeof(struct ib_grh); |
| 152 | |
| 153 | if (swqe->wr.opcode == IB_WR_SEND_WITH_IMM) { |
| 154 | wc.wc_flags = IB_WC_WITH_IMM; |
| 155 | wc.ex.imm_data = swqe->wr.ex.imm_data; |
| 156 | } |
| 157 | |
| 158 | spin_lock_irqsave(&qp->r_lock, flags); |
| 159 | |
| 160 | /* |
| 161 | * Get the next work request entry to find where to put the data. |
| 162 | */ |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 163 | if (qp->r_flags & RVT_R_REUSE_SGE) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 164 | qp->r_flags &= ~RVT_R_REUSE_SGE; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 165 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 166 | int ret; |
| 167 | |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 168 | ret = hfi1_rvt_get_rwqe(qp, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 169 | if (ret < 0) { |
Brian Welty | beb5a04 | 2017-02-08 05:27:01 -0800 | [diff] [blame] | 170 | rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 171 | goto bail_unlock; |
| 172 | } |
| 173 | if (!ret) { |
| 174 | if (qp->ibqp.qp_num == 0) |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 175 | ibp->rvp.n_vl15_dropped++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 176 | goto bail_unlock; |
| 177 | } |
| 178 | } |
| 179 | /* Silently drop packets which are too big. */ |
| 180 | if (unlikely(wc.byte_len > qp->r_len)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 181 | qp->r_flags |= RVT_R_REUSE_SGE; |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 182 | ibp->rvp.n_pkt_drops++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 183 | goto bail_unlock; |
| 184 | } |
| 185 | |
| 186 | if (ah_attr->ah_flags & IB_AH_GRH) { |
Dasaratharaman Chandramouli | 527dbf1 | 2016-07-25 13:40:40 -0700 | [diff] [blame] | 187 | struct ib_grh grh; |
| 188 | struct ib_global_route grd = ah_attr->grh; |
| 189 | |
| 190 | hfi1_make_grh(ibp, &grh, &grd, 0, 0); |
| 191 | hfi1_copy_sge(&qp->r_sge, &grh, |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 192 | sizeof(grh), true, false); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 193 | wc.wc_flags |= IB_WC_GRH; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 194 | } else { |
Brian Welty | 1198fce | 2017-02-08 05:27:37 -0800 | [diff] [blame] | 195 | rvt_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true); |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 196 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 197 | ssge.sg_list = swqe->sg_list + 1; |
| 198 | ssge.sge = *swqe->sg_list; |
| 199 | ssge.num_sge = swqe->wr.num_sge; |
| 200 | sge = &ssge.sge; |
| 201 | while (length) { |
| 202 | u32 len = sge->length; |
| 203 | |
| 204 | if (len > length) |
| 205 | len = length; |
| 206 | if (len > sge->sge_length) |
| 207 | len = sge->sge_length; |
| 208 | WARN_ON_ONCE(len == 0); |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 209 | hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, true, false); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 210 | sge->vaddr += len; |
| 211 | sge->length -= len; |
| 212 | sge->sge_length -= len; |
| 213 | if (sge->sge_length == 0) { |
| 214 | if (--ssge.num_sge) |
| 215 | *sge = *ssge.sg_list++; |
| 216 | } else if (sge->length == 0 && sge->mr->lkey) { |
Dennis Dalessandro | cd4ceee | 2016-01-19 14:41:55 -0800 | [diff] [blame] | 217 | if (++sge->n >= RVT_SEGSZ) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 218 | if (++sge->m >= sge->mr->mapsz) |
| 219 | break; |
| 220 | sge->n = 0; |
| 221 | } |
| 222 | sge->vaddr = |
| 223 | sge->mr->map[sge->m]->segs[sge->n].vaddr; |
| 224 | sge->length = |
| 225 | sge->mr->map[sge->m]->segs[sge->n].length; |
| 226 | } |
| 227 | length -= len; |
| 228 | } |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 229 | rvt_put_ss(&qp->r_sge); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 230 | if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 231 | goto bail_unlock; |
| 232 | wc.wr_id = qp->r_wr_id; |
| 233 | wc.status = IB_WC_SUCCESS; |
| 234 | wc.opcode = IB_WC_RECV; |
| 235 | wc.qp = &qp->ibqp; |
| 236 | wc.src_qp = sqp->ibqp.qp_num; |
| 237 | if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI) { |
| 238 | if (sqp->ibqp.qp_type == IB_QPT_GSI || |
| 239 | sqp->ibqp.qp_type == IB_QPT_SMI) |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 240 | wc.pkey_index = swqe->ud_wr.pkey_index; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 241 | else |
| 242 | wc.pkey_index = sqp->s_pkey_index; |
| 243 | } else { |
| 244 | wc.pkey_index = 0; |
| 245 | } |
| 246 | wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1)); |
| 247 | /* Check for loopback when the port lid is not set */ |
| 248 | if (wc.slid == 0 && sqp->ibqp.qp_type == IB_QPT_GSI) |
Dennis Dalessandro | 8859b4a | 2016-01-19 14:42:11 -0800 | [diff] [blame] | 249 | wc.slid = be16_to_cpu(IB_LID_PERMISSIVE); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 250 | wc.sl = ah_attr->sl; |
| 251 | wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1); |
| 252 | wc.port_num = qp->port_num; |
| 253 | /* Signal completion event if the solicited bit is set. */ |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 254 | rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, |
| 255 | swqe->wr.send_flags & IB_SEND_SOLICITED); |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 256 | ibp->rvp.n_loop_pkts++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 257 | bail_unlock: |
| 258 | spin_unlock_irqrestore(&qp->r_lock, flags); |
| 259 | drop: |
| 260 | rcu_read_unlock(); |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * hfi1_make_ud_req - construct a UD request packet |
| 265 | * @qp: the QP |
| 266 | * |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 267 | * Assume s_lock is held. |
| 268 | * |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 269 | * Return 1 if constructed; otherwise, return 0. |
| 270 | */ |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 271 | int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 272 | { |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 273 | struct hfi1_qp_priv *priv = qp->priv; |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 274 | struct ib_other_headers *ohdr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 275 | struct ib_ah_attr *ah_attr; |
| 276 | struct hfi1_pportdata *ppd; |
| 277 | struct hfi1_ibport *ibp; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 278 | struct rvt_swqe *wqe; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 279 | u32 nwords; |
| 280 | u32 extra_bytes; |
| 281 | u32 bth0; |
| 282 | u16 lrh0; |
| 283 | u16 lid; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 284 | int next_cur; |
| 285 | u8 sc5; |
| 286 | |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 287 | ps->s_txreq = get_txreq(ps->dev, qp); |
| 288 | if (IS_ERR(ps->s_txreq)) |
| 289 | goto bail_no_tx; |
| 290 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 291 | if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) { |
| 292 | if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 293 | goto bail; |
| 294 | /* We are in the error state, flush the work request. */ |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 295 | smp_read_barrier_depends(); /* see post_one_send */ |
| 296 | if (qp->s_last == ACCESS_ONCE(qp->s_head)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 297 | goto bail; |
| 298 | /* If DMAs are in progress, we can't flush immediately. */ |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 299 | if (iowait_sdma_pending(&priv->s_iowait)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 300 | qp->s_flags |= RVT_S_WAIT_DMA; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 301 | goto bail; |
| 302 | } |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 303 | wqe = rvt_get_swqe_ptr(qp, qp->s_last); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 304 | hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR); |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 305 | goto done_free_tx; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 308 | /* see post_one_send() */ |
| 309 | smp_read_barrier_depends(); |
| 310 | if (qp->s_cur == ACCESS_ONCE(qp->s_head)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 311 | goto bail; |
| 312 | |
Dennis Dalessandro | 83693bd | 2016-01-19 14:43:33 -0800 | [diff] [blame] | 313 | wqe = rvt_get_swqe_ptr(qp, qp->s_cur); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 314 | next_cur = qp->s_cur + 1; |
| 315 | if (next_cur >= qp->s_size) |
| 316 | next_cur = 0; |
| 317 | |
| 318 | /* Construct the header. */ |
| 319 | ibp = to_iport(qp->ibqp.device, qp->port_num); |
| 320 | ppd = ppd_from_ibp(ibp); |
Dennis Dalessandro | 15723f0 | 2016-01-19 14:42:17 -0800 | [diff] [blame] | 321 | ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr; |
Dennis Dalessandro | 8859b4a | 2016-01-19 14:42:11 -0800 | [diff] [blame] | 322 | if (ah_attr->dlid < be16_to_cpu(IB_MULTICAST_LID_BASE) || |
| 323 | ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 324 | lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1); |
Jubin John | 17fb4f2 | 2016-02-14 20:21:52 -0800 | [diff] [blame] | 325 | if (unlikely(!loopback && |
| 326 | (lid == ppd->lid || |
| 327 | (lid == be16_to_cpu(IB_LID_PERMISSIVE) && |
| 328 | qp->ibqp.qp_type == IB_QPT_GSI)))) { |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 329 | unsigned long tflags = ps->flags; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 330 | /* |
| 331 | * If DMAs are in progress, we can't generate |
| 332 | * a completion for the loopback packet since |
| 333 | * it would be out of order. |
| 334 | * Instead of waiting, we could queue a |
| 335 | * zero length descriptor so we get a callback. |
| 336 | */ |
Mike Marciniszyn | 14553ca | 2016-02-14 12:45:36 -0800 | [diff] [blame] | 337 | if (iowait_sdma_pending(&priv->s_iowait)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 338 | qp->s_flags |= RVT_S_WAIT_DMA; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 339 | goto bail; |
| 340 | } |
| 341 | qp->s_cur = next_cur; |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 342 | spin_unlock_irqrestore(&qp->s_lock, tflags); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 343 | ud_loopback(qp, wqe); |
Mike Marciniszyn | 747f4d7 | 2016-04-12 10:46:10 -0700 | [diff] [blame] | 344 | spin_lock_irqsave(&qp->s_lock, tflags); |
| 345 | ps->flags = tflags; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 346 | hfi1_send_complete(qp, wqe, IB_WC_SUCCESS); |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 347 | goto done_free_tx; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 348 | } |
| 349 | } |
| 350 | |
| 351 | qp->s_cur = next_cur; |
| 352 | extra_bytes = -wqe->length & 3; |
| 353 | nwords = (wqe->length + extra_bytes) >> 2; |
| 354 | |
| 355 | /* header size in 32-bit words LRH+BTH+DETH = (8+12+8)/4. */ |
| 356 | qp->s_hdrwords = 7; |
Don Hiatt | e922ae0 | 2016-12-07 19:33:00 -0800 | [diff] [blame] | 357 | ps->s_txreq->s_cur_size = wqe->length; |
Mitko Haralanov | b777f15 | 2016-12-07 19:33:27 -0800 | [diff] [blame] | 358 | ps->s_txreq->ss = &qp->s_sge; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 359 | qp->s_srate = ah_attr->static_rate; |
| 360 | qp->srate_mbps = ib_rate_to_mbps(qp->s_srate); |
| 361 | qp->s_wqe = wqe; |
| 362 | qp->s_sge.sge = wqe->sg_list[0]; |
| 363 | qp->s_sge.sg_list = wqe->sg_list + 1; |
| 364 | qp->s_sge.num_sge = wqe->wr.num_sge; |
| 365 | qp->s_sge.total_len = wqe->length; |
| 366 | |
| 367 | if (ah_attr->ah_flags & IB_AH_GRH) { |
| 368 | /* Header size in 32-bit words. */ |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 369 | qp->s_hdrwords += hfi1_make_grh(ibp, |
| 370 | &ps->s_txreq->phdr.hdr.u.l.grh, |
| 371 | &ah_attr->grh, |
| 372 | qp->s_hdrwords, nwords); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 373 | lrh0 = HFI1_LRH_GRH; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 374 | ohdr = &ps->s_txreq->phdr.hdr.u.l.oth; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 375 | /* |
| 376 | * Don't worry about sending to locally attached multicast |
| 377 | * QPs. It is unspecified by the spec. what happens. |
| 378 | */ |
| 379 | } else { |
| 380 | /* Header size in 32-bit words. */ |
| 381 | lrh0 = HFI1_LRH_BTH; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 382 | ohdr = &ps->s_txreq->phdr.hdr.u.oth; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 383 | } |
| 384 | if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) { |
| 385 | qp->s_hdrwords++; |
| 386 | ohdr->u.ud.imm_data = wqe->wr.ex.imm_data; |
| 387 | bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 388 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 389 | bth0 = IB_OPCODE_UD_SEND_ONLY << 24; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 390 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 391 | sc5 = ibp->sl_to_sc[ah_attr->sl]; |
| 392 | lrh0 |= (ah_attr->sl & 0xf) << 4; |
| 393 | if (qp->ibqp.qp_type == IB_QPT_SMI) { |
| 394 | lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */ |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 395 | priv->s_sc = 0xf; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 396 | } else { |
| 397 | lrh0 |= (sc5 & 0xf) << 12; |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 398 | priv->s_sc = sc5; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 399 | } |
Dennis Dalessandro | 4c6829c | 2016-01-19 14:42:00 -0800 | [diff] [blame] | 400 | priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 401 | ps->s_txreq->sde = priv->s_sde; |
Jubin John | 721d042 | 2016-02-14 12:45:00 -0800 | [diff] [blame] | 402 | priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc); |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 403 | ps->s_txreq->psc = priv->s_sendcontext; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 404 | ps->s_txreq->phdr.hdr.lrh[0] = cpu_to_be16(lrh0); |
| 405 | ps->s_txreq->phdr.hdr.lrh[1] = cpu_to_be16(ah_attr->dlid); |
| 406 | ps->s_txreq->phdr.hdr.lrh[2] = |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 407 | cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 408 | if (ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) { |
| 409 | ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE; |
| 410 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 411 | lid = ppd->lid; |
| 412 | if (lid) { |
| 413 | lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1); |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 414 | ps->s_txreq->phdr.hdr.lrh[3] = cpu_to_be16(lid); |
| 415 | } else { |
| 416 | ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE; |
| 417 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 418 | } |
| 419 | if (wqe->wr.send_flags & IB_SEND_SOLICITED) |
| 420 | bth0 |= IB_BTH_SOLICITED; |
| 421 | bth0 |= extra_bytes << 20; |
| 422 | if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI) |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 423 | bth0 |= hfi1_get_pkey(ibp, wqe->ud_wr.pkey_index); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 424 | else |
| 425 | bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index); |
| 426 | ohdr->bth[0] = cpu_to_be32(bth0); |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 427 | ohdr->bth[1] = cpu_to_be32(wqe->ud_wr.remote_qpn); |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 428 | ohdr->bth[2] = cpu_to_be32(mask_psn(wqe->psn)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 429 | /* |
| 430 | * Qkeys with the high order bit set mean use the |
| 431 | * qkey from the QP context instead of the WR (see 10.2.5). |
| 432 | */ |
Christoph Hellwig | e622f2f | 2015-10-08 09:16:33 +0100 | [diff] [blame] | 433 | ohdr->u.ud.deth[0] = cpu_to_be32((int)wqe->ud_wr.remote_qkey < 0 ? |
| 434 | qp->qkey : wqe->ud_wr.remote_qkey); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 435 | ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num); |
| 436 | /* disarm any ahg */ |
Dasaratharaman Chandramouli | a9b6b3b | 2016-07-25 13:40:16 -0700 | [diff] [blame] | 437 | priv->s_ahg->ahgcount = 0; |
| 438 | priv->s_ahg->ahgidx = 0; |
| 439 | priv->s_ahg->tx_flags = 0; |
Mike Marciniszyn | 711e104 | 2016-02-14 12:45:18 -0800 | [diff] [blame] | 440 | /* pbc */ |
| 441 | ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 442 | |
Mike Marciniszyn | 46a80d6 | 2016-02-14 12:10:04 -0800 | [diff] [blame] | 443 | return 1; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 444 | |
| 445 | done_free_tx: |
| 446 | hfi1_put_txreq(ps->s_txreq); |
| 447 | ps->s_txreq = NULL; |
| 448 | return 1; |
| 449 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 450 | bail: |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 451 | hfi1_put_txreq(ps->s_txreq); |
| 452 | |
| 453 | bail_no_tx: |
| 454 | ps->s_txreq = NULL; |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 455 | qp->s_flags &= ~RVT_S_BUSY; |
Dennis Dalessandro | bb5df5f | 2016-02-14 12:44:43 -0800 | [diff] [blame] | 456 | qp->s_hdrwords = 0; |
| 457 | return 0; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /* |
| 461 | * Hardware can't check this so we do it here. |
| 462 | * |
| 463 | * This is a slightly different algorithm than the standard pkey check. It |
| 464 | * special cases the management keys and allows for 0x7fff and 0xffff to be in |
| 465 | * the table at the same time. |
| 466 | * |
| 467 | * @returns the index found or -1 if not found |
| 468 | */ |
| 469 | int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey) |
| 470 | { |
| 471 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
| 472 | unsigned i; |
| 473 | |
| 474 | if (pkey == FULL_MGMT_P_KEY || pkey == LIM_MGMT_P_KEY) { |
| 475 | unsigned lim_idx = -1; |
| 476 | |
| 477 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) { |
| 478 | /* here we look for an exact match */ |
| 479 | if (ppd->pkeys[i] == pkey) |
| 480 | return i; |
| 481 | if (ppd->pkeys[i] == LIM_MGMT_P_KEY) |
| 482 | lim_idx = i; |
| 483 | } |
| 484 | |
| 485 | /* did not find 0xffff return 0x7fff idx if found */ |
| 486 | if (pkey == FULL_MGMT_P_KEY) |
| 487 | return lim_idx; |
| 488 | |
| 489 | /* no match... */ |
| 490 | return -1; |
| 491 | } |
| 492 | |
| 493 | pkey &= 0x7fff; /* remove limited/full membership bit */ |
| 494 | |
| 495 | for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) |
| 496 | if ((ppd->pkeys[i] & 0x7fff) == pkey) |
| 497 | return i; |
| 498 | |
| 499 | /* |
| 500 | * Should not get here, this means hardware failed to validate pkeys. |
| 501 | */ |
| 502 | return -1; |
| 503 | } |
| 504 | |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 505 | void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 506 | u32 pkey, u32 slid, u32 dlid, u8 sc5, |
| 507 | const struct ib_grh *old_grh) |
| 508 | { |
| 509 | u64 pbc, pbc_flags = 0; |
| 510 | u32 bth0, plen, vl, hwords = 5; |
| 511 | u16 lrh0; |
| 512 | u8 sl = ibp->sc_to_sl[sc5]; |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 513 | struct ib_header hdr; |
| 514 | struct ib_other_headers *ohdr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 515 | struct pio_buf *pbuf; |
| 516 | struct send_context *ctxt = qp_to_send_context(qp, sc5); |
| 517 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
| 518 | |
| 519 | if (old_grh) { |
| 520 | struct ib_grh *grh = &hdr.u.l.grh; |
| 521 | |
| 522 | grh->version_tclass_flow = old_grh->version_tclass_flow; |
| 523 | grh->paylen = cpu_to_be16((hwords - 2 + SIZE_OF_CRC) << 2); |
| 524 | grh->hop_limit = 0xff; |
| 525 | grh->sgid = old_grh->dgid; |
| 526 | grh->dgid = old_grh->sgid; |
| 527 | ohdr = &hdr.u.l.oth; |
| 528 | lrh0 = HFI1_LRH_GRH; |
| 529 | hwords += sizeof(struct ib_grh) / sizeof(u32); |
| 530 | } else { |
| 531 | ohdr = &hdr.u.oth; |
| 532 | lrh0 = HFI1_LRH_BTH; |
| 533 | } |
| 534 | |
| 535 | lrh0 |= (sc5 & 0xf) << 12 | sl << 4; |
| 536 | |
| 537 | bth0 = pkey | (IB_OPCODE_CNP << 24); |
| 538 | ohdr->bth[0] = cpu_to_be32(bth0); |
| 539 | |
Don Hiatt | 3d59109 | 2017-04-09 10:16:28 -0700 | [diff] [blame^] | 540 | ohdr->bth[1] = cpu_to_be32(remote_qpn | (1 << IB_BECN_SHIFT)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 541 | ohdr->bth[2] = 0; /* PSN 0 */ |
| 542 | |
| 543 | hdr.lrh[0] = cpu_to_be16(lrh0); |
| 544 | hdr.lrh[1] = cpu_to_be16(dlid); |
| 545 | hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC); |
| 546 | hdr.lrh[3] = cpu_to_be16(slid); |
| 547 | |
| 548 | plen = 2 /* PBC */ + hwords; |
| 549 | pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT; |
| 550 | vl = sc_to_vlt(ppd->dd, sc5); |
| 551 | pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen); |
| 552 | if (ctxt) { |
| 553 | pbuf = sc_buffer_alloc(ctxt, plen, NULL, NULL); |
| 554 | if (pbuf) |
| 555 | ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc, |
| 556 | &hdr, hwords); |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /* |
| 561 | * opa_smp_check() - Do the regular pkey checking, and the additional |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 562 | * checks for SMPs specified in OPAv1 rev 1.0, 9/19/2016 update, section |
| 563 | * 9.10.25 ("SMA Packet Checks"). |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 564 | * |
| 565 | * Note that: |
| 566 | * - Checks are done using the pkey directly from the packet's BTH, |
| 567 | * and specifically _not_ the pkey that we attach to the completion, |
| 568 | * which may be different. |
| 569 | * - These checks are specifically for "non-local" SMPs (i.e., SMPs |
| 570 | * which originated on another node). SMPs which are sent from, and |
| 571 | * destined to this node are checked in opa_local_smp_check(). |
| 572 | * |
| 573 | * At the point where opa_smp_check() is called, we know: |
| 574 | * - destination QP is QP0 |
| 575 | * |
| 576 | * opa_smp_check() returns 0 if all checks succeed, 1 otherwise. |
| 577 | */ |
| 578 | static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5, |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 579 | struct rvt_qp *qp, u16 slid, struct opa_smp *smp) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 580 | { |
| 581 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
| 582 | |
| 583 | /* |
| 584 | * I don't think it's possible for us to get here with sc != 0xf, |
| 585 | * but check it to be certain. |
| 586 | */ |
| 587 | if (sc5 != 0xf) |
| 588 | return 1; |
| 589 | |
| 590 | if (rcv_pkey_check(ppd, pkey, sc5, slid)) |
| 591 | return 1; |
| 592 | |
| 593 | /* |
| 594 | * At this point we know (and so don't need to check again) that |
| 595 | * the pkey is either LIM_MGMT_P_KEY, or FULL_MGMT_P_KEY |
| 596 | * (see ingress_pkey_check). |
| 597 | */ |
| 598 | if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE && |
| 599 | smp->mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED) { |
| 600 | ingress_pkey_table_fail(ppd, pkey, slid); |
| 601 | return 1; |
| 602 | } |
| 603 | |
| 604 | /* |
| 605 | * SMPs fall into one of four (disjoint) categories: |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 606 | * SMA request, SMA response, SMA trap, or SMA trap repress. |
| 607 | * Our response depends, in part, on which type of SMP we're |
| 608 | * processing. |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 609 | * |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 610 | * If this is an SMA response, skip the check here. |
| 611 | * |
| 612 | * If this is an SMA request or SMA trap repress: |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 613 | * - pkey != FULL_MGMT_P_KEY => |
| 614 | * increment port recv constraint errors, drop MAD |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 615 | * |
| 616 | * Otherwise: |
| 617 | * - accept if the port is running an SM |
| 618 | * - drop MAD if it's an SMA trap |
| 619 | * - pkey == FULL_MGMT_P_KEY => |
| 620 | * reply with unsupported method |
| 621 | * - pkey != FULL_MGMT_P_KEY => |
| 622 | * increment port recv constraint errors, drop MAD |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 623 | */ |
| 624 | switch (smp->method) { |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 625 | case IB_MGMT_METHOD_GET_RESP: |
| 626 | case IB_MGMT_METHOD_REPORT_RESP: |
| 627 | break; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 628 | case IB_MGMT_METHOD_GET: |
| 629 | case IB_MGMT_METHOD_SET: |
| 630 | case IB_MGMT_METHOD_REPORT: |
| 631 | case IB_MGMT_METHOD_TRAP_REPRESS: |
| 632 | if (pkey != FULL_MGMT_P_KEY) { |
| 633 | ingress_pkey_table_fail(ppd, pkey, slid); |
| 634 | return 1; |
| 635 | } |
| 636 | break; |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 637 | default: |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 638 | if (ibp->rvp.port_cap_flags & IB_PORT_SM) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 639 | return 0; |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 640 | if (smp->method == IB_MGMT_METHOD_TRAP) |
| 641 | return 1; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 642 | if (pkey == FULL_MGMT_P_KEY) { |
| 643 | smp->status |= IB_SMP_UNSUP_METHOD; |
| 644 | return 0; |
| 645 | } |
Jianxin Xiong | f380920 | 2016-09-30 20:11:09 -0700 | [diff] [blame] | 646 | ingress_pkey_table_fail(ppd, pkey, slid); |
| 647 | return 1; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 648 | } |
| 649 | return 0; |
| 650 | } |
| 651 | |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 652 | /** |
| 653 | * hfi1_ud_rcv - receive an incoming UD packet |
| 654 | * @ibp: the port the packet came in on |
| 655 | * @hdr: the packet header |
| 656 | * @rcv_flags: flags relevant to rcv processing |
| 657 | * @data: the packet data |
| 658 | * @tlen: the packet length |
| 659 | * @qp: the QP the packet came on |
| 660 | * |
| 661 | * This is called from qp_rcv() to process an incoming UD packet |
| 662 | * for the given QP. |
| 663 | * Called at interrupt level. |
| 664 | */ |
| 665 | void hfi1_ud_rcv(struct hfi1_packet *packet) |
| 666 | { |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 667 | struct ib_other_headers *ohdr = packet->ohdr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 668 | int opcode; |
| 669 | u32 hdrsize = packet->hlen; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 670 | struct ib_wc wc; |
| 671 | u32 qkey; |
| 672 | u32 src_qp; |
| 673 | u16 dlid, pkey; |
| 674 | int mgmt_pkey_idx = -1; |
Sebastian Sanchez | f3e862c | 2017-02-08 05:26:25 -0800 | [diff] [blame] | 675 | struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd); |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 676 | struct hfi1_pportdata *ppd = ppd_from_ibp(ibp); |
Mike Marciniszyn | 261a435 | 2016-09-06 04:35:05 -0700 | [diff] [blame] | 677 | struct ib_header *hdr = packet->hdr; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 678 | u32 rcv_flags = packet->rcv_flags; |
| 679 | void *data = packet->ebuf; |
| 680 | u32 tlen = packet->tlen; |
Dennis Dalessandro | 895420d | 2016-01-19 14:42:28 -0800 | [diff] [blame] | 681 | struct rvt_qp *qp = packet->qp; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 682 | bool has_grh = rcv_flags & HFI1_HAS_GRH; |
Dasaratharaman Chandramouli | aad559c | 2017-04-09 10:16:15 -0700 | [diff] [blame] | 683 | u8 sc5 = hfi1_9B_get_sc5(hdr, packet->rhf); |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 684 | u32 bth1; |
| 685 | u8 sl_from_sc, sl; |
| 686 | u16 slid; |
| 687 | u8 extra_bytes; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 688 | |
| 689 | qkey = be32_to_cpu(ohdr->u.ud.deth[0]); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 690 | src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK; |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 691 | dlid = ib_get_dlid(hdr); |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 692 | bth1 = be32_to_cpu(ohdr->bth[1]); |
Don Hiatt | cb427057 | 2017-04-09 10:16:22 -0700 | [diff] [blame] | 693 | slid = ib_get_slid(hdr); |
| 694 | pkey = ib_bth_get_pkey(ohdr); |
| 695 | opcode = ib_bth_get_opcode(ohdr); |
| 696 | sl = ib_get_sl(hdr); |
| 697 | extra_bytes = ib_bth_get_pad(ohdr); |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 698 | extra_bytes += (SIZE_OF_CRC << 2); |
| 699 | sl_from_sc = ibp->sc_to_sl[sc5]; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 700 | |
Mitko Haralanov | 5fd2b56 | 2016-07-25 13:38:07 -0700 | [diff] [blame] | 701 | process_ecn(qp, packet, (opcode != IB_OPCODE_CNP)); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 702 | /* |
| 703 | * Get the number of bytes the message was padded by |
| 704 | * and drop incomplete packets. |
| 705 | */ |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 706 | if (unlikely(tlen < (hdrsize + extra_bytes))) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 707 | goto drop; |
| 708 | |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 709 | tlen -= hdrsize + extra_bytes; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 710 | |
| 711 | /* |
| 712 | * Check that the permissive LID is only used on QP0 |
| 713 | * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1). |
| 714 | */ |
| 715 | if (qp->ibqp.qp_num) { |
| 716 | if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE || |
| 717 | hdr->lrh[3] == IB_LID_PERMISSIVE)) |
| 718 | goto drop; |
| 719 | if (qp->ibqp.qp_num > 1) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 720 | if (unlikely(rcv_pkey_check(ppd, pkey, sc5, slid))) { |
| 721 | /* |
| 722 | * Traps will not be sent for packets dropped |
| 723 | * by the HW. This is fine, as sending trap |
| 724 | * for invalid pkeys is optional according to |
| 725 | * IB spec (release 1.3, section 10.9.4) |
| 726 | */ |
Erik E. Kahn | 5cd2411 | 2015-12-10 09:59:40 -0500 | [diff] [blame] | 727 | hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 728 | pkey, sl, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 729 | src_qp, qp->ibqp.qp_num, |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 730 | slid, dlid); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | } else { |
| 734 | /* GSI packet */ |
| 735 | mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey); |
| 736 | if (mgmt_pkey_idx < 0) |
| 737 | goto drop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 738 | } |
| 739 | if (unlikely(qkey != qp->qkey)) { |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 740 | hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey, sl, |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 741 | src_qp, qp->ibqp.qp_num, |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 742 | slid, dlid); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 743 | return; |
| 744 | } |
| 745 | /* Drop invalid MAD packets (see 13.5.3.1). */ |
| 746 | if (unlikely(qp->ibqp.qp_num == 1 && |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 747 | (tlen > 2048 || (sc5 == 0xF)))) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 748 | goto drop; |
| 749 | } else { |
| 750 | /* Received on QP0, and so by definition, this is an SMP */ |
| 751 | struct opa_smp *smp = (struct opa_smp *)data; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 752 | |
| 753 | if (opa_smp_check(ibp, pkey, sc5, qp, slid, smp)) |
| 754 | goto drop; |
| 755 | |
| 756 | if (tlen > 2048) |
| 757 | goto drop; |
| 758 | if ((hdr->lrh[1] == IB_LID_PERMISSIVE || |
| 759 | hdr->lrh[3] == IB_LID_PERMISSIVE) && |
| 760 | smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) |
| 761 | goto drop; |
| 762 | |
| 763 | /* look up SMI pkey */ |
| 764 | mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey); |
| 765 | if (mgmt_pkey_idx < 0) |
| 766 | goto drop; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 767 | } |
| 768 | |
| 769 | if (qp->ibqp.qp_num > 1 && |
| 770 | opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) { |
| 771 | wc.ex.imm_data = ohdr->u.ud.imm_data; |
| 772 | wc.wc_flags = IB_WC_WITH_IMM; |
| 773 | tlen -= sizeof(u32); |
| 774 | } else if (opcode == IB_OPCODE_UD_SEND_ONLY) { |
| 775 | wc.ex.imm_data = 0; |
| 776 | wc.wc_flags = 0; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 777 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 778 | goto drop; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 779 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 780 | |
| 781 | /* |
| 782 | * A GRH is expected to precede the data even if not |
| 783 | * present on the wire. |
| 784 | */ |
| 785 | wc.byte_len = tlen + sizeof(struct ib_grh); |
| 786 | |
| 787 | /* |
| 788 | * Get the next work request entry to find where to put the data. |
| 789 | */ |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 790 | if (qp->r_flags & RVT_R_REUSE_SGE) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 791 | qp->r_flags &= ~RVT_R_REUSE_SGE; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 792 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 793 | int ret; |
| 794 | |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 795 | ret = hfi1_rvt_get_rwqe(qp, 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 796 | if (ret < 0) { |
Brian Welty | beb5a04 | 2017-02-08 05:27:01 -0800 | [diff] [blame] | 797 | rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 798 | return; |
| 799 | } |
| 800 | if (!ret) { |
| 801 | if (qp->ibqp.qp_num == 0) |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 802 | ibp->rvp.n_vl15_dropped++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 803 | return; |
| 804 | } |
| 805 | } |
| 806 | /* Silently drop packets which are too big. */ |
| 807 | if (unlikely(wc.byte_len > qp->r_len)) { |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 808 | qp->r_flags |= RVT_R_REUSE_SGE; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 809 | goto drop; |
| 810 | } |
| 811 | if (has_grh) { |
| 812 | hfi1_copy_sge(&qp->r_sge, &hdr->u.l.grh, |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 813 | sizeof(struct ib_grh), true, false); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 814 | wc.wc_flags |= IB_WC_GRH; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 815 | } else { |
Brian Welty | 1198fce | 2017-02-08 05:27:37 -0800 | [diff] [blame] | 816 | rvt_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true); |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 817 | } |
Dean Luick | 7b0b01a | 2016-02-03 14:35:49 -0800 | [diff] [blame] | 818 | hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh), |
Brian Welty | 0128fce | 2017-02-08 05:27:31 -0800 | [diff] [blame] | 819 | true, false); |
Dennis Dalessandro | ec4274f | 2016-01-19 14:43:44 -0800 | [diff] [blame] | 820 | rvt_put_ss(&qp->r_sge); |
Dennis Dalessandro | 54d10c1 | 2016-01-19 14:43:01 -0800 | [diff] [blame] | 821 | if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags)) |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 822 | return; |
| 823 | wc.wr_id = qp->r_wr_id; |
| 824 | wc.status = IB_WC_SUCCESS; |
| 825 | wc.opcode = IB_WC_RECV; |
| 826 | wc.vendor_err = 0; |
| 827 | wc.qp = &qp->ibqp; |
| 828 | wc.src_qp = src_qp; |
| 829 | |
| 830 | if (qp->ibqp.qp_type == IB_QPT_GSI || |
| 831 | qp->ibqp.qp_type == IB_QPT_SMI) { |
| 832 | if (mgmt_pkey_idx < 0) { |
| 833 | if (net_ratelimit()) { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 834 | struct hfi1_devdata *dd = ppd->dd; |
| 835 | |
| 836 | dd_dev_err(dd, "QP type %d mgmt_pkey_idx < 0 and packet not dropped???\n", |
| 837 | qp->ibqp.qp_type); |
| 838 | mgmt_pkey_idx = 0; |
| 839 | } |
| 840 | } |
| 841 | wc.pkey_index = (unsigned)mgmt_pkey_idx; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 842 | } else { |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 843 | wc.pkey_index = 0; |
Jubin John | e490974 | 2016-02-14 20:22:00 -0800 | [diff] [blame] | 844 | } |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 845 | |
Dasaratharaman Chandramouli | 89c057c | 2016-07-25 13:40:28 -0700 | [diff] [blame] | 846 | wc.slid = slid; |
| 847 | wc.sl = sl_from_sc; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 848 | |
| 849 | /* |
| 850 | * Save the LMC lower bits if the destination LID is a unicast LID. |
| 851 | */ |
Dennis Dalessandro | 8859b4a | 2016-01-19 14:42:11 -0800 | [diff] [blame] | 852 | wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 : |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 853 | dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1); |
| 854 | wc.port_num = qp->port_num; |
| 855 | /* Signal completion event if the solicited bit is set. */ |
Dennis Dalessandro | abd712d | 2016-01-19 14:43:22 -0800 | [diff] [blame] | 856 | rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, |
| 857 | (ohdr->bth[0] & |
| 858 | cpu_to_be32(IB_BTH_SOLICITED)) != 0); |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 859 | return; |
| 860 | |
| 861 | drop: |
Dennis Dalessandro | 4eb0688 | 2016-01-19 14:42:39 -0800 | [diff] [blame] | 862 | ibp->rvp.n_pkt_drops++; |
Mike Marciniszyn | 7724105 | 2015-07-30 15:17:43 -0400 | [diff] [blame] | 863 | } |