ud.c 30 KB

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