Skip to contentSkip to conversation

ionic: Expose more port stats to ethtool

PATCH Superseded Eric Joyner 3 participants 11 messages Jun 10 – Jun 15

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover ionic: Expose more port stats to ethtool

The primary aim of this patchset is to support the reporting of new port statistics (and one old one) that firmware sends to the driver; these include general FEC codeword stats and the FEC histogram. A scheme for these extra stats is introduced in order to prevent devices that don't support these new statistics from unconditionally setting them or reporting them in ethtool.

---
v4:
- A big addition is a new scheme where the driver will only report the new statistics supported by firmware if the firmware sets the statistic value to something that isn't invalid; more details in patch 3, and this is used in patch 5 to prevent FEC stats from being unconditionally reported on devices/firmware versions that don't support these stats.
- The link_down_count from firmware mentioned in v2 was moved back to an entry in the general ethtool statistics; the existing driver-calculated value for the ethtool ext link is more appropriate due to the firmware value being a small size and not resetting between driver loads.
- Add netdev_err_once() call recommended by Sashiko for ethtool handler
- Drop devcmd retry logic patch from previous versions for now; explicitly include Brett's patch from another patchset to fix the ionic_get_link_ext_stats() PF/VF check

v3:
Address issues mostly found by Sashiko:
- Fix potential return of uninitialized variable in __ionic_dev_cmd_wait()
- Fix bounds of wait in __ionic_dev_cmd_wait() to prevent function from giving up prematurely now that the wait period has changed
- Add NULL check to ionic_get_link_ext_stats(), following the example set by ionic_get_link_ksettings()
- Add missing le16_to_cpu() when copying link_down_count from firmware

v2:
- Add missing cpu_to_le64() to FEC histogram stat assignment
- Remove unused pb_stats field that's replaced by the new FEC/extra stats
- Replace ethtool ext link stat with firmware stat instead of adding the firmware stat to general ethtool statistics; remove old driver calculated stat
- Add explanation for what EAGAIN return value could be used for in commit message

Brett Creeley (1):
ionic: Fix check in ionic_get_link_ext_stats

Eric Joyner (4):
ionic: Update ionic_if.h with new extra port stats
ionic: Report "rx_bits_phy" stat to ethtool
ionic: Report "link_down_events_phy" in ethtool statistics
ionic: Add .get_fec_stats ethtool handler

 .../net/ethernet/pensando/ionic/ionic_dev.h   |  1 +
 .../ethernet/pensando/ionic/ionic_ethtool.c   | 83 ++++++++++++++++++-
 .../net/ethernet/pensando/ionic/ionic_if.h    | 39 +++------
 .../net/ethernet/pensando/ionic/ionic_main.c  |  6 ++
 .../net/ethernet/pensando/ionic/ionic_stats.c | 64 +++++++++++++-
 5 files changed, 164 insertions(+), 29 deletions(-)

base-commit: 93790c374b9d77f3db15786d7d432872d92751cf

Signature · 1 line
2.17.1
#1 lore raw

PATCH v4 1/5 ionic: Fix check in ionic_get_link_ext_stats

From: Brett Creeley <[email protected]>

The current check will fail if SR-IOV is not initialized for the physical function; this is because is_physfn is 0 if sriov_init() isn't run or fails. Change the check that prevents getting the link down count to use is_virtfn instead so that VFs don't get this functionality, which was the original intent.

