bfa_fcs.c 33 KB

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