[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20220218153535.optweu6jtzkerehe@skbuf>
Date: Fri, 18 Feb 2022 17:35:35 +0200
From: Vladimir Oltean <olteanv@...il.com>
To: Oleksij Rempel <o.rempel@...gutronix.de>
Cc: Woojung Huh <woojung.huh@...rochip.com>,
UNGLinuxDriver@...rochip.com, Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
Vivien Didelot <vivien.didelot@...il.com>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>, kernel@...gutronix.de,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH net-next v3 1/1] net: dsa: microchip: ksz9477: export HW
stats over stats64 interface
On Fri, Feb 18, 2022 at 01:11:49PM +0100, Oleksij Rempel wrote:
> +static void ksz9477_r_mib_stats64(struct ksz_device *dev, int port)
> +{
> + struct rtnl_link_stats64 *stats;
> + struct ksz9477_stats_raw raw;
> + struct ksz_port_mib *mib;
> +
> + mib = &dev->ports[port].mib;
> + stats = &mib->stats64;
> +
> + memcpy(&raw, mib->counters, sizeof(raw));
I don't think you need an on-stack copy of mib->counters. If you're
concerned about line length just make "raw" point to mib->counters.
> +
> + spin_lock(&mib->stats64_lock);
> +
> + stats->rx_packets = raw.rx_bcast + raw.rx_mcast + raw.rx_ucast;
> + stats->tx_packets = raw.tx_bcast + raw.tx_mcast + raw.tx_ucast;
> +
> + /* HW counters are counting bytes + FCS which is not acceptable
> + * for rtnl_link_stats64 interface
> + */
> + stats->rx_bytes = raw.rx_total - stats->rx_packets * ETH_FCS_LEN;
> + stats->tx_bytes = raw.tx_total - stats->tx_packets * ETH_FCS_LEN;
> +
> + stats->rx_length_errors = raw.rx_undersize + raw.rx_fragments +
> + raw.rx_oversize;
> +
> + stats->rx_crc_errors = raw.rx_crc_err;
> + stats->rx_frame_errors = raw.rx_align_err;
> + stats->rx_dropped = raw.rx_discards;
> + stats->rx_errors = stats->rx_length_errors + stats->rx_crc_errors +
> + stats->rx_frame_errors + stats->rx_dropped;
> +
> + stats->tx_window_errors = raw.tx_late_col;
> + stats->tx_fifo_errors = raw.tx_discards;
> + stats->tx_aborted_errors = raw.tx_exc_col;
> + stats->tx_errors = stats->tx_window_errors + stats->tx_fifo_errors +
> + stats->tx_aborted_errors;
> +
> + stats->multicast = raw.rx_mcast;
> + stats->collisions = raw.tx_total_col;
> +
> + spin_unlock(&mib->stats64_lock);
> +}
Powered by blists - more mailing lists