Re: [RFC net-next v3 5/6] net: phy: nxp-c45-tja11xx: add MACsec statistics
flat view
From: Sabrina Dubroca <sd@queasysnail.net>
Date: 2023-09-11 22:11:29
Also in:
lkml
2023-09-06, 19:01:33 +0300, Radu Pirea (NXP OSS) wrote:
quoted hunk ↗ jump to hunk
+static int nxp_c45_mdo_get_dev_stats(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct macsec_dev_stats *dev_stats; + struct nxp_c45_secy *phy_secy; + u32 reg = 0; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + dev_stats = ctx->stats.dev_stats; + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_macsec_read(phydev, MACSEC_OPUS, ®); + 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 :(
quoted hunk ↗ jump to hunk
+ nxp_c45_macsec_read(phydev, MACSEC_OPTLS, ®); + dev_stats->OutPktsTooLong = reg; + nxp_c45_macsec_read(phydev, MACSEC_INPBTS, ®); + dev_stats->InPktsBadTag = reg; + + nxp_c45_macsec_read(phydev, MACSEC_INPWTS, ®); + if (phy_secy->secy->validate_frames == MACSEC_VALIDATE_STRICT) + dev_stats->InPktsNoTag += reg; + else + dev_stats->InPktsUntagged += reg; + + nxp_c45_macsec_read(phydev, MACSEC_IPSNFS, ®); + if (phy_secy->secy->validate_frames == MACSEC_VALIDATE_STRICT) + dev_stats->InPktsNoSCI += reg; + else + dev_stats->InPktsUnknownSCI += reg; + + /* Always 0. */ + dev_stats->InPktsOverrun = 0; + + return 0; +} + +static int nxp_c45_mdo_get_tx_sc_stats(struct macsec_context *ctx) +{ + struct phy_device *phydev = ctx->phydev; + struct nxp_c45_phy *priv = phydev->priv; + struct macsec_tx_sa_stats tx_sa_stats; + struct macsec_tx_sc_stats *stats; + struct nxp_c45_secy *phy_secy; + struct nxp_c45_sa *pos, *tmp; + u32 reg = 0; + + phy_secy = nxp_c45_find_secy(&priv->macsec->secy_list, ctx->secy->sci); + if (IS_ERR(phy_secy)) + return PTR_ERR(phy_secy); + + stats = ctx->stats.tx_sc_stats; + nxp_c45_select_secy(phydev, phy_secy->secy_id); + + nxp_c45_macsec_read(phydev, MACSEC_OOE1HS, ®); + stats->OutOctetsEncrypted = (u64)reg << 32; + nxp_c45_macsec_read(phydev, MACSEC_OOE2HS, ®); + 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); -- Sabrina