xref: /openbmc/linux/drivers/net/ethernet/qualcomm/emac/emac.h (revision c4e7beea21921733026b6a1bca0652c883d84680)
1b9b17debSTimur Tabi /* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
2b9b17debSTimur Tabi  *
3b9b17debSTimur Tabi  * This program is free software; you can redistribute it and/or modify
4b9b17debSTimur Tabi  * it under the terms of the GNU General Public License version 2 and
5b9b17debSTimur Tabi  * only version 2 as published by the Free Software Foundation.
6b9b17debSTimur Tabi  *
7b9b17debSTimur Tabi  * This program is distributed in the hope that it will be useful,
8b9b17debSTimur Tabi  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9b9b17debSTimur Tabi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10b9b17debSTimur Tabi  * GNU General Public License for more details.
11b9b17debSTimur Tabi  */
12b9b17debSTimur Tabi 
13b9b17debSTimur Tabi #ifndef _EMAC_H_
14b9b17debSTimur Tabi #define _EMAC_H_
15b9b17debSTimur Tabi 
16b9b17debSTimur Tabi #include <linux/irqreturn.h>
17b9b17debSTimur Tabi #include <linux/netdevice.h>
18b9b17debSTimur Tabi #include <linux/clk.h>
19b9b17debSTimur Tabi #include <linux/platform_device.h>
20b9b17debSTimur Tabi #include "emac-mac.h"
21b9b17debSTimur Tabi #include "emac-phy.h"
2241c1093fSTimur Tabi #include "emac-sgmii.h"
23b9b17debSTimur Tabi 
24b9b17debSTimur Tabi /* EMAC base register offsets */
25*c4e7beeaSTimur Tabi #define EMAC_DMA_MAS_CTRL		0x1400
26*c4e7beeaSTimur Tabi #define EMAC_IRQ_MOD_TIM_INIT		0x1408
27*c4e7beeaSTimur Tabi #define EMAC_BLK_IDLE_STS		0x140c
28*c4e7beeaSTimur Tabi #define EMAC_PHY_LINK_DELAY		0x141c
29*c4e7beeaSTimur Tabi #define EMAC_SYS_ALIV_CTRL		0x1434
30*c4e7beeaSTimur Tabi #define EMAC_MAC_CTRL			0x1480
31*c4e7beeaSTimur Tabi #define EMAC_MAC_IPGIFG_CTRL		0x1484
32*c4e7beeaSTimur Tabi #define EMAC_MAC_STA_ADDR0		0x1488
33*c4e7beeaSTimur Tabi #define EMAC_MAC_STA_ADDR1		0x148c
34*c4e7beeaSTimur Tabi #define EMAC_HASH_TAB_REG0		0x1490
35*c4e7beeaSTimur Tabi #define EMAC_HASH_TAB_REG1		0x1494
36*c4e7beeaSTimur Tabi #define EMAC_MAC_HALF_DPLX_CTRL		0x1498
37*c4e7beeaSTimur Tabi #define EMAC_MAX_FRAM_LEN_CTRL		0x149c
38*c4e7beeaSTimur Tabi #define EMAC_WOL_CTRL0			0x14a0
39*c4e7beeaSTimur Tabi #define EMAC_RSS_KEY0			0x14b0
40*c4e7beeaSTimur Tabi #define EMAC_H1TPD_BASE_ADDR_LO		0x14e0
41*c4e7beeaSTimur Tabi #define EMAC_H2TPD_BASE_ADDR_LO		0x14e4
42*c4e7beeaSTimur Tabi #define EMAC_H3TPD_BASE_ADDR_LO		0x14e8
43*c4e7beeaSTimur Tabi #define EMAC_INTER_SRAM_PART9		0x1534
44*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_0		0x1540
45*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_1		0x1544
46*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_2		0x1550
47*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_10		0x1554
48*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_12		0x1558
49*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_13		0x155c
50*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_3		0x1560
51*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_4		0x1564
52*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_5		0x1568
53*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_14		0x156c
54*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_15		0x1570
55*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_16		0x1574
56*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_6		0x1578
57*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_8		0x1580
58*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_9		0x1584
59*c4e7beeaSTimur Tabi #define EMAC_DESC_CTRL_11		0x1588
60*c4e7beeaSTimur Tabi #define EMAC_TXQ_CTRL_0			0x1590
61*c4e7beeaSTimur Tabi #define EMAC_TXQ_CTRL_1			0x1594
62*c4e7beeaSTimur Tabi #define EMAC_TXQ_CTRL_2			0x1598
63*c4e7beeaSTimur Tabi #define EMAC_RXQ_CTRL_0			0x15a0
64*c4e7beeaSTimur Tabi #define EMAC_RXQ_CTRL_1			0x15a4
65*c4e7beeaSTimur Tabi #define EMAC_RXQ_CTRL_2			0x15a8
66*c4e7beeaSTimur Tabi #define EMAC_RXQ_CTRL_3			0x15ac
67*c4e7beeaSTimur Tabi #define EMAC_BASE_CPU_NUMBER		0x15b8
68*c4e7beeaSTimur Tabi #define EMAC_DMA_CTRL			0x15c0
69*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_0			0x15e0
70*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_5			0x15e4
71*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_6			0x15e8
72*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_13			0x15ec
73*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_2			0x15f4
74*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_3			0x15f8
75*c4e7beeaSTimur Tabi #define EMAC_INT_STATUS			0x1600
76*c4e7beeaSTimur Tabi #define EMAC_INT_MASK			0x1604
77*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_11			0x160c
78*c4e7beeaSTimur Tabi #define EMAC_AXI_MAST_CTRL		0x1610
79*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_12			0x1614
80*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_9			0x1618
81*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_10			0x161c
82*c4e7beeaSTimur Tabi #define EMAC_ATHR_HEADER_CTRL		0x1620
83*c4e7beeaSTimur Tabi #define EMAC_RXMAC_STATC_REG0		0x1700
84*c4e7beeaSTimur Tabi #define EMAC_RXMAC_STATC_REG22		0x1758
85*c4e7beeaSTimur Tabi #define EMAC_TXMAC_STATC_REG0		0x1760
86*c4e7beeaSTimur Tabi #define EMAC_TXMAC_STATC_REG24		0x17c0
87*c4e7beeaSTimur Tabi #define EMAC_CLK_GATE_CTRL		0x1814
88*c4e7beeaSTimur Tabi #define EMAC_CORE_HW_VERSION		0x1974
89*c4e7beeaSTimur Tabi #define EMAC_MISC_CTRL			0x1990
90*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_7			0x19e0
91*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_8			0x19e4
92*c4e7beeaSTimur Tabi #define EMAC_IDT_TABLE0			0x1b00
93*c4e7beeaSTimur Tabi #define EMAC_RXMAC_STATC_REG23		0x1bc8
94*c4e7beeaSTimur Tabi #define EMAC_RXMAC_STATC_REG24		0x1bcc
95*c4e7beeaSTimur Tabi #define EMAC_TXMAC_STATC_REG25		0x1bd0
96*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_15			0x1bd4
97*c4e7beeaSTimur Tabi #define EMAC_MAILBOX_16			0x1bd8
98*c4e7beeaSTimur Tabi #define EMAC_INT1_MASK			0x1bf0
99*c4e7beeaSTimur Tabi #define EMAC_INT1_STATUS		0x1bf4
100*c4e7beeaSTimur Tabi #define EMAC_INT2_MASK			0x1bf8
101*c4e7beeaSTimur Tabi #define EMAC_INT2_STATUS		0x1bfc
102*c4e7beeaSTimur Tabi #define EMAC_INT3_MASK			0x1c00
103*c4e7beeaSTimur Tabi #define EMAC_INT3_STATUS		0x1c04
104b9b17debSTimur Tabi 
105b9b17debSTimur Tabi /* EMAC_DMA_MAS_CTRL */
106b9b17debSTimur Tabi #define DEV_ID_NUM_BMSK                                     0x7f000000
107b9b17debSTimur Tabi #define DEV_ID_NUM_SHFT                                             24
108b9b17debSTimur Tabi #define DEV_REV_NUM_BMSK                                      0xff0000
109b9b17debSTimur Tabi #define DEV_REV_NUM_SHFT                                            16
110b9b17debSTimur Tabi #define INT_RD_CLR_EN                                           0x4000
111b9b17debSTimur Tabi #define IRQ_MODERATOR2_EN                                        0x800
112b9b17debSTimur Tabi #define IRQ_MODERATOR_EN                                         0x400
113b9b17debSTimur Tabi #define LPW_CLK_SEL                                               0x80
114b9b17debSTimur Tabi #define LPW_STATE                                                 0x20
115b9b17debSTimur Tabi #define LPW_MODE                                                  0x10
116b9b17debSTimur Tabi #define SOFT_RST                                                   0x1
117b9b17debSTimur Tabi 
118b9b17debSTimur Tabi /* EMAC_IRQ_MOD_TIM_INIT */
119b9b17debSTimur Tabi #define IRQ_MODERATOR2_INIT_BMSK                            0xffff0000
120b9b17debSTimur Tabi #define IRQ_MODERATOR2_INIT_SHFT                                    16
121b9b17debSTimur Tabi #define IRQ_MODERATOR_INIT_BMSK                                 0xffff
122b9b17debSTimur Tabi #define IRQ_MODERATOR_INIT_SHFT                                      0
123b9b17debSTimur Tabi 
124b9b17debSTimur Tabi /* EMAC_INT_STATUS */
125b9b17debSTimur Tabi #define DIS_INT                                                BIT(31)
126b9b17debSTimur Tabi #define PTP_INT                                                BIT(30)
127b9b17debSTimur Tabi #define RFD4_UR_INT                                            BIT(29)
128b9b17debSTimur Tabi #define TX_PKT_INT3                                            BIT(26)
129b9b17debSTimur Tabi #define TX_PKT_INT2                                            BIT(25)
130b9b17debSTimur Tabi #define TX_PKT_INT1                                            BIT(24)
131b9b17debSTimur Tabi #define RX_PKT_INT3                                            BIT(19)
132b9b17debSTimur Tabi #define RX_PKT_INT2                                            BIT(18)
133b9b17debSTimur Tabi #define RX_PKT_INT1                                            BIT(17)
134b9b17debSTimur Tabi #define RX_PKT_INT0                                            BIT(16)
135b9b17debSTimur Tabi #define TX_PKT_INT                                             BIT(15)
136b9b17debSTimur Tabi #define TXQ_TO_INT                                             BIT(14)
137b9b17debSTimur Tabi #define GPHY_WAKEUP_INT                                        BIT(13)
138b9b17debSTimur Tabi #define GPHY_LINK_DOWN_INT                                     BIT(12)
139b9b17debSTimur Tabi #define GPHY_LINK_UP_INT                                       BIT(11)
140b9b17debSTimur Tabi #define DMAW_TO_INT                                            BIT(10)
141b9b17debSTimur Tabi #define DMAR_TO_INT                                             BIT(9)
142b9b17debSTimur Tabi #define TXF_UR_INT                                              BIT(8)
143b9b17debSTimur Tabi #define RFD3_UR_INT                                             BIT(7)
144b9b17debSTimur Tabi #define RFD2_UR_INT                                             BIT(6)
145b9b17debSTimur Tabi #define RFD1_UR_INT                                             BIT(5)
146b9b17debSTimur Tabi #define RFD0_UR_INT                                             BIT(4)
147b9b17debSTimur Tabi #define RXF_OF_INT                                              BIT(3)
148b9b17debSTimur Tabi #define SW_MAN_INT                                              BIT(2)
149b9b17debSTimur Tabi 
150b9b17debSTimur Tabi /* EMAC_MAILBOX_6 */
151b9b17debSTimur Tabi #define RFD2_PROC_IDX_BMSK                                   0xfff0000
152b9b17debSTimur Tabi #define RFD2_PROC_IDX_SHFT                                          16
153b9b17debSTimur Tabi #define RFD2_PROD_IDX_BMSK                                       0xfff
154b9b17debSTimur Tabi #define RFD2_PROD_IDX_SHFT                                           0
155b9b17debSTimur Tabi 
156b9b17debSTimur Tabi /* EMAC_CORE_HW_VERSION */
157b9b17debSTimur Tabi #define MAJOR_BMSK                                          0xf0000000
158b9b17debSTimur Tabi #define MAJOR_SHFT                                                  28
159b9b17debSTimur Tabi #define MINOR_BMSK                                           0xfff0000
160b9b17debSTimur Tabi #define MINOR_SHFT                                                  16
161b9b17debSTimur Tabi #define STEP_BMSK                                               0xffff
162b9b17debSTimur Tabi #define STEP_SHFT                                                    0
163b9b17debSTimur Tabi 
164b9b17debSTimur Tabi /* EMAC_EMAC_WRAPPER_CSR1 */
165b9b17debSTimur Tabi #define TX_INDX_FIFO_SYNC_RST                                  BIT(23)
166b9b17debSTimur Tabi #define TX_TS_FIFO_SYNC_RST                                    BIT(22)
167b9b17debSTimur Tabi #define RX_TS_FIFO2_SYNC_RST                                   BIT(21)
168b9b17debSTimur Tabi #define RX_TS_FIFO1_SYNC_RST                                   BIT(20)
169b9b17debSTimur Tabi #define TX_TS_ENABLE                                           BIT(16)
170b9b17debSTimur Tabi #define DIS_1588_CLKS                                          BIT(11)
171b9b17debSTimur Tabi #define FREQ_MODE                                               BIT(9)
172b9b17debSTimur Tabi #define ENABLE_RRD_TIMESTAMP                                    BIT(3)
173b9b17debSTimur Tabi 
174b9b17debSTimur Tabi /* EMAC_EMAC_WRAPPER_CSR2 */
175b9b17debSTimur Tabi #define HDRIVE_BMSK                                             0x3000
176b9b17debSTimur Tabi #define HDRIVE_SHFT                                                 12
177b9b17debSTimur Tabi #define SLB_EN                                                  BIT(9)
178b9b17debSTimur Tabi #define PLB_EN                                                  BIT(8)
179b9b17debSTimur Tabi #define WOL_EN                                                  BIT(3)
180b9b17debSTimur Tabi #define PHY_RESET                                               BIT(0)
181b9b17debSTimur Tabi 
182b9b17debSTimur Tabi #define EMAC_DEV_ID                                             0x0040
183b9b17debSTimur Tabi 
184b9b17debSTimur Tabi /* SGMII v2 per lane registers */
185b9b17debSTimur Tabi #define SGMII_LN_RSM_START             0x029C
186b9b17debSTimur Tabi 
187b9b17debSTimur Tabi /* SGMII v2 PHY common registers */
188b9b17debSTimur Tabi #define SGMII_PHY_CMN_CTRL            0x0408
189b9b17debSTimur Tabi #define SGMII_PHY_CMN_RESET_CTRL      0x0410
190b9b17debSTimur Tabi 
191b9b17debSTimur Tabi /* SGMII v2 PHY registers per lane */
192b9b17debSTimur Tabi #define SGMII_PHY_LN_OFFSET          0x0400
193b9b17debSTimur Tabi #define SGMII_PHY_LN_LANE_STATUS     0x00DC
194b9b17debSTimur Tabi #define SGMII_PHY_LN_BIST_GEN0       0x008C
195b9b17debSTimur Tabi #define SGMII_PHY_LN_BIST_GEN1       0x0090
196b9b17debSTimur Tabi #define SGMII_PHY_LN_BIST_GEN2       0x0094
197b9b17debSTimur Tabi #define SGMII_PHY_LN_BIST_GEN3       0x0098
198b9b17debSTimur Tabi #define SGMII_PHY_LN_CDR_CTRL1       0x005C
199b9b17debSTimur Tabi 
200b9b17debSTimur Tabi enum emac_clk_id {
201b9b17debSTimur Tabi 	EMAC_CLK_AXI,
202b9b17debSTimur Tabi 	EMAC_CLK_CFG_AHB,
203b9b17debSTimur Tabi 	EMAC_CLK_HIGH_SPEED,
204b9b17debSTimur Tabi 	EMAC_CLK_MDIO,
205b9b17debSTimur Tabi 	EMAC_CLK_TX,
206b9b17debSTimur Tabi 	EMAC_CLK_RX,
207b9b17debSTimur Tabi 	EMAC_CLK_SYS,
208b9b17debSTimur Tabi 	EMAC_CLK_CNT
209b9b17debSTimur Tabi };
210b9b17debSTimur Tabi 
211b9b17debSTimur Tabi #define EMAC_LINK_SPEED_UNKNOWN                                    0x0
212b9b17debSTimur Tabi #define EMAC_LINK_SPEED_10_HALF                                 BIT(0)
213b9b17debSTimur Tabi #define EMAC_LINK_SPEED_10_FULL                                 BIT(1)
214b9b17debSTimur Tabi #define EMAC_LINK_SPEED_100_HALF                                BIT(2)
215b9b17debSTimur Tabi #define EMAC_LINK_SPEED_100_FULL                                BIT(3)
216b9b17debSTimur Tabi #define EMAC_LINK_SPEED_1GB_FULL                                BIT(5)
217b9b17debSTimur Tabi 
218b9b17debSTimur Tabi #define EMAC_MAX_SETUP_LNK_CYCLE                                   100
219b9b17debSTimur Tabi 
220b9b17debSTimur Tabi struct emac_stats {
221b9b17debSTimur Tabi 	/* rx */
222b9b17debSTimur Tabi 	u64 rx_ok;              /* good packets */
223b9b17debSTimur Tabi 	u64 rx_bcast;           /* good broadcast packets */
224b9b17debSTimur Tabi 	u64 rx_mcast;           /* good multicast packets */
225b9b17debSTimur Tabi 	u64 rx_pause;           /* pause packet */
226b9b17debSTimur Tabi 	u64 rx_ctrl;            /* control packets other than pause frame. */
227b9b17debSTimur Tabi 	u64 rx_fcs_err;         /* packets with bad FCS. */
228b9b17debSTimur Tabi 	u64 rx_len_err;         /* packets with length mismatch */
229b9b17debSTimur Tabi 	u64 rx_byte_cnt;        /* good bytes count (without FCS) */
230b9b17debSTimur Tabi 	u64 rx_runt;            /* runt packets */
231b9b17debSTimur Tabi 	u64 rx_frag;            /* fragment count */
232b9b17debSTimur Tabi 	u64 rx_sz_64;	        /* packets that are 64 bytes */
233b9b17debSTimur Tabi 	u64 rx_sz_65_127;       /* packets that are 65-127 bytes */
234b9b17debSTimur Tabi 	u64 rx_sz_128_255;      /* packets that are 128-255 bytes */
235b9b17debSTimur Tabi 	u64 rx_sz_256_511;      /* packets that are 256-511 bytes */
236b9b17debSTimur Tabi 	u64 rx_sz_512_1023;     /* packets that are 512-1023 bytes */
237b9b17debSTimur Tabi 	u64 rx_sz_1024_1518;    /* packets that are 1024-1518 bytes */
238b9b17debSTimur Tabi 	u64 rx_sz_1519_max;     /* packets that are 1519-MTU bytes*/
239b9b17debSTimur Tabi 	u64 rx_sz_ov;           /* packets that are >MTU bytes (truncated) */
240b9b17debSTimur Tabi 	u64 rx_rxf_ov;          /* packets dropped due to RX FIFO overflow */
241b9b17debSTimur Tabi 	u64 rx_align_err;       /* alignment errors */
242b9b17debSTimur Tabi 	u64 rx_bcast_byte_cnt;  /* broadcast packets byte count (without FCS) */
243b9b17debSTimur Tabi 	u64 rx_mcast_byte_cnt;  /* multicast packets byte count (without FCS) */
244b9b17debSTimur Tabi 	u64 rx_err_addr;        /* packets dropped due to address filtering */
245b9b17debSTimur Tabi 	u64 rx_crc_align;       /* CRC align errors */
246b9b17debSTimur Tabi 	u64 rx_jabbers;         /* jabbers */
247b9b17debSTimur Tabi 
248b9b17debSTimur Tabi 	/* tx */
249b9b17debSTimur Tabi 	u64 tx_ok;              /* good packets */
250b9b17debSTimur Tabi 	u64 tx_bcast;           /* good broadcast packets */
251b9b17debSTimur Tabi 	u64 tx_mcast;           /* good multicast packets */
252b9b17debSTimur Tabi 	u64 tx_pause;           /* pause packets */
253b9b17debSTimur Tabi 	u64 tx_exc_defer;       /* packets with excessive deferral */
254b9b17debSTimur Tabi 	u64 tx_ctrl;            /* control packets other than pause frame */
255b9b17debSTimur Tabi 	u64 tx_defer;           /* packets that are deferred. */
256b9b17debSTimur Tabi 	u64 tx_byte_cnt;        /* good bytes count (without FCS) */
257b9b17debSTimur Tabi 	u64 tx_sz_64;           /* packets that are 64 bytes */
258b9b17debSTimur Tabi 	u64 tx_sz_65_127;       /* packets that are 65-127 bytes */
259b9b17debSTimur Tabi 	u64 tx_sz_128_255;      /* packets that are 128-255 bytes */
260b9b17debSTimur Tabi 	u64 tx_sz_256_511;      /* packets that are 256-511 bytes */
261b9b17debSTimur Tabi 	u64 tx_sz_512_1023;     /* packets that are 512-1023 bytes */
262b9b17debSTimur Tabi 	u64 tx_sz_1024_1518;    /* packets that are 1024-1518 bytes */
263b9b17debSTimur Tabi 	u64 tx_sz_1519_max;     /* packets that are 1519-MTU bytes */
264b9b17debSTimur Tabi 	u64 tx_1_col;           /* packets single prior collision */
265b9b17debSTimur Tabi 	u64 tx_2_col;           /* packets with multiple prior collisions */
266b9b17debSTimur Tabi 	u64 tx_late_col;        /* packets with late collisions */
267b9b17debSTimur Tabi 	u64 tx_abort_col;       /* packets aborted due to excess collisions */
268b9b17debSTimur Tabi 	u64 tx_underrun;        /* packets aborted due to FIFO underrun */
269b9b17debSTimur Tabi 	u64 tx_rd_eop;          /* count of reads beyond EOP */
270b9b17debSTimur Tabi 	u64 tx_len_err;         /* packets with length mismatch */
271b9b17debSTimur Tabi 	u64 tx_trunc;           /* packets truncated due to size >MTU */
272b9b17debSTimur Tabi 	u64 tx_bcast_byte;      /* broadcast packets byte count (without FCS) */
273b9b17debSTimur Tabi 	u64 tx_mcast_byte;      /* multicast packets byte count (without FCS) */
274b9b17debSTimur Tabi 	u64 tx_col;             /* collisions */
275b9b17debSTimur Tabi 
276b9b17debSTimur Tabi 	spinlock_t lock;	/* prevent multiple simultaneous readers */
277b9b17debSTimur Tabi };
278b9b17debSTimur Tabi 
279b9b17debSTimur Tabi /* RSS hstype Definitions */
280b9b17debSTimur Tabi #define EMAC_RSS_HSTYP_IPV4_EN				    0x00000001
281b9b17debSTimur Tabi #define EMAC_RSS_HSTYP_TCP4_EN				    0x00000002
282b9b17debSTimur Tabi #define EMAC_RSS_HSTYP_IPV6_EN				    0x00000004
283b9b17debSTimur Tabi #define EMAC_RSS_HSTYP_TCP6_EN				    0x00000008
284b9b17debSTimur Tabi #define EMAC_RSS_HSTYP_ALL_EN (\
285b9b17debSTimur Tabi 		EMAC_RSS_HSTYP_IPV4_EN   |\
286b9b17debSTimur Tabi 		EMAC_RSS_HSTYP_TCP4_EN   |\
287b9b17debSTimur Tabi 		EMAC_RSS_HSTYP_IPV6_EN   |\
288b9b17debSTimur Tabi 		EMAC_RSS_HSTYP_TCP6_EN)
289b9b17debSTimur Tabi 
290b9b17debSTimur Tabi #define EMAC_VLAN_TO_TAG(_vlan, _tag) \
291b9b17debSTimur Tabi 		(_tag =  ((((_vlan) >> 8) & 0xFF) | (((_vlan) & 0xFF) << 8)))
292b9b17debSTimur Tabi 
293b9b17debSTimur Tabi #define EMAC_TAG_TO_VLAN(_tag, _vlan) \
294b9b17debSTimur Tabi 		(_vlan = ((((_tag) >> 8) & 0xFF) | (((_tag) & 0xFF) << 8)))
295b9b17debSTimur Tabi 
296b9b17debSTimur Tabi #define EMAC_DEF_RX_BUF_SIZE					  1536
297b9b17debSTimur Tabi #define EMAC_MAX_JUMBO_PKT_SIZE				    (9 * 1024)
298b9b17debSTimur Tabi #define EMAC_MAX_TX_OFFLOAD_THRESH			    (9 * 1024)
299b9b17debSTimur Tabi 
300b9b17debSTimur Tabi #define EMAC_MAX_ETH_FRAME_SIZE		       EMAC_MAX_JUMBO_PKT_SIZE
301b9b17debSTimur Tabi #define EMAC_MIN_ETH_FRAME_SIZE					    68
302b9b17debSTimur Tabi 
303b9b17debSTimur Tabi #define EMAC_DEF_TX_QUEUES					     1
304b9b17debSTimur Tabi #define EMAC_DEF_RX_QUEUES					     1
305b9b17debSTimur Tabi 
306b9b17debSTimur Tabi #define EMAC_MIN_TX_DESCS					   128
307b9b17debSTimur Tabi #define EMAC_MIN_RX_DESCS					   128
308b9b17debSTimur Tabi 
309b9b17debSTimur Tabi #define EMAC_MAX_TX_DESCS					 16383
310b9b17debSTimur Tabi #define EMAC_MAX_RX_DESCS					  2047
311b9b17debSTimur Tabi 
312b9b17debSTimur Tabi #define EMAC_DEF_TX_DESCS					   512
313b9b17debSTimur Tabi #define EMAC_DEF_RX_DESCS					   256
314b9b17debSTimur Tabi 
315b9b17debSTimur Tabi #define EMAC_DEF_RX_IRQ_MOD					   250
316b9b17debSTimur Tabi #define EMAC_DEF_TX_IRQ_MOD					   250
317b9b17debSTimur Tabi 
318b9b17debSTimur Tabi #define EMAC_WATCHDOG_TIME				      (5 * HZ)
319b9b17debSTimur Tabi 
320b9b17debSTimur Tabi /* by default check link every 4 seconds */
321b9b17debSTimur Tabi #define EMAC_TRY_LINK_TIMEOUT				      (4 * HZ)
322b9b17debSTimur Tabi 
323b9b17debSTimur Tabi /* emac_irq per-device (per-adapter) irq properties.
324b9b17debSTimur Tabi  * @irq:	irq number.
325b9b17debSTimur Tabi  * @mask	mask to use over status register.
326b9b17debSTimur Tabi  */
327b9b17debSTimur Tabi struct emac_irq {
328b9b17debSTimur Tabi 	unsigned int	irq;
329b9b17debSTimur Tabi 	u32		mask;
330b9b17debSTimur Tabi };
331b9b17debSTimur Tabi 
332b9b17debSTimur Tabi /* The device's main data structure */
333b9b17debSTimur Tabi struct emac_adapter {
334b9b17debSTimur Tabi 	struct net_device		*netdev;
335b9b17debSTimur Tabi 	struct mii_bus			*mii_bus;
336b9b17debSTimur Tabi 	struct phy_device		*phydev;
337b9b17debSTimur Tabi 
338b9b17debSTimur Tabi 	void __iomem			*base;
339b9b17debSTimur Tabi 	void __iomem			*csr;
340b9b17debSTimur Tabi 
34141c1093fSTimur Tabi 	struct emac_sgmii		phy;
342b9b17debSTimur Tabi 	struct emac_stats		stats;
343b9b17debSTimur Tabi 
344b9b17debSTimur Tabi 	struct emac_irq			irq;
345b9b17debSTimur Tabi 	struct clk			*clk[EMAC_CLK_CNT];
346b9b17debSTimur Tabi 
347b9b17debSTimur Tabi 	/* All Descriptor memory */
348b9b17debSTimur Tabi 	struct emac_ring_header		ring_header;
349b9b17debSTimur Tabi 	struct emac_tx_queue		tx_q;
350b9b17debSTimur Tabi 	struct emac_rx_queue		rx_q;
351b9b17debSTimur Tabi 	unsigned int			tx_desc_cnt;
352b9b17debSTimur Tabi 	unsigned int			rx_desc_cnt;
353b9b17debSTimur Tabi 	unsigned int			rrd_size; /* in quad words */
354b9b17debSTimur Tabi 	unsigned int			rfd_size; /* in quad words */
355b9b17debSTimur Tabi 	unsigned int			tpd_size; /* in quad words */
356b9b17debSTimur Tabi 
357b9b17debSTimur Tabi 	unsigned int			rxbuf_size;
358b9b17debSTimur Tabi 
359b44700e9STimur Tabi 	/* Flow control / pause frames support. If automatic=True, do whatever
360b44700e9STimur Tabi 	 * the PHY does. Otherwise, use tx_flow_control and rx_flow_control.
361b44700e9STimur Tabi 	 */
362b44700e9STimur Tabi 	bool				automatic;
363b44700e9STimur Tabi 	bool				tx_flow_control;
364b44700e9STimur Tabi 	bool				rx_flow_control;
365b44700e9STimur Tabi 
366b9b17debSTimur Tabi 	/* Ring parameter */
367b9b17debSTimur Tabi 	u8				tpd_burst;
368b9b17debSTimur Tabi 	u8				rfd_burst;
369b9b17debSTimur Tabi 	unsigned int			dmaw_dly_cnt;
370b9b17debSTimur Tabi 	unsigned int			dmar_dly_cnt;
371b9b17debSTimur Tabi 	enum emac_dma_req_block		dmar_block;
372b9b17debSTimur Tabi 	enum emac_dma_req_block		dmaw_block;
373b9b17debSTimur Tabi 	enum emac_dma_order		dma_order;
374b9b17debSTimur Tabi 
375b9b17debSTimur Tabi 	u32				irq_mod;
376b9b17debSTimur Tabi 	u32				preamble;
377b9b17debSTimur Tabi 
378b9b17debSTimur Tabi 	struct work_struct		work_thread;
379b9b17debSTimur Tabi 
380b9b17debSTimur Tabi 	u16				msg_enable;
381b9b17debSTimur Tabi 
382b9b17debSTimur Tabi 	struct mutex			reset_lock;
383b9b17debSTimur Tabi };
384b9b17debSTimur Tabi 
385b9b17debSTimur Tabi int emac_reinit_locked(struct emac_adapter *adpt);
386b9b17debSTimur Tabi void emac_reg_update32(void __iomem *addr, u32 mask, u32 val);
387b9b17debSTimur Tabi 
38879f664edSTimur Tabi void emac_set_ethtool_ops(struct net_device *netdev);
38979f664edSTimur Tabi void emac_update_hw_stats(struct emac_adapter *adpt);
39079f664edSTimur Tabi 
391b9b17debSTimur Tabi #endif /* _EMAC_H_ */
392