bnx2i_hwi.c 74 KB

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