bfa_core.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include "bfad_drv.h"
  18. #include "bfa_modules.h"
  19. #include "bfi_reg.h"
  20. BFA_TRC_FILE(HAL, CORE);
  21. /*
  22. * BFA module list terminated by NULL
  23. */
  24. static struct bfa_module_s *hal_mods[] = {
  25. &hal_mod_fcdiag,
  26. &hal_mod_sgpg,
  27. &hal_mod_fcport,
  28. &hal_mod_fcxp,
  29. &hal_mod_lps,
  30. &hal_mod_uf,
  31. &hal_mod_rport,
  32. &hal_mod_fcp,
  33. &hal_mod_dconf,
  34. NULL
  35. };
  36. /*
  37. * Message handlers for various modules.
  38. */
  39. static bfa_isr_func_t bfa_isrs[BFI_MC_MAX] = {
  40. bfa_isr_unhandled, /* NONE */
  41. bfa_isr_unhandled, /* BFI_MC_IOC */
  42. bfa_fcdiag_intr, /* BFI_MC_DIAG */
  43. bfa_isr_unhandled, /* BFI_MC_FLASH */
  44. bfa_isr_unhandled, /* BFI_MC_CEE */
  45. bfa_fcport_isr, /* BFI_MC_FCPORT */
  46. bfa_isr_unhandled, /* BFI_MC_IOCFC */
  47. bfa_isr_unhandled, /* BFI_MC_LL */
  48. bfa_uf_isr, /* BFI_MC_UF */
  49. bfa_fcxp_isr, /* BFI_MC_FCXP */
  50. bfa_lps_isr, /* BFI_MC_LPS */
  51. bfa_rport_isr, /* BFI_MC_RPORT */
  52. bfa_itn_isr, /* BFI_MC_ITN */
  53. bfa_isr_unhandled, /* BFI_MC_IOIM_READ */
  54. bfa_isr_unhandled, /* BFI_MC_IOIM_WRITE */
  55. bfa_isr_unhandled, /* BFI_MC_IOIM_IO */
  56. bfa_ioim_isr, /* BFI_MC_IOIM */
  57. bfa_ioim_good_comp_isr, /* BFI_MC_IOIM_IOCOM */
  58. bfa_tskim_isr, /* BFI_MC_TSKIM */
  59. bfa_isr_unhandled, /* BFI_MC_SBOOT */
  60. bfa_isr_unhandled, /* BFI_MC_IPFC */
  61. bfa_isr_unhandled, /* BFI_MC_PORT */
  62. bfa_isr_unhandled, /* --------- */
  63. bfa_isr_unhandled, /* --------- */
  64. bfa_isr_unhandled, /* --------- */
  65. bfa_isr_unhandled, /* --------- */
  66. bfa_isr_unhandled, /* --------- */
  67. bfa_isr_unhandled, /* --------- */
  68. bfa_isr_unhandled, /* --------- */
  69. bfa_isr_unhandled, /* --------- */
  70. bfa_isr_unhandled, /* --------- */
  71. bfa_isr_unhandled, /* --------- */
  72. };
  73. /*
  74. * Message handlers for mailbox command classes
  75. */
  76. static bfa_ioc_mbox_mcfunc_t bfa_mbox_isrs[BFI_MC_MAX] = {
  77. NULL,
  78. NULL, /* BFI_MC_IOC */
  79. NULL, /* BFI_MC_DIAG */
  80. NULL, /* BFI_MC_FLASH */
  81. NULL, /* BFI_MC_CEE */
  82. NULL, /* BFI_MC_PORT */
  83. bfa_iocfc_isr, /* BFI_MC_IOCFC */
  84. NULL,
  85. };
  86. static void
  87. bfa_com_port_attach(struct bfa_s *bfa)
  88. {
  89. struct bfa_port_s *port = &bfa->modules.port;
  90. struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
  91. bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod);
  92. bfa_port_mem_claim(port, port_dma->kva_curp, port_dma->dma_curp);
  93. }
  94. /*
  95. * ablk module attach
  96. */
  97. static void
  98. bfa_com_ablk_attach(struct bfa_s *bfa)
  99. {
  100. struct bfa_ablk_s *ablk = &bfa->modules.ablk;
  101. struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
  102. bfa_ablk_attach(ablk, &bfa->ioc);
  103. bfa_ablk_memclaim(ablk, ablk_dma->kva_curp, ablk_dma->dma_curp);
  104. }
  105. static void
  106. bfa_com_cee_attach(struct bfa_s *bfa)
  107. {
  108. struct bfa_cee_s *cee = &bfa->modules.cee;
  109. struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
  110. cee->trcmod = bfa->trcmod;
  111. bfa_cee_attach(cee, &bfa->ioc, bfa);
  112. bfa_cee_mem_claim(cee, cee_dma->kva_curp, cee_dma->dma_curp);
  113. }
  114. static void
  115. bfa_com_sfp_attach(struct bfa_s *bfa)
  116. {
  117. struct bfa_sfp_s *sfp = BFA_SFP_MOD(bfa);
  118. struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
  119. bfa_sfp_attach(sfp, &bfa->ioc, bfa, bfa->trcmod);
  120. bfa_sfp_memclaim(sfp, sfp_dma->kva_curp, sfp_dma->dma_curp);
  121. }
  122. static void
  123. bfa_com_flash_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
  124. {
  125. struct bfa_flash_s *flash = BFA_FLASH(bfa);
  126. struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
  127. bfa_flash_attach(flash, &bfa->ioc, bfa, bfa->trcmod, mincfg);
  128. bfa_flash_memclaim(flash, flash_dma->kva_curp,
  129. flash_dma->dma_curp, mincfg);
  130. }
  131. static void
  132. bfa_com_diag_attach(struct bfa_s *bfa)
  133. {
  134. struct bfa_diag_s *diag = BFA_DIAG_MOD(bfa);
  135. struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
  136. bfa_diag_attach(diag, &bfa->ioc, bfa, bfa_fcport_beacon, bfa->trcmod);
  137. bfa_diag_memclaim(diag, diag_dma->kva_curp, diag_dma->dma_curp);
  138. }
  139. static void
  140. bfa_com_phy_attach(struct bfa_s *bfa, bfa_boolean_t mincfg)
  141. {
  142. struct bfa_phy_s *phy = BFA_PHY(bfa);
  143. struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
  144. bfa_phy_attach(phy, &bfa->ioc, bfa, bfa->trcmod, mincfg);
  145. bfa_phy_memclaim(phy, phy_dma->kva_curp, phy_dma->dma_curp, mincfg);
  146. }
  147. /*
  148. * BFA IOC FC related definitions
  149. */
  150. /*
  151. * IOC local definitions
  152. */
  153. #define BFA_IOCFC_TOV 5000 /* msecs */
  154. enum {
  155. BFA_IOCFC_ACT_NONE = 0,
  156. BFA_IOCFC_ACT_INIT = 1,
  157. BFA_IOCFC_ACT_STOP = 2,
  158. BFA_IOCFC_ACT_DISABLE = 3,
  159. BFA_IOCFC_ACT_ENABLE = 4,
  160. };
  161. #define DEF_CFG_NUM_FABRICS 1
  162. #define DEF_CFG_NUM_LPORTS 256
  163. #define DEF_CFG_NUM_CQS 4
  164. #define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
  165. #define DEF_CFG_NUM_TSKIM_REQS 128
  166. #define DEF_CFG_NUM_FCXP_REQS 64
  167. #define DEF_CFG_NUM_UF_BUFS 64
  168. #define DEF_CFG_NUM_RPORTS 1024
  169. #define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
  170. #define DEF_CFG_NUM_TINS 256
  171. #define DEF_CFG_NUM_SGPGS 2048
  172. #define DEF_CFG_NUM_REQQ_ELEMS 256
  173. #define DEF_CFG_NUM_RSPQ_ELEMS 64
  174. #define DEF_CFG_NUM_SBOOT_TGTS 16
  175. #define DEF_CFG_NUM_SBOOT_LUNS 16
  176. /*
  177. * IOCFC state machine definitions/declarations
  178. */
  179. bfa_fsm_state_decl(bfa_iocfc, stopped, struct bfa_iocfc_s, enum iocfc_event);
  180. bfa_fsm_state_decl(bfa_iocfc, initing, struct bfa_iocfc_s, enum iocfc_event);
  181. bfa_fsm_state_decl(bfa_iocfc, dconf_read, struct bfa_iocfc_s, enum iocfc_event);
  182. bfa_fsm_state_decl(bfa_iocfc, init_cfg_wait,
  183. struct bfa_iocfc_s, enum iocfc_event);
  184. bfa_fsm_state_decl(bfa_iocfc, init_cfg_done,
  185. struct bfa_iocfc_s, enum iocfc_event);
  186. bfa_fsm_state_decl(bfa_iocfc, operational,
  187. struct bfa_iocfc_s, enum iocfc_event);
  188. bfa_fsm_state_decl(bfa_iocfc, dconf_write,
  189. struct bfa_iocfc_s, enum iocfc_event);
  190. bfa_fsm_state_decl(bfa_iocfc, stopping, struct bfa_iocfc_s, enum iocfc_event);
  191. bfa_fsm_state_decl(bfa_iocfc, enabling, struct bfa_iocfc_s, enum iocfc_event);
  192. bfa_fsm_state_decl(bfa_iocfc, cfg_wait, struct bfa_iocfc_s, enum iocfc_event);
  193. bfa_fsm_state_decl(bfa_iocfc, disabling, struct bfa_iocfc_s, enum iocfc_event);
  194. bfa_fsm_state_decl(bfa_iocfc, disabled, struct bfa_iocfc_s, enum iocfc_event);
  195. bfa_fsm_state_decl(bfa_iocfc, failed, struct bfa_iocfc_s, enum iocfc_event);
  196. bfa_fsm_state_decl(bfa_iocfc, init_failed,
  197. struct bfa_iocfc_s, enum iocfc_event);
  198. /*
  199. * forward declaration for IOC FC functions
  200. */
  201. static void bfa_iocfc_start_submod(struct bfa_s *bfa);
  202. static void bfa_iocfc_disable_submod(struct bfa_s *bfa);
  203. static void bfa_iocfc_send_cfg(void *bfa_arg);
  204. static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
  205. static void bfa_iocfc_disable_cbfn(void *bfa_arg);
  206. static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
  207. static void bfa_iocfc_reset_cbfn(void *bfa_arg);
  208. static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
  209. static void bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete);
  210. static void bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl);
  211. static void bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl);
  212. static void bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl);
  213. static void
  214. bfa_iocfc_sm_stopped_entry(struct bfa_iocfc_s *iocfc)
  215. {
  216. }
  217. static void
  218. bfa_iocfc_sm_stopped(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  219. {
  220. bfa_trc(iocfc->bfa, event);
  221. switch (event) {
  222. case IOCFC_E_INIT:
  223. case IOCFC_E_ENABLE:
  224. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_initing);
  225. break;
  226. default:
  227. bfa_sm_fault(iocfc->bfa, event);
  228. break;
  229. }
  230. }
  231. static void
  232. bfa_iocfc_sm_initing_entry(struct bfa_iocfc_s *iocfc)
  233. {
  234. bfa_ioc_enable(&iocfc->bfa->ioc);
  235. }
  236. static void
  237. bfa_iocfc_sm_initing(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  238. {
  239. bfa_trc(iocfc->bfa, event);
  240. switch (event) {
  241. case IOCFC_E_IOC_ENABLED:
  242. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
  243. break;
  244. case IOCFC_E_DISABLE:
  245. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  246. break;
  247. case IOCFC_E_STOP:
  248. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
  249. break;
  250. case IOCFC_E_IOC_FAILED:
  251. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
  252. break;
  253. default:
  254. bfa_sm_fault(iocfc->bfa, event);
  255. break;
  256. }
  257. }
  258. static void
  259. bfa_iocfc_sm_dconf_read_entry(struct bfa_iocfc_s *iocfc)
  260. {
  261. bfa_dconf_modinit(iocfc->bfa);
  262. }
  263. static void
  264. bfa_iocfc_sm_dconf_read(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  265. {
  266. bfa_trc(iocfc->bfa, event);
  267. switch (event) {
  268. case IOCFC_E_DCONF_DONE:
  269. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_wait);
  270. break;
  271. case IOCFC_E_DISABLE:
  272. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  273. break;
  274. case IOCFC_E_STOP:
  275. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
  276. break;
  277. case IOCFC_E_IOC_FAILED:
  278. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
  279. break;
  280. default:
  281. bfa_sm_fault(iocfc->bfa, event);
  282. break;
  283. }
  284. }
  285. static void
  286. bfa_iocfc_sm_init_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
  287. {
  288. bfa_iocfc_send_cfg(iocfc->bfa);
  289. }
  290. static void
  291. bfa_iocfc_sm_init_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  292. {
  293. bfa_trc(iocfc->bfa, event);
  294. switch (event) {
  295. case IOCFC_E_CFG_DONE:
  296. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_cfg_done);
  297. break;
  298. case IOCFC_E_DISABLE:
  299. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  300. break;
  301. case IOCFC_E_STOP:
  302. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
  303. break;
  304. case IOCFC_E_IOC_FAILED:
  305. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_init_failed);
  306. break;
  307. default:
  308. bfa_sm_fault(iocfc->bfa, event);
  309. break;
  310. }
  311. }
  312. static void
  313. bfa_iocfc_sm_init_cfg_done_entry(struct bfa_iocfc_s *iocfc)
  314. {
  315. iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
  316. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
  317. bfa_iocfc_init_cb, iocfc->bfa);
  318. }
  319. static void
  320. bfa_iocfc_sm_init_cfg_done(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  321. {
  322. bfa_trc(iocfc->bfa, event);
  323. switch (event) {
  324. case IOCFC_E_START:
  325. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
  326. break;
  327. case IOCFC_E_STOP:
  328. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
  329. break;
  330. case IOCFC_E_DISABLE:
  331. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  332. break;
  333. case IOCFC_E_IOC_FAILED:
  334. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
  335. break;
  336. default:
  337. bfa_sm_fault(iocfc->bfa, event);
  338. break;
  339. }
  340. }
  341. static void
  342. bfa_iocfc_sm_operational_entry(struct bfa_iocfc_s *iocfc)
  343. {
  344. bfa_fcport_init(iocfc->bfa);
  345. bfa_iocfc_start_submod(iocfc->bfa);
  346. }
  347. static void
  348. bfa_iocfc_sm_operational(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  349. {
  350. bfa_trc(iocfc->bfa, event);
  351. switch (event) {
  352. case IOCFC_E_STOP:
  353. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
  354. break;
  355. case IOCFC_E_DISABLE:
  356. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  357. break;
  358. case IOCFC_E_IOC_FAILED:
  359. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
  360. break;
  361. default:
  362. bfa_sm_fault(iocfc->bfa, event);
  363. break;
  364. }
  365. }
  366. static void
  367. bfa_iocfc_sm_dconf_write_entry(struct bfa_iocfc_s *iocfc)
  368. {
  369. bfa_dconf_modexit(iocfc->bfa);
  370. }
  371. static void
  372. bfa_iocfc_sm_dconf_write(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  373. {
  374. bfa_trc(iocfc->bfa, event);
  375. switch (event) {
  376. case IOCFC_E_DCONF_DONE:
  377. case IOCFC_E_IOC_FAILED:
  378. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
  379. break;
  380. default:
  381. bfa_sm_fault(iocfc->bfa, event);
  382. break;
  383. }
  384. }
  385. static void
  386. bfa_iocfc_sm_stopping_entry(struct bfa_iocfc_s *iocfc)
  387. {
  388. bfa_ioc_disable(&iocfc->bfa->ioc);
  389. }
  390. static void
  391. bfa_iocfc_sm_stopping(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  392. {
  393. bfa_trc(iocfc->bfa, event);
  394. switch (event) {
  395. case IOCFC_E_IOC_DISABLED:
  396. bfa_isr_disable(iocfc->bfa);
  397. bfa_iocfc_disable_submod(iocfc->bfa);
  398. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
  399. iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
  400. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.stop_hcb_qe,
  401. bfa_iocfc_stop_cb, iocfc->bfa);
  402. break;
  403. case IOCFC_E_IOC_ENABLED:
  404. case IOCFC_E_DCONF_DONE:
  405. case IOCFC_E_CFG_DONE:
  406. break;
  407. default:
  408. bfa_sm_fault(iocfc->bfa, event);
  409. break;
  410. }
  411. }
  412. static void
  413. bfa_iocfc_sm_enabling_entry(struct bfa_iocfc_s *iocfc)
  414. {
  415. bfa_ioc_enable(&iocfc->bfa->ioc);
  416. }
  417. static void
  418. bfa_iocfc_sm_enabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  419. {
  420. bfa_trc(iocfc->bfa, event);
  421. switch (event) {
  422. case IOCFC_E_IOC_ENABLED:
  423. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
  424. break;
  425. case IOCFC_E_DISABLE:
  426. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  427. break;
  428. case IOCFC_E_STOP:
  429. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
  430. break;
  431. case IOCFC_E_IOC_FAILED:
  432. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
  433. if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
  434. break;
  435. iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
  436. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
  437. bfa_iocfc_enable_cb, iocfc->bfa);
  438. iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
  439. break;
  440. default:
  441. bfa_sm_fault(iocfc->bfa, event);
  442. break;
  443. }
  444. }
  445. static void
  446. bfa_iocfc_sm_cfg_wait_entry(struct bfa_iocfc_s *iocfc)
  447. {
  448. bfa_iocfc_send_cfg(iocfc->bfa);
  449. }
  450. static void
  451. bfa_iocfc_sm_cfg_wait(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  452. {
  453. bfa_trc(iocfc->bfa, event);
  454. switch (event) {
  455. case IOCFC_E_CFG_DONE:
  456. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_operational);
  457. if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
  458. break;
  459. iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
  460. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
  461. bfa_iocfc_enable_cb, iocfc->bfa);
  462. iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
  463. break;
  464. case IOCFC_E_DISABLE:
  465. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  466. break;
  467. case IOCFC_E_STOP:
  468. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
  469. break;
  470. case IOCFC_E_IOC_FAILED:
  471. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_failed);
  472. if (iocfc->bfa->iocfc.cb_reqd == BFA_FALSE)
  473. break;
  474. iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
  475. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.en_hcb_qe,
  476. bfa_iocfc_enable_cb, iocfc->bfa);
  477. iocfc->bfa->iocfc.cb_reqd = BFA_FALSE;
  478. break;
  479. default:
  480. bfa_sm_fault(iocfc->bfa, event);
  481. break;
  482. }
  483. }
  484. static void
  485. bfa_iocfc_sm_disabling_entry(struct bfa_iocfc_s *iocfc)
  486. {
  487. bfa_ioc_disable(&iocfc->bfa->ioc);
  488. }
  489. static void
  490. bfa_iocfc_sm_disabling(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  491. {
  492. bfa_trc(iocfc->bfa, event);
  493. switch (event) {
  494. case IOCFC_E_IOC_DISABLED:
  495. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabled);
  496. break;
  497. case IOCFC_E_IOC_ENABLED:
  498. case IOCFC_E_DCONF_DONE:
  499. case IOCFC_E_CFG_DONE:
  500. break;
  501. default:
  502. bfa_sm_fault(iocfc->bfa, event);
  503. break;
  504. }
  505. }
  506. static void
  507. bfa_iocfc_sm_disabled_entry(struct bfa_iocfc_s *iocfc)
  508. {
  509. bfa_isr_disable(iocfc->bfa);
  510. bfa_iocfc_disable_submod(iocfc->bfa);
  511. iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
  512. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
  513. bfa_iocfc_disable_cb, iocfc->bfa);
  514. }
  515. static void
  516. bfa_iocfc_sm_disabled(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  517. {
  518. bfa_trc(iocfc->bfa, event);
  519. switch (event) {
  520. case IOCFC_E_STOP:
  521. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
  522. break;
  523. case IOCFC_E_ENABLE:
  524. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_enabling);
  525. break;
  526. default:
  527. bfa_sm_fault(iocfc->bfa, event);
  528. break;
  529. }
  530. }
  531. static void
  532. bfa_iocfc_sm_failed_entry(struct bfa_iocfc_s *iocfc)
  533. {
  534. bfa_isr_disable(iocfc->bfa);
  535. bfa_iocfc_disable_submod(iocfc->bfa);
  536. }
  537. static void
  538. bfa_iocfc_sm_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  539. {
  540. bfa_trc(iocfc->bfa, event);
  541. switch (event) {
  542. case IOCFC_E_STOP:
  543. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_write);
  544. break;
  545. case IOCFC_E_DISABLE:
  546. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_disabling);
  547. break;
  548. case IOCFC_E_IOC_ENABLED:
  549. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_cfg_wait);
  550. break;
  551. case IOCFC_E_IOC_FAILED:
  552. break;
  553. default:
  554. bfa_sm_fault(iocfc->bfa, event);
  555. break;
  556. }
  557. }
  558. static void
  559. bfa_iocfc_sm_init_failed_entry(struct bfa_iocfc_s *iocfc)
  560. {
  561. bfa_isr_disable(iocfc->bfa);
  562. iocfc->bfa->iocfc.op_status = BFA_STATUS_FAILED;
  563. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.init_hcb_qe,
  564. bfa_iocfc_init_cb, iocfc->bfa);
  565. }
  566. static void
  567. bfa_iocfc_sm_init_failed(struct bfa_iocfc_s *iocfc, enum iocfc_event event)
  568. {
  569. bfa_trc(iocfc->bfa, event);
  570. switch (event) {
  571. case IOCFC_E_STOP:
  572. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopping);
  573. break;
  574. case IOCFC_E_DISABLE:
  575. bfa_ioc_disable(&iocfc->bfa->ioc);
  576. break;
  577. case IOCFC_E_IOC_ENABLED:
  578. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_dconf_read);
  579. break;
  580. case IOCFC_E_IOC_DISABLED:
  581. bfa_fsm_set_state(iocfc, bfa_iocfc_sm_stopped);
  582. iocfc->bfa->iocfc.op_status = BFA_STATUS_OK;
  583. bfa_cb_queue(iocfc->bfa, &iocfc->bfa->iocfc.dis_hcb_qe,
  584. bfa_iocfc_disable_cb, iocfc->bfa);
  585. break;
  586. case IOCFC_E_IOC_FAILED:
  587. break;
  588. default:
  589. bfa_sm_fault(iocfc->bfa, event);
  590. break;
  591. }
  592. }
  593. /*
  594. * BFA Interrupt handling functions
  595. */
  596. static void
  597. bfa_reqq_resume(struct bfa_s *bfa, int qid)
  598. {
  599. struct list_head *waitq, *qe, *qen;
  600. struct bfa_reqq_wait_s *wqe;
  601. waitq = bfa_reqq(bfa, qid);
  602. list_for_each_safe(qe, qen, waitq) {
  603. /*
  604. * Callback only as long as there is room in request queue
  605. */
  606. if (bfa_reqq_full(bfa, qid))
  607. break;
  608. list_del(qe);
  609. wqe = (struct bfa_reqq_wait_s *) qe;
  610. wqe->qresume(wqe->cbarg);
  611. }
  612. }
  613. bfa_boolean_t
  614. bfa_isr_rspq(struct bfa_s *bfa, int qid)
  615. {
  616. struct bfi_msg_s *m;
  617. u32 pi, ci;
  618. struct list_head *waitq;
  619. bfa_boolean_t ret;
  620. ci = bfa_rspq_ci(bfa, qid);
  621. pi = bfa_rspq_pi(bfa, qid);
  622. ret = (ci != pi);
  623. while (ci != pi) {
  624. m = bfa_rspq_elem(bfa, qid, ci);
  625. WARN_ON(m->mhdr.msg_class >= BFI_MC_MAX);
  626. bfa_isrs[m->mhdr.msg_class] (bfa, m);
  627. CQ_INCR(ci, bfa->iocfc.cfg.drvcfg.num_rspq_elems);
  628. }
  629. /*
  630. * acknowledge RME completions and update CI
  631. */
  632. bfa_isr_rspq_ack(bfa, qid, ci);
  633. /*
  634. * Resume any pending requests in the corresponding reqq.
  635. */
  636. waitq = bfa_reqq(bfa, qid);
  637. if (!list_empty(waitq))
  638. bfa_reqq_resume(bfa, qid);
  639. return ret;
  640. }
  641. static inline void
  642. bfa_isr_reqq(struct bfa_s *bfa, int qid)
  643. {
  644. struct list_head *waitq;
  645. bfa_isr_reqq_ack(bfa, qid);
  646. /*
  647. * Resume any pending requests in the corresponding reqq.
  648. */
  649. waitq = bfa_reqq(bfa, qid);
  650. if (!list_empty(waitq))
  651. bfa_reqq_resume(bfa, qid);
  652. }
  653. void
  654. bfa_msix_all(struct bfa_s *bfa, int vec)
  655. {
  656. u32 intr, qintr;
  657. int queue;
  658. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  659. if (!intr)
  660. return;
  661. /*
  662. * RME completion queue interrupt
  663. */
  664. qintr = intr & __HFN_INT_RME_MASK;
  665. if (qintr && bfa->queue_process) {
  666. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  667. bfa_isr_rspq(bfa, queue);
  668. }
  669. intr &= ~qintr;
  670. if (!intr)
  671. return;
  672. /*
  673. * CPE completion queue interrupt
  674. */
  675. qintr = intr & __HFN_INT_CPE_MASK;
  676. if (qintr && bfa->queue_process) {
  677. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  678. bfa_isr_reqq(bfa, queue);
  679. }
  680. intr &= ~qintr;
  681. if (!intr)
  682. return;
  683. bfa_msix_lpu_err(bfa, intr);
  684. }
  685. bfa_boolean_t
  686. bfa_intx(struct bfa_s *bfa)
  687. {
  688. u32 intr, qintr;
  689. int queue;
  690. bfa_boolean_t rspq_comp = BFA_FALSE;
  691. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  692. qintr = intr & (__HFN_INT_RME_MASK | __HFN_INT_CPE_MASK);
  693. if (qintr)
  694. writel(qintr, bfa->iocfc.bfa_regs.intr_status);
  695. /*
  696. * Unconditional RME completion queue interrupt
  697. */
  698. if (bfa->queue_process) {
  699. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  700. if (bfa_isr_rspq(bfa, queue))
  701. rspq_comp = BFA_TRUE;
  702. }
  703. if (!intr)
  704. return (qintr | rspq_comp) ? BFA_TRUE : BFA_FALSE;
  705. /*
  706. * CPE completion queue interrupt
  707. */
  708. qintr = intr & __HFN_INT_CPE_MASK;
  709. if (qintr && bfa->queue_process) {
  710. for (queue = 0; queue < BFI_IOC_MAX_CQS; queue++)
  711. bfa_isr_reqq(bfa, queue);
  712. }
  713. intr &= ~qintr;
  714. if (!intr)
  715. return BFA_TRUE;
  716. if (bfa->intr_enabled)
  717. bfa_msix_lpu_err(bfa, intr);
  718. return BFA_TRUE;
  719. }
  720. void
  721. bfa_isr_enable(struct bfa_s *bfa)
  722. {
  723. u32 umsk;
  724. int pci_func = bfa_ioc_pcifn(&bfa->ioc);
  725. bfa_trc(bfa, pci_func);
  726. bfa_msix_ctrl_install(bfa);
  727. if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
  728. umsk = __HFN_INT_ERR_MASK_CT2;
  729. umsk |= pci_func == 0 ?
  730. __HFN_INT_FN0_MASK_CT2 : __HFN_INT_FN1_MASK_CT2;
  731. } else {
  732. umsk = __HFN_INT_ERR_MASK;
  733. umsk |= pci_func == 0 ? __HFN_INT_FN0_MASK : __HFN_INT_FN1_MASK;
  734. }
  735. writel(umsk, bfa->iocfc.bfa_regs.intr_status);
  736. writel(~umsk, bfa->iocfc.bfa_regs.intr_mask);
  737. bfa->iocfc.intr_mask = ~umsk;
  738. bfa_isr_mode_set(bfa, bfa->msix.nvecs != 0);
  739. /*
  740. * Set the flag indicating successful enabling of interrupts
  741. */
  742. bfa->intr_enabled = BFA_TRUE;
  743. }
  744. void
  745. bfa_isr_disable(struct bfa_s *bfa)
  746. {
  747. bfa->intr_enabled = BFA_FALSE;
  748. bfa_isr_mode_set(bfa, BFA_FALSE);
  749. writel(-1L, bfa->iocfc.bfa_regs.intr_mask);
  750. bfa_msix_uninstall(bfa);
  751. }
  752. void
  753. bfa_msix_reqq(struct bfa_s *bfa, int vec)
  754. {
  755. bfa_isr_reqq(bfa, vec - bfa->iocfc.hwif.cpe_vec_q0);
  756. }
  757. void
  758. bfa_isr_unhandled(struct bfa_s *bfa, struct bfi_msg_s *m)
  759. {
  760. bfa_trc(bfa, m->mhdr.msg_class);
  761. bfa_trc(bfa, m->mhdr.msg_id);
  762. bfa_trc(bfa, m->mhdr.mtag.i2htok);
  763. WARN_ON(1);
  764. bfa_trc_stop(bfa->trcmod);
  765. }
  766. void
  767. bfa_msix_rspq(struct bfa_s *bfa, int vec)
  768. {
  769. bfa_isr_rspq(bfa, vec - bfa->iocfc.hwif.rme_vec_q0);
  770. }
  771. void
  772. bfa_msix_lpu_err(struct bfa_s *bfa, int vec)
  773. {
  774. u32 intr, curr_value;
  775. bfa_boolean_t lpu_isr, halt_isr, pss_isr;
  776. intr = readl(bfa->iocfc.bfa_regs.intr_status);
  777. if (bfa_asic_id_ct2(bfa->ioc.pcidev.device_id)) {
  778. halt_isr = intr & __HFN_INT_CPQ_HALT_CT2;
  779. pss_isr = intr & __HFN_INT_ERR_PSS_CT2;
  780. lpu_isr = intr & (__HFN_INT_MBOX_LPU0_CT2 |
  781. __HFN_INT_MBOX_LPU1_CT2);
  782. intr &= __HFN_INT_ERR_MASK_CT2;
  783. } else {
  784. halt_isr = bfa_asic_id_ct(bfa->ioc.pcidev.device_id) ?
  785. (intr & __HFN_INT_LL_HALT) : 0;
  786. pss_isr = intr & __HFN_INT_ERR_PSS;
  787. lpu_isr = intr & (__HFN_INT_MBOX_LPU0 | __HFN_INT_MBOX_LPU1);
  788. intr &= __HFN_INT_ERR_MASK;
  789. }
  790. if (lpu_isr)
  791. bfa_ioc_mbox_isr(&bfa->ioc);
  792. if (intr) {
  793. if (halt_isr) {
  794. /*
  795. * If LL_HALT bit is set then FW Init Halt LL Port
  796. * Register needs to be cleared as well so Interrupt
  797. * Status Register will be cleared.
  798. */
  799. curr_value = readl(bfa->ioc.ioc_regs.ll_halt);
  800. curr_value &= ~__FW_INIT_HALT_P;
  801. writel(curr_value, bfa->ioc.ioc_regs.ll_halt);
  802. }
  803. if (pss_isr) {
  804. /*
  805. * ERR_PSS bit needs to be cleared as well in case
  806. * interrups are shared so driver's interrupt handler is
  807. * still called even though it is already masked out.
  808. */
  809. curr_value = readl(
  810. bfa->ioc.ioc_regs.pss_err_status_reg);
  811. writel(curr_value,
  812. bfa->ioc.ioc_regs.pss_err_status_reg);
  813. }
  814. writel(intr, bfa->iocfc.bfa_regs.intr_status);
  815. bfa_ioc_error_isr(&bfa->ioc);
  816. }
  817. }
  818. /*
  819. * BFA IOC FC related functions
  820. */
  821. /*
  822. * BFA IOC private functions
  823. */
  824. /*
  825. * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
  826. */
  827. static void
  828. bfa_iocfc_send_cfg(void *bfa_arg)
  829. {
  830. struct bfa_s *bfa = bfa_arg;
  831. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  832. struct bfi_iocfc_cfg_req_s cfg_req;
  833. struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
  834. struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
  835. int i;
  836. WARN_ON(cfg->fwcfg.num_cqs > BFI_IOC_MAX_CQS);
  837. bfa_trc(bfa, cfg->fwcfg.num_cqs);
  838. bfa_iocfc_reset_queues(bfa);
  839. /*
  840. * initialize IOC configuration info
  841. */
  842. cfg_info->single_msix_vec = 0;
  843. if (bfa->msix.nvecs == 1)
  844. cfg_info->single_msix_vec = 1;
  845. cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
  846. cfg_info->num_cqs = cfg->fwcfg.num_cqs;
  847. cfg_info->num_ioim_reqs = cpu_to_be16(bfa_fcpim_get_throttle_cfg(bfa,
  848. cfg->fwcfg.num_ioim_reqs));
  849. cfg_info->num_fwtio_reqs = cpu_to_be16(cfg->fwcfg.num_fwtio_reqs);
  850. bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
  851. /*
  852. * dma map REQ and RSP circular queues and shadow pointers
  853. */
  854. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  855. bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
  856. iocfc->req_cq_ba[i].pa);
  857. bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
  858. iocfc->req_cq_shadow_ci[i].pa);
  859. cfg_info->req_cq_elems[i] =
  860. cpu_to_be16(cfg->drvcfg.num_reqq_elems);
  861. bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
  862. iocfc->rsp_cq_ba[i].pa);
  863. bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
  864. iocfc->rsp_cq_shadow_pi[i].pa);
  865. cfg_info->rsp_cq_elems[i] =
  866. cpu_to_be16(cfg->drvcfg.num_rspq_elems);
  867. }
  868. /*
  869. * Enable interrupt coalescing if it is driver init path
  870. * and not ioc disable/enable path.
  871. */
  872. if (bfa_fsm_cmp_state(iocfc, bfa_iocfc_sm_init_cfg_wait))
  873. cfg_info->intr_attr.coalesce = BFA_TRUE;
  874. /*
  875. * dma map IOC configuration itself
  876. */
  877. bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
  878. bfa_fn_lpu(bfa));
  879. bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
  880. bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
  881. sizeof(struct bfi_iocfc_cfg_req_s));
  882. }
  883. static void
  884. bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  885. struct bfa_pcidev_s *pcidev)
  886. {
  887. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  888. bfa->bfad = bfad;
  889. iocfc->bfa = bfa;
  890. iocfc->cfg = *cfg;
  891. /*
  892. * Initialize chip specific handlers.
  893. */
  894. if (bfa_asic_id_ctc(bfa_ioc_devid(&bfa->ioc))) {
  895. iocfc->hwif.hw_reginit = bfa_hwct_reginit;
  896. iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
  897. iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
  898. iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
  899. iocfc->hwif.hw_msix_ctrl_install = bfa_hwct_msix_ctrl_install;
  900. iocfc->hwif.hw_msix_queue_install = bfa_hwct_msix_queue_install;
  901. iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
  902. iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
  903. iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
  904. iocfc->hwif.hw_msix_get_rme_range = bfa_hwct_msix_get_rme_range;
  905. iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CT;
  906. iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CT;
  907. } else {
  908. iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
  909. iocfc->hwif.hw_reqq_ack = NULL;
  910. iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
  911. iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
  912. iocfc->hwif.hw_msix_ctrl_install = bfa_hwcb_msix_ctrl_install;
  913. iocfc->hwif.hw_msix_queue_install = bfa_hwcb_msix_queue_install;
  914. iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
  915. iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
  916. iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
  917. iocfc->hwif.hw_msix_get_rme_range = bfa_hwcb_msix_get_rme_range;
  918. iocfc->hwif.rme_vec_q0 = BFI_MSIX_RME_QMIN_CB +
  919. bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
  920. iocfc->hwif.cpe_vec_q0 = BFI_MSIX_CPE_QMIN_CB +
  921. bfa_ioc_pcifn(&bfa->ioc) * BFI_IOC_MAX_CQS;
  922. }
  923. if (bfa_asic_id_ct2(bfa_ioc_devid(&bfa->ioc))) {
  924. iocfc->hwif.hw_reginit = bfa_hwct2_reginit;
  925. iocfc->hwif.hw_isr_mode_set = NULL;
  926. iocfc->hwif.hw_rspq_ack = bfa_hwct2_rspq_ack;
  927. }
  928. iocfc->hwif.hw_reginit(bfa);
  929. bfa->msix.nvecs = 0;
  930. }
  931. static void
  932. bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg)
  933. {
  934. u8 *dm_kva = NULL;
  935. u64 dm_pa = 0;
  936. int i, per_reqq_sz, per_rspq_sz;
  937. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  938. struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
  939. struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
  940. struct bfa_mem_dma_s *reqq_dma, *rspq_dma;
  941. /* First allocate dma memory for IOC */
  942. bfa_ioc_mem_claim(&bfa->ioc, bfa_mem_dma_virt(ioc_dma),
  943. bfa_mem_dma_phys(ioc_dma));
  944. /* Claim DMA-able memory for the request/response queues */
  945. per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
  946. BFA_DMA_ALIGN_SZ);
  947. per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
  948. BFA_DMA_ALIGN_SZ);
  949. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  950. reqq_dma = BFA_MEM_REQQ_DMA(bfa, i);
  951. iocfc->req_cq_ba[i].kva = bfa_mem_dma_virt(reqq_dma);
  952. iocfc->req_cq_ba[i].pa = bfa_mem_dma_phys(reqq_dma);
  953. memset(iocfc->req_cq_ba[i].kva, 0, per_reqq_sz);
  954. rspq_dma = BFA_MEM_RSPQ_DMA(bfa, i);
  955. iocfc->rsp_cq_ba[i].kva = bfa_mem_dma_virt(rspq_dma);
  956. iocfc->rsp_cq_ba[i].pa = bfa_mem_dma_phys(rspq_dma);
  957. memset(iocfc->rsp_cq_ba[i].kva, 0, per_rspq_sz);
  958. }
  959. /* Claim IOCFC dma memory - for shadow CI/PI */
  960. dm_kva = bfa_mem_dma_virt(iocfc_dma);
  961. dm_pa = bfa_mem_dma_phys(iocfc_dma);
  962. for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
  963. iocfc->req_cq_shadow_ci[i].kva = dm_kva;
  964. iocfc->req_cq_shadow_ci[i].pa = dm_pa;
  965. dm_kva += BFA_CACHELINE_SZ;
  966. dm_pa += BFA_CACHELINE_SZ;
  967. iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
  968. iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
  969. dm_kva += BFA_CACHELINE_SZ;
  970. dm_pa += BFA_CACHELINE_SZ;
  971. }
  972. /* Claim IOCFC dma memory - for the config info page */
  973. bfa->iocfc.cfg_info.kva = dm_kva;
  974. bfa->iocfc.cfg_info.pa = dm_pa;
  975. bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
  976. dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  977. dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  978. /* Claim IOCFC dma memory - for the config response */
  979. bfa->iocfc.cfgrsp_dma.kva = dm_kva;
  980. bfa->iocfc.cfgrsp_dma.pa = dm_pa;
  981. bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
  982. dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  983. BFA_CACHELINE_SZ);
  984. dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  985. BFA_CACHELINE_SZ);
  986. /* Claim IOCFC kva memory */
  987. bfa_ioc_debug_memclaim(&bfa->ioc, bfa_mem_kva_curp(iocfc));
  988. bfa_mem_kva_curp(iocfc) += BFA_DBG_FWTRC_LEN;
  989. }
  990. /*
  991. * Start BFA submodules.
  992. */
  993. static void
  994. bfa_iocfc_start_submod(struct bfa_s *bfa)
  995. {
  996. int i;
  997. bfa->queue_process = BFA_TRUE;
  998. for (i = 0; i < BFI_IOC_MAX_CQS; i++)
  999. bfa_isr_rspq_ack(bfa, i, bfa_rspq_ci(bfa, i));
  1000. for (i = 0; hal_mods[i]; i++)
  1001. hal_mods[i]->start(bfa);
  1002. bfa->iocfc.submod_enabled = BFA_TRUE;
  1003. }
  1004. /*
  1005. * Disable BFA submodules.
  1006. */
  1007. static void
  1008. bfa_iocfc_disable_submod(struct bfa_s *bfa)
  1009. {
  1010. int i;
  1011. if (bfa->iocfc.submod_enabled == BFA_FALSE)
  1012. return;
  1013. for (i = 0; hal_mods[i]; i++)
  1014. hal_mods[i]->iocdisable(bfa);
  1015. bfa->iocfc.submod_enabled = BFA_FALSE;
  1016. }
  1017. static void
  1018. bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
  1019. {
  1020. struct bfa_s *bfa = bfa_arg;
  1021. if (complete)
  1022. bfa_cb_init(bfa->bfad, bfa->iocfc.op_status);
  1023. }
  1024. static void
  1025. bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
  1026. {
  1027. struct bfa_s *bfa = bfa_arg;
  1028. struct bfad_s *bfad = bfa->bfad;
  1029. if (compl)
  1030. complete(&bfad->comp);
  1031. }
  1032. static void
  1033. bfa_iocfc_enable_cb(void *bfa_arg, bfa_boolean_t compl)
  1034. {
  1035. struct bfa_s *bfa = bfa_arg;
  1036. struct bfad_s *bfad = bfa->bfad;
  1037. if (compl)
  1038. complete(&bfad->enable_comp);
  1039. }
  1040. static void
  1041. bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
  1042. {
  1043. struct bfa_s *bfa = bfa_arg;
  1044. struct bfad_s *bfad = bfa->bfad;
  1045. if (compl)
  1046. complete(&bfad->disable_comp);
  1047. }
  1048. /**
  1049. * configure queue registers from firmware response
  1050. */
  1051. static void
  1052. bfa_iocfc_qreg(struct bfa_s *bfa, struct bfi_iocfc_qreg_s *qreg)
  1053. {
  1054. int i;
  1055. struct bfa_iocfc_regs_s *r = &bfa->iocfc.bfa_regs;
  1056. void __iomem *kva = bfa_ioc_bar0(&bfa->ioc);
  1057. for (i = 0; i < BFI_IOC_MAX_CQS; i++) {
  1058. bfa->iocfc.hw_qid[i] = qreg->hw_qid[i];
  1059. r->cpe_q_ci[i] = kva + be32_to_cpu(qreg->cpe_q_ci_off[i]);
  1060. r->cpe_q_pi[i] = kva + be32_to_cpu(qreg->cpe_q_pi_off[i]);
  1061. r->cpe_q_ctrl[i] = kva + be32_to_cpu(qreg->cpe_qctl_off[i]);
  1062. r->rme_q_ci[i] = kva + be32_to_cpu(qreg->rme_q_ci_off[i]);
  1063. r->rme_q_pi[i] = kva + be32_to_cpu(qreg->rme_q_pi_off[i]);
  1064. r->rme_q_ctrl[i] = kva + be32_to_cpu(qreg->rme_qctl_off[i]);
  1065. }
  1066. }
  1067. static void
  1068. bfa_iocfc_res_recfg(struct bfa_s *bfa, struct bfa_iocfc_fwcfg_s *fwcfg)
  1069. {
  1070. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1071. struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
  1072. bfa_fcxp_res_recfg(bfa, fwcfg->num_fcxp_reqs);
  1073. bfa_uf_res_recfg(bfa, fwcfg->num_uf_bufs);
  1074. bfa_rport_res_recfg(bfa, fwcfg->num_rports);
  1075. bfa_fcp_res_recfg(bfa, cpu_to_be16(cfg_info->num_ioim_reqs),
  1076. fwcfg->num_ioim_reqs);
  1077. bfa_tskim_res_recfg(bfa, fwcfg->num_tskim_reqs);
  1078. }
  1079. /*
  1080. * Update BFA configuration from firmware configuration.
  1081. */
  1082. static void
  1083. bfa_iocfc_cfgrsp(struct bfa_s *bfa)
  1084. {
  1085. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1086. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  1087. struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
  1088. fwcfg->num_cqs = fwcfg->num_cqs;
  1089. fwcfg->num_ioim_reqs = be16_to_cpu(fwcfg->num_ioim_reqs);
  1090. fwcfg->num_fwtio_reqs = be16_to_cpu(fwcfg->num_fwtio_reqs);
  1091. fwcfg->num_tskim_reqs = be16_to_cpu(fwcfg->num_tskim_reqs);
  1092. fwcfg->num_fcxp_reqs = be16_to_cpu(fwcfg->num_fcxp_reqs);
  1093. fwcfg->num_uf_bufs = be16_to_cpu(fwcfg->num_uf_bufs);
  1094. fwcfg->num_rports = be16_to_cpu(fwcfg->num_rports);
  1095. /*
  1096. * configure queue register offsets as learnt from firmware
  1097. */
  1098. bfa_iocfc_qreg(bfa, &cfgrsp->qreg);
  1099. /*
  1100. * Re-configure resources as learnt from Firmware
  1101. */
  1102. bfa_iocfc_res_recfg(bfa, fwcfg);
  1103. /*
  1104. * Install MSIX queue handlers
  1105. */
  1106. bfa_msix_queue_install(bfa);
  1107. if (bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn != 0) {
  1108. bfa->ioc.attr->pwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_pwwn;
  1109. bfa->ioc.attr->nwwn = bfa->iocfc.cfgrsp->pbc_cfg.pbc_nwwn;
  1110. bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
  1111. }
  1112. }
  1113. void
  1114. bfa_iocfc_reset_queues(struct bfa_s *bfa)
  1115. {
  1116. int q;
  1117. for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
  1118. bfa_reqq_ci(bfa, q) = 0;
  1119. bfa_reqq_pi(bfa, q) = 0;
  1120. bfa_rspq_ci(bfa, q) = 0;
  1121. bfa_rspq_pi(bfa, q) = 0;
  1122. }
  1123. }
  1124. /*
  1125. * Process FAA pwwn msg from fw.
  1126. */
  1127. static void
  1128. bfa_iocfc_process_faa_addr(struct bfa_s *bfa, struct bfi_faa_addr_msg_s *msg)
  1129. {
  1130. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1131. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  1132. cfgrsp->pbc_cfg.pbc_pwwn = msg->pwwn;
  1133. cfgrsp->pbc_cfg.pbc_nwwn = msg->nwwn;
  1134. bfa->ioc.attr->pwwn = msg->pwwn;
  1135. bfa->ioc.attr->nwwn = msg->nwwn;
  1136. bfa_fsm_send_event(iocfc, IOCFC_E_CFG_DONE);
  1137. }
  1138. /* Fabric Assigned Address specific functions */
  1139. /*
  1140. * Check whether IOC is ready before sending command down
  1141. */
  1142. static bfa_status_t
  1143. bfa_faa_validate_request(struct bfa_s *bfa)
  1144. {
  1145. enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
  1146. u32 card_type = bfa->ioc.attr->card_type;
  1147. if (bfa_ioc_is_operational(&bfa->ioc)) {
  1148. if ((ioc_type != BFA_IOC_TYPE_FC) || bfa_mfg_is_mezz(card_type))
  1149. return BFA_STATUS_FEATURE_NOT_SUPPORTED;
  1150. } else {
  1151. return BFA_STATUS_IOC_NON_OP;
  1152. }
  1153. return BFA_STATUS_OK;
  1154. }
  1155. bfa_status_t
  1156. bfa_faa_query(struct bfa_s *bfa, struct bfa_faa_attr_s *attr,
  1157. bfa_cb_iocfc_t cbfn, void *cbarg)
  1158. {
  1159. struct bfi_faa_query_s faa_attr_req;
  1160. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1161. bfa_status_t status;
  1162. iocfc->faa_args.faa_attr = attr;
  1163. iocfc->faa_args.faa_cb.faa_cbfn = cbfn;
  1164. iocfc->faa_args.faa_cb.faa_cbarg = cbarg;
  1165. status = bfa_faa_validate_request(bfa);
  1166. if (status != BFA_STATUS_OK)
  1167. return status;
  1168. if (iocfc->faa_args.busy == BFA_TRUE)
  1169. return BFA_STATUS_DEVBUSY;
  1170. iocfc->faa_args.busy = BFA_TRUE;
  1171. memset(&faa_attr_req, 0, sizeof(struct bfi_faa_query_s));
  1172. bfi_h2i_set(faa_attr_req.mh, BFI_MC_IOCFC,
  1173. BFI_IOCFC_H2I_FAA_QUERY_REQ, bfa_fn_lpu(bfa));
  1174. bfa_ioc_mbox_send(&bfa->ioc, &faa_attr_req,
  1175. sizeof(struct bfi_faa_query_s));
  1176. return BFA_STATUS_OK;
  1177. }
  1178. /*
  1179. * FAA query response
  1180. */
  1181. static void
  1182. bfa_faa_query_reply(struct bfa_iocfc_s *iocfc,
  1183. bfi_faa_query_rsp_t *rsp)
  1184. {
  1185. void *cbarg = iocfc->faa_args.faa_cb.faa_cbarg;
  1186. if (iocfc->faa_args.faa_attr) {
  1187. iocfc->faa_args.faa_attr->faa = rsp->faa;
  1188. iocfc->faa_args.faa_attr->faa_state = rsp->faa_status;
  1189. iocfc->faa_args.faa_attr->pwwn_source = rsp->addr_source;
  1190. }
  1191. WARN_ON(!iocfc->faa_args.faa_cb.faa_cbfn);
  1192. iocfc->faa_args.faa_cb.faa_cbfn(cbarg, BFA_STATUS_OK);
  1193. iocfc->faa_args.busy = BFA_FALSE;
  1194. }
  1195. /*
  1196. * IOC enable request is complete
  1197. */
  1198. static void
  1199. bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
  1200. {
  1201. struct bfa_s *bfa = bfa_arg;
  1202. if (status == BFA_STATUS_OK)
  1203. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_ENABLED);
  1204. else
  1205. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
  1206. }
  1207. /*
  1208. * IOC disable request is complete
  1209. */
  1210. static void
  1211. bfa_iocfc_disable_cbfn(void *bfa_arg)
  1212. {
  1213. struct bfa_s *bfa = bfa_arg;
  1214. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_DISABLED);
  1215. }
  1216. /*
  1217. * Notify sub-modules of hardware failure.
  1218. */
  1219. static void
  1220. bfa_iocfc_hbfail_cbfn(void *bfa_arg)
  1221. {
  1222. struct bfa_s *bfa = bfa_arg;
  1223. bfa->queue_process = BFA_FALSE;
  1224. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_IOC_FAILED);
  1225. }
  1226. /*
  1227. * Actions on chip-reset completion.
  1228. */
  1229. static void
  1230. bfa_iocfc_reset_cbfn(void *bfa_arg)
  1231. {
  1232. struct bfa_s *bfa = bfa_arg;
  1233. bfa_iocfc_reset_queues(bfa);
  1234. bfa_isr_enable(bfa);
  1235. }
  1236. /*
  1237. * Query IOC memory requirement information.
  1238. */
  1239. void
  1240. bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  1241. struct bfa_s *bfa)
  1242. {
  1243. int q, per_reqq_sz, per_rspq_sz;
  1244. struct bfa_mem_dma_s *ioc_dma = BFA_MEM_IOC_DMA(bfa);
  1245. struct bfa_mem_dma_s *iocfc_dma = BFA_MEM_IOCFC_DMA(bfa);
  1246. struct bfa_mem_kva_s *iocfc_kva = BFA_MEM_IOCFC_KVA(bfa);
  1247. u32 dm_len = 0;
  1248. /* dma memory setup for IOC */
  1249. bfa_mem_dma_setup(meminfo, ioc_dma,
  1250. BFA_ROUNDUP(sizeof(struct bfi_ioc_attr_s), BFA_DMA_ALIGN_SZ));
  1251. /* dma memory setup for REQ/RSP queues */
  1252. per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
  1253. BFA_DMA_ALIGN_SZ);
  1254. per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
  1255. BFA_DMA_ALIGN_SZ);
  1256. for (q = 0; q < cfg->fwcfg.num_cqs; q++) {
  1257. bfa_mem_dma_setup(meminfo, BFA_MEM_REQQ_DMA(bfa, q),
  1258. per_reqq_sz);
  1259. bfa_mem_dma_setup(meminfo, BFA_MEM_RSPQ_DMA(bfa, q),
  1260. per_rspq_sz);
  1261. }
  1262. /* IOCFC dma memory - calculate Shadow CI/PI size */
  1263. for (q = 0; q < cfg->fwcfg.num_cqs; q++)
  1264. dm_len += (2 * BFA_CACHELINE_SZ);
  1265. /* IOCFC dma memory - calculate config info / rsp size */
  1266. dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
  1267. dm_len += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
  1268. BFA_CACHELINE_SZ);
  1269. /* dma memory setup for IOCFC */
  1270. bfa_mem_dma_setup(meminfo, iocfc_dma, dm_len);
  1271. /* kva memory setup for IOCFC */
  1272. bfa_mem_kva_setup(meminfo, iocfc_kva, BFA_DBG_FWTRC_LEN);
  1273. }
  1274. /*
  1275. * Query IOC memory requirement information.
  1276. */
  1277. void
  1278. bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1279. struct bfa_pcidev_s *pcidev)
  1280. {
  1281. int i;
  1282. struct bfa_ioc_s *ioc = &bfa->ioc;
  1283. bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
  1284. bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
  1285. bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
  1286. bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
  1287. ioc->trcmod = bfa->trcmod;
  1288. bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod);
  1289. bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_PCIFN_CLASS_FC);
  1290. bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
  1291. bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
  1292. bfa_iocfc_mem_claim(bfa, cfg);
  1293. INIT_LIST_HEAD(&bfa->timer_mod.timer_q);
  1294. INIT_LIST_HEAD(&bfa->comp_q);
  1295. for (i = 0; i < BFI_IOC_MAX_CQS; i++)
  1296. INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
  1297. bfa->iocfc.cb_reqd = BFA_FALSE;
  1298. bfa->iocfc.op_status = BFA_STATUS_OK;
  1299. bfa->iocfc.submod_enabled = BFA_FALSE;
  1300. bfa_fsm_set_state(&bfa->iocfc, bfa_iocfc_sm_stopped);
  1301. }
  1302. /*
  1303. * Query IOC memory requirement information.
  1304. */
  1305. void
  1306. bfa_iocfc_init(struct bfa_s *bfa)
  1307. {
  1308. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_INIT);
  1309. }
  1310. /*
  1311. * IOC start called from bfa_start(). Called to start IOC operations
  1312. * at driver instantiation for this instance.
  1313. */
  1314. void
  1315. bfa_iocfc_start(struct bfa_s *bfa)
  1316. {
  1317. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_START);
  1318. }
  1319. /*
  1320. * IOC stop called from bfa_stop(). Called only when driver is unloaded
  1321. * for this instance.
  1322. */
  1323. void
  1324. bfa_iocfc_stop(struct bfa_s *bfa)
  1325. {
  1326. bfa->queue_process = BFA_FALSE;
  1327. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_STOP);
  1328. }
  1329. void
  1330. bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
  1331. {
  1332. struct bfa_s *bfa = bfaarg;
  1333. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1334. union bfi_iocfc_i2h_msg_u *msg;
  1335. msg = (union bfi_iocfc_i2h_msg_u *) m;
  1336. bfa_trc(bfa, msg->mh.msg_id);
  1337. switch (msg->mh.msg_id) {
  1338. case BFI_IOCFC_I2H_CFG_REPLY:
  1339. bfa_iocfc_cfgrsp(bfa);
  1340. break;
  1341. case BFI_IOCFC_I2H_UPDATEQ_RSP:
  1342. iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
  1343. break;
  1344. case BFI_IOCFC_I2H_ADDR_MSG:
  1345. bfa_iocfc_process_faa_addr(bfa,
  1346. (struct bfi_faa_addr_msg_s *)msg);
  1347. break;
  1348. case BFI_IOCFC_I2H_FAA_QUERY_RSP:
  1349. bfa_faa_query_reply(iocfc, (bfi_faa_query_rsp_t *)msg);
  1350. break;
  1351. default:
  1352. WARN_ON(1);
  1353. }
  1354. }
  1355. void
  1356. bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
  1357. {
  1358. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1359. attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
  1360. attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
  1361. be16_to_cpu(iocfc->cfginfo->intr_attr.delay) :
  1362. be16_to_cpu(iocfc->cfgrsp->intr_attr.delay);
  1363. attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
  1364. be16_to_cpu(iocfc->cfginfo->intr_attr.latency) :
  1365. be16_to_cpu(iocfc->cfgrsp->intr_attr.latency);
  1366. attr->config = iocfc->cfg;
  1367. }
  1368. bfa_status_t
  1369. bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
  1370. {
  1371. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1372. struct bfi_iocfc_set_intr_req_s *m;
  1373. iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
  1374. iocfc->cfginfo->intr_attr.delay = cpu_to_be16(attr->delay);
  1375. iocfc->cfginfo->intr_attr.latency = cpu_to_be16(attr->latency);
  1376. if (!bfa_iocfc_is_operational(bfa))
  1377. return BFA_STATUS_OK;
  1378. m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
  1379. if (!m)
  1380. return BFA_STATUS_DEVBUSY;
  1381. bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
  1382. bfa_fn_lpu(bfa));
  1383. m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
  1384. m->delay = iocfc->cfginfo->intr_attr.delay;
  1385. m->latency = iocfc->cfginfo->intr_attr.latency;
  1386. bfa_trc(bfa, attr->delay);
  1387. bfa_trc(bfa, attr->latency);
  1388. bfa_reqq_produce(bfa, BFA_REQQ_IOC, m->mh);
  1389. return BFA_STATUS_OK;
  1390. }
  1391. void
  1392. bfa_iocfc_set_snsbase(struct bfa_s *bfa, int seg_no, u64 snsbase_pa)
  1393. {
  1394. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1395. iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
  1396. bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase[seg_no], snsbase_pa);
  1397. }
  1398. /*
  1399. * Enable IOC after it is disabled.
  1400. */
  1401. void
  1402. bfa_iocfc_enable(struct bfa_s *bfa)
  1403. {
  1404. bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
  1405. "IOC Enable");
  1406. bfa->iocfc.cb_reqd = BFA_TRUE;
  1407. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_ENABLE);
  1408. }
  1409. void
  1410. bfa_iocfc_disable(struct bfa_s *bfa)
  1411. {
  1412. bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
  1413. "IOC Disable");
  1414. bfa->queue_process = BFA_FALSE;
  1415. bfa_fsm_send_event(&bfa->iocfc, IOCFC_E_DISABLE);
  1416. }
  1417. bfa_boolean_t
  1418. bfa_iocfc_is_operational(struct bfa_s *bfa)
  1419. {
  1420. return bfa_ioc_is_operational(&bfa->ioc) &&
  1421. bfa_fsm_cmp_state(&bfa->iocfc, bfa_iocfc_sm_operational);
  1422. }
  1423. /*
  1424. * Return boot target port wwns -- read from boot information in flash.
  1425. */
  1426. void
  1427. bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
  1428. {
  1429. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1430. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  1431. int i;
  1432. if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
  1433. bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
  1434. *nwwns = cfgrsp->pbc_cfg.nbluns;
  1435. for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
  1436. wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
  1437. return;
  1438. }
  1439. *nwwns = cfgrsp->bootwwns.nwwns;
  1440. memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
  1441. }
  1442. int
  1443. bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
  1444. {
  1445. struct bfa_iocfc_s *iocfc = &bfa->iocfc;
  1446. struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
  1447. memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
  1448. return cfgrsp->pbc_cfg.nvports;
  1449. }
  1450. /*
  1451. * Use this function query the memory requirement of the BFA library.
  1452. * This function needs to be called before bfa_attach() to get the
  1453. * memory required of the BFA layer for a given driver configuration.
  1454. *
  1455. * This call will fail, if the cap is out of range compared to pre-defined
  1456. * values within the BFA library
  1457. *
  1458. * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
  1459. * its configuration in this structure.
  1460. * The default values for struct bfa_iocfc_cfg_s can be
  1461. * fetched using bfa_cfg_get_default() API.
  1462. *
  1463. * If cap's boundary check fails, the library will use
  1464. * the default bfa_cap_t values (and log a warning msg).
  1465. *
  1466. * @param[out] meminfo - pointer to bfa_meminfo_t. This content
  1467. * indicates the memory type (see bfa_mem_type_t) and
  1468. * amount of memory required.
  1469. *
  1470. * Driver should allocate the memory, populate the
  1471. * starting address for each block and provide the same
  1472. * structure as input parameter to bfa_attach() call.
  1473. *
  1474. * @param[in] bfa - pointer to the bfa structure, used while fetching the
  1475. * dma, kva memory information of the bfa sub-modules.
  1476. *
  1477. * @return void
  1478. *
  1479. * Special Considerations: @note
  1480. */
  1481. void
  1482. bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo,
  1483. struct bfa_s *bfa)
  1484. {
  1485. int i;
  1486. struct bfa_mem_dma_s *port_dma = BFA_MEM_PORT_DMA(bfa);
  1487. struct bfa_mem_dma_s *ablk_dma = BFA_MEM_ABLK_DMA(bfa);
  1488. struct bfa_mem_dma_s *cee_dma = BFA_MEM_CEE_DMA(bfa);
  1489. struct bfa_mem_dma_s *sfp_dma = BFA_MEM_SFP_DMA(bfa);
  1490. struct bfa_mem_dma_s *flash_dma = BFA_MEM_FLASH_DMA(bfa);
  1491. struct bfa_mem_dma_s *diag_dma = BFA_MEM_DIAG_DMA(bfa);
  1492. struct bfa_mem_dma_s *phy_dma = BFA_MEM_PHY_DMA(bfa);
  1493. WARN_ON((cfg == NULL) || (meminfo == NULL));
  1494. memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
  1495. /* Initialize the DMA & KVA meminfo queues */
  1496. INIT_LIST_HEAD(&meminfo->dma_info.qe);
  1497. INIT_LIST_HEAD(&meminfo->kva_info.qe);
  1498. bfa_iocfc_meminfo(cfg, meminfo, bfa);
  1499. for (i = 0; hal_mods[i]; i++)
  1500. hal_mods[i]->meminfo(cfg, meminfo, bfa);
  1501. /* dma info setup */
  1502. bfa_mem_dma_setup(meminfo, port_dma, bfa_port_meminfo());
  1503. bfa_mem_dma_setup(meminfo, ablk_dma, bfa_ablk_meminfo());
  1504. bfa_mem_dma_setup(meminfo, cee_dma, bfa_cee_meminfo());
  1505. bfa_mem_dma_setup(meminfo, sfp_dma, bfa_sfp_meminfo());
  1506. bfa_mem_dma_setup(meminfo, flash_dma,
  1507. bfa_flash_meminfo(cfg->drvcfg.min_cfg));
  1508. bfa_mem_dma_setup(meminfo, diag_dma, bfa_diag_meminfo());
  1509. bfa_mem_dma_setup(meminfo, phy_dma,
  1510. bfa_phy_meminfo(cfg->drvcfg.min_cfg));
  1511. }
  1512. /*
  1513. * Use this function to do attach the driver instance with the BFA
  1514. * library. This function will not trigger any HW initialization
  1515. * process (which will be done in bfa_init() call)
  1516. *
  1517. * This call will fail, if the cap is out of range compared to
  1518. * pre-defined values within the BFA library
  1519. *
  1520. * @param[out] bfa Pointer to bfa_t.
  1521. * @param[in] bfad Opaque handle back to the driver's IOC structure
  1522. * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
  1523. * that was used in bfa_cfg_get_meminfo().
  1524. * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
  1525. * use the bfa_cfg_get_meminfo() call to
  1526. * find the memory blocks required, allocate the
  1527. * required memory and provide the starting addresses.
  1528. * @param[in] pcidev pointer to struct bfa_pcidev_s
  1529. *
  1530. * @return
  1531. * void
  1532. *
  1533. * Special Considerations:
  1534. *
  1535. * @note
  1536. *
  1537. */
  1538. void
  1539. bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  1540. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  1541. {
  1542. int i;
  1543. struct bfa_mem_dma_s *dma_info, *dma_elem;
  1544. struct bfa_mem_kva_s *kva_info, *kva_elem;
  1545. struct list_head *dm_qe, *km_qe;
  1546. bfa->fcs = BFA_FALSE;
  1547. WARN_ON((cfg == NULL) || (meminfo == NULL));
  1548. /* Initialize memory pointers for iterative allocation */
  1549. dma_info = &meminfo->dma_info;
  1550. dma_info->kva_curp = dma_info->kva;
  1551. dma_info->dma_curp = dma_info->dma;
  1552. kva_info = &meminfo->kva_info;
  1553. kva_info->kva_curp = kva_info->kva;
  1554. list_for_each(dm_qe, &dma_info->qe) {
  1555. dma_elem = (struct bfa_mem_dma_s *) dm_qe;
  1556. dma_elem->kva_curp = dma_elem->kva;
  1557. dma_elem->dma_curp = dma_elem->dma;
  1558. }
  1559. list_for_each(km_qe, &kva_info->qe) {
  1560. kva_elem = (struct bfa_mem_kva_s *) km_qe;
  1561. kva_elem->kva_curp = kva_elem->kva;
  1562. }
  1563. bfa_iocfc_attach(bfa, bfad, cfg, pcidev);
  1564. for (i = 0; hal_mods[i]; i++)
  1565. hal_mods[i]->attach(bfa, bfad, cfg, pcidev);
  1566. bfa_com_port_attach(bfa);
  1567. bfa_com_ablk_attach(bfa);
  1568. bfa_com_cee_attach(bfa);
  1569. bfa_com_sfp_attach(bfa);
  1570. bfa_com_flash_attach(bfa, cfg->drvcfg.min_cfg);
  1571. bfa_com_diag_attach(bfa);
  1572. bfa_com_phy_attach(bfa, cfg->drvcfg.min_cfg);
  1573. }
  1574. /*
  1575. * Use this function to delete a BFA IOC. IOC should be stopped (by
  1576. * calling bfa_stop()) before this function call.
  1577. *
  1578. * @param[in] bfa - pointer to bfa_t.
  1579. *
  1580. * @return
  1581. * void
  1582. *
  1583. * Special Considerations:
  1584. *
  1585. * @note
  1586. */
  1587. void
  1588. bfa_detach(struct bfa_s *bfa)
  1589. {
  1590. int i;
  1591. for (i = 0; hal_mods[i]; i++)
  1592. hal_mods[i]->detach(bfa);
  1593. bfa_ioc_detach(&bfa->ioc);
  1594. }
  1595. void
  1596. bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
  1597. {
  1598. INIT_LIST_HEAD(comp_q);
  1599. list_splice_tail_init(&bfa->comp_q, comp_q);
  1600. }
  1601. void
  1602. bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
  1603. {
  1604. struct list_head *qe;
  1605. struct list_head *qen;
  1606. struct bfa_cb_qe_s *hcb_qe;
  1607. bfa_cb_cbfn_status_t cbfn;
  1608. list_for_each_safe(qe, qen, comp_q) {
  1609. hcb_qe = (struct bfa_cb_qe_s *) qe;
  1610. if (hcb_qe->pre_rmv) {
  1611. /* qe is invalid after return, dequeue before cbfn() */
  1612. list_del(qe);
  1613. cbfn = (bfa_cb_cbfn_status_t)(hcb_qe->cbfn);
  1614. cbfn(hcb_qe->cbarg, hcb_qe->fw_status);
  1615. } else
  1616. hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
  1617. }
  1618. }
  1619. void
  1620. bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
  1621. {
  1622. struct list_head *qe;
  1623. struct bfa_cb_qe_s *hcb_qe;
  1624. while (!list_empty(comp_q)) {
  1625. bfa_q_deq(comp_q, &qe);
  1626. hcb_qe = (struct bfa_cb_qe_s *) qe;
  1627. WARN_ON(hcb_qe->pre_rmv);
  1628. hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
  1629. }
  1630. }
  1631. /*
  1632. * Return the list of PCI vendor/device id lists supported by this
  1633. * BFA instance.
  1634. */
  1635. void
  1636. bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
  1637. {
  1638. static struct bfa_pciid_s __pciids[] = {
  1639. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
  1640. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
  1641. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
  1642. {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
  1643. };
  1644. *npciids = sizeof(__pciids) / sizeof(__pciids[0]);
  1645. *pciids = __pciids;
  1646. }
  1647. /*
  1648. * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
  1649. * into BFA layer). The OS driver can then turn back and overwrite entries that
  1650. * have been configured by the user.
  1651. *
  1652. * @param[in] cfg - pointer to bfa_ioc_cfg_t
  1653. *
  1654. * @return
  1655. * void
  1656. *
  1657. * Special Considerations:
  1658. * note
  1659. */
  1660. void
  1661. bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
  1662. {
  1663. cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
  1664. cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
  1665. cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
  1666. cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
  1667. cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
  1668. cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
  1669. cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
  1670. cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
  1671. cfg->fwcfg.num_fwtio_reqs = 0;
  1672. cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
  1673. cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
  1674. cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
  1675. cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
  1676. cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
  1677. cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
  1678. cfg->drvcfg.ioc_recover = BFA_FALSE;
  1679. cfg->drvcfg.delay_comp = BFA_FALSE;
  1680. }
  1681. void
  1682. bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
  1683. {
  1684. bfa_cfg_get_default(cfg);
  1685. cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
  1686. cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
  1687. cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
  1688. cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
  1689. cfg->fwcfg.num_rports = BFA_RPORT_MIN;
  1690. cfg->fwcfg.num_fwtio_reqs = 0;
  1691. cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
  1692. cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
  1693. cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
  1694. cfg->drvcfg.min_cfg = BFA_TRUE;
  1695. }