bfa_core.c 50 KB

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