bfa_fcs.c 37 KB

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