From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, Florian Fainelli <f.fainelli@gmail.com>
Subject: [PATCH net-next 03/11] net: bcmgenet: modularize bcmgenet_{open,close}
Date: Thu, 10 Jul 2014 15:46:16 -0700 [thread overview]
Message-ID: <1405032384-24006-4-git-send-email-f.fainelli@gmail.com> (raw)
In-Reply-To: <1405032384-24006-1-git-send-email-f.fainelli@gmail.com>
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 <f.fainelli@gmail.com>
---
drivers/net/ethernet/broadcom/genet/bcmgenet.c | 86 ++++++++++++++++----------
1 file changed, 53 insertions(+), 33 deletions(-)
diff --git a/drivers/net/ethernet/broadcom/genet/bcmgenet.c b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
index ae5a0c50e6ca..4d586f0d7d63 100644
--- a/drivers/net/ethernet/broadcom/genet/bcmgenet.c
+++ b/drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -1495,6 +1495,17 @@ static int reset_umac(struct bcmgenet_priv *priv)
return 0;
}
+static void bcmgenet_intr_disable(struct bcmgenet_priv *priv)
+{
+ /* Mask all interrupts.*/
+ bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_MASK_SET);
+ bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_CLEAR);
+ bcmgenet_intrl2_0_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
+ bcmgenet_intrl2_1_writel(priv, 0xFFFFFFFF, INTRL2_CPU_MASK_SET);
+ bcmgenet_intrl2_1_writel(priv, 0xFFFFFFFF, INTRL2_CPU_CLEAR);
+ bcmgenet_intrl2_1_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
+}
+
static int init_umac(struct bcmgenet_priv *priv)
{
struct device *kdev = &priv->pdev->dev;
@@ -1523,10 +1534,7 @@ static int init_umac(struct bcmgenet_priv *priv)
if (!GENET_IS_V1(priv) && !GENET_IS_V2(priv))
bcmgenet_rbuf_writel(priv, 1, RBUF_TBUF_SIZE_CTRL);
- /* Mask all interrupts.*/
- bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_MASK_SET);
- bcmgenet_intrl2_0_writel(priv, 0xFFFFFFFF, INTRL2_CPU_CLEAR);
- bcmgenet_intrl2_0_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
+ bcmgenet_intr_disable(priv);
cpu_mask_clear = UMAC_IRQ_RXDMA_BDONE;
@@ -1993,6 +2001,23 @@ static void bcmgenet_enable_dma(struct bcmgenet_priv *priv, u32 dma_ctrl)
bcmgenet_tdma_writel(priv, reg, DMA_CTRL);
}
+static void bcmgenet_netif_start(struct net_device *dev)
+{
+ struct bcmgenet_priv *priv = netdev_priv(dev);
+
+ /* Start the network engine */
+ napi_enable(&priv->napi);
+
+ umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, 1);
+
+ if (phy_is_internal(priv->phydev))
+ bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
+
+ netif_tx_start_all_queues(dev);
+
+ phy_start(priv->phydev);
+}
+
static int bcmgenet_open(struct net_device *dev)
{
struct bcmgenet_priv *priv = netdev_priv(dev);
@@ -2016,6 +2041,10 @@ static int bcmgenet_open(struct net_device *dev)
/* disable ethernet MAC while updating its registers */
umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, 0);
+ /* Make sure we reflect the value of CRC_CMD_FWD */
+ reg = bcmgenet_umac_readl(priv, UMAC_CMD);
+ priv->crc_fwd_en = !!(reg & CMD_CRC_FWD);
+
bcmgenet_set_hw_addr(priv, dev->dev_addr);
if (priv->wol_enabled) {
@@ -2030,6 +2059,8 @@ static int bcmgenet_open(struct net_device *dev)
bcmgenet_ext_writel(priv, reg, EXT_EXT_PWR_MGMT);
}
+ device_set_wakeup_capable(&dev->dev, 1);
+
/* Disable RX/TX DMA and flush TX queues */
dma_ctrl = bcmgenet_dma_disable(priv);
@@ -2057,23 +2088,7 @@ static int bcmgenet_open(struct net_device *dev)
goto err_irq0;
}
- /* Start the network engine */
- napi_enable(&priv->napi);
-
- umac_enable_set(priv, CMD_TX_EN | CMD_RX_EN, 1);
-
- /* Make sure we reflect the value of CRC_CMD_FWD */
- reg = bcmgenet_umac_readl(priv, UMAC_CMD);
- priv->crc_fwd_en = !!(reg & CMD_CRC_FWD);
-
- device_set_wakeup_capable(&dev->dev, 1);
-
- if (phy_is_internal(priv->phydev))
- bcmgenet_power_up(priv, GENET_POWER_PASSIVE);
-
- netif_tx_start_all_queues(dev);
-
- phy_start(priv->phydev);
+ bcmgenet_netif_start(dev);
return 0;
@@ -2140,6 +2155,22 @@ static int bcmgenet_dma_teardown(struct bcmgenet_priv *priv)
return ret;
}
+static void bcmgenet_netif_stop(struct net_device *dev)
+{
+ struct bcmgenet_priv *priv = netdev_priv(dev);
+
+ netif_tx_stop_all_queues(dev);
+ napi_disable(&priv->napi);
+ phy_stop(priv->phydev);
+
+ bcmgenet_intr_disable(priv);
+
+ /* Wait for pending work items to complete. Since interrupts are
+ * disabled no new work will be scheduled.
+ */
+ cancel_work_sync(&priv->bcmgenet_irq_work);
+}
+
static int bcmgenet_close(struct net_device *dev)
{
struct bcmgenet_priv *priv = netdev_priv(dev);
@@ -2147,13 +2178,11 @@ static int bcmgenet_close(struct net_device *dev)
netif_dbg(priv, ifdown, dev, "bcmgenet_close\n");
- phy_stop(priv->phydev);
+ bcmgenet_netif_stop(dev);
/* Disable MAC receive */
umac_enable_set(priv, CMD_RX_EN, 0);
- netif_tx_stop_all_queues(dev);
-
ret = bcmgenet_dma_teardown(priv);
if (ret)
return ret;
@@ -2161,8 +2190,6 @@ static int bcmgenet_close(struct net_device *dev)
/* Disable MAC transmit. TX DMA disabled have to done before this */
umac_enable_set(priv, CMD_TX_EN, 0);
- napi_disable(&priv->napi);
-
/* tx reclaim */
bcmgenet_tx_reclaim_all(dev);
bcmgenet_fini_dma(priv);
@@ -2170,12 +2197,6 @@ static int bcmgenet_close(struct net_device *dev)
free_irq(priv->irq0, priv);
free_irq(priv->irq1, priv);
- /* Wait for pending work items to complete - we are stopping
- * the clock now. Since interrupts are disabled, no new work
- * will be scheduled.
- */
- cancel_work_sync(&priv->bcmgenet_irq_work);
-
if (phy_is_internal(priv->phydev))
bcmgenet_power_down(priv, GENET_POWER_PASSIVE);
@@ -2573,7 +2594,6 @@ static int bcmgenet_remove(struct platform_device *pdev)
return 0;
}
-
static struct platform_driver bcmgenet_driver = {
.probe = bcmgenet_probe,
.remove = bcmgenet_remove,
--
1.9.1
next prev parent reply other threads:[~2014-07-10 22:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-10 22:46 [PATCH net-next 00/11] net: bcmgenet: PM and Wake-on-LAN Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 01/11] net: bcmgenet: remove wol_enabled conditional code Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 02/11] net: bcmgenet: add umac_enable_set helper Florian Fainelli
2014-07-11 20:39 ` David Miller
2014-07-10 22:46 ` Florian Fainelli [this message]
2014-07-10 22:46 ` [PATCH net-next 04/11] net: bcmgenet: add suspend/resume callbacks Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 05/11] net: bcmgenet: request Wake-on-LAN interrupt Florian Fainelli
2014-07-11 20:41 ` David Miller
2014-07-10 22:46 ` [PATCH net-next 06/11] net: bcmgenet: add Wake-on-LAN support code Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 07/11] net: bcmgenet: handle GENET_POWER_WOL_MAGIC Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 08/11] net: bcmgenet: handle UMAC_IRQ_MPD_R interrupt bit Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 09/11] net: bcmgenet: fix bcmgenet_wol_resume Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 10/11] net: bcmgenet: suspend and resume from Wake-on-LAN Florian Fainelli
2014-07-10 22:46 ` [PATCH net-next 11/11] net: bcmgenet: hook ethtool set/get_wol operations Florian Fainelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1405032384-24006-4-git-send-email-f.fainelli@gmail.com \
--to=f.fainelli@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).