bnx2i_hwi.c 82 KB

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