bnx2x_stats.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* bnx2x_stats.h: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2011 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #ifndef BNX2X_STATS_H
  18. #define BNX2X_STATS_H
  19. #include <linux/types.h>
  20. struct nig_stats {
  21. u32 brb_discard;
  22. u32 brb_packet;
  23. u32 brb_truncate;
  24. u32 flow_ctrl_discard;
  25. u32 flow_ctrl_octets;
  26. u32 flow_ctrl_packet;
  27. u32 mng_discard;
  28. u32 mng_octet_inp;
  29. u32 mng_octet_out;
  30. u32 mng_packet_inp;
  31. u32 mng_packet_out;
  32. u32 pbf_octets;
  33. u32 pbf_packet;
  34. u32 safc_inp;
  35. u32 egress_mac_pkt0_lo;
  36. u32 egress_mac_pkt0_hi;
  37. u32 egress_mac_pkt1_lo;
  38. u32 egress_mac_pkt1_hi;
  39. };
  40. enum bnx2x_stats_event {
  41. STATS_EVENT_PMF = 0,
  42. STATS_EVENT_LINK_UP,
  43. STATS_EVENT_UPDATE,
  44. STATS_EVENT_STOP,
  45. STATS_EVENT_MAX
  46. };
  47. enum bnx2x_stats_state {
  48. STATS_STATE_DISABLED = 0,
  49. STATS_STATE_ENABLED,
  50. STATS_STATE_MAX
  51. };
  52. struct bnx2x_eth_stats {
  53. u32 total_bytes_received_hi;
  54. u32 total_bytes_received_lo;
  55. u32 total_bytes_transmitted_hi;
  56. u32 total_bytes_transmitted_lo;
  57. u32 total_unicast_packets_received_hi;
  58. u32 total_unicast_packets_received_lo;
  59. u32 total_multicast_packets_received_hi;
  60. u32 total_multicast_packets_received_lo;
  61. u32 total_broadcast_packets_received_hi;
  62. u32 total_broadcast_packets_received_lo;
  63. u32 total_unicast_packets_transmitted_hi;
  64. u32 total_unicast_packets_transmitted_lo;
  65. u32 total_multicast_packets_transmitted_hi;
  66. u32 total_multicast_packets_transmitted_lo;
  67. u32 total_broadcast_packets_transmitted_hi;
  68. u32 total_broadcast_packets_transmitted_lo;
  69. u32 valid_bytes_received_hi;
  70. u32 valid_bytes_received_lo;
  71. u32 error_bytes_received_hi;
  72. u32 error_bytes_received_lo;
  73. u32 etherstatsoverrsizepkts_hi;
  74. u32 etherstatsoverrsizepkts_lo;
  75. u32 no_buff_discard_hi;
  76. u32 no_buff_discard_lo;
  77. u32 rx_stat_ifhcinbadoctets_hi;
  78. u32 rx_stat_ifhcinbadoctets_lo;
  79. u32 tx_stat_ifhcoutbadoctets_hi;
  80. u32 tx_stat_ifhcoutbadoctets_lo;
  81. u32 rx_stat_dot3statsfcserrors_hi;
  82. u32 rx_stat_dot3statsfcserrors_lo;
  83. u32 rx_stat_dot3statsalignmenterrors_hi;
  84. u32 rx_stat_dot3statsalignmenterrors_lo;
  85. u32 rx_stat_dot3statscarriersenseerrors_hi;
  86. u32 rx_stat_dot3statscarriersenseerrors_lo;
  87. u32 rx_stat_falsecarriererrors_hi;
  88. u32 rx_stat_falsecarriererrors_lo;
  89. u32 rx_stat_etherstatsundersizepkts_hi;
  90. u32 rx_stat_etherstatsundersizepkts_lo;
  91. u32 rx_stat_dot3statsframestoolong_hi;
  92. u32 rx_stat_dot3statsframestoolong_lo;
  93. u32 rx_stat_etherstatsfragments_hi;
  94. u32 rx_stat_etherstatsfragments_lo;
  95. u32 rx_stat_etherstatsjabbers_hi;
  96. u32 rx_stat_etherstatsjabbers_lo;
  97. u32 rx_stat_maccontrolframesreceived_hi;
  98. u32 rx_stat_maccontrolframesreceived_lo;
  99. u32 rx_stat_bmac_xpf_hi;
  100. u32 rx_stat_bmac_xpf_lo;
  101. u32 rx_stat_bmac_xcf_hi;
  102. u32 rx_stat_bmac_xcf_lo;
  103. u32 rx_stat_xoffstateentered_hi;
  104. u32 rx_stat_xoffstateentered_lo;
  105. u32 rx_stat_xonpauseframesreceived_hi;
  106. u32 rx_stat_xonpauseframesreceived_lo;
  107. u32 rx_stat_xoffpauseframesreceived_hi;
  108. u32 rx_stat_xoffpauseframesreceived_lo;
  109. u32 tx_stat_outxonsent_hi;
  110. u32 tx_stat_outxonsent_lo;
  111. u32 tx_stat_outxoffsent_hi;
  112. u32 tx_stat_outxoffsent_lo;
  113. u32 tx_stat_flowcontroldone_hi;
  114. u32 tx_stat_flowcontroldone_lo;
  115. u32 tx_stat_etherstatscollisions_hi;
  116. u32 tx_stat_etherstatscollisions_lo;
  117. u32 tx_stat_dot3statssinglecollisionframes_hi;
  118. u32 tx_stat_dot3statssinglecollisionframes_lo;
  119. u32 tx_stat_dot3statsmultiplecollisionframes_hi;
  120. u32 tx_stat_dot3statsmultiplecollisionframes_lo;
  121. u32 tx_stat_dot3statsdeferredtransmissions_hi;
  122. u32 tx_stat_dot3statsdeferredtransmissions_lo;
  123. u32 tx_stat_dot3statsexcessivecollisions_hi;
  124. u32 tx_stat_dot3statsexcessivecollisions_lo;
  125. u32 tx_stat_dot3statslatecollisions_hi;
  126. u32 tx_stat_dot3statslatecollisions_lo;
  127. u32 tx_stat_etherstatspkts64octets_hi;
  128. u32 tx_stat_etherstatspkts64octets_lo;
  129. u32 tx_stat_etherstatspkts65octetsto127octets_hi;
  130. u32 tx_stat_etherstatspkts65octetsto127octets_lo;
  131. u32 tx_stat_etherstatspkts128octetsto255octets_hi;
  132. u32 tx_stat_etherstatspkts128octetsto255octets_lo;
  133. u32 tx_stat_etherstatspkts256octetsto511octets_hi;
  134. u32 tx_stat_etherstatspkts256octetsto511octets_lo;
  135. u32 tx_stat_etherstatspkts512octetsto1023octets_hi;
  136. u32 tx_stat_etherstatspkts512octetsto1023octets_lo;
  137. u32 tx_stat_etherstatspkts1024octetsto1522octets_hi;
  138. u32 tx_stat_etherstatspkts1024octetsto1522octets_lo;
  139. u32 tx_stat_etherstatspktsover1522octets_hi;
  140. u32 tx_stat_etherstatspktsover1522octets_lo;
  141. u32 tx_stat_bmac_2047_hi;
  142. u32 tx_stat_bmac_2047_lo;
  143. u32 tx_stat_bmac_4095_hi;
  144. u32 tx_stat_bmac_4095_lo;
  145. u32 tx_stat_bmac_9216_hi;
  146. u32 tx_stat_bmac_9216_lo;
  147. u32 tx_stat_bmac_16383_hi;
  148. u32 tx_stat_bmac_16383_lo;
  149. u32 tx_stat_dot3statsinternalmactransmiterrors_hi;
  150. u32 tx_stat_dot3statsinternalmactransmiterrors_lo;
  151. u32 tx_stat_bmac_ufl_hi;
  152. u32 tx_stat_bmac_ufl_lo;
  153. u32 pause_frames_received_hi;
  154. u32 pause_frames_received_lo;
  155. u32 pause_frames_sent_hi;
  156. u32 pause_frames_sent_lo;
  157. u32 etherstatspkts1024octetsto1522octets_hi;
  158. u32 etherstatspkts1024octetsto1522octets_lo;
  159. u32 etherstatspktsover1522octets_hi;
  160. u32 etherstatspktsover1522octets_lo;
  161. u32 brb_drop_hi;
  162. u32 brb_drop_lo;
  163. u32 brb_truncate_hi;
  164. u32 brb_truncate_lo;
  165. u32 mac_filter_discard;
  166. u32 mf_tag_discard;
  167. u32 brb_truncate_discard;
  168. u32 mac_discard;
  169. u32 driver_xoff;
  170. u32 rx_err_discard_pkt;
  171. u32 rx_skb_alloc_failed;
  172. u32 hw_csum_err;
  173. u32 nig_timer_max;
  174. /* TPA */
  175. u32 total_tpa_aggregations_hi;
  176. u32 total_tpa_aggregations_lo;
  177. u32 total_tpa_aggregated_frames_hi;
  178. u32 total_tpa_aggregated_frames_lo;
  179. u32 total_tpa_bytes_hi;
  180. u32 total_tpa_bytes_lo;
  181. };
  182. struct bnx2x_eth_q_stats {
  183. u32 total_unicast_bytes_received_hi;
  184. u32 total_unicast_bytes_received_lo;
  185. u32 total_broadcast_bytes_received_hi;
  186. u32 total_broadcast_bytes_received_lo;
  187. u32 total_multicast_bytes_received_hi;
  188. u32 total_multicast_bytes_received_lo;
  189. u32 total_bytes_received_hi;
  190. u32 total_bytes_received_lo;
  191. u32 total_unicast_bytes_transmitted_hi;
  192. u32 total_unicast_bytes_transmitted_lo;
  193. u32 total_broadcast_bytes_transmitted_hi;
  194. u32 total_broadcast_bytes_transmitted_lo;
  195. u32 total_multicast_bytes_transmitted_hi;
  196. u32 total_multicast_bytes_transmitted_lo;
  197. u32 total_bytes_transmitted_hi;
  198. u32 total_bytes_transmitted_lo;
  199. u32 total_unicast_packets_received_hi;
  200. u32 total_unicast_packets_received_lo;
  201. u32 total_multicast_packets_received_hi;
  202. u32 total_multicast_packets_received_lo;
  203. u32 total_broadcast_packets_received_hi;
  204. u32 total_broadcast_packets_received_lo;
  205. u32 total_unicast_packets_transmitted_hi;
  206. u32 total_unicast_packets_transmitted_lo;
  207. u32 total_multicast_packets_transmitted_hi;
  208. u32 total_multicast_packets_transmitted_lo;
  209. u32 total_broadcast_packets_transmitted_hi;
  210. u32 total_broadcast_packets_transmitted_lo;
  211. u32 valid_bytes_received_hi;
  212. u32 valid_bytes_received_lo;
  213. u32 etherstatsoverrsizepkts_hi;
  214. u32 etherstatsoverrsizepkts_lo;
  215. u32 no_buff_discard_hi;
  216. u32 no_buff_discard_lo;
  217. u32 driver_xoff;
  218. u32 rx_err_discard_pkt;
  219. u32 rx_skb_alloc_failed;
  220. u32 hw_csum_err;
  221. u32 total_packets_received_checksum_discarded_hi;
  222. u32 total_packets_received_checksum_discarded_lo;
  223. u32 total_packets_received_ttl0_discarded_hi;
  224. u32 total_packets_received_ttl0_discarded_lo;
  225. u32 total_transmitted_dropped_packets_error_hi;
  226. u32 total_transmitted_dropped_packets_error_lo;
  227. /* TPA */
  228. u32 total_tpa_aggregations_hi;
  229. u32 total_tpa_aggregations_lo;
  230. u32 total_tpa_aggregated_frames_hi;
  231. u32 total_tpa_aggregated_frames_lo;
  232. u32 total_tpa_bytes_hi;
  233. u32 total_tpa_bytes_lo;
  234. };
  235. /****************************************************************************
  236. * Macros
  237. ****************************************************************************/
  238. /* sum[hi:lo] += add[hi:lo] */
  239. #define ADD_64(s_hi, a_hi, s_lo, a_lo) \
  240. do { \
  241. s_lo += a_lo; \
  242. s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
  243. } while (0)
  244. /* difference = minuend - subtrahend */
  245. #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
  246. do { \
  247. if (m_lo < s_lo) { \
  248. /* underflow */ \
  249. d_hi = m_hi - s_hi; \
  250. if (d_hi > 0) { \
  251. /* we can 'loan' 1 */ \
  252. d_hi--; \
  253. d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
  254. } else { \
  255. /* m_hi <= s_hi */ \
  256. d_hi = 0; \
  257. d_lo = 0; \
  258. } \
  259. } else { \
  260. /* m_lo >= s_lo */ \
  261. if (m_hi < s_hi) { \
  262. d_hi = 0; \
  263. d_lo = 0; \
  264. } else { \
  265. /* m_hi >= s_hi */ \
  266. d_hi = m_hi - s_hi; \
  267. d_lo = m_lo - s_lo; \
  268. } \
  269. } \
  270. } while (0)
  271. #define UPDATE_STAT64(s, t) \
  272. do { \
  273. DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
  274. diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
  275. pstats->mac_stx[0].t##_hi = new->s##_hi; \
  276. pstats->mac_stx[0].t##_lo = new->s##_lo; \
  277. ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
  278. pstats->mac_stx[1].t##_lo, diff.lo); \
  279. } while (0)
  280. #define UPDATE_STAT64_NIG(s, t) \
  281. do { \
  282. DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
  283. diff.lo, new->s##_lo, old->s##_lo); \
  284. ADD_64(estats->t##_hi, diff.hi, \
  285. estats->t##_lo, diff.lo); \
  286. } while (0)
  287. /* sum[hi:lo] += add */
  288. #define ADD_EXTEND_64(s_hi, s_lo, a) \
  289. do { \
  290. s_lo += a; \
  291. s_hi += (s_lo < a) ? 1 : 0; \
  292. } while (0)
  293. #define ADD_STAT64(diff, t) \
  294. do { \
  295. ADD_64(pstats->mac_stx[1].t##_hi, new->diff##_hi, \
  296. pstats->mac_stx[1].t##_lo, new->diff##_lo); \
  297. } while (0)
  298. #define UPDATE_EXTEND_STAT(s) \
  299. do { \
  300. ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
  301. pstats->mac_stx[1].s##_lo, \
  302. new->s); \
  303. } while (0)
  304. #define UPDATE_EXTEND_TSTAT(s, t) \
  305. do { \
  306. diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \
  307. old_tclient->s = tclient->s; \
  308. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  309. } while (0)
  310. #define UPDATE_EXTEND_USTAT(s, t) \
  311. do { \
  312. diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
  313. old_uclient->s = uclient->s; \
  314. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  315. } while (0)
  316. #define UPDATE_EXTEND_XSTAT(s, t) \
  317. do { \
  318. diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
  319. old_xclient->s = xclient->s; \
  320. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  321. } while (0)
  322. /* minuend -= subtrahend */
  323. #define SUB_64(m_hi, s_hi, m_lo, s_lo) \
  324. do { \
  325. DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
  326. } while (0)
  327. /* minuend[hi:lo] -= subtrahend */
  328. #define SUB_EXTEND_64(m_hi, m_lo, s) \
  329. do { \
  330. SUB_64(m_hi, 0, m_lo, s); \
  331. } while (0)
  332. #define SUB_EXTEND_USTAT(s, t) \
  333. do { \
  334. diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
  335. SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  336. } while (0)
  337. /* forward */
  338. struct bnx2x;
  339. void bnx2x_stats_init(struct bnx2x *bp);
  340. void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
  341. #endif /* BNX2X_STATS_H */