macb.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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. #define MACB_MID 0x00fc
  62. /* GEM register offsets. */
  63. #define GEM_NCFGR 0x0004
  64. #define GEM_USRIO 0x000c
  65. #define GEM_HRB 0x0080
  66. #define GEM_HRT 0x0084
  67. #define GEM_SA1B 0x0088
  68. #define GEM_SA1T 0x008C
  69. #define GEM_OTX 0x0100
  70. /* Bitfields in NCR */
  71. #define MACB_LB_OFFSET 0
  72. #define MACB_LB_SIZE 1
  73. #define MACB_LLB_OFFSET 1
  74. #define MACB_LLB_SIZE 1
  75. #define MACB_RE_OFFSET 2
  76. #define MACB_RE_SIZE 1
  77. #define MACB_TE_OFFSET 3
  78. #define MACB_TE_SIZE 1
  79. #define MACB_MPE_OFFSET 4
  80. #define MACB_MPE_SIZE 1
  81. #define MACB_CLRSTAT_OFFSET 5
  82. #define MACB_CLRSTAT_SIZE 1
  83. #define MACB_INCSTAT_OFFSET 6
  84. #define MACB_INCSTAT_SIZE 1
  85. #define MACB_WESTAT_OFFSET 7
  86. #define MACB_WESTAT_SIZE 1
  87. #define MACB_BP_OFFSET 8
  88. #define MACB_BP_SIZE 1
  89. #define MACB_TSTART_OFFSET 9
  90. #define MACB_TSTART_SIZE 1
  91. #define MACB_THALT_OFFSET 10
  92. #define MACB_THALT_SIZE 1
  93. #define MACB_NCR_TPF_OFFSET 11
  94. #define MACB_NCR_TPF_SIZE 1
  95. #define MACB_TZQ_OFFSET 12
  96. #define MACB_TZQ_SIZE 1
  97. /* Bitfields in NCFGR */
  98. #define MACB_SPD_OFFSET 0
  99. #define MACB_SPD_SIZE 1
  100. #define MACB_FD_OFFSET 1
  101. #define MACB_FD_SIZE 1
  102. #define MACB_BIT_RATE_OFFSET 2
  103. #define MACB_BIT_RATE_SIZE 1
  104. #define MACB_JFRAME_OFFSET 3
  105. #define MACB_JFRAME_SIZE 1
  106. #define MACB_CAF_OFFSET 4
  107. #define MACB_CAF_SIZE 1
  108. #define MACB_NBC_OFFSET 5
  109. #define MACB_NBC_SIZE 1
  110. #define MACB_NCFGR_MTI_OFFSET 6
  111. #define MACB_NCFGR_MTI_SIZE 1
  112. #define MACB_UNI_OFFSET 7
  113. #define MACB_UNI_SIZE 1
  114. #define MACB_BIG_OFFSET 8
  115. #define MACB_BIG_SIZE 1
  116. #define MACB_EAE_OFFSET 9
  117. #define MACB_EAE_SIZE 1
  118. #define MACB_CLK_OFFSET 10
  119. #define MACB_CLK_SIZE 2
  120. #define MACB_RTY_OFFSET 12
  121. #define MACB_RTY_SIZE 1
  122. #define MACB_PAE_OFFSET 13
  123. #define MACB_PAE_SIZE 1
  124. #define MACB_RBOF_OFFSET 14
  125. #define MACB_RBOF_SIZE 2
  126. #define MACB_RLCE_OFFSET 16
  127. #define MACB_RLCE_SIZE 1
  128. #define MACB_DRFCS_OFFSET 17
  129. #define MACB_DRFCS_SIZE 1
  130. #define MACB_EFRHD_OFFSET 18
  131. #define MACB_EFRHD_SIZE 1
  132. #define MACB_IRXFCS_OFFSET 19
  133. #define MACB_IRXFCS_SIZE 1
  134. /* GEM specific NCFGR bitfields. */
  135. #define GEM_CLK_OFFSET 18
  136. #define GEM_CLK_SIZE 3
  137. /* Bitfields in NSR */
  138. #define MACB_NSR_LINK_OFFSET 0
  139. #define MACB_NSR_LINK_SIZE 1
  140. #define MACB_MDIO_OFFSET 1
  141. #define MACB_MDIO_SIZE 1
  142. #define MACB_IDLE_OFFSET 2
  143. #define MACB_IDLE_SIZE 1
  144. /* Bitfields in TSR */
  145. #define MACB_UBR_OFFSET 0
  146. #define MACB_UBR_SIZE 1
  147. #define MACB_COL_OFFSET 1
  148. #define MACB_COL_SIZE 1
  149. #define MACB_TSR_RLE_OFFSET 2
  150. #define MACB_TSR_RLE_SIZE 1
  151. #define MACB_TGO_OFFSET 3
  152. #define MACB_TGO_SIZE 1
  153. #define MACB_BEX_OFFSET 4
  154. #define MACB_BEX_SIZE 1
  155. #define MACB_COMP_OFFSET 5
  156. #define MACB_COMP_SIZE 1
  157. #define MACB_UND_OFFSET 6
  158. #define MACB_UND_SIZE 1
  159. /* Bitfields in RSR */
  160. #define MACB_BNA_OFFSET 0
  161. #define MACB_BNA_SIZE 1
  162. #define MACB_REC_OFFSET 1
  163. #define MACB_REC_SIZE 1
  164. #define MACB_OVR_OFFSET 2
  165. #define MACB_OVR_SIZE 1
  166. /* Bitfields in ISR/IER/IDR/IMR */
  167. #define MACB_MFD_OFFSET 0
  168. #define MACB_MFD_SIZE 1
  169. #define MACB_RCOMP_OFFSET 1
  170. #define MACB_RCOMP_SIZE 1
  171. #define MACB_RXUBR_OFFSET 2
  172. #define MACB_RXUBR_SIZE 1
  173. #define MACB_TXUBR_OFFSET 3
  174. #define MACB_TXUBR_SIZE 1
  175. #define MACB_ISR_TUND_OFFSET 4
  176. #define MACB_ISR_TUND_SIZE 1
  177. #define MACB_ISR_RLE_OFFSET 5
  178. #define MACB_ISR_RLE_SIZE 1
  179. #define MACB_TXERR_OFFSET 6
  180. #define MACB_TXERR_SIZE 1
  181. #define MACB_TCOMP_OFFSET 7
  182. #define MACB_TCOMP_SIZE 1
  183. #define MACB_ISR_LINK_OFFSET 9
  184. #define MACB_ISR_LINK_SIZE 1
  185. #define MACB_ISR_ROVR_OFFSET 10
  186. #define MACB_ISR_ROVR_SIZE 1
  187. #define MACB_HRESP_OFFSET 11
  188. #define MACB_HRESP_SIZE 1
  189. #define MACB_PFR_OFFSET 12
  190. #define MACB_PFR_SIZE 1
  191. #define MACB_PTZ_OFFSET 13
  192. #define MACB_PTZ_SIZE 1
  193. /* Bitfields in MAN */
  194. #define MACB_DATA_OFFSET 0
  195. #define MACB_DATA_SIZE 16
  196. #define MACB_CODE_OFFSET 16
  197. #define MACB_CODE_SIZE 2
  198. #define MACB_REGA_OFFSET 18
  199. #define MACB_REGA_SIZE 5
  200. #define MACB_PHYA_OFFSET 23
  201. #define MACB_PHYA_SIZE 5
  202. #define MACB_RW_OFFSET 28
  203. #define MACB_RW_SIZE 2
  204. #define MACB_SOF_OFFSET 30
  205. #define MACB_SOF_SIZE 2
  206. /* Bitfields in USRIO (AVR32) */
  207. #define MACB_MII_OFFSET 0
  208. #define MACB_MII_SIZE 1
  209. #define MACB_EAM_OFFSET 1
  210. #define MACB_EAM_SIZE 1
  211. #define MACB_TX_PAUSE_OFFSET 2
  212. #define MACB_TX_PAUSE_SIZE 1
  213. #define MACB_TX_PAUSE_ZERO_OFFSET 3
  214. #define MACB_TX_PAUSE_ZERO_SIZE 1
  215. /* Bitfields in USRIO (AT91) */
  216. #define MACB_RMII_OFFSET 0
  217. #define MACB_RMII_SIZE 1
  218. #define MACB_CLKEN_OFFSET 1
  219. #define MACB_CLKEN_SIZE 1
  220. /* Bitfields in WOL */
  221. #define MACB_IP_OFFSET 0
  222. #define MACB_IP_SIZE 16
  223. #define MACB_MAG_OFFSET 16
  224. #define MACB_MAG_SIZE 1
  225. #define MACB_ARP_OFFSET 17
  226. #define MACB_ARP_SIZE 1
  227. #define MACB_SA1_OFFSET 18
  228. #define MACB_SA1_SIZE 1
  229. #define MACB_WOL_MTI_OFFSET 19
  230. #define MACB_WOL_MTI_SIZE 1
  231. /* Bitfields in MID */
  232. #define MACB_IDNUM_OFFSET 16
  233. #define MACB_IDNUM_SIZE 16
  234. #define MACB_REV_OFFSET 0
  235. #define MACB_REV_SIZE 16
  236. /* Constants for CLK */
  237. #define MACB_CLK_DIV8 0
  238. #define MACB_CLK_DIV16 1
  239. #define MACB_CLK_DIV32 2
  240. #define MACB_CLK_DIV64 3
  241. /* GEM specific constants for CLK. */
  242. #define GEM_CLK_DIV8 0
  243. #define GEM_CLK_DIV16 1
  244. #define GEM_CLK_DIV32 2
  245. #define GEM_CLK_DIV48 3
  246. #define GEM_CLK_DIV64 4
  247. #define GEM_CLK_DIV96 5
  248. /* Constants for MAN register */
  249. #define MACB_MAN_SOF 1
  250. #define MACB_MAN_WRITE 1
  251. #define MACB_MAN_READ 2
  252. #define MACB_MAN_CODE 2
  253. /* Bit manipulation macros */
  254. #define MACB_BIT(name) \
  255. (1 << MACB_##name##_OFFSET)
  256. #define MACB_BF(name,value) \
  257. (((value) & ((1 << MACB_##name##_SIZE) - 1)) \
  258. << MACB_##name##_OFFSET)
  259. #define MACB_BFEXT(name,value)\
  260. (((value) >> MACB_##name##_OFFSET) \
  261. & ((1 << MACB_##name##_SIZE) - 1))
  262. #define MACB_BFINS(name,value,old) \
  263. (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \
  264. << MACB_##name##_OFFSET)) \
  265. | MACB_BF(name,value))
  266. #define GEM_BIT(name) \
  267. (1 << GEM_##name##_OFFSET)
  268. #define GEM_BF(name, value) \
  269. (((value) & ((1 << GEM_##name##_SIZE) - 1)) \
  270. << GEM_##name##_OFFSET)
  271. #define GEM_BFEXT(name, value)\
  272. (((value) >> GEM_##name##_OFFSET) \
  273. & ((1 << GEM_##name##_SIZE) - 1))
  274. #define GEM_BFINS(name, value, old) \
  275. (((old) & ~(((1 << GEM_##name##_SIZE) - 1) \
  276. << GEM_##name##_OFFSET)) \
  277. | GEM_BF(name, value))
  278. /* Register access macros */
  279. #define macb_readl(port,reg) \
  280. __raw_readl((port)->regs + MACB_##reg)
  281. #define macb_writel(port,reg,value) \
  282. __raw_writel((value), (port)->regs + MACB_##reg)
  283. #define gem_readl(port, reg) \
  284. __raw_readl((port)->regs + GEM_##reg)
  285. #define gem_writel(port, reg, value) \
  286. __raw_writel((value), (port)->regs + GEM_##reg)
  287. /*
  288. * Conditional GEM/MACB macros. These perform the operation to the correct
  289. * register dependent on whether the device is a GEM or a MACB. For registers
  290. * and bitfields that are common across both devices, use macb_{read,write}l
  291. * to avoid the cost of the conditional.
  292. */
  293. #define macb_or_gem_writel(__bp, __reg, __value) \
  294. ({ \
  295. if (macb_is_gem((__bp))) \
  296. gem_writel((__bp), __reg, __value); \
  297. else \
  298. macb_writel((__bp), __reg, __value); \
  299. })
  300. #define macb_or_gem_readl(__bp, __reg) \
  301. ({ \
  302. u32 __v; \
  303. if (macb_is_gem((__bp))) \
  304. __v = gem_readl((__bp), __reg); \
  305. else \
  306. __v = macb_readl((__bp), __reg); \
  307. __v; \
  308. })
  309. struct dma_desc {
  310. u32 addr;
  311. u32 ctrl;
  312. };
  313. /* DMA descriptor bitfields */
  314. #define MACB_RX_USED_OFFSET 0
  315. #define MACB_RX_USED_SIZE 1
  316. #define MACB_RX_WRAP_OFFSET 1
  317. #define MACB_RX_WRAP_SIZE 1
  318. #define MACB_RX_WADDR_OFFSET 2
  319. #define MACB_RX_WADDR_SIZE 30
  320. #define MACB_RX_FRMLEN_OFFSET 0
  321. #define MACB_RX_FRMLEN_SIZE 12
  322. #define MACB_RX_OFFSET_OFFSET 12
  323. #define MACB_RX_OFFSET_SIZE 2
  324. #define MACB_RX_SOF_OFFSET 14
  325. #define MACB_RX_SOF_SIZE 1
  326. #define MACB_RX_EOF_OFFSET 15
  327. #define MACB_RX_EOF_SIZE 1
  328. #define MACB_RX_CFI_OFFSET 16
  329. #define MACB_RX_CFI_SIZE 1
  330. #define MACB_RX_VLAN_PRI_OFFSET 17
  331. #define MACB_RX_VLAN_PRI_SIZE 3
  332. #define MACB_RX_PRI_TAG_OFFSET 20
  333. #define MACB_RX_PRI_TAG_SIZE 1
  334. #define MACB_RX_VLAN_TAG_OFFSET 21
  335. #define MACB_RX_VLAN_TAG_SIZE 1
  336. #define MACB_RX_TYPEID_MATCH_OFFSET 22
  337. #define MACB_RX_TYPEID_MATCH_SIZE 1
  338. #define MACB_RX_SA4_MATCH_OFFSET 23
  339. #define MACB_RX_SA4_MATCH_SIZE 1
  340. #define MACB_RX_SA3_MATCH_OFFSET 24
  341. #define MACB_RX_SA3_MATCH_SIZE 1
  342. #define MACB_RX_SA2_MATCH_OFFSET 25
  343. #define MACB_RX_SA2_MATCH_SIZE 1
  344. #define MACB_RX_SA1_MATCH_OFFSET 26
  345. #define MACB_RX_SA1_MATCH_SIZE 1
  346. #define MACB_RX_EXT_MATCH_OFFSET 28
  347. #define MACB_RX_EXT_MATCH_SIZE 1
  348. #define MACB_RX_UHASH_MATCH_OFFSET 29
  349. #define MACB_RX_UHASH_MATCH_SIZE 1
  350. #define MACB_RX_MHASH_MATCH_OFFSET 30
  351. #define MACB_RX_MHASH_MATCH_SIZE 1
  352. #define MACB_RX_BROADCAST_OFFSET 31
  353. #define MACB_RX_BROADCAST_SIZE 1
  354. #define MACB_TX_FRMLEN_OFFSET 0
  355. #define MACB_TX_FRMLEN_SIZE 11
  356. #define MACB_TX_LAST_OFFSET 15
  357. #define MACB_TX_LAST_SIZE 1
  358. #define MACB_TX_NOCRC_OFFSET 16
  359. #define MACB_TX_NOCRC_SIZE 1
  360. #define MACB_TX_BUF_EXHAUSTED_OFFSET 27
  361. #define MACB_TX_BUF_EXHAUSTED_SIZE 1
  362. #define MACB_TX_UNDERRUN_OFFSET 28
  363. #define MACB_TX_UNDERRUN_SIZE 1
  364. #define MACB_TX_ERROR_OFFSET 29
  365. #define MACB_TX_ERROR_SIZE 1
  366. #define MACB_TX_WRAP_OFFSET 30
  367. #define MACB_TX_WRAP_SIZE 1
  368. #define MACB_TX_USED_OFFSET 31
  369. #define MACB_TX_USED_SIZE 1
  370. struct ring_info {
  371. struct sk_buff *skb;
  372. dma_addr_t mapping;
  373. };
  374. /*
  375. * Hardware-collected statistics. Used when updating the network
  376. * device stats by a periodic timer.
  377. */
  378. struct macb_stats {
  379. u32 rx_pause_frames;
  380. u32 tx_ok;
  381. u32 tx_single_cols;
  382. u32 tx_multiple_cols;
  383. u32 rx_ok;
  384. u32 rx_fcs_errors;
  385. u32 rx_align_errors;
  386. u32 tx_deferred;
  387. u32 tx_late_cols;
  388. u32 tx_excessive_cols;
  389. u32 tx_underruns;
  390. u32 tx_carrier_errors;
  391. u32 rx_resource_errors;
  392. u32 rx_overruns;
  393. u32 rx_symbol_errors;
  394. u32 rx_oversize_pkts;
  395. u32 rx_jabbers;
  396. u32 rx_undersize_pkts;
  397. u32 sqe_test_errors;
  398. u32 rx_length_mismatch;
  399. u32 tx_pause_frames;
  400. };
  401. struct gem_stats {
  402. u32 tx_octets_31_0;
  403. u32 tx_octets_47_32;
  404. u32 tx_frames;
  405. u32 tx_broadcast_frames;
  406. u32 tx_multicast_frames;
  407. u32 tx_pause_frames;
  408. u32 tx_64_byte_frames;
  409. u32 tx_65_127_byte_frames;
  410. u32 tx_128_255_byte_frames;
  411. u32 tx_256_511_byte_frames;
  412. u32 tx_512_1023_byte_frames;
  413. u32 tx_1024_1518_byte_frames;
  414. u32 tx_greater_than_1518_byte_frames;
  415. u32 tx_underrun;
  416. u32 tx_single_collision_frames;
  417. u32 tx_multiple_collision_frames;
  418. u32 tx_excessive_collisions;
  419. u32 tx_late_collisions;
  420. u32 tx_deferred_frames;
  421. u32 tx_carrier_sense_errors;
  422. u32 rx_octets_31_0;
  423. u32 rx_octets_47_32;
  424. u32 rx_frames;
  425. u32 rx_broadcast_frames;
  426. u32 rx_multicast_frames;
  427. u32 rx_pause_frames;
  428. u32 rx_64_byte_frames;
  429. u32 rx_65_127_byte_frames;
  430. u32 rx_128_255_byte_frames;
  431. u32 rx_256_511_byte_frames;
  432. u32 rx_512_1023_byte_frames;
  433. u32 rx_1024_1518_byte_frames;
  434. u32 rx_greater_than_1518_byte_frames;
  435. u32 rx_undersized_frames;
  436. u32 rx_oversize_frames;
  437. u32 rx_jabbers;
  438. u32 rx_frame_check_sequence_errors;
  439. u32 rx_length_field_frame_errors;
  440. u32 rx_symbol_errors;
  441. u32 rx_alignment_errors;
  442. u32 rx_resource_errors;
  443. u32 rx_overruns;
  444. u32 rx_ip_header_checksum_errors;
  445. u32 rx_tcp_checksum_errors;
  446. u32 rx_udp_checksum_errors;
  447. };
  448. struct macb {
  449. void __iomem *regs;
  450. unsigned int rx_tail;
  451. struct dma_desc *rx_ring;
  452. void *rx_buffers;
  453. unsigned int tx_head, tx_tail;
  454. struct dma_desc *tx_ring;
  455. struct ring_info *tx_skb;
  456. spinlock_t lock;
  457. struct platform_device *pdev;
  458. struct clk *pclk;
  459. struct clk *hclk;
  460. struct net_device *dev;
  461. struct napi_struct napi;
  462. struct net_device_stats stats;
  463. union {
  464. struct macb_stats macb;
  465. struct gem_stats gem;
  466. } hw_stats;
  467. dma_addr_t rx_ring_dma;
  468. dma_addr_t tx_ring_dma;
  469. dma_addr_t rx_buffers_dma;
  470. unsigned int rx_pending, tx_pending;
  471. struct mii_bus *mii_bus;
  472. struct phy_device *phy_dev;
  473. unsigned int link;
  474. unsigned int speed;
  475. unsigned int duplex;
  476. };
  477. static inline bool macb_is_gem(struct macb *bp)
  478. {
  479. return MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2;
  480. }
  481. #endif /* _MACB_H */