1ec21e2ecSJeff Kirsher /****************************************************************************/
2ec21e2ecSJeff Kirsher 
3ec21e2ecSJeff Kirsher /*
4ec21e2ecSJeff Kirsher  *	fec.h  --  Fast Ethernet Controller for Motorola ColdFire SoC
5ec21e2ecSJeff Kirsher  *		   processors.
6ec21e2ecSJeff Kirsher  *
7ec21e2ecSJeff Kirsher  *	(C) Copyright 2000-2005, Greg Ungerer (gerg@snapgear.com)
8ec21e2ecSJeff Kirsher  *	(C) Copyright 2000-2001, Lineo (www.lineo.com)
9ec21e2ecSJeff Kirsher  */
10ec21e2ecSJeff Kirsher 
11ec21e2ecSJeff Kirsher /****************************************************************************/
12ec21e2ecSJeff Kirsher #ifndef FEC_H
13ec21e2ecSJeff Kirsher #define	FEC_H
14ec21e2ecSJeff Kirsher /****************************************************************************/
15ec21e2ecSJeff Kirsher 
166605b730SFrank Li #include <linux/clocksource.h>
176605b730SFrank Li #include <linux/net_tstamp.h>
186605b730SFrank Li #include <linux/ptp_clock_kernel.h>
196605b730SFrank Li 
20ec21e2ecSJeff Kirsher #if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
21ec21e2ecSJeff Kirsher     defined(CONFIG_M520x) || defined(CONFIG_M532x) || \
22ec21e2ecSJeff Kirsher     defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
23ec21e2ecSJeff Kirsher /*
24ec21e2ecSJeff Kirsher  *	Just figures, Motorola would have to change the offsets for
25ec21e2ecSJeff Kirsher  *	registers in the same peripheral device on different models
26ec21e2ecSJeff Kirsher  *	of the ColdFire!
27ec21e2ecSJeff Kirsher  */
28ec21e2ecSJeff Kirsher #define FEC_IEVENT		0x004 /* Interrupt event reg */
29ec21e2ecSJeff Kirsher #define FEC_IMASK		0x008 /* Interrupt mask reg */
30ec21e2ecSJeff Kirsher #define FEC_R_DES_ACTIVE	0x010 /* Receive descriptor reg */
31ec21e2ecSJeff Kirsher #define FEC_X_DES_ACTIVE	0x014 /* Transmit descriptor reg */
32ec21e2ecSJeff Kirsher #define FEC_ECNTRL		0x024 /* Ethernet control reg */
33ec21e2ecSJeff Kirsher #define FEC_MII_DATA		0x040 /* MII manage frame reg */
34ec21e2ecSJeff Kirsher #define FEC_MII_SPEED		0x044 /* MII speed control reg */
35ec21e2ecSJeff Kirsher #define FEC_MIB_CTRLSTAT	0x064 /* MIB control/status reg */
36ec21e2ecSJeff Kirsher #define FEC_R_CNTRL		0x084 /* Receive control reg */
37ec21e2ecSJeff Kirsher #define FEC_X_CNTRL		0x0c4 /* Transmit Control reg */
38ec21e2ecSJeff Kirsher #define FEC_ADDR_LOW		0x0e4 /* Low 32bits MAC address */
39ec21e2ecSJeff Kirsher #define FEC_ADDR_HIGH		0x0e8 /* High 16bits MAC address */
40ec21e2ecSJeff Kirsher #define FEC_OPD			0x0ec /* Opcode + Pause duration */
41ec21e2ecSJeff Kirsher #define FEC_HASH_TABLE_HIGH	0x118 /* High 32bits hash table */
42ec21e2ecSJeff Kirsher #define FEC_HASH_TABLE_LOW	0x11c /* Low 32bits hash table */
43ec21e2ecSJeff Kirsher #define FEC_GRP_HASH_TABLE_HIGH	0x120 /* High 32bits hash table */
44ec21e2ecSJeff Kirsher #define FEC_GRP_HASH_TABLE_LOW	0x124 /* Low 32bits hash table */
45ec21e2ecSJeff Kirsher #define FEC_X_WMRK		0x144 /* FIFO transmit water mark */
46ec21e2ecSJeff Kirsher #define FEC_R_BOUND		0x14c /* FIFO receive bound reg */
47ec21e2ecSJeff Kirsher #define FEC_R_FSTART		0x150 /* FIFO receive start reg */
48ec21e2ecSJeff Kirsher #define FEC_R_DES_START		0x180 /* Receive descriptor ring */
49ec21e2ecSJeff Kirsher #define FEC_X_DES_START		0x184 /* Transmit descriptor ring */
50ec21e2ecSJeff Kirsher #define FEC_R_BUFF_SIZE		0x188 /* Maximum receive buff size */
51baa70a5cSFrank Li #define FEC_R_FIFO_RSFL		0x190 /* Receive FIFO section full threshold */
52baa70a5cSFrank Li #define FEC_R_FIFO_RSEM		0x194 /* Receive FIFO section empty threshold */
53baa70a5cSFrank Li #define FEC_R_FIFO_RAEM		0x198 /* Receive FIFO almost empty threshold */
54baa70a5cSFrank Li #define FEC_R_FIFO_RAFL		0x19c /* Receive FIFO almost full threshold */
554c09eed9SJim Baxter #define FEC_RACC		0x1C4 /* Receive Accelerator function */
56ec21e2ecSJeff Kirsher #define FEC_MIIGSK_CFGR		0x300 /* MIIGSK Configuration reg */
57ec21e2ecSJeff Kirsher #define FEC_MIIGSK_ENR		0x308 /* MIIGSK Enable reg */
58ec21e2ecSJeff Kirsher 
598d82f219SEric Benard #define BM_MIIGSK_CFGR_MII		0x00
608d82f219SEric Benard #define BM_MIIGSK_CFGR_RMII		0x01
618d82f219SEric Benard #define BM_MIIGSK_CFGR_FRCONT_10M	0x40
628d82f219SEric Benard 
63ec21e2ecSJeff Kirsher #else
64ec21e2ecSJeff Kirsher 
65ec21e2ecSJeff Kirsher #define FEC_ECNTRL		0x000 /* Ethernet control reg */
66ec21e2ecSJeff Kirsher #define FEC_IEVENT		0x004 /* Interrupt even reg */
67ec21e2ecSJeff Kirsher #define FEC_IMASK		0x008 /* Interrupt mask reg */
68ec21e2ecSJeff Kirsher #define FEC_IVEC		0x00c /* Interrupt vec status reg */
69ec21e2ecSJeff Kirsher #define FEC_R_DES_ACTIVE	0x010 /* Receive descriptor reg */
70ec21e2ecSJeff Kirsher #define FEC_X_DES_ACTIVE	0x014 /* Transmit descriptor reg */
71ec21e2ecSJeff Kirsher #define FEC_MII_DATA		0x040 /* MII manage frame reg */
72ec21e2ecSJeff Kirsher #define FEC_MII_SPEED		0x044 /* MII speed control reg */
73ec21e2ecSJeff Kirsher #define FEC_R_BOUND		0x08c /* FIFO receive bound reg */
74ec21e2ecSJeff Kirsher #define FEC_R_FSTART		0x090 /* FIFO receive start reg */
75ec21e2ecSJeff Kirsher #define FEC_X_WMRK		0x0a4 /* FIFO transmit water mark */
76ec21e2ecSJeff Kirsher #define FEC_X_FSTART		0x0ac /* FIFO transmit start reg */
77ec21e2ecSJeff Kirsher #define FEC_R_CNTRL		0x104 /* Receive control reg */
78ec21e2ecSJeff Kirsher #define FEC_MAX_FRM_LEN		0x108 /* Maximum frame length reg */
79ec21e2ecSJeff Kirsher #define FEC_X_CNTRL		0x144 /* Transmit Control reg */
80ec21e2ecSJeff Kirsher #define FEC_ADDR_LOW		0x3c0 /* Low 32bits MAC address */
81ec21e2ecSJeff Kirsher #define FEC_ADDR_HIGH		0x3c4 /* High 16bits MAC address */
82ec21e2ecSJeff Kirsher #define FEC_GRP_HASH_TABLE_HIGH	0x3c8 /* High 32bits hash table */
83ec21e2ecSJeff Kirsher #define FEC_GRP_HASH_TABLE_LOW	0x3cc /* Low 32bits hash table */
84ec21e2ecSJeff Kirsher #define FEC_R_DES_START		0x3d0 /* Receive descriptor ring */
85ec21e2ecSJeff Kirsher #define FEC_X_DES_START		0x3d4 /* Transmit descriptor ring */
86ec21e2ecSJeff Kirsher #define FEC_R_BUFF_SIZE		0x3d8 /* Maximum receive buff size */
87ec21e2ecSJeff Kirsher #define FEC_FIFO_RAM		0x400 /* FIFO RAM buffer */
88ec21e2ecSJeff Kirsher 
89ec21e2ecSJeff Kirsher #endif /* CONFIG_M5272 */
90ec21e2ecSJeff Kirsher 
91ec21e2ecSJeff Kirsher 
92ec21e2ecSJeff Kirsher /*
93ec21e2ecSJeff Kirsher  *	Define the buffer descriptor structure.
94ec21e2ecSJeff Kirsher  */
95ec21e2ecSJeff Kirsher #if defined(CONFIG_ARCH_MXC) || defined(CONFIG_SOC_IMX28)
96ec21e2ecSJeff Kirsher struct bufdesc {
97ec21e2ecSJeff Kirsher 	unsigned short cbd_datlen;	/* Data length */
98ec21e2ecSJeff Kirsher 	unsigned short cbd_sc;	/* Control and status info */
99ec21e2ecSJeff Kirsher 	unsigned long cbd_bufaddr;	/* Buffer address */
100ff43da86SFrank Li };
101acac8406SFrank Li #else
102acac8406SFrank Li struct bufdesc {
103acac8406SFrank Li 	unsigned short	cbd_sc;			/* Control and status info */
104acac8406SFrank Li 	unsigned short	cbd_datlen;		/* Data length */
105acac8406SFrank Li 	unsigned long	cbd_bufaddr;		/* Buffer address */
106acac8406SFrank Li };
107acac8406SFrank Li #endif
108ff43da86SFrank Li 
109ff43da86SFrank Li struct bufdesc_ex {
110ff43da86SFrank Li 	struct bufdesc desc;
1116605b730SFrank Li 	unsigned long cbd_esc;
1126605b730SFrank Li 	unsigned long cbd_prot;
1136605b730SFrank Li 	unsigned long cbd_bdu;
1146605b730SFrank Li 	unsigned long ts;
1156605b730SFrank Li 	unsigned short res0[4];
116ec21e2ecSJeff Kirsher };
117ff43da86SFrank Li 
118ec21e2ecSJeff Kirsher /*
119ec21e2ecSJeff Kirsher  *	The following definitions courtesy of commproc.h, which where
120ec21e2ecSJeff Kirsher  *	Copyright (c) 1997 Dan Malek (dmalek@jlc.net).
121ec21e2ecSJeff Kirsher  */
122ec21e2ecSJeff Kirsher #define BD_SC_EMPTY     ((ushort)0x8000)        /* Receive is empty */
123ec21e2ecSJeff Kirsher #define BD_SC_READY     ((ushort)0x8000)        /* Transmit is ready */
124ec21e2ecSJeff Kirsher #define BD_SC_WRAP      ((ushort)0x2000)        /* Last buffer descriptor */
125ec21e2ecSJeff Kirsher #define BD_SC_INTRPT    ((ushort)0x1000)        /* Interrupt on change */
126ec21e2ecSJeff Kirsher #define BD_SC_CM        ((ushort)0x0200)        /* Continuous mode */
127ec21e2ecSJeff Kirsher #define BD_SC_ID        ((ushort)0x0100)        /* Rec'd too many idles */
128ec21e2ecSJeff Kirsher #define BD_SC_P         ((ushort)0x0100)        /* xmt preamble */
129ec21e2ecSJeff Kirsher #define BD_SC_BR        ((ushort)0x0020)        /* Break received */
130ec21e2ecSJeff Kirsher #define BD_SC_FR        ((ushort)0x0010)        /* Framing error */
131ec21e2ecSJeff Kirsher #define BD_SC_PR        ((ushort)0x0008)        /* Parity error */
132ec21e2ecSJeff Kirsher #define BD_SC_OV        ((ushort)0x0002)        /* Overrun */
133ec21e2ecSJeff Kirsher #define BD_SC_CD        ((ushort)0x0001)        /* ?? */
134ec21e2ecSJeff Kirsher 
135ec21e2ecSJeff Kirsher /* Buffer descriptor control/status used by Ethernet receive.
136ec21e2ecSJeff Kirsher */
137ec21e2ecSJeff Kirsher #define BD_ENET_RX_EMPTY        ((ushort)0x8000)
138ec21e2ecSJeff Kirsher #define BD_ENET_RX_WRAP         ((ushort)0x2000)
139ec21e2ecSJeff Kirsher #define BD_ENET_RX_INTR         ((ushort)0x1000)
140ec21e2ecSJeff Kirsher #define BD_ENET_RX_LAST         ((ushort)0x0800)
141ec21e2ecSJeff Kirsher #define BD_ENET_RX_FIRST        ((ushort)0x0400)
142ec21e2ecSJeff Kirsher #define BD_ENET_RX_MISS         ((ushort)0x0100)
143ec21e2ecSJeff Kirsher #define BD_ENET_RX_LG           ((ushort)0x0020)
144ec21e2ecSJeff Kirsher #define BD_ENET_RX_NO           ((ushort)0x0010)
145ec21e2ecSJeff Kirsher #define BD_ENET_RX_SH           ((ushort)0x0008)
146ec21e2ecSJeff Kirsher #define BD_ENET_RX_CR           ((ushort)0x0004)
147ec21e2ecSJeff Kirsher #define BD_ENET_RX_OV           ((ushort)0x0002)
148ec21e2ecSJeff Kirsher #define BD_ENET_RX_CL           ((ushort)0x0001)
149ec21e2ecSJeff Kirsher #define BD_ENET_RX_STATS        ((ushort)0x013f)        /* All status bits */
150ec21e2ecSJeff Kirsher 
151ec21e2ecSJeff Kirsher /* Buffer descriptor control/status used by Ethernet transmit.
152ec21e2ecSJeff Kirsher */
153ec21e2ecSJeff Kirsher #define BD_ENET_TX_READY        ((ushort)0x8000)
154ec21e2ecSJeff Kirsher #define BD_ENET_TX_PAD          ((ushort)0x4000)
155ec21e2ecSJeff Kirsher #define BD_ENET_TX_WRAP         ((ushort)0x2000)
156ec21e2ecSJeff Kirsher #define BD_ENET_TX_INTR         ((ushort)0x1000)
157ec21e2ecSJeff Kirsher #define BD_ENET_TX_LAST         ((ushort)0x0800)
158ec21e2ecSJeff Kirsher #define BD_ENET_TX_TC           ((ushort)0x0400)
159ec21e2ecSJeff Kirsher #define BD_ENET_TX_DEF          ((ushort)0x0200)
160ec21e2ecSJeff Kirsher #define BD_ENET_TX_HB           ((ushort)0x0100)
161ec21e2ecSJeff Kirsher #define BD_ENET_TX_LC           ((ushort)0x0080)
162ec21e2ecSJeff Kirsher #define BD_ENET_TX_RL           ((ushort)0x0040)
163ec21e2ecSJeff Kirsher #define BD_ENET_TX_RCMASK       ((ushort)0x003c)
164ec21e2ecSJeff Kirsher #define BD_ENET_TX_UN           ((ushort)0x0002)
165ec21e2ecSJeff Kirsher #define BD_ENET_TX_CSL          ((ushort)0x0001)
166ec21e2ecSJeff Kirsher #define BD_ENET_TX_STATS        ((ushort)0x03ff)        /* All status bits */
167ec21e2ecSJeff Kirsher 
1684c09eed9SJim Baxter /*enhanced buffer descriptor control/status used by Ethernet transmit*/
169405f257fSFrank Li #define BD_ENET_TX_INT          0x40000000
170405f257fSFrank Li #define BD_ENET_TX_TS           0x20000000
1714c09eed9SJim Baxter #define BD_ENET_TX_PINS         0x10000000
1724c09eed9SJim Baxter #define BD_ENET_TX_IINS         0x08000000
173405f257fSFrank Li 
174405f257fSFrank Li 
175405f257fSFrank Li /* This device has up to three irqs on some platforms */
176405f257fSFrank Li #define FEC_IRQ_NUM		3
177405f257fSFrank Li 
178405f257fSFrank Li /* The number of Tx and Rx buffers.  These are allocated from the page
179405f257fSFrank Li  * pool.  The code may assume these are power of two, so it it best
180405f257fSFrank Li  * to keep them that size.
181405f257fSFrank Li  * We don't need to allocate pages for the transmitter.  We just use
182405f257fSFrank Li  * the skbuffer directly.
183405f257fSFrank Li  */
184405f257fSFrank Li 
185405f257fSFrank Li #define FEC_ENET_RX_PAGES	8
186405f257fSFrank Li #define FEC_ENET_RX_FRSIZE	2048
187405f257fSFrank Li #define FEC_ENET_RX_FRPPG	(PAGE_SIZE / FEC_ENET_RX_FRSIZE)
188405f257fSFrank Li #define RX_RING_SIZE		(FEC_ENET_RX_FRPPG * FEC_ENET_RX_PAGES)
189405f257fSFrank Li #define FEC_ENET_TX_FRSIZE	2048
190405f257fSFrank Li #define FEC_ENET_TX_FRPPG	(PAGE_SIZE / FEC_ENET_TX_FRSIZE)
191405f257fSFrank Li #define TX_RING_SIZE		16	/* Must be power of two */
192405f257fSFrank Li #define TX_RING_MOD_MASK	15	/*   for this to work */
193405f257fSFrank Li 
194405f257fSFrank Li #define BD_ENET_RX_INT          0x00800000
195405f257fSFrank Li #define BD_ENET_RX_PTP          ((ushort)0x0400)
1964c09eed9SJim Baxter #define BD_ENET_RX_ICE		0x00000020
1974c09eed9SJim Baxter #define BD_ENET_RX_PCR		0x00000010
1984c09eed9SJim Baxter #define FLAG_RX_CSUM_ENABLED	(BD_ENET_RX_ICE | BD_ENET_RX_PCR)
1994c09eed9SJim Baxter #define FLAG_RX_CSUM_ERROR	(BD_ENET_RX_ICE | BD_ENET_RX_PCR)
200405f257fSFrank Li 
201*54309fa6SFrank Li struct fec_enet_delayed_work {
202*54309fa6SFrank Li 	struct delayed_work delay_work;
203*54309fa6SFrank Li 	bool timeout;
204*54309fa6SFrank Li };
205*54309fa6SFrank Li 
206405f257fSFrank Li /* The FEC buffer descriptors track the ring buffers.  The rx_bd_base and
207405f257fSFrank Li  * tx_bd_base always point to the base of the buffer descriptors.  The
208405f257fSFrank Li  * cur_rx and cur_tx point to the currently available buffer.
209405f257fSFrank Li  * The dirty_tx tracks the current buffer that is being sent by the
210405f257fSFrank Li  * controller.  The cur_tx and dirty_tx are equal under both completely
211405f257fSFrank Li  * empty and completely full conditions.  The empty/ready indicator in
212405f257fSFrank Li  * the buffer descriptor determines the actual condition.
213405f257fSFrank Li  */
214405f257fSFrank Li struct fec_enet_private {
215405f257fSFrank Li 	/* Hardware registers of the FEC device */
216405f257fSFrank Li 	void __iomem *hwp;
217405f257fSFrank Li 
218405f257fSFrank Li 	struct net_device *netdev;
219405f257fSFrank Li 
220405f257fSFrank Li 	struct clk *clk_ipg;
221405f257fSFrank Li 	struct clk *clk_ahb;
222daa7d392SWolfram Sang 	struct clk *clk_enet_out;
2236605b730SFrank Li 	struct clk *clk_ptp;
224405f257fSFrank Li 
225405f257fSFrank Li 	/* The saved address of a sent-in-place packet/buffer, for skfree(). */
226405f257fSFrank Li 	unsigned char *tx_bounce[TX_RING_SIZE];
227405f257fSFrank Li 	struct	sk_buff *tx_skbuff[TX_RING_SIZE];
228405f257fSFrank Li 	struct	sk_buff *rx_skbuff[RX_RING_SIZE];
229405f257fSFrank Li 
230405f257fSFrank Li 	/* CPM dual port RAM relative addresses */
231405f257fSFrank Li 	dma_addr_t	bd_dma;
232405f257fSFrank Li 	/* Address of Rx and Tx buffers */
233405f257fSFrank Li 	struct bufdesc	*rx_bd_base;
234405f257fSFrank Li 	struct bufdesc	*tx_bd_base;
235405f257fSFrank Li 	/* The next free ring entry */
236405f257fSFrank Li 	struct bufdesc	*cur_rx, *cur_tx;
237405f257fSFrank Li 	/* The ring entries to be free()ed */
238405f257fSFrank Li 	struct bufdesc	*dirty_tx;
239405f257fSFrank Li 
240405f257fSFrank Li 	struct	platform_device *pdev;
241405f257fSFrank Li 
242405f257fSFrank Li 	int	opened;
243405f257fSFrank Li 	int	dev_id;
244405f257fSFrank Li 
245405f257fSFrank Li 	/* Phylib and MDIO interface */
246405f257fSFrank Li 	struct	mii_bus *mii_bus;
247405f257fSFrank Li 	struct	phy_device *phy_dev;
248405f257fSFrank Li 	int	mii_timeout;
249405f257fSFrank Li 	uint	phy_speed;
250405f257fSFrank Li 	phy_interface_t	phy_interface;
251405f257fSFrank Li 	int	link;
252405f257fSFrank Li 	int	full_duplex;
253d97e7497SLucas Stach 	int	speed;
254405f257fSFrank Li 	struct	completion mdio_done;
255405f257fSFrank Li 	int	irq[FEC_IRQ_NUM];
256ff43da86SFrank Li 	int	bufdesc_ex;
257baa70a5cSFrank Li 	int	pause_flag;
2586605b730SFrank Li 
259dc975382SFrank Li 	struct	napi_struct napi;
2604c09eed9SJim Baxter 	int	csum_flags;
261dc975382SFrank Li 
2626605b730SFrank Li 	struct ptp_clock *ptp_clock;
2636605b730SFrank Li 	struct ptp_clock_info ptp_caps;
2646605b730SFrank Li 	unsigned long last_overflow_check;
2656605b730SFrank Li 	spinlock_t tmreg_lock;
2666605b730SFrank Li 	struct cyclecounter cc;
2676605b730SFrank Li 	struct timecounter tc;
2686605b730SFrank Li 	int rx_hwtstamp_filter;
2696605b730SFrank Li 	u32 base_incval;
2706605b730SFrank Li 	u32 cycle_speed;
2716605b730SFrank Li 	int hwts_rx_en;
2726605b730SFrank Li 	int hwts_tx_en;
2736605b730SFrank Li 	struct timer_list time_keep;
274*54309fa6SFrank Li 	struct fec_enet_delayed_work delay_work;
275405f257fSFrank Li };
276ec21e2ecSJeff Kirsher 
2776605b730SFrank Li void fec_ptp_init(struct net_device *ndev, struct platform_device *pdev);
2786605b730SFrank Li void fec_ptp_start_cyclecounter(struct net_device *ndev);
2796605b730SFrank Li int fec_ptp_ioctl(struct net_device *ndev, struct ifreq *ifr, int cmd);
2806605b730SFrank Li 
281ec21e2ecSJeff Kirsher /****************************************************************************/
282ec21e2ecSJeff Kirsher #endif /* FEC_H */
283