bfa_fcs.c 39 KB

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