OSDN Git Service

net: stmmac: Determine earlier the size of RX buffer
authorJose Abreu <Jose.Abreu@synopsys.com>
Wed, 18 Dec 2019 10:17:36 +0000 (11:17 +0100)
committerDavid S. Miller <davem@davemloft.net>
Wed, 18 Dec 2019 20:04:17 +0000 (12:04 -0800)
Split Header feature needs to know the size of RX buffer but current
code is determining it too late. Fix this by moving the RX buffer
computation to earlier stage.

Changes from v2:
- Do not try to align already aligned buffer size

Fixes: 67afd6d1cfdf ("net: stmmac: Add Split Header support and enable it in XGMAC cores")
Signed-off-by: Jose Abreu <Jose.Abreu@synopsys.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c

index bbc65bd..eccbf5d 100644 (file)
@@ -1293,19 +1293,9 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
        struct stmmac_priv *priv = netdev_priv(dev);
        u32 rx_count = priv->plat->rx_queues_to_use;
        int ret = -ENOMEM;
-       int bfsize = 0;
        int queue;
        int i;
 
-       bfsize = stmmac_set_16kib_bfsize(priv, dev->mtu);
-       if (bfsize < 0)
-               bfsize = 0;
-
-       if (bfsize < BUF_SIZE_16KiB)
-               bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
-
-       priv->dma_buf_sz = bfsize;
-
        /* RX INITIALIZATION */
        netif_dbg(priv, probe, priv->dev,
                  "SKB addresses:\nskb\t\tskb data\tdma data\n");
@@ -1347,8 +1337,6 @@ static int init_dma_rx_desc_rings(struct net_device *dev, gfp_t flags)
                }
        }
 
-       buf_sz = bfsize;
-
        return 0;
 
 err_init_rx_buffers:
@@ -2658,6 +2646,7 @@ static void stmmac_hw_teardown(struct net_device *dev)
 static int stmmac_open(struct net_device *dev)
 {
        struct stmmac_priv *priv = netdev_priv(dev);
+       int bfsize = 0;
        u32 chan;
        int ret;
 
@@ -2677,7 +2666,16 @@ static int stmmac_open(struct net_device *dev)
        memset(&priv->xstats, 0, sizeof(struct stmmac_extra_stats));
        priv->xstats.threshold = tc;
 
-       priv->dma_buf_sz = STMMAC_ALIGN(buf_sz);
+       bfsize = stmmac_set_16kib_bfsize(priv, dev->mtu);
+       if (bfsize < 0)
+               bfsize = 0;
+
+       if (bfsize < BUF_SIZE_16KiB)
+               bfsize = stmmac_set_bfsize(dev->mtu, priv->dma_buf_sz);
+
+       priv->dma_buf_sz = bfsize;
+       buf_sz = bfsize;
+
        priv->rx_copybreak = STMMAC_RX_COPYBREAK;
 
        ret = alloc_dma_desc_resources(priv);