xref: /openbmc/linux/drivers/net/ethernet/actions/owl-emac.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
1*de6e0b19SCristian Ciocaltea /* SPDX-License-Identifier: GPL-2.0-or-later */
2*de6e0b19SCristian Ciocaltea /*
3*de6e0b19SCristian Ciocaltea  * Actions Semi Owl SoCs Ethernet MAC driver
4*de6e0b19SCristian Ciocaltea  *
5*de6e0b19SCristian Ciocaltea  * Copyright (c) 2012 Actions Semi Inc.
6*de6e0b19SCristian Ciocaltea  * Copyright (c) 2021 Cristian Ciocaltea <cristian.ciocaltea@gmail.com>
7*de6e0b19SCristian Ciocaltea  */
8*de6e0b19SCristian Ciocaltea 
9*de6e0b19SCristian Ciocaltea #ifndef __OWL_EMAC_H__
10*de6e0b19SCristian Ciocaltea #define __OWL_EMAC_H__
11*de6e0b19SCristian Ciocaltea 
12*de6e0b19SCristian Ciocaltea #define OWL_EMAC_DRVNAME			"owl-emac"
13*de6e0b19SCristian Ciocaltea 
14*de6e0b19SCristian Ciocaltea #define OWL_EMAC_POLL_DELAY_USEC		5
15*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MDIO_POLL_TIMEOUT_USEC		1000
16*de6e0b19SCristian Ciocaltea #define OWL_EMAC_RESET_POLL_TIMEOUT_USEC	2000
17*de6e0b19SCristian Ciocaltea #define OWL_EMAC_TX_TIMEOUT			(2 * HZ)
18*de6e0b19SCristian Ciocaltea 
19*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MTU_MIN			ETH_MIN_MTU
20*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MTU_MAX			ETH_DATA_LEN
21*de6e0b19SCristian Ciocaltea #define OWL_EMAC_RX_FRAME_MAX_LEN		(ETH_FRAME_LEN + ETH_FCS_LEN)
22*de6e0b19SCristian Ciocaltea #define OWL_EMAC_SKB_ALIGN			4
23*de6e0b19SCristian Ciocaltea #define OWL_EMAC_SKB_RESERVE			18
24*de6e0b19SCristian Ciocaltea 
25*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MAX_MULTICAST_ADDRS		14
26*de6e0b19SCristian Ciocaltea #define OWL_EMAC_SETUP_FRAME_LEN		192
27*de6e0b19SCristian Ciocaltea 
28*de6e0b19SCristian Ciocaltea #define OWL_EMAC_RX_RING_SIZE			64
29*de6e0b19SCristian Ciocaltea #define OWL_EMAC_TX_RING_SIZE			32
30*de6e0b19SCristian Ciocaltea 
31*de6e0b19SCristian Ciocaltea /* Bus mode register */
32*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR0			0x0000
33*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR0_SWR		BIT(0)	/* Software reset */
34*de6e0b19SCristian Ciocaltea 
35*de6e0b19SCristian Ciocaltea /* Transmit/receive poll demand registers */
36*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR1			0x0008
37*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR1_TPD		0x01
38*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR2			0x0010
39*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR2_RPD		0x01
40*de6e0b19SCristian Ciocaltea 
41*de6e0b19SCristian Ciocaltea /* Receive/transmit descriptor list base address registers */
42*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR3			0x0018
43*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR4			0x0020
44*de6e0b19SCristian Ciocaltea 
45*de6e0b19SCristian Ciocaltea /* Status register */
46*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR5			0x0028
47*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR5_TS		GENMASK(22, 20)	/* Transmit process state */
48*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR5_TS		20
49*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR5_TS_DATA		0x03	/* Transferring data HOST -> FIFO */
50*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR5_TS_CDES		0x07	/* Closing transmit descriptor */
51*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR5_RS		GENMASK(19, 17)	/* Receive process state */
52*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR5_RS		17
53*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR5_RS_FDES		0x01	/* Fetching receive descriptor */
54*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR5_RS_CDES		0x05	/* Closing receive descriptor */
55*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR5_RS_DATA		0x07	/* Transferring data FIFO -> HOST */
56*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_NIS		BIT(16)	/* Normal interrupt summary */
57*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_AIS		BIT(15)	/* Abnormal interrupt summary */
58*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_ERI		BIT(14)	/* Early receive interrupt */
59*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_GTE		BIT(11)	/* General-purpose timer expiration */
60*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_ETI		BIT(10)	/* Early transmit interrupt */
61*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_RPS		BIT(8)	/* Receive process stopped */
62*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_RU		BIT(7)	/* Receive buffer unavailable */
63*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_RI		BIT(6)	/* Receive interrupt */
64*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_UNF		BIT(5)	/* Transmit underflow */
65*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_LCIS		BIT(4)	/* Link change status */
66*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_LCIQ		BIT(3)	/* Link change interrupt */
67*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_TU		BIT(2)	/* Transmit buffer unavailable */
68*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_TPS		BIT(1)	/* Transmit process stopped */
69*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR5_TI		BIT(0)	/* Transmit interrupt */
70*de6e0b19SCristian Ciocaltea 
71*de6e0b19SCristian Ciocaltea /* Operation mode register */
72*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR6			0x0030
73*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_RA		BIT(30)	/* Receive all */
74*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_TTM		BIT(22)	/* Transmit threshold mode */
75*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_SF		BIT(21)	/* Store and forward */
76*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR6_SPEED		GENMASK(17, 16)	/* Eth speed selection */
77*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR6_SPEED		16
78*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR6_SPEED_100M	0x00
79*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR6_SPEED_10M		0x02
80*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_ST		BIT(13)	/* Start/stop transmit command */
81*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_LP		BIT(10)	/* Loopback mode */
82*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_FD		BIT(9)	/* Full duplex mode */
83*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_PM		BIT(7)	/* Pass all multicast */
84*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_PR		BIT(6)	/* Promiscuous mode */
85*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_IF		BIT(4)	/* Inverse filtering */
86*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_PB		BIT(3)	/* Pass bad frames */
87*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_HO		BIT(2)	/* Hash only filtering mode */
88*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_SR		BIT(1)	/* Start/stop receive command */
89*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR6_HP		BIT(0)	/* Hash/perfect receive filtering mode */
90*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR6_STSR	       (OWL_EMAC_BIT_MAC_CSR6_ST | \
91*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR6_SR)
92*de6e0b19SCristian Ciocaltea 
93*de6e0b19SCristian Ciocaltea /* Interrupt enable register */
94*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR7			0x0038
95*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_NIE		BIT(16)	/* Normal interrupt summary enable */
96*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_AIE		BIT(15)	/* Abnormal interrupt summary enable */
97*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_ERE		BIT(14)	/* Early receive interrupt enable */
98*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_GTE		BIT(11)	/* General-purpose timer overflow */
99*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_ETE		BIT(10)	/* Early transmit interrupt enable */
100*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_RSE		BIT(8)	/* Receive stopped enable */
101*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_RUE		BIT(7)	/* Receive buffer unavailable enable */
102*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_RIE		BIT(6)	/* Receive interrupt enable */
103*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_UNE		BIT(5)	/* Underflow interrupt enable */
104*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_TUE		BIT(2)	/* Transmit buffer unavailable enable */
105*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_TSE		BIT(1)	/* Transmit stopped enable */
106*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_TIE		BIT(0)	/* Transmit interrupt enable */
107*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR7_ALL_NOT_TUE      (OWL_EMAC_BIT_MAC_CSR7_ERE | \
108*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_GTE | \
109*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_ETE | \
110*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_RSE | \
111*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_RUE | \
112*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_RIE | \
113*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_UNE | \
114*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_TSE | \
115*de6e0b19SCristian Ciocaltea 						OWL_EMAC_BIT_MAC_CSR7_TIE)
116*de6e0b19SCristian Ciocaltea 
117*de6e0b19SCristian Ciocaltea /* Missed frames and overflow counter register */
118*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR8			0x0040
119*de6e0b19SCristian Ciocaltea /* MII management and serial ROM register */
120*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR9			0x0048
121*de6e0b19SCristian Ciocaltea 
122*de6e0b19SCristian Ciocaltea /* MII serial management register */
123*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR10			0x0050
124*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR10_SB		BIT(31)	/* Start transfer or busy */
125*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR10_CLKDIV		GENMASK(30, 28)	/* Clock divider */
126*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR10_CLKDIV		28
127*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR10_CLKDIV_128	0x04
128*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_WR	0x01	/* Register write command */
129*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR10_OPCODE		26	/* Operation mode */
130*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_DCG	0x00	/* Disable clock generation */
131*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_WR	0x01	/* Register write command */
132*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_RD	0x02	/* Register read command */
133*de6e0b19SCristian Ciocaltea #define OWL_EMAC_VAL_MAC_CSR10_OPCODE_CDS	0x03	/* Clock divider set */
134*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR10_PHYADD		GENMASK(25, 21)	/* Physical layer address */
135*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR10_PHYADD		21
136*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR10_REGADD		GENMASK(20, 16)	/* Register address */
137*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR10_REGADD		16
138*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_MAC_CSR10_DATA		GENMASK(15, 0)	/* Register data */
139*de6e0b19SCristian Ciocaltea 
140*de6e0b19SCristian Ciocaltea /* General-purpose timer and interrupt mitigation control register */
141*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR11			0x0058
142*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR11_TT		27	/* Transmit timer */
143*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR11_NTP		24	/* No. of transmit packets */
144*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR11_RT		20	/* Receive timer */
145*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR11_NRP		17	/* No. of receive packets */
146*de6e0b19SCristian Ciocaltea 
147*de6e0b19SCristian Ciocaltea /* MAC address low/high registers */
148*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR16			0x0080
149*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR17			0x0088
150*de6e0b19SCristian Ciocaltea 
151*de6e0b19SCristian Ciocaltea /* Pause time & cache thresholds register */
152*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR18			0x0090
153*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR18_CPTL		24	/* Cache pause threshold level */
154*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR18_CRTL		16	/* Cache restart threshold level */
155*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR18_PQT		0	/* Flow control pause quanta time */
156*de6e0b19SCristian Ciocaltea 
157*de6e0b19SCristian Ciocaltea /* FIFO pause & restart threshold register */
158*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR19			0x0098
159*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR19_FPTL		16	/* FIFO pause threshold level */
160*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CSR19_FRTL		0	/* FIFO restart threshold level */
161*de6e0b19SCristian Ciocaltea 
162*de6e0b19SCristian Ciocaltea /* Flow control setup & status register */
163*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CSR20			0x00A0
164*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR20_FCE		BIT(31)	/* Flow Control Enable */
165*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR20_TUE		BIT(30)	/* Transmit Un-pause frames Enable */
166*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR20_TPE		BIT(29)	/* Transmit Pause frames Enable */
167*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR20_RPE		BIT(28)	/* Receive Pause frames Enable */
168*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CSR20_BPE		BIT(27)	/* Back pressure (half-duplex) Enable */
169*de6e0b19SCristian Ciocaltea 
170*de6e0b19SCristian Ciocaltea /* MII control register */
171*de6e0b19SCristian Ciocaltea #define OWL_EMAC_REG_MAC_CTRL			0x00B0
172*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CTRL_RRSB		BIT(8)	/* RMII_REFCLK select bit */
173*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_MAC_CTRL_SSDC		4	/* SMII SYNC delay cycle */
174*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CTRL_RCPS		BIT(1)	/* REF_CLK phase select */
175*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_MAC_CTRL_RSIS		BIT(0)	/* RMII/SMII interface select */
176*de6e0b19SCristian Ciocaltea 
177*de6e0b19SCristian Ciocaltea /* Receive descriptor status field */
178*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_OWN			BIT(31)	/* Ownership bit */
179*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_FF			BIT(30)	/* Filtering fail */
180*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_RDES0_FL			GENMASK(29, 16)	/* Frame length */
181*de6e0b19SCristian Ciocaltea #define OWL_EMAC_OFF_RDES0_FL			16
182*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_ES			BIT(15)	/* Error summary */
183*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_DE			BIT(14)	/* Descriptor error */
184*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_RF			BIT(11)	/* Runt frame */
185*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_MF			BIT(10)	/* Multicast frame */
186*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_FS			BIT(9)	/* First descriptor */
187*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_LS			BIT(8)	/* Last descriptor */
188*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_TL			BIT(7)	/* Frame too long */
189*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_CS			BIT(6)	/* Collision seen */
190*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_FT			BIT(5)	/* Frame type */
191*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_RE			BIT(3)	/* Report on MII error */
192*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_DB			BIT(2)	/* Dribbling bit */
193*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_CE			BIT(1)	/* CRC error */
194*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES0_ZERO			BIT(0)	/* Legal frame length indicator */
195*de6e0b19SCristian Ciocaltea 
196*de6e0b19SCristian Ciocaltea /* Receive descriptor control and count field */
197*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_RDES1_RER			BIT(25)	/* Receive end of ring */
198*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_RDES1_RBS1			GENMASK(10, 0) /* Buffer 1 size */
199*de6e0b19SCristian Ciocaltea 
200*de6e0b19SCristian Ciocaltea /* Transmit descriptor status field */
201*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_OWN			BIT(31)	/* Ownership bit */
202*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_ES			BIT(15)	/* Error summary */
203*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_LO			BIT(11)	/* Loss of carrier */
204*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_NC			BIT(10)	/* No carrier */
205*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_LC			BIT(9)	/* Late collision */
206*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_EC			BIT(8)	/* Excessive collisions */
207*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_TDES0_CC			GENMASK(6, 3) /* Collision count */
208*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_UF			BIT(1)	/* Underflow error */
209*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES0_DE			BIT(0)	/* Deferred */
210*de6e0b19SCristian Ciocaltea 
211*de6e0b19SCristian Ciocaltea /* Transmit descriptor control and count field */
212*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_IC			BIT(31)	/* Interrupt on completion */
213*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_LS			BIT(30)	/* Last descriptor */
214*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_FS			BIT(29)	/* First descriptor */
215*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_FT1			BIT(28)	/* Filtering type */
216*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_SET			BIT(27)	/* Setup packet */
217*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_AC			BIT(26)	/* Add CRC disable */
218*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_TER			BIT(25)	/* Transmit end of ring */
219*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_DPD			BIT(23)	/* Disabled padding */
220*de6e0b19SCristian Ciocaltea #define OWL_EMAC_BIT_TDES1_FT0			BIT(22)	/* Filtering type */
221*de6e0b19SCristian Ciocaltea #define OWL_EMAC_MSK_TDES1_TBS1			GENMASK(10, 0) /* Buffer 1 size */
222*de6e0b19SCristian Ciocaltea 
223*de6e0b19SCristian Ciocaltea static const char *const owl_emac_clk_names[] = { "eth", "rmii" };
224*de6e0b19SCristian Ciocaltea #define OWL_EMAC_NCLKS ARRAY_SIZE(owl_emac_clk_names)
225*de6e0b19SCristian Ciocaltea 
226*de6e0b19SCristian Ciocaltea enum owl_emac_clk_map {
227*de6e0b19SCristian Ciocaltea 	OWL_EMAC_CLK_ETH = 0,
228*de6e0b19SCristian Ciocaltea 	OWL_EMAC_CLK_RMII
229*de6e0b19SCristian Ciocaltea };
230*de6e0b19SCristian Ciocaltea 
231*de6e0b19SCristian Ciocaltea struct owl_emac_addr_list {
232*de6e0b19SCristian Ciocaltea 	u8 addrs[OWL_EMAC_MAX_MULTICAST_ADDRS][ETH_ALEN];
233*de6e0b19SCristian Ciocaltea 	int count;
234*de6e0b19SCristian Ciocaltea };
235*de6e0b19SCristian Ciocaltea 
236*de6e0b19SCristian Ciocaltea /* TX/RX descriptors */
237*de6e0b19SCristian Ciocaltea struct owl_emac_ring_desc {
238*de6e0b19SCristian Ciocaltea 	u32 status;
239*de6e0b19SCristian Ciocaltea 	u32 control;
240*de6e0b19SCristian Ciocaltea 	u32 buf_addr;
241*de6e0b19SCristian Ciocaltea 	u32 reserved;		/* 2nd buffer address is not used */
242*de6e0b19SCristian Ciocaltea };
243*de6e0b19SCristian Ciocaltea 
244*de6e0b19SCristian Ciocaltea struct owl_emac_ring {
245*de6e0b19SCristian Ciocaltea 	struct owl_emac_ring_desc *descs;
246*de6e0b19SCristian Ciocaltea 	dma_addr_t descs_dma;
247*de6e0b19SCristian Ciocaltea 	struct sk_buff **skbs;
248*de6e0b19SCristian Ciocaltea 	dma_addr_t *skbs_dma;
249*de6e0b19SCristian Ciocaltea 	unsigned int size;
250*de6e0b19SCristian Ciocaltea 	unsigned int head;
251*de6e0b19SCristian Ciocaltea 	unsigned int tail;
252*de6e0b19SCristian Ciocaltea };
253*de6e0b19SCristian Ciocaltea 
254*de6e0b19SCristian Ciocaltea struct owl_emac_priv {
255*de6e0b19SCristian Ciocaltea 	struct net_device *netdev;
256*de6e0b19SCristian Ciocaltea 	void __iomem *base;
257*de6e0b19SCristian Ciocaltea 
258*de6e0b19SCristian Ciocaltea 	struct clk_bulk_data clks[OWL_EMAC_NCLKS];
259*de6e0b19SCristian Ciocaltea 	struct reset_control *reset;
260*de6e0b19SCristian Ciocaltea 
261*de6e0b19SCristian Ciocaltea 	struct owl_emac_ring rx_ring;
262*de6e0b19SCristian Ciocaltea 	struct owl_emac_ring tx_ring;
263*de6e0b19SCristian Ciocaltea 
264*de6e0b19SCristian Ciocaltea 	struct mii_bus *mii;
265*de6e0b19SCristian Ciocaltea 	struct napi_struct napi;
266*de6e0b19SCristian Ciocaltea 
267*de6e0b19SCristian Ciocaltea 	phy_interface_t phy_mode;
268*de6e0b19SCristian Ciocaltea 	unsigned int link;
269*de6e0b19SCristian Ciocaltea 	int speed;
270*de6e0b19SCristian Ciocaltea 	int duplex;
271*de6e0b19SCristian Ciocaltea 	int pause;
272*de6e0b19SCristian Ciocaltea 	struct owl_emac_addr_list mcaddr_list;
273*de6e0b19SCristian Ciocaltea 
274*de6e0b19SCristian Ciocaltea 	struct work_struct mac_reset_task;
275*de6e0b19SCristian Ciocaltea 
276*de6e0b19SCristian Ciocaltea 	u32 msg_enable;		/* Debug message level */
277*de6e0b19SCristian Ciocaltea 	spinlock_t lock;	/* Sync concurrent ring access */
278*de6e0b19SCristian Ciocaltea };
279*de6e0b19SCristian Ciocaltea 
280*de6e0b19SCristian Ciocaltea #endif /* __OWL_EMAC_H__ */
281