net: systemport: Dynamically allocate number of TX rings
authorFlorian Fainelli <f.fainelli@gmail.com>
Fri, 20 Jan 2017 19:08:26 +0000 (11:08 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sun, 22 Jan 2017 21:56:06 +0000 (16:56 -0500)
In preparation for adding SYSTEMPORT Lite, which has twice as less transmit
queues than SYSTEMPORT make sure we do allocate TX rings based on the
systemport,txq property to get an appropriate memory footprint.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bcmsysport.c
drivers/net/ethernet/broadcom/bcmsysport.h

index 744ed6ddaf373964a2b3526a2b73613932c73c87..31bb2c3696ec08db121c5b0cd134d4d26f4a52c0 100644 (file)
@@ -1752,6 +1752,10 @@ static int bcm_sysport_probe(struct platform_device *pdev)
        if (of_property_read_u32(dn, "systemport,num-rxq", &rxq))
                rxq = 1;
 
+       /* Sanity check the number of transmit queues */
+       if (!txq || txq > TDMA_NUM_RINGS)
+               return -EINVAL;
+
        dev = alloc_etherdev_mqs(sizeof(*priv), txq, rxq);
        if (!dev)
                return -ENOMEM;
@@ -1759,6 +1763,13 @@ static int bcm_sysport_probe(struct platform_device *pdev)
        /* Initialize private members */
        priv = netdev_priv(dev);
 
+       /* Allocate number of TX rings */
+       priv->tx_rings = devm_kcalloc(&pdev->dev, txq,
+                                     sizeof(struct bcm_sysport_tx_ring),
+                                     GFP_KERNEL);
+       if (!priv->tx_rings)
+               return -ENOMEM;
+
        priv->irq0 = platform_get_irq(pdev, 0);
        priv->irq1 = platform_get_irq(pdev, 1);
        priv->wol_irq = platform_get_irq(pdev, 2);
index 1c82e3da69a7bf6134389d982e15bc17697327a6..f051356b02746a24595b7f4ae5b367e45737e8cf 100644 (file)
@@ -659,7 +659,7 @@ struct bcm_sysport_priv {
        int                     wol_irq;
 
        /* Transmit rings */
-       struct bcm_sysport_tx_ring tx_rings[TDMA_NUM_RINGS];
+       struct bcm_sysport_tx_ring *tx_rings;
 
        /* Receive queue */
        void __iomem            *rx_bds;