From nobody Thu Sep 11 16:05:28 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 97FDBC64ED6 for ; Fri, 17 Feb 2023 11:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229740AbjBQLC1 (ORCPT ); Fri, 17 Feb 2023 06:02:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229525AbjBQLCC (ORCPT ); Fri, 17 Feb 2023 06:02:02 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7516063BCD; Fri, 17 Feb 2023 03:02:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1676631720; x=1708167720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ds+xcdqyuM0AGf3EleSMTk8z7ILujR2TSv0lkawhf5Q=; b=nTisAfsAfnY5JDN9PKV5dWpBPs099NqS/+o0mrQZyac8jDuH2X279Dew uhOokDJGkYlSVxr9CI4DPSXKozBackFXlgnQOwAm3ts6fqVMScQyqi18P 05Hf+DFOxNxsjK/t2mf+bNh0XntlxgKQb+uobEJ/5j+p6KRFFejvvzYbW dLyRXBOsoV/PST5VH+dmwzIfVLT4BrILs8SvZNYBP/cti9LIeUWL+Lgyk 1t9B5lTNi5Zho6XrOqWZRx4cQRDVeolv/Ako62qwq47KxNSLPTSAAS3f7 tSx1WOixoe499R8/ieoQgPDcz4Wy7Ror+WEN+Ik5XNlRxiJ0ZeFSKMnzN A==; X-IronPort-AV: E=Sophos;i="5.97,304,1669100400"; d="scan'208";a="137756684" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa6.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 17 Feb 2023 04:01:59 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 17 Feb 2023 04:01:59 -0700 Received: from che-lt-i67786lx.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 17 Feb 2023 04:01:55 -0700 From: Rakesh Sankaranarayanan To: , CC: , , , , , , , , , Thangaraj Samynathan Subject: [PATCH v2 net-next 1/5] net: dsa: microchip: add rmon grouping for ethtool statistics Date: Fri, 17 Feb 2023 16:32:07 +0530 Message-ID: <20230217110211.433505-2-rakesh.sankaranarayanan@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> References: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add support for ethtool standard device statistics grouping. Support rm= on statistics grouping using rmon groups parameter in ethtool command. rmon provides packet size based range grouping. Common mib parameters are us= ed across all KSZ series swtches for packet size statistics, except for KSZ8830. KSZ series have mib counters for packets with size: - less than 64 Bytes, - 65 to 127 Bytes, - 128 to 255 Bytes, - 256 to 511 Bytes, - 512 to 1023 Bytes, - 1024 to 1522 Bytes, - 1523 to 2000 Bytes and - More than 2001 Bytes KSZ8830 have mib counters upto 1024-1522 range only. Since no other cha= nge, common range used across all KSZ series, but used upto only upto 1024-1= 522 for KSZ8830. Co-developed-by: Thangaraj Samynathan Signed-off-by: Rakesh Sankaranarayanan --- drivers/net/dsa/microchip/Makefile | 1 + drivers/net/dsa/microchip/ksz_common.c | 15 ++ drivers/net/dsa/microchip/ksz_common.h | 3 + drivers/net/dsa/microchip/ksz_ethtool.c | 180 ++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_ethtool.h | 18 +++ 5 files changed, 217 insertions(+) create mode 100644 drivers/net/dsa/microchip/ksz_ethtool.c create mode 100644 drivers/net/dsa/microchip/ksz_ethtool.h diff --git a/drivers/net/dsa/microchip/Makefile b/drivers/net/dsa/microchip= /Makefile index 48360cc9fc68..2b698ac39a1f 100644 --- a/drivers/net/dsa/microchip/Makefile +++ b/drivers/net/dsa/microchip/Makefile @@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON) +=3D ksz_switch.o ksz_switch-objs :=3D ksz_common.o +ksz_switch-objs +=3D ksz_ethtool.o ksz_switch-objs +=3D ksz9477.o ksz_switch-objs +=3D ksz8795.o ksz_switch-objs +=3D lan937x_main.o diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 729b36eeb2c4..61f4e23d8849 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -27,6 +27,7 @@ #include =20 #include "ksz_common.h" +#include "ksz_ethtool.h" #include "ksz_ptp.h" #include "ksz8.h" #include "ksz9477.h" @@ -204,6 +205,7 @@ static const struct ksz_dev_ops ksz8_dev_ops =3D { .freeze_mib =3D ksz8_freeze_mib, .port_init_cnt =3D ksz8_port_init_cnt, .fdb_dump =3D ksz8_fdb_dump, + .get_rmon_stats =3D ksz8_get_rmon_stats, .mdb_add =3D ksz8_mdb_add, .mdb_del =3D ksz8_mdb_del, .vlan_filtering =3D ksz8_port_vlan_filtering, @@ -241,6 +243,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops =3D { .r_mib_stat64 =3D ksz_r_mib_stats64, .freeze_mib =3D ksz9477_freeze_mib, .port_init_cnt =3D ksz9477_port_init_cnt, + .get_rmon_stats =3D ksz9477_get_rmon_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -277,6 +280,7 @@ static const struct ksz_dev_ops lan937x_dev_ops =3D { .r_mib_stat64 =3D ksz_r_mib_stats64, .freeze_mib =3D ksz9477_freeze_mib, .port_init_cnt =3D ksz9477_port_init_cnt, + .get_rmon_stats =3D ksz9477_get_rmon_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -1730,6 +1734,16 @@ static void ksz_get_pause_stats(struct dsa_switch *d= s, int port, spin_unlock(&mib->stats64_lock); } =20 +static void ksz_get_rmon_stats(struct dsa_switch *ds, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges) +{ + struct ksz_device *dev =3D ds->priv; + + if (dev->dev_ops->get_rmon_stats) + dev->dev_ops->get_rmon_stats(dev, port, rmon_stats, ranges); +} + static void ksz_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *buf) { @@ -3186,6 +3200,7 @@ static const struct dsa_switch_ops ksz_switch_ops =3D= { .port_mirror_del =3D ksz_port_mirror_del, .get_stats64 =3D ksz_get_stats64, .get_pause_stats =3D ksz_get_pause_stats, + .get_rmon_stats =3D ksz_get_rmon_stats, .port_change_mtu =3D ksz_change_mtu, .port_max_mtu =3D ksz_max_mtu, .get_ts_info =3D ksz_get_ts_info, diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/micro= chip/ksz_common.h index d2d5761d58e9..a4e53431218c 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -361,6 +361,9 @@ struct ksz_dev_ops { int (*reset)(struct ksz_device *dev); int (*init)(struct ksz_device *dev); void (*exit)(struct ksz_device *dev); + void (*get_rmon_stats)(struct ksz_device *dev, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges); }; =20 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv); diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/micr= ochip/ksz_ethtool.c new file mode 100644 index 000000000000..0f3f18545858 --- /dev/null +++ b/drivers/net/dsa/microchip/ksz_ethtool.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Microchip KSZ series ethtool statistics + * + * Copyright (C) 2022 Microchip Technology Inc. + */ + +#include "ksz_common.h" +#include "ksz_ethtool.h" + +enum ksz8_mib_entry { + KSZ8_RX, + KSZ8_RX_HI, + KSZ8_RX_UNDERSIZE, + KSZ8_RX_FRAGMENTS, + KSZ8_RX_OVERSIZE, + KSZ8_RX_JABBERS, + KSZ8_RX_SYMBOL_ERR, + KSZ8_RX_CRC_ERR, + KSZ8_RX_ALIGN_ERR, + KSZ8_RX_MAC_CTL, + KSZ8_RX_PAUSE, + KSZ8_RX_BCAST, + KSZ8_RX_MCAST, + KSZ8_RX_UCAST, + KSZ8_RX_64_OR_LESS, + KSZ8_RX_65_127, + KSZ8_RX_128_255, + KSZ8_RX_256_511, + KSZ8_RX_512_1023, + KSZ8_RX_1024_1522, + KSZ8_TX, + KSZ8_TX_HI, + KSZ8_TX_LATE_COL, + KSZ8_TX_PAUSE, + KSZ8_TX_BCAST, + KSZ8_TX_MCAST, + KSZ8_TX_UCAST, + KSZ8_TX_DEFERRED, + KSZ8_TX_TOTAL_COL, + KSZ8_TX_EXC_COL, + KSZ8_TX_SINGLE_COL, + KSZ8_TX_MULT_COL, + KSZ8_RX_DISCARDS, + KSZ8_TX_DISCARDS, +}; + +enum ksz9477_mib_entry { + KSZ9477_RX_HI, + KSZ9477_RX_UNDERSIZE, + KSZ9477_RX_FRAGMENTS, + KSZ9477_RX_OVERSIZE, + KSZ9477_RX_JABBERS, + KSZ9477_RX_SYMBOL_ERR, + KSZ9477_RX_CRC_ERR, + KSZ9477_RX_ALIGN_ERR, + KSZ9477_RX_MAC_CTL, + KSZ9477_RX_PAUSE, + KSZ9477_RX_BCAST, + KSZ9477_RX_MCAST, + KSZ9477_RX_UCAST, + KSZ9477_RX_64_OR_LESS, + KSZ9477_RX_65_127, + KSZ9477_RX_128_255, + KSZ9477_RX_256_511, + KSZ9477_RX_512_1023, + KSZ9477_RX_1024_1522, + KSZ9477_RX_1523_2000, + KSZ9477_RX_2001, + KSZ9477_TX_HI, + KSZ9477_TX_LATE_COL, + KSZ9477_TX_PAUSE, + KSZ9477_TX_BCAST, + KSZ9477_TX_MCAST, + KSZ9477_TX_UCAST, + KSZ9477_TX_DEFERRED, + KSZ9477_TX_TOTAL_COL, + KSZ9477_TX_EXC_COL, + KSZ9477_TX_SINGLE_COL, + KSZ9477_TX_MULT_COL, + KSZ9477_RX_TOTAL, + KSZ9477_TX_TOTAL, + KSZ9477_RX_DISCARDS, + KSZ9477_TX_DISCARDS, +}; + +static const struct ethtool_rmon_hist_range ksz_rmon_ranges[] =3D { + { 0, 64 }, + { 65, 127 }, + { 128, 255 }, + { 256, 511 }, + { 512, 1023 }, + { 1024, 1522 }, + { 1523, 2000 }, + { 2001, 9000 }, + {} +}; + +#define KSZ8_HIST_LEN 6 +#define KSZ9477_HIST_LEN 8 + +void ksz8_get_rmon_stats(struct ksz_device *dev, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges) +{ + struct ksz_port_mib *mib; + u64 *cnt; + u8 i; + + mib =3D &dev->ports[port].mib; + + mutex_lock(&mib->cnt_mutex); + + cnt =3D &mib->counters[KSZ8_RX_UNDERSIZE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ8_RX_UNDERSIZE, NULL, cnt); + rmon_stats->undersize_pkts =3D *cnt; + + cnt =3D &mib->counters[KSZ8_RX_OVERSIZE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ8_RX_OVERSIZE, NULL, cnt); + rmon_stats->oversize_pkts =3D *cnt; + + cnt =3D &mib->counters[KSZ8_RX_FRAGMENTS]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ8_RX_FRAGMENTS, NULL, cnt); + rmon_stats->fragments =3D *cnt; + + cnt =3D &mib->counters[KSZ8_RX_JABBERS]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ8_RX_JABBERS, NULL, cnt); + rmon_stats->jabbers =3D *cnt; + + for (i =3D 0; i < KSZ8_HIST_LEN; i++) { + cnt =3D &mib->counters[KSZ8_RX_64_OR_LESS + i]; + dev->dev_ops->r_mib_pkt(dev, port, + (KSZ8_RX_64_OR_LESS + i), NULL, cnt); + rmon_stats->hist[i] =3D *cnt; + } + + mutex_unlock(&mib->cnt_mutex); + + *ranges =3D ksz_rmon_ranges; +} + +void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges) +{ + struct ksz_port_mib *mib; + u64 *cnt; + u8 i; + + mib =3D &dev->ports[port].mib; + + mutex_lock(&mib->cnt_mutex); + + cnt =3D &mib->counters[KSZ9477_RX_UNDERSIZE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ9477_RX_UNDERSIZE, NULL, cnt); + rmon_stats->undersize_pkts =3D *cnt; + + cnt =3D &mib->counters[KSZ9477_RX_OVERSIZE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ9477_RX_OVERSIZE, NULL, cnt); + rmon_stats->oversize_pkts =3D *cnt; + + cnt =3D &mib->counters[KSZ9477_RX_FRAGMENTS]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ9477_RX_FRAGMENTS, NULL, cnt); + rmon_stats->fragments =3D *cnt; + + cnt =3D &mib->counters[KSZ9477_RX_JABBERS]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ9477_RX_JABBERS, NULL, cnt); + rmon_stats->jabbers =3D *cnt; + + for (i =3D 0; i < KSZ9477_HIST_LEN; i++) { + cnt =3D &mib->counters[KSZ9477_RX_64_OR_LESS + i]; + dev->dev_ops->r_mib_pkt(dev, port, + (KSZ9477_RX_64_OR_LESS + i), NULL, cnt); + rmon_stats->hist[i] =3D *cnt; + } + + mutex_unlock(&mib->cnt_mutex); + + *ranges =3D ksz_rmon_ranges; +} diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/micr= ochip/ksz_ethtool.h new file mode 100644 index 000000000000..6927e2f143f8 --- /dev/null +++ b/drivers/net/dsa/microchip/ksz_ethtool.h @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Microchip KSZ series ethtool statistics + * + * Copyright (C) 2022 Microchip Technology Inc. + */ + +#ifndef __KSZ_ETHTOOL_H +#define __KSZ_ETHTOOL_H + +void ksz8_get_rmon_stats(struct ksz_device *dev, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges); + +void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, + struct ethtool_rmon_stats *rmon_stats, + const struct ethtool_rmon_hist_range **ranges); +#endif --=20 2.34.1 From nobody Thu Sep 11 16:05:28 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBBFBC64ED9 for ; Fri, 17 Feb 2023 11:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbjBQLCb (ORCPT ); Fri, 17 Feb 2023 06:02:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229882AbjBQLCO (ORCPT ); Fri, 17 Feb 2023 06:02:14 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B1A644E3; Fri, 17 Feb 2023 03:02:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1676631726; x=1708167726; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qQ8jpLCWB3xADM+WiiX2unPMfeq17rScD8SdIVMh6Nk=; b=xgWeM/zR6Qs6Ff3tD5BukDZ5MPDlDW2Tc8AH3YIHtkdaY1WFZWAP9S4W HD31uuQCCMx52b5ZqNrDpv2zNWneXvFgWRlxZbmKMVy9Rj7LnHGalG4JB RvrebxSnKPTApgCb/uDR4k2IU3EoZkP1RNvUBTLpnmZsPGZT0EohXqLnb tUoFz0rx+a9BBdc0urCdQy8N7n7pG0Z06IAHY50mJt9qxwy1VwklGrNXr fw4JkZf0WbI/MYOrUevLh3EL11GNzYZtGiyzyd6UBkQMvgx+bx2zWK188 z0pFBWuf4SeBeRN9JJWa2euIMTxLfxwh4yr9xqwddBoLISGNuUEkhQP7S Q==; X-IronPort-AV: E=Sophos;i="5.97,304,1669100400"; d="scan'208";a="201101352" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 17 Feb 2023 04:02:06 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex03.mchp-main.com (10.10.85.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 17 Feb 2023 04:02:05 -0700 Received: from che-lt-i67786lx.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 17 Feb 2023 04:02:02 -0700 From: Rakesh Sankaranarayanan To: , CC: , , , , , , , , Subject: [PATCH v2 net-next 2/5] net: dsa: microchip: add eth ctrl grouping for ethtool statistics Date: Fri, 17 Feb 2023 16:32:08 +0530 Message-ID: <20230217110211.433505-3-rakesh.sankaranarayanan@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> References: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add support for ethtool standard device statistics grouping. Support ethernet mac ctrl statistics grouping using eth-ctrl groups parameter in ethtool command. Signed-off-by: Rakesh Sankaranarayanan --- drivers/net/dsa/microchip/ksz_common.c | 13 ++++++++ drivers/net/dsa/microchip/ksz_common.h | 2 ++ drivers/net/dsa/microchip/ksz_ethtool.c | 42 +++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_ethtool.h | 4 +++ 4 files changed, 61 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 61f4e23d8849..91fc7eed79f0 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -206,6 +206,7 @@ static const struct ksz_dev_ops ksz8_dev_ops =3D { .port_init_cnt =3D ksz8_port_init_cnt, .fdb_dump =3D ksz8_fdb_dump, .get_rmon_stats =3D ksz8_get_rmon_stats, + .get_eth_ctrl_stats =3D ksz8_get_eth_ctrl_stats, .mdb_add =3D ksz8_mdb_add, .mdb_del =3D ksz8_mdb_del, .vlan_filtering =3D ksz8_port_vlan_filtering, @@ -244,6 +245,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops =3D { .freeze_mib =3D ksz9477_freeze_mib, .port_init_cnt =3D ksz9477_port_init_cnt, .get_rmon_stats =3D ksz9477_get_rmon_stats, + .get_eth_ctrl_stats =3D ksz9477_get_eth_ctrl_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -281,6 +283,7 @@ static const struct ksz_dev_ops lan937x_dev_ops =3D { .freeze_mib =3D ksz9477_freeze_mib, .port_init_cnt =3D ksz9477_port_init_cnt, .get_rmon_stats =3D ksz9477_get_rmon_stats, + .get_eth_ctrl_stats =3D ksz9477_get_eth_ctrl_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -1744,6 +1747,15 @@ static void ksz_get_rmon_stats(struct dsa_switch *ds= , int port, dev->dev_ops->get_rmon_stats(dev, port, rmon_stats, ranges); } =20 +static void ksz_get_eth_ctrl_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats) +{ + struct ksz_device *dev =3D ds->priv; + + if (dev->dev_ops->get_eth_ctrl_stats) + dev->dev_ops->get_eth_ctrl_stats(dev, port, ctrl_stats); +} + static void ksz_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *buf) { @@ -3201,6 +3213,7 @@ static const struct dsa_switch_ops ksz_switch_ops =3D= { .get_stats64 =3D ksz_get_stats64, .get_pause_stats =3D ksz_get_pause_stats, .get_rmon_stats =3D ksz_get_rmon_stats, + .get_eth_ctrl_stats =3D ksz_get_eth_ctrl_stats, .port_change_mtu =3D ksz_change_mtu, .port_max_mtu =3D ksz_max_mtu, .get_ts_info =3D ksz_get_ts_info, diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/micro= chip/ksz_common.h index a4e53431218c..7b0219947c7a 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -364,6 +364,8 @@ struct ksz_dev_ops { void (*get_rmon_stats)(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges); + void (*get_eth_ctrl_stats)(struct ksz_device *dev, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats); }; =20 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv); diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/micr= ochip/ksz_ethtool.c index 0f3f18545858..122c4371810a 100644 --- a/drivers/net/dsa/microchip/ksz_ethtool.c +++ b/drivers/net/dsa/microchip/ksz_ethtool.c @@ -139,6 +139,27 @@ void ksz8_get_rmon_stats(struct ksz_device *dev, int p= ort, *ranges =3D ksz_rmon_ranges; } =20 +void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats) +{ + struct ksz_port_mib *mib; + u64 *cnt; + + mib =3D &dev->ports[port].mib; + + mutex_lock(&mib->cnt_mutex); + + cnt =3D &mib->counters[KSZ8_TX_PAUSE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ8_TX_PAUSE, NULL, cnt); + ctrl_stats->MACControlFramesTransmitted =3D *cnt; + + cnt =3D &mib->counters[KSZ8_RX_PAUSE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ8_RX_PAUSE, NULL, cnt); + ctrl_stats->MACControlFramesReceived =3D *cnt; + + mutex_unlock(&mib->cnt_mutex); +} + void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges) @@ -178,3 +199,24 @@ void ksz9477_get_rmon_stats(struct ksz_device *dev, in= t port, =20 *ranges =3D ksz_rmon_ranges; } + +void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats) +{ + struct ksz_port_mib *mib; + u64 *cnt; + + mib =3D &dev->ports[port].mib; + + mutex_lock(&mib->cnt_mutex); + + cnt =3D &mib->counters[KSZ9477_TX_PAUSE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ9477_TX_PAUSE, NULL, cnt); + ctrl_stats->MACControlFramesTransmitted =3D *cnt; + + cnt =3D &mib->counters[KSZ9477_RX_PAUSE]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ9477_RX_PAUSE, NULL, cnt); + ctrl_stats->MACControlFramesReceived =3D *cnt; + + mutex_unlock(&mib->cnt_mutex); +} diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/micr= ochip/ksz_ethtool.h index 6927e2f143f8..18dc155d60b9 100644 --- a/drivers/net/dsa/microchip/ksz_ethtool.h +++ b/drivers/net/dsa/microchip/ksz_ethtool.h @@ -11,8 +11,12 @@ void ksz8_get_rmon_stats(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges); +void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats); =20 void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges); +void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port, + struct ethtool_eth_ctrl_stats *ctrl_stats); #endif --=20 2.34.1 From nobody Thu Sep 11 16:05:28 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F313DC678D5 for ; Fri, 17 Feb 2023 11:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229893AbjBQLCe (ORCPT ); Fri, 17 Feb 2023 06:02:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229921AbjBQLCR (ORCPT ); Fri, 17 Feb 2023 06:02:17 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E6353028D; Fri, 17 Feb 2023 03:02:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1676631731; x=1708167731; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TvhosYpnCmaq54jP9gfBjQ65AsWAKLJ0NHHkCvJYYsE=; b=02i8fHAMnIOCfyGqS8UJ0QkFaAGsB+0AEbhmpkN6vb7DXXmaEdVo/ApL Utv9kWRqzuP2fD5ZtX9ibSBTk9VZpthUJjDODR0Lda62vXFZIxekevgvY gurmeNau07If7VUybKvE74EHQxwNEwRwWvYotmY7cWlAuJeg8yYmOKfDo 20LcTa9r2PyOmQ4/oLOvS9svyqakWVkw2AhFI1YA2157nZrNs+X03keom J3l5bkNdlPNimbdcnBawm1ZgyfaRnl8fnXeDk0lwAatTqrC1gHIgJiDfW ex092jZ6353EQEdpOSpQDTgDGXrYY6znvVJcoO0qGi5PQDgusRVUjVDfj Q==; X-IronPort-AV: E=Sophos;i="5.97,304,1669100400"; d="scan'208";a="212497761" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 17 Feb 2023 04:02:10 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 17 Feb 2023 04:02:10 -0700 Received: from che-lt-i67786lx.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 17 Feb 2023 04:02:07 -0700 From: Rakesh Sankaranarayanan To: , CC: , , , , , , , , Subject: [PATCH v2 net-next 3/5] net: dsa: microchip: add eth mac grouping for ethtool statistics Date: Fri, 17 Feb 2023 16:32:09 +0530 Message-ID: <20230217110211.433505-4-rakesh.sankaranarayanan@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> References: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add support for ethtool standard device statistics grouping. Support ethernet mac statistics grouping using eth-mac groups parameter in ethtool command. Signed-off-by: Rakesh Sankaranarayanan --- drivers/net/dsa/microchip/ksz_common.c | 13 ++++ drivers/net/dsa/microchip/ksz_common.h | 2 + drivers/net/dsa/microchip/ksz_ethtool.c | 90 +++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_ethtool.h | 4 ++ 4 files changed, 109 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 91fc7eed79f0..e4a51f13afa4 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -207,6 +207,7 @@ static const struct ksz_dev_ops ksz8_dev_ops =3D { .fdb_dump =3D ksz8_fdb_dump, .get_rmon_stats =3D ksz8_get_rmon_stats, .get_eth_ctrl_stats =3D ksz8_get_eth_ctrl_stats, + .get_eth_mac_stats =3D ksz8_get_eth_mac_stats, .mdb_add =3D ksz8_mdb_add, .mdb_del =3D ksz8_mdb_del, .vlan_filtering =3D ksz8_port_vlan_filtering, @@ -246,6 +247,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops =3D { .port_init_cnt =3D ksz9477_port_init_cnt, .get_rmon_stats =3D ksz9477_get_rmon_stats, .get_eth_ctrl_stats =3D ksz9477_get_eth_ctrl_stats, + .get_eth_mac_stats =3D ksz9477_get_eth_mac_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -284,6 +286,7 @@ static const struct ksz_dev_ops lan937x_dev_ops =3D { .port_init_cnt =3D ksz9477_port_init_cnt, .get_rmon_stats =3D ksz9477_get_rmon_stats, .get_eth_ctrl_stats =3D ksz9477_get_eth_ctrl_stats, + .get_eth_mac_stats =3D ksz9477_get_eth_mac_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -1756,6 +1759,15 @@ static void ksz_get_eth_ctrl_stats(struct dsa_switch= *ds, int port, dev->dev_ops->get_eth_ctrl_stats(dev, port, ctrl_stats); } =20 +static void ksz_get_eth_mac_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_mac_stats *mac_stats) +{ + struct ksz_device *dev =3D ds->priv; + + if (dev->dev_ops->get_eth_mac_stats) + dev->dev_ops->get_eth_mac_stats(dev, port, mac_stats); +} + static void ksz_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *buf) { @@ -3214,6 +3226,7 @@ static const struct dsa_switch_ops ksz_switch_ops =3D= { .get_pause_stats =3D ksz_get_pause_stats, .get_rmon_stats =3D ksz_get_rmon_stats, .get_eth_ctrl_stats =3D ksz_get_eth_ctrl_stats, + .get_eth_mac_stats =3D ksz_get_eth_mac_stats, .port_change_mtu =3D ksz_change_mtu, .port_max_mtu =3D ksz_max_mtu, .get_ts_info =3D ksz_get_ts_info, diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/micro= chip/ksz_common.h index 7b0219947c7a..738e81923c31 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -366,6 +366,8 @@ struct ksz_dev_ops { const struct ethtool_rmon_hist_range **ranges); void (*get_eth_ctrl_stats)(struct ksz_device *dev, int port, struct ethtool_eth_ctrl_stats *ctrl_stats); + void (*get_eth_mac_stats)(struct ksz_device *dev, int port, + struct ethtool_eth_mac_stats *mac_stats); }; =20 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv); diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/micr= ochip/ksz_ethtool.c index 122c4371810a..42954bbfb9b4 100644 --- a/drivers/net/dsa/microchip/ksz_ethtool.c +++ b/drivers/net/dsa/microchip/ksz_ethtool.c @@ -160,6 +160,50 @@ void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, i= nt port, mutex_unlock(&mib->cnt_mutex); } =20 +void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port, + struct ethtool_eth_mac_stats *mac_stats) +{ + struct ksz_port_mib *mib; + u64 *ctr; + + mib =3D &dev->ports[port].mib; + + mutex_lock(&mib->cnt_mutex); + ctr =3D mib->counters; + + while (mib->cnt_ptr < dev->info->mib_cnt) { + dev->dev_ops->r_mib_pkt(dev, port, mib->cnt_ptr, + NULL, &mib->counters[mib->cnt_ptr]); + ++mib->cnt_ptr; + } + + mac_stats->FramesTransmittedOK =3D ctr[KSZ8_TX_MCAST] + + ctr[KSZ8_TX_BCAST] + + ctr[KSZ8_TX_UCAST] + + ctr[KSZ8_TX_PAUSE] - + ctr[KSZ8_TX_DISCARDS]; + mac_stats->SingleCollisionFrames =3D ctr[KSZ8_TX_SINGLE_COL]; + mac_stats->MultipleCollisionFrames =3D ctr[KSZ8_TX_MULT_COL]; + mac_stats->FramesReceivedOK =3D ctr[KSZ8_RX_MCAST] + + ctr[KSZ8_RX_BCAST] + + ctr[KSZ8_RX_UCAST] + + ctr[KSZ8_RX_PAUSE] + + ctr[KSZ8_RX_DISCARDS]; + mac_stats->FrameCheckSequenceErrors =3D ctr[KSZ8_RX_CRC_ERR]; + mac_stats->AlignmentErrors =3D ctr[KSZ8_RX_ALIGN_ERR]; + mac_stats->FramesWithDeferredXmissions =3D ctr[KSZ8_TX_DEFERRED]; + mac_stats->LateCollisions =3D ctr[KSZ8_TX_LATE_COL]; + mac_stats->FramesAbortedDueToXSColls =3D ctr[KSZ8_TX_EXC_COL]; + mac_stats->MulticastFramesXmittedOK =3D ctr[KSZ8_TX_MCAST]; + mac_stats->BroadcastFramesXmittedOK =3D ctr[KSZ8_TX_BCAST]; + mac_stats->MulticastFramesReceivedOK =3D ctr[KSZ8_RX_MCAST]; + mac_stats->BroadcastFramesReceivedOK =3D ctr[KSZ8_RX_BCAST]; + + mib->cnt_ptr =3D 0; + + mutex_unlock(&mib->cnt_mutex); +} + void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges) @@ -220,3 +264,49 @@ void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev= , int port, =20 mutex_unlock(&mib->cnt_mutex); } + +void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port, + struct ethtool_eth_mac_stats *mac_stats) +{ + struct ksz_port_mib *mib; + u64 *ctr; + + mib =3D &dev->ports[port].mib; + ctr =3D mib->counters; + + mutex_lock(&mib->cnt_mutex); + + while (mib->cnt_ptr < dev->info->mib_cnt) { + dev->dev_ops->r_mib_pkt(dev, port, mib->cnt_ptr, + NULL, &mib->counters[mib->cnt_ptr]); + ++mib->cnt_ptr; + } + + mac_stats->FramesTransmittedOK =3D ctr[KSZ9477_TX_MCAST] + + ctr[KSZ9477_TX_BCAST] + + ctr[KSZ9477_TX_UCAST] + + ctr[KSZ9477_TX_PAUSE] - + ctr[KSZ9477_TX_DISCARDS]; + mac_stats->SingleCollisionFrames =3D ctr[KSZ9477_TX_SINGLE_COL]; + mac_stats->MultipleCollisionFrames =3D ctr[KSZ9477_TX_MULT_COL]; + mac_stats->FramesReceivedOK =3D ctr[KSZ9477_RX_MCAST] + + ctr[KSZ9477_RX_BCAST] + + ctr[KSZ9477_RX_UCAST] + + ctr[KSZ9477_RX_PAUSE] + + ctr[KSZ9477_RX_DISCARDS]; + mac_stats->FrameCheckSequenceErrors =3D ctr[KSZ9477_RX_CRC_ERR]; + mac_stats->AlignmentErrors =3D ctr[KSZ9477_RX_ALIGN_ERR]; + mac_stats->OctetsTransmittedOK =3D ctr[KSZ9477_TX_TOTAL] - + (18 * mac_stats->FramesTransmittedOK); + mac_stats->FramesWithDeferredXmissions =3D ctr[KSZ9477_TX_DEFERRED]; + mac_stats->LateCollisions =3D ctr[KSZ9477_TX_LATE_COL]; + mac_stats->FramesAbortedDueToXSColls =3D ctr[KSZ9477_TX_EXC_COL]; + mac_stats->MulticastFramesXmittedOK =3D ctr[KSZ9477_TX_MCAST]; + mac_stats->BroadcastFramesXmittedOK =3D ctr[KSZ9477_TX_BCAST]; + mac_stats->MulticastFramesReceivedOK =3D ctr[KSZ9477_RX_MCAST]; + mac_stats->BroadcastFramesReceivedOK =3D ctr[KSZ9477_RX_BCAST]; + + mib->cnt_ptr =3D 0; + + mutex_unlock(&mib->cnt_mutex); +} diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/micr= ochip/ksz_ethtool.h index 18dc155d60b9..2dcfe8922b4e 100644 --- a/drivers/net/dsa/microchip/ksz_ethtool.h +++ b/drivers/net/dsa/microchip/ksz_ethtool.h @@ -13,10 +13,14 @@ void ksz8_get_rmon_stats(struct ksz_device *dev, int po= rt, const struct ethtool_rmon_hist_range **ranges); void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int port, struct ethtool_eth_ctrl_stats *ctrl_stats); +void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port, + struct ethtool_eth_mac_stats *mac_stats); =20 void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges); void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, int port, struct ethtool_eth_ctrl_stats *ctrl_stats); +void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port, + struct ethtool_eth_mac_stats *mac_stats); #endif --=20 2.34.1 From nobody Thu Sep 11 16:05:28 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D5DEC677F1 for ; Fri, 17 Feb 2023 11:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229915AbjBQLCh (ORCPT ); Fri, 17 Feb 2023 06:02:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbjBQLCW (ORCPT ); Fri, 17 Feb 2023 06:02:22 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 072A83028D; Fri, 17 Feb 2023 03:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1676631740; x=1708167740; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xuAQHwlijF+Yj0VX+hzdHh3BDSnnpTYis5wdwFZYBCU=; b=r2CeWCvXHU0dxcrwPxxhXf7bABxpbm/Y1ur/5GqiCLVCkoPo8R0EBueP qY66D4fdOl8gGXftvI4pkrzjUvdBV9FOgePpD3t31aN5DMi2kuq9AVOE7 ti0lGWA75ZwGI4Nl0I5PVoYAS9147j5/M/QEe2oEQWseSaZJ7Dn+/dJBC 5ZZfZGxg3wQgv1gSTtONZG8rLpFF1/0xR0Ye2rKniRFRI4Q9Z1hOLKc50 T9HVJUFMpJiUrJVJXYd4oR4yqVvOTX6Wm/uQv+YPp5BpfOK18TyWXn3pe +w8IjXJC/BpbvdTMeQjvwqeh7YsUINlAkOgakGJjvlYju9Ypk7t+9P1Qt g==; X-IronPort-AV: E=Sophos;i="5.97,304,1669100400"; d="scan'208";a="201101386" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 17 Feb 2023 04:02:20 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 17 Feb 2023 04:02:15 -0700 Received: from che-lt-i67786lx.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 17 Feb 2023 04:02:12 -0700 From: Rakesh Sankaranarayanan To: , CC: , , , , , , , , Subject: [PATCH v2 net-next 4/5] net: dsa: microchip: add eth phy grouping for ethtool statistics Date: Fri, 17 Feb 2023 16:32:10 +0530 Message-ID: <20230217110211.433505-5-rakesh.sankaranarayanan@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> References: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add support for ethtool standard device statistics grouping. Support ethernet phy statistics grouping using eth-phy groups parameter in ethtool command. Signed-off-by: Rakesh Sankaranarayanan --- drivers/net/dsa/microchip/ksz_common.c | 13 +++++++++ drivers/net/dsa/microchip/ksz_common.h | 2 ++ drivers/net/dsa/microchip/ksz_ethtool.c | 36 +++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_ethtool.h | 5 ++++ 4 files changed, 56 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index e4a51f13afa4..01adcbeffaaa 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -208,6 +208,7 @@ static const struct ksz_dev_ops ksz8_dev_ops =3D { .get_rmon_stats =3D ksz8_get_rmon_stats, .get_eth_ctrl_stats =3D ksz8_get_eth_ctrl_stats, .get_eth_mac_stats =3D ksz8_get_eth_mac_stats, + .get_eth_phy_stats =3D ksz8_get_eth_phy_stats, .mdb_add =3D ksz8_mdb_add, .mdb_del =3D ksz8_mdb_del, .vlan_filtering =3D ksz8_port_vlan_filtering, @@ -248,6 +249,7 @@ static const struct ksz_dev_ops ksz9477_dev_ops =3D { .get_rmon_stats =3D ksz9477_get_rmon_stats, .get_eth_ctrl_stats =3D ksz9477_get_eth_ctrl_stats, .get_eth_mac_stats =3D ksz9477_get_eth_mac_stats, + .get_eth_phy_stats =3D ksz9477_get_eth_phy_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -287,6 +289,7 @@ static const struct ksz_dev_ops lan937x_dev_ops =3D { .get_rmon_stats =3D ksz9477_get_rmon_stats, .get_eth_ctrl_stats =3D ksz9477_get_eth_ctrl_stats, .get_eth_mac_stats =3D ksz9477_get_eth_mac_stats, + .get_eth_phy_stats =3D ksz9477_get_eth_phy_stats, .vlan_filtering =3D ksz9477_port_vlan_filtering, .vlan_add =3D ksz9477_port_vlan_add, .vlan_del =3D ksz9477_port_vlan_del, @@ -1768,6 +1771,15 @@ static void ksz_get_eth_mac_stats(struct dsa_switch = *ds, int port, dev->dev_ops->get_eth_mac_stats(dev, port, mac_stats); } =20 +static void ksz_get_eth_phy_stats(struct dsa_switch *ds, int port, + struct ethtool_eth_phy_stats *phy_stats) +{ + struct ksz_device *dev =3D ds->priv; + + if (dev->dev_ops->get_eth_phy_stats) + dev->dev_ops->get_eth_phy_stats(dev, port, phy_stats); +} + static void ksz_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *buf) { @@ -3227,6 +3239,7 @@ static const struct dsa_switch_ops ksz_switch_ops =3D= { .get_rmon_stats =3D ksz_get_rmon_stats, .get_eth_ctrl_stats =3D ksz_get_eth_ctrl_stats, .get_eth_mac_stats =3D ksz_get_eth_mac_stats, + .get_eth_phy_stats =3D ksz_get_eth_phy_stats, .port_change_mtu =3D ksz_change_mtu, .port_max_mtu =3D ksz_max_mtu, .get_ts_info =3D ksz_get_ts_info, diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/micro= chip/ksz_common.h index 738e81923c31..8a71e035b699 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -368,6 +368,8 @@ struct ksz_dev_ops { struct ethtool_eth_ctrl_stats *ctrl_stats); void (*get_eth_mac_stats)(struct ksz_device *dev, int port, struct ethtool_eth_mac_stats *mac_stats); + void (*get_eth_phy_stats)(struct ksz_device *dev, int port, + struct ethtool_eth_phy_stats *phy_stats); }; =20 struct ksz_device *ksz_switch_alloc(struct device *base, void *priv); diff --git a/drivers/net/dsa/microchip/ksz_ethtool.c b/drivers/net/dsa/micr= ochip/ksz_ethtool.c index 42954bbfb9b4..c0b95d78e41e 100644 --- a/drivers/net/dsa/microchip/ksz_ethtool.c +++ b/drivers/net/dsa/microchip/ksz_ethtool.c @@ -204,6 +204,24 @@ void ksz8_get_eth_mac_stats(struct ksz_device *dev, in= t port, mutex_unlock(&mib->cnt_mutex); } =20 +void ksz8_get_eth_phy_stats(struct ksz_device *dev, int port, + struct ethtool_eth_phy_stats *phy_stats) +{ + struct ksz_port_mib *mib; + u64 *cnt; + + mib =3D &dev->ports[port].mib; + + mutex_lock(&mib->cnt_mutex); + + cnt =3D &mib->counters[KSZ8_RX_SYMBOL_ERR]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ8_RX_SYMBOL_ERR, NULL, cnt); + + phy_stats->SymbolErrorDuringCarrier =3D *cnt; + + mutex_unlock(&mib->cnt_mutex); +} + void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, const struct ethtool_rmon_hist_range **ranges) @@ -310,3 +328,21 @@ void ksz9477_get_eth_mac_stats(struct ksz_device *dev,= int port, =20 mutex_unlock(&mib->cnt_mutex); } + +void ksz9477_get_eth_phy_stats(struct ksz_device *dev, int port, + struct ethtool_eth_phy_stats *phy_stats) +{ + struct ksz_port_mib *mib; + u64 *cnt; + + mib =3D &dev->ports[port].mib; + + mutex_lock(&mib->cnt_mutex); + + cnt =3D &mib->counters[KSZ9477_RX_SYMBOL_ERR]; + dev->dev_ops->r_mib_pkt(dev, port, KSZ9477_RX_SYMBOL_ERR, NULL, cnt); + + phy_stats->SymbolErrorDuringCarrier =3D *cnt; + + mutex_unlock(&mib->cnt_mutex); +} diff --git a/drivers/net/dsa/microchip/ksz_ethtool.h b/drivers/net/dsa/micr= ochip/ksz_ethtool.h index 2dcfe8922b4e..042a0b38a899 100644 --- a/drivers/net/dsa/microchip/ksz_ethtool.h +++ b/drivers/net/dsa/microchip/ksz_ethtool.h @@ -15,6 +15,8 @@ void ksz8_get_eth_ctrl_stats(struct ksz_device *dev, int = port, struct ethtool_eth_ctrl_stats *ctrl_stats); void ksz8_get_eth_mac_stats(struct ksz_device *dev, int port, struct ethtool_eth_mac_stats *mac_stats); +void ksz8_get_eth_phy_stats(struct ksz_device *dev, int port, + struct ethtool_eth_phy_stats *phy_stats); =20 void ksz9477_get_rmon_stats(struct ksz_device *dev, int port, struct ethtool_rmon_stats *rmon_stats, @@ -23,4 +25,7 @@ void ksz9477_get_eth_ctrl_stats(struct ksz_device *dev, i= nt port, struct ethtool_eth_ctrl_stats *ctrl_stats); void ksz9477_get_eth_mac_stats(struct ksz_device *dev, int port, struct ethtool_eth_mac_stats *mac_stats); +void ksz9477_get_eth_phy_stats(struct ksz_device *dev, int port, + struct ethtool_eth_phy_stats *phy_stats); + #endif --=20 2.34.1 From nobody Thu Sep 11 16:05:28 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DFB3C678DB for ; Fri, 17 Feb 2023 11:02:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229946AbjBQLCi (ORCPT ); Fri, 17 Feb 2023 06:02:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbjBQLCY (ORCPT ); Fri, 17 Feb 2023 06:02:24 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A095E62439; Fri, 17 Feb 2023 03:02:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1676631742; x=1708167742; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=F2mURk/fbobB4rI6EopNkBH1Wbw2zILKSpSvtFfxyOs=; b=eQNrVXFDEmZzuAZDqlRVBTjeGoRydN9SESgFhTA4pQ9PUpAOAeuxXc1B kZUtuaahjaGYvQATNYZOvO7gFqwNFJsmBSyh0KDGdxO1CvFkOwxXAeNOv ylZPs1AbZOHGv04ZnH8us0rVMhGVboPYvsTNBRGpxLdeeEvObaI+9c0mV 5NTtv6R0QOp4Z1lLdcoe6ZkpweKpYAg76RxK4gD1JxiCFqzJIMkt63Mim Kh4z27MoxPhO+QxIARXFwFiyOgNXBckNZzpW+G4YaSrbUx67QTMik84oz INmU2O+o0CUjlmbZHERgjBokzEXqEXmLtg0jC0Xq/LbWoVXOZSCotp6mH Q==; X-IronPort-AV: E=Sophos;i="5.97,304,1669100400"; d="scan'208";a="201101424" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa2.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 17 Feb 2023 04:02:21 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.16; Fri, 17 Feb 2023 04:02:20 -0700 Received: from che-lt-i67786lx.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Fri, 17 Feb 2023 04:02:17 -0700 From: Rakesh Sankaranarayanan To: , CC: , , , , , , , , Subject: [PATCH v2 net-next 5/5] net: dsa: microchip: remove num_alus_variable Date: Fri, 17 Feb 2023 16:32:11 +0530 Message-ID: <20230217110211.433505-6-rakesh.sankaranarayanan@microchip.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> References: <20230217110211.433505-1-rakesh.sankaranarayanan@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Remove num_alus variable from ksz_chip_data structure since it is unused now. Signed-off-by: Rakesh Sankaranarayanan --- drivers/net/dsa/microchip/ksz_common.c | 16 ---------------- drivers/net/dsa/microchip/ksz_common.h | 1 - 2 files changed, 17 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/micro= chip/ksz_common.c index 01adcbeffaaa..152f68eda355 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -1095,7 +1095,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ8563_CHIP_ID, .dev_name =3D "KSZ8563", .num_vlans =3D 4096, - .num_alus =3D 4096, .num_statics =3D 16, .cpu_ports =3D 0x07, /* can be configured as cpu port */ .port_cnt =3D 3, /* total port count */ @@ -1124,7 +1123,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ8795_CHIP_ID, .dev_name =3D "KSZ8795", .num_vlans =3D 4096, - .num_alus =3D 0, .num_statics =3D 8, .cpu_ports =3D 0x10, /* can be configured as cpu port */ .port_cnt =3D 5, /* total cpu and user ports */ @@ -1163,7 +1161,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ8794_CHIP_ID, .dev_name =3D "KSZ8794", .num_vlans =3D 4096, - .num_alus =3D 0, .num_statics =3D 8, .cpu_ports =3D 0x10, /* can be configured as cpu port */ .port_cnt =3D 5, /* total cpu and user ports */ @@ -1188,7 +1185,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ8765_CHIP_ID, .dev_name =3D "KSZ8765", .num_vlans =3D 4096, - .num_alus =3D 0, .num_statics =3D 8, .cpu_ports =3D 0x10, /* can be configured as cpu port */ .port_cnt =3D 5, /* total cpu and user ports */ @@ -1213,7 +1209,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ8830_CHIP_ID, .dev_name =3D "KSZ8863/KSZ8873", .num_vlans =3D 16, - .num_alus =3D 0, .num_statics =3D 8, .cpu_ports =3D 0x4, /* can be configured as cpu port */ .port_cnt =3D 3, @@ -1234,7 +1229,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ9477_CHIP_ID, .dev_name =3D "KSZ9477", .num_vlans =3D 4096, - .num_alus =3D 4096, .num_statics =3D 16, .cpu_ports =3D 0x7F, /* can be configured as cpu port */ .port_cnt =3D 7, /* total physical port count */ @@ -1268,7 +1262,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ9896_CHIP_ID, .dev_name =3D "KSZ9896", .num_vlans =3D 4096, - .num_alus =3D 4096, .num_statics =3D 16, .cpu_ports =3D 0x3F, /* can be configured as cpu port */ .port_cnt =3D 6, /* total physical port count */ @@ -1301,7 +1294,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ9897_CHIP_ID, .dev_name =3D "KSZ9897", .num_vlans =3D 4096, - .num_alus =3D 4096, .num_statics =3D 16, .cpu_ports =3D 0x7F, /* can be configured as cpu port */ .port_cnt =3D 7, /* total physical port count */ @@ -1332,7 +1324,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ9893_CHIP_ID, .dev_name =3D "KSZ9893", .num_vlans =3D 4096, - .num_alus =3D 4096, .num_statics =3D 16, .cpu_ports =3D 0x07, /* can be configured as cpu port */ .port_cnt =3D 3, /* total port count */ @@ -1358,7 +1349,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ9563_CHIP_ID, .dev_name =3D "KSZ9563", .num_vlans =3D 4096, - .num_alus =3D 4096, .num_statics =3D 16, .cpu_ports =3D 0x07, /* can be configured as cpu port */ .port_cnt =3D 3, /* total port count */ @@ -1385,7 +1375,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D KSZ9567_CHIP_ID, .dev_name =3D "KSZ9567", .num_vlans =3D 4096, - .num_alus =3D 4096, .num_statics =3D 16, .cpu_ports =3D 0x7F, /* can be configured as cpu port */ .port_cnt =3D 7, /* total physical port count */ @@ -1417,7 +1406,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D LAN9370_CHIP_ID, .dev_name =3D "LAN9370", .num_vlans =3D 4096, - .num_alus =3D 1024, .num_statics =3D 256, .cpu_ports =3D 0x10, /* can be configured as cpu port */ .port_cnt =3D 5, /* total physical port count */ @@ -1443,7 +1431,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D LAN9371_CHIP_ID, .dev_name =3D "LAN9371", .num_vlans =3D 4096, - .num_alus =3D 1024, .num_statics =3D 256, .cpu_ports =3D 0x30, /* can be configured as cpu port */ .port_cnt =3D 6, /* total physical port count */ @@ -1469,7 +1456,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D LAN9372_CHIP_ID, .dev_name =3D "LAN9372", .num_vlans =3D 4096, - .num_alus =3D 1024, .num_statics =3D 256, .cpu_ports =3D 0x30, /* can be configured as cpu port */ .port_cnt =3D 8, /* total physical port count */ @@ -1499,7 +1485,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D LAN9373_CHIP_ID, .dev_name =3D "LAN9373", .num_vlans =3D 4096, - .num_alus =3D 1024, .num_statics =3D 256, .cpu_ports =3D 0x38, /* can be configured as cpu port */ .port_cnt =3D 5, /* total physical port count */ @@ -1529,7 +1514,6 @@ const struct ksz_chip_data ksz_switch_chips[] =3D { .chip_id =3D LAN9374_CHIP_ID, .dev_name =3D "LAN9374", .num_vlans =3D 4096, - .num_alus =3D 1024, .num_statics =3D 256, .cpu_ports =3D 0x30, /* can be configured as cpu port */ .port_cnt =3D 8, /* total physical port count */ diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/micro= chip/ksz_common.h index 8a71e035b699..40c4f5f2d9d5 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -44,7 +44,6 @@ struct ksz_chip_data { u32 chip_id; const char *dev_name; int num_vlans; - int num_alus; int num_statics; int cpu_ports; int port_cnt; --=20 2.34.1