rxe_comp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /*
  2. * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved.
  3. * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/skbuff.h>
  34. #include "rxe.h"
  35. #include "rxe_loc.h"
  36. #include "rxe_queue.h"
  37. #include "rxe_task.h"
  38. enum comp_state {
  39. COMPST_GET_ACK,
  40. COMPST_GET_WQE,
  41. COMPST_COMP_WQE,
  42. COMPST_COMP_ACK,
  43. COMPST_CHECK_PSN,
  44. COMPST_CHECK_ACK,
  45. COMPST_READ,
  46. COMPST_ATOMIC,
  47. COMPST_WRITE_SEND,
  48. COMPST_UPDATE_COMP,
  49. COMPST_ERROR_RETRY,
  50. COMPST_RNR_RETRY,
  51. COMPST_ERROR,
  52. COMPST_EXIT, /* We have an issue, and we want to rerun the completer */
  53. COMPST_DONE, /* The completer finished successflly */
  54. };
  55. static char *comp_state_name[] = {
  56. [COMPST_GET_ACK] = "GET ACK",
  57. [COMPST_GET_WQE] = "GET WQE",
  58. [COMPST_COMP_WQE] = "COMP WQE",
  59. [COMPST_COMP_ACK] = "COMP ACK",
  60. [COMPST_CHECK_PSN] = "CHECK PSN",
  61. [COMPST_CHECK_ACK] = "CHECK ACK",
  62. [COMPST_READ] = "READ",
  63. [COMPST_ATOMIC] = "ATOMIC",
  64. [COMPST_WRITE_SEND] = "WRITE/SEND",
  65. [COMPST_UPDATE_COMP] = "UPDATE COMP",
  66. [COMPST_ERROR_RETRY] = "ERROR RETRY",
  67. [COMPST_RNR_RETRY] = "RNR RETRY",
  68. [COMPST_ERROR] = "ERROR",
  69. [COMPST_EXIT] = "EXIT",
  70. [COMPST_DONE] = "DONE",
  71. };
  72. static unsigned long rnrnak_usec[32] = {
  73. [IB_RNR_TIMER_655_36] = 655360,
  74. [IB_RNR_TIMER_000_01] = 10,
  75. [IB_RNR_TIMER_000_02] = 20,
  76. [IB_RNR_TIMER_000_03] = 30,
  77. [IB_RNR_TIMER_000_04] = 40,
  78. [IB_RNR_TIMER_000_06] = 60,
  79. [IB_RNR_TIMER_000_08] = 80,
  80. [IB_RNR_TIMER_000_12] = 120,
  81. [IB_RNR_TIMER_000_16] = 160,
  82. [IB_RNR_TIMER_000_24] = 240,
  83. [IB_RNR_TIMER_000_32] = 320,
  84. [IB_RNR_TIMER_000_48] = 480,
  85. [IB_RNR_TIMER_000_64] = 640,
  86. [IB_RNR_TIMER_000_96] = 960,
  87. [IB_RNR_TIMER_001_28] = 1280,
  88. [IB_RNR_TIMER_001_92] = 1920,
  89. [IB_RNR_TIMER_002_56] = 2560,
  90. [IB_RNR_TIMER_003_84] = 3840,
  91. [IB_RNR_TIMER_005_12] = 5120,
  92. [IB_RNR_TIMER_007_68] = 7680,
  93. [IB_RNR_TIMER_010_24] = 10240,
  94. [IB_RNR_TIMER_015_36] = 15360,
  95. [IB_RNR_TIMER_020_48] = 20480,
  96. [IB_RNR_TIMER_030_72] = 30720,
  97. [IB_RNR_TIMER_040_96] = 40960,
  98. [IB_RNR_TIMER_061_44] = 61410,
  99. [IB_RNR_TIMER_081_92] = 81920,
  100. [IB_RNR_TIMER_122_88] = 122880,
  101. [IB_RNR_TIMER_163_84] = 163840,
  102. [IB_RNR_TIMER_245_76] = 245760,
  103. [IB_RNR_TIMER_327_68] = 327680,
  104. [IB_RNR_TIMER_491_52] = 491520,
  105. };
  106. static inline unsigned long rnrnak_jiffies(u8 timeout)
  107. {
  108. return max_t(unsigned long,
  109. usecs_to_jiffies(rnrnak_usec[timeout]), 1);
  110. }
  111. static enum ib_wc_opcode wr_to_wc_opcode(enum ib_wr_opcode opcode)
  112. {
  113. switch (opcode) {
  114. case IB_WR_RDMA_WRITE: return IB_WC_RDMA_WRITE;
  115. case IB_WR_RDMA_WRITE_WITH_IMM: return IB_WC_RDMA_WRITE;
  116. case IB_WR_SEND: return IB_WC_SEND;
  117. case IB_WR_SEND_WITH_IMM: return IB_WC_SEND;
  118. case IB_WR_RDMA_READ: return IB_WC_RDMA_READ;
  119. case IB_WR_ATOMIC_CMP_AND_SWP: return IB_WC_COMP_SWAP;
  120. case IB_WR_ATOMIC_FETCH_AND_ADD: return IB_WC_FETCH_ADD;
  121. case IB_WR_LSO: return IB_WC_LSO;
  122. case IB_WR_SEND_WITH_INV: return IB_WC_SEND;
  123. case IB_WR_RDMA_READ_WITH_INV: return IB_WC_RDMA_READ;
  124. case IB_WR_LOCAL_INV: return IB_WC_LOCAL_INV;
  125. case IB_WR_REG_MR: return IB_WC_REG_MR;
  126. default:
  127. return 0xff;
  128. }
  129. }
  130. void retransmit_timer(struct timer_list *t)
  131. {
  132. struct rxe_qp *qp = from_timer(qp, t, retrans_timer);
  133. if (qp->valid) {
  134. qp->comp.timeout = 1;
  135. rxe_run_task(&qp->comp.task, 1);
  136. }
  137. }
  138. void rxe_comp_queue_pkt(struct rxe_dev *rxe, struct rxe_qp *qp,
  139. struct sk_buff *skb)
  140. {
  141. int must_sched;
  142. skb_queue_tail(&qp->resp_pkts, skb);
  143. must_sched = skb_queue_len(&qp->resp_pkts) > 1;
  144. if (must_sched != 0)
  145. rxe_counter_inc(rxe, RXE_CNT_COMPLETER_SCHED);
  146. rxe_run_task(&qp->comp.task, must_sched);
  147. }
  148. static inline enum comp_state get_wqe(struct rxe_qp *qp,
  149. struct rxe_pkt_info *pkt,
  150. struct rxe_send_wqe **wqe_p)
  151. {
  152. struct rxe_send_wqe *wqe;
  153. /* we come here whether or not we found a response packet to see if
  154. * there are any posted WQEs
  155. */
  156. wqe = queue_head(qp->sq.queue);
  157. *wqe_p = wqe;
  158. /* no WQE or requester has not started it yet */
  159. if (!wqe || wqe->state == wqe_state_posted)
  160. return pkt ? COMPST_DONE : COMPST_EXIT;
  161. /* WQE does not require an ack */
  162. if (wqe->state == wqe_state_done)
  163. return COMPST_COMP_WQE;
  164. /* WQE caused an error */
  165. if (wqe->state == wqe_state_error)
  166. return COMPST_ERROR;
  167. /* we have a WQE, if we also have an ack check its PSN */
  168. return pkt ? COMPST_CHECK_PSN : COMPST_EXIT;
  169. }
  170. static inline void reset_retry_counters(struct rxe_qp *qp)
  171. {
  172. qp->comp.retry_cnt = qp->attr.retry_cnt;
  173. qp->comp.rnr_retry = qp->attr.rnr_retry;
  174. qp->comp.started_retry = 0;
  175. }
  176. static inline enum comp_state check_psn(struct rxe_qp *qp,
  177. struct rxe_pkt_info *pkt,
  178. struct rxe_send_wqe *wqe)
  179. {
  180. s32 diff;
  181. /* check to see if response is past the oldest WQE. if it is, complete
  182. * send/write or error read/atomic
  183. */
  184. diff = psn_compare(pkt->psn, wqe->last_psn);
  185. if (diff > 0) {
  186. if (wqe->state == wqe_state_pending) {
  187. if (wqe->mask & WR_ATOMIC_OR_READ_MASK)
  188. return COMPST_ERROR_RETRY;
  189. reset_retry_counters(qp);
  190. return COMPST_COMP_WQE;
  191. } else {
  192. return COMPST_DONE;
  193. }
  194. }
  195. /* compare response packet to expected response */
  196. diff = psn_compare(pkt->psn, qp->comp.psn);
  197. if (diff < 0) {
  198. /* response is most likely a retried packet if it matches an
  199. * uncompleted WQE go complete it else ignore it
  200. */
  201. if (pkt->psn == wqe->last_psn)
  202. return COMPST_COMP_ACK;
  203. else
  204. return COMPST_DONE;
  205. } else if ((diff > 0) && (wqe->mask & WR_ATOMIC_OR_READ_MASK)) {
  206. return COMPST_DONE;
  207. } else {
  208. return COMPST_CHECK_ACK;
  209. }
  210. }
  211. static inline enum comp_state check_ack(struct rxe_qp *qp,
  212. struct rxe_pkt_info *pkt,
  213. struct rxe_send_wqe *wqe)
  214. {
  215. unsigned int mask = pkt->mask;
  216. u8 syn;
  217. struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
  218. /* Check the sequence only */
  219. switch (qp->comp.opcode) {
  220. case -1:
  221. /* Will catch all *_ONLY cases. */
  222. if (!(mask & RXE_START_MASK))
  223. return COMPST_ERROR;
  224. break;
  225. case IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST:
  226. case IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE:
  227. if (pkt->opcode != IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE &&
  228. pkt->opcode != IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST) {
  229. /* read retries of partial data may restart from
  230. * read response first or response only.
  231. */
  232. if ((pkt->psn == wqe->first_psn &&
  233. pkt->opcode ==
  234. IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST) ||
  235. (wqe->first_psn == wqe->last_psn &&
  236. pkt->opcode ==
  237. IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY))
  238. break;
  239. return COMPST_ERROR;
  240. }
  241. break;
  242. default:
  243. WARN_ON_ONCE(1);
  244. }
  245. /* Check operation validity. */
  246. switch (pkt->opcode) {
  247. case IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST:
  248. case IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST:
  249. case IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY:
  250. syn = aeth_syn(pkt);
  251. if ((syn & AETH_TYPE_MASK) != AETH_ACK)
  252. return COMPST_ERROR;
  253. /* fall through */
  254. /* (IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE doesn't have an AETH)
  255. */
  256. case IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE:
  257. if (wqe->wr.opcode != IB_WR_RDMA_READ &&
  258. wqe->wr.opcode != IB_WR_RDMA_READ_WITH_INV) {
  259. wqe->status = IB_WC_FATAL_ERR;
  260. return COMPST_ERROR;
  261. }
  262. reset_retry_counters(qp);
  263. return COMPST_READ;
  264. case IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE:
  265. syn = aeth_syn(pkt);
  266. if ((syn & AETH_TYPE_MASK) != AETH_ACK)
  267. return COMPST_ERROR;
  268. if (wqe->wr.opcode != IB_WR_ATOMIC_CMP_AND_SWP &&
  269. wqe->wr.opcode != IB_WR_ATOMIC_FETCH_AND_ADD)
  270. return COMPST_ERROR;
  271. reset_retry_counters(qp);
  272. return COMPST_ATOMIC;
  273. case IB_OPCODE_RC_ACKNOWLEDGE:
  274. syn = aeth_syn(pkt);
  275. switch (syn & AETH_TYPE_MASK) {
  276. case AETH_ACK:
  277. reset_retry_counters(qp);
  278. return COMPST_WRITE_SEND;
  279. case AETH_RNR_NAK:
  280. rxe_counter_inc(rxe, RXE_CNT_RCV_RNR);
  281. return COMPST_RNR_RETRY;
  282. case AETH_NAK:
  283. switch (syn) {
  284. case AETH_NAK_PSN_SEQ_ERROR:
  285. /* a nak implicitly acks all packets with psns
  286. * before
  287. */
  288. if (psn_compare(pkt->psn, qp->comp.psn) > 0) {
  289. rxe_counter_inc(rxe,
  290. RXE_CNT_RCV_SEQ_ERR);
  291. qp->comp.psn = pkt->psn;
  292. if (qp->req.wait_psn) {
  293. qp->req.wait_psn = 0;
  294. rxe_run_task(&qp->req.task, 0);
  295. }
  296. }
  297. return COMPST_ERROR_RETRY;
  298. case AETH_NAK_INVALID_REQ:
  299. wqe->status = IB_WC_REM_INV_REQ_ERR;
  300. return COMPST_ERROR;
  301. case AETH_NAK_REM_ACC_ERR:
  302. wqe->status = IB_WC_REM_ACCESS_ERR;
  303. return COMPST_ERROR;
  304. case AETH_NAK_REM_OP_ERR:
  305. wqe->status = IB_WC_REM_OP_ERR;
  306. return COMPST_ERROR;
  307. default:
  308. pr_warn("unexpected nak %x\n", syn);
  309. wqe->status = IB_WC_REM_OP_ERR;
  310. return COMPST_ERROR;
  311. }
  312. default:
  313. return COMPST_ERROR;
  314. }
  315. break;
  316. default:
  317. pr_warn("unexpected opcode\n");
  318. }
  319. return COMPST_ERROR;
  320. }
  321. static inline enum comp_state do_read(struct rxe_qp *qp,
  322. struct rxe_pkt_info *pkt,
  323. struct rxe_send_wqe *wqe)
  324. {
  325. int ret;
  326. ret = copy_data(qp->pd, IB_ACCESS_LOCAL_WRITE,
  327. &wqe->dma, payload_addr(pkt),
  328. payload_size(pkt), to_mem_obj, NULL);
  329. if (ret)
  330. return COMPST_ERROR;
  331. if (wqe->dma.resid == 0 && (pkt->mask & RXE_END_MASK))
  332. return COMPST_COMP_ACK;
  333. else
  334. return COMPST_UPDATE_COMP;
  335. }
  336. static inline enum comp_state do_atomic(struct rxe_qp *qp,
  337. struct rxe_pkt_info *pkt,
  338. struct rxe_send_wqe *wqe)
  339. {
  340. int ret;
  341. u64 atomic_orig = atmack_orig(pkt);
  342. ret = copy_data(qp->pd, IB_ACCESS_LOCAL_WRITE,
  343. &wqe->dma, &atomic_orig,
  344. sizeof(u64), to_mem_obj, NULL);
  345. if (ret)
  346. return COMPST_ERROR;
  347. else
  348. return COMPST_COMP_ACK;
  349. }
  350. static void make_send_cqe(struct rxe_qp *qp, struct rxe_send_wqe *wqe,
  351. struct rxe_cqe *cqe)
  352. {
  353. memset(cqe, 0, sizeof(*cqe));
  354. if (!qp->is_user) {
  355. struct ib_wc *wc = &cqe->ibwc;
  356. wc->wr_id = wqe->wr.wr_id;
  357. wc->status = wqe->status;
  358. wc->opcode = wr_to_wc_opcode(wqe->wr.opcode);
  359. if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
  360. wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
  361. wc->wc_flags = IB_WC_WITH_IMM;
  362. wc->byte_len = wqe->dma.length;
  363. wc->qp = &qp->ibqp;
  364. } else {
  365. struct ib_uverbs_wc *uwc = &cqe->uibwc;
  366. uwc->wr_id = wqe->wr.wr_id;
  367. uwc->status = wqe->status;
  368. uwc->opcode = wr_to_wc_opcode(wqe->wr.opcode);
  369. if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
  370. wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
  371. uwc->wc_flags = IB_WC_WITH_IMM;
  372. uwc->byte_len = wqe->dma.length;
  373. uwc->qp_num = qp->ibqp.qp_num;
  374. }
  375. }
  376. /*
  377. * IBA Spec. Section 10.7.3.1 SIGNALED COMPLETIONS
  378. * ---------8<---------8<-------------
  379. * ...Note that if a completion error occurs, a Work Completion
  380. * will always be generated, even if the signaling
  381. * indicator requests an Unsignaled Completion.
  382. * ---------8<---------8<-------------
  383. */
  384. static void do_complete(struct rxe_qp *qp, struct rxe_send_wqe *wqe)
  385. {
  386. struct rxe_cqe cqe;
  387. if ((qp->sq_sig_type == IB_SIGNAL_ALL_WR) ||
  388. (wqe->wr.send_flags & IB_SEND_SIGNALED) ||
  389. wqe->status != IB_WC_SUCCESS) {
  390. make_send_cqe(qp, wqe, &cqe);
  391. advance_consumer(qp->sq.queue);
  392. rxe_cq_post(qp->scq, &cqe, 0);
  393. } else {
  394. advance_consumer(qp->sq.queue);
  395. }
  396. /*
  397. * we completed something so let req run again
  398. * if it is trying to fence
  399. */
  400. if (qp->req.wait_fence) {
  401. qp->req.wait_fence = 0;
  402. rxe_run_task(&qp->req.task, 0);
  403. }
  404. }
  405. static inline enum comp_state complete_ack(struct rxe_qp *qp,
  406. struct rxe_pkt_info *pkt,
  407. struct rxe_send_wqe *wqe)
  408. {
  409. unsigned long flags;
  410. if (wqe->has_rd_atomic) {
  411. wqe->has_rd_atomic = 0;
  412. atomic_inc(&qp->req.rd_atomic);
  413. if (qp->req.need_rd_atomic) {
  414. qp->comp.timeout_retry = 0;
  415. qp->req.need_rd_atomic = 0;
  416. rxe_run_task(&qp->req.task, 0);
  417. }
  418. }
  419. if (unlikely(qp->req.state == QP_STATE_DRAIN)) {
  420. /* state_lock used by requester & completer */
  421. spin_lock_irqsave(&qp->state_lock, flags);
  422. if ((qp->req.state == QP_STATE_DRAIN) &&
  423. (qp->comp.psn == qp->req.psn)) {
  424. qp->req.state = QP_STATE_DRAINED;
  425. spin_unlock_irqrestore(&qp->state_lock, flags);
  426. if (qp->ibqp.event_handler) {
  427. struct ib_event ev;
  428. ev.device = qp->ibqp.device;
  429. ev.element.qp = &qp->ibqp;
  430. ev.event = IB_EVENT_SQ_DRAINED;
  431. qp->ibqp.event_handler(&ev,
  432. qp->ibqp.qp_context);
  433. }
  434. } else {
  435. spin_unlock_irqrestore(&qp->state_lock, flags);
  436. }
  437. }
  438. do_complete(qp, wqe);
  439. if (psn_compare(pkt->psn, qp->comp.psn) >= 0)
  440. return COMPST_UPDATE_COMP;
  441. else
  442. return COMPST_DONE;
  443. }
  444. static inline enum comp_state complete_wqe(struct rxe_qp *qp,
  445. struct rxe_pkt_info *pkt,
  446. struct rxe_send_wqe *wqe)
  447. {
  448. if (pkt && wqe->state == wqe_state_pending) {
  449. if (psn_compare(wqe->last_psn, qp->comp.psn) >= 0) {
  450. qp->comp.psn = (wqe->last_psn + 1) & BTH_PSN_MASK;
  451. qp->comp.opcode = -1;
  452. }
  453. if (qp->req.wait_psn) {
  454. qp->req.wait_psn = 0;
  455. rxe_run_task(&qp->req.task, 1);
  456. }
  457. }
  458. do_complete(qp, wqe);
  459. return COMPST_GET_WQE;
  460. }
  461. static void rxe_drain_resp_pkts(struct rxe_qp *qp, bool notify)
  462. {
  463. struct sk_buff *skb;
  464. struct rxe_send_wqe *wqe;
  465. while ((skb = skb_dequeue(&qp->resp_pkts))) {
  466. rxe_drop_ref(qp);
  467. kfree_skb(skb);
  468. }
  469. while ((wqe = queue_head(qp->sq.queue))) {
  470. if (notify) {
  471. wqe->status = IB_WC_WR_FLUSH_ERR;
  472. do_complete(qp, wqe);
  473. } else {
  474. advance_consumer(qp->sq.queue);
  475. }
  476. }
  477. }
  478. int rxe_completer(void *arg)
  479. {
  480. struct rxe_qp *qp = (struct rxe_qp *)arg;
  481. struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
  482. struct rxe_send_wqe *wqe = wqe;
  483. struct sk_buff *skb = NULL;
  484. struct rxe_pkt_info *pkt = NULL;
  485. enum comp_state state;
  486. rxe_add_ref(qp);
  487. if (!qp->valid || qp->req.state == QP_STATE_ERROR ||
  488. qp->req.state == QP_STATE_RESET) {
  489. rxe_drain_resp_pkts(qp, qp->valid &&
  490. qp->req.state == QP_STATE_ERROR);
  491. goto exit;
  492. }
  493. if (qp->comp.timeout) {
  494. qp->comp.timeout_retry = 1;
  495. qp->comp.timeout = 0;
  496. } else {
  497. qp->comp.timeout_retry = 0;
  498. }
  499. if (qp->req.need_retry)
  500. goto exit;
  501. state = COMPST_GET_ACK;
  502. while (1) {
  503. pr_debug("qp#%d state = %s\n", qp_num(qp),
  504. comp_state_name[state]);
  505. switch (state) {
  506. case COMPST_GET_ACK:
  507. skb = skb_dequeue(&qp->resp_pkts);
  508. if (skb) {
  509. pkt = SKB_TO_PKT(skb);
  510. qp->comp.timeout_retry = 0;
  511. }
  512. state = COMPST_GET_WQE;
  513. break;
  514. case COMPST_GET_WQE:
  515. state = get_wqe(qp, pkt, &wqe);
  516. break;
  517. case COMPST_CHECK_PSN:
  518. state = check_psn(qp, pkt, wqe);
  519. break;
  520. case COMPST_CHECK_ACK:
  521. state = check_ack(qp, pkt, wqe);
  522. break;
  523. case COMPST_READ:
  524. state = do_read(qp, pkt, wqe);
  525. break;
  526. case COMPST_ATOMIC:
  527. state = do_atomic(qp, pkt, wqe);
  528. break;
  529. case COMPST_WRITE_SEND:
  530. if (wqe->state == wqe_state_pending &&
  531. wqe->last_psn == pkt->psn)
  532. state = COMPST_COMP_ACK;
  533. else
  534. state = COMPST_UPDATE_COMP;
  535. break;
  536. case COMPST_COMP_ACK:
  537. state = complete_ack(qp, pkt, wqe);
  538. break;
  539. case COMPST_COMP_WQE:
  540. state = complete_wqe(qp, pkt, wqe);
  541. break;
  542. case COMPST_UPDATE_COMP:
  543. if (pkt->mask & RXE_END_MASK)
  544. qp->comp.opcode = -1;
  545. else
  546. qp->comp.opcode = pkt->opcode;
  547. if (psn_compare(pkt->psn, qp->comp.psn) >= 0)
  548. qp->comp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
  549. if (qp->req.wait_psn) {
  550. qp->req.wait_psn = 0;
  551. rxe_run_task(&qp->req.task, 1);
  552. }
  553. state = COMPST_DONE;
  554. break;
  555. case COMPST_DONE:
  556. if (pkt) {
  557. rxe_drop_ref(pkt->qp);
  558. kfree_skb(skb);
  559. skb = NULL;
  560. }
  561. goto done;
  562. case COMPST_EXIT:
  563. if (qp->comp.timeout_retry && wqe) {
  564. state = COMPST_ERROR_RETRY;
  565. break;
  566. }
  567. /* re reset the timeout counter if
  568. * (1) QP is type RC
  569. * (2) the QP is alive
  570. * (3) there is a packet sent by the requester that
  571. * might be acked (we still might get spurious
  572. * timeouts but try to keep them as few as possible)
  573. * (4) the timeout parameter is set
  574. */
  575. if ((qp_type(qp) == IB_QPT_RC) &&
  576. (qp->req.state == QP_STATE_READY) &&
  577. (psn_compare(qp->req.psn, qp->comp.psn) > 0) &&
  578. qp->qp_timeout_jiffies)
  579. mod_timer(&qp->retrans_timer,
  580. jiffies + qp->qp_timeout_jiffies);
  581. goto exit;
  582. case COMPST_ERROR_RETRY:
  583. /* we come here if the retry timer fired and we did
  584. * not receive a response packet. try to retry the send
  585. * queue if that makes sense and the limits have not
  586. * been exceeded. remember that some timeouts are
  587. * spurious since we do not reset the timer but kick
  588. * it down the road or let it expire
  589. */
  590. /* there is nothing to retry in this case */
  591. if (!wqe || (wqe->state == wqe_state_posted)) {
  592. goto exit;
  593. }
  594. /* if we've started a retry, don't start another
  595. * retry sequence, unless this is a timeout.
  596. */
  597. if (qp->comp.started_retry &&
  598. !qp->comp.timeout_retry) {
  599. if (pkt) {
  600. rxe_drop_ref(pkt->qp);
  601. kfree_skb(skb);
  602. skb = NULL;
  603. }
  604. goto done;
  605. }
  606. if (qp->comp.retry_cnt > 0) {
  607. if (qp->comp.retry_cnt != 7)
  608. qp->comp.retry_cnt--;
  609. /* no point in retrying if we have already
  610. * seen the last ack that the requester could
  611. * have caused
  612. */
  613. if (psn_compare(qp->req.psn,
  614. qp->comp.psn) > 0) {
  615. /* tell the requester to retry the
  616. * send queue next time around
  617. */
  618. rxe_counter_inc(rxe,
  619. RXE_CNT_COMP_RETRY);
  620. qp->req.need_retry = 1;
  621. qp->comp.started_retry = 1;
  622. rxe_run_task(&qp->req.task, 0);
  623. }
  624. if (pkt) {
  625. rxe_drop_ref(pkt->qp);
  626. kfree_skb(skb);
  627. skb = NULL;
  628. }
  629. goto done;
  630. } else {
  631. rxe_counter_inc(rxe, RXE_CNT_RETRY_EXCEEDED);
  632. wqe->status = IB_WC_RETRY_EXC_ERR;
  633. state = COMPST_ERROR;
  634. }
  635. break;
  636. case COMPST_RNR_RETRY:
  637. if (qp->comp.rnr_retry > 0) {
  638. if (qp->comp.rnr_retry != 7)
  639. qp->comp.rnr_retry--;
  640. qp->req.need_retry = 1;
  641. pr_debug("qp#%d set rnr nak timer\n",
  642. qp_num(qp));
  643. mod_timer(&qp->rnr_nak_timer,
  644. jiffies + rnrnak_jiffies(aeth_syn(pkt)
  645. & ~AETH_TYPE_MASK));
  646. rxe_drop_ref(pkt->qp);
  647. kfree_skb(skb);
  648. skb = NULL;
  649. goto exit;
  650. } else {
  651. rxe_counter_inc(rxe,
  652. RXE_CNT_RNR_RETRY_EXCEEDED);
  653. wqe->status = IB_WC_RNR_RETRY_EXC_ERR;
  654. state = COMPST_ERROR;
  655. }
  656. break;
  657. case COMPST_ERROR:
  658. WARN_ON_ONCE(wqe->status == IB_WC_SUCCESS);
  659. do_complete(qp, wqe);
  660. rxe_qp_error(qp);
  661. if (pkt) {
  662. rxe_drop_ref(pkt->qp);
  663. kfree_skb(skb);
  664. skb = NULL;
  665. }
  666. goto exit;
  667. }
  668. }
  669. exit:
  670. /* we come here if we are done with processing and want the task to
  671. * exit from the loop calling us
  672. */
  673. WARN_ON_ONCE(skb);
  674. rxe_drop_ref(qp);
  675. return -EAGAIN;
  676. done:
  677. /* we come here if we have processed a packet we want the task to call
  678. * us again to see if there is anything else to do
  679. */
  680. WARN_ON_ONCE(skb);
  681. rxe_drop_ref(qp);
  682. return 0;
  683. }