18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
38c2ecf20Sopenharmony_ci */
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#ifndef _EMAC_H_
68c2ecf20Sopenharmony_ci#define _EMAC_H_
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/irqreturn.h>
98c2ecf20Sopenharmony_ci#include <linux/netdevice.h>
108c2ecf20Sopenharmony_ci#include <linux/clk.h>
118c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
128c2ecf20Sopenharmony_ci#include "emac-mac.h"
138c2ecf20Sopenharmony_ci#include "emac-phy.h"
148c2ecf20Sopenharmony_ci#include "emac-sgmii.h"
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci/* EMAC base register offsets */
178c2ecf20Sopenharmony_ci#define EMAC_DMA_MAS_CTRL		0x1400
188c2ecf20Sopenharmony_ci#define EMAC_IRQ_MOD_TIM_INIT		0x1408
198c2ecf20Sopenharmony_ci#define EMAC_BLK_IDLE_STS		0x140c
208c2ecf20Sopenharmony_ci#define EMAC_PHY_LINK_DELAY		0x141c
218c2ecf20Sopenharmony_ci#define EMAC_SYS_ALIV_CTRL		0x1434
228c2ecf20Sopenharmony_ci#define EMAC_MAC_CTRL			0x1480
238c2ecf20Sopenharmony_ci#define EMAC_MAC_IPGIFG_CTRL		0x1484
248c2ecf20Sopenharmony_ci#define EMAC_MAC_STA_ADDR0		0x1488
258c2ecf20Sopenharmony_ci#define EMAC_MAC_STA_ADDR1		0x148c
268c2ecf20Sopenharmony_ci#define EMAC_HASH_TAB_REG0		0x1490
278c2ecf20Sopenharmony_ci#define EMAC_HASH_TAB_REG1		0x1494
288c2ecf20Sopenharmony_ci#define EMAC_MAC_HALF_DPLX_CTRL		0x1498
298c2ecf20Sopenharmony_ci#define EMAC_MAX_FRAM_LEN_CTRL		0x149c
308c2ecf20Sopenharmony_ci#define EMAC_WOL_CTRL0			0x14a0
318c2ecf20Sopenharmony_ci#define EMAC_RSS_KEY0			0x14b0
328c2ecf20Sopenharmony_ci#define EMAC_H1TPD_BASE_ADDR_LO		0x14e0
338c2ecf20Sopenharmony_ci#define EMAC_H2TPD_BASE_ADDR_LO		0x14e4
348c2ecf20Sopenharmony_ci#define EMAC_H3TPD_BASE_ADDR_LO		0x14e8
358c2ecf20Sopenharmony_ci#define EMAC_INTER_SRAM_PART9		0x1534
368c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_0		0x1540
378c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_1		0x1544
388c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_2		0x1550
398c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_10		0x1554
408c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_12		0x1558
418c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_13		0x155c
428c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_3		0x1560
438c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_4		0x1564
448c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_5		0x1568
458c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_14		0x156c
468c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_15		0x1570
478c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_16		0x1574
488c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_6		0x1578
498c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_8		0x1580
508c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_9		0x1584
518c2ecf20Sopenharmony_ci#define EMAC_DESC_CTRL_11		0x1588
528c2ecf20Sopenharmony_ci#define EMAC_TXQ_CTRL_0			0x1590
538c2ecf20Sopenharmony_ci#define EMAC_TXQ_CTRL_1			0x1594
548c2ecf20Sopenharmony_ci#define EMAC_TXQ_CTRL_2			0x1598
558c2ecf20Sopenharmony_ci#define EMAC_RXQ_CTRL_0			0x15a0
568c2ecf20Sopenharmony_ci#define EMAC_RXQ_CTRL_1			0x15a4
578c2ecf20Sopenharmony_ci#define EMAC_RXQ_CTRL_2			0x15a8
588c2ecf20Sopenharmony_ci#define EMAC_RXQ_CTRL_3			0x15ac
598c2ecf20Sopenharmony_ci#define EMAC_BASE_CPU_NUMBER		0x15b8
608c2ecf20Sopenharmony_ci#define EMAC_DMA_CTRL			0x15c0
618c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_0			0x15e0
628c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_5			0x15e4
638c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_6			0x15e8
648c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_13			0x15ec
658c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_2			0x15f4
668c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_3			0x15f8
678c2ecf20Sopenharmony_ci#define EMAC_INT_STATUS			0x1600
688c2ecf20Sopenharmony_ci#define EMAC_INT_MASK			0x1604
698c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_11			0x160c
708c2ecf20Sopenharmony_ci#define EMAC_AXI_MAST_CTRL		0x1610
718c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_12			0x1614
728c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_9			0x1618
738c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_10			0x161c
748c2ecf20Sopenharmony_ci#define EMAC_ATHR_HEADER_CTRL		0x1620
758c2ecf20Sopenharmony_ci#define EMAC_RXMAC_STATC_REG0		0x1700
768c2ecf20Sopenharmony_ci#define EMAC_RXMAC_STATC_REG22		0x1758
778c2ecf20Sopenharmony_ci#define EMAC_TXMAC_STATC_REG0		0x1760
788c2ecf20Sopenharmony_ci#define EMAC_TXMAC_STATC_REG24		0x17c0
798c2ecf20Sopenharmony_ci#define EMAC_CLK_GATE_CTRL		0x1814
808c2ecf20Sopenharmony_ci#define EMAC_CORE_HW_VERSION		0x1974
818c2ecf20Sopenharmony_ci#define EMAC_MISC_CTRL			0x1990
828c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_7			0x19e0
838c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_8			0x19e4
848c2ecf20Sopenharmony_ci#define EMAC_IDT_TABLE0			0x1b00
858c2ecf20Sopenharmony_ci#define EMAC_RXMAC_STATC_REG23		0x1bc8
868c2ecf20Sopenharmony_ci#define EMAC_RXMAC_STATC_REG24		0x1bcc
878c2ecf20Sopenharmony_ci#define EMAC_TXMAC_STATC_REG25		0x1bd0
888c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_15			0x1bd4
898c2ecf20Sopenharmony_ci#define EMAC_MAILBOX_16			0x1bd8
908c2ecf20Sopenharmony_ci#define EMAC_INT1_MASK			0x1bf0
918c2ecf20Sopenharmony_ci#define EMAC_INT1_STATUS		0x1bf4
928c2ecf20Sopenharmony_ci#define EMAC_INT2_MASK			0x1bf8
938c2ecf20Sopenharmony_ci#define EMAC_INT2_STATUS		0x1bfc
948c2ecf20Sopenharmony_ci#define EMAC_INT3_MASK			0x1c00
958c2ecf20Sopenharmony_ci#define EMAC_INT3_STATUS		0x1c04
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci/* EMAC_DMA_MAS_CTRL */
988c2ecf20Sopenharmony_ci#define DEV_ID_NUM_BMSK                                     0x7f000000
998c2ecf20Sopenharmony_ci#define DEV_ID_NUM_SHFT                                             24
1008c2ecf20Sopenharmony_ci#define DEV_REV_NUM_BMSK                                      0xff0000
1018c2ecf20Sopenharmony_ci#define DEV_REV_NUM_SHFT                                            16
1028c2ecf20Sopenharmony_ci#define INT_RD_CLR_EN                                           0x4000
1038c2ecf20Sopenharmony_ci#define IRQ_MODERATOR2_EN                                        0x800
1048c2ecf20Sopenharmony_ci#define IRQ_MODERATOR_EN                                         0x400
1058c2ecf20Sopenharmony_ci#define LPW_CLK_SEL                                               0x80
1068c2ecf20Sopenharmony_ci#define LPW_STATE                                                 0x20
1078c2ecf20Sopenharmony_ci#define LPW_MODE                                                  0x10
1088c2ecf20Sopenharmony_ci#define SOFT_RST                                                   0x1
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci/* EMAC_IRQ_MOD_TIM_INIT */
1118c2ecf20Sopenharmony_ci#define IRQ_MODERATOR2_INIT_BMSK                            0xffff0000
1128c2ecf20Sopenharmony_ci#define IRQ_MODERATOR2_INIT_SHFT                                    16
1138c2ecf20Sopenharmony_ci#define IRQ_MODERATOR_INIT_BMSK                                 0xffff
1148c2ecf20Sopenharmony_ci#define IRQ_MODERATOR_INIT_SHFT                                      0
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/* EMAC_INT_STATUS */
1178c2ecf20Sopenharmony_ci#define DIS_INT                                                BIT(31)
1188c2ecf20Sopenharmony_ci#define PTP_INT                                                BIT(30)
1198c2ecf20Sopenharmony_ci#define RFD4_UR_INT                                            BIT(29)
1208c2ecf20Sopenharmony_ci#define TX_PKT_INT3                                            BIT(26)
1218c2ecf20Sopenharmony_ci#define TX_PKT_INT2                                            BIT(25)
1228c2ecf20Sopenharmony_ci#define TX_PKT_INT1                                            BIT(24)
1238c2ecf20Sopenharmony_ci#define RX_PKT_INT3                                            BIT(19)
1248c2ecf20Sopenharmony_ci#define RX_PKT_INT2                                            BIT(18)
1258c2ecf20Sopenharmony_ci#define RX_PKT_INT1                                            BIT(17)
1268c2ecf20Sopenharmony_ci#define RX_PKT_INT0                                            BIT(16)
1278c2ecf20Sopenharmony_ci#define TX_PKT_INT                                             BIT(15)
1288c2ecf20Sopenharmony_ci#define TXQ_TO_INT                                             BIT(14)
1298c2ecf20Sopenharmony_ci#define GPHY_WAKEUP_INT                                        BIT(13)
1308c2ecf20Sopenharmony_ci#define GPHY_LINK_DOWN_INT                                     BIT(12)
1318c2ecf20Sopenharmony_ci#define GPHY_LINK_UP_INT                                       BIT(11)
1328c2ecf20Sopenharmony_ci#define DMAW_TO_INT                                            BIT(10)
1338c2ecf20Sopenharmony_ci#define DMAR_TO_INT                                             BIT(9)
1348c2ecf20Sopenharmony_ci#define TXF_UR_INT                                              BIT(8)
1358c2ecf20Sopenharmony_ci#define RFD3_UR_INT                                             BIT(7)
1368c2ecf20Sopenharmony_ci#define RFD2_UR_INT                                             BIT(6)
1378c2ecf20Sopenharmony_ci#define RFD1_UR_INT                                             BIT(5)
1388c2ecf20Sopenharmony_ci#define RFD0_UR_INT                                             BIT(4)
1398c2ecf20Sopenharmony_ci#define RXF_OF_INT                                              BIT(3)
1408c2ecf20Sopenharmony_ci#define SW_MAN_INT                                              BIT(2)
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci/* EMAC_MAILBOX_6 */
1438c2ecf20Sopenharmony_ci#define RFD2_PROC_IDX_BMSK                                   0xfff0000
1448c2ecf20Sopenharmony_ci#define RFD2_PROC_IDX_SHFT                                          16
1458c2ecf20Sopenharmony_ci#define RFD2_PROD_IDX_BMSK                                       0xfff
1468c2ecf20Sopenharmony_ci#define RFD2_PROD_IDX_SHFT                                           0
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/* EMAC_CORE_HW_VERSION */
1498c2ecf20Sopenharmony_ci#define MAJOR_BMSK                                          0xf0000000
1508c2ecf20Sopenharmony_ci#define MAJOR_SHFT                                                  28
1518c2ecf20Sopenharmony_ci#define MINOR_BMSK                                           0xfff0000
1528c2ecf20Sopenharmony_ci#define MINOR_SHFT                                                  16
1538c2ecf20Sopenharmony_ci#define STEP_BMSK                                               0xffff
1548c2ecf20Sopenharmony_ci#define STEP_SHFT                                                    0
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* EMAC_EMAC_WRAPPER_CSR1 */
1578c2ecf20Sopenharmony_ci#define TX_INDX_FIFO_SYNC_RST                                  BIT(23)
1588c2ecf20Sopenharmony_ci#define TX_TS_FIFO_SYNC_RST                                    BIT(22)
1598c2ecf20Sopenharmony_ci#define RX_TS_FIFO2_SYNC_RST                                   BIT(21)
1608c2ecf20Sopenharmony_ci#define RX_TS_FIFO1_SYNC_RST                                   BIT(20)
1618c2ecf20Sopenharmony_ci#define TX_TS_ENABLE                                           BIT(16)
1628c2ecf20Sopenharmony_ci#define DIS_1588_CLKS                                          BIT(11)
1638c2ecf20Sopenharmony_ci#define FREQ_MODE                                               BIT(9)
1648c2ecf20Sopenharmony_ci#define ENABLE_RRD_TIMESTAMP                                    BIT(3)
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci/* EMAC_EMAC_WRAPPER_CSR2 */
1678c2ecf20Sopenharmony_ci#define HDRIVE_BMSK                                             0x3000
1688c2ecf20Sopenharmony_ci#define HDRIVE_SHFT                                                 12
1698c2ecf20Sopenharmony_ci#define SLB_EN                                                  BIT(9)
1708c2ecf20Sopenharmony_ci#define PLB_EN                                                  BIT(8)
1718c2ecf20Sopenharmony_ci#define WOL_EN                                                  BIT(3)
1728c2ecf20Sopenharmony_ci#define PHY_RESET                                               BIT(0)
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci#define EMAC_DEV_ID                                             0x0040
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci/* SGMII v2 per lane registers */
1778c2ecf20Sopenharmony_ci#define SGMII_LN_RSM_START             0x029C
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci/* SGMII v2 PHY common registers */
1808c2ecf20Sopenharmony_ci#define SGMII_PHY_CMN_CTRL            0x0408
1818c2ecf20Sopenharmony_ci#define SGMII_PHY_CMN_RESET_CTRL      0x0410
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/* SGMII v2 PHY registers per lane */
1848c2ecf20Sopenharmony_ci#define SGMII_PHY_LN_OFFSET          0x0400
1858c2ecf20Sopenharmony_ci#define SGMII_PHY_LN_LANE_STATUS     0x00DC
1868c2ecf20Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN0       0x008C
1878c2ecf20Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN1       0x0090
1888c2ecf20Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN2       0x0094
1898c2ecf20Sopenharmony_ci#define SGMII_PHY_LN_BIST_GEN3       0x0098
1908c2ecf20Sopenharmony_ci#define SGMII_PHY_LN_CDR_CTRL1       0x005C
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_cienum emac_clk_id {
1938c2ecf20Sopenharmony_ci	EMAC_CLK_AXI,
1948c2ecf20Sopenharmony_ci	EMAC_CLK_CFG_AHB,
1958c2ecf20Sopenharmony_ci	EMAC_CLK_HIGH_SPEED,
1968c2ecf20Sopenharmony_ci	EMAC_CLK_MDIO,
1978c2ecf20Sopenharmony_ci	EMAC_CLK_TX,
1988c2ecf20Sopenharmony_ci	EMAC_CLK_RX,
1998c2ecf20Sopenharmony_ci	EMAC_CLK_SYS,
2008c2ecf20Sopenharmony_ci	EMAC_CLK_CNT
2018c2ecf20Sopenharmony_ci};
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci#define EMAC_LINK_SPEED_UNKNOWN                                    0x0
2048c2ecf20Sopenharmony_ci#define EMAC_LINK_SPEED_10_HALF                                 BIT(0)
2058c2ecf20Sopenharmony_ci#define EMAC_LINK_SPEED_10_FULL                                 BIT(1)
2068c2ecf20Sopenharmony_ci#define EMAC_LINK_SPEED_100_HALF                                BIT(2)
2078c2ecf20Sopenharmony_ci#define EMAC_LINK_SPEED_100_FULL                                BIT(3)
2088c2ecf20Sopenharmony_ci#define EMAC_LINK_SPEED_1GB_FULL                                BIT(5)
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci#define EMAC_MAX_SETUP_LNK_CYCLE                                   100
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_cistruct emac_stats {
2138c2ecf20Sopenharmony_ci	/* rx */
2148c2ecf20Sopenharmony_ci	u64 rx_ok;              /* good packets */
2158c2ecf20Sopenharmony_ci	u64 rx_bcast;           /* good broadcast packets */
2168c2ecf20Sopenharmony_ci	u64 rx_mcast;           /* good multicast packets */
2178c2ecf20Sopenharmony_ci	u64 rx_pause;           /* pause packet */
2188c2ecf20Sopenharmony_ci	u64 rx_ctrl;            /* control packets other than pause frame. */
2198c2ecf20Sopenharmony_ci	u64 rx_fcs_err;         /* packets with bad FCS. */
2208c2ecf20Sopenharmony_ci	u64 rx_len_err;         /* packets with length mismatch */
2218c2ecf20Sopenharmony_ci	u64 rx_byte_cnt;        /* good bytes count (without FCS) */
2228c2ecf20Sopenharmony_ci	u64 rx_runt;            /* runt packets */
2238c2ecf20Sopenharmony_ci	u64 rx_frag;            /* fragment count */
2248c2ecf20Sopenharmony_ci	u64 rx_sz_64;	        /* packets that are 64 bytes */
2258c2ecf20Sopenharmony_ci	u64 rx_sz_65_127;       /* packets that are 65-127 bytes */
2268c2ecf20Sopenharmony_ci	u64 rx_sz_128_255;      /* packets that are 128-255 bytes */
2278c2ecf20Sopenharmony_ci	u64 rx_sz_256_511;      /* packets that are 256-511 bytes */
2288c2ecf20Sopenharmony_ci	u64 rx_sz_512_1023;     /* packets that are 512-1023 bytes */
2298c2ecf20Sopenharmony_ci	u64 rx_sz_1024_1518;    /* packets that are 1024-1518 bytes */
2308c2ecf20Sopenharmony_ci	u64 rx_sz_1519_max;     /* packets that are 1519-MTU bytes*/
2318c2ecf20Sopenharmony_ci	u64 rx_sz_ov;           /* packets that are >MTU bytes (truncated) */
2328c2ecf20Sopenharmony_ci	u64 rx_rxf_ov;          /* packets dropped due to RX FIFO overflow */
2338c2ecf20Sopenharmony_ci	u64 rx_align_err;       /* alignment errors */
2348c2ecf20Sopenharmony_ci	u64 rx_bcast_byte_cnt;  /* broadcast packets byte count (without FCS) */
2358c2ecf20Sopenharmony_ci	u64 rx_mcast_byte_cnt;  /* multicast packets byte count (without FCS) */
2368c2ecf20Sopenharmony_ci	u64 rx_err_addr;        /* packets dropped due to address filtering */
2378c2ecf20Sopenharmony_ci	u64 rx_crc_align;       /* CRC align errors */
2388c2ecf20Sopenharmony_ci	u64 rx_jabbers;         /* jabbers */
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci	/* tx */
2418c2ecf20Sopenharmony_ci	u64 tx_ok;              /* good packets */
2428c2ecf20Sopenharmony_ci	u64 tx_bcast;           /* good broadcast packets */
2438c2ecf20Sopenharmony_ci	u64 tx_mcast;           /* good multicast packets */
2448c2ecf20Sopenharmony_ci	u64 tx_pause;           /* pause packets */
2458c2ecf20Sopenharmony_ci	u64 tx_exc_defer;       /* packets with excessive deferral */
2468c2ecf20Sopenharmony_ci	u64 tx_ctrl;            /* control packets other than pause frame */
2478c2ecf20Sopenharmony_ci	u64 tx_defer;           /* packets that are deferred. */
2488c2ecf20Sopenharmony_ci	u64 tx_byte_cnt;        /* good bytes count (without FCS) */
2498c2ecf20Sopenharmony_ci	u64 tx_sz_64;           /* packets that are 64 bytes */
2508c2ecf20Sopenharmony_ci	u64 tx_sz_65_127;       /* packets that are 65-127 bytes */
2518c2ecf20Sopenharmony_ci	u64 tx_sz_128_255;      /* packets that are 128-255 bytes */
2528c2ecf20Sopenharmony_ci	u64 tx_sz_256_511;      /* packets that are 256-511 bytes */
2538c2ecf20Sopenharmony_ci	u64 tx_sz_512_1023;     /* packets that are 512-1023 bytes */
2548c2ecf20Sopenharmony_ci	u64 tx_sz_1024_1518;    /* packets that are 1024-1518 bytes */
2558c2ecf20Sopenharmony_ci	u64 tx_sz_1519_max;     /* packets that are 1519-MTU bytes */
2568c2ecf20Sopenharmony_ci	u64 tx_1_col;           /* packets single prior collision */
2578c2ecf20Sopenharmony_ci	u64 tx_2_col;           /* packets with multiple prior collisions */
2588c2ecf20Sopenharmony_ci	u64 tx_late_col;        /* packets with late collisions */
2598c2ecf20Sopenharmony_ci	u64 tx_abort_col;       /* packets aborted due to excess collisions */
2608c2ecf20Sopenharmony_ci	u64 tx_underrun;        /* packets aborted due to FIFO underrun */
2618c2ecf20Sopenharmony_ci	u64 tx_rd_eop;          /* count of reads beyond EOP */
2628c2ecf20Sopenharmony_ci	u64 tx_len_err;         /* packets with length mismatch */
2638c2ecf20Sopenharmony_ci	u64 tx_trunc;           /* packets truncated due to size >MTU */
2648c2ecf20Sopenharmony_ci	u64 tx_bcast_byte;      /* broadcast packets byte count (without FCS) */
2658c2ecf20Sopenharmony_ci	u64 tx_mcast_byte;      /* multicast packets byte count (without FCS) */
2668c2ecf20Sopenharmony_ci	u64 tx_col;             /* collisions */
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci	spinlock_t lock;	/* prevent multiple simultaneous readers */
2698c2ecf20Sopenharmony_ci};
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci/* RSS hstype Definitions */
2728c2ecf20Sopenharmony_ci#define EMAC_RSS_HSTYP_IPV4_EN				    0x00000001
2738c2ecf20Sopenharmony_ci#define EMAC_RSS_HSTYP_TCP4_EN				    0x00000002
2748c2ecf20Sopenharmony_ci#define EMAC_RSS_HSTYP_IPV6_EN				    0x00000004
2758c2ecf20Sopenharmony_ci#define EMAC_RSS_HSTYP_TCP6_EN				    0x00000008
2768c2ecf20Sopenharmony_ci#define EMAC_RSS_HSTYP_ALL_EN (\
2778c2ecf20Sopenharmony_ci		EMAC_RSS_HSTYP_IPV4_EN   |\
2788c2ecf20Sopenharmony_ci		EMAC_RSS_HSTYP_TCP4_EN   |\
2798c2ecf20Sopenharmony_ci		EMAC_RSS_HSTYP_IPV6_EN   |\
2808c2ecf20Sopenharmony_ci		EMAC_RSS_HSTYP_TCP6_EN)
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci#define EMAC_VLAN_TO_TAG(_vlan, _tag) \
2838c2ecf20Sopenharmony_ci		(_tag =  ((((_vlan) >> 8) & 0xFF) | (((_vlan) & 0xFF) << 8)))
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci#define EMAC_TAG_TO_VLAN(_tag, _vlan) \
2868c2ecf20Sopenharmony_ci		(_vlan = ((((_tag) >> 8) & 0xFF) | (((_tag) & 0xFF) << 8)))
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci#define EMAC_DEF_RX_BUF_SIZE					  1536
2898c2ecf20Sopenharmony_ci#define EMAC_MAX_JUMBO_PKT_SIZE				    (9 * 1024)
2908c2ecf20Sopenharmony_ci#define EMAC_MAX_TX_OFFLOAD_THRESH			    (9 * 1024)
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_ci#define EMAC_MAX_ETH_FRAME_SIZE		       EMAC_MAX_JUMBO_PKT_SIZE
2938c2ecf20Sopenharmony_ci#define EMAC_MIN_ETH_FRAME_SIZE					    68
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci#define EMAC_DEF_TX_QUEUES					     1
2968c2ecf20Sopenharmony_ci#define EMAC_DEF_RX_QUEUES					     1
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci#define EMAC_MIN_TX_DESCS					   128
2998c2ecf20Sopenharmony_ci#define EMAC_MIN_RX_DESCS					   128
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci#define EMAC_MAX_TX_DESCS					 16383
3028c2ecf20Sopenharmony_ci#define EMAC_MAX_RX_DESCS					  2047
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci#define EMAC_DEF_TX_DESCS					   512
3058c2ecf20Sopenharmony_ci#define EMAC_DEF_RX_DESCS					   256
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ci#define EMAC_DEF_RX_IRQ_MOD					   250
3088c2ecf20Sopenharmony_ci#define EMAC_DEF_TX_IRQ_MOD					   250
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci#define EMAC_WATCHDOG_TIME				      (5 * HZ)
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci/* by default check link every 4 seconds */
3138c2ecf20Sopenharmony_ci#define EMAC_TRY_LINK_TIMEOUT				      (4 * HZ)
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci/* emac_irq per-device (per-adapter) irq properties.
3168c2ecf20Sopenharmony_ci * @irq:	irq number.
3178c2ecf20Sopenharmony_ci * @mask	mask to use over status register.
3188c2ecf20Sopenharmony_ci */
3198c2ecf20Sopenharmony_cistruct emac_irq {
3208c2ecf20Sopenharmony_ci	unsigned int	irq;
3218c2ecf20Sopenharmony_ci	u32		mask;
3228c2ecf20Sopenharmony_ci};
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci/* The device's main data structure */
3258c2ecf20Sopenharmony_cistruct emac_adapter {
3268c2ecf20Sopenharmony_ci	struct net_device		*netdev;
3278c2ecf20Sopenharmony_ci	struct mii_bus			*mii_bus;
3288c2ecf20Sopenharmony_ci	struct phy_device		*phydev;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	void __iomem			*base;
3318c2ecf20Sopenharmony_ci	void __iomem			*csr;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	struct emac_sgmii		phy;
3348c2ecf20Sopenharmony_ci	struct emac_stats		stats;
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	struct emac_irq			irq;
3378c2ecf20Sopenharmony_ci	struct clk			*clk[EMAC_CLK_CNT];
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	/* All Descriptor memory */
3408c2ecf20Sopenharmony_ci	struct emac_ring_header		ring_header;
3418c2ecf20Sopenharmony_ci	struct emac_tx_queue		tx_q;
3428c2ecf20Sopenharmony_ci	struct emac_rx_queue		rx_q;
3438c2ecf20Sopenharmony_ci	unsigned int			tx_desc_cnt;
3448c2ecf20Sopenharmony_ci	unsigned int			rx_desc_cnt;
3458c2ecf20Sopenharmony_ci	unsigned int			rrd_size; /* in quad words */
3468c2ecf20Sopenharmony_ci	unsigned int			rfd_size; /* in quad words */
3478c2ecf20Sopenharmony_ci	unsigned int			tpd_size; /* in quad words */
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci	unsigned int			rxbuf_size;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	/* Flow control / pause frames support. If automatic=True, do whatever
3528c2ecf20Sopenharmony_ci	 * the PHY does. Otherwise, use tx_flow_control and rx_flow_control.
3538c2ecf20Sopenharmony_ci	 */
3548c2ecf20Sopenharmony_ci	bool				automatic;
3558c2ecf20Sopenharmony_ci	bool				tx_flow_control;
3568c2ecf20Sopenharmony_ci	bool				rx_flow_control;
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	/* True == use single-pause-frame mode. */
3598c2ecf20Sopenharmony_ci	bool				single_pause_mode;
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	/* Ring parameter */
3628c2ecf20Sopenharmony_ci	u8				tpd_burst;
3638c2ecf20Sopenharmony_ci	u8				rfd_burst;
3648c2ecf20Sopenharmony_ci	unsigned int			dmaw_dly_cnt;
3658c2ecf20Sopenharmony_ci	unsigned int			dmar_dly_cnt;
3668c2ecf20Sopenharmony_ci	enum emac_dma_req_block		dmar_block;
3678c2ecf20Sopenharmony_ci	enum emac_dma_req_block		dmaw_block;
3688c2ecf20Sopenharmony_ci	enum emac_dma_order		dma_order;
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	u32				irq_mod;
3718c2ecf20Sopenharmony_ci	u32				preamble;
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci	struct work_struct		work_thread;
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_ci	u16				msg_enable;
3768c2ecf20Sopenharmony_ci
3778c2ecf20Sopenharmony_ci	struct mutex			reset_lock;
3788c2ecf20Sopenharmony_ci};
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ciint emac_reinit_locked(struct emac_adapter *adpt);
3818c2ecf20Sopenharmony_civoid emac_reg_update32(void __iomem *addr, u32 mask, u32 val);
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_civoid emac_set_ethtool_ops(struct net_device *netdev);
3848c2ecf20Sopenharmony_civoid emac_update_hw_stats(struct emac_adapter *adpt);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci#endif /* _EMAC_H_ */
387