diff mbox series

[v2] net: axienet: allow setups without MDIO

Message ID 20210324130536.1663062-1-daniel@zonque.org (mailing list archive)
State Accepted
Commit de9c7854e6e1589f639c6352112956d08243b659
Delegated to: Netdev Maintainers
Headers show
Series [v2] net: axienet: allow setups without MDIO | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers warning 3 maintainers not CCed: linux-arm-kernel@lists.infradead.org michal.simek@xilinx.com linux@armlinux.org.uk
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 7 this patch: 7
netdev/kdoc success Errors and warnings before: 2 this patch: 2
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 51 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/header_inline success Link

Commit Message

Daniel Mack March 24, 2021, 1:05 p.m. UTC
In setups with fixed-link settings there is no mdio node in DTS.
axienet_probe() already handles that gracefully but lp->mii_bus is
then NULL.

Fix code that tries to blindly grab the MDIO lock by introducing two helper
functions that make the locking conditional.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
v2:
  * Also fix axienet_dma_err_handler, as pointed out by Andrew Lunn

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 12 ++++++++++++
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 12 ++++++------
 2 files changed, 18 insertions(+), 6 deletions(-)

Comments

Radhey Shyam Pandey March 25, 2021, 12:44 p.m. UTC | #1
> -----Original Message-----
> From: Daniel Mack <daniel@zonque.org>
> Sent: Wednesday, March 24, 2021 6:36 PM
> To: Radhey Shyam Pandey <radheys@xilinx.com>
> Cc: davem@davemloft.net; kuba@kernel.org; netdev@vger.kernel.org;
> Daniel Mack <daniel@zonque.org>
> Subject: [PATCH v2] net: axienet: allow setups without MDIO
> 
> In setups with fixed-link settings there is no mdio node in DTS.
> axienet_probe() already handles that gracefully but lp->mii_bus is then
> NULL.
> 
> Fix code that tries to blindly grab the MDIO lock by introducing two helper
> functions that make the locking conditional.
> 
> Signed-off-by: Daniel Mack <daniel@zonque.org>

Reviewed-by: Radhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
Thanks!
> ---
> v2:
>   * Also fix axienet_dma_err_handler, as pointed out by Andrew Lunn
> 
>  drivers/net/ethernet/xilinx/xilinx_axienet.h      | 12 ++++++++++++
>  drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 12 ++++++------
>  2 files changed, 18 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet.h
> b/drivers/net/ethernet/xilinx/xilinx_axienet.h
> index 1e966a39967e5..aca7f82f6791b 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet.h
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet.h
> @@ -504,6 +504,18 @@ static inline u32 axinet_ior_read_mcr(struct
> axienet_local *lp)
>  	return axienet_ior(lp, XAE_MDIO_MCR_OFFSET);  }
> 
> +static inline void axienet_lock_mii(struct axienet_local *lp) {
> +	if (lp->mii_bus)
> +		mutex_lock(&lp->mii_bus->mdio_lock);
> +}
> +
> +static inline void axienet_unlock_mii(struct axienet_local *lp) {
> +	if (lp->mii_bus)
> +		mutex_unlock(&lp->mii_bus->mdio_lock);
> +}
> +
>  /**
>   * axienet_iow - Memory mapped Axi Ethernet register write
>   * @lp:         Pointer to axienet local structure
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> index 3a8775e0ca552..61380c6b65b86 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> @@ -1053,9 +1053,9 @@ static int axienet_open(struct net_device *ndev)
>  	 * including the MDIO. MDIO must be disabled before resetting.
>  	 * Hold MDIO bus lock to avoid MDIO accesses during the reset.
>  	 */
> -	mutex_lock(&lp->mii_bus->mdio_lock);
> +	axienet_lock_mii(lp);
>  	ret = axienet_device_reset(ndev);
> -	mutex_unlock(&lp->mii_bus->mdio_lock);
> +	axienet_unlock_mii(lp);
> 
>  	ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0);
>  	if (ret) {
> @@ -1148,9 +1148,9 @@ static int axienet_stop(struct net_device *ndev)
>  	}
> 
>  	/* Do a reset to ensure DMA is really stopped */
> -	mutex_lock(&lp->mii_bus->mdio_lock);
> +	axienet_lock_mii(lp);
>  	__axienet_device_reset(lp);
> -	mutex_unlock(&lp->mii_bus->mdio_lock);
> +	axienet_unlock_mii(lp);
> 
>  	cancel_work_sync(&lp->dma_err_task);
> 
> @@ -1709,9 +1709,9 @@ static void axienet_dma_err_handler(struct
> work_struct *work)
>  	 * including the MDIO. MDIO must be disabled before resetting.
>  	 * Hold MDIO bus lock to avoid MDIO accesses during the reset.
>  	 */
> -	mutex_lock(&lp->mii_bus->mdio_lock);
> +	axienet_lock_mii(lp);
>  	__axienet_device_reset(lp);
> -	mutex_unlock(&lp->mii_bus->mdio_lock);
> +	axienet_unlock_mii(lp);
> 
>  	for (i = 0; i < lp->tx_bd_num; i++) {
>  		cur_p = &lp->tx_bd_v[i];
> --
> 2.30.2
patchwork-bot+netdevbpf@kernel.org March 26, 2021, 12:30 a.m. UTC | #2
Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Wed, 24 Mar 2021 14:05:36 +0100 you wrote:
> In setups with fixed-link settings there is no mdio node in DTS.
> axienet_probe() already handles that gracefully but lp->mii_bus is
> then NULL.
> 
> Fix code that tries to blindly grab the MDIO lock by introducing two helper
> functions that make the locking conditional.
> 
> [...]

Here is the summary with links:
  - [v2] net: axienet: allow setups without MDIO
    https://git.kernel.org/netdev/net/c/de9c7854e6e1

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet.h b/drivers/net/ethernet/xilinx/xilinx_axienet.h
index 1e966a39967e5..aca7f82f6791b 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet.h
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet.h
@@ -504,6 +504,18 @@  static inline u32 axinet_ior_read_mcr(struct axienet_local *lp)
 	return axienet_ior(lp, XAE_MDIO_MCR_OFFSET);
 }
 
