fabric.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /*
  2. * Copyright (c) 2005-2009 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. * fabric.c Fabric module implementation.
  19. */
  20. #include "fcs_fabric.h"
  21. #include "fcs_lport.h"
  22. #include "fcs_vport.h"
  23. #include "fcs_trcmod.h"
  24. #include "fcs_fcxp.h"
  25. #include "fcs_auth.h"
  26. #include "fcs.h"
  27. #include "fcbuild.h"
  28. #include <log/bfa_log_fcs.h>
  29. #include <aen/bfa_aen_port.h>
  30. #include <bfa_svc.h>
  31. BFA_TRC_FILE(FCS, FABRIC);
  32. #define BFA_FCS_FABRIC_RETRY_DELAY (2000) /* Milliseconds */
  33. #define BFA_FCS_FABRIC_CLEANUP_DELAY (10000) /* Milliseconds */
  34. #define bfa_fcs_fabric_set_opertype(__fabric) do { \
  35. if (bfa_pport_get_topology((__fabric)->fcs->bfa) \
  36. == BFA_PPORT_TOPOLOGY_P2P) \
  37. (__fabric)->oper_type = BFA_PPORT_TYPE_NPORT; \
  38. else \
  39. (__fabric)->oper_type = BFA_PPORT_TYPE_NLPORT; \
  40. } while (0)
  41. /*
  42. * forward declarations
  43. */
  44. static void bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric);
  45. static void bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric);
  46. static void bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric);
  47. static void bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric);
  48. static void bfa_fcs_fabric_delay(void *cbarg);
  49. static void bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric);
  50. static void bfa_fcs_fabric_delete_comp(void *cbarg);
  51. static void bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric,
  52. struct fchs_s *fchs, u16 len);
  53. static void bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
  54. struct fchs_s *fchs, u16 len);
  55. static void bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric);
  56. static void bfa_fcs_fabric_flogiacc_comp(void *fcsarg,
  57. struct bfa_fcxp_s *fcxp,
  58. void *cbarg, bfa_status_t status,
  59. u32 rsp_len,
  60. u32 resid_len,
  61. struct fchs_s *rspfchs);
  62. /**
  63. * fcs_fabric_sm fabric state machine functions
  64. */
  65. /**
  66. * Fabric state machine events
  67. */
  68. enum bfa_fcs_fabric_event {
  69. BFA_FCS_FABRIC_SM_CREATE = 1, /* fabric create from driver */
  70. BFA_FCS_FABRIC_SM_DELETE = 2, /* fabric delete from driver */
  71. BFA_FCS_FABRIC_SM_LINK_DOWN = 3, /* link down from port */
  72. BFA_FCS_FABRIC_SM_LINK_UP = 4, /* link up from port */
  73. BFA_FCS_FABRIC_SM_CONT_OP = 5, /* continue op from flogi/auth */
  74. BFA_FCS_FABRIC_SM_RETRY_OP = 6, /* continue op from flogi/auth */
  75. BFA_FCS_FABRIC_SM_NO_FABRIC = 7, /* no fabric from flogi/auth
  76. */
  77. BFA_FCS_FABRIC_SM_PERF_EVFP = 8, /* perform EVFP from
  78. *flogi/auth */
  79. BFA_FCS_FABRIC_SM_ISOLATE = 9, /* isolate from EVFP processing */
  80. BFA_FCS_FABRIC_SM_NO_TAGGING = 10,/* no VFT tagging from EVFP */
  81. BFA_FCS_FABRIC_SM_DELAYED = 11, /* timeout delay event */
  82. BFA_FCS_FABRIC_SM_AUTH_FAILED = 12, /* authentication failed */
  83. BFA_FCS_FABRIC_SM_AUTH_SUCCESS = 13, /* authentication successful
  84. */
  85. BFA_FCS_FABRIC_SM_DELCOMP = 14, /* all vports deleted event */
  86. BFA_FCS_FABRIC_SM_LOOPBACK = 15, /* Received our own FLOGI */
  87. BFA_FCS_FABRIC_SM_START = 16, /* fabric delete from driver */
  88. };
  89. static void bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
  90. enum bfa_fcs_fabric_event event);
  91. static void bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
  92. enum bfa_fcs_fabric_event event);
  93. static void bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
  94. enum bfa_fcs_fabric_event event);
  95. static void bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
  96. enum bfa_fcs_fabric_event event);
  97. static void bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
  98. enum bfa_fcs_fabric_event event);
  99. static void bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
  100. enum bfa_fcs_fabric_event event);
  101. static void bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
  102. enum bfa_fcs_fabric_event event);
  103. static void bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
  104. enum bfa_fcs_fabric_event event);
  105. static void bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
  106. enum bfa_fcs_fabric_event event);
  107. static void bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
  108. enum bfa_fcs_fabric_event event);
  109. static void bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
  110. enum bfa_fcs_fabric_event event);
  111. static void bfa_fcs_fabric_sm_evfp_done(struct bfa_fcs_fabric_s *fabric,
  112. enum bfa_fcs_fabric_event event);
  113. static void bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
  114. enum bfa_fcs_fabric_event event);
  115. static void bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
  116. enum bfa_fcs_fabric_event event);
  117. /**
  118. * Beginning state before fabric creation.
  119. */
  120. static void
  121. bfa_fcs_fabric_sm_uninit(struct bfa_fcs_fabric_s *fabric,
  122. enum bfa_fcs_fabric_event event)
  123. {
  124. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  125. bfa_trc(fabric->fcs, event);
  126. switch (event) {
  127. case BFA_FCS_FABRIC_SM_CREATE:
  128. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_created);
  129. bfa_fcs_fabric_init(fabric);
  130. bfa_fcs_lport_init(&fabric->bport, fabric->fcs, FC_VF_ID_NULL,
  131. &fabric->bport.port_cfg, NULL);
  132. break;
  133. case BFA_FCS_FABRIC_SM_LINK_UP:
  134. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  135. break;
  136. default:
  137. bfa_sm_fault(fabric->fcs, event);
  138. }
  139. }
  140. /**
  141. * Beginning state before fabric creation.
  142. */
  143. static void
  144. bfa_fcs_fabric_sm_created(struct bfa_fcs_fabric_s *fabric,
  145. enum bfa_fcs_fabric_event event)
  146. {
  147. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  148. bfa_trc(fabric->fcs, event);
  149. switch (event) {
  150. case BFA_FCS_FABRIC_SM_START:
  151. if (bfa_pport_is_linkup(fabric->fcs->bfa)) {
  152. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
  153. bfa_fcs_fabric_login(fabric);
  154. } else
  155. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  156. break;
  157. case BFA_FCS_FABRIC_SM_LINK_UP:
  158. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  159. break;
  160. case BFA_FCS_FABRIC_SM_DELETE:
  161. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
  162. bfa_fcs_modexit_comp(fabric->fcs);
  163. break;
  164. default:
  165. bfa_sm_fault(fabric->fcs, event);
  166. }
  167. }
  168. /**
  169. * Link is down, awaiting LINK UP event from port. This is also the
  170. * first state at fabric creation.
  171. */
  172. static void
  173. bfa_fcs_fabric_sm_linkdown(struct bfa_fcs_fabric_s *fabric,
  174. enum bfa_fcs_fabric_event event)
  175. {
  176. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  177. bfa_trc(fabric->fcs, event);
  178. switch (event) {
  179. case BFA_FCS_FABRIC_SM_LINK_UP:
  180. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
  181. bfa_fcs_fabric_login(fabric);
  182. break;
  183. case BFA_FCS_FABRIC_SM_RETRY_OP:
  184. break;
  185. case BFA_FCS_FABRIC_SM_DELETE:
  186. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  187. bfa_fcs_fabric_delete(fabric);
  188. break;
  189. default:
  190. bfa_sm_fault(fabric->fcs, event);
  191. }
  192. }
  193. /**
  194. * FLOGI is in progress, awaiting FLOGI reply.
  195. */
  196. static void
  197. bfa_fcs_fabric_sm_flogi(struct bfa_fcs_fabric_s *fabric,
  198. enum bfa_fcs_fabric_event event)
  199. {
  200. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  201. bfa_trc(fabric->fcs, event);
  202. switch (event) {
  203. case BFA_FCS_FABRIC_SM_CONT_OP:
  204. bfa_pport_set_tx_bbcredit(fabric->fcs->bfa, fabric->bb_credit);
  205. fabric->fab_type = BFA_FCS_FABRIC_SWITCHED;
  206. if (fabric->auth_reqd && fabric->is_auth) {
  207. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth);
  208. bfa_trc(fabric->fcs, event);
  209. } else {
  210. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
  211. bfa_fcs_fabric_notify_online(fabric);
  212. }
  213. break;
  214. case BFA_FCS_FABRIC_SM_RETRY_OP:
  215. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi_retry);
  216. bfa_timer_start(fabric->fcs->bfa, &fabric->delay_timer,
  217. bfa_fcs_fabric_delay, fabric,
  218. BFA_FCS_FABRIC_RETRY_DELAY);
  219. break;
  220. case BFA_FCS_FABRIC_SM_LOOPBACK:
  221. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_loopback);
  222. bfa_lps_discard(fabric->lps);
  223. bfa_fcs_fabric_set_opertype(fabric);
  224. break;
  225. case BFA_FCS_FABRIC_SM_NO_FABRIC:
  226. fabric->fab_type = BFA_FCS_FABRIC_N2N;
  227. bfa_pport_set_tx_bbcredit(fabric->fcs->bfa, fabric->bb_credit);
  228. bfa_fcs_fabric_notify_online(fabric);
  229. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_nofabric);
  230. break;
  231. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  232. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  233. bfa_lps_discard(fabric->lps);
  234. break;
  235. case BFA_FCS_FABRIC_SM_DELETE:
  236. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  237. bfa_lps_discard(fabric->lps);
  238. bfa_fcs_fabric_delete(fabric);
  239. break;
  240. default:
  241. bfa_sm_fault(fabric->fcs, event);
  242. }
  243. }
  244. static void
  245. bfa_fcs_fabric_sm_flogi_retry(struct bfa_fcs_fabric_s *fabric,
  246. enum bfa_fcs_fabric_event event)
  247. {
  248. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  249. bfa_trc(fabric->fcs, event);
  250. switch (event) {
  251. case BFA_FCS_FABRIC_SM_DELAYED:
  252. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_flogi);
  253. bfa_fcs_fabric_login(fabric);
  254. break;
  255. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  256. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  257. bfa_timer_stop(&fabric->delay_timer);
  258. break;
  259. case BFA_FCS_FABRIC_SM_DELETE:
  260. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  261. bfa_timer_stop(&fabric->delay_timer);
  262. bfa_fcs_fabric_delete(fabric);
  263. break;
  264. default:
  265. bfa_sm_fault(fabric->fcs, event);
  266. }
  267. }
  268. /**
  269. * Authentication is in progress, awaiting authentication results.
  270. */
  271. static void
  272. bfa_fcs_fabric_sm_auth(struct bfa_fcs_fabric_s *fabric,
  273. enum bfa_fcs_fabric_event event)
  274. {
  275. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  276. bfa_trc(fabric->fcs, event);
  277. switch (event) {
  278. case BFA_FCS_FABRIC_SM_AUTH_FAILED:
  279. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
  280. bfa_lps_discard(fabric->lps);
  281. break;
  282. case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
  283. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_online);
  284. bfa_fcs_fabric_notify_online(fabric);
  285. break;
  286. case BFA_FCS_FABRIC_SM_PERF_EVFP:
  287. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp);
  288. break;
  289. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  290. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  291. bfa_lps_discard(fabric->lps);
  292. break;
  293. case BFA_FCS_FABRIC_SM_DELETE:
  294. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  295. bfa_fcs_fabric_delete(fabric);
  296. break;
  297. default:
  298. bfa_sm_fault(fabric->fcs, event);
  299. }
  300. }
  301. /**
  302. * Authentication failed
  303. */
  304. static void
  305. bfa_fcs_fabric_sm_auth_failed(struct bfa_fcs_fabric_s *fabric,
  306. enum bfa_fcs_fabric_event event)
  307. {
  308. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  309. bfa_trc(fabric->fcs, event);
  310. switch (event) {
  311. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  312. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  313. bfa_fcs_fabric_notify_offline(fabric);
  314. break;
  315. case BFA_FCS_FABRIC_SM_DELETE:
  316. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  317. bfa_fcs_fabric_delete(fabric);
  318. break;
  319. default:
  320. bfa_sm_fault(fabric->fcs, event);
  321. }
  322. }
  323. /**
  324. * Port is in loopback mode.
  325. */
  326. static void
  327. bfa_fcs_fabric_sm_loopback(struct bfa_fcs_fabric_s *fabric,
  328. enum bfa_fcs_fabric_event event)
  329. {
  330. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  331. bfa_trc(fabric->fcs, event);
  332. switch (event) {
  333. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  334. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  335. bfa_fcs_fabric_notify_offline(fabric);
  336. break;
  337. case BFA_FCS_FABRIC_SM_DELETE:
  338. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  339. bfa_fcs_fabric_delete(fabric);
  340. break;
  341. default:
  342. bfa_sm_fault(fabric->fcs, event);
  343. }
  344. }
  345. /**
  346. * There is no attached fabric - private loop or NPort-to-NPort topology.
  347. */
  348. static void
  349. bfa_fcs_fabric_sm_nofabric(struct bfa_fcs_fabric_s *fabric,
  350. enum bfa_fcs_fabric_event event)
  351. {
  352. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  353. bfa_trc(fabric->fcs, event);
  354. switch (event) {
  355. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  356. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  357. bfa_lps_discard(fabric->lps);
  358. bfa_fcs_fabric_notify_offline(fabric);
  359. break;
  360. case BFA_FCS_FABRIC_SM_DELETE:
  361. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  362. bfa_fcs_fabric_delete(fabric);
  363. break;
  364. case BFA_FCS_FABRIC_SM_NO_FABRIC:
  365. bfa_trc(fabric->fcs, fabric->bb_credit);
  366. bfa_pport_set_tx_bbcredit(fabric->fcs->bfa, fabric->bb_credit);
  367. break;
  368. default:
  369. bfa_sm_fault(fabric->fcs, event);
  370. }
  371. }
  372. /**
  373. * Fabric is online - normal operating state.
  374. */
  375. static void
  376. bfa_fcs_fabric_sm_online(struct bfa_fcs_fabric_s *fabric,
  377. enum bfa_fcs_fabric_event event)
  378. {
  379. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  380. bfa_trc(fabric->fcs, event);
  381. switch (event) {
  382. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  383. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_linkdown);
  384. bfa_lps_discard(fabric->lps);
  385. bfa_fcs_fabric_notify_offline(fabric);
  386. break;
  387. case BFA_FCS_FABRIC_SM_DELETE:
  388. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_deleting);
  389. bfa_fcs_fabric_delete(fabric);
  390. break;
  391. case BFA_FCS_FABRIC_SM_AUTH_FAILED:
  392. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_auth_failed);
  393. bfa_lps_discard(fabric->lps);
  394. break;
  395. case BFA_FCS_FABRIC_SM_AUTH_SUCCESS:
  396. break;
  397. default:
  398. bfa_sm_fault(fabric->fcs, event);
  399. }
  400. }
  401. /**
  402. * Exchanging virtual fabric parameters.
  403. */
  404. static void
  405. bfa_fcs_fabric_sm_evfp(struct bfa_fcs_fabric_s *fabric,
  406. enum bfa_fcs_fabric_event event)
  407. {
  408. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  409. bfa_trc(fabric->fcs, event);
  410. switch (event) {
  411. case BFA_FCS_FABRIC_SM_CONT_OP:
  412. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_evfp_done);
  413. break;
  414. case BFA_FCS_FABRIC_SM_ISOLATE:
  415. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_isolated);
  416. break;
  417. default:
  418. bfa_sm_fault(fabric->fcs, event);
  419. }
  420. }
  421. /**
  422. * EVFP exchange complete and VFT tagging is enabled.
  423. */
  424. static void
  425. bfa_fcs_fabric_sm_evfp_done(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. }
  431. /**
  432. * Port is isolated after EVFP exchange due to VF_ID mismatch (N and F).
  433. */
  434. static void
  435. bfa_fcs_fabric_sm_isolated(struct bfa_fcs_fabric_s *fabric,
  436. enum bfa_fcs_fabric_event event)
  437. {
  438. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  439. bfa_trc(fabric->fcs, event);
  440. bfa_log(fabric->fcs->logm, BFA_LOG_FCS_FABRIC_ISOLATED,
  441. fabric->bport.port_cfg.pwwn, fabric->fcs->port_vfid,
  442. fabric->event_arg.swp_vfid);
  443. }
  444. /**
  445. * Fabric is being deleted, awaiting vport delete completions.
  446. */
  447. static void
  448. bfa_fcs_fabric_sm_deleting(struct bfa_fcs_fabric_s *fabric,
  449. enum bfa_fcs_fabric_event event)
  450. {
  451. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  452. bfa_trc(fabric->fcs, event);
  453. switch (event) {
  454. case BFA_FCS_FABRIC_SM_DELCOMP:
  455. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
  456. bfa_fcs_modexit_comp(fabric->fcs);
  457. break;
  458. case BFA_FCS_FABRIC_SM_LINK_UP:
  459. break;
  460. case BFA_FCS_FABRIC_SM_LINK_DOWN:
  461. bfa_fcs_fabric_notify_offline(fabric);
  462. break;
  463. default:
  464. bfa_sm_fault(fabric->fcs, event);
  465. }
  466. }
  467. /**
  468. * fcs_fabric_private fabric private functions
  469. */
  470. static void
  471. bfa_fcs_fabric_init(struct bfa_fcs_fabric_s *fabric)
  472. {
  473. struct bfa_port_cfg_s *port_cfg = &fabric->bport.port_cfg;
  474. port_cfg->roles = BFA_PORT_ROLE_FCP_IM;
  475. port_cfg->nwwn = bfa_ioc_get_nwwn(&fabric->fcs->bfa->ioc);
  476. port_cfg->pwwn = bfa_ioc_get_pwwn(&fabric->fcs->bfa->ioc);
  477. }
  478. /**
  479. * Port Symbolic Name Creation for base port.
  480. */
  481. void
  482. bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
  483. {
  484. struct bfa_port_cfg_s *port_cfg = &fabric->bport.port_cfg;
  485. struct bfa_adapter_attr_s adapter_attr;
  486. struct bfa_fcs_driver_info_s *driver_info = &fabric->fcs->driver_info;
  487. bfa_os_memset((void *)&adapter_attr, 0,
  488. sizeof(struct bfa_adapter_attr_s));
  489. bfa_ioc_get_adapter_attr(&fabric->fcs->bfa->ioc, &adapter_attr);
  490. /*
  491. * Model name/number
  492. */
  493. strncpy((char *)&port_cfg->sym_name, adapter_attr.model,
  494. BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
  495. strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  496. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  497. /*
  498. * Driver Version
  499. */
  500. strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
  501. BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
  502. strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  503. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  504. /*
  505. * Host machine name
  506. */
  507. strncat((char *)&port_cfg->sym_name,
  508. (char *)driver_info->host_machine_name,
  509. BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
  510. strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  511. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  512. /*
  513. * Host OS Info :
  514. * If OS Patch Info is not there, do not truncate any bytes from the
  515. * OS name string and instead copy the entire OS info string (64 bytes).
  516. */
  517. if (driver_info->host_os_patch[0] == '\0') {
  518. strncat((char *)&port_cfg->sym_name,
  519. (char *)driver_info->host_os_name, BFA_FCS_OS_STR_LEN);
  520. strncat((char *)&port_cfg->sym_name,
  521. BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  522. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  523. } else {
  524. strncat((char *)&port_cfg->sym_name,
  525. (char *)driver_info->host_os_name,
  526. BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
  527. strncat((char *)&port_cfg->sym_name,
  528. BFA_FCS_PORT_SYMBNAME_SEPARATOR,
  529. sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
  530. /*
  531. * Append host OS Patch Info
  532. */
  533. strncat((char *)&port_cfg->sym_name,
  534. (char *)driver_info->host_os_patch,
  535. BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
  536. }
  537. /*
  538. * null terminate
  539. */
  540. port_cfg->sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
  541. }
  542. /**
  543. * bfa lps login completion callback
  544. */
  545. void
  546. bfa_cb_lps_flogi_comp(void *bfad, void *uarg, bfa_status_t status)
  547. {
  548. struct bfa_fcs_fabric_s *fabric = uarg;
  549. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  550. bfa_trc(fabric->fcs, status);
  551. switch (status) {
  552. case BFA_STATUS_OK:
  553. fabric->stats.flogi_accepts++;
  554. break;
  555. case BFA_STATUS_INVALID_MAC:
  556. /*
  557. * Only for CNA
  558. */
  559. fabric->stats.flogi_acc_err++;
  560. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  561. return;
  562. case BFA_STATUS_EPROTOCOL:
  563. switch (bfa_lps_get_extstatus(fabric->lps)) {
  564. case BFA_EPROTO_BAD_ACCEPT:
  565. fabric->stats.flogi_acc_err++;
  566. break;
  567. case BFA_EPROTO_UNKNOWN_RSP:
  568. fabric->stats.flogi_unknown_rsp++;
  569. break;
  570. default:
  571. break;
  572. }
  573. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  574. return;
  575. case BFA_STATUS_FABRIC_RJT:
  576. fabric->stats.flogi_rejects++;
  577. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  578. return;
  579. default:
  580. fabric->stats.flogi_rsp_err++;
  581. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_RETRY_OP);
  582. return;
  583. }
  584. fabric->bb_credit = bfa_lps_get_peer_bbcredit(fabric->lps);
  585. bfa_trc(fabric->fcs, fabric->bb_credit);
  586. if (!bfa_lps_is_brcd_fabric(fabric->lps))
  587. fabric->fabric_name = bfa_lps_get_peer_nwwn(fabric->lps);
  588. /*
  589. * Check port type. It should be 1 = F-port.
  590. */
  591. if (bfa_lps_is_fport(fabric->lps)) {
  592. fabric->bport.pid = bfa_lps_get_pid(fabric->lps);
  593. fabric->is_npiv = bfa_lps_is_npiv_en(fabric->lps);
  594. fabric->is_auth = bfa_lps_is_authreq(fabric->lps);
  595. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CONT_OP);
  596. } else {
  597. /*
  598. * Nport-2-Nport direct attached
  599. */
  600. fabric->bport.port_topo.pn2n.rem_port_wwn =
  601. bfa_lps_get_peer_pwwn(fabric->lps);
  602. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
  603. }
  604. bfa_trc(fabric->fcs, fabric->bport.pid);
  605. bfa_trc(fabric->fcs, fabric->is_npiv);
  606. bfa_trc(fabric->fcs, fabric->is_auth);
  607. }
  608. /**
  609. * Allocate and send FLOGI.
  610. */
  611. static void
  612. bfa_fcs_fabric_login(struct bfa_fcs_fabric_s *fabric)
  613. {
  614. struct bfa_s *bfa = fabric->fcs->bfa;
  615. struct bfa_port_cfg_s *pcfg = &fabric->bport.port_cfg;
  616. u8 alpa = 0;
  617. if (bfa_pport_get_topology(bfa) == BFA_PPORT_TOPOLOGY_LOOP)
  618. alpa = bfa_pport_get_myalpa(bfa);
  619. bfa_lps_flogi(fabric->lps, fabric, alpa, bfa_pport_get_maxfrsize(bfa),
  620. pcfg->pwwn, pcfg->nwwn, fabric->auth_reqd);
  621. fabric->stats.flogi_sent++;
  622. }
  623. static void
  624. bfa_fcs_fabric_notify_online(struct bfa_fcs_fabric_s *fabric)
  625. {
  626. struct bfa_fcs_vport_s *vport;
  627. struct list_head *qe, *qen;
  628. bfa_trc(fabric->fcs, fabric->fabric_name);
  629. bfa_fcs_fabric_set_opertype(fabric);
  630. fabric->stats.fabric_onlines++;
  631. /**
  632. * notify online event to base and then virtual ports
  633. */
  634. bfa_fcs_port_online(&fabric->bport);
  635. list_for_each_safe(qe, qen, &fabric->vport_q) {
  636. vport = (struct bfa_fcs_vport_s *)qe;
  637. bfa_fcs_vport_online(vport);
  638. }
  639. }
  640. static void
  641. bfa_fcs_fabric_notify_offline(struct bfa_fcs_fabric_s *fabric)
  642. {
  643. struct bfa_fcs_vport_s *vport;
  644. struct list_head *qe, *qen;
  645. bfa_trc(fabric->fcs, fabric->fabric_name);
  646. fabric->stats.fabric_offlines++;
  647. /**
  648. * notify offline event first to vports and then base port.
  649. */
  650. list_for_each_safe(qe, qen, &fabric->vport_q) {
  651. vport = (struct bfa_fcs_vport_s *)qe;
  652. bfa_fcs_vport_offline(vport);
  653. }
  654. bfa_fcs_port_offline(&fabric->bport);
  655. fabric->fabric_name = 0;
  656. fabric->fabric_ip_addr[0] = 0;
  657. }
  658. static void
  659. bfa_fcs_fabric_delay(void *cbarg)
  660. {
  661. struct bfa_fcs_fabric_s *fabric = cbarg;
  662. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELAYED);
  663. }
  664. /**
  665. * Delete all vports and wait for vport delete completions.
  666. */
  667. static void
  668. bfa_fcs_fabric_delete(struct bfa_fcs_fabric_s *fabric)
  669. {
  670. struct bfa_fcs_vport_s *vport;
  671. struct list_head *qe, *qen;
  672. list_for_each_safe(qe, qen, &fabric->vport_q) {
  673. vport = (struct bfa_fcs_vport_s *)qe;
  674. bfa_fcs_vport_delete(vport);
  675. }
  676. bfa_fcs_port_delete(&fabric->bport);
  677. bfa_wc_wait(&fabric->wc);
  678. }
  679. static void
  680. bfa_fcs_fabric_delete_comp(void *cbarg)
  681. {
  682. struct bfa_fcs_fabric_s *fabric = cbarg;
  683. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELCOMP);
  684. }
  685. /**
  686. * fcs_fabric_public fabric public functions
  687. */
  688. /**
  689. * Module initialization
  690. */
  691. void
  692. bfa_fcs_fabric_modinit(struct bfa_fcs_s *fcs)
  693. {
  694. struct bfa_fcs_fabric_s *fabric;
  695. fabric = &fcs->fabric;
  696. bfa_os_memset(fabric, 0, sizeof(struct bfa_fcs_fabric_s));
  697. /**
  698. * Initialize base fabric.
  699. */
  700. fabric->fcs = fcs;
  701. INIT_LIST_HEAD(&fabric->vport_q);
  702. INIT_LIST_HEAD(&fabric->vf_q);
  703. fabric->lps = bfa_lps_alloc(fcs->bfa);
  704. bfa_assert(fabric->lps);
  705. /**
  706. * Initialize fabric delete completion handler. Fabric deletion is complete
  707. * when the last vport delete is complete.
  708. */
  709. bfa_wc_init(&fabric->wc, bfa_fcs_fabric_delete_comp, fabric);
  710. bfa_wc_up(&fabric->wc); /* For the base port */
  711. bfa_sm_set_state(fabric, bfa_fcs_fabric_sm_uninit);
  712. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_CREATE);
  713. bfa_trc(fcs, 0);
  714. }
  715. /**
  716. * Module cleanup
  717. */
  718. void
  719. bfa_fcs_fabric_modexit(struct bfa_fcs_s *fcs)
  720. {
  721. struct bfa_fcs_fabric_s *fabric;
  722. bfa_trc(fcs, 0);
  723. /**
  724. * Cleanup base fabric.
  725. */
  726. fabric = &fcs->fabric;
  727. bfa_lps_delete(fabric->lps);
  728. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_DELETE);
  729. }
  730. /**
  731. * Fabric module start -- kick starts FCS actions
  732. */
  733. void
  734. bfa_fcs_fabric_modstart(struct bfa_fcs_s *fcs)
  735. {
  736. struct bfa_fcs_fabric_s *fabric;
  737. bfa_trc(fcs, 0);
  738. fabric = &fcs->fabric;
  739. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_START);
  740. }
  741. /**
  742. * Suspend fabric activity as part of driver suspend.
  743. */
  744. void
  745. bfa_fcs_fabric_modsusp(struct bfa_fcs_s *fcs)
  746. {
  747. }
  748. bfa_boolean_t
  749. bfa_fcs_fabric_is_loopback(struct bfa_fcs_fabric_s *fabric)
  750. {
  751. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_loopback);
  752. }
  753. enum bfa_pport_type
  754. bfa_fcs_fabric_port_type(struct bfa_fcs_fabric_s *fabric)
  755. {
  756. return fabric->oper_type;
  757. }
  758. /**
  759. * Link up notification from BFA physical port module.
  760. */
  761. void
  762. bfa_fcs_fabric_link_up(struct bfa_fcs_fabric_s *fabric)
  763. {
  764. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  765. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_UP);
  766. }
  767. /**
  768. * Link down notification from BFA physical port module.
  769. */
  770. void
  771. bfa_fcs_fabric_link_down(struct bfa_fcs_fabric_s *fabric)
  772. {
  773. bfa_trc(fabric->fcs, fabric->bport.port_cfg.pwwn);
  774. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LINK_DOWN);
  775. }
  776. /**
  777. * A child vport is being created in the fabric.
  778. *
  779. * Call from vport module at vport creation. A list of base port and vports
  780. * belonging to a fabric is maintained to propagate link events.
  781. *
  782. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  783. * param[in] vport - Vport being created.
  784. *
  785. * @return None (always succeeds)
  786. */
  787. void
  788. bfa_fcs_fabric_addvport(struct bfa_fcs_fabric_s *fabric,
  789. struct bfa_fcs_vport_s *vport)
  790. {
  791. /**
  792. * - add vport to fabric's vport_q
  793. */
  794. bfa_trc(fabric->fcs, fabric->vf_id);
  795. list_add_tail(&vport->qe, &fabric->vport_q);
  796. fabric->num_vports++;
  797. bfa_wc_up(&fabric->wc);
  798. }
  799. /**
  800. * A child vport is being deleted from fabric.
  801. *
  802. * Vport is being deleted.
  803. */
  804. void
  805. bfa_fcs_fabric_delvport(struct bfa_fcs_fabric_s *fabric,
  806. struct bfa_fcs_vport_s *vport)
  807. {
  808. list_del(&vport->qe);
  809. fabric->num_vports--;
  810. bfa_wc_down(&fabric->wc);
  811. }
  812. /**
  813. * Base port is deleted.
  814. */
  815. void
  816. bfa_fcs_fabric_port_delete_comp(struct bfa_fcs_fabric_s *fabric)
  817. {
  818. bfa_wc_down(&fabric->wc);
  819. }
  820. /**
  821. * Check if fabric is online.
  822. *
  823. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  824. *
  825. * @return TRUE/FALSE
  826. */
  827. int
  828. bfa_fcs_fabric_is_online(struct bfa_fcs_fabric_s *fabric)
  829. {
  830. return bfa_sm_cmp_state(fabric, bfa_fcs_fabric_sm_online);
  831. }
  832. bfa_status_t
  833. bfa_fcs_fabric_addvf(struct bfa_fcs_fabric_s *vf, struct bfa_fcs_s *fcs,
  834. struct bfa_port_cfg_s *port_cfg,
  835. struct bfad_vf_s *vf_drv)
  836. {
  837. bfa_sm_set_state(vf, bfa_fcs_fabric_sm_uninit);
  838. return BFA_STATUS_OK;
  839. }
  840. /**
  841. * Lookup for a vport withing a fabric given its pwwn
  842. */
  843. struct bfa_fcs_vport_s *
  844. bfa_fcs_fabric_vport_lookup(struct bfa_fcs_fabric_s *fabric, wwn_t pwwn)
  845. {
  846. struct bfa_fcs_vport_s *vport;
  847. struct list_head *qe;
  848. list_for_each(qe, &fabric->vport_q) {
  849. vport = (struct bfa_fcs_vport_s *)qe;
  850. if (bfa_fcs_port_get_pwwn(&vport->lport) == pwwn)
  851. return vport;
  852. }
  853. return NULL;
  854. }
  855. /**
  856. * In a given fabric, return the number of lports.
  857. *
  858. * param[in] fabric - Fabric instance. This can be a base fabric or vf.
  859. *
  860. * @return : 1 or more.
  861. */
  862. u16
  863. bfa_fcs_fabric_vport_count(struct bfa_fcs_fabric_s *fabric)
  864. {
  865. return fabric->num_vports;
  866. }
  867. /**
  868. * Unsolicited frame receive handling.
  869. */
  870. void
  871. bfa_fcs_fabric_uf_recv(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
  872. u16 len)
  873. {
  874. u32 pid = fchs->d_id;
  875. struct bfa_fcs_vport_s *vport;
  876. struct list_head *qe;
  877. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  878. struct fc_logi_s *flogi = (struct fc_logi_s *) els_cmd;
  879. bfa_trc(fabric->fcs, len);
  880. bfa_trc(fabric->fcs, pid);
  881. /**
  882. * Look for our own FLOGI frames being looped back. This means an
  883. * external loopback cable is in place. Our own FLOGI frames are
  884. * sometimes looped back when switch port gets temporarily bypassed.
  885. */
  886. if ((pid == bfa_os_ntoh3b(FC_FABRIC_PORT))
  887. && (els_cmd->els_code == FC_ELS_FLOGI)
  888. && (flogi->port_name == bfa_fcs_port_get_pwwn(&fabric->bport))) {
  889. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_LOOPBACK);
  890. return;
  891. }
  892. /**
  893. * FLOGI/EVFP exchanges should be consumed by base fabric.
  894. */
  895. if (fchs->d_id == bfa_os_hton3b(FC_FABRIC_PORT)) {
  896. bfa_trc(fabric->fcs, pid);
  897. bfa_fcs_fabric_process_uf(fabric, fchs, len);
  898. return;
  899. }
  900. if (fabric->bport.pid == pid) {
  901. /**
  902. * All authentication frames should be routed to auth
  903. */
  904. bfa_trc(fabric->fcs, els_cmd->els_code);
  905. if (els_cmd->els_code == FC_ELS_AUTH) {
  906. bfa_trc(fabric->fcs, els_cmd->els_code);
  907. fabric->auth.response = (u8 *) els_cmd;
  908. return;
  909. }
  910. bfa_trc(fabric->fcs, *(u8 *) ((u8 *) fchs));
  911. bfa_fcs_port_uf_recv(&fabric->bport, fchs, len);
  912. return;
  913. }
  914. /**
  915. * look for a matching local port ID
  916. */
  917. list_for_each(qe, &fabric->vport_q) {
  918. vport = (struct bfa_fcs_vport_s *)qe;
  919. if (vport->lport.pid == pid) {
  920. bfa_fcs_port_uf_recv(&vport->lport, fchs, len);
  921. return;
  922. }
  923. }
  924. bfa_trc(fabric->fcs, els_cmd->els_code);
  925. bfa_fcs_port_uf_recv(&fabric->bport, fchs, len);
  926. }
  927. /**
  928. * Unsolicited frames to be processed by fabric.
  929. */
  930. static void
  931. bfa_fcs_fabric_process_uf(struct bfa_fcs_fabric_s *fabric, struct fchs_s *fchs,
  932. u16 len)
  933. {
  934. struct fc_els_cmd_s *els_cmd = (struct fc_els_cmd_s *) (fchs + 1);
  935. bfa_trc(fabric->fcs, els_cmd->els_code);
  936. switch (els_cmd->els_code) {
  937. case FC_ELS_FLOGI:
  938. bfa_fcs_fabric_process_flogi(fabric, fchs, len);
  939. break;
  940. default:
  941. /*
  942. * need to generate a LS_RJT
  943. */
  944. break;
  945. }
  946. }
  947. /**
  948. * Process incoming FLOGI
  949. */
  950. static void
  951. bfa_fcs_fabric_process_flogi(struct bfa_fcs_fabric_s *fabric,
  952. struct fchs_s *fchs, u16 len)
  953. {
  954. struct fc_logi_s *flogi = (struct fc_logi_s *) (fchs + 1);
  955. struct bfa_fcs_port_s *bport = &fabric->bport;
  956. bfa_trc(fabric->fcs, fchs->s_id);
  957. fabric->stats.flogi_rcvd++;
  958. /*
  959. * Check port type. It should be 0 = n-port.
  960. */
  961. if (flogi->csp.port_type) {
  962. /*
  963. * @todo: may need to send a LS_RJT
  964. */
  965. bfa_trc(fabric->fcs, flogi->port_name);
  966. fabric->stats.flogi_rejected++;
  967. return;
  968. }
  969. fabric->bb_credit = bfa_os_ntohs(flogi->csp.bbcred);
  970. bport->port_topo.pn2n.rem_port_wwn = flogi->port_name;
  971. bport->port_topo.pn2n.reply_oxid = fchs->ox_id;
  972. /*
  973. * Send a Flogi Acc
  974. */
  975. bfa_fcs_fabric_send_flogi_acc(fabric);
  976. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_NO_FABRIC);
  977. }
  978. static void
  979. bfa_fcs_fabric_send_flogi_acc(struct bfa_fcs_fabric_s *fabric)
  980. {
  981. struct bfa_port_cfg_s *pcfg = &fabric->bport.port_cfg;
  982. struct bfa_fcs_port_n2n_s *n2n_port = &fabric->bport.port_topo.pn2n;
  983. struct bfa_s *bfa = fabric->fcs->bfa;
  984. struct bfa_fcxp_s *fcxp;
  985. u16 reqlen;
  986. struct fchs_s fchs;
  987. fcxp = bfa_fcs_fcxp_alloc(fabric->fcs);
  988. /**
  989. * Do not expect this failure -- expect remote node to retry
  990. */
  991. if (!fcxp)
  992. return;
  993. reqlen = fc_flogi_acc_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
  994. bfa_os_hton3b(FC_FABRIC_PORT),
  995. n2n_port->reply_oxid, pcfg->pwwn,
  996. pcfg->nwwn, bfa_pport_get_maxfrsize(bfa),
  997. bfa_pport_get_rx_bbcredit(bfa));
  998. bfa_fcxp_send(fcxp, NULL, fabric->vf_id, bfa_lps_get_tag(fabric->lps),
  999. BFA_FALSE, FC_CLASS_3, reqlen, &fchs,
  1000. bfa_fcs_fabric_flogiacc_comp, fabric,
  1001. FC_MAX_PDUSZ, 0); /* Timeout 0 indicates no
  1002. * response expected
  1003. */
  1004. }
  1005. /**
  1006. * Flogi Acc completion callback.
  1007. */
  1008. static void
  1009. bfa_fcs_fabric_flogiacc_comp(void *fcsarg, struct bfa_fcxp_s *fcxp, void *cbarg,
  1010. bfa_status_t status, u32 rsp_len,
  1011. u32 resid_len, struct fchs_s *rspfchs)
  1012. {
  1013. struct bfa_fcs_fabric_s *fabric = cbarg;
  1014. bfa_trc(fabric->fcs, status);
  1015. }
  1016. /*
  1017. *
  1018. * @param[in] fabric - fabric
  1019. * @param[in] result - 1
  1020. *
  1021. * @return - none
  1022. */
  1023. void
  1024. bfa_fcs_auth_finished(struct bfa_fcs_fabric_s *fabric, enum auth_status status)
  1025. {
  1026. bfa_trc(fabric->fcs, status);
  1027. if (status == FC_AUTH_STATE_SUCCESS)
  1028. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_AUTH_SUCCESS);
  1029. else
  1030. bfa_sm_send_event(fabric, BFA_FCS_FABRIC_SM_AUTH_FAILED);
  1031. }
  1032. /**
  1033. * Send AEN notification
  1034. */
  1035. static void
  1036. bfa_fcs_fabric_aen_post(struct bfa_fcs_port_s *port,
  1037. enum bfa_port_aen_event event)
  1038. {
  1039. union bfa_aen_data_u aen_data;
  1040. struct bfa_log_mod_s *logmod = port->fcs->logm;
  1041. wwn_t pwwn = bfa_fcs_port_get_pwwn(port);
  1042. wwn_t fwwn = bfa_fcs_port_get_fabric_name(port);
  1043. char pwwn_ptr[BFA_STRING_32];
  1044. char fwwn_ptr[BFA_STRING_32];
  1045. wwn2str(pwwn_ptr, pwwn);
  1046. wwn2str(fwwn_ptr, fwwn);
  1047. switch (event) {
  1048. case BFA_PORT_AEN_FABRIC_NAME_CHANGE:
  1049. bfa_log(logmod, BFA_AEN_PORT_FABRIC_NAME_CHANGE, pwwn_ptr,
  1050. fwwn_ptr);
  1051. break;
  1052. default:
  1053. break;
  1054. }
  1055. aen_data.port.pwwn = pwwn;
  1056. aen_data.port.fwwn = fwwn;
  1057. }
  1058. /*
  1059. *
  1060. * @param[in] fabric - fabric
  1061. * @param[in] wwn_t - new fabric name
  1062. *
  1063. * @return - none
  1064. */
  1065. void
  1066. bfa_fcs_fabric_set_fabric_name(struct bfa_fcs_fabric_s *fabric,
  1067. wwn_t fabric_name)
  1068. {
  1069. bfa_trc(fabric->fcs, fabric_name);
  1070. if (fabric->fabric_name == 0) {
  1071. /*
  1072. * With BRCD switches, we don't get Fabric Name in FLOGI.
  1073. * Don't generate a fabric name change event in this case.
  1074. */
  1075. fabric->fabric_name = fabric_name;
  1076. } else {
  1077. fabric->fabric_name = fabric_name;
  1078. /*
  1079. * Generate a Event
  1080. */
  1081. bfa_fcs_fabric_aen_post(&fabric->bport,
  1082. BFA_PORT_AEN_FABRIC_NAME_CHANGE);
  1083. }
  1084. }
  1085. /**
  1086. * Not used by FCS.
  1087. */
  1088. void
  1089. bfa_cb_lps_flogo_comp(void *bfad, void *uarg)
  1090. {
  1091. }