xref: /linux/drivers/net/ethernet/cadence/macb.h (revision d2912cb15bdda8ba4a5dd73396ad62641af2f520)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
29f2f381fSJeff Kirsher /*
39f2f381fSJeff Kirsher  * Atmel MACB Ethernet Controller driver
49f2f381fSJeff Kirsher  *
59f2f381fSJeff Kirsher  * Copyright (C) 2004-2006 Atmel Corporation
69f2f381fSJeff Kirsher  */
79f2f381fSJeff Kirsher #ifndef _MACB_H
89f2f381fSJeff Kirsher #define _MACB_H
99f2f381fSJeff Kirsher 
10fc182b85SRussell King #include <linux/phy.h>
11ab91f0a9SRafal Ozieblo #include <linux/ptp_clock_kernel.h>
12ab91f0a9SRafal Ozieblo #include <linux/net_tstamp.h>
13032dc41bSHarini Katakam #include <linux/interrupt.h>
14fc182b85SRussell King 
157b429614SRafal Ozieblo #if defined(CONFIG_ARCH_DMA_ADDR_T_64BIT) || defined(CONFIG_MACB_USE_HWSTAMP)
167b429614SRafal Ozieblo #define MACB_EXT_DESC
177b429614SRafal Ozieblo #endif
187b429614SRafal Ozieblo 
19d1d1b53dSNicolas Ferre #define MACB_GREGS_NBR 16
207c39994fSNicolas Ferre #define MACB_GREGS_VERSION 2
2102c958ddSCyrille Pitchen #define MACB_MAX_QUEUES 8
22d1d1b53dSNicolas Ferre 
239f2f381fSJeff Kirsher /* MACB register offsets */
245c2fa0f6SXander Huff #define MACB_NCR		0x0000 /* Network Control */
255c2fa0f6SXander Huff #define MACB_NCFGR		0x0004 /* Network Config */
265c2fa0f6SXander Huff #define MACB_NSR		0x0008 /* Network Status */
271fd3ca4eSJoachim Eastwood #define MACB_TAR		0x000c /* AT91RM9200 only */
281fd3ca4eSJoachim Eastwood #define MACB_TCR		0x0010 /* AT91RM9200 only */
295c2fa0f6SXander Huff #define MACB_TSR		0x0014 /* Transmit Status */
305c2fa0f6SXander Huff #define MACB_RBQP		0x0018 /* RX Q Base Address */
315c2fa0f6SXander Huff #define MACB_TBQP		0x001c /* TX Q Base Address */
325c2fa0f6SXander Huff #define MACB_RSR		0x0020 /* Receive Status */
335c2fa0f6SXander Huff #define MACB_ISR		0x0024 /* Interrupt Status */
345c2fa0f6SXander Huff #define MACB_IER		0x0028 /* Interrupt Enable */
355c2fa0f6SXander Huff #define MACB_IDR		0x002c /* Interrupt Disable */
365c2fa0f6SXander Huff #define MACB_IMR		0x0030 /* Interrupt Mask */
375c2fa0f6SXander Huff #define MACB_MAN		0x0034 /* PHY Maintenance */
389f2f381fSJeff Kirsher #define MACB_PTR		0x0038
399f2f381fSJeff Kirsher #define MACB_PFR		0x003c
409f2f381fSJeff Kirsher #define MACB_FTO		0x0040
419f2f381fSJeff Kirsher #define MACB_SCF		0x0044
429f2f381fSJeff Kirsher #define MACB_MCF		0x0048
439f2f381fSJeff Kirsher #define MACB_FRO		0x004c
449f2f381fSJeff Kirsher #define MACB_FCSE		0x0050
459f2f381fSJeff Kirsher #define MACB_ALE		0x0054
469f2f381fSJeff Kirsher #define MACB_DTF		0x0058
479f2f381fSJeff Kirsher #define MACB_LCOL		0x005c
489f2f381fSJeff Kirsher #define MACB_EXCOL		0x0060
499f2f381fSJeff Kirsher #define MACB_TUND		0x0064
509f2f381fSJeff Kirsher #define MACB_CSE		0x0068
519f2f381fSJeff Kirsher #define MACB_RRE		0x006c
529f2f381fSJeff Kirsher #define MACB_ROVR		0x0070
539f2f381fSJeff Kirsher #define MACB_RSE		0x0074
549f2f381fSJeff Kirsher #define MACB_ELE		0x0078
559f2f381fSJeff Kirsher #define MACB_RJA		0x007c
569f2f381fSJeff Kirsher #define MACB_USF		0x0080
579f2f381fSJeff Kirsher #define MACB_STE		0x0084
589f2f381fSJeff Kirsher #define MACB_RLE		0x0088
599f2f381fSJeff Kirsher #define MACB_TPF		0x008c
609f2f381fSJeff Kirsher #define MACB_HRB		0x0090
619f2f381fSJeff Kirsher #define MACB_HRT		0x0094
629f2f381fSJeff Kirsher #define MACB_SA1B		0x0098
639f2f381fSJeff Kirsher #define MACB_SA1T		0x009c
649f2f381fSJeff Kirsher #define MACB_SA2B		0x00a0
659f2f381fSJeff Kirsher #define MACB_SA2T		0x00a4
669f2f381fSJeff Kirsher #define MACB_SA3B		0x00a8
679f2f381fSJeff Kirsher #define MACB_SA3T		0x00ac
689f2f381fSJeff Kirsher #define MACB_SA4B		0x00b0
699f2f381fSJeff Kirsher #define MACB_SA4T		0x00b4
709f2f381fSJeff Kirsher #define MACB_TID		0x00b8
719f2f381fSJeff Kirsher #define MACB_TPQ		0x00bc
729f2f381fSJeff Kirsher #define MACB_USRIO		0x00c0
739f2f381fSJeff Kirsher #define MACB_WOL		0x00c4
74f75ba50bSJamie Iles #define MACB_MID		0x00fc
75fff8019aSHarini Katakam #define MACB_TBQPH		0x04C8
76fff8019aSHarini Katakam #define MACB_RBQPH		0x04D4
77f75ba50bSJamie Iles 
78f75ba50bSJamie Iles /* GEM register offsets. */
795c2fa0f6SXander Huff #define GEM_NCFGR		0x0004 /* Network Config */
805c2fa0f6SXander Huff #define GEM_USRIO		0x000c /* User IO */
815c2fa0f6SXander Huff #define GEM_DMACFG		0x0010 /* DMA Configuration */
8298b5a0f4SHarini Katakam #define GEM_JML			0x0048 /* Jumbo Max Length */
835c2fa0f6SXander Huff #define GEM_HRB			0x0080 /* Hash Bottom */
845c2fa0f6SXander Huff #define GEM_HRT			0x0084 /* Hash Top */
855c2fa0f6SXander Huff #define GEM_SA1B		0x0088 /* Specific1 Bottom */
865c2fa0f6SXander Huff #define GEM_SA1T		0x008C /* Specific1 Top */
875c2fa0f6SXander Huff #define GEM_SA2B		0x0090 /* Specific2 Bottom */
885c2fa0f6SXander Huff #define GEM_SA2T		0x0094 /* Specific2 Top */
895c2fa0f6SXander Huff #define GEM_SA3B		0x0098 /* Specific3 Bottom */
905c2fa0f6SXander Huff #define GEM_SA3T		0x009C /* Specific3 Top */
915c2fa0f6SXander Huff #define GEM_SA4B		0x00A0 /* Specific4 Bottom */
925c2fa0f6SXander Huff #define GEM_SA4T		0x00A4 /* Specific4 Top */
93ab91f0a9SRafal Ozieblo #define GEM_EFTSH		0x00e8 /* PTP Event Frame Transmitted Seconds Register 47:32 */
94ab91f0a9SRafal Ozieblo #define GEM_EFRSH		0x00ec /* PTP Event Frame Received Seconds Register 47:32 */
95ab91f0a9SRafal Ozieblo #define GEM_PEFTSH		0x00f0 /* PTP Peer Event Frame Transmitted Seconds Register 47:32 */
96ab91f0a9SRafal Ozieblo #define GEM_PEFRSH		0x00f4 /* PTP Peer Event Frame Received Seconds Register 47:32 */
975c2fa0f6SXander Huff #define GEM_OTX			0x0100 /* Octets transmitted */
986f79eed8SXander Huff #define GEM_OCTTXL		0x0100 /* Octets transmitted [31:0] */
996f79eed8SXander Huff #define GEM_OCTTXH		0x0104 /* Octets transmitted [47:32] */
1006f79eed8SXander Huff #define GEM_TXCNT		0x0108 /* Frames Transmitted counter */
1016f79eed8SXander Huff #define GEM_TXBCCNT		0x010c /* Broadcast Frames counter */
1026f79eed8SXander Huff #define GEM_TXMCCNT		0x0110 /* Multicast Frames counter */
1036f79eed8SXander Huff #define GEM_TXPAUSECNT		0x0114 /* Pause Frames Transmitted Counter */
1046f79eed8SXander Huff #define GEM_TX64CNT		0x0118 /* 64 byte Frames TX counter */
1056f79eed8SXander Huff #define GEM_TX65CNT		0x011c /* 65-127 byte Frames TX counter */
1066f79eed8SXander Huff #define GEM_TX128CNT		0x0120 /* 128-255 byte Frames TX counter */
1076f79eed8SXander Huff #define GEM_TX256CNT		0x0124 /* 256-511 byte Frames TX counter */
1086f79eed8SXander Huff #define GEM_TX512CNT		0x0128 /* 512-1023 byte Frames TX counter */
1096f79eed8SXander Huff #define GEM_TX1024CNT		0x012c /* 1024-1518 byte Frames TX counter */
1106f79eed8SXander Huff #define GEM_TX1519CNT		0x0130 /* 1519+ byte Frames TX counter */
1116f79eed8SXander Huff #define GEM_TXURUNCNT		0x0134 /* TX under run error counter */
1126f79eed8SXander Huff #define GEM_SNGLCOLLCNT		0x0138 /* Single Collision Frame Counter */
1136f79eed8SXander Huff #define GEM_MULTICOLLCNT	0x013c /* Multiple Collision Frame Counter */
1146f79eed8SXander Huff #define GEM_EXCESSCOLLCNT	0x0140 /* Excessive Collision Frame Counter */
1156f79eed8SXander Huff #define GEM_LATECOLLCNT		0x0144 /* Late Collision Frame Counter */
1166f79eed8SXander Huff #define GEM_TXDEFERCNT		0x0148 /* Deferred Transmission Frame Counter */
1176f79eed8SXander Huff #define GEM_TXCSENSECNT		0x014c /* Carrier Sense Error Counter */
1183ff13f1cSXander Huff #define GEM_ORX			0x0150 /* Octets received */
1196f79eed8SXander Huff #define GEM_OCTRXL		0x0150 /* Octets received [31:0] */
1206f79eed8SXander Huff #define GEM_OCTRXH		0x0154 /* Octets received [47:32] */
1216f79eed8SXander Huff #define GEM_RXCNT		0x0158 /* Frames Received Counter */
1226f79eed8SXander Huff #define GEM_RXBROADCNT		0x015c /* Broadcast Frames Received Counter */
1236f79eed8SXander Huff #define GEM_RXMULTICNT		0x0160 /* Multicast Frames Received Counter */
1246f79eed8SXander Huff #define GEM_RXPAUSECNT		0x0164 /* Pause Frames Received Counter */
1256f79eed8SXander Huff #define GEM_RX64CNT		0x0168 /* 64 byte Frames RX Counter */
1266f79eed8SXander Huff #define GEM_RX65CNT		0x016c /* 65-127 byte Frames RX Counter */
1276f79eed8SXander Huff #define GEM_RX128CNT		0x0170 /* 128-255 byte Frames RX Counter */
1286f79eed8SXander Huff #define GEM_RX256CNT		0x0174 /* 256-511 byte Frames RX Counter */
1296f79eed8SXander Huff #define GEM_RX512CNT		0x0178 /* 512-1023 byte Frames RX Counter */
1306f79eed8SXander Huff #define GEM_RX1024CNT		0x017c /* 1024-1518 byte Frames RX Counter */
1316f79eed8SXander Huff #define GEM_RX1519CNT		0x0180 /* 1519+ byte Frames RX Counter */
1326f79eed8SXander Huff #define GEM_RXUNDRCNT		0x0184 /* Undersize Frames Received Counter */
1336f79eed8SXander Huff #define GEM_RXOVRCNT		0x0188 /* Oversize Frames Received Counter */
1346f79eed8SXander Huff #define GEM_RXJABCNT		0x018c /* Jabbers Received Counter */
1356f79eed8SXander Huff #define GEM_RXFCSCNT		0x0190 /* Frame Check Sequence Error Counter */
1366f79eed8SXander Huff #define GEM_RXLENGTHCNT		0x0194 /* Length Field Error Counter */
1376f79eed8SXander Huff #define GEM_RXSYMBCNT		0x0198 /* Symbol Error Counter */
1386f79eed8SXander Huff #define GEM_RXALIGNCNT		0x019c /* Alignment Error Counter */
1396f79eed8SXander Huff #define GEM_RXRESERRCNT		0x01a0 /* Receive Resource Error Counter */
1406f79eed8SXander Huff #define GEM_RXORCNT		0x01a4 /* Receive Overrun Counter */
1416f79eed8SXander Huff #define GEM_RXIPCCNT		0x01a8 /* IP header Checksum Error Counter */
1426f79eed8SXander Huff #define GEM_RXTCPCCNT		0x01ac /* TCP Checksum Error Counter */
1436f79eed8SXander Huff #define GEM_RXUDPCCNT		0x01b0 /* UDP Checksum Error Counter */
144c2594d80SAndrei.Pistirica@microchip.com #define GEM_TISUBN		0x01bc /* 1588 Timer Increment Sub-ns */
145c2594d80SAndrei.Pistirica@microchip.com #define GEM_TSH			0x01c0 /* 1588 Timer Seconds High */
146c2594d80SAndrei.Pistirica@microchip.com #define GEM_TSL			0x01d0 /* 1588 Timer Seconds Low */
147c2594d80SAndrei.Pistirica@microchip.com #define GEM_TN			0x01d4 /* 1588 Timer Nanoseconds */
148c2594d80SAndrei.Pistirica@microchip.com #define GEM_TA			0x01d8 /* 1588 Timer Adjust */
149c2594d80SAndrei.Pistirica@microchip.com #define GEM_TI			0x01dc /* 1588 Timer Increment */
150c2594d80SAndrei.Pistirica@microchip.com #define GEM_EFTSL		0x01e0 /* PTP Event Frame Tx Seconds Low */
151c2594d80SAndrei.Pistirica@microchip.com #define GEM_EFTN		0x01e4 /* PTP Event Frame Tx Nanoseconds */
152c2594d80SAndrei.Pistirica@microchip.com #define GEM_EFRSL		0x01e8 /* PTP Event Frame Rx Seconds Low */
153c2594d80SAndrei.Pistirica@microchip.com #define GEM_EFRN		0x01ec /* PTP Event Frame Rx Nanoseconds */
154c2594d80SAndrei.Pistirica@microchip.com #define GEM_PEFTSL		0x01f0 /* PTP Peer Event Frame Tx Secs Low */
155c2594d80SAndrei.Pistirica@microchip.com #define GEM_PEFTN		0x01f4 /* PTP Peer Event Frame Tx Ns */
156c2594d80SAndrei.Pistirica@microchip.com #define GEM_PEFRSL		0x01f8 /* PTP Peer Event Frame Rx Sec Low */
157c2594d80SAndrei.Pistirica@microchip.com #define GEM_PEFRN		0x01fc /* PTP Peer Event Frame Rx Ns */
1585c2fa0f6SXander Huff #define GEM_DCFG1		0x0280 /* Design Config 1 */
1595c2fa0f6SXander Huff #define GEM_DCFG2		0x0284 /* Design Config 2 */
1605c2fa0f6SXander Huff #define GEM_DCFG3		0x0288 /* Design Config 3 */
1615c2fa0f6SXander Huff #define GEM_DCFG4		0x028c /* Design Config 4 */
1625c2fa0f6SXander Huff #define GEM_DCFG5		0x0290 /* Design Config 5 */
1635c2fa0f6SXander Huff #define GEM_DCFG6		0x0294 /* Design Config 6 */
1645c2fa0f6SXander Huff #define GEM_DCFG7		0x0298 /* Design Config 7 */
165ae8223deSRafal Ozieblo #define GEM_DCFG8		0x029C /* Design Config 8 */
166404cd086SHarini Katakam #define GEM_DCFG10		0x02A4 /* Design Config 10 */
1679f2f381fSJeff Kirsher 
168ab91f0a9SRafal Ozieblo #define GEM_TXBDCTRL	0x04cc /* TX Buffer Descriptor control register */
169ab91f0a9SRafal Ozieblo #define GEM_RXBDCTRL	0x04d0 /* RX Buffer Descriptor control register */
170ab91f0a9SRafal Ozieblo 
171ae8223deSRafal Ozieblo /* Screener Type 2 match registers */
172ae8223deSRafal Ozieblo #define GEM_SCRT2		0x540
173ae8223deSRafal Ozieblo 
174ae8223deSRafal Ozieblo /* EtherType registers */
175ae8223deSRafal Ozieblo #define GEM_ETHT		0x06E0
176ae8223deSRafal Ozieblo 
177ae8223deSRafal Ozieblo /* Type 2 compare registers */
178ae8223deSRafal Ozieblo #define GEM_T2CMPW0		0x0700
179ae8223deSRafal Ozieblo #define GEM_T2CMPW1		0x0704
180ae8223deSRafal Ozieblo #define T2CMP_OFST(t2idx)	(t2idx * 2)
181ae8223deSRafal Ozieblo 
182ae8223deSRafal Ozieblo /* type 2 compare registers
183ae8223deSRafal Ozieblo  * each location requires 3 compare regs
184ae8223deSRafal Ozieblo  */
185ae8223deSRafal Ozieblo #define GEM_IP4SRC_CMP(idx)		(idx * 3)
186ae8223deSRafal Ozieblo #define GEM_IP4DST_CMP(idx)		(idx * 3 + 1)
187ae8223deSRafal Ozieblo #define GEM_PORT_CMP(idx)		(idx * 3 + 2)
188ae8223deSRafal Ozieblo 
189ae8223deSRafal Ozieblo /* Which screening type 2 EtherType register will be used (0 - 7) */
190ae8223deSRafal Ozieblo #define SCRT2_ETHT		0
191ae8223deSRafal Ozieblo 
19202c958ddSCyrille Pitchen #define GEM_ISR(hw_q)		(0x0400 + ((hw_q) << 2))
19302c958ddSCyrille Pitchen #define GEM_TBQP(hw_q)		(0x0440 + ((hw_q) << 2))
194fff8019aSHarini Katakam #define GEM_TBQPH(hw_q)		(0x04C8)
19502c958ddSCyrille Pitchen #define GEM_RBQP(hw_q)		(0x0480 + ((hw_q) << 2))
196ae1f2a56SRafal Ozieblo #define GEM_RBQS(hw_q)		(0x04A0 + ((hw_q) << 2))
197ae1f2a56SRafal Ozieblo #define GEM_RBQPH(hw_q)		(0x04D4)
19802c958ddSCyrille Pitchen #define GEM_IER(hw_q)		(0x0600 + ((hw_q) << 2))
19902c958ddSCyrille Pitchen #define GEM_IDR(hw_q)		(0x0620 + ((hw_q) << 2))
20002c958ddSCyrille Pitchen #define GEM_IMR(hw_q)		(0x0640 + ((hw_q) << 2))
20102c958ddSCyrille Pitchen 
2029f2f381fSJeff Kirsher /* Bitfields in NCR */
2035c2fa0f6SXander Huff #define MACB_LB_OFFSET		0 /* reserved */
2049f2f381fSJeff Kirsher #define MACB_LB_SIZE		1
2055c2fa0f6SXander Huff #define MACB_LLB_OFFSET		1 /* Loop back local */
2069f2f381fSJeff Kirsher #define MACB_LLB_SIZE		1
2075c2fa0f6SXander Huff #define MACB_RE_OFFSET		2 /* Receive enable */
2089f2f381fSJeff Kirsher #define MACB_RE_SIZE		1
2095c2fa0f6SXander Huff #define MACB_TE_OFFSET		3 /* Transmit enable */
2109f2f381fSJeff Kirsher #define MACB_TE_SIZE		1
2115c2fa0f6SXander Huff #define MACB_MPE_OFFSET		4 /* Management port enable */
2129f2f381fSJeff Kirsher #define MACB_MPE_SIZE		1
2135c2fa0f6SXander Huff #define MACB_CLRSTAT_OFFSET	5 /* Clear stats regs */
2149f2f381fSJeff Kirsher #define MACB_CLRSTAT_SIZE	1
2155c2fa0f6SXander Huff #define MACB_INCSTAT_OFFSET	6 /* Incremental stats regs */
2169f2f381fSJeff Kirsher #define MACB_INCSTAT_SIZE	1
2175c2fa0f6SXander Huff #define MACB_WESTAT_OFFSET	7 /* Write enable stats regs */
2189f2f381fSJeff Kirsher #define MACB_WESTAT_SIZE	1
2195c2fa0f6SXander Huff #define MACB_BP_OFFSET		8 /* Back pressure */
2209f2f381fSJeff Kirsher #define MACB_BP_SIZE		1
2215c2fa0f6SXander Huff #define MACB_TSTART_OFFSET	9 /* Start transmission */
2229f2f381fSJeff Kirsher #define MACB_TSTART_SIZE	1
2235c2fa0f6SXander Huff #define MACB_THALT_OFFSET	10 /* Transmit halt */
2249f2f381fSJeff Kirsher #define MACB_THALT_SIZE		1
2255c2fa0f6SXander Huff #define MACB_NCR_TPF_OFFSET	11 /* Transmit pause frame */
2269f2f381fSJeff Kirsher #define MACB_NCR_TPF_SIZE	1
2276f79eed8SXander Huff #define MACB_TZQ_OFFSET		12 /* Transmit zero quantum pause frame */
2289f2f381fSJeff Kirsher #define MACB_TZQ_SIZE		1
229c2594d80SAndrei.Pistirica@microchip.com #define MACB_SRTSM_OFFSET	15
230ab91f0a9SRafal Ozieblo #define MACB_OSSMODE_OFFSET 24 /* Enable One Step Synchro Mode */
231ab91f0a9SRafal Ozieblo #define MACB_OSSMODE_SIZE	1
2329f2f381fSJeff Kirsher 
2339f2f381fSJeff Kirsher /* Bitfields in NCFGR */
2345c2fa0f6SXander Huff #define MACB_SPD_OFFSET		0 /* Speed */
2359f2f381fSJeff Kirsher #define MACB_SPD_SIZE		1
2365c2fa0f6SXander Huff #define MACB_FD_OFFSET		1 /* Full duplex */
2379f2f381fSJeff Kirsher #define MACB_FD_SIZE		1
2385c2fa0f6SXander Huff #define MACB_BIT_RATE_OFFSET	2 /* Discard non-VLAN frames */
2399f2f381fSJeff Kirsher #define MACB_BIT_RATE_SIZE	1
2405c2fa0f6SXander Huff #define MACB_JFRAME_OFFSET	3 /* reserved */
2419f2f381fSJeff Kirsher #define MACB_JFRAME_SIZE	1
2425c2fa0f6SXander Huff #define MACB_CAF_OFFSET		4 /* Copy all frames */
2439f2f381fSJeff Kirsher #define MACB_CAF_SIZE		1
2445c2fa0f6SXander Huff #define MACB_NBC_OFFSET		5 /* No broadcast */
2459f2f381fSJeff Kirsher #define MACB_NBC_SIZE		1
2465c2fa0f6SXander Huff #define MACB_NCFGR_MTI_OFFSET	6 /* Multicast hash enable */
2479f2f381fSJeff Kirsher #define MACB_NCFGR_MTI_SIZE	1
2485c2fa0f6SXander Huff #define MACB_UNI_OFFSET		7 /* Unicast hash enable */
2499f2f381fSJeff Kirsher #define MACB_UNI_SIZE		1
2505c2fa0f6SXander Huff #define MACB_BIG_OFFSET		8 /* Receive 1536 byte frames */
2519f2f381fSJeff Kirsher #define MACB_BIG_SIZE		1
2526f79eed8SXander Huff #define MACB_EAE_OFFSET		9 /* External address match enable */
2539f2f381fSJeff Kirsher #define MACB_EAE_SIZE		1
2549f2f381fSJeff Kirsher #define MACB_CLK_OFFSET		10
2559f2f381fSJeff Kirsher #define MACB_CLK_SIZE		2
2565c2fa0f6SXander Huff #define MACB_RTY_OFFSET		12 /* Retry test */
2579f2f381fSJeff Kirsher #define MACB_RTY_SIZE		1
2585c2fa0f6SXander Huff #define MACB_PAE_OFFSET		13 /* Pause enable */
2599f2f381fSJeff Kirsher #define MACB_PAE_SIZE		1
2601fd3ca4eSJoachim Eastwood #define MACB_RM9200_RMII_OFFSET	13 /* AT91RM9200 only */
2611fd3ca4eSJoachim Eastwood #define MACB_RM9200_RMII_SIZE	1  /* AT91RM9200 only */
2625c2fa0f6SXander Huff #define MACB_RBOF_OFFSET	14 /* Receive buffer offset */
2639f2f381fSJeff Kirsher #define MACB_RBOF_SIZE		2
2646f79eed8SXander Huff #define MACB_RLCE_OFFSET	16 /* Length field error frame discard */
2659f2f381fSJeff Kirsher #define MACB_RLCE_SIZE		1
2665c2fa0f6SXander Huff #define MACB_DRFCS_OFFSET	17 /* FCS remove */
2679f2f381fSJeff Kirsher #define MACB_DRFCS_SIZE		1
2689f2f381fSJeff Kirsher #define MACB_EFRHD_OFFSET	18
2699f2f381fSJeff Kirsher #define MACB_EFRHD_SIZE		1
2709f2f381fSJeff Kirsher #define MACB_IRXFCS_OFFSET	19
2719f2f381fSJeff Kirsher #define MACB_IRXFCS_SIZE	1
2729f2f381fSJeff Kirsher 
27370c9f3d4SJamie Iles /* GEM specific NCFGR bitfields. */
2745c2fa0f6SXander Huff #define GEM_GBE_OFFSET		10 /* Gigabit mode enable */
275140b7552SPatrice Vilchez #define GEM_GBE_SIZE		1
276022be25cSPunnaiah Choudary Kalluri #define GEM_PCSSEL_OFFSET	11
277022be25cSPunnaiah Choudary Kalluri #define GEM_PCSSEL_SIZE		1
2785c2fa0f6SXander Huff #define GEM_CLK_OFFSET		18 /* MDC clock division */
27970c9f3d4SJamie Iles #define GEM_CLK_SIZE		3
2805c2fa0f6SXander Huff #define GEM_DBW_OFFSET		21 /* Data bus width */
281757a03c6SJamie Iles #define GEM_DBW_SIZE		2
282924ec53cSCyrille Pitchen #define GEM_RXCOEN_OFFSET	24
283924ec53cSCyrille Pitchen #define GEM_RXCOEN_SIZE		1
284022be25cSPunnaiah Choudary Kalluri #define GEM_SGMIIEN_OFFSET	27
285022be25cSPunnaiah Choudary Kalluri #define GEM_SGMIIEN_SIZE	1
286022be25cSPunnaiah Choudary Kalluri 
287757a03c6SJamie Iles 
288757a03c6SJamie Iles /* Constants for data bus width. */
2896f79eed8SXander Huff #define GEM_DBW32		0 /* 32 bit AMBA AHB data bus width */
2906f79eed8SXander Huff #define GEM_DBW64		1 /* 64 bit AMBA AHB data bus width */
2916f79eed8SXander Huff #define GEM_DBW128		2 /* 128 bit AMBA AHB data bus width */
292757a03c6SJamie Iles 
2930116da4fSJamie Iles /* Bitfields in DMACFG. */
2946f79eed8SXander Huff #define GEM_FBLDO_OFFSET	0 /* fixed burst length for DMA */
295b3e3bd71SNicolas Ferre #define GEM_FBLDO_SIZE		5
296a50dad35SArun Chandran #define GEM_ENDIA_DESC_OFFSET	6 /* endian swap mode for management descriptor access */
297ea373041SArun Chandran #define GEM_ENDIA_DESC_SIZE	1
298a50dad35SArun Chandran #define GEM_ENDIA_PKT_OFFSET	7 /* endian swap mode for packet data access */
299ea373041SArun Chandran #define GEM_ENDIA_PKT_SIZE	1
3006f79eed8SXander Huff #define GEM_RXBMS_OFFSET	8 /* RX packet buffer memory size select */
301b3e3bd71SNicolas Ferre #define GEM_RXBMS_SIZE		2
3026f79eed8SXander Huff #define GEM_TXPBMS_OFFSET	10 /* TX packet buffer memory size select */
303b3e3bd71SNicolas Ferre #define GEM_TXPBMS_SIZE		1
3046f79eed8SXander Huff #define GEM_TXCOEN_OFFSET	11 /* TX IP/TCP/UDP checksum gen offload */
305b3e3bd71SNicolas Ferre #define GEM_TXCOEN_SIZE		1
3066f79eed8SXander Huff #define GEM_RXBS_OFFSET		16 /* DMA receive buffer size */
3070116da4fSJamie Iles #define GEM_RXBS_SIZE		8
3085c2fa0f6SXander Huff #define GEM_DDRP_OFFSET		24 /* disc_when_no_ahb */
309b3e3bd71SNicolas Ferre #define GEM_DDRP_SIZE		1
3107b429614SRafal Ozieblo #define GEM_RXEXT_OFFSET	28 /* RX extended Buffer Descriptor mode */
3117b429614SRafal Ozieblo #define GEM_RXEXT_SIZE		1
3127b429614SRafal Ozieblo #define GEM_TXEXT_OFFSET	29 /* TX extended Buffer Descriptor mode */
3137b429614SRafal Ozieblo #define GEM_TXEXT_SIZE		1
314fff8019aSHarini Katakam #define GEM_ADDR64_OFFSET	30 /* Address bus width - 64b or 32b */
315fff8019aSHarini Katakam #define GEM_ADDR64_SIZE		1
316b3e3bd71SNicolas Ferre 
3170116da4fSJamie Iles 
3189f2f381fSJeff Kirsher /* Bitfields in NSR */
3195c2fa0f6SXander Huff #define MACB_NSR_LINK_OFFSET	0 /* pcs_link_state */
3209f2f381fSJeff Kirsher #define MACB_NSR_LINK_SIZE	1
3216f79eed8SXander Huff #define MACB_MDIO_OFFSET	1 /* status of the mdio_in pin */
3229f2f381fSJeff Kirsher #define MACB_MDIO_SIZE		1
3236f79eed8SXander Huff #define MACB_IDLE_OFFSET	2 /* The PHY management logic is idle */
3249f2f381fSJeff Kirsher #define MACB_IDLE_SIZE		1
3259f2f381fSJeff Kirsher 
3269f2f381fSJeff Kirsher /* Bitfields in TSR */
3275c2fa0f6SXander Huff #define MACB_UBR_OFFSET		0 /* Used bit read */
3289f2f381fSJeff Kirsher #define MACB_UBR_SIZE		1
3295c2fa0f6SXander Huff #define MACB_COL_OFFSET		1 /* Collision occurred */
3309f2f381fSJeff Kirsher #define MACB_COL_SIZE		1
3315c2fa0f6SXander Huff #define MACB_TSR_RLE_OFFSET	2 /* Retry limit exceeded */
3329f2f381fSJeff Kirsher #define MACB_TSR_RLE_SIZE	1
3335c2fa0f6SXander Huff #define MACB_TGO_OFFSET		3 /* Transmit go */
3349f2f381fSJeff Kirsher #define MACB_TGO_SIZE		1
3356f79eed8SXander Huff #define MACB_BEX_OFFSET		4 /* TX frame corruption due to AHB error */
3369f2f381fSJeff Kirsher #define MACB_BEX_SIZE		1
3371fd3ca4eSJoachim Eastwood #define MACB_RM9200_BNQ_OFFSET	4 /* AT91RM9200 only */
3381fd3ca4eSJoachim Eastwood #define MACB_RM9200_BNQ_SIZE	1 /* AT91RM9200 only */
3395c2fa0f6SXander Huff #define MACB_COMP_OFFSET	5 /* Trnasmit complete */
3409f2f381fSJeff Kirsher #define MACB_COMP_SIZE		1
3415c2fa0f6SXander Huff #define MACB_UND_OFFSET		6 /* Trnasmit under run */
3429f2f381fSJeff Kirsher #define MACB_UND_SIZE		1
3439f2f381fSJeff Kirsher 
3449f2f381fSJeff Kirsher /* Bitfields in RSR */
3455c2fa0f6SXander Huff #define MACB_BNA_OFFSET		0 /* Buffer not available */
3469f2f381fSJeff Kirsher #define MACB_BNA_SIZE		1
3475c2fa0f6SXander Huff #define MACB_REC_OFFSET		1 /* Frame received */
3489f2f381fSJeff Kirsher #define MACB_REC_SIZE		1
3495c2fa0f6SXander Huff #define MACB_OVR_OFFSET		2 /* Receive overrun */
3509f2f381fSJeff Kirsher #define MACB_OVR_SIZE		1
3519f2f381fSJeff Kirsher 
3529f2f381fSJeff Kirsher /* Bitfields in ISR/IER/IDR/IMR */
3535c2fa0f6SXander Huff #define MACB_MFD_OFFSET		0 /* Management frame sent */
3549f2f381fSJeff Kirsher #define MACB_MFD_SIZE		1
3555c2fa0f6SXander Huff #define MACB_RCOMP_OFFSET	1 /* Receive complete */
3569f2f381fSJeff Kirsher #define MACB_RCOMP_SIZE		1
3575c2fa0f6SXander Huff #define MACB_RXUBR_OFFSET	2 /* RX used bit read */
3589f2f381fSJeff Kirsher #define MACB_RXUBR_SIZE		1
3595c2fa0f6SXander Huff #define MACB_TXUBR_OFFSET	3 /* TX used bit read */
3609f2f381fSJeff Kirsher #define MACB_TXUBR_SIZE		1
3616f79eed8SXander Huff #define MACB_ISR_TUND_OFFSET	4 /* Enable TX buffer under run interrupt */
3629f2f381fSJeff Kirsher #define MACB_ISR_TUND_SIZE	1
3636f79eed8SXander Huff #define MACB_ISR_RLE_OFFSET	5 /* EN retry exceeded/late coll interrupt */
3649f2f381fSJeff Kirsher #define MACB_ISR_RLE_SIZE	1
3656f79eed8SXander Huff #define MACB_TXERR_OFFSET	6 /* EN TX frame corrupt from error interrupt */
3669f2f381fSJeff Kirsher #define MACB_TXERR_SIZE		1
3676f79eed8SXander Huff #define MACB_TCOMP_OFFSET	7 /* Enable transmit complete interrupt */
3689f2f381fSJeff Kirsher #define MACB_TCOMP_SIZE		1
3696f79eed8SXander Huff #define MACB_ISR_LINK_OFFSET	9 /* Enable link change interrupt */
3709f2f381fSJeff Kirsher #define MACB_ISR_LINK_SIZE	1
3716f79eed8SXander Huff #define MACB_ISR_ROVR_OFFSET	10 /* Enable receive overrun interrupt */
3729f2f381fSJeff Kirsher #define MACB_ISR_ROVR_SIZE	1
3736f79eed8SXander Huff #define MACB_HRESP_OFFSET	11 /* Enable hrsep not OK interrupt */
3749f2f381fSJeff Kirsher #define MACB_HRESP_SIZE		1
3756f79eed8SXander Huff #define MACB_PFR_OFFSET		12 /* Enable pause frame w/ quantum interrupt */
3769f2f381fSJeff Kirsher #define MACB_PFR_SIZE		1
3776f79eed8SXander Huff #define MACB_PTZ_OFFSET		13 /* Enable pause time zero interrupt */
3789f2f381fSJeff Kirsher #define MACB_PTZ_SIZE		1
3793e2a5e15SSergio Prado #define MACB_WOL_OFFSET		14 /* Enable wake-on-lan interrupt */
3803e2a5e15SSergio Prado #define MACB_WOL_SIZE		1
381c2594d80SAndrei.Pistirica@microchip.com #define MACB_DRQFR_OFFSET	18 /* PTP Delay Request Frame Received */
382c2594d80SAndrei.Pistirica@microchip.com #define MACB_DRQFR_SIZE		1
383c2594d80SAndrei.Pistirica@microchip.com #define MACB_SFR_OFFSET		19 /* PTP Sync Frame Received */
384c2594d80SAndrei.Pistirica@microchip.com #define MACB_SFR_SIZE		1
385c2594d80SAndrei.Pistirica@microchip.com #define MACB_DRQFT_OFFSET	20 /* PTP Delay Request Frame Transmitted */
386c2594d80SAndrei.Pistirica@microchip.com #define MACB_DRQFT_SIZE		1
387c2594d80SAndrei.Pistirica@microchip.com #define MACB_SFT_OFFSET		21 /* PTP Sync Frame Transmitted */
388c2594d80SAndrei.Pistirica@microchip.com #define MACB_SFT_SIZE		1
389c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRQFR_OFFSET	22 /* PDelay Request Frame Received */
390c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRQFR_SIZE	1
391c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRSFR_OFFSET	23 /* PDelay Response Frame Received */
392c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRSFR_SIZE	1
393c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRQFT_OFFSET	24 /* PDelay Request Frame Transmitted */
394c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRQFT_SIZE	1
395c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRSFT_OFFSET	25 /* PDelay Response Frame Transmitted */
396c2594d80SAndrei.Pistirica@microchip.com #define MACB_PDRSFT_SIZE	1
397c2594d80SAndrei.Pistirica@microchip.com #define MACB_SRI_OFFSET		26 /* TSU Seconds Register Increment */
398c2594d80SAndrei.Pistirica@microchip.com #define MACB_SRI_SIZE		1
399c2594d80SAndrei.Pistirica@microchip.com 
400c2594d80SAndrei.Pistirica@microchip.com /* Timer increment fields */
401c2594d80SAndrei.Pistirica@microchip.com #define MACB_TI_CNS_OFFSET	0
402c2594d80SAndrei.Pistirica@microchip.com #define MACB_TI_CNS_SIZE	8
403c2594d80SAndrei.Pistirica@microchip.com #define MACB_TI_ACNS_OFFSET	8
404c2594d80SAndrei.Pistirica@microchip.com #define MACB_TI_ACNS_SIZE	8
405c2594d80SAndrei.Pistirica@microchip.com #define MACB_TI_NIT_OFFSET	16
406c2594d80SAndrei.Pistirica@microchip.com #define MACB_TI_NIT_SIZE	8
4079f2f381fSJeff Kirsher 
4089f2f381fSJeff Kirsher /* Bitfields in MAN */
4095c2fa0f6SXander Huff #define MACB_DATA_OFFSET	0 /* data */
4109f2f381fSJeff Kirsher #define MACB_DATA_SIZE		16
4115c2fa0f6SXander Huff #define MACB_CODE_OFFSET	16 /* Must be written to 10 */
4129f2f381fSJeff Kirsher #define MACB_CODE_SIZE		2
4135c2fa0f6SXander Huff #define MACB_REGA_OFFSET	18 /* Register address */
4149f2f381fSJeff Kirsher #define MACB_REGA_SIZE		5
4155c2fa0f6SXander Huff #define MACB_PHYA_OFFSET	23 /* PHY address */
4169f2f381fSJeff Kirsher #define MACB_PHYA_SIZE		5
4176f79eed8SXander Huff #define MACB_RW_OFFSET		28 /* Operation. 10 is read. 01 is write. */
4189f2f381fSJeff Kirsher #define MACB_RW_SIZE		2
4196f79eed8SXander Huff #define MACB_SOF_OFFSET		30 /* Must be written to 1 for Clause 22 */
4209f2f381fSJeff Kirsher #define MACB_SOF_SIZE		2
4219f2f381fSJeff Kirsher 
4229f2f381fSJeff Kirsher /* Bitfields in USRIO (AVR32) */
4239f2f381fSJeff Kirsher #define MACB_MII_OFFSET				0
4249f2f381fSJeff Kirsher #define MACB_MII_SIZE				1
4259f2f381fSJeff Kirsher #define MACB_EAM_OFFSET				1
4269f2f381fSJeff Kirsher #define MACB_EAM_SIZE				1
4279f2f381fSJeff Kirsher #define MACB_TX_PAUSE_OFFSET			2
4289f2f381fSJeff Kirsher #define MACB_TX_PAUSE_SIZE			1
4299f2f381fSJeff Kirsher #define MACB_TX_PAUSE_ZERO_OFFSET		3
4309f2f381fSJeff Kirsher #define MACB_TX_PAUSE_ZERO_SIZE			1
4319f2f381fSJeff Kirsher 
4329f2f381fSJeff Kirsher /* Bitfields in USRIO (AT91) */
4339f2f381fSJeff Kirsher #define MACB_RMII_OFFSET			0
4349f2f381fSJeff Kirsher #define MACB_RMII_SIZE				1
435140b7552SPatrice Vilchez #define GEM_RGMII_OFFSET			0 /* GEM gigabit mode */
436140b7552SPatrice Vilchez #define GEM_RGMII_SIZE				1
4379f2f381fSJeff Kirsher #define MACB_CLKEN_OFFSET			1
4389f2f381fSJeff Kirsher #define MACB_CLKEN_SIZE				1
4399f2f381fSJeff Kirsher 
4409f2f381fSJeff Kirsher /* Bitfields in WOL */
4419f2f381fSJeff Kirsher #define MACB_IP_OFFSET				0
4429f2f381fSJeff Kirsher #define MACB_IP_SIZE				16
4439f2f381fSJeff Kirsher #define MACB_MAG_OFFSET				16
4449f2f381fSJeff Kirsher #define MACB_MAG_SIZE				1
4459f2f381fSJeff Kirsher #define MACB_ARP_OFFSET				17
4469f2f381fSJeff Kirsher #define MACB_ARP_SIZE				1
4479f2f381fSJeff Kirsher #define MACB_SA1_OFFSET				18
4489f2f381fSJeff Kirsher #define MACB_SA1_SIZE				1
4499f2f381fSJeff Kirsher #define MACB_WOL_MTI_OFFSET			19
4509f2f381fSJeff Kirsher #define MACB_WOL_MTI_SIZE			1
4519f2f381fSJeff Kirsher 
452f75ba50bSJamie Iles /* Bitfields in MID */
453f75ba50bSJamie Iles #define MACB_IDNUM_OFFSET			16
454d941bebfSPunnaiah Choudary Kalluri #define MACB_IDNUM_SIZE				12
455f75ba50bSJamie Iles #define MACB_REV_OFFSET				0
456f75ba50bSJamie Iles #define MACB_REV_SIZE				16
457f75ba50bSJamie Iles 
458757a03c6SJamie Iles /* Bitfields in DCFG1. */
459581df9e1SNicolas Ferre #define GEM_IRQCOR_OFFSET			23
460581df9e1SNicolas Ferre #define GEM_IRQCOR_SIZE				1
461757a03c6SJamie Iles #define GEM_DBWDEF_OFFSET			25
462757a03c6SJamie Iles #define GEM_DBWDEF_SIZE				3
463757a03c6SJamie Iles 
464e175587fSNicolas Ferre /* Bitfields in DCFG2. */
465e175587fSNicolas Ferre #define GEM_RX_PKT_BUFF_OFFSET			20
466e175587fSNicolas Ferre #define GEM_RX_PKT_BUFF_SIZE			1
467e175587fSNicolas Ferre #define GEM_TX_PKT_BUFF_OFFSET			21
468e175587fSNicolas Ferre #define GEM_TX_PKT_BUFF_SIZE			1
469e175587fSNicolas Ferre 
4707b429614SRafal Ozieblo 
4717b429614SRafal Ozieblo /* Bitfields in DCFG5. */
4727b429614SRafal Ozieblo #define GEM_TSU_OFFSET				8
4737b429614SRafal Ozieblo #define GEM_TSU_SIZE				1
4747b429614SRafal Ozieblo 
4751629dd4fSRafal Ozieblo /* Bitfields in DCFG6. */
4761629dd4fSRafal Ozieblo #define GEM_PBUF_LSO_OFFSET			27
4771629dd4fSRafal Ozieblo #define GEM_PBUF_LSO_SIZE			1
478dc97a89eSRafal Ozieblo #define GEM_DAW64_OFFSET			23
479dc97a89eSRafal Ozieblo #define GEM_DAW64_SIZE				1
4801629dd4fSRafal Ozieblo 
481ae8223deSRafal Ozieblo /* Bitfields in DCFG8. */
482ae8223deSRafal Ozieblo #define GEM_T1SCR_OFFSET			24
483ae8223deSRafal Ozieblo #define GEM_T1SCR_SIZE				8
484ae8223deSRafal Ozieblo #define GEM_T2SCR_OFFSET			16
485ae8223deSRafal Ozieblo #define GEM_T2SCR_SIZE				8
486ae8223deSRafal Ozieblo #define GEM_SCR2ETH_OFFSET			8
487ae8223deSRafal Ozieblo #define GEM_SCR2ETH_SIZE			8
488ae8223deSRafal Ozieblo #define GEM_SCR2CMP_OFFSET			0
489ae8223deSRafal Ozieblo #define GEM_SCR2CMP_SIZE			8
490ae8223deSRafal Ozieblo 
491404cd086SHarini Katakam /* Bitfields in DCFG10 */
492404cd086SHarini Katakam #define GEM_TXBD_RDBUFF_OFFSET			12
493404cd086SHarini Katakam #define GEM_TXBD_RDBUFF_SIZE			4
494404cd086SHarini Katakam #define GEM_RXBD_RDBUFF_OFFSET			8
495404cd086SHarini Katakam #define GEM_RXBD_RDBUFF_SIZE			4
496404cd086SHarini Katakam 
497c2594d80SAndrei.Pistirica@microchip.com /* Bitfields in TISUBN */
498c2594d80SAndrei.Pistirica@microchip.com #define GEM_SUBNSINCR_OFFSET			0
499c2594d80SAndrei.Pistirica@microchip.com #define GEM_SUBNSINCR_SIZE			16
500c2594d80SAndrei.Pistirica@microchip.com 
501c2594d80SAndrei.Pistirica@microchip.com /* Bitfields in TI */
502c2594d80SAndrei.Pistirica@microchip.com #define GEM_NSINCR_OFFSET			0
503c2594d80SAndrei.Pistirica@microchip.com #define GEM_NSINCR_SIZE				8
504c2594d80SAndrei.Pistirica@microchip.com 
505ab91f0a9SRafal Ozieblo /* Bitfields in TSH */
506ab91f0a9SRafal Ozieblo #define GEM_TSH_OFFSET				0 /* TSU timer value (s). MSB [47:32] of seconds timer count */
507ab91f0a9SRafal Ozieblo #define GEM_TSH_SIZE				16
508ab91f0a9SRafal Ozieblo 
509ab91f0a9SRafal Ozieblo /* Bitfields in TSL */
510ab91f0a9SRafal Ozieblo #define GEM_TSL_OFFSET				0 /* TSU timer value (s). LSB [31:0] of seconds timer count */
511ab91f0a9SRafal Ozieblo #define GEM_TSL_SIZE				32
512ab91f0a9SRafal Ozieblo 
513ab91f0a9SRafal Ozieblo /* Bitfields in TN */
514ab91f0a9SRafal Ozieblo #define GEM_TN_OFFSET				0 /* TSU timer value (ns) */
515ab91f0a9SRafal Ozieblo #define GEM_TN_SIZE					30
516ab91f0a9SRafal Ozieblo 
517ab91f0a9SRafal Ozieblo /* Bitfields in TXBDCTRL */
518ab91f0a9SRafal Ozieblo #define GEM_TXTSMODE_OFFSET			4 /* TX Descriptor Timestamp Insertion mode */
519ab91f0a9SRafal Ozieblo #define GEM_TXTSMODE_SIZE			2
520ab91f0a9SRafal Ozieblo 
521ab91f0a9SRafal Ozieblo /* Bitfields in RXBDCTRL */
522ab91f0a9SRafal Ozieblo #define GEM_RXTSMODE_OFFSET			4 /* RX Descriptor Timestamp Insertion mode */
523ab91f0a9SRafal Ozieblo #define GEM_RXTSMODE_SIZE			2
524ab91f0a9SRafal Ozieblo 
525ae8223deSRafal Ozieblo /* Bitfields in SCRT2 */
526ae8223deSRafal Ozieblo #define GEM_QUEUE_OFFSET			0 /* Queue Number */
527ae8223deSRafal Ozieblo #define GEM_QUEUE_SIZE				4
528ae8223deSRafal Ozieblo #define GEM_VLANPR_OFFSET			4 /* VLAN Priority */
529ae8223deSRafal Ozieblo #define GEM_VLANPR_SIZE				3
530ae8223deSRafal Ozieblo #define GEM_VLANEN_OFFSET			8 /* VLAN Enable */
531ae8223deSRafal Ozieblo #define GEM_VLANEN_SIZE				1
532ae8223deSRafal Ozieblo #define GEM_ETHT2IDX_OFFSET			9 /* Index to screener type 2 EtherType register */
533ae8223deSRafal Ozieblo #define GEM_ETHT2IDX_SIZE			3
534ae8223deSRafal Ozieblo #define GEM_ETHTEN_OFFSET			12 /* EtherType Enable */
535ae8223deSRafal Ozieblo #define GEM_ETHTEN_SIZE				1
536ae8223deSRafal Ozieblo #define GEM_CMPA_OFFSET				13 /* Compare A - Index to screener type 2 Compare register */
537ae8223deSRafal Ozieblo #define GEM_CMPA_SIZE				5
538ae8223deSRafal Ozieblo #define GEM_CMPAEN_OFFSET			18 /* Compare A Enable */
539ae8223deSRafal Ozieblo #define GEM_CMPAEN_SIZE				1
540ae8223deSRafal Ozieblo #define GEM_CMPB_OFFSET				19 /* Compare B - Index to screener type 2 Compare register */
541ae8223deSRafal Ozieblo #define GEM_CMPB_SIZE				5
542ae8223deSRafal Ozieblo #define GEM_CMPBEN_OFFSET			24 /* Compare B Enable */
543ae8223deSRafal Ozieblo #define GEM_CMPBEN_SIZE				1
544ae8223deSRafal Ozieblo #define GEM_CMPC_OFFSET				25 /* Compare C - Index to screener type 2 Compare register */
545ae8223deSRafal Ozieblo #define GEM_CMPC_SIZE				5
546ae8223deSRafal Ozieblo #define GEM_CMPCEN_OFFSET			30 /* Compare C Enable */
547ae8223deSRafal Ozieblo #define GEM_CMPCEN_SIZE				1
548ae8223deSRafal Ozieblo 
549ae8223deSRafal Ozieblo /* Bitfields in ETHT */
550ae8223deSRafal Ozieblo #define GEM_ETHTCMP_OFFSET			0 /* EtherType compare value */
551ae8223deSRafal Ozieblo #define GEM_ETHTCMP_SIZE			16
552ae8223deSRafal Ozieblo 
553ae8223deSRafal Ozieblo /* Bitfields in T2CMPW0 */
554ae8223deSRafal Ozieblo #define GEM_T2CMP_OFFSET			16 /* 0xFFFF0000 compare value */
555ae8223deSRafal Ozieblo #define GEM_T2CMP_SIZE				16
556ae8223deSRafal Ozieblo #define GEM_T2MASK_OFFSET			0 /* 0x0000FFFF compare value or mask */
557ae8223deSRafal Ozieblo #define GEM_T2MASK_SIZE				16
558ae8223deSRafal Ozieblo 
559ae8223deSRafal Ozieblo /* Bitfields in T2CMPW1 */
560ae8223deSRafal Ozieblo #define GEM_T2DISMSK_OFFSET			9 /* disable mask */
561ae8223deSRafal Ozieblo #define GEM_T2DISMSK_SIZE			1
562ae8223deSRafal Ozieblo #define GEM_T2CMPOFST_OFFSET			7 /* compare offset */
563ae8223deSRafal Ozieblo #define GEM_T2CMPOFST_SIZE			2
564ae8223deSRafal Ozieblo #define GEM_T2OFST_OFFSET			0 /* offset value */
565ae8223deSRafal Ozieblo #define GEM_T2OFST_SIZE				7
566ae8223deSRafal Ozieblo 
567ae8223deSRafal Ozieblo /* Offset for screener type 2 compare values (T2CMPOFST).
568ae8223deSRafal Ozieblo  * Note the offset is applied after the specified point,
569ae8223deSRafal Ozieblo  * e.g. GEM_T2COMPOFST_ETYPE denotes the EtherType field, so an offset
570ae8223deSRafal Ozieblo  * of 12 bytes from this would be the source IP address in an IP header
571ae8223deSRafal Ozieblo  */
572ae8223deSRafal Ozieblo #define GEM_T2COMPOFST_SOF		0
573ae8223deSRafal Ozieblo #define GEM_T2COMPOFST_ETYPE	1
574ae8223deSRafal Ozieblo #define GEM_T2COMPOFST_IPHDR	2
575ae8223deSRafal Ozieblo #define GEM_T2COMPOFST_TCPUDP	3
576ae8223deSRafal Ozieblo 
577ae8223deSRafal Ozieblo /* offset from EtherType to IP address */
578ae8223deSRafal Ozieblo #define ETYPE_SRCIP_OFFSET			12
579ae8223deSRafal Ozieblo #define ETYPE_DSTIP_OFFSET			16
580ae8223deSRafal Ozieblo 
581ae8223deSRafal Ozieblo /* offset from IP header to port */
582ae8223deSRafal Ozieblo #define IPHDR_SRCPORT_OFFSET		0
583ae8223deSRafal Ozieblo #define IPHDR_DSTPORT_OFFSET		2
584ae8223deSRafal Ozieblo 
585ab91f0a9SRafal Ozieblo /* Transmit DMA buffer descriptor Word 1 */
586ab91f0a9SRafal Ozieblo #define GEM_DMA_TXVALID_OFFSET		23 /* timestamp has been captured in the Buffer Descriptor */
587ab91f0a9SRafal Ozieblo #define GEM_DMA_TXVALID_SIZE		1
588ab91f0a9SRafal Ozieblo 
589ab91f0a9SRafal Ozieblo /* Receive DMA buffer descriptor Word 0 */
590ab91f0a9SRafal Ozieblo #define GEM_DMA_RXVALID_OFFSET		2 /* indicates a valid timestamp in the Buffer Descriptor */
591ab91f0a9SRafal Ozieblo #define GEM_DMA_RXVALID_SIZE		1
592ab91f0a9SRafal Ozieblo 
593ab91f0a9SRafal Ozieblo /* DMA buffer descriptor Word 2 (32 bit addressing) or Word 4 (64 bit addressing) */
594ab91f0a9SRafal Ozieblo #define GEM_DMA_SECL_OFFSET			30 /* Timestamp seconds[1:0]  */
595ab91f0a9SRafal Ozieblo #define GEM_DMA_SECL_SIZE			2
596ab91f0a9SRafal Ozieblo #define GEM_DMA_NSEC_OFFSET			0 /* Timestamp nanosecs [29:0] */
597ab91f0a9SRafal Ozieblo #define GEM_DMA_NSEC_SIZE			30
598ab91f0a9SRafal Ozieblo 
599ab91f0a9SRafal Ozieblo /* DMA buffer descriptor Word 3 (32 bit addressing) or Word 5 (64 bit addressing) */
600ab91f0a9SRafal Ozieblo 
601ab91f0a9SRafal Ozieblo /* New hardware supports 12 bit precision of timestamp in DMA buffer descriptor.
602ab91f0a9SRafal Ozieblo  * Old hardware supports only 6 bit precision but it is enough for PTP.
603ab91f0a9SRafal Ozieblo  * Less accuracy is used always instead of checking hardware version.
604ab91f0a9SRafal Ozieblo  */
605ab91f0a9SRafal Ozieblo #define GEM_DMA_SECH_OFFSET			0 /* Timestamp seconds[5:2] */
606ab91f0a9SRafal Ozieblo #define GEM_DMA_SECH_SIZE			4
607ab91f0a9SRafal Ozieblo #define GEM_DMA_SEC_WIDTH			(GEM_DMA_SECH_SIZE + GEM_DMA_SECL_SIZE)
608ab91f0a9SRafal Ozieblo #define GEM_DMA_SEC_TOP				(1 << GEM_DMA_SEC_WIDTH)
609ab91f0a9SRafal Ozieblo #define GEM_DMA_SEC_MASK			(GEM_DMA_SEC_TOP - 1)
610ab91f0a9SRafal Ozieblo 
611c2594d80SAndrei.Pistirica@microchip.com /* Bitfields in ADJ */
612c2594d80SAndrei.Pistirica@microchip.com #define GEM_ADDSUB_OFFSET			31
613c2594d80SAndrei.Pistirica@microchip.com #define GEM_ADDSUB_SIZE				1
6149f2f381fSJeff Kirsher /* Constants for CLK */
6159f2f381fSJeff Kirsher #define MACB_CLK_DIV8				0
6169f2f381fSJeff Kirsher #define MACB_CLK_DIV16				1
6179f2f381fSJeff Kirsher #define MACB_CLK_DIV32				2
6189f2f381fSJeff Kirsher #define MACB_CLK_DIV64				3
6199f2f381fSJeff Kirsher 
62070c9f3d4SJamie Iles /* GEM specific constants for CLK. */
62170c9f3d4SJamie Iles #define GEM_CLK_DIV8				0
62270c9f3d4SJamie Iles #define GEM_CLK_DIV16				1
62370c9f3d4SJamie Iles #define GEM_CLK_DIV32				2
62470c9f3d4SJamie Iles #define GEM_CLK_DIV48				3
62570c9f3d4SJamie Iles #define GEM_CLK_DIV64				4
62670c9f3d4SJamie Iles #define GEM_CLK_DIV96				5
62770c9f3d4SJamie Iles 
6289f2f381fSJeff Kirsher /* Constants for MAN register */
6299f2f381fSJeff Kirsher #define MACB_MAN_SOF				1
6309f2f381fSJeff Kirsher #define MACB_MAN_WRITE				1
6319f2f381fSJeff Kirsher #define MACB_MAN_READ				2
6329f2f381fSJeff Kirsher #define MACB_MAN_CODE				2
6339f2f381fSJeff Kirsher 
634581df9e1SNicolas Ferre /* Capability mask bits */
635e175587fSNicolas Ferre #define MACB_CAPS_ISR_CLEAR_ON_WRITE		0x00000001
636a8487489SBoris BREZILLON #define MACB_CAPS_USRIO_HAS_CLKEN		0x00000002
6376bdaa5e9SNicolas Ferre #define MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII	0x00000004
638222ca8e0SNathan Sullivan #define MACB_CAPS_NO_GIGABIT_HALF		0x00000008
639ce721a70SNeil Armstrong #define MACB_CAPS_USRIO_DISABLED		0x00000010
640c5181895SHarini Katakam #define MACB_CAPS_JUMBO				0x00000020
641c2594d80SAndrei.Pistirica@microchip.com #define MACB_CAPS_GEM_HAS_PTP			0x00000040
642404cd086SHarini Katakam #define MACB_CAPS_BD_RD_PREFETCH		0x00000080
643e501070eSHarini Katakam #define MACB_CAPS_NEEDS_RSTONUBR		0x00000100
644e175587fSNicolas Ferre #define MACB_CAPS_FIFO_MODE			0x10000000
645e175587fSNicolas Ferre #define MACB_CAPS_GIGABIT_MODE_AVAILABLE	0x20000000
646a4c35ed3SCyrille Pitchen #define MACB_CAPS_SG_DISABLED			0x40000000
647e175587fSNicolas Ferre #define MACB_CAPS_MACB_IS_GEM			0x80000000
648581df9e1SNicolas Ferre 
6491629dd4fSRafal Ozieblo /* LSO settings */
6501629dd4fSRafal Ozieblo #define MACB_LSO_UFO_ENABLE			0x01
6511629dd4fSRafal Ozieblo #define MACB_LSO_TSO_ENABLE			0x02
6521629dd4fSRafal Ozieblo 
6539f2f381fSJeff Kirsher /* Bit manipulation macros */
6549f2f381fSJeff Kirsher #define MACB_BIT(name)					\
6559f2f381fSJeff Kirsher 	(1 << MACB_##name##_OFFSET)
6569f2f381fSJeff Kirsher #define MACB_BF(name,value)				\
6579f2f381fSJeff Kirsher 	(((value) & ((1 << MACB_##name##_SIZE) - 1))	\
6589f2f381fSJeff Kirsher 	 << MACB_##name##_OFFSET)
6599f2f381fSJeff Kirsher #define MACB_BFEXT(name,value)\
6609f2f381fSJeff Kirsher 	(((value) >> MACB_##name##_OFFSET)		\
6619f2f381fSJeff Kirsher 	 & ((1 << MACB_##name##_SIZE) - 1))
6629f2f381fSJeff Kirsher #define MACB_BFINS(name,value,old)			\
6639f2f381fSJeff Kirsher 	(((old) & ~(((1 << MACB_##name##_SIZE) - 1)	\
6649f2f381fSJeff Kirsher 		    << MACB_##name##_OFFSET))		\
6659f2f381fSJeff Kirsher 	 | MACB_BF(name,value))
6669f2f381fSJeff Kirsher 
667f75ba50bSJamie Iles #define GEM_BIT(name)					\
668f75ba50bSJamie Iles 	(1 << GEM_##name##_OFFSET)
669f75ba50bSJamie Iles #define GEM_BF(name, value)				\
670f75ba50bSJamie Iles 	(((value) & ((1 << GEM_##name##_SIZE) - 1))	\
671f75ba50bSJamie Iles 	 << GEM_##name##_OFFSET)
672f75ba50bSJamie Iles #define GEM_BFEXT(name, value)\
673f75ba50bSJamie Iles 	(((value) >> GEM_##name##_OFFSET)		\
674f75ba50bSJamie Iles 	 & ((1 << GEM_##name##_SIZE) - 1))
675f75ba50bSJamie Iles #define GEM_BFINS(name, value, old)			\
676f75ba50bSJamie Iles 	(((old) & ~(((1 << GEM_##name##_SIZE) - 1)	\
677f75ba50bSJamie Iles 		    << GEM_##name##_OFFSET))		\
678f75ba50bSJamie Iles 	 | GEM_BF(name, value))
679f75ba50bSJamie Iles 
6809f2f381fSJeff Kirsher /* Register access macros */
6817a6e0706SDavid S. Miller #define macb_readl(port, reg)		(port)->macb_reg_readl((port), MACB_##reg)
6827a6e0706SDavid S. Miller #define macb_writel(port, reg, value)	(port)->macb_reg_writel((port), MACB_##reg, (value))
6837a6e0706SDavid S. Miller #define gem_readl(port, reg)		(port)->macb_reg_readl((port), GEM_##reg)
6847a6e0706SDavid S. Miller #define gem_writel(port, reg, value)	(port)->macb_reg_writel((port), GEM_##reg, (value))
6857a6e0706SDavid S. Miller #define queue_readl(queue, reg)		(queue)->bp->macb_reg_readl((queue)->bp, (queue)->reg)
6867a6e0706SDavid S. Miller #define queue_writel(queue, reg, value)	(queue)->bp->macb_reg_writel((queue)->bp, (queue)->reg, (value))
687ae8223deSRafal Ozieblo #define gem_readl_n(port, reg, idx)		(port)->macb_reg_readl((port), GEM_##reg + idx * 4)
688ae8223deSRafal Ozieblo #define gem_writel_n(port, reg, idx, value)	(port)->macb_reg_writel((port), GEM_##reg + idx * 4, (value))
689f75ba50bSJamie Iles 
690ab91f0a9SRafal Ozieblo #define PTP_TS_BUFFER_SIZE		128 /* must be power of 2 */
691ab91f0a9SRafal Ozieblo 
6926f79eed8SXander Huff /* Conditional GEM/MACB macros.  These perform the operation to the correct
693f75ba50bSJamie Iles  * register dependent on whether the device is a GEM or a MACB.  For registers
694f75ba50bSJamie Iles  * and bitfields that are common across both devices, use macb_{read,write}l
695f75ba50bSJamie Iles  * to avoid the cost of the conditional.
696f75ba50bSJamie Iles  */
697f75ba50bSJamie Iles #define macb_or_gem_writel(__bp, __reg, __value) \
698f75ba50bSJamie Iles 	({ \
699f75ba50bSJamie Iles 		if (macb_is_gem((__bp))) \
700f75ba50bSJamie Iles 			gem_writel((__bp), __reg, __value); \
701f75ba50bSJamie Iles 		else \
702f75ba50bSJamie Iles 			macb_writel((__bp), __reg, __value); \
703f75ba50bSJamie Iles 	})
704f75ba50bSJamie Iles 
705f75ba50bSJamie Iles #define macb_or_gem_readl(__bp, __reg) \
706f75ba50bSJamie Iles 	({ \
707f75ba50bSJamie Iles 		u32 __v; \
708f75ba50bSJamie Iles 		if (macb_is_gem((__bp))) \
709f75ba50bSJamie Iles 			__v = gem_readl((__bp), __reg); \
710f75ba50bSJamie Iles 		else \
711f75ba50bSJamie Iles 			__v = macb_readl((__bp), __reg); \
712f75ba50bSJamie Iles 		__v; \
713f75ba50bSJamie Iles 	})
7149f2f381fSJeff Kirsher 
7158beb79b7SHarini Katakam #define MACB_READ_NSR(bp)	macb_readl(bp, NSR)
7168beb79b7SHarini Katakam 
7176f79eed8SXander Huff /* struct macb_dma_desc - Hardware DMA descriptor
71855054a16SHavard Skinnemoen  * @addr: DMA address of data buffer
71955054a16SHavard Skinnemoen  * @ctrl: Control and status bits
72055054a16SHavard Skinnemoen  */
72155054a16SHavard Skinnemoen struct macb_dma_desc {
7229f2f381fSJeff Kirsher 	u32	addr;
7239f2f381fSJeff Kirsher 	u32	ctrl;
724dc97a89eSRafal Ozieblo };
725dc97a89eSRafal Ozieblo 
7267b429614SRafal Ozieblo #ifdef MACB_EXT_DESC
7277b429614SRafal Ozieblo #define HW_DMA_CAP_32B		0
7287b429614SRafal Ozieblo #define HW_DMA_CAP_64B		(1 << 0)
7297b429614SRafal Ozieblo #define HW_DMA_CAP_PTP		(1 << 1)
7307b429614SRafal Ozieblo #define HW_DMA_CAP_64B_PTP	(HW_DMA_CAP_64B | HW_DMA_CAP_PTP)
731dc97a89eSRafal Ozieblo 
732dc97a89eSRafal Ozieblo struct macb_dma_desc_64 {
733fff8019aSHarini Katakam 	u32 addrh;
734fff8019aSHarini Katakam 	u32 resvd;
7359f2f381fSJeff Kirsher };
7367b429614SRafal Ozieblo 
7377b429614SRafal Ozieblo struct macb_dma_desc_ptp {
7387b429614SRafal Ozieblo 	u32	ts_1;
7397b429614SRafal Ozieblo 	u32	ts_2;
7407b429614SRafal Ozieblo };
741ab91f0a9SRafal Ozieblo 
742ab91f0a9SRafal Ozieblo struct gem_tx_ts {
743ab91f0a9SRafal Ozieblo 	struct sk_buff *skb;
744ab91f0a9SRafal Ozieblo 	struct macb_dma_desc_ptp desc_ptp;
745ab91f0a9SRafal Ozieblo };
746dc97a89eSRafal Ozieblo #endif
7479f2f381fSJeff Kirsher 
7489f2f381fSJeff Kirsher /* DMA descriptor bitfields */
7499f2f381fSJeff Kirsher #define MACB_RX_USED_OFFSET			0
7509f2f381fSJeff Kirsher #define MACB_RX_USED_SIZE			1
7519f2f381fSJeff Kirsher #define MACB_RX_WRAP_OFFSET			1
7529f2f381fSJeff Kirsher #define MACB_RX_WRAP_SIZE			1
7539f2f381fSJeff Kirsher #define MACB_RX_WADDR_OFFSET			2
7549f2f381fSJeff Kirsher #define MACB_RX_WADDR_SIZE			30
7559f2f381fSJeff Kirsher 
7569f2f381fSJeff Kirsher #define MACB_RX_FRMLEN_OFFSET			0
7579f2f381fSJeff Kirsher #define MACB_RX_FRMLEN_SIZE			12
7589f2f381fSJeff Kirsher #define MACB_RX_OFFSET_OFFSET			12
7599f2f381fSJeff Kirsher #define MACB_RX_OFFSET_SIZE			2
7609f2f381fSJeff Kirsher #define MACB_RX_SOF_OFFSET			14
7619f2f381fSJeff Kirsher #define MACB_RX_SOF_SIZE			1
7629f2f381fSJeff Kirsher #define MACB_RX_EOF_OFFSET			15
7639f2f381fSJeff Kirsher #define MACB_RX_EOF_SIZE			1
7649f2f381fSJeff Kirsher #define MACB_RX_CFI_OFFSET			16
7659f2f381fSJeff Kirsher #define MACB_RX_CFI_SIZE			1
7669f2f381fSJeff Kirsher #define MACB_RX_VLAN_PRI_OFFSET			17
7679f2f381fSJeff Kirsher #define MACB_RX_VLAN_PRI_SIZE			3
7689f2f381fSJeff Kirsher #define MACB_RX_PRI_TAG_OFFSET			20
7699f2f381fSJeff Kirsher #define MACB_RX_PRI_TAG_SIZE			1
7709f2f381fSJeff Kirsher #define MACB_RX_VLAN_TAG_OFFSET			21
7719f2f381fSJeff Kirsher #define MACB_RX_VLAN_TAG_SIZE			1
7729f2f381fSJeff Kirsher #define MACB_RX_TYPEID_MATCH_OFFSET		22
7739f2f381fSJeff Kirsher #define MACB_RX_TYPEID_MATCH_SIZE		1
7749f2f381fSJeff Kirsher #define MACB_RX_SA4_MATCH_OFFSET		23
7759f2f381fSJeff Kirsher #define MACB_RX_SA4_MATCH_SIZE			1
7769f2f381fSJeff Kirsher #define MACB_RX_SA3_MATCH_OFFSET		24
7779f2f381fSJeff Kirsher #define MACB_RX_SA3_MATCH_SIZE			1
7789f2f381fSJeff Kirsher #define MACB_RX_SA2_MATCH_OFFSET		25
7799f2f381fSJeff Kirsher #define MACB_RX_SA2_MATCH_SIZE			1
7809f2f381fSJeff Kirsher #define MACB_RX_SA1_MATCH_OFFSET		26
7819f2f381fSJeff Kirsher #define MACB_RX_SA1_MATCH_SIZE			1
7829f2f381fSJeff Kirsher #define MACB_RX_EXT_MATCH_OFFSET		28
7839f2f381fSJeff Kirsher #define MACB_RX_EXT_MATCH_SIZE			1
7849f2f381fSJeff Kirsher #define MACB_RX_UHASH_MATCH_OFFSET		29
7859f2f381fSJeff Kirsher #define MACB_RX_UHASH_MATCH_SIZE		1
7869f2f381fSJeff Kirsher #define MACB_RX_MHASH_MATCH_OFFSET		30
7879f2f381fSJeff Kirsher #define MACB_RX_MHASH_MATCH_SIZE		1
7889f2f381fSJeff Kirsher #define MACB_RX_BROADCAST_OFFSET		31
7899f2f381fSJeff Kirsher #define MACB_RX_BROADCAST_SIZE			1
7909f2f381fSJeff Kirsher 
79198b5a0f4SHarini Katakam #define MACB_RX_FRMLEN_MASK			0xFFF
79298b5a0f4SHarini Katakam #define MACB_RX_JFRMLEN_MASK			0x3FFF
79398b5a0f4SHarini Katakam 
794924ec53cSCyrille Pitchen /* RX checksum offload disabled: bit 24 clear in NCFGR */
795924ec53cSCyrille Pitchen #define GEM_RX_TYPEID_MATCH_OFFSET		22
796924ec53cSCyrille Pitchen #define GEM_RX_TYPEID_MATCH_SIZE		2
797924ec53cSCyrille Pitchen 
798924ec53cSCyrille Pitchen /* RX checksum offload enabled: bit 24 set in NCFGR */
799924ec53cSCyrille Pitchen #define GEM_RX_CSUM_OFFSET			22
800924ec53cSCyrille Pitchen #define GEM_RX_CSUM_SIZE			2
801924ec53cSCyrille Pitchen 
8029f2f381fSJeff Kirsher #define MACB_TX_FRMLEN_OFFSET			0
8039f2f381fSJeff Kirsher #define MACB_TX_FRMLEN_SIZE			11
8049f2f381fSJeff Kirsher #define MACB_TX_LAST_OFFSET			15
8059f2f381fSJeff Kirsher #define MACB_TX_LAST_SIZE			1
8069f2f381fSJeff Kirsher #define MACB_TX_NOCRC_OFFSET			16
8079f2f381fSJeff Kirsher #define MACB_TX_NOCRC_SIZE			1
8081629dd4fSRafal Ozieblo #define MACB_MSS_MFS_OFFSET			16
8091629dd4fSRafal Ozieblo #define MACB_MSS_MFS_SIZE			14
8101629dd4fSRafal Ozieblo #define MACB_TX_LSO_OFFSET			17
8111629dd4fSRafal Ozieblo #define MACB_TX_LSO_SIZE			2
8121629dd4fSRafal Ozieblo #define MACB_TX_TCP_SEQ_SRC_OFFSET		19
8131629dd4fSRafal Ozieblo #define MACB_TX_TCP_SEQ_SRC_SIZE		1
8149f2f381fSJeff Kirsher #define MACB_TX_BUF_EXHAUSTED_OFFSET		27
8159f2f381fSJeff Kirsher #define MACB_TX_BUF_EXHAUSTED_SIZE		1
8169f2f381fSJeff Kirsher #define MACB_TX_UNDERRUN_OFFSET			28
8179f2f381fSJeff Kirsher #define MACB_TX_UNDERRUN_SIZE			1
8189f2f381fSJeff Kirsher #define MACB_TX_ERROR_OFFSET			29
8199f2f381fSJeff Kirsher #define MACB_TX_ERROR_SIZE			1
8209f2f381fSJeff Kirsher #define MACB_TX_WRAP_OFFSET			30
8219f2f381fSJeff Kirsher #define MACB_TX_WRAP_SIZE			1
8229f2f381fSJeff Kirsher #define MACB_TX_USED_OFFSET			31
8239f2f381fSJeff Kirsher #define MACB_TX_USED_SIZE			1
8249f2f381fSJeff Kirsher 
825a4c35ed3SCyrille Pitchen #define GEM_TX_FRMLEN_OFFSET			0
826a4c35ed3SCyrille Pitchen #define GEM_TX_FRMLEN_SIZE			14
827a4c35ed3SCyrille Pitchen 
828924ec53cSCyrille Pitchen /* Buffer descriptor constants */
829924ec53cSCyrille Pitchen #define GEM_RX_CSUM_NONE			0
830924ec53cSCyrille Pitchen #define GEM_RX_CSUM_IP_ONLY			1
831924ec53cSCyrille Pitchen #define GEM_RX_CSUM_IP_TCP			2
832924ec53cSCyrille Pitchen #define GEM_RX_CSUM_IP_UDP			3
833924ec53cSCyrille Pitchen 
834924ec53cSCyrille Pitchen /* limit RX checksum offload to TCP and UDP packets */
835924ec53cSCyrille Pitchen #define GEM_RX_CSUM_CHECKED_MASK		2
836924ec53cSCyrille Pitchen 
8376f79eed8SXander Huff /* struct macb_tx_skb - data about an skb which is being transmitted
838a4c35ed3SCyrille Pitchen  * @skb: skb currently being transmitted, only set for the last buffer
839a4c35ed3SCyrille Pitchen  *       of the frame
840a4c35ed3SCyrille Pitchen  * @mapping: DMA address of the skb's fragment buffer
841a4c35ed3SCyrille Pitchen  * @size: size of the DMA mapped buffer
842a4c35ed3SCyrille Pitchen  * @mapped_as_page: true when buffer was mapped with skb_frag_dma_map(),
843a4c35ed3SCyrille Pitchen  *                  false when buffer was mapped with dma_map_single()
84455054a16SHavard Skinnemoen  */
84555054a16SHavard Skinnemoen struct macb_tx_skb {
8469f2f381fSJeff Kirsher 	struct sk_buff		*skb;
8479f2f381fSJeff Kirsher 	dma_addr_t		mapping;
848a4c35ed3SCyrille Pitchen 	size_t			size;
849a4c35ed3SCyrille Pitchen 	bool			mapped_as_page;
8509f2f381fSJeff Kirsher };
8519f2f381fSJeff Kirsher 
8526f79eed8SXander Huff /* Hardware-collected statistics. Used when updating the network
8539f2f381fSJeff Kirsher  * device stats by a periodic timer.
8549f2f381fSJeff Kirsher  */
8559f2f381fSJeff Kirsher struct macb_stats {
8569f2f381fSJeff Kirsher 	u32	rx_pause_frames;
8579f2f381fSJeff Kirsher 	u32	tx_ok;
8589f2f381fSJeff Kirsher 	u32	tx_single_cols;
8599f2f381fSJeff Kirsher 	u32	tx_multiple_cols;
8609f2f381fSJeff Kirsher 	u32	rx_ok;
8619f2f381fSJeff Kirsher 	u32	rx_fcs_errors;
8629f2f381fSJeff Kirsher 	u32	rx_align_errors;
8639f2f381fSJeff Kirsher 	u32	tx_deferred;
8649f2f381fSJeff Kirsher 	u32	tx_late_cols;
8659f2f381fSJeff Kirsher 	u32	tx_excessive_cols;
8669f2f381fSJeff Kirsher 	u32	tx_underruns;
8679f2f381fSJeff Kirsher 	u32	tx_carrier_errors;
8689f2f381fSJeff Kirsher 	u32	rx_resource_errors;
8699f2f381fSJeff Kirsher 	u32	rx_overruns;
8709f2f381fSJeff Kirsher 	u32	rx_symbol_errors;
8719f2f381fSJeff Kirsher 	u32	rx_oversize_pkts;
8729f2f381fSJeff Kirsher 	u32	rx_jabbers;
8739f2f381fSJeff Kirsher 	u32	rx_undersize_pkts;
8749f2f381fSJeff Kirsher 	u32	sqe_test_errors;
8759f2f381fSJeff Kirsher 	u32	rx_length_mismatch;
8769f2f381fSJeff Kirsher 	u32	tx_pause_frames;
8779f2f381fSJeff Kirsher };
8789f2f381fSJeff Kirsher 
879a494ed8eSJamie Iles struct gem_stats {
880a494ed8eSJamie Iles 	u32	tx_octets_31_0;
881a494ed8eSJamie Iles 	u32	tx_octets_47_32;
882a494ed8eSJamie Iles 	u32	tx_frames;
883a494ed8eSJamie Iles 	u32	tx_broadcast_frames;
884a494ed8eSJamie Iles 	u32	tx_multicast_frames;
885a494ed8eSJamie Iles 	u32	tx_pause_frames;
886a494ed8eSJamie Iles 	u32	tx_64_byte_frames;
887a494ed8eSJamie Iles 	u32	tx_65_127_byte_frames;
888a494ed8eSJamie Iles 	u32	tx_128_255_byte_frames;
889a494ed8eSJamie Iles 	u32	tx_256_511_byte_frames;
890a494ed8eSJamie Iles 	u32	tx_512_1023_byte_frames;
891a494ed8eSJamie Iles 	u32	tx_1024_1518_byte_frames;
892a494ed8eSJamie Iles 	u32	tx_greater_than_1518_byte_frames;
893a494ed8eSJamie Iles 	u32	tx_underrun;
894a494ed8eSJamie Iles 	u32	tx_single_collision_frames;
895a494ed8eSJamie Iles 	u32	tx_multiple_collision_frames;
896a494ed8eSJamie Iles 	u32	tx_excessive_collisions;
897a494ed8eSJamie Iles 	u32	tx_late_collisions;
898a494ed8eSJamie Iles 	u32	tx_deferred_frames;
899a494ed8eSJamie Iles 	u32	tx_carrier_sense_errors;
900a494ed8eSJamie Iles 	u32	rx_octets_31_0;
901a494ed8eSJamie Iles 	u32	rx_octets_47_32;
902a494ed8eSJamie Iles 	u32	rx_frames;
903a494ed8eSJamie Iles 	u32	rx_broadcast_frames;
904a494ed8eSJamie Iles 	u32	rx_multicast_frames;
905a494ed8eSJamie Iles 	u32	rx_pause_frames;
906a494ed8eSJamie Iles 	u32	rx_64_byte_frames;
907a494ed8eSJamie Iles 	u32	rx_65_127_byte_frames;
908a494ed8eSJamie Iles 	u32	rx_128_255_byte_frames;
909a494ed8eSJamie Iles 	u32	rx_256_511_byte_frames;
910a494ed8eSJamie Iles 	u32	rx_512_1023_byte_frames;
911a494ed8eSJamie Iles 	u32	rx_1024_1518_byte_frames;
912a494ed8eSJamie Iles 	u32	rx_greater_than_1518_byte_frames;
913a494ed8eSJamie Iles 	u32	rx_undersized_frames;
914a494ed8eSJamie Iles 	u32	rx_oversize_frames;
915a494ed8eSJamie Iles 	u32	rx_jabbers;
916a494ed8eSJamie Iles 	u32	rx_frame_check_sequence_errors;
917a494ed8eSJamie Iles 	u32	rx_length_field_frame_errors;
918a494ed8eSJamie Iles 	u32	rx_symbol_errors;
919a494ed8eSJamie Iles 	u32	rx_alignment_errors;
920a494ed8eSJamie Iles 	u32	rx_resource_errors;
921a494ed8eSJamie Iles 	u32	rx_overruns;
922a494ed8eSJamie Iles 	u32	rx_ip_header_checksum_errors;
923a494ed8eSJamie Iles 	u32	rx_tcp_checksum_errors;
924a494ed8eSJamie Iles 	u32	rx_udp_checksum_errors;
925a494ed8eSJamie Iles };
926a494ed8eSJamie Iles 
9273ff13f1cSXander Huff /* Describes the name and offset of an individual statistic register, as
9283ff13f1cSXander Huff  * returned by `ethtool -S`. Also describes which net_device_stats statistics
9293ff13f1cSXander Huff  * this register should contribute to.
9303ff13f1cSXander Huff  */
9313ff13f1cSXander Huff struct gem_statistic {
9323ff13f1cSXander Huff 	char stat_string[ETH_GSTRING_LEN];
9333ff13f1cSXander Huff 	int offset;
9343ff13f1cSXander Huff 	u32 stat_bits;
9353ff13f1cSXander Huff };
9363ff13f1cSXander Huff 
9373ff13f1cSXander Huff /* Bitfield defs for net_device_stat statistics */
9383ff13f1cSXander Huff #define GEM_NDS_RXERR_OFFSET		0
9393ff13f1cSXander Huff #define GEM_NDS_RXLENERR_OFFSET		1
9403ff13f1cSXander Huff #define GEM_NDS_RXOVERERR_OFFSET	2
9413ff13f1cSXander Huff #define GEM_NDS_RXCRCERR_OFFSET		3
9423ff13f1cSXander Huff #define GEM_NDS_RXFRAMEERR_OFFSET	4
9433ff13f1cSXander Huff #define GEM_NDS_RXFIFOERR_OFFSET	5
9443ff13f1cSXander Huff #define GEM_NDS_TXERR_OFFSET		6
9453ff13f1cSXander Huff #define GEM_NDS_TXABORTEDERR_OFFSET	7
9463ff13f1cSXander Huff #define GEM_NDS_TXCARRIERERR_OFFSET	8
9473ff13f1cSXander Huff #define GEM_NDS_TXFIFOERR_OFFSET	9
9483ff13f1cSXander Huff #define GEM_NDS_COLLISIONS_OFFSET	10
9493ff13f1cSXander Huff 
9503ff13f1cSXander Huff #define GEM_STAT_TITLE(name, title) GEM_STAT_TITLE_BITS(name, title, 0)
9513ff13f1cSXander Huff #define GEM_STAT_TITLE_BITS(name, title, bits) {	\
9523ff13f1cSXander Huff 	.stat_string = title,				\
9533ff13f1cSXander Huff 	.offset = GEM_##name,				\
9543ff13f1cSXander Huff 	.stat_bits = bits				\
9553ff13f1cSXander Huff }
9563ff13f1cSXander Huff 
9573ff13f1cSXander Huff /* list of gem statistic registers. The names MUST match the
9583ff13f1cSXander Huff  * corresponding GEM_* definitions.
9593ff13f1cSXander Huff  */
9603ff13f1cSXander Huff static const struct gem_statistic gem_statistics[] = {
9613ff13f1cSXander Huff 	GEM_STAT_TITLE(OCTTXL, "tx_octets"), /* OCTTXH combined with OCTTXL */
9623ff13f1cSXander Huff 	GEM_STAT_TITLE(TXCNT, "tx_frames"),
9633ff13f1cSXander Huff 	GEM_STAT_TITLE(TXBCCNT, "tx_broadcast_frames"),
9643ff13f1cSXander Huff 	GEM_STAT_TITLE(TXMCCNT, "tx_multicast_frames"),
9653ff13f1cSXander Huff 	GEM_STAT_TITLE(TXPAUSECNT, "tx_pause_frames"),
9663ff13f1cSXander Huff 	GEM_STAT_TITLE(TX64CNT, "tx_64_byte_frames"),
9673ff13f1cSXander Huff 	GEM_STAT_TITLE(TX65CNT, "tx_65_127_byte_frames"),
9683ff13f1cSXander Huff 	GEM_STAT_TITLE(TX128CNT, "tx_128_255_byte_frames"),
9693ff13f1cSXander Huff 	GEM_STAT_TITLE(TX256CNT, "tx_256_511_byte_frames"),
9703ff13f1cSXander Huff 	GEM_STAT_TITLE(TX512CNT, "tx_512_1023_byte_frames"),
9713ff13f1cSXander Huff 	GEM_STAT_TITLE(TX1024CNT, "tx_1024_1518_byte_frames"),
9723ff13f1cSXander Huff 	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"),
9733ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(TXURUNCNT, "tx_underrun",
9743ff13f1cSXander Huff 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_TXFIFOERR)),
9753ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(SNGLCOLLCNT, "tx_single_collision_frames",
9763ff13f1cSXander Huff 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
9773ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(MULTICOLLCNT, "tx_multiple_collision_frames",
9783ff13f1cSXander Huff 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
9793ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(EXCESSCOLLCNT, "tx_excessive_collisions",
9803ff13f1cSXander Huff 			    GEM_BIT(NDS_TXERR)|
9813ff13f1cSXander Huff 			    GEM_BIT(NDS_TXABORTEDERR)|
9823ff13f1cSXander Huff 			    GEM_BIT(NDS_COLLISIONS)),
9833ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(LATECOLLCNT, "tx_late_collisions",
9843ff13f1cSXander Huff 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
9853ff13f1cSXander Huff 	GEM_STAT_TITLE(TXDEFERCNT, "tx_deferred_frames"),
9863ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(TXCSENSECNT, "tx_carrier_sense_errors",
9873ff13f1cSXander Huff 			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
9883ff13f1cSXander Huff 	GEM_STAT_TITLE(OCTRXL, "rx_octets"), /* OCTRXH combined with OCTRXL */
9893ff13f1cSXander Huff 	GEM_STAT_TITLE(RXCNT, "rx_frames"),
9903ff13f1cSXander Huff 	GEM_STAT_TITLE(RXBROADCNT, "rx_broadcast_frames"),
9913ff13f1cSXander Huff 	GEM_STAT_TITLE(RXMULTICNT, "rx_multicast_frames"),
9923ff13f1cSXander Huff 	GEM_STAT_TITLE(RXPAUSECNT, "rx_pause_frames"),
9933ff13f1cSXander Huff 	GEM_STAT_TITLE(RX64CNT, "rx_64_byte_frames"),
9943ff13f1cSXander Huff 	GEM_STAT_TITLE(RX65CNT, "rx_65_127_byte_frames"),
9953ff13f1cSXander Huff 	GEM_STAT_TITLE(RX128CNT, "rx_128_255_byte_frames"),
9963ff13f1cSXander Huff 	GEM_STAT_TITLE(RX256CNT, "rx_256_511_byte_frames"),
9973ff13f1cSXander Huff 	GEM_STAT_TITLE(RX512CNT, "rx_512_1023_byte_frames"),
9983ff13f1cSXander Huff 	GEM_STAT_TITLE(RX1024CNT, "rx_1024_1518_byte_frames"),
9993ff13f1cSXander Huff 	GEM_STAT_TITLE(RX1519CNT, "rx_greater_than_1518_byte_frames"),
10003ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXUNDRCNT, "rx_undersized_frames",
10013ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)),
10023ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXOVRCNT, "rx_oversize_frames",
10033ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)),
10043ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXJABCNT, "rx_jabbers",
10053ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)),
10063ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXFCSCNT, "rx_frame_check_sequence_errors",
10073ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXCRCERR)),
10083ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXLENGTHCNT, "rx_length_field_frame_errors",
10093ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)),
10103ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXSYMBCNT, "rx_symbol_errors",
10113ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXFRAMEERR)),
10123ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXALIGNCNT, "rx_alignment_errors",
10133ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXOVERERR)),
10143ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXRESERRCNT, "rx_resource_errors",
10153ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXOVERERR)),
10163ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXORCNT, "rx_overruns",
10173ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXFIFOERR)),
10183ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXIPCCNT, "rx_ip_header_checksum_errors",
10193ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)),
10203ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXTCPCCNT, "rx_tcp_checksum_errors",
10213ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)),
10223ff13f1cSXander Huff 	GEM_STAT_TITLE_BITS(RXUDPCCNT, "rx_udp_checksum_errors",
10233ff13f1cSXander Huff 			    GEM_BIT(NDS_RXERR)),
10243ff13f1cSXander Huff };
10253ff13f1cSXander Huff 
10263ff13f1cSXander Huff #define GEM_STATS_LEN ARRAY_SIZE(gem_statistics)
10273ff13f1cSXander Huff 
1028512286bbSRafal Ozieblo #define QUEUE_STAT_TITLE(title) {	\
1029512286bbSRafal Ozieblo 	.stat_string = title,			\
1030512286bbSRafal Ozieblo }
1031512286bbSRafal Ozieblo 
1032512286bbSRafal Ozieblo /* per queue statistics, each should be unsigned long type */
1033512286bbSRafal Ozieblo struct queue_stats {
1034512286bbSRafal Ozieblo 	union {
1035512286bbSRafal Ozieblo 		unsigned long first;
1036512286bbSRafal Ozieblo 		unsigned long rx_packets;
1037512286bbSRafal Ozieblo 	};
1038512286bbSRafal Ozieblo 	unsigned long rx_bytes;
1039512286bbSRafal Ozieblo 	unsigned long rx_dropped;
1040512286bbSRafal Ozieblo 	unsigned long tx_packets;
1041512286bbSRafal Ozieblo 	unsigned long tx_bytes;
1042512286bbSRafal Ozieblo 	unsigned long tx_dropped;
1043512286bbSRafal Ozieblo };
1044512286bbSRafal Ozieblo 
1045512286bbSRafal Ozieblo static const struct gem_statistic queue_statistics[] = {
1046512286bbSRafal Ozieblo 		QUEUE_STAT_TITLE("rx_packets"),
1047512286bbSRafal Ozieblo 		QUEUE_STAT_TITLE("rx_bytes"),
1048512286bbSRafal Ozieblo 		QUEUE_STAT_TITLE("rx_dropped"),
1049512286bbSRafal Ozieblo 		QUEUE_STAT_TITLE("tx_packets"),
1050512286bbSRafal Ozieblo 		QUEUE_STAT_TITLE("tx_bytes"),
1051512286bbSRafal Ozieblo 		QUEUE_STAT_TITLE("tx_dropped"),
1052512286bbSRafal Ozieblo };
1053512286bbSRafal Ozieblo 
1054512286bbSRafal Ozieblo #define QUEUE_STATS_LEN ARRAY_SIZE(queue_statistics)
1055512286bbSRafal Ozieblo 
10564df95131SNicolas Ferre struct macb;
1057ae1f2a56SRafal Ozieblo struct macb_queue;
10584df95131SNicolas Ferre 
10594df95131SNicolas Ferre struct macb_or_gem_ops {
10604df95131SNicolas Ferre 	int	(*mog_alloc_rx_buffers)(struct macb *bp);
10614df95131SNicolas Ferre 	void	(*mog_free_rx_buffers)(struct macb *bp);
10624df95131SNicolas Ferre 	void	(*mog_init_rings)(struct macb *bp);
1063ae1f2a56SRafal Ozieblo 	int	(*mog_rx)(struct macb_queue *queue, int budget);
10644df95131SNicolas Ferre };
10654df95131SNicolas Ferre 
1066c2594d80SAndrei.Pistirica@microchip.com /* MACB-PTP interface: adapt to platform needs. */
1067c2594d80SAndrei.Pistirica@microchip.com struct macb_ptp_info {
1068c2594d80SAndrei.Pistirica@microchip.com 	void (*ptp_init)(struct net_device *ndev);
1069c2594d80SAndrei.Pistirica@microchip.com 	void (*ptp_remove)(struct net_device *ndev);
1070c2594d80SAndrei.Pistirica@microchip.com 	s32 (*get_ptp_max_adj)(void);
1071c2594d80SAndrei.Pistirica@microchip.com 	unsigned int (*get_tsu_rate)(struct macb *bp);
1072c2594d80SAndrei.Pistirica@microchip.com 	int (*get_ts_info)(struct net_device *dev,
1073c2594d80SAndrei.Pistirica@microchip.com 			   struct ethtool_ts_info *info);
1074c2594d80SAndrei.Pistirica@microchip.com 	int (*get_hwtst)(struct net_device *netdev,
1075c2594d80SAndrei.Pistirica@microchip.com 			 struct ifreq *ifr);
1076c2594d80SAndrei.Pistirica@microchip.com 	int (*set_hwtst)(struct net_device *netdev,
1077c2594d80SAndrei.Pistirica@microchip.com 			 struct ifreq *ifr, int cmd);
1078c2594d80SAndrei.Pistirica@microchip.com };
1079c2594d80SAndrei.Pistirica@microchip.com 
1080c1e85c6cSClaudiu Beznea struct macb_pm_data {
1081c1e85c6cSClaudiu Beznea 	u32 scrt2;
1082c1e85c6cSClaudiu Beznea 	u32 usrio;
1083c1e85c6cSClaudiu Beznea };
1084c1e85c6cSClaudiu Beznea 
1085e175587fSNicolas Ferre struct macb_config {
1086e175587fSNicolas Ferre 	u32			caps;
1087e175587fSNicolas Ferre 	unsigned int		dma_burst_length;
1088c69618b3SNicolas Ferre 	int	(*clk_init)(struct platform_device *pdev, struct clk **pclk,
1089aead88bdSshubhrajyoti.datta@xilinx.com 			    struct clk **hclk, struct clk **tx_clk,
1090f5473d1dSHarini Katakam 			    struct clk **rx_clk, struct clk **tsu_clk);
1091421d9df0SCyrille Pitchen 	int	(*init)(struct platform_device *pdev);
109298b5a0f4SHarini Katakam 	int	jumbo_max_len;
1093e175587fSNicolas Ferre };
1094e175587fSNicolas Ferre 
1095ab91f0a9SRafal Ozieblo struct tsu_incr {
1096ab91f0a9SRafal Ozieblo 	u32 sub_ns;
1097ab91f0a9SRafal Ozieblo 	u32 ns;
1098ab91f0a9SRafal Ozieblo };
1099ab91f0a9SRafal Ozieblo 
110002c958ddSCyrille Pitchen struct macb_queue {
110102c958ddSCyrille Pitchen 	struct macb		*bp;
110202c958ddSCyrille Pitchen 	int			irq;
110302c958ddSCyrille Pitchen 
110402c958ddSCyrille Pitchen 	unsigned int		ISR;
110502c958ddSCyrille Pitchen 	unsigned int		IER;
110602c958ddSCyrille Pitchen 	unsigned int		IDR;
110702c958ddSCyrille Pitchen 	unsigned int		IMR;
110802c958ddSCyrille Pitchen 	unsigned int		TBQP;
1109fff8019aSHarini Katakam 	unsigned int		TBQPH;
1110ae1f2a56SRafal Ozieblo 	unsigned int		RBQS;
1111ae1f2a56SRafal Ozieblo 	unsigned int		RBQP;
1112ae1f2a56SRafal Ozieblo 	unsigned int		RBQPH;
111302c958ddSCyrille Pitchen 
111402c958ddSCyrille Pitchen 	unsigned int		tx_head, tx_tail;
111502c958ddSCyrille Pitchen 	struct macb_dma_desc	*tx_ring;
111602c958ddSCyrille Pitchen 	struct macb_tx_skb	*tx_skb;
111702c958ddSCyrille Pitchen 	dma_addr_t		tx_ring_dma;
111802c958ddSCyrille Pitchen 	struct work_struct	tx_error_task;
1119ab91f0a9SRafal Ozieblo 
1120ae1f2a56SRafal Ozieblo 	dma_addr_t		rx_ring_dma;
1121ae1f2a56SRafal Ozieblo 	dma_addr_t		rx_buffers_dma;
1122ae1f2a56SRafal Ozieblo 	unsigned int		rx_tail;
1123ae1f2a56SRafal Ozieblo 	unsigned int		rx_prepared_head;
1124ae1f2a56SRafal Ozieblo 	struct macb_dma_desc	*rx_ring;
1125ae1f2a56SRafal Ozieblo 	struct sk_buff		**rx_skbuff;
1126ae1f2a56SRafal Ozieblo 	void			*rx_buffers;
1127ae1f2a56SRafal Ozieblo 	struct napi_struct	napi;
1128512286bbSRafal Ozieblo 	struct queue_stats stats;
1129ae1f2a56SRafal Ozieblo 
1130ab91f0a9SRafal Ozieblo #ifdef CONFIG_MACB_USE_HWSTAMP
1131ab91f0a9SRafal Ozieblo 	struct work_struct	tx_ts_task;
1132ab91f0a9SRafal Ozieblo 	unsigned int		tx_ts_head, tx_ts_tail;
1133ab91f0a9SRafal Ozieblo 	struct gem_tx_ts	tx_timestamps[PTP_TS_BUFFER_SIZE];
1134ab91f0a9SRafal Ozieblo #endif
113502c958ddSCyrille Pitchen };
113602c958ddSCyrille Pitchen 
1137ae8223deSRafal Ozieblo struct ethtool_rx_fs_item {
1138ae8223deSRafal Ozieblo 	struct ethtool_rx_flow_spec fs;
1139ae8223deSRafal Ozieblo 	struct list_head list;
1140ae8223deSRafal Ozieblo };
1141ae8223deSRafal Ozieblo 
1142ae8223deSRafal Ozieblo struct ethtool_rx_fs_list {
1143ae8223deSRafal Ozieblo 	struct list_head list;
1144ae8223deSRafal Ozieblo 	unsigned int count;
1145ae8223deSRafal Ozieblo };
1146ae8223deSRafal Ozieblo 
11479f2f381fSJeff Kirsher struct macb {
11489f2f381fSJeff Kirsher 	void __iomem		*regs;
1149f2ce8a9eSAndy Shevchenko 	bool			native_io;
1150f2ce8a9eSAndy Shevchenko 
1151f2ce8a9eSAndy Shevchenko 	/* hardware IO accessors */
11527a6e0706SDavid S. Miller 	u32	(*macb_reg_readl)(struct macb *bp, int offset);
11537a6e0706SDavid S. Miller 	void	(*macb_reg_writel)(struct macb *bp, int offset, u32 value);
11549f2f381fSJeff Kirsher 
11551b44791aSNicolas Ferre 	size_t			rx_buffer_size;
11569f2f381fSJeff Kirsher 
1157b410d13eSZach Brown 	unsigned int		rx_ring_size;
1158b410d13eSZach Brown 	unsigned int		tx_ring_size;
1159b410d13eSZach Brown 
116002c958ddSCyrille Pitchen 	unsigned int		num_queues;
1161bfa0914aSNicolas Ferre 	unsigned int		queue_mask;
116202c958ddSCyrille Pitchen 	struct macb_queue	queues[MACB_MAX_QUEUES];
11639f2f381fSJeff Kirsher 
11649f2f381fSJeff Kirsher 	spinlock_t		lock;
11659f2f381fSJeff Kirsher 	struct platform_device	*pdev;
11669f2f381fSJeff Kirsher 	struct clk		*pclk;
11679f2f381fSJeff Kirsher 	struct clk		*hclk;
1168e1824dfeSSoren Brinkmann 	struct clk		*tx_clk;
1169aead88bdSshubhrajyoti.datta@xilinx.com 	struct clk		*rx_clk;
1170f5473d1dSHarini Katakam 	struct clk		*tsu_clk;
11719f2f381fSJeff Kirsher 	struct net_device	*dev;
1172a494ed8eSJamie Iles 	union {
1173a494ed8eSJamie Iles 		struct macb_stats	macb;
1174a494ed8eSJamie Iles 		struct gem_stats	gem;
1175a494ed8eSJamie Iles 	}			hw_stats;
11769f2f381fSJeff Kirsher 
11774df95131SNicolas Ferre 	struct macb_or_gem_ops	macbgem_ops;
11784df95131SNicolas Ferre 
11799f2f381fSJeff Kirsher 	struct mii_bus		*mii_bus;
1180dacdbb4dSMichael Grzeschik 	struct device_node	*phy_node;
11818bcbf82fSAndy Shevchenko 	int 			link;
11828bcbf82fSAndy Shevchenko 	int 			speed;
11838bcbf82fSAndy Shevchenko 	int 			duplex;
1184fb97a846SJean-Christophe PLAGNIOL-VILLARD 
1185581df9e1SNicolas Ferre 	u32			caps;
1186e175587fSNicolas Ferre 	unsigned int		dma_burst_length;
1187581df9e1SNicolas Ferre 
1188fb97a846SJean-Christophe PLAGNIOL-VILLARD 	phy_interface_t		phy_interface;
1189b85008b7SJoachim Eastwood 
11904dda6f6dSJoachim Eastwood 	/* AT91RM9200 transmit */
1191b85008b7SJoachim Eastwood 	struct sk_buff *skb;			/* holds skb until xmit interrupt completes */
1192b85008b7SJoachim Eastwood 	dma_addr_t skb_physaddr;		/* phys addr from pci_map_single */
1193b85008b7SJoachim Eastwood 	int skb_length;				/* saved skb length for pci_unmap_single */
1194a4c35ed3SCyrille Pitchen 	unsigned int		max_tx_length;
11953ff13f1cSXander Huff 
1196512286bbSRafal Ozieblo 	u64			ethtool_stats[GEM_STATS_LEN + QUEUE_STATS_LEN * MACB_MAX_QUEUES];
119798b5a0f4SHarini Katakam 
119898b5a0f4SHarini Katakam 	unsigned int		rx_frm_len_mask;
119998b5a0f4SHarini Katakam 	unsigned int		jumbo_max_len;
12003e2a5e15SSergio Prado 
12013e2a5e15SSergio Prado 	u32			wol;
1202c2594d80SAndrei.Pistirica@microchip.com 
1203c2594d80SAndrei.Pistirica@microchip.com 	struct macb_ptp_info	*ptp_info;	/* macb-ptp interface */
12047b429614SRafal Ozieblo #ifdef MACB_EXT_DESC
12057b429614SRafal Ozieblo 	uint8_t hw_dma_cap;
1206dc97a89eSRafal Ozieblo #endif
1207ab91f0a9SRafal Ozieblo 	spinlock_t tsu_clk_lock; /* gem tsu clock locking */
1208ab91f0a9SRafal Ozieblo 	unsigned int tsu_rate;
1209ab91f0a9SRafal Ozieblo 	struct ptp_clock *ptp_clock;
1210ab91f0a9SRafal Ozieblo 	struct ptp_clock_info ptp_clock_info;
1211ab91f0a9SRafal Ozieblo 	struct tsu_incr tsu_incr;
1212ab91f0a9SRafal Ozieblo 	struct hwtstamp_config tstamp_config;
1213ae8223deSRafal Ozieblo 
1214ae8223deSRafal Ozieblo 	/* RX queue filer rule set*/
1215ae8223deSRafal Ozieblo 	struct ethtool_rx_fs_list rx_fs_list;
1216ae8223deSRafal Ozieblo 	spinlock_t rx_fs_lock;
1217ae8223deSRafal Ozieblo 	unsigned int max_tuples;
1218032dc41bSHarini Katakam 
1219032dc41bSHarini Katakam 	struct tasklet_struct	hresp_err_tasklet;
1220404cd086SHarini Katakam 
1221404cd086SHarini Katakam 	int	rx_bd_rd_prefetch;
1222404cd086SHarini Katakam 	int	tx_bd_rd_prefetch;
1223e501070eSHarini Katakam 
1224e501070eSHarini Katakam 	u32	rx_intr_mask;
1225c1e85c6cSClaudiu Beznea 
1226c1e85c6cSClaudiu Beznea 	struct macb_pm_data pm_data;
12279f2f381fSJeff Kirsher };
12289f2f381fSJeff Kirsher 
1229ab91f0a9SRafal Ozieblo #ifdef CONFIG_MACB_USE_HWSTAMP
1230ab91f0a9SRafal Ozieblo #define GEM_TSEC_SIZE  (GEM_TSH_SIZE + GEM_TSL_SIZE)
1231ab91f0a9SRafal Ozieblo #define TSU_SEC_MAX_VAL (((u64)1 << GEM_TSEC_SIZE) - 1)
1232ab91f0a9SRafal Ozieblo #define TSU_NSEC_MAX_VAL ((1 << GEM_TN_SIZE) - 1)
1233ab91f0a9SRafal Ozieblo 
1234ab91f0a9SRafal Ozieblo enum macb_bd_control {
1235ab91f0a9SRafal Ozieblo 	TSTAMP_DISABLED,
1236ab91f0a9SRafal Ozieblo 	TSTAMP_FRAME_PTP_EVENT_ONLY,
1237ab91f0a9SRafal Ozieblo 	TSTAMP_ALL_PTP_FRAMES,
1238ab91f0a9SRafal Ozieblo 	TSTAMP_ALL_FRAMES,
1239ab91f0a9SRafal Ozieblo };
1240ab91f0a9SRafal Ozieblo 
1241ab91f0a9SRafal Ozieblo void gem_ptp_init(struct net_device *ndev);
1242ab91f0a9SRafal Ozieblo void gem_ptp_remove(struct net_device *ndev);
1243ab91f0a9SRafal Ozieblo int gem_ptp_txstamp(struct macb_queue *queue, struct sk_buff *skb, struct macb_dma_desc *des);
1244ab91f0a9SRafal Ozieblo void gem_ptp_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc);
1245ab91f0a9SRafal Ozieblo static inline int gem_ptp_do_txstamp(struct macb_queue *queue, struct sk_buff *skb, struct macb_dma_desc *desc)
1246ab91f0a9SRafal Ozieblo {
1247ab91f0a9SRafal Ozieblo 	if (queue->bp->tstamp_config.tx_type == TSTAMP_DISABLED)
1248ab91f0a9SRafal Ozieblo 		return -ENOTSUPP;
1249ab91f0a9SRafal Ozieblo 
1250ab91f0a9SRafal Ozieblo 	return gem_ptp_txstamp(queue, skb, desc);
1251ab91f0a9SRafal Ozieblo }
1252ab91f0a9SRafal Ozieblo 
1253ab91f0a9SRafal Ozieblo static inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc)
1254ab91f0a9SRafal Ozieblo {
1255ab91f0a9SRafal Ozieblo 	if (bp->tstamp_config.rx_filter == TSTAMP_DISABLED)
1256ab91f0a9SRafal Ozieblo 		return;
1257ab91f0a9SRafal Ozieblo 
1258ab91f0a9SRafal Ozieblo 	gem_ptp_rxstamp(bp, skb, desc);
1259ab91f0a9SRafal Ozieblo }
1260ab91f0a9SRafal Ozieblo int gem_get_hwtst(struct net_device *dev, struct ifreq *rq);
1261ab91f0a9SRafal Ozieblo int gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd);
1262ab91f0a9SRafal Ozieblo #else
1263ab91f0a9SRafal Ozieblo static inline void gem_ptp_init(struct net_device *ndev) { }
1264ab91f0a9SRafal Ozieblo static inline void gem_ptp_remove(struct net_device *ndev) { }
1265ab91f0a9SRafal Ozieblo 
1266ab91f0a9SRafal Ozieblo static inline int gem_ptp_do_txstamp(struct macb_queue *queue, struct sk_buff *skb, struct macb_dma_desc *desc)
1267ab91f0a9SRafal Ozieblo {
1268ab91f0a9SRafal Ozieblo 	return -1;
1269ab91f0a9SRafal Ozieblo }
1270ab91f0a9SRafal Ozieblo 
1271ab91f0a9SRafal Ozieblo static inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc) { }
1272ab91f0a9SRafal Ozieblo #endif
1273ab91f0a9SRafal Ozieblo 
1274f75ba50bSJamie Iles static inline bool macb_is_gem(struct macb *bp)
1275f75ba50bSJamie Iles {
1276e175587fSNicolas Ferre 	return !!(bp->caps & MACB_CAPS_MACB_IS_GEM);
1277f75ba50bSJamie Iles }
1278f75ba50bSJamie Iles 
1279c2594d80SAndrei.Pistirica@microchip.com static inline bool gem_has_ptp(struct macb *bp)
1280c2594d80SAndrei.Pistirica@microchip.com {
1281c2594d80SAndrei.Pistirica@microchip.com 	return !!(bp->caps & MACB_CAPS_GEM_HAS_PTP);
1282c2594d80SAndrei.Pistirica@microchip.com }
1283c2594d80SAndrei.Pistirica@microchip.com 
12849f2f381fSJeff Kirsher #endif /* _MACB_H */
1285