bna_enet.c 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152
  1. /*
  2. * Linux network driver for Brocade Converged Network Adapter.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License (GPL) Version 2 as
  6. * published by the Free Software Foundation
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. */
  13. /*
  14. * Copyright (c) 2005-2011 Brocade Communications Systems, Inc.
  15. * All rights reserved
  16. * www.brocade.com
  17. */
  18. #include "bna.h"
  19. static inline int
  20. ethport_can_be_up(struct bna_ethport *ethport)
  21. {
  22. int ready = 0;
  23. if (ethport->bna->enet.type == BNA_ENET_T_REGULAR)
  24. ready = ((ethport->flags & BNA_ETHPORT_F_ADMIN_UP) &&
  25. (ethport->flags & BNA_ETHPORT_F_RX_STARTED) &&
  26. (ethport->flags & BNA_ETHPORT_F_PORT_ENABLED));
  27. else
  28. ready = ((ethport->flags & BNA_ETHPORT_F_ADMIN_UP) &&
  29. (ethport->flags & BNA_ETHPORT_F_RX_STARTED) &&
  30. !(ethport->flags & BNA_ETHPORT_F_PORT_ENABLED));
  31. return ready;
  32. }
  33. #define ethport_is_up ethport_can_be_up
  34. enum bna_ethport_event {
  35. ETHPORT_E_START = 1,
  36. ETHPORT_E_STOP = 2,
  37. ETHPORT_E_FAIL = 3,
  38. ETHPORT_E_UP = 4,
  39. ETHPORT_E_DOWN = 5,
  40. ETHPORT_E_FWRESP_UP_OK = 6,
  41. ETHPORT_E_FWRESP_DOWN = 7,
  42. ETHPORT_E_FWRESP_UP_FAIL = 8,
  43. };
  44. enum bna_enet_event {
  45. ENET_E_START = 1,
  46. ENET_E_STOP = 2,
  47. ENET_E_FAIL = 3,
  48. ENET_E_PAUSE_CFG = 4,
  49. ENET_E_MTU_CFG = 5,
  50. ENET_E_FWRESP_PAUSE = 6,
  51. ENET_E_CHLD_STOPPED = 7,
  52. };
  53. enum bna_ioceth_event {
  54. IOCETH_E_ENABLE = 1,
  55. IOCETH_E_DISABLE = 2,
  56. IOCETH_E_IOC_RESET = 3,
  57. IOCETH_E_IOC_FAILED = 4,
  58. IOCETH_E_IOC_READY = 5,
  59. IOCETH_E_ENET_ATTR_RESP = 6,
  60. IOCETH_E_ENET_STOPPED = 7,
  61. IOCETH_E_IOC_DISABLED = 8,
  62. };
  63. #define bna_stats_copy(_name, _type) \
  64. do { \
  65. count = sizeof(struct bfi_enet_stats_ ## _type) / sizeof(u64); \
  66. stats_src = (u64 *)&bna->stats.hw_stats_kva->_name ## _stats; \
  67. stats_dst = (u64 *)&bna->stats.hw_stats._name ## _stats; \
  68. for (i = 0; i < count; i++) \
  69. stats_dst[i] = be64_to_cpu(stats_src[i]); \
  70. } while (0) \
  71. /*
  72. * FW response handlers
  73. */
  74. static void
  75. bna_bfi_ethport_enable_aen(struct bna_ethport *ethport,
  76. struct bfi_msgq_mhdr *msghdr)
  77. {
  78. ethport->flags |= BNA_ETHPORT_F_PORT_ENABLED;
  79. if (ethport_can_be_up(ethport))
  80. bfa_fsm_send_event(ethport, ETHPORT_E_UP);
  81. }
  82. static void
  83. bna_bfi_ethport_disable_aen(struct bna_ethport *ethport,
  84. struct bfi_msgq_mhdr *msghdr)
  85. {
  86. int ethport_up = ethport_is_up(ethport);
  87. ethport->flags &= ~BNA_ETHPORT_F_PORT_ENABLED;
  88. if (ethport_up)
  89. bfa_fsm_send_event(ethport, ETHPORT_E_DOWN);
  90. }
  91. static void
  92. bna_bfi_ethport_admin_rsp(struct bna_ethport *ethport,
  93. struct bfi_msgq_mhdr *msghdr)
  94. {
  95. struct bfi_enet_enable_req *admin_req =
  96. &ethport->bfi_enet_cmd.admin_req;
  97. struct bfi_enet_rsp *rsp = (struct bfi_enet_rsp *)msghdr;
  98. switch (admin_req->enable) {
  99. case BNA_STATUS_T_ENABLED:
  100. if (rsp->error == BFI_ENET_CMD_OK)
  101. bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_OK);
  102. else {
  103. ethport->flags &= ~BNA_ETHPORT_F_PORT_ENABLED;
  104. bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_FAIL);
  105. }
  106. break;
  107. case BNA_STATUS_T_DISABLED:
  108. bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_DOWN);
  109. ethport->link_status = BNA_LINK_DOWN;
  110. ethport->link_cbfn(ethport->bna->bnad, BNA_LINK_DOWN);
  111. break;
  112. }
  113. }
  114. static void
  115. bna_bfi_ethport_lpbk_rsp(struct bna_ethport *ethport,
  116. struct bfi_msgq_mhdr *msghdr)
  117. {
  118. struct bfi_enet_diag_lb_req *diag_lb_req =
  119. &ethport->bfi_enet_cmd.lpbk_req;
  120. struct bfi_enet_rsp *rsp = (struct bfi_enet_rsp *)msghdr;
  121. switch (diag_lb_req->enable) {
  122. case BNA_STATUS_T_ENABLED:
  123. if (rsp->error == BFI_ENET_CMD_OK)
  124. bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_OK);
  125. else {
  126. ethport->flags &= ~BNA_ETHPORT_F_ADMIN_UP;
  127. bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_UP_FAIL);
  128. }
  129. break;
  130. case BNA_STATUS_T_DISABLED:
  131. bfa_fsm_send_event(ethport, ETHPORT_E_FWRESP_DOWN);
  132. break;
  133. }
  134. }
  135. static void
  136. bna_bfi_pause_set_rsp(struct bna_enet *enet, struct bfi_msgq_mhdr *msghdr)
  137. {
  138. bfa_fsm_send_event(enet, ENET_E_FWRESP_PAUSE);
  139. }
  140. static void
  141. bna_bfi_attr_get_rsp(struct bna_ioceth *ioceth,
  142. struct bfi_msgq_mhdr *msghdr)
  143. {
  144. struct bfi_enet_attr_rsp *rsp = (struct bfi_enet_attr_rsp *)msghdr;
  145. /**
  146. * Store only if not set earlier, since BNAD can override the HW
  147. * attributes
  148. */
  149. if (!ioceth->attr.fw_query_complete) {
  150. ioceth->attr.num_txq = ntohl(rsp->max_cfg);
  151. ioceth->attr.num_rxp = ntohl(rsp->max_cfg);
  152. ioceth->attr.num_ucmac = ntohl(rsp->max_ucmac);
  153. ioceth->attr.num_mcmac = BFI_ENET_MAX_MCAM;
  154. ioceth->attr.max_rit_size = ntohl(rsp->rit_size);
  155. ioceth->attr.fw_query_complete = true;
  156. }
  157. bfa_fsm_send_event(ioceth, IOCETH_E_ENET_ATTR_RESP);
  158. }
  159. static void
  160. bna_bfi_stats_get_rsp(struct bna *bna, struct bfi_msgq_mhdr *msghdr)
  161. {
  162. struct bfi_enet_stats_req *stats_req = &bna->stats_mod.stats_get;
  163. u64 *stats_src;
  164. u64 *stats_dst;
  165. u32 tx_enet_mask = ntohl(stats_req->tx_enet_mask);
  166. u32 rx_enet_mask = ntohl(stats_req->rx_enet_mask);
  167. int count;
  168. int i;
  169. bna_stats_copy(mac, mac);
  170. bna_stats_copy(bpc, bpc);
  171. bna_stats_copy(rad, rad);
  172. bna_stats_copy(rlb, rad);
  173. bna_stats_copy(fc_rx, fc_rx);
  174. bna_stats_copy(fc_tx, fc_tx);
  175. stats_src = (u64 *)&(bna->stats.hw_stats_kva->rxf_stats[0]);
  176. /* Copy Rxf stats to SW area, scatter them while copying */
  177. for (i = 0; i < BFI_ENET_CFG_MAX; i++) {
  178. stats_dst = (u64 *)&(bna->stats.hw_stats.rxf_stats[i]);
  179. memset(stats_dst, 0, sizeof(struct bfi_enet_stats_rxf));
  180. if (rx_enet_mask & ((u32)(1 << i))) {
  181. int k;
  182. count = sizeof(struct bfi_enet_stats_rxf) /
  183. sizeof(u64);
  184. for (k = 0; k < count; k++) {
  185. stats_dst[k] = be64_to_cpu(*stats_src);
  186. stats_src++;
  187. }
  188. }
  189. }
  190. /* Copy Txf stats to SW area, scatter them while copying */
  191. for (i = 0; i < BFI_ENET_CFG_MAX; i++) {
  192. stats_dst = (u64 *)&(bna->stats.hw_stats.txf_stats[i]);
  193. memset(stats_dst, 0, sizeof(struct bfi_enet_stats_txf));
  194. if (tx_enet_mask & ((u32)(1 << i))) {
  195. int k;
  196. count = sizeof(struct bfi_enet_stats_txf) /
  197. sizeof(u64);
  198. for (k = 0; k < count; k++) {
  199. stats_dst[k] = be64_to_cpu(*stats_src);
  200. stats_src++;
  201. }
  202. }
  203. }
  204. bna->stats_mod.stats_get_busy = false;
  205. bnad_cb_stats_get(bna->bnad, BNA_CB_SUCCESS, &bna->stats);
  206. }
  207. static void
  208. bna_bfi_ethport_linkup_aen(struct bna_ethport *ethport,
  209. struct bfi_msgq_mhdr *msghdr)
  210. {
  211. ethport->link_status = BNA_LINK_UP;
  212. /* Dispatch events */
  213. ethport->link_cbfn(ethport->bna->bnad, ethport->link_status);
  214. }
  215. static void
  216. bna_bfi_ethport_linkdown_aen(struct bna_ethport *ethport,
  217. struct bfi_msgq_mhdr *msghdr)
  218. {
  219. ethport->link_status = BNA_LINK_DOWN;
  220. /* Dispatch events */
  221. ethport->link_cbfn(ethport->bna->bnad, BNA_LINK_DOWN);
  222. }
  223. static void
  224. bna_err_handler(struct bna *bna, u32 intr_status)
  225. {
  226. if (BNA_IS_HALT_INTR(bna, intr_status))
  227. bna_halt_clear(bna);
  228. bfa_nw_ioc_error_isr(&bna->ioceth.ioc);
  229. }
  230. void
  231. bna_mbox_handler(struct bna *bna, u32 intr_status)
  232. {
  233. if (BNA_IS_ERR_INTR(bna, intr_status)) {
  234. bna_err_handler(bna, intr_status);
  235. return;
  236. }
  237. if (BNA_IS_MBOX_INTR(bna, intr_status))
  238. bfa_nw_ioc_mbox_isr(&bna->ioceth.ioc);
  239. }
  240. static void
  241. bna_msgq_rsp_handler(void *arg, struct bfi_msgq_mhdr *msghdr)
  242. {
  243. struct bna *bna = (struct bna *)arg;
  244. struct bna_tx *tx;
  245. struct bna_rx *rx;
  246. switch (msghdr->msg_id) {
  247. case BFI_ENET_I2H_RX_CFG_SET_RSP:
  248. bna_rx_from_rid(bna, msghdr->enet_id, rx);
  249. if (rx)
  250. bna_bfi_rx_enet_start_rsp(rx, msghdr);
  251. break;
  252. case BFI_ENET_I2H_RX_CFG_CLR_RSP:
  253. bna_rx_from_rid(bna, msghdr->enet_id, rx);
  254. if (rx)
  255. bna_bfi_rx_enet_stop_rsp(rx, msghdr);
  256. break;
  257. case BFI_ENET_I2H_RIT_CFG_RSP:
  258. case BFI_ENET_I2H_RSS_CFG_RSP:
  259. case BFI_ENET_I2H_RSS_ENABLE_RSP:
  260. case BFI_ENET_I2H_RX_PROMISCUOUS_RSP:
  261. case BFI_ENET_I2H_RX_DEFAULT_RSP:
  262. case BFI_ENET_I2H_MAC_UCAST_SET_RSP:
  263. case BFI_ENET_I2H_MAC_UCAST_CLR_RSP:
  264. case BFI_ENET_I2H_MAC_UCAST_ADD_RSP:
  265. case BFI_ENET_I2H_MAC_UCAST_DEL_RSP:
  266. case BFI_ENET_I2H_MAC_MCAST_DEL_RSP:
  267. case BFI_ENET_I2H_MAC_MCAST_FILTER_RSP:
  268. case BFI_ENET_I2H_RX_VLAN_SET_RSP:
  269. case BFI_ENET_I2H_RX_VLAN_STRIP_ENABLE_RSP:
  270. bna_rx_from_rid(bna, msghdr->enet_id, rx);
  271. if (rx)
  272. bna_bfi_rxf_cfg_rsp(&rx->rxf, msghdr);
  273. break;
  274. case BFI_ENET_I2H_MAC_MCAST_ADD_RSP:
  275. bna_rx_from_rid(bna, msghdr->enet_id, rx);
  276. if (rx)
  277. bna_bfi_rxf_mcast_add_rsp(&rx->rxf, msghdr);
  278. break;
  279. case BFI_ENET_I2H_TX_CFG_SET_RSP:
  280. bna_tx_from_rid(bna, msghdr->enet_id, tx);
  281. if (tx)
  282. bna_bfi_tx_enet_start_rsp(tx, msghdr);
  283. break;
  284. case BFI_ENET_I2H_TX_CFG_CLR_RSP:
  285. bna_tx_from_rid(bna, msghdr->enet_id, tx);
  286. if (tx)
  287. bna_bfi_tx_enet_stop_rsp(tx, msghdr);
  288. break;
  289. case BFI_ENET_I2H_PORT_ADMIN_RSP:
  290. bna_bfi_ethport_admin_rsp(&bna->ethport, msghdr);
  291. break;
  292. case BFI_ENET_I2H_DIAG_LOOPBACK_RSP:
  293. bna_bfi_ethport_lpbk_rsp(&bna->ethport, msghdr);
  294. break;
  295. case BFI_ENET_I2H_SET_PAUSE_RSP:
  296. bna_bfi_pause_set_rsp(&bna->enet, msghdr);
  297. break;
  298. case BFI_ENET_I2H_GET_ATTR_RSP:
  299. bna_bfi_attr_get_rsp(&bna->ioceth, msghdr);
  300. break;
  301. case BFI_ENET_I2H_STATS_GET_RSP:
  302. bna_bfi_stats_get_rsp(bna, msghdr);
  303. break;
  304. case BFI_ENET_I2H_STATS_CLR_RSP:
  305. /* No-op */
  306. break;
  307. case BFI_ENET_I2H_LINK_UP_AEN:
  308. bna_bfi_ethport_linkup_aen(&bna->ethport, msghdr);
  309. break;
  310. case BFI_ENET_I2H_LINK_DOWN_AEN:
  311. bna_bfi_ethport_linkdown_aen(&bna->ethport, msghdr);
  312. break;
  313. case BFI_ENET_I2H_PORT_ENABLE_AEN:
  314. bna_bfi_ethport_enable_aen(&bna->ethport, msghdr);
  315. break;
  316. case BFI_ENET_I2H_PORT_DISABLE_AEN:
  317. bna_bfi_ethport_disable_aen(&bna->ethport, msghdr);
  318. break;
  319. case BFI_ENET_I2H_BW_UPDATE_AEN:
  320. bna_bfi_bw_update_aen(&bna->tx_mod);
  321. break;
  322. default:
  323. break;
  324. }
  325. }
  326. /**
  327. * ETHPORT
  328. */
  329. #define call_ethport_stop_cbfn(_ethport) \
  330. do { \
  331. if ((_ethport)->stop_cbfn) { \
  332. void (*cbfn)(struct bna_enet *); \
  333. cbfn = (_ethport)->stop_cbfn; \
  334. (_ethport)->stop_cbfn = NULL; \
  335. cbfn(&(_ethport)->bna->enet); \
  336. } \
  337. } while (0)
  338. #define call_ethport_adminup_cbfn(ethport, status) \
  339. do { \
  340. if ((ethport)->adminup_cbfn) { \
  341. void (*cbfn)(struct bnad *, enum bna_cb_status); \
  342. cbfn = (ethport)->adminup_cbfn; \
  343. (ethport)->adminup_cbfn = NULL; \
  344. cbfn((ethport)->bna->bnad, status); \
  345. } \
  346. } while (0)
  347. static void
  348. bna_bfi_ethport_admin_up(struct bna_ethport *ethport)
  349. {
  350. struct bfi_enet_enable_req *admin_up_req =
  351. &ethport->bfi_enet_cmd.admin_req;
  352. bfi_msgq_mhdr_set(admin_up_req->mh, BFI_MC_ENET,
  353. BFI_ENET_H2I_PORT_ADMIN_UP_REQ, 0, 0);
  354. admin_up_req->mh.num_entries = htons(
  355. bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req)));
  356. admin_up_req->enable = BNA_STATUS_T_ENABLED;
  357. bfa_msgq_cmd_set(&ethport->msgq_cmd, NULL, NULL,
  358. sizeof(struct bfi_enet_enable_req), &admin_up_req->mh);
  359. bfa_msgq_cmd_post(&ethport->bna->msgq, &ethport->msgq_cmd);
  360. }
  361. static void
  362. bna_bfi_ethport_admin_down(struct bna_ethport *ethport)
  363. {
  364. struct bfi_enet_enable_req *admin_down_req =
  365. &ethport->bfi_enet_cmd.admin_req;
  366. bfi_msgq_mhdr_set(admin_down_req->mh, BFI_MC_ENET,
  367. BFI_ENET_H2I_PORT_ADMIN_UP_REQ, 0, 0);
  368. admin_down_req->mh.num_entries = htons(
  369. bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_enable_req)));
  370. admin_down_req->enable = BNA_STATUS_T_DISABLED;
  371. bfa_msgq_cmd_set(&ethport->msgq_cmd, NULL, NULL,
  372. sizeof(struct bfi_enet_enable_req), &admin_down_req->mh);
  373. bfa_msgq_cmd_post(&ethport->bna->msgq, &ethport->msgq_cmd);
  374. }
  375. static void
  376. bna_bfi_ethport_lpbk_up(struct bna_ethport *ethport)
  377. {
  378. struct bfi_enet_diag_lb_req *lpbk_up_req =
  379. &ethport->bfi_enet_cmd.lpbk_req;
  380. bfi_msgq_mhdr_set(lpbk_up_req->mh, BFI_MC_ENET,
  381. BFI_ENET_H2I_DIAG_LOOPBACK_REQ, 0, 0);
  382. lpbk_up_req->mh.num_entries = htons(
  383. bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_diag_lb_req)));
  384. lpbk_up_req->mode = (ethport->bna->enet.type ==
  385. BNA_ENET_T_LOOPBACK_INTERNAL) ?
  386. BFI_ENET_DIAG_LB_OPMODE_EXT :
  387. BFI_ENET_DIAG_LB_OPMODE_CBL;
  388. lpbk_up_req->enable = BNA_STATUS_T_ENABLED;
  389. bfa_msgq_cmd_set(&ethport->msgq_cmd, NULL, NULL,
  390. sizeof(struct bfi_enet_diag_lb_req), &lpbk_up_req->mh);
  391. bfa_msgq_cmd_post(&ethport->bna->msgq, &ethport->msgq_cmd);
  392. }
  393. static void
  394. bna_bfi_ethport_lpbk_down(struct bna_ethport *ethport)
  395. {
  396. struct bfi_enet_diag_lb_req *lpbk_down_req =
  397. &ethport->bfi_enet_cmd.lpbk_req;
  398. bfi_msgq_mhdr_set(lpbk_down_req->mh, BFI_MC_ENET,
  399. BFI_ENET_H2I_DIAG_LOOPBACK_REQ, 0, 0);
  400. lpbk_down_req->mh.num_entries = htons(
  401. bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_diag_lb_req)));
  402. lpbk_down_req->enable = BNA_STATUS_T_DISABLED;
  403. bfa_msgq_cmd_set(&ethport->msgq_cmd, NULL, NULL,
  404. sizeof(struct bfi_enet_diag_lb_req), &lpbk_down_req->mh);
  405. bfa_msgq_cmd_post(&ethport->bna->msgq, &ethport->msgq_cmd);
  406. }
  407. static void
  408. bna_bfi_ethport_up(struct bna_ethport *ethport)
  409. {
  410. if (ethport->bna->enet.type == BNA_ENET_T_REGULAR)
  411. bna_bfi_ethport_admin_up(ethport);
  412. else
  413. bna_bfi_ethport_lpbk_up(ethport);
  414. }
  415. static void
  416. bna_bfi_ethport_down(struct bna_ethport *ethport)
  417. {
  418. if (ethport->bna->enet.type == BNA_ENET_T_REGULAR)
  419. bna_bfi_ethport_admin_down(ethport);
  420. else
  421. bna_bfi_ethport_lpbk_down(ethport);
  422. }
  423. bfa_fsm_state_decl(bna_ethport, stopped, struct bna_ethport,
  424. enum bna_ethport_event);
  425. bfa_fsm_state_decl(bna_ethport, down, struct bna_ethport,
  426. enum bna_ethport_event);
  427. bfa_fsm_state_decl(bna_ethport, up_resp_wait, struct bna_ethport,
  428. enum bna_ethport_event);
  429. bfa_fsm_state_decl(bna_ethport, down_resp_wait, struct bna_ethport,
  430. enum bna_ethport_event);
  431. bfa_fsm_state_decl(bna_ethport, up, struct bna_ethport,
  432. enum bna_ethport_event);
  433. bfa_fsm_state_decl(bna_ethport, last_resp_wait, struct bna_ethport,
  434. enum bna_ethport_event);
  435. static void
  436. bna_ethport_sm_stopped_entry(struct bna_ethport *ethport)
  437. {
  438. call_ethport_stop_cbfn(ethport);
  439. }
  440. static void
  441. bna_ethport_sm_stopped(struct bna_ethport *ethport,
  442. enum bna_ethport_event event)
  443. {
  444. switch (event) {
  445. case ETHPORT_E_START:
  446. bfa_fsm_set_state(ethport, bna_ethport_sm_down);
  447. break;
  448. case ETHPORT_E_STOP:
  449. call_ethport_stop_cbfn(ethport);
  450. break;
  451. case ETHPORT_E_FAIL:
  452. /* No-op */
  453. break;
  454. case ETHPORT_E_DOWN:
  455. /* This event is received due to Rx objects failing */
  456. /* No-op */
  457. break;
  458. default:
  459. bfa_sm_fault(event);
  460. }
  461. }
  462. static void
  463. bna_ethport_sm_down_entry(struct bna_ethport *ethport)
  464. {
  465. }
  466. static void
  467. bna_ethport_sm_down(struct bna_ethport *ethport,
  468. enum bna_ethport_event event)
  469. {
  470. switch (event) {
  471. case ETHPORT_E_STOP:
  472. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  473. break;
  474. case ETHPORT_E_FAIL:
  475. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  476. break;
  477. case ETHPORT_E_UP:
  478. bfa_fsm_set_state(ethport, bna_ethport_sm_up_resp_wait);
  479. bna_bfi_ethport_up(ethport);
  480. break;
  481. default:
  482. bfa_sm_fault(event);
  483. }
  484. }
  485. static void
  486. bna_ethport_sm_up_resp_wait_entry(struct bna_ethport *ethport)
  487. {
  488. }
  489. static void
  490. bna_ethport_sm_up_resp_wait(struct bna_ethport *ethport,
  491. enum bna_ethport_event event)
  492. {
  493. switch (event) {
  494. case ETHPORT_E_STOP:
  495. bfa_fsm_set_state(ethport, bna_ethport_sm_last_resp_wait);
  496. break;
  497. case ETHPORT_E_FAIL:
  498. call_ethport_adminup_cbfn(ethport, BNA_CB_FAIL);
  499. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  500. break;
  501. case ETHPORT_E_DOWN:
  502. call_ethport_adminup_cbfn(ethport, BNA_CB_INTERRUPT);
  503. bfa_fsm_set_state(ethport, bna_ethport_sm_down_resp_wait);
  504. break;
  505. case ETHPORT_E_FWRESP_UP_OK:
  506. call_ethport_adminup_cbfn(ethport, BNA_CB_SUCCESS);
  507. bfa_fsm_set_state(ethport, bna_ethport_sm_up);
  508. break;
  509. case ETHPORT_E_FWRESP_UP_FAIL:
  510. call_ethport_adminup_cbfn(ethport, BNA_CB_FAIL);
  511. bfa_fsm_set_state(ethport, bna_ethport_sm_down);
  512. break;
  513. case ETHPORT_E_FWRESP_DOWN:
  514. /* down_resp_wait -> up_resp_wait transition on ETHPORT_E_UP */
  515. bna_bfi_ethport_up(ethport);
  516. break;
  517. default:
  518. bfa_sm_fault(event);
  519. }
  520. }
  521. static void
  522. bna_ethport_sm_down_resp_wait_entry(struct bna_ethport *ethport)
  523. {
  524. /**
  525. * NOTE: Do not call bna_bfi_ethport_down() here. That will over step
  526. * mbox due to up_resp_wait -> down_resp_wait transition on event
  527. * ETHPORT_E_DOWN
  528. */
  529. }
  530. static void
  531. bna_ethport_sm_down_resp_wait(struct bna_ethport *ethport,
  532. enum bna_ethport_event event)
  533. {
  534. switch (event) {
  535. case ETHPORT_E_STOP:
  536. bfa_fsm_set_state(ethport, bna_ethport_sm_last_resp_wait);
  537. break;
  538. case ETHPORT_E_FAIL:
  539. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  540. break;
  541. case ETHPORT_E_UP:
  542. bfa_fsm_set_state(ethport, bna_ethport_sm_up_resp_wait);
  543. break;
  544. case ETHPORT_E_FWRESP_UP_OK:
  545. /* up_resp_wait->down_resp_wait transition on ETHPORT_E_DOWN */
  546. bna_bfi_ethport_down(ethport);
  547. break;
  548. case ETHPORT_E_FWRESP_UP_FAIL:
  549. case ETHPORT_E_FWRESP_DOWN:
  550. bfa_fsm_set_state(ethport, bna_ethport_sm_down);
  551. break;
  552. default:
  553. bfa_sm_fault(event);
  554. }
  555. }
  556. static void
  557. bna_ethport_sm_up_entry(struct bna_ethport *ethport)
  558. {
  559. }
  560. static void
  561. bna_ethport_sm_up(struct bna_ethport *ethport,
  562. enum bna_ethport_event event)
  563. {
  564. switch (event) {
  565. case ETHPORT_E_STOP:
  566. bfa_fsm_set_state(ethport, bna_ethport_sm_last_resp_wait);
  567. bna_bfi_ethport_down(ethport);
  568. break;
  569. case ETHPORT_E_FAIL:
  570. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  571. break;
  572. case ETHPORT_E_DOWN:
  573. bfa_fsm_set_state(ethport, bna_ethport_sm_down_resp_wait);
  574. bna_bfi_ethport_down(ethport);
  575. break;
  576. default:
  577. bfa_sm_fault(event);
  578. }
  579. }
  580. static void
  581. bna_ethport_sm_last_resp_wait_entry(struct bna_ethport *ethport)
  582. {
  583. }
  584. static void
  585. bna_ethport_sm_last_resp_wait(struct bna_ethport *ethport,
  586. enum bna_ethport_event event)
  587. {
  588. switch (event) {
  589. case ETHPORT_E_FAIL:
  590. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  591. break;
  592. case ETHPORT_E_DOWN:
  593. /**
  594. * This event is received due to Rx objects stopping in
  595. * parallel to ethport
  596. */
  597. /* No-op */
  598. break;
  599. case ETHPORT_E_FWRESP_UP_OK:
  600. /* up_resp_wait->last_resp_wait transition on ETHPORT_T_STOP */
  601. bna_bfi_ethport_down(ethport);
  602. break;
  603. case ETHPORT_E_FWRESP_UP_FAIL:
  604. case ETHPORT_E_FWRESP_DOWN:
  605. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  606. break;
  607. default:
  608. bfa_sm_fault(event);
  609. }
  610. }
  611. static void
  612. bna_ethport_init(struct bna_ethport *ethport, struct bna *bna)
  613. {
  614. ethport->flags |= (BNA_ETHPORT_F_ADMIN_UP | BNA_ETHPORT_F_PORT_ENABLED);
  615. ethport->bna = bna;
  616. ethport->link_status = BNA_LINK_DOWN;
  617. ethport->link_cbfn = bnad_cb_ethport_link_status;
  618. ethport->rx_started_count = 0;
  619. ethport->stop_cbfn = NULL;
  620. ethport->adminup_cbfn = NULL;
  621. bfa_fsm_set_state(ethport, bna_ethport_sm_stopped);
  622. }
  623. static void
  624. bna_ethport_uninit(struct bna_ethport *ethport)
  625. {
  626. ethport->flags &= ~BNA_ETHPORT_F_ADMIN_UP;
  627. ethport->flags &= ~BNA_ETHPORT_F_PORT_ENABLED;
  628. ethport->bna = NULL;
  629. }
  630. static void
  631. bna_ethport_start(struct bna_ethport *ethport)
  632. {
  633. bfa_fsm_send_event(ethport, ETHPORT_E_START);
  634. }
  635. static void
  636. bna_enet_cb_ethport_stopped(struct bna_enet *enet)
  637. {
  638. bfa_wc_down(&enet->chld_stop_wc);
  639. }
  640. static void
  641. bna_ethport_stop(struct bna_ethport *ethport)
  642. {
  643. ethport->stop_cbfn = bna_enet_cb_ethport_stopped;
  644. bfa_fsm_send_event(ethport, ETHPORT_E_STOP);
  645. }
  646. static void
  647. bna_ethport_fail(struct bna_ethport *ethport)
  648. {
  649. /* Reset the physical port status to enabled */
  650. ethport->flags |= BNA_ETHPORT_F_PORT_ENABLED;
  651. if (ethport->link_status != BNA_LINK_DOWN) {
  652. ethport->link_status = BNA_LINK_DOWN;
  653. ethport->link_cbfn(ethport->bna->bnad, BNA_LINK_DOWN);
  654. }
  655. bfa_fsm_send_event(ethport, ETHPORT_E_FAIL);
  656. }
  657. /* Should be called only when ethport is disabled */
  658. void
  659. bna_ethport_cb_rx_started(struct bna_ethport *ethport)
  660. {
  661. ethport->rx_started_count++;
  662. if (ethport->rx_started_count == 1) {
  663. ethport->flags |= BNA_ETHPORT_F_RX_STARTED;
  664. if (ethport_can_be_up(ethport))
  665. bfa_fsm_send_event(ethport, ETHPORT_E_UP);
  666. }
  667. }
  668. void
  669. bna_ethport_cb_rx_stopped(struct bna_ethport *ethport)
  670. {
  671. int ethport_up = ethport_is_up(ethport);
  672. ethport->rx_started_count--;
  673. if (ethport->rx_started_count == 0) {
  674. ethport->flags &= ~BNA_ETHPORT_F_RX_STARTED;
  675. if (ethport_up)
  676. bfa_fsm_send_event(ethport, ETHPORT_E_DOWN);
  677. }
  678. }
  679. /**
  680. * ENET
  681. */
  682. #define bna_enet_chld_start(enet) \
  683. do { \
  684. enum bna_tx_type tx_type = \
  685. ((enet)->type == BNA_ENET_T_REGULAR) ? \
  686. BNA_TX_T_REGULAR : BNA_TX_T_LOOPBACK; \
  687. enum bna_rx_type rx_type = \
  688. ((enet)->type == BNA_ENET_T_REGULAR) ? \
  689. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
  690. bna_ethport_start(&(enet)->bna->ethport); \
  691. bna_tx_mod_start(&(enet)->bna->tx_mod, tx_type); \
  692. bna_rx_mod_start(&(enet)->bna->rx_mod, rx_type); \
  693. } while (0)
  694. #define bna_enet_chld_stop(enet) \
  695. do { \
  696. enum bna_tx_type tx_type = \
  697. ((enet)->type == BNA_ENET_T_REGULAR) ? \
  698. BNA_TX_T_REGULAR : BNA_TX_T_LOOPBACK; \
  699. enum bna_rx_type rx_type = \
  700. ((enet)->type == BNA_ENET_T_REGULAR) ? \
  701. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
  702. bfa_wc_init(&(enet)->chld_stop_wc, bna_enet_cb_chld_stopped, (enet));\
  703. bfa_wc_up(&(enet)->chld_stop_wc); \
  704. bna_ethport_stop(&(enet)->bna->ethport); \
  705. bfa_wc_up(&(enet)->chld_stop_wc); \
  706. bna_tx_mod_stop(&(enet)->bna->tx_mod, tx_type); \
  707. bfa_wc_up(&(enet)->chld_stop_wc); \
  708. bna_rx_mod_stop(&(enet)->bna->rx_mod, rx_type); \
  709. bfa_wc_wait(&(enet)->chld_stop_wc); \
  710. } while (0)
  711. #define bna_enet_chld_fail(enet) \
  712. do { \
  713. bna_ethport_fail(&(enet)->bna->ethport); \
  714. bna_tx_mod_fail(&(enet)->bna->tx_mod); \
  715. bna_rx_mod_fail(&(enet)->bna->rx_mod); \
  716. } while (0)
  717. #define bna_enet_rx_start(enet) \
  718. do { \
  719. enum bna_rx_type rx_type = \
  720. ((enet)->type == BNA_ENET_T_REGULAR) ? \
  721. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
  722. bna_rx_mod_start(&(enet)->bna->rx_mod, rx_type); \
  723. } while (0)
  724. #define bna_enet_rx_stop(enet) \
  725. do { \
  726. enum bna_rx_type rx_type = \
  727. ((enet)->type == BNA_ENET_T_REGULAR) ? \
  728. BNA_RX_T_REGULAR : BNA_RX_T_LOOPBACK; \
  729. bfa_wc_init(&(enet)->chld_stop_wc, bna_enet_cb_chld_stopped, (enet));\
  730. bfa_wc_up(&(enet)->chld_stop_wc); \
  731. bna_rx_mod_stop(&(enet)->bna->rx_mod, rx_type); \
  732. bfa_wc_wait(&(enet)->chld_stop_wc); \
  733. } while (0)
  734. #define call_enet_stop_cbfn(enet) \
  735. do { \
  736. if ((enet)->stop_cbfn) { \
  737. void (*cbfn)(void *); \
  738. void *cbarg; \
  739. cbfn = (enet)->stop_cbfn; \
  740. cbarg = (enet)->stop_cbarg; \
  741. (enet)->stop_cbfn = NULL; \
  742. (enet)->stop_cbarg = NULL; \
  743. cbfn(cbarg); \
  744. } \
  745. } while (0)
  746. #define call_enet_pause_cbfn(enet) \
  747. do { \
  748. if ((enet)->pause_cbfn) { \
  749. void (*cbfn)(struct bnad *); \
  750. cbfn = (enet)->pause_cbfn; \
  751. (enet)->pause_cbfn = NULL; \
  752. cbfn((enet)->bna->bnad); \
  753. } \
  754. } while (0)
  755. #define call_enet_mtu_cbfn(enet) \
  756. do { \
  757. if ((enet)->mtu_cbfn) { \
  758. void (*cbfn)(struct bnad *); \
  759. cbfn = (enet)->mtu_cbfn; \
  760. (enet)->mtu_cbfn = NULL; \
  761. cbfn((enet)->bna->bnad); \
  762. } \
  763. } while (0)
  764. static void bna_enet_cb_chld_stopped(void *arg);
  765. static void bna_bfi_pause_set(struct bna_enet *enet);
  766. bfa_fsm_state_decl(bna_enet, stopped, struct bna_enet,
  767. enum bna_enet_event);
  768. bfa_fsm_state_decl(bna_enet, pause_init_wait, struct bna_enet,
  769. enum bna_enet_event);
  770. bfa_fsm_state_decl(bna_enet, last_resp_wait, struct bna_enet,
  771. enum bna_enet_event);
  772. bfa_fsm_state_decl(bna_enet, started, struct bna_enet,
  773. enum bna_enet_event);
  774. bfa_fsm_state_decl(bna_enet, cfg_wait, struct bna_enet,
  775. enum bna_enet_event);
  776. bfa_fsm_state_decl(bna_enet, cfg_stop_wait, struct bna_enet,
  777. enum bna_enet_event);
  778. bfa_fsm_state_decl(bna_enet, chld_stop_wait, struct bna_enet,
  779. enum bna_enet_event);
  780. static void
  781. bna_enet_sm_stopped_entry(struct bna_enet *enet)
  782. {
  783. call_enet_pause_cbfn(enet);
  784. call_enet_mtu_cbfn(enet);
  785. call_enet_stop_cbfn(enet);
  786. }
  787. static void
  788. bna_enet_sm_stopped(struct bna_enet *enet, enum bna_enet_event event)
  789. {
  790. switch (event) {
  791. case ENET_E_START:
  792. bfa_fsm_set_state(enet, bna_enet_sm_pause_init_wait);
  793. break;
  794. case ENET_E_STOP:
  795. call_enet_stop_cbfn(enet);
  796. break;
  797. case ENET_E_FAIL:
  798. /* No-op */
  799. break;
  800. case ENET_E_PAUSE_CFG:
  801. call_enet_pause_cbfn(enet);
  802. break;
  803. case ENET_E_MTU_CFG:
  804. call_enet_mtu_cbfn(enet);
  805. break;
  806. case ENET_E_CHLD_STOPPED:
  807. /**
  808. * This event is received due to Ethport, Tx and Rx objects
  809. * failing
  810. */
  811. /* No-op */
  812. break;
  813. default:
  814. bfa_sm_fault(event);
  815. }
  816. }
  817. static void
  818. bna_enet_sm_pause_init_wait_entry(struct bna_enet *enet)
  819. {
  820. bna_bfi_pause_set(enet);
  821. }
  822. static void
  823. bna_enet_sm_pause_init_wait(struct bna_enet *enet,
  824. enum bna_enet_event event)
  825. {
  826. switch (event) {
  827. case ENET_E_STOP:
  828. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  829. bfa_fsm_set_state(enet, bna_enet_sm_last_resp_wait);
  830. break;
  831. case ENET_E_FAIL:
  832. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  833. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  834. break;
  835. case ENET_E_PAUSE_CFG:
  836. enet->flags |= BNA_ENET_F_PAUSE_CHANGED;
  837. break;
  838. case ENET_E_MTU_CFG:
  839. /* No-op */
  840. break;
  841. case ENET_E_FWRESP_PAUSE:
  842. if (enet->flags & BNA_ENET_F_PAUSE_CHANGED) {
  843. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  844. bna_bfi_pause_set(enet);
  845. } else {
  846. bfa_fsm_set_state(enet, bna_enet_sm_started);
  847. bna_enet_chld_start(enet);
  848. }
  849. break;
  850. default:
  851. bfa_sm_fault(event);
  852. }
  853. }
  854. static void
  855. bna_enet_sm_last_resp_wait_entry(struct bna_enet *enet)
  856. {
  857. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  858. }
  859. static void
  860. bna_enet_sm_last_resp_wait(struct bna_enet *enet,
  861. enum bna_enet_event event)
  862. {
  863. switch (event) {
  864. case ENET_E_FAIL:
  865. case ENET_E_FWRESP_PAUSE:
  866. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  867. break;
  868. default:
  869. bfa_sm_fault(event);
  870. }
  871. }
  872. static void
  873. bna_enet_sm_started_entry(struct bna_enet *enet)
  874. {
  875. /**
  876. * NOTE: Do not call bna_enet_chld_start() here, since it will be
  877. * inadvertently called during cfg_wait->started transition as well
  878. */
  879. call_enet_pause_cbfn(enet);
  880. call_enet_mtu_cbfn(enet);
  881. }
  882. static void
  883. bna_enet_sm_started(struct bna_enet *enet,
  884. enum bna_enet_event event)
  885. {
  886. switch (event) {
  887. case ENET_E_STOP:
  888. bfa_fsm_set_state(enet, bna_enet_sm_chld_stop_wait);
  889. break;
  890. case ENET_E_FAIL:
  891. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  892. bna_enet_chld_fail(enet);
  893. break;
  894. case ENET_E_PAUSE_CFG:
  895. bfa_fsm_set_state(enet, bna_enet_sm_cfg_wait);
  896. bna_bfi_pause_set(enet);
  897. break;
  898. case ENET_E_MTU_CFG:
  899. bfa_fsm_set_state(enet, bna_enet_sm_cfg_wait);
  900. bna_enet_rx_stop(enet);
  901. break;
  902. default:
  903. bfa_sm_fault(event);
  904. }
  905. }
  906. static void
  907. bna_enet_sm_cfg_wait_entry(struct bna_enet *enet)
  908. {
  909. }
  910. static void
  911. bna_enet_sm_cfg_wait(struct bna_enet *enet,
  912. enum bna_enet_event event)
  913. {
  914. switch (event) {
  915. case ENET_E_STOP:
  916. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  917. enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
  918. bfa_fsm_set_state(enet, bna_enet_sm_cfg_stop_wait);
  919. break;
  920. case ENET_E_FAIL:
  921. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  922. enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
  923. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  924. bna_enet_chld_fail(enet);
  925. break;
  926. case ENET_E_PAUSE_CFG:
  927. enet->flags |= BNA_ENET_F_PAUSE_CHANGED;
  928. break;
  929. case ENET_E_MTU_CFG:
  930. enet->flags |= BNA_ENET_F_MTU_CHANGED;
  931. break;
  932. case ENET_E_CHLD_STOPPED:
  933. bna_enet_rx_start(enet);
  934. /* Fall through */
  935. case ENET_E_FWRESP_PAUSE:
  936. if (enet->flags & BNA_ENET_F_PAUSE_CHANGED) {
  937. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  938. bna_bfi_pause_set(enet);
  939. } else if (enet->flags & BNA_ENET_F_MTU_CHANGED) {
  940. enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
  941. bna_enet_rx_stop(enet);
  942. } else {
  943. bfa_fsm_set_state(enet, bna_enet_sm_started);
  944. }
  945. break;
  946. default:
  947. bfa_sm_fault(event);
  948. }
  949. }
  950. static void
  951. bna_enet_sm_cfg_stop_wait_entry(struct bna_enet *enet)
  952. {
  953. enet->flags &= ~BNA_ENET_F_PAUSE_CHANGED;
  954. enet->flags &= ~BNA_ENET_F_MTU_CHANGED;
  955. }
  956. static void
  957. bna_enet_sm_cfg_stop_wait(struct bna_enet *enet,
  958. enum bna_enet_event event)
  959. {
  960. switch (event) {
  961. case ENET_E_FAIL:
  962. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  963. bna_enet_chld_fail(enet);
  964. break;
  965. case ENET_E_FWRESP_PAUSE:
  966. case ENET_E_CHLD_STOPPED:
  967. bfa_fsm_set_state(enet, bna_enet_sm_chld_stop_wait);
  968. break;
  969. default:
  970. bfa_sm_fault(event);
  971. }
  972. }
  973. static void
  974. bna_enet_sm_chld_stop_wait_entry(struct bna_enet *enet)
  975. {
  976. bna_enet_chld_stop(enet);
  977. }
  978. static void
  979. bna_enet_sm_chld_stop_wait(struct bna_enet *enet,
  980. enum bna_enet_event event)
  981. {
  982. switch (event) {
  983. case ENET_E_FAIL:
  984. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  985. bna_enet_chld_fail(enet);
  986. break;
  987. case ENET_E_CHLD_STOPPED:
  988. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  989. break;
  990. default:
  991. bfa_sm_fault(event);
  992. }
  993. }
  994. static void
  995. bna_bfi_pause_set(struct bna_enet *enet)
  996. {
  997. struct bfi_enet_set_pause_req *pause_req = &enet->pause_req;
  998. bfi_msgq_mhdr_set(pause_req->mh, BFI_MC_ENET,
  999. BFI_ENET_H2I_SET_PAUSE_REQ, 0, 0);
  1000. pause_req->mh.num_entries = htons(
  1001. bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_set_pause_req)));
  1002. pause_req->tx_pause = enet->pause_config.tx_pause;
  1003. pause_req->rx_pause = enet->pause_config.rx_pause;
  1004. bfa_msgq_cmd_set(&enet->msgq_cmd, NULL, NULL,
  1005. sizeof(struct bfi_enet_set_pause_req), &pause_req->mh);
  1006. bfa_msgq_cmd_post(&enet->bna->msgq, &enet->msgq_cmd);
  1007. }
  1008. static void
  1009. bna_enet_cb_chld_stopped(void *arg)
  1010. {
  1011. struct bna_enet *enet = (struct bna_enet *)arg;
  1012. bfa_fsm_send_event(enet, ENET_E_CHLD_STOPPED);
  1013. }
  1014. static void
  1015. bna_enet_init(struct bna_enet *enet, struct bna *bna)
  1016. {
  1017. enet->bna = bna;
  1018. enet->flags = 0;
  1019. enet->mtu = 0;
  1020. enet->type = BNA_ENET_T_REGULAR;
  1021. enet->stop_cbfn = NULL;
  1022. enet->stop_cbarg = NULL;
  1023. enet->pause_cbfn = NULL;
  1024. enet->mtu_cbfn = NULL;
  1025. bfa_fsm_set_state(enet, bna_enet_sm_stopped);
  1026. }
  1027. static void
  1028. bna_enet_uninit(struct bna_enet *enet)
  1029. {
  1030. enet->flags = 0;
  1031. enet->bna = NULL;
  1032. }
  1033. static void
  1034. bna_enet_start(struct bna_enet *enet)
  1035. {
  1036. enet->flags |= BNA_ENET_F_IOCETH_READY;
  1037. if (enet->flags & BNA_ENET_F_ENABLED)
  1038. bfa_fsm_send_event(enet, ENET_E_START);
  1039. }
  1040. static void
  1041. bna_ioceth_cb_enet_stopped(void *arg)
  1042. {
  1043. struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
  1044. bfa_fsm_send_event(ioceth, IOCETH_E_ENET_STOPPED);
  1045. }
  1046. static void
  1047. bna_enet_stop(struct bna_enet *enet)
  1048. {
  1049. enet->stop_cbfn = bna_ioceth_cb_enet_stopped;
  1050. enet->stop_cbarg = &enet->bna->ioceth;
  1051. enet->flags &= ~BNA_ENET_F_IOCETH_READY;
  1052. bfa_fsm_send_event(enet, ENET_E_STOP);
  1053. }
  1054. static void
  1055. bna_enet_fail(struct bna_enet *enet)
  1056. {
  1057. enet->flags &= ~BNA_ENET_F_IOCETH_READY;
  1058. bfa_fsm_send_event(enet, ENET_E_FAIL);
  1059. }
  1060. void
  1061. bna_enet_cb_tx_stopped(struct bna_enet *enet)
  1062. {
  1063. bfa_wc_down(&enet->chld_stop_wc);
  1064. }
  1065. void
  1066. bna_enet_cb_rx_stopped(struct bna_enet *enet)
  1067. {
  1068. bfa_wc_down(&enet->chld_stop_wc);
  1069. }
  1070. int
  1071. bna_enet_mtu_get(struct bna_enet *enet)
  1072. {
  1073. return enet->mtu;
  1074. }
  1075. void
  1076. bna_enet_enable(struct bna_enet *enet)
  1077. {
  1078. if (enet->fsm != (bfa_sm_t)bna_enet_sm_stopped)
  1079. return;
  1080. enet->flags |= BNA_ENET_F_ENABLED;
  1081. if (enet->flags & BNA_ENET_F_IOCETH_READY)
  1082. bfa_fsm_send_event(enet, ENET_E_START);
  1083. }
  1084. void
  1085. bna_enet_disable(struct bna_enet *enet, enum bna_cleanup_type type,
  1086. void (*cbfn)(void *))
  1087. {
  1088. if (type == BNA_SOFT_CLEANUP) {
  1089. (*cbfn)(enet->bna->bnad);
  1090. return;
  1091. }
  1092. enet->stop_cbfn = cbfn;
  1093. enet->stop_cbarg = enet->bna->bnad;
  1094. enet->flags &= ~BNA_ENET_F_ENABLED;
  1095. bfa_fsm_send_event(enet, ENET_E_STOP);
  1096. }
  1097. void
  1098. bna_enet_pause_config(struct bna_enet *enet,
  1099. struct bna_pause_config *pause_config,
  1100. void (*cbfn)(struct bnad *))
  1101. {
  1102. enet->pause_config = *pause_config;
  1103. enet->pause_cbfn = cbfn;
  1104. bfa_fsm_send_event(enet, ENET_E_PAUSE_CFG);
  1105. }
  1106. void
  1107. bna_enet_mtu_set(struct bna_enet *enet, int mtu,
  1108. void (*cbfn)(struct bnad *))
  1109. {
  1110. enet->mtu = mtu;
  1111. enet->mtu_cbfn = cbfn;
  1112. bfa_fsm_send_event(enet, ENET_E_MTU_CFG);
  1113. }
  1114. void
  1115. bna_enet_perm_mac_get(struct bna_enet *enet, mac_t *mac)
  1116. {
  1117. *mac = bfa_nw_ioc_get_mac(&enet->bna->ioceth.ioc);
  1118. }
  1119. /**
  1120. * IOCETH
  1121. */
  1122. #define enable_mbox_intr(_ioceth) \
  1123. do { \
  1124. u32 intr_status; \
  1125. bna_intr_status_get((_ioceth)->bna, intr_status); \
  1126. bnad_cb_mbox_intr_enable((_ioceth)->bna->bnad); \
  1127. bna_mbox_intr_enable((_ioceth)->bna); \
  1128. } while (0)
  1129. #define disable_mbox_intr(_ioceth) \
  1130. do { \
  1131. bna_mbox_intr_disable((_ioceth)->bna); \
  1132. bnad_cb_mbox_intr_disable((_ioceth)->bna->bnad); \
  1133. } while (0)
  1134. #define call_ioceth_stop_cbfn(_ioceth) \
  1135. do { \
  1136. if ((_ioceth)->stop_cbfn) { \
  1137. void (*cbfn)(struct bnad *); \
  1138. struct bnad *cbarg; \
  1139. cbfn = (_ioceth)->stop_cbfn; \
  1140. cbarg = (_ioceth)->stop_cbarg; \
  1141. (_ioceth)->stop_cbfn = NULL; \
  1142. (_ioceth)->stop_cbarg = NULL; \
  1143. cbfn(cbarg); \
  1144. } \
  1145. } while (0)
  1146. #define bna_stats_mod_uninit(_stats_mod) \
  1147. do { \
  1148. } while (0)
  1149. #define bna_stats_mod_start(_stats_mod) \
  1150. do { \
  1151. (_stats_mod)->ioc_ready = true; \
  1152. } while (0)
  1153. #define bna_stats_mod_stop(_stats_mod) \
  1154. do { \
  1155. (_stats_mod)->ioc_ready = false; \
  1156. } while (0)
  1157. #define bna_stats_mod_fail(_stats_mod) \
  1158. do { \
  1159. (_stats_mod)->ioc_ready = false; \
  1160. (_stats_mod)->stats_get_busy = false; \
  1161. (_stats_mod)->stats_clr_busy = false; \
  1162. } while (0)
  1163. static void bna_bfi_attr_get(struct bna_ioceth *ioceth);
  1164. bfa_fsm_state_decl(bna_ioceth, stopped, struct bna_ioceth,
  1165. enum bna_ioceth_event);
  1166. bfa_fsm_state_decl(bna_ioceth, ioc_ready_wait, struct bna_ioceth,
  1167. enum bna_ioceth_event);
  1168. bfa_fsm_state_decl(bna_ioceth, enet_attr_wait, struct bna_ioceth,
  1169. enum bna_ioceth_event);
  1170. bfa_fsm_state_decl(bna_ioceth, ready, struct bna_ioceth,
  1171. enum bna_ioceth_event);
  1172. bfa_fsm_state_decl(bna_ioceth, last_resp_wait, struct bna_ioceth,
  1173. enum bna_ioceth_event);
  1174. bfa_fsm_state_decl(bna_ioceth, enet_stop_wait, struct bna_ioceth,
  1175. enum bna_ioceth_event);
  1176. bfa_fsm_state_decl(bna_ioceth, ioc_disable_wait, struct bna_ioceth,
  1177. enum bna_ioceth_event);
  1178. bfa_fsm_state_decl(bna_ioceth, failed, struct bna_ioceth,
  1179. enum bna_ioceth_event);
  1180. static void
  1181. bna_ioceth_sm_stopped_entry(struct bna_ioceth *ioceth)
  1182. {
  1183. call_ioceth_stop_cbfn(ioceth);
  1184. }
  1185. static void
  1186. bna_ioceth_sm_stopped(struct bna_ioceth *ioceth,
  1187. enum bna_ioceth_event event)
  1188. {
  1189. switch (event) {
  1190. case IOCETH_E_ENABLE:
  1191. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_ready_wait);
  1192. bfa_nw_ioc_enable(&ioceth->ioc);
  1193. break;
  1194. case IOCETH_E_DISABLE:
  1195. bfa_fsm_set_state(ioceth, bna_ioceth_sm_stopped);
  1196. break;
  1197. case IOCETH_E_IOC_RESET:
  1198. enable_mbox_intr(ioceth);
  1199. break;
  1200. case IOCETH_E_IOC_FAILED:
  1201. disable_mbox_intr(ioceth);
  1202. bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
  1203. break;
  1204. default:
  1205. bfa_sm_fault(event);
  1206. }
  1207. }
  1208. static void
  1209. bna_ioceth_sm_ioc_ready_wait_entry(struct bna_ioceth *ioceth)
  1210. {
  1211. /**
  1212. * Do not call bfa_nw_ioc_enable() here. It must be called in the
  1213. * previous state due to failed -> ioc_ready_wait transition.
  1214. */
  1215. }
  1216. static void
  1217. bna_ioceth_sm_ioc_ready_wait(struct bna_ioceth *ioceth,
  1218. enum bna_ioceth_event event)
  1219. {
  1220. switch (event) {
  1221. case IOCETH_E_DISABLE:
  1222. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
  1223. bfa_nw_ioc_disable(&ioceth->ioc);
  1224. break;
  1225. case IOCETH_E_IOC_RESET:
  1226. enable_mbox_intr(ioceth);
  1227. break;
  1228. case IOCETH_E_IOC_FAILED:
  1229. disable_mbox_intr(ioceth);
  1230. bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
  1231. break;
  1232. case IOCETH_E_IOC_READY:
  1233. bfa_fsm_set_state(ioceth, bna_ioceth_sm_enet_attr_wait);
  1234. break;
  1235. default:
  1236. bfa_sm_fault(event);
  1237. }
  1238. }
  1239. static void
  1240. bna_ioceth_sm_enet_attr_wait_entry(struct bna_ioceth *ioceth)
  1241. {
  1242. bna_bfi_attr_get(ioceth);
  1243. }
  1244. static void
  1245. bna_ioceth_sm_enet_attr_wait(struct bna_ioceth *ioceth,
  1246. enum bna_ioceth_event event)
  1247. {
  1248. switch (event) {
  1249. case IOCETH_E_DISABLE:
  1250. bfa_fsm_set_state(ioceth, bna_ioceth_sm_last_resp_wait);
  1251. break;
  1252. case IOCETH_E_IOC_FAILED:
  1253. disable_mbox_intr(ioceth);
  1254. bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
  1255. break;
  1256. case IOCETH_E_ENET_ATTR_RESP:
  1257. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ready);
  1258. break;
  1259. default:
  1260. bfa_sm_fault(event);
  1261. }
  1262. }
  1263. static void
  1264. bna_ioceth_sm_ready_entry(struct bna_ioceth *ioceth)
  1265. {
  1266. bna_enet_start(&ioceth->bna->enet);
  1267. bna_stats_mod_start(&ioceth->bna->stats_mod);
  1268. bnad_cb_ioceth_ready(ioceth->bna->bnad);
  1269. }
  1270. static void
  1271. bna_ioceth_sm_ready(struct bna_ioceth *ioceth, enum bna_ioceth_event event)
  1272. {
  1273. switch (event) {
  1274. case IOCETH_E_DISABLE:
  1275. bfa_fsm_set_state(ioceth, bna_ioceth_sm_enet_stop_wait);
  1276. break;
  1277. case IOCETH_E_IOC_FAILED:
  1278. disable_mbox_intr(ioceth);
  1279. bna_enet_fail(&ioceth->bna->enet);
  1280. bna_stats_mod_fail(&ioceth->bna->stats_mod);
  1281. bfa_fsm_set_state(ioceth, bna_ioceth_sm_failed);
  1282. break;
  1283. default:
  1284. bfa_sm_fault(event);
  1285. }
  1286. }
  1287. static void
  1288. bna_ioceth_sm_last_resp_wait_entry(struct bna_ioceth *ioceth)
  1289. {
  1290. }
  1291. static void
  1292. bna_ioceth_sm_last_resp_wait(struct bna_ioceth *ioceth,
  1293. enum bna_ioceth_event event)
  1294. {
  1295. switch (event) {
  1296. case IOCETH_E_IOC_FAILED:
  1297. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
  1298. disable_mbox_intr(ioceth);
  1299. bfa_nw_ioc_disable(&ioceth->ioc);
  1300. break;
  1301. case IOCETH_E_ENET_ATTR_RESP:
  1302. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
  1303. bfa_nw_ioc_disable(&ioceth->ioc);
  1304. break;
  1305. default:
  1306. bfa_sm_fault(event);
  1307. }
  1308. }
  1309. static void
  1310. bna_ioceth_sm_enet_stop_wait_entry(struct bna_ioceth *ioceth)
  1311. {
  1312. bna_stats_mod_stop(&ioceth->bna->stats_mod);
  1313. bna_enet_stop(&ioceth->bna->enet);
  1314. }
  1315. static void
  1316. bna_ioceth_sm_enet_stop_wait(struct bna_ioceth *ioceth,
  1317. enum bna_ioceth_event event)
  1318. {
  1319. switch (event) {
  1320. case IOCETH_E_IOC_FAILED:
  1321. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
  1322. disable_mbox_intr(ioceth);
  1323. bna_enet_fail(&ioceth->bna->enet);
  1324. bna_stats_mod_fail(&ioceth->bna->stats_mod);
  1325. bfa_nw_ioc_disable(&ioceth->ioc);
  1326. break;
  1327. case IOCETH_E_ENET_STOPPED:
  1328. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
  1329. bfa_nw_ioc_disable(&ioceth->ioc);
  1330. break;
  1331. default:
  1332. bfa_sm_fault(event);
  1333. }
  1334. }
  1335. static void
  1336. bna_ioceth_sm_ioc_disable_wait_entry(struct bna_ioceth *ioceth)
  1337. {
  1338. }
  1339. static void
  1340. bna_ioceth_sm_ioc_disable_wait(struct bna_ioceth *ioceth,
  1341. enum bna_ioceth_event event)
  1342. {
  1343. switch (event) {
  1344. case IOCETH_E_IOC_DISABLED:
  1345. disable_mbox_intr(ioceth);
  1346. bfa_fsm_set_state(ioceth, bna_ioceth_sm_stopped);
  1347. break;
  1348. case IOCETH_E_ENET_STOPPED:
  1349. /* This event is received due to enet failing */
  1350. /* No-op */
  1351. break;
  1352. default:
  1353. bfa_sm_fault(event);
  1354. }
  1355. }
  1356. static void
  1357. bna_ioceth_sm_failed_entry(struct bna_ioceth *ioceth)
  1358. {
  1359. bnad_cb_ioceth_failed(ioceth->bna->bnad);
  1360. }
  1361. static void
  1362. bna_ioceth_sm_failed(struct bna_ioceth *ioceth,
  1363. enum bna_ioceth_event event)
  1364. {
  1365. switch (event) {
  1366. case IOCETH_E_DISABLE:
  1367. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_disable_wait);
  1368. bfa_nw_ioc_disable(&ioceth->ioc);
  1369. break;
  1370. case IOCETH_E_IOC_RESET:
  1371. enable_mbox_intr(ioceth);
  1372. bfa_fsm_set_state(ioceth, bna_ioceth_sm_ioc_ready_wait);
  1373. break;
  1374. case IOCETH_E_IOC_FAILED:
  1375. break;
  1376. default:
  1377. bfa_sm_fault(event);
  1378. }
  1379. }
  1380. static void
  1381. bna_bfi_attr_get(struct bna_ioceth *ioceth)
  1382. {
  1383. struct bfi_enet_attr_req *attr_req = &ioceth->attr_req;
  1384. bfi_msgq_mhdr_set(attr_req->mh, BFI_MC_ENET,
  1385. BFI_ENET_H2I_GET_ATTR_REQ, 0, 0);
  1386. attr_req->mh.num_entries = htons(
  1387. bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_attr_req)));
  1388. bfa_msgq_cmd_set(&ioceth->msgq_cmd, NULL, NULL,
  1389. sizeof(struct bfi_enet_attr_req), &attr_req->mh);
  1390. bfa_msgq_cmd_post(&ioceth->bna->msgq, &ioceth->msgq_cmd);
  1391. }
  1392. /* IOC callback functions */
  1393. static void
  1394. bna_cb_ioceth_enable(void *arg, enum bfa_status error)
  1395. {
  1396. struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
  1397. if (error)
  1398. bfa_fsm_send_event(ioceth, IOCETH_E_IOC_FAILED);
  1399. else
  1400. bfa_fsm_send_event(ioceth, IOCETH_E_IOC_READY);
  1401. }
  1402. static void
  1403. bna_cb_ioceth_disable(void *arg)
  1404. {
  1405. struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
  1406. bfa_fsm_send_event(ioceth, IOCETH_E_IOC_DISABLED);
  1407. }
  1408. static void
  1409. bna_cb_ioceth_hbfail(void *arg)
  1410. {
  1411. struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
  1412. bfa_fsm_send_event(ioceth, IOCETH_E_IOC_FAILED);
  1413. }
  1414. static void
  1415. bna_cb_ioceth_reset(void *arg)
  1416. {
  1417. struct bna_ioceth *ioceth = (struct bna_ioceth *)arg;
  1418. bfa_fsm_send_event(ioceth, IOCETH_E_IOC_RESET);
  1419. }
  1420. static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
  1421. bna_cb_ioceth_enable,
  1422. bna_cb_ioceth_disable,
  1423. bna_cb_ioceth_hbfail,
  1424. bna_cb_ioceth_reset
  1425. };
  1426. static void bna_attr_init(struct bna_ioceth *ioceth)
  1427. {
  1428. ioceth->attr.num_txq = BFI_ENET_DEF_TXQ;
  1429. ioceth->attr.num_rxp = BFI_ENET_DEF_RXP;
  1430. ioceth->attr.num_ucmac = BFI_ENET_DEF_UCAM;
  1431. ioceth->attr.num_mcmac = BFI_ENET_MAX_MCAM;
  1432. ioceth->attr.max_rit_size = BFI_ENET_DEF_RITSZ;
  1433. ioceth->attr.fw_query_complete = false;
  1434. }
  1435. static void
  1436. bna_ioceth_init(struct bna_ioceth *ioceth, struct bna *bna,
  1437. struct bna_res_info *res_info)
  1438. {
  1439. u64 dma;
  1440. u8 *kva;
  1441. ioceth->bna = bna;
  1442. /**
  1443. * Attach IOC and claim:
  1444. * 1. DMA memory for IOC attributes
  1445. * 2. Kernel memory for FW trace
  1446. */
  1447. bfa_nw_ioc_attach(&ioceth->ioc, ioceth, &bna_ioceth_cbfn);
  1448. bfa_nw_ioc_pci_init(&ioceth->ioc, &bna->pcidev, BFI_PCIFN_CLASS_ETH);
  1449. BNA_GET_DMA_ADDR(
  1450. &res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mdl[0].dma, dma);
  1451. kva = res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mdl[0].kva;
  1452. bfa_nw_ioc_mem_claim(&ioceth->ioc, kva, dma);
  1453. kva = res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.mdl[0].kva;
  1454. bfa_nw_ioc_debug_memclaim(&ioceth->ioc, kva);
  1455. /**
  1456. * Attach common modules (Diag, SFP, CEE, Port) and claim respective
  1457. * DMA memory.
  1458. */
  1459. BNA_GET_DMA_ADDR(
  1460. &res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mdl[0].dma, dma);
  1461. kva = res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mdl[0].kva;
  1462. bfa_nw_cee_attach(&bna->cee, &ioceth->ioc, bna);
  1463. bfa_nw_cee_mem_claim(&bna->cee, kva, dma);
  1464. kva += bfa_nw_cee_meminfo();
  1465. dma += bfa_nw_cee_meminfo();
  1466. bfa_nw_flash_attach(&bna->flash, &ioceth->ioc, bna);
  1467. bfa_nw_flash_memclaim(&bna->flash, kva, dma);
  1468. kva += bfa_nw_flash_meminfo();
  1469. dma += bfa_nw_flash_meminfo();
  1470. bfa_msgq_attach(&bna->msgq, &ioceth->ioc);
  1471. bfa_msgq_memclaim(&bna->msgq, kva, dma);
  1472. bfa_msgq_regisr(&bna->msgq, BFI_MC_ENET, bna_msgq_rsp_handler, bna);
  1473. kva += bfa_msgq_meminfo();
  1474. dma += bfa_msgq_meminfo();
  1475. ioceth->stop_cbfn = NULL;
  1476. ioceth->stop_cbarg = NULL;
  1477. bna_attr_init(ioceth);
  1478. bfa_fsm_set_state(ioceth, bna_ioceth_sm_stopped);
  1479. }
  1480. static void
  1481. bna_ioceth_uninit(struct bna_ioceth *ioceth)
  1482. {
  1483. bfa_nw_ioc_detach(&ioceth->ioc);
  1484. ioceth->bna = NULL;
  1485. }
  1486. void
  1487. bna_ioceth_enable(struct bna_ioceth *ioceth)
  1488. {
  1489. if (ioceth->fsm == (bfa_fsm_t)bna_ioceth_sm_ready) {
  1490. bnad_cb_ioceth_ready(ioceth->bna->bnad);
  1491. return;
  1492. }
  1493. if (ioceth->fsm == (bfa_fsm_t)bna_ioceth_sm_stopped)
  1494. bfa_fsm_send_event(ioceth, IOCETH_E_ENABLE);
  1495. }
  1496. void
  1497. bna_ioceth_disable(struct bna_ioceth *ioceth, enum bna_cleanup_type type)
  1498. {
  1499. if (type == BNA_SOFT_CLEANUP) {
  1500. bnad_cb_ioceth_disabled(ioceth->bna->bnad);
  1501. return;
  1502. }
  1503. ioceth->stop_cbfn = bnad_cb_ioceth_disabled;
  1504. ioceth->stop_cbarg = ioceth->bna->bnad;
  1505. bfa_fsm_send_event(ioceth, IOCETH_E_DISABLE);
  1506. }
  1507. static void
  1508. bna_ucam_mod_init(struct bna_ucam_mod *ucam_mod, struct bna *bna,
  1509. struct bna_res_info *res_info)
  1510. {
  1511. int i;
  1512. ucam_mod->ucmac = (struct bna_mac *)
  1513. res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.mdl[0].kva;
  1514. INIT_LIST_HEAD(&ucam_mod->free_q);
  1515. for (i = 0; i < bna->ioceth.attr.num_ucmac; i++) {
  1516. bfa_q_qe_init(&ucam_mod->ucmac[i].qe);
  1517. list_add_tail(&ucam_mod->ucmac[i].qe, &ucam_mod->free_q);
  1518. }
  1519. ucam_mod->bna = bna;
  1520. }
  1521. static void
  1522. bna_ucam_mod_uninit(struct bna_ucam_mod *ucam_mod)
  1523. {
  1524. struct list_head *qe;
  1525. int i = 0;
  1526. list_for_each(qe, &ucam_mod->free_q)
  1527. i++;
  1528. ucam_mod->bna = NULL;
  1529. }
  1530. static void
  1531. bna_mcam_mod_init(struct bna_mcam_mod *mcam_mod, struct bna *bna,
  1532. struct bna_res_info *res_info)
  1533. {
  1534. int i;
  1535. mcam_mod->mcmac = (struct bna_mac *)
  1536. res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.mdl[0].kva;
  1537. INIT_LIST_HEAD(&mcam_mod->free_q);
  1538. for (i = 0; i < bna->ioceth.attr.num_mcmac; i++) {
  1539. bfa_q_qe_init(&mcam_mod->mcmac[i].qe);
  1540. list_add_tail(&mcam_mod->mcmac[i].qe, &mcam_mod->free_q);
  1541. }
  1542. mcam_mod->mchandle = (struct bna_mcam_handle *)
  1543. res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.mdl[0].kva;
  1544. INIT_LIST_HEAD(&mcam_mod->free_handle_q);
  1545. for (i = 0; i < bna->ioceth.attr.num_mcmac; i++) {
  1546. bfa_q_qe_init(&mcam_mod->mchandle[i].qe);
  1547. list_add_tail(&mcam_mod->mchandle[i].qe,
  1548. &mcam_mod->free_handle_q);
  1549. }
  1550. mcam_mod->bna = bna;
  1551. }
  1552. static void
  1553. bna_mcam_mod_uninit(struct bna_mcam_mod *mcam_mod)
  1554. {
  1555. struct list_head *qe;
  1556. int i;
  1557. i = 0;
  1558. list_for_each(qe, &mcam_mod->free_q) i++;
  1559. i = 0;
  1560. list_for_each(qe, &mcam_mod->free_handle_q) i++;
  1561. mcam_mod->bna = NULL;
  1562. }
  1563. static void
  1564. bna_bfi_stats_get(struct bna *bna)
  1565. {
  1566. struct bfi_enet_stats_req *stats_req = &bna->stats_mod.stats_get;
  1567. bna->stats_mod.stats_get_busy = true;
  1568. bfi_msgq_mhdr_set(stats_req->mh, BFI_MC_ENET,
  1569. BFI_ENET_H2I_STATS_GET_REQ, 0, 0);
  1570. stats_req->mh.num_entries = htons(
  1571. bfi_msgq_num_cmd_entries(sizeof(struct bfi_enet_stats_req)));
  1572. stats_req->stats_mask = htons(BFI_ENET_STATS_ALL);
  1573. stats_req->tx_enet_mask = htonl(bna->tx_mod.rid_mask);
  1574. stats_req->rx_enet_mask = htonl(bna->rx_mod.rid_mask);
  1575. stats_req->host_buffer.a32.addr_hi = bna->stats.hw_stats_dma.msb;
  1576. stats_req->host_buffer.a32.addr_lo = bna->stats.hw_stats_dma.lsb;
  1577. bfa_msgq_cmd_set(&bna->stats_mod.stats_get_cmd, NULL, NULL,
  1578. sizeof(struct bfi_enet_stats_req), &stats_req->mh);
  1579. bfa_msgq_cmd_post(&bna->msgq, &bna->stats_mod.stats_get_cmd);
  1580. }
  1581. void
  1582. bna_res_req(struct bna_res_info *res_info)
  1583. {
  1584. /* DMA memory for COMMON_MODULE */
  1585. res_info[BNA_RES_MEM_T_COM].res_type = BNA_RES_T_MEM;
  1586. res_info[BNA_RES_MEM_T_COM].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
  1587. res_info[BNA_RES_MEM_T_COM].res_u.mem_info.num = 1;
  1588. res_info[BNA_RES_MEM_T_COM].res_u.mem_info.len = ALIGN(
  1589. (bfa_nw_cee_meminfo() +
  1590. bfa_nw_flash_meminfo() +
  1591. bfa_msgq_meminfo()), PAGE_SIZE);
  1592. /* DMA memory for retrieving IOC attributes */
  1593. res_info[BNA_RES_MEM_T_ATTR].res_type = BNA_RES_T_MEM;
  1594. res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
  1595. res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.num = 1;
  1596. res_info[BNA_RES_MEM_T_ATTR].res_u.mem_info.len =
  1597. ALIGN(bfa_nw_ioc_meminfo(), PAGE_SIZE);
  1598. /* Virtual memory for retreiving fw_trc */
  1599. res_info[BNA_RES_MEM_T_FWTRC].res_type = BNA_RES_T_MEM;
  1600. res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.mem_type = BNA_MEM_T_KVA;
  1601. res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.num = 1;
  1602. res_info[BNA_RES_MEM_T_FWTRC].res_u.mem_info.len = BNA_DBG_FWTRC_LEN;
  1603. /* DMA memory for retreiving stats */
  1604. res_info[BNA_RES_MEM_T_STATS].res_type = BNA_RES_T_MEM;
  1605. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mem_type = BNA_MEM_T_DMA;
  1606. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.num = 1;
  1607. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.len =
  1608. ALIGN(sizeof(struct bfi_enet_stats),
  1609. PAGE_SIZE);
  1610. }
  1611. void
  1612. bna_mod_res_req(struct bna *bna, struct bna_res_info *res_info)
  1613. {
  1614. struct bna_attr *attr = &bna->ioceth.attr;
  1615. /* Virtual memory for Tx objects - stored by Tx module */
  1616. res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_type = BNA_RES_T_MEM;
  1617. res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_u.mem_info.mem_type =
  1618. BNA_MEM_T_KVA;
  1619. res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_u.mem_info.num = 1;
  1620. res_info[BNA_MOD_RES_MEM_T_TX_ARRAY].res_u.mem_info.len =
  1621. attr->num_txq * sizeof(struct bna_tx);
  1622. /* Virtual memory for TxQ - stored by Tx module */
  1623. res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_type = BNA_RES_T_MEM;
  1624. res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.mem_type =
  1625. BNA_MEM_T_KVA;
  1626. res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.num = 1;
  1627. res_info[BNA_MOD_RES_MEM_T_TXQ_ARRAY].res_u.mem_info.len =
  1628. attr->num_txq * sizeof(struct bna_txq);
  1629. /* Virtual memory for Rx objects - stored by Rx module */
  1630. res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_type = BNA_RES_T_MEM;
  1631. res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_u.mem_info.mem_type =
  1632. BNA_MEM_T_KVA;
  1633. res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_u.mem_info.num = 1;
  1634. res_info[BNA_MOD_RES_MEM_T_RX_ARRAY].res_u.mem_info.len =
  1635. attr->num_rxp * sizeof(struct bna_rx);
  1636. /* Virtual memory for RxPath - stored by Rx module */
  1637. res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_type = BNA_RES_T_MEM;
  1638. res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_u.mem_info.mem_type =
  1639. BNA_MEM_T_KVA;
  1640. res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_u.mem_info.num = 1;
  1641. res_info[BNA_MOD_RES_MEM_T_RXP_ARRAY].res_u.mem_info.len =
  1642. attr->num_rxp * sizeof(struct bna_rxp);
  1643. /* Virtual memory for RxQ - stored by Rx module */
  1644. res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_type = BNA_RES_T_MEM;
  1645. res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.mem_type =
  1646. BNA_MEM_T_KVA;
  1647. res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.num = 1;
  1648. res_info[BNA_MOD_RES_MEM_T_RXQ_ARRAY].res_u.mem_info.len =
  1649. (attr->num_rxp * 2) * sizeof(struct bna_rxq);
  1650. /* Virtual memory for Unicast MAC address - stored by ucam module */
  1651. res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_type = BNA_RES_T_MEM;
  1652. res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.mem_type =
  1653. BNA_MEM_T_KVA;
  1654. res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.num = 1;
  1655. res_info[BNA_MOD_RES_MEM_T_UCMAC_ARRAY].res_u.mem_info.len =
  1656. attr->num_ucmac * sizeof(struct bna_mac);
  1657. /* Virtual memory for Multicast MAC address - stored by mcam module */
  1658. res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_type = BNA_RES_T_MEM;
  1659. res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.mem_type =
  1660. BNA_MEM_T_KVA;
  1661. res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.num = 1;
  1662. res_info[BNA_MOD_RES_MEM_T_MCMAC_ARRAY].res_u.mem_info.len =
  1663. attr->num_mcmac * sizeof(struct bna_mac);
  1664. /* Virtual memory for Multicast handle - stored by mcam module */
  1665. res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_type = BNA_RES_T_MEM;
  1666. res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.mem_type =
  1667. BNA_MEM_T_KVA;
  1668. res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.num = 1;
  1669. res_info[BNA_MOD_RES_MEM_T_MCHANDLE_ARRAY].res_u.mem_info.len =
  1670. attr->num_mcmac * sizeof(struct bna_mcam_handle);
  1671. }
  1672. void
  1673. bna_init(struct bna *bna, struct bnad *bnad,
  1674. struct bfa_pcidev *pcidev, struct bna_res_info *res_info)
  1675. {
  1676. bna->bnad = bnad;
  1677. bna->pcidev = *pcidev;
  1678. bna->stats.hw_stats_kva = (struct bfi_enet_stats *)
  1679. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].kva;
  1680. bna->stats.hw_stats_dma.msb =
  1681. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].dma.msb;
  1682. bna->stats.hw_stats_dma.lsb =
  1683. res_info[BNA_RES_MEM_T_STATS].res_u.mem_info.mdl[0].dma.lsb;
  1684. bna_reg_addr_init(bna, &bna->pcidev);
  1685. /* Also initializes diag, cee, sfp, phy_port, msgq */
  1686. bna_ioceth_init(&bna->ioceth, bna, res_info);
  1687. bna_enet_init(&bna->enet, bna);
  1688. bna_ethport_init(&bna->ethport, bna);
  1689. }
  1690. void
  1691. bna_mod_init(struct bna *bna, struct bna_res_info *res_info)
  1692. {
  1693. bna_tx_mod_init(&bna->tx_mod, bna, res_info);
  1694. bna_rx_mod_init(&bna->rx_mod, bna, res_info);
  1695. bna_ucam_mod_init(&bna->ucam_mod, bna, res_info);
  1696. bna_mcam_mod_init(&bna->mcam_mod, bna, res_info);
  1697. bna->default_mode_rid = BFI_INVALID_RID;
  1698. bna->promisc_rid = BFI_INVALID_RID;
  1699. bna->mod_flags |= BNA_MOD_F_INIT_DONE;
  1700. }
  1701. void
  1702. bna_uninit(struct bna *bna)
  1703. {
  1704. if (bna->mod_flags & BNA_MOD_F_INIT_DONE) {
  1705. bna_mcam_mod_uninit(&bna->mcam_mod);
  1706. bna_ucam_mod_uninit(&bna->ucam_mod);
  1707. bna_rx_mod_uninit(&bna->rx_mod);
  1708. bna_tx_mod_uninit(&bna->tx_mod);
  1709. bna->mod_flags &= ~BNA_MOD_F_INIT_DONE;
  1710. }
  1711. bna_stats_mod_uninit(&bna->stats_mod);
  1712. bna_ethport_uninit(&bna->ethport);
  1713. bna_enet_uninit(&bna->enet);
  1714. bna_ioceth_uninit(&bna->ioceth);
  1715. bna->bnad = NULL;
  1716. }
  1717. int
  1718. bna_num_txq_set(struct bna *bna, int num_txq)
  1719. {
  1720. if (bna->ioceth.attr.fw_query_complete &&
  1721. (num_txq <= bna->ioceth.attr.num_txq)) {
  1722. bna->ioceth.attr.num_txq = num_txq;
  1723. return BNA_CB_SUCCESS;
  1724. }
  1725. return BNA_CB_FAIL;
  1726. }
  1727. int
  1728. bna_num_rxp_set(struct bna *bna, int num_rxp)
  1729. {
  1730. if (bna->ioceth.attr.fw_query_complete &&
  1731. (num_rxp <= bna->ioceth.attr.num_rxp)) {
  1732. bna->ioceth.attr.num_rxp = num_rxp;
  1733. return BNA_CB_SUCCESS;
  1734. }
  1735. return BNA_CB_FAIL;
  1736. }
  1737. struct bna_mac *
  1738. bna_ucam_mod_mac_get(struct bna_ucam_mod *ucam_mod)
  1739. {
  1740. struct list_head *qe;
  1741. if (list_empty(&ucam_mod->free_q))
  1742. return NULL;
  1743. bfa_q_deq(&ucam_mod->free_q, &qe);
  1744. return (struct bna_mac *)qe;
  1745. }
  1746. void
  1747. bna_ucam_mod_mac_put(struct bna_ucam_mod *ucam_mod, struct bna_mac *mac)
  1748. {
  1749. list_add_tail(&mac->qe, &ucam_mod->free_q);
  1750. }
  1751. struct bna_mac *
  1752. bna_mcam_mod_mac_get(struct bna_mcam_mod *mcam_mod)
  1753. {
  1754. struct list_head *qe;
  1755. if (list_empty(&mcam_mod->free_q))
  1756. return NULL;
  1757. bfa_q_deq(&mcam_mod->free_q, &qe);
  1758. return (struct bna_mac *)qe;
  1759. }
  1760. void
  1761. bna_mcam_mod_mac_put(struct bna_mcam_mod *mcam_mod, struct bna_mac *mac)
  1762. {
  1763. list_add_tail(&mac->qe, &mcam_mod->free_q);
  1764. }
  1765. struct bna_mcam_handle *
  1766. bna_mcam_mod_handle_get(struct bna_mcam_mod *mcam_mod)
  1767. {
  1768. struct list_head *qe;
  1769. if (list_empty(&mcam_mod->free_handle_q))
  1770. return NULL;
  1771. bfa_q_deq(&mcam_mod->free_handle_q, &qe);
  1772. return (struct bna_mcam_handle *)qe;
  1773. }
  1774. void
  1775. bna_mcam_mod_handle_put(struct bna_mcam_mod *mcam_mod,
  1776. struct bna_mcam_handle *handle)
  1777. {
  1778. list_add_tail(&handle->qe, &mcam_mod->free_handle_q);
  1779. }
  1780. void
  1781. bna_hw_stats_get(struct bna *bna)
  1782. {
  1783. if (!bna->stats_mod.ioc_ready) {
  1784. bnad_cb_stats_get(bna->bnad, BNA_CB_FAIL, &bna->stats);
  1785. return;
  1786. }
  1787. if (bna->stats_mod.stats_get_busy) {
  1788. bnad_cb_stats_get(bna->bnad, BNA_CB_BUSY, &bna->stats);
  1789. return;
  1790. }
  1791. bna_bfi_stats_get(bna);
  1792. }