+static inline void axienet_lock_mii(struct axienet_local *lp)
+{
+	if (lp->mii_bus)
+		mutex_lock(&lp->mii_bus->mdio_lock);
+}
+
+static inline void axienet_unlock_mii(struct axienet_local *lp)
+{
+	if (lp->mii_bus)
+		mutex_unlock(&lp->mii_bus->mdio_lock);
+}
+
 /**
  * axienet_iow - Memory mapped Axi Ethernet register write
  * @lp:         Pointer to axienet local structure
diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
index 3a8775e0ca552..61380c6b65b86 100644
--- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
+++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -1053,9 +1053,9 @@  static int axienet_open(struct net_device *ndev)
 	 * including the MDIO. MDIO must be disabled before resetting.
 	 * Hold MDIO bus lock to avoid MDIO accesses during the reset.
 	 */
-	mutex_lock(&lp->mii_bus->mdio_lock);
+	axienet_lock_mii(lp);
 	ret = axienet_device_reset(ndev);
-	mutex_unlock(&lp->mii_bus->mdio_lock);
+	axienet_unlock_mii(lp);
 
 	ret = phylink_of_phy_connect(lp->phylink, lp->dev->of_node, 0);
 	if (ret) {
@@ -1148,9 +1148,9 @@  static int axienet_stop(struct net_device *ndev)
 	}
 
 	/* Do a reset to ensure DMA is really stopped */
-	mutex_lock(&lp->mii_bus->mdio_lock);
+	axienet_lock_mii(lp);
 	__axienet_device_reset(lp);
-	mutex_unlock(&lp->mii_bus->mdio_lock);
+	axienet_unlock_mii(lp);
 
 	cancel_work_sync(&lp->dma_err_task);
 
@@ -1709,9 +1709,9 @@  static void axienet_dma_err_handler(struct work_struct *work)
 	 * including the MDIO. MDIO must be disabled before resetting.
 	 * Hold MDIO bus lock to avoid MDIO accesses during the reset.
 	 */
-	mutex_lock(&lp->mii_bus->mdio_lock);
+	axienet_lock_mii(lp);
 	__axienet_device_reset(lp);
-	mutex_unlock(&lp->mii_bus->mdio_lock);
+	axienet_unlock_mii(lp);
 
 	for (i = 0; i < lp->tx_bd_num; i++) {
 		cur_p = &lp->tx_bd_v[i];