bfa_fcs.c 41 KB

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