bfa_core.c 49 KB

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