ipath_rc.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  1. /*
  2. * Copyright (c) 2006 QLogic, Inc. 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 "ipath_verbs.h"
  34. #include "ips_common.h"
  35. /* cut down ridiculously long IB macro names */
  36. #define OP(x) IB_OPCODE_RC_##x
  37. /**
  38. * ipath_init_restart- initialize the qp->s_sge after a restart
  39. * @qp: the QP who's SGE we're restarting
  40. * @wqe: the work queue to initialize the QP's SGE from
  41. *
  42. * The QP s_lock should be held.
  43. */
  44. static void ipath_init_restart(struct ipath_qp *qp, struct ipath_swqe *wqe)
  45. {
  46. struct ipath_ibdev *dev;
  47. u32 len;
  48. len = ((qp->s_psn - wqe->psn) & IPS_PSN_MASK) *
  49. ib_mtu_enum_to_int(qp->path_mtu);
  50. qp->s_sge.sge = wqe->sg_list[0];
  51. qp->s_sge.sg_list = wqe->sg_list + 1;
  52. qp->s_sge.num_sge = wqe->wr.num_sge;
  53. ipath_skip_sge(&qp->s_sge, len);
  54. qp->s_len = wqe->length - len;
  55. dev = to_idev(qp->ibqp.device);
  56. spin_lock(&dev->pending_lock);
  57. if (list_empty(&qp->timerwait))
  58. list_add_tail(&qp->timerwait,
  59. &dev->pending[dev->pending_index]);
  60. spin_unlock(&dev->pending_lock);
  61. }
  62. /**
  63. * ipath_make_rc_ack - construct a response packet (ACK, NAK, or RDMA read)
  64. * @qp: a pointer to the QP
  65. * @ohdr: a pointer to the IB header being constructed
  66. * @pmtu: the path MTU
  67. *
  68. * Return bth0 if constructed; otherwise, return 0.
  69. * Note the QP s_lock must be held.
  70. */
  71. u32 ipath_make_rc_ack(struct ipath_qp *qp,
  72. struct ipath_other_headers *ohdr,
  73. u32 pmtu)
  74. {
  75. struct ipath_sge_state *ss;
  76. u32 hwords;
  77. u32 len;
  78. u32 bth0;
  79. /* header size in 32-bit words LRH+BTH = (8+12)/4. */
  80. hwords = 5;
  81. /*
  82. * Send a response. Note that we are in the responder's
  83. * side of the QP context.
  84. */
  85. switch (qp->s_ack_state) {
  86. case OP(RDMA_READ_REQUEST):
  87. ss = &qp->s_rdma_sge;
  88. len = qp->s_rdma_len;
  89. if (len > pmtu) {
  90. len = pmtu;
  91. qp->s_ack_state = OP(RDMA_READ_RESPONSE_FIRST);
  92. } else
  93. qp->s_ack_state = OP(RDMA_READ_RESPONSE_ONLY);
  94. qp->s_rdma_len -= len;
  95. bth0 = qp->s_ack_state << 24;
  96. ohdr->u.aeth = ipath_compute_aeth(qp);
  97. hwords++;
  98. break;
  99. case OP(RDMA_READ_RESPONSE_FIRST):
  100. qp->s_ack_state = OP(RDMA_READ_RESPONSE_MIDDLE);
  101. /* FALLTHROUGH */
  102. case OP(RDMA_READ_RESPONSE_MIDDLE):
  103. ss = &qp->s_rdma_sge;
  104. len = qp->s_rdma_len;
  105. if (len > pmtu)
  106. len = pmtu;
  107. else {
  108. ohdr->u.aeth = ipath_compute_aeth(qp);
  109. hwords++;
  110. qp->s_ack_state = OP(RDMA_READ_RESPONSE_LAST);
  111. }
  112. qp->s_rdma_len -= len;
  113. bth0 = qp->s_ack_state << 24;
  114. break;
  115. case OP(RDMA_READ_RESPONSE_LAST):
  116. case OP(RDMA_READ_RESPONSE_ONLY):
  117. /*
  118. * We have to prevent new requests from changing
  119. * the r_sge state while a ipath_verbs_send()
  120. * is in progress.
  121. * Changing r_state allows the receiver
  122. * to continue processing new packets.
  123. * We do it here now instead of above so
  124. * that we are sure the packet was sent before
  125. * changing the state.
  126. */
  127. qp->r_state = OP(RDMA_READ_RESPONSE_LAST);
  128. qp->s_ack_state = OP(ACKNOWLEDGE);
  129. return 0;
  130. case OP(COMPARE_SWAP):
  131. case OP(FETCH_ADD):
  132. ss = NULL;
  133. len = 0;
  134. qp->r_state = OP(SEND_LAST);
  135. qp->s_ack_state = OP(ACKNOWLEDGE);
  136. bth0 = IB_OPCODE_ATOMIC_ACKNOWLEDGE << 24;
  137. ohdr->u.at.aeth = ipath_compute_aeth(qp);
  138. ohdr->u.at.atomic_ack_eth = cpu_to_be64(qp->s_ack_atomic);
  139. hwords += sizeof(ohdr->u.at) / 4;
  140. break;
  141. default:
  142. /* Send a regular ACK. */
  143. ss = NULL;
  144. len = 0;
  145. qp->s_ack_state = OP(ACKNOWLEDGE);
  146. bth0 = qp->s_ack_state << 24;
  147. ohdr->u.aeth = ipath_compute_aeth(qp);
  148. hwords++;
  149. }
  150. qp->s_hdrwords = hwords;
  151. qp->s_cur_sge = ss;
  152. qp->s_cur_size = len;
  153. return bth0;
  154. }
  155. /**
  156. * ipath_make_rc_req - construct a request packet (SEND, RDMA r/w, ATOMIC)
  157. * @qp: a pointer to the QP
  158. * @ohdr: a pointer to the IB header being constructed
  159. * @pmtu: the path MTU
  160. * @bth0p: pointer to the BTH opcode word
  161. * @bth2p: pointer to the BTH PSN word
  162. *
  163. * Return 1 if constructed; otherwise, return 0.
  164. * Note the QP s_lock must be held.
  165. */
  166. int ipath_make_rc_req(struct ipath_qp *qp,
  167. struct ipath_other_headers *ohdr,
  168. u32 pmtu, u32 *bth0p, u32 *bth2p)
  169. {
  170. struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
  171. struct ipath_sge_state *ss;
  172. struct ipath_swqe *wqe;
  173. u32 hwords;
  174. u32 len;
  175. u32 bth0;
  176. u32 bth2;
  177. char newreq;
  178. if (!(ib_ipath_state_ops[qp->state] & IPATH_PROCESS_SEND_OK) ||
  179. qp->s_rnr_timeout)
  180. goto done;
  181. /* header size in 32-bit words LRH+BTH = (8+12)/4. */
  182. hwords = 5;
  183. bth0 = 0;
  184. /* Send a request. */
  185. wqe = get_swqe_ptr(qp, qp->s_cur);
  186. switch (qp->s_state) {
  187. default:
  188. /*
  189. * Resend an old request or start a new one.
  190. *
  191. * We keep track of the current SWQE so that
  192. * we don't reset the "furthest progress" state
  193. * if we need to back up.
  194. */
  195. newreq = 0;
  196. if (qp->s_cur == qp->s_tail) {
  197. /* Check if send work queue is empty. */
  198. if (qp->s_tail == qp->s_head)
  199. goto done;
  200. qp->s_psn = wqe->psn = qp->s_next_psn;
  201. newreq = 1;
  202. }
  203. /*
  204. * Note that we have to be careful not to modify the
  205. * original work request since we may need to resend
  206. * it.
  207. */
  208. qp->s_sge.sge = wqe->sg_list[0];
  209. qp->s_sge.sg_list = wqe->sg_list + 1;
  210. qp->s_sge.num_sge = wqe->wr.num_sge;
  211. qp->s_len = len = wqe->length;
  212. ss = &qp->s_sge;
  213. bth2 = 0;
  214. switch (wqe->wr.opcode) {
  215. case IB_WR_SEND:
  216. case IB_WR_SEND_WITH_IMM:
  217. /* If no credit, return. */
  218. if (qp->s_lsn != (u32) -1 &&
  219. ipath_cmp24(wqe->ssn, qp->s_lsn + 1) > 0)
  220. goto done;
  221. wqe->lpsn = wqe->psn;
  222. if (len > pmtu) {
  223. wqe->lpsn += (len - 1) / pmtu;
  224. qp->s_state = OP(SEND_FIRST);
  225. len = pmtu;
  226. break;
  227. }
  228. if (wqe->wr.opcode == IB_WR_SEND)
  229. qp->s_state = OP(SEND_ONLY);
  230. else {
  231. qp->s_state = OP(SEND_ONLY_WITH_IMMEDIATE);
  232. /* Immediate data comes after the BTH */
  233. ohdr->u.imm_data = wqe->wr.imm_data;
  234. hwords += 1;
  235. }
  236. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  237. bth0 |= 1 << 23;
  238. bth2 = 1 << 31; /* Request ACK. */
  239. if (++qp->s_cur == qp->s_size)
  240. qp->s_cur = 0;
  241. break;
  242. case IB_WR_RDMA_WRITE:
  243. if (newreq && qp->s_lsn != (u32) -1)
  244. qp->s_lsn++;
  245. /* FALLTHROUGH */
  246. case IB_WR_RDMA_WRITE_WITH_IMM:
  247. /* If no credit, return. */
  248. if (qp->s_lsn != (u32) -1 &&
  249. ipath_cmp24(wqe->ssn, qp->s_lsn + 1) > 0)
  250. goto done;
  251. ohdr->u.rc.reth.vaddr =
  252. cpu_to_be64(wqe->wr.wr.rdma.remote_addr);
  253. ohdr->u.rc.reth.rkey =
  254. cpu_to_be32(wqe->wr.wr.rdma.rkey);
  255. ohdr->u.rc.reth.length = cpu_to_be32(len);
  256. hwords += sizeof(struct ib_reth) / 4;
  257. wqe->lpsn = wqe->psn;
  258. if (len > pmtu) {
  259. wqe->lpsn += (len - 1) / pmtu;
  260. qp->s_state = OP(RDMA_WRITE_FIRST);
  261. len = pmtu;
  262. break;
  263. }
  264. if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
  265. qp->s_state = OP(RDMA_WRITE_ONLY);
  266. else {
  267. qp->s_state =
  268. OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE);
  269. /* Immediate data comes after RETH */
  270. ohdr->u.rc.imm_data = wqe->wr.imm_data;
  271. hwords += 1;
  272. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  273. bth0 |= 1 << 23;
  274. }
  275. bth2 = 1 << 31; /* Request ACK. */
  276. if (++qp->s_cur == qp->s_size)
  277. qp->s_cur = 0;
  278. break;
  279. case IB_WR_RDMA_READ:
  280. ohdr->u.rc.reth.vaddr =
  281. cpu_to_be64(wqe->wr.wr.rdma.remote_addr);
  282. ohdr->u.rc.reth.rkey =
  283. cpu_to_be32(wqe->wr.wr.rdma.rkey);
  284. ohdr->u.rc.reth.length = cpu_to_be32(len);
  285. qp->s_state = OP(RDMA_READ_REQUEST);
  286. hwords += sizeof(ohdr->u.rc.reth) / 4;
  287. if (newreq) {
  288. if (qp->s_lsn != (u32) -1)
  289. qp->s_lsn++;
  290. /*
  291. * Adjust s_next_psn to count the
  292. * expected number of responses.
  293. */
  294. if (len > pmtu)
  295. qp->s_next_psn += (len - 1) / pmtu;
  296. wqe->lpsn = qp->s_next_psn++;
  297. }
  298. ss = NULL;
  299. len = 0;
  300. if (++qp->s_cur == qp->s_size)
  301. qp->s_cur = 0;
  302. break;
  303. case IB_WR_ATOMIC_CMP_AND_SWP:
  304. case IB_WR_ATOMIC_FETCH_AND_ADD:
  305. if (wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP)
  306. qp->s_state = OP(COMPARE_SWAP);
  307. else
  308. qp->s_state = OP(FETCH_ADD);
  309. ohdr->u.atomic_eth.vaddr = cpu_to_be64(
  310. wqe->wr.wr.atomic.remote_addr);
  311. ohdr->u.atomic_eth.rkey = cpu_to_be32(
  312. wqe->wr.wr.atomic.rkey);
  313. ohdr->u.atomic_eth.swap_data = cpu_to_be64(
  314. wqe->wr.wr.atomic.swap);
  315. ohdr->u.atomic_eth.compare_data = cpu_to_be64(
  316. wqe->wr.wr.atomic.compare_add);
  317. hwords += sizeof(struct ib_atomic_eth) / 4;
  318. if (newreq) {
  319. if (qp->s_lsn != (u32) -1)
  320. qp->s_lsn++;
  321. wqe->lpsn = wqe->psn;
  322. }
  323. if (++qp->s_cur == qp->s_size)
  324. qp->s_cur = 0;
  325. ss = NULL;
  326. len = 0;
  327. break;
  328. default:
  329. goto done;
  330. }
  331. if (newreq) {
  332. qp->s_tail++;
  333. if (qp->s_tail >= qp->s_size)
  334. qp->s_tail = 0;
  335. }
  336. bth2 |= qp->s_psn++ & IPS_PSN_MASK;
  337. if ((int)(qp->s_psn - qp->s_next_psn) > 0)
  338. qp->s_next_psn = qp->s_psn;
  339. spin_lock(&dev->pending_lock);
  340. if (list_empty(&qp->timerwait))
  341. list_add_tail(&qp->timerwait,
  342. &dev->pending[dev->pending_index]);
  343. spin_unlock(&dev->pending_lock);
  344. break;
  345. case OP(RDMA_READ_RESPONSE_FIRST):
  346. /*
  347. * This case can only happen if a send is restarted. See
  348. * ipath_restart_rc().
  349. */
  350. ipath_init_restart(qp, wqe);
  351. /* FALLTHROUGH */
  352. case OP(SEND_FIRST):
  353. qp->s_state = OP(SEND_MIDDLE);
  354. /* FALLTHROUGH */
  355. case OP(SEND_MIDDLE):
  356. bth2 = qp->s_psn++ & IPS_PSN_MASK;
  357. if ((int)(qp->s_psn - qp->s_next_psn) > 0)
  358. qp->s_next_psn = qp->s_psn;
  359. ss = &qp->s_sge;
  360. len = qp->s_len;
  361. if (len > pmtu) {
  362. /*
  363. * Request an ACK every 1/2 MB to avoid retransmit
  364. * timeouts.
  365. */
  366. if (((wqe->length - len) % (512 * 1024)) == 0)
  367. bth2 |= 1 << 31;
  368. len = pmtu;
  369. break;
  370. }
  371. if (wqe->wr.opcode == IB_WR_SEND)
  372. qp->s_state = OP(SEND_LAST);
  373. else {
  374. qp->s_state = OP(SEND_LAST_WITH_IMMEDIATE);
  375. /* Immediate data comes after the BTH */
  376. ohdr->u.imm_data = wqe->wr.imm_data;
  377. hwords += 1;
  378. }
  379. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  380. bth0 |= 1 << 23;
  381. bth2 |= 1 << 31; /* Request ACK. */
  382. qp->s_cur++;
  383. if (qp->s_cur >= qp->s_size)
  384. qp->s_cur = 0;
  385. break;
  386. case OP(RDMA_READ_RESPONSE_LAST):
  387. /*
  388. * This case can only happen if a RDMA write is restarted.
  389. * See ipath_restart_rc().
  390. */
  391. ipath_init_restart(qp, wqe);
  392. /* FALLTHROUGH */
  393. case OP(RDMA_WRITE_FIRST):
  394. qp->s_state = OP(RDMA_WRITE_MIDDLE);
  395. /* FALLTHROUGH */
  396. case OP(RDMA_WRITE_MIDDLE):
  397. bth2 = qp->s_psn++ & IPS_PSN_MASK;
  398. if ((int)(qp->s_psn - qp->s_next_psn) > 0)
  399. qp->s_next_psn = qp->s_psn;
  400. ss = &qp->s_sge;
  401. len = qp->s_len;
  402. if (len > pmtu) {
  403. /*
  404. * Request an ACK every 1/2 MB to avoid retransmit
  405. * timeouts.
  406. */
  407. if (((wqe->length - len) % (512 * 1024)) == 0)
  408. bth2 |= 1 << 31;
  409. len = pmtu;
  410. break;
  411. }
  412. if (wqe->wr.opcode == IB_WR_RDMA_WRITE)
  413. qp->s_state = OP(RDMA_WRITE_LAST);
  414. else {
  415. qp->s_state = OP(RDMA_WRITE_LAST_WITH_IMMEDIATE);
  416. /* Immediate data comes after the BTH */
  417. ohdr->u.imm_data = wqe->wr.imm_data;
  418. hwords += 1;
  419. if (wqe->wr.send_flags & IB_SEND_SOLICITED)
  420. bth0 |= 1 << 23;
  421. }
  422. bth2 |= 1 << 31; /* Request ACK. */
  423. qp->s_cur++;
  424. if (qp->s_cur >= qp->s_size)
  425. qp->s_cur = 0;
  426. break;
  427. case OP(RDMA_READ_RESPONSE_MIDDLE):
  428. /*
  429. * This case can only happen if a RDMA read is restarted.
  430. * See ipath_restart_rc().
  431. */
  432. ipath_init_restart(qp, wqe);
  433. len = ((qp->s_psn - wqe->psn) & IPS_PSN_MASK) * pmtu;
  434. ohdr->u.rc.reth.vaddr =
  435. cpu_to_be64(wqe->wr.wr.rdma.remote_addr + len);
  436. ohdr->u.rc.reth.rkey =
  437. cpu_to_be32(wqe->wr.wr.rdma.rkey);
  438. ohdr->u.rc.reth.length = cpu_to_be32(qp->s_len);
  439. qp->s_state = OP(RDMA_READ_REQUEST);
  440. hwords += sizeof(ohdr->u.rc.reth) / 4;
  441. bth2 = qp->s_psn++ & IPS_PSN_MASK;
  442. if ((int)(qp->s_psn - qp->s_next_psn) > 0)
  443. qp->s_next_psn = qp->s_psn;
  444. ss = NULL;
  445. len = 0;
  446. qp->s_cur++;
  447. if (qp->s_cur == qp->s_size)
  448. qp->s_cur = 0;
  449. break;
  450. case OP(RDMA_READ_REQUEST):
  451. case OP(COMPARE_SWAP):
  452. case OP(FETCH_ADD):
  453. /*
  454. * We shouldn't start anything new until this request is
  455. * finished. The ACK will handle rescheduling us. XXX The
  456. * number of outstanding ones is negotiated at connection
  457. * setup time (see pg. 258,289)? XXX Also, if we support
  458. * multiple outstanding requests, we need to check the WQE
  459. * IB_SEND_FENCE flag and not send a new request if a RDMA
  460. * read or atomic is pending.
  461. */
  462. goto done;
  463. }
  464. qp->s_len -= len;
  465. qp->s_hdrwords = hwords;
  466. qp->s_cur_sge = ss;
  467. qp->s_cur_size = len;
  468. *bth0p = bth0 | (qp->s_state << 24);
  469. *bth2p = bth2;
  470. return 1;
  471. done:
  472. return 0;
  473. }
  474. /**
  475. * send_rc_ack - Construct an ACK packet and send it
  476. * @qp: a pointer to the QP
  477. *
  478. * This is called from ipath_rc_rcv() and only uses the receive
  479. * side QP state.
  480. * Note that RDMA reads are handled in the send side QP state and tasklet.
  481. */
  482. static void send_rc_ack(struct ipath_qp *qp)
  483. {
  484. struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
  485. u16 lrh0;
  486. u32 bth0;
  487. u32 hwords;
  488. struct ipath_ib_header hdr;
  489. struct ipath_other_headers *ohdr;
  490. /* Construct the header. */
  491. ohdr = &hdr.u.oth;
  492. lrh0 = IPS_LRH_BTH;
  493. /* header size in 32-bit words LRH+BTH+AETH = (8+12+4)/4. */
  494. hwords = 6;
  495. if (unlikely(qp->remote_ah_attr.ah_flags & IB_AH_GRH)) {
  496. hwords += ipath_make_grh(dev, &hdr.u.l.grh,
  497. &qp->remote_ah_attr.grh,
  498. hwords, 0);
  499. ohdr = &hdr.u.l.oth;
  500. lrh0 = IPS_LRH_GRH;
  501. }
  502. bth0 = ipath_layer_get_pkey(dev->dd, qp->s_pkey_index);
  503. ohdr->u.aeth = ipath_compute_aeth(qp);
  504. if (qp->s_ack_state >= OP(COMPARE_SWAP)) {
  505. bth0 |= IB_OPCODE_ATOMIC_ACKNOWLEDGE << 24;
  506. ohdr->u.at.atomic_ack_eth = cpu_to_be64(qp->s_ack_atomic);
  507. hwords += sizeof(ohdr->u.at.atomic_ack_eth) / 4;
  508. } else
  509. bth0 |= OP(ACKNOWLEDGE) << 24;
  510. lrh0 |= qp->remote_ah_attr.sl << 4;
  511. hdr.lrh[0] = cpu_to_be16(lrh0);
  512. hdr.lrh[1] = cpu_to_be16(qp->remote_ah_attr.dlid);
  513. hdr.lrh[2] = cpu_to_be16(hwords + SIZE_OF_CRC);
  514. hdr.lrh[3] = cpu_to_be16(ipath_layer_get_lid(dev->dd));
  515. ohdr->bth[0] = cpu_to_be32(bth0);
  516. ohdr->bth[1] = cpu_to_be32(qp->remote_qpn);
  517. ohdr->bth[2] = cpu_to_be32(qp->s_ack_psn & IPS_PSN_MASK);
  518. /*
  519. * If we can send the ACK, clear the ACK state.
  520. */
  521. if (ipath_verbs_send(dev->dd, hwords, (u32 *) &hdr, 0, NULL) == 0) {
  522. qp->s_ack_state = OP(ACKNOWLEDGE);
  523. dev->n_rc_qacks++;
  524. dev->n_unicast_xmit++;
  525. }
  526. }
  527. /**
  528. * reset_psn - reset the QP state to send starting from PSN
  529. * @qp: the QP
  530. * @psn: the packet sequence number to restart at
  531. *
  532. * This is called from ipath_rc_rcv() to process an incoming RC ACK
  533. * for the given QP.
  534. * Called at interrupt level with the QP s_lock held.
  535. */
  536. static void reset_psn(struct ipath_qp *qp, u32 psn)
  537. {
  538. u32 n = qp->s_last;
  539. struct ipath_swqe *wqe = get_swqe_ptr(qp, n);
  540. u32 opcode;
  541. qp->s_cur = n;
  542. /*
  543. * If we are starting the request from the beginning,
  544. * let the normal send code handle initialization.
  545. */
  546. if (ipath_cmp24(psn, wqe->psn) <= 0) {
  547. qp->s_state = OP(SEND_LAST);
  548. goto done;
  549. }
  550. /* Find the work request opcode corresponding to the given PSN. */
  551. opcode = wqe->wr.opcode;
  552. for (;;) {
  553. int diff;
  554. if (++n == qp->s_size)
  555. n = 0;
  556. if (n == qp->s_tail)
  557. break;
  558. wqe = get_swqe_ptr(qp, n);
  559. diff = ipath_cmp24(psn, wqe->psn);
  560. if (diff < 0)
  561. break;
  562. qp->s_cur = n;
  563. /*
  564. * If we are starting the request from the beginning,
  565. * let the normal send code handle initialization.
  566. */
  567. if (diff == 0) {
  568. qp->s_state = OP(SEND_LAST);
  569. goto done;
  570. }
  571. opcode = wqe->wr.opcode;
  572. }
  573. /*
  574. * Set the state to restart in the middle of a request.
  575. * Don't change the s_sge, s_cur_sge, or s_cur_size.
  576. * See ipath_do_rc_send().
  577. */
  578. switch (opcode) {
  579. case IB_WR_SEND:
  580. case IB_WR_SEND_WITH_IMM:
  581. qp->s_state = OP(RDMA_READ_RESPONSE_FIRST);
  582. break;
  583. case IB_WR_RDMA_WRITE:
  584. case IB_WR_RDMA_WRITE_WITH_IMM:
  585. qp->s_state = OP(RDMA_READ_RESPONSE_LAST);
  586. break;
  587. case IB_WR_RDMA_READ:
  588. qp->s_state = OP(RDMA_READ_RESPONSE_MIDDLE);
  589. break;
  590. default:
  591. /*
  592. * This case shouldn't happen since its only
  593. * one PSN per req.
  594. */
  595. qp->s_state = OP(SEND_LAST);
  596. }
  597. done:
  598. qp->s_psn = psn;
  599. }
  600. /**
  601. * ipath_restart_rc - back up requester to resend the last un-ACKed request
  602. * @qp: the QP to restart
  603. * @psn: packet sequence number for the request
  604. * @wc: the work completion request
  605. *
  606. * The QP s_lock should be held.
  607. */
  608. void ipath_restart_rc(struct ipath_qp *qp, u32 psn, struct ib_wc *wc)
  609. {
  610. struct ipath_swqe *wqe = get_swqe_ptr(qp, qp->s_last);
  611. struct ipath_ibdev *dev;
  612. /*
  613. * If there are no requests pending, we are done.
  614. */
  615. if (ipath_cmp24(psn, qp->s_next_psn) >= 0 ||
  616. qp->s_last == qp->s_tail)
  617. goto done;
  618. if (qp->s_retry == 0) {
  619. wc->wr_id = wqe->wr.wr_id;
  620. wc->status = IB_WC_RETRY_EXC_ERR;
  621. wc->opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
  622. wc->vendor_err = 0;
  623. wc->byte_len = 0;
  624. wc->qp_num = qp->ibqp.qp_num;
  625. wc->src_qp = qp->remote_qpn;
  626. wc->pkey_index = 0;
  627. wc->slid = qp->remote_ah_attr.dlid;
  628. wc->sl = qp->remote_ah_attr.sl;
  629. wc->dlid_path_bits = 0;
  630. wc->port_num = 0;
  631. ipath_sqerror_qp(qp, wc);
  632. goto bail;
  633. }
  634. qp->s_retry--;
  635. /*
  636. * Remove the QP from the timeout queue.
  637. * Note: it may already have been removed by ipath_ib_timer().
  638. */
  639. dev = to_idev(qp->ibqp.device);
  640. spin_lock(&dev->pending_lock);
  641. if (!list_empty(&qp->timerwait))
  642. list_del_init(&qp->timerwait);
  643. spin_unlock(&dev->pending_lock);
  644. if (wqe->wr.opcode == IB_WR_RDMA_READ)
  645. dev->n_rc_resends++;
  646. else
  647. dev->n_rc_resends += (int)qp->s_psn - (int)psn;
  648. reset_psn(qp, psn);
  649. done:
  650. tasklet_hi_schedule(&qp->s_task);
  651. bail:
  652. return;
  653. }
  654. /**
  655. * do_rc_ack - process an incoming RC ACK
  656. * @qp: the QP the ACK came in on
  657. * @psn: the packet sequence number of the ACK
  658. * @opcode: the opcode of the request that resulted in the ACK
  659. *
  660. * This is called from ipath_rc_rcv_resp() to process an incoming RC ACK
  661. * for the given QP.
  662. * Called at interrupt level with the QP s_lock held.
  663. * Returns 1 if OK, 0 if current operation should be aborted (NAK).
  664. */
  665. static int do_rc_ack(struct ipath_qp *qp, u32 aeth, u32 psn, int opcode)
  666. {
  667. struct ipath_ibdev *dev = to_idev(qp->ibqp.device);
  668. struct ib_wc wc;
  669. struct ipath_swqe *wqe;
  670. int ret = 0;
  671. /*
  672. * Remove the QP from the timeout queue (or RNR timeout queue).
  673. * If ipath_ib_timer() has already removed it,
  674. * it's OK since we hold the QP s_lock and ipath_restart_rc()
  675. * just won't find anything to restart if we ACK everything.
  676. */
  677. spin_lock(&dev->pending_lock);
  678. if (!list_empty(&qp->timerwait))
  679. list_del_init(&qp->timerwait);
  680. spin_unlock(&dev->pending_lock);
  681. /*
  682. * Note that NAKs implicitly ACK outstanding SEND and RDMA write
  683. * requests and implicitly NAK RDMA read and atomic requests issued
  684. * before the NAK'ed request. The MSN won't include the NAK'ed
  685. * request but will include an ACK'ed request(s).
  686. */
  687. wqe = get_swqe_ptr(qp, qp->s_last);
  688. /* Nothing is pending to ACK/NAK. */
  689. if (qp->s_last == qp->s_tail)
  690. goto bail;
  691. /*
  692. * The MSN might be for a later WQE than the PSN indicates so
  693. * only complete WQEs that the PSN finishes.
  694. */
  695. while (ipath_cmp24(psn, wqe->lpsn) >= 0) {
  696. /* If we are ACKing a WQE, the MSN should be >= the SSN. */
  697. if (ipath_cmp24(aeth, wqe->ssn) < 0)
  698. break;
  699. /*
  700. * If this request is a RDMA read or atomic, and the ACK is
  701. * for a later operation, this ACK NAKs the RDMA read or
  702. * atomic. In other words, only a RDMA_READ_LAST or ONLY
  703. * can ACK a RDMA read and likewise for atomic ops. Note
  704. * that the NAK case can only happen if relaxed ordering is
  705. * used and requests are sent after an RDMA read or atomic
  706. * is sent but before the response is received.
  707. */
  708. if ((wqe->wr.opcode == IB_WR_RDMA_READ &&
  709. opcode != OP(RDMA_READ_RESPONSE_LAST)) ||
  710. ((wqe->wr.opcode == IB_WR_ATOMIC_CMP_AND_SWP ||
  711. wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) &&
  712. (opcode != OP(ATOMIC_ACKNOWLEDGE) ||
  713. ipath_cmp24(wqe->psn, psn) != 0))) {
  714. /*
  715. * The last valid PSN seen is the previous
  716. * request's.
  717. */
  718. qp->s_last_psn = wqe->psn - 1;
  719. /* Retry this request. */
  720. ipath_restart_rc(qp, wqe->psn, &wc);
  721. /*
  722. * No need to process the ACK/NAK since we are
  723. * restarting an earlier request.
  724. */
  725. goto bail;
  726. }
  727. /* Post a send completion queue entry if requested. */
  728. if (!test_bit(IPATH_S_SIGNAL_REQ_WR, &qp->s_flags) ||
  729. (wqe->wr.send_flags & IB_SEND_SIGNALED)) {
  730. wc.wr_id = wqe->wr.wr_id;
  731. wc.status = IB_WC_SUCCESS;
  732. wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
  733. wc.vendor_err = 0;
  734. wc.byte_len = wqe->length;
  735. wc.qp_num = qp->ibqp.qp_num;
  736. wc.src_qp = qp->remote_qpn;
  737. wc.pkey_index = 0;
  738. wc.slid = qp->remote_ah_attr.dlid;
  739. wc.sl = qp->remote_ah_attr.sl;
  740. wc.dlid_path_bits = 0;
  741. wc.port_num = 0;
  742. ipath_cq_enter(to_icq(qp->ibqp.send_cq), &wc, 0);
  743. }
  744. qp->s_retry = qp->s_retry_cnt;
  745. /*
  746. * If we are completing a request which is in the process of
  747. * being resent, we can stop resending it since we know the
  748. * responder has already seen it.
  749. */
  750. if (qp->s_last == qp->s_cur) {
  751. if (++qp->s_cur >= qp->s_size)
  752. qp->s_cur = 0;
  753. wqe = get_swqe_ptr(qp, qp->s_cur);
  754. qp->s_state = OP(SEND_LAST);
  755. qp->s_psn = wqe->psn;
  756. }
  757. if (++qp->s_last >= qp->s_size)
  758. qp->s_last = 0;
  759. wqe = get_swqe_ptr(qp, qp->s_last);
  760. if (qp->s_last == qp->s_tail)
  761. break;
  762. }
  763. switch (aeth >> 29) {
  764. case 0: /* ACK */
  765. dev->n_rc_acks++;
  766. /* If this is a partial ACK, reset the retransmit timer. */
  767. if (qp->s_last != qp->s_tail) {
  768. spin_lock(&dev->pending_lock);
  769. list_add_tail(&qp->timerwait,
  770. &dev->pending[dev->pending_index]);
  771. spin_unlock(&dev->pending_lock);
  772. }
  773. ipath_get_credit(qp, aeth);
  774. qp->s_rnr_retry = qp->s_rnr_retry_cnt;
  775. qp->s_retry = qp->s_retry_cnt;
  776. qp->s_last_psn = psn;
  777. ret = 1;
  778. goto bail;
  779. case 1: /* RNR NAK */
  780. dev->n_rnr_naks++;
  781. if (qp->s_rnr_retry == 0) {
  782. if (qp->s_last == qp->s_tail)
  783. goto bail;
  784. wc.status = IB_WC_RNR_RETRY_EXC_ERR;
  785. goto class_b;
  786. }
  787. if (qp->s_rnr_retry_cnt < 7)
  788. qp->s_rnr_retry--;
  789. if (qp->s_last == qp->s_tail)
  790. goto bail;
  791. /* The last valid PSN is the previous PSN. */
  792. qp->s_last_psn = psn - 1;
  793. dev->n_rc_resends += (int)qp->s_psn - (int)psn;
  794. reset_psn(qp, psn);
  795. qp->s_rnr_timeout =
  796. ib_ipath_rnr_table[(aeth >> IPS_AETH_CREDIT_SHIFT) &
  797. IPS_AETH_CREDIT_MASK];
  798. ipath_insert_rnr_queue(qp);
  799. goto bail;
  800. case 3: /* NAK */
  801. /* The last valid PSN seen is the previous request's. */
  802. if (qp->s_last != qp->s_tail)
  803. qp->s_last_psn = wqe->psn - 1;
  804. switch ((aeth >> IPS_AETH_CREDIT_SHIFT) &
  805. IPS_AETH_CREDIT_MASK) {
  806. case 0: /* PSN sequence error */
  807. dev->n_seq_naks++;
  808. /*
  809. * Back up to the responder's expected PSN. XXX
  810. * Note that we might get a NAK in the middle of an
  811. * RDMA READ response which terminates the RDMA
  812. * READ.
  813. */
  814. if (qp->s_last == qp->s_tail)
  815. break;
  816. if (ipath_cmp24(psn, wqe->psn) < 0)
  817. break;
  818. /* Retry the request. */
  819. ipath_restart_rc(qp, psn, &wc);
  820. break;
  821. case 1: /* Invalid Request */
  822. wc.status = IB_WC_REM_INV_REQ_ERR;
  823. dev->n_other_naks++;
  824. goto class_b;
  825. case 2: /* Remote Access Error */
  826. wc.status = IB_WC_REM_ACCESS_ERR;
  827. dev->n_other_naks++;
  828. goto class_b;
  829. case 3: /* Remote Operation Error */
  830. wc.status = IB_WC_REM_OP_ERR;
  831. dev->n_other_naks++;
  832. class_b:
  833. wc.wr_id = wqe->wr.wr_id;
  834. wc.opcode = ib_ipath_wc_opcode[wqe->wr.opcode];
  835. wc.vendor_err = 0;
  836. wc.byte_len = 0;
  837. wc.qp_num = qp->ibqp.qp_num;
  838. wc.src_qp = qp->remote_qpn;
  839. wc.pkey_index = 0;
  840. wc.slid = qp->remote_ah_attr.dlid;
  841. wc.sl = qp->remote_ah_attr.sl;
  842. wc.dlid_path_bits = 0;
  843. wc.port_num = 0;
  844. ipath_sqerror_qp(qp, &wc);
  845. break;
  846. default:
  847. /* Ignore other reserved NAK error codes */
  848. goto reserved;
  849. }
  850. qp->s_rnr_retry = qp->s_rnr_retry_cnt;
  851. goto bail;
  852. default: /* 2: reserved */
  853. reserved:
  854. /* Ignore reserved NAK codes. */
  855. goto bail;
  856. }
  857. bail:
  858. return ret;
  859. }
  860. /**
  861. * ipath_rc_rcv_resp - process an incoming RC response packet
  862. * @dev: the device this packet came in on
  863. * @ohdr: the other headers for this packet
  864. * @data: the packet data
  865. * @tlen: the packet length
  866. * @qp: the QP for this packet
  867. * @opcode: the opcode for this packet
  868. * @psn: the packet sequence number for this packet
  869. * @hdrsize: the header length
  870. * @pmtu: the path MTU
  871. * @header_in_data: true if part of the header data is in the data buffer
  872. *
  873. * This is called from ipath_rc_rcv() to process an incoming RC response
  874. * packet for the given QP.
  875. * Called at interrupt level.
  876. */
  877. static inline void ipath_rc_rcv_resp(struct ipath_ibdev *dev,
  878. struct ipath_other_headers *ohdr,
  879. void *data, u32 tlen,
  880. struct ipath_qp *qp,
  881. u32 opcode,
  882. u32 psn, u32 hdrsize, u32 pmtu,
  883. int header_in_data)
  884. {
  885. unsigned long flags;
  886. struct ib_wc wc;
  887. int diff;
  888. u32 pad;
  889. u32 aeth;
  890. spin_lock_irqsave(&qp->s_lock, flags);
  891. /* Ignore invalid responses. */
  892. if (ipath_cmp24(psn, qp->s_next_psn) >= 0)
  893. goto ack_done;
  894. /* Ignore duplicate responses. */
  895. diff = ipath_cmp24(psn, qp->s_last_psn);
  896. if (unlikely(diff <= 0)) {
  897. /* Update credits for "ghost" ACKs */
  898. if (diff == 0 && opcode == OP(ACKNOWLEDGE)) {
  899. if (!header_in_data)
  900. aeth = be32_to_cpu(ohdr->u.aeth);
  901. else {
  902. aeth = be32_to_cpu(((__be32 *) data)[0]);
  903. data += sizeof(__be32);
  904. }
  905. if ((aeth >> 29) == 0)
  906. ipath_get_credit(qp, aeth);
  907. }
  908. goto ack_done;
  909. }
  910. switch (opcode) {
  911. case OP(ACKNOWLEDGE):
  912. case OP(ATOMIC_ACKNOWLEDGE):
  913. case OP(RDMA_READ_RESPONSE_FIRST):
  914. if (!header_in_data)
  915. aeth = be32_to_cpu(ohdr->u.aeth);
  916. else {
  917. aeth = be32_to_cpu(((__be32 *) data)[0]);
  918. data += sizeof(__be32);
  919. }
  920. if (opcode == OP(ATOMIC_ACKNOWLEDGE))
  921. *(u64 *) qp->s_sge.sge.vaddr = *(u64 *) data;
  922. if (!do_rc_ack(qp, aeth, psn, opcode) ||
  923. opcode != OP(RDMA_READ_RESPONSE_FIRST))
  924. goto ack_done;
  925. hdrsize += 4;
  926. /*
  927. * do_rc_ack() has already checked the PSN so skip
  928. * the sequence check.
  929. */
  930. goto rdma_read;
  931. case OP(RDMA_READ_RESPONSE_MIDDLE):
  932. /* no AETH, no ACK */
  933. if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) {
  934. dev->n_rdma_seq++;
  935. ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
  936. goto ack_done;
  937. }
  938. rdma_read:
  939. if (unlikely(qp->s_state != OP(RDMA_READ_REQUEST)))
  940. goto ack_done;
  941. if (unlikely(tlen != (hdrsize + pmtu + 4)))
  942. goto ack_done;
  943. if (unlikely(pmtu >= qp->s_len))
  944. goto ack_done;
  945. /* We got a response so update the timeout. */
  946. if (unlikely(qp->s_last == qp->s_tail ||
  947. get_swqe_ptr(qp, qp->s_last)->wr.opcode !=
  948. IB_WR_RDMA_READ))
  949. goto ack_done;
  950. spin_lock(&dev->pending_lock);
  951. if (qp->s_rnr_timeout == 0 && !list_empty(&qp->timerwait))
  952. list_move_tail(&qp->timerwait,
  953. &dev->pending[dev->pending_index]);
  954. spin_unlock(&dev->pending_lock);
  955. /*
  956. * Update the RDMA receive state but do the copy w/o
  957. * holding the locks and blocking interrupts.
  958. * XXX Yet another place that affects relaxed RDMA order
  959. * since we don't want s_sge modified.
  960. */
  961. qp->s_len -= pmtu;
  962. qp->s_last_psn = psn;
  963. spin_unlock_irqrestore(&qp->s_lock, flags);
  964. ipath_copy_sge(&qp->s_sge, data, pmtu);
  965. goto bail;
  966. case OP(RDMA_READ_RESPONSE_LAST):
  967. /* ACKs READ req. */
  968. if (unlikely(ipath_cmp24(psn, qp->s_last_psn + 1))) {
  969. dev->n_rdma_seq++;
  970. ipath_restart_rc(qp, qp->s_last_psn + 1, &wc);
  971. goto ack_done;
  972. }
  973. /* FALLTHROUGH */
  974. case OP(RDMA_READ_RESPONSE_ONLY):
  975. if (unlikely(qp->s_state != OP(RDMA_READ_REQUEST)))
  976. goto ack_done;
  977. /*
  978. * Get the number of bytes the message was padded by.
  979. */
  980. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  981. /*
  982. * Check that the data size is >= 1 && <= pmtu.
  983. * Remember to account for the AETH header (4) and
  984. * ICRC (4).
  985. */
  986. if (unlikely(tlen <= (hdrsize + pad + 8))) {
  987. /* XXX Need to generate an error CQ entry. */
  988. goto ack_done;
  989. }
  990. tlen -= hdrsize + pad + 8;
  991. if (unlikely(tlen != qp->s_len)) {
  992. /* XXX Need to generate an error CQ entry. */
  993. goto ack_done;
  994. }
  995. if (!header_in_data)
  996. aeth = be32_to_cpu(ohdr->u.aeth);
  997. else {
  998. aeth = be32_to_cpu(((__be32 *) data)[0]);
  999. data += sizeof(__be32);
  1000. }
  1001. ipath_copy_sge(&qp->s_sge, data, tlen);
  1002. if (do_rc_ack(qp, aeth, psn, OP(RDMA_READ_RESPONSE_LAST))) {
  1003. /*
  1004. * Change the state so we contimue
  1005. * processing new requests and wake up the
  1006. * tasklet if there are posted sends.
  1007. */
  1008. qp->s_state = OP(SEND_LAST);
  1009. if (qp->s_tail != qp->s_head)
  1010. tasklet_hi_schedule(&qp->s_task);
  1011. }
  1012. goto ack_done;
  1013. }
  1014. ack_done:
  1015. spin_unlock_irqrestore(&qp->s_lock, flags);
  1016. bail:
  1017. return;
  1018. }
  1019. /**
  1020. * ipath_rc_rcv_error - process an incoming duplicate or error RC packet
  1021. * @dev: the device this packet came in on
  1022. * @ohdr: the other headers for this packet
  1023. * @data: the packet data
  1024. * @qp: the QP for this packet
  1025. * @opcode: the opcode for this packet
  1026. * @psn: the packet sequence number for this packet
  1027. * @diff: the difference between the PSN and the expected PSN
  1028. * @header_in_data: true if part of the header data is in the data buffer
  1029. *
  1030. * This is called from ipath_rc_rcv() to process an unexpected
  1031. * incoming RC packet for the given QP.
  1032. * Called at interrupt level.
  1033. * Return 1 if no more processing is needed; otherwise return 0 to
  1034. * schedule a response to be sent and the s_lock unlocked.
  1035. */
  1036. static inline int ipath_rc_rcv_error(struct ipath_ibdev *dev,
  1037. struct ipath_other_headers *ohdr,
  1038. void *data,
  1039. struct ipath_qp *qp,
  1040. u32 opcode,
  1041. u32 psn,
  1042. int diff,
  1043. int header_in_data)
  1044. {
  1045. struct ib_reth *reth;
  1046. if (diff > 0) {
  1047. /*
  1048. * Packet sequence error.
  1049. * A NAK will ACK earlier sends and RDMA writes.
  1050. * Don't queue the NAK if a RDMA read, atomic, or
  1051. * NAK is pending though.
  1052. */
  1053. spin_lock(&qp->s_lock);
  1054. if ((qp->s_ack_state >= OP(RDMA_READ_REQUEST) &&
  1055. qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE) ||
  1056. qp->s_nak_state != 0) {
  1057. spin_unlock(&qp->s_lock);
  1058. goto done;
  1059. }
  1060. qp->s_ack_state = OP(SEND_ONLY);
  1061. qp->s_nak_state = IB_NAK_PSN_ERROR;
  1062. /* Use the expected PSN. */
  1063. qp->s_ack_psn = qp->r_psn;
  1064. goto resched;
  1065. }
  1066. /*
  1067. * Handle a duplicate request. Don't re-execute SEND, RDMA
  1068. * write or atomic op. Don't NAK errors, just silently drop
  1069. * the duplicate request. Note that r_sge, r_len, and
  1070. * r_rcv_len may be in use so don't modify them.
  1071. *
  1072. * We are supposed to ACK the earliest duplicate PSN but we
  1073. * can coalesce an outstanding duplicate ACK. We have to
  1074. * send the earliest so that RDMA reads can be restarted at
  1075. * the requester's expected PSN.
  1076. */
  1077. spin_lock(&qp->s_lock);
  1078. if (qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE &&
  1079. ipath_cmp24(psn, qp->s_ack_psn) >= 0) {
  1080. if (qp->s_ack_state < IB_OPCODE_RDMA_READ_REQUEST)
  1081. qp->s_ack_psn = psn;
  1082. spin_unlock(&qp->s_lock);
  1083. goto done;
  1084. }
  1085. switch (opcode) {
  1086. case OP(RDMA_READ_REQUEST):
  1087. /*
  1088. * We have to be careful to not change s_rdma_sge
  1089. * while ipath_do_rc_send() is using it and not
  1090. * holding the s_lock.
  1091. */
  1092. if (qp->s_ack_state != OP(ACKNOWLEDGE) &&
  1093. qp->s_ack_state >= IB_OPCODE_RDMA_READ_REQUEST) {
  1094. spin_unlock(&qp->s_lock);
  1095. dev->n_rdma_dup_busy++;
  1096. goto done;
  1097. }
  1098. /* RETH comes after BTH */
  1099. if (!header_in_data)
  1100. reth = &ohdr->u.rc.reth;
  1101. else {
  1102. reth = (struct ib_reth *)data;
  1103. data += sizeof(*reth);
  1104. }
  1105. qp->s_rdma_len = be32_to_cpu(reth->length);
  1106. if (qp->s_rdma_len != 0) {
  1107. u32 rkey = be32_to_cpu(reth->rkey);
  1108. u64 vaddr = be64_to_cpu(reth->vaddr);
  1109. int ok;
  1110. /*
  1111. * Address range must be a subset of the original
  1112. * request and start on pmtu boundaries.
  1113. */
  1114. ok = ipath_rkey_ok(dev, &qp->s_rdma_sge,
  1115. qp->s_rdma_len, vaddr, rkey,
  1116. IB_ACCESS_REMOTE_READ);
  1117. if (unlikely(!ok))
  1118. goto done;
  1119. } else {
  1120. qp->s_rdma_sge.sg_list = NULL;
  1121. qp->s_rdma_sge.num_sge = 0;
  1122. qp->s_rdma_sge.sge.mr = NULL;
  1123. qp->s_rdma_sge.sge.vaddr = NULL;
  1124. qp->s_rdma_sge.sge.length = 0;
  1125. qp->s_rdma_sge.sge.sge_length = 0;
  1126. }
  1127. break;
  1128. case OP(COMPARE_SWAP):
  1129. case OP(FETCH_ADD):
  1130. /*
  1131. * Check for the PSN of the last atomic operation
  1132. * performed and resend the result if found.
  1133. */
  1134. if ((psn & IPS_PSN_MASK) != qp->r_atomic_psn) {
  1135. spin_unlock(&qp->s_lock);
  1136. goto done;
  1137. }
  1138. qp->s_ack_atomic = qp->r_atomic_data;
  1139. break;
  1140. }
  1141. qp->s_ack_state = opcode;
  1142. qp->s_nak_state = 0;
  1143. qp->s_ack_psn = psn;
  1144. resched:
  1145. return 0;
  1146. done:
  1147. return 1;
  1148. }
  1149. /**
  1150. * ipath_rc_rcv - process an incoming RC packet
  1151. * @dev: the device this packet came in on
  1152. * @hdr: the header of this packet
  1153. * @has_grh: true if the header has a GRH
  1154. * @data: the packet data
  1155. * @tlen: the packet length
  1156. * @qp: the QP for this packet
  1157. *
  1158. * This is called from ipath_qp_rcv() to process an incoming RC packet
  1159. * for the given QP.
  1160. * Called at interrupt level.
  1161. */
  1162. void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
  1163. int has_grh, void *data, u32 tlen, struct ipath_qp *qp)
  1164. {
  1165. struct ipath_other_headers *ohdr;
  1166. u32 opcode;
  1167. u32 hdrsize;
  1168. u32 psn;
  1169. u32 pad;
  1170. unsigned long flags;
  1171. struct ib_wc wc;
  1172. u32 pmtu = ib_mtu_enum_to_int(qp->path_mtu);
  1173. int diff;
  1174. struct ib_reth *reth;
  1175. int header_in_data;
  1176. /* Check for GRH */
  1177. if (!has_grh) {
  1178. ohdr = &hdr->u.oth;
  1179. hdrsize = 8 + 12; /* LRH + BTH */
  1180. psn = be32_to_cpu(ohdr->bth[2]);
  1181. header_in_data = 0;
  1182. } else {
  1183. ohdr = &hdr->u.l.oth;
  1184. hdrsize = 8 + 40 + 12; /* LRH + GRH + BTH */
  1185. /*
  1186. * The header with GRH is 60 bytes and the core driver sets
  1187. * the eager header buffer size to 56 bytes so the last 4
  1188. * bytes of the BTH header (PSN) is in the data buffer.
  1189. */
  1190. header_in_data =
  1191. ipath_layer_get_rcvhdrentsize(dev->dd) == 16;
  1192. if (header_in_data) {
  1193. psn = be32_to_cpu(((__be32 *) data)[0]);
  1194. data += sizeof(__be32);
  1195. } else
  1196. psn = be32_to_cpu(ohdr->bth[2]);
  1197. }
  1198. /*
  1199. * Process responses (ACKs) before anything else. Note that the
  1200. * packet sequence number will be for something in the send work
  1201. * queue rather than the expected receive packet sequence number.
  1202. * In other words, this QP is the requester.
  1203. */
  1204. opcode = be32_to_cpu(ohdr->bth[0]) >> 24;
  1205. if (opcode >= OP(RDMA_READ_RESPONSE_FIRST) &&
  1206. opcode <= OP(ATOMIC_ACKNOWLEDGE)) {
  1207. ipath_rc_rcv_resp(dev, ohdr, data, tlen, qp, opcode, psn,
  1208. hdrsize, pmtu, header_in_data);
  1209. goto bail;
  1210. }
  1211. spin_lock_irqsave(&qp->r_rq.lock, flags);
  1212. /* Compute 24 bits worth of difference. */
  1213. diff = ipath_cmp24(psn, qp->r_psn);
  1214. if (unlikely(diff)) {
  1215. if (ipath_rc_rcv_error(dev, ohdr, data, qp, opcode,
  1216. psn, diff, header_in_data))
  1217. goto done;
  1218. goto resched;
  1219. }
  1220. /* Check for opcode sequence errors. */
  1221. switch (qp->r_state) {
  1222. case OP(SEND_FIRST):
  1223. case OP(SEND_MIDDLE):
  1224. if (opcode == OP(SEND_MIDDLE) ||
  1225. opcode == OP(SEND_LAST) ||
  1226. opcode == OP(SEND_LAST_WITH_IMMEDIATE))
  1227. break;
  1228. nack_inv:
  1229. /*
  1230. * A NAK will ACK earlier sends and RDMA writes. Don't queue the
  1231. * NAK if a RDMA read, atomic, or NAK is pending though.
  1232. */
  1233. spin_lock(&qp->s_lock);
  1234. if (qp->s_ack_state >= OP(RDMA_READ_REQUEST) &&
  1235. qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE) {
  1236. spin_unlock(&qp->s_lock);
  1237. goto done;
  1238. }
  1239. /* XXX Flush WQEs */
  1240. qp->state = IB_QPS_ERR;
  1241. qp->s_ack_state = OP(SEND_ONLY);
  1242. qp->s_nak_state = IB_NAK_INVALID_REQUEST;
  1243. qp->s_ack_psn = qp->r_psn;
  1244. goto resched;
  1245. case OP(RDMA_WRITE_FIRST):
  1246. case OP(RDMA_WRITE_MIDDLE):
  1247. if (opcode == OP(RDMA_WRITE_MIDDLE) ||
  1248. opcode == OP(RDMA_WRITE_LAST) ||
  1249. opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
  1250. break;
  1251. goto nack_inv;
  1252. case OP(RDMA_READ_REQUEST):
  1253. case OP(COMPARE_SWAP):
  1254. case OP(FETCH_ADD):
  1255. /*
  1256. * Drop all new requests until a response has been sent. A
  1257. * new request then ACKs the RDMA response we sent. Relaxed
  1258. * ordering would allow new requests to be processed but we
  1259. * would need to keep a queue of rwqe's for all that are in
  1260. * progress. Note that we can't RNR NAK this request since
  1261. * the RDMA READ or atomic response is already queued to be
  1262. * sent (unless we implement a response send queue).
  1263. */
  1264. goto done;
  1265. default:
  1266. if (opcode == OP(SEND_MIDDLE) ||
  1267. opcode == OP(SEND_LAST) ||
  1268. opcode == OP(SEND_LAST_WITH_IMMEDIATE) ||
  1269. opcode == OP(RDMA_WRITE_MIDDLE) ||
  1270. opcode == OP(RDMA_WRITE_LAST) ||
  1271. opcode == OP(RDMA_WRITE_LAST_WITH_IMMEDIATE))
  1272. goto nack_inv;
  1273. break;
  1274. }
  1275. wc.imm_data = 0;
  1276. wc.wc_flags = 0;
  1277. /* OK, process the packet. */
  1278. switch (opcode) {
  1279. case OP(SEND_FIRST):
  1280. if (!ipath_get_rwqe(qp, 0)) {
  1281. rnr_nak:
  1282. /*
  1283. * A RNR NAK will ACK earlier sends and RDMA writes.
  1284. * Don't queue the NAK if a RDMA read or atomic
  1285. * is pending though.
  1286. */
  1287. spin_lock(&qp->s_lock);
  1288. if (qp->s_ack_state >=
  1289. OP(RDMA_READ_REQUEST) &&
  1290. qp->s_ack_state != IB_OPCODE_ACKNOWLEDGE) {
  1291. spin_unlock(&qp->s_lock);
  1292. goto done;
  1293. }
  1294. qp->s_ack_state = OP(SEND_ONLY);
  1295. qp->s_nak_state = IB_RNR_NAK | qp->s_min_rnr_timer;
  1296. qp->s_ack_psn = qp->r_psn;
  1297. goto resched;
  1298. }
  1299. qp->r_rcv_len = 0;
  1300. /* FALLTHROUGH */
  1301. case OP(SEND_MIDDLE):
  1302. case OP(RDMA_WRITE_MIDDLE):
  1303. send_middle:
  1304. /* Check for invalid length PMTU or posted rwqe len. */
  1305. if (unlikely(tlen != (hdrsize + pmtu + 4)))
  1306. goto nack_inv;
  1307. qp->r_rcv_len += pmtu;
  1308. if (unlikely(qp->r_rcv_len > qp->r_len))
  1309. goto nack_inv;
  1310. ipath_copy_sge(&qp->r_sge, data, pmtu);
  1311. break;
  1312. case OP(RDMA_WRITE_LAST_WITH_IMMEDIATE):
  1313. /* consume RWQE */
  1314. if (!ipath_get_rwqe(qp, 1))
  1315. goto rnr_nak;
  1316. goto send_last_imm;
  1317. case OP(SEND_ONLY):
  1318. case OP(SEND_ONLY_WITH_IMMEDIATE):
  1319. if (!ipath_get_rwqe(qp, 0))
  1320. goto rnr_nak;
  1321. qp->r_rcv_len = 0;
  1322. if (opcode == OP(SEND_ONLY))
  1323. goto send_last;
  1324. /* FALLTHROUGH */
  1325. case OP(SEND_LAST_WITH_IMMEDIATE):
  1326. send_last_imm:
  1327. if (header_in_data) {
  1328. wc.imm_data = *(__be32 *) data;
  1329. data += sizeof(__be32);
  1330. } else {
  1331. /* Immediate data comes after BTH */
  1332. wc.imm_data = ohdr->u.imm_data;
  1333. }
  1334. hdrsize += 4;
  1335. wc.wc_flags = IB_WC_WITH_IMM;
  1336. /* FALLTHROUGH */
  1337. case OP(SEND_LAST):
  1338. case OP(RDMA_WRITE_LAST):
  1339. send_last:
  1340. /* Get the number of bytes the message was padded by. */
  1341. pad = (be32_to_cpu(ohdr->bth[0]) >> 20) & 3;
  1342. /* Check for invalid length. */
  1343. /* XXX LAST len should be >= 1 */
  1344. if (unlikely(tlen < (hdrsize + pad + 4)))
  1345. goto nack_inv;
  1346. /* Don't count the CRC. */
  1347. tlen -= (hdrsize + pad + 4);
  1348. wc.byte_len = tlen + qp->r_rcv_len;
  1349. if (unlikely(wc.byte_len > qp->r_len))
  1350. goto nack_inv;
  1351. ipath_copy_sge(&qp->r_sge, data, tlen);
  1352. atomic_inc(&qp->msn);
  1353. if (opcode == OP(RDMA_WRITE_LAST) ||
  1354. opcode == OP(RDMA_WRITE_ONLY))
  1355. break;
  1356. wc.wr_id = qp->r_wr_id;
  1357. wc.status = IB_WC_SUCCESS;
  1358. wc.opcode = IB_WC_RECV;
  1359. wc.vendor_err = 0;
  1360. wc.qp_num = qp->ibqp.qp_num;
  1361. wc.src_qp = qp->remote_qpn;
  1362. wc.pkey_index = 0;
  1363. wc.slid = qp->remote_ah_attr.dlid;
  1364. wc.sl = qp->remote_ah_attr.sl;
  1365. wc.dlid_path_bits = 0;
  1366. wc.port_num = 0;
  1367. /* Signal completion event if the solicited bit is set. */
  1368. ipath_cq_enter(to_icq(qp->ibqp.recv_cq), &wc,
  1369. (ohdr->bth[0] &
  1370. __constant_cpu_to_be32(1 << 23)) != 0);
  1371. break;
  1372. case OP(RDMA_WRITE_FIRST):
  1373. case OP(RDMA_WRITE_ONLY):
  1374. case OP(RDMA_WRITE_ONLY_WITH_IMMEDIATE):
  1375. /* consume RWQE */
  1376. /* RETH comes after BTH */
  1377. if (!header_in_data)
  1378. reth = &ohdr->u.rc.reth;
  1379. else {
  1380. reth = (struct ib_reth *)data;
  1381. data += sizeof(*reth);
  1382. }
  1383. hdrsize += sizeof(*reth);
  1384. qp->r_len = be32_to_cpu(reth->length);
  1385. qp->r_rcv_len = 0;
  1386. if (qp->r_len != 0) {
  1387. u32 rkey = be32_to_cpu(reth->rkey);
  1388. u64 vaddr = be64_to_cpu(reth->vaddr);
  1389. int ok;
  1390. /* Check rkey & NAK */
  1391. ok = ipath_rkey_ok(dev, &qp->r_sge,
  1392. qp->r_len, vaddr, rkey,
  1393. IB_ACCESS_REMOTE_WRITE);
  1394. if (unlikely(!ok)) {
  1395. nack_acc:
  1396. /*
  1397. * A NAK will ACK earlier sends and RDMA
  1398. * writes. Don't queue the NAK if a RDMA
  1399. * read, atomic, or NAK is pending though.
  1400. */
  1401. spin_lock(&qp->s_lock);
  1402. if (qp->s_ack_state >=
  1403. OP(RDMA_READ_REQUEST) &&
  1404. qp->s_ack_state !=
  1405. IB_OPCODE_ACKNOWLEDGE) {
  1406. spin_unlock(&qp->s_lock);
  1407. goto done;
  1408. }
  1409. /* XXX Flush WQEs */
  1410. qp->state = IB_QPS_ERR;
  1411. qp->s_ack_state = OP(RDMA_WRITE_ONLY);
  1412. qp->s_nak_state =
  1413. IB_NAK_REMOTE_ACCESS_ERROR;
  1414. qp->s_ack_psn = qp->r_psn;
  1415. goto resched;
  1416. }
  1417. } else {
  1418. qp->r_sge.sg_list = NULL;
  1419. qp->r_sge.sge.mr = NULL;
  1420. qp->r_sge.sge.vaddr = NULL;
  1421. qp->r_sge.sge.length = 0;
  1422. qp->r_sge.sge.sge_length = 0;
  1423. }
  1424. if (unlikely(!(qp->qp_access_flags &
  1425. IB_ACCESS_REMOTE_WRITE)))
  1426. goto nack_acc;
  1427. if (opcode == OP(RDMA_WRITE_FIRST))
  1428. goto send_middle;
  1429. else if (opcode == OP(RDMA_WRITE_ONLY))
  1430. goto send_last;
  1431. if (!ipath_get_rwqe(qp, 1))
  1432. goto rnr_nak;
  1433. goto send_last_imm;
  1434. case OP(RDMA_READ_REQUEST):
  1435. /* RETH comes after BTH */
  1436. if (!header_in_data)
  1437. reth = &ohdr->u.rc.reth;
  1438. else {
  1439. reth = (struct ib_reth *)data;
  1440. data += sizeof(*reth);
  1441. }
  1442. spin_lock(&qp->s_lock);
  1443. if (qp->s_ack_state != OP(ACKNOWLEDGE) &&
  1444. qp->s_ack_state >= IB_OPCODE_RDMA_READ_REQUEST) {
  1445. spin_unlock(&qp->s_lock);
  1446. goto done;
  1447. }
  1448. qp->s_rdma_len = be32_to_cpu(reth->length);
  1449. if (qp->s_rdma_len != 0) {
  1450. u32 rkey = be32_to_cpu(reth->rkey);
  1451. u64 vaddr = be64_to_cpu(reth->vaddr);
  1452. int ok;
  1453. /* Check rkey & NAK */
  1454. ok = ipath_rkey_ok(dev, &qp->s_rdma_sge,
  1455. qp->s_rdma_len, vaddr, rkey,
  1456. IB_ACCESS_REMOTE_READ);
  1457. if (unlikely(!ok)) {
  1458. spin_unlock(&qp->s_lock);
  1459. goto nack_acc;
  1460. }
  1461. /*
  1462. * Update the next expected PSN. We add 1 later
  1463. * below, so only add the remainder here.
  1464. */
  1465. if (qp->s_rdma_len > pmtu)
  1466. qp->r_psn += (qp->s_rdma_len - 1) / pmtu;
  1467. } else {
  1468. qp->s_rdma_sge.sg_list = NULL;
  1469. qp->s_rdma_sge.num_sge = 0;
  1470. qp->s_rdma_sge.sge.mr = NULL;
  1471. qp->s_rdma_sge.sge.vaddr = NULL;
  1472. qp->s_rdma_sge.sge.length = 0;
  1473. qp->s_rdma_sge.sge.sge_length = 0;
  1474. }
  1475. if (unlikely(!(qp->qp_access_flags &
  1476. IB_ACCESS_REMOTE_READ)))
  1477. goto nack_acc;
  1478. /*
  1479. * We need to increment the MSN here instead of when we
  1480. * finish sending the result since a duplicate request would
  1481. * increment it more than once.
  1482. */
  1483. atomic_inc(&qp->msn);
  1484. qp->s_ack_state = opcode;
  1485. qp->s_nak_state = 0;
  1486. qp->s_ack_psn = psn;
  1487. qp->r_psn++;
  1488. qp->r_state = opcode;
  1489. goto rdmadone;
  1490. case OP(COMPARE_SWAP):
  1491. case OP(FETCH_ADD): {
  1492. struct ib_atomic_eth *ateth;
  1493. u64 vaddr;
  1494. u64 sdata;
  1495. u32 rkey;
  1496. if (!header_in_data)
  1497. ateth = &ohdr->u.atomic_eth;
  1498. else {
  1499. ateth = (struct ib_atomic_eth *)data;
  1500. data += sizeof(*ateth);
  1501. }
  1502. vaddr = be64_to_cpu(ateth->vaddr);
  1503. if (unlikely(vaddr & (sizeof(u64) - 1)))
  1504. goto nack_inv;
  1505. rkey = be32_to_cpu(ateth->rkey);
  1506. /* Check rkey & NAK */
  1507. if (unlikely(!ipath_rkey_ok(dev, &qp->r_sge,
  1508. sizeof(u64), vaddr, rkey,
  1509. IB_ACCESS_REMOTE_ATOMIC)))
  1510. goto nack_acc;
  1511. if (unlikely(!(qp->qp_access_flags &
  1512. IB_ACCESS_REMOTE_ATOMIC)))
  1513. goto nack_acc;
  1514. /* Perform atomic OP and save result. */
  1515. sdata = be64_to_cpu(ateth->swap_data);
  1516. spin_lock(&dev->pending_lock);
  1517. qp->r_atomic_data = *(u64 *) qp->r_sge.sge.vaddr;
  1518. if (opcode == OP(FETCH_ADD))
  1519. *(u64 *) qp->r_sge.sge.vaddr =
  1520. qp->r_atomic_data + sdata;
  1521. else if (qp->r_atomic_data ==
  1522. be64_to_cpu(ateth->compare_data))
  1523. *(u64 *) qp->r_sge.sge.vaddr = sdata;
  1524. spin_unlock(&dev->pending_lock);
  1525. atomic_inc(&qp->msn);
  1526. qp->r_atomic_psn = psn & IPS_PSN_MASK;
  1527. psn |= 1 << 31;
  1528. break;
  1529. }
  1530. default:
  1531. /* Drop packet for unknown opcodes. */
  1532. goto done;
  1533. }
  1534. qp->r_psn++;
  1535. qp->r_state = opcode;
  1536. /* Send an ACK if requested or required. */
  1537. if (psn & (1 << 31)) {
  1538. /*
  1539. * Coalesce ACKs unless there is a RDMA READ or
  1540. * ATOMIC pending.
  1541. */
  1542. spin_lock(&qp->s_lock);
  1543. if (qp->s_ack_state == OP(ACKNOWLEDGE) ||
  1544. qp->s_ack_state < IB_OPCODE_RDMA_READ_REQUEST) {
  1545. qp->s_ack_state = opcode;
  1546. qp->s_nak_state = 0;
  1547. qp->s_ack_psn = psn;
  1548. qp->s_ack_atomic = qp->r_atomic_data;
  1549. goto resched;
  1550. }
  1551. spin_unlock(&qp->s_lock);
  1552. }
  1553. done:
  1554. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  1555. goto bail;
  1556. resched:
  1557. /*
  1558. * Try to send ACK right away but not if ipath_do_rc_send() is
  1559. * active.
  1560. */
  1561. if (qp->s_hdrwords == 0 &&
  1562. (qp->s_ack_state < IB_OPCODE_RDMA_READ_REQUEST ||
  1563. qp->s_ack_state >= IB_OPCODE_COMPARE_SWAP))
  1564. send_rc_ack(qp);
  1565. rdmadone:
  1566. spin_unlock(&qp->s_lock);
  1567. spin_unlock_irqrestore(&qp->r_rq.lock, flags);
  1568. /* Call ipath_do_rc_send() in another thread. */
  1569. tasklet_hi_schedule(&qp->s_task);
  1570. bail:
  1571. return;
  1572. }