bnxt_en: Refactor __bnxt_xmit_xdp().
authorMichael Chan <michael.chan@broadcom.com>
Mon, 8 Jul 2019 21:53:02 +0000 (17:53 -0400)
committerDavid S. Miller <davem@davemloft.net>
Mon, 8 Jul 2019 22:15:24 +0000 (15:15 -0700)
__bnxt_xmit_xdp() is used by XDP_TX and ethtool loopback packet transmit.
Refactor it so that it can be re-used by the XDP_REDIRECT logic.
Restructure the TX interrupt handler logic to cleanly separate XDP_TX
logic in preparation for XDP_REDIRECT.

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

index 4b3ae92a082b50a85519786abf14c2bd2cb7c70f..bf12cfce64c2561aa1f5e8b536d3b4627210e9a1 100644 (file)
@@ -596,6 +596,7 @@ struct bnxt_sw_tx_bd {
        DEFINE_DMA_UNMAP_ADDR(mapping);
        u8                      is_gso;
        u8                      is_push;
+       u8                      action;
        union {
                unsigned short          nr_frags;
                u16                     rx_prod;
index 21a043112d4edfe710b61055fed846d9d2da8e81..a0f3277447f57a80d5401b7f1f1dcf3fc2869740 100644 (file)
@@ -2799,7 +2799,7 @@ static int bnxt_run_loopback(struct bnxt *bp)
                dev_kfree_skb(skb);
                return -EIO;
        }
-       __bnxt_xmit_xdp(bp, txr, map, pkt_size, 0);
+       bnxt_xmit_bd(bp, txr, map, pkt_size);
 
        /* Sync BD data before updating doorbell */
        wmb();
index 4bc95950ea1bf98494790a6cf3f66c446a0d9020..41e232e133dbfe937e21439421616c27607690f4 100644 (file)
@@ -19,8 +19,9 @@
 #include "bnxt.h"
 #include "bnxt_xdp.h"
 
-void __bnxt_xmit_xdp(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
-                    dma_addr_t mapping, u32 len, u16 rx_prod)
+struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
+                                  struct bnxt_tx_ring_info *txr,
+                                  dma_addr_t mapping, u32 len)
 {
        struct bnxt_sw_tx_bd *tx_buf;
        struct tx_bd *txbd;
@@ -29,7 +30,6 @@ void __bnxt_xmit_xdp(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
 
        prod = txr->tx_prod;
        tx_buf = &txr->tx_buf_ring[prod];
-       tx_buf->rx_prod = rx_prod;
 
        txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)];
        flags = (len << TX_BD_LEN_SHIFT) | (1 << TX_BD_FLAGS_BD_CNT_SHIFT) |
@@ -40,30 +40,43 @@ void __bnxt_xmit_xdp(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
 
        prod = NEXT_TX(prod);
        txr->tx_prod = prod;
+       return tx_buf;
+}
+
+static void __bnxt_xmit_xdp(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
+                           dma_addr_t mapping, u32 len, u16 rx_prod)
+{
+       struct bnxt_sw_tx_bd *tx_buf;
+
+       tx_buf = bnxt_xmit_bd(bp, txr, mapping, len);
+       tx_buf->rx_prod = rx_prod;
+       tx_buf->action = XDP_TX;
 }
 
 void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts)
 {
        struct bnxt_tx_ring_info *txr = bnapi->tx_ring;
        struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
+       bool rx_doorbell_needed = false;
        struct bnxt_sw_tx_bd *tx_buf;
        u16 tx_cons = txr->tx_cons;
        u16 last_tx_cons = tx_cons;
-       u16 rx_prod;
        int i;
 
        for (i = 0; i < nr_pkts; i++) {
-               last_tx_cons = tx_cons;
+               tx_buf = &txr->tx_buf_ring[tx_cons];
+
+               if (tx_buf->action == XDP_TX) {
+                       rx_doorbell_needed = true;
+                       last_tx_cons = tx_cons;
+               }
                tx_cons = NEXT_TX(tx_cons);
        }
        txr->tx_cons = tx_cons;
-       if (bnxt_tx_avail(bp, txr) == bp->tx_ring_size) {
-               rx_prod = rxr->rx_prod;
-       } else {
+       if (rx_doorbell_needed) {
                tx_buf = &txr->tx_buf_ring[last_tx_cons];
-               rx_prod = tx_buf->rx_prod;
+               bnxt_db_write(bp, &rxr->rx_db, tx_buf->rx_prod);
        }
-       bnxt_db_write(bp, &rxr->rx_db, rx_prod);
 }
 
 /* returns the following:
index b36087b3f9b091df8b12163498a9255aa4066e12..20e470cd4f99a84e0bb497ffd5d5f666bd12f666 100644 (file)
@@ -10,8 +10,9 @@
 #ifndef BNXT_XDP_H
 #define BNXT_XDP_H
 
-void __bnxt_xmit_xdp(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
-                    dma_addr_t mapping, u32 len, u16 rx_prod);
+struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
+                                  struct bnxt_tx_ring_info *txr,
+                                  dma_addr_t mapping, u32 len);
 void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts);
 bool bnxt_rx_xdp(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, u16 cons,
                 struct page *page, u8 **data_ptr, unsigned int *len,