qib_ud.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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 = qib_get_rwqe(qp, 0);
  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. smp_read_barrier_depends(); /* see post_one_send */
  235. if (qp->s_last == ACCESS_ONCE(qp->s_head))
  236. goto bail;
  237. /* If DMAs are in progress, we can't flush immediately. */
  238. if (atomic_read(&priv->s_dma_busy)) {
  239. qp->s_flags |= RVT_S_WAIT_DMA;
  240. goto bail;
  241. }
  242. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  243. qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
  244. goto done;
  245. }
  246. /* see post_one_send() */
  247. smp_read_barrier_depends();
  248. if (qp->s_cur == ACCESS_ONCE(qp->s_head))
  249. goto bail;
  250. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  251. next_cur = qp->s_cur + 1;
  252. if (next_cur >= qp->s_size)
  253. next_cur = 0;
  254. /* Construct the header. */
  255. ibp = to_iport(qp->ibqp.device, qp->port_num);
  256. ppd = ppd_from_ibp(ibp);
  257. ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
  258. if (rdma_ah_get_dlid(ah_attr) >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
  259. if (rdma_ah_get_dlid(ah_attr) !=
  260. be16_to_cpu(IB_LID_PERMISSIVE))
  261. this_cpu_inc(ibp->pmastats->n_multicast_xmit);
  262. else
  263. this_cpu_inc(ibp->pmastats->n_unicast_xmit);
  264. } else {
  265. this_cpu_inc(ibp->pmastats->n_unicast_xmit);
  266. lid = rdma_ah_get_dlid(ah_attr) & ~((1 << ppd->lmc) - 1);
  267. if (unlikely(lid == ppd->lid)) {
  268. unsigned long tflags = *flags;
  269. /*
  270. * If DMAs are in progress, we can't generate
  271. * a completion for the loopback packet since
  272. * it would be out of order.
  273. * XXX Instead of waiting, we could queue a
  274. * zero length descriptor so we get a callback.
  275. */
  276. if (atomic_read(&priv->s_dma_busy)) {
  277. qp->s_flags |= RVT_S_WAIT_DMA;
  278. goto bail;
  279. }
  280. qp->s_cur = next_cur;
  281. spin_unlock_irqrestore(&qp->s_lock, tflags);
  282. qib_ud_loopback(qp, wqe);
  283. spin_lock_irqsave(&qp->s_lock, tflags);
  284. *flags = tflags;
  285. qib_send_complete(qp, wqe, IB_WC_SUCCESS);
  286. goto done;
  287. }
  288. }
  289. qp->s_cur = next_cur;
  290. extra_bytes = -wqe->length & 3;
  291. nwords = (wqe->length + extra_bytes) >> 2;
  292. /* header size in 32-bit words LRH+BTH+DETH = (8+12+8)/4. */
  293. qp->s_hdrwords = 7;
  294. qp->s_cur_size = wqe->length;
  295. qp->s_cur_sge = &qp->s_sge;
  296. qp->s_srate = rdma_ah_get_static_rate(ah_attr);
  297. qp->s_wqe = wqe;
  298. qp->s_sge.sge = wqe->sg_list[0];
  299. qp->s_sge.sg_list = wqe->sg_list + 1;
  300. qp->s_sge.num_sge = wqe->wr.num_sge;
  301. qp->s_sge.total_len = wqe->length;
  302. if (rdma_ah_get_ah_flags(ah_attr) & IB_AH_GRH) {
  303. /* Header size in 32-bit words. */
  304. qp->s_hdrwords += qib_make_grh(ibp, &priv->s_hdr->u.l.grh,
  305. rdma_ah_read_grh(ah_attr),
  306. qp->s_hdrwords, nwords);
  307. lrh0 = QIB_LRH_GRH;
  308. ohdr = &priv->s_hdr->u.l.oth;
  309. /*
  310. * Don't worry about sending to locally attached multicast
  311. * QPs. It is unspecified by the spec. what happens.
  312. */
  313. } else {
  314. /* Header size in 32-bit words. */
  315. lrh0 = QIB_LRH_BTH;
  316. ohdr = &priv->s_hdr->u.oth;
  317. }
  318. if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
  319. qp->s_hdrwords++;
  320. ohdr->u.ud.imm_data = wqe->wr.ex.imm_data;
  321. bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
  322. } else
  323. bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
  324. lrh0 |= rdma_ah_get_sl(ah_attr) << 4;
  325. if (qp->ibqp.qp_type == IB_QPT_SMI)
  326. lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
  327. else
  328. lrh0 |= ibp->sl_to_vl[rdma_ah_get_sl(ah_attr)] << 12;
  329. priv->s_hdr->lrh[0] = cpu_to_be16(lrh0);
  330. priv->s_hdr->lrh[1] =
  331. cpu_to_be16(rdma_ah_get_dlid(ah_attr)); /* DEST LID */
  332. priv->s_hdr->lrh[2] =
  333. cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
  334. lid = ppd->lid;
  335. if (lid) {
  336. lid |= rdma_ah_get_path_bits(ah_attr) &
  337. ((1 << ppd->lmc) - 1);
  338. priv->s_hdr->lrh[3] = cpu_to_be16(lid);
  339. } else
  340. priv->s_hdr->lrh[3] = IB_LID_PERMISSIVE;
  341. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  342. bth0 |= IB_BTH_SOLICITED;
  343. bth0 |= extra_bytes << 20;
  344. bth0 |= qp->ibqp.qp_type == IB_QPT_SMI ? QIB_DEFAULT_P_KEY :
  345. qib_get_pkey(ibp, qp->ibqp.qp_type == IB_QPT_GSI ?
  346. wqe->ud_wr.pkey_index : qp->s_pkey_index);
  347. ohdr->bth[0] = cpu_to_be32(bth0);
  348. /*
  349. * Use the multicast QP if the destination LID is a multicast LID.
  350. */
  351. ohdr->bth[1] = rdma_ah_get_dlid(ah_attr) >=
  352. be16_to_cpu(IB_MULTICAST_LID_BASE) &&
  353. rdma_ah_get_dlid(ah_attr) != be16_to_cpu(IB_LID_PERMISSIVE) ?
  354. cpu_to_be32(QIB_MULTICAST_QPN) :
  355. cpu_to_be32(wqe->ud_wr.remote_qpn);
  356. ohdr->bth[2] = cpu_to_be32(wqe->psn & QIB_PSN_MASK);
  357. /*
  358. * Qkeys with the high order bit set mean use the
  359. * qkey from the QP context instead of the WR (see 10.2.5).
  360. */
  361. ohdr->u.ud.deth[0] = cpu_to_be32((int)wqe->ud_wr.remote_qkey < 0 ?
  362. qp->qkey : wqe->ud_wr.remote_qkey);
  363. ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
  364. done:
  365. return 1;
  366. bail:
  367. qp->s_flags &= ~RVT_S_BUSY;
  368. return ret;
  369. }
  370. static unsigned qib_lookup_pkey(struct qib_ibport *ibp, u16 pkey)
  371. {
  372. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  373. struct qib_devdata *dd = ppd->dd;
  374. unsigned ctxt = ppd->hw_pidx;
  375. unsigned i;
  376. pkey &= 0x7fff; /* remove limited/full membership bit */
  377. for (i = 0; i < ARRAY_SIZE(dd->rcd[ctxt]->pkeys); ++i)
  378. if ((dd->rcd[ctxt]->pkeys[i] & 0x7fff) == pkey)
  379. return i;
  380. /*
  381. * Should not get here, this means hardware failed to validate pkeys.
  382. * Punt and return index 0.
  383. */
  384. return 0;
  385. }
  386. /**
  387. * qib_ud_rcv - receive an incoming UD packet
  388. * @ibp: the port the packet came in on
  389. * @hdr: the packet header
  390. * @has_grh: true if the packet has a GRH
  391. * @data: the packet data
  392. * @tlen: the packet length
  393. * @qp: the QP the packet came on
  394. *
  395. * This is called from qib_qp_rcv() to process an incoming UD packet
  396. * for the given QP.
  397. * Called at interrupt level.
  398. */
  399. void qib_ud_rcv(struct qib_ibport *ibp, struct ib_header *hdr,
  400. int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
  401. {
  402. struct ib_other_headers *ohdr;
  403. int opcode;
  404. u32 hdrsize;
  405. u32 pad;
  406. struct ib_wc wc;
  407. u32 qkey;
  408. u32 src_qp;
  409. u16 dlid;
  410. /* Check for GRH */
  411. if (!has_grh) {
  412. ohdr = &hdr->u.oth;
  413. hdrsize = 8 + 12 + 8; /* LRH + BTH + DETH */
  414. } else {
  415. ohdr = &hdr->u.l.oth;
  416. hdrsize = 8 + 40 + 12 + 8; /* LRH + GRH + BTH + DETH */
  417. }
  418. qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
  419. src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
  420. /*
  421. * Get the number of bytes the message was padded by
  422. * and drop incomplete packets.
  423. */
  424. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  425. if (unlikely(tlen < (hdrsize + pad + 4)))
  426. goto drop;
  427. tlen -= hdrsize + pad + 4;
  428. /*
  429. * Check that the permissive LID is only used on QP0
  430. * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
  431. */
  432. if (qp->ibqp.qp_num) {
  433. if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE ||
  434. hdr->lrh[3] == IB_LID_PERMISSIVE))
  435. goto drop;
  436. if (qp->ibqp.qp_num > 1) {
  437. u16 pkey1, pkey2;
  438. pkey1 = be32_to_cpu(ohdr->bth[0]);
  439. pkey2 = qib_get_pkey(ibp, qp->s_pkey_index);
  440. if (unlikely(!qib_pkey_ok(pkey1, pkey2))) {
  441. qib_bad_pkey(ibp,
  442. pkey1,
  443. (be16_to_cpu(hdr->lrh[0]) >> 4) &
  444. 0xF,
  445. src_qp, qp->ibqp.qp_num,
  446. hdr->lrh[3], hdr->lrh[1]);
  447. return;
  448. }
  449. }
  450. if (unlikely(qkey != qp->qkey))
  451. return;
  452. /* Drop invalid MAD packets (see 13.5.3.1). */
  453. if (unlikely(qp->ibqp.qp_num == 1 &&
  454. (tlen != 256 ||
  455. (be16_to_cpu(hdr->lrh[0]) >> 12) == 15)))
  456. goto drop;
  457. } else {
  458. struct ib_smp *smp;
  459. /* Drop invalid MAD packets (see 13.5.3.1). */
  460. if (tlen != 256 || (be16_to_cpu(hdr->lrh[0]) >> 12) != 15)
  461. goto drop;
  462. smp = (struct ib_smp *) data;
  463. if ((hdr->lrh[1] == IB_LID_PERMISSIVE ||
  464. hdr->lrh[3] == IB_LID_PERMISSIVE) &&
  465. smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  466. goto drop;
  467. }
  468. /*
  469. * The opcode is in the low byte when its in network order
  470. * (top byte when in host order).
  471. */
  472. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  473. if (qp->ibqp.qp_num > 1 &&
  474. opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
  475. wc.ex.imm_data = ohdr->u.ud.imm_data;
  476. wc.wc_flags = IB_WC_WITH_IMM;
  477. tlen -= sizeof(u32);
  478. } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
  479. wc.ex.imm_data = 0;
  480. wc.wc_flags = 0;
  481. } else
  482. goto drop;
  483. /*
  484. * A GRH is expected to precede the data even if not
  485. * present on the wire.
  486. */
  487. wc.byte_len = tlen + sizeof(struct ib_grh);
  488. /*
  489. * Get the next work request entry to find where to put the data.
  490. */
  491. if (qp->r_flags & RVT_R_REUSE_SGE)
  492. qp->r_flags &= ~RVT_R_REUSE_SGE;
  493. else {
  494. int ret;
  495. ret = qib_get_rwqe(qp, 0);
  496. if (ret < 0) {
  497. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  498. return;
  499. }
  500. if (!ret) {
  501. if (qp->ibqp.qp_num == 0)
  502. ibp->rvp.n_vl15_dropped++;
  503. return;
  504. }
  505. }
  506. /* Silently drop packets which are too big. */
  507. if (unlikely(wc.byte_len > qp->r_len)) {
  508. qp->r_flags |= RVT_R_REUSE_SGE;
  509. goto drop;
  510. }
  511. if (has_grh) {
  512. qib_copy_sge(&qp->r_sge, &hdr->u.l.grh,
  513. sizeof(struct ib_grh), 1);
  514. wc.wc_flags |= IB_WC_GRH;
  515. } else
  516. rvt_skip_sge(&qp->r_sge, sizeof(struct ib_grh), true);
  517. qib_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh), 1);
  518. rvt_put_ss(&qp->r_sge);
  519. if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
  520. return;
  521. wc.wr_id = qp->r_wr_id;
  522. wc.status = IB_WC_SUCCESS;
  523. wc.opcode = IB_WC_RECV;
  524. wc.vendor_err = 0;
  525. wc.qp = &qp->ibqp;
  526. wc.src_qp = src_qp;
  527. wc.pkey_index = qp->ibqp.qp_type == IB_QPT_GSI ?
  528. qib_lookup_pkey(ibp, be32_to_cpu(ohdr->bth[0])) : 0;
  529. wc.slid = be16_to_cpu(hdr->lrh[3]);
  530. wc.sl = (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF;
  531. dlid = be16_to_cpu(hdr->lrh[1]);
  532. /*
  533. * Save the LMC lower bits if the destination LID is a unicast LID.
  534. */
  535. wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 :
  536. dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
  537. wc.port_num = qp->port_num;
  538. /* Signal completion event if the solicited bit is set. */
  539. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
  540. (ohdr->bth[0] &
  541. cpu_to_be32(IB_BTH_SOLICITED)) != 0);
  542. return;
  543. drop:
  544. ibp->rvp.n_pkt_drops++;
  545. }