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