aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/ethernet/cadence
diff options
context:
space:
mode:
authorArnd Bergmann <arnd@arndb.de>2011-11-23 15:47:41 -0500
committerArnd Bergmann <arnd@arndb.de>2011-11-23 15:47:41 -0500
commit58a273745fbb2fbd01d26e7a60f0acc8c1d99469 (patch)
treebc16200f3b6ea150b298422754e32959eaa339bc /drivers/net/ethernet/cadence
parent951c486f62490e032da0ad17e93270b0cfb6687f (diff)
parent0116da4fcc1ae8a80d9002441e98768f2a6fa2fe (diff)
Merge branches 'drivers/macb-gem' and 'drivers/pxa-gpio' into next/drivers
Diffstat (limited to 'drivers/net/ethernet/cadence')
-rw-r--r--drivers/net/ethernet/cadence/Kconfig16
-rw-r--r--drivers/net/ethernet/cadence/at91_ether.c3
-rw-r--r--drivers/net/ethernet/cadence/at91_ether.h4
-rw-r--r--drivers/net/ethernet/cadence/macb.c344
-rw-r--r--drivers/net/ethernet/cadence/macb.h150
5 files changed, 385 insertions, 132 deletions
diff --git a/drivers/net/ethernet/cadence/Kconfig b/drivers/net/ethernet/cadence/Kconfig
index 98849a1fc749..a2e150059bc7 100644
--- a/drivers/net/ethernet/cadence/Kconfig
+++ b/drivers/net/ethernet/cadence/Kconfig
@@ -5,8 +5,8 @@
5config HAVE_NET_MACB 5config HAVE_NET_MACB
6 bool 6 bool
7 7
8config NET_ATMEL 8config NET_CADENCE
9 bool "Atmel devices" 9 bool "Cadence devices"
10 depends on HAVE_NET_MACB || (ARM && ARCH_AT91RM9200) 10 depends on HAVE_NET_MACB || (ARM && ARCH_AT91RM9200)
11 ---help--- 11 ---help---
12 If you have a network (Ethernet) card belonging to this class, say Y. 12 If you have a network (Ethernet) card belonging to this class, say Y.
@@ -20,7 +20,7 @@ config NET_ATMEL
20 the remaining Atmel network card questions. If you say Y, you will be 20 the remaining Atmel network card questions. If you say Y, you will be
21 asked for your specific card in the following questions. 21 asked for your specific card in the following questions.
22 22
23if NET_ATMEL 23if NET_CADENCE
24 24
25config ARM_AT91_ETHER 25config ARM_AT91_ETHER
26 tristate "AT91RM9200 Ethernet support" 26 tristate "AT91RM9200 Ethernet support"
@@ -32,14 +32,16 @@ config ARM_AT91_ETHER
32 ethernet support, then you should always answer Y to this. 32 ethernet support, then you should always answer Y to this.
33 33
34config MACB 34config MACB
35 tristate "Atmel MACB support" 35 tristate "Cadence MACB/GEM support"
36 depends on HAVE_NET_MACB 36 depends on HAVE_NET_MACB
37 select PHYLIB 37 select PHYLIB
38 ---help--- 38 ---help---
39 The Atmel MACB ethernet interface is found on many AT32 and AT91 39 The Cadence MACB ethernet interface is found on many Atmel AT32 and
40 parts. Say Y to include support for the MACB chip. 40 AT91 parts. This driver also supports the Cadence GEM (Gigabit
41 Ethernet MAC found in some ARM SoC devices). Note: the Gigabit mode
42 is not yet supported. Say Y to include support for the MACB/GEM chip.
41 43
42 To compile this driver as a module, choose M here: the module 44 To compile this driver as a module, choose M here: the module
43 will be called macb. 45 will be called macb.
44 46
45endif # NET_ATMEL 47endif # NET_CADENCE
diff --git a/drivers/net/ethernet/cadence/at91_ether.c b/drivers/net/ethernet/cadence/at91_ether.c
index 56624d303487..dfeb46cb3f74 100644
--- a/drivers/net/ethernet/cadence/at91_ether.c
+++ b/drivers/net/ethernet/cadence/at91_ether.c
@@ -26,6 +26,7 @@
26#include <linux/skbuff.h> 26#include <linux/skbuff.h>
27#include <linux/dma-mapping.h> 27#include <linux/dma-mapping.h>
28#include <linux/ethtool.h> 28#include <linux/ethtool.h>
29#include <linux/platform_data/macb.h>
29#include <linux/platform_device.h> 30#include <linux/platform_device.h>
30#include <linux/clk.h> 31#include <linux/clk.h>
31#include <linux/gfp.h> 32#include <linux/gfp.h>
@@ -984,7 +985,7 @@ static const struct net_device_ops at91ether_netdev_ops = {
984static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_address, 985static int __init at91ether_setup(unsigned long phy_type, unsigned short phy_address,
985 struct platform_device *pdev, struct clk *ether_clk) 986 struct platform_device *pdev, struct clk *ether_clk)
986{ 987{
987 struct at91_eth_data *board_data = pdev->dev.platform_data; 988 struct macb_platform_data *board_data = pdev->dev.platform_data;
988 struct net_device *dev; 989 struct net_device *dev;
989 struct at91_private *lp; 990 struct at91_private *lp;
990 unsigned int val; 991 unsigned int val;
diff --git a/drivers/net/ethernet/cadence/at91_ether.h b/drivers/net/ethernet/cadence/at91_ether.h
index 353f4dab62be..3725fbb0defe 100644
--- a/drivers/net/ethernet/cadence/at91_ether.h
+++ b/drivers/net/ethernet/cadence/at91_ether.h
@@ -85,7 +85,9 @@ struct recv_desc_bufs
85struct at91_private 85struct at91_private
86{ 86{
87 struct mii_if_info mii; /* ethtool support */ 87 struct mii_if_info mii; /* ethtool support */
88 struct at91_eth_data board_data; /* board-specific configuration */ 88 struct macb_platform_data board_data; /* board-specific
89 * configuration (shared with
90 * macb for common data */
89 struct clk *ether_clk; /* clock */ 91 struct clk *ether_clk; /* clock */
90 92
91 /* PHY */ 93 /* PHY */
diff --git a/drivers/net/ethernet/cadence/macb.c b/drivers/net/ethernet/cadence/macb.c
index a437b46e5490..64d61461bdc7 100644
--- a/drivers/net/ethernet/cadence/macb.c
+++ b/drivers/net/ethernet/cadence/macb.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Atmel MACB Ethernet Controller driver 2 * Cadence MACB/GEM Ethernet Controller driver
3 * 3 *
4 * Copyright (C) 2004-2006 Atmel Corporation 4 * Copyright (C) 2004-2006 Atmel Corporation
5 * 5 *
@@ -8,6 +8,7 @@
8 * published by the Free Software Foundation. 8 * published by the Free Software Foundation.
9 */ 9 */
10 10
11#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11#include <linux/clk.h> 12#include <linux/clk.h>
12#include <linux/module.h> 13#include <linux/module.h>
13#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
@@ -19,12 +20,10 @@
19#include <linux/netdevice.h> 20#include <linux/netdevice.h>
20#include <linux/etherdevice.h> 21#include <linux/etherdevice.h>
21#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/platform_data/macb.h>
22#include <linux/platform_device.h> 24#include <linux/platform_device.h>
23#include <linux/phy.h> 25#include <linux/phy.h>
24 26
25#include <mach/board.h>
26#include <mach/cpu.h>
27
28#include "macb.h" 27#include "macb.h"
29 28
30#define RX_BUFFER_SIZE 128 29#define RX_BUFFER_SIZE 128
@@ -60,9 +59,9 @@ static void __macb_set_hwaddr(struct macb *bp)
60 u16 top; 59 u16 top;
61 60
62 bottom = cpu_to_le32(*((u32 *)bp->dev->dev_addr)); 61 bottom = cpu_to_le32(*((u32 *)bp->dev->dev_addr));
63 macb_writel(bp, SA1B, bottom); 62 macb_or_gem_writel(bp, SA1B, bottom);
64 top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4))); 63 top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4)));
65 macb_writel(bp, SA1T, top); 64 macb_or_gem_writel(bp, SA1T, top);
66} 65}
67 66
68static void __init macb_get_hwaddr(struct macb *bp) 67static void __init macb_get_hwaddr(struct macb *bp)
@@ -71,8 +70,8 @@ static void __init macb_get_hwaddr(struct macb *bp)
71 u16 top; 70 u16 top;
72 u8 addr[6]; 71 u8 addr[6];
73 72
74 bottom = macb_readl(bp, SA1B); 73 bottom = macb_or_gem_readl(bp, SA1B);
75 top = macb_readl(bp, SA1T); 74 top = macb_or_gem_readl(bp, SA1T);
76 75
77 addr[0] = bottom & 0xff; 76 addr[0] = bottom & 0xff;
78 addr[1] = (bottom >> 8) & 0xff; 77 addr[1] = (bottom >> 8) & 0xff;
@@ -84,7 +83,7 @@ static void __init macb_get_hwaddr(struct macb *bp)
84 if (is_valid_ether_addr(addr)) { 83 if (is_valid_ether_addr(addr)) {
85 memcpy(bp->dev->dev_addr, addr, sizeof(addr)); 84 memcpy(bp->dev->dev_addr, addr, sizeof(addr));
86 } else { 85 } else {
87 dev_info(&bp->pdev->dev, "invalid hw address, using random\n"); 86 netdev_info(bp->dev, "invalid hw address, using random\n");
88 random_ether_addr(bp->dev->dev_addr); 87 random_ether_addr(bp->dev->dev_addr);
89 } 88 }
90} 89}
@@ -178,11 +177,12 @@ static void macb_handle_link_change(struct net_device *dev)
178 177
179 if (status_change) { 178 if (status_change) {
180 if (phydev->link) 179 if (phydev->link)
181 printk(KERN_INFO "%s: link up (%d/%s)\n", 180 netdev_info(dev, "link up (%d/%s)\n",
182 dev->name, phydev->speed, 181 phydev->speed,
183 DUPLEX_FULL == phydev->duplex ? "Full":"Half"); 182 phydev->duplex == DUPLEX_FULL ?
183 "Full" : "Half");
184 else 184 else
185 printk(KERN_INFO "%s: link down\n", dev->name); 185 netdev_info(dev, "link down\n");
186 } 186 }
187} 187}
188 188
@@ -191,12 +191,12 @@ static int macb_mii_probe(struct net_device *dev)
191{ 191{
192 struct macb *bp = netdev_priv(dev); 192 struct macb *bp = netdev_priv(dev);
193 struct phy_device *phydev; 193 struct phy_device *phydev;
194 struct eth_platform_data *pdata; 194 struct macb_platform_data *pdata;
195 int ret; 195 int ret;
196 196
197 phydev = phy_find_first(bp->mii_bus); 197 phydev = phy_find_first(bp->mii_bus);
198 if (!phydev) { 198 if (!phydev) {
199 printk (KERN_ERR "%s: no PHY found\n", dev->name); 199 netdev_err(dev, "no PHY found\n");
200 return -1; 200 return -1;
201 } 201 }
202 202
@@ -209,7 +209,7 @@ static int macb_mii_probe(struct net_device *dev)
209 PHY_INTERFACE_MODE_RMII : 209 PHY_INTERFACE_MODE_RMII :
210 PHY_INTERFACE_MODE_MII); 210 PHY_INTERFACE_MODE_MII);
211 if (ret) { 211 if (ret) {
212 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); 212 netdev_err(dev, "Could not attach to PHY\n");
213 return ret; 213 return ret;
214 } 214 }
215 215
@@ -228,7 +228,7 @@ static int macb_mii_probe(struct net_device *dev)
228 228
229static int macb_mii_init(struct macb *bp) 229static int macb_mii_init(struct macb *bp)
230{ 230{
231 struct eth_platform_data *pdata; 231 struct macb_platform_data *pdata;
232 int err = -ENXIO, i; 232 int err = -ENXIO, i;
233 233
234 /* Enable management port */ 234 /* Enable management port */
@@ -285,8 +285,8 @@ err_out:
285static void macb_update_stats(struct macb *bp) 285static void macb_update_stats(struct macb *bp)
286{ 286{
287 u32 __iomem *reg = bp->regs + MACB_PFR; 287 u32 __iomem *reg = bp->regs + MACB_PFR;
288 u32 *p = &bp->hw_stats.rx_pause_frames; 288 u32 *p = &bp->hw_stats.macb.rx_pause_frames;
289 u32 *end = &bp->hw_stats.tx_pause_frames + 1; 289 u32 *end = &bp->hw_stats.macb.tx_pause_frames + 1;
290 290
291 WARN_ON((unsigned long)(end - p - 1) != (MACB_TPF - MACB_PFR) / 4); 291 WARN_ON((unsigned long)(end - p - 1) != (MACB_TPF - MACB_PFR) / 4);
292 292
@@ -303,14 +303,13 @@ static void macb_tx(struct macb *bp)
303 status = macb_readl(bp, TSR); 303 status = macb_readl(bp, TSR);
304 macb_writel(bp, TSR, status); 304 macb_writel(bp, TSR, status);
305 305
306 dev_dbg(&bp->pdev->dev, "macb_tx status = %02lx\n", 306 netdev_dbg(bp->dev, "macb_tx status = %02lx\n", (unsigned long)status);
307 (unsigned long)status);
308 307
309 if (status & (MACB_BIT(UND) | MACB_BIT(TSR_RLE))) { 308 if (status & (MACB_BIT(UND) | MACB_BIT(TSR_RLE))) {
310 int i; 309 int i;
311 printk(KERN_ERR "%s: TX %s, resetting buffers\n", 310 netdev_err(bp->dev, "TX %s, resetting buffers\n",
312 bp->dev->name, status & MACB_BIT(UND) ? 311 status & MACB_BIT(UND) ?
313 "underrun" : "retry limit exceeded"); 312 "underrun" : "retry limit exceeded");
314 313
315 /* Transfer ongoing, disable transmitter, to avoid confusion */ 314 /* Transfer ongoing, disable transmitter, to avoid confusion */
316 if (status & MACB_BIT(TGO)) 315 if (status & MACB_BIT(TGO))
@@ -369,8 +368,8 @@ static void macb_tx(struct macb *bp)
369 if (!(bufstat & MACB_BIT(TX_USED))) 368 if (!(bufstat & MACB_BIT(TX_USED)))
370 break; 369 break;
371 370
372 dev_dbg(&bp->pdev->dev, "skb %u (data %p) TX complete\n", 371 netdev_dbg(bp->dev, "skb %u (data %p) TX complete\n",
373 tail, skb->data); 372 tail, skb->data);
374 dma_unmap_single(&bp->pdev->dev, rp->mapping, skb->len, 373 dma_unmap_single(&bp->pdev->dev, rp->mapping, skb->len,
375 DMA_TO_DEVICE); 374 DMA_TO_DEVICE);
376 bp->stats.tx_packets++; 375 bp->stats.tx_packets++;
@@ -395,8 +394,8 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag,
395 394
396 len = MACB_BFEXT(RX_FRMLEN, bp->rx_ring[last_frag].ctrl); 395 len = MACB_BFEXT(RX_FRMLEN, bp->rx_ring[last_frag].ctrl);
397 396
398 dev_dbg(&bp->pdev->dev, "macb_rx_frame frags %u - %u (len %u)\n", 397 netdev_dbg(bp->dev, "macb_rx_frame frags %u - %u (len %u)\n",
399 first_frag, last_frag, len); 398 first_frag, last_frag, len);
400 399
401 skb = dev_alloc_skb(len + RX_OFFSET); 400 skb = dev_alloc_skb(len + RX_OFFSET);
402 if (!skb) { 401 if (!skb) {
@@ -437,8 +436,8 @@ static int macb_rx_frame(struct macb *bp, unsigned int first_frag,
437 436
438 bp->stats.rx_packets++; 437 bp->stats.rx_packets++;
439 bp->stats.rx_bytes += len; 438 bp->stats.rx_bytes += len;
440 dev_dbg(&bp->pdev->dev, "received skb of length %u, csum: %08x\n", 439 netdev_dbg(bp->dev, "received skb of length %u, csum: %08x\n",
441 skb->len, skb->csum); 440 skb->len, skb->csum);
442 netif_receive_skb(skb); 441 netif_receive_skb(skb);
443 442
444 return 0; 443 return 0;
@@ -515,8 +514,8 @@ static int macb_poll(struct napi_struct *napi, int budget)
515 514
516 work_done = 0; 515 work_done = 0;
517 516
518 dev_dbg(&bp->pdev->dev, "poll: status = %08lx, budget = %d\n", 517 netdev_dbg(bp->dev, "poll: status = %08lx, budget = %d\n",
519 (unsigned long)status, budget); 518 (unsigned long)status, budget);
520 519
521 work_done = macb_rx(bp, budget); 520 work_done = macb_rx(bp, budget);
522 if (work_done < budget) { 521 if (work_done < budget) {
@@ -565,8 +564,7 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
565 macb_writel(bp, IDR, MACB_RX_INT_FLAGS); 564 macb_writel(bp, IDR, MACB_RX_INT_FLAGS);
566 565
567 if (napi_schedule_prep(&bp->napi)) { 566 if (napi_schedule_prep(&bp->napi)) {
568 dev_dbg(&bp->pdev->dev, 567 netdev_dbg(bp->dev, "scheduling RX softirq\n");
569 "scheduling RX softirq\n");
570 __napi_schedule(&bp->napi); 568 __napi_schedule(&bp->napi);
571 } 569 }
572 } 570 }
@@ -582,16 +580,19 @@ static irqreturn_t macb_interrupt(int irq, void *dev_id)
582 580
583 if (status & MACB_BIT(ISR_ROVR)) { 581 if (status & MACB_BIT(ISR_ROVR)) {
584 /* We missed at least one packet */ 582 /* We missed at least one packet */
585 bp->hw_stats.rx_overruns++; 583 if (macb_is_gem(bp))
584 bp->hw_stats.gem.rx_overruns++;
585 else
586 bp->hw_stats.macb.rx_overruns++;
586 } 587 }
587 588
588 if (status & MACB_BIT(HRESP)) { 589 if (status & MACB_BIT(HRESP)) {
589 /* 590 /*
590 * TODO: Reset the hardware, and maybe move the printk 591 * TODO: Reset the hardware, and maybe move the
591 * to a lower-priority context as well (work queue?) 592 * netdev_err to a lower-priority context as well
593 * (work queue?)
592 */ 594 */
593 printk(KERN_ERR "%s: DMA bus error: HRESP not OK\n", 595 netdev_err(dev, "DMA bus error: HRESP not OK\n");
594 dev->name);
595 } 596 }
596 597
597 status = macb_readl(bp, ISR); 598 status = macb_readl(bp, ISR);
@@ -626,16 +627,12 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
626 unsigned long flags; 627 unsigned long flags;
627 628
628#ifdef DEBUG 629#ifdef DEBUG
629 int i; 630 netdev_dbg(bp->dev,
630 dev_dbg(&bp->pdev->dev, 631 "start_xmit: len %u head %p data %p tail %p end %p\n",
631 "start_xmit: len %u head %p data %p tail %p end %p\n", 632 skb->len, skb->head, skb->data,
632 skb->len, skb->head, skb->data, 633 skb_tail_pointer(skb), skb_end_pointer(skb));
633 skb_tail_pointer(skb), skb_end_pointer(skb)); 634 print_hex_dump(KERN_DEBUG, "data: ", DUMP_PREFIX_OFFSET, 16, 1,
634 dev_dbg(&bp->pdev->dev, 635 skb->data, 16, true);
635 "data:");
636 for (i = 0; i < 16; i++)
637 printk(" %02x", (unsigned int)skb->data[i]);
638 printk("\n");
639#endif 636#endif
640 637
641 len = skb->len; 638 len = skb->len;
@@ -645,21 +642,20 @@ static int macb_start_xmit(struct sk_buff *skb, struct net_device *dev)
645 if (TX_BUFFS_AVAIL(bp) < 1) { 642 if (TX_BUFFS_AVAIL(bp) < 1) {
646 netif_stop_queue(dev); 643 netif_stop_queue(dev);
647 spin_unlock_irqrestore(&bp->lock, flags); 644 spin_unlock_irqrestore(&bp->lock, flags);
648 dev_err(&bp->pdev->dev, 645 netdev_err(bp->dev, "BUG! Tx Ring full when queue awake!\n");
649 "BUG! Tx Ring full when queue awake!\n"); 646 netdev_dbg(bp->dev, "tx_head = %u, tx_tail = %u\n",
650 dev_dbg(&bp->pdev->dev, "tx_head = %u, tx_tail = %u\n", 647 bp->tx_head, bp->tx_tail);
651 bp->tx_head, bp->tx_tail);
652 return NETDEV_TX_BUSY; 648 return NETDEV_TX_BUSY;
653 } 649 }
654 650
655 entry = bp->tx_head; 651 entry = bp->tx_head;
656 dev_dbg(&bp->pdev->dev, "Allocated ring entry %u\n", entry); 652 netdev_dbg(bp->dev, "Allocated ring entry %u\n", entry);
657 mapping = dma_map_single(&bp->pdev->dev, skb->data, 653 mapping = dma_map_single(&bp->pdev->dev, skb->data,
658 len, DMA_TO_DEVICE); 654 len, DMA_TO_DEVICE);
659 bp->tx_skb[entry].skb = skb; 655 bp->tx_skb[entry].skb = skb;
660 bp->tx_skb[entry].mapping = mapping; 656 bp->tx_skb[entry].mapping = mapping;
661 dev_dbg(&bp->pdev->dev, "Mapped skb data %p to DMA addr %08lx\n", 657 netdev_dbg(bp->dev, "Mapped skb data %p to DMA addr %08lx\n",
662 skb->data, (unsigned long)mapping); 658 skb->data, (unsigned long)mapping);
663 659
664 ctrl = MACB_BF(TX_FRMLEN, len); 660 ctrl = MACB_BF(TX_FRMLEN, len);
665 ctrl |= MACB_BIT(TX_LAST); 661 ctrl |= MACB_BIT(TX_LAST);
@@ -723,27 +719,27 @@ static int macb_alloc_consistent(struct macb *bp)
723 &bp->rx_ring_dma, GFP_KERNEL); 719 &bp->rx_ring_dma, GFP_KERNEL);
724 if (!bp->rx_ring) 720 if (!bp->rx_ring)
725 goto out_err; 721 goto out_err;
726 dev_dbg(&bp->pdev->dev, 722 netdev_dbg(bp->dev,
727 "Allocated RX ring of %d bytes at %08lx (mapped %p)\n", 723 "Allocated RX ring of %d bytes at %08lx (mapped %p)\n",
728 size, (unsigned long)bp->rx_ring_dma, bp->rx_ring); 724 size, (unsigned long)bp->rx_ring_dma, bp->rx_ring);
729 725
730 size = TX_RING_BYTES; 726 size = TX_RING_BYTES;
731 bp->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size, 727 bp->tx_ring = dma_alloc_coherent(&bp->pdev->dev, size,
732 &bp->tx_ring_dma, GFP_KERNEL); 728 &bp->tx_ring_dma, GFP_KERNEL);
733 if (!bp->tx_ring) 729 if (!bp->tx_ring)
734 goto out_err; 730 goto out_err;
735 dev_dbg(&bp->pdev->dev, 731 netdev_dbg(bp->dev,
736 "Allocated TX ring of %d bytes at %08lx (mapped %p)\n", 732 "Allocated TX ring of %d bytes at %08lx (mapped %p)\n",
737 size, (unsigned long)bp->tx_ring_dma, bp->tx_ring); 733 size, (unsigned long)bp->tx_ring_dma, bp->tx_ring);
738 734
739 size = RX_RING_SIZE * RX_BUFFER_SIZE; 735 size = RX_RING_SIZE * RX_BUFFER_SIZE;
740 bp->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, size, 736 bp->rx_buffers = dma_alloc_coherent(&bp->pdev->dev, size,
741 &bp->rx_buffers_dma, GFP_KERNEL); 737 &bp->rx_buffers_dma, GFP_KERNEL);
742 if (!bp->rx_buffers) 738 if (!bp->rx_buffers)
743 goto out_err; 739 goto out_err;
744 dev_dbg(&bp->pdev->dev, 740 netdev_dbg(bp->dev,
745 "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n", 741 "Allocated RX buffers of %d bytes at %08lx (mapped %p)\n",
746 size, (unsigned long)bp->rx_buffers_dma, bp->rx_buffers); 742 size, (unsigned long)bp->rx_buffers_dma, bp->rx_buffers);
747 743
748 return 0; 744 return 0;
749 745
@@ -797,6 +793,84 @@ static void macb_reset_hw(struct macb *bp)
797 macb_readl(bp, ISR); 793 macb_readl(bp, ISR);
798} 794}
799 795
796static u32 gem_mdc_clk_div(struct macb *bp)
797{
798 u32 config;
799 unsigned long pclk_hz = clk_get_rate(bp->pclk);
800
801 if (pclk_hz <= 20000000)
802 config = GEM_BF(CLK, GEM_CLK_DIV8);
803 else if (pclk_hz <= 40000000)
804 config = GEM_BF(CLK, GEM_CLK_DIV16);
805 else if (pclk_hz <= 80000000)
806 config = GEM_BF(CLK, GEM_CLK_DIV32);
807 else if (pclk_hz <= 120000000)
808 config = GEM_BF(CLK, GEM_CLK_DIV48);
809 else if (pclk_hz <= 160000000)
810 config = GEM_BF(CLK, GEM_CLK_DIV64);
811 else
812 config = GEM_BF(CLK, GEM_CLK_DIV96);
813
814 return config;
815}
816
817static u32 macb_mdc_clk_div(struct macb *bp)
818{
819 u32 config;
820 unsigned long pclk_hz;
821
822 if (macb_is_gem(bp))
823 return gem_mdc_clk_div(bp);
824
825 pclk_hz = clk_get_rate(bp->pclk);
826 if (pclk_hz <= 20000000)
827 config = MACB_BF(CLK, MACB_CLK_DIV8);
828 else if (pclk_hz <= 40000000)
829 config = MACB_BF(CLK, MACB_CLK_DIV16);
830 else if (pclk_hz <= 80000000)
831 config = MACB_BF(CLK, MACB_CLK_DIV32);
832 else
833 config = MACB_BF(CLK, MACB_CLK_DIV64);
834
835 return config;
836}
837
838/*
839 * Get the DMA bus width field of the network configuration register that we
840 * should program. We find the width from decoding the design configuration
841 * register to find the maximum supported data bus width.
842 */
843static u32 macb_dbw(struct macb *bp)
844{
845 if (!macb_is_gem(bp))
846 return 0;
847
848 switch (GEM_BFEXT(DBWDEF, gem_readl(bp, DCFG1))) {
849 case 4:
850 return GEM_BF(DBW, GEM_DBW128);
851 case 2:
852 return GEM_BF(DBW, GEM_DBW64);
853 case 1:
854 default:
855 return GEM_BF(DBW, GEM_DBW32);
856 }
857}
858
859/*
860 * Configure the receive DMA engine to use the correct receive buffer size.
861 * This is a configurable parameter for GEM.
862 */
863static void macb_configure_dma(struct macb *bp)
864{
865 u32 dmacfg;
866
867 if (macb_is_gem(bp)) {
868 dmacfg = gem_readl(bp, DMACFG) & ~GEM_BF(RXBS, -1L);
869 dmacfg |= GEM_BF(RXBS, RX_BUFFER_SIZE / 64);
870 gem_writel(bp, DMACFG, dmacfg);
871 }
872}
873
800static void macb_init_hw(struct macb *bp) 874static void macb_init_hw(struct macb *bp)
801{ 875{
802 u32 config; 876 u32 config;
@@ -804,7 +878,7 @@ static void macb_init_hw(struct macb *bp)
804 macb_reset_hw(bp); 878 macb_reset_hw(bp);
805 __macb_set_hwaddr(bp); 879 __macb_set_hwaddr(bp);
806 880
807 config = macb_readl(bp, NCFGR) & MACB_BF(CLK, -1L); 881 config = macb_mdc_clk_div(bp);
808 config |= MACB_BIT(PAE); /* PAuse Enable */ 882 config |= MACB_BIT(PAE); /* PAuse Enable */
809 config |= MACB_BIT(DRFCS); /* Discard Rx FCS */ 883 config |= MACB_BIT(DRFCS); /* Discard Rx FCS */
810 config |= MACB_BIT(BIG); /* Receive oversized frames */ 884 config |= MACB_BIT(BIG); /* Receive oversized frames */
@@ -812,8 +886,11 @@ static void macb_init_hw(struct macb *bp)
812 config |= MACB_BIT(CAF); /* Copy All Frames */ 886 config |= MACB_BIT(CAF); /* Copy All Frames */
813 if (!(bp->dev->flags & IFF_BROADCAST)) 887 if (!(bp->dev->flags & IFF_BROADCAST))
814 config |= MACB_BIT(NBC); /* No BroadCast */ 888 config |= MACB_BIT(NBC); /* No BroadCast */
889 config |= macb_dbw(bp);
815 macb_writel(bp, NCFGR, config); 890 macb_writel(bp, NCFGR, config);
816 891
892 macb_configure_dma(bp);
893
817 /* Initialize TX and RX buffers */ 894 /* Initialize TX and RX buffers */
818 macb_writel(bp, RBQP, bp->rx_ring_dma); 895 macb_writel(bp, RBQP, bp->rx_ring_dma);
819 macb_writel(bp, TBQP, bp->tx_ring_dma); 896 macb_writel(bp, TBQP, bp->tx_ring_dma);
@@ -909,8 +986,8 @@ static void macb_sethashtable(struct net_device *dev)
909 mc_filter[bitnr >> 5] |= 1 << (bitnr & 31); 986 mc_filter[bitnr >> 5] |= 1 << (bitnr & 31);
910 } 987 }
911 988
912 macb_writel(bp, HRB, mc_filter[0]); 989 macb_or_gem_writel(bp, HRB, mc_filter[0]);
913 macb_writel(bp, HRT, mc_filter[1]); 990 macb_or_gem_writel(bp, HRT, mc_filter[1]);
914} 991}
915 992
916/* 993/*
@@ -932,8 +1009,8 @@ static void macb_set_rx_mode(struct net_device *dev)
932 1009
933 if (dev->flags & IFF_ALLMULTI) { 1010 if (dev->flags & IFF_ALLMULTI) {
934 /* Enable all multicast mode */ 1011 /* Enable all multicast mode */
935 macb_writel(bp, HRB, -1); 1012 macb_or_gem_writel(bp, HRB, -1);
936 macb_writel(bp, HRT, -1); 1013 macb_or_gem_writel(bp, HRT, -1);
937 cfg |= MACB_BIT(NCFGR_MTI); 1014 cfg |= MACB_BIT(NCFGR_MTI);
938 } else if (!netdev_mc_empty(dev)) { 1015 } else if (!netdev_mc_empty(dev)) {
939 /* Enable specific multicasts */ 1016 /* Enable specific multicasts */
@@ -941,8 +1018,8 @@ static void macb_set_rx_mode(struct net_device *dev)
941 cfg |= MACB_BIT(NCFGR_MTI); 1018 cfg |= MACB_BIT(NCFGR_MTI);
942 } else if (dev->flags & (~IFF_ALLMULTI)) { 1019 } else if (dev->flags & (~IFF_ALLMULTI)) {
943 /* Disable all multicast mode */ 1020 /* Disable all multicast mode */
944 macb_writel(bp, HRB, 0); 1021 macb_or_gem_writel(bp, HRB, 0);
945 macb_writel(bp, HRT, 0); 1022 macb_or_gem_writel(bp, HRT, 0);
946 cfg &= ~MACB_BIT(NCFGR_MTI); 1023 cfg &= ~MACB_BIT(NCFGR_MTI);
947 } 1024 }
948 1025
@@ -954,7 +1031,7 @@ static int macb_open(struct net_device *dev)
954 struct macb *bp = netdev_priv(dev); 1031 struct macb *bp = netdev_priv(dev);
955 int err; 1032 int err;
956 1033
957 dev_dbg(&bp->pdev->dev, "open\n"); 1034 netdev_dbg(bp->dev, "open\n");
958 1035
959 /* if the phy is not yet register, retry later*/ 1036 /* if the phy is not yet register, retry later*/
960 if (!bp->phy_dev) 1037 if (!bp->phy_dev)
@@ -965,9 +1042,8 @@ static int macb_open(struct net_device *dev)
965 1042
966 err = macb_alloc_consistent(bp); 1043 err = macb_alloc_consistent(bp);
967 if (err) { 1044 if (err) {
968 printk(KERN_ERR 1045 netdev_err(dev, "Unable to allocate DMA memory (error %d)\n",
969 "%s: Unable to allocate DMA memory (error %d)\n", 1046 err);
970 dev->name, err);
971 return err; 1047 return err;
972 } 1048 }
973 1049
@@ -1005,11 +1081,62 @@ static int macb_close(struct net_device *dev)
1005 return 0; 1081 return 0;
1006} 1082}
1007 1083
1084static void gem_update_stats(struct macb *bp)
1085{
1086 u32 __iomem *reg = bp->regs + GEM_OTX;
1087 u32 *p = &bp->hw_stats.gem.tx_octets_31_0;
1088 u32 *end = &bp->hw_stats.gem.rx_udp_checksum_errors + 1;
1089
1090 for (; p < end; p++, reg++)
1091 *p += __raw_readl(reg);
1092}
1093
1094static struct net_device_stats *gem_get_stats(struct macb *bp)
1095{
1096 struct gem_stats *hwstat = &bp->hw_stats.gem;
1097 struct net_device_stats *nstat = &bp->stats;
1098
1099 gem_update_stats(bp);
1100
1101 nstat->rx_errors = (hwstat->rx_frame_check_sequence_errors +
1102 hwstat->rx_alignment_errors +
1103 hwstat->rx_resource_errors +
1104 hwstat->rx_overruns +
1105 hwstat->rx_oversize_frames +
1106 hwstat->rx_jabbers +
1107 hwstat->rx_undersized_frames +
1108 hwstat->rx_length_field_frame_errors);
1109 nstat->tx_errors = (hwstat->tx_late_collisions +
1110 hwstat->tx_excessive_collisions +
1111 hwstat->tx_underrun +
1112 hwstat->tx_carrier_sense_errors);
1113 nstat->multicast = hwstat->rx_multicast_frames;
1114 nstat->collisions = (hwstat->tx_single_collision_frames +
1115 hwstat->tx_multiple_collision_frames +
1116 hwstat->tx_excessive_collisions);
1117 nstat->rx_length_errors = (hwstat->rx_oversize_frames +
1118 hwstat->rx_jabbers +
1119 hwstat->rx_undersized_frames +
1120 hwstat->rx_length_field_frame_errors);
1121 nstat->rx_over_errors = hwstat->rx_resource_errors;
1122 nstat->rx_crc_errors = hwstat->rx_frame_check_sequence_errors;
1123 nstat->rx_frame_errors = hwstat->rx_alignment_errors;
1124 nstat->rx_fifo_errors = hwstat->rx_overruns;
1125 nstat->tx_aborted_errors = hwstat->tx_excessive_collisions;
1126 nstat->tx_carrier_errors = hwstat->tx_carrier_sense_errors;
1127 nstat->tx_fifo_errors = hwstat->tx_underrun;
1128
1129 return nstat;
1130}
1131
1008static struct net_device_stats *macb_get_stats(struct net_device *dev) 1132static struct net_device_stats *macb_get_stats(struct net_device *dev)
1009{ 1133{
1010 struct macb *bp = netdev_priv(dev); 1134 struct macb *bp = netdev_priv(dev);
1011 struct net_device_stats *nstat = &bp->stats; 1135 struct net_device_stats *nstat = &bp->stats;
1012 struct macb_stats *hwstat = &bp->hw_stats; 1136 struct macb_stats *hwstat = &bp->hw_stats.macb;
1137
1138 if (macb_is_gem(bp))
1139 return gem_get_stats(bp);
1013 1140
1014 /* read stats from hardware */ 1141 /* read stats from hardware */
1015 macb_update_stats(bp); 1142 macb_update_stats(bp);
@@ -1119,12 +1246,11 @@ static const struct net_device_ops macb_netdev_ops = {
1119 1246
1120static int __init macb_probe(struct platform_device *pdev) 1247static int __init macb_probe(struct platform_device *pdev)
1121{ 1248{
1122 struct eth_platform_data *pdata; 1249 struct macb_platform_data *pdata;
1123 struct resource *regs; 1250 struct resource *regs;
1124 struct net_device *dev; 1251 struct net_device *dev;
1125 struct macb *bp; 1252 struct macb *bp;
1126 struct phy_device *phydev; 1253 struct phy_device *phydev;
1127 unsigned long pclk_hz;
1128 u32 config; 1254 u32 config;
1129 int err = -ENXIO; 1255 int err = -ENXIO;
1130 1256
@@ -1152,28 +1278,19 @@ static int __init macb_probe(struct platform_device *pdev)
1152 1278
1153 spin_lock_init(&bp->lock); 1279 spin_lock_init(&bp->lock);
1154 1280
1155#if defined(CONFIG_ARCH_AT91) 1281 bp->pclk = clk_get(&pdev->dev, "pclk");
1156 bp->pclk = clk_get(&pdev->dev, "macb_clk");
1157 if (IS_ERR(bp->pclk)) { 1282 if (IS_ERR(bp->pclk)) {
1158 dev_err(&pdev->dev, "failed to get macb_clk\n"); 1283 dev_err(&pdev->dev, "failed to get macb_clk\n");
1159 goto err_out_free_dev; 1284 goto err_out_free_dev;
1160 } 1285 }
1161 clk_enable(bp->pclk); 1286 clk_enable(bp->pclk);
1162#else 1287
1163 bp->pclk = clk_get(&pdev->dev, "pclk");
1164 if (IS_ERR(bp->pclk)) {
1165 dev_err(&pdev->dev, "failed to get pclk\n");
1166 goto err_out_free_dev;
1167 }
1168 bp->hclk = clk_get(&pdev->dev, "hclk"); 1288 bp->hclk = clk_get(&pdev->dev, "hclk");
1169 if (IS_ERR(bp->hclk)) { 1289 if (IS_ERR(bp->hclk)) {
1170 dev_err(&pdev->dev, "failed to get hclk\n"); 1290 dev_err(&pdev->dev, "failed to get hclk\n");
1171 goto err_out_put_pclk; 1291 goto err_out_put_pclk;
1172 } 1292 }
1173
1174 clk_enable(bp->pclk);
1175 clk_enable(bp->hclk); 1293 clk_enable(bp->hclk);
1176#endif
1177 1294
1178 bp->regs = ioremap(regs->start, resource_size(regs)); 1295 bp->regs = ioremap(regs->start, resource_size(regs));
1179 if (!bp->regs) { 1296 if (!bp->regs) {
@@ -1185,9 +1302,8 @@ static int __init macb_probe(struct platform_device *pdev)
1185 dev->irq = platform_get_irq(pdev, 0); 1302 dev->irq = platform_get_irq(pdev, 0);
1186 err = request_irq(dev->irq, macb_interrupt, 0, dev->name, dev); 1303 err = request_irq(dev->irq, macb_interrupt, 0, dev->name, dev);
1187 if (err) { 1304 if (err) {
1188 printk(KERN_ERR 1305 dev_err(&pdev->dev, "Unable to request IRQ %d (error %d)\n",
1189 "%s: Unable to request IRQ %d (error %d)\n", 1306 dev->irq, err);
1190 dev->name, dev->irq, err);
1191 goto err_out_iounmap; 1307 goto err_out_iounmap;
1192 } 1308 }
1193 1309
@@ -1198,15 +1314,8 @@ static int __init macb_probe(struct platform_device *pdev)
1198 dev->base_addr = regs->start; 1314 dev->base_addr = regs->start;
1199 1315
1200 /* Set MII management clock divider */ 1316 /* Set MII management clock divider */
1201 pclk_hz = clk_get_rate(bp->pclk); 1317 config = macb_mdc_clk_div(bp);
1202 if (pclk_hz <= 20000000) 1318 config |= macb_dbw(bp);
1203 config = MACB_BF(CLK, MACB_CLK_DIV8);
1204 else if (pclk_hz <= 40000000)
1205 config = MACB_BF(CLK, MACB_CLK_DIV16);
1206 else if (pclk_hz <= 80000000)
1207 config = MACB_BF(CLK, MACB_CLK_DIV32);
1208 else
1209 config = MACB_BF(CLK, MACB_CLK_DIV64);
1210 macb_writel(bp, NCFGR, config); 1319 macb_writel(bp, NCFGR, config);
1211 1320
1212 macb_get_hwaddr(bp); 1321 macb_get_hwaddr(bp);
@@ -1214,15 +1323,16 @@ static int __init macb_probe(struct platform_device *pdev)
1214 1323
1215 if (pdata && pdata->is_rmii) 1324 if (pdata && pdata->is_rmii)
1216#if defined(CONFIG_ARCH_AT91) 1325#if defined(CONFIG_ARCH_AT91)
1217 macb_writel(bp, USRIO, (MACB_BIT(RMII) | MACB_BIT(CLKEN)) ); 1326 macb_or_gem_writel(bp, USRIO, (MACB_BIT(RMII) |
1327 MACB_BIT(CLKEN)));
1218#else 1328#else
1219 macb_writel(bp, USRIO, 0); 1329 macb_or_gem_writel(bp, USRIO, 0);
1220#endif 1330#endif
1221 else 1331 else
1222#if defined(CONFIG_ARCH_AT91) 1332#if defined(CONFIG_ARCH_AT91)
1223 macb_writel(bp, USRIO, MACB_BIT(CLKEN)); 1333 macb_or_gem_writel(bp, USRIO, MACB_BIT(CLKEN));
1224#else 1334#else
1225 macb_writel(bp, USRIO, MACB_BIT(MII)); 1335 macb_or_gem_writel(bp, USRIO, MACB_BIT(MII));
1226#endif 1336#endif
1227 1337
1228 bp->tx_pending = DEF_TX_RING_PENDING; 1338 bp->tx_pending = DEF_TX_RING_PENDING;
@@ -1239,13 +1349,13 @@ static int __init macb_probe(struct platform_device *pdev)
1239 1349
1240 platform_set_drvdata(pdev, dev); 1350 platform_set_drvdata(pdev, dev);
1241 1351
1242 printk(KERN_INFO "%s: Atmel MACB at 0x%08lx irq %d (%pM)\n", 1352 netdev_info(dev, "Cadence %s at 0x%08lx irq %d (%pM)\n",
1243 dev->name, dev->base_addr, dev->irq, dev->dev_addr); 1353 macb_is_gem(bp) ? "GEM" : "MACB", dev->base_addr,
1354 dev->irq, dev->dev_addr);
1244 1355
1245 phydev = bp->phy_dev; 1356 phydev = bp->phy_dev;
1246 printk(KERN_INFO "%s: attached PHY driver [%s] " 1357 netdev_info(dev, "attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
1247 "(mii_bus:phy_addr=%s, irq=%d)\n", dev->name, 1358 phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
1248 phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
1249 1359
1250 return 0; 1360 return 0;
1251 1361
@@ -1256,14 +1366,10 @@ err_out_free_irq:
1256err_out_iounmap: 1366err_out_iounmap:
1257 iounmap(bp->regs); 1367 iounmap(bp->regs);
1258err_out_disable_clocks: 1368err_out_disable_clocks:
1259#ifndef CONFIG_ARCH_AT91
1260 clk_disable(bp->hclk); 1369 clk_disable(bp->hclk);
1261 clk_put(bp->hclk); 1370 clk_put(bp->hclk);
1262#endif
1263 clk_disable(bp->pclk); 1371 clk_disable(bp->pclk);
1264#ifndef CONFIG_ARCH_AT91
1265err_out_put_pclk: 1372err_out_put_pclk:
1266#endif
1267 clk_put(bp->pclk); 1373 clk_put(bp->pclk);
1268err_out_free_dev: 1374err_out_free_dev:
1269 free_netdev(dev); 1375 free_netdev(dev);
@@ -1289,10 +1395,8 @@ static int __exit macb_remove(struct platform_device *pdev)
1289 unregister_netdev(dev); 1395 unregister_netdev(dev);
1290 free_irq(dev->irq, dev); 1396 free_irq(dev->irq, dev);
1291 iounmap(bp->regs); 1397 iounmap(bp->regs);
1292#ifndef CONFIG_ARCH_AT91
1293 clk_disable(bp->hclk); 1398 clk_disable(bp->hclk);
1294 clk_put(bp->hclk); 1399 clk_put(bp->hclk);
1295#endif
1296 clk_disable(bp->pclk); 1400 clk_disable(bp->pclk);
1297 clk_put(bp->pclk); 1401 clk_put(bp->pclk);
1298 free_netdev(dev); 1402 free_netdev(dev);
@@ -1310,9 +1414,7 @@ static int macb_suspend(struct platform_device *pdev, pm_message_t state)
1310 1414
1311 netif_device_detach(netdev); 1415 netif_device_detach(netdev);
1312 1416
1313#ifndef CONFIG_ARCH_AT91
1314 clk_disable(bp->hclk); 1417 clk_disable(bp->hclk);
1315#endif
1316 clk_disable(bp->pclk); 1418 clk_disable(bp->pclk);
1317 1419
1318 return 0; 1420 return 0;
@@ -1324,9 +1426,7 @@ static int macb_resume(struct platform_device *pdev)
1324 struct macb *bp = netdev_priv(netdev); 1426 struct macb *bp = netdev_priv(netdev);
1325 1427
1326 clk_enable(bp->pclk); 1428 clk_enable(bp->pclk);
1327#ifndef CONFIG_ARCH_AT91
1328 clk_enable(bp->hclk); 1429 clk_enable(bp->hclk);
1329#endif
1330 1430
1331 netif_device_attach(netdev); 1431 netif_device_attach(netdev);
1332 1432
@@ -1361,6 +1461,6 @@ module_init(macb_init);
1361module_exit(macb_exit); 1461module_exit(macb_exit);
1362 1462
1363MODULE_LICENSE("GPL"); 1463MODULE_LICENSE("GPL");
1364MODULE_DESCRIPTION("Atmel MACB Ethernet driver"); 1464MODULE_DESCRIPTION("Cadence MACB/GEM Ethernet driver");
1365MODULE_AUTHOR("Haavard Skinnemoen (Atmel)"); 1465MODULE_AUTHOR("Haavard Skinnemoen (Atmel)");
1366MODULE_ALIAS("platform:macb"); 1466MODULE_ALIAS("platform:macb");
diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
index d3212f6db703..193107884a5a 100644
--- a/drivers/net/ethernet/cadence/macb.h
+++ b/drivers/net/ethernet/cadence/macb.h
@@ -59,6 +59,24 @@
59#define MACB_TPQ 0x00bc 59#define MACB_TPQ 0x00bc
60#define MACB_USRIO 0x00c0 60#define MACB_USRIO 0x00c0
61#define MACB_WOL 0x00c4 61#define MACB_WOL 0x00c4
62#define MACB_MID 0x00fc
63
64/* GEM register offsets. */
65#define GEM_NCFGR 0x0004
66#define GEM_USRIO 0x000c
67#define GEM_DMACFG 0x0010
68#define GEM_HRB 0x0080
69#define GEM_HRT 0x0084
70#define GEM_SA1B 0x0088
71#define GEM_SA1T 0x008C
72#define GEM_OTX 0x0100
73#define GEM_DCFG1 0x0280
74#define GEM_DCFG2 0x0284
75#define GEM_DCFG3 0x0288
76#define GEM_DCFG4 0x028c
77#define GEM_DCFG5 0x0290
78#define GEM_DCFG6 0x0294
79#define GEM_DCFG7 0x0298
62 80
63/* Bitfields in NCR */ 81/* Bitfields in NCR */
64#define MACB_LB_OFFSET 0 82#define MACB_LB_OFFSET 0
@@ -126,6 +144,21 @@
126#define MACB_IRXFCS_OFFSET 19 144#define MACB_IRXFCS_OFFSET 19
127#define MACB_IRXFCS_SIZE 1 145#define MACB_IRXFCS_SIZE 1
128 146
147/* GEM specific NCFGR bitfields. */
148#define GEM_CLK_OFFSET 18
149#define GEM_CLK_SIZE 3
150#define GEM_DBW_OFFSET 21
151#define GEM_DBW_SIZE 2
152
153/* Constants for data bus width. */
154#define GEM_DBW32 0
155#define GEM_DBW64 1
156#define GEM_DBW128 2
157
158/* Bitfields in DMACFG. */
159#define GEM_RXBS_OFFSET 16
160#define GEM_RXBS_SIZE 8
161
129/* Bitfields in NSR */ 162/* Bitfields in NSR */
130#define MACB_NSR_LINK_OFFSET 0 163#define MACB_NSR_LINK_OFFSET 0
131#define MACB_NSR_LINK_SIZE 1 164#define MACB_NSR_LINK_SIZE 1
@@ -228,12 +261,30 @@
228#define MACB_WOL_MTI_OFFSET 19 261#define MACB_WOL_MTI_OFFSET 19
229#define MACB_WOL_MTI_SIZE 1 262#define MACB_WOL_MTI_SIZE 1
230 263
264/* Bitfields in MID */
265#define MACB_IDNUM_OFFSET 16
266#define MACB_IDNUM_SIZE 16
267#define MACB_REV_OFFSET 0
268#define MACB_REV_SIZE 16
269
270/* Bitfields in DCFG1. */
271#define GEM_DBWDEF_OFFSET 25
272#define GEM_DBWDEF_SIZE 3
273
231/* Constants for CLK */ 274/* Constants for CLK */
232#define MACB_CLK_DIV8 0 275#define MACB_CLK_DIV8 0
233#define MACB_CLK_DIV16 1 276#define MACB_CLK_DIV16 1
234#define MACB_CLK_DIV32 2 277#define MACB_CLK_DIV32 2
235#define MACB_CLK_DIV64 3 278#define MACB_CLK_DIV64 3
236 279
280/* GEM specific constants for CLK. */
281#define GEM_CLK_DIV8 0
282#define GEM_CLK_DIV16 1
283#define GEM_CLK_DIV32 2
284#define GEM_CLK_DIV48 3
285#define GEM_CLK_DIV64 4
286#define GEM_CLK_DIV96 5
287
237/* Constants for MAN register */ 288/* Constants for MAN register */
238#define MACB_MAN_SOF 1 289#define MACB_MAN_SOF 1
239#define MACB_MAN_WRITE 1 290#define MACB_MAN_WRITE 1
@@ -254,11 +305,52 @@
254 << MACB_##name##_OFFSET)) \ 305 << MACB_##name##_OFFSET)) \
255 | MACB_BF(name,value)) 306 | MACB_BF(name,value))
256 307
308#define GEM_BIT(name) \
309 (1 << GEM_##name##_OFFSET)
310#define GEM_BF(name, value) \
311 (((value) & ((1 << GEM_##name##_SIZE) - 1)) \
312 << GEM_##name##_OFFSET)
313#define GEM_BFEXT(name, value)\
314 (((value) >> GEM_##name##_OFFSET) \
315 & ((1 << GEM_##name##_SIZE) - 1))
316#define GEM_BFINS(name, value, old) \
317 (((old) & ~(((1 << GEM_##name##_SIZE) - 1) \
318 << GEM_##name##_OFFSET)) \
319 | GEM_BF(name, value))
320
257/* Register access macros */ 321/* Register access macros */
258#define macb_readl(port,reg) \ 322#define macb_readl(port,reg) \
259 __raw_readl((port)->regs + MACB_##reg) 323 __raw_readl((port)->regs + MACB_##reg)
260#define macb_writel(port,reg,value) \ 324#define macb_writel(port,reg,value) \
261 __raw_writel((value), (port)->regs + MACB_##reg) 325 __raw_writel((value), (port)->regs + MACB_##reg)
326#define gem_readl(port, reg) \
327 __raw_readl((port)->regs + GEM_##reg)
328#define gem_writel(port, reg, value) \
329 __raw_writel((value), (port)->regs + GEM_##reg)
330
331/*
332 * Conditional GEM/MACB macros. These perform the operation to the correct
333 * register dependent on whether the device is a GEM or a MACB. For registers
334 * and bitfields that are common across both devices, use macb_{read,write}l
335 * to avoid the cost of the conditional.
336 */
337#define macb_or_gem_writel(__bp, __reg, __value) \
338 ({ \
339 if (macb_is_gem((__bp))) \
340 gem_writel((__bp), __reg, __value); \
341 else \
342 macb_writel((__bp), __reg, __value); \
343 })
344
345#define macb_or_gem_readl(__bp, __reg) \
346 ({ \
347 u32 __v; \
348 if (macb_is_gem((__bp))) \
349 __v = gem_readl((__bp), __reg); \
350 else \
351 __v = macb_readl((__bp), __reg); \
352 __v; \
353 })
262 354
263struct dma_desc { 355struct dma_desc {
264 u32 addr; 356 u32 addr;
@@ -358,6 +450,54 @@ struct macb_stats {
358 u32 tx_pause_frames; 450 u32 tx_pause_frames;
359}; 451};
360 452
453struct gem_stats {
454 u32 tx_octets_31_0;
455 u32 tx_octets_47_32;
456 u32 tx_frames;
457 u32 tx_broadcast_frames;
458 u32 tx_multicast_frames;
459 u32 tx_pause_frames;
460 u32 tx_64_byte_frames;
461 u32 tx_65_127_byte_frames;
462 u32 tx_128_255_byte_frames;
463 u32 tx_256_511_byte_frames;
464 u32 tx_512_1023_byte_frames;
465 u32 tx_1024_1518_byte_frames;
466 u32 tx_greater_than_1518_byte_frames;
467 u32 tx_underrun;
468 u32 tx_single_collision_frames;
469 u32 tx_multiple_collision_frames;
470 u32 tx_excessive_collisions;
471 u32 tx_late_collisions;
472 u32 tx_deferred_frames;
473 u32 tx_carrier_sense_errors;
474 u32 rx_octets_31_0;
475 u32 rx_octets_47_32;
476 u32 rx_frames;
477 u32 rx_broadcast_frames;
478 u32 rx_multicast_frames;
479 u32 rx_pause_frames;
480 u32 rx_64_byte_frames;
481 u32 rx_65_127_byte_frames;
482 u32 rx_128_255_byte_frames;
483 u32 rx_256_511_byte_frames;
484 u32 rx_512_1023_byte_frames;
485 u32 rx_1024_1518_byte_frames;
486 u32 rx_greater_than_1518_byte_frames;
487 u32 rx_undersized_frames;
488 u32 rx_oversize_frames;
489 u32 rx_jabbers;
490 u32 rx_frame_check_sequence_errors;
491 u32 rx_length_field_frame_errors;
492 u32 rx_symbol_errors;
493 u32 rx_alignment_errors;
494 u32 rx_resource_errors;
495 u32 rx_overruns;
496 u32 rx_ip_header_checksum_errors;
497 u32 rx_tcp_checksum_errors;
498 u32 rx_udp_checksum_errors;
499};
500
361struct macb { 501struct macb {
362 void __iomem *regs; 502 void __iomem *regs;
363 503
@@ -376,7 +516,10 @@ struct macb {
376 struct net_device *dev; 516 struct net_device *dev;
377 struct napi_struct napi; 517 struct napi_struct napi;
378 struct net_device_stats stats; 518 struct net_device_stats stats;
379 struct macb_stats hw_stats; 519 union {
520 struct macb_stats macb;
521 struct gem_stats gem;
522 } hw_stats;
380 523
381 dma_addr_t rx_ring_dma; 524 dma_addr_t rx_ring_dma;
382 dma_addr_t tx_ring_dma; 525 dma_addr_t tx_ring_dma;
@@ -391,4 +534,9 @@ struct macb {
391 unsigned int duplex; 534 unsigned int duplex;
392}; 535};
393 536
537static inline bool macb_is_gem(struct macb *bp)
538{
539 return MACB_BFEXT(IDNUM, macb_readl(bp, MID)) == 0x2;
540}
541
394#endif /* _MACB_H */ 542#endif /* _MACB_H */