bfa_fcport.c 43 KB

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