162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
362306a36Sopenharmony_ci */
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci#ifndef _EMAC_H_
662306a36Sopenharmony_ci#define _EMAC_H_
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include <linux/irqreturn.h>
962306a36Sopenharmony_ci#include <linux/netdevice.h>
1062306a36Sopenharmony_ci#include <linux/clk.h>
1162306a36Sopenharmony_ci#include <linux/platform_device.h>
1262306a36Sopenharmony_ci#include "emac-mac.h"
1362306a36Sopenharmony_ci#include "emac-phy.h"
1462306a36Sopenharmony_ci#include "emac-sgmii.h"
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci/* EMAC base register offsets */
1762306a36Sopenharmony_ci#define EMAC_DMA_MAS_CTRL		0x1400
1862306a36Sopenharmony_ci#define EMAC_IRQ_MOD_TIM_INIT		0x1408
1962306a36Sopenharmony_ci#define EMAC_BLK_IDLE_STS		0x140c
2062306a36Sopenharmony_ci#define EMAC_PHY_LINK_DELAY		0x141c
2162306a36Sopenharmony_ci#define EMAC_SYS_ALIV_CTRL		0x1434
2262306a36Sopenharmony_ci#define EMAC_MAC_CTRL			0x1480
2362306a36Sopenharmony_ci#define EMAC_MAC_IPGIFG_CTRL		0x1484
2462306a36Sopenharmony_ci#define EMAC_MAC_STA_ADDR0		0x1488
2562306a36Sopenharmony_ci#define EMAC_MAC_STA_ADDR1		0x148c
2662306a36Sopenharmony_ci#define EMAC_HASH_TAB_REG0		0x1490
2762306a36Sopenharmony_ci#define EMAC_HASH_TAB_REG1		0x1494
2862306a36Sopenharmony_ci#define EMAC_MAC_HALF_DPLX_CTRL		0x1498
2962306a36Sopenharmony_ci#define EMAC_MAX_FRAM_LEN_CTRL		0x149c
3062306a36Sopenharmony_ci#define EMAC_WOL_CTRL0			0x14a0
3162306a36Sopenharmony_ci#define EMAC_RSS_KEY0			0x14b0
3262306a36Sopenharmony_ci#define EMAC_H1TPD_BASE_ADDR_LO		0x14e0
3362306a36Sopenharmony_ci#define EMAC_H2TPD_BASE_ADDR_LO		0x14e4
3462306a36Sopenharmony_ci#define EMAC_H3TPD_BASE_ADDR_LO		0x14e8
3562306a36Sopenharmony_ci#define EMAC_INTER_SRAM_PART9		0x1534
3662306a36Sopenharmony_ci#define EMAC_DESC_CTRL_0		0x1540
3762306a36Sopenharmony_ci#define EMAC_DESC_CTRL_1		0x1544
3862306a36Sopenharmony_ci#define EMAC_DESC_CTRL_2		0x1550
3962306a36Sopenharmony_ci#define EMAC_DESC_CTRL_10		0x1554
4062306a36Sopenharmony_ci#define EMAC_DESC_CTRL_12		0x1558
4162306a36Sopenharmony_ci#define EMAC_DESC_CTRL_13		0x155c
4262306a36Sopenharmony_ci#define EMAC_DESC_CTRL_3		0x1560
4362306a36Sopenharmony_ci#define EMAC_DESC_CTRL_4		0x1564
4462306a36Sopenharmony_ci#define EMAC_DESC_CTRL_5		0x1568
4562306a36Sopenharmony_ci#define EMAC_DESC_CTRL_14		0x156c
4662306a36Sopenharmony_ci#define EMAC_DESC_CTRL_15		0x1570
4762306a36Sopenharmony_ci#define EMAC_DESC_CTRL_16		0x1574
4862306a36Sopenharmony_ci#define EMAC_DESC_CTRL_6		0x1578
4962306a36Sopenharmony_ci#define EMAC_DESC_CTRL_8		0x1580
5062306a36Sopenharmony_ci#define EMAC_DESC_CTRL_9		0x1584
5162306a36Sopenharmony_ci#define EMAC_DESC_CTRL_11		0x1588
5262306a36Sopenharmony_ci#define EMAC_TXQ_CTRL_0			0x1590
5362306a36Sopenharmony_ci#define EMAC_TXQ_CTRL_1			0x1594
5462306a36Sopenharmony_ci#define EMAC_TXQ_CTRL_2			0x1598
5562306a36Sopenharmony_ci#define EMAC_RXQ_CTRL_0			0x15a0
5662306a36Sopenharmony_ci#define EMAC_RXQ_CTRL_1			0x15a4
5762306a36Sopenharmony_ci#define EMAC_RXQ_CTRL_2			0x15a8
5862306a36Sopenharmony_ci#define EMAC_RXQ_CTRL_3			0x15ac
5962306a36Sopenharmony_ci#define EMAC_BASE_CPU_NUMBER		0x15b8
6062306a36Sopenharmony_ci#define EMAC_DMA_CTRL			0x15c0
6162306a36Sopenharmony_ci#define EMAC_MAILBOX_0			0x15e0
6262306a36Sopenharmony_ci#define EMAC_MAILBOX_5			0x15e4
6362306a36Sopenharmony_ci#define EMAC_MAILBOX_6			0x15e8
6462306a36Sopenharmony_ci#define EMAC_MAILBOX_13			0x15ec
6562306a36Sopenharmony_ci#define EMAC_MAILBOX_2			0x15f4
6662306a36Sopenharmony_ci#define EMAC_MAILBOX_3			0x15f8
6762306a36Sopenharmony_ci#define EMAC_INT_STATUS			0x1600
6862306a36Sopenharmony_ci#define EMAC_INT_MASK			0x1604
6962306a36Sopenharmony_ci#define EMAC_MAILBOX_11			0x160c
7062306a36Sopenharmony_ci#define EMAC_AXI_MAST_CTRL		0x1610
7162306a36Sopenharmony_ci#define EMAC_MAILBOX_12			0x1614
7262306a36Sopenharmony_ci#define EMAC_MAILBOX_9			0x1618
7362306a36Sopenharmony_ci#define EMAC_MAILBOX_10			0x161c
7462306a36Sopenharmony_ci#define EMAC_ATHR_HEADER_CTRL		0x1620
7562306a36Sopenharmony_ci#define EMAC_RXMAC_STATC_REG0		0x1700
7662306a36Sopenharmony_ci#define EMAC_RXMAC_STATC_REG22		0x1758
7762306a36Sopenharmony_ci#define EMAC_TXMAC_STATC_REG0		0x1760
7862306a36Sopenharmony_ci#define EMAC_TXMAC_STATC_REG24		0x17c0
7962306a36Sopenharmony_ci#define EMAC_CLK_GATE_CTRL		0x1814
8062306a36Sopenharmony_ci#define EMAC_CORE_HW_VERSION		0x1974
8162306a36Sopenharmony_ci#define EMAC_MISC_CTRL			0x1990
8262306a36Sopenharmony_ci#define EMAC_MAILBOX_7			0x19e0
8362306a36Sopenharmony_ci#define EMAC_MAILBOX_8			0x19e4
8462306a36Sopenharmony_ci#define EMAC_IDT_TABLE0			0x1b00
8562306a36Sopenharmony_ci#define EMAC_RXMAC_STATC_REG23		0x1bc8
8662306a36Sopenharmony_ci#define EMAC_RXMAC_STATC_REG24		0x1bcc
8762306a36Sopenharmony_ci#define EMAC_TXMAC_STATC_REG25		0x1bd0
8862306a36Sopenharmony_ci#define EMAC_MAILBOX_15			0x1bd4
8962306a36Sopenharmony_ci#define EMAC_MAILBOX_16			0x1bd8
9062306a36Sopenharmony_ci#define EMAC_INT1_MASK			0x1bf0
9162306a36Sopenharmony_ci#define EMAC_INT1_STATUS		0x1bf4
9262306a36Sopenharmony_ci#define EMAC_INT2_MASK			0x1bf8
9362306a36Sopenharmony_ci#define EMAC_INT2_STATUS		0x1bfc
9462306a36Sopenharmony_ci#define EMAC_INT3_MASK			0x1c00
9562306a36Sopenharmony_ci#define EMAC_INT3_STATUS		0x1c04
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci/* EMAC_DMA_MAS_CTRL */
9862306a36Sopenharmony_ci#define DEV_ID_NUM_BMSK                                     0x7f000000
9962306a36Sopenharmony_ci#define DEV_ID_NUM_SHFT                                             24
10062306a36Sopenharmony_ci#define DEV_REV_NUM_BMSK                                      0xff0000
10162306a36Sopenharmony_ci#define DEV_REV_NUM_SHFT                                            16
10262306a36Sopenharmony_ci#define INT_RD_CLR_EN                                           0x4000
10362306a36Sopenharmony_ci#define IRQ_MODERATOR2_EN                                        0x800
10462306a36Sopenharmony_ci#define IRQ_MODERATOR_EN                                         0x400
10562306a36Sopenharmony_ci#define LPW_CLK_SEL                                               0x80
10662306a36Sopenharmony_ci#define LPW_STATE                                                 0x20
10762306a36Sopenharmony_ci#define LPW_MODE                                                  0x10
10862306a36Sopenharmony_ci#define SOFT_RST                                                   0x1
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci/* EMAC_IRQ_MOD_TIM_INIT */
11162306a36Sopenharmony_ci#define IRQ_MODERATOR2_INIT_BMSK                            0xffff0000
11262306a36Sopenharmony_ci#define IRQ_MODERATOR2_INIT_SHFT                                    16
11362306a36Sopenharmony_ci#define IRQ_MODERATOR_INIT_BMSK                                 0xffff
11462306a36Sopenharmony_ci#define IRQ_MODERATOR_INIT_SHFT                                      0
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_ci/* EMAC_INT_STATUS */
11762306a36Sopenharmony_ci#define DIS_INT                                                BIT(31)
11862306a36Sopenharmony_ci#define PTP_INT                                                BIT(30)
11962306a36Sopenharmony_ci#define RFD4_UR_INT                                            BIT(29)
12062306a36Sopenharmony_ci#define TX_PKT_INT3                                            BIT(26)
12162306a36Sopenharmony_ci#define TX_PKT_INT2                                            BIT(25)
12262306a36Sopenharmony_ci#define TX_PKT_INT1                                            BIT(24)
12362306a36Sopenharmony_ci#define RX_PKT_INT3                                            BIT(19)
12462306a36Sopenharmony_ci#define RX_PKT_INT2                                            BIT(18)
12562306a36Sopenharmony_ci#define RX_PKT_INT1                                            BIT(17)
12662306a36Sopenharmony_ci#define RX_PKT_INT0                                            BIT(16)
12762306a36Sopenharmony_ci#define TX_PKT_INT                                             BIT(15)
12862306a36Sopenharmony_ci#define TXQ_TO_INT                                             BIT(14)
12962306a36Sopenharmony_ci#define GPHY_WAKEUP_INT                                        BIT(13)
13062306a36Sopenharmony_ci#define GPHY_LINK_DOWN_INT                                     BIT(12)
13162306a36Sopenharmony_ci#define GPHY_LINK_UP_INT                                       BIT(11)
13262306a36Sopenharmony_ci#define DMAW_TO_INT                                            BIT(10)
13362306a36Sopenharmony_ci#define DMAR_TO_INT                                             BIT(9)
13462306a36Sopenharmony_ci#define TXF_UR_INT                                              BIT(8)
13562306a36Sopenharmony_ci#define RFD3_UR_INT                                             BIT(7)
13662306a36Sopenharmony_ci#define RFD2_UR_INT                                             BIT(6)
13762306a36Sopenharmony_ci#define RFD1_UR_INT                                             BIT(5)
13862306a36Sopenharmony_ci#define RFD0_UR_INT                                             BIT(4)
13962306a36Sopenharmony_ci#define RXF_OF_INT                                              BIT(3)
14062306a36Sopenharmony_ci#define SW_MAN_INT                                              BIT(2)
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/* EMAC_MAILBOX_6 */
14362306a36Sopenharmony_ci#define RFD2_PROC_IDX_BMSK                                   0xfff0000
14462306a36Sopenharmony_ci#define RFD2_PROC_IDX_SHFT                                          16
14562306a36Sopenharmony_ci#define RFD2_PROD_IDX_BMSK                                       0xfff
14662306a36Sopenharmony_ci#define RFD2_PROD_IDX_SHFT                                           0
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/* EMAC_CORE_HW_VERSION */
14962306a36Sopenharmony_ci#define MAJOR_BMSK                                          0xf0000000
15062306a36Sopenharmony_ci#define MAJOR_SHFT                                                  28
15162306a36Sopenharmony_ci#define MINOR_BMSK                                           0xfff0000
15262306a36Sopenharmony_ci#define MINOR_SHFT                                                  16
15362306a36Sopenharmony_ci#define STEP_BMSK                                               0xffff
15462306a36Sopenharmony_ci#define STEP_SHFT                                                    0
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci/* EMAC_EMAC_WRAPPER_CSR1 */
15762306a36Sopenharmony_ci#define TX_INDX_FIFO_SYNC_RST                                  BIT(23)
15862306a36Sopenharmony_ci#define TX_TS_FIFO_SYNC_RST                                    BIT(22)
15962306a36Sopenharmony_ci#define RX_TS_FIFO2_SYNC_RST                                   BIT(21)
16062306a36Sopenharmony_ci#define RX_TS_FIFO1_SYNC_RST                                   BIT(20)
16162306a36Sopenharmony_ci#define TX_TS_ENABLE                                           BIT(16)
16262306a36Sopenharmony_ci#define DIS_1588_CLKS                                          BIT(11)
16362306a36Sopenharmony_ci#define FREQ_MODE                                               BIT(9)
16462306a36Sopenharmony_ci#define ENABLE_RRD_TIMESTAMP                                    BIT(3)
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci/* EMAC_EMAC_WRAPPER_CSR2 */
16762306a36Sopenharmony_ci#define HDRIVE_BMSK                                             0x3000
16862306a36Sopenharmony_ci#define HDRIVE_SHFT                                                 12
16962306a36Sopenharmony_ci#define SLB_EN                                                  BIT(9)
17062306a36Sopenharmony_ci#define PLB_EN                                                  BIT(8)
17162306a36Sopenharmony_ci#define WOL_EN                                                  BIT(3)
17262306a36Sopenharmony_ci#define PHY_RESET                                               BIT(0)
17362306a36Sopenharmony_ci
17462306a36Sopenharmony_ci#define EMAC_DEV_ID                                             0x0040
17562306a36Sopenharmony_ci
17662306a36Sopenharmony_ci/* SGMII v2 per lane registers */
17762306a36Sopenharmony_ci#define SGMII_LN_RSM_START             0x029C
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/* SGMII v2 PHY common registers */
18062306a36Sopenharmony_ci#define SGMII_PHY_CMN_CTRL            0x0408
18162306a36Sopenharmony_ci#define SGMII_PHY_CMN_RESET_CTRL      0x0410
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci/* SGMII v2 PHY registers per lane */
18462306a36Sopenharmony_ci#define SGMII_PHY_LN_OFFSET          0x0400
18562306a36Sopenharmony_ci#define SGMII_PHY_LN_LANE_STATUS     0x00DC
18662306a36Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN0       0x008C
18762306a36Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN1       0x0090
18862306a36Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN2       0x0094
18962306a36Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN3       0x0098
19062306a36Sopenharmony_ci#define SGMII_PHY_LN_CDR_CTRL1       0x005C
19162306a36Sopenharmony_ci
19262306a36Sopenharmony_cienum emac_clk_id {
19362306a36Sopenharmony_ci	EMAC_CLK_AXI,
19462306a36Sopenharmony_ci	EMAC_CLK_CFG_AHB,
19562306a36Sopenharmony_ci	EMAC_CLK_HIGH_SPEED,
19662306a36Sopenharmony_ci	EMAC_CLK_MDIO,
19762306a36Sopenharmony_ci	EMAC_CLK_TX,
19862306a36Sopenharmony_ci	EMAC_CLK_RX,
19962306a36Sopenharmony_ci	EMAC_CLK_SYS,
20062306a36Sopenharmony_ci	EMAC_CLK_CNT
20162306a36Sopenharmony_ci};
20262306a36Sopenharmony_ci
20362306a36Sopenharmony_ci#define EMAC_LINK_SPEED_UNKNOWN                                    0x0
20462306a36Sopenharmony_ci#define EMAC_LINK_SPEED_10_HALF                                 BIT(0)
20562306a36Sopenharmony_ci#define EMAC_LINK_SPEED_10_FULL                                 BIT(1)
20662306a36Sopenharmony_ci#define EMAC_LINK_SPEED_100_HALF                                BIT(2)
20762306a36Sopenharmony_ci#define EMAC_LINK_SPEED_100_FULL                                BIT(3)
20862306a36Sopenharmony_ci#define EMAC_LINK_SPEED_1GB_FULL                                BIT(5)
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci#define EMAC_MAX_SETUP_LNK_CYCLE                                   100
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_cistruct emac_stats {
21362306a36Sopenharmony_ci	/* rx */
21462306a36Sopenharmony_ci	u64 rx_ok;              /* good packets */
21562306a36Sopenharmony_ci	u64 rx_bcast;           /* good broadcast packets */
21662306a36Sopenharmony_ci	u64 rx_mcast;           /* good multicast packets */
21762306a36Sopenharmony_ci	u64 rx_pause;           /* pause packet */
21862306a36Sopenharmony_ci	u64 rx_ctrl;            /* control packets other than pause frame. */
21962306a36Sopenharmony_ci	u64 rx_fcs_err;         /* packets with bad FCS. */
22062306a36Sopenharmony_ci	u64 rx_len_err;         /* packets with length mismatch */
22162306a36Sopenharmony_ci	u64 rx_byte_cnt;        /* good bytes count (without FCS) */
22262306a36Sopenharmony_ci	u64 rx_runt;            /* runt packets */
22362306a36Sopenharmony_ci	u64 rx_frag;            /* fragment count */
22462306a36Sopenharmony_ci	u64 rx_sz_64;	        /* packets that are 64 bytes */
22562306a36Sopenharmony_ci	u64 rx_sz_65_127;       /* packets that are 65-127 bytes */
22662306a36Sopenharmony_ci	u64 rx_sz_128_255;      /* packets that are 128-255 bytes */
22762306a36Sopenharmony_ci	u64 rx_sz_256_511;      /* packets that are 256-511 bytes */
22862306a36Sopenharmony_ci	u64 rx_sz_512_1023;     /* packets that are 512-1023 bytes */
22962306a36Sopenharmony_ci	u64 rx_sz_1024_1518;    /* packets that are 1024-1518 bytes */
23062306a36Sopenharmony_ci	u64 rx_sz_1519_max;     /* packets that are 1519-MTU bytes*/
23162306a36Sopenharmony_ci	u64 rx_sz_ov;           /* packets that are >MTU bytes (truncated) */
23262306a36Sopenharmony_ci	u64 rx_rxf_ov;          /* packets dropped due to RX FIFO overflow */
23362306a36Sopenharmony_ci	u64 rx_align_err;       /* alignment errors */
23462306a36Sopenharmony_ci	u64 rx_bcast_byte_cnt;  /* broadcast packets byte count (without FCS) */
23562306a36Sopenharmony_ci	u64 rx_mcast_byte_cnt;  /* multicast packets byte count (without FCS) */
23662306a36Sopenharmony_ci	u64 rx_err_addr;        /* packets dropped due to address filtering */
23762306a36Sopenharmony_ci	u64 rx_crc_align;       /* CRC align errors */
23862306a36Sopenharmony_ci	u64 rx_jabbers;         /* jabbers */
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci	/* tx */
24162306a36Sopenharmony_ci	u64 tx_ok;              /* good packets */
24262306a36Sopenharmony_ci	u64 tx_bcast;           /* good broadcast packets */
24362306a36Sopenharmony_ci	u64 tx_mcast;           /* good multicast packets */
24462306a36Sopenharmony_ci	u64 tx_pause;           /* pause packets */
24562306a36Sopenharmony_ci	u64 tx_exc_defer;       /* packets with excessive deferral */
24662306a36Sopenharmony_ci	u64 tx_ctrl;            /* control packets other than pause frame */
24762306a36Sopenharmony_ci	u64 tx_defer;           /* packets that are deferred. */
24862306a36Sopenharmony_ci	u64 tx_byte_cnt;        /* good bytes count (without FCS) */
24962306a36Sopenharmony_ci	u64 tx_sz_64;           /* packets that are 64 bytes */
25062306a36Sopenharmony_ci	u64 tx_sz_65_127;       /* packets that are 65-127 bytes */
25162306a36Sopenharmony_ci	u64 tx_sz_128_255;      /* packets that are 128-255 bytes */
25262306a36Sopenharmony_ci	u64 tx_sz_256_511;      /* packets that are 256-511 bytes */
25362306a36Sopenharmony_ci	u64 tx_sz_512_1023;     /* packets that are 512-1023 bytes */
25462306a36Sopenharmony_ci	u64 tx_sz_1024_1518;    /* packets that are 1024-1518 bytes */
25562306a36Sopenharmony_ci	u64 tx_sz_1519_max;     /* packets that are 1519-MTU bytes */
25662306a36Sopenharmony_ci	u64 tx_1_col;           /* packets single prior collision */
25762306a36Sopenharmony_ci	u64 tx_2_col;           /* packets with multiple prior collisions */
25862306a36Sopenharmony_ci	u64 tx_late_col;        /* packets with late collisions */
25962306a36Sopenharmony_ci	u64 tx_abort_col;       /* packets aborted due to excess collisions */
26062306a36Sopenharmony_ci	u64 tx_underrun;        /* packets aborted due to FIFO underrun */
26162306a36Sopenharmony_ci	u64 tx_rd_eop;          /* count of reads beyond EOP */
26262306a36Sopenharmony_ci	u64 tx_len_err;         /* packets with length mismatch */
26362306a36Sopenharmony_ci	u64 tx_trunc;           /* packets truncated due to size >MTU */
26462306a36Sopenharmony_ci	u64 tx_bcast_byte;      /* broadcast packets byte count (without FCS) */
26562306a36Sopenharmony_ci	u64 tx_mcast_byte;      /* multicast packets byte count (without FCS) */
26662306a36Sopenharmony_ci	u64 tx_col;             /* collisions */
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci	spinlock_t lock;	/* prevent multiple simultaneous readers */
26962306a36Sopenharmony_ci};
27062306a36Sopenharmony_ci
27162306a36Sopenharmony_ci/* RSS hstype Definitions */
27262306a36Sopenharmony_ci#define EMAC_RSS_HSTYP_IPV4_EN				    0x00000001
27362306a36Sopenharmony_ci#define EMAC_RSS_HSTYP_TCP4_EN				    0x00000002
27462306a36Sopenharmony_ci#define EMAC_RSS_HSTYP_IPV6_EN				    0x00000004
27562306a36Sopenharmony_ci#define EMAC_RSS_HSTYP_TCP6_EN				    0x00000008
27662306a36Sopenharmony_ci#define EMAC_RSS_HSTYP_ALL_EN (\
27762306a36Sopenharmony_ci		EMAC_RSS_HSTYP_IPV4_EN   |\
27862306a36Sopenharmony_ci		EMAC_RSS_HSTYP_TCP4_EN   |\
27962306a36Sopenharmony_ci		EMAC_RSS_HSTYP_IPV6_EN   |\
28062306a36Sopenharmony_ci		EMAC_RSS_HSTYP_TCP6_EN)
28162306a36Sopenharmony_ci
28262306a36Sopenharmony_ci#define EMAC_VLAN_TO_TAG(_vlan, _tag) \
28362306a36Sopenharmony_ci		(_tag =  ((((_vlan) >> 8) & 0xFF) | (((_vlan) & 0xFF) << 8)))
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_ci#define EMAC_TAG_TO_VLAN(_tag, _vlan) \
28662306a36Sopenharmony_ci		(_vlan = ((((_tag) >> 8) & 0xFF) | (((_tag) & 0xFF) << 8)))
28762306a36Sopenharmony_ci
28862306a36Sopenharmony_ci#define EMAC_DEF_RX_BUF_SIZE					  1536
28962306a36Sopenharmony_ci#define EMAC_MAX_JUMBO_PKT_SIZE				    (9 * 1024)
29062306a36Sopenharmony_ci#define EMAC_MAX_TX_OFFLOAD_THRESH			    (9 * 1024)
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci#define EMAC_MAX_ETH_FRAME_SIZE		       EMAC_MAX_JUMBO_PKT_SIZE
29362306a36Sopenharmony_ci#define EMAC_MIN_ETH_FRAME_SIZE					    68
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_ci#define EMAC_DEF_TX_QUEUES					     1
29662306a36Sopenharmony_ci#define EMAC_DEF_RX_QUEUES					     1
29762306a36Sopenharmony_ci
29862306a36Sopenharmony_ci#define EMAC_MIN_TX_DESCS					   128
29962306a36Sopenharmony_ci#define EMAC_MIN_RX_DESCS					   128
30062306a36Sopenharmony_ci
30162306a36Sopenharmony_ci#define EMAC_MAX_TX_DESCS					 16383
30262306a36Sopenharmony_ci#define EMAC_MAX_RX_DESCS					  2047
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci#define EMAC_DEF_TX_DESCS					   512
30562306a36Sopenharmony_ci#define EMAC_DEF_RX_DESCS					   256
30662306a36Sopenharmony_ci
30762306a36Sopenharmony_ci#define EMAC_DEF_RX_IRQ_MOD					   250
30862306a36Sopenharmony_ci#define EMAC_DEF_TX_IRQ_MOD					   250
30962306a36Sopenharmony_ci
31062306a36Sopenharmony_ci#define EMAC_WATCHDOG_TIME				      (5 * HZ)
31162306a36Sopenharmony_ci
31262306a36Sopenharmony_ci/* by default check link every 4 seconds */
31362306a36Sopenharmony_ci#define EMAC_TRY_LINK_TIMEOUT				      (4 * HZ)
31462306a36Sopenharmony_ci
31562306a36Sopenharmony_ci/* emac_irq per-device (per-adapter) irq properties.
31662306a36Sopenharmony_ci * @irq:	irq number.
31762306a36Sopenharmony_ci * @mask	mask to use over status register.
31862306a36Sopenharmony_ci */
31962306a36Sopenharmony_cistruct emac_irq {
32062306a36Sopenharmony_ci	unsigned int	irq;
32162306a36Sopenharmony_ci	u32		mask;
32262306a36Sopenharmony_ci};
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci/* The device's main data structure */
32562306a36Sopenharmony_cistruct emac_adapter {
32662306a36Sopenharmony_ci	struct net_device		*netdev;
32762306a36Sopenharmony_ci	struct mii_bus			*mii_bus;
32862306a36Sopenharmony_ci	struct phy_device		*phydev;
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci	void __iomem			*base;
33162306a36Sopenharmony_ci	void __iomem			*csr;
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_ci	struct emac_sgmii		phy;
33462306a36Sopenharmony_ci	struct emac_stats		stats;
33562306a36Sopenharmony_ci
33662306a36Sopenharmony_ci	struct emac_irq			irq;
33762306a36Sopenharmony_ci	struct clk			*clk[EMAC_CLK_CNT];
33862306a36Sopenharmony_ci
33962306a36Sopenharmony_ci	/* All Descriptor memory */
34062306a36Sopenharmony_ci	struct emac_ring_header		ring_header;
34162306a36Sopenharmony_ci	struct emac_tx_queue		tx_q;
34262306a36Sopenharmony_ci	struct emac_rx_queue		rx_q;
34362306a36Sopenharmony_ci	unsigned int			tx_desc_cnt;
34462306a36Sopenharmony_ci	unsigned int			rx_desc_cnt;
34562306a36Sopenharmony_ci	unsigned int			rrd_size; /* in quad words */
34662306a36Sopenharmony_ci	unsigned int			rfd_size; /* in quad words */
34762306a36Sopenharmony_ci	unsigned int			tpd_size; /* in quad words */
34862306a36Sopenharmony_ci
34962306a36Sopenharmony_ci	unsigned int			rxbuf_size;
35062306a36Sopenharmony_ci
35162306a36Sopenharmony_ci	/* Flow control / pause frames support. If automatic=True, do whatever
35262306a36Sopenharmony_ci	 * the PHY does. Otherwise, use tx_flow_control and rx_flow_control.
35362306a36Sopenharmony_ci	 */
35462306a36Sopenharmony_ci	bool				automatic;
35562306a36Sopenharmony_ci	bool				tx_flow_control;
35662306a36Sopenharmony_ci	bool				rx_flow_control;
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_ci	/* True == use single-pause-frame mode. */
35962306a36Sopenharmony_ci	bool				single_pause_mode;
36062306a36Sopenharmony_ci
36162306a36Sopenharmony_ci	/* Ring parameter */
36262306a36Sopenharmony_ci	u8				tpd_burst;
36362306a36Sopenharmony_ci	u8				rfd_burst;
36462306a36Sopenharmony_ci	unsigned int			dmaw_dly_cnt;
36562306a36Sopenharmony_ci	unsigned int			dmar_dly_cnt;
36662306a36Sopenharmony_ci	enum emac_dma_req_block		dmar_block;
36762306a36Sopenharmony_ci	enum emac_dma_req_block		dmaw_block;
36862306a36Sopenharmony_ci	enum emac_dma_order		dma_order;
36962306a36Sopenharmony_ci
37062306a36Sopenharmony_ci	u32				irq_mod;
37162306a36Sopenharmony_ci	u32				preamble;
37262306a36Sopenharmony_ci
37362306a36Sopenharmony_ci	struct work_struct		work_thread;
37462306a36Sopenharmony_ci
37562306a36Sopenharmony_ci	u16				msg_enable;
37662306a36Sopenharmony_ci
37762306a36Sopenharmony_ci	struct mutex			reset_lock;
37862306a36Sopenharmony_ci};
37962306a36Sopenharmony_ci
38062306a36Sopenharmony_ciint emac_reinit_locked(struct emac_adapter *adpt);
38162306a36Sopenharmony_civoid emac_reg_update32(void __iomem *addr, u32 mask, u32 val);
38262306a36Sopenharmony_ci
38362306a36Sopenharmony_civoid emac_set_ethtool_ops(struct net_device *netdev);
38462306a36Sopenharmony_civoid emac_update_hw_stats(struct emac_adapter *adpt);
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ci#endif /* _EMAC_H_ */
387