bnx2i_hwi.c 72 KB

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