bfa_fcs.c 36 KB

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