bfa_core.c 50 KB

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