mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jens Emil Schulz Ostergaard <jensemil.schulzostergaard@microchip.com>
To: <netdev-bot+sashiko@kernel.org>
Cc: <UNGLinuxDriver@microchip.com>, <andrew@lunn.ch>,
	<olteanv@gmail.com>, <davem@davemloft.net>, <kuba@kernel.org>,
	<pabeni@redhat.com>, <horms@kernel.org>, <robh@kernel.org>,
	<krzk+dt@kernel.org>, <conor+dt@kernel.org>,
	<woojung.huh@microchip.com>, <linux@armlinux.org.uk>,
	<Steen.Hegelund@microchip.com>, <daniel.machon@microchip.com>,
	<geert+renesas@glider.be>, <magnus.damm@gmail.com>,
	<edumazet@kernel.org>, <richardcochran@gmail.com>,
	<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <linux-renesas-soc@vger.kernel.org>
Subject: Re: [PATCH net-next v15 9/9] net: dsa: lan9645x: add port statistics
Date: Thu, 22 Oct 2026 14:17:39 +0200	[thread overview]
Message-ID: <a1f7a38b614d0b5b802c422dab8ca304fd6b9a81.camel@microchip.com> (raw)
In-Reply-To: <179240453307.3135.2065386937763476332@kernel.org>

