ruc.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110
  1. /*
  2. * Copyright(c) 2015 - 2017 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 <linux/spinlock.h>
  48. #include "hfi.h"
  49. #include "mad.h"
  50. #include "qp.h"
  51. #include "verbs_txreq.h"
  52. #include "trace.h"
  53. /*
  54. * Validate a RWQE and fill in the SGE state.
  55. * Return 1 if OK.
  56. */
  57. static int init_sge(struct rvt_qp *qp, struct rvt_rwqe *wqe)
  58. {
  59. int i, j, ret;
  60. struct ib_wc wc;
  61. struct rvt_lkey_table *rkt;
  62. struct rvt_pd *pd;
  63. struct rvt_sge_state *ss;
  64. rkt = &to_idev(qp->ibqp.device)->rdi.lkey_table;
  65. pd = ibpd_to_rvtpd(qp->ibqp.srq ? qp->ibqp.srq->pd : qp->ibqp.pd);
  66. ss = &qp->r_sge;
  67. ss->sg_list = qp->r_sg_list;
  68. qp->r_len = 0;
  69. for (i = j = 0; i < wqe->num_sge; i++) {
  70. if (wqe->sg_list[i].length == 0)
  71. continue;
  72. /* Check LKEY */
  73. ret = rvt_lkey_ok(rkt, pd, j ? &ss->sg_list[j - 1] : &ss->sge,
  74. NULL, &wqe->sg_list[i],
  75. IB_ACCESS_LOCAL_WRITE);
  76. if (unlikely(ret <= 0))
  77. goto bad_lkey;
  78. qp->r_len += wqe->sg_list[i].length;
  79. j++;
  80. }
  81. ss->num_sge = j;
  82. ss->total_len = qp->r_len;
  83. ret = 1;
  84. goto bail;
  85. bad_lkey:
  86. while (j) {
  87. struct rvt_sge *sge = --j ? &ss->sg_list[j - 1] : &ss->sge;
  88. rvt_put_mr(sge->mr);
  89. }
  90. ss->num_sge = 0;
  91. memset(&wc, 0, sizeof(wc));
  92. wc.wr_id = wqe->wr_id;
  93. wc.status = IB_WC_LOC_PROT_ERR;
  94. wc.opcode = IB_WC_RECV;
  95. wc.qp = &qp->ibqp;
  96. /* Signal solicited completion event. */
  97. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc, 1);
  98. ret = 0;
  99. bail:
  100. return ret;
  101. }
  102. /**
  103. * hfi1_rvt_get_rwqe - copy the next RWQE into the QP's RWQE
  104. * @qp: the QP
  105. * @wr_id_only: update qp->r_wr_id only, not qp->r_sge
  106. *
  107. * Return -1 if there is a local error, 0 if no RWQE is available,
  108. * otherwise return 1.
  109. *
  110. * Can be called from interrupt level.
  111. */
  112. int hfi1_rvt_get_rwqe(struct rvt_qp *qp, int wr_id_only)
  113. {
  114. unsigned long flags;
  115. struct rvt_rq *rq;
  116. struct rvt_rwq *wq;
  117. struct rvt_srq *srq;
  118. struct rvt_rwqe *wqe;
  119. void (*handler)(struct ib_event *, void *);
  120. u32 tail;
  121. int ret;
  122. if (qp->ibqp.srq) {
  123. srq = ibsrq_to_rvtsrq(qp->ibqp.srq);
  124. handler = srq->ibsrq.event_handler;
  125. rq = &srq->rq;
  126. } else {
  127. srq = NULL;
  128. handler = NULL;
  129. rq = &qp->r_rq;
  130. }
  131. spin_lock_irqsave(&rq->lock, flags);
  132. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK)) {
  133. ret = 0;
  134. goto unlock;
  135. }
  136. wq = rq->wq;
  137. tail = wq->tail;
  138. /* Validate tail before using it since it is user writable. */
  139. if (tail >= rq->size)
  140. tail = 0;
  141. if (unlikely(tail == wq->head)) {
  142. ret = 0;
  143. goto unlock;
  144. }
  145. /* Make sure entry is read after head index is read. */
  146. smp_rmb();
  147. wqe = rvt_get_rwqe_ptr(rq, tail);
  148. /*
  149. * Even though we update the tail index in memory, the verbs
  150. * consumer is not supposed to post more entries until a
  151. * completion is generated.
  152. */
  153. if (++tail >= rq->size)
  154. tail = 0;
  155. wq->tail = tail;
  156. if (!wr_id_only && !init_sge(qp, wqe)) {
  157. ret = -1;
  158. goto unlock;
  159. }
  160. qp->r_wr_id = wqe->wr_id;
  161. ret = 1;
  162. set_bit(RVT_R_WRID_VALID, &qp->r_aflags);
  163. if (handler) {
  164. u32 n;
  165. /*
  166. * Validate head pointer value and compute
  167. * the number of remaining WQEs.
  168. */
  169. n = wq->head;
  170. if (n >= rq->size)
  171. n = 0;
  172. if (n < tail)
  173. n += rq->size - tail;
  174. else
  175. n -= tail;
  176. if (n < srq->limit) {
  177. struct ib_event ev;
  178. srq->limit = 0;
  179. spin_unlock_irqrestore(&rq->lock, flags);
  180. ev.device = qp->ibqp.device;
  181. ev.element.srq = qp->ibqp.srq;
  182. ev.event = IB_EVENT_SRQ_LIMIT_REACHED;
  183. handler(&ev, srq->ibsrq.srq_context);
  184. goto bail;
  185. }
  186. }
  187. unlock:
  188. spin_unlock_irqrestore(&rq->lock, flags);
  189. bail:
  190. return ret;
  191. }
  192. static int gid_ok(union ib_gid *gid, __be64 gid_prefix, __be64 id)
  193. {
  194. return (gid->global.interface_id == id &&
  195. (gid->global.subnet_prefix == gid_prefix ||
  196. gid->global.subnet_prefix == IB_DEFAULT_GID_PREFIX));
  197. }
  198. /*
  199. *
  200. * This should be called with the QP r_lock held.
  201. *
  202. * The s_lock will be acquired around the hfi1_migrate_qp() call.
  203. */
  204. int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_packet *packet)
  205. {
  206. __be64 guid;
  207. unsigned long flags;
  208. struct rvt_qp *qp = packet->qp;
  209. u8 sc5 = ibp->sl_to_sc[rdma_ah_get_sl(&qp->remote_ah_attr)];
  210. u32 dlid = packet->dlid;
  211. u32 slid = packet->slid;
  212. u32 sl = packet->sl;
  213. bool migrated = packet->migrated;
  214. u16 pkey = packet->pkey;
  215. if (qp->s_mig_state == IB_MIG_ARMED && migrated) {
  216. if (!packet->grh) {
  217. if ((rdma_ah_get_ah_flags(&qp->alt_ah_attr) &
  218. IB_AH_GRH) &&
  219. (packet->etype != RHF_RCV_TYPE_BYPASS))
  220. return 1;
  221. } else {
  222. const struct ib_global_route *grh;
  223. if (!(rdma_ah_get_ah_flags(&qp->alt_ah_attr) &
  224. IB_AH_GRH))
  225. return 1;
  226. grh = rdma_ah_read_grh(&qp->alt_ah_attr);
  227. guid = get_sguid(ibp, grh->sgid_index);
  228. if (!gid_ok(&packet->grh->dgid, ibp->rvp.gid_prefix,
  229. guid))
  230. return 1;
  231. if (!gid_ok(
  232. &packet->grh->sgid,
  233. grh->dgid.global.subnet_prefix,
  234. grh->dgid.global.interface_id))
  235. return 1;
  236. }
  237. if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), pkey,
  238. sc5, slid))) {
  239. hfi1_bad_pkey(ibp, pkey, sl, 0, qp->ibqp.qp_num,
  240. slid, dlid);
  241. return 1;
  242. }
  243. /* Validate the SLID. See Ch. 9.6.1.5 and 17.2.8 */
  244. if (slid != rdma_ah_get_dlid(&qp->alt_ah_attr) ||
  245. ppd_from_ibp(ibp)->port !=
  246. rdma_ah_get_port_num(&qp->alt_ah_attr))
  247. return 1;
  248. spin_lock_irqsave(&qp->s_lock, flags);
  249. hfi1_migrate_qp(qp);
  250. spin_unlock_irqrestore(&qp->s_lock, flags);
  251. } else {
  252. if (!packet->grh) {
  253. if ((rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
  254. IB_AH_GRH) &&
  255. (packet->etype != RHF_RCV_TYPE_BYPASS))
  256. return 1;
  257. } else {
  258. const struct ib_global_route *grh;
  259. if (!(rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
  260. IB_AH_GRH))
  261. return 1;
  262. grh = rdma_ah_read_grh(&qp->remote_ah_attr);
  263. guid = get_sguid(ibp, grh->sgid_index);
  264. if (!gid_ok(&packet->grh->dgid, ibp->rvp.gid_prefix,
  265. guid))
  266. return 1;
  267. if (!gid_ok(
  268. &packet->grh->sgid,
  269. grh->dgid.global.subnet_prefix,
  270. grh->dgid.global.interface_id))
  271. return 1;
  272. }
  273. if (unlikely(rcv_pkey_check(ppd_from_ibp(ibp), pkey,
  274. sc5, slid))) {
  275. hfi1_bad_pkey(ibp, pkey, sl, 0, qp->ibqp.qp_num,
  276. slid, dlid);
  277. return 1;
  278. }
  279. /* Validate the SLID. See Ch. 9.6.1.5 */
  280. if ((slid != rdma_ah_get_dlid(&qp->remote_ah_attr)) ||
  281. ppd_from_ibp(ibp)->port != qp->port_num)
  282. return 1;
  283. if (qp->s_mig_state == IB_MIG_REARM && !migrated)
  284. qp->s_mig_state = IB_MIG_ARMED;
  285. }
  286. return 0;
  287. }
  288. /**
  289. * ruc_loopback - handle UC and RC loopback requests
  290. * @sqp: the sending QP
  291. *
  292. * This is called from hfi1_do_send() to
  293. * forward a WQE addressed to the same HFI.
  294. * Note that although we are single threaded due to the send engine, we still
  295. * have to protect against post_send(). We don't have to worry about
  296. * receive interrupts since this is a connected protocol and all packets
  297. * will pass through here.
  298. */
  299. static void ruc_loopback(struct rvt_qp *sqp)
  300. {
  301. struct hfi1_ibport *ibp = to_iport(sqp->ibqp.device, sqp->port_num);
  302. struct rvt_qp *qp;
  303. struct rvt_swqe *wqe;
  304. struct rvt_sge *sge;
  305. unsigned long flags;
  306. struct ib_wc wc;
  307. u64 sdata;
  308. atomic64_t *maddr;
  309. enum ib_wc_status send_status;
  310. bool release;
  311. int ret;
  312. bool copy_last = false;
  313. int local_ops = 0;
  314. rcu_read_lock();
  315. /*
  316. * Note that we check the responder QP state after
  317. * checking the requester's state.
  318. */
  319. qp = rvt_lookup_qpn(ib_to_rvt(sqp->ibqp.device), &ibp->rvp,
  320. sqp->remote_qpn);
  321. spin_lock_irqsave(&sqp->s_lock, flags);
  322. /* Return if we are already busy processing a work request. */
  323. if ((sqp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT)) ||
  324. !(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_OR_FLUSH_SEND))
  325. goto unlock;
  326. sqp->s_flags |= RVT_S_BUSY;
  327. again:
  328. if (sqp->s_last == READ_ONCE(sqp->s_head))
  329. goto clr_busy;
  330. wqe = rvt_get_swqe_ptr(sqp, sqp->s_last);
  331. /* Return if it is not OK to start a new work request. */
  332. if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_NEXT_SEND_OK)) {
  333. if (!(ib_rvt_state_ops[sqp->state] & RVT_FLUSH_SEND))
  334. goto clr_busy;
  335. /* We are in the error state, flush the work request. */
  336. send_status = IB_WC_WR_FLUSH_ERR;
  337. goto flush_send;
  338. }
  339. /*
  340. * We can rely on the entry not changing without the s_lock
  341. * being held until we update s_last.
  342. * We increment s_cur to indicate s_last is in progress.
  343. */
  344. if (sqp->s_last == sqp->s_cur) {
  345. if (++sqp->s_cur >= sqp->s_size)
  346. sqp->s_cur = 0;
  347. }
  348. spin_unlock_irqrestore(&sqp->s_lock, flags);
  349. if (!qp || !(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) ||
  350. qp->ibqp.qp_type != sqp->ibqp.qp_type) {
  351. ibp->rvp.n_pkt_drops++;
  352. /*
  353. * For RC, the requester would timeout and retry so
  354. * shortcut the timeouts and just signal too many retries.
  355. */
  356. if (sqp->ibqp.qp_type == IB_QPT_RC)
  357. send_status = IB_WC_RETRY_EXC_ERR;
  358. else
  359. send_status = IB_WC_SUCCESS;
  360. goto serr;
  361. }
  362. memset(&wc, 0, sizeof(wc));
  363. send_status = IB_WC_SUCCESS;
  364. release = true;
  365. sqp->s_sge.sge = wqe->sg_list[0];
  366. sqp->s_sge.sg_list = wqe->sg_list + 1;
  367. sqp->s_sge.num_sge = wqe->wr.num_sge;
  368. sqp->s_len = wqe->length;
  369. switch (wqe->wr.opcode) {
  370. case IB_WR_REG_MR:
  371. goto send_comp;
  372. case IB_WR_LOCAL_INV:
  373. if (!(wqe->wr.send_flags & RVT_SEND_COMPLETION_ONLY)) {
  374. if (rvt_invalidate_rkey(sqp,
  375. wqe->wr.ex.invalidate_rkey))
  376. send_status = IB_WC_LOC_PROT_ERR;
  377. local_ops = 1;
  378. }
  379. goto send_comp;
  380. case IB_WR_SEND_WITH_INV:
  381. if (!rvt_invalidate_rkey(qp, wqe->wr.ex.invalidate_rkey)) {
  382. wc.wc_flags = IB_WC_WITH_INVALIDATE;
  383. wc.ex.invalidate_rkey = wqe->wr.ex.invalidate_rkey;
  384. }
  385. goto send;
  386. case IB_WR_SEND_WITH_IMM:
  387. wc.wc_flags = IB_WC_WITH_IMM;
  388. wc.ex.imm_data = wqe->wr.ex.imm_data;
  389. /* FALLTHROUGH */
  390. case IB_WR_SEND:
  391. send:
  392. ret = hfi1_rvt_get_rwqe(qp, 0);
  393. if (ret < 0)
  394. goto op_err;
  395. if (!ret)
  396. goto rnr_nak;
  397. break;
  398. case IB_WR_RDMA_WRITE_WITH_IMM:
  399. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
  400. goto inv_err;
  401. wc.wc_flags = IB_WC_WITH_IMM;
  402. wc.ex.imm_data = wqe->wr.ex.imm_data;
  403. ret = hfi1_rvt_get_rwqe(qp, 1);
  404. if (ret < 0)
  405. goto op_err;
  406. if (!ret)
  407. goto rnr_nak;
  408. /* skip copy_last set and qp_access_flags recheck */
  409. goto do_write;
  410. case IB_WR_RDMA_WRITE:
  411. copy_last = rvt_is_user_qp(qp);
  412. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
  413. goto inv_err;
  414. do_write:
  415. if (wqe->length == 0)
  416. break;
  417. if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, wqe->length,
  418. wqe->rdma_wr.remote_addr,
  419. wqe->rdma_wr.rkey,
  420. IB_ACCESS_REMOTE_WRITE)))
  421. goto acc_err;
  422. qp->r_sge.sg_list = NULL;
  423. qp->r_sge.num_sge = 1;
  424. qp->r_sge.total_len = wqe->length;
  425. break;
  426. case IB_WR_RDMA_READ:
  427. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ)))
  428. goto inv_err;
  429. if (unlikely(!rvt_rkey_ok(qp, &sqp->s_sge.sge, wqe->length,
  430. wqe->rdma_wr.remote_addr,
  431. wqe->rdma_wr.rkey,
  432. IB_ACCESS_REMOTE_READ)))
  433. goto acc_err;
  434. release = false;
  435. sqp->s_sge.sg_list = NULL;
  436. sqp->s_sge.num_sge = 1;
  437. qp->r_sge.sge = wqe->sg_list[0];
  438. qp->r_sge.sg_list = wqe->sg_list + 1;
  439. qp->r_sge.num_sge = wqe->wr.num_sge;
  440. qp->r_sge.total_len = wqe->length;
  441. break;
  442. case IB_WR_ATOMIC_CMP_AND_SWP:
  443. case IB_WR_ATOMIC_FETCH_AND_ADD:
  444. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))
  445. goto inv_err;
  446. if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
  447. wqe->atomic_wr.remote_addr,
  448. wqe->atomic_wr.rkey,
  449. IB_ACCESS_REMOTE_ATOMIC)))
  450. goto acc_err;
  451. /* Perform atomic OP and save result. */
  452. maddr = (atomic64_t *)qp->r_sge.sge.vaddr;
  453. sdata = wqe->atomic_wr.compare_add;
  454. *(u64 *)sqp->s_sge.sge.vaddr =
  455. (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
  456. (u64)atomic64_add_return(sdata, maddr) - sdata :
  457. (u64)cmpxchg((u64 *)qp->r_sge.sge.vaddr,
  458. sdata, wqe->atomic_wr.swap);
  459. rvt_put_mr(qp->r_sge.sge.mr);
  460. qp->r_sge.num_sge = 0;
  461. goto send_comp;
  462. default:
  463. send_status = IB_WC_LOC_QP_OP_ERR;
  464. goto serr;
  465. }
  466. sge = &sqp->s_sge.sge;
  467. while (sqp->s_len) {
  468. u32 len = sqp->s_len;
  469. if (len > sge->length)
  470. len = sge->length;
  471. if (len > sge->sge_length)
  472. len = sge->sge_length;
  473. WARN_ON_ONCE(len == 0);
  474. hfi1_copy_sge(&qp->r_sge, sge->vaddr, len, release, copy_last);
  475. sge->vaddr += len;
  476. sge->length -= len;
  477. sge->sge_length -= len;
  478. if (sge->sge_length == 0) {
  479. if (!release)
  480. rvt_put_mr(sge->mr);
  481. if (--sqp->s_sge.num_sge)
  482. *sge = *sqp->s_sge.sg_list++;
  483. } else if (sge->length == 0 && sge->mr->lkey) {
  484. if (++sge->n >= RVT_SEGSZ) {
  485. if (++sge->m >= sge->mr->mapsz)
  486. break;
  487. sge->n = 0;
  488. }
  489. sge->vaddr =
  490. sge->mr->map[sge->m]->segs[sge->n].vaddr;
  491. sge->length =
  492. sge->mr->map[sge->m]->segs[sge->n].length;
  493. }
  494. sqp->s_len -= len;
  495. }
  496. if (release)
  497. rvt_put_ss(&qp->r_sge);
  498. if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
  499. goto send_comp;
  500. if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM)
  501. wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;
  502. else
  503. wc.opcode = IB_WC_RECV;
  504. wc.wr_id = qp->r_wr_id;
  505. wc.status = IB_WC_SUCCESS;
  506. wc.byte_len = wqe->length;
  507. wc.qp = &qp->ibqp;
  508. wc.src_qp = qp->remote_qpn;
  509. wc.slid = rdma_ah_get_dlid(&qp->remote_ah_attr) & U16_MAX;
  510. wc.sl = rdma_ah_get_sl(&qp->remote_ah_attr);
  511. wc.port_num = 1;
  512. /* Signal completion event if the solicited bit is set. */
  513. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
  514. wqe->wr.send_flags & IB_SEND_SOLICITED);
  515. send_comp:
  516. spin_lock_irqsave(&sqp->s_lock, flags);
  517. ibp->rvp.n_loop_pkts++;
  518. flush_send:
  519. sqp->s_rnr_retry = sqp->s_rnr_retry_cnt;
  520. hfi1_send_complete(sqp, wqe, send_status);
  521. if (local_ops) {
  522. atomic_dec(&sqp->local_ops_pending);
  523. local_ops = 0;
  524. }
  525. goto again;
  526. rnr_nak:
  527. /* Handle RNR NAK */
  528. if (qp->ibqp.qp_type == IB_QPT_UC)
  529. goto send_comp;
  530. ibp->rvp.n_rnr_naks++;
  531. /*
  532. * Note: we don't need the s_lock held since the BUSY flag
  533. * makes this single threaded.
  534. */
  535. if (sqp->s_rnr_retry == 0) {
  536. send_status = IB_WC_RNR_RETRY_EXC_ERR;
  537. goto serr;
  538. }
  539. if (sqp->s_rnr_retry_cnt < 7)
  540. sqp->s_rnr_retry--;
  541. spin_lock_irqsave(&sqp->s_lock, flags);
  542. if (!(ib_rvt_state_ops[sqp->state] & RVT_PROCESS_RECV_OK))
  543. goto clr_busy;
  544. rvt_add_rnr_timer(sqp, qp->r_min_rnr_timer <<
  545. IB_AETH_CREDIT_SHIFT);
  546. goto clr_busy;
  547. op_err:
  548. send_status = IB_WC_REM_OP_ERR;
  549. wc.status = IB_WC_LOC_QP_OP_ERR;
  550. goto err;
  551. inv_err:
  552. send_status = IB_WC_REM_INV_REQ_ERR;
  553. wc.status = IB_WC_LOC_QP_OP_ERR;
  554. goto err;
  555. acc_err:
  556. send_status = IB_WC_REM_ACCESS_ERR;
  557. wc.status = IB_WC_LOC_PROT_ERR;
  558. err:
  559. /* responder goes to error state */
  560. rvt_rc_error(qp, wc.status);
  561. serr:
  562. spin_lock_irqsave(&sqp->s_lock, flags);
  563. hfi1_send_complete(sqp, wqe, send_status);
  564. if (sqp->ibqp.qp_type == IB_QPT_RC) {
  565. int lastwqe = rvt_error_qp(sqp, IB_WC_WR_FLUSH_ERR);
  566. sqp->s_flags &= ~RVT_S_BUSY;
  567. spin_unlock_irqrestore(&sqp->s_lock, flags);
  568. if (lastwqe) {
  569. struct ib_event ev;
  570. ev.device = sqp->ibqp.device;
  571. ev.element.qp = &sqp->ibqp;
  572. ev.event = IB_EVENT_QP_LAST_WQE_REACHED;
  573. sqp->ibqp.event_handler(&ev, sqp->ibqp.qp_context);
  574. }
  575. goto done;
  576. }
  577. clr_busy:
  578. sqp->s_flags &= ~RVT_S_BUSY;
  579. unlock:
  580. spin_unlock_irqrestore(&sqp->s_lock, flags);
  581. done:
  582. rcu_read_unlock();
  583. }
  584. /**
  585. * hfi1_make_grh - construct a GRH header
  586. * @ibp: a pointer to the IB port
  587. * @hdr: a pointer to the GRH header being constructed
  588. * @grh: the global route address to send to
  589. * @hwords: size of header after grh being sent in dwords
  590. * @nwords: the number of 32 bit words of data being sent
  591. *
  592. * Return the size of the header in 32 bit words.
  593. */
  594. u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
  595. const struct ib_global_route *grh, u32 hwords, u32 nwords)
  596. {
  597. hdr->version_tclass_flow =
  598. cpu_to_be32((IB_GRH_VERSION << IB_GRH_VERSION_SHIFT) |
  599. (grh->traffic_class << IB_GRH_TCLASS_SHIFT) |
  600. (grh->flow_label << IB_GRH_FLOW_SHIFT));
  601. hdr->paylen = cpu_to_be16((hwords + nwords) << 2);
  602. /* next_hdr is defined by C8-7 in ch. 8.4.1 */
  603. hdr->next_hdr = IB_GRH_NEXT_HDR;
  604. hdr->hop_limit = grh->hop_limit;
  605. /* The SGID is 32-bit aligned. */
  606. hdr->sgid.global.subnet_prefix = ibp->rvp.gid_prefix;
  607. hdr->sgid.global.interface_id =
  608. grh->sgid_index < HFI1_GUIDS_PER_PORT ?
  609. get_sguid(ibp, grh->sgid_index) :
  610. get_sguid(ibp, HFI1_PORT_GUID_INDEX);
  611. hdr->dgid = grh->dgid;
  612. /* GRH header size in 32-bit words. */
  613. return sizeof(struct ib_grh) / sizeof(u32);
  614. }
  615. #define BTH2_OFFSET (offsetof(struct hfi1_sdma_header, \
  616. hdr.ibh.u.oth.bth[2]) / 4)
  617. /**
  618. * build_ahg - create ahg in s_ahg
  619. * @qp: a pointer to QP
  620. * @npsn: the next PSN for the request/response
  621. *
  622. * This routine handles the AHG by allocating an ahg entry and causing the
  623. * copy of the first middle.
  624. *
  625. * Subsequent middles use the copied entry, editing the
  626. * PSN with 1 or 2 edits.
  627. */
  628. static inline void build_ahg(struct rvt_qp *qp, u32 npsn)
  629. {
  630. struct hfi1_qp_priv *priv = qp->priv;
  631. if (unlikely(qp->s_flags & RVT_S_AHG_CLEAR))
  632. clear_ahg(qp);
  633. if (!(qp->s_flags & RVT_S_AHG_VALID)) {
  634. /* first middle that needs copy */
  635. if (qp->s_ahgidx < 0)
  636. qp->s_ahgidx = sdma_ahg_alloc(priv->s_sde);
  637. if (qp->s_ahgidx >= 0) {
  638. qp->s_ahgpsn = npsn;
  639. priv->s_ahg->tx_flags |= SDMA_TXREQ_F_AHG_COPY;
  640. /* save to protect a change in another thread */
  641. priv->s_ahg->ahgidx = qp->s_ahgidx;
  642. qp->s_flags |= RVT_S_AHG_VALID;
  643. }
  644. } else {
  645. /* subsequent middle after valid */
  646. if (qp->s_ahgidx >= 0) {
  647. priv->s_ahg->tx_flags |= SDMA_TXREQ_F_USE_AHG;
  648. priv->s_ahg->ahgidx = qp->s_ahgidx;
  649. priv->s_ahg->ahgcount++;
  650. priv->s_ahg->ahgdesc[0] =
  651. sdma_build_ahg_descriptor(
  652. (__force u16)cpu_to_be16((u16)npsn),
  653. BTH2_OFFSET,
  654. 16,
  655. 16);
  656. if ((npsn & 0xffff0000) !=
  657. (qp->s_ahgpsn & 0xffff0000)) {
  658. priv->s_ahg->ahgcount++;
  659. priv->s_ahg->ahgdesc[1] =
  660. sdma_build_ahg_descriptor(
  661. (__force u16)cpu_to_be16(
  662. (u16)(npsn >> 16)),
  663. BTH2_OFFSET,
  664. 0,
  665. 16);
  666. }
  667. }
  668. }
  669. }
  670. static inline void hfi1_make_ruc_bth(struct rvt_qp *qp,
  671. struct ib_other_headers *ohdr,
  672. u32 bth0, u32 bth1, u32 bth2)
  673. {
  674. bth1 |= qp->remote_qpn;
  675. ohdr->bth[0] = cpu_to_be32(bth0);
  676. ohdr->bth[1] = cpu_to_be32(bth1);
  677. ohdr->bth[2] = cpu_to_be32(bth2);
  678. }
  679. /**
  680. * hfi1_make_ruc_header_16B - build a 16B header
  681. * @qp: the queue pair
  682. * @ohdr: a pointer to the destination header memory
  683. * @bth0: bth0 passed in from the RC/UC builder
  684. * @bth2: bth2 passed in from the RC/UC builder
  685. * @middle: non zero implies indicates ahg "could" be used
  686. * @ps: the current packet state
  687. *
  688. * This routine may disarm ahg under these situations:
  689. * - packet needs a GRH
  690. * - BECN needed
  691. * - migration state not IB_MIG_MIGRATED
  692. */
  693. static inline void hfi1_make_ruc_header_16B(struct rvt_qp *qp,
  694. struct ib_other_headers *ohdr,
  695. u32 bth0, u32 bth2, int middle,
  696. struct hfi1_pkt_state *ps)
  697. {
  698. struct hfi1_qp_priv *priv = qp->priv;
  699. struct hfi1_ibport *ibp = ps->ibp;
  700. struct hfi1_pportdata *ppd = ppd_from_ibp(ibp);
  701. u32 bth1 = 0;
  702. u32 slid;
  703. u16 pkey = hfi1_get_pkey(ibp, qp->s_pkey_index);
  704. u8 l4 = OPA_16B_L4_IB_LOCAL;
  705. u8 extra_bytes = hfi1_get_16b_padding(
  706. (ps->s_txreq->hdr_dwords << 2),
  707. ps->s_txreq->s_cur_size);
  708. u32 nwords = SIZE_OF_CRC + ((ps->s_txreq->s_cur_size +
  709. extra_bytes + SIZE_OF_LT) >> 2);
  710. bool becn = false;
  711. if (unlikely(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH) &&
  712. hfi1_check_mcast(rdma_ah_get_dlid(&qp->remote_ah_attr))) {
  713. struct ib_grh *grh;
  714. struct ib_global_route *grd =
  715. rdma_ah_retrieve_grh(&qp->remote_ah_attr);
  716. /*
  717. * Ensure OPA GIDs are transformed to IB gids
  718. * before creating the GRH.
  719. */
  720. if (grd->sgid_index == OPA_GID_INDEX)
  721. grd->sgid_index = 0;
  722. grh = &ps->s_txreq->phdr.hdr.opah.u.l.grh;
  723. l4 = OPA_16B_L4_IB_GLOBAL;
  724. ps->s_txreq->hdr_dwords +=
  725. hfi1_make_grh(ibp, grh, grd,
  726. ps->s_txreq->hdr_dwords - LRH_16B_DWORDS,
  727. nwords);
  728. middle = 0;
  729. }
  730. if (qp->s_mig_state == IB_MIG_MIGRATED)
  731. bth1 |= OPA_BTH_MIG_REQ;
  732. else
  733. middle = 0;
  734. if (qp->s_flags & RVT_S_ECN) {
  735. qp->s_flags &= ~RVT_S_ECN;
  736. /* we recently received a FECN, so return a BECN */
  737. becn = true;
  738. middle = 0;
  739. }
  740. if (middle)
  741. build_ahg(qp, bth2);
  742. else
  743. qp->s_flags &= ~RVT_S_AHG_VALID;
  744. bth0 |= pkey;
  745. bth0 |= extra_bytes << 20;
  746. hfi1_make_ruc_bth(qp, ohdr, bth0, bth1, bth2);
  747. if (!ppd->lid)
  748. slid = be32_to_cpu(OPA_LID_PERMISSIVE);
  749. else
  750. slid = ppd->lid |
  751. (rdma_ah_get_path_bits(&qp->remote_ah_attr) &
  752. ((1 << ppd->lmc) - 1));
  753. hfi1_make_16b_hdr(&ps->s_txreq->phdr.hdr.opah,
  754. slid,
  755. opa_get_lid(rdma_ah_get_dlid(&qp->remote_ah_attr),
  756. 16B),
  757. (ps->s_txreq->hdr_dwords + nwords) >> 1,
  758. pkey, becn, 0, l4, priv->s_sc);
  759. }
  760. /**
  761. * hfi1_make_ruc_header_9B - build a 9B header
  762. * @qp: the queue pair
  763. * @ohdr: a pointer to the destination header memory
  764. * @bth0: bth0 passed in from the RC/UC builder
  765. * @bth2: bth2 passed in from the RC/UC builder
  766. * @middle: non zero implies indicates ahg "could" be used
  767. * @ps: the current packet state
  768. *
  769. * This routine may disarm ahg under these situations:
  770. * - packet needs a GRH
  771. * - BECN needed
  772. * - migration state not IB_MIG_MIGRATED
  773. */
  774. static inline void hfi1_make_ruc_header_9B(struct rvt_qp *qp,
  775. struct ib_other_headers *ohdr,
  776. u32 bth0, u32 bth2, int middle,
  777. struct hfi1_pkt_state *ps)
  778. {
  779. struct hfi1_qp_priv *priv = qp->priv;
  780. struct hfi1_ibport *ibp = ps->ibp;
  781. u32 bth1 = 0;
  782. u16 pkey = hfi1_get_pkey(ibp, qp->s_pkey_index);
  783. u16 lrh0 = HFI1_LRH_BTH;
  784. u8 extra_bytes = -ps->s_txreq->s_cur_size & 3;
  785. u32 nwords = SIZE_OF_CRC + ((ps->s_txreq->s_cur_size +
  786. extra_bytes) >> 2);
  787. if (unlikely(rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH)) {
  788. struct ib_grh *grh = &ps->s_txreq->phdr.hdr.ibh.u.l.grh;
  789. lrh0 = HFI1_LRH_GRH;
  790. ps->s_txreq->hdr_dwords +=
  791. hfi1_make_grh(ibp, grh,
  792. rdma_ah_read_grh(&qp->remote_ah_attr),
  793. ps->s_txreq->hdr_dwords - LRH_9B_DWORDS,
  794. nwords);
  795. middle = 0;
  796. }
  797. lrh0 |= (priv->s_sc & 0xf) << 12 |
  798. (rdma_ah_get_sl(&qp->remote_ah_attr) & 0xf) << 4;
  799. if (qp->s_mig_state == IB_MIG_MIGRATED)
  800. bth0 |= IB_BTH_MIG_REQ;
  801. else
  802. middle = 0;
  803. if (qp->s_flags & RVT_S_ECN) {
  804. qp->s_flags &= ~RVT_S_ECN;
  805. /* we recently received a FECN, so return a BECN */
  806. bth1 |= (IB_BECN_MASK << IB_BECN_SHIFT);
  807. middle = 0;
  808. }
  809. if (middle)
  810. build_ahg(qp, bth2);
  811. else
  812. qp->s_flags &= ~RVT_S_AHG_VALID;
  813. bth0 |= pkey;
  814. bth0 |= extra_bytes << 20;
  815. hfi1_make_ruc_bth(qp, ohdr, bth0, bth1, bth2);
  816. hfi1_make_ib_hdr(&ps->s_txreq->phdr.hdr.ibh,
  817. lrh0,
  818. ps->s_txreq->hdr_dwords + nwords,
  819. opa_get_lid(rdma_ah_get_dlid(&qp->remote_ah_attr), 9B),
  820. ppd_from_ibp(ibp)->lid |
  821. rdma_ah_get_path_bits(&qp->remote_ah_attr));
  822. }
  823. typedef void (*hfi1_make_ruc_hdr)(struct rvt_qp *qp,
  824. struct ib_other_headers *ohdr,
  825. u32 bth0, u32 bth2, int middle,
  826. struct hfi1_pkt_state *ps);
  827. /* We support only two types - 9B and 16B for now */
  828. static const hfi1_make_ruc_hdr hfi1_ruc_header_tbl[2] = {
  829. [HFI1_PKT_TYPE_9B] = &hfi1_make_ruc_header_9B,
  830. [HFI1_PKT_TYPE_16B] = &hfi1_make_ruc_header_16B
  831. };
  832. void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
  833. u32 bth0, u32 bth2, int middle,
  834. struct hfi1_pkt_state *ps)
  835. {
  836. struct hfi1_qp_priv *priv = qp->priv;
  837. /*
  838. * reset s_ahg/AHG fields
  839. *
  840. * This insures that the ahgentry/ahgcount
  841. * are at a non-AHG default to protect
  842. * build_verbs_tx_desc() from using
  843. * an include ahgidx.
  844. *
  845. * build_ahg() will modify as appropriate
  846. * to use the AHG feature.
  847. */
  848. priv->s_ahg->tx_flags = 0;
  849. priv->s_ahg->ahgcount = 0;
  850. priv->s_ahg->ahgidx = 0;
  851. /* Make the appropriate header */
  852. hfi1_ruc_header_tbl[priv->hdr_type](qp, ohdr, bth0, bth2, middle, ps);
  853. }
  854. /* when sending, force a reschedule every one of these periods */
  855. #define SEND_RESCHED_TIMEOUT (5 * HZ) /* 5s in jiffies */
  856. /**
  857. * schedule_send_yield - test for a yield required for QP send engine
  858. * @timeout: Final time for timeout slice for jiffies
  859. * @qp: a pointer to QP
  860. * @ps: a pointer to a structure with commonly lookup values for
  861. * the the send engine progress
  862. *
  863. * This routine checks if the time slice for the QP has expired
  864. * for RC QPs, if so an additional work entry is queued. At this
  865. * point, other QPs have an opportunity to be scheduled. It
  866. * returns true if a yield is required, otherwise, false
  867. * is returned.
  868. */
  869. static bool schedule_send_yield(struct rvt_qp *qp,
  870. struct hfi1_pkt_state *ps)
  871. {
  872. ps->pkts_sent = true;
  873. if (unlikely(time_after(jiffies, ps->timeout))) {
  874. if (!ps->in_thread ||
  875. workqueue_congested(ps->cpu, ps->ppd->hfi1_wq)) {
  876. spin_lock_irqsave(&qp->s_lock, ps->flags);
  877. qp->s_flags &= ~RVT_S_BUSY;
  878. hfi1_schedule_send(qp);
  879. spin_unlock_irqrestore(&qp->s_lock, ps->flags);
  880. this_cpu_inc(*ps->ppd->dd->send_schedule);
  881. trace_hfi1_rc_expired_time_slice(qp, true);
  882. return true;
  883. }
  884. cond_resched();
  885. this_cpu_inc(*ps->ppd->dd->send_schedule);
  886. ps->timeout = jiffies + ps->timeout_int;
  887. }
  888. trace_hfi1_rc_expired_time_slice(qp, false);
  889. return false;
  890. }
  891. void hfi1_do_send_from_rvt(struct rvt_qp *qp)
  892. {
  893. hfi1_do_send(qp, false);
  894. }
  895. void _hfi1_do_send(struct work_struct *work)
  896. {
  897. struct iowait *wait = container_of(work, struct iowait, iowork);
  898. struct rvt_qp *qp = iowait_to_qp(wait);
  899. hfi1_do_send(qp, true);
  900. }
  901. /**
  902. * hfi1_do_send - perform a send on a QP
  903. * @work: contains a pointer to the QP
  904. * @in_thread: true if in a workqueue thread
  905. *
  906. * Process entries in the send work queue until credit or queue is
  907. * exhausted. Only allow one CPU to send a packet per QP.
  908. * Otherwise, two threads could send packets out of order.
  909. */
  910. void hfi1_do_send(struct rvt_qp *qp, bool in_thread)
  911. {
  912. struct hfi1_pkt_state ps;
  913. struct hfi1_qp_priv *priv = qp->priv;
  914. int (*make_req)(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  915. ps.dev = to_idev(qp->ibqp.device);
  916. ps.ibp = to_iport(qp->ibqp.device, qp->port_num);
  917. ps.ppd = ppd_from_ibp(ps.ibp);
  918. ps.in_thread = in_thread;
  919. trace_hfi1_rc_do_send(qp, in_thread);
  920. switch (qp->ibqp.qp_type) {
  921. case IB_QPT_RC:
  922. if (!loopback && ((rdma_ah_get_dlid(&qp->remote_ah_attr) &
  923. ~((1 << ps.ppd->lmc) - 1)) ==
  924. ps.ppd->lid)) {
  925. ruc_loopback(qp);
  926. return;
  927. }
  928. make_req = hfi1_make_rc_req;
  929. ps.timeout_int = qp->timeout_jiffies;
  930. break;
  931. case IB_QPT_UC:
  932. if (!loopback && ((rdma_ah_get_dlid(&qp->remote_ah_attr) &
  933. ~((1 << ps.ppd->lmc) - 1)) ==
  934. ps.ppd->lid)) {
  935. ruc_loopback(qp);
  936. return;
  937. }
  938. make_req = hfi1_make_uc_req;
  939. ps.timeout_int = SEND_RESCHED_TIMEOUT;
  940. break;
  941. default:
  942. make_req = hfi1_make_ud_req;
  943. ps.timeout_int = SEND_RESCHED_TIMEOUT;
  944. }
  945. spin_lock_irqsave(&qp->s_lock, ps.flags);
  946. /* Return if we are already busy processing a work request. */
  947. if (!hfi1_send_ok(qp)) {
  948. spin_unlock_irqrestore(&qp->s_lock, ps.flags);
  949. return;
  950. }
  951. qp->s_flags |= RVT_S_BUSY;
  952. ps.timeout_int = ps.timeout_int / 8;
  953. ps.timeout = jiffies + ps.timeout_int;
  954. ps.cpu = priv->s_sde ? priv->s_sde->cpu :
  955. cpumask_first(cpumask_of_node(ps.ppd->dd->node));
  956. ps.pkts_sent = false;
  957. /* insure a pre-built packet is handled */
  958. ps.s_txreq = get_waiting_verbs_txreq(qp);
  959. do {
  960. /* Check for a constructed packet to be sent. */
  961. if (ps.s_txreq) {
  962. spin_unlock_irqrestore(&qp->s_lock, ps.flags);
  963. /*
  964. * If the packet cannot be sent now, return and
  965. * the send engine will be woken up later.
  966. */
  967. if (hfi1_verbs_send(qp, &ps))
  968. return;
  969. /* allow other tasks to run */
  970. if (schedule_send_yield(qp, &ps))
  971. return;
  972. spin_lock_irqsave(&qp->s_lock, ps.flags);
  973. }
  974. } while (make_req(qp, &ps));
  975. iowait_starve_clear(ps.pkts_sent, &priv->s_iowait);
  976. spin_unlock_irqrestore(&qp->s_lock, ps.flags);
  977. }
  978. /*
  979. * This should be called with s_lock held.
  980. */
  981. void hfi1_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
  982. enum ib_wc_status status)
  983. {
  984. u32 old_last, last;
  985. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_OR_FLUSH_SEND))
  986. return;
  987. last = qp->s_last;
  988. old_last = last;
  989. trace_hfi1_qp_send_completion(qp, wqe, last);
  990. if (++last >= qp->s_size)
  991. last = 0;
  992. trace_hfi1_qp_send_completion(qp, wqe, last);
  993. qp->s_last = last;
  994. /* See post_send() */
  995. barrier();
  996. rvt_put_swqe(wqe);
  997. if (qp->ibqp.qp_type == IB_QPT_UD ||
  998. qp->ibqp.qp_type == IB_QPT_SMI ||
  999. qp->ibqp.qp_type == IB_QPT_GSI)
  1000. atomic_dec(&ibah_to_rvtah(wqe->ud_wr.ah)->refcount);
  1001. rvt_qp_swqe_complete(qp,
  1002. wqe,
  1003. ib_hfi1_wc_opcode[wqe->wr.opcode],
  1004. status);
  1005. if (qp->s_acked == old_last)
  1006. qp->s_acked = last;
  1007. if (qp->s_cur == old_last)
  1008. qp->s_cur = last;
  1009. if (qp->s_tail == old_last)
  1010. qp->s_tail = last;
  1011. if (qp->state == IB_QPS_SQD && last == qp->s_cur)
  1012. qp->s_draining = 0;
  1013. }