From patchwork Wed Sep 4 08:12:53 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: 13789995 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 4236ACA0ED3 for ; Wed, 4 Sep 2024 08:32:52 +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=ahFwRYF1L4+bQjekBRLowMqc+VK9Xi7RUsKyCiPwcWI=; b=nfr61otfB8avks 2nw0V0fIYeI6yhtegpbTflf0+FNkHWF5PNN6tsMBw5MTOeu7PMDUAzul0vSVxePqMGOOfxQMIAij7 jZRlItqO4M8qzSwoH5lr1FL2JaaGFZI8FEhP7MoG/ZNY4BYBXMTGDi7NKrWaG2YZn68TxAyrzAQ4d tTdc4EcAb5YI9oJCEVRAUX0GQvqBhWazV+k8Ghm+gDn3TRGlmGOBxlz0hmBJuHLkXqRPJKyIbt6Gr nM4PirxyjOG6Ey4kRwWmpMO584OD2ojMwp+LdXgzANhNlOBZCtFr4AHXIGqyHjZFWJMfyvumVBq+A zN2KOTGksgEZ6v5SOFiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sllRZ-00000003QBU-0nk0; Wed, 04 Sep 2024 08:32:49 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sll9I-00000003KsO-3lcG for linux-rockchip@bombadil.infradead.org; Wed, 04 Sep 2024 08:13:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=4GTsj+/6I+4aRzJauq9YUMpgA1HZJq8pEaLGWrwrm8A=; b=CvT5nIf2RFaIQZSAg2HlQ3NupO F5i8hR+ulRwzSrDLrwIINYSkp3y3alEtIxA6yG8RQPZYVIcNjz7dGj5tg3me3DmZySX36KlRmqiTh Y8sOt/dkCVCzqIUYOefNjm9V8MqPQTgGevmpYp+KjpFIc/l6g7aIKomGZLyKLSAv4dKgfV2O5KWiR K5XyUCd/dQ2pO35o8C6Tsuyu1hkK4Qh543BeebVs42KZ0lXSQLJTfCXd0bIZyn+Fk+H4B+sEyjkyx d3i6xfA5PEOuf2PeP32h9lXsQ4cHIQ/R89P5iE7jNZSXbPsSTKu3a16fnUgukUtyri1RNkUUwFkoV xTAHwmgQ==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sll94-00000000Al0-0CJz for linux-rockchip@lists.infradead.org; Wed, 04 Sep 2024 08:13:46 +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 1sll8y-0007dM-Li for linux-rockchip@lists.infradead.org; Wed, 04 Sep 2024 10:13:36 +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 1sll8s-005OsR-L7 for linux-rockchip@lists.infradead.org; Wed, 04 Sep 2024 10:13:30 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 2389A332031 for ; Wed, 04 Sep 2024 08:13:30 +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 A0714331F63; Wed, 04 Sep 2024 08:13:22 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id ffdfeab7; Wed, 4 Sep 2024 08:13:20 +0000 (UTC) From: Marc Kleine-Budde Date: Wed, 04 Sep 2024 10:12:53 +0200 Subject: [PATCH can-next v5 09/20] can: rockchip_canfd: rkcanfd_handle_rx_int_one(): implement workaround for erratum 5: check for empty FIFO MIME-Version: 1.0 Message-Id: <20240904-rockchip-canfd-v5-9-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=4011; i=mkl@pengutronix.de; h=from:subject:message-id; bh=gTvq7gHTXf9S/cqPeCfVe7J+meaf29zJX+AvP7bOZn8=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm2BaPeIrctjvtuUXSNHX0rSrSlIEBYZOETZXt1 lLz7HKt4zaJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtgWjwAKCRAoOKI+ei28 b6rkB/9vXJFKAya63M40ICu1SrKQooaTP3GWEI/RpH/tvQoBuUsR+GJNynz5Yvjarh4SXZZ4MNl MTNGp84YPOR1wvZy9GL4sHzGSGecx8oK7Xm8yTH5s2zKP5IgrsU7uEvwwd9wNFVCttKPV/u5tsM uuEL0oBYboZUOyiHUi66MUBnuD51rV+c/ME/2Djt7T2+r1tlHrTlsamFEOwt02GlMYc2nWpzHXI Ok6fDC/TDxYRz/VjVsWoX4wcoC/3G/TfMB1rlDg6tBexWhhzXA3p0AI5HVVGTpNFV1tg08xWry0 pctZeBACTze1KHocrIhyvyGRONtGJ6naZZ5z5eeSLMYJ3rGh 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_091342_469099_515A641F X-CRM114-Status: GOOD ( 19.35 ) 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 rk3568 CAN-FD errata sheet as of Tue 07 Nov 2023 11:25:31 +08:00 says: | Erratum 5: Counters related to the TXFIFO and RXFIFO exhibit | abnormal counting behavior. | | Due to a bug in the cross-asynchronous logic of the enable signals | for rx_fifo_cnt and txe_fifo_frame_cnt counters, the counts of these | two counters become inaccurate. This issue has resulted in the | inability to use the TXFIFO and RXFIFO functions. The errata sheet mentioned above states that only the rk3568v2 is affected by this erratum, but tests with the rk3568v2 and rk3568v3 show that the RX_FIFO_CNT is sometimes too high. This leads to CAN frames being read from the FIFO, which is then already empty. Further tests on the rk3568v2 and rk3568v3 show that in this situation (i.e. empty FIFO) all elements of the FIFO header (frameinfo, id, ts) contain the same data. On the rk3568v2 and rk3568v3, this problem only occurs extremely rarely with the standard clock of 300 MHz, but almost immediately at 80 MHz. To workaround this problem, check for empty FIFO with rkcanfd_fifo_header_empty() in rkcanfd_handle_rx_int_one() and exit early. Tested-by: Alibek Omarov Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-rx.c | 14 ++++++++++++++ drivers/net/can/rockchip/rockchip_canfd.h | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index 5398aff0d180..609282359bca 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -47,6 +47,16 @@ rkcanfd_fifo_header_to_cfd_header(const struct rkcanfd_priv *priv, return len + cfd->len; } +static inline bool +rkcanfd_fifo_header_empty(const struct rkcanfd_fifo_header *header) +{ + /* Erratum 5: If the FIFO is empty, we read the same value for + * all elements. + */ + return header->frameinfo == header->id && + header->frameinfo == header->ts; +} + static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) { struct net_device_stats *stats = &priv->ndev->stats; @@ -63,6 +73,10 @@ static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) rkcanfd_read_rep(priv, RKCANFD_REG_RX_FIFO_RDATA, cfd->data, sizeof(cfd->data)); + /* Erratum 5: Counters for TXEFIFO and RXFIFO may be wrong */ + if (rkcanfd_fifo_header_empty(header)) + return 0; + len = rkcanfd_fifo_header_to_cfd_header(priv, header, cfd); /* Drop any received CAN-FD frames if CAN-FD mode is not diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 3dafb5e68dc5..c775e75a2740 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -315,6 +315,28 @@ /* Erratum 5: Counters related to the TXFIFO and RXFIFO exhibit * abnormal counting behavior. + * + * The rk3568 CAN-FD errata sheet as of Tue 07 Nov 2023 11:25:31 +08:00 + * states that only the rk3568v2 is affected by this erratum, but + * tests with the rk3568v2 and rk3568v3 show that the RX_FIFO_CNT is + * sometimes too high. This leads to CAN frames being read from the + * FIFO, which is then already empty. + * + * Further tests on the rk3568v2 and rk3568v3 show that in this + * situation (i.e. empty FIFO) all elements of the FIFO header + * (frameinfo, id, ts) contain the same data. + * + * On the rk3568v2 and rk3568v3, this problem only occurs extremely + * rarely with the standard clock of 300 MHz, but almost immediately + * at 80 MHz. + * + * To workaround this problem, check for empty FIFO with + * rkcanfd_fifo_header_empty() in rkcanfd_handle_rx_int_one() and exit + * early. + * + * To reproduce: + * assigned-clocks = <&cru CLK_CANx>; + * assigned-clock-rates = <80000000>; */ #define RKCANFD_QUIRK_RK3568_ERRATUM_5 BIT(4)