[PATCH net-next v3 2/2] net: xilinx: axienet: Add statistics support

Jakub Kicinski kuba at kernel.org
Fri Aug 16 19:42:03 PDT 2024


On Thu, 15 Aug 2024 10:40:31 -0400 Sean Anderson wrote:
> +	u64 hw_stat_base[STAT_COUNT];
> +	u64 hw_last_counter[STAT_COUNT];

I think hw_last_counter has to be u32..

> +	seqcount_mutex_t hw_stats_seqcount;
> +	struct mutex stats_lock;
> +	struct delayed_work stats_work;
> +	bool reset_in_progress;
> +
>  	struct work_struct dma_err_task;
>  
>  	int tx_irq;
> diff --git a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> index b2d7c396e2e3..9353a4f0ab1b 100644
> --- a/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> +++ b/drivers/net/ethernet/xilinx/xilinx_axienet_main.c
> @@ -519,11 +519,55 @@ static void axienet_setoptions(struct net_device *ndev, u32 options)
>  	lp->options |= options;
>  }
>  
> +static u64 axienet_stat(struct axienet_local *lp, enum temac_stat stat)
> +{
> +	u32 counter;
> +
> +	if (lp->reset_in_progress)
> +		return lp->hw_stat_base[stat];
> +
> +	counter = axienet_ior(lp, XAE_STATS_OFFSET + stat * 8);
> +	return lp->hw_stat_base[stat] + (counter - lp->hw_last_counter[stat]);

.. or you need to cast the (counter - lp->...) result to u32.
Otherwise counter's type is getting bumped to 64 and you're just doing
64b math here.

> +}
> +
> +static void axienet_stats_update(struct axienet_local *lp, bool reset)
> +{
> +	enum temac_stat stat;
> +
> +	write_seqcount_begin(&lp->hw_stats_seqcount);
> +	lp->reset_in_progress = reset;
> +	for (stat = 0; stat < STAT_COUNT; stat++) {
> +		u32 counter = axienet_ior(lp, XAE_STATS_OFFSET + stat * 8);
> +
> +		lp->hw_stat_base[stat] += counter - lp->hw_last_counter[stat];
> +		lp->hw_last_counter[stat] = counter;
> +	}
> +	write_seqcount_end(&lp->hw_stats_seqcount);



More information about the linux-arm-kernel mailing list