From patchwork Fri Aug 30 19:25:58 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: 13785468 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 73F4DCA100C for ; Fri, 30 Aug 2024 19:28:00 +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=O3bIyyrIGVJbs2h/geuJMDH2d8pwpqeN07OEGGlY8yI=; b=v1SsK05uBh2Tyc jftHmHrerVV5TVxotWMqd+2sfD8Ep6LXTLLQSyqYdCUcd3x00RDVV1KqrRkWuC9L5uzyehBfrri7U wbySKKFogWDA+SzmD1udpiWnnOdIG/ixDvF5adxC15UMSK8th6c3GgYjZFK6W3mRFx14D7xXUnwHH FaB10psTKqWfZAh0SmoaSzNiL4qsHANRYM2ZO5DqB7iMYxtHtcfyi3ObRDLx5v897WtmkEUFf+OaQ PuY6TNH3epUc9+V6nATGI+MKCMEMmK5hsiJWKh0NY1V0Op1iDnwFz+QjrXxJTWtK5c32oI8coHaz5 cl86CpiW4qdccYtQ5UEA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Hn-00000007Ru6-0XEv; Fri, 30 Aug 2024 19:27:55 +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 1sk7Gn-00000007RLt-2rGY for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:26:57 +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 1sk7Gj-000644-FH for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:49 +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 1sk7Gi-004Dbw-HD for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:48 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 3939A32E12A for ; Fri, 30 Aug 2024 19:26:48 +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 E9ED232E0EE; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id 06327bef; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:25:58 +0200 Subject: [PATCH can-next v3 01/20] dt-bindings: can: rockchip_canfd: add rockchip CAN-FD controller MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-1-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=2962; i=mkl@pengutronix.de; h=from:subject:message-id; bh=ZqYWMtyrGWI+DE0ip880R/3MA9gTBkSpAwRLmioirEI=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzX6+Nn8nhElPP2Q042ZgQTmKKPk6r8mCLry x96UlbW6TyJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc1wAKCRAoOKI+ei28 b7GeB/wJNwTHxmEwZ8UOuRl0GaCTPzH+/C/ubbvie6+fmfM8EQzNGCINpnOG6hwhrnFKb202wNw 39Q54Awy2+NTdVYlWMl2la1PZ28jSOpZuoGtZOFE65k1hDm8znxQrtiCa8Zl+rAH5oKcXHoeX0b 1HcU7LNE5JAzTaQ6cyHS2YklF0egzGlvuAXldoOm50Yj4vuvKACHBykgSH1xyndGM0nTXyzP3VK /lk1AYLm1EmA8V5iR9b3WZ4C2T6YdnZooJ7Z2AswZXRshsAyi1yoSrySZbZPAI9lDmHYQVPRE2P DQ95cBHv05L+fiVvV+3rXL92pbejaHkXDspGbn72QtuSZVyS 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-20240830_122653_748642_687EF838 X-CRM114-Status: GOOD ( 13.46 ) 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 Add documentation for the rockchip rk3568 CAN-FD controller. Co-developed-by: Elaine Zhang Signed-off-by: Elaine Zhang Signed-off-by: Marc Kleine-Budde --- .../bindings/net/can/rockchip,rk3568-canfd.yaml | 74 ++++++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 81 insertions(+) diff --git a/Documentation/devicetree/bindings/net/can/rockchip,rk3568-canfd.yaml b/Documentation/devicetree/bindings/net/can/rockchip,rk3568-canfd.yaml new file mode 100644 index 000000000000..022ae799b0cc --- /dev/null +++ b/Documentation/devicetree/bindings/net/can/rockchip,rk3568-canfd.yaml @@ -0,0 +1,74 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/can/rockchip,canfd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: + Rockchip CAN-FD controller + +maintainers: + - Marc Kleine-Budde + +allOf: + - $ref: can-controller.yaml# + +properties: + compatible: + oneOf: + - const: rockchip,rk3568v2-canfd + - items: + - const: rockchip,rk3568v3-canfd + - const: rockchip,rk3568v2-canfd + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 2 + + clock-names: + items: + - const: baud + - const: pclk + + resets: + maxItems: 2 + + reset-names: + items: + - const: core + - const: apb + +required: + - compatible + - reg + - interrupts + - clocks + - resets + +additionalProperties: false + +examples: + - | + #include + #include + #include + + soc { + #address-cells = <2>; + #size-cells = <2>; + + can@fe570000 { + compatible = "rockchip,rk3568v2-canfd"; + reg = <0x0 0xfe570000 0x0 0x1000>; + interrupts = ; + clocks = <&cru CLK_CAN0>, <&cru PCLK_CAN0>; + clock-names = "baud", "pclk"; + resets = <&cru SRST_CAN0>, <&cru SRST_P_CAN0>; + reset-names = "core", "apb"; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index baf88e74c907..115307354f0b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19730,6 +19730,13 @@ F: Documentation/ABI/*/sysfs-driver-hid-roccat* F: drivers/hid/hid-roccat* F: include/linux/hid-roccat* +ROCKCHIP CAN-FD DRIVER +M: Marc Kleine-Budde +R: kernel@pengutronix.de +L: linux-can@vger.kernel.org +S: Maintained +F: Documentation/devicetree/bindings/net/can/rockchip,rk3568-canfd.yaml + ROCKCHIP CRYPTO DRIVERS M: Corentin Labbe L: linux-crypto@vger.kernel.org From patchwork Fri Aug 30 19:25: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: 13785491 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 CE0F2CA0FE8 for ; Fri, 30 Aug 2024 19:40:21 +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=2/ru/Pi9VNY1i2EfH2S1E6shF56Tn+M5Cz7oqPq2gHw=; b=dDfGdVUUI/Zo1K gFENcX40teWIE4/huT2m8wfiJhQ6RfUeDVS3yhNyUAFG+Wla9Ew9Q9ndwxkdHr0Y4OooLLgAglcfo xI2ioxuI56maoSAaL+irTn67wlbBnGWaqpSFFSN6EkOAYYR5h3wPm5QjNoYDXGWMNJu6XgdkMGaRF pUrd8AdGJXS/u5b/POJzRbt3nswPgx57CXzucnPhbP5lh1pIyoSMwCXs6rwhXbbahlvDpSbDlHhHs N+YJq0za+sg3FC99tTDm6HEdB92I0xULvNxqjDD/mY0pRqckMJK2Hnfv9816Doq7/NoLm4NqiCbb4 oCFck68rdN3gefoGeoeg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Tm-00000007VUv-2LxU; Fri, 30 Aug 2024 19:40:18 +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 1sk7HK-00000007Rbg-1YAN for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:26 +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=k3/Rv0l9/1nizDIHR4fIB/wwDyXy6KWWy6aIsll9qIo=; b=UAw1bVTKAnxl+tLipK7zsAkNvE edq6c2auTzlWwTHAFkjwgzQGlrYzhY0a0IlFzdK2sxCWhtBhFTYblHWAvaaxxPPase5O0d22LDy/5 CvIuLYBeHti3+ZCYhP7FhHGpM++N+Ntpo/TGKXKzvdfoSQgP3/mwFu1tex8OCmbgLtZYkqH6jwF21 mDwf5j1SnFKBlr2mTReJackm55TOG6PbpM57KjcSWj3ozj5GZSrQp8Kwt0re28TMqEVRlg95QmloG nkuL2Ua/4YxryQv08GPiGNCNDvfwyZQHZU7nfxx13iQ7dat5A4iMUGYY8KLYDoEpkBo47F64hPooB HD6YFnRw==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H1-0000000Bk8h-0Bjo for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:16 +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 1sk7Gk-00064E-0z for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:50 +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 1sk7Gi-004Dc1-KP for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:48 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 43F5D32E12B for ; Fri, 30 Aug 2024 19:26:48 +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 18AF132E0EF; 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 a3fe34c3; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:25:59 +0200 Subject: [PATCH can-next v3 02/20] arm64: dts: rockchip: add CAN-FD controller nodes to rk3568 MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-2-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 , David Jander X-Mailer: b4 0.15-dev-99b12 X-Developer-Signature: v=1; a=openpgp-sha256; l=2004; i=mkl@pengutronix.de; h=from:subject:message-id; bh=hsRqfgdlLKDhtXJmoP6WFcH3+AxgGwl/ZeSBxntK4ss=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzZlcMMB9MmqDH2wzfEbm7tio2J3Zd9tJqhD EkKfkAOYqKJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc2QAKCRAoOKI+ei28 b3DlB/9omU/3gf7SfVCIev3i0XhU3s95dm/ZkAXX4q1HpoUSzJhjRr5x5iyDcuV+7Ec4s4vqzwk yK4qvRjhuCDSFoLSrGkK3BE5FH3ieW3MUf+f+MaQPwOvodW/qJSSSQoZKY0ni6gZkrhNShF34hB 77WHBYyFo+lgpEiTA3gERb+9rFcmLx7HQj6eXHp5Pu3Er3UjWDJ6+pwJ+uidlP9sjv2rpt7rsaw LYa35GOcHM/nW+rLj/zHR0JKaiXGiHO39ves7PkhTo/xU2DFZsr/n6yla9CIDRXn33Qy5aZdDVB QEfSmzWqa5s+InWtU5fOvEXrGm4VZLJsZxzNzOz7aqP2hHhU 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-20240830_202713_296041_D03E3229 X-CRM114-Status: GOOD ( 11.02 ) 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 From: David Jander Add nodes to the rk3568 devicetree to support the CAN-FD controllers. Signed-off-by: David Jander Signed-off-by: Marc Kleine-Budde --- arch/arm64/boot/dts/rockchip/rk3568.dtsi | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/arch/arm64/boot/dts/rockchip/rk3568.dtsi b/arch/arm64/boot/dts/rockchip/rk3568.dtsi index f1be76a54ceb..70847556627d 100644 --- a/arch/arm64/boot/dts/rockchip/rk3568.dtsi +++ b/arch/arm64/boot/dts/rockchip/rk3568.dtsi @@ -213,6 +213,45 @@ gmac0_mtl_tx_setup: tx-queues-config { }; }; + can0: can@fe570000 { + compatible = "rockchip,rk3568v2-canfd"; + reg = <0x0 0xfe570000 0x0 0x1000>; + interrupts = ; + clocks = <&cru CLK_CAN0>, <&cru PCLK_CAN0>; + clock-names = "baud", "pclk"; + resets = <&cru SRST_CAN0>, <&cru SRST_P_CAN0>; + reset-names = "core", "apb"; + pinctrl-names = "default"; + pinctrl-0 = <&can0m0_pins>; + status = "disabled"; + }; + + can1: can@fe580000 { + compatible = "rockchip,rk3568v2-canfd"; + reg = <0x0 0xfe580000 0x0 0x1000>; + interrupts = ; + clocks = <&cru CLK_CAN1>, <&cru PCLK_CAN1>; + clock-names = "baud", "pclk"; + resets = <&cru SRST_CAN1>, <&cru SRST_P_CAN1>; + reset-names = "core", "apb"; + pinctrl-names = "default"; + pinctrl-0 = <&can1m0_pins>; + status = "disabled"; + }; + + can2: can@fe590000 { + compatible = "rockchip,rk3568v2-canfd"; + reg = <0x0 0xfe590000 0x0 0x1000>; + interrupts = ; + clocks = <&cru CLK_CAN2>, <&cru PCLK_CAN2>; + clock-names = "baud", "pclk"; + resets = <&cru SRST_CAN2>, <&cru SRST_P_CAN2>; + reset-names = "core", "apb"; + pinctrl-names = "default"; + pinctrl-0 = <&can2m0_pins>; + status = "disabled"; + }; + combphy0: phy@fe820000 { compatible = "rockchip,rk3568-naneng-combphy"; reg = <0x0 0xfe820000 0x0 0x100>; From patchwork Fri Aug 30 19:26:00 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: 13785467 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 9340ECA1009 for ; Fri, 30 Aug 2024 19:27:59 +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=0Wow6CZCkQpwhgslKTh+svbWt3SX1heQndsjwzwoQ+A=; b=ayASNBuTS1YHM8 BquMdPgTv9OAdehHior+ETY5bXdFPDWJ+RuGWG0NWW3X/J2wlivKGY+AZrIdzD4vhUNjy5ZckiwC0 bNf/YdWWkAii+YMK/a/x2fXQfwbZ2SY2KKnkgYyKF9LGPtYbf5zOObUosBeyRO1J0IT227E2PtaDR tQ+Mon/2PYRml1coXbs5EHhRwdcOJWT9RyJ0AsZTnN9m+o0mKCj9iRgSOkSyb80yyP54BU9dc7Irq 9Z7K2Dngllaf9208wNdf29oFFSfRKV1+wSOwDcV/4diadyqJElCn4j8C+86J4pPi6GaBpa/pKxeIo j4JK37COsw1AyHwwfPhg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Hm-00000007RtA-2i7z; Fri, 30 Aug 2024 19:27:54 +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 1sk7Gn-00000007RLu-3jOp for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:26:57 +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 1sk7Gj-00064L-K0 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:49 +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 1sk7Gi-004DcE-OB for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:48 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 6DC5132E12E for ; Fri, 30 Aug 2024 19:26:48 +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 39E2132E0F1; 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 92190dc0; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:00 +0200 Subject: [PATCH can-next v3 03/20] arm64: dts: rockchip: mecsbc: add CAN0 and CAN1 interfaces MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-3-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 , David Jander X-Mailer: b4 0.15-dev-99b12 X-Developer-Signature: v=1; a=openpgp-sha256; l=1124; i=mkl@pengutronix.de; h=from:subject:message-id; bh=eUdsJQc+V4w0oQE9pU47g8jWlMZiCB8g32l6Vl5i0Vw=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzaPgDZvy5tM0I9QrC/kgwEQOzCUMJavOH96 K6i1vgtUI6JATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc2gAKCRAoOKI+ei28 byNuB/0RbxECsQ6hUWgv9/j89foy4wDxtOZjs5LPx7skZ0rBMDYISXj/spqyVFUvgDSzkNHEy5Y SkbTBnQkLfgouwSN4dDXssgFGx7w74XzM2uo7npm5XqDTskHh4wpCy9j86Y2nQci9K2MZE9YDj/ s/8S79OPeT+Pug1YBH1mUfCX34J3m1SNWVNvBYtayNvNv+OaxkgkVNue9i8BdzkCZU3vqheyLeL 5fwNQmlVvegwH3PaARcr/fC4xEvJrLnaocoC1exnWN5LxpKCG7mIwhQ4Z49Hx0VKcAZ/xreOn1a g9EAj300J0BXMGg3luXdNtRjF27KPGrYQNm8yK5+z4/dO+Xv 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-20240830_122653_965226_3D29EA2D X-CRM114-Status: GOOD ( 11.54 ) 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 From: David Jander This patch adds support for the CAN0 and CAN1 interfaces to the board. Signed-off-by: David Jander Signed-off-by: Marc Kleine-Budde --- arch/arm64/boot/dts/rockchip/rk3568-mecsbc.dts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm64/boot/dts/rockchip/rk3568-mecsbc.dts b/arch/arm64/boot/dts/rockchip/rk3568-mecsbc.dts index c2dfffc638d1..052ef03694cf 100644 --- a/arch/arm64/boot/dts/rockchip/rk3568-mecsbc.dts +++ b/arch/arm64/boot/dts/rockchip/rk3568-mecsbc.dts @@ -117,6 +117,20 @@ &cpu3 { cpu-supply = <&vdd_cpu>; }; +&can0 { + compatible = "rockchip,rk3568v3-canfd", "rockchip,rk3568v2-canfd"; + pinctrl-names = "default"; + pinctrl-0 = <&can0m0_pins>; + status = "okay"; +}; + +&can1 { + compatible = "rockchip,rk3568v3-canfd", "rockchip,rk3568v2-canfd"; + pinctrl-names = "default"; + pinctrl-0 = <&can1m1_pins>; + status = "okay"; +}; + &gmac1 { assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>; assigned-clock-parents = <&cru SCLK_GMAC1_RGMII_SPEED>, <&cru CLK_MAC1_2TOP>; From patchwork Fri Aug 30 19:26:01 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: 13785508 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 EBD4CCA1009 for ; Fri, 30 Aug 2024 19:43: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=C+z2ay73CHFl4o1F0t9ZXqcgjBcNtfWKrQQpZO5OvEU=; b=xL+jWN4dC6WHdw xhhRk/55fXF/hAgGT1ddZNPJAbp+Wzj13zMsNaf7ySxoqphxgfAgvJv8gRMEoyLCWJSoqKwk5uGZ6 10djVGqAKJe58KWL6qESx4iinNuPo+h69x7OYDfojkqHqeZ0cF8lLM4MNCLuNFW2ORN/X/jA78ZEz 7iQ3vzSqjn6j4Kyz3/uGIgPLESBwxcl56dFcu890JajnnK92xtELkPtbe1hCOQTPmCkswbEERSNxB r6YjGzE0NUnz5nwOiJI1EyQg1D0DpRsaEob+tyLi+eNgyPH91fbwrNIBcGyMtS8tEVWL0zfuUV5qH GD6QXIypmooh2s1Ny+Mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7XA-00000007WAT-2NbF; Fri, 30 Aug 2024 19:43:48 +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 1sk7Hc-00000007RnB-3cHK for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:45 +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=AwsXRCGXxHkAN8PDhMI0RwzDMyVEGDGiwAXQAIaqNPY=; b=P80wsJ1aTIEmNzB9h8Fe7Pp8Ht uheQ8bmNayvr18EoW7fmxcKKk4KUQpDqz325+ORQUMx2J6oeUsC4N9efKNbKxrjUA7oLRQSO7O6uK RRtrgkZEEZAgtWTTaZlBvnXaJxRpO1rCg63GB7hnfx8oF4s/cpGvkfxKNXNuNKgFYEvfKj8V8p6ph Mxi8jMB6O9be3sQsFX4KuGZi40DcRrTJMDXCkKpO7GZRvdKOGgUUuzaA2CAQ6TGw+v4kcd3iaQsDj 4fbf1r2TTsij7VtzmnNA8+MaP9xo9nNoNdF8tU4oPGeHhIBgo5UEphkg+zE3dpymK9qQc5bCyZzDP pJAdqMzQ==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H3-0000000Bk8g-1Pot for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:27 +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 1sk7Gj-00064f-Tg for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:49 +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 1sk7Gi-004DcM-SG for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:48 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 8684D32E131 for ; Fri, 30 Aug 2024 19:26:48 +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 5911332E0F3; 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 22516864; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:01 +0200 Subject: [PATCH can-next v3 04/20] can: rockchip_canfd: add driver for Rockchip CAN-FD controller MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-4-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=46574; i=mkl@pengutronix.de; h=from:subject:message-id; bh=Z2/rSBVvCjbhxs0pYxeQVcBmduuXSD43SrG/Ct/eh88=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzcZsHEbCzo6vUi6GhX3k74z9sXHKkbRZhuQ QfQraiRJN6JATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc3AAKCRAoOKI+ei28 byKQB/9vqQBqFoLtTb8CWBfVhTb3vIE5+ojGTKublEM1B/K4qaIkOLg3aUMBnbRaWsZnhI5IOF0 Z836LoKBoxQijJtTB5/wGrnYh0Ut7OMj7ytb3LsLDlDlJfV5a3+BPE4M9/VA4K27MtRG6WslPrI VEEmfp3sjmrXKOS4AEWiOAxUVoMaD/r1/YrjIr2leKuv3/vLR/syqbTxW0DPmlQJvVBPXphCK1p b5LH5Eg2r0+f2R1LdoI29mVtOEX0ozTed376a3PEqhO8ZSHqzanJ5EoK1g7kSeaxq1+oXGUJX7k 7IloX3TZ0X6a8+3A1A7zHQJu/FbEQnytevGYUhCJ/3aI5kFd 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-20240830_202719_216229_1CC5CFB0 X-CRM114-Status: GOOD ( 23.26 ) 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 Add driver for the Rockchip CAN-FD controller. The IP core on the rk3568v2 SoC has 12 documented errata. Corrections for these errata will be added in the upcoming patches. Since several workarounds are required for the TX path, only add the base driver that only implements the RX path. Although the RX path implements CAN-FD support, it's not activated in ctrlmode_supported, as the IP core in the rk3568v2 has problems with receiving or sending certain CAN-FD frames. Signed-off-by: Marc Kleine-Budde --- MAINTAINERS | 1 + drivers/net/can/Kconfig | 1 + drivers/net/can/Makefile | 1 + drivers/net/can/rockchip/Kconfig | 9 + drivers/net/can/rockchip/Makefile | 9 + drivers/net/can/rockchip/rockchip_canfd-core.c | 868 +++++++++++++++++++++ drivers/net/can/rockchip/rockchip_canfd-rx.c | 118 +++ .../net/can/rockchip/rockchip_canfd-timestamp.c | 15 + drivers/net/can/rockchip/rockchip_canfd-tx.c | 12 + drivers/net/can/rockchip/rockchip_canfd.h | 361 +++++++++ 10 files changed, 1395 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 115307354f0b..01f129458838 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19736,6 +19736,7 @@ R: kernel@pengutronix.de L: linux-can@vger.kernel.org S: Maintained F: Documentation/devicetree/bindings/net/can/rockchip,rk3568-canfd.yaml +F: drivers/net/can/rockchip/ ROCKCHIP CRYPTO DRIVERS M: Corentin Labbe diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig index 7f9b60a42d29..cf989bea9aa3 100644 --- a/drivers/net/can/Kconfig +++ b/drivers/net/can/Kconfig @@ -225,6 +225,7 @@ source "drivers/net/can/m_can/Kconfig" source "drivers/net/can/mscan/Kconfig" source "drivers/net/can/peak_canfd/Kconfig" source "drivers/net/can/rcar/Kconfig" +source "drivers/net/can/rockchip/Kconfig" source "drivers/net/can/sja1000/Kconfig" source "drivers/net/can/softing/Kconfig" source "drivers/net/can/spi/Kconfig" diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile index 4669cd51e7bf..a71db2cfe990 100644 --- a/drivers/net/can/Makefile +++ b/drivers/net/can/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_CAN_SLCAN) += slcan/ obj-y += dev/ obj-y += esd/ obj-y += rcar/ +obj-y += rockchip/ obj-y += spi/ obj-y += usb/ obj-y += softing/ diff --git a/drivers/net/can/rockchip/Kconfig b/drivers/net/can/rockchip/Kconfig new file mode 100644 index 000000000000..e029e2a3ca4b --- /dev/null +++ b/drivers/net/can/rockchip/Kconfig @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 + +config CAN_ROCKCHIP_CANFD + tristate "Rockchip CAN-FD controller" + depends on OF || COMPILE_TEST + select CAN_RX_OFFLOAD + help + Say Y here if you want to use CAN-FD controller found on + Rockchip SoCs. diff --git a/drivers/net/can/rockchip/Makefile b/drivers/net/can/rockchip/Makefile new file mode 100644 index 000000000000..4eb7c50d8d5b --- /dev/null +++ b/drivers/net/can/rockchip/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_CAN_ROCKCHIP_CANFD) += rockchip_canfd.o + +rockchip_canfd-objs := +rockchip_canfd-objs += rockchip_canfd-core.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 new file mode 100644 index 000000000000..f1b2bad04bf4 --- /dev/null +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -0,0 +1,868 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2023, 2024 Pengutronix, +// Marc Kleine-Budde +// +// Based on: +// +// Rockchip CANFD driver +// +// Copyright (c) 2020 Rockchip Electronics Co. Ltd. +// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rockchip_canfd.h" + +static const struct rkcanfd_devtype_data rkcanfd_devtype_data_rk3568v2 = { + .model = RKCANFD_MODEL_RK3568V2, +}; + +static const char *__rkcanfd_get_model_str(enum rkcanfd_model model) +{ + switch (model) { + case RKCANFD_MODEL_RK3568V2: + return "rk3568v2"; + } + + return ""; +} + +static inline const char * +rkcanfd_get_model_str(const struct rkcanfd_priv *priv) +{ + return __rkcanfd_get_model_str(priv->devtype_data.model); +} + +/* Note: + * + * The formula to calculate the CAN System Clock is: + * + * Tsclk = 2 x Tclk x (brp + 1) + * + * Double the data sheet's brp_min, brp_max and brp_inc values (both + * for the arbitration and data bit timing) to take the "2 x" into + * account. + */ +static const struct can_bittiming_const rkcanfd_bittiming_const = { + .name = DEVICE_NAME, + .tseg1_min = 1, + .tseg1_max = 256, + .tseg2_min = 1, + .tseg2_max = 128, + .sjw_max = 128, + .brp_min = 2, /* value from data sheet x2 */ + .brp_max = 512, /* value from data sheet x2 */ + .brp_inc = 2, /* value from data sheet x2 */ +}; + +static const struct can_bittiming_const rkcanfd_data_bittiming_const = { + .name = DEVICE_NAME, + .tseg1_min = 1, + .tseg1_max = 32, + .tseg2_min = 1, + .tseg2_max = 16, + .sjw_max = 16, + .brp_min = 2, /* value from data sheet x2 */ + .brp_max = 512, /* value from data sheet x2 */ + .brp_inc = 2, /* value from data sheet x2 */ +}; + +static void rkcanfd_chip_set_reset_mode(const struct rkcanfd_priv *priv) +{ + reset_control_assert(priv->reset); + udelay(2); + reset_control_deassert(priv->reset); + + rkcanfd_write(priv, RKCANFD_REG_MODE, 0x0); +} + +static void rkcanfd_chip_set_work_mode(const struct rkcanfd_priv *priv) +{ + rkcanfd_write(priv, RKCANFD_REG_MODE, priv->reg_mode_default); +} + +static int rkcanfd_set_bittiming(struct rkcanfd_priv *priv) +{ + const struct can_bittiming *dbt = &priv->can.data_bittiming; + const struct can_bittiming *bt = &priv->can.bittiming; + u32 reg_nbt, reg_dbt, reg_tdc; + u32 tdco; + + reg_nbt = FIELD_PREP(RKCANFD_REG_FD_NOMINAL_BITTIMING_SJW, + bt->sjw - 1) | + FIELD_PREP(RKCANFD_REG_FD_NOMINAL_BITTIMING_BRP, + (bt->brp / 2) - 1) | + FIELD_PREP(RKCANFD_REG_FD_NOMINAL_BITTIMING_TSEG2, + bt->phase_seg2 - 1) | + FIELD_PREP(RKCANFD_REG_FD_NOMINAL_BITTIMING_TSEG1, + bt->prop_seg + bt->phase_seg1 - 1); + + rkcanfd_write(priv, RKCANFD_REG_FD_NOMINAL_BITTIMING, reg_nbt); + + if (!(priv->can.ctrlmode & CAN_CTRLMODE_FD)) + return 0; + + reg_dbt = FIELD_PREP(RKCANFD_REG_FD_DATA_BITTIMING_SJW, + dbt->sjw - 1) | + FIELD_PREP(RKCANFD_REG_FD_DATA_BITTIMING_BRP, + (dbt->brp / 2) - 1) | + FIELD_PREP(RKCANFD_REG_FD_DATA_BITTIMING_TSEG2, + dbt->phase_seg2 - 1) | + FIELD_PREP(RKCANFD_REG_FD_DATA_BITTIMING_TSEG1, + dbt->prop_seg + dbt->phase_seg1 - 1); + + rkcanfd_write(priv, RKCANFD_REG_FD_DATA_BITTIMING, reg_dbt); + + tdco = (priv->can.clock.freq / dbt->bitrate) * 2 / 3; + tdco = min(tdco, FIELD_MAX(RKCANFD_REG_TRANSMIT_DELAY_COMPENSATION_TDC_OFFSET)); + + reg_tdc = FIELD_PREP(RKCANFD_REG_TRANSMIT_DELAY_COMPENSATION_TDC_OFFSET, tdco) | + RKCANFD_REG_TRANSMIT_DELAY_COMPENSATION_TDC_ENABLE; + rkcanfd_write(priv, RKCANFD_REG_TRANSMIT_DELAY_COMPENSATION, + reg_tdc); + + return 0; +} + +static void rkcanfd_get_berr_counter_raw(struct rkcanfd_priv *priv, + struct can_berr_counter *bec) +{ + bec->rxerr = rkcanfd_read(priv, RKCANFD_REG_RXERRORCNT); + bec->txerr = rkcanfd_read(priv, RKCANFD_REG_TXERRORCNT); +} + +static int rkcanfd_get_berr_counter(const struct net_device *ndev, + struct can_berr_counter *bec) +{ + struct rkcanfd_priv *priv = netdev_priv(ndev); + int err; + + err = pm_runtime_resume_and_get(ndev->dev.parent); + if (err) + return err; + + rkcanfd_get_berr_counter_raw(priv, bec); + + pm_runtime_put(ndev->dev.parent); + + return 0; +} + +static void rkcanfd_chip_interrupts_enable(const struct rkcanfd_priv *priv) +{ + rkcanfd_write(priv, RKCANFD_REG_INT_MASK, priv->reg_int_mask_default); + + netdev_dbg(priv->ndev, "%s: reg_int_mask=0x%08x\n", __func__, + rkcanfd_read(priv, RKCANFD_REG_INT_MASK)); +} + +static void rkcanfd_chip_interrupts_disable(const struct rkcanfd_priv *priv) +{ + rkcanfd_write(priv, RKCANFD_REG_INT_MASK, RKCANFD_REG_INT_ALL); +} + +static void rkcanfd_chip_fifo_setup(struct rkcanfd_priv *priv) +{ + u32 reg; + + /* TXE FIFO */ + reg = rkcanfd_read(priv, RKCANFD_REG_RX_FIFO_CTRL); + reg |= RKCANFD_REG_RX_FIFO_CTRL_RX_FIFO_ENABLE; + rkcanfd_write(priv, RKCANFD_REG_RX_FIFO_CTRL, reg); + + /* RX FIFO */ + reg = rkcanfd_read(priv, RKCANFD_REG_RX_FIFO_CTRL); + reg |= RKCANFD_REG_RX_FIFO_CTRL_RX_FIFO_ENABLE; + rkcanfd_write(priv, RKCANFD_REG_RX_FIFO_CTRL, reg); + + WRITE_ONCE(priv->tx_head, 0); + WRITE_ONCE(priv->tx_tail, 0); + netdev_reset_queue(priv->ndev); +} + +static void rkcanfd_chip_start(struct rkcanfd_priv *priv) +{ + u32 reg; + + rkcanfd_chip_set_reset_mode(priv); + + /* Receiving Filter: accept all */ + rkcanfd_write(priv, RKCANFD_REG_IDCODE, 0x0); + rkcanfd_write(priv, RKCANFD_REG_IDMASK, RKCANFD_REG_IDCODE_EXTENDED_FRAME_ID); + + /* enable: + * - CAN_FD: enable CAN-FD + * - AUTO_RETX_MODE: auto retransmission on TX error + * - COVER_MODE: RX-FIFO overwrite mode, do not send OVERLOAD frames + * - WORK_MODE: transition from reset to working mode + */ + reg = rkcanfd_read(priv, RKCANFD_REG_MODE); + priv->reg_mode_default = reg | + RKCANFD_REG_MODE_CAN_FD_MODE_ENABLE | + RKCANFD_REG_MODE_AUTO_RETX_MODE | + RKCANFD_REG_MODE_COVER_MODE | + RKCANFD_REG_MODE_WORK_MODE; + + /* mask, i.e. ignore: + * - TIMESTAMP_COUNTER_OVERFLOW_INT - timestamp counter overflow interrupt + * - TX_ARBIT_FAIL_INT - TX arbitration fail interrupt + * - OVERLOAD_INT - CAN bus overload interrupt + */ + priv->reg_int_mask_default = + RKCANFD_REG_INT_TIMESTAMP_COUNTER_OVERFLOW_INT | + RKCANFD_REG_INT_TX_ARBIT_FAIL_INT | + RKCANFD_REG_INT_OVERLOAD_INT; + + rkcanfd_chip_fifo_setup(priv); + rkcanfd_timestamp_init(priv); + rkcanfd_set_bittiming(priv); + + rkcanfd_chip_interrupts_disable(priv); + rkcanfd_chip_set_work_mode(priv); + + priv->can.state = CAN_STATE_ERROR_ACTIVE; + + netdev_dbg(priv->ndev, "%s: reg_mode=0x%08x\n", __func__, + rkcanfd_read(priv, RKCANFD_REG_MODE)); +} + +static void __rkcanfd_chip_stop(struct rkcanfd_priv *priv, const enum can_state state) +{ + priv->can.state = state; + + rkcanfd_chip_set_reset_mode(priv); + rkcanfd_chip_interrupts_disable(priv); +} + +static void rkcanfd_chip_stop(struct rkcanfd_priv *priv, const enum can_state state) +{ + priv->can.state = state; + + __rkcanfd_chip_stop(priv, state); +} + +static void rkcanfd_chip_stop_sync(struct rkcanfd_priv *priv, const enum can_state state) +{ + priv->can.state = state; + + __rkcanfd_chip_stop(priv, state); +} + +static int rkcanfd_set_mode(struct net_device *ndev, + enum can_mode mode) +{ + struct rkcanfd_priv *priv = netdev_priv(ndev); + + switch (mode) { + case CAN_MODE_START: + rkcanfd_chip_start(priv); + rkcanfd_chip_interrupts_enable(priv); + netif_wake_queue(ndev); + break; + + default: + return -EOPNOTSUPP; + } + + return 0; +} + +static struct sk_buff * +rkcanfd_alloc_can_err_skb(struct rkcanfd_priv *priv, + struct can_frame **cf, u32 *timestamp) +{ + struct sk_buff *skb; + + *timestamp = rkcanfd_get_timestamp(priv); + + skb = alloc_can_err_skb(priv->ndev, cf); + + return skb; +} + +static const char *rkcanfd_get_error_type_str(unsigned int type) +{ + switch (type) { + case RKCANFD_REG_ERROR_CODE_TYPE_BIT: + return "Bit"; + case RKCANFD_REG_ERROR_CODE_TYPE_STUFF: + return "Stuff"; + case RKCANFD_REG_ERROR_CODE_TYPE_FORM: + return "Form"; + case RKCANFD_REG_ERROR_CODE_TYPE_ACK: + return "ACK"; + case RKCANFD_REG_ERROR_CODE_TYPE_CRC: + return "CRC"; + } + + return ""; +} + +#define RKCAN_ERROR_CODE(reg_ec, code) \ + ((reg_ec) & RKCANFD_REG_ERROR_CODE_##code ? __stringify(code) " " : "") + +static void +rkcanfd_handle_error_int_reg_ec(struct rkcanfd_priv *priv, struct can_frame *cf, + const u32 reg_ec) +{ + struct net_device_stats *stats = &priv->ndev->stats; + unsigned int type; + u32 reg_state, reg_cmd; + + type = FIELD_GET(RKCANFD_REG_ERROR_CODE_TYPE, reg_ec); + reg_cmd = rkcanfd_read(priv, RKCANFD_REG_CMD); + reg_state = rkcanfd_read(priv, RKCANFD_REG_STATE); + + netdev_dbg(priv->ndev, "%s Error in %s %s Phase: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s(0x%08x) CMD=%u RX=%u TX=%u Error-Warning=%u Bus-Off=%u\n", + rkcanfd_get_error_type_str(type), + reg_ec & RKCANFD_REG_ERROR_CODE_DIRECTION_RX ? "RX" : "TX", + reg_ec & RKCANFD_REG_ERROR_CODE_PHASE ? "Data" : "Arbitration", + RKCAN_ERROR_CODE(reg_ec, TX_OVERLOAD), + RKCAN_ERROR_CODE(reg_ec, TX_ERROR), + RKCAN_ERROR_CODE(reg_ec, TX_ACK), + RKCAN_ERROR_CODE(reg_ec, TX_ACK_EOF), + RKCAN_ERROR_CODE(reg_ec, TX_CRC), + RKCAN_ERROR_CODE(reg_ec, TX_STUFF_COUNT), + RKCAN_ERROR_CODE(reg_ec, TX_DATA), + RKCAN_ERROR_CODE(reg_ec, TX_SOF_DLC), + RKCAN_ERROR_CODE(reg_ec, TX_IDLE), + RKCAN_ERROR_CODE(reg_ec, RX_BUF_INT), + RKCAN_ERROR_CODE(reg_ec, RX_SPACE), + RKCAN_ERROR_CODE(reg_ec, RX_EOF), + RKCAN_ERROR_CODE(reg_ec, RX_ACK_LIM), + RKCAN_ERROR_CODE(reg_ec, RX_ACK), + RKCAN_ERROR_CODE(reg_ec, RX_CRC_LIM), + RKCAN_ERROR_CODE(reg_ec, RX_CRC), + RKCAN_ERROR_CODE(reg_ec, RX_STUFF_COUNT), + RKCAN_ERROR_CODE(reg_ec, RX_DATA), + RKCAN_ERROR_CODE(reg_ec, RX_DLC), + RKCAN_ERROR_CODE(reg_ec, RX_BRS_ESI), + RKCAN_ERROR_CODE(reg_ec, RX_RES), + RKCAN_ERROR_CODE(reg_ec, RX_FDF), + RKCAN_ERROR_CODE(reg_ec, RX_ID2_RTR), + RKCAN_ERROR_CODE(reg_ec, RX_SOF_IDE), + RKCAN_ERROR_CODE(reg_ec, RX_IDLE), + reg_ec, reg_cmd, + !!(reg_state & RKCANFD_REG_STATE_RX_PERIOD), + !!(reg_state & RKCANFD_REG_STATE_TX_PERIOD), + !!(reg_state & RKCANFD_REG_STATE_ERROR_WARNING_STATE), + !!(reg_state & RKCANFD_REG_STATE_BUS_OFF_STATE)); + + priv->can.can_stats.bus_error++; + + if (reg_ec & RKCANFD_REG_ERROR_CODE_DIRECTION_RX) + stats->rx_errors++; + else + stats->tx_errors++; + + if (!cf) + return; + + if (reg_ec & RKCANFD_REG_ERROR_CODE_DIRECTION_RX) { + if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_SOF_IDE) + cf->data[3] = CAN_ERR_PROT_LOC_SOF; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_ID2_RTR) + cf->data[3] = CAN_ERR_PROT_LOC_RTR; + /* RKCANFD_REG_ERROR_CODE_RX_FDF */ + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_RES) + cf->data[3] = CAN_ERR_PROT_LOC_RES0; + /* RKCANFD_REG_ERROR_CODE_RX_BRS_ESI */ + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_DLC) + cf->data[3] = CAN_ERR_PROT_LOC_DLC; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_DATA) + cf->data[3] = CAN_ERR_PROT_LOC_DATA; + /* RKCANFD_REG_ERROR_CODE_RX_STUFF_COUNT */ + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_CRC) + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_CRC_LIM) + cf->data[3] = CAN_ERR_PROT_LOC_ACK_DEL; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_ACK) + cf->data[3] = CAN_ERR_PROT_LOC_ACK; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_ACK_LIM) + cf->data[3] = CAN_ERR_PROT_LOC_ACK_DEL; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_EOF) + cf->data[3] = CAN_ERR_PROT_LOC_EOF; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_SPACE) + cf->data[3] = CAN_ERR_PROT_LOC_EOF; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_RX_BUF_INT) + cf->data[3] = CAN_ERR_PROT_LOC_INTERM; + } else { + cf->data[2] |= CAN_ERR_PROT_TX; + + if (reg_ec & RKCANFD_REG_ERROR_CODE_TX_SOF_DLC) + cf->data[3] = CAN_ERR_PROT_LOC_SOF; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_TX_DATA) + cf->data[3] = CAN_ERR_PROT_LOC_DATA; + /* RKCANFD_REG_ERROR_CODE_TX_STUFF_COUNT */ + else if (reg_ec & RKCANFD_REG_ERROR_CODE_TX_CRC) + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_TX_ACK_EOF) + cf->data[3] = CAN_ERR_PROT_LOC_ACK; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_TX_ACK) + cf->data[3] = CAN_ERR_PROT_LOC_ACK; + else if (reg_ec & RKCANFD_REG_ERROR_CODE_TX_ACK_EOF) + cf->data[3] = CAN_ERR_PROT_LOC_ACK_DEL; + /* RKCANFD_REG_ERROR_CODE_TX_ERROR */ + else if (reg_ec & RKCANFD_REG_ERROR_CODE_TX_OVERLOAD) + cf->data[2] |= CAN_ERR_PROT_OVERLOAD; + } + + switch (reg_ec & RKCANFD_REG_ERROR_CODE_TYPE) { + case FIELD_PREP_CONST(RKCANFD_REG_ERROR_CODE_TYPE, + RKCANFD_REG_ERROR_CODE_TYPE_BIT): + + cf->data[2] |= CAN_ERR_PROT_BIT; + break; + case FIELD_PREP_CONST(RKCANFD_REG_ERROR_CODE_TYPE, + RKCANFD_REG_ERROR_CODE_TYPE_STUFF): + cf->data[2] |= CAN_ERR_PROT_STUFF; + break; + case FIELD_PREP_CONST(RKCANFD_REG_ERROR_CODE_TYPE, + RKCANFD_REG_ERROR_CODE_TYPE_FORM): + cf->data[2] |= CAN_ERR_PROT_FORM; + break; + case FIELD_PREP_CONST(RKCANFD_REG_ERROR_CODE_TYPE, + RKCANFD_REG_ERROR_CODE_TYPE_ACK): + cf->can_id |= CAN_ERR_ACK; + break; + case FIELD_PREP_CONST(RKCANFD_REG_ERROR_CODE_TYPE, + RKCANFD_REG_ERROR_CODE_TYPE_CRC): + cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; + break; + } +} + +static int rkcanfd_handle_error_int(struct rkcanfd_priv *priv) +{ + struct net_device_stats *stats = &priv->ndev->stats; + struct can_frame *cf = NULL; + u32 reg_ec, timestamp; + struct sk_buff *skb; + int err; + + reg_ec = rkcanfd_read(priv, RKCANFD_REG_ERROR_CODE); + + if (!reg_ec) + return 0; + + skb = rkcanfd_alloc_can_err_skb(priv, &cf, ×tamp); + if (cf) { + struct can_berr_counter bec; + + rkcanfd_get_berr_counter_raw(priv, &bec); + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR | CAN_ERR_CNT; + cf->data[6] = bec.txerr; + cf->data[7] = bec.rxerr; + } + + rkcanfd_handle_error_int_reg_ec(priv, cf, reg_ec); + + if (!cf) + return 0; + + err = can_rx_offload_queue_timestamp(&priv->offload, skb, timestamp); + if (err) + stats->rx_fifo_errors++; + + return 0; +} + +static int rkcanfd_handle_state_error_int(struct rkcanfd_priv *priv) +{ + struct net_device_stats *stats = &priv->ndev->stats; + enum can_state new_state, rx_state, tx_state; + struct net_device *ndev = priv->ndev; + struct can_berr_counter bec; + struct can_frame *cf = NULL; + struct sk_buff *skb; + u32 timestamp; + int err; + + rkcanfd_get_berr_counter_raw(priv, &bec); + can_state_get_by_berr_counter(ndev, &bec, &tx_state, &rx_state); + + new_state = max(tx_state, rx_state); + if (new_state == priv->can.state) + return 0; + + /* The skb allocation might fail, but can_change_state() + * handles cf == NULL. + */ + skb = rkcanfd_alloc_can_err_skb(priv, &cf, ×tamp); + can_change_state(ndev, cf, tx_state, rx_state); + + if (new_state == CAN_STATE_BUS_OFF) { + rkcanfd_chip_stop(priv, CAN_STATE_BUS_OFF); + can_bus_off(ndev); + } + + if (!skb) + return 0; + + if (new_state != CAN_STATE_BUS_OFF) { + cf->can_id |= CAN_ERR_CNT; + cf->data[6] = bec.txerr; + cf->data[7] = bec.rxerr; + } + + err = can_rx_offload_queue_timestamp(&priv->offload, skb, timestamp); + if (err) + stats->rx_fifo_errors++; + + return 0; +} + +static int +rkcanfd_handle_rx_fifo_overflow_int(struct rkcanfd_priv *priv) +{ + struct net_device_stats *stats = &priv->ndev->stats; + struct can_berr_counter bec; + struct can_frame *cf = NULL; + struct sk_buff *skb; + u32 timestamp; + int err; + + stats->rx_over_errors++; + stats->rx_errors++; + + netdev_dbg(priv->ndev, "RX-FIFO overflow\n"); + + skb = rkcanfd_alloc_can_err_skb(priv, &cf, ×tamp); + if (skb) + return 0; + + rkcanfd_get_berr_counter_raw(priv, &bec); + + cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT; + cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; + cf->data[6] = bec.txerr; + cf->data[7] = bec.rxerr; + + err = can_rx_offload_queue_timestamp(&priv->offload, skb, timestamp); + if (err) + stats->rx_fifo_errors++; + + return 0; +} + +#define rkcanfd_handle(priv, irq, ...) \ +({ \ + struct rkcanfd_priv *_priv = (priv); \ + int err; \ +\ + err = rkcanfd_handle_##irq(_priv, ## __VA_ARGS__); \ + if (err) \ + netdev_err(_priv->ndev, \ + "IRQ handler rkcanfd_handle_%s() returned error: %pe\n", \ + __stringify(irq), ERR_PTR(err)); \ + err; \ +}) + +static irqreturn_t rkcanfd_irq(int irq, void *dev_id) +{ + struct rkcanfd_priv *priv = dev_id; + u32 reg_int_unmasked, reg_int; + + reg_int_unmasked = rkcanfd_read(priv, RKCANFD_REG_INT); + reg_int = reg_int_unmasked & ~priv->reg_int_mask_default; + + if (!reg_int) + return IRQ_NONE; + + /* First ACK then handle, to avoid lost-IRQ race condition on + * fast re-occurring interrupts. + */ + rkcanfd_write(priv, RKCANFD_REG_INT, reg_int); + + if (reg_int & RKCANFD_REG_INT_RX_FINISH_INT) + rkcanfd_handle(priv, rx_int); + + if (reg_int & RKCANFD_REG_INT_ERROR_INT) + rkcanfd_handle(priv, error_int); + + if (reg_int & (RKCANFD_REG_INT_BUS_OFF_INT | + RKCANFD_REG_INT_PASSIVE_ERROR_INT | + RKCANFD_REG_INT_ERROR_WARNING_INT) || + priv->can.state > CAN_STATE_ERROR_ACTIVE) + rkcanfd_handle(priv, state_error_int); + + if (reg_int & RKCANFD_REG_INT_RX_FIFO_OVERFLOW_INT) + rkcanfd_handle(priv, rx_fifo_overflow_int); + + if (reg_int & ~(RKCANFD_REG_INT_ALL_ERROR | + RKCANFD_REG_INT_RX_FIFO_OVERFLOW_INT | + RKCANFD_REG_INT_RX_FINISH_INT)) + netdev_err(priv->ndev, "%s: int=0x%08x\n", __func__, reg_int); + + if (reg_int & RKCANFD_REG_INT_WAKEUP_INT) + netdev_info(priv->ndev, "%s: WAKEUP_INT\n", __func__); + + if (reg_int & RKCANFD_REG_INT_TXE_FIFO_FULL_INT) + netdev_info(priv->ndev, "%s: TXE_FIFO_FULL_INT\n", __func__); + + if (reg_int & RKCANFD_REG_INT_TXE_FIFO_OV_INT) + netdev_info(priv->ndev, "%s: TXE_FIFO_OV_INT\n", __func__); + + if (reg_int & RKCANFD_REG_INT_BUS_OFF_RECOVERY_INT) + netdev_info(priv->ndev, "%s: BUS_OFF_RECOVERY_INT\n", __func__); + + if (reg_int & RKCANFD_REG_INT_RX_FIFO_FULL_INT) + netdev_info(priv->ndev, "%s: RX_FIFO_FULL_INT\n", __func__); + + if (reg_int & RKCANFD_REG_INT_OVERLOAD_INT) + netdev_info(priv->ndev, "%s: OVERLOAD_INT\n", __func__); + + can_rx_offload_irq_finish(&priv->offload); + + return IRQ_HANDLED; +} + +static int rkcanfd_open(struct net_device *ndev) +{ + struct rkcanfd_priv *priv = netdev_priv(ndev); + int err; + + err = open_candev(ndev); + if (err) + return err; + + err = pm_runtime_resume_and_get(ndev->dev.parent); + if (err) + goto out_close_candev; + + rkcanfd_chip_start(priv); + can_rx_offload_enable(&priv->offload); + + err = request_irq(ndev->irq, rkcanfd_irq, IRQF_SHARED, ndev->name, priv); + if (err) + goto out_rkcanfd_chip_stop; + + rkcanfd_chip_interrupts_enable(priv); + + netif_start_queue(ndev); + + return 0; + +out_rkcanfd_chip_stop: + rkcanfd_chip_stop_sync(priv, CAN_STATE_STOPPED); + pm_runtime_put(ndev->dev.parent); +out_close_candev: + close_candev(ndev); + return err; +} + +static int rkcanfd_stop(struct net_device *ndev) +{ + struct rkcanfd_priv *priv = netdev_priv(ndev); + + netif_stop_queue(ndev); + + rkcanfd_chip_interrupts_disable(priv); + free_irq(ndev->irq, priv); + can_rx_offload_disable(&priv->offload); + rkcanfd_chip_stop_sync(priv, CAN_STATE_STOPPED); + close_candev(ndev); + + pm_runtime_put(ndev->dev.parent); + + return 0; +} + +static const struct net_device_ops rkcanfd_netdev_ops = { + .ndo_open = rkcanfd_open, + .ndo_stop = rkcanfd_stop, + .ndo_start_xmit = rkcanfd_start_xmit, + .ndo_change_mtu = can_change_mtu, +}; + +static int __maybe_unused rkcanfd_runtime_suspend(struct device *dev) +{ + struct rkcanfd_priv *priv = dev_get_drvdata(dev); + + clk_bulk_disable_unprepare(priv->clks_num, priv->clks); + + return 0; +} + +static int __maybe_unused rkcanfd_runtime_resume(struct device *dev) +{ + struct rkcanfd_priv *priv = dev_get_drvdata(dev); + + return clk_bulk_prepare_enable(priv->clks_num, priv->clks); +} + +static void rkcanfd_register_done(const struct rkcanfd_priv *priv) +{ + u32 dev_id; + + dev_id = rkcanfd_read(priv, RKCANFD_REG_RTL_VERSION); + + netdev_info(priv->ndev, + "Rockchip-CANFD %s rev%lu.%lu found\n", + rkcanfd_get_model_str(priv), + FIELD_GET(RKCANFD_REG_RTL_VERSION_MAJOR, dev_id), + FIELD_GET(RKCANFD_REG_RTL_VERSION_MINOR, dev_id)); +} + +static int rkcanfd_register(struct rkcanfd_priv *priv) +{ + struct net_device *ndev = priv->ndev; + int err; + + pm_runtime_enable(ndev->dev.parent); + + err = pm_runtime_resume_and_get(ndev->dev.parent); + if (err) + goto out_pm_runtime_disable; + + err = register_candev(ndev); + if (err) + goto out_pm_runtime_put_sync; + + rkcanfd_register_done(priv); + + pm_runtime_put(ndev->dev.parent); + + return 0; + +out_pm_runtime_put_sync: + pm_runtime_put_sync(ndev->dev.parent); +out_pm_runtime_disable: + pm_runtime_disable(ndev->dev.parent); + + return err; +} + +static inline void rkcanfd_unregister(struct rkcanfd_priv *priv) +{ + struct net_device *ndev = priv->ndev; + + unregister_candev(ndev); + pm_runtime_disable(ndev->dev.parent); +} + +static const struct of_device_id rkcanfd_of_match[] = { + { + .compatible = "rockchip,rk3568v2-canfd", + .data = &rkcanfd_devtype_data_rk3568v2, + }, { + /* sentinel */ + }, +}; +MODULE_DEVICE_TABLE(of, rkcanfd_of_match); + +static int rkcanfd_probe(struct platform_device *pdev) +{ + struct rkcanfd_priv *priv; + struct net_device *ndev; + const void *match; + int err; + + ndev = alloc_candev(sizeof(struct rkcanfd_priv), RKCANFD_TXFIFO_DEPTH); + if (!ndev) + return -ENOMEM; + + priv = netdev_priv(ndev); + + ndev->irq = platform_get_irq(pdev, 0); + if (ndev->irq < 0) { + err = ndev->irq; + goto out_free_candev; + } + + priv->clks_num = devm_clk_bulk_get_all(&pdev->dev, &priv->clks); + if (priv->clks_num < 0) { + err = priv->clks_num; + goto out_free_candev; + } + + priv->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(priv->regs)) { + err = PTR_ERR(priv->regs); + goto out_free_candev; + } + + priv->reset = devm_reset_control_array_get_exclusive(&pdev->dev); + if (IS_ERR(priv->reset)) { + err = dev_err_probe(&pdev->dev, PTR_ERR(priv->reset), + "Failed to get reset line\n"); + goto out_free_candev; + } + + SET_NETDEV_DEV(ndev, &pdev->dev); + + ndev->netdev_ops = &rkcanfd_netdev_ops; + ndev->flags |= IFF_ECHO; + + platform_set_drvdata(pdev, priv); + priv->can.clock.freq = clk_get_rate(priv->clks[0].clk); + priv->can.bittiming_const = &rkcanfd_bittiming_const; + priv->can.data_bittiming_const = &rkcanfd_data_bittiming_const; + priv->can.ctrlmode_supported = 0; + priv->can.do_set_mode = rkcanfd_set_mode; + priv->can.do_get_berr_counter = rkcanfd_get_berr_counter; + priv->ndev = ndev; + + match = device_get_match_data(&pdev->dev); + if (match) + priv->devtype_data = *(struct rkcanfd_devtype_data *)match; + + err = can_rx_offload_add_manual(ndev, &priv->offload, + RKCANFD_NAPI_WEIGHT); + if (err) + goto out_free_candev; + + err = rkcanfd_register(priv); + if (err) + goto out_can_rx_offload_del; + + return 0; + +out_can_rx_offload_del: + can_rx_offload_del(&priv->offload); +out_free_candev: + free_candev(ndev); + + return err; +} + +static void rkcanfd_remove(struct platform_device *pdev) +{ + struct rkcanfd_priv *priv = platform_get_drvdata(pdev); + struct net_device *ndev = priv->ndev; + + can_rx_offload_del(&priv->offload); + rkcanfd_unregister(priv); + free_candev(ndev); +} + +static const struct dev_pm_ops rkcanfd_pm_ops = { + SET_RUNTIME_PM_OPS(rkcanfd_runtime_suspend, + rkcanfd_runtime_resume, NULL) +}; + +static struct platform_driver rkcanfd_driver = { + .driver = { + .name = DEVICE_NAME, + .pm = &rkcanfd_pm_ops, + .of_match_table = rkcanfd_of_match, + }, + .probe = rkcanfd_probe, + .remove = rkcanfd_remove, +}; +module_platform_driver(rkcanfd_driver); + +MODULE_AUTHOR("Marc Kleine-Budde "); +MODULE_DESCRIPTION("Rockchip CAN-FD Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c new file mode 100644 index 000000000000..5398aff0d180 --- /dev/null +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -0,0 +1,118 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2023, 2024 Pengutronix, +// Marc Kleine-Budde +// + +#include "rockchip_canfd.h" + +static unsigned int +rkcanfd_fifo_header_to_cfd_header(const struct rkcanfd_priv *priv, + const struct rkcanfd_fifo_header *header, + struct canfd_frame *cfd) +{ + unsigned int len = sizeof(*cfd) - sizeof(cfd->data); + u8 dlc; + + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_FRAME_FORMAT) + cfd->can_id = FIELD_GET(RKCANFD_REG_FD_ID_EFF, header->id) | + CAN_EFF_FLAG; + else + cfd->can_id = FIELD_GET(RKCANFD_REG_FD_ID_SFF, header->id); + + dlc = FIELD_GET(RKCANFD_REG_FD_FRAMEINFO_DATA_LENGTH, + header->frameinfo); + + /* CAN-FD */ + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_FDF) { + cfd->len = can_fd_dlc2len(dlc); + + /* The cfd is not allocated by alloc_canfd_skb(), so + * set CANFD_FDF here. + */ + cfd->flags |= CANFD_FDF; + + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_BRS) + cfd->flags |= CANFD_BRS; + } else { + cfd->len = can_cc_dlc2len(dlc); + + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_RTR) { + cfd->can_id |= CAN_RTR_FLAG; + + return len; + } + } + + return len + cfd->len; +} + +static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) +{ + struct net_device_stats *stats = &priv->ndev->stats; + struct canfd_frame cfd[1] = { }, *skb_cfd; + struct rkcanfd_fifo_header header[1] = { }; + struct sk_buff *skb; + unsigned int len; + int err; + + /* read header into separate struct and convert it later */ + rkcanfd_read_rep(priv, RKCANFD_REG_RX_FIFO_RDATA, + header, sizeof(*header)); + /* read data directly into cfd */ + rkcanfd_read_rep(priv, RKCANFD_REG_RX_FIFO_RDATA, + cfd->data, sizeof(cfd->data)); + + len = rkcanfd_fifo_header_to_cfd_header(priv, header, cfd); + + /* Drop any received CAN-FD frames if CAN-FD mode is not + * requested. + */ + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_FDF && + !(priv->can.ctrlmode & CAN_CTRLMODE_FD)) { + stats->rx_dropped++; + + return 0; + } + + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_FDF) + skb = alloc_canfd_skb(priv->ndev, &skb_cfd); + else + skb = alloc_can_skb(priv->ndev, (struct can_frame **)&skb_cfd); + + if (!skb) { + stats->rx_dropped++; + + return 0; + } + + memcpy(skb_cfd, cfd, len); + + err = can_rx_offload_queue_timestamp(&priv->offload, skb, header->ts); + if (err) + stats->rx_fifo_errors++; + + return 0; +} + +static inline unsigned int +rkcanfd_rx_fifo_get_len(const struct rkcanfd_priv *priv) +{ + const u32 reg = rkcanfd_read(priv, RKCANFD_REG_RX_FIFO_CTRL); + + return FIELD_GET(RKCANFD_REG_RX_FIFO_CTRL_RX_FIFO_CNT, reg); +} + +int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv) +{ + unsigned int len; + int err; + + while ((len = rkcanfd_rx_fifo_get_len(priv))) { + err = rkcanfd_handle_rx_int_one(priv); + if (err) + return err; + } + + return 0; +} diff --git a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c new file mode 100644 index 000000000000..9301b3ceceb0 --- /dev/null +++ b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2023, 2024 Pengutronix, +// Marc Kleine-Budde +// + +#include "rockchip_canfd.h" + +void rkcanfd_timestamp_init(struct rkcanfd_priv *priv) +{ + u32 reg; + + reg = RKCANFD_REG_TIMESTAMP_CTRL_TIME_BASE_COUNTER_ENABLE; + rkcanfd_write(priv, RKCANFD_REG_TIMESTAMP_CTRL, reg); +} diff --git a/drivers/net/can/rockchip/rockchip_canfd-tx.c b/drivers/net/can/rockchip/rockchip_canfd-tx.c new file mode 100644 index 000000000000..89c65db3b2dc --- /dev/null +++ b/drivers/net/can/rockchip/rockchip_canfd-tx.c @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// Copyright (c) 2023, 2024 Pengutronix, +// Marc Kleine-Budde +// + +#include "rockchip_canfd.h" + +int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev) +{ + return NETDEV_TX_OK; +} diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h new file mode 100644 index 000000000000..0848b1900baa --- /dev/null +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -0,0 +1,361 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2023, 2024 Pengutronix, + * Marc Kleine-Budde + */ + +#ifndef _ROCKCHIP_CANFD_H +#define _ROCKCHIP_CANFD_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define RKCANFD_REG_MODE 0x000 +#define RKCANFD_REG_MODE_CAN_FD_MODE_ENABLE BIT(15) +#define RKCANFD_REG_MODE_DPEE BIT(14) +#define RKCANFD_REG_MODE_BRSD BIT(13) +#define RKCANFD_REG_MODE_SPACE_RX_MODE BIT(12) +#define RKCANFD_REG_MODE_AUTO_BUS_ON BIT(11) +#define RKCANFD_REG_MODE_AUTO_RETX_MODE BIT(10) +#define RKCANFD_REG_MODE_OVLD_MODE BIT(9) +#define RKCANFD_REG_MODE_COVER_MODE BIT(8) +#define RKCANFD_REG_MODE_RXSORT_MODE BIT(7) +#define RKCANFD_REG_MODE_TXORDER_MODE BIT(6) +#define RKCANFD_REG_MODE_RXSTX_MODE BIT(5) +#define RKCANFD_REG_MODE_LBACK_MODE BIT(4) +#define RKCANFD_REG_MODE_SILENT_MODE BIT(3) +#define RKCANFD_REG_MODE_SELF_TEST BIT(2) +#define RKCANFD_REG_MODE_SLEEP_MODE BIT(1) +#define RKCANFD_REG_MODE_WORK_MODE BIT(0) + +#define RKCANFD_REG_CMD 0x004 +#define RKCANFD_REG_CMD_TX1_REQ BIT(1) +#define RKCANFD_REG_CMD_TX0_REQ BIT(0) +#define RKCANFD_REG_CMD_TX_REQ(i) (RKCANFD_REG_CMD_TX0_REQ << (i)) + +#define RKCANFD_REG_STATE 0x008 +#define RKCANFD_REG_STATE_SLEEP_STATE BIT(6) +#define RKCANFD_REG_STATE_BUS_OFF_STATE BIT(5) +#define RKCANFD_REG_STATE_ERROR_WARNING_STATE BIT(4) +#define RKCANFD_REG_STATE_TX_PERIOD BIT(3) +#define RKCANFD_REG_STATE_RX_PERIOD BIT(2) +#define RKCANFD_REG_STATE_TX_BUFFER_FULL BIT(1) +#define RKCANFD_REG_STATE_RX_BUFFER_FULL BIT(0) + +#define RKCANFD_REG_INT 0x00c +#define RKCANFD_REG_INT_WAKEUP_INT BIT(14) +#define RKCANFD_REG_INT_TXE_FIFO_FULL_INT BIT(13) +#define RKCANFD_REG_INT_TXE_FIFO_OV_INT BIT(12) +#define RKCANFD_REG_INT_TIMESTAMP_COUNTER_OVERFLOW_INT BIT(11) +#define RKCANFD_REG_INT_BUS_OFF_RECOVERY_INT BIT(10) +#define RKCANFD_REG_INT_BUS_OFF_INT BIT(9) +#define RKCANFD_REG_INT_RX_FIFO_OVERFLOW_INT BIT(8) +#define RKCANFD_REG_INT_RX_FIFO_FULL_INT BIT(7) +#define RKCANFD_REG_INT_ERROR_INT BIT(6) +#define RKCANFD_REG_INT_TX_ARBIT_FAIL_INT BIT(5) +#define RKCANFD_REG_INT_PASSIVE_ERROR_INT BIT(4) +#define RKCANFD_REG_INT_OVERLOAD_INT BIT(3) +#define RKCANFD_REG_INT_ERROR_WARNING_INT BIT(2) +#define RKCANFD_REG_INT_TX_FINISH_INT BIT(1) +#define RKCANFD_REG_INT_RX_FINISH_INT BIT(0) + +#define RKCANFD_REG_INT_ALL \ + (RKCANFD_REG_INT_WAKEUP_INT | \ + RKCANFD_REG_INT_TXE_FIFO_FULL_INT | \ + RKCANFD_REG_INT_TXE_FIFO_OV_INT | \ + RKCANFD_REG_INT_TIMESTAMP_COUNTER_OVERFLOW_INT | \ + RKCANFD_REG_INT_BUS_OFF_RECOVERY_INT | \ + RKCANFD_REG_INT_BUS_OFF_INT | \ + RKCANFD_REG_INT_RX_FIFO_OVERFLOW_INT | \ + RKCANFD_REG_INT_RX_FIFO_FULL_INT | \ + RKCANFD_REG_INT_ERROR_INT | \ + RKCANFD_REG_INT_TX_ARBIT_FAIL_INT | \ + RKCANFD_REG_INT_PASSIVE_ERROR_INT | \ + RKCANFD_REG_INT_OVERLOAD_INT | \ + RKCANFD_REG_INT_ERROR_WARNING_INT | \ + RKCANFD_REG_INT_TX_FINISH_INT | \ + RKCANFD_REG_INT_RX_FINISH_INT) + +#define RKCANFD_REG_INT_ALL_ERROR \ + (RKCANFD_REG_INT_BUS_OFF_INT | \ + RKCANFD_REG_INT_ERROR_INT | \ + RKCANFD_REG_INT_PASSIVE_ERROR_INT | \ + RKCANFD_REG_INT_ERROR_WARNING_INT) + +#define RKCANFD_REG_INT_MASK 0x010 + +#define RKCANFD_REG_DMA_CTL 0x014 +#define RKCANFD_REG_DMA_CTL_DMA_RX_MODE BIT(1) +#define RKCANFD_REG_DMA_CTL_DMA_TX_MODE BIT(9) + +#define RKCANFD_REG_BITTIMING 0x018 +#define RKCANFD_REG_BITTIMING_SAMPLE_MODE BIT(16) +#define RKCANFD_REG_BITTIMING_SJW GENMASK(15, 14) +#define RKCANFD_REG_BITTIMING_BRP GENMASK(13, 8) +#define RKCANFD_REG_BITTIMING_TSEG2 GENMASK(6, 4) +#define RKCANFD_REG_BITTIMING_TSEG1 GENMASK(3, 0) + +#define RKCANFD_REG_ARBITFAIL 0x028 +#define RKCANFD_REG_ARBITFAIL_ARBIT_FAIL_CODE GENMASK(6, 0) + +/* Register seems to be clear or read */ +#define RKCANFD_REG_ERROR_CODE 0x02c +#define RKCANFD_REG_ERROR_CODE_PHASE BIT(29) +#define RKCANFD_REG_ERROR_CODE_TYPE GENMASK(28, 26) +#define RKCANFD_REG_ERROR_CODE_TYPE_BIT 0x0 +#define RKCANFD_REG_ERROR_CODE_TYPE_STUFF 0x1 +#define RKCANFD_REG_ERROR_CODE_TYPE_FORM 0x2 +#define RKCANFD_REG_ERROR_CODE_TYPE_ACK 0x3 +#define RKCANFD_REG_ERROR_CODE_TYPE_CRC 0x4 +#define RKCANFD_REG_ERROR_CODE_DIRECTION_RX BIT(25) +#define RKCANFD_REG_ERROR_CODE_TX GENMASK(24, 16) +#define RKCANFD_REG_ERROR_CODE_TX_OVERLOAD BIT(24) +#define RKCANFD_REG_ERROR_CODE_TX_ERROR BIT(23) +#define RKCANFD_REG_ERROR_CODE_TX_ACK BIT(22) +#define RKCANFD_REG_ERROR_CODE_TX_ACK_EOF BIT(21) +#define RKCANFD_REG_ERROR_CODE_TX_CRC BIT(20) +#define RKCANFD_REG_ERROR_CODE_TX_STUFF_COUNT BIT(19) +#define RKCANFD_REG_ERROR_CODE_TX_DATA BIT(18) +#define RKCANFD_REG_ERROR_CODE_TX_SOF_DLC BIT(17) +#define RKCANFD_REG_ERROR_CODE_TX_IDLE BIT(16) +#define RKCANFD_REG_ERROR_CODE_RX GENMASK(15, 0) +#define RKCANFD_REG_ERROR_CODE_RX_BUF_INT BIT(15) +#define RKCANFD_REG_ERROR_CODE_RX_SPACE BIT(14) +#define RKCANFD_REG_ERROR_CODE_RX_EOF BIT(13) +#define RKCANFD_REG_ERROR_CODE_RX_ACK_LIM BIT(12) +#define RKCANFD_REG_ERROR_CODE_RX_ACK BIT(11) +#define RKCANFD_REG_ERROR_CODE_RX_CRC_LIM BIT(10) +#define RKCANFD_REG_ERROR_CODE_RX_CRC BIT(9) +#define RKCANFD_REG_ERROR_CODE_RX_STUFF_COUNT BIT(8) +#define RKCANFD_REG_ERROR_CODE_RX_DATA BIT(7) +#define RKCANFD_REG_ERROR_CODE_RX_DLC BIT(6) +#define RKCANFD_REG_ERROR_CODE_RX_BRS_ESI BIT(5) +#define RKCANFD_REG_ERROR_CODE_RX_RES BIT(4) +#define RKCANFD_REG_ERROR_CODE_RX_FDF BIT(3) +#define RKCANFD_REG_ERROR_CODE_RX_ID2_RTR BIT(2) +#define RKCANFD_REG_ERROR_CODE_RX_SOF_IDE BIT(1) +#define RKCANFD_REG_ERROR_CODE_RX_IDLE BIT(0) + +#define RKCANFD_REG_ERROR_CODE_NOACK \ + (FIELD_PREP(RKCANFD_REG_ERROR_CODE_TYPE, \ + RKCANFD_REG_ERROR_CODE_TYPE_ACK) | \ + RKCANFD_REG_ERROR_CODE_TX_ACK_EOF | \ + RKCANFD_REG_ERROR_CODE_RX_ACK) + +#define RKCANFD_REG_RXERRORCNT 0x034 +#define RKCANFD_REG_RXERRORCNT_RX_ERR_CNT GENMASK(7, 0) + +#define RKCANFD_REG_TXERRORCNT 0x038 +#define RKCANFD_REG_TXERRORCNT_TX_ERR_CNT GENMASK(8, 0) + +#define RKCANFD_REG_IDCODE 0x03c +#define RKCANFD_REG_IDCODE_STANDARD_FRAME_ID GENMASK(10, 0) +#define RKCANFD_REG_IDCODE_EXTENDED_FRAME_ID GENMASK(28, 0) + +#define RKCANFD_REG_IDMASK 0x040 + +#define RKCANFD_REG_TXFRAMEINFO 0x050 +#define RKCANFD_REG_FRAMEINFO_FRAME_FORMAT BIT(7) +#define RKCANFD_REG_FRAMEINFO_RTR BIT(6) +#define RKCANFD_REG_FRAMEINFO_DATA_LENGTH GENMASK(3, 0) + +#define RKCANFD_REG_TXID 0x054 +#define RKCANFD_REG_TXID_TX_ID GENMASK(28, 0) + +#define RKCANFD_REG_TXDATA0 0x058 +#define RKCANFD_REG_TXDATA1 0x05C +#define RKCANFD_REG_RXFRAMEINFO 0x060 +#define RKCANFD_REG_RXID 0x064 +#define RKCANFD_REG_RXDATA0 0x068 +#define RKCANFD_REG_RXDATA1 0x06c + +#define RKCANFD_REG_RTL_VERSION 0x070 +#define RKCANFD_REG_RTL_VERSION_MAJOR GENMASK(7, 4) +#define RKCANFD_REG_RTL_VERSION_MINOR GENMASK(3, 0) + +#define RKCANFD_REG_FD_NOMINAL_BITTIMING 0x100 +#define RKCANFD_REG_FD_NOMINAL_BITTIMING_SAMPLE_MODE BIT(31) +#define RKCANFD_REG_FD_NOMINAL_BITTIMING_SJW GENMASK(30, 24) +#define RKCANFD_REG_FD_NOMINAL_BITTIMING_BRP GENMASK(23, 16) +#define RKCANFD_REG_FD_NOMINAL_BITTIMING_TSEG2 GENMASK(14, 8) +#define RKCANFD_REG_FD_NOMINAL_BITTIMING_TSEG1 GENMASK(7, 0) + +#define RKCANFD_REG_FD_DATA_BITTIMING 0x104 +#define RKCANFD_REG_FD_DATA_BITTIMING_SAMPLE_MODE BIT(21) +#define RKCANFD_REG_FD_DATA_BITTIMING_SJW GENMASK(20, 17) +#define RKCANFD_REG_FD_DATA_BITTIMING_BRP GENMASK(16, 9) +#define RKCANFD_REG_FD_DATA_BITTIMING_TSEG2 GENMASK(8, 5) +#define RKCANFD_REG_FD_DATA_BITTIMING_TSEG1 GENMASK(4, 0) + +#define RKCANFD_REG_TRANSMIT_DELAY_COMPENSATION 0x108 +#define RKCANFD_REG_TRANSMIT_DELAY_COMPENSATION_TDC_OFFSET GENMASK(6, 1) +#define RKCANFD_REG_TRANSMIT_DELAY_COMPENSATION_TDC_ENABLE BIT(0) + +#define RKCANFD_REG_TIMESTAMP_CTRL 0x10c +/* datasheet says 6:1, which is wrong */ +#define RKCANFD_REG_TIMESTAMP_CTRL_TIME_BASE_COUNTER_PRESCALE GENMASK(5, 1) +#define RKCANFD_REG_TIMESTAMP_CTRL_TIME_BASE_COUNTER_ENABLE BIT(0) + +#define RKCANFD_REG_TIMESTAMP 0x110 + +#define RKCANFD_REG_TXEVENT_FIFO_CTRL 0x114 +#define RKCANFD_REG_TXEVENT_FIFO_CTRL_TXE_FIFO_CNT GENMASK(8, 5) +#define RKCANFD_REG_TXEVENT_FIFO_CTRL_TXE_FIFO_WATERMARK GENMASK(4, 1) +#define RKCANFD_REG_TXEVENT_FIFO_CTRL_TXE_FIFO_ENABLE BIT(0) + +#define RKCANFD_REG_RX_FIFO_CTRL 0x118 +#define RKCANFD_REG_RX_FIFO_CTRL_RX_FIFO_CNT GENMASK(6, 4) +#define RKCANFD_REG_RX_FIFO_CTRL_RX_FIFO_FULL_WATERMARK GENMASK(3, 1) +#define RKCANFD_REG_RX_FIFO_CTRL_RX_FIFO_ENABLE BIT(0) + +#define RKCANFD_REG_AFC_CTRL 0x11c +#define RKCANFD_REG_AFC_CTRL_UAF5 BIT(4) +#define RKCANFD_REG_AFC_CTRL_UAF4 BIT(3) +#define RKCANFD_REG_AFC_CTRL_UAF3 BIT(2) +#define RKCANFD_REG_AFC_CTRL_UAF2 BIT(1) +#define RKCANFD_REG_AFC_CTRL_UAF1 BIT(0) + +#define RKCANFD_REG_IDCODE0 0x120 +#define RKCANFD_REG_IDMASK0 0x124 +#define RKCANFD_REG_IDCODE1 0x128 +#define RKCANFD_REG_IDMASK1 0x12c +#define RKCANFD_REG_IDCODE2 0x130 +#define RKCANFD_REG_IDMASK2 0x134 +#define RKCANFD_REG_IDCODE3 0x138 +#define RKCANFD_REG_IDMASK3 0x13c +#define RKCANFD_REG_IDCODE4 0x140 +#define RKCANFD_REG_IDMASK4 0x144 + +#define RKCANFD_REG_FD_TXFRAMEINFO 0x200 +#define RKCANFD_REG_FD_FRAMEINFO_FRAME_FORMAT BIT(7) +#define RKCANFD_REG_FD_FRAMEINFO_RTR BIT(6) +#define RKCANFD_REG_FD_FRAMEINFO_FDF BIT(5) +#define RKCANFD_REG_FD_FRAMEINFO_BRS BIT(4) +#define RKCANFD_REG_FD_FRAMEINFO_DATA_LENGTH GENMASK(3, 0) + +#define RKCANFD_REG_FD_TXID 0x204 +#define RKCANFD_REG_FD_ID_EFF GENMASK(28, 0) +#define RKCANFD_REG_FD_ID_SFF GENMASK(11, 0) + +#define RKCANFD_REG_FD_TXDATA0 0x208 +#define RKCANFD_REG_FD_TXDATA1 0x20c +#define RKCANFD_REG_FD_TXDATA2 0x210 +#define RKCANFD_REG_FD_TXDATA3 0x214 +#define RKCANFD_REG_FD_TXDATA4 0x218 +#define RKCANFD_REG_FD_TXDATA5 0x21c +#define RKCANFD_REG_FD_TXDATA6 0x220 +#define RKCANFD_REG_FD_TXDATA7 0x224 +#define RKCANFD_REG_FD_TXDATA8 0x228 +#define RKCANFD_REG_FD_TXDATA9 0x22c +#define RKCANFD_REG_FD_TXDATA10 0x230 +#define RKCANFD_REG_FD_TXDATA11 0x234 +#define RKCANFD_REG_FD_TXDATA12 0x238 +#define RKCANFD_REG_FD_TXDATA13 0x23c +#define RKCANFD_REG_FD_TXDATA14 0x240 +#define RKCANFD_REG_FD_TXDATA15 0x244 + +#define RKCANFD_REG_FD_RXFRAMEINFO 0x300 +#define RKCANFD_REG_FD_RXID 0x304 +#define RKCANFD_REG_FD_RXTIMESTAMP 0x308 +#define RKCANFD_REG_FD_RXDATA0 0x30c +#define RKCANFD_REG_FD_RXDATA1 0x310 +#define RKCANFD_REG_FD_RXDATA2 0x314 +#define RKCANFD_REG_FD_RXDATA3 0x318 +#define RKCANFD_REG_FD_RXDATA4 0x31c +#define RKCANFD_REG_FD_RXDATA5 0x320 +#define RKCANFD_REG_FD_RXDATA6 0x320 +#define RKCANFD_REG_FD_RXDATA7 0x328 +#define RKCANFD_REG_FD_RXDATA8 0x32c +#define RKCANFD_REG_FD_RXDATA9 0x330 +#define RKCANFD_REG_FD_RXDATA10 0x334 +#define RKCANFD_REG_FD_RXDATA11 0x338 +#define RKCANFD_REG_FD_RXDATA12 0x33c +#define RKCANFD_REG_FD_RXDATA13 0x340 +#define RKCANFD_REG_FD_RXDATA14 0x344 +#define RKCANFD_REG_FD_RXDATA15 0x348 + +#define RKCANFD_REG_RX_FIFO_RDATA 0x400 +#define RKCANFD_REG_TXE_FIFO_RDATA 0x500 + +#define DEVICE_NAME "rockchip_canfd" +#define RKCANFD_NAPI_WEIGHT 32 +#define RKCANFD_TXFIFO_DEPTH 1 +#define RKCANFD_TX_STOP_THRESHOLD 1 +#define RKCANFD_TX_START_THRESHOLD 1 + +#define RKCANFD_TIMESTAMP_WORK_MAX_DELAY_SEC 60 +#define RKCANFD_ERRATUM_5_SYSCLOCK_HZ_MIN (300 * MEGA) + +enum rkcanfd_model { + RKCANFD_MODEL_RK3568V2 = 0x35682, +}; + +struct rkcanfd_devtype_data { + enum rkcanfd_model model; +}; + +struct rkcanfd_fifo_header { + u32 frameinfo; + u32 id; + u32 ts; +}; + +struct rkcanfd_priv { + struct can_priv can; + struct can_rx_offload offload; + struct net_device *ndev; + + void __iomem *regs; + unsigned int tx_head; + unsigned int tx_tail; + + u32 reg_mode_default; + u32 reg_int_mask_default; + struct rkcanfd_devtype_data devtype_data; + + struct reset_control *reset; + struct clk_bulk_data *clks; + int clks_num; +}; + +static inline u32 +rkcanfd_read(const struct rkcanfd_priv *priv, u32 reg) +{ + return readl(priv->regs + reg); +} + +static inline void +rkcanfd_read_rep(const struct rkcanfd_priv *priv, u32 reg, + void *buf, unsigned int len) +{ + readsl(priv->regs + reg, buf, len / sizeof(u32)); +} + +static inline void +rkcanfd_write(const struct rkcanfd_priv *priv, u32 reg, u32 val) +{ + writel(val, priv->regs + reg); +} + +static inline u32 +rkcanfd_get_timestamp(const struct rkcanfd_priv *priv) +{ + return rkcanfd_read(priv, RKCANFD_REG_TIMESTAMP); +} + +int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv); + +void rkcanfd_timestamp_init(struct rkcanfd_priv *priv); + +int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev); + +#endif From patchwork Fri Aug 30 19:26:02 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: 13785500 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 E7689CA0FE8 for ; Fri, 30 Aug 2024 19:42:55 +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=kidBwUMnOIKuAwGb8PYEhQzWrkvH3OalyCZMU8N3+B0=; b=V7bceJC4kW3hgC jt50bASBGByYVkFWb/lQHrjv5QbBtISiH0Ax35DHGkwPWMj+PCM/gpUk05JL1p2mzpDCS/QYugA7M b4IPxNbT+tM22m+NucTvZ5IML/fW4Ib11h4ZXDp8jlTxoCfa7hWUK/03D2nwEznnsV54qAv+XMAMY zsfjL0ajx3W+GLBE7XvSRTHi15L1as7bCox3/7h1TXfyldHIzdMfVrVgCVB8oqkBihhWvLLm86DZl yxhfq0pd1ztK18H7LcAfXKS5ZOv+rKPzj6VizeX6M3o6tL6F4r6kQtbRQIj3s37j/cwqdvhCZcf1m JNfNh6lXeO0m52oS2W5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7WH-00000007Vu2-1BUj; Fri, 30 Aug 2024 19:42:53 +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 1sk7HO-00000007RdX-09SZ for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:30 +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=3zmsjBLTu1k5iT9Rbcc+pSOXFx58txD1k4afWCHcdGw=; b=XKmvGbJdD4J2yvr2R12PkRAcWJ h4Oj142BAjBL4660xybkNPXWfqME2+A8rfmmhn5zhPFT441Rf1NunYR+2hF8xJZCYDyfpUTqP628D kDAxql99nZYNbI4NtxmDuQoPMZcZpFjJ+X3JGt/vcUIQq88FDvWmMgHiKT4Vyn3L9I4OnNcHr/lkk ZP72j3dEW4GfE/WCMGR5Hao+LCkFe+CeLkbCD+R6jJCbc/4NmQZRapjfMZda8V5DKwlqRikgCFFTQ TxgnMAiYr4vc6j/kLygDJRa1UNUjQpNhPYFjV7ElSwBUWUiOAcaEsPV5iY7VedzZBNN/Khi+ShXy8 F+0T9krw==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H1-0000000Bk8t-3Xgz for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:19 +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 1sk7Gw-0006Ea-I1 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:02 +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 1sk7Gn-004DjO-TO for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:53 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 7881932E1C3 for ; Fri, 30 Aug 2024 19:26:53 +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 737BF32E0F6; 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 f39f0aa6; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:02 +0200 Subject: [PATCH can-next v3 05/20] can: rockchip_canfd: add quirks for errata workarounds MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-5-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=4201; i=mkl@pengutronix.de; h=from:subject:message-id; bh=Q1BkNbeC/Vz6nQS8dYGWDRL1T1AB9nyLFONDH/lcnLM=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzdCxMPKknDs4rS5qGpXq5aT6os0+ueqW6Ot M6KylWGtsWJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc3QAKCRAoOKI+ei28 b1EZCACKyvbImZBiCBPvunyRKxuU/vWv1GbQh4jRbXMZJTGVTm527NPXV6aBynYx3fBVJ5c1Yfr a4pcheophUUb3kMZ8nzux/Pkd3S99RFmxfChBpbtnaY5ItokxkwyWVAL4IiK4P48zWgzoOPGf0y Eo4pptWtTSD5QjLVUsDwbJefBSfq85KSdSFomwwdVCwoJboviGPUMDOvSOoryvB21/cUh/t3Boi reqeZtt/6YmmbkyLk0CTRYivUUqsoJoz/nRM1CaJ9OSHNGWtzgj++dLdQ9hu6malfYnRwxgYYxR pZ6X6YXmZ+rmHxlUkM7StYzyp8Gn4jOKVco2oOVDOMARogqu 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-20240830_202715_458639_DD9843A3 X-CRM114-Status: GOOD ( 16.54 ) 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 Add a basic infrastructure for quirks for the 12 documented errata. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 11 +++++- drivers/net/can/rockchip/rockchip_canfd.h | 55 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index f1b2bad04bf4..18957769b3d3 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -26,6 +26,12 @@ static const struct rkcanfd_devtype_data rkcanfd_devtype_data_rk3568v2 = { .model = RKCANFD_MODEL_RK3568V2, + .quirks = RKCANFD_QUIRK_RK3568_ERRATUM_1 | RKCANFD_QUIRK_RK3568_ERRATUM_2 | + RKCANFD_QUIRK_RK3568_ERRATUM_3 | RKCANFD_QUIRK_RK3568_ERRATUM_4 | + RKCANFD_QUIRK_RK3568_ERRATUM_5 | RKCANFD_QUIRK_RK3568_ERRATUM_6 | + RKCANFD_QUIRK_RK3568_ERRATUM_7 | RKCANFD_QUIRK_RK3568_ERRATUM_8 | + RKCANFD_QUIRK_RK3568_ERRATUM_9 | RKCANFD_QUIRK_RK3568_ERRATUM_10 | + RKCANFD_QUIRK_RK3568_ERRATUM_11 | RKCANFD_QUIRK_RK3568_ERRATUM_12, }; static const char *__rkcanfd_get_model_str(enum rkcanfd_model model) @@ -709,10 +715,11 @@ static void rkcanfd_register_done(const struct rkcanfd_priv *priv) dev_id = rkcanfd_read(priv, RKCANFD_REG_RTL_VERSION); netdev_info(priv->ndev, - "Rockchip-CANFD %s rev%lu.%lu found\n", + "Rockchip-CANFD %s rev%lu.%lu (errata 0x%04x) found\n", rkcanfd_get_model_str(priv), FIELD_GET(RKCANFD_REG_RTL_VERSION_MAJOR, dev_id), - FIELD_GET(RKCANFD_REG_RTL_VERSION_MINOR, dev_id)); + FIELD_GET(RKCANFD_REG_RTL_VERSION_MINOR, dev_id), + priv->devtype_data.quirks); } static int rkcanfd_register(struct rkcanfd_priv *priv) diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 0848b1900baa..09626ca174a8 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -295,12 +295,67 @@ #define RKCANFD_TIMESTAMP_WORK_MAX_DELAY_SEC 60 #define RKCANFD_ERRATUM_5_SYSCLOCK_HZ_MIN (300 * MEGA) +/* rk3568 CAN-FD Errata, as of Tue 07 Nov 2023 11:25:31 +08:00 */ + +/* Erratum 1: The error frame sent by the CAN controller has an + * abnormal format. + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_1 BIT(0) + +/* Erratum 2: The error frame sent after detecting a CRC error has an + * abnormal position. + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_2 BIT(1) + +/* Erratum 3: Intermittent CRC calculation errors. */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_3 BIT(2) + +/* Erratum 4: Intermittent occurrence of stuffing errors. */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_4 BIT(3) + +/* Erratum 5: Counters related to the TXFIFO and RXFIFO exhibit + * abnormal counting behavior. + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_5 BIT(4) + +/* Erratum 6: The CAN controller's transmission of extended frames may + * intermittently change into standard frames + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_6 BIT(5) + +/* Erratum 7: In the passive error state, the CAN controller's + * interframe space segment counting is inaccurate. + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_7 BIT(6) + +/* Erratum 8: The Format-Error error flag is transmitted one bit + * later. + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_8 BIT(7) + +/* Erratum 9: In the arbitration segment, the CAN controller will + * identify stuffing errors as arbitration failures. + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_9 BIT(8) + +/* Erratum 10: Does not support the BUSOFF slow recovery mechanism. */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_10 BIT(9) + +/* Erratum 11: Arbitration error. */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_11 BIT(10) + +/* Erratum 12: A dominant bit at the third bit of the intermission may + * cause a transmission error. + */ +#define RKCANFD_QUIRK_RK3568_ERRATUM_12 BIT(11) + enum rkcanfd_model { RKCANFD_MODEL_RK3568V2 = 0x35682, }; struct rkcanfd_devtype_data { enum rkcanfd_model model; + u32 quirks; }; struct rkcanfd_fifo_header { From patchwork Fri Aug 30 19:26:03 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: 13785492 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 C074BCA0FE8 for ; Fri, 30 Aug 2024 19:42:04 +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=YmB7I7ekMjYF7EkULyVNbLWRuRA7yleOY7lnmgy6wWw=; b=ejR+fNrbmn0uT8 FRj+4uhxL/A2Rnutjgcw//RAiMvucg+LWbCBtKEHMGe1fD4UVhWFBDI6rMg/A8nUUsJd/1kvJ+cFi W7nbbetC3VjuiOWtJ0hjZMfoeDNKBDCDHxboOtHdt851AR+hC0MvBA5iu/EvgI9u0c/7vSjLKhlCE zQ96fTfoVDfFDSJfTCoqNwae4/diqc7qG12k79PzmndCX3RFYKikG5WQMsNDmQ7NUAkHIEQd4tp7N OsySI96nIiJORekWdfBeY2NWvcWaFFjW+6/SAgDRaWrfskz/lo+J9YMVvR5c698AIqSK2uEqPNTPl t47TbwuzRR913Cp+5I4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7VS-00000007Vls-01Q7; Fri, 30 Aug 2024 19:42:02 +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 1sk7HN-00000007Rd5-0qtv for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:29 +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=qCc2WSKDVxzJzyJ3BGWZcdOCvsretILK/n3l9I9Qj5s=; b=PUtSSI/zOmwd8E88IHUbRb4ub3 wkdSHzpxBzrAok4nZEsWhpBCMwR/OUmUCYONwZzfLai8waU2G1TkxKZ0ao49w+Kar78Jxni3tiVmG ZSf2s+VUuxTrHNIFc1carfKh+9z2A7uWSY2aX5fuH3v+7I2bRuQzxuHwnabeS+ZCS/sb+Ah3UlUlc 2zjDEa7PoP/iJQJ+sGIk9uf2G/2aENTaRawdh2GVzQ6c9sLI/kLidsynVoHp61tbS5E+vLPwXekkh gGUWrSN1mXDCs7olfVpmbBUWBDNxiuyzVZHEfQAyNCNqs6hpoiFks45tdhA42+EqWJxUQEmrClQ45 Lzeomi/A==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H1-0000000Bk8q-3Xs4 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:19 +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 1sk7Gw-0006Ed-12 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:02 +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 1sk7Gn-004DjD-T3 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:53 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 7729432E1C1 for ; Fri, 30 Aug 2024 19:26:53 +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 8E1A732E0F9; 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 20c9dded; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:03 +0200 Subject: [PATCH can-next v3 06/20] can: rockchip_canfd: add quirk for broken CAN-FD support MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-6-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=2840; i=mkl@pengutronix.de; h=from:subject:message-id; bh=/s9xfpJ5faFkGxYn0Ztg+FA4vUJebVCmlZ+jp3JMo/M=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzemRIbXa/PmuAVlyR17VkN3WesDJ5DSIwa1 o/GPL/G4YiJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc3gAKCRAoOKI+ei28 b4u5B/9Z8Lw54hZD9Og8L8NooyA5prCXBHit7uJyJEacOmq/a5SkJ1Sx6/QpeW6QEUSlzXt9Sih 0nCG80uJ+KtuDlQ54VXnf8TZDfOhAM1Ax9CN4cKV+EpFaGKbkDQyxFCH1jd/8DYnvH6YjMZ1X+4 n5UPgolZYckOUsqmoiylGqyecDWmjUGfDmgkRHvhySrMViq731MGYz1x1KCAl7QnbWbvtwZDKJL FhrXT+5uIgfFrLHZPg5g7p84WBilAJdv9G0BkPW6mTmCsSQ0lX6j6mjRzplLBxAade+LkfHcRPH Eo//nYTq3mrFPaiWO0d6P4DV+du7urhONggQN7cFIX3b/VvY 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-20240830_202715_833069_4EF5E447 X-CRM114-Status: GOOD ( 15.83 ) 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 errata sheets doesn't say anything about CAN-FD, but tests on the rk3568v2 and rk3568v3 show that receiving certain CAN-FD frames triggers an Error Interrupt. Mark the CAN-FD support as broken. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 5 ++++- drivers/net/can/rockchip/rockchip_canfd.h | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index 18957769b3d3..61de6f89cf16 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -31,7 +31,8 @@ static const struct rkcanfd_devtype_data rkcanfd_devtype_data_rk3568v2 = { RKCANFD_QUIRK_RK3568_ERRATUM_5 | RKCANFD_QUIRK_RK3568_ERRATUM_6 | RKCANFD_QUIRK_RK3568_ERRATUM_7 | RKCANFD_QUIRK_RK3568_ERRATUM_8 | RKCANFD_QUIRK_RK3568_ERRATUM_9 | RKCANFD_QUIRK_RK3568_ERRATUM_10 | - RKCANFD_QUIRK_RK3568_ERRATUM_11 | RKCANFD_QUIRK_RK3568_ERRATUM_12, + RKCANFD_QUIRK_RK3568_ERRATUM_11 | RKCANFD_QUIRK_RK3568_ERRATUM_12 | + RKCANFD_QUIRK_CANFD_BROKEN, }; static const char *__rkcanfd_get_model_str(enum rkcanfd_model model) @@ -817,6 +818,8 @@ static int rkcanfd_probe(struct platform_device *pdev) priv->can.bittiming_const = &rkcanfd_bittiming_const; priv->can.data_bittiming_const = &rkcanfd_data_bittiming_const; priv->can.ctrlmode_supported = 0; + if (!(priv->devtype_data.quirks & RKCANFD_QUIRK_CANFD_BROKEN)) + priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD; priv->can.do_set_mode = rkcanfd_set_mode; priv->can.do_get_berr_counter = rkcanfd_get_berr_counter; priv->ndev = ndev; diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 09626ca174a8..7321027534fb 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -349,6 +349,27 @@ */ #define RKCANFD_QUIRK_RK3568_ERRATUM_12 BIT(11) +/* Tests on the rk3568v2 and rk3568v3 show that receiving certain + * CAN-FD frames trigger an Error Interrupt. + * + * - Form Error in RX Arbitration Phase: TX_IDLE RX_STUFF_COUNT (0x0a010100) CMD=0 RX=0 TX=0 + * Error-Warning=1 Bus-Off=0 + * To reproduce: + * host: + * cansend can0 002##01f + * DUT: + * candump any,0:0,#FFFFFFFF -cexdHtA + * + * - Form Error in RX Arbitration Phase: TX_IDLE RX_CRC (0x0a010200) CMD=0 RX=0 TX=0 + * Error-Warning=1 Bus-Off=0 + * To reproduce: + * host: + * cansend can0 002##07217010000000000 + * DUT: + * candump any,0:0,#FFFFFFFF -cexdHtA + */ +#define RKCANFD_QUIRK_CANFD_BROKEN BIT(12) + enum rkcanfd_model { RKCANFD_MODEL_RK3568V2 = 0x35682, }; From patchwork Fri Aug 30 19:26:04 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: 13785477 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 8785FCA0FE8 for ; Fri, 30 Aug 2024 19:35:09 +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=x6aqCH5ZXD5sJRISVkV7HSct3AaVNQ/AD0OjPMYedJg=; b=32/kp2LCOpLURy WAnq5CWAbOUXz3E2dLUIpJeoMGGFJqgHF2ugKVpua8K5PcWOC5bL5yB+m+sDo9F6EzLS3j+KuMJV6 YCgxcq2MkFX7Kade49Jc4yw/yqZHaXp78YTc3wars6lrPw6iKPS02pn40wCNsSbebXv4GXHaJOrK2 ThOWv8qELaUP1nzl09lclQADu0JhfcXeUMZkVH/epHMa8rHAQpYzYvY9X7DnsH0+duAOvcw4uzSu4 tosfSsL7tWJZE2KhTIOAgq8jIgrbkk6DP7V/fQZgJnNTyCHk4HmkyBItXsh6/U6O4TDfd3Ce+yOah r4i2cKsiVQkJHA2cW8MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Ok-00000007UaJ-0yFd; Fri, 30 Aug 2024 19:35:06 +0000 Received: from metis.whiteo.stw.pengutronix.de ([185.203.201.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Gx-00000007RQR-0xUu for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:06 +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 1sk7Gu-0006EU-8t for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:00 +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 1sk7Gn-004Dj7-Tn for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:53 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 76FD332E1C0 for ; Fri, 30 Aug 2024 19:26:53 +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 AA29232E0FD; 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 ec69a17b; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:04 +0200 Subject: [PATCH can-next v3 07/20] can: rockchip_canfd: add support for rk3568v3 MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-7-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=2430; i=mkl@pengutronix.de; h=from:subject:message-id; bh=gHcn4OZDSX+A/OQCPXVw5Njr3d5BhPC3JSMfqT4fihA=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzgTN/nn4L8IxlLVyeswobJnPMW7kpp2fMql IMKxHzbLnSJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc4AAKCRAoOKI+ei28 b2mVB/4se9H/tExfU14wiMJK1hvhyPR7kwXQF9faq8pnDmbr4CVsq5FSeUAjtmDTftqgLh6DWpt M8lgpAR5Ui3g2a+jR+iWEpvPbKlS4tjumk6y6Tiyw25pcnDUx4pDrqF1VIO6syYsZpD+09wuCP9 pyEygU9Fezl3KhWI6LvK8FPB1E+5Qdf8e9E5u1YKuZVsE94sNUTA5jUGCAAymS9v1vUl5gojABE bUVcn00AHkShAUtfX+73UMRLd+Cmo0RbeagCyd/6mVU5hm9wK5HXosd0ut2MynVRZR8SLAJD1ep /xJuTlUSBfNWztAo5ycPeSmlwzXFC0HxwkSkvxDN85YdDGpx 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-20240830_122703_326133_04D5FEB1 X-CRM114-Status: GOOD ( 14.58 ) 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 Add the support for the rk3568v3 SoC, the CAN-FD IP core has 7 documented errata. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 20 ++++++++++++++++++++ drivers/net/can/rockchip/rockchip_canfd.h | 1 + 2 files changed, 21 insertions(+) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index 61de6f89cf16..40911bb63623 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -35,11 +35,28 @@ static const struct rkcanfd_devtype_data rkcanfd_devtype_data_rk3568v2 = { RKCANFD_QUIRK_CANFD_BROKEN, }; +/* 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 erratum 5, but tests + * with the rk3568v2 and rk3568v3 show that the RX_FIFO_CNT is + * sometimes too high. In contrast to the errata sheet mark rk3568v3 + * as effected by erratum 5, too. + */ +static const struct rkcanfd_devtype_data rkcanfd_devtype_data_rk3568v3 = { + .model = RKCANFD_MODEL_RK3568V3, + .quirks = RKCANFD_QUIRK_RK3568_ERRATUM_1 | RKCANFD_QUIRK_RK3568_ERRATUM_2 | + RKCANFD_QUIRK_RK3568_ERRATUM_5 | RKCANFD_QUIRK_RK3568_ERRATUM_7 | + RKCANFD_QUIRK_RK3568_ERRATUM_8 | RKCANFD_QUIRK_RK3568_ERRATUM_10 | + RKCANFD_QUIRK_RK3568_ERRATUM_11 | RKCANFD_QUIRK_RK3568_ERRATUM_12 | + RKCANFD_QUIRK_CANFD_BROKEN, +}; + static const char *__rkcanfd_get_model_str(enum rkcanfd_model model) { switch (model) { case RKCANFD_MODEL_RK3568V2: return "rk3568v2"; + case RKCANFD_MODEL_RK3568V3: + return "rk3568v3"; } return ""; @@ -764,6 +781,9 @@ static const struct of_device_id rkcanfd_of_match[] = { { .compatible = "rockchip,rk3568v2-canfd", .data = &rkcanfd_devtype_data_rk3568v2, + }, { + .compatible = "rockchip,rk3568v3-canfd", + .data = &rkcanfd_devtype_data_rk3568v3, }, { /* sentinel */ }, diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 7321027534fb..9b446331fbd0 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -372,6 +372,7 @@ enum rkcanfd_model { RKCANFD_MODEL_RK3568V2 = 0x35682, + RKCANFD_MODEL_RK3568V3 = 0x35683, }; struct rkcanfd_devtype_data { From patchwork Fri Aug 30 19:26:05 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: 13785505 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 10456CA100F for ; Fri, 30 Aug 2024 19:43:51 +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=QxT0A5XY9TTNZwKWwvE9/CwiKrpDAfydHN5PpiIwx3I=; b=ucrZo5uWcu3NUo DaYVWR/lNa6tPsDyZgcq3zMOgYedF+cpcJzungfSHtxFgyEM2cnKnaNaOKyB5ncvTvgfdsmofdf6E Cy3iEXRkYt290cS8buJB3KpiO7kJR1VeacaS0RntNWT25gatCTQkG59PoBSI9Xua5+YXZ9GcJvLmw MmJh6ecnKoRDl34YULPnyBHmJzFFZwM/dSole52YlQRMHA9MLvvMG0iTRpy0nwsD6/nCav24SRpYP 5ckDfUE7PMj1o/GWPdZrKfIxWb+jwTfs//bgzedpZcaMBt4KNBGEtXR5Pj6GVHSu5X9TU3ttHLFYL 3tHzvTr+GFBtHFwIKTkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7X9-00000007W9x-4Aam; Fri, 30 Aug 2024 19:43:47 +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 1sk7HZ-00000007Rmn-2bOu for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:41 +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=O2o35DDud5/YIBL4hwLHTP83QbZaDoW23aqgoTrtLLQ=; b=ZaD5IFpg+icegO6vyRI2qnB2tF ep00rUSyUqt5I3QSPwF4ikTcQ86Ue4Cr68eqo5HDS19e4isCZO45he1pqvkyEvXclDbuw4GrZgJss c7cGuRPBCOsMc2PM3uoZ9UDn8zPPnKDblBMo7obP4YoliOlPFX9db8GJq9gYSeGfJ23CaJaCFmSJv KHrrN5wWiXw7HPJqyvN6grGkT+xpE79EVGbqP7Gn0iHgo2OnPmTnl4G3EM5Fmot9MQxMcRu/r40N0 Hdc1aW2SraObcV43vJbmKtnpau98WEMG5GRvyXdv1SP2c+0nabmxKIJ3LCiJJ+gtgbPJaRHzFyZ1W lG8hUmPQ==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H5-0000000Bk8m-0K4Q for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:30 +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 1sk7Gu-0006EV-88 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:00 +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 1sk7Gn-004DjR-VU for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:54 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 989DF32E1C5 for ; Fri, 30 Aug 2024 19:26:53 +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 C65BD32E100; 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 6919bcdd; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:05 +0200 Subject: [PATCH can-next v3 08/20] can: rockchip_canfd: add notes about known issues MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-8-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=1219; i=mkl@pengutronix.de; h=from:subject:message-id; bh=L9Nl19jQ0rlZqgQunUAoISdoYkyHWfdsG+IX7vgSjoA=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzhwYzVlZ5wgnyOhhah5zZi7aL0R3v/KCscT //i1+bUVYGJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc4QAKCRAoOKI+ei28 bzgDB/95axjXMh3uhwLCVlXLIf/5saGkNkJg7v8r5K6zFqEcBDYC4ezeGNsieKXdZypu6o3ShZb zS7fkisKxMrhMHi+Wxd9FL8zbh2QllzbzVUtI0h1sLQptrcCT/pA8CRU1RgOndN8UNEb6XU6AOY dVU6jGkZeeVMCmM5uJ1Ni1Ec3a0UYdWk7RXHhCWy2AYbrNxsvxXYW5pAY4FA2td01CfmXIAHHJb Yzq6iK5VtkGLzSyp94y4FpV8PC6EaA3Id15mtbTwWidbaPvx448qPLpemWWy2BUpqBa6Jk9sl4C TDOkcS625UYVwPZykUbKY3IuxW3LZ+94Agb4C0ns6V3RYzE2 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-20240830_202721_741100_AD4791D7 X-CRM114-Status: GOOD ( 10.97 ) 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 Even the rk3568v3 has some known issues. Document them together with a reproducer. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 9b446331fbd0..3dafb5e68dc5 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -370,6 +370,26 @@ */ #define RKCANFD_QUIRK_CANFD_BROKEN BIT(12) +/* known issues with rk3568v3: + * + * - Overload situation during high bus load + * To reproduce: + * host: + * # add a 2nd CAN adapter to the CAN bus + * cangen can0 -I 1 -Li -Di -p10 -g 0.3 + * cansequence -rve + * DUT: + * cangen can0 -I2 -L1 -Di -p10 -c10 -g 1 -e + * cansequence -rv -i 1 + * + * - TX starvation after repeated Bus-Off + * To reproduce: + * host: + * sleep 3 && cangen can0 -I2 -Li -Di -p10 -g 0.0 + * DUT: + * cangen can0 -I2 -Li -Di -p10 -g 0.05 + */ + enum rkcanfd_model { RKCANFD_MODEL_RK3568V2 = 0x35682, RKCANFD_MODEL_RK3568V3 = 0x35683, 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: 13785478 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 68CD7CA0FE8 for ; Fri, 30 Aug 2024 19:36:51 +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=GLAD3VLq29XY0VFTIHdCztNx2y4U6yRyB0b+26dIPqg=; b=JPhUg2GGysF5r3 eSdnVR4qaamq6ROY5nhnME362u6b1WAS9fMoFzib0DB5+qyiymIy+ncS/XV9rULDlSJWQUmPdZl8k B4nQnUUJsbcrQpE3/AV0o4f1IchmjtPc4U4GDz9P/Hk40aQQEsjF8pCKAAU/K9+9jw24cCeAM6cGe vtg6tmPBReddQBJIojWcyWy3++1M1CqqxpQ7dTlLacHZumXiJk/HDbZCpUP40R3qMQi/qlmvIDuaA xty3LrH8XtapaqSsfKwvcM1S8YqQrc6s0JCXFqHp2uzO+1rhe2A1UuTp9LwUjlBuRCmH4tSOINDdb lS2uPhzzOIZRToVYJjMw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7QO-00000007Un7-35MU; Fri, 30 Aug 2024 19:36:48 +0000 Received: from metis.whiteo.stw.pengutronix.de ([185.203.201.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Gx-00000007RQT-0g1I for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:07 +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 1sk7Gu-0006En-Gl for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:00 +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 1sk7Go-004Djc-51 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:54 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id AD6DC32E1C7 for ; Fri, 30 Aug 2024 19:26:53 +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 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: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240830_122703_262182_D61B2980 X-CRM114-Status: GOOD ( 19.06 ) 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. 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) From patchwork Fri Aug 30 19:26:07 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: 13785509 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 86543CA0FE8 for ; Fri, 30 Aug 2024 19:43:59 +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=vg4CuLJkbNOUTC/uV8ZM0X8H9L7prpLE5kJFT6XkVR4=; b=N+MFpZjYRZe1aE 90foaRBHMHm0yrb9dmk0OSWyKbRQrnEhLGVrKfBgfXKujMLjCNO3lI6d00OrQXg654vPkbdG5T8gr T/vWJ9om+zG2STBaqEbBpUsUuecBLyS9A+ThholtcUQGgIA4jeut5SqWLLS6WYxhDn2/0K04maxoH bQKRce0x+juRdbfby7hsyFe/cONaTFL9bSzINbdoDMrZkWTIICynB/63Lxfoj6VVLdcc9cnmW/weT 9xu6117gGUSa4RR+uM2T2DgaU+TzdiYh+Q5jB2nMyDebeCzIGK4pLIUvRqK9DwDun6gpbgzK0AjnQ b+NzYndaVnHFL99s9xGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7XH-00000007WGl-3AzF; Fri, 30 Aug 2024 19:43:55 +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 1sk7IX-00000007SGS-0y9t for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:28:41 +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=4SvbK1wjeW/ERXiS9UqxXa1yRBdT2XB7FjvXQTYntM4=; b=rAT+Hw2BSNcbEFo9HejMitPQca FsnOSPGJrpFh2rxu0/bELhOa1ZGTiNrQa/KAFpTXq9wodpKMj6N5l05yF21MIZiO3xwlgaWfiGtDT poWr78Pex77/2nDWYnaMLgTXAXpwtV5aQwc+C3Fl0JRE9f/IppOvGG51ZEsYdXFED2K5wjH8GxqrV eargmFo/xmH/irwdRtvUwMmUdFKBOHpF5FQ5cyIQFTGUt3EcOZCtQqfSr03Np3Ma3mfoa9l/6EvvM vDAgX1D7X5VLG/Pu2D1RuD+oQ1VJU0lh/IAMSpHNBiEmAin12+rUq0a2j9UQcPg5EO3jeOH7S2U9x L4kWNqTA==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H9-0000000Bk8l-0Mdc for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:28:36 +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 1sk7Gu-0006F8-HY for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:00 +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 1sk7Go-004Djo-A9 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:54 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id B06EC32E1C9 for ; Fri, 30 Aug 2024 19:26:53 +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 07AA132E107; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id a697fdc8; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:07 +0200 Subject: [PATCH can-next v3 10/20] can: rockchip_canfd: rkcanfd_register_done(): add warning for erratum 5 MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-10-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=1385; i=mkl@pengutronix.de; h=from:subject:message-id; bh=y0d1r7AKHz0UNb79ePpfEEpNKI/dMUqJeszbCY2XjeA=; b=owGbwMvMwMWoYbHIrkp3Tz7jabUkhrRLMk9WSnI6zdqm+rqubaJv0Hpum/wXK/fkxl9rrD/3x C1yxVvjTkZjFgZGLgZZMUWWAIddbQ+2sdzV3GMXDzOIlQlkCgMXpwBMpHIBB8MUlfxqvebQibof HCpOrjyp1xLP+rfNSWaNuZ7wI0VvhoQYZ3/+u/flZjR4Giqr6H/mYNV9uCxpPUfX7unP/kRz71V /oLHil2p19UP78sJe3Sm3w6XNl71wteHXbixoTjurdE9xUeDKQ3y3nv0XXNKf8V5eYOL6KK8VV2 Q1nZ/d+P5OYHl6llNR5E/j6fNWNzw6I8i7ZMLmq3HGs89Jt4ctKL7Gtshc/1P+gfB2/cw/j2TUc 28orzBQuhp9XEJie8HnWhUHc76zYlWZmwwjVu6sXr6vZX8H8wO5FYFvb6vU/a5NMDHRjDu+7mXu xSldAYnpq4xrOi17fI+8Weci8/6LxZUIZWPDRu/I633vAQ== 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-20240830_202833_347903_593B745F X-CRM114-Status: GOOD ( 11.65 ) 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 Tests on the rk3568v2 and rk3568v3 show that a reduced "baudclk" (e.g. 80MHz, compared to the standard 300MHz) significantly increases the possibility of incorrect FIFO counters, i.e. erratum 5. Print an info message if the clock is below the known good value of 300MHz. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index 40911bb63623..d6c0f2fe8d2b 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -738,6 +738,13 @@ static void rkcanfd_register_done(const struct rkcanfd_priv *priv) FIELD_GET(RKCANFD_REG_RTL_VERSION_MAJOR, dev_id), FIELD_GET(RKCANFD_REG_RTL_VERSION_MINOR, dev_id), priv->devtype_data.quirks); + + if (priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_5 && + priv->can.clock.freq < RKCANFD_ERRATUM_5_SYSCLOCK_HZ_MIN) + netdev_info(priv->ndev, + "Erratum 5: CAN clock frequency (%luMHz) lower than known good (%luMHz), expect degraded performance\n", + priv->can.clock.freq / MEGA, + RKCANFD_ERRATUM_5_SYSCLOCK_HZ_MIN / MEGA); } static int rkcanfd_register(struct rkcanfd_priv *priv) From patchwork Fri Aug 30 19:26:08 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: 13785502 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 226ABCA1009 for ; Fri, 30 Aug 2024 19:43:49 +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=QKFeP7iZ/XKsLZkzrnZQnEYTHdmRlduqaXCAvbP8T9c=; b=DeGB1riGRwn46i wvs6nQntWAuum+uMe8pLlyS432lYx5yPjnRRzvHuAUccbZZyWD0Hv7At8ptYZA3RpEifVBhPvsv+R fk+wMFtn7AbxuYX+bnMrTZXm3rTZEfyhdH93qGOlZyqn94WraK4zZ5BA+yC2Xd/GWz6Jv+oL6GaPF 6O3oKRPKv+6APO9ssB72e5pOwlr/wt484scZfs/1aCrwL79BvCO8CyHQ0adEH+lxcbagLA/Uc5Bx+ s3nQOgSAsfa9j7LEY8rtUVuw1dKXg6gRQPYQXgI8ZbTBW8tSbQPwbWZnbbtuaEWllulA1fiK3icTd G9NdGyhAFevWywdFmy6w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7X8-00000007W87-0LSW; Fri, 30 Aug 2024 19:43:46 +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 1sk7HU-00000007RhE-3bGo for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:37 +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=EWyr825/iJPLApRpfcIyOTf/NfhK8xbO49TVOZ/vAdY=; b=KsThncSJkjpkRvpoORLe/+L+BO 07/eIuT6l8xFnQPn5hsZjqT5wIW92AXI/hDd7bGGAXB/b9X9d6dtq4tlFY36Sqfu7vFBE1DA9LhqH b2mfLlFKwLoIunGNgJZNK/TkSRJDaNQ1vzPvPRAy90aMK6ReFWFmlXT3MU0chAV0GqaOTKUwxlx5D OKP4NptNNZJwQERawMj+vTe544g1fX5r556yCZ53YKzw1FQAbe1eWvp8x29hm2+r58g14q1Pk8x5P IIvVafAotnd8RJ7icCRFn54Wdbb6svZ21yQ5Us/bcN9GtX3m5riHoM3UZcFINjLeTnp3esEyCwdb+ R/xT2zqg==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H7-0000000Bk8n-0okj for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:29 +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 1sk7Gv-0006F9-4u for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:01 +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 1sk7Go-004Djq-9i for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:54 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id B17FD32E1CB for ; Fri, 30 Aug 2024 19:26:53 +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 25CE232E10B; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id e6b381cd; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:08 +0200 Subject: [PATCH can-next v3 11/20] can: rockchip_canfd: add TX PATH MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-11-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=10634; i=mkl@pengutronix.de; h=from:subject:message-id; bh=2q83bv77P0AVNp96dv+i5vR0t+SuKp7hRgUG61dPO0o=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzmfy6HRWFKyEtfiykyn7ddHSngAvEVoZLOt Php/fuLKFGJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc5gAKCRAoOKI+ei28 bx68CACC5w3WKLqtA3r8tEyvMe/xSc65O+ruW7JMFU70kl5IzIv/7t9wuK96eHnfVKqfp7VAodv wibGZeBponUE4JSNvyFIHBsyzbeqWc0hvn4nZRTnZKgN4ae2W7hflFj/mcwxsUbkbjlPXzcdzKj T1rLNfMqqEM+8UQG/xkiMxjNNI5NAwnqSrk6trimy1gnwbXsKXES8Lb+rwA+E2GAnbcWGdtOTYC qjKkhquHNW9HJWTBs/7r7ZOQSxPZuDiTcIisDss7UjIm/ToivBd6GKYKxGXmznySHFHDLFTVc5g GYYBs4WDYeFnMQM8ur+1Jw8EKNc7e4eeexWUOZnhhemI3ZU8 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-20240830_202720_610621_5B111B9F X-CRM114-Status: GOOD ( 24.28 ) 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 IP core has a TX event FIFO. In other IP cores, this type of FIFO usually contains the events that a CAN frame has been successfully sent. However, the IP core on the rk3568v2 the FIFO also holds events of unsuccessful transmission attempts. It turned out that the best way to work around this problem is to set the IP core to self-receive mode (RXSTX), filter out the self-received frames and insert them into the complete TX path. Add a pair new functions to check if 2 struct canfd_frame are equal. The 1st checks if the header of the CAN frames are equal, the 2nd checks if the data portion are equal: - rkcanfd_can_frame_header_equal() - rkcanfd_can_frame_data_equal() Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 6 +- drivers/net/can/rockchip/rockchip_canfd-rx.c | 96 ++++++++++++++++++++++++++ drivers/net/can/rockchip/rockchip_canfd-tx.c | 94 +++++++++++++++++++++++++ drivers/net/can/rockchip/rockchip_canfd.h | 26 +++++++ 4 files changed, 221 insertions(+), 1 deletion(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index d6c0f2fe8d2b..700702e4d2ed 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -229,6 +229,7 @@ static void rkcanfd_chip_start(struct rkcanfd_priv *priv) * - CAN_FD: enable CAN-FD * - AUTO_RETX_MODE: auto retransmission on TX error * - COVER_MODE: RX-FIFO overwrite mode, do not send OVERLOAD frames + * - RXSTX_MODE: Receive Self Transmit data mode * - WORK_MODE: transition from reset to working mode */ reg = rkcanfd_read(priv, RKCANFD_REG_MODE); @@ -236,17 +237,20 @@ static void rkcanfd_chip_start(struct rkcanfd_priv *priv) RKCANFD_REG_MODE_CAN_FD_MODE_ENABLE | RKCANFD_REG_MODE_AUTO_RETX_MODE | RKCANFD_REG_MODE_COVER_MODE | + RKCANFD_REG_MODE_RXSTX_MODE | RKCANFD_REG_MODE_WORK_MODE; /* mask, i.e. ignore: * - TIMESTAMP_COUNTER_OVERFLOW_INT - timestamp counter overflow interrupt * - TX_ARBIT_FAIL_INT - TX arbitration fail interrupt * - OVERLOAD_INT - CAN bus overload interrupt + * - TX_FINISH_INT - Transmit finish interrupt */ priv->reg_int_mask_default = RKCANFD_REG_INT_TIMESTAMP_COUNTER_OVERFLOW_INT | RKCANFD_REG_INT_TX_ARBIT_FAIL_INT | - RKCANFD_REG_INT_OVERLOAD_INT; + RKCANFD_REG_INT_OVERLOAD_INT | + RKCANFD_REG_INT_TX_FINISH_INT; rkcanfd_chip_fifo_setup(priv); rkcanfd_timestamp_init(priv); diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index 609282359bca..650dfd41e0a0 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -4,8 +4,52 @@ // Marc Kleine-Budde // +#include + #include "rockchip_canfd.h" +static bool rkcanfd_can_frame_header_equal(const struct canfd_frame *const cfd1, + const struct canfd_frame *const cfd2, + const bool is_canfd) +{ + const u8 mask_flags = CANFD_BRS | CANFD_ESI | CANFD_FDF; + canid_t mask = CAN_EFF_FLAG; + + if (canfd_sanitize_len(cfd1->len) != canfd_sanitize_len(cfd2->len)) + return false; + + if (!is_canfd) + mask |= CAN_RTR_FLAG; + + if (cfd1->can_id & CAN_EFF_FLAG) + mask |= CAN_EFF_MASK; + else + mask |= CAN_SFF_MASK; + + if ((cfd1->can_id & mask) != (cfd2->can_id & mask)) + return false; + + if (is_canfd && + (cfd1->flags & mask_flags) != (cfd2->flags & mask_flags)) + return false; + + return true; +} + +static bool rkcanfd_can_frame_data_equal(const struct canfd_frame *cfd1, + const struct canfd_frame *cfd2, + const bool is_canfd) +{ + u8 len; + + if (!is_canfd && (cfd1->can_id & CAN_RTR_FLAG)) + return true; + + len = canfd_sanitize_len(cfd1->len); + + return !memcmp(cfd1->data, cfd2->data, len); +} + static unsigned int rkcanfd_fifo_header_to_cfd_header(const struct rkcanfd_priv *priv, const struct rkcanfd_fifo_header *header, @@ -47,6 +91,48 @@ rkcanfd_fifo_header_to_cfd_header(const struct rkcanfd_priv *priv, return len + cfd->len; } +static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv, + const struct canfd_frame *cfd_rx, const u32 ts, + bool *tx_done) +{ + const struct canfd_frame *cfd_nominal; + const struct sk_buff *skb; + unsigned int tx_tail; + + tx_tail = rkcanfd_get_tx_tail(priv); + skb = priv->can.echo_skb[tx_tail]; + if (!skb) { + netdev_err(priv->ndev, + "%s: echo_skb[%u]=NULL tx_head=0x%08x tx_tail=0x%08x\n", + __func__, tx_tail, + priv->tx_head, priv->tx_tail); + + return -ENOMSG; + } + cfd_nominal = (struct canfd_frame *)skb->data; + + /* We RX'ed a frame identical to our pending TX frame. */ + if (rkcanfd_can_frame_header_equal(cfd_rx, cfd_nominal, + cfd_rx->flags & CANFD_FDF) && + rkcanfd_can_frame_data_equal(cfd_rx, cfd_nominal, + cfd_rx->flags & CANFD_FDF)) { + unsigned int frame_len; + + rkcanfd_handle_tx_done_one(priv, ts, &frame_len); + + WRITE_ONCE(priv->tx_tail, priv->tx_tail + 1); + netif_subqueue_completed_wake(priv->ndev, 0, 1, frame_len, + rkcanfd_get_tx_free(priv), + RKCANFD_TX_START_THRESHOLD); + + *tx_done = true; + + return 0; + } + + return 0; +} + static inline bool rkcanfd_fifo_header_empty(const struct rkcanfd_fifo_header *header) { @@ -89,6 +175,16 @@ static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) return 0; } + if (rkcanfd_get_tx_pending(priv)) { + bool tx_done = false; + + err = rkcanfd_rxstx_filter(priv, cfd, header->ts, &tx_done); + if (err) + return err; + if (tx_done) + return 0; + } + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_FDF) skb = alloc_canfd_skb(priv->ndev, &skb_cfd); else diff --git a/drivers/net/can/rockchip/rockchip_canfd-tx.c b/drivers/net/can/rockchip/rockchip_canfd-tx.c index 89c65db3b2dc..668a902f4c2a 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-tx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-tx.c @@ -4,9 +4,103 @@ // Marc Kleine-Budde // +#include + #include "rockchip_canfd.h" +static void rkcanfd_start_xmit_write_cmd(const struct rkcanfd_priv *priv, + const u32 reg_cmd) +{ + rkcanfd_write(priv, RKCANFD_REG_CMD, reg_cmd); +} + int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev) { + struct rkcanfd_priv *priv = netdev_priv(ndev); + u32 reg_frameinfo, reg_id, reg_cmd; + unsigned int tx_head, frame_len; + const struct canfd_frame *cfd; + int err; + u8 i; + + if (can_dropped_invalid_skb(ndev, skb)) + return NETDEV_TX_OK; + + if (!netif_subqueue_maybe_stop(priv->ndev, 0, + rkcanfd_get_tx_free(priv), + RKCANFD_TX_STOP_THRESHOLD, + RKCANFD_TX_START_THRESHOLD)) { + if (net_ratelimit()) + netdev_info(priv->ndev, + "Stopping tx-queue (tx_head=0x%08x, tx_tail=0x%08x, tx_pending=%d)\n", + priv->tx_head, priv->tx_tail, + rkcanfd_get_tx_pending(priv)); + + return NETDEV_TX_BUSY; + } + + cfd = (struct canfd_frame *)skb->data; + + if (cfd->can_id & CAN_EFF_FLAG) { + reg_frameinfo = RKCANFD_REG_FD_FRAMEINFO_FRAME_FORMAT; + reg_id = FIELD_PREP(RKCANFD_REG_FD_ID_EFF, cfd->can_id); + } else { + reg_frameinfo = 0; + reg_id = FIELD_PREP(RKCANFD_REG_FD_ID_SFF, cfd->can_id); + } + + if (cfd->can_id & CAN_RTR_FLAG) + reg_frameinfo |= RKCANFD_REG_FD_FRAMEINFO_RTR; + + if (can_is_canfd_skb(skb)) { + reg_frameinfo |= RKCANFD_REG_FD_FRAMEINFO_FDF; + + if (cfd->flags & CANFD_BRS) + reg_frameinfo |= RKCANFD_REG_FD_FRAMEINFO_BRS; + + reg_frameinfo |= FIELD_PREP(RKCANFD_REG_FD_FRAMEINFO_DATA_LENGTH, + can_fd_len2dlc(cfd->len)); + } else { + reg_frameinfo |= FIELD_PREP(RKCANFD_REG_FD_FRAMEINFO_DATA_LENGTH, + cfd->len); + } + + tx_head = rkcanfd_get_tx_head(priv); + reg_cmd = RKCANFD_REG_CMD_TX_REQ(tx_head); + + rkcanfd_write(priv, RKCANFD_REG_FD_TXFRAMEINFO, reg_frameinfo); + rkcanfd_write(priv, RKCANFD_REG_FD_TXID, reg_id); + for (i = 0; i < cfd->len; i += 4) + rkcanfd_write(priv, RKCANFD_REG_FD_TXDATA0 + i, + *(u32 *)(cfd->data + i)); + + frame_len = can_skb_get_frame_len(skb); + err = can_put_echo_skb(skb, ndev, tx_head, frame_len); + if (!err) + netdev_sent_queue(priv->ndev, frame_len); + + WRITE_ONCE(priv->tx_head, priv->tx_head + 1); + + rkcanfd_start_xmit_write_cmd(priv, reg_cmd); + + netif_subqueue_maybe_stop(priv->ndev, 0, + rkcanfd_get_tx_free(priv), + RKCANFD_TX_STOP_THRESHOLD, + RKCANFD_TX_START_THRESHOLD); + return NETDEV_TX_OK; } + +void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts, + unsigned int *frame_len_p) +{ + struct net_device_stats *stats = &priv->ndev->stats; + unsigned int tx_tail; + + tx_tail = rkcanfd_get_tx_tail(priv); + stats->tx_bytes += + can_rx_offload_get_echo_skb_queue_timestamp(&priv->offload, + tx_tail, ts, + frame_len_p); + stats->tx_packets++; +} diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index c775e75a2740..a4688411e586 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -471,10 +471,36 @@ rkcanfd_get_timestamp(const struct rkcanfd_priv *priv) return rkcanfd_read(priv, RKCANFD_REG_TIMESTAMP); } +static inline unsigned int +rkcanfd_get_tx_head(const struct rkcanfd_priv *priv) +{ + return READ_ONCE(priv->tx_head) & (RKCANFD_TXFIFO_DEPTH - 1); +} + +static inline unsigned int +rkcanfd_get_tx_tail(const struct rkcanfd_priv *priv) +{ + return READ_ONCE(priv->tx_tail) & (RKCANFD_TXFIFO_DEPTH - 1); +} + +static inline unsigned int +rkcanfd_get_tx_pending(const struct rkcanfd_priv *priv) +{ + return READ_ONCE(priv->tx_head) - READ_ONCE(priv->tx_tail); +} + +static inline unsigned int +rkcanfd_get_tx_free(const struct rkcanfd_priv *priv) +{ + return RKCANFD_TXFIFO_DEPTH - rkcanfd_get_tx_pending(priv); +} + int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv); void rkcanfd_timestamp_init(struct rkcanfd_priv *priv); int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev); +void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts, + unsigned int *frame_len_p); #endif From patchwork Fri Aug 30 19:26:09 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: 13785507 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 BAC7DCA1010 for ; Fri, 30 Aug 2024 19:43: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=meLmuWQ08XHhdZJYV2l+coA8/4skZvAtO2ulONBwTow=; b=1v+gRj70iM5t1m NaPH9qK5SoVYfq3kxgSlvCxcdfYT/gHV+VGT8STi8aWo2ymfyyKnFSWiR+xEb84CwPxQ9dG2SU6Rw 2DHN+fKjNbiHmF3G3QlSGIxFDFaFoUl1AhReVXe36PvlMdsXstfOcjB0nDcNWi7wb/TwFeElErfzl hTt/jaj1obhNVahdzbNN2N0EZdOp54uKy+K92dli4PfloTiH+yAExhJOptVwsQ9Wq/Mbdfvkvw4aa /9AzvdqbGUPwVPr6VlRcOYLvnm+jUtQxGcWI0LbWrtpisgY6YtidU+LmkRVLqTdGyM6WLi0JgRaxK 882Ijl+9Fr3fQSUp5iSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7XB-00000007WB8-0VLV; Fri, 30 Aug 2024 19:43: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 1sk7IE-00000007SBq-1gUF for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:28:22 +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=Nnxfi0agsRF9x2Zf79yA2so9KLsTA76oklTN1hK5+eI=; b=lrHI2v6/i2BkKhc+DdQiasdx/O KA6j+hiFqYArELPEVFQ25LCswGDExezrdgevbVLxonOBhP9tHFb+05ZVmkEz+eebQKGbbJCulWaDa wRGaEeVZ9TdFnAFTlea7OKXwGj4gG9vIKPOCFhqULRTyoA1fi+w+foaEYTrjnaYT4ksurhvz1aK9w 6t4tEyBrXOhED7Zw7gO+g7YjRXY6moxUrJAEceyILlpWbXzyWcN5dIHFNAbR/2MWkEpmkDSDCAvZt p/mlJ2blu4wUeUNEewstyrqCx+G18aVMSC4RUNI0jzO6/1OnF+jHj3MfuZAn4UXFUeSK5zwnUh/rr C+meb8lQ==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7HB-0000000Bk8p-0dZD for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:28:12 +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 1sk7Gv-0006FE-Ub for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:02 +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 1sk7Go-004Dju-Br for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:54 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id D13F332E1CE for ; Fri, 30 Aug 2024 19:26:53 +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 3B7D832E10D; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id ae84f775; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:09 +0200 Subject: [PATCH can-next v3 12/20] can: rockchip_canfd: implement workaround for erratum 6 MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-12-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=5063; i=mkl@pengutronix.de; h=from:subject:message-id; bh=5JeJQ42d2DMhVn68wwekCxp+TLXGZIVkZeddV9SsMsc=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzncoFakpn/ITkHLZo2lljs7bF0J4i5RLq4J P7TxPr5pEOJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc5wAKCRAoOKI+ei28 b9dqCACMC2WCgPuxVPZxoUi7FktsCsH+BiQ3oQjQFHOpOqI+Nvkhn82v40oQ2WqEuPHci4oFqz0 prWzjaXQjlgzqTquWpqA2nuNmGqEmCWB8QtXm8XUgP4qAeBh4bvyhtwqfXmGxVBB+36MddO2JHc wyPPPPEZ2JgMxbQ2gjxsEagX8shE+qjd6tayfIILRVIktA09hx/ojD1ZyI3GrO/pBT2WUjB/gni ybzkxeol8eT3tlja9obJJgoat4k/KPBu9oJYiOWpxBb/lhIy1TwSLYvDI6W5ekW937deNo7fEJx ITuR966Y5hzeVbf3xULIcWz7q8Es63R8RG9UMGWDPOk0vHYS 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-20240830_202807_498917_6B76494E X-CRM114-Status: GOOD ( 20.92 ) 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: | The CAN controller's transmission of extended frames may | intermittently change into standard frames. | | When using the CAN controller to send extended frames, if the | 'tx_req' is configured as 1 and coincides with the internal | transmission point, the extended frame will be transmitted onto the | bus in the format of a standard frame. To work around Erratum 6, the driver is in self-receiving mode (RXSTX) and all received CAN frames are passed through rkcanfd_rxstx_filter(). Add a check in rkcanfd_rxstx_filter() whether the received frame corresponds to the current outgoing frame, but the extended CAN ID has been mangled to a standard ID. In this case re-send the original CAN frame. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-rx.c | 44 ++++++++++++++++++++++++++++ drivers/net/can/rockchip/rockchip_canfd-tx.c | 8 +++++ drivers/net/can/rockchip/rockchip_canfd.h | 19 ++++++++++++ 3 files changed, 71 insertions(+) diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index 650dfd41e0a0..31cee3362f1e 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -95,6 +95,7 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv, const struct canfd_frame *cfd_rx, const u32 ts, bool *tx_done) { + struct net_device_stats *stats = &priv->ndev->stats; const struct canfd_frame *cfd_nominal; const struct sk_buff *skb; unsigned int tx_tail; @@ -130,6 +131,49 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv, return 0; } + if (!(priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_6)) + return 0; + + /* Erratum 6: Extended frames may be send as standard frames. + * + * Not affected if: + * - TX'ed a standard frame -or- + * - RX'ed an extended frame + */ + if (!(cfd_nominal->can_id & CAN_EFF_FLAG) || + (cfd_rx->can_id & CAN_EFF_FLAG)) + return 0; + + /* Not affected if: + * - standard part and RTR flag of the TX'ed frame + * is not equal the CAN-ID and RTR flag of the RX'ed frame. + */ + if ((cfd_nominal->can_id & (CAN_RTR_FLAG | CAN_SFF_MASK)) != + (cfd_rx->can_id & (CAN_RTR_FLAG | CAN_SFF_MASK))) + return 0; + + /* Not affected if: + * - length is not the same + */ + if (cfd_nominal->len != cfd_rx->len) + return 0; + + /* Not affected if: + * - the data of non RTR frames is different + */ + if (!(cfd_nominal->can_id & CAN_RTR_FLAG) && + memcmp(cfd_nominal->data, cfd_rx->data, cfd_nominal->len)) + return 0; + + /* Affected by Erratum 6 */ + + *tx_done = true; + + stats->tx_packets++; + stats->tx_errors++; + + rkcanfd_xmit_retry(priv); + return 0; } diff --git a/drivers/net/can/rockchip/rockchip_canfd-tx.c b/drivers/net/can/rockchip/rockchip_canfd-tx.c index 668a902f4c2a..e98e7a836b83 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-tx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-tx.c @@ -14,6 +14,14 @@ static void rkcanfd_start_xmit_write_cmd(const struct rkcanfd_priv *priv, rkcanfd_write(priv, RKCANFD_REG_CMD, reg_cmd); } +void rkcanfd_xmit_retry(struct rkcanfd_priv *priv) +{ + const unsigned int tx_head = rkcanfd_get_tx_head(priv); + const u32 reg_cmd = RKCANFD_REG_CMD_TX_REQ(tx_head); + + rkcanfd_start_xmit_write_cmd(priv, reg_cmd); +} + int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev) { struct rkcanfd_priv *priv = netdev_priv(ndev); diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index a4688411e586..3fe6ddcdd8ac 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -342,6 +342,24 @@ /* Erratum 6: The CAN controller's transmission of extended frames may * intermittently change into standard frames + * + * Work around this issue by activating self reception (RXSTX). If we + * have pending TX CAN frames, check all RX'ed CAN frames in + * rkcanfd_rxstx_filter(). + * + * If it's a frame we've send and it's OK, call the TX complete + * handler: rkcanfd_handle_tx_done_one(). Mask the TX complete IRQ. + * + * If it's a frame we've send, but the CAN-ID is mangled, resend the + * original extended frame. + * + * To reproduce: + * host: + * canfdtest -evx -g can0 + * candump any,0:80000000 -cexdtA + * dut: + * canfdtest -evx can0 + * ethtool -S can0 */ #define RKCANFD_QUIRK_RK3568_ERRATUM_6 BIT(5) @@ -499,6 +517,7 @@ int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv); void rkcanfd_timestamp_init(struct rkcanfd_priv *priv); +void rkcanfd_xmit_retry(struct rkcanfd_priv *priv); int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev); void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts, unsigned int *frame_len_p); From patchwork Fri Aug 30 19:26:10 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: 13785503 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 F2B50CA100E for ; Fri, 30 Aug 2024 19:43:49 +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=I/sUylnTvdE30O/4KFRD3/YnyUiU06emFBx2nbwSD+8=; b=K8DlLzQxWDGlqw B2138I4p2aM9nx7K8349BvRoLNPP6mSK54GR65mlO60CHyRu424RK3ygJKDf8J5pwzpqusN53u3ge bT7mx1NHB5q+5t4T9hFsOI+LIxNxy9XJNywSWkO8mRFLLNd85QNxeyKJU+NHsPIWzXBQzgcffwG3Y n1pHEHfUB8JEHKvrDSOuNgoCJfUtvpCAg3sx6lYY8e30j/OOqvti4U3UKta+LNZH5HEO501/fm+iP 7Nr+AKcOWlQqzdADIr5u0jFqnWobulQNXlXeiYzaghgJkbGYDBZ1x6QwEzwGWx07tmWDlq1wZUdgT p+xfWFsA8/Bo/JSFHmBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7X8-00000007W8u-3gjF; Fri, 30 Aug 2024 19:43:46 +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 1sk7HV-00000007Rhm-06aq for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:37 +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=NjgMAzXyB328mv1ytJ0sfk4/u5T+J0Dhf8YdBAfzs8o=; b=GnHEwo63D24bHKmOIX4Sz5tXhD KydAqtVqqTelnIlDXc/KNbMYC3jO9bvvZ96iUOhm8m77Cy7Pvhu3kIK+xr1zmssX3NdbAGKBYBqad xVmWK922Z8H7fpfdUsuy3lLYixZkBB5opZ43IeZthLJD19iSSBt/wKseNmSP8yyLxqAsORyEmcX8D FB6F95I4YgU2rSk6xEy6B6CsaMyNHzuB1UYoQv+ZxVLWKTLnV2vU3ChgPY1dWw6daeAj4+QYYoZ+M nwQYhYLaHbEQSfnHdh1nFX67bMoNQ/Y9DDpO9ppYGIk4heHFwd+13PXus8NqCudL/MadbCCce+cHA Czzl7fXw==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H8-0000000Bk8o-0ET9 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:29 +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 1sk7Gv-0006FZ-80 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:01 +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 1sk7Go-004Dk7-E2 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:54 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id D73C632E1D0 for ; Fri, 30 Aug 2024 19:26:53 +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 53CEE32E110; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id a5043944; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:10 +0200 Subject: [PATCH can-next v3 13/20] can: rockchip_canfd: implement workaround for erratum 12 MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-13-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=1861; i=mkl@pengutronix.de; h=from:subject:message-id; bh=S2FPUCLf0HBw5+QixJBEj6Z5Avphz5THqZA6bqbQ93k=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzpP6wKpibmHfjLF1qfFuihHr56ftTgVnR6z LIlpPNt6IyJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc6QAKCRAoOKI+ei28 bx5dB/4yPBgAM53a48MOSFzCdZDUgDWQAgUuVlJECEna86uJhVcJos/7VYOYM9ogf04TXi7Ko3U NvzsxRchuy8RMckHiY5uv6QNDN6D0kzox+eBdnaXLt8JD4p7M8RY8oowyeHDfhhUuzkxux9GigX SZQpPLwpb7MawqNMFgcKGaL5gNIgQRz58nRIIHDc8gVeVXtxcI8WzNbjfHIstE2NiKzf4AYdfQW tU8h0fQ+h3JJSK4hPr4TqW9aaVr6gKMD9rjzQZ8ExQ/xsfFIAbvwtp8++0R5qOjn29F3zMJx3yP dh/AkVp8kUWwlvdOuH43+WPPVv/Pu+QTZvVV61ycv2i/aSXn 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-20240830_202720_501810_9DB36251 X-CRM114-Status: GOOD ( 13.42 ) 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: | A dominant bit at the third bit of the intermission may cause a | transmission error. | | When sampling the third bit of the intermission as a dominant bit, if | tx_req is configured to transmit extended frames at this time, the | extended frame may be sent to the bus in the format of a standard | frame. The extended frame will be sent as a standard frame and will not | result in error frames Turn on "Interframe Spaceing RX Mode" only during TX to work around erratum 12, according to rock-chip: | Spaceing RX Mode = 1, the third Bit between frames cannot receive | and send, and the fourth Bit begins to receive and send. | | Spaceing RX Mode = 0, allowing the third Bit between frames to | receive and send. Message-ID: Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-tx.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/net/can/rockchip/rockchip_canfd-tx.c b/drivers/net/can/rockchip/rockchip_canfd-tx.c index e98e7a836b83..9db6d90a4e7f 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-tx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-tx.c @@ -11,7 +11,14 @@ static void rkcanfd_start_xmit_write_cmd(const struct rkcanfd_priv *priv, const u32 reg_cmd) { + if (priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_12) + rkcanfd_write(priv, RKCANFD_REG_MODE, priv->reg_mode_default | + RKCANFD_REG_MODE_SPACE_RX_MODE); + rkcanfd_write(priv, RKCANFD_REG_CMD, reg_cmd); + + if (priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_12) + rkcanfd_write(priv, RKCANFD_REG_MODE, priv->reg_mode_default); } void rkcanfd_xmit_retry(struct rkcanfd_priv *priv) From patchwork Fri Aug 30 19:26:11 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: 13785501 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 8ED76CA1009 for ; Fri, 30 Aug 2024 19:42:57 +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=KE7IbEp6SkyXQQHEEineaVQwad3jnf6/xAhpkTWJgJI=; b=j4tgJX/RLwUzuv 3NUnFXlzmZOy//UCP90J/741do43uK7hAfA2w9N1mr2OR5kcPywu6XaHIr4GwB2YpacwqtEsf1gXx WaMPcqklh9Gt5bE7+PrvV3spvC2JtQLPXD83WrvKo9ZeFR0y+PsYlgmcF5lFqqKGhTb5ve71alO9F GVu41IPKlTE/YwHNWcyYFaY+/nyfsghOT067hFsuzwlwivLqssOF95IHQohQ/VtcROC6GZ/Tl0yvd XIWifByBC+a/cA9TSsMFeFj76YVQPjf25XNXtSRamzDcfrkXLBxbd1YHzGtg1YIwwzmLnz2O4IEcw S5KFYrNE5ToJmvj27dxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7WH-00000007VuQ-2zs3; Fri, 30 Aug 2024 19:42:53 +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 1sk7HO-00000007RdZ-0F1h for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:30 +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=FpR/UK/AYumXQ1qWK9ZkOXcjNVhkkvODXdN+USv6x9E=; b=dqqnnEEKhmh8RjNl5Im9o3goTc QIVR5UPZlPTrIRzd4JsLaQDbPYMrk/+JN87bm9OHg0GcnH/mL/dO5UfrnBfBCZ3RBbFSU7jk0hDYA iM/IHIMEkJow4wkK81A5fKuqxa30javCpQYZLb0hT6qEcZkaE7vi3A1N9BAOYac/9/03ClE/rq1t+ P03OrYHyOco5d14mS3UERlTsc2Q1dmzr/LRSVOQNVE3YssQPxppB3QH0e7+b5i82GCXfDWQfUccS8 1/I/XGaJAQN3mmvHgMMVv0poT9xj64F+EfNhfrr7PLi0ZDKuvTYMjws/5DIQNHPRCHfpbZbtCivf/ Bh1Gaddg==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H1-0000000Bk8s-3Xi3 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:22 +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 1sk7Gw-0006FT-7k for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:02 +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 1sk7Go-004DkL-EY for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:54 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id ECD1832E1D6 for ; Fri, 30 Aug 2024 19:26:53 +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 66FC832E113; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id 4a7dea85; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:11 +0200 Subject: [PATCH can-next v3 14/20] can: rockchip_canfd: rkcanfd_get_berr_counter_corrected(): work around broken {RX,TX}ERRORCNT register MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-14-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=6870; i=mkl@pengutronix.de; h=from:subject:message-id; bh=DJ+fhm2Yj2TmsuGIAwwI2LYdWTC/F0r0cDuJqYQdeZk=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzqYIJEK7iHbPJ+hnw1BQMI1jU1YdhsAlVxi 0fnn0tmrb6JATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc6gAKCRAoOKI+ei28 b28gCACJ2SKUL8GptaakLs71H5Pd/rF0QUJjljnAwEhstL9Juua7uBc3dDxBc+ac4Sl/thXJ7h0 rZe1uSVhujtY/Buv1VUBj3l375wsLpNwes0wUeFlQaiCQueiGS2UVpA8279OhOKqIBPRuXIYH/l 0/HDl0qh+rv14SHAhgDs8J7y87NmGHZFmg8tYluQU3UrFUFbHUc3fVaS/DuAL3ZrAb8b+e/HyKp L9vfGO/JhPTo0VcereXA+bUrPAm+KUvAoHojUl0g5WM81cZnXgdPz92QP+pL4qp9sxgRLn6x/2+ 4ZEPyHDrMOYBjqbspmrQ/PPaY919TsX7yTha7fRDWmmlQVXw 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-20240830_202716_275826_15C8CC79 X-CRM114-Status: GOOD ( 20.60 ) 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 Tests show that sometimes both CAN bus error counters read 0x0, even if the controller is in warning mode (RKCANFD_REG_STATE_ERROR_WARNING_STATE in RKCANFD_REG_STATE set). To work around this issue, if both error counters read from hardware are 0x0, use the structure priv->bec, otherwise save the read value in priv->bec. In rkcanfd_handle_rx_int_one() decrement the priv->bec.rxerr for successfully RX'ed CAN frames. In rkcanfd_handle_tx_done_one() decrement the priv->bec.txerr for successfully TX'ed CAN frames. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 50 ++++++++++++++++++++++---- drivers/net/can/rockchip/rockchip_canfd-rx.c | 15 ++++++++ drivers/net/can/rockchip/rockchip_canfd-tx.c | 8 +++++ drivers/net/can/rockchip/rockchip_canfd.h | 2 ++ 4 files changed, 69 insertions(+), 6 deletions(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index 700702e4d2ed..cf176180a282 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -159,11 +159,47 @@ static int rkcanfd_set_bittiming(struct rkcanfd_priv *priv) return 0; } -static void rkcanfd_get_berr_counter_raw(struct rkcanfd_priv *priv, - struct can_berr_counter *bec) +static void rkcanfd_get_berr_counter_corrected(struct rkcanfd_priv *priv, + struct can_berr_counter *bec) { + struct can_berr_counter bec_raw; + u32 reg_state; + bec->rxerr = rkcanfd_read(priv, RKCANFD_REG_RXERRORCNT); bec->txerr = rkcanfd_read(priv, RKCANFD_REG_TXERRORCNT); + bec_raw = *bec; + + /* Tests show that sometimes both CAN bus error counters read + * 0x0, even if the controller is in warning mode + * (RKCANFD_REG_STATE_ERROR_WARNING_STATE in RKCANFD_REG_STATE + * set). + * + * In case both error counters read 0x0, use the struct + * priv->bec, otherwise save the read value to priv->bec. + * + * rkcanfd_handle_rx_int_one() handles the decrementing of + * priv->bec.rxerr for successfully RX'ed CAN frames. + * + * Luckily the controller doesn't decrement the RX CAN bus + * error counter in hardware for self received TX'ed CAN + * frames (RKCANFD_REG_MODE_RXSTX_MODE), so RXSTX doesn't + * interfere with proper RX CAN bus error counters. + * + * rkcanfd_handle_tx_done_one() handles the decrementing of + * priv->bec.txerr for successfully TX'ed CAN frames. + */ + if (!bec->rxerr && !bec->txerr) + *bec = priv->bec; + else + priv->bec = *bec; + + reg_state = rkcanfd_read(priv, RKCANFD_REG_STATE); + netdev_vdbg(priv->ndev, + "%s: Raw/Cor: txerr=%3u/%3u rxerr=%3u/%3u Bus Off=%u Warning=%u\n", + __func__, + bec_raw.txerr, bec->txerr, bec_raw.rxerr, bec->rxerr, + !!(reg_state & RKCANFD_REG_STATE_BUS_OFF_STATE), + !!(reg_state & RKCANFD_REG_STATE_ERROR_WARNING_STATE)); } static int rkcanfd_get_berr_counter(const struct net_device *ndev, @@ -176,7 +212,7 @@ static int rkcanfd_get_berr_counter(const struct net_device *ndev, if (err) return err; - rkcanfd_get_berr_counter_raw(priv, bec); + rkcanfd_get_berr_counter_corrected(priv, bec); pm_runtime_put(ndev->dev.parent); @@ -252,6 +288,8 @@ static void rkcanfd_chip_start(struct rkcanfd_priv *priv) RKCANFD_REG_INT_OVERLOAD_INT | RKCANFD_REG_INT_TX_FINISH_INT; + memset(&priv->bec, 0x0, sizeof(priv->bec)); + rkcanfd_chip_fifo_setup(priv); rkcanfd_timestamp_init(priv); rkcanfd_set_bittiming(priv); @@ -488,7 +526,7 @@ static int rkcanfd_handle_error_int(struct rkcanfd_priv *priv) if (cf) { struct can_berr_counter bec; - rkcanfd_get_berr_counter_raw(priv, &bec); + rkcanfd_get_berr_counter_corrected(priv, &bec); cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR | CAN_ERR_CNT; cf->data[6] = bec.txerr; cf->data[7] = bec.rxerr; @@ -517,7 +555,7 @@ static int rkcanfd_handle_state_error_int(struct rkcanfd_priv *priv) u32 timestamp; int err; - rkcanfd_get_berr_counter_raw(priv, &bec); + rkcanfd_get_berr_counter_corrected(priv, &bec); can_state_get_by_berr_counter(ndev, &bec, &tx_state, &rx_state); new_state = max(tx_state, rx_state); @@ -570,7 +608,7 @@ rkcanfd_handle_rx_fifo_overflow_int(struct rkcanfd_priv *priv) if (skb) return 0; - rkcanfd_get_berr_counter_raw(priv, &bec); + rkcanfd_get_berr_counter_corrected(priv, &bec); cf->can_id |= CAN_ERR_CRTL | CAN_ERR_CNT; cf->data[1] = CAN_ERR_CRTL_RX_OVERFLOW; diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index 31cee3362f1e..eff08948840c 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -167,6 +167,13 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv, /* Affected by Erratum 6 */ + /* Manual handling of CAN Bus Error counters. See + * rkcanfd_get_corrected_berr_counter() for detailed + * explanation. + */ + if (priv->bec.txerr) + priv->bec.txerr--; + *tx_done = true; stats->tx_packets++; @@ -229,6 +236,14 @@ static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) return 0; } + /* Manual handling of CAN Bus Error counters. See + * rkcanfd_get_corrected_berr_counter() for detailed + * explanation. + */ + if (priv->bec.rxerr) + priv->bec.rxerr = min(CAN_ERROR_PASSIVE_THRESHOLD, + priv->bec.rxerr) - 1; + if (header->frameinfo & RKCANFD_REG_FD_FRAMEINFO_FDF) skb = alloc_canfd_skb(priv->ndev, &skb_cfd); else diff --git a/drivers/net/can/rockchip/rockchip_canfd-tx.c b/drivers/net/can/rockchip/rockchip_canfd-tx.c index 9db6d90a4e7f..f8e74e814b3b 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-tx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-tx.c @@ -113,6 +113,14 @@ void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts, unsigned int tx_tail; tx_tail = rkcanfd_get_tx_tail(priv); + + /* Manual handling of CAN Bus Error counters. See + * rkcanfd_get_corrected_berr_counter() for detailed + * explanation. + */ + if (priv->bec.txerr) + priv->bec.txerr--; + stats->tx_bytes += can_rx_offload_get_echo_skb_queue_timestamp(&priv->offload, tx_tail, ts, diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 3fe6ddcdd8ac..67f135fbcfb9 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -459,6 +459,8 @@ struct rkcanfd_priv { u32 reg_int_mask_default; struct rkcanfd_devtype_data devtype_data; + struct can_berr_counter bec; + struct reset_control *reset; struct clk_bulk_data *clks; int clks_num; From patchwork Fri Aug 30 19:26:12 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: 13785489 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 03988CA1009 for ; Fri, 30 Aug 2024 19:39:33 +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=BRL+OxoS3oya2sDNkHjqqYErfakH0Ps/D3JO4lricNw=; b=dZEFHLvkgw/rZo GsjkMagF2AG/GikweI7RRSqXaBZTDYmFkElPsqXaTnAuV7fHzWq15o0+n8KifVDgi+yGeLdkaCEyc PBJXSnn0a63g7T9fdvJgVbrYXdpHW5N+dvBsdR4xS0dwzm4Hj/ksgeihg8uuHUUIP/YJVwx/76RVi +yHLvwtiYKp1xorti9c94XOD8e0cvH/50jusRsCn6eLWwn/ZiudxVLhRa7QBmb9Hk8bRGAWNpx414 QuAalfwjXFXk+nKsYky7CxQAemiRGE3mAifW+vpCV4y2lKLIArFmnHfiiUdlMSP9FNPL/HAKQTFd0 zgvK0RtnbSsdgPeWGINQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Sw-00000007VMf-0GWQ; Fri, 30 Aug 2024 19:39:26 +0000 Received: from metis.whiteo.stw.pengutronix.de ([185.203.201.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H3-00000007RUZ-0TVV for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:12 +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 1sk7H0-0006Mo-Nc for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:06 +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 1sk7Gs-004Ds3-TI for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:59 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 8A14332E282 for ; Fri, 30 Aug 2024 19:26:58 +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 7B9CA32E116; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id 60ce9336; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:12 +0200 Subject: [PATCH can-next v3 15/20] can: rockchip_canfd: add stats support for errata workarounds MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-15-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=6702; i=mkl@pengutronix.de; h=from:subject:message-id; bh=Qq58LRu4MZgbExO9gq+wk7eqvvt3AfhiJu8u44wVz9M=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzs47gZRhzQm1197UhBA41DjgqvQmNvLpJ5m JkBHCb2YkqJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc7AAKCRAoOKI+ei28 bximB/4vumJG+dPsQDw4QJt8R2oLJ+CS8UIaPkkG1FUMBgt+TKgRYXon0Hy9AKDFkdrOr7TPYDZ iMm0ICWXZvEgd14HxZ4wectgzMzudShOB5RwKSduRNr41FNyRlv+M4lh1TqVwiqwTEf11EnRhWQ 3eXofGuYtpZNXZa7sFpqcxBfuEa18OxZx8x26/M+YcmRG32JJ6V/3w/a3i49WsA+C/lHlClQaPa TMzedDJJsPMHkKE9r9wulDPv/OolzMwRcBP5p1SCVBkiVAYIgFzkBCfjV5CvbB/Kih+ZvaRMiMq 2FgHoQ2o4/tyXDPQwe58mnjR2kenx5JydCqxtUYkyjJthB0h 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-20240830_122709_553374_A598461C X-CRM114-Status: GOOD ( 22.29 ) 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. 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); From patchwork Fri Aug 30 19:26:13 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: 13785490 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 27DD5CA1009 for ; Fri, 30 Aug 2024 19:40:21 +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=Zt06IM/7awOM2vduUkUl5OMYJFRuuPA53/gjF35j1SY=; b=YHd5NbyN0nG+GC Rq/vwQymR8Ugy/9t8mXKLNJOn0Fpii47qJ/QMXHjYToxGkKvXN5mW1SvHymoJAfrMVS4L/mJS5aaK 8Xxi7kvtnvpv1PRg6OMYfaSakknq7CYjV0pWLSIEgoAdeaMx/G280F15dTPMM34yykVgTWfvbHOio TbaG80yR3+CG2t1LTrf0Nk0rpRioFU1ndDwB1NuNoUzV2y92QxaSTEz3ZD7pLd4rRRbIS4TG4gdA1 +ssbBeYhSEdhJ0s8YAB5nhJLUbNc2V0YTG4ouDQb1/nq5c3grN0egWYbeCz9lJkiIBAjRMoTPDo0O RXJFk/9CZsNrA8NMWD4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7Tm-00000007VUh-0naU; Fri, 30 Aug 2024 19:40:18 +0000 Received: from metis.whiteo.stw.pengutronix.de ([185.203.201.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H6-00000007RWy-0dI7 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:13 +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 1sk7H4-0006Wr-H5 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:10 +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 1sk7Gx-004DxI-Va for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:04 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 9F84932E2CB for ; Fri, 30 Aug 2024 19:27:03 +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 8E6D132E118; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id c1f7dc44; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:13 +0200 Subject: [PATCH can-next v3 16/20] can: rockchip_canfd: prepare to use full TX-FIFO depth MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-16-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=4154; i=mkl@pengutronix.de; h=from:subject:message-id; bh=bzaZeLqVpFxgzGtxEbJ+YPhAuZF1PlCPIMtvxQ/VRUA=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzt6d6pYBLK48sMQGSY882lzbTcdr+7oJsrB mrUjTtmcLiJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc7QAKCRAoOKI+ei28 b30oB/9naTa2umyplhGaEfflNa5JhTvYvmeKclM+xu9sV+u9MtvGvr2NCQHeJNazDIJT8bRiYdN O2bqwe44lCnbl81sr8yu65bIBkHywW7G8N6M65RWODarTfGz4SVwBYtQktODBEYVDqbU+PHTsT5 su4RySf58wUJ+8nJQHkWKfbUMjIGAiIpnSrRxBkgJDBbFt6ihskwbJoPW6zMv5pgWdKVYw5j03F 5kOqrkMfMqyAfSUABQe7sDos46UlGAz4GoszjFu7uDIOl3Hrg1dmlBDxOnXgoQ3O1sYAT5VPN8H KcJDsy5ey/wDipODrnv3ZbJE58F2kegnR+ASjoNQFtYHTsxJ 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-20240830_122712_256925_C5B6E3CF X-CRM114-Status: GOOD ( 17.80 ) 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 So far the TX-FIFO is only used with a depth of 1, although the hardware offers a depth of 2. The workaround for the chips that are affected by erratum 6, i.e. EFF frames may be send as standard frames, is to re-send the EFF frame. This means the driver cannot queue the next frame for sending, as long ad the EFF frame has not been successfully send out. Introduce rkcanfd_get_effective_tx_free() that returns "0" space in the TX-FIFO if an EFF frame is pending and the actual free space in the TX-FIFO otherwise. Then replace rkcanfd_get_tx_free() with rkcanfd_get_effective_tx_free() everywhere. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-rx.c | 2 +- drivers/net/can/rockchip/rockchip_canfd-tx.c | 38 ++++++++++++++++++++++++++-- drivers/net/can/rockchip/rockchip_canfd.h | 1 + 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index 9f72483dab18..bacef5e5dc39 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -124,7 +124,7 @@ static int rkcanfd_rxstx_filter(struct rkcanfd_priv *priv, WRITE_ONCE(priv->tx_tail, priv->tx_tail + 1); netif_subqueue_completed_wake(priv->ndev, 0, 1, frame_len, - rkcanfd_get_tx_free(priv), + rkcanfd_get_effective_tx_free(priv), RKCANFD_TX_START_THRESHOLD); *tx_done = true; diff --git a/drivers/net/can/rockchip/rockchip_canfd-tx.c b/drivers/net/can/rockchip/rockchip_canfd-tx.c index f8e74e814b3b..d10da548ba71 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-tx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-tx.c @@ -8,6 +8,40 @@ #include "rockchip_canfd.h" +static bool rkcanfd_tx_tail_is_eff(const struct rkcanfd_priv *priv) +{ + const struct canfd_frame *cfd; + const struct sk_buff *skb; + unsigned int tx_tail; + + if (!rkcanfd_get_tx_pending(priv)) + return false; + + tx_tail = rkcanfd_get_tx_tail(priv); + skb = priv->can.echo_skb[tx_tail]; + if (!skb) { + netdev_err(priv->ndev, + "%s: echo_skb[%u]=NULL tx_head=0x%08x tx_tail=0x%08x\n", + __func__, tx_tail, + priv->tx_head, priv->tx_tail); + + return false; + } + + cfd = (struct canfd_frame *)skb->data; + + return cfd->can_id & CAN_EFF_FLAG; +} + +unsigned int rkcanfd_get_effective_tx_free(const struct rkcanfd_priv *priv) +{ + if (priv->devtype_data.quirks & RKCANFD_QUIRK_RK3568_ERRATUM_6 && + rkcanfd_tx_tail_is_eff(priv)) + return 0; + + return rkcanfd_get_tx_free(priv); +} + static void rkcanfd_start_xmit_write_cmd(const struct rkcanfd_priv *priv, const u32 reg_cmd) { @@ -42,7 +76,7 @@ int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev) return NETDEV_TX_OK; if (!netif_subqueue_maybe_stop(priv->ndev, 0, - rkcanfd_get_tx_free(priv), + rkcanfd_get_effective_tx_free(priv), RKCANFD_TX_STOP_THRESHOLD, RKCANFD_TX_START_THRESHOLD)) { if (net_ratelimit()) @@ -99,7 +133,7 @@ int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev) rkcanfd_start_xmit_write_cmd(priv, reg_cmd); netif_subqueue_maybe_stop(priv->ndev, 0, - rkcanfd_get_tx_free(priv), + rkcanfd_get_effective_tx_free(priv), RKCANFD_TX_STOP_THRESHOLD, RKCANFD_TX_START_THRESHOLD); diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index f24a1d18be66..37d90400429f 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -533,6 +533,7 @@ int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv); void rkcanfd_timestamp_init(struct rkcanfd_priv *priv); +unsigned int rkcanfd_get_effective_tx_free(const struct rkcanfd_priv *priv); void rkcanfd_xmit_retry(struct rkcanfd_priv *priv); int rkcanfd_start_xmit(struct sk_buff *skb, struct net_device *ndev); void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts, From patchwork Fri Aug 30 19:26:14 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: 13785480 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 3F2D1CA1009 for ; Fri, 30 Aug 2024 19:37:45 +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=p6lUSlmJaEr1Y7WSbx/u5MKHO9/txyryFEPG3d6Gkgo=; b=42o/q39iD6jsSj cFjKyXk97T+c1b06KrduTyLFnfQUC2eO5eFOk+CS1RjoZaQ426H8uKzd7YRmXg6JQc/QdQ0MnF19v lqdkP2Z3+X2sWO7BAONBUQNPSVUcXazEMv3HKF6qSqobL3agXGsZwsROPH0jL3dBIICvbZu7bCudR i6Cx5KRr9vMfR+3ZxT5SqqHEvIbq+STyH13Hp5rakA+UpZaRxy6r7JxRSxXKvOlWtt8M3x0szO3zt DWw7Lva4R2C/7OuVixogHcHr08Tt3QO0Kh33vDhtOgHkKIq3iWjleLf/Q4k8T8E+mH/tCN5Jrc7uj pUENk7r8KIFRDBz/wUvA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7RF-00000007Uuj-1bcA; Fri, 30 Aug 2024 19:37:41 +0000 Received: from metis.whiteo.stw.pengutronix.de ([185.203.201.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H3-00000007RUY-0KXR for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:10 +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 1sk7H0-0006Mn-Nl for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:06 +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 1sk7Gt-004DsB-27 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:59 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 9E97E32E285 for ; Fri, 30 Aug 2024 19:26:58 +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 A1F4732E11B; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id 40896589; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:14 +0200 Subject: [PATCH can-next v3 17/20] can: rockchip_canfd: enable full TX-FIFO depth of 2 MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-17-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=829; i=mkl@pengutronix.de; h=from:subject:message-id; bh=0qsTluf2v/emmiVgIm5E1cbr10zmDr/+ymw0kEVGdYo=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzvjy4jqUm/zK6mDpwf+DQmica5PWPiqNoRA khjvmzz3n2JATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc7wAKCRAoOKI+ei28 byTmB/9ESAI5QuKqSA0DURrOxJYsHbs+uaoPoGfB77NewMn/Lic8BfpYpxt8LGedMCgzYhVSrIR b1uSjUdEkyHQvoVChDaBY9RrnOLy7qjfANBJggHiEpOKPWX7VZ7mz7T6CMcx+/Pfw/sWDrKKQ7+ RoE/EmXeFUoTr9CFa57EAjv8Sy0192FMMIICvA4Qwrr7ABj9yKtIOJeSPNDIL+O93fZweKXkQ9k zZw7tMT/Ph1dp6Ql9nsmNw3MPtNcT360AiWbmq8acBB4+qSvGiBVCJaRGDkW+YZ5fq4ud/NUZgI EOBzPpoCT+KkOmRflmsWI1tZ5R2XzJDr9ibYOjvaNqAIk1pO 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-20240830_122709_254623_BBCF283B X-CRM114-Status: GOOD ( 12.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 previous commit prepared the TX path to make use of the full TX-FIFO depth as much as possible. Increase the available TX-FIFO depth to the hardware maximum of 2. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 37d90400429f..6be2865ec95a 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -288,7 +288,7 @@ #define DEVICE_NAME "rockchip_canfd" #define RKCANFD_NAPI_WEIGHT 32 -#define RKCANFD_TXFIFO_DEPTH 1 +#define RKCANFD_TXFIFO_DEPTH 2 #define RKCANFD_TX_STOP_THRESHOLD 1 #define RKCANFD_TX_START_THRESHOLD 1 From patchwork Fri Aug 30 19:26:15 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: 13785506 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 DAB9FCA0FE8 for ; Fri, 30 Aug 2024 19:43:49 +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=otJsz6awROEIFF6r4yqy0zunx3sIansZI3ARk6te/mM=; b=edLwH00tU7nq3n 2X6MF9o5UJlNFGhfcY+AHWsXG1f50/NeDFvc7b8lP75p28OYMvWdzSX5kWFvNeFybziyA9vThqCL5 NnOBI0ZhXSpOxJEdUKo+0clnGh1NDhllArv+ELThPZzTkMu+Y/ras7TqM6VCoaGKhyKyb4GTEUZLc wF6KQxrA/ISxhGWIQTvrVROCl2RhxIrf/M2ttXq0riHvYqbCu6JXCn8zA1RPNiwtS87xL79rhkMr3 bw9fvT0s9RS6qDOpWf7uiVTwkx0oL2VG7F/3+PZyncyh6lOPQx4/9x+uL4px+0UevnDBDA0vhQDkW KQzcHwRSJ53ExMaVnJiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7X8-00000007W8X-1ylP; Fri, 30 Aug 2024 19:43:46 +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 1sk7HU-00000007RhI-3ZVZ for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:37 +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=B+hXcn2vA770AApbEBZ4BEyfdeamxwHU6wSJcx0Z6IQ=; b=deZSXHj9cp9w/3HmyGhUPai0Oh yNmaoQvAkupCQs7yFt5fpAC6FLROdO0cNnyDzcArdDemW+al4GKko0iE65zpe+eO5OZFM+Z6jU/Ju w6jws15cGUXGqTQeCaXImZH64uXRwggUR1cu6hcCTgOeWC09al31jvFrmKBFR4B7yYsNI0fIl4ZK9 zwlXF3Kajv8mVoKgr6VHj0sxKx6zquAfeufVSje3u1bF7rf1n7d0b+h9WtxahFee1Q8kH63rWiAiy dkR/x9Pn28WpiFkJkiINmLuwV1az2P2oQOcjEUSRg8M0bu67LkxegkCo1UmbAz3T98tJ7tHgWfVn5 d0XLUu2A==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H8-0000000Bk9Q-0Ec7 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:27 +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 1sk7H1-0006Mp-PN for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:07 +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 1sk7Gs-004Ds5-Tt for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:59 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 93CF832E283 for ; Fri, 30 Aug 2024 19:26:58 +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 BEAFA32E11E; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id b414e826; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:15 +0200 Subject: [PATCH can-next v3 18/20] can: rockchip_canfd: add hardware timestamping support MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-18-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=9046; i=mkl@pengutronix.de; h=from:subject:message-id; bh=+meZphvzteAtCOrac7FHKFFj9qclAUNi1NRCRVPJi7o=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzwt9XTCs6r4giJ51rJkf9K/y78leH7taUVl horu80UG5yJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc8AAKCRAoOKI+ei28 bwp3B/99Oc+Mx4HN5L+gteN/9Te0h4sXFH+SBdw+/7LIeTIyazLMbKChZklDL1hQN1Aiw1YHyus FundkpSjphcVhcsxofyD9iGpxk3BB53NHvcXERKxl8ZabyLY7WgKMKl7Bj6hoK9+rMs6gyhHqNb +ZBbkV35FWe7iuHbKECyD9nstZqr3PYSAbVoB9fQav2K+kQSmUkW6piAWyy212Yip8gGAU0xxVc p/G6ybCV1Fo18ckwNxpJcRBAYWLMC46PytkaGZPVkTFdz8Gqw0dKQPuHwoGcvt8XzrZXk97g2D3 jUa+KQ7BCGYG1RRZEs+XhZODwjLQkv7wmMSbvWmDhvrzU7Mx 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-20240830_202720_421689_9B133129 X-CRM114-Status: GOOD ( 20.90 ) 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 Add support for hardware based timestamping. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 6 ++ drivers/net/can/rockchip/rockchip_canfd-ethtool.c | 2 +- drivers/net/can/rockchip/rockchip_canfd-rx.c | 1 + .../net/can/rockchip/rockchip_canfd-timestamp.c | 94 +++++++++++++++++++++- drivers/net/can/rockchip/rockchip_canfd-tx.c | 4 + drivers/net/can/rockchip/rockchip_canfd.h | 11 +++ 6 files changed, 115 insertions(+), 3 deletions(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index 4db552bfc4db..015623314e88 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -292,6 +292,8 @@ static void rkcanfd_chip_start(struct rkcanfd_priv *priv) rkcanfd_chip_fifo_setup(priv); rkcanfd_timestamp_init(priv); + rkcanfd_timestamp_start(priv); + rkcanfd_set_bittiming(priv); rkcanfd_chip_interrupts_disable(priv); @@ -315,6 +317,7 @@ static void rkcanfd_chip_stop(struct rkcanfd_priv *priv, const enum can_state st { priv->can.state = state; + rkcanfd_timestamp_stop(priv); __rkcanfd_chip_stop(priv, state); } @@ -322,6 +325,7 @@ static void rkcanfd_chip_stop_sync(struct rkcanfd_priv *priv, const enum can_sta { priv->can.state = state; + rkcanfd_timestamp_stop_sync(priv); __rkcanfd_chip_stop(priv, state); } @@ -353,6 +357,8 @@ rkcanfd_alloc_can_err_skb(struct rkcanfd_priv *priv, *timestamp = rkcanfd_get_timestamp(priv); skb = alloc_can_err_skb(priv->ndev, cf); + if (skb) + rkcanfd_skb_set_timestamp(priv, skb, *timestamp); return skb; } diff --git a/drivers/net/can/rockchip/rockchip_canfd-ethtool.c b/drivers/net/can/rockchip/rockchip_canfd-ethtool.c index 0084f37b2b9f..5aeeef64a67a 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-ethtool.c +++ b/drivers/net/can/rockchip/rockchip_canfd-ethtool.c @@ -59,7 +59,7 @@ rkcanfd_ethtool_get_ethtool_stats(struct net_device *ndev, } static const struct ethtool_ops rkcanfd_ethtool_ops = { - .get_ts_info = ethtool_op_get_ts_info, + .get_ts_info = can_ethtool_op_get_ts_info_hwts, .get_strings = rkcanfd_ethtool_get_strings, .get_sset_count = rkcanfd_ethtool_get_sset_count, .get_ethtool_stats = rkcanfd_ethtool_get_ethtool_stats, diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index bacef5e5dc39..d862116840eb 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -267,6 +267,7 @@ static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) } memcpy(skb_cfd, cfd, len); + rkcanfd_skb_set_timestamp(priv, skb, header->ts); err = can_rx_offload_queue_timestamp(&priv->offload, skb, header->ts); if (err) diff --git a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c index 9301b3ceceb0..81cccc5fd838 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-timestamp.c +++ b/drivers/net/can/rockchip/rockchip_canfd-timestamp.c @@ -4,12 +4,102 @@ // Marc Kleine-Budde // +#include + #include "rockchip_canfd.h" +static u64 rkcanfd_timestamp_read(const struct cyclecounter *cc) +{ + const struct rkcanfd_priv *priv = container_of(cc, struct rkcanfd_priv, cc); + + return rkcanfd_get_timestamp(priv); +} + +void rkcanfd_skb_set_timestamp(const struct rkcanfd_priv *priv, + struct sk_buff *skb, const u32 timestamp) +{ + struct skb_shared_hwtstamps *hwtstamps = skb_hwtstamps(skb); + u64 ns; + + ns = timecounter_cyc2time(&priv->tc, timestamp); + + hwtstamps->hwtstamp = ns_to_ktime(ns); +} + +static void rkcanfd_timestamp_work(struct work_struct *work) +{ + const struct delayed_work *delayed_work = to_delayed_work(work); + struct rkcanfd_priv *priv; + + priv = container_of(delayed_work, struct rkcanfd_priv, timestamp); + timecounter_read(&priv->tc); + + schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies); +} + void rkcanfd_timestamp_init(struct rkcanfd_priv *priv) { - u32 reg; + const struct can_bittiming *dbt = &priv->can.data_bittiming; + const struct can_bittiming *bt = &priv->can.bittiming; + struct cyclecounter *cc = &priv->cc; + u32 bitrate, div, reg, rate; + u64 work_delay_ns; + u64 max_cycles; - reg = RKCANFD_REG_TIMESTAMP_CTRL_TIME_BASE_COUNTER_ENABLE; + /* At the standard clock rate of 300Mhz on the rk3658, the 32 + * bit timer overflows every 14s. This means that we have to + * poll it quite often to avoid missing a wrap around. + * + * Divide it down to a reasonable rate, at least twice the bit + * rate. + */ + bitrate = max(bt->bitrate, dbt->bitrate); + div = min(DIV_ROUND_UP(priv->can.clock.freq, bitrate * 2), + FIELD_MAX(RKCANFD_REG_TIMESTAMP_CTRL_TIME_BASE_COUNTER_PRESCALE) + 1); + + reg = FIELD_PREP(RKCANFD_REG_TIMESTAMP_CTRL_TIME_BASE_COUNTER_PRESCALE, + div - 1) | + RKCANFD_REG_TIMESTAMP_CTRL_TIME_BASE_COUNTER_ENABLE; rkcanfd_write(priv, RKCANFD_REG_TIMESTAMP_CTRL, reg); + + cc->read = rkcanfd_timestamp_read; + cc->mask = CYCLECOUNTER_MASK(32); + + rate = priv->can.clock.freq / div; + clocks_calc_mult_shift(&cc->mult, &cc->shift, rate, NSEC_PER_SEC, + RKCANFD_TIMESTAMP_WORK_MAX_DELAY_SEC); + + max_cycles = div_u64(ULLONG_MAX, cc->mult); + max_cycles = min(max_cycles, cc->mask); + work_delay_ns = clocksource_cyc2ns(max_cycles, cc->mult, cc->shift) / 3; + priv->work_delay_jiffies = nsecs_to_jiffies(work_delay_ns); + INIT_DELAYED_WORK(&priv->timestamp, rkcanfd_timestamp_work); + + netdev_dbg(priv->ndev, "clock=%lu.%02luMHz bitrate=%lu.%02luMBit/s div=%u rate=%lu.%02luMHz mult=%u shift=%u delay=%lus\n", + priv->can.clock.freq / MEGA, + priv->can.clock.freq % MEGA / KILO / 10, + bitrate / MEGA, + bitrate % MEGA / KILO / 100, + div, + rate / MEGA, + rate % MEGA / KILO / 10, + cc->mult, cc->shift, + priv->work_delay_jiffies / HZ); +} + +void rkcanfd_timestamp_start(struct rkcanfd_priv *priv) +{ + timecounter_init(&priv->tc, &priv->cc, ktime_get_real_ns()); + + schedule_delayed_work(&priv->timestamp, priv->work_delay_jiffies); +} + +void rkcanfd_timestamp_stop(struct rkcanfd_priv *priv) +{ + cancel_delayed_work(&priv->timestamp); +} + +void rkcanfd_timestamp_stop_sync(struct rkcanfd_priv *priv) +{ + cancel_delayed_work_sync(&priv->timestamp); } diff --git a/drivers/net/can/rockchip/rockchip_canfd-tx.c b/drivers/net/can/rockchip/rockchip_canfd-tx.c index d10da548ba71..f954f38b955f 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-tx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-tx.c @@ -145,8 +145,10 @@ void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts, { struct net_device_stats *stats = &priv->ndev->stats; unsigned int tx_tail; + struct sk_buff *skb; tx_tail = rkcanfd_get_tx_tail(priv); + skb = priv->can.echo_skb[tx_tail]; /* Manual handling of CAN Bus Error counters. See * rkcanfd_get_corrected_berr_counter() for detailed @@ -155,6 +157,8 @@ void rkcanfd_handle_tx_done_one(struct rkcanfd_priv *priv, const u32 ts, if (priv->bec.txerr) priv->bec.txerr--; + if (skb) + rkcanfd_skb_set_timestamp(priv, skb, ts); stats->tx_bytes += can_rx_offload_get_echo_skb_queue_timestamp(&priv->offload, tx_tail, ts, diff --git a/drivers/net/can/rockchip/rockchip_canfd.h b/drivers/net/can/rockchip/rockchip_canfd.h index 6be2865ec95a..3efd7f174e14 100644 --- a/drivers/net/can/rockchip/rockchip_canfd.h +++ b/drivers/net/can/rockchip/rockchip_canfd.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -469,6 +470,11 @@ struct rkcanfd_priv { u32 reg_int_mask_default; struct rkcanfd_devtype_data devtype_data; + struct cyclecounter cc; + struct timecounter tc; + struct delayed_work timestamp; + unsigned long work_delay_jiffies; + struct can_berr_counter bec; struct rkcanfd_stats stats; @@ -531,7 +537,12 @@ void rkcanfd_ethtool_init(struct rkcanfd_priv *priv); int rkcanfd_handle_rx_int(struct rkcanfd_priv *priv); +void rkcanfd_skb_set_timestamp(const struct rkcanfd_priv *priv, + struct sk_buff *skb, const u32 timestamp); void rkcanfd_timestamp_init(struct rkcanfd_priv *priv); +void rkcanfd_timestamp_start(struct rkcanfd_priv *priv); +void rkcanfd_timestamp_stop(struct rkcanfd_priv *priv); +void rkcanfd_timestamp_stop_sync(struct rkcanfd_priv *priv); unsigned int rkcanfd_get_effective_tx_free(const struct rkcanfd_priv *priv); void rkcanfd_xmit_retry(struct rkcanfd_priv *priv); From patchwork Fri Aug 30 19:26:16 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: 13785479 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 A54ABCA0FE8 for ; Fri, 30 Aug 2024 19:37:44 +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=LIH9DG8/VNJIJm+iP1+56rgwJ0MIcwzY/4LWXqCOhkY=; b=Tez7QrpEqqbGt9 aIAGpQqCXgr11qp29HaaK4xp7Yj3bM00qLm/j8DR5/In8ECm+Y7QG046D5UZNE3wE1fJougp/p2wb hzYo2PfuqPzNC98W1onxpVbW2/GNGWNDLU39fwrwSlNCqEy+SgfVBOpuqA9sKrH4ERssCXIkdhzUM xi1JH2O8KPhCnaqE0OGDmlEytctGSu66XL2QxmspPEBBWXdbk8owbSnl5Ku3CF+BEvw1UeLQHm1Ko L0TwN4kGQfO5zSDBffpJ8ufpRQ0qcqeX3ShXZEGd4SNme9b2iBjWxtCvWvXmr3nbZk4gabFzcxBwC +twi8jTGJr/wvE77u0Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7RF-00000007Uuw-3D2g; Fri, 30 Aug 2024 19:37:41 +0000 Received: from metis.whiteo.stw.pengutronix.de ([185.203.201.7]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H3-00000007RUa-10QE for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:11 +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 1sk7H0-0006Mv-UT for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:06 +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 1sk7Gt-004DsA-1K for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:59 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 99AC832E284 for ; Fri, 30 Aug 2024 19:26:58 +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 D5C3832E122; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id 00dd0844; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:16 +0200 Subject: [PATCH can-next v3 19/20] can: rockchip_canfd: add support for CAN_CTRLMODE_LOOPBACK MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-19-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=2085; i=mkl@pengutronix.de; h=from:subject:message-id; bh=pJWpPFSCn3sCCP4vrlGklsSt8C8X6Jas6pWN/uv/+PE=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzywZtTWV4igNjMO2OEf0qve+1RVtZKz3rxo xcrLg7bg+GJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc8gAKCRAoOKI+ei28 b+UHB/0bekIU85aSffkV0pRC1pyZtDUNEjl+drk8xQrzw7GgnJrNp53WBNqQR5y5NNEXOvK3GAJ XCzYfe3PM6d0sdos1k0Z2IxefC4y7kcJHVi76EGoQ6AsetJOb6qDwMpqZNgNaAkscJ3Sqdrs/Ll VGh0ISxeODl9JAkmGUdyzy9AS1n+T5dqiS+uaftnDOm/iY/J87e/E62n5bzMlk/eUngtQByaqc8 TkK68RRNkMEq93TpHyJR+ja/0hFt2h2pDndXWKiHMfz64vs9lIfuJWAIvSPM3DZixV2CaJ+W7m+ XHWgpLkETPxreM4cYYLzNlfBAkRDZfX8f2IeYEsDp6bit6CI 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-20240830_122709_547492_9AEC322A X-CRM114-Status: GOOD ( 15.46 ) 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 Add support for loopback mode. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 7 ++++++- drivers/net/can/rockchip/rockchip_canfd-rx.c | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index 015623314e88..8853f6a135da 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -276,6 +276,11 @@ static void rkcanfd_chip_start(struct rkcanfd_priv *priv) RKCANFD_REG_MODE_RXSTX_MODE | RKCANFD_REG_MODE_WORK_MODE; + if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) + priv->reg_mode_default |= RKCANFD_REG_MODE_LBACK_MODE | + RKCANFD_REG_MODE_SILENT_MODE | + RKCANFD_REG_MODE_SELF_TEST; + /* mask, i.e. ignore: * - TIMESTAMP_COUNTER_OVERFLOW_INT - timestamp counter overflow interrupt * - TX_ARBIT_FAIL_INT - TX arbitration fail interrupt @@ -894,7 +899,7 @@ static int rkcanfd_probe(struct platform_device *pdev) priv->can.clock.freq = clk_get_rate(priv->clks[0].clk); priv->can.bittiming_const = &rkcanfd_bittiming_const; priv->can.data_bittiming_const = &rkcanfd_data_bittiming_const; - priv->can.ctrlmode_supported = 0; + priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK; if (!(priv->devtype_data.quirks & RKCANFD_QUIRK_CANFD_BROKEN)) priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD; priv->can.do_set_mode = rkcanfd_set_mode; diff --git a/drivers/net/can/rockchip/rockchip_canfd-rx.c b/drivers/net/can/rockchip/rockchip_canfd-rx.c index d862116840eb..475c0409e215 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-rx.c +++ b/drivers/net/can/rockchip/rockchip_canfd-rx.c @@ -243,7 +243,7 @@ static int rkcanfd_handle_rx_int_one(struct rkcanfd_priv *priv) err = rkcanfd_rxstx_filter(priv, cfd, header->ts, &tx_done); if (err) return err; - if (tx_done) + if (tx_done && !(priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)) return 0; } From patchwork Fri Aug 30 19:26:17 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: 13785504 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 BD815CA100C for ; Fri, 30 Aug 2024 19:43:50 +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=+fW66a47EtbdxisvaYN9flzraDzFpDVKsSBN4aDZ4Jc=; b=PSoUhNyTp11fGF sD3F/tJzXUIG8fHwxVJZcTMc76m5KRzfFWCH7ECCxafV1kTZs9D4YAeVumT9tJck4N3K78nvsvMBL R48e2TNVt/N9FWeCOWKWpiRg1Cz2RXOgF0oiT6qHvenaiT/Kxu3lAJcIeNlLyh+FRPg1zx5/h3QAZ aYEVKMRsUnnLaIFd8qdEqleOtxWuCSAIYASQWOh4NLT9/EZeJU03x5dzmxVp9ndyXabY4vPA/1WQ6 tDKKBaaGi0395l2sNF4KwZpKDhS/bT97oW3Y8+lerO7NHpeLLDqYKYPYste4BjudQJPf2RaPF8/y7 XmzfurKwhUvTpPqffXWQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7X9-00000007W9S-1lKB; Fri, 30 Aug 2024 19:43:47 +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 1sk7HX-00000007RmE-2WJy for linux-rockchip@bombadil.infradead.org; Fri, 30 Aug 2024 19:27:39 +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=Ajn95mjztpqdyxZFAAv0n3MypG6/uf4WyrVQ4Yhw5Os=; b=PicOCz7W7Op58AvkS2cdVwnW8w eh0YQJ3fB3WZC4Ty1MzN2qrqKKHyp1ZD4I1OBBRROX3KpeDVKxgeoxqHhYZQwTHsU3c6c5b50fcpS idvhTYyJMCJxiKaj41J3Z3wYQs+5h4gtO0GKAt/8b0m7W2UCkm83zWJ5GLN7/ey8I0mC0oiboCxXE 2fCgmFsLAlxt58LjvlIEPdndW1MLuwy+oFXrSq7Hw0LEuAkX6gHaEMNEra7wBsh9bcnQHrxvduRlA RHwNZstNbk6D7Oc1tGH14Ya/nqKAKECREmdBRHps0N7TLLhggFd3FrVbyrgplRJEjmeqcSAAlm1od q3SSWNZg==; Received: from metis.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::104]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sk7H8-0000000Bk9R-0Ek5 for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 19:27:31 +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 1sk7H1-0006Mu-QK for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:27:07 +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 1sk7Gt-004DsF-3y for linux-rockchip@lists.infradead.org; Fri, 30 Aug 2024 21:26:59 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id BDFC832E286 for ; Fri, 30 Aug 2024 19:26:58 +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 F1D7232E125; Fri, 30 Aug 2024 19:26:47 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id 662e71b0; Fri, 30 Aug 2024 19:26:45 +0000 (UTC) From: Marc Kleine-Budde Date: Fri, 30 Aug 2024 21:26:17 +0200 Subject: [PATCH can-next v3 20/20] can: rockchip_canfd: add support for CAN_CTRLMODE_BERR_REPORTING MIME-Version: 1.0 Message-Id: <20240830-rockchip-canfd-v3-20-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=2351; i=mkl@pengutronix.de; h=from:subject:message-id; bh=LuMx/PlnK3WbirTHya0KJ2kuGTfiCv8jMDhEO9L4kY8=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBm0hzzWSZOPJIz9FhQvHlaytA5ca9hKvtWeb2oA Fr49Lzww3SJATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZtIc8wAKCRAoOKI+ei28 b8uTB/9NEiPYXbc82AadhaySflhfwVIf5BtMH5bmwGVeSDZC/X8ynol4bfnf5wTWpTLRtzOXz66 Jbjx227dEo7mAAxhxpBzqRgd77cxSjNuNnfRSJOsJBsiPaAqx0ZTRnLSnuENt5f6JmUtEFJ4WCa tvWGu4GlbAroBT9sbSWYebwkDRZJOUjgqU0gyxawT/doIV/fs4NQnJpPz+aActxaj11Wy85eBsi 4bhC9e35yMzatN6hcpilFlPlUuWPPlr1fA85YlEP9vQVIZaenZt/an/VOFfPzRYeRiyKVOvV8mS KO7eDPfk0xrDFyyhPf5MwGGhQEchxEyuB9YnwV4980Vy/txw 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-20240830_202722_617013_330FF508 X-CRM114-Status: GOOD ( 16.16 ) 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 Add support for Bus Error Reporting. Signed-off-by: Marc Kleine-Budde --- drivers/net/can/rockchip/rockchip_canfd-core.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/net/can/rockchip/rockchip_canfd-core.c b/drivers/net/can/rockchip/rockchip_canfd-core.c index 8853f6a135da..6883153e8fc1 100644 --- a/drivers/net/can/rockchip/rockchip_canfd-core.c +++ b/drivers/net/can/rockchip/rockchip_canfd-core.c @@ -293,6 +293,12 @@ static void rkcanfd_chip_start(struct rkcanfd_priv *priv) RKCANFD_REG_INT_OVERLOAD_INT | RKCANFD_REG_INT_TX_FINISH_INT; + /* Do not mask the bus error interrupt if the bus error + * reporting is requested. + */ + if (!(priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)) + priv->reg_int_mask_default |= RKCANFD_REG_INT_ERROR_INT; + memset(&priv->bec, 0x0, sizeof(priv->bec)); rkcanfd_chip_fifo_setup(priv); @@ -533,14 +539,16 @@ static int rkcanfd_handle_error_int(struct rkcanfd_priv *priv) if (!reg_ec) return 0; - skb = rkcanfd_alloc_can_err_skb(priv, &cf, ×tamp); - if (cf) { - struct can_berr_counter bec; + if (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) { + skb = rkcanfd_alloc_can_err_skb(priv, &cf, ×tamp); + if (cf) { + struct can_berr_counter bec; - rkcanfd_get_berr_counter_corrected(priv, &bec); - cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR | CAN_ERR_CNT; - cf->data[6] = bec.txerr; - cf->data[7] = bec.rxerr; + rkcanfd_get_berr_counter_corrected(priv, &bec); + cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR | CAN_ERR_CNT; + cf->data[6] = bec.txerr; + cf->data[7] = bec.rxerr; + } } rkcanfd_handle_error_int_reg_ec(priv, cf, reg_ec); @@ -899,7 +907,8 @@ static int rkcanfd_probe(struct platform_device *pdev) priv->can.clock.freq = clk_get_rate(priv->clks[0].clk); priv->can.bittiming_const = &rkcanfd_bittiming_const; priv->can.data_bittiming_const = &rkcanfd_data_bittiming_const; - priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK; + priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | + CAN_CTRLMODE_BERR_REPORTING; if (!(priv->devtype_data.quirks & RKCANFD_QUIRK_CANFD_BROKEN)) priv->can.ctrlmode_supported |= CAN_CTRLMODE_FD; priv->can.do_set_mode = rkcanfd_set_mode;