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