bfa_fcs.c 41 KB

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