ud.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059
  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));
  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 == ACCESS_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 == ACCESS_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. struct ib_header *hdr = packet->hdr;
  776. void *data = packet->payload;
  777. u32 tlen = packet->tlen;
  778. struct rvt_qp *qp = packet->qp;
  779. u8 sc5 = packet->sc;
  780. u8 sl_from_sc;
  781. u8 opcode = packet->opcode;
  782. u8 sl = packet->sl;
  783. u32 dlid = packet->dlid;
  784. u32 slid = packet->slid;
  785. u8 extra_bytes;
  786. bool dlid_is_permissive;
  787. bool slid_is_permissive;
  788. extra_bytes = packet->pad + packet->extra_byte + (SIZE_OF_CRC << 2);
  789. qkey = ib_get_qkey(ohdr);
  790. src_qp = ib_get_sqpn(ohdr);
  791. if (packet->etype == RHF_RCV_TYPE_BYPASS) {
  792. u32 permissive_lid =
  793. opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B);
  794. pkey = hfi1_16B_get_pkey(packet->hdr);
  795. dlid_is_permissive = (dlid == permissive_lid);
  796. slid_is_permissive = (slid == permissive_lid);
  797. } else {
  798. hdr = packet->hdr;
  799. pkey = ib_bth_get_pkey(ohdr);
  800. dlid_is_permissive = (dlid == be16_to_cpu(IB_LID_PERMISSIVE));
  801. slid_is_permissive = (slid == be16_to_cpu(IB_LID_PERMISSIVE));
  802. }
  803. sl_from_sc = ibp->sc_to_sl[sc5];
  804. process_ecn(qp, packet, (opcode != IB_OPCODE_CNP));
  805. /*
  806. * Get the number of bytes the message was padded by
  807. * and drop incomplete packets.
  808. */
  809. if (unlikely(tlen < (hdrsize + extra_bytes)))
  810. goto drop;
  811. tlen -= hdrsize + extra_bytes;
  812. /*
  813. * Check that the permissive LID is only used on QP0
  814. * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
  815. */
  816. if (qp->ibqp.qp_num) {
  817. if (unlikely(dlid_is_permissive || slid_is_permissive))
  818. goto drop;
  819. if (qp->ibqp.qp_num > 1) {
  820. if (unlikely(rcv_pkey_check(ppd, pkey, sc5, slid))) {
  821. /*
  822. * Traps will not be sent for packets dropped
  823. * by the HW. This is fine, as sending trap
  824. * for invalid pkeys is optional according to
  825. * IB spec (release 1.3, section 10.9.4)
  826. */
  827. hfi1_bad_pkey(ibp,
  828. pkey, sl,
  829. src_qp, qp->ibqp.qp_num,
  830. slid, dlid);
  831. return;
  832. }
  833. } else {
  834. /* GSI packet */
  835. mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
  836. if (mgmt_pkey_idx < 0)
  837. goto drop;
  838. }
  839. if (unlikely(qkey != qp->qkey)) /* Silent drop */
  840. return;
  841. /* Drop invalid MAD packets (see 13.5.3.1). */
  842. if (unlikely(qp->ibqp.qp_num == 1 &&
  843. (tlen > 2048 || (sc5 == 0xF))))
  844. goto drop;
  845. } else {
  846. /* Received on QP0, and so by definition, this is an SMP */
  847. struct opa_smp *smp = (struct opa_smp *)data;
  848. if (opa_smp_check(ibp, pkey, sc5, qp, slid, smp))
  849. goto drop;
  850. if (tlen > 2048)
  851. goto drop;
  852. if ((dlid_is_permissive || slid_is_permissive) &&
  853. smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  854. goto drop;
  855. /* look up SMI pkey */
  856. mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
  857. if (mgmt_pkey_idx < 0)
  858. goto drop;
  859. }
  860. if (qp->ibqp.qp_num > 1 &&
  861. opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
  862. wc.ex.imm_data = ohdr->u.ud.imm_data;
  863. wc.wc_flags = IB_WC_WITH_IMM;
  864. tlen -= sizeof(u32);
  865. } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
  866. wc.ex.imm_data = 0;
  867. wc.wc_flags = 0;
  868. } else {
  869. goto drop;
  870. }
  871. /*
  872. * A GRH is expected to precede the data even if not
  873. * present on the wire.
  874. */
  875. wc.byte_len = tlen + sizeof(struct ib_grh);
  876. /*
  877. * Get the next work request entry to find where to put the data.
  878. */
  879. if (qp->r_flags & RVT_R_REUSE_SGE) {
  880. qp->r_flags &= ~RVT_R_REUSE_SGE;
  881. } else {
  882. int ret;
  883. ret = hfi1_rvt_get_rwqe(qp, 0);
  884. if (ret < 0) {
  885. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  886. return;
  887. }
  888. if (!ret) {
  889. if (qp->ibqp.qp_num == 0)
  890. ibp->rvp.n_vl15_dropped++;
  891. return;
  892. }
  893. }
  894. /* Silently drop packets which are too big. */
  895. if (unlikely(wc.byte_len > qp->r_len)) {
  896. qp->r_flags |= RVT_R_REUSE_SGE;
  897. goto drop;
  898. }
  899. if (packet->grh) {
  900. hfi1_copy_sge(&qp->r_sge, packet->grh,
  901. sizeof(struct ib_grh), true, false);
  902. wc.wc_flags |= IB_WC_GRH;
  903. } else if (packet->etype == RHF_RCV_TYPE_BYPASS) {
  904. struct ib_grh grh;
  905. /*
  906. * Assuming we only created 16B on the send side
  907. * if we want to use large LIDs, since GRH was stripped
  908. * out when creating 16B, add back the GRH here.
  909. */
  910. hfi1_make_ext_grh(packet, &grh, slid, dlid);
  911. hfi1_copy_sge(&qp->r_sge, &grh,
  912. sizeof(struct ib_grh), true, false);
  913. wc.wc_flags |= IB_WC_GRH;
  914. } else {
  915. rvt_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
  916. }
  917. hfi1_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
  918. true, false);
  919. rvt_put_ss(&qp->r_sge);
  920. if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
  921. return;
  922. wc.wr_id = qp->r_wr_id;
  923. wc.status = IB_WC_SUCCESS;
  924. wc.opcode = IB_WC_RECV;
  925. wc.vendor_err = 0;
  926. wc.qp = &qp->ibqp;
  927. wc.src_qp = src_qp;
  928. if (qp->ibqp.qp_type == IB_QPT_GSI ||
  929. qp->ibqp.qp_type == IB_QPT_SMI) {
  930. if (mgmt_pkey_idx < 0) {
  931. if (net_ratelimit()) {
  932. struct hfi1_devdata *dd = ppd->dd;
  933. dd_dev_err(dd, "QP type %d mgmt_pkey_idx < 0 and packet not dropped???\n",
  934. qp->ibqp.qp_type);
  935. mgmt_pkey_idx = 0;
  936. }
  937. }
  938. wc.pkey_index = (unsigned)mgmt_pkey_idx;
  939. } else {
  940. wc.pkey_index = 0;
  941. }
  942. if (slid_is_permissive)
  943. slid = be32_to_cpu(OPA_LID_PERMISSIVE);
  944. wc.slid = slid;
  945. wc.sl = sl_from_sc;
  946. /*
  947. * Save the LMC lower bits if the destination LID is a unicast LID.
  948. */
  949. wc.dlid_path_bits = hfi1_check_mcast(dlid) ? 0 :
  950. dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
  951. wc.port_num = qp->port_num;
  952. /* Signal completion event if the solicited bit is set. */
  953. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
  954. (ohdr->bth[0] &
  955. cpu_to_be32(IB_BTH_SOLICITED)) != 0);
  956. return;
  957. drop:
  958. ibp->rvp.n_pkt_drops++;
  959. }