Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler
@ 2026-11-25 23:22 Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time Brett Creeley
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Brett Creeley @ 2026-11-25 23:22 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Shannon Nelson
  Cc: netdev, Simon Horman, Vadim Fedorenko, Nikhil P. Rao, Eric Joyner,
	Breno Leitao, Arun Kumar Prakash

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

Patch 1 makes the driver write the IONIC_STAT_INVALID markers in
extra_stats, and take the ethtool -S snapshot of that block, 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 5 made
old firmware report forced-FEC links as FEC off, which v4 also fixes.

The netdev AI review of v5 asked whether status.fec_type can keep a
stale value after a firmware reset brings up firmware that predates the
field. It cannot: firmware copies the whole port status block to the
host, reserved bytes included, at LIF init and on every link event, and
firmware that predates the field leaves those bytes zero.

Claude was used while developing this series, to investigate the
review questions and to help write the code changes and commit
messages. The series was tested on AMD Pensando NICs: ethtool --show-fec
with and without statistics, the FEC link modes, and ethtool -S, before
and after PCI resets run while those queries were looping.

---
Changes in v6:
- rebase on net-next
- patch 1:
  - take the ethtool -S snapshot of extra_stats one counter at a time
    with READ_ONCE() too, and retitle the patch (netdev AI review of v5)
- patch 2:
  - read config.fec_type once in ionic_get_link_ksettings()
  - drop the comment that repeated the commit message
  - describe the devices generically in the commit message
- patch 4:
  - read config.fec_type once in ionic_get_fecparam() (netdev AI review
    of v5)
- patch 5:
  - drop the comment that repeated the commit message
- patches 5 and 6:
  - pass the configured FEC type to ionic_active_fec_type() so that it
    is read once (netdev AI review of v5)
- Link to v5: https://patch.msgid.link/20261118-ionic-get-fec-stats-v5-0-c9c0ee63df4c@amd.com

Changes in v5:
- Patch 2: say that firmware leaves the supported FEC types in the port
  identity unset (netdev AI review of v4).
- Link to v4: https://lore.kernel.org/r/20261116-ionic-get-fec-stats-v4-0-d25cae9f1e87@amd.com

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/20261104-ionic-get-fec-stats-v3-0-b261fd53d0a7@amd.com

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/20260814-ionic-get-fec-stats-v2-1-13f0e7d2e702@amd.com

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/20260731214021.15279-1-eric.joyner@amd.com

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

Nikhil P. Rao (4):
      ionic: access the extra_stats counters one 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    | 139 ++++++++++++++++++---
 drivers/net/ethernet/pensando/ionic/ionic_main.c   |   8 +-
 drivers/net/ethernet/pensando/ionic/ionic_stats.c  |   8 +-
 drivers/net/ethernet/pensando/ionic/ionic_stats.h  |   2 +
 4 files changed, 140 insertions(+), 17 deletions(-)
---
base-commit: e20f88c4f08bc9dba09c48ddc9806015f79fb20b
change-id: 20260814-ionic-get-fec-stats-990736964908

