bnx2fc_hwi.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190
  1. /* bnx2fc_hwi.c: Broadcom NetXtreme II Linux FCoE offload driver.
  2. * This file contains the code that low level functions that interact
  3. * with 57712 FCoE firmware.
  4. *
  5. * Copyright (c) 2008 - 2011 Broadcom Corporation
  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: Bhanu Prakash Gollapudi (bprakash@broadcom.com)
  12. */
  13. #include "bnx2fc.h"
  14. DECLARE_PER_CPU(struct bnx2fc_percpu_s, bnx2fc_percpu);
  15. static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
  16. struct fcoe_kcqe *new_cqe_kcqe);
  17. static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
  18. struct fcoe_kcqe *ofld_kcqe);
  19. static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
  20. struct fcoe_kcqe *ofld_kcqe);
  21. static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code);
  22. static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
  23. struct fcoe_kcqe *destroy_kcqe);
  24. int bnx2fc_send_stat_req(struct bnx2fc_hba *hba)
  25. {
  26. struct fcoe_kwqe_stat stat_req;
  27. struct kwqe *kwqe_arr[2];
  28. int num_kwqes = 1;
  29. int rc = 0;
  30. memset(&stat_req, 0x00, sizeof(struct fcoe_kwqe_stat));
  31. stat_req.hdr.op_code = FCOE_KWQE_OPCODE_STAT;
  32. stat_req.hdr.flags =
  33. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  34. stat_req.stat_params_addr_lo = (u32) hba->stats_buf_dma;
  35. stat_req.stat_params_addr_hi = (u32) ((u64)hba->stats_buf_dma >> 32);
  36. kwqe_arr[0] = (struct kwqe *) &stat_req;
  37. if (hba->cnic && hba->cnic->submit_kwqes)
  38. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  39. return rc;
  40. }
  41. /**
  42. * bnx2fc_send_fw_fcoe_init_msg - initiates initial handshake with FCoE f/w
  43. *
  44. * @hba: adapter structure pointer
  45. *
  46. * Send down FCoE firmware init KWQEs which initiates the initial handshake
  47. * with the f/w.
  48. *
  49. */
  50. int bnx2fc_send_fw_fcoe_init_msg(struct bnx2fc_hba *hba)
  51. {
  52. struct fcoe_kwqe_init1 fcoe_init1;
  53. struct fcoe_kwqe_init2 fcoe_init2;
  54. struct fcoe_kwqe_init3 fcoe_init3;
  55. struct kwqe *kwqe_arr[3];
  56. int num_kwqes = 3;
  57. int rc = 0;
  58. if (!hba->cnic) {
  59. printk(KERN_ERR PFX "hba->cnic NULL during fcoe fw init\n");
  60. return -ENODEV;
  61. }
  62. /* fill init1 KWQE */
  63. memset(&fcoe_init1, 0x00, sizeof(struct fcoe_kwqe_init1));
  64. fcoe_init1.hdr.op_code = FCOE_KWQE_OPCODE_INIT1;
  65. fcoe_init1.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  66. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  67. fcoe_init1.num_tasks = BNX2FC_MAX_TASKS;
  68. fcoe_init1.sq_num_wqes = BNX2FC_SQ_WQES_MAX;
  69. fcoe_init1.rq_num_wqes = BNX2FC_RQ_WQES_MAX;
  70. fcoe_init1.rq_buffer_log_size = BNX2FC_RQ_BUF_LOG_SZ;
  71. fcoe_init1.cq_num_wqes = BNX2FC_CQ_WQES_MAX;
  72. fcoe_init1.dummy_buffer_addr_lo = (u32) hba->dummy_buf_dma;
  73. fcoe_init1.dummy_buffer_addr_hi = (u32) ((u64)hba->dummy_buf_dma >> 32);
  74. fcoe_init1.task_list_pbl_addr_lo = (u32) hba->task_ctx_bd_dma;
  75. fcoe_init1.task_list_pbl_addr_hi =
  76. (u32) ((u64) hba->task_ctx_bd_dma >> 32);
  77. fcoe_init1.mtu = BNX2FC_MINI_JUMBO_MTU;
  78. fcoe_init1.flags = (PAGE_SHIFT <<
  79. FCOE_KWQE_INIT1_LOG_PAGE_SIZE_SHIFT);
  80. fcoe_init1.num_sessions_log = BNX2FC_NUM_MAX_SESS_LOG;
  81. /* fill init2 KWQE */
  82. memset(&fcoe_init2, 0x00, sizeof(struct fcoe_kwqe_init2));
  83. fcoe_init2.hdr.op_code = FCOE_KWQE_OPCODE_INIT2;
  84. fcoe_init2.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  85. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  86. fcoe_init2.hsi_major_version = FCOE_HSI_MAJOR_VERSION;
  87. fcoe_init2.hsi_minor_version = FCOE_HSI_MINOR_VERSION;
  88. fcoe_init2.hash_tbl_pbl_addr_lo = (u32) hba->hash_tbl_pbl_dma;
  89. fcoe_init2.hash_tbl_pbl_addr_hi = (u32)
  90. ((u64) hba->hash_tbl_pbl_dma >> 32);
  91. fcoe_init2.t2_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_dma;
  92. fcoe_init2.t2_hash_tbl_addr_hi = (u32)
  93. ((u64) hba->t2_hash_tbl_dma >> 32);
  94. fcoe_init2.t2_ptr_hash_tbl_addr_lo = (u32) hba->t2_hash_tbl_ptr_dma;
  95. fcoe_init2.t2_ptr_hash_tbl_addr_hi = (u32)
  96. ((u64) hba->t2_hash_tbl_ptr_dma >> 32);
  97. fcoe_init2.free_list_count = BNX2FC_NUM_MAX_SESS;
  98. /* fill init3 KWQE */
  99. memset(&fcoe_init3, 0x00, sizeof(struct fcoe_kwqe_init3));
  100. fcoe_init3.hdr.op_code = FCOE_KWQE_OPCODE_INIT3;
  101. fcoe_init3.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  102. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  103. fcoe_init3.error_bit_map_lo = 0xffffffff;
  104. fcoe_init3.error_bit_map_hi = 0xffffffff;
  105. fcoe_init3.perf_config = 1;
  106. kwqe_arr[0] = (struct kwqe *) &fcoe_init1;
  107. kwqe_arr[1] = (struct kwqe *) &fcoe_init2;
  108. kwqe_arr[2] = (struct kwqe *) &fcoe_init3;
  109. if (hba->cnic && hba->cnic->submit_kwqes)
  110. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  111. return rc;
  112. }
  113. int bnx2fc_send_fw_fcoe_destroy_msg(struct bnx2fc_hba *hba)
  114. {
  115. struct fcoe_kwqe_destroy fcoe_destroy;
  116. struct kwqe *kwqe_arr[2];
  117. int num_kwqes = 1;
  118. int rc = -1;
  119. /* fill destroy KWQE */
  120. memset(&fcoe_destroy, 0x00, sizeof(struct fcoe_kwqe_destroy));
  121. fcoe_destroy.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY;
  122. fcoe_destroy.hdr.flags = (FCOE_KWQE_LAYER_CODE <<
  123. FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  124. kwqe_arr[0] = (struct kwqe *) &fcoe_destroy;
  125. if (hba->cnic && hba->cnic->submit_kwqes)
  126. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  127. return rc;
  128. }
  129. /**
  130. * bnx2fc_send_session_ofld_req - initiates FCoE Session offload process
  131. *
  132. * @port: port structure pointer
  133. * @tgt: bnx2fc_rport structure pointer
  134. */
  135. int bnx2fc_send_session_ofld_req(struct fcoe_port *port,
  136. struct bnx2fc_rport *tgt)
  137. {
  138. struct fc_lport *lport = port->lport;
  139. struct bnx2fc_interface *interface = port->priv;
  140. struct bnx2fc_hba *hba = interface->hba;
  141. struct kwqe *kwqe_arr[4];
  142. struct fcoe_kwqe_conn_offload1 ofld_req1;
  143. struct fcoe_kwqe_conn_offload2 ofld_req2;
  144. struct fcoe_kwqe_conn_offload3 ofld_req3;
  145. struct fcoe_kwqe_conn_offload4 ofld_req4;
  146. struct fc_rport_priv *rdata = tgt->rdata;
  147. struct fc_rport *rport = tgt->rport;
  148. int num_kwqes = 4;
  149. u32 port_id;
  150. int rc = 0;
  151. u16 conn_id;
  152. /* Initialize offload request 1 structure */
  153. memset(&ofld_req1, 0x00, sizeof(struct fcoe_kwqe_conn_offload1));
  154. ofld_req1.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN1;
  155. ofld_req1.hdr.flags =
  156. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  157. conn_id = (u16)tgt->fcoe_conn_id;
  158. ofld_req1.fcoe_conn_id = conn_id;
  159. ofld_req1.sq_addr_lo = (u32) tgt->sq_dma;
  160. ofld_req1.sq_addr_hi = (u32)((u64) tgt->sq_dma >> 32);
  161. ofld_req1.rq_pbl_addr_lo = (u32) tgt->rq_pbl_dma;
  162. ofld_req1.rq_pbl_addr_hi = (u32)((u64) tgt->rq_pbl_dma >> 32);
  163. ofld_req1.rq_first_pbe_addr_lo = (u32) tgt->rq_dma;
  164. ofld_req1.rq_first_pbe_addr_hi =
  165. (u32)((u64) tgt->rq_dma >> 32);
  166. ofld_req1.rq_prod = 0x8000;
  167. /* Initialize offload request 2 structure */
  168. memset(&ofld_req2, 0x00, sizeof(struct fcoe_kwqe_conn_offload2));
  169. ofld_req2.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN2;
  170. ofld_req2.hdr.flags =
  171. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  172. ofld_req2.tx_max_fc_pay_len = rdata->maxframe_size;
  173. ofld_req2.cq_addr_lo = (u32) tgt->cq_dma;
  174. ofld_req2.cq_addr_hi = (u32)((u64)tgt->cq_dma >> 32);
  175. ofld_req2.xferq_addr_lo = (u32) tgt->xferq_dma;
  176. ofld_req2.xferq_addr_hi = (u32)((u64)tgt->xferq_dma >> 32);
  177. ofld_req2.conn_db_addr_lo = (u32)tgt->conn_db_dma;
  178. ofld_req2.conn_db_addr_hi = (u32)((u64)tgt->conn_db_dma >> 32);
  179. /* Initialize offload request 3 structure */
  180. memset(&ofld_req3, 0x00, sizeof(struct fcoe_kwqe_conn_offload3));
  181. ofld_req3.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN3;
  182. ofld_req3.hdr.flags =
  183. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  184. ofld_req3.vlan_tag = interface->vlan_id <<
  185. FCOE_KWQE_CONN_OFFLOAD3_VLAN_ID_SHIFT;
  186. ofld_req3.vlan_tag |= 3 << FCOE_KWQE_CONN_OFFLOAD3_PRIORITY_SHIFT;
  187. port_id = fc_host_port_id(lport->host);
  188. if (port_id == 0) {
  189. BNX2FC_HBA_DBG(lport, "ofld_req: port_id = 0, link down?\n");
  190. return -EINVAL;
  191. }
  192. /*
  193. * Store s_id of the initiator for further reference. This will
  194. * be used during disable/destroy during linkdown processing as
  195. * when the lport is reset, the port_id also is reset to 0
  196. */
  197. tgt->sid = port_id;
  198. ofld_req3.s_id[0] = (port_id & 0x000000FF);
  199. ofld_req3.s_id[1] = (port_id & 0x0000FF00) >> 8;
  200. ofld_req3.s_id[2] = (port_id & 0x00FF0000) >> 16;
  201. port_id = rport->port_id;
  202. ofld_req3.d_id[0] = (port_id & 0x000000FF);
  203. ofld_req3.d_id[1] = (port_id & 0x0000FF00) >> 8;
  204. ofld_req3.d_id[2] = (port_id & 0x00FF0000) >> 16;
  205. ofld_req3.tx_total_conc_seqs = rdata->max_seq;
  206. ofld_req3.tx_max_conc_seqs_c3 = rdata->max_seq;
  207. ofld_req3.rx_max_fc_pay_len = lport->mfs;
  208. ofld_req3.rx_total_conc_seqs = BNX2FC_MAX_SEQS;
  209. ofld_req3.rx_max_conc_seqs_c3 = BNX2FC_MAX_SEQS;
  210. ofld_req3.rx_open_seqs_exch_c3 = 1;
  211. ofld_req3.confq_first_pbe_addr_lo = tgt->confq_dma;
  212. ofld_req3.confq_first_pbe_addr_hi = (u32)((u64) tgt->confq_dma >> 32);
  213. /* set mul_n_port_ids supported flag to 0, until it is supported */
  214. ofld_req3.flags = 0;
  215. /*
  216. ofld_req3.flags |= (((lport->send_sp_features & FC_SP_FT_MNA) ? 1:0) <<
  217. FCOE_KWQE_CONN_OFFLOAD3_B_MUL_N_PORT_IDS_SHIFT);
  218. */
  219. /* Info from PLOGI response */
  220. ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_EDTR) ? 1 : 0) <<
  221. FCOE_KWQE_CONN_OFFLOAD3_B_E_D_TOV_RES_SHIFT);
  222. ofld_req3.flags |= (((rdata->sp_features & FC_SP_FT_SEQC) ? 1 : 0) <<
  223. FCOE_KWQE_CONN_OFFLOAD3_B_CONT_INCR_SEQ_CNT_SHIFT);
  224. /*
  225. * Info from PRLI response, this info is used for sequence level error
  226. * recovery support
  227. */
  228. if (tgt->dev_type == TYPE_TAPE) {
  229. ofld_req3.flags |= 1 <<
  230. FCOE_KWQE_CONN_OFFLOAD3_B_CONF_REQ_SHIFT;
  231. ofld_req3.flags |= (((rdata->flags & FC_RP_FLAGS_REC_SUPPORTED)
  232. ? 1 : 0) <<
  233. FCOE_KWQE_CONN_OFFLOAD3_B_REC_VALID_SHIFT);
  234. }
  235. /* vlan flag */
  236. ofld_req3.flags |= (interface->vlan_enabled <<
  237. FCOE_KWQE_CONN_OFFLOAD3_B_VLAN_FLAG_SHIFT);
  238. /* C2_VALID and ACK flags are not set as they are not suppported */
  239. /* Initialize offload request 4 structure */
  240. memset(&ofld_req4, 0x00, sizeof(struct fcoe_kwqe_conn_offload4));
  241. ofld_req4.hdr.op_code = FCOE_KWQE_OPCODE_OFFLOAD_CONN4;
  242. ofld_req4.hdr.flags =
  243. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  244. ofld_req4.e_d_tov_timer_val = lport->e_d_tov / 20;
  245. ofld_req4.src_mac_addr_lo[0] = port->data_src_addr[5];
  246. /* local mac */
  247. ofld_req4.src_mac_addr_lo[1] = port->data_src_addr[4];
  248. ofld_req4.src_mac_addr_mid[0] = port->data_src_addr[3];
  249. ofld_req4.src_mac_addr_mid[1] = port->data_src_addr[2];
  250. ofld_req4.src_mac_addr_hi[0] = port->data_src_addr[1];
  251. ofld_req4.src_mac_addr_hi[1] = port->data_src_addr[0];
  252. ofld_req4.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
  253. /* fcf mac */
  254. ofld_req4.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
  255. ofld_req4.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
  256. ofld_req4.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
  257. ofld_req4.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
  258. ofld_req4.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
  259. ofld_req4.lcq_addr_lo = (u32) tgt->lcq_dma;
  260. ofld_req4.lcq_addr_hi = (u32)((u64) tgt->lcq_dma >> 32);
  261. ofld_req4.confq_pbl_base_addr_lo = (u32) tgt->confq_pbl_dma;
  262. ofld_req4.confq_pbl_base_addr_hi =
  263. (u32)((u64) tgt->confq_pbl_dma >> 32);
  264. kwqe_arr[0] = (struct kwqe *) &ofld_req1;
  265. kwqe_arr[1] = (struct kwqe *) &ofld_req2;
  266. kwqe_arr[2] = (struct kwqe *) &ofld_req3;
  267. kwqe_arr[3] = (struct kwqe *) &ofld_req4;
  268. if (hba->cnic && hba->cnic->submit_kwqes)
  269. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  270. return rc;
  271. }
  272. /**
  273. * bnx2fc_send_session_enable_req - initiates FCoE Session enablement
  274. *
  275. * @port: port structure pointer
  276. * @tgt: bnx2fc_rport structure pointer
  277. */
  278. static int bnx2fc_send_session_enable_req(struct fcoe_port *port,
  279. struct bnx2fc_rport *tgt)
  280. {
  281. struct kwqe *kwqe_arr[2];
  282. struct bnx2fc_interface *interface = port->priv;
  283. struct bnx2fc_hba *hba = interface->hba;
  284. struct fcoe_kwqe_conn_enable_disable enbl_req;
  285. struct fc_lport *lport = port->lport;
  286. struct fc_rport *rport = tgt->rport;
  287. int num_kwqes = 1;
  288. int rc = 0;
  289. u32 port_id;
  290. memset(&enbl_req, 0x00,
  291. sizeof(struct fcoe_kwqe_conn_enable_disable));
  292. enbl_req.hdr.op_code = FCOE_KWQE_OPCODE_ENABLE_CONN;
  293. enbl_req.hdr.flags =
  294. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  295. enbl_req.src_mac_addr_lo[0] = port->data_src_addr[5];
  296. /* local mac */
  297. enbl_req.src_mac_addr_lo[1] = port->data_src_addr[4];
  298. enbl_req.src_mac_addr_mid[0] = port->data_src_addr[3];
  299. enbl_req.src_mac_addr_mid[1] = port->data_src_addr[2];
  300. enbl_req.src_mac_addr_hi[0] = port->data_src_addr[1];
  301. enbl_req.src_mac_addr_hi[1] = port->data_src_addr[0];
  302. memcpy(tgt->src_addr, port->data_src_addr, ETH_ALEN);
  303. enbl_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
  304. enbl_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
  305. enbl_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
  306. enbl_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
  307. enbl_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
  308. enbl_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
  309. port_id = fc_host_port_id(lport->host);
  310. if (port_id != tgt->sid) {
  311. printk(KERN_ERR PFX "WARN: enable_req port_id = 0x%x,"
  312. "sid = 0x%x\n", port_id, tgt->sid);
  313. port_id = tgt->sid;
  314. }
  315. enbl_req.s_id[0] = (port_id & 0x000000FF);
  316. enbl_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
  317. enbl_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
  318. port_id = rport->port_id;
  319. enbl_req.d_id[0] = (port_id & 0x000000FF);
  320. enbl_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
  321. enbl_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
  322. enbl_req.vlan_tag = interface->vlan_id <<
  323. FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
  324. enbl_req.vlan_tag |= 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
  325. enbl_req.vlan_flag = interface->vlan_enabled;
  326. enbl_req.context_id = tgt->context_id;
  327. enbl_req.conn_id = tgt->fcoe_conn_id;
  328. kwqe_arr[0] = (struct kwqe *) &enbl_req;
  329. if (hba->cnic && hba->cnic->submit_kwqes)
  330. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  331. return rc;
  332. }
  333. /**
  334. * bnx2fc_send_session_disable_req - initiates FCoE Session disable
  335. *
  336. * @port: port structure pointer
  337. * @tgt: bnx2fc_rport structure pointer
  338. */
  339. int bnx2fc_send_session_disable_req(struct fcoe_port *port,
  340. struct bnx2fc_rport *tgt)
  341. {
  342. struct bnx2fc_interface *interface = port->priv;
  343. struct bnx2fc_hba *hba = interface->hba;
  344. struct fcoe_kwqe_conn_enable_disable disable_req;
  345. struct kwqe *kwqe_arr[2];
  346. struct fc_rport *rport = tgt->rport;
  347. int num_kwqes = 1;
  348. int rc = 0;
  349. u32 port_id;
  350. memset(&disable_req, 0x00,
  351. sizeof(struct fcoe_kwqe_conn_enable_disable));
  352. disable_req.hdr.op_code = FCOE_KWQE_OPCODE_DISABLE_CONN;
  353. disable_req.hdr.flags =
  354. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  355. disable_req.src_mac_addr_lo[0] = tgt->src_addr[5];
  356. disable_req.src_mac_addr_lo[1] = tgt->src_addr[4];
  357. disable_req.src_mac_addr_mid[0] = tgt->src_addr[3];
  358. disable_req.src_mac_addr_mid[1] = tgt->src_addr[2];
  359. disable_req.src_mac_addr_hi[0] = tgt->src_addr[1];
  360. disable_req.src_mac_addr_hi[1] = tgt->src_addr[0];
  361. disable_req.dst_mac_addr_lo[0] = interface->ctlr.dest_addr[5];
  362. disable_req.dst_mac_addr_lo[1] = interface->ctlr.dest_addr[4];
  363. disable_req.dst_mac_addr_mid[0] = interface->ctlr.dest_addr[3];
  364. disable_req.dst_mac_addr_mid[1] = interface->ctlr.dest_addr[2];
  365. disable_req.dst_mac_addr_hi[0] = interface->ctlr.dest_addr[1];
  366. disable_req.dst_mac_addr_hi[1] = interface->ctlr.dest_addr[0];
  367. port_id = tgt->sid;
  368. disable_req.s_id[0] = (port_id & 0x000000FF);
  369. disable_req.s_id[1] = (port_id & 0x0000FF00) >> 8;
  370. disable_req.s_id[2] = (port_id & 0x00FF0000) >> 16;
  371. port_id = rport->port_id;
  372. disable_req.d_id[0] = (port_id & 0x000000FF);
  373. disable_req.d_id[1] = (port_id & 0x0000FF00) >> 8;
  374. disable_req.d_id[2] = (port_id & 0x00FF0000) >> 16;
  375. disable_req.context_id = tgt->context_id;
  376. disable_req.conn_id = tgt->fcoe_conn_id;
  377. disable_req.vlan_tag = interface->vlan_id <<
  378. FCOE_KWQE_CONN_ENABLE_DISABLE_VLAN_ID_SHIFT;
  379. disable_req.vlan_tag |=
  380. 3 << FCOE_KWQE_CONN_ENABLE_DISABLE_PRIORITY_SHIFT;
  381. disable_req.vlan_flag = interface->vlan_enabled;
  382. kwqe_arr[0] = (struct kwqe *) &disable_req;
  383. if (hba->cnic && hba->cnic->submit_kwqes)
  384. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  385. return rc;
  386. }
  387. /**
  388. * bnx2fc_send_session_destroy_req - initiates FCoE Session destroy
  389. *
  390. * @port: port structure pointer
  391. * @tgt: bnx2fc_rport structure pointer
  392. */
  393. int bnx2fc_send_session_destroy_req(struct bnx2fc_hba *hba,
  394. struct bnx2fc_rport *tgt)
  395. {
  396. struct fcoe_kwqe_conn_destroy destroy_req;
  397. struct kwqe *kwqe_arr[2];
  398. int num_kwqes = 1;
  399. int rc = 0;
  400. memset(&destroy_req, 0x00, sizeof(struct fcoe_kwqe_conn_destroy));
  401. destroy_req.hdr.op_code = FCOE_KWQE_OPCODE_DESTROY_CONN;
  402. destroy_req.hdr.flags =
  403. (FCOE_KWQE_LAYER_CODE << FCOE_KWQE_HEADER_LAYER_CODE_SHIFT);
  404. destroy_req.context_id = tgt->context_id;
  405. destroy_req.conn_id = tgt->fcoe_conn_id;
  406. kwqe_arr[0] = (struct kwqe *) &destroy_req;
  407. if (hba->cnic && hba->cnic->submit_kwqes)
  408. rc = hba->cnic->submit_kwqes(hba->cnic, kwqe_arr, num_kwqes);
  409. return rc;
  410. }
  411. static bool is_valid_lport(struct bnx2fc_hba *hba, struct fc_lport *lport)
  412. {
  413. struct bnx2fc_lport *blport;
  414. spin_lock_bh(&hba->hba_lock);
  415. list_for_each_entry(blport, &hba->vports, list) {
  416. if (blport->lport == lport) {
  417. spin_unlock_bh(&hba->hba_lock);
  418. return true;
  419. }
  420. }
  421. spin_unlock_bh(&hba->hba_lock);
  422. return false;
  423. }
  424. static void bnx2fc_unsol_els_work(struct work_struct *work)
  425. {
  426. struct bnx2fc_unsol_els *unsol_els;
  427. struct fc_lport *lport;
  428. struct bnx2fc_hba *hba;
  429. struct fc_frame *fp;
  430. unsol_els = container_of(work, struct bnx2fc_unsol_els, unsol_els_work);
  431. lport = unsol_els->lport;
  432. fp = unsol_els->fp;
  433. hba = unsol_els->hba;
  434. if (is_valid_lport(hba, lport))
  435. fc_exch_recv(lport, fp);
  436. kfree(unsol_els);
  437. }
  438. void bnx2fc_process_l2_frame_compl(struct bnx2fc_rport *tgt,
  439. unsigned char *buf,
  440. u32 frame_len, u16 l2_oxid)
  441. {
  442. struct fcoe_port *port = tgt->port;
  443. struct fc_lport *lport = port->lport;
  444. struct bnx2fc_interface *interface = port->priv;
  445. struct bnx2fc_unsol_els *unsol_els;
  446. struct fc_frame_header *fh;
  447. struct fc_frame *fp;
  448. struct sk_buff *skb;
  449. u32 payload_len;
  450. u32 crc;
  451. u8 op;
  452. unsol_els = kzalloc(sizeof(*unsol_els), GFP_ATOMIC);
  453. if (!unsol_els) {
  454. BNX2FC_TGT_DBG(tgt, "Unable to allocate unsol_work\n");
  455. return;
  456. }
  457. BNX2FC_TGT_DBG(tgt, "l2_frame_compl l2_oxid = 0x%x, frame_len = %d\n",
  458. l2_oxid, frame_len);
  459. payload_len = frame_len - sizeof(struct fc_frame_header);
  460. fp = fc_frame_alloc(lport, payload_len);
  461. if (!fp) {
  462. printk(KERN_ERR PFX "fc_frame_alloc failure\n");
  463. kfree(unsol_els);
  464. return;
  465. }
  466. fh = (struct fc_frame_header *) fc_frame_header_get(fp);
  467. /* Copy FC Frame header and payload into the frame */
  468. memcpy(fh, buf, frame_len);
  469. if (l2_oxid != FC_XID_UNKNOWN)
  470. fh->fh_ox_id = htons(l2_oxid);
  471. skb = fp_skb(fp);
  472. if ((fh->fh_r_ctl == FC_RCTL_ELS_REQ) ||
  473. (fh->fh_r_ctl == FC_RCTL_ELS_REP)) {
  474. if (fh->fh_type == FC_TYPE_ELS) {
  475. op = fc_frame_payload_op(fp);
  476. if ((op == ELS_TEST) || (op == ELS_ESTC) ||
  477. (op == ELS_FAN) || (op == ELS_CSU)) {
  478. /*
  479. * No need to reply for these
  480. * ELS requests
  481. */
  482. printk(KERN_ERR PFX "dropping ELS 0x%x\n", op);
  483. kfree_skb(skb);
  484. kfree(unsol_els);
  485. return;
  486. }
  487. }
  488. crc = fcoe_fc_crc(fp);
  489. fc_frame_init(fp);
  490. fr_dev(fp) = lport;
  491. fr_sof(fp) = FC_SOF_I3;
  492. fr_eof(fp) = FC_EOF_T;
  493. fr_crc(fp) = cpu_to_le32(~crc);
  494. unsol_els->lport = lport;
  495. unsol_els->hba = interface->hba;
  496. unsol_els->fp = fp;
  497. INIT_WORK(&unsol_els->unsol_els_work, bnx2fc_unsol_els_work);
  498. queue_work(bnx2fc_wq, &unsol_els->unsol_els_work);
  499. } else {
  500. BNX2FC_HBA_DBG(lport, "fh_r_ctl = 0x%x\n", fh->fh_r_ctl);
  501. kfree_skb(skb);
  502. kfree(unsol_els);
  503. }
  504. }
  505. static void bnx2fc_process_unsol_compl(struct bnx2fc_rport *tgt, u16 wqe)
  506. {
  507. u8 num_rq;
  508. struct fcoe_err_report_entry *err_entry;
  509. unsigned char *rq_data;
  510. unsigned char *buf = NULL, *buf1;
  511. int i;
  512. u16 xid;
  513. u32 frame_len, len;
  514. struct bnx2fc_cmd *io_req = NULL;
  515. struct fcoe_task_ctx_entry *task, *task_page;
  516. struct bnx2fc_interface *interface = tgt->port->priv;
  517. struct bnx2fc_hba *hba = interface->hba;
  518. int task_idx, index;
  519. int rc = 0;
  520. u64 err_warn_bit_map;
  521. u8 err_warn = 0xff;
  522. BNX2FC_TGT_DBG(tgt, "Entered UNSOL COMPLETION wqe = 0x%x\n", wqe);
  523. switch (wqe & FCOE_UNSOLICITED_CQE_SUBTYPE) {
  524. case FCOE_UNSOLICITED_FRAME_CQE_TYPE:
  525. frame_len = (wqe & FCOE_UNSOLICITED_CQE_PKT_LEN) >>
  526. FCOE_UNSOLICITED_CQE_PKT_LEN_SHIFT;
  527. num_rq = (frame_len + BNX2FC_RQ_BUF_SZ - 1) / BNX2FC_RQ_BUF_SZ;
  528. spin_lock_bh(&tgt->tgt_lock);
  529. rq_data = (unsigned char *)bnx2fc_get_next_rqe(tgt, num_rq);
  530. spin_unlock_bh(&tgt->tgt_lock);
  531. if (rq_data) {
  532. buf = rq_data;
  533. } else {
  534. buf1 = buf = kmalloc((num_rq * BNX2FC_RQ_BUF_SZ),
  535. GFP_ATOMIC);
  536. if (!buf1) {
  537. BNX2FC_TGT_DBG(tgt, "Memory alloc failure\n");
  538. break;
  539. }
  540. for (i = 0; i < num_rq; i++) {
  541. spin_lock_bh(&tgt->tgt_lock);
  542. rq_data = (unsigned char *)
  543. bnx2fc_get_next_rqe(tgt, 1);
  544. spin_unlock_bh(&tgt->tgt_lock);
  545. len = BNX2FC_RQ_BUF_SZ;
  546. memcpy(buf1, rq_data, len);
  547. buf1 += len;
  548. }
  549. }
  550. bnx2fc_process_l2_frame_compl(tgt, buf, frame_len,
  551. FC_XID_UNKNOWN);
  552. if (buf != rq_data)
  553. kfree(buf);
  554. spin_lock_bh(&tgt->tgt_lock);
  555. bnx2fc_return_rqe(tgt, num_rq);
  556. spin_unlock_bh(&tgt->tgt_lock);
  557. break;
  558. case FCOE_ERROR_DETECTION_CQE_TYPE:
  559. /*
  560. * In case of error reporting CQE a single RQ entry
  561. * is consumed.
  562. */
  563. spin_lock_bh(&tgt->tgt_lock);
  564. num_rq = 1;
  565. err_entry = (struct fcoe_err_report_entry *)
  566. bnx2fc_get_next_rqe(tgt, 1);
  567. xid = err_entry->fc_hdr.ox_id;
  568. BNX2FC_TGT_DBG(tgt, "Unsol Error Frame OX_ID = 0x%x\n", xid);
  569. BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x\n",
  570. err_entry->data.err_warn_bitmap_hi,
  571. err_entry->data.err_warn_bitmap_lo);
  572. BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x\n",
  573. err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
  574. if (xid > BNX2FC_MAX_XID) {
  575. BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n",
  576. xid);
  577. goto ret_err_rqe;
  578. }
  579. task_idx = xid / BNX2FC_TASKS_PER_PAGE;
  580. index = xid % BNX2FC_TASKS_PER_PAGE;
  581. task_page = (struct fcoe_task_ctx_entry *)
  582. hba->task_ctx[task_idx];
  583. task = &(task_page[index]);
  584. io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
  585. if (!io_req)
  586. goto ret_err_rqe;
  587. if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
  588. printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
  589. goto ret_err_rqe;
  590. }
  591. if (test_and_clear_bit(BNX2FC_FLAG_IO_CLEANUP,
  592. &io_req->req_flags)) {
  593. BNX2FC_IO_DBG(io_req, "unsol_err: cleanup in "
  594. "progress.. ignore unsol err\n");
  595. goto ret_err_rqe;
  596. }
  597. err_warn_bit_map = (u64)
  598. ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
  599. (u64)err_entry->data.err_warn_bitmap_lo;
  600. for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
  601. if (err_warn_bit_map & (u64)((u64)1 << i)) {
  602. err_warn = i;
  603. break;
  604. }
  605. }
  606. /*
  607. * If ABTS is already in progress, and FW error is
  608. * received after that, do not cancel the timeout_work
  609. * and let the error recovery continue by explicitly
  610. * logging out the target, when the ABTS eventually
  611. * times out.
  612. */
  613. if (test_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags)) {
  614. printk(KERN_ERR PFX "err_warn: io_req (0x%x) already "
  615. "in ABTS processing\n", xid);
  616. goto ret_err_rqe;
  617. }
  618. BNX2FC_TGT_DBG(tgt, "err = 0x%x\n", err_warn);
  619. if (tgt->dev_type != TYPE_TAPE)
  620. goto skip_rec;
  621. switch (err_warn) {
  622. case FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION:
  623. case FCOE_ERROR_CODE_DATA_OOO_RO:
  624. case FCOE_ERROR_CODE_COMMON_INCORRECT_SEQ_CNT:
  625. case FCOE_ERROR_CODE_DATA_SOFI3_SEQ_ACTIVE_SET:
  626. case FCOE_ERROR_CODE_FCP_RSP_OPENED_SEQ:
  627. case FCOE_ERROR_CODE_DATA_SOFN_SEQ_ACTIVE_RESET:
  628. BNX2FC_TGT_DBG(tgt, "REC TOV popped for xid - 0x%x\n",
  629. xid);
  630. memset(&io_req->err_entry, 0,
  631. sizeof(struct fcoe_err_report_entry));
  632. memcpy(&io_req->err_entry, err_entry,
  633. sizeof(struct fcoe_err_report_entry));
  634. if (!test_bit(BNX2FC_FLAG_SRR_SENT,
  635. &io_req->req_flags)) {
  636. spin_unlock_bh(&tgt->tgt_lock);
  637. rc = bnx2fc_send_rec(io_req);
  638. spin_lock_bh(&tgt->tgt_lock);
  639. if (rc)
  640. goto skip_rec;
  641. } else
  642. printk(KERN_ERR PFX "SRR in progress\n");
  643. goto ret_err_rqe;
  644. break;
  645. default:
  646. break;
  647. }
  648. skip_rec:
  649. set_bit(BNX2FC_FLAG_ISSUE_ABTS, &io_req->req_flags);
  650. /*
  651. * Cancel the timeout_work, as we received IO
  652. * completion with FW error.
  653. */
  654. if (cancel_delayed_work(&io_req->timeout_work))
  655. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  656. rc = bnx2fc_initiate_abts(io_req);
  657. if (rc != SUCCESS) {
  658. printk(KERN_ERR PFX "err_warn: initiate_abts "
  659. "failed xid = 0x%x. issue cleanup\n",
  660. io_req->xid);
  661. bnx2fc_initiate_cleanup(io_req);
  662. }
  663. ret_err_rqe:
  664. bnx2fc_return_rqe(tgt, 1);
  665. spin_unlock_bh(&tgt->tgt_lock);
  666. break;
  667. case FCOE_WARNING_DETECTION_CQE_TYPE:
  668. /*
  669. *In case of warning reporting CQE a single RQ entry
  670. * is consumes.
  671. */
  672. spin_lock_bh(&tgt->tgt_lock);
  673. num_rq = 1;
  674. err_entry = (struct fcoe_err_report_entry *)
  675. bnx2fc_get_next_rqe(tgt, 1);
  676. xid = cpu_to_be16(err_entry->fc_hdr.ox_id);
  677. BNX2FC_TGT_DBG(tgt, "Unsol Warning Frame OX_ID = 0x%x\n", xid);
  678. BNX2FC_TGT_DBG(tgt, "err_warn_bitmap = %08x:%08x",
  679. err_entry->data.err_warn_bitmap_hi,
  680. err_entry->data.err_warn_bitmap_lo);
  681. BNX2FC_TGT_DBG(tgt, "buf_offsets - tx = 0x%x, rx = 0x%x",
  682. err_entry->data.tx_buf_off, err_entry->data.rx_buf_off);
  683. if (xid > BNX2FC_MAX_XID) {
  684. BNX2FC_TGT_DBG(tgt, "xid(0x%x) out of FW range\n", xid);
  685. goto ret_warn_rqe;
  686. }
  687. err_warn_bit_map = (u64)
  688. ((u64)err_entry->data.err_warn_bitmap_hi << 32) |
  689. (u64)err_entry->data.err_warn_bitmap_lo;
  690. for (i = 0; i < BNX2FC_NUM_ERR_BITS; i++) {
  691. if (err_warn_bit_map & (u64) (1 << i)) {
  692. err_warn = i;
  693. break;
  694. }
  695. }
  696. BNX2FC_TGT_DBG(tgt, "warn = 0x%x\n", err_warn);
  697. task_idx = xid / BNX2FC_TASKS_PER_PAGE;
  698. index = xid % BNX2FC_TASKS_PER_PAGE;
  699. task_page = (struct fcoe_task_ctx_entry *)
  700. interface->hba->task_ctx[task_idx];
  701. task = &(task_page[index]);
  702. io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
  703. if (!io_req)
  704. goto ret_warn_rqe;
  705. if (io_req->cmd_type != BNX2FC_SCSI_CMD) {
  706. printk(KERN_ERR PFX "err_warn: Not a SCSI cmd\n");
  707. goto ret_warn_rqe;
  708. }
  709. memset(&io_req->err_entry, 0,
  710. sizeof(struct fcoe_err_report_entry));
  711. memcpy(&io_req->err_entry, err_entry,
  712. sizeof(struct fcoe_err_report_entry));
  713. if (err_warn == FCOE_ERROR_CODE_REC_TOV_TIMER_EXPIRATION)
  714. /* REC_TOV is not a warning code */
  715. BUG_ON(1);
  716. else
  717. BNX2FC_TGT_DBG(tgt, "Unsolicited warning\n");
  718. ret_warn_rqe:
  719. bnx2fc_return_rqe(tgt, 1);
  720. spin_unlock_bh(&tgt->tgt_lock);
  721. break;
  722. default:
  723. printk(KERN_ERR PFX "Unsol Compl: Invalid CQE Subtype\n");
  724. break;
  725. }
  726. }
  727. void bnx2fc_process_cq_compl(struct bnx2fc_rport *tgt, u16 wqe)
  728. {
  729. struct fcoe_task_ctx_entry *task;
  730. struct fcoe_task_ctx_entry *task_page;
  731. struct fcoe_port *port = tgt->port;
  732. struct bnx2fc_interface *interface = port->priv;
  733. struct bnx2fc_hba *hba = interface->hba;
  734. struct bnx2fc_cmd *io_req;
  735. int task_idx, index;
  736. u16 xid;
  737. u8 cmd_type;
  738. u8 rx_state = 0;
  739. u8 num_rq;
  740. spin_lock_bh(&tgt->tgt_lock);
  741. xid = wqe & FCOE_PEND_WQ_CQE_TASK_ID;
  742. if (xid >= BNX2FC_MAX_TASKS) {
  743. printk(KERN_ERR PFX "ERROR:xid out of range\n");
  744. spin_unlock_bh(&tgt->tgt_lock);
  745. return;
  746. }
  747. task_idx = xid / BNX2FC_TASKS_PER_PAGE;
  748. index = xid % BNX2FC_TASKS_PER_PAGE;
  749. task_page = (struct fcoe_task_ctx_entry *)hba->task_ctx[task_idx];
  750. task = &(task_page[index]);
  751. num_rq = ((task->rxwr_txrd.var_ctx.rx_flags &
  752. FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE) >>
  753. FCOE_TCE_RX_WR_TX_RD_VAR_NUM_RQ_WQE_SHIFT);
  754. io_req = (struct bnx2fc_cmd *)hba->cmd_mgr->cmds[xid];
  755. if (io_req == NULL) {
  756. printk(KERN_ERR PFX "ERROR? cq_compl - io_req is NULL\n");
  757. spin_unlock_bh(&tgt->tgt_lock);
  758. return;
  759. }
  760. /* Timestamp IO completion time */
  761. cmd_type = io_req->cmd_type;
  762. rx_state = ((task->rxwr_txrd.var_ctx.rx_flags &
  763. FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE) >>
  764. FCOE_TCE_RX_WR_TX_RD_VAR_RX_STATE_SHIFT);
  765. /* Process other IO completion types */
  766. switch (cmd_type) {
  767. case BNX2FC_SCSI_CMD:
  768. if (rx_state == FCOE_TASK_RX_STATE_COMPLETED) {
  769. bnx2fc_process_scsi_cmd_compl(io_req, task, num_rq);
  770. spin_unlock_bh(&tgt->tgt_lock);
  771. return;
  772. }
  773. if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
  774. bnx2fc_process_abts_compl(io_req, task, num_rq);
  775. else if (rx_state ==
  776. FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
  777. bnx2fc_process_cleanup_compl(io_req, task, num_rq);
  778. else
  779. printk(KERN_ERR PFX "Invalid rx state - %d\n",
  780. rx_state);
  781. break;
  782. case BNX2FC_TASK_MGMT_CMD:
  783. BNX2FC_IO_DBG(io_req, "Processing TM complete\n");
  784. bnx2fc_process_tm_compl(io_req, task, num_rq);
  785. break;
  786. case BNX2FC_ABTS:
  787. /*
  788. * ABTS request received by firmware. ABTS response
  789. * will be delivered to the task belonging to the IO
  790. * that was aborted
  791. */
  792. BNX2FC_IO_DBG(io_req, "cq_compl- ABTS sent out by fw\n");
  793. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  794. break;
  795. case BNX2FC_ELS:
  796. if (rx_state == FCOE_TASK_RX_STATE_COMPLETED)
  797. bnx2fc_process_els_compl(io_req, task, num_rq);
  798. else if (rx_state == FCOE_TASK_RX_STATE_ABTS_COMPLETED)
  799. bnx2fc_process_abts_compl(io_req, task, num_rq);
  800. else if (rx_state ==
  801. FCOE_TASK_RX_STATE_EXCHANGE_CLEANUP_COMPLETED)
  802. bnx2fc_process_cleanup_compl(io_req, task, num_rq);
  803. else
  804. printk(KERN_ERR PFX "Invalid rx state = %d\n",
  805. rx_state);
  806. break;
  807. case BNX2FC_CLEANUP:
  808. BNX2FC_IO_DBG(io_req, "cq_compl- cleanup resp rcvd\n");
  809. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  810. break;
  811. case BNX2FC_SEQ_CLEANUP:
  812. BNX2FC_IO_DBG(io_req, "cq_compl(0x%x) - seq cleanup resp\n",
  813. io_req->xid);
  814. bnx2fc_process_seq_cleanup_compl(io_req, task, rx_state);
  815. kref_put(&io_req->refcount, bnx2fc_cmd_release);
  816. break;
  817. default:
  818. printk(KERN_ERR PFX "Invalid cmd_type %d\n", cmd_type);
  819. break;
  820. }
  821. spin_unlock_bh(&tgt->tgt_lock);
  822. }
  823. void bnx2fc_arm_cq(struct bnx2fc_rport *tgt)
  824. {
  825. struct b577xx_fcoe_rx_doorbell *rx_db = &tgt->rx_db;
  826. u32 msg;
  827. wmb();
  828. rx_db->doorbell_cq_cons = tgt->cq_cons_idx | (tgt->cq_curr_toggle_bit <<
  829. FCOE_CQE_TOGGLE_BIT_SHIFT);
  830. msg = *((u32 *)rx_db);
  831. writel(cpu_to_le32(msg), tgt->ctx_base);
  832. mmiowb();
  833. }
  834. struct bnx2fc_work *bnx2fc_alloc_work(struct bnx2fc_rport *tgt, u16 wqe)
  835. {
  836. struct bnx2fc_work *work;
  837. work = kzalloc(sizeof(struct bnx2fc_work), GFP_ATOMIC);
  838. if (!work)
  839. return NULL;
  840. INIT_LIST_HEAD(&work->list);
  841. work->tgt = tgt;
  842. work->wqe = wqe;
  843. return work;
  844. }
  845. int bnx2fc_process_new_cqes(struct bnx2fc_rport *tgt)
  846. {
  847. struct fcoe_cqe *cq;
  848. u32 cq_cons;
  849. struct fcoe_cqe *cqe;
  850. u32 num_free_sqes = 0;
  851. u32 num_cqes = 0;
  852. u16 wqe;
  853. /*
  854. * cq_lock is a low contention lock used to protect
  855. * the CQ data structure from being freed up during
  856. * the upload operation
  857. */
  858. spin_lock_bh(&tgt->cq_lock);
  859. if (!tgt->cq) {
  860. printk(KERN_ERR PFX "process_new_cqes: cq is NULL\n");
  861. spin_unlock_bh(&tgt->cq_lock);
  862. return 0;
  863. }
  864. cq = tgt->cq;
  865. cq_cons = tgt->cq_cons_idx;
  866. cqe = &cq[cq_cons];
  867. while (((wqe = cqe->wqe) & FCOE_CQE_TOGGLE_BIT) ==
  868. (tgt->cq_curr_toggle_bit <<
  869. FCOE_CQE_TOGGLE_BIT_SHIFT)) {
  870. /* new entry on the cq */
  871. if (wqe & FCOE_CQE_CQE_TYPE) {
  872. /* Unsolicited event notification */
  873. bnx2fc_process_unsol_compl(tgt, wqe);
  874. } else {
  875. /* Pending work request completion */
  876. struct bnx2fc_work *work = NULL;
  877. struct bnx2fc_percpu_s *fps = NULL;
  878. unsigned int cpu = wqe % num_possible_cpus();
  879. fps = &per_cpu(bnx2fc_percpu, cpu);
  880. spin_lock_bh(&fps->fp_work_lock);
  881. if (unlikely(!fps->iothread))
  882. goto unlock;
  883. work = bnx2fc_alloc_work(tgt, wqe);
  884. if (work)
  885. list_add_tail(&work->list,
  886. &fps->work_list);
  887. unlock:
  888. spin_unlock_bh(&fps->fp_work_lock);
  889. /* Pending work request completion */
  890. if (fps->iothread && work)
  891. wake_up_process(fps->iothread);
  892. else
  893. bnx2fc_process_cq_compl(tgt, wqe);
  894. num_free_sqes++;
  895. }
  896. cqe++;
  897. tgt->cq_cons_idx++;
  898. num_cqes++;
  899. if (tgt->cq_cons_idx == BNX2FC_CQ_WQES_MAX) {
  900. tgt->cq_cons_idx = 0;
  901. cqe = cq;
  902. tgt->cq_curr_toggle_bit =
  903. 1 - tgt->cq_curr_toggle_bit;
  904. }
  905. }
  906. if (num_cqes) {
  907. /* Arm CQ only if doorbell is mapped */
  908. if (tgt->ctx_base)
  909. bnx2fc_arm_cq(tgt);
  910. atomic_add(num_free_sqes, &tgt->free_sqes);
  911. }
  912. spin_unlock_bh(&tgt->cq_lock);
  913. return 0;
  914. }
  915. /**
  916. * bnx2fc_fastpath_notification - process global event queue (KCQ)
  917. *
  918. * @hba: adapter structure pointer
  919. * @new_cqe_kcqe: pointer to newly DMA'd KCQ entry
  920. *
  921. * Fast path event notification handler
  922. */
  923. static void bnx2fc_fastpath_notification(struct bnx2fc_hba *hba,
  924. struct fcoe_kcqe *new_cqe_kcqe)
  925. {
  926. u32 conn_id = new_cqe_kcqe->fcoe_conn_id;
  927. struct bnx2fc_rport *tgt = hba->tgt_ofld_list[conn_id];
  928. if (!tgt) {
  929. printk(KERN_ERR PFX "conn_id 0x%x not valid\n", conn_id);
  930. return;
  931. }
  932. bnx2fc_process_new_cqes(tgt);
  933. }
  934. /**
  935. * bnx2fc_process_ofld_cmpl - process FCoE session offload completion
  936. *
  937. * @hba: adapter structure pointer
  938. * @ofld_kcqe: connection offload kcqe pointer
  939. *
  940. * handle session offload completion, enable the session if offload is
  941. * successful.
  942. */
  943. static void bnx2fc_process_ofld_cmpl(struct bnx2fc_hba *hba,
  944. struct fcoe_kcqe *ofld_kcqe)
  945. {
  946. struct bnx2fc_rport *tgt;
  947. struct fcoe_port *port;
  948. struct bnx2fc_interface *interface;
  949. u32 conn_id;
  950. u32 context_id;
  951. int rc;
  952. conn_id = ofld_kcqe->fcoe_conn_id;
  953. context_id = ofld_kcqe->fcoe_conn_context_id;
  954. tgt = hba->tgt_ofld_list[conn_id];
  955. if (!tgt) {
  956. printk(KERN_ALERT PFX "ERROR:ofld_cmpl: No pending ofld req\n");
  957. return;
  958. }
  959. BNX2FC_TGT_DBG(tgt, "Entered ofld compl - context_id = 0x%x\n",
  960. ofld_kcqe->fcoe_conn_context_id);
  961. port = tgt->port;
  962. interface = tgt->port->priv;
  963. if (hba != interface->hba) {
  964. printk(KERN_ERR PFX "ERROR:ofld_cmpl: HBA mis-match\n");
  965. goto ofld_cmpl_err;
  966. }
  967. /*
  968. * cnic has allocated a context_id for this session; use this
  969. * while enabling the session.
  970. */
  971. tgt->context_id = context_id;
  972. if (ofld_kcqe->completion_status) {
  973. if (ofld_kcqe->completion_status ==
  974. FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE) {
  975. printk(KERN_ERR PFX "unable to allocate FCoE context "
  976. "resources\n");
  977. set_bit(BNX2FC_FLAG_CTX_ALLOC_FAILURE, &tgt->flags);
  978. }
  979. goto ofld_cmpl_err;
  980. } else {
  981. /* now enable the session */
  982. rc = bnx2fc_send_session_enable_req(port, tgt);
  983. if (rc) {
  984. printk(KERN_ERR PFX "enable session failed\n");
  985. goto ofld_cmpl_err;
  986. }
  987. }
  988. return;
  989. ofld_cmpl_err:
  990. set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
  991. wake_up_interruptible(&tgt->ofld_wait);
  992. }
  993. /**
  994. * bnx2fc_process_enable_conn_cmpl - process FCoE session enable completion
  995. *
  996. * @hba: adapter structure pointer
  997. * @ofld_kcqe: connection offload kcqe pointer
  998. *
  999. * handle session enable completion, mark the rport as ready
  1000. */
  1001. static void bnx2fc_process_enable_conn_cmpl(struct bnx2fc_hba *hba,
  1002. struct fcoe_kcqe *ofld_kcqe)
  1003. {
  1004. struct bnx2fc_rport *tgt;
  1005. struct bnx2fc_interface *interface;
  1006. u32 conn_id;
  1007. u32 context_id;
  1008. context_id = ofld_kcqe->fcoe_conn_context_id;
  1009. conn_id = ofld_kcqe->fcoe_conn_id;
  1010. tgt = hba->tgt_ofld_list[conn_id];
  1011. if (!tgt) {
  1012. printk(KERN_ERR PFX "ERROR:enbl_cmpl: No pending ofld req\n");
  1013. return;
  1014. }
  1015. BNX2FC_TGT_DBG(tgt, "Enable compl - context_id = 0x%x\n",
  1016. ofld_kcqe->fcoe_conn_context_id);
  1017. /*
  1018. * context_id should be the same for this target during offload
  1019. * and enable
  1020. */
  1021. if (tgt->context_id != context_id) {
  1022. printk(KERN_ERR PFX "context id mis-match\n");
  1023. return;
  1024. }
  1025. interface = tgt->port->priv;
  1026. if (hba != interface->hba) {
  1027. printk(KERN_ERR PFX "bnx2fc-enbl_cmpl: HBA mis-match\n");
  1028. goto enbl_cmpl_err;
  1029. }
  1030. if (ofld_kcqe->completion_status)
  1031. goto enbl_cmpl_err;
  1032. else {
  1033. /* enable successful - rport ready for issuing IOs */
  1034. set_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
  1035. set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
  1036. wake_up_interruptible(&tgt->ofld_wait);
  1037. }
  1038. return;
  1039. enbl_cmpl_err:
  1040. set_bit(BNX2FC_FLAG_OFLD_REQ_CMPL, &tgt->flags);
  1041. wake_up_interruptible(&tgt->ofld_wait);
  1042. }
  1043. static void bnx2fc_process_conn_disable_cmpl(struct bnx2fc_hba *hba,
  1044. struct fcoe_kcqe *disable_kcqe)
  1045. {
  1046. struct bnx2fc_rport *tgt;
  1047. u32 conn_id;
  1048. conn_id = disable_kcqe->fcoe_conn_id;
  1049. tgt = hba->tgt_ofld_list[conn_id];
  1050. if (!tgt) {
  1051. printk(KERN_ERR PFX "ERROR: disable_cmpl: No disable req\n");
  1052. return;
  1053. }
  1054. BNX2FC_TGT_DBG(tgt, PFX "disable_cmpl: conn_id %d\n", conn_id);
  1055. if (disable_kcqe->completion_status) {
  1056. printk(KERN_ERR PFX "Disable failed with cmpl status %d\n",
  1057. disable_kcqe->completion_status);
  1058. return;
  1059. } else {
  1060. /* disable successful */
  1061. BNX2FC_TGT_DBG(tgt, "disable successful\n");
  1062. clear_bit(BNX2FC_FLAG_OFFLOADED, &tgt->flags);
  1063. set_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
  1064. set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
  1065. wake_up_interruptible(&tgt->upld_wait);
  1066. }
  1067. }
  1068. static void bnx2fc_process_conn_destroy_cmpl(struct bnx2fc_hba *hba,
  1069. struct fcoe_kcqe *destroy_kcqe)
  1070. {
  1071. struct bnx2fc_rport *tgt;
  1072. u32 conn_id;
  1073. conn_id = destroy_kcqe->fcoe_conn_id;
  1074. tgt = hba->tgt_ofld_list[conn_id];
  1075. if (!tgt) {
  1076. printk(KERN_ERR PFX "destroy_cmpl: No destroy req\n");
  1077. return;
  1078. }
  1079. BNX2FC_TGT_DBG(tgt, "destroy_cmpl: conn_id %d\n", conn_id);
  1080. if (destroy_kcqe->completion_status) {
  1081. printk(KERN_ERR PFX "Destroy conn failed, cmpl status %d\n",
  1082. destroy_kcqe->completion_status);
  1083. return;
  1084. } else {
  1085. /* destroy successful */
  1086. BNX2FC_TGT_DBG(tgt, "upload successful\n");
  1087. clear_bit(BNX2FC_FLAG_DISABLED, &tgt->flags);
  1088. set_bit(BNX2FC_FLAG_DESTROYED, &tgt->flags);
  1089. set_bit(BNX2FC_FLAG_UPLD_REQ_COMPL, &tgt->flags);
  1090. wake_up_interruptible(&tgt->upld_wait);
  1091. }
  1092. }
  1093. static void bnx2fc_init_failure(struct bnx2fc_hba *hba, u32 err_code)
  1094. {
  1095. switch (err_code) {
  1096. case FCOE_KCQE_COMPLETION_STATUS_INVALID_OPCODE:
  1097. printk(KERN_ERR PFX "init_failure due to invalid opcode\n");
  1098. break;
  1099. case FCOE_KCQE_COMPLETION_STATUS_CTX_ALLOC_FAILURE:
  1100. printk(KERN_ERR PFX "init failed due to ctx alloc failure\n");
  1101. break;
  1102. case FCOE_KCQE_COMPLETION_STATUS_NIC_ERROR:
  1103. printk(KERN_ERR PFX "init_failure due to NIC error\n");
  1104. break;
  1105. case FCOE_KCQE_COMPLETION_STATUS_ERROR:
  1106. printk(KERN_ERR PFX "init failure due to compl status err\n");
  1107. break;
  1108. case FCOE_KCQE_COMPLETION_STATUS_WRONG_HSI_VERSION:
  1109. printk(KERN_ERR PFX "init failure due to HSI mismatch\n");
  1110. break;
  1111. default:
  1112. printk(KERN_ERR PFX "Unknown Error code %d\n", err_code);
  1113. }
  1114. }
  1115. /**
  1116. * bnx2fc_indicae_kcqe - process KCQE
  1117. *
  1118. * @hba: adapter structure pointer
  1119. * @kcqe: kcqe pointer
  1120. * @num_cqe: Number of completion queue elements
  1121. *
  1122. * Generic KCQ event handler
  1123. */
  1124. void bnx2fc_indicate_kcqe(void *context, struct kcqe *kcq[],
  1125. u32 num_cqe)
  1126. {
  1127. struct bnx2fc_hba *hba = (struct bnx2fc_hba *)context;
  1128. int i = 0;
  1129. struct fcoe_kcqe *kcqe = NULL;
  1130. while (i < num_cqe) {
  1131. kcqe = (struct fcoe_kcqe *) kcq[i++];
  1132. switch (kcqe->op_code) {
  1133. case FCOE_KCQE_OPCODE_CQ_EVENT_NOTIFICATION:
  1134. bnx2fc_fastpath_notification(hba, kcqe);
  1135. break;
  1136. case FCOE_KCQE_OPCODE_OFFLOAD_CONN:
  1137. bnx2fc_process_ofld_cmpl(hba, kcqe);
  1138. break;
  1139. case FCOE_KCQE_OPCODE_ENABLE_CONN:
  1140. bnx2fc_process_enable_conn_cmpl(hba, kcqe);
  1141. break;
  1142. case FCOE_KCQE_OPCODE_INIT_FUNC:
  1143. if (kcqe->completion_status !=
  1144. FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
  1145. bnx2fc_init_failure(hba,
  1146. kcqe->completion_status);
  1147. } else {
  1148. set_bit(ADAPTER_STATE_UP, &hba->adapter_state);
  1149. bnx2fc_get_link_state(hba);
  1150. printk(KERN_INFO PFX "[%.2x]: FCOE_INIT passed\n",
  1151. (u8)hba->pcidev->bus->number);
  1152. }
  1153. break;
  1154. case FCOE_KCQE_OPCODE_DESTROY_FUNC:
  1155. if (kcqe->completion_status !=
  1156. FCOE_KCQE_COMPLETION_STATUS_SUCCESS) {
  1157. printk(KERN_ERR PFX "DESTROY failed\n");
  1158. } else {
  1159. printk(KERN_ERR PFX "DESTROY success\n");
  1160. }
  1161. set_bit(BNX2FC_FLAG_DESTROY_CMPL, &hba->flags);
  1162. wake_up_interruptible(&hba->destroy_wait);
  1163. break;
  1164. case FCOE_KCQE_OPCODE_DISABLE_CONN:
  1165. bnx2fc_process_conn_disable_cmpl(hba, kcqe);
  1166. break;
  1167. case FCOE_KCQE_OPCODE_DESTROY_CONN:
  1168. bnx2fc_process_conn_destroy_cmpl(hba, kcqe);
  1169. break;
  1170. case FCOE_KCQE_OPCODE_STAT_FUNC:
  1171. if (kcqe->completion_status !=
  1172. FCOE_KCQE_COMPLETION_STATUS_SUCCESS)
  1173. printk(KERN_ERR PFX "STAT failed\n");
  1174. complete(&hba->stat_req_done);
  1175. break;
  1176. case FCOE_KCQE_OPCODE_FCOE_ERROR:
  1177. /* fall thru */
  1178. default:
  1179. printk(KERN_ERR PFX "unknown opcode 0x%x\n",
  1180. kcqe->op_code);
  1181. }
  1182. }
  1183. }
  1184. void bnx2fc_add_2_sq(struct bnx2fc_rport *tgt, u16 xid)
  1185. {
  1186. struct fcoe_sqe *sqe;
  1187. sqe = &tgt->sq[tgt->sq_prod_idx];
  1188. /* Fill SQ WQE */
  1189. sqe->wqe = xid << FCOE_SQE_TASK_ID_SHIFT;
  1190. sqe->wqe |= tgt->sq_curr_toggle_bit << FCOE_SQE_TOGGLE_BIT_SHIFT;
  1191. /* Advance SQ Prod Idx */
  1192. if (++tgt->sq_prod_idx == BNX2FC_SQ_WQES_MAX) {
  1193. tgt->sq_prod_idx = 0;
  1194. tgt->sq_curr_toggle_bit = 1 - tgt->sq_curr_toggle_bit;
  1195. }
  1196. }
  1197. void bnx2fc_ring_doorbell(struct bnx2fc_rport *tgt)
  1198. {
  1199. struct b577xx_doorbell_set_prod *sq_db = &tgt->sq_db;
  1200. u32 msg;
  1201. wmb();
  1202. sq_db->prod = tgt->sq_prod_idx |
  1203. (tgt->sq_curr_toggle_bit << 15);
  1204. msg = *((u32 *)sq_db);
  1205. writel(cpu_to_le32(msg), tgt->ctx_base);
  1206. mmiowb();
  1207. }
  1208. int bnx2fc_map_doorbell(struct bnx2fc_rport *tgt)
  1209. {
  1210. u32 context_id = tgt->context_id;
  1211. struct fcoe_port *port = tgt->port;
  1212. u32 reg_off;
  1213. resource_size_t reg_base;
  1214. struct bnx2fc_interface *interface = port->priv;
  1215. struct bnx2fc_hba *hba = interface->hba;
  1216. reg_base = pci_resource_start(hba->pcidev,
  1217. BNX2X_DOORBELL_PCI_BAR);
  1218. reg_off = BNX2FC_5771X_DB_PAGE_SIZE *
  1219. (context_id & 0x1FFFF) + DPM_TRIGER_TYPE;
  1220. tgt->ctx_base = ioremap_nocache(reg_base + reg_off, 4);
  1221. if (!tgt->ctx_base)
  1222. return -ENOMEM;
  1223. return 0;
  1224. }
  1225. char *bnx2fc_get_next_rqe(struct bnx2fc_rport *tgt, u8 num_items)
  1226. {
  1227. char *buf = (char *)tgt->rq + (tgt->rq_cons_idx * BNX2FC_RQ_BUF_SZ);
  1228. if (tgt->rq_cons_idx + num_items > BNX2FC_RQ_WQES_MAX)
  1229. return NULL;
  1230. tgt->rq_cons_idx += num_items;
  1231. if (tgt->rq_cons_idx >= BNX2FC_RQ_WQES_MAX)
  1232. tgt->rq_cons_idx -= BNX2FC_RQ_WQES_MAX;
  1233. return buf;
  1234. }
  1235. void bnx2fc_return_rqe(struct bnx2fc_rport *tgt, u8 num_items)
  1236. {
  1237. /* return the rq buffer */
  1238. u32 next_prod_idx = tgt->rq_prod_idx + num_items;
  1239. if ((next_prod_idx & 0x7fff) == BNX2FC_RQ_WQES_MAX) {
  1240. /* Wrap around RQ */
  1241. next_prod_idx += 0x8000 - BNX2FC_RQ_WQES_MAX;
  1242. }
  1243. tgt->rq_prod_idx = next_prod_idx;
  1244. tgt->conn_db->rq_prod = tgt->rq_prod_idx;
  1245. }
  1246. void bnx2fc_init_seq_cleanup_task(struct bnx2fc_cmd *seq_clnp_req,
  1247. struct fcoe_task_ctx_entry *task,
  1248. struct bnx2fc_cmd *orig_io_req,
  1249. u32 offset)
  1250. {
  1251. struct scsi_cmnd *sc_cmd = orig_io_req->sc_cmd;
  1252. struct bnx2fc_rport *tgt = seq_clnp_req->tgt;
  1253. struct bnx2fc_interface *interface = tgt->port->priv;
  1254. struct fcoe_bd_ctx *bd = orig_io_req->bd_tbl->bd_tbl;
  1255. struct fcoe_task_ctx_entry *orig_task;
  1256. struct fcoe_task_ctx_entry *task_page;
  1257. struct fcoe_ext_mul_sges_ctx *sgl;
  1258. u8 task_type = FCOE_TASK_TYPE_SEQUENCE_CLEANUP;
  1259. u8 orig_task_type;
  1260. u16 orig_xid = orig_io_req->xid;
  1261. u32 context_id = tgt->context_id;
  1262. u64 phys_addr = (u64)orig_io_req->bd_tbl->bd_tbl_dma;
  1263. u32 orig_offset = offset;
  1264. int bd_count;
  1265. int orig_task_idx, index;
  1266. int i;
  1267. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1268. if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
  1269. orig_task_type = FCOE_TASK_TYPE_WRITE;
  1270. else
  1271. orig_task_type = FCOE_TASK_TYPE_READ;
  1272. /* Tx flags */
  1273. task->txwr_rxrd.const_ctx.tx_flags =
  1274. FCOE_TASK_TX_STATE_SEQUENCE_CLEANUP <<
  1275. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1276. /* init flags */
  1277. task->txwr_rxrd.const_ctx.init_flags = task_type <<
  1278. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1279. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1280. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1281. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1282. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1283. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1284. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1285. task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
  1286. task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_seq_cnt = 0;
  1287. task->txwr_rxrd.union_ctx.cleanup.ctx.rolled_tx_data_offset = offset;
  1288. bd_count = orig_io_req->bd_tbl->bd_valid;
  1289. /* obtain the appropriate bd entry from relative offset */
  1290. for (i = 0; i < bd_count; i++) {
  1291. if (offset < bd[i].buf_len)
  1292. break;
  1293. offset -= bd[i].buf_len;
  1294. }
  1295. phys_addr += (i * sizeof(struct fcoe_bd_ctx));
  1296. if (orig_task_type == FCOE_TASK_TYPE_WRITE) {
  1297. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
  1298. (u32)phys_addr;
  1299. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
  1300. (u32)((u64)phys_addr >> 32);
  1301. task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
  1302. bd_count;
  1303. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_off =
  1304. offset; /* adjusted offset */
  1305. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_idx = i;
  1306. } else {
  1307. orig_task_idx = orig_xid / BNX2FC_TASKS_PER_PAGE;
  1308. index = orig_xid % BNX2FC_TASKS_PER_PAGE;
  1309. task_page = (struct fcoe_task_ctx_entry *)
  1310. interface->hba->task_ctx[orig_task_idx];
  1311. orig_task = &(task_page[index]);
  1312. /* Multiple SGEs were used for this IO */
  1313. sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
  1314. sgl->mul_sgl.cur_sge_addr.lo = (u32)phys_addr;
  1315. sgl->mul_sgl.cur_sge_addr.hi = (u32)((u64)phys_addr >> 32);
  1316. sgl->mul_sgl.sgl_size = bd_count;
  1317. sgl->mul_sgl.cur_sge_off = offset; /*adjusted offset */
  1318. sgl->mul_sgl.cur_sge_idx = i;
  1319. memset(&task->rxwr_only.rx_seq_ctx, 0,
  1320. sizeof(struct fcoe_rx_seq_ctx));
  1321. task->rxwr_only.rx_seq_ctx.low_exp_ro = orig_offset;
  1322. task->rxwr_only.rx_seq_ctx.high_exp_ro = orig_offset;
  1323. }
  1324. }
  1325. void bnx2fc_init_cleanup_task(struct bnx2fc_cmd *io_req,
  1326. struct fcoe_task_ctx_entry *task,
  1327. u16 orig_xid)
  1328. {
  1329. u8 task_type = FCOE_TASK_TYPE_EXCHANGE_CLEANUP;
  1330. struct bnx2fc_rport *tgt = io_req->tgt;
  1331. u32 context_id = tgt->context_id;
  1332. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1333. /* Tx Write Rx Read */
  1334. /* init flags */
  1335. task->txwr_rxrd.const_ctx.init_flags = task_type <<
  1336. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1337. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1338. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1339. if (tgt->dev_type == TYPE_TAPE)
  1340. task->txwr_rxrd.const_ctx.init_flags |=
  1341. FCOE_TASK_DEV_TYPE_TAPE <<
  1342. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1343. else
  1344. task->txwr_rxrd.const_ctx.init_flags |=
  1345. FCOE_TASK_DEV_TYPE_DISK <<
  1346. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1347. task->txwr_rxrd.union_ctx.cleanup.ctx.cleaned_task_id = orig_xid;
  1348. /* Tx flags */
  1349. task->txwr_rxrd.const_ctx.tx_flags =
  1350. FCOE_TASK_TX_STATE_EXCHANGE_CLEANUP <<
  1351. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1352. /* Rx Read Tx Write */
  1353. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1354. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1355. task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
  1356. FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
  1357. }
  1358. void bnx2fc_init_mp_task(struct bnx2fc_cmd *io_req,
  1359. struct fcoe_task_ctx_entry *task)
  1360. {
  1361. struct bnx2fc_mp_req *mp_req = &(io_req->mp_req);
  1362. struct bnx2fc_rport *tgt = io_req->tgt;
  1363. struct fc_frame_header *fc_hdr;
  1364. struct fcoe_ext_mul_sges_ctx *sgl;
  1365. u8 task_type = 0;
  1366. u64 *hdr;
  1367. u64 temp_hdr[3];
  1368. u32 context_id;
  1369. /* Obtain task_type */
  1370. if ((io_req->cmd_type == BNX2FC_TASK_MGMT_CMD) ||
  1371. (io_req->cmd_type == BNX2FC_ELS)) {
  1372. task_type = FCOE_TASK_TYPE_MIDPATH;
  1373. } else if (io_req->cmd_type == BNX2FC_ABTS) {
  1374. task_type = FCOE_TASK_TYPE_ABTS;
  1375. }
  1376. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1377. /* Setup the task from io_req for easy reference */
  1378. io_req->task = task;
  1379. BNX2FC_IO_DBG(io_req, "Init MP task for cmd_type = %d task_type = %d\n",
  1380. io_req->cmd_type, task_type);
  1381. /* Tx only */
  1382. if ((task_type == FCOE_TASK_TYPE_MIDPATH) ||
  1383. (task_type == FCOE_TASK_TYPE_UNSOLICITED)) {
  1384. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
  1385. (u32)mp_req->mp_req_bd_dma;
  1386. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
  1387. (u32)((u64)mp_req->mp_req_bd_dma >> 32);
  1388. task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size = 1;
  1389. }
  1390. /* Tx Write Rx Read */
  1391. /* init flags */
  1392. task->txwr_rxrd.const_ctx.init_flags = task_type <<
  1393. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1394. if (tgt->dev_type == TYPE_TAPE)
  1395. task->txwr_rxrd.const_ctx.init_flags |=
  1396. FCOE_TASK_DEV_TYPE_TAPE <<
  1397. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1398. else
  1399. task->txwr_rxrd.const_ctx.init_flags |=
  1400. FCOE_TASK_DEV_TYPE_DISK <<
  1401. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1402. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1403. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1404. /* tx flags */
  1405. task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_INIT <<
  1406. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1407. /* Rx Write Tx Read */
  1408. task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
  1409. /* rx flags */
  1410. task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
  1411. FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
  1412. context_id = tgt->context_id;
  1413. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1414. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1415. fc_hdr = &(mp_req->req_fc_hdr);
  1416. if (task_type == FCOE_TASK_TYPE_MIDPATH) {
  1417. fc_hdr->fh_ox_id = cpu_to_be16(io_req->xid);
  1418. fc_hdr->fh_rx_id = htons(0xffff);
  1419. task->rxwr_txrd.var_ctx.rx_id = 0xffff;
  1420. } else if (task_type == FCOE_TASK_TYPE_UNSOLICITED) {
  1421. fc_hdr->fh_rx_id = cpu_to_be16(io_req->xid);
  1422. }
  1423. /* Fill FC Header into middle path buffer */
  1424. hdr = (u64 *) &task->txwr_rxrd.union_ctx.tx_frame.fc_hdr;
  1425. memcpy(temp_hdr, fc_hdr, sizeof(temp_hdr));
  1426. hdr[0] = cpu_to_be64(temp_hdr[0]);
  1427. hdr[1] = cpu_to_be64(temp_hdr[1]);
  1428. hdr[2] = cpu_to_be64(temp_hdr[2]);
  1429. /* Rx Only */
  1430. if (task_type == FCOE_TASK_TYPE_MIDPATH) {
  1431. sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
  1432. sgl->mul_sgl.cur_sge_addr.lo = (u32)mp_req->mp_resp_bd_dma;
  1433. sgl->mul_sgl.cur_sge_addr.hi =
  1434. (u32)((u64)mp_req->mp_resp_bd_dma >> 32);
  1435. sgl->mul_sgl.sgl_size = 1;
  1436. }
  1437. }
  1438. void bnx2fc_init_task(struct bnx2fc_cmd *io_req,
  1439. struct fcoe_task_ctx_entry *task)
  1440. {
  1441. u8 task_type;
  1442. struct scsi_cmnd *sc_cmd = io_req->sc_cmd;
  1443. struct io_bdt *bd_tbl = io_req->bd_tbl;
  1444. struct bnx2fc_rport *tgt = io_req->tgt;
  1445. struct fcoe_cached_sge_ctx *cached_sge;
  1446. struct fcoe_ext_mul_sges_ctx *sgl;
  1447. int dev_type = tgt->dev_type;
  1448. u64 *fcp_cmnd;
  1449. u64 tmp_fcp_cmnd[4];
  1450. u32 context_id;
  1451. int cnt, i;
  1452. int bd_count;
  1453. memset(task, 0, sizeof(struct fcoe_task_ctx_entry));
  1454. /* Setup the task from io_req for easy reference */
  1455. io_req->task = task;
  1456. if (sc_cmd->sc_data_direction == DMA_TO_DEVICE)
  1457. task_type = FCOE_TASK_TYPE_WRITE;
  1458. else
  1459. task_type = FCOE_TASK_TYPE_READ;
  1460. /* Tx only */
  1461. bd_count = bd_tbl->bd_valid;
  1462. cached_sge = &task->rxwr_only.union_ctx.read_info.sgl_ctx.cached_sge;
  1463. if (task_type == FCOE_TASK_TYPE_WRITE) {
  1464. if ((dev_type == TYPE_DISK) && (bd_count == 1)) {
  1465. struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
  1466. task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.lo =
  1467. cached_sge->cur_buf_addr.lo =
  1468. fcoe_bd_tbl->buf_addr_lo;
  1469. task->txwr_only.sgl_ctx.cached_sge.cur_buf_addr.hi =
  1470. cached_sge->cur_buf_addr.hi =
  1471. fcoe_bd_tbl->buf_addr_hi;
  1472. task->txwr_only.sgl_ctx.cached_sge.cur_buf_rem =
  1473. cached_sge->cur_buf_rem =
  1474. fcoe_bd_tbl->buf_len;
  1475. task->txwr_rxrd.const_ctx.init_flags |= 1 <<
  1476. FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
  1477. } else {
  1478. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.lo =
  1479. (u32)bd_tbl->bd_tbl_dma;
  1480. task->txwr_only.sgl_ctx.sgl.mul_sgl.cur_sge_addr.hi =
  1481. (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
  1482. task->txwr_only.sgl_ctx.sgl.mul_sgl.sgl_size =
  1483. bd_tbl->bd_valid;
  1484. }
  1485. }
  1486. /*Tx Write Rx Read */
  1487. /* Init state to NORMAL */
  1488. task->txwr_rxrd.const_ctx.init_flags |= task_type <<
  1489. FCOE_TCE_TX_WR_RX_RD_CONST_TASK_TYPE_SHIFT;
  1490. if (dev_type == TYPE_TAPE) {
  1491. task->txwr_rxrd.const_ctx.init_flags |=
  1492. FCOE_TASK_DEV_TYPE_TAPE <<
  1493. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1494. io_req->rec_retry = 0;
  1495. io_req->rec_retry = 0;
  1496. } else
  1497. task->txwr_rxrd.const_ctx.init_flags |=
  1498. FCOE_TASK_DEV_TYPE_DISK <<
  1499. FCOE_TCE_TX_WR_RX_RD_CONST_DEV_TYPE_SHIFT;
  1500. task->txwr_rxrd.const_ctx.init_flags |= FCOE_TASK_CLASS_TYPE_3 <<
  1501. FCOE_TCE_TX_WR_RX_RD_CONST_CLASS_TYPE_SHIFT;
  1502. /* tx flags */
  1503. task->txwr_rxrd.const_ctx.tx_flags = FCOE_TASK_TX_STATE_NORMAL <<
  1504. FCOE_TCE_TX_WR_RX_RD_CONST_TX_STATE_SHIFT;
  1505. /* Set initial seq counter */
  1506. task->txwr_rxrd.union_ctx.tx_seq.ctx.seq_cnt = 1;
  1507. /* Fill FCP_CMND IU */
  1508. fcp_cmnd = (u64 *)
  1509. task->txwr_rxrd.union_ctx.fcp_cmd.opaque;
  1510. bnx2fc_build_fcp_cmnd(io_req, (struct fcp_cmnd *)&tmp_fcp_cmnd);
  1511. /* swap fcp_cmnd */
  1512. cnt = sizeof(struct fcp_cmnd) / sizeof(u64);
  1513. for (i = 0; i < cnt; i++) {
  1514. *fcp_cmnd = cpu_to_be64(tmp_fcp_cmnd[i]);
  1515. fcp_cmnd++;
  1516. }
  1517. /* Rx Write Tx Read */
  1518. task->rxwr_txrd.const_ctx.data_2_trns = io_req->data_xfer_len;
  1519. context_id = tgt->context_id;
  1520. task->rxwr_txrd.const_ctx.init_flags = context_id <<
  1521. FCOE_TCE_RX_WR_TX_RD_CONST_CID_SHIFT;
  1522. /* rx flags */
  1523. /* Set state to "waiting for the first packet" */
  1524. task->rxwr_txrd.var_ctx.rx_flags |= 1 <<
  1525. FCOE_TCE_RX_WR_TX_RD_VAR_EXP_FIRST_FRAME_SHIFT;
  1526. task->rxwr_txrd.var_ctx.rx_id = 0xffff;
  1527. /* Rx Only */
  1528. if (task_type != FCOE_TASK_TYPE_READ)
  1529. return;
  1530. sgl = &task->rxwr_only.union_ctx.read_info.sgl_ctx.sgl;
  1531. bd_count = bd_tbl->bd_valid;
  1532. if (dev_type == TYPE_DISK) {
  1533. if (bd_count == 1) {
  1534. struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
  1535. cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
  1536. cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
  1537. cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
  1538. task->txwr_rxrd.const_ctx.init_flags |= 1 <<
  1539. FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
  1540. } else if (bd_count == 2) {
  1541. struct fcoe_bd_ctx *fcoe_bd_tbl = bd_tbl->bd_tbl;
  1542. cached_sge->cur_buf_addr.lo = fcoe_bd_tbl->buf_addr_lo;
  1543. cached_sge->cur_buf_addr.hi = fcoe_bd_tbl->buf_addr_hi;
  1544. cached_sge->cur_buf_rem = fcoe_bd_tbl->buf_len;
  1545. fcoe_bd_tbl++;
  1546. cached_sge->second_buf_addr.lo =
  1547. fcoe_bd_tbl->buf_addr_lo;
  1548. cached_sge->second_buf_addr.hi =
  1549. fcoe_bd_tbl->buf_addr_hi;
  1550. cached_sge->second_buf_rem = fcoe_bd_tbl->buf_len;
  1551. task->txwr_rxrd.const_ctx.init_flags |= 1 <<
  1552. FCOE_TCE_TX_WR_RX_RD_CONST_CACHED_SGE_SHIFT;
  1553. } else {
  1554. sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
  1555. sgl->mul_sgl.cur_sge_addr.hi =
  1556. (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
  1557. sgl->mul_sgl.sgl_size = bd_count;
  1558. }
  1559. } else {
  1560. sgl->mul_sgl.cur_sge_addr.lo = (u32)bd_tbl->bd_tbl_dma;
  1561. sgl->mul_sgl.cur_sge_addr.hi =
  1562. (u32)((u64)bd_tbl->bd_tbl_dma >> 32);
  1563. sgl->mul_sgl.sgl_size = bd_count;
  1564. }
  1565. }
  1566. /**
  1567. * bnx2fc_setup_task_ctx - allocate and map task context
  1568. *
  1569. * @hba: pointer to adapter structure
  1570. *
  1571. * allocate memory for task context, and associated BD table to be used
  1572. * by firmware
  1573. *
  1574. */
  1575. int bnx2fc_setup_task_ctx(struct bnx2fc_hba *hba)
  1576. {
  1577. int rc = 0;
  1578. struct regpair *task_ctx_bdt;
  1579. dma_addr_t addr;
  1580. int i;
  1581. /*
  1582. * Allocate task context bd table. A page size of bd table
  1583. * can map 256 buffers. Each buffer contains 32 task context
  1584. * entries. Hence the limit with one page is 8192 task context
  1585. * entries.
  1586. */
  1587. hba->task_ctx_bd_tbl = dma_alloc_coherent(&hba->pcidev->dev,
  1588. PAGE_SIZE,
  1589. &hba->task_ctx_bd_dma,
  1590. GFP_KERNEL);
  1591. if (!hba->task_ctx_bd_tbl) {
  1592. printk(KERN_ERR PFX "unable to allocate task context BDT\n");
  1593. rc = -1;
  1594. goto out;
  1595. }
  1596. memset(hba->task_ctx_bd_tbl, 0, PAGE_SIZE);
  1597. /*
  1598. * Allocate task_ctx which is an array of pointers pointing to
  1599. * a page containing 32 task contexts
  1600. */
  1601. hba->task_ctx = kzalloc((BNX2FC_TASK_CTX_ARR_SZ * sizeof(void *)),
  1602. GFP_KERNEL);
  1603. if (!hba->task_ctx) {
  1604. printk(KERN_ERR PFX "unable to allocate task context array\n");
  1605. rc = -1;
  1606. goto out1;
  1607. }
  1608. /*
  1609. * Allocate task_ctx_dma which is an array of dma addresses
  1610. */
  1611. hba->task_ctx_dma = kmalloc((BNX2FC_TASK_CTX_ARR_SZ *
  1612. sizeof(dma_addr_t)), GFP_KERNEL);
  1613. if (!hba->task_ctx_dma) {
  1614. printk(KERN_ERR PFX "unable to alloc context mapping array\n");
  1615. rc = -1;
  1616. goto out2;
  1617. }
  1618. task_ctx_bdt = (struct regpair *)hba->task_ctx_bd_tbl;
  1619. for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
  1620. hba->task_ctx[i] = dma_alloc_coherent(&hba->pcidev->dev,
  1621. PAGE_SIZE,
  1622. &hba->task_ctx_dma[i],
  1623. GFP_KERNEL);
  1624. if (!hba->task_ctx[i]) {
  1625. printk(KERN_ERR PFX "unable to alloc task context\n");
  1626. rc = -1;
  1627. goto out3;
  1628. }
  1629. memset(hba->task_ctx[i], 0, PAGE_SIZE);
  1630. addr = (u64)hba->task_ctx_dma[i];
  1631. task_ctx_bdt->hi = cpu_to_le32((u64)addr >> 32);
  1632. task_ctx_bdt->lo = cpu_to_le32((u32)addr);
  1633. task_ctx_bdt++;
  1634. }
  1635. return 0;
  1636. out3:
  1637. for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
  1638. if (hba->task_ctx[i]) {
  1639. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1640. hba->task_ctx[i], hba->task_ctx_dma[i]);
  1641. hba->task_ctx[i] = NULL;
  1642. }
  1643. }
  1644. kfree(hba->task_ctx_dma);
  1645. hba->task_ctx_dma = NULL;
  1646. out2:
  1647. kfree(hba->task_ctx);
  1648. hba->task_ctx = NULL;
  1649. out1:
  1650. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1651. hba->task_ctx_bd_tbl, hba->task_ctx_bd_dma);
  1652. hba->task_ctx_bd_tbl = NULL;
  1653. out:
  1654. return rc;
  1655. }
  1656. void bnx2fc_free_task_ctx(struct bnx2fc_hba *hba)
  1657. {
  1658. int i;
  1659. if (hba->task_ctx_bd_tbl) {
  1660. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1661. hba->task_ctx_bd_tbl,
  1662. hba->task_ctx_bd_dma);
  1663. hba->task_ctx_bd_tbl = NULL;
  1664. }
  1665. if (hba->task_ctx) {
  1666. for (i = 0; i < BNX2FC_TASK_CTX_ARR_SZ; i++) {
  1667. if (hba->task_ctx[i]) {
  1668. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1669. hba->task_ctx[i],
  1670. hba->task_ctx_dma[i]);
  1671. hba->task_ctx[i] = NULL;
  1672. }
  1673. }
  1674. kfree(hba->task_ctx);
  1675. hba->task_ctx = NULL;
  1676. }
  1677. kfree(hba->task_ctx_dma);
  1678. hba->task_ctx_dma = NULL;
  1679. }
  1680. static void bnx2fc_free_hash_table(struct bnx2fc_hba *hba)
  1681. {
  1682. int i;
  1683. int segment_count;
  1684. int hash_table_size;
  1685. u32 *pbl;
  1686. segment_count = hba->hash_tbl_segment_count;
  1687. hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
  1688. sizeof(struct fcoe_hash_table_entry);
  1689. pbl = hba->hash_tbl_pbl;
  1690. for (i = 0; i < segment_count; ++i) {
  1691. dma_addr_t dma_address;
  1692. dma_address = le32_to_cpu(*pbl);
  1693. ++pbl;
  1694. dma_address += ((u64)le32_to_cpu(*pbl)) << 32;
  1695. ++pbl;
  1696. dma_free_coherent(&hba->pcidev->dev,
  1697. BNX2FC_HASH_TBL_CHUNK_SIZE,
  1698. hba->hash_tbl_segments[i],
  1699. dma_address);
  1700. }
  1701. if (hba->hash_tbl_pbl) {
  1702. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1703. hba->hash_tbl_pbl,
  1704. hba->hash_tbl_pbl_dma);
  1705. hba->hash_tbl_pbl = NULL;
  1706. }
  1707. }
  1708. static int bnx2fc_allocate_hash_table(struct bnx2fc_hba *hba)
  1709. {
  1710. int i;
  1711. int hash_table_size;
  1712. int segment_count;
  1713. int segment_array_size;
  1714. int dma_segment_array_size;
  1715. dma_addr_t *dma_segment_array;
  1716. u32 *pbl;
  1717. hash_table_size = BNX2FC_NUM_MAX_SESS * BNX2FC_MAX_ROWS_IN_HASH_TBL *
  1718. sizeof(struct fcoe_hash_table_entry);
  1719. segment_count = hash_table_size + BNX2FC_HASH_TBL_CHUNK_SIZE - 1;
  1720. segment_count /= BNX2FC_HASH_TBL_CHUNK_SIZE;
  1721. hba->hash_tbl_segment_count = segment_count;
  1722. segment_array_size = segment_count * sizeof(*hba->hash_tbl_segments);
  1723. hba->hash_tbl_segments = kzalloc(segment_array_size, GFP_KERNEL);
  1724. if (!hba->hash_tbl_segments) {
  1725. printk(KERN_ERR PFX "hash table pointers alloc failed\n");
  1726. return -ENOMEM;
  1727. }
  1728. dma_segment_array_size = segment_count * sizeof(*dma_segment_array);
  1729. dma_segment_array = kzalloc(dma_segment_array_size, GFP_KERNEL);
  1730. if (!dma_segment_array) {
  1731. printk(KERN_ERR PFX "hash table pointers (dma) alloc failed\n");
  1732. return -ENOMEM;
  1733. }
  1734. for (i = 0; i < segment_count; ++i) {
  1735. hba->hash_tbl_segments[i] =
  1736. dma_alloc_coherent(&hba->pcidev->dev,
  1737. BNX2FC_HASH_TBL_CHUNK_SIZE,
  1738. &dma_segment_array[i],
  1739. GFP_KERNEL);
  1740. if (!hba->hash_tbl_segments[i]) {
  1741. printk(KERN_ERR PFX "hash segment alloc failed\n");
  1742. while (--i >= 0) {
  1743. dma_free_coherent(&hba->pcidev->dev,
  1744. BNX2FC_HASH_TBL_CHUNK_SIZE,
  1745. hba->hash_tbl_segments[i],
  1746. dma_segment_array[i]);
  1747. hba->hash_tbl_segments[i] = NULL;
  1748. }
  1749. kfree(dma_segment_array);
  1750. return -ENOMEM;
  1751. }
  1752. memset(hba->hash_tbl_segments[i], 0,
  1753. BNX2FC_HASH_TBL_CHUNK_SIZE);
  1754. }
  1755. hba->hash_tbl_pbl = dma_alloc_coherent(&hba->pcidev->dev,
  1756. PAGE_SIZE,
  1757. &hba->hash_tbl_pbl_dma,
  1758. GFP_KERNEL);
  1759. if (!hba->hash_tbl_pbl) {
  1760. printk(KERN_ERR PFX "hash table pbl alloc failed\n");
  1761. kfree(dma_segment_array);
  1762. return -ENOMEM;
  1763. }
  1764. memset(hba->hash_tbl_pbl, 0, PAGE_SIZE);
  1765. pbl = hba->hash_tbl_pbl;
  1766. for (i = 0; i < segment_count; ++i) {
  1767. u64 paddr = dma_segment_array[i];
  1768. *pbl = cpu_to_le32((u32) paddr);
  1769. ++pbl;
  1770. *pbl = cpu_to_le32((u32) (paddr >> 32));
  1771. ++pbl;
  1772. }
  1773. pbl = hba->hash_tbl_pbl;
  1774. i = 0;
  1775. while (*pbl && *(pbl + 1)) {
  1776. u32 lo;
  1777. u32 hi;
  1778. lo = *pbl;
  1779. ++pbl;
  1780. hi = *pbl;
  1781. ++pbl;
  1782. ++i;
  1783. }
  1784. kfree(dma_segment_array);
  1785. return 0;
  1786. }
  1787. /**
  1788. * bnx2fc_setup_fw_resc - Allocate and map hash table and dummy buffer
  1789. *
  1790. * @hba: Pointer to adapter structure
  1791. *
  1792. */
  1793. int bnx2fc_setup_fw_resc(struct bnx2fc_hba *hba)
  1794. {
  1795. u64 addr;
  1796. u32 mem_size;
  1797. int i;
  1798. if (bnx2fc_allocate_hash_table(hba))
  1799. return -ENOMEM;
  1800. mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
  1801. hba->t2_hash_tbl_ptr = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
  1802. &hba->t2_hash_tbl_ptr_dma,
  1803. GFP_KERNEL);
  1804. if (!hba->t2_hash_tbl_ptr) {
  1805. printk(KERN_ERR PFX "unable to allocate t2 hash table ptr\n");
  1806. bnx2fc_free_fw_resc(hba);
  1807. return -ENOMEM;
  1808. }
  1809. memset(hba->t2_hash_tbl_ptr, 0x00, mem_size);
  1810. mem_size = BNX2FC_NUM_MAX_SESS *
  1811. sizeof(struct fcoe_t2_hash_table_entry);
  1812. hba->t2_hash_tbl = dma_alloc_coherent(&hba->pcidev->dev, mem_size,
  1813. &hba->t2_hash_tbl_dma,
  1814. GFP_KERNEL);
  1815. if (!hba->t2_hash_tbl) {
  1816. printk(KERN_ERR PFX "unable to allocate t2 hash table\n");
  1817. bnx2fc_free_fw_resc(hba);
  1818. return -ENOMEM;
  1819. }
  1820. memset(hba->t2_hash_tbl, 0x00, mem_size);
  1821. for (i = 0; i < BNX2FC_NUM_MAX_SESS; i++) {
  1822. addr = (unsigned long) hba->t2_hash_tbl_dma +
  1823. ((i+1) * sizeof(struct fcoe_t2_hash_table_entry));
  1824. hba->t2_hash_tbl[i].next.lo = addr & 0xffffffff;
  1825. hba->t2_hash_tbl[i].next.hi = addr >> 32;
  1826. }
  1827. hba->dummy_buffer = dma_alloc_coherent(&hba->pcidev->dev,
  1828. PAGE_SIZE, &hba->dummy_buf_dma,
  1829. GFP_KERNEL);
  1830. if (!hba->dummy_buffer) {
  1831. printk(KERN_ERR PFX "unable to alloc MP Dummy Buffer\n");
  1832. bnx2fc_free_fw_resc(hba);
  1833. return -ENOMEM;
  1834. }
  1835. hba->stats_buffer = dma_alloc_coherent(&hba->pcidev->dev,
  1836. PAGE_SIZE,
  1837. &hba->stats_buf_dma,
  1838. GFP_KERNEL);
  1839. if (!hba->stats_buffer) {
  1840. printk(KERN_ERR PFX "unable to alloc Stats Buffer\n");
  1841. bnx2fc_free_fw_resc(hba);
  1842. return -ENOMEM;
  1843. }
  1844. memset(hba->stats_buffer, 0x00, PAGE_SIZE);
  1845. return 0;
  1846. }
  1847. void bnx2fc_free_fw_resc(struct bnx2fc_hba *hba)
  1848. {
  1849. u32 mem_size;
  1850. if (hba->stats_buffer) {
  1851. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1852. hba->stats_buffer, hba->stats_buf_dma);
  1853. hba->stats_buffer = NULL;
  1854. }
  1855. if (hba->dummy_buffer) {
  1856. dma_free_coherent(&hba->pcidev->dev, PAGE_SIZE,
  1857. hba->dummy_buffer, hba->dummy_buf_dma);
  1858. hba->dummy_buffer = NULL;
  1859. }
  1860. if (hba->t2_hash_tbl_ptr) {
  1861. mem_size = BNX2FC_NUM_MAX_SESS * sizeof(struct regpair);
  1862. dma_free_coherent(&hba->pcidev->dev, mem_size,
  1863. hba->t2_hash_tbl_ptr,
  1864. hba->t2_hash_tbl_ptr_dma);
  1865. hba->t2_hash_tbl_ptr = NULL;
  1866. }
  1867. if (hba->t2_hash_tbl) {
  1868. mem_size = BNX2FC_NUM_MAX_SESS *
  1869. sizeof(struct fcoe_t2_hash_table_entry);
  1870. dma_free_coherent(&hba->pcidev->dev, mem_size,
  1871. hba->t2_hash_tbl, hba->t2_hash_tbl_dma);
  1872. hba->t2_hash_tbl = NULL;
  1873. }
  1874. bnx2fc_free_hash_table(hba);
  1875. }