bfa_fcs.c 37 KB

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