bfa_fcs.c 39 KB

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