Skip to content

Commit 909ff5e

Browse files
ffainellidavem330
authored andcommitted
net: bcmgenet: modularize bcmgenet_{open,close}
Introduce a bunch of helper functions: bcmgenet_netif_start, bcmgenet_netif_stop and bcmgenet_intr_disable to help reuse code that is going to be necessary for suspend/resume. Signed-off-by: Florian Fainelli <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e29585b commit 909ff5e

File tree

1 file changed

+53
-33
lines changed

1 file changed

+53
-33
lines changed

drivers/net/ethernet/broadcom/genet/bcmgenet.c

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,17 @@ static int reset_umac(struct bcmgenet_priv *priv)
14881488
return 0;
14891489
}
14901490

1491+
static void bcmgenet_intr_disable(struct bcmgenet_priv *priv)
1492+
{
1493+
/* Mask all interrupts.*/
1494+
bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_MASK_SET);
1495+
bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_CLEAR);
1496+
bcmgenet_intrl2_0_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
1497+
bcmgenet_intrl2_1_writel(priv, 0xFFFFFFFF, INTRL2_CPU_MASK_SET);
1498+
bcmgenet_intrl2_1_writel(priv, 0xFFFFFFFF, INTRL2_CPU_CLEAR);
1499+
bcmgenet_intrl2_1_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
1500+
}
1501+
14911502
static int init_umac(struct bcmgenet_priv *priv)
14921503
{
14931504
struct device *kdev = &priv->pdev->dev;
@@ -1516,10 +1527,7 @@ static int init_umac(struct bcmgenet_priv *priv)
15161527
if (!GENET_IS_V1(priv) && !GENET_IS_V2(priv))
15171528
bcmgenet_rbuf_writel(priv, 1, RBUF_TBUF_SIZE_CTRL);
15181529

1519-
/* Mask all interrupts.*/
1520-
bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_MASK_SET);
1521-
bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_CLEAR);
1522-
bcmgenet_intrl2_0_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
1530+
bcmgenet_intr_disable(priv);
15231531

15241532
cpu_mask_clear = UMAC_IRQ_RXDMA_BDONE;
15251533

@@ -1986,6 +1994,23 @@ static void bcmgenet_enable_dma(struct bcmgenet_priv *priv, u32 dma_ctrl)
19861994
bcmgenet_tdma_writel(priv, reg, DMA_CTRL);
19871995
}
19881996

1997+
static void bcmgenet_netif_start(struct net_device *dev)
1998+
{
1999+
struct bcmgenet_priv *priv = netdev_priv(dev);
2000+
2001+
/* Start the network engine */
2002+
napi_enable(&priv->napi);
2003+
2004+
umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, true);
2005+
2006+
if (phy_is_internal(priv->phydev))
2007+
bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
2008+
2009+
netif_tx_start_all_queues(dev);
2010+
2011+
phy_start(priv->phydev);
2012+
}
2013+
19892014
static int bcmgenet_open(struct net_device *dev)
19902015
{
19912016
struct bcmgenet_priv *priv = netdev_priv(dev);
@@ -2009,6 +2034,10 @@ static int bcmgenet_open(struct net_device *dev)
20092034
/* disable ethernet MAC while updating its registers */
20102035
umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, false);
20112036

2037+
/* Make sure we reflect the value of CRC_CMD_FWD */
2038+
reg = bcmgenet_umac_readl(priv, UMAC_CMD);
2039+
priv->crc_fwd_en = !!(reg & CMD_CRC_FWD);
2040+
20122041
bcmgenet_set_hw_addr(priv, dev->dev_addr);
20132042

20142043
if (phy_is_internal(priv->phydev)) {
@@ -2017,6 +2046,8 @@ static int bcmgenet_open(struct net_device *dev)
20172046
bcmgenet_ext_writel(priv, reg, EXT_EXT_PWR_MGMT);
20182047
}
20192048

2049+
device_set_wakeup_capable(&dev->dev, 1);
2050+
20202051
/* Disable RX/TX DMA and flush TX queues */
20212052
dma_ctrl = bcmgenet_dma_disable(priv);
20222053

@@ -2044,23 +2075,7 @@ static int bcmgenet_open(struct net_device *dev)
20442075
goto err_irq0;
20452076
}
20462077

2047-
/* Start the network engine */
2048-
napi_enable(&priv->napi);
2049-
2050-
umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, true);
2051-
2052-
/* Make sure we reflect the value of CRC_CMD_FWD */
2053-
reg = bcmgenet_umac_readl(priv, UMAC_CMD);
2054-
priv->crc_fwd_en = !!(reg & CMD_CRC_FWD);
2055-
2056-
device_set_wakeup_capable(&dev->dev, 1);
2057-
2058-
if (phy_is_internal(priv->phydev))
2059-
bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
2060-
2061-
netif_tx_start_all_queues(dev);
2062-
2063-
phy_start(priv->phydev);
2078+
bcmgenet_netif_start(dev);
20642079

20652080
return 0;
20662081

@@ -2127,42 +2142,48 @@ static int bcmgenet_dma_teardown(struct bcmgenet_priv *priv)
21272142
return ret;
21282143
}
21292144

2145+
static void bcmgenet_netif_stop(struct net_device *dev)
2146+
{
2147+
struct bcmgenet_priv *priv = netdev_priv(dev);
2148+
2149+
netif_tx_stop_all_queues(dev);
2150+
napi_disable(&priv->napi);
2151+
phy_stop(priv->phydev);
2152+
2153+
bcmgenet_intr_disable(priv);
2154+
2155+
/* Wait for pending work items to complete. Since interrupts are
2156+
* disabled no new work will be scheduled.
2157+
*/
2158+
cancel_work_sync(&priv->bcmgenet_irq_work);
2159+
}
2160+
21302161
static int bcmgenet_close(struct net_device *dev)
21312162
{
21322163
struct bcmgenet_priv *priv = netdev_priv(dev);
21332164
int ret;
21342165

21352166
netif_dbg(priv, ifdown, dev, "bcmgenet_close\n");
21362167

2137-
phy_stop(priv->phydev);
2168+
bcmgenet_netif_stop(dev);
21382169

21392170
/* Disable MAC receive */
21402171
umac_enable_set(priv, CMD_RX_EN, false);
21412172

2142-
netif_tx_stop_all_queues(dev);
2143-
21442173
ret = bcmgenet_dma_teardown(priv);
21452174
if (ret)
21462175
return ret;
21472176

21482177
/* Disable MAC transmit. TX DMA disabled have to done before this */
21492178
umac_enable_set(priv, CMD_TX_EN, false);
21502179

2151-
napi_disable(&priv->napi);
2152-
21532180
/* tx reclaim */
21542181
bcmgenet_tx_reclaim_all(dev);
21552182
bcmgenet_fini_dma(priv);
21562183

21572184
free_irq(priv->irq0, priv);
21582185
free_irq(priv->irq1, priv);
21592186

2160-
/* Wait for pending work items to complete - we are stopping
2161-
* the clock now. Since interrupts are disabled, no new work
2162-
* will be scheduled.
2163-
*/
2164-
cancel_work_sync(&priv->bcmgenet_irq_work);
2165-
21662187
if (phy_is_internal(priv->phydev))
21672188
bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
21682189

@@ -2563,7 +2584,6 @@ static int bcmgenet_remove(struct platform_device *pdev)
25632584
return 0;
25642585
}
25652586

2566-
25672587
static struct platform_driver bcmgenet_driver = {
25682588
.probe = bcmgenet_probe,
25692589
.remove = bcmgenet_remove,

0 commit comments

Comments
 (0)