Skip to content

Commit 165f876

Browse files
vvfedorenkokuba-moo
authored andcommitted
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 <[email protected]> Reviewed-by: Michael Chan <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent fc5570e commit 165f876

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

drivers/net/ethernet/broadcom/bnxt/bnxt.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,11 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
512512
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
513513
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
514514

515-
if (ptp && ptp->tx_tstamp_en && !skb_is_gso(skb) &&
516-
atomic_dec_if_positive(&ptp->tx_avail) >= 0) {
515+
if (ptp && ptp->tx_tstamp_en && !skb_is_gso(skb)) {
516+
if (!atomic_dec_if_positive(&ptp->tx_avail)) {
517+
atomic64_inc(&ptp->stats.ts_err);
518+
goto tx_no_ts;
519+
}
517520
if (!bnxt_ptp_parse(skb, &ptp->tx_seqid,
518521
&ptp->tx_hdr_off)) {
519522
if (vlan_tag_flags)
@@ -526,6 +529,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
526529
}
527530
}
528531

532+
tx_no_ts:
529533
if (unlikely(skb->no_fcs))
530534
lflags |= cpu_to_le32(TX_BD_FLAGS_NO_CRC);
531535

@@ -732,8 +736,10 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
732736
return NETDEV_TX_OK;
733737

734738
tx_dma_error:
735-
if (BNXT_TX_PTP_IS_SET(lflags))
739+
if (BNXT_TX_PTP_IS_SET(lflags)) {
740+
atomic64_inc(&bp->ptp_cfg->stats.ts_err);
736741
atomic_inc(&bp->ptp_cfg->tx_avail);
742+
}
737743

738744
last_frag = i;
739745

@@ -812,10 +818,12 @@ static void __bnxt_tx_int(struct bnxt *bp, struct bnxt_tx_ring_info *txr,
812818
if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS)) {
813819
if (BNXT_CHIP_P5(bp)) {
814820
/* PTP worker takes ownership of the skb */
815-
if (!bnxt_get_tx_ts_p5(bp, skb))
821+
if (!bnxt_get_tx_ts_p5(bp, skb)) {
816822
skb = NULL;
817-
else
823+
} else {
824+
atomic64_inc(&bp->ptp_cfg->stats.ts_err);
818825
atomic_inc(&bp->ptp_cfg->tx_avail);
826+
}
819827
}
820828
}
821829

drivers/net/ethernet/broadcom/bnxt/bnxt_ethtool.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5233,6 +5233,19 @@ static void bnxt_get_rmon_stats(struct net_device *dev,
52335233
*ranges = bnxt_rmon_ranges;
52345234
}
52355235

5236+
static void bnxt_get_ptp_stats(struct net_device *dev,
5237+
struct ethtool_ts_stats *ts_stats)
5238+
{
5239+
struct bnxt *bp = netdev_priv(dev);
5240+
struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
5241+
5242+
if (ptp) {
5243+
ts_stats->pkts = ptp->stats.ts_pkts;
5244+
ts_stats->lost = ptp->stats.ts_lost;
5245+
ts_stats->err = atomic64_read(&ptp->stats.ts_err);
5246+
}
5247+
}
5248+
52365249
static void bnxt_get_link_ext_stats(struct net_device *dev,
52375250
struct ethtool_link_ext_stats *stats)
52385251
{
@@ -5316,4 +5329,5 @@ const struct ethtool_ops bnxt_ethtool_ops = {
53165329
.get_eth_mac_stats = bnxt_get_eth_mac_stats,
53175330
.get_eth_ctrl_stats = bnxt_get_eth_ctrl_stats,
53185331
.get_rmon_stats = bnxt_get_rmon_stats,
5332+
.get_ts_stats = bnxt_get_ptp_stats,
53195333
};

drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,13 @@ static void bnxt_stamp_tx_skb(struct bnxt *bp, struct sk_buff *skb)
696696
spin_unlock_bh(&ptp->ptp_lock);
697697
timestamp.hwtstamp = ns_to_ktime(ns);
698698
skb_tstamp_tx(ptp->tx_skb, &timestamp);
699+
ptp->stats.ts_pkts++;
699700
} else {
700701
if (!time_after_eq(jiffies, ptp->abs_txts_tmo)) {
701702
ptp->txts_pending = true;
702703
return;
703704
}
705+
ptp->stats.ts_lost++;
704706
netdev_warn_once(bp->dev,
705707
"TS query for TX timer failed rc = %x\n", rc);
706708
}
@@ -979,6 +981,11 @@ int bnxt_ptp_init(struct bnxt *bp, bool phc_cfg)
979981
rc = err;
980982
goto out;
981983
}
984+
985+
ptp->stats.ts_pkts = 0;
986+
ptp->stats.ts_lost = 0;
987+
atomic64_set(&ptp->stats.ts_err, 0);
988+
982989
if (BNXT_CHIP_P5(bp)) {
983990
spin_lock_bh(&ptp->ptp_lock);
984991
bnxt_refclk_read(bp, NULL, &ptp->current_time);
@@ -1013,5 +1020,6 @@ void bnxt_ptp_clear(struct bnxt *bp)
10131020
dev_kfree_skb_any(ptp->tx_skb);
10141021
ptp->tx_skb = NULL;
10151022
}
1023+
10161024
bnxt_unmap_ptp_regs(bp);
10171025
}

drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ struct bnxt_pps {
7979
struct pps_pin pins[BNXT_MAX_TSIO_PINS];
8080
};
8181

82+
struct bnxt_ptp_stats {
83+
u64 ts_pkts;
84+
u64 ts_lost;
85+
atomic64_t ts_err;
86+
};
87+
8288
struct bnxt_ptp_cfg {
8389
struct ptp_clock_info ptp_info;
8490
struct ptp_clock *ptp_clock;
@@ -125,6 +131,8 @@ struct bnxt_ptp_cfg {
125131
u32 refclk_mapped_regs[2];
126132
u32 txts_tmo;
127133
unsigned long abs_txts_tmo;
134+
135+
struct bnxt_ptp_stats stats;
128136
};
129137

130138
#if BITS_PER_LONG == 32

0 commit comments

Comments
 (0)