netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-2.6 V2] tg3: Fix phylib locking strategy
@ 2009-10-06  3:55 Matt Carlson
  2009-10-06  5:45 ` Felix Radensky
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Matt Carlson @ 2009-10-06  3:55 UTC (permalink / raw)
  To: Felix Radensky; +Cc: netdev, Michael Chan, andy

O.K.  Here is the latest version.  Felix, can you verify your problem
is solved with this patch?

---

Felix Radensky noted that chip resets were generating stack trace dumps.
This is because the driver is attempting to acquire the mdio bus mutex
while holding the tp->lock spinlock.  The fix is to change the code such
that every phy access takes the tp->lock spinlock instead.

Signed-off-by: Matt Carlson <mcarlson@broadcom.com>
---
 drivers/net/tg3.c |   41 ++++++++++++++---------------------------
 drivers/net/tg3.h |    1 -
 2 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index f09bc5d..ba5d3fe 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -902,11 +902,12 @@ static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg)
 	struct tg3 *tp = bp->priv;
 	u32 val;
 
-	if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_PAUSED)
-		return -EAGAIN;
+	spin_lock_bh(&tp->lock);
 
 	if (tg3_readphy(tp, reg, &val))
-		return -EIO;
+		val = -EIO;
+
+	spin_unlock_bh(&tp->lock);
 
 	return val;
 }
@@ -914,14 +915,16 @@ static int tg3_mdio_read(struct mii_bus *bp, int mii_id, int reg)
 static int tg3_mdio_write(struct mii_bus *bp, int mii_id, int reg, u16 val)
 {
 	struct tg3 *tp = bp->priv;
+	u32 ret = 0;
 
-	if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_PAUSED)
-		return -EAGAIN;
+	spin_lock_bh(&tp->lock);
 
 	if (tg3_writephy(tp, reg, val))
-		return -EIO;
+		ret = -EIO;
 
-	return 0;
+	spin_unlock_bh(&tp->lock);
+
+	return ret;
 }
 
 static int tg3_mdio_reset(struct mii_bus *bp)
@@ -1011,12 +1014,6 @@ static void tg3_mdio_config_5785(struct tg3 *tp)
 
 static void tg3_mdio_start(struct tg3 *tp)
 {
-	if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) {
-		mutex_lock(&tp->mdio_bus->mdio_lock);
-		tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED;
-		mutex_unlock(&tp->mdio_bus->mdio_lock);
-	}
-
 	tp->mi_mode &= ~MAC_MI_MODE_AUTO_POLL;
 	tw32_f(MAC_MI_MODE, tp->mi_mode);
 	udelay(80);
@@ -1041,15 +1038,6 @@ static void tg3_mdio_start(struct tg3 *tp)
 		tg3_mdio_config_5785(tp);
 }
 
-static void tg3_mdio_stop(struct tg3 *tp)
-{
-	if (tp->tg3_flags3 & TG3_FLG3_MDIOBUS_INITED) {
-		mutex_lock(&tp->mdio_bus->mdio_lock);
-		tp->tg3_flags3 |= TG3_FLG3_MDIOBUS_PAUSED;
-		mutex_unlock(&tp->mdio_bus->mdio_lock);
-	}
-}
-
 static int tg3_mdio_init(struct tg3 *tp)
 {
 	int i;
@@ -1141,7 +1129,6 @@ static void tg3_mdio_fini(struct tg3 *tp)
 		tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_INITED;
 		mdiobus_unregister(tp->mdio_bus);
 		mdiobus_free(tp->mdio_bus);
-		tp->tg3_flags3 &= ~TG3_FLG3_MDIOBUS_PAUSED;
 	}
 }
 
@@ -1363,7 +1350,7 @@ static void tg3_adjust_link(struct net_device *dev)
 	struct tg3 *tp = netdev_priv(dev);
 	struct phy_device *phydev = tp->mdio_bus->phy_map[PHY_ADDR];
 
-	spin_lock(&tp->lock);
+	spin_lock_bh(&tp->lock);
 
 	mac_mode = tp->mac_mode & ~(MAC_MODE_PORT_MODE_MASK |
 				    MAC_MODE_HALF_DUPLEX);
@@ -1431,7 +1418,7 @@ static void tg3_adjust_link(struct net_device *dev)
 	tp->link_config.active_speed = phydev->speed;
 	tp->link_config.active_duplex = phydev->duplex;
 
-	spin_unlock(&tp->lock);
+	spin_unlock_bh(&tp->lock);
 
 	if (linkmesg)
 		tg3_link_report(tp);
@@ -6392,8 +6379,6 @@ static int tg3_chip_reset(struct tg3 *tp)
 
 	tg3_nvram_lock(tp);
 
-	tg3_mdio_stop(tp);
-
 	tg3_ape_lock(tp, TG3_APE_LOCK_GRC);
 
 	/* No matching tg3_nvram_unlock() after this because
@@ -8698,6 +8683,8 @@ static int tg3_close(struct net_device *dev)
 
 	del_timer_sync(&tp->timer);
 
+	tg3_phy_stop(tp);
+
 	tg3_full_lock(tp, 1);
 #if 0
 	tg3_dump_state(tp);
diff --git a/drivers/net/tg3.h b/drivers/net/tg3.h
index 524691c..bab7940 100644
--- a/drivers/net/tg3.h
+++ b/drivers/net/tg3.h
@@ -2748,7 +2748,6 @@ struct tg3 {
 #define TG3_FLG3_5701_DMA_BUG		0x00000008
 #define TG3_FLG3_USE_PHYLIB		0x00000010
 #define TG3_FLG3_MDIOBUS_INITED		0x00000020
-#define TG3_FLG3_MDIOBUS_PAUSED		0x00000040
 #define TG3_FLG3_PHY_CONNECTED		0x00000080
 #define TG3_FLG3_RGMII_STD_IBND_DISABLE	0x00000100
 #define TG3_FLG3_RGMII_EXT_IBND_RX_EN	0x00000200
-- 
1.6.4.4



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

* Re: [PATCH net-2.6 V2] tg3: Fix phylib locking strategy
  2009-10-06  3:55 [PATCH net-2.6 V2] tg3: Fix phylib locking strategy Matt Carlson
@ 2009-10-06  5:45 ` Felix Radensky
  2009-10-07 10:41 ` David Miller
  2009-11-16 20:53 ` Felix Radensky
  2 siblings, 0 replies; 4+ messages in thread