Best regards,
--  
Brett Creeley <brett.creeley@amd.com>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time
  2026-11-25 23:22 [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler Brett Creeley
@ 2026-11-25 23:22 ` Brett Creeley
  2026-11-26 23:24   ` netdev-bot+sashiko
  2026-11-25 23:22 ` [PATCH net-next v6 2/6] ionic: report FEC off as a supported link mode Brett Creeley
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Brett Creeley @ 2026-11-25 23:22 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Shannon Nelson
  Cc: netdev, Simon Horman, Vadim Fedorenko, Nikhil P. Rao, Eric Joyner,
	Breno Leitao, Arun Kumar Prakash

From: "Nikhil P. Rao" <nikhil.rao@amd.com>

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,
and ethtool -S takes its snapshot of the block with a struct copy.

Both run without a common lock: ionic_port_init() is called from the
firmware recovery work, and an ethtool -S that got past the device
present check before the netdev was detached can still be running.
Neither memset() nor a struct copy guarantees the width of its
accesses, so the snapshot can hold a counter that is neither its old
value nor the marker, and ethtool -S then reports it.  The
.get_fec_stats handler added later in this series has the same need.

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

Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
Signed-off-by: Eric Joyner <eric.joyner@amd.com>
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_main.c  | 8 ++++++--
 drivers/net/ethernet/pensando/ionic/ionic_stats.c | 8 +++++++-
 drivers/net/ethernet/pensando/ionic/ionic_stats.h | 2 ++
 3 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_main.c b/drivers/net/ethernet/pensando/ionic/ionic_main.c
index 1ad5f529e600..16c1b1fd155c 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_main.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_main.c
@@ -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);
@@ -728,7 +729,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) {
@@ -746,8 +749,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);
 
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
index 428d5cca930f..89926e5a2f3c 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
@@ -237,7 +237,10 @@ 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;
+	const __le64 *src;
 	u32 count = 0;
+	__le64 *dst;
+	size_t i;
 
 	if (!(lif->ionic->ident.dev.capabilities &
 	      cpu_to_le64(IONIC_DEV_CAP_EXTRA_STATS)))
@@ -252,7 +255,10 @@ static u32 ionic_extra_port_stats_get_count(struct ionic_lif *lif)
 		return count;
 	}
 
-	*pes_cache = idev->port_info->extra_stats;
+	src = (const __le64 *)&idev->port_info->extra_stats;
+	dst = (__le64 *)pes_cache;
+	for (i = 0; i < sizeof(*pes_cache) / sizeof(*dst); i++)
+		dst[i] = READ_ONCE(src[i]);
 
 	if (pes_cache->rx_bits_phy != IONIC_STAT_INVALID)
 		count++;
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.h b/drivers/net/ethernet/pensando/ionic/ionic_stats.h
index 7ed935868e84..8a0edcc86fb8 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_stats.h
+++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.h
@@ -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))

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v6 2/6] ionic: report FEC off as a supported link mode
  2026-11-25 23:22 [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time Brett Creeley
@ 2026-11-25 23:22 ` Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 3/6] ionic: report the configured FEC mode in ethtool_fecparam.fec Brett Creeley
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Brett Creeley @ 2026-11-25 23:22 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Shannon Nelson
  Cc: netdev, Simon Horman, Vadim Fedorenko, Nikhil P. Rao, Eric Joyner,
	Breno Leitao, Arun Kumar Prakash

From: Eric Joyner <eric.joyner@amd.com>

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.  Read config.fec_type once for that
chain: firmware updates it by DMA, and with a read per comparison a
change between them could leave no FEC mode advertised.

Firmware does not report which FEC modes a port supports: the port
identity has a field for them, but firmware leaves it unset.  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: some
devices' firmware rejects it, others accept it.

Fixes: 4d03e00a2140 ("ionic: Add initial ethtool support")
Signed-off-by: Eric Joyner <eric.joyner@amd.com>
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index 29b9a8502b8e..16c6e4c9852e 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -149,6 +149,7 @@ static int ionic_get_link_ksettings(struct net_device *netdev,
 	struct ionic_lif *lif = netdev_priv(netdev);
 	struct ionic_dev *idev = &lif->ionic->idev;
 	int copper_seen = 0;
+	u8 fec_type;
 
 	ethtool_link_ksettings_zero_link_mode(ks, supported);
 
@@ -298,11 +299,15 @@ static int ionic_get_link_ksettings(struct net_device *netdev,
 
 	linkmode_copy(ks->link_modes.advertising, ks->link_modes.supported);
 
+	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)
+	fec_type = READ_ONCE(idev->port_info->config.fec_type);
+	if (fec_type == IONIC_PORT_FEC_TYPE_NONE)
+		ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_NONE);
+	else if (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)
+	else if (fec_type == IONIC_PORT_FEC_TYPE_RS)
 		ethtool_link_ksettings_add_link_mode(ks, advertising, FEC_RS);
 
 	ethtool_link_ksettings_add_link_mode(ks, supported, FIBRE);

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v6 3/6] ionic: report the configured FEC mode in ethtool_fecparam.fec
  2026-11-25 23:22 [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 2/6] ionic: report FEC off as a supported link mode Brett Creeley
