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->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. * Attach time initialization
  690. */
  691. void
  692. bfa_fcs_fabric_attach(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. }
  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. }