From patchwork Wed Sep 4 08:12:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Kleine-Budde X-Patchwork-Id: 13789982 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A850DCA0ED3 for ; Wed, 4 Sep 2024 08:28:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=uoGCEtsOkOYhhzbUWzF1vApl+tjn0B/txy4Hfg4XwjM=; b=jin7CCF2HUgDuK +CCH6e3qAK0bajoHw6Wkzoqcha1a3HUCwJoT4EYEZR2Cd/JfSW1PQcq9vnphiW0l72Vexev/FANF2 3alBXhf9OgORKhLnHHaApm4VucrGaqPAFwZYHTLBOehUjtS9nDPnJgw5vXkY7u/O6RyU7jO2q8Dy7 uGZi3hSceCgP6XKItJe6Cxpnkbx1BkGHyvPhi36pAk93Ql2bL7buBKniZvlm9I2v3g9w+7JzCUDiy E1UzRnaC7vzJpfX4t/QDSGE8hqZH3tiP5G3kLwZY5CTwc24pp2WXKOXMG6IV9Hv3u+UiHgQadM3VR 73Df8HyCyi6e1De4rAbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllNi-00000003P8w-1sGr; Wed, 04 Sep 2024 08:28:50 +0000 Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sll99-00000003KmR-3rp4 for linux-rockchip@lists.infradead.org; Wed, 04 Sep 2024 08:13:51 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sll97-0007xN-IB for linux-rockchip@lists.infradead.org; Wed, 04 Sep 2024 10:13:45 +0200 Received: from [2a0a:edc0:0:b01:1d::7b] (helo=bjornoya.blackshift.org) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sll8x-005P1U-VD for linux-rockchip@lists.infradead.org; Wed, 04 Sep 2024 10:13:36 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 921E73320E7 for ; Wed, 04 Sep 2024 08:13:35 +0000 (UTC) Received: from hardanger.blackshift.org (unknown [172.20.34.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by bjornoya.blackshift.org (Postfix) with ESMTPS id 59ECB331F77; Wed, 04 Sep 2024 08:13:23 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id 4978443d; Wed, 4 Sep 2024 08:13:20 +0000 (UTC) From: Marc Kleine-Budde Date: Wed, 04 Sep 2024 10:12:59 +0200 Subject: [PATCH can-next v5 15/20] can: rockchip_canfd: add stats support for errata workarounds MIME-Version: 1.0 Message-Id: <20240904-rockchip-canfd-v5-15-8ae22bcb27cc@pengutronix.de> References: <20240904-rockchip-canfd-v5-0-8ae22bcb27cc@pengutronix.de> In-Reply-To: <20240904-rockchip-canfd-v5-0-8ae22bcb27cc@pengutronix.de> To: kernel@pengutronix.de, Alibek Omarov , Vincent Mailhol , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Philipp Zabel , Elaine Zhang , David Jander Cc: Simon Horman , linux-can@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Kleine-Budde X-Mailer: b4 0.15-dev-99b12 X-Developer-Signature: v=1; a=openpgp-sha256; l=6752; i=mkl@pengutronix.de; h=from:subject:message-id; bh=M8RAQjNTeDBT8nZWTnxb7Ws+IsIfE4vLrIdAxoZeDu8=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm2BaXLZVwNdcefenDwTZjvua2vQCINkO6y79v1 cIb3MgOhLaJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtgWlwAKCRAoOKI+ei28 b0rkB/9MqObIn0VWIrq7t7WWz2vr1jnxjSfWsxGHe7u7pPhAOh/abVBCgRrPRUVFVa4FhvRECLD tyQhV65FMFudcmFGNwtywZSextTczzzH7+B1VJKJfQckFpLxhwtkqCIsAd7GvxuuzrLWtSN3rGs NBrOfvj0sAZkYrG+mIRsMTYhbkA+eueSdZvV2o1ibNLReqkrPQE+Evha9zSmfYAiqlM1YKw+8sp BOEfzUS6WVYeP9lGoAmqKdz+yowEdSM1fTAKU+vTrMo0t0pzFI94pqpaOFMmmXexAZHzOOrYD3S zsukV19InKs6XFI9FbcuM5LIlnHdwAXOYftVmPRar5fsrj6h X-Developer-Key: i=mkl@pengutronix.de; a=openpgp; fpr=C1400BA0B3989E6FBC7D5B5C2B5EE211C58AEA54 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_011348_127429_40351DBB X-CRM114-Status: GOOD ( 22.68 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org The driver contains workarounds for some of the rk3568v2 errata. Add ethtool-based statistics ("ethtool -S") to track how often an erratum workaround was needed. Tested-by: Alibek Omarov Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/Makefile | 1 + drivers/net/can/rockchip/rockchip_canfd-core.c | 2 + drivers/net/can/rockchip/rockchip_canfd-ethtool.c | 73 +++++++++++++++++++++++ drivers/net/can/rockchip/rockchip_canfd-rx.c | 13 +++- drivers/net/can/rockchip/rockchip_canfd.h | 14 +++++ 5 files changed, 102 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/rockchip/Makefile b/drivers/net/can/rockchip/Makefile index 4eb7c50d8d5b..3760d3e1baa3 100644 --- a/drivers/net/can/rockchip/Makefile +++ b/drivers/net/can/rockchip/Makefile @@ -4,6 +4,7 @@ obj-$(CONFIG_CAN_ROCKCHIP_CANFD) += rockchip_canfd.o rockchip_canfd-objs := rockchip_canfd-objs += rockchip_canfd-core.o +rockchip_canfd-objs += rockchip_canfd-ethtool.o rockchip_canfd-objs += rockchip_canfd-rx.o rockchip_canfd-objs += rockchip_canfd-timestamp.o rockchip_canfd-objs += rockchip_canfd-tx.o diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index cf176180a282..4db552bfc4db 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -800,6 +800,8 @@ static int rkcanfd_register(struct rkcanfd_priv *priv) if (err) goto out_pm_runtime_disable; + rkcanfd_ethtool_init(priv); + err = register_candev(ndev); if (err) goto out_pm_runtime_put_sync; diff --git a/drivers/net/can/rockchip/rockchip_canfd-ethtool.c b/drivers/net/can/rockchip/rockchip_canfd-ethtool.c new file mode 100644 index 000000000000..0084f37b2b9f --- /dev/null +++ b/drivers/net/can/rockchip/rockchip_canfd-ethtool.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2023, 2024 Pengutronix, +// Marc Kleine-Budde +// + +#include + +#include "rockchip_canfd.h" + +enum rkcanfd_stats_type { + RKCANFD_STATS_TYPE_RX_FIFO_EMPTY_ERRORS, + RKCANFD_STATS_TYPE_TX_EXTENDED_AS_STANDARD_ERRORS, +}; + +static const char rkcanfd_stats_strings[][ETH_GSTRING_LEN] = { + [RKCANFD_STATS_TYPE_RX_FIFO_EMPTY_ERRORS] = "rx_fifo_empty_errors", + [RKCANFD_STATS_TYPE_TX_EXTENDED_AS_STANDARD_ERRORS] = "tx_extended_as_standard_errors", +}; + +static void +rkcanfd_ethtool_get_strings(struct net_device *ndev, u32 stringset, u8 *buf) +{ + switch (stringset) { + case ETH_SS_STATS: + memcpy(buf, rkcanfd_stats_strings, + sizeof(rkcanfd_stats_strings)); + } +} + +static int rkcanfd_ethtool_get_sset_count(struct net_device *netdev, int sset) +{ + switch (sset) { + case ETH_SS_STATS: + return ARRAY_SIZE(rkcanfd_stats_strings); + default: + return -EOPNOTSUPP; + } +} + +static void +rkcanfd_ethtool_get_ethtool_stats(struct net_device *ndev, + struct ethtool_stats *stats, u64 *data) +{ + struct rkcanfd_priv *priv = netdev_priv(ndev); + struct rkcanfd_stats *rkcanfd_stats; + unsigned int start; + + rkcanfd_stats = &priv->stats; + + do { + start = u64_stats_fetch_begin(&rkcanfd_stats->syncp); + + data[RKCANFD_STATS_TYPE_RX_FIFO_EMPTY_ERRORS] = + u64_stats_read(&rkcanfd_stats->rx_fifo_empty_errors); + data[RKCANFD_STATS_TYPE_TX_EXTENDED_AS_STANDARD_ERRORS] = + u64_stats_read(&rkcanfd_stats->tx_extended_as_standard_errors); + } while (u64_stats_fetch_retry(&rkcanfd_stats->syncp, start)); +} + +static const struct ethtool_ops rkcanfd_ethtool_ops = { + .get_ts_info = ethtool_op_get_ts_info, + .get_strings = rkcanfd_ethtool_get_strings, + .get_sset_count = rkcanfd_ethtool_get_sset_count, + .get_ethtool_stats = rkcanfd_ethtool_get_ethtool_stats, +}; + +void rkcanfd_ethtool_init(struct rkcanfd_priv *priv) +{ + priv->ndev->ethtool_ops = &rkcanfd_ethtool_ops; + + u64_stats_init(&priv->stats.syncp); +} diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index eff08948840c..9f72483dab18 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -96,6 +96,7 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv, bool *tx_done) { struct net_device_stats *stats = &priv->ndev->stats; + struct rkcanfd_stats *rkcanfd_stats = &priv->stats; const struct canfd_frame *cfd_nominal; const struct sk_buff *skb; unsigned int tx_tail; @@ -166,6 +167,9 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv, return 0; /* Affected by Erratum 6 */ + u64_stats_update_begin(&rkcanfd_stats->syncp); + u64_stats_inc(&rkcanfd_stats->tx_extended_as_standard_errors); + u64_stats_update_end(&rkcanfd_stats->syncp); /* Manual handling of CAN Bus Error counters. See * rkcanfd_get_corrected_berr_counter() for detailed @@ -211,8 +215,15 @@ static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) cfd->data, sizeof(cfd->data)); /* Erratum 5: Counters for TXEFIFO and RXFIFO may be wrong */ - if (rkcanfd_fifo_header_empty(header)) + if (rkcanfd_fifo_header_empty(header)) { + struct rkcanfd_stats *rkcanfd_stats = &priv->stats; + + u64_stats_update_begin(&rkcanfd_stats->syncp); + u64_stats_inc(&rkcanfd_stats->rx_fifo_empty_errors); + u64_stats_update_end(&rkcanfd_stats->syncp); + return 0; + } len = rkcanfd_fifo_header_to_cfd_header(priv, header, cfd); diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 67f135fbcfb9..f24a1d18be66 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -446,6 +446,16 @@ struct rkcanfd_fifo_header { u32 ts; }; +struct rkcanfd_stats { + struct u64_stats_sync syncp; + + /* Erratum 5 */ + u64_stats_t rx_fifo_empty_errors; + + /* Erratum 6 */ + u64_stats_t tx_extended_as_standard_errors; +}; + struct rkcanfd_priv { struct can_priv can; struct can_rx_offload offload; @@ -461,6 +471,8 @@ struct rkcanfd_priv { struct can_berr_counter bec; + struct rkcanfd_stats stats; + struct reset_control *reset; struct clk_bulk_data *clks; int clks_num; @@ -515,6 +527,8 @@ rkcanfd_get_tx_free(const struct rkcanfd_priv *priv) return RKCANFD_TXFIFO_DEPTH - rkcanfd_get_tx_pending(priv); } +void rkcanfd_ethtool_init(struct rkcanfd_priv *priv); + int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv); void rkcanfd_timestamp_init(struct rkcanfd_priv *priv);