@ 2026-11-25 23:22 ` Brett Creeley
  2026-11-26 23:24   ` netdev-bot+sashiko
  2026-11-25 23:22 ` [PATCH net-next v6 4/6] ionic: map the FEC type through a helper in ionic_get_fecparam() Brett Creeley
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 9+ messages in thread
From: Brett Creeley @ 2026-11-25 23:22 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Shannon Nelson
  Cc: netdev, Simon Horman, Vadim Fedorenko, Nikhil P. Rao, Eric Joyner,
	Breno Leitao, Arun Kumar Prakash

From: "Nikhil P. Rao" <nikhil.rao@amd.com>

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")
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
Signed-off-by: Eric Joyner <eric.joyner@amd.com>
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index 16c6e4c9852e..e7262a842eda 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -432,17 +432,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;
 }
 

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v6 4/6] ionic: map the FEC type through a helper in ionic_get_fecparam()
  2026-11-25 23:22 [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler Brett Creeley
                   ` (2 preceding siblings ...)
  2026-11-25 23:22 ` [PATCH net-next v6 3/6] ionic: report the configured FEC mode in ethtool_fecparam.fec Brett Creeley
@ 2026-11-25 23:22 ` Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 5/6] ionic: report the operational FEC mode from ethtool --show-fec Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 6/6] ionic: Add .get_fec_stats ethtool handler Brett Creeley
  5 siblings, 0 replies; 9+ messages in thread
From: Brett Creeley @ 2026-11-25 23:22 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Shannon Nelson
  Cc: netdev, Simon Horman, Vadim Fedorenko, Nikhil P. Rao, Eric Joyner,
	Breno Leitao, Arun Kumar Prakash

From: "Nikhil P. Rao" <nikhil.rao@amd.com>

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.  Read config.fec_type once, as the switch did, so the two fields
cannot be filled from different values while firmware rewrites
port_info.

No functional change.

Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
Signed-off-by: Eric Joyner <eric.joyner@amd.com>
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
---
 .../net/ethernet/pensando/ionic/ionic_ethtool.c    | 36 +++++++++++++---------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index e7262a842eda..312cd3e5e404 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -424,25 +424,33 @@ 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;
+	u8 config_fec_type;
+
+	lif = netdev_priv(netdev);
+	port_info = lif->ionic->idev.port_info;
+	config_fec_type = port_info->config.fec_type;
+
+	fec->active_fec = ionic_fec_type_to_ethtool(config_fec_type);
+	fec->fec = ionic_fec_type_to_ethtool(config_fec_type);
 
 	return 0;
 }

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v6 5/6] ionic: report the operational FEC mode from ethtool --show-fec
  2026-11-25 23:22 [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler Brett Creeley
                   ` (3 preceding siblings ...)
  2026-11-25 23:22 ` [PATCH net-next v6 4/6] ionic: map the FEC type through a helper in ionic_get_fecparam() Brett Creeley
@ 2026-11-25 23:22 ` Brett Creeley
  2026-11-25 23:22 ` [PATCH net-next v6 6/6] ionic: Add .get_fec_stats ethtool handler Brett Creeley
  5 siblings, 0 replies; 9+ messages in thread
From: Brett Creeley @ 2026-11-25 23:22 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Shannon Nelson
  Cc: netdev, Simon Horman, Vadim Fedorenko, Nikhil P. Rao, Eric Joyner,
	Breno Leitao, Arun Kumar Prakash

From: "Nikhil P. Rao" <nikhil.rao@amd.com>

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")
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
Signed-off-by: Eric Joyner <eric.joyner@amd.com>
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index 312cd3e5e404..3b6c436104d1 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -438,18 +438,29 @@ static u32 ionic_fec_type_to_ethtool(u8 fec_type)
 	}
 }
 
