netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] r6040: misc cleanups
@ 2012-04-11 17:18 Florian Fainelli
  2012-04-11 17:18 ` [PATCH 1/8] r6040: consolidate MAC reset to its own function Florian Fainelli
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

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(-)

-- 
1.7.5.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/8] r6040: consolidate MAC reset to its own function
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-11 17:18 ` [PATCH 2/8] r6040: remove unused variable mcr1 from private structure Florian Fainelli
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

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.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |   37 ++++++++++++++++++-------------------
 1 files changed, 18 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index a26307f..c10b0b8 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -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;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/8] r6040: remove unused variable mcr1 from private structure
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
  2012-04-11 17:18 ` [PATCH 1/8] r6040: consolidate MAC reset to its own function Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-11 17:18 ` [PATCH 3/8] r6040: add a MAC operation timeout define Florian Fainelli
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index c10b0b8..fa29596 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -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;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/8] r6040: add a MAC operation timeout define
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
  2012-04-11 17:18 ` [PATCH 1/8] r6040: consolidate MAC reset to its own function Florian Fainelli
  2012-04-11 17:18 ` [PATCH 2/8] r6040: remove unused variable mcr1 from private structure Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-11 17:18 ` [PATCH 4/8] r6040: fix typo on stats update in tx path Florian Fainelli
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

2048 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.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index fa29596..9ffbf6e 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -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);
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/8] r6040: fix typo on stats update in tx path
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
                   ` (2 preceding siblings ...)
  2012-04-11 17:18 ` [PATCH 3/8] r6040: add a MAC operation timeout define Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-11 17:18 ` [PATCH 5/8] r6040: define and use MLSR register bits Florian Fainelli
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

We are currently updating the rx fifo error counter in the tx path while
it should have been the tx fifo error counter, fix that.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index 9ffbf6e..db33573 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -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++;
 
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/8] r6040: define and use MLSR register bits
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
                   ` (3 preceding siblings ...)
  2012-04-11 17:18 ` [PATCH 4/8] r6040: fix typo on stats update in tx path Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-11 17:18 ` [PATCH 6/8] r6040: define and use MTPR transmit enable bit Florian Fainelli
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

Define the MLSR (MAC Last Status Register bits) for:
- tx fifo under-run
- tx exceed collision
- tx late collision

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index db33573..1a365ae 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -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)
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/8] r6040: define and use MTPR transmit enable bit
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
                   ` (4 preceding siblings ...)
  2012-04-11 17:18 ` [PATCH 5/8] r6040: define and use MLSR register bits Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-11 17:18 ` [PATCH 7/8] r6040: define and use bits of register PHY_CC Florian Fainelli
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

Define MTPR bit 0 of the register and use it where it is appropriate.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index 1a365ae..afa4186 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -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 */
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/8] r6040: define and use bits of register PHY_CC
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
                   ` (5 preceding siblings ...)
  2012-04-11 17:18 ` [PATCH 6/8] r6040: define and use MTPR transmit enable bit Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-11 17:18 ` [PATCH 8/8] r6040: update copyright from 2007 to now Florian Fainelli
  2012-04-12 20:07 ` [PATCH 0/8] r6040: misc cleanups David Miller
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

Define and use the bits of the PHY_CC (status change configuration) register.

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index afa4186..050cf59 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -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;
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 8/8] r6040: update copyright from 2007 to now
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
                   ` (6 preceding siblings ...)
  2012-04-11 17:18 ` [PATCH 7/8] r6040: define and use bits of register PHY_CC Florian Fainelli
@ 2012-04-11 17:18 ` Florian Fainelli
  2012-04-12 20:07 ` [PATCH 0/8] r6040: misc cleanups David Miller
  8 siblings, 0 replies; 10+ messages in thread
From: Florian Fainelli @ 2012-04-11 17:18 UTC (permalink / raw)
  To: davem; +Cc: netdev, Florian Fainelli

Signed-off-by: Florian Fainelli <florian@openwrt.org>
---
 drivers/net/ethernet/rdc/r6040.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/ethernet/rdc/r6040.c b/drivers/net/ethernet/rdc/r6040.c
index 050cf59..4de7364 100644
--- a/drivers/net/ethernet/rdc/r6040.c
+++ b/drivers/net/ethernet/rdc/r6040.c
@@ -4,7 +4,7 @@
  * Copyright (C) 2004 Sten Wang <sten.wang@rdc.com.tw>
  * Copyright (C) 2007
  *	Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
- *	Florian Fainelli <florian@openwrt.org>
+ * Copyright (C) 2007-2012 Florian Fainelli <florian@openwrt.org>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/8] r6040: misc cleanups
  2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
                   ` (7 preceding siblings ...)
  2012-04-11 17:18 ` [PATCH 8/8] r6040: update copyright from 2007 to now Florian Fainelli
@ 2012-04-12 20:07 ` David Miller
  8 siblings, 0 replies; 10+ messages in thread
From: David Miller @ 2012-04-12 20:07 UTC (permalink / raw)
  To: florian; +Cc: netdev

From: Florian Fainelli <florian@openwrt.org>
Date: Wed, 11 Apr 2012 19:18:35 +0200

> This series contains some cleanups and one small fix, they are targetted
> at net-next.

All applied, thanks Florian.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-04-12 20:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-11 17:18 [PATCH 0/8] r6040: misc cleanups Florian Fainelli
2012-04-11 17:18 ` [PATCH 1/8] r6040: consolidate MAC reset to its own function Florian Fainelli
2012-04-11 17:18 ` [PATCH 2/8] r6040: remove unused variable mcr1 from private structure Florian Fainelli
2012-04-11 17:18 ` [PATCH 3/8] r6040: add a MAC operation timeout define Florian Fainelli
2012-04-11 17:18 ` [PATCH 4/8] r6040: fix typo on stats update in tx path Florian Fainelli
2012-04-11 17:18 ` [PATCH 5/8] r6040: define and use MLSR register bits Florian Fainelli
2012-04-11 17:18 ` [PATCH 6/8] r6040: define and use MTPR transmit enable bit Florian Fainelli
2012-04-11 17:18 ` [PATCH 7/8] r6040: define and use bits of register PHY_CC Florian Fainelli
2012-04-11 17:18 ` [PATCH 8/8] r6040: update copyright from 2007 to now Florian Fainelli
2012-04-12 20:07 ` [PATCH 0/8] r6040: misc cleanups David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).