bnx2i_hwi.c 73 KB

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