Skip to content

Commit

Permalink
net: axienet: allow setups without MDIO
Browse files Browse the repository at this point in the history
[ Upstream commit de9c785 ]

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>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
zonque authored and gregkh committed Apr 21, 2021
1 parent f4d949e commit 10c717b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 12 additions & 0 deletions drivers/net/ethernet/xilinx/xilinx_axienet.h
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,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
Expand Down
12 changes: 6 additions & 6 deletions drivers/net/ethernet/xilinx/xilinx_axienet_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -1664,9 +1664,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];
Expand Down

0 comments on commit 10c717b

Please sign in to comment.