uc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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 "hfi.h"
  48. #include "verbs_txreq.h"
  49. #include "qp.h"
  50. /* cut down ridiculously long IB macro names */
  51. #define OP(x) UC_OP(x)
  52. /**
  53. * hfi1_make_uc_req - construct a request packet (SEND, RDMA write)
  54. * @qp: a pointer to the QP
  55. *
  56. * Assume s_lock is held.
  57. *
  58. * Return 1 if constructed; otherwise, return 0.
  59. */
  60. int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps)
  61. {
  62. struct hfi1_qp_priv *priv = qp->priv;
  63. struct ib_other_headers *ohdr;
  64. struct rvt_swqe *wqe;
  65. u32 hwords;
  66. u32 bth0 = 0;
  67. u32 len;
  68. u32 pmtu = qp->pmtu;
  69. int middle = 0;
  70. ps->s_txreq = get_txreq(ps->dev, qp);
  71. if (!ps->s_txreq)
  72. goto bail_no_tx;
  73. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) {
  74. if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
  75. goto bail;
  76. /* We are in the error state, flush the work request. */
  77. if (qp->s_last == READ_ONCE(qp->s_head))
  78. goto bail;
  79. /* If DMAs are in progress, we can't flush immediately. */
  80. if (iowait_sdma_pending(&priv->s_iowait)) {
  81. qp->s_flags |= RVT_S_WAIT_DMA;
  82. goto bail;
  83. }
  84. clear_ahg(qp);
  85. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  86. hfi1_send_complete(qp, wqe, IB_WC_WR_FLUSH_ERR);
  87. goto done_free_tx;
  88. }
  89. if (priv->hdr_type == HFI1_PKT_TYPE_9B) {
  90. /* header size in 32-bit words LRH+BTH = (8+12)/4. */
  91. hwords = 5;
  92. if (rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH)
  93. ohdr = &ps->s_txreq->phdr.hdr.ibh.u.l.oth;
  94. else
  95. ohdr = &ps->s_txreq->phdr.hdr.ibh.u.oth;
  96. } else {
  97. /* header size in 32-bit words 16B LRH+BTH = (16+12)/4. */
  98. hwords = 7;
  99. if ((rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH) &&
  100. (hfi1_check_mcast(rdma_ah_get_dlid(&qp->remote_ah_attr))))
  101. ohdr = &ps->s_txreq->phdr.hdr.opah.u.l.oth;
  102. else
  103. ohdr = &ps->s_txreq->phdr.hdr.opah.u.oth;
  104. }
  105. /* Get the next send request. */
  106. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  107. qp->s_wqe = NULL;
  108. switch (qp->s_state) {
  109. default:
  110. if (!(ib_rvt_state_ops[qp->state] &
  111. RVT_PROCESS_NEXT_SEND_OK))
  112. goto bail;
  113. /* Check if send work queue is empty. */
  114. if (qp->s_cur == READ_ONCE(qp->s_head)) {
  115. clear_ahg(qp);
  116. goto bail;
  117. }
  118. /*
  119. * Local operations are processed immediately
  120. * after all prior requests have completed.
  121. */
  122. if (wqe->wr.opcode == IB_WR_REG_MR ||
  123. wqe->wr.opcode == IB_WR_LOCAL_INV) {
  124. int local_ops = 0;
  125. int err = 0;
  126. if (qp->s_last != qp->s_cur)
  127. goto bail;
  128. if (++qp->s_cur == qp->s_size)
  129. qp->s_cur = 0;
  130. if (!(wqe->wr.send_flags & RVT_SEND_COMPLETION_ONLY)) {
  131. err = rvt_invalidate_rkey(
  132. qp, wqe->wr.ex.invalidate_rkey);
  133. local_ops = 1;
  134. }
  135. hfi1_send_complete(qp, wqe, err ? IB_WC_LOC_PROT_ERR
  136. : IB_WC_SUCCESS);
  137. if (local_ops)
  138. atomic_dec(&qp->local_ops_pending);
  139. goto done_free_tx;
  140. }
  141. /*
  142. * Start a new request.
  143. */
  144. qp->s_psn = wqe->psn;
  145. qp->s_sge.sge = wqe->sg_list[0];
  146. qp->s_sge.sg_list = wqe->sg_list + 1;
  147. qp->s_sge.num_sge = wqe->wr.num_sge;
  148. qp->s_sge.total_len = wqe->length;
  149. len = wqe->length;
  150. qp->s_len = len;
  151. switch (wqe->wr.opcode) {
  152. case IB_WR_SEND:
  153. case IB_WR_SEND_WITH_IMM:
  154. if (len > pmtu) {
  155. qp->s_state = OP(SEND_FIRST);
  156. len = pmtu;
  157. break;
  158. }
  159. if (wqe->wr.opcode == IB_WR_SEND) {
  160. qp->s_state = OP(SEND_ONLY);
  161. } else {
  162. qp->s_state =
  163. OP(SEND_ONLY_WITH_IMMEDIATE);
  164. /* Immediate data comes after the BTH */
  165. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  166. hwords += 1;
  167. }
  168. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  169. bth0 |= IB_BTH_SOLICITED;
  170. qp->s_wqe = wqe;
  171. if (++qp->s_cur >= qp->s_size)
  172. qp->s_cur = 0;
  173. break;
  174. case IB_WR_RDMA_WRITE:
  175. case IB_WR_RDMA_WRITE_WITH_IMM:
  176. ohdr->u.rc.reth.vaddr =
  177. cpu_to_be64(wqe->rdma_wr.remote_addr);
  178. ohdr->u.rc.reth.rkey =
  179. cpu_to_be32(wqe->rdma_wr.rkey);
  180. ohdr->u.rc.reth.length = cpu_to_be32(len);
  181. hwords += sizeof(struct ib_reth) / 4;
  182. if (len > pmtu) {
  183. qp->s_state = OP(RDMA_WRITE_FIRST);
  184. len = pmtu;
  185. break;
  186. }
  187. if (wqe->wr.opcode == IB_WR_RDMA_WRITE) {
  188. qp->s_state = OP(RDMA_WRITE_ONLY);
  189. } else {
  190. qp->s_state =
  191. OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
  192. /* Immediate data comes after the RETH */
  193. ohdr->u.rc.imm_data = wqe->wr.ex.imm_data;
  194. hwords += 1;
  195. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  196. bth0 |= IB_BTH_SOLICITED;
  197. }
  198. qp->s_wqe = wqe;
  199. if (++qp->s_cur >= qp->s_size)
  200. qp->s_cur = 0;
  201. break;
  202. default:
  203. goto bail;
  204. }
  205. break;
  206. case OP(SEND_FIRST):
  207. qp->s_state = OP(SEND_MIDDLE);
  208. /* FALLTHROUGH */
  209. case OP(SEND_MIDDLE):
  210. len = qp->s_len;
  211. if (len > pmtu) {
  212. len = pmtu;
  213. middle = HFI1_CAP_IS_KSET(SDMA_AHG);
  214. break;
  215. }
  216. if (wqe->wr.opcode == IB_WR_SEND) {
  217. qp->s_state = OP(SEND_LAST);
  218. } else {
  219. qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
  220. /* Immediate data comes after the BTH */
  221. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  222. hwords += 1;
  223. }
  224. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  225. bth0 |= IB_BTH_SOLICITED;
  226. qp->s_wqe = wqe;
  227. if (++qp->s_cur >= qp->s_size)
  228. qp->s_cur = 0;
  229. break;
  230. case OP(RDMA_WRITE_FIRST):
  231. qp->s_state = OP(RDMA_WRITE_MIDDLE);
  232. /* FALLTHROUGH */
  233. case OP(RDMA_WRITE_MIDDLE):
  234. len = qp->s_len;
  235. if (len > pmtu) {
  236. len = pmtu;
  237. middle = HFI1_CAP_IS_KSET(SDMA_AHG);
  238. break;
  239. }
  240. if (wqe->wr.opcode == IB_WR_RDMA_WRITE) {
  241. qp->s_state = OP(RDMA_WRITE_LAST);
  242. } else {
  243. qp->s_state =
  244. OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
  245. /* Immediate data comes after the BTH */
  246. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  247. hwords += 1;
  248. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  249. bth0 |= IB_BTH_SOLICITED;
  250. }
  251. qp->s_wqe = wqe;
  252. if (++qp->s_cur >= qp->s_size)
  253. qp->s_cur = 0;
  254. break;
  255. }
  256. qp->s_len -= len;
  257. ps->s_txreq->hdr_dwords = hwords;
  258. ps->s_txreq->sde = priv->s_sde;
  259. ps->s_txreq->ss = &qp->s_sge;
  260. ps->s_txreq->s_cur_size = len;
  261. hfi1_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24),
  262. mask_psn(qp->s_psn++), middle, ps);
  263. return 1;
  264. done_free_tx:
  265. hfi1_put_txreq(ps->s_txreq);
  266. ps->s_txreq = NULL;
  267. return 1;
  268. bail:
  269. hfi1_put_txreq(ps->s_txreq);
  270. bail_no_tx:
  271. ps->s_txreq = NULL;
  272. qp->s_flags &= ~RVT_S_BUSY;
  273. return 0;
  274. }
  275. /**
  276. * hfi1_uc_rcv - handle an incoming UC packet
  277. * @ibp: the port the packet came in on
  278. * @hdr: the header of the packet
  279. * @rcv_flags: flags relevant to rcv processing
  280. * @data: the packet data
  281. * @tlen: the length of the packet
  282. * @qp: the QP for this packet.
  283. *
  284. * This is called from qp_rcv() to process an incoming UC packet
  285. * for the given QP.
  286. * Called at interrupt level.
  287. */
  288. void hfi1_uc_rcv(struct hfi1_packet *packet)
  289. {
  290. struct hfi1_ibport *ibp = rcd_to_iport(packet->rcd);
  291. void *data = packet->payload;
  292. u32 tlen = packet->tlen;
  293. struct rvt_qp *qp = packet->qp;
  294. struct ib_other_headers *ohdr = packet->ohdr;
  295. u32 opcode = packet->opcode;
  296. u32 hdrsize = packet->hlen;
  297. u32 psn;
  298. u32 pad = packet->pad;
  299. struct ib_wc wc;
  300. u32 pmtu = qp->pmtu;
  301. struct ib_reth *reth;
  302. int ret;
  303. u8 extra_bytes = pad + packet->extra_byte + (SIZE_OF_CRC << 2);
  304. if (hfi1_ruc_check_hdr(ibp, packet))
  305. return;
  306. process_ecn(qp, packet);
  307. psn = ib_bth_get_psn(ohdr);
  308. /* Compare the PSN verses the expected PSN. */
  309. if (unlikely(cmp_psn(psn, qp->r_psn) != 0)) {
  310. /*
  311. * Handle a sequence error.
  312. * Silently drop any current message.
  313. */
  314. qp->r_psn = psn;
  315. inv:
  316. if (qp->r_state == OP(SEND_FIRST) ||
  317. qp->r_state == OP(SEND_MIDDLE)) {
  318. set_bit(RVT_R_REWIND_SGE, &qp->r_aflags);
  319. qp->r_sge.num_sge = 0;
  320. } else {
  321. rvt_put_ss(&qp->r_sge);
  322. }
  323. qp->r_state = OP(SEND_LAST);
  324. switch (opcode) {
  325. case OP(SEND_FIRST):
  326. case OP(SEND_ONLY):
  327. case OP(SEND_ONLY_WITH_IMMEDIATE):
  328. goto send_first;
  329. case OP(RDMA_WRITE_FIRST):
  330. case OP(RDMA_WRITE_ONLY):
  331. case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
  332. goto rdma_first;
  333. default:
  334. goto drop;
  335. }
  336. }
  337. /* Check for opcode sequence errors. */
  338. switch (qp->r_state) {
  339. case OP(SEND_FIRST):
  340. case OP(SEND_MIDDLE):
  341. if (opcode == OP(SEND_MIDDLE) ||
  342. opcode == OP(SEND_LAST) ||
  343. opcode == OP(SEND_LAST_WITH_IMMEDIATE))
  344. break;
  345. goto inv;
  346. case OP(RDMA_WRITE_FIRST):
  347. case OP(RDMA_WRITE_MIDDLE):
  348. if (opcode == OP(RDMA_WRITE_MIDDLE) ||
  349. opcode == OP(RDMA_WRITE_LAST) ||
  350. opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
  351. break;
  352. goto inv;
  353. default:
  354. if (opcode == OP(SEND_FIRST) ||
  355. opcode == OP(SEND_ONLY) ||
  356. opcode == OP(SEND_ONLY_WITH_IMMEDIATE) ||
  357. opcode == OP(RDMA_WRITE_FIRST) ||
  358. opcode == OP(RDMA_WRITE_ONLY) ||
  359. opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE))
  360. break;
  361. goto inv;
  362. }
  363. if (qp->state == IB_QPS_RTR && !(qp->r_flags & RVT_R_COMM_EST))
  364. rvt_comm_est(qp);
  365. /* OK, process the packet. */
  366. switch (opcode) {
  367. case OP(SEND_FIRST):
  368. case OP(SEND_ONLY):
  369. case OP(SEND_ONLY_WITH_IMMEDIATE):
  370. send_first:
  371. if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) {
  372. qp->r_sge = qp->s_rdma_read_sge;
  373. } else {
  374. ret = rvt_get_rwqe(qp, false);
  375. if (ret < 0)
  376. goto op_err;
  377. if (!ret)
  378. goto drop;
  379. /*
  380. * qp->s_rdma_read_sge will be the owner
  381. * of the mr references.
  382. */
  383. qp->s_rdma_read_sge = qp->r_sge;
  384. }
  385. qp->r_rcv_len = 0;
  386. if (opcode == OP(SEND_ONLY))
  387. goto no_immediate_data;
  388. else if (opcode == OP(SEND_ONLY_WITH_IMMEDIATE))
  389. goto send_last_imm;
  390. /* FALLTHROUGH */
  391. case OP(SEND_MIDDLE):
  392. /* Check for invalid length PMTU or posted rwqe len. */
  393. /*
  394. * There will be no padding for 9B packet but 16B packets
  395. * will come in with some padding since we always add
  396. * CRC and LT bytes which will need to be flit aligned
  397. */
  398. if (unlikely(tlen != (hdrsize + pmtu + extra_bytes)))
  399. goto rewind;
  400. qp->r_rcv_len += pmtu;
  401. if (unlikely(qp->r_rcv_len > qp->r_len))
  402. goto rewind;
  403. hfi1_copy_sge(&qp->r_sge, data, pmtu, false, false);
  404. break;
  405. case OP(SEND_LAST_WITH_IMMEDIATE):
  406. send_last_imm:
  407. wc.ex.imm_data = ohdr->u.imm_data;
  408. wc.wc_flags = IB_WC_WITH_IMM;
  409. goto send_last;
  410. case OP(SEND_LAST):
  411. no_immediate_data:
  412. wc.ex.imm_data = 0;
  413. wc.wc_flags = 0;
  414. send_last:
  415. /* Check for invalid length. */
  416. /* LAST len should be >= 1 */
  417. if (unlikely(tlen < (hdrsize + extra_bytes)))
  418. goto rewind;
  419. /* Don't count the CRC. */
  420. tlen -= (hdrsize + extra_bytes);
  421. wc.byte_len = tlen + qp->r_rcv_len;
  422. if (unlikely(wc.byte_len > qp->r_len))
  423. goto rewind;
  424. wc.opcode = IB_WC_RECV;
  425. hfi1_copy_sge(&qp->r_sge, data, tlen, false, false);
  426. rvt_put_ss(&qp->s_rdma_read_sge);
  427. last_imm:
  428. wc.wr_id = qp->r_wr_id;
  429. wc.status = IB_WC_SUCCESS;
  430. wc.qp = &qp->ibqp;
  431. wc.src_qp = qp->remote_qpn;
  432. wc.slid = rdma_ah_get_dlid(&qp->remote_ah_attr) & U16_MAX;
  433. /*
  434. * It seems that IB mandates the presence of an SL in a
  435. * work completion only for the UD transport (see section
  436. * 11.4.2 of IBTA Vol. 1).
  437. *
  438. * However, the way the SL is chosen below is consistent
  439. * with the way that IB/qib works and is trying avoid
  440. * introducing incompatibilities.
  441. *
  442. * See also OPA Vol. 1, section 9.7.6, and table 9-17.
  443. */
  444. wc.sl = rdma_ah_get_sl(&qp->remote_ah_attr);
  445. /* zero fields that are N/A */
  446. wc.vendor_err = 0;
  447. wc.pkey_index = 0;
  448. wc.dlid_path_bits = 0;
  449. wc.port_num = 0;
  450. /* Signal completion event if the solicited bit is set. */
  451. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
  452. ib_bth_is_solicited(ohdr));
  453. break;
  454. case OP(RDMA_WRITE_FIRST):
  455. case OP(RDMA_WRITE_ONLY):
  456. case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE): /* consume RWQE */
  457. rdma_first:
  458. if (unlikely(!(qp->qp_access_flags &
  459. IB_ACCESS_REMOTE_WRITE))) {
  460. goto drop;
  461. }
  462. reth = &ohdr->u.rc.reth;
  463. qp->r_len = be32_to_cpu(reth->length);
  464. qp->r_rcv_len = 0;
  465. qp->r_sge.sg_list = NULL;
  466. if (qp->r_len != 0) {
  467. u32 rkey = be32_to_cpu(reth->rkey);
  468. u64 vaddr = be64_to_cpu(reth->vaddr);
  469. int ok;
  470. /* Check rkey */
  471. ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len,
  472. vaddr, rkey, IB_ACCESS_REMOTE_WRITE);
  473. if (unlikely(!ok))
  474. goto drop;
  475. qp->r_sge.num_sge = 1;
  476. } else {
  477. qp->r_sge.num_sge = 0;
  478. qp->r_sge.sge.mr = NULL;
  479. qp->r_sge.sge.vaddr = NULL;
  480. qp->r_sge.sge.length = 0;
  481. qp->r_sge.sge.sge_length = 0;
  482. }
  483. if (opcode == OP(RDMA_WRITE_ONLY)) {
  484. goto rdma_last;
  485. } else if (opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE)) {
  486. wc.ex.imm_data = ohdr->u.rc.imm_data;
  487. goto rdma_last_imm;
  488. }
  489. /* FALLTHROUGH */
  490. case OP(RDMA_WRITE_MIDDLE):
  491. /* Check for invalid length PMTU or posted rwqe len. */
  492. if (unlikely(tlen != (hdrsize + pmtu + 4)))
  493. goto drop;
  494. qp->r_rcv_len += pmtu;
  495. if (unlikely(qp->r_rcv_len > qp->r_len))
  496. goto drop;
  497. hfi1_copy_sge(&qp->r_sge, data, pmtu, true, false);
  498. break;
  499. case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
  500. wc.ex.imm_data = ohdr->u.imm_data;
  501. rdma_last_imm:
  502. wc.wc_flags = IB_WC_WITH_IMM;
  503. /* Check for invalid length. */
  504. /* LAST len should be >= 1 */
  505. if (unlikely(tlen < (hdrsize + pad + 4)))
  506. goto drop;
  507. /* Don't count the CRC. */
  508. tlen -= (hdrsize + extra_bytes);
  509. if (unlikely(tlen + qp->r_rcv_len != qp->r_len))
  510. goto drop;
  511. if (test_and_clear_bit(RVT_R_REWIND_SGE, &qp->r_aflags)) {
  512. rvt_put_ss(&qp->s_rdma_read_sge);
  513. } else {
  514. ret = rvt_get_rwqe(qp, true);
  515. if (ret < 0)
  516. goto op_err;
  517. if (!ret)
  518. goto drop;
  519. }
  520. wc.byte_len = qp->r_len;
  521. wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;
  522. hfi1_copy_sge(&qp->r_sge, data, tlen, true, false);
  523. rvt_put_ss(&qp->r_sge);
  524. goto last_imm;
  525. case OP(RDMA_WRITE_LAST):
  526. rdma_last:
  527. /* Check for invalid length. */
  528. /* LAST len should be >= 1 */
  529. if (unlikely(tlen < (hdrsize + pad + 4)))
  530. goto drop;
  531. /* Don't count the CRC. */
  532. tlen -= (hdrsize + extra_bytes);
  533. if (unlikely(tlen + qp->r_rcv_len != qp->r_len))
  534. goto drop;
  535. hfi1_copy_sge(&qp->r_sge, data, tlen, true, false);
  536. rvt_put_ss(&qp->r_sge);
  537. break;
  538. default:
  539. /* Drop packet for unknown opcodes. */
  540. goto drop;
  541. }
  542. qp->r_psn++;
  543. qp->r_state = opcode;
  544. return;
  545. rewind:
  546. set_bit(RVT_R_REWIND_SGE, &qp->r_aflags);
  547. qp->r_sge.num_sge = 0;
  548. drop:
  549. ibp->rvp.n_pkt_drops++;
  550. return;
  551. op_err:
  552. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  553. }