blob: d50057c244b291298ced3ee13e30249b2091b87a [file] [log] [blame]
Haavard Skinnemoen89e57852006-11-09 14:51:17 +01001/*
2 * Atmel MACB Ethernet Controller driver
3 *
4 * Copyright (C) 2004-2006 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#ifndef _MACB_H
11#define _MACB_H
12
13/* MACB register offsets */
14#define MACB_NCR 0x0000
15#define MACB_NCFGR 0x0004
16#define MACB_NSR 0x0008
17#define MACB_TSR 0x0014
18#define MACB_RBQP 0x0018
19#define MACB_TBQP 0x001c
20#define MACB_RSR 0x0020
21#define MACB_ISR 0x0024
22#define MACB_IER 0x0028
23#define MACB_IDR 0x002c
24#define MACB_IMR 0x0030
25#define MACB_MAN 0x0034
26#define MACB_PTR 0x0038
27#define MACB_PFR 0x003c
28#define MACB_FTO 0x0040
29#define MACB_SCF 0x0044
30#define MACB_MCF 0x0048
31#define MACB_FRO 0x004c
32#define MACB_FCSE 0x0050
33#define MACB_ALE 0x0054
34#define MACB_DTF 0x0058
35#define MACB_LCOL 0x005c
36#define MACB_EXCOL 0x0060
37#define MACB_TUND 0x0064
38#define MACB_CSE 0x0068
39#define MACB_RRE 0x006c
40#define MACB_ROVR 0x0070
41#define MACB_RSE 0x0074
42#define MACB_ELE 0x0078
43#define MACB_RJA 0x007c
44#define MACB_USF 0x0080
45#define MACB_STE 0x0084
46#define MACB_RLE 0x0088
47#define MACB_TPF 0x008c
48#define MACB_HRB 0x0090
49#define MACB_HRT 0x0094
50#define MACB_SA1B 0x0098
51#define MACB_SA1T 0x009c
52#define MACB_SA2B 0x00a0
53#define MACB_SA2T 0x00a4
54#define MACB_SA3B 0x00a8
55#define MACB_SA3T 0x00ac
56#define MACB_SA4B 0x00b0
57#define MACB_SA4T 0x00b4
58#define MACB_TID 0x00b8
59#define MACB_TPQ 0x00bc
60#define MACB_USRIO 0x00c0
61#define MACB_WOL 0x00c4
Jamie Ilesf75ba502011-11-08 10:12:32 +000062#define MACB_MID 0x00fc
63
64/* GEM register offsets. */
65#define GEM_NCFGR 0x0004
66#define GEM_USRIO 0x000c
67#define GEM_HRB 0x0080
68#define GEM_HRT 0x0084
69#define GEM_SA1B 0x0088
70#define GEM_SA1T 0x008C
Haavard Skinnemoen89e57852006-11-09 14:51:17 +010071
72/* Bitfields in NCR */
73#define MACB_LB_OFFSET 0
74#define MACB_LB_SIZE 1
75#define MACB_LLB_OFFSET 1
76#define MACB_LLB_SIZE 1
77#define MACB_RE_OFFSET 2
78#define MACB_RE_SIZE 1
79#define MACB_TE_OFFSET 3
80#define MACB_TE_SIZE 1
81#define MACB_MPE_OFFSET 4
82#define MACB_MPE_SIZE 1
83#define MACB_CLRSTAT_OFFSET 5
84#define MACB_CLRSTAT_SIZE 1
85#define MACB_INCSTAT_OFFSET 6
86#define MACB_INCSTAT_SIZE 1
87#define MACB_WESTAT_OFFSET 7
88#define MACB_WESTAT_SIZE 1
89#define MACB_BP_OFFSET 8
90#define MACB_BP_SIZE 1
91#define MACB_TSTART_OFFSET 9
92#define MACB_TSTART_SIZE 1
93#define MACB_THALT_OFFSET 10
94#define MACB_THALT_SIZE 1
95#define MACB_NCR_TPF_OFFSET 11
96#define MACB_NCR_TPF_SIZE 1
97#define MACB_TZQ_OFFSET 12
98#define MACB_TZQ_SIZE 1
99
100/* Bitfields in NCFGR */
101#define MACB_SPD_OFFSET 0
102#define MACB_SPD_SIZE 1
103#define MACB_FD_OFFSET 1
104#define MACB_FD_SIZE 1
105#define MACB_BIT_RATE_OFFSET 2
106#define MACB_BIT_RATE_SIZE 1
107#define MACB_JFRAME_OFFSET 3
108#define MACB_JFRAME_SIZE 1
109#define MACB_CAF_OFFSET 4
110#define MACB_CAF_SIZE 1
111#define MACB_NBC_OFFSET 5
112#define MACB_NBC_SIZE 1
113#define MACB_NCFGR_MTI_OFFSET 6
114#define MACB_NCFGR_MTI_SIZE 1
115#define MACB_UNI_OFFSET 7
116#define MACB_UNI_SIZE 1
117#define MACB_BIG_OFFSET 8
118#define MACB_BIG_SIZE 1
119#define MACB_EAE_OFFSET 9
120#define MACB_EAE_SIZE 1
121#define MACB_CLK_OFFSET 10
122#define MACB_CLK_SIZE 2
123#define MACB_RTY_OFFSET 12
124#define MACB_RTY_SIZE 1
125#define MACB_PAE_OFFSET 13
126#define MACB_PAE_SIZE 1
127#define MACB_RBOF_OFFSET 14
128#define MACB_RBOF_SIZE 2
129#define MACB_RLCE_OFFSET 16
130#define MACB_RLCE_SIZE 1
131#define MACB_DRFCS_OFFSET 17
132#define MACB_DRFCS_SIZE 1
133#define MACB_EFRHD_OFFSET 18
134#define MACB_EFRHD_SIZE 1
135#define MACB_IRXFCS_OFFSET 19
136#define MACB_IRXFCS_SIZE 1
137
138/* Bitfields in NSR */
139#define MACB_NSR_LINK_OFFSET 0
140#define MACB_NSR_LINK_SIZE 1
141#define MACB_MDIO_OFFSET 1
142#define MACB_MDIO_SIZE 1
143#define MACB_IDLE_OFFSET 2
144#define MACB_IDLE_SIZE 1
145
146/* Bitfields in TSR */
147#define MACB_UBR_OFFSET 0
148#define MACB_UBR_SIZE 1
149#define MACB_COL_OFFSET 1
150#define MACB_COL_SIZE 1
151#define MACB_TSR_RLE_OFFSET 2
152#define MACB_TSR_RLE_SIZE 1
153#define MACB_TGO_OFFSET 3
154#define MACB_TGO_SIZE 1
155#define MACB_BEX_OFFSET 4
156#define MACB_BEX_SIZE 1
157#define MACB_COMP_OFFSET 5
158#define MACB_COMP_SIZE 1
159#define MACB_UND_OFFSET 6
160#define MACB_UND_SIZE 1
161
162/* Bitfields in RSR */
163#define MACB_BNA_OFFSET 0
164#define MACB_BNA_SIZE 1
165#define MACB_REC_OFFSET 1
166#define MACB_REC_SIZE 1
167#define MACB_OVR_OFFSET 2
168#define MACB_OVR_SIZE 1
169
170/* Bitfields in ISR/IER/IDR/IMR */
171#define MACB_MFD_OFFSET 0
172#define MACB_MFD_SIZE 1
173#define MACB_RCOMP_OFFSET 1
174#define MACB_RCOMP_SIZE 1
175#define MACB_RXUBR_OFFSET 2
176#define MACB_RXUBR_SIZE 1
177#define MACB_TXUBR_OFFSET 3
178#define MACB_TXUBR_SIZE 1
179#define MACB_ISR_TUND_OFFSET 4
180#define MACB_ISR_TUND_SIZE 1
181#define MACB_ISR_RLE_OFFSET 5
182#define MACB_ISR_RLE_SIZE 1
183#define MACB_TXERR_OFFSET 6
184#define MACB_TXERR_SIZE 1
185#define MACB_TCOMP_OFFSET 7
186#define MACB_TCOMP_SIZE 1
187#define MACB_ISR_LINK_OFFSET 9
188#define MACB_ISR_LINK_SIZE 1
189#define MACB_ISR_ROVR_OFFSET 10
190#define MACB_ISR_ROVR_SIZE 1
191#define MACB_HRESP_OFFSET 11
192#define MACB_HRESP_SIZE 1
193#define MACB_PFR_OFFSET 12
194#define MACB_PFR_SIZE 1
195#define MACB_PTZ_OFFSET 13
196#define MACB_PTZ_SIZE 1
197
198/* Bitfields in MAN */
199#define MACB_DATA_OFFSET 0
200#define MACB_DATA_SIZE 16
201#define MACB_CODE_OFFSET 16
202#define MACB_CODE_SIZE 2
203#define MACB_REGA_OFFSET 18
204#define MACB_REGA_SIZE 5
205#define MACB_PHYA_OFFSET 23
206#define MACB_PHYA_SIZE 5
207#define MACB_RW_OFFSET 28
208#define MACB_RW_SIZE 2
209#define MACB_SOF_OFFSET 30
210#define MACB_SOF_SIZE 2
211
Andrew Victor0cc86742007-02-07 16:40:44 +0100212/* Bitfields in USRIO (AVR32) */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100213#define MACB_MII_OFFSET 0
214#define MACB_MII_SIZE 1
215#define MACB_EAM_OFFSET 1
216#define MACB_EAM_SIZE 1
217#define MACB_TX_PAUSE_OFFSET 2
218#define MACB_TX_PAUSE_SIZE 1
219#define MACB_TX_PAUSE_ZERO_OFFSET 3
220#define MACB_TX_PAUSE_ZERO_SIZE 1
221
Andrew Victor0cc86742007-02-07 16:40:44 +0100222/* Bitfields in USRIO (AT91) */
223#define MACB_RMII_OFFSET 0
224#define MACB_RMII_SIZE 1
225#define MACB_CLKEN_OFFSET 1
226#define MACB_CLKEN_SIZE 1
227
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100228/* Bitfields in WOL */
229#define MACB_IP_OFFSET 0
230#define MACB_IP_SIZE 16
231#define MACB_MAG_OFFSET 16
232#define MACB_MAG_SIZE 1
233#define MACB_ARP_OFFSET 17
234#define MACB_ARP_SIZE 1
235#define MACB_SA1_OFFSET 18
236#define MACB_SA1_SIZE 1
237#define MACB_WOL_MTI_OFFSET 19
238#define MACB_WOL_MTI_SIZE 1
239
Jamie Ilesf75ba502011-11-08 10:12:32 +0000240/* Bitfields in MID */
241#define MACB_IDNUM_OFFSET 16
242#define MACB_IDNUM_SIZE 16
243#define MACB_REV_OFFSET 0
244#define MACB_REV_SIZE 16
245
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100246/* Constants for CLK */
247#define MACB_CLK_DIV8 0
248#define MACB_CLK_DIV16 1
249#define MACB_CLK_DIV32 2
250#define MACB_CLK_DIV64 3
251
252/* Constants for MAN register */
253#define MACB_MAN_SOF 1
254#define MACB_MAN_WRITE 1
255#define MACB_MAN_READ 2
256#define MACB_MAN_CODE 2
257
258/* Bit manipulation macros */
259#define MACB_BIT(name) \
260 (1 << MACB_##name##_OFFSET)
261#define MACB_BF(name,value) \
262 (((value) & ((1 << MACB_##name##_SIZE) - 1)) \
263 << MACB_##name##_OFFSET)
264#define MACB_BFEXT(name,value)\
265 (((value) >> MACB_##name##_OFFSET) \
266 & ((1 << MACB_##name##_SIZE) - 1))
267#define MACB_BFINS(name,value,old) \
268 (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \
269 << MACB_##name##_OFFSET)) \
270 | MACB_BF(name,value))
271
Jamie Ilesf75ba502011-11-08 10:12:32 +0000272#define GEM_BIT(name) \
273 (1 << GEM_##name##_OFFSET)
274#define GEM_BF(name, value) \
275 (((value) & ((1 << GEM_##name##_SIZE) - 1)) \
276 << GEM_##name##_OFFSET)
277#define GEM_BFEXT(name, value)\
278 (((value) >> GEM_##name##_OFFSET) \
279 & ((1 << GEM_##name##_SIZE) - 1))
280#define GEM_BFINS(name, value, old) \
281 (((old) & ~(((1 << GEM_##name##_SIZE) - 1) \
282 << GEM_##name##_OFFSET)) \
283 | GEM_BF(name, value))
284
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100285/* Register access macros */
286#define macb_readl(port,reg) \
Haavard Skinnemoen0f0d84e2006-12-08 14:38:30 +0100287 __raw_readl((port)->regs + MACB_##reg)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100288#define macb_writel(port,reg,value) \
Haavard Skinnemoen0f0d84e2006-12-08 14:38:30 +0100289 __raw_writel((value), (port)->regs + MACB_##reg)
Jamie Ilesf75ba502011-11-08 10:12:32 +0000290#define gem_readl(port, reg) \
291 __raw_readl((port)->regs + GEM_##reg)
292#define gem_writel(port, reg, value) \
293 __raw_writel((value), (port)->regs + GEM_##reg)
294
295/*
296 * Conditional GEM/MACB macros. These perform the operation to the correct
297 * register dependent on whether the device is a GEM or a MACB. For registers
298 * and bitfields that are common across both devices, use macb_{read,write}l
299 * to avoid the cost of the conditional.
300 */
301#define macb_or_gem_writel(__bp, __reg, __value) \
302 ({ \
303 if (macb_is_gem((__bp))) \
304 gem_writel((__bp), __reg, __value); \
305 else \
306 macb_writel((__bp), __reg, __value); \
307 })
308
309#define macb_or_gem_readl(__bp, __reg) \
310 ({ \
311 u32 __v; \
312 if (macb_is_gem((__bp))) \
313 __v = gem_readl((__bp), __reg); \
314 else \
315 __v = macb_readl((__bp), __reg); \
316 __v; \
317 })
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100318
319struct dma_desc {
320 u32 addr;
321 u32 ctrl;
322};
323
324/* DMA descriptor bitfields */
325#define MACB_RX_USED_OFFSET 0
326#define MACB_RX_USED_SIZE 1
327#define MACB_RX_WRAP_OFFSET 1
328#define MACB_RX_WRAP_SIZE 1
329#define MACB_RX_WADDR_OFFSET 2
330#define MACB_RX_WADDR_SIZE 30
331
332#define MACB_RX_FRMLEN_OFFSET 0
333#define MACB_RX_FRMLEN_SIZE 12
334#define MACB_RX_OFFSET_OFFSET 12
335#define MACB_RX_OFFSET_SIZE 2
336#define MACB_RX_SOF_OFFSET 14
337#define MACB_RX_SOF_SIZE 1
338#define MACB_RX_EOF_OFFSET 15
339#define MACB_RX_EOF_SIZE 1
340#define MACB_RX_CFI_OFFSET 16
341#define MACB_RX_CFI_SIZE 1
342#define MACB_RX_VLAN_PRI_OFFSET 17
343#define MACB_RX_VLAN_PRI_SIZE 3
344#define MACB_RX_PRI_TAG_OFFSET 20
345#define MACB_RX_PRI_TAG_SIZE 1
346#define MACB_RX_VLAN_TAG_OFFSET 21
347#define MACB_RX_VLAN_TAG_SIZE 1
348#define MACB_RX_TYPEID_MATCH_OFFSET 22
349#define MACB_RX_TYPEID_MATCH_SIZE 1
350#define MACB_RX_SA4_MATCH_OFFSET 23
351#define MACB_RX_SA4_MATCH_SIZE 1
352#define MACB_RX_SA3_MATCH_OFFSET 24
353#define MACB_RX_SA3_MATCH_SIZE 1
354#define MACB_RX_SA2_MATCH_OFFSET 25
355#define MACB_RX_SA2_MATCH_SIZE 1
356#define MACB_RX_SA1_MATCH_OFFSET 26
357#define MACB_RX_SA1_MATCH_SIZE 1
358#define MACB_RX_EXT_MATCH_OFFSET 28
359#define MACB_RX_EXT_MATCH_SIZE 1
360#define MACB_RX_UHASH_MATCH_OFFSET 29
361#define MACB_RX_UHASH_MATCH_SIZE 1
362#define MACB_RX_MHASH_MATCH_OFFSET 30
363#define MACB_RX_MHASH_MATCH_SIZE 1
364#define MACB_RX_BROADCAST_OFFSET 31
365#define MACB_RX_BROADCAST_SIZE 1
366
367#define MACB_TX_FRMLEN_OFFSET 0
368#define MACB_TX_FRMLEN_SIZE 11
369#define MACB_TX_LAST_OFFSET 15
370#define MACB_TX_LAST_SIZE 1
371#define MACB_TX_NOCRC_OFFSET 16
372#define MACB_TX_NOCRC_SIZE 1
373#define MACB_TX_BUF_EXHAUSTED_OFFSET 27
374#define MACB_TX_BUF_EXHAUSTED_SIZE 1
375#define MACB_TX_UNDERRUN_OFFSET 28
376#define MACB_TX_UNDERRUN_SIZE 1
377#define MACB_TX_ERROR_OFFSET 29
378#define MACB_TX_ERROR_SIZE 1
379#define MACB_TX_WRAP_OFFSET 30
380#define MACB_TX_WRAP_SIZE 1
381#define MACB_TX_USED_OFFSET 31
382#define MACB_TX_USED_SIZE 1
383
384struct ring_info {
385 struct sk_buff *skb;
386 dma_addr_t mapping;
387};
388
389/*
390 * Hardware-collected statistics. Used when updating the network
391 * device stats by a periodic timer.
392 */
393struct macb_stats {
394 u32 rx_pause_frames;
395 u32 tx_ok;
396 u32 tx_single_cols;
397 u32 tx_multiple_cols;
398 u32 rx_ok;
399 u32 rx_fcs_errors;
400 u32 rx_align_errors;
401 u32 tx_deferred;
402 u32 tx_late_cols;
403 u32 tx_excessive_cols;
404 u32 tx_underruns;
405 u32 tx_carrier_errors;
406 u32 rx_resource_errors;
407 u32 rx_overruns;
408 u32 rx_symbol_errors;
409 u32 rx_oversize_pkts;
410 u32 rx_jabbers;
411 u32 rx_undersize_pkts;
412 u32 sqe_test_errors;
413 u32 rx_length_mismatch;
414 u32 tx_pause_frames;
415};
416
417struct macb {
418 void __iomem *regs;
419
420 unsigned int rx_tail;
421 struct dma_desc *rx_ring;
422 void *rx_buffers;
423
424 unsigned int tx_head, tx_tail;
425 struct dma_desc *tx_ring;
426 struct ring_info *tx_skb;
427
428 spinlock_t lock;
429 struct platform_device *pdev;
430 struct clk *pclk;
431 struct clk *hclk;
432 struct net_device *dev;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700433 struct napi_struct napi;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100434 struct net_device_stats stats;
435 struct macb_stats hw_stats;
436
437 dma_addr_t rx_ring_dma;
438 dma_addr_t tx_ring_dma;
439 dma_addr_t rx_buffers_dma;
440
441 unsigned int rx_pending, tx_pending;
442
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700443 struct mii_bus *mii_bus;
frederic RODO6c36a702007-07-12 19:07:24 +0200444 struct phy_device *phy_dev;
445 unsigned int link;
446 unsigned int speed;
447 unsigned int duplex;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100448};
449
Jamie Ilesf75ba502011-11-08 10:12:32 +0000450static inline bool macb_is_gem(struct macb *bp)
451{
452 return MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2;
453}
454
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100455#endif /* _MACB_H */