ruc.c 30 KB

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