18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Atmel MACB Ethernet Controller driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2004-2006 Atmel Corporation
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef _MACB_H
88c2ecf20Sopenharmony_ci#define _MACB_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/clk.h>
118c2ecf20Sopenharmony_ci#include <linux/phylink.h>
128c2ecf20Sopenharmony_ci#include <linux/ptp_clock_kernel.h>
138c2ecf20Sopenharmony_ci#include <linux/net_tstamp.h>
148c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#if defined(CONFIG_ARCH_DMA_ADDR_T_64BIT) || defined(CONFIG_MACB_USE_HWSTAMP)
178c2ecf20Sopenharmony_ci#define MACB_EXT_DESC
188c2ecf20Sopenharmony_ci#endif
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define MACB_GREGS_NBR 16
218c2ecf20Sopenharmony_ci#define MACB_GREGS_VERSION 2
228c2ecf20Sopenharmony_ci#define MACB_MAX_QUEUES 8
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* MACB register offsets */
258c2ecf20Sopenharmony_ci#define MACB_NCR		0x0000 /* Network Control */
268c2ecf20Sopenharmony_ci#define MACB_NCFGR		0x0004 /* Network Config */
278c2ecf20Sopenharmony_ci#define MACB_NSR		0x0008 /* Network Status */
288c2ecf20Sopenharmony_ci#define MACB_TAR		0x000c /* AT91RM9200 only */
298c2ecf20Sopenharmony_ci#define MACB_TCR		0x0010 /* AT91RM9200 only */
308c2ecf20Sopenharmony_ci#define MACB_TSR		0x0014 /* Transmit Status */
318c2ecf20Sopenharmony_ci#define MACB_RBQP		0x0018 /* RX Q Base Address */
328c2ecf20Sopenharmony_ci#define MACB_TBQP		0x001c /* TX Q Base Address */
338c2ecf20Sopenharmony_ci#define MACB_RSR		0x0020 /* Receive Status */
348c2ecf20Sopenharmony_ci#define MACB_ISR		0x0024 /* Interrupt Status */
358c2ecf20Sopenharmony_ci#define MACB_IER		0x0028 /* Interrupt Enable */
368c2ecf20Sopenharmony_ci#define MACB_IDR		0x002c /* Interrupt Disable */
378c2ecf20Sopenharmony_ci#define MACB_IMR		0x0030 /* Interrupt Mask */
388c2ecf20Sopenharmony_ci#define MACB_MAN		0x0034 /* PHY Maintenance */
398c2ecf20Sopenharmony_ci#define MACB_PTR		0x0038
408c2ecf20Sopenharmony_ci#define MACB_PFR		0x003c
418c2ecf20Sopenharmony_ci#define MACB_FTO		0x0040
428c2ecf20Sopenharmony_ci#define MACB_SCF		0x0044
438c2ecf20Sopenharmony_ci#define MACB_MCF		0x0048
448c2ecf20Sopenharmony_ci#define MACB_FRO		0x004c
458c2ecf20Sopenharmony_ci#define MACB_FCSE		0x0050
468c2ecf20Sopenharmony_ci#define MACB_ALE		0x0054
478c2ecf20Sopenharmony_ci#define MACB_DTF		0x0058
488c2ecf20Sopenharmony_ci#define MACB_LCOL		0x005c
498c2ecf20Sopenharmony_ci#define MACB_EXCOL		0x0060
508c2ecf20Sopenharmony_ci#define MACB_TUND		0x0064
518c2ecf20Sopenharmony_ci#define MACB_CSE		0x0068
528c2ecf20Sopenharmony_ci#define MACB_RRE		0x006c
538c2ecf20Sopenharmony_ci#define MACB_ROVR		0x0070
548c2ecf20Sopenharmony_ci#define MACB_RSE		0x0074
558c2ecf20Sopenharmony_ci#define MACB_ELE		0x0078
568c2ecf20Sopenharmony_ci#define MACB_RJA		0x007c
578c2ecf20Sopenharmony_ci#define MACB_USF		0x0080
588c2ecf20Sopenharmony_ci#define MACB_STE		0x0084
598c2ecf20Sopenharmony_ci#define MACB_RLE		0x0088
608c2ecf20Sopenharmony_ci#define MACB_TPF		0x008c
618c2ecf20Sopenharmony_ci#define MACB_HRB		0x0090
628c2ecf20Sopenharmony_ci#define MACB_HRT		0x0094
638c2ecf20Sopenharmony_ci#define MACB_SA1B		0x0098
648c2ecf20Sopenharmony_ci#define MACB_SA1T		0x009c
658c2ecf20Sopenharmony_ci#define MACB_SA2B		0x00a0
668c2ecf20Sopenharmony_ci#define MACB_SA2T		0x00a4
678c2ecf20Sopenharmony_ci#define MACB_SA3B		0x00a8
688c2ecf20Sopenharmony_ci#define MACB_SA3T		0x00ac
698c2ecf20Sopenharmony_ci#define MACB_SA4B		0x00b0
708c2ecf20Sopenharmony_ci#define MACB_SA4T		0x00b4
718c2ecf20Sopenharmony_ci#define MACB_TID		0x00b8
728c2ecf20Sopenharmony_ci#define MACB_TPQ		0x00bc
738c2ecf20Sopenharmony_ci#define MACB_USRIO		0x00c0
748c2ecf20Sopenharmony_ci#define MACB_WOL		0x00c4
758c2ecf20Sopenharmony_ci#define MACB_MID		0x00fc
768c2ecf20Sopenharmony_ci#define MACB_TBQPH		0x04C8
778c2ecf20Sopenharmony_ci#define MACB_RBQPH		0x04D4
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/* GEM register offsets. */
808c2ecf20Sopenharmony_ci#define GEM_NCFGR		0x0004 /* Network Config */
818c2ecf20Sopenharmony_ci#define GEM_USRIO		0x000c /* User IO */
828c2ecf20Sopenharmony_ci#define GEM_DMACFG		0x0010 /* DMA Configuration */
838c2ecf20Sopenharmony_ci#define GEM_JML			0x0048 /* Jumbo Max Length */
848c2ecf20Sopenharmony_ci#define GEM_HRB			0x0080 /* Hash Bottom */
858c2ecf20Sopenharmony_ci#define GEM_HRT			0x0084 /* Hash Top */
868c2ecf20Sopenharmony_ci#define GEM_SA1B		0x0088 /* Specific1 Bottom */
878c2ecf20Sopenharmony_ci#define GEM_SA1T		0x008C /* Specific1 Top */
888c2ecf20Sopenharmony_ci#define GEM_SA2B		0x0090 /* Specific2 Bottom */
898c2ecf20Sopenharmony_ci#define GEM_SA2T		0x0094 /* Specific2 Top */
908c2ecf20Sopenharmony_ci#define GEM_SA3B		0x0098 /* Specific3 Bottom */
918c2ecf20Sopenharmony_ci#define GEM_SA3T		0x009C /* Specific3 Top */
928c2ecf20Sopenharmony_ci#define GEM_SA4B		0x00A0 /* Specific4 Bottom */
938c2ecf20Sopenharmony_ci#define GEM_SA4T		0x00A4 /* Specific4 Top */
948c2ecf20Sopenharmony_ci#define GEM_WOL			0x00b8 /* Wake on LAN */
958c2ecf20Sopenharmony_ci#define GEM_EFTSH		0x00e8 /* PTP Event Frame Transmitted Seconds Register 47:32 */
968c2ecf20Sopenharmony_ci#define GEM_EFRSH		0x00ec /* PTP Event Frame Received Seconds Register 47:32 */
978c2ecf20Sopenharmony_ci#define GEM_PEFTSH		0x00f0 /* PTP Peer Event Frame Transmitted Seconds Register 47:32 */
988c2ecf20Sopenharmony_ci#define GEM_PEFRSH		0x00f4 /* PTP Peer Event Frame Received Seconds Register 47:32 */
998c2ecf20Sopenharmony_ci#define GEM_OTX			0x0100 /* Octets transmitted */
1008c2ecf20Sopenharmony_ci#define GEM_OCTTXL		0x0100 /* Octets transmitted [31:0] */
1018c2ecf20Sopenharmony_ci#define GEM_OCTTXH		0x0104 /* Octets transmitted [47:32] */
1028c2ecf20Sopenharmony_ci#define GEM_TXCNT		0x0108 /* Frames Transmitted counter */
1038c2ecf20Sopenharmony_ci#define GEM_TXBCCNT		0x010c /* Broadcast Frames counter */
1048c2ecf20Sopenharmony_ci#define GEM_TXMCCNT		0x0110 /* Multicast Frames counter */
1058c2ecf20Sopenharmony_ci#define GEM_TXPAUSECNT		0x0114 /* Pause Frames Transmitted Counter */
1068c2ecf20Sopenharmony_ci#define GEM_TX64CNT		0x0118 /* 64 byte Frames TX counter */
1078c2ecf20Sopenharmony_ci#define GEM_TX65CNT		0x011c /* 65-127 byte Frames TX counter */
1088c2ecf20Sopenharmony_ci#define GEM_TX128CNT		0x0120 /* 128-255 byte Frames TX counter */
1098c2ecf20Sopenharmony_ci#define GEM_TX256CNT		0x0124 /* 256-511 byte Frames TX counter */
1108c2ecf20Sopenharmony_ci#define GEM_TX512CNT		0x0128 /* 512-1023 byte Frames TX counter */
1118c2ecf20Sopenharmony_ci#define GEM_TX1024CNT		0x012c /* 1024-1518 byte Frames TX counter */
1128c2ecf20Sopenharmony_ci#define GEM_TX1519CNT		0x0130 /* 1519+ byte Frames TX counter */
1138c2ecf20Sopenharmony_ci#define GEM_TXURUNCNT		0x0134 /* TX under run error counter */
1148c2ecf20Sopenharmony_ci#define GEM_SNGLCOLLCNT		0x0138 /* Single Collision Frame Counter */
1158c2ecf20Sopenharmony_ci#define GEM_MULTICOLLCNT	0x013c /* Multiple Collision Frame Counter */
1168c2ecf20Sopenharmony_ci#define GEM_EXCESSCOLLCNT	0x0140 /* Excessive Collision Frame Counter */
1178c2ecf20Sopenharmony_ci#define GEM_LATECOLLCNT		0x0144 /* Late Collision Frame Counter */
1188c2ecf20Sopenharmony_ci#define GEM_TXDEFERCNT		0x0148 /* Deferred Transmission Frame Counter */
1198c2ecf20Sopenharmony_ci#define GEM_TXCSENSECNT		0x014c /* Carrier Sense Error Counter */
1208c2ecf20Sopenharmony_ci#define GEM_ORX			0x0150 /* Octets received */
1218c2ecf20Sopenharmony_ci#define GEM_OCTRXL		0x0150 /* Octets received [31:0] */
1228c2ecf20Sopenharmony_ci#define GEM_OCTRXH		0x0154 /* Octets received [47:32] */
1238c2ecf20Sopenharmony_ci#define GEM_RXCNT		0x0158 /* Frames Received Counter */
1248c2ecf20Sopenharmony_ci#define GEM_RXBROADCNT		0x015c /* Broadcast Frames Received Counter */
1258c2ecf20Sopenharmony_ci#define GEM_RXMULTICNT		0x0160 /* Multicast Frames Received Counter */
1268c2ecf20Sopenharmony_ci#define GEM_RXPAUSECNT		0x0164 /* Pause Frames Received Counter */
1278c2ecf20Sopenharmony_ci#define GEM_RX64CNT		0x0168 /* 64 byte Frames RX Counter */
1288c2ecf20Sopenharmony_ci#define GEM_RX65CNT		0x016c /* 65-127 byte Frames RX Counter */
1298c2ecf20Sopenharmony_ci#define GEM_RX128CNT		0x0170 /* 128-255 byte Frames RX Counter */
1308c2ecf20Sopenharmony_ci#define GEM_RX256CNT		0x0174 /* 256-511 byte Frames RX Counter */
1318c2ecf20Sopenharmony_ci#define GEM_RX512CNT		0x0178 /* 512-1023 byte Frames RX Counter */
1328c2ecf20Sopenharmony_ci#define GEM_RX1024CNT		0x017c /* 1024-1518 byte Frames RX Counter */
1338c2ecf20Sopenharmony_ci#define GEM_RX1519CNT		0x0180 /* 1519+ byte Frames RX Counter */
1348c2ecf20Sopenharmony_ci#define GEM_RXUNDRCNT		0x0184 /* Undersize Frames Received Counter */
1358c2ecf20Sopenharmony_ci#define GEM_RXOVRCNT		0x0188 /* Oversize Frames Received Counter */
1368c2ecf20Sopenharmony_ci#define GEM_RXJABCNT		0x018c /* Jabbers Received Counter */
1378c2ecf20Sopenharmony_ci#define GEM_RXFCSCNT		0x0190 /* Frame Check Sequence Error Counter */
1388c2ecf20Sopenharmony_ci#define GEM_RXLENGTHCNT		0x0194 /* Length Field Error Counter */
1398c2ecf20Sopenharmony_ci#define GEM_RXSYMBCNT		0x0198 /* Symbol Error Counter */
1408c2ecf20Sopenharmony_ci#define GEM_RXALIGNCNT		0x019c /* Alignment Error Counter */
1418c2ecf20Sopenharmony_ci#define GEM_RXRESERRCNT		0x01a0 /* Receive Resource Error Counter */
1428c2ecf20Sopenharmony_ci#define GEM_RXORCNT		0x01a4 /* Receive Overrun Counter */
1438c2ecf20Sopenharmony_ci#define GEM_RXIPCCNT		0x01a8 /* IP header Checksum Error Counter */
1448c2ecf20Sopenharmony_ci#define GEM_RXTCPCCNT		0x01ac /* TCP Checksum Error Counter */
1458c2ecf20Sopenharmony_ci#define GEM_RXUDPCCNT		0x01b0 /* UDP Checksum Error Counter */
1468c2ecf20Sopenharmony_ci#define GEM_TISUBN		0x01bc /* 1588 Timer Increment Sub-ns */
1478c2ecf20Sopenharmony_ci#define GEM_TSH			0x01c0 /* 1588 Timer Seconds High */
1488c2ecf20Sopenharmony_ci#define GEM_TSL			0x01d0 /* 1588 Timer Seconds Low */
1498c2ecf20Sopenharmony_ci#define GEM_TN			0x01d4 /* 1588 Timer Nanoseconds */
1508c2ecf20Sopenharmony_ci#define GEM_TA			0x01d8 /* 1588 Timer Adjust */
1518c2ecf20Sopenharmony_ci#define GEM_TI			0x01dc /* 1588 Timer Increment */
1528c2ecf20Sopenharmony_ci#define GEM_EFTSL		0x01e0 /* PTP Event Frame Tx Seconds Low */
1538c2ecf20Sopenharmony_ci#define GEM_EFTN		0x01e4 /* PTP Event Frame Tx Nanoseconds */
1548c2ecf20Sopenharmony_ci#define GEM_EFRSL		0x01e8 /* PTP Event Frame Rx Seconds Low */
1558c2ecf20Sopenharmony_ci#define GEM_EFRN		0x01ec /* PTP Event Frame Rx Nanoseconds */
1568c2ecf20Sopenharmony_ci#define GEM_PEFTSL		0x01f0 /* PTP Peer Event Frame Tx Secs Low */
1578c2ecf20Sopenharmony_ci#define GEM_PEFTN		0x01f4 /* PTP Peer Event Frame Tx Ns */
1588c2ecf20Sopenharmony_ci#define GEM_PEFRSL		0x01f8 /* PTP Peer Event Frame Rx Sec Low */
1598c2ecf20Sopenharmony_ci#define GEM_PEFRN		0x01fc /* PTP Peer Event Frame Rx Ns */
1608c2ecf20Sopenharmony_ci#define GEM_DCFG1		0x0280 /* Design Config 1 */
1618c2ecf20Sopenharmony_ci#define GEM_DCFG2		0x0284 /* Design Config 2 */
1628c2ecf20Sopenharmony_ci#define GEM_DCFG3		0x0288 /* Design Config 3 */
1638c2ecf20Sopenharmony_ci#define GEM_DCFG4		0x028c /* Design Config 4 */
1648c2ecf20Sopenharmony_ci#define GEM_DCFG5		0x0290 /* Design Config 5 */
1658c2ecf20Sopenharmony_ci#define GEM_DCFG6		0x0294 /* Design Config 6 */
1668c2ecf20Sopenharmony_ci#define GEM_DCFG7		0x0298 /* Design Config 7 */
1678c2ecf20Sopenharmony_ci#define GEM_DCFG8		0x029C /* Design Config 8 */
1688c2ecf20Sopenharmony_ci#define GEM_DCFG10		0x02A4 /* Design Config 10 */
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci#define GEM_TXBDCTRL	0x04cc /* TX Buffer Descriptor control register */
1718c2ecf20Sopenharmony_ci#define GEM_RXBDCTRL	0x04d0 /* RX Buffer Descriptor control register */
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/* Screener Type 2 match registers */
1748c2ecf20Sopenharmony_ci#define GEM_SCRT2		0x540
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* EtherType registers */
1778c2ecf20Sopenharmony_ci#define GEM_ETHT		0x06E0
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/* Type 2 compare registers */
1808c2ecf20Sopenharmony_ci#define GEM_T2CMPW0		0x0700
1818c2ecf20Sopenharmony_ci#define GEM_T2CMPW1		0x0704
1828c2ecf20Sopenharmony_ci#define T2CMP_OFST(t2idx)	(t2idx * 2)
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci/* type 2 compare registers
1858c2ecf20Sopenharmony_ci * each location requires 3 compare regs
1868c2ecf20Sopenharmony_ci */
1878c2ecf20Sopenharmony_ci#define GEM_IP4SRC_CMP(idx)		(idx * 3)
1888c2ecf20Sopenharmony_ci#define GEM_IP4DST_CMP(idx)		(idx * 3 + 1)
1898c2ecf20Sopenharmony_ci#define GEM_PORT_CMP(idx)		(idx * 3 + 2)
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci/* Which screening type 2 EtherType register will be used (0 - 7) */
1928c2ecf20Sopenharmony_ci#define SCRT2_ETHT		0
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci#define GEM_ISR(hw_q)		(0x0400 + ((hw_q) << 2))
1958c2ecf20Sopenharmony_ci#define GEM_TBQP(hw_q)		(0x0440 + ((hw_q) << 2))
1968c2ecf20Sopenharmony_ci#define GEM_TBQPH(hw_q)		(0x04C8)
1978c2ecf20Sopenharmony_ci#define GEM_RBQP(hw_q)		(0x0480 + ((hw_q) << 2))
1988c2ecf20Sopenharmony_ci#define GEM_RBQS(hw_q)		(0x04A0 + ((hw_q) << 2))
1998c2ecf20Sopenharmony_ci#define GEM_RBQPH(hw_q)		(0x04D4)
2008c2ecf20Sopenharmony_ci#define GEM_IER(hw_q)		(0x0600 + ((hw_q) << 2))
2018c2ecf20Sopenharmony_ci#define GEM_IDR(hw_q)		(0x0620 + ((hw_q) << 2))
2028c2ecf20Sopenharmony_ci#define GEM_IMR(hw_q)		(0x0640 + ((hw_q) << 2))
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* Bitfields in NCR */
2058c2ecf20Sopenharmony_ci#define MACB_LB_OFFSET		0 /* reserved */
2068c2ecf20Sopenharmony_ci#define MACB_LB_SIZE		1
2078c2ecf20Sopenharmony_ci#define MACB_LLB_OFFSET		1 /* Loop back local */
2088c2ecf20Sopenharmony_ci#define MACB_LLB_SIZE		1
2098c2ecf20Sopenharmony_ci#define MACB_RE_OFFSET		2 /* Receive enable */
2108c2ecf20Sopenharmony_ci#define MACB_RE_SIZE		1
2118c2ecf20Sopenharmony_ci#define MACB_TE_OFFSET		3 /* Transmit enable */
2128c2ecf20Sopenharmony_ci#define MACB_TE_SIZE		1
2138c2ecf20Sopenharmony_ci#define MACB_MPE_OFFSET		4 /* Management port enable */
2148c2ecf20Sopenharmony_ci#define MACB_MPE_SIZE		1
2158c2ecf20Sopenharmony_ci#define MACB_CLRSTAT_OFFSET	5 /* Clear stats regs */
2168c2ecf20Sopenharmony_ci#define MACB_CLRSTAT_SIZE	1
2178c2ecf20Sopenharmony_ci#define MACB_INCSTAT_OFFSET	6 /* Incremental stats regs */
2188c2ecf20Sopenharmony_ci#define MACB_INCSTAT_SIZE	1
2198c2ecf20Sopenharmony_ci#define MACB_WESTAT_OFFSET	7 /* Write enable stats regs */
2208c2ecf20Sopenharmony_ci#define MACB_WESTAT_SIZE	1
2218c2ecf20Sopenharmony_ci#define MACB_BP_OFFSET		8 /* Back pressure */
2228c2ecf20Sopenharmony_ci#define MACB_BP_SIZE		1
2238c2ecf20Sopenharmony_ci#define MACB_TSTART_OFFSET	9 /* Start transmission */
2248c2ecf20Sopenharmony_ci#define MACB_TSTART_SIZE	1
2258c2ecf20Sopenharmony_ci#define MACB_THALT_OFFSET	10 /* Transmit halt */
2268c2ecf20Sopenharmony_ci#define MACB_THALT_SIZE		1
2278c2ecf20Sopenharmony_ci#define MACB_NCR_TPF_OFFSET	11 /* Transmit pause frame */
2288c2ecf20Sopenharmony_ci#define MACB_NCR_TPF_SIZE	1
2298c2ecf20Sopenharmony_ci#define MACB_TZQ_OFFSET		12 /* Transmit zero quantum pause frame */
2308c2ecf20Sopenharmony_ci#define MACB_TZQ_SIZE		1
2318c2ecf20Sopenharmony_ci#define MACB_SRTSM_OFFSET	15
2328c2ecf20Sopenharmony_ci#define MACB_OSSMODE_OFFSET 24 /* Enable One Step Synchro Mode */
2338c2ecf20Sopenharmony_ci#define MACB_OSSMODE_SIZE	1
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci/* Bitfields in NCFGR */
2368c2ecf20Sopenharmony_ci#define MACB_SPD_OFFSET		0 /* Speed */
2378c2ecf20Sopenharmony_ci#define MACB_SPD_SIZE		1
2388c2ecf20Sopenharmony_ci#define MACB_FD_OFFSET		1 /* Full duplex */
2398c2ecf20Sopenharmony_ci#define MACB_FD_SIZE		1
2408c2ecf20Sopenharmony_ci#define MACB_BIT_RATE_OFFSET	2 /* Discard non-VLAN frames */
2418c2ecf20Sopenharmony_ci#define MACB_BIT_RATE_SIZE	1
2428c2ecf20Sopenharmony_ci#define MACB_JFRAME_OFFSET	3 /* reserved */
2438c2ecf20Sopenharmony_ci#define MACB_JFRAME_SIZE	1
2448c2ecf20Sopenharmony_ci#define MACB_CAF_OFFSET		4 /* Copy all frames */
2458c2ecf20Sopenharmony_ci#define MACB_CAF_SIZE		1
2468c2ecf20Sopenharmony_ci#define MACB_NBC_OFFSET		5 /* No broadcast */
2478c2ecf20Sopenharmony_ci#define MACB_NBC_SIZE		1
2488c2ecf20Sopenharmony_ci#define MACB_NCFGR_MTI_OFFSET	6 /* Multicast hash enable */
2498c2ecf20Sopenharmony_ci#define MACB_NCFGR_MTI_SIZE	1
2508c2ecf20Sopenharmony_ci#define MACB_UNI_OFFSET		7 /* Unicast hash enable */
2518c2ecf20Sopenharmony_ci#define MACB_UNI_SIZE		1
2528c2ecf20Sopenharmony_ci#define MACB_BIG_OFFSET		8 /* Receive 1536 byte frames */
2538c2ecf20Sopenharmony_ci#define MACB_BIG_SIZE		1
2548c2ecf20Sopenharmony_ci#define MACB_EAE_OFFSET		9 /* External address match enable */
2558c2ecf20Sopenharmony_ci#define MACB_EAE_SIZE		1
2568c2ecf20Sopenharmony_ci#define MACB_CLK_OFFSET		10
2578c2ecf20Sopenharmony_ci#define MACB_CLK_SIZE		2
2588c2ecf20Sopenharmony_ci#define MACB_RTY_OFFSET		12 /* Retry test */
2598c2ecf20Sopenharmony_ci#define MACB_RTY_SIZE		1
2608c2ecf20Sopenharmony_ci#define MACB_PAE_OFFSET		13 /* Pause enable */
2618c2ecf20Sopenharmony_ci#define MACB_PAE_SIZE		1
2628c2ecf20Sopenharmony_ci#define MACB_RM9200_RMII_OFFSET	13 /* AT91RM9200 only */
2638c2ecf20Sopenharmony_ci#define MACB_RM9200_RMII_SIZE	1  /* AT91RM9200 only */
2648c2ecf20Sopenharmony_ci#define MACB_RBOF_OFFSET	14 /* Receive buffer offset */
2658c2ecf20Sopenharmony_ci#define MACB_RBOF_SIZE		2
2668c2ecf20Sopenharmony_ci#define MACB_RLCE_OFFSET	16 /* Length field error frame discard */
2678c2ecf20Sopenharmony_ci#define MACB_RLCE_SIZE		1
2688c2ecf20Sopenharmony_ci#define MACB_DRFCS_OFFSET	17 /* FCS remove */
2698c2ecf20Sopenharmony_ci#define MACB_DRFCS_SIZE		1
2708c2ecf20Sopenharmony_ci#define MACB_EFRHD_OFFSET	18
2718c2ecf20Sopenharmony_ci#define MACB_EFRHD_SIZE		1
2728c2ecf20Sopenharmony_ci#define MACB_IRXFCS_OFFSET	19
2738c2ecf20Sopenharmony_ci#define MACB_IRXFCS_SIZE	1
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci/* GEM specific NCFGR bitfields. */
2768c2ecf20Sopenharmony_ci#define GEM_GBE_OFFSET		10 /* Gigabit mode enable */
2778c2ecf20Sopenharmony_ci#define GEM_GBE_SIZE		1
2788c2ecf20Sopenharmony_ci#define GEM_PCSSEL_OFFSET	11
2798c2ecf20Sopenharmony_ci#define GEM_PCSSEL_SIZE		1
2808c2ecf20Sopenharmony_ci#define GEM_CLK_OFFSET		18 /* MDC clock division */
2818c2ecf20Sopenharmony_ci#define GEM_CLK_SIZE		3
2828c2ecf20Sopenharmony_ci#define GEM_DBW_OFFSET		21 /* Data bus width */
2838c2ecf20Sopenharmony_ci#define GEM_DBW_SIZE		2
2848c2ecf20Sopenharmony_ci#define GEM_RXCOEN_OFFSET	24
2858c2ecf20Sopenharmony_ci#define GEM_RXCOEN_SIZE		1
2868c2ecf20Sopenharmony_ci#define GEM_SGMIIEN_OFFSET	27
2878c2ecf20Sopenharmony_ci#define GEM_SGMIIEN_SIZE	1
2888c2ecf20Sopenharmony_ci
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci/* Constants for data bus width. */
2918c2ecf20Sopenharmony_ci#define GEM_DBW32		0 /* 32 bit AMBA AHB data bus width */
2928c2ecf20Sopenharmony_ci#define GEM_DBW64		1 /* 64 bit AMBA AHB data bus width */
2938c2ecf20Sopenharmony_ci#define GEM_DBW128		2 /* 128 bit AMBA AHB data bus width */
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci/* Bitfields in DMACFG. */
2968c2ecf20Sopenharmony_ci#define GEM_FBLDO_OFFSET	0 /* fixed burst length for DMA */
2978c2ecf20Sopenharmony_ci#define GEM_FBLDO_SIZE		5
2988c2ecf20Sopenharmony_ci#define GEM_ENDIA_DESC_OFFSET	6 /* endian swap mode for management descriptor access */
2998c2ecf20Sopenharmony_ci#define GEM_ENDIA_DESC_SIZE	1
3008c2ecf20Sopenharmony_ci#define GEM_ENDIA_PKT_OFFSET	7 /* endian swap mode for packet data access */
3018c2ecf20Sopenharmony_ci#define GEM_ENDIA_PKT_SIZE	1
3028c2ecf20Sopenharmony_ci#define GEM_RXBMS_OFFSET	8 /* RX packet buffer memory size select */
3038c2ecf20Sopenharmony_ci#define GEM_RXBMS_SIZE		2
3048c2ecf20Sopenharmony_ci#define GEM_TXPBMS_OFFSET	10 /* TX packet buffer memory size select */
3058c2ecf20Sopenharmony_ci#define GEM_TXPBMS_SIZE		1
3068c2ecf20Sopenharmony_ci#define GEM_TXCOEN_OFFSET	11 /* TX IP/TCP/UDP checksum gen offload */
3078c2ecf20Sopenharmony_ci#define GEM_TXCOEN_SIZE		1
3088c2ecf20Sopenharmony_ci#define GEM_RXBS_OFFSET		16 /* DMA receive buffer size */
3098c2ecf20Sopenharmony_ci#define GEM_RXBS_SIZE		8
3108c2ecf20Sopenharmony_ci#define GEM_DDRP_OFFSET		24 /* disc_when_no_ahb */
3118c2ecf20Sopenharmony_ci#define GEM_DDRP_SIZE		1
3128c2ecf20Sopenharmony_ci#define GEM_RXEXT_OFFSET	28 /* RX extended Buffer Descriptor mode */
3138c2ecf20Sopenharmony_ci#define GEM_RXEXT_SIZE		1
3148c2ecf20Sopenharmony_ci#define GEM_TXEXT_OFFSET	29 /* TX extended Buffer Descriptor mode */
3158c2ecf20Sopenharmony_ci#define GEM_TXEXT_SIZE		1
3168c2ecf20Sopenharmony_ci#define GEM_ADDR64_OFFSET	30 /* Address bus width - 64b or 32b */
3178c2ecf20Sopenharmony_ci#define GEM_ADDR64_SIZE		1
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci/* Bitfields in NSR */
3218c2ecf20Sopenharmony_ci#define MACB_NSR_LINK_OFFSET	0 /* pcs_link_state */
3228c2ecf20Sopenharmony_ci#define MACB_NSR_LINK_SIZE	1
3238c2ecf20Sopenharmony_ci#define MACB_MDIO_OFFSET	1 /* status of the mdio_in pin */
3248c2ecf20Sopenharmony_ci#define MACB_MDIO_SIZE		1
3258c2ecf20Sopenharmony_ci#define MACB_IDLE_OFFSET	2 /* The PHY management logic is idle */
3268c2ecf20Sopenharmony_ci#define MACB_IDLE_SIZE		1
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci/* Bitfields in TSR */
3298c2ecf20Sopenharmony_ci#define MACB_UBR_OFFSET		0 /* Used bit read */
3308c2ecf20Sopenharmony_ci#define MACB_UBR_SIZE		1
3318c2ecf20Sopenharmony_ci#define MACB_COL_OFFSET		1 /* Collision occurred */
3328c2ecf20Sopenharmony_ci#define MACB_COL_SIZE		1
3338c2ecf20Sopenharmony_ci#define MACB_TSR_RLE_OFFSET	2 /* Retry limit exceeded */
3348c2ecf20Sopenharmony_ci#define MACB_TSR_RLE_SIZE	1
3358c2ecf20Sopenharmony_ci#define MACB_TGO_OFFSET		3 /* Transmit go */
3368c2ecf20Sopenharmony_ci#define MACB_TGO_SIZE		1
3378c2ecf20Sopenharmony_ci#define MACB_BEX_OFFSET		4 /* TX frame corruption due to AHB error */
3388c2ecf20Sopenharmony_ci#define MACB_BEX_SIZE		1
3398c2ecf20Sopenharmony_ci#define MACB_RM9200_BNQ_OFFSET	4 /* AT91RM9200 only */
3408c2ecf20Sopenharmony_ci#define MACB_RM9200_BNQ_SIZE	1 /* AT91RM9200 only */
3418c2ecf20Sopenharmony_ci#define MACB_COMP_OFFSET	5 /* Trnasmit complete */
3428c2ecf20Sopenharmony_ci#define MACB_COMP_SIZE		1
3438c2ecf20Sopenharmony_ci#define MACB_UND_OFFSET		6 /* Trnasmit under run */
3448c2ecf20Sopenharmony_ci#define MACB_UND_SIZE		1
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_ci/* Bitfields in RSR */
3478c2ecf20Sopenharmony_ci#define MACB_BNA_OFFSET		0 /* Buffer not available */
3488c2ecf20Sopenharmony_ci#define MACB_BNA_SIZE		1
3498c2ecf20Sopenharmony_ci#define MACB_REC_OFFSET		1 /* Frame received */
3508c2ecf20Sopenharmony_ci#define MACB_REC_SIZE		1
3518c2ecf20Sopenharmony_ci#define MACB_OVR_OFFSET		2 /* Receive overrun */
3528c2ecf20Sopenharmony_ci#define MACB_OVR_SIZE		1
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci/* Bitfields in ISR/IER/IDR/IMR */
3558c2ecf20Sopenharmony_ci#define MACB_MFD_OFFSET		0 /* Management frame sent */
3568c2ecf20Sopenharmony_ci#define MACB_MFD_SIZE		1
3578c2ecf20Sopenharmony_ci#define MACB_RCOMP_OFFSET	1 /* Receive complete */
3588c2ecf20Sopenharmony_ci#define MACB_RCOMP_SIZE		1
3598c2ecf20Sopenharmony_ci#define MACB_RXUBR_OFFSET	2 /* RX used bit read */
3608c2ecf20Sopenharmony_ci#define MACB_RXUBR_SIZE		1
3618c2ecf20Sopenharmony_ci#define MACB_TXUBR_OFFSET	3 /* TX used bit read */
3628c2ecf20Sopenharmony_ci#define MACB_TXUBR_SIZE		1
3638c2ecf20Sopenharmony_ci#define MACB_ISR_TUND_OFFSET	4 /* Enable TX buffer under run interrupt */
3648c2ecf20Sopenharmony_ci#define MACB_ISR_TUND_SIZE	1
3658c2ecf20Sopenharmony_ci#define MACB_ISR_RLE_OFFSET	5 /* EN retry exceeded/late coll interrupt */
3668c2ecf20Sopenharmony_ci#define MACB_ISR_RLE_SIZE	1
3678c2ecf20Sopenharmony_ci#define MACB_TXERR_OFFSET	6 /* EN TX frame corrupt from error interrupt */
3688c2ecf20Sopenharmony_ci#define MACB_TXERR_SIZE		1
3698c2ecf20Sopenharmony_ci#define MACB_RM9200_TBRE_OFFSET	6 /* EN may send new frame interrupt (RM9200) */
3708c2ecf20Sopenharmony_ci#define MACB_RM9200_TBRE_SIZE	1
3718c2ecf20Sopenharmony_ci#define MACB_TCOMP_OFFSET	7 /* Enable transmit complete interrupt */
3728c2ecf20Sopenharmony_ci#define MACB_TCOMP_SIZE		1
3738c2ecf20Sopenharmony_ci#define MACB_ISR_LINK_OFFSET	9 /* Enable link change interrupt */
3748c2ecf20Sopenharmony_ci#define MACB_ISR_LINK_SIZE	1
3758c2ecf20Sopenharmony_ci#define MACB_ISR_ROVR_OFFSET	10 /* Enable receive overrun interrupt */
3768c2ecf20Sopenharmony_ci#define MACB_ISR_ROVR_SIZE	1
3778c2ecf20Sopenharmony_ci#define MACB_HRESP_OFFSET	11 /* Enable hrsep not OK interrupt */
3788c2ecf20Sopenharmony_ci#define MACB_HRESP_SIZE		1
3798c2ecf20Sopenharmony_ci#define MACB_PFR_OFFSET		12 /* Enable pause frame w/ quantum interrupt */
3808c2ecf20Sopenharmony_ci#define MACB_PFR_SIZE		1
3818c2ecf20Sopenharmony_ci#define MACB_PTZ_OFFSET		13 /* Enable pause time zero interrupt */
3828c2ecf20Sopenharmony_ci#define MACB_PTZ_SIZE		1
3838c2ecf20Sopenharmony_ci#define MACB_WOL_OFFSET		14 /* Enable wake-on-lan interrupt */
3848c2ecf20Sopenharmony_ci#define MACB_WOL_SIZE		1
3858c2ecf20Sopenharmony_ci#define MACB_DRQFR_OFFSET	18 /* PTP Delay Request Frame Received */
3868c2ecf20Sopenharmony_ci#define MACB_DRQFR_SIZE		1
3878c2ecf20Sopenharmony_ci#define MACB_SFR_OFFSET		19 /* PTP Sync Frame Received */
3888c2ecf20Sopenharmony_ci#define MACB_SFR_SIZE		1
3898c2ecf20Sopenharmony_ci#define MACB_DRQFT_OFFSET	20 /* PTP Delay Request Frame Transmitted */
3908c2ecf20Sopenharmony_ci#define MACB_DRQFT_SIZE		1
3918c2ecf20Sopenharmony_ci#define MACB_SFT_OFFSET		21 /* PTP Sync Frame Transmitted */
3928c2ecf20Sopenharmony_ci#define MACB_SFT_SIZE		1
3938c2ecf20Sopenharmony_ci#define MACB_PDRQFR_OFFSET	22 /* PDelay Request Frame Received */
3948c2ecf20Sopenharmony_ci#define MACB_PDRQFR_SIZE	1
3958c2ecf20Sopenharmony_ci#define MACB_PDRSFR_OFFSET	23 /* PDelay Response Frame Received */
3968c2ecf20Sopenharmony_ci#define MACB_PDRSFR_SIZE	1
3978c2ecf20Sopenharmony_ci#define MACB_PDRQFT_OFFSET	24 /* PDelay Request Frame Transmitted */
3988c2ecf20Sopenharmony_ci#define MACB_PDRQFT_SIZE	1
3998c2ecf20Sopenharmony_ci#define MACB_PDRSFT_OFFSET	25 /* PDelay Response Frame Transmitted */
4008c2ecf20Sopenharmony_ci#define MACB_PDRSFT_SIZE	1
4018c2ecf20Sopenharmony_ci#define MACB_SRI_OFFSET		26 /* TSU Seconds Register Increment */
4028c2ecf20Sopenharmony_ci#define MACB_SRI_SIZE		1
4038c2ecf20Sopenharmony_ci#define GEM_WOL_OFFSET		28 /* Enable wake-on-lan interrupt */
4048c2ecf20Sopenharmony_ci#define GEM_WOL_SIZE		1
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/* Timer increment fields */
4078c2ecf20Sopenharmony_ci#define MACB_TI_CNS_OFFSET	0
4088c2ecf20Sopenharmony_ci#define MACB_TI_CNS_SIZE	8
4098c2ecf20Sopenharmony_ci#define MACB_TI_ACNS_OFFSET	8
4108c2ecf20Sopenharmony_ci#define MACB_TI_ACNS_SIZE	8
4118c2ecf20Sopenharmony_ci#define MACB_TI_NIT_OFFSET	16
4128c2ecf20Sopenharmony_ci#define MACB_TI_NIT_SIZE	8
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci/* Bitfields in MAN */
4158c2ecf20Sopenharmony_ci#define MACB_DATA_OFFSET	0 /* data */
4168c2ecf20Sopenharmony_ci#define MACB_DATA_SIZE		16
4178c2ecf20Sopenharmony_ci#define MACB_CODE_OFFSET	16 /* Must be written to 10 */
4188c2ecf20Sopenharmony_ci#define MACB_CODE_SIZE		2
4198c2ecf20Sopenharmony_ci#define MACB_REGA_OFFSET	18 /* Register address */
4208c2ecf20Sopenharmony_ci#define MACB_REGA_SIZE		5
4218c2ecf20Sopenharmony_ci#define MACB_PHYA_OFFSET	23 /* PHY address */
4228c2ecf20Sopenharmony_ci#define MACB_PHYA_SIZE		5
4238c2ecf20Sopenharmony_ci#define MACB_RW_OFFSET		28 /* Operation. 10 is read. 01 is write. */
4248c2ecf20Sopenharmony_ci#define MACB_RW_SIZE		2
4258c2ecf20Sopenharmony_ci#define MACB_SOF_OFFSET		30 /* Must be written to 1 for Clause 22 */
4268c2ecf20Sopenharmony_ci#define MACB_SOF_SIZE		2
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci/* Bitfields in USRIO (AVR32) */
4298c2ecf20Sopenharmony_ci#define MACB_MII_OFFSET				0
4308c2ecf20Sopenharmony_ci#define MACB_MII_SIZE				1
4318c2ecf20Sopenharmony_ci#define MACB_EAM_OFFSET				1
4328c2ecf20Sopenharmony_ci#define MACB_EAM_SIZE				1
4338c2ecf20Sopenharmony_ci#define MACB_TX_PAUSE_OFFSET			2
4348c2ecf20Sopenharmony_ci#define MACB_TX_PAUSE_SIZE			1
4358c2ecf20Sopenharmony_ci#define MACB_TX_PAUSE_ZERO_OFFSET		3
4368c2ecf20Sopenharmony_ci#define MACB_TX_PAUSE_ZERO_SIZE			1
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/* Bitfields in USRIO (AT91) */
4398c2ecf20Sopenharmony_ci#define MACB_RMII_OFFSET			0
4408c2ecf20Sopenharmony_ci#define MACB_RMII_SIZE				1
4418c2ecf20Sopenharmony_ci#define GEM_RGMII_OFFSET			0 /* GEM gigabit mode */
4428c2ecf20Sopenharmony_ci#define GEM_RGMII_SIZE				1
4438c2ecf20Sopenharmony_ci#define MACB_CLKEN_OFFSET			1
4448c2ecf20Sopenharmony_ci#define MACB_CLKEN_SIZE				1
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci/* Bitfields in WOL */
4478c2ecf20Sopenharmony_ci#define MACB_IP_OFFSET				0
4488c2ecf20Sopenharmony_ci#define MACB_IP_SIZE				16
4498c2ecf20Sopenharmony_ci#define MACB_MAG_OFFSET				16
4508c2ecf20Sopenharmony_ci#define MACB_MAG_SIZE				1
4518c2ecf20Sopenharmony_ci#define MACB_ARP_OFFSET				17
4528c2ecf20Sopenharmony_ci#define MACB_ARP_SIZE				1
4538c2ecf20Sopenharmony_ci#define MACB_SA1_OFFSET				18
4548c2ecf20Sopenharmony_ci#define MACB_SA1_SIZE				1
4558c2ecf20Sopenharmony_ci#define MACB_WOL_MTI_OFFSET			19
4568c2ecf20Sopenharmony_ci#define MACB_WOL_MTI_SIZE			1
4578c2ecf20Sopenharmony_ci
4588c2ecf20Sopenharmony_ci/* Bitfields in MID */
4598c2ecf20Sopenharmony_ci#define MACB_IDNUM_OFFSET			16
4608c2ecf20Sopenharmony_ci#define MACB_IDNUM_SIZE				12
4618c2ecf20Sopenharmony_ci#define MACB_REV_OFFSET				0
4628c2ecf20Sopenharmony_ci#define MACB_REV_SIZE				16
4638c2ecf20Sopenharmony_ci
4648c2ecf20Sopenharmony_ci/* Bitfields in DCFG1. */
4658c2ecf20Sopenharmony_ci#define GEM_IRQCOR_OFFSET			23
4668c2ecf20Sopenharmony_ci#define GEM_IRQCOR_SIZE				1
4678c2ecf20Sopenharmony_ci#define GEM_DBWDEF_OFFSET			25
4688c2ecf20Sopenharmony_ci#define GEM_DBWDEF_SIZE				3
4698c2ecf20Sopenharmony_ci
4708c2ecf20Sopenharmony_ci/* Bitfields in DCFG2. */
4718c2ecf20Sopenharmony_ci#define GEM_RX_PKT_BUFF_OFFSET			20
4728c2ecf20Sopenharmony_ci#define GEM_RX_PKT_BUFF_SIZE			1
4738c2ecf20Sopenharmony_ci#define GEM_TX_PKT_BUFF_OFFSET			21
4748c2ecf20Sopenharmony_ci#define GEM_TX_PKT_BUFF_SIZE			1
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci/* Bitfields in DCFG5. */
4788c2ecf20Sopenharmony_ci#define GEM_TSU_OFFSET				8
4798c2ecf20Sopenharmony_ci#define GEM_TSU_SIZE				1
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci/* Bitfields in DCFG6. */
4828c2ecf20Sopenharmony_ci#define GEM_PBUF_LSO_OFFSET			27
4838c2ecf20Sopenharmony_ci#define GEM_PBUF_LSO_SIZE			1
4848c2ecf20Sopenharmony_ci#define GEM_DAW64_OFFSET			23
4858c2ecf20Sopenharmony_ci#define GEM_DAW64_SIZE				1
4868c2ecf20Sopenharmony_ci
4878c2ecf20Sopenharmony_ci/* Bitfields in DCFG8. */
4888c2ecf20Sopenharmony_ci#define GEM_T1SCR_OFFSET			24
4898c2ecf20Sopenharmony_ci#define GEM_T1SCR_SIZE				8
4908c2ecf20Sopenharmony_ci#define GEM_T2SCR_OFFSET			16
4918c2ecf20Sopenharmony_ci#define GEM_T2SCR_SIZE				8
4928c2ecf20Sopenharmony_ci#define GEM_SCR2ETH_OFFSET			8
4938c2ecf20Sopenharmony_ci#define GEM_SCR2ETH_SIZE			8
4948c2ecf20Sopenharmony_ci#define GEM_SCR2CMP_OFFSET			0
4958c2ecf20Sopenharmony_ci#define GEM_SCR2CMP_SIZE			8
4968c2ecf20Sopenharmony_ci
4978c2ecf20Sopenharmony_ci/* Bitfields in DCFG10 */
4988c2ecf20Sopenharmony_ci#define GEM_TXBD_RDBUFF_OFFSET			12
4998c2ecf20Sopenharmony_ci#define GEM_TXBD_RDBUFF_SIZE			4
5008c2ecf20Sopenharmony_ci#define GEM_RXBD_RDBUFF_OFFSET			8
5018c2ecf20Sopenharmony_ci#define GEM_RXBD_RDBUFF_SIZE			4
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci/* Bitfields in TISUBN */
5048c2ecf20Sopenharmony_ci#define GEM_SUBNSINCR_OFFSET			0
5058c2ecf20Sopenharmony_ci#define GEM_SUBNSINCRL_OFFSET			24
5068c2ecf20Sopenharmony_ci#define GEM_SUBNSINCRL_SIZE			8
5078c2ecf20Sopenharmony_ci#define GEM_SUBNSINCRH_OFFSET			0
5088c2ecf20Sopenharmony_ci#define GEM_SUBNSINCRH_SIZE			16
5098c2ecf20Sopenharmony_ci#define GEM_SUBNSINCR_SIZE			24
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci/* Bitfields in TI */
5128c2ecf20Sopenharmony_ci#define GEM_NSINCR_OFFSET			0
5138c2ecf20Sopenharmony_ci#define GEM_NSINCR_SIZE				8
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci/* Bitfields in TSH */
5168c2ecf20Sopenharmony_ci#define GEM_TSH_OFFSET				0 /* TSU timer value (s). MSB [47:32] of seconds timer count */
5178c2ecf20Sopenharmony_ci#define GEM_TSH_SIZE				16
5188c2ecf20Sopenharmony_ci
5198c2ecf20Sopenharmony_ci/* Bitfields in TSL */
5208c2ecf20Sopenharmony_ci#define GEM_TSL_OFFSET				0 /* TSU timer value (s). LSB [31:0] of seconds timer count */
5218c2ecf20Sopenharmony_ci#define GEM_TSL_SIZE				32
5228c2ecf20Sopenharmony_ci
5238c2ecf20Sopenharmony_ci/* Bitfields in TN */
5248c2ecf20Sopenharmony_ci#define GEM_TN_OFFSET				0 /* TSU timer value (ns) */
5258c2ecf20Sopenharmony_ci#define GEM_TN_SIZE					30
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci/* Bitfields in TXBDCTRL */
5288c2ecf20Sopenharmony_ci#define GEM_TXTSMODE_OFFSET			4 /* TX Descriptor Timestamp Insertion mode */
5298c2ecf20Sopenharmony_ci#define GEM_TXTSMODE_SIZE			2
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci/* Bitfields in RXBDCTRL */
5328c2ecf20Sopenharmony_ci#define GEM_RXTSMODE_OFFSET			4 /* RX Descriptor Timestamp Insertion mode */
5338c2ecf20Sopenharmony_ci#define GEM_RXTSMODE_SIZE			2
5348c2ecf20Sopenharmony_ci
5358c2ecf20Sopenharmony_ci/* Bitfields in SCRT2 */
5368c2ecf20Sopenharmony_ci#define GEM_QUEUE_OFFSET			0 /* Queue Number */
5378c2ecf20Sopenharmony_ci#define GEM_QUEUE_SIZE				4
5388c2ecf20Sopenharmony_ci#define GEM_VLANPR_OFFSET			4 /* VLAN Priority */
5398c2ecf20Sopenharmony_ci#define GEM_VLANPR_SIZE				3
5408c2ecf20Sopenharmony_ci#define GEM_VLANEN_OFFSET			8 /* VLAN Enable */
5418c2ecf20Sopenharmony_ci#define GEM_VLANEN_SIZE				1
5428c2ecf20Sopenharmony_ci#define GEM_ETHT2IDX_OFFSET			9 /* Index to screener type 2 EtherType register */
5438c2ecf20Sopenharmony_ci#define GEM_ETHT2IDX_SIZE			3
5448c2ecf20Sopenharmony_ci#define GEM_ETHTEN_OFFSET			12 /* EtherType Enable */
5458c2ecf20Sopenharmony_ci#define GEM_ETHTEN_SIZE				1
5468c2ecf20Sopenharmony_ci#define GEM_CMPA_OFFSET				13 /* Compare A - Index to screener type 2 Compare register */
5478c2ecf20Sopenharmony_ci#define GEM_CMPA_SIZE				5
5488c2ecf20Sopenharmony_ci#define GEM_CMPAEN_OFFSET			18 /* Compare A Enable */
5498c2ecf20Sopenharmony_ci#define GEM_CMPAEN_SIZE				1
5508c2ecf20Sopenharmony_ci#define GEM_CMPB_OFFSET				19 /* Compare B - Index to screener type 2 Compare register */
5518c2ecf20Sopenharmony_ci#define GEM_CMPB_SIZE				5
5528c2ecf20Sopenharmony_ci#define GEM_CMPBEN_OFFSET			24 /* Compare B Enable */
5538c2ecf20Sopenharmony_ci#define GEM_CMPBEN_SIZE				1
5548c2ecf20Sopenharmony_ci#define GEM_CMPC_OFFSET				25 /* Compare C - Index to screener type 2 Compare register */
5558c2ecf20Sopenharmony_ci#define GEM_CMPC_SIZE				5
5568c2ecf20Sopenharmony_ci#define GEM_CMPCEN_OFFSET			30 /* Compare C Enable */
5578c2ecf20Sopenharmony_ci#define GEM_CMPCEN_SIZE				1
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_ci/* Bitfields in ETHT */
5608c2ecf20Sopenharmony_ci#define GEM_ETHTCMP_OFFSET			0 /* EtherType compare value */
5618c2ecf20Sopenharmony_ci#define GEM_ETHTCMP_SIZE			16
5628c2ecf20Sopenharmony_ci
5638c2ecf20Sopenharmony_ci/* Bitfields in T2CMPW0 */
5648c2ecf20Sopenharmony_ci#define GEM_T2CMP_OFFSET			16 /* 0xFFFF0000 compare value */
5658c2ecf20Sopenharmony_ci#define GEM_T2CMP_SIZE				16
5668c2ecf20Sopenharmony_ci#define GEM_T2MASK_OFFSET			0 /* 0x0000FFFF compare value or mask */
5678c2ecf20Sopenharmony_ci#define GEM_T2MASK_SIZE				16
5688c2ecf20Sopenharmony_ci
5698c2ecf20Sopenharmony_ci/* Bitfields in T2CMPW1 */
5708c2ecf20Sopenharmony_ci#define GEM_T2DISMSK_OFFSET			9 /* disable mask */
5718c2ecf20Sopenharmony_ci#define GEM_T2DISMSK_SIZE			1
5728c2ecf20Sopenharmony_ci#define GEM_T2CMPOFST_OFFSET			7 /* compare offset */
5738c2ecf20Sopenharmony_ci#define GEM_T2CMPOFST_SIZE			2
5748c2ecf20Sopenharmony_ci#define GEM_T2OFST_OFFSET			0 /* offset value */
5758c2ecf20Sopenharmony_ci#define GEM_T2OFST_SIZE				7
5768c2ecf20Sopenharmony_ci
5778c2ecf20Sopenharmony_ci/* Offset for screener type 2 compare values (T2CMPOFST).
5788c2ecf20Sopenharmony_ci * Note the offset is applied after the specified point,
5798c2ecf20Sopenharmony_ci * e.g. GEM_T2COMPOFST_ETYPE denotes the EtherType field, so an offset
5808c2ecf20Sopenharmony_ci * of 12 bytes from this would be the source IP address in an IP header
5818c2ecf20Sopenharmony_ci */
5828c2ecf20Sopenharmony_ci#define GEM_T2COMPOFST_SOF		0
5838c2ecf20Sopenharmony_ci#define GEM_T2COMPOFST_ETYPE	1
5848c2ecf20Sopenharmony_ci#define GEM_T2COMPOFST_IPHDR	2
5858c2ecf20Sopenharmony_ci#define GEM_T2COMPOFST_TCPUDP	3
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_ci/* offset from EtherType to IP address */
5888c2ecf20Sopenharmony_ci#define ETYPE_SRCIP_OFFSET			12
5898c2ecf20Sopenharmony_ci#define ETYPE_DSTIP_OFFSET			16
5908c2ecf20Sopenharmony_ci
5918c2ecf20Sopenharmony_ci/* offset from IP header to port */
5928c2ecf20Sopenharmony_ci#define IPHDR_SRCPORT_OFFSET		0
5938c2ecf20Sopenharmony_ci#define IPHDR_DSTPORT_OFFSET		2
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci/* Transmit DMA buffer descriptor Word 1 */
5968c2ecf20Sopenharmony_ci#define GEM_DMA_TXVALID_OFFSET		23 /* timestamp has been captured in the Buffer Descriptor */
5978c2ecf20Sopenharmony_ci#define GEM_DMA_TXVALID_SIZE		1
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_ci/* Receive DMA buffer descriptor Word 0 */
6008c2ecf20Sopenharmony_ci#define GEM_DMA_RXVALID_OFFSET		2 /* indicates a valid timestamp in the Buffer Descriptor */
6018c2ecf20Sopenharmony_ci#define GEM_DMA_RXVALID_SIZE		1
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci/* DMA buffer descriptor Word 2 (32 bit addressing) or Word 4 (64 bit addressing) */
6048c2ecf20Sopenharmony_ci#define GEM_DMA_SECL_OFFSET			30 /* Timestamp seconds[1:0]  */
6058c2ecf20Sopenharmony_ci#define GEM_DMA_SECL_SIZE			2
6068c2ecf20Sopenharmony_ci#define GEM_DMA_NSEC_OFFSET			0 /* Timestamp nanosecs [29:0] */
6078c2ecf20Sopenharmony_ci#define GEM_DMA_NSEC_SIZE			30
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci/* DMA buffer descriptor Word 3 (32 bit addressing) or Word 5 (64 bit addressing) */
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci/* New hardware supports 12 bit precision of timestamp in DMA buffer descriptor.
6128c2ecf20Sopenharmony_ci * Old hardware supports only 6 bit precision but it is enough for PTP.
6138c2ecf20Sopenharmony_ci * Less accuracy is used always instead of checking hardware version.
6148c2ecf20Sopenharmony_ci */
6158c2ecf20Sopenharmony_ci#define GEM_DMA_SECH_OFFSET			0 /* Timestamp seconds[5:2] */
6168c2ecf20Sopenharmony_ci#define GEM_DMA_SECH_SIZE			4
6178c2ecf20Sopenharmony_ci#define GEM_DMA_SEC_WIDTH			(GEM_DMA_SECH_SIZE + GEM_DMA_SECL_SIZE)
6188c2ecf20Sopenharmony_ci#define GEM_DMA_SEC_TOP				(1 << GEM_DMA_SEC_WIDTH)
6198c2ecf20Sopenharmony_ci#define GEM_DMA_SEC_MASK			(GEM_DMA_SEC_TOP - 1)
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci/* Bitfields in ADJ */
6228c2ecf20Sopenharmony_ci#define GEM_ADDSUB_OFFSET			31
6238c2ecf20Sopenharmony_ci#define GEM_ADDSUB_SIZE				1
6248c2ecf20Sopenharmony_ci/* Constants for CLK */
6258c2ecf20Sopenharmony_ci#define MACB_CLK_DIV8				0
6268c2ecf20Sopenharmony_ci#define MACB_CLK_DIV16				1
6278c2ecf20Sopenharmony_ci#define MACB_CLK_DIV32				2
6288c2ecf20Sopenharmony_ci#define MACB_CLK_DIV64				3
6298c2ecf20Sopenharmony_ci
6308c2ecf20Sopenharmony_ci/* GEM specific constants for CLK. */
6318c2ecf20Sopenharmony_ci#define GEM_CLK_DIV8				0
6328c2ecf20Sopenharmony_ci#define GEM_CLK_DIV16				1
6338c2ecf20Sopenharmony_ci#define GEM_CLK_DIV32				2
6348c2ecf20Sopenharmony_ci#define GEM_CLK_DIV48				3
6358c2ecf20Sopenharmony_ci#define GEM_CLK_DIV64				4
6368c2ecf20Sopenharmony_ci#define GEM_CLK_DIV96				5
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci/* Constants for MAN register */
6398c2ecf20Sopenharmony_ci#define MACB_MAN_C22_SOF			1
6408c2ecf20Sopenharmony_ci#define MACB_MAN_C22_WRITE			1
6418c2ecf20Sopenharmony_ci#define MACB_MAN_C22_READ			2
6428c2ecf20Sopenharmony_ci#define MACB_MAN_C22_CODE			2
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci#define MACB_MAN_C45_SOF			0
6458c2ecf20Sopenharmony_ci#define MACB_MAN_C45_ADDR			0
6468c2ecf20Sopenharmony_ci#define MACB_MAN_C45_WRITE			1
6478c2ecf20Sopenharmony_ci#define MACB_MAN_C45_POST_READ_INCR		2
6488c2ecf20Sopenharmony_ci#define MACB_MAN_C45_READ			3
6498c2ecf20Sopenharmony_ci#define MACB_MAN_C45_CODE			2
6508c2ecf20Sopenharmony_ci
6518c2ecf20Sopenharmony_ci/* Capability mask bits */
6528c2ecf20Sopenharmony_ci#define MACB_CAPS_ISR_CLEAR_ON_WRITE		0x00000001
6538c2ecf20Sopenharmony_ci#define MACB_CAPS_USRIO_HAS_CLKEN		0x00000002
6548c2ecf20Sopenharmony_ci#define MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII	0x00000004
6558c2ecf20Sopenharmony_ci#define MACB_CAPS_NO_GIGABIT_HALF		0x00000008
6568c2ecf20Sopenharmony_ci#define MACB_CAPS_USRIO_DISABLED		0x00000010
6578c2ecf20Sopenharmony_ci#define MACB_CAPS_JUMBO				0x00000020
6588c2ecf20Sopenharmony_ci#define MACB_CAPS_GEM_HAS_PTP			0x00000040
6598c2ecf20Sopenharmony_ci#define MACB_CAPS_BD_RD_PREFETCH		0x00000080
6608c2ecf20Sopenharmony_ci#define MACB_CAPS_NEEDS_RSTONUBR		0x00000100
6618c2ecf20Sopenharmony_ci#define MACB_CAPS_MACB_IS_EMAC			0x08000000
6628c2ecf20Sopenharmony_ci#define MACB_CAPS_FIFO_MODE			0x10000000
6638c2ecf20Sopenharmony_ci#define MACB_CAPS_GIGABIT_MODE_AVAILABLE	0x20000000
6648c2ecf20Sopenharmony_ci#define MACB_CAPS_SG_DISABLED			0x40000000
6658c2ecf20Sopenharmony_ci#define MACB_CAPS_MACB_IS_GEM			0x80000000
6668c2ecf20Sopenharmony_ci
6678c2ecf20Sopenharmony_ci/* LSO settings */
6688c2ecf20Sopenharmony_ci#define MACB_LSO_UFO_ENABLE			0x01
6698c2ecf20Sopenharmony_ci#define MACB_LSO_TSO_ENABLE			0x02
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci/* Bit manipulation macros */
6728c2ecf20Sopenharmony_ci#define MACB_BIT(name)					\
6738c2ecf20Sopenharmony_ci	(1 << MACB_##name##_OFFSET)
6748c2ecf20Sopenharmony_ci#define MACB_BF(name,value)				\
6758c2ecf20Sopenharmony_ci	(((value) & ((1 << MACB_##name##_SIZE) - 1))	\
6768c2ecf20Sopenharmony_ci	 << MACB_##name##_OFFSET)
6778c2ecf20Sopenharmony_ci#define MACB_BFEXT(name,value)\
6788c2ecf20Sopenharmony_ci	(((value) >> MACB_##name##_OFFSET)		\
6798c2ecf20Sopenharmony_ci	 & ((1 << MACB_##name##_SIZE) - 1))
6808c2ecf20Sopenharmony_ci#define MACB_BFINS(name,value,old)			\
6818c2ecf20Sopenharmony_ci	(((old) & ~(((1 << MACB_##name##_SIZE) - 1)	\
6828c2ecf20Sopenharmony_ci		    << MACB_##name##_OFFSET))		\
6838c2ecf20Sopenharmony_ci	 | MACB_BF(name,value))
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_ci#define GEM_BIT(name)					\
6868c2ecf20Sopenharmony_ci	(1 << GEM_##name##_OFFSET)
6878c2ecf20Sopenharmony_ci#define GEM_BF(name, value)				\
6888c2ecf20Sopenharmony_ci	(((value) & ((1 << GEM_##name##_SIZE) - 1))	\
6898c2ecf20Sopenharmony_ci	 << GEM_##name##_OFFSET)
6908c2ecf20Sopenharmony_ci#define GEM_BFEXT(name, value)\
6918c2ecf20Sopenharmony_ci	(((value) >> GEM_##name##_OFFSET)		\
6928c2ecf20Sopenharmony_ci	 & ((1 << GEM_##name##_SIZE) - 1))
6938c2ecf20Sopenharmony_ci#define GEM_BFINS(name, value, old)			\
6948c2ecf20Sopenharmony_ci	(((old) & ~(((1 << GEM_##name##_SIZE) - 1)	\
6958c2ecf20Sopenharmony_ci		    << GEM_##name##_OFFSET))		\
6968c2ecf20Sopenharmony_ci	 | GEM_BF(name, value))
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci/* Register access macros */
6998c2ecf20Sopenharmony_ci#define macb_readl(port, reg)		(port)->macb_reg_readl((port), MACB_##reg)
7008c2ecf20Sopenharmony_ci#define macb_writel(port, reg, value)	(port)->macb_reg_writel((port), MACB_##reg, (value))
7018c2ecf20Sopenharmony_ci#define gem_readl(port, reg)		(port)->macb_reg_readl((port), GEM_##reg)
7028c2ecf20Sopenharmony_ci#define gem_writel(port, reg, value)	(port)->macb_reg_writel((port), GEM_##reg, (value))
7038c2ecf20Sopenharmony_ci#define queue_readl(queue, reg)		(queue)->bp->macb_reg_readl((queue)->bp, (queue)->reg)
7048c2ecf20Sopenharmony_ci#define queue_writel(queue, reg, value)	(queue)->bp->macb_reg_writel((queue)->bp, (queue)->reg, (value))
7058c2ecf20Sopenharmony_ci#define gem_readl_n(port, reg, idx)		(port)->macb_reg_readl((port), GEM_##reg + idx * 4)
7068c2ecf20Sopenharmony_ci#define gem_writel_n(port, reg, idx, value)	(port)->macb_reg_writel((port), GEM_##reg + idx * 4, (value))
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci#define PTP_TS_BUFFER_SIZE		128 /* must be power of 2 */
7098c2ecf20Sopenharmony_ci
7108c2ecf20Sopenharmony_ci/* Conditional GEM/MACB macros.  These perform the operation to the correct
7118c2ecf20Sopenharmony_ci * register dependent on whether the device is a GEM or a MACB.  For registers
7128c2ecf20Sopenharmony_ci * and bitfields that are common across both devices, use macb_{read,write}l
7138c2ecf20Sopenharmony_ci * to avoid the cost of the conditional.
7148c2ecf20Sopenharmony_ci */
7158c2ecf20Sopenharmony_ci#define macb_or_gem_writel(__bp, __reg, __value) \
7168c2ecf20Sopenharmony_ci	({ \
7178c2ecf20Sopenharmony_ci		if (macb_is_gem((__bp))) \
7188c2ecf20Sopenharmony_ci			gem_writel((__bp), __reg, __value); \
7198c2ecf20Sopenharmony_ci		else \
7208c2ecf20Sopenharmony_ci			macb_writel((__bp), __reg, __value); \
7218c2ecf20Sopenharmony_ci	})
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci#define macb_or_gem_readl(__bp, __reg) \
7248c2ecf20Sopenharmony_ci	({ \
7258c2ecf20Sopenharmony_ci		u32 __v; \
7268c2ecf20Sopenharmony_ci		if (macb_is_gem((__bp))) \
7278c2ecf20Sopenharmony_ci			__v = gem_readl((__bp), __reg); \
7288c2ecf20Sopenharmony_ci		else \
7298c2ecf20Sopenharmony_ci			__v = macb_readl((__bp), __reg); \
7308c2ecf20Sopenharmony_ci		__v; \
7318c2ecf20Sopenharmony_ci	})
7328c2ecf20Sopenharmony_ci
7338c2ecf20Sopenharmony_ci#define MACB_READ_NSR(bp)	macb_readl(bp, NSR)
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci/* struct macb_dma_desc - Hardware DMA descriptor
7368c2ecf20Sopenharmony_ci * @addr: DMA address of data buffer
7378c2ecf20Sopenharmony_ci * @ctrl: Control and status bits
7388c2ecf20Sopenharmony_ci */
7398c2ecf20Sopenharmony_cistruct macb_dma_desc {
7408c2ecf20Sopenharmony_ci	u32	addr;
7418c2ecf20Sopenharmony_ci	u32	ctrl;
7428c2ecf20Sopenharmony_ci};
7438c2ecf20Sopenharmony_ci
7448c2ecf20Sopenharmony_ci#ifdef MACB_EXT_DESC
7458c2ecf20Sopenharmony_ci#define HW_DMA_CAP_32B		0
7468c2ecf20Sopenharmony_ci#define HW_DMA_CAP_64B		(1 << 0)
7478c2ecf20Sopenharmony_ci#define HW_DMA_CAP_PTP		(1 << 1)
7488c2ecf20Sopenharmony_ci#define HW_DMA_CAP_64B_PTP	(HW_DMA_CAP_64B | HW_DMA_CAP_PTP)
7498c2ecf20Sopenharmony_ci
7508c2ecf20Sopenharmony_cistruct macb_dma_desc_64 {
7518c2ecf20Sopenharmony_ci	u32 addrh;
7528c2ecf20Sopenharmony_ci	u32 resvd;
7538c2ecf20Sopenharmony_ci};
7548c2ecf20Sopenharmony_ci
7558c2ecf20Sopenharmony_cistruct macb_dma_desc_ptp {
7568c2ecf20Sopenharmony_ci	u32	ts_1;
7578c2ecf20Sopenharmony_ci	u32	ts_2;
7588c2ecf20Sopenharmony_ci};
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_cistruct gem_tx_ts {
7618c2ecf20Sopenharmony_ci	struct sk_buff *skb;
7628c2ecf20Sopenharmony_ci	struct macb_dma_desc_ptp desc_ptp;
7638c2ecf20Sopenharmony_ci};
7648c2ecf20Sopenharmony_ci#endif
7658c2ecf20Sopenharmony_ci
7668c2ecf20Sopenharmony_ci/* DMA descriptor bitfields */
7678c2ecf20Sopenharmony_ci#define MACB_RX_USED_OFFSET			0
7688c2ecf20Sopenharmony_ci#define MACB_RX_USED_SIZE			1
7698c2ecf20Sopenharmony_ci#define MACB_RX_WRAP_OFFSET			1
7708c2ecf20Sopenharmony_ci#define MACB_RX_WRAP_SIZE			1
7718c2ecf20Sopenharmony_ci#define MACB_RX_WADDR_OFFSET			2
7728c2ecf20Sopenharmony_ci#define MACB_RX_WADDR_SIZE			30
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci#define MACB_RX_FRMLEN_OFFSET			0
7758c2ecf20Sopenharmony_ci#define MACB_RX_FRMLEN_SIZE			12
7768c2ecf20Sopenharmony_ci#define MACB_RX_OFFSET_OFFSET			12
7778c2ecf20Sopenharmony_ci#define MACB_RX_OFFSET_SIZE			2
7788c2ecf20Sopenharmony_ci#define MACB_RX_SOF_OFFSET			14
7798c2ecf20Sopenharmony_ci#define MACB_RX_SOF_SIZE			1
7808c2ecf20Sopenharmony_ci#define MACB_RX_EOF_OFFSET			15
7818c2ecf20Sopenharmony_ci#define MACB_RX_EOF_SIZE			1
7828c2ecf20Sopenharmony_ci#define MACB_RX_CFI_OFFSET			16
7838c2ecf20Sopenharmony_ci#define MACB_RX_CFI_SIZE			1
7848c2ecf20Sopenharmony_ci#define MACB_RX_VLAN_PRI_OFFSET			17
7858c2ecf20Sopenharmony_ci#define MACB_RX_VLAN_PRI_SIZE			3
7868c2ecf20Sopenharmony_ci#define MACB_RX_PRI_TAG_OFFSET			20
7878c2ecf20Sopenharmony_ci#define MACB_RX_PRI_TAG_SIZE			1
7888c2ecf20Sopenharmony_ci#define MACB_RX_VLAN_TAG_OFFSET			21
7898c2ecf20Sopenharmony_ci#define MACB_RX_VLAN_TAG_SIZE			1
7908c2ecf20Sopenharmony_ci#define MACB_RX_TYPEID_MATCH_OFFSET		22
7918c2ecf20Sopenharmony_ci#define MACB_RX_TYPEID_MATCH_SIZE		1
7928c2ecf20Sopenharmony_ci#define MACB_RX_SA4_MATCH_OFFSET		23
7938c2ecf20Sopenharmony_ci#define MACB_RX_SA4_MATCH_SIZE			1
7948c2ecf20Sopenharmony_ci#define MACB_RX_SA3_MATCH_OFFSET		24
7958c2ecf20Sopenharmony_ci#define MACB_RX_SA3_MATCH_SIZE			1
7968c2ecf20Sopenharmony_ci#define MACB_RX_SA2_MATCH_OFFSET		25
7978c2ecf20Sopenharmony_ci#define MACB_RX_SA2_MATCH_SIZE			1
7988c2ecf20Sopenharmony_ci#define MACB_RX_SA1_MATCH_OFFSET		26
7998c2ecf20Sopenharmony_ci#define MACB_RX_SA1_MATCH_SIZE			1
8008c2ecf20Sopenharmony_ci#define MACB_RX_EXT_MATCH_OFFSET		28
8018c2ecf20Sopenharmony_ci#define MACB_RX_EXT_MATCH_SIZE			1
8028c2ecf20Sopenharmony_ci#define MACB_RX_UHASH_MATCH_OFFSET		29
8038c2ecf20Sopenharmony_ci#define MACB_RX_UHASH_MATCH_SIZE		1
8048c2ecf20Sopenharmony_ci#define MACB_RX_MHASH_MATCH_OFFSET		30
8058c2ecf20Sopenharmony_ci#define MACB_RX_MHASH_MATCH_SIZE		1
8068c2ecf20Sopenharmony_ci#define MACB_RX_BROADCAST_OFFSET		31
8078c2ecf20Sopenharmony_ci#define MACB_RX_BROADCAST_SIZE			1
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_ci#define MACB_RX_FRMLEN_MASK			0xFFF
8108c2ecf20Sopenharmony_ci#define MACB_RX_JFRMLEN_MASK			0x3FFF
8118c2ecf20Sopenharmony_ci
8128c2ecf20Sopenharmony_ci/* RX checksum offload disabled: bit 24 clear in NCFGR */
8138c2ecf20Sopenharmony_ci#define GEM_RX_TYPEID_MATCH_OFFSET		22
8148c2ecf20Sopenharmony_ci#define GEM_RX_TYPEID_MATCH_SIZE		2
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci/* RX checksum offload enabled: bit 24 set in NCFGR */
8178c2ecf20Sopenharmony_ci#define GEM_RX_CSUM_OFFSET			22
8188c2ecf20Sopenharmony_ci#define GEM_RX_CSUM_SIZE			2
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci#define MACB_TX_FRMLEN_OFFSET			0
8218c2ecf20Sopenharmony_ci#define MACB_TX_FRMLEN_SIZE			11
8228c2ecf20Sopenharmony_ci#define MACB_TX_LAST_OFFSET			15
8238c2ecf20Sopenharmony_ci#define MACB_TX_LAST_SIZE			1
8248c2ecf20Sopenharmony_ci#define MACB_TX_NOCRC_OFFSET			16
8258c2ecf20Sopenharmony_ci#define MACB_TX_NOCRC_SIZE			1
8268c2ecf20Sopenharmony_ci#define MACB_MSS_MFS_OFFSET			16
8278c2ecf20Sopenharmony_ci#define MACB_MSS_MFS_SIZE			14
8288c2ecf20Sopenharmony_ci#define MACB_TX_LSO_OFFSET			17
8298c2ecf20Sopenharmony_ci#define MACB_TX_LSO_SIZE			2
8308c2ecf20Sopenharmony_ci#define MACB_TX_TCP_SEQ_SRC_OFFSET		19
8318c2ecf20Sopenharmony_ci#define MACB_TX_TCP_SEQ_SRC_SIZE		1
8328c2ecf20Sopenharmony_ci#define MACB_TX_BUF_EXHAUSTED_OFFSET		27
8338c2ecf20Sopenharmony_ci#define MACB_TX_BUF_EXHAUSTED_SIZE		1
8348c2ecf20Sopenharmony_ci#define MACB_TX_UNDERRUN_OFFSET			28
8358c2ecf20Sopenharmony_ci#define MACB_TX_UNDERRUN_SIZE			1
8368c2ecf20Sopenharmony_ci#define MACB_TX_ERROR_OFFSET			29
8378c2ecf20Sopenharmony_ci#define MACB_TX_ERROR_SIZE			1
8388c2ecf20Sopenharmony_ci#define MACB_TX_WRAP_OFFSET			30
8398c2ecf20Sopenharmony_ci#define MACB_TX_WRAP_SIZE			1
8408c2ecf20Sopenharmony_ci#define MACB_TX_USED_OFFSET			31
8418c2ecf20Sopenharmony_ci#define MACB_TX_USED_SIZE			1
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci#define GEM_TX_FRMLEN_OFFSET			0
8448c2ecf20Sopenharmony_ci#define GEM_TX_FRMLEN_SIZE			14
8458c2ecf20Sopenharmony_ci
8468c2ecf20Sopenharmony_ci/* Buffer descriptor constants */
8478c2ecf20Sopenharmony_ci#define GEM_RX_CSUM_NONE			0
8488c2ecf20Sopenharmony_ci#define GEM_RX_CSUM_IP_ONLY			1
8498c2ecf20Sopenharmony_ci#define GEM_RX_CSUM_IP_TCP			2
8508c2ecf20Sopenharmony_ci#define GEM_RX_CSUM_IP_UDP			3
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_ci/* limit RX checksum offload to TCP and UDP packets */
8538c2ecf20Sopenharmony_ci#define GEM_RX_CSUM_CHECKED_MASK		2
8548c2ecf20Sopenharmony_ci
8558c2ecf20Sopenharmony_ci/* Scaled PPM fraction */
8568c2ecf20Sopenharmony_ci#define PPM_FRACTION	16
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci/* struct macb_tx_skb - data about an skb which is being transmitted
8598c2ecf20Sopenharmony_ci * @skb: skb currently being transmitted, only set for the last buffer
8608c2ecf20Sopenharmony_ci *       of the frame
8618c2ecf20Sopenharmony_ci * @mapping: DMA address of the skb's fragment buffer
8628c2ecf20Sopenharmony_ci * @size: size of the DMA mapped buffer
8638c2ecf20Sopenharmony_ci * @mapped_as_page: true when buffer was mapped with skb_frag_dma_map(),
8648c2ecf20Sopenharmony_ci *                  false when buffer was mapped with dma_map_single()
8658c2ecf20Sopenharmony_ci */
8668c2ecf20Sopenharmony_cistruct macb_tx_skb {
8678c2ecf20Sopenharmony_ci	struct sk_buff		*skb;
8688c2ecf20Sopenharmony_ci	dma_addr_t		mapping;
8698c2ecf20Sopenharmony_ci	size_t			size;
8708c2ecf20Sopenharmony_ci	bool			mapped_as_page;
8718c2ecf20Sopenharmony_ci};
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_ci/* Hardware-collected statistics. Used when updating the network
8748c2ecf20Sopenharmony_ci * device stats by a periodic timer.
8758c2ecf20Sopenharmony_ci */
8768c2ecf20Sopenharmony_cistruct macb_stats {
8778c2ecf20Sopenharmony_ci	u32	rx_pause_frames;
8788c2ecf20Sopenharmony_ci	u32	tx_ok;
8798c2ecf20Sopenharmony_ci	u32	tx_single_cols;
8808c2ecf20Sopenharmony_ci	u32	tx_multiple_cols;
8818c2ecf20Sopenharmony_ci	u32	rx_ok;
8828c2ecf20Sopenharmony_ci	u32	rx_fcs_errors;
8838c2ecf20Sopenharmony_ci	u32	rx_align_errors;
8848c2ecf20Sopenharmony_ci	u32	tx_deferred;
8858c2ecf20Sopenharmony_ci	u32	tx_late_cols;
8868c2ecf20Sopenharmony_ci	u32	tx_excessive_cols;
8878c2ecf20Sopenharmony_ci	u32	tx_underruns;
8888c2ecf20Sopenharmony_ci	u32	tx_carrier_errors;
8898c2ecf20Sopenharmony_ci	u32	rx_resource_errors;
8908c2ecf20Sopenharmony_ci	u32	rx_overruns;
8918c2ecf20Sopenharmony_ci	u32	rx_symbol_errors;
8928c2ecf20Sopenharmony_ci	u32	rx_oversize_pkts;
8938c2ecf20Sopenharmony_ci	u32	rx_jabbers;
8948c2ecf20Sopenharmony_ci	u32	rx_undersize_pkts;
8958c2ecf20Sopenharmony_ci	u32	sqe_test_errors;
8968c2ecf20Sopenharmony_ci	u32	rx_length_mismatch;
8978c2ecf20Sopenharmony_ci	u32	tx_pause_frames;
8988c2ecf20Sopenharmony_ci};
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_cistruct gem_stats {
9018c2ecf20Sopenharmony_ci	u32	tx_octets_31_0;
9028c2ecf20Sopenharmony_ci	u32	tx_octets_47_32;
9038c2ecf20Sopenharmony_ci	u32	tx_frames;
9048c2ecf20Sopenharmony_ci	u32	tx_broadcast_frames;
9058c2ecf20Sopenharmony_ci	u32	tx_multicast_frames;
9068c2ecf20Sopenharmony_ci	u32	tx_pause_frames;
9078c2ecf20Sopenharmony_ci	u32	tx_64_byte_frames;
9088c2ecf20Sopenharmony_ci	u32	tx_65_127_byte_frames;
9098c2ecf20Sopenharmony_ci	u32	tx_128_255_byte_frames;
9108c2ecf20Sopenharmony_ci	u32	tx_256_511_byte_frames;
9118c2ecf20Sopenharmony_ci	u32	tx_512_1023_byte_frames;
9128c2ecf20Sopenharmony_ci	u32	tx_1024_1518_byte_frames;
9138c2ecf20Sopenharmony_ci	u32	tx_greater_than_1518_byte_frames;
9148c2ecf20Sopenharmony_ci	u32	tx_underrun;
9158c2ecf20Sopenharmony_ci	u32	tx_single_collision_frames;
9168c2ecf20Sopenharmony_ci	u32	tx_multiple_collision_frames;
9178c2ecf20Sopenharmony_ci	u32	tx_excessive_collisions;
9188c2ecf20Sopenharmony_ci	u32	tx_late_collisions;
9198c2ecf20Sopenharmony_ci	u32	tx_deferred_frames;
9208c2ecf20Sopenharmony_ci	u32	tx_carrier_sense_errors;
9218c2ecf20Sopenharmony_ci	u32	rx_octets_31_0;
9228c2ecf20Sopenharmony_ci	u32	rx_octets_47_32;
9238c2ecf20Sopenharmony_ci	u32	rx_frames;
9248c2ecf20Sopenharmony_ci	u32	rx_broadcast_frames;
9258c2ecf20Sopenharmony_ci	u32	rx_multicast_frames;
9268c2ecf20Sopenharmony_ci	u32	rx_pause_frames;
9278c2ecf20Sopenharmony_ci	u32	rx_64_byte_frames;
9288c2ecf20Sopenharmony_ci	u32	rx_65_127_byte_frames;
9298c2ecf20Sopenharmony_ci	u32	rx_128_255_byte_frames;
9308c2ecf20Sopenharmony_ci	u32	rx_256_511_byte_frames;
9318c2ecf20Sopenharmony_ci	u32	rx_512_1023_byte_frames;
9328c2ecf20Sopenharmony_ci	u32	rx_1024_1518_byte_frames;
9338c2ecf20Sopenharmony_ci	u32	rx_greater_than_1518_byte_frames;
9348c2ecf20Sopenharmony_ci	u32	rx_undersized_frames;
9358c2ecf20Sopenharmony_ci	u32	rx_oversize_frames;
9368c2ecf20Sopenharmony_ci	u32	rx_jabbers;
9378c2ecf20Sopenharmony_ci	u32	rx_frame_check_sequence_errors;
9388c2ecf20Sopenharmony_ci	u32	rx_length_field_frame_errors;
9398c2ecf20Sopenharmony_ci	u32	rx_symbol_errors;
9408c2ecf20Sopenharmony_ci	u32	rx_alignment_errors;
9418c2ecf20Sopenharmony_ci	u32	rx_resource_errors;
9428c2ecf20Sopenharmony_ci	u32	rx_overruns;
9438c2ecf20Sopenharmony_ci	u32	rx_ip_header_checksum_errors;
9448c2ecf20Sopenharmony_ci	u32	rx_tcp_checksum_errors;
9458c2ecf20Sopenharmony_ci	u32	rx_udp_checksum_errors;
9468c2ecf20Sopenharmony_ci};
9478c2ecf20Sopenharmony_ci
9488c2ecf20Sopenharmony_ci/* Describes the name and offset of an individual statistic register, as
9498c2ecf20Sopenharmony_ci * returned by `ethtool -S`. Also describes which net_device_stats statistics
9508c2ecf20Sopenharmony_ci * this register should contribute to.
9518c2ecf20Sopenharmony_ci */
9528c2ecf20Sopenharmony_cistruct gem_statistic {
9538c2ecf20Sopenharmony_ci	char stat_string[ETH_GSTRING_LEN];
9548c2ecf20Sopenharmony_ci	int offset;
9558c2ecf20Sopenharmony_ci	u32 stat_bits;
9568c2ecf20Sopenharmony_ci};
9578c2ecf20Sopenharmony_ci
9588c2ecf20Sopenharmony_ci/* Bitfield defs for net_device_stat statistics */
9598c2ecf20Sopenharmony_ci#define GEM_NDS_RXERR_OFFSET		0
9608c2ecf20Sopenharmony_ci#define GEM_NDS_RXLENERR_OFFSET		1
9618c2ecf20Sopenharmony_ci#define GEM_NDS_RXOVERERR_OFFSET	2
9628c2ecf20Sopenharmony_ci#define GEM_NDS_RXCRCERR_OFFSET		3
9638c2ecf20Sopenharmony_ci#define GEM_NDS_RXFRAMEERR_OFFSET	4
9648c2ecf20Sopenharmony_ci#define GEM_NDS_RXFIFOERR_OFFSET	5
9658c2ecf20Sopenharmony_ci#define GEM_NDS_TXERR_OFFSET		6
9668c2ecf20Sopenharmony_ci#define GEM_NDS_TXABORTEDERR_OFFSET	7
9678c2ecf20Sopenharmony_ci#define GEM_NDS_TXCARRIERERR_OFFSET	8
9688c2ecf20Sopenharmony_ci#define GEM_NDS_TXFIFOERR_OFFSET	9
9698c2ecf20Sopenharmony_ci#define GEM_NDS_COLLISIONS_OFFSET	10
9708c2ecf20Sopenharmony_ci
9718c2ecf20Sopenharmony_ci#define GEM_STAT_TITLE(name, title) GEM_STAT_TITLE_BITS(name, title, 0)
9728c2ecf20Sopenharmony_ci#define GEM_STAT_TITLE_BITS(name, title, bits) {	\
9738c2ecf20Sopenharmony_ci	.stat_string = title,				\
9748c2ecf20Sopenharmony_ci	.offset = GEM_##name,				\
9758c2ecf20Sopenharmony_ci	.stat_bits = bits				\
9768c2ecf20Sopenharmony_ci}
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_ci/* list of gem statistic registers. The names MUST match the
9798c2ecf20Sopenharmony_ci * corresponding GEM_* definitions.
9808c2ecf20Sopenharmony_ci */
9818c2ecf20Sopenharmony_cistatic const struct gem_statistic gem_statistics[] = {
9828c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(OCTTXL, "tx_octets"), /* OCTTXH combined with OCTTXL */
9838c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TXCNT, "tx_frames"),
9848c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TXBCCNT, "tx_broadcast_frames"),
9858c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TXMCCNT, "tx_multicast_frames"),
9868c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TXPAUSECNT, "tx_pause_frames"),
9878c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TX64CNT, "tx_64_byte_frames"),
9888c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TX65CNT, "tx_65_127_byte_frames"),
9898c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TX128CNT, "tx_128_255_byte_frames"),
9908c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TX256CNT, "tx_256_511_byte_frames"),
9918c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TX512CNT, "tx_512_1023_byte_frames"),
9928c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TX1024CNT, "tx_1024_1518_byte_frames"),
9938c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"),
9948c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(TXURUNCNT, "tx_underrun",
9958c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_TXFIFOERR)),
9968c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(SNGLCOLLCNT, "tx_single_collision_frames",
9978c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
9988c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(MULTICOLLCNT, "tx_multiple_collision_frames",
9998c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
10008c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(EXCESSCOLLCNT, "tx_excessive_collisions",
10018c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_TXERR)|
10028c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_TXABORTEDERR)|
10038c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_COLLISIONS)),
10048c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(LATECOLLCNT, "tx_late_collisions",
10058c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
10068c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(TXDEFERCNT, "tx_deferred_frames"),
10078c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(TXCSENSECNT, "tx_carrier_sense_errors",
10088c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)),
10098c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(OCTRXL, "rx_octets"), /* OCTRXH combined with OCTRXL */
10108c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RXCNT, "rx_frames"),
10118c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RXBROADCNT, "rx_broadcast_frames"),
10128c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RXMULTICNT, "rx_multicast_frames"),
10138c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RXPAUSECNT, "rx_pause_frames"),
10148c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RX64CNT, "rx_64_byte_frames"),
10158c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RX65CNT, "rx_65_127_byte_frames"),
10168c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RX128CNT, "rx_128_255_byte_frames"),
10178c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RX256CNT, "rx_256_511_byte_frames"),
10188c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RX512CNT, "rx_512_1023_byte_frames"),
10198c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RX1024CNT, "rx_1024_1518_byte_frames"),
10208c2ecf20Sopenharmony_ci	GEM_STAT_TITLE(RX1519CNT, "rx_greater_than_1518_byte_frames"),
10218c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXUNDRCNT, "rx_undersized_frames",
10228c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)),
10238c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXOVRCNT, "rx_oversize_frames",
10248c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)),
10258c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXJABCNT, "rx_jabbers",
10268c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)),
10278c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXFCSCNT, "rx_frame_check_sequence_errors",
10288c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXCRCERR)),
10298c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXLENGTHCNT, "rx_length_field_frame_errors",
10308c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)),
10318c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXSYMBCNT, "rx_symbol_errors",
10328c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXFRAMEERR)),
10338c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXALIGNCNT, "rx_alignment_errors",
10348c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXOVERERR)),
10358c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXRESERRCNT, "rx_resource_errors",
10368c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXOVERERR)),
10378c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXORCNT, "rx_overruns",
10388c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXFIFOERR)),
10398c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXIPCCNT, "rx_ip_header_checksum_errors",
10408c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)),
10418c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXTCPCCNT, "rx_tcp_checksum_errors",
10428c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)),
10438c2ecf20Sopenharmony_ci	GEM_STAT_TITLE_BITS(RXUDPCCNT, "rx_udp_checksum_errors",
10448c2ecf20Sopenharmony_ci			    GEM_BIT(NDS_RXERR)),
10458c2ecf20Sopenharmony_ci};
10468c2ecf20Sopenharmony_ci
10478c2ecf20Sopenharmony_ci#define GEM_STATS_LEN ARRAY_SIZE(gem_statistics)
10488c2ecf20Sopenharmony_ci
10498c2ecf20Sopenharmony_ci#define QUEUE_STAT_TITLE(title) {	\
10508c2ecf20Sopenharmony_ci	.stat_string = title,			\
10518c2ecf20Sopenharmony_ci}
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_ci/* per queue statistics, each should be unsigned long type */
10548c2ecf20Sopenharmony_cistruct queue_stats {
10558c2ecf20Sopenharmony_ci	union {
10568c2ecf20Sopenharmony_ci		unsigned long first;
10578c2ecf20Sopenharmony_ci		unsigned long rx_packets;
10588c2ecf20Sopenharmony_ci	};
10598c2ecf20Sopenharmony_ci	unsigned long rx_bytes;
10608c2ecf20Sopenharmony_ci	unsigned long rx_dropped;
10618c2ecf20Sopenharmony_ci	unsigned long tx_packets;
10628c2ecf20Sopenharmony_ci	unsigned long tx_bytes;
10638c2ecf20Sopenharmony_ci	unsigned long tx_dropped;
10648c2ecf20Sopenharmony_ci};
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_cistatic const struct gem_statistic queue_statistics[] = {
10678c2ecf20Sopenharmony_ci		QUEUE_STAT_TITLE("rx_packets"),
10688c2ecf20Sopenharmony_ci		QUEUE_STAT_TITLE("rx_bytes"),
10698c2ecf20Sopenharmony_ci		QUEUE_STAT_TITLE("rx_dropped"),
10708c2ecf20Sopenharmony_ci		QUEUE_STAT_TITLE("tx_packets"),
10718c2ecf20Sopenharmony_ci		QUEUE_STAT_TITLE("tx_bytes"),
10728c2ecf20Sopenharmony_ci		QUEUE_STAT_TITLE("tx_dropped"),
10738c2ecf20Sopenharmony_ci};
10748c2ecf20Sopenharmony_ci
10758c2ecf20Sopenharmony_ci#define QUEUE_STATS_LEN ARRAY_SIZE(queue_statistics)
10768c2ecf20Sopenharmony_ci
10778c2ecf20Sopenharmony_cistruct macb;
10788c2ecf20Sopenharmony_cistruct macb_queue;
10798c2ecf20Sopenharmony_ci
10808c2ecf20Sopenharmony_cistruct macb_or_gem_ops {
10818c2ecf20Sopenharmony_ci	int	(*mog_alloc_rx_buffers)(struct macb *bp);
10828c2ecf20Sopenharmony_ci	void	(*mog_free_rx_buffers)(struct macb *bp);
10838c2ecf20Sopenharmony_ci	void	(*mog_init_rings)(struct macb *bp);
10848c2ecf20Sopenharmony_ci	int	(*mog_rx)(struct macb_queue *queue, struct napi_struct *napi,
10858c2ecf20Sopenharmony_ci			  int budget);
10868c2ecf20Sopenharmony_ci};
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_ci/* MACB-PTP interface: adapt to platform needs. */
10898c2ecf20Sopenharmony_cistruct macb_ptp_info {
10908c2ecf20Sopenharmony_ci	void (*ptp_init)(struct net_device *ndev);
10918c2ecf20Sopenharmony_ci	void (*ptp_remove)(struct net_device *ndev);
10928c2ecf20Sopenharmony_ci	s32 (*get_ptp_max_adj)(void);
10938c2ecf20Sopenharmony_ci	unsigned int (*get_tsu_rate)(struct macb *bp);
10948c2ecf20Sopenharmony_ci	int (*get_ts_info)(struct net_device *dev,
10958c2ecf20Sopenharmony_ci			   struct ethtool_ts_info *info);
10968c2ecf20Sopenharmony_ci	int (*get_hwtst)(struct net_device *netdev,
10978c2ecf20Sopenharmony_ci			 struct ifreq *ifr);
10988c2ecf20Sopenharmony_ci	int (*set_hwtst)(struct net_device *netdev,
10998c2ecf20Sopenharmony_ci			 struct ifreq *ifr, int cmd);
11008c2ecf20Sopenharmony_ci};
11018c2ecf20Sopenharmony_ci
11028c2ecf20Sopenharmony_cistruct macb_pm_data {
11038c2ecf20Sopenharmony_ci	u32 scrt2;
11048c2ecf20Sopenharmony_ci	u32 usrio;
11058c2ecf20Sopenharmony_ci};
11068c2ecf20Sopenharmony_ci
11078c2ecf20Sopenharmony_cistruct macb_config {
11088c2ecf20Sopenharmony_ci	u32			caps;
11098c2ecf20Sopenharmony_ci	unsigned int		dma_burst_length;
11108c2ecf20Sopenharmony_ci	int	(*clk_init)(struct platform_device *pdev, struct clk **pclk,
11118c2ecf20Sopenharmony_ci			    struct clk **hclk, struct clk **tx_clk,
11128c2ecf20Sopenharmony_ci			    struct clk **rx_clk, struct clk **tsu_clk);
11138c2ecf20Sopenharmony_ci	int	(*init)(struct platform_device *pdev);
11148c2ecf20Sopenharmony_ci	int	jumbo_max_len;
11158c2ecf20Sopenharmony_ci};
11168c2ecf20Sopenharmony_ci
11178c2ecf20Sopenharmony_cistruct tsu_incr {
11188c2ecf20Sopenharmony_ci	u32 sub_ns;
11198c2ecf20Sopenharmony_ci	u32 ns;
11208c2ecf20Sopenharmony_ci};
11218c2ecf20Sopenharmony_ci
11228c2ecf20Sopenharmony_cistruct macb_queue {
11238c2ecf20Sopenharmony_ci	struct macb		*bp;
11248c2ecf20Sopenharmony_ci	int			irq;
11258c2ecf20Sopenharmony_ci
11268c2ecf20Sopenharmony_ci	unsigned int		ISR;
11278c2ecf20Sopenharmony_ci	unsigned int		IER;
11288c2ecf20Sopenharmony_ci	unsigned int		IDR;
11298c2ecf20Sopenharmony_ci	unsigned int		IMR;
11308c2ecf20Sopenharmony_ci	unsigned int		TBQP;
11318c2ecf20Sopenharmony_ci	unsigned int		TBQPH;
11328c2ecf20Sopenharmony_ci	unsigned int		RBQS;
11338c2ecf20Sopenharmony_ci	unsigned int		RBQP;
11348c2ecf20Sopenharmony_ci	unsigned int		RBQPH;
11358c2ecf20Sopenharmony_ci
11368c2ecf20Sopenharmony_ci	unsigned int		tx_head, tx_tail;
11378c2ecf20Sopenharmony_ci	struct macb_dma_desc	*tx_ring;
11388c2ecf20Sopenharmony_ci	struct macb_tx_skb	*tx_skb;
11398c2ecf20Sopenharmony_ci	dma_addr_t		tx_ring_dma;
11408c2ecf20Sopenharmony_ci	struct work_struct	tx_error_task;
11418c2ecf20Sopenharmony_ci
11428c2ecf20Sopenharmony_ci	dma_addr_t		rx_ring_dma;
11438c2ecf20Sopenharmony_ci	dma_addr_t		rx_buffers_dma;
11448c2ecf20Sopenharmony_ci	unsigned int		rx_tail;
11458c2ecf20Sopenharmony_ci	unsigned int		rx_prepared_head;
11468c2ecf20Sopenharmony_ci	struct macb_dma_desc	*rx_ring;
11478c2ecf20Sopenharmony_ci	struct sk_buff		**rx_skbuff;
11488c2ecf20Sopenharmony_ci	void			*rx_buffers;
11498c2ecf20Sopenharmony_ci	struct napi_struct	napi;
11508c2ecf20Sopenharmony_ci	struct queue_stats stats;
11518c2ecf20Sopenharmony_ci
11528c2ecf20Sopenharmony_ci#ifdef CONFIG_MACB_USE_HWSTAMP
11538c2ecf20Sopenharmony_ci	struct work_struct	tx_ts_task;
11548c2ecf20Sopenharmony_ci	unsigned int		tx_ts_head, tx_ts_tail;
11558c2ecf20Sopenharmony_ci	struct gem_tx_ts	tx_timestamps[PTP_TS_BUFFER_SIZE];
11568c2ecf20Sopenharmony_ci#endif
11578c2ecf20Sopenharmony_ci};
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_cistruct ethtool_rx_fs_item {
11608c2ecf20Sopenharmony_ci	struct ethtool_rx_flow_spec fs;
11618c2ecf20Sopenharmony_ci	struct list_head list;
11628c2ecf20Sopenharmony_ci};
11638c2ecf20Sopenharmony_ci
11648c2ecf20Sopenharmony_cistruct ethtool_rx_fs_list {
11658c2ecf20Sopenharmony_ci	struct list_head list;
11668c2ecf20Sopenharmony_ci	unsigned int count;
11678c2ecf20Sopenharmony_ci};
11688c2ecf20Sopenharmony_ci
11698c2ecf20Sopenharmony_cistruct macb {
11708c2ecf20Sopenharmony_ci	void __iomem		*regs;
11718c2ecf20Sopenharmony_ci	bool			native_io;
11728c2ecf20Sopenharmony_ci
11738c2ecf20Sopenharmony_ci	/* hardware IO accessors */
11748c2ecf20Sopenharmony_ci	u32	(*macb_reg_readl)(struct macb *bp, int offset);
11758c2ecf20Sopenharmony_ci	void	(*macb_reg_writel)(struct macb *bp, int offset, u32 value);
11768c2ecf20Sopenharmony_ci
11778c2ecf20Sopenharmony_ci	size_t			rx_buffer_size;
11788c2ecf20Sopenharmony_ci
11798c2ecf20Sopenharmony_ci	unsigned int		rx_ring_size;
11808c2ecf20Sopenharmony_ci	unsigned int		tx_ring_size;
11818c2ecf20Sopenharmony_ci
11828c2ecf20Sopenharmony_ci	unsigned int		num_queues;
11838c2ecf20Sopenharmony_ci	unsigned int		queue_mask;
11848c2ecf20Sopenharmony_ci	struct macb_queue	queues[MACB_MAX_QUEUES];
11858c2ecf20Sopenharmony_ci
11868c2ecf20Sopenharmony_ci	spinlock_t		lock;
11878c2ecf20Sopenharmony_ci	struct platform_device	*pdev;
11888c2ecf20Sopenharmony_ci	struct clk		*pclk;
11898c2ecf20Sopenharmony_ci	struct clk		*hclk;
11908c2ecf20Sopenharmony_ci	struct clk		*tx_clk;
11918c2ecf20Sopenharmony_ci	struct clk		*rx_clk;
11928c2ecf20Sopenharmony_ci	struct clk		*tsu_clk;
11938c2ecf20Sopenharmony_ci	struct net_device	*dev;
11948c2ecf20Sopenharmony_ci	union {
11958c2ecf20Sopenharmony_ci		struct macb_stats	macb;
11968c2ecf20Sopenharmony_ci		struct gem_stats	gem;
11978c2ecf20Sopenharmony_ci	}			hw_stats;
11988c2ecf20Sopenharmony_ci
11998c2ecf20Sopenharmony_ci	struct macb_or_gem_ops	macbgem_ops;
12008c2ecf20Sopenharmony_ci
12018c2ecf20Sopenharmony_ci	struct mii_bus		*mii_bus;
12028c2ecf20Sopenharmony_ci	struct phylink		*phylink;
12038c2ecf20Sopenharmony_ci	struct phylink_config	phylink_config;
12048c2ecf20Sopenharmony_ci
12058c2ecf20Sopenharmony_ci	u32			caps;
12068c2ecf20Sopenharmony_ci	unsigned int		dma_burst_length;
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_ci	phy_interface_t		phy_interface;
12098c2ecf20Sopenharmony_ci
12108c2ecf20Sopenharmony_ci	/* AT91RM9200 transmit queue (1 on wire + 1 queued) */
12118c2ecf20Sopenharmony_ci	struct macb_tx_skb	rm9200_txq[2];
12128c2ecf20Sopenharmony_ci	unsigned int		rm9200_tx_tail;
12138c2ecf20Sopenharmony_ci	unsigned int		rm9200_tx_len;
12148c2ecf20Sopenharmony_ci	unsigned int		max_tx_length;
12158c2ecf20Sopenharmony_ci
12168c2ecf20Sopenharmony_ci	u64			ethtool_stats[GEM_STATS_LEN + QUEUE_STATS_LEN * MACB_MAX_QUEUES];
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	unsigned int		rx_frm_len_mask;
12198c2ecf20Sopenharmony_ci	unsigned int		jumbo_max_len;
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci	u32			wol;
12228c2ecf20Sopenharmony_ci
12238c2ecf20Sopenharmony_ci	struct macb_ptp_info	*ptp_info;	/* macb-ptp interface */
12248c2ecf20Sopenharmony_ci#ifdef MACB_EXT_DESC
12258c2ecf20Sopenharmony_ci	uint8_t hw_dma_cap;
12268c2ecf20Sopenharmony_ci#endif
12278c2ecf20Sopenharmony_ci	spinlock_t tsu_clk_lock; /* gem tsu clock locking */
12288c2ecf20Sopenharmony_ci	unsigned int tsu_rate;
12298c2ecf20Sopenharmony_ci	struct ptp_clock *ptp_clock;
12308c2ecf20Sopenharmony_ci	struct ptp_clock_info ptp_clock_info;
12318c2ecf20Sopenharmony_ci	struct tsu_incr tsu_incr;
12328c2ecf20Sopenharmony_ci	struct hwtstamp_config tstamp_config;
12338c2ecf20Sopenharmony_ci
12348c2ecf20Sopenharmony_ci	/* RX queue filer rule set*/
12358c2ecf20Sopenharmony_ci	struct ethtool_rx_fs_list rx_fs_list;
12368c2ecf20Sopenharmony_ci	spinlock_t rx_fs_lock;
12378c2ecf20Sopenharmony_ci	unsigned int max_tuples;
12388c2ecf20Sopenharmony_ci
12398c2ecf20Sopenharmony_ci	struct tasklet_struct	hresp_err_tasklet;
12408c2ecf20Sopenharmony_ci
12418c2ecf20Sopenharmony_ci	int	rx_bd_rd_prefetch;
12428c2ecf20Sopenharmony_ci	int	tx_bd_rd_prefetch;
12438c2ecf20Sopenharmony_ci
12448c2ecf20Sopenharmony_ci	u32	rx_intr_mask;
12458c2ecf20Sopenharmony_ci
12468c2ecf20Sopenharmony_ci	struct macb_pm_data pm_data;
12478c2ecf20Sopenharmony_ci};
12488c2ecf20Sopenharmony_ci
12498c2ecf20Sopenharmony_ci#ifdef CONFIG_MACB_USE_HWSTAMP
12508c2ecf20Sopenharmony_ci#define GEM_TSEC_SIZE  (GEM_TSH_SIZE + GEM_TSL_SIZE)
12518c2ecf20Sopenharmony_ci#define TSU_SEC_MAX_VAL (((u64)1 << GEM_TSEC_SIZE) - 1)
12528c2ecf20Sopenharmony_ci#define TSU_NSEC_MAX_VAL ((1 << GEM_TN_SIZE) - 1)
12538c2ecf20Sopenharmony_ci
12548c2ecf20Sopenharmony_cienum macb_bd_control {
12558c2ecf20Sopenharmony_ci	TSTAMP_DISABLED,
12568c2ecf20Sopenharmony_ci	TSTAMP_FRAME_PTP_EVENT_ONLY,
12578c2ecf20Sopenharmony_ci	TSTAMP_ALL_PTP_FRAMES,
12588c2ecf20Sopenharmony_ci	TSTAMP_ALL_FRAMES,
12598c2ecf20Sopenharmony_ci};
12608c2ecf20Sopenharmony_ci
12618c2ecf20Sopenharmony_civoid gem_ptp_init(struct net_device *ndev);
12628c2ecf20Sopenharmony_civoid gem_ptp_remove(struct net_device *ndev);
12638c2ecf20Sopenharmony_ciint gem_ptp_txstamp(struct macb_queue *queue, struct sk_buff *skb, struct macb_dma_desc *des);
12648c2ecf20Sopenharmony_civoid gem_ptp_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc);
12658c2ecf20Sopenharmony_cistatic inline int gem_ptp_do_txstamp(struct macb_queue *queue, struct sk_buff *skb, struct macb_dma_desc *desc)
12668c2ecf20Sopenharmony_ci{
12678c2ecf20Sopenharmony_ci	if (queue->bp->tstamp_config.tx_type == TSTAMP_DISABLED)
12688c2ecf20Sopenharmony_ci		return -ENOTSUPP;
12698c2ecf20Sopenharmony_ci
12708c2ecf20Sopenharmony_ci	return gem_ptp_txstamp(queue, skb, desc);
12718c2ecf20Sopenharmony_ci}
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_cistatic inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc)
12748c2ecf20Sopenharmony_ci{
12758c2ecf20Sopenharmony_ci	if (bp->tstamp_config.rx_filter == TSTAMP_DISABLED)
12768c2ecf20Sopenharmony_ci		return;
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci	gem_ptp_rxstamp(bp, skb, desc);
12798c2ecf20Sopenharmony_ci}
12808c2ecf20Sopenharmony_ciint gem_get_hwtst(struct net_device *dev, struct ifreq *rq);
12818c2ecf20Sopenharmony_ciint gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd);
12828c2ecf20Sopenharmony_ci#else
12838c2ecf20Sopenharmony_cistatic inline void gem_ptp_init(struct net_device *ndev) { }
12848c2ecf20Sopenharmony_cistatic inline void gem_ptp_remove(struct net_device *ndev) { }
12858c2ecf20Sopenharmony_ci
12868c2ecf20Sopenharmony_cistatic inline int gem_ptp_do_txstamp(struct macb_queue *queue, struct sk_buff *skb, struct macb_dma_desc *desc)
12878c2ecf20Sopenharmony_ci{
12888c2ecf20Sopenharmony_ci	return -1;
12898c2ecf20Sopenharmony_ci}
12908c2ecf20Sopenharmony_ci
12918c2ecf20Sopenharmony_cistatic inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc) { }
12928c2ecf20Sopenharmony_ci#endif
12938c2ecf20Sopenharmony_ci
12948c2ecf20Sopenharmony_cistatic inline bool macb_is_gem(struct macb *bp)
12958c2ecf20Sopenharmony_ci{
12968c2ecf20Sopenharmony_ci	return !!(bp->caps & MACB_CAPS_MACB_IS_GEM);
12978c2ecf20Sopenharmony_ci}
12988c2ecf20Sopenharmony_ci
12998c2ecf20Sopenharmony_cistatic inline bool gem_has_ptp(struct macb *bp)
13008c2ecf20Sopenharmony_ci{
13018c2ecf20Sopenharmony_ci	return !!(bp->caps & MACB_CAPS_GEM_HAS_PTP);
13028c2ecf20Sopenharmony_ci}
13038c2ecf20Sopenharmony_ci
13048c2ecf20Sopenharmony_ci/**
13058c2ecf20Sopenharmony_ci * struct macb_platform_data - platform data for MACB Ethernet used for PCI registration
13068c2ecf20Sopenharmony_ci * @pclk:		platform clock
13078c2ecf20Sopenharmony_ci * @hclk:		AHB clock
13088c2ecf20Sopenharmony_ci */
13098c2ecf20Sopenharmony_cistruct macb_platform_data {
13108c2ecf20Sopenharmony_ci	struct clk	*pclk;
13118c2ecf20Sopenharmony_ci	struct clk	*hclk;
13128c2ecf20Sopenharmony_ci};
13138c2ecf20Sopenharmony_ci
13148c2ecf20Sopenharmony_ci#endif /* _MACB_H */
1315