+static u8 ionic_active_fec_type(const struct ionic_port_info *port_info,
+				u8 config_fec_type)
+{
+	if (READ_ONCE(port_info->config.an_enable))
+		return READ_ONCE(port_info->status.fec_type);
+
+	return config_fec_type;
+}
+
 static int ionic_get_fecparam(struct net_device *netdev,
 			      struct ethtool_fecparam *fec)
 {
 	struct ionic_port_info *port_info;
 	struct ionic_lif *lif;
 	u8 config_fec_type;
+	u8 active_fec_type;
 
 	lif = netdev_priv(netdev);
 	port_info = lif->ionic->idev.port_info;
-	config_fec_type = port_info->config.fec_type;
+	config_fec_type = READ_ONCE(port_info->config.fec_type);
+	active_fec_type = ionic_active_fec_type(port_info, config_fec_type);
 
-	fec->active_fec = ionic_fec_type_to_ethtool(config_fec_type);
+	fec->active_fec = ionic_fec_type_to_ethtool(active_fec_type);
 	fec->fec = ionic_fec_type_to_ethtool(config_fec_type);
 
 	return 0;

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH net-next v6 6/6] ionic: Add .get_fec_stats ethtool handler
  2026-11-25 23:22 [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler Brett Creeley
                   ` (4 preceding siblings ...)
  2026-11-25 23:22 ` [PATCH net-next v6 5/6] ionic: report the operational FEC mode from ethtool --show-fec Brett Creeley
@ 2026-11-25 23:22 ` Brett Creeley
  5 siblings, 0 replies; 9+ messages in thread
From: Brett Creeley @ 2026-11-25 23:22 UTC (permalink / raw)
  To: Brett Creeley, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Shannon Nelson
  Cc: netdev, Simon Horman, Vadim Fedorenko, Nikhil P. Rao, Eric Joyner,
	Breno Leitao, Arun Kumar Prakash

From: Eric Joyner <eric.joyner@amd.com>

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.

Co-developed-by: Nikhil P. Rao <nikhil.rao@amd.com>
Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
Signed-off-by: Eric Joyner <eric.joyner@amd.com>
Signed-off-by: Brett Creeley <brett.creeley@amd.com>
---
 .../net/ethernet/pensando/ionic/ionic_ethtool.c    | 86 ++++++++++++++++++++++
 1 file changed, 86 insertions(+)

diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
index 3b6c436104d1..ceb029dae0fa 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
@@ -466,6 +466,91 @@ 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;
+	u8 config_fec_type;
+
+	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;
+	}
+
+	config_fec_type = READ_ONCE(port_info->config.fec_type);
+	if (ionic_active_fec_type(port_info, config_fec_type) !=
+	    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)
 {
@@ -1200,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,

-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time
  2026-11-25 23:22 ` [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time Brett Creeley
@ 2026-11-26 23:24   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26 23:24 UTC (permalink / raw)
  To: brett.creeley
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, sln, netdev, horms,
	vadim.fedorenko, nikhil.rao, eric.joyner, leitao,
	ArunKumar.Prakash

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] Commit "ionic: access the extra_stats counters one at a time"
  fixes a user-visible defect but has no Fixes: tag.

--

ionic: access the extra_stats counters one at a time

This commit stops ionic_port_init() from writing the IONIC_STAT_INVALID
markers into port_info->extra_stats with a memset() of the whole block.
It also stops ionic_extra_port_stats_get_count() from taking its snapshot
with a struct copy. Both now walk the block as an array of __le64, using
WRITE_ONCE() and READ_ONCE() on one counter at a time, so ethtool -S
cannot report a torn counter.

> Both run without a common lock: ionic_port_init() is called from the
> firmware recovery work, and an ethtool -S that got past the device
> present check before the netdev was detached can still be running.
> Neither memset() nor a struct copy guarantees the width of its
> accesses, so the snapshot can hold a counter that is neither its old
> value nor the marker, and ethtool -S then reports it.  The
> .get_fec_stats handler added later in this series has the same need.
>
> [ ... ]
>
>     Signed-off-by: Nikhil P. Rao <nikhil.rao@amd.com>
>     Signed-off-by: Eric Joyner <eric.joyner@amd.com>
>     Signed-off-by: Brett Creeley <brett.creeley@amd.com>

[Severity: Low]
The commit message describes a bug that users can see: ethtool -S can
report a torn counter. Should this patch carry a Fixes: tag?

The two constructs it replaces both come from the same commit. One is the
memset(&idev->port_info->extra_stats, 0xff, ...) in ionic_port_init(). The
other is the struct copy in ionic_extra_port_stats_get_count():

    *pes_cache = idev->port_info->extra_stats;

That commit has already been applied to the net tree:

    Fixes: cb683ff6ee07 ("ionic: Report "rx_bits_phy" stat to ethtool")

Other fixes in this series carry Fixes: tags. Examples are "ionic: report
FEC off as a supported link mode", "ionic: report the configured FEC mode
in ethtool_fecparam.fec" and "ionic: report the operational FEC mode from
ethtool --show-fec". That makes the missing tag here look unintentional.

Without the tag, stable and backport tooling will not pick this up for
kernels that contain cb683ff6ee07. If the torn read is not considered
worth backporting, could the commit message say so?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-ionic-get-fec-stats-v6-0-1ab49c729c00%40amd.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next v6 3/6] ionic: report the configured FEC mode in ethtool_fecparam.fec
  2026-11-25 23:22 ` [PATCH net-next v6 3/6] ionic: report the configured FEC mode in ethtool_fecparam.fec Brett Creeley
@ 2026-11-26 23:24   ` netdev-bot+sashiko
  0 siblings, 0 replies; 9+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26 23:24 UTC (permalink / raw)
  To: brett.creeley
  Cc: andrew+netdev, davem, edumazet, kuba, pabeni, sln, netdev, horms,
	vadim.fedorenko, nikhil.rao, eric.joyner, leitao,
	ArunKumar.Prakash

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] When port autoneg is on, ionic_get_fecparam() reports a stale
  manual setting as the port's configured FEC.

