macb.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*
  2. * File : macb.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Develop Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2011-03-18 weety first version
  23. */
  24. #ifndef _MACB_H
  25. #define _MACB_H
  26. #include <mii.h>
  27. /* MACB register offsets */
  28. #define MACB_NCR 0x0000
  29. #define MACB_NCFGR 0x0004
  30. #define MACB_NSR 0x0008
  31. #define MACB_TSR 0x0014
  32. #define MACB_RBQP 0x0018
  33. #define MACB_TBQP 0x001c
  34. #define MACB_RSR 0x0020
  35. #define MACB_ISR 0x0024
  36. #define MACB_IER 0x0028
  37. #define MACB_IDR 0x002c
  38. #define MACB_IMR 0x0030
  39. #define MACB_MAN 0x0034
  40. #define MACB_PTR 0x0038
  41. #define MACB_PFR 0x003c
  42. #define MACB_FTO 0x0040
  43. #define MACB_SCF 0x0044
  44. #define MACB_MCF 0x0048
  45. #define MACB_FRO 0x004c
  46. #define MACB_FCSE 0x0050
  47. #define MACB_ALE 0x0054
  48. #define MACB_DTF 0x0058
  49. #define MACB_LCOL 0x005c
  50. #define MACB_EXCOL 0x0060
  51. #define MACB_TUND 0x0064
  52. #define MACB_CSE 0x0068
  53. #define MACB_RRE 0x006c
  54. #define MACB_ROVR 0x0070
  55. #define MACB_RSE 0x0074
  56. #define MACB_ELE 0x0078
  57. #define MACB_RJA 0x007c
  58. #define MACB_USF 0x0080
  59. #define MACB_STE 0x0084
  60. #define MACB_RLE 0x0088
  61. #define MACB_TPF 0x008c
  62. #define MACB_HRB 0x0090
  63. #define MACB_HRT 0x0094
  64. #define MACB_SA1B 0x0098
  65. #define MACB_SA1T 0x009c
  66. #define MACB_SA2B 0x00a0
  67. #define MACB_SA2T 0x00a4
  68. #define MACB_SA3B 0x00a8
  69. #define MACB_SA3T 0x00ac
  70. #define MACB_SA4B 0x00b0
  71. #define MACB_SA4T 0x00b4
  72. #define MACB_TID 0x00b8
  73. #define MACB_TPQ 0x00bc
  74. #define MACB_USRIO 0x00c0
  75. #define MACB_WOL 0x00c4
  76. /* Bitfields in NCR */
  77. #define MACB_LB_OFFSET 0
  78. #define MACB_LB_SIZE 1
  79. #define MACB_LLB_OFFSET 1
  80. #define MACB_LLB_SIZE 1
  81. #define MACB_RE_OFFSET 2
  82. #define MACB_RE_SIZE 1
  83. #define MACB_TE_OFFSET 3
  84. #define MACB_TE_SIZE 1
  85. #define MACB_MPE_OFFSET 4
  86. #define MACB_MPE_SIZE 1
  87. #define MACB_CLRSTAT_OFFSET 5
  88. #define MACB_CLRSTAT_SIZE 1
  89. #define MACB_INCSTAT_OFFSET 6
  90. #define MACB_INCSTAT_SIZE 1
  91. #define MACB_WESTAT_OFFSET 7
  92. #define MACB_WESTAT_SIZE 1
  93. #define MACB_BP_OFFSET 8
  94. #define MACB_BP_SIZE 1
  95. #define MACB_TSTART_OFFSET 9
  96. #define MACB_TSTART_SIZE 1
  97. #define MACB_THALT_OFFSET 10
  98. #define MACB_THALT_SIZE 1
  99. #define MACB_NCR_TPF_OFFSET 11
  100. #define MACB_NCR_TPF_SIZE 1
  101. #define MACB_TZQ_OFFSET 12
  102. #define MACB_TZQ_SIZE 1
  103. /* Bitfields in NCFGR */
  104. #define MACB_SPD_OFFSET 0
  105. #define MACB_SPD_SIZE 1
  106. #define MACB_FD_OFFSET 1
  107. #define MACB_FD_SIZE 1
  108. #define MACB_BIT_RATE_OFFSET 2
  109. #define MACB_BIT_RATE_SIZE 1
  110. #define MACB_JFRAME_OFFSET 3
  111. #define MACB_JFRAME_SIZE 1
  112. #define MACB_CAF_OFFSET 4
  113. #define MACB_CAF_SIZE 1
  114. #define MACB_NBC_OFFSET 5
  115. #define MACB_NBC_SIZE 1
  116. #define MACB_NCFGR_MTI_OFFSET 6
  117. #define MACB_NCFGR_MTI_SIZE 1
  118. #define MACB_UNI_OFFSET 7
  119. #define MACB_UNI_SIZE 1
  120. #define MACB_BIG_OFFSET 8
  121. #define MACB_BIG_SIZE 1
  122. #define MACB_EAE_OFFSET 9
  123. #define MACB_EAE_SIZE 1
  124. #define MACB_CLK_OFFSET 10
  125. #define MACB_CLK_SIZE 2
  126. #define MACB_RTY_OFFSET 12
  127. #define MACB_RTY_SIZE 1
  128. #define MACB_PAE_OFFSET 13
  129. #define MACB_PAE_SIZE 1
  130. #define MACB_RBOF_OFFSET 14
  131. #define MACB_RBOF_SIZE 2
  132. #define MACB_RLCE_OFFSET 16
  133. #define MACB_RLCE_SIZE 1
  134. #define MACB_DRFCS_OFFSET 17
  135. #define MACB_DRFCS_SIZE 1
  136. #define MACB_EFRHD_OFFSET 18
  137. #define MACB_EFRHD_SIZE 1
  138. #define MACB_IRXFCS_OFFSET 19
  139. #define MACB_IRXFCS_SIZE 1
  140. /* Bitfields in NSR */
  141. #define MACB_NSR_LINK_OFFSET 0
  142. #define MACB_NSR_LINK_SIZE 1
  143. #define MACB_MDIO_OFFSET 1
  144. #define MACB_MDIO_SIZE 1
  145. #define MACB_IDLE_OFFSET 2
  146. #define MACB_IDLE_SIZE 1
  147. /* Bitfields in TSR */
  148. #define MACB_UBR_OFFSET 0
  149. #define MACB_UBR_SIZE 1
  150. #define MACB_COL_OFFSET 1
  151. #define MACB_COL_SIZE 1
  152. #define MACB_TSR_RLE_OFFSET 2
  153. #define MACB_TSR_RLE_SIZE 1
  154. #define MACB_TGO_OFFSET 3
  155. #define MACB_TGO_SIZE 1
  156. #define MACB_BEX_OFFSET 4
  157. #define MACB_BEX_SIZE 1
  158. #define MACB_COMP_OFFSET 5
  159. #define MACB_COMP_SIZE 1
  160. #define MACB_UND_OFFSET 6
  161. #define MACB_UND_SIZE 1
  162. /* Bitfields in RSR */
  163. #define MACB_BNA_OFFSET 0
  164. #define MACB_BNA_SIZE 1
  165. #define MACB_REC_OFFSET 1
  166. #define MACB_REC_SIZE 1
  167. #define MACB_OVR_OFFSET 2
  168. #define MACB_OVR_SIZE 1
  169. /* Bitfields in ISR/IER/IDR/IMR */
  170. #define MACB_MFD_OFFSET 0
  171. #define MACB_MFD_SIZE 1
  172. #define MACB_RCOMP_OFFSET 1
  173. #define MACB_RCOMP_SIZE 1
  174. #define MACB_RXUBR_OFFSET 2
  175. #define MACB_RXUBR_SIZE 1
  176. #define MACB_TXUBR_OFFSET 3
  177. #define MACB_TXUBR_SIZE 1
  178. #define MACB_ISR_TUND_OFFSET 4
  179. #define MACB_ISR_TUND_SIZE 1
  180. #define MACB_ISR_RLE_OFFSET 5
  181. #define MACB_ISR_RLE_SIZE 1
  182. #define MACB_TXERR_OFFSET 6
  183. #define MACB_TXERR_SIZE 1
  184. #define MACB_TCOMP_OFFSET 7
  185. #define MACB_TCOMP_SIZE 1
  186. #define MACB_ISR_LINK_OFFSET 9
  187. #define MACB_ISR_LINK_SIZE 1
  188. #define MACB_ISR_ROVR_OFFSET 10
  189. #define MACB_ISR_ROVR_SIZE 1
  190. #define MACB_HRESP_OFFSET 11
  191. #define MACB_HRESP_SIZE 1
  192. #define MACB_PFR_OFFSET 12
  193. #define MACB_PFR_SIZE 1
  194. #define MACB_PTZ_OFFSET 13
  195. #define MACB_PTZ_SIZE 1
  196. /* Bitfields in MAN */
  197. #define MACB_DATA_OFFSET 0
  198. #define MACB_DATA_SIZE 16
  199. #define MACB_CODE_OFFSET 16
  200. #define MACB_CODE_SIZE 2
  201. #define MACB_REGA_OFFSET 18
  202. #define MACB_REGA_SIZE 5
  203. #define MACB_PHYA_OFFSET 23
  204. #define MACB_PHYA_SIZE 5
  205. #define MACB_RW_OFFSET 28
  206. #define MACB_RW_SIZE 2
  207. #define MACB_SOF_OFFSET 30
  208. #define MACB_SOF_SIZE 2
  209. /* Bitfields in USRIO (AVR32) */
  210. #define MACB_MII_OFFSET 0
  211. #define MACB_MII_SIZE 1
  212. #define MACB_EAM_OFFSET 1
  213. #define MACB_EAM_SIZE 1
  214. #define MACB_TX_PAUSE_OFFSET 2
  215. #define MACB_TX_PAUSE_SIZE 1
  216. #define MACB_TX_PAUSE_ZERO_OFFSET 3
  217. #define MACB_TX_PAUSE_ZERO_SIZE 1
  218. /* Bitfields in USRIO (AT91) */
  219. #define MACB_RMII_OFFSET 0
  220. #define MACB_RMII_SIZE 1
  221. #define MACB_CLKEN_OFFSET 1
  222. #define MACB_CLKEN_SIZE 1
  223. /* Bitfields in WOL */
  224. #define MACB_IP_OFFSET 0
  225. #define MACB_IP_SIZE 16
  226. #define MACB_MAG_OFFSET 16
  227. #define MACB_MAG_SIZE 1
  228. #define MACB_ARP_OFFSET 17
  229. #define MACB_ARP_SIZE 1
  230. #define MACB_SA1_OFFSET 18
  231. #define MACB_SA1_SIZE 1
  232. #define MACB_WOL_MTI_OFFSET 19
  233. #define MACB_WOL_MTI_SIZE 1
  234. /* Constants for CLK */
  235. #define MACB_CLK_DIV8 0
  236. #define MACB_CLK_DIV16 1
  237. #define MACB_CLK_DIV32 2
  238. #define MACB_CLK_DIV64 3
  239. /* Constants for MAN register */
  240. #define MACB_MAN_SOF 1
  241. #define MACB_MAN_WRITE 1
  242. #define MACB_MAN_READ 2
  243. #define MACB_MAN_CODE 2
  244. /* Bit manipulation macros */
  245. #define MACB_BIT(name) \
  246. (1 << MACB_##name##_OFFSET)
  247. #define MACB_BF(name,value) \
  248. (((value) & ((1 << MACB_##name##_SIZE) - 1)) \
  249. << MACB_##name##_OFFSET)
  250. #define MACB_BFEXT(name,value)\
  251. (((value) >> MACB_##name##_OFFSET) \
  252. & ((1 << MACB_##name##_SIZE) - 1))
  253. #define MACB_BFINS(name,value,old) \
  254. (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \
  255. << MACB_##name##_OFFSET)) \
  256. | MACB_BF(name,value))
  257. /* Register access macros */
  258. #define macb_readl(port,reg) \
  259. readl((port)->regs + MACB_##reg)
  260. #define macb_writel(port,reg,value) \
  261. writel((value), (port)->regs + MACB_##reg)
  262. struct dma_desc {
  263. rt_uint32_t addr;
  264. rt_uint32_t ctrl;
  265. };
  266. /* DMA descriptor bitfields */
  267. #define MACB_RX_USED_OFFSET 0
  268. #define MACB_RX_USED_SIZE 1
  269. #define MACB_RX_WRAP_OFFSET 1
  270. #define MACB_RX_WRAP_SIZE 1
  271. #define MACB_RX_WADDR_OFFSET 2
  272. #define MACB_RX_WADDR_SIZE 30
  273. #define MACB_RX_FRMLEN_OFFSET 0
  274. #define MACB_RX_FRMLEN_SIZE 12
  275. #define MACB_RX_OFFSET_OFFSET 12
  276. #define MACB_RX_OFFSET_SIZE 2
  277. #define MACB_RX_SOF_OFFSET 14
  278. #define MACB_RX_SOF_SIZE 1
  279. #define MACB_RX_EOF_OFFSET 15
  280. #define MACB_RX_EOF_SIZE 1
  281. #define MACB_RX_CFI_OFFSET 16
  282. #define MACB_RX_CFI_SIZE 1
  283. #define MACB_RX_VLAN_PRI_OFFSET 17
  284. #define MACB_RX_VLAN_PRI_SIZE 3
  285. #define MACB_RX_PRI_TAG_OFFSET 20
  286. #define MACB_RX_PRI_TAG_SIZE 1
  287. #define MACB_RX_VLAN_TAG_OFFSET 21
  288. #define MACB_RX_VLAN_TAG_SIZE 1
  289. #define MACB_RX_TYPEID_MATCH_OFFSET 22
  290. #define MACB_RX_TYPEID_MATCH_SIZE 1
  291. #define MACB_RX_SA4_MATCH_OFFSET 23
  292. #define MACB_RX_SA4_MATCH_SIZE 1
  293. #define MACB_RX_SA3_MATCH_OFFSET 24
  294. #define MACB_RX_SA3_MATCH_SIZE 1
  295. #define MACB_RX_SA2_MATCH_OFFSET 25
  296. #define MACB_RX_SA2_MATCH_SIZE 1
  297. #define MACB_RX_SA1_MATCH_OFFSET 26
  298. #define MACB_RX_SA1_MATCH_SIZE 1
  299. #define MACB_RX_EXT_MATCH_OFFSET 28
  300. #define MACB_RX_EXT_MATCH_SIZE 1
  301. #define MACB_RX_UHASH_MATCH_OFFSET 29
  302. #define MACB_RX_UHASH_MATCH_SIZE 1
  303. #define MACB_RX_MHASH_MATCH_OFFSET 30
  304. #define MACB_RX_MHASH_MATCH_SIZE 1
  305. #define MACB_RX_BROADCAST_OFFSET 31
  306. #define MACB_RX_BROADCAST_SIZE 1
  307. #define MACB_TX_FRMLEN_OFFSET 0
  308. #define MACB_TX_FRMLEN_SIZE 11
  309. #define MACB_TX_LAST_OFFSET 15
  310. #define MACB_TX_LAST_SIZE 1
  311. #define MACB_TX_NOCRC_OFFSET 16
  312. #define MACB_TX_NOCRC_SIZE 1
  313. #define MACB_TX_BUF_EXHAUSTED_OFFSET 27
  314. #define MACB_TX_BUF_EXHAUSTED_SIZE 1
  315. #define MACB_TX_UNDERRUN_OFFSET 28
  316. #define MACB_TX_UNDERRUN_SIZE 1
  317. #define MACB_TX_ERROR_OFFSET 29
  318. #define MACB_TX_ERROR_SIZE 1
  319. #define MACB_TX_WRAP_OFFSET 30
  320. #define MACB_TX_WRAP_SIZE 1
  321. #define MACB_TX_USED_OFFSET 31
  322. #define MACB_TX_USED_SIZE 1
  323. extern void rt_hw_macb_init();
  324. #endif /* _MACB_H */