macb.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /*
  2. * Atmel MACB Ethernet Controller driver
  3. *
  4. * Copyright (C) 2004-2006 Atmel Corporation
  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 version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _MACB_H
  11. #define _MACB_H
  12. /* MACB register offsets */
  13. #define MACB_NCR 0x0000
  14. #define MACB_NCFGR 0x0004
  15. #define MACB_NSR 0x0008
  16. #define MACB_TSR 0x0014
  17. #define MACB_RBQP 0x0018
  18. #define MACB_TBQP 0x001c
  19. #define MACB_RSR 0x0020
  20. #define MACB_ISR 0x0024
  21. #define MACB_IER 0x0028
  22. #define MACB_IDR 0x002c
  23. #define MACB_IMR 0x0030
  24. #define MACB_MAN 0x0034
  25. #define MACB_PTR 0x0038
  26. #define MACB_PFR 0x003c
  27. #define MACB_FTO 0x0040
  28. #define MACB_SCF 0x0044
  29. #define MACB_MCF 0x0048
  30. #define MACB_FRO 0x004c
  31. #define MACB_FCSE 0x0050
  32. #define MACB_ALE 0x0054
  33. #define MACB_DTF 0x0058
  34. #define MACB_LCOL 0x005c
  35. #define MACB_EXCOL 0x0060
  36. #define MACB_TUND 0x0064
  37. #define MACB_CSE 0x0068
  38. #define MACB_RRE 0x006c
  39. #define MACB_ROVR 0x0070
  40. #define MACB_RSE 0x0074
  41. #define MACB_ELE 0x0078
  42. #define MACB_RJA 0x007c
  43. #define MACB_USF 0x0080
  44. #define MACB_STE 0x0084
  45. #define MACB_RLE 0x0088
  46. #define MACB_TPF 0x008c
  47. #define MACB_HRB 0x0090
  48. #define MACB_HRT 0x0094
  49. #define MACB_SA1B 0x0098
  50. #define MACB_SA1T 0x009c
  51. #define MACB_SA2B 0x00a0
  52. #define MACB_SA2T 0x00a4
  53. #define MACB_SA3B 0x00a8
  54. #define MACB_SA3T 0x00ac
  55. #define MACB_SA4B 0x00b0
  56. #define MACB_SA4T 0x00b4
  57. #define MACB_TID 0x00b8
  58. #define MACB_TPQ 0x00bc
  59. #define MACB_USRIO 0x00c0
  60. #define MACB_WOL 0x00c4
  61. /* Bitfields in NCR */
  62. #define MACB_LB_OFFSET 0
  63. #define MACB_LB_SIZE 1
  64. #define MACB_LLB_OFFSET 1
  65. #define MACB_LLB_SIZE 1
  66. #define MACB_RE_OFFSET 2
  67. #define MACB_RE_SIZE 1
  68. #define MACB_TE_OFFSET 3
  69. #define MACB_TE_SIZE 1
  70. #define MACB_MPE_OFFSET 4
  71. #define MACB_MPE_SIZE 1
  72. #define MACB_CLRSTAT_OFFSET 5
  73. #define MACB_CLRSTAT_SIZE 1
  74. #define MACB_INCSTAT_OFFSET 6
  75. #define MACB_INCSTAT_SIZE 1
  76. #define MACB_WESTAT_OFFSET 7
  77. #define MACB_WESTAT_SIZE 1
  78. #define MACB_BP_OFFSET 8
  79. #define MACB_BP_SIZE 1
  80. #define MACB_TSTART_OFFSET 9
  81. #define MACB_TSTART_SIZE 1
  82. #define MACB_THALT_OFFSET 10
  83. #define MACB_THALT_SIZE 1
  84. #define MACB_NCR_TPF_OFFSET 11
  85. #define MACB_NCR_TPF_SIZE 1
  86. #define MACB_TZQ_OFFSET 12
  87. #define MACB_TZQ_SIZE 1
  88. /* Bitfields in NCFGR */
  89. #define MACB_SPD_OFFSET 0
  90. #define MACB_SPD_SIZE 1
  91. #define MACB_FD_OFFSET 1
  92. #define MACB_FD_SIZE 1
  93. #define MACB_BIT_RATE_OFFSET 2
  94. #define MACB_BIT_RATE_SIZE 1
  95. #define MACB_JFRAME_OFFSET 3
  96. #define MACB_JFRAME_SIZE 1
  97. #define MACB_CAF_OFFSET 4
  98. #define MACB_CAF_SIZE 1
  99. #define MACB_NBC_OFFSET 5
  100. #define MACB_NBC_SIZE 1
  101. #define MACB_NCFGR_MTI_OFFSET 6
  102. #define MACB_NCFGR_MTI_SIZE 1
  103. #define MACB_UNI_OFFSET 7
  104. #define MACB_UNI_SIZE 1
  105. #define MACB_BIG_OFFSET 8
  106. #define MACB_BIG_SIZE 1
  107. #define MACB_EAE_OFFSET 9
  108. #define MACB_EAE_SIZE 1
  109. #define MACB_CLK_OFFSET 10
  110. #define MACB_CLK_SIZE 2
  111. #define MACB_RTY_OFFSET 12
  112. #define MACB_RTY_SIZE 1
  113. #define MACB_PAE_OFFSET 13
  114. #define MACB_PAE_SIZE 1
  115. #define MACB_RBOF_OFFSET 14
  116. #define MACB_RBOF_SIZE 2
  117. #define MACB_RLCE_OFFSET 16
  118. #define MACB_RLCE_SIZE 1
  119. #define MACB_DRFCS_OFFSET 17
  120. #define MACB_DRFCS_SIZE 1
  121. #define MACB_EFRHD_OFFSET 18
  122. #define MACB_EFRHD_SIZE 1
  123. #define MACB_IRXFCS_OFFSET 19
  124. #define MACB_IRXFCS_SIZE 1
  125. /* Bitfields in NSR */
  126. #define MACB_NSR_LINK_OFFSET 0
  127. #define MACB_NSR_LINK_SIZE 1
  128. #define MACB_MDIO_OFFSET 1
  129. #define MACB_MDIO_SIZE 1
  130. #define MACB_IDLE_OFFSET 2
  131. #define MACB_IDLE_SIZE 1
  132. /* Bitfields in TSR */
  133. #define MACB_UBR_OFFSET 0
  134. #define MACB_UBR_SIZE 1
  135. #define MACB_COL_OFFSET 1
  136. #define MACB_COL_SIZE 1
  137. #define MACB_TSR_RLE_OFFSET 2
  138. #define MACB_TSR_RLE_SIZE 1
  139. #define MACB_TGO_OFFSET 3
  140. #define MACB_TGO_SIZE 1
  141. #define MACB_BEX_OFFSET 4
  142. #define MACB_BEX_SIZE 1
  143. #define MACB_COMP_OFFSET 5
  144. #define MACB_COMP_SIZE 1
  145. #define MACB_UND_OFFSET 6
  146. #define MACB_UND_SIZE 1
  147. /* Bitfields in RSR */
  148. #define MACB_BNA_OFFSET 0
  149. #define MACB_BNA_SIZE 1
  150. #define MACB_REC_OFFSET 1
  151. #define MACB_REC_SIZE 1
  152. #define MACB_OVR_OFFSET 2
  153. #define MACB_OVR_SIZE 1
  154. /* Bitfields in ISR/IER/IDR/IMR */
  155. #define MACB_MFD_OFFSET 0
  156. #define MACB_MFD_SIZE 1
  157. #define MACB_RCOMP_OFFSET 1
  158. #define MACB_RCOMP_SIZE 1
  159. #define MACB_RXUBR_OFFSET 2
  160. #define MACB_RXUBR_SIZE 1
  161. #define MACB_TXUBR_OFFSET 3
  162. #define MACB_TXUBR_SIZE 1
  163. #define MACB_ISR_TUND_OFFSET 4
  164. #define MACB_ISR_TUND_SIZE 1
  165. #define MACB_ISR_RLE_OFFSET 5
  166. #define MACB_ISR_RLE_SIZE 1
  167. #define MACB_TXERR_OFFSET 6
  168. #define MACB_TXERR_SIZE 1
  169. #define MACB_TCOMP_OFFSET 7
  170. #define MACB_TCOMP_SIZE 1
  171. #define MACB_ISR_LINK_OFFSET 9
  172. #define MACB_ISR_LINK_SIZE 1
  173. #define MACB_ISR_ROVR_OFFSET 10
  174. #define MACB_ISR_ROVR_SIZE 1
  175. #define MACB_HRESP_OFFSET 11
  176. #define MACB_HRESP_SIZE 1
  177. #define MACB_PFR_OFFSET 12
  178. #define MACB_PFR_SIZE 1
  179. #define MACB_PTZ_OFFSET 13
  180. #define MACB_PTZ_SIZE 1
  181. /* Bitfields in MAN */
  182. #define MACB_DATA_OFFSET 0
  183. #define MACB_DATA_SIZE 16
  184. #define MACB_CODE_OFFSET 16
  185. #define MACB_CODE_SIZE 2
  186. #define MACB_REGA_OFFSET 18
  187. #define MACB_REGA_SIZE 5
  188. #define MACB_PHYA_OFFSET 23
  189. #define MACB_PHYA_SIZE 5
  190. #define MACB_RW_OFFSET 28
  191. #define MACB_RW_SIZE 2
  192. #define MACB_SOF_OFFSET 30
  193. #define MACB_SOF_SIZE 2
  194. /* Bitfields in USRIO (AVR32) */
  195. #define MACB_MII_OFFSET 0
  196. #define MACB_MII_SIZE 1
  197. #define MACB_EAM_OFFSET 1
  198. #define MACB_EAM_SIZE 1
  199. #define MACB_TX_PAUSE_OFFSET 2
  200. #define MACB_TX_PAUSE_SIZE 1
  201. #define MACB_TX_PAUSE_ZERO_OFFSET 3
  202. #define MACB_TX_PAUSE_ZERO_SIZE 1
  203. /* Bitfields in USRIO (AT91) */
  204. #define MACB_RMII_OFFSET 0
  205. #define MACB_RMII_SIZE 1
  206. #define MACB_CLKEN_OFFSET 1
  207. #define MACB_CLKEN_SIZE 1
  208. /* Bitfields in WOL */
  209. #define MACB_IP_OFFSET 0
  210. #define MACB_IP_SIZE 16
  211. #define MACB_MAG_OFFSET 16
  212. #define MACB_MAG_SIZE 1
  213. #define MACB_ARP_OFFSET 17
  214. #define MACB_ARP_SIZE 1
  215. #define MACB_SA1_OFFSET 18
  216. #define MACB_SA1_SIZE 1
  217. #define MACB_WOL_MTI_OFFSET 19
  218. #define MACB_WOL_MTI_SIZE 1
  219. /* Constants for CLK */
  220. #define MACB_CLK_DIV8 0
  221. #define MACB_CLK_DIV16 1
  222. #define MACB_CLK_DIV32 2
  223. #define MACB_CLK_DIV64 3
  224. /* Constants for MAN register */
  225. #define MACB_MAN_SOF 1
  226. #define MACB_MAN_WRITE 1
  227. #define MACB_MAN_READ 2
  228. #define MACB_MAN_CODE 2
  229. /* Bit manipulation macros */
  230. #define MACB_BIT(name) \
  231. (1 << MACB_##name##_OFFSET)
  232. #define MACB_BF(name,value) \
  233. (((value) & ((1 << MACB_##name##_SIZE) - 1)) \
  234. << MACB_##name##_OFFSET)
  235. #define MACB_BFEXT(name,value)\
  236. (((value) >> MACB_##name##_OFFSET) \
  237. & ((1 << MACB_##name##_SIZE) - 1))
  238. #define MACB_BFINS(name,value,old) \
  239. (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \
  240. << MACB_##name##_OFFSET)) \
  241. | MACB_BF(name,value))
  242. /* Register access macros */
  243. #define macb_readl(port,reg) \
  244. __raw_readl((port)->regs + MACB_##reg)
  245. #define macb_writel(port,reg,value) \
  246. __raw_writel((value), (port)->regs + MACB_##reg)
  247. struct dma_desc {
  248. u32 addr;
  249. u32 ctrl;
  250. };
  251. /* DMA descriptor bitfields */
  252. #define MACB_RX_USED_OFFSET 0
  253. #define MACB_RX_USED_SIZE 1
  254. #define MACB_RX_WRAP_OFFSET 1
  255. #define MACB_RX_WRAP_SIZE 1
  256. #define MACB_RX_WADDR_OFFSET 2
  257. #define MACB_RX_WADDR_SIZE 30
  258. #define MACB_RX_FRMLEN_OFFSET 0
  259. #define MACB_RX_FRMLEN_SIZE 12
  260. #define MACB_RX_OFFSET_OFFSET 12
  261. #define MACB_RX_OFFSET_SIZE 2
  262. #define MACB_RX_SOF_OFFSET 14
  263. #define MACB_RX_SOF_SIZE 1
  264. #define MACB_RX_EOF_OFFSET 15
  265. #define MACB_RX_EOF_SIZE 1
  266. #define MACB_RX_CFI_OFFSET 16
  267. #define MACB_RX_CFI_SIZE 1
  268. #define MACB_RX_VLAN_PRI_OFFSET 17
  269. #define MACB_RX_VLAN_PRI_SIZE 3
  270. #define MACB_RX_PRI_TAG_OFFSET 20
  271. #define MACB_RX_PRI_TAG_SIZE 1
  272. #define MACB_RX_VLAN_TAG_OFFSET 21
  273. #define MACB_RX_VLAN_TAG_SIZE 1
  274. #define MACB_RX_TYPEID_MATCH_OFFSET 22
  275. #define MACB_RX_TYPEID_MATCH_SIZE 1
  276. #define MACB_RX_SA4_MATCH_OFFSET 23
  277. #define MACB_RX_SA4_MATCH_SIZE 1
  278. #define MACB_RX_SA3_MATCH_OFFSET 24
  279. #define MACB_RX_SA3_MATCH_SIZE 1
  280. #define MACB_RX_SA2_MATCH_OFFSET 25
  281. #define MACB_RX_SA2_MATCH_SIZE 1
  282. #define MACB_RX_SA1_MATCH_OFFSET 26
  283. #define MACB_RX_SA1_MATCH_SIZE 1
  284. #define MACB_RX_EXT_MATCH_OFFSET 28
  285. #define MACB_RX_EXT_MATCH_SIZE 1
  286. #define MACB_RX_UHASH_MATCH_OFFSET 29
  287. #define MACB_RX_UHASH_MATCH_SIZE 1
  288. #define MACB_RX_MHASH_MATCH_OFFSET 30
  289. #define MACB_RX_MHASH_MATCH_SIZE 1
  290. #define MACB_RX_BROADCAST_OFFSET 31
  291. #define MACB_RX_BROADCAST_SIZE 1
  292. #define MACB_TX_FRMLEN_OFFSET 0
  293. #define MACB_TX_FRMLEN_SIZE 11
  294. #define MACB_TX_LAST_OFFSET 15
  295. #define MACB_TX_LAST_SIZE 1
  296. #define MACB_TX_NOCRC_OFFSET 16
  297. #define MACB_TX_NOCRC_SIZE 1
  298. #define MACB_TX_BUF_EXHAUSTED_OFFSET 27
  299. #define MACB_TX_BUF_EXHAUSTED_SIZE 1
  300. #define MACB_TX_UNDERRUN_OFFSET 28
  301. #define MACB_TX_UNDERRUN_SIZE 1
  302. #define MACB_TX_ERROR_OFFSET 29
  303. #define MACB_TX_ERROR_SIZE 1
  304. #define MACB_TX_WRAP_OFFSET 30
  305. #define MACB_TX_WRAP_SIZE 1
  306. #define MACB_TX_USED_OFFSET 31
  307. #define MACB_TX_USED_SIZE 1
  308. struct ring_info {
  309. struct sk_buff *skb;
  310. dma_addr_t mapping;
  311. };
  312. /*
  313. * Hardware-collected statistics. Used when updating the network
  314. * device stats by a periodic timer.
  315. */
  316. struct macb_stats {
  317. u32 rx_pause_frames;
  318. u32 tx_ok;
  319. u32 tx_single_cols;
  320. u32 tx_multiple_cols;
  321. u32 rx_ok;
  322. u32 rx_fcs_errors;
  323. u32 rx_align_errors;
  324. u32 tx_deferred;
  325. u32 tx_late_cols;
  326. u32 tx_excessive_cols;
  327. u32 tx_underruns;
  328. u32 tx_carrier_errors;
  329. u32 rx_resource_errors;
  330. u32 rx_overruns;
  331. u32 rx_symbol_errors;
  332. u32 rx_oversize_pkts;
  333. u32 rx_jabbers;
  334. u32 rx_undersize_pkts;
  335. u32 sqe_test_errors;
  336. u32 rx_length_mismatch;
  337. u32 tx_pause_frames;
  338. };
  339. struct macb {
  340. void __iomem *regs;
  341. unsigned int rx_tail;
  342. struct dma_desc *rx_ring;
  343. void *rx_buffers;
  344. unsigned int tx_head, tx_tail;
  345. struct dma_desc *tx_ring;
  346. struct ring_info *tx_skb;
  347. spinlock_t lock;
  348. struct platform_device *pdev;
  349. struct clk *pclk;
  350. struct clk *hclk;
  351. struct net_device *dev;
  352. struct net_device_stats stats;
  353. struct macb_stats hw_stats;
  354. dma_addr_t rx_ring_dma;
  355. dma_addr_t tx_ring_dma;
  356. dma_addr_t rx_buffers_dma;
  357. unsigned int rx_pending, tx_pending;
  358. struct delayed_work periodic_task;
  359. struct mutex mdio_mutex;
  360. struct completion mdio_complete;
  361. struct mii_if_info mii;
  362. };
  363. #endif /* _MACB_H */