ionic: Report "rx_bits_phy" stat to ethtool

This stat contains the number of total bits that the PHY has received;
it's useful for BER calculations. Add it to the ethtool stats output.

However, since this is one of the new "extra port stats", it's reported
in a different manner than the existing port stats and only
conditionally added to the ethtool stats output list: both the
DEV_CAP_EXTRA_STATS capability must be supported by the firmware, and
the firmware must set the value of the statistic to something other than
IONIC_STAT_INVALID.

To help support this scheme, the extra port stats region is initialized to
0xff's/IONIC_STAT_INVALID by the driver, to ensure the statistics that
the driver knows about but the firmware does not are still invalid
to the driver.

Signed-off-by: Eric Joyner <eric.joyner@amd.com>
Link: https://patch.msgid.link/20260614205303.48088-4-eric.joyner@amd.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Eric Joyner 2026-06-14 13:53:01 -07:00 committed by Jakub Kicinski
parent 433bc50081
commit cb683ff6ee
4 changed files with 73 additions and 1 deletions

View File

@ -184,6 +184,7 @@ struct ionic_dev {
u32 port_info_sz;
struct ionic_port_info *port_info;
dma_addr_t port_info_pa;
struct ionic_port_extra_stats port_extra_stats_cache;
struct ionic_devinfo dev_info;
};

View File

@ -731,6 +731,12 @@ int ionic_port_init(struct ionic *ionic)
return -ENOMEM;
}
/* If the driver knows about more "extra stats" than the firmware,
* make sure these stats are marked as invalid.
*/
memset(&idev->port_info->extra_stats, 0xff,
sizeof(idev->port_info->extra_stats));
sz = min(sizeof(ident->port.config), sizeof(idev->dev_cmd_regs->data));
mutex_lock(&ionic->dev_cmd_lock);

View File

@ -167,6 +167,7 @@ static const struct ionic_stat_desc ionic_rx_stats_desc[] = {
#define IONIC_NUM_PORT_STATS ARRAY_SIZE(ionic_port_stats_desc)
#define IONIC_NUM_TX_STATS ARRAY_SIZE(ionic_tx_stats_desc)
#define IONIC_NUM_RX_STATS ARRAY_SIZE(ionic_rx_stats_desc)
#define IONIC_NUM_EXTRA_PORT_STATS 1
#define MAX_Q(lif) ((lif)->netdev->real_num_tx_queues)
@ -232,6 +233,33 @@ static void ionic_get_lif_stats(struct ionic_lif *lif,
stats->hw_tx_aborted_errors = ns.tx_aborted_errors;
}
static u32 ionic_extra_port_stats_get_count(struct ionic_lif *lif)
{
struct ionic_dev *idev = &lif->ionic->idev;
struct ionic_port_extra_stats *pes_cache;
u32 count = 0;
if (!(lif->ionic->ident.dev.capabilities &
cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
return count;
pes_cache = &idev->port_extra_stats_cache;
/* Treat all of the extra port stats as invalid in subsequent calls if
* port_info isn't set; otherwise cache a valid snapshot for them.
*/
if (!idev->port_info) {
memset(pes_cache, 0xff, sizeof(*pes_cache));
return count;
}
*pes_cache = idev->port_info->extra_stats;
if (pes_cache->rx_bits_phy != IONIC_STAT_INVALID)
count++;
return count;
}
static u64 ionic_sw_stats_get_count(struct ionic_lif *lif)
{
u64 total = 0, tx_queues = MAX_Q(lif), rx_queues = MAX_Q(lif);
@ -243,7 +271,7 @@ static u64 ionic_sw_stats_get_count(struct ionic_lif *lif)
rx_queues += 1;
total += IONIC_NUM_LIF_STATS;
total += IONIC_NUM_PORT_STATS;
total += IONIC_NUM_PORT_STATS + ionic_extra_port_stats_get_count(lif);
total += tx_queues * IONIC_NUM_TX_STATS;
total += rx_queues * IONIC_NUM_RX_STATS;
@ -271,6 +299,20 @@ static void ionic_sw_stats_get_rx_strings(struct ionic_lif *lif, u8 **buf,
ionic_rx_stats_desc[i].name);
}
static void ionic_extra_port_stats_get_strings(struct ionic_lif *lif, u8 **buf)
{
struct ionic_port_extra_stats *pes_cache;
if (!(lif->ionic->ident.dev.capabilities &
cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
return;
pes_cache = &lif->ionic->idev.port_extra_stats_cache;
if (pes_cache->rx_bits_phy != IONIC_STAT_INVALID)
ethtool_puts(buf, "rx_bits_phy");
}
static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
{
int i, q_num;
@ -280,6 +322,7 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
ethtool_puts(buf, ionic_port_stats_desc[i].name);
ionic_extra_port_stats_get_strings(lif, buf);
for (q_num = 0; q_num < MAX_Q(lif); q_num++)
ionic_sw_stats_get_tx_strings(lif, buf, q_num);
@ -322,6 +365,25 @@ static void ionic_sw_stats_get_rxq_values(struct ionic_lif *lif, u64 **buf,
}
}
static void ionic_extra_port_stats_get_values(struct ionic_lif *lif, u64 **buf)
{
struct ionic_port_extra_stats *pes_cache;
if (!(lif->ionic->ident.dev.capabilities &
cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
return;
/* The number of statistics added to @buf here must equal
* ionic_extra_port_stats_get_count().
*/
pes_cache = &lif->ionic->idev.port_extra_stats_cache;
if (pes_cache->rx_bits_phy != IONIC_STAT_INVALID) {
**buf = le64_to_cpu(pes_cache->rx_bits_phy);
(*buf)++;
}
}
static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
{
struct ionic_port_stats *port_stats;
@ -341,6 +403,7 @@ static void ionic_sw_stats_get_values(struct ionic_lif *lif, u64 **buf)
&ionic_port_stats_desc[i]);
(*buf)++;
}
ionic_extra_port_stats_get_values(lif, buf);
for (q_num = 0; q_num < MAX_Q(lif); q_num++)
ionic_sw_stats_get_txq_values(lif, buf, q_num);

View File

@ -4,6 +4,8 @@
#ifndef _IONIC_STATS_H_
#define _IONIC_STATS_H_
#define IONIC_STAT_INVALID (cpu_to_le64(~0ULL))
#define IONIC_STAT_TO_OFFSET(type, stat_name) (offsetof(type, stat_name))
#define IONIC_STAT_DESC(type, stat_name) { \