@@ -880,7 +880,10 @@ struct bnxt_sw_tx_bd {
struct page *page;
DEFINE_DMA_UNMAP_ADDR(mapping);
DEFINE_DMA_UNMAP_LEN(len);
- u16 extra_segs;
+ union {
+ u16 extra_segs;
+ u16 xdp_len;
+ };
u8 hdr_size;
u8 is_ts_pkt;
u8 is_push;
@@ -1134,6 +1137,8 @@ struct bnxt_tx_sw_stats {
/* non-ethtool stats follow */
u64 tx_packets;
u64 tx_bytes;
+ u64 xdp_packets; /* under rx syncp */
+ u64 xdp_bytes; /* under rx syncp */
struct u64_stats_sync syncp;
};
@@ -13181,6 +13181,8 @@ static void bnxt_get_ring_stats(struct bnxt *bp,
stats->tx_packets += sw_stats.tx.tx_packets;
stats->tx_bytes += sw_stats.tx.tx_bytes;
+ stats->tx_packets += sw_stats.tx.xdp_packets;
+ stats->tx_bytes += sw_stats.tx.xdp_bytes;
stats->rx_missed_errors +=
BNXT_GET_RING_STATS64(sw, rx_discard_pkts);
@@ -13272,8 +13274,9 @@ static void bnxt_get_one_ring_drv_stats(struct bnxt *bp,
stats->rx_total_bytes += sw_stats.rx.rx_bytes;
stats->rx_total_ring_discards +=
BNXT_GET_RING_STATS64(hw_stats, rx_discard_pkts);
- stats->tx_total_packets += sw_stats.tx.tx_packets;
- stats->tx_total_bytes += sw_stats.tx.tx_bytes;
+ stats->tx_total_packets +=
+ sw_stats.tx.tx_packets + sw_stats.tx.xdp_packets;
+ stats->tx_total_bytes += sw_stats.tx.tx_bytes + sw_stats.tx.xdp_bytes;
stats->tx_total_resets += sw_stats.tx.tx_resets;
stats->tx_total_ring_discards +=
BNXT_GET_RING_STATS64(hw_stats, tx_discard_pkts);
@@ -15698,6 +15701,7 @@ static void bnxt_get_base_stats(struct net_device *dev,
struct netdev_queue_stats_tx *tx)
{
struct bnxt *bp = netdev_priv(dev);
+ int i;
rx->packets = bp->ring_drv_stats_prev.rx_total_packets;
rx->bytes = bp->ring_drv_stats_prev.rx_total_bytes;
@@ -15705,6 +15709,21 @@ static void bnxt_get_base_stats(struct net_device *dev,
tx->packets = bp->ring_drv_stats_prev.tx_total_packets;
tx->bytes = bp->ring_drv_stats_prev.tx_total_bytes;
+
+ for (i = 0; i < bp->cp_nr_rings; i++) {
+ struct bnxt_sw_stats *sw_stats = bp->bnapi[i]->cp_ring.sw_stats;
+ unsigned int seq;
+ u64 pkts, bytes;
+
+ do {
+ seq = u64_stats_fetch_begin(&sw_stats->rx.syncp);
+ pkts = sw_stats->tx.xdp_packets;
+ bytes = sw_stats->tx.xdp_bytes;
+ } while (u64_stats_fetch_retry(&sw_stats->rx.syncp, seq));
+
+ tx->packets += pkts;
+ tx->bytes += bytes;
+ }
}
static const struct netdev_stat_ops bnxt_stat_ops = {
@@ -38,6 +38,7 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
if (xdp && xdp_buff_has_frags(xdp)) {
sinfo = xdp_get_shared_info_from_buff(xdp);
num_frags = sinfo->nr_frags;
+ tx_buf->xdp_len += sinfo->xdp_frags_size;
}
/* fill up the first buffer */
@@ -47,6 +48,8 @@ struct bnxt_sw_tx_bd *bnxt_xmit_bd(struct bnxt *bp,
if (xdp)
tx_buf->page = virt_to_head_page(xdp->data);
+ tx_buf->xdp_len += len;
+
txbd = &txr->tx_desc_ring[TX_RING(bp, prod)][TX_IDX(prod)];
flags = (len << TX_BD_LEN_SHIFT) |
((num_frags + 1) << TX_BD_FLAGS_BD_CNT_SHIFT) |
@@ -120,9 +123,11 @@ static void __bnxt_xmit_xdp_redirect(struct bnxt *bp,
void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
{
+ struct bnxt_sw_stats *sw_stats = bnapi->cp_ring.sw_stats;
struct bnxt_tx_ring_info *txr = bnapi->tx_ring[0];
struct bnxt_rx_ring_info *rxr = bnapi->rx_ring;
u16 tx_hw_cons = txr->tx_hw_cons;
+ unsigned int pkts = 0, bytes = 0;
bool rx_doorbell_needed = false;
struct bnxt_sw_tx_bd *tx_buf;
u16 tx_cons = txr->tx_cons;
@@ -135,6 +140,10 @@ void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
while (RING_TX(bp, tx_cons) != tx_hw_cons) {
tx_buf = &txr->tx_buf_ring[RING_TX(bp, tx_cons)];
+ pkts++;
+ bytes += tx_buf->xdp_len;
+ tx_buf->xdp_len = 0;
+
if (tx_buf->action == XDP_REDIRECT) {
struct pci_dev *pdev = bp->pdev;
@@ -163,6 +172,12 @@ void bnxt_tx_int_xdp(struct bnxt *bp, struct bnxt_napi *bnapi, int budget)
tx_cons = NEXT_TX(tx_cons);
}
+ /* Note: Rx sync here, because Rx == NAPI context */
+ u64_stats_update_begin(&sw_stats->rx.syncp);
+ sw_stats->tx.xdp_packets += pkts;
+ sw_stats->tx.xdp_bytes += bytes;
+ u64_stats_update_end(&sw_stats->rx.syncp);
+
bnapi->events &= ~BNXT_TX_CMP_EVENT;
WRITE_ONCE(txr->tx_cons, tx_cons);
if (rx_doorbell_needed) {
Count XDP_TX and XDP_REDIRECT packets. Since the Tx rings are separate we count the packets sent to the base stats, not per-queues stats. The XDP stats are protected by the Rx syncp since they are in NAPI context. Feels slightly less ugly than having a Tx stats in Rx struct. But neither is ideal. Signed-off-by: Jakub Kicinski <kuba@kernel.org> --- drivers/net/ethernet/broadcom/bnxt/bnxt.h | 7 +++++- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 23 +++++++++++++++++-- drivers/net/ethernet/broadcom/bnxt/bnxt_xdp.c | 15 ++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-)