From: "Nikhil P. Rao" 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. Signed-off-by: Nikhil P. Rao Signed-off-by: Eric Joyner --- 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(-) diff --git a/drivers/net/ethernet/pensando/ionic/ionic_main.c b/drivers/net/ethernet/pensando/ionic/ionic_main.c index 9955ab77d86d..b8d0ce597176 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); @@ -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); 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 + #define IONIC_STAT_INVALID (cpu_to_le64(~0ULL)) #define IONIC_STAT_TO_OFFSET(type, stat_name) (offsetof(type, stat_name)) -- 2.53.0