bnx2i_hwi.c 82 KB

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