bfa_fcs.c 42 KB

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