On Mon, 2026-10-19 at 10:08 +0000, netdev-bot+sashiko@kernel.org wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 0 · Medium: 1 · Low: 0
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
> 
> - [Medium] lan9645x_stats_get_stats64()
>   (drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c) counts error…
> 
> --
> 
> net: dsa: lan9645x: add port statistics
> 
> This adds port statistics support to the lan9645x DSA driver. The 32 bit
> hardware counters are polled into a 64 bit software cache, and the pMAC
> counters are summed into the aggregate source. The cache is exposed through
> ethtool -S, the standard ethtool groups and ndo_get_stats64.
> 
> > diff --git a/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c
> > new file mode 100644
> > index 0000000000000..a21afb4d98532
> > --- /dev/null
> > +++ b/drivers/net/dsa/microchip/lan9645x/lan9645x_stats.c
> > @@ -0,0 +1,854 @@
> 
> [ ... ]
> 
> > +void lan9645x_stats_get_stats64(struct lan9645x *lan9645x, int port,
> > +                             struct rtnl_link_stats64 *stats)
> > +{
> 
> [ ... ]
> 
> > +     stats->rx_packets = c[SCNT_RX_SHORT] +
> > +                         c[SCNT_RX_JABBER] +
> > +                         c[SCNT_RX_SZ_64] +
> > +                         c[SCNT_RX_SZ_65_127] +
> > +                         c[SCNT_RX_SZ_128_255] +
> > +                         c[SCNT_RX_SZ_256_511] +
> > +                         c[SCNT_RX_SZ_512_1023] +
> > +                         c[SCNT_RX_SZ_1024_1526] +
> > +                         c[SCNT_RX_SZ_JUMBO] +
> > +                         c[SCNT_RX_LONG] +
> > +                         c[SCNT_RX_PMAC_SHORT] +
> > +                         c[SCNT_RX_PMAC_FRAG] +
> > +                         c[SCNT_RX_PMAC_JABBER] +
> > +                         c[SCNT_RX_PMAC_SZ_64] +
> > +                         c[SCNT_RX_PMAC_SZ_65_127] +
> > +                         c[SCNT_RX_PMAC_SZ_128_255] +
> > +                         c[SCNT_RX_PMAC_SZ_256_511] +
> > +                         c[SCNT_RX_PMAC_SZ_512_1023] +
> > +                         c[SCNT_RX_PMAC_SZ_1024_1526] +
> > +                         c[SCNT_RX_PMAC_SZ_JUMBO] +
> > +                         c[SCNT_RX_PMAC_LONG];
> > +
> > +     stats->multicast = c[SCNT_RX_MC] + c[SCNT_RX_PMAC_MC];
> > +
> > +     stats->rx_errors = c[SCNT_RX_SHORT] +
> > +                        c[SCNT_RX_JABBER] +
> > +                        c[SCNT_RX_CRC] +
> > +                        c[SCNT_RX_LONG] +
> > +                        c[SCNT_RX_PMAC_SHORT] +
> > +                        c[SCNT_RX_PMAC_JABBER] +
> > +                        c[SCNT_RX_PMAC_CRC] +
> > +                        c[SCNT_RX_PMAC_LONG];
> 
> [Severity: Medium]
> Should short, jabber and oversize frames be counted in rx_packets in
> lan9645x_stats_get_stats64()?
> 
> rx_packets and rx_errors both add SCNT_RX_SHORT, SCNT_RX_JABBER and
> SCNT_RX_LONG, plus their pMAC versions. JABBER and LONG are also added to
> rx_length_errors. So every malformed frame received on a user port counts
> once as a good packet and once as an error.
> 
> The rtnl_link_stats64 kernel-doc in include/uapi/linux/if_link.h says:
> 
>   @rx_packets: Number of good packets received by the interface.
> 
> The v5 changelog also says CRC and symbol error frames "are already counted
> in SZ_* buckets". Since those buckets feed rx_packets, frames with a bad CRC
> would be counted as good packets as well.
> 
> This also gives a different answer from lan9645x_stats_get_eth_mac_stats(),
> which counts good received frames as UC + MC + BC only:
> 
>         m->FramesReceivedOK = c[SCNT_RX_UC] +
>                               c[SCNT_RX_MC] +
>                               c[SCNT_RX_BC] +
>                               ...
> 
> As a result, rx_packets is larger than FramesReceivedOK by the number of
> errored frames. ocelot_port_get_stats64() uses a similar rx_packets formula,
> but that does not match the uAPI description either.
> 
> Could rx_packets be derived the same way as FramesReceivedOK?
> 
> A separate point: c[SCNT_RX_PMAC_FRAG] is added to rx_packets but not to
> rx_errors. The comment in lan9645x_stats_get_rmon_stats() says:
> 
>         /* ... Only SCNT_RX_PMAC_FRAG counts runts with an invalid
>          * CRC, so fragments is left unset rather than reporting the pMAC alone.
>          */
> 
> Going by that comment, a pMAC runt with a bad CRC would be counted as a
> good packet and left out of the error total. Is that intended?
> 
> v12 removed the eMAC SCNT_RX_FRAG from rx_packets, but the pMAC version is
> still there. Since the pMAC gets no traffic without MAC merge, this has
> little effect today.
> 

Dismissed, intended.

This follows mscc/ocelot. The hardware has no good frames only octet
counter. rx_oct counts good and bad frames, so rx_bytes cannot follow
the uapi description. We make sure rx_packets matches by counting the
same frames as rx_bytes. Bad frames are also reported in rx_errors.

FramesReceivedOK is the 802.3 good frame count and is meant to differ.

SCNT_RX_PMAC_FRAG is the size class below 64 bytes for pMAC runts with
an invalid CRC, so it belongs in rx_packets next to the size buckets.
Its frames are already in rx_errors through SCNT_RX_PMAC_CRC, which
counts CRC errors at any frame size, in the same way a frame of 64
bytes or more with a bad CRC sits in a size bucket and in SCNT_RX_CRC.
Adding it to rx_errors would count those runts twice.

The eMAC SCNT_RX_FRAG is not the same counter. It only counts runts
with an invalid CRC on half-duplex links, and on full-duplex links
counts frames received after the port is paused, which is why it is
not used.


> --
> Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261015-dsa_lan9645x_switch_driver_base-v15-0-562f316f78b9%40microchip.com


      reply	other threads:[~2026-10-22 12:17 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  8:05 [PATCH net-next v15 0/9] net: dsa: add DSA support for the LAN9645x switch chip family Jens Emil Schulz Østergaard
2026-10-15  8:05 ` [PATCH net-next v15 1/9] net: dsa: add tag driver for LAN9645X Jens Emil Schulz Østergaard
2026-10-19 10:08   ` netdev-bot+sashiko
2026-10-22 11:49     ` Jens Emil Schulz Ostergaard
2026-10-15  8:05 ` [PATCH net-next v15 2/9] dt-bindings: net: dsa: add Microchip LAN9645x switch Jens Emil Schulz Østergaard
2026-10-19 10:08   ` netdev-bot+sashiko
2026-10-22 11:52     ` Jens Emil Schulz Ostergaard
2026-10-15  8:05 ` [PATCH net-next v15 3/9] net: dsa: lan9645x: add autogenerated register macros Jens Emil Schulz Østergaard
2026-10-15  8:05 ` [PATCH net-next v15 4/9] net: dsa: lan9645x: add basic dsa driver for LAN9645X Jens Emil Schulz Østergaard
2026-10-19 10:08   ` netdev-bot+sashiko
2026-10-22 11:53     ` Jens Emil Schulz Ostergaard
2026-10-15  8:05 ` [PATCH net-next v15 5/9] net: dsa: lan9645x: add vlan support Jens Emil Schulz Østergaard
2026-10-19 10:08   ` netdev-bot+sashiko
2026-10-15  8:06 ` [PATCH net-next v15 6/9] net: dsa: lan9645x: add mac table integration Jens Emil Schulz Østergaard
2026-10-15  8:06 ` [PATCH net-next v15 7/9] net: dsa: lan9645x: add mdb management Jens Emil Schulz Østergaard
2026-10-19 10:08   ` netdev-bot+sashiko
2026-10-22 12:05     ` Jens Emil Schulz Ostergaard
2026-10-15  8:06 ` [PATCH net-next v15 8/9] net: dsa: lan9645x: add bridge support Jens Emil Schulz Østergaard
2026-10-19 10:08   ` netdev-bot+sashiko
2026-10-22 12:13     ` Jens Emil Schulz Ostergaard
2026-10-15  8:06 ` [PATCH net-next v15 9/9] net: dsa: lan9645x: add port statistics Jens Emil Schulz Østergaard
2026-10-19 10:08   ` netdev-bot+sashiko
2026-10-22 12:17     ` Jens Emil Schulz Ostergaard [this message]

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=a1f7a38b614d0b5b802c422dab8ca304fd6b9a81.camel@microchip.com \
    --to=jensemil.schulzostergaard@microchip.com \
    --cc=Steen.Hegelund@microchip.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=conor+dt@kernel.org \
    --cc=daniel.machon@microchip.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=edumazet@kernel.org \
    --cc=geert+renesas@glider.be \
    --cc=horms@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=magnus.damm@gmail.com \
    --cc=netdev-bot+sashiko@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=robh@kernel.org \
    --cc=woojung.huh@microchip.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

all inboxes | Powered by JetHome®