bfa_fcs.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519
  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, bfa_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. 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. bfa_boolean_t
  874. bfa_fcs_fabric_is_loopback(struct bfa_fcs_fabric_s *fabric)
  875. {
  876. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_loopback);
  877. }
  878. bfa_boolean_t
  879. bfa_fcs_fabric_is_auth_failed(struct bfa_fcs_fabric_s *fabric)
  880. {
  881. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_auth_failed);
  882. }
  883. enum bfa_port_type
  884. bfa_fcs_fabric_port_type(struct bfa_fcs_fabric_s *fabric)
  885. {
  886. return fabric->oper_type;
  887. }
  888. /*
  889. * Link up notification from BFA physical port module.
  890. */
  891. void
  892. bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
  893. {
  894. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  895. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
  896. }
  897. /*
  898. * Link down notification from BFA physical port module.
  899. */
  900. void
  901. bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
  902. {
  903. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  904. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
  905. }
  906. /*
  907. * A child vport is being created in the fabric.
  908. *
  909. * Call from vport module at vport creation. A list of base port and vports
  910. * belonging to a fabric is maintained to propagate link events.
  911. *
  912. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  913. * param[in] vport - Vport being created.
  914. *
  915. * @return None (always succeeds)
  916. */
  917. void
  918. bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
  919. struct bfa_fcs_vport_s *vport)
  920. {
  921. /*
  922. * - add vport to fabric's vport_q
  923. */
  924. bfa_trc(fabric->fcs, fabric->vf_id);
  925. list_add_tail(&vport->qe, &fabric->vport_q);
  926. fabric->num_vports++;
  927. bfa_wc_up(&fabric->wc);
  928. }
  929. /*
  930. * A child vport is being deleted from fabric.
  931. *
  932. * Vport is being deleted.
  933. */
  934. void
  935. bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
  936. struct bfa_fcs_vport_s *vport)
  937. {
  938. list_del(&vport->qe);
  939. fabric->num_vports--;
  940. bfa_wc_down(&fabric->wc);
  941. }
  942. /*
  943. * Base port is deleted.
  944. */
  945. void
  946. bfa_fcs_fabric_port_delete_comp(struct bfa_fcs_fabric_s *fabric)
  947. {
  948. bfa_wc_down(&fabric->wc);
  949. }
  950. /*
  951. * Check if fabric is online.
  952. *
  953. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  954. *
  955. * @return TRUE/FALSE
  956. */
  957. int
  958. bfa_fcs_fabric_is_online(struct bfa_fcs_fabric_s *fabric)
  959. {
  960. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_online);
  961. }
  962. /*
  963. * Lookup for a vport withing a fabric given its pwwn
  964. */
  965. struct bfa_fcs_vport_s *
  966. bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
  967. {
  968. struct bfa_fcs_vport_s *vport;
  969. struct list_head *qe;
  970. list_for_each(qe, &fabric->vport_q) {
  971. vport = (struct bfa_fcs_vport_s *) qe;
  972. if (bfa_fcs_lport_get_pwwn(&vport->lport) == pwwn)
  973. return vport;
  974. }
  975. return NULL;
  976. }
  977. /*
  978. * In a given fabric, return the number of lports.
  979. *
  980. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  981. *
  982. * @return : 1 or more.
  983. */
  984. u16
  985. bfa_fcs_fabric_vport_count(struct bfa_fcs_fabric_s *fabric)
  986. {
  987. return fabric->num_vports;
  988. }
  989. /*
  990. * Get OUI of the attached switch.
  991. *
  992. * Note : Use of this function should be avoided as much as possible.
  993. * This function should be used only if there is any requirement
  994. * to check for FOS version below 6.3.
  995. * To check if the attached fabric is a brocade fabric, use
  996. * bfa_lps_is_brcd_fabric() which works for FOS versions 6.3
  997. * or above only.
  998. */
  999. u16
  1000. bfa_fcs_fabric_get_switch_oui(struct bfa_fcs_fabric_s *fabric)
  1001. {
  1002. wwn_t fab_nwwn;
  1003. u8 *tmp;
  1004. u16 oui;
  1005. fab_nwwn = bfa_lps_get_peer_nwwn(fabric->lps);
  1006. tmp = (u8 *)&fab_nwwn;
  1007. oui = (tmp[3] << 8) | tmp[4];
  1008. return oui;
  1009. }
  1010. /*
  1011. * Unsolicited frame receive handling.
  1012. */
  1013. void
  1014. bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
  1015. u16 len)
  1016. {
  1017. u32 pid = fchs->d_id;
  1018. struct bfa_fcs_vport_s *vport;
  1019. struct list_head *qe;
  1020. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  1021. struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
  1022. bfa_trc(fabric->fcs, len);
  1023. bfa_trc(fabric->fcs, pid);
  1024. /*
  1025. * Look for our own FLOGI frames being looped back. This means an
  1026. * external loopback cable is in place. Our own FLOGI frames are
  1027. * sometimes looped back when switch port gets temporarily bypassed.
  1028. */
  1029. if ((pid == bfa_os_ntoh3b(FC_FABRIC_PORT)) &&
  1030. (els_cmd->els_code == FC_ELS_FLOGI) &&
  1031. (flogi->port_name == bfa_fcs_lport_get_pwwn(&fabric->bport))) {
  1032. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
  1033. return;
  1034. }
  1035. /*
  1036. * FLOGI/EVFP exchanges should be consumed by base fabric.
  1037. */
  1038. if (fchs->d_id == bfa_os_hton3b(FC_FABRIC_PORT)) {
  1039. bfa_trc(fabric->fcs, pid);
  1040. bfa_fcs_fabric_process_uf(fabric, fchs, len);
  1041. return;
  1042. }
  1043. if (fabric->bport.pid == pid) {
  1044. /*
  1045. * All authentication frames should be routed to auth
  1046. */
  1047. bfa_trc(fabric->fcs, els_cmd->els_code);
  1048. if (els_cmd->els_code == FC_ELS_AUTH) {
  1049. bfa_trc(fabric->fcs, els_cmd->els_code);
  1050. return;
  1051. }
  1052. bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
  1053. bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
  1054. return;
  1055. }
  1056. /*
  1057. * look for a matching local port ID
  1058. */
  1059. list_for_each(qe, &fabric->vport_q) {
  1060. vport = (struct bfa_fcs_vport_s *) qe;
  1061. if (vport->lport.pid == pid) {
  1062. bfa_fcs_lport_uf_recv(&vport->lport, fchs, len);
  1063. return;
  1064. }
  1065. }
  1066. bfa_trc(fabric->fcs, els_cmd->els_code);
  1067. bfa_fcs_lport_uf_recv(&fabric->bport, fchs, len);
  1068. }
  1069. /*
  1070. * Unsolicited frames to be processed by fabric.
  1071. */
  1072. static void
  1073. bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
  1074. u16 len)
  1075. {
  1076. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  1077. bfa_trc(fabric->fcs, els_cmd->els_code);
  1078. switch (els_cmd->els_code) {
  1079. case FC_ELS_FLOGI:
  1080. bfa_fcs_fabric_process_flogi(fabric, fchs, len);
  1081. break;
  1082. default:
  1083. /*
  1084. * need to generate a LS_RJT
  1085. */
  1086. break;
  1087. }
  1088. }
  1089. /*
  1090. * Process incoming FLOGI
  1091. */
  1092. static void
  1093. bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
  1094. struct fchs_s *fchs, u16 len)
  1095. {
  1096. struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
  1097. struct bfa_fcs_lport_s *bport = &fabric->bport;
  1098. bfa_trc(fabric->fcs, fchs->s_id);
  1099. fabric->stats.flogi_rcvd++;
  1100. /*
  1101. * Check port type. It should be 0 = n-port.
  1102. */
  1103. if (flogi->csp.port_type) {
  1104. /*
  1105. * @todo: may need to send a LS_RJT
  1106. */
  1107. bfa_trc(fabric->fcs, flogi->port_name);
  1108. fabric->stats.flogi_rejected++;
  1109. return;
  1110. }
  1111. fabric->bb_credit = be16_to_cpu(flogi->csp.bbcred);
  1112. bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
  1113. bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
  1114. /*
  1115. * Send a Flogi Acc
  1116. */
  1117. bfa_fcs_fabric_send_flogi_acc(fabric);
  1118. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
  1119. }
  1120. static void
  1121. bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
  1122. {
  1123. struct bfa_lport_cfg_s *pcfg = &fabric->bport.port_cfg;
  1124. struct bfa_fcs_lport_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
  1125. struct bfa_s *bfa = fabric->fcs->bfa;
  1126. struct bfa_fcxp_s *fcxp;
  1127. u16 reqlen;
  1128. struct fchs_s fchs;
  1129. fcxp = bfa_fcs_fcxp_alloc(fabric->fcs);
  1130. /*
  1131. * Do not expect this failure -- expect remote node to retry
  1132. */
  1133. if (!fcxp)
  1134. return;
  1135. reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  1136. bfa_os_hton3b(FC_FABRIC_PORT),
  1137. n2n_port->reply_oxid, pcfg->pwwn,
  1138. pcfg->nwwn,
  1139. bfa_fcport_get_maxfrsize(bfa),
  1140. bfa_fcport_get_rx_bbcredit(bfa));
  1141. bfa_fcxp_send(fcxp, NULL, fabric->vf_id, bfa_lps_get_tag(fabric->lps),
  1142. BFA_FALSE, FC_CLASS_3,
  1143. reqlen, &fchs, bfa_fcs_fabric_flogiacc_comp, fabric,
  1144. FC_MAX_PDUSZ, 0);
  1145. }
  1146. /*
  1147. * Flogi Acc completion callback.
  1148. */
  1149. static void
  1150. bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1151. bfa_status_t status, u32 rsp_len,
  1152. u32 resid_len, struct fchs_s *rspfchs)
  1153. {
  1154. struct bfa_fcs_fabric_s *fabric = cbarg;
  1155. bfa_trc(fabric->fcs, status);
  1156. }
  1157. /*
  1158. *
  1159. * @param[in] fabric - fabric
  1160. * @param[in] wwn_t - new fabric name
  1161. *
  1162. * @return - none
  1163. */
  1164. void
  1165. bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
  1166. wwn_t fabric_name)
  1167. {
  1168. struct bfad_s *bfad = (struct bfad_s *)fabric->fcs->bfad;
  1169. char pwwn_ptr[BFA_STRING_32];
  1170. char fwwn_ptr[BFA_STRING_32];
  1171. bfa_trc(fabric->fcs, fabric_name);
  1172. if (fabric->fabric_name == 0) {
  1173. /*
  1174. * With BRCD switches, we don't get Fabric Name in FLOGI.
  1175. * Don't generate a fabric name change event in this case.
  1176. */
  1177. fabric->fabric_name = fabric_name;
  1178. } else {
  1179. fabric->fabric_name = fabric_name;
  1180. wwn2str(pwwn_ptr, bfa_fcs_lport_get_pwwn(&fabric->bport));
  1181. wwn2str(fwwn_ptr,
  1182. bfa_fcs_lport_get_fabric_name(&fabric->bport));
  1183. BFA_LOG(KERN_WARNING, bfad, bfa_log_level,
  1184. "Base port WWN = %s Fabric WWN = %s\n",
  1185. pwwn_ptr, fwwn_ptr);
  1186. }
  1187. }
  1188. /*
  1189. * Returns FCS vf structure for a given vf_id.
  1190. *
  1191. * param[in] vf_id - VF_ID
  1192. *
  1193. * return
  1194. * If lookup succeeds, retuns fcs vf object, otherwise returns NULL
  1195. */
  1196. bfa_fcs_vf_t *
  1197. bfa_fcs_vf_lookup(struct bfa_fcs_s *fcs, u16 vf_id)
  1198. {
  1199. bfa_trc(fcs, vf_id);
  1200. if (vf_id == FC_VF_ID_NULL)
  1201. return &fcs->fabric;
  1202. return NULL;
  1203. }
  1204. /*
  1205. * BFA FCS PPORT ( physical port)
  1206. */
  1207. static void
  1208. bfa_fcs_port_event_handler(void *cbarg, enum bfa_port_linkstate event)
  1209. {
  1210. struct bfa_fcs_s *fcs = cbarg;
  1211. bfa_trc(fcs, event);
  1212. switch (event) {
  1213. case BFA_PORT_LINKUP:
  1214. bfa_fcs_fabric_link_up(&fcs->fabric);
  1215. break;
  1216. case BFA_PORT_LINKDOWN:
  1217. bfa_fcs_fabric_link_down(&fcs->fabric);
  1218. break;
  1219. default:
  1220. bfa_assert(0);
  1221. }
  1222. }
  1223. void
  1224. bfa_fcs_port_attach(struct bfa_fcs_s *fcs)
  1225. {
  1226. bfa_fcport_event_register(fcs->bfa, bfa_fcs_port_event_handler, fcs);
  1227. }
  1228. /*
  1229. * BFA FCS UF ( Unsolicited Frames)
  1230. */
  1231. /*
  1232. * BFA callback for unsolicited frame receive handler.
  1233. *
  1234. * @param[in] cbarg callback arg for receive handler
  1235. * @param[in] uf unsolicited frame descriptor
  1236. *
  1237. * @return None
  1238. */
  1239. static void
  1240. bfa_fcs_uf_recv(void *cbarg, struct bfa_uf_s *uf)
  1241. {
  1242. struct bfa_fcs_s *fcs = (struct bfa_fcs_s *) cbarg;
  1243. struct fchs_s *fchs = bfa_uf_get_frmbuf(uf);
  1244. u16 len = bfa_uf_get_frmlen(uf);
  1245. struct fc_vft_s *vft;
  1246. struct bfa_fcs_fabric_s *fabric;
  1247. /*
  1248. * check for VFT header
  1249. */
  1250. if (fchs->routing == FC_RTG_EXT_HDR &&
  1251. fchs->cat_info == FC_CAT_VFT_HDR) {
  1252. bfa_stats(fcs, uf.tagged);
  1253. vft = bfa_uf_get_frmbuf(uf);
  1254. if (fcs->port_vfid == vft->vf_id)
  1255. fabric = &fcs->fabric;
  1256. else
  1257. fabric = bfa_fcs_vf_lookup(fcs, (u16) vft->vf_id);
  1258. /*
  1259. * drop frame if vfid is unknown
  1260. */
  1261. if (!fabric) {
  1262. bfa_assert(0);
  1263. bfa_stats(fcs, uf.vfid_unknown);
  1264. bfa_uf_free(uf);
  1265. return;
  1266. }
  1267. /*
  1268. * skip vft header
  1269. */
  1270. fchs = (struct fchs_s *) (vft + 1);
  1271. len -= sizeof(struct fc_vft_s);
  1272. bfa_trc(fcs, vft->vf_id);
  1273. } else {
  1274. bfa_stats(fcs, uf.untagged);
  1275. fabric = &fcs->fabric;
  1276. }
  1277. bfa_trc(fcs, ((u32 *) fchs)[0]);
  1278. bfa_trc(fcs, ((u32 *) fchs)[1]);
  1279. bfa_trc(fcs, ((u32 *) fchs)[2]);
  1280. bfa_trc(fcs, ((u32 *) fchs)[3]);
  1281. bfa_trc(fcs, ((u32 *) fchs)[4]);
  1282. bfa_trc(fcs, ((u32 *) fchs)[5]);
  1283. bfa_trc(fcs, len);
  1284. bfa_fcs_fabric_uf_recv(fabric, fchs, len);
  1285. bfa_uf_free(uf);
  1286. }
  1287. void
  1288. bfa_fcs_uf_attach(struct bfa_fcs_s *fcs)
  1289. {
  1290. bfa_uf_recv_register(fcs->bfa, bfa_fcs_uf_recv, fcs);
  1291. }