162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Atmel MACB Ethernet Controller driver 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2004-2006 Atmel Corporation 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci#ifndef _MACB_H 862306a36Sopenharmony_ci#define _MACB_H 962306a36Sopenharmony_ci 1062306a36Sopenharmony_ci#include <linux/clk.h> 1162306a36Sopenharmony_ci#include <linux/phylink.h> 1262306a36Sopenharmony_ci#include <linux/ptp_clock_kernel.h> 1362306a36Sopenharmony_ci#include <linux/net_tstamp.h> 1462306a36Sopenharmony_ci#include <linux/interrupt.h> 1562306a36Sopenharmony_ci#include <linux/phy/phy.h> 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#if defined(CONFIG_ARCH_DMA_ADDR_T_64BIT) || defined(CONFIG_MACB_USE_HWSTAMP) 1862306a36Sopenharmony_ci#define MACB_EXT_DESC 1962306a36Sopenharmony_ci#endif 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define MACB_GREGS_NBR 16 2262306a36Sopenharmony_ci#define MACB_GREGS_VERSION 2 2362306a36Sopenharmony_ci#define MACB_MAX_QUEUES 8 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci/* MACB register offsets */ 2662306a36Sopenharmony_ci#define MACB_NCR 0x0000 /* Network Control */ 2762306a36Sopenharmony_ci#define MACB_NCFGR 0x0004 /* Network Config */ 2862306a36Sopenharmony_ci#define MACB_NSR 0x0008 /* Network Status */ 2962306a36Sopenharmony_ci#define MACB_TAR 0x000c /* AT91RM9200 only */ 3062306a36Sopenharmony_ci#define MACB_TCR 0x0010 /* AT91RM9200 only */ 3162306a36Sopenharmony_ci#define MACB_TSR 0x0014 /* Transmit Status */ 3262306a36Sopenharmony_ci#define MACB_RBQP 0x0018 /* RX Q Base Address */ 3362306a36Sopenharmony_ci#define MACB_TBQP 0x001c /* TX Q Base Address */ 3462306a36Sopenharmony_ci#define MACB_RSR 0x0020 /* Receive Status */ 3562306a36Sopenharmony_ci#define MACB_ISR 0x0024 /* Interrupt Status */ 3662306a36Sopenharmony_ci#define MACB_IER 0x0028 /* Interrupt Enable */ 3762306a36Sopenharmony_ci#define MACB_IDR 0x002c /* Interrupt Disable */ 3862306a36Sopenharmony_ci#define MACB_IMR 0x0030 /* Interrupt Mask */ 3962306a36Sopenharmony_ci#define MACB_MAN 0x0034 /* PHY Maintenance */ 4062306a36Sopenharmony_ci#define MACB_PTR 0x0038 4162306a36Sopenharmony_ci#define MACB_PFR 0x003c 4262306a36Sopenharmony_ci#define MACB_FTO 0x0040 4362306a36Sopenharmony_ci#define MACB_SCF 0x0044 4462306a36Sopenharmony_ci#define MACB_MCF 0x0048 4562306a36Sopenharmony_ci#define MACB_FRO 0x004c 4662306a36Sopenharmony_ci#define MACB_FCSE 0x0050 4762306a36Sopenharmony_ci#define MACB_ALE 0x0054 4862306a36Sopenharmony_ci#define MACB_DTF 0x0058 4962306a36Sopenharmony_ci#define MACB_LCOL 0x005c 5062306a36Sopenharmony_ci#define MACB_EXCOL 0x0060 5162306a36Sopenharmony_ci#define MACB_TUND 0x0064 5262306a36Sopenharmony_ci#define MACB_CSE 0x0068 5362306a36Sopenharmony_ci#define MACB_RRE 0x006c 5462306a36Sopenharmony_ci#define MACB_ROVR 0x0070 5562306a36Sopenharmony_ci#define MACB_RSE 0x0074 5662306a36Sopenharmony_ci#define MACB_ELE 0x0078 5762306a36Sopenharmony_ci#define MACB_RJA 0x007c 5862306a36Sopenharmony_ci#define MACB_USF 0x0080 5962306a36Sopenharmony_ci#define MACB_STE 0x0084 6062306a36Sopenharmony_ci#define MACB_RLE 0x0088 6162306a36Sopenharmony_ci#define MACB_TPF 0x008c 6262306a36Sopenharmony_ci#define MACB_HRB 0x0090 6362306a36Sopenharmony_ci#define MACB_HRT 0x0094 6462306a36Sopenharmony_ci#define MACB_SA1B 0x0098 6562306a36Sopenharmony_ci#define MACB_SA1T 0x009c 6662306a36Sopenharmony_ci#define MACB_SA2B 0x00a0 6762306a36Sopenharmony_ci#define MACB_SA2T 0x00a4 6862306a36Sopenharmony_ci#define MACB_SA3B 0x00a8 6962306a36Sopenharmony_ci#define MACB_SA3T 0x00ac 7062306a36Sopenharmony_ci#define MACB_SA4B 0x00b0 7162306a36Sopenharmony_ci#define MACB_SA4T 0x00b4 7262306a36Sopenharmony_ci#define MACB_TID 0x00b8 7362306a36Sopenharmony_ci#define MACB_TPQ 0x00bc 7462306a36Sopenharmony_ci#define MACB_USRIO 0x00c0 7562306a36Sopenharmony_ci#define MACB_WOL 0x00c4 7662306a36Sopenharmony_ci#define MACB_MID 0x00fc 7762306a36Sopenharmony_ci#define MACB_TBQPH 0x04C8 7862306a36Sopenharmony_ci#define MACB_RBQPH 0x04D4 7962306a36Sopenharmony_ci 8062306a36Sopenharmony_ci/* GEM register offsets. */ 8162306a36Sopenharmony_ci#define GEM_NCR 0x0000 /* Network Control */ 8262306a36Sopenharmony_ci#define GEM_NCFGR 0x0004 /* Network Config */ 8362306a36Sopenharmony_ci#define GEM_USRIO 0x000c /* User IO */ 8462306a36Sopenharmony_ci#define GEM_DMACFG 0x0010 /* DMA Configuration */ 8562306a36Sopenharmony_ci#define GEM_PBUFRXCUT 0x0044 /* RX Partial Store and Forward */ 8662306a36Sopenharmony_ci#define GEM_JML 0x0048 /* Jumbo Max Length */ 8762306a36Sopenharmony_ci#define GEM_HS_MAC_CONFIG 0x0050 /* GEM high speed config */ 8862306a36Sopenharmony_ci#define GEM_HRB 0x0080 /* Hash Bottom */ 8962306a36Sopenharmony_ci#define GEM_HRT 0x0084 /* Hash Top */ 9062306a36Sopenharmony_ci#define GEM_SA1B 0x0088 /* Specific1 Bottom */ 9162306a36Sopenharmony_ci#define GEM_SA1T 0x008C /* Specific1 Top */ 9262306a36Sopenharmony_ci#define GEM_SA2B 0x0090 /* Specific2 Bottom */ 9362306a36Sopenharmony_ci#define GEM_SA2T 0x0094 /* Specific2 Top */ 9462306a36Sopenharmony_ci#define GEM_SA3B 0x0098 /* Specific3 Bottom */ 9562306a36Sopenharmony_ci#define GEM_SA3T 0x009C /* Specific3 Top */ 9662306a36Sopenharmony_ci#define GEM_SA4B 0x00A0 /* Specific4 Bottom */ 9762306a36Sopenharmony_ci#define GEM_SA4T 0x00A4 /* Specific4 Top */ 9862306a36Sopenharmony_ci#define GEM_WOL 0x00b8 /* Wake on LAN */ 9962306a36Sopenharmony_ci#define GEM_RXPTPUNI 0x00D4 /* PTP RX Unicast address */ 10062306a36Sopenharmony_ci#define GEM_TXPTPUNI 0x00D8 /* PTP TX Unicast address */ 10162306a36Sopenharmony_ci#define GEM_EFTSH 0x00e8 /* PTP Event Frame Transmitted Seconds Register 47:32 */ 10262306a36Sopenharmony_ci#define GEM_EFRSH 0x00ec /* PTP Event Frame Received Seconds Register 47:32 */ 10362306a36Sopenharmony_ci#define GEM_PEFTSH 0x00f0 /* PTP Peer Event Frame Transmitted Seconds Register 47:32 */ 10462306a36Sopenharmony_ci#define GEM_PEFRSH 0x00f4 /* PTP Peer Event Frame Received Seconds Register 47:32 */ 10562306a36Sopenharmony_ci#define GEM_OTX 0x0100 /* Octets transmitted */ 10662306a36Sopenharmony_ci#define GEM_OCTTXL 0x0100 /* Octets transmitted [31:0] */ 10762306a36Sopenharmony_ci#define GEM_OCTTXH 0x0104 /* Octets transmitted [47:32] */ 10862306a36Sopenharmony_ci#define GEM_TXCNT 0x0108 /* Frames Transmitted counter */ 10962306a36Sopenharmony_ci#define GEM_TXBCCNT 0x010c /* Broadcast Frames counter */ 11062306a36Sopenharmony_ci#define GEM_TXMCCNT 0x0110 /* Multicast Frames counter */ 11162306a36Sopenharmony_ci#define GEM_TXPAUSECNT 0x0114 /* Pause Frames Transmitted Counter */ 11262306a36Sopenharmony_ci#define GEM_TX64CNT 0x0118 /* 64 byte Frames TX counter */ 11362306a36Sopenharmony_ci#define GEM_TX65CNT 0x011c /* 65-127 byte Frames TX counter */ 11462306a36Sopenharmony_ci#define GEM_TX128CNT 0x0120 /* 128-255 byte Frames TX counter */ 11562306a36Sopenharmony_ci#define GEM_TX256CNT 0x0124 /* 256-511 byte Frames TX counter */ 11662306a36Sopenharmony_ci#define GEM_TX512CNT 0x0128 /* 512-1023 byte Frames TX counter */ 11762306a36Sopenharmony_ci#define GEM_TX1024CNT 0x012c /* 1024-1518 byte Frames TX counter */ 11862306a36Sopenharmony_ci#define GEM_TX1519CNT 0x0130 /* 1519+ byte Frames TX counter */ 11962306a36Sopenharmony_ci#define GEM_TXURUNCNT 0x0134 /* TX under run error counter */ 12062306a36Sopenharmony_ci#define GEM_SNGLCOLLCNT 0x0138 /* Single Collision Frame Counter */ 12162306a36Sopenharmony_ci#define GEM_MULTICOLLCNT 0x013c /* Multiple Collision Frame Counter */ 12262306a36Sopenharmony_ci#define GEM_EXCESSCOLLCNT 0x0140 /* Excessive Collision Frame Counter */ 12362306a36Sopenharmony_ci#define GEM_LATECOLLCNT 0x0144 /* Late Collision Frame Counter */ 12462306a36Sopenharmony_ci#define GEM_TXDEFERCNT 0x0148 /* Deferred Transmission Frame Counter */ 12562306a36Sopenharmony_ci#define GEM_TXCSENSECNT 0x014c /* Carrier Sense Error Counter */ 12662306a36Sopenharmony_ci#define GEM_ORX 0x0150 /* Octets received */ 12762306a36Sopenharmony_ci#define GEM_OCTRXL 0x0150 /* Octets received [31:0] */ 12862306a36Sopenharmony_ci#define GEM_OCTRXH 0x0154 /* Octets received [47:32] */ 12962306a36Sopenharmony_ci#define GEM_RXCNT 0x0158 /* Frames Received Counter */ 13062306a36Sopenharmony_ci#define GEM_RXBROADCNT 0x015c /* Broadcast Frames Received Counter */ 13162306a36Sopenharmony_ci#define GEM_RXMULTICNT 0x0160 /* Multicast Frames Received Counter */ 13262306a36Sopenharmony_ci#define GEM_RXPAUSECNT 0x0164 /* Pause Frames Received Counter */ 13362306a36Sopenharmony_ci#define GEM_RX64CNT 0x0168 /* 64 byte Frames RX Counter */ 13462306a36Sopenharmony_ci#define GEM_RX65CNT 0x016c /* 65-127 byte Frames RX Counter */ 13562306a36Sopenharmony_ci#define GEM_RX128CNT 0x0170 /* 128-255 byte Frames RX Counter */ 13662306a36Sopenharmony_ci#define GEM_RX256CNT 0x0174 /* 256-511 byte Frames RX Counter */ 13762306a36Sopenharmony_ci#define GEM_RX512CNT 0x0178 /* 512-1023 byte Frames RX Counter */ 13862306a36Sopenharmony_ci#define GEM_RX1024CNT 0x017c /* 1024-1518 byte Frames RX Counter */ 13962306a36Sopenharmony_ci#define GEM_RX1519CNT 0x0180 /* 1519+ byte Frames RX Counter */ 14062306a36Sopenharmony_ci#define GEM_RXUNDRCNT 0x0184 /* Undersize Frames Received Counter */ 14162306a36Sopenharmony_ci#define GEM_RXOVRCNT 0x0188 /* Oversize Frames Received Counter */ 14262306a36Sopenharmony_ci#define GEM_RXJABCNT 0x018c /* Jabbers Received Counter */ 14362306a36Sopenharmony_ci#define GEM_RXFCSCNT 0x0190 /* Frame Check Sequence Error Counter */ 14462306a36Sopenharmony_ci#define GEM_RXLENGTHCNT 0x0194 /* Length Field Error Counter */ 14562306a36Sopenharmony_ci#define GEM_RXSYMBCNT 0x0198 /* Symbol Error Counter */ 14662306a36Sopenharmony_ci#define GEM_RXALIGNCNT 0x019c /* Alignment Error Counter */ 14762306a36Sopenharmony_ci#define GEM_RXRESERRCNT 0x01a0 /* Receive Resource Error Counter */ 14862306a36Sopenharmony_ci#define GEM_RXORCNT 0x01a4 /* Receive Overrun Counter */ 14962306a36Sopenharmony_ci#define GEM_RXIPCCNT 0x01a8 /* IP header Checksum Error Counter */ 15062306a36Sopenharmony_ci#define GEM_RXTCPCCNT 0x01ac /* TCP Checksum Error Counter */ 15162306a36Sopenharmony_ci#define GEM_RXUDPCCNT 0x01b0 /* UDP Checksum Error Counter */ 15262306a36Sopenharmony_ci#define GEM_TISUBN 0x01bc /* 1588 Timer Increment Sub-ns */ 15362306a36Sopenharmony_ci#define GEM_TSH 0x01c0 /* 1588 Timer Seconds High */ 15462306a36Sopenharmony_ci#define GEM_TSL 0x01d0 /* 1588 Timer Seconds Low */ 15562306a36Sopenharmony_ci#define GEM_TN 0x01d4 /* 1588 Timer Nanoseconds */ 15662306a36Sopenharmony_ci#define GEM_TA 0x01d8 /* 1588 Timer Adjust */ 15762306a36Sopenharmony_ci#define GEM_TI 0x01dc /* 1588 Timer Increment */ 15862306a36Sopenharmony_ci#define GEM_EFTSL 0x01e0 /* PTP Event Frame Tx Seconds Low */ 15962306a36Sopenharmony_ci#define GEM_EFTN 0x01e4 /* PTP Event Frame Tx Nanoseconds */ 16062306a36Sopenharmony_ci#define GEM_EFRSL 0x01e8 /* PTP Event Frame Rx Seconds Low */ 16162306a36Sopenharmony_ci#define GEM_EFRN 0x01ec /* PTP Event Frame Rx Nanoseconds */ 16262306a36Sopenharmony_ci#define GEM_PEFTSL 0x01f0 /* PTP Peer Event Frame Tx Secs Low */ 16362306a36Sopenharmony_ci#define GEM_PEFTN 0x01f4 /* PTP Peer Event Frame Tx Ns */ 16462306a36Sopenharmony_ci#define GEM_PEFRSL 0x01f8 /* PTP Peer Event Frame Rx Sec Low */ 16562306a36Sopenharmony_ci#define GEM_PEFRN 0x01fc /* PTP Peer Event Frame Rx Ns */ 16662306a36Sopenharmony_ci#define GEM_PCSCNTRL 0x0200 /* PCS Control */ 16762306a36Sopenharmony_ci#define GEM_PCSSTS 0x0204 /* PCS Status */ 16862306a36Sopenharmony_ci#define GEM_PCSPHYTOPID 0x0208 /* PCS PHY Top ID */ 16962306a36Sopenharmony_ci#define GEM_PCSPHYBOTID 0x020c /* PCS PHY Bottom ID */ 17062306a36Sopenharmony_ci#define GEM_PCSANADV 0x0210 /* PCS AN Advertisement */ 17162306a36Sopenharmony_ci#define GEM_PCSANLPBASE 0x0214 /* PCS AN Link Partner Base */ 17262306a36Sopenharmony_ci#define GEM_PCSANEXP 0x0218 /* PCS AN Expansion */ 17362306a36Sopenharmony_ci#define GEM_PCSANNPTX 0x021c /* PCS AN Next Page TX */ 17462306a36Sopenharmony_ci#define GEM_PCSANNPLP 0x0220 /* PCS AN Next Page LP */ 17562306a36Sopenharmony_ci#define GEM_PCSANEXTSTS 0x023c /* PCS AN Extended Status */ 17662306a36Sopenharmony_ci#define GEM_DCFG1 0x0280 /* Design Config 1 */ 17762306a36Sopenharmony_ci#define GEM_DCFG2 0x0284 /* Design Config 2 */ 17862306a36Sopenharmony_ci#define GEM_DCFG3 0x0288 /* Design Config 3 */ 17962306a36Sopenharmony_ci#define GEM_DCFG4 0x028c /* Design Config 4 */ 18062306a36Sopenharmony_ci#define GEM_DCFG5 0x0290 /* Design Config 5 */ 18162306a36Sopenharmony_ci#define GEM_DCFG6 0x0294 /* Design Config 6 */ 18262306a36Sopenharmony_ci#define GEM_DCFG7 0x0298 /* Design Config 7 */ 18362306a36Sopenharmony_ci#define GEM_DCFG8 0x029C /* Design Config 8 */ 18462306a36Sopenharmony_ci#define GEM_DCFG10 0x02A4 /* Design Config 10 */ 18562306a36Sopenharmony_ci#define GEM_DCFG12 0x02AC /* Design Config 12 */ 18662306a36Sopenharmony_ci#define GEM_USX_CONTROL 0x0A80 /* High speed PCS control register */ 18762306a36Sopenharmony_ci#define GEM_USX_STATUS 0x0A88 /* High speed PCS status register */ 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci#define GEM_TXBDCTRL 0x04cc /* TX Buffer Descriptor control register */ 19062306a36Sopenharmony_ci#define GEM_RXBDCTRL 0x04d0 /* RX Buffer Descriptor control register */ 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci/* Screener Type 2 match registers */ 19362306a36Sopenharmony_ci#define GEM_SCRT2 0x540 19462306a36Sopenharmony_ci 19562306a36Sopenharmony_ci/* EtherType registers */ 19662306a36Sopenharmony_ci#define GEM_ETHT 0x06E0 19762306a36Sopenharmony_ci 19862306a36Sopenharmony_ci/* Type 2 compare registers */ 19962306a36Sopenharmony_ci#define GEM_T2CMPW0 0x0700 20062306a36Sopenharmony_ci#define GEM_T2CMPW1 0x0704 20162306a36Sopenharmony_ci#define T2CMP_OFST(t2idx) (t2idx * 2) 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci/* type 2 compare registers 20462306a36Sopenharmony_ci * each location requires 3 compare regs 20562306a36Sopenharmony_ci */ 20662306a36Sopenharmony_ci#define GEM_IP4SRC_CMP(idx) (idx * 3) 20762306a36Sopenharmony_ci#define GEM_IP4DST_CMP(idx) (idx * 3 + 1) 20862306a36Sopenharmony_ci#define GEM_PORT_CMP(idx) (idx * 3 + 2) 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci/* Which screening type 2 EtherType register will be used (0 - 7) */ 21162306a36Sopenharmony_ci#define SCRT2_ETHT 0 21262306a36Sopenharmony_ci 21362306a36Sopenharmony_ci#define GEM_ISR(hw_q) (0x0400 + ((hw_q) << 2)) 21462306a36Sopenharmony_ci#define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2)) 21562306a36Sopenharmony_ci#define GEM_TBQPH(hw_q) (0x04C8) 21662306a36Sopenharmony_ci#define GEM_RBQP(hw_q) (0x0480 + ((hw_q) << 2)) 21762306a36Sopenharmony_ci#define GEM_RBQS(hw_q) (0x04A0 + ((hw_q) << 2)) 21862306a36Sopenharmony_ci#define GEM_RBQPH(hw_q) (0x04D4) 21962306a36Sopenharmony_ci#define GEM_IER(hw_q) (0x0600 + ((hw_q) << 2)) 22062306a36Sopenharmony_ci#define GEM_IDR(hw_q) (0x0620 + ((hw_q) << 2)) 22162306a36Sopenharmony_ci#define GEM_IMR(hw_q) (0x0640 + ((hw_q) << 2)) 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci/* Bitfields in NCR */ 22462306a36Sopenharmony_ci#define MACB_LB_OFFSET 0 /* reserved */ 22562306a36Sopenharmony_ci#define MACB_LB_SIZE 1 22662306a36Sopenharmony_ci#define MACB_LLB_OFFSET 1 /* Loop back local */ 22762306a36Sopenharmony_ci#define MACB_LLB_SIZE 1 22862306a36Sopenharmony_ci#define MACB_RE_OFFSET 2 /* Receive enable */ 22962306a36Sopenharmony_ci#define MACB_RE_SIZE 1 23062306a36Sopenharmony_ci#define MACB_TE_OFFSET 3 /* Transmit enable */ 23162306a36Sopenharmony_ci#define MACB_TE_SIZE 1 23262306a36Sopenharmony_ci#define MACB_MPE_OFFSET 4 /* Management port enable */ 23362306a36Sopenharmony_ci#define MACB_MPE_SIZE 1 23462306a36Sopenharmony_ci#define MACB_CLRSTAT_OFFSET 5 /* Clear stats regs */ 23562306a36Sopenharmony_ci#define MACB_CLRSTAT_SIZE 1 23662306a36Sopenharmony_ci#define MACB_INCSTAT_OFFSET 6 /* Incremental stats regs */ 23762306a36Sopenharmony_ci#define MACB_INCSTAT_SIZE 1 23862306a36Sopenharmony_ci#define MACB_WESTAT_OFFSET 7 /* Write enable stats regs */ 23962306a36Sopenharmony_ci#define MACB_WESTAT_SIZE 1 24062306a36Sopenharmony_ci#define MACB_BP_OFFSET 8 /* Back pressure */ 24162306a36Sopenharmony_ci#define MACB_BP_SIZE 1 24262306a36Sopenharmony_ci#define MACB_TSTART_OFFSET 9 /* Start transmission */ 24362306a36Sopenharmony_ci#define MACB_TSTART_SIZE 1 24462306a36Sopenharmony_ci#define MACB_THALT_OFFSET 10 /* Transmit halt */ 24562306a36Sopenharmony_ci#define MACB_THALT_SIZE 1 24662306a36Sopenharmony_ci#define MACB_NCR_TPF_OFFSET 11 /* Transmit pause frame */ 24762306a36Sopenharmony_ci#define MACB_NCR_TPF_SIZE 1 24862306a36Sopenharmony_ci#define MACB_TZQ_OFFSET 12 /* Transmit zero quantum pause frame */ 24962306a36Sopenharmony_ci#define MACB_TZQ_SIZE 1 25062306a36Sopenharmony_ci#define MACB_SRTSM_OFFSET 15 /* Store Receive Timestamp to Memory */ 25162306a36Sopenharmony_ci#define MACB_PTPUNI_OFFSET 20 /* PTP Unicast packet enable */ 25262306a36Sopenharmony_ci#define MACB_PTPUNI_SIZE 1 25362306a36Sopenharmony_ci#define MACB_OSSMODE_OFFSET 24 /* Enable One Step Synchro Mode */ 25462306a36Sopenharmony_ci#define MACB_OSSMODE_SIZE 1 25562306a36Sopenharmony_ci#define MACB_MIIONRGMII_OFFSET 28 /* MII Usage on RGMII Interface */ 25662306a36Sopenharmony_ci#define MACB_MIIONRGMII_SIZE 1 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_ci/* Bitfields in NCFGR */ 25962306a36Sopenharmony_ci#define MACB_SPD_OFFSET 0 /* Speed */ 26062306a36Sopenharmony_ci#define MACB_SPD_SIZE 1 26162306a36Sopenharmony_ci#define MACB_FD_OFFSET 1 /* Full duplex */ 26262306a36Sopenharmony_ci#define MACB_FD_SIZE 1 26362306a36Sopenharmony_ci#define MACB_BIT_RATE_OFFSET 2 /* Discard non-VLAN frames */ 26462306a36Sopenharmony_ci#define MACB_BIT_RATE_SIZE 1 26562306a36Sopenharmony_ci#define MACB_JFRAME_OFFSET 3 /* reserved */ 26662306a36Sopenharmony_ci#define MACB_JFRAME_SIZE 1 26762306a36Sopenharmony_ci#define MACB_CAF_OFFSET 4 /* Copy all frames */ 26862306a36Sopenharmony_ci#define MACB_CAF_SIZE 1 26962306a36Sopenharmony_ci#define MACB_NBC_OFFSET 5 /* No broadcast */ 27062306a36Sopenharmony_ci#define MACB_NBC_SIZE 1 27162306a36Sopenharmony_ci#define MACB_NCFGR_MTI_OFFSET 6 /* Multicast hash enable */ 27262306a36Sopenharmony_ci#define MACB_NCFGR_MTI_SIZE 1 27362306a36Sopenharmony_ci#define MACB_UNI_OFFSET 7 /* Unicast hash enable */ 27462306a36Sopenharmony_ci#define MACB_UNI_SIZE 1 27562306a36Sopenharmony_ci#define MACB_BIG_OFFSET 8 /* Receive 1536 byte frames */ 27662306a36Sopenharmony_ci#define MACB_BIG_SIZE 1 27762306a36Sopenharmony_ci#define MACB_EAE_OFFSET 9 /* External address match enable */ 27862306a36Sopenharmony_ci#define MACB_EAE_SIZE 1 27962306a36Sopenharmony_ci#define MACB_CLK_OFFSET 10 28062306a36Sopenharmony_ci#define MACB_CLK_SIZE 2 28162306a36Sopenharmony_ci#define MACB_RTY_OFFSET 12 /* Retry test */ 28262306a36Sopenharmony_ci#define MACB_RTY_SIZE 1 28362306a36Sopenharmony_ci#define MACB_PAE_OFFSET 13 /* Pause enable */ 28462306a36Sopenharmony_ci#define MACB_PAE_SIZE 1 28562306a36Sopenharmony_ci#define MACB_RM9200_RMII_OFFSET 13 /* AT91RM9200 only */ 28662306a36Sopenharmony_ci#define MACB_RM9200_RMII_SIZE 1 /* AT91RM9200 only */ 28762306a36Sopenharmony_ci#define MACB_RBOF_OFFSET 14 /* Receive buffer offset */ 28862306a36Sopenharmony_ci#define MACB_RBOF_SIZE 2 28962306a36Sopenharmony_ci#define MACB_RLCE_OFFSET 16 /* Length field error frame discard */ 29062306a36Sopenharmony_ci#define MACB_RLCE_SIZE 1 29162306a36Sopenharmony_ci#define MACB_DRFCS_OFFSET 17 /* FCS remove */ 29262306a36Sopenharmony_ci#define MACB_DRFCS_SIZE 1 29362306a36Sopenharmony_ci#define MACB_EFRHD_OFFSET 18 29462306a36Sopenharmony_ci#define MACB_EFRHD_SIZE 1 29562306a36Sopenharmony_ci#define MACB_IRXFCS_OFFSET 19 29662306a36Sopenharmony_ci#define MACB_IRXFCS_SIZE 1 29762306a36Sopenharmony_ci 29862306a36Sopenharmony_ci/* GEM specific NCR bitfields. */ 29962306a36Sopenharmony_ci#define GEM_ENABLE_HS_MAC_OFFSET 31 30062306a36Sopenharmony_ci#define GEM_ENABLE_HS_MAC_SIZE 1 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci/* GEM specific NCFGR bitfields. */ 30362306a36Sopenharmony_ci#define GEM_FD_OFFSET 1 /* Full duplex */ 30462306a36Sopenharmony_ci#define GEM_FD_SIZE 1 30562306a36Sopenharmony_ci#define GEM_GBE_OFFSET 10 /* Gigabit mode enable */ 30662306a36Sopenharmony_ci#define GEM_GBE_SIZE 1 30762306a36Sopenharmony_ci#define GEM_PCSSEL_OFFSET 11 30862306a36Sopenharmony_ci#define GEM_PCSSEL_SIZE 1 30962306a36Sopenharmony_ci#define GEM_PAE_OFFSET 13 /* Pause enable */ 31062306a36Sopenharmony_ci#define GEM_PAE_SIZE 1 31162306a36Sopenharmony_ci#define GEM_CLK_OFFSET 18 /* MDC clock division */ 31262306a36Sopenharmony_ci#define GEM_CLK_SIZE 3 31362306a36Sopenharmony_ci#define GEM_DBW_OFFSET 21 /* Data bus width */ 31462306a36Sopenharmony_ci#define GEM_DBW_SIZE 2 31562306a36Sopenharmony_ci#define GEM_RXCOEN_OFFSET 24 31662306a36Sopenharmony_ci#define GEM_RXCOEN_SIZE 1 31762306a36Sopenharmony_ci#define GEM_SGMIIEN_OFFSET 27 31862306a36Sopenharmony_ci#define GEM_SGMIIEN_SIZE 1 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ci 32162306a36Sopenharmony_ci/* Constants for data bus width. */ 32262306a36Sopenharmony_ci#define GEM_DBW32 0 /* 32 bit AMBA AHB data bus width */ 32362306a36Sopenharmony_ci#define GEM_DBW64 1 /* 64 bit AMBA AHB data bus width */ 32462306a36Sopenharmony_ci#define GEM_DBW128 2 /* 128 bit AMBA AHB data bus width */ 32562306a36Sopenharmony_ci 32662306a36Sopenharmony_ci/* Bitfields in DMACFG. */ 32762306a36Sopenharmony_ci#define GEM_FBLDO_OFFSET 0 /* fixed burst length for DMA */ 32862306a36Sopenharmony_ci#define GEM_FBLDO_SIZE 5 32962306a36Sopenharmony_ci#define GEM_ENDIA_DESC_OFFSET 6 /* endian swap mode for management descriptor access */ 33062306a36Sopenharmony_ci#define GEM_ENDIA_DESC_SIZE 1 33162306a36Sopenharmony_ci#define GEM_ENDIA_PKT_OFFSET 7 /* endian swap mode for packet data access */ 33262306a36Sopenharmony_ci#define GEM_ENDIA_PKT_SIZE 1 33362306a36Sopenharmony_ci#define GEM_RXBMS_OFFSET 8 /* RX packet buffer memory size select */ 33462306a36Sopenharmony_ci#define GEM_RXBMS_SIZE 2 33562306a36Sopenharmony_ci#define GEM_TXPBMS_OFFSET 10 /* TX packet buffer memory size select */ 33662306a36Sopenharmony_ci#define GEM_TXPBMS_SIZE 1 33762306a36Sopenharmony_ci#define GEM_TXCOEN_OFFSET 11 /* TX IP/TCP/UDP checksum gen offload */ 33862306a36Sopenharmony_ci#define GEM_TXCOEN_SIZE 1 33962306a36Sopenharmony_ci#define GEM_RXBS_OFFSET 16 /* DMA receive buffer size */ 34062306a36Sopenharmony_ci#define GEM_RXBS_SIZE 8 34162306a36Sopenharmony_ci#define GEM_DDRP_OFFSET 24 /* disc_when_no_ahb */ 34262306a36Sopenharmony_ci#define GEM_DDRP_SIZE 1 34362306a36Sopenharmony_ci#define GEM_RXEXT_OFFSET 28 /* RX extended Buffer Descriptor mode */ 34462306a36Sopenharmony_ci#define GEM_RXEXT_SIZE 1 34562306a36Sopenharmony_ci#define GEM_TXEXT_OFFSET 29 /* TX extended Buffer Descriptor mode */ 34662306a36Sopenharmony_ci#define GEM_TXEXT_SIZE 1 34762306a36Sopenharmony_ci#define GEM_ADDR64_OFFSET 30 /* Address bus width - 64b or 32b */ 34862306a36Sopenharmony_ci#define GEM_ADDR64_SIZE 1 34962306a36Sopenharmony_ci 35062306a36Sopenharmony_ci 35162306a36Sopenharmony_ci/* Bitfields in PBUFRXCUT */ 35262306a36Sopenharmony_ci#define GEM_ENCUTTHRU_OFFSET 31 /* Enable RX partial store and forward */ 35362306a36Sopenharmony_ci#define GEM_ENCUTTHRU_SIZE 1 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci/* Bitfields in NSR */ 35662306a36Sopenharmony_ci#define MACB_NSR_LINK_OFFSET 0 /* pcs_link_state */ 35762306a36Sopenharmony_ci#define MACB_NSR_LINK_SIZE 1 35862306a36Sopenharmony_ci#define MACB_MDIO_OFFSET 1 /* status of the mdio_in pin */ 35962306a36Sopenharmony_ci#define MACB_MDIO_SIZE 1 36062306a36Sopenharmony_ci#define MACB_IDLE_OFFSET 2 /* The PHY management logic is idle */ 36162306a36Sopenharmony_ci#define MACB_IDLE_SIZE 1 36262306a36Sopenharmony_ci 36362306a36Sopenharmony_ci/* Bitfields in TSR */ 36462306a36Sopenharmony_ci#define MACB_UBR_OFFSET 0 /* Used bit read */ 36562306a36Sopenharmony_ci#define MACB_UBR_SIZE 1 36662306a36Sopenharmony_ci#define MACB_COL_OFFSET 1 /* Collision occurred */ 36762306a36Sopenharmony_ci#define MACB_COL_SIZE 1 36862306a36Sopenharmony_ci#define MACB_TSR_RLE_OFFSET 2 /* Retry limit exceeded */ 36962306a36Sopenharmony_ci#define MACB_TSR_RLE_SIZE 1 37062306a36Sopenharmony_ci#define MACB_TGO_OFFSET 3 /* Transmit go */ 37162306a36Sopenharmony_ci#define MACB_TGO_SIZE 1 37262306a36Sopenharmony_ci#define MACB_BEX_OFFSET 4 /* TX frame corruption due to AHB error */ 37362306a36Sopenharmony_ci#define MACB_BEX_SIZE 1 37462306a36Sopenharmony_ci#define MACB_RM9200_BNQ_OFFSET 4 /* AT91RM9200 only */ 37562306a36Sopenharmony_ci#define MACB_RM9200_BNQ_SIZE 1 /* AT91RM9200 only */ 37662306a36Sopenharmony_ci#define MACB_COMP_OFFSET 5 /* Trnasmit complete */ 37762306a36Sopenharmony_ci#define MACB_COMP_SIZE 1 37862306a36Sopenharmony_ci#define MACB_UND_OFFSET 6 /* Trnasmit under run */ 37962306a36Sopenharmony_ci#define MACB_UND_SIZE 1 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci/* Bitfields in RSR */ 38262306a36Sopenharmony_ci#define MACB_BNA_OFFSET 0 /* Buffer not available */ 38362306a36Sopenharmony_ci#define MACB_BNA_SIZE 1 38462306a36Sopenharmony_ci#define MACB_REC_OFFSET 1 /* Frame received */ 38562306a36Sopenharmony_ci#define MACB_REC_SIZE 1 38662306a36Sopenharmony_ci#define MACB_OVR_OFFSET 2 /* Receive overrun */ 38762306a36Sopenharmony_ci#define MACB_OVR_SIZE 1 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci/* Bitfields in ISR/IER/IDR/IMR */ 39062306a36Sopenharmony_ci#define MACB_MFD_OFFSET 0 /* Management frame sent */ 39162306a36Sopenharmony_ci#define MACB_MFD_SIZE 1 39262306a36Sopenharmony_ci#define MACB_RCOMP_OFFSET 1 /* Receive complete */ 39362306a36Sopenharmony_ci#define MACB_RCOMP_SIZE 1 39462306a36Sopenharmony_ci#define MACB_RXUBR_OFFSET 2 /* RX used bit read */ 39562306a36Sopenharmony_ci#define MACB_RXUBR_SIZE 1 39662306a36Sopenharmony_ci#define MACB_TXUBR_OFFSET 3 /* TX used bit read */ 39762306a36Sopenharmony_ci#define MACB_TXUBR_SIZE 1 39862306a36Sopenharmony_ci#define MACB_ISR_TUND_OFFSET 4 /* Enable TX buffer under run interrupt */ 39962306a36Sopenharmony_ci#define MACB_ISR_TUND_SIZE 1 40062306a36Sopenharmony_ci#define MACB_ISR_RLE_OFFSET 5 /* EN retry exceeded/late coll interrupt */ 40162306a36Sopenharmony_ci#define MACB_ISR_RLE_SIZE 1 40262306a36Sopenharmony_ci#define MACB_TXERR_OFFSET 6 /* EN TX frame corrupt from error interrupt */ 40362306a36Sopenharmony_ci#define MACB_TXERR_SIZE 1 40462306a36Sopenharmony_ci#define MACB_RM9200_TBRE_OFFSET 6 /* EN may send new frame interrupt (RM9200) */ 40562306a36Sopenharmony_ci#define MACB_RM9200_TBRE_SIZE 1 40662306a36Sopenharmony_ci#define MACB_TCOMP_OFFSET 7 /* Enable transmit complete interrupt */ 40762306a36Sopenharmony_ci#define MACB_TCOMP_SIZE 1 40862306a36Sopenharmony_ci#define MACB_ISR_LINK_OFFSET 9 /* Enable link change interrupt */ 40962306a36Sopenharmony_ci#define MACB_ISR_LINK_SIZE 1 41062306a36Sopenharmony_ci#define MACB_ISR_ROVR_OFFSET 10 /* Enable receive overrun interrupt */ 41162306a36Sopenharmony_ci#define MACB_ISR_ROVR_SIZE 1 41262306a36Sopenharmony_ci#define MACB_HRESP_OFFSET 11 /* Enable hrsep not OK interrupt */ 41362306a36Sopenharmony_ci#define MACB_HRESP_SIZE 1 41462306a36Sopenharmony_ci#define MACB_PFR_OFFSET 12 /* Enable pause frame w/ quantum interrupt */ 41562306a36Sopenharmony_ci#define MACB_PFR_SIZE 1 41662306a36Sopenharmony_ci#define MACB_PTZ_OFFSET 13 /* Enable pause time zero interrupt */ 41762306a36Sopenharmony_ci#define MACB_PTZ_SIZE 1 41862306a36Sopenharmony_ci#define MACB_WOL_OFFSET 14 /* Enable wake-on-lan interrupt */ 41962306a36Sopenharmony_ci#define MACB_WOL_SIZE 1 42062306a36Sopenharmony_ci#define MACB_DRQFR_OFFSET 18 /* PTP Delay Request Frame Received */ 42162306a36Sopenharmony_ci#define MACB_DRQFR_SIZE 1 42262306a36Sopenharmony_ci#define MACB_SFR_OFFSET 19 /* PTP Sync Frame Received */ 42362306a36Sopenharmony_ci#define MACB_SFR_SIZE 1 42462306a36Sopenharmony_ci#define MACB_DRQFT_OFFSET 20 /* PTP Delay Request Frame Transmitted */ 42562306a36Sopenharmony_ci#define MACB_DRQFT_SIZE 1 42662306a36Sopenharmony_ci#define MACB_SFT_OFFSET 21 /* PTP Sync Frame Transmitted */ 42762306a36Sopenharmony_ci#define MACB_SFT_SIZE 1 42862306a36Sopenharmony_ci#define MACB_PDRQFR_OFFSET 22 /* PDelay Request Frame Received */ 42962306a36Sopenharmony_ci#define MACB_PDRQFR_SIZE 1 43062306a36Sopenharmony_ci#define MACB_PDRSFR_OFFSET 23 /* PDelay Response Frame Received */ 43162306a36Sopenharmony_ci#define MACB_PDRSFR_SIZE 1 43262306a36Sopenharmony_ci#define MACB_PDRQFT_OFFSET 24 /* PDelay Request Frame Transmitted */ 43362306a36Sopenharmony_ci#define MACB_PDRQFT_SIZE 1 43462306a36Sopenharmony_ci#define MACB_PDRSFT_OFFSET 25 /* PDelay Response Frame Transmitted */ 43562306a36Sopenharmony_ci#define MACB_PDRSFT_SIZE 1 43662306a36Sopenharmony_ci#define MACB_SRI_OFFSET 26 /* TSU Seconds Register Increment */ 43762306a36Sopenharmony_ci#define MACB_SRI_SIZE 1 43862306a36Sopenharmony_ci#define GEM_WOL_OFFSET 28 /* Enable wake-on-lan interrupt */ 43962306a36Sopenharmony_ci#define GEM_WOL_SIZE 1 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci/* Timer increment fields */ 44262306a36Sopenharmony_ci#define MACB_TI_CNS_OFFSET 0 44362306a36Sopenharmony_ci#define MACB_TI_CNS_SIZE 8 44462306a36Sopenharmony_ci#define MACB_TI_ACNS_OFFSET 8 44562306a36Sopenharmony_ci#define MACB_TI_ACNS_SIZE 8 44662306a36Sopenharmony_ci#define MACB_TI_NIT_OFFSET 16 44762306a36Sopenharmony_ci#define MACB_TI_NIT_SIZE 8 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci/* Bitfields in MAN */ 45062306a36Sopenharmony_ci#define MACB_DATA_OFFSET 0 /* data */ 45162306a36Sopenharmony_ci#define MACB_DATA_SIZE 16 45262306a36Sopenharmony_ci#define MACB_CODE_OFFSET 16 /* Must be written to 10 */ 45362306a36Sopenharmony_ci#define MACB_CODE_SIZE 2 45462306a36Sopenharmony_ci#define MACB_REGA_OFFSET 18 /* Register address */ 45562306a36Sopenharmony_ci#define MACB_REGA_SIZE 5 45662306a36Sopenharmony_ci#define MACB_PHYA_OFFSET 23 /* PHY address */ 45762306a36Sopenharmony_ci#define MACB_PHYA_SIZE 5 45862306a36Sopenharmony_ci#define MACB_RW_OFFSET 28 /* Operation. 10 is read. 01 is write. */ 45962306a36Sopenharmony_ci#define MACB_RW_SIZE 2 46062306a36Sopenharmony_ci#define MACB_SOF_OFFSET 30 /* Must be written to 1 for Clause 22 */ 46162306a36Sopenharmony_ci#define MACB_SOF_SIZE 2 46262306a36Sopenharmony_ci 46362306a36Sopenharmony_ci/* Bitfields in USRIO (AVR32) */ 46462306a36Sopenharmony_ci#define MACB_MII_OFFSET 0 46562306a36Sopenharmony_ci#define MACB_MII_SIZE 1 46662306a36Sopenharmony_ci#define MACB_EAM_OFFSET 1 46762306a36Sopenharmony_ci#define MACB_EAM_SIZE 1 46862306a36Sopenharmony_ci#define MACB_TX_PAUSE_OFFSET 2 46962306a36Sopenharmony_ci#define MACB_TX_PAUSE_SIZE 1 47062306a36Sopenharmony_ci#define MACB_TX_PAUSE_ZERO_OFFSET 3 47162306a36Sopenharmony_ci#define MACB_TX_PAUSE_ZERO_SIZE 1 47262306a36Sopenharmony_ci 47362306a36Sopenharmony_ci/* Bitfields in USRIO (AT91) */ 47462306a36Sopenharmony_ci#define MACB_RMII_OFFSET 0 47562306a36Sopenharmony_ci#define MACB_RMII_SIZE 1 47662306a36Sopenharmony_ci#define GEM_RGMII_OFFSET 0 /* GEM gigabit mode */ 47762306a36Sopenharmony_ci#define GEM_RGMII_SIZE 1 47862306a36Sopenharmony_ci#define MACB_CLKEN_OFFSET 1 47962306a36Sopenharmony_ci#define MACB_CLKEN_SIZE 1 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci/* Bitfields in WOL */ 48262306a36Sopenharmony_ci#define MACB_IP_OFFSET 0 48362306a36Sopenharmony_ci#define MACB_IP_SIZE 16 48462306a36Sopenharmony_ci#define MACB_MAG_OFFSET 16 48562306a36Sopenharmony_ci#define MACB_MAG_SIZE 1 48662306a36Sopenharmony_ci#define MACB_ARP_OFFSET 17 48762306a36Sopenharmony_ci#define MACB_ARP_SIZE 1 48862306a36Sopenharmony_ci#define MACB_SA1_OFFSET 18 48962306a36Sopenharmony_ci#define MACB_SA1_SIZE 1 49062306a36Sopenharmony_ci#define MACB_WOL_MTI_OFFSET 19 49162306a36Sopenharmony_ci#define MACB_WOL_MTI_SIZE 1 49262306a36Sopenharmony_ci 49362306a36Sopenharmony_ci/* Bitfields in MID */ 49462306a36Sopenharmony_ci#define MACB_IDNUM_OFFSET 16 49562306a36Sopenharmony_ci#define MACB_IDNUM_SIZE 12 49662306a36Sopenharmony_ci#define MACB_REV_OFFSET 0 49762306a36Sopenharmony_ci#define MACB_REV_SIZE 16 49862306a36Sopenharmony_ci 49962306a36Sopenharmony_ci/* Bitfield in HS_MAC_CONFIG */ 50062306a36Sopenharmony_ci#define GEM_HS_MAC_SPEED_OFFSET 0 50162306a36Sopenharmony_ci#define GEM_HS_MAC_SPEED_SIZE 3 50262306a36Sopenharmony_ci 50362306a36Sopenharmony_ci/* Bitfields in PCSCNTRL */ 50462306a36Sopenharmony_ci#define GEM_PCSAUTONEG_OFFSET 12 50562306a36Sopenharmony_ci#define GEM_PCSAUTONEG_SIZE 1 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci/* Bitfields in DCFG1. */ 50862306a36Sopenharmony_ci#define GEM_IRQCOR_OFFSET 23 50962306a36Sopenharmony_ci#define GEM_IRQCOR_SIZE 1 51062306a36Sopenharmony_ci#define GEM_DBWDEF_OFFSET 25 51162306a36Sopenharmony_ci#define GEM_DBWDEF_SIZE 3 51262306a36Sopenharmony_ci#define GEM_NO_PCS_OFFSET 0 51362306a36Sopenharmony_ci#define GEM_NO_PCS_SIZE 1 51462306a36Sopenharmony_ci 51562306a36Sopenharmony_ci/* Bitfields in DCFG2. */ 51662306a36Sopenharmony_ci#define GEM_RX_PKT_BUFF_OFFSET 20 51762306a36Sopenharmony_ci#define GEM_RX_PKT_BUFF_SIZE 1 51862306a36Sopenharmony_ci#define GEM_TX_PKT_BUFF_OFFSET 21 51962306a36Sopenharmony_ci#define GEM_TX_PKT_BUFF_SIZE 1 52062306a36Sopenharmony_ci 52162306a36Sopenharmony_ci#define GEM_RX_PBUF_ADDR_OFFSET 22 52262306a36Sopenharmony_ci#define GEM_RX_PBUF_ADDR_SIZE 4 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_ci/* Bitfields in DCFG5. */ 52562306a36Sopenharmony_ci#define GEM_TSU_OFFSET 8 52662306a36Sopenharmony_ci#define GEM_TSU_SIZE 1 52762306a36Sopenharmony_ci 52862306a36Sopenharmony_ci/* Bitfields in DCFG6. */ 52962306a36Sopenharmony_ci#define GEM_PBUF_LSO_OFFSET 27 53062306a36Sopenharmony_ci#define GEM_PBUF_LSO_SIZE 1 53162306a36Sopenharmony_ci#define GEM_PBUF_CUTTHRU_OFFSET 25 53262306a36Sopenharmony_ci#define GEM_PBUF_CUTTHRU_SIZE 1 53362306a36Sopenharmony_ci#define GEM_DAW64_OFFSET 23 53462306a36Sopenharmony_ci#define GEM_DAW64_SIZE 1 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_ci/* Bitfields in DCFG8. */ 53762306a36Sopenharmony_ci#define GEM_T1SCR_OFFSET 24 53862306a36Sopenharmony_ci#define GEM_T1SCR_SIZE 8 53962306a36Sopenharmony_ci#define GEM_T2SCR_OFFSET 16 54062306a36Sopenharmony_ci#define GEM_T2SCR_SIZE 8 54162306a36Sopenharmony_ci#define GEM_SCR2ETH_OFFSET 8 54262306a36Sopenharmony_ci#define GEM_SCR2ETH_SIZE 8 54362306a36Sopenharmony_ci#define GEM_SCR2CMP_OFFSET 0 54462306a36Sopenharmony_ci#define GEM_SCR2CMP_SIZE 8 54562306a36Sopenharmony_ci 54662306a36Sopenharmony_ci/* Bitfields in DCFG10 */ 54762306a36Sopenharmony_ci#define GEM_TXBD_RDBUFF_OFFSET 12 54862306a36Sopenharmony_ci#define GEM_TXBD_RDBUFF_SIZE 4 54962306a36Sopenharmony_ci#define GEM_RXBD_RDBUFF_OFFSET 8 55062306a36Sopenharmony_ci#define GEM_RXBD_RDBUFF_SIZE 4 55162306a36Sopenharmony_ci 55262306a36Sopenharmony_ci/* Bitfields in DCFG12. */ 55362306a36Sopenharmony_ci#define GEM_HIGH_SPEED_OFFSET 26 55462306a36Sopenharmony_ci#define GEM_HIGH_SPEED_SIZE 1 55562306a36Sopenharmony_ci 55662306a36Sopenharmony_ci/* Bitfields in USX_CONTROL. */ 55762306a36Sopenharmony_ci#define GEM_USX_CTRL_SPEED_OFFSET 14 55862306a36Sopenharmony_ci#define GEM_USX_CTRL_SPEED_SIZE 3 55962306a36Sopenharmony_ci#define GEM_SERDES_RATE_OFFSET 12 56062306a36Sopenharmony_ci#define GEM_SERDES_RATE_SIZE 2 56162306a36Sopenharmony_ci#define GEM_RX_SCR_BYPASS_OFFSET 9 56262306a36Sopenharmony_ci#define GEM_RX_SCR_BYPASS_SIZE 1 56362306a36Sopenharmony_ci#define GEM_TX_SCR_BYPASS_OFFSET 8 56462306a36Sopenharmony_ci#define GEM_TX_SCR_BYPASS_SIZE 1 56562306a36Sopenharmony_ci#define GEM_TX_EN_OFFSET 1 56662306a36Sopenharmony_ci#define GEM_TX_EN_SIZE 1 56762306a36Sopenharmony_ci#define GEM_SIGNAL_OK_OFFSET 0 56862306a36Sopenharmony_ci#define GEM_SIGNAL_OK_SIZE 1 56962306a36Sopenharmony_ci 57062306a36Sopenharmony_ci/* Bitfields in USX_STATUS. */ 57162306a36Sopenharmony_ci#define GEM_USX_BLOCK_LOCK_OFFSET 0 57262306a36Sopenharmony_ci#define GEM_USX_BLOCK_LOCK_SIZE 1 57362306a36Sopenharmony_ci 57462306a36Sopenharmony_ci/* Bitfields in TISUBN */ 57562306a36Sopenharmony_ci#define GEM_SUBNSINCR_OFFSET 0 57662306a36Sopenharmony_ci#define GEM_SUBNSINCRL_OFFSET 24 57762306a36Sopenharmony_ci#define GEM_SUBNSINCRL_SIZE 8 57862306a36Sopenharmony_ci#define GEM_SUBNSINCRH_OFFSET 0 57962306a36Sopenharmony_ci#define GEM_SUBNSINCRH_SIZE 16 58062306a36Sopenharmony_ci#define GEM_SUBNSINCR_SIZE 24 58162306a36Sopenharmony_ci 58262306a36Sopenharmony_ci/* Bitfields in TI */ 58362306a36Sopenharmony_ci#define GEM_NSINCR_OFFSET 0 58462306a36Sopenharmony_ci#define GEM_NSINCR_SIZE 8 58562306a36Sopenharmony_ci 58662306a36Sopenharmony_ci/* Bitfields in TSH */ 58762306a36Sopenharmony_ci#define GEM_TSH_OFFSET 0 /* TSU timer value (s). MSB [47:32] of seconds timer count */ 58862306a36Sopenharmony_ci#define GEM_TSH_SIZE 16 58962306a36Sopenharmony_ci 59062306a36Sopenharmony_ci/* Bitfields in TSL */ 59162306a36Sopenharmony_ci#define GEM_TSL_OFFSET 0 /* TSU timer value (s). LSB [31:0] of seconds timer count */ 59262306a36Sopenharmony_ci#define GEM_TSL_SIZE 32 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ci/* Bitfields in TN */ 59562306a36Sopenharmony_ci#define GEM_TN_OFFSET 0 /* TSU timer value (ns) */ 59662306a36Sopenharmony_ci#define GEM_TN_SIZE 30 59762306a36Sopenharmony_ci 59862306a36Sopenharmony_ci/* Bitfields in TXBDCTRL */ 59962306a36Sopenharmony_ci#define GEM_TXTSMODE_OFFSET 4 /* TX Descriptor Timestamp Insertion mode */ 60062306a36Sopenharmony_ci#define GEM_TXTSMODE_SIZE 2 60162306a36Sopenharmony_ci 60262306a36Sopenharmony_ci/* Bitfields in RXBDCTRL */ 60362306a36Sopenharmony_ci#define GEM_RXTSMODE_OFFSET 4 /* RX Descriptor Timestamp Insertion mode */ 60462306a36Sopenharmony_ci#define GEM_RXTSMODE_SIZE 2 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci/* Bitfields in SCRT2 */ 60762306a36Sopenharmony_ci#define GEM_QUEUE_OFFSET 0 /* Queue Number */ 60862306a36Sopenharmony_ci#define GEM_QUEUE_SIZE 4 60962306a36Sopenharmony_ci#define GEM_VLANPR_OFFSET 4 /* VLAN Priority */ 61062306a36Sopenharmony_ci#define GEM_VLANPR_SIZE 3 61162306a36Sopenharmony_ci#define GEM_VLANEN_OFFSET 8 /* VLAN Enable */ 61262306a36Sopenharmony_ci#define GEM_VLANEN_SIZE 1 61362306a36Sopenharmony_ci#define GEM_ETHT2IDX_OFFSET 9 /* Index to screener type 2 EtherType register */ 61462306a36Sopenharmony_ci#define GEM_ETHT2IDX_SIZE 3 61562306a36Sopenharmony_ci#define GEM_ETHTEN_OFFSET 12 /* EtherType Enable */ 61662306a36Sopenharmony_ci#define GEM_ETHTEN_SIZE 1 61762306a36Sopenharmony_ci#define GEM_CMPA_OFFSET 13 /* Compare A - Index to screener type 2 Compare register */ 61862306a36Sopenharmony_ci#define GEM_CMPA_SIZE 5 61962306a36Sopenharmony_ci#define GEM_CMPAEN_OFFSET 18 /* Compare A Enable */ 62062306a36Sopenharmony_ci#define GEM_CMPAEN_SIZE 1 62162306a36Sopenharmony_ci#define GEM_CMPB_OFFSET 19 /* Compare B - Index to screener type 2 Compare register */ 62262306a36Sopenharmony_ci#define GEM_CMPB_SIZE 5 62362306a36Sopenharmony_ci#define GEM_CMPBEN_OFFSET 24 /* Compare B Enable */ 62462306a36Sopenharmony_ci#define GEM_CMPBEN_SIZE 1 62562306a36Sopenharmony_ci#define GEM_CMPC_OFFSET 25 /* Compare C - Index to screener type 2 Compare register */ 62662306a36Sopenharmony_ci#define GEM_CMPC_SIZE 5 62762306a36Sopenharmony_ci#define GEM_CMPCEN_OFFSET 30 /* Compare C Enable */ 62862306a36Sopenharmony_ci#define GEM_CMPCEN_SIZE 1 62962306a36Sopenharmony_ci 63062306a36Sopenharmony_ci/* Bitfields in ETHT */ 63162306a36Sopenharmony_ci#define GEM_ETHTCMP_OFFSET 0 /* EtherType compare value */ 63262306a36Sopenharmony_ci#define GEM_ETHTCMP_SIZE 16 63362306a36Sopenharmony_ci 63462306a36Sopenharmony_ci/* Bitfields in T2CMPW0 */ 63562306a36Sopenharmony_ci#define GEM_T2CMP_OFFSET 16 /* 0xFFFF0000 compare value */ 63662306a36Sopenharmony_ci#define GEM_T2CMP_SIZE 16 63762306a36Sopenharmony_ci#define GEM_T2MASK_OFFSET 0 /* 0x0000FFFF compare value or mask */ 63862306a36Sopenharmony_ci#define GEM_T2MASK_SIZE 16 63962306a36Sopenharmony_ci 64062306a36Sopenharmony_ci/* Bitfields in T2CMPW1 */ 64162306a36Sopenharmony_ci#define GEM_T2DISMSK_OFFSET 9 /* disable mask */ 64262306a36Sopenharmony_ci#define GEM_T2DISMSK_SIZE 1 64362306a36Sopenharmony_ci#define GEM_T2CMPOFST_OFFSET 7 /* compare offset */ 64462306a36Sopenharmony_ci#define GEM_T2CMPOFST_SIZE 2 64562306a36Sopenharmony_ci#define GEM_T2OFST_OFFSET 0 /* offset value */ 64662306a36Sopenharmony_ci#define GEM_T2OFST_SIZE 7 64762306a36Sopenharmony_ci 64862306a36Sopenharmony_ci/* Offset for screener type 2 compare values (T2CMPOFST). 64962306a36Sopenharmony_ci * Note the offset is applied after the specified point, 65062306a36Sopenharmony_ci * e.g. GEM_T2COMPOFST_ETYPE denotes the EtherType field, so an offset 65162306a36Sopenharmony_ci * of 12 bytes from this would be the source IP address in an IP header 65262306a36Sopenharmony_ci */ 65362306a36Sopenharmony_ci#define GEM_T2COMPOFST_SOF 0 65462306a36Sopenharmony_ci#define GEM_T2COMPOFST_ETYPE 1 65562306a36Sopenharmony_ci#define GEM_T2COMPOFST_IPHDR 2 65662306a36Sopenharmony_ci#define GEM_T2COMPOFST_TCPUDP 3 65762306a36Sopenharmony_ci 65862306a36Sopenharmony_ci/* offset from EtherType to IP address */ 65962306a36Sopenharmony_ci#define ETYPE_SRCIP_OFFSET 12 66062306a36Sopenharmony_ci#define ETYPE_DSTIP_OFFSET 16 66162306a36Sopenharmony_ci 66262306a36Sopenharmony_ci/* offset from IP header to port */ 66362306a36Sopenharmony_ci#define IPHDR_SRCPORT_OFFSET 0 66462306a36Sopenharmony_ci#define IPHDR_DSTPORT_OFFSET 2 66562306a36Sopenharmony_ci 66662306a36Sopenharmony_ci/* Transmit DMA buffer descriptor Word 1 */ 66762306a36Sopenharmony_ci#define GEM_DMA_TXVALID_OFFSET 23 /* timestamp has been captured in the Buffer Descriptor */ 66862306a36Sopenharmony_ci#define GEM_DMA_TXVALID_SIZE 1 66962306a36Sopenharmony_ci 67062306a36Sopenharmony_ci/* Receive DMA buffer descriptor Word 0 */ 67162306a36Sopenharmony_ci#define GEM_DMA_RXVALID_OFFSET 2 /* indicates a valid timestamp in the Buffer Descriptor */ 67262306a36Sopenharmony_ci#define GEM_DMA_RXVALID_SIZE 1 67362306a36Sopenharmony_ci 67462306a36Sopenharmony_ci/* DMA buffer descriptor Word 2 (32 bit addressing) or Word 4 (64 bit addressing) */ 67562306a36Sopenharmony_ci#define GEM_DMA_SECL_OFFSET 30 /* Timestamp seconds[1:0] */ 67662306a36Sopenharmony_ci#define GEM_DMA_SECL_SIZE 2 67762306a36Sopenharmony_ci#define GEM_DMA_NSEC_OFFSET 0 /* Timestamp nanosecs [29:0] */ 67862306a36Sopenharmony_ci#define GEM_DMA_NSEC_SIZE 30 67962306a36Sopenharmony_ci 68062306a36Sopenharmony_ci/* DMA buffer descriptor Word 3 (32 bit addressing) or Word 5 (64 bit addressing) */ 68162306a36Sopenharmony_ci 68262306a36Sopenharmony_ci/* New hardware supports 12 bit precision of timestamp in DMA buffer descriptor. 68362306a36Sopenharmony_ci * Old hardware supports only 6 bit precision but it is enough for PTP. 68462306a36Sopenharmony_ci * Less accuracy is used always instead of checking hardware version. 68562306a36Sopenharmony_ci */ 68662306a36Sopenharmony_ci#define GEM_DMA_SECH_OFFSET 0 /* Timestamp seconds[5:2] */ 68762306a36Sopenharmony_ci#define GEM_DMA_SECH_SIZE 4 68862306a36Sopenharmony_ci#define GEM_DMA_SEC_WIDTH (GEM_DMA_SECH_SIZE + GEM_DMA_SECL_SIZE) 68962306a36Sopenharmony_ci#define GEM_DMA_SEC_TOP (1 << GEM_DMA_SEC_WIDTH) 69062306a36Sopenharmony_ci#define GEM_DMA_SEC_MASK (GEM_DMA_SEC_TOP - 1) 69162306a36Sopenharmony_ci 69262306a36Sopenharmony_ci/* Bitfields in ADJ */ 69362306a36Sopenharmony_ci#define GEM_ADDSUB_OFFSET 31 69462306a36Sopenharmony_ci#define GEM_ADDSUB_SIZE 1 69562306a36Sopenharmony_ci/* Constants for CLK */ 69662306a36Sopenharmony_ci#define MACB_CLK_DIV8 0 69762306a36Sopenharmony_ci#define MACB_CLK_DIV16 1 69862306a36Sopenharmony_ci#define MACB_CLK_DIV32 2 69962306a36Sopenharmony_ci#define MACB_CLK_DIV64 3 70062306a36Sopenharmony_ci 70162306a36Sopenharmony_ci/* GEM specific constants for CLK. */ 70262306a36Sopenharmony_ci#define GEM_CLK_DIV8 0 70362306a36Sopenharmony_ci#define GEM_CLK_DIV16 1 70462306a36Sopenharmony_ci#define GEM_CLK_DIV32 2 70562306a36Sopenharmony_ci#define GEM_CLK_DIV48 3 70662306a36Sopenharmony_ci#define GEM_CLK_DIV64 4 70762306a36Sopenharmony_ci#define GEM_CLK_DIV96 5 70862306a36Sopenharmony_ci#define GEM_CLK_DIV128 6 70962306a36Sopenharmony_ci#define GEM_CLK_DIV224 7 71062306a36Sopenharmony_ci 71162306a36Sopenharmony_ci/* Constants for MAN register */ 71262306a36Sopenharmony_ci#define MACB_MAN_C22_SOF 1 71362306a36Sopenharmony_ci#define MACB_MAN_C22_WRITE 1 71462306a36Sopenharmony_ci#define MACB_MAN_C22_READ 2 71562306a36Sopenharmony_ci#define MACB_MAN_C22_CODE 2 71662306a36Sopenharmony_ci 71762306a36Sopenharmony_ci#define MACB_MAN_C45_SOF 0 71862306a36Sopenharmony_ci#define MACB_MAN_C45_ADDR 0 71962306a36Sopenharmony_ci#define MACB_MAN_C45_WRITE 1 72062306a36Sopenharmony_ci#define MACB_MAN_C45_POST_READ_INCR 2 72162306a36Sopenharmony_ci#define MACB_MAN_C45_READ 3 72262306a36Sopenharmony_ci#define MACB_MAN_C45_CODE 2 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_ci/* Capability mask bits */ 72562306a36Sopenharmony_ci#define MACB_CAPS_ISR_CLEAR_ON_WRITE 0x00000001 72662306a36Sopenharmony_ci#define MACB_CAPS_USRIO_HAS_CLKEN 0x00000002 72762306a36Sopenharmony_ci#define MACB_CAPS_USRIO_DEFAULT_IS_MII_GMII 0x00000004 72862306a36Sopenharmony_ci#define MACB_CAPS_NO_GIGABIT_HALF 0x00000008 72962306a36Sopenharmony_ci#define MACB_CAPS_USRIO_DISABLED 0x00000010 73062306a36Sopenharmony_ci#define MACB_CAPS_JUMBO 0x00000020 73162306a36Sopenharmony_ci#define MACB_CAPS_GEM_HAS_PTP 0x00000040 73262306a36Sopenharmony_ci#define MACB_CAPS_BD_RD_PREFETCH 0x00000080 73362306a36Sopenharmony_ci#define MACB_CAPS_NEEDS_RSTONUBR 0x00000100 73462306a36Sopenharmony_ci#define MACB_CAPS_MIIONRGMII 0x00000200 73562306a36Sopenharmony_ci#define MACB_CAPS_NEED_TSUCLK 0x00000400 73662306a36Sopenharmony_ci#define MACB_CAPS_PCS 0x01000000 73762306a36Sopenharmony_ci#define MACB_CAPS_HIGH_SPEED 0x02000000 73862306a36Sopenharmony_ci#define MACB_CAPS_CLK_HW_CHG 0x04000000 73962306a36Sopenharmony_ci#define MACB_CAPS_MACB_IS_EMAC 0x08000000 74062306a36Sopenharmony_ci#define MACB_CAPS_FIFO_MODE 0x10000000 74162306a36Sopenharmony_ci#define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000 74262306a36Sopenharmony_ci#define MACB_CAPS_SG_DISABLED 0x40000000 74362306a36Sopenharmony_ci#define MACB_CAPS_MACB_IS_GEM 0x80000000 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_ci/* LSO settings */ 74662306a36Sopenharmony_ci#define MACB_LSO_UFO_ENABLE 0x01 74762306a36Sopenharmony_ci#define MACB_LSO_TSO_ENABLE 0x02 74862306a36Sopenharmony_ci 74962306a36Sopenharmony_ci/* Bit manipulation macros */ 75062306a36Sopenharmony_ci#define MACB_BIT(name) \ 75162306a36Sopenharmony_ci (1 << MACB_##name##_OFFSET) 75262306a36Sopenharmony_ci#define MACB_BF(name,value) \ 75362306a36Sopenharmony_ci (((value) & ((1 << MACB_##name##_SIZE) - 1)) \ 75462306a36Sopenharmony_ci << MACB_##name##_OFFSET) 75562306a36Sopenharmony_ci#define MACB_BFEXT(name,value)\ 75662306a36Sopenharmony_ci (((value) >> MACB_##name##_OFFSET) \ 75762306a36Sopenharmony_ci & ((1 << MACB_##name##_SIZE) - 1)) 75862306a36Sopenharmony_ci#define MACB_BFINS(name,value,old) \ 75962306a36Sopenharmony_ci (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \ 76062306a36Sopenharmony_ci << MACB_##name##_OFFSET)) \ 76162306a36Sopenharmony_ci | MACB_BF(name,value)) 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ci#define GEM_BIT(name) \ 76462306a36Sopenharmony_ci (1 << GEM_##name##_OFFSET) 76562306a36Sopenharmony_ci#define GEM_BF(name, value) \ 76662306a36Sopenharmony_ci (((value) & ((1 << GEM_##name##_SIZE) - 1)) \ 76762306a36Sopenharmony_ci << GEM_##name##_OFFSET) 76862306a36Sopenharmony_ci#define GEM_BFEXT(name, value)\ 76962306a36Sopenharmony_ci (((value) >> GEM_##name##_OFFSET) \ 77062306a36Sopenharmony_ci & ((1 << GEM_##name##_SIZE) - 1)) 77162306a36Sopenharmony_ci#define GEM_BFINS(name, value, old) \ 77262306a36Sopenharmony_ci (((old) & ~(((1 << GEM_##name##_SIZE) - 1) \ 77362306a36Sopenharmony_ci << GEM_##name##_OFFSET)) \ 77462306a36Sopenharmony_ci | GEM_BF(name, value)) 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_ci/* Register access macros */ 77762306a36Sopenharmony_ci#define macb_readl(port, reg) (port)->macb_reg_readl((port), MACB_##reg) 77862306a36Sopenharmony_ci#define macb_writel(port, reg, value) (port)->macb_reg_writel((port), MACB_##reg, (value)) 77962306a36Sopenharmony_ci#define gem_readl(port, reg) (port)->macb_reg_readl((port), GEM_##reg) 78062306a36Sopenharmony_ci#define gem_writel(port, reg, value) (port)->macb_reg_writel((port), GEM_##reg, (value)) 78162306a36Sopenharmony_ci#define queue_readl(queue, reg) (queue)->bp->macb_reg_readl((queue)->bp, (queue)->reg) 78262306a36Sopenharmony_ci#define queue_writel(queue, reg, value) (queue)->bp->macb_reg_writel((queue)->bp, (queue)->reg, (value)) 78362306a36Sopenharmony_ci#define gem_readl_n(port, reg, idx) (port)->macb_reg_readl((port), GEM_##reg + idx * 4) 78462306a36Sopenharmony_ci#define gem_writel_n(port, reg, idx, value) (port)->macb_reg_writel((port), GEM_##reg + idx * 4, (value)) 78562306a36Sopenharmony_ci 78662306a36Sopenharmony_ci/* Conditional GEM/MACB macros. These perform the operation to the correct 78762306a36Sopenharmony_ci * register dependent on whether the device is a GEM or a MACB. For registers 78862306a36Sopenharmony_ci * and bitfields that are common across both devices, use macb_{read,write}l 78962306a36Sopenharmony_ci * to avoid the cost of the conditional. 79062306a36Sopenharmony_ci */ 79162306a36Sopenharmony_ci#define macb_or_gem_writel(__bp, __reg, __value) \ 79262306a36Sopenharmony_ci ({ \ 79362306a36Sopenharmony_ci if (macb_is_gem((__bp))) \ 79462306a36Sopenharmony_ci gem_writel((__bp), __reg, __value); \ 79562306a36Sopenharmony_ci else \ 79662306a36Sopenharmony_ci macb_writel((__bp), __reg, __value); \ 79762306a36Sopenharmony_ci }) 79862306a36Sopenharmony_ci 79962306a36Sopenharmony_ci#define macb_or_gem_readl(__bp, __reg) \ 80062306a36Sopenharmony_ci ({ \ 80162306a36Sopenharmony_ci u32 __v; \ 80262306a36Sopenharmony_ci if (macb_is_gem((__bp))) \ 80362306a36Sopenharmony_ci __v = gem_readl((__bp), __reg); \ 80462306a36Sopenharmony_ci else \ 80562306a36Sopenharmony_ci __v = macb_readl((__bp), __reg); \ 80662306a36Sopenharmony_ci __v; \ 80762306a36Sopenharmony_ci }) 80862306a36Sopenharmony_ci 80962306a36Sopenharmony_ci#define MACB_READ_NSR(bp) macb_readl(bp, NSR) 81062306a36Sopenharmony_ci 81162306a36Sopenharmony_ci/* struct macb_dma_desc - Hardware DMA descriptor 81262306a36Sopenharmony_ci * @addr: DMA address of data buffer 81362306a36Sopenharmony_ci * @ctrl: Control and status bits 81462306a36Sopenharmony_ci */ 81562306a36Sopenharmony_cistruct macb_dma_desc { 81662306a36Sopenharmony_ci u32 addr; 81762306a36Sopenharmony_ci u32 ctrl; 81862306a36Sopenharmony_ci}; 81962306a36Sopenharmony_ci 82062306a36Sopenharmony_ci#ifdef MACB_EXT_DESC 82162306a36Sopenharmony_ci#define HW_DMA_CAP_32B 0 82262306a36Sopenharmony_ci#define HW_DMA_CAP_64B (1 << 0) 82362306a36Sopenharmony_ci#define HW_DMA_CAP_PTP (1 << 1) 82462306a36Sopenharmony_ci#define HW_DMA_CAP_64B_PTP (HW_DMA_CAP_64B | HW_DMA_CAP_PTP) 82562306a36Sopenharmony_ci 82662306a36Sopenharmony_cistruct macb_dma_desc_64 { 82762306a36Sopenharmony_ci u32 addrh; 82862306a36Sopenharmony_ci u32 resvd; 82962306a36Sopenharmony_ci}; 83062306a36Sopenharmony_ci 83162306a36Sopenharmony_cistruct macb_dma_desc_ptp { 83262306a36Sopenharmony_ci u32 ts_1; 83362306a36Sopenharmony_ci u32 ts_2; 83462306a36Sopenharmony_ci}; 83562306a36Sopenharmony_ci#endif 83662306a36Sopenharmony_ci 83762306a36Sopenharmony_ci/* DMA descriptor bitfields */ 83862306a36Sopenharmony_ci#define MACB_RX_USED_OFFSET 0 83962306a36Sopenharmony_ci#define MACB_RX_USED_SIZE 1 84062306a36Sopenharmony_ci#define MACB_RX_WRAP_OFFSET 1 84162306a36Sopenharmony_ci#define MACB_RX_WRAP_SIZE 1 84262306a36Sopenharmony_ci#define MACB_RX_WADDR_OFFSET 2 84362306a36Sopenharmony_ci#define MACB_RX_WADDR_SIZE 30 84462306a36Sopenharmony_ci 84562306a36Sopenharmony_ci#define MACB_RX_FRMLEN_OFFSET 0 84662306a36Sopenharmony_ci#define MACB_RX_FRMLEN_SIZE 12 84762306a36Sopenharmony_ci#define MACB_RX_OFFSET_OFFSET 12 84862306a36Sopenharmony_ci#define MACB_RX_OFFSET_SIZE 2 84962306a36Sopenharmony_ci#define MACB_RX_SOF_OFFSET 14 85062306a36Sopenharmony_ci#define MACB_RX_SOF_SIZE 1 85162306a36Sopenharmony_ci#define MACB_RX_EOF_OFFSET 15 85262306a36Sopenharmony_ci#define MACB_RX_EOF_SIZE 1 85362306a36Sopenharmony_ci#define MACB_RX_CFI_OFFSET 16 85462306a36Sopenharmony_ci#define MACB_RX_CFI_SIZE 1 85562306a36Sopenharmony_ci#define MACB_RX_VLAN_PRI_OFFSET 17 85662306a36Sopenharmony_ci#define MACB_RX_VLAN_PRI_SIZE 3 85762306a36Sopenharmony_ci#define MACB_RX_PRI_TAG_OFFSET 20 85862306a36Sopenharmony_ci#define MACB_RX_PRI_TAG_SIZE 1 85962306a36Sopenharmony_ci#define MACB_RX_VLAN_TAG_OFFSET 21 86062306a36Sopenharmony_ci#define MACB_RX_VLAN_TAG_SIZE 1 86162306a36Sopenharmony_ci#define MACB_RX_TYPEID_MATCH_OFFSET 22 86262306a36Sopenharmony_ci#define MACB_RX_TYPEID_MATCH_SIZE 1 86362306a36Sopenharmony_ci#define MACB_RX_SA4_MATCH_OFFSET 23 86462306a36Sopenharmony_ci#define MACB_RX_SA4_MATCH_SIZE 1 86562306a36Sopenharmony_ci#define MACB_RX_SA3_MATCH_OFFSET 24 86662306a36Sopenharmony_ci#define MACB_RX_SA3_MATCH_SIZE 1 86762306a36Sopenharmony_ci#define MACB_RX_SA2_MATCH_OFFSET 25 86862306a36Sopenharmony_ci#define MACB_RX_SA2_MATCH_SIZE 1 86962306a36Sopenharmony_ci#define MACB_RX_SA1_MATCH_OFFSET 26 87062306a36Sopenharmony_ci#define MACB_RX_SA1_MATCH_SIZE 1 87162306a36Sopenharmony_ci#define MACB_RX_EXT_MATCH_OFFSET 28 87262306a36Sopenharmony_ci#define MACB_RX_EXT_MATCH_SIZE 1 87362306a36Sopenharmony_ci#define MACB_RX_UHASH_MATCH_OFFSET 29 87462306a36Sopenharmony_ci#define MACB_RX_UHASH_MATCH_SIZE 1 87562306a36Sopenharmony_ci#define MACB_RX_MHASH_MATCH_OFFSET 30 87662306a36Sopenharmony_ci#define MACB_RX_MHASH_MATCH_SIZE 1 87762306a36Sopenharmony_ci#define MACB_RX_BROADCAST_OFFSET 31 87862306a36Sopenharmony_ci#define MACB_RX_BROADCAST_SIZE 1 87962306a36Sopenharmony_ci 88062306a36Sopenharmony_ci#define MACB_RX_FRMLEN_MASK 0xFFF 88162306a36Sopenharmony_ci#define MACB_RX_JFRMLEN_MASK 0x3FFF 88262306a36Sopenharmony_ci 88362306a36Sopenharmony_ci/* RX checksum offload disabled: bit 24 clear in NCFGR */ 88462306a36Sopenharmony_ci#define GEM_RX_TYPEID_MATCH_OFFSET 22 88562306a36Sopenharmony_ci#define GEM_RX_TYPEID_MATCH_SIZE 2 88662306a36Sopenharmony_ci 88762306a36Sopenharmony_ci/* RX checksum offload enabled: bit 24 set in NCFGR */ 88862306a36Sopenharmony_ci#define GEM_RX_CSUM_OFFSET 22 88962306a36Sopenharmony_ci#define GEM_RX_CSUM_SIZE 2 89062306a36Sopenharmony_ci 89162306a36Sopenharmony_ci#define MACB_TX_FRMLEN_OFFSET 0 89262306a36Sopenharmony_ci#define MACB_TX_FRMLEN_SIZE 11 89362306a36Sopenharmony_ci#define MACB_TX_LAST_OFFSET 15 89462306a36Sopenharmony_ci#define MACB_TX_LAST_SIZE 1 89562306a36Sopenharmony_ci#define MACB_TX_NOCRC_OFFSET 16 89662306a36Sopenharmony_ci#define MACB_TX_NOCRC_SIZE 1 89762306a36Sopenharmony_ci#define MACB_MSS_MFS_OFFSET 16 89862306a36Sopenharmony_ci#define MACB_MSS_MFS_SIZE 14 89962306a36Sopenharmony_ci#define MACB_TX_LSO_OFFSET 17 90062306a36Sopenharmony_ci#define MACB_TX_LSO_SIZE 2 90162306a36Sopenharmony_ci#define MACB_TX_TCP_SEQ_SRC_OFFSET 19 90262306a36Sopenharmony_ci#define MACB_TX_TCP_SEQ_SRC_SIZE 1 90362306a36Sopenharmony_ci#define MACB_TX_BUF_EXHAUSTED_OFFSET 27 90462306a36Sopenharmony_ci#define MACB_TX_BUF_EXHAUSTED_SIZE 1 90562306a36Sopenharmony_ci#define MACB_TX_UNDERRUN_OFFSET 28 90662306a36Sopenharmony_ci#define MACB_TX_UNDERRUN_SIZE 1 90762306a36Sopenharmony_ci#define MACB_TX_ERROR_OFFSET 29 90862306a36Sopenharmony_ci#define MACB_TX_ERROR_SIZE 1 90962306a36Sopenharmony_ci#define MACB_TX_WRAP_OFFSET 30 91062306a36Sopenharmony_ci#define MACB_TX_WRAP_SIZE 1 91162306a36Sopenharmony_ci#define MACB_TX_USED_OFFSET 31 91262306a36Sopenharmony_ci#define MACB_TX_USED_SIZE 1 91362306a36Sopenharmony_ci 91462306a36Sopenharmony_ci#define GEM_TX_FRMLEN_OFFSET 0 91562306a36Sopenharmony_ci#define GEM_TX_FRMLEN_SIZE 14 91662306a36Sopenharmony_ci 91762306a36Sopenharmony_ci/* Buffer descriptor constants */ 91862306a36Sopenharmony_ci#define GEM_RX_CSUM_NONE 0 91962306a36Sopenharmony_ci#define GEM_RX_CSUM_IP_ONLY 1 92062306a36Sopenharmony_ci#define GEM_RX_CSUM_IP_TCP 2 92162306a36Sopenharmony_ci#define GEM_RX_CSUM_IP_UDP 3 92262306a36Sopenharmony_ci 92362306a36Sopenharmony_ci/* limit RX checksum offload to TCP and UDP packets */ 92462306a36Sopenharmony_ci#define GEM_RX_CSUM_CHECKED_MASK 2 92562306a36Sopenharmony_ci 92662306a36Sopenharmony_ci/* Scaled PPM fraction */ 92762306a36Sopenharmony_ci#define PPM_FRACTION 16 92862306a36Sopenharmony_ci 92962306a36Sopenharmony_ci/* struct macb_tx_skb - data about an skb which is being transmitted 93062306a36Sopenharmony_ci * @skb: skb currently being transmitted, only set for the last buffer 93162306a36Sopenharmony_ci * of the frame 93262306a36Sopenharmony_ci * @mapping: DMA address of the skb's fragment buffer 93362306a36Sopenharmony_ci * @size: size of the DMA mapped buffer 93462306a36Sopenharmony_ci * @mapped_as_page: true when buffer was mapped with skb_frag_dma_map(), 93562306a36Sopenharmony_ci * false when buffer was mapped with dma_map_single() 93662306a36Sopenharmony_ci */ 93762306a36Sopenharmony_cistruct macb_tx_skb { 93862306a36Sopenharmony_ci struct sk_buff *skb; 93962306a36Sopenharmony_ci dma_addr_t mapping; 94062306a36Sopenharmony_ci size_t size; 94162306a36Sopenharmony_ci bool mapped_as_page; 94262306a36Sopenharmony_ci}; 94362306a36Sopenharmony_ci 94462306a36Sopenharmony_ci/* Hardware-collected statistics. Used when updating the network 94562306a36Sopenharmony_ci * device stats by a periodic timer. 94662306a36Sopenharmony_ci */ 94762306a36Sopenharmony_cistruct macb_stats { 94862306a36Sopenharmony_ci u32 rx_pause_frames; 94962306a36Sopenharmony_ci u32 tx_ok; 95062306a36Sopenharmony_ci u32 tx_single_cols; 95162306a36Sopenharmony_ci u32 tx_multiple_cols; 95262306a36Sopenharmony_ci u32 rx_ok; 95362306a36Sopenharmony_ci u32 rx_fcs_errors; 95462306a36Sopenharmony_ci u32 rx_align_errors; 95562306a36Sopenharmony_ci u32 tx_deferred; 95662306a36Sopenharmony_ci u32 tx_late_cols; 95762306a36Sopenharmony_ci u32 tx_excessive_cols; 95862306a36Sopenharmony_ci u32 tx_underruns; 95962306a36Sopenharmony_ci u32 tx_carrier_errors; 96062306a36Sopenharmony_ci u32 rx_resource_errors; 96162306a36Sopenharmony_ci u32 rx_overruns; 96262306a36Sopenharmony_ci u32 rx_symbol_errors; 96362306a36Sopenharmony_ci u32 rx_oversize_pkts; 96462306a36Sopenharmony_ci u32 rx_jabbers; 96562306a36Sopenharmony_ci u32 rx_undersize_pkts; 96662306a36Sopenharmony_ci u32 sqe_test_errors; 96762306a36Sopenharmony_ci u32 rx_length_mismatch; 96862306a36Sopenharmony_ci u32 tx_pause_frames; 96962306a36Sopenharmony_ci}; 97062306a36Sopenharmony_ci 97162306a36Sopenharmony_cistruct gem_stats { 97262306a36Sopenharmony_ci u32 tx_octets_31_0; 97362306a36Sopenharmony_ci u32 tx_octets_47_32; 97462306a36Sopenharmony_ci u32 tx_frames; 97562306a36Sopenharmony_ci u32 tx_broadcast_frames; 97662306a36Sopenharmony_ci u32 tx_multicast_frames; 97762306a36Sopenharmony_ci u32 tx_pause_frames; 97862306a36Sopenharmony_ci u32 tx_64_byte_frames; 97962306a36Sopenharmony_ci u32 tx_65_127_byte_frames; 98062306a36Sopenharmony_ci u32 tx_128_255_byte_frames; 98162306a36Sopenharmony_ci u32 tx_256_511_byte_frames; 98262306a36Sopenharmony_ci u32 tx_512_1023_byte_frames; 98362306a36Sopenharmony_ci u32 tx_1024_1518_byte_frames; 98462306a36Sopenharmony_ci u32 tx_greater_than_1518_byte_frames; 98562306a36Sopenharmony_ci u32 tx_underrun; 98662306a36Sopenharmony_ci u32 tx_single_collision_frames; 98762306a36Sopenharmony_ci u32 tx_multiple_collision_frames; 98862306a36Sopenharmony_ci u32 tx_excessive_collisions; 98962306a36Sopenharmony_ci u32 tx_late_collisions; 99062306a36Sopenharmony_ci u32 tx_deferred_frames; 99162306a36Sopenharmony_ci u32 tx_carrier_sense_errors; 99262306a36Sopenharmony_ci u32 rx_octets_31_0; 99362306a36Sopenharmony_ci u32 rx_octets_47_32; 99462306a36Sopenharmony_ci u32 rx_frames; 99562306a36Sopenharmony_ci u32 rx_broadcast_frames; 99662306a36Sopenharmony_ci u32 rx_multicast_frames; 99762306a36Sopenharmony_ci u32 rx_pause_frames; 99862306a36Sopenharmony_ci u32 rx_64_byte_frames; 99962306a36Sopenharmony_ci u32 rx_65_127_byte_frames; 100062306a36Sopenharmony_ci u32 rx_128_255_byte_frames; 100162306a36Sopenharmony_ci u32 rx_256_511_byte_frames; 100262306a36Sopenharmony_ci u32 rx_512_1023_byte_frames; 100362306a36Sopenharmony_ci u32 rx_1024_1518_byte_frames; 100462306a36Sopenharmony_ci u32 rx_greater_than_1518_byte_frames; 100562306a36Sopenharmony_ci u32 rx_undersized_frames; 100662306a36Sopenharmony_ci u32 rx_oversize_frames; 100762306a36Sopenharmony_ci u32 rx_jabbers; 100862306a36Sopenharmony_ci u32 rx_frame_check_sequence_errors; 100962306a36Sopenharmony_ci u32 rx_length_field_frame_errors; 101062306a36Sopenharmony_ci u32 rx_symbol_errors; 101162306a36Sopenharmony_ci u32 rx_alignment_errors; 101262306a36Sopenharmony_ci u32 rx_resource_errors; 101362306a36Sopenharmony_ci u32 rx_overruns; 101462306a36Sopenharmony_ci u32 rx_ip_header_checksum_errors; 101562306a36Sopenharmony_ci u32 rx_tcp_checksum_errors; 101662306a36Sopenharmony_ci u32 rx_udp_checksum_errors; 101762306a36Sopenharmony_ci}; 101862306a36Sopenharmony_ci 101962306a36Sopenharmony_ci/* Describes the name and offset of an individual statistic register, as 102062306a36Sopenharmony_ci * returned by `ethtool -S`. Also describes which net_device_stats statistics 102162306a36Sopenharmony_ci * this register should contribute to. 102262306a36Sopenharmony_ci */ 102362306a36Sopenharmony_cistruct gem_statistic { 102462306a36Sopenharmony_ci char stat_string[ETH_GSTRING_LEN]; 102562306a36Sopenharmony_ci int offset; 102662306a36Sopenharmony_ci u32 stat_bits; 102762306a36Sopenharmony_ci}; 102862306a36Sopenharmony_ci 102962306a36Sopenharmony_ci/* Bitfield defs for net_device_stat statistics */ 103062306a36Sopenharmony_ci#define GEM_NDS_RXERR_OFFSET 0 103162306a36Sopenharmony_ci#define GEM_NDS_RXLENERR_OFFSET 1 103262306a36Sopenharmony_ci#define GEM_NDS_RXOVERERR_OFFSET 2 103362306a36Sopenharmony_ci#define GEM_NDS_RXCRCERR_OFFSET 3 103462306a36Sopenharmony_ci#define GEM_NDS_RXFRAMEERR_OFFSET 4 103562306a36Sopenharmony_ci#define GEM_NDS_RXFIFOERR_OFFSET 5 103662306a36Sopenharmony_ci#define GEM_NDS_TXERR_OFFSET 6 103762306a36Sopenharmony_ci#define GEM_NDS_TXABORTEDERR_OFFSET 7 103862306a36Sopenharmony_ci#define GEM_NDS_TXCARRIERERR_OFFSET 8 103962306a36Sopenharmony_ci#define GEM_NDS_TXFIFOERR_OFFSET 9 104062306a36Sopenharmony_ci#define GEM_NDS_COLLISIONS_OFFSET 10 104162306a36Sopenharmony_ci 104262306a36Sopenharmony_ci#define GEM_STAT_TITLE(name, title) GEM_STAT_TITLE_BITS(name, title, 0) 104362306a36Sopenharmony_ci#define GEM_STAT_TITLE_BITS(name, title, bits) { \ 104462306a36Sopenharmony_ci .stat_string = title, \ 104562306a36Sopenharmony_ci .offset = GEM_##name, \ 104662306a36Sopenharmony_ci .stat_bits = bits \ 104762306a36Sopenharmony_ci} 104862306a36Sopenharmony_ci 104962306a36Sopenharmony_ci/* list of gem statistic registers. The names MUST match the 105062306a36Sopenharmony_ci * corresponding GEM_* definitions. 105162306a36Sopenharmony_ci */ 105262306a36Sopenharmony_cistatic const struct gem_statistic gem_statistics[] = { 105362306a36Sopenharmony_ci GEM_STAT_TITLE(OCTTXL, "tx_octets"), /* OCTTXH combined with OCTTXL */ 105462306a36Sopenharmony_ci GEM_STAT_TITLE(TXCNT, "tx_frames"), 105562306a36Sopenharmony_ci GEM_STAT_TITLE(TXBCCNT, "tx_broadcast_frames"), 105662306a36Sopenharmony_ci GEM_STAT_TITLE(TXMCCNT, "tx_multicast_frames"), 105762306a36Sopenharmony_ci GEM_STAT_TITLE(TXPAUSECNT, "tx_pause_frames"), 105862306a36Sopenharmony_ci GEM_STAT_TITLE(TX64CNT, "tx_64_byte_frames"), 105962306a36Sopenharmony_ci GEM_STAT_TITLE(TX65CNT, "tx_65_127_byte_frames"), 106062306a36Sopenharmony_ci GEM_STAT_TITLE(TX128CNT, "tx_128_255_byte_frames"), 106162306a36Sopenharmony_ci GEM_STAT_TITLE(TX256CNT, "tx_256_511_byte_frames"), 106262306a36Sopenharmony_ci GEM_STAT_TITLE(TX512CNT, "tx_512_1023_byte_frames"), 106362306a36Sopenharmony_ci GEM_STAT_TITLE(TX1024CNT, "tx_1024_1518_byte_frames"), 106462306a36Sopenharmony_ci GEM_STAT_TITLE(TX1519CNT, "tx_greater_than_1518_byte_frames"), 106562306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(TXURUNCNT, "tx_underrun", 106662306a36Sopenharmony_ci GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_TXFIFOERR)), 106762306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(SNGLCOLLCNT, "tx_single_collision_frames", 106862306a36Sopenharmony_ci GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)), 106962306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(MULTICOLLCNT, "tx_multiple_collision_frames", 107062306a36Sopenharmony_ci GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)), 107162306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(EXCESSCOLLCNT, "tx_excessive_collisions", 107262306a36Sopenharmony_ci GEM_BIT(NDS_TXERR)| 107362306a36Sopenharmony_ci GEM_BIT(NDS_TXABORTEDERR)| 107462306a36Sopenharmony_ci GEM_BIT(NDS_COLLISIONS)), 107562306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(LATECOLLCNT, "tx_late_collisions", 107662306a36Sopenharmony_ci GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)), 107762306a36Sopenharmony_ci GEM_STAT_TITLE(TXDEFERCNT, "tx_deferred_frames"), 107862306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(TXCSENSECNT, "tx_carrier_sense_errors", 107962306a36Sopenharmony_ci GEM_BIT(NDS_TXERR)|GEM_BIT(NDS_COLLISIONS)), 108062306a36Sopenharmony_ci GEM_STAT_TITLE(OCTRXL, "rx_octets"), /* OCTRXH combined with OCTRXL */ 108162306a36Sopenharmony_ci GEM_STAT_TITLE(RXCNT, "rx_frames"), 108262306a36Sopenharmony_ci GEM_STAT_TITLE(RXBROADCNT, "rx_broadcast_frames"), 108362306a36Sopenharmony_ci GEM_STAT_TITLE(RXMULTICNT, "rx_multicast_frames"), 108462306a36Sopenharmony_ci GEM_STAT_TITLE(RXPAUSECNT, "rx_pause_frames"), 108562306a36Sopenharmony_ci GEM_STAT_TITLE(RX64CNT, "rx_64_byte_frames"), 108662306a36Sopenharmony_ci GEM_STAT_TITLE(RX65CNT, "rx_65_127_byte_frames"), 108762306a36Sopenharmony_ci GEM_STAT_TITLE(RX128CNT, "rx_128_255_byte_frames"), 108862306a36Sopenharmony_ci GEM_STAT_TITLE(RX256CNT, "rx_256_511_byte_frames"), 108962306a36Sopenharmony_ci GEM_STAT_TITLE(RX512CNT, "rx_512_1023_byte_frames"), 109062306a36Sopenharmony_ci GEM_STAT_TITLE(RX1024CNT, "rx_1024_1518_byte_frames"), 109162306a36Sopenharmony_ci GEM_STAT_TITLE(RX1519CNT, "rx_greater_than_1518_byte_frames"), 109262306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXUNDRCNT, "rx_undersized_frames", 109362306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)), 109462306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXOVRCNT, "rx_oversize_frames", 109562306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)), 109662306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXJABCNT, "rx_jabbers", 109762306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXLENERR)), 109862306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXFCSCNT, "rx_frame_check_sequence_errors", 109962306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXCRCERR)), 110062306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXLENGTHCNT, "rx_length_field_frame_errors", 110162306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)), 110262306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXSYMBCNT, "rx_symbol_errors", 110362306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXFRAMEERR)), 110462306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXALIGNCNT, "rx_alignment_errors", 110562306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXOVERERR)), 110662306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXRESERRCNT, "rx_resource_errors", 110762306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXOVERERR)), 110862306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXORCNT, "rx_overruns", 110962306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)|GEM_BIT(NDS_RXFIFOERR)), 111062306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXIPCCNT, "rx_ip_header_checksum_errors", 111162306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)), 111262306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXTCPCCNT, "rx_tcp_checksum_errors", 111362306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)), 111462306a36Sopenharmony_ci GEM_STAT_TITLE_BITS(RXUDPCCNT, "rx_udp_checksum_errors", 111562306a36Sopenharmony_ci GEM_BIT(NDS_RXERR)), 111662306a36Sopenharmony_ci}; 111762306a36Sopenharmony_ci 111862306a36Sopenharmony_ci#define GEM_STATS_LEN ARRAY_SIZE(gem_statistics) 111962306a36Sopenharmony_ci 112062306a36Sopenharmony_ci#define QUEUE_STAT_TITLE(title) { \ 112162306a36Sopenharmony_ci .stat_string = title, \ 112262306a36Sopenharmony_ci} 112362306a36Sopenharmony_ci 112462306a36Sopenharmony_ci/* per queue statistics, each should be unsigned long type */ 112562306a36Sopenharmony_cistruct queue_stats { 112662306a36Sopenharmony_ci union { 112762306a36Sopenharmony_ci unsigned long first; 112862306a36Sopenharmony_ci unsigned long rx_packets; 112962306a36Sopenharmony_ci }; 113062306a36Sopenharmony_ci unsigned long rx_bytes; 113162306a36Sopenharmony_ci unsigned long rx_dropped; 113262306a36Sopenharmony_ci unsigned long tx_packets; 113362306a36Sopenharmony_ci unsigned long tx_bytes; 113462306a36Sopenharmony_ci unsigned long tx_dropped; 113562306a36Sopenharmony_ci}; 113662306a36Sopenharmony_ci 113762306a36Sopenharmony_cistatic const struct gem_statistic queue_statistics[] = { 113862306a36Sopenharmony_ci QUEUE_STAT_TITLE("rx_packets"), 113962306a36Sopenharmony_ci QUEUE_STAT_TITLE("rx_bytes"), 114062306a36Sopenharmony_ci QUEUE_STAT_TITLE("rx_dropped"), 114162306a36Sopenharmony_ci QUEUE_STAT_TITLE("tx_packets"), 114262306a36Sopenharmony_ci QUEUE_STAT_TITLE("tx_bytes"), 114362306a36Sopenharmony_ci QUEUE_STAT_TITLE("tx_dropped"), 114462306a36Sopenharmony_ci}; 114562306a36Sopenharmony_ci 114662306a36Sopenharmony_ci#define QUEUE_STATS_LEN ARRAY_SIZE(queue_statistics) 114762306a36Sopenharmony_ci 114862306a36Sopenharmony_cistruct macb; 114962306a36Sopenharmony_cistruct macb_queue; 115062306a36Sopenharmony_ci 115162306a36Sopenharmony_cistruct macb_or_gem_ops { 115262306a36Sopenharmony_ci int (*mog_alloc_rx_buffers)(struct macb *bp); 115362306a36Sopenharmony_ci void (*mog_free_rx_buffers)(struct macb *bp); 115462306a36Sopenharmony_ci void (*mog_init_rings)(struct macb *bp); 115562306a36Sopenharmony_ci int (*mog_rx)(struct macb_queue *queue, struct napi_struct *napi, 115662306a36Sopenharmony_ci int budget); 115762306a36Sopenharmony_ci}; 115862306a36Sopenharmony_ci 115962306a36Sopenharmony_ci/* MACB-PTP interface: adapt to platform needs. */ 116062306a36Sopenharmony_cistruct macb_ptp_info { 116162306a36Sopenharmony_ci void (*ptp_init)(struct net_device *ndev); 116262306a36Sopenharmony_ci void (*ptp_remove)(struct net_device *ndev); 116362306a36Sopenharmony_ci s32 (*get_ptp_max_adj)(void); 116462306a36Sopenharmony_ci unsigned int (*get_tsu_rate)(struct macb *bp); 116562306a36Sopenharmony_ci int (*get_ts_info)(struct net_device *dev, 116662306a36Sopenharmony_ci struct ethtool_ts_info *info); 116762306a36Sopenharmony_ci int (*get_hwtst)(struct net_device *netdev, 116862306a36Sopenharmony_ci struct ifreq *ifr); 116962306a36Sopenharmony_ci int (*set_hwtst)(struct net_device *netdev, 117062306a36Sopenharmony_ci struct ifreq *ifr, int cmd); 117162306a36Sopenharmony_ci}; 117262306a36Sopenharmony_ci 117362306a36Sopenharmony_cistruct macb_pm_data { 117462306a36Sopenharmony_ci u32 scrt2; 117562306a36Sopenharmony_ci u32 usrio; 117662306a36Sopenharmony_ci}; 117762306a36Sopenharmony_ci 117862306a36Sopenharmony_cistruct macb_usrio_config { 117962306a36Sopenharmony_ci u32 mii; 118062306a36Sopenharmony_ci u32 rmii; 118162306a36Sopenharmony_ci u32 rgmii; 118262306a36Sopenharmony_ci u32 refclk; 118362306a36Sopenharmony_ci u32 hdfctlen; 118462306a36Sopenharmony_ci}; 118562306a36Sopenharmony_ci 118662306a36Sopenharmony_cistruct macb_config { 118762306a36Sopenharmony_ci u32 caps; 118862306a36Sopenharmony_ci unsigned int dma_burst_length; 118962306a36Sopenharmony_ci int (*clk_init)(struct platform_device *pdev, struct clk **pclk, 119062306a36Sopenharmony_ci struct clk **hclk, struct clk **tx_clk, 119162306a36Sopenharmony_ci struct clk **rx_clk, struct clk **tsu_clk); 119262306a36Sopenharmony_ci int (*init)(struct platform_device *pdev); 119362306a36Sopenharmony_ci unsigned int max_tx_length; 119462306a36Sopenharmony_ci int jumbo_max_len; 119562306a36Sopenharmony_ci const struct macb_usrio_config *usrio; 119662306a36Sopenharmony_ci}; 119762306a36Sopenharmony_ci 119862306a36Sopenharmony_cistruct tsu_incr { 119962306a36Sopenharmony_ci u32 sub_ns; 120062306a36Sopenharmony_ci u32 ns; 120162306a36Sopenharmony_ci}; 120262306a36Sopenharmony_ci 120362306a36Sopenharmony_cistruct macb_queue { 120462306a36Sopenharmony_ci struct macb *bp; 120562306a36Sopenharmony_ci int irq; 120662306a36Sopenharmony_ci 120762306a36Sopenharmony_ci unsigned int ISR; 120862306a36Sopenharmony_ci unsigned int IER; 120962306a36Sopenharmony_ci unsigned int IDR; 121062306a36Sopenharmony_ci unsigned int IMR; 121162306a36Sopenharmony_ci unsigned int TBQP; 121262306a36Sopenharmony_ci unsigned int TBQPH; 121362306a36Sopenharmony_ci unsigned int RBQS; 121462306a36Sopenharmony_ci unsigned int RBQP; 121562306a36Sopenharmony_ci unsigned int RBQPH; 121662306a36Sopenharmony_ci 121762306a36Sopenharmony_ci /* Lock to protect tx_head and tx_tail */ 121862306a36Sopenharmony_ci spinlock_t tx_ptr_lock; 121962306a36Sopenharmony_ci unsigned int tx_head, tx_tail; 122062306a36Sopenharmony_ci struct macb_dma_desc *tx_ring; 122162306a36Sopenharmony_ci struct macb_tx_skb *tx_skb; 122262306a36Sopenharmony_ci dma_addr_t tx_ring_dma; 122362306a36Sopenharmony_ci struct work_struct tx_error_task; 122462306a36Sopenharmony_ci bool txubr_pending; 122562306a36Sopenharmony_ci struct napi_struct napi_tx; 122662306a36Sopenharmony_ci 122762306a36Sopenharmony_ci dma_addr_t rx_ring_dma; 122862306a36Sopenharmony_ci dma_addr_t rx_buffers_dma; 122962306a36Sopenharmony_ci unsigned int rx_tail; 123062306a36Sopenharmony_ci unsigned int rx_prepared_head; 123162306a36Sopenharmony_ci struct macb_dma_desc *rx_ring; 123262306a36Sopenharmony_ci struct sk_buff **rx_skbuff; 123362306a36Sopenharmony_ci void *rx_buffers; 123462306a36Sopenharmony_ci struct napi_struct napi_rx; 123562306a36Sopenharmony_ci struct queue_stats stats; 123662306a36Sopenharmony_ci}; 123762306a36Sopenharmony_ci 123862306a36Sopenharmony_cistruct ethtool_rx_fs_item { 123962306a36Sopenharmony_ci struct ethtool_rx_flow_spec fs; 124062306a36Sopenharmony_ci struct list_head list; 124162306a36Sopenharmony_ci}; 124262306a36Sopenharmony_ci 124362306a36Sopenharmony_cistruct ethtool_rx_fs_list { 124462306a36Sopenharmony_ci struct list_head list; 124562306a36Sopenharmony_ci unsigned int count; 124662306a36Sopenharmony_ci}; 124762306a36Sopenharmony_ci 124862306a36Sopenharmony_cistruct macb { 124962306a36Sopenharmony_ci void __iomem *regs; 125062306a36Sopenharmony_ci bool native_io; 125162306a36Sopenharmony_ci 125262306a36Sopenharmony_ci /* hardware IO accessors */ 125362306a36Sopenharmony_ci u32 (*macb_reg_readl)(struct macb *bp, int offset); 125462306a36Sopenharmony_ci void (*macb_reg_writel)(struct macb *bp, int offset, u32 value); 125562306a36Sopenharmony_ci 125662306a36Sopenharmony_ci size_t rx_buffer_size; 125762306a36Sopenharmony_ci 125862306a36Sopenharmony_ci unsigned int rx_ring_size; 125962306a36Sopenharmony_ci unsigned int tx_ring_size; 126062306a36Sopenharmony_ci 126162306a36Sopenharmony_ci unsigned int num_queues; 126262306a36Sopenharmony_ci unsigned int queue_mask; 126362306a36Sopenharmony_ci struct macb_queue queues[MACB_MAX_QUEUES]; 126462306a36Sopenharmony_ci 126562306a36Sopenharmony_ci spinlock_t lock; 126662306a36Sopenharmony_ci struct platform_device *pdev; 126762306a36Sopenharmony_ci struct clk *pclk; 126862306a36Sopenharmony_ci struct clk *hclk; 126962306a36Sopenharmony_ci struct clk *tx_clk; 127062306a36Sopenharmony_ci struct clk *rx_clk; 127162306a36Sopenharmony_ci struct clk *tsu_clk; 127262306a36Sopenharmony_ci struct net_device *dev; 127362306a36Sopenharmony_ci union { 127462306a36Sopenharmony_ci struct macb_stats macb; 127562306a36Sopenharmony_ci struct gem_stats gem; 127662306a36Sopenharmony_ci } hw_stats; 127762306a36Sopenharmony_ci 127862306a36Sopenharmony_ci struct macb_or_gem_ops macbgem_ops; 127962306a36Sopenharmony_ci 128062306a36Sopenharmony_ci struct mii_bus *mii_bus; 128162306a36Sopenharmony_ci struct phylink *phylink; 128262306a36Sopenharmony_ci struct phylink_config phylink_config; 128362306a36Sopenharmony_ci struct phylink_pcs phylink_usx_pcs; 128462306a36Sopenharmony_ci struct phylink_pcs phylink_sgmii_pcs; 128562306a36Sopenharmony_ci 128662306a36Sopenharmony_ci u32 caps; 128762306a36Sopenharmony_ci unsigned int dma_burst_length; 128862306a36Sopenharmony_ci 128962306a36Sopenharmony_ci phy_interface_t phy_interface; 129062306a36Sopenharmony_ci 129162306a36Sopenharmony_ci /* AT91RM9200 transmit queue (1 on wire + 1 queued) */ 129262306a36Sopenharmony_ci struct macb_tx_skb rm9200_txq[2]; 129362306a36Sopenharmony_ci unsigned int max_tx_length; 129462306a36Sopenharmony_ci 129562306a36Sopenharmony_ci u64 ethtool_stats[GEM_STATS_LEN + QUEUE_STATS_LEN * MACB_MAX_QUEUES]; 129662306a36Sopenharmony_ci 129762306a36Sopenharmony_ci unsigned int rx_frm_len_mask; 129862306a36Sopenharmony_ci unsigned int jumbo_max_len; 129962306a36Sopenharmony_ci 130062306a36Sopenharmony_ci u32 wol; 130162306a36Sopenharmony_ci 130262306a36Sopenharmony_ci /* holds value of rx watermark value for pbuf_rxcutthru register */ 130362306a36Sopenharmony_ci u32 rx_watermark; 130462306a36Sopenharmony_ci 130562306a36Sopenharmony_ci struct macb_ptp_info *ptp_info; /* macb-ptp interface */ 130662306a36Sopenharmony_ci 130762306a36Sopenharmony_ci struct phy *sgmii_phy; /* for ZynqMP SGMII mode */ 130862306a36Sopenharmony_ci 130962306a36Sopenharmony_ci#ifdef MACB_EXT_DESC 131062306a36Sopenharmony_ci uint8_t hw_dma_cap; 131162306a36Sopenharmony_ci#endif 131262306a36Sopenharmony_ci spinlock_t tsu_clk_lock; /* gem tsu clock locking */ 131362306a36Sopenharmony_ci unsigned int tsu_rate; 131462306a36Sopenharmony_ci struct ptp_clock *ptp_clock; 131562306a36Sopenharmony_ci struct ptp_clock_info ptp_clock_info; 131662306a36Sopenharmony_ci struct tsu_incr tsu_incr; 131762306a36Sopenharmony_ci struct hwtstamp_config tstamp_config; 131862306a36Sopenharmony_ci 131962306a36Sopenharmony_ci /* RX queue filer rule set*/ 132062306a36Sopenharmony_ci struct ethtool_rx_fs_list rx_fs_list; 132162306a36Sopenharmony_ci spinlock_t rx_fs_lock; 132262306a36Sopenharmony_ci unsigned int max_tuples; 132362306a36Sopenharmony_ci 132462306a36Sopenharmony_ci struct tasklet_struct hresp_err_tasklet; 132562306a36Sopenharmony_ci 132662306a36Sopenharmony_ci int rx_bd_rd_prefetch; 132762306a36Sopenharmony_ci int tx_bd_rd_prefetch; 132862306a36Sopenharmony_ci 132962306a36Sopenharmony_ci u32 rx_intr_mask; 133062306a36Sopenharmony_ci 133162306a36Sopenharmony_ci struct macb_pm_data pm_data; 133262306a36Sopenharmony_ci const struct macb_usrio_config *usrio; 133362306a36Sopenharmony_ci}; 133462306a36Sopenharmony_ci 133562306a36Sopenharmony_ci#ifdef CONFIG_MACB_USE_HWSTAMP 133662306a36Sopenharmony_ci#define GEM_TSEC_SIZE (GEM_TSH_SIZE + GEM_TSL_SIZE) 133762306a36Sopenharmony_ci#define TSU_SEC_MAX_VAL (((u64)1 << GEM_TSEC_SIZE) - 1) 133862306a36Sopenharmony_ci#define TSU_NSEC_MAX_VAL ((1 << GEM_TN_SIZE) - 1) 133962306a36Sopenharmony_ci 134062306a36Sopenharmony_cienum macb_bd_control { 134162306a36Sopenharmony_ci TSTAMP_DISABLED, 134262306a36Sopenharmony_ci TSTAMP_FRAME_PTP_EVENT_ONLY, 134362306a36Sopenharmony_ci TSTAMP_ALL_PTP_FRAMES, 134462306a36Sopenharmony_ci TSTAMP_ALL_FRAMES, 134562306a36Sopenharmony_ci}; 134662306a36Sopenharmony_ci 134762306a36Sopenharmony_civoid gem_ptp_init(struct net_device *ndev); 134862306a36Sopenharmony_civoid gem_ptp_remove(struct net_device *ndev); 134962306a36Sopenharmony_civoid gem_ptp_txstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc); 135062306a36Sopenharmony_civoid gem_ptp_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc); 135162306a36Sopenharmony_cistatic inline void gem_ptp_do_txstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc) 135262306a36Sopenharmony_ci{ 135362306a36Sopenharmony_ci if (bp->tstamp_config.tx_type == TSTAMP_DISABLED) 135462306a36Sopenharmony_ci return; 135562306a36Sopenharmony_ci 135662306a36Sopenharmony_ci gem_ptp_txstamp(bp, skb, desc); 135762306a36Sopenharmony_ci} 135862306a36Sopenharmony_ci 135962306a36Sopenharmony_cistatic inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc) 136062306a36Sopenharmony_ci{ 136162306a36Sopenharmony_ci if (bp->tstamp_config.rx_filter == TSTAMP_DISABLED) 136262306a36Sopenharmony_ci return; 136362306a36Sopenharmony_ci 136462306a36Sopenharmony_ci gem_ptp_rxstamp(bp, skb, desc); 136562306a36Sopenharmony_ci} 136662306a36Sopenharmony_ciint gem_get_hwtst(struct net_device *dev, struct ifreq *rq); 136762306a36Sopenharmony_ciint gem_set_hwtst(struct net_device *dev, struct ifreq *ifr, int cmd); 136862306a36Sopenharmony_ci#else 136962306a36Sopenharmony_cistatic inline void gem_ptp_init(struct net_device *ndev) { } 137062306a36Sopenharmony_cistatic inline void gem_ptp_remove(struct net_device *ndev) { } 137162306a36Sopenharmony_ci 137262306a36Sopenharmony_cistatic inline void gem_ptp_do_txstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc) { } 137362306a36Sopenharmony_cistatic inline void gem_ptp_do_rxstamp(struct macb *bp, struct sk_buff *skb, struct macb_dma_desc *desc) { } 137462306a36Sopenharmony_ci#endif 137562306a36Sopenharmony_ci 137662306a36Sopenharmony_cistatic inline bool macb_is_gem(struct macb *bp) 137762306a36Sopenharmony_ci{ 137862306a36Sopenharmony_ci return !!(bp->caps & MACB_CAPS_MACB_IS_GEM); 137962306a36Sopenharmony_ci} 138062306a36Sopenharmony_ci 138162306a36Sopenharmony_cistatic inline bool gem_has_ptp(struct macb *bp) 138262306a36Sopenharmony_ci{ 138362306a36Sopenharmony_ci return IS_ENABLED(CONFIG_MACB_USE_HWSTAMP) && (bp->caps & MACB_CAPS_GEM_HAS_PTP); 138462306a36Sopenharmony_ci} 138562306a36Sopenharmony_ci 138662306a36Sopenharmony_ci/** 138762306a36Sopenharmony_ci * struct macb_platform_data - platform data for MACB Ethernet used for PCI registration 138862306a36Sopenharmony_ci * @pclk: platform clock 138962306a36Sopenharmony_ci * @hclk: AHB clock 139062306a36Sopenharmony_ci */ 139162306a36Sopenharmony_cistruct macb_platform_data { 139262306a36Sopenharmony_ci struct clk *pclk; 139362306a36Sopenharmony_ci struct clk *hclk; 139462306a36Sopenharmony_ci}; 139562306a36Sopenharmony_ci 139662306a36Sopenharmony_ci#endif /* _MACB_H */ 1397