blob: 852c20f5498c6851a28da574ee49f0e97de02a72 [file] [log] [blame]
Mike Marciniszyn77241052015-07-30 15:17:43 -04001/*
Jubin John05d6ac12016-02-14 20:22:17 -08002 * Copyright(c) 2015, 2016 Intel Corporation.
Mike Marciniszyn77241052015-07-30 15:17:43 -04003 *
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 Marciniszyn77241052015-07-30 15:17:43 -04009 * 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 Marciniszyn77241052015-07-30 15:17:43 -040020 * 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 Dalessandrobb5df5f2016-02-14 12:44:43 -080053#include "verbs_txreq.h"
Mike Marciniszyn711e1042016-02-14 12:45:18 -080054#include "qp.h"
Mike Marciniszyn77241052015-07-30 15:17:43 -040055
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 Dalessandro895420d2016-01-19 14:42:28 -080066static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
Mike Marciniszyn77241052015-07-30 15:17:43 -040067{
68 struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
69 struct hfi1_pportdata *ppd;
Dennis Dalessandro895420d2016-01-19 14:42:28 -080070 struct rvt_qp *qp;
Mike Marciniszyn77241052015-07-30 15:17:43 -040071 struct ib_ah_attr *ah_attr;
72 unsigned long flags;
Dennis Dalessandro895420d2016-01-19 14:42:28 -080073 struct rvt_sge_state ssge;
74 struct rvt_sge *sge;
Mike Marciniszyn77241052015-07-30 15:17:43 -040075 struct ib_wc wc;
76 u32 length;
77 enum ib_qp_type sqptype, dqptype;
78
79 rcu_read_lock();
80
Dennis Dalessandroec4274f2016-01-19 14:43:44 -080081 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp,
82 swqe->ud_wr.remote_qpn);
Mike Marciniszyn77241052015-07-30 15:17:43 -040083 if (!qp) {
Dennis Dalessandro4eb06882016-01-19 14:42:39 -080084 ibp->rvp.n_pkt_drops++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040085 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 Dalessandro83693bd2016-01-19 14:43:33 -080095 !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
Dennis Dalessandro4eb06882016-01-19 14:42:39 -080096 ibp->rvp.n_pkt_drops++;
Mike Marciniszyn77241052015-07-30 15:17:43 -040097 goto drop;
98 }
99
Dennis Dalessandro15723f02016-01-19 14:42:17 -0800100 ah_attr = &ibah_to_rvtah(swqe->ud_wr.ah)->attr;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400101 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. Kahn5cd24112015-12-10 09:59:40 -0500113 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, pkey,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400114 ah_attr->sl,
115 sqp->ibqp.qp_num, qp->ibqp.qp_num,
Erik E. Kahn5cd24112015-12-10 09:59:40 -0500116 slid, ah_attr->dlid);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400117 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 Hellwige622f2f2015-10-08 09:16:33 +0100129 qkey = (int)swqe->ud_wr.remote_qkey < 0 ?
130 sqp->qkey : swqe->ud_wr.remote_qkey;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400131 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. Kahn5cd24112015-12-10 09:59:40 -0500136 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400137 ah_attr->sl,
138 sqp->ibqp.qp_num, qp->ibqp.qp_num,
Erik E. Kahn5cd24112015-12-10 09:59:40 -0500139 lid,
140 ah_attr->dlid);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400141 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 Johne4909742016-02-14 20:22:00 -0800163 if (qp->r_flags & RVT_R_REUSE_SGE) {
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800164 qp->r_flags &= ~RVT_R_REUSE_SGE;
Jubin Johne4909742016-02-14 20:22:00 -0800165 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400166 int ret;
167
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800168 ret = hfi1_rvt_get_rwqe(qp, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400169 if (ret < 0) {
170 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
171 goto bail_unlock;
172 }
173 if (!ret) {
174 if (qp->ibqp.qp_num == 0)
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800175 ibp->rvp.n_vl15_dropped++;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400176 goto bail_unlock;
177 }
178 }
179 /* Silently drop packets which are too big. */
180 if (unlikely(wc.byte_len > qp->r_len)) {
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800181 qp->r_flags |= RVT_R_REUSE_SGE;
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800182 ibp->rvp.n_pkt_drops++;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400183 goto bail_unlock;
184 }
185
186 if (ah_attr->ah_flags & IB_AH_GRH) {
187 hfi1_copy_sge(&qp->r_sge, &ah_attr->grh,
Dean Luick7b0b01a2016-02-03 14:35:49 -0800188 sizeof(struct ib_grh), 1, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400189 wc.wc_flags |= IB_WC_GRH;
Jubin Johne4909742016-02-14 20:22:00 -0800190 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400191 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
Jubin Johne4909742016-02-14 20:22:00 -0800192 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400193 ssge.sg_list = swqe->sg_list + 1;
194 ssge.sge = *swqe->sg_list;
195 ssge.num_sge = swqe->wr.num_sge;
196 sge = &ssge.sge;
197 while (length) {
198 u32 len = sge->length;
199
200 if (len > length)
201 len = length;
202 if (len > sge->sge_length)
203 len = sge->sge_length;
204 WARN_ON_ONCE(len == 0);
Dean Luick7b0b01a2016-02-03 14:35:49 -0800205 hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, 1, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400206 sge->vaddr += len;
207 sge->length -= len;
208 sge->sge_length -= len;
209 if (sge->sge_length == 0) {
210 if (--ssge.num_sge)
211 *sge = *ssge.sg_list++;
212 } else if (sge->length == 0 && sge->mr->lkey) {
Dennis Dalessandrocd4ceee2016-01-19 14:41:55 -0800213 if (++sge->n >= RVT_SEGSZ) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400214 if (++sge->m >= sge->mr->mapsz)
215 break;
216 sge->n = 0;
217 }
218 sge->vaddr =
219 sge->mr->map[sge->m]->segs[sge->n].vaddr;
220 sge->length =
221 sge->mr->map[sge->m]->segs[sge->n].length;
222 }
223 length -= len;
224 }
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800225 rvt_put_ss(&qp->r_sge);
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800226 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400227 goto bail_unlock;
228 wc.wr_id = qp->r_wr_id;
229 wc.status = IB_WC_SUCCESS;
230 wc.opcode = IB_WC_RECV;
231 wc.qp = &qp->ibqp;
232 wc.src_qp = sqp->ibqp.qp_num;
233 if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI) {
234 if (sqp->ibqp.qp_type == IB_QPT_GSI ||
235 sqp->ibqp.qp_type == IB_QPT_SMI)
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100236 wc.pkey_index = swqe->ud_wr.pkey_index;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400237 else
238 wc.pkey_index = sqp->s_pkey_index;
239 } else {
240 wc.pkey_index = 0;
241 }
242 wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1));
243 /* Check for loopback when the port lid is not set */
244 if (wc.slid == 0 && sqp->ibqp.qp_type == IB_QPT_GSI)
Dennis Dalessandro8859b4a2016-01-19 14:42:11 -0800245 wc.slid = be16_to_cpu(IB_LID_PERMISSIVE);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400246 wc.sl = ah_attr->sl;
247 wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1);
248 wc.port_num = qp->port_num;
249 /* Signal completion event if the solicited bit is set. */
Dennis Dalessandroabd712d2016-01-19 14:43:22 -0800250 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
251 swqe->wr.send_flags & IB_SEND_SOLICITED);
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800252 ibp->rvp.n_loop_pkts++;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400253bail_unlock:
254 spin_unlock_irqrestore(&qp->r_lock, flags);
255drop:
256 rcu_read_unlock();
257}
258
259/**
260 * hfi1_make_ud_req - construct a UD request packet
261 * @qp: the QP
262 *
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800263 * Assume s_lock is held.
264 *
Mike Marciniszyn77241052015-07-30 15:17:43 -0400265 * Return 1 if constructed; otherwise, return 0.
266 */
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800267int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400268{
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800269 struct hfi1_qp_priv *priv = qp->priv;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400270 struct hfi1_other_headers *ohdr;
271 struct ib_ah_attr *ah_attr;
272 struct hfi1_pportdata *ppd;
273 struct hfi1_ibport *ibp;
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800274 struct rvt_swqe *wqe;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400275 u32 nwords;
276 u32 extra_bytes;
277 u32 bth0;
278 u16 lrh0;
279 u16 lid;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400280 int next_cur;
281 u8 sc5;
282
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800283 ps->s_txreq = get_txreq(ps->dev, qp);
284 if (IS_ERR(ps->s_txreq))
285 goto bail_no_tx;
286
Dennis Dalessandro83693bd2016-01-19 14:43:33 -0800287 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
288 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400289 goto bail;
290 /* We are in the error state, flush the work request. */
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800291 smp_read_barrier_depends(); /* see post_one_send */
292 if (qp->s_last == ACCESS_ONCE(qp->s_head))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400293 goto bail;
294 /* If DMAs are in progress, we can't flush immediately. */
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800295 if (iowait_sdma_pending(&priv->s_iowait)) {
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800296 qp->s_flags |= RVT_S_WAIT_DMA;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400297 goto bail;
298 }
Dennis Dalessandro83693bd2016-01-19 14:43:33 -0800299 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400300 hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800301 goto done_free_tx;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400302 }
303
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800304 /* see post_one_send() */
305 smp_read_barrier_depends();
306 if (qp->s_cur == ACCESS_ONCE(qp->s_head))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400307 goto bail;
308
Dennis Dalessandro83693bd2016-01-19 14:43:33 -0800309 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400310 next_cur = qp->s_cur + 1;
311 if (next_cur >= qp->s_size)
312 next_cur = 0;
313
314 /* Construct the header. */
315 ibp = to_iport(qp->ibqp.device, qp->port_num);
316 ppd = ppd_from_ibp(ibp);
Dennis Dalessandro15723f02016-01-19 14:42:17 -0800317 ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
Dennis Dalessandro8859b4a2016-01-19 14:42:11 -0800318 if (ah_attr->dlid < be16_to_cpu(IB_MULTICAST_LID_BASE) ||
319 ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400320 lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1);
Jubin John17fb4f22016-02-14 20:21:52 -0800321 if (unlikely(!loopback &&
322 (lid == ppd->lid ||
323 (lid == be16_to_cpu(IB_LID_PERMISSIVE) &&
324 qp->ibqp.qp_type == IB_QPT_GSI)))) {
Mike Marciniszyn747f4d72016-04-12 10:46:10 -0700325 unsigned long tflags = ps->flags;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400326 /*
327 * If DMAs are in progress, we can't generate
328 * a completion for the loopback packet since
329 * it would be out of order.
330 * Instead of waiting, we could queue a
331 * zero length descriptor so we get a callback.
332 */
Mike Marciniszyn14553ca2016-02-14 12:45:36 -0800333 if (iowait_sdma_pending(&priv->s_iowait)) {
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800334 qp->s_flags |= RVT_S_WAIT_DMA;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400335 goto bail;
336 }
337 qp->s_cur = next_cur;
Mike Marciniszyn747f4d72016-04-12 10:46:10 -0700338 spin_unlock_irqrestore(&qp->s_lock, tflags);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400339 ud_loopback(qp, wqe);
Mike Marciniszyn747f4d72016-04-12 10:46:10 -0700340 spin_lock_irqsave(&qp->s_lock, tflags);
341 ps->flags = tflags;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400342 hfi1_send_complete(qp, wqe, IB_WC_SUCCESS);
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800343 goto done_free_tx;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400344 }
345 }
346
347 qp->s_cur = next_cur;
348 extra_bytes = -wqe->length & 3;
349 nwords = (wqe->length + extra_bytes) >> 2;
350
351 /* header size in 32-bit words LRH+BTH+DETH = (8+12+8)/4. */
352 qp->s_hdrwords = 7;
353 qp->s_cur_size = wqe->length;
354 qp->s_cur_sge = &qp->s_sge;
355 qp->s_srate = ah_attr->static_rate;
356 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate);
357 qp->s_wqe = wqe;
358 qp->s_sge.sge = wqe->sg_list[0];
359 qp->s_sge.sg_list = wqe->sg_list + 1;
360 qp->s_sge.num_sge = wqe->wr.num_sge;
361 qp->s_sge.total_len = wqe->length;
362
363 if (ah_attr->ah_flags & IB_AH_GRH) {
364 /* Header size in 32-bit words. */
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800365 qp->s_hdrwords += hfi1_make_grh(ibp,
366 &ps->s_txreq->phdr.hdr.u.l.grh,
367 &ah_attr->grh,
368 qp->s_hdrwords, nwords);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400369 lrh0 = HFI1_LRH_GRH;
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800370 ohdr = &ps->s_txreq->phdr.hdr.u.l.oth;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400371 /*
372 * Don't worry about sending to locally attached multicast
373 * QPs. It is unspecified by the spec. what happens.
374 */
375 } else {
376 /* Header size in 32-bit words. */
377 lrh0 = HFI1_LRH_BTH;
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800378 ohdr = &ps->s_txreq->phdr.hdr.u.oth;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400379 }
380 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
381 qp->s_hdrwords++;
382 ohdr->u.ud.imm_data = wqe->wr.ex.imm_data;
383 bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
Jubin Johne4909742016-02-14 20:22:00 -0800384 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400385 bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
Jubin Johne4909742016-02-14 20:22:00 -0800386 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400387 sc5 = ibp->sl_to_sc[ah_attr->sl];
388 lrh0 |= (ah_attr->sl & 0xf) << 4;
389 if (qp->ibqp.qp_type == IB_QPT_SMI) {
390 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800391 priv->s_sc = 0xf;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400392 } else {
393 lrh0 |= (sc5 & 0xf) << 12;
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800394 priv->s_sc = sc5;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400395 }
Dennis Dalessandro4c6829c2016-01-19 14:42:00 -0800396 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800397 ps->s_txreq->sde = priv->s_sde;
Jubin John721d0422016-02-14 12:45:00 -0800398 priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800399 ps->s_txreq->psc = priv->s_sendcontext;
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800400 ps->s_txreq->phdr.hdr.lrh[0] = cpu_to_be16(lrh0);
401 ps->s_txreq->phdr.hdr.lrh[1] = cpu_to_be16(ah_attr->dlid);
402 ps->s_txreq->phdr.hdr.lrh[2] =
Mike Marciniszyn77241052015-07-30 15:17:43 -0400403 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800404 if (ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
405 ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE;
406 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400407 lid = ppd->lid;
408 if (lid) {
409 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1);
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800410 ps->s_txreq->phdr.hdr.lrh[3] = cpu_to_be16(lid);
411 } else {
412 ps->s_txreq->phdr.hdr.lrh[3] = IB_LID_PERMISSIVE;
413 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400414 }
415 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
416 bth0 |= IB_BTH_SOLICITED;
417 bth0 |= extra_bytes << 20;
418 if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI)
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100419 bth0 |= hfi1_get_pkey(ibp, wqe->ud_wr.pkey_index);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400420 else
421 bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index);
422 ohdr->bth[0] = cpu_to_be32(bth0);
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100423 ohdr->bth[1] = cpu_to_be32(wqe->ud_wr.remote_qpn);
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800424 ohdr->bth[2] = cpu_to_be32(mask_psn(wqe->psn));
Mike Marciniszyn77241052015-07-30 15:17:43 -0400425 /*
426 * Qkeys with the high order bit set mean use the
427 * qkey from the QP context instead of the WR (see 10.2.5).
428 */
Christoph Hellwige622f2f2015-10-08 09:16:33 +0100429 ohdr->u.ud.deth[0] = cpu_to_be32((int)wqe->ud_wr.remote_qkey < 0 ?
430 qp->qkey : wqe->ud_wr.remote_qkey);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400431 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
432 /* disarm any ahg */
Dasaratharaman Chandramoulia9b6b3b2016-07-25 13:40:16 -0700433 priv->s_ahg->ahgcount = 0;
434 priv->s_ahg->ahgidx = 0;
435 priv->s_ahg->tx_flags = 0;
Mike Marciniszyn711e1042016-02-14 12:45:18 -0800436 /* pbc */
437 ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400438
Mike Marciniszyn46a80d62016-02-14 12:10:04 -0800439 return 1;
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800440
441done_free_tx:
442 hfi1_put_txreq(ps->s_txreq);
443 ps->s_txreq = NULL;
444 return 1;
445
Mike Marciniszyn77241052015-07-30 15:17:43 -0400446bail:
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800447 hfi1_put_txreq(ps->s_txreq);
448
449bail_no_tx:
450 ps->s_txreq = NULL;
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800451 qp->s_flags &= ~RVT_S_BUSY;
Dennis Dalessandrobb5df5f2016-02-14 12:44:43 -0800452 qp->s_hdrwords = 0;
453 return 0;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400454}
455
456/*
457 * Hardware can't check this so we do it here.
458 *
459 * This is a slightly different algorithm than the standard pkey check. It
460 * special cases the management keys and allows for 0x7fff and 0xffff to be in
461 * the table at the same time.
462 *
463 * @returns the index found or -1 if not found
464 */
465int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey)
466{
467 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
468 unsigned i;
469
470 if (pkey == FULL_MGMT_P_KEY || pkey == LIM_MGMT_P_KEY) {
471 unsigned lim_idx = -1;
472
473 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) {
474 /* here we look for an exact match */
475 if (ppd->pkeys[i] == pkey)
476 return i;
477 if (ppd->pkeys[i] == LIM_MGMT_P_KEY)
478 lim_idx = i;
479 }
480
481 /* did not find 0xffff return 0x7fff idx if found */
482 if (pkey == FULL_MGMT_P_KEY)
483 return lim_idx;
484
485 /* no match... */
486 return -1;
487 }
488
489 pkey &= 0x7fff; /* remove limited/full membership bit */
490
491 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i)
492 if ((ppd->pkeys[i] & 0x7fff) == pkey)
493 return i;
494
495 /*
496 * Should not get here, this means hardware failed to validate pkeys.
497 */
498 return -1;
499}
500
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800501void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400502 u32 pkey, u32 slid, u32 dlid, u8 sc5,
503 const struct ib_grh *old_grh)
504{
505 u64 pbc, pbc_flags = 0;
506 u32 bth0, plen, vl, hwords = 5;
507 u16 lrh0;
508 u8 sl = ibp->sc_to_sl[sc5];
509 struct hfi1_ib_header hdr;
510 struct hfi1_other_headers *ohdr;
511 struct pio_buf *pbuf;
512 struct send_context *ctxt = qp_to_send_context(qp, sc5);
513 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
514
515 if (old_grh) {
516 struct ib_grh *grh = &hdr.u.l.grh;
517
518 grh->version_tclass_flow = old_grh->version_tclass_flow;
519 grh->paylen = cpu_to_be16((hwords - 2 + SIZE_OF_CRC) << 2);
520 grh->hop_limit = 0xff;
521 grh->sgid = old_grh->dgid;
522 grh->dgid = old_grh->sgid;
523 ohdr = &hdr.u.l.oth;
524 lrh0 = HFI1_LRH_GRH;
525 hwords += sizeof(struct ib_grh) / sizeof(u32);
526 } else {
527 ohdr = &hdr.u.oth;
528 lrh0 = HFI1_LRH_BTH;
529 }
530
531 lrh0 |= (sc5 & 0xf) << 12 | sl << 4;
532
533 bth0 = pkey | (IB_OPCODE_CNP << 24);
534 ohdr->bth[0] = cpu_to_be32(bth0);
535
536 ohdr->bth[1] = cpu_to_be32(remote_qpn | (1 << HFI1_BECN_SHIFT));
537 ohdr->bth[2] = 0; /* PSN 0 */
538
539 hdr.lrh[0] = cpu_to_be16(lrh0);
540 hdr.lrh[1] = cpu_to_be16(dlid);
541 hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC);
542 hdr.lrh[3] = cpu_to_be16(slid);
543
544 plen = 2 /* PBC */ + hwords;
545 pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
546 vl = sc_to_vlt(ppd->dd, sc5);
547 pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
548 if (ctxt) {
549 pbuf = sc_buffer_alloc(ctxt, plen, NULL, NULL);
550 if (pbuf)
551 ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc,
552 &hdr, hwords);
553 }
554}
555
556/*
557 * opa_smp_check() - Do the regular pkey checking, and the additional
558 * checks for SMPs specified in OPAv1 rev 0.90, section 9.10.26
559 * ("SMA Packet Checks").
560 *
561 * Note that:
562 * - Checks are done using the pkey directly from the packet's BTH,
563 * and specifically _not_ the pkey that we attach to the completion,
564 * which may be different.
565 * - These checks are specifically for "non-local" SMPs (i.e., SMPs
566 * which originated on another node). SMPs which are sent from, and
567 * destined to this node are checked in opa_local_smp_check().
568 *
569 * At the point where opa_smp_check() is called, we know:
570 * - destination QP is QP0
571 *
572 * opa_smp_check() returns 0 if all checks succeed, 1 otherwise.
573 */
574static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5,
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800575 struct rvt_qp *qp, u16 slid, struct opa_smp *smp)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400576{
577 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
578
579 /*
580 * I don't think it's possible for us to get here with sc != 0xf,
581 * but check it to be certain.
582 */
583 if (sc5 != 0xf)
584 return 1;
585
586 if (rcv_pkey_check(ppd, pkey, sc5, slid))
587 return 1;
588
589 /*
590 * At this point we know (and so don't need to check again) that
591 * the pkey is either LIM_MGMT_P_KEY, or FULL_MGMT_P_KEY
592 * (see ingress_pkey_check).
593 */
594 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE &&
595 smp->mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED) {
596 ingress_pkey_table_fail(ppd, pkey, slid);
597 return 1;
598 }
599
600 /*
601 * SMPs fall into one of four (disjoint) categories:
602 * SMA request, SMA response, trap, or trap repress.
603 * Our response depends, in part, on which type of
604 * SMP we're processing.
605 *
606 * If this is not an SMA request, or trap repress:
607 * - accept MAD if the port is running an SM
608 * - pkey == FULL_MGMT_P_KEY =>
609 * reply with unsupported method (i.e., just mark
610 * the smp's status field here, and let it be
611 * processed normally)
612 * - pkey != LIM_MGMT_P_KEY =>
613 * increment port recv constraint errors, drop MAD
614 * If this is an SMA request or trap repress:
615 * - pkey != FULL_MGMT_P_KEY =>
616 * increment port recv constraint errors, drop MAD
617 */
618 switch (smp->method) {
619 case IB_MGMT_METHOD_GET:
620 case IB_MGMT_METHOD_SET:
621 case IB_MGMT_METHOD_REPORT:
622 case IB_MGMT_METHOD_TRAP_REPRESS:
623 if (pkey != FULL_MGMT_P_KEY) {
624 ingress_pkey_table_fail(ppd, pkey, slid);
625 return 1;
626 }
627 break;
628 case IB_MGMT_METHOD_SEND:
629 case IB_MGMT_METHOD_TRAP:
630 case IB_MGMT_METHOD_GET_RESP:
631 case IB_MGMT_METHOD_REPORT_RESP:
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800632 if (ibp->rvp.port_cap_flags & IB_PORT_SM)
Mike Marciniszyn77241052015-07-30 15:17:43 -0400633 return 0;
634 if (pkey == FULL_MGMT_P_KEY) {
635 smp->status |= IB_SMP_UNSUP_METHOD;
636 return 0;
637 }
638 if (pkey != LIM_MGMT_P_KEY) {
639 ingress_pkey_table_fail(ppd, pkey, slid);
640 return 1;
641 }
642 break;
643 default:
644 break;
645 }
646 return 0;
647}
648
Mike Marciniszyn77241052015-07-30 15:17:43 -0400649/**
650 * hfi1_ud_rcv - receive an incoming UD packet
651 * @ibp: the port the packet came in on
652 * @hdr: the packet header
653 * @rcv_flags: flags relevant to rcv processing
654 * @data: the packet data
655 * @tlen: the packet length
656 * @qp: the QP the packet came on
657 *
658 * This is called from qp_rcv() to process an incoming UD packet
659 * for the given QP.
660 * Called at interrupt level.
661 */
662void hfi1_ud_rcv(struct hfi1_packet *packet)
663{
664 struct hfi1_other_headers *ohdr = packet->ohdr;
665 int opcode;
666 u32 hdrsize = packet->hlen;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400667 struct ib_wc wc;
668 u32 qkey;
669 u32 src_qp;
670 u16 dlid, pkey;
671 int mgmt_pkey_idx = -1;
672 struct hfi1_ibport *ibp = &packet->rcd->ppd->ibport_data;
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700673 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400674 struct hfi1_ib_header *hdr = packet->hdr;
675 u32 rcv_flags = packet->rcv_flags;
676 void *data = packet->ebuf;
677 u32 tlen = packet->tlen;
Dennis Dalessandro895420d2016-01-19 14:42:28 -0800678 struct rvt_qp *qp = packet->qp;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400679 bool has_grh = rcv_flags & HFI1_HAS_GRH;
Mike Marciniszyn896ce452016-07-01 15:57:02 -0700680 u8 sc5 = hdr2sc((struct hfi1_message_header *)hdr, packet->rhf);
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700681 u32 bth1;
682 u8 sl_from_sc, sl;
683 u16 slid;
684 u8 extra_bytes;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400685
686 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800687 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400688 dlid = be16_to_cpu(hdr->lrh[1]);
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700689 bth1 = be32_to_cpu(ohdr->bth[1]);
690 slid = be16_to_cpu(hdr->lrh[3]);
691 pkey = (u16)be32_to_cpu(ohdr->bth[0]);
692 sl = (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xf;
693 extra_bytes = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
694 extra_bytes += (SIZE_OF_CRC << 2);
695 sl_from_sc = ibp->sc_to_sl[sc5];
Mike Marciniszyn77241052015-07-30 15:17:43 -0400696
Mike Marciniszyn77241052015-07-30 15:17:43 -0400697 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
698 opcode &= 0xff;
699
Mitko Haralanov5fd2b562016-07-25 13:38:07 -0700700 process_ecn(qp, packet, (opcode != IB_OPCODE_CNP));
Mike Marciniszyn77241052015-07-30 15:17:43 -0400701 /*
702 * Get the number of bytes the message was padded by
703 * and drop incomplete packets.
704 */
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700705 if (unlikely(tlen < (hdrsize + extra_bytes)))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400706 goto drop;
707
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700708 tlen -= hdrsize + extra_bytes;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400709
710 /*
711 * Check that the permissive LID is only used on QP0
712 * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
713 */
714 if (qp->ibqp.qp_num) {
715 if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE ||
716 hdr->lrh[3] == IB_LID_PERMISSIVE))
717 goto drop;
718 if (qp->ibqp.qp_num > 1) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400719 if (unlikely(rcv_pkey_check(ppd, pkey, sc5, slid))) {
720 /*
721 * Traps will not be sent for packets dropped
722 * by the HW. This is fine, as sending trap
723 * for invalid pkeys is optional according to
724 * IB spec (release 1.3, section 10.9.4)
725 */
Erik E. Kahn5cd24112015-12-10 09:59:40 -0500726 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY,
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700727 pkey, sl,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400728 src_qp, qp->ibqp.qp_num,
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700729 slid, dlid);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400730 return;
731 }
732 } else {
733 /* GSI packet */
734 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
735 if (mgmt_pkey_idx < 0)
736 goto drop;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400737 }
738 if (unlikely(qkey != qp->qkey)) {
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700739 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey, sl,
Mike Marciniszyn77241052015-07-30 15:17:43 -0400740 src_qp, qp->ibqp.qp_num,
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700741 slid, dlid);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400742 return;
743 }
744 /* Drop invalid MAD packets (see 13.5.3.1). */
745 if (unlikely(qp->ibqp.qp_num == 1 &&
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700746 (tlen > 2048 || (sc5 == 0xF))))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400747 goto drop;
748 } else {
749 /* Received on QP0, and so by definition, this is an SMP */
750 struct opa_smp *smp = (struct opa_smp *)data;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400751
752 if (opa_smp_check(ibp, pkey, sc5, qp, slid, smp))
753 goto drop;
754
755 if (tlen > 2048)
756 goto drop;
757 if ((hdr->lrh[1] == IB_LID_PERMISSIVE ||
758 hdr->lrh[3] == IB_LID_PERMISSIVE) &&
759 smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
760 goto drop;
761
762 /* look up SMI pkey */
763 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
764 if (mgmt_pkey_idx < 0)
765 goto drop;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400766 }
767
768 if (qp->ibqp.qp_num > 1 &&
769 opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
770 wc.ex.imm_data = ohdr->u.ud.imm_data;
771 wc.wc_flags = IB_WC_WITH_IMM;
772 tlen -= sizeof(u32);
773 } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
774 wc.ex.imm_data = 0;
775 wc.wc_flags = 0;
Jubin Johne4909742016-02-14 20:22:00 -0800776 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400777 goto drop;
Jubin Johne4909742016-02-14 20:22:00 -0800778 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400779
780 /*
781 * A GRH is expected to precede the data even if not
782 * present on the wire.
783 */
784 wc.byte_len = tlen + sizeof(struct ib_grh);
785
786 /*
787 * Get the next work request entry to find where to put the data.
788 */
Jubin Johne4909742016-02-14 20:22:00 -0800789 if (qp->r_flags & RVT_R_REUSE_SGE) {
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800790 qp->r_flags &= ~RVT_R_REUSE_SGE;
Jubin Johne4909742016-02-14 20:22:00 -0800791 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400792 int ret;
793
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800794 ret = hfi1_rvt_get_rwqe(qp, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400795 if (ret < 0) {
796 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
797 return;
798 }
799 if (!ret) {
800 if (qp->ibqp.qp_num == 0)
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800801 ibp->rvp.n_vl15_dropped++;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400802 return;
803 }
804 }
805 /* Silently drop packets which are too big. */
806 if (unlikely(wc.byte_len > qp->r_len)) {
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800807 qp->r_flags |= RVT_R_REUSE_SGE;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400808 goto drop;
809 }
810 if (has_grh) {
811 hfi1_copy_sge(&qp->r_sge, &hdr->u.l.grh,
Dean Luick7b0b01a2016-02-03 14:35:49 -0800812 sizeof(struct ib_grh), 1, 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400813 wc.wc_flags |= IB_WC_GRH;
Jubin Johne4909742016-02-14 20:22:00 -0800814 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400815 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
Jubin Johne4909742016-02-14 20:22:00 -0800816 }
Dean Luick7b0b01a2016-02-03 14:35:49 -0800817 hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
818 1, 0);
Dennis Dalessandroec4274f2016-01-19 14:43:44 -0800819 rvt_put_ss(&qp->r_sge);
Dennis Dalessandro54d10c12016-01-19 14:43:01 -0800820 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
Mike Marciniszyn77241052015-07-30 15:17:43 -0400821 return;
822 wc.wr_id = qp->r_wr_id;
823 wc.status = IB_WC_SUCCESS;
824 wc.opcode = IB_WC_RECV;
825 wc.vendor_err = 0;
826 wc.qp = &qp->ibqp;
827 wc.src_qp = src_qp;
828
829 if (qp->ibqp.qp_type == IB_QPT_GSI ||
830 qp->ibqp.qp_type == IB_QPT_SMI) {
831 if (mgmt_pkey_idx < 0) {
832 if (net_ratelimit()) {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400833 struct hfi1_devdata *dd = ppd->dd;
834
835 dd_dev_err(dd, "QP type %d mgmt_pkey_idx < 0 and packet not dropped???\n",
836 qp->ibqp.qp_type);
837 mgmt_pkey_idx = 0;
838 }
839 }
840 wc.pkey_index = (unsigned)mgmt_pkey_idx;
Jubin Johne4909742016-02-14 20:22:00 -0800841 } else {
Mike Marciniszyn77241052015-07-30 15:17:43 -0400842 wc.pkey_index = 0;
Jubin Johne4909742016-02-14 20:22:00 -0800843 }
Mike Marciniszyn77241052015-07-30 15:17:43 -0400844
Dasaratharaman Chandramouli89c057c2016-07-25 13:40:28 -0700845 wc.slid = slid;
846 wc.sl = sl_from_sc;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400847
848 /*
849 * Save the LMC lower bits if the destination LID is a unicast LID.
850 */
Dennis Dalessandro8859b4a2016-01-19 14:42:11 -0800851 wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 :
Mike Marciniszyn77241052015-07-30 15:17:43 -0400852 dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
853 wc.port_num = qp->port_num;
854 /* Signal completion event if the solicited bit is set. */
Dennis Dalessandroabd712d2016-01-19 14:43:22 -0800855 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
856 (ohdr->bth[0] &
857 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
Mike Marciniszyn77241052015-07-30 15:17:43 -0400858 return;
859
860drop:
Dennis Dalessandro4eb06882016-01-19 14:42:39 -0800861 ibp->rvp.n_pkt_drops++;
Mike Marciniszyn77241052015-07-30 15:17:43 -0400862}