qib_ud.c 16 KB

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