at91_ether share stats/address setting with macb
Subsystems (4)
cover at91_ether share stats/address setting with macb
Patch 1-2 add support for some special at91_ether features to macb address setting code. This will allow us to have one address setting function that can be shared.
Patch 4 removes the at91_ether address set/get code and make use of the exported functions for macb.
Patch 5 remove the at91_ether statistics functions and replace them with equivalent function from macb.
Patch 6 removes an unused member from the at91_ether/macb private struct.
Patch 7 is a clean up of the print outs from at91_ether.
Patch 8 is a misc clean up patch which fixes some comment and style issues.
Most of the code left in at91_ether now deal with configuration and DMA rx/tx which is hard to share with macb since this is specific for the IP block in AT91RM9200.
Next I'll work on adding PHY GPIO interrupt to the macb driver. at91_ether had this functionality before it began using mdio functions from macb.
Joachim Eastwood (8):
net/macb: check all address registers sets net/macb: support reversed hw addr
net/macb: export macb_set_hwaddr and macb_get_hwaddr net/at91_ether: use macb functions for get/set hwaddr net/at91_ether: use stat function from macb net/at91_ether: drop board_data private struct member net/at91_ether: clean up print outs net/at91_ether: fix comment and style issues
drivers/net/ethernet/cadence/at91_ether.c | 289 +++++++----------------------- drivers/net/ethernet/cadence/macb.c | 54 ++++-- drivers/net/ethernet/cadence/macb.h | 10 +- 3 files changed, 109 insertions(+), 244 deletions(-)
Signature · 1 line
1.8.0
PATCH 1/8 net/macb: check all address registers sets
The macb driver in u-boot uses the first register set while the at91_ether driver in u-boot uses the second register set.
By checking all register set, like at91_ether does, this code can be shared between the drivers.
This only changes behavior on macb if no vaild address is found in the first register set.
--- drivers/net/ethernet/cadence/macb.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-)
drivers/net/ethernet/cadence/macb.c +20 -15
@@ -114,23 +114,28 @@ static void __init macb_get_hwaddr(struct macb *bp)u32 bottom;u16 top;u8 addr[6 ]; +int i; - bottom =macb_or_gem_readl (bp,SA1B ); - top =macb_or_gem_readl (bp,SA1T ); - - addr[0 ] = bottom &0xff ; - addr[1 ] = (bottom >>8 ) &0xff ; - addr[2 ] = (bottom >>16 ) &0xff ; - addr[3 ] = (bottom >>24 ) &0xff ; - addr[4 ] = top &0xff ; - addr[5 ] = (top >>8 ) &0xff ; - -if (is_valid_ether_addr (addr)) { -memcpy (bp->dev->dev_addr, addr,sizeof (addr)); - }else { -netdev_info (bp->dev,"invalid hw address, using random\n" ); -eth_hw_addr_random (bp->dev); +/* Check all 4 address register for vaild address */ +for (i =0 ; i <4 ; i++) { + bottom =macb_or_gem_readl (bp,SA1B + i *8 ); + top =macb_or_gem_readl (bp,SA1T + i *8 ); + + addr[0 ] = bottom &0xff ; + addr[1 ] = (bottom >>8 ) &0xff ; + addr[2 ] = (bottom >>16 ) &0xff ; + addr[3 ] = (bottom >>24 ) &0xff ; + addr[4 ] = top &0xff ; + addr[5 ] = (top >>8 ) &0xff ; + +if (is_valid_ether_addr (addr)) { +memcpy (bp->dev->dev_addr, addr,sizeof (addr)); +return ; + } } + +netdev_info (bp->dev,"invalid hw address, using random\n" ); +eth_hw_addr_random (bp->dev); }static int macb_mdio_read (struct mii_bus *bus,int mii_id,int regnum)
Signature · 1 line
1.8.0
PATCH 2/8 net/macb: support reversed hw addr
In reply to Joachim EastwoodThis is used on one AT91RM9200 board where a bootloader stores the Ethernet address in the wrong order.
Support this on macb so address setting functions can be shared with the at91_ether driver.
--- drivers/net/ethernet/cadence/macb.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/net/ethernet/cadence/macb.c +18 -6
@@ -111,22 +111,34 @@ static void __macb_set_hwaddr(struct macb *bp)static void __init macb_get_hwaddr (struct macb *bp) { +struct macb_platform_data *pdata;u32 bottom;u16 top;u8 addr[6 ];int i; + pdata = bp->pdev->dev.platform_data; +/* Check all 4 address register for vaild address */ for (i =0 ; i <4 ; i++) { bottom =macb_or_gem_readl (bp,SA1B + i *8 ); top =macb_or_gem_readl (bp,SA1T + i *8 ); - addr[0 ] = bottom &0xff ; - addr[1 ] = (bottom >>8 ) &0xff ; - addr[2 ] = (bottom >>16 ) &0xff ; - addr[3 ] = (bottom >>24 ) &0xff ; - addr[4 ] = top &0xff ; - addr[5 ] = (top >>8 ) &0xff ; +if (pdata && pdata->rev_eth_addr) { + addr[5 ] = bottom &0xff ; + addr[4 ] = (bottom >>8 ) &0xff ; + addr[3 ] = (bottom >>16 ) &0xff ; + addr[2 ] = (bottom >>24 ) &0xff ; + addr[1 ] = top &0xff ; + addr[0 ] = (top &0xff00 ) >>8 ; + }else { + addr[0 ] = bottom &0xff ; + addr[1 ] = (bottom >>8 ) &0xff ; + addr[2 ] = (bottom >>16 ) &0xff ; + addr[3 ] = (bottom >>24 ) &0xff ; + addr[4 ] = top &0xff ; + addr[5 ] = (top >>8 ) &0xff ; + }if (is_valid_ether_addr (addr)) {memcpy (bp->dev->dev_addr, addr,sizeof (addr));
Signature · 1 line
1.8.0
PATCH 3/8 net/macb: export macb_set_hwaddr and macb_get_hwaddr
In reply to Joachim Eastwoodfor usage in at91_ether driver.
--- drivers/net/ethernet/cadence/macb.c | 8 +++++--- drivers/net/ethernet/cadence/macb.h | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-)
drivers/net/ethernet/cadence/macb.c +5 -3
@@ -98,7 +98,7 @@ static void *macb_rx_buffer(struct macb *bp, unsigned int index)return bp->rx_buffers +RX_BUFFER_SIZE *macb_rx_ring_wrap (index); } -static void __macb_set_hwaddr (struct macb *bp) +void macb_set_hwaddr (struct macb *bp) {u32 bottom;u16 top;
@@ -108,8 +108,9 @@ static void __macb_set_hwaddr(struct macb *bp) top =cpu_to_le16 (*((u16 *)(bp->dev->dev_addr +4 )));macb_or_gem_writel (bp,SA1T , top); } +EXPORT_SYMBOL_GPL (macb_set_hwaddr); -static void __init macb_get_hwaddr (struct macb *bp) +void macb_get_hwaddr (struct macb *bp) {struct macb_platform_data *pdata;u32 bottom;
@@ -149,6 +150,7 @@ static void __init macb_get_hwaddr(struct macb *bp)netdev_info (bp->dev,"invalid hw address, using random\n" );eth_hw_addr_random (bp->dev); } +EXPORT_SYMBOL_GPL (macb_get_hwaddr);static int macb_mdio_read (struct mii_bus *bus,int mii_id,int regnum) {
@@ -1035,7 +1037,7 @@ static void macb_init_hw(struct macb *bp)u32 config;macb_reset_hw (bp); -__macb_set_hwaddr (bp); +macb_set_hwaddr (bp); config =macb_mdc_clk_div (bp); config |=MACB_BF (RBOF ,NET_IP_ALIGN );/* Make eth data aligned */
drivers/net/ethernet/cadence/macb.h +2 -0
@@ -573,6 +573,8 @@ extern const struct ethtool_ops macb_ethtool_ops;int macb_mii_init (struct macb *bp);int macb_ioctl (struct net_device *dev,struct ifreq *rq,int cmd);void macb_set_rx_mode (struct net_device *dev); +void macb_set_hwaddr (struct macb *bp); +void macb_get_hwaddr (struct macb *bp);static inline bool macb_is_gem (struct macb *bp) {
Signature · 1 line
1.8.0
PATCH 4/8 net/at91_ether: use macb functions for get/set hwaddr
In reply to Joachim Eastwood--- drivers/net/ethernet/cadence/at91_ether.c | 112 +----------------------------- 1 file changed, 3 insertions(+), 109 deletions(-)
drivers/net/ethernet/cadence/at91_ether.c +3 -109
@@ -46,109 +46,6 @@/* max number of receive buffers */ #define MAX_RX_DESCR 9 -/* ......................... ADDRESS MANAGEMENT ........................ */ - -/* -* NOTE: Your bootloader must always set the MAC address correctly before -* booting into Linux. -* -* - It must always set the MAC address after reset, even if it doesn't -* happen to access the Ethernet while it's booting. Some versions of -* U-Boot on the AT91RM9200-DK do not do this. -* -* - Likewise it must store the addresses in the correct byte order. -* MicroMonitor (uMon) on the CSB337 does this incorrectly (and -* continues to do so, for bug-compatibility). -*/ - -static short __init unpack_mac_address (struct net_device *dev,unsigned int hi,unsigned int lo) -{ -struct macb *lp =netdev_priv (dev); -char addr[6 ]; - -if (lp->board_data.rev_eth_addr) { - addr[5 ] = (lo &0xff );/* The CSB337 bootloader stores the MAC the wrong-way around */ - addr[4 ] = (lo &0xff00 ) >>8 ; - addr[3 ] = (lo &0xff0000 ) >>16 ; - addr[2 ] = (lo &0xff000000 ) >>24 ; - addr[1 ] = (hi &0xff ); - addr[0 ] = (hi &0xff00 ) >>8 ; - } -else { - addr[0 ] = (lo &0xff ); - addr[1 ] = (lo &0xff00 ) >>8 ; - addr[2 ] = (lo &0xff0000 ) >>16 ; - addr[3 ] = (lo &0xff000000 ) >>24 ; - addr[4 ] = (hi &0xff ); - addr[5 ] = (hi &0xff00 ) >>8 ; - } - -if (is_valid_ether_addr (addr)) { -memcpy (dev->dev_addr, &addr,6 ); -return 1 ; - } -return 0 ; -} - -/* -* Set the ethernet MAC address in dev->dev_addr -*/ -static void __init get_mac_address (struct net_device *dev) -{ -struct macb *lp =netdev_priv (dev); - -/* Check Specific-Address 1 */ -if (unpack_mac_address (dev,macb_readl (lp,SA1T ),macb_readl (lp,SA1B ))) -return ; -/* Check Specific-Address 2 */ -if (unpack_mac_address (dev,macb_readl (lp,SA2T ),macb_readl (lp,SA2B ))) -return ; -/* Check Specific-Address 3 */ -if (unpack_mac_address (dev,macb_readl (lp,SA3T ),macb_readl (lp,SA3B ))) -return ; -/* Check Specific-Address 4 */ -if (unpack_mac_address (dev,macb_readl (lp,SA4T ),macb_readl (lp,SA4B ))) -return ; - -printk (KERN_ERR "at91_ether: Your bootloader did not configure a MAC address.\n" ); -} - -/* -* Program the hardware MAC address from dev->dev_addr. -*/ -static void update_mac_address (struct net_device *dev) -{ -struct macb *lp =netdev_priv (dev); - -macb_writel (lp,SA1B , (dev->dev_addr[3 ] <<24 ) | (dev->dev_addr[2 ] <<16 ) - | (dev->dev_addr[1 ] <<8 ) | (dev->dev_addr[0 ])); -macb_writel (lp,SA1T , (dev->dev_addr[5 ] <<8 ) | (dev->dev_addr[4 ])); - -macb_writel (lp,SA2B ,0 ); -macb_writel (lp,SA2T ,0 ); -} - -/* -* Store the new hardware address in dev->dev_addr, and update the MAC. -*/ -static int set_mac_address (struct net_device *dev,void * addr) -{ -struct sockaddr *address = addr; - -if (!is_valid_ether_addr (address->sa_data)) -return -EADDRNOTAVAIL ; - -memcpy (dev->dev_addr, address->sa_data, dev->addr_len); -update_mac_address (dev); - -printk ("%s: Setting MAC address to %pM\n" , dev->name, - dev->dev_addr); - -return 0 ; -} - -/* ................................ MAC ................................ */ -/* * Initialize and start the Receiver and Transmit subsystems */
@@ -219,8 +116,7 @@ static int at91ether_open(struct net_device *dev) ctl =macb_readl (lp,NCR );macb_writel (lp,NCR , ctl |MACB_BIT (CLRSTAT )); -/* Update the MAC address (incase user has changed it) */ -update_mac_address (dev); +macb_set_hwaddr (lp); ret =at91ether_start (dev);if (ret)
@@ -438,7 +334,7 @@ static const struct net_device_ops at91ether_netdev_ops = { .ndo_start_xmit = at91ether_start_xmit, .ndo_get_stats = at91ether_stats, .ndo_set_rx_mode = macb_set_rx_mode, - .ndo_set_mac_address = set_mac_address, + .ndo_set_mac_address = eth_mac_addr, .ndo_do_ioctl = macb_ioctl, .ndo_validate_addr = eth_validate_addr, .ndo_change_mtu = eth_change_mtu,
@@ -557,9 +453,7 @@ static int __init at91ether_probe(struct platform_device *pdev) res =at91ether_get_hwaddr_dt (lp);if (res <0 ) -get_mac_address (dev);/* Get ethernet address and store it in dev->dev_addr */ - -update_mac_address (dev);/* Program ethernet address into MAC */ +macb_get_hwaddr (lp); res =at91ether_get_phy_mode_dt (pdev);if (res <0 ) {
Signature · 1 line
1.8.0
PATCH 5/8 net/at91_ether: use stat function from macb
In reply to Joachim Eastwood--- drivers/net/ethernet/cadence/at91_ether.c | 49 +++++-------------------------- drivers/net/ethernet/cadence/macb.c | 3 +- drivers/net/ethernet/cadence/macb.h | 1 + 3 files changed, 11 insertions(+), 42 deletions(-)
drivers/net/ethernet/cadence/at91_ether.c +8 -41
@@ -182,7 +182,6 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev) lp->skb = skb; lp->skb_length = skb->len; lp->skb_physaddr =dma_map_single (NULL , skb->data, skb->len,DMA_TO_DEVICE ); - dev->stats.tx_bytes += skb->len;/* Set address of the data in the Transmit Address register */ macb_writel (lp,TAR , lp->skb_physaddr);
@@ -200,41 +199,6 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev) }/* -* Update the current statistics from the internal statistics registers. -*/ -static struct net_device_stats *at91ether_stats (struct net_device *dev) -{ -struct macb *lp =netdev_priv (dev); -int ale, lenerr, seqe, lcol, ecol; - -if (netif_running (dev)) { - dev->stats.rx_packets +=macb_readl (lp,FRO );/* Good frames received */ - ale =macb_readl (lp,ALE ); - dev->stats.rx_frame_errors += ale;/* Alignment errors */ - lenerr =macb_readl (lp,ELE ) +macb_readl (lp,USF ); - dev->stats.rx_length_errors += lenerr;/* Excessive Length or Undersize Frame error */ - seqe =macb_readl (lp,FCSE ); - dev->stats.rx_crc_errors += seqe;/* CRC error */ - dev->stats.rx_fifo_errors +=macb_readl (lp,RRE );/* Receive buffer not available */ - dev->stats.rx_errors += (ale + lenerr + seqe - +macb_readl (lp,RSE ) +macb_readl (lp,RJA )); - - dev->stats.tx_packets +=macb_readl (lp,FTO );/* Frames successfully transmitted */ - dev->stats.tx_fifo_errors +=macb_readl (lp,TUND );/* Transmit FIFO underruns */ - dev->stats.tx_carrier_errors +=macb_readl (lp,CSE );/* Carrier Sense errors */ - dev->stats.tx_heartbeat_errors +=macb_readl (lp,STE );/* Heartbeat error */ - - lcol =macb_readl (lp,LCOL ); - ecol =macb_readl (lp,EXCOL ); - dev->stats.tx_window_errors += lcol;/* Late collisions */ - dev->stats.tx_aborted_errors += ecol;/* 16 collisions */ - - dev->stats.collisions += (macb_readl (lp,SCF ) +macb_readl (lp,MCF ) + lcol + ecol); - } -return &dev->stats; -} - -/* * Extract received frame from buffer descriptors and sent to upper layers. * (Called from interrupt context) */
@@ -254,15 +218,16 @@ static void at91ether_rx(struct net_device *dev)memcpy (skb_put (skb, pktlen), p_recv, pktlen); skb->protocol =eth_type_trans (skb, dev); - dev->stats.rx_bytes += pktlen; + lp->stats.rx_packets++; + lp->stats.rx_bytes += pktlen;netif_rx (skb); }else { - dev->stats.rx_dropped +=1 ; + lp->stats.rx_dropped++;netdev_notice (dev,"Memory squeeze, dropping packet.\n" ); }if (lp->rx_ring[lp->rx_tail].ctrl &MACB_BIT (RX_MHASH_MATCH )) - dev->stats.multicast++; + lp->stats.multicast++;/* reset ownership bit */ lp->rx_ring[lp->rx_tail].addr &= ~MACB_BIT (RX_USED );
@@ -294,12 +259,14 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)if (intstatus &MACB_BIT (TCOMP )) {/* Transmit complete */ /* The TCOM bit is set even if the transmission failed. */ if (intstatus & (MACB_BIT (ISR_TUND ) |MACB_BIT (ISR_RLE ))) - dev->stats.tx_errors +=1 ; + lp->stats.tx_errors++;if (lp->skb) {dev_kfree_skb_irq (lp->skb); lp->skb =NULL ;dma_unmap_single (NULL , lp->skb_physaddr, lp->skb_length,DMA_TO_DEVICE ); + lp->stats.tx_packets++; + lp->stats.tx_bytes += lp->skb_length; }netif_wake_queue (dev); }
@@ -332,7 +299,7 @@ static const struct net_device_ops at91ether_netdev_ops = { .ndo_open = at91ether_open, .ndo_stop = at91ether_close, .ndo_start_xmit = at91ether_start_xmit, - .ndo_get_stats = at91ether_stats, + .ndo_get_stats = macb_get_stats, .ndo_set_rx_mode = macb_set_rx_mode, .ndo_set_mac_address = eth_mac_addr, .ndo_do_ioctl = macb_ioctl,
drivers/net/ethernet/cadence/macb.c +2 -1
@@ -1292,7 +1292,7 @@ static struct net_device_stats *gem_get_stats(struct macb *bp)return nstat; } -static struct net_device_stats *macb_get_stats (struct net_device *dev) +struct net_device_stats *macb_get_stats (struct net_device *dev) {struct macb *bp =netdev_priv (dev);struct net_device_stats *nstat = &bp->stats;
@@ -1338,6 +1338,7 @@ static struct net_device_stats *macb_get_stats(struct net_device *dev)return nstat; } +EXPORT_SYMBOL_GPL (macb_get_stats);static int macb_get_settings (struct net_device *dev,struct ethtool_cmd *cmd) {
drivers/net/ethernet/cadence/macb.h +1 -0
@@ -572,6 +572,7 @@ extern const struct ethtool_ops macb_ethtool_ops;int macb_mii_init (struct macb *bp);int macb_ioctl (struct net_device *dev,struct ifreq *rq,int cmd); +struct net_device_stats *macb_get_stats (struct net_device *dev);void macb_set_rx_mode (struct net_device *dev);void macb_set_hwaddr (struct macb *bp);void macb_get_hwaddr (struct macb *bp);
Signature · 1 line
1.8.0
PATCH 6/8 net/at91_ether: drop board_data private struct member
In reply to Joachim EastwoodNo longer used after gpio phy interrupt support was removed from at91_ether.
--- drivers/net/ethernet/cadence/at91_ether.c | 2 -- drivers/net/ethernet/cadence/macb.h | 7 +------ 2 files changed, 1 insertion(+), 8 deletions(-)
drivers/net/ethernet/cadence/at91_ether.c +0 -2
@@ -387,8 +387,6 @@ static int __init at91ether_probe(struct platform_device *pdev) lp =netdev_priv (dev); lp->pdev = pdev; lp->dev = dev; -if (board_data) - lp->board_data = *board_data;spin_lock_init (&lp->lock); dev->base_addr = regs->start;/* physical base address */
drivers/net/ethernet/cadence/macb.h +1 -6
@@ -557,12 +557,7 @@ struct macb {phy_interface_t phy_interface; -/* at91_private */ -struct macb_platform_data board_data;/* board-specific -* configuration (shared with -* macb for common data */ - -/* Transmit */ +/* AT91RM9200 transmit */ struct sk_buff *skb;/* holds skb until xmit interrupt completes */ dma_addr_t skb_physaddr;/* phys addr from pci_map_single */ int skb_length;/* saved skb length for pci_unmap_single */
Signature · 1 line
1.8.0
PATCH 7/8 net/at91_ether: clean up print outs
In reply to Joachim EastwoodConvert all printk's to netdev_ counterparts and fix up some printed texts.
--- drivers/net/ethernet/cadence/at91_ether.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/net/ethernet/cadence/at91_ether.c +7 -10
@@ -60,7 +60,7 @@ static int at91ether_start(struct net_device *dev)MAX_RX_DESCR *sizeof (struct macb_dma_desc ), &lp->rx_ring_dma, GFP_KERNEL);if (!lp->rx_ring) { -netdev_err (lp->dev,"unable to alloc rx ring DMA buffer\n" ); +netdev_err (dev,"unable to alloc rx ring DMA buffer\n" );return -ENOMEM ; }
@@ -68,7 +68,7 @@ static int at91ether_start(struct net_device *dev)MAX_RX_DESCR *MAX_RBUFF_SZ , &lp->rx_buffers_dma, GFP_KERNEL);if (!lp->rx_buffers) { -netdev_err (lp->dev,"unable to alloc rx data DMA buffer\n" ); +netdev_err (dev,"unable to alloc rx data DMA buffer\n" ); dma_free_coherent(&lp->pdev->dev, MAX_RX_DESCR * sizeof(struct macb_dma_desc),
@@ -189,7 +189,7 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)macb_writel (lp,TCR , skb->len); }else { -printk (KERN_ERR "at91_ether.c: at91ether_start_xmit() called, but device is busy!\n" ); +netdev_err (dev,"%s called, but device is busy!\n" , __func__);return NETDEV_TX_BUSY ;/* if we return anything but zero, dev.c:1055 calls kfree_skb(skb) on this skb, he also reports -ENETDOWN and printk's, so either we free and return(0) or don't free and return 1 */
@@ -279,7 +279,7 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id) }if (intstatus &MACB_BIT (ISR_ROVR )) -printk ("%s: ROVR error\n" , dev->name); +netdev_err (dev,"ROVR error\n" );return IRQ_HANDLED ; }
@@ -449,14 +449,11 @@ static int __init at91ether_probe(struct platform_device *pdev) phydev = lp->phy_dev;netdev_info (dev,"attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n" , - phydev->drv->name,dev_name (&phydev->dev), phydev->irq); + phydev->drv->name,dev_name (&phydev->dev), phydev->irq);/* Display ethernet banner */ -printk (KERN_INFO "%s: AT91 ethernet at 0x%08x int=%d %s%s (%pM)\n" , - dev->name, (uint ) dev->base_addr, dev->irq, -macb_readl (lp,NCFGR ) &MACB_BIT (SPD ) ?"100-" :"10-" , -macb_readl (lp,NCFGR ) &MACB_BIT (FD ) ?"FullDuplex" :"HalfDuplex" , - dev->dev_addr); +netdev_info (dev,"AT91 ethernet at 0x%08lx int=%d (%pM)\n" , + dev->base_addr, dev->irq, dev->dev_addr);return 0 ;
Signature · 1 line
1.8.0
PATCH 8/8 net/at91_ether: fix comment and style issues
In reply to Joachim Eastwood--- drivers/net/ethernet/cadence/at91_ether.c | 111 ++++++++++++++---------------- 1 file changed, 51 insertions(+), 60 deletions(-)
drivers/net/ethernet/cadence/at91_ether.c +51 -60
@@ -6,11 +6,6 @@* Based on an earlier Atmel EMAC macrocell driver by Atmel and Lineo Inc. * Initial version by Rick Bronson 01/11/2003 * -* Intel LXT971A PHY support by Christopher Bahns & David Knickerbocker -* (Polaroid Corporation) -* -* Realtek RTL8201(B)L PHY support by Roman Avramenko <[email protected]> -* * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version
@@ -38,22 +33,17 @@#include "macb.h" -#define DRV_NAME "at91_ether" -#define DRV_VERSION "1.0" -/* 1518 rounded up */ #define MAX_RBUFF_SZ 0x600/* max number of receive buffers */ #define MAX_RX_DESCR 9 -/* -* Initialize and start the Receiver and Transmit subsystems -*/ +/* Initialize and start the Receiver and Transmit subsystems */ static int at91ether_start (struct net_device *dev) {struct macb *lp =netdev_priv (dev); -unsigned long ctl;dma_addr_t addr; +u32 ctl;int i; lp->rx_ring = dma_alloc_coherent(&lp->pdev->dev,
@@ -100,13 +90,11 @@ static int at91ether_start(struct net_device *dev)return 0 ; } -/* -* Open the ethernet interface -*/ +/* Open the ethernet interface */ static int at91ether_open (struct net_device *dev) {struct macb *lp =netdev_priv (dev); -unsigned long ctl; +u32 ctl;int ret;if (!is_valid_ether_addr (dev->dev_addr))
@@ -123,9 +111,13 @@ static int at91ether_open(struct net_device *dev)return ret;/* Enable MAC interrupts */ -macb_writel (lp,IER ,MACB_BIT (RCOMP ) |MACB_BIT (RXUBR ) - |MACB_BIT (ISR_TUND ) |MACB_BIT (ISR_RLE ) |MACB_BIT (TCOMP ) - |MACB_BIT (ISR_ROVR ) |MACB_BIT (HRESP )); +macb_writel (lp,IER ,MACB_BIT (RCOMP ) | +MACB_BIT (RXUBR ) | +MACB_BIT (ISR_TUND ) | +MACB_BIT (ISR_RLE ) | +MACB_BIT (TCOMP ) | +MACB_BIT (ISR_ROVR ) | +MACB_BIT (HRESP ));/* schedule a link state check */ phy_start (lp->phy_dev);
@@ -135,23 +127,24 @@ static int at91ether_open(struct net_device *dev)return 0 ; } -/* -* Close the interface -*/ +/* Close the interface */ static int at91ether_close (struct net_device *dev) {struct macb *lp =netdev_priv (dev); -unsigned long ctl; +u32 ctl;/* Disable Receiver and Transmitter */ ctl =macb_readl (lp,NCR );macb_writel (lp,NCR , ctl & ~(MACB_BIT (TE ) |MACB_BIT (RE )));/* Disable MAC interrupts */ -macb_writel (lp,IDR ,MACB_BIT (RCOMP ) |MACB_BIT (RXUBR ) - |MACB_BIT (ISR_TUND ) |MACB_BIT (ISR_RLE ) - |MACB_BIT (TCOMP ) |MACB_BIT (ISR_ROVR ) - |MACB_BIT (HRESP )); +macb_writel (lp,IDR ,MACB_BIT (RCOMP ) | +MACB_BIT (RXUBR ) | +MACB_BIT (ISR_TUND ) | +MACB_BIT (ISR_RLE ) | +MACB_BIT (TCOMP ) | +MACB_BIT (ISR_ROVR ) | +MACB_BIT (HRESP ));netif_stop_queue (dev);
@@ -168,9 +161,7 @@ static int at91ether_close(struct net_device *dev)return 0 ; } -/* -* Transmit packet. -*/ +/* Transmit packet */ static int at91ether_start_xmit (struct sk_buff *skb,struct net_device *dev) {struct macb *lp =netdev_priv (dev);
@@ -181,7 +172,8 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev)/* Store packet information (to free when Tx completed) */ lp->skb = skb; lp->skb_length = skb->len; - lp->skb_physaddr =dma_map_single (NULL , skb->data, skb->len,DMA_TO_DEVICE ); + lp->skb_physaddr =dma_map_single (NULL , skb->data, skb->len, +DMA_TO_DEVICE );/* Set address of the data in the Transmit Address register */ macb_writel (lp,TAR , lp->skb_physaddr);
@@ -190,16 +182,13 @@ static int at91ether_start_xmit(struct sk_buff *skb, struct net_device *dev) }else {netdev_err (dev,"%s called, but device is busy!\n" , __func__); -return NETDEV_TX_BUSY ;/* if we return anything but zero, dev.c:1055 calls kfree_skb(skb) -on this skb, he also reports -ENETDOWN and printk's, so either -we free and return(0) or don't free and return 1 */ +return NETDEV_TX_BUSY ; }return NETDEV_TX_OK ; } -/* -* Extract received frame from buffer descriptors and sent to upper layers. +/* Extract received frame from buffer descriptors and sent to upper layers. * (Called from interrupt context) */ static void at91ether_rx (struct net_device *dev)
@@ -240,24 +229,25 @@ static void at91ether_rx(struct net_device *dev) } } -/* -* MAC interrupt handler -*/ +/* MAC interrupt handler */ static irqreturn_t at91ether_interrupt (int irq,void *dev_id) { -struct net_device *dev = (struct net_device *) dev_id; +struct net_device *dev = dev_id;struct macb *lp =netdev_priv (dev); -unsigned long intstatus, ctl; +u32 intstatus, ctl;/* MAC Interrupt Status register indicates what interrupts are pending. -It is automatically cleared once read. */ +* It is automatically cleared once read. +*/ intstatus =macb_readl (lp,ISR ); -if (intstatus &MACB_BIT (RCOMP ))/* Receive complete */ +/* Receive complete */ +if (intstatus &MACB_BIT (RCOMP ))at91ether_rx (dev); -if (intstatus &MACB_BIT (TCOMP )) {/* Transmit complete */ -/* The TCOM bit is set even if the transmission failed. */ +/* Transmit complete */ +if (intstatus &MACB_BIT (TCOMP )) { +/* The TCOM bit is set even if the transmission failed */ if (intstatus & (MACB_BIT (ISR_TUND ) |MACB_BIT (ISR_RLE ))) lp->stats.tx_errors++;
@@ -271,7 +261,7 @@ static irqreturn_t at91ether_interrupt(int irq, void *dev_id)netif_wake_queue (dev); } -/* Work-around for Errata #11 */ +/* Work-around for EMAC Errata section 41.3.1 */ if (intstatus &MACB_BIT (RXUBR )) { ctl =macb_readl (lp,NCR );macb_writel (lp,NCR , ctl & ~MACB_BIT (RE ));
@@ -354,18 +344,17 @@ static int at91ether_get_hwaddr_dt(struct macb *bp) }#endif -/* -* Detect MAC & PHY and perform ethernet interface initialization -*/ +/* Detect MAC & PHY and perform ethernet interface initialization */ static int __init at91ether_probe (struct platform_device *pdev) {struct macb_platform_data *board_data = pdev->dev.platform_data;struct resource *regs;struct net_device *dev;struct phy_device *phydev; +struct pinctrl *pinctrl;struct macb *lp;int res; -struct pinctrl *pinctrl; +u32 reg; regs =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!regs)
@@ -389,7 +378,8 @@ static int __init at91ether_probe(struct platform_device *pdev) lp->dev = dev;spin_lock_init (&lp->lock); - dev->base_addr = regs->start;/* physical base address */ +/* physical base address */ + dev->base_addr = regs->start; lp->regs =devm_ioremap (&pdev->dev, regs->start,resource_size (regs));if (!lp->regs) { res = -ENOMEM ;
@@ -432,10 +422,11 @@ static int __init at91ether_probe(struct platform_device *pdev)macb_writel (lp,NCR ,0 ); + reg =MACB_BF (CLK ,MACB_CLK_DIV32 ) |MACB_BIT (BIG );if (lp->phy_interface ==PHY_INTERFACE_MODE_RMII ) -macb_writel (lp,NCFGR ,MACB_BF (CLK ,MACB_CLK_DIV32 ) |MACB_BIT (BIG ) |MACB_BIT (RM9200_RMII )); -else -macb_writel (lp,NCFGR ,MACB_BF (CLK ,MACB_CLK_DIV32 ) |MACB_BIT (BIG )); + reg |=MACB_BIT (RM9200_RMII ); + +macb_writel (lp,NCFGR , reg);/* Register the network interface */ res =register_netdev (dev);
@@ -445,11 +436,13 @@ static int __init at91ether_probe(struct platform_device *pdev)if (macb_mii_init (lp) !=0 ) goto err_out_unregister_netdev; -netif_carrier_off (dev);/* will be enabled in open() */ +/* will be enabled in open() */ +netif_carrier_off (dev); phydev = lp->phy_dev;netdev_info (dev,"attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n" , - phydev->drv->name,dev_name (&phydev->dev), phydev->irq); + phydev->drv->name,dev_name (&phydev->dev), + phydev->irq);/* Display ethernet banner */ netdev_info(dev, "AT91 ethernet at 0x%08lx int=%d (%pM)\n",
@@ -486,7 +479,6 @@ static int __devexit at91ether_remove(struct platform_device *pdev) }#ifdef CONFIG_PM -static int at91ether_suspend (struct platform_device *pdev,pm_message_t mesg) {struct net_device *net_dev =platform_get_drvdata (pdev);
@@ -514,7 +506,6 @@ static int at91ether_resume(struct platform_device *pdev) }return 0 ; } -#else #define at91ether_suspend NULL#define at91ether_resume NULL
@@ -525,7 +516,7 @@ static struct platform_driver at91ether_driver = { .suspend = at91ether_suspend, .resume = at91ether_resume, .driver = { - .name = DRV_NAME, + .name = "at91_ether", .owner = THIS_MODULE, .of_match_table = of_match_ptr(at91ether_dt_ids), },
@@ -547,4 +538,4 @@ module_exit(at91ether_exit)MODULE_LICENSE ("GPL" );MODULE_DESCRIPTION ("AT91RM9200 EMAC Ethernet driver" );MODULE_AUTHOR ("Andrew Victor" ); -MODULE_ALIAS ("platform:" DRV_NAME ); +MODULE_ALIAS ("platform:at91_ether" );
Signature · 1 line
1.8.0
David Miller
maintainerFrom: Joachim Eastwood <[email protected]>
Date: Wed, 7 Nov 2012 19:14:49 +0100
Quoted 8 lines
Patch 1-2 add support for some special
at91_etherfeatures to macb address setting code. This will allow us to have one address setting function that can be shared.Patch 4 removes the
at91_etheraddress set/get code and make use of the exported functions for macb.Patch 5 remove the
at91_etherstatistics functions and replace them with equivalent function from macb.Patch 6 removes an unused member from the at91_ether/macb private struct.
Quoted 8 lines
Patch 7 is a clean up of the print outs from
at91_ether.Patch 8 is a misc clean up patch which fixes some comment and style issues.
Most of the code left in
at91_ethernow deal with configuration and DMA rx/tx which is hard to share with macb since this is specific for the IP block in AT91RM9200.Next I'll work on adding PHY GPIO interrupt to the macb driver.
at91_etherhad this functionality before it began using mdio functions from macb.
All applied to net-next, thanks.