qib_rc.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  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. if (qp->s_last == READ_ONCE(qp->s_head))
  232. goto bail;
  233. /* If DMAs are in progress, we can't flush immediately. */
  234. if (atomic_read(&priv->s_dma_busy)) {
  235. qp->s_flags |= RVT_S_WAIT_DMA;
  236. goto bail;
  237. }
  238. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  239. rvt_send_complete(qp, wqe, qp->s_last != qp->s_acked ?
  240. IB_WC_SUCCESS : IB_WC_WR_FLUSH_ERR);
  241. /* will get called again */
  242. goto done;
  243. }
  244. if (qp->s_flags & (RVT_S_WAIT_RNR | RVT_S_WAIT_ACK))
  245. goto bail;
  246. if (qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) {
  247. if (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0) {
  248. qp->s_flags |= RVT_S_WAIT_PSN;
  249. goto bail;
  250. }
  251. qp->s_sending_psn = qp->s_psn;
  252. qp->s_sending_hpsn = qp->s_psn - 1;
  253. }
  254. /* header size in 32-bit words LRH+BTH = (8+12)/4. */
  255. hwords = 5;
  256. bth0 = 0;
  257. /* Send a request. */
  258. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  259. switch (qp->s_state) {
  260. default:
  261. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_NEXT_SEND_OK))
  262. goto bail;
  263. /*
  264. * Resend an old request or start a new one.
  265. *
  266. * We keep track of the current SWQE so that
  267. * we don't reset the "furthest progress" state
  268. * if we need to back up.
  269. */
  270. newreq = 0;
  271. if (qp->s_cur == qp->s_tail) {
  272. /* Check if send work queue is empty. */
  273. if (qp->s_tail == READ_ONCE(qp->s_head))
  274. goto bail;
  275. /*
  276. * If a fence is requested, wait for previous
  277. * RDMA read and atomic operations to finish.
  278. */
  279. if ((wqe->wr.send_flags & IB_SEND_FENCE) &&
  280. qp->s_num_rd_atomic) {
  281. qp->s_flags |= RVT_S_WAIT_FENCE;
  282. goto bail;
  283. }
  284. newreq = 1;
  285. qp->s_psn = wqe->psn;
  286. }
  287. /*
  288. * Note that we have to be careful not to modify the
  289. * original work request since we may need to resend
  290. * it.
  291. */
  292. len = wqe->length;
  293. ss = &qp->s_sge;
  294. bth2 = qp->s_psn & QIB_PSN_MASK;
  295. switch (wqe->wr.opcode) {
  296. case IB_WR_SEND:
  297. case IB_WR_SEND_WITH_IMM:
  298. /* If no credit, return. */
  299. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
  300. rvt_cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) {
  301. qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
  302. goto bail;
  303. }
  304. if (len > pmtu) {
  305. qp->s_state = OP(SEND_FIRST);
  306. len = pmtu;
  307. break;
  308. }
  309. if (wqe->wr.opcode == IB_WR_SEND)
  310. qp->s_state = OP(SEND_ONLY);
  311. else {
  312. qp->s_state = OP(SEND_ONLY_WITH_IMMEDIATE);
  313. /* Immediate data comes after the BTH */
  314. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  315. hwords += 1;
  316. }
  317. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  318. bth0 |= IB_BTH_SOLICITED;
  319. bth2 |= IB_BTH_REQ_ACK;
  320. if (++qp->s_cur == qp->s_size)
  321. qp->s_cur = 0;
  322. break;
  323. case IB_WR_RDMA_WRITE:
  324. if (newreq && !(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
  325. qp->s_lsn++;
  326. goto no_flow_control;
  327. case IB_WR_RDMA_WRITE_WITH_IMM:
  328. /* If no credit, return. */
  329. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT) &&
  330. rvt_cmp_msn(wqe->ssn, qp->s_lsn + 1) > 0) {
  331. qp->s_flags |= RVT_S_WAIT_SSN_CREDIT;
  332. goto bail;
  333. }
  334. no_flow_control:
  335. ohdr->u.rc.reth.vaddr =
  336. cpu_to_be64(wqe->rdma_wr.remote_addr);
  337. ohdr->u.rc.reth.rkey =
  338. cpu_to_be32(wqe->rdma_wr.rkey);
  339. ohdr->u.rc.reth.length = cpu_to_be32(len);
  340. hwords += sizeof(struct ib_reth) / sizeof(u32);
  341. if (len > pmtu) {
  342. qp->s_state = OP(RDMA_WRITE_FIRST);
  343. len = pmtu;
  344. break;
  345. }
  346. if (wqe->rdma_wr.wr.opcode == IB_WR_RDMA_WRITE)
  347. qp->s_state = OP(RDMA_WRITE_ONLY);
  348. else {
  349. qp->s_state = OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
  350. /* Immediate data comes after RETH */
  351. ohdr->u.rc.imm_data =
  352. wqe->rdma_wr.wr.ex.imm_data;
  353. hwords += 1;
  354. if (wqe->rdma_wr.wr.send_flags & IB_SEND_SOLICITED)
  355. bth0 |= IB_BTH_SOLICITED;
  356. }
  357. bth2 |= IB_BTH_REQ_ACK;
  358. if (++qp->s_cur == qp->s_size)
  359. qp->s_cur = 0;
  360. break;
  361. case IB_WR_RDMA_READ:
  362. /*
  363. * Don't allow more operations to be started
  364. * than the QP limits allow.
  365. */
  366. if (newreq) {
  367. if (qp->s_num_rd_atomic >=
  368. qp->s_max_rd_atomic) {
  369. qp->s_flags |= RVT_S_WAIT_RDMAR;
  370. goto bail;
  371. }
  372. qp->s_num_rd_atomic++;
  373. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
  374. qp->s_lsn++;
  375. }
  376. ohdr->u.rc.reth.vaddr =
  377. cpu_to_be64(wqe->rdma_wr.remote_addr);
  378. ohdr->u.rc.reth.rkey =
  379. cpu_to_be32(wqe->rdma_wr.rkey);
  380. ohdr->u.rc.reth.length = cpu_to_be32(len);
  381. qp->s_state = OP(RDMA_READ_REQUEST);
  382. hwords += sizeof(ohdr->u.rc.reth) / sizeof(u32);
  383. ss = NULL;
  384. len = 0;
  385. bth2 |= IB_BTH_REQ_ACK;
  386. if (++qp->s_cur == qp->s_size)
  387. qp->s_cur = 0;
  388. break;
  389. case IB_WR_ATOMIC_CMP_AND_SWP:
  390. case IB_WR_ATOMIC_FETCH_AND_ADD:
  391. /*
  392. * Don't allow more operations to be started
  393. * than the QP limits allow.
  394. */
  395. if (newreq) {
  396. if (qp->s_num_rd_atomic >=
  397. qp->s_max_rd_atomic) {
  398. qp->s_flags |= RVT_S_WAIT_RDMAR;
  399. goto bail;
  400. }
  401. qp->s_num_rd_atomic++;
  402. if (!(qp->s_flags & RVT_S_UNLIMITED_CREDIT))
  403. qp->s_lsn++;
  404. }
  405. if (wqe->atomic_wr.wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP) {
  406. qp->s_state = OP(COMPARE_SWAP);
  407. put_ib_ateth_swap(wqe->atomic_wr.swap,
  408. &ohdr->u.atomic_eth);
  409. put_ib_ateth_compare(wqe->atomic_wr.compare_add,
  410. &ohdr->u.atomic_eth);
  411. } else {
  412. qp->s_state = OP(FETCH_ADD);
  413. put_ib_ateth_swap(wqe->atomic_wr.compare_add,
  414. &ohdr->u.atomic_eth);
  415. put_ib_ateth_compare(0, &ohdr->u.atomic_eth);
  416. }
  417. put_ib_ateth_vaddr(wqe->atomic_wr.remote_addr,
  418. &ohdr->u.atomic_eth);
  419. ohdr->u.atomic_eth.rkey = cpu_to_be32(
  420. wqe->atomic_wr.rkey);
  421. hwords += sizeof(struct ib_atomic_eth) / sizeof(u32);
  422. ss = NULL;
  423. len = 0;
  424. bth2 |= IB_BTH_REQ_ACK;
  425. if (++qp->s_cur == qp->s_size)
  426. qp->s_cur = 0;
  427. break;
  428. default:
  429. goto bail;
  430. }
  431. qp->s_sge.sge = wqe->sg_list[0];
  432. qp->s_sge.sg_list = wqe->sg_list + 1;
  433. qp->s_sge.num_sge = wqe->wr.num_sge;
  434. qp->s_sge.total_len = wqe->length;
  435. qp->s_len = wqe->length;
  436. if (newreq) {
  437. qp->s_tail++;
  438. if (qp->s_tail >= qp->s_size)
  439. qp->s_tail = 0;
  440. }
  441. if (wqe->wr.opcode == IB_WR_RDMA_READ)
  442. qp->s_psn = wqe->lpsn + 1;
  443. else
  444. qp->s_psn++;
  445. break;
  446. case OP(RDMA_READ_RESPONSE_FIRST):
  447. /*
  448. * qp->s_state is normally set to the opcode of the
  449. * last packet constructed for new requests and therefore
  450. * is never set to RDMA read response.
  451. * RDMA_READ_RESPONSE_FIRST is used by the ACK processing
  452. * thread to indicate a SEND needs to be restarted from an
  453. * earlier PSN without interferring with the sending thread.
  454. * See qib_restart_rc().
  455. */
  456. qp->s_len = restart_sge(&qp->s_sge, wqe, qp->s_psn, pmtu);
  457. /* FALLTHROUGH */
  458. case OP(SEND_FIRST):
  459. qp->s_state = OP(SEND_MIDDLE);
  460. /* FALLTHROUGH */
  461. case OP(SEND_MIDDLE):
  462. bth2 = qp->s_psn++ & QIB_PSN_MASK;
  463. ss = &qp->s_sge;
  464. len = qp->s_len;
  465. if (len > pmtu) {
  466. len = pmtu;
  467. break;
  468. }
  469. if (wqe->wr.opcode == IB_WR_SEND)
  470. qp->s_state = OP(SEND_LAST);
  471. else {
  472. qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
  473. /* Immediate data comes after the BTH */
  474. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  475. hwords += 1;
  476. }
  477. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  478. bth0 |= IB_BTH_SOLICITED;
  479. bth2 |= IB_BTH_REQ_ACK;
  480. qp->s_cur++;
  481. if (qp->s_cur >= qp->s_size)
  482. qp->s_cur = 0;
  483. break;
  484. case OP(RDMA_READ_RESPONSE_LAST):
  485. /*
  486. * qp->s_state is normally set to the opcode of the
  487. * last packet constructed for new requests and therefore
  488. * is never set to RDMA read response.
  489. * RDMA_READ_RESPONSE_LAST is used by the ACK processing
  490. * thread to indicate a RDMA write needs to be restarted from
  491. * an earlier PSN without interferring with the sending thread.
  492. * See qib_restart_rc().
  493. */
  494. qp->s_len = restart_sge(&qp->s_sge, wqe, qp->s_psn, pmtu);
  495. /* FALLTHROUGH */
  496. case OP(RDMA_WRITE_FIRST):
  497. qp->s_state = OP(RDMA_WRITE_MIDDLE);
  498. /* FALLTHROUGH */
  499. case OP(RDMA_WRITE_MIDDLE):
  500. bth2 = qp->s_psn++ & QIB_PSN_MASK;
  501. ss = &qp->s_sge;
  502. len = qp->s_len;
  503. if (len > pmtu) {
  504. len = pmtu;
  505. break;
  506. }
  507. if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
  508. qp->s_state = OP(RDMA_WRITE_LAST);
  509. else {
  510. qp->s_state = OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
  511. /* Immediate data comes after the BTH */
  512. ohdr->u.imm_data = wqe->wr.ex.imm_data;
  513. hwords += 1;
  514. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  515. bth0 |= IB_BTH_SOLICITED;
  516. }
  517. bth2 |= IB_BTH_REQ_ACK;
  518. qp->s_cur++;
  519. if (qp->s_cur >= qp->s_size)
  520. qp->s_cur = 0;
  521. break;
  522. case OP(RDMA_READ_RESPONSE_MIDDLE):
  523. /*
  524. * qp->s_state is normally set to the opcode of the
  525. * last packet constructed for new requests and therefore
  526. * is never set to RDMA read response.
  527. * RDMA_READ_RESPONSE_MIDDLE is used by the ACK processing
  528. * thread to indicate a RDMA read needs to be restarted from
  529. * an earlier PSN without interferring with the sending thread.
  530. * See qib_restart_rc().
  531. */
  532. len = ((qp->s_psn - wqe->psn) & QIB_PSN_MASK) * pmtu;
  533. ohdr->u.rc.reth.vaddr =
  534. cpu_to_be64(wqe->rdma_wr.remote_addr + len);
  535. ohdr->u.rc.reth.rkey =
  536. cpu_to_be32(wqe->rdma_wr.rkey);
  537. ohdr->u.rc.reth.length = cpu_to_be32(wqe->length - len);
  538. qp->s_state = OP(RDMA_READ_REQUEST);
  539. hwords += sizeof(ohdr->u.rc.reth) / sizeof(u32);
  540. bth2 = (qp->s_psn & QIB_PSN_MASK) | IB_BTH_REQ_ACK;
  541. qp->s_psn = wqe->lpsn + 1;
  542. ss = NULL;
  543. len = 0;
  544. qp->s_cur++;
  545. if (qp->s_cur == qp->s_size)
  546. qp->s_cur = 0;
  547. break;
  548. }
  549. qp->s_sending_hpsn = bth2;
  550. delta = (((int) bth2 - (int) wqe->psn) << 8) >> 8;
  551. if (delta && delta % QIB_PSN_CREDIT == 0)
  552. bth2 |= IB_BTH_REQ_ACK;
  553. if (qp->s_flags & RVT_S_SEND_ONE) {
  554. qp->s_flags &= ~RVT_S_SEND_ONE;
  555. qp->s_flags |= RVT_S_WAIT_ACK;
  556. bth2 |= IB_BTH_REQ_ACK;
  557. }
  558. qp->s_len -= len;
  559. qp->s_hdrwords = hwords;
  560. qp->s_cur_sge = ss;
  561. qp->s_cur_size = len;
  562. qib_make_ruc_header(qp, ohdr, bth0 | (qp->s_state << 24), bth2);
  563. done:
  564. return 1;
  565. bail:
  566. qp->s_flags &= ~RVT_S_BUSY;
  567. return ret;
  568. }
  569. /**
  570. * qib_send_rc_ack - Construct an ACK packet and send it
  571. * @qp: a pointer to the QP
  572. *
  573. * This is called from qib_rc_rcv() and qib_kreceive().
  574. * Note that RDMA reads and atomics are handled in the
  575. * send side QP state and tasklet.
  576. */
  577. void qib_send_rc_ack(struct rvt_qp *qp)
  578. {
  579. struct qib_devdata *dd = dd_from_ibdev(qp->ibqp.device);
  580. struct qib_ibport *ibp = to_iport(qp->ibqp.device, qp->port_num);
  581. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  582. u64 pbc;
  583. u16 lrh0;
  584. u32 bth0;
  585. u32 hwords;
  586. u32 pbufn;
  587. u32 __iomem *piobuf;
  588. struct ib_header hdr;
  589. struct ib_other_headers *ohdr;
  590. u32 control;
  591. unsigned long flags;
  592. spin_lock_irqsave(&qp->s_lock, flags);
  593. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
  594. goto unlock;
  595. /* Don't send ACK or NAK if a RDMA read or atomic is pending. */
  596. if ((qp->s_flags & RVT_S_RESP_PENDING) || qp->s_rdma_ack_cnt)
  597. goto queue_ack;
  598. /* Construct the header with s_lock held so APM doesn't change it. */
  599. ohdr = &hdr.u.oth;
  600. lrh0 = QIB_LRH_BTH;
  601. /* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4. */
  602. hwords = 6;
  603. if (unlikely(rdma_ah_get_ah_flags(&qp->remote_ah_attr) &
  604. IB_AH_GRH)) {
  605. hwords += qib_make_grh(ibp, &hdr.u.l.grh,
  606. rdma_ah_read_grh(&qp->remote_ah_attr),
  607. hwords, 0);
  608. ohdr = &hdr.u.l.oth;
  609. lrh0 = QIB_LRH_GRH;
  610. }
  611. /* read pkey_index w/o lock (its atomic) */
  612. bth0 = qib_get_pkey(ibp, qp->s_pkey_index) | (OP(ACKNOWLEDGE) << 24);
  613. if (qp->s_mig_state == IB_MIG_MIGRATED)
  614. bth0 |= IB_BTH_MIG_REQ;
  615. if (qp->r_nak_state)
  616. ohdr->u.aeth = cpu_to_be32((qp->r_msn & IB_MSN_MASK) |
  617. (qp->r_nak_state <<
  618. IB_AETH_CREDIT_SHIFT));
  619. else
  620. ohdr->u.aeth = rvt_compute_aeth(qp);
  621. lrh0 |= ibp->sl_to_vl[rdma_ah_get_sl(&qp->remote_ah_attr)] << 12 |
  622. rdma_ah_get_sl(&qp->remote_ah_attr) << 4;
  623. hdr.lrh[0] = cpu_to_be16(lrh0);
  624. hdr.lrh[1] = cpu_to_be16(rdma_ah_get_dlid(&qp->remote_ah_attr));
  625. hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC);
  626. hdr.lrh[3] = cpu_to_be16(ppd->lid |
  627. rdma_ah_get_path_bits(&qp->remote_ah_attr));
  628. ohdr->bth[0] = cpu_to_be32(bth0);
  629. ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
  630. ohdr->bth[2] = cpu_to_be32(qp->r_ack_psn & QIB_PSN_MASK);
  631. spin_unlock_irqrestore(&qp->s_lock, flags);
  632. /* Don't try to send ACKs if the link isn't ACTIVE */
  633. if (!(ppd->lflags & QIBL_LINKACTIVE))
  634. goto done;
  635. control = dd->f_setpbc_control(ppd, hwords + SIZE_OF_CRC,
  636. qp->s_srate, lrh0 >> 12);
  637. /* length is + 1 for the control dword */
  638. pbc = ((u64) control << 32) | (hwords + 1);
  639. piobuf = dd->f_getsendbuf(ppd, pbc, &pbufn);
  640. if (!piobuf) {
  641. /*
  642. * We are out of PIO buffers at the moment.
  643. * Pass responsibility for sending the ACK to the
  644. * send tasklet so that when a PIO buffer becomes
  645. * available, the ACK is sent ahead of other outgoing
  646. * packets.
  647. */
  648. spin_lock_irqsave(&qp->s_lock, flags);
  649. goto queue_ack;
  650. }
  651. /*
  652. * Write the pbc.
  653. * We have to flush after the PBC for correctness
  654. * on some cpus or WC buffer can be written out of order.
  655. */
  656. writeq(pbc, piobuf);
  657. if (dd->flags & QIB_PIO_FLUSH_WC) {
  658. u32 *hdrp = (u32 *) &hdr;
  659. qib_flush_wc();
  660. qib_pio_copy(piobuf + 2, hdrp, hwords - 1);
  661. qib_flush_wc();
  662. __raw_writel(hdrp[hwords - 1], piobuf + hwords + 1);
  663. } else
  664. qib_pio_copy(piobuf + 2, (u32 *) &hdr, hwords);
  665. if (dd->flags & QIB_USE_SPCL_TRIG) {
  666. u32 spcl_off = (pbufn >= dd->piobcnt2k) ? 2047 : 1023;
  667. qib_flush_wc();
  668. __raw_writel(0xaebecede, piobuf + spcl_off);
  669. }
  670. qib_flush_wc();
  671. qib_sendbuf_done(dd, pbufn);
  672. this_cpu_inc(ibp->pmastats->n_unicast_xmit);
  673. goto done;
  674. queue_ack:
  675. if (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK) {
  676. this_cpu_inc(*ibp->rvp.rc_qacks);
  677. qp->s_flags |= RVT_S_ACK_PENDING | RVT_S_RESP_PENDING;
  678. qp->s_nak_state = qp->r_nak_state;
  679. qp->s_ack_psn = qp->r_ack_psn;
  680. /* Schedule the send tasklet. */
  681. qib_schedule_send(qp);
  682. }
  683. unlock:
  684. spin_unlock_irqrestore(&qp->s_lock, flags);
  685. done:
  686. return;
  687. }
  688. /**
  689. * reset_psn - reset the QP state to send starting from PSN
  690. * @qp: the QP
  691. * @psn: the packet sequence number to restart at
  692. *
  693. * This is called from qib_rc_rcv() to process an incoming RC ACK
  694. * for the given QP.
  695. * Called at interrupt level with the QP s_lock held.
  696. */
  697. static void reset_psn(struct rvt_qp *qp, u32 psn)
  698. {
  699. u32 n = qp->s_acked;
  700. struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, n);
  701. u32 opcode;
  702. qp->s_cur = n;
  703. /*
  704. * If we are starting the request from the beginning,
  705. * let the normal send code handle initialization.
  706. */
  707. if (qib_cmp24(psn, wqe->psn) <= 0) {
  708. qp->s_state = OP(SEND_LAST);
  709. goto done;
  710. }
  711. /* Find the work request opcode corresponding to the given PSN. */
  712. opcode = wqe->wr.opcode;
  713. for (;;) {
  714. int diff;
  715. if (++n == qp->s_size)
  716. n = 0;
  717. if (n == qp->s_tail)
  718. break;
  719. wqe = rvt_get_swqe_ptr(qp, n);
  720. diff = qib_cmp24(psn, wqe->psn);
  721. if (diff < 0)
  722. break;
  723. qp->s_cur = n;
  724. /*
  725. * If we are starting the request from the beginning,
  726. * let the normal send code handle initialization.
  727. */
  728. if (diff == 0) {
  729. qp->s_state = OP(SEND_LAST);
  730. goto done;
  731. }
  732. opcode = wqe->wr.opcode;
  733. }
  734. /*
  735. * Set the state to restart in the middle of a request.
  736. * Don't change the s_sge, s_cur_sge, or s_cur_size.
  737. * See qib_make_rc_req().
  738. */
  739. switch (opcode) {
  740. case IB_WR_SEND:
  741. case IB_WR_SEND_WITH_IMM:
  742. qp->s_state = OP(RDMA_READ_RESPONSE_FIRST);
  743. break;
  744. case IB_WR_RDMA_WRITE:
  745. case IB_WR_RDMA_WRITE_WITH_IMM:
  746. qp->s_state = OP(RDMA_READ_RESPONSE_LAST);
  747. break;
  748. case IB_WR_RDMA_READ:
  749. qp->s_state = OP(RDMA_READ_RESPONSE_MIDDLE);
  750. break;
  751. default:
  752. /*
  753. * This case shouldn't happen since its only
  754. * one PSN per req.
  755. */
  756. qp->s_state = OP(SEND_LAST);
  757. }
  758. done:
  759. qp->s_psn = psn;
  760. /*
  761. * Set RVT_S_WAIT_PSN as qib_rc_complete() may start the timer
  762. * asynchronously before the send tasklet can get scheduled.
  763. * Doing it in qib_make_rc_req() is too late.
  764. */
  765. if ((qib_cmp24(qp->s_psn, qp->s_sending_hpsn) <= 0) &&
  766. (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0))
  767. qp->s_flags |= RVT_S_WAIT_PSN;
  768. }
  769. /*
  770. * Back up requester to resend the last un-ACKed request.
  771. * The QP r_lock and s_lock should be held and interrupts disabled.
  772. */
  773. void qib_restart_rc(struct rvt_qp *qp, u32 psn, int wait)
  774. {
  775. struct rvt_swqe *wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  776. struct qib_ibport *ibp;
  777. if (qp->s_retry == 0) {
  778. if (qp->s_mig_state == IB_MIG_ARMED) {
  779. qib_migrate_qp(qp);
  780. qp->s_retry = qp->s_retry_cnt;
  781. } else if (qp->s_last == qp->s_acked) {
  782. rvt_send_complete(qp, wqe, IB_WC_RETRY_EXC_ERR);
  783. rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
  784. return;
  785. } else /* XXX need to handle delayed completion */
  786. return;
  787. } else
  788. qp->s_retry--;
  789. ibp = to_iport(qp->ibqp.device, qp->port_num);
  790. if (wqe->wr.opcode == IB_WR_RDMA_READ)
  791. ibp->rvp.n_rc_resends++;
  792. else
  793. ibp->rvp.n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK;
  794. qp->s_flags &= ~(RVT_S_WAIT_FENCE | RVT_S_WAIT_RDMAR |
  795. RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_PSN |
  796. RVT_S_WAIT_ACK);
  797. if (wait)
  798. qp->s_flags |= RVT_S_SEND_ONE;
  799. reset_psn(qp, psn);
  800. }
  801. /*
  802. * Set qp->s_sending_psn to the next PSN after the given one.
  803. * This would be psn+1 except when RDMA reads are present.
  804. */
  805. static void reset_sending_psn(struct rvt_qp *qp, u32 psn)
  806. {
  807. struct rvt_swqe *wqe;
  808. u32 n = qp->s_last;
  809. /* Find the work request corresponding to the given PSN. */
  810. for (;;) {
  811. wqe = rvt_get_swqe_ptr(qp, n);
  812. if (qib_cmp24(psn, wqe->lpsn) <= 0) {
  813. if (wqe->wr.opcode == IB_WR_RDMA_READ)
  814. qp->s_sending_psn = wqe->lpsn + 1;
  815. else
  816. qp->s_sending_psn = psn + 1;
  817. break;
  818. }
  819. if (++n == qp->s_size)
  820. n = 0;
  821. if (n == qp->s_tail)
  822. break;
  823. }
  824. }
  825. /*
  826. * This should be called with the QP s_lock held and interrupts disabled.
  827. */
  828. void qib_rc_send_complete(struct rvt_qp *qp, struct ib_header *hdr)
  829. {
  830. struct ib_other_headers *ohdr;
  831. struct rvt_swqe *wqe;
  832. u32 opcode;
  833. u32 psn;
  834. if (!(ib_rvt_state_ops[qp->state] & RVT_SEND_OR_FLUSH_OR_RECV_OK))
  835. return;
  836. /* Find out where the BTH is */
  837. if ((be16_to_cpu(hdr->lrh[0]) & 3) == QIB_LRH_BTH)
  838. ohdr = &hdr->u.oth;
  839. else
  840. ohdr = &hdr->u.l.oth;
  841. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  842. if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) &&
  843. opcode <= OP(ATOMIC_ACKNOWLEDGE)) {
  844. WARN_ON(!qp->s_rdma_ack_cnt);
  845. qp->s_rdma_ack_cnt--;
  846. return;
  847. }
  848. psn = be32_to_cpu(ohdr->bth[2]);
  849. reset_sending_psn(qp, psn);
  850. /*
  851. * Start timer after a packet requesting an ACK has been sent and
  852. * there are still requests that haven't been acked.
  853. */
  854. if ((psn & IB_BTH_REQ_ACK) && qp->s_acked != qp->s_tail &&
  855. !(qp->s_flags & (RVT_S_TIMER | RVT_S_WAIT_RNR | RVT_S_WAIT_PSN)) &&
  856. (ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
  857. rvt_add_retry_timer(qp);
  858. while (qp->s_last != qp->s_acked) {
  859. u32 s_last;
  860. wqe = rvt_get_swqe_ptr(qp, qp->s_last);
  861. if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) >= 0 &&
  862. qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)
  863. break;
  864. s_last = qp->s_last;
  865. if (++s_last >= qp->s_size)
  866. s_last = 0;
  867. qp->s_last = s_last;
  868. /* see post_send() */
  869. barrier();
  870. rvt_put_swqe(wqe);
  871. rvt_qp_swqe_complete(qp,
  872. wqe,
  873. ib_qib_wc_opcode[wqe->wr.opcode],
  874. IB_WC_SUCCESS);
  875. }
  876. /*
  877. * If we were waiting for sends to complete before resending,
  878. * and they are now complete, restart sending.
  879. */
  880. if (qp->s_flags & RVT_S_WAIT_PSN &&
  881. qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
  882. qp->s_flags &= ~RVT_S_WAIT_PSN;
  883. qp->s_sending_psn = qp->s_psn;
  884. qp->s_sending_hpsn = qp->s_psn - 1;
  885. qib_schedule_send(qp);
  886. }
  887. }
  888. static inline void update_last_psn(struct rvt_qp *qp, u32 psn)
  889. {
  890. qp->s_last_psn = psn;
  891. }
  892. /*
  893. * Generate a SWQE completion.
  894. * This is similar to qib_send_complete but has to check to be sure
  895. * that the SGEs are not being referenced if the SWQE is being resent.
  896. */
  897. static struct rvt_swqe *do_rc_completion(struct rvt_qp *qp,
  898. struct rvt_swqe *wqe,
  899. struct qib_ibport *ibp)
  900. {
  901. /*
  902. * Don't decrement refcount and don't generate a
  903. * completion if the SWQE is being resent until the send
  904. * is finished.
  905. */
  906. if (qib_cmp24(wqe->lpsn, qp->s_sending_psn) < 0 ||
  907. qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) > 0) {
  908. u32 s_last;
  909. rvt_put_swqe(wqe);
  910. s_last = qp->s_last;
  911. if (++s_last >= qp->s_size)
  912. s_last = 0;
  913. qp->s_last = s_last;
  914. /* see post_send() */
  915. barrier();
  916. rvt_qp_swqe_complete(qp,
  917. wqe,
  918. ib_qib_wc_opcode[wqe->wr.opcode],
  919. IB_WC_SUCCESS);
  920. } else
  921. this_cpu_inc(*ibp->rvp.rc_delayed_comp);
  922. qp->s_retry = qp->s_retry_cnt;
  923. update_last_psn(qp, wqe->lpsn);
  924. /*
  925. * If we are completing a request which is in the process of
  926. * being resent, we can stop resending it since we know the
  927. * responder has already seen it.
  928. */
  929. if (qp->s_acked == qp->s_cur) {
  930. if (++qp->s_cur >= qp->s_size)
  931. qp->s_cur = 0;
  932. qp->s_acked = qp->s_cur;
  933. wqe = rvt_get_swqe_ptr(qp, qp->s_cur);
  934. if (qp->s_acked != qp->s_tail) {
  935. qp->s_state = OP(SEND_LAST);
  936. qp->s_psn = wqe->psn;
  937. }
  938. } else {
  939. if (++qp->s_acked >= qp->s_size)
  940. qp->s_acked = 0;
  941. if (qp->state == IB_QPS_SQD && qp->s_acked == qp->s_cur)
  942. qp->s_draining = 0;
  943. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  944. }
  945. return wqe;
  946. }
  947. /**
  948. * do_rc_ack - process an incoming RC ACK
  949. * @qp: the QP the ACK came in on
  950. * @psn: the packet sequence number of the ACK
  951. * @opcode: the opcode of the request that resulted in the ACK
  952. *
  953. * This is called from qib_rc_rcv_resp() to process an incoming RC ACK
  954. * for the given QP.
  955. * Called at interrupt level with the QP s_lock held.
  956. * Returns 1 if OK, 0 if current operation should be aborted (NAK).
  957. */
  958. static int do_rc_ack(struct rvt_qp *qp, u32 aeth, u32 psn, int opcode,
  959. u64 val, struct qib_ctxtdata *rcd)
  960. {
  961. struct qib_ibport *ibp;
  962. enum ib_wc_status status;
  963. struct rvt_swqe *wqe;
  964. int ret = 0;
  965. u32 ack_psn;
  966. int diff;
  967. /*
  968. * Note that NAKs implicitly ACK outstanding SEND and RDMA write
  969. * requests and implicitly NAK RDMA read and atomic requests issued
  970. * before the NAK'ed request. The MSN won't include the NAK'ed
  971. * request but will include an ACK'ed request(s).
  972. */
  973. ack_psn = psn;
  974. if (aeth >> IB_AETH_NAK_SHIFT)
  975. ack_psn--;
  976. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  977. ibp = to_iport(qp->ibqp.device, qp->port_num);
  978. /*
  979. * The MSN might be for a later WQE than the PSN indicates so
  980. * only complete WQEs that the PSN finishes.
  981. */
  982. while ((diff = qib_cmp24(ack_psn, wqe->lpsn)) >= 0) {
  983. /*
  984. * RDMA_READ_RESPONSE_ONLY is a special case since
  985. * we want to generate completion events for everything
  986. * before the RDMA read, copy the data, then generate
  987. * the completion for the read.
  988. */
  989. if (wqe->wr.opcode == IB_WR_RDMA_READ &&
  990. opcode == OP(RDMA_READ_RESPONSE_ONLY) &&
  991. diff == 0) {
  992. ret = 1;
  993. goto bail;
  994. }
  995. /*
  996. * If this request is a RDMA read or atomic, and the ACK is
  997. * for a later operation, this ACK NAKs the RDMA read or
  998. * atomic. In other words, only a RDMA_READ_LAST or ONLY
  999. * can ACK a RDMA read and likewise for atomic ops. Note
  1000. * that the NAK case can only happen if relaxed ordering is
  1001. * used and requests are sent after an RDMA read or atomic
  1002. * is sent but before the response is received.
  1003. */
  1004. if ((wqe->wr.opcode == IB_WR_RDMA_READ &&
  1005. (opcode != OP(RDMA_READ_RESPONSE_LAST) || diff != 0)) ||
  1006. ((wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1007. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) &&
  1008. (opcode != OP(ATOMIC_ACKNOWLEDGE) || diff != 0))) {
  1009. /* Retry this request. */
  1010. if (!(qp->r_flags & RVT_R_RDMAR_SEQ)) {
  1011. qp->r_flags |= RVT_R_RDMAR_SEQ;
  1012. qib_restart_rc(qp, qp->s_last_psn + 1, 0);
  1013. if (list_empty(&qp->rspwait)) {
  1014. qp->r_flags |= RVT_R_RSP_SEND;
  1015. rvt_get_qp(qp);
  1016. list_add_tail(&qp->rspwait,
  1017. &rcd->qp_wait_list);
  1018. }
  1019. }
  1020. /*
  1021. * No need to process the ACK/NAK since we are
  1022. * restarting an earlier request.
  1023. */
  1024. goto bail;
  1025. }
  1026. if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1027. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) {
  1028. u64 *vaddr = wqe->sg_list[0].vaddr;
  1029. *vaddr = val;
  1030. }
  1031. if (qp->s_num_rd_atomic &&
  1032. (wqe->wr.opcode == IB_WR_RDMA_READ ||
  1033. wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1034. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)) {
  1035. qp->s_num_rd_atomic--;
  1036. /* Restart sending task if fence is complete */
  1037. if ((qp->s_flags & RVT_S_WAIT_FENCE) &&
  1038. !qp->s_num_rd_atomic) {
  1039. qp->s_flags &= ~(RVT_S_WAIT_FENCE |
  1040. RVT_S_WAIT_ACK);
  1041. qib_schedule_send(qp);
  1042. } else if (qp->s_flags & RVT_S_WAIT_RDMAR) {
  1043. qp->s_flags &= ~(RVT_S_WAIT_RDMAR |
  1044. RVT_S_WAIT_ACK);
  1045. qib_schedule_send(qp);
  1046. }
  1047. }
  1048. wqe = do_rc_completion(qp, wqe, ibp);
  1049. if (qp->s_acked == qp->s_tail)
  1050. break;
  1051. }
  1052. switch (aeth >> IB_AETH_NAK_SHIFT) {
  1053. case 0: /* ACK */
  1054. this_cpu_inc(*ibp->rvp.rc_acks);
  1055. if (qp->s_acked != qp->s_tail) {
  1056. /*
  1057. * We are expecting more ACKs so
  1058. * reset the retransmit timer.
  1059. */
  1060. rvt_mod_retry_timer(qp);
  1061. /*
  1062. * We can stop resending the earlier packets and
  1063. * continue with the next packet the receiver wants.
  1064. */
  1065. if (qib_cmp24(qp->s_psn, psn) <= 0)
  1066. reset_psn(qp, psn + 1);
  1067. } else {
  1068. /* No more acks - kill all timers */
  1069. rvt_stop_rc_timers(qp);
  1070. if (qib_cmp24(qp->s_psn, psn) <= 0) {
  1071. qp->s_state = OP(SEND_LAST);
  1072. qp->s_psn = psn + 1;
  1073. }
  1074. }
  1075. if (qp->s_flags & RVT_S_WAIT_ACK) {
  1076. qp->s_flags &= ~RVT_S_WAIT_ACK;
  1077. qib_schedule_send(qp);
  1078. }
  1079. rvt_get_credit(qp, aeth);
  1080. qp->s_rnr_retry = qp->s_rnr_retry_cnt;
  1081. qp->s_retry = qp->s_retry_cnt;
  1082. update_last_psn(qp, psn);
  1083. return 1;
  1084. case 1: /* RNR NAK */
  1085. ibp->rvp.n_rnr_naks++;
  1086. if (qp->s_acked == qp->s_tail)
  1087. goto bail;
  1088. if (qp->s_flags & RVT_S_WAIT_RNR)
  1089. goto bail;
  1090. if (qp->s_rnr_retry == 0) {
  1091. status = IB_WC_RNR_RETRY_EXC_ERR;
  1092. goto class_b;
  1093. }
  1094. if (qp->s_rnr_retry_cnt < 7)
  1095. qp->s_rnr_retry--;
  1096. /* The last valid PSN is the previous PSN. */
  1097. update_last_psn(qp, psn - 1);
  1098. ibp->rvp.n_rc_resends += (qp->s_psn - psn) & QIB_PSN_MASK;
  1099. reset_psn(qp, psn);
  1100. qp->s_flags &= ~(RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_ACK);
  1101. rvt_stop_rc_timers(qp);
  1102. rvt_add_rnr_timer(qp, aeth);
  1103. return 0;
  1104. case 3: /* NAK */
  1105. if (qp->s_acked == qp->s_tail)
  1106. goto bail;
  1107. /* The last valid PSN is the previous PSN. */
  1108. update_last_psn(qp, psn - 1);
  1109. switch ((aeth >> IB_AETH_CREDIT_SHIFT) &
  1110. IB_AETH_CREDIT_MASK) {
  1111. case 0: /* PSN sequence error */
  1112. ibp->rvp.n_seq_naks++;
  1113. /*
  1114. * Back up to the responder's expected PSN.
  1115. * Note that we might get a NAK in the middle of an
  1116. * RDMA READ response which terminates the RDMA
  1117. * READ.
  1118. */
  1119. qib_restart_rc(qp, psn, 0);
  1120. qib_schedule_send(qp);
  1121. break;
  1122. case 1: /* Invalid Request */
  1123. status = IB_WC_REM_INV_REQ_ERR;
  1124. ibp->rvp.n_other_naks++;
  1125. goto class_b;
  1126. case 2: /* Remote Access Error */
  1127. status = IB_WC_REM_ACCESS_ERR;
  1128. ibp->rvp.n_other_naks++;
  1129. goto class_b;
  1130. case 3: /* Remote Operation Error */
  1131. status = IB_WC_REM_OP_ERR;
  1132. ibp->rvp.n_other_naks++;
  1133. class_b:
  1134. if (qp->s_last == qp->s_acked) {
  1135. rvt_send_complete(qp, wqe, status);
  1136. rvt_error_qp(qp, IB_WC_WR_FLUSH_ERR);
  1137. }
  1138. break;
  1139. default:
  1140. /* Ignore other reserved NAK error codes */
  1141. goto reserved;
  1142. }
  1143. qp->s_retry = qp->s_retry_cnt;
  1144. qp->s_rnr_retry = qp->s_rnr_retry_cnt;
  1145. goto bail;
  1146. default: /* 2: reserved */
  1147. reserved:
  1148. /* Ignore reserved NAK codes. */
  1149. goto bail;
  1150. }
  1151. bail:
  1152. rvt_stop_rc_timers(qp);
  1153. return ret;
  1154. }
  1155. /*
  1156. * We have seen an out of sequence RDMA read middle or last packet.
  1157. * This ACKs SENDs and RDMA writes up to the first RDMA read or atomic SWQE.
  1158. */
  1159. static void rdma_seq_err(struct rvt_qp *qp, struct qib_ibport *ibp, u32 psn,
  1160. struct qib_ctxtdata *rcd)
  1161. {
  1162. struct rvt_swqe *wqe;
  1163. /* Remove QP from retry timer */
  1164. rvt_stop_rc_timers(qp);
  1165. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1166. while (qib_cmp24(psn, wqe->lpsn) > 0) {
  1167. if (wqe->wr.opcode == IB_WR_RDMA_READ ||
  1168. wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  1169. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD)
  1170. break;
  1171. wqe = do_rc_completion(qp, wqe, ibp);
  1172. }
  1173. ibp->rvp.n_rdma_seq++;
  1174. qp->r_flags |= RVT_R_RDMAR_SEQ;
  1175. qib_restart_rc(qp, qp->s_last_psn + 1, 0);
  1176. if (list_empty(&qp->rspwait)) {
  1177. qp->r_flags |= RVT_R_RSP_SEND;
  1178. rvt_get_qp(qp);
  1179. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1180. }
  1181. }
  1182. /**
  1183. * qib_rc_rcv_resp - process an incoming RC response packet
  1184. * @ibp: the port this packet came in on
  1185. * @ohdr: the other headers for this packet
  1186. * @data: the packet data
  1187. * @tlen: the packet length
  1188. * @qp: the QP for this packet
  1189. * @opcode: the opcode for this packet
  1190. * @psn: the packet sequence number for this packet
  1191. * @hdrsize: the header length
  1192. * @pmtu: the path MTU
  1193. *
  1194. * This is called from qib_rc_rcv() to process an incoming RC response
  1195. * packet for the given QP.
  1196. * Called at interrupt level.
  1197. */
  1198. static void qib_rc_rcv_resp(struct qib_ibport *ibp,
  1199. struct ib_other_headers *ohdr,
  1200. void *data, u32 tlen,
  1201. struct rvt_qp *qp,
  1202. u32 opcode,
  1203. u32 psn, u32 hdrsize, u32 pmtu,
  1204. struct qib_ctxtdata *rcd)
  1205. {
  1206. struct rvt_swqe *wqe;
  1207. struct qib_pportdata *ppd = ppd_from_ibp(ibp);
  1208. enum ib_wc_status status;
  1209. unsigned long flags;
  1210. int diff;
  1211. u32 pad;
  1212. u32 aeth;
  1213. u64 val;
  1214. if (opcode != OP(RDMA_READ_RESPONSE_MIDDLE)) {
  1215. /*
  1216. * If ACK'd PSN on SDMA busy list try to make progress to
  1217. * reclaim SDMA credits.
  1218. */
  1219. if ((qib_cmp24(psn, qp->s_sending_psn) >= 0) &&
  1220. (qib_cmp24(qp->s_sending_psn, qp->s_sending_hpsn) <= 0)) {
  1221. /*
  1222. * If send tasklet not running attempt to progress
  1223. * SDMA queue.
  1224. */
  1225. if (!(qp->s_flags & RVT_S_BUSY)) {
  1226. /* Acquire SDMA Lock */
  1227. spin_lock_irqsave(&ppd->sdma_lock, flags);
  1228. /* Invoke sdma make progress */
  1229. qib_sdma_make_progress(ppd);
  1230. /* Release SDMA Lock */
  1231. spin_unlock_irqrestore(&ppd->sdma_lock, flags);
  1232. }
  1233. }
  1234. }
  1235. spin_lock_irqsave(&qp->s_lock, flags);
  1236. if (!(ib_rvt_state_ops[qp->state] & RVT_PROCESS_RECV_OK))
  1237. goto ack_done;
  1238. /* Ignore invalid responses. */
  1239. if (qib_cmp24(psn, READ_ONCE(qp->s_next_psn)) >= 0)
  1240. goto ack_done;
  1241. /* Ignore duplicate responses. */
  1242. diff = qib_cmp24(psn, qp->s_last_psn);
  1243. if (unlikely(diff <= 0)) {
  1244. /* Update credits for "ghost" ACKs */
  1245. if (diff == 0 && opcode == OP(ACKNOWLEDGE)) {
  1246. aeth = be32_to_cpu(ohdr->u.aeth);
  1247. if ((aeth >> IB_AETH_NAK_SHIFT) == 0)
  1248. rvt_get_credit(qp, aeth);
  1249. }
  1250. goto ack_done;
  1251. }
  1252. /*
  1253. * Skip everything other than the PSN we expect, if we are waiting
  1254. * for a reply to a restarted RDMA read or atomic op.
  1255. */
  1256. if (qp->r_flags & RVT_R_RDMAR_SEQ) {
  1257. if (qib_cmp24(psn, qp->s_last_psn + 1) != 0)
  1258. goto ack_done;
  1259. qp->r_flags &= ~RVT_R_RDMAR_SEQ;
  1260. }
  1261. if (unlikely(qp->s_acked == qp->s_tail))
  1262. goto ack_done;
  1263. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1264. status = IB_WC_SUCCESS;
  1265. switch (opcode) {
  1266. case OP(ACKNOWLEDGE):
  1267. case OP(ATOMIC_ACKNOWLEDGE):
  1268. case OP(RDMA_READ_RESPONSE_FIRST):
  1269. aeth = be32_to_cpu(ohdr->u.aeth);
  1270. if (opcode == OP(ATOMIC_ACKNOWLEDGE))
  1271. val = ib_u64_get(&ohdr->u.at.atomic_ack_eth);
  1272. else
  1273. val = 0;
  1274. if (!do_rc_ack(qp, aeth, psn, opcode, val, rcd) ||
  1275. opcode != OP(RDMA_READ_RESPONSE_FIRST))
  1276. goto ack_done;
  1277. hdrsize += 4;
  1278. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1279. if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
  1280. goto ack_op_err;
  1281. /*
  1282. * If this is a response to a resent RDMA read, we
  1283. * have to be careful to copy the data to the right
  1284. * location.
  1285. */
  1286. qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge,
  1287. wqe, psn, pmtu);
  1288. goto read_middle;
  1289. case OP(RDMA_READ_RESPONSE_MIDDLE):
  1290. /* no AETH, no ACK */
  1291. if (unlikely(qib_cmp24(psn, qp->s_last_psn + 1)))
  1292. goto ack_seq_err;
  1293. if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
  1294. goto ack_op_err;
  1295. read_middle:
  1296. if (unlikely(tlen != (hdrsize + pmtu + 4)))
  1297. goto ack_len_err;
  1298. if (unlikely(pmtu >= qp->s_rdma_read_len))
  1299. goto ack_len_err;
  1300. /*
  1301. * We got a response so update the timeout.
  1302. * 4.096 usec. * (1 << qp->timeout)
  1303. */
  1304. rvt_mod_retry_timer(qp);
  1305. if (qp->s_flags & RVT_S_WAIT_ACK) {
  1306. qp->s_flags &= ~RVT_S_WAIT_ACK;
  1307. qib_schedule_send(qp);
  1308. }
  1309. if (opcode == OP(RDMA_READ_RESPONSE_MIDDLE))
  1310. qp->s_retry = qp->s_retry_cnt;
  1311. /*
  1312. * Update the RDMA receive state but do the copy w/o
  1313. * holding the locks and blocking interrupts.
  1314. */
  1315. qp->s_rdma_read_len -= pmtu;
  1316. update_last_psn(qp, psn);
  1317. spin_unlock_irqrestore(&qp->s_lock, flags);
  1318. rvt_copy_sge(qp, &qp->s_rdma_read_sge,
  1319. data, pmtu, false, false);
  1320. goto bail;
  1321. case OP(RDMA_READ_RESPONSE_ONLY):
  1322. aeth = be32_to_cpu(ohdr->u.aeth);
  1323. if (!do_rc_ack(qp, aeth, psn, opcode, 0, rcd))
  1324. goto ack_done;
  1325. /* Get the number of bytes the message was padded by. */
  1326. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  1327. /*
  1328. * Check that the data size is >= 0 && <= pmtu.
  1329. * Remember to account for the AETH header (4) and
  1330. * ICRC (4).
  1331. */
  1332. if (unlikely(tlen < (hdrsize + pad + 8)))
  1333. goto ack_len_err;
  1334. /*
  1335. * If this is a response to a resent RDMA read, we
  1336. * have to be careful to copy the data to the right
  1337. * location.
  1338. */
  1339. wqe = rvt_get_swqe_ptr(qp, qp->s_acked);
  1340. qp->s_rdma_read_len = restart_sge(&qp->s_rdma_read_sge,
  1341. wqe, psn, pmtu);
  1342. goto read_last;
  1343. case OP(RDMA_READ_RESPONSE_LAST):
  1344. /* ACKs READ req. */
  1345. if (unlikely(qib_cmp24(psn, qp->s_last_psn + 1)))
  1346. goto ack_seq_err;
  1347. if (unlikely(wqe->wr.opcode != IB_WR_RDMA_READ))
  1348. goto ack_op_err;
  1349. /* Get the number of bytes the message was padded by. */
  1350. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  1351. /*
  1352. * Check that the data size is >= 1 && <= pmtu.
  1353. * Remember to account for the AETH header (4) and
  1354. * ICRC (4).
  1355. */
  1356. if (unlikely(tlen <= (hdrsize + pad + 8)))
  1357. goto ack_len_err;
  1358. read_last:
  1359. tlen -= hdrsize + pad + 8;
  1360. if (unlikely(tlen != qp->s_rdma_read_len))
  1361. goto ack_len_err;
  1362. aeth = be32_to_cpu(ohdr->u.aeth);
  1363. rvt_copy_sge(qp, &qp->s_rdma_read_sge,
  1364. data, tlen, false, false);
  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. rvt_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 = rvt_get_rwqe(qp, false);
  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. rvt_copy_sge(qp, &qp->r_sge, data, pmtu, true, false);
  1711. break;
  1712. case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
  1713. /* consume RWQE */
  1714. ret = rvt_get_rwqe(qp, true);
  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 = rvt_get_rwqe(qp, false);
  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. /* fall through -- 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. rvt_copy_sge(qp, &qp->r_sge, data, tlen, true, false);
  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. ib_bth_is_solicited(ohdr));
  1778. break;
  1779. case OP(RDMA_WRITE_FIRST):
  1780. case OP(RDMA_WRITE_ONLY):
  1781. case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
  1782. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_WRITE)))
  1783. goto nack_inv;
  1784. /* consume RWQE */
  1785. reth = &ohdr->u.rc.reth;
  1786. hdrsize += sizeof(*reth);
  1787. qp->r_len = be32_to_cpu(reth->length);
  1788. qp->r_rcv_len = 0;
  1789. qp->r_sge.sg_list = NULL;
  1790. if (qp->r_len != 0) {
  1791. u32 rkey = be32_to_cpu(reth->rkey);
  1792. u64 vaddr = be64_to_cpu(reth->vaddr);
  1793. int ok;
  1794. /* Check rkey & NAK */
  1795. ok = rvt_rkey_ok(qp, &qp->r_sge.sge, qp->r_len, vaddr,
  1796. rkey, IB_ACCESS_REMOTE_WRITE);
  1797. if (unlikely(!ok))
  1798. goto nack_acc;
  1799. qp->r_sge.num_sge = 1;
  1800. } else {
  1801. qp->r_sge.num_sge = 0;
  1802. qp->r_sge.sge.mr = NULL;
  1803. qp->r_sge.sge.vaddr = NULL;
  1804. qp->r_sge.sge.length = 0;
  1805. qp->r_sge.sge.sge_length = 0;
  1806. }
  1807. if (opcode == OP(RDMA_WRITE_FIRST))
  1808. goto send_middle;
  1809. else if (opcode == OP(RDMA_WRITE_ONLY))
  1810. goto no_immediate_data;
  1811. ret = rvt_get_rwqe(qp, true);
  1812. if (ret < 0)
  1813. goto nack_op_err;
  1814. if (!ret) {
  1815. rvt_put_ss(&qp->r_sge);
  1816. goto rnr_nak;
  1817. }
  1818. wc.ex.imm_data = ohdr->u.rc.imm_data;
  1819. hdrsize += 4;
  1820. wc.wc_flags = IB_WC_WITH_IMM;
  1821. goto send_last;
  1822. case OP(RDMA_READ_REQUEST): {
  1823. struct rvt_ack_entry *e;
  1824. u32 len;
  1825. u8 next;
  1826. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_READ)))
  1827. goto nack_inv;
  1828. next = qp->r_head_ack_queue + 1;
  1829. /* s_ack_queue is size QIB_MAX_RDMA_ATOMIC+1 so use > not >= */
  1830. if (next > QIB_MAX_RDMA_ATOMIC)
  1831. next = 0;
  1832. spin_lock_irqsave(&qp->s_lock, flags);
  1833. if (unlikely(next == qp->s_tail_ack_queue)) {
  1834. if (!qp->s_ack_queue[next].sent)
  1835. goto nack_inv_unlck;
  1836. qib_update_ack_queue(qp, next);
  1837. }
  1838. e = &qp->s_ack_queue[qp->r_head_ack_queue];
  1839. if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
  1840. rvt_put_mr(e->rdma_sge.mr);
  1841. e->rdma_sge.mr = NULL;
  1842. }
  1843. reth = &ohdr->u.rc.reth;
  1844. len = be32_to_cpu(reth->length);
  1845. if (len) {
  1846. u32 rkey = be32_to_cpu(reth->rkey);
  1847. u64 vaddr = be64_to_cpu(reth->vaddr);
  1848. int ok;
  1849. /* Check rkey & NAK */
  1850. ok = rvt_rkey_ok(qp, &e->rdma_sge, len, vaddr,
  1851. rkey, IB_ACCESS_REMOTE_READ);
  1852. if (unlikely(!ok))
  1853. goto nack_acc_unlck;
  1854. /*
  1855. * Update the next expected PSN. We add 1 later
  1856. * below, so only add the remainder here.
  1857. */
  1858. qp->r_psn += rvt_div_mtu(qp, len - 1);
  1859. } else {
  1860. e->rdma_sge.mr = NULL;
  1861. e->rdma_sge.vaddr = NULL;
  1862. e->rdma_sge.length = 0;
  1863. e->rdma_sge.sge_length = 0;
  1864. }
  1865. e->opcode = opcode;
  1866. e->sent = 0;
  1867. e->psn = psn;
  1868. e->lpsn = qp->r_psn;
  1869. /*
  1870. * We need to increment the MSN here instead of when we
  1871. * finish sending the result since a duplicate request would
  1872. * increment it more than once.
  1873. */
  1874. qp->r_msn++;
  1875. qp->r_psn++;
  1876. qp->r_state = opcode;
  1877. qp->r_nak_state = 0;
  1878. qp->r_head_ack_queue = next;
  1879. /* Schedule the send tasklet. */
  1880. qp->s_flags |= RVT_S_RESP_PENDING;
  1881. qib_schedule_send(qp);
  1882. goto sunlock;
  1883. }
  1884. case OP(COMPARE_SWAP):
  1885. case OP(FETCH_ADD): {
  1886. struct ib_atomic_eth *ateth;
  1887. struct rvt_ack_entry *e;
  1888. u64 vaddr;
  1889. atomic64_t *maddr;
  1890. u64 sdata;
  1891. u32 rkey;
  1892. u8 next;
  1893. if (unlikely(!(qp->qp_access_flags & IB_ACCESS_REMOTE_ATOMIC)))
  1894. goto nack_inv;
  1895. next = qp->r_head_ack_queue + 1;
  1896. if (next > QIB_MAX_RDMA_ATOMIC)
  1897. next = 0;
  1898. spin_lock_irqsave(&qp->s_lock, flags);
  1899. if (unlikely(next == qp->s_tail_ack_queue)) {
  1900. if (!qp->s_ack_queue[next].sent)
  1901. goto nack_inv_unlck;
  1902. qib_update_ack_queue(qp, next);
  1903. }
  1904. e = &qp->s_ack_queue[qp->r_head_ack_queue];
  1905. if (e->opcode == OP(RDMA_READ_REQUEST) && e->rdma_sge.mr) {
  1906. rvt_put_mr(e->rdma_sge.mr);
  1907. e->rdma_sge.mr = NULL;
  1908. }
  1909. ateth = &ohdr->u.atomic_eth;
  1910. vaddr = get_ib_ateth_vaddr(ateth);
  1911. if (unlikely(vaddr & (sizeof(u64) - 1)))
  1912. goto nack_inv_unlck;
  1913. rkey = be32_to_cpu(ateth->rkey);
  1914. /* Check rkey & NAK */
  1915. if (unlikely(!rvt_rkey_ok(qp, &qp->r_sge.sge, sizeof(u64),
  1916. vaddr, rkey,
  1917. IB_ACCESS_REMOTE_ATOMIC)))
  1918. goto nack_acc_unlck;
  1919. /* Perform atomic OP and save result. */
  1920. maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
  1921. sdata = get_ib_ateth_swap(ateth);
  1922. e->atomic_data = (opcode == OP(FETCH_ADD)) ?
  1923. (u64) atomic64_add_return(sdata, maddr) - sdata :
  1924. (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
  1925. get_ib_ateth_compare(ateth),
  1926. sdata);
  1927. rvt_put_mr(qp->r_sge.sge.mr);
  1928. qp->r_sge.num_sge = 0;
  1929. e->opcode = opcode;
  1930. e->sent = 0;
  1931. e->psn = psn;
  1932. e->lpsn = psn;
  1933. qp->r_msn++;
  1934. qp->r_psn++;
  1935. qp->r_state = opcode;
  1936. qp->r_nak_state = 0;
  1937. qp->r_head_ack_queue = next;
  1938. /* Schedule the send tasklet. */
  1939. qp->s_flags |= RVT_S_RESP_PENDING;
  1940. qib_schedule_send(qp);
  1941. goto sunlock;
  1942. }
  1943. default:
  1944. /* NAK unknown opcodes. */
  1945. goto nack_inv;
  1946. }
  1947. qp->r_psn++;
  1948. qp->r_state = opcode;
  1949. qp->r_ack_psn = psn;
  1950. qp->r_nak_state = 0;
  1951. /* Send an ACK if requested or required. */
  1952. if (psn & (1 << 31))
  1953. goto send_ack;
  1954. return;
  1955. rnr_nak:
  1956. qp->r_nak_state = IB_RNR_NAK | qp->r_min_rnr_timer;
  1957. qp->r_ack_psn = qp->r_psn;
  1958. /* Queue RNR NAK for later */
  1959. if (list_empty(&qp->rspwait)) {
  1960. qp->r_flags |= RVT_R_RSP_NAK;
  1961. rvt_get_qp(qp);
  1962. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1963. }
  1964. return;
  1965. nack_op_err:
  1966. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  1967. qp->r_nak_state = IB_NAK_REMOTE_OPERATIONAL_ERROR;
  1968. qp->r_ack_psn = qp->r_psn;
  1969. /* Queue NAK for later */
  1970. if (list_empty(&qp->rspwait)) {
  1971. qp->r_flags |= RVT_R_RSP_NAK;
  1972. rvt_get_qp(qp);
  1973. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1974. }
  1975. return;
  1976. nack_inv_unlck:
  1977. spin_unlock_irqrestore(&qp->s_lock, flags);
  1978. nack_inv:
  1979. rvt_rc_error(qp, IB_WC_LOC_QP_OP_ERR);
  1980. qp->r_nak_state = IB_NAK_INVALID_REQUEST;
  1981. qp->r_ack_psn = qp->r_psn;
  1982. /* Queue NAK for later */
  1983. if (list_empty(&qp->rspwait)) {
  1984. qp->r_flags |= RVT_R_RSP_NAK;
  1985. rvt_get_qp(qp);
  1986. list_add_tail(&qp->rspwait, &rcd->qp_wait_list);
  1987. }
  1988. return;
  1989. nack_acc_unlck:
  1990. spin_unlock_irqrestore(&qp->s_lock, flags);
  1991. nack_acc:
  1992. rvt_rc_error(qp, IB_WC_LOC_PROT_ERR);
  1993. qp->r_nak_state = IB_NAK_REMOTE_ACCESS_ERROR;
  1994. qp->r_ack_psn = qp->r_psn;
  1995. send_ack:
  1996. qib_send_rc_ack(qp);
  1997. return;
  1998. sunlock:
  1999. spin_unlock_irqrestore(&qp->s_lock, flags);
  2000. }