From nobody Fri Sep 19 00:54:51 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 710FCC47089 for ; Wed, 30 Nov 2022 20:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229800AbiK3UIN (ORCPT ); Wed, 30 Nov 2022 15:08:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229794AbiK3UIK (ORCPT ); Wed, 30 Nov 2022 15:08:10 -0500 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6BF0F711A4; Wed, 30 Nov 2022 12:08:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1669838888; x=1701374888; h=from:to:subject:date:message-id:mime-version: content-transfer-encoding; bh=8guv5jwcaPQnC7by4n9uUpuRQSBkVBi41RgNbjLZ4lI=; b=U4yK5oV/5RhUvxKCPmIKeqqghxdMagcYu6pgMXYmbWUMj8sgRPc1PyjH RqNWy17a390Cnvl5OuFfHIp9FvnkE29GXXSD7lD6I/4piLGMqZDuC3N+2 I42p17uwvAc21pONyaoQDlsReTiKzAeAe8qxbp0uxdBzES1c2HuSzog4I eexBv68elP2GqqfPC0+LXZUj+vQyTCGS68A6oRMhJj7rdlf+t3DSvBe0C xrWXnY3eB+tgOsLjrYWvN8rgQlRmkd3u1fQ54hrEsPgUCLIuo8rXHuMiW uEy8pC8QgZDmtYTSlCGWG+aQG+yOKKLSstXZECMJCW8l30Do5SgWk+nQ3 g==; X-IronPort-AV: E=Sophos;i="5.96,207,1665471600"; d="scan'208";a="202086423" Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 30 Nov 2022 13:08:07 -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.12; Wed, 30 Nov 2022 13:08:07 -0700 Received: from AUS-LT-C33025.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.12 via Frontend Transport; Wed, 30 Nov 2022 13:08:05 -0700 From: Jerry Ray To: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , "Paolo Abeni" , , , Jerry Ray Subject: [PATCH net-next v4] dsa: lan9303: Add 3 ethtool stats Date: Wed, 30 Nov 2022 14:08:04 -0600 Message-ID: <20221130200804.21778-1-jerry.ray@microchip.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding Buffer Manager and Switch Engine counters to the reported statistics. As these stats are kept by the switch rather than the port instance, they are indexed differently. These statistics are maintained by the switch and count the packets dropped due to buffer limits. Note that the rtnl_link_stats: rx_dropped statistic does not include dropped packets due to buffer exhaustion and as such, part of this counter would more appropriately fall under the rx_missed_errors. Migrating to phylink will be a pre-requisite for adding the stats64 API, at which point the rtnl_link_stats will come into play. Signed-off-by: Jerry Ray --- v3->v4: added returning stat of 0 if there is a device read failure. removed unrelated change. v2->v3: Isolating this patch to include only the added counters. Renamed the new statsistic labels to better identify them. Added the SWE Filtered counter to the reported statistics. Added comments to explain the added counters. v1->v2: Split patch into 2 pieces. Removed the adding of a module number to the driver. --- drivers/net/dsa/lan9303-core.c | 57 +++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c index 80f07bd20593..93c2a3c549cb 100644 --- a/drivers/net/dsa/lan9303-core.c +++ b/drivers/net/dsa/lan9303-core.c @@ -176,11 +176,14 @@ # define LAN9303_SWE_PORT_MIRROR_DISABLED 0 #define LAN9303_SWE_INGRESS_PORT_TYPE 0x1847 #define LAN9303_SWE_INGRESS_PORT_TYPE_VLAN 3 +#define LAN9303_SWE_FILTERED_CNT_SRC_0 0x1850 #define LAN9303_BM_CFG 0x1c00 +#define LAN9303_BM_DRP_CNT_SRC_0 0x1c05 #define LAN9303_BM_EGRSS_PORT_TYPE 0x1c0c # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT2 (BIT(17) | BIT(16)) # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT1 (BIT(9) | BIT(8)) # define LAN9303_BM_EGRSS_PORT_TYPE_SPECIAL_TAG_PORT0 (BIT(1) | BIT(0)) +#define LAN9303_BM_RATE_DRP_CNT_SRC_0 0x1c16 =20 #define LAN9303_SWITCH_PORT_REG(port, reg0) (0x400 * (port) + (reg0)) =20 @@ -978,10 +981,33 @@ static const struct lan9303_mib_desc lan9303_mib[] = =3D { { .offset =3D LAN9303_MAC_TX_LATECOL_0, .name =3D "TxLateCol", }, }; =20 +/* Buffer Management Statistics (indexed by port) */ +/* Switch Engine Statistics (indexed by port) */ +static const struct lan9303_mib_desc lan9303_switch_mib[] =3D { + { .offset =3D LAN9303_BM_DRP_CNT_SRC_0, .name =3D "TotalDropped", }, + { .offset =3D LAN9303_BM_RATE_DRP_CNT_SRC_0, .name =3D "LimitDropped", }, + { .offset =3D LAN9303_SWE_FILTERED_CNT_SRC_0, .name =3D "SweFiltered", }, +}; + +/* TotalDropped: This register counts the total number of packets drop= ped + * by the Buffer Manager that were received on the given port.=C2=A0This c= ount + * includes packets dropped due to buffer space limits and ingress rate li= mit + * discarding (Red and random Yellow dropping). + * + * LimitDropped: This register counts the number of packets received o= n a + * port that were dropped by the Buffer Manager solely due to ingress rate + * limiting (discarding packets due to Red and random Yellow dropping). + * + * SweFiltered: This counter contains the number of packets filtered = by + * the Switch Engine at ingress for a given port. The count includes packe= ts + * filtered due to broadcast throttling, but does not include packets drop= ped + * due to ingress rate limiting. + */ + static void lan9303_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data) { - unsigned int u; + unsigned int i, u; =20 if (stringset !=3D ETH_SS_STATS) return; @@ -990,26 +1016,49 @@ static void lan9303_get_strings(struct dsa_switch *d= s, int port, strncpy(data + u * ETH_GSTRING_LEN, lan9303_mib[u].name, ETH_GSTRING_LEN); } + for (i =3D 0; i < ARRAY_SIZE(lan9303_switch_mib); i++) { + strncpy(data + (u + i) * ETH_GSTRING_LEN, + lan9303_switch_mib[i].name, ETH_GSTRING_LEN); + } } =20 static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port, uint64_t *data) { struct lan9303 *chip =3D ds->priv; - unsigned int u; + unsigned int i, u; =20 for (u =3D 0; u < ARRAY_SIZE(lan9303_mib); u++) { u32 reg; int ret; =20 + /* Read Port-based MIB stats. */ ret =3D lan9303_read_switch_port( chip, port, lan9303_mib[u].offset, ®); =20 - if (ret) + if (ret) { dev_warn(chip->dev, "Reading status port %d reg %u failed\n", port, lan9303_mib[u].offset); + reg =3D 0; + } data[u] =3D reg; } + for (i =3D 0; i < ARRAY_SIZE(lan9303_switch_mib); i++) { + u32 reg; + int ret; + + /* Read Switch stats indexed by port. */ + ret =3D lan9303_read_switch_reg(chip, + (lan9303_switch_mib[i].offset + + port), ®); + + if (ret) { + dev_warn(chip->dev, "Reading status port %d reg %u failed\n", + port, lan9303_switch_mib[i].offset + port); + reg =3D 0; + } + data[i + u] =3D reg; + } } =20 static int lan9303_get_sset_count(struct dsa_switch *ds, int port, int sse= t) @@ -1017,7 +1066,7 @@ static int lan9303_get_sset_count(struct dsa_switch *= ds, int port, int sset) if (sset !=3D ETH_SS_STATS) return 0; =20 - return ARRAY_SIZE(lan9303_mib); + return ARRAY_SIZE(lan9303_mib) + ARRAY_SIZE(lan9303_switch_mib); } =20 static int lan9303_phy_read(struct dsa_switch *ds, int phy, int regnum) --=20 2.17.1