From patchwork Wed Jul 31 09:37:18 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: 13748407 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 04AC5C3DA7F for ; Wed, 31 Jul 2024 09:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type: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=dneNBAvzYycDUR4bvnc5xaQ9nliTq0mdeCZeWb2aqgY=; b=QDkoCPPT8oH9fTeFafgWRkXOtd ivoOOkFcd/LMPU7aEe26ILug5hiuv63uqvarqz/JB9kq7k7f1L9LXIo51Cpke6yLOujo37u/OHrem pv5HR0Y6ut8co3elDErKf+sEcs7z88amsiXIvKcQvUbPHxb484rvPKXmSM6epoAZ7BMvXlwVM1gar Qd/vrw/b06l94xQhP8E4PY1PU0n9XRjeyuQaNmFGEYxEAxhTpOeWxuqzfhQXYNvEMi+IAAMT4Vl/E +as/p8nITd9Kf+yS6Vm8A8F4rriY3bmZSDotFqPAWyQ2738+Y49xyynPlwje59EiEv3X+X1K8PSTS MFvv3cNA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sZ5uR-00000000aeZ-0tSx; Wed, 31 Jul 2024 09:46:15 +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 1sZ5mh-00000000XMO-1Oad for linux-arm-kernel@bombadil.infradead.org; Wed, 31 Jul 2024 09:38:15 +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=dneNBAvzYycDUR4bvnc5xaQ9nliTq0mdeCZeWb2aqgY=; b=mR+A5MY/rPo4WgFMDQfEkgTfkk TkaWm5JGdfa6z07zg/63QVjtRJ3PIzaFnma+XJ2YHTsTdVDrcZoz/x3oUHpWd95eZv/JshIIf7csl 8GJ8l94d4kM+Goe3lrLeNDxlFNpqZ3OS4VztB2LyKbmekqe5zxlLqKYNE2xGqJPVitUO4vkY4Cn9r +NPVM8MUaMAxvsWBwiTKPAyhZxbFKoGUC4/qJDYnyQ/2LP3w51x9qmooPeH9Cp097OQ8B9K6sI1CW kdh/8kMhcsI82+7VI08DkskPEAYzLYw83BEJzZ/O6/Ez4AvibWf9zr4Iz6yZ8pCbhOP1dvM/eQZ3z cU7ot6Hw==; 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 1sZ5mc-00000005BRC-3VQ6 for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2024 09:38: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 1sZ5mb-0005kf-0i for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2024 11:38:09 +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 1sZ5mR-003Uti-Dy for linux-arm-kernel@lists.infradead.org; Wed, 31 Jul 2024 11:37:59 +0200 Received: from dspam.blackshift.org (localhost [127.0.0.1]) by bjornoya.blackshift.org (Postfix) with SMTP id 0C0E431290E for ; Wed, 31 Jul 2024 09:37:59 +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 DC5DC31288C; Wed, 31 Jul 2024 09:37:55 +0000 (UTC) Received: from [172.20.34.65] (localhost [::1]) by hardanger.blackshift.org (OpenSMTPD) with ESMTP id caada1fe; Wed, 31 Jul 2024 09:37:42 +0000 (UTC) From: Marc Kleine-Budde Date: Wed, 31 Jul 2024 11:37:18 +0200 Subject: [PATCH can-next v2 16/20] can: rockchip_canfd: prepare to use full TX-FIFO depth MIME-Version: 1.0 Message-Id: <20240731-rockchip-canfd-v2-16-d9604c5b4be8@pengutronix.de> References: <20240731-rockchip-canfd-v2-0-d9604c5b4be8@pengutronix.de> In-Reply-To: <20240731-rockchip-canfd-v2-0-d9604c5b4be8@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-37811 X-Developer-Signature: v=1; a=openpgp-sha256; l=4154; i=mkl@pengutronix.de; h=from:subject:message-id; bh=k5pNbsDPkKghkSy78ahf8n3dUVHetyX10cJ+72ndVeI=; b=owEBbQGS/pANAwAKASg4oj56LbxvAcsmYgBmqgXdt0hcQzdQ5doIHpL8mo8OrRFTTyf3ZKcn+ ywdy0YlhR2JATMEAAEKAB0WIQRQQLqG4LYE3Sm8Pl8oOKI+ei28bwUCZqoF3QAKCRAoOKI+ei28 b7fBB/4n1Ql7LRYeCSH2DzVzLCUlPeN4yVuVxqbdpPmD50qdii9DTGEBn+r+O1Cqwsus+pwVPli 6f+j8uRmeiCbLcEZBuG0wE1DUC9aqjzrej73nJTVj3uj9/uPtzc+iOQAJhM1p/4BWz3b2ZQtgH0 pngigcRl6cWl5lD6GPmNxV+GkfueNYnMNpfhNwQJcZ8BMMpHS1XZGLWYdaKPCufrS5t3gqX1UkU inmnfPS+YyRPDV/txt2ueCdO/BTtOg8zXKubp/Oc3RooKJr6xWebqODaS2U2r17b9Ah0XO9+B8l 1gPdYwQJ5nBycziYFP7JgTvcplQ6n2Cr5GGp4O8A7ly3pqUE 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-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240731_103811_188937_F720B8CA X-CRM114-Status: GOOD ( 19.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=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,