bfa_fcs.c 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736
  1. /*
  2. * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. /**
  18. * bfa_fcs.c BFA FCS main
  19. */
  20. #include "bfa_fcs.h"
  21. #include "bfa_fcbuild.h"
  22. #include "bfad_drv.h"
  23. BFA_TRC_FILE(FCS, FCS);
  24. /**
  25. * FCS sub-modules
  26. */
  27. struct bfa_fcs_mod_s {
  28. void (*attach) (struct bfa_fcs_s *fcs);
  29. void (*modinit) (struct bfa_fcs_s *fcs);
  30. void (*modexit) (struct bfa_fcs_s *fcs);
  31. };
  32. #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
  33. static struct bfa_fcs_mod_s fcs_modules[] = {
  34. { bfa_fcs_port_attach, NULL, NULL },
  35. { bfa_fcs_uf_attach, NULL, NULL },
  36. { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
  37. bfa_fcs_fabric_modexit },
  38. };
  39. /**
  40. * fcs_api BFA FCS API
  41. */
  42. static void
  43. bfa_fcs_exit_comp(void *fcs_cbarg)
  44. {
  45. struct bfa_fcs_s *fcs = fcs_cbarg;
  46. struct bfad_s *bfad = fcs->bfad;
  47. complete(&bfad->comp);
  48. }
  49. /**
  50. * fcs_api BFA FCS API
  51. */
  52. /**
  53. * fcs attach -- called once to initialize data structures at driver attach time
  54. */
  55. void
  56. bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad,
  57. bfa_boolean_t min_cfg)
  58. {
  59. int i;
  60. struct bfa_fcs_mod_s *mod;
  61. fcs->bfa = bfa;
  62. fcs->bfad = bfad;
  63. fcs->min_cfg = min_cfg;
  64. bfa_attach_fcs(bfa);
  65. fcbuild_init();
  66. for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
  67. mod = &fcs_modules[i];
  68. if (mod->attach)
  69. mod->attach(fcs);
  70. }
  71. }
  72. /**
  73. * fcs initialization, called once after bfa initialization is complete
  74. */
  75. void
  76. bfa_fcs_init(struct bfa_fcs_s *fcs)
  77. {
  78. int i, npbc_vports;
  79. struct bfa_fcs_mod_s *mod;
  80. struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS];
  81. for (i = 0; i < sizeof(fcs_modules) / sizeof(fcs_modules[0]); i++) {
  82. mod = &fcs_modules[i];
  83. if (mod->modinit)
  84. mod->modinit(fcs);
  85. }
  86. /* Initialize pbc vports */
  87. if (!fcs->min_cfg) {
  88. npbc_vports =
  89. bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports);
  90. for (i = 0; i < npbc_vports; i++)
  91. bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]);
  92. }
  93. }
  94. /**
  95. * Start FCS operations.
  96. */
  97. void
  98. bfa_fcs_start(struct bfa_fcs_s *fcs)
  99. {
  100. bfa_fcs_fabric_modstart(fcs);
  101. }
  102. /**
  103. * brief
  104. * FCS driver details initialization.
  105. *
  106. * param[in] fcs FCS instance
  107. * param[in] driver_info Driver Details
  108. *
  109. * return None
  110. */
  111. void
  112. bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs,
  113. struct bfa_fcs_driver_info_s *driver_info)
  114. {
  115. fcs->driver_info = *driver_info;
  116. bfa_fcs_fabric_psymb_init(&fcs->fabric);
  117. }
  118. /**
  119. * brief
  120. * FCS FDMI Driver Parameter Initialization
  121. *
  122. * param[in] fcs FCS instance
  123. * param[in] fdmi_enable TRUE/FALSE
  124. *
  125. * return None
  126. */
  127. void
  128. bfa_fcs_set_fdmi_param(struct bfa_fcs_s *fcs, bfa_boolean_t fdmi_enable)
  129. {
  130. fcs->fdmi_enabled = fdmi_enable;
  131. }
  132. /**
  133. * brief
  134. * FCS instance cleanup and exit.
  135. *
  136. * param[in] fcs FCS instance
  137. * return None
  138. */
  139. void
  140. bfa_fcs_exit(struct bfa_fcs_s *fcs)
  141. {
  142. struct bfa_fcs_mod_s *mod;
  143. int nmods, i;
  144. bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs);
  145. nmods = sizeof(fcs_modules) / sizeof(fcs_modules[0]);
  146. for (i = 0; i < nmods; i++) {
  147. mod = &fcs_modules[i];
  148. if (mod->modexit) {
  149. bfa_wc_up(&fcs->wc);
  150. mod->modexit(fcs);
  151. }
  152. }
  153. bfa_wc_wait(&fcs->wc);
  154. }
  155. void
  156. bfa_fcs_trc_init(struct bfa_fcs_s *fcs, struct bfa_trc_mod_s *trcmod)
  157. {
  158. fcs->trcmod = trcmod;
  159. }
  160. void
  161. bfa_fcs_modexit_comp(struct bfa_fcs_s *fcs)
  162. {
  163. bfa_wc_down(&fcs->wc);
  164. }
  165. /**
  166. * Fabric module implementation.
  167. */
  168. #define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
  169. #define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
  170. #define bfa_fcs_fabric_set_opertype(__fabric) do { \
  171. if (bfa_fcport_get_topology((__fabric)->fcs->bfa) \
  172. == BFA_PORT_TOPOLOGY_P2P) \
  173. (__fabric)->oper_type = BFA_PORT_TYPE_NPORT; \
  174. else \
  175. (__fabric)->oper_type = BFA_PORT_TYPE_NLPORT; \
  176. } while (0)
  177. /*
  178. * forward declarations
  179. */
  180. static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
  181. static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
  182. static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
  183. static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
  184. static void bfa_fcs_fabric_delay(void *cbarg);
  185. static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
  186. static void bfa_fcs_fabric_delete_comp(void *cbarg);
  187. static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
  188. struct fchs_s *fchs, u16 len);
  189. static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
  190. struct fchs_s *fchs, u16 len);
  191. static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
  192. static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
  193. struct bfa_fcxp_s *fcxp, void *cbarg,
  194. bfa_status_t status,
  195. u32 rsp_len,
  196. u32 resid_len,
  197. struct fchs_s *rspfchs);
  198. /**
  199. * fcs_fabric_sm fabric state machine functions
  200. */
  201. /**
  202. * Fabric state machine events
  203. */
  204. enum bfa_fcs_fabric_event {
  205. BFA_FCS_FABRIC_SM_CREATE = 1, /* create from driver */
  206. BFA_FCS_FABRIC_SM_DELETE = 2, /* delete from driver */
  207. BFA_FCS_FABRIC_SM_LINK_DOWN = 3, /* link down from port */
  208. BFA_FCS_FABRIC_SM_LINK_UP = 4, /* link up from port */
  209. BFA_FCS_FABRIC_SM_CONT_OP = 5, /* flogi/auth continue op */
  210. BFA_FCS_FABRIC_SM_RETRY_OP = 6, /* flogi/auth retry op */
  211. BFA_FCS_FABRIC_SM_NO_FABRIC = 7, /* from flogi/auth */
  212. BFA_FCS_FABRIC_SM_PERF_EVFP = 8, /* from flogi/auth */
  213. BFA_FCS_FABRIC_SM_ISOLATE = 9, /* from EVFP processing */
  214. BFA_FCS_FABRIC_SM_NO_TAGGING = 10, /* no VFT tagging from EVFP */
  215. BFA_FCS_FABRIC_SM_DELAYED = 11, /* timeout delay event */
  216. BFA_FCS_FABRIC_SM_AUTH_FAILED = 12, /* auth failed */
  217. BFA_FCS_FABRIC_SM_AUTH_SUCCESS = 13, /* auth successful */
  218. BFA_FCS_FABRIC_SM_DELCOMP = 14, /* all vports deleted event */
  219. BFA_FCS_FABRIC_SM_LOOPBACK = 15, /* Received our own FLOGI */
  220. BFA_FCS_FABRIC_SM_START = 16, /* from driver */
  221. };
  222. static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
  223. enum bfa_fcs_fabric_event event);
  224. static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
  225. enum bfa_fcs_fabric_event event);
  226. static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
  227. enum bfa_fcs_fabric_event event);
  228. static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
  229. enum bfa_fcs_fabric_event event);
  230. static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
  231. enum bfa_fcs_fabric_event event);
  232. static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
  233. enum bfa_fcs_fabric_event event);
  234. static void bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
  235. enum bfa_fcs_fabric_event event);
  236. static void bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
  237. enum bfa_fcs_fabric_event event);
  238. static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
  239. enum bfa_fcs_fabric_event event);
  240. static void bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
  241. enum bfa_fcs_fabric_event event);
  242. static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
  243. enum bfa_fcs_fabric_event event);
  244. static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
  245. enum bfa_fcs_fabric_event event);
  246. static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
  247. enum bfa_fcs_fabric_event event);
  248. static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
  249. enum bfa_fcs_fabric_event event);
  250. /**
  251. * Beginning state before fabric creation.
  252. */
  253. static void
  254. bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
  255. enum bfa_fcs_fabric_event event)
  256. {
  257. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  258. bfa_trc(fabric->fcs, event);
  259. switch (event) {
  260. case BFA_FCS_FABRIC_SM_CREATE:
  261. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
  262. bfa_fcs_fabric_init(fabric);
  263. bfa_fcs_lport_init(&fabric->bport, &fabric->bport.port_cfg);
  264. break;
  265. case BFA_FCS_FABRIC_SM_LINK_UP:
  266. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  267. break;
  268. default:
  269. bfa_sm_fault(fabric->fcs, event);
  270. }
  271. }
  272. /**
  273. * Beginning state before fabric creation.
  274. */
  275. static void
  276. bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
  277. enum bfa_fcs_fabric_event event)
  278. {
  279. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  280. bfa_trc(fabric->fcs, event);
  281. switch (event) {
  282. case BFA_FCS_FABRIC_SM_START:
  283. if (bfa_fcport_is_linkup(fabric->fcs->bfa)) {
  284. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
  285. bfa_fcs_fabric_login(fabric);
  286. } else
  287. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  288. break;
  289. case BFA_FCS_FABRIC_SM_LINK_UP:
  290. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  291. break;
  292. case BFA_FCS_FABRIC_SM_DELETE:
  293. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
  294. bfa_fcs_modexit_comp(fabric->fcs);
  295. break;
  296. default:
  297. bfa_sm_fault(fabric->fcs, event);
  298. }
  299. }
  300. /**
  301. * Link is down, awaiting LINK UP event from port. This is also the
  302. * first state at fabric creation.
  303. */
  304. static void
  305. bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
  306. enum bfa_fcs_fabric_event event)
  307. {
  308. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  309. bfa_trc(fabric->fcs, event);
  310. switch (event) {
  311. case BFA_FCS_FABRIC_SM_LINK_UP:
  312. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
  313. bfa_fcs_fabric_login(fabric);
  314. break;
  315. case BFA_FCS_FABRIC_SM_RETRY_OP:
  316. break;
  317. case BFA_FCS_FABRIC_SM_DELETE:
  318. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  319. bfa_fcs_fabric_delete(fabric);
  320. break;
  321. default:
  322. bfa_sm_fault(fabric->fcs, event);
  323. }
  324. }
  325. /**
  326. * FLOGI is in progress, awaiting FLOGI reply.
  327. */
  328. static void
  329. bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
  330. enum bfa_fcs_fabric_event event)
  331. {
  332. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  333. bfa_trc(fabric->fcs, event);
  334. switch (event) {
  335. case BFA_FCS_FABRIC_SM_CONT_OP:
  336. bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
  337. fabric->bb_credit);
  338. fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
  339. if (fabric->auth_reqd && fabric->is_auth) {
  340. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
  341. bfa_trc(fabric->fcs, event);
  342. } else {
  343. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
  344. bfa_fcs_fabric_notify_online(fabric);
  345. }
  346. break;
  347. case BFA_FCS_FABRIC_SM_RETRY_OP:
  348. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
  349. bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
  350. bfa_fcs_fabric_delay, fabric,
  351. BFA_FCS_FABRIC_RETRY_DELAY);
  352. break;
  353. case BFA_FCS_FABRIC_SM_LOOPBACK:
  354. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
  355. bfa_lps_discard(fabric->lps);
  356. bfa_fcs_fabric_set_opertype(fabric);
  357. break;
  358. case BFA_FCS_FABRIC_SM_NO_FABRIC:
  359. fabric->fab_type = BFA_FCS_FABRIC_N2N;
  360. bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
  361. fabric->bb_credit);
  362. bfa_fcs_fabric_notify_online(fabric);
  363. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
  364. break;
  365. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  366. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  367. bfa_lps_discard(fabric->lps);
  368. break;
  369. case BFA_FCS_FABRIC_SM_DELETE:
  370. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  371. bfa_lps_discard(fabric->lps);
  372. bfa_fcs_fabric_delete(fabric);
  373. break;
  374. default:
  375. bfa_sm_fault(fabric->fcs, event);
  376. }
  377. }
  378. static void
  379. bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
  380. enum bfa_fcs_fabric_event event)
  381. {
  382. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  383. bfa_trc(fabric->fcs, event);
  384. switch (event) {
  385. case BFA_FCS_FABRIC_SM_DELAYED:
  386. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
  387. bfa_fcs_fabric_login(fabric);
  388. break;
  389. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  390. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  391. bfa_timer_stop(&fabric->delay_timer);
  392. break;
  393. case BFA_FCS_FABRIC_SM_DELETE:
  394. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  395. bfa_timer_stop(&fabric->delay_timer);
  396. bfa_fcs_fabric_delete(fabric);
  397. break;
  398. default:
  399. bfa_sm_fault(fabric->fcs, event);
  400. }
  401. }
  402. /**
  403. * Authentication is in progress, awaiting authentication results.
  404. */
  405. static void
  406. bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
  407. enum bfa_fcs_fabric_event event)
  408. {
  409. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  410. bfa_trc(fabric->fcs, event);
  411. switch (event) {
  412. case BFA_FCS_FABRIC_SM_AUTH_FAILED:
  413. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
  414. bfa_lps_discard(fabric->lps);
  415. break;
  416. case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
  417. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
  418. bfa_fcs_fabric_notify_online(fabric);
  419. break;
  420. case BFA_FCS_FABRIC_SM_PERF_EVFP:
  421. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
  422. break;
  423. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  424. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  425. bfa_lps_discard(fabric->lps);
  426. break;
  427. case BFA_FCS_FABRIC_SM_DELETE:
  428. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  429. bfa_fcs_fabric_delete(fabric);
  430. break;
  431. default:
  432. bfa_sm_fault(fabric->fcs, event);
  433. }
  434. }
  435. /**
  436. * Authentication failed
  437. */
  438. static void
  439. bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
  440. enum bfa_fcs_fabric_event event)
  441. {
  442. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  443. bfa_trc(fabric->fcs, event);
  444. switch (event) {
  445. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  446. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  447. bfa_fcs_fabric_notify_offline(fabric);
  448. break;
  449. case BFA_FCS_FABRIC_SM_DELETE:
  450. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  451. bfa_fcs_fabric_delete(fabric);
  452. break;
  453. default:
  454. bfa_sm_fault(fabric->fcs, event);
  455. }
  456. }
  457. /**
  458. * Port is in loopback mode.
  459. */
  460. static void
  461. bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
  462. enum bfa_fcs_fabric_event event)
  463. {
  464. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  465. bfa_trc(fabric->fcs, event);
  466. switch (event) {
  467. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  468. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  469. bfa_fcs_fabric_notify_offline(fabric);
  470. break;
  471. case BFA_FCS_FABRIC_SM_DELETE:
  472. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  473. bfa_fcs_fabric_delete(fabric);
  474. break;
  475. default:
  476. bfa_sm_fault(fabric->fcs, event);
  477. }
  478. }
  479. /**
  480. * There is no attached fabric - private loop or NPort-to-NPort topology.
  481. */
  482. static void
  483. bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
  484. enum bfa_fcs_fabric_event event)
  485. {
  486. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  487. bfa_trc(fabric->fcs, event);
  488. switch (event) {
  489. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  490. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  491. bfa_lps_discard(fabric->lps);
  492. bfa_fcs_fabric_notify_offline(fabric);
  493. break;
  494. case BFA_FCS_FABRIC_SM_DELETE:
  495. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  496. bfa_fcs_fabric_delete(fabric);
  497. break;
  498. case BFA_FCS_FABRIC_SM_NO_FABRIC:
  499. bfa_trc(fabric->fcs, fabric->bb_credit);
  500. bfa_fcport_set_tx_bbcredit(fabric->fcs->bfa,
  501. fabric->bb_credit);
  502. break;
  503. default:
  504. bfa_sm_fault(fabric->fcs, event);
  505. }
  506. }
  507. /**
  508. * Fabric is online - normal operating state.
  509. */
  510. static void
  511. bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
  512. enum bfa_fcs_fabric_event event)
  513. {
  514. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  515. bfa_trc(fabric->fcs, event);
  516. switch (event) {
  517. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  518. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  519. bfa_lps_discard(fabric->lps);
  520. bfa_fcs_fabric_notify_offline(fabric);
  521. break;
  522. case BFA_FCS_FABRIC_SM_DELETE:
  523. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  524. bfa_fcs_fabric_delete(fabric);
  525. break;
  526. case BFA_FCS_FABRIC_SM_AUTH_FAILED:
  527. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
  528. bfa_lps_discard(fabric->lps);
  529. break;
  530. case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
  531. break;
  532. default:
  533. bfa_sm_fault(fabric->fcs, event);
  534. }
  535. }
  536. /**
  537. * Exchanging virtual fabric parameters.
  538. */
  539. static void
  540. bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
  541. enum bfa_fcs_fabric_event event)
  542. {
  543. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  544. bfa_trc(fabric->fcs, event);
  545. switch (event) {
  546. case BFA_FCS_FABRIC_SM_CONT_OP:
  547. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
  548. break;
  549. case BFA_FCS_FABRIC_SM_ISOLATE:
  550. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
  551. break;
  552. default:
  553. bfa_sm_fault(fabric->fcs, event);
  554. }
  555. }
  556. /**
  557. * EVFP exchange complete and VFT tagging is enabled.
  558. */
  559. static void
  560. bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
  561. enum bfa_fcs_fabric_event event)
  562. {
  563. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  564. bfa_trc(fabric->fcs, event);
  565. }
  566. /**
  567. * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
  568. */
  569. static void
  570. bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
  571. enum bfa_fcs_fabric_event event)
  572. {
  573. struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
  574. char pwwn_ptr[BFA_STRING_32];
  575. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  576. bfa_trc(fabric->fcs, event);
  577. wwn2str(pwwn_ptr, fabric->bport.port_cfg.pwwn);
  578. BFA_LOG(KERN_INFO, bfad, log_level,
  579. "Port is isolated due to VF_ID mismatch. "
  580. "PWWN: %s Port VF_ID: %04x switch port VF_ID: %04x.",
  581. pwwn_ptr, fabric->fcs->port_vfid,
  582. fabric->event_arg.swp_vfid);
  583. }
  584. /**
  585. * Fabric is being deleted, awaiting vport delete completions.
  586. */
  587. static void
  588. bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
  589. enum bfa_fcs_fabric_event event)
  590. {
  591. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  592. bfa_trc(fabric->fcs, event);
  593. switch (event) {
  594. case BFA_FCS_FABRIC_SM_DELCOMP:
  595. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
  596. bfa_fcs_modexit_comp(fabric->fcs);
  597. break;
  598. case BFA_FCS_FABRIC_SM_LINK_UP:
  599. break;
  600. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  601. bfa_fcs_fabric_notify_offline(fabric);
  602. break;
  603. default:
  604. bfa_sm_fault(fabric->fcs, event);
  605. }
  606. }
  607. /**
  608. * fcs_fabric_private fabric private functions
  609. */
  610. static void
  611. bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
  612. {
  613. struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
  614. port_cfg->roles = BFA_LPORT_ROLE_FCP_IM;
  615. port_cfg->nwwn = bfa_ioc_get_nwwn(&fabric->fcs->bfa->ioc);
  616. port_cfg->pwwn = bfa_ioc_get_pwwn(&fabric->fcs->bfa->ioc);
  617. }
  618. /**
  619. * Port Symbolic Name Creation for base port.
  620. */
  621. void
  622. bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
  623. {
  624. struct bfa_lport_cfg_s *port_cfg = &fabric->bport.port_cfg;
  625. char model[BFA_ADAPTER_MODEL_NAME_LEN] = {0};
  626. struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
  627. bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
  628. /* Model name/number */
  629. strncpy((char *)&port_cfg->sym_name, model,
  630. BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
  631. strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  632. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  633. /* Driver Version */
  634. strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
  635. BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
  636. strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  637. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  638. /* Host machine name */
  639. strncat((char *)&port_cfg->sym_name,
  640. (char *)driver_info->host_machine_name,
  641. BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
  642. strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  643. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  644. /*
  645. * Host OS Info :
  646. * If OS Patch Info is not there, do not truncate any bytes from the
  647. * OS name string and instead copy the entire OS info string (64 bytes).
  648. */
  649. if (driver_info->host_os_patch[0] == '\0') {
  650. strncat((char *)&port_cfg->sym_name,
  651. (char *)driver_info->host_os_name,
  652. BFA_FCS_OS_STR_LEN);
  653. strncat((char *)&port_cfg->sym_name,
  654. BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  655. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  656. } else {
  657. strncat((char *)&port_cfg->sym_name,
  658. (char *)driver_info->host_os_name,
  659. BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
  660. strncat((char *)&port_cfg->sym_name,
  661. BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  662. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  663. /* Append host OS Patch Info */
  664. strncat((char *)&port_cfg->sym_name,
  665. (char *)driver_info->host_os_patch,
  666. BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
  667. }
  668. /* null terminate */
  669. port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
  670. }
  671. /**
  672. * bfa lps login completion callback
  673. */
  674. void
  675. bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
  676. {
  677. struct bfa_fcs_fabric_s *fabric = uarg;
  678. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  679. bfa_trc(fabric->fcs, status);
  680. switch (status) {
  681. case BFA_STATUS_OK:
  682. fabric->stats.flogi_accepts++;
  683. break;
  684. case BFA_STATUS_INVALID_MAC:
  685. /* Only for CNA */
  686. fabric->stats.flogi_acc_err++;
  687. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  688. return;
  689. case BFA_STATUS_EPROTOCOL:
  690. switch (bfa_lps_get_extstatus(fabric->lps)) {
  691. case BFA_EPROTO_BAD_ACCEPT:
  692. fabric->stats.flogi_acc_err++;
  693. break;
  694. case BFA_EPROTO_UNKNOWN_RSP:
  695. fabric->stats.flogi_unknown_rsp++;
  696. break;
  697. default:
  698. break;
  699. }
  700. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  701. return;
  702. case BFA_STATUS_FABRIC_RJT:
  703. fabric->stats.flogi_rejects++;
  704. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  705. return;
  706. default:
  707. fabric->stats.flogi_rsp_err++;
  708. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  709. return;
  710. }
  711. fabric->bb_credit = bfa_lps_get_peer_bbcredit(fabric->lps);
  712. bfa_trc(fabric->fcs, fabric->bb_credit);
  713. if (!bfa_lps_is_brcd_fabric(fabric->lps))
  714. fabric->fabric_name = bfa_lps_get_peer_nwwn(fabric->lps);
  715. /*
  716. * Check port type. It should be 1 = F-port.
  717. */
  718. if (bfa_lps_is_fport(fabric->lps)) {
  719. fabric->bport.pid = bfa_lps_get_pid(fabric->lps);
  720. fabric->is_npiv = bfa_lps_is_npiv_en(fabric->lps);
  721. fabric->is_auth = bfa_lps_is_authreq(fabric->lps);
  722. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
  723. } else {
  724. /*
  725. * Nport-2-Nport direct attached
  726. */
  727. fabric->bport.port_topo.pn2n.rem_port_wwn =
  728. bfa_lps_get_peer_pwwn(fabric->lps);
  729. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
  730. }
  731. bfa_trc(fabric->fcs, fabric->bport.pid);
  732. bfa_trc(fabric->fcs, fabric->is_npiv);
  733. bfa_trc(fabric->fcs, fabric->is_auth);
  734. }
  735. /**
  736. * Allocate and send FLOGI.
  737. */
  738. static void
  739. bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
  740. {
  741. struct bfa_s *bfa = fabric->fcs->bfa;
  742. struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
  743. u8 alpa = 0;
  744. if (bfa_fcport_get_topology(bfa) == BFA_PORT_TOPOLOGY_LOOP)
  745. alpa = bfa_fcport_get_myalpa(bfa);
  746. bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_fcport_get_maxfrsize(bfa),
  747. pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
  748. fabric->stats.flogi_sent++;
  749. }
  750. static void
  751. bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
  752. {
  753. struct bfa_fcs_vport_s *vport;
  754. struct list_head *qe, *qen;
  755. bfa_trc(fabric->fcs, fabric->fabric_name);
  756. bfa_fcs_fabric_set_opertype(fabric);
  757. fabric->stats.fabric_onlines++;
  758. /**
  759. * notify online event to base and then virtual ports
  760. */
  761. bfa_fcs_lport_online(&fabric->bport);
  762. list_for_each_safe(qe, qen, &fabric->vport_q) {
  763. vport = (struct bfa_fcs_vport_s *) qe;
  764. bfa_fcs_vport_online(vport);
  765. }
  766. }
  767. static void
  768. bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
  769. {
  770. struct bfa_fcs_vport_s *vport;
  771. struct list_head *qe, *qen;
  772. bfa_trc(fabric->fcs, fabric->fabric_name);
  773. fabric->stats.fabric_offlines++;
  774. /**
  775. * notify offline event first to vports and then base port.
  776. */
  777. list_for_each_safe(qe, qen, &fabric->vport_q) {
  778. vport = (struct bfa_fcs_vport_s *) qe;
  779. bfa_fcs_vport_offline(vport);
  780. }
  781. bfa_fcs_lport_offline(&fabric->bport);
  782. fabric->fabric_name = 0;
  783. fabric->fabric_ip_addr[0] = 0;
  784. }
  785. static void
  786. bfa_fcs_fabric_delay(void *cbarg)
  787. {
  788. struct bfa_fcs_fabric_s *fabric = cbarg;
  789. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
  790. }
  791. /**
  792. * Delete all vports and wait for vport delete completions.
  793. */
  794. static void
  795. bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
  796. {
  797. struct bfa_fcs_vport_s *vport;
  798. struct list_head *qe, *qen;
  799. list_for_each_safe(qe, qen, &fabric->vport_q) {
  800. vport = (struct bfa_fcs_vport_s *) qe;
  801. bfa_fcs_vport_fcs_delete(vport);
  802. }
  803. bfa_fcs_lport_delete(&fabric->bport);
  804. bfa_wc_wait(&fabric->wc);
  805. }
  806. static void
  807. bfa_fcs_fabric_delete_comp(void *cbarg)
  808. {
  809. struct bfa_fcs_fabric_s *fabric = cbarg;
  810. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
  811. }
  812. /**
  813. * fcs_fabric_public fabric public functions
  814. */
  815. /**
  816. * Attach time initialization.
  817. */
  818. void
  819. bfa_fcs_fabric_attach(struct bfa_fcs_s *fcs)
  820. {
  821. struct bfa_fcs_fabric_s *fabric;
  822. fabric = &fcs->fabric;
  823. bfa_os_memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
  824. /**
  825. * Initialize base fabric.
  826. */
  827. fabric->fcs = fcs;
  828. INIT_LIST_HEAD(&fabric->vport_q);
  829. INIT_LIST_HEAD(&fabric->vf_q);
  830. fabric->lps = bfa_lps_alloc(fcs->bfa);
  831. bfa_assert(fabric->lps);
  832. /**
  833. * Initialize fabric delete completion handler. Fabric deletion is
  834. * complete when the last vport delete is complete.
  835. */
  836. bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
  837. bfa_wc_up(&fabric->wc); /* For the base port */
  838. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
  839. bfa_fcs_lport_attach(&fabric->bport, fabric->fcs, FC_VF_ID_NULL, NULL);
  840. }
  841. void
  842. bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
  843. {
  844. bfa_sm_send_event(&fcs->fabric, BFA_FCS_FABRIC_SM_CREATE);
  845. bfa_trc(fcs, 0);
  846. }
  847. /**
  848. * Module cleanup
  849. */
  850. void
  851. bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
  852. {
  853. struct bfa_fcs_fabric_s *fabric;
  854. bfa_trc(fcs, 0);
  855. /**
  856. * Cleanup base fabric.
  857. */
  858. fabric = &fcs->fabric;
  859. bfa_lps_delete(fabric->lps);
  860. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
  861. }
  862. /**
  863. * Fabric module start -- kick starts FCS actions
  864. */
  865. void
  866. bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
  867. {
  868. struct bfa_fcs_fabric_s *fabric;
  869. bfa_trc(fcs, 0);
  870. fabric = &fcs->fabric;
  871. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
  872. }
  873. /**
  874. * Suspend fabric activity as part of driver suspend.
  875. */
  876. void
  877. bfa_fcs_fabric_modsusp(struct bfa_fcs_s *fcs)
  878. {
  879. }
  880. bfa_boolean_t
  881. bfa_fcs_fabric_is_loopback(struct bfa_fcs_fabric_s *fabric)
  882. {
  883. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_loopback);
  884. }
  885. bfa_boolean_t
  886. bfa_fcs_fabric_is_auth_failed(struct bfa_fcs_fabric_s *fabric)
  887. {
  888. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_auth_failed);
  889. }
  890. enum bfa_port_type
  891. bfa_fcs_fabric_port_type(struct bfa_fcs_fabric_s *fabric)
  892. {
  893. return fabric->oper_type;
  894. }
  895. /**
  896. * Link up notification from BFA physical port module.
  897. */
  898. void
  899. bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
  900. {
  901. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  902. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
  903. }
  904. /**
  905. * Link down notification from BFA physical port module.
  906. */
  907. void
  908. bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
  909. {
  910. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  911. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
  912. }
  913. /**
  914. * A child vport is being created in the fabric.
  915. *
  916. * Call from vport module at vport creation. A list of base port and vports
  917. * belonging to a fabric is maintained to propagate link events.
  918. *
  919. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  920. * param[in] vport - Vport being created.
  921. *
  922. * @return None (always succeeds)
  923. */
  924. void
  925. bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
  926. struct bfa_fcs_vport_s *vport)
  927. {
  928. /**
  929. * - add vport to fabric's vport_q
  930. */
  931. bfa_trc(fabric->fcs, fabric->vf_id);
  932. list_add_tail(&vport->qe, &fabric->vport_q);
  933. fabric->num_vports++;
  934. bfa_wc_up(&fabric->wc);
  935. }
  936. /**
  937. * A child vport is being deleted from fabric.
  938. *
  939. * Vport is being deleted.
  940. */
  941. void
  942. bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
  943. struct bfa_fcs_vport_s *vport)
  944. {
  945. list_del(&vport->qe);
  946. fabric->num_vports--;
  947. bfa_wc_down(&fabric->wc);
  948. }
  949. /**
  950. * Base port is deleted.
  951. */
  952. void
  953. bfa_fcs_fabric_port_delete_comp(struct bfa_fcs_fabric_s *fabric)
  954. {
  955. bfa_wc_down(&fabric->wc);
  956. }
  957. /**
  958. * Check if fabric is online.
  959. *
  960. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  961. *
  962. * @return TRUE/FALSE
  963. */
  964. int
  965. bfa_fcs_fabric_is_online(struct bfa_fcs_fabric_s *fabric)
  966. {
  967. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_online);
  968. }
  969. /**
  970. * brief
  971. *
  972. */
  973. bfa_status_t
  974. bfa_fcs_fabric_addvf(struct bfa_fcs_fabric_s *vf, struct bfa_fcs_s *fcs,
  975. struct bfa_lport_cfg_s *port_cfg, struct bfad_vf_s *vf_drv)
  976. {
  977. bfa_sm_set_state(vf, bfa_fcs_fabric_sm_uninit);
  978. return BFA_STATUS_OK;
  979. }
  980. /**
  981. * Lookup for a vport withing a fabric given its pwwn
  982. */
  983. struct bfa_fcs_vport_s *
  984. bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
  985. {
  986. struct bfa_fcs_vport_s *vport;
  987. struct list_head *qe;
  988. list_for_each(qe, &fabric->vport_q) {
  989. vport = (struct bfa_fcs_vport_s *) qe;
  990. if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
  991. return vport;
  992. }
  993. return NULL;
  994. }
  995. /**
  996. * In a given fabric, return the number of lports.
  997. *
  998. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  999. *
  1000. * @return : 1 or more.
  1001. */
  1002. u16
  1003. bfa_fcs_fabric_vport_count(struct bfa_fcs_fabric_s *fabric)
  1004. {
  1005. return fabric->num_vports;
  1006. }
  1007. /*
  1008. * Get OUI of the attached switch.
  1009. *
  1010. * Note : Use of this function should be avoided as much as possible.
  1011. * This function should be used only if there is any requirement
  1012. * to check for FOS version below 6.3.
  1013. * To check if the attached fabric is a brocade fabric, use
  1014. * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
  1015. * or above only.
  1016. */
  1017. u16
  1018. bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
  1019. {
  1020. wwn_t fab_nwwn;
  1021. u8 *tmp;
  1022. u16 oui;
  1023. fab_nwwn = bfa_lps_get_peer_nwwn(fabric->lps);
  1024. tmp = (u8 *)&fab_nwwn;
  1025. oui = (tmp[3] << 8) | tmp[4];
  1026. return oui;
  1027. }
  1028. /**
  1029. * Unsolicited frame receive handling.
  1030. */
  1031. void
  1032. bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
  1033. u16 len)
  1034. {
  1035. u32 pid = fchs->d_id;
  1036. struct bfa_fcs_vport_s *vport;
  1037. struct list_head *qe;
  1038. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  1039. struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
  1040. bfa_trc(fabric->fcs, len);
  1041. bfa_trc(fabric->fcs, pid);
  1042. /**
  1043. * Look for our own FLOGI frames being looped back. This means an
  1044. * external loopback cable is in place. Our own FLOGI frames are
  1045. * sometimes looped back when switch port gets temporarily bypassed.
  1046. */
  1047. if ((pid == bfa_os_ntoh3b(FC_FABRIC_PORT)) &&
  1048. (els_cmd->els_code == FC_ELS_FLOGI) &&
  1049. (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
  1050. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
  1051. return;
  1052. }
  1053. /**
  1054. * FLOGI/EVFP exchanges should be consumed by base fabric.
  1055. */
  1056. if (fchs->d_id == bfa_os_hton3b(FC_FABRIC_PORT)) {
  1057. bfa_trc(fabric->fcs, pid);
  1058. bfa_fcs_fabric_process_uf(fabric, fchs, len);
  1059. return;
  1060. }
  1061. if (fabric->bport.pid == pid) {
  1062. /**
  1063. * All authentication frames should be routed to auth
  1064. */
  1065. bfa_trc(fabric->fcs, els_cmd->els_code);
  1066. if (els_cmd->els_code == FC_ELS_AUTH) {
  1067. bfa_trc(fabric->fcs, els_cmd->els_code);
  1068. return;
  1069. }
  1070. bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
  1071. bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
  1072. return;
  1073. }
  1074. /**
  1075. * look for a matching local port ID
  1076. */
  1077. list_for_each(qe, &fabric->vport_q) {
  1078. vport = (struct bfa_fcs_vport_s *) qe;
  1079. if (vport->lport.pid == pid) {
  1080. bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
  1081. return;
  1082. }
  1083. }
  1084. bfa_trc(fabric->fcs, els_cmd->els_code);
  1085. bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
  1086. }
  1087. /**
  1088. * Unsolicited frames to be processed by fabric.
  1089. */
  1090. static void
  1091. bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
  1092. u16 len)
  1093. {
  1094. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  1095. bfa_trc(fabric->fcs, els_cmd->els_code);
  1096. switch (els_cmd->els_code) {
  1097. case FC_ELS_FLOGI:
  1098. bfa_fcs_fabric_process_flogi(fabric, fchs, len);
  1099. break;
  1100. default:
  1101. /*
  1102. * need to generate a LS_RJT
  1103. */
  1104. break;
  1105. }
  1106. }
  1107. /**
  1108. * Process incoming FLOGI
  1109. */
  1110. static void
  1111. bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
  1112. struct fchs_s *fchs, u16 len)
  1113. {
  1114. struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
  1115. struct bfa_fcs_lport_s *bport = &fabric->bport;
  1116. bfa_trc(fabric->fcs, fchs->s_id);
  1117. fabric->stats.flogi_rcvd++;
  1118. /*
  1119. * Check port type. It should be 0 = n-port.
  1120. */
  1121. if (flogi->csp.port_type) {
  1122. /*
  1123. * @todo: may need to send a LS_RJT
  1124. */
  1125. bfa_trc(fabric->fcs, flogi->port_name);
  1126. fabric->stats.flogi_rejected++;
  1127. return;
  1128. }
  1129. fabric->bb_credit = bfa_os_ntohs(flogi->csp.bbcred);
  1130. bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
  1131. bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
  1132. /*
  1133. * Send a Flogi Acc
  1134. */
  1135. bfa_fcs_fabric_send_flogi_acc(fabric);
  1136. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
  1137. }
  1138. static void
  1139. bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
  1140. {
  1141. struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
  1142. struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
  1143. struct bfa_s *bfa = fabric->fcs->bfa;
  1144. struct bfa_fcxp_s *fcxp;
  1145. u16 reqlen;
  1146. struct fchs_s fchs;
  1147. fcxp = bfa_fcs_fcxp_alloc(fabric->fcs);
  1148. /**
  1149. * Do not expect this failure -- expect remote node to retry
  1150. */
  1151. if (!fcxp)
  1152. return;
  1153. reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1154. bfa_os_hton3b(FC_FABRIC_PORT),
  1155. n2n_port->reply_oxid, pcfg->pwwn,
  1156. pcfg->nwwn,
  1157. bfa_fcport_get_maxfrsize(bfa),
  1158. bfa_fcport_get_rx_bbcredit(bfa));
  1159. bfa_fcxp_send(fcxp, NULL, fabric->vf_id, bfa_lps_get_tag(fabric->lps),
  1160. BFA_FALSE, FC_CLASS_3,
  1161. reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
  1162. FC_MAX_PDUSZ, 0);
  1163. }
  1164. /**
  1165. * Flogi Acc completion callback.
  1166. */
  1167. static void
  1168. bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1169. bfa_status_t status, u32 rsp_len,
  1170. u32 resid_len, struct fchs_s *rspfchs)
  1171. {
  1172. struct bfa_fcs_fabric_s *fabric = cbarg;
  1173. bfa_trc(fabric->fcs, status);
  1174. }
  1175. /*
  1176. *
  1177. * @param[in] fabric - fabric
  1178. * @param[in] wwn_t - new fabric name
  1179. *
  1180. * @return - none
  1181. */
  1182. void
  1183. bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
  1184. wwn_t fabric_name)
  1185. {
  1186. struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
  1187. char pwwn_ptr[BFA_STRING_32];
  1188. char fwwn_ptr[BFA_STRING_32];
  1189. bfa_trc(fabric->fcs, fabric_name);
  1190. if (fabric->fabric_name == 0) {
  1191. /*
  1192. * With BRCD switches, we don't get Fabric Name in FLOGI.
  1193. * Don't generate a fabric name change event in this case.
  1194. */
  1195. fabric->fabric_name = fabric_name;
  1196. } else {
  1197. fabric->fabric_name = fabric_name;
  1198. wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
  1199. wwn2str(fwwn_ptr,
  1200. bfa_fcs_lport_get_fabric_name(&fabric->bport));
  1201. BFA_LOG(KERN_WARNING, bfad, log_level,
  1202. "Base port WWN = %s Fabric WWN = %s\n",
  1203. pwwn_ptr, fwwn_ptr);
  1204. }
  1205. }
  1206. /**
  1207. * fcs_vf_api virtual fabrics API
  1208. */
  1209. /**
  1210. * Enable VF mode.
  1211. *
  1212. * @param[in] fcs fcs module instance
  1213. * @param[in] vf_id default vf_id of port, FC_VF_ID_NULL
  1214. * to use standard default vf_id of 1.
  1215. *
  1216. * @retval BFA_STATUS_OK vf mode is enabled
  1217. * @retval BFA_STATUS_BUSY Port is active. Port must be disabled
  1218. * before VF mode can be enabled.
  1219. */
  1220. bfa_status_t
  1221. bfa_fcs_vf_mode_enable(struct bfa_fcs_s *fcs, u16 vf_id)
  1222. {
  1223. return BFA_STATUS_OK;
  1224. }
  1225. /**
  1226. * Disable VF mode.
  1227. *
  1228. * @param[in] fcs fcs module instance
  1229. *
  1230. * @retval BFA_STATUS_OK vf mode is disabled
  1231. * @retval BFA_STATUS_BUSY VFs are present and being used. All
  1232. * VFs must be deleted before disabling
  1233. * VF mode.
  1234. */
  1235. bfa_status_t
  1236. bfa_fcs_vf_mode_disable(struct bfa_fcs_s *fcs)
  1237. {
  1238. return BFA_STATUS_OK;
  1239. }
  1240. /**
  1241. * Create a new VF instance.
  1242. *
  1243. * A new VF is created using the given VF configuration. A VF is identified
  1244. * by VF id. No duplicate VF creation is allowed with the same VF id. Once
  1245. * a VF is created, VF is automatically started after link initialization
  1246. * and EVFP exchange is completed.
  1247. *
  1248. * param[in] vf - FCS vf data structure. Memory is
  1249. * allocated by caller (driver)
  1250. * param[in] fcs - FCS module
  1251. * param[in] vf_cfg - VF configuration
  1252. * param[in] vf_drv - Opaque handle back to the driver's
  1253. * virtual vf structure
  1254. *
  1255. * retval BFA_STATUS_OK VF creation is successful
  1256. * retval BFA_STATUS_FAILED VF creation failed
  1257. * retval BFA_STATUS_EEXIST A VF exists with the given vf_id
  1258. */
  1259. bfa_status_t
  1260. bfa_fcs_vf_create(bfa_fcs_vf_t *vf, struct bfa_fcs_s *fcs, u16 vf_id,
  1261. struct bfa_lport_cfg_s *port_cfg, struct bfad_vf_s *vf_drv)
  1262. {
  1263. bfa_trc(fcs, vf_id);
  1264. return BFA_STATUS_OK;
  1265. }
  1266. /**
  1267. * Use this function to delete a BFA VF object. VF object should
  1268. * be stopped before this function call.
  1269. *
  1270. * param[in] vf - pointer to bfa_vf_t.
  1271. *
  1272. * retval BFA_STATUS_OK On vf deletion success
  1273. * retval BFA_STATUS_BUSY VF is not in a stopped state
  1274. * retval BFA_STATUS_INPROGRESS VF deletion in in progress
  1275. */
  1276. bfa_status_t
  1277. bfa_fcs_vf_delete(bfa_fcs_vf_t *vf)
  1278. {
  1279. bfa_trc(vf->fcs, vf->vf_id);
  1280. return BFA_STATUS_OK;
  1281. }
  1282. /**
  1283. * Returns attributes of the given VF.
  1284. *
  1285. * param[in] vf pointer to bfa_vf_t.
  1286. * param[out] vf_attr vf attributes returned
  1287. *
  1288. * return None
  1289. */
  1290. void
  1291. bfa_fcs_vf_get_attr(bfa_fcs_vf_t *vf, struct bfa_vf_attr_s *vf_attr)
  1292. {
  1293. bfa_trc(vf->fcs, vf->vf_id);
  1294. }
  1295. /**
  1296. * Return statistics associated with the given vf.
  1297. *
  1298. * param[in] vf pointer to bfa_vf_t.
  1299. * param[out] vf_stats vf statistics returned
  1300. *
  1301. * @return None
  1302. */
  1303. void
  1304. bfa_fcs_vf_get_stats(bfa_fcs_vf_t *vf, struct bfa_vf_stats_s *vf_stats)
  1305. {
  1306. bfa_os_memcpy(vf_stats, &vf->stats, sizeof(struct bfa_vf_stats_s));
  1307. }
  1308. /**
  1309. * clear statistics associated with the given vf.
  1310. *
  1311. * param[in] vf pointer to bfa_vf_t.
  1312. *
  1313. * @return None
  1314. */
  1315. void
  1316. bfa_fcs_vf_clear_stats(bfa_fcs_vf_t *vf)
  1317. {
  1318. bfa_os_memset(&vf->stats, 0, sizeof(struct bfa_vf_stats_s));
  1319. }
  1320. /**
  1321. * Returns FCS vf structure for a given vf_id.
  1322. *
  1323. * param[in] vf_id - VF_ID
  1324. *
  1325. * return
  1326. * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
  1327. */
  1328. bfa_fcs_vf_t *
  1329. bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
  1330. {
  1331. bfa_trc(fcs, vf_id);
  1332. if (vf_id == FC_VF_ID_NULL)
  1333. return &fcs->fabric;
  1334. return NULL;
  1335. }
  1336. /**
  1337. * Return the list of VFs configured.
  1338. *
  1339. * param[in] fcs fcs module instance
  1340. * param[out] vf_ids returned list of vf_ids
  1341. * param[in,out] nvfs in:size of vf_ids array,
  1342. * out:total elements present,
  1343. * actual elements returned is limited by the size
  1344. *
  1345. * return Driver VF structure
  1346. */
  1347. void
  1348. bfa_fcs_vf_list(struct bfa_fcs_s *fcs, u16 *vf_ids, int *nvfs)
  1349. {
  1350. bfa_trc(fcs, *nvfs);
  1351. }
  1352. /**
  1353. * Return the list of all VFs visible from fabric.
  1354. *
  1355. * param[in] fcs fcs module instance
  1356. * param[out] vf_ids returned list of vf_ids
  1357. * param[in,out] nvfs in:size of vf_ids array,
  1358. * out:total elements present,
  1359. * actual elements returned is limited by the size
  1360. *
  1361. * return Driver VF structure
  1362. */
  1363. void
  1364. bfa_fcs_vf_list_all(struct bfa_fcs_s *fcs, u16 *vf_ids, int *nvfs)
  1365. {
  1366. bfa_trc(fcs, *nvfs);
  1367. }
  1368. /**
  1369. * Return the list of local logical ports present in the given VF.
  1370. *
  1371. * param[in] vf vf for which logical ports are returned
  1372. * param[out] lpwwn returned logical port wwn list
  1373. * param[in,out] nlports in:size of lpwwn list;
  1374. * out:total elements present,
  1375. * actual elements returned is limited by the size
  1376. */
  1377. void
  1378. bfa_fcs_vf_get_ports(bfa_fcs_vf_t *vf, wwn_t lpwwn[], int *nlports)
  1379. {
  1380. struct list_head *qe;
  1381. struct bfa_fcs_vport_s *vport;
  1382. int i;
  1383. struct bfa_fcs_s *fcs;
  1384. if (vf == NULL || lpwwn == NULL || *nlports == 0)
  1385. return;
  1386. fcs = vf->fcs;
  1387. bfa_trc(fcs, vf->vf_id);
  1388. bfa_trc(fcs, (u32) *nlports);
  1389. i = 0;
  1390. lpwwn[i++] = vf->bport.port_cfg.pwwn;
  1391. list_for_each(qe, &vf->vport_q) {
  1392. if (i >= *nlports)
  1393. break;
  1394. vport = (struct bfa_fcs_vport_s *) qe;
  1395. lpwwn[i++] = vport->lport.port_cfg.pwwn;
  1396. }
  1397. bfa_trc(fcs, i);
  1398. *nlports = i;
  1399. }
  1400. /**
  1401. * BFA FCS PPORT ( physical port)
  1402. */
  1403. static void
  1404. bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
  1405. {
  1406. struct bfa_fcs_s *fcs = cbarg;
  1407. bfa_trc(fcs, event);
  1408. switch (event) {
  1409. case BFA_PORT_LINKUP:
  1410. bfa_fcs_fabric_link_up(&fcs->fabric);
  1411. break;
  1412. case BFA_PORT_LINKDOWN:
  1413. bfa_fcs_fabric_link_down(&fcs->fabric);
  1414. break;
  1415. default:
  1416. bfa_assert(0);
  1417. }
  1418. }
  1419. void
  1420. bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
  1421. {
  1422. bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
  1423. }
  1424. /**
  1425. * BFA FCS UF ( Unsolicited Frames)
  1426. */
  1427. /**
  1428. * BFA callback for unsolicited frame receive handler.
  1429. *
  1430. * @param[in] cbarg callback arg for receive handler
  1431. * @param[in] uf unsolicited frame descriptor
  1432. *
  1433. * @return None
  1434. */
  1435. static void
  1436. bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
  1437. {
  1438. struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
  1439. struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
  1440. u16 len = bfa_uf_get_frmlen(uf);
  1441. struct fc_vft_s *vft;
  1442. struct bfa_fcs_fabric_s *fabric;
  1443. /**
  1444. * check for VFT header
  1445. */
  1446. if (fchs->routing == FC_RTG_EXT_HDR &&
  1447. fchs->cat_info == FC_CAT_VFT_HDR) {
  1448. bfa_stats(fcs, uf.tagged);
  1449. vft = bfa_uf_get_frmbuf(uf);
  1450. if (fcs->port_vfid == vft->vf_id)
  1451. fabric = &fcs->fabric;
  1452. else
  1453. fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
  1454. /**
  1455. * drop frame if vfid is unknown
  1456. */
  1457. if (!fabric) {
  1458. bfa_assert(0);
  1459. bfa_stats(fcs, uf.vfid_unknown);
  1460. bfa_uf_free(uf);
  1461. return;
  1462. }
  1463. /**
  1464. * skip vft header
  1465. */
  1466. fchs = (struct fchs_s *) (vft + 1);
  1467. len -= sizeof(struct fc_vft_s);
  1468. bfa_trc(fcs, vft->vf_id);
  1469. } else {
  1470. bfa_stats(fcs, uf.untagged);
  1471. fabric = &fcs->fabric;
  1472. }
  1473. bfa_trc(fcs, ((u32 *) fchs)[0]);
  1474. bfa_trc(fcs, ((u32 *) fchs)[1]);
  1475. bfa_trc(fcs, ((u32 *) fchs)[2]);
  1476. bfa_trc(fcs, ((u32 *) fchs)[3]);
  1477. bfa_trc(fcs, ((u32 *) fchs)[4]);
  1478. bfa_trc(fcs, ((u32 *) fchs)[5]);
  1479. bfa_trc(fcs, len);
  1480. bfa_fcs_fabric_uf_recv(fabric, fchs, len);
  1481. bfa_uf_free(uf);
  1482. }
  1483. void
  1484. bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
  1485. {
  1486. bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
  1487. }