bcm63xx_enet: small fixes and cleanups
Subsystems (2)
cover bcm63xx_enet: small fixes and cleanups
This patch set fixes a few theoretical issues and cleans up the code a bit. It also adds a bit more managed function usage to simplify clock and iomem usage.
Based on net-next.
Jonas Gorski (6):
bcm63xx_enet: correct clock usage
bcm63xx_enet: do not write to random DMA channel on BCM6345
bcm63xx_enet: do not rely on probe order
bcm63xx_enet: use managed functions for clock/ioremap
bcm63xx_enet: drop unneeded NULL phy_clk check
bcm63xx_enet: remove unneeded include
drivers/net/ethernet/broadcom/bcm63xx_enet.c | 78 ++++++++++------------------ drivers/net/ethernet/broadcom/bcm63xx_enet.h | 1 - 2 files changed, 28 insertions(+), 51 deletions(-)
Signature · 1 line
2.13.2
PATCH 1/6 bcm63xx_enet: correct clock usage
Check the return code of prepare_enable and change one last instance of enable only to prepare_enable. Also properly disable and release the clock in error paths and on remove for enetsw.
--- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 31 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-)
drivers/net/ethernet/broadcom/bcm63xx_enet.c +23 -8
@@ -1773,7 +1773,9 @@ static int bcm_enet_probe(struct platform_device *pdev) ret =PTR_ERR (priv->mac_clk); goto out; } -clk_prepare_enable (priv->mac_clk); + ret =clk_prepare_enable (priv->mac_clk); +if (ret) + goto out_put_clk_mac;/* initialize default and fetch platform data */ priv->rx_ring_size =BCMENET_DEF_RX_DESC ;
@@ -1805,9 +1807,11 @@ static int bcm_enet_probe(struct platform_device *pdev)if (IS_ERR (priv->phy_clk)) { ret =PTR_ERR (priv->phy_clk); priv->phy_clk =NULL ; - goto out_put_clk_mac; + goto out_disable_clk_mac; } -clk_prepare_enable (priv->phy_clk); + ret =clk_prepare_enable (priv->phy_clk); +if (ret) + goto out_put_clk_phy; }/* do minimal hardware init to be able to probe mii bus */
@@ -1900,13 +1904,16 @@ static int bcm_enet_probe(struct platform_device *pdev) out_uninit_hw:/* turn off mdc clock */ enet_writel (priv,0 ,ENET_MIISC_REG ); -if (priv->phy_clk) { +if (priv->phy_clk)clk_disable_unprepare (priv->phy_clk); + +out_put_clk_phy: +if (priv->phy_clk)clk_put (priv->phy_clk); - } -out_put_clk_mac: +out_disable_clk_mac:clk_disable_unprepare (priv->mac_clk); +out_put_clk_mac:clk_put (priv->mac_clk); out:free_netdev (dev);
@@ -2748,7 +2755,9 @@ static int bcm_enetsw_probe(struct platform_device *pdev) ret =PTR_ERR (priv->mac_clk); goto out_unmap; } -clk_enable (priv->mac_clk); + ret =clk_prepare_enable (priv->mac_clk); +if (ret) + goto out_put_clk; priv->rx_chan =0 ; priv->tx_chan =1 ;
@@ -2769,7 +2778,7 @@ static int bcm_enetsw_probe(struct platform_device *pdev) ret =register_netdev (dev);if (ret) - goto out_put_clk; + goto out_disable_clk;netif_carrier_off (dev);platform_set_drvdata (pdev, dev);
@@ -2778,6 +2787,9 @@ static int bcm_enetsw_probe(struct platform_device *pdev)return 0 ; +out_disable_clk: +clk_disable_unprepare (priv->mac_clk); + out_put_clk:clk_put (priv->mac_clk);
@@ -2809,6 +2821,9 @@ static int bcm_enetsw_remove(struct platform_device *pdev) res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );release_mem_region (res->start,resource_size (res)); +clk_disable_unprepare (priv->mac_clk); +clk_put (priv->mac_clk); +free_netdev (dev);return 0 ; }
Signature · 1 line
2.13.2
PATCH 2/6 bcm63xx_enet: do not write to random DMA channel on BCM6345
In reply to Jonas GorskiThe DMA controller regs actually point to DMA channel 0, so the write to ENETDMA_CFG_REG will actually modify a random DMA channel.
Since DMA controller registers do not exist on BCM6345, guard the write with the usual check for dma_has_sram.
--- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bcm63xx_enet.c +2 -1
@@ -1062,7 +1062,8 @@ static int bcm_enet_open(struct net_device *dev) val =enet_readl (priv,ENET_CTL_REG ); val |=ENET_CTL_ENABLE_MASK ;enet_writel (priv, val,ENET_CTL_REG ); -enet_dma_writel (priv,ENETDMA_CFG_EN_MASK ,ENETDMA_CFG_REG ); +if (priv->dma_has_sram) +enet_dma_writel (priv,ENETDMA_CFG_EN_MASK ,ENETDMA_CFG_REG );enet_dmac_writel (priv, priv->dma_chan_en_mask,ENETDMAC_CHANCFG , priv->rx_chan);
Signature · 1 line
2.13.2
PATCH 3/6 bcm63xx_enet: do not rely on probe order
In reply to Jonas GorskiDo not rely on the shared device being probed before the enet(sw) devices. This makes it easier to eventually move out the shared device as a dma controller driver (what it should be).
--- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/net/ethernet/broadcom/bcm63xx_enet.c +2 -7
@@ -1722,10 +1722,8 @@ static int bcm_enet_probe(struct platform_device *pdev)const char *clk_name;int i, ret; -/* stop if shared driver failed, assume driver->probe will be -* called in the same order we register devices (correct ?) */ if (!bcm_enet_shared_base[0 ]) -return -ENODEV ; +return -EPROBE_DEFER ; res_irq =platform_get_resource (pdev,IORESOURCE_IRQ ,0 ); res_irq_rx =platform_get_resource (pdev,IORESOURCE_IRQ ,1 );
@@ -2696,11 +2694,8 @@ static int bcm_enetsw_probe(struct platform_device *pdev)struct resource *res_mem;int ret, irq_rx, irq_tx; -/* stop if shared driver failed, assume driver->probe will be -* called in the same order we register devices (correct ?) -*/ if (!bcm_enet_shared_base[0 ]) -return -ENODEV ; +return -EPROBE_DEFER ; res_mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); irq_rx =platform_get_irq (pdev,0 );
Signature · 1 line
2.13.2
PATCH 4/6 bcm63xx_enet: use managed functions for clock/ioremap
In reply to Jonas GorskiUse managed functions where possible to reduce the amount of resource handling on error and remove paths.
--- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 54 +++++++--------------------- 1 file changed, 12 insertions(+), 42 deletions(-)
drivers/net/ethernet/broadcom/bcm63xx_enet.c +12 -42
@@ -1767,14 +1767,14 @@ static int bcm_enet_probe(struct platform_device *pdev) clk_name ="enet1" ; } - priv->mac_clk =clk_get (&pdev->dev, clk_name); + priv->mac_clk =devm_clk_get (&pdev->dev, clk_name);if (IS_ERR (priv->mac_clk)) { ret =PTR_ERR (priv->mac_clk); goto out; } ret =clk_prepare_enable (priv->mac_clk);if (ret) - goto out_put_clk_mac; + goto out;/* initialize default and fetch platform data */ priv->rx_ring_size =BCMENET_DEF_RX_DESC ;
@@ -1802,7 +1802,7 @@ static int bcm_enet_probe(struct platform_device *pdev)if (priv->mac_id ==0 && priv->has_phy && !priv->use_external_mii) {/* using internal PHY, enable clock */ - priv->phy_clk =clk_get (&pdev->dev,"ephy" ); + priv->phy_clk =devm_clk_get (&pdev->dev,"ephy" );if (IS_ERR (priv->phy_clk)) { ret =PTR_ERR (priv->phy_clk); priv->phy_clk =NULL ;
@@ -1810,7 +1810,7 @@ static int bcm_enet_probe(struct platform_device *pdev) } ret =clk_prepare_enable (priv->phy_clk);if (ret) - goto out_put_clk_phy; + goto out_disable_clk_mac; }/* do minimal hardware init to be able to probe mii bus */
@@ -1906,14 +1906,8 @@ static int bcm_enet_probe(struct platform_device *pdev)if (priv->phy_clk)clk_disable_unprepare (priv->phy_clk); -out_put_clk_phy: -if (priv->phy_clk) -clk_put (priv->phy_clk); - out_disable_clk_mac:clk_disable_unprepare (priv->mac_clk); -out_put_clk_mac: -clk_put (priv->mac_clk); out:free_netdev (dev);return ret;
@@ -1949,12 +1943,10 @@ static int bcm_enet_remove(struct platform_device *pdev) }/* disable hw block clocks */ -if (priv->phy_clk) { +if (priv->phy_clk)clk_disable_unprepare (priv->phy_clk); -clk_put (priv->phy_clk); - } +clk_disable_unprepare (priv->mac_clk); -clk_put (priv->mac_clk);free_netdev (dev);return 0 ;
@@ -2734,26 +2726,20 @@ static int bcm_enetsw_probe(struct platform_device *pdev)if (ret) goto out; -if (!request_mem_region (res_mem->start,resource_size (res_mem), -"bcm63xx_enetsw" )) { - ret = -EBUSY ; + priv->base =devm_ioremap_resource (&pdev->dev, res_mem); +if (IS_ERR (priv->base)) { + ret =PTR_ERR (priv->base); goto out; } - priv->base =ioremap (res_mem->start,resource_size (res_mem)); -if (priv->base ==NULL ) { - ret = -ENOMEM ; - goto out_release_mem; - } - - priv->mac_clk =clk_get (&pdev->dev,"enetsw" ); + priv->mac_clk =devm_clk_get (&pdev->dev,"enetsw" );if (IS_ERR (priv->mac_clk)) { ret =PTR_ERR (priv->mac_clk); - goto out_unmap; + goto out; } ret =clk_prepare_enable (priv->mac_clk);if (ret) - goto out_put_clk; + goto out; priv->rx_chan =0 ; priv->tx_chan =1 ;
@@ -2785,15 +2771,6 @@ static int bcm_enetsw_probe(struct platform_device *pdev) out_disable_clk:clk_disable_unprepare (priv->mac_clk); - -out_put_clk: -clk_put (priv->mac_clk); - -out_unmap: -iounmap (priv->base); - -out_release_mem: -release_mem_region (res_mem->start,resource_size (res_mem)); out:free_netdev (dev);return ret;
@@ -2805,20 +2782,13 @@ static int bcm_enetsw_remove(struct platform_device *pdev) {struct bcm_enet_priv *priv;struct net_device *dev; -struct resource *res;/* stop netdevice */ dev =platform_get_drvdata (pdev); priv =netdev_priv (dev);unregister_netdev (dev); -/* release device resources */ -iounmap (priv->base); - res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); -release_mem_region (res->start,resource_size (res)); -clk_disable_unprepare (priv->mac_clk); -clk_put (priv->mac_clk);free_netdev (dev);return 0 ;
Signature · 1 line
2.13.2
PATCH 5/6 bcm63xx_enet: drop unneeded NULL phy_clk check
In reply to Jonas Gorskiclk_disable and clk_unprepare are NULL-safe, so need to duplicate the NULL check of the functions.
--- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/broadcom/bcm63xx_enet.c +2 -5
@@ -1903,8 +1903,7 @@ static int bcm_enet_probe(struct platform_device *pdev) out_uninit_hw:/* turn off mdc clock */ enet_writel (priv,0 ,ENET_MIISC_REG ); -if (priv->phy_clk) -clk_disable_unprepare (priv->phy_clk); +clk_disable_unprepare (priv->phy_clk); out_disable_clk_mac:clk_disable_unprepare (priv->mac_clk);
@@ -1943,9 +1942,7 @@ static int bcm_enet_remove(struct platform_device *pdev) }/* disable hw block clocks */ -if (priv->phy_clk) -clk_disable_unprepare (priv->phy_clk); - +clk_disable_unprepare (priv->phy_clk);clk_disable_unprepare (priv->mac_clk);free_netdev (dev);
Signature · 1 line
2.13.2
PATCH 6/6 bcm63xx_enet: remove unneeded include
In reply to Jonas GorskiWe don't use anyhing from that file, so drop it.
--- drivers/net/ethernet/broadcom/bcm63xx_enet.h | 1 - 1 file changed, 1 deletion(-)
drivers/net/ethernet/broadcom/bcm63xx_enet.h +0 -1
@@ -8,7 +8,6 @@#include <linux/platform_device.h> #include <bcm63xx_regs.h> -#include <bcm63xx_irq.h> #include <bcm63xx_io.h> #include <bcm63xx_iudma.h>
Signature · 1 line
2.13.2
David Miller
maintainerFrom: Jonas Gorski <[email protected]>
Date: Sun, 1 Oct 2017 13:02:14 +0200
Quoted 5 lines
This patch set fixes a few theoretical issues and cleans up the code a bit. It also adds a bit more managed function usage to simplify clock and iomem usage.
Based on net-next.
Series applied.