From: Vadim Fedorenko <vadim.fedorenko@linux.dev>
To: Brett Creeley <brett.creeley@amd.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@kernel.org>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Shannon Nelson <sln@onemain.com>
Cc: netdev@vger.kernel.org, Simon Horman <horms@kernel.org>,
"Nikhil P. Rao" <nikhil.rao@amd.com>,
Eric Joyner <eric.joyner@amd.com>,
Breno Leitao <leitao@debian.org>,
Arun Kumar Prakash <ArunKumar.Prakash@amd.com>
Subject: Re: [PATCH net-next v6 1/6] ionic: access the extra_stats counters one at a time
Date: Sat, 28 Nov 2026 13:21:58 +0000 [thread overview]
Message-ID: <0a15473f-6aaf-45b2-9ae2-3660f82ad9a2@linux.dev> (raw)
In-Reply-To: <20261125-ionic-get-fec-stats-v6-1-1ab49c729c00@amd.com>
On 25/11/2026 23:22, Brett Creeley wrote:
> 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))
>
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
next prev parent reply other threads:[~2026-11-28 13:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
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-28 13:21 ` Vadim Fedorenko [this message]
2026-11-25 23:22 ` [PATCH net-next v6 2/6] ionic: report FEC off as a supported link mode Brett Creeley
2026-11-28 13:22 ` Vadim Fedorenko
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-28 13:23 ` Vadim Fedorenko
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-28 13:26 ` Vadim Fedorenko
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-28 13:27 ` Vadim Fedorenko
2026-11-25 23:22 ` [PATCH net-next v6 6/6] ionic: Add .get_fec_stats ethtool handler Brett Creeley
2026-11-28 10:06 ` Vadim Fedorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0a15473f-6aaf-45b2-9ae2-3660f82ad9a2@linux.dev \
--to=vadim.fedorenko@linux.dev \
--cc=ArunKumar.Prakash@amd.com \
--cc=andrew+netdev@lunn.ch \
--cc=brett.creeley@amd.com \
--cc=davem@davemloft.net \
--cc=edumazet@kernel.org \
--cc=eric.joyner@amd.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=leitao@debian.org \
--cc=netdev@vger.kernel.org \
--cc=nikhil.rao@amd.com \
--cc=pabeni@redhat.com \
--cc=sln@onemain.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox