bfa_fcs.c 35 KB

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