blob: 354ed8f77884e6f8f5bb6d70f2899a56adcaa4a4 [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
Jamie Iles70c9f3d2011-03-09 16:22:54 +0000138/* GEM specific NCFGR bitfields. */
139#define GEM_CLK_OFFSET 18
140#define GEM_CLK_SIZE 3
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100141/* Bitfields in NSR */
142#define MACB_NSR_LINK_OFFSET 0
143#define MACB_NSR_LINK_SIZE 1
144#define MACB_MDIO_OFFSET 1
145#define MACB_MDIO_SIZE 1
146#define MACB_IDLE_OFFSET 2
147#define MACB_IDLE_SIZE 1
148
149/* Bitfields in TSR */
150#define MACB_UBR_OFFSET 0
151#define MACB_UBR_SIZE 1
152#define MACB_COL_OFFSET 1
153#define MACB_COL_SIZE 1
154#define MACB_TSR_RLE_OFFSET 2
155#define MACB_TSR_RLE_SIZE 1
156#define MACB_TGO_OFFSET 3
157#define MACB_TGO_SIZE 1
158#define MACB_BEX_OFFSET 4
159#define MACB_BEX_SIZE 1
160#define MACB_COMP_OFFSET 5
161#define MACB_COMP_SIZE 1
162#define MACB_UND_OFFSET 6
163#define MACB_UND_SIZE 1
164
165/* Bitfields in RSR */
166#define MACB_BNA_OFFSET 0
167#define MACB_BNA_SIZE 1
168#define MACB_REC_OFFSET 1
169#define MACB_REC_SIZE 1
170#define MACB_OVR_OFFSET 2
171#define MACB_OVR_SIZE 1
172
173/* Bitfields in ISR/IER/IDR/IMR */
174#define MACB_MFD_OFFSET 0
175#define MACB_MFD_SIZE 1
176#define MACB_RCOMP_OFFSET 1
177#define MACB_RCOMP_SIZE 1
178#define MACB_RXUBR_OFFSET 2
179#define MACB_RXUBR_SIZE 1
180#define MACB_TXUBR_OFFSET 3
181#define MACB_TXUBR_SIZE 1
182#define MACB_ISR_TUND_OFFSET 4
183#define MACB_ISR_TUND_SIZE 1
184#define MACB_ISR_RLE_OFFSET 5
185#define MACB_ISR_RLE_SIZE 1
186#define MACB_TXERR_OFFSET 6
187#define MACB_TXERR_SIZE 1
188#define MACB_TCOMP_OFFSET 7
189#define MACB_TCOMP_SIZE 1
190#define MACB_ISR_LINK_OFFSET 9
191#define MACB_ISR_LINK_SIZE 1
192#define MACB_ISR_ROVR_OFFSET 10
193#define MACB_ISR_ROVR_SIZE 1
194#define MACB_HRESP_OFFSET 11
195#define MACB_HRESP_SIZE 1
196#define MACB_PFR_OFFSET 12
197#define MACB_PFR_SIZE 1
198#define MACB_PTZ_OFFSET 13
199#define MACB_PTZ_SIZE 1
200
201/* Bitfields in MAN */
202#define MACB_DATA_OFFSET 0
203#define MACB_DATA_SIZE 16
204#define MACB_CODE_OFFSET 16
205#define MACB_CODE_SIZE 2
206#define MACB_REGA_OFFSET 18
207#define MACB_REGA_SIZE 5
208#define MACB_PHYA_OFFSET 23
209#define MACB_PHYA_SIZE 5
210#define MACB_RW_OFFSET 28
211#define MACB_RW_SIZE 2
212#define MACB_SOF_OFFSET 30
213#define MACB_SOF_SIZE 2
214
Andrew Victor0cc86742007-02-07 16:40:44 +0100215/* Bitfields in USRIO (AVR32) */
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100216#define MACB_MII_OFFSET 0
217#define MACB_MII_SIZE 1
218#define MACB_EAM_OFFSET 1
219#define MACB_EAM_SIZE 1
220#define MACB_TX_PAUSE_OFFSET 2
221#define MACB_TX_PAUSE_SIZE 1
222#define MACB_TX_PAUSE_ZERO_OFFSET 3
223#define MACB_TX_PAUSE_ZERO_SIZE 1
224
Andrew Victor0cc86742007-02-07 16:40:44 +0100225/* Bitfields in USRIO (AT91) */
226#define MACB_RMII_OFFSET 0
227#define MACB_RMII_SIZE 1
228#define MACB_CLKEN_OFFSET 1
229#define MACB_CLKEN_SIZE 1
230
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100231/* Bitfields in WOL */
232#define MACB_IP_OFFSET 0
233#define MACB_IP_SIZE 16
234#define MACB_MAG_OFFSET 16
235#define MACB_MAG_SIZE 1
236#define MACB_ARP_OFFSET 17
237#define MACB_ARP_SIZE 1
238#define MACB_SA1_OFFSET 18
239#define MACB_SA1_SIZE 1
240#define MACB_WOL_MTI_OFFSET 19
241#define MACB_WOL_MTI_SIZE 1
242
Jamie Ilesf75ba502011-11-08 10:12:32 +0000243/* Bitfields in MID */
244#define MACB_IDNUM_OFFSET 16
245#define MACB_IDNUM_SIZE 16
246#define MACB_REV_OFFSET 0
247#define MACB_REV_SIZE 16
248
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100249/* Constants for CLK */
250#define MACB_CLK_DIV8 0
251#define MACB_CLK_DIV16 1
252#define MACB_CLK_DIV32 2
253#define MACB_CLK_DIV64 3
254
Jamie Iles70c9f3d2011-03-09 16:22:54 +0000255/* GEM specific constants for CLK. */
256#define GEM_CLK_DIV8 0
257#define GEM_CLK_DIV16 1
258#define GEM_CLK_DIV32 2
259#define GEM_CLK_DIV48 3
260#define GEM_CLK_DIV64 4
261#define GEM_CLK_DIV96 5
262
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100263/* Constants for MAN register */
264#define MACB_MAN_SOF 1
265#define MACB_MAN_WRITE 1
266#define MACB_MAN_READ 2
267#define MACB_MAN_CODE 2
268
269/* Bit manipulation macros */
270#define MACB_BIT(name) \
271 (1 << MACB_##name##_OFFSET)
272#define MACB_BF(name,value) \
273 (((value) & ((1 << MACB_##name##_SIZE) - 1)) \
274 << MACB_##name##_OFFSET)
275#define MACB_BFEXT(name,value)\
276 (((value) >> MACB_##name##_OFFSET) \
277 & ((1 << MACB_##name##_SIZE) - 1))
278#define MACB_BFINS(name,value,old) \
279 (((old) & ~(((1 << MACB_##name##_SIZE) - 1) \
280 << MACB_##name##_OFFSET)) \
281 | MACB_BF(name,value))
282
Jamie Ilesf75ba502011-11-08 10:12:32 +0000283#define GEM_BIT(name) \
284 (1 << GEM_##name##_OFFSET)
285#define GEM_BF(name, value) \
286 (((value) & ((1 << GEM_##name##_SIZE) - 1)) \
287 << GEM_##name##_OFFSET)
288#define GEM_BFEXT(name, value)\
289 (((value) >> GEM_##name##_OFFSET) \
290 & ((1 << GEM_##name##_SIZE) - 1))
291#define GEM_BFINS(name, value, old) \
292 (((old) & ~(((1 << GEM_##name##_SIZE) - 1) \
293 << GEM_##name##_OFFSET)) \
294 | GEM_BF(name, value))
295
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100296/* Register access macros */
297#define macb_readl(port,reg) \
Haavard Skinnemoen0f0d84e2006-12-08 14:38:30 +0100298 __raw_readl((port)->regs + MACB_##reg)
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100299#define macb_writel(port,reg,value) \
Haavard Skinnemoen0f0d84e2006-12-08 14:38:30 +0100300 __raw_writel((value), (port)->regs + MACB_##reg)
Jamie Ilesf75ba502011-11-08 10:12:32 +0000301#define gem_readl(port, reg) \
302 __raw_readl((port)->regs + GEM_##reg)
303#define gem_writel(port, reg, value) \
304 __raw_writel((value), (port)->regs + GEM_##reg)
305
306/*
307 * Conditional GEM/MACB macros. These perform the operation to the correct
308 * register dependent on whether the device is a GEM or a MACB. For registers
309 * and bitfields that are common across both devices, use macb_{read,write}l
310 * to avoid the cost of the conditional.
311 */
312#define macb_or_gem_writel(__bp, __reg, __value) \
313 ({ \
314 if (macb_is_gem((__bp))) \
315 gem_writel((__bp), __reg, __value); \
316 else \
317 macb_writel((__bp), __reg, __value); \
318 })
319
320#define macb_or_gem_readl(__bp, __reg) \
321 ({ \
322 u32 __v; \
323 if (macb_is_gem((__bp))) \
324 __v = gem_readl((__bp), __reg); \
325 else \
326 __v = macb_readl((__bp), __reg); \
327 __v; \
328 })
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100329
330struct dma_desc {
331 u32 addr;
332 u32 ctrl;
333};
334
335/* DMA descriptor bitfields */
336#define MACB_RX_USED_OFFSET 0
337#define MACB_RX_USED_SIZE 1
338#define MACB_RX_WRAP_OFFSET 1
339#define MACB_RX_WRAP_SIZE 1
340#define MACB_RX_WADDR_OFFSET 2
341#define MACB_RX_WADDR_SIZE 30
342
343#define MACB_RX_FRMLEN_OFFSET 0
344#define MACB_RX_FRMLEN_SIZE 12
345#define MACB_RX_OFFSET_OFFSET 12
346#define MACB_RX_OFFSET_SIZE 2
347#define MACB_RX_SOF_OFFSET 14
348#define MACB_RX_SOF_SIZE 1
349#define MACB_RX_EOF_OFFSET 15
350#define MACB_RX_EOF_SIZE 1
351#define MACB_RX_CFI_OFFSET 16
352#define MACB_RX_CFI_SIZE 1
353#define MACB_RX_VLAN_PRI_OFFSET 17
354#define MACB_RX_VLAN_PRI_SIZE 3
355#define MACB_RX_PRI_TAG_OFFSET 20
356#define MACB_RX_PRI_TAG_SIZE 1
357#define MACB_RX_VLAN_TAG_OFFSET 21
358#define MACB_RX_VLAN_TAG_SIZE 1
359#define MACB_RX_TYPEID_MATCH_OFFSET 22
360#define MACB_RX_TYPEID_MATCH_SIZE 1
361#define MACB_RX_SA4_MATCH_OFFSET 23
362#define MACB_RX_SA4_MATCH_SIZE 1
363#define MACB_RX_SA3_MATCH_OFFSET 24
364#define MACB_RX_SA3_MATCH_SIZE 1
365#define MACB_RX_SA2_MATCH_OFFSET 25
366#define MACB_RX_SA2_MATCH_SIZE 1
367#define MACB_RX_SA1_MATCH_OFFSET 26
368#define MACB_RX_SA1_MATCH_SIZE 1
369#define MACB_RX_EXT_MATCH_OFFSET 28
370#define MACB_RX_EXT_MATCH_SIZE 1
371#define MACB_RX_UHASH_MATCH_OFFSET 29
372#define MACB_RX_UHASH_MATCH_SIZE 1
373#define MACB_RX_MHASH_MATCH_OFFSET 30
374#define MACB_RX_MHASH_MATCH_SIZE 1
375#define MACB_RX_BROADCAST_OFFSET 31
376#define MACB_RX_BROADCAST_SIZE 1
377
378#define MACB_TX_FRMLEN_OFFSET 0
379#define MACB_TX_FRMLEN_SIZE 11
380#define MACB_TX_LAST_OFFSET 15
381#define MACB_TX_LAST_SIZE 1
382#define MACB_TX_NOCRC_OFFSET 16
383#define MACB_TX_NOCRC_SIZE 1
384#define MACB_TX_BUF_EXHAUSTED_OFFSET 27
385#define MACB_TX_BUF_EXHAUSTED_SIZE 1
386#define MACB_TX_UNDERRUN_OFFSET 28
387#define MACB_TX_UNDERRUN_SIZE 1
388#define MACB_TX_ERROR_OFFSET 29
389#define MACB_TX_ERROR_SIZE 1
390#define MACB_TX_WRAP_OFFSET 30
391#define MACB_TX_WRAP_SIZE 1
392#define MACB_TX_USED_OFFSET 31
393#define MACB_TX_USED_SIZE 1
394
395struct ring_info {
396 struct sk_buff *skb;
397 dma_addr_t mapping;
398};
399
400/*
401 * Hardware-collected statistics. Used when updating the network
402 * device stats by a periodic timer.
403 */
404struct macb_stats {
405 u32 rx_pause_frames;
406 u32 tx_ok;
407 u32 tx_single_cols;
408 u32 tx_multiple_cols;
409 u32 rx_ok;
410 u32 rx_fcs_errors;
411 u32 rx_align_errors;
412 u32 tx_deferred;
413 u32 tx_late_cols;
414 u32 tx_excessive_cols;
415 u32 tx_underruns;
416 u32 tx_carrier_errors;
417 u32 rx_resource_errors;
418 u32 rx_overruns;
419 u32 rx_symbol_errors;
420 u32 rx_oversize_pkts;
421 u32 rx_jabbers;
422 u32 rx_undersize_pkts;
423 u32 sqe_test_errors;
424 u32 rx_length_mismatch;
425 u32 tx_pause_frames;
426};
427
428struct macb {
429 void __iomem *regs;
430
431 unsigned int rx_tail;
432 struct dma_desc *rx_ring;
433 void *rx_buffers;
434
435 unsigned int tx_head, tx_tail;
436 struct dma_desc *tx_ring;
437 struct ring_info *tx_skb;
438
439 spinlock_t lock;
440 struct platform_device *pdev;
441 struct clk *pclk;
442 struct clk *hclk;
443 struct net_device *dev;
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700444 struct napi_struct napi;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100445 struct net_device_stats stats;
446 struct macb_stats hw_stats;
447
448 dma_addr_t rx_ring_dma;
449 dma_addr_t tx_ring_dma;
450 dma_addr_t rx_buffers_dma;
451
452 unsigned int rx_pending, tx_pending;
453
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700454 struct mii_bus *mii_bus;
frederic RODO6c36a702007-07-12 19:07:24 +0200455 struct phy_device *phy_dev;
456 unsigned int link;
457 unsigned int speed;
458 unsigned int duplex;
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100459};
460
Jamie Ilesf75ba502011-11-08 10:12:32 +0000461static inline bool macb_is_gem(struct macb *bp)
462{
463 return MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2;
464}
465
Haavard Skinnemoen89e57852006-11-09 14:51:17 +0100466#endif /* _MACB_H */