bfa_core.c 51 KB

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