bnx2i_hwi.c 73 KB

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