bnx2fc_hwi.c 62 KB

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