uc.c 16 KB

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