ud.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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. qp->s_hdrwords = 7;
  315. if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
  316. qp->s_hdrwords++;
  317. if (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) {
  318. grh = &ps->s_txreq->phdr.hdr.ibh.u.l.grh;
  319. qp->s_hdrwords += hfi1_make_grh(ibp, grh,
  320. rdma_ah_read_grh(ah_attr),
  321. qp->s_hdrwords - 2, nwords);
  322. lrh0 = HFI1_LRH_GRH;
  323. ohdr = &ps->s_txreq->phdr.hdr.ibh.u.l.oth;
  324. } else {
  325. lrh0 = HFI1_LRH_BTH;
  326. ohdr = &ps->s_txreq->phdr.hdr.ibh.u.oth;
  327. }
  328. sc5 = ibp->sl_to_sc[rdma_ah_get_sl(ah_attr)];
  329. lrh0 |= (rdma_ah_get_sl(ah_attr) & 0xf) << 4;
  330. if (qp->ibqp.qp_type == IB_QPT_SMI) {
  331. lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
  332. priv->s_sc = 0xf;
  333. } else {
  334. lrh0 |= (sc5 & 0xf) << 12;
  335. priv->s_sc = sc5;
  336. }
  337. dlid = opa_get_lid(rdma_ah_get_dlid(ah_attr), 9B);
  338. if (dlid == be16_to_cpu(IB_LID_PERMISSIVE)) {
  339. slid = be16_to_cpu(IB_LID_PERMISSIVE);
  340. } else {
  341. u16 lid = (u16)ppd->lid;
  342. if (lid) {
  343. lid |= rdma_ah_get_path_bits(ah_attr) &
  344. ((1 << ppd->lmc) - 1);
  345. slid = lid;
  346. } else {
  347. slid = be16_to_cpu(IB_LID_PERMISSIVE);
  348. }
  349. }
  350. hfi1_make_bth_deth(qp, wqe, ohdr, &pkey, extra_bytes, false);
  351. len = qp->s_hdrwords + nwords;
  352. /* Setup the packet */
  353. ps->s_txreq->phdr.hdr.hdr_type = HFI1_PKT_TYPE_9B;
  354. hfi1_make_ib_hdr(&ps->s_txreq->phdr.hdr.ibh,
  355. lrh0, len, dlid, slid);
  356. }
  357. void hfi1_make_ud_req_16B(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  358. struct rvt_swqe *wqe)
  359. {
  360. struct hfi1_qp_priv *priv = qp->priv;
  361. struct ib_other_headers *ohdr;
  362. struct rdma_ah_attr *ah_attr;
  363. struct hfi1_pportdata *ppd;
  364. struct hfi1_ibport *ibp;
  365. u32 dlid, slid, nwords, extra_bytes;
  366. u16 len, pkey;
  367. u8 l4, sc5;
  368. ibp = to_iport(qp->ibqp.device, qp->port_num);
  369. ppd = ppd_from_ibp(ibp);
  370. ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
  371. /* header size in dwords 16B LRH+BTH+DETH = (16+12+8)/4. */
  372. qp->s_hdrwords = 9;
  373. if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
  374. qp->s_hdrwords++;
  375. /* SW provides space for CRC and LT for bypass packets. */
  376. extra_bytes = hfi1_get_16b_padding((qp->s_hdrwords << 2),
  377. wqe->length);
  378. nwords = ((wqe->length + extra_bytes + SIZE_OF_LT) >> 2) + SIZE_OF_CRC;
  379. if ((rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) &&
  380. hfi1_check_mcast(rdma_ah_get_dlid(ah_attr))) {
  381. struct ib_grh *grh;
  382. struct ib_global_route *grd = rdma_ah_retrieve_grh(ah_attr);
  383. /*
  384. * Ensure OPA GIDs are transformed to IB gids
  385. * before creating the GRH.
  386. */
  387. if (grd->sgid_index == OPA_GID_INDEX) {
  388. dd_dev_warn(ppd->dd, "Bad sgid_index. sgid_index: %d\n",
  389. grd->sgid_index);
  390. grd->sgid_index = 0;
  391. }
  392. grh = &ps->s_txreq->phdr.hdr.opah.u.l.grh;
  393. qp->s_hdrwords += hfi1_make_grh(ibp, grh, grd,
  394. qp->s_hdrwords - 4, nwords);
  395. ohdr = &ps->s_txreq->phdr.hdr.opah.u.l.oth;
  396. l4 = OPA_16B_L4_IB_GLOBAL;
  397. } else {
  398. ohdr = &ps->s_txreq->phdr.hdr.opah.u.oth;
  399. l4 = OPA_16B_L4_IB_LOCAL;
  400. }
  401. sc5 = ibp->sl_to_sc[rdma_ah_get_sl(ah_attr)];
  402. if (qp->ibqp.qp_type == IB_QPT_SMI)
  403. priv->s_sc = 0xf;
  404. else
  405. priv->s_sc = sc5;
  406. dlid = opa_get_lid(rdma_ah_get_dlid(ah_attr), 16B);
  407. if (!ppd->lid)
  408. slid = be32_to_cpu(OPA_LID_PERMISSIVE);
  409. else
  410. slid = ppd->lid | (rdma_ah_get_path_bits(ah_attr) &
  411. ((1 << ppd->lmc) - 1));
  412. hfi1_make_bth_deth(qp, wqe, ohdr, &pkey, extra_bytes, true);
  413. /* Convert dwords to flits */
  414. len = (qp->s_hdrwords + nwords) >> 1;
  415. /* Setup the packet */
  416. ps->s_txreq->phdr.hdr.hdr_type = HFI1_PKT_TYPE_16B;
  417. hfi1_make_16b_hdr(&ps->s_txreq->phdr.hdr.opah,
  418. slid, dlid, len, pkey, 0, 0, l4, priv->s_sc);
  419. }
  420. /**
  421. * hfi1_make_ud_req - construct a UD request packet
  422. * @qp: the QP
  423. *
  424. * Assume s_lock is held.
  425. *
  426. * Return 1 if constructed; otherwise, return 0.
  427. */
  428. int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
  429. {
  430. struct hfi1_qp_priv *priv = qp->priv;
  431. struct rdma_ah_attr *ah_attr;
  432. struct hfi1_pportdata *ppd;
  433. struct hfi1_ibport *ibp;
  434. struct rvt_swqe *wqe;
  435. int next_cur;
  436. u32 lid;
  437. ps->s_txreq = get_txreq(ps->dev, qp);
  438. if (IS_ERR(ps->s_txreq))
  439. goto bail_no_tx;
  440. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
  441. if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
  442. goto bail;
  443. /* We are in the error state, flush the work request. */
  444. smp_read_barrier_depends(); /* see post_one_send */
  445. if (qp->s_last == READ_ONCE(qp->s_head))
  446. goto bail;
  447. /* If DMAs are in progress, we can't flush immediately. */
  448. if (iowait_sdma_pending(&priv->s_iowait)) {
  449. qp->s_flags |= RVT_S_WAIT_DMA;
  450. goto bail;
  451. }
  452. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  453. hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
  454. goto done_free_tx;
  455. }
  456. /* see post_one_send() */
  457. smp_read_barrier_depends();
  458. if (qp->s_cur == READ_ONCE(qp->s_head))
  459. goto bail;
  460. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  461. next_cur = qp->s_cur + 1;
  462. if (next_cur >= qp->s_size)
  463. next_cur = 0;
  464. /* Construct the header. */
  465. ibp = to_iport(qp->ibqp.device, qp->port_num);
  466. ppd = ppd_from_ibp(ibp);
  467. ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
  468. priv->hdr_type = hfi1_get_hdr_type(ppd->lid, ah_attr);
  469. if ((!hfi1_check_mcast(rdma_ah_get_dlid(ah_attr))) ||
  470. (rdma_ah_get_dlid(ah_attr) == be32_to_cpu(OPA_LID_PERMISSIVE))) {
  471. lid = rdma_ah_get_dlid(ah_attr) & ~((1 << ppd->lmc) - 1);
  472. if (unlikely(!loopback &&
  473. ((lid == ppd->lid) ||
  474. ((lid == be32_to_cpu(OPA_LID_PERMISSIVE)) &&
  475. (qp->ibqp.qp_type == IB_QPT_GSI))))) {
  476. unsigned long tflags = ps->flags;
  477. /*
  478. * If DMAs are in progress, we can't generate
  479. * a completion for the loopback packet since
  480. * it would be out of order.
  481. * Instead of waiting, we could queue a
  482. * zero length descriptor so we get a callback.
  483. */
  484. if (iowait_sdma_pending(&priv->s_iowait)) {
  485. qp->s_flags |= RVT_S_WAIT_DMA;
  486. goto bail;
  487. }
  488. qp->s_cur = next_cur;
  489. spin_unlock_irqrestore(&qp->s_lock, tflags);
  490. ud_loopback(qp, wqe);
  491. spin_lock_irqsave(&qp->s_lock, tflags);
  492. ps->flags = tflags;
  493. hfi1_send_complete(qp, wqe, IB_WC_SUCCESS);
  494. goto done_free_tx;
  495. }
  496. }
  497. qp->s_cur = next_cur;
  498. ps->s_txreq->s_cur_size = wqe->length;
  499. ps->s_txreq->ss = &qp->s_sge;
  500. qp->s_srate = rdma_ah_get_static_rate(ah_attr);
  501. qp->srate_mbps = ib_rate_to_mbps(qp->s_srate);
  502. qp->s_wqe = wqe;
  503. qp->s_sge.sge = wqe->sg_list[0];
  504. qp->s_sge.sg_list = wqe->sg_list + 1;
  505. qp->s_sge.num_sge = wqe->wr.num_sge;
  506. qp->s_sge.total_len = wqe->length;
  507. /* Make the appropriate header */
  508. hfi1_make_ud_req_tbl[priv->hdr_type](qp, ps, qp->s_wqe);
  509. priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
  510. ps->s_txreq->sde = priv->s_sde;
  511. priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
  512. ps->s_txreq->psc = priv->s_sendcontext;
  513. /* disarm any ahg */
  514. priv->s_ahg->ahgcount = 0;
  515. priv->s_ahg->ahgidx = 0;
  516. priv->s_ahg->tx_flags = 0;
  517. /* pbc */
  518. ps->s_txreq->hdr_dwords = qp->s_hdrwords + 2;
  519. return 1;
  520. done_free_tx:
  521. hfi1_put_txreq(ps->s_txreq);
  522. ps->s_txreq = NULL;
  523. return 1;
  524. bail:
  525. hfi1_put_txreq(ps->s_txreq);
  526. bail_no_tx:
  527. ps->s_txreq = NULL;
  528. qp->s_flags &= ~RVT_S_BUSY;
  529. qp->s_hdrwords = 0;
  530. return 0;
  531. }
  532. /*
  533. * Hardware can't check this so we do it here.
  534. *
  535. * This is a slightly different algorithm than the standard pkey check. It
  536. * special cases the management keys and allows for 0x7fff and 0xffff to be in
  537. * the table at the same time.
  538. *
  539. * @returns the index found or -1 if not found
  540. */
  541. int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey)
  542. {
  543. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  544. unsigned i;
  545. if (pkey == FULL_MGMT_P_KEY || pkey == LIM_MGMT_P_KEY) {
  546. unsigned lim_idx = -1;
  547. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) {
  548. /* here we look for an exact match */
  549. if (ppd->pkeys[i] == pkey)
  550. return i;
  551. if (ppd->pkeys[i] == LIM_MGMT_P_KEY)
  552. lim_idx = i;
  553. }
  554. /* did not find 0xffff return 0x7fff idx if found */
  555. if (pkey == FULL_MGMT_P_KEY)
  556. return lim_idx;
  557. /* no match... */
  558. return -1;
  559. }
  560. pkey &= 0x7fff; /* remove limited/full membership bit */
  561. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i)
  562. if ((ppd->pkeys[i] & 0x7fff) == pkey)
  563. return i;
  564. /*
  565. * Should not get here, this means hardware failed to validate pkeys.
  566. */
  567. return -1;
  568. }
  569. void return_cnp_16B(struct hfi1_ibport *ibp, struct rvt_qp *qp,
  570. u32 remote_qpn, u32 pkey, u32 slid, u32 dlid,
  571. u8 sc5, const struct ib_grh *old_grh)
  572. {
  573. u64 pbc, pbc_flags = 0;
  574. u32 bth0, plen, vl, hwords = 7;
  575. u16 len;
  576. u8 l4;
  577. struct hfi1_16b_header hdr;
  578. struct ib_other_headers *ohdr;
  579. struct pio_buf *pbuf;
  580. struct send_context *ctxt = qp_to_send_context(qp, sc5);
  581. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  582. u32 nwords;
  583. /* Populate length */
  584. nwords = ((hfi1_get_16b_padding(hwords << 2, 0) +
  585. SIZE_OF_LT) >> 2) + SIZE_OF_CRC;
  586. if (old_grh) {
  587. struct ib_grh *grh = &hdr.u.l.grh;
  588. grh->version_tclass_flow = old_grh->version_tclass_flow;
  589. grh->paylen = cpu_to_be16((hwords - 4 + nwords) << 2);
  590. grh->hop_limit = 0xff;
  591. grh->sgid = old_grh->dgid;
  592. grh->dgid = old_grh->sgid;
  593. ohdr = &hdr.u.l.oth;
  594. l4 = OPA_16B_L4_IB_GLOBAL;
  595. hwords += sizeof(struct ib_grh) / sizeof(u32);
  596. } else {
  597. ohdr = &hdr.u.oth;
  598. l4 = OPA_16B_L4_IB_LOCAL;
  599. }
  600. /* BIT 16 to 19 is TVER. Bit 20 to 22 is pad cnt */
  601. bth0 = (IB_OPCODE_CNP << 24) | (1 << 16) |
  602. (hfi1_get_16b_padding(hwords << 2, 0) << 20);
  603. ohdr->bth[0] = cpu_to_be32(bth0);
  604. ohdr->bth[1] = cpu_to_be32(remote_qpn);
  605. ohdr->bth[2] = 0; /* PSN 0 */
  606. /* Convert dwords to flits */
  607. len = (hwords + nwords) >> 1;
  608. hfi1_make_16b_hdr(&hdr, slid, dlid, len, pkey, 1, 0, l4, sc5);
  609. plen = 2 /* PBC */ + hwords + nwords;
  610. pbc_flags |= PBC_PACKET_BYPASS | PBC_INSERT_BYPASS_ICRC;
  611. vl = sc_to_vlt(ppd->dd, sc5);
  612. pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
  613. if (ctxt) {
  614. pbuf = sc_buffer_alloc(ctxt, plen, NULL, NULL);
  615. if (pbuf)
  616. ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc,
  617. &hdr, hwords);
  618. }
  619. }
  620. void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
  621. u32 pkey, u32 slid, u32 dlid, u8 sc5,
  622. const struct ib_grh *old_grh)
  623. {
  624. u64 pbc, pbc_flags = 0;
  625. u32 bth0, plen, vl, hwords = 5;
  626. u16 lrh0;
  627. u8 sl = ibp->sc_to_sl[sc5];
  628. struct ib_header hdr;
  629. struct ib_other_headers *ohdr;
  630. struct pio_buf *pbuf;
  631. struct send_context *ctxt = qp_to_send_context(qp, sc5);
  632. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  633. if (old_grh) {
  634. struct ib_grh *grh = &hdr.u.l.grh;
  635. grh->version_tclass_flow = old_grh->version_tclass_flow;
  636. grh->paylen = cpu_to_be16((hwords - 2 + 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. (ohdr->bth[0] &
  953. cpu_to_be32(IB_BTH_SOLICITED)) != 0);
  954. return;
  955. drop:
  956. ibp->rvp.n_pkt_drops++;
  957. }