xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/xilinx/xilinx_axienet.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Definitions for Xilinx Axi Ethernet device driver.
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2009 Secret Lab Technologies, Ltd.
6*4882a593Smuzhiyun  * Copyright (c) 2010 - 2012 Xilinx, Inc. All rights reserved.
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef XILINX_AXIENET_H
10*4882a593Smuzhiyun #define XILINX_AXIENET_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/netdevice.h>
13*4882a593Smuzhiyun #include <linux/spinlock.h>
14*4882a593Smuzhiyun #include <linux/interrupt.h>
15*4882a593Smuzhiyun #include <linux/if_vlan.h>
16*4882a593Smuzhiyun #include <linux/phylink.h>
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun /* Packet size info */
19*4882a593Smuzhiyun #define XAE_HDR_SIZE			14 /* Size of Ethernet header */
20*4882a593Smuzhiyun #define XAE_TRL_SIZE			 4 /* Size of Ethernet trailer (FCS) */
21*4882a593Smuzhiyun #define XAE_MTU			      1500 /* Max MTU of an Ethernet frame */
22*4882a593Smuzhiyun #define XAE_JUMBO_MTU		      9000 /* Max MTU of a jumbo Eth. frame */
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define XAE_MAX_FRAME_SIZE	 (XAE_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
25*4882a593Smuzhiyun #define XAE_MAX_VLAN_FRAME_SIZE  (XAE_MTU + VLAN_ETH_HLEN + XAE_TRL_SIZE)
26*4882a593Smuzhiyun #define XAE_MAX_JUMBO_FRAME_SIZE (XAE_JUMBO_MTU + XAE_HDR_SIZE + XAE_TRL_SIZE)
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /* Configuration options */
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun /* Accept all incoming packets. Default: disabled (cleared) */
31*4882a593Smuzhiyun #define XAE_OPTION_PROMISC			(1 << 0)
32*4882a593Smuzhiyun 
33*4882a593Smuzhiyun /* Jumbo frame support for Tx & Rx. Default: disabled (cleared) */
34*4882a593Smuzhiyun #define XAE_OPTION_JUMBO			(1 << 1)
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun /* VLAN Rx & Tx frame support. Default: disabled (cleared) */
37*4882a593Smuzhiyun #define XAE_OPTION_VLAN				(1 << 2)
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /* Enable recognition of flow control frames on Rx. Default: enabled (set) */
40*4882a593Smuzhiyun #define XAE_OPTION_FLOW_CONTROL			(1 << 4)
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun /* Strip FCS and PAD from incoming frames. Note: PAD from VLAN frames is not
43*4882a593Smuzhiyun  * stripped. Default: disabled (set)
44*4882a593Smuzhiyun  */
45*4882a593Smuzhiyun #define XAE_OPTION_FCS_STRIP			(1 << 5)
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /* Generate FCS field and add PAD automatically for outgoing frames.
48*4882a593Smuzhiyun  * Default: enabled (set)
49*4882a593Smuzhiyun  */
50*4882a593Smuzhiyun #define XAE_OPTION_FCS_INSERT			(1 << 6)
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /* Enable Length/Type error checking for incoming frames. When this option is
53*4882a593Smuzhiyun  * set, the MAC will filter frames that have a mismatched type/length field
54*4882a593Smuzhiyun  * and if XAE_OPTION_REPORT_RXERR is set, the user is notified when these
55*4882a593Smuzhiyun  * types of frames are encountered. When this option is cleared, the MAC will
56*4882a593Smuzhiyun  * allow these types of frames to be received. Default: enabled (set)
57*4882a593Smuzhiyun  */
58*4882a593Smuzhiyun #define XAE_OPTION_LENTYPE_ERR			(1 << 7)
59*4882a593Smuzhiyun 
60*4882a593Smuzhiyun /* Enable the transmitter. Default: enabled (set) */
61*4882a593Smuzhiyun #define XAE_OPTION_TXEN				(1 << 11)
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /*  Enable the receiver. Default: enabled (set) */
64*4882a593Smuzhiyun #define XAE_OPTION_RXEN				(1 << 12)
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /*  Default options set when device is initialized or reset */
67*4882a593Smuzhiyun #define XAE_OPTION_DEFAULTS				   \
68*4882a593Smuzhiyun 				(XAE_OPTION_TXEN |	   \
69*4882a593Smuzhiyun 				 XAE_OPTION_FLOW_CONTROL | \
70*4882a593Smuzhiyun 				 XAE_OPTION_RXEN)
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /* Axi DMA Register definitions */
73*4882a593Smuzhiyun 
74*4882a593Smuzhiyun #define XAXIDMA_TX_CR_OFFSET	0x00000000 /* Channel control */
75*4882a593Smuzhiyun #define XAXIDMA_TX_SR_OFFSET	0x00000004 /* Status */
76*4882a593Smuzhiyun #define XAXIDMA_TX_CDESC_OFFSET	0x00000008 /* Current descriptor pointer */
77*4882a593Smuzhiyun #define XAXIDMA_TX_TDESC_OFFSET	0x00000010 /* Tail descriptor pointer */
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #define XAXIDMA_RX_CR_OFFSET	0x00000030 /* Channel control */
80*4882a593Smuzhiyun #define XAXIDMA_RX_SR_OFFSET	0x00000034 /* Status */
81*4882a593Smuzhiyun #define XAXIDMA_RX_CDESC_OFFSET	0x00000038 /* Current descriptor pointer */
82*4882a593Smuzhiyun #define XAXIDMA_RX_TDESC_OFFSET	0x00000040 /* Tail descriptor pointer */
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun #define XAXIDMA_CR_RUNSTOP_MASK	0x00000001 /* Start/stop DMA channel */
85*4882a593Smuzhiyun #define XAXIDMA_CR_RESET_MASK	0x00000004 /* Reset DMA engine */
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun #define XAXIDMA_SR_HALT_MASK	0x00000001 /* Indicates DMA channel halted */
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun #define XAXIDMA_BD_NDESC_OFFSET		0x00 /* Next descriptor pointer */
90*4882a593Smuzhiyun #define XAXIDMA_BD_BUFA_OFFSET		0x08 /* Buffer address */
91*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_LEN_OFFSET	0x18 /* Control/buffer length */
92*4882a593Smuzhiyun #define XAXIDMA_BD_STS_OFFSET		0x1C /* Status */
93*4882a593Smuzhiyun #define XAXIDMA_BD_USR0_OFFSET		0x20 /* User IP specific word0 */
94*4882a593Smuzhiyun #define XAXIDMA_BD_USR1_OFFSET		0x24 /* User IP specific word1 */
95*4882a593Smuzhiyun #define XAXIDMA_BD_USR2_OFFSET		0x28 /* User IP specific word2 */
96*4882a593Smuzhiyun #define XAXIDMA_BD_USR3_OFFSET		0x2C /* User IP specific word3 */
97*4882a593Smuzhiyun #define XAXIDMA_BD_USR4_OFFSET		0x30 /* User IP specific word4 */
98*4882a593Smuzhiyun #define XAXIDMA_BD_ID_OFFSET		0x34 /* Sw ID */
99*4882a593Smuzhiyun #define XAXIDMA_BD_HAS_STSCNTRL_OFFSET	0x38 /* Whether has stscntrl strm */
100*4882a593Smuzhiyun #define XAXIDMA_BD_HAS_DRE_OFFSET	0x3C /* Whether has DRE */
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #define XAXIDMA_BD_HAS_DRE_SHIFT	8 /* Whether has DRE shift */
103*4882a593Smuzhiyun #define XAXIDMA_BD_HAS_DRE_MASK		0xF00 /* Whether has DRE mask */
104*4882a593Smuzhiyun #define XAXIDMA_BD_WORDLEN_MASK		0xFF /* Whether has DRE mask */
105*4882a593Smuzhiyun 
106*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_LENGTH_MASK	0x007FFFFF /* Requested len */
107*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_TXSOF_MASK	0x08000000 /* First tx packet */
108*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet */
109*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun #define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout counter */
112*4882a593Smuzhiyun #define XAXIDMA_COALESCE_MASK		0x00FF0000 /* Coalesce counter */
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #define XAXIDMA_DELAY_SHIFT		24
115*4882a593Smuzhiyun #define XAXIDMA_COALESCE_SHIFT		16
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun #define XAXIDMA_IRQ_IOC_MASK		0x00001000 /* Completion intr */
118*4882a593Smuzhiyun #define XAXIDMA_IRQ_DELAY_MASK		0x00002000 /* Delay interrupt */
119*4882a593Smuzhiyun #define XAXIDMA_IRQ_ERROR_MASK		0x00004000 /* Error interrupt */
120*4882a593Smuzhiyun #define XAXIDMA_IRQ_ALL_MASK		0x00007000 /* All interrupts */
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /* Default TX/RX Threshold and waitbound values for SGDMA mode */
123*4882a593Smuzhiyun #define XAXIDMA_DFT_TX_THRESHOLD	24
124*4882a593Smuzhiyun #define XAXIDMA_DFT_TX_WAITBOUND	254
125*4882a593Smuzhiyun #define XAXIDMA_DFT_RX_THRESHOLD	24
126*4882a593Smuzhiyun #define XAXIDMA_DFT_RX_WAITBOUND	254
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_TXSOF_MASK	0x08000000 /* First tx packet */
129*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet */
130*4882a593Smuzhiyun #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits */
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun #define XAXIDMA_BD_STS_ACTUAL_LEN_MASK	0x007FFFFF /* Actual len */
133*4882a593Smuzhiyun #define XAXIDMA_BD_STS_COMPLETE_MASK	0x80000000 /* Completed */
134*4882a593Smuzhiyun #define XAXIDMA_BD_STS_DEC_ERR_MASK	0x40000000 /* Decode error */
135*4882a593Smuzhiyun #define XAXIDMA_BD_STS_SLV_ERR_MASK	0x20000000 /* Slave error */
136*4882a593Smuzhiyun #define XAXIDMA_BD_STS_INT_ERR_MASK	0x10000000 /* Internal err */
137*4882a593Smuzhiyun #define XAXIDMA_BD_STS_ALL_ERR_MASK	0x70000000 /* All errors */
138*4882a593Smuzhiyun #define XAXIDMA_BD_STS_RXSOF_MASK	0x08000000 /* First rx pkt */
139*4882a593Smuzhiyun #define XAXIDMA_BD_STS_RXEOF_MASK	0x04000000 /* Last rx pkt */
140*4882a593Smuzhiyun #define XAXIDMA_BD_STS_ALL_MASK		0xFC000000 /* All status bits */
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun #define XAXIDMA_BD_MINIMUM_ALIGNMENT	0x40
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /* Axi Ethernet registers definition */
145*4882a593Smuzhiyun #define XAE_RAF_OFFSET		0x00000000 /* Reset and Address filter */
146*4882a593Smuzhiyun #define XAE_TPF_OFFSET		0x00000004 /* Tx Pause Frame */
147*4882a593Smuzhiyun #define XAE_IFGP_OFFSET		0x00000008 /* Tx Inter-frame gap adjustment*/
148*4882a593Smuzhiyun #define XAE_IS_OFFSET		0x0000000C /* Interrupt status */
149*4882a593Smuzhiyun #define XAE_IP_OFFSET		0x00000010 /* Interrupt pending */
150*4882a593Smuzhiyun #define XAE_IE_OFFSET		0x00000014 /* Interrupt enable */
151*4882a593Smuzhiyun #define XAE_TTAG_OFFSET		0x00000018 /* Tx VLAN TAG */
152*4882a593Smuzhiyun #define XAE_RTAG_OFFSET		0x0000001C /* Rx VLAN TAG */
153*4882a593Smuzhiyun #define XAE_UAWL_OFFSET		0x00000020 /* Unicast address word lower */
154*4882a593Smuzhiyun #define XAE_UAWU_OFFSET		0x00000024 /* Unicast address word upper */
155*4882a593Smuzhiyun #define XAE_TPID0_OFFSET	0x00000028 /* VLAN TPID0 register */
156*4882a593Smuzhiyun #define XAE_TPID1_OFFSET	0x0000002C /* VLAN TPID1 register */
157*4882a593Smuzhiyun #define XAE_PPST_OFFSET		0x00000030 /* PCS PMA Soft Temac Status Reg */
158*4882a593Smuzhiyun #define XAE_RCW0_OFFSET		0x00000400 /* Rx Configuration Word 0 */
159*4882a593Smuzhiyun #define XAE_RCW1_OFFSET		0x00000404 /* Rx Configuration Word 1 */
160*4882a593Smuzhiyun #define XAE_TC_OFFSET		0x00000408 /* Tx Configuration */
161*4882a593Smuzhiyun #define XAE_FCC_OFFSET		0x0000040C /* Flow Control Configuration */
162*4882a593Smuzhiyun #define XAE_EMMC_OFFSET		0x00000410 /* EMAC mode configuration */
163*4882a593Smuzhiyun #define XAE_PHYC_OFFSET		0x00000414 /* RGMII/SGMII configuration */
164*4882a593Smuzhiyun #define XAE_ID_OFFSET		0x000004F8 /* Identification register */
165*4882a593Smuzhiyun #define XAE_MDIO_MC_OFFSET	0x00000500 /* MII Management Config */
166*4882a593Smuzhiyun #define XAE_MDIO_MCR_OFFSET	0x00000504 /* MII Management Control */
167*4882a593Smuzhiyun #define XAE_MDIO_MWD_OFFSET	0x00000508 /* MII Management Write Data */
168*4882a593Smuzhiyun #define XAE_MDIO_MRD_OFFSET	0x0000050C /* MII Management Read Data */
169*4882a593Smuzhiyun #define XAE_UAW0_OFFSET		0x00000700 /* Unicast address word 0 */
170*4882a593Smuzhiyun #define XAE_UAW1_OFFSET		0x00000704 /* Unicast address word 1 */
171*4882a593Smuzhiyun #define XAE_FMI_OFFSET		0x00000708 /* Filter Mask Index */
172*4882a593Smuzhiyun #define XAE_AF0_OFFSET		0x00000710 /* Address Filter 0 */
173*4882a593Smuzhiyun #define XAE_AF1_OFFSET		0x00000714 /* Address Filter 1 */
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun #define XAE_TX_VLAN_DATA_OFFSET 0x00004000 /* TX VLAN data table address */
176*4882a593Smuzhiyun #define XAE_RX_VLAN_DATA_OFFSET 0x00008000 /* RX VLAN data table address */
177*4882a593Smuzhiyun #define XAE_MCAST_TABLE_OFFSET	0x00020000 /* Multicast table address */
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /* Bit Masks for Axi Ethernet RAF register */
180*4882a593Smuzhiyun /* Reject receive multicast destination address */
181*4882a593Smuzhiyun #define XAE_RAF_MCSTREJ_MASK		0x00000002
182*4882a593Smuzhiyun /* Reject receive broadcast destination address */
183*4882a593Smuzhiyun #define XAE_RAF_BCSTREJ_MASK		0x00000004
184*4882a593Smuzhiyun #define XAE_RAF_TXVTAGMODE_MASK		0x00000018 /* Tx VLAN TAG mode */
185*4882a593Smuzhiyun #define XAE_RAF_RXVTAGMODE_MASK		0x00000060 /* Rx VLAN TAG mode */
186*4882a593Smuzhiyun #define XAE_RAF_TXVSTRPMODE_MASK	0x00000180 /* Tx VLAN STRIP mode */
187*4882a593Smuzhiyun #define XAE_RAF_RXVSTRPMODE_MASK	0x00000600 /* Rx VLAN STRIP mode */
188*4882a593Smuzhiyun #define XAE_RAF_NEWFNCENBL_MASK		0x00000800 /* New function mode */
189*4882a593Smuzhiyun /* Extended Multicast Filtering mode */
190*4882a593Smuzhiyun #define XAE_RAF_EMULTIFLTRENBL_MASK	0x00001000
191*4882a593Smuzhiyun #define XAE_RAF_STATSRST_MASK		0x00002000 /* Stats. Counter Reset */
192*4882a593Smuzhiyun #define XAE_RAF_RXBADFRMEN_MASK		0x00004000 /* Recv Bad Frame Enable */
193*4882a593Smuzhiyun #define XAE_RAF_TXVTAGMODE_SHIFT	3 /* Tx Tag mode shift bits */
194*4882a593Smuzhiyun #define XAE_RAF_RXVTAGMODE_SHIFT	5 /* Rx Tag mode shift bits */
195*4882a593Smuzhiyun #define XAE_RAF_TXVSTRPMODE_SHIFT	7 /* Tx strip mode shift bits*/
196*4882a593Smuzhiyun #define XAE_RAF_RXVSTRPMODE_SHIFT	9 /* Rx Strip mode shift bits*/
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun /* Bit Masks for Axi Ethernet TPF and IFGP registers */
199*4882a593Smuzhiyun #define XAE_TPF_TPFV_MASK		0x0000FFFF /* Tx pause frame value */
200*4882a593Smuzhiyun /* Transmit inter-frame gap adjustment value */
201*4882a593Smuzhiyun #define XAE_IFGP0_IFGP_MASK		0x0000007F
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun /* Bit Masks for Axi Ethernet IS, IE and IP registers, Same masks apply
204*4882a593Smuzhiyun  * for all 3 registers.
205*4882a593Smuzhiyun  */
206*4882a593Smuzhiyun /* Hard register access complete */
207*4882a593Smuzhiyun #define XAE_INT_HARDACSCMPLT_MASK	0x00000001
208*4882a593Smuzhiyun /* Auto negotiation complete */
209*4882a593Smuzhiyun #define XAE_INT_AUTONEG_MASK		0x00000002
210*4882a593Smuzhiyun #define XAE_INT_RXCMPIT_MASK		0x00000004 /* Rx complete */
211*4882a593Smuzhiyun #define XAE_INT_RXRJECT_MASK		0x00000008 /* Rx frame rejected */
212*4882a593Smuzhiyun #define XAE_INT_RXFIFOOVR_MASK		0x00000010 /* Rx fifo overrun */
213*4882a593Smuzhiyun #define XAE_INT_TXCMPIT_MASK		0x00000020 /* Tx complete */
214*4882a593Smuzhiyun #define XAE_INT_RXDCMLOCK_MASK		0x00000040 /* Rx Dcm Lock */
215*4882a593Smuzhiyun #define XAE_INT_MGTRDY_MASK		0x00000080 /* MGT clock Lock */
216*4882a593Smuzhiyun #define XAE_INT_PHYRSTCMPLT_MASK	0x00000100 /* Phy Reset complete */
217*4882a593Smuzhiyun #define XAE_INT_ALL_MASK		0x0000003F /* All the ints */
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun /* INT bits that indicate receive errors */
220*4882a593Smuzhiyun #define XAE_INT_RECV_ERROR_MASK				\
221*4882a593Smuzhiyun 	(XAE_INT_RXRJECT_MASK | XAE_INT_RXFIFOOVR_MASK)
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun /* Bit masks for Axi Ethernet VLAN TPID Word 0 register */
224*4882a593Smuzhiyun #define XAE_TPID_0_MASK		0x0000FFFF /* TPID 0 */
225*4882a593Smuzhiyun #define XAE_TPID_1_MASK		0xFFFF0000 /* TPID 1 */
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun /* Bit masks for Axi Ethernet VLAN TPID Word 1 register */
228*4882a593Smuzhiyun #define XAE_TPID_2_MASK		0x0000FFFF /* TPID 0 */
229*4882a593Smuzhiyun #define XAE_TPID_3_MASK		0xFFFF0000 /* TPID 1 */
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun /* Bit masks for Axi Ethernet RCW1 register */
232*4882a593Smuzhiyun #define XAE_RCW1_RST_MASK	0x80000000 /* Reset */
233*4882a593Smuzhiyun #define XAE_RCW1_JUM_MASK	0x40000000 /* Jumbo frame enable */
234*4882a593Smuzhiyun /* In-Band FCS enable (FCS not stripped) */
235*4882a593Smuzhiyun #define XAE_RCW1_FCS_MASK	0x20000000
236*4882a593Smuzhiyun #define XAE_RCW1_RX_MASK	0x10000000 /* Receiver enable */
237*4882a593Smuzhiyun #define XAE_RCW1_VLAN_MASK	0x08000000 /* VLAN frame enable */
238*4882a593Smuzhiyun /* Length/type field valid check disable */
239*4882a593Smuzhiyun #define XAE_RCW1_LT_DIS_MASK	0x02000000
240*4882a593Smuzhiyun /* Control frame Length check disable */
241*4882a593Smuzhiyun #define XAE_RCW1_CL_DIS_MASK	0x01000000
242*4882a593Smuzhiyun /* Pause frame source address bits [47:32]. Bits [31:0] are
243*4882a593Smuzhiyun  * stored in register RCW0
244*4882a593Smuzhiyun  */
245*4882a593Smuzhiyun #define XAE_RCW1_PAUSEADDR_MASK 0x0000FFFF
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun /* Bit masks for Axi Ethernet TC register */
248*4882a593Smuzhiyun #define XAE_TC_RST_MASK		0x80000000 /* Reset */
249*4882a593Smuzhiyun #define XAE_TC_JUM_MASK		0x40000000 /* Jumbo frame enable */
250*4882a593Smuzhiyun /* In-Band FCS enable (FCS not generated) */
251*4882a593Smuzhiyun #define XAE_TC_FCS_MASK		0x20000000
252*4882a593Smuzhiyun #define XAE_TC_TX_MASK		0x10000000 /* Transmitter enable */
253*4882a593Smuzhiyun #define XAE_TC_VLAN_MASK	0x08000000 /* VLAN frame enable */
254*4882a593Smuzhiyun /* Inter-frame gap adjustment enable */
255*4882a593Smuzhiyun #define XAE_TC_IFG_MASK		0x02000000
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun /* Bit masks for Axi Ethernet FCC register */
258*4882a593Smuzhiyun #define XAE_FCC_FCRX_MASK	0x20000000 /* Rx flow control enable */
259*4882a593Smuzhiyun #define XAE_FCC_FCTX_MASK	0x40000000 /* Tx flow control enable */
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun /* Bit masks for Axi Ethernet EMMC register */
262*4882a593Smuzhiyun #define XAE_EMMC_LINKSPEED_MASK	0xC0000000 /* Link speed */
263*4882a593Smuzhiyun #define XAE_EMMC_RGMII_MASK	0x20000000 /* RGMII mode enable */
264*4882a593Smuzhiyun #define XAE_EMMC_SGMII_MASK	0x10000000 /* SGMII mode enable */
265*4882a593Smuzhiyun #define XAE_EMMC_GPCS_MASK	0x08000000 /* 1000BaseX mode enable */
266*4882a593Smuzhiyun #define XAE_EMMC_HOST_MASK	0x04000000 /* Host interface enable */
267*4882a593Smuzhiyun #define XAE_EMMC_TX16BIT	0x02000000 /* 16 bit Tx client enable */
268*4882a593Smuzhiyun #define XAE_EMMC_RX16BIT	0x01000000 /* 16 bit Rx client enable */
269*4882a593Smuzhiyun #define XAE_EMMC_LINKSPD_10	0x00000000 /* Link Speed mask for 10 Mbit */
270*4882a593Smuzhiyun #define XAE_EMMC_LINKSPD_100	0x40000000 /* Link Speed mask for 100 Mbit */
271*4882a593Smuzhiyun #define XAE_EMMC_LINKSPD_1000	0x80000000 /* Link Speed mask for 1000 Mbit */
272*4882a593Smuzhiyun 
273*4882a593Smuzhiyun /* Bit masks for Axi Ethernet PHYC register */
274*4882a593Smuzhiyun #define XAE_PHYC_SGMIILINKSPEED_MASK	0xC0000000 /* SGMII link speed mask*/
275*4882a593Smuzhiyun #define XAE_PHYC_RGMIILINKSPEED_MASK	0x0000000C /* RGMII link speed */
276*4882a593Smuzhiyun #define XAE_PHYC_RGMIIHD_MASK		0x00000002 /* RGMII Half-duplex */
277*4882a593Smuzhiyun #define XAE_PHYC_RGMIILINK_MASK		0x00000001 /* RGMII link status */
278*4882a593Smuzhiyun #define XAE_PHYC_RGLINKSPD_10		0x00000000 /* RGMII link 10 Mbit */
279*4882a593Smuzhiyun #define XAE_PHYC_RGLINKSPD_100		0x00000004 /* RGMII link 100 Mbit */
280*4882a593Smuzhiyun #define XAE_PHYC_RGLINKSPD_1000		0x00000008 /* RGMII link 1000 Mbit */
281*4882a593Smuzhiyun #define XAE_PHYC_SGLINKSPD_10		0x00000000 /* SGMII link 10 Mbit */
282*4882a593Smuzhiyun #define XAE_PHYC_SGLINKSPD_100		0x40000000 /* SGMII link 100 Mbit */
283*4882a593Smuzhiyun #define XAE_PHYC_SGLINKSPD_1000		0x80000000 /* SGMII link 1000 Mbit */
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun /* Bit masks for Axi Ethernet MDIO interface MC register */
286*4882a593Smuzhiyun #define XAE_MDIO_MC_MDIOEN_MASK		0x00000040 /* MII management enable */
287*4882a593Smuzhiyun #define XAE_MDIO_MC_CLOCK_DIVIDE_MAX	0x3F	   /* Maximum MDIO divisor */
288*4882a593Smuzhiyun 
289*4882a593Smuzhiyun /* Bit masks for Axi Ethernet MDIO interface MCR register */
290*4882a593Smuzhiyun #define XAE_MDIO_MCR_PHYAD_MASK		0x1F000000 /* Phy Address Mask */
291*4882a593Smuzhiyun #define XAE_MDIO_MCR_PHYAD_SHIFT	24	   /* Phy Address Shift */
292*4882a593Smuzhiyun #define XAE_MDIO_MCR_REGAD_MASK		0x001F0000 /* Reg Address Mask */
293*4882a593Smuzhiyun #define XAE_MDIO_MCR_REGAD_SHIFT	16	   /* Reg Address Shift */
294*4882a593Smuzhiyun #define XAE_MDIO_MCR_OP_MASK		0x0000C000 /* Operation Code Mask */
295*4882a593Smuzhiyun #define XAE_MDIO_MCR_OP_SHIFT		13	   /* Operation Code Shift */
296*4882a593Smuzhiyun #define XAE_MDIO_MCR_OP_READ_MASK	0x00008000 /* Op Code Read Mask */
297*4882a593Smuzhiyun #define XAE_MDIO_MCR_OP_WRITE_MASK	0x00004000 /* Op Code Write Mask */
298*4882a593Smuzhiyun #define XAE_MDIO_MCR_INITIATE_MASK	0x00000800 /* Ready Mask */
299*4882a593Smuzhiyun #define XAE_MDIO_MCR_READY_MASK		0x00000080 /* Ready Mask */
300*4882a593Smuzhiyun 
301*4882a593Smuzhiyun /* Bit masks for Axi Ethernet MDIO interface MIS, MIP, MIE, MIC registers */
302*4882a593Smuzhiyun #define XAE_MDIO_INT_MIIM_RDY_MASK	0x00000001 /* MIIM Interrupt */
303*4882a593Smuzhiyun 
304*4882a593Smuzhiyun /* Bit masks for Axi Ethernet UAW1 register */
305*4882a593Smuzhiyun /* Station address bits [47:32]; Station address
306*4882a593Smuzhiyun  * bits [31:0] are stored in register UAW0
307*4882a593Smuzhiyun  */
308*4882a593Smuzhiyun #define XAE_UAW1_UNICASTADDR_MASK	0x0000FFFF
309*4882a593Smuzhiyun 
310*4882a593Smuzhiyun /* Bit masks for Axi Ethernet FMI register */
311*4882a593Smuzhiyun #define XAE_FMI_PM_MASK			0x80000000 /* Promis. mode enable */
312*4882a593Smuzhiyun #define XAE_FMI_IND_MASK		0x00000003 /* Index Mask */
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun #define XAE_MDIO_DIV_DFT		29 /* Default MDIO clock divisor */
315*4882a593Smuzhiyun 
316*4882a593Smuzhiyun /* Defines for different options for C_PHY_TYPE parameter in Axi Ethernet IP */
317*4882a593Smuzhiyun #define XAE_PHY_TYPE_MII		0
318*4882a593Smuzhiyun #define XAE_PHY_TYPE_GMII		1
319*4882a593Smuzhiyun #define XAE_PHY_TYPE_RGMII_1_3		2
320*4882a593Smuzhiyun #define XAE_PHY_TYPE_RGMII_2_0		3
321*4882a593Smuzhiyun #define XAE_PHY_TYPE_SGMII		4
322*4882a593Smuzhiyun #define XAE_PHY_TYPE_1000BASE_X		5
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun  /* Total number of entries in the hardware multicast table. */
325*4882a593Smuzhiyun #define XAE_MULTICAST_CAM_TABLE_NUM	4
326*4882a593Smuzhiyun 
327*4882a593Smuzhiyun /* Axi Ethernet Synthesis features */
328*4882a593Smuzhiyun #define XAE_FEATURE_PARTIAL_RX_CSUM	(1 << 0)
329*4882a593Smuzhiyun #define XAE_FEATURE_PARTIAL_TX_CSUM	(1 << 1)
330*4882a593Smuzhiyun #define XAE_FEATURE_FULL_RX_CSUM	(1 << 2)
331*4882a593Smuzhiyun #define XAE_FEATURE_FULL_TX_CSUM	(1 << 3)
332*4882a593Smuzhiyun #define XAE_FEATURE_DMA_64BIT		(1 << 4)
333*4882a593Smuzhiyun 
334*4882a593Smuzhiyun #define XAE_NO_CSUM_OFFLOAD		0
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun #define XAE_FULL_CSUM_STATUS_MASK	0x00000038
337*4882a593Smuzhiyun #define XAE_IP_UDP_CSUM_VALIDATED	0x00000003
338*4882a593Smuzhiyun #define XAE_IP_TCP_CSUM_VALIDATED	0x00000002
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun #define DELAY_OF_ONE_MILLISEC		1000
341*4882a593Smuzhiyun 
342*4882a593Smuzhiyun /**
343*4882a593Smuzhiyun  * struct axidma_bd - Axi Dma buffer descriptor layout
344*4882a593Smuzhiyun  * @next:         MM2S/S2MM Next Descriptor Pointer
345*4882a593Smuzhiyun  * @next_msb:     MM2S/S2MM Next Descriptor Pointer (high 32 bits)
346*4882a593Smuzhiyun  * @phys:         MM2S/S2MM Buffer Address
347*4882a593Smuzhiyun  * @phys_msb:     MM2S/S2MM Buffer Address (high 32 bits)
348*4882a593Smuzhiyun  * @reserved3:    Reserved and not used
349*4882a593Smuzhiyun  * @reserved4:    Reserved and not used
350*4882a593Smuzhiyun  * @cntrl:        MM2S/S2MM Control value
351*4882a593Smuzhiyun  * @status:       MM2S/S2MM Status value
352*4882a593Smuzhiyun  * @app0:         MM2S/S2MM User Application Field 0.
353*4882a593Smuzhiyun  * @app1:         MM2S/S2MM User Application Field 1.
354*4882a593Smuzhiyun  * @app2:         MM2S/S2MM User Application Field 2.
355*4882a593Smuzhiyun  * @app3:         MM2S/S2MM User Application Field 3.
356*4882a593Smuzhiyun  * @app4:         MM2S/S2MM User Application Field 4.
357*4882a593Smuzhiyun  */
358*4882a593Smuzhiyun struct axidma_bd {
359*4882a593Smuzhiyun 	u32 next;	/* Physical address of next buffer descriptor */
360*4882a593Smuzhiyun 	u32 next_msb;	/* high 32 bits for IP >= v7.1, reserved on older IP */
361*4882a593Smuzhiyun 	u32 phys;
362*4882a593Smuzhiyun 	u32 phys_msb;	/* for IP >= v7.1, reserved for older IP */
363*4882a593Smuzhiyun 	u32 reserved3;
364*4882a593Smuzhiyun 	u32 reserved4;
365*4882a593Smuzhiyun 	u32 cntrl;
366*4882a593Smuzhiyun 	u32 status;
367*4882a593Smuzhiyun 	u32 app0;
368*4882a593Smuzhiyun 	u32 app1;	/* TX start << 16 | insert */
369*4882a593Smuzhiyun 	u32 app2;	/* TX csum seed */
370*4882a593Smuzhiyun 	u32 app3;
371*4882a593Smuzhiyun 	u32 app4;   /* Last field used by HW */
372*4882a593Smuzhiyun 	struct sk_buff *skb;
373*4882a593Smuzhiyun } __aligned(XAXIDMA_BD_MINIMUM_ALIGNMENT);
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun /**
376*4882a593Smuzhiyun  * struct axienet_local - axienet private per device data
377*4882a593Smuzhiyun  * @ndev:	Pointer for net_device to which it will be attached.
378*4882a593Smuzhiyun  * @dev:	Pointer to device structure
379*4882a593Smuzhiyun  * @phy_node:	Pointer to device node structure
380*4882a593Smuzhiyun  * @mii_bus:	Pointer to MII bus structure
381*4882a593Smuzhiyun  * @regs_start: Resource start for axienet device addresses
382*4882a593Smuzhiyun  * @regs:	Base address for the axienet_local device address space
383*4882a593Smuzhiyun  * @dma_regs:	Base address for the axidma device address space
384*4882a593Smuzhiyun  * @dma_err_tasklet: Tasklet structure to process Axi DMA errors
385*4882a593Smuzhiyun  * @tx_irq:	Axidma TX IRQ number
386*4882a593Smuzhiyun  * @rx_irq:	Axidma RX IRQ number
387*4882a593Smuzhiyun  * @phy_mode:	Phy type to identify between MII/GMII/RGMII/SGMII/1000 Base-X
388*4882a593Smuzhiyun  * @options:	AxiEthernet option word
389*4882a593Smuzhiyun  * @last_link:	Phy link state in which the PHY was negotiated earlier
390*4882a593Smuzhiyun  * @features:	Stores the extended features supported by the axienet hw
391*4882a593Smuzhiyun  * @tx_bd_v:	Virtual address of the TX buffer descriptor ring
392*4882a593Smuzhiyun  * @tx_bd_p:	Physical address(start address) of the TX buffer descr. ring
393*4882a593Smuzhiyun  * @rx_bd_v:	Virtual address of the RX buffer descriptor ring
394*4882a593Smuzhiyun  * @rx_bd_p:	Physical address(start address) of the RX buffer descr. ring
395*4882a593Smuzhiyun  * @tx_bd_ci:	Stores the index of the Tx buffer descriptor in the ring being
396*4882a593Smuzhiyun  *		accessed currently. Used while alloc. BDs before a TX starts
397*4882a593Smuzhiyun  * @tx_bd_tail:	Stores the index of the Tx buffer descriptor in the ring being
398*4882a593Smuzhiyun  *		accessed currently. Used while processing BDs after the TX
399*4882a593Smuzhiyun  *		completed.
400*4882a593Smuzhiyun  * @rx_bd_ci:	Stores the index of the Rx buffer descriptor in the ring being
401*4882a593Smuzhiyun  *		accessed currently.
402*4882a593Smuzhiyun  * @max_frm_size: Stores the maximum size of the frame that can be that
403*4882a593Smuzhiyun  *		  Txed/Rxed in the existing hardware. If jumbo option is
404*4882a593Smuzhiyun  *		  supported, the maximum frame size would be 9k. Else it is
405*4882a593Smuzhiyun  *		  1522 bytes (assuming support for basic VLAN)
406*4882a593Smuzhiyun  * @rxmem:	Stores rx memory size for jumbo frame handling.
407*4882a593Smuzhiyun  * @csum_offload_on_tx_path:	Stores the checksum selection on TX side.
408*4882a593Smuzhiyun  * @csum_offload_on_rx_path:	Stores the checksum selection on RX side.
409*4882a593Smuzhiyun  * @coalesce_count_rx:	Store the irq coalesce on RX side.
410*4882a593Smuzhiyun  * @coalesce_count_tx:	Store the irq coalesce on TX side.
411*4882a593Smuzhiyun  */
412*4882a593Smuzhiyun struct axienet_local {
413*4882a593Smuzhiyun 	struct net_device *ndev;
414*4882a593Smuzhiyun 	struct device *dev;
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun 	/* Connection to PHY device */
417*4882a593Smuzhiyun 	struct device_node *phy_node;
418*4882a593Smuzhiyun 
419*4882a593Smuzhiyun 	struct phylink *phylink;
420*4882a593Smuzhiyun 	struct phylink_config phylink_config;
421*4882a593Smuzhiyun 
422*4882a593Smuzhiyun 	/* Reference to PCS/PMA PHY if used */
423*4882a593Smuzhiyun 	struct mdio_device *pcs_phy;
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun 	/* Clock for AXI bus */
426*4882a593Smuzhiyun 	struct clk *clk;
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun 	/* MDIO bus data */
429*4882a593Smuzhiyun 	struct mii_bus *mii_bus;	/* MII bus reference */
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun 	/* IO registers, dma functions and IRQs */
432*4882a593Smuzhiyun 	resource_size_t regs_start;
433*4882a593Smuzhiyun 	void __iomem *regs;
434*4882a593Smuzhiyun 	void __iomem *dma_regs;
435*4882a593Smuzhiyun 
436*4882a593Smuzhiyun 	struct work_struct dma_err_task;
437*4882a593Smuzhiyun 
438*4882a593Smuzhiyun 	int tx_irq;
439*4882a593Smuzhiyun 	int rx_irq;
440*4882a593Smuzhiyun 	int eth_irq;
441*4882a593Smuzhiyun 	phy_interface_t phy_mode;
442*4882a593Smuzhiyun 
443*4882a593Smuzhiyun 	u32 options;			/* Current options word */
444*4882a593Smuzhiyun 	u32 features;
445*4882a593Smuzhiyun 
446*4882a593Smuzhiyun 	/* Buffer descriptors */
447*4882a593Smuzhiyun 	struct axidma_bd *tx_bd_v;
448*4882a593Smuzhiyun 	dma_addr_t tx_bd_p;
449*4882a593Smuzhiyun 	u32 tx_bd_num;
450*4882a593Smuzhiyun 	struct axidma_bd *rx_bd_v;
451*4882a593Smuzhiyun 	dma_addr_t rx_bd_p;
452*4882a593Smuzhiyun 	u32 rx_bd_num;
453*4882a593Smuzhiyun 	u32 tx_bd_ci;
454*4882a593Smuzhiyun 	u32 tx_bd_tail;
455*4882a593Smuzhiyun 	u32 rx_bd_ci;
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun 	u32 max_frm_size;
458*4882a593Smuzhiyun 	u32 rxmem;
459*4882a593Smuzhiyun 
460*4882a593Smuzhiyun 	int csum_offload_on_tx_path;
461*4882a593Smuzhiyun 	int csum_offload_on_rx_path;
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun 	u32 coalesce_count_rx;
464*4882a593Smuzhiyun 	u32 coalesce_count_tx;
465*4882a593Smuzhiyun };
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun /**
468*4882a593Smuzhiyun  * struct axiethernet_option - Used to set axi ethernet hardware options
469*4882a593Smuzhiyun  * @opt:	Option to be set.
470*4882a593Smuzhiyun  * @reg:	Register offset to be written for setting the option
471*4882a593Smuzhiyun  * @m_or:	Mask to be ORed for setting the option in the register
472*4882a593Smuzhiyun  */
473*4882a593Smuzhiyun struct axienet_option {
474*4882a593Smuzhiyun 	u32 opt;
475*4882a593Smuzhiyun 	u32 reg;
476*4882a593Smuzhiyun 	u32 m_or;
477*4882a593Smuzhiyun };
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun /**
480*4882a593Smuzhiyun  * axienet_ior - Memory mapped Axi Ethernet register read
481*4882a593Smuzhiyun  * @lp:         Pointer to axienet local structure
482*4882a593Smuzhiyun  * @offset:     Address offset from the base address of Axi Ethernet core
483*4882a593Smuzhiyun  *
484*4882a593Smuzhiyun  * Return: The contents of the Axi Ethernet register
485*4882a593Smuzhiyun  *
486*4882a593Smuzhiyun  * This function returns the contents of the corresponding register.
487*4882a593Smuzhiyun  */
axienet_ior(struct axienet_local * lp,off_t offset)488*4882a593Smuzhiyun static inline u32 axienet_ior(struct axienet_local *lp, off_t offset)
489*4882a593Smuzhiyun {
490*4882a593Smuzhiyun 	return ioread32(lp->regs + offset);
491*4882a593Smuzhiyun }
492*4882a593Smuzhiyun 
axinet_ior_read_mcr(struct axienet_local * lp)493*4882a593Smuzhiyun static inline u32 axinet_ior_read_mcr(struct axienet_local *lp)
494*4882a593Smuzhiyun {
495*4882a593Smuzhiyun 	return axienet_ior(lp, XAE_MDIO_MCR_OFFSET);
496*4882a593Smuzhiyun }
497*4882a593Smuzhiyun 
498*4882a593Smuzhiyun /**
499*4882a593Smuzhiyun  * axienet_iow - Memory mapped Axi Ethernet register write
500*4882a593Smuzhiyun  * @lp:         Pointer to axienet local structure
501*4882a593Smuzhiyun  * @offset:     Address offset from the base address of Axi Ethernet core
502*4882a593Smuzhiyun  * @value:      Value to be written into the Axi Ethernet register
503*4882a593Smuzhiyun  *
504*4882a593Smuzhiyun  * This function writes the desired value into the corresponding Axi Ethernet
505*4882a593Smuzhiyun  * register.
506*4882a593Smuzhiyun  */
axienet_iow(struct axienet_local * lp,off_t offset,u32 value)507*4882a593Smuzhiyun static inline void axienet_iow(struct axienet_local *lp, off_t offset,
508*4882a593Smuzhiyun 			       u32 value)
509*4882a593Smuzhiyun {
510*4882a593Smuzhiyun 	iowrite32(value, lp->regs + offset);
511*4882a593Smuzhiyun }
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun /* Function prototypes visible in xilinx_axienet_mdio.c for other files */
514*4882a593Smuzhiyun int axienet_mdio_enable(struct axienet_local *lp);
515*4882a593Smuzhiyun void axienet_mdio_disable(struct axienet_local *lp);
516*4882a593Smuzhiyun int axienet_mdio_setup(struct axienet_local *lp);
517*4882a593Smuzhiyun void axienet_mdio_teardown(struct axienet_local *lp);
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun #endif /* XILINX_AXI_ENET_H */
520