ud.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083
  1. /*
  2. * Copyright(c) 2015 - 2018 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 = rvt_get_rwqe(qp, false);
  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. rvt_copy_sge(qp, &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. rvt_copy_sge(qp, &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. u32 dest_qp = wqe->ud_wr.remote_qpn;
  368. u32 src_qp = qp->ibqp.qp_num;
  369. u16 len, pkey;
  370. u8 l4, sc5;
  371. bool is_mgmt = false;
  372. ibp = to_iport(qp->ibqp.device, qp->port_num);
  373. ppd = ppd_from_ibp(ibp);
  374. ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
  375. /*
  376. * Build 16B Management Packet if either the destination
  377. * or source queue pair number is 0 or 1.
  378. */
  379. if (dest_qp == 0 || src_qp == 0 || dest_qp == 1 || src_qp == 1) {
  380. /* header size in dwords 16B LRH+L4_FM = (16+8)/4. */
  381. ps->s_txreq->hdr_dwords = 6;
  382. is_mgmt = true;
  383. } else {
  384. /* header size in dwords 16B LRH+BTH+DETH = (16+12+8)/4. */
  385. ps->s_txreq->hdr_dwords = 9;
  386. if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
  387. ps->s_txreq->hdr_dwords++;
  388. }
  389. /* SW provides space for CRC and LT for bypass packets. */
  390. extra_bytes = hfi1_get_16b_padding((ps->s_txreq->hdr_dwords << 2),
  391. wqe->length);
  392. nwords = ((wqe->length + extra_bytes + SIZE_OF_LT) >> 2) + SIZE_OF_CRC;
  393. if ((rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) &&
  394. hfi1_check_mcast(rdma_ah_get_dlid(ah_attr))) {
  395. struct ib_grh *grh;
  396. struct ib_global_route *grd = rdma_ah_retrieve_grh(ah_attr);
  397. /*
  398. * Ensure OPA GIDs are transformed to IB gids
  399. * before creating the GRH.
  400. */
  401. if (grd->sgid_index == OPA_GID_INDEX) {
  402. dd_dev_warn(ppd->dd, "Bad sgid_index. sgid_index: %d\n",
  403. grd->sgid_index);
  404. grd->sgid_index = 0;
  405. }
  406. grh = &ps->s_txreq->phdr.hdr.opah.u.l.grh;
  407. ps->s_txreq->hdr_dwords += hfi1_make_grh(
  408. ibp, grh, grd,
  409. ps->s_txreq->hdr_dwords - LRH_16B_DWORDS,
  410. nwords);
  411. ohdr = &ps->s_txreq->phdr.hdr.opah.u.l.oth;
  412. l4 = OPA_16B_L4_IB_GLOBAL;
  413. } else {
  414. ohdr = &ps->s_txreq->phdr.hdr.opah.u.oth;
  415. l4 = OPA_16B_L4_IB_LOCAL;
  416. }
  417. sc5 = ibp->sl_to_sc[rdma_ah_get_sl(ah_attr)];
  418. if (qp->ibqp.qp_type == IB_QPT_SMI)
  419. priv->s_sc = 0xf;
  420. else
  421. priv->s_sc = sc5;
  422. dlid = opa_get_lid(rdma_ah_get_dlid(ah_attr), 16B);
  423. if (!ppd->lid)
  424. slid = be32_to_cpu(OPA_LID_PERMISSIVE);
  425. else
  426. slid = ppd->lid | (rdma_ah_get_path_bits(ah_attr) &
  427. ((1 << ppd->lmc) - 1));
  428. if (is_mgmt) {
  429. l4 = OPA_16B_L4_FM;
  430. pkey = hfi1_get_pkey(ibp, wqe->ud_wr.pkey_index);
  431. hfi1_16B_set_qpn(&ps->s_txreq->phdr.hdr.opah.u.mgmt,
  432. dest_qp, src_qp);
  433. } else {
  434. hfi1_make_bth_deth(qp, wqe, ohdr, &pkey, extra_bytes, true);
  435. }
  436. /* Convert dwords to flits */
  437. len = (ps->s_txreq->hdr_dwords + nwords) >> 1;
  438. /* Setup the packet */
  439. ps->s_txreq->phdr.hdr.hdr_type = HFI1_PKT_TYPE_16B;
  440. hfi1_make_16b_hdr(&ps->s_txreq->phdr.hdr.opah,
  441. slid, dlid, len, pkey, 0, 0, l4, priv->s_sc);
  442. }
  443. /**
  444. * hfi1_make_ud_req - construct a UD request packet
  445. * @qp: the QP
  446. *
  447. * Assume s_lock is held.
  448. *
  449. * Return 1 if constructed; otherwise, return 0.
  450. */
  451. int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
  452. {
  453. struct hfi1_qp_priv *priv = qp->priv;
  454. struct rdma_ah_attr *ah_attr;
  455. struct hfi1_pportdata *ppd;
  456. struct hfi1_ibport *ibp;
  457. struct rvt_swqe *wqe;
  458. int next_cur;
  459. u32 lid;
  460. ps->s_txreq = get_txreq(ps->dev, qp);
  461. if (!ps->s_txreq)
  462. goto bail_no_tx;
  463. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
  464. if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
  465. goto bail;
  466. /* We are in the error state, flush the work request. */
  467. if (qp->s_last == READ_ONCE(qp->s_head))
  468. goto bail;
  469. /* If DMAs are in progress, we can't flush immediately. */
  470. if (iowait_sdma_pending(&priv->s_iowait)) {
  471. qp->s_flags |= RVT_S_WAIT_DMA;
  472. goto bail;
  473. }
  474. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  475. rvt_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
  476. goto done_free_tx;
  477. }
  478. /* see post_one_send() */
  479. if (qp->s_cur == READ_ONCE(qp->s_head))
  480. goto bail;
  481. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  482. next_cur = qp->s_cur + 1;
  483. if (next_cur >= qp->s_size)
  484. next_cur = 0;
  485. /* Construct the header. */
  486. ibp = to_iport(qp->ibqp.device, qp->port_num);
  487. ppd = ppd_from_ibp(ibp);
  488. ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
  489. priv->hdr_type = hfi1_get_hdr_type(ppd->lid, ah_attr);
  490. if ((!hfi1_check_mcast(rdma_ah_get_dlid(ah_attr))) ||
  491. (rdma_ah_get_dlid(ah_attr) == be32_to_cpu(OPA_LID_PERMISSIVE))) {
  492. lid = rdma_ah_get_dlid(ah_attr) & ~((1 << ppd->lmc) - 1);
  493. if (unlikely(!loopback &&
  494. ((lid == ppd->lid) ||
  495. ((lid == be32_to_cpu(OPA_LID_PERMISSIVE)) &&
  496. (qp->ibqp.qp_type == IB_QPT_GSI))))) {
  497. unsigned long tflags = ps->flags;
  498. /*
  499. * If DMAs are in progress, we can't generate
  500. * a completion for the loopback packet since
  501. * it would be out of order.
  502. * Instead of waiting, we could queue a
  503. * zero length descriptor so we get a callback.
  504. */
  505. if (iowait_sdma_pending(&priv->s_iowait)) {
  506. qp->s_flags |= RVT_S_WAIT_DMA;
  507. goto bail;
  508. }
  509. qp->s_cur = next_cur;
  510. spin_unlock_irqrestore(&qp->s_lock, tflags);
  511. ud_loopback(qp, wqe);
  512. spin_lock_irqsave(&qp->s_lock, tflags);
  513. ps->flags = tflags;
  514. rvt_send_complete(qp, wqe, IB_WC_SUCCESS);
  515. goto done_free_tx;
  516. }
  517. }
  518. qp->s_cur = next_cur;
  519. ps->s_txreq->s_cur_size = wqe->length;
  520. ps->s_txreq->ss = &qp->s_sge;
  521. qp->s_srate = rdma_ah_get_static_rate(ah_attr);
  522. qp->srate_mbps = ib_rate_to_mbps(qp->s_srate);
  523. qp->s_wqe = wqe;
  524. qp->s_sge.sge = wqe->sg_list[0];
  525. qp->s_sge.sg_list = wqe->sg_list + 1;
  526. qp->s_sge.num_sge = wqe->wr.num_sge;
  527. qp->s_sge.total_len = wqe->length;
  528. /* Make the appropriate header */
  529. hfi1_make_ud_req_tbl[priv->hdr_type](qp, ps, qp->s_wqe);
  530. priv->s_sde = qp_to_sdma_engine(qp, priv->s_sc);
  531. ps->s_txreq->sde = priv->s_sde;
  532. priv->s_sendcontext = qp_to_send_context(qp, priv->s_sc);
  533. ps->s_txreq->psc = priv->s_sendcontext;
  534. /* disarm any ahg */
  535. priv->s_ahg->ahgcount = 0;
  536. priv->s_ahg->ahgidx = 0;
  537. priv->s_ahg->tx_flags = 0;
  538. return 1;
  539. done_free_tx:
  540. hfi1_put_txreq(ps->s_txreq);
  541. ps->s_txreq = NULL;
  542. return 1;
  543. bail:
  544. hfi1_put_txreq(ps->s_txreq);
  545. bail_no_tx:
  546. ps->s_txreq = NULL;
  547. qp->s_flags &= ~RVT_S_BUSY;
  548. return 0;
  549. }
  550. /*
  551. * Hardware can't check this so we do it here.
  552. *
  553. * This is a slightly different algorithm than the standard pkey check. It
  554. * special cases the management keys and allows for 0x7fff and 0xffff to be in
  555. * the table at the same time.
  556. *
  557. * @returns the index found or -1 if not found
  558. */
  559. int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey)
  560. {
  561. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  562. unsigned i;
  563. if (pkey == FULL_MGMT_P_KEY || pkey == LIM_MGMT_P_KEY) {
  564. unsigned lim_idx = -1;
  565. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i) {
  566. /* here we look for an exact match */
  567. if (ppd->pkeys[i] == pkey)
  568. return i;
  569. if (ppd->pkeys[i] == LIM_MGMT_P_KEY)
  570. lim_idx = i;
  571. }
  572. /* did not find 0xffff return 0x7fff idx if found */
  573. if (pkey == FULL_MGMT_P_KEY)
  574. return lim_idx;
  575. /* no match... */
  576. return -1;
  577. }
  578. pkey &= 0x7fff; /* remove limited/full membership bit */
  579. for (i = 0; i < ARRAY_SIZE(ppd->pkeys); ++i)
  580. if ((ppd->pkeys[i] & 0x7fff) == pkey)
  581. return i;
  582. /*
  583. * Should not get here, this means hardware failed to validate pkeys.
  584. */
  585. return -1;
  586. }
  587. void return_cnp_16B(struct hfi1_ibport *ibp, struct rvt_qp *qp,
  588. u32 remote_qpn, u16 pkey, u32 slid, u32 dlid,
  589. u8 sc5, const struct ib_grh *old_grh)
  590. {
  591. u64 pbc, pbc_flags = 0;
  592. u32 bth0, plen, vl, hwords = 7;
  593. u16 len;
  594. u8 l4;
  595. struct hfi1_16b_header hdr;
  596. struct ib_other_headers *ohdr;
  597. struct pio_buf *pbuf;
  598. struct send_context *ctxt = qp_to_send_context(qp, sc5);
  599. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  600. u32 nwords;
  601. /* Populate length */
  602. nwords = ((hfi1_get_16b_padding(hwords << 2, 0) +
  603. SIZE_OF_LT) >> 2) + SIZE_OF_CRC;
  604. if (old_grh) {
  605. struct ib_grh *grh = &hdr.u.l.grh;
  606. grh->version_tclass_flow = old_grh->version_tclass_flow;
  607. grh->paylen = cpu_to_be16(
  608. (hwords - LRH_16B_DWORDS + nwords) << 2);
  609. grh->hop_limit = 0xff;
  610. grh->sgid = old_grh->dgid;
  611. grh->dgid = old_grh->sgid;
  612. ohdr = &hdr.u.l.oth;
  613. l4 = OPA_16B_L4_IB_GLOBAL;
  614. hwords += sizeof(struct ib_grh) / sizeof(u32);
  615. } else {
  616. ohdr = &hdr.u.oth;
  617. l4 = OPA_16B_L4_IB_LOCAL;
  618. }
  619. /* BIT 16 to 19 is TVER. Bit 20 to 22 is pad cnt */
  620. bth0 = (IB_OPCODE_CNP << 24) | (1 << 16) |
  621. (hfi1_get_16b_padding(hwords << 2, 0) << 20);
  622. ohdr->bth[0] = cpu_to_be32(bth0);
  623. ohdr->bth[1] = cpu_to_be32(remote_qpn);
  624. ohdr->bth[2] = 0; /* PSN 0 */
  625. /* Convert dwords to flits */
  626. len = (hwords + nwords) >> 1;
  627. hfi1_make_16b_hdr(&hdr, slid, dlid, len, pkey, 1, 0, l4, sc5);
  628. plen = 2 /* PBC */ + hwords + nwords;
  629. pbc_flags |= PBC_PACKET_BYPASS | PBC_INSERT_BYPASS_ICRC;
  630. vl = sc_to_vlt(ppd->dd, sc5);
  631. pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
  632. if (ctxt) {
  633. pbuf = sc_buffer_alloc(ctxt, plen, NULL, NULL);
  634. if (pbuf)
  635. ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc,
  636. &hdr, hwords);
  637. }
  638. }
  639. void return_cnp(struct hfi1_ibport *ibp, struct rvt_qp *qp, u32 remote_qpn,
  640. u16 pkey, u32 slid, u32 dlid, u8 sc5,
  641. const struct ib_grh *old_grh)
  642. {
  643. u64 pbc, pbc_flags = 0;
  644. u32 bth0, plen, vl, hwords = 5;
  645. u16 lrh0;
  646. u8 sl = ibp->sc_to_sl[sc5];
  647. struct ib_header hdr;
  648. struct ib_other_headers *ohdr;
  649. struct pio_buf *pbuf;
  650. struct send_context *ctxt = qp_to_send_context(qp, sc5);
  651. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  652. if (old_grh) {
  653. struct ib_grh *grh = &hdr.u.l.grh;
  654. grh->version_tclass_flow = old_grh->version_tclass_flow;
  655. grh->paylen = cpu_to_be16(
  656. (hwords - LRH_9B_DWORDS + SIZE_OF_CRC) << 2);
  657. grh->hop_limit = 0xff;
  658. grh->sgid = old_grh->dgid;
  659. grh->dgid = old_grh->sgid;
  660. ohdr = &hdr.u.l.oth;
  661. lrh0 = HFI1_LRH_GRH;
  662. hwords += sizeof(struct ib_grh) / sizeof(u32);
  663. } else {
  664. ohdr = &hdr.u.oth;
  665. lrh0 = HFI1_LRH_BTH;
  666. }
  667. lrh0 |= (sc5 & 0xf) << 12 | sl << 4;
  668. bth0 = pkey | (IB_OPCODE_CNP << 24);
  669. ohdr->bth[0] = cpu_to_be32(bth0);
  670. ohdr->bth[1] = cpu_to_be32(remote_qpn | (1 << IB_BECN_SHIFT));
  671. ohdr->bth[2] = 0; /* PSN 0 */
  672. hfi1_make_ib_hdr(&hdr, lrh0, hwords + SIZE_OF_CRC, dlid, slid);
  673. plen = 2 /* PBC */ + hwords;
  674. pbc_flags |= (ib_is_sc5(sc5) << PBC_DC_INFO_SHIFT);
  675. vl = sc_to_vlt(ppd->dd, sc5);
  676. pbc = create_pbc(ppd, pbc_flags, qp->srate_mbps, vl, plen);
  677. if (ctxt) {
  678. pbuf = sc_buffer_alloc(ctxt, plen, NULL, NULL);
  679. if (pbuf)
  680. ppd->dd->pio_inline_send(ppd->dd, pbuf, pbc,
  681. &hdr, hwords);
  682. }
  683. }
  684. /*
  685. * opa_smp_check() - Do the regular pkey checking, and the additional
  686. * checks for SMPs specified in OPAv1 rev 1.0, 9/19/2016 update, section
  687. * 9.10.25 ("SMA Packet Checks").
  688. *
  689. * Note that:
  690. * - Checks are done using the pkey directly from the packet's BTH,
  691. * and specifically _not_ the pkey that we attach to the completion,
  692. * which may be different.
  693. * - These checks are specifically for "non-local" SMPs (i.e., SMPs
  694. * which originated on another node). SMPs which are sent from, and
  695. * destined to this node are checked in opa_local_smp_check().
  696. *
  697. * At the point where opa_smp_check() is called, we know:
  698. * - destination QP is QP0
  699. *
  700. * opa_smp_check() returns 0 if all checks succeed, 1 otherwise.
  701. */
  702. static int opa_smp_check(struct hfi1_ibport *ibp, u16 pkey, u8 sc5,
  703. struct rvt_qp *qp, u16 slid, struct opa_smp *smp)
  704. {
  705. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  706. /*
  707. * I don't think it's possible for us to get here with sc != 0xf,
  708. * but check it to be certain.
  709. */
  710. if (sc5 != 0xf)
  711. return 1;
  712. if (rcv_pkey_check(ppd, pkey, sc5, slid))
  713. return 1;
  714. /*
  715. * At this point we know (and so don't need to check again) that
  716. * the pkey is either LIM_MGMT_P_KEY, or FULL_MGMT_P_KEY
  717. * (see ingress_pkey_check).
  718. */
  719. if (smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE &&
  720. smp->mgmt_class != IB_MGMT_CLASS_SUBN_LID_ROUTED) {
  721. ingress_pkey_table_fail(ppd, pkey, slid);
  722. return 1;
  723. }
  724. /*
  725. * SMPs fall into one of four (disjoint) categories:
  726. * SMA request, SMA response, SMA trap, or SMA trap repress.
  727. * Our response depends, in part, on which type of SMP we're
  728. * processing.
  729. *
  730. * If this is an SMA response, skip the check here.
  731. *
  732. * If this is an SMA request or SMA trap repress:
  733. * - pkey != FULL_MGMT_P_KEY =>
  734. * increment port recv constraint errors, drop MAD
  735. *
  736. * Otherwise:
  737. * - accept if the port is running an SM
  738. * - drop MAD if it's an SMA trap
  739. * - pkey == FULL_MGMT_P_KEY =>
  740. * reply with unsupported method
  741. * - pkey != FULL_MGMT_P_KEY =>
  742. * increment port recv constraint errors, drop MAD
  743. */
  744. switch (smp->method) {
  745. case IB_MGMT_METHOD_GET_RESP:
  746. case IB_MGMT_METHOD_REPORT_RESP:
  747. break;
  748. case IB_MGMT_METHOD_GET:
  749. case IB_MGMT_METHOD_SET:
  750. case IB_MGMT_METHOD_REPORT:
  751. case IB_MGMT_METHOD_TRAP_REPRESS:
  752. if (pkey != FULL_MGMT_P_KEY) {
  753. ingress_pkey_table_fail(ppd, pkey, slid);
  754. return 1;
  755. }
  756. break;
  757. default:
  758. if (ibp->rvp.port_cap_flags & IB_PORT_SM)
  759. return 0;
  760. if (smp->method == IB_MGMT_METHOD_TRAP)
  761. return 1;
  762. if (pkey == FULL_MGMT_P_KEY) {
  763. smp->status |= IB_SMP_UNSUP_METHOD;
  764. return 0;
  765. }
  766. ingress_pkey_table_fail(ppd, pkey, slid);
  767. return 1;
  768. }
  769. return 0;
  770. }
  771. /**
  772. * hfi1_ud_rcv - receive an incoming UD packet
  773. * @ibp: the port the packet came in on
  774. * @hdr: the packet header
  775. * @rcv_flags: flags relevant to rcv processing
  776. * @data: the packet data
  777. * @tlen: the packet length
  778. * @qp: the QP the packet came on
  779. *
  780. * This is called from qp_rcv() to process an incoming UD packet
  781. * for the given QP.
  782. * Called at interrupt level.
  783. */
  784. void hfi1_ud_rcv(struct hfi1_packet *packet)
  785. {
  786. u32 hdrsize = packet->hlen;
  787. struct ib_wc wc;
  788. u32 src_qp;
  789. u16 pkey;
  790. int mgmt_pkey_idx = -1;
  791. struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd);
  792. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  793. void *data = packet->payload;
  794. u32 tlen = packet->tlen;
  795. struct rvt_qp *qp = packet->qp;
  796. u8 sc5 = packet->sc;
  797. u8 sl_from_sc;
  798. u8 opcode = packet->opcode;
  799. u8 sl = packet->sl;
  800. u32 dlid = packet->dlid;
  801. u32 slid = packet->slid;
  802. u8 extra_bytes;
  803. u8 l4 = 0;
  804. bool dlid_is_permissive;
  805. bool slid_is_permissive;
  806. bool solicited = false;
  807. extra_bytes = packet->pad + packet->extra_byte + (SIZE_OF_CRC << 2);
  808. if (packet->etype == RHF_RCV_TYPE_BYPASS) {
  809. u32 permissive_lid =
  810. opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B);
  811. l4 = hfi1_16B_get_l4(packet->hdr);
  812. pkey = hfi1_16B_get_pkey(packet->hdr);
  813. dlid_is_permissive = (dlid == permissive_lid);
  814. slid_is_permissive = (slid == permissive_lid);
  815. } else {
  816. pkey = ib_bth_get_pkey(packet->ohdr);
  817. dlid_is_permissive = (dlid == be16_to_cpu(IB_LID_PERMISSIVE));
  818. slid_is_permissive = (slid == be16_to_cpu(IB_LID_PERMISSIVE));
  819. }
  820. sl_from_sc = ibp->sc_to_sl[sc5];
  821. if (likely(l4 != OPA_16B_L4_FM)) {
  822. src_qp = ib_get_sqpn(packet->ohdr);
  823. solicited = ib_bth_is_solicited(packet->ohdr);
  824. } else {
  825. src_qp = hfi1_16B_get_src_qpn(packet->mgmt);
  826. }
  827. process_ecn(qp, packet, (opcode != IB_OPCODE_CNP));
  828. /*
  829. * Get the number of bytes the message was padded by
  830. * and drop incomplete packets.
  831. */
  832. if (unlikely(tlen < (hdrsize + extra_bytes)))
  833. goto drop;
  834. tlen -= hdrsize + extra_bytes;
  835. /*
  836. * Check that the permissive LID is only used on QP0
  837. * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
  838. */
  839. if (qp->ibqp.qp_num) {
  840. if (unlikely(dlid_is_permissive || slid_is_permissive))
  841. goto drop;
  842. if (qp->ibqp.qp_num > 1) {
  843. if (unlikely(rcv_pkey_check(ppd, pkey, sc5, slid))) {
  844. /*
  845. * Traps will not be sent for packets dropped
  846. * by the HW. This is fine, as sending trap
  847. * for invalid pkeys is optional according to
  848. * IB spec (release 1.3, section 10.9.4)
  849. */
  850. hfi1_bad_pkey(ibp,
  851. pkey, sl,
  852. src_qp, qp->ibqp.qp_num,
  853. slid, dlid);
  854. return;
  855. }
  856. } else {
  857. /* GSI packet */
  858. mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
  859. if (mgmt_pkey_idx < 0)
  860. goto drop;
  861. }
  862. if (unlikely(l4 != OPA_16B_L4_FM &&
  863. ib_get_qkey(packet->ohdr) != qp->qkey))
  864. return; /* Silent drop */
  865. /* Drop invalid MAD packets (see 13.5.3.1). */
  866. if (unlikely(qp->ibqp.qp_num == 1 &&
  867. (tlen > 2048 || (sc5 == 0xF))))
  868. goto drop;
  869. } else {
  870. /* Received on QP0, and so by definition, this is an SMP */
  871. struct opa_smp *smp = (struct opa_smp *)data;
  872. if (opa_smp_check(ibp, pkey, sc5, qp, slid, smp))
  873. goto drop;
  874. if (tlen > 2048)
  875. goto drop;
  876. if ((dlid_is_permissive || slid_is_permissive) &&
  877. smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  878. goto drop;
  879. /* look up SMI pkey */
  880. mgmt_pkey_idx = hfi1_lookup_pkey_idx(ibp, pkey);
  881. if (mgmt_pkey_idx < 0)
  882. goto drop;
  883. }
  884. if (qp->ibqp.qp_num > 1 &&
  885. opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
  886. wc.ex.imm_data = packet->ohdr->u.ud.imm_data;
  887. wc.wc_flags = IB_WC_WITH_IMM;
  888. tlen -= sizeof(u32);
  889. } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
  890. wc.ex.imm_data = 0;
  891. wc.wc_flags = 0;
  892. } else {
  893. goto drop;
  894. }
  895. /*
  896. * A GRH is expected to precede the data even if not
  897. * present on the wire.
  898. */
  899. wc.byte_len = tlen + sizeof(struct ib_grh);
  900. /*
  901. * Get the next work request entry to find where to put the data.
  902. */
  903. if (qp->r_flags & RVT_R_REUSE_SGE) {
  904. qp->r_flags &= ~RVT_R_REUSE_SGE;
  905. } else {
  906. int ret;
  907. ret = rvt_get_rwqe(qp, false);
  908. if (ret < 0) {
  909. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  910. return;
  911. }
  912. if (!ret) {
  913. if (qp->ibqp.qp_num == 0)
  914. ibp->rvp.n_vl15_dropped++;
  915. return;
  916. }
  917. }
  918. /* Silently drop packets which are too big. */
  919. if (unlikely(wc.byte_len > qp->r_len)) {
  920. qp->r_flags |= RVT_R_REUSE_SGE;
  921. goto drop;
  922. }
  923. if (packet->grh) {
  924. rvt_copy_sge(qp, &qp->r_sge, packet->grh,
  925. sizeof(struct ib_grh), true, false);
  926. wc.wc_flags |= IB_WC_GRH;
  927. } else if (packet->etype == RHF_RCV_TYPE_BYPASS) {
  928. struct ib_grh grh;
  929. /*
  930. * Assuming we only created 16B on the send side
  931. * if we want to use large LIDs, since GRH was stripped
  932. * out when creating 16B, add back the GRH here.
  933. */
  934. hfi1_make_ext_grh(packet, &grh, slid, dlid);
  935. rvt_copy_sge(qp, &qp->r_sge, &grh,
  936. sizeof(struct ib_grh), true, false);
  937. wc.wc_flags |= IB_WC_GRH;
  938. } else {
  939. rvt_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
  940. }
  941. rvt_copy_sge(qp, &qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh),
  942. true, false);
  943. rvt_put_ss(&qp->r_sge);
  944. if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
  945. return;
  946. wc.wr_id = qp->r_wr_id;
  947. wc.status = IB_WC_SUCCESS;
  948. wc.opcode = IB_WC_RECV;
  949. wc.vendor_err = 0;
  950. wc.qp = &qp->ibqp;
  951. wc.src_qp = src_qp;
  952. if (qp->ibqp.qp_type == IB_QPT_GSI ||
  953. qp->ibqp.qp_type == IB_QPT_SMI) {
  954. if (mgmt_pkey_idx < 0) {
  955. if (net_ratelimit()) {
  956. struct hfi1_devdata *dd = ppd->dd;
  957. dd_dev_err(dd, "QP type %d mgmt_pkey_idx < 0 and packet not dropped???\n",
  958. qp->ibqp.qp_type);
  959. mgmt_pkey_idx = 0;
  960. }
  961. }
  962. wc.pkey_index = (unsigned)mgmt_pkey_idx;
  963. } else {
  964. wc.pkey_index = 0;
  965. }
  966. if (slid_is_permissive)
  967. slid = be32_to_cpu(OPA_LID_PERMISSIVE);
  968. wc.slid = slid & U16_MAX;
  969. wc.sl = sl_from_sc;
  970. /*
  971. * Save the LMC lower bits if the destination LID is a unicast LID.
  972. */
  973. wc.dlid_path_bits = hfi1_check_mcast(dlid) ? 0 :
  974. dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
  975. wc.port_num = qp->port_num;
  976. /* Signal completion event if the solicited bit is set. */
  977. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, solicited);
  978. return;
  979. drop:
  980. ibp->rvp.n_pkt_drops++;
  981. }