xref: /linux/drivers/net/ethernet/cadence/macb.h (revision b3e3bd71b429c04490d6a57671f2bbe2121d4f5a)
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. */
174*b3e3bd71SNicolas Ferre #define GEM_FBLDO_OFFSET			0
175*b3e3bd71SNicolas Ferre #define GEM_FBLDO_SIZE				5
176*b3e3bd71SNicolas Ferre #define GEM_RXBMS_OFFSET			8
177*b3e3bd71SNicolas Ferre #define GEM_RXBMS_SIZE				2
178*b3e3bd71SNicolas Ferre #define GEM_TXPBMS_OFFSET			10
179*b3e3bd71SNicolas Ferre #define GEM_TXPBMS_SIZE				1
180*b3e3bd71SNicolas Ferre #define GEM_TXCOEN_OFFSET			11
181*b3e3bd71SNicolas Ferre #define GEM_TXCOEN_SIZE				1
1820116da4fSJamie Iles #define GEM_RXBS_OFFSET				16
1830116da4fSJamie Iles #define GEM_RXBS_SIZE				8
184*b3e3bd71SNicolas Ferre #define GEM_DDRP_OFFSET				24
185*b3e3bd71SNicolas Ferre #define GEM_DDRP_SIZE				1
186*b3e3bd71SNicolas Ferre 
1870116da4fSJamie Iles 
1889f2f381fSJeff Kirsher /* Bitfields in NSR */
1899f2f381fSJeff Kirsher #define MACB_NSR_LINK_OFFSET			0
1909f2f381fSJeff Kirsher #define MACB_NSR_LINK_SIZE			1
1919f2f381fSJeff Kirsher #define MACB_MDIO_OFFSET			1
1929f2f381fSJeff Kirsher #define MACB_MDIO_SIZE				1
1939f2f381fSJeff Kirsher #define MACB_IDLE_OFFSET			2
1949f2f381fSJeff Kirsher #define MACB_IDLE_SIZE				1
1959f2f381fSJeff Kirsher 
1969f2f381fSJeff Kirsher /* Bitfields in TSR */
1979f2f381fSJeff Kirsher #define MACB_UBR_OFFSET				0
1989f2f381fSJeff Kirsher #define MACB_UBR_SIZE				1
1999f2f381fSJeff Kirsher #define MACB_COL_OFFSET				1
2009f2f381fSJeff Kirsher #define MACB_COL_SIZE				1
2019f2f381fSJeff Kirsher #define MACB_TSR_RLE_OFFSET			2
2029f2f381fSJeff Kirsher #define MACB_TSR_RLE_SIZE			1
2039f2f381fSJeff Kirsher #define MACB_TGO_OFFSET				3
2049f2f381fSJeff Kirsher #define MACB_TGO_SIZE				1
2059f2f381fSJeff Kirsher #define MACB_BEX_OFFSET				4
2069f2f381fSJeff Kirsher #define MACB_BEX_SIZE				1
2071fd3ca4eSJoachim Eastwood #define MACB_RM9200_BNQ_OFFSET			4 /* AT91RM9200 only */
2081fd3ca4eSJoachim Eastwood #define MACB_RM9200_BNQ_SIZE			1 /* AT91RM9200 only */
2099f2f381fSJeff Kirsher #define MACB_COMP_OFFSET			5
2109f2f381fSJeff Kirsher #define MACB_COMP_SIZE				1
2119f2f381fSJeff Kirsher #define MACB_UND_OFFSET				6
2129f2f381fSJeff Kirsher #define MACB_UND_SIZE				1
2139f2f381fSJeff Kirsher 
2149f2f381fSJeff Kirsher /* Bitfields in RSR */
2159f2f381fSJeff Kirsher #define MACB_BNA_OFFSET				0
2169f2f381fSJeff Kirsher #define MACB_BNA_SIZE				1
2179f2f381fSJeff Kirsher #define MACB_REC_OFFSET				1
2189f2f381fSJeff Kirsher #define MACB_REC_SIZE				1
2199f2f381fSJeff Kirsher #define MACB_OVR_OFFSET				2
2209f2f381fSJeff Kirsher #define MACB_OVR_SIZE				1
2219f2f381fSJeff Kirsher 
2229f2f381fSJeff Kirsher /* Bitfields in ISR/IER/IDR/IMR */
2239f2f381fSJeff Kirsher #define MACB_MFD_OFFSET				0
2249f2f381fSJeff Kirsher #define MACB_MFD_SIZE				1
2259f2f381fSJeff Kirsher #define MACB_RCOMP_OFFSET			1
2269f2f381fSJeff Kirsher #define MACB_RCOMP_SIZE				1
2279f2f381fSJeff Kirsher #define MACB_RXUBR_OFFSET			2
2289f2f381fSJeff Kirsher #define MACB_RXUBR_SIZE				1
2299f2f381fSJeff Kirsher #define MACB_TXUBR_OFFSET			3
2309f2f381fSJeff Kirsher #define MACB_TXUBR_SIZE				1
2319f2f381fSJeff Kirsher #define MACB_ISR_TUND_OFFSET			4
2329f2f381fSJeff Kirsher #define MACB_ISR_TUND_SIZE			1
2339f2f381fSJeff Kirsher #define MACB_ISR_RLE_OFFSET			5
2349f2f381fSJeff Kirsher #define MACB_ISR_RLE_SIZE			1
2359f2f381fSJeff Kirsher #define MACB_TXERR_OFFSET			6
2369f2f381fSJeff Kirsher #define MACB_TXERR_SIZE				1
2379f2f381fSJeff Kirsher #define MACB_TCOMP_OFFSET			7
2389f2f381fSJeff Kirsher #define MACB_TCOMP_SIZE				1
2399f2f381fSJeff Kirsher #define MACB_ISR_LINK_OFFSET			9
2409f2f381fSJeff Kirsher #define MACB_ISR_LINK_SIZE			1
2419f2f381fSJeff Kirsher #define MACB_ISR_ROVR_OFFSET			10
2429f2f381fSJeff Kirsher #define MACB_ISR_ROVR_SIZE			1
2439f2f381fSJeff Kirsher #define MACB_HRESP_OFFSET			11
2449f2f381fSJeff Kirsher #define MACB_HRESP_SIZE				1
2459f2f381fSJeff Kirsher #define MACB_PFR_OFFSET				12
2469f2f381fSJeff Kirsher #define MACB_PFR_SIZE				1
2479f2f381fSJeff Kirsher #define MACB_PTZ_OFFSET				13
2489f2f381fSJeff Kirsher #define MACB_PTZ_SIZE				1
2499f2f381fSJeff Kirsher 
2509f2f381fSJeff Kirsher /* Bitfields in MAN */
2519f2f381fSJeff Kirsher #define MACB_DATA_OFFSET			0
2529f2f381fSJeff Kirsher #define MACB_DATA_SIZE				16
2539f2f381fSJeff Kirsher #define MACB_CODE_OFFSET			16
2549f2f381fSJeff Kirsher #define MACB_CODE_SIZE				2
2559f2f381fSJeff Kirsher #define MACB_REGA_OFFSET			18
2569f2f381fSJeff Kirsher #define MACB_REGA_SIZE				5
2579f2f381fSJeff Kirsher #define MACB_PHYA_OFFSET			23
2589f2f381fSJeff Kirsher #define MACB_PHYA_SIZE				5
2599f2f381fSJeff Kirsher #define MACB_RW_OFFSET				28
2609f2f381fSJeff Kirsher #define MACB_RW_SIZE				2
2619f2f381fSJeff Kirsher #define MACB_SOF_OFFSET				30
2629f2f381fSJeff Kirsher #define MACB_SOF_SIZE				2
2639f2f381fSJeff Kirsher 
2649f2f381fSJeff Kirsher /* Bitfields in USRIO (AVR32) */
2659f2f381fSJeff Kirsher #define MACB_MII_OFFSET				0
2669f2f381fSJeff Kirsher #define MACB_MII_SIZE				1
2679f2f381fSJeff Kirsher #define MACB_EAM_OFFSET				1
2689f2f381fSJeff Kirsher #define MACB_EAM_SIZE				1
2699f2f381fSJeff Kirsher #define MACB_TX_PAUSE_OFFSET			2
2709f2f381fSJeff Kirsher #define MACB_TX_PAUSE_SIZE			1
2719f2f381fSJeff Kirsher #define MACB_TX_PAUSE_ZERO_OFFSET		3
2729f2f381fSJeff Kirsher #define MACB_TX_PAUSE_ZERO_SIZE			1
2739f2f381fSJeff Kirsher 
2749f2f381fSJeff Kirsher /* Bitfields in USRIO (AT91) */
2759f2f381fSJeff Kirsher #define MACB_RMII_OFFSET			0
2769f2f381fSJeff Kirsher #define MACB_RMII_SIZE				1
277140b7552SPatrice Vilchez #define GEM_RGMII_OFFSET			0	/* GEM gigabit mode */
278140b7552SPatrice Vilchez #define GEM_RGMII_SIZE				1
2799f2f381fSJeff Kirsher #define MACB_CLKEN_OFFSET			1
2809f2f381fSJeff Kirsher #define MACB_CLKEN_SIZE				1
2819f2f381fSJeff Kirsher 
2829f2f381fSJeff Kirsher /* Bitfields in WOL */
2839f2f381fSJeff Kirsher #define MACB_IP_OFFSET				0
2849f2f381fSJeff Kirsher #define MACB_IP_SIZE				16
2859f2f381fSJeff Kirsher #define MACB_MAG_OFFSET				16
2869f2f381fSJeff Kirsher #define MACB_MAG_SIZE				1
2879f2f381fSJeff Kirsher #define MACB_ARP_OFFSET				17
2889f2f381fSJeff Kirsher #define MACB_ARP_SIZE				1
2899f2f381fSJeff Kirsher #define MACB_SA1_OFFSET				18
2909f2f381fSJeff Kirsher #define MACB_SA1_SIZE				1
2919f2f381fSJeff Kirsher #define MACB_WOL_MTI_OFFSET			19
2929f2f381fSJeff Kirsher #define MACB_WOL_MTI_SIZE			1
2939f2f381fSJeff Kirsher 
294f75ba50bSJamie Iles /* Bitfields in MID */
295f75ba50bSJamie Iles #define MACB_IDNUM_OFFSET			16
296f75ba50bSJamie Iles #define MACB_IDNUM_SIZE				16
297f75ba50bSJamie Iles #define MACB_REV_OFFSET				0
298f75ba50bSJamie Iles #define MACB_REV_SIZE				16
299f75ba50bSJamie Iles 
300757a03c6SJamie Iles /* Bitfields in DCFG1. */
301757a03c6SJamie Iles #define GEM_DBWDEF_OFFSET			25
302757a03c6SJamie Iles #define GEM_DBWDEF_SIZE				3
303757a03c6SJamie Iles 
3049f2f381fSJeff Kirsher /* Constants for CLK */
3059f2f381fSJeff Kirsher #define MACB_CLK_DIV8				0
3069f2f381fSJeff Kirsher #define MACB_CLK_DIV16				1
3079f2f381fSJeff Kirsher #define MACB_CLK_DIV32				2
3089f2f381fSJeff Kirsher #define MACB_CLK_DIV64				3
3099f2f381fSJeff Kirsher 
31070c9f3d4SJamie Iles /* GEM specific constants for CLK. */
31170c9f3d4SJamie Iles #define GEM_CLK_DIV8				0
31270c9f3d4SJamie Iles #define GEM_CLK_DIV16				1
31370c9f3d4SJamie Iles #define GEM_CLK_DIV32				2
31470c9f3d4SJamie Iles #define GEM_CLK_DIV48				3
31570c9f3d4SJamie Iles #define GEM_CLK_DIV64				4
31670c9f3d4SJamie Iles #define GEM_CLK_DIV96				5
31770c9f3d4SJamie Iles 
3189f2f381fSJeff Kirsher /* Constants for MAN register */
3199f2f381fSJeff Kirsher #define MACB_MAN_SOF				1
3209f2f381fSJeff Kirsher #define MACB_MAN_WRITE				1
3219f2f381fSJeff Kirsher #define MACB_MAN_READ				2
3229f2f381fSJeff Kirsher #define MACB_MAN_CODE				2
3239f2f381fSJeff Kirsher 
3249f2f381fSJeff Kirsher /* Bit manipulation macros */
3259f2f381fSJeff Kirsher #define MACB_BIT(name)					\
3269f2f381fSJeff Kirsher 	(1 << MACB_##name##_OFFSET)
3279f2f381fSJeff Kirsher #define MACB_BF(name,value)				\
3289f2f381fSJeff Kirsher 	(((value) & ((1 << MACB_##name##_SIZE) - 1))	\
3299f2f381fSJeff Kirsher 	 << MACB_##name##_OFFSET)
3309f2f381fSJeff Kirsher #define MACB_BFEXT(name,value)\
3319f2f381fSJeff Kirsher 	(((value) >> MACB_##name##_OFFSET)		\
3329f2f381fSJeff Kirsher 	 & ((1 << MACB_##name##_SIZE) - 1))
3339f2f381fSJeff Kirsher #define MACB_BFINS(name,value,old)			\
3349f2f381fSJeff Kirsher 	(((old) & ~(((1 << MACB_##name##_SIZE) - 1)	\
3359f2f381fSJeff Kirsher 		    << MACB_##name##_OFFSET))		\
3369f2f381fSJeff Kirsher 	 | MACB_BF(name,value))
3379f2f381fSJeff Kirsher 
338f75ba50bSJamie Iles #define GEM_BIT(name)					\
339f75ba50bSJamie Iles 	(1 << GEM_##name##_OFFSET)
340f75ba50bSJamie Iles #define GEM_BF(name, value)				\
341f75ba50bSJamie Iles 	(((value) & ((1 << GEM_##name##_SIZE) - 1))	\
342f75ba50bSJamie Iles 	 << GEM_##name##_OFFSET)
343f75ba50bSJamie Iles #define GEM_BFEXT(name, value)\
344f75ba50bSJamie Iles 	(((value) >> GEM_##name##_OFFSET)		\
345f75ba50bSJamie Iles 	 & ((1 << GEM_##name##_SIZE) - 1))
346f75ba50bSJamie Iles #define GEM_BFINS(name, value, old)			\
347f75ba50bSJamie Iles 	(((old) & ~(((1 << GEM_##name##_SIZE) - 1)	\
348f75ba50bSJamie Iles 		    << GEM_##name##_OFFSET))		\
349f75ba50bSJamie Iles 	 | GEM_BF(name, value))
350f75ba50bSJamie Iles 
3519f2f381fSJeff Kirsher /* Register access macros */
3529f2f381fSJeff Kirsher #define macb_readl(port,reg)				\
3539f2f381fSJeff Kirsher 	__raw_readl((port)->regs + MACB_##reg)
3549f2f381fSJeff Kirsher #define macb_writel(port,reg,value)			\
3559f2f381fSJeff Kirsher 	__raw_writel((value), (port)->regs + MACB_##reg)
356f75ba50bSJamie Iles #define gem_readl(port, reg)				\
357f75ba50bSJamie Iles 	__raw_readl((port)->regs + GEM_##reg)
358f75ba50bSJamie Iles #define gem_writel(port, reg, value)			\
359f75ba50bSJamie Iles 	__raw_writel((value), (port)->regs + GEM_##reg)
360f75ba50bSJamie Iles 
361f75ba50bSJamie Iles /*
362f75ba50bSJamie Iles  * Conditional GEM/MACB macros.  These perform the operation to the correct
363f75ba50bSJamie Iles  * register dependent on whether the device is a GEM or a MACB.  For registers
364f75ba50bSJamie Iles  * and bitfields that are common across both devices, use macb_{read,write}l
365f75ba50bSJamie Iles  * to avoid the cost of the conditional.
366f75ba50bSJamie Iles  */
367f75ba50bSJamie Iles #define macb_or_gem_writel(__bp, __reg, __value) \
368f75ba50bSJamie Iles 	({ \
369f75ba50bSJamie Iles 		if (macb_is_gem((__bp))) \
370f75ba50bSJamie Iles 			gem_writel((__bp), __reg, __value); \
371f75ba50bSJamie Iles 		else \
372f75ba50bSJamie Iles 			macb_writel((__bp), __reg, __value); \
373f75ba50bSJamie Iles 	})
374f75ba50bSJamie Iles 
375f75ba50bSJamie Iles #define macb_or_gem_readl(__bp, __reg) \
376f75ba50bSJamie Iles 	({ \
377f75ba50bSJamie Iles 		u32 __v; \
378f75ba50bSJamie Iles 		if (macb_is_gem((__bp))) \
379f75ba50bSJamie Iles 			__v = gem_readl((__bp), __reg); \
380f75ba50bSJamie Iles 		else \
381f75ba50bSJamie Iles 			__v = macb_readl((__bp), __reg); \
382f75ba50bSJamie Iles 		__v; \
383f75ba50bSJamie Iles 	})
3849f2f381fSJeff Kirsher 
38555054a16SHavard Skinnemoen /**
38655054a16SHavard Skinnemoen  * struct macb_dma_desc - Hardware DMA descriptor
38755054a16SHavard Skinnemoen  * @addr: DMA address of data buffer
38855054a16SHavard Skinnemoen  * @ctrl: Control and status bits
38955054a16SHavard Skinnemoen  */
39055054a16SHavard Skinnemoen struct macb_dma_desc {
3919f2f381fSJeff Kirsher 	u32	addr;
3929f2f381fSJeff Kirsher 	u32	ctrl;
3939f2f381fSJeff Kirsher };
3949f2f381fSJeff Kirsher 
3959f2f381fSJeff Kirsher /* DMA descriptor bitfields */
3969f2f381fSJeff Kirsher #define MACB_RX_USED_OFFSET			0
3979f2f381fSJeff Kirsher #define MACB_RX_USED_SIZE			1
3989f2f381fSJeff Kirsher #define MACB_RX_WRAP_OFFSET			1
3999f2f381fSJeff Kirsher #define MACB_RX_WRAP_SIZE			1
4009f2f381fSJeff Kirsher #define MACB_RX_WADDR_OFFSET			2
4019f2f381fSJeff Kirsher #define MACB_RX_WADDR_SIZE			30
4029f2f381fSJeff Kirsher 
4039f2f381fSJeff Kirsher #define MACB_RX_FRMLEN_OFFSET			0
4049f2f381fSJeff Kirsher #define MACB_RX_FRMLEN_SIZE			12
4059f2f381fSJeff Kirsher #define MACB_RX_OFFSET_OFFSET			12
4069f2f381fSJeff Kirsher #define MACB_RX_OFFSET_SIZE			2
4079f2f381fSJeff Kirsher #define MACB_RX_SOF_OFFSET			14
4089f2f381fSJeff Kirsher #define MACB_RX_SOF_SIZE			1
4099f2f381fSJeff Kirsher #define MACB_RX_EOF_OFFSET			15
4109f2f381fSJeff Kirsher #define MACB_RX_EOF_SIZE			1
4119f2f381fSJeff Kirsher #define MACB_RX_CFI_OFFSET			16
4129f2f381fSJeff Kirsher #define MACB_RX_CFI_SIZE			1
4139f2f381fSJeff Kirsher #define MACB_RX_VLAN_PRI_OFFSET			17
4149f2f381fSJeff Kirsher #define MACB_RX_VLAN_PRI_SIZE			3
4159f2f381fSJeff Kirsher #define MACB_RX_PRI_TAG_OFFSET			20
4169f2f381fSJeff Kirsher #define MACB_RX_PRI_TAG_SIZE			1
4179f2f381fSJeff Kirsher #define MACB_RX_VLAN_TAG_OFFSET			21
4189f2f381fSJeff Kirsher #define MACB_RX_VLAN_TAG_SIZE			1
4199f2f381fSJeff Kirsher #define MACB_RX_TYPEID_MATCH_OFFSET		22
4209f2f381fSJeff Kirsher #define MACB_RX_TYPEID_MATCH_SIZE		1
4219f2f381fSJeff Kirsher #define MACB_RX_SA4_MATCH_OFFSET		23
4229f2f381fSJeff Kirsher #define MACB_RX_SA4_MATCH_SIZE			1
4239f2f381fSJeff Kirsher #define MACB_RX_SA3_MATCH_OFFSET		24
4249f2f381fSJeff Kirsher #define MACB_RX_SA3_MATCH_SIZE			1
4259f2f381fSJeff Kirsher #define MACB_RX_SA2_MATCH_OFFSET		25
4269f2f381fSJeff Kirsher #define MACB_RX_SA2_MATCH_SIZE			1
4279f2f381fSJeff Kirsher #define MACB_RX_SA1_MATCH_OFFSET		26
4289f2f381fSJeff Kirsher #define MACB_RX_SA1_MATCH_SIZE			1
4299f2f381fSJeff Kirsher #define MACB_RX_EXT_MATCH_OFFSET		28
4309f2f381fSJeff Kirsher #define MACB_RX_EXT_MATCH_SIZE			1
4319f2f381fSJeff Kirsher #define MACB_RX_UHASH_MATCH_OFFSET		29
4329f2f381fSJeff Kirsher #define MACB_RX_UHASH_MATCH_SIZE		1
4339f2f381fSJeff Kirsher #define MACB_RX_MHASH_MATCH_OFFSET		30
4349f2f381fSJeff Kirsher #define MACB_RX_MHASH_MATCH_SIZE		1
4359f2f381fSJeff Kirsher #define MACB_RX_BROADCAST_OFFSET		31
4369f2f381fSJeff Kirsher #define MACB_RX_BROADCAST_SIZE			1
4379f2f381fSJeff Kirsher 
4389f2f381fSJeff Kirsher #define MACB_TX_FRMLEN_OFFSET			0
4399f2f381fSJeff Kirsher #define MACB_TX_FRMLEN_SIZE			11
4409f2f381fSJeff Kirsher #define MACB_TX_LAST_OFFSET			15
4419f2f381fSJeff Kirsher #define MACB_TX_LAST_SIZE			1
4429f2f381fSJeff Kirsher #define MACB_TX_NOCRC_OFFSET			16
4439f2f381fSJeff Kirsher #define MACB_TX_NOCRC_SIZE			1
4449f2f381fSJeff Kirsher #define MACB_TX_BUF_EXHAUSTED_OFFSET		27
4459f2f381fSJeff Kirsher #define MACB_TX_BUF_EXHAUSTED_SIZE		1
4469f2f381fSJeff Kirsher #define MACB_TX_UNDERRUN_OFFSET			28
4479f2f381fSJeff Kirsher #define MACB_TX_UNDERRUN_SIZE			1
4489f2f381fSJeff Kirsher #define MACB_TX_ERROR_OFFSET			29
4499f2f381fSJeff Kirsher #define MACB_TX_ERROR_SIZE			1
4509f2f381fSJeff Kirsher #define MACB_TX_WRAP_OFFSET			30
4519f2f381fSJeff Kirsher #define MACB_TX_WRAP_SIZE			1
4529f2f381fSJeff Kirsher #define MACB_TX_USED_OFFSET			31
4539f2f381fSJeff Kirsher #define MACB_TX_USED_SIZE			1
4549f2f381fSJeff Kirsher 
45555054a16SHavard Skinnemoen /**
45655054a16SHavard Skinnemoen  * struct macb_tx_skb - data about an skb which is being transmitted
45755054a16SHavard Skinnemoen  * @skb: skb currently being transmitted
45855054a16SHavard Skinnemoen  * @mapping: DMA address of the skb's data buffer
45955054a16SHavard Skinnemoen  */
46055054a16SHavard Skinnemoen struct macb_tx_skb {
4619f2f381fSJeff Kirsher 	struct sk_buff		*skb;
4629f2f381fSJeff Kirsher 	dma_addr_t		mapping;
4639f2f381fSJeff Kirsher };
4649f2f381fSJeff Kirsher 
4659f2f381fSJeff Kirsher /*
4669f2f381fSJeff Kirsher  * Hardware-collected statistics. Used when updating the network
4679f2f381fSJeff Kirsher  * device stats by a periodic timer.
4689f2f381fSJeff Kirsher  */
4699f2f381fSJeff Kirsher struct macb_stats {
4709f2f381fSJeff Kirsher 	u32	rx_pause_frames;
4719f2f381fSJeff Kirsher 	u32	tx_ok;
4729f2f381fSJeff Kirsher 	u32	tx_single_cols;
4739f2f381fSJeff Kirsher 	u32	tx_multiple_cols;
4749f2f381fSJeff Kirsher 	u32	rx_ok;
4759f2f381fSJeff Kirsher 	u32	rx_fcs_errors;
4769f2f381fSJeff Kirsher 	u32	rx_align_errors;
4779f2f381fSJeff Kirsher 	u32	tx_deferred;
4789f2f381fSJeff Kirsher 	u32	tx_late_cols;
4799f2f381fSJeff Kirsher 	u32	tx_excessive_cols;
4809f2f381fSJeff Kirsher 	u32	tx_underruns;
4819f2f381fSJeff Kirsher 	u32	tx_carrier_errors;
4829f2f381fSJeff Kirsher 	u32	rx_resource_errors;
4839f2f381fSJeff Kirsher 	u32	rx_overruns;
4849f2f381fSJeff Kirsher 	u32	rx_symbol_errors;
4859f2f381fSJeff Kirsher 	u32	rx_oversize_pkts;
4869f2f381fSJeff Kirsher 	u32	rx_jabbers;
4879f2f381fSJeff Kirsher 	u32	rx_undersize_pkts;
4889f2f381fSJeff Kirsher 	u32	sqe_test_errors;
4899f2f381fSJeff Kirsher 	u32	rx_length_mismatch;
4909f2f381fSJeff Kirsher 	u32	tx_pause_frames;
4919f2f381fSJeff Kirsher };
4929f2f381fSJeff Kirsher 
493a494ed8eSJamie Iles struct gem_stats {
494a494ed8eSJamie Iles 	u32	tx_octets_31_0;
495a494ed8eSJamie Iles 	u32	tx_octets_47_32;
496a494ed8eSJamie Iles 	u32	tx_frames;
497a494ed8eSJamie Iles 	u32	tx_broadcast_frames;
498a494ed8eSJamie Iles 	u32	tx_multicast_frames;
499a494ed8eSJamie Iles 	u32	tx_pause_frames;
500a494ed8eSJamie Iles 	u32	tx_64_byte_frames;
501a494ed8eSJamie Iles 	u32	tx_65_127_byte_frames;
502a494ed8eSJamie Iles 	u32	tx_128_255_byte_frames;
503a494ed8eSJamie Iles 	u32	tx_256_511_byte_frames;
504a494ed8eSJamie Iles 	u32	tx_512_1023_byte_frames;
505a494ed8eSJamie Iles 	u32	tx_1024_1518_byte_frames;
506a494ed8eSJamie Iles 	u32	tx_greater_than_1518_byte_frames;
507a494ed8eSJamie Iles 	u32	tx_underrun;
508a494ed8eSJamie Iles 	u32	tx_single_collision_frames;
509a494ed8eSJamie Iles 	u32	tx_multiple_collision_frames;
510a494ed8eSJamie Iles 	u32	tx_excessive_collisions;
511a494ed8eSJamie Iles 	u32	tx_late_collisions;
512a494ed8eSJamie Iles 	u32	tx_deferred_frames;
513a494ed8eSJamie Iles 	u32	tx_carrier_sense_errors;
514a494ed8eSJamie Iles 	u32	rx_octets_31_0;
515a494ed8eSJamie Iles 	u32	rx_octets_47_32;
516a494ed8eSJamie Iles 	u32	rx_frames;
517a494ed8eSJamie Iles 	u32	rx_broadcast_frames;
518a494ed8eSJamie Iles 	u32	rx_multicast_frames;
519a494ed8eSJamie Iles 	u32	rx_pause_frames;
520a494ed8eSJamie Iles 	u32	rx_64_byte_frames;
521a494ed8eSJamie Iles 	u32	rx_65_127_byte_frames;
522a494ed8eSJamie Iles 	u32	rx_128_255_byte_frames;
523a494ed8eSJamie Iles 	u32	rx_256_511_byte_frames;
524a494ed8eSJamie Iles 	u32	rx_512_1023_byte_frames;
525a494ed8eSJamie Iles 	u32	rx_1024_1518_byte_frames;
526a494ed8eSJamie Iles 	u32	rx_greater_than_1518_byte_frames;
527a494ed8eSJamie Iles 	u32	rx_undersized_frames;
528a494ed8eSJamie Iles 	u32	rx_oversize_frames;
529a494ed8eSJamie Iles 	u32	rx_jabbers;
530a494ed8eSJamie Iles 	u32	rx_frame_check_sequence_errors;
531a494ed8eSJamie Iles 	u32	rx_length_field_frame_errors;
532a494ed8eSJamie Iles 	u32	rx_symbol_errors;
533a494ed8eSJamie Iles 	u32	rx_alignment_errors;
534a494ed8eSJamie Iles 	u32	rx_resource_errors;
535a494ed8eSJamie Iles 	u32	rx_overruns;
536a494ed8eSJamie Iles 	u32	rx_ip_header_checksum_errors;
537a494ed8eSJamie Iles 	u32	rx_tcp_checksum_errors;
538a494ed8eSJamie Iles 	u32	rx_udp_checksum_errors;
539a494ed8eSJamie Iles };
540a494ed8eSJamie Iles 
5419f2f381fSJeff Kirsher struct macb {
5429f2f381fSJeff Kirsher 	void __iomem		*regs;
5439f2f381fSJeff Kirsher 
5449f2f381fSJeff Kirsher 	unsigned int		rx_tail;
54555054a16SHavard Skinnemoen 	struct macb_dma_desc	*rx_ring;
5469f2f381fSJeff Kirsher 	void			*rx_buffers;
5479f2f381fSJeff Kirsher 
5489f2f381fSJeff Kirsher 	unsigned int		tx_head, tx_tail;
54955054a16SHavard Skinnemoen 	struct macb_dma_desc	*tx_ring;
55055054a16SHavard Skinnemoen 	struct macb_tx_skb	*tx_skb;
5519f2f381fSJeff Kirsher 
5529f2f381fSJeff Kirsher 	spinlock_t		lock;
5539f2f381fSJeff Kirsher 	struct platform_device	*pdev;
5549f2f381fSJeff Kirsher 	struct clk		*pclk;
5559f2f381fSJeff Kirsher 	struct clk		*hclk;
5569f2f381fSJeff Kirsher 	struct net_device	*dev;
5579f2f381fSJeff Kirsher 	struct napi_struct	napi;
558e86cd53aSNicolas Ferre 	struct work_struct	tx_error_task;
5599f2f381fSJeff Kirsher 	struct net_device_stats	stats;
560a494ed8eSJamie Iles 	union {
561a494ed8eSJamie Iles 		struct macb_stats	macb;
562a494ed8eSJamie Iles 		struct gem_stats	gem;
563a494ed8eSJamie Iles 	}			hw_stats;
5649f2f381fSJeff Kirsher 
5659f2f381fSJeff Kirsher 	dma_addr_t		rx_ring_dma;
5669f2f381fSJeff Kirsher 	dma_addr_t		tx_ring_dma;
5679f2f381fSJeff Kirsher 	dma_addr_t		rx_buffers_dma;
5689f2f381fSJeff Kirsher 
5699f2f381fSJeff Kirsher 	struct mii_bus		*mii_bus;
5709f2f381fSJeff Kirsher 	struct phy_device	*phy_dev;
5719f2f381fSJeff Kirsher 	unsigned int 		link;
5729f2f381fSJeff Kirsher 	unsigned int 		speed;
5739f2f381fSJeff Kirsher 	unsigned int 		duplex;
574fb97a846SJean-Christophe PLAGNIOL-VILLARD 
575fb97a846SJean-Christophe PLAGNIOL-VILLARD 	phy_interface_t		phy_interface;
576b85008b7SJoachim Eastwood 
5774dda6f6dSJoachim Eastwood 	/* AT91RM9200 transmit */
578b85008b7SJoachim Eastwood 	struct sk_buff *skb;			/* holds skb until xmit interrupt completes */
579b85008b7SJoachim Eastwood 	dma_addr_t skb_physaddr;		/* phys addr from pci_map_single */
580b85008b7SJoachim Eastwood 	int skb_length;				/* saved skb length for pci_unmap_single */
5819f2f381fSJeff Kirsher };
5829f2f381fSJeff Kirsher 
5830005f541SJoachim Eastwood extern const struct ethtool_ops macb_ethtool_ops;
5840005f541SJoachim Eastwood 
5850005f541SJoachim Eastwood int macb_mii_init(struct macb *bp);
5860005f541SJoachim Eastwood int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
5872ea32eedSJoachim Eastwood struct net_device_stats *macb_get_stats(struct net_device *dev);
588e0da1f14SJoachim Eastwood void macb_set_rx_mode(struct net_device *dev);
589314bccc4SJoachim Eastwood void macb_set_hwaddr(struct macb *bp);
590314bccc4SJoachim Eastwood void macb_get_hwaddr(struct macb *bp);
5910005f541SJoachim Eastwood 
592f75ba50bSJamie Iles static inline bool macb_is_gem(struct macb *bp)
593f75ba50bSJamie Iles {
594f75ba50bSJamie Iles 	return MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2;
595f75ba50bSJamie Iles }
596f75ba50bSJamie Iles 
5979f2f381fSJeff Kirsher #endif /* _MACB_H */
598