Fixes 132b4ebfa090 ("ionic: add support for ethtool extended stat link_down_count")
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +9 -2
index 78a802eb159f..6069fa460913 100644
@@ -116,8 +116,15 @@ static void ionic_get_link_ext_stats(struct net_device *netdev,
 {
 	struct ionic_lif *lif = netdev_priv(netdev);
 
-	if (lif->ionic->pdev->is_physfn)
-		stats->link_down_events = lif->link_down_count;
+	if (lif->ionic->pdev->is_virtfn)
+		return;
+
+	if (!lif->ionic->idev.port_info) {
+		netdev_err_once(netdev, "port_info not initialized\n");
+		return;
+	}
+
+	stats->link_down_events = lif->link_down_count;
 }
 
 static int ionic_get_link_ksettings(struct net_device *netdev,
Signature · 1 line
2.17.1
#2 lore raw

PATCH v4 2/5 ionic: Update ionic_if.h with new extra port stats

In reply to Eric Joyner

Add a new structure to report additional statistics from the firmware to struct ionic_port_info. This new struct currently only contains FEC related statistics, but any new port-level statistics collected by the firmware would go into it.

The new structure is located in the same area as the unused ionic_port_pb_stats structure, so this patch also removes that since it was never used in this driver.

Finally, to indicate firmware support for the new structure, introduce a new device capability that the driver can use to see if the attached device supports reporting these extra stats.

---
 .../net/ethernet/pensando/ionic/ionic_if.h    | 39 +++++++------------
 1 file changed, 13 insertions(+), 26 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_if.h +13 -26
index 23d6e2b4791e..e84df6115a77 100644
@@ -7,6 +7,7 @@
 #define IONIC_DEV_INFO_SIGNATURE		0x44455649      /* 'DEVI' */
 #define IONIC_DEV_INFO_VERSION			1
 #define IONIC_IFNAMSIZ				16
+#define IONIC_STAT_INVALID			((__le64)-1)
 
 /*
  * enum ionic_cmd_opcode - Device commands
@@ -273,10 +274,12 @@ union ionic_drv_identity {
  * enum ionic_dev_capability - Device capabilities
  * @IONIC_DEV_CAP_VF_CTRL:     Device supports VF ctrl operations
  * @IONIC_DEV_CAP_DISC_CMB:    Device supports CMB discovery operations
+ * @IONIC_DEV_CAP_EXTRA_STATS: Device supports extra stats schema
  */
 enum ionic_dev_capability {
 	IONIC_DEV_CAP_VF_CTRL        = BIT(0),
 	IONIC_DEV_CAP_DISC_CMB       = BIT(1),
+	IONIC_DEV_CAP_EXTRA_STATS    = BIT(4),
 };
 
 /**
@@ -2855,6 +2858,14 @@ struct ionic_mgmt_port_stats {
 	__le64 frames_tx_pause;
 };
 
+struct ionic_port_extra_stats {
+	__le64 rsfec_correctable_blocks;
+	__le64 rsfec_uncorrectable_blocks;
+	__le64 fec_corrected_bits_total;
+	__le64 rx_bits_phy;
+	__le64 fec_codeword_error_bin[16];
+};
+
 enum ionic_pb_buffer_drop_stats {
 	IONIC_BUFFER_INTRINSIC_DROP = 0,
 	IONIC_BUFFER_DISCARDED,
@@ -2883,28 +2894,6 @@ enum ionic_oflow_drop_stats {
 	IONIC_OFLOW_DROP_MAX,
 };
 
-/* struct ionic_port_pb_stats - packet buffers system stats
- * uses ionic_pb_buffer_drop_stats for drop_counts[]
- */
-struct ionic_port_pb_stats {
-	__le64 sop_count_in;
-	__le64 eop_count_in;
-	__le64 sop_count_out;
-	__le64 eop_count_out;
-	__le64 drop_counts[IONIC_BUFFER_DROP_MAX];
-	__le64 input_queue_buffer_occupancy[IONIC_QOS_TC_MAX];
-	__le64 input_queue_port_monitor[IONIC_QOS_TC_MAX];
-	__le64 output_queue_port_monitor[IONIC_QOS_TC_MAX];
-	__le64 oflow_drop_counts[IONIC_OFLOW_DROP_MAX];
-	__le64 input_queue_good_pkts_in[IONIC_QOS_TC_MAX];
-	__le64 input_queue_good_pkts_out[IONIC_QOS_TC_MAX];
-	__le64 input_queue_err_pkts_in[IONIC_QOS_TC_MAX];
-	__le64 input_queue_fifo_depth[IONIC_QOS_TC_MAX];
-	__le64 input_queue_max_fifo_depth[IONIC_QOS_TC_MAX];
-	__le64 input_queue_peak_occupancy[IONIC_QOS_TC_MAX];
-	__le64 output_queue_buffer_occupancy[IONIC_QOS_TC_MAX];
-};
-
 /**
  * struct ionic_port_identity - port identity structure
  * @version:        identity structure version
@@ -2950,7 +2939,7 @@ union ionic_port_identity {
  * @sprom_page2:     Extended Transceiver sprom, page 2
  * @sprom_page17:    Extended Transceiver sprom, page 17
  * @rsvd:            reserved byte(s)
- * @pb_stats:        uplink pb drop stats
+ * @extra_stats:     Extra port statistics data
  */
 struct ionic_port_info {
 	union ionic_port_config config;
@@ -2968,9 +2957,7 @@ struct ionic_port_info {
 		};
 	};
 	u8     rsvd[376];
-
-	/* pb_stats must start at 2k offset */
-	struct ionic_port_pb_stats  pb_stats;
+	struct ionic_port_extra_stats extra_stats;
 };
 
 /*
Signature · 1 line
2.17.1
#3 lore raw

PATCH v4 3/5 ionic: Report "rx_bits_phy" stat to ethtool

In reply to Eric Joyner

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.

---
 .../net/ethernet/pensando/ionic/ionic_dev.h   |  1 +
 .../net/ethernet/pensando/ionic/ionic_main.c  |  6 ++
 .../net/ethernet/pensando/ionic/ionic_stats.c | 58 ++++++++++++++++++-
 3 files changed, 64 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.h +1 -0
index 35566f97eaea..5f677bcbaf02 100644
@@ -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;
 };
drivers/net/ethernet/pensando/ionic/ionic_main.c +6 -0
index 3c5200e2fdb7..306d9d160e17 100644
@@ -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);
drivers/net/ethernet/pensando/ionic/ionic_stats.c +57 -1

100 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

PATCH v4 4/5 ionic: Report "link_down_events_phy" in ethtool statistics

In reply to Eric Joyner

There already exists a link_down_events statistic that is calculated by the firmware and is reported via the .get_link_ext_stats() ethtool handler, but there is a value that is calculated by the firmware, too, that could be useful.

Instead of replacing the driver calculated value, add the firmware value to the ethtool general stats output. Unlike the driver value, the firmware value doesn't get reset unless the actual card itself gets reset and is limited 16 bits, making it harder to use to track link down events e.g. during the current boot and any excessive number of link flaps. That said, it could still be useful to track link down events while the driver is not loaded, such as checking if the link partner is flapping while the local system is booting or otherwise does not have the ionic driver loaded.

---
 drivers/net/ethernet/pensando/ionic/ionic_stats.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_stats.c +7 -1
index e81190cc9d2f..d0ebba7aec22 100644
@@ -237,7 +237,7 @@ 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;
+	u32 count = 1;
 
 	if (!(lif->ionic->ident.dev.capabilities &
 	      cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
@@ -296,6 +296,8 @@ static void ionic_extra_port_stats_get_strings(struct ionic_lif *lif, u8 **buf)
 {
 	struct ionic_port_extra_stats *pes_cache;
 
+	ethtool_puts(buf, "link_down_events_phy");
+
 	if (!(lif->ionic->ident.dev.capabilities &
 	    cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
 		return;
@@ -360,8 +362,12 @@ 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_info *port_info = lif->ionic->idev.port_info;
 	struct ionic_port_extra_stats *pes_cache;
 
+	**buf = le16_to_cpu(port_info->status.link_down_count);
+	(*buf)++;
+
 	if (!(lif->ionic->ident.dev.capabilities &
 	      cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
 		return;
Signature · 1 line
2.17.1
#5 lore raw

PATCH v4 5/5 ionic: Add .get_fec_stats ethtool handler

In reply to Eric Joyner

Reports FEC statistics totals and an 802.3ck FEC histogram. Per-lane counts currently aren't supported.

The reporting of these statistics is gated by DEV_CAP_EXTRA_STATS and checks for IONIC_STAT_INVALID, since only the newest devices support reporting all of these stats. Older devices can only report some of the statistics or not at all, and so the output will properly exclude those unsupported statistics.

Assisted-by Claude:claude-4.6-sonnet
---
 .../ethernet/pensando/ionic/ionic_ethtool.c   | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +72 -0
index 6069fa460913..41bb27669907 100644
@@ -425,6 +425,77 @@ static int ionic_get_fecparam(struct net_device *netdev,
 	return 0;
 }
 
+static const struct ethtool_fec_hist_range ionic_fec_ranges[] = {
+	{ 0, 0},
+	{ 1, 1},
+	{ 2, 2},
+	{ 3, 3},
+	{ 4, 4},
+	{ 5, 5},
+	{ 6, 6},
+	{ 7, 7},
+	{ 8, 8},
+	{ 9, 9},
+	{ 10, 10},
+	{ 11, 11},
+	{ 12, 12},
+	{ 13, 13},
+	{ 14, 14},
+	{ 15, 15},
+	{ 0, 0},
+};
+
+#define IONIC_FEC_STAT(dst, src)			\
+	do {						\
+		if ((src) != IONIC_STAT_INVALID)	\
+			(dst) = le64_to_cpu((src));	\
+	} while (0)
+
+static void
+ionic_fill_fec_hist(const struct ionic_port_extra_stats *port_extra_stats,
+		    struct ethtool_fec_hist *hist)
+{
+	__le64 fec_cw_err_bin;
+	int i;
+
+	if (port_extra_stats->fec_codeword_error_bin[0] == IONIC_STAT_INVALID)
+		return;
+
+	hist->ranges = ionic_fec_ranges;
+	/* All bins in ranges must be set */
+	for (i = 0; i < ARRAY_SIZE(ionic_fec_ranges) - 1; i++) {
+		fec_cw_err_bin = port_extra_stats->fec_codeword_error_bin[i];
+
+		if (fec_cw_err_bin != IONIC_STAT_INVALID)
+			hist->values[i].sum = le64_to_cpu(fec_cw_err_bin);
+		else
+			hist->values[i].sum = 0;
+	}
+}
+
+static void ionic_get_fec_stats(struct net_device *netdev,
+				struct ethtool_fec_stats *fec_stats,
+				struct ethtool_fec_hist *hist)
+{
+	struct ionic_port_extra_stats *port_extra_stats;
+	struct ionic_lif *lif = netdev_priv(netdev);
+
+	if (!(lif->ionic->ident.dev.capabilities &
+	      cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
+		return;
+
+	port_extra_stats = &lif->ionic->idev.port_info->extra_stats;
+
+	IONIC_FEC_STAT(fec_stats->corrected_blocks.total,
+		       port_extra_stats->rsfec_correctable_blocks);
+	IONIC_FEC_STAT(fec_stats->uncorrectable_blocks.total,
+		       port_extra_stats->rsfec_uncorrectable_blocks);
+	IONIC_FEC_STAT(fec_stats->corrected_bits.total,
+		       port_extra_stats->fec_corrected_bits_total);
+
+	ionic_fill_fec_hist(port_extra_stats, hist);
+}
+
 static int ionic_set_fecparam(struct net_device *netdev,
 			      struct ethtool_fecparam *fec)
 {
@@ -1161,6 +1232,7 @@ static const struct ethtool_ops ionic_ethtool_ops = {
 	.get_module_eeprom_by_page	= ionic_get_module_eeprom_by_page,
 	.get_pauseparam		= ionic_get_pauseparam,
 	.set_pauseparam		= ionic_set_pauseparam,
+	.get_fec_stats		= ionic_get_fec_stats,
 	.get_fecparam		= ionic_get_fecparam,
 	.set_fecparam		= ionic_set_fecparam,
 	.get_ts_info		= ionic_get_ts_info,
Signature · 1 line
2.17.1
reviewer
#6 lore raw
In reply to Eric Joyner
Quoted 6 lines · Eric Joyner

The primary aim of this patchset is to support the reporting of new port statistics (and one old one) that firmware sends to the driver; these include general FEC codeword stats and the FEC histogram. A scheme for these extra stats is introduced in order to prevent devices that don't support these new statistics from unconditionally setting them or reporting them in ethtool.

...

Hi Eric,

There is AI-generated review of this patch-set available on both
https://sashiko.dev and https://netdev-ai.bots.linux.dev/sashiko/
I would appreciate it if you could look over that with a view to addressing any issues that directly affect this patch.

#7 lore raw
Quoted 11 lines · Simon Horman

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 6 lines · Eric Joyner

The primary aim of this patchset is to support the reporting of new port statistics (and one old one) that firmware sends to the driver; these include general FEC codeword stats and the FEC histogram. A scheme for these extra stats is introduced in order to prevent devices that don't support these new statistics from unconditionally setting them or reporting them in ethtool.

Quoted 8 lines

...

Hi Eric,

There is AI-generated review of this patch-set available on both
https://sashiko.dev and https://netdev-ai.bots.linux.dev/sashiko/
I would appreciate it if you could look over that with a view to addressing any issues that directly affect this patch.

Thanks for letting me know; I've submitted a v5 where I hope I've addressed all of the comments.

- Eric

maintainer
#8 lore raw
In reply to Eric Joyner
Quoted 4 lines · On Tue, 9 Jun 2026 23:18:25 -0700 Eric Joyner wrote:

- The link_down_count from firmware mentioned in v2 was moved back to an entry in the general ethtool statistics; the existing driver-calculated value for the ethtool ext link is more appropriate due to the firmware value being a small size and not resetting between driver loads.

There's a uAPI stat defined for something but you don't use it because you can't be bothered to handle overflow and reset? What am I missing :/

#9 lore raw
Quoted 11 lines · Jakub Kicinski

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 4 lines · On Tue, 9 Jun 2026 23:18:25 -0700 Eric Joyner wrote:

- The link_down_count from firmware mentioned in v2 was moved back to an entry in the general ethtool statistics; the existing driver-calculated value for the ethtool ext link is more appropriate due to the firmware value being a small size and not resetting between driver loads.

There's a uAPI stat defined for something but you don't use it because you can't be bothered to handle overflow and reset? What am I missing :/

I could add the overflow and reset handling (I was working on it for a v5), but to me, it didn't seem like it was worth the effort to modify the stat from firmware instead of continuing to use the existing driver-calculated stat. It wasn't really a "can I do this" question but more "is it worth doing this?"

To start, it didn't seem like there was a specific standard that the API expected; it looked like "copy straight from the adapter if you can, or just calculate something if you can't". It's hard to tell what the actual expectations for the interface outside of the struct comment since there aren't many drivers using it. The Mellanox and Broadcom driver stat handlers just read the link down count straight from hardware (though I don't know if those stats get reset on driver load or reboot and we're the outlier in the way our firmware behaves). The Intel drivers are similar to what we do now in the ionic driver, and they just count the link down events that the driver detects, but I know that they don't expose a link down count from the hardware. What we do now seems good enough for that purpose? It's bigger than 16 bits and gets reset on driver load, so why add more code to handle something that this seems to do well enough?

But, I also still want the raw firmware stat because the firmware has a different lifetime than the driver, and so it will count link down events while the driver isn't loaded or in a state to receive link events. But since maybe that's only useful for debugging, it belongs in debugfs instead? I just thought drivers could more or less put what they want in ethtool -S output, so that seemed like an okay place to put it.

- Eric

maintainer
#10 lore raw
Quoted 19 lines · On Sat, 13 Jun 2026 18:34:23 -0700 Eric Joyner wrote:

I could add the overflow and reset handling (I was working on it for a v5), but to me, it didn't seem like it was worth the effort to modify the stat from firmware instead of continuing to use the existing driver-calculated stat. It wasn't really a "can I do this" question but more "is it worth doing this?"

To start, it didn't seem like there was a specific standard that the API expected; it looked like "copy straight from the adapter if you can, or just calculate something if you can't". It's hard to tell what the actual expectations for the interface outside of the struct comment since there aren't many drivers using it. The Mellanox and Broadcom driver stat handlers just read the link down count straight from hardware (though I don't know if those stats get reset on driver load or reboot and we're the outlier in the way our firmware behaves). The Intel drivers are similar to what we do now in the ionic driver, and they just count the link down events that the driver detects, but I know that they don't expose a link down count from the hardware. What we do now seems good enough for that purpose? It's bigger than 16 bits and gets reset on driver load, so why add more code to handle something that this seems to do well enough?

Quoted 6 lines

But, I also still want the raw firmware stat because the firmware has a different lifetime than the driver, and so it will count link down events while the driver isn't loaded or in a state to receive link events. But since maybe that's only useful for debugging, it belongs in debugfs instead? I just thought drivers could more or less put what they want in ethtool -S output, so that seemed like an okay place to put it.

I sent a patch to delete this incorrect stat ASAP. Feel free to add it to ethtool -S under a name that clearly indicates that it's _not_ the phy down count in the next cycle.