bnx2i_hwi.c 83 KB

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