qib_ud.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  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 ib_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. rcu_read_unlock();
  66. return;
  67. }
  68. sqptype = sqp->ibqp.qp_type == IB_QPT_GSI ?
  69. IB_QPT_UD : sqp->ibqp.qp_type;
  70. dqptype = qp->ibqp.qp_type == IB_QPT_GSI ?
  71. IB_QPT_UD : qp->ibqp.qp_type;
  72. if (dqptype != sqptype ||
  73. !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
  74. ibp->rvp.n_pkt_drops++;
  75. goto drop;
  76. }
  77. ah_attr = &ibah_to_rvtah(swqe->ud_wr.ah)->attr;
  78. ppd = ppd_from_ibp(ibp);
  79. if (qp->ibqp.qp_num > 1) {
  80. u16 pkey1;
  81. u16 pkey2;
  82. u16 lid;
  83. pkey1 = qib_get_pkey(ibp, sqp->s_pkey_index);
  84. pkey2 = qib_get_pkey(ibp, qp->s_pkey_index);
  85. if (unlikely(!qib_pkey_ok(pkey1, pkey2))) {
  86. lid = ppd->lid | (ah_attr->src_path_bits &
  87. ((1 << ppd->lmc) - 1));
  88. qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY, pkey1,
  89. ah_attr->sl,
  90. sqp->ibqp.qp_num, qp->ibqp.qp_num,
  91. cpu_to_be16(lid),
  92. cpu_to_be16(ah_attr->dlid));
  93. goto drop;
  94. }
  95. }
  96. /*
  97. * Check that the qkey matches (except for QP0, see 9.6.1.4.1).
  98. * Qkeys with the high order bit set mean use the
  99. * qkey from the QP context instead of the WR (see 10.2.5).
  100. */
  101. if (qp->ibqp.qp_num) {
  102. u32 qkey;
  103. qkey = (int)swqe->ud_wr.remote_qkey < 0 ?
  104. sqp->qkey : swqe->ud_wr.remote_qkey;
  105. if (unlikely(qkey != qp->qkey)) {
  106. u16 lid;
  107. lid = ppd->lid | (ah_attr->src_path_bits &
  108. ((1 << ppd->lmc) - 1));
  109. qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_QKEY, qkey,
  110. ah_attr->sl,
  111. sqp->ibqp.qp_num, qp->ibqp.qp_num,
  112. cpu_to_be16(lid),
  113. cpu_to_be16(ah_attr->dlid));
  114. goto drop;
  115. }
  116. }
  117. /*
  118. * A GRH is expected to precede the data even if not
  119. * present on the wire.
  120. */
  121. length = swqe->length;
  122. memset(&wc, 0, sizeof(wc));
  123. wc.byte_len = length + sizeof(struct ib_grh);
  124. if (swqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
  125. wc.wc_flags = IB_WC_WITH_IMM;
  126. wc.ex.imm_data = swqe->wr.ex.imm_data;
  127. }
  128. spin_lock_irqsave(&qp->r_lock, flags);
  129. /*
  130. * Get the next work request entry to find where to put the data.
  131. */
  132. if (qp->r_flags & RVT_R_REUSE_SGE)
  133. qp->r_flags &= ~RVT_R_REUSE_SGE;
  134. else {
  135. int ret;
  136. ret = qib_get_rwqe(qp, 0);
  137. if (ret < 0) {
  138. qib_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  139. goto bail_unlock;
  140. }
  141. if (!ret) {
  142. if (qp->ibqp.qp_num == 0)
  143. ibp->rvp.n_vl15_dropped++;
  144. goto bail_unlock;
  145. }
  146. }
  147. /* Silently drop packets which are too big. */
  148. if (unlikely(wc.byte_len > qp->r_len)) {
  149. qp->r_flags |= RVT_R_REUSE_SGE;
  150. ibp->rvp.n_pkt_drops++;
  151. goto bail_unlock;
  152. }
  153. if (ah_attr->ah_flags & IB_AH_GRH) {
  154. qib_copy_sge(&qp->r_sge, &ah_attr->grh,
  155. sizeof(struct ib_grh), 1);
  156. wc.wc_flags |= IB_WC_GRH;
  157. } else
  158. qib_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
  159. ssge.sg_list = swqe->sg_list + 1;
  160. ssge.sge = *swqe->sg_list;
  161. ssge.num_sge = swqe->wr.num_sge;
  162. sge = &ssge.sge;
  163. while (length) {
  164. u32 len = sge->length;
  165. if (len > length)
  166. len = length;
  167. if (len > sge->sge_length)
  168. len = sge->sge_length;
  169. BUG_ON(len == 0);
  170. qib_copy_sge(&qp->r_sge, sge->vaddr, len, 1);
  171. sge->vaddr += len;
  172. sge->length -= len;
  173. sge->sge_length -= len;
  174. if (sge->sge_length == 0) {
  175. if (--ssge.num_sge)
  176. *sge = *ssge.sg_list++;
  177. } else if (sge->length == 0 && sge->mr->lkey) {
  178. if (++sge->n >= RVT_SEGSZ) {
  179. if (++sge->m >= sge->mr->mapsz)
  180. break;
  181. sge->n = 0;
  182. }
  183. sge->vaddr =
  184. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  185. sge->length =
  186. sge->mr->map[sge->m]->segs[sge->n].length;
  187. }
  188. length -= len;
  189. }
  190. rvt_put_ss(&qp->r_sge);
  191. if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
  192. goto bail_unlock;
  193. wc.wr_id = qp->r_wr_id;
  194. wc.status = IB_WC_SUCCESS;
  195. wc.opcode = IB_WC_RECV;
  196. wc.qp = &qp->ibqp;
  197. wc.src_qp = sqp->ibqp.qp_num;
  198. wc.pkey_index = qp->ibqp.qp_type == IB_QPT_GSI ?
  199. swqe->ud_wr.pkey_index : 0;
  200. wc.slid = ppd->lid | (ah_attr->src_path_bits & ((1 << ppd->lmc) - 1));
  201. wc.sl = ah_attr->sl;
  202. wc.dlid_path_bits = ah_attr->dlid & ((1 << ppd->lmc) - 1);
  203. wc.port_num = qp->port_num;
  204. /* Signal completion event if the solicited bit is set. */
  205. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
  206. swqe->wr.send_flags & IB_SEND_SOLICITED);
  207. ibp->rvp.n_loop_pkts++;
  208. bail_unlock:
  209. spin_unlock_irqrestore(&qp->r_lock, flags);
  210. drop:
  211. rcu_read_unlock();
  212. }
  213. /**
  214. * qib_make_ud_req - construct a UD request packet
  215. * @qp: the QP
  216. *
  217. * Assumes the s_lock is held.
  218. *
  219. * Return 1 if constructed; otherwise, return 0.
  220. */
  221. int qib_make_ud_req(struct rvt_qp *qp)
  222. {
  223. struct qib_qp_priv *priv = qp->priv;
  224. struct qib_other_headers *ohdr;
  225. struct ib_ah_attr *ah_attr;
  226. struct qib_pportdata *ppd;
  227. struct qib_ibport *ibp;
  228. struct rvt_swqe *wqe;
  229. u32 nwords;
  230. u32 extra_bytes;
  231. u32 bth0;
  232. u16 lrh0;
  233. u16 lid;
  234. int ret = 0;
  235. int next_cur;
  236. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
  237. if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
  238. goto bail;
  239. /* We are in the error state, flush the work request. */
  240. smp_read_barrier_depends(); /* see post_one_send */
  241. if (qp->s_last == ACCESS_ONCE(qp->s_head))
  242. goto bail;
  243. /* If DMAs are in progress, we can't flush immediately. */
  244. if (atomic_read(&priv->s_dma_busy)) {
  245. qp->s_flags |= RVT_S_WAIT_DMA;
  246. goto bail;
  247. }
  248. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  249. qib_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
  250. goto done;
  251. }
  252. /* see post_one_send() */
  253. smp_read_barrier_depends();
  254. if (qp->s_cur == ACCESS_ONCE(qp->s_head))
  255. goto bail;
  256. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  257. next_cur = qp->s_cur + 1;
  258. if (next_cur >= qp->s_size)
  259. next_cur = 0;
  260. /* Construct the header. */
  261. ibp = to_iport(qp->ibqp.device, qp->port_num);
  262. ppd = ppd_from_ibp(ibp);
  263. ah_attr = &ibah_to_rvtah(wqe->ud_wr.ah)->attr;
  264. if (ah_attr->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE)) {
  265. if (ah_attr->dlid != be16_to_cpu(IB_LID_PERMISSIVE))
  266. this_cpu_inc(ibp->pmastats->n_multicast_xmit);
  267. else
  268. this_cpu_inc(ibp->pmastats->n_unicast_xmit);
  269. } else {
  270. this_cpu_inc(ibp->pmastats->n_unicast_xmit);
  271. lid = ah_attr->dlid & ~((1 << ppd->lmc) - 1);
  272. if (unlikely(lid == ppd->lid)) {
  273. unsigned long flags;
  274. /*
  275. * If DMAs are in progress, we can't generate
  276. * a completion for the loopback packet since
  277. * it would be out of order.
  278. * XXX Instead of waiting, we could queue a
  279. * zero length descriptor so we get a callback.
  280. */
  281. if (atomic_read(&priv->s_dma_busy)) {
  282. qp->s_flags |= RVT_S_WAIT_DMA;
  283. goto bail;
  284. }
  285. qp->s_cur = next_cur;
  286. local_irq_save(flags);
  287. spin_unlock_irqrestore(&qp->s_lock, flags);
  288. qib_ud_loopback(qp, wqe);
  289. spin_lock_irqsave(&qp->s_lock, flags);
  290. qib_send_complete(qp, wqe, IB_WC_SUCCESS);
  291. goto done;
  292. }
  293. }
  294. qp->s_cur = next_cur;
  295. extra_bytes = -wqe->length & 3;
  296. nwords = (wqe->length + extra_bytes) >> 2;
  297. /* header size in 32-bit words LRH+BTH+DETH = (8+12+8)/4. */
  298. qp->s_hdrwords = 7;
  299. qp->s_cur_size = wqe->length;
  300. qp->s_cur_sge = &qp->s_sge;
  301. qp->s_srate = ah_attr->static_rate;
  302. qp->s_wqe = wqe;
  303. qp->s_sge.sge = wqe->sg_list[0];
  304. qp->s_sge.sg_list = wqe->sg_list + 1;
  305. qp->s_sge.num_sge = wqe->wr.num_sge;
  306. qp->s_sge.total_len = wqe->length;
  307. if (ah_attr->ah_flags & IB_AH_GRH) {
  308. /* Header size in 32-bit words. */
  309. qp->s_hdrwords += qib_make_grh(ibp, &priv->s_hdr->u.l.grh,
  310. &ah_attr->grh,
  311. qp->s_hdrwords, nwords);
  312. lrh0 = QIB_LRH_GRH;
  313. ohdr = &priv->s_hdr->u.l.oth;
  314. /*
  315. * Don't worry about sending to locally attached multicast
  316. * QPs. It is unspecified by the spec. what happens.
  317. */
  318. } else {
  319. /* Header size in 32-bit words. */
  320. lrh0 = QIB_LRH_BTH;
  321. ohdr = &priv->s_hdr->u.oth;
  322. }
  323. if (wqe->wr.opcode == IB_WR_SEND_WITH_IMM) {
  324. qp->s_hdrwords++;
  325. ohdr->u.ud.imm_data = wqe->wr.ex.imm_data;
  326. bth0 = IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE << 24;
  327. } else
  328. bth0 = IB_OPCODE_UD_SEND_ONLY << 24;
  329. lrh0 |= ah_attr->sl << 4;
  330. if (qp->ibqp.qp_type == IB_QPT_SMI)
  331. lrh0 |= 0xF000; /* Set VL (see ch. 13.5.3.1) */
  332. else
  333. lrh0 |= ibp->sl_to_vl[ah_attr->sl] << 12;
  334. priv->s_hdr->lrh[0] = cpu_to_be16(lrh0);
  335. priv->s_hdr->lrh[1] = cpu_to_be16(ah_attr->dlid); /* DEST LID */
  336. priv->s_hdr->lrh[2] =
  337. cpu_to_be16(qp->s_hdrwords + nwords + SIZE_OF_CRC);
  338. lid = ppd->lid;
  339. if (lid) {
  340. lid |= ah_attr->src_path_bits & ((1 << ppd->lmc) - 1);
  341. priv->s_hdr->lrh[3] = cpu_to_be16(lid);
  342. } else
  343. priv->s_hdr->lrh[3] = IB_LID_PERMISSIVE;
  344. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  345. bth0 |= IB_BTH_SOLICITED;
  346. bth0 |= extra_bytes << 20;
  347. bth0 |= qp->ibqp.qp_type == IB_QPT_SMI ? QIB_DEFAULT_P_KEY :
  348. qib_get_pkey(ibp, qp->ibqp.qp_type == IB_QPT_GSI ?
  349. wqe->ud_wr.pkey_index : qp->s_pkey_index);
  350. ohdr->bth[0] = cpu_to_be32(bth0);
  351. /*
  352. * Use the multicast QP if the destination LID is a multicast LID.
  353. */
  354. ohdr->bth[1] = ah_attr->dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) &&
  355. ah_attr->dlid != be16_to_cpu(IB_LID_PERMISSIVE) ?
  356. cpu_to_be32(QIB_MULTICAST_QPN) :
  357. cpu_to_be32(wqe->ud_wr.remote_qpn);
  358. ohdr->bth[2] = cpu_to_be32(wqe->psn & QIB_PSN_MASK);
  359. /*
  360. * Qkeys with the high order bit set mean use the
  361. * qkey from the QP context instead of the WR (see 10.2.5).
  362. */
  363. ohdr->u.ud.deth[0] = cpu_to_be32((int)wqe->ud_wr.remote_qkey < 0 ?
  364. qp->qkey : wqe->ud_wr.remote_qkey);
  365. ohdr->u.ud.deth[1] = cpu_to_be32(qp->ibqp.qp_num);
  366. done:
  367. return 1;
  368. bail:
  369. qp->s_flags &= ~RVT_S_BUSY;
  370. return ret;
  371. }
  372. static unsigned qib_lookup_pkey(struct qib_ibport *ibp, u16 pkey)
  373. {
  374. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  375. struct qib_devdata *dd = ppd->dd;
  376. unsigned ctxt = ppd->hw_pidx;
  377. unsigned i;
  378. pkey &= 0x7fff; /* remove limited/full membership bit */
  379. for (i = 0; i < ARRAY_SIZE(dd->rcd[ctxt]->pkeys); ++i)
  380. if ((dd->rcd[ctxt]->pkeys[i] & 0x7fff) == pkey)
  381. return i;
  382. /*
  383. * Should not get here, this means hardware failed to validate pkeys.
  384. * Punt and return index 0.
  385. */
  386. return 0;
  387. }
  388. /**
  389. * qib_ud_rcv - receive an incoming UD packet
  390. * @ibp: the port the packet came in on
  391. * @hdr: the packet header
  392. * @has_grh: true if the packet has a GRH
  393. * @data: the packet data
  394. * @tlen: the packet length
  395. * @qp: the QP the packet came on
  396. *
  397. * This is called from qib_qp_rcv() to process an incoming UD packet
  398. * for the given QP.
  399. * Called at interrupt level.
  400. */
  401. void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
  402. int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
  403. {
  404. struct qib_other_headers *ohdr;
  405. int opcode;
  406. u32 hdrsize;
  407. u32 pad;
  408. struct ib_wc wc;
  409. u32 qkey;
  410. u32 src_qp;
  411. u16 dlid;
  412. /* Check for GRH */
  413. if (!has_grh) {
  414. ohdr = &hdr->u.oth;
  415. hdrsize = 8 + 12 + 8; /* LRH + BTH + DETH */
  416. } else {
  417. ohdr = &hdr->u.l.oth;
  418. hdrsize = 8 + 40 + 12 + 8; /* LRH + GRH + BTH + DETH */
  419. }
  420. qkey = be32_to_cpu(ohdr->u.ud.deth[0]);
  421. src_qp = be32_to_cpu(ohdr->u.ud.deth[1]) & RVT_QPN_MASK;
  422. /*
  423. * Get the number of bytes the message was padded by
  424. * and drop incomplete packets.
  425. */
  426. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  427. if (unlikely(tlen < (hdrsize + pad + 4)))
  428. goto drop;
  429. tlen -= hdrsize + pad + 4;
  430. /*
  431. * Check that the permissive LID is only used on QP0
  432. * and the QKEY matches (see 9.6.1.4.1 and 9.6.1.5.1).
  433. */
  434. if (qp->ibqp.qp_num) {
  435. if (unlikely(hdr->lrh[1] == IB_LID_PERMISSIVE ||
  436. hdr->lrh[3] == IB_LID_PERMISSIVE))
  437. goto drop;
  438. if (qp->ibqp.qp_num > 1) {
  439. u16 pkey1, pkey2;
  440. pkey1 = be32_to_cpu(ohdr->bth[0]);
  441. pkey2 = qib_get_pkey(ibp, qp->s_pkey_index);
  442. if (unlikely(!qib_pkey_ok(pkey1, pkey2))) {
  443. qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_PKEY,
  444. pkey1,
  445. (be16_to_cpu(hdr->lrh[0]) >> 4) &
  446. 0xF,
  447. src_qp, qp->ibqp.qp_num,
  448. hdr->lrh[3], hdr->lrh[1]);
  449. return;
  450. }
  451. }
  452. if (unlikely(qkey != qp->qkey)) {
  453. qib_bad_pqkey(ibp, IB_NOTICE_TRAP_BAD_QKEY, qkey,
  454. (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF,
  455. src_qp, qp->ibqp.qp_num,
  456. hdr->lrh[3], hdr->lrh[1]);
  457. return;
  458. }
  459. /* Drop invalid MAD packets (see 13.5.3.1). */
  460. if (unlikely(qp->ibqp.qp_num == 1 &&
  461. (tlen != 256 ||
  462. (be16_to_cpu(hdr->lrh[0]) >> 12) == 15)))
  463. goto drop;
  464. } else {
  465. struct ib_smp *smp;
  466. /* Drop invalid MAD packets (see 13.5.3.1). */
  467. if (tlen != 256 || (be16_to_cpu(hdr->lrh[0]) >> 12) != 15)
  468. goto drop;
  469. smp = (struct ib_smp *) data;
  470. if ((hdr->lrh[1] == IB_LID_PERMISSIVE ||
  471. hdr->lrh[3] == IB_LID_PERMISSIVE) &&
  472. smp->mgmt_class != IB_MGMT_CLASS_SUBN_DIRECTED_ROUTE)
  473. goto drop;
  474. }
  475. /*
  476. * The opcode is in the low byte when its in network order
  477. * (top byte when in host order).
  478. */
  479. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  480. if (qp->ibqp.qp_num > 1 &&
  481. opcode == IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE) {
  482. wc.ex.imm_data = ohdr->u.ud.imm_data;
  483. wc.wc_flags = IB_WC_WITH_IMM;
  484. tlen -= sizeof(u32);
  485. } else if (opcode == IB_OPCODE_UD_SEND_ONLY) {
  486. wc.ex.imm_data = 0;
  487. wc.wc_flags = 0;
  488. } else
  489. goto drop;
  490. /*
  491. * A GRH is expected to precede the data even if not
  492. * present on the wire.
  493. */
  494. wc.byte_len = tlen + sizeof(struct ib_grh);
  495. /*
  496. * Get the next work request entry to find where to put the data.
  497. */
  498. if (qp->r_flags & RVT_R_REUSE_SGE)
  499. qp->r_flags &= ~RVT_R_REUSE_SGE;
  500. else {
  501. int ret;
  502. ret = qib_get_rwqe(qp, 0);
  503. if (ret < 0) {
  504. qib_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  505. return;
  506. }
  507. if (!ret) {
  508. if (qp->ibqp.qp_num == 0)
  509. ibp->rvp.n_vl15_dropped++;
  510. return;
  511. }
  512. }
  513. /* Silently drop packets which are too big. */
  514. if (unlikely(wc.byte_len > qp->r_len)) {
  515. qp->r_flags |= RVT_R_REUSE_SGE;
  516. goto drop;
  517. }
  518. if (has_grh) {
  519. qib_copy_sge(&qp->r_sge, &hdr->u.l.grh,
  520. sizeof(struct ib_grh), 1);
  521. wc.wc_flags |= IB_WC_GRH;
  522. } else
  523. qib_skip_sge(&qp->r_sge, sizeof(struct ib_grh), 1);
  524. qib_copy_sge(&qp->r_sge, data, wc.byte_len - sizeof(struct ib_grh), 1);
  525. rvt_put_ss(&qp->r_sge);
  526. if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
  527. return;
  528. wc.wr_id = qp->r_wr_id;
  529. wc.status = IB_WC_SUCCESS;
  530. wc.opcode = IB_WC_RECV;
  531. wc.vendor_err = 0;
  532. wc.qp = &qp->ibqp;
  533. wc.src_qp = src_qp;
  534. wc.pkey_index = qp->ibqp.qp_type == IB_QPT_GSI ?
  535. qib_lookup_pkey(ibp, be32_to_cpu(ohdr->bth[0])) : 0;
  536. wc.slid = be16_to_cpu(hdr->lrh[3]);
  537. wc.sl = (be16_to_cpu(hdr->lrh[0]) >> 4) & 0xF;
  538. dlid = be16_to_cpu(hdr->lrh[1]);
  539. /*
  540. * Save the LMC lower bits if the destination LID is a unicast LID.
  541. */
  542. wc.dlid_path_bits = dlid >= be16_to_cpu(IB_MULTICAST_LID_BASE) ? 0 :
  543. dlid & ((1 << ppd_from_ibp(ibp)->lmc) - 1);
  544. wc.port_num = qp->port_num;
  545. /* Signal completion event if the solicited bit is set. */
  546. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
  547. (ohdr->bth[0] &
  548. cpu_to_be32(IB_BTH_SOLICITED)) != 0);
  549. return;
  550. drop:
  551. ibp->rvp.n_pkt_drops++;
  552. }