Skip to contentSkip to conversation

ionic: FEC reporting fixes and .get_fec_stats handler

PATCH Superseded Eric Joyner 2 participants 12 messages Nov 16 – Nov 19

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover ionic: FEC reporting fixes and .get_fec_stats handler

Add a .get_fec_stats ethtool handler, and fix the FEC reporting it depends on.

Patch 1 writes the IONIC_STAT_INVALID markers in extra_stats one counter at a time, so a reader that tests a single counter cannot see a torn value.

Patch 2 adds FEC off to the supported and advertised link modes. Firmware does not report which FEC modes a port supports, so the supported list holds every mode an ionic device can use, and firmware rejects a request for a mode the port cannot run.

Patches 3-5 fix ionic_get_fecparam(). fec->fec reported the constant set of supported modes instead of the configured mode, and fec->active_fec reported the requested mode instead of the operational one. Patches 2, 3 and 5 have Fixes: tags, but the later patches build on the lines they change, so they are sent to net-next with them rather than to net. The bugs only affect what ethtool reports.

Patch 6 adds the handler. It reports statistics only while the active FEC mode is RS.

The netdev AI review of v2, which Simon forwarded, asked whether the per-bin local really guarantees a single read of each counter. It does not, so v3 reads every counter with READ_ONCE() and drops the struct copy. The port_info lifetime problem that the AI review raised on v1 and v2 is fixed in net-next by commit d90d1a768b3b ("ionic: fix port_info use-after-free on firmware recovery"). The netdev AI review of v3, which Jakub forwarded, found that FEC off was not listed as a supported link mode, which the new patch 2 fixes, and that patch 4 made old firmware report forced-FEC links as FEC off, which v4 also fixes.

Claude was used while developing this series: to investigate the v2 and v3 review questions, and to help write the code changes and commit messages. The authors reviewed every change. The series was tested on Pollara and Vulcano NICs.

---
Changes in v4:
- Add patch 2, which reports FEC off as a supported link mode (netdev
AI review of v3).
- Patch 5: with autoneg off, report the configured FEC mode as active,
so firmware that predates status.fec_type no longer reports forced-FEC
links as FEC off, and add a Fixes: tag (netdev AI review of v3).
- Patch 6: gate the statistics on the same active FEC mode as patch 5.
- Patch 6: explain why an RS check is enough for the histogram (netdev
AI review of v3).
- Rebase onto current net-next.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Read each counter with READ_ONCE() and drop the struct copy of
extra_stats (netdev AI review of v2).
- Report statistics based on status.fec_type, the operational FEC mode,
instead of config.fec_type, matching the active FEC mode that patch 4 reports.
- Add patches 1-4, which fix the FEC reporting the handler depends on.
Patches 1-4 are by Nikhil, who is also a Co-developed-by on patch 5.
- Drop Vadim's Reviewed-by from v1, since the code has changed.
- Rebase onto current net-next.
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Latch each histogram bin into a local before testing it against IONIC_STAT_INVALID, so the sentinel check and the store cannot be folded into two separate reads of the firmware-updated DMA buffer.
- Explain in the commit message why the RS FEC check gates every reported counter rather than just the histogram: they all come from the RS decoder, including fec_corrected_bits_total despite its name.
- Rebased onto current net-next.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Eric Joyner (2):
ionic: report FEC off as a supported link mode
ionic: Add .get_fec_stats ethtool handler

Nikhil P. Rao (4):
ionic: write the extra_stats invalid markers one counter at a time
ionic: report the configured FEC mode in ethtool_fecparam.fec
ionic: map the FEC type through a helper in ionic_get_fecparam()
ionic: report the operational FEC mode from ethtool --show-fec

 .../net/ethernet/pensando/ionic/ionic_ethtool.c    | 137 +++++++++++++++++++--
 drivers/net/ethernet/pensando/ionic/ionic_main.c   |   8 +-
 drivers/net/ethernet/pensando/ionic/ionic_stats.h  |   2 +
 3 files changed, 132 insertions(+), 15 deletions(-)

---
base-commit: 573af801552999954caa8347e4490b04cf4763f0
change-id: 20260814-ionic-get-fec-stats-990736964908

Best regards,

Signature · 1 line
Eric Joyner <[email protected]>
#1 lore raw

PATCH v4 1/6 ionic: write the extra_stats invalid markers one counter at a time

From: "Nikhil P. Rao" <[email protected]>

ionic_port_init() marks every counter in the device-written extra_stats block invalid before asking firmware to refresh it, so that a statistic this driver knows about but the firmware does not is reported as absent rather than as zero. It does that with a memset() of the whole block.

The .get_fec_stats handler added later in this series reads those counters one at a time and tests each against IONIC_STAT_INVALID to decide whether to report it. memset() gives no guarantee about the width of its stores, so such a reader can observe a counter that is neither its old value nor the marker.

The block is entirely __le64, each member naturally aligned, so walk it as an array and write the markers one counter at a time instead. A counter read on its own is then either a complete value or the marker.

---
 drivers/net/ethernet/pensando/ionic/ionic_main.c  | 8 ++++++--
 drivers/net/ethernet/pensando/ionic/ionic_stats.h | 2 ++
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_main.c +6 -2
index 9955ab77d86d..b8d0ce597176 100644
@@ -12,6 +12,7 @@
 #include "ionic.h"
 #include "ionic_bus.h"
 #include "ionic_lif.h"
+#include "ionic_stats.h"
 #include "ionic_debugfs.h"
 
 MODULE_DESCRIPTION(IONIC_DRV_DESCRIPTION);
@@ -727,7 +728,9 @@ int ionic_port_init(struct ionic *ionic)
 	struct ionic_identity *ident = &ionic->ident;
 	struct ionic_dev *idev = &ionic->idev;
 	bool allocated = false;
+	__le64 *stat;
 	size_t sz;
+	size_t i;
 	int err;
 
 	if (!idev->port_info) {
@@ -745,8 +748,9 @@ int ionic_port_init(struct ionic *ionic)
 	/* 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));
+	stat = (__le64 *)&idev->port_info->extra_stats;
+	for (i = 0; i < sizeof(idev->port_info->extra_stats) / sizeof(*stat); i++)
+		WRITE_ONCE(stat[i], IONIC_STAT_INVALID);
 
 	WRITE_ONCE(idev->link_down_count_init, false);
 
drivers/net/ethernet/pensando/ionic/ionic_stats.h +2 -0
index 7ed935868e84..8a0edcc86fb8 100644
@@ -4,6 +4,8 @@
 #ifndef _IONIC_STATS_H_
 #define _IONIC_STATS_H_
 
+#include <linux/ethtool.h>
+
 #define IONIC_STAT_INVALID	(cpu_to_le64(~0ULL))
 
 #define IONIC_STAT_TO_OFFSET(type, stat_name) (offsetof(type, stat_name))
Signature · 1 line
2.53.0
#2 lore raw

PATCH v4 2/6 ionic: report FEC off as a supported link mode

In reply to Eric Joyner

ionic_get_link_ksettings() lists BaseR and RS as supported FEC modes but never lists FEC off, although ionic_set_fecparam() accepts it. Add FEC_NONE to the supported modes, and to the advertised modes when the port is configured with FEC off.

Firmware does not report which FEC modes a port supports, so the list holds every mode an ionic device can use, and firmware rejects a request for a mode the port cannot run. BaseR and RS are already listed on every port this way. Off follows the same rule: AINIC firmware rejects it, while DSC firmware accepts it.

Fixes 4d03e00a2140 ("ionic: Add initial ethtool support")
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +8 -1
index 119ac720c078..84378bef9fb8 100644
@@ -298,9 +298,16 @@ static int ionic_get_link_ksettings(struct net_device *netdev,
 
 	linkmode_copy(ks->link_modes.advertising, ks->link_modes.supported);
 
+	/* Firmware does not report which FEC modes a port supports, so list
+	 * every mode an ionic device can use; firmware rejects a request for
+	 * a mode the port cannot run.
+	 */
+	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);
 	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
 	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);
-	if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_FC)
+	if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_NONE)
+		ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
+	else if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_FC)
 		ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_BASER);
 	else if (idev->port_info->config.fec_type == IONIC_PORT_FEC_TYPE_RS)
 		ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH net-next v4 2/6] ionic: report FEC off as a supported link mode

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] ionic_get_link_ksettings() (drivers/net/ethernet/pensando/ionic/ionic_ethtool.c) now sets…

--

ionic: report FEC off as a supported link mode

This patch adds FEC_NONE to the supported link modes that ionic_get_link_ksettings() reports. It also adds FEC_NONE to the advertised modes when the port is configured with FEC off. According to the commit message, firmware does not report per-port FEC capabilities, so every mode any ionic device can use is listed, and firmware rejects the ones a given port cannot run.

drivers/net/ethernet/pensando/ionic/ionic_ethtool.c static int ionic_get_link_ksettings(struct net_device *netdev, · line 305

Quoted 13 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +5 -0
index 119ac720c0787..84378bef9fb8b 100644
@@ -298,9 +298,16 @@ static int ionic_get_link_ksettings(struct net_device *netdev,
 
 	linkmode_copy(ks->link_modes.advertising, ks->link_modes.supported);
 
+	/* Firmware does not report which FEC modes a port supports, so list
+	 * every mode an ionic device can use; firmware rejects a request for
+	 * a mode the port cannot run.
+	 */
+	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_NONE);

[Severity: Medium]
Is the claim in this comment accurate? The firmware ABI in ionic_if.h seems to define a per-port list of supported FEC types:

drivers/net/ethernet/pensando/ionic/ionic_if.h:
* @fec_type: supported fec types
...

union ionic_port_identity {
	struct {
		...
		u8     fec_type[4];
		u8     pause_type[2];
		u8     loopback_mode[2];
		__le32 speeds[16];
		...

ionic_port_identify() in ionic_main.c already copies this structure into ionic->ident.port with memcpy_fromio(). However, nothing in the driver reads ident.port.fec_type[].

The commit message says AINIC firmware rejects FEC off. With this change, ethtool on an AINIC port will show "None" as a supported FEC mode. A request for FEC off then reaches firmware through ionic_set_fecparam():

	if (fec_type != lif->ionic->idev.port_info->config.fec_type) {
		mutex_lock(&lif->ionic->dev_cmd_lock);
		ionic_dev_cmd_port_fec(&lif->ionic->idev, fec_type);
		ret = ionic_dev_cmd_wait(lif->ionic, DEVCMD_TIMEOUT);

and the firmware error comes back to userspace.

If firmware fills identity.fec_type[], could the supported FEC set be built from it instead of extending the hardcoded list?

If firmware does not fill it, should the comment say that the field exists but is not populated? As written, the comment contradicts the documented ABI.

There is also another way to tell the parts apart. The driver already reads dev_info.asic_type in ionic_init_devinfo(), and ionic_doorbell_wa() uses it for per-ASIC behaviour. Could asic_type be used to leave FEC_NONE out on parts whose firmware rejects FEC off?

The later patches in this series do not appear to change this. At the end of the series, FEC_NONE is still added to supported unconditionally, and ident.port.fec_type[] is still never read.

Quoted 2 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +0 -0
 	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_BASER);
 	ethtool_link_ksettings_add_link_mode(ks, supported, FEC_RS);

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-ionic-get-fec-stats-v4-0-d25cae9f1e87%40amd.com
#4 lore raw

Re: [PATCH net-next v4 2/6] ionic: report FEC off as a supported link mode

Quoted 2 lines · On Tue, 17 Nov 2026 23:10:26 +0000 [email protected] wrote:

Is the claim in this comment accurate? The firmware ABI in ionic_if.h seems to define a per-port list of supported FEC types:

[...]

Quoted 2 lines

If firmware fills identity.fec_type[], could the supported FEC set be built from it instead of extending the hardcoded list?

Firmware does not fill it. The port identify handler zeroes the identity and sets only the port type and config, which is why the driver never reads fec_type[].

Quoted 3 lines

If firmware does not fill it, should the comment say that the field exists but is not populated? As written, the comment contradicts the documented ABI.

Fair point. v5 rewords the comment and the commit message to say that the field exists but firmware leaves it unset.

Quoted 4 lines

There is also another way to tell the parts apart. The driver already reads dev_info.asic_type in ionic_init_devinfo(), and ionic_doorbell_wa() uses it for per-ASIC behaviour. Could asic_type be used to leave FEC_NONE out on parts whose firmware rejects FEC off?

Whether FEC off is accepted is decided by firmware, and keying it on asic_type would hardcode that firmware policy in the driver. The list already includes BaseR and RS on every port, whatever its speed, and firmware rejects a mode a port cannot run, so FEC off follows the same rule.

Thanks,
Eric

pw-bot: cr

#5 lore raw

PATCH v4 3/6 ionic: report the configured FEC mode in ethtool_fecparam.fec

In reply to Eric Joyner

From: "Nikhil P. Rao" <[email protected]>

ionic_get_fecparam() fills fec->fec with the constant ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER. The uAPI defines fec as the configured FEC modes, so a port configured for RS reports all three:

Supported/Configured FEC encodings: Off RS BaseR

where it should report RS alone. Take fec->fec from config.fec_type. Supported modes belong in ETHTOOL_GLINKSETTINGS, which ionic_get_link_ksettings() already fills.

fec->active_fec still reads config.fec_type; reporting the operational mode is a separate change.

Fixes e95f922f4c2f ("ionic: implement ethtool set-fec")
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +3 -2
index 84378bef9fb8..13b5874fe5ad 100644
@@ -434,17 +434,18 @@ static int ionic_get_fecparam(struct net_device *netdev,
 	switch (lif->ionic->idev.port_info->config.fec_type) {
 	case IONIC_PORT_FEC_TYPE_NONE:
 		fec->active_fec = ETHTOOL_FEC_OFF;
+		fec->fec = ETHTOOL_FEC_OFF;
 		break;
 	case IONIC_PORT_FEC_TYPE_RS:
 		fec->active_fec = ETHTOOL_FEC_RS;
+		fec->fec = ETHTOOL_FEC_RS;
 		break;
 	case IONIC_PORT_FEC_TYPE_FC:
 		fec->active_fec = ETHTOOL_FEC_BASER;
+		fec->fec = ETHTOOL_FEC_BASER;
 		break;
 	}
 
-	fec->fec = ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER;
-
 	return 0;
 }
 
Signature · 1 line
2.53.0
#6 lore raw

PATCH v4 4/6 ionic: map the FEC type through a helper in ionic_get_fecparam()

In reply to Eric Joyner

From: "Nikhil P. Rao" <[email protected]>

ionic_get_fecparam() maps config.fec_type onto the ethtool FEC values with a switch that assigns both fec->active_fec and fec->fec in each arm. A later patch gives the two fields distinct sources, which would mean duplicating the switch.

Move the mapping into ionic_fec_type_to_ethtool() and call it once per field.

No functional change.

---
 .../net/ethernet/pensando/ionic/ionic_ethtool.c    | 34 +++++++++++++---------
 1 file changed, 20 insertions(+), 14 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +20 -14
index 13b5874fe5ad..8f0f1585116b 100644
@@ -426,25 +426,31 @@ static int ionic_set_pauseparam(struct net_device *netdev,
 	return 0;
 }
 
-static int ionic_get_fecparam(struct net_device *netdev,
-			      struct ethtool_fecparam *fec)
+static u32 ionic_fec_type_to_ethtool(u8 fec_type)
 {
-	struct ionic_lif *lif = netdev_priv(netdev);
-
-	switch (lif->ionic->idev.port_info->config.fec_type) {
+	switch (fec_type) {
 	case IONIC_PORT_FEC_TYPE_NONE:
-		fec->active_fec = ETHTOOL_FEC_OFF;
-		fec->fec = ETHTOOL_FEC_OFF;
-		break;
+		return ETHTOOL_FEC_OFF;
 	case IONIC_PORT_FEC_TYPE_RS:
-		fec->active_fec = ETHTOOL_FEC_RS;
-		fec->fec = ETHTOOL_FEC_RS;
-		break;
+		return ETHTOOL_FEC_RS;
 	case IONIC_PORT_FEC_TYPE_FC:
-		fec->active_fec = ETHTOOL_FEC_BASER;
-		fec->fec = ETHTOOL_FEC_BASER;
-		break;
+		return ETHTOOL_FEC_BASER;
+	default:
+		return 0;
 	}
+}
+
+static int ionic_get_fecparam(struct net_device *netdev,
+			      struct ethtool_fecparam *fec)
+{
+	struct ionic_port_info *port_info;
+	struct ionic_lif *lif;
+
+	lif = netdev_priv(netdev);
+	port_info = lif->ionic->idev.port_info;
+
+	fec->active_fec = ionic_fec_type_to_ethtool(port_info->config.fec_type);
+	fec->fec = ionic_fec_type_to_ethtool(port_info->config.fec_type);
 
 	return 0;
 }
Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH net-next v4 4/6] ionic: map the FEC type through a helper in ionic_get_fecparam()

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] In drivers/net/ethernet/pensando/ionic/ionic_ethtool.c, the refactor changes ionic_get_fecparam() so that it reads the device-…

--

ionic: map the FEC type through a helper in ionic_get_fecparam()

This patch moves the mapping from config.fec_type to the ethtool FEC values out of ionic_get_fecparam() and into a new helper, ionic_fec_type_to_ethtool(). The helper is then called once for fec->active_fec and once for fec->fec. The commit message says there is no functional change.

Quoted 4 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +0 -0
index 13b5874fe5ad4..8f0f1585116bc 100644

[ ... ]

drivers/net/ethernet/pensando/ionic/ionic_ethtool.c static int ionic_set_pauseparam(struct net_device *netdev, · line 453

Quoted 11 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +11 -0
+static int ionic_get_fecparam(struct net_device *netdev,
+			      struct ethtool_fecparam *fec)
+{
+	struct ionic_port_info *port_info;
+	struct ionic_lif *lif;
+
+	lif = netdev_priv(netdev);
+	port_info = lif->ionic->idev.port_info;
+
+	fec->active_fec = ionic_fec_type_to_ethtool(port_info->config.fec_type);
+	fec->fec = ionic_fec_type_to_ethtool(port_info->config.fec_type);

[Severity: Low]
Could active_fec and fec end up built from two different values of port_info->config.fec_type here?

The old code loaded config.fec_type once, as the switch expression, and set both fields from that one value. The new code does two separate plain loads, one per ionic_fec_type_to_ethtool() call. There is no local snapshot, no READ_ONCE() and no lock.

port_info is coherent DMA memory shared with the device:

ionic_main.c:ionic_port_init() {
    ...
	idev->port_info = dma_alloc_coherent(ionic->dev,
				     idev->port_info_sz,
				     &idev->port_info_pa,
				     GFP_KERNEL);
    ...
}

Its address is passed to firmware in ionic_dev_cmd_port_init():

	.port_init.info_pa = cpu_to_le64(idev->port_info_pa),
Quoted 1 line

From that point, firmware writes config.fec_type. RTNL does not

serialize those writes.

If firmware updates the field between the two loads, ethtool --show-fec could report a configured/active pair that never existed together. The compiler cannot merge the two loads either: with -fno-strict-aliasing, the u32 store to fec->active_fec may alias the u8 source.

Given this, is "No functional change" in the commit message quite accurate?

The later patch in this series, "ionic: report the operational FEC mode from ethtool --show-fec", rewrites these lines but keeps the double read. When autoneg is off, ionic_active_fec_type() returns READ_ONCE(port_info->config.fec_type), and ionic_get_fecparam() then reads READ_ONCE(port_info->config.fec_type) again for fec->fec.

Would it be simpler to read config.fec_type once into a local u8 and use that for both fields?

Quoted 3 lines

return 0;
}

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-ionic-get-fec-stats-v4-0-d25cae9f1e87%40amd.com
#8 lore raw

PATCH v4 5/6 ionic: report the operational FEC mode from ethtool --show-fec

In reply to Eric Joyner

From: "Nikhil P. Rao" <[email protected]>

ionic_get_fecparam() fills fec->active_fec from config.fec_type, the mode the host requested, which on an autoneg link is whatever was last programmed while the link negotiates something else. On an autoneg link, read it from status.fec_type, where firmware reports the operational mode.

status.fec_type was carved out of the reserved area by commit c4e7a75a096c ("ionic: updates to ionic FW api description"), and firmware older than that leaves the byte zero, which reads as FEC off. With autoneg disabled the port runs the configured mode, so keep reporting config.fec_type there; only autoneg links on such old firmware report FEC off.

Fixes e95f922f4c2f ("ionic: implement ethtool set-fec")
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +16 -2
index 8f0f1585116b..ac728b8aa780 100644
@@ -440,6 +440,18 @@ static u32 ionic_fec_type_to_ethtool(u8 fec_type)
 	}
 }
 
+/* Firmware that predates status.fec_type leaves it zero, which reads as
+ * FEC off.  With autoneg disabled the port runs the configured mode, so
+ * only trust status.fec_type on an autoneg link.
+ */
+static u8 ionic_active_fec_type(const struct ionic_port_info *port_info)
+{
+	if (READ_ONCE(port_info->config.an_enable))
+		return READ_ONCE(port_info->status.fec_type);
+
+	return READ_ONCE(port_info->config.fec_type);
+}
+
 static int ionic_get_fecparam(struct net_device *netdev,
 			      struct ethtool_fecparam *fec)
 {
@@ -449,8 +461,10 @@ static int ionic_get_fecparam(struct net_device *netdev,
 	lif = netdev_priv(netdev);
 	port_info = lif->ionic->idev.port_info;
 
-	fec->active_fec = ionic_fec_type_to_ethtool(port_info->config.fec_type);
-	fec->fec = ionic_fec_type_to_ethtool(port_info->config.fec_type);
+	fec->active_fec =
+		ionic_fec_type_to_ethtool(ionic_active_fec_type(port_info));
+	fec->fec =
+		ionic_fec_type_to_ethtool(READ_ONCE(port_info->config.fec_type));
 
 	return 0;
 }
Signature · 1 line
2.53.0
#9 lore raw

Re: [PATCH net-next v4 5/6] ionic: report the operational FEC mode from ethtool --show-fec

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The commit says old firmware "leaves the byte zero", so an autoneg link on that firmware reports FEC off.

--

ionic: report the operational FEC mode from ethtool --show-fec

On autoneg links, ionic_get_fecparam() now fills active_fec from status.fec_type, the operational mode reported by firmware. Without autoneg it keeps using config.fec_type. The commit message says firmware that predates status.fec_type leaves that byte zero, so on such firmware an autoneg link reports FEC off.

Quoted 6 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +0 -0
index 8f0f1585116bc..ac728b8aa780e 100644
@@ -440,6 +440,18 @@ static u32 ionic_fec_type_to_ethtool(u8 fec_type)
 	}

drivers/net/ethernet/pensando/ionic/ionic_ethtool.c static u32 ionic_fec_type_to_ethtool(u8 fec_type) · line 450

Quoted 10 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +8 -0
 }
 
+/* Firmware that predates status.fec_type leaves it zero, which reads as
+ * FEC off.  With autoneg disabled the port runs the configured mode, so
+ * only trust status.fec_type on an autoneg link.
+ */
+static u8 ionic_active_fec_type(const struct ionic_port_info *port_info)
+{
+	if (READ_ONCE(port_info->config.an_enable))
+		return READ_ONCE(port_info->status.fec_type);

[Severity: Medium]
Is status.fec_type actually guaranteed to be zero on older firmware once the device has been through a firmware reset?

The commit message says:

firmware older than that leaves the byte zero, which reads as FEC off.

The driver only zeroes that byte when it first allocates the port_info DMA buffer. ionic_lif_handle_fw_up() calls ionic_port_init() again. That function allocates only when idev->port_info is NULL, so after a reset it reuses the old buffer:

drivers/net/ethernet/pensando/ionic/ionic_main.c:ionic_port_init() {
    ...
	if (!idev->port_info) {
		idev->port_info_sz = ALIGN(sizeof(*idev->port_info), PAGE_SIZE);
		idev->port_info = dma_alloc_coherent(ionic->dev,
    ...
	stat = (__le64 *)&idev->port_info->extra_stats;
	for (i = 0; i < sizeof(idev->port_info->extra_stats) / sizeof(*stat); i++)
		WRITE_ONCE(stat[i], IONIC_STAT_INVALID);
    ...
}

Before PORT_INIT, only extra_stats is reset, to cover fields the firmware does not know about. Nothing clears status.fec_type. The buffer is freed only by ionic_port_reset(), which runs from probe and remove.

Say a newer firmware has written IONIC_PORT_FEC_TYPE_RS into status.fec_type. The device is then reset into firmware older than c4e7a75a096c, for example by downgrading with devlink flash and FW_CONTROL ACTIVATE, or by falling back to another image. In that case, can ionic_get_fecparam() keep reporting the stale RS value as active_fec on autoneg links until the driver is reloaded? That would hold even if the link negotiated a different mode or no FEC.

This depends on the old firmware not writing the former reserved byte. That hasn't been confirmed, but the extra_stats invalidation suggests firmware writes only the fields it knows about.

Would it make sense to clear status.fec_type, or the whole status block, in ionic_port_init() before PORT_INIT, the same way extra_stats is handled?

The later commit "ionic: Add .get_fec_stats ethtool handler" also uses ionic_active_fec_type(). That path is gated on IONIC_DEV_CAP_EXTRA_STATS, so old firmware does not reach it, and the rest of the series does not change this.

Quoted 4 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +4 -0
+
+	return READ_ONCE(port_info->config.fec_type);
+}
+

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116-ionic-get-fec-stats-v4-0-d25cae9f1e87%40amd.com
#10 lore raw

Re: [PATCH net-next v4 5/6] ionic: report the operational FEC mode from ethtool --show-fec

Quoted 2 lines · On Tue, 17 Nov 2026 23:10:29 +0000 [email protected] wrote:

Is status.fec_type actually guaranteed to be zero on older firmware once the device has been through a firmware reset?

[...]

Quoted 3 lines

Would it make sense to clear status.fec_type, or the whole status block, in ionic_port_init() before PORT_INIT, the same way extra_stats is handled?

No, a stale value can't be reported. During a firmware reset the netdev stays detached until ionic_restart_lif() has run ionic_lif_init(), so ethtool can't reach ionic_get_fecparam() before then. LIF_INIT makes firmware write the whole port status block to the host, the former reserved byte included, and firmware that predates status.fec_type already did that. By the time the netdev is attached again, the byte holds what the running firmware wrote.

Thanks,
Eric

#11 lore raw

PATCH v4 6/6 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. Every counter reported here comes from the RS decoder, including fec_corrected_bits_total despite its name, and the only histogram format firmware produces is the 16-bin one from RS(544,514), so nothing is reported unless RS is the active FEC mode. The only devices whose firmware reports the histogram do not support RS(528,514), so RS on those devices is always RS(544,514).

These are physical port counters, so virtual functions are skipped the same way ionic_get_link_ext_stats() skips them, rather than reporting the port's counters as if they belonged to the VF.

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.

The firmware writes these counters by DMA while they are being read. Use READ_ONCE() to ensure that the IONIC_STAT_INVALID test and the store see the same value. Counters are still read one at a time, so the set reported can span more than one firmware update.

---
 .../net/ethernet/pensando/ionic/ionic_ethtool.c    | 83 ++++++++++++++++++++++
 1 file changed, 83 insertions(+)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +83 -0
index ac728b8aa780..b4835cc52cc7 100644
@@ -469,6 +469,88 @@ static int ionic_get_fecparam(struct net_device *netdev,
 	return 0;
 }
 
+#define IONIC_FEC_STAT(dst, src)			\
+	do {						\
+		__le64 __val = READ_ONCE(src);		\
+							\
+		if (__val != IONIC_STAT_INVALID)	\
+			(dst) = le64_to_cpu(__val);	\
+	} while (0)
+
+static const struct ethtool_fec_hist_range ionic_fec_hist_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},
+};
+
+static void
+ionic_fill_fec_hist(const struct ionic_port_extra_stats *port_extra_stats,
+		    struct ethtool_fec_hist *hist)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(port_extra_stats->fec_codeword_error_bin); i++) {
+		__le64 val = READ_ONCE(port_extra_stats->fec_codeword_error_bin[i]);
+
+		if (val == IONIC_STAT_INVALID)
+			return;
+
+		hist->values[i].sum = le64_to_cpu(val);
+	}
+
+	hist->ranges = ionic_fec_hist_ranges;
+}
+
+static void ionic_get_fec_stats(struct net_device *netdev,
+				struct ethtool_fec_stats *fec_stats,
+				struct ethtool_fec_hist *hist)
+{
+	struct ionic_lif *lif = netdev_priv(netdev);
+	struct ionic_port_info *port_info;
+
+	if (lif->ionic->pdev->is_virtfn)
+		return;
+
+	if (test_bit(IONIC_LIF_F_FW_RESET, lif->state))
+		return;
+
+	if (!(lif->ionic->ident.dev.capabilities &
+	      cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
+		return;
+
+	port_info = lif->ionic->idev.port_info;
+	if (!port_info) {
+		netdev_err_once(netdev, "port_info not initialized\n");
+		return;
+	}
+
+	if (ionic_active_fec_type(port_info) != IONIC_PORT_FEC_TYPE_RS)
+		return;
+
+	IONIC_FEC_STAT(fec_stats->corrected_blocks.total,
+		       port_info->extra_stats.rsfec_correctable_blocks);
+	IONIC_FEC_STAT(fec_stats->uncorrectable_blocks.total,
+		       port_info->extra_stats.rsfec_uncorrectable_blocks);
+	IONIC_FEC_STAT(fec_stats->corrected_bits.total,
+		       port_info->extra_stats.fec_corrected_bits_total);
+
+	ionic_fill_fec_hist(&port_info->extra_stats, hist);
+}
+
 static int ionic_set_fecparam(struct net_device *netdev,
 			      struct ethtool_fecparam *fec)
 {
@@ -1203,6 +1285,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.53.0