Re: [RFC net-next v3 5/6] net: phy: nxp-c45-tja11xx: add MACsec statistics

From: Radu Pirea (OSS)
Date: Mon Sep 11 2023 - 18:06:44 EST




On 11.09.2023 15:00, Sabrina Dubroca wrote:
2023-09-06, 19:01:33 +0300, Radu Pirea (NXP OSS) wrote:
+
+ nxp_c45_macsec_read(phydev, MACSEC_OPUS, &reg);
+ dev_stats->OutPktsUntagged = reg;

Can you read directly into OutPktsUntagged? It would make the code a
little bit more readable.

It's a bit unfortunate that all those stats read turn into 2 (or 4 for
the 64b counters) reads. If the HW's value can be incremented while
we're reading it we'll see an inconsistent value :(


The 32b reads are consistent. The inconsistency may appear when the lower half of a 64b register overflows.

+
+ nxp_c45_macsec_read(phydev, MACSEC_OOE1HS, &reg);
+ stats->OutOctetsEncrypted = (u64)reg << 32;
+ nxp_c45_macsec_read(phydev, MACSEC_OOE2HS, &reg);
+ stats->OutOctetsEncrypted |= reg;

Since you have a few 64b HW counters, I'd suggest a helper:

stats->OutOctetsEncrypted = nxp_c45_macsec_read64(phydev, MACSEC_OOE1HS, MACSEC_OOE2HS);


Or (more consistent with the 32b reads):

nxp_c45_macsec_read64(phydev, MACSEC_OOE1HS, MACSEC_OOE2HS, &stats->OutOctetsEncrypted);



I will add two helper:
- nxp_c45_macsec_read32_64 - read 32bit counter into u64
- nxp_c45_macsec_read64 - read 64bit counter into u64

--
Radu P.