net: bcmgenet: Reset RBUF on first open
authorPhil Elwell <phil@raspberrypi.com>
Fri, 25 Sep 2020 14:07:23 +0000 (15:07 +0100)
committerpopcornmix <popcornmix@gmail.com>
Wed, 27 Jan 2021 19:13:20 +0000 (19:13 +0000)
If the RBUF logic is not reset when the kernel starts then there
may be some data left over from any network boot loader. If the
64-byte packet headers are enabled then this can be fatal.

Extend bcmgenet_dma_disable to do perform the reset, but not when
called from bcmgenet_resume in order to preserve a wake packet.

N.B. This different handling of resume is just based on a hunch -
why else wouldn't one reset the RBUF as well as the TBUF? If this
isn't the case then it's easy to change the patch to make the RBUF
reset unconditional.

See: https://github.com/raspberrypi/linux/issues/3850

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
drivers/net/ethernet/broadcom/genet/bcmgenet.c

index ae7011c..3cbfe5b 100644 (file)
@@ -3243,7 +3243,7 @@ static void bcmgenet_get_hw_addr(struct bcmgenet_priv *priv,
 }
 
 /* Returns a reusable dma control register value */
-static u32 bcmgenet_dma_disable(struct bcmgenet_priv *priv)
+static u32 bcmgenet_dma_disable(struct bcmgenet_priv *priv, bool flush_rx)
 {
        u32 reg;
        u32 dma_ctrl;
@@ -3262,6 +3262,14 @@ static u32 bcmgenet_dma_disable(struct bcmgenet_priv *priv)
        udelay(10);
        bcmgenet_umac_writel(priv, 0, UMAC_TX_FLUSH);
 
+       if (flush_rx) {
+           reg = bcmgenet_rbuf_ctrl_get(priv);
+           bcmgenet_rbuf_ctrl_set(priv, reg | BIT(0));
+           udelay(10);
+           bcmgenet_rbuf_ctrl_set(priv, reg);
+           udelay(10);
+       }
+
        return dma_ctrl;
 }
 
@@ -3332,8 +3340,8 @@ static int bcmgenet_open(struct net_device *dev)
                bcmgenet_ext_writel(priv, reg, EXT_EXT_PWR_MGMT);
        }
 
-       /* Disable RX/TX DMA and flush TX queues */
-       dma_ctrl = bcmgenet_dma_disable(priv);
+       /* Disable RX/TX DMA and flush TX and RX queues */
+       dma_ctrl = bcmgenet_dma_disable(priv, true);
 
        /* Reinitialize TDMA and RDMA and SW housekeeping */
        ret = bcmgenet_init_dma(priv);
@@ -4194,7 +4202,7 @@ static int bcmgenet_resume(struct device *d)
        }
 
        /* Disable RX/TX DMA and flush TX queues */
-       dma_ctrl = bcmgenet_dma_disable(priv);
+       dma_ctrl = bcmgenet_dma_disable(priv, false);
 
        /* Reinitialize TDMA and RDMA and SW housekeeping */
        ret = bcmgenet_init_dma(priv);