bfa_fcport.c 46 KB

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