bnx2i_hwi.c 73 KB

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