fabric.c 32 KB

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