r6040: misc cleanups
Subsystems (3)
cover r6040: misc cleanups
Hi David,
This series contains some cleanups and one small fix, they are targetted at net-next.
Thanks!
Florian Fainelli (8):
r6040: consolidate MAC reset to its own function
r6040: remove unused variable mcr1 from private structure
r6040: add a MAC operation timeout define
r6040: fix typo on stats update in tx path
r6040: define and use MLSR register bits
r6040: define and use MTPR transmit enable bit
r6040: define and use bits of register PHY_CC
r6040: update copyright from 2007 to now
drivers/net/ethernet/rdc/r6040.c | 75 ++++++++++++++++++++++---------------- 1 files changed, 44 insertions(+), 31 deletions(-)
Signature · 1 line
1.7.5.4
PATCH 1/8 r6040: consolidate MAC reset to its own function
The reset of the MAC is currently done identically from two places and one place is not waiting for the MAC_SM bit to be set after reset. Everytime the MAC is software resetted a state machine is also needed so consolidate the reset to its own function.
--- drivers/net/ethernet/rdc/r6040.c | 37 ++++++++++++++++++------------------- 1 files changed, 18 insertions(+), 19 deletions(-)
drivers/net/ethernet/rdc/r6040.c +18 -19
@@ -358,27 +358,35 @@ err_exit:return rc; } -static void r6040_init_mac_regs (struct net_device *dev) +static void r6040_reset_mac (struct r6040_private *lp) { -struct r6040_private *lp =netdev_priv (dev);void __iomem *ioaddr = lp->base;int limit =2048 ;u16 cmd; -/* Mask Off Interrupt */ -iowrite16 (MSK_INT , ioaddr +MIER ); - -/* Reset RDC MAC */ iowrite16 (MAC_RST , ioaddr +MCR1 );while (limit--) { cmd =ioread16 (ioaddr +MCR1 );if (cmd &MAC_RST )break ; } +/* Reset internal state machine */ iowrite16 (MAC_SM_RST , ioaddr +MAC_SM );iowrite16 (0 , ioaddr +MAC_SM );mdelay (5 ); +} + +static void r6040_init_mac_regs (struct net_device *dev) +{ +struct r6040_private *lp =netdev_priv (dev); +void __iomem *ioaddr = lp->base; + +/* Mask Off Interrupt */ +iowrite16 (MSK_INT , ioaddr +MIER ); + +/* Reset RDC MAC */ +r6040_reset_mac (lp);/* MAC Bus Control Register */ iowrite16 (MBCR_DEFAULT , ioaddr +MBCR );
@@ -445,18 +453,13 @@ static void r6040_down(struct net_device *dev) {struct r6040_private *lp =netdev_priv (dev);void __iomem *ioaddr = lp->base; -int limit =2048 ;u16 *adrp; -u16 cmd;/* Stop MAC */ iowrite16 (MSK_INT , ioaddr +MIER );/* Mask Off Interrupt */ -iowrite16 (MAC_RST , ioaddr +MCR1 );/* Reset RDC MAC */ -while (limit--) { - cmd =ioread16 (ioaddr +MCR1 ); -if (cmd &MAC_RST ) -break ; - } + +/* Reset RDC MAC */ +r6040_reset_mac (lp);/* Restore MAC Address to MIDx */ adrp = (u16 *) dev->dev_addr;
@@ -736,11 +739,7 @@ static void r6040_mac_address(struct net_device *dev)u16 *adrp;/* Reset MAC */ -iowrite16 (MAC_RST , ioaddr +MCR1 ); -/* Reset internal state machine */ -iowrite16 (MAC_SM_RST , ioaddr +MAC_SM ); -iowrite16 (0 , ioaddr +MAC_SM ); -mdelay (5 ); +r6040_reset_mac (lp);/* Restore MAC Address */ adrp = (u16 *) dev->dev_addr;
Signature · 1 line
1.7.5.4
PATCH 2/8 r6040: remove unused variable mcr1 from private structure
In reply to Florian Fainelli--- drivers/net/ethernet/rdc/r6040.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/rdc/r6040.c +1 -1
@@ -187,7 +187,7 @@ struct r6040_private {dma_addr_t rx_ring_dma;dma_addr_t tx_ring_dma;u16 tx_free_desc; -u16 mcr0, mcr1; +u16 mcr0;struct net_device *dev;struct mii_bus *mii_bus;struct napi_struct napi;
Signature · 1 line
1.7.5.4
PATCH 3/8 r6040: add a MAC operation timeout define
In reply to Florian Fainelli2048 is the usual value for busy-waiting on a register r/w, define it as MAC_DEF_TIMEOUT and use it where it is appropriate.
--- drivers/net/ethernet/rdc/r6040.c | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-)
drivers/net/ethernet/rdc/r6040.c +5 -3
@@ -137,6 +137,8 @@#define MBCR_DEFAULT 0x012A/* MAC Bus Control Register */ #define MCAST_MAX 3/* Max number multicast addresses to filter */ +#define MAC_DEF_TIMEOUT 2048/* Default MAC read/write operation timeout */ +/* Descriptor status */ #define DSC_OWNER_MAC 0x8000/* MAC is the owner of this descriptor */ #define DSC_RX_OK 0x4000/* RX was successful */
@@ -204,7 +206,7 @@ static char version[] __devinitdata = DRV_NAME/* Read a word data from PHY Chip */ static int r6040_phy_read (void __iomem *ioaddr,int phy_addr,int reg) { -int limit =2048 ; +int limit =MAC_DEF_TIMEOUT ;u16 cmd;iowrite16 (MDIO_READ + reg + (phy_addr <<8 ), ioaddr +MMDIO );
@@ -222,7 +224,7 @@ static int r6040_phy_read(void __iomem *ioaddr, int phy_addr, int reg)static void r6040_phy_write (void __iomem *ioaddr,int phy_addr,int reg,u16 val) { -int limit =2048 ; +int limit =MAC_DEF_TIMEOUT ;u16 cmd;iowrite16 (val, ioaddr +MMWD );
@@ -361,7 +363,7 @@ err_exit:static void r6040_reset_mac (struct r6040_private *lp) {void __iomem *ioaddr = lp->base; -int limit =2048 ; +int limit =MAC_DEF_TIMEOUT ;u16 cmd;iowrite16 (MAC_RST , ioaddr +MCR1 );
Signature · 1 line
1.7.5.4
PATCH 4/8 r6040: fix typo on stats update in tx path
In reply to Florian FainelliWe are currently updating the rx fifo error counter in the tx path while it should have been the tx fifo error counter, fix that.
--- drivers/net/ethernet/rdc/r6040.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/rdc/r6040.c +1 -1
@@ -605,7 +605,7 @@ static void r6040_tx(struct net_device *dev) err =ioread16 (ioaddr +MLSR );if (err &0x0200 ) - dev->stats.rx_fifo_errors++; + dev->stats.tx_fifo_errors++;if (err & (0x2000 |0x4000 )) dev->stats.tx_carrier_errors++;
Signature · 1 line
1.7.5.4
PATCH 5/8 r6040: define and use MLSR register bits
In reply to Florian FainelliDefine the MLSR (MAC Last Status Register bits) for:
- tx fifo under-run
- tx exceed collision
- tx late collision
--- drivers/net/ethernet/rdc/r6040.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-)
drivers/net/ethernet/rdc/r6040.c +5 -2
@@ -77,6 +77,9 @@#define MR_BSR 0x18/* RX buffer size */ #define MR_DCR 0x1A/* RX descriptor control */ #define MLSR 0x1C/* Last status */ +#define TX_FIFO_UNDR 0x0200/* TX FIFO under-run */ +#define TX_EXCEEDC 0x2000/* Transmit exceed collision */ +#define TX_LATEC 0x4000/* Transmit late collision */ #define MMDIO 0x20/* MDIO control register */ #define MDIO_WRITE 0x4000/* MDIO write */ #define MDIO_READ 0x2000/* MDIO read */
@@ -604,9 +607,9 @@ static void r6040_tx(struct net_device *dev)/* Check for errors */ err =ioread16 (ioaddr +MLSR ); -if (err &0x0200 ) +if (err &TX_FIFO_UNDR ) dev->stats.tx_fifo_errors++; -if (err & (0x2000 |0x4000 )) +if (err & (TX_EXCEEDC |TX_LATEC )) dev->stats.tx_carrier_errors++;if (descptr->status &DSC_OWNER_MAC )
Signature · 1 line
1.7.5.4
PATCH 6/8 r6040: define and use MTPR transmit enable bit
In reply to Florian FainelliDefine MTPR bit 0 of the register and use it where it is appropriate.
--- drivers/net/ethernet/rdc/r6040.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/rdc/r6040.c +3 -2
@@ -74,6 +74,7 @@#define MT_ICR 0x0C/* TX interrupt control */ #define MR_ICR 0x10/* RX interrupt control */ #define MTPR 0x14/* TX poll command register */ +#define TM2TX 0x0001/* Trigger MAC to transmit */ #define MR_BSR 0x18/* RX buffer size */ #define MR_DCR 0x1A/* RX descriptor control */ #define MLSR 0x1C/* Last status */
@@ -420,7 +421,7 @@ static void r6040_init_mac_regs(struct net_device *dev)/* Let TX poll the descriptors * we may got called by r6040_tx_timeout which has left * some unsent tx buffers */ -iowrite16 (0x01 , ioaddr +MTPR ); +iowrite16 (TM2TX , ioaddr +MTPR ); }static void r6040_tx_timeout (struct net_device *dev)
@@ -844,7 +845,7 @@ static netdev_tx_t r6040_start_xmit(struct sk_buff *skb,skb_tx_timestamp (skb);/* Trigger the MAC to check the TX descriptor */ -iowrite16 (0x01 , ioaddr +MTPR ); +iowrite16 (TM2TX , ioaddr +MTPR ); lp->tx_insert_ptr = descptr->vndescp;/* If no tx resource, stop */
Signature · 1 line
1.7.5.4
PATCH 7/8 r6040: define and use bits of register PHY_CC
In reply to Florian FainelliDefine and use the bits of the PHY_CC (status change configuration) register.
--- drivers/net/ethernet/rdc/r6040.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/rdc/r6040.c +10 -2
@@ -128,6 +128,9 @@#define MID_3M 0x82/* MID3 Medium */ #define MID_3H 0x84/* MID3 High */ #define PHY_CC 0x88/* PHY status change configuration register */ +#define SCEN 0x8000/* PHY status change enable */ +#define PHYAD_SHIFT 8/* PHY address shift */ +#define TMRDIV_SHIFT 0/* Timer divider shift */ #define PHY_ST 0x8A/* PHY status register */ #define MAC_SM 0xAC/* MAC status machine */ #define MAC_SM_RST 0x0002/* MAC status machine reset */
@@ -1132,10 +1135,15 @@ static int __devinit r6040_init_one(struct pci_dev *pdev, err = -EIO ; goto err_out_free_res; } +/* If PHY status change register is still set to zero it means the -* bootloader didn't initialize it */ +* bootloader didn't initialize it, so we set it to: +* - enable phy status change +* - enable all phy addresses +* - set to lowest timer divider */ if (ioread16 (ioaddr +PHY_CC ) ==0 ) -iowrite16 (0x9f07 , ioaddr +PHY_CC ); +iowrite16 (SCEN |PHY_MAX_ADDR <<PHYAD_SHIFT | +7 <<TMRDIV_SHIFT , ioaddr +PHY_CC );/* Init system & device */ lp->base = ioaddr;
Signature · 1 line
1.7.5.4
PATCH 8/8 r6040: update copyright from 2007 to now
In reply to Florian Fainelli--- drivers/net/ethernet/rdc/r6040.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/net/ethernet/rdc/r6040.c +1 -1
@@ -4,7 +4,7 @@* Copyright (C) 2004 Sten Wang <[email protected]> * Copyright (C) 2007 * Daniel Gimpelevich <[email protected]> -* Florian Fainelli <[email protected]> +* Copyright (C) 2007-2012 Florian Fainelli <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License
Signature · 1 line
1.7.5.4
David Miller
maintainerFrom: Florian Fainelli <[email protected]>
Date: Wed, 11 Apr 2012 19:18:35 +0200
Quoted 2 lines
This series contains some cleanups and one small fix, they are targetted at net-next.
All applied, thanks Florian.