bnxt_en: add timestamping statistics support

The ethtool_ts_stats structure was introduced earlier this year. Now
it's time to support this group of counters in more drivers.
This patch adds support to bnxt driver.

Signed-off-by: Vadim Fedorenko <vadfed@meta.com>
Reviewed-by: Michael Chan <michael.chan@broadcom.com>
Link: https://lore.kernel.org/r/20240530204751.99636-1-vadfed@meta.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Vadim Fedorenko 2024-05-30 13:47:51 -07:00 committed by Jakub Kicinski
parent fc5570e0bd
commit 165f87691a
4 changed files with 43 additions and 5 deletions

View File

@ -512,8 +512,11 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
if (ptp && ptp->tx_tstamp_en && !skb_is_gso(skb) && if (ptp && ptp->tx_tstamp_en && !skb_is_gso(skb)) {
atomic_dec_if_positive(&ptp->tx_avail) >= 0) { if (!atomic_dec_if_positive(&ptp->tx_avail)) {
atomic64_inc(&ptp->stats.ts_err);
goto tx_no_ts;
}
if (!bnxt_ptp_parse(skb, &ptp->tx_seqid, if (!bnxt_ptp_parse(skb, &ptp->tx_seqid,
&ptp->tx_hdr_off)) { &ptp->tx_hdr_off)) {
if (vlan_tag_flags) if (vlan_tag_flags)
@ -526,6 +529,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
} }
} }
tx_no_ts:
if (unlikely(skb->no_fcs)) if (unlikely(skb->no_fcs))
lflags |= cpu_to_le32(TX_BD_FLAGS_NO_CRC); lflags |= cpu_to_le32(TX_BD_FLAGS_NO_CRC);
@ -732,8 +736,10 @@ tx_done:
return NETDEV_TX_OK; return NETDEV_TX_OK;
tx_dma_error: tx_dma_error:
if (BNXT_TX_PTP_IS_SET(lflags)) if (BNXT_TX_PTP_IS_SET(lflags)) {
atomic64_inc(&bp->ptp_cfg->stats.ts_err);
atomic_inc(&bp->ptp_cfg->tx_avail); atomic_inc(&bp->ptp_cfg->tx_avail);
}
last_frag = i; last_frag = i;
@ -812,10 +818,12 @@ static void __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) { if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
if (BNXT_CHIP_P5(bp)) { if (BNXT_CHIP_P5(bp)) {
/* PTP worker takes ownership of the skb */ /* PTP worker takes ownership of the skb */
if (!bnxt_get_tx_ts_p5(bp, skb)) if (!bnxt_get_tx_ts_p5(bp, skb)) {
skb = NULL; skb = NULL;
else } else {
atomic64_inc(&bp->ptp_cfg->stats.ts_err);
atomic_inc(&bp->ptp_cfg->tx_avail); atomic_inc(&bp->ptp_cfg->tx_avail);
}
} }
} }

View File

@ -5233,6 +5233,19 @@ static void bnxt_get_rmon_stats(struct net_device *dev,
*ranges = bnxt_rmon_ranges; *ranges = bnxt_rmon_ranges;
} }
static void bnxt_get_ptp_stats(struct net_device *dev,
struct ethtool_ts_stats *ts_stats)
{
struct bnxt *bp = netdev_priv(dev);
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
if (ptp) {
ts_stats->pkts = ptp->stats.ts_pkts;
ts_stats->lost = ptp->stats.ts_lost;
ts_stats->err = atomic64_read(&ptp->stats.ts_err);
}
}
static void bnxt_get_link_ext_stats(struct net_device *dev, static void bnxt_get_link_ext_stats(struct net_device *dev,
struct ethtool_link_ext_stats *stats) struct ethtool_link_ext_stats *stats)
{ {
@ -5316,4 +5329,5 @@ const struct ethtool_ops bnxt_ethtool_ops = {
.get_eth_mac_stats = bnxt_get_eth_mac_stats, .get_eth_mac_stats = bnxt_get_eth_mac_stats,
.get_eth_ctrl_stats = bnxt_get_eth_ctrl_stats, .get_eth_ctrl_stats = bnxt_get_eth_ctrl_stats,
.get_rmon_stats = bnxt_get_rmon_stats, .get_rmon_stats = bnxt_get_rmon_stats,
.get_ts_stats = bnxt_get_ptp_stats,
}; };

View File

@ -696,11 +696,13 @@ static void bnxt_stamp_tx_skb(struct bnxt *bp, struct sk_buff *skb)
spin_unlock_bh(&ptp->ptp_lock); spin_unlock_bh(&ptp->ptp_lock);
timestamp.hwtstamp = ns_to_ktime(ns); timestamp.hwtstamp = ns_to_ktime(ns);
skb_tstamp_tx(ptp->tx_skb, &timestamp); skb_tstamp_tx(ptp->tx_skb, &timestamp);
ptp->stats.ts_pkts++;
} else { } else {
if (!time_after_eq(jiffies, ptp->abs_txts_tmo)) { if (!time_after_eq(jiffies, ptp->abs_txts_tmo)) {
ptp->txts_pending = true; ptp->txts_pending = true;
return; return;
} }
ptp->stats.ts_lost++;
netdev_warn_once(bp->dev, netdev_warn_once(bp->dev,
"TS query for TX timer failed rc = %x\n", rc); "TS query for TX timer failed rc = %x\n", rc);
} }
@ -979,6 +981,11 @@ int bnxt_ptp_init(struct bnxt *bp, bool phc_cfg)
rc = err; rc = err;
goto out; goto out;
} }
ptp->stats.ts_pkts = 0;
ptp->stats.ts_lost = 0;
atomic64_set(&ptp->stats.ts_err, 0);
if (BNXT_CHIP_P5(bp)) { if (BNXT_CHIP_P5(bp)) {
spin_lock_bh(&ptp->ptp_lock); spin_lock_bh(&ptp->ptp_lock);
bnxt_refclk_read(bp, NULL, &ptp->current_time); bnxt_refclk_read(bp, NULL, &ptp->current_time);
@ -1013,5 +1020,6 @@ void bnxt_ptp_clear(struct bnxt *bp)
dev_kfree_skb_any(ptp->tx_skb); dev_kfree_skb_any(ptp->tx_skb);
ptp->tx_skb = NULL; ptp->tx_skb = NULL;
} }
bnxt_unmap_ptp_regs(bp); bnxt_unmap_ptp_regs(bp);
} }

View File

@ -79,6 +79,12 @@ struct bnxt_pps {
struct pps_pin pins[BNXT_MAX_TSIO_PINS]; struct pps_pin pins[BNXT_MAX_TSIO_PINS];
}; };
struct bnxt_ptp_stats {
u64 ts_pkts;
u64 ts_lost;
atomic64_t ts_err;
};
struct bnxt_ptp_cfg { struct bnxt_ptp_cfg {
struct ptp_clock_info ptp_info; struct ptp_clock_info ptp_info;
struct ptp_clock *ptp_clock; struct ptp_clock *ptp_clock;
@ -125,6 +131,8 @@ struct bnxt_ptp_cfg {
u32 refclk_mapped_regs[2]; u32 refclk_mapped_regs[2];
u32 txts_tmo; u32 txts_tmo;
unsigned long abs_txts_tmo; unsigned long abs_txts_tmo;
struct bnxt_ptp_stats stats;
}; };
#if BITS_PER_LONG == 32 #if BITS_PER_LONG == 32