Received: by 2002:a05:6a10:5594:0:0:0:0 with SMTP id ee20csp37780pxb; Mon, 25 Apr 2022 05:22:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyl0w4T2CrRru/xtmtQEah6f/XIkZtmt0Ic8mklRknYd7cKIetQPFQTvhCi3KxsB7sZv+TI X-Received: by 2002:a63:2acd:0:b0:3aa:86eb:3dc with SMTP id q196-20020a632acd000000b003aa86eb03dcmr14767967pgq.441.1650889351166; Mon, 25 Apr 2022 05:22:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650889351; cv=none; d=google.com; s=arc-20160816; b=j5zrvNaIeWsUtfg8gnV/7LzjXexq1ekP5DoQogduncPKCR21oK/rKqhekObgr2UHEg kEs7Vr02OfGlp6Uf8O/0dyjd07Q/pK38vCy0uRN9CTrUJZLOMBNxGlMSUCNUuK+yNVCV rlMHNYnw3KjKyLdBCm3uzTKCEH7H6kzqOGCEM3LpVT4660OTl8VMIQEdGc4xi9mbpbD7 YN3zDldoO3t70EMSCfUEwjCNxD9ZXAqHzqlZpBWRBXxj54mF4+NyCpq+I1q60OeuUMl3 JN2ESdqvl9hup3l4GZtuw5CVSeEv3iEWWcuV5C1u8VA10LJ2dq2DcX34SZ3kffYF+BMP T/hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=JO5DN4ttzY0OwoUIKsY6rztJAHi+fNur3UJjfomKDII=; b=AzI70c9mE+TQYx16YmRASCWY6awfUbniUQOX9TinoEm+Q8fwralG2uHFSrRjXS1iw4 GNTPm7Jqv7XXahxMIVI1L3ZyvB2QnZ8TJcPDlvbBs+839AOcJYztSfxas9IhJddf0f0X 8x6Rt0NONbbFwuU3GgZFiGYbPut/uQHz8q4ECMKmO84ZCMdzvtko0HfqA9ZHVhtIFSig PaZG05MTyFaUBR8pqlO/JdEzYDrE1Snhe/Ef2HjASWI05Zzb5wIqBuVP5TlUvz46K+qv uCmP5mryjs9iGK8Oow/Nd6HdG8rECMsuF0szrY+l02x8LNsVJgnAgoW+dcEZF+kSh3LY 1D8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v69-20020a638948000000b003ab234cfbb2si4331645pgd.697.2022.04.25.05.22.14; Mon, 25 Apr 2022 05:22:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237553AbiDYLUg (ORCPT + 99 others); Mon, 25 Apr 2022 07:20:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236749AbiDYLUd (ORCPT ); Mon, 25 Apr 2022 07:20:33 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 846B6C7EB2 for ; Mon, 25 Apr 2022 04:17:26 -0700 (PDT) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1niwib-0002gW-0j; Mon, 25 Apr 2022 13:17:25 +0200 Received: from ore by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1niwiY-0001Al-Jm; Mon, 25 Apr 2022 13:17:22 +0200 Date: Mon, 25 Apr 2022 13:17:22 +0200 From: Oleksij Rempel To: Arun Ramadoss Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Paolo Abeni , Jakub Kicinski , "David S. Miller" , Vladimir Oltean , Florian Fainelli , Vivien Didelot , Andrew Lunn , UNGLinuxDriver@microchip.com, Woojung Huh , Oleksij Rempel Subject: Re: [RFC Patch net-next] net: dsa: ksz9477: move get_stats64 to ksz_common.c Message-ID: <20220425111722.GA24511@pengutronix.de> References: <20220425105500.20899-1-arun.ramadoss@microchip.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20220425105500.20899-1-arun.ramadoss@microchip.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 13:16:18 up 25 days, 23:45, 79 users, load average: 0.12, 0.14, 0.16 User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 25, 2022 at 04:25:00PM +0530, Arun Ramadoss wrote: > The mib counters for the ksz9477 is same for the ksz9477 switch and > LAN937x switch. Hence moving it to ksz_common.c file in order to have it > generic function. The DSA hook get_stats64 now can call ksz_get_stats64. > > Signed-off-by: Arun Ramadoss Looks ok for me. Reviewed-by: Oleksij Rempel Thank you! > --- > drivers/net/dsa/microchip/ksz9477.c | 98 +------------------------- > drivers/net/dsa/microchip/ksz_common.c | 96 +++++++++++++++++++++++++ > drivers/net/dsa/microchip/ksz_common.h | 3 + > 3 files changed, 101 insertions(+), 96 deletions(-) > > diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c > index 4f617fee9a4e..48c90e4cda30 100644 > --- a/drivers/net/dsa/microchip/ksz9477.c > +++ b/drivers/net/dsa/microchip/ksz9477.c > @@ -65,100 +65,6 @@ static const struct { > { 0x83, "tx_discards" }, > }; > > -struct ksz9477_stats_raw { > - u64 rx_hi; > - u64 rx_undersize; > - u64 rx_fragments; > - u64 rx_oversize; > - u64 rx_jabbers; > - u64 rx_symbol_err; > - u64 rx_crc_err; > - u64 rx_align_err; > - u64 rx_mac_ctrl; > - u64 rx_pause; > - u64 rx_bcast; > - u64 rx_mcast; > - u64 rx_ucast; > - u64 rx_64_or_less; > - u64 rx_65_127; > - u64 rx_128_255; > - u64 rx_256_511; > - u64 rx_512_1023; > - u64 rx_1024_1522; > - u64 rx_1523_2000; > - u64 rx_2001; > - u64 tx_hi; > - u64 tx_late_col; > - u64 tx_pause; > - u64 tx_bcast; > - u64 tx_mcast; > - u64 tx_ucast; > - u64 tx_deferred; > - u64 tx_total_col; > - u64 tx_exc_col; > - u64 tx_single_col; > - u64 tx_mult_col; > - u64 rx_total; > - u64 tx_total; > - u64 rx_discards; > - u64 tx_discards; > -}; > - > -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; > - raw = (struct ksz9477_stats_raw *)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); > -} > - > -static void ksz9477_get_stats64(struct dsa_switch *ds, int port, > - struct rtnl_link_stats64 *s) > -{ > - struct ksz_device *dev = ds->priv; > - struct ksz_port_mib *mib; > - > - mib = &dev->ports[port].mib; > - > - spin_lock(&mib->stats64_lock); > - memcpy(s, &mib->stats64, sizeof(*s)); > - spin_unlock(&mib->stats64_lock); > -} > - > static void ksz_cfg(struct ksz_device *dev, u32 addr, u8 bits, bool set) > { > regmap_update_bits(dev->regmap[0], addr, bits, set ? bits : 0); > @@ -1462,7 +1368,7 @@ static const struct dsa_switch_ops ksz9477_switch_ops = { > .port_mdb_del = ksz9477_port_mdb_del, > .port_mirror_add = ksz9477_port_mirror_add, > .port_mirror_del = ksz9477_port_mirror_del, > - .get_stats64 = ksz9477_get_stats64, > + .get_stats64 = ksz_get_stats64, > .port_change_mtu = ksz9477_change_mtu, > .port_max_mtu = ksz9477_max_mtu, > }; > @@ -1653,7 +1559,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { > .port_setup = ksz9477_port_setup, > .r_mib_cnt = ksz9477_r_mib_cnt, > .r_mib_pkt = ksz9477_r_mib_pkt, > - .r_mib_stat64 = ksz9477_r_mib_stats64, > + .r_mib_stat64 = ksz_r_mib_stats64, > .freeze_mib = ksz9477_freeze_mib, > .port_init_cnt = ksz9477_port_init_cnt, > .shutdown = ksz9477_reset_switch, > diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c > index 9b9f570ebb0b..10f127b09e58 100644 > --- a/drivers/net/dsa/microchip/ksz_common.c > +++ b/drivers/net/dsa/microchip/ksz_common.c > @@ -20,6 +20,102 @@ > > #include "ksz_common.h" > > +struct ksz_stats_raw { > + u64 rx_hi; > + u64 rx_undersize; > + u64 rx_fragments; > + u64 rx_oversize; > + u64 rx_jabbers; > + u64 rx_symbol_err; > + u64 rx_crc_err; > + u64 rx_align_err; > + u64 rx_mac_ctrl; > + u64 rx_pause; > + u64 rx_bcast; > + u64 rx_mcast; > + u64 rx_ucast; > + u64 rx_64_or_less; > + u64 rx_65_127; > + u64 rx_128_255; > + u64 rx_256_511; > + u64 rx_512_1023; > + u64 rx_1024_1522; > + u64 rx_1523_2000; > + u64 rx_2001; > + u64 tx_hi; > + u64 tx_late_col; > + u64 tx_pause; > + u64 tx_bcast; > + u64 tx_mcast; > + u64 tx_ucast; > + u64 tx_deferred; > + u64 tx_total_col; > + u64 tx_exc_col; > + u64 tx_single_col; > + u64 tx_mult_col; > + u64 rx_total; > + u64 tx_total; > + u64 rx_discards; > + u64 tx_discards; > +}; > + > +void ksz_r_mib_stats64(struct ksz_device *dev, int port) > +{ > + struct rtnl_link_stats64 *stats; > + struct ksz_stats_raw *raw; > + struct ksz_port_mib *mib; > + > + mib = &dev->ports[port].mib; > + stats = &mib->stats64; > + raw = (struct ksz_stats_raw *)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); > +} > +EXPORT_SYMBOL_GPL(ksz_r_mib_stats64); > + > +void ksz_get_stats64(struct dsa_switch *ds, int port, > + struct rtnl_link_stats64 *s) > +{ > + struct ksz_device *dev = ds->priv; > + struct ksz_port_mib *mib; > + > + mib = &dev->ports[port].mib; > + > + spin_lock(&mib->stats64_lock); > + memcpy(s, &mib->stats64, sizeof(*s)); > + spin_unlock(&mib->stats64_lock); > +} > +EXPORT_SYMBOL_GPL(ksz_get_stats64); > + > void ksz_update_port_member(struct ksz_device *dev, int port) > { > struct ksz_port *p = &dev->ports[port]; > diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h > index 4d978832c448..28cda79b090f 100644 > --- a/drivers/net/dsa/microchip/ksz_common.h > +++ b/drivers/net/dsa/microchip/ksz_common.h > @@ -151,6 +151,9 @@ int ksz9477_switch_register(struct ksz_device *dev); > > void ksz_update_port_member(struct ksz_device *dev, int port); > void ksz_init_mib_timer(struct ksz_device *dev); > +void ksz_r_mib_stats64(struct ksz_device *dev, int port); > +void ksz_get_stats64(struct dsa_switch *ds, int port, > + struct rtnl_link_stats64 *s); > > /* Common DSA access functions */ > > -- > 2.33.0 > > -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |