qib_rc.c 57 KB

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