Commit 9f898fc2 authored by Justin Chen's avatar Justin Chen Committed by Jakub Kicinski

net: bcmasp: fix memory leak when bringing down interface

When bringing down the TX rings we flush the rings but forget to
reclaimed the flushed packets. This leads to a memory leak since we
do not free the dma mapped buffers. This also leads to tx control
block corruption when bringing down the interface for power
management.

Fixes: 490cb412 ("net: bcmasp: Add support for ASP2.0 Ethernet controller")
Signed-off-by: default avatarJustin Chen <justin.chen@broadcom.com>
Acked-by: default avatarFlorian Fainelli <florian.fainelli@broadcom.com>
Reviewed-by: default avatarSimon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240418180541.2271719-1-justin.chen@broadcom.comSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 680d11f6
...@@ -436,10 +436,8 @@ static void umac_init(struct bcmasp_intf *intf) ...@@ -436,10 +436,8 @@ static void umac_init(struct bcmasp_intf *intf)
umac_wl(intf, 0x800, UMC_RX_MAX_PKT_SZ); umac_wl(intf, 0x800, UMC_RX_MAX_PKT_SZ);
} }
static int bcmasp_tx_poll(struct napi_struct *napi, int budget) static int bcmasp_tx_reclaim(struct bcmasp_intf *intf)
{ {
struct bcmasp_intf *intf =
container_of(napi, struct bcmasp_intf, tx_napi);
struct bcmasp_intf_stats64 *stats = &intf->stats64; struct bcmasp_intf_stats64 *stats = &intf->stats64;
struct device *kdev = &intf->parent->pdev->dev; struct device *kdev = &intf->parent->pdev->dev;
unsigned long read, released = 0; unsigned long read, released = 0;
...@@ -482,10 +480,16 @@ static int bcmasp_tx_poll(struct napi_struct *napi, int budget) ...@@ -482,10 +480,16 @@ static int bcmasp_tx_poll(struct napi_struct *napi, int budget)
DESC_RING_COUNT); DESC_RING_COUNT);
} }
/* Ensure all descriptors have been written to DRAM for the hardware return released;
* to see updated contents. }
*/
wmb(); static int bcmasp_tx_poll(struct napi_struct *napi, int budget)
{
struct bcmasp_intf *intf =
container_of(napi, struct bcmasp_intf, tx_napi);
int released = 0;
released = bcmasp_tx_reclaim(intf);
napi_complete(&intf->tx_napi); napi_complete(&intf->tx_napi);
...@@ -797,6 +801,7 @@ static void bcmasp_init_tx(struct bcmasp_intf *intf) ...@@ -797,6 +801,7 @@ static void bcmasp_init_tx(struct bcmasp_intf *intf)
intf->tx_spb_dma_read = intf->tx_spb_dma_addr; intf->tx_spb_dma_read = intf->tx_spb_dma_addr;
intf->tx_spb_index = 0; intf->tx_spb_index = 0;
intf->tx_spb_clean_index = 0; intf->tx_spb_clean_index = 0;
memset(intf->tx_cbs, 0, sizeof(struct bcmasp_tx_cb) * DESC_RING_COUNT);
/* Make sure channels are disabled */ /* Make sure channels are disabled */
tx_spb_ctrl_wl(intf, 0x0, TX_SPB_CTRL_ENABLE); tx_spb_ctrl_wl(intf, 0x0, TX_SPB_CTRL_ENABLE);
...@@ -885,6 +890,8 @@ static void bcmasp_netif_deinit(struct net_device *dev) ...@@ -885,6 +890,8 @@ static void bcmasp_netif_deinit(struct net_device *dev)
} while (timeout-- > 0); } while (timeout-- > 0);
tx_spb_dma_wl(intf, 0x0, TX_SPB_DMA_FIFO_CTRL); tx_spb_dma_wl(intf, 0x0, TX_SPB_DMA_FIFO_CTRL);
bcmasp_tx_reclaim(intf);
umac_enable_set(intf, UMC_CMD_TX_EN, 0); umac_enable_set(intf, UMC_CMD_TX_EN, 0);
phy_stop(dev->phydev); phy_stop(dev->phydev);
......
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