Commit 28c2d1a7 authored by Doug Berger's avatar Doug Berger Committed by David S. Miller

net: bcmgenet: enable loopback during UniMAC sw_reset

It is necessary for the UniMAC to be clocked at least 5 cycles
while the sw_reset is asserted to ensure a clean reset.

It was discovered that this condition was not being met when
connected to an external RGMII PHY that disabled the Rx clock in
the Power Save state.

This commit modifies the reset_umac function to place the (RG)MII
interface into a local loopback mode where the Rx clock comes
from the GENET sourced Tx clk during the sw_reset to ensure the
presence and stability of the clock.

In addition, it turns out that the sw_reset of the UniMAC is not
self clearing, but this was masked by a bug in the timeout code.

The sw_reset is now explicitly cleared by zeroing the UMAC_CMD
register before returning from reset_umac which makes it no
longer necessary to do so in init_umac and makes the clearing of
CMD_TX_EN and CMD_RX_EN by umac_enable_set redundant. The
timeout code (and its associated bug) are removed so reset_umac
no longer needs to return a result, and that means init_umac
that calls reset_umac does not need to as well.

Fixes: 1c1008c7 ("net: bcmgenet: add main driver file")
Signed-off-by: default avatarDoug Berger <opendmb@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 4fd6dc98
...@@ -1935,12 +1935,8 @@ static void umac_enable_set(struct bcmgenet_priv *priv, u32 mask, bool enable) ...@@ -1935,12 +1935,8 @@ static void umac_enable_set(struct bcmgenet_priv *priv, u32 mask, bool enable)
usleep_range(1000, 2000); usleep_range(1000, 2000);
} }
static int reset_umac(struct bcmgenet_priv *priv) static void reset_umac(struct bcmgenet_priv *priv)
{ {
struct device *kdev = &priv->pdev->dev;
unsigned int timeout = 0;
u32 reg;
/* 7358a0/7552a0: bad default in RBUF_FLUSH_CTRL.umac_sw_rst */ /* 7358a0/7552a0: bad default in RBUF_FLUSH_CTRL.umac_sw_rst */
bcmgenet_rbuf_ctrl_set(priv, 0); bcmgenet_rbuf_ctrl_set(priv, 0);
udelay(10); udelay(10);
...@@ -1948,23 +1944,10 @@ static int reset_umac(struct bcmgenet_priv *priv) ...@@ -1948,23 +1944,10 @@ static int reset_umac(struct bcmgenet_priv *priv)
/* disable MAC while updating its registers */ /* disable MAC while updating its registers */
bcmgenet_umac_writel(priv, 0, UMAC_CMD); bcmgenet_umac_writel(priv, 0, UMAC_CMD);
/* issue soft reset, wait for it to complete */ /* issue soft reset with (rg)mii loopback to ensure a stable rxclk */
bcmgenet_umac_writel(priv, CMD_SW_RESET, UMAC_CMD); bcmgenet_umac_writel(priv, CMD_SW_RESET | CMD_LCL_LOOP_EN, UMAC_CMD);
while (timeout++ < 1000) { udelay(2);
reg = bcmgenet_umac_readl(priv, UMAC_CMD); bcmgenet_umac_writel(priv, 0, UMAC_CMD);
if (!(reg & CMD_SW_RESET))
return 0;
udelay(1);
}
if (timeout == 1000) {
dev_err(kdev,
"timeout waiting for MAC to come out of reset\n");
return -ETIMEDOUT;
}
return 0;
} }
static void bcmgenet_intr_disable(struct bcmgenet_priv *priv) static void bcmgenet_intr_disable(struct bcmgenet_priv *priv)
...@@ -1994,20 +1977,16 @@ static void bcmgenet_link_intr_enable(struct bcmgenet_priv *priv) ...@@ -1994,20 +1977,16 @@ static void bcmgenet_link_intr_enable(struct bcmgenet_priv *priv)
bcmgenet_intrl2_0_writel(priv, int0_enable, INTRL2_CPU_MASK_CLEAR); bcmgenet_intrl2_0_writel(priv, int0_enable, INTRL2_CPU_MASK_CLEAR);
} }
static int init_umac(struct bcmgenet_priv *priv) static void init_umac(struct bcmgenet_priv *priv)
{ {
struct device *kdev = &priv->pdev->dev; struct device *kdev = &priv->pdev->dev;
int ret;
u32 reg; u32 reg;
u32 int0_enable = 0; u32 int0_enable = 0;
dev_dbg(&priv->pdev->dev, "bcmgenet: init_umac\n"); dev_dbg(&priv->pdev->dev, "bcmgenet: init_umac\n");
ret = reset_umac(priv); reset_umac(priv);
if (ret)
return ret;
bcmgenet_umac_writel(priv, 0, UMAC_CMD);
/* clear tx/rx counter */ /* clear tx/rx counter */
bcmgenet_umac_writel(priv, bcmgenet_umac_writel(priv,
MIB_RESET_RX | MIB_RESET_TX | MIB_RESET_RUNT, MIB_RESET_RX | MIB_RESET_TX | MIB_RESET_RUNT,
...@@ -2046,8 +2025,6 @@ static int init_umac(struct bcmgenet_priv *priv) ...@@ -2046,8 +2025,6 @@ static int init_umac(struct bcmgenet_priv *priv)
bcmgenet_intrl2_0_writel(priv, int0_enable, INTRL2_CPU_MASK_CLEAR); bcmgenet_intrl2_0_writel(priv, int0_enable, INTRL2_CPU_MASK_CLEAR);
dev_dbg(kdev, "done init umac\n"); dev_dbg(kdev, "done init umac\n");
return 0;
} }
/* Initialize a Tx ring along with corresponding hardware registers */ /* Initialize a Tx ring along with corresponding hardware registers */
...@@ -2863,12 +2840,7 @@ static int bcmgenet_open(struct net_device *dev) ...@@ -2863,12 +2840,7 @@ static int bcmgenet_open(struct net_device *dev)
/* take MAC out of reset */ /* take MAC out of reset */
bcmgenet_umac_reset(priv); bcmgenet_umac_reset(priv);
ret = init_umac(priv); init_umac(priv);
if (ret)
goto err_clk_disable;
/* disable ethernet MAC while updating its registers */
umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, false);
/* Make sure we reflect the value of CRC_CMD_FWD */ /* Make sure we reflect the value of CRC_CMD_FWD */
reg = bcmgenet_umac_readl(priv, UMAC_CMD); reg = bcmgenet_umac_readl(priv, UMAC_CMD);
...@@ -3546,9 +3518,7 @@ static int bcmgenet_probe(struct platform_device *pdev) ...@@ -3546,9 +3518,7 @@ static int bcmgenet_probe(struct platform_device *pdev)
!strcasecmp(phy_mode_str, "internal")) !strcasecmp(phy_mode_str, "internal"))
bcmgenet_power_up(priv, GENET_POWER_PASSIVE); bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
err = reset_umac(priv); reset_umac(priv);
if (err)
goto err_clk_disable;
err = bcmgenet_mii_init(dev); err = bcmgenet_mii_init(dev);
if (err) if (err)
...@@ -3660,9 +3630,7 @@ static int bcmgenet_resume(struct device *d) ...@@ -3660,9 +3630,7 @@ static int bcmgenet_resume(struct device *d)
bcmgenet_umac_reset(priv); bcmgenet_umac_reset(priv);
ret = init_umac(priv); init_umac(priv);
if (ret)
goto out_clk_disable;
/* From WOL-enabled suspend, switch to regular clock */ /* From WOL-enabled suspend, switch to regular clock */
if (priv->wolopts) if (priv->wolopts)
...@@ -3672,9 +3640,6 @@ static int bcmgenet_resume(struct device *d) ...@@ -3672,9 +3640,6 @@ static int bcmgenet_resume(struct device *d)
/* Speed settings must be restored */ /* Speed settings must be restored */
bcmgenet_mii_config(priv->dev, false); bcmgenet_mii_config(priv->dev, false);
/* disable ethernet MAC while updating its registers */
umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, false);
bcmgenet_set_hw_addr(priv, dev->dev_addr); bcmgenet_set_hw_addr(priv, dev->dev_addr);
if (priv->internal_phy) { if (priv->internal_phy) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment