qib_rc.c 57 KB

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