bfa_fcport.c 38 KB

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