bnx2i_hwi.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603
  1. /* bnx2i_hwi.c: Broadcom NetXtreme II iSCSI driver.
  2. *
  3. * Copyright (c) 2006 - 2010 Broadcom Corporation
  4. * Copyright (c) 2007, 2008 Red Hat, Inc. All rights reserved.
  5. * Copyright (c) 2007, 2008 Mike Christie
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation.
  10. *
  11. * Written by: Anil Veerabhadrappa (anilgv@broadcom.com)
  12. * Maintained by: Eddie Wai (eddie.wai@broadcom.com)
  13. */
  14. #include <linux/gfp.h>
  15. #include <scsi/scsi_tcq.h>
  16. #include <scsi/libiscsi.h>
  17. #include "bnx2i.h"
  18. /**
  19. * bnx2i_get_cid_num - get cid from ep
  20. * @ep: endpoint pointer
  21. *
  22. * Only applicable to 57710 family of devices
  23. */
  24. static u32 bnx2i_get_cid_num(struct bnx2i_endpoint *ep)
  25. {
  26. u32 cid;
  27. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  28. cid = ep->ep_cid;
  29. else
  30. cid = GET_CID_NUM(ep->ep_cid);
  31. return cid;
  32. }
  33. /**
  34. * bnx2i_adjust_qp_size - Adjust SQ/RQ/CQ size for 57710 device type
  35. * @hba: Adapter for which adjustments is to be made
  36. *
  37. * Only applicable to 57710 family of devices
  38. */
  39. static void bnx2i_adjust_qp_size(struct bnx2i_hba *hba)
  40. {
  41. u32 num_elements_per_pg;
  42. if (test_bit(BNX2I_NX2_DEV_5706, &hba->cnic_dev_type) ||
  43. test_bit(BNX2I_NX2_DEV_5708, &hba->cnic_dev_type) ||
  44. test_bit(BNX2I_NX2_DEV_5709, &hba->cnic_dev_type)) {
  45. if (!is_power_of_2(hba->max_sqes))
  46. hba->max_sqes = rounddown_pow_of_two(hba->max_sqes);
  47. if (!is_power_of_2(hba->max_rqes))
  48. hba->max_rqes = rounddown_pow_of_two(hba->max_rqes);
  49. }
  50. /* Adjust each queue size if the user selection does not
  51. * yield integral num of page buffers
  52. */
  53. /* adjust SQ */
  54. num_elements_per_pg = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
  55. if (hba->max_sqes < num_elements_per_pg)
  56. hba->max_sqes = num_elements_per_pg;
  57. else if (hba->max_sqes % num_elements_per_pg)
  58. hba->max_sqes = (hba->max_sqes + num_elements_per_pg - 1) &
  59. ~(num_elements_per_pg - 1);
  60. /* adjust CQ */
  61. num_elements_per_pg = PAGE_SIZE / BNX2I_CQE_SIZE;
  62. if (hba->max_cqes < num_elements_per_pg)
  63. hba->max_cqes = num_elements_per_pg;
  64. else if (hba->max_cqes % num_elements_per_pg)
  65. hba->max_cqes = (hba->max_cqes + num_elements_per_pg - 1) &
  66. ~(num_elements_per_pg - 1);
  67. /* adjust RQ */
  68. num_elements_per_pg = PAGE_SIZE / BNX2I_RQ_WQE_SIZE;
  69. if (hba->max_rqes < num_elements_per_pg)
  70. hba->max_rqes = num_elements_per_pg;
  71. else if (hba->max_rqes % num_elements_per_pg)
  72. hba->max_rqes = (hba->max_rqes + num_elements_per_pg - 1) &
  73. ~(num_elements_per_pg - 1);
  74. }
  75. /**
  76. * bnx2i_get_link_state - get network interface link state
  77. * @hba: adapter instance pointer
  78. *
  79. * updates adapter structure flag based on netdev state
  80. */
  81. static void bnx2i_get_link_state(struct bnx2i_hba *hba)
  82. {
  83. if (test_bit(__LINK_STATE_NOCARRIER, &hba->netdev->state))
  84. set_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  85. else
  86. clear_bit(ADAPTER_STATE_LINK_DOWN, &hba->adapter_state);
  87. }
  88. /**
  89. * bnx2i_iscsi_license_error - displays iscsi license related error message
  90. * @hba: adapter instance pointer
  91. * @error_code: error classification
  92. *
  93. * Puts out an error log when driver is unable to offload iscsi connection
  94. * due to license restrictions
  95. */
  96. static void bnx2i_iscsi_license_error(struct bnx2i_hba *hba, u32 error_code)
  97. {
  98. if (error_code == ISCSI_KCQE_COMPLETION_STATUS_ISCSI_NOT_SUPPORTED)
  99. /* iSCSI offload not supported on this device */
  100. printk(KERN_ERR "bnx2i: iSCSI not supported, dev=%s\n",
  101. hba->netdev->name);
  102. if (error_code == ISCSI_KCQE_COMPLETION_STATUS_LOM_ISCSI_NOT_ENABLED)
  103. /* iSCSI offload not supported on this LOM device */
  104. printk(KERN_ERR "bnx2i: LOM is not enable to "
  105. "offload iSCSI connections, dev=%s\n",
  106. hba->netdev->name);
  107. set_bit(ADAPTER_STATE_INIT_FAILED, &hba->adapter_state);
  108. }
  109. /**
  110. * bnx2i_arm_cq_event_coalescing - arms CQ to enable EQ notification
  111. * @ep: endpoint (transport indentifier) structure
  112. * @action: action, ARM or DISARM. For now only ARM_CQE is used
  113. *
  114. * Arm'ing CQ will enable chip to generate global EQ events inorder to interrupt
  115. * the driver. EQ event is generated CQ index is hit or at least 1 CQ is
  116. * outstanding and on chip timer expires
  117. */
  118. void bnx2i_arm_cq_event_coalescing(struct bnx2i_endpoint *ep, u8 action)
  119. {
  120. struct bnx2i_5771x_cq_db *cq_db;
  121. u16 cq_index;
  122. u16 next_index;
  123. u32 num_active_cmds;
  124. /* Coalesce CQ entries only on 10G devices */
  125. if (!test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  126. return;
  127. /* Do not update CQ DB multiple times before firmware writes
  128. * '0xFFFF' to CQDB->SQN field. Deviation may cause spurious
  129. * interrupts and other unwanted results
  130. */
  131. cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
  132. if (cq_db->sqn[0] && cq_db->sqn[0] != 0xFFFF)
  133. return;
  134. if (action == CNIC_ARM_CQE) {
  135. num_active_cmds = ep->num_active_cmds;
  136. if (num_active_cmds <= event_coal_min)
  137. next_index = 1;
  138. else
  139. next_index = event_coal_min +
  140. (num_active_cmds - event_coal_min) / event_coal_div;
  141. if (!next_index)
  142. next_index = 1;
  143. cq_index = ep->qp.cqe_exp_seq_sn + next_index - 1;
  144. if (cq_index > ep->qp.cqe_size * 2)
  145. cq_index -= ep->qp.cqe_size * 2;
  146. if (!cq_index)
  147. cq_index = 1;
  148. cq_db->sqn[0] = cq_index;
  149. }
  150. }
  151. /**
  152. * bnx2i_get_rq_buf - copy RQ buffer contents to driver buffer
  153. * @conn: iscsi connection on which RQ event occurred
  154. * @ptr: driver buffer to which RQ buffer contents is to
  155. * be copied
  156. * @len: length of valid data inside RQ buf
  157. *
  158. * Copies RQ buffer contents from shared (DMA'able) memory region to
  159. * driver buffer. RQ is used to DMA unsolicitated iscsi pdu's and
  160. * scsi sense info
  161. */
  162. void bnx2i_get_rq_buf(struct bnx2i_conn *bnx2i_conn, char *ptr, int len)
  163. {
  164. if (!bnx2i_conn->ep->qp.rqe_left)
  165. return;
  166. bnx2i_conn->ep->qp.rqe_left--;
  167. memcpy(ptr, (u8 *) bnx2i_conn->ep->qp.rq_cons_qe, len);
  168. if (bnx2i_conn->ep->qp.rq_cons_qe == bnx2i_conn->ep->qp.rq_last_qe) {
  169. bnx2i_conn->ep->qp.rq_cons_qe = bnx2i_conn->ep->qp.rq_first_qe;
  170. bnx2i_conn->ep->qp.rq_cons_idx = 0;
  171. } else {
  172. bnx2i_conn->ep->qp.rq_cons_qe++;
  173. bnx2i_conn->ep->qp.rq_cons_idx++;
  174. }
  175. }
  176. static void bnx2i_ring_577xx_doorbell(struct bnx2i_conn *conn)
  177. {
  178. struct bnx2i_5771x_dbell dbell;
  179. u32 msg;
  180. memset(&dbell, 0, sizeof(dbell));
  181. dbell.dbell.header = (B577XX_ISCSI_CONNECTION_TYPE <<
  182. B577XX_DOORBELL_HDR_CONN_TYPE_SHIFT);
  183. msg = *((u32 *)&dbell);
  184. /* TODO : get doorbell register mapping */
  185. writel(cpu_to_le32(msg), conn->ep->qp.ctx_base);
  186. }
  187. /**
  188. * bnx2i_put_rq_buf - Replenish RQ buffer, if required ring on chip doorbell
  189. * @conn: iscsi connection on which event to post
  190. * @count: number of RQ buffer being posted to chip
  191. *
  192. * No need to ring hardware doorbell for 57710 family of devices
  193. */
  194. void bnx2i_put_rq_buf(struct bnx2i_conn *bnx2i_conn, int count)
  195. {
  196. struct bnx2i_5771x_sq_rq_db *rq_db;
  197. u16 hi_bit = (bnx2i_conn->ep->qp.rq_prod_idx & 0x8000);
  198. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  199. ep->qp.rqe_left += count;
  200. ep->qp.rq_prod_idx &= 0x7FFF;
  201. ep->qp.rq_prod_idx += count;
  202. if (ep->qp.rq_prod_idx > bnx2i_conn->hba->max_rqes) {
  203. ep->qp.rq_prod_idx %= bnx2i_conn->hba->max_rqes;
  204. if (!hi_bit)
  205. ep->qp.rq_prod_idx |= 0x8000;
  206. } else
  207. ep->qp.rq_prod_idx |= hi_bit;
  208. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  209. rq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.rq_pgtbl_virt;
  210. rq_db->prod_idx = ep->qp.rq_prod_idx;
  211. /* no need to ring hardware doorbell for 57710 */
  212. } else {
  213. writew(ep->qp.rq_prod_idx,
  214. ep->qp.ctx_base + CNIC_RECV_DOORBELL);
  215. }
  216. mmiowb();
  217. }
  218. /**
  219. * bnx2i_ring_sq_dbell - Ring SQ doorbell to wake-up the processing engine
  220. * @conn: iscsi connection to which new SQ entries belong
  221. * @count: number of SQ WQEs to post
  222. *
  223. * SQ DB is updated in host memory and TX Doorbell is rung for 57710 family
  224. * of devices. For 5706/5708/5709 new SQ WQE count is written into the
  225. * doorbell register
  226. */
  227. static void bnx2i_ring_sq_dbell(struct bnx2i_conn *bnx2i_conn, int count)
  228. {
  229. struct bnx2i_5771x_sq_rq_db *sq_db;
  230. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  231. ep->num_active_cmds++;
  232. wmb(); /* flush SQ WQE memory before the doorbell is rung */
  233. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  234. sq_db = (struct bnx2i_5771x_sq_rq_db *) ep->qp.sq_pgtbl_virt;
  235. sq_db->prod_idx = ep->qp.sq_prod_idx;
  236. bnx2i_ring_577xx_doorbell(bnx2i_conn);
  237. } else
  238. writew(count, ep->qp.ctx_base + CNIC_SEND_DOORBELL);
  239. mmiowb(); /* flush posted PCI writes */
  240. }
  241. /**
  242. * bnx2i_ring_dbell_update_sq_params - update SQ driver parameters
  243. * @conn: iscsi connection to which new SQ entries belong
  244. * @count: number of SQ WQEs to post
  245. *
  246. * this routine will update SQ driver parameters and ring the doorbell
  247. */
  248. static void bnx2i_ring_dbell_update_sq_params(struct bnx2i_conn *bnx2i_conn,
  249. int count)
  250. {
  251. int tmp_cnt;
  252. if (count == 1) {
  253. if (bnx2i_conn->ep->qp.sq_prod_qe ==
  254. bnx2i_conn->ep->qp.sq_last_qe)
  255. bnx2i_conn->ep->qp.sq_prod_qe =
  256. bnx2i_conn->ep->qp.sq_first_qe;
  257. else
  258. bnx2i_conn->ep->qp.sq_prod_qe++;
  259. } else {
  260. if ((bnx2i_conn->ep->qp.sq_prod_qe + count) <=
  261. bnx2i_conn->ep->qp.sq_last_qe)
  262. bnx2i_conn->ep->qp.sq_prod_qe += count;
  263. else {
  264. tmp_cnt = bnx2i_conn->ep->qp.sq_last_qe -
  265. bnx2i_conn->ep->qp.sq_prod_qe;
  266. bnx2i_conn->ep->qp.sq_prod_qe =
  267. &bnx2i_conn->ep->qp.sq_first_qe[count -
  268. (tmp_cnt + 1)];
  269. }
  270. }
  271. bnx2i_conn->ep->qp.sq_prod_idx += count;
  272. /* Ring the doorbell */
  273. bnx2i_ring_sq_dbell(bnx2i_conn, bnx2i_conn->ep->qp.sq_prod_idx);
  274. }
  275. /**
  276. * bnx2i_send_iscsi_login - post iSCSI login request MP WQE to hardware
  277. * @conn: iscsi connection
  278. * @cmd: driver command structure which is requesting
  279. * a WQE to sent to chip for further processing
  280. *
  281. * prepare and post an iSCSI Login request WQE to CNIC firmware
  282. */
  283. int bnx2i_send_iscsi_login(struct bnx2i_conn *bnx2i_conn,
  284. struct iscsi_task *task)
  285. {
  286. struct bnx2i_cmd *bnx2i_cmd;
  287. struct bnx2i_login_request *login_wqe;
  288. struct iscsi_login *login_hdr;
  289. u32 dword;
  290. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  291. login_hdr = (struct iscsi_login *)task->hdr;
  292. login_wqe = (struct bnx2i_login_request *)
  293. bnx2i_conn->ep->qp.sq_prod_qe;
  294. login_wqe->op_code = login_hdr->opcode;
  295. login_wqe->op_attr = login_hdr->flags;
  296. login_wqe->version_max = login_hdr->max_version;
  297. login_wqe->version_min = login_hdr->min_version;
  298. login_wqe->data_length = ntoh24(login_hdr->dlength);
  299. login_wqe->isid_lo = *((u32 *) login_hdr->isid);
  300. login_wqe->isid_hi = *((u16 *) login_hdr->isid + 2);
  301. login_wqe->tsih = login_hdr->tsih;
  302. login_wqe->itt = task->itt |
  303. (ISCSI_TASK_TYPE_MPATH << ISCSI_LOGIN_REQUEST_TYPE_SHIFT);
  304. login_wqe->cid = login_hdr->cid;
  305. login_wqe->cmd_sn = be32_to_cpu(login_hdr->cmdsn);
  306. login_wqe->exp_stat_sn = be32_to_cpu(login_hdr->exp_statsn);
  307. login_wqe->flags = ISCSI_LOGIN_REQUEST_UPDATE_EXP_STAT_SN;
  308. login_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
  309. login_wqe->resp_bd_list_addr_hi =
  310. (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
  311. dword = ((1 << ISCSI_LOGIN_REQUEST_NUM_RESP_BDS_SHIFT) |
  312. (bnx2i_conn->gen_pdu.resp_buf_size <<
  313. ISCSI_LOGIN_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
  314. login_wqe->resp_buffer = dword;
  315. login_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
  316. login_wqe->bd_list_addr_hi =
  317. (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
  318. login_wqe->num_bds = 1;
  319. login_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  320. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  321. return 0;
  322. }
  323. /**
  324. * bnx2i_send_iscsi_tmf - post iSCSI task management request MP WQE to hardware
  325. * @conn: iscsi connection
  326. * @mtask: driver command structure which is requesting
  327. * a WQE to sent to chip for further processing
  328. *
  329. * prepare and post an iSCSI Login request WQE to CNIC firmware
  330. */
  331. int bnx2i_send_iscsi_tmf(struct bnx2i_conn *bnx2i_conn,
  332. struct iscsi_task *mtask)
  333. {
  334. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  335. struct iscsi_tm *tmfabort_hdr;
  336. struct scsi_cmnd *ref_sc;
  337. struct iscsi_task *ctask;
  338. struct bnx2i_cmd *bnx2i_cmd;
  339. struct bnx2i_tmf_request *tmfabort_wqe;
  340. u32 dword;
  341. u32 scsi_lun[2];
  342. bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
  343. tmfabort_hdr = (struct iscsi_tm *)mtask->hdr;
  344. tmfabort_wqe = (struct bnx2i_tmf_request *)
  345. bnx2i_conn->ep->qp.sq_prod_qe;
  346. tmfabort_wqe->op_code = tmfabort_hdr->opcode;
  347. tmfabort_wqe->op_attr = tmfabort_hdr->flags;
  348. tmfabort_wqe->itt = (mtask->itt | (ISCSI_TASK_TYPE_MPATH << 14));
  349. tmfabort_wqe->reserved2 = 0;
  350. tmfabort_wqe->cmd_sn = be32_to_cpu(tmfabort_hdr->cmdsn);
  351. switch (tmfabort_hdr->flags & ISCSI_FLAG_TM_FUNC_MASK) {
  352. case ISCSI_TM_FUNC_ABORT_TASK:
  353. case ISCSI_TM_FUNC_TASK_REASSIGN:
  354. ctask = iscsi_itt_to_task(conn, tmfabort_hdr->rtt);
  355. if (!ctask || !ctask->sc)
  356. /*
  357. * the iscsi layer must have completed the cmd while
  358. * was starting up.
  359. *
  360. * Note: In the case of a SCSI cmd timeout, the task's
  361. * sc is still active; hence ctask->sc != 0
  362. * In this case, the task must be aborted
  363. */
  364. return 0;
  365. ref_sc = ctask->sc;
  366. if (ref_sc->sc_data_direction == DMA_TO_DEVICE)
  367. dword = (ISCSI_TASK_TYPE_WRITE <<
  368. ISCSI_CMD_REQUEST_TYPE_SHIFT);
  369. else
  370. dword = (ISCSI_TASK_TYPE_READ <<
  371. ISCSI_CMD_REQUEST_TYPE_SHIFT);
  372. tmfabort_wqe->ref_itt = (dword |
  373. (tmfabort_hdr->rtt & ISCSI_ITT_MASK));
  374. break;
  375. default:
  376. tmfabort_wqe->ref_itt = RESERVED_ITT;
  377. }
  378. memcpy(scsi_lun, tmfabort_hdr->lun, sizeof(struct scsi_lun));
  379. tmfabort_wqe->lun[0] = be32_to_cpu(scsi_lun[0]);
  380. tmfabort_wqe->lun[1] = be32_to_cpu(scsi_lun[1]);
  381. tmfabort_wqe->ref_cmd_sn = be32_to_cpu(tmfabort_hdr->refcmdsn);
  382. tmfabort_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
  383. tmfabort_wqe->bd_list_addr_hi = (u32)
  384. ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  385. tmfabort_wqe->num_bds = 1;
  386. tmfabort_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  387. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  388. return 0;
  389. }
  390. /**
  391. * bnx2i_send_iscsi_text - post iSCSI text WQE to hardware
  392. * @conn: iscsi connection
  393. * @mtask: driver command structure which is requesting
  394. * a WQE to sent to chip for further processing
  395. *
  396. * prepare and post an iSCSI Text request WQE to CNIC firmware
  397. */
  398. int bnx2i_send_iscsi_text(struct bnx2i_conn *bnx2i_conn,
  399. struct iscsi_task *mtask)
  400. {
  401. struct bnx2i_cmd *bnx2i_cmd;
  402. struct bnx2i_text_request *text_wqe;
  403. struct iscsi_text *text_hdr;
  404. u32 dword;
  405. bnx2i_cmd = (struct bnx2i_cmd *)mtask->dd_data;
  406. text_hdr = (struct iscsi_text *)mtask->hdr;
  407. text_wqe = (struct bnx2i_text_request *) bnx2i_conn->ep->qp.sq_prod_qe;
  408. memset(text_wqe, 0, sizeof(struct bnx2i_text_request));
  409. text_wqe->op_code = text_hdr->opcode;
  410. text_wqe->op_attr = text_hdr->flags;
  411. text_wqe->data_length = ntoh24(text_hdr->dlength);
  412. text_wqe->itt = mtask->itt |
  413. (ISCSI_TASK_TYPE_MPATH << ISCSI_TEXT_REQUEST_TYPE_SHIFT);
  414. text_wqe->ttt = be32_to_cpu(text_hdr->ttt);
  415. text_wqe->cmd_sn = be32_to_cpu(text_hdr->cmdsn);
  416. text_wqe->resp_bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.resp_bd_dma;
  417. text_wqe->resp_bd_list_addr_hi =
  418. (u32) ((u64) bnx2i_conn->gen_pdu.resp_bd_dma >> 32);
  419. dword = ((1 << ISCSI_TEXT_REQUEST_NUM_RESP_BDS_SHIFT) |
  420. (bnx2i_conn->gen_pdu.resp_buf_size <<
  421. ISCSI_TEXT_REQUEST_RESP_BUFFER_LENGTH_SHIFT));
  422. text_wqe->resp_buffer = dword;
  423. text_wqe->bd_list_addr_lo = (u32) bnx2i_conn->gen_pdu.req_bd_dma;
  424. text_wqe->bd_list_addr_hi =
  425. (u32) ((u64) bnx2i_conn->gen_pdu.req_bd_dma >> 32);
  426. text_wqe->num_bds = 1;
  427. text_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  428. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  429. return 0;
  430. }
  431. /**
  432. * bnx2i_send_iscsi_scsicmd - post iSCSI scsicmd request WQE to hardware
  433. * @conn: iscsi connection
  434. * @cmd: driver command structure which is requesting
  435. * a WQE to sent to chip for further processing
  436. *
  437. * prepare and post an iSCSI SCSI-CMD request WQE to CNIC firmware
  438. */
  439. int bnx2i_send_iscsi_scsicmd(struct bnx2i_conn *bnx2i_conn,
  440. struct bnx2i_cmd *cmd)
  441. {
  442. struct bnx2i_cmd_request *scsi_cmd_wqe;
  443. scsi_cmd_wqe = (struct bnx2i_cmd_request *)
  444. bnx2i_conn->ep->qp.sq_prod_qe;
  445. memcpy(scsi_cmd_wqe, &cmd->req, sizeof(struct bnx2i_cmd_request));
  446. scsi_cmd_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  447. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  448. return 0;
  449. }
  450. /**
  451. * bnx2i_send_iscsi_nopout - post iSCSI NOPOUT request WQE to hardware
  452. * @conn: iscsi connection
  453. * @cmd: driver command structure which is requesting
  454. * a WQE to sent to chip for further processing
  455. * @datap: payload buffer pointer
  456. * @data_len: payload data length
  457. * @unsol: indicated whether nopout pdu is unsolicited pdu or
  458. * in response to target's NOPIN w/ TTT != FFFFFFFF
  459. *
  460. * prepare and post a nopout request WQE to CNIC firmware
  461. */
  462. int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
  463. struct iscsi_task *task,
  464. char *datap, int data_len, int unsol)
  465. {
  466. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  467. struct bnx2i_cmd *bnx2i_cmd;
  468. struct bnx2i_nop_out_request *nopout_wqe;
  469. struct iscsi_nopout *nopout_hdr;
  470. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  471. nopout_hdr = (struct iscsi_nopout *)task->hdr;
  472. nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
  473. memset(nopout_wqe, 0x00, sizeof(struct bnx2i_nop_out_request));
  474. nopout_wqe->op_code = nopout_hdr->opcode;
  475. nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
  476. memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
  477. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  478. u32 tmp = nopout_wqe->lun[0];
  479. /* 57710 requires LUN field to be swapped */
  480. nopout_wqe->lun[0] = nopout_wqe->lun[1];
  481. nopout_wqe->lun[1] = tmp;
  482. }
  483. nopout_wqe->itt = ((u16)task->itt |
  484. (ISCSI_TASK_TYPE_MPATH <<
  485. ISCSI_TMF_REQUEST_TYPE_SHIFT));
  486. nopout_wqe->ttt = nopout_hdr->ttt;
  487. nopout_wqe->flags = 0;
  488. if (!unsol)
  489. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  490. else if (nopout_hdr->itt == RESERVED_ITT)
  491. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  492. nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
  493. nopout_wqe->data_length = data_len;
  494. if (data_len) {
  495. /* handle payload data, not required in first release */
  496. printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
  497. } else {
  498. nopout_wqe->bd_list_addr_lo = (u32)
  499. bnx2i_conn->hba->mp_bd_dma;
  500. nopout_wqe->bd_list_addr_hi =
  501. (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  502. nopout_wqe->num_bds = 1;
  503. }
  504. nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  505. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  506. return 0;
  507. }
  508. /**
  509. * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
  510. * @conn: iscsi connection
  511. * @cmd: driver command structure which is requesting
  512. * a WQE to sent to chip for further processing
  513. *
  514. * prepare and post logout request WQE to CNIC firmware
  515. */
  516. int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
  517. struct iscsi_task *task)
  518. {
  519. struct bnx2i_cmd *bnx2i_cmd;
  520. struct bnx2i_logout_request *logout_wqe;
  521. struct iscsi_logout *logout_hdr;
  522. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  523. logout_hdr = (struct iscsi_logout *)task->hdr;
  524. logout_wqe = (struct bnx2i_logout_request *)
  525. bnx2i_conn->ep->qp.sq_prod_qe;
  526. memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
  527. logout_wqe->op_code = logout_hdr->opcode;
  528. logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
  529. logout_wqe->op_attr =
  530. logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
  531. logout_wqe->itt = ((u16)task->itt |
  532. (ISCSI_TASK_TYPE_MPATH <<
  533. ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
  534. logout_wqe->data_length = 0;
  535. logout_wqe->cid = 0;
  536. logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
  537. logout_wqe->bd_list_addr_hi = (u32)
  538. ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  539. logout_wqe->num_bds = 1;
  540. logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  541. bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
  542. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  543. return 0;
  544. }
  545. /**
  546. * bnx2i_update_iscsi_conn - post iSCSI logout request WQE to hardware
  547. * @conn: iscsi connection which requires iscsi parameter update
  548. *
  549. * sends down iSCSI Conn Update request to move iSCSI conn to FFP
  550. */
  551. void bnx2i_update_iscsi_conn(struct iscsi_conn *conn)
  552. {
  553. struct bnx2i_conn *bnx2i_conn = conn->dd_data;
  554. struct bnx2i_hba *hba = bnx2i_conn->hba;
  555. struct kwqe *kwqe_arr[2];
  556. struct iscsi_kwqe_conn_update *update_wqe;
  557. struct iscsi_kwqe_conn_update conn_update_kwqe;
  558. update_wqe = &conn_update_kwqe;
  559. update_wqe->hdr.op_code = ISCSI_KWQE_OPCODE_UPDATE_CONN;
  560. update_wqe->hdr.flags =
  561. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  562. /* 5771x requires conn context id to be passed as is */
  563. if (test_bit(BNX2I_NX2_DEV_57710, &bnx2i_conn->ep->hba->cnic_dev_type))
  564. update_wqe->context_id = bnx2i_conn->ep->ep_cid;
  565. else
  566. update_wqe->context_id = (bnx2i_conn->ep->ep_cid >> 7);
  567. update_wqe->conn_flags = 0;
  568. if (conn->hdrdgst_en)
  569. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_HEADER_DIGEST;
  570. if (conn->datadgst_en)
  571. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_DATA_DIGEST;
  572. if (conn->session->initial_r2t_en)
  573. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_INITIAL_R2T;
  574. if (conn->session->imm_data_en)
  575. update_wqe->conn_flags |= ISCSI_KWQE_CONN_UPDATE_IMMEDIATE_DATA;
  576. update_wqe->max_send_pdu_length = conn->max_xmit_dlength;
  577. update_wqe->max_recv_pdu_length = conn->max_recv_dlength;
  578. update_wqe->first_burst_length = conn->session->first_burst;
  579. update_wqe->max_burst_length = conn->session->max_burst;
  580. update_wqe->exp_stat_sn = conn->exp_statsn;
  581. update_wqe->max_outstanding_r2ts = conn->session->max_r2t;
  582. update_wqe->session_error_recovery_level = conn->session->erl;
  583. iscsi_conn_printk(KERN_ALERT, conn,
  584. "bnx2i: conn update - MBL 0x%x FBL 0x%x"
  585. "MRDSL_I 0x%x MRDSL_T 0x%x \n",
  586. update_wqe->max_burst_length,
  587. update_wqe->first_burst_length,
  588. update_wqe->max_recv_pdu_length,
  589. update_wqe->max_send_pdu_length);
  590. kwqe_arr[0] = (struct kwqe *) update_wqe;
  591. if (hba->cnic && hba->cnic->submit_kwqes)
  592. hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
  593. }
  594. /**
  595. * bnx2i_ep_ofld_timer - post iSCSI logout request WQE to hardware
  596. * @data: endpoint (transport handle) structure pointer
  597. *
  598. * routine to handle connection offload/destroy request timeout
  599. */
  600. void bnx2i_ep_ofld_timer(unsigned long data)
  601. {
  602. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) data;
  603. if (ep->state == EP_STATE_OFLD_START) {
  604. printk(KERN_ALERT "ofld_timer: CONN_OFLD timeout\n");
  605. ep->state = EP_STATE_OFLD_FAILED;
  606. } else if (ep->state == EP_STATE_DISCONN_START) {
  607. printk(KERN_ALERT "ofld_timer: CONN_DISCON timeout\n");
  608. ep->state = EP_STATE_DISCONN_TIMEDOUT;
  609. } else if (ep->state == EP_STATE_CLEANUP_START) {
  610. printk(KERN_ALERT "ofld_timer: CONN_CLEANUP timeout\n");
  611. ep->state = EP_STATE_CLEANUP_FAILED;
  612. }
  613. wake_up_interruptible(&ep->ofld_wait);
  614. }
  615. static int bnx2i_power_of2(u32 val)
  616. {
  617. u32 power = 0;
  618. if (val & (val - 1))
  619. return power;
  620. val--;
  621. while (val) {
  622. val = val >> 1;
  623. power++;
  624. }
  625. return power;
  626. }
  627. /**
  628. * bnx2i_send_cmd_cleanup_req - send iscsi cmd context clean-up request
  629. * @hba: adapter structure pointer
  630. * @cmd: driver command structure which is requesting
  631. * a WQE to sent to chip for further processing
  632. *
  633. * prepares and posts CONN_OFLD_REQ1/2 KWQE
  634. */
  635. void bnx2i_send_cmd_cleanup_req(struct bnx2i_hba *hba, struct bnx2i_cmd *cmd)
  636. {
  637. struct bnx2i_cleanup_request *cmd_cleanup;
  638. cmd_cleanup =
  639. (struct bnx2i_cleanup_request *)cmd->conn->ep->qp.sq_prod_qe;
  640. memset(cmd_cleanup, 0x00, sizeof(struct bnx2i_cleanup_request));
  641. cmd_cleanup->op_code = ISCSI_OPCODE_CLEANUP_REQUEST;
  642. cmd_cleanup->itt = cmd->req.itt;
  643. cmd_cleanup->cq_index = 0; /* CQ# used for completion, 5771x only */
  644. bnx2i_ring_dbell_update_sq_params(cmd->conn, 1);
  645. }
  646. /**
  647. * bnx2i_send_conn_destroy - initiates iscsi connection teardown process
  648. * @hba: adapter structure pointer
  649. * @ep: endpoint (transport indentifier) structure
  650. *
  651. * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE to initiate
  652. * iscsi connection context clean-up process
  653. */
  654. int bnx2i_send_conn_destroy(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  655. {
  656. struct kwqe *kwqe_arr[2];
  657. struct iscsi_kwqe_conn_destroy conn_cleanup;
  658. int rc = -EINVAL;
  659. memset(&conn_cleanup, 0x00, sizeof(struct iscsi_kwqe_conn_destroy));
  660. conn_cleanup.hdr.op_code = ISCSI_KWQE_OPCODE_DESTROY_CONN;
  661. conn_cleanup.hdr.flags =
  662. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  663. /* 5771x requires conn context id to be passed as is */
  664. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  665. conn_cleanup.context_id = ep->ep_cid;
  666. else
  667. conn_cleanup.context_id = (ep->ep_cid >> 7);
  668. conn_cleanup.reserved0 = (u16)ep->ep_iscsi_cid;
  669. kwqe_arr[0] = (struct kwqe *) &conn_cleanup;
  670. if (hba->cnic && hba->cnic->submit_kwqes)
  671. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 1);
  672. return rc;
  673. }
  674. /**
  675. * bnx2i_570x_send_conn_ofld_req - initiates iscsi conn context setup process
  676. * @hba: adapter structure pointer
  677. * @ep: endpoint (transport indentifier) structure
  678. *
  679. * 5706/5708/5709 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  680. */
  681. static int bnx2i_570x_send_conn_ofld_req(struct bnx2i_hba *hba,
  682. struct bnx2i_endpoint *ep)
  683. {
  684. struct kwqe *kwqe_arr[2];
  685. struct iscsi_kwqe_conn_offload1 ofld_req1;
  686. struct iscsi_kwqe_conn_offload2 ofld_req2;
  687. dma_addr_t dma_addr;
  688. int num_kwqes = 2;
  689. u32 *ptbl;
  690. int rc = -EINVAL;
  691. ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
  692. ofld_req1.hdr.flags =
  693. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  694. ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
  695. dma_addr = ep->qp.sq_pgtbl_phys;
  696. ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
  697. ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  698. dma_addr = ep->qp.cq_pgtbl_phys;
  699. ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
  700. ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  701. ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
  702. ofld_req2.hdr.flags =
  703. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  704. dma_addr = ep->qp.rq_pgtbl_phys;
  705. ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
  706. ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  707. ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
  708. ofld_req2.sq_first_pte.hi = *ptbl++;
  709. ofld_req2.sq_first_pte.lo = *ptbl;
  710. ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
  711. ofld_req2.cq_first_pte.hi = *ptbl++;
  712. ofld_req2.cq_first_pte.lo = *ptbl;
  713. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  714. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  715. ofld_req2.num_additional_wqes = 0;
  716. if (hba->cnic && hba->cnic->submit_kwqes)
  717. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  718. return rc;
  719. }
  720. /**
  721. * bnx2i_5771x_send_conn_ofld_req - initiates iscsi connection context creation
  722. * @hba: adapter structure pointer
  723. * @ep: endpoint (transport indentifier) structure
  724. *
  725. * 57710 specific - prepares and posts CONN_OFLD_REQ1/2 KWQE
  726. */
  727. static int bnx2i_5771x_send_conn_ofld_req(struct bnx2i_hba *hba,
  728. struct bnx2i_endpoint *ep)
  729. {
  730. struct kwqe *kwqe_arr[5];
  731. struct iscsi_kwqe_conn_offload1 ofld_req1;
  732. struct iscsi_kwqe_conn_offload2 ofld_req2;
  733. struct iscsi_kwqe_conn_offload3 ofld_req3[1];
  734. dma_addr_t dma_addr;
  735. int num_kwqes = 2;
  736. u32 *ptbl;
  737. int rc = -EINVAL;
  738. ofld_req1.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN1;
  739. ofld_req1.hdr.flags =
  740. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  741. ofld_req1.iscsi_conn_id = (u16) ep->ep_iscsi_cid;
  742. dma_addr = ep->qp.sq_pgtbl_phys + ISCSI_SQ_DB_SIZE;
  743. ofld_req1.sq_page_table_addr_lo = (u32) dma_addr;
  744. ofld_req1.sq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  745. dma_addr = ep->qp.cq_pgtbl_phys + ISCSI_CQ_DB_SIZE;
  746. ofld_req1.cq_page_table_addr_lo = (u32) dma_addr;
  747. ofld_req1.cq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  748. ofld_req2.hdr.op_code = ISCSI_KWQE_OPCODE_OFFLOAD_CONN2;
  749. ofld_req2.hdr.flags =
  750. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  751. dma_addr = ep->qp.rq_pgtbl_phys + ISCSI_RQ_DB_SIZE;
  752. ofld_req2.rq_page_table_addr_lo = (u32) dma_addr;
  753. ofld_req2.rq_page_table_addr_hi = (u32) ((u64) dma_addr >> 32);
  754. ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
  755. ofld_req2.sq_first_pte.hi = *ptbl++;
  756. ofld_req2.sq_first_pte.lo = *ptbl;
  757. ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
  758. ofld_req2.cq_first_pte.hi = *ptbl++;
  759. ofld_req2.cq_first_pte.lo = *ptbl;
  760. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  761. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  762. ofld_req2.num_additional_wqes = 1;
  763. memset(ofld_req3, 0x00, sizeof(ofld_req3[0]));
  764. ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
  765. ofld_req3[0].qp_first_pte[0].hi = *ptbl++;
  766. ofld_req3[0].qp_first_pte[0].lo = *ptbl;
  767. kwqe_arr[2] = (struct kwqe *) ofld_req3;
  768. /* need if we decide to go with multiple KCQE's per conn */
  769. num_kwqes += 1;
  770. if (hba->cnic && hba->cnic->submit_kwqes)
  771. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  772. return rc;
  773. }
  774. /**
  775. * bnx2i_send_conn_ofld_req - initiates iscsi connection context setup process
  776. *
  777. * @hba: adapter structure pointer
  778. * @ep: endpoint (transport indentifier) structure
  779. *
  780. * this routine prepares and posts CONN_OFLD_REQ1/2 KWQE
  781. */
  782. int bnx2i_send_conn_ofld_req(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  783. {
  784. int rc;
  785. if (test_bit(BNX2I_NX2_DEV_57710, &hba->cnic_dev_type))
  786. rc = bnx2i_5771x_send_conn_ofld_req(hba, ep);
  787. else
  788. rc = bnx2i_570x_send_conn_ofld_req(hba, ep);
  789. return rc;
  790. }
  791. /**
  792. * setup_qp_page_tables - iscsi QP page table setup function
  793. * @ep: endpoint (transport indentifier) structure
  794. *
  795. * Sets up page tables for SQ/RQ/CQ, 1G/sec (5706/5708/5709) devices requires
  796. * 64-bit address in big endian format. Whereas 10G/sec (57710) requires
  797. * PT in little endian format
  798. */
  799. static void setup_qp_page_tables(struct bnx2i_endpoint *ep)
  800. {
  801. int num_pages;
  802. u32 *ptbl;
  803. dma_addr_t page;
  804. int cnic_dev_10g;
  805. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type))
  806. cnic_dev_10g = 1;
  807. else
  808. cnic_dev_10g = 0;
  809. /* SQ page table */
  810. memset(ep->qp.sq_pgtbl_virt, 0, ep->qp.sq_pgtbl_size);
  811. num_pages = ep->qp.sq_mem_size / PAGE_SIZE;
  812. page = ep->qp.sq_phys;
  813. if (cnic_dev_10g)
  814. ptbl = (u32 *)((u8 *)ep->qp.sq_pgtbl_virt + ISCSI_SQ_DB_SIZE);
  815. else
  816. ptbl = (u32 *) ep->qp.sq_pgtbl_virt;
  817. while (num_pages--) {
  818. if (cnic_dev_10g) {
  819. /* PTE is written in little endian format for 57710 */
  820. *ptbl = (u32) page;
  821. ptbl++;
  822. *ptbl = (u32) ((u64) page >> 32);
  823. ptbl++;
  824. page += PAGE_SIZE;
  825. } else {
  826. /* PTE is written in big endian format for
  827. * 5706/5708/5709 devices */
  828. *ptbl = (u32) ((u64) page >> 32);
  829. ptbl++;
  830. *ptbl = (u32) page;
  831. ptbl++;
  832. page += PAGE_SIZE;
  833. }
  834. }
  835. /* RQ page table */
  836. memset(ep->qp.rq_pgtbl_virt, 0, ep->qp.rq_pgtbl_size);
  837. num_pages = ep->qp.rq_mem_size / PAGE_SIZE;
  838. page = ep->qp.rq_phys;
  839. if (cnic_dev_10g)
  840. ptbl = (u32 *)((u8 *)ep->qp.rq_pgtbl_virt + ISCSI_RQ_DB_SIZE);
  841. else
  842. ptbl = (u32 *) ep->qp.rq_pgtbl_virt;
  843. while (num_pages--) {
  844. if (cnic_dev_10g) {
  845. /* PTE is written in little endian format for 57710 */
  846. *ptbl = (u32) page;
  847. ptbl++;
  848. *ptbl = (u32) ((u64) page >> 32);
  849. ptbl++;
  850. page += PAGE_SIZE;
  851. } else {
  852. /* PTE is written in big endian format for
  853. * 5706/5708/5709 devices */
  854. *ptbl = (u32) ((u64) page >> 32);
  855. ptbl++;
  856. *ptbl = (u32) page;
  857. ptbl++;
  858. page += PAGE_SIZE;
  859. }
  860. }
  861. /* CQ page table */
  862. memset(ep->qp.cq_pgtbl_virt, 0, ep->qp.cq_pgtbl_size);
  863. num_pages = ep->qp.cq_mem_size / PAGE_SIZE;
  864. page = ep->qp.cq_phys;
  865. if (cnic_dev_10g)
  866. ptbl = (u32 *)((u8 *)ep->qp.cq_pgtbl_virt + ISCSI_CQ_DB_SIZE);
  867. else
  868. ptbl = (u32 *) ep->qp.cq_pgtbl_virt;
  869. while (num_pages--) {
  870. if (cnic_dev_10g) {
  871. /* PTE is written in little endian format for 57710 */
  872. *ptbl = (u32) page;
  873. ptbl++;
  874. *ptbl = (u32) ((u64) page >> 32);
  875. ptbl++;
  876. page += PAGE_SIZE;
  877. } else {
  878. /* PTE is written in big endian format for
  879. * 5706/5708/5709 devices */
  880. *ptbl = (u32) ((u64) page >> 32);
  881. ptbl++;
  882. *ptbl = (u32) page;
  883. ptbl++;
  884. page += PAGE_SIZE;
  885. }
  886. }
  887. }
  888. /**
  889. * bnx2i_alloc_qp_resc - allocates required resources for QP.
  890. * @hba: adapter structure pointer
  891. * @ep: endpoint (transport indentifier) structure
  892. *
  893. * Allocate QP (transport layer for iSCSI connection) resources, DMA'able
  894. * memory for SQ/RQ/CQ and page tables. EP structure elements such
  895. * as producer/consumer indexes/pointers, queue sizes and page table
  896. * contents are setup
  897. */
  898. int bnx2i_alloc_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  899. {
  900. struct bnx2i_5771x_cq_db *cq_db;
  901. ep->hba = hba;
  902. ep->conn = NULL;
  903. ep->ep_cid = ep->ep_iscsi_cid = ep->ep_pg_cid = 0;
  904. /* Allocate page table memory for SQ which is page aligned */
  905. ep->qp.sq_mem_size = hba->max_sqes * BNX2I_SQ_WQE_SIZE;
  906. ep->qp.sq_mem_size =
  907. (ep->qp.sq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  908. ep->qp.sq_pgtbl_size =
  909. (ep->qp.sq_mem_size / PAGE_SIZE) * sizeof(void *);
  910. ep->qp.sq_pgtbl_size =
  911. (ep->qp.sq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  912. ep->qp.sq_pgtbl_virt =
  913. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
  914. &ep->qp.sq_pgtbl_phys, GFP_KERNEL);
  915. if (!ep->qp.sq_pgtbl_virt) {
  916. printk(KERN_ALERT "bnx2i: unable to alloc SQ PT mem (%d)\n",
  917. ep->qp.sq_pgtbl_size);
  918. goto mem_alloc_err;
  919. }
  920. /* Allocate memory area for actual SQ element */
  921. ep->qp.sq_virt =
  922. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
  923. &ep->qp.sq_phys, GFP_KERNEL);
  924. if (!ep->qp.sq_virt) {
  925. printk(KERN_ALERT "bnx2i: unable to alloc SQ BD memory %d\n",
  926. ep->qp.sq_mem_size);
  927. goto mem_alloc_err;
  928. }
  929. memset(ep->qp.sq_virt, 0x00, ep->qp.sq_mem_size);
  930. ep->qp.sq_first_qe = ep->qp.sq_virt;
  931. ep->qp.sq_prod_qe = ep->qp.sq_first_qe;
  932. ep->qp.sq_cons_qe = ep->qp.sq_first_qe;
  933. ep->qp.sq_last_qe = &ep->qp.sq_first_qe[hba->max_sqes - 1];
  934. ep->qp.sq_prod_idx = 0;
  935. ep->qp.sq_cons_idx = 0;
  936. ep->qp.sqe_left = hba->max_sqes;
  937. /* Allocate page table memory for CQ which is page aligned */
  938. ep->qp.cq_mem_size = hba->max_cqes * BNX2I_CQE_SIZE;
  939. ep->qp.cq_mem_size =
  940. (ep->qp.cq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  941. ep->qp.cq_pgtbl_size =
  942. (ep->qp.cq_mem_size / PAGE_SIZE) * sizeof(void *);
  943. ep->qp.cq_pgtbl_size =
  944. (ep->qp.cq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  945. ep->qp.cq_pgtbl_virt =
  946. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
  947. &ep->qp.cq_pgtbl_phys, GFP_KERNEL);
  948. if (!ep->qp.cq_pgtbl_virt) {
  949. printk(KERN_ALERT "bnx2i: unable to alloc CQ PT memory %d\n",
  950. ep->qp.cq_pgtbl_size);
  951. goto mem_alloc_err;
  952. }
  953. /* Allocate memory area for actual CQ element */
  954. ep->qp.cq_virt =
  955. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
  956. &ep->qp.cq_phys, GFP_KERNEL);
  957. if (!ep->qp.cq_virt) {
  958. printk(KERN_ALERT "bnx2i: unable to alloc CQ BD memory %d\n",
  959. ep->qp.cq_mem_size);
  960. goto mem_alloc_err;
  961. }
  962. memset(ep->qp.cq_virt, 0x00, ep->qp.cq_mem_size);
  963. ep->qp.cq_first_qe = ep->qp.cq_virt;
  964. ep->qp.cq_prod_qe = ep->qp.cq_first_qe;
  965. ep->qp.cq_cons_qe = ep->qp.cq_first_qe;
  966. ep->qp.cq_last_qe = &ep->qp.cq_first_qe[hba->max_cqes - 1];
  967. ep->qp.cq_prod_idx = 0;
  968. ep->qp.cq_cons_idx = 0;
  969. ep->qp.cqe_left = hba->max_cqes;
  970. ep->qp.cqe_exp_seq_sn = ISCSI_INITIAL_SN;
  971. ep->qp.cqe_size = hba->max_cqes;
  972. /* Invalidate all EQ CQE index, req only for 57710 */
  973. cq_db = (struct bnx2i_5771x_cq_db *) ep->qp.cq_pgtbl_virt;
  974. memset(cq_db->sqn, 0xFF, sizeof(cq_db->sqn[0]) * BNX2X_MAX_CQS);
  975. /* Allocate page table memory for RQ which is page aligned */
  976. ep->qp.rq_mem_size = hba->max_rqes * BNX2I_RQ_WQE_SIZE;
  977. ep->qp.rq_mem_size =
  978. (ep->qp.rq_mem_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  979. ep->qp.rq_pgtbl_size =
  980. (ep->qp.rq_mem_size / PAGE_SIZE) * sizeof(void *);
  981. ep->qp.rq_pgtbl_size =
  982. (ep->qp.rq_pgtbl_size + (PAGE_SIZE - 1)) & PAGE_MASK;
  983. ep->qp.rq_pgtbl_virt =
  984. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
  985. &ep->qp.rq_pgtbl_phys, GFP_KERNEL);
  986. if (!ep->qp.rq_pgtbl_virt) {
  987. printk(KERN_ALERT "bnx2i: unable to alloc RQ PT mem %d\n",
  988. ep->qp.rq_pgtbl_size);
  989. goto mem_alloc_err;
  990. }
  991. /* Allocate memory area for actual RQ element */
  992. ep->qp.rq_virt =
  993. dma_alloc_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
  994. &ep->qp.rq_phys, GFP_KERNEL);
  995. if (!ep->qp.rq_virt) {
  996. printk(KERN_ALERT "bnx2i: unable to alloc RQ BD memory %d\n",
  997. ep->qp.rq_mem_size);
  998. goto mem_alloc_err;
  999. }
  1000. ep->qp.rq_first_qe = ep->qp.rq_virt;
  1001. ep->qp.rq_prod_qe = ep->qp.rq_first_qe;
  1002. ep->qp.rq_cons_qe = ep->qp.rq_first_qe;
  1003. ep->qp.rq_last_qe = &ep->qp.rq_first_qe[hba->max_rqes - 1];
  1004. ep->qp.rq_prod_idx = 0x8000;
  1005. ep->qp.rq_cons_idx = 0;
  1006. ep->qp.rqe_left = hba->max_rqes;
  1007. setup_qp_page_tables(ep);
  1008. return 0;
  1009. mem_alloc_err:
  1010. bnx2i_free_qp_resc(hba, ep);
  1011. return -ENOMEM;
  1012. }
  1013. /**
  1014. * bnx2i_free_qp_resc - free memory resources held by QP
  1015. * @hba: adapter structure pointer
  1016. * @ep: endpoint (transport indentifier) structure
  1017. *
  1018. * Free QP resources - SQ/RQ/CQ memory and page tables.
  1019. */
  1020. void bnx2i_free_qp_resc(struct bnx2i_hba *hba, struct bnx2i_endpoint *ep)
  1021. {
  1022. if (ep->qp.ctx_base) {
  1023. iounmap(ep->qp.ctx_base);
  1024. ep->qp.ctx_base = NULL;
  1025. }
  1026. /* Free SQ mem */
  1027. if (ep->qp.sq_pgtbl_virt) {
  1028. dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_pgtbl_size,
  1029. ep->qp.sq_pgtbl_virt, ep->qp.sq_pgtbl_phys);
  1030. ep->qp.sq_pgtbl_virt = NULL;
  1031. ep->qp.sq_pgtbl_phys = 0;
  1032. }
  1033. if (ep->qp.sq_virt) {
  1034. dma_free_coherent(&hba->pcidev->dev, ep->qp.sq_mem_size,
  1035. ep->qp.sq_virt, ep->qp.sq_phys);
  1036. ep->qp.sq_virt = NULL;
  1037. ep->qp.sq_phys = 0;
  1038. }
  1039. /* Free RQ mem */
  1040. if (ep->qp.rq_pgtbl_virt) {
  1041. dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_pgtbl_size,
  1042. ep->qp.rq_pgtbl_virt, ep->qp.rq_pgtbl_phys);
  1043. ep->qp.rq_pgtbl_virt = NULL;
  1044. ep->qp.rq_pgtbl_phys = 0;
  1045. }
  1046. if (ep->qp.rq_virt) {
  1047. dma_free_coherent(&hba->pcidev->dev, ep->qp.rq_mem_size,
  1048. ep->qp.rq_virt, ep->qp.rq_phys);
  1049. ep->qp.rq_virt = NULL;
  1050. ep->qp.rq_phys = 0;
  1051. }
  1052. /* Free CQ mem */
  1053. if (ep->qp.cq_pgtbl_virt) {
  1054. dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_pgtbl_size,
  1055. ep->qp.cq_pgtbl_virt, ep->qp.cq_pgtbl_phys);
  1056. ep->qp.cq_pgtbl_virt = NULL;
  1057. ep->qp.cq_pgtbl_phys = 0;
  1058. }
  1059. if (ep->qp.cq_virt) {
  1060. dma_free_coherent(&hba->pcidev->dev, ep->qp.cq_mem_size,
  1061. ep->qp.cq_virt, ep->qp.cq_phys);
  1062. ep->qp.cq_virt = NULL;
  1063. ep->qp.cq_phys = 0;
  1064. }
  1065. }
  1066. /**
  1067. * bnx2i_send_fw_iscsi_init_msg - initiates initial handshake with iscsi f/w
  1068. * @hba: adapter structure pointer
  1069. *
  1070. * Send down iscsi_init KWQEs which initiates the initial handshake with the f/w
  1071. * This results in iSCSi support validation and on-chip context manager
  1072. * initialization. Firmware completes this handshake with a CQE carrying
  1073. * the result of iscsi support validation. Parameter carried by
  1074. * iscsi init request determines the number of offloaded connection and
  1075. * tolerance level for iscsi protocol violation this hba/chip can support
  1076. */
  1077. int bnx2i_send_fw_iscsi_init_msg(struct bnx2i_hba *hba)
  1078. {
  1079. struct kwqe *kwqe_arr[3];
  1080. struct iscsi_kwqe_init1 iscsi_init;
  1081. struct iscsi_kwqe_init2 iscsi_init2;
  1082. int rc = 0;
  1083. u64 mask64;
  1084. bnx2i_adjust_qp_size(hba);
  1085. iscsi_init.flags =
  1086. ISCSI_PAGE_SIZE_4K << ISCSI_KWQE_INIT1_PAGE_SIZE_SHIFT;
  1087. if (en_tcp_dack)
  1088. iscsi_init.flags |= ISCSI_KWQE_INIT1_DELAYED_ACK_ENABLE;
  1089. iscsi_init.reserved0 = 0;
  1090. iscsi_init.num_cqs = 1;
  1091. iscsi_init.hdr.op_code = ISCSI_KWQE_OPCODE_INIT1;
  1092. iscsi_init.hdr.flags =
  1093. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1094. iscsi_init.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
  1095. iscsi_init.dummy_buffer_addr_hi =
  1096. (u32) ((u64) hba->dummy_buf_dma >> 32);
  1097. hba->num_ccell = hba->max_sqes >> 1;
  1098. hba->ctx_ccell_tasks =
  1099. ((hba->num_ccell & 0xFFFF) | (hba->max_sqes << 16));
  1100. iscsi_init.num_ccells_per_conn = hba->num_ccell;
  1101. iscsi_init.num_tasks_per_conn = hba->max_sqes;
  1102. iscsi_init.sq_wqes_per_page = PAGE_SIZE / BNX2I_SQ_WQE_SIZE;
  1103. iscsi_init.sq_num_wqes = hba->max_sqes;
  1104. iscsi_init.cq_log_wqes_per_page =
  1105. (u8) bnx2i_power_of2(PAGE_SIZE / BNX2I_CQE_SIZE);
  1106. iscsi_init.cq_num_wqes = hba->max_cqes;
  1107. iscsi_init.cq_num_pages = (hba->max_cqes * BNX2I_CQE_SIZE +
  1108. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1109. iscsi_init.sq_num_pages = (hba->max_sqes * BNX2I_SQ_WQE_SIZE +
  1110. (PAGE_SIZE - 1)) / PAGE_SIZE;
  1111. iscsi_init.rq_buffer_size = BNX2I_RQ_WQE_SIZE;
  1112. iscsi_init.rq_num_wqes = hba->max_rqes;
  1113. iscsi_init2.hdr.op_code = ISCSI_KWQE_OPCODE_INIT2;
  1114. iscsi_init2.hdr.flags =
  1115. (ISCSI_KWQE_LAYER_CODE << ISCSI_KWQE_HEADER_LAYER_CODE_SHIFT);
  1116. iscsi_init2.max_cq_sqn = hba->max_cqes * 2 + 1;
  1117. mask64 = 0x0ULL;
  1118. mask64 |= (
  1119. /* CISCO MDS */
  1120. (1UL <<
  1121. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV) |
  1122. /* HP MSA1510i */
  1123. (1UL <<
  1124. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN) |
  1125. /* EMC */
  1126. (1ULL << ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN));
  1127. if (error_mask1)
  1128. iscsi_init2.error_bit_map[0] = error_mask1;
  1129. else
  1130. iscsi_init2.error_bit_map[0] = (u32) mask64;
  1131. if (error_mask2)
  1132. iscsi_init2.error_bit_map[1] = error_mask2;
  1133. else
  1134. iscsi_init2.error_bit_map[1] = (u32) (mask64 >> 32);
  1135. iscsi_error_mask = mask64;
  1136. kwqe_arr[0] = (struct kwqe *) &iscsi_init;
  1137. kwqe_arr[1] = (struct kwqe *) &iscsi_init2;
  1138. if (hba->cnic && hba->cnic->submit_kwqes)
  1139. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, 2);
  1140. return rc;
  1141. }
  1142. /**
  1143. * bnx2i_process_scsi_cmd_resp - this function handles scsi cmd completion.
  1144. * @conn: iscsi connection
  1145. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1146. *
  1147. * process SCSI CMD Response CQE & complete the request to SCSI-ML
  1148. */
  1149. static int bnx2i_process_scsi_cmd_resp(struct iscsi_session *session,
  1150. struct bnx2i_conn *bnx2i_conn,
  1151. struct cqe *cqe)
  1152. {
  1153. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1154. struct bnx2i_cmd_response *resp_cqe;
  1155. struct bnx2i_cmd *bnx2i_cmd;
  1156. struct iscsi_task *task;
  1157. struct iscsi_cmd_rsp *hdr;
  1158. u32 datalen = 0;
  1159. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1160. spin_lock(&session->lock);
  1161. task = iscsi_itt_to_task(conn,
  1162. resp_cqe->itt & ISCSI_CMD_RESPONSE_INDEX);
  1163. if (!task)
  1164. goto fail;
  1165. bnx2i_cmd = task->dd_data;
  1166. if (bnx2i_cmd->req.op_attr & ISCSI_CMD_REQUEST_READ) {
  1167. conn->datain_pdus_cnt +=
  1168. resp_cqe->task_stat.read_stat.num_data_outs;
  1169. conn->rxdata_octets +=
  1170. bnx2i_cmd->req.total_data_transfer_length;
  1171. } else {
  1172. conn->dataout_pdus_cnt +=
  1173. resp_cqe->task_stat.read_stat.num_data_outs;
  1174. conn->r2t_pdus_cnt +=
  1175. resp_cqe->task_stat.read_stat.num_r2ts;
  1176. conn->txdata_octets +=
  1177. bnx2i_cmd->req.total_data_transfer_length;
  1178. }
  1179. bnx2i_iscsi_unmap_sg_list(bnx2i_cmd);
  1180. hdr = (struct iscsi_cmd_rsp *)task->hdr;
  1181. resp_cqe = (struct bnx2i_cmd_response *)cqe;
  1182. hdr->opcode = resp_cqe->op_code;
  1183. hdr->max_cmdsn = cpu_to_be32(resp_cqe->max_cmd_sn);
  1184. hdr->exp_cmdsn = cpu_to_be32(resp_cqe->exp_cmd_sn);
  1185. hdr->response = resp_cqe->response;
  1186. hdr->cmd_status = resp_cqe->status;
  1187. hdr->flags = resp_cqe->response_flags;
  1188. hdr->residual_count = cpu_to_be32(resp_cqe->residual_count);
  1189. if (resp_cqe->op_code == ISCSI_OP_SCSI_DATA_IN)
  1190. goto done;
  1191. if (resp_cqe->status == SAM_STAT_CHECK_CONDITION) {
  1192. datalen = resp_cqe->data_length;
  1193. if (datalen < 2)
  1194. goto done;
  1195. if (datalen > BNX2I_RQ_WQE_SIZE) {
  1196. iscsi_conn_printk(KERN_ERR, conn,
  1197. "sense data len %d > RQ sz\n",
  1198. datalen);
  1199. datalen = BNX2I_RQ_WQE_SIZE;
  1200. } else if (datalen > ISCSI_DEF_MAX_RECV_SEG_LEN) {
  1201. iscsi_conn_printk(KERN_ERR, conn,
  1202. "sense data len %d > conn data\n",
  1203. datalen);
  1204. datalen = ISCSI_DEF_MAX_RECV_SEG_LEN;
  1205. }
  1206. bnx2i_get_rq_buf(bnx2i_cmd->conn, conn->data, datalen);
  1207. bnx2i_put_rq_buf(bnx2i_cmd->conn, 1);
  1208. }
  1209. done:
  1210. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr,
  1211. conn->data, datalen);
  1212. fail:
  1213. spin_unlock(&session->lock);
  1214. return 0;
  1215. }
  1216. /**
  1217. * bnx2i_process_login_resp - this function handles iscsi login response
  1218. * @session: iscsi session pointer
  1219. * @bnx2i_conn: iscsi connection pointer
  1220. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1221. *
  1222. * process Login Response CQE & complete it to open-iscsi user daemon
  1223. */
  1224. static int bnx2i_process_login_resp(struct iscsi_session *session,
  1225. struct bnx2i_conn *bnx2i_conn,
  1226. struct cqe *cqe)
  1227. {
  1228. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1229. struct iscsi_task *task;
  1230. struct bnx2i_login_response *login;
  1231. struct iscsi_login_rsp *resp_hdr;
  1232. int pld_len;
  1233. int pad_len;
  1234. login = (struct bnx2i_login_response *) cqe;
  1235. spin_lock(&session->lock);
  1236. task = iscsi_itt_to_task(conn,
  1237. login->itt & ISCSI_LOGIN_RESPONSE_INDEX);
  1238. if (!task)
  1239. goto done;
  1240. resp_hdr = (struct iscsi_login_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1241. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1242. resp_hdr->opcode = login->op_code;
  1243. resp_hdr->flags = login->response_flags;
  1244. resp_hdr->max_version = login->version_max;
  1245. resp_hdr->active_version = login->version_active;
  1246. resp_hdr->hlength = 0;
  1247. hton24(resp_hdr->dlength, login->data_length);
  1248. memcpy(resp_hdr->isid, &login->isid_lo, 6);
  1249. resp_hdr->tsih = cpu_to_be16(login->tsih);
  1250. resp_hdr->itt = task->hdr->itt;
  1251. resp_hdr->statsn = cpu_to_be32(login->stat_sn);
  1252. resp_hdr->exp_cmdsn = cpu_to_be32(login->exp_cmd_sn);
  1253. resp_hdr->max_cmdsn = cpu_to_be32(login->max_cmd_sn);
  1254. resp_hdr->status_class = login->status_class;
  1255. resp_hdr->status_detail = login->status_detail;
  1256. pld_len = login->data_length;
  1257. bnx2i_conn->gen_pdu.resp_wr_ptr =
  1258. bnx2i_conn->gen_pdu.resp_buf + pld_len;
  1259. pad_len = 0;
  1260. if (pld_len & 0x3)
  1261. pad_len = 4 - (pld_len % 4);
  1262. if (pad_len) {
  1263. int i = 0;
  1264. for (i = 0; i < pad_len; i++) {
  1265. bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
  1266. bnx2i_conn->gen_pdu.resp_wr_ptr++;
  1267. }
  1268. }
  1269. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
  1270. bnx2i_conn->gen_pdu.resp_buf,
  1271. bnx2i_conn->gen_pdu.resp_wr_ptr - bnx2i_conn->gen_pdu.resp_buf);
  1272. done:
  1273. spin_unlock(&session->lock);
  1274. return 0;
  1275. }
  1276. /**
  1277. * bnx2i_process_text_resp - this function handles iscsi text response
  1278. * @session: iscsi session pointer
  1279. * @bnx2i_conn: iscsi connection pointer
  1280. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1281. *
  1282. * process iSCSI Text Response CQE& complete it to open-iscsi user daemon
  1283. */
  1284. static int bnx2i_process_text_resp(struct iscsi_session *session,
  1285. struct bnx2i_conn *bnx2i_conn,
  1286. struct cqe *cqe)
  1287. {
  1288. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1289. struct iscsi_task *task;
  1290. struct bnx2i_text_response *text;
  1291. struct iscsi_text_rsp *resp_hdr;
  1292. int pld_len;
  1293. int pad_len;
  1294. text = (struct bnx2i_text_response *) cqe;
  1295. spin_lock(&session->lock);
  1296. task = iscsi_itt_to_task(conn, text->itt & ISCSI_LOGIN_RESPONSE_INDEX);
  1297. if (!task)
  1298. goto done;
  1299. resp_hdr = (struct iscsi_text_rsp *)&bnx2i_conn->gen_pdu.resp_hdr;
  1300. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1301. resp_hdr->opcode = text->op_code;
  1302. resp_hdr->flags = text->response_flags;
  1303. resp_hdr->hlength = 0;
  1304. hton24(resp_hdr->dlength, text->data_length);
  1305. resp_hdr->itt = task->hdr->itt;
  1306. resp_hdr->ttt = cpu_to_be32(text->ttt);
  1307. resp_hdr->statsn = task->hdr->exp_statsn;
  1308. resp_hdr->exp_cmdsn = cpu_to_be32(text->exp_cmd_sn);
  1309. resp_hdr->max_cmdsn = cpu_to_be32(text->max_cmd_sn);
  1310. pld_len = text->data_length;
  1311. bnx2i_conn->gen_pdu.resp_wr_ptr = bnx2i_conn->gen_pdu.resp_buf +
  1312. pld_len;
  1313. pad_len = 0;
  1314. if (pld_len & 0x3)
  1315. pad_len = 4 - (pld_len % 4);
  1316. if (pad_len) {
  1317. int i = 0;
  1318. for (i = 0; i < pad_len; i++) {
  1319. bnx2i_conn->gen_pdu.resp_wr_ptr[0] = 0;
  1320. bnx2i_conn->gen_pdu.resp_wr_ptr++;
  1321. }
  1322. }
  1323. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr,
  1324. bnx2i_conn->gen_pdu.resp_buf,
  1325. bnx2i_conn->gen_pdu.resp_wr_ptr -
  1326. bnx2i_conn->gen_pdu.resp_buf);
  1327. done:
  1328. spin_unlock(&session->lock);
  1329. return 0;
  1330. }
  1331. /**
  1332. * bnx2i_process_tmf_resp - this function handles iscsi TMF response
  1333. * @session: iscsi session pointer
  1334. * @bnx2i_conn: iscsi connection pointer
  1335. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1336. *
  1337. * process iSCSI TMF Response CQE and wake up the driver eh thread.
  1338. */
  1339. static int bnx2i_process_tmf_resp(struct iscsi_session *session,
  1340. struct bnx2i_conn *bnx2i_conn,
  1341. struct cqe *cqe)
  1342. {
  1343. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1344. struct iscsi_task *task;
  1345. struct bnx2i_tmf_response *tmf_cqe;
  1346. struct iscsi_tm_rsp *resp_hdr;
  1347. tmf_cqe = (struct bnx2i_tmf_response *)cqe;
  1348. spin_lock(&session->lock);
  1349. task = iscsi_itt_to_task(conn,
  1350. tmf_cqe->itt & ISCSI_TMF_RESPONSE_INDEX);
  1351. if (!task)
  1352. goto done;
  1353. resp_hdr = (struct iscsi_tm_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1354. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1355. resp_hdr->opcode = tmf_cqe->op_code;
  1356. resp_hdr->max_cmdsn = cpu_to_be32(tmf_cqe->max_cmd_sn);
  1357. resp_hdr->exp_cmdsn = cpu_to_be32(tmf_cqe->exp_cmd_sn);
  1358. resp_hdr->itt = task->hdr->itt;
  1359. resp_hdr->response = tmf_cqe->response;
  1360. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1361. done:
  1362. spin_unlock(&session->lock);
  1363. return 0;
  1364. }
  1365. /**
  1366. * bnx2i_process_logout_resp - this function handles iscsi logout response
  1367. * @session: iscsi session pointer
  1368. * @bnx2i_conn: iscsi connection pointer
  1369. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1370. *
  1371. * process iSCSI Logout Response CQE & make function call to
  1372. * notify the user daemon.
  1373. */
  1374. static int bnx2i_process_logout_resp(struct iscsi_session *session,
  1375. struct bnx2i_conn *bnx2i_conn,
  1376. struct cqe *cqe)
  1377. {
  1378. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1379. struct iscsi_task *task;
  1380. struct bnx2i_logout_response *logout;
  1381. struct iscsi_logout_rsp *resp_hdr;
  1382. logout = (struct bnx2i_logout_response *) cqe;
  1383. spin_lock(&session->lock);
  1384. task = iscsi_itt_to_task(conn,
  1385. logout->itt & ISCSI_LOGOUT_RESPONSE_INDEX);
  1386. if (!task)
  1387. goto done;
  1388. resp_hdr = (struct iscsi_logout_rsp *) &bnx2i_conn->gen_pdu.resp_hdr;
  1389. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1390. resp_hdr->opcode = logout->op_code;
  1391. resp_hdr->flags = logout->response;
  1392. resp_hdr->hlength = 0;
  1393. resp_hdr->itt = task->hdr->itt;
  1394. resp_hdr->statsn = task->hdr->exp_statsn;
  1395. resp_hdr->exp_cmdsn = cpu_to_be32(logout->exp_cmd_sn);
  1396. resp_hdr->max_cmdsn = cpu_to_be32(logout->max_cmd_sn);
  1397. resp_hdr->t2wait = cpu_to_be32(logout->time_to_wait);
  1398. resp_hdr->t2retain = cpu_to_be32(logout->time_to_retain);
  1399. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1400. bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
  1401. done:
  1402. spin_unlock(&session->lock);
  1403. return 0;
  1404. }
  1405. /**
  1406. * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
  1407. * @session: iscsi session pointer
  1408. * @bnx2i_conn: iscsi connection pointer
  1409. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1410. *
  1411. * process iSCSI NOPIN local completion CQE, frees IIT and command structures
  1412. */
  1413. static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
  1414. struct bnx2i_conn *bnx2i_conn,
  1415. struct cqe *cqe)
  1416. {
  1417. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1418. struct bnx2i_nop_in_msg *nop_in;
  1419. struct iscsi_task *task;
  1420. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1421. spin_lock(&session->lock);
  1422. task = iscsi_itt_to_task(conn,
  1423. nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
  1424. if (task)
  1425. __iscsi_put_task(task);
  1426. spin_unlock(&session->lock);
  1427. }
  1428. /**
  1429. * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
  1430. * @conn: iscsi connection
  1431. *
  1432. * Firmware advances RQ producer index for every unsolicited PDU even if
  1433. * payload data length is '0'. This function makes corresponding
  1434. * adjustments on the driver side to match this f/w behavior
  1435. */
  1436. static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
  1437. {
  1438. char dummy_rq_data[2];
  1439. bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
  1440. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1441. }
  1442. /**
  1443. * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
  1444. * @session: iscsi session pointer
  1445. * @bnx2i_conn: iscsi connection pointer
  1446. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1447. *
  1448. * process iSCSI target's proactive iSCSI NOPIN request
  1449. */
  1450. static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
  1451. struct bnx2i_conn *bnx2i_conn,
  1452. struct cqe *cqe)
  1453. {
  1454. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1455. struct iscsi_task *task;
  1456. struct bnx2i_nop_in_msg *nop_in;
  1457. struct iscsi_nopin *hdr;
  1458. int tgt_async_nop = 0;
  1459. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1460. spin_lock(&session->lock);
  1461. hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
  1462. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1463. hdr->opcode = nop_in->op_code;
  1464. hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
  1465. hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
  1466. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1467. if (nop_in->itt == (u16) RESERVED_ITT) {
  1468. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1469. hdr->itt = RESERVED_ITT;
  1470. tgt_async_nop = 1;
  1471. goto done;
  1472. }
  1473. /* this is a response to one of our nop-outs */
  1474. task = iscsi_itt_to_task(conn,
  1475. (itt_t) (nop_in->itt & ISCSI_NOP_IN_MSG_INDEX));
  1476. if (task) {
  1477. hdr->flags = ISCSI_FLAG_CMD_FINAL;
  1478. hdr->itt = task->hdr->itt;
  1479. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1480. memcpy(hdr->lun, nop_in->lun, 8);
  1481. }
  1482. done:
  1483. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1484. spin_unlock(&session->lock);
  1485. return tgt_async_nop;
  1486. }
  1487. /**
  1488. * bnx2i_process_async_mesg - this function handles iscsi async message
  1489. * @session: iscsi session pointer
  1490. * @bnx2i_conn: iscsi connection pointer
  1491. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1492. *
  1493. * process iSCSI ASYNC Message
  1494. */
  1495. static void bnx2i_process_async_mesg(struct iscsi_session *session,
  1496. struct bnx2i_conn *bnx2i_conn,
  1497. struct cqe *cqe)
  1498. {
  1499. struct bnx2i_async_msg *async_cqe;
  1500. struct iscsi_async *resp_hdr;
  1501. u8 async_event;
  1502. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1503. async_cqe = (struct bnx2i_async_msg *)cqe;
  1504. async_event = async_cqe->async_event;
  1505. if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
  1506. iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
  1507. "async: scsi events not supported\n");
  1508. return;
  1509. }
  1510. spin_lock(&session->lock);
  1511. resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
  1512. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1513. resp_hdr->opcode = async_cqe->op_code;
  1514. resp_hdr->flags = 0x80;
  1515. memcpy(resp_hdr->lun, async_cqe->lun, 8);
  1516. resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
  1517. resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
  1518. resp_hdr->async_event = async_cqe->async_event;
  1519. resp_hdr->async_vcode = async_cqe->async_vcode;
  1520. resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
  1521. resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
  1522. resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
  1523. __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
  1524. (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1525. spin_unlock(&session->lock);
  1526. }
  1527. /**
  1528. * bnx2i_process_reject_mesg - process iscsi reject pdu
  1529. * @session: iscsi session pointer
  1530. * @bnx2i_conn: iscsi connection pointer
  1531. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1532. *
  1533. * process iSCSI REJECT message
  1534. */
  1535. static void bnx2i_process_reject_mesg(struct iscsi_session *session,
  1536. struct bnx2i_conn *bnx2i_conn,
  1537. struct cqe *cqe)
  1538. {
  1539. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1540. struct bnx2i_reject_msg *reject;
  1541. struct iscsi_reject *hdr;
  1542. reject = (struct bnx2i_reject_msg *) cqe;
  1543. if (reject->data_length) {
  1544. bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
  1545. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1546. } else
  1547. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1548. spin_lock(&session->lock);
  1549. hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
  1550. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1551. hdr->opcode = reject->op_code;
  1552. hdr->reason = reject->reason;
  1553. hton24(hdr->dlength, reject->data_length);
  1554. hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
  1555. hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
  1556. hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
  1557. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
  1558. reject->data_length);
  1559. spin_unlock(&session->lock);
  1560. }
  1561. /**
  1562. * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
  1563. * @session: iscsi session pointer
  1564. * @bnx2i_conn: iscsi connection pointer
  1565. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1566. *
  1567. * process command cleanup response CQE during conn shutdown or error recovery
  1568. */
  1569. static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
  1570. struct bnx2i_conn *bnx2i_conn,
  1571. struct cqe *cqe)
  1572. {
  1573. struct bnx2i_cleanup_response *cmd_clean_rsp;
  1574. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1575. struct iscsi_task *task;
  1576. cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
  1577. spin_lock(&session->lock);
  1578. task = iscsi_itt_to_task(conn,
  1579. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1580. if (!task)
  1581. printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
  1582. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1583. spin_unlock(&session->lock);
  1584. complete(&bnx2i_conn->cmd_cleanup_cmpl);
  1585. }
  1586. /**
  1587. * bnx2i_process_new_cqes - process newly DMA'ed CQE's
  1588. * @bnx2i_conn: iscsi connection
  1589. *
  1590. * this function is called by generic KCQ handler to process all pending CQE's
  1591. */
  1592. static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
  1593. {
  1594. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1595. struct iscsi_session *session = conn->session;
  1596. struct qp_info *qp = &bnx2i_conn->ep->qp;
  1597. struct bnx2i_nop_in_msg *nopin;
  1598. int tgt_async_msg;
  1599. while (1) {
  1600. nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
  1601. if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
  1602. break;
  1603. if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx))) {
  1604. if (nopin->op_code == ISCSI_OP_NOOP_IN &&
  1605. nopin->itt == (u16) RESERVED_ITT) {
  1606. printk(KERN_ALERT "bnx2i: Unsolicited "
  1607. "NOP-In detected for suspended "
  1608. "connection dev=%s!\n",
  1609. bnx2i_conn->hba->netdev->name);
  1610. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1611. goto cqe_out;
  1612. }
  1613. break;
  1614. }
  1615. tgt_async_msg = 0;
  1616. switch (nopin->op_code) {
  1617. case ISCSI_OP_SCSI_CMD_RSP:
  1618. case ISCSI_OP_SCSI_DATA_IN:
  1619. bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
  1620. qp->cq_cons_qe);
  1621. break;
  1622. case ISCSI_OP_LOGIN_RSP:
  1623. bnx2i_process_login_resp(session, bnx2i_conn,
  1624. qp->cq_cons_qe);
  1625. break;
  1626. case ISCSI_OP_SCSI_TMFUNC_RSP:
  1627. bnx2i_process_tmf_resp(session, bnx2i_conn,
  1628. qp->cq_cons_qe);
  1629. break;
  1630. case ISCSI_OP_TEXT_RSP:
  1631. bnx2i_process_text_resp(session, bnx2i_conn,
  1632. qp->cq_cons_qe);
  1633. break;
  1634. case ISCSI_OP_LOGOUT_RSP:
  1635. bnx2i_process_logout_resp(session, bnx2i_conn,
  1636. qp->cq_cons_qe);
  1637. break;
  1638. case ISCSI_OP_NOOP_IN:
  1639. if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
  1640. qp->cq_cons_qe))
  1641. tgt_async_msg = 1;
  1642. break;
  1643. case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
  1644. bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
  1645. qp->cq_cons_qe);
  1646. break;
  1647. case ISCSI_OP_ASYNC_EVENT:
  1648. bnx2i_process_async_mesg(session, bnx2i_conn,
  1649. qp->cq_cons_qe);
  1650. tgt_async_msg = 1;
  1651. break;
  1652. case ISCSI_OP_REJECT:
  1653. bnx2i_process_reject_mesg(session, bnx2i_conn,
  1654. qp->cq_cons_qe);
  1655. break;
  1656. case ISCSI_OPCODE_CLEANUP_RESPONSE:
  1657. bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
  1658. qp->cq_cons_qe);
  1659. break;
  1660. default:
  1661. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  1662. nopin->op_code);
  1663. }
  1664. if (!tgt_async_msg)
  1665. bnx2i_conn->ep->num_active_cmds--;
  1666. cqe_out:
  1667. /* clear out in production version only, till beta keep opcode
  1668. * field intact, will be helpful in debugging (context dump)
  1669. * nopin->op_code = 0;
  1670. */
  1671. qp->cqe_exp_seq_sn++;
  1672. if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
  1673. qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
  1674. if (qp->cq_cons_qe == qp->cq_last_qe) {
  1675. qp->cq_cons_qe = qp->cq_first_qe;
  1676. qp->cq_cons_idx = 0;
  1677. } else {
  1678. qp->cq_cons_qe++;
  1679. qp->cq_cons_idx++;
  1680. }
  1681. }
  1682. bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
  1683. }
  1684. /**
  1685. * bnx2i_fastpath_notification - process global event queue (KCQ)
  1686. * @hba: adapter structure pointer
  1687. * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
  1688. *
  1689. * Fast path event notification handler, KCQ entry carries context id
  1690. * of the connection that has 1 or more pending CQ entries
  1691. */
  1692. static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
  1693. struct iscsi_kcqe *new_cqe_kcqe)
  1694. {
  1695. struct bnx2i_conn *conn;
  1696. u32 iscsi_cid;
  1697. iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
  1698. conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1699. if (!conn) {
  1700. printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
  1701. return;
  1702. }
  1703. if (!conn->ep) {
  1704. printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
  1705. return;
  1706. }
  1707. bnx2i_process_new_cqes(conn);
  1708. }
  1709. /**
  1710. * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
  1711. * @hba: adapter structure pointer
  1712. * @update_kcqe: kcqe pointer
  1713. *
  1714. * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
  1715. */
  1716. static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
  1717. struct iscsi_kcqe *update_kcqe)
  1718. {
  1719. struct bnx2i_conn *conn;
  1720. u32 iscsi_cid;
  1721. iscsi_cid = update_kcqe->iscsi_conn_id;
  1722. conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1723. if (!conn) {
  1724. printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
  1725. return;
  1726. }
  1727. if (!conn->ep) {
  1728. printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
  1729. return;
  1730. }
  1731. if (update_kcqe->completion_status) {
  1732. printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
  1733. conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
  1734. } else
  1735. conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
  1736. wake_up_interruptible(&conn->ep->ofld_wait);
  1737. }
  1738. /**
  1739. * bnx2i_recovery_que_add_conn - add connection to recovery queue
  1740. * @hba: adapter structure pointer
  1741. * @bnx2i_conn: iscsi connection
  1742. *
  1743. * Add connection to recovery queue and schedule adapter eh worker
  1744. */
  1745. static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
  1746. struct bnx2i_conn *bnx2i_conn)
  1747. {
  1748. iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
  1749. ISCSI_ERR_CONN_FAILED);
  1750. }
  1751. /**
  1752. * bnx2i_process_tcp_error - process error notification on a given connection
  1753. *
  1754. * @hba: adapter structure pointer
  1755. * @tcp_err: tcp error kcqe pointer
  1756. *
  1757. * handles tcp level error notifications from FW.
  1758. */
  1759. static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
  1760. struct iscsi_kcqe *tcp_err)
  1761. {
  1762. struct bnx2i_conn *bnx2i_conn;
  1763. u32 iscsi_cid;
  1764. iscsi_cid = tcp_err->iscsi_conn_id;
  1765. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1766. if (!bnx2i_conn) {
  1767. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1768. return;
  1769. }
  1770. printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
  1771. iscsi_cid, tcp_err->completion_status);
  1772. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  1773. }
  1774. /**
  1775. * bnx2i_process_iscsi_error - process error notification on a given connection
  1776. * @hba: adapter structure pointer
  1777. * @iscsi_err: iscsi error kcqe pointer
  1778. *
  1779. * handles iscsi error notifications from the FW. Firmware based in initial
  1780. * handshake classifies iscsi protocol / TCP rfc violation into either
  1781. * warning or error indications. If indication is of "Error" type, driver
  1782. * will initiate session recovery for that connection/session. For
  1783. * "Warning" type indication, driver will put out a system log message
  1784. * (there will be only one message for each type for the life of the
  1785. * session, this is to avoid un-necessarily overloading the system)
  1786. */
  1787. static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
  1788. struct iscsi_kcqe *iscsi_err)
  1789. {
  1790. struct bnx2i_conn *bnx2i_conn;
  1791. u32 iscsi_cid;
  1792. char warn_notice[] = "iscsi_warning";
  1793. char error_notice[] = "iscsi_error";
  1794. char additional_notice[64];
  1795. char *message;
  1796. int need_recovery;
  1797. u64 err_mask64;
  1798. iscsi_cid = iscsi_err->iscsi_conn_id;
  1799. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1800. if (!bnx2i_conn) {
  1801. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1802. return;
  1803. }
  1804. err_mask64 = (0x1ULL << iscsi_err->completion_status);
  1805. if (err_mask64 & iscsi_error_mask) {
  1806. need_recovery = 0;
  1807. message = warn_notice;
  1808. } else {
  1809. need_recovery = 1;
  1810. message = error_notice;
  1811. }
  1812. switch (iscsi_err->completion_status) {
  1813. case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
  1814. strcpy(additional_notice, "hdr digest err");
  1815. break;
  1816. case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
  1817. strcpy(additional_notice, "data digest err");
  1818. break;
  1819. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
  1820. strcpy(additional_notice, "wrong opcode rcvd");
  1821. break;
  1822. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
  1823. strcpy(additional_notice, "AHS len > 0 rcvd");
  1824. break;
  1825. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
  1826. strcpy(additional_notice, "invalid ITT rcvd");
  1827. break;
  1828. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
  1829. strcpy(additional_notice, "wrong StatSN rcvd");
  1830. break;
  1831. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
  1832. strcpy(additional_notice, "wrong DataSN rcvd");
  1833. break;
  1834. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
  1835. strcpy(additional_notice, "pend R2T violation");
  1836. break;
  1837. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
  1838. strcpy(additional_notice, "ERL0, UO");
  1839. break;
  1840. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
  1841. strcpy(additional_notice, "ERL0, U1");
  1842. break;
  1843. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
  1844. strcpy(additional_notice, "ERL0, U2");
  1845. break;
  1846. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
  1847. strcpy(additional_notice, "ERL0, U3");
  1848. break;
  1849. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
  1850. strcpy(additional_notice, "ERL0, U4");
  1851. break;
  1852. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
  1853. strcpy(additional_notice, "ERL0, U5");
  1854. break;
  1855. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
  1856. strcpy(additional_notice, "ERL0, U6");
  1857. break;
  1858. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
  1859. strcpy(additional_notice, "invalid resi len");
  1860. break;
  1861. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
  1862. strcpy(additional_notice, "MRDSL violation");
  1863. break;
  1864. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
  1865. strcpy(additional_notice, "F-bit not set");
  1866. break;
  1867. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
  1868. strcpy(additional_notice, "invalid TTT");
  1869. break;
  1870. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
  1871. strcpy(additional_notice, "invalid DataSN");
  1872. break;
  1873. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
  1874. strcpy(additional_notice, "burst len violation");
  1875. break;
  1876. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
  1877. strcpy(additional_notice, "buf offset violation");
  1878. break;
  1879. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
  1880. strcpy(additional_notice, "invalid LUN field");
  1881. break;
  1882. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
  1883. strcpy(additional_notice, "invalid R2TSN field");
  1884. break;
  1885. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
  1886. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
  1887. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
  1888. strcpy(additional_notice, "invalid cmd len1");
  1889. break;
  1890. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
  1891. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
  1892. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
  1893. strcpy(additional_notice, "invalid cmd len2");
  1894. break;
  1895. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
  1896. strcpy(additional_notice,
  1897. "pend r2t exceeds MaxOutstandingR2T value");
  1898. break;
  1899. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
  1900. strcpy(additional_notice, "TTT is rsvd");
  1901. break;
  1902. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
  1903. strcpy(additional_notice, "MBL violation");
  1904. break;
  1905. #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
  1906. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
  1907. case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
  1908. strcpy(additional_notice, "data seg len != 0");
  1909. break;
  1910. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
  1911. strcpy(additional_notice, "reject pdu len error");
  1912. break;
  1913. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
  1914. strcpy(additional_notice, "async pdu len error");
  1915. break;
  1916. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
  1917. strcpy(additional_notice, "nopin pdu len error");
  1918. break;
  1919. #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
  1920. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
  1921. case BNX2_ERR_PEND_R2T_IN_CLEANUP:
  1922. strcpy(additional_notice, "pend r2t in cleanup");
  1923. break;
  1924. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
  1925. strcpy(additional_notice, "IP fragments rcvd");
  1926. break;
  1927. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
  1928. strcpy(additional_notice, "IP options error");
  1929. break;
  1930. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
  1931. strcpy(additional_notice, "urgent flag error");
  1932. break;
  1933. default:
  1934. printk(KERN_ALERT "iscsi_err - unknown err %x\n",
  1935. iscsi_err->completion_status);
  1936. }
  1937. if (need_recovery) {
  1938. iscsi_conn_printk(KERN_ALERT,
  1939. bnx2i_conn->cls_conn->dd_data,
  1940. "bnx2i: %s - %s\n",
  1941. message, additional_notice);
  1942. iscsi_conn_printk(KERN_ALERT,
  1943. bnx2i_conn->cls_conn->dd_data,
  1944. "conn_err - hostno %d conn %p, "
  1945. "iscsi_cid %x cid %x\n",
  1946. bnx2i_conn->hba->shost->host_no,
  1947. bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
  1948. bnx2i_conn->ep->ep_cid);
  1949. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  1950. } else
  1951. if (!test_and_set_bit(iscsi_err->completion_status,
  1952. (void *) &bnx2i_conn->violation_notified))
  1953. iscsi_conn_printk(KERN_ALERT,
  1954. bnx2i_conn->cls_conn->dd_data,
  1955. "bnx2i: %s - %s\n",
  1956. message, additional_notice);
  1957. }
  1958. /**
  1959. * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
  1960. * @hba: adapter structure pointer
  1961. * @conn_destroy: conn destroy kcqe pointer
  1962. *
  1963. * handles connection destroy completion request.
  1964. */
  1965. static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
  1966. struct iscsi_kcqe *conn_destroy)
  1967. {
  1968. struct bnx2i_endpoint *ep;
  1969. ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
  1970. if (!ep) {
  1971. printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
  1972. "offload request, unexpected complection\n");
  1973. return;
  1974. }
  1975. if (hba != ep->hba) {
  1976. printk(KERN_ALERT "conn destroy- error hba mis-match\n");
  1977. return;
  1978. }
  1979. if (conn_destroy->completion_status) {
  1980. printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
  1981. ep->state = EP_STATE_CLEANUP_FAILED;
  1982. } else
  1983. ep->state = EP_STATE_CLEANUP_CMPL;
  1984. wake_up_interruptible(&ep->ofld_wait);
  1985. }
  1986. /**
  1987. * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
  1988. * @hba: adapter structure pointer
  1989. * @ofld_kcqe: conn offload kcqe pointer
  1990. *
  1991. * handles initial connection offload completion, ep_connect() thread is
  1992. * woken-up to continue with LLP connect process
  1993. */
  1994. static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
  1995. struct iscsi_kcqe *ofld_kcqe)
  1996. {
  1997. u32 cid_addr;
  1998. struct bnx2i_endpoint *ep;
  1999. u32 cid_num;
  2000. ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
  2001. if (!ep) {
  2002. printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
  2003. return;
  2004. }
  2005. if (hba != ep->hba) {
  2006. printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
  2007. return;
  2008. }
  2009. if (ofld_kcqe->completion_status) {
  2010. ep->state = EP_STATE_OFLD_FAILED;
  2011. if (ofld_kcqe->completion_status ==
  2012. ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
  2013. printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - unable "
  2014. "to allocate iSCSI context resources\n",
  2015. hba->netdev->name);
  2016. else if (ofld_kcqe->completion_status ==
  2017. ISCSI_KCQE_COMPLETION_STATUS_INVALID_OPCODE)
  2018. printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
  2019. "opcode\n", hba->netdev->name);
  2020. else if (ofld_kcqe->completion_status ==
  2021. ISCSI_KCQE_COMPLETION_STATUS_CID_BUSY)
  2022. /* error status code valid only for 5771x chipset */
  2023. ep->state = EP_STATE_OFLD_FAILED_CID_BUSY;
  2024. else
  2025. printk(KERN_ALERT "bnx2i (%s): ofld1 cmpl - invalid "
  2026. "error code %d\n", hba->netdev->name,
  2027. ofld_kcqe->completion_status);
  2028. } else {
  2029. ep->state = EP_STATE_OFLD_COMPL;
  2030. cid_addr = ofld_kcqe->iscsi_conn_context_id;
  2031. cid_num = bnx2i_get_cid_num(ep);
  2032. ep->ep_cid = cid_addr;
  2033. ep->qp.ctx_base = NULL;
  2034. }
  2035. wake_up_interruptible(&ep->ofld_wait);
  2036. }
  2037. /**
  2038. * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
  2039. * @hba: adapter structure pointer
  2040. * @update_kcqe: kcqe pointer
  2041. *
  2042. * Generic KCQ event handler/dispatcher
  2043. */
  2044. static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
  2045. u32 num_cqe)
  2046. {
  2047. struct bnx2i_hba *hba = context;
  2048. int i = 0;
  2049. struct iscsi_kcqe *ikcqe = NULL;
  2050. while (i < num_cqe) {
  2051. ikcqe = (struct iscsi_kcqe *) kcqe[i++];
  2052. if (ikcqe->op_code ==
  2053. ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
  2054. bnx2i_fastpath_notification(hba, ikcqe);
  2055. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
  2056. bnx2i_process_ofld_cmpl(hba, ikcqe);
  2057. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
  2058. bnx2i_process_update_conn_cmpl(hba, ikcqe);
  2059. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
  2060. if (ikcqe->completion_status !=
  2061. ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
  2062. bnx2i_iscsi_license_error(hba, ikcqe->\
  2063. completion_status);
  2064. else {
  2065. set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  2066. bnx2i_get_link_state(hba);
  2067. printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
  2068. "ISCSI_INIT passed\n",
  2069. (u8)hba->pcidev->bus->number,
  2070. hba->pci_devno,
  2071. (u8)hba->pci_func);
  2072. }
  2073. } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
  2074. bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
  2075. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
  2076. bnx2i_process_iscsi_error(hba, ikcqe);
  2077. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
  2078. bnx2i_process_tcp_error(hba, ikcqe);
  2079. else
  2080. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  2081. ikcqe->op_code);
  2082. }
  2083. }
  2084. /**
  2085. * bnx2i_indicate_netevent - Generic netdev event handler
  2086. * @context: adapter structure pointer
  2087. * @event: event type
  2088. *
  2089. * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
  2090. * NETDEV_GOING_DOWN and NETDEV_CHANGE
  2091. */
  2092. static void bnx2i_indicate_netevent(void *context, unsigned long event)
  2093. {
  2094. struct bnx2i_hba *hba = context;
  2095. switch (event) {
  2096. case NETDEV_UP:
  2097. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
  2098. bnx2i_send_fw_iscsi_init_msg(hba);
  2099. break;
  2100. case NETDEV_DOWN:
  2101. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  2102. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  2103. break;
  2104. case NETDEV_GOING_DOWN:
  2105. set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  2106. iscsi_host_for_each_session(hba->shost,
  2107. bnx2i_drop_session);
  2108. break;
  2109. case NETDEV_CHANGE:
  2110. bnx2i_get_link_state(hba);
  2111. break;
  2112. default:
  2113. ;
  2114. }
  2115. }
  2116. /**
  2117. * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
  2118. * @cm_sk: cnic sock structure pointer
  2119. *
  2120. * function callback exported via bnx2i - cnic driver interface to
  2121. * indicate completion of option-2 TCP connect request.
  2122. */
  2123. static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
  2124. {
  2125. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2126. if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
  2127. ep->state = EP_STATE_CONNECT_FAILED;
  2128. else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
  2129. ep->state = EP_STATE_CONNECT_COMPL;
  2130. else
  2131. ep->state = EP_STATE_CONNECT_FAILED;
  2132. wake_up_interruptible(&ep->ofld_wait);
  2133. }
  2134. /**
  2135. * bnx2i_cm_close_cmpl - process tcp conn close completion
  2136. * @cm_sk: cnic sock structure pointer
  2137. *
  2138. * function callback exported via bnx2i - cnic driver interface to
  2139. * indicate completion of option-2 graceful TCP connect shutdown
  2140. */
  2141. static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
  2142. {
  2143. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2144. ep->state = EP_STATE_DISCONN_COMPL;
  2145. wake_up_interruptible(&ep->ofld_wait);
  2146. }
  2147. /**
  2148. * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
  2149. * @cm_sk: cnic sock structure pointer
  2150. *
  2151. * function callback exported via bnx2i - cnic driver interface to
  2152. * indicate completion of option-2 abortive TCP connect termination
  2153. */
  2154. static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
  2155. {
  2156. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2157. ep->state = EP_STATE_DISCONN_COMPL;
  2158. wake_up_interruptible(&ep->ofld_wait);
  2159. }
  2160. /**
  2161. * bnx2i_cm_remote_close - process received TCP FIN
  2162. * @hba: adapter structure pointer
  2163. * @update_kcqe: kcqe pointer
  2164. *
  2165. * function callback exported via bnx2i - cnic driver interface to indicate
  2166. * async TCP events such as FIN
  2167. */
  2168. static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
  2169. {
  2170. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2171. ep->state = EP_STATE_TCP_FIN_RCVD;
  2172. if (ep->conn)
  2173. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2174. }
  2175. /**
  2176. * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
  2177. * @hba: adapter structure pointer
  2178. * @update_kcqe: kcqe pointer
  2179. *
  2180. * function callback exported via bnx2i - cnic driver interface to
  2181. * indicate async TCP events (RST) sent by the peer.
  2182. */
  2183. static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
  2184. {
  2185. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2186. u32 old_state = ep->state;
  2187. ep->state = EP_STATE_TCP_RST_RCVD;
  2188. if (old_state == EP_STATE_DISCONN_START)
  2189. wake_up_interruptible(&ep->ofld_wait);
  2190. else
  2191. if (ep->conn)
  2192. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2193. }
  2194. static int bnx2i_send_nl_mesg(void *context, u32 msg_type,
  2195. char *buf, u16 buflen)
  2196. {
  2197. struct bnx2i_hba *hba = context;
  2198. int rc;
  2199. if (!hba)
  2200. return -ENODEV;
  2201. rc = iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
  2202. msg_type, buf, buflen);
  2203. if (rc)
  2204. printk(KERN_ALERT "bnx2i: private nl message send error\n");
  2205. return rc;
  2206. }
  2207. /**
  2208. * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
  2209. * carrying callback function pointers
  2210. *
  2211. */
  2212. struct cnic_ulp_ops bnx2i_cnic_cb = {
  2213. .cnic_init = bnx2i_ulp_init,
  2214. .cnic_exit = bnx2i_ulp_exit,
  2215. .cnic_start = bnx2i_start,
  2216. .cnic_stop = bnx2i_stop,
  2217. .indicate_kcqes = bnx2i_indicate_kcqe,
  2218. .indicate_netevent = bnx2i_indicate_netevent,
  2219. .cm_connect_complete = bnx2i_cm_connect_cmpl,
  2220. .cm_close_complete = bnx2i_cm_close_cmpl,
  2221. .cm_abort_complete = bnx2i_cm_abort_cmpl,
  2222. .cm_remote_close = bnx2i_cm_remote_close,
  2223. .cm_remote_abort = bnx2i_cm_remote_abort,
  2224. .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
  2225. .owner = THIS_MODULE
  2226. };
  2227. /**
  2228. * bnx2i_map_ep_dbell_regs - map connection doorbell registers
  2229. * @ep: bnx2i endpoint
  2230. *
  2231. * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
  2232. * register in BAR #0. Whereas in 57710 these register are accessed by
  2233. * mapping BAR #1
  2234. */
  2235. int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
  2236. {
  2237. u32 cid_num;
  2238. u32 reg_off;
  2239. u32 first_l4l5;
  2240. u32 ctx_sz;
  2241. u32 config2;
  2242. resource_size_t reg_base;
  2243. cid_num = bnx2i_get_cid_num(ep);
  2244. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  2245. reg_base = pci_resource_start(ep->hba->pcidev,
  2246. BNX2X_DOORBELL_PCI_BAR);
  2247. reg_off = BNX2I_5771X_DBELL_PAGE_SIZE * (cid_num & 0x1FFFF) +
  2248. DPM_TRIGER_TYPE;
  2249. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
  2250. goto arm_cq;
  2251. }
  2252. reg_base = ep->hba->netdev->base_addr;
  2253. if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
  2254. (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
  2255. config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
  2256. first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
  2257. ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
  2258. if (ctx_sz)
  2259. reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
  2260. + BNX2I_570X_PAGE_SIZE_DEFAULT *
  2261. (((cid_num - first_l4l5) / ctx_sz) + 256);
  2262. else
  2263. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2264. } else
  2265. /* 5709 device in normal node and 5706/5708 devices */
  2266. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2267. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
  2268. MB_KERNEL_CTX_SIZE);
  2269. if (!ep->qp.ctx_base)
  2270. return -ENOMEM;
  2271. arm_cq:
  2272. bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
  2273. return 0;
  2274. }