[PATCH net-next 3/4] net: airoha: add rx_stall_recover ethtool counter

From: Vitaliy Sochnev

Date: Sun Aug 30 2026 - 03:59:49 EST


Make the RX-ring hw-stall recovery added by the previous commit
observable without grepping dmesg for its dev_warn_ratelimited():
add a custom ethtool -S statistic, rx_stall_recover, incremented once
per completed recovery.

It's tracked per-QDMA-instance rather than per-netdev, since the
stalled ring can carry traffic for more than one netdev at once (VIP
classification shares ring 4 across several protocols/ports on this
hardware) - there's no single netdev to attribute an individual event
to, so all netdevs behind the same QDMA instance report the same
aggregate count.

Kept separate from the actual recovery fix since this adds new
ethtool ABI and has no bearing on correctness; happy to have it queued
independently if that's preferred.

Signed-off-by: Vitaliy Sochnev <sochnev.v.74@xxxxxxxxx>
---
drivers/net/ethernet/airoha/airoha_eth.c | 44 ++++++++++++++++++++++++
drivers/net/ethernet/airoha/airoha_eth.h | 5 +++
2 files changed, 49 insertions(+)

diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index b53fe5b17653..efb1dd69cc16 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -1000,6 +1000,7 @@ static void airoha_qdma_rx_recover_work(struct work_struct *work)
napi_enable(&q->napi);
napi_schedule(&q->napi);

+ qdma->rx_recover_count++;
dev_warn_ratelimited(qdma->eth->dev,
"qid=%d RX ring recovered after hw stall (RX DMA paused for %lld us on this QDMA instance)\n",
qid, rx_dma_off_us);
@@ -2600,6 +2601,46 @@ static void airoha_ethtool_get_drvinfo(struct net_device *netdev,
strscpy(info->bus_info, dev_name(eth->dev), sizeof(info->bus_info));
}

+static const char airoha_ethtool_stats_str[][ETH_GSTRING_LEN] = {
+ "rx_stall_recover",
+};
+
+static void airoha_ethtool_get_strings(struct net_device *netdev, u32 sset,
+ u8 *data)
+{
+ int i;
+
+ if (sset != ETH_SS_STATS)
+ return;
+
+ for (i = 0; i < ARRAY_SIZE(airoha_ethtool_stats_str); i++)
+ ethtool_puts(&data, airoha_ethtool_stats_str[i]);
+}
+
+static int airoha_ethtool_get_sset_count(struct net_device *netdev, int sset)
+{
+ return sset == ETH_SS_STATS ?
+ ARRAY_SIZE(airoha_ethtool_stats_str) : -EOPNOTSUPP;
+}
+
+static void airoha_ethtool_get_ethtool_stats(struct net_device *netdev,
+ struct ethtool_stats *stats,
+ u64 *data)
+{
+ struct airoha_gdm_dev *dev = netdev_priv(netdev);
+ struct airoha_qdma *qdma;
+
+ rcu_read_lock();
+ qdma = rcu_dereference(dev->qdma);
+ /* aggregate recovery count for the whole qdma instance: the
+ * stalled ring can carry traffic for more than one netdev (VIP
+ * classification shares ring 4 across several protocols/ports),
+ * so there's no single netdev to attribute an individual event to
+ */
+ data[0] = qdma ? qdma->rx_recover_count : 0;
+ rcu_read_unlock();
+}
+
static void airoha_ethtool_get_mac_stats(struct net_device *netdev,
struct ethtool_eth_mac_stats *stats)
{
@@ -3502,6 +3543,9 @@ static const struct net_device_ops airoha_netdev_ops = {

static const struct ethtool_ops airoha_ethtool_ops = {
.get_drvinfo = airoha_ethtool_get_drvinfo,
+ .get_strings = airoha_ethtool_get_strings,
+ .get_sset_count = airoha_ethtool_get_sset_count,
+ .get_ethtool_stats = airoha_ethtool_get_ethtool_stats,
.get_eth_mac_stats = airoha_ethtool_get_mac_stats,
.get_rmon_stats = airoha_ethtool_get_rmon_stats,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h
index 483d6b59c351..d6591a779743 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.h
+++ b/drivers/net/ethernet/airoha/airoha_eth.h
@@ -582,6 +582,11 @@ struct airoha_qdma {
*/
struct work_struct rx_recover_work;
DECLARE_BITMAP(rx_recover_mask, AIROHA_NUM_RX_RING);
+ /* count of completed hw-stall recoveries, exposed via ethtool -S
+ * so a recovery event (and the packets it drops) is observable
+ * without grepping dmesg for the dev_warn_ratelimited() above
+ */
+ u32 rx_recover_count;

DECLARE_BITMAP(qos_channel_map, AIROHA_NUM_QOS_CHANNELS);
};
--
2.55.0