mmc_core.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*******************************************************************************
  2. DWMAC Management Counters
  3. Copyright (C) 2011 STMicroelectronics Ltd
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  17. *******************************************************************************/
  18. #include <linux/kernel.h>
  19. #include <linux/io.h>
  20. #include "mmc.h"
  21. /* MAC Management Counters register offset */
  22. #define MMC_CNTRL 0x00 /* MMC Control */
  23. #define MMC_RX_INTR 0x04 /* MMC RX Interrupt */
  24. #define MMC_TX_INTR 0x08 /* MMC TX Interrupt */
  25. #define MMC_RX_INTR_MASK 0x0c /* MMC Interrupt Mask */
  26. #define MMC_TX_INTR_MASK 0x10 /* MMC Interrupt Mask */
  27. #define MMC_DEFAULT_MASK 0xffffffff
  28. /* MMC TX counter registers */
  29. /* Note:
  30. * _GB register stands for good and bad frames
  31. * _G is for good only.
  32. */
  33. #define MMC_TX_OCTETCOUNT_GB 0x14
  34. #define MMC_TX_FRAMECOUNT_GB 0x18
  35. #define MMC_TX_BROADCASTFRAME_G 0x1c
  36. #define MMC_TX_MULTICASTFRAME_G 0x20
  37. #define MMC_TX_64_OCTETS_GB 0x24
  38. #define MMC_TX_65_TO_127_OCTETS_GB 0x28
  39. #define MMC_TX_128_TO_255_OCTETS_GB 0x2c
  40. #define MMC_TX_256_TO_511_OCTETS_GB 0x30
  41. #define MMC_TX_512_TO_1023_OCTETS_GB 0x34
  42. #define MMC_TX_1024_TO_MAX_OCTETS_GB 0x38
  43. #define MMC_TX_UNICAST_GB 0x3c
  44. #define MMC_TX_MULTICAST_GB 0x40
  45. #define MMC_TX_BROADCAST_GB 0x44
  46. #define MMC_TX_UNDERFLOW_ERROR 0x48
  47. #define MMC_TX_SINGLECOL_G 0x4c
  48. #define MMC_TX_MULTICOL_G 0x50
  49. #define MMC_TX_DEFERRED 0x54
  50. #define MMC_TX_LATECOL 0x58
  51. #define MMC_TX_EXESSCOL 0x5c
  52. #define MMC_TX_CARRIER_ERROR 0x60
  53. #define MMC_TX_OCTETCOUNT_G 0x64
  54. #define MMC_TX_FRAMECOUNT_G 0x68
  55. #define MMC_TX_EXCESSDEF 0x6c
  56. #define MMC_TX_PAUSE_FRAME 0x70
  57. #define MMC_TX_VLAN_FRAME_G 0x74
  58. /* MMC RX counter registers */
  59. #define MMC_RX_FRAMECOUNT_GB 0x80
  60. #define MMC_RX_OCTETCOUNT_GB 0x84
  61. #define MMC_RX_OCTETCOUNT_G 0x88
  62. #define MMC_RX_BROADCASTFRAME_G 0x8c
  63. #define MMC_RX_MULTICASTFRAME_G 0x90
  64. #define MMC_RX_CRC_ERROR 0x94
  65. #define MMC_RX_ALIGN_ERROR 0x98
  66. #define MMC_RX_RUN_ERROR 0x9C
  67. #define MMC_RX_JABBER_ERROR 0xA0
  68. #define MMC_RX_UNDERSIZE_G 0xA4
  69. #define MMC_RX_OVERSIZE_G 0xA8
  70. #define MMC_RX_64_OCTETS_GB 0xAC
  71. #define MMC_RX_65_TO_127_OCTETS_GB 0xb0
  72. #define MMC_RX_128_TO_255_OCTETS_GB 0xb4
  73. #define MMC_RX_256_TO_511_OCTETS_GB 0xb8
  74. #define MMC_RX_512_TO_1023_OCTETS_GB 0xbc
  75. #define MMC_RX_1024_TO_MAX_OCTETS_GB 0xc0
  76. #define MMC_RX_UNICAST_G 0xc4
  77. #define MMC_RX_LENGTH_ERROR 0xc8
  78. #define MMC_RX_AUTOFRANGETYPE 0xcc
  79. #define MMC_RX_PAUSE_FRAMES 0xd0
  80. #define MMC_RX_FIFO_OVERFLOW 0xd4
  81. #define MMC_RX_VLAN_FRAMES_GB 0xd8
  82. #define MMC_RX_WATCHDOG_ERROR 0xdc
  83. /* IPC*/
  84. #define MMC_RX_IPC_INTR_MASK 0x100
  85. #define MMC_RX_IPC_INTR 0x108
  86. /* IPv4*/
  87. #define MMC_RX_IPV4_GD 0x110
  88. #define MMC_RX_IPV4_HDERR 0x114
  89. #define MMC_RX_IPV4_NOPAY 0x118
  90. #define MMC_RX_IPV4_FRAG 0x11C
  91. #define MMC_RX_IPV4_UDSBL 0x120
  92. #define MMC_RX_IPV4_GD_OCTETS 0x150
  93. #define MMC_RX_IPV4_HDERR_OCTETS 0x154
  94. #define MMC_RX_IPV4_NOPAY_OCTETS 0x158
  95. #define MMC_RX_IPV4_FRAG_OCTETS 0x15c
  96. #define MMC_RX_IPV4_UDSBL_OCTETS 0x160
  97. /* IPV6*/
  98. #define MMC_RX_IPV6_GD_OCTETS 0x164
  99. #define MMC_RX_IPV6_HDERR_OCTETS 0x168
  100. #define MMC_RX_IPV6_NOPAY_OCTETS 0x16c
  101. #define MMC_RX_IPV6_GD 0x124
  102. #define MMC_RX_IPV6_HDERR 0x128
  103. #define MMC_RX_IPV6_NOPAY 0x12c
  104. /* Protocols*/
  105. #define MMC_RX_UDP_GD 0x130
  106. #define MMC_RX_UDP_ERR 0x134
  107. #define MMC_RX_TCP_GD 0x138
  108. #define MMC_RX_TCP_ERR 0x13c
  109. #define MMC_RX_ICMP_GD 0x140
  110. #define MMC_RX_ICMP_ERR 0x144
  111. #define MMC_RX_UDP_GD_OCTETS 0x170
  112. #define MMC_RX_UDP_ERR_OCTETS 0x174
  113. #define MMC_RX_TCP_GD_OCTETS 0x178
  114. #define MMC_RX_TCP_ERR_OCTETS 0x17c
  115. #define MMC_RX_ICMP_GD_OCTETS 0x180
  116. #define MMC_RX_ICMP_ERR_OCTETS 0x184
  117. void dwmac_mmc_ctrl(void __iomem *mmcaddr, unsigned int mode)
  118. {
  119. u32 value = readl(mmcaddr + MMC_CNTRL);
  120. value |= (mode & 0x3F);
  121. writel(value, mmcaddr + MMC_CNTRL);
  122. pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
  123. MMC_CNTRL, value);
  124. }
  125. /* To mask all all interrupts.*/
  126. void dwmac_mmc_intr_all_mask(void __iomem *mmcaddr)
  127. {
  128. writel(MMC_DEFAULT_MASK, mmcaddr + MMC_RX_INTR_MASK);
  129. writel(MMC_DEFAULT_MASK, mmcaddr + MMC_TX_INTR_MASK);
  130. writel(MMC_DEFAULT_MASK, mmcaddr + MMC_RX_IPC_INTR_MASK);
  131. }
  132. /* This reads the MAC core counters (if actaully supported).
  133. * by default the MMC core is programmed to reset each
  134. * counter after a read. So all the field of the mmc struct
  135. * have to be incremented.
  136. */
  137. void dwmac_mmc_read(void __iomem *mmcaddr, struct stmmac_counters *mmc)
  138. {
  139. mmc->mmc_tx_octetcount_gb += readl(mmcaddr + MMC_TX_OCTETCOUNT_GB);
  140. mmc->mmc_tx_framecount_gb += readl(mmcaddr + MMC_TX_FRAMECOUNT_GB);
  141. mmc->mmc_tx_broadcastframe_g += readl(mmcaddr +
  142. MMC_TX_BROADCASTFRAME_G);
  143. mmc->mmc_tx_multicastframe_g += readl(mmcaddr +
  144. MMC_TX_MULTICASTFRAME_G);
  145. mmc->mmc_tx_64_octets_gb += readl(mmcaddr + MMC_TX_64_OCTETS_GB);
  146. mmc->mmc_tx_65_to_127_octets_gb +=
  147. readl(mmcaddr + MMC_TX_65_TO_127_OCTETS_GB);
  148. mmc->mmc_tx_128_to_255_octets_gb +=
  149. readl(mmcaddr + MMC_TX_128_TO_255_OCTETS_GB);
  150. mmc->mmc_tx_256_to_511_octets_gb +=
  151. readl(mmcaddr + MMC_TX_256_TO_511_OCTETS_GB);
  152. mmc->mmc_tx_512_to_1023_octets_gb +=
  153. readl(mmcaddr + MMC_TX_512_TO_1023_OCTETS_GB);
  154. mmc->mmc_tx_1024_to_max_octets_gb +=
  155. readl(mmcaddr + MMC_TX_1024_TO_MAX_OCTETS_GB);
  156. mmc->mmc_tx_unicast_gb += readl(mmcaddr + MMC_TX_UNICAST_GB);
  157. mmc->mmc_tx_multicast_gb += readl(mmcaddr + MMC_TX_MULTICAST_GB);
  158. mmc->mmc_tx_broadcast_gb += readl(mmcaddr + MMC_TX_BROADCAST_GB);
  159. mmc->mmc_tx_underflow_error += readl(mmcaddr + MMC_TX_UNDERFLOW_ERROR);
  160. mmc->mmc_tx_singlecol_g += readl(mmcaddr + MMC_TX_SINGLECOL_G);
  161. mmc->mmc_tx_multicol_g += readl(mmcaddr + MMC_TX_MULTICOL_G);
  162. mmc->mmc_tx_deferred += readl(mmcaddr + MMC_TX_DEFERRED);
  163. mmc->mmc_tx_latecol += readl(mmcaddr + MMC_TX_LATECOL);
  164. mmc->mmc_tx_exesscol += readl(mmcaddr + MMC_TX_EXESSCOL);
  165. mmc->mmc_tx_carrier_error += readl(mmcaddr + MMC_TX_CARRIER_ERROR);
  166. mmc->mmc_tx_octetcount_g += readl(mmcaddr + MMC_TX_OCTETCOUNT_G);
  167. mmc->mmc_tx_framecount_g += readl(mmcaddr + MMC_TX_FRAMECOUNT_G);
  168. mmc->mmc_tx_excessdef += readl(mmcaddr + MMC_TX_EXCESSDEF);
  169. mmc->mmc_tx_pause_frame += readl(mmcaddr + MMC_TX_PAUSE_FRAME);
  170. mmc->mmc_tx_vlan_frame_g += readl(mmcaddr + MMC_TX_VLAN_FRAME_G);
  171. /* MMC RX counter registers */
  172. mmc->mmc_rx_framecount_gb += readl(mmcaddr + MMC_RX_FRAMECOUNT_GB);
  173. mmc->mmc_rx_octetcount_gb += readl(mmcaddr + MMC_RX_OCTETCOUNT_GB);
  174. mmc->mmc_rx_octetcount_g += readl(mmcaddr + MMC_RX_OCTETCOUNT_G);
  175. mmc->mmc_rx_broadcastframe_g += readl(mmcaddr +
  176. MMC_RX_BROADCASTFRAME_G);
  177. mmc->mmc_rx_multicastframe_g += readl(mmcaddr +
  178. MMC_RX_MULTICASTFRAME_G);
  179. mmc->mmc_rx_crc_error += readl(mmcaddr + MMC_RX_CRC_ERROR);
  180. mmc->mmc_rx_align_error += readl(mmcaddr + MMC_RX_ALIGN_ERROR);
  181. mmc->mmc_rx_run_error += readl(mmcaddr + MMC_RX_RUN_ERROR);
  182. mmc->mmc_rx_jabber_error += readl(mmcaddr + MMC_RX_JABBER_ERROR);
  183. mmc->mmc_rx_undersize_g += readl(mmcaddr + MMC_RX_UNDERSIZE_G);
  184. mmc->mmc_rx_oversize_g += readl(mmcaddr + MMC_RX_OVERSIZE_G);
  185. mmc->mmc_rx_64_octets_gb += readl(mmcaddr + MMC_RX_64_OCTETS_GB);
  186. mmc->mmc_rx_65_to_127_octets_gb +=
  187. readl(mmcaddr + MMC_RX_65_TO_127_OCTETS_GB);
  188. mmc->mmc_rx_128_to_255_octets_gb +=
  189. readl(mmcaddr + MMC_RX_128_TO_255_OCTETS_GB);
  190. mmc->mmc_rx_256_to_511_octets_gb +=
  191. readl(mmcaddr + MMC_RX_256_TO_511_OCTETS_GB);
  192. mmc->mmc_rx_512_to_1023_octets_gb +=
  193. readl(mmcaddr + MMC_RX_512_TO_1023_OCTETS_GB);
  194. mmc->mmc_rx_1024_to_max_octets_gb +=
  195. readl(mmcaddr + MMC_RX_1024_TO_MAX_OCTETS_GB);
  196. mmc->mmc_rx_unicast_g += readl(mmcaddr + MMC_RX_UNICAST_G);
  197. mmc->mmc_rx_length_error += readl(mmcaddr + MMC_RX_LENGTH_ERROR);
  198. mmc->mmc_rx_autofrangetype += readl(mmcaddr + MMC_RX_AUTOFRANGETYPE);
  199. mmc->mmc_rx_pause_frames += readl(mmcaddr + MMC_RX_PAUSE_FRAMES);
  200. mmc->mmc_rx_fifo_overflow += readl(mmcaddr + MMC_RX_FIFO_OVERFLOW);
  201. mmc->mmc_rx_vlan_frames_gb += readl(mmcaddr + MMC_RX_VLAN_FRAMES_GB);
  202. mmc->mmc_rx_watchdog_error += readl(mmcaddr + MMC_RX_WATCHDOG_ERROR);
  203. /* IPC */
  204. mmc->mmc_rx_ipc_intr_mask += readl(mmcaddr + MMC_RX_IPC_INTR_MASK);
  205. mmc->mmc_rx_ipc_intr += readl(mmcaddr + MMC_RX_IPC_INTR);
  206. /* IPv4 */
  207. mmc->mmc_rx_ipv4_gd += readl(mmcaddr + MMC_RX_IPV4_GD);
  208. mmc->mmc_rx_ipv4_hderr += readl(mmcaddr + MMC_RX_IPV4_HDERR);
  209. mmc->mmc_rx_ipv4_nopay += readl(mmcaddr + MMC_RX_IPV4_NOPAY);
  210. mmc->mmc_rx_ipv4_frag += readl(mmcaddr + MMC_RX_IPV4_FRAG);
  211. mmc->mmc_rx_ipv4_udsbl += readl(mmcaddr + MMC_RX_IPV4_UDSBL);
  212. mmc->mmc_rx_ipv4_gd_octets += readl(mmcaddr + MMC_RX_IPV4_GD_OCTETS);
  213. mmc->mmc_rx_ipv4_hderr_octets +=
  214. readl(mmcaddr + MMC_RX_IPV4_HDERR_OCTETS);
  215. mmc->mmc_rx_ipv4_nopay_octets +=
  216. readl(mmcaddr + MMC_RX_IPV4_NOPAY_OCTETS);
  217. mmc->mmc_rx_ipv4_frag_octets += readl(mmcaddr +
  218. MMC_RX_IPV4_FRAG_OCTETS);
  219. mmc->mmc_rx_ipv4_udsbl_octets +=
  220. readl(mmcaddr + MMC_RX_IPV4_UDSBL_OCTETS);
  221. /* IPV6 */
  222. mmc->mmc_rx_ipv6_gd_octets += readl(mmcaddr + MMC_RX_IPV6_GD_OCTETS);
  223. mmc->mmc_rx_ipv6_hderr_octets +=
  224. readl(mmcaddr + MMC_RX_IPV6_HDERR_OCTETS);
  225. mmc->mmc_rx_ipv6_nopay_octets +=
  226. readl(mmcaddr + MMC_RX_IPV6_NOPAY_OCTETS);
  227. mmc->mmc_rx_ipv6_gd += readl(mmcaddr + MMC_RX_IPV6_GD);
  228. mmc->mmc_rx_ipv6_hderr += readl(mmcaddr + MMC_RX_IPV6_HDERR);
  229. mmc->mmc_rx_ipv6_nopay += readl(mmcaddr + MMC_RX_IPV6_NOPAY);
  230. /* Protocols */
  231. mmc->mmc_rx_udp_gd += readl(mmcaddr + MMC_RX_UDP_GD);
  232. mmc->mmc_rx_udp_err += readl(mmcaddr + MMC_RX_UDP_ERR);
  233. mmc->mmc_rx_tcp_gd += readl(mmcaddr + MMC_RX_TCP_GD);
  234. mmc->mmc_rx_tcp_err += readl(mmcaddr + MMC_RX_TCP_ERR);
  235. mmc->mmc_rx_icmp_gd += readl(mmcaddr + MMC_RX_ICMP_GD);
  236. mmc->mmc_rx_icmp_err += readl(mmcaddr + MMC_RX_ICMP_ERR);
  237. mmc->mmc_rx_udp_gd_octets += readl(mmcaddr + MMC_RX_UDP_GD_OCTETS);
  238. mmc->mmc_rx_udp_err_octets += readl(mmcaddr + MMC_RX_UDP_ERR_OCTETS);
  239. mmc->mmc_rx_tcp_gd_octets += readl(mmcaddr + MMC_RX_TCP_GD_OCTETS);
  240. mmc->mmc_rx_tcp_err_octets += readl(mmcaddr + MMC_RX_TCP_ERR_OCTETS);
  241. mmc->mmc_rx_icmp_gd_octets += readl(mmcaddr + MMC_RX_ICMP_GD_OCTETS);
  242. mmc->mmc_rx_icmp_err_octets += readl(mmcaddr + MMC_RX_ICMP_ERR_OCTETS);
  243. }