Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1647419pxb; Wed, 10 Feb 2021 13:13:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyPSw0Wq8FPCJs4QFHkhHP4q1BxLtMSSIf19NgRMpGntJFUr3ylZZi5tCi3FucxmQ+z150M X-Received: by 2002:a17:906:c296:: with SMTP id r22mr5055284ejz.158.1612991636167; Wed, 10 Feb 2021 13:13:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612991636; cv=none; d=google.com; s=arc-20160816; b=fsPX7XvaZw7Eahj2OdDPIQTM3RLA7zAHhzkxSihGt8ualyd3gtqDtt3cdV/h4szVKc gcW1e8RhaYJuI059cjPtVv67xQ3nzQFXwqedkI/XixM1Tdl64cK2YbD7ghzYwzW2NN6r PTvpJ2dnqk+ytAW5LV2oHizx/ZS0w31i9Tmin5YM4kkpJhhH8QHQRmGO6dP2PLtS6JhX fM4cFNO/KBFdx+lN+5cjjOrdarAFY7AcQt4sQcCBhmfuxwd+JGc20Pxvl14pSAool04s RQSQ6snqEp9zRDXCjcNJ4+kaCxu8XqriuzXSvUPHKUb3FQGyaLitNXAlWX/hnyZGJOjP +WMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XFYwk+ThwpaIVka92LotS47Rkx7x2jw8LAKSGXHzb78=; b=XlWTxA+rrNPW9B70qa3uYpJBn2iMGUQSb7tyZIQBxQMR3zKoDKGriIHlu2FaJkVkkZ RXX8tjJjcJDojjZF28wCcxh2fnJPhoegXnnqMbkIP8mNiulspaUlcTz0acwrvHaJDj/M Xg7mGedljwYLCXc0Vc0y5RMvufkLYchPBvbVQ5O3KkQ7m7EEbNDBAiVZQwXiDSCY82Ho 7bHpoCYZS12VmcIepoSZt1CbVEHNgGTSCbZKdTf8mTsD5y08mgKWpOn9xnf0iyzNenaA MrF9odybgolTmcuD9aviGVkXuYy05+k2+C63p7NTni0h5n6JKbVGT1NjBQvJjE3ZrmoD JKYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=cmuRuexc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f8si1998361ejf.3.2021.02.10.13.13.30; Wed, 10 Feb 2021 13:13:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=cmuRuexc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233691AbhBJVMO (ORCPT + 99 others); Wed, 10 Feb 2021 16:12:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232587AbhBJVJD (ORCPT ); Wed, 10 Feb 2021 16:09:03 -0500 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D5A2C061574; Wed, 10 Feb 2021 13:08:22 -0800 (PST) Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id E641023E82; Wed, 10 Feb 2021 22:08:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1612991301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XFYwk+ThwpaIVka92LotS47Rkx7x2jw8LAKSGXHzb78=; b=cmuRuexcXGmSv/QoZDYdQWIhvUwn0LjMg7xHQRyLJWHwAcuxHPhl+QX86d24RscFEIUV2z qI0f7RoENCJaG7R9ezLiQrxdelXWcNe77p0MW+f0wqyGkQOdtgHk+6w7tmidZ1KNFguhOG pt8pjCPYb3D4cjpUSvnjMpHOkaxRkkI= From: Michael Walle To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andrew Lunn , Heiner Kallweit , Russell King , "David S . Miller" , Jakub Kicinski , Michael Walle Subject: [PATCH net-next v3 8/9] net: phy: icplus: add PHY counter for IP101G Date: Wed, 10 Feb 2021 22:08:08 +0100 Message-Id: <20210210210809.30125-9-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210210210809.30125-1-michael@walle.cc> References: <20210210210809.30125-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The IP101G provides three counters: RX packets, CRC errors and symbol errors. The error counters can be configured to clear automatically on read. Unfortunately, this isn't true for the RX packet counter. Because of this and because the RX packet counter is more likely to overflow, than the error counters implement only support for the error counters. Signed-off-by: Michael Walle Reviewed-by: Andrew Lunn --- Changes since v2: - none Changes since v1: - renamed the functions to represend a IP101G-only function - enable the counters in IP101G's config_init() drivers/net/phy/icplus.c | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c index 7e0ef05b1cae..96e9d1d12992 100644 --- a/drivers/net/phy/icplus.c +++ b/drivers/net/phy/icplus.c @@ -51,6 +51,12 @@ MODULE_LICENSE("GPL"); #define IP101G_DEFAULT_PAGE 16 +#define IP101G_P1_CNT_CTRL 17 +#define CNT_CTRL_RX_EN BIT(13) +#define IP101G_P8_CNT_CTRL 17 +#define CNT_CTRL_RDCLR_EN BIT(15) +#define IP101G_CNT_REG 18 + #define IP175C_PHY_ID 0x02430d80 #define IP1001_PHY_ID 0x02430d90 #define IP101A_PHY_ID 0x02430c54 @@ -65,8 +71,19 @@ enum ip101gr_sel_intr32 { IP101GR_SEL_INTR32_RXER, }; +struct ip101g_hw_stat { + const char *name; + int page; +}; + +static struct ip101g_hw_stat ip101g_hw_stats[] = { + { "phy_crc_errors", 1 }, + { "phy_symbol_errors", 11, }, +}; + struct ip101a_g_phy_priv { enum ip101gr_sel_intr32 sel_intr32; + u64 stats[ARRAY_SIZE(ip101g_hw_stats)]; }; static int ip175c_config_init(struct phy_device *phydev) @@ -263,6 +280,20 @@ static int ip101a_config_init(struct phy_device *phydev) static int ip101g_config_init(struct phy_device *phydev) { + int ret; + + /* Enable the PHY counters */ + ret = phy_modify_paged(phydev, 1, IP101G_P1_CNT_CTRL, + CNT_CTRL_RX_EN, CNT_CTRL_RX_EN); + if (ret) + return ret; + + /* Clear error counters on read */ + ret = phy_modify_paged(phydev, 8, IP101G_P8_CNT_CTRL, + CNT_CTRL_RDCLR_EN, CNT_CTRL_RDCLR_EN); + if (ret) + return ret; + return ip101a_g_config_intr_pin(phydev); } @@ -403,6 +434,47 @@ static int ip101g_match_phy_device(struct phy_device *phydev) return ip101a_g_match_phy_device(phydev, false); } +static int ip101g_get_sset_count(struct phy_device *phydev) +{ + return ARRAY_SIZE(ip101g_hw_stats); +} + +static void ip101g_get_strings(struct phy_device *phydev, u8 *data) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ip101g_hw_stats); i++) + strscpy(data + i * ETH_GSTRING_LEN, + ip101g_hw_stats[i].name, ETH_GSTRING_LEN); +} + +static u64 ip101g_get_stat(struct phy_device *phydev, int i) +{ + struct ip101g_hw_stat stat = ip101g_hw_stats[i]; + struct ip101a_g_phy_priv *priv = phydev->priv; + int val; + u64 ret; + + val = phy_read_paged(phydev, stat.page, IP101G_CNT_REG); + if (val < 0) { + ret = U64_MAX; + } else { + priv->stats[i] += val; + ret = priv->stats[i]; + } + + return ret; +} + +static void ip101g_get_stats(struct phy_device *phydev, + struct ethtool_stats *stats, u64 *data) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(ip101g_hw_stats); i++) + data[i] = ip101g_get_stat(phydev, i); +} + static struct phy_driver icplus_driver[] = { { PHY_ID_MATCH_MODEL(IP175C_PHY_ID), @@ -443,6 +515,9 @@ static struct phy_driver icplus_driver[] = { .handle_interrupt = ip101a_g_handle_interrupt, .config_init = ip101g_config_init, .soft_reset = genphy_soft_reset, + .get_sset_count = ip101g_get_sset_count, + .get_strings = ip101g_get_strings, + .get_stats = ip101g_get_stats, .suspend = genphy_suspend, .resume = genphy_resume, } }; -- 2.20.1