1f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell/* 2f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved. 3f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved. 4f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 5f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * This software is available to you under a choice of one of two 6f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * licenses. You may choose to be licensed under the terms of the GNU 7f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * General Public License (GPL) Version 2, available from the file 8f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * COPYING in the main directory of this source tree, or the 9f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * OpenIB.org BSD license below: 10f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 11f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Redistribution and use in source and binary forms, with or 12f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * without modification, are permitted provided that the following 13f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * conditions are met: 14f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 15f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * - Redistributions of source code must retain the above 16f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * copyright notice, this list of conditions and the following 17f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * disclaimer. 18f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 19f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * - Redistributions in binary form must reproduce the above 20f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * copyright notice, this list of conditions and the following 21f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * disclaimer in the documentation and/or other materials 22f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * provided with the distribution. 23f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 24f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 28f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 29f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 30f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 31f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * SOFTWARE. 32f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 33f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 34f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell#include <rdma/ib_smi.h> 35f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 36f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell#include "qib.h" 37f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell#include "qib_mad.h" 38f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 39f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell/** 40f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * qib_ud_loopback - handle send on loopback QPs 41f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @sqp: the sending QP 42f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @swqe: the send work request 43f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 44f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * This is called from qib_make_ud_req() to forward a WQE addressed 45f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * to the same HCA. 46f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Note that the receive interrupt handler may be calling qib_ud_rcv() 47f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * while this is being called. 48f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 49f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellstatic void qib_ud_loopback(struct qib_qp *sqp, struct qib_swqe *swqe) 50f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell{ 51f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num); 52f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_pportdata *ppd; 53f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_qp *qp; 54f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct ib_ah_attr *ah_attr; 55f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell unsigned long flags; 56f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_sge_state ssge; 57f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_sge *sge; 58f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct ib_wc wc; 59f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 length; 60f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 61f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp = qib_lookup_qpn(ibp, swqe->wr.wr.ud.remote_qpn); 62f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!qp) { 63f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_pkt_drops++; 64f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell return; 65f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 66f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_type != sqp->ibqp.qp_type || 67f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell !(ib_qib_state_ops[qp->state] & QIB_PROCESS_RECV_OK)) { 68f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_pkt_drops++; 69f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto drop; 70f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 71f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 72f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ah_attr = &to_iah(swqe->wr.wr.ud.ah)->attr; 73f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ppd = ppd_from_ibp(ibp); 74f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 75f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_num > 1) { 76f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 pkey1; 77f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 pkey2; 78f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 lid; 79f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 80f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell pkey1 = qib_get_pkey(ibp, sqp->s_pkey_index); 81f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell pkey2 = qib_get_pkey(ibp, qp->s_pkey_index); 82f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(!qib_pkey_ok(pkey1, pkey2))) { 83f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lid = ppd->lid | (ah_attr->src_path_bits & 84f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ((1 << ppd->lmc) - 1)); 85f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY, pkey1, 86f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ah_attr->sl, 87f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sqp->ibqp.qp_num, qp->ibqp.qp_num, 88f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell cpu_to_be16(lid), 89f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell cpu_to_be16(ah_attr->dlid)); 90f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto drop; 91f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 92f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 93f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 94f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 95f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Check that the qkey matches (except for QP0, see 9.6.1.4.1). 96f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Qkeys with the high order bit set mean use the 97f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * qkey from the QP context instead of the WR (see 10.2.5). 98f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 99f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_num) { 100f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 qkey; 101f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 102f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qkey = (int)swqe->wr.wr.ud.remote_qkey < 0 ? 103f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sqp->qkey : swqe->wr.wr.ud.remote_qkey; 104f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(qkey != qp->qkey)) { 105f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 lid; 106f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 107f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lid = ppd->lid | (ah_attr->src_path_bits & 108f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ((1 << ppd->lmc) - 1)); 109f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_QKEY, qkey, 110f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ah_attr->sl, 111f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sqp->ibqp.qp_num, qp->ibqp.qp_num, 112f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell cpu_to_be16(lid), 113f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell cpu_to_be16(ah_attr->dlid)); 114f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto drop; 115f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 116f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 117f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 118f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 11925985edcedea6396277003854657b5f3cb31a628Lucas De Marchi * A GRH is expected to precede the data even if not 120f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * present on the wire. 121f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 122f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell length = swqe->length; 123f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell memset(&wc, 0, sizeof wc); 124f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.byte_len = length + sizeof(struct ib_grh); 125f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 126f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (swqe->wr.opcode == IB_WR_SEND_WITH_IMM) { 127f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.wc_flags = IB_WC_WITH_IMM; 128f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.ex.imm_data = swqe->wr.ex.imm_data; 129f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 130f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 131f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell spin_lock_irqsave(&qp->r_lock, flags); 132f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 133f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 134f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Get the next work request entry to find where to put the data. 135f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 136f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->r_flags & QIB_R_REUSE_SGE) 137f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->r_flags &= ~QIB_R_REUSE_SGE; 138f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell else { 139f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell int ret; 140f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 141f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ret = qib_get_rwqe(qp, 0); 142f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (ret < 0) { 143f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_rc_error(qp, IB_WC_LOC_QP_OP_ERR); 144f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail_unlock; 145f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 146f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!ret) { 147f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_num == 0) 148f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_vl15_dropped++; 149f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail_unlock; 150f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 151f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 152f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Silently drop packets which are too big. */ 153f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(wc.byte_len > qp->r_len)) { 154f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->r_flags |= QIB_R_REUSE_SGE; 155f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_pkt_drops++; 156f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail_unlock; 157f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 158f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 159f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (ah_attr->ah_flags & IB_AH_GRH) { 160f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_copy_sge(&qp->r_sge, &ah_attr->grh, 161f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sizeof(struct ib_grh), 1); 162f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.wc_flags |= IB_WC_GRH; 163f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else 164f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1); 165f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ssge.sg_list = swqe->sg_list + 1; 166f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ssge.sge = *swqe->sg_list; 167f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ssge.num_sge = swqe->wr.num_sge; 168f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge = &ssge.sge; 169f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell while (length) { 170f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 len = sge->length; 171f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 172f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (len > length) 173f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell len = length; 174f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (len > sge->sge_length) 175f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell len = sge->sge_length; 176f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell BUG_ON(len == 0); 177f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_copy_sge(&qp->r_sge, sge->vaddr, len, 1); 178f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->vaddr += len; 179f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->length -= len; 180f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->sge_length -= len; 181f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (sge->sge_length == 0) { 182f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (--ssge.num_sge) 183f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell *sge = *ssge.sg_list++; 184f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else if (sge->length == 0 && sge->mr->lkey) { 185f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (++sge->n >= QIB_SEGSZ) { 186f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (++sge->m >= sge->mr->mapsz) 187f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell break; 188f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->n = 0; 189f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 190f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->vaddr = 191f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->mr->map[sge->m]->segs[sge->n].vaddr; 192f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->length = 193f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sge->mr->map[sge->m]->segs[sge->n].length; 194f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 195f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell length -= len; 196f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 197f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell while (qp->r_sge.num_sge) { 198f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell atomic_dec(&qp->r_sge.sge.mr->refcount); 199f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (--qp->r_sge.num_sge) 200f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->r_sge.sge = *qp->r_sge.sg_list++; 201f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 202f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) 203f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail_unlock; 204f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.wr_id = qp->r_wr_id; 205f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.status = IB_WC_SUCCESS; 206f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.opcode = IB_WC_RECV; 207f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.qp = &qp->ibqp; 208f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.src_qp = sqp->ibqp.qp_num; 209f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.pkey_index = qp->ibqp.qp_type == IB_QPT_GSI ? 210f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell swqe->wr.wr.ud.pkey_index : 0; 211f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1)); 212f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.sl = ah_attr->sl; 213f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1); 214f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.port_num = qp->port_num; 215f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Signal completion event if the solicited bit is set. */ 216f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 217f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell swqe->wr.send_flags & IB_SEND_SOLICITED); 218f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_loop_pkts++; 219f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellbail_unlock: 220f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell spin_unlock_irqrestore(&qp->r_lock, flags); 221f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbelldrop: 222f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (atomic_dec_and_test(&qp->refcount)) 223f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wake_up(&qp->wait); 224f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell} 225f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 226f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell/** 227f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * qib_make_ud_req - construct a UD request packet 228f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @qp: the QP 229f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 230f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Return 1 if constructed; otherwise, return 0. 231f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 232f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellint qib_make_ud_req(struct qib_qp *qp) 233f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell{ 234f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_other_headers *ohdr; 235f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct ib_ah_attr *ah_attr; 236f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_pportdata *ppd; 237f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_ibport *ibp; 238f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_swqe *wqe; 239f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell unsigned long flags; 240f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 nwords; 241f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 extra_bytes; 242f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 bth0; 243f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 lrh0; 244f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 lid; 245f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell int ret = 0; 246f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell int next_cur; 247f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 248f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 249f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 250f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!(ib_qib_state_ops[qp->state] & QIB_PROCESS_NEXT_SEND_OK)) { 251f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!(ib_qib_state_ops[qp->state] & QIB_FLUSH_SEND)) 252f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail; 253f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* We are in the error state, flush the work request. */ 254f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->s_last == qp->s_head) 255f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail; 256f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* If DMAs are in progress, we can't flush immediately. */ 257f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (atomic_read(&qp->s_dma_busy)) { 258f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_flags |= QIB_S_WAIT_DMA; 259f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail; 260f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 261f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wqe = get_swqe_ptr(qp, qp->s_last); 262f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR); 263f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto done; 264f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 265f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 266f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->s_cur == qp->s_head) 267f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail; 268f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 269f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wqe = get_swqe_ptr(qp, qp->s_cur); 270f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell next_cur = qp->s_cur + 1; 271f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (next_cur >= qp->s_size) 272f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell next_cur = 0; 273f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 274f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Construct the header. */ 275f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp = to_iport(qp->ibqp.device, qp->port_num); 276f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ppd = ppd_from_ibp(ibp); 277f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ah_attr = &to_iah(wqe->wr.wr.ud.ah)->attr; 278f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (ah_attr->dlid >= QIB_MULTICAST_LID_BASE) { 279f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (ah_attr->dlid != QIB_PERMISSIVE_LID) 280f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_multicast_xmit++; 281f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell else 282f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_unicast_xmit++; 283f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else { 284f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_unicast_xmit++; 285f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1); 286f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(lid == ppd->lid)) { 287f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 288f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * If DMAs are in progress, we can't generate 289f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * a completion for the loopback packet since 290f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * it would be out of order. 291f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * XXX Instead of waiting, we could queue a 292f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * zero length descriptor so we get a callback. 293f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 294f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (atomic_read(&qp->s_dma_busy)) { 295f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_flags |= QIB_S_WAIT_DMA; 296f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto bail; 297f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 298f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_cur = next_cur; 299f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 300f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_ud_loopback(qp, wqe); 301f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell spin_lock_irqsave(&qp->s_lock, flags); 302f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_send_complete(qp, wqe, IB_WC_SUCCESS); 303f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto done; 304f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 305f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 306f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 307f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_cur = next_cur; 308f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell extra_bytes = -wqe->length & 3; 309f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell nwords = (wqe->length + extra_bytes) >> 2; 310f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 311f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* header size in 32-bit words LRH+BTH+DETH = (8+12+8)/4. */ 312f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdrwords = 7; 313f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_cur_size = wqe->length; 314f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_cur_sge = &qp->s_sge; 315f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_srate = ah_attr->static_rate; 316f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_wqe = wqe; 317f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_sge.sge = wqe->sg_list[0]; 318f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_sge.sg_list = wqe->sg_list + 1; 319f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_sge.num_sge = wqe->wr.num_sge; 320f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_sge.total_len = wqe->length; 321f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 322f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (ah_attr->ah_flags & IB_AH_GRH) { 323f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Header size in 32-bit words. */ 324f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdrwords += qib_make_grh(ibp, &qp->s_hdr.u.l.grh, 325f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell &ah_attr->grh, 326f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdrwords, nwords); 327f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lrh0 = QIB_LRH_GRH; 328f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr = &qp->s_hdr.u.l.oth; 329f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 330f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Don't worry about sending to locally attached multicast 331f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * QPs. It is unspecified by the spec. what happens. 332f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 333f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else { 334f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Header size in 32-bit words. */ 335f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lrh0 = QIB_LRH_BTH; 336f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr = &qp->s_hdr.u.oth; 337f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 338f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) { 339f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdrwords++; 340f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr->u.ud.imm_data = wqe->wr.ex.imm_data; 341f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24; 342f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else 343f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell bth0 = IB_OPCODE_UD_SEND_ONLY << 24; 344f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lrh0 |= ah_attr->sl << 4; 345f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_type == IB_QPT_SMI) 346f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */ 347f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell else 348f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lrh0 |= ibp->sl_to_vl[ah_attr->sl] << 12; 349f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdr.lrh[0] = cpu_to_be16(lrh0); 350f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdr.lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */ 351f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdr.lrh[2] = cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC); 352f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lid = ppd->lid; 353f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (lid) { 354f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1); 355f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdr.lrh[3] = cpu_to_be16(lid); 356f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else 357f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_hdr.lrh[3] = IB_LID_PERMISSIVE; 358f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (wqe->wr.send_flags & IB_SEND_SOLICITED) 359f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell bth0 |= IB_BTH_SOLICITED; 360f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell bth0 |= extra_bytes << 20; 361f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell bth0 |= qp->ibqp.qp_type == IB_QPT_SMI ? QIB_DEFAULT_P_KEY : 362f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_get_pkey(ibp, qp->ibqp.qp_type == IB_QPT_GSI ? 363f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wqe->wr.wr.ud.pkey_index : qp->s_pkey_index); 364f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr->bth[0] = cpu_to_be32(bth0); 365f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 366f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Use the multicast QP if the destination LID is a multicast LID. 367f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 368f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr->bth[1] = ah_attr->dlid >= QIB_MULTICAST_LID_BASE && 369f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ah_attr->dlid != QIB_PERMISSIVE_LID ? 370f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell cpu_to_be32(QIB_MULTICAST_QPN) : 371f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell cpu_to_be32(wqe->wr.wr.ud.remote_qpn); 372f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr->bth[2] = cpu_to_be32(qp->s_next_psn++ & QIB_PSN_MASK); 373f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 374f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Qkeys with the high order bit set mean use the 375f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * qkey from the QP context instead of the WR (see 10.2.5). 376f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 377f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr->u.ud.deth[0] = cpu_to_be32((int)wqe->wr.wr.ud.remote_qkey < 0 ? 378f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->qkey : wqe->wr.wr.ud.remote_qkey); 379f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num); 380f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 381f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbelldone: 382f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ret = 1; 383f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell goto unlock; 384f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 385f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellbail: 386f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->s_flags &= ~QIB_S_BUSY; 387f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellunlock: 388f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell spin_unlock_irqrestore(&qp->s_lock, flags); 389f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell return ret; 390f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell} 391f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 392f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellstatic unsigned qib_lookup_pkey(struct qib_ibport *ibp, u16 pkey) 393f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell{ 394f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_pportdata *ppd = ppd_from_ibp(ibp); 395f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_devdata *dd = ppd->dd; 396f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell unsigned ctxt = ppd->hw_pidx; 397f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell unsigned i; 398f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 399f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell pkey &= 0x7fff; /* remove limited/full membership bit */ 400f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 401f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell for (i = 0; i < ARRAY_SIZE(dd->rcd[ctxt]->pkeys); ++i) 402f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if ((dd->rcd[ctxt]->pkeys[i] & 0x7fff) == pkey) 403f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell return i; 404f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 405f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 406f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Should not get here, this means hardware failed to validate pkeys. 407f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Punt and return index 0. 408f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 409f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell return 0; 410f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell} 411f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 412f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell/** 413f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * qib_ud_rcv - receive an incoming UD packet 414f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @ibp: the port the packet came in on 415f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @hdr: the packet header 416f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @has_grh: true if the packet has a GRH 417f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @data: the packet data 418f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @tlen: the packet length 419f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * @qp: the QP the packet came on 420f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * 421f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * This is called from qib_qp_rcv() to process an incoming UD packet 422f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * for the given QP. 423f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Called at interrupt level. 424f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 425f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbellvoid qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr, 426f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell int has_grh, void *data, u32 tlen, struct qib_qp *qp) 427f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell{ 428f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct qib_other_headers *ohdr; 429f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell int opcode; 430f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 hdrsize; 431f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 pad; 432f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct ib_wc wc; 433f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 qkey; 434f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u32 src_qp; 435f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 dlid; 436f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 437f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Check for GRH */ 438f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!has_grh) { 439f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr = &hdr->u.oth; 440f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell hdrsize = 8 + 12 + 8; /* LRH + BTH + DETH */ 441f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else { 442f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ohdr = &hdr->u.l.oth; 443f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell hdrsize = 8 + 40 + 12 + 8; /* LRH + GRH + BTH + DETH */ 444f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 445f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qkey = be32_to_cpu(ohdr->u.ud.deth[0]); 446f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & QIB_QPN_MASK; 447f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 448057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn /* 449057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn * Get the number of bytes the message was padded by 450057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn * and drop incomplete packets. 451057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn */ 452f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3; 453057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn if (unlikely(tlen < (hdrsize + pad + 4))) 454057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn goto drop; 455057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn 456f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell tlen -= hdrsize + pad + 4; 457f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 458f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 459f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Check that the permissive LID is only used on QP0 460f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1). 461f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 462f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_num) { 463f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE || 464057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn hdr->lrh[3] == IB_LID_PERMISSIVE)) 465057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn goto drop; 466f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_num > 1) { 467f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell u16 pkey1, pkey2; 468f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 469f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell pkey1 = be32_to_cpu(ohdr->bth[0]); 470f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell pkey2 = qib_get_pkey(ibp, qp->s_pkey_index); 471f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(!qib_pkey_ok(pkey1, pkey2))) { 472f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY, 473f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell pkey1, 474f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell (be16_to_cpu(hdr->lrh[0]) >> 4) & 475f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 0xF, 476f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell src_qp, qp->ibqp.qp_num, 477f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell hdr->lrh[3], hdr->lrh[1]); 478057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn return; 479f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 480f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 481f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(qkey != qp->qkey)) { 482f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_QKEY, qkey, 483f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF, 484f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell src_qp, qp->ibqp.qp_num, 485f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell hdr->lrh[3], hdr->lrh[1]); 486057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn return; 487f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 488f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Drop invalid MAD packets (see 13.5.3.1). */ 489f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(qp->ibqp.qp_num == 1 && 490f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell (tlen != 256 || 491057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn (be16_to_cpu(hdr->lrh[0]) >> 12) == 15))) 492057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn goto drop; 493f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else { 494f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell struct ib_smp *smp; 495f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 496f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Drop invalid MAD packets (see 13.5.3.1). */ 497057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn if (tlen != 256 || (be16_to_cpu(hdr->lrh[0]) >> 12) != 15) 498057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn goto drop; 499f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell smp = (struct ib_smp *) data; 500f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if ((hdr->lrh[1] == IB_LID_PERMISSIVE || 501f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell hdr->lrh[3] == IB_LID_PERMISSIVE) && 502057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE) 503057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn goto drop; 504f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 505f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 506f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 507f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * The opcode is in the low byte when its in network order 508f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * (top byte when in host order). 509f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 510f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell opcode = be32_to_cpu(ohdr->bth[0]) >> 24; 511f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_num > 1 && 512f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) { 513f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.ex.imm_data = ohdr->u.ud.imm_data; 514f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.wc_flags = IB_WC_WITH_IMM; 515c7665e5a6988450a6cc19c2dc1dff4d290077614Mike Marciniszyn tlen -= sizeof(u32); 516f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else if (opcode == IB_OPCODE_UD_SEND_ONLY) { 517f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.ex.imm_data = 0; 518f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.wc_flags = 0; 519057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn } else 520057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn goto drop; 521f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 522f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 52325985edcedea6396277003854657b5f3cb31a628Lucas De Marchi * A GRH is expected to precede the data even if not 524f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * present on the wire. 525f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 526f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.byte_len = tlen + sizeof(struct ib_grh); 527f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 528f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 529f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Get the next work request entry to find where to put the data. 530f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 531f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->r_flags & QIB_R_REUSE_SGE) 532f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->r_flags &= ~QIB_R_REUSE_SGE; 533f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell else { 534f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell int ret; 535f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell 536f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ret = qib_get_rwqe(qp, 0); 537f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (ret < 0) { 538f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_rc_error(qp, IB_WC_LOC_QP_OP_ERR); 539a5210c12b7c4e34e904f4820a4abd048a2d75db5Ralph Campbell return; 540f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 541f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!ret) { 542f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (qp->ibqp.qp_num == 0) 543f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell ibp->n_vl15_dropped++; 544a5210c12b7c4e34e904f4820a4abd048a2d75db5Ralph Campbell return; 545f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 546f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 547f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Silently drop packets which are too big. */ 548f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (unlikely(wc.byte_len > qp->r_len)) { 549f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->r_flags |= QIB_R_REUSE_SGE; 550057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn goto drop; 551f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 552f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (has_grh) { 553f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_copy_sge(&qp->r_sge, &hdr->u.l.grh, 554f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell sizeof(struct ib_grh), 1); 555f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.wc_flags |= IB_WC_GRH; 556f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } else 557f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1); 558f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh), 1); 559f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell while (qp->r_sge.num_sge) { 560f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell atomic_dec(&qp->r_sge.sge.mr->refcount); 561f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (--qp->r_sge.num_sge) 562f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qp->r_sge.sge = *qp->r_sge.sg_list++; 563f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell } 564f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell if (!test_and_clear_bit(QIB_R_WRID_VALID, &qp->r_aflags)) 565a5210c12b7c4e34e904f4820a4abd048a2d75db5Ralph Campbell return; 566f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.wr_id = qp->r_wr_id; 567f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.status = IB_WC_SUCCESS; 568f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.opcode = IB_WC_RECV; 569f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.vendor_err = 0; 570f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.qp = &qp->ibqp; 571f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.src_qp = src_qp; 572f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.pkey_index = qp->ibqp.qp_type == IB_QPT_GSI ? 573f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_lookup_pkey(ibp, be32_to_cpu(ohdr->bth[0])) : 0; 574f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.slid = be16_to_cpu(hdr->lrh[3]); 575f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.sl = (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF; 576f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell dlid = be16_to_cpu(hdr->lrh[1]); 577f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* 578f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell * Save the LMC lower bits if the destination LID is a unicast LID. 579f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell */ 580f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.dlid_path_bits = dlid >= QIB_MULTICAST_LID_BASE ? 0 : 581f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1); 582f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell wc.port_num = qp->port_num; 583f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell /* Signal completion event if the solicited bit is set. */ 584f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell qib_cq_enter(to_icq(qp->ibqp.recv_cq), &wc, 585f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell (ohdr->bth[0] & 586f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell cpu_to_be32(IB_BTH_SOLICITED)) != 0); 587057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn return; 588057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn 589057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyndrop: 590057ae62faceccb50b0c2387af60dbbbcd40aab84Mike Marciniszyn ibp->n_pkt_drops++; 591f931551bafe1f10ded7f5282e2aa162c267a2e5dRalph Campbell} 592