bnx2i_hwi.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436
  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. * @datap: payload buffer pointer
  407. * @data_len: payload data length
  408. * @unsol: indicated whether nopout pdu is unsolicited pdu or
  409. * in response to target's NOPIN w/ TTT != FFFFFFFF
  410. *
  411. * prepare and post a nopout request WQE to CNIC firmware
  412. */
  413. int bnx2i_send_iscsi_nopout(struct bnx2i_conn *bnx2i_conn,
  414. struct iscsi_task *task,
  415. char *datap, int data_len, int unsol)
  416. {
  417. struct bnx2i_endpoint *ep = bnx2i_conn->ep;
  418. struct bnx2i_cmd *bnx2i_cmd;
  419. struct bnx2i_nop_out_request *nopout_wqe;
  420. struct iscsi_nopout *nopout_hdr;
  421. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  422. nopout_hdr = (struct iscsi_nopout *)task->hdr;
  423. nopout_wqe = (struct bnx2i_nop_out_request *)ep->qp.sq_prod_qe;
  424. nopout_wqe->op_code = nopout_hdr->opcode;
  425. nopout_wqe->op_attr = ISCSI_FLAG_CMD_FINAL;
  426. memcpy(nopout_wqe->lun, nopout_hdr->lun, 8);
  427. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  428. u32 tmp = nopout_hdr->lun[0];
  429. /* 57710 requires LUN field to be swapped */
  430. nopout_hdr->lun[0] = nopout_hdr->lun[1];
  431. nopout_hdr->lun[1] = tmp;
  432. }
  433. nopout_wqe->itt = ((u16)task->itt |
  434. (ISCSI_TASK_TYPE_MPATH <<
  435. ISCSI_TMF_REQUEST_TYPE_SHIFT));
  436. nopout_wqe->ttt = nopout_hdr->ttt;
  437. nopout_wqe->flags = 0;
  438. if (!unsol)
  439. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  440. else if (nopout_hdr->itt == RESERVED_ITT)
  441. nopout_wqe->flags = ISCSI_NOP_OUT_REQUEST_LOCAL_COMPLETION;
  442. nopout_wqe->cmd_sn = be32_to_cpu(nopout_hdr->cmdsn);
  443. nopout_wqe->data_length = data_len;
  444. if (data_len) {
  445. /* handle payload data, not required in first release */
  446. printk(KERN_ALERT "NOPOUT: WARNING!! payload len != 0\n");
  447. } else {
  448. nopout_wqe->bd_list_addr_lo = (u32)
  449. bnx2i_conn->hba->mp_bd_dma;
  450. nopout_wqe->bd_list_addr_hi =
  451. (u32) ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  452. nopout_wqe->num_bds = 1;
  453. }
  454. nopout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  455. bnx2i_ring_dbell_update_sq_params(bnx2i_conn, 1);
  456. return 0;
  457. }
  458. /**
  459. * bnx2i_send_iscsi_logout - post iSCSI logout request WQE to hardware
  460. * @conn: iscsi connection
  461. * @cmd: driver command structure which is requesting
  462. * a WQE to sent to chip for further processing
  463. *
  464. * prepare and post logout request WQE to CNIC firmware
  465. */
  466. int bnx2i_send_iscsi_logout(struct bnx2i_conn *bnx2i_conn,
  467. struct iscsi_task *task)
  468. {
  469. struct bnx2i_cmd *bnx2i_cmd;
  470. struct bnx2i_logout_request *logout_wqe;
  471. struct iscsi_logout *logout_hdr;
  472. bnx2i_cmd = (struct bnx2i_cmd *)task->dd_data;
  473. logout_hdr = (struct iscsi_logout *)task->hdr;
  474. logout_wqe = (struct bnx2i_logout_request *)
  475. bnx2i_conn->ep->qp.sq_prod_qe;
  476. memset(logout_wqe, 0x00, sizeof(struct bnx2i_logout_request));
  477. logout_wqe->op_code = logout_hdr->opcode;
  478. logout_wqe->cmd_sn = be32_to_cpu(logout_hdr->cmdsn);
  479. logout_wqe->op_attr =
  480. logout_hdr->flags | ISCSI_LOGOUT_REQUEST_ALWAYS_ONE;
  481. logout_wqe->itt = ((u16)task->itt |
  482. (ISCSI_TASK_TYPE_MPATH <<
  483. ISCSI_LOGOUT_REQUEST_TYPE_SHIFT));
  484. logout_wqe->data_length = 0;
  485. logout_wqe->cid = 0;
  486. logout_wqe->bd_list_addr_lo = (u32) bnx2i_conn->hba->mp_bd_dma;
  487. logout_wqe->bd_list_addr_hi = (u32)
  488. ((u64) bnx2i_conn->hba->mp_bd_dma >> 32);
  489. logout_wqe->num_bds = 1;
  490. logout_wqe->cq_index = 0; /* CQ# used for completion, 5771x only */
  491. bnx2i_conn->ep->state = EP_STATE_LOGOUT_SENT;
  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. bnx2i_conn->ep->state = EP_STATE_LOGOUT_RESP_RCVD;
  1287. done:
  1288. spin_unlock(&session->lock);
  1289. return 0;
  1290. }
  1291. /**
  1292. * bnx2i_process_nopin_local_cmpl - this function handles iscsi nopin CQE
  1293. * @session: iscsi session pointer
  1294. * @bnx2i_conn: iscsi connection pointer
  1295. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1296. *
  1297. * process iSCSI NOPIN local completion CQE, frees IIT and command structures
  1298. */
  1299. static void bnx2i_process_nopin_local_cmpl(struct iscsi_session *session,
  1300. struct bnx2i_conn *bnx2i_conn,
  1301. struct cqe *cqe)
  1302. {
  1303. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1304. struct bnx2i_nop_in_msg *nop_in;
  1305. struct iscsi_task *task;
  1306. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1307. spin_lock(&session->lock);
  1308. task = iscsi_itt_to_task(conn,
  1309. nop_in->itt & ISCSI_NOP_IN_MSG_INDEX);
  1310. if (task)
  1311. iscsi_put_task(task);
  1312. spin_unlock(&session->lock);
  1313. }
  1314. /**
  1315. * bnx2i_unsol_pdu_adjust_rq - makes adjustments to RQ after unsol pdu is recvd
  1316. * @conn: iscsi connection
  1317. *
  1318. * Firmware advances RQ producer index for every unsolicited PDU even if
  1319. * payload data length is '0'. This function makes corresponding
  1320. * adjustments on the driver side to match this f/w behavior
  1321. */
  1322. static void bnx2i_unsol_pdu_adjust_rq(struct bnx2i_conn *bnx2i_conn)
  1323. {
  1324. char dummy_rq_data[2];
  1325. bnx2i_get_rq_buf(bnx2i_conn, dummy_rq_data, 1);
  1326. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1327. }
  1328. /**
  1329. * bnx2i_process_nopin_mesg - this function handles iscsi nopin CQE
  1330. * @session: iscsi session pointer
  1331. * @bnx2i_conn: iscsi connection pointer
  1332. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1333. *
  1334. * process iSCSI target's proactive iSCSI NOPIN request
  1335. */
  1336. static int bnx2i_process_nopin_mesg(struct iscsi_session *session,
  1337. struct bnx2i_conn *bnx2i_conn,
  1338. struct cqe *cqe)
  1339. {
  1340. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1341. struct iscsi_task *task;
  1342. struct bnx2i_nop_in_msg *nop_in;
  1343. struct iscsi_nopin *hdr;
  1344. u32 itt;
  1345. int tgt_async_nop = 0;
  1346. nop_in = (struct bnx2i_nop_in_msg *)cqe;
  1347. itt = nop_in->itt & ISCSI_NOP_IN_MSG_INDEX;
  1348. spin_lock(&session->lock);
  1349. hdr = (struct iscsi_nopin *)&bnx2i_conn->gen_pdu.resp_hdr;
  1350. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1351. hdr->opcode = nop_in->op_code;
  1352. hdr->max_cmdsn = cpu_to_be32(nop_in->max_cmd_sn);
  1353. hdr->exp_cmdsn = cpu_to_be32(nop_in->exp_cmd_sn);
  1354. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1355. if (itt == (u16) RESERVED_ITT) {
  1356. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1357. hdr->itt = RESERVED_ITT;
  1358. tgt_async_nop = 1;
  1359. goto done;
  1360. }
  1361. /* this is a response to one of our nop-outs */
  1362. task = iscsi_itt_to_task(conn, itt);
  1363. if (task) {
  1364. hdr->flags = ISCSI_FLAG_CMD_FINAL;
  1365. hdr->itt = task->hdr->itt;
  1366. hdr->ttt = cpu_to_be32(nop_in->ttt);
  1367. memcpy(hdr->lun, nop_in->lun, 8);
  1368. }
  1369. done:
  1370. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, NULL, 0);
  1371. spin_unlock(&session->lock);
  1372. return tgt_async_nop;
  1373. }
  1374. /**
  1375. * bnx2i_process_async_mesg - this function handles iscsi async message
  1376. * @session: iscsi session pointer
  1377. * @bnx2i_conn: iscsi connection pointer
  1378. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1379. *
  1380. * process iSCSI ASYNC Message
  1381. */
  1382. static void bnx2i_process_async_mesg(struct iscsi_session *session,
  1383. struct bnx2i_conn *bnx2i_conn,
  1384. struct cqe *cqe)
  1385. {
  1386. struct bnx2i_async_msg *async_cqe;
  1387. struct iscsi_async *resp_hdr;
  1388. u8 async_event;
  1389. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1390. async_cqe = (struct bnx2i_async_msg *)cqe;
  1391. async_event = async_cqe->async_event;
  1392. if (async_event == ISCSI_ASYNC_MSG_SCSI_EVENT) {
  1393. iscsi_conn_printk(KERN_ALERT, bnx2i_conn->cls_conn->dd_data,
  1394. "async: scsi events not supported\n");
  1395. return;
  1396. }
  1397. spin_lock(&session->lock);
  1398. resp_hdr = (struct iscsi_async *) &bnx2i_conn->gen_pdu.resp_hdr;
  1399. memset(resp_hdr, 0, sizeof(struct iscsi_hdr));
  1400. resp_hdr->opcode = async_cqe->op_code;
  1401. resp_hdr->flags = 0x80;
  1402. memcpy(resp_hdr->lun, async_cqe->lun, 8);
  1403. resp_hdr->exp_cmdsn = cpu_to_be32(async_cqe->exp_cmd_sn);
  1404. resp_hdr->max_cmdsn = cpu_to_be32(async_cqe->max_cmd_sn);
  1405. resp_hdr->async_event = async_cqe->async_event;
  1406. resp_hdr->async_vcode = async_cqe->async_vcode;
  1407. resp_hdr->param1 = cpu_to_be16(async_cqe->param1);
  1408. resp_hdr->param2 = cpu_to_be16(async_cqe->param2);
  1409. resp_hdr->param3 = cpu_to_be16(async_cqe->param3);
  1410. __iscsi_complete_pdu(bnx2i_conn->cls_conn->dd_data,
  1411. (struct iscsi_hdr *)resp_hdr, NULL, 0);
  1412. spin_unlock(&session->lock);
  1413. }
  1414. /**
  1415. * bnx2i_process_reject_mesg - process iscsi reject pdu
  1416. * @session: iscsi session pointer
  1417. * @bnx2i_conn: iscsi connection pointer
  1418. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1419. *
  1420. * process iSCSI REJECT message
  1421. */
  1422. static void bnx2i_process_reject_mesg(struct iscsi_session *session,
  1423. struct bnx2i_conn *bnx2i_conn,
  1424. struct cqe *cqe)
  1425. {
  1426. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1427. struct bnx2i_reject_msg *reject;
  1428. struct iscsi_reject *hdr;
  1429. reject = (struct bnx2i_reject_msg *) cqe;
  1430. if (reject->data_length) {
  1431. bnx2i_get_rq_buf(bnx2i_conn, conn->data, reject->data_length);
  1432. bnx2i_put_rq_buf(bnx2i_conn, 1);
  1433. } else
  1434. bnx2i_unsol_pdu_adjust_rq(bnx2i_conn);
  1435. spin_lock(&session->lock);
  1436. hdr = (struct iscsi_reject *) &bnx2i_conn->gen_pdu.resp_hdr;
  1437. memset(hdr, 0, sizeof(struct iscsi_hdr));
  1438. hdr->opcode = reject->op_code;
  1439. hdr->reason = reject->reason;
  1440. hton24(hdr->dlength, reject->data_length);
  1441. hdr->max_cmdsn = cpu_to_be32(reject->max_cmd_sn);
  1442. hdr->exp_cmdsn = cpu_to_be32(reject->exp_cmd_sn);
  1443. hdr->ffffffff = cpu_to_be32(RESERVED_ITT);
  1444. __iscsi_complete_pdu(conn, (struct iscsi_hdr *)hdr, conn->data,
  1445. reject->data_length);
  1446. spin_unlock(&session->lock);
  1447. }
  1448. /**
  1449. * bnx2i_process_cmd_cleanup_resp - process scsi command clean-up completion
  1450. * @session: iscsi session pointer
  1451. * @bnx2i_conn: iscsi connection pointer
  1452. * @cqe: pointer to newly DMA'ed CQE entry for processing
  1453. *
  1454. * process command cleanup response CQE during conn shutdown or error recovery
  1455. */
  1456. static void bnx2i_process_cmd_cleanup_resp(struct iscsi_session *session,
  1457. struct bnx2i_conn *bnx2i_conn,
  1458. struct cqe *cqe)
  1459. {
  1460. struct bnx2i_cleanup_response *cmd_clean_rsp;
  1461. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1462. struct iscsi_task *task;
  1463. cmd_clean_rsp = (struct bnx2i_cleanup_response *)cqe;
  1464. spin_lock(&session->lock);
  1465. task = iscsi_itt_to_task(conn,
  1466. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1467. if (!task)
  1468. printk(KERN_ALERT "bnx2i: cmd clean ITT %x not active\n",
  1469. cmd_clean_rsp->itt & ISCSI_CLEANUP_RESPONSE_INDEX);
  1470. spin_unlock(&session->lock);
  1471. complete(&bnx2i_conn->cmd_cleanup_cmpl);
  1472. }
  1473. /**
  1474. * bnx2i_process_new_cqes - process newly DMA'ed CQE's
  1475. * @bnx2i_conn: iscsi connection
  1476. *
  1477. * this function is called by generic KCQ handler to process all pending CQE's
  1478. */
  1479. static void bnx2i_process_new_cqes(struct bnx2i_conn *bnx2i_conn)
  1480. {
  1481. struct iscsi_conn *conn = bnx2i_conn->cls_conn->dd_data;
  1482. struct iscsi_session *session = conn->session;
  1483. struct qp_info *qp = &bnx2i_conn->ep->qp;
  1484. struct bnx2i_nop_in_msg *nopin;
  1485. int tgt_async_msg;
  1486. while (1) {
  1487. nopin = (struct bnx2i_nop_in_msg *) qp->cq_cons_qe;
  1488. if (nopin->cq_req_sn != qp->cqe_exp_seq_sn)
  1489. break;
  1490. if (unlikely(test_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx)))
  1491. break;
  1492. tgt_async_msg = 0;
  1493. switch (nopin->op_code) {
  1494. case ISCSI_OP_SCSI_CMD_RSP:
  1495. case ISCSI_OP_SCSI_DATA_IN:
  1496. bnx2i_process_scsi_cmd_resp(session, bnx2i_conn,
  1497. qp->cq_cons_qe);
  1498. break;
  1499. case ISCSI_OP_LOGIN_RSP:
  1500. bnx2i_process_login_resp(session, bnx2i_conn,
  1501. qp->cq_cons_qe);
  1502. break;
  1503. case ISCSI_OP_SCSI_TMFUNC_RSP:
  1504. bnx2i_process_tmf_resp(session, bnx2i_conn,
  1505. qp->cq_cons_qe);
  1506. break;
  1507. case ISCSI_OP_LOGOUT_RSP:
  1508. bnx2i_process_logout_resp(session, bnx2i_conn,
  1509. qp->cq_cons_qe);
  1510. break;
  1511. case ISCSI_OP_NOOP_IN:
  1512. if (bnx2i_process_nopin_mesg(session, bnx2i_conn,
  1513. qp->cq_cons_qe))
  1514. tgt_async_msg = 1;
  1515. break;
  1516. case ISCSI_OPCODE_NOPOUT_LOCAL_COMPLETION:
  1517. bnx2i_process_nopin_local_cmpl(session, bnx2i_conn,
  1518. qp->cq_cons_qe);
  1519. break;
  1520. case ISCSI_OP_ASYNC_EVENT:
  1521. bnx2i_process_async_mesg(session, bnx2i_conn,
  1522. qp->cq_cons_qe);
  1523. tgt_async_msg = 1;
  1524. break;
  1525. case ISCSI_OP_REJECT:
  1526. bnx2i_process_reject_mesg(session, bnx2i_conn,
  1527. qp->cq_cons_qe);
  1528. break;
  1529. case ISCSI_OPCODE_CLEANUP_RESPONSE:
  1530. bnx2i_process_cmd_cleanup_resp(session, bnx2i_conn,
  1531. qp->cq_cons_qe);
  1532. break;
  1533. default:
  1534. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  1535. nopin->op_code);
  1536. }
  1537. if (!tgt_async_msg)
  1538. bnx2i_conn->ep->num_active_cmds--;
  1539. /* clear out in production version only, till beta keep opcode
  1540. * field intact, will be helpful in debugging (context dump)
  1541. * nopin->op_code = 0;
  1542. */
  1543. qp->cqe_exp_seq_sn++;
  1544. if (qp->cqe_exp_seq_sn == (qp->cqe_size * 2 + 1))
  1545. qp->cqe_exp_seq_sn = ISCSI_INITIAL_SN;
  1546. if (qp->cq_cons_qe == qp->cq_last_qe) {
  1547. qp->cq_cons_qe = qp->cq_first_qe;
  1548. qp->cq_cons_idx = 0;
  1549. } else {
  1550. qp->cq_cons_qe++;
  1551. qp->cq_cons_idx++;
  1552. }
  1553. }
  1554. bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE);
  1555. }
  1556. /**
  1557. * bnx2i_fastpath_notification - process global event queue (KCQ)
  1558. * @hba: adapter structure pointer
  1559. * @new_cqe_kcqe: pointer to newly DMA'ed KCQE entry
  1560. *
  1561. * Fast path event notification handler, KCQ entry carries context id
  1562. * of the connection that has 1 or more pending CQ entries
  1563. */
  1564. static void bnx2i_fastpath_notification(struct bnx2i_hba *hba,
  1565. struct iscsi_kcqe *new_cqe_kcqe)
  1566. {
  1567. struct bnx2i_conn *conn;
  1568. u32 iscsi_cid;
  1569. iscsi_cid = new_cqe_kcqe->iscsi_conn_id;
  1570. conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1571. if (!conn) {
  1572. printk(KERN_ALERT "cid #%x not valid\n", iscsi_cid);
  1573. return;
  1574. }
  1575. if (!conn->ep) {
  1576. printk(KERN_ALERT "cid #%x - ep not bound\n", iscsi_cid);
  1577. return;
  1578. }
  1579. bnx2i_process_new_cqes(conn);
  1580. }
  1581. /**
  1582. * bnx2i_process_update_conn_cmpl - process iscsi conn update completion KCQE
  1583. * @hba: adapter structure pointer
  1584. * @update_kcqe: kcqe pointer
  1585. *
  1586. * CONN_UPDATE completion handler, this completes iSCSI connection FFP migration
  1587. */
  1588. static void bnx2i_process_update_conn_cmpl(struct bnx2i_hba *hba,
  1589. struct iscsi_kcqe *update_kcqe)
  1590. {
  1591. struct bnx2i_conn *conn;
  1592. u32 iscsi_cid;
  1593. iscsi_cid = update_kcqe->iscsi_conn_id;
  1594. conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1595. if (!conn) {
  1596. printk(KERN_ALERT "conn_update: cid %x not valid\n", iscsi_cid);
  1597. return;
  1598. }
  1599. if (!conn->ep) {
  1600. printk(KERN_ALERT "cid %x does not have ep bound\n", iscsi_cid);
  1601. return;
  1602. }
  1603. if (update_kcqe->completion_status) {
  1604. printk(KERN_ALERT "request failed cid %x\n", iscsi_cid);
  1605. conn->ep->state = EP_STATE_ULP_UPDATE_FAILED;
  1606. } else
  1607. conn->ep->state = EP_STATE_ULP_UPDATE_COMPL;
  1608. wake_up_interruptible(&conn->ep->ofld_wait);
  1609. }
  1610. /**
  1611. * bnx2i_recovery_que_add_conn - add connection to recovery queue
  1612. * @hba: adapter structure pointer
  1613. * @bnx2i_conn: iscsi connection
  1614. *
  1615. * Add connection to recovery queue and schedule adapter eh worker
  1616. */
  1617. static void bnx2i_recovery_que_add_conn(struct bnx2i_hba *hba,
  1618. struct bnx2i_conn *bnx2i_conn)
  1619. {
  1620. iscsi_conn_failure(bnx2i_conn->cls_conn->dd_data,
  1621. ISCSI_ERR_CONN_FAILED);
  1622. }
  1623. /**
  1624. * bnx2i_process_tcp_error - process error notification on a given connection
  1625. *
  1626. * @hba: adapter structure pointer
  1627. * @tcp_err: tcp error kcqe pointer
  1628. *
  1629. * handles tcp level error notifications from FW.
  1630. */
  1631. static void bnx2i_process_tcp_error(struct bnx2i_hba *hba,
  1632. struct iscsi_kcqe *tcp_err)
  1633. {
  1634. struct bnx2i_conn *bnx2i_conn;
  1635. u32 iscsi_cid;
  1636. iscsi_cid = tcp_err->iscsi_conn_id;
  1637. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1638. if (!bnx2i_conn) {
  1639. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1640. return;
  1641. }
  1642. printk(KERN_ALERT "bnx2i - cid 0x%x had TCP errors, error code 0x%x\n",
  1643. iscsi_cid, tcp_err->completion_status);
  1644. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  1645. }
  1646. /**
  1647. * bnx2i_process_iscsi_error - process error notification on a given connection
  1648. * @hba: adapter structure pointer
  1649. * @iscsi_err: iscsi error kcqe pointer
  1650. *
  1651. * handles iscsi error notifications from the FW. Firmware based in initial
  1652. * handshake classifies iscsi protocol / TCP rfc violation into either
  1653. * warning or error indications. If indication is of "Error" type, driver
  1654. * will initiate session recovery for that connection/session. For
  1655. * "Warning" type indication, driver will put out a system log message
  1656. * (there will be only one message for each type for the life of the
  1657. * session, this is to avoid un-necessarily overloading the system)
  1658. */
  1659. static void bnx2i_process_iscsi_error(struct bnx2i_hba *hba,
  1660. struct iscsi_kcqe *iscsi_err)
  1661. {
  1662. struct bnx2i_conn *bnx2i_conn;
  1663. u32 iscsi_cid;
  1664. char warn_notice[] = "iscsi_warning";
  1665. char error_notice[] = "iscsi_error";
  1666. char additional_notice[64];
  1667. char *message;
  1668. int need_recovery;
  1669. u64 err_mask64;
  1670. iscsi_cid = iscsi_err->iscsi_conn_id;
  1671. bnx2i_conn = bnx2i_get_conn_from_id(hba, iscsi_cid);
  1672. if (!bnx2i_conn) {
  1673. printk(KERN_ALERT "bnx2i - cid 0x%x not valid\n", iscsi_cid);
  1674. return;
  1675. }
  1676. err_mask64 = (0x1ULL << iscsi_err->completion_status);
  1677. if (err_mask64 & iscsi_error_mask) {
  1678. need_recovery = 0;
  1679. message = warn_notice;
  1680. } else {
  1681. need_recovery = 1;
  1682. message = error_notice;
  1683. }
  1684. switch (iscsi_err->completion_status) {
  1685. case ISCSI_KCQE_COMPLETION_STATUS_HDR_DIG_ERR:
  1686. strcpy(additional_notice, "hdr digest err");
  1687. break;
  1688. case ISCSI_KCQE_COMPLETION_STATUS_DATA_DIG_ERR:
  1689. strcpy(additional_notice, "data digest err");
  1690. break;
  1691. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_OPCODE:
  1692. strcpy(additional_notice, "wrong opcode rcvd");
  1693. break;
  1694. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_AHS_LEN:
  1695. strcpy(additional_notice, "AHS len > 0 rcvd");
  1696. break;
  1697. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ITT:
  1698. strcpy(additional_notice, "invalid ITT rcvd");
  1699. break;
  1700. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_STATSN:
  1701. strcpy(additional_notice, "wrong StatSN rcvd");
  1702. break;
  1703. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_EXP_DATASN:
  1704. strcpy(additional_notice, "wrong DataSN rcvd");
  1705. break;
  1706. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T:
  1707. strcpy(additional_notice, "pend R2T violation");
  1708. break;
  1709. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_0:
  1710. strcpy(additional_notice, "ERL0, UO");
  1711. break;
  1712. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_1:
  1713. strcpy(additional_notice, "ERL0, U1");
  1714. break;
  1715. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_2:
  1716. strcpy(additional_notice, "ERL0, U2");
  1717. break;
  1718. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_3:
  1719. strcpy(additional_notice, "ERL0, U3");
  1720. break;
  1721. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_4:
  1722. strcpy(additional_notice, "ERL0, U4");
  1723. break;
  1724. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_5:
  1725. strcpy(additional_notice, "ERL0, U5");
  1726. break;
  1727. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_O_U_6:
  1728. strcpy(additional_notice, "ERL0, U6");
  1729. break;
  1730. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_RCV_LEN:
  1731. strcpy(additional_notice, "invalid resi len");
  1732. break;
  1733. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_RCV_PDU_LEN:
  1734. strcpy(additional_notice, "MRDSL violation");
  1735. break;
  1736. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_F_BIT_ZERO:
  1737. strcpy(additional_notice, "F-bit not set");
  1738. break;
  1739. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_NOT_RSRV:
  1740. strcpy(additional_notice, "invalid TTT");
  1741. break;
  1742. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATASN:
  1743. strcpy(additional_notice, "invalid DataSN");
  1744. break;
  1745. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REMAIN_BURST_LEN:
  1746. strcpy(additional_notice, "burst len violation");
  1747. break;
  1748. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_BUFFER_OFF:
  1749. strcpy(additional_notice, "buf offset violation");
  1750. break;
  1751. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_LUN:
  1752. strcpy(additional_notice, "invalid LUN field");
  1753. break;
  1754. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_R2TSN:
  1755. strcpy(additional_notice, "invalid R2TSN field");
  1756. break;
  1757. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0 \
  1758. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_0
  1759. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_0:
  1760. strcpy(additional_notice, "invalid cmd len1");
  1761. break;
  1762. #define BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1 \
  1763. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DESIRED_DATA_TRNS_LEN_1
  1764. case BNX2I_ERR_DESIRED_DATA_TRNS_LEN_1:
  1765. strcpy(additional_notice, "invalid cmd len2");
  1766. break;
  1767. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_EXCEED:
  1768. strcpy(additional_notice,
  1769. "pend r2t exceeds MaxOutstandingR2T value");
  1770. break;
  1771. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_TTT_IS_RSRV:
  1772. strcpy(additional_notice, "TTT is rsvd");
  1773. break;
  1774. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_MAX_BURST_LEN:
  1775. strcpy(additional_notice, "MBL violation");
  1776. break;
  1777. #define BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO \
  1778. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_DATA_SEG_LEN_NOT_ZERO
  1779. case BNX2I_ERR_DATA_SEG_LEN_NOT_ZERO:
  1780. strcpy(additional_notice, "data seg len != 0");
  1781. break;
  1782. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_REJECT_PDU_LEN:
  1783. strcpy(additional_notice, "reject pdu len error");
  1784. break;
  1785. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_ASYNC_PDU_LEN:
  1786. strcpy(additional_notice, "async pdu len error");
  1787. break;
  1788. case ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_NOPIN_PDU_LEN:
  1789. strcpy(additional_notice, "nopin pdu len error");
  1790. break;
  1791. #define BNX2_ERR_PEND_R2T_IN_CLEANUP \
  1792. ISCSI_KCQE_COMPLETION_STATUS_PROTOCOL_ERR_PEND_R2T_IN_CLEANUP
  1793. case BNX2_ERR_PEND_R2T_IN_CLEANUP:
  1794. strcpy(additional_notice, "pend r2t in cleanup");
  1795. break;
  1796. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_FRAGMENT:
  1797. strcpy(additional_notice, "IP fragments rcvd");
  1798. break;
  1799. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_IP_OPTIONS:
  1800. strcpy(additional_notice, "IP options error");
  1801. break;
  1802. case ISCI_KCQE_COMPLETION_STATUS_TCP_ERROR_URGENT_FLAG:
  1803. strcpy(additional_notice, "urgent flag error");
  1804. break;
  1805. default:
  1806. printk(KERN_ALERT "iscsi_err - unknown err %x\n",
  1807. iscsi_err->completion_status);
  1808. }
  1809. if (need_recovery) {
  1810. iscsi_conn_printk(KERN_ALERT,
  1811. bnx2i_conn->cls_conn->dd_data,
  1812. "bnx2i: %s - %s\n",
  1813. message, additional_notice);
  1814. iscsi_conn_printk(KERN_ALERT,
  1815. bnx2i_conn->cls_conn->dd_data,
  1816. "conn_err - hostno %d conn %p, "
  1817. "iscsi_cid %x cid %x\n",
  1818. bnx2i_conn->hba->shost->host_no,
  1819. bnx2i_conn, bnx2i_conn->ep->ep_iscsi_cid,
  1820. bnx2i_conn->ep->ep_cid);
  1821. bnx2i_recovery_que_add_conn(bnx2i_conn->hba, bnx2i_conn);
  1822. } else
  1823. if (!test_and_set_bit(iscsi_err->completion_status,
  1824. (void *) &bnx2i_conn->violation_notified))
  1825. iscsi_conn_printk(KERN_ALERT,
  1826. bnx2i_conn->cls_conn->dd_data,
  1827. "bnx2i: %s - %s\n",
  1828. message, additional_notice);
  1829. }
  1830. /**
  1831. * bnx2i_process_conn_destroy_cmpl - process iscsi conn destroy completion
  1832. * @hba: adapter structure pointer
  1833. * @conn_destroy: conn destroy kcqe pointer
  1834. *
  1835. * handles connection destroy completion request.
  1836. */
  1837. static void bnx2i_process_conn_destroy_cmpl(struct bnx2i_hba *hba,
  1838. struct iscsi_kcqe *conn_destroy)
  1839. {
  1840. struct bnx2i_endpoint *ep;
  1841. ep = bnx2i_find_ep_in_destroy_list(hba, conn_destroy->iscsi_conn_id);
  1842. if (!ep) {
  1843. printk(KERN_ALERT "bnx2i_conn_destroy_cmpl: no pending "
  1844. "offload request, unexpected complection\n");
  1845. return;
  1846. }
  1847. if (hba != ep->hba) {
  1848. printk(KERN_ALERT "conn destroy- error hba mis-match\n");
  1849. return;
  1850. }
  1851. if (conn_destroy->completion_status) {
  1852. printk(KERN_ALERT "conn_destroy_cmpl: op failed\n");
  1853. ep->state = EP_STATE_CLEANUP_FAILED;
  1854. } else
  1855. ep->state = EP_STATE_CLEANUP_CMPL;
  1856. wake_up_interruptible(&ep->ofld_wait);
  1857. }
  1858. /**
  1859. * bnx2i_process_ofld_cmpl - process initial iscsi conn offload completion
  1860. * @hba: adapter structure pointer
  1861. * @ofld_kcqe: conn offload kcqe pointer
  1862. *
  1863. * handles initial connection offload completion, ep_connect() thread is
  1864. * woken-up to continue with LLP connect process
  1865. */
  1866. static void bnx2i_process_ofld_cmpl(struct bnx2i_hba *hba,
  1867. struct iscsi_kcqe *ofld_kcqe)
  1868. {
  1869. u32 cid_addr;
  1870. struct bnx2i_endpoint *ep;
  1871. u32 cid_num;
  1872. ep = bnx2i_find_ep_in_ofld_list(hba, ofld_kcqe->iscsi_conn_id);
  1873. if (!ep) {
  1874. printk(KERN_ALERT "ofld_cmpl: no pend offload request\n");
  1875. return;
  1876. }
  1877. if (hba != ep->hba) {
  1878. printk(KERN_ALERT "ofld_cmpl: error hba mis-match\n");
  1879. return;
  1880. }
  1881. if (ofld_kcqe->completion_status) {
  1882. if (ofld_kcqe->completion_status ==
  1883. ISCSI_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE)
  1884. printk(KERN_ALERT "bnx2i: unable to allocate"
  1885. " iSCSI context resources\n");
  1886. ep->state = EP_STATE_OFLD_FAILED;
  1887. } else {
  1888. ep->state = EP_STATE_OFLD_COMPL;
  1889. cid_addr = ofld_kcqe->iscsi_conn_context_id;
  1890. cid_num = bnx2i_get_cid_num(ep);
  1891. ep->ep_cid = cid_addr;
  1892. ep->qp.ctx_base = NULL;
  1893. }
  1894. wake_up_interruptible(&ep->ofld_wait);
  1895. }
  1896. /**
  1897. * bnx2i_indicate_kcqe - process iscsi conn update completion KCQE
  1898. * @hba: adapter structure pointer
  1899. * @update_kcqe: kcqe pointer
  1900. *
  1901. * Generic KCQ event handler/dispatcher
  1902. */
  1903. static void bnx2i_indicate_kcqe(void *context, struct kcqe *kcqe[],
  1904. u32 num_cqe)
  1905. {
  1906. struct bnx2i_hba *hba = context;
  1907. int i = 0;
  1908. struct iscsi_kcqe *ikcqe = NULL;
  1909. while (i < num_cqe) {
  1910. ikcqe = (struct iscsi_kcqe *) kcqe[i++];
  1911. if (ikcqe->op_code ==
  1912. ISCSI_KCQE_OPCODE_CQ_EVENT_NOTIFICATION)
  1913. bnx2i_fastpath_notification(hba, ikcqe);
  1914. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_OFFLOAD_CONN)
  1915. bnx2i_process_ofld_cmpl(hba, ikcqe);
  1916. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_UPDATE_CONN)
  1917. bnx2i_process_update_conn_cmpl(hba, ikcqe);
  1918. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_INIT) {
  1919. if (ikcqe->completion_status !=
  1920. ISCSI_KCQE_COMPLETION_STATUS_SUCCESS)
  1921. bnx2i_iscsi_license_error(hba, ikcqe->\
  1922. completion_status);
  1923. else {
  1924. set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1925. bnx2i_get_link_state(hba);
  1926. printk(KERN_INFO "bnx2i [%.2x:%.2x.%.2x]: "
  1927. "ISCSI_INIT passed\n",
  1928. (u8)hba->pcidev->bus->number,
  1929. hba->pci_devno,
  1930. (u8)hba->pci_func);
  1931. }
  1932. } else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_DESTROY_CONN)
  1933. bnx2i_process_conn_destroy_cmpl(hba, ikcqe);
  1934. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_ISCSI_ERROR)
  1935. bnx2i_process_iscsi_error(hba, ikcqe);
  1936. else if (ikcqe->op_code == ISCSI_KCQE_OPCODE_TCP_ERROR)
  1937. bnx2i_process_tcp_error(hba, ikcqe);
  1938. else
  1939. printk(KERN_ALERT "bnx2i: unknown opcode 0x%x\n",
  1940. ikcqe->op_code);
  1941. }
  1942. }
  1943. /**
  1944. * bnx2i_indicate_netevent - Generic netdev event handler
  1945. * @context: adapter structure pointer
  1946. * @event: event type
  1947. *
  1948. * Handles four netdev events, NETDEV_UP, NETDEV_DOWN,
  1949. * NETDEV_GOING_DOWN and NETDEV_CHANGE
  1950. */
  1951. static void bnx2i_indicate_netevent(void *context, unsigned long event)
  1952. {
  1953. struct bnx2i_hba *hba = context;
  1954. switch (event) {
  1955. case NETDEV_UP:
  1956. if (!test_bit(ADAPTER_STATE_UP, &hba->adapter_state))
  1957. bnx2i_send_fw_iscsi_init_msg(hba);
  1958. break;
  1959. case NETDEV_DOWN:
  1960. clear_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  1961. clear_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1962. break;
  1963. case NETDEV_GOING_DOWN:
  1964. set_bit(ADAPTER_STATE_GOING_DOWN, &hba->adapter_state);
  1965. iscsi_host_for_each_session(hba->shost,
  1966. bnx2i_drop_session);
  1967. break;
  1968. case NETDEV_CHANGE:
  1969. bnx2i_get_link_state(hba);
  1970. break;
  1971. default:
  1972. ;
  1973. }
  1974. }
  1975. /**
  1976. * bnx2i_cm_connect_cmpl - process iscsi conn establishment completion
  1977. * @cm_sk: cnic sock structure pointer
  1978. *
  1979. * function callback exported via bnx2i - cnic driver interface to
  1980. * indicate completion of option-2 TCP connect request.
  1981. */
  1982. static void bnx2i_cm_connect_cmpl(struct cnic_sock *cm_sk)
  1983. {
  1984. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  1985. if (test_bit(ADAPTER_STATE_GOING_DOWN, &ep->hba->adapter_state))
  1986. ep->state = EP_STATE_CONNECT_FAILED;
  1987. else if (test_bit(SK_F_OFFLD_COMPLETE, &cm_sk->flags))
  1988. ep->state = EP_STATE_CONNECT_COMPL;
  1989. else
  1990. ep->state = EP_STATE_CONNECT_FAILED;
  1991. wake_up_interruptible(&ep->ofld_wait);
  1992. }
  1993. /**
  1994. * bnx2i_cm_close_cmpl - process tcp conn close completion
  1995. * @cm_sk: cnic sock structure pointer
  1996. *
  1997. * function callback exported via bnx2i - cnic driver interface to
  1998. * indicate completion of option-2 graceful TCP connect shutdown
  1999. */
  2000. static void bnx2i_cm_close_cmpl(struct cnic_sock *cm_sk)
  2001. {
  2002. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2003. ep->state = EP_STATE_DISCONN_COMPL;
  2004. wake_up_interruptible(&ep->ofld_wait);
  2005. }
  2006. /**
  2007. * bnx2i_cm_abort_cmpl - process abortive tcp conn teardown completion
  2008. * @cm_sk: cnic sock structure pointer
  2009. *
  2010. * function callback exported via bnx2i - cnic driver interface to
  2011. * indicate completion of option-2 abortive TCP connect termination
  2012. */
  2013. static void bnx2i_cm_abort_cmpl(struct cnic_sock *cm_sk)
  2014. {
  2015. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2016. ep->state = EP_STATE_DISCONN_COMPL;
  2017. wake_up_interruptible(&ep->ofld_wait);
  2018. }
  2019. /**
  2020. * bnx2i_cm_remote_close - process received TCP FIN
  2021. * @hba: adapter structure pointer
  2022. * @update_kcqe: kcqe pointer
  2023. *
  2024. * function callback exported via bnx2i - cnic driver interface to indicate
  2025. * async TCP events such as FIN
  2026. */
  2027. static void bnx2i_cm_remote_close(struct cnic_sock *cm_sk)
  2028. {
  2029. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2030. ep->state = EP_STATE_TCP_FIN_RCVD;
  2031. if (ep->conn)
  2032. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2033. }
  2034. /**
  2035. * bnx2i_cm_remote_abort - process TCP RST and start conn cleanup
  2036. * @hba: adapter structure pointer
  2037. * @update_kcqe: kcqe pointer
  2038. *
  2039. * function callback exported via bnx2i - cnic driver interface to
  2040. * indicate async TCP events (RST) sent by the peer.
  2041. */
  2042. static void bnx2i_cm_remote_abort(struct cnic_sock *cm_sk)
  2043. {
  2044. struct bnx2i_endpoint *ep = (struct bnx2i_endpoint *) cm_sk->context;
  2045. ep->state = EP_STATE_TCP_RST_RCVD;
  2046. if (ep->conn)
  2047. bnx2i_recovery_que_add_conn(ep->hba, ep->conn);
  2048. }
  2049. static void bnx2i_send_nl_mesg(struct cnic_dev *dev, u32 msg_type,
  2050. char *buf, u16 buflen)
  2051. {
  2052. struct bnx2i_hba *hba;
  2053. hba = bnx2i_find_hba_for_cnic(dev);
  2054. if (!hba)
  2055. return;
  2056. if (iscsi_offload_mesg(hba->shost, &bnx2i_iscsi_transport,
  2057. msg_type, buf, buflen))
  2058. printk(KERN_ALERT "bnx2i: private nl message send error\n");
  2059. }
  2060. /**
  2061. * bnx2i_cnic_cb - global template of bnx2i - cnic driver interface structure
  2062. * carrying callback function pointers
  2063. *
  2064. */
  2065. struct cnic_ulp_ops bnx2i_cnic_cb = {
  2066. .cnic_init = bnx2i_ulp_init,
  2067. .cnic_exit = bnx2i_ulp_exit,
  2068. .cnic_start = bnx2i_start,
  2069. .cnic_stop = bnx2i_stop,
  2070. .indicate_kcqes = bnx2i_indicate_kcqe,
  2071. .indicate_netevent = bnx2i_indicate_netevent,
  2072. .cm_connect_complete = bnx2i_cm_connect_cmpl,
  2073. .cm_close_complete = bnx2i_cm_close_cmpl,
  2074. .cm_abort_complete = bnx2i_cm_abort_cmpl,
  2075. .cm_remote_close = bnx2i_cm_remote_close,
  2076. .cm_remote_abort = bnx2i_cm_remote_abort,
  2077. .iscsi_nl_send_msg = bnx2i_send_nl_mesg,
  2078. .owner = THIS_MODULE
  2079. };
  2080. /**
  2081. * bnx2i_map_ep_dbell_regs - map connection doorbell registers
  2082. * @ep: bnx2i endpoint
  2083. *
  2084. * maps connection's SQ and RQ doorbell registers, 5706/5708/5709 hosts these
  2085. * register in BAR #0. Whereas in 57710 these register are accessed by
  2086. * mapping BAR #1
  2087. */
  2088. int bnx2i_map_ep_dbell_regs(struct bnx2i_endpoint *ep)
  2089. {
  2090. u32 cid_num;
  2091. u32 reg_off;
  2092. u32 first_l4l5;
  2093. u32 ctx_sz;
  2094. u32 config2;
  2095. resource_size_t reg_base;
  2096. cid_num = bnx2i_get_cid_num(ep);
  2097. if (test_bit(BNX2I_NX2_DEV_57710, &ep->hba->cnic_dev_type)) {
  2098. reg_base = pci_resource_start(ep->hba->pcidev,
  2099. BNX2X_DOORBELL_PCI_BAR);
  2100. reg_off = PAGE_SIZE * (cid_num & 0x1FFFF) + DPM_TRIGER_TYPE;
  2101. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off, 4);
  2102. goto arm_cq;
  2103. }
  2104. reg_base = ep->hba->netdev->base_addr;
  2105. if ((test_bit(BNX2I_NX2_DEV_5709, &ep->hba->cnic_dev_type)) &&
  2106. (ep->hba->mail_queue_access == BNX2I_MQ_BIN_MODE)) {
  2107. config2 = REG_RD(ep->hba, BNX2_MQ_CONFIG2);
  2108. first_l4l5 = config2 & BNX2_MQ_CONFIG2_FIRST_L4L5;
  2109. ctx_sz = (config2 & BNX2_MQ_CONFIG2_CONT_SZ) >> 3;
  2110. if (ctx_sz)
  2111. reg_off = CTX_OFFSET + MAX_CID_CNT * MB_KERNEL_CTX_SIZE
  2112. + BNX2I_570X_PAGE_SIZE_DEFAULT *
  2113. (((cid_num - first_l4l5) / ctx_sz) + 256);
  2114. else
  2115. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2116. } else
  2117. /* 5709 device in normal node and 5706/5708 devices */
  2118. reg_off = CTX_OFFSET + (MB_KERNEL_CTX_SIZE * cid_num);
  2119. ep->qp.ctx_base = ioremap_nocache(reg_base + reg_off,
  2120. MB_KERNEL_CTX_SIZE);
  2121. if (!ep->qp.ctx_base)
  2122. return -ENOMEM;
  2123. arm_cq:
  2124. bnx2i_arm_cq_event_coalescing(ep, CNIC_ARM_CQE);
  2125. return 0;
  2126. }