Commit ee44d0b7 authored by Andre Przywara's avatar Andre Przywara Committed by David S. Miller

net: axienet: Propagate failure of DMA descriptor setup

When we fail allocating the DMA buffers in axienet_dma_bd_init(), we
report this error, but carry on with initialisation nevertheless.

This leads to a kernel panic when the driver later wants to send a
packet, as it uses uninitialised data structures.

Make the axienet_device_reset() routine return an error value, as it
contains the DMA buffer initialisation. Make sure we propagate the error
up the chain and eventually fail the driver initialisation, to avoid
relying on non-initialised buffers.
Signed-off-by: default avatarAndre Przywara <andre.przywara@arm.com>
Reviewed-by: default avatarRadhey Shyam Pandey <radhey.shyam.pandey@xilinx.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 24201a64
...@@ -437,9 +437,10 @@ static void axienet_setoptions(struct net_device *ndev, u32 options) ...@@ -437,9 +437,10 @@ static void axienet_setoptions(struct net_device *ndev, u32 options)
lp->options |= options; lp->options |= options;
} }
static void __axienet_device_reset(struct axienet_local *lp) static int __axienet_device_reset(struct axienet_local *lp)
{ {
u32 timeout; u32 timeout;
/* Reset Axi DMA. This would reset Axi Ethernet core as well. The reset /* Reset Axi DMA. This would reset Axi Ethernet core as well. The reset
* process of Axi DMA takes a while to complete as all pending * process of Axi DMA takes a while to complete as all pending
* commands/transfers will be flushed or completed during this * commands/transfers will be flushed or completed during this
...@@ -455,9 +456,11 @@ static void __axienet_device_reset(struct axienet_local *lp) ...@@ -455,9 +456,11 @@ static void __axienet_device_reset(struct axienet_local *lp)
if (--timeout == 0) { if (--timeout == 0) {
netdev_err(lp->ndev, "%s: DMA reset timeout!\n", netdev_err(lp->ndev, "%s: DMA reset timeout!\n",
__func__); __func__);
break; return -ETIMEDOUT;
} }
} }
return 0;
} }
/** /**
...@@ -470,13 +473,17 @@ static void __axienet_device_reset(struct axienet_local *lp) ...@@ -470,13 +473,17 @@ static void __axienet_device_reset(struct axienet_local *lp)
* areconnected to Axi Ethernet reset lines, this in turn resets the Axi * areconnected to Axi Ethernet reset lines, this in turn resets the Axi
* Ethernet core. No separate hardware reset is done for the Axi Ethernet * Ethernet core. No separate hardware reset is done for the Axi Ethernet
* core. * core.
* Returns 0 on success or a negative error number otherwise.
*/ */
static void axienet_device_reset(struct net_device *ndev) static int axienet_device_reset(struct net_device *ndev)
{ {
u32 axienet_status; u32 axienet_status;
struct axienet_local *lp = netdev_priv(ndev); struct axienet_local *lp = netdev_priv(ndev);
int ret;
__axienet_device_reset(lp); ret = __axienet_device_reset(lp);
if (ret)
return ret;
lp->max_frm_size = XAE_MAX_VLAN_FRAME_SIZE; lp->max_frm_size = XAE_MAX_VLAN_FRAME_SIZE;
lp->options |= XAE_OPTION_VLAN; lp->options |= XAE_OPTION_VLAN;
...@@ -491,9 +498,11 @@ static void axienet_device_reset(struct net_device *ndev) ...@@ -491,9 +498,11 @@ static void axienet_device_reset(struct net_device *ndev)
lp->options |= XAE_OPTION_JUMBO; lp->options |= XAE_OPTION_JUMBO;
} }
if (axienet_dma_bd_init(ndev)) { ret = axienet_dma_bd_init(ndev);
if (ret) {
netdev_err(ndev, "%s: descriptor allocation failed\n", netdev_err(ndev, "%s: descriptor allocation failed\n",
__func__); __func__);
return ret;
} }
axienet_status = axienet_ior(lp, XAE_RCW1_OFFSET); axienet_status = axienet_ior(lp, XAE_RCW1_OFFSET);
...@@ -518,6 +527,8 @@ static void axienet_device_reset(struct net_device *ndev) ...@@ -518,6 +527,8 @@ static void axienet_device_reset(struct net_device *ndev)
axienet_setoptions(ndev, lp->options); axienet_setoptions(ndev, lp->options);
netif_trans_update(ndev); netif_trans_update(ndev);
return 0;
} }
/** /**
...@@ -921,8 +932,9 @@ static int axienet_open(struct net_device *ndev) ...@@ -921,8 +932,9 @@ static int axienet_open(struct net_device *ndev)
*/ */
mutex_lock(&lp->mii_bus->mdio_lock); mutex_lock(&lp->mii_bus->mdio_lock);
axienet_mdio_disable(lp); axienet_mdio_disable(lp);
axienet_device_reset(ndev); ret = axienet_device_reset(ndev);
ret = axienet_mdio_enable(lp); if (ret == 0)
ret = axienet_mdio_enable(lp);
mutex_unlock(&lp->mii_bus->mdio_lock); mutex_unlock(&lp->mii_bus->mdio_lock);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment