bfa_fcport.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. /*
  2. * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
  3. * All rights reserved
  4. * www.brocade.com
  5. *
  6. * Linux driver for Brocade Fibre Channel Host Bus Adapter.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License (GPL) Version 2 as
  10. * published by the Free Software Foundation
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. */
  17. #include <bfa.h>
  18. #include <bfa_svc.h>
  19. #include <bfi/bfi_pport.h>
  20. #include <cs/bfa_debug.h>
  21. #include <aen/bfa_aen.h>
  22. #include <cs/bfa_plog.h>
  23. #include <aen/bfa_aen_port.h>
  24. BFA_TRC_FILE(HAL, FCPORT);
  25. BFA_MODULE(fcport);
  26. /*
  27. * The port is considered disabled if corresponding physical port or IOC are
  28. * disabled explicitly
  29. */
  30. #define BFA_PORT_IS_DISABLED(bfa) \
  31. ((bfa_fcport_is_disabled(bfa) == BFA_TRUE) || \
  32. (bfa_ioc_is_disabled(&bfa->ioc) == BFA_TRUE))
  33. /*
  34. * forward declarations
  35. */
  36. static bfa_boolean_t bfa_fcport_send_enable(struct bfa_fcport_s *fcport);
  37. static bfa_boolean_t bfa_fcport_send_disable(struct bfa_fcport_s *fcport);
  38. static void bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport);
  39. static void bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport);
  40. static void bfa_fcport_set_wwns(struct bfa_fcport_s *fcport);
  41. static void __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete);
  42. static void bfa_fcport_callback(struct bfa_fcport_s *fcport,
  43. enum bfa_pport_linkstate event);
  44. static void bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln,
  45. enum bfa_pport_linkstate event);
  46. static void __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete);
  47. static void bfa_fcport_stats_get_timeout(void *cbarg);
  48. static void bfa_fcport_stats_clr_timeout(void *cbarg);
  49. /**
  50. * bfa_pport_private
  51. */
  52. /**
  53. * BFA port state machine events
  54. */
  55. enum bfa_fcport_sm_event {
  56. BFA_FCPORT_SM_START = 1, /* start port state machine */
  57. BFA_FCPORT_SM_STOP = 2, /* stop port state machine */
  58. BFA_FCPORT_SM_ENABLE = 3, /* enable port */
  59. BFA_FCPORT_SM_DISABLE = 4, /* disable port state machine */
  60. BFA_FCPORT_SM_FWRSP = 5, /* firmware enable/disable rsp */
  61. BFA_FCPORT_SM_LINKUP = 6, /* firmware linkup event */
  62. BFA_FCPORT_SM_LINKDOWN = 7, /* firmware linkup down */
  63. BFA_FCPORT_SM_QRESUME = 8, /* CQ space available */
  64. BFA_FCPORT_SM_HWFAIL = 9, /* IOC h/w failure */
  65. };
  66. /**
  67. * BFA port link notification state machine events
  68. */
  69. enum bfa_fcport_ln_sm_event {
  70. BFA_FCPORT_LN_SM_LINKUP = 1, /* linkup event */
  71. BFA_FCPORT_LN_SM_LINKDOWN = 2, /* linkdown event */
  72. BFA_FCPORT_LN_SM_NOTIFICATION = 3 /* done notification */
  73. };
  74. static void bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  75. enum bfa_fcport_sm_event event);
  76. static void bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  77. enum bfa_fcport_sm_event event);
  78. static void bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  79. enum bfa_fcport_sm_event event);
  80. static void bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  81. enum bfa_fcport_sm_event event);
  82. static void bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  83. enum bfa_fcport_sm_event event);
  84. static void bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  85. enum bfa_fcport_sm_event event);
  86. static void bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  87. enum bfa_fcport_sm_event event);
  88. static void bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  89. enum bfa_fcport_sm_event event);
  90. static void bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  91. enum bfa_fcport_sm_event event);
  92. static void bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  93. enum bfa_fcport_sm_event event);
  94. static void bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  95. enum bfa_fcport_sm_event event);
  96. static void bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  97. enum bfa_fcport_ln_sm_event event);
  98. static void bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  99. enum bfa_fcport_ln_sm_event event);
  100. static void bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  101. enum bfa_fcport_ln_sm_event event);
  102. static void bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  103. enum bfa_fcport_ln_sm_event event);
  104. static void bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  105. enum bfa_fcport_ln_sm_event event);
  106. static void bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  107. enum bfa_fcport_ln_sm_event event);
  108. static void bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  109. enum bfa_fcport_ln_sm_event event);
  110. static struct bfa_sm_table_s hal_pport_sm_table[] = {
  111. {BFA_SM(bfa_fcport_sm_uninit), BFA_PPORT_ST_UNINIT},
  112. {BFA_SM(bfa_fcport_sm_enabling_qwait), BFA_PPORT_ST_ENABLING_QWAIT},
  113. {BFA_SM(bfa_fcport_sm_enabling), BFA_PPORT_ST_ENABLING},
  114. {BFA_SM(bfa_fcport_sm_linkdown), BFA_PPORT_ST_LINKDOWN},
  115. {BFA_SM(bfa_fcport_sm_linkup), BFA_PPORT_ST_LINKUP},
  116. {BFA_SM(bfa_fcport_sm_disabling_qwait), BFA_PPORT_ST_DISABLING_QWAIT},
  117. {BFA_SM(bfa_fcport_sm_disabling), BFA_PPORT_ST_DISABLING},
  118. {BFA_SM(bfa_fcport_sm_disabled), BFA_PPORT_ST_DISABLED},
  119. {BFA_SM(bfa_fcport_sm_stopped), BFA_PPORT_ST_STOPPED},
  120. {BFA_SM(bfa_fcport_sm_iocdown), BFA_PPORT_ST_IOCDOWN},
  121. {BFA_SM(bfa_fcport_sm_iocfail), BFA_PPORT_ST_IOCDOWN},
  122. };
  123. static void
  124. bfa_fcport_aen_post(struct bfa_fcport_s *fcport, enum bfa_port_aen_event event)
  125. {
  126. union bfa_aen_data_u aen_data;
  127. struct bfa_log_mod_s *logmod = fcport->bfa->logm;
  128. wwn_t pwwn = fcport->pwwn;
  129. char pwwn_ptr[BFA_STRING_32];
  130. memset(&aen_data, 0, sizeof(aen_data));
  131. wwn2str(pwwn_ptr, pwwn);
  132. bfa_log(logmod, BFA_LOG_CREATE_ID(BFA_AEN_CAT_PORT, event), pwwn_ptr);
  133. aen_data.port.ioc_type = bfa_get_type(fcport->bfa);
  134. aen_data.port.pwwn = pwwn;
  135. }
  136. static void
  137. bfa_fcport_sm_uninit(struct bfa_fcport_s *fcport,
  138. enum bfa_fcport_sm_event event)
  139. {
  140. bfa_trc(fcport->bfa, event);
  141. switch (event) {
  142. case BFA_FCPORT_SM_START:
  143. /**
  144. * Start event after IOC is configured and BFA is started.
  145. */
  146. if (bfa_fcport_send_enable(fcport))
  147. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  148. else
  149. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
  150. break;
  151. case BFA_FCPORT_SM_ENABLE:
  152. /**
  153. * Port is persistently configured to be in enabled state. Do
  154. * not change state. Port enabling is done when START event is
  155. * received.
  156. */
  157. break;
  158. case BFA_FCPORT_SM_DISABLE:
  159. /**
  160. * If a port is persistently configured to be disabled, the
  161. * first event will a port disable request.
  162. */
  163. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  164. break;
  165. case BFA_FCPORT_SM_HWFAIL:
  166. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  167. break;
  168. default:
  169. bfa_sm_fault(fcport->bfa, event);
  170. }
  171. }
  172. static void
  173. bfa_fcport_sm_enabling_qwait(struct bfa_fcport_s *fcport,
  174. enum bfa_fcport_sm_event event)
  175. {
  176. bfa_trc(fcport->bfa, event);
  177. switch (event) {
  178. case BFA_FCPORT_SM_QRESUME:
  179. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  180. bfa_fcport_send_enable(fcport);
  181. break;
  182. case BFA_FCPORT_SM_STOP:
  183. bfa_reqq_wcancel(&fcport->reqq_wait);
  184. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  185. break;
  186. case BFA_FCPORT_SM_ENABLE:
  187. /**
  188. * Already enable is in progress.
  189. */
  190. break;
  191. case BFA_FCPORT_SM_DISABLE:
  192. /**
  193. * Just send disable request to firmware when room becomes
  194. * available in request queue.
  195. */
  196. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  197. bfa_reqq_wcancel(&fcport->reqq_wait);
  198. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  199. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  200. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  201. break;
  202. case BFA_FCPORT_SM_LINKUP:
  203. case BFA_FCPORT_SM_LINKDOWN:
  204. /**
  205. * Possible to get link events when doing back-to-back
  206. * enable/disables.
  207. */
  208. break;
  209. case BFA_FCPORT_SM_HWFAIL:
  210. bfa_reqq_wcancel(&fcport->reqq_wait);
  211. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  212. break;
  213. default:
  214. bfa_sm_fault(fcport->bfa, event);
  215. }
  216. }
  217. static void
  218. bfa_fcport_sm_enabling(struct bfa_fcport_s *fcport,
  219. enum bfa_fcport_sm_event event)
  220. {
  221. bfa_trc(fcport->bfa, event);
  222. switch (event) {
  223. case BFA_FCPORT_SM_FWRSP:
  224. case BFA_FCPORT_SM_LINKDOWN:
  225. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  226. break;
  227. case BFA_FCPORT_SM_LINKUP:
  228. bfa_fcport_update_linkinfo(fcport);
  229. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  230. bfa_assert(fcport->event_cbfn);
  231. bfa_fcport_callback(fcport, BFA_PPORT_LINKUP);
  232. break;
  233. case BFA_FCPORT_SM_ENABLE:
  234. /**
  235. * Already being enabled.
  236. */
  237. break;
  238. case BFA_FCPORT_SM_DISABLE:
  239. if (bfa_fcport_send_disable(fcport))
  240. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  241. else
  242. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  243. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  244. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  245. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  246. break;
  247. case BFA_FCPORT_SM_STOP:
  248. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  249. break;
  250. case BFA_FCPORT_SM_HWFAIL:
  251. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  252. break;
  253. default:
  254. bfa_sm_fault(fcport->bfa, event);
  255. }
  256. }
  257. static void
  258. bfa_fcport_sm_linkdown(struct bfa_fcport_s *fcport,
  259. enum bfa_fcport_sm_event event)
  260. {
  261. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  262. bfa_trc(fcport->bfa, event);
  263. switch (event) {
  264. case BFA_FCPORT_SM_LINKUP:
  265. bfa_fcport_update_linkinfo(fcport);
  266. bfa_sm_set_state(fcport, bfa_fcport_sm_linkup);
  267. bfa_assert(fcport->event_cbfn);
  268. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  269. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkup");
  270. if (!bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  271. bfa_trc(fcport->bfa, pevent->link_state.fcf.fipenabled);
  272. bfa_trc(fcport->bfa, pevent->link_state.fcf.fipfailed);
  273. if (pevent->link_state.fcf.fipfailed)
  274. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  275. BFA_PL_EID_FIP_FCF_DISC, 0,
  276. "FIP FCF Discovery Failed");
  277. else
  278. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  279. BFA_PL_EID_FIP_FCF_DISC, 0,
  280. "FIP FCF Discovered");
  281. }
  282. bfa_fcport_callback(fcport, BFA_PPORT_LINKUP);
  283. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ONLINE);
  284. /**
  285. * If QoS is enabled and it is not online,
  286. * Send a separate event.
  287. */
  288. if ((fcport->cfg.qos_enabled)
  289. && (bfa_os_ntohl(fcport->qos_attr.state) != BFA_QOS_ONLINE))
  290. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_QOS_NEG);
  291. break;
  292. case BFA_FCPORT_SM_LINKDOWN:
  293. /**
  294. * Possible to get link down event.
  295. */
  296. break;
  297. case BFA_FCPORT_SM_ENABLE:
  298. /**
  299. * Already enabled.
  300. */
  301. break;
  302. case BFA_FCPORT_SM_DISABLE:
  303. if (bfa_fcport_send_disable(fcport))
  304. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  305. else
  306. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  307. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  308. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  309. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  310. break;
  311. case BFA_FCPORT_SM_STOP:
  312. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  313. break;
  314. case BFA_FCPORT_SM_HWFAIL:
  315. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  316. break;
  317. default:
  318. bfa_sm_fault(fcport->bfa, event);
  319. }
  320. }
  321. static void
  322. bfa_fcport_sm_linkup(struct bfa_fcport_s *fcport,
  323. enum bfa_fcport_sm_event event)
  324. {
  325. bfa_trc(fcport->bfa, event);
  326. switch (event) {
  327. case BFA_FCPORT_SM_ENABLE:
  328. /**
  329. * Already enabled.
  330. */
  331. break;
  332. case BFA_FCPORT_SM_DISABLE:
  333. if (bfa_fcport_send_disable(fcport))
  334. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  335. else
  336. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling_qwait);
  337. bfa_fcport_reset_linkinfo(fcport);
  338. bfa_fcport_callback(fcport, BFA_PPORT_LINKDOWN);
  339. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  340. BFA_PL_EID_PORT_DISABLE, 0, "Port Disable");
  341. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  342. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISABLE);
  343. break;
  344. case BFA_FCPORT_SM_LINKDOWN:
  345. bfa_sm_set_state(fcport, bfa_fcport_sm_linkdown);
  346. bfa_fcport_reset_linkinfo(fcport);
  347. bfa_fcport_callback(fcport, BFA_PPORT_LINKDOWN);
  348. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  349. BFA_PL_EID_PORT_ST_CHANGE, 0, "Port Linkdown");
  350. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  351. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  352. else
  353. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  354. break;
  355. case BFA_FCPORT_SM_STOP:
  356. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  357. bfa_fcport_reset_linkinfo(fcport);
  358. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  359. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  360. else
  361. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  362. break;
  363. case BFA_FCPORT_SM_HWFAIL:
  364. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  365. bfa_fcport_reset_linkinfo(fcport);
  366. bfa_fcport_callback(fcport, BFA_PPORT_LINKDOWN);
  367. if (BFA_PORT_IS_DISABLED(fcport->bfa))
  368. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_OFFLINE);
  369. else
  370. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_DISCONNECT);
  371. break;
  372. default:
  373. bfa_sm_fault(fcport->bfa, event);
  374. }
  375. }
  376. static void
  377. bfa_fcport_sm_disabling_qwait(struct bfa_fcport_s *fcport,
  378. enum bfa_fcport_sm_event event)
  379. {
  380. bfa_trc(fcport->bfa, event);
  381. switch (event) {
  382. case BFA_FCPORT_SM_QRESUME:
  383. bfa_sm_set_state(fcport, bfa_fcport_sm_disabling);
  384. bfa_fcport_send_disable(fcport);
  385. break;
  386. case BFA_FCPORT_SM_STOP:
  387. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  388. bfa_reqq_wcancel(&fcport->reqq_wait);
  389. break;
  390. case BFA_FCPORT_SM_DISABLE:
  391. /**
  392. * Already being disabled.
  393. */
  394. break;
  395. case BFA_FCPORT_SM_LINKUP:
  396. case BFA_FCPORT_SM_LINKDOWN:
  397. /**
  398. * Possible to get link events when doing back-to-back
  399. * enable/disables.
  400. */
  401. break;
  402. case BFA_FCPORT_SM_HWFAIL:
  403. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  404. bfa_reqq_wcancel(&fcport->reqq_wait);
  405. break;
  406. default:
  407. bfa_sm_fault(fcport->bfa, event);
  408. }
  409. }
  410. static void
  411. bfa_fcport_sm_disabling(struct bfa_fcport_s *fcport,
  412. enum bfa_fcport_sm_event event)
  413. {
  414. bfa_trc(fcport->bfa, event);
  415. switch (event) {
  416. case BFA_FCPORT_SM_FWRSP:
  417. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  418. break;
  419. case BFA_FCPORT_SM_DISABLE:
  420. /**
  421. * Already being disabled.
  422. */
  423. break;
  424. case BFA_FCPORT_SM_ENABLE:
  425. if (bfa_fcport_send_enable(fcport))
  426. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  427. else
  428. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
  429. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  430. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  431. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  432. break;
  433. case BFA_FCPORT_SM_STOP:
  434. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  435. break;
  436. case BFA_FCPORT_SM_LINKUP:
  437. case BFA_FCPORT_SM_LINKDOWN:
  438. /**
  439. * Possible to get link events when doing back-to-back
  440. * enable/disables.
  441. */
  442. break;
  443. case BFA_FCPORT_SM_HWFAIL:
  444. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  445. break;
  446. default:
  447. bfa_sm_fault(fcport->bfa, event);
  448. }
  449. }
  450. static void
  451. bfa_fcport_sm_disabled(struct bfa_fcport_s *fcport,
  452. enum bfa_fcport_sm_event event)
  453. {
  454. bfa_trc(fcport->bfa, event);
  455. switch (event) {
  456. case BFA_FCPORT_SM_START:
  457. /**
  458. * Ignore start event for a port that is disabled.
  459. */
  460. break;
  461. case BFA_FCPORT_SM_STOP:
  462. bfa_sm_set_state(fcport, bfa_fcport_sm_stopped);
  463. break;
  464. case BFA_FCPORT_SM_ENABLE:
  465. if (bfa_fcport_send_enable(fcport))
  466. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  467. else
  468. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
  469. bfa_plog_str(fcport->bfa->plog, BFA_PL_MID_HAL,
  470. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  471. bfa_fcport_aen_post(fcport, BFA_PORT_AEN_ENABLE);
  472. break;
  473. case BFA_FCPORT_SM_DISABLE:
  474. /**
  475. * Already disabled.
  476. */
  477. break;
  478. case BFA_FCPORT_SM_HWFAIL:
  479. bfa_sm_set_state(fcport, bfa_fcport_sm_iocfail);
  480. break;
  481. default:
  482. bfa_sm_fault(fcport->bfa, event);
  483. }
  484. }
  485. static void
  486. bfa_fcport_sm_stopped(struct bfa_fcport_s *fcport,
  487. enum bfa_fcport_sm_event event)
  488. {
  489. bfa_trc(fcport->bfa, event);
  490. switch (event) {
  491. case BFA_FCPORT_SM_START:
  492. if (bfa_fcport_send_enable(fcport))
  493. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  494. else
  495. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
  496. break;
  497. default:
  498. /**
  499. * Ignore all other events.
  500. */
  501. ;
  502. }
  503. }
  504. /**
  505. * Port is enabled. IOC is down/failed.
  506. */
  507. static void
  508. bfa_fcport_sm_iocdown(struct bfa_fcport_s *fcport,
  509. enum bfa_fcport_sm_event event)
  510. {
  511. bfa_trc(fcport->bfa, event);
  512. switch (event) {
  513. case BFA_FCPORT_SM_START:
  514. if (bfa_fcport_send_enable(fcport))
  515. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling);
  516. else
  517. bfa_sm_set_state(fcport, bfa_fcport_sm_enabling_qwait);
  518. break;
  519. default:
  520. /**
  521. * Ignore all events.
  522. */
  523. ;
  524. }
  525. }
  526. /**
  527. * Port is disabled. IOC is down/failed.
  528. */
  529. static void
  530. bfa_fcport_sm_iocfail(struct bfa_fcport_s *fcport,
  531. enum bfa_fcport_sm_event event)
  532. {
  533. bfa_trc(fcport->bfa, event);
  534. switch (event) {
  535. case BFA_FCPORT_SM_START:
  536. bfa_sm_set_state(fcport, bfa_fcport_sm_disabled);
  537. break;
  538. case BFA_FCPORT_SM_ENABLE:
  539. bfa_sm_set_state(fcport, bfa_fcport_sm_iocdown);
  540. break;
  541. default:
  542. /**
  543. * Ignore all events.
  544. */
  545. ;
  546. }
  547. }
  548. /**
  549. * Link state is down
  550. */
  551. static void
  552. bfa_fcport_ln_sm_dn(struct bfa_fcport_ln_s *ln,
  553. enum bfa_fcport_ln_sm_event event)
  554. {
  555. bfa_trc(ln->fcport->bfa, event);
  556. switch (event) {
  557. case BFA_FCPORT_LN_SM_LINKUP:
  558. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  559. bfa_fcport_queue_cb(ln, BFA_PPORT_LINKUP);
  560. break;
  561. default:
  562. bfa_sm_fault(ln->fcport->bfa, event);
  563. }
  564. }
  565. /**
  566. * Link state is waiting for down notification
  567. */
  568. static void
  569. bfa_fcport_ln_sm_dn_nf(struct bfa_fcport_ln_s *ln,
  570. enum bfa_fcport_ln_sm_event event)
  571. {
  572. bfa_trc(ln->fcport->bfa, event);
  573. switch (event) {
  574. case BFA_FCPORT_LN_SM_LINKUP:
  575. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  576. break;
  577. case BFA_FCPORT_LN_SM_NOTIFICATION:
  578. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  579. break;
  580. default:
  581. bfa_sm_fault(ln->fcport->bfa, event);
  582. }
  583. }
  584. /**
  585. * Link state is waiting for down notification and there is a pending up
  586. */
  587. static void
  588. bfa_fcport_ln_sm_dn_up_nf(struct bfa_fcport_ln_s *ln,
  589. enum bfa_fcport_ln_sm_event event)
  590. {
  591. bfa_trc(ln->fcport->bfa, event);
  592. switch (event) {
  593. case BFA_FCPORT_LN_SM_LINKDOWN:
  594. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  595. break;
  596. case BFA_FCPORT_LN_SM_NOTIFICATION:
  597. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_nf);
  598. bfa_fcport_queue_cb(ln, BFA_PPORT_LINKUP);
  599. break;
  600. default:
  601. bfa_sm_fault(ln->fcport->bfa, event);
  602. }
  603. }
  604. /**
  605. * Link state is up
  606. */
  607. static void
  608. bfa_fcport_ln_sm_up(struct bfa_fcport_ln_s *ln,
  609. enum bfa_fcport_ln_sm_event event)
  610. {
  611. bfa_trc(ln->fcport->bfa, event);
  612. switch (event) {
  613. case BFA_FCPORT_LN_SM_LINKDOWN:
  614. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  615. bfa_fcport_queue_cb(ln, BFA_PPORT_LINKDOWN);
  616. break;
  617. default:
  618. bfa_sm_fault(ln->fcport->bfa, event);
  619. }
  620. }
  621. /**
  622. * Link state is waiting for up notification
  623. */
  624. static void
  625. bfa_fcport_ln_sm_up_nf(struct bfa_fcport_ln_s *ln,
  626. enum bfa_fcport_ln_sm_event event)
  627. {
  628. bfa_trc(ln->fcport->bfa, event);
  629. switch (event) {
  630. case BFA_FCPORT_LN_SM_LINKDOWN:
  631. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  632. break;
  633. case BFA_FCPORT_LN_SM_NOTIFICATION:
  634. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up);
  635. break;
  636. default:
  637. bfa_sm_fault(ln->fcport->bfa, event);
  638. }
  639. }
  640. /**
  641. * Link state is waiting for up notification and there is a pending down
  642. */
  643. static void
  644. bfa_fcport_ln_sm_up_dn_nf(struct bfa_fcport_ln_s *ln,
  645. enum bfa_fcport_ln_sm_event event)
  646. {
  647. bfa_trc(ln->fcport->bfa, event);
  648. switch (event) {
  649. case BFA_FCPORT_LN_SM_LINKUP:
  650. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_up_nf);
  651. break;
  652. case BFA_FCPORT_LN_SM_NOTIFICATION:
  653. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_nf);
  654. bfa_fcport_queue_cb(ln, BFA_PPORT_LINKDOWN);
  655. break;
  656. default:
  657. bfa_sm_fault(ln->fcport->bfa, event);
  658. }
  659. }
  660. /**
  661. * Link state is waiting for up notification and there are pending down and up
  662. */
  663. static void
  664. bfa_fcport_ln_sm_up_dn_up_nf(struct bfa_fcport_ln_s *ln,
  665. enum bfa_fcport_ln_sm_event event)
  666. {
  667. bfa_trc(ln->fcport->bfa, event);
  668. switch (event) {
  669. case BFA_FCPORT_LN_SM_LINKDOWN:
  670. bfa_sm_set_state(ln, bfa_fcport_ln_sm_up_dn_nf);
  671. break;
  672. case BFA_FCPORT_LN_SM_NOTIFICATION:
  673. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn_up_nf);
  674. bfa_fcport_queue_cb(ln, BFA_PPORT_LINKDOWN);
  675. break;
  676. default:
  677. bfa_sm_fault(ln->fcport->bfa, event);
  678. }
  679. }
  680. /**
  681. * bfa_pport_private
  682. */
  683. static void
  684. __bfa_cb_fcport_event(void *cbarg, bfa_boolean_t complete)
  685. {
  686. struct bfa_fcport_ln_s *ln = cbarg;
  687. if (complete)
  688. ln->fcport->event_cbfn(ln->fcport->event_cbarg, ln->ln_event);
  689. else
  690. bfa_sm_send_event(ln, BFA_FCPORT_LN_SM_NOTIFICATION);
  691. }
  692. static void
  693. bfa_fcport_callback(struct bfa_fcport_s *fcport, enum bfa_pport_linkstate event)
  694. {
  695. if (fcport->bfa->fcs) {
  696. fcport->event_cbfn(fcport->event_cbarg, event);
  697. return;
  698. }
  699. switch (event) {
  700. case BFA_PPORT_LINKUP:
  701. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKUP);
  702. break;
  703. case BFA_PPORT_LINKDOWN:
  704. bfa_sm_send_event(&fcport->ln, BFA_FCPORT_LN_SM_LINKDOWN);
  705. break;
  706. default:
  707. bfa_assert(0);
  708. }
  709. }
  710. static void
  711. bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_pport_linkstate event)
  712. {
  713. ln->ln_event = event;
  714. bfa_cb_queue(ln->fcport->bfa, &ln->ln_qe, __bfa_cb_fcport_event, ln);
  715. }
  716. #define FCPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_fcport_stats_u), \
  717. BFA_CACHELINE_SZ))
  718. static void
  719. bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  720. u32 *dm_len)
  721. {
  722. *dm_len += FCPORT_STATS_DMA_SZ;
  723. }
  724. static void
  725. bfa_fcport_qresume(void *cbarg)
  726. {
  727. struct bfa_fcport_s *fcport = cbarg;
  728. bfa_sm_send_event(fcport, BFA_FCPORT_SM_QRESUME);
  729. }
  730. static void
  731. bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo)
  732. {
  733. u8 *dm_kva;
  734. u64 dm_pa;
  735. dm_kva = bfa_meminfo_dma_virt(meminfo);
  736. dm_pa = bfa_meminfo_dma_phys(meminfo);
  737. fcport->stats_kva = dm_kva;
  738. fcport->stats_pa = dm_pa;
  739. fcport->stats = (union bfa_fcport_stats_u *)dm_kva;
  740. dm_kva += FCPORT_STATS_DMA_SZ;
  741. dm_pa += FCPORT_STATS_DMA_SZ;
  742. bfa_meminfo_dma_virt(meminfo) = dm_kva;
  743. bfa_meminfo_dma_phys(meminfo) = dm_pa;
  744. }
  745. /**
  746. * Memory initialization.
  747. */
  748. static void
  749. bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  750. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  751. {
  752. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  753. struct bfa_pport_cfg_s *port_cfg = &fcport->cfg;
  754. struct bfa_fcport_ln_s *ln = &fcport->ln;
  755. bfa_os_memset(fcport, 0, sizeof(struct bfa_fcport_s));
  756. fcport->bfa = bfa;
  757. ln->fcport = fcport;
  758. bfa_fcport_mem_claim(fcport, meminfo);
  759. bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
  760. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  761. /**
  762. * initialize and set default configuration
  763. */
  764. port_cfg->topology = BFA_PPORT_TOPOLOGY_P2P;
  765. port_cfg->speed = BFA_PPORT_SPEED_AUTO;
  766. port_cfg->trunked = BFA_FALSE;
  767. port_cfg->maxfrsize = 0;
  768. port_cfg->trl_def_speed = BFA_PPORT_SPEED_1GBPS;
  769. bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
  770. }
  771. static void
  772. bfa_fcport_initdone(struct bfa_s *bfa)
  773. {
  774. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  775. /**
  776. * Initialize port attributes from IOC hardware data.
  777. */
  778. bfa_fcport_set_wwns(fcport);
  779. if (fcport->cfg.maxfrsize == 0)
  780. fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  781. fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  782. fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  783. bfa_assert(fcport->cfg.maxfrsize);
  784. bfa_assert(fcport->cfg.rx_bbcredit);
  785. bfa_assert(fcport->speed_sup);
  786. }
  787. static void
  788. bfa_fcport_detach(struct bfa_s *bfa)
  789. {
  790. }
  791. /**
  792. * Called when IOC is ready.
  793. */
  794. static void
  795. bfa_fcport_start(struct bfa_s *bfa)
  796. {
  797. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
  798. }
  799. /**
  800. * Called before IOC is stopped.
  801. */
  802. static void
  803. bfa_fcport_stop(struct bfa_s *bfa)
  804. {
  805. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
  806. }
  807. /**
  808. * Called when IOC failure is detected.
  809. */
  810. static void
  811. bfa_fcport_iocdisable(struct bfa_s *bfa)
  812. {
  813. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_HWFAIL);
  814. }
  815. static void
  816. bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
  817. {
  818. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  819. fcport->speed = pevent->link_state.speed;
  820. fcport->topology = pevent->link_state.topology;
  821. if (fcport->topology == BFA_PPORT_TOPOLOGY_LOOP)
  822. fcport->myalpa =
  823. pevent->link_state.tl.loop_info.myalpa;
  824. /*
  825. * QoS Details
  826. */
  827. bfa_os_assign(fcport->qos_attr, pevent->link_state.qos_attr);
  828. bfa_os_assign(fcport->qos_vc_attr, pevent->link_state.qos_vc_attr);
  829. bfa_trc(fcport->bfa, fcport->speed);
  830. bfa_trc(fcport->bfa, fcport->topology);
  831. }
  832. static void
  833. bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
  834. {
  835. fcport->speed = BFA_PPORT_SPEED_UNKNOWN;
  836. fcport->topology = BFA_PPORT_TOPOLOGY_NONE;
  837. }
  838. /**
  839. * Send port enable message to firmware.
  840. */
  841. static bfa_boolean_t
  842. bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
  843. {
  844. struct bfi_fcport_enable_req_s *m;
  845. /**
  846. * Increment message tag before queue check, so that responses to old
  847. * requests are discarded.
  848. */
  849. fcport->msgtag++;
  850. /**
  851. * check for room in queue to send request now
  852. */
  853. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  854. if (!m) {
  855. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  856. &fcport->reqq_wait);
  857. return BFA_FALSE;
  858. }
  859. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
  860. bfa_lpuid(fcport->bfa));
  861. m->nwwn = fcport->nwwn;
  862. m->pwwn = fcport->pwwn;
  863. m->port_cfg = fcport->cfg;
  864. m->msgtag = fcport->msgtag;
  865. m->port_cfg.maxfrsize = bfa_os_htons(fcport->cfg.maxfrsize);
  866. bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
  867. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
  868. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
  869. /**
  870. * queue I/O message to firmware
  871. */
  872. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  873. return BFA_TRUE;
  874. }
  875. /**
  876. * Send port disable message to firmware.
  877. */
  878. static bfa_boolean_t
  879. bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
  880. {
  881. struct bfi_fcport_req_s *m;
  882. /**
  883. * Increment message tag before queue check, so that responses to old
  884. * requests are discarded.
  885. */
  886. fcport->msgtag++;
  887. /**
  888. * check for room in queue to send request now
  889. */
  890. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  891. if (!m) {
  892. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  893. &fcport->reqq_wait);
  894. return BFA_FALSE;
  895. }
  896. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
  897. bfa_lpuid(fcport->bfa));
  898. m->msgtag = fcport->msgtag;
  899. /**
  900. * queue I/O message to firmware
  901. */
  902. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  903. return BFA_TRUE;
  904. }
  905. static void
  906. bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
  907. {
  908. fcport->pwwn = bfa_ioc_get_pwwn(&fcport->bfa->ioc);
  909. fcport->nwwn = bfa_ioc_get_nwwn(&fcport->bfa->ioc);
  910. bfa_trc(fcport->bfa, fcport->pwwn);
  911. bfa_trc(fcport->bfa, fcport->nwwn);
  912. }
  913. static void
  914. bfa_fcport_send_txcredit(void *port_cbarg)
  915. {
  916. struct bfa_fcport_s *fcport = port_cbarg;
  917. struct bfi_fcport_set_svc_params_req_s *m;
  918. /**
  919. * check for room in queue to send request now
  920. */
  921. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  922. if (!m) {
  923. bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
  924. return;
  925. }
  926. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
  927. bfa_lpuid(fcport->bfa));
  928. m->tx_bbcredit = bfa_os_htons((u16) fcport->cfg.tx_bbcredit);
  929. /**
  930. * queue I/O message to firmware
  931. */
  932. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  933. }
  934. static void
  935. bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
  936. struct bfa_qos_stats_s *s)
  937. {
  938. u32 *dip = (u32 *) d;
  939. u32 *sip = (u32 *) s;
  940. int i;
  941. /* Now swap the 32 bit fields */
  942. for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
  943. dip[i] = bfa_os_ntohl(sip[i]);
  944. }
  945. static void
  946. bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
  947. struct bfa_fcoe_stats_s *s)
  948. {
  949. u32 *dip = (u32 *) d;
  950. u32 *sip = (u32 *) s;
  951. int i;
  952. for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
  953. i = i + 2) {
  954. #ifdef __BIGENDIAN
  955. dip[i] = bfa_os_ntohl(sip[i]);
  956. dip[i + 1] = bfa_os_ntohl(sip[i + 1]);
  957. #else
  958. dip[i] = bfa_os_ntohl(sip[i + 1]);
  959. dip[i + 1] = bfa_os_ntohl(sip[i]);
  960. #endif
  961. }
  962. }
  963. static void
  964. __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
  965. {
  966. struct bfa_fcport_s *fcport = cbarg;
  967. if (complete) {
  968. if (fcport->stats_status == BFA_STATUS_OK) {
  969. /* Swap FC QoS or FCoE stats */
  970. if (bfa_ioc_get_fcmode(&fcport->bfa->ioc))
  971. bfa_fcport_qos_stats_swap(
  972. &fcport->stats_ret->fcqos,
  973. &fcport->stats->fcqos);
  974. else
  975. bfa_fcport_fcoe_stats_swap(
  976. &fcport->stats_ret->fcoe,
  977. &fcport->stats->fcoe);
  978. }
  979. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  980. } else {
  981. fcport->stats_busy = BFA_FALSE;
  982. fcport->stats_status = BFA_STATUS_OK;
  983. }
  984. }
  985. static void
  986. bfa_fcport_stats_get_timeout(void *cbarg)
  987. {
  988. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  989. bfa_trc(fcport->bfa, fcport->stats_qfull);
  990. if (fcport->stats_qfull) {
  991. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  992. fcport->stats_qfull = BFA_FALSE;
  993. }
  994. fcport->stats_status = BFA_STATUS_ETIMER;
  995. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
  996. fcport);
  997. }
  998. static void
  999. bfa_fcport_send_stats_get(void *cbarg)
  1000. {
  1001. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  1002. struct bfi_fcport_req_s *msg;
  1003. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  1004. if (!msg) {
  1005. fcport->stats_qfull = BFA_TRUE;
  1006. bfa_reqq_winit(&fcport->stats_reqq_wait,
  1007. bfa_fcport_send_stats_get, fcport);
  1008. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  1009. &fcport->stats_reqq_wait);
  1010. return;
  1011. }
  1012. fcport->stats_qfull = BFA_FALSE;
  1013. bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  1014. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
  1015. bfa_lpuid(fcport->bfa));
  1016. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  1017. }
  1018. static void
  1019. __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
  1020. {
  1021. struct bfa_fcport_s *fcport = cbarg;
  1022. if (complete) {
  1023. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  1024. } else {
  1025. fcport->stats_busy = BFA_FALSE;
  1026. fcport->stats_status = BFA_STATUS_OK;
  1027. }
  1028. }
  1029. static void
  1030. bfa_fcport_stats_clr_timeout(void *cbarg)
  1031. {
  1032. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  1033. bfa_trc(fcport->bfa, fcport->stats_qfull);
  1034. if (fcport->stats_qfull) {
  1035. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  1036. fcport->stats_qfull = BFA_FALSE;
  1037. }
  1038. fcport->stats_status = BFA_STATUS_ETIMER;
  1039. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  1040. __bfa_cb_fcport_stats_clr, fcport);
  1041. }
  1042. static void
  1043. bfa_fcport_send_stats_clear(void *cbarg)
  1044. {
  1045. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  1046. struct bfi_fcport_req_s *msg;
  1047. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  1048. if (!msg) {
  1049. fcport->stats_qfull = BFA_TRUE;
  1050. bfa_reqq_winit(&fcport->stats_reqq_wait,
  1051. bfa_fcport_send_stats_clear, fcport);
  1052. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  1053. &fcport->stats_reqq_wait);
  1054. return;
  1055. }
  1056. fcport->stats_qfull = BFA_FALSE;
  1057. bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  1058. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
  1059. bfa_lpuid(fcport->bfa));
  1060. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  1061. }
  1062. /**
  1063. * bfa_pport_public
  1064. */
  1065. /**
  1066. * Firmware message handler.
  1067. */
  1068. void
  1069. bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  1070. {
  1071. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1072. union bfi_fcport_i2h_msg_u i2hmsg;
  1073. i2hmsg.msg = msg;
  1074. fcport->event_arg.i2hmsg = i2hmsg;
  1075. switch (msg->mhdr.msg_id) {
  1076. case BFI_FCPORT_I2H_ENABLE_RSP:
  1077. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  1078. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  1079. break;
  1080. case BFI_FCPORT_I2H_DISABLE_RSP:
  1081. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  1082. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  1083. break;
  1084. case BFI_FCPORT_I2H_EVENT:
  1085. switch (i2hmsg.event->link_state.linkstate) {
  1086. case BFA_PPORT_LINKUP:
  1087. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
  1088. break;
  1089. case BFA_PPORT_LINKDOWN:
  1090. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
  1091. break;
  1092. case BFA_PPORT_TRUNK_LINKDOWN:
  1093. /** todo: event notification */
  1094. break;
  1095. }
  1096. break;
  1097. case BFI_FCPORT_I2H_STATS_GET_RSP:
  1098. /*
  1099. * check for timer pop before processing the rsp
  1100. */
  1101. if (fcport->stats_busy == BFA_FALSE ||
  1102. fcport->stats_status == BFA_STATUS_ETIMER)
  1103. break;
  1104. bfa_timer_stop(&fcport->timer);
  1105. fcport->stats_status = i2hmsg.pstatsget_rsp->status;
  1106. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  1107. __bfa_cb_fcport_stats_get, fcport);
  1108. break;
  1109. case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
  1110. /*
  1111. * check for timer pop before processing the rsp
  1112. */
  1113. if (fcport->stats_busy == BFA_FALSE ||
  1114. fcport->stats_status == BFA_STATUS_ETIMER)
  1115. break;
  1116. bfa_timer_stop(&fcport->timer);
  1117. fcport->stats_status = BFA_STATUS_OK;
  1118. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  1119. __bfa_cb_fcport_stats_clr, fcport);
  1120. break;
  1121. default:
  1122. bfa_assert(0);
  1123. break;
  1124. }
  1125. }
  1126. /**
  1127. * bfa_pport_api
  1128. */
  1129. /**
  1130. * Registered callback for port events.
  1131. */
  1132. void
  1133. bfa_fcport_event_register(struct bfa_s *bfa,
  1134. void (*cbfn) (void *cbarg, bfa_pport_event_t event),
  1135. void *cbarg)
  1136. {
  1137. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1138. fcport->event_cbfn = cbfn;
  1139. fcport->event_cbarg = cbarg;
  1140. }
  1141. bfa_status_t
  1142. bfa_fcport_enable(struct bfa_s *bfa)
  1143. {
  1144. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1145. if (fcport->diag_busy)
  1146. return BFA_STATUS_DIAG_BUSY;
  1147. else if (bfa_sm_cmp_state
  1148. (BFA_FCPORT_MOD(bfa), bfa_fcport_sm_disabling_qwait))
  1149. return BFA_STATUS_DEVBUSY;
  1150. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
  1151. return BFA_STATUS_OK;
  1152. }
  1153. bfa_status_t
  1154. bfa_fcport_disable(struct bfa_s *bfa)
  1155. {
  1156. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
  1157. return BFA_STATUS_OK;
  1158. }
  1159. /**
  1160. * Configure port speed.
  1161. */
  1162. bfa_status_t
  1163. bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
  1164. {
  1165. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1166. bfa_trc(bfa, speed);
  1167. if ((speed != BFA_PPORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
  1168. bfa_trc(bfa, fcport->speed_sup);
  1169. return BFA_STATUS_UNSUPP_SPEED;
  1170. }
  1171. fcport->cfg.speed = speed;
  1172. return BFA_STATUS_OK;
  1173. }
  1174. /**
  1175. * Get current speed.
  1176. */
  1177. enum bfa_pport_speed
  1178. bfa_fcport_get_speed(struct bfa_s *bfa)
  1179. {
  1180. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1181. return fcport->speed;
  1182. }
  1183. /**
  1184. * Configure port topology.
  1185. */
  1186. bfa_status_t
  1187. bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_pport_topology topology)
  1188. {
  1189. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1190. bfa_trc(bfa, topology);
  1191. bfa_trc(bfa, fcport->cfg.topology);
  1192. switch (topology) {
  1193. case BFA_PPORT_TOPOLOGY_P2P:
  1194. case BFA_PPORT_TOPOLOGY_LOOP:
  1195. case BFA_PPORT_TOPOLOGY_AUTO:
  1196. break;
  1197. default:
  1198. return BFA_STATUS_EINVAL;
  1199. }
  1200. fcport->cfg.topology = topology;
  1201. return BFA_STATUS_OK;
  1202. }
  1203. /**
  1204. * Get current topology.
  1205. */
  1206. enum bfa_pport_topology
  1207. bfa_fcport_get_topology(struct bfa_s *bfa)
  1208. {
  1209. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1210. return fcport->topology;
  1211. }
  1212. bfa_status_t
  1213. bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  1214. {
  1215. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1216. bfa_trc(bfa, alpa);
  1217. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  1218. bfa_trc(bfa, fcport->cfg.hardalpa);
  1219. fcport->cfg.cfg_hardalpa = BFA_TRUE;
  1220. fcport->cfg.hardalpa = alpa;
  1221. return BFA_STATUS_OK;
  1222. }
  1223. bfa_status_t
  1224. bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
  1225. {
  1226. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1227. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  1228. bfa_trc(bfa, fcport->cfg.hardalpa);
  1229. fcport->cfg.cfg_hardalpa = BFA_FALSE;
  1230. return BFA_STATUS_OK;
  1231. }
  1232. bfa_boolean_t
  1233. bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  1234. {
  1235. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1236. *alpa = fcport->cfg.hardalpa;
  1237. return fcport->cfg.cfg_hardalpa;
  1238. }
  1239. u8
  1240. bfa_fcport_get_myalpa(struct bfa_s *bfa)
  1241. {
  1242. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1243. return fcport->myalpa;
  1244. }
  1245. bfa_status_t
  1246. bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  1247. {
  1248. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1249. bfa_trc(bfa, maxfrsize);
  1250. bfa_trc(bfa, fcport->cfg.maxfrsize);
  1251. /*
  1252. * with in range
  1253. */
  1254. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  1255. return BFA_STATUS_INVLD_DFSZ;
  1256. /*
  1257. * power of 2, if not the max frame size of 2112
  1258. */
  1259. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  1260. return BFA_STATUS_INVLD_DFSZ;
  1261. fcport->cfg.maxfrsize = maxfrsize;
  1262. return BFA_STATUS_OK;
  1263. }
  1264. u16
  1265. bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
  1266. {
  1267. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1268. return fcport->cfg.maxfrsize;
  1269. }
  1270. u32
  1271. bfa_fcport_mypid(struct bfa_s *bfa)
  1272. {
  1273. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1274. return fcport->mypid;
  1275. }
  1276. u8
  1277. bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
  1278. {
  1279. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1280. return fcport->cfg.rx_bbcredit;
  1281. }
  1282. void
  1283. bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
  1284. {
  1285. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1286. fcport->cfg.tx_bbcredit = (u8) tx_bbcredit;
  1287. bfa_fcport_send_txcredit(fcport);
  1288. }
  1289. /**
  1290. * Get port attributes.
  1291. */
  1292. wwn_t
  1293. bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  1294. {
  1295. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1296. if (node)
  1297. return fcport->nwwn;
  1298. else
  1299. return fcport->pwwn;
  1300. }
  1301. void
  1302. bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_pport_attr_s *attr)
  1303. {
  1304. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1305. bfa_os_memset(attr, 0, sizeof(struct bfa_pport_attr_s));
  1306. attr->nwwn = fcport->nwwn;
  1307. attr->pwwn = fcport->pwwn;
  1308. bfa_os_memcpy(&attr->pport_cfg, &fcport->cfg,
  1309. sizeof(struct bfa_pport_cfg_s));
  1310. /*
  1311. * speed attributes
  1312. */
  1313. attr->pport_cfg.speed = fcport->cfg.speed;
  1314. attr->speed_supported = fcport->speed_sup;
  1315. attr->speed = fcport->speed;
  1316. attr->cos_supported = FC_CLASS_3;
  1317. /*
  1318. * topology attributes
  1319. */
  1320. attr->pport_cfg.topology = fcport->cfg.topology;
  1321. attr->topology = fcport->topology;
  1322. /*
  1323. * beacon attributes
  1324. */
  1325. attr->beacon = fcport->beacon;
  1326. attr->link_e2e_beacon = fcport->link_e2e_beacon;
  1327. attr->plog_enabled = bfa_plog_get_setting(fcport->bfa->plog);
  1328. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  1329. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  1330. attr->port_state = bfa_sm_to_state(hal_pport_sm_table, fcport->sm);
  1331. if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
  1332. attr->port_state = BFA_PPORT_ST_IOCDIS;
  1333. else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
  1334. attr->port_state = BFA_PPORT_ST_FWMISMATCH;
  1335. }
  1336. #define BFA_FCPORT_STATS_TOV 1000
  1337. /**
  1338. * Fetch port attributes (FCQoS or FCoE).
  1339. */
  1340. bfa_status_t
  1341. bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  1342. bfa_cb_pport_t cbfn, void *cbarg)
  1343. {
  1344. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1345. if (fcport->stats_busy) {
  1346. bfa_trc(bfa, fcport->stats_busy);
  1347. return BFA_STATUS_DEVBUSY;
  1348. }
  1349. fcport->stats_busy = BFA_TRUE;
  1350. fcport->stats_ret = stats;
  1351. fcport->stats_cbfn = cbfn;
  1352. fcport->stats_cbarg = cbarg;
  1353. bfa_fcport_send_stats_get(fcport);
  1354. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
  1355. fcport, BFA_FCPORT_STATS_TOV);
  1356. return BFA_STATUS_OK;
  1357. }
  1358. /**
  1359. * Reset port statistics (FCQoS or FCoE).
  1360. */
  1361. bfa_status_t
  1362. bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1363. {
  1364. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1365. if (fcport->stats_busy) {
  1366. bfa_trc(bfa, fcport->stats_busy);
  1367. return BFA_STATUS_DEVBUSY;
  1368. }
  1369. fcport->stats_busy = BFA_TRUE;
  1370. fcport->stats_cbfn = cbfn;
  1371. fcport->stats_cbarg = cbarg;
  1372. bfa_fcport_send_stats_clear(fcport);
  1373. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
  1374. fcport, BFA_FCPORT_STATS_TOV);
  1375. return BFA_STATUS_OK;
  1376. }
  1377. /**
  1378. * Fetch FCQoS port statistics
  1379. */
  1380. bfa_status_t
  1381. bfa_fcport_get_qos_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  1382. bfa_cb_pport_t cbfn, void *cbarg)
  1383. {
  1384. /* Meaningful only for FC mode */
  1385. bfa_assert(bfa_ioc_get_fcmode(&bfa->ioc));
  1386. return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
  1387. }
  1388. /**
  1389. * Reset FCoE port statistics
  1390. */
  1391. bfa_status_t
  1392. bfa_fcport_clear_qos_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1393. {
  1394. /* Meaningful only for FC mode */
  1395. bfa_assert(bfa_ioc_get_fcmode(&bfa->ioc));
  1396. return bfa_fcport_clear_stats(bfa, cbfn, cbarg);
  1397. }
  1398. /**
  1399. * Fetch FCQoS port statistics
  1400. */
  1401. bfa_status_t
  1402. bfa_fcport_get_fcoe_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  1403. bfa_cb_pport_t cbfn, void *cbarg)
  1404. {
  1405. /* Meaningful only for FCoE mode */
  1406. bfa_assert(!bfa_ioc_get_fcmode(&bfa->ioc));
  1407. return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
  1408. }
  1409. /**
  1410. * Reset FCoE port statistics
  1411. */
  1412. bfa_status_t
  1413. bfa_fcport_clear_fcoe_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1414. {
  1415. /* Meaningful only for FCoE mode */
  1416. bfa_assert(!bfa_ioc_get_fcmode(&bfa->ioc));
  1417. return bfa_fcport_clear_stats(bfa, cbfn, cbarg);
  1418. }
  1419. bfa_status_t
  1420. bfa_fcport_trunk_enable(struct bfa_s *bfa, u8 bitmap)
  1421. {
  1422. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1423. bfa_trc(bfa, bitmap);
  1424. bfa_trc(bfa, fcport->cfg.trunked);
  1425. bfa_trc(bfa, fcport->cfg.trunk_ports);
  1426. if (!bitmap || (bitmap & (bitmap - 1)))
  1427. return BFA_STATUS_EINVAL;
  1428. fcport->cfg.trunked = BFA_TRUE;
  1429. fcport->cfg.trunk_ports = bitmap;
  1430. return BFA_STATUS_OK;
  1431. }
  1432. void
  1433. bfa_fcport_qos_get_attr(struct bfa_s *bfa, struct bfa_qos_attr_s *qos_attr)
  1434. {
  1435. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1436. qos_attr->state = bfa_os_ntohl(fcport->qos_attr.state);
  1437. qos_attr->total_bb_cr = bfa_os_ntohl(fcport->qos_attr.total_bb_cr);
  1438. }
  1439. void
  1440. bfa_fcport_qos_get_vc_attr(struct bfa_s *bfa,
  1441. struct bfa_qos_vc_attr_s *qos_vc_attr)
  1442. {
  1443. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1444. struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
  1445. u32 i = 0;
  1446. qos_vc_attr->total_vc_count = bfa_os_ntohs(bfa_vc_attr->total_vc_count);
  1447. qos_vc_attr->shared_credit = bfa_os_ntohs(bfa_vc_attr->shared_credit);
  1448. qos_vc_attr->elp_opmode_flags =
  1449. bfa_os_ntohl(bfa_vc_attr->elp_opmode_flags);
  1450. /*
  1451. * Individual VC info
  1452. */
  1453. while (i < qos_vc_attr->total_vc_count) {
  1454. qos_vc_attr->vc_info[i].vc_credit =
  1455. bfa_vc_attr->vc_info[i].vc_credit;
  1456. qos_vc_attr->vc_info[i].borrow_credit =
  1457. bfa_vc_attr->vc_info[i].borrow_credit;
  1458. qos_vc_attr->vc_info[i].priority =
  1459. bfa_vc_attr->vc_info[i].priority;
  1460. ++i;
  1461. }
  1462. }
  1463. /**
  1464. * Fetch port attributes.
  1465. */
  1466. bfa_status_t
  1467. bfa_fcport_trunk_disable(struct bfa_s *bfa)
  1468. {
  1469. return BFA_STATUS_OK;
  1470. }
  1471. bfa_boolean_t
  1472. bfa_fcport_trunk_query(struct bfa_s *bfa, u32 *bitmap)
  1473. {
  1474. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1475. *bitmap = fcport->cfg.trunk_ports;
  1476. return fcport->cfg.trunked;
  1477. }
  1478. bfa_boolean_t
  1479. bfa_fcport_is_disabled(struct bfa_s *bfa)
  1480. {
  1481. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1482. return bfa_sm_to_state(hal_pport_sm_table, fcport->sm) ==
  1483. BFA_PPORT_ST_DISABLED;
  1484. }
  1485. bfa_boolean_t
  1486. bfa_fcport_is_ratelim(struct bfa_s *bfa)
  1487. {
  1488. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1489. return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
  1490. }
  1491. void
  1492. bfa_fcport_cfg_qos(struct bfa_s *bfa, bfa_boolean_t on_off)
  1493. {
  1494. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1495. enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
  1496. bfa_trc(bfa, on_off);
  1497. bfa_trc(bfa, fcport->cfg.qos_enabled);
  1498. bfa_trc(bfa, ioc_type);
  1499. if (ioc_type == BFA_IOC_TYPE_FC)
  1500. fcport->cfg.qos_enabled = on_off;
  1501. }
  1502. void
  1503. bfa_fcport_cfg_ratelim(struct bfa_s *bfa, bfa_boolean_t on_off)
  1504. {
  1505. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1506. bfa_trc(bfa, on_off);
  1507. bfa_trc(bfa, fcport->cfg.ratelimit);
  1508. fcport->cfg.ratelimit = on_off;
  1509. if (fcport->cfg.trl_def_speed == BFA_PPORT_SPEED_UNKNOWN)
  1510. fcport->cfg.trl_def_speed = BFA_PPORT_SPEED_1GBPS;
  1511. }
  1512. /**
  1513. * Configure default minimum ratelim speed
  1514. */
  1515. bfa_status_t
  1516. bfa_fcport_cfg_ratelim_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
  1517. {
  1518. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1519. bfa_trc(bfa, speed);
  1520. /*
  1521. * Auto and speeds greater than the supported speed, are invalid
  1522. */
  1523. if ((speed == BFA_PPORT_SPEED_AUTO) || (speed > fcport->speed_sup)) {
  1524. bfa_trc(bfa, fcport->speed_sup);
  1525. return BFA_STATUS_UNSUPP_SPEED;
  1526. }
  1527. fcport->cfg.trl_def_speed = speed;
  1528. return BFA_STATUS_OK;
  1529. }
  1530. /**
  1531. * Get default minimum ratelim speed
  1532. */
  1533. enum bfa_pport_speed
  1534. bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
  1535. {
  1536. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1537. bfa_trc(bfa, fcport->cfg.trl_def_speed);
  1538. return fcport->cfg.trl_def_speed;
  1539. }
  1540. void
  1541. bfa_fcport_busy(struct bfa_s *bfa, bfa_boolean_t status)
  1542. {
  1543. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1544. bfa_trc(bfa, status);
  1545. bfa_trc(bfa, fcport->diag_busy);
  1546. fcport->diag_busy = status;
  1547. }
  1548. void
  1549. bfa_fcport_beacon(struct bfa_s *bfa, bfa_boolean_t beacon,
  1550. bfa_boolean_t link_e2e_beacon)
  1551. {
  1552. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1553. bfa_trc(bfa, beacon);
  1554. bfa_trc(bfa, link_e2e_beacon);
  1555. bfa_trc(bfa, fcport->beacon);
  1556. bfa_trc(bfa, fcport->link_e2e_beacon);
  1557. fcport->beacon = beacon;
  1558. fcport->link_e2e_beacon = link_e2e_beacon;
  1559. }
  1560. bfa_boolean_t
  1561. bfa_fcport_is_linkup(struct bfa_s *bfa)
  1562. {
  1563. return bfa_sm_cmp_state(BFA_FCPORT_MOD(bfa), bfa_fcport_sm_linkup);
  1564. }