162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2010 ASIX Electronics Corporation
462306a36Sopenharmony_ci * Copyright (c) 2020 Samsung Electronics
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * ASIX AX88796C SPI Fast Ethernet Linux driver
762306a36Sopenharmony_ci */
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#ifndef _AX88796C_MAIN_H
1062306a36Sopenharmony_ci#define _AX88796C_MAIN_H
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ci#include <linux/netdevice.h>
1362306a36Sopenharmony_ci#include <linux/mii.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#include "ax88796c_spi.h"
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci/* These identify the driver base version and may not be removed. */
1862306a36Sopenharmony_ci#define DRV_NAME	"ax88796c"
1962306a36Sopenharmony_ci#define ADP_NAME	"ASIX AX88796C SPI Ethernet Adapter"
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define TX_QUEUE_HIGH_WATER		45	/* Tx queue high water mark */
2262306a36Sopenharmony_ci#define TX_QUEUE_LOW_WATER		20	/* Tx queue low water mark */
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define AX88796C_REGDUMP_LEN		256
2562306a36Sopenharmony_ci#define AX88796C_PHY_REGDUMP_LEN	14
2662306a36Sopenharmony_ci#define AX88796C_PHY_ID			0x10
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define TX_OVERHEAD			8
2962306a36Sopenharmony_ci#define TX_EOP_SIZE			4
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_ci#define AX_MCAST_FILTER_SIZE		8
3262306a36Sopenharmony_ci#define AX_MAX_MCAST			64
3362306a36Sopenharmony_ci#define AX_MAX_CLK                      80000000
3462306a36Sopenharmony_ci#define TX_HDR_SOP_DICF			0x8000
3562306a36Sopenharmony_ci#define TX_HDR_SOP_CPHI			0x4000
3662306a36Sopenharmony_ci#define TX_HDR_SOP_INT			0x2000
3762306a36Sopenharmony_ci#define TX_HDR_SOP_MDEQ			0x1000
3862306a36Sopenharmony_ci#define TX_HDR_SOP_PKTLEN		0x07FF
3962306a36Sopenharmony_ci#define TX_HDR_SOP_SEQNUM		0xF800
4062306a36Sopenharmony_ci#define TX_HDR_SOP_PKTLENBAR		0x07FF
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define TX_HDR_SEG_FS			0x8000
4362306a36Sopenharmony_ci#define TX_HDR_SEG_LS			0x4000
4462306a36Sopenharmony_ci#define TX_HDR_SEG_SEGNUM		0x3800
4562306a36Sopenharmony_ci#define TX_HDR_SEG_SEGLEN		0x0700
4662306a36Sopenharmony_ci#define TX_HDR_SEG_EOFST		0xC000
4762306a36Sopenharmony_ci#define TX_HDR_SEG_SOFST		0x3800
4862306a36Sopenharmony_ci#define TX_HDR_SEG_SEGLENBAR		0x07FF
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci#define TX_HDR_EOP_SEQNUM		0xF800
5162306a36Sopenharmony_ci#define TX_HDR_EOP_PKTLEN		0x07FF
5262306a36Sopenharmony_ci#define TX_HDR_EOP_SEQNUMBAR		0xF800
5362306a36Sopenharmony_ci#define TX_HDR_EOP_PKTLENBAR		0x07FF
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* Rx header fields mask */
5662306a36Sopenharmony_ci#define RX_HDR1_MCBC			0x8000
5762306a36Sopenharmony_ci#define RX_HDR1_STUFF_PKT		0x4000
5862306a36Sopenharmony_ci#define RX_HDR1_MII_ERR			0x2000
5962306a36Sopenharmony_ci#define RX_HDR1_CRC_ERR			0x1000
6062306a36Sopenharmony_ci#define RX_HDR1_PKT_LEN			0x07FF
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define RX_HDR2_SEQ_NUM			0xF800
6362306a36Sopenharmony_ci#define RX_HDR2_PKT_LEN_BAR		0x7FFF
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci#define RX_HDR3_PE			0x8000
6662306a36Sopenharmony_ci#define RX_HDR3_L3_TYPE_IPV4V6		0x6000
6762306a36Sopenharmony_ci#define RX_HDR3_L3_TYPE_IP		0x4000
6862306a36Sopenharmony_ci#define RX_HDR3_L3_TYPE_IPV6		0x2000
6962306a36Sopenharmony_ci#define RX_HDR3_L4_TYPE_ICMPV6		0x1400
7062306a36Sopenharmony_ci#define RX_HDR3_L4_TYPE_TCP		0x1000
7162306a36Sopenharmony_ci#define RX_HDR3_L4_TYPE_IGMP		0x0c00
7262306a36Sopenharmony_ci#define RX_HDR3_L4_TYPE_ICMP		0x0800
7362306a36Sopenharmony_ci#define RX_HDR3_L4_TYPE_UDP		0x0400
7462306a36Sopenharmony_ci#define RX_HDR3_L3_ERR			0x0200
7562306a36Sopenharmony_ci#define RX_HDR3_L4_ERR			0x0100
7662306a36Sopenharmony_ci#define RX_HDR3_PRIORITY(x)		((x) << 4)
7762306a36Sopenharmony_ci#define RX_HDR3_STRIP			0x0008
7862306a36Sopenharmony_ci#define RX_HDR3_VLAN_ID			0x0007
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_cistruct ax88796c_pcpu_stats {
8162306a36Sopenharmony_ci	u64_stats_t rx_packets;
8262306a36Sopenharmony_ci	u64_stats_t rx_bytes;
8362306a36Sopenharmony_ci	u64_stats_t tx_packets;
8462306a36Sopenharmony_ci	u64_stats_t tx_bytes;
8562306a36Sopenharmony_ci	struct u64_stats_sync syncp;
8662306a36Sopenharmony_ci	u32 rx_dropped;
8762306a36Sopenharmony_ci	u32 tx_dropped;
8862306a36Sopenharmony_ci	u32 rx_frame_errors;
8962306a36Sopenharmony_ci	u32 rx_crc_errors;
9062306a36Sopenharmony_ci};
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_cistruct ax88796c_device {
9362306a36Sopenharmony_ci	struct spi_device	*spi;
9462306a36Sopenharmony_ci	struct net_device	*ndev;
9562306a36Sopenharmony_ci	struct ax88796c_pcpu_stats __percpu *stats;
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci	struct work_struct	ax_work;
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci	struct mutex		spi_lock; /* device access */
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci	struct sk_buff_head	tx_wait_q;
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	struct axspi_data	ax_spi;
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci	struct mii_bus		*mdiobus;
10662306a36Sopenharmony_ci	struct phy_device	*phydev;
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ci	int			msg_enable;
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	u16			seq_num;
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci	u8			multi_filter[AX_MCAST_FILTER_SIZE];
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci	int			link;
11562306a36Sopenharmony_ci	int			speed;
11662306a36Sopenharmony_ci	int			duplex;
11762306a36Sopenharmony_ci	int			pause;
11862306a36Sopenharmony_ci	int			asym_pause;
11962306a36Sopenharmony_ci	int			flowctrl;
12062306a36Sopenharmony_ci		#define AX_FC_NONE		0
12162306a36Sopenharmony_ci		#define AX_FC_RX		BIT(0)
12262306a36Sopenharmony_ci		#define AX_FC_TX		BIT(1)
12362306a36Sopenharmony_ci		#define AX_FC_ANEG		BIT(2)
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci	u32			priv_flags;
12662306a36Sopenharmony_ci		#define AX_CAP_COMP		BIT(0)
12762306a36Sopenharmony_ci		#define AX_PRIV_FLAGS_MASK	(AX_CAP_COMP)
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	unsigned long		flags;
13062306a36Sopenharmony_ci		#define EVENT_INTR		0
13162306a36Sopenharmony_ci		#define EVENT_TX		1
13262306a36Sopenharmony_ci		#define EVENT_SET_MULTI		2
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci};
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define to_ax88796c_device(ndev) ((struct ax88796c_device *)netdev_priv(ndev))
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_cienum skb_state {
13962306a36Sopenharmony_ci	illegal = 0,
14062306a36Sopenharmony_ci	tx_done,
14162306a36Sopenharmony_ci	rx_done,
14262306a36Sopenharmony_ci	rx_err,
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_cistruct skb_data {
14662306a36Sopenharmony_ci	enum skb_state state;
14762306a36Sopenharmony_ci	size_t len;
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci/* A88796C register definition */
15162306a36Sopenharmony_ci	/* Definition of PAGE0 */
15262306a36Sopenharmony_ci#define P0_PSR		(0x00)
15362306a36Sopenharmony_ci	#define PSR_DEV_READY		BIT(7)
15462306a36Sopenharmony_ci	#define PSR_RESET		(0 << 15)
15562306a36Sopenharmony_ci	#define PSR_RESET_CLR		BIT(15)
15662306a36Sopenharmony_ci#define P0_BOR		(0x02)
15762306a36Sopenharmony_ci#define P0_FER		(0x04)
15862306a36Sopenharmony_ci	#define FER_IPALM		BIT(0)
15962306a36Sopenharmony_ci	#define FER_DCRC		BIT(1)
16062306a36Sopenharmony_ci	#define FER_RH3M		BIT(2)
16162306a36Sopenharmony_ci	#define FER_HEADERSWAP		BIT(7)
16262306a36Sopenharmony_ci	#define FER_WSWAP		BIT(8)
16362306a36Sopenharmony_ci	#define FER_BSWAP		BIT(9)
16462306a36Sopenharmony_ci	#define FER_INTHI		BIT(10)
16562306a36Sopenharmony_ci	#define FER_INTLO		(0 << 10)
16662306a36Sopenharmony_ci	#define FER_IRQ_PULL		BIT(11)
16762306a36Sopenharmony_ci	#define FER_RXEN		BIT(14)
16862306a36Sopenharmony_ci	#define FER_TXEN		BIT(15)
16962306a36Sopenharmony_ci#define P0_ISR		(0x06)
17062306a36Sopenharmony_ci	#define ISR_RXPKT		BIT(0)
17162306a36Sopenharmony_ci	#define ISR_MDQ			BIT(4)
17262306a36Sopenharmony_ci	#define ISR_TXT			BIT(5)
17362306a36Sopenharmony_ci	#define ISR_TXPAGES		BIT(6)
17462306a36Sopenharmony_ci	#define ISR_TXERR		BIT(8)
17562306a36Sopenharmony_ci	#define ISR_LINK		BIT(9)
17662306a36Sopenharmony_ci#define P0_IMR		(0x08)
17762306a36Sopenharmony_ci	#define IMR_RXPKT		BIT(0)
17862306a36Sopenharmony_ci	#define IMR_MDQ			BIT(4)
17962306a36Sopenharmony_ci	#define IMR_TXT			BIT(5)
18062306a36Sopenharmony_ci	#define IMR_TXPAGES		BIT(6)
18162306a36Sopenharmony_ci	#define IMR_TXERR		BIT(8)
18262306a36Sopenharmony_ci	#define IMR_LINK		BIT(9)
18362306a36Sopenharmony_ci	#define IMR_MASKALL		(0xFFFF)
18462306a36Sopenharmony_ci	#define IMR_DEFAULT		(IMR_TXERR)
18562306a36Sopenharmony_ci#define P0_WFCR		(0x0A)
18662306a36Sopenharmony_ci	#define WFCR_PMEIND		BIT(0) /* PME indication */
18762306a36Sopenharmony_ci	#define WFCR_PMETYPE		BIT(1) /* PME I/O type */
18862306a36Sopenharmony_ci	#define WFCR_PMEPOL		BIT(2) /* PME polarity */
18962306a36Sopenharmony_ci	#define WFCR_PMERST		BIT(3) /* Reset PME */
19062306a36Sopenharmony_ci	#define WFCR_SLEEP		BIT(4) /* Enable sleep mode */
19162306a36Sopenharmony_ci	#define WFCR_WAKEUP		BIT(5) /* Enable wakeup mode */
19262306a36Sopenharmony_ci	#define WFCR_WAITEVENT		BIT(6) /* Reserved */
19362306a36Sopenharmony_ci	#define WFCR_CLRWAKE		BIT(7) /* Clear wakeup */
19462306a36Sopenharmony_ci	#define WFCR_LINKCH		BIT(8) /* Enable link change */
19562306a36Sopenharmony_ci	#define WFCR_MAGICP		BIT(9) /* Enable magic packet */
19662306a36Sopenharmony_ci	#define WFCR_WAKEF		BIT(10) /* Enable wakeup frame */
19762306a36Sopenharmony_ci	#define WFCR_PMEEN		BIT(11) /* Enable PME pin */
19862306a36Sopenharmony_ci	#define WFCR_LINKCHS		BIT(12) /* Link change status */
19962306a36Sopenharmony_ci	#define WFCR_MAGICPS		BIT(13) /* Magic packet status */
20062306a36Sopenharmony_ci	#define WFCR_WAKEFS		BIT(14) /* Wakeup frame status */
20162306a36Sopenharmony_ci	#define WFCR_PMES		BIT(15) /* PME pin status */
20262306a36Sopenharmony_ci#define P0_PSCR		(0x0C)
20362306a36Sopenharmony_ci	#define PSCR_PS_MASK		(0xFFF0)
20462306a36Sopenharmony_ci	#define PSCR_PS_D0		(0)
20562306a36Sopenharmony_ci	#define PSCR_PS_D1		BIT(0)
20662306a36Sopenharmony_ci	#define PSCR_PS_D2		BIT(1)
20762306a36Sopenharmony_ci	#define PSCR_FPS		BIT(3) /* Enable fiber mode PS */
20862306a36Sopenharmony_ci	#define PSCR_SWPS		BIT(4) /* Enable software */
20962306a36Sopenharmony_ci						 /* PS control */
21062306a36Sopenharmony_ci	#define PSCR_WOLPS		BIT(5) /* Enable WOL PS */
21162306a36Sopenharmony_ci	#define PSCR_SWWOL		BIT(6) /* Enable software select */
21262306a36Sopenharmony_ci						 /* WOL PS */
21362306a36Sopenharmony_ci	#define PSCR_PHYOSC		BIT(7) /* Internal PHY OSC control */
21462306a36Sopenharmony_ci	#define PSCR_FOFEF		BIT(8) /* Force PHY generate FEF */
21562306a36Sopenharmony_ci	#define PSCR_FOF		BIT(9) /* Force PHY in fiber mode */
21662306a36Sopenharmony_ci	#define PSCR_PHYPD		BIT(10) /* PHY power down. */
21762306a36Sopenharmony_ci						  /* Active high */
21862306a36Sopenharmony_ci	#define PSCR_PHYRST		BIT(11) /* PHY reset signal. */
21962306a36Sopenharmony_ci						  /* Active low */
22062306a36Sopenharmony_ci	#define PSCR_PHYCSIL		BIT(12) /* PHY cable energy detect */
22162306a36Sopenharmony_ci	#define PSCR_PHYCOFF		BIT(13) /* PHY cable off */
22262306a36Sopenharmony_ci	#define PSCR_PHYLINK		BIT(14) /* PHY link status */
22362306a36Sopenharmony_ci	#define PSCR_EEPOK		BIT(15) /* EEPROM load complete */
22462306a36Sopenharmony_ci#define P0_MACCR	(0x0E)
22562306a36Sopenharmony_ci	#define MACCR_RXEN		BIT(0) /* Enable RX */
22662306a36Sopenharmony_ci	#define MACCR_DUPLEX_FULL	BIT(1) /* 1: Full, 0: Half */
22762306a36Sopenharmony_ci	#define MACCR_SPEED_100		BIT(2) /* 1: 100Mbps, 0: 10Mbps */
22862306a36Sopenharmony_ci	#define MACCR_RXFC_ENABLE	BIT(3)
22962306a36Sopenharmony_ci	#define MACCR_RXFC_MASK		0xFFF7
23062306a36Sopenharmony_ci	#define MACCR_TXFC_ENABLE	BIT(4)
23162306a36Sopenharmony_ci	#define MACCR_TXFC_MASK		0xFFEF
23262306a36Sopenharmony_ci	#define MACCR_PSI		BIT(6) /* Software Cable-Off */
23362306a36Sopenharmony_ci					       /* Power Saving Interrupt */
23462306a36Sopenharmony_ci	#define MACCR_PF		BIT(7)
23562306a36Sopenharmony_ci	#define MACCR_PMM_BITS		8
23662306a36Sopenharmony_ci	#define MACCR_PMM_MASK		(0x1F00)
23762306a36Sopenharmony_ci	#define MACCR_PMM_RESET		BIT(8)
23862306a36Sopenharmony_ci	#define MACCR_PMM_WAIT		(2 << 8)
23962306a36Sopenharmony_ci	#define MACCR_PMM_READY		(3 << 8)
24062306a36Sopenharmony_ci	#define MACCR_PMM_D1		(4 << 8)
24162306a36Sopenharmony_ci	#define MACCR_PMM_D2		(5 << 8)
24262306a36Sopenharmony_ci	#define MACCR_PMM_WAKE		(7 << 8)
24362306a36Sopenharmony_ci	#define MACCR_PMM_D1_WAKE	(8 << 8)
24462306a36Sopenharmony_ci	#define MACCR_PMM_D2_WAKE	(9 << 8)
24562306a36Sopenharmony_ci	#define MACCR_PMM_SLEEP		(10 << 8)
24662306a36Sopenharmony_ci	#define MACCR_PMM_PHY_RESET	(11 << 8)
24762306a36Sopenharmony_ci	#define MACCR_PMM_SOFT_D1	(16 << 8)
24862306a36Sopenharmony_ci	#define MACCR_PMM_SOFT_D2	(17 << 8)
24962306a36Sopenharmony_ci#define P0_TFBFCR	(0x10)
25062306a36Sopenharmony_ci	#define TFBFCR_SCHE_FREE_PAGE	0xE07F
25162306a36Sopenharmony_ci	#define TFBFCR_FREE_PAGE_BITS	0x07
25262306a36Sopenharmony_ci	#define TFBFCR_FREE_PAGE_LATCH	BIT(6)
25362306a36Sopenharmony_ci	#define TFBFCR_SET_FREE_PAGE(x)	(((x) & 0x3F) << TFBFCR_FREE_PAGE_BITS)
25462306a36Sopenharmony_ci	#define TFBFCR_TX_PAGE_SET	BIT(13)
25562306a36Sopenharmony_ci	#define TFBFCR_MANU_ENTX	BIT(15)
25662306a36Sopenharmony_ci	#define TX_FREEBUF_MASK		0x003F
25762306a36Sopenharmony_ci	#define TX_DPTSTART		0x4000
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci#define P0_TSNR		(0x12)
26062306a36Sopenharmony_ci	#define TXNR_TXB_ERR		BIT(5)
26162306a36Sopenharmony_ci	#define TXNR_TXB_IDLE		BIT(6)
26262306a36Sopenharmony_ci	#define TSNR_PKT_CNT(x)		(((x) & 0x3F) << 8)
26362306a36Sopenharmony_ci	#define TXNR_TXB_REINIT		BIT(14)
26462306a36Sopenharmony_ci	#define TSNR_TXB_START		BIT(15)
26562306a36Sopenharmony_ci#define P0_RTDPR	(0x14)
26662306a36Sopenharmony_ci#define P0_RXBCR1	(0x16)
26762306a36Sopenharmony_ci	#define RXBCR1_RXB_DISCARD	BIT(14)
26862306a36Sopenharmony_ci	#define RXBCR1_RXB_START	BIT(15)
26962306a36Sopenharmony_ci#define P0_RXBCR2	(0x18)
27062306a36Sopenharmony_ci	#define RXBCR2_PKT_MASK		(0xFF)
27162306a36Sopenharmony_ci	#define RXBCR2_RXPC_MASK	(0x7F)
27262306a36Sopenharmony_ci	#define RXBCR2_RXB_READY	BIT(13)
27362306a36Sopenharmony_ci	#define RXBCR2_RXB_IDLE		BIT(14)
27462306a36Sopenharmony_ci	#define RXBCR2_RXB_REINIT	BIT(15)
27562306a36Sopenharmony_ci#define P0_RTWCR	(0x1A)
27662306a36Sopenharmony_ci	#define RTWCR_RXWC_MASK		(0x3FFF)
27762306a36Sopenharmony_ci	#define RTWCR_RX_LATCH		BIT(15)
27862306a36Sopenharmony_ci#define P0_RCPHR	(0x1C)
27962306a36Sopenharmony_ci
28062306a36Sopenharmony_ci	/* Definition of PAGE1 */
28162306a36Sopenharmony_ci#define P1_RPPER	(0x22)
28262306a36Sopenharmony_ci	#define RPPER_RXEN		BIT(0)
28362306a36Sopenharmony_ci#define P1_MRCR		(0x28)
28462306a36Sopenharmony_ci#define P1_MDR		(0x2A)
28562306a36Sopenharmony_ci#define P1_RMPR		(0x2C)
28662306a36Sopenharmony_ci#define P1_TMPR		(0x2E)
28762306a36Sopenharmony_ci#define P1_RXBSPCR	(0x30)
28862306a36Sopenharmony_ci	#define RXBSPCR_STUF_WORD_CNT(x)	(((x) & 0x7000) >> 12)
28962306a36Sopenharmony_ci	#define RXBSPCR_STUF_ENABLE		BIT(15)
29062306a36Sopenharmony_ci#define P1_MCR		(0x32)
29162306a36Sopenharmony_ci	#define MCR_SBP			BIT(8)
29262306a36Sopenharmony_ci	#define MCR_SM			BIT(9)
29362306a36Sopenharmony_ci	#define MCR_CRCENLAN		BIT(11)
29462306a36Sopenharmony_ci	#define MCR_STP			BIT(12)
29562306a36Sopenharmony_ci	/* Definition of PAGE2 */
29662306a36Sopenharmony_ci#define P2_CIR		(0x42)
29762306a36Sopenharmony_ci#define P2_PCR		(0x44)
29862306a36Sopenharmony_ci	#define PCR_POLL_EN		BIT(0)
29962306a36Sopenharmony_ci	#define PCR_POLL_FLOWCTRL	BIT(1)
30062306a36Sopenharmony_ci	#define PCR_POLL_BMCR		BIT(2)
30162306a36Sopenharmony_ci	#define PCR_PHYID(x)		((x) << 8)
30262306a36Sopenharmony_ci#define P2_PHYSR	(0x46)
30362306a36Sopenharmony_ci#define P2_MDIODR	(0x48)
30462306a36Sopenharmony_ci#define P2_MDIOCR	(0x4A)
30562306a36Sopenharmony_ci	#define MDIOCR_RADDR(x)		((x) & 0x1F)
30662306a36Sopenharmony_ci	#define MDIOCR_FADDR(x)		(((x) & 0x1F) << 8)
30762306a36Sopenharmony_ci	#define MDIOCR_VALID		BIT(13)
30862306a36Sopenharmony_ci	#define MDIOCR_READ		BIT(14)
30962306a36Sopenharmony_ci	#define MDIOCR_WRITE		BIT(15)
31062306a36Sopenharmony_ci#define P2_LCR0		(0x4C)
31162306a36Sopenharmony_ci	#define LCR_LED0_EN		BIT(0)
31262306a36Sopenharmony_ci	#define LCR_LED0_100MODE	BIT(1)
31362306a36Sopenharmony_ci	#define LCR_LED0_DUPLEX		BIT(2)
31462306a36Sopenharmony_ci	#define LCR_LED0_LINK		BIT(3)
31562306a36Sopenharmony_ci	#define LCR_LED0_ACT		BIT(4)
31662306a36Sopenharmony_ci	#define LCR_LED0_COL		BIT(5)
31762306a36Sopenharmony_ci	#define LCR_LED0_10MODE		BIT(6)
31862306a36Sopenharmony_ci	#define LCR_LED0_DUPCOL		BIT(7)
31962306a36Sopenharmony_ci	#define LCR_LED1_EN		BIT(8)
32062306a36Sopenharmony_ci	#define LCR_LED1_100MODE	BIT(9)
32162306a36Sopenharmony_ci	#define LCR_LED1_DUPLEX		BIT(10)
32262306a36Sopenharmony_ci	#define LCR_LED1_LINK		BIT(11)
32362306a36Sopenharmony_ci	#define LCR_LED1_ACT		BIT(12)
32462306a36Sopenharmony_ci	#define LCR_LED1_COL		BIT(13)
32562306a36Sopenharmony_ci	#define LCR_LED1_10MODE		BIT(14)
32662306a36Sopenharmony_ci	#define LCR_LED1_DUPCOL		BIT(15)
32762306a36Sopenharmony_ci#define P2_LCR1		(0x4E)
32862306a36Sopenharmony_ci	#define LCR_LED2_MASK		(0xFF00)
32962306a36Sopenharmony_ci	#define LCR_LED2_EN		BIT(0)
33062306a36Sopenharmony_ci	#define LCR_LED2_100MODE	BIT(1)
33162306a36Sopenharmony_ci	#define LCR_LED2_DUPLEX		BIT(2)
33262306a36Sopenharmony_ci	#define LCR_LED2_LINK		BIT(3)
33362306a36Sopenharmony_ci	#define LCR_LED2_ACT		BIT(4)
33462306a36Sopenharmony_ci	#define LCR_LED2_COL		BIT(5)
33562306a36Sopenharmony_ci	#define LCR_LED2_10MODE		BIT(6)
33662306a36Sopenharmony_ci	#define LCR_LED2_DUPCOL		BIT(7)
33762306a36Sopenharmony_ci#define P2_IPGCR	(0x50)
33862306a36Sopenharmony_ci#define P2_CRIR		(0x52)
33962306a36Sopenharmony_ci#define P2_FLHWCR	(0x54)
34062306a36Sopenharmony_ci#define P2_RXCR		(0x56)
34162306a36Sopenharmony_ci	#define RXCR_PRO		BIT(0)
34262306a36Sopenharmony_ci	#define RXCR_AMALL		BIT(1)
34362306a36Sopenharmony_ci	#define RXCR_SEP		BIT(2)
34462306a36Sopenharmony_ci	#define RXCR_AB			BIT(3)
34562306a36Sopenharmony_ci	#define RXCR_AM			BIT(4)
34662306a36Sopenharmony_ci	#define RXCR_AP			BIT(5)
34762306a36Sopenharmony_ci	#define RXCR_ARP		BIT(6)
34862306a36Sopenharmony_ci#define P2_JLCR		(0x58)
34962306a36Sopenharmony_ci#define P2_MPLR		(0x5C)
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci	/* Definition of PAGE3 */
35262306a36Sopenharmony_ci#define P3_MACASR0	(0x62)
35362306a36Sopenharmony_ci	#define P3_MACASR(x)		(P3_MACASR0 + 2 * (x))
35462306a36Sopenharmony_ci	#define MACASR_LOWBYTE_MASK	0x00FF
35562306a36Sopenharmony_ci	#define MACASR_HIGH_BITS	0x08
35662306a36Sopenharmony_ci#define P3_MACASR1	(0x64)
35762306a36Sopenharmony_ci#define P3_MACASR2	(0x66)
35862306a36Sopenharmony_ci#define P3_MFAR01	(0x68)
35962306a36Sopenharmony_ci#define P3_MFAR_BASE	(0x68)
36062306a36Sopenharmony_ci	#define P3_MFAR(x)		(P3_MFAR_BASE + 2 * (x))
36162306a36Sopenharmony_ci
36262306a36Sopenharmony_ci#define P3_MFAR23	(0x6A)
36362306a36Sopenharmony_ci#define P3_MFAR45	(0x6C)
36462306a36Sopenharmony_ci#define P3_MFAR67	(0x6E)
36562306a36Sopenharmony_ci#define P3_VID0FR	(0x70)
36662306a36Sopenharmony_ci#define P3_VID1FR	(0x72)
36762306a36Sopenharmony_ci#define P3_EECSR	(0x74)
36862306a36Sopenharmony_ci#define P3_EEDR		(0x76)
36962306a36Sopenharmony_ci#define P3_EECR		(0x78)
37062306a36Sopenharmony_ci	#define EECR_ADDR_MASK		(0x00FF)
37162306a36Sopenharmony_ci	#define EECR_READ_ACT		BIT(8)
37262306a36Sopenharmony_ci	#define EECR_WRITE_ACT		BIT(9)
37362306a36Sopenharmony_ci	#define EECR_WRITE_DISABLE	BIT(10)
37462306a36Sopenharmony_ci	#define EECR_WRITE_ENABLE	BIT(11)
37562306a36Sopenharmony_ci	#define EECR_EE_READY		BIT(13)
37662306a36Sopenharmony_ci	#define EECR_RELOAD		BIT(14)
37762306a36Sopenharmony_ci	#define EECR_RESET		BIT(15)
37862306a36Sopenharmony_ci#define P3_TPCR		(0x7A)
37962306a36Sopenharmony_ci	#define TPCR_PATT_MASK		(0xFF)
38062306a36Sopenharmony_ci	#define TPCR_RAND_PKT_EN	BIT(14)
38162306a36Sopenharmony_ci	#define TPCR_FIXED_PKT_EN	BIT(15)
38262306a36Sopenharmony_ci#define P3_TPLR		(0x7C)
38362306a36Sopenharmony_ci	/* Definition of PAGE4 */
38462306a36Sopenharmony_ci#define P4_SPICR	(0x8A)
38562306a36Sopenharmony_ci	#define SPICR_RCEN		BIT(0)
38662306a36Sopenharmony_ci	#define SPICR_QCEN		BIT(1)
38762306a36Sopenharmony_ci	#define SPICR_RBRE		BIT(3)
38862306a36Sopenharmony_ci	#define SPICR_PMM		BIT(4)
38962306a36Sopenharmony_ci	#define SPICR_LOOPBACK		BIT(8)
39062306a36Sopenharmony_ci	#define SPICR_CORE_RES_CLR	BIT(10)
39162306a36Sopenharmony_ci	#define SPICR_SPI_RES_CLR	BIT(11)
39262306a36Sopenharmony_ci#define P4_SPIISMR	(0x8C)
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci#define P4_COERCR0	(0x92)
39562306a36Sopenharmony_ci	#define COERCR0_RXIPCE		BIT(0)
39662306a36Sopenharmony_ci	#define COERCR0_RXIPVE		BIT(1)
39762306a36Sopenharmony_ci	#define COERCR0_RXV6PE		BIT(2)
39862306a36Sopenharmony_ci	#define COERCR0_RXTCPE		BIT(3)
39962306a36Sopenharmony_ci	#define COERCR0_RXUDPE		BIT(4)
40062306a36Sopenharmony_ci	#define COERCR0_RXICMP		BIT(5)
40162306a36Sopenharmony_ci	#define COERCR0_RXIGMP		BIT(6)
40262306a36Sopenharmony_ci	#define COERCR0_RXICV6		BIT(7)
40362306a36Sopenharmony_ci
40462306a36Sopenharmony_ci	#define COERCR0_RXTCPV6		BIT(8)
40562306a36Sopenharmony_ci	#define COERCR0_RXUDPV6		BIT(9)
40662306a36Sopenharmony_ci	#define COERCR0_RXICMV6		BIT(10)
40762306a36Sopenharmony_ci	#define COERCR0_RXIGMV6		BIT(11)
40862306a36Sopenharmony_ci	#define COERCR0_RXICV6V6	BIT(12)
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci	#define COERCR0_DEFAULT		(COERCR0_RXIPCE | COERCR0_RXV6PE | \
41162306a36Sopenharmony_ci					 COERCR0_RXTCPE | COERCR0_RXUDPE | \
41262306a36Sopenharmony_ci					 COERCR0_RXTCPV6 | COERCR0_RXUDPV6)
41362306a36Sopenharmony_ci#define P4_COERCR1	(0x94)
41462306a36Sopenharmony_ci	#define COERCR1_IPCEDP		BIT(0)
41562306a36Sopenharmony_ci	#define COERCR1_IPVEDP		BIT(1)
41662306a36Sopenharmony_ci	#define COERCR1_V6VEDP		BIT(2)
41762306a36Sopenharmony_ci	#define COERCR1_TCPEDP		BIT(3)
41862306a36Sopenharmony_ci	#define COERCR1_UDPEDP		BIT(4)
41962306a36Sopenharmony_ci	#define COERCR1_ICMPDP		BIT(5)
42062306a36Sopenharmony_ci	#define COERCR1_IGMPDP		BIT(6)
42162306a36Sopenharmony_ci	#define COERCR1_ICV6DP		BIT(7)
42262306a36Sopenharmony_ci	#define COERCR1_RX64TE		BIT(8)
42362306a36Sopenharmony_ci	#define COERCR1_RXPPPE		BIT(9)
42462306a36Sopenharmony_ci	#define COERCR1_TCP6DP		BIT(10)
42562306a36Sopenharmony_ci	#define COERCR1_UDP6DP		BIT(11)
42662306a36Sopenharmony_ci	#define COERCR1_IC6DP		BIT(12)
42762306a36Sopenharmony_ci	#define COERCR1_IG6DP		BIT(13)
42862306a36Sopenharmony_ci	#define COERCR1_ICV66DP		BIT(14)
42962306a36Sopenharmony_ci	#define COERCR1_RPCE		BIT(15)
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ci	#define COERCR1_DEFAULT		(COERCR1_RXPPPE)
43262306a36Sopenharmony_ci
43362306a36Sopenharmony_ci#define P4_COETCR0	(0x96)
43462306a36Sopenharmony_ci	#define COETCR0_TXIP		BIT(0)
43562306a36Sopenharmony_ci	#define COETCR0_TXTCP		BIT(1)
43662306a36Sopenharmony_ci	#define COETCR0_TXUDP		BIT(2)
43762306a36Sopenharmony_ci	#define COETCR0_TXICMP		BIT(3)
43862306a36Sopenharmony_ci	#define COETCR0_TXIGMP		BIT(4)
43962306a36Sopenharmony_ci	#define COETCR0_TXICV6		BIT(5)
44062306a36Sopenharmony_ci	#define COETCR0_TXTCPV6		BIT(8)
44162306a36Sopenharmony_ci	#define COETCR0_TXUDPV6		BIT(9)
44262306a36Sopenharmony_ci	#define COETCR0_TXICMV6		BIT(10)
44362306a36Sopenharmony_ci	#define COETCR0_TXIGMV6		BIT(11)
44462306a36Sopenharmony_ci	#define COETCR0_TXICV6V6	BIT(12)
44562306a36Sopenharmony_ci
44662306a36Sopenharmony_ci	#define COETCR0_DEFAULT		(COETCR0_TXIP | COETCR0_TXTCP | \
44762306a36Sopenharmony_ci					 COETCR0_TXUDP | COETCR0_TXTCPV6 | \
44862306a36Sopenharmony_ci					 COETCR0_TXUDPV6)
44962306a36Sopenharmony_ci#define P4_COETCR1	(0x98)
45062306a36Sopenharmony_ci	#define COETCR1_TX64TE		BIT(0)
45162306a36Sopenharmony_ci	#define COETCR1_TXPPPE		BIT(1)
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci#define P4_COECEDR	(0x9A)
45462306a36Sopenharmony_ci#define P4_L2CECR	(0x9C)
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci	/* Definition of PAGE5 */
45762306a36Sopenharmony_ci#define P5_WFTR		(0xA2)
45862306a36Sopenharmony_ci	#define WFTR_2MS		(0x01)
45962306a36Sopenharmony_ci	#define WFTR_4MS		(0x02)
46062306a36Sopenharmony_ci	#define WFTR_8MS		(0x03)
46162306a36Sopenharmony_ci	#define WFTR_16MS		(0x04)
46262306a36Sopenharmony_ci	#define WFTR_32MS		(0x05)
46362306a36Sopenharmony_ci	#define WFTR_64MS		(0x06)
46462306a36Sopenharmony_ci	#define WFTR_128MS		(0x07)
46562306a36Sopenharmony_ci	#define WFTR_256MS		(0x08)
46662306a36Sopenharmony_ci	#define WFTR_512MS		(0x09)
46762306a36Sopenharmony_ci	#define WFTR_1024MS		(0x0A)
46862306a36Sopenharmony_ci	#define WFTR_2048MS		(0x0B)
46962306a36Sopenharmony_ci	#define WFTR_4096MS		(0x0C)
47062306a36Sopenharmony_ci	#define WFTR_8192MS		(0x0D)
47162306a36Sopenharmony_ci	#define WFTR_16384MS		(0x0E)
47262306a36Sopenharmony_ci	#define WFTR_32768MS		(0x0F)
47362306a36Sopenharmony_ci#define P5_WFCCR	(0xA4)
47462306a36Sopenharmony_ci#define P5_WFCR03	(0xA6)
47562306a36Sopenharmony_ci	#define WFCR03_F0_EN		BIT(0)
47662306a36Sopenharmony_ci	#define WFCR03_F1_EN		BIT(4)
47762306a36Sopenharmony_ci	#define WFCR03_F2_EN		BIT(8)
47862306a36Sopenharmony_ci	#define WFCR03_F3_EN		BIT(12)
47962306a36Sopenharmony_ci#define P5_WFCR47	(0xA8)
48062306a36Sopenharmony_ci	#define WFCR47_F4_EN		BIT(0)
48162306a36Sopenharmony_ci	#define WFCR47_F5_EN		BIT(4)
48262306a36Sopenharmony_ci	#define WFCR47_F6_EN		BIT(8)
48362306a36Sopenharmony_ci	#define WFCR47_F7_EN		BIT(12)
48462306a36Sopenharmony_ci#define P5_WF0BMR0	(0xAA)
48562306a36Sopenharmony_ci#define P5_WF0BMR1	(0xAC)
48662306a36Sopenharmony_ci#define P5_WF0CR	(0xAE)
48762306a36Sopenharmony_ci#define P5_WF0OBR	(0xB0)
48862306a36Sopenharmony_ci#define P5_WF1BMR0	(0xB2)
48962306a36Sopenharmony_ci#define P5_WF1BMR1	(0xB4)
49062306a36Sopenharmony_ci#define P5_WF1CR	(0xB6)
49162306a36Sopenharmony_ci#define P5_WF1OBR	(0xB8)
49262306a36Sopenharmony_ci#define P5_WF2BMR0	(0xBA)
49362306a36Sopenharmony_ci#define P5_WF2BMR1	(0xBC)
49462306a36Sopenharmony_ci
49562306a36Sopenharmony_ci	/* Definition of PAGE6 */
49662306a36Sopenharmony_ci#define P6_WF2CR	(0xC2)
49762306a36Sopenharmony_ci#define P6_WF2OBR	(0xC4)
49862306a36Sopenharmony_ci#define P6_WF3BMR0	(0xC6)
49962306a36Sopenharmony_ci#define P6_WF3BMR1	(0xC8)
50062306a36Sopenharmony_ci#define P6_WF3CR	(0xCA)
50162306a36Sopenharmony_ci#define P6_WF3OBR	(0xCC)
50262306a36Sopenharmony_ci#define P6_WF4BMR0	(0xCE)
50362306a36Sopenharmony_ci#define P6_WF4BMR1	(0xD0)
50462306a36Sopenharmony_ci#define P6_WF4CR	(0xD2)
50562306a36Sopenharmony_ci#define P6_WF4OBR	(0xD4)
50662306a36Sopenharmony_ci#define P6_WF5BMR0	(0xD6)
50762306a36Sopenharmony_ci#define P6_WF5BMR1	(0xD8)
50862306a36Sopenharmony_ci#define P6_WF5CR	(0xDA)
50962306a36Sopenharmony_ci#define P6_WF5OBR	(0xDC)
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci/* Definition of PAGE7 */
51262306a36Sopenharmony_ci#define P7_WF6BMR0	(0xE2)
51362306a36Sopenharmony_ci#define P7_WF6BMR1	(0xE4)
51462306a36Sopenharmony_ci#define P7_WF6CR	(0xE6)
51562306a36Sopenharmony_ci#define P7_WF6OBR	(0xE8)
51662306a36Sopenharmony_ci#define P7_WF7BMR0	(0xEA)
51762306a36Sopenharmony_ci#define P7_WF7BMR1	(0xEC)
51862306a36Sopenharmony_ci#define P7_WF7CR	(0xEE)
51962306a36Sopenharmony_ci#define P7_WF7OBR	(0xF0)
52062306a36Sopenharmony_ci#define P7_WFR01	(0xF2)
52162306a36Sopenharmony_ci#define P7_WFR23	(0xF4)
52262306a36Sopenharmony_ci#define P7_WFR45	(0xF6)
52362306a36Sopenharmony_ci#define P7_WFR67	(0xF8)
52462306a36Sopenharmony_ci#define P7_WFPC0	(0xFA)
52562306a36Sopenharmony_ci#define P7_WFPC1	(0xFC)
52662306a36Sopenharmony_ci
52762306a36Sopenharmony_ci/* Tx headers structure */
52862306a36Sopenharmony_cistruct tx_sop_header {
52962306a36Sopenharmony_ci	/* bit 15-11: flags, bit 10-0: packet length */
53062306a36Sopenharmony_ci	u16 flags_len;
53162306a36Sopenharmony_ci	/* bit 15-11: sequence number, bit 11-0: packet length bar */
53262306a36Sopenharmony_ci	u16 seq_lenbar;
53362306a36Sopenharmony_ci};
53462306a36Sopenharmony_ci
53562306a36Sopenharmony_cistruct tx_segment_header {
53662306a36Sopenharmony_ci	/* bit 15-14: flags, bit 13-11: segment number */
53762306a36Sopenharmony_ci	/* bit 10-0: segment length */
53862306a36Sopenharmony_ci	u16 flags_seqnum_seglen;
53962306a36Sopenharmony_ci	/* bit 15-14: end offset, bit 13-11: start offset */
54062306a36Sopenharmony_ci	/* bit 10-0: segment length bar */
54162306a36Sopenharmony_ci	u16 eo_so_seglenbar;
54262306a36Sopenharmony_ci};
54362306a36Sopenharmony_ci
54462306a36Sopenharmony_cistruct tx_eop_header {
54562306a36Sopenharmony_ci	/* bit 15-11: sequence number, bit 10-0: packet length */
54662306a36Sopenharmony_ci	u16 seq_len;
54762306a36Sopenharmony_ci	/* bit 15-11: sequence number bar, bit 10-0: packet length bar */
54862306a36Sopenharmony_ci	u16 seqbar_lenbar;
54962306a36Sopenharmony_ci};
55062306a36Sopenharmony_ci
55162306a36Sopenharmony_cistruct tx_pkt_info {
55262306a36Sopenharmony_ci	struct tx_sop_header sop;
55362306a36Sopenharmony_ci	struct tx_segment_header seg;
55462306a36Sopenharmony_ci	struct tx_eop_header eop;
55562306a36Sopenharmony_ci	u16 pkt_len;
55662306a36Sopenharmony_ci	u16 seq_num;
55762306a36Sopenharmony_ci};
55862306a36Sopenharmony_ci
55962306a36Sopenharmony_ci/* Rx headers structure */
56062306a36Sopenharmony_cistruct rx_header {
56162306a36Sopenharmony_ci	u16 flags_len;
56262306a36Sopenharmony_ci	u16 seq_lenbar;
56362306a36Sopenharmony_ci	u16 flags;
56462306a36Sopenharmony_ci};
56562306a36Sopenharmony_ci
56662306a36Sopenharmony_ciextern unsigned long ax88796c_no_regs_mask[];
56762306a36Sopenharmony_ci
56862306a36Sopenharmony_ci#endif /* #ifndef _AX88796C_MAIN_H */
569