bfa_fcport.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671
  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. }
  345. break;
  346. case BFA_PPORT_SM_STOP:
  347. bfa_sm_set_state(pport, bfa_pport_sm_stopped);
  348. bfa_pport_reset_linkinfo(pport);
  349. if (BFA_PORT_IS_DISABLED(pport->bfa)) {
  350. bfa_pport_aen_post(pport, BFA_PORT_AEN_OFFLINE);
  351. } else {
  352. bfa_pport_aen_post(pport, BFA_PORT_AEN_DISCONNECT);
  353. }
  354. break;
  355. case BFA_PPORT_SM_HWFAIL:
  356. bfa_sm_set_state(pport, bfa_pport_sm_iocdown);
  357. bfa_pport_reset_linkinfo(pport);
  358. bfa_pport_callback(pport, BFA_PPORT_LINKDOWN);
  359. if (BFA_PORT_IS_DISABLED(pport->bfa)) {
  360. bfa_pport_aen_post(pport, BFA_PORT_AEN_OFFLINE);
  361. } else {
  362. bfa_pport_aen_post(pport, BFA_PORT_AEN_DISCONNECT);
  363. }
  364. break;
  365. default:
  366. bfa_sm_fault(pport->bfa, event);
  367. }
  368. }
  369. static void
  370. bfa_pport_sm_disabling_qwait(struct bfa_pport_s *pport,
  371. enum bfa_pport_sm_event event)
  372. {
  373. bfa_trc(pport->bfa, event);
  374. switch (event) {
  375. case BFA_PPORT_SM_QRESUME:
  376. bfa_sm_set_state(pport, bfa_pport_sm_disabling);
  377. bfa_pport_send_disable(pport);
  378. break;
  379. case BFA_PPORT_SM_STOP:
  380. bfa_sm_set_state(pport, bfa_pport_sm_stopped);
  381. bfa_reqq_wcancel(&pport->reqq_wait);
  382. break;
  383. case BFA_PPORT_SM_DISABLE:
  384. /**
  385. * Already being disabled.
  386. */
  387. break;
  388. case BFA_PPORT_SM_LINKUP:
  389. case BFA_PPORT_SM_LINKDOWN:
  390. /**
  391. * Possible to get link events when doing back-to-back
  392. * enable/disables.
  393. */
  394. break;
  395. case BFA_PPORT_SM_HWFAIL:
  396. bfa_sm_set_state(pport, bfa_pport_sm_iocfail);
  397. bfa_reqq_wcancel(&pport->reqq_wait);
  398. break;
  399. default:
  400. bfa_sm_fault(pport->bfa, event);
  401. }
  402. }
  403. static void
  404. bfa_pport_sm_disabling(struct bfa_pport_s *pport, enum bfa_pport_sm_event event)
  405. {
  406. bfa_trc(pport->bfa, event);
  407. switch (event) {
  408. case BFA_PPORT_SM_FWRSP:
  409. bfa_sm_set_state(pport, bfa_pport_sm_disabled);
  410. break;
  411. case BFA_PPORT_SM_DISABLE:
  412. /**
  413. * Already being disabled.
  414. */
  415. break;
  416. case BFA_PPORT_SM_ENABLE:
  417. if (bfa_pport_send_enable(pport))
  418. bfa_sm_set_state(pport, bfa_pport_sm_enabling);
  419. else
  420. bfa_sm_set_state(pport, bfa_pport_sm_enabling_qwait);
  421. bfa_plog_str(pport->bfa->plog, BFA_PL_MID_HAL,
  422. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  423. bfa_pport_aen_post(pport, BFA_PORT_AEN_ENABLE);
  424. break;
  425. case BFA_PPORT_SM_STOP:
  426. bfa_sm_set_state(pport, bfa_pport_sm_stopped);
  427. break;
  428. case BFA_PPORT_SM_LINKUP:
  429. case BFA_PPORT_SM_LINKDOWN:
  430. /**
  431. * Possible to get link events when doing back-to-back
  432. * enable/disables.
  433. */
  434. break;
  435. case BFA_PPORT_SM_HWFAIL:
  436. bfa_sm_set_state(pport, bfa_pport_sm_iocfail);
  437. break;
  438. default:
  439. bfa_sm_fault(pport->bfa, event);
  440. }
  441. }
  442. static void
  443. bfa_pport_sm_disabled(struct bfa_pport_s *pport, enum bfa_pport_sm_event event)
  444. {
  445. bfa_trc(pport->bfa, event);
  446. switch (event) {
  447. case BFA_PPORT_SM_START:
  448. /**
  449. * Ignore start event for a port that is disabled.
  450. */
  451. break;
  452. case BFA_PPORT_SM_STOP:
  453. bfa_sm_set_state(pport, bfa_pport_sm_stopped);
  454. break;
  455. case BFA_PPORT_SM_ENABLE:
  456. if (bfa_pport_send_enable(pport))
  457. bfa_sm_set_state(pport, bfa_pport_sm_enabling);
  458. else
  459. bfa_sm_set_state(pport, bfa_pport_sm_enabling_qwait);
  460. bfa_plog_str(pport->bfa->plog, BFA_PL_MID_HAL,
  461. BFA_PL_EID_PORT_ENABLE, 0, "Port Enable");
  462. bfa_pport_aen_post(pport, BFA_PORT_AEN_ENABLE);
  463. break;
  464. case BFA_PPORT_SM_DISABLE:
  465. /**
  466. * Already disabled.
  467. */
  468. break;
  469. case BFA_PPORT_SM_HWFAIL:
  470. bfa_sm_set_state(pport, bfa_pport_sm_iocfail);
  471. break;
  472. default:
  473. bfa_sm_fault(pport->bfa, event);
  474. }
  475. }
  476. static void
  477. bfa_pport_sm_stopped(struct bfa_pport_s *pport, enum bfa_pport_sm_event event)
  478. {
  479. bfa_trc(pport->bfa, event);
  480. switch (event) {
  481. case BFA_PPORT_SM_START:
  482. if (bfa_pport_send_enable(pport))
  483. bfa_sm_set_state(pport, bfa_pport_sm_enabling);
  484. else
  485. bfa_sm_set_state(pport, bfa_pport_sm_enabling_qwait);
  486. break;
  487. default:
  488. /**
  489. * Ignore all other events.
  490. */
  491. ;
  492. }
  493. }
  494. /**
  495. * Port is enabled. IOC is down/failed.
  496. */
  497. static void
  498. bfa_pport_sm_iocdown(struct bfa_pport_s *pport, enum bfa_pport_sm_event event)
  499. {
  500. bfa_trc(pport->bfa, event);
  501. switch (event) {
  502. case BFA_PPORT_SM_START:
  503. if (bfa_pport_send_enable(pport))
  504. bfa_sm_set_state(pport, bfa_pport_sm_enabling);
  505. else
  506. bfa_sm_set_state(pport, bfa_pport_sm_enabling_qwait);
  507. break;
  508. default:
  509. /**
  510. * Ignore all events.
  511. */
  512. ;
  513. }
  514. }
  515. /**
  516. * Port is disabled. IOC is down/failed.
  517. */
  518. static void
  519. bfa_pport_sm_iocfail(struct bfa_pport_s *pport, enum bfa_pport_sm_event event)
  520. {
  521. bfa_trc(pport->bfa, event);
  522. switch (event) {
  523. case BFA_PPORT_SM_START:
  524. bfa_sm_set_state(pport, bfa_pport_sm_disabled);
  525. break;
  526. case BFA_PPORT_SM_ENABLE:
  527. bfa_sm_set_state(pport, bfa_pport_sm_iocdown);
  528. break;
  529. default:
  530. /**
  531. * Ignore all events.
  532. */
  533. ;
  534. }
  535. }
  536. /**
  537. * bfa_pport_private
  538. */
  539. static void
  540. __bfa_cb_port_event(void *cbarg, bfa_boolean_t complete)
  541. {
  542. struct bfa_pport_s *pport = cbarg;
  543. if (complete)
  544. pport->event_cbfn(pport->event_cbarg, pport->hcb_event);
  545. }
  546. #define PPORT_STATS_DMA_SZ (BFA_ROUNDUP(sizeof(union bfa_pport_stats_u), \
  547. BFA_CACHELINE_SZ))
  548. static void
  549. bfa_pport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len,
  550. u32 *dm_len)
  551. {
  552. *dm_len += PPORT_STATS_DMA_SZ;
  553. }
  554. static void
  555. bfa_pport_qresume(void *cbarg)
  556. {
  557. struct bfa_pport_s *port = cbarg;
  558. bfa_sm_send_event(port, BFA_PPORT_SM_QRESUME);
  559. }
  560. static void
  561. bfa_pport_mem_claim(struct bfa_pport_s *pport, struct bfa_meminfo_s *meminfo)
  562. {
  563. u8 *dm_kva;
  564. u64 dm_pa;
  565. dm_kva = bfa_meminfo_dma_virt(meminfo);
  566. dm_pa = bfa_meminfo_dma_phys(meminfo);
  567. pport->stats_kva = dm_kva;
  568. pport->stats_pa = dm_pa;
  569. pport->stats = (union bfa_pport_stats_u *)dm_kva;
  570. dm_kva += PPORT_STATS_DMA_SZ;
  571. dm_pa += PPORT_STATS_DMA_SZ;
  572. bfa_meminfo_dma_virt(meminfo) = dm_kva;
  573. bfa_meminfo_dma_phys(meminfo) = dm_pa;
  574. }
  575. /**
  576. * Memory initialization.
  577. */
  578. static void
  579. bfa_pport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
  580. struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
  581. {
  582. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  583. struct bfa_pport_cfg_s *port_cfg = &pport->cfg;
  584. bfa_os_memset(pport, 0, sizeof(struct bfa_pport_s));
  585. pport->bfa = bfa;
  586. bfa_pport_mem_claim(pport, meminfo);
  587. bfa_sm_set_state(pport, bfa_pport_sm_uninit);
  588. /**
  589. * initialize and set default configuration
  590. */
  591. port_cfg->topology = BFA_PPORT_TOPOLOGY_P2P;
  592. port_cfg->speed = BFA_PPORT_SPEED_AUTO;
  593. port_cfg->trunked = BFA_FALSE;
  594. port_cfg->maxfrsize = 0;
  595. port_cfg->trl_def_speed = BFA_PPORT_SPEED_1GBPS;
  596. bfa_reqq_winit(&pport->reqq_wait, bfa_pport_qresume, pport);
  597. }
  598. static void
  599. bfa_pport_initdone(struct bfa_s *bfa)
  600. {
  601. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  602. /**
  603. * Initialize port attributes from IOC hardware data.
  604. */
  605. bfa_pport_set_wwns(pport);
  606. if (pport->cfg.maxfrsize == 0)
  607. pport->cfg.maxfrsize = bfa_ioc_maxfrsize(&bfa->ioc);
  608. pport->cfg.rx_bbcredit = bfa_ioc_rx_bbcredit(&bfa->ioc);
  609. pport->speed_sup = bfa_ioc_speed_sup(&bfa->ioc);
  610. bfa_assert(pport->cfg.maxfrsize);
  611. bfa_assert(pport->cfg.rx_bbcredit);
  612. bfa_assert(pport->speed_sup);
  613. }
  614. static void
  615. bfa_pport_detach(struct bfa_s *bfa)
  616. {
  617. }
  618. /**
  619. * Called when IOC is ready.
  620. */
  621. static void
  622. bfa_pport_start(struct bfa_s *bfa)
  623. {
  624. bfa_sm_send_event(BFA_PORT_MOD(bfa), BFA_PPORT_SM_START);
  625. }
  626. /**
  627. * Called before IOC is stopped.
  628. */
  629. static void
  630. bfa_pport_stop(struct bfa_s *bfa)
  631. {
  632. bfa_sm_send_event(BFA_PORT_MOD(bfa), BFA_PPORT_SM_STOP);
  633. }
  634. /**
  635. * Called when IOC failure is detected.
  636. */
  637. static void
  638. bfa_pport_iocdisable(struct bfa_s *bfa)
  639. {
  640. bfa_sm_send_event(BFA_PORT_MOD(bfa), BFA_PPORT_SM_HWFAIL);
  641. }
  642. static void
  643. bfa_pport_update_linkinfo(struct bfa_pport_s *pport)
  644. {
  645. struct bfi_pport_event_s *pevent = pport->event_arg.i2hmsg.event;
  646. pport->speed = pevent->link_state.speed;
  647. pport->topology = pevent->link_state.topology;
  648. if (pport->topology == BFA_PPORT_TOPOLOGY_LOOP)
  649. pport->myalpa = pevent->link_state.tl.loop_info.myalpa;
  650. /*
  651. * QoS Details
  652. */
  653. bfa_os_assign(pport->qos_attr, pevent->link_state.qos_attr);
  654. bfa_os_assign(pport->qos_vc_attr, pevent->link_state.qos_vc_attr);
  655. bfa_trc(pport->bfa, pport->speed);
  656. bfa_trc(pport->bfa, pport->topology);
  657. }
  658. static void
  659. bfa_pport_reset_linkinfo(struct bfa_pport_s *pport)
  660. {
  661. pport->speed = BFA_PPORT_SPEED_UNKNOWN;
  662. pport->topology = BFA_PPORT_TOPOLOGY_NONE;
  663. }
  664. /**
  665. * Send port enable message to firmware.
  666. */
  667. static bfa_boolean_t
  668. bfa_pport_send_enable(struct bfa_pport_s *port)
  669. {
  670. struct bfi_pport_enable_req_s *m;
  671. /**
  672. * Increment message tag before queue check, so that responses to old
  673. * requests are discarded.
  674. */
  675. port->msgtag++;
  676. /**
  677. * check for room in queue to send request now
  678. */
  679. m = bfa_reqq_next(port->bfa, BFA_REQQ_PORT);
  680. if (!m) {
  681. bfa_reqq_wait(port->bfa, BFA_REQQ_PORT, &port->reqq_wait);
  682. return BFA_FALSE;
  683. }
  684. bfi_h2i_set(m->mh, BFI_MC_FC_PORT, BFI_PPORT_H2I_ENABLE_REQ,
  685. bfa_lpuid(port->bfa));
  686. m->nwwn = port->nwwn;
  687. m->pwwn = port->pwwn;
  688. m->port_cfg = port->cfg;
  689. m->msgtag = port->msgtag;
  690. m->port_cfg.maxfrsize = bfa_os_htons(port->cfg.maxfrsize);
  691. bfa_dma_be_addr_set(m->stats_dma_addr, port->stats_pa);
  692. bfa_trc(port->bfa, m->stats_dma_addr.a32.addr_lo);
  693. bfa_trc(port->bfa, m->stats_dma_addr.a32.addr_hi);
  694. /**
  695. * queue I/O message to firmware
  696. */
  697. bfa_reqq_produce(port->bfa, BFA_REQQ_PORT);
  698. return BFA_TRUE;
  699. }
  700. /**
  701. * Send port disable message to firmware.
  702. */
  703. static bfa_boolean_t
  704. bfa_pport_send_disable(struct bfa_pport_s *port)
  705. {
  706. bfi_pport_disable_req_t *m;
  707. /**
  708. * Increment message tag before queue check, so that responses to old
  709. * requests are discarded.
  710. */
  711. port->msgtag++;
  712. /**
  713. * check for room in queue to send request now
  714. */
  715. m = bfa_reqq_next(port->bfa, BFA_REQQ_PORT);
  716. if (!m) {
  717. bfa_reqq_wait(port->bfa, BFA_REQQ_PORT, &port->reqq_wait);
  718. return BFA_FALSE;
  719. }
  720. bfi_h2i_set(m->mh, BFI_MC_FC_PORT, BFI_PPORT_H2I_DISABLE_REQ,
  721. bfa_lpuid(port->bfa));
  722. m->msgtag = port->msgtag;
  723. /**
  724. * queue I/O message to firmware
  725. */
  726. bfa_reqq_produce(port->bfa, BFA_REQQ_PORT);
  727. return BFA_TRUE;
  728. }
  729. static void
  730. bfa_pport_set_wwns(struct bfa_pport_s *port)
  731. {
  732. port->pwwn = bfa_ioc_get_pwwn(&port->bfa->ioc);
  733. port->nwwn = bfa_ioc_get_nwwn(&port->bfa->ioc);
  734. bfa_trc(port->bfa, port->pwwn);
  735. bfa_trc(port->bfa, port->nwwn);
  736. }
  737. static void
  738. bfa_port_send_txcredit(void *port_cbarg)
  739. {
  740. struct bfa_pport_s *port = port_cbarg;
  741. struct bfi_pport_set_svc_params_req_s *m;
  742. /**
  743. * check for room in queue to send request now
  744. */
  745. m = bfa_reqq_next(port->bfa, BFA_REQQ_PORT);
  746. if (!m) {
  747. bfa_trc(port->bfa, port->cfg.tx_bbcredit);
  748. return;
  749. }
  750. bfi_h2i_set(m->mh, BFI_MC_FC_PORT, BFI_PPORT_H2I_SET_SVC_PARAMS_REQ,
  751. bfa_lpuid(port->bfa));
  752. m->tx_bbcredit = bfa_os_htons((u16) port->cfg.tx_bbcredit);
  753. /**
  754. * queue I/O message to firmware
  755. */
  756. bfa_reqq_produce(port->bfa, BFA_REQQ_PORT);
  757. }
  758. /**
  759. * bfa_pport_public
  760. */
  761. /**
  762. * Firmware message handler.
  763. */
  764. void
  765. bfa_pport_isr(struct bfa_s *bfa, struct bfi_msg_s *msg)
  766. {
  767. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  768. union bfi_pport_i2h_msg_u i2hmsg;
  769. i2hmsg.msg = msg;
  770. pport->event_arg.i2hmsg = i2hmsg;
  771. switch (msg->mhdr.msg_id) {
  772. case BFI_PPORT_I2H_ENABLE_RSP:
  773. if (pport->msgtag == i2hmsg.enable_rsp->msgtag)
  774. bfa_sm_send_event(pport, BFA_PPORT_SM_FWRSP);
  775. break;
  776. case BFI_PPORT_I2H_DISABLE_RSP:
  777. if (pport->msgtag == i2hmsg.enable_rsp->msgtag)
  778. bfa_sm_send_event(pport, BFA_PPORT_SM_FWRSP);
  779. break;
  780. case BFI_PPORT_I2H_EVENT:
  781. switch (i2hmsg.event->link_state.linkstate) {
  782. case BFA_PPORT_LINKUP:
  783. bfa_sm_send_event(pport, BFA_PPORT_SM_LINKUP);
  784. break;
  785. case BFA_PPORT_LINKDOWN:
  786. bfa_sm_send_event(pport, BFA_PPORT_SM_LINKDOWN);
  787. break;
  788. case BFA_PPORT_TRUNK_LINKDOWN:
  789. /** todo: event notification */
  790. break;
  791. }
  792. break;
  793. case BFI_PPORT_I2H_GET_STATS_RSP:
  794. case BFI_PPORT_I2H_GET_QOS_STATS_RSP:
  795. /*
  796. * check for timer pop before processing the rsp
  797. */
  798. if (pport->stats_busy == BFA_FALSE
  799. || pport->stats_status == BFA_STATUS_ETIMER)
  800. break;
  801. bfa_timer_stop(&pport->timer);
  802. pport->stats_status = i2hmsg.getstats_rsp->status;
  803. bfa_cb_queue(pport->bfa, &pport->hcb_qe, __bfa_cb_port_stats,
  804. pport);
  805. break;
  806. case BFI_PPORT_I2H_CLEAR_STATS_RSP:
  807. case BFI_PPORT_I2H_CLEAR_QOS_STATS_RSP:
  808. /*
  809. * check for timer pop before processing the rsp
  810. */
  811. if (pport->stats_busy == BFA_FALSE
  812. || pport->stats_status == BFA_STATUS_ETIMER)
  813. break;
  814. bfa_timer_stop(&pport->timer);
  815. pport->stats_status = BFA_STATUS_OK;
  816. bfa_cb_queue(pport->bfa, &pport->hcb_qe,
  817. __bfa_cb_port_stats_clr, pport);
  818. break;
  819. default:
  820. bfa_assert(0);
  821. }
  822. }
  823. /**
  824. * bfa_pport_api
  825. */
  826. /**
  827. * Registered callback for port events.
  828. */
  829. void
  830. bfa_pport_event_register(struct bfa_s *bfa,
  831. void (*cbfn) (void *cbarg, bfa_pport_event_t event),
  832. void *cbarg)
  833. {
  834. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  835. pport->event_cbfn = cbfn;
  836. pport->event_cbarg = cbarg;
  837. }
  838. bfa_status_t
  839. bfa_pport_enable(struct bfa_s *bfa)
  840. {
  841. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  842. if (pport->diag_busy)
  843. return (BFA_STATUS_DIAG_BUSY);
  844. else if (bfa_sm_cmp_state
  845. (BFA_PORT_MOD(bfa), bfa_pport_sm_disabling_qwait))
  846. return (BFA_STATUS_DEVBUSY);
  847. bfa_sm_send_event(BFA_PORT_MOD(bfa), BFA_PPORT_SM_ENABLE);
  848. return BFA_STATUS_OK;
  849. }
  850. bfa_status_t
  851. bfa_pport_disable(struct bfa_s *bfa)
  852. {
  853. bfa_sm_send_event(BFA_PORT_MOD(bfa), BFA_PPORT_SM_DISABLE);
  854. return BFA_STATUS_OK;
  855. }
  856. /**
  857. * Configure port speed.
  858. */
  859. bfa_status_t
  860. bfa_pport_cfg_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
  861. {
  862. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  863. bfa_trc(bfa, speed);
  864. if ((speed != BFA_PPORT_SPEED_AUTO) && (speed > pport->speed_sup)) {
  865. bfa_trc(bfa, pport->speed_sup);
  866. return BFA_STATUS_UNSUPP_SPEED;
  867. }
  868. pport->cfg.speed = speed;
  869. return (BFA_STATUS_OK);
  870. }
  871. /**
  872. * Get current speed.
  873. */
  874. enum bfa_pport_speed
  875. bfa_pport_get_speed(struct bfa_s *bfa)
  876. {
  877. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  878. return port->speed;
  879. }
  880. /**
  881. * Configure port topology.
  882. */
  883. bfa_status_t
  884. bfa_pport_cfg_topology(struct bfa_s *bfa, enum bfa_pport_topology topology)
  885. {
  886. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  887. bfa_trc(bfa, topology);
  888. bfa_trc(bfa, pport->cfg.topology);
  889. switch (topology) {
  890. case BFA_PPORT_TOPOLOGY_P2P:
  891. case BFA_PPORT_TOPOLOGY_LOOP:
  892. case BFA_PPORT_TOPOLOGY_AUTO:
  893. break;
  894. default:
  895. return BFA_STATUS_EINVAL;
  896. }
  897. pport->cfg.topology = topology;
  898. return (BFA_STATUS_OK);
  899. }
  900. /**
  901. * Get current topology.
  902. */
  903. enum bfa_pport_topology
  904. bfa_pport_get_topology(struct bfa_s *bfa)
  905. {
  906. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  907. return port->topology;
  908. }
  909. bfa_status_t
  910. bfa_pport_cfg_hardalpa(struct bfa_s *bfa, u8 alpa)
  911. {
  912. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  913. bfa_trc(bfa, alpa);
  914. bfa_trc(bfa, pport->cfg.cfg_hardalpa);
  915. bfa_trc(bfa, pport->cfg.hardalpa);
  916. pport->cfg.cfg_hardalpa = BFA_TRUE;
  917. pport->cfg.hardalpa = alpa;
  918. return (BFA_STATUS_OK);
  919. }
  920. bfa_status_t
  921. bfa_pport_clr_hardalpa(struct bfa_s *bfa)
  922. {
  923. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  924. bfa_trc(bfa, pport->cfg.cfg_hardalpa);
  925. bfa_trc(bfa, pport->cfg.hardalpa);
  926. pport->cfg.cfg_hardalpa = BFA_FALSE;
  927. return (BFA_STATUS_OK);
  928. }
  929. bfa_boolean_t
  930. bfa_pport_get_hardalpa(struct bfa_s *bfa, u8 *alpa)
  931. {
  932. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  933. *alpa = port->cfg.hardalpa;
  934. return port->cfg.cfg_hardalpa;
  935. }
  936. u8
  937. bfa_pport_get_myalpa(struct bfa_s *bfa)
  938. {
  939. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  940. return port->myalpa;
  941. }
  942. bfa_status_t
  943. bfa_pport_cfg_maxfrsize(struct bfa_s *bfa, u16 maxfrsize)
  944. {
  945. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  946. bfa_trc(bfa, maxfrsize);
  947. bfa_trc(bfa, pport->cfg.maxfrsize);
  948. /*
  949. * with in range
  950. */
  951. if ((maxfrsize > FC_MAX_PDUSZ) || (maxfrsize < FC_MIN_PDUSZ))
  952. return (BFA_STATUS_INVLD_DFSZ);
  953. /*
  954. * power of 2, if not the max frame size of 2112
  955. */
  956. if ((maxfrsize != FC_MAX_PDUSZ) && (maxfrsize & (maxfrsize - 1)))
  957. return (BFA_STATUS_INVLD_DFSZ);
  958. pport->cfg.maxfrsize = maxfrsize;
  959. return (BFA_STATUS_OK);
  960. }
  961. u16
  962. bfa_pport_get_maxfrsize(struct bfa_s *bfa)
  963. {
  964. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  965. return port->cfg.maxfrsize;
  966. }
  967. u32
  968. bfa_pport_mypid(struct bfa_s *bfa)
  969. {
  970. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  971. return port->mypid;
  972. }
  973. u8
  974. bfa_pport_get_rx_bbcredit(struct bfa_s *bfa)
  975. {
  976. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  977. return port->cfg.rx_bbcredit;
  978. }
  979. void
  980. bfa_pport_set_tx_bbcredit(struct bfa_s *bfa, u16 tx_bbcredit)
  981. {
  982. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  983. port->cfg.tx_bbcredit = (u8) tx_bbcredit;
  984. bfa_port_send_txcredit(port);
  985. }
  986. /**
  987. * Get port attributes.
  988. */
  989. wwn_t
  990. bfa_pport_get_wwn(struct bfa_s *bfa, bfa_boolean_t node)
  991. {
  992. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  993. if (node)
  994. return pport->nwwn;
  995. else
  996. return pport->pwwn;
  997. }
  998. void
  999. bfa_pport_get_attr(struct bfa_s *bfa, struct bfa_pport_attr_s *attr)
  1000. {
  1001. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1002. bfa_os_memset(attr, 0, sizeof(struct bfa_pport_attr_s));
  1003. attr->nwwn = pport->nwwn;
  1004. attr->pwwn = pport->pwwn;
  1005. bfa_os_memcpy(&attr->pport_cfg, &pport->cfg,
  1006. sizeof(struct bfa_pport_cfg_s));
  1007. /*
  1008. * speed attributes
  1009. */
  1010. attr->pport_cfg.speed = pport->cfg.speed;
  1011. attr->speed_supported = pport->speed_sup;
  1012. attr->speed = pport->speed;
  1013. attr->cos_supported = FC_CLASS_3;
  1014. /*
  1015. * topology attributes
  1016. */
  1017. attr->pport_cfg.topology = pport->cfg.topology;
  1018. attr->topology = pport->topology;
  1019. /*
  1020. * beacon attributes
  1021. */
  1022. attr->beacon = pport->beacon;
  1023. attr->link_e2e_beacon = pport->link_e2e_beacon;
  1024. attr->plog_enabled = bfa_plog_get_setting(pport->bfa->plog);
  1025. attr->pport_cfg.path_tov = bfa_fcpim_path_tov_get(bfa);
  1026. attr->pport_cfg.q_depth = bfa_fcpim_qdepth_get(bfa);
  1027. attr->port_state = bfa_sm_to_state(hal_pport_sm_table, pport->sm);
  1028. if (bfa_ioc_is_disabled(&pport->bfa->ioc))
  1029. attr->port_state = BFA_PPORT_ST_IOCDIS;
  1030. else if (bfa_ioc_fw_mismatch(&pport->bfa->ioc))
  1031. attr->port_state = BFA_PPORT_ST_FWMISMATCH;
  1032. }
  1033. static void
  1034. bfa_port_stats_query(void *cbarg)
  1035. {
  1036. struct bfa_pport_s *port = (struct bfa_pport_s *)cbarg;
  1037. bfi_pport_get_stats_req_t *msg;
  1038. msg = bfa_reqq_next(port->bfa, BFA_REQQ_PORT);
  1039. if (!msg) {
  1040. port->stats_qfull = BFA_TRUE;
  1041. bfa_reqq_winit(&port->stats_reqq_wait, bfa_port_stats_query,
  1042. port);
  1043. bfa_reqq_wait(port->bfa, BFA_REQQ_PORT, &port->stats_reqq_wait);
  1044. return;
  1045. }
  1046. port->stats_qfull = BFA_FALSE;
  1047. bfa_os_memset(msg, 0, sizeof(bfi_pport_get_stats_req_t));
  1048. bfi_h2i_set(msg->mh, BFI_MC_FC_PORT, BFI_PPORT_H2I_GET_STATS_REQ,
  1049. bfa_lpuid(port->bfa));
  1050. bfa_reqq_produce(port->bfa, BFA_REQQ_PORT);
  1051. return;
  1052. }
  1053. static void
  1054. bfa_port_stats_clear(void *cbarg)
  1055. {
  1056. struct bfa_pport_s *port = (struct bfa_pport_s *)cbarg;
  1057. bfi_pport_clear_stats_req_t *msg;
  1058. msg = bfa_reqq_next(port->bfa, BFA_REQQ_PORT);
  1059. if (!msg) {
  1060. port->stats_qfull = BFA_TRUE;
  1061. bfa_reqq_winit(&port->stats_reqq_wait, bfa_port_stats_clear,
  1062. port);
  1063. bfa_reqq_wait(port->bfa, BFA_REQQ_PORT, &port->stats_reqq_wait);
  1064. return;
  1065. }
  1066. port->stats_qfull = BFA_FALSE;
  1067. bfa_os_memset(msg, 0, sizeof(bfi_pport_clear_stats_req_t));
  1068. bfi_h2i_set(msg->mh, BFI_MC_FC_PORT, BFI_PPORT_H2I_CLEAR_STATS_REQ,
  1069. bfa_lpuid(port->bfa));
  1070. bfa_reqq_produce(port->bfa, BFA_REQQ_PORT);
  1071. return;
  1072. }
  1073. static void
  1074. bfa_port_qos_stats_clear(void *cbarg)
  1075. {
  1076. struct bfa_pport_s *port = (struct bfa_pport_s *)cbarg;
  1077. bfi_pport_clear_qos_stats_req_t *msg;
  1078. msg = bfa_reqq_next(port->bfa, BFA_REQQ_PORT);
  1079. if (!msg) {
  1080. port->stats_qfull = BFA_TRUE;
  1081. bfa_reqq_winit(&port->stats_reqq_wait, bfa_port_qos_stats_clear,
  1082. port);
  1083. bfa_reqq_wait(port->bfa, BFA_REQQ_PORT, &port->stats_reqq_wait);
  1084. return;
  1085. }
  1086. port->stats_qfull = BFA_FALSE;
  1087. bfa_os_memset(msg, 0, sizeof(bfi_pport_clear_qos_stats_req_t));
  1088. bfi_h2i_set(msg->mh, BFI_MC_FC_PORT, BFI_PPORT_H2I_CLEAR_QOS_STATS_REQ,
  1089. bfa_lpuid(port->bfa));
  1090. bfa_reqq_produce(port->bfa, BFA_REQQ_PORT);
  1091. return;
  1092. }
  1093. static void
  1094. bfa_pport_stats_swap(union bfa_pport_stats_u *d, union bfa_pport_stats_u *s)
  1095. {
  1096. u32 *dip = (u32 *) d;
  1097. u32 *sip = (u32 *) s;
  1098. int i;
  1099. /*
  1100. * Do 64 bit fields swap first
  1101. */
  1102. for (i = 0;
  1103. i <
  1104. ((sizeof(union bfa_pport_stats_u) -
  1105. sizeof(struct bfa_qos_stats_s)) / sizeof(u32)); i = i + 2) {
  1106. #ifdef __BIGENDIAN
  1107. dip[i] = bfa_os_ntohl(sip[i]);
  1108. dip[i + 1] = bfa_os_ntohl(sip[i + 1]);
  1109. #else
  1110. dip[i] = bfa_os_ntohl(sip[i + 1]);
  1111. dip[i + 1] = bfa_os_ntohl(sip[i]);
  1112. #endif
  1113. }
  1114. /*
  1115. * Now swap the 32 bit fields
  1116. */
  1117. for (; i < (sizeof(union bfa_pport_stats_u) / sizeof(u32)); ++i)
  1118. dip[i] = bfa_os_ntohl(sip[i]);
  1119. }
  1120. static void
  1121. __bfa_cb_port_stats_clr(void *cbarg, bfa_boolean_t complete)
  1122. {
  1123. struct bfa_pport_s *port = cbarg;
  1124. if (complete) {
  1125. port->stats_cbfn(port->stats_cbarg, port->stats_status);
  1126. } else {
  1127. port->stats_busy = BFA_FALSE;
  1128. port->stats_status = BFA_STATUS_OK;
  1129. }
  1130. }
  1131. static void
  1132. bfa_port_stats_clr_timeout(void *cbarg)
  1133. {
  1134. struct bfa_pport_s *port = (struct bfa_pport_s *)cbarg;
  1135. bfa_trc(port->bfa, port->stats_qfull);
  1136. if (port->stats_qfull) {
  1137. bfa_reqq_wcancel(&port->stats_reqq_wait);
  1138. port->stats_qfull = BFA_FALSE;
  1139. }
  1140. port->stats_status = BFA_STATUS_ETIMER;
  1141. bfa_cb_queue(port->bfa, &port->hcb_qe, __bfa_cb_port_stats_clr, port);
  1142. }
  1143. static void
  1144. __bfa_cb_port_stats(void *cbarg, bfa_boolean_t complete)
  1145. {
  1146. struct bfa_pport_s *port = cbarg;
  1147. if (complete) {
  1148. if (port->stats_status == BFA_STATUS_OK)
  1149. bfa_pport_stats_swap(port->stats_ret, port->stats);
  1150. port->stats_cbfn(port->stats_cbarg, port->stats_status);
  1151. } else {
  1152. port->stats_busy = BFA_FALSE;
  1153. port->stats_status = BFA_STATUS_OK;
  1154. }
  1155. }
  1156. static void
  1157. bfa_port_stats_timeout(void *cbarg)
  1158. {
  1159. struct bfa_pport_s *port = (struct bfa_pport_s *)cbarg;
  1160. bfa_trc(port->bfa, port->stats_qfull);
  1161. if (port->stats_qfull) {
  1162. bfa_reqq_wcancel(&port->stats_reqq_wait);
  1163. port->stats_qfull = BFA_FALSE;
  1164. }
  1165. port->stats_status = BFA_STATUS_ETIMER;
  1166. bfa_cb_queue(port->bfa, &port->hcb_qe, __bfa_cb_port_stats, port);
  1167. }
  1168. #define BFA_PORT_STATS_TOV 1000
  1169. /**
  1170. * Fetch port attributes.
  1171. */
  1172. bfa_status_t
  1173. bfa_pport_get_stats(struct bfa_s *bfa, union bfa_pport_stats_u *stats,
  1174. bfa_cb_pport_t cbfn, void *cbarg)
  1175. {
  1176. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  1177. if (port->stats_busy) {
  1178. bfa_trc(bfa, port->stats_busy);
  1179. return (BFA_STATUS_DEVBUSY);
  1180. }
  1181. port->stats_busy = BFA_TRUE;
  1182. port->stats_ret = stats;
  1183. port->stats_cbfn = cbfn;
  1184. port->stats_cbarg = cbarg;
  1185. bfa_port_stats_query(port);
  1186. bfa_timer_start(bfa, &port->timer, bfa_port_stats_timeout, port,
  1187. BFA_PORT_STATS_TOV);
  1188. return (BFA_STATUS_OK);
  1189. }
  1190. bfa_status_t
  1191. bfa_pport_clear_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1192. {
  1193. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  1194. if (port->stats_busy) {
  1195. bfa_trc(bfa, port->stats_busy);
  1196. return (BFA_STATUS_DEVBUSY);
  1197. }
  1198. port->stats_busy = BFA_TRUE;
  1199. port->stats_cbfn = cbfn;
  1200. port->stats_cbarg = cbarg;
  1201. bfa_port_stats_clear(port);
  1202. bfa_timer_start(bfa, &port->timer, bfa_port_stats_clr_timeout, port,
  1203. BFA_PORT_STATS_TOV);
  1204. return (BFA_STATUS_OK);
  1205. }
  1206. bfa_status_t
  1207. bfa_pport_trunk_enable(struct bfa_s *bfa, u8 bitmap)
  1208. {
  1209. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1210. bfa_trc(bfa, bitmap);
  1211. bfa_trc(bfa, pport->cfg.trunked);
  1212. bfa_trc(bfa, pport->cfg.trunk_ports);
  1213. if (!bitmap || (bitmap & (bitmap - 1)))
  1214. return BFA_STATUS_EINVAL;
  1215. pport->cfg.trunked = BFA_TRUE;
  1216. pport->cfg.trunk_ports = bitmap;
  1217. return BFA_STATUS_OK;
  1218. }
  1219. void
  1220. bfa_pport_qos_get_attr(struct bfa_s *bfa, struct bfa_qos_attr_s *qos_attr)
  1221. {
  1222. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1223. qos_attr->state = bfa_os_ntohl(pport->qos_attr.state);
  1224. qos_attr->total_bb_cr = bfa_os_ntohl(pport->qos_attr.total_bb_cr);
  1225. }
  1226. void
  1227. bfa_pport_qos_get_vc_attr(struct bfa_s *bfa,
  1228. struct bfa_qos_vc_attr_s *qos_vc_attr)
  1229. {
  1230. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1231. struct bfa_qos_vc_attr_s *bfa_vc_attr = &pport->qos_vc_attr;
  1232. u32 i = 0;
  1233. qos_vc_attr->total_vc_count = bfa_os_ntohs(bfa_vc_attr->total_vc_count);
  1234. qos_vc_attr->shared_credit = bfa_os_ntohs(bfa_vc_attr->shared_credit);
  1235. qos_vc_attr->elp_opmode_flags =
  1236. bfa_os_ntohl(bfa_vc_attr->elp_opmode_flags);
  1237. /*
  1238. * Individual VC info
  1239. */
  1240. while (i < qos_vc_attr->total_vc_count) {
  1241. qos_vc_attr->vc_info[i].vc_credit =
  1242. bfa_vc_attr->vc_info[i].vc_credit;
  1243. qos_vc_attr->vc_info[i].borrow_credit =
  1244. bfa_vc_attr->vc_info[i].borrow_credit;
  1245. qos_vc_attr->vc_info[i].priority =
  1246. bfa_vc_attr->vc_info[i].priority;
  1247. ++i;
  1248. }
  1249. }
  1250. /**
  1251. * Fetch QoS Stats.
  1252. */
  1253. bfa_status_t
  1254. bfa_pport_get_qos_stats(struct bfa_s *bfa, union bfa_pport_stats_u *stats,
  1255. bfa_cb_pport_t cbfn, void *cbarg)
  1256. {
  1257. /*
  1258. * QoS stats is embedded in port stats
  1259. */
  1260. return (bfa_pport_get_stats(bfa, stats, cbfn, cbarg));
  1261. }
  1262. bfa_status_t
  1263. bfa_pport_clear_qos_stats(struct bfa_s *bfa, bfa_cb_pport_t cbfn, void *cbarg)
  1264. {
  1265. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  1266. if (port->stats_busy) {
  1267. bfa_trc(bfa, port->stats_busy);
  1268. return (BFA_STATUS_DEVBUSY);
  1269. }
  1270. port->stats_busy = BFA_TRUE;
  1271. port->stats_cbfn = cbfn;
  1272. port->stats_cbarg = cbarg;
  1273. bfa_port_qos_stats_clear(port);
  1274. bfa_timer_start(bfa, &port->timer, bfa_port_stats_clr_timeout, port,
  1275. BFA_PORT_STATS_TOV);
  1276. return (BFA_STATUS_OK);
  1277. }
  1278. /**
  1279. * Fetch port attributes.
  1280. */
  1281. bfa_status_t
  1282. bfa_pport_trunk_disable(struct bfa_s *bfa)
  1283. {
  1284. return (BFA_STATUS_OK);
  1285. }
  1286. bfa_boolean_t
  1287. bfa_pport_trunk_query(struct bfa_s *bfa, u32 *bitmap)
  1288. {
  1289. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  1290. *bitmap = port->cfg.trunk_ports;
  1291. return port->cfg.trunked;
  1292. }
  1293. bfa_boolean_t
  1294. bfa_pport_is_disabled(struct bfa_s *bfa)
  1295. {
  1296. struct bfa_pport_s *port = BFA_PORT_MOD(bfa);
  1297. return (bfa_sm_to_state(hal_pport_sm_table, port->sm) ==
  1298. BFA_PPORT_ST_DISABLED);
  1299. }
  1300. bfa_boolean_t
  1301. bfa_pport_is_ratelim(struct bfa_s *bfa)
  1302. {
  1303. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1304. return (pport->cfg.ratelimit ? BFA_TRUE : BFA_FALSE);
  1305. }
  1306. void
  1307. bfa_pport_cfg_qos(struct bfa_s *bfa, bfa_boolean_t on_off)
  1308. {
  1309. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1310. bfa_trc(bfa, on_off);
  1311. bfa_trc(bfa, pport->cfg.qos_enabled);
  1312. pport->cfg.qos_enabled = on_off;
  1313. }
  1314. void
  1315. bfa_pport_cfg_ratelim(struct bfa_s *bfa, bfa_boolean_t on_off)
  1316. {
  1317. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1318. bfa_trc(bfa, on_off);
  1319. bfa_trc(bfa, pport->cfg.ratelimit);
  1320. pport->cfg.ratelimit = on_off;
  1321. if (pport->cfg.trl_def_speed == BFA_PPORT_SPEED_UNKNOWN)
  1322. pport->cfg.trl_def_speed = BFA_PPORT_SPEED_1GBPS;
  1323. }
  1324. /**
  1325. * Configure default minimum ratelim speed
  1326. */
  1327. bfa_status_t
  1328. bfa_pport_cfg_ratelim_speed(struct bfa_s *bfa, enum bfa_pport_speed speed)
  1329. {
  1330. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1331. bfa_trc(bfa, speed);
  1332. /*
  1333. * Auto and speeds greater than the supported speed, are invalid
  1334. */
  1335. if ((speed == BFA_PPORT_SPEED_AUTO) || (speed > pport->speed_sup)) {
  1336. bfa_trc(bfa, pport->speed_sup);
  1337. return BFA_STATUS_UNSUPP_SPEED;
  1338. }
  1339. pport->cfg.trl_def_speed = speed;
  1340. return (BFA_STATUS_OK);
  1341. }
  1342. /**
  1343. * Get default minimum ratelim speed
  1344. */
  1345. enum bfa_pport_speed
  1346. bfa_pport_get_ratelim_speed(struct bfa_s *bfa)
  1347. {
  1348. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1349. bfa_trc(bfa, pport->cfg.trl_def_speed);
  1350. return (pport->cfg.trl_def_speed);
  1351. }
  1352. void
  1353. bfa_pport_busy(struct bfa_s *bfa, bfa_boolean_t status)
  1354. {
  1355. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1356. bfa_trc(bfa, status);
  1357. bfa_trc(bfa, pport->diag_busy);
  1358. pport->diag_busy = status;
  1359. }
  1360. void
  1361. bfa_pport_beacon(struct bfa_s *bfa, bfa_boolean_t beacon,
  1362. bfa_boolean_t link_e2e_beacon)
  1363. {
  1364. struct bfa_pport_s *pport = BFA_PORT_MOD(bfa);
  1365. bfa_trc(bfa, beacon);
  1366. bfa_trc(bfa, link_e2e_beacon);
  1367. bfa_trc(bfa, pport->beacon);
  1368. bfa_trc(bfa, pport->link_e2e_beacon);
  1369. pport->beacon = beacon;
  1370. pport->link_e2e_beacon = link_e2e_beacon;
  1371. }
  1372. bfa_boolean_t
  1373. bfa_pport_is_linkup(struct bfa_s *bfa)
  1374. {
  1375. return bfa_sm_cmp_state(BFA_PORT_MOD(bfa), bfa_pport_sm_linkup);
  1376. }