3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2015 Intel Corporation.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
21 * Copyright(c) 2015 Intel Corporation.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51 #include <linux/net.h>
52 #include <rdma/ib_smi.h>
59 * ud_loopback - handle send on loopback QPs
60 * @sqp: the sending QP
61 * @swqe: the send work request
63 * This is called from hfi1_make_ud_req() to forward a WQE addressed
65 * Note that the receive interrupt handler may be calling hfi1_ud_rcv()
66 * while this is being called.
68 static void ud_loopback(struct rvt_qp *sqp, struct rvt_swqe *swqe)
70 struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
71 struct hfi1_pportdata *ppd;
73 struct ib_ah_attr *ah_attr;
75 struct rvt_sge_state ssge;
79 enum ib_qp_type sqptype, dqptype;
83 qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp,
84 swqe->ud_wr.remote_qpn);
86 ibp->rvp.n_pkt_drops++;
91 sqptype = sqp->ibqp.qp_type == IB_QPT_GSI ?
92 IB_QPT_UD : sqp->ibqp.qp_type;
93 dqptype = qp->ibqp.qp_type == IB_QPT_GSI ?
94 IB_QPT_UD : qp->ibqp.qp_type;
96 if (dqptype != sqptype ||
97 !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
98 ibp->rvp.n_pkt_drops++;
102 ah_attr = &ibah_to_rvtah(swqe->ud_wr.ah)->attr;
103 ppd = ppd_from_ibp(ibp);
105 if (qp->ibqp.qp_num > 1) {
108 u8 sc5 = ibp->sl_to_sc[ah_attr->sl];
110 pkey = hfi1_get_pkey(ibp, sqp->s_pkey_index);
111 slid = ppd->lid | (ah_attr->src_path_bits &
112 ((1 << ppd->lmc) - 1));
113 if (unlikely(ingress_pkey_check(ppd, pkey, sc5,
114 qp->s_pkey_index, slid))) {
115 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY, pkey,
117 sqp->ibqp.qp_num, qp->ibqp.qp_num,
118 slid, ah_attr->dlid);
124 * Check that the qkey matches (except for QP0, see 9.6.1.4.1).
125 * Qkeys with the high order bit set mean use the
126 * qkey from the QP context instead of the WR (see 10.2.5).
128 if (qp->ibqp.qp_num) {
131 qkey = (int)swqe->ud_wr.remote_qkey < 0 ?
132 sqp->qkey : swqe->ud_wr.remote_qkey;
133 if (unlikely(qkey != qp->qkey)) {
136 lid = ppd->lid | (ah_attr->src_path_bits &
137 ((1 << ppd->lmc) - 1));
138 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey,
140 sqp->ibqp.qp_num, qp->ibqp.qp_num,
148 * A GRH is expected to precede the data even if not
149 * present on the wire.
151 length = swqe->length;
152 memset(&wc, 0, sizeof(wc));
153 wc.byte_len = length + sizeof(struct ib_grh);
155 if (swqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
156 wc.wc_flags = IB_WC_WITH_IMM;
157 wc.ex.imm_data = swqe->wr.ex.imm_data;
160 spin_lock_irqsave(&qp->r_lock, flags);
163 * Get the next work request entry to find where to put the data.
165 if (qp->r_flags & RVT_R_REUSE_SGE)
166 qp->r_flags &= ~RVT_R_REUSE_SGE;
170 ret = hfi1_rvt_get_rwqe(qp, 0);
172 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
176 if (qp->ibqp.qp_num == 0)
177 ibp->rvp.n_vl15_dropped++;
181 /* Silently drop packets which are too big. */
182 if (unlikely(wc.byte_len > qp->r_len)) {
183 qp->r_flags |= RVT_R_REUSE_SGE;
184 ibp->rvp.n_pkt_drops++;
188 if (ah_attr->ah_flags & IB_AH_GRH) {
189 hfi1_copy_sge(&qp->r_sge, &ah_attr->grh,
190 sizeof(struct ib_grh), 1, 0);
191 wc.wc_flags |= IB_WC_GRH;
193 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
194 ssge.sg_list = swqe->sg_list + 1;
195 ssge.sge = *swqe->sg_list;
196 ssge.num_sge = swqe->wr.num_sge;
199 u32 len = sge->length;
203 if (len > sge->sge_length)
204 len = sge->sge_length;
205 WARN_ON_ONCE(len == 0);
206 hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, 1, 0);
209 sge->sge_length -= len;
210 if (sge->sge_length == 0) {
212 *sge = *ssge.sg_list++;
213 } else if (sge->length == 0 && sge->mr->lkey) {
214 if (++sge->n >= RVT_SEGSZ) {
215 if (++sge->m >= sge->mr->mapsz)
220 sge->mr->map[sge->m]->segs[sge->n].vaddr;
222 sge->mr->map[sge->m]->segs[sge->n].length;
226 rvt_put_ss(&qp->r_sge);
227 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
229 wc.wr_id = qp->r_wr_id;
230 wc.status = IB_WC_SUCCESS;
231 wc.opcode = IB_WC_RECV;
233 wc.src_qp = sqp->ibqp.qp_num;
234 if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI) {
235 if (sqp->ibqp.qp_type == IB_QPT_GSI ||
236 sqp->ibqp.qp_type == IB_QPT_SMI)
237 wc.pkey_index = swqe->ud_wr.pkey_index;
239 wc.pkey_index = sqp->s_pkey_index;
243 wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1));
244 /* Check for loopback when the port lid is not set */
245 if (wc.slid == 0 && sqp->ibqp.qp_type == IB_QPT_GSI)
246 wc.slid = be16_to_cpu(IB_LID_PERMISSIVE);
248 wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1);
249 wc.port_num = qp->port_num;
250 /* Signal completion event if the solicited bit is set. */
251 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
252 swqe->wr.send_flags & IB_SEND_SOLICITED);
253 ibp->rvp.n_loop_pkts++;
255 spin_unlock_irqrestore(&qp->r_lock, flags);
261 * hfi1_make_ud_req - construct a UD request packet
264 * Assume s_lock is held.
266 * Return 1 if constructed; otherwise, return 0.
268 int hfi1_make_ud_req(struct rvt_qp *qp)
270 struct hfi1_qp_priv *priv = qp->priv;
271 struct hfi1_other_headers *ohdr;
272 struct ib_ah_attr *ah_attr;
273 struct hfi1_pportdata *ppd;
274 struct hfi1_ibport *ibp;
275 struct rvt_swqe *wqe;
285 if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
286 if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
288 /* We are in the error state, flush the work request. */
289 smp_read_barrier_depends(); /* see post_one_send */
290 if (qp->s_last == ACCESS_ONCE(qp->s_head))
292 /* If DMAs are in progress, we can't flush immediately. */
293 if (atomic_read(&priv->s_iowait.sdma_busy)) {
294 qp->s_flags |= RVT_S_WAIT_DMA;
297 wqe = rvt_get_swqe_ptr(qp, qp->s_last);
298 hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
302 /* see post_one_send() */
303 smp_read_barrier_depends();
304 if (qp->s_cur == ACCESS_ONCE(qp->s_head))
307 wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
308 next_cur = qp->s_cur + 1;
309 if (next_cur >= qp->s_size)
312 /* Construct the header. */
313 ibp = to_iport(qp->ibqp.device, qp->port_num);
314 ppd = ppd_from_ibp(ibp);
315 ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
316 if (ah_attr->dlid < be16_to_cpu(IB_MULTICAST_LID_BASE) ||
317 ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
318 lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1);
319 if (unlikely(!loopback && (lid == ppd->lid ||
320 (lid == be16_to_cpu(IB_LID_PERMISSIVE) &&
321 qp->ibqp.qp_type == IB_QPT_GSI)))) {
324 * If DMAs are in progress, we can't generate
325 * a completion for the loopback packet since
326 * it would be out of order.
327 * Instead of waiting, we could queue a
328 * zero length descriptor so we get a callback.
330 if (atomic_read(&priv->s_iowait.sdma_busy)) {
331 qp->s_flags |= RVT_S_WAIT_DMA;
334 qp->s_cur = next_cur;
335 local_irq_save(flags);
336 spin_unlock_irqrestore(&qp->s_lock, flags);
337 ud_loopback(qp, wqe);
338 spin_lock_irqsave(&qp->s_lock, flags);
339 hfi1_send_complete(qp, wqe, IB_WC_SUCCESS);
344 qp->s_cur = next_cur;
345 extra_bytes = -wqe->length & 3;
346 nwords = (wqe->length + extra_bytes) >> 2;
348 /* header size in 32-bit words LRH+BTH+DETH = (8+12+8)/4. */
350 qp->s_cur_size = wqe->length;
351 qp->s_cur_sge = &qp->s_sge;
352 qp->s_srate = ah_attr->static_rate;
353 qp->srate_mbps = ib_rate_to_mbps(qp->s_srate);
355 qp->s_sge.sge = wqe->sg_list[0];
356 qp->s_sge.sg_list = wqe->sg_list + 1;
357 qp->s_sge.num_sge = wqe->wr.num_sge;
358 qp->s_sge.total_len = wqe->length;
360 if (ah_attr->ah_flags & IB_AH_GRH) {
361 /* Header size in 32-bit words. */
362 qp->s_hdrwords += hfi1_make_grh(ibp, &priv->s_hdr->ibh.u.l.grh,
364 qp->s_hdrwords, nwords);
366 ohdr = &priv->s_hdr->ibh.u.l.oth;
368 * Don't worry about sending to locally attached multicast
369 * QPs. It is unspecified by the spec. what happens.
372 /* Header size in 32-bit words. */
374 ohdr = &priv->s_hdr->ibh.u.oth;
376 if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
378 ohdr->u.ud.imm_data = wqe->wr.ex.imm_data;
379 bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
381 bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
382 sc5 = ibp->sl_to_sc[ah_attr->sl];
383 lrh0 |= (ah_attr->sl & 0xf) << 4;
384 if (qp->ibqp.qp_type == IB_QPT_SMI) {
385 lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
388 lrh0 |= (sc5 & 0xf) << 12;
391 priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
392 priv->s_hdr->ibh.lrh[0] = cpu_to_be16(lrh0);
393 priv->s_hdr->ibh.lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */
394 priv->s_hdr->ibh.lrh[2] =
395 cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
396 if (ah_attr->dlid == be16_to_cpu(IB_LID_PERMISSIVE))
397 priv->s_hdr->ibh.lrh[3] = IB_LID_PERMISSIVE;
401 lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1);
402 priv->s_hdr->ibh.lrh[3] = cpu_to_be16(lid);
404 priv->s_hdr->ibh.lrh[3] = IB_LID_PERMISSIVE;
406 if (wqe->wr.send_flags & IB_SEND_SOLICITED)
407 bth0 |= IB_BTH_SOLICITED;
408 bth0 |= extra_bytes << 20;
409 if (qp->ibqp.qp_type == IB_QPT_GSI || qp->ibqp.qp_type == IB_QPT_SMI)
410 bth0 |= hfi1_get_pkey(ibp, wqe->ud_wr.pkey_index);
412 bth0 |= hfi1_get_pkey(ibp, qp->s_pkey_index);
413 ohdr->bth[0] = cpu_to_be32(bth0);
414 ohdr->bth[1] = cpu_to_be32(wqe->ud_wr.remote_qpn);
415 ohdr->bth[2] = cpu_to_be32(mask_psn(wqe->psn));
417 * Qkeys with the high order bit set mean use the
418 * qkey from the QP context instead of the WR (see 10.2.5).
420 ohdr->u.ud.deth[0] = cpu_to_be32((int)wqe->ud_wr.remote_qkey < 0 ?
421 qp->qkey : wqe->ud_wr.remote_qkey);
422 ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
424 priv->s_hdr->ahgcount = 0;
425 priv->s_hdr->ahgidx = 0;
426 priv->s_hdr->tx_flags = 0;
427 priv->s_hdr->sde = NULL;
432 qp->s_flags &= ~RVT_S_BUSY;
437 * Hardware can't check this so we do it here.
439 * This is a slightly different algorithm than the standard pkey check. It
440 * special cases the management keys and allows for 0x7fff and 0xffff to be in
441 * the table at the same time.
443 * @returns the index found or -1 if not found
445 int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey)
447 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
450 if (pkey == FULL_MGMT_P_KEY || pkey == LIM_MGMT_P_KEY) {
451 unsigned lim_idx = -1;
453 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) {
454 /* here we look for an exact match */
455 if (ppd->pkeys[i] == pkey)
457 if (ppd->pkeys[i] == LIM_MGMT_P_KEY)
461 /* did not find 0xffff return 0x7fff idx if found */
462 if (pkey == FULL_MGMT_P_KEY)
469 pkey &= 0x7fff; /* remove limited/full membership bit */
471 for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i)
472 if ((ppd->pkeys[i] & 0x7fff) == pkey)
476 * Should not get here, this means hardware failed to validate pkeys.
481 void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
482 u32 pkey, u32 slid, u32 dlid, u8 sc5,
483 const struct ib_grh *old_grh)
485 u64 pbc, pbc_flags = 0;
486 u32 bth0, plen, vl, hwords = 5;
488 u8 sl = ibp->sc_to_sl[sc5];
489 struct hfi1_ib_header hdr;
490 struct hfi1_other_headers *ohdr;
491 struct pio_buf *pbuf;
492 struct send_context *ctxt = qp_to_send_context(qp, sc5);
493 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
496 struct ib_grh *grh = &hdr.u.l.grh;
498 grh->version_tclass_flow = old_grh->version_tclass_flow;
499 grh->paylen = cpu_to_be16((hwords - 2 + SIZE_OF_CRC) << 2);
500 grh->hop_limit = 0xff;
501 grh->sgid = old_grh->dgid;
502 grh->dgid = old_grh->sgid;
505 hwords += sizeof(struct ib_grh) / sizeof(u32);
511 lrh0 |= (sc5 & 0xf) << 12 | sl << 4;
513 bth0 = pkey | (IB_OPCODE_CNP << 24);
514 ohdr->bth[0] = cpu_to_be32(bth0);
516 ohdr->bth[1] = cpu_to_be32(remote_qpn | (1 << HFI1_BECN_SHIFT));
517 ohdr->bth[2] = 0; /* PSN 0 */
519 hdr.lrh[0] = cpu_to_be16(lrh0);
520 hdr.lrh[1] = cpu_to_be16(dlid);
521 hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC);
522 hdr.lrh[3] = cpu_to_be16(slid);
524 plen = 2 /* PBC */ + hwords;
525 pbc_flags |= (!!(sc5 & 0x10)) << PBC_DC_INFO_SHIFT;
526 vl = sc_to_vlt(ppd->dd, sc5);
527 pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
529 pbuf = sc_buffer_alloc(ctxt, plen, NULL, NULL);
531 ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc,
537 * opa_smp_check() - Do the regular pkey checking, and the additional
538 * checks for SMPs specified in OPAv1 rev 0.90, section 9.10.26
539 * ("SMA Packet Checks").
542 * - Checks are done using the pkey directly from the packet's BTH,
543 * and specifically _not_ the pkey that we attach to the completion,
544 * which may be different.
545 * - These checks are specifically for "non-local" SMPs (i.e., SMPs
546 * which originated on another node). SMPs which are sent from, and
547 * destined to this node are checked in opa_local_smp_check().
549 * At the point where opa_smp_check() is called, we know:
550 * - destination QP is QP0
552 * opa_smp_check() returns 0 if all checks succeed, 1 otherwise.
554 static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5,
555 struct rvt_qp *qp, u16 slid, struct opa_smp *smp)
557 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
560 * I don't think it's possible for us to get here with sc != 0xf,
561 * but check it to be certain.
566 if (rcv_pkey_check(ppd, pkey, sc5, slid))
570 * At this point we know (and so don't need to check again) that
571 * the pkey is either LIM_MGMT_P_KEY, or FULL_MGMT_P_KEY
572 * (see ingress_pkey_check).
574 if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE &&
575 smp->mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED) {
576 ingress_pkey_table_fail(ppd, pkey, slid);
581 * SMPs fall into one of four (disjoint) categories:
582 * SMA request, SMA response, trap, or trap repress.
583 * Our response depends, in part, on which type of
584 * SMP we're processing.
586 * If this is not an SMA request, or trap repress:
587 * - accept MAD if the port is running an SM
588 * - pkey == FULL_MGMT_P_KEY =>
589 * reply with unsupported method (i.e., just mark
590 * the smp's status field here, and let it be
591 * processed normally)
592 * - pkey != LIM_MGMT_P_KEY =>
593 * increment port recv constraint errors, drop MAD
594 * If this is an SMA request or trap repress:
595 * - pkey != FULL_MGMT_P_KEY =>
596 * increment port recv constraint errors, drop MAD
598 switch (smp->method) {
599 case IB_MGMT_METHOD_GET:
600 case IB_MGMT_METHOD_SET:
601 case IB_MGMT_METHOD_REPORT:
602 case IB_MGMT_METHOD_TRAP_REPRESS:
603 if (pkey != FULL_MGMT_P_KEY) {
604 ingress_pkey_table_fail(ppd, pkey, slid);
608 case IB_MGMT_METHOD_SEND:
609 case IB_MGMT_METHOD_TRAP:
610 case IB_MGMT_METHOD_GET_RESP:
611 case IB_MGMT_METHOD_REPORT_RESP:
612 if (ibp->rvp.port_cap_flags & IB_PORT_SM)
614 if (pkey == FULL_MGMT_P_KEY) {
615 smp->status |= IB_SMP_UNSUP_METHOD;
618 if (pkey != LIM_MGMT_P_KEY) {
619 ingress_pkey_table_fail(ppd, pkey, slid);
631 * hfi1_ud_rcv - receive an incoming UD packet
632 * @ibp: the port the packet came in on
633 * @hdr: the packet header
634 * @rcv_flags: flags relevant to rcv processing
635 * @data: the packet data
636 * @tlen: the packet length
637 * @qp: the QP the packet came on
639 * This is called from qp_rcv() to process an incoming UD packet
641 * Called at interrupt level.
643 void hfi1_ud_rcv(struct hfi1_packet *packet)
645 struct hfi1_other_headers *ohdr = packet->ohdr;
647 u32 hdrsize = packet->hlen;
653 int mgmt_pkey_idx = -1;
654 struct hfi1_ibport *ibp = &packet->rcd->ppd->ibport_data;
655 struct hfi1_ib_header *hdr = packet->hdr;
656 u32 rcv_flags = packet->rcv_flags;
657 void *data = packet->ebuf;
658 u32 tlen = packet->tlen;
659 struct rvt_qp *qp = packet->qp;
660 bool has_grh = rcv_flags & HFI1_HAS_GRH;
661 bool sc4_bit = has_sc4_bit(packet);
665 struct ib_grh *grh = NULL;
667 qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
668 src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
669 dlid = be16_to_cpu(hdr->lrh[1]);
670 is_mcast = (dlid > be16_to_cpu(IB_MULTICAST_LID_BASE)) &&
671 (dlid != be16_to_cpu(IB_LID_PERMISSIVE));
672 bth1 = be32_to_cpu(ohdr->bth[1]);
673 if (unlikely(bth1 & HFI1_BECN_SMASK)) {
675 * In pre-B0 h/w the CNP_OPCODE is handled via an
678 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
679 u32 lqpn = be32_to_cpu(ohdr->bth[1]) & RVT_QPN_MASK;
682 sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf;
684 sl = ibp->sc_to_sl[sc5];
686 process_becn(ppd, sl, 0, lqpn, 0, IB_CC_SVCTYPE_UD);
690 * The opcode is in the low byte when its in network order
691 * (top byte when in host order).
693 opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
696 pkey = (u16)be32_to_cpu(ohdr->bth[0]);
698 if (!is_mcast && (opcode != IB_OPCODE_CNP) && bth1 & HFI1_FECN_SMASK) {
699 u16 slid = be16_to_cpu(hdr->lrh[3]);
702 sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf;
705 return_cnp(ibp, qp, src_qp, pkey, dlid, slid, sc5, grh);
708 * Get the number of bytes the message was padded by
709 * and drop incomplete packets.
711 pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
712 if (unlikely(tlen < (hdrsize + pad + 4)))
715 tlen -= hdrsize + pad + 4;
718 * Check that the permissive LID is only used on QP0
719 * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
721 if (qp->ibqp.qp_num) {
722 if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE ||
723 hdr->lrh[3] == IB_LID_PERMISSIVE))
725 if (qp->ibqp.qp_num > 1) {
726 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
730 sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf;
733 slid = be16_to_cpu(hdr->lrh[3]);
734 if (unlikely(rcv_pkey_check(ppd, pkey, sc5, slid))) {
736 * Traps will not be sent for packets dropped
737 * by the HW. This is fine, as sending trap
738 * for invalid pkeys is optional according to
739 * IB spec (release 1.3, section 10.9.4)
741 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_P_KEY,
743 (be16_to_cpu(hdr->lrh[0]) >> 4) &
745 src_qp, qp->ibqp.qp_num,
746 be16_to_cpu(hdr->lrh[3]),
747 be16_to_cpu(hdr->lrh[1]));
752 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
753 if (mgmt_pkey_idx < 0)
757 if (unlikely(qkey != qp->qkey)) {
758 hfi1_bad_pqkey(ibp, OPA_TRAP_BAD_Q_KEY, qkey,
759 (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF,
760 src_qp, qp->ibqp.qp_num,
761 be16_to_cpu(hdr->lrh[3]),
762 be16_to_cpu(hdr->lrh[1]));
765 /* Drop invalid MAD packets (see 13.5.3.1). */
766 if (unlikely(qp->ibqp.qp_num == 1 &&
768 (be16_to_cpu(hdr->lrh[0]) >> 12) == 15)))
771 /* Received on QP0, and so by definition, this is an SMP */
772 struct opa_smp *smp = (struct opa_smp *)data;
773 u16 slid = be16_to_cpu(hdr->lrh[3]);
776 sc5 = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf;
779 if (opa_smp_check(ibp, pkey, sc5, qp, slid, smp))
784 if ((hdr->lrh[1] == IB_LID_PERMISSIVE ||
785 hdr->lrh[3] == IB_LID_PERMISSIVE) &&
786 smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
789 /* look up SMI pkey */
790 mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
791 if (mgmt_pkey_idx < 0)
796 if (qp->ibqp.qp_num > 1 &&
797 opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
798 wc.ex.imm_data = ohdr->u.ud.imm_data;
799 wc.wc_flags = IB_WC_WITH_IMM;
801 } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
808 * A GRH is expected to precede the data even if not
809 * present on the wire.
811 wc.byte_len = tlen + sizeof(struct ib_grh);
814 * Get the next work request entry to find where to put the data.
816 if (qp->r_flags & RVT_R_REUSE_SGE)
817 qp->r_flags &= ~RVT_R_REUSE_SGE;
821 ret = hfi1_rvt_get_rwqe(qp, 0);
823 hfi1_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
827 if (qp->ibqp.qp_num == 0)
828 ibp->rvp.n_vl15_dropped++;
832 /* Silently drop packets which are too big. */
833 if (unlikely(wc.byte_len > qp->r_len)) {
834 qp->r_flags |= RVT_R_REUSE_SGE;
838 hfi1_copy_sge(&qp->r_sge, &hdr->u.l.grh,
839 sizeof(struct ib_grh), 1, 0);
840 wc.wc_flags |= IB_WC_GRH;
842 hfi1_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
843 hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
845 rvt_put_ss(&qp->r_sge);
846 if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
848 wc.wr_id = qp->r_wr_id;
849 wc.status = IB_WC_SUCCESS;
850 wc.opcode = IB_WC_RECV;
855 if (qp->ibqp.qp_type == IB_QPT_GSI ||
856 qp->ibqp.qp_type == IB_QPT_SMI) {
857 if (mgmt_pkey_idx < 0) {
858 if (net_ratelimit()) {
859 struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
860 struct hfi1_devdata *dd = ppd->dd;
862 dd_dev_err(dd, "QP type %d mgmt_pkey_idx < 0 and packet not dropped???\n",
867 wc.pkey_index = (unsigned)mgmt_pkey_idx;
871 wc.slid = be16_to_cpu(hdr->lrh[3]);
872 sc = (be16_to_cpu(hdr->lrh[0]) >> 12) & 0xf;
874 wc.sl = ibp->sc_to_sl[sc];
877 * Save the LMC lower bits if the destination LID is a unicast LID.
879 wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 :
880 dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
881 wc.port_num = qp->port_num;
882 /* Signal completion event if the solicited bit is set. */
883 rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
885 cpu_to_be32(IB_BTH_SOLICITED)) != 0);
889 ibp->rvp.n_pkt_drops++;