qib_rc.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160
  1. /*
  2. * Copyright (c) 2006, 2007, 2008, 2009 QLogic Corporation. All rights reserved.
  3. * Copyright (c) 2005, 2006 PathScale, 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/io.h>
  34. #include "qib.h"
  35. /* cut down ridiculously long IB macro names */
  36. #define OP(x) IB_OPCODE_RC_##x
  37. static u32 restart_sge(struct rvt_sge_state *ss, struct rvt_swqe *wqe,
  38. u32 psn, u32 pmtu)
  39. {
  40. u32 len;
  41. len = ((psn - wqe->psn) & QIB_PSN_MASK) * pmtu;
  42. ss->sge = wqe->sg_list[0];
  43. ss->sg_list = wqe->sg_list + 1;
  44. ss->num_sge = wqe->wr.num_sge;
  45. ss->total_len = wqe->length;
  46. rvt_skip_sge(ss, len, false);
  47. return wqe->length - len;
  48. }
  49. /**
  50. * qib_make_rc_ack - construct a response packet (ACK, NAK, or RDMA read)
  51. * @dev: the device for this QP
  52. * @qp: a pointer to the QP
  53. * @ohdr: a pointer to the IB header being constructed
  54. * @pmtu: the path MTU
  55. *
  56. * Return 1 if constructed; otherwise, return 0.
  57. * Note that we are in the responder's side of the QP context.
  58. * Note the QP s_lock must be held.
  59. */
  60. static int qib_make_rc_ack(struct qib_ibdev *dev, struct rvt_qp *qp,
  61. struct ib_other_headers *ohdr, u32 pmtu)
  62. {
  63. struct rvt_ack_entry *e;
  64. u32 hwords;
  65. u32 len;
  66. u32 bth0;
  67. u32 bth2;
  68. /* Don't send an ACK if we aren't supposed to. */
  69. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
  70. goto bail;
  71. /* header size in 32-bit words LRH+BTH = (8+12)/4. */
  72. hwords = 5;
  73. switch (qp->s_ack_state) {
  74. case OP(RDMA_READ_RESPONSE_LAST):
  75. case OP(RDMA_READ_RESPONSE_ONLY):
  76. e = &qp->s_ack_queue[qp->s_tail_ack_queue];
  77. if (e->rdma_sge.mr) {
  78. rvt_put_mr(e->rdma_sge.mr);
  79. e->rdma_sge.mr = NULL;
  80. }
  81. /* FALLTHROUGH */
  82. case OP(ATOMIC_ACKNOWLEDGE):
  83. /*
  84. * We can increment the tail pointer now that the last
  85. * response has been sent instead of only being
  86. * constructed.
  87. */
  88. if (++qp->s_tail_ack_queue > QIB_MAX_RDMA_ATOMIC)
  89. qp->s_tail_ack_queue = 0;
  90. /* FALLTHROUGH */
  91. case OP(SEND_ONLY):
  92. case OP(ACKNOWLEDGE):
  93. /* Check for no next entry in the queue. */
  94. if (qp->r_head_ack_queue == qp->s_tail_ack_queue) {
  95. if (qp->s_flags & RVT_S_ACK_PENDING)
  96. goto normal;
  97. goto bail;
  98. }
  99. e = &qp->s_ack_queue[qp->s_tail_ack_queue];
  100. if (e->opcode == OP(RDMA_READ_REQUEST)) {
  101. /*
  102. * If a RDMA read response is being resent and
  103. * we haven't seen the duplicate request yet,
  104. * then stop sending the remaining responses the
  105. * responder has seen until the requester resends it.
  106. */
  107. len = e->rdma_sge.sge_length;
  108. if (len && !e->rdma_sge.mr) {
  109. qp->s_tail_ack_queue = qp->r_head_ack_queue;
  110. goto bail;
  111. }
  112. /* Copy SGE state in case we need to resend */
  113. qp->s_rdma_mr = e->rdma_sge.mr;
  114. if (qp->s_rdma_mr)
  115. rvt_get_mr(qp->s_rdma_mr);
  116. qp->s_ack_rdma_sge.sge = e->rdma_sge;
  117. qp->s_ack_rdma_sge.num_sge = 1;
  118. qp->s_cur_sge = &qp->s_ack_rdma_sge;
  119. if (len > pmtu) {
  120. len = pmtu;
  121. qp->s_ack_state = OP(RDMA_READ_RESPONSE_FIRST);
  122. } else {
  123. qp->s_ack_state = OP(RDMA_READ_RESPONSE_ONLY);
  124. e->sent = 1;
  125. }
  126. ohdr->u.aeth = rvt_compute_aeth(qp);
  127. hwords++;
  128. qp->s_ack_rdma_psn = e->psn;
  129. bth2 = qp->s_ack_rdma_psn++ & QIB_PSN_MASK;
  130. } else {
  131. /* COMPARE_SWAP or FETCH_ADD */
  132. qp->s_cur_sge = NULL;
  133. len = 0;
  134. qp->s_ack_state = OP(ATOMIC_ACKNOWLEDGE);
  135. ohdr->u.at.aeth = rvt_compute_aeth(qp);
  136. ib_u64_put(e->atomic_data, &ohdr->u.at.atomic_ack_eth);
  137. hwords += sizeof(ohdr->u.at) / sizeof(u32);
  138. bth2 = e->psn & QIB_PSN_MASK;
  139. e->sent = 1;
  140. }
  141. bth0 = qp->s_ack_state << 24;
  142. break;
  143. case OP(RDMA_READ_RESPONSE_FIRST):
  144. qp->s_ack_state = OP(RDMA_READ_RESPONSE_MIDDLE);
  145. /* FALLTHROUGH */
  146. case OP(RDMA_READ_RESPONSE_MIDDLE):
  147. qp->s_cur_sge = &qp->s_ack_rdma_sge;
  148. qp->s_rdma_mr = qp->s_ack_rdma_sge.sge.mr;
  149. if (qp->s_rdma_mr)
  150. rvt_get_mr(qp->s_rdma_mr);
  151. len = qp->s_ack_rdma_sge.sge.sge_length;
  152. if (len > pmtu)
  153. len = pmtu;
  154. else {
  155. ohdr->u.aeth = rvt_compute_aeth(qp);
  156. hwords++;
  157. qp->s_ack_state = OP(RDMA_READ_RESPONSE_LAST);
  158. e = &qp->s_ack_queue[qp->s_tail_ack_queue];
  159. e->sent = 1;
  160. }
  161. bth0 = qp->s_ack_state << 24;
  162. bth2 = qp->s_ack_rdma_psn++ & QIB_PSN_MASK;
  163. break;
  164. default:
  165. normal:
  166. /*
  167. * Send a regular ACK.
  168. * Set the s_ack_state so we wait until after sending
  169. * the ACK before setting s_ack_state to ACKNOWLEDGE
  170. * (see above).
  171. */
  172. qp->s_ack_state = OP(SEND_ONLY);
  173. qp->s_flags &= ~RVT_S_ACK_PENDING;
  174. qp->s_cur_sge = NULL;
  175. if (qp->s_nak_state)
  176. ohdr->u.aeth =
  177. cpu_to_be32((qp->r_msn & IB_MSN_MASK) |
  178. (qp->s_nak_state <<
  179. IB_AETH_CREDIT_SHIFT));
  180. else
  181. ohdr->u.aeth = rvt_compute_aeth(qp);
  182. hwords++;
  183. len = 0;
  184. bth0 = OP(ACKNOWLEDGE) << 24;
  185. bth2 = qp->s_ack_psn & QIB_PSN_MASK;
  186. }
  187. qp->s_rdma_ack_cnt++;
  188. qp->s_hdrwords = hwords;
  189. qp->s_cur_size = len;
  190. qib_make_ruc_header(qp, ohdr, bth0, bth2);
  191. return 1;
  192. bail:
  193. qp->s_ack_state = OP(ACKNOWLEDGE);
  194. qp->s_flags &= ~(RVT_S_RESP_PENDING | RVT_S_ACK_PENDING);
  195. return 0;
  196. }
  197. /**
  198. * qib_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC)
  199. * @qp: a pointer to the QP
  200. *
  201. * Assumes the s_lock is held.
  202. *
  203. * Return 1 if constructed; otherwise, return 0.
  204. */
  205. int qib_make_rc_req(struct rvt_qp *qp, unsigned long *flags)
  206. {
  207. struct qib_qp_priv *priv = qp->priv;
  208. struct qib_ibdev *dev = to_idev(qp->ibqp.device);
  209. struct ib_other_headers *ohdr;
  210. struct rvt_sge_state *ss;
  211. struct rvt_swqe *wqe;
  212. u32 hwords;
  213. u32 len;
  214. u32 bth0;
  215. u32 bth2;
  216. u32 pmtu = qp->pmtu;
  217. char newreq;
  218. int ret = 0;
  219. int delta;
  220. ohdr = &priv->s_hdr->u.oth;
  221. if (rdma_ah_get_ah_flags(&qp->remote_ah_attr) & IB_AH_GRH)
  222. ohdr = &priv->s_hdr->u.l.oth;
  223. /* Sending responses has higher priority over sending requests. */
  224. if ((qp->s_flags & RVT_S_RESP_PENDING) &&
  225. qib_make_rc_ack(dev, qp, ohdr, pmtu))
  226. goto done;
  227. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_SEND_OK)) {
  228. if (!(ib_rvt_state_ops[qp->state] & RVT_FLUSH_SEND))
  229. goto bail;
  230. /* We are in the error state, flush the work request. */
  231. smp_read_barrier_depends(); /* see post_one_send() */
  232. if (qp->s_last == READ_ONCE(qp->s_head))
  233. goto bail;
  234. /* If DMAs are in progress, we can't flush immediately. */
  235. if (atomic_read(&priv->s_dma_busy)) {
  236. qp->s_flags |= RVT_S_WAIT_DMA;
  237. goto bail;
  238. }
  239. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  240. qib_send_complete(qp, wqe, qp->s_last != qp->s_acked ?
  241. IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR);
  242. /* will get called again */
  243. goto done;
  244. }
  245. if (qp->s_flags & (RVT_S_WAIT_RNR | RVT_S_WAIT_ACK))
  246. goto bail;
  247. if (qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) {
  248. if (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) {
  249. qp->s_flags |= RVT_S_WAIT_PSN;
  250. goto bail;
  251. }
  252. qp->s_sending_psn = qp->s_psn;
  253. qp->s_sending_hpsn = qp->s_psn - 1;
  254. }
  255. /* header size in 32-bit words LRH+BTH = (8+12)/4. */
  256. hwords = 5;
  257. bth0 = 0;
  258. /* Send a request. */
  259. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  260. switch (qp->s_state) {
  261. default:
  262. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK))
  263. goto bail;
  264. /*
  265. * Resend an old request or start a new one.
  266. *
  267. * We keep track of the current SWQE so that
  268. * we don't reset the "furthest progress" state
  269. * if we need to back up.
  270. */
  271. newreq = 0;
  272. if (qp->s_cur == qp->s_tail) {
  273. /* Check if send work queue is empty. */
  274. smp_read_barrier_depends(); /* see post_one_send() */
  275. if (qp->s_tail == READ_ONCE(qp->s_head))
  276. goto bail;
  277. /*
  278. * If a fence is requested, wait for previous
  279. * RDMA read and atomic operations to finish.
  280. */
  281. if ((wqe->wr.send_flags & IB_SEND_FENCE) &&
  282. qp->s_num_rd_atomic) {
  283. qp->s_flags |= RVT_S_WAIT_FENCE;
  284. goto bail;
  285. }
  286. newreq = 1;
  287. qp->s_psn = wqe->psn;
  288. }
  289. /*
  290. * Note that we have to be careful not to modify the
  291. * original work request since we may need to resend
  292. * it.
  293. */
  294. len = wqe->length;
  295. ss = &qp->s_sge;
  296. bth2 = qp->s_psn & QIB_PSN_MASK;
  297. switch (wqe->wr.opcode) {
  298. case IB_WR_SEND:
  299. case IB_WR_SEND_WITH_IMM:
  300. /* If no credit, return. */
  301. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
  302. rvt_cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) {
  303. qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
  304. goto bail;
  305. }
  306. if (len > pmtu) {
  307. qp->s_state = OP(SEND_FIRST);
  308. len = pmtu;
  309. break;
  310. }
  311. if (wqe->wr.opcode == IB_WR_SEND)
  312. qp->s_state = OP(SEND_ONLY);
  313. else {
  314. qp->s_state = OP(SEND_ONLY_WITH_IMMEDIATE);
  315. /* Immediate data comes after the BTH */
  316. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  317. hwords += 1;
  318. }
  319. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  320. bth0 |= IB_BTH_SOLICITED;
  321. bth2 |= IB_BTH_REQ_ACK;
  322. if (++qp->s_cur == qp->s_size)
  323. qp->s_cur = 0;
  324. break;
  325. case IB_WR_RDMA_WRITE:
  326. if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
  327. qp->s_lsn++;
  328. goto no_flow_control;
  329. case IB_WR_RDMA_WRITE_WITH_IMM:
  330. /* If no credit, return. */
  331. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
  332. rvt_cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) {
  333. qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
  334. goto bail;
  335. }
  336. no_flow_control:
  337. ohdr->u.rc.reth.vaddr =
  338. cpu_to_be64(wqe->rdma_wr.remote_addr);
  339. ohdr->u.rc.reth.rkey =
  340. cpu_to_be32(wqe->rdma_wr.rkey);
  341. ohdr->u.rc.reth.length = cpu_to_be32(len);
  342. hwords += sizeof(struct ib_reth) / sizeof(u32);
  343. if (len > pmtu) {
  344. qp->s_state = OP(RDMA_WRITE_FIRST);
  345. len = pmtu;
  346. break;
  347. }
  348. if (wqe->rdma_wr.wr.opcode == IB_WR_RDMA_WRITE)
  349. qp->s_state = OP(RDMA_WRITE_ONLY);
  350. else {
  351. qp->s_state = OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
  352. /* Immediate data comes after RETH */
  353. ohdr->u.rc.imm_data =
  354. wqe->rdma_wr.wr.ex.imm_data;
  355. hwords += 1;
  356. if (wqe->rdma_wr.wr.send_flags & IB_SEND_SOLICITED)
  357. bth0 |= IB_BTH_SOLICITED;
  358. }
  359. bth2 |= IB_BTH_REQ_ACK;
  360. if (++qp->s_cur == qp->s_size)
  361. qp->s_cur = 0;
  362. break;
  363. case IB_WR_RDMA_READ:
  364. /*
  365. * Don't allow more operations to be started
  366. * than the QP limits allow.
  367. */
  368. if (newreq) {
  369. if (qp->s_num_rd_atomic >=
  370. qp->s_max_rd_atomic) {
  371. qp->s_flags |= RVT_S_WAIT_RDMAR;
  372. goto bail;
  373. }
  374. qp->s_num_rd_atomic++;
  375. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
  376. qp->s_lsn++;
  377. }
  378. ohdr->u.rc.reth.vaddr =
  379. cpu_to_be64(wqe->rdma_wr.remote_addr);
  380. ohdr->u.rc.reth.rkey =
  381. cpu_to_be32(wqe->rdma_wr.rkey);
  382. ohdr->u.rc.reth.length = cpu_to_be32(len);
  383. qp->s_state = OP(RDMA_READ_REQUEST);
  384. hwords += sizeof(ohdr->u.rc.reth) / sizeof(u32);
  385. ss = NULL;
  386. len = 0;
  387. bth2 |= IB_BTH_REQ_ACK;
  388. if (++qp->s_cur == qp->s_size)
  389. qp->s_cur = 0;
  390. break;
  391. case IB_WR_ATOMIC_CMP_AND_SWP:
  392. case IB_WR_ATOMIC_FETCH_AND_ADD:
  393. /*
  394. * Don't allow more operations to be started
  395. * than the QP limits allow.
  396. */
  397. if (newreq) {
  398. if (qp->s_num_rd_atomic >=
  399. qp->s_max_rd_atomic) {
  400. qp->s_flags |= RVT_S_WAIT_RDMAR;
  401. goto bail;
  402. }
  403. qp->s_num_rd_atomic++;
  404. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
  405. qp->s_lsn++;
  406. }
  407. if (wqe->atomic_wr.wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
  408. qp->s_state = OP(COMPARE_SWAP);
  409. put_ib_ateth_swap(wqe->atomic_wr.swap,
  410. &ohdr->u.atomic_eth);
  411. put_ib_ateth_swap(wqe->atomic_wr.compare_add,
  412. &ohdr->u.atomic_eth);
  413. } else {
  414. qp->s_state = OP(FETCH_ADD);
  415. put_ib_ateth_swap(wqe->atomic_wr.compare_add,
  416. &ohdr->u.atomic_eth);
  417. put_ib_ateth_swap(0, &ohdr->u.atomic_eth);
  418. }
  419. put_ib_ateth_vaddr(wqe->atomic_wr.remote_addr,
  420. &ohdr->u.atomic_eth);
  421. ohdr->u.atomic_eth.rkey = cpu_to_be32(
  422. wqe->atomic_wr.rkey);
  423. hwords += sizeof(struct ib_atomic_eth) / sizeof(u32);
  424. ss = NULL;
  425. len = 0;
  426. bth2 |= IB_BTH_REQ_ACK;
  427. if (++qp->s_cur == qp->s_size)
  428. qp->s_cur = 0;
  429. break;
  430. default:
  431. goto bail;
  432. }
  433. qp->s_sge.sge = wqe->sg_list[0];
  434. qp->s_sge.sg_list = wqe->sg_list + 1;
  435. qp->s_sge.num_sge = wqe->wr.num_sge;
  436. qp->s_sge.total_len = wqe->length;
  437. qp->s_len = wqe->length;
  438. if (newreq) {
  439. qp->s_tail++;
  440. if (qp->s_tail >= qp->s_size)
  441. qp->s_tail = 0;
  442. }
  443. if (wqe->wr.opcode == IB_WR_RDMA_READ)
  444. qp->s_psn = wqe->lpsn + 1;
  445. else
  446. qp->s_psn++;
  447. break;
  448. case OP(RDMA_READ_RESPONSE_FIRST):
  449. /*
  450. * qp->s_state is normally set to the opcode of the
  451. * last packet constructed for new requests and therefore
  452. * is never set to RDMA read response.
  453. * RDMA_READ_RESPONSE_FIRST is used by the ACK processing
  454. * thread to indicate a SEND needs to be restarted from an
  455. * earlier PSN without interferring with the sending thread.
  456. * See qib_restart_rc().
  457. */
  458. qp->s_len = restart_sge(&qp->s_sge, wqe, qp->s_psn, pmtu);
  459. /* FALLTHROUGH */
  460. case OP(SEND_FIRST):
  461. qp->s_state = OP(SEND_MIDDLE);
  462. /* FALLTHROUGH */
  463. case OP(SEND_MIDDLE):
  464. bth2 = qp->s_psn++ & QIB_PSN_MASK;
  465. ss = &qp->s_sge;
  466. len = qp->s_len;
  467. if (len > pmtu) {
  468. len = pmtu;
  469. break;
  470. }
  471. if (wqe->wr.opcode == IB_WR_SEND)
  472. qp->s_state = OP(SEND_LAST);
  473. else {
  474. qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
  475. /* Immediate data comes after the BTH */
  476. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  477. hwords += 1;
  478. }
  479. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  480. bth0 |= IB_BTH_SOLICITED;
  481. bth2 |= IB_BTH_REQ_ACK;
  482. qp->s_cur++;
  483. if (qp->s_cur >= qp->s_size)
  484. qp->s_cur = 0;
  485. break;
  486. case OP(RDMA_READ_RESPONSE_LAST):
  487. /*
  488. * qp->s_state is normally set to the opcode of the
  489. * last packet constructed for new requests and therefore
  490. * is never set to RDMA read response.
  491. * RDMA_READ_RESPONSE_LAST is used by the ACK processing
  492. * thread to indicate a RDMA write needs to be restarted from
  493. * an earlier PSN without interferring with the sending thread.
  494. * See qib_restart_rc().
  495. */
  496. qp->s_len = restart_sge(&qp->s_sge, wqe, qp->s_psn, pmtu);
  497. /* FALLTHROUGH */
  498. case OP(RDMA_WRITE_FIRST):
  499. qp->s_state = OP(RDMA_WRITE_MIDDLE);
  500. /* FALLTHROUGH */
  501. case OP(RDMA_WRITE_MIDDLE):
  502. bth2 = qp->s_psn++ & QIB_PSN_MASK;
  503. ss = &qp->s_sge;
  504. len = qp->s_len;
  505. if (len > pmtu) {
  506. len = pmtu;
  507. break;
  508. }
  509. if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
  510. qp->s_state = OP(RDMA_WRITE_LAST);
  511. else {
  512. qp->s_state = OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
  513. /* Immediate data comes after the BTH */
  514. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  515. hwords += 1;
  516. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  517. bth0 |= IB_BTH_SOLICITED;
  518. }
  519. bth2 |= IB_BTH_REQ_ACK;
  520. qp->s_cur++;
  521. if (qp->s_cur >= qp->s_size)
  522. qp->s_cur = 0;
  523. break;
  524. case OP(RDMA_READ_RESPONSE_MIDDLE):
  525. /*
  526. * qp->s_state is normally set to the opcode of the
  527. * last packet constructed for new requests and therefore
  528. * is never set to RDMA read response.
  529. * RDMA_READ_RESPONSE_MIDDLE is used by the ACK processing
  530. * thread to indicate a RDMA read needs to be restarted from
  531. * an earlier PSN without interferring with the sending thread.
  532. * See qib_restart_rc().
  533. */
  534. len = ((qp->s_psn - wqe->psn) & QIB_PSN_MASK) * pmtu;
  535. ohdr->u.rc.reth.vaddr =
  536. cpu_to_be64(wqe->rdma_wr.remote_addr + len);
  537. ohdr->u.rc.reth.rkey =
  538. cpu_to_be32(wqe->rdma_wr.rkey);
  539. ohdr->u.rc.reth.length = cpu_to_be32(wqe->length - len);
  540. qp->s_state = OP(RDMA_READ_REQUEST);
  541. hwords += sizeof(ohdr->u.rc.reth) / sizeof(u32);
  542. bth2 = (qp->s_psn & QIB_PSN_MASK) | IB_BTH_REQ_ACK;
  543. qp->s_psn = wqe->lpsn + 1;
  544. ss = NULL;
  545. len = 0;
  546. qp->s_cur++;
  547. if (qp->s_cur == qp->s_size)
  548. qp->s_cur = 0;
  549. break;
  550. }
  551. qp->s_sending_hpsn = bth2;
  552. delta = (((int) bth2 - (int) wqe->psn) << 8) >> 8;
  553. if (delta && delta % QIB_PSN_CREDIT == 0)
  554. bth2 |= IB_BTH_REQ_ACK;
  555. if (qp->s_flags & RVT_S_SEND_ONE) {
  556. qp->s_flags &= ~RVT_S_SEND_ONE;
  557. qp->s_flags |= RVT_S_WAIT_ACK;
  558. bth2 |= IB_BTH_REQ_ACK;
  559. }
  560. qp->s_len -= len;
  561. qp->s_hdrwords = hwords;
  562. qp->s_cur_sge = ss;
  563. qp->s_cur_size = len;
  564. qib_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24), bth2);
  565. done:
  566. return 1;
  567. bail:
  568. qp->s_flags &= ~RVT_S_BUSY;
  569. return ret;
  570. }
  571. /**
  572. * qib_send_rc_ack - Construct an ACK packet and send it
  573. * @qp: a pointer to the QP
  574. *
  575. * This is called from qib_rc_rcv() and qib_kreceive().
  576. * Note that RDMA reads and atomics are handled in the
  577. * send side QP state and tasklet.
  578. */
  579. void qib_send_rc_ack(struct rvt_qp *qp)
  580. {
  581. struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  582. struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
  583. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  584. u64 pbc;
  585. u16 lrh0;
  586. u32 bth0;
  587. u32 hwords;
  588. u32 pbufn;
  589. u32 __iomem *piobuf;
  590. struct ib_header hdr;
  591. struct ib_other_headers *ohdr;
  592. u32 control;
  593. unsigned long flags;
  594. spin_lock_irqsave(&qp->s_lock, flags);
  595. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
  596. goto unlock;
  597. /* Don't send ACK or NAK if a RDMA read or atomic is pending. */
  598. if ((qp->s_flags & RVT_S_RESP_PENDING) || qp->s_rdma_ack_cnt)
  599. goto queue_ack;
  600. /* Construct the header with s_lock held so APM doesn't change it. */
  601. ohdr = &hdr.u.oth;
  602. lrh0 = QIB_LRH_BTH;
  603. /* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4. */
  604. hwords = 6;
  605. if (unlikely(rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
  606. IB_AH_GRH)) {
  607. hwords += qib_make_grh(ibp, &hdr.u.l.grh,
  608. rdma_ah_read_grh(&qp->remote_ah_attr),
  609. hwords, 0);
  610. ohdr = &hdr.u.l.oth;
  611. lrh0 = QIB_LRH_GRH;
  612. }
  613. /* read pkey_index w/o lock (its atomic) */
  614. bth0 = qib_get_pkey(ibp, qp->s_pkey_index) | (OP(ACKNOWLEDGE) << 24);
  615. if (qp->s_mig_state == IB_MIG_MIGRATED)
  616. bth0 |= IB_BTH_MIG_REQ;
  617. if (qp->r_nak_state)
  618. ohdr->u.aeth = cpu_to_be32((qp->r_msn & IB_MSN_MASK) |
  619. (qp->r_nak_state <<
  620. IB_AETH_CREDIT_SHIFT));
  621. else
  622. ohdr->u.aeth = rvt_compute_aeth(qp);
  623. lrh0 |= ibp->sl_to_vl[rdma_ah_get_sl(&qp->remote_ah_attr)] << 12 |
  624. rdma_ah_get_sl(&qp->remote_ah_attr) << 4;
  625. hdr.lrh[0] = cpu_to_be16(lrh0);
  626. hdr.lrh[1] = cpu_to_be16(rdma_ah_get_dlid(&qp->remote_ah_attr));
  627. hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC);
  628. hdr.lrh[3] = cpu_to_be16(ppd->lid |
  629. rdma_ah_get_path_bits(&qp->remote_ah_attr));
  630. ohdr->bth[0] = cpu_to_be32(bth0);
  631. ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
  632. ohdr->bth[2] = cpu_to_be32(qp->r_ack_psn & QIB_PSN_MASK);
  633. spin_unlock_irqrestore(&qp->s_lock, flags);
  634. /* Don't try to send ACKs if the link isn't ACTIVE */
  635. if (!(ppd->lflags & QIBL_LINKACTIVE))
  636. goto done;
  637. control = dd->f_setpbc_control(ppd, hwords + SIZE_OF_CRC,
  638. qp->s_srate, lrh0 >> 12);
  639. /* length is + 1 for the control dword */
  640. pbc = ((u64) control << 32) | (hwords + 1);
  641. piobuf = dd->f_getsendbuf(ppd, pbc, &pbufn);
  642. if (!piobuf) {
  643. /*
  644. * We are out of PIO buffers at the moment.
  645. * Pass responsibility for sending the ACK to the
  646. * send tasklet so that when a PIO buffer becomes
  647. * available, the ACK is sent ahead of other outgoing
  648. * packets.
  649. */
  650. spin_lock_irqsave(&qp->s_lock, flags);
  651. goto queue_ack;
  652. }
  653. /*
  654. * Write the pbc.
  655. * We have to flush after the PBC for correctness
  656. * on some cpus or WC buffer can be written out of order.
  657. */
  658. writeq(pbc, piobuf);
  659. if (dd->flags & QIB_PIO_FLUSH_WC) {
  660. u32 *hdrp = (u32 *) &hdr;
  661. qib_flush_wc();
  662. qib_pio_copy(piobuf + 2, hdrp, hwords - 1);
  663. qib_flush_wc();
  664. __raw_writel(hdrp[hwords - 1], piobuf + hwords + 1);
  665. } else
  666. qib_pio_copy(piobuf + 2, (u32 *) &hdr, hwords);
  667. if (dd->flags & QIB_USE_SPCL_TRIG) {
  668. u32 spcl_off = (pbufn >= dd->piobcnt2k) ? 2047 : 1023;
  669. qib_flush_wc();
  670. __raw_writel(0xaebecede, piobuf + spcl_off);
  671. }
  672. qib_flush_wc();
  673. qib_sendbuf_done(dd, pbufn);
  674. this_cpu_inc(ibp->pmastats->n_unicast_xmit);
  675. goto done;
  676. queue_ack:
  677. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  678. this_cpu_inc(*ibp->rvp.rc_qacks);
  679. qp->s_flags |= RVT_S_ACK_PENDING | RVT_S_RESP_PENDING;
  680. qp->s_nak_state = qp->r_nak_state;
  681. qp->s_ack_psn = qp->r_ack_psn;
  682. /* Schedule the send tasklet. */
  683. qib_schedule_send(qp);
  684. }
  685. unlock:
  686. spin_unlock_irqrestore(&qp->s_lock, flags);
  687. done:
  688. return;
  689. }
  690. /**
  691. * reset_psn - reset the QP state to send starting from PSN
  692. * @qp: the QP
  693. * @psn: the packet sequence number to restart at
  694. *
  695. * This is called from qib_rc_rcv() to process an incoming RC ACK
  696. * for the given QP.
  697. * Called at interrupt level with the QP s_lock held.
  698. */
  699. static void reset_psn(struct rvt_qp *qp, u32 psn)
  700. {
  701. u32 n = qp->s_acked;
  702. struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, n);
  703. u32 opcode;
  704. qp->s_cur = n;
  705. /*
  706. * If we are starting the request from the beginning,
  707. * let the normal send code handle initialization.
  708. */
  709. if (qib_cmp24(psn, wqe->psn) <= 0) {
  710. qp->s_state = OP(SEND_LAST);
  711. goto done;
  712. }
  713. /* Find the work request opcode corresponding to the given PSN. */
  714. opcode = wqe->wr.opcode;
  715. for (;;) {
  716. int diff;
  717. if (++n == qp->s_size)
  718. n = 0;
  719. if (n == qp->s_tail)
  720. break;
  721. wqe = rvt_get_swqe_ptr(qp, n);
  722. diff = qib_cmp24(psn, wqe->psn);
  723. if (diff < 0)
  724. break;
  725. qp->s_cur = n;
  726. /*
  727. * If we are starting the request from the beginning,
  728. * let the normal send code handle initialization.
  729. */
  730. if (diff == 0) {
  731. qp->s_state = OP(SEND_LAST);
  732. goto done;
  733. }
  734. opcode = wqe->wr.opcode;
  735. }
  736. /*
  737. * Set the state to restart in the middle of a request.
  738. * Don't change the s_sge, s_cur_sge, or s_cur_size.
  739. * See qib_make_rc_req().
  740. */
  741. switch (opcode) {
  742. case IB_WR_SEND:
  743. case IB_WR_SEND_WITH_IMM:
  744. qp->s_state = OP(RDMA_READ_RESPONSE_FIRST);
  745. break;
  746. case IB_WR_RDMA_WRITE:
  747. case IB_WR_RDMA_WRITE_WITH_IMM:
  748. qp->s_state = OP(RDMA_READ_RESPONSE_LAST);
  749. break;
  750. case IB_WR_RDMA_READ:
  751. qp->s_state = OP(RDMA_READ_RESPONSE_MIDDLE);
  752. break;
  753. default:
  754. /*
  755. * This case shouldn't happen since its only
  756. * one PSN per req.
  757. */
  758. qp->s_state = OP(SEND_LAST);
  759. }
  760. done:
  761. qp->s_psn = psn;
  762. /*
  763. * Set RVT_S_WAIT_PSN as qib_rc_complete() may start the timer
  764. * asynchronously before the send tasklet can get scheduled.
  765. * Doing it in qib_make_rc_req() is too late.
  766. */
  767. if ((qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) &&
  768. (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0))
  769. qp->s_flags |= RVT_S_WAIT_PSN;
  770. }
  771. /*
  772. * Back up requester to resend the last un-ACKed request.
  773. * The QP r_lock and s_lock should be held and interrupts disabled.
  774. */
  775. void qib_restart_rc(struct rvt_qp *qp, u32 psn, int wait)
  776. {
  777. struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  778. struct qib_ibport *ibp;
  779. if (qp->s_retry == 0) {
  780. if (qp->s_mig_state == IB_MIG_ARMED) {
  781. qib_migrate_qp(qp);
  782. qp->s_retry = qp->s_retry_cnt;
  783. } else if (qp->s_last == qp->s_acked) {
  784. qib_send_complete(qp, wqe, IB_WC_RETRY_EXC_ERR);
  785. rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
  786. return;
  787. } else /* XXX need to handle delayed completion */
  788. return;
  789. } else
  790. qp->s_retry--;
  791. ibp = to_iport(qp->ibqp.device, qp->port_num);
  792. if (wqe->wr.opcode == IB_WR_RDMA_READ)
  793. ibp->rvp.n_rc_resends++;
  794. else
  795. ibp->rvp.n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK;
  796. qp->s_flags &= ~(RVT_S_WAIT_FENCE | RVT_S_WAIT_RDMAR |
  797. RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_PSN |
  798. RVT_S_WAIT_ACK);
  799. if (wait)
  800. qp->s_flags |= RVT_S_SEND_ONE;
  801. reset_psn(qp, psn);
  802. }
  803. /*
  804. * Set qp->s_sending_psn to the next PSN after the given one.
  805. * This would be psn+1 except when RDMA reads are present.
  806. */
  807. static void reset_sending_psn(struct rvt_qp *qp, u32 psn)
  808. {
  809. struct rvt_swqe *wqe;
  810. u32 n = qp->s_last;
  811. /* Find the work request corresponding to the given PSN. */
  812. for (;;) {
  813. wqe = rvt_get_swqe_ptr(qp, n);
  814. if (qib_cmp24(psn, wqe->lpsn) <= 0) {
  815. if (wqe->wr.opcode == IB_WR_RDMA_READ)
  816. qp->s_sending_psn = wqe->lpsn + 1;
  817. else
  818. qp->s_sending_psn = psn + 1;
  819. break;
  820. }
  821. if (++n == qp->s_size)
  822. n = 0;
  823. if (n == qp->s_tail)
  824. break;
  825. }
  826. }
  827. /*
  828. * This should be called with the QP s_lock held and interrupts disabled.
  829. */
  830. void qib_rc_send_complete(struct rvt_qp *qp, struct ib_header *hdr)
  831. {
  832. struct ib_other_headers *ohdr;
  833. struct rvt_swqe *wqe;
  834. u32 opcode;
  835. u32 psn;
  836. if (!(ib_rvt_state_ops[qp->state] & RVT_SEND_OR_FLUSH_OR_RECV_OK))
  837. return;
  838. /* Find out where the BTH is */
  839. if ((be16_to_cpu(hdr->lrh[0]) & 3) == QIB_LRH_BTH)
  840. ohdr = &hdr->u.oth;
  841. else
  842. ohdr = &hdr->u.l.oth;
  843. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  844. if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) &&
  845. opcode <= OP(ATOMIC_ACKNOWLEDGE)) {
  846. WARN_ON(!qp->s_rdma_ack_cnt);
  847. qp->s_rdma_ack_cnt--;
  848. return;
  849. }
  850. psn = be32_to_cpu(ohdr->bth[2]);
  851. reset_sending_psn(qp, psn);
  852. /*
  853. * Start timer after a packet requesting an ACK has been sent and
  854. * there are still requests that haven't been acked.
  855. */
  856. if ((psn & IB_BTH_REQ_ACK) && qp->s_acked != qp->s_tail &&
  857. !(qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR | RVT_S_WAIT_PSN)) &&
  858. (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
  859. rvt_add_retry_timer(qp);
  860. while (qp->s_last != qp->s_acked) {
  861. u32 s_last;
  862. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  863. if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) >= 0 &&
  864. qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)
  865. break;
  866. s_last = qp->s_last;
  867. if (++s_last >= qp->s_size)
  868. s_last = 0;
  869. qp->s_last = s_last;
  870. /* see post_send() */
  871. barrier();
  872. rvt_put_swqe(wqe);
  873. rvt_qp_swqe_complete(qp,
  874. wqe,
  875. ib_qib_wc_opcode[wqe->wr.opcode],
  876. IB_WC_SUCCESS);
  877. }
  878. /*
  879. * If we were waiting for sends to complete before resending,
  880. * and they are now complete, restart sending.
  881. */
  882. if (qp->s_flags & RVT_S_WAIT_PSN &&
  883. qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
  884. qp->s_flags &= ~RVT_S_WAIT_PSN;
  885. qp->s_sending_psn = qp->s_psn;
  886. qp->s_sending_hpsn = qp->s_psn - 1;
  887. qib_schedule_send(qp);
  888. }
  889. }
  890. static inline void update_last_psn(struct rvt_qp *qp, u32 psn)
  891. {
  892. qp->s_last_psn = psn;
  893. }
  894. /*
  895. * Generate a SWQE completion.
  896. * This is similar to qib_send_complete but has to check to be sure
  897. * that the SGEs are not being referenced if the SWQE is being resent.
  898. */
  899. static struct rvt_swqe *do_rc_completion(struct rvt_qp *qp,
  900. struct rvt_swqe *wqe,
  901. struct qib_ibport *ibp)
  902. {
  903. /*
  904. * Don't decrement refcount and don't generate a
  905. * completion if the SWQE is being resent until the send
  906. * is finished.
  907. */
  908. if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) < 0 ||
  909. qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
  910. u32 s_last;
  911. rvt_put_swqe(wqe);
  912. s_last = qp->s_last;
  913. if (++s_last >= qp->s_size)
  914. s_last = 0;
  915. qp->s_last = s_last;
  916. /* see post_send() */
  917. barrier();
  918. rvt_qp_swqe_complete(qp,
  919. wqe,
  920. ib_qib_wc_opcode[wqe->wr.opcode],
  921. IB_WC_SUCCESS);
  922. } else
  923. this_cpu_inc(*ibp->rvp.rc_delayed_comp);
  924. qp->s_retry = qp->s_retry_cnt;
  925. update_last_psn(qp, wqe->lpsn);
  926. /*
  927. * If we are completing a request which is in the process of
  928. * being resent, we can stop resending it since we know the
  929. * responder has already seen it.
  930. */
  931. if (qp->s_acked == qp->s_cur) {
  932. if (++qp->s_cur >= qp->s_size)
  933. qp->s_cur = 0;
  934. qp->s_acked = qp->s_cur;
  935. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  936. if (qp->s_acked != qp->s_tail) {
  937. qp->s_state = OP(SEND_LAST);
  938. qp->s_psn = wqe->psn;
  939. }
  940. } else {
  941. if (++qp->s_acked >= qp->s_size)
  942. qp->s_acked = 0;
  943. if (qp->state == IB_QPS_SQD && qp->s_acked == qp->s_cur)
  944. qp->s_draining = 0;
  945. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  946. }
  947. return wqe;
  948. }
  949. /**
  950. * do_rc_ack - process an incoming RC ACK
  951. * @qp: the QP the ACK came in on
  952. * @psn: the packet sequence number of the ACK
  953. * @opcode: the opcode of the request that resulted in the ACK
  954. *
  955. * This is called from qib_rc_rcv_resp() to process an incoming RC ACK
  956. * for the given QP.
  957. * Called at interrupt level with the QP s_lock held.
  958. * Returns 1 if OK, 0 if current operation should be aborted (NAK).
  959. */
  960. static int do_rc_ack(struct rvt_qp *qp, u32 aeth, u32 psn, int opcode,
  961. u64 val, struct qib_ctxtdata *rcd)
  962. {
  963. struct qib_ibport *ibp;
  964. enum ib_wc_status status;
  965. struct rvt_swqe *wqe;
  966. int ret = 0;
  967. u32 ack_psn;
  968. int diff;
  969. /*
  970. * Note that NAKs implicitly ACK outstanding SEND and RDMA write
  971. * requests and implicitly NAK RDMA read and atomic requests issued
  972. * before the NAK'ed request. The MSN won't include the NAK'ed
  973. * request but will include an ACK'ed request(s).
  974. */
  975. ack_psn = psn;
  976. if (aeth >> IB_AETH_NAK_SHIFT)
  977. ack_psn--;
  978. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  979. ibp = to_iport(qp->ibqp.device, qp->port_num);
  980. /*
  981. * The MSN might be for a later WQE than the PSN indicates so
  982. * only complete WQEs that the PSN finishes.
  983. */
  984. while ((diff = qib_cmp24(ack_psn, wqe->lpsn)) >= 0) {
  985. /*
  986. * RDMA_READ_RESPONSE_ONLY is a special case since
  987. * we want to generate completion events for everything
  988. * before the RDMA read, copy the data, then generate
  989. * the completion for the read.
  990. */
  991. if (wqe->wr.opcode == IB_WR_RDMA_READ &&
  992. opcode == OP(RDMA_READ_RESPONSE_ONLY) &&
  993. diff == 0) {
  994. ret = 1;
  995. goto bail;
  996. }
  997. /*
  998. * If this request is a RDMA read or atomic, and the ACK is
  999. * for a later operation, this ACK NAKs the RDMA read or
  1000. * atomic. In other words, only a RDMA_READ_LAST or ONLY
  1001. * can ACK a RDMA read and likewise for atomic ops. Note
  1002. * that the NAK case can only happen if relaxed ordering is
  1003. * used and requests are sent after an RDMA read or atomic
  1004. * is sent but before the response is received.
  1005. */
  1006. if ((wqe->wr.opcode == IB_WR_RDMA_READ &&
  1007. (opcode != OP(RDMA_READ_RESPONSE_LAST) || diff != 0)) ||
  1008. ((wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1009. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) &&
  1010. (opcode != OP(ATOMIC_ACKNOWLEDGE) || diff != 0))) {
  1011. /* Retry this request. */
  1012. if (!(qp->r_flags & RVT_R_RDMAR_SEQ)) {
  1013. qp->r_flags |= RVT_R_RDMAR_SEQ;
  1014. qib_restart_rc(qp, qp->s_last_psn + 1, 0);
  1015. if (list_empty(&qp->rspwait)) {
  1016. qp->r_flags |= RVT_R_RSP_SEND;
  1017. rvt_get_qp(qp);
  1018. list_add_tail(&qp->rspwait,
  1019. &rcd->qp_wait_list);
  1020. }
  1021. }
  1022. /*
  1023. * No need to process the ACK/NAK since we are
  1024. * restarting an earlier request.
  1025. */
  1026. goto bail;
  1027. }
  1028. if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1029. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
  1030. u64 *vaddr = wqe->sg_list[0].vaddr;
  1031. *vaddr = val;
  1032. }
  1033. if (qp->s_num_rd_atomic &&
  1034. (wqe->wr.opcode == IB_WR_RDMA_READ ||
  1035. wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1036. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)) {
  1037. qp->s_num_rd_atomic--;
  1038. /* Restart sending task if fence is complete */
  1039. if ((qp->s_flags & RVT_S_WAIT_FENCE) &&
  1040. !qp->s_num_rd_atomic) {
  1041. qp->s_flags &= ~(RVT_S_WAIT_FENCE |
  1042. RVT_S_WAIT_ACK);
  1043. qib_schedule_send(qp);
  1044. } else if (qp->s_flags & RVT_S_WAIT_RDMAR) {
  1045. qp->s_flags &= ~(RVT_S_WAIT_RDMAR |
  1046. RVT_S_WAIT_ACK);
  1047. qib_schedule_send(qp);
  1048. }
  1049. }
  1050. wqe = do_rc_completion(qp, wqe, ibp);
  1051. if (qp->s_acked == qp->s_tail)
  1052. break;
  1053. }
  1054. switch (aeth >> IB_AETH_NAK_SHIFT) {
  1055. case 0: /* ACK */
  1056. this_cpu_inc(*ibp->rvp.rc_acks);
  1057. if (qp->s_acked != qp->s_tail) {
  1058. /*
  1059. * We are expecting more ACKs so
  1060. * reset the retransmit timer.
  1061. */
  1062. rvt_mod_retry_timer(qp);
  1063. /*
  1064. * We can stop resending the earlier packets and
  1065. * continue with the next packet the receiver wants.
  1066. */
  1067. if (qib_cmp24(qp->s_psn, psn) <= 0)
  1068. reset_psn(qp, psn + 1);
  1069. } else {
  1070. /* No more acks - kill all timers */
  1071. rvt_stop_rc_timers(qp);
  1072. if (qib_cmp24(qp->s_psn, psn) <= 0) {
  1073. qp->s_state = OP(SEND_LAST);
  1074. qp->s_psn = psn + 1;
  1075. }
  1076. }
  1077. if (qp->s_flags & RVT_S_WAIT_ACK) {
  1078. qp->s_flags &= ~RVT_S_WAIT_ACK;
  1079. qib_schedule_send(qp);
  1080. }
  1081. rvt_get_credit(qp, aeth);
  1082. qp->s_rnr_retry = qp->s_rnr_retry_cnt;
  1083. qp->s_retry = qp->s_retry_cnt;
  1084. update_last_psn(qp, psn);
  1085. return 1;
  1086. case 1: /* RNR NAK */
  1087. ibp->rvp.n_rnr_naks++;
  1088. if (qp->s_acked == qp->s_tail)
  1089. goto bail;
  1090. if (qp->s_flags & RVT_S_WAIT_RNR)
  1091. goto bail;
  1092. if (qp->s_rnr_retry == 0) {
  1093. status = IB_WC_RNR_RETRY_EXC_ERR;
  1094. goto class_b;
  1095. }
  1096. if (qp->s_rnr_retry_cnt < 7)
  1097. qp->s_rnr_retry--;
  1098. /* The last valid PSN is the previous PSN. */
  1099. update_last_psn(qp, psn - 1);
  1100. ibp->rvp.n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK;
  1101. reset_psn(qp, psn);
  1102. qp->s_flags &= ~(RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_ACK);
  1103. rvt_stop_rc_timers(qp);
  1104. rvt_add_rnr_timer(qp, aeth);
  1105. return 0;
  1106. case 3: /* NAK */
  1107. if (qp->s_acked == qp->s_tail)
  1108. goto bail;
  1109. /* The last valid PSN is the previous PSN. */
  1110. update_last_psn(qp, psn - 1);
  1111. switch ((aeth >> IB_AETH_CREDIT_SHIFT) &
  1112. IB_AETH_CREDIT_MASK) {
  1113. case 0: /* PSN sequence error */
  1114. ibp->rvp.n_seq_naks++;
  1115. /*
  1116. * Back up to the responder's expected PSN.
  1117. * Note that we might get a NAK in the middle of an
  1118. * RDMA READ response which terminates the RDMA
  1119. * READ.
  1120. */
  1121. qib_restart_rc(qp, psn, 0);
  1122. qib_schedule_send(qp);
  1123. break;
  1124. case 1: /* Invalid Request */
  1125. status = IB_WC_REM_INV_REQ_ERR;
  1126. ibp->rvp.n_other_naks++;
  1127. goto class_b;
  1128. case 2: /* Remote Access Error */
  1129. status = IB_WC_REM_ACCESS_ERR;
  1130. ibp->rvp.n_other_naks++;
  1131. goto class_b;
  1132. case 3: /* Remote Operation Error */
  1133. status = IB_WC_REM_OP_ERR;
  1134. ibp->rvp.n_other_naks++;
  1135. class_b:
  1136. if (qp->s_last == qp->s_acked) {
  1137. qib_send_complete(qp, wqe, status);
  1138. rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
  1139. }
  1140. break;
  1141. default:
  1142. /* Ignore other reserved NAK error codes */
  1143. goto reserved;
  1144. }
  1145. qp->s_retry = qp->s_retry_cnt;
  1146. qp->s_rnr_retry = qp->s_rnr_retry_cnt;
  1147. goto bail;
  1148. default: /* 2: reserved */
  1149. reserved:
  1150. /* Ignore reserved NAK codes. */
  1151. goto bail;
  1152. }
  1153. bail:
  1154. rvt_stop_rc_timers(qp);
  1155. return ret;
  1156. }
  1157. /*
  1158. * We have seen an out of sequence RDMA read middle or last packet.
  1159. * This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE.
  1160. */
  1161. static void rdma_seq_err(struct rvt_qp *qp, struct qib_ibport *ibp, u32 psn,
  1162. struct qib_ctxtdata *rcd)
  1163. {
  1164. struct rvt_swqe *wqe;
  1165. /* Remove QP from retry timer */
  1166. rvt_stop_rc_timers(qp);
  1167. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1168. while (qib_cmp24(psn, wqe->lpsn) > 0) {
  1169. if (wqe->wr.opcode == IB_WR_RDMA_READ ||
  1170. wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1171. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)
  1172. break;
  1173. wqe = do_rc_completion(qp, wqe, ibp);
  1174. }
  1175. ibp->rvp.n_rdma_seq++;
  1176. qp->r_flags |= RVT_R_RDMAR_SEQ;
  1177. qib_restart_rc(qp, qp->s_last_psn + 1, 0);
  1178. if (list_empty(&qp->rspwait)) {
  1179. qp->r_flags |= RVT_R_RSP_SEND;
  1180. rvt_get_qp(qp);
  1181. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1182. }
  1183. }
  1184. /**
  1185. * qib_rc_rcv_resp - process an incoming RC response packet
  1186. * @ibp: the port this packet came in on
  1187. * @ohdr: the other headers for this packet
  1188. * @data: the packet data
  1189. * @tlen: the packet length
  1190. * @qp: the QP for this packet
  1191. * @opcode: the opcode for this packet
  1192. * @psn: the packet sequence number for this packet
  1193. * @hdrsize: the header length
  1194. * @pmtu: the path MTU
  1195. *
  1196. * This is called from qib_rc_rcv() to process an incoming RC response
  1197. * packet for the given QP.
  1198. * Called at interrupt level.
  1199. */
  1200. static void qib_rc_rcv_resp(struct qib_ibport *ibp,
  1201. struct ib_other_headers *ohdr,
  1202. void *data, u32 tlen,
  1203. struct rvt_qp *qp,
  1204. u32 opcode,
  1205. u32 psn, u32 hdrsize, u32 pmtu,
  1206. struct qib_ctxtdata *rcd)
  1207. {
  1208. struct rvt_swqe *wqe;
  1209. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1210. enum ib_wc_status status;
  1211. unsigned long flags;
  1212. int diff;
  1213. u32 pad;
  1214. u32 aeth;
  1215. u64 val;
  1216. if (opcode != OP(RDMA_READ_RESPONSE_MIDDLE)) {
  1217. /*
  1218. * If ACK'd PSN on SDMA busy list try to make progress to
  1219. * reclaim SDMA credits.
  1220. */
  1221. if ((qib_cmp24(psn, qp->s_sending_psn) >= 0) &&
  1222. (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)) {
  1223. /*
  1224. * If send tasklet not running attempt to progress
  1225. * SDMA queue.
  1226. */
  1227. if (!(qp->s_flags & RVT_S_BUSY)) {
  1228. /* Acquire SDMA Lock */
  1229. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1230. /* Invoke sdma make progress */
  1231. qib_sdma_make_progress(ppd);
  1232. /* Release SDMA Lock */
  1233. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1234. }
  1235. }
  1236. }
  1237. spin_lock_irqsave(&qp->s_lock, flags);
  1238. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
  1239. goto ack_done;
  1240. /* Ignore invalid responses. */
  1241. smp_read_barrier_depends(); /* see post_one_send */
  1242. if (qib_cmp24(psn, READ_ONCE(qp->s_next_psn)) >= 0)
  1243. goto ack_done;
  1244. /* Ignore duplicate responses. */
  1245. diff = qib_cmp24(psn, qp->s_last_psn);
  1246. if (unlikely(diff <= 0)) {
  1247. /* Update credits for "ghost" ACKs */
  1248. if (diff == 0 && opcode == OP(ACKNOWLEDGE)) {
  1249. aeth = be32_to_cpu(ohdr->u.aeth);
  1250. if ((aeth >> IB_AETH_NAK_SHIFT) == 0)
  1251. rvt_get_credit(qp, aeth);
  1252. }
  1253. goto ack_done;
  1254. }
  1255. /*
  1256. * Skip everything other than the PSN we expect, if we are waiting
  1257. * for a reply to a restarted RDMA read or atomic op.
  1258. */
  1259. if (qp->r_flags & RVT_R_RDMAR_SEQ) {
  1260. if (qib_cmp24(psn, qp->s_last_psn + 1) != 0)
  1261. goto ack_done;
  1262. qp->r_flags &= ~RVT_R_RDMAR_SEQ;
  1263. }
  1264. if (unlikely(qp->s_acked == qp->s_tail))
  1265. goto ack_done;
  1266. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1267. status = IB_WC_SUCCESS;
  1268. switch (opcode) {
  1269. case OP(ACKNOWLEDGE):
  1270. case OP(ATOMIC_ACKNOWLEDGE):
  1271. case OP(RDMA_READ_RESPONSE_FIRST):
  1272. aeth = be32_to_cpu(ohdr->u.aeth);
  1273. if (opcode == OP(ATOMIC_ACKNOWLEDGE))
  1274. val = ib_u64_get(&ohdr->u.at.atomic_ack_eth);
  1275. else
  1276. val = 0;
  1277. if (!do_rc_ack(qp, aeth, psn, opcode, val, rcd) ||
  1278. opcode != OP(RDMA_READ_RESPONSE_FIRST))
  1279. goto ack_done;
  1280. hdrsize += 4;
  1281. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1282. if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
  1283. goto ack_op_err;
  1284. /*
  1285. * If this is a response to a resent RDMA read, we
  1286. * have to be careful to copy the data to the right
  1287. * location.
  1288. */
  1289. qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge,
  1290. wqe, psn, pmtu);
  1291. goto read_middle;
  1292. case OP(RDMA_READ_RESPONSE_MIDDLE):
  1293. /* no AETH, no ACK */
  1294. if (unlikely(qib_cmp24(psn, qp->s_last_psn + 1)))
  1295. goto ack_seq_err;
  1296. if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
  1297. goto ack_op_err;
  1298. read_middle:
  1299. if (unlikely(tlen != (hdrsize + pmtu + 4)))
  1300. goto ack_len_err;
  1301. if (unlikely(pmtu >= qp->s_rdma_read_len))
  1302. goto ack_len_err;
  1303. /*
  1304. * We got a response so update the timeout.
  1305. * 4.096 usec. * (1 << qp->timeout)
  1306. */
  1307. rvt_mod_retry_timer(qp);
  1308. if (qp->s_flags & RVT_S_WAIT_ACK) {
  1309. qp->s_flags &= ~RVT_S_WAIT_ACK;
  1310. qib_schedule_send(qp);
  1311. }
  1312. if (opcode == OP(RDMA_READ_RESPONSE_MIDDLE))
  1313. qp->s_retry = qp->s_retry_cnt;
  1314. /*
  1315. * Update the RDMA receive state but do the copy w/o
  1316. * holding the locks and blocking interrupts.
  1317. */
  1318. qp->s_rdma_read_len -= pmtu;
  1319. update_last_psn(qp, psn);
  1320. spin_unlock_irqrestore(&qp->s_lock, flags);
  1321. qib_copy_sge(&qp->s_rdma_read_sge, data, pmtu, 0);
  1322. goto bail;
  1323. case OP(RDMA_READ_RESPONSE_ONLY):
  1324. aeth = be32_to_cpu(ohdr->u.aeth);
  1325. if (!do_rc_ack(qp, aeth, psn, opcode, 0, rcd))
  1326. goto ack_done;
  1327. /* Get the number of bytes the message was padded by. */
  1328. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  1329. /*
  1330. * Check that the data size is >= 0 && <= pmtu.
  1331. * Remember to account for the AETH header (4) and
  1332. * ICRC (4).
  1333. */
  1334. if (unlikely(tlen < (hdrsize + pad + 8)))
  1335. goto ack_len_err;
  1336. /*
  1337. * If this is a response to a resent RDMA read, we
  1338. * have to be careful to copy the data to the right
  1339. * location.
  1340. */
  1341. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1342. qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge,
  1343. wqe, psn, pmtu);
  1344. goto read_last;
  1345. case OP(RDMA_READ_RESPONSE_LAST):
  1346. /* ACKs READ req. */
  1347. if (unlikely(qib_cmp24(psn, qp->s_last_psn + 1)))
  1348. goto ack_seq_err;
  1349. if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
  1350. goto ack_op_err;
  1351. /* Get the number of bytes the message was padded by. */
  1352. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  1353. /*
  1354. * Check that the data size is >= 1 && <= pmtu.
  1355. * Remember to account for the AETH header (4) and
  1356. * ICRC (4).
  1357. */
  1358. if (unlikely(tlen <= (hdrsize + pad + 8)))
  1359. goto ack_len_err;
  1360. read_last:
  1361. tlen -= hdrsize + pad + 8;
  1362. if (unlikely(tlen != qp->s_rdma_read_len))
  1363. goto ack_len_err;
  1364. aeth = be32_to_cpu(ohdr->u.aeth);
  1365. qib_copy_sge(&qp->s_rdma_read_sge, data, tlen, 0);
  1366. WARN_ON(qp->s_rdma_read_sge.num_sge);
  1367. (void) do_rc_ack(qp, aeth, psn,
  1368. OP(RDMA_READ_RESPONSE_LAST), 0, rcd);
  1369. goto ack_done;
  1370. }
  1371. ack_op_err:
  1372. status = IB_WC_LOC_QP_OP_ERR;
  1373. goto ack_err;
  1374. ack_seq_err:
  1375. rdma_seq_err(qp, ibp, psn, rcd);
  1376. goto ack_done;
  1377. ack_len_err:
  1378. status = IB_WC_LOC_LEN_ERR;
  1379. ack_err:
  1380. if (qp->s_last == qp->s_acked) {
  1381. qib_send_complete(qp, wqe, status);
  1382. rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
  1383. }
  1384. ack_done:
  1385. spin_unlock_irqrestore(&qp->s_lock, flags);
  1386. bail:
  1387. return;
  1388. }
  1389. /**
  1390. * qib_rc_rcv_error - process an incoming duplicate or error RC packet
  1391. * @ohdr: the other headers for this packet
  1392. * @data: the packet data
  1393. * @qp: the QP for this packet
  1394. * @opcode: the opcode for this packet
  1395. * @psn: the packet sequence number for this packet
  1396. * @diff: the difference between the PSN and the expected PSN
  1397. *
  1398. * This is called from qib_rc_rcv() to process an unexpected
  1399. * incoming RC packet for the given QP.
  1400. * Called at interrupt level.
  1401. * Return 1 if no more processing is needed; otherwise return 0 to
  1402. * schedule a response to be sent.
  1403. */
  1404. static int qib_rc_rcv_error(struct ib_other_headers *ohdr,
  1405. void *data,
  1406. struct rvt_qp *qp,
  1407. u32 opcode,
  1408. u32 psn,
  1409. int diff,
  1410. struct qib_ctxtdata *rcd)
  1411. {
  1412. struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
  1413. struct rvt_ack_entry *e;
  1414. unsigned long flags;
  1415. u8 i, prev;
  1416. int old_req;
  1417. if (diff > 0) {
  1418. /*
  1419. * Packet sequence error.
  1420. * A NAK will ACK earlier sends and RDMA writes.
  1421. * Don't queue the NAK if we already sent one.
  1422. */
  1423. if (!qp->r_nak_state) {
  1424. ibp->rvp.n_rc_seqnak++;
  1425. qp->r_nak_state = IB_NAK_PSN_ERROR;
  1426. /* Use the expected PSN. */
  1427. qp->r_ack_psn = qp->r_psn;
  1428. /*
  1429. * Wait to send the sequence NAK until all packets
  1430. * in the receive queue have been processed.
  1431. * Otherwise, we end up propagating congestion.
  1432. */
  1433. if (list_empty(&qp->rspwait)) {
  1434. qp->r_flags |= RVT_R_RSP_NAK;
  1435. rvt_get_qp(qp);
  1436. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1437. }
  1438. }
  1439. goto done;
  1440. }
  1441. /*
  1442. * Handle a duplicate request. Don't re-execute SEND, RDMA
  1443. * write or atomic op. Don't NAK errors, just silently drop
  1444. * the duplicate request. Note that r_sge, r_len, and
  1445. * r_rcv_len may be in use so don't modify them.
  1446. *
  1447. * We are supposed to ACK the earliest duplicate PSN but we
  1448. * can coalesce an outstanding duplicate ACK. We have to
  1449. * send the earliest so that RDMA reads can be restarted at
  1450. * the requester's expected PSN.
  1451. *
  1452. * First, find where this duplicate PSN falls within the
  1453. * ACKs previously sent.
  1454. * old_req is true if there is an older response that is scheduled
  1455. * to be sent before sending this one.
  1456. */
  1457. e = NULL;
  1458. old_req = 1;
  1459. ibp->rvp.n_rc_dupreq++;
  1460. spin_lock_irqsave(&qp->s_lock, flags);
  1461. for (i = qp->r_head_ack_queue; ; i = prev) {
  1462. if (i == qp->s_tail_ack_queue)
  1463. old_req = 0;
  1464. if (i)
  1465. prev = i - 1;
  1466. else
  1467. prev = QIB_MAX_RDMA_ATOMIC;
  1468. if (prev == qp->r_head_ack_queue) {
  1469. e = NULL;
  1470. break;
  1471. }
  1472. e = &qp->s_ack_queue[prev];
  1473. if (!e->opcode) {
  1474. e = NULL;
  1475. break;
  1476. }
  1477. if (qib_cmp24(psn, e->psn) >= 0) {
  1478. if (prev == qp->s_tail_ack_queue &&
  1479. qib_cmp24(psn, e->lpsn) <= 0)
  1480. old_req = 0;
  1481. break;
  1482. }
  1483. }
  1484. switch (opcode) {
  1485. case OP(RDMA_READ_REQUEST): {
  1486. struct ib_reth *reth;
  1487. u32 offset;
  1488. u32 len;
  1489. /*
  1490. * If we didn't find the RDMA read request in the ack queue,
  1491. * we can ignore this request.
  1492. */
  1493. if (!e || e->opcode != OP(RDMA_READ_REQUEST))
  1494. goto unlock_done;
  1495. /* RETH comes after BTH */
  1496. reth = &ohdr->u.rc.reth;
  1497. /*
  1498. * Address range must be a subset of the original
  1499. * request and start on pmtu boundaries.
  1500. * We reuse the old ack_queue slot since the requester
  1501. * should not back up and request an earlier PSN for the
  1502. * same request.
  1503. */
  1504. offset = ((psn - e->psn) & QIB_PSN_MASK) *
  1505. qp->pmtu;
  1506. len = be32_to_cpu(reth->length);
  1507. if (unlikely(offset + len != e->rdma_sge.sge_length))
  1508. goto unlock_done;
  1509. if (e->rdma_sge.mr) {
  1510. rvt_put_mr(e->rdma_sge.mr);
  1511. e->rdma_sge.mr = NULL;
  1512. }
  1513. if (len != 0) {
  1514. u32 rkey = be32_to_cpu(reth->rkey);
  1515. u64 vaddr = be64_to_cpu(reth->vaddr);
  1516. int ok;
  1517. ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr, rkey,
  1518. IB_ACCESS_REMOTE_READ);
  1519. if (unlikely(!ok))
  1520. goto unlock_done;
  1521. } else {
  1522. e->rdma_sge.vaddr = NULL;
  1523. e->rdma_sge.length = 0;
  1524. e->rdma_sge.sge_length = 0;
  1525. }
  1526. e->psn = psn;
  1527. if (old_req)
  1528. goto unlock_done;
  1529. qp->s_tail_ack_queue = prev;
  1530. break;
  1531. }
  1532. case OP(COMPARE_SWAP):
  1533. case OP(FETCH_ADD): {
  1534. /*
  1535. * If we didn't find the atomic request in the ack queue
  1536. * or the send tasklet is already backed up to send an
  1537. * earlier entry, we can ignore this request.
  1538. */
  1539. if (!e || e->opcode != (u8) opcode || old_req)
  1540. goto unlock_done;
  1541. qp->s_tail_ack_queue = prev;
  1542. break;
  1543. }
  1544. default:
  1545. /*
  1546. * Ignore this operation if it doesn't request an ACK
  1547. * or an earlier RDMA read or atomic is going to be resent.
  1548. */
  1549. if (!(psn & IB_BTH_REQ_ACK) || old_req)
  1550. goto unlock_done;
  1551. /*
  1552. * Resend the most recent ACK if this request is
  1553. * after all the previous RDMA reads and atomics.
  1554. */
  1555. if (i == qp->r_head_ack_queue) {
  1556. spin_unlock_irqrestore(&qp->s_lock, flags);
  1557. qp->r_nak_state = 0;
  1558. qp->r_ack_psn = qp->r_psn - 1;
  1559. goto send_ack;
  1560. }
  1561. /*
  1562. * Try to send a simple ACK to work around a Mellanox bug
  1563. * which doesn't accept a RDMA read response or atomic
  1564. * response as an ACK for earlier SENDs or RDMA writes.
  1565. */
  1566. if (!(qp->s_flags & RVT_S_RESP_PENDING)) {
  1567. spin_unlock_irqrestore(&qp->s_lock, flags);
  1568. qp->r_nak_state = 0;
  1569. qp->r_ack_psn = qp->s_ack_queue[i].psn - 1;
  1570. goto send_ack;
  1571. }
  1572. /*
  1573. * Resend the RDMA read or atomic op which
  1574. * ACKs this duplicate request.
  1575. */
  1576. qp->s_tail_ack_queue = i;
  1577. break;
  1578. }
  1579. qp->s_ack_state = OP(ACKNOWLEDGE);
  1580. qp->s_flags |= RVT_S_RESP_PENDING;
  1581. qp->r_nak_state = 0;
  1582. qib_schedule_send(qp);
  1583. unlock_done:
  1584. spin_unlock_irqrestore(&qp->s_lock, flags);
  1585. done:
  1586. return 1;
  1587. send_ack:
  1588. return 0;
  1589. }
  1590. static inline void qib_update_ack_queue(struct rvt_qp *qp, unsigned n)
  1591. {
  1592. unsigned next;
  1593. next = n + 1;
  1594. if (next > QIB_MAX_RDMA_ATOMIC)
  1595. next = 0;
  1596. qp->s_tail_ack_queue = next;
  1597. qp->s_ack_state = OP(ACKNOWLEDGE);
  1598. }
  1599. /**
  1600. * qib_rc_rcv - process an incoming RC packet
  1601. * @rcd: the context pointer
  1602. * @hdr: the header of this packet
  1603. * @has_grh: true if the header has a GRH
  1604. * @data: the packet data
  1605. * @tlen: the packet length
  1606. * @qp: the QP for this packet
  1607. *
  1608. * This is called from qib_qp_rcv() to process an incoming RC packet
  1609. * for the given QP.
  1610. * Called at interrupt level.
  1611. */
  1612. void qib_rc_rcv(struct qib_ctxtdata *rcd, struct ib_header *hdr,
  1613. int has_grh, void *data, u32 tlen, struct rvt_qp *qp)
  1614. {
  1615. struct qib_ibport *ibp = &rcd->ppd->ibport_data;
  1616. struct ib_other_headers *ohdr;
  1617. u32 opcode;
  1618. u32 hdrsize;
  1619. u32 psn;
  1620. u32 pad;
  1621. struct ib_wc wc;
  1622. u32 pmtu = qp->pmtu;
  1623. int diff;
  1624. struct ib_reth *reth;
  1625. unsigned long flags;
  1626. int ret;
  1627. /* Check for GRH */
  1628. if (!has_grh) {
  1629. ohdr = &hdr->u.oth;
  1630. hdrsize = 8 + 12; /* LRH + BTH */
  1631. } else {
  1632. ohdr = &hdr->u.l.oth;
  1633. hdrsize = 8 + 40 + 12; /* LRH + GRH + BTH */
  1634. }
  1635. opcode = be32_to_cpu(ohdr->bth[0]);
  1636. if (qib_ruc_check_hdr(ibp, hdr, has_grh, qp, opcode))
  1637. return;
  1638. psn = be32_to_cpu(ohdr->bth[2]);
  1639. opcode >>= 24;
  1640. /*
  1641. * Process responses (ACKs) before anything else. Note that the
  1642. * packet sequence number will be for something in the send work
  1643. * queue rather than the expected receive packet sequence number.
  1644. * In other words, this QP is the requester.
  1645. */
  1646. if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) &&
  1647. opcode <= OP(ATOMIC_ACKNOWLEDGE)) {
  1648. qib_rc_rcv_resp(ibp, ohdr, data, tlen, qp, opcode, psn,
  1649. hdrsize, pmtu, rcd);
  1650. return;
  1651. }
  1652. /* Compute 24 bits worth of difference. */
  1653. diff = qib_cmp24(psn, qp->r_psn);
  1654. if (unlikely(diff)) {
  1655. if (qib_rc_rcv_error(ohdr, data, qp, opcode, psn, diff, rcd))
  1656. return;
  1657. goto send_ack;
  1658. }
  1659. /* Check for opcode sequence errors. */
  1660. switch (qp->r_state) {
  1661. case OP(SEND_FIRST):
  1662. case OP(SEND_MIDDLE):
  1663. if (opcode == OP(SEND_MIDDLE) ||
  1664. opcode == OP(SEND_LAST) ||
  1665. opcode == OP(SEND_LAST_WITH_IMMEDIATE))
  1666. break;
  1667. goto nack_inv;
  1668. case OP(RDMA_WRITE_FIRST):
  1669. case OP(RDMA_WRITE_MIDDLE):
  1670. if (opcode == OP(RDMA_WRITE_MIDDLE) ||
  1671. opcode == OP(RDMA_WRITE_LAST) ||
  1672. opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
  1673. break;
  1674. goto nack_inv;
  1675. default:
  1676. if (opcode == OP(SEND_MIDDLE) ||
  1677. opcode == OP(SEND_LAST) ||
  1678. opcode == OP(SEND_LAST_WITH_IMMEDIATE) ||
  1679. opcode == OP(RDMA_WRITE_MIDDLE) ||
  1680. opcode == OP(RDMA_WRITE_LAST) ||
  1681. opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
  1682. goto nack_inv;
  1683. /*
  1684. * Note that it is up to the requester to not send a new
  1685. * RDMA read or atomic operation before receiving an ACK
  1686. * for the previous operation.
  1687. */
  1688. break;
  1689. }
  1690. if (qp->state == IB_QPS_RTR && !(qp->r_flags & RVT_R_COMM_EST))
  1691. rvt_comm_est(qp);
  1692. /* OK, process the packet. */
  1693. switch (opcode) {
  1694. case OP(SEND_FIRST):
  1695. ret = qib_get_rwqe(qp, 0);
  1696. if (ret < 0)
  1697. goto nack_op_err;
  1698. if (!ret)
  1699. goto rnr_nak;
  1700. qp->r_rcv_len = 0;
  1701. /* FALLTHROUGH */
  1702. case OP(SEND_MIDDLE):
  1703. case OP(RDMA_WRITE_MIDDLE):
  1704. send_middle:
  1705. /* Check for invalid length PMTU or posted rwqe len. */
  1706. if (unlikely(tlen != (hdrsize + pmtu + 4)))
  1707. goto nack_inv;
  1708. qp->r_rcv_len += pmtu;
  1709. if (unlikely(qp->r_rcv_len > qp->r_len))
  1710. goto nack_inv;
  1711. qib_copy_sge(&qp->r_sge, data, pmtu, 1);
  1712. break;
  1713. case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
  1714. /* consume RWQE */
  1715. ret = qib_get_rwqe(qp, 1);
  1716. if (ret < 0)
  1717. goto nack_op_err;
  1718. if (!ret)
  1719. goto rnr_nak;
  1720. goto send_last_imm;
  1721. case OP(SEND_ONLY):
  1722. case OP(SEND_ONLY_WITH_IMMEDIATE):
  1723. ret = qib_get_rwqe(qp, 0);
  1724. if (ret < 0)
  1725. goto nack_op_err;
  1726. if (!ret)
  1727. goto rnr_nak;
  1728. qp->r_rcv_len = 0;
  1729. if (opcode == OP(SEND_ONLY))
  1730. goto no_immediate_data;
  1731. /* FALLTHROUGH for SEND_ONLY_WITH_IMMEDIATE */
  1732. case OP(SEND_LAST_WITH_IMMEDIATE):
  1733. send_last_imm:
  1734. wc.ex.imm_data = ohdr->u.imm_data;
  1735. hdrsize += 4;
  1736. wc.wc_flags = IB_WC_WITH_IMM;
  1737. goto send_last;
  1738. case OP(SEND_LAST):
  1739. case OP(RDMA_WRITE_LAST):
  1740. no_immediate_data:
  1741. wc.wc_flags = 0;
  1742. wc.ex.imm_data = 0;
  1743. send_last:
  1744. /* Get the number of bytes the message was padded by. */
  1745. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  1746. /* Check for invalid length. */
  1747. /* XXX LAST len should be >= 1 */
  1748. if (unlikely(tlen < (hdrsize + pad + 4)))
  1749. goto nack_inv;
  1750. /* Don't count the CRC. */
  1751. tlen -= (hdrsize + pad + 4);
  1752. wc.byte_len = tlen + qp->r_rcv_len;
  1753. if (unlikely(wc.byte_len > qp->r_len))
  1754. goto nack_inv;
  1755. qib_copy_sge(&qp->r_sge, data, tlen, 1);
  1756. rvt_put_ss(&qp->r_sge);
  1757. qp->r_msn++;
  1758. if (!test_and_clear_bit(RVT_R_WRID_VALID, &qp->r_aflags))
  1759. break;
  1760. wc.wr_id = qp->r_wr_id;
  1761. wc.status = IB_WC_SUCCESS;
  1762. if (opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE) ||
  1763. opcode == OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE))
  1764. wc.opcode = IB_WC_RECV_RDMA_WITH_IMM;
  1765. else
  1766. wc.opcode = IB_WC_RECV;
  1767. wc.qp = &qp->ibqp;
  1768. wc.src_qp = qp->remote_qpn;
  1769. wc.slid = rdma_ah_get_dlid(&qp->remote_ah_attr);
  1770. wc.sl = rdma_ah_get_sl(&qp->remote_ah_attr);
  1771. /* zero fields that are N/A */
  1772. wc.vendor_err = 0;
  1773. wc.pkey_index = 0;
  1774. wc.dlid_path_bits = 0;
  1775. wc.port_num = 0;
  1776. /* Signal completion event if the solicited bit is set. */
  1777. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.recv_cq), &wc,
  1778. (ohdr->bth[0] &
  1779. cpu_to_be32(IB_BTH_SOLICITED)) != 0);
  1780. break;
  1781. case OP(RDMA_WRITE_FIRST):
  1782. case OP(RDMA_WRITE_ONLY):
  1783. case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
  1784. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
  1785. goto nack_inv;
  1786. /* consume RWQE */
  1787. reth = &ohdr->u.rc.reth;
  1788. hdrsize += sizeof(*reth);
  1789. qp->r_len = be32_to_cpu(reth->length);
  1790. qp->r_rcv_len = 0;
  1791. qp->r_sge.sg_list = NULL;
  1792. if (qp->r_len != 0) {
  1793. u32 rkey = be32_to_cpu(reth->rkey);
  1794. u64 vaddr = be64_to_cpu(reth->vaddr);
  1795. int ok;
  1796. /* Check rkey & NAK */
  1797. ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, vaddr,
  1798. rkey, IB_ACCESS_REMOTE_WRITE);
  1799. if (unlikely(!ok))
  1800. goto nack_acc;
  1801. qp->r_sge.num_sge = 1;
  1802. } else {
  1803. qp->r_sge.num_sge = 0;
  1804. qp->r_sge.sge.mr = NULL;
  1805. qp->r_sge.sge.vaddr = NULL;
  1806. qp->r_sge.sge.length = 0;
  1807. qp->r_sge.sge.sge_length = 0;
  1808. }
  1809. if (opcode == OP(RDMA_WRITE_FIRST))
  1810. goto send_middle;
  1811. else if (opcode == OP(RDMA_WRITE_ONLY))
  1812. goto no_immediate_data;
  1813. ret = qib_get_rwqe(qp, 1);
  1814. if (ret < 0)
  1815. goto nack_op_err;
  1816. if (!ret) {
  1817. rvt_put_ss(&qp->r_sge);
  1818. goto rnr_nak;
  1819. }
  1820. wc.ex.imm_data = ohdr->u.rc.imm_data;
  1821. hdrsize += 4;
  1822. wc.wc_flags = IB_WC_WITH_IMM;
  1823. goto send_last;
  1824. case OP(RDMA_READ_REQUEST): {
  1825. struct rvt_ack_entry *e;
  1826. u32 len;
  1827. u8 next;
  1828. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ)))
  1829. goto nack_inv;
  1830. next = qp->r_head_ack_queue + 1;
  1831. /* s_ack_queue is size QIB_MAX_RDMA_ATOMIC+1 so use > not >= */
  1832. if (next > QIB_MAX_RDMA_ATOMIC)
  1833. next = 0;
  1834. spin_lock_irqsave(&qp->s_lock, flags);
  1835. if (unlikely(next == qp->s_tail_ack_queue)) {
  1836. if (!qp->s_ack_queue[next].sent)
  1837. goto nack_inv_unlck;
  1838. qib_update_ack_queue(qp, next);
  1839. }
  1840. e = &qp->s_ack_queue[qp->r_head_ack_queue];
  1841. if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
  1842. rvt_put_mr(e->rdma_sge.mr);
  1843. e->rdma_sge.mr = NULL;
  1844. }
  1845. reth = &ohdr->u.rc.reth;
  1846. len = be32_to_cpu(reth->length);
  1847. if (len) {
  1848. u32 rkey = be32_to_cpu(reth->rkey);
  1849. u64 vaddr = be64_to_cpu(reth->vaddr);
  1850. int ok;
  1851. /* Check rkey & NAK */
  1852. ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr,
  1853. rkey, IB_ACCESS_REMOTE_READ);
  1854. if (unlikely(!ok))
  1855. goto nack_acc_unlck;
  1856. /*
  1857. * Update the next expected PSN. We add 1 later
  1858. * below, so only add the remainder here.
  1859. */
  1860. qp->r_psn += rvt_div_mtu(qp, len - 1);
  1861. } else {
  1862. e->rdma_sge.mr = NULL;
  1863. e->rdma_sge.vaddr = NULL;
  1864. e->rdma_sge.length = 0;
  1865. e->rdma_sge.sge_length = 0;
  1866. }
  1867. e->opcode = opcode;
  1868. e->sent = 0;
  1869. e->psn = psn;
  1870. e->lpsn = qp->r_psn;
  1871. /*
  1872. * We need to increment the MSN here instead of when we
  1873. * finish sending the result since a duplicate request would
  1874. * increment it more than once.
  1875. */
  1876. qp->r_msn++;
  1877. qp->r_psn++;
  1878. qp->r_state = opcode;
  1879. qp->r_nak_state = 0;
  1880. qp->r_head_ack_queue = next;
  1881. /* Schedule the send tasklet. */
  1882. qp->s_flags |= RVT_S_RESP_PENDING;
  1883. qib_schedule_send(qp);
  1884. goto sunlock;
  1885. }
  1886. case OP(COMPARE_SWAP):
  1887. case OP(FETCH_ADD): {
  1888. struct ib_atomic_eth *ateth;
  1889. struct rvt_ack_entry *e;
  1890. u64 vaddr;
  1891. atomic64_t *maddr;
  1892. u64 sdata;
  1893. u32 rkey;
  1894. u8 next;
  1895. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))
  1896. goto nack_inv;
  1897. next = qp->r_head_ack_queue + 1;
  1898. if (next > QIB_MAX_RDMA_ATOMIC)
  1899. next = 0;
  1900. spin_lock_irqsave(&qp->s_lock, flags);
  1901. if (unlikely(next == qp->s_tail_ack_queue)) {
  1902. if (!qp->s_ack_queue[next].sent)
  1903. goto nack_inv_unlck;
  1904. qib_update_ack_queue(qp, next);
  1905. }
  1906. e = &qp->s_ack_queue[qp->r_head_ack_queue];
  1907. if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
  1908. rvt_put_mr(e->rdma_sge.mr);
  1909. e->rdma_sge.mr = NULL;
  1910. }
  1911. ateth = &ohdr->u.atomic_eth;
  1912. vaddr = get_ib_ateth_vaddr(ateth);
  1913. if (unlikely(vaddr & (sizeof(u64) - 1)))
  1914. goto nack_inv_unlck;
  1915. rkey = be32_to_cpu(ateth->rkey);
  1916. /* Check rkey & NAK */
  1917. if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
  1918. vaddr, rkey,
  1919. IB_ACCESS_REMOTE_ATOMIC)))
  1920. goto nack_acc_unlck;
  1921. /* Perform atomic OP and save result. */
  1922. maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
  1923. sdata = get_ib_ateth_swap(ateth);
  1924. e->atomic_data = (opcode == OP(FETCH_ADD)) ?
  1925. (u64) atomic64_add_return(sdata, maddr) - sdata :
  1926. (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
  1927. get_ib_ateth_compare(ateth),
  1928. sdata);
  1929. rvt_put_mr(qp->r_sge.sge.mr);
  1930. qp->r_sge.num_sge = 0;
  1931. e->opcode = opcode;
  1932. e->sent = 0;
  1933. e->psn = psn;
  1934. e->lpsn = psn;
  1935. qp->r_msn++;
  1936. qp->r_psn++;
  1937. qp->r_state = opcode;
  1938. qp->r_nak_state = 0;
  1939. qp->r_head_ack_queue = next;
  1940. /* Schedule the send tasklet. */
  1941. qp->s_flags |= RVT_S_RESP_PENDING;
  1942. qib_schedule_send(qp);
  1943. goto sunlock;
  1944. }
  1945. default:
  1946. /* NAK unknown opcodes. */
  1947. goto nack_inv;
  1948. }
  1949. qp->r_psn++;
  1950. qp->r_state = opcode;
  1951. qp->r_ack_psn = psn;
  1952. qp->r_nak_state = 0;
  1953. /* Send an ACK if requested or required. */
  1954. if (psn & (1 << 31))
  1955. goto send_ack;
  1956. return;
  1957. rnr_nak:
  1958. qp->r_nak_state = IB_RNR_NAK | qp->r_min_rnr_timer;
  1959. qp->r_ack_psn = qp->r_psn;
  1960. /* Queue RNR NAK for later */
  1961. if (list_empty(&qp->rspwait)) {
  1962. qp->r_flags |= RVT_R_RSP_NAK;
  1963. rvt_get_qp(qp);
  1964. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1965. }
  1966. return;
  1967. nack_op_err:
  1968. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  1969. qp->r_nak_state = IB_NAK_REMOTE_OPERATIONAL_ERROR;
  1970. qp->r_ack_psn = qp->r_psn;
  1971. /* Queue NAK for later */
  1972. if (list_empty(&qp->rspwait)) {
  1973. qp->r_flags |= RVT_R_RSP_NAK;
  1974. rvt_get_qp(qp);
  1975. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1976. }
  1977. return;
  1978. nack_inv_unlck:
  1979. spin_unlock_irqrestore(&qp->s_lock, flags);
  1980. nack_inv:
  1981. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  1982. qp->r_nak_state = IB_NAK_INVALID_REQUEST;
  1983. qp->r_ack_psn = qp->r_psn;
  1984. /* Queue NAK for later */
  1985. if (list_empty(&qp->rspwait)) {
  1986. qp->r_flags |= RVT_R_RSP_NAK;
  1987. rvt_get_qp(qp);
  1988. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1989. }
  1990. return;
  1991. nack_acc_unlck:
  1992. spin_unlock_irqrestore(&qp->s_lock, flags);
  1993. nack_acc:
  1994. rvt_rc_error(qp, IB_WC_LOC_PROT_ERR);
  1995. qp->r_nak_state = IB_NAK_REMOTE_ACCESS_ERROR;
  1996. qp->r_ack_psn = qp->r_psn;
  1997. send_ack:
  1998. qib_send_rc_ack(qp);
  1999. return;
  2000. sunlock:
  2001. spin_unlock_irqrestore(&qp->s_lock, flags);
  2002. }