xref: /linux/drivers/net/ethernet/cadence/macb.h (revision 4df95131ea803bcb94f472d465c73ed57015c470)
19f2f381fSJeff Kirsher /*
29f2f381fSJeff Kirsher  * Atmel MACB Ethernet Controller driver
39f2f381fSJeff Kirsher  *
49f2f381fSJeff Kirsher  * Copyright (C) 2004-2006 Atmel Corporation
59f2f381fSJeff Kirsher  *
69f2f381fSJeff Kirsher  * This program is free software; you can redistribute it and/or modify
79f2f381fSJeff Kirsher  * it under the terms of the GNU General Public License version 2 as
89f2f381fSJeff Kirsher  * published by the Free Software Foundation.
99f2f381fSJeff Kirsher  */
109f2f381fSJeff Kirsher #ifndef _MACB_H
119f2f381fSJeff Kirsher #define _MACB_H
129f2f381fSJeff Kirsher 
13d1d1b53dSNicolas Ferre #define MACB_GREGS_NBR 16
14d1d1b53dSNicolas Ferre #define MACB_GREGS_VERSION 1
15d1d1b53dSNicolas Ferre 
169f2f381fSJeff Kirsher /* MACB register offsets */
179f2f381fSJeff Kirsher #define MACB_NCR				0x0000
189f2f381fSJeff Kirsher #define MACB_NCFGR				0x0004
199f2f381fSJeff Kirsher #define MACB_NSR				0x0008
201fd3ca4eSJoachim Eastwood #define MACB_TAR				0x000c /* AT91RM9200 only */
211fd3ca4eSJoachim Eastwood #define MACB_TCR				0x0010 /* AT91RM9200 only */
229f2f381fSJeff Kirsher #define MACB_TSR				0x0014
239f2f381fSJeff Kirsher #define MACB_RBQP				0x0018
249f2f381fSJeff Kirsher #define MACB_TBQP				0x001c
259f2f381fSJeff Kirsher #define MACB_RSR				0x0020
269f2f381fSJeff Kirsher #define MACB_ISR				0x0024
279f2f381fSJeff Kirsher #define MACB_IER				0x0028
289f2f381fSJeff Kirsher #define MACB_IDR				0x002c
299f2f381fSJeff Kirsher #define MACB_IMR				0x0030
309f2f381fSJeff Kirsher #define MACB_MAN				0x0034
319f2f381fSJeff Kirsher #define MACB_PTR				0x0038
329f2f381fSJeff Kirsher #define MACB_PFR				0x003c
339f2f381fSJeff Kirsher #define MACB_FTO				0x0040
349f2f381fSJeff Kirsher #define MACB_SCF				0x0044
359f2f381fSJeff Kirsher #define MACB_MCF				0x0048
369f2f381fSJeff Kirsher #define MACB_FRO				0x004c
379f2f381fSJeff Kirsher #define MACB_FCSE				0x0050
389f2f381fSJeff Kirsher #define MACB_ALE				0x0054
399f2f381fSJeff Kirsher #define MACB_DTF				0x0058
409f2f381fSJeff Kirsher #define MACB_LCOL				0x005c
419f2f381fSJeff Kirsher #define MACB_EXCOL				0x0060
429f2f381fSJeff Kirsher #define MACB_TUND				0x0064
439f2f381fSJeff Kirsher #define MACB_CSE				0x0068
449f2f381fSJeff Kirsher #define MACB_RRE				0x006c
459f2f381fSJeff Kirsher #define MACB_ROVR				0x0070
469f2f381fSJeff Kirsher #define MACB_RSE				0x0074
479f2f381fSJeff Kirsher #define MACB_ELE				0x0078
489f2f381fSJeff Kirsher #define MACB_RJA				0x007c
499f2f381fSJeff Kirsher #define MACB_USF				0x0080
509f2f381fSJeff Kirsher #define MACB_STE				0x0084
519f2f381fSJeff Kirsher #define MACB_RLE				0x0088
529f2f381fSJeff Kirsher #define MACB_TPF				0x008c
539f2f381fSJeff Kirsher #define MACB_HRB				0x0090
549f2f381fSJeff Kirsher #define MACB_HRT				0x0094
559f2f381fSJeff Kirsher #define MACB_SA1B				0x0098
569f2f381fSJeff Kirsher #define MACB_SA1T				0x009c
579f2f381fSJeff Kirsher #define MACB_SA2B				0x00a0
589f2f381fSJeff Kirsher #define MACB_SA2T				0x00a4
599f2f381fSJeff Kirsher #define MACB_SA3B				0x00a8
609f2f381fSJeff Kirsher #define MACB_SA3T				0x00ac
619f2f381fSJeff Kirsher #define MACB_SA4B				0x00b0
629f2f381fSJeff Kirsher #define MACB_SA4T				0x00b4
639f2f381fSJeff Kirsher #define MACB_TID				0x00b8
649f2f381fSJeff Kirsher #define MACB_TPQ				0x00bc
659f2f381fSJeff Kirsher #define MACB_USRIO				0x00c0
669f2f381fSJeff Kirsher #define MACB_WOL				0x00c4
67f75ba50bSJamie Iles #define MACB_MID				0x00fc
68f75ba50bSJamie Iles 
69f75ba50bSJamie Iles /* GEM register offsets. */
70f75ba50bSJamie Iles #define GEM_NCFGR				0x0004
71f75ba50bSJamie Iles #define GEM_USRIO				0x000c
720116da4fSJamie Iles #define GEM_DMACFG				0x0010
73f75ba50bSJamie Iles #define GEM_HRB					0x0080
74f75ba50bSJamie Iles #define GEM_HRT					0x0084
75f75ba50bSJamie Iles #define GEM_SA1B				0x0088
76f75ba50bSJamie Iles #define GEM_SA1T				0x008C
773629a6ceSJoachim Eastwood #define GEM_SA2B				0x0090
783629a6ceSJoachim Eastwood #define GEM_SA2T				0x0094
793629a6ceSJoachim Eastwood #define GEM_SA3B				0x0098
803629a6ceSJoachim Eastwood #define GEM_SA3T				0x009C
813629a6ceSJoachim Eastwood #define GEM_SA4B				0x00A0
823629a6ceSJoachim Eastwood #define GEM_SA4T				0x00A4
83a494ed8eSJamie Iles #define GEM_OTX					0x0100
84757a03c6SJamie Iles #define GEM_DCFG1				0x0280
85757a03c6SJamie Iles #define GEM_DCFG2				0x0284
86757a03c6SJamie Iles #define GEM_DCFG3				0x0288
87757a03c6SJamie Iles #define GEM_DCFG4				0x028c
88757a03c6SJamie Iles #define GEM_DCFG5				0x0290
89757a03c6SJamie Iles #define GEM_DCFG6				0x0294
90757a03c6SJamie Iles #define GEM_DCFG7				0x0298
919f2f381fSJeff Kirsher 
929f2f381fSJeff Kirsher /* Bitfields in NCR */
939f2f381fSJeff Kirsher #define MACB_LB_OFFSET				0
949f2f381fSJeff Kirsher #define MACB_LB_SIZE				1
959f2f381fSJeff Kirsher #define MACB_LLB_OFFSET				1
969f2f381fSJeff Kirsher #define MACB_LLB_SIZE				1
979f2f381fSJeff Kirsher #define MACB_RE_OFFSET				2
989f2f381fSJeff Kirsher #define MACB_RE_SIZE				1
999f2f381fSJeff Kirsher #define MACB_TE_OFFSET				3
1009f2f381fSJeff Kirsher #define MACB_TE_SIZE				1
1019f2f381fSJeff Kirsher #define MACB_MPE_OFFSET				4
1029f2f381fSJeff Kirsher #define MACB_MPE_SIZE				1
1039f2f381fSJeff Kirsher #define MACB_CLRSTAT_OFFSET			5
1049f2f381fSJeff Kirsher #define MACB_CLRSTAT_SIZE			1
1059f2f381fSJeff Kirsher #define MACB_INCSTAT_OFFSET			6
1069f2f381fSJeff Kirsher #define MACB_INCSTAT_SIZE			1
1079f2f381fSJeff Kirsher #define MACB_WESTAT_OFFSET			7
1089f2f381fSJeff Kirsher #define MACB_WESTAT_SIZE			1
1099f2f381fSJeff Kirsher #define MACB_BP_OFFSET				8
1109f2f381fSJeff Kirsher #define MACB_BP_SIZE				1
1119f2f381fSJeff Kirsher #define MACB_TSTART_OFFSET			9
1129f2f381fSJeff Kirsher #define MACB_TSTART_SIZE			1
1139f2f381fSJeff Kirsher #define MACB_THALT_OFFSET			10
1149f2f381fSJeff Kirsher #define MACB_THALT_SIZE				1
1159f2f381fSJeff Kirsher #define MACB_NCR_TPF_OFFSET			11
1169f2f381fSJeff Kirsher #define MACB_NCR_TPF_SIZE			1
1179f2f381fSJeff Kirsher #define MACB_TZQ_OFFSET				12
1189f2f381fSJeff Kirsher #define MACB_TZQ_SIZE				1
1199f2f381fSJeff Kirsher 
1209f2f381fSJeff Kirsher /* Bitfields in NCFGR */
1219f2f381fSJeff Kirsher #define MACB_SPD_OFFSET				0
1229f2f381fSJeff Kirsher #define MACB_SPD_SIZE				1
1239f2f381fSJeff Kirsher #define MACB_FD_OFFSET				1
1249f2f381fSJeff Kirsher #define MACB_FD_SIZE				1
1259f2f381fSJeff Kirsher #define MACB_BIT_RATE_OFFSET			2
1269f2f381fSJeff Kirsher #define MACB_BIT_RATE_SIZE			1
1279f2f381fSJeff Kirsher #define MACB_JFRAME_OFFSET			3
1289f2f381fSJeff Kirsher #define MACB_JFRAME_SIZE			1
1299f2f381fSJeff Kirsher #define MACB_CAF_OFFSET				4
1309f2f381fSJeff Kirsher #define MACB_CAF_SIZE				1
1319f2f381fSJeff Kirsher #define MACB_NBC_OFFSET				5
1329f2f381fSJeff Kirsher #define MACB_NBC_SIZE				1
1339f2f381fSJeff Kirsher #define MACB_NCFGR_MTI_OFFSET			6
1349f2f381fSJeff Kirsher #define MACB_NCFGR_MTI_SIZE			1
1359f2f381fSJeff Kirsher #define MACB_UNI_OFFSET				7
1369f2f381fSJeff Kirsher #define MACB_UNI_SIZE				1
1379f2f381fSJeff Kirsher #define MACB_BIG_OFFSET				8
1389f2f381fSJeff Kirsher #define MACB_BIG_SIZE				1
1399f2f381fSJeff Kirsher #define MACB_EAE_OFFSET				9
1409f2f381fSJeff Kirsher #define MACB_EAE_SIZE				1
1419f2f381fSJeff Kirsher #define MACB_CLK_OFFSET				10
1429f2f381fSJeff Kirsher #define MACB_CLK_SIZE				2
1439f2f381fSJeff Kirsher #define MACB_RTY_OFFSET				12
1449f2f381fSJeff Kirsher #define MACB_RTY_SIZE				1
1459f2f381fSJeff Kirsher #define MACB_PAE_OFFSET				13
1469f2f381fSJeff Kirsher #define MACB_PAE_SIZE				1
1471fd3ca4eSJoachim Eastwood #define MACB_RM9200_RMII_OFFSET			13 /* AT91RM9200 only */
1481fd3ca4eSJoachim Eastwood #define MACB_RM9200_RMII_SIZE			1  /* AT91RM9200 only */
1499f2f381fSJeff Kirsher #define MACB_RBOF_OFFSET			14
1509f2f381fSJeff Kirsher #define MACB_RBOF_SIZE				2
1519f2f381fSJeff Kirsher #define MACB_RLCE_OFFSET			16
1529f2f381fSJeff Kirsher #define MACB_RLCE_SIZE				1
1539f2f381fSJeff Kirsher #define MACB_DRFCS_OFFSET			17
1549f2f381fSJeff Kirsher #define MACB_DRFCS_SIZE				1
1559f2f381fSJeff Kirsher #define MACB_EFRHD_OFFSET			18
1569f2f381fSJeff Kirsher #define MACB_EFRHD_SIZE				1
1579f2f381fSJeff Kirsher #define MACB_IRXFCS_OFFSET			19
1589f2f381fSJeff Kirsher #define MACB_IRXFCS_SIZE			1
1599f2f381fSJeff Kirsher 
16070c9f3d4SJamie Iles /* GEM specific NCFGR bitfields. */
161140b7552SPatrice Vilchez #define GEM_GBE_OFFSET				10
162140b7552SPatrice Vilchez #define GEM_GBE_SIZE				1
16370c9f3d4SJamie Iles #define GEM_CLK_OFFSET				18
16470c9f3d4SJamie Iles #define GEM_CLK_SIZE				3
165757a03c6SJamie Iles #define GEM_DBW_OFFSET				21
166757a03c6SJamie Iles #define GEM_DBW_SIZE				2
167757a03c6SJamie Iles 
168757a03c6SJamie Iles /* Constants for data bus width. */
169757a03c6SJamie Iles #define GEM_DBW32				0
170757a03c6SJamie Iles #define GEM_DBW64				1
171757a03c6SJamie Iles #define GEM_DBW128				2
172757a03c6SJamie Iles 
1730116da4fSJamie Iles /* Bitfields in DMACFG. */
174b3e3bd71SNicolas Ferre #define GEM_FBLDO_OFFSET			0
175b3e3bd71SNicolas Ferre #define GEM_FBLDO_SIZE				5
176a1ae385dSSteffen Trumtrar #define GEM_ENDIA_OFFSET			7
177a1ae385dSSteffen Trumtrar #define GEM_ENDIA_SIZE				1
178b3e3bd71SNicolas Ferre #define GEM_RXBMS_OFFSET			8
179b3e3bd71SNicolas Ferre #define GEM_RXBMS_SIZE				2
180b3e3bd71SNicolas Ferre #define GEM_TXPBMS_OFFSET			10
181b3e3bd71SNicolas Ferre #define GEM_TXPBMS_SIZE				1
182b3e3bd71SNicolas Ferre #define GEM_TXCOEN_OFFSET			11
183b3e3bd71SNicolas Ferre #define GEM_TXCOEN_SIZE				1
1840116da4fSJamie Iles #define GEM_RXBS_OFFSET				16
1850116da4fSJamie Iles #define GEM_RXBS_SIZE				8
186b3e3bd71SNicolas Ferre #define GEM_DDRP_OFFSET				24
187b3e3bd71SNicolas Ferre #define GEM_DDRP_SIZE				1
188b3e3bd71SNicolas Ferre 
1890116da4fSJamie Iles 
1909f2f381fSJeff Kirsher /* Bitfields in NSR */
1919f2f381fSJeff Kirsher #define MACB_NSR_LINK_OFFSET			0
1929f2f381fSJeff Kirsher #define MACB_NSR_LINK_SIZE			1
1939f2f381fSJeff Kirsher #define MACB_MDIO_OFFSET			1
1949f2f381fSJeff Kirsher #define MACB_MDIO_SIZE				1
1959f2f381fSJeff Kirsher #define MACB_IDLE_OFFSET			2
1969f2f381fSJeff Kirsher #define MACB_IDLE_SIZE				1
1979f2f381fSJeff Kirsher 
1989f2f381fSJeff Kirsher /* Bitfields in TSR */
1999f2f381fSJeff Kirsher #define MACB_UBR_OFFSET				0
2009f2f381fSJeff Kirsher #define MACB_UBR_SIZE				1
2019f2f381fSJeff Kirsher #define MACB_COL_OFFSET				1
2029f2f381fSJeff Kirsher #define MACB_COL_SIZE				1
2039f2f381fSJeff Kirsher #define MACB_TSR_RLE_OFFSET			2
2049f2f381fSJeff Kirsher #define MACB_TSR_RLE_SIZE			1
2059f2f381fSJeff Kirsher #define MACB_TGO_OFFSET				3
2069f2f381fSJeff Kirsher #define MACB_TGO_SIZE				1
2079f2f381fSJeff Kirsher #define MACB_BEX_OFFSET				4
2089f2f381fSJeff Kirsher #define MACB_BEX_SIZE				1
2091fd3ca4eSJoachim Eastwood #define MACB_RM9200_BNQ_OFFSET			4 /* AT91RM9200 only */
2101fd3ca4eSJoachim Eastwood #define MACB_RM9200_BNQ_SIZE			1 /* AT91RM9200 only */
2119f2f381fSJeff Kirsher #define MACB_COMP_OFFSET			5
2129f2f381fSJeff Kirsher #define MACB_COMP_SIZE				1
2139f2f381fSJeff Kirsher #define MACB_UND_OFFSET				6
2149f2f381fSJeff Kirsher #define MACB_UND_SIZE				1
2159f2f381fSJeff Kirsher 
2169f2f381fSJeff Kirsher /* Bitfields in RSR */
2179f2f381fSJeff Kirsher #define MACB_BNA_OFFSET				0
2189f2f381fSJeff Kirsher #define MACB_BNA_SIZE				1
2199f2f381fSJeff Kirsher #define MACB_REC_OFFSET				1
2209f2f381fSJeff Kirsher #define MACB_REC_SIZE				1
2219f2f381fSJeff Kirsher #define MACB_OVR_OFFSET				2
2229f2f381fSJeff Kirsher #define MACB_OVR_SIZE				1
2239f2f381fSJeff Kirsher 
2249f2f381fSJeff Kirsher /* Bitfields in ISR/IER/IDR/IMR */
2259f2f381fSJeff Kirsher #define MACB_MFD_OFFSET				0
2269f2f381fSJeff Kirsher #define MACB_MFD_SIZE				1
2279f2f381fSJeff Kirsher #define MACB_RCOMP_OFFSET			1
2289f2f381fSJeff Kirsher #define MACB_RCOMP_SIZE				1
2299f2f381fSJeff Kirsher #define MACB_RXUBR_OFFSET			2
2309f2f381fSJeff Kirsher #define MACB_RXUBR_SIZE				1
2319f2f381fSJeff Kirsher #define MACB_TXUBR_OFFSET			3
2329f2f381fSJeff Kirsher #define MACB_TXUBR_SIZE				1
2339f2f381fSJeff Kirsher #define MACB_ISR_TUND_OFFSET			4
2349f2f381fSJeff Kirsher #define MACB_ISR_TUND_SIZE			1
2359f2f381fSJeff Kirsher #define MACB_ISR_RLE_OFFSET			5
2369f2f381fSJeff Kirsher #define MACB_ISR_RLE_SIZE			1
2379f2f381fSJeff Kirsher #define MACB_TXERR_OFFSET			6
2389f2f381fSJeff Kirsher #define MACB_TXERR_SIZE				1
2399f2f381fSJeff Kirsher #define MACB_TCOMP_OFFSET			7
2409f2f381fSJeff Kirsher #define MACB_TCOMP_SIZE				1
2419f2f381fSJeff Kirsher #define MACB_ISR_LINK_OFFSET			9
2429f2f381fSJeff Kirsher #define MACB_ISR_LINK_SIZE			1
2439f2f381fSJeff Kirsher #define MACB_ISR_ROVR_OFFSET			10
2449f2f381fSJeff Kirsher #define MACB_ISR_ROVR_SIZE			1
2459f2f381fSJeff Kirsher #define MACB_HRESP_OFFSET			11
2469f2f381fSJeff Kirsher #define MACB_HRESP_SIZE				1
2479f2f381fSJeff Kirsher #define MACB_PFR_OFFSET				12
2489f2f381fSJeff Kirsher #define MACB_PFR_SIZE				1
2499f2f381fSJeff Kirsher #define MACB_PTZ_OFFSET				13
2509f2f381fSJeff Kirsher #define MACB_PTZ_SIZE				1
2519f2f381fSJeff Kirsher 
2529f2f381fSJeff Kirsher /* Bitfields in MAN */
2539f2f381fSJeff Kirsher #define MACB_DATA_OFFSET			0
2549f2f381fSJeff Kirsher #define MACB_DATA_SIZE				16
2559f2f381fSJeff Kirsher #define MACB_CODE_OFFSET			16
2569f2f381fSJeff Kirsher #define MACB_CODE_SIZE				2
2579f2f381fSJeff Kirsher #define MACB_REGA_OFFSET			18
2589f2f381fSJeff Kirsher #define MACB_REGA_SIZE				5
2599f2f381fSJeff Kirsher #define MACB_PHYA_OFFSET			23
2609f2f381fSJeff Kirsher #define MACB_PHYA_SIZE				5
2619f2f381fSJeff Kirsher #define MACB_RW_OFFSET				28
2629f2f381fSJeff Kirsher #define MACB_RW_SIZE				2
2639f2f381fSJeff Kirsher #define MACB_SOF_OFFSET				30
2649f2f381fSJeff Kirsher #define MACB_SOF_SIZE				2
2659f2f381fSJeff Kirsher 
2669f2f381fSJeff Kirsher /* Bitfields in USRIO (AVR32) */
2679f2f381fSJeff Kirsher #define MACB_MII_OFFSET				0
2689f2f381fSJeff Kirsher #define MACB_MII_SIZE				1
2699f2f381fSJeff Kirsher #define MACB_EAM_OFFSET				1
2709f2f381fSJeff Kirsher #define MACB_EAM_SIZE				1
2719f2f381fSJeff Kirsher #define MACB_TX_PAUSE_OFFSET			2
2729f2f381fSJeff Kirsher #define MACB_TX_PAUSE_SIZE			1
2739f2f381fSJeff Kirsher #define MACB_TX_PAUSE_ZERO_OFFSET		3
2749f2f381fSJeff Kirsher #define MACB_TX_PAUSE_ZERO_SIZE			1
2759f2f381fSJeff Kirsher 
2769f2f381fSJeff Kirsher /* Bitfields in USRIO (AT91) */
2779f2f381fSJeff Kirsher #define MACB_RMII_OFFSET			0
2789f2f381fSJeff Kirsher #define MACB_RMII_SIZE				1
279140b7552SPatrice Vilchez #define GEM_RGMII_OFFSET			0	/* GEM gigabit mode */
280140b7552SPatrice Vilchez #define GEM_RGMII_SIZE				1
2819f2f381fSJeff Kirsher #define MACB_CLKEN_OFFSET			1
2829f2f381fSJeff Kirsher #define MACB_CLKEN_SIZE				1
2839f2f381fSJeff Kirsher 
2849f2f381fSJeff Kirsher /* Bitfields in WOL */
2859f2f381fSJeff Kirsher #define MACB_IP_OFFSET				0
2869f2f381fSJeff Kirsher #define MACB_IP_SIZE				16
2879f2f381fSJeff Kirsher #define MACB_MAG_OFFSET				16
2889f2f381fSJeff Kirsher #define MACB_MAG_SIZE				1
2899f2f381fSJeff Kirsher #define MACB_ARP_OFFSET				17
2909f2f381fSJeff Kirsher #define MACB_ARP_SIZE				1
2919f2f381fSJeff Kirsher #define MACB_SA1_OFFSET				18
2929f2f381fSJeff Kirsher #define MACB_SA1_SIZE				1
2939f2f381fSJeff Kirsher #define MACB_WOL_MTI_OFFSET			19
2949f2f381fSJeff Kirsher #define MACB_WOL_MTI_SIZE			1
2959f2f381fSJeff Kirsher 
296f75ba50bSJamie Iles /* Bitfields in MID */
297f75ba50bSJamie Iles #define MACB_IDNUM_OFFSET			16
298f75ba50bSJamie Iles #define MACB_IDNUM_SIZE				16
299f75ba50bSJamie Iles #define MACB_REV_OFFSET				0
300f75ba50bSJamie Iles #define MACB_REV_SIZE				16
301f75ba50bSJamie Iles 
302757a03c6SJamie Iles /* Bitfields in DCFG1. */
303581df9e1SNicolas Ferre #define GEM_IRQCOR_OFFSET			23
304581df9e1SNicolas Ferre #define GEM_IRQCOR_SIZE				1
305757a03c6SJamie Iles #define GEM_DBWDEF_OFFSET			25
306757a03c6SJamie Iles #define GEM_DBWDEF_SIZE				3
307757a03c6SJamie Iles 
3089f2f381fSJeff Kirsher /* Constants for CLK */
3099f2f381fSJeff Kirsher #define MACB_CLK_DIV8				0
3109f2f381fSJeff Kirsher #define MACB_CLK_DIV16				1
3119f2f381fSJeff Kirsher #define MACB_CLK_DIV32				2
3129f2f381fSJeff Kirsher #define MACB_CLK_DIV64				3
3139f2f381fSJeff Kirsher 
31470c9f3d4SJamie Iles /* GEM specific constants for CLK. */
31570c9f3d4SJamie Iles #define GEM_CLK_DIV8				0
31670c9f3d4SJamie Iles #define GEM_CLK_DIV16				1
31770c9f3d4SJamie Iles #define GEM_CLK_DIV32				2
31870c9f3d4SJamie Iles #define GEM_CLK_DIV48				3
31970c9f3d4SJamie Iles #define GEM_CLK_DIV64				4
32070c9f3d4SJamie Iles #define GEM_CLK_DIV96				5
32170c9f3d4SJamie Iles 
3229f2f381fSJeff Kirsher /* Constants for MAN register */
3239f2f381fSJeff Kirsher #define MACB_MAN_SOF				1
3249f2f381fSJeff Kirsher #define MACB_MAN_WRITE				1
3259f2f381fSJeff Kirsher #define MACB_MAN_READ				2
3269f2f381fSJeff Kirsher #define MACB_MAN_CODE				2
3279f2f381fSJeff Kirsher 
328581df9e1SNicolas Ferre /* Capability mask bits */
329581df9e1SNicolas Ferre #define MACB_CAPS_ISR_CLEAR_ON_WRITE		0x1
330581df9e1SNicolas Ferre 
3319f2f381fSJeff Kirsher /* Bit manipulation macros */
3329f2f381fSJeff Kirsher #define MACB_BIT(name)					\
3339f2f381fSJeff Kirsher 	(1 << MACB_##name##_OFFSET)
3349f2f381fSJeff Kirsher #define MACB_BF(name,value)				\
3359f2f381fSJeff Kirsher 	(((value) & ((1 << MACB_##name##_SIZE) - 1))	\
3369f2f381fSJeff Kirsher 	 << MACB_##name##_OFFSET)
3379f2f381fSJeff Kirsher #define MACB_BFEXT(name,value)\
3389f2f381fSJeff Kirsher 	(((value) >> MACB_##name##_OFFSET)		\
3399f2f381fSJeff Kirsher 	 & ((1 << MACB_##name##_SIZE) - 1))
3409f2f381fSJeff Kirsher #define MACB_BFINS(name,value,old)			\
3419f2f381fSJeff Kirsher 	(((old) & ~(((1 << MACB_##name##_SIZE) - 1)	\
3429f2f381fSJeff Kirsher 		    << MACB_##name##_OFFSET))		\
3439f2f381fSJeff Kirsher 	 | MACB_BF(name,value))
3449f2f381fSJeff Kirsher 
345f75ba50bSJamie Iles #define GEM_BIT(name)					\
346f75ba50bSJamie Iles 	(1 << GEM_##name##_OFFSET)
347f75ba50bSJamie Iles #define GEM_BF(name, value)				\
348f75ba50bSJamie Iles 	(((value) & ((1 << GEM_##name##_SIZE) - 1))	\
349f75ba50bSJamie Iles 	 << GEM_##name##_OFFSET)
350f75ba50bSJamie Iles #define GEM_BFEXT(name, value)\
351f75ba50bSJamie Iles 	(((value) >> GEM_##name##_OFFSET)		\
352f75ba50bSJamie Iles 	 & ((1 << GEM_##name##_SIZE) - 1))
353f75ba50bSJamie Iles #define GEM_BFINS(name, value, old)			\
354f75ba50bSJamie Iles 	(((old) & ~(((1 << GEM_##name##_SIZE) - 1)	\
355f75ba50bSJamie Iles 		    << GEM_##name##_OFFSET))		\
356f75ba50bSJamie Iles 	 | GEM_BF(name, value))
357f75ba50bSJamie Iles 
3589f2f381fSJeff Kirsher /* Register access macros */
3599f2f381fSJeff Kirsher #define macb_readl(port,reg)				\
3609f2f381fSJeff Kirsher 	__raw_readl((port)->regs + MACB_##reg)
3619f2f381fSJeff Kirsher #define macb_writel(port,reg,value)			\
3629f2f381fSJeff Kirsher 	__raw_writel((value), (port)->regs + MACB_##reg)
363f75ba50bSJamie Iles #define gem_readl(port, reg)				\
364f75ba50bSJamie Iles 	__raw_readl((port)->regs + GEM_##reg)
365f75ba50bSJamie Iles #define gem_writel(port, reg, value)			\
366f75ba50bSJamie Iles 	__raw_writel((value), (port)->regs + GEM_##reg)
367f75ba50bSJamie Iles 
368f75ba50bSJamie Iles /*
369f75ba50bSJamie Iles  * Conditional GEM/MACB macros.  These perform the operation to the correct
370f75ba50bSJamie Iles  * register dependent on whether the device is a GEM or a MACB.  For registers
371f75ba50bSJamie Iles  * and bitfields that are common across both devices, use macb_{read,write}l
372f75ba50bSJamie Iles  * to avoid the cost of the conditional.
373f75ba50bSJamie Iles  */
374f75ba50bSJamie Iles #define macb_or_gem_writel(__bp, __reg, __value) \
375f75ba50bSJamie Iles 	({ \
376f75ba50bSJamie Iles 		if (macb_is_gem((__bp))) \
377f75ba50bSJamie Iles 			gem_writel((__bp), __reg, __value); \
378f75ba50bSJamie Iles 		else \
379f75ba50bSJamie Iles 			macb_writel((__bp), __reg, __value); \
380f75ba50bSJamie Iles 	})
381f75ba50bSJamie Iles 
382f75ba50bSJamie Iles #define macb_or_gem_readl(__bp, __reg) \
383f75ba50bSJamie Iles 	({ \
384f75ba50bSJamie Iles 		u32 __v; \
385f75ba50bSJamie Iles 		if (macb_is_gem((__bp))) \
386f75ba50bSJamie Iles 			__v = gem_readl((__bp), __reg); \
387f75ba50bSJamie Iles 		else \
388f75ba50bSJamie Iles 			__v = macb_readl((__bp), __reg); \
389f75ba50bSJamie Iles 		__v; \
390f75ba50bSJamie Iles 	})
3919f2f381fSJeff Kirsher 
39255054a16SHavard Skinnemoen /**
39355054a16SHavard Skinnemoen  * struct macb_dma_desc - Hardware DMA descriptor
39455054a16SHavard Skinnemoen  * @addr: DMA address of data buffer
39555054a16SHavard Skinnemoen  * @ctrl: Control and status bits
39655054a16SHavard Skinnemoen  */
39755054a16SHavard Skinnemoen struct macb_dma_desc {
3989f2f381fSJeff Kirsher 	u32	addr;
3999f2f381fSJeff Kirsher 	u32	ctrl;
4009f2f381fSJeff Kirsher };
4019f2f381fSJeff Kirsher 
4029f2f381fSJeff Kirsher /* DMA descriptor bitfields */
4039f2f381fSJeff Kirsher #define MACB_RX_USED_OFFSET			0
4049f2f381fSJeff Kirsher #define MACB_RX_USED_SIZE			1
4059f2f381fSJeff Kirsher #define MACB_RX_WRAP_OFFSET			1
4069f2f381fSJeff Kirsher #define MACB_RX_WRAP_SIZE			1
4079f2f381fSJeff Kirsher #define MACB_RX_WADDR_OFFSET			2
4089f2f381fSJeff Kirsher #define MACB_RX_WADDR_SIZE			30
4099f2f381fSJeff Kirsher 
4109f2f381fSJeff Kirsher #define MACB_RX_FRMLEN_OFFSET			0
4119f2f381fSJeff Kirsher #define MACB_RX_FRMLEN_SIZE			12
4129f2f381fSJeff Kirsher #define MACB_RX_OFFSET_OFFSET			12
4139f2f381fSJeff Kirsher #define MACB_RX_OFFSET_SIZE			2
4149f2f381fSJeff Kirsher #define MACB_RX_SOF_OFFSET			14
4159f2f381fSJeff Kirsher #define MACB_RX_SOF_SIZE			1
4169f2f381fSJeff Kirsher #define MACB_RX_EOF_OFFSET			15
4179f2f381fSJeff Kirsher #define MACB_RX_EOF_SIZE			1
4189f2f381fSJeff Kirsher #define MACB_RX_CFI_OFFSET			16
4199f2f381fSJeff Kirsher #define MACB_RX_CFI_SIZE			1
4209f2f381fSJeff Kirsher #define MACB_RX_VLAN_PRI_OFFSET			17
4219f2f381fSJeff Kirsher #define MACB_RX_VLAN_PRI_SIZE			3
4229f2f381fSJeff Kirsher #define MACB_RX_PRI_TAG_OFFSET			20
4239f2f381fSJeff Kirsher #define MACB_RX_PRI_TAG_SIZE			1
4249f2f381fSJeff Kirsher #define MACB_RX_VLAN_TAG_OFFSET			21
4259f2f381fSJeff Kirsher #define MACB_RX_VLAN_TAG_SIZE			1
4269f2f381fSJeff Kirsher #define MACB_RX_TYPEID_MATCH_OFFSET		22
4279f2f381fSJeff Kirsher #define MACB_RX_TYPEID_MATCH_SIZE		1
4289f2f381fSJeff Kirsher #define MACB_RX_SA4_MATCH_OFFSET		23
4299f2f381fSJeff Kirsher #define MACB_RX_SA4_MATCH_SIZE			1
4309f2f381fSJeff Kirsher #define MACB_RX_SA3_MATCH_OFFSET		24
4319f2f381fSJeff Kirsher #define MACB_RX_SA3_MATCH_SIZE			1
4329f2f381fSJeff Kirsher #define MACB_RX_SA2_MATCH_OFFSET		25
4339f2f381fSJeff Kirsher #define MACB_RX_SA2_MATCH_SIZE			1
4349f2f381fSJeff Kirsher #define MACB_RX_SA1_MATCH_OFFSET		26
4359f2f381fSJeff Kirsher #define MACB_RX_SA1_MATCH_SIZE			1
4369f2f381fSJeff Kirsher #define MACB_RX_EXT_MATCH_OFFSET		28
4379f2f381fSJeff Kirsher #define MACB_RX_EXT_MATCH_SIZE			1
4389f2f381fSJeff Kirsher #define MACB_RX_UHASH_MATCH_OFFSET		29
4399f2f381fSJeff Kirsher #define MACB_RX_UHASH_MATCH_SIZE		1
4409f2f381fSJeff Kirsher #define MACB_RX_MHASH_MATCH_OFFSET		30
4419f2f381fSJeff Kirsher #define MACB_RX_MHASH_MATCH_SIZE		1
4429f2f381fSJeff Kirsher #define MACB_RX_BROADCAST_OFFSET		31
4439f2f381fSJeff Kirsher #define MACB_RX_BROADCAST_SIZE			1
4449f2f381fSJeff Kirsher 
4459f2f381fSJeff Kirsher #define MACB_TX_FRMLEN_OFFSET			0
4469f2f381fSJeff Kirsher #define MACB_TX_FRMLEN_SIZE			11
4479f2f381fSJeff Kirsher #define MACB_TX_LAST_OFFSET			15
4489f2f381fSJeff Kirsher #define MACB_TX_LAST_SIZE			1
4499f2f381fSJeff Kirsher #define MACB_TX_NOCRC_OFFSET			16
4509f2f381fSJeff Kirsher #define MACB_TX_NOCRC_SIZE			1
4519f2f381fSJeff Kirsher #define MACB_TX_BUF_EXHAUSTED_OFFSET		27
4529f2f381fSJeff Kirsher #define MACB_TX_BUF_EXHAUSTED_SIZE		1
4539f2f381fSJeff Kirsher #define MACB_TX_UNDERRUN_OFFSET			28
4549f2f381fSJeff Kirsher #define MACB_TX_UNDERRUN_SIZE			1
4559f2f381fSJeff Kirsher #define MACB_TX_ERROR_OFFSET			29
4569f2f381fSJeff Kirsher #define MACB_TX_ERROR_SIZE			1
4579f2f381fSJeff Kirsher #define MACB_TX_WRAP_OFFSET			30
4589f2f381fSJeff Kirsher #define MACB_TX_WRAP_SIZE			1
4599f2f381fSJeff Kirsher #define MACB_TX_USED_OFFSET			31
4609f2f381fSJeff Kirsher #define MACB_TX_USED_SIZE			1
4619f2f381fSJeff Kirsher 
46255054a16SHavard Skinnemoen /**
46355054a16SHavard Skinnemoen  * struct macb_tx_skb - data about an skb which is being transmitted
46455054a16SHavard Skinnemoen  * @skb: skb currently being transmitted
46555054a16SHavard Skinnemoen  * @mapping: DMA address of the skb's data buffer
46655054a16SHavard Skinnemoen  */
46755054a16SHavard Skinnemoen struct macb_tx_skb {
4689f2f381fSJeff Kirsher 	struct sk_buff		*skb;
4699f2f381fSJeff Kirsher 	dma_addr_t		mapping;
4709f2f381fSJeff Kirsher };
4719f2f381fSJeff Kirsher 
4729f2f381fSJeff Kirsher /*
4739f2f381fSJeff Kirsher  * Hardware-collected statistics. Used when updating the network
4749f2f381fSJeff Kirsher  * device stats by a periodic timer.
4759f2f381fSJeff Kirsher  */
4769f2f381fSJeff Kirsher struct macb_stats {
4779f2f381fSJeff Kirsher 	u32	rx_pause_frames;
4789f2f381fSJeff Kirsher 	u32	tx_ok;
4799f2f381fSJeff Kirsher 	u32	tx_single_cols;
4809f2f381fSJeff Kirsher 	u32	tx_multiple_cols;
4819f2f381fSJeff Kirsher 	u32	rx_ok;
4829f2f381fSJeff Kirsher 	u32	rx_fcs_errors;
4839f2f381fSJeff Kirsher 	u32	rx_align_errors;
4849f2f381fSJeff Kirsher 	u32	tx_deferred;
4859f2f381fSJeff Kirsher 	u32	tx_late_cols;
4869f2f381fSJeff Kirsher 	u32	tx_excessive_cols;
4879f2f381fSJeff Kirsher 	u32	tx_underruns;
4889f2f381fSJeff Kirsher 	u32	tx_carrier_errors;
4899f2f381fSJeff Kirsher 	u32	rx_resource_errors;
4909f2f381fSJeff Kirsher 	u32	rx_overruns;
4919f2f381fSJeff Kirsher 	u32	rx_symbol_errors;
4929f2f381fSJeff Kirsher 	u32	rx_oversize_pkts;
4939f2f381fSJeff Kirsher 	u32	rx_jabbers;
4949f2f381fSJeff Kirsher 	u32	rx_undersize_pkts;
4959f2f381fSJeff Kirsher 	u32	sqe_test_errors;
4969f2f381fSJeff Kirsher 	u32	rx_length_mismatch;
4979f2f381fSJeff Kirsher 	u32	tx_pause_frames;
4989f2f381fSJeff Kirsher };
4999f2f381fSJeff Kirsher 
500a494ed8eSJamie Iles struct gem_stats {
501a494ed8eSJamie Iles 	u32	tx_octets_31_0;
502a494ed8eSJamie Iles 	u32	tx_octets_47_32;
503a494ed8eSJamie Iles 	u32	tx_frames;
504a494ed8eSJamie Iles 	u32	tx_broadcast_frames;
505a494ed8eSJamie Iles 	u32	tx_multicast_frames;
506a494ed8eSJamie Iles 	u32	tx_pause_frames;
507a494ed8eSJamie Iles 	u32	tx_64_byte_frames;
508a494ed8eSJamie Iles 	u32	tx_65_127_byte_frames;
509a494ed8eSJamie Iles 	u32	tx_128_255_byte_frames;
510a494ed8eSJamie Iles 	u32	tx_256_511_byte_frames;
511a494ed8eSJamie Iles 	u32	tx_512_1023_byte_frames;
512a494ed8eSJamie Iles 	u32	tx_1024_1518_byte_frames;
513a494ed8eSJamie Iles 	u32	tx_greater_than_1518_byte_frames;
514a494ed8eSJamie Iles 	u32	tx_underrun;
515a494ed8eSJamie Iles 	u32	tx_single_collision_frames;
516a494ed8eSJamie Iles 	u32	tx_multiple_collision_frames;
517a494ed8eSJamie Iles 	u32	tx_excessive_collisions;
518a494ed8eSJamie Iles 	u32	tx_late_collisions;
519a494ed8eSJamie Iles 	u32	tx_deferred_frames;
520a494ed8eSJamie Iles 	u32	tx_carrier_sense_errors;
521a494ed8eSJamie Iles 	u32	rx_octets_31_0;
522a494ed8eSJamie Iles 	u32	rx_octets_47_32;
523a494ed8eSJamie Iles 	u32	rx_frames;
524a494ed8eSJamie Iles 	u32	rx_broadcast_frames;
525a494ed8eSJamie Iles 	u32	rx_multicast_frames;
526a494ed8eSJamie Iles 	u32	rx_pause_frames;
527a494ed8eSJamie Iles 	u32	rx_64_byte_frames;
528a494ed8eSJamie Iles 	u32	rx_65_127_byte_frames;
529a494ed8eSJamie Iles 	u32	rx_128_255_byte_frames;
530a494ed8eSJamie Iles 	u32	rx_256_511_byte_frames;
531a494ed8eSJamie Iles 	u32	rx_512_1023_byte_frames;
532a494ed8eSJamie Iles 	u32	rx_1024_1518_byte_frames;
533a494ed8eSJamie Iles 	u32	rx_greater_than_1518_byte_frames;
534a494ed8eSJamie Iles 	u32	rx_undersized_frames;
535a494ed8eSJamie Iles 	u32	rx_oversize_frames;
536a494ed8eSJamie Iles 	u32	rx_jabbers;
537a494ed8eSJamie Iles 	u32	rx_frame_check_sequence_errors;
538a494ed8eSJamie Iles 	u32	rx_length_field_frame_errors;
539a494ed8eSJamie Iles 	u32	rx_symbol_errors;
540a494ed8eSJamie Iles 	u32	rx_alignment_errors;
541a494ed8eSJamie Iles 	u32	rx_resource_errors;
542a494ed8eSJamie Iles 	u32	rx_overruns;
543a494ed8eSJamie Iles 	u32	rx_ip_header_checksum_errors;
544a494ed8eSJamie Iles 	u32	rx_tcp_checksum_errors;
545a494ed8eSJamie Iles 	u32	rx_udp_checksum_errors;
546a494ed8eSJamie Iles };
547a494ed8eSJamie Iles 
548*4df95131SNicolas Ferre struct macb;
549*4df95131SNicolas Ferre 
550*4df95131SNicolas Ferre struct macb_or_gem_ops {
551*4df95131SNicolas Ferre 	int	(*mog_alloc_rx_buffers)(struct macb *bp);
552*4df95131SNicolas Ferre 	void	(*mog_free_rx_buffers)(struct macb *bp);
553*4df95131SNicolas Ferre 	void	(*mog_init_rings)(struct macb *bp);
554*4df95131SNicolas Ferre 	int	(*mog_rx)(struct macb *bp, int budget);
555*4df95131SNicolas Ferre };
556*4df95131SNicolas Ferre 
5579f2f381fSJeff Kirsher struct macb {
5589f2f381fSJeff Kirsher 	void __iomem		*regs;
5599f2f381fSJeff Kirsher 
5609f2f381fSJeff Kirsher 	unsigned int		rx_tail;
561*4df95131SNicolas Ferre 	unsigned int		rx_prepared_head;
56255054a16SHavard Skinnemoen 	struct macb_dma_desc	*rx_ring;
563*4df95131SNicolas Ferre 	struct sk_buff		**rx_skbuff;
5649f2f381fSJeff Kirsher 	void			*rx_buffers;
5651b44791aSNicolas Ferre 	size_t			rx_buffer_size;
5669f2f381fSJeff Kirsher 
5679f2f381fSJeff Kirsher 	unsigned int		tx_head, tx_tail;
56855054a16SHavard Skinnemoen 	struct macb_dma_desc	*tx_ring;
56955054a16SHavard Skinnemoen 	struct macb_tx_skb	*tx_skb;
5709f2f381fSJeff Kirsher 
5719f2f381fSJeff Kirsher 	spinlock_t		lock;
5729f2f381fSJeff Kirsher 	struct platform_device	*pdev;
5739f2f381fSJeff Kirsher 	struct clk		*pclk;
5749f2f381fSJeff Kirsher 	struct clk		*hclk;
5759f2f381fSJeff Kirsher 	struct net_device	*dev;
5769f2f381fSJeff Kirsher 	struct napi_struct	napi;
577e86cd53aSNicolas Ferre 	struct work_struct	tx_error_task;
5789f2f381fSJeff Kirsher 	struct net_device_stats	stats;
579a494ed8eSJamie Iles 	union {
580a494ed8eSJamie Iles 		struct macb_stats	macb;
581a494ed8eSJamie Iles 		struct gem_stats	gem;
582a494ed8eSJamie Iles 	}			hw_stats;
5839f2f381fSJeff Kirsher 
5849f2f381fSJeff Kirsher 	dma_addr_t		rx_ring_dma;
5859f2f381fSJeff Kirsher 	dma_addr_t		tx_ring_dma;
5869f2f381fSJeff Kirsher 	dma_addr_t		rx_buffers_dma;
5879f2f381fSJeff Kirsher 
588*4df95131SNicolas Ferre 	struct macb_or_gem_ops	macbgem_ops;
589*4df95131SNicolas Ferre 
5909f2f381fSJeff Kirsher 	struct mii_bus		*mii_bus;
5919f2f381fSJeff Kirsher 	struct phy_device	*phy_dev;
5929f2f381fSJeff Kirsher 	unsigned int 		link;
5939f2f381fSJeff Kirsher 	unsigned int 		speed;
5949f2f381fSJeff Kirsher 	unsigned int 		duplex;
595fb97a846SJean-Christophe PLAGNIOL-VILLARD 
596581df9e1SNicolas Ferre 	u32			caps;
597581df9e1SNicolas Ferre 
598fb97a846SJean-Christophe PLAGNIOL-VILLARD 	phy_interface_t		phy_interface;
599b85008b7SJoachim Eastwood 
6004dda6f6dSJoachim Eastwood 	/* AT91RM9200 transmit */
601b85008b7SJoachim Eastwood 	struct sk_buff *skb;			/* holds skb until xmit interrupt completes */
602b85008b7SJoachim Eastwood 	dma_addr_t skb_physaddr;		/* phys addr from pci_map_single */
603b85008b7SJoachim Eastwood 	int skb_length;				/* saved skb length for pci_unmap_single */
6049f2f381fSJeff Kirsher };
6059f2f381fSJeff Kirsher 
6060005f541SJoachim Eastwood extern const struct ethtool_ops macb_ethtool_ops;
6070005f541SJoachim Eastwood 
6080005f541SJoachim Eastwood int macb_mii_init(struct macb *bp);
6090005f541SJoachim Eastwood int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
6102ea32eedSJoachim Eastwood struct net_device_stats *macb_get_stats(struct net_device *dev);
611e0da1f14SJoachim Eastwood void macb_set_rx_mode(struct net_device *dev);
612314bccc4SJoachim Eastwood void macb_set_hwaddr(struct macb *bp);
613314bccc4SJoachim Eastwood void macb_get_hwaddr(struct macb *bp);
6140005f541SJoachim Eastwood 
615f75ba50bSJamie Iles static inline bool macb_is_gem(struct macb *bp)
616f75ba50bSJamie Iles {
617f75ba50bSJamie Iles 	return MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2;
618f75ba50bSJamie Iles }
619f75ba50bSJamie Iles 
6209f2f381fSJeff Kirsher #endif /* _MACB_H */
621