From patchwork Fri Aug 30 19:26:06 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: 13785456 X-Patchwork-Delegate: kuba@kernel.org Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3A3B21BF81A for ; Fri, 30 Aug 2024 19:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725046033; cv=none; b=J7phIRj6KNcp3HnxZPeVYl1sDwLCXkFqW9OdhjF4/oiy/MqHPzwQoLPktEtf/j3au5k5jNVx8gAX9Ct9IpMrV4mqwkhhiIKueDPZcCvSXqUvqUi/fNfEB7Prj76vyLAo43BYjdCU/xnh6UBqN8A8o9vpSvQ4xr8uYq5AsCci5K4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725046033; c=relaxed/simple; bh=E348lbl4YjxRw525OqHE19nd+KpH5SOYoX/5CzKjCIs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T8f9TR8ljw6Ls7dOas6jmZK6467K0kx1fVw76A2jF4+LfWmu0Xz+7B6voWfxZbEumAuJi2V6A9KFExbsfXPnkgU2NasxDZoBGbehesv5dP+sgUCOpngLG62sUE298SfOu6RZ5sHV7PZRbb4yHcMvgw77WHLEXLUFJklRbea3o8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de 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 1sk7Gy-0006K2-Se for netdev@vger.kernel.org; Fri, 30 Aug 2024 21:27:04 +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 1sk7Gq-004DpA-Ng for netdev@vger.kernel.org; Fri, 30 Aug 2024 21:26:56 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 5A3C532E23D for ; Fri, 30 Aug 2024 19:26:56 +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 E4CD332E104; Fri, 30 Aug 2024 19:26:46 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id b61f5efc; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:06 +0200 Subject: [PATCH can-next v3 09/20] can: rockchip_canfd: rkcanfd_handle_rx_int_one(): implement workaround for erratum 5: check for empty FIFO Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-9-d426266453fa@pengutronix.de> References: <20240830-rockchip-canfd-v3-0-d426266453fa@pengutronix.de> In-Reply-To: <20240830-rockchip-canfd-v3-0-d426266453fa@pengutronix.de> To: kernel@pengutronix.de, 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=3961; i=mkl@pengutronix.de; h=from:subject:message-id; bh=E348lbl4YjxRw525OqHE19nd+KpH5SOYoX/5CzKjCIs=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzjloGg0f2UNxy13GCu3jaj+LSpm7mkIVe7l IEZGscLCFOJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc4wAKCRAoOKI+ei28 bwBVCACMJJjhVmIxP8iia/ptcUA+kYYM/nIVcgTbAKT21nUJMZbIJfrvMCB4h4m/Int42mdlJIO P5IheSxRNTiOligfmFbAui1Cuq5TSInCDBNi/0Yqux8v9mrPst/rEaFTofUr+daI+sAq+DPmYCP opcM0UrSAotFaYDaUT8hl3Y6mQ45L9xosoveXJUcYQFCCoSZzxxiiF2zl20dl65vTl01Jj1q+42 Vxkj9xu6r/oaQLVapd2oJuj4l4ynimNEiqGY3TYX2zjghfek69QefKbVOIiXXwTCowRDIEAZ/RR SIFsDLRNzCgZdGuabj/bOr+VnvY4mOqjJwC+XhWYsdHawL01 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: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.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. 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)