bfa_fcport.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  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. struct bfa_timeval_s tv;
  756. bfa_os_memset(fcport, 0, sizeof(struct bfa_fcport_s));
  757. fcport->bfa = bfa;
  758. ln->fcport = fcport;
  759. bfa_fcport_mem_claim(fcport, meminfo);
  760. bfa_sm_set_state(fcport, bfa_fcport_sm_uninit);
  761. bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn);
  762. /**
  763. * initialize time stamp for stats reset
  764. */
  765. bfa_os_gettimeofday(&tv);
  766. fcport->stats_reset_time = tv.tv_sec;
  767. /**
  768. * initialize and set default configuration
  769. */
  770. port_cfg->topology = BFA_PPORT_TOPOLOGY_P2P;
  771. port_cfg->speed = BFA_PPORT_SPEED_AUTO;
  772. port_cfg->trunked = BFA_FALSE;
  773. port_cfg->maxfrsize = 0;
  774. port_cfg->trl_def_speed = BFA_PPORT_SPEED_1GBPS;
  775. bfa_reqq_winit(&fcport->reqq_wait, bfa_fcport_qresume, fcport);
  776. }
  777. static void
  778. bfa_fcport_detach(struct bfa_s *bfa)
  779. {
  780. }
  781. /**
  782. * Called when IOC is ready.
  783. */
  784. static void
  785. bfa_fcport_start(struct bfa_s *bfa)
  786. {
  787. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_START);
  788. }
  789. /**
  790. * Called before IOC is stopped.
  791. */
  792. static void
  793. bfa_fcport_stop(struct bfa_s *bfa)
  794. {
  795. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_STOP);
  796. }
  797. /**
  798. * Called when IOC failure is detected.
  799. */
  800. static void
  801. bfa_fcport_iocdisable(struct bfa_s *bfa)
  802. {
  803. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_HWFAIL);
  804. }
  805. static void
  806. bfa_fcport_update_linkinfo(struct bfa_fcport_s *fcport)
  807. {
  808. struct bfi_fcport_event_s *pevent = fcport->event_arg.i2hmsg.event;
  809. fcport->speed = pevent->link_state.speed;
  810. fcport->topology = pevent->link_state.topology;
  811. if (fcport->topology == BFA_PPORT_TOPOLOGY_LOOP)
  812. fcport->myalpa =
  813. pevent->link_state.tl.loop_info.myalpa;
  814. /*
  815. * QoS Details
  816. */
  817. bfa_os_assign(fcport->qos_attr, pevent->link_state.qos_attr);
  818. bfa_os_assign(fcport->qos_vc_attr, pevent->link_state.qos_vc_attr);
  819. bfa_trc(fcport->bfa, fcport->speed);
  820. bfa_trc(fcport->bfa, fcport->topology);
  821. }
  822. static void
  823. bfa_fcport_reset_linkinfo(struct bfa_fcport_s *fcport)
  824. {
  825. fcport->speed = BFA_PPORT_SPEED_UNKNOWN;
  826. fcport->topology = BFA_PPORT_TOPOLOGY_NONE;
  827. }
  828. /**
  829. * Send port enable message to firmware.
  830. */
  831. static bfa_boolean_t
  832. bfa_fcport_send_enable(struct bfa_fcport_s *fcport)
  833. {
  834. struct bfi_fcport_enable_req_s *m;
  835. /**
  836. * Increment message tag before queue check, so that responses to old
  837. * requests are discarded.
  838. */
  839. fcport->msgtag++;
  840. /**
  841. * check for room in queue to send request now
  842. */
  843. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  844. if (!m) {
  845. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  846. &fcport->reqq_wait);
  847. return BFA_FALSE;
  848. }
  849. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_ENABLE_REQ,
  850. bfa_lpuid(fcport->bfa));
  851. m->nwwn = fcport->nwwn;
  852. m->pwwn = fcport->pwwn;
  853. m->port_cfg = fcport->cfg;
  854. m->msgtag = fcport->msgtag;
  855. m->port_cfg.maxfrsize = bfa_os_htons(fcport->cfg.maxfrsize);
  856. bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa);
  857. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo);
  858. bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi);
  859. /**
  860. * queue I/O message to firmware
  861. */
  862. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  863. return BFA_TRUE;
  864. }
  865. /**
  866. * Send port disable message to firmware.
  867. */
  868. static bfa_boolean_t
  869. bfa_fcport_send_disable(struct bfa_fcport_s *fcport)
  870. {
  871. struct bfi_fcport_req_s *m;
  872. /**
  873. * Increment message tag before queue check, so that responses to old
  874. * requests are discarded.
  875. */
  876. fcport->msgtag++;
  877. /**
  878. * check for room in queue to send request now
  879. */
  880. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  881. if (!m) {
  882. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  883. &fcport->reqq_wait);
  884. return BFA_FALSE;
  885. }
  886. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_DISABLE_REQ,
  887. bfa_lpuid(fcport->bfa));
  888. m->msgtag = fcport->msgtag;
  889. /**
  890. * queue I/O message to firmware
  891. */
  892. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  893. return BFA_TRUE;
  894. }
  895. static void
  896. bfa_fcport_set_wwns(struct bfa_fcport_s *fcport)
  897. {
  898. fcport->pwwn = bfa_ioc_get_pwwn(&fcport->bfa->ioc);
  899. fcport->nwwn = bfa_ioc_get_nwwn(&fcport->bfa->ioc);
  900. bfa_trc(fcport->bfa, fcport->pwwn);
  901. bfa_trc(fcport->bfa, fcport->nwwn);
  902. }
  903. static void
  904. bfa_fcport_send_txcredit(void *port_cbarg)
  905. {
  906. struct bfa_fcport_s *fcport = port_cbarg;
  907. struct bfi_fcport_set_svc_params_req_s *m;
  908. /**
  909. * check for room in queue to send request now
  910. */
  911. m = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  912. if (!m) {
  913. bfa_trc(fcport->bfa, fcport->cfg.tx_bbcredit);
  914. return;
  915. }
  916. bfi_h2i_set(m->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_SET_SVC_PARAMS_REQ,
  917. bfa_lpuid(fcport->bfa));
  918. m->tx_bbcredit = bfa_os_htons((u16) fcport->cfg.tx_bbcredit);
  919. /**
  920. * queue I/O message to firmware
  921. */
  922. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  923. }
  924. static void
  925. bfa_fcport_qos_stats_swap(struct bfa_qos_stats_s *d,
  926. struct bfa_qos_stats_s *s)
  927. {
  928. u32 *dip = (u32 *) d;
  929. u32 *sip = (u32 *) s;
  930. int i;
  931. /* Now swap the 32 bit fields */
  932. for (i = 0; i < (sizeof(struct bfa_qos_stats_s)/sizeof(u32)); ++i)
  933. dip[i] = bfa_os_ntohl(sip[i]);
  934. }
  935. static void
  936. bfa_fcport_fcoe_stats_swap(struct bfa_fcoe_stats_s *d,
  937. struct bfa_fcoe_stats_s *s)
  938. {
  939. u32 *dip = (u32 *) d;
  940. u32 *sip = (u32 *) s;
  941. int i;
  942. for (i = 0; i < ((sizeof(struct bfa_fcoe_stats_s))/sizeof(u32));
  943. i = i + 2) {
  944. #ifdef __BIGENDIAN
  945. dip[i] = bfa_os_ntohl(sip[i]);
  946. dip[i + 1] = bfa_os_ntohl(sip[i + 1]);
  947. #else
  948. dip[i] = bfa_os_ntohl(sip[i + 1]);
  949. dip[i + 1] = bfa_os_ntohl(sip[i]);
  950. #endif
  951. }
  952. }
  953. static void
  954. __bfa_cb_fcport_stats_get(void *cbarg, bfa_boolean_t complete)
  955. {
  956. struct bfa_fcport_s *fcport = cbarg;
  957. if (complete) {
  958. if (fcport->stats_status == BFA_STATUS_OK) {
  959. struct bfa_timeval_s tv;
  960. /* Swap FC QoS or FCoE stats */
  961. if (bfa_ioc_get_fcmode(&fcport->bfa->ioc)) {
  962. bfa_fcport_qos_stats_swap(
  963. &fcport->stats_ret->fcqos,
  964. &fcport->stats->fcqos);
  965. } else {
  966. bfa_fcport_fcoe_stats_swap(
  967. &fcport->stats_ret->fcoe,
  968. &fcport->stats->fcoe);
  969. bfa_os_gettimeofday(&tv);
  970. fcport->stats_ret->fcoe.secs_reset =
  971. tv.tv_sec - fcport->stats_reset_time;
  972. }
  973. }
  974. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  975. } else {
  976. fcport->stats_busy = BFA_FALSE;
  977. fcport->stats_status = BFA_STATUS_OK;
  978. }
  979. }
  980. static void
  981. bfa_fcport_stats_get_timeout(void *cbarg)
  982. {
  983. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  984. bfa_trc(fcport->bfa, fcport->stats_qfull);
  985. if (fcport->stats_qfull) {
  986. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  987. fcport->stats_qfull = BFA_FALSE;
  988. }
  989. fcport->stats_status = BFA_STATUS_ETIMER;
  990. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe, __bfa_cb_fcport_stats_get,
  991. fcport);
  992. }
  993. static void
  994. bfa_fcport_send_stats_get(void *cbarg)
  995. {
  996. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  997. struct bfi_fcport_req_s *msg;
  998. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  999. if (!msg) {
  1000. fcport->stats_qfull = BFA_TRUE;
  1001. bfa_reqq_winit(&fcport->stats_reqq_wait,
  1002. bfa_fcport_send_stats_get, fcport);
  1003. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  1004. &fcport->stats_reqq_wait);
  1005. return;
  1006. }
  1007. fcport->stats_qfull = BFA_FALSE;
  1008. bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  1009. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_GET_REQ,
  1010. bfa_lpuid(fcport->bfa));
  1011. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  1012. }
  1013. static void
  1014. __bfa_cb_fcport_stats_clr(void *cbarg, bfa_boolean_t complete)
  1015. {
  1016. struct bfa_fcport_s *fcport = cbarg;
  1017. if (complete) {
  1018. struct bfa_timeval_s tv;
  1019. /**
  1020. * re-initialize time stamp for stats reset
  1021. */
  1022. bfa_os_gettimeofday(&tv);
  1023. fcport->stats_reset_time = tv.tv_sec;
  1024. fcport->stats_cbfn(fcport->stats_cbarg, fcport->stats_status);
  1025. } else {
  1026. fcport->stats_busy = BFA_FALSE;
  1027. fcport->stats_status = BFA_STATUS_OK;
  1028. }
  1029. }
  1030. static void
  1031. bfa_fcport_stats_clr_timeout(void *cbarg)
  1032. {
  1033. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  1034. bfa_trc(fcport->bfa, fcport->stats_qfull);
  1035. if (fcport->stats_qfull) {
  1036. bfa_reqq_wcancel(&fcport->stats_reqq_wait);
  1037. fcport->stats_qfull = BFA_FALSE;
  1038. }
  1039. fcport->stats_status = BFA_STATUS_ETIMER;
  1040. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  1041. __bfa_cb_fcport_stats_clr, fcport);
  1042. }
  1043. static void
  1044. bfa_fcport_send_stats_clear(void *cbarg)
  1045. {
  1046. struct bfa_fcport_s *fcport = (struct bfa_fcport_s *) cbarg;
  1047. struct bfi_fcport_req_s *msg;
  1048. msg = bfa_reqq_next(fcport->bfa, BFA_REQQ_PORT);
  1049. if (!msg) {
  1050. fcport->stats_qfull = BFA_TRUE;
  1051. bfa_reqq_winit(&fcport->stats_reqq_wait,
  1052. bfa_fcport_send_stats_clear, fcport);
  1053. bfa_reqq_wait(fcport->bfa, BFA_REQQ_PORT,
  1054. &fcport->stats_reqq_wait);
  1055. return;
  1056. }
  1057. fcport->stats_qfull = BFA_FALSE;
  1058. bfa_os_memset(msg, 0, sizeof(struct bfi_fcport_req_s));
  1059. bfi_h2i_set(msg->mh, BFI_MC_FCPORT, BFI_FCPORT_H2I_STATS_CLEAR_REQ,
  1060. bfa_lpuid(fcport->bfa));
  1061. bfa_reqq_produce(fcport->bfa, BFA_REQQ_PORT);
  1062. }
  1063. /**
  1064. * bfa_pport_public
  1065. */
  1066. /**
  1067. * Called to initialize port attributes
  1068. */
  1069. void
  1070. bfa_fcport_init(struct bfa_s *bfa)
  1071. {
  1072. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1073. /**
  1074. * Initialize port attributes from IOC hardware data.
  1075. */
  1076. bfa_fcport_set_wwns(fcport);
  1077. if (fcport->cfg.maxfrsize == 0)
  1078. fcport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  1079. fcport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  1080. fcport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  1081. bfa_assert(fcport->cfg.maxfrsize);
  1082. bfa_assert(fcport->cfg.rx_bbcredit);
  1083. bfa_assert(fcport->speed_sup);
  1084. }
  1085. /**
  1086. * Firmware message handler.
  1087. */
  1088. void
  1089. bfa_fcport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  1090. {
  1091. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1092. union bfi_fcport_i2h_msg_u i2hmsg;
  1093. i2hmsg.msg = msg;
  1094. fcport->event_arg.i2hmsg = i2hmsg;
  1095. switch (msg->mhdr.msg_id) {
  1096. case BFI_FCPORT_I2H_ENABLE_RSP:
  1097. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  1098. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  1099. break;
  1100. case BFI_FCPORT_I2H_DISABLE_RSP:
  1101. if (fcport->msgtag == i2hmsg.penable_rsp->msgtag)
  1102. bfa_sm_send_event(fcport, BFA_FCPORT_SM_FWRSP);
  1103. break;
  1104. case BFI_FCPORT_I2H_EVENT:
  1105. switch (i2hmsg.event->link_state.linkstate) {
  1106. case BFA_PPORT_LINKUP:
  1107. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKUP);
  1108. break;
  1109. case BFA_PPORT_LINKDOWN:
  1110. bfa_sm_send_event(fcport, BFA_FCPORT_SM_LINKDOWN);
  1111. break;
  1112. case BFA_PPORT_TRUNK_LINKDOWN:
  1113. /** todo: event notification */
  1114. break;
  1115. }
  1116. break;
  1117. case BFI_FCPORT_I2H_STATS_GET_RSP:
  1118. /*
  1119. * check for timer pop before processing the rsp
  1120. */
  1121. if (fcport->stats_busy == BFA_FALSE ||
  1122. fcport->stats_status == BFA_STATUS_ETIMER)
  1123. break;
  1124. bfa_timer_stop(&fcport->timer);
  1125. fcport->stats_status = i2hmsg.pstatsget_rsp->status;
  1126. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  1127. __bfa_cb_fcport_stats_get, fcport);
  1128. break;
  1129. case BFI_FCPORT_I2H_STATS_CLEAR_RSP:
  1130. /*
  1131. * check for timer pop before processing the rsp
  1132. */
  1133. if (fcport->stats_busy == BFA_FALSE ||
  1134. fcport->stats_status == BFA_STATUS_ETIMER)
  1135. break;
  1136. bfa_timer_stop(&fcport->timer);
  1137. fcport->stats_status = BFA_STATUS_OK;
  1138. bfa_cb_queue(fcport->bfa, &fcport->hcb_qe,
  1139. __bfa_cb_fcport_stats_clr, fcport);
  1140. break;
  1141. default:
  1142. bfa_assert(0);
  1143. break;
  1144. }
  1145. }
  1146. /**
  1147. * bfa_pport_api
  1148. */
  1149. /**
  1150. * Registered callback for port events.
  1151. */
  1152. void
  1153. bfa_fcport_event_register(struct bfa_s *bfa,
  1154. void (*cbfn) (void *cbarg, bfa_pport_event_t event),
  1155. void *cbarg)
  1156. {
  1157. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1158. fcport->event_cbfn = cbfn;
  1159. fcport->event_cbarg = cbarg;
  1160. }
  1161. bfa_status_t
  1162. bfa_fcport_enable(struct bfa_s *bfa)
  1163. {
  1164. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1165. if (fcport->diag_busy)
  1166. return BFA_STATUS_DIAG_BUSY;
  1167. else if (bfa_sm_cmp_state
  1168. (BFA_FCPORT_MOD(bfa), bfa_fcport_sm_disabling_qwait))
  1169. return BFA_STATUS_DEVBUSY;
  1170. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_ENABLE);
  1171. return BFA_STATUS_OK;
  1172. }
  1173. bfa_status_t
  1174. bfa_fcport_disable(struct bfa_s *bfa)
  1175. {
  1176. bfa_sm_send_event(BFA_FCPORT_MOD(bfa), BFA_FCPORT_SM_DISABLE);
  1177. return BFA_STATUS_OK;
  1178. }
  1179. /**
  1180. * Configure port speed.
  1181. */
  1182. bfa_status_t
  1183. bfa_fcport_cfg_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
  1184. {
  1185. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1186. bfa_trc(bfa, speed);
  1187. if ((speed != BFA_PPORT_SPEED_AUTO) && (speed > fcport->speed_sup)) {
  1188. bfa_trc(bfa, fcport->speed_sup);
  1189. return BFA_STATUS_UNSUPP_SPEED;
  1190. }
  1191. fcport->cfg.speed = speed;
  1192. return BFA_STATUS_OK;
  1193. }
  1194. /**
  1195. * Get current speed.
  1196. */
  1197. enum bfa_pport_speed
  1198. bfa_fcport_get_speed(struct bfa_s *bfa)
  1199. {
  1200. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1201. return fcport->speed;
  1202. }
  1203. /**
  1204. * Configure port topology.
  1205. */
  1206. bfa_status_t
  1207. bfa_fcport_cfg_topology(struct bfa_s *bfa, enum bfa_pport_topology topology)
  1208. {
  1209. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1210. bfa_trc(bfa, topology);
  1211. bfa_trc(bfa, fcport->cfg.topology);
  1212. switch (topology) {
  1213. case BFA_PPORT_TOPOLOGY_P2P:
  1214. case BFA_PPORT_TOPOLOGY_LOOP:
  1215. case BFA_PPORT_TOPOLOGY_AUTO:
  1216. break;
  1217. default:
  1218. return BFA_STATUS_EINVAL;
  1219. }
  1220. fcport->cfg.topology = topology;
  1221. return BFA_STATUS_OK;
  1222. }
  1223. /**
  1224. * Get current topology.
  1225. */
  1226. enum bfa_pport_topology
  1227. bfa_fcport_get_topology(struct bfa_s *bfa)
  1228. {
  1229. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1230. return fcport->topology;
  1231. }
  1232. bfa_status_t
  1233. bfa_fcport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  1234. {
  1235. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1236. bfa_trc(bfa, alpa);
  1237. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  1238. bfa_trc(bfa, fcport->cfg.hardalpa);
  1239. fcport->cfg.cfg_hardalpa = BFA_TRUE;
  1240. fcport->cfg.hardalpa = alpa;
  1241. return BFA_STATUS_OK;
  1242. }
  1243. bfa_status_t
  1244. bfa_fcport_clr_hardalpa(struct bfa_s *bfa)
  1245. {
  1246. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1247. bfa_trc(bfa, fcport->cfg.cfg_hardalpa);
  1248. bfa_trc(bfa, fcport->cfg.hardalpa);
  1249. fcport->cfg.cfg_hardalpa = BFA_FALSE;
  1250. return BFA_STATUS_OK;
  1251. }
  1252. bfa_boolean_t
  1253. bfa_fcport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  1254. {
  1255. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1256. *alpa = fcport->cfg.hardalpa;
  1257. return fcport->cfg.cfg_hardalpa;
  1258. }
  1259. u8
  1260. bfa_fcport_get_myalpa(struct bfa_s *bfa)
  1261. {
  1262. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1263. return fcport->myalpa;
  1264. }
  1265. bfa_status_t
  1266. bfa_fcport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  1267. {
  1268. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1269. bfa_trc(bfa, maxfrsize);
  1270. bfa_trc(bfa, fcport->cfg.maxfrsize);
  1271. /*
  1272. * with in range
  1273. */
  1274. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  1275. return BFA_STATUS_INVLD_DFSZ;
  1276. /*
  1277. * power of 2, if not the max frame size of 2112
  1278. */
  1279. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  1280. return BFA_STATUS_INVLD_DFSZ;
  1281. fcport->cfg.maxfrsize = maxfrsize;
  1282. return BFA_STATUS_OK;
  1283. }
  1284. u16
  1285. bfa_fcport_get_maxfrsize(struct bfa_s *bfa)
  1286. {
  1287. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1288. return fcport->cfg.maxfrsize;
  1289. }
  1290. u32
  1291. bfa_fcport_mypid(struct bfa_s *bfa)
  1292. {
  1293. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1294. return fcport->mypid;
  1295. }
  1296. u8
  1297. bfa_fcport_get_rx_bbcredit(struct bfa_s *bfa)
  1298. {
  1299. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1300. return fcport->cfg.rx_bbcredit;
  1301. }
  1302. void
  1303. bfa_fcport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
  1304. {
  1305. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1306. fcport->cfg.tx_bbcredit = (u8) tx_bbcredit;
  1307. bfa_fcport_send_txcredit(fcport);
  1308. }
  1309. /**
  1310. * Get port attributes.
  1311. */
  1312. wwn_t
  1313. bfa_fcport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  1314. {
  1315. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1316. if (node)
  1317. return fcport->nwwn;
  1318. else
  1319. return fcport->pwwn;
  1320. }
  1321. void
  1322. bfa_fcport_get_attr(struct bfa_s *bfa, struct bfa_pport_attr_s *attr)
  1323. {
  1324. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1325. bfa_os_memset(attr, 0, sizeof(struct bfa_pport_attr_s));
  1326. attr->nwwn = fcport->nwwn;
  1327. attr->pwwn = fcport->pwwn;
  1328. attr->factorypwwn = bfa_ioc_get_mfg_pwwn(&bfa->ioc);
  1329. attr->factorynwwn = bfa_ioc_get_mfg_nwwn(&bfa->ioc);
  1330. bfa_os_memcpy(&attr->pport_cfg, &fcport->cfg,
  1331. sizeof(struct bfa_pport_cfg_s));
  1332. /*
  1333. * speed attributes
  1334. */
  1335. attr->pport_cfg.speed = fcport->cfg.speed;
  1336. attr->speed_supported = fcport->speed_sup;
  1337. attr->speed = fcport->speed;
  1338. attr->cos_supported = FC_CLASS_3;
  1339. /*
  1340. * topology attributes
  1341. */
  1342. attr->pport_cfg.topology = fcport->cfg.topology;
  1343. attr->topology = fcport->topology;
  1344. /*
  1345. * beacon attributes
  1346. */
  1347. attr->beacon = fcport->beacon;
  1348. attr->link_e2e_beacon = fcport->link_e2e_beacon;
  1349. attr->plog_enabled = bfa_plog_get_setting(fcport->bfa->plog);
  1350. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  1351. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  1352. attr->port_state = bfa_sm_to_state(hal_pport_sm_table, fcport->sm);
  1353. if (bfa_ioc_is_disabled(&fcport->bfa->ioc))
  1354. attr->port_state = BFA_PPORT_ST_IOCDIS;
  1355. else if (bfa_ioc_fw_mismatch(&fcport->bfa->ioc))
  1356. attr->port_state = BFA_PPORT_ST_FWMISMATCH;
  1357. }
  1358. #define BFA_FCPORT_STATS_TOV 1000
  1359. /**
  1360. * Fetch port attributes (FCQoS or FCoE).
  1361. */
  1362. bfa_status_t
  1363. bfa_fcport_get_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  1364. bfa_cb_pport_t cbfn, void *cbarg)
  1365. {
  1366. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1367. if (fcport->stats_busy) {
  1368. bfa_trc(bfa, fcport->stats_busy);
  1369. return BFA_STATUS_DEVBUSY;
  1370. }
  1371. fcport->stats_busy = BFA_TRUE;
  1372. fcport->stats_ret = stats;
  1373. fcport->stats_cbfn = cbfn;
  1374. fcport->stats_cbarg = cbarg;
  1375. bfa_fcport_send_stats_get(fcport);
  1376. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_get_timeout,
  1377. fcport, BFA_FCPORT_STATS_TOV);
  1378. return BFA_STATUS_OK;
  1379. }
  1380. /**
  1381. * Reset port statistics (FCQoS or FCoE).
  1382. */
  1383. bfa_status_t
  1384. bfa_fcport_clear_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1385. {
  1386. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1387. if (fcport->stats_busy) {
  1388. bfa_trc(bfa, fcport->stats_busy);
  1389. return BFA_STATUS_DEVBUSY;
  1390. }
  1391. fcport->stats_busy = BFA_TRUE;
  1392. fcport->stats_cbfn = cbfn;
  1393. fcport->stats_cbarg = cbarg;
  1394. bfa_fcport_send_stats_clear(fcport);
  1395. bfa_timer_start(bfa, &fcport->timer, bfa_fcport_stats_clr_timeout,
  1396. fcport, BFA_FCPORT_STATS_TOV);
  1397. return BFA_STATUS_OK;
  1398. }
  1399. /**
  1400. * Fetch FCQoS port statistics
  1401. */
  1402. bfa_status_t
  1403. bfa_fcport_get_qos_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  1404. bfa_cb_pport_t cbfn, void *cbarg)
  1405. {
  1406. /* Meaningful only for FC mode */
  1407. bfa_assert(bfa_ioc_get_fcmode(&bfa->ioc));
  1408. return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
  1409. }
  1410. /**
  1411. * Reset FCoE port statistics
  1412. */
  1413. bfa_status_t
  1414. bfa_fcport_clear_qos_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1415. {
  1416. /* Meaningful only for FC mode */
  1417. bfa_assert(bfa_ioc_get_fcmode(&bfa->ioc));
  1418. return bfa_fcport_clear_stats(bfa, cbfn, cbarg);
  1419. }
  1420. /**
  1421. * Fetch FCQoS port statistics
  1422. */
  1423. bfa_status_t
  1424. bfa_fcport_get_fcoe_stats(struct bfa_s *bfa, union bfa_fcport_stats_u *stats,
  1425. bfa_cb_pport_t cbfn, void *cbarg)
  1426. {
  1427. /* Meaningful only for FCoE mode */
  1428. bfa_assert(!bfa_ioc_get_fcmode(&bfa->ioc));
  1429. return bfa_fcport_get_stats(bfa, stats, cbfn, cbarg);
  1430. }
  1431. /**
  1432. * Reset FCoE port statistics
  1433. */
  1434. bfa_status_t
  1435. bfa_fcport_clear_fcoe_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1436. {
  1437. /* Meaningful only for FCoE mode */
  1438. bfa_assert(!bfa_ioc_get_fcmode(&bfa->ioc));
  1439. return bfa_fcport_clear_stats(bfa, cbfn, cbarg);
  1440. }
  1441. bfa_status_t
  1442. bfa_fcport_trunk_enable(struct bfa_s *bfa, u8 bitmap)
  1443. {
  1444. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1445. bfa_trc(bfa, bitmap);
  1446. bfa_trc(bfa, fcport->cfg.trunked);
  1447. bfa_trc(bfa, fcport->cfg.trunk_ports);
  1448. if (!bitmap || (bitmap & (bitmap - 1)))
  1449. return BFA_STATUS_EINVAL;
  1450. fcport->cfg.trunked = BFA_TRUE;
  1451. fcport->cfg.trunk_ports = bitmap;
  1452. return BFA_STATUS_OK;
  1453. }
  1454. void
  1455. bfa_fcport_qos_get_attr(struct bfa_s *bfa, struct bfa_qos_attr_s *qos_attr)
  1456. {
  1457. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1458. qos_attr->state = bfa_os_ntohl(fcport->qos_attr.state);
  1459. qos_attr->total_bb_cr = bfa_os_ntohl(fcport->qos_attr.total_bb_cr);
  1460. }
  1461. void
  1462. bfa_fcport_qos_get_vc_attr(struct bfa_s *bfa,
  1463. struct bfa_qos_vc_attr_s *qos_vc_attr)
  1464. {
  1465. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1466. struct bfa_qos_vc_attr_s *bfa_vc_attr = &fcport->qos_vc_attr;
  1467. u32 i = 0;
  1468. qos_vc_attr->total_vc_count = bfa_os_ntohs(bfa_vc_attr->total_vc_count);
  1469. qos_vc_attr->shared_credit = bfa_os_ntohs(bfa_vc_attr->shared_credit);
  1470. qos_vc_attr->elp_opmode_flags =
  1471. bfa_os_ntohl(bfa_vc_attr->elp_opmode_flags);
  1472. /*
  1473. * Individual VC info
  1474. */
  1475. while (i < qos_vc_attr->total_vc_count) {
  1476. qos_vc_attr->vc_info[i].vc_credit =
  1477. bfa_vc_attr->vc_info[i].vc_credit;
  1478. qos_vc_attr->vc_info[i].borrow_credit =
  1479. bfa_vc_attr->vc_info[i].borrow_credit;
  1480. qos_vc_attr->vc_info[i].priority =
  1481. bfa_vc_attr->vc_info[i].priority;
  1482. ++i;
  1483. }
  1484. }
  1485. /**
  1486. * Fetch port attributes.
  1487. */
  1488. bfa_status_t
  1489. bfa_fcport_trunk_disable(struct bfa_s *bfa)
  1490. {
  1491. return BFA_STATUS_OK;
  1492. }
  1493. bfa_boolean_t
  1494. bfa_fcport_trunk_query(struct bfa_s *bfa, u32 *bitmap)
  1495. {
  1496. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1497. *bitmap = fcport->cfg.trunk_ports;
  1498. return fcport->cfg.trunked;
  1499. }
  1500. bfa_boolean_t
  1501. bfa_fcport_is_disabled(struct bfa_s *bfa)
  1502. {
  1503. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1504. return bfa_sm_to_state(hal_pport_sm_table, fcport->sm) ==
  1505. BFA_PPORT_ST_DISABLED;
  1506. }
  1507. bfa_boolean_t
  1508. bfa_fcport_is_ratelim(struct bfa_s *bfa)
  1509. {
  1510. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1511. return fcport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE;
  1512. }
  1513. void
  1514. bfa_fcport_cfg_qos(struct bfa_s *bfa, bfa_boolean_t on_off)
  1515. {
  1516. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1517. enum bfa_ioc_type_e ioc_type = bfa_get_type(bfa);
  1518. bfa_trc(bfa, on_off);
  1519. bfa_trc(bfa, fcport->cfg.qos_enabled);
  1520. bfa_trc(bfa, ioc_type);
  1521. if (ioc_type == BFA_IOC_TYPE_FC)
  1522. fcport->cfg.qos_enabled = on_off;
  1523. }
  1524. void
  1525. bfa_fcport_cfg_ratelim(struct bfa_s *bfa, bfa_boolean_t on_off)
  1526. {
  1527. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1528. bfa_trc(bfa, on_off);
  1529. bfa_trc(bfa, fcport->cfg.ratelimit);
  1530. fcport->cfg.ratelimit = on_off;
  1531. if (fcport->cfg.trl_def_speed == BFA_PPORT_SPEED_UNKNOWN)
  1532. fcport->cfg.trl_def_speed = BFA_PPORT_SPEED_1GBPS;
  1533. }
  1534. /**
  1535. * Configure default minimum ratelim speed
  1536. */
  1537. bfa_status_t
  1538. bfa_fcport_cfg_ratelim_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
  1539. {
  1540. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1541. bfa_trc(bfa, speed);
  1542. /*
  1543. * Auto and speeds greater than the supported speed, are invalid
  1544. */
  1545. if ((speed == BFA_PPORT_SPEED_AUTO) || (speed > fcport->speed_sup)) {
  1546. bfa_trc(bfa, fcport->speed_sup);
  1547. return BFA_STATUS_UNSUPP_SPEED;
  1548. }
  1549. fcport->cfg.trl_def_speed = speed;
  1550. return BFA_STATUS_OK;
  1551. }
  1552. /**
  1553. * Get default minimum ratelim speed
  1554. */
  1555. enum bfa_pport_speed
  1556. bfa_fcport_get_ratelim_speed(struct bfa_s *bfa)
  1557. {
  1558. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1559. bfa_trc(bfa, fcport->cfg.trl_def_speed);
  1560. return fcport->cfg.trl_def_speed;
  1561. }
  1562. void
  1563. bfa_fcport_busy(struct bfa_s *bfa, bfa_boolean_t status)
  1564. {
  1565. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1566. bfa_trc(bfa, status);
  1567. bfa_trc(bfa, fcport->diag_busy);
  1568. fcport->diag_busy = status;
  1569. }
  1570. void
  1571. bfa_fcport_beacon(struct bfa_s *bfa, bfa_boolean_t beacon,
  1572. bfa_boolean_t link_e2e_beacon)
  1573. {
  1574. struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa);
  1575. bfa_trc(bfa, beacon);
  1576. bfa_trc(bfa, link_e2e_beacon);
  1577. bfa_trc(bfa, fcport->beacon);
  1578. bfa_trc(bfa, fcport->link_e2e_beacon);
  1579. fcport->beacon = beacon;
  1580. fcport->link_e2e_beacon = link_e2e_beacon;
  1581. }
  1582. bfa_boolean_t
  1583. bfa_fcport_is_linkup(struct bfa_s *bfa)
  1584. {
  1585. return bfa_sm_cmp_state(BFA_FCPORT_MOD(bfa), bfa_fcport_sm_linkup);
  1586. }