--

ionic: report the configured FEC mode in ethtool_fecparam.fec

ionic_get_fecparam() used to set fec->fec to the constant
ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER. With this patch it
sets fec->fec from port_info->config.fec_type, so only the configured FEC
mode is reported. fec->active_fec is still derived from config.fec_type.

> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> index 16c6e4c9852e9..e7262a842eda4 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_ethtool.c
> @@ -432,17 +432,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;
>  	}

[Severity: Medium]
Can this report an old manual setting as the configured FEC when
autoneg is enabled on the port?

fec->fec now comes only from config.fec_type, and config.an_enable is
never checked. With autoneg on, ETHTOOL_GFECPARAM and
ETHTOOL_MSG_FEC_GET would show one fixed mode (for example "Configured
FEC encodings: RS"). That mode is whatever was last set by hand.
ETHTOOL_FEC_AUTO is never reported.

The uAPI kernel-doc for struct ethtool_fecparam says:

 * FEC settings are configured by link autonegotiation whenever it's enabled.

ionic_set_fecparam() also rejects FEC changes while autoneg is on:

	if (lif->ionic->idev.port_info->config.an_enable) {
		netdev_err(netdev, "FEC request not allowed while autoneg is enabled\n");
		return -EINVAL;
	}

Both suggest config.fec_type is not the policy in effect under autoneg.
The later patch in this series, "ionic: report the operational FEC mode
from ethtool --show-fec", describes config.fec_type on an autoneg link
as whatever was last programmed while the link negotiates something
else.

The problem still exists at the end of the series. There, active_fec
uses status.fec_type under autoneg through ionic_active_fec_type(), but
fec still has no autoneg check:

	fec->active_fec = ionic_fec_type_to_ethtool(active_fec_type);
	fec->fec = ionic_fec_type_to_ethtool(config_fec_type);

ionic_get_link_ksettings() does put config.fec_type into the advertised
FEC link modes. If firmware uses config.fec_type as the FEC request
during autoneg, reporting it here may be intended.

If it does not, should fec->fec report ETHTOOL_FEC_AUTO when
config.an_enable is set?

>  
> -	fec->fec = ETHTOOL_FEC_OFF | ETHTOOL_FEC_RS | ETHTOOL_FEC_BASER;
> -
>  	return 0;
>  }

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261125-ionic-get-fec-stats-v6-0-1ab49c729c00%40amd.com

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-11-26 23:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 23:22 [PATCH net-next v6 0/6] ionic: FEC reporting fixes and .get_fec_stats handler Brett Creeley
2026-11-25 23:22 ` [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time Brett Creeley
2026-11-26 23:24   ` netdev-bot+sashiko
2026-11-25 23:22 ` [PATCH net-next v6 2/6] ionic: report FEC off as a supported link mode Brett Creeley
2026-11-25 23:22 ` [PATCH net-next v6 3/6] ionic: report the configured FEC mode in ethtool_fecparam.fec Brett Creeley
2026-11-26 23:24   ` netdev-bot+sashiko
2026-11-25 23:22 ` [PATCH net-next v6 4/6] ionic: map the FEC type through a helper in ionic_get_fecparam() Brett Creeley
2026-11-25 23:22 ` [PATCH net-next v6 5/6] ionic: report the operational FEC mode from ethtool --show-fec Brett Creeley
2026-11-25 23:22 ` [PATCH net-next v6 6/6] ionic: Add .get_fec_stats ethtool handler Brett Creeley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox