bnx2i_hwi.c 74 KB

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