bfa_fcport.c 44 KB

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