From: Felix Radensky @ 2009-10-06  5:45 UTC (permalink / raw)
  To: Matt Carlson; +Cc: netdev, Michael Chan, andy

Hi, Matt

Matt Carlson wrote:
> O.K.  Here is the latest version.  Felix, can you verify your problem
> is solved with this patch?
>
>   
Thanks for the patch. I don't have the board with Broadcom NIC at the 
moment.
Hopefully I'll get it back in a couple of days and will test your patch.

Felix.

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

* Re: [PATCH net-2.6 V2] tg3: Fix phylib locking strategy
  2009-10-06  3:55 [PATCH net-2.6 V2] tg3: Fix phylib locking strategy Matt Carlson
  2009-10-06  5:45 ` Felix Radensky
@ 2009-10-07 10:41 ` David Miller
  2009-11-16 20:53 ` Felix Radensky
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2009-10-07 10:41 UTC (permalink / raw)
  To: mcarlson; +Cc: felix, netdev, mchan, andy

From: "Matt Carlson" <mcarlson@broadcom.com>
Date: Mon, 5 Oct 2009 20:55:29 -0700

> O.K.  Here is the latest version.  Felix, can you verify your problem
> is solved with this patch?
> 
> ---
> 
> Felix Radensky noted that chip resets were generating stack trace dumps.
> This is because the driver is attempting to acquire the mdio bus mutex
> while holding the tp->lock spinlock.  The fix is to change the code such
> that every phy access takes the tp->lock spinlock instead.
> 
> Signed-off-by: Matt Carlson <mcarlson@broadcom.com>

I'm going to apply this now to net-2.6, let me know if there are
any updates after testing.

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

* Re: [PATCH net-2.6 V2] tg3: Fix phylib locking strategy
  2009-10-06  3:55 [PATCH net-2.6 V2] tg3: Fix phylib locking strategy Matt Carlson
  2009-10-06  5:45 ` Felix Radensky
  2009-10-07 10:41 ` David Miller
@ 2009-11-16 20:53 ` Felix Radensky
  2 siblings, 0 replies; 4+ messages in thread
From: Felix Radensky @ 2009-11-16 20:53 UTC (permalink / raw)
  To: Matt Carlson; +Cc: netdev, Michael Chan, andy

Hi, Matt

Matt Carlson wrote:
> O.K.  Here is the latest version.  Felix, can you verify your problem
> is solved with this patch?
>
> ---
>
> Felix Radensky noted that chip resets were generating stack trace dumps.
> This is because the driver is attempting to acquire the mdio bus mutex
> while holding the tp->lock spinlock.  The fix is to change the code such
> that every phy access takes the tp->lock spinlock instead.
>
>   
Sorry for a very long delay, I didn't have access to hardware until today.
Your patch fixes initial problem I've reported, but I have a different
problem now, maybe it's related. It is 100% reproducible by the following
sequence

modprobe tg3
ifconfig eth2 up
ifconfig eth2 down
ifconfig eth2 up

As a result, link is not recognized after third invocation of ifconfig,
although network cable is plugged in. Below are relevant kernel messages.
Reloading tg3 driver fixes the problem.

tg3.c:v3.102 (September 1, 2009)
tg3 0002:05:00.0: PME# disabled
tg3 mdio bus: probed
eth2: Tigon3 [partno(BCM57760) rev 57780001] (PCI Express) MAC address 
00:10:18:00:00:00
eth2: attached PHY driver [Broadcom BCM57780] (mii_bus:phy_addr=500:01)
eth2: RXcsums[1] LinkChgREG[0] MIirq[0] ASF[0] TSOcap[1]
eth2: dma_rwctrl[76180000] dma_mask[64-bit]
tg3 0002:05:00.0: PME# disabled
tg3: eth2: Link is down.
tg3: eth2: Link is up at 1000 Mbps, full duplex.
tg3: eth2: Flow control is on for TX and on for RX.
tg3: eth2: Link is down.
tg3 0002:05:00.0: PME# disabled
tg3: eth2: Link is down.

Thanks.

Felix.


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

end of thread, other threads:[~2009-11-16 22:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-06  3:55 [PATCH net-2.6 V2] tg3: Fix phylib locking strategy Matt Carlson
2009-10-06  5:45 ` Felix Radensky
2009-10-07 10:41 ` David Miller
2009-11-16 20:53 ` Felix Radensky

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