bnxt_en: Add tx ring mapping logic.
authorMichael Chan <michael.chan@broadcom.com>
Mon, 6 Feb 2017 21:55:39 +0000 (16:55 -0500)
committerDavid S. Miller <davem@davemloft.net>
Tue, 7 Feb 2017 18:30:59 +0000 (13:30 -0500)
To support XDP_TX, we need to add a set of dedicated TX rings, each
associated with the NAPI of an RX ring.  To assign XDP rings and regular
rings in a flexible way, we add a bp->tx_ring_map[] array to do the
remapping.  The netdev txq index is stored in the new field txq_index
so that we can retrieve the netdev txq when handling TX completions.
In this patch, before we introduce XDP_TX, the mapping is 1:1.

v2: Fixed a bug in bnxt_tx_int().

Signed-off-by: Michael Chan <michael.chan@broadcom.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/broadcom/bnxt/bnxt.c
drivers/net/ethernet/broadcom/bnxt/bnxt.h

index 1b051f9305983cd6f2919e195f032936e40cd6b5..811bc825bf90a86d32d6b2cfd7f9ff7650db095e 100644 (file)
@@ -262,8 +262,8 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
                return NETDEV_TX_OK;
        }
 
-       txr = &bp->tx_ring[i];
        txq = netdev_get_tx_queue(dev, i);
+       txr = &bp->tx_ring[bp->tx_ring_map[i]];
        prod = txr->tx_prod;
 
        free_size = bnxt_tx_avail(bp, txr);
@@ -509,8 +509,7 @@ tx_dma_error:
 static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
 {
        struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
-       int index = txr - &bp->tx_ring[0];
-       struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, index);
+       struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index);
        u16 cons = txr->tx_cons;
        struct pci_dev *pdev = bp->pdev;
        int i;
@@ -2975,6 +2974,8 @@ static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init)
                bnxt_free_stats(bp);
                bnxt_free_ring_grps(bp);
                bnxt_free_vnics(bp);
+               kfree(bp->tx_ring_map);
+               bp->tx_ring_map = NULL;
                kfree(bp->tx_ring);
                bp->tx_ring = NULL;
                kfree(bp->rx_ring);
@@ -3027,6 +3028,12 @@ static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
                if (!bp->tx_ring)
                        return -ENOMEM;
 
+               bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16),
+                                         GFP_KERNEL);
+
+               if (!bp->tx_ring_map)
+                       return -ENOMEM;
+
                if (bp->flags & BNXT_FLAG_SHARED_RINGS)
                        j = 0;
                else
@@ -3035,6 +3042,8 @@ static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init)
                for (i = 0; i < bp->tx_nr_rings; i++, j++) {
                        bp->tx_ring[i].bnapi = bp->bnapi[j];
                        bp->bnapi[j]->tx_ring = &bp->tx_ring[i];
+                       bp->tx_ring_map[i] = i;
+                       bp->tx_ring[i].txq_index = i;
                }
 
                rc = bnxt_alloc_stats(bp);
index 3a079b834a9c89f15e1c5d11533b2ed41b735f99..97ccce184694fc3191fc591e0d6e0efcf62d11c1 100644 (file)
@@ -566,6 +566,7 @@ struct bnxt_tx_ring_info {
        struct bnxt_napi        *bnapi;
        u16                     tx_prod;
        u16                     tx_cons;
+       u16                     txq_index;
        void __iomem            *tx_doorbell;
 
        struct tx_bd            *tx_desc_ring[MAX_TX_PAGES];
@@ -995,6 +996,7 @@ struct bnxt {
 
        struct bnxt_rx_ring_info        *rx_ring;
        struct bnxt_tx_ring_info        *tx_ring;
+       u16                     *tx_ring_map;
 
        struct sk_buff *        (*gro_func)(struct bnxt_tpa_info *, int, int,
                                            struct sk_buff *);