rxe_comp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  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(unsigned long data)
  131. {
  132. struct rxe_qp *qp = (struct rxe_qp *)data;
  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. rxe_run_task(&qp->comp.task, must_sched);
  145. }
  146. static inline enum comp_state get_wqe(struct rxe_qp *qp,
  147. struct rxe_pkt_info *pkt,
  148. struct rxe_send_wqe **wqe_p)
  149. {
  150. struct rxe_send_wqe *wqe;
  151. /* we come here whether or not we found a response packet to see if
  152. * there are any posted WQEs
  153. */
  154. wqe = queue_head(qp->sq.queue);
  155. *wqe_p = wqe;
  156. /* no WQE or requester has not started it yet */
  157. if (!wqe || wqe->state == wqe_state_posted)
  158. return pkt ? COMPST_DONE : COMPST_EXIT;
  159. /* WQE does not require an ack */
  160. if (wqe->state == wqe_state_done)
  161. return COMPST_COMP_WQE;
  162. /* WQE caused an error */
  163. if (wqe->state == wqe_state_error)
  164. return COMPST_ERROR;
  165. /* we have a WQE, if we also have an ack check its PSN */
  166. return pkt ? COMPST_CHECK_PSN : COMPST_EXIT;
  167. }
  168. static inline void reset_retry_counters(struct rxe_qp *qp)
  169. {
  170. qp->comp.retry_cnt = qp->attr.retry_cnt;
  171. qp->comp.rnr_retry = qp->attr.rnr_retry;
  172. }
  173. static inline enum comp_state check_psn(struct rxe_qp *qp,
  174. struct rxe_pkt_info *pkt,
  175. struct rxe_send_wqe *wqe)
  176. {
  177. s32 diff;
  178. /* check to see if response is past the oldest WQE. if it is, complete
  179. * send/write or error read/atomic
  180. */
  181. diff = psn_compare(pkt->psn, wqe->last_psn);
  182. if (diff > 0) {
  183. if (wqe->state == wqe_state_pending) {
  184. if (wqe->mask & WR_ATOMIC_OR_READ_MASK)
  185. return COMPST_ERROR_RETRY;
  186. reset_retry_counters(qp);
  187. return COMPST_COMP_WQE;
  188. } else {
  189. return COMPST_DONE;
  190. }
  191. }
  192. /* compare response packet to expected response */
  193. diff = psn_compare(pkt->psn, qp->comp.psn);
  194. if (diff < 0) {
  195. /* response is most likely a retried packet if it matches an
  196. * uncompleted WQE go complete it else ignore it
  197. */
  198. if (pkt->psn == wqe->last_psn)
  199. return COMPST_COMP_ACK;
  200. else
  201. return COMPST_DONE;
  202. } else if ((diff > 0) && (wqe->mask & WR_ATOMIC_OR_READ_MASK)) {
  203. return COMPST_ERROR_RETRY;
  204. } else {
  205. return COMPST_CHECK_ACK;
  206. }
  207. }
  208. static inline enum comp_state check_ack(struct rxe_qp *qp,
  209. struct rxe_pkt_info *pkt,
  210. struct rxe_send_wqe *wqe)
  211. {
  212. unsigned int mask = pkt->mask;
  213. u8 syn;
  214. /* Check the sequence only */
  215. switch (qp->comp.opcode) {
  216. case -1:
  217. /* Will catch all *_ONLY cases. */
  218. if (!(mask & RXE_START_MASK))
  219. return COMPST_ERROR;
  220. break;
  221. case IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST:
  222. case IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE:
  223. if (pkt->opcode != IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE &&
  224. pkt->opcode != IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST) {
  225. return COMPST_ERROR;
  226. }
  227. break;
  228. default:
  229. WARN_ON(1);
  230. }
  231. /* Check operation validity. */
  232. switch (pkt->opcode) {
  233. case IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST:
  234. case IB_OPCODE_RC_RDMA_READ_RESPONSE_LAST:
  235. case IB_OPCODE_RC_RDMA_READ_RESPONSE_ONLY:
  236. syn = aeth_syn(pkt);
  237. if ((syn & AETH_TYPE_MASK) != AETH_ACK)
  238. return COMPST_ERROR;
  239. /* Fall through (IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE
  240. * doesn't have an AETH)
  241. */
  242. case IB_OPCODE_RC_RDMA_READ_RESPONSE_MIDDLE:
  243. if (wqe->wr.opcode != IB_WR_RDMA_READ &&
  244. wqe->wr.opcode != IB_WR_RDMA_READ_WITH_INV) {
  245. return COMPST_ERROR;
  246. }
  247. reset_retry_counters(qp);
  248. return COMPST_READ;
  249. case IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE:
  250. syn = aeth_syn(pkt);
  251. if ((syn & AETH_TYPE_MASK) != AETH_ACK)
  252. return COMPST_ERROR;
  253. if (wqe->wr.opcode != IB_WR_ATOMIC_CMP_AND_SWP &&
  254. wqe->wr.opcode != IB_WR_ATOMIC_FETCH_AND_ADD)
  255. return COMPST_ERROR;
  256. reset_retry_counters(qp);
  257. return COMPST_ATOMIC;
  258. case IB_OPCODE_RC_ACKNOWLEDGE:
  259. syn = aeth_syn(pkt);
  260. switch (syn & AETH_TYPE_MASK) {
  261. case AETH_ACK:
  262. reset_retry_counters(qp);
  263. return COMPST_WRITE_SEND;
  264. case AETH_RNR_NAK:
  265. return COMPST_RNR_RETRY;
  266. case AETH_NAK:
  267. switch (syn) {
  268. case AETH_NAK_PSN_SEQ_ERROR:
  269. /* a nak implicitly acks all packets with psns
  270. * before
  271. */
  272. if (psn_compare(pkt->psn, qp->comp.psn) > 0) {
  273. qp->comp.psn = pkt->psn;
  274. if (qp->req.wait_psn) {
  275. qp->req.wait_psn = 0;
  276. rxe_run_task(&qp->req.task, 1);
  277. }
  278. }
  279. return COMPST_ERROR_RETRY;
  280. case AETH_NAK_INVALID_REQ:
  281. wqe->status = IB_WC_REM_INV_REQ_ERR;
  282. return COMPST_ERROR;
  283. case AETH_NAK_REM_ACC_ERR:
  284. wqe->status = IB_WC_REM_ACCESS_ERR;
  285. return COMPST_ERROR;
  286. case AETH_NAK_REM_OP_ERR:
  287. wqe->status = IB_WC_REM_OP_ERR;
  288. return COMPST_ERROR;
  289. default:
  290. pr_warn("unexpected nak %x\n", syn);
  291. wqe->status = IB_WC_REM_OP_ERR;
  292. return COMPST_ERROR;
  293. }
  294. default:
  295. return COMPST_ERROR;
  296. }
  297. break;
  298. default:
  299. pr_warn("unexpected opcode\n");
  300. }
  301. return COMPST_ERROR;
  302. }
  303. static inline enum comp_state do_read(struct rxe_qp *qp,
  304. struct rxe_pkt_info *pkt,
  305. struct rxe_send_wqe *wqe)
  306. {
  307. struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
  308. int ret;
  309. ret = copy_data(rxe, qp->pd, IB_ACCESS_LOCAL_WRITE,
  310. &wqe->dma, payload_addr(pkt),
  311. payload_size(pkt), to_mem_obj, NULL);
  312. if (ret)
  313. return COMPST_ERROR;
  314. if (wqe->dma.resid == 0 && (pkt->mask & RXE_END_MASK))
  315. return COMPST_COMP_ACK;
  316. else
  317. return COMPST_UPDATE_COMP;
  318. }
  319. static inline enum comp_state do_atomic(struct rxe_qp *qp,
  320. struct rxe_pkt_info *pkt,
  321. struct rxe_send_wqe *wqe)
  322. {
  323. struct rxe_dev *rxe = to_rdev(qp->ibqp.device);
  324. int ret;
  325. u64 atomic_orig = atmack_orig(pkt);
  326. ret = copy_data(rxe, qp->pd, IB_ACCESS_LOCAL_WRITE,
  327. &wqe->dma, &atomic_orig,
  328. sizeof(u64), to_mem_obj, NULL);
  329. if (ret)
  330. return COMPST_ERROR;
  331. else
  332. return COMPST_COMP_ACK;
  333. }
  334. static void make_send_cqe(struct rxe_qp *qp, struct rxe_send_wqe *wqe,
  335. struct rxe_cqe *cqe)
  336. {
  337. memset(cqe, 0, sizeof(*cqe));
  338. if (!qp->is_user) {
  339. struct ib_wc *wc = &cqe->ibwc;
  340. wc->wr_id = wqe->wr.wr_id;
  341. wc->status = wqe->status;
  342. wc->opcode = wr_to_wc_opcode(wqe->wr.opcode);
  343. if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
  344. wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
  345. wc->wc_flags = IB_WC_WITH_IMM;
  346. wc->byte_len = wqe->dma.length;
  347. wc->qp = &qp->ibqp;
  348. } else {
  349. struct ib_uverbs_wc *uwc = &cqe->uibwc;
  350. uwc->wr_id = wqe->wr.wr_id;
  351. uwc->status = wqe->status;
  352. uwc->opcode = wr_to_wc_opcode(wqe->wr.opcode);
  353. if (wqe->wr.opcode == IB_WR_RDMA_WRITE_WITH_IMM ||
  354. wqe->wr.opcode == IB_WR_SEND_WITH_IMM)
  355. uwc->wc_flags = IB_WC_WITH_IMM;
  356. uwc->byte_len = wqe->dma.length;
  357. uwc->qp_num = qp->ibqp.qp_num;
  358. }
  359. }
  360. static void do_complete(struct rxe_qp *qp, struct rxe_send_wqe *wqe)
  361. {
  362. struct rxe_cqe cqe;
  363. if ((qp->sq_sig_type == IB_SIGNAL_ALL_WR) ||
  364. (wqe->wr.send_flags & IB_SEND_SIGNALED) ||
  365. (qp->req.state == QP_STATE_ERROR)) {
  366. make_send_cqe(qp, wqe, &cqe);
  367. rxe_cq_post(qp->scq, &cqe, 0);
  368. }
  369. advance_consumer(qp->sq.queue);
  370. /*
  371. * we completed something so let req run again
  372. * if it is trying to fence
  373. */
  374. if (qp->req.wait_fence) {
  375. qp->req.wait_fence = 0;
  376. rxe_run_task(&qp->req.task, 1);
  377. }
  378. }
  379. static inline enum comp_state complete_ack(struct rxe_qp *qp,
  380. struct rxe_pkt_info *pkt,
  381. struct rxe_send_wqe *wqe)
  382. {
  383. unsigned long flags;
  384. if (wqe->has_rd_atomic) {
  385. wqe->has_rd_atomic = 0;
  386. atomic_inc(&qp->req.rd_atomic);
  387. if (qp->req.need_rd_atomic) {
  388. qp->comp.timeout_retry = 0;
  389. qp->req.need_rd_atomic = 0;
  390. rxe_run_task(&qp->req.task, 1);
  391. }
  392. }
  393. if (unlikely(qp->req.state == QP_STATE_DRAIN)) {
  394. /* state_lock used by requester & completer */
  395. spin_lock_irqsave(&qp->state_lock, flags);
  396. if ((qp->req.state == QP_STATE_DRAIN) &&
  397. (qp->comp.psn == qp->req.psn)) {
  398. qp->req.state = QP_STATE_DRAINED;
  399. spin_unlock_irqrestore(&qp->state_lock, flags);
  400. if (qp->ibqp.event_handler) {
  401. struct ib_event ev;
  402. ev.device = qp->ibqp.device;
  403. ev.element.qp = &qp->ibqp;
  404. ev.event = IB_EVENT_SQ_DRAINED;
  405. qp->ibqp.event_handler(&ev,
  406. qp->ibqp.qp_context);
  407. }
  408. } else {
  409. spin_unlock_irqrestore(&qp->state_lock, flags);
  410. }
  411. }
  412. do_complete(qp, wqe);
  413. if (psn_compare(pkt->psn, qp->comp.psn) >= 0)
  414. return COMPST_UPDATE_COMP;
  415. else
  416. return COMPST_DONE;
  417. }
  418. static inline enum comp_state complete_wqe(struct rxe_qp *qp,
  419. struct rxe_pkt_info *pkt,
  420. struct rxe_send_wqe *wqe)
  421. {
  422. qp->comp.opcode = -1;
  423. if (pkt) {
  424. if (psn_compare(pkt->psn, qp->comp.psn) >= 0)
  425. qp->comp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
  426. if (qp->req.wait_psn) {
  427. qp->req.wait_psn = 0;
  428. rxe_run_task(&qp->req.task, 1);
  429. }
  430. }
  431. do_complete(qp, wqe);
  432. return COMPST_GET_WQE;
  433. }
  434. int rxe_completer(void *arg)
  435. {
  436. struct rxe_qp *qp = (struct rxe_qp *)arg;
  437. struct rxe_send_wqe *wqe = wqe;
  438. struct sk_buff *skb = NULL;
  439. struct rxe_pkt_info *pkt = NULL;
  440. enum comp_state state;
  441. if (!qp->valid) {
  442. while ((skb = skb_dequeue(&qp->resp_pkts))) {
  443. rxe_drop_ref(qp);
  444. kfree_skb(skb);
  445. }
  446. skb = NULL;
  447. pkt = NULL;
  448. while (queue_head(qp->sq.queue))
  449. advance_consumer(qp->sq.queue);
  450. goto exit;
  451. }
  452. if (qp->req.state == QP_STATE_ERROR) {
  453. while ((skb = skb_dequeue(&qp->resp_pkts))) {
  454. rxe_drop_ref(qp);
  455. kfree_skb(skb);
  456. }
  457. skb = NULL;
  458. pkt = NULL;
  459. while ((wqe = queue_head(qp->sq.queue))) {
  460. wqe->status = IB_WC_WR_FLUSH_ERR;
  461. do_complete(qp, wqe);
  462. }
  463. goto exit;
  464. }
  465. if (qp->req.state == QP_STATE_RESET) {
  466. while ((skb = skb_dequeue(&qp->resp_pkts))) {
  467. rxe_drop_ref(qp);
  468. kfree_skb(skb);
  469. }
  470. skb = NULL;
  471. pkt = NULL;
  472. while (queue_head(qp->sq.queue))
  473. advance_consumer(qp->sq.queue);
  474. goto exit;
  475. }
  476. if (qp->comp.timeout) {
  477. qp->comp.timeout_retry = 1;
  478. qp->comp.timeout = 0;
  479. } else {
  480. qp->comp.timeout_retry = 0;
  481. }
  482. if (qp->req.need_retry)
  483. goto exit;
  484. state = COMPST_GET_ACK;
  485. while (1) {
  486. pr_debug("qp#%d state = %s\n", qp_num(qp),
  487. comp_state_name[state]);
  488. switch (state) {
  489. case COMPST_GET_ACK:
  490. skb = skb_dequeue(&qp->resp_pkts);
  491. if (skb) {
  492. pkt = SKB_TO_PKT(skb);
  493. qp->comp.timeout_retry = 0;
  494. }
  495. state = COMPST_GET_WQE;
  496. break;
  497. case COMPST_GET_WQE:
  498. state = get_wqe(qp, pkt, &wqe);
  499. break;
  500. case COMPST_CHECK_PSN:
  501. state = check_psn(qp, pkt, wqe);
  502. break;
  503. case COMPST_CHECK_ACK:
  504. state = check_ack(qp, pkt, wqe);
  505. break;
  506. case COMPST_READ:
  507. state = do_read(qp, pkt, wqe);
  508. break;
  509. case COMPST_ATOMIC:
  510. state = do_atomic(qp, pkt, wqe);
  511. break;
  512. case COMPST_WRITE_SEND:
  513. if (wqe->state == wqe_state_pending &&
  514. wqe->last_psn == pkt->psn)
  515. state = COMPST_COMP_ACK;
  516. else
  517. state = COMPST_UPDATE_COMP;
  518. break;
  519. case COMPST_COMP_ACK:
  520. state = complete_ack(qp, pkt, wqe);
  521. break;
  522. case COMPST_COMP_WQE:
  523. state = complete_wqe(qp, pkt, wqe);
  524. break;
  525. case COMPST_UPDATE_COMP:
  526. if (pkt->mask & RXE_END_MASK)
  527. qp->comp.opcode = -1;
  528. else
  529. qp->comp.opcode = pkt->opcode;
  530. if (psn_compare(pkt->psn, qp->comp.psn) >= 0)
  531. qp->comp.psn = (pkt->psn + 1) & BTH_PSN_MASK;
  532. if (qp->req.wait_psn) {
  533. qp->req.wait_psn = 0;
  534. rxe_run_task(&qp->req.task, 1);
  535. }
  536. state = COMPST_DONE;
  537. break;
  538. case COMPST_DONE:
  539. if (pkt) {
  540. rxe_drop_ref(pkt->qp);
  541. kfree_skb(skb);
  542. }
  543. goto done;
  544. case COMPST_EXIT:
  545. if (qp->comp.timeout_retry && wqe) {
  546. state = COMPST_ERROR_RETRY;
  547. break;
  548. }
  549. /* re reset the timeout counter if
  550. * (1) QP is type RC
  551. * (2) the QP is alive
  552. * (3) there is a packet sent by the requester that
  553. * might be acked (we still might get spurious
  554. * timeouts but try to keep them as few as possible)
  555. * (4) the timeout parameter is set
  556. */
  557. if ((qp_type(qp) == IB_QPT_RC) &&
  558. (qp->req.state == QP_STATE_READY) &&
  559. (psn_compare(qp->req.psn, qp->comp.psn) > 0) &&
  560. qp->qp_timeout_jiffies)
  561. mod_timer(&qp->retrans_timer,
  562. jiffies + qp->qp_timeout_jiffies);
  563. goto exit;
  564. case COMPST_ERROR_RETRY:
  565. /* we come here if the retry timer fired and we did
  566. * not receive a response packet. try to retry the send
  567. * queue if that makes sense and the limits have not
  568. * been exceeded. remember that some timeouts are
  569. * spurious since we do not reset the timer but kick
  570. * it down the road or let it expire
  571. */
  572. /* there is nothing to retry in this case */
  573. if (!wqe || (wqe->state == wqe_state_posted))
  574. goto exit;
  575. if (qp->comp.retry_cnt > 0) {
  576. if (qp->comp.retry_cnt != 7)
  577. qp->comp.retry_cnt--;
  578. /* no point in retrying if we have already
  579. * seen the last ack that the requester could
  580. * have caused
  581. */
  582. if (psn_compare(qp->req.psn,
  583. qp->comp.psn) > 0) {
  584. /* tell the requester to retry the
  585. * send send queue next time around
  586. */
  587. qp->req.need_retry = 1;
  588. rxe_run_task(&qp->req.task, 1);
  589. }
  590. if (pkt) {
  591. rxe_drop_ref(pkt->qp);
  592. kfree_skb(skb);
  593. }
  594. goto exit;
  595. } else {
  596. wqe->status = IB_WC_RETRY_EXC_ERR;
  597. state = COMPST_ERROR;
  598. }
  599. break;
  600. case COMPST_RNR_RETRY:
  601. if (qp->comp.rnr_retry > 0) {
  602. if (qp->comp.rnr_retry != 7)
  603. qp->comp.rnr_retry--;
  604. qp->req.need_retry = 1;
  605. pr_debug("qp#%d set rnr nak timer\n",
  606. qp_num(qp));
  607. mod_timer(&qp->rnr_nak_timer,
  608. jiffies + rnrnak_jiffies(aeth_syn(pkt)
  609. & ~AETH_TYPE_MASK));
  610. goto exit;
  611. } else {
  612. wqe->status = IB_WC_RNR_RETRY_EXC_ERR;
  613. state = COMPST_ERROR;
  614. }
  615. break;
  616. case COMPST_ERROR:
  617. do_complete(qp, wqe);
  618. rxe_qp_error(qp);
  619. if (pkt) {
  620. rxe_drop_ref(pkt->qp);
  621. kfree_skb(skb);
  622. }
  623. goto exit;
  624. }
  625. }
  626. exit:
  627. /* we come here if we are done with processing and want the task to
  628. * exit from the loop calling us
  629. */
  630. return -EAGAIN;
  631. done:
  632. /* we come here if we have processed a packet we want the task to call
  633. * us again to see if there is anything else to do
  634. */
  635. return 0;
  636. }