From nobody Sun May 10 16:25:41 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1B4EC433EF for ; Fri, 29 Apr 2022 08:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356072AbiD2Iud (ORCPT ); Fri, 29 Apr 2022 04:50:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356054AbiD2Iub (ORCPT ); Fri, 29 Apr 2022 04:50:31 -0400 Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1E4D54BC9 for ; Fri, 29 Apr 2022 01:47:13 -0700 (PDT) X-Halon-ID: f513e3fe-c798-11ec-9627-0050569116f7 Authorized-sender: andreas@gaisler.com Received: from andreas.got.gaisler.com (h-98-128-223-123.na.cust.bahnhof.se [98.128.223.123]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id f513e3fe-c798-11ec-9627-0050569116f7; Fri, 29 Apr 2022 10:47:11 +0200 (CEST) From: Andreas Larsson To: linux-can@vger.kernel.org Cc: Wolfgang Grandegger , Marc Kleine-Budde , Oliver Hartkopp , linux-kernel@vger.kernel.org, software@gaisler.com, Daniel Hellstrom Subject: [PATCH v2 1/3] can: grcan: use ofdev->dev when allocating DMA memory Date: Fri, 29 Apr 2022 10:46:54 +0200 Message-Id: <20220429084656.29788-2-andreas@gaisler.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220429084656.29788-1-andreas@gaisler.com> References: <20220429084656.29788-1-andreas@gaisler.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Daniel Hellstrom Use the device of the device tree node should be rather than the device of the struct net_device when allocating DMA buffers. The driver got away with it on sparc32 until commit 53b7670e5735 ("sparc: factor the dma coherent mapping into helper") after which the driver oopses. Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN co= res") Signed-off-by: Daniel Hellstrom Signed-off-by: Andreas Larsson --- drivers/net/can/grcan.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index d0c5a7a60daf..f7c3cf941f61 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -248,6 +248,7 @@ struct grcan_device_config { struct grcan_priv { struct can_priv can; /* must be the first member */ struct net_device *dev; + struct device *ofdev_dev; struct napi_struct napi; =20 struct grcan_registers __iomem *regs; /* ioremap'ed registers */ @@ -921,7 +922,7 @@ static void grcan_free_dma_buffers(struct net_device *d= ev) struct grcan_priv *priv =3D netdev_priv(dev); struct grcan_dma *dma =3D &priv->dma; =20 - dma_free_coherent(&dev->dev, dma->base_size, dma->base_buf, + dma_free_coherent(priv->ofdev_dev, dma->base_size, dma->base_buf, dma->base_handle); memset(dma, 0, sizeof(*dma)); } @@ -946,7 +947,8 @@ static int grcan_allocate_dma_buffers(struct net_device= *dev, =20 /* Extra GRCAN_BUFFER_ALIGNMENT to allow for alignment */ dma->base_size =3D lsize + ssize + GRCAN_BUFFER_ALIGNMENT; - dma->base_buf =3D dma_alloc_coherent(&dev->dev, + + dma->base_buf =3D dma_alloc_coherent(priv->ofdev_dev, dma->base_size, &dma->base_handle, GFP_KERNEL); @@ -1587,6 +1589,7 @@ static int grcan_setup_netdev(struct platform_device = *ofdev, memcpy(&priv->config, &grcan_module_config, sizeof(struct grcan_device_config)); priv->dev =3D dev; + priv->ofdev_dev =3D &ofdev->dev; priv->regs =3D base; priv->can.bittiming_const =3D &grcan_bittiming_const; priv->can.do_set_bittiming =3D grcan_set_bittiming; --=20 2.17.1 From nobody Sun May 10 16:25:41 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4231DC433EF for ; Fri, 29 Apr 2022 08:47:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356113AbiD2Iui (ORCPT ); Fri, 29 Apr 2022 04:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356054AbiD2Iue (ORCPT ); Fri, 29 Apr 2022 04:50:34 -0400 Received: from bin-mail-out-06.binero.net (bin-mail-out-06.binero.net [195.74.38.229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D33AA57179 for ; Fri, 29 Apr 2022 01:47:16 -0700 (PDT) X-Halon-ID: f6a103d4-c798-11ec-9627-0050569116f7 Authorized-sender: andreas@gaisler.com Received: from andreas.got.gaisler.com (h-98-128-223-123.na.cust.bahnhof.se [98.128.223.123]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id f6a103d4-c798-11ec-9627-0050569116f7; Fri, 29 Apr 2022 10:47:14 +0200 (CEST) From: Andreas Larsson To: linux-can@vger.kernel.org Cc: Wolfgang Grandegger , Marc Kleine-Budde , Oliver Hartkopp , linux-kernel@vger.kernel.org, software@gaisler.com Subject: [PATCH v2 2/3] can: grcan: Fix broken system id check for errata workaround needs Date: Fri, 29 Apr 2022 10:46:55 +0200 Message-Id: <20220429084656.29788-3-andreas@gaisler.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220429084656.29788-1-andreas@gaisler.com> References: <20220429084656.29788-1-andreas@gaisler.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The systemid property was checked for in the wrong place of the devicetree and compared to the wrong value. Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN co= res") Signed-off-by: Andreas Larsson --- drivers/net/can/grcan.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index f7c3cf941f61..2f56d4bbb65c 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -241,7 +241,7 @@ struct grcan_device_config { .rxsize =3D GRCAN_DEFAULT_BUFFER_SIZE, \ } =20 -#define GRCAN_TXBUG_SAFE_GRLIB_VERSION 0x4100 +#define GRCAN_TXBUG_SAFE_GRLIB_VERSION 4100 #define GRLIB_VERSION_MASK 0xffff =20 /* GRCAN private data structure */ @@ -1642,6 +1642,7 @@ static int grcan_setup_netdev(struct platform_device = *ofdev, static int grcan_probe(struct platform_device *ofdev) { struct device_node *np =3D ofdev->dev.of_node; + struct device_node *sysid_parent; u32 sysid, ambafreq; int irq, err; void __iomem *base; @@ -1650,10 +1651,15 @@ static int grcan_probe(struct platform_device *ofde= v) /* Compare GRLIB version number with the first that does not * have the tx bug (see start_xmit) */ - err =3D of_property_read_u32(np, "systemid", &sysid); - if (!err && ((sysid & GRLIB_VERSION_MASK) - >=3D GRCAN_TXBUG_SAFE_GRLIB_VERSION)) - txbug =3D false; + sysid_parent =3D of_find_node_by_path("/ambapp0"); + if (sysid_parent) { + of_node_get(sysid_parent); + err =3D of_property_read_u32(sysid_parent, "systemid", &sysid); + if (!err && ((sysid & GRLIB_VERSION_MASK) + >=3D GRCAN_TXBUG_SAFE_GRLIB_VERSION)) + txbug =3D false; + of_node_put(sysid_parent); + } =20 err =3D of_property_read_u32(np, "freq", &ambafreq); if (err) { --=20 2.17.1 From nobody Sun May 10 16:25:41 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14653C433F5 for ; Fri, 29 Apr 2022 08:47:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356118AbiD2Iuo (ORCPT ); Fri, 29 Apr 2022 04:50:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356111AbiD2Iuh (ORCPT ); Fri, 29 Apr 2022 04:50:37 -0400 Received: from vsp-unauthed02.binero.net (vsp-unauthed02.binero.net [195.74.38.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C34075A09D for ; Fri, 29 Apr 2022 01:47:19 -0700 (PDT) X-Halon-ID: f886a4f6-c798-11ec-9627-0050569116f7 Authorized-sender: andreas@gaisler.com Received: from andreas.got.gaisler.com (h-98-128-223-123.na.cust.bahnhof.se [98.128.223.123]) by bin-vsp-out-03.atm.binero.net (Halon) with ESMTPA id f886a4f6-c798-11ec-9627-0050569116f7; Fri, 29 Apr 2022 10:47:17 +0200 (CEST) From: Andreas Larsson To: linux-can@vger.kernel.org Cc: Wolfgang Grandegger , Marc Kleine-Budde , Oliver Hartkopp , linux-kernel@vger.kernel.org, software@gaisler.com Subject: [PATCH v2 3/3] can: grcan: Only use the napi poll budget for rx Date: Fri, 29 Apr 2022 10:46:56 +0200 Message-Id: <20220429084656.29788-4-andreas@gaisler.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220429084656.29788-1-andreas@gaisler.com> References: <20220429084656.29788-1-andreas@gaisler.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The previous split budget between tx and rx made it return not using the entire budget but at the same time not having calling called napi_complete. This sometimes led to the poll to not be called, and at the same time having tx and rx interrupts disabled resulting in the driver getting stuck. Fixes: 6cec9b07fe6a ("can: grcan: Add device driver for GRCAN and GRHCAN co= res") Signed-off-by: Andreas Larsson --- drivers/net/can/grcan.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/net/can/grcan.c b/drivers/net/can/grcan.c index 2f56d4bbb65c..cb98eadc3b93 100644 --- a/drivers/net/can/grcan.c +++ b/drivers/net/can/grcan.c @@ -1124,7 +1124,7 @@ static int grcan_close(struct net_device *dev) return 0; } =20 -static int grcan_transmit_catch_up(struct net_device *dev, int budget) +static void grcan_transmit_catch_up(struct net_device *dev) { struct grcan_priv *priv =3D netdev_priv(dev); unsigned long flags; @@ -1132,7 +1132,7 @@ static int grcan_transmit_catch_up(struct net_device = *dev, int budget) =20 spin_lock_irqsave(&priv->lock, flags); =20 - work_done =3D catch_up_echo_skb(dev, budget, true); + work_done =3D catch_up_echo_skb(dev, -1, true); if (work_done) { if (!priv->resetting && !priv->closing && !(priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)) @@ -1146,8 +1146,6 @@ static int grcan_transmit_catch_up(struct net_device = *dev, int budget) } =20 spin_unlock_irqrestore(&priv->lock, flags); - - return work_done; } =20 static int grcan_receive(struct net_device *dev, int budget) @@ -1229,19 +1227,13 @@ static int grcan_poll(struct napi_struct *napi, int= budget) struct net_device *dev =3D priv->dev; struct grcan_registers __iomem *regs =3D priv->regs; unsigned long flags; - int tx_work_done, rx_work_done; - int rx_budget =3D budget / 2; - int tx_budget =3D budget - rx_budget; + int work_done; =20 - /* Half of the budget for receiving messages */ - rx_work_done =3D grcan_receive(dev, rx_budget); + work_done =3D grcan_receive(dev, budget); =20 - /* Half of the budget for transmitting messages as that can trigger echo - * frames being received - */ - tx_work_done =3D grcan_transmit_catch_up(dev, tx_budget); + grcan_transmit_catch_up(dev); =20 - if (rx_work_done < rx_budget && tx_work_done < tx_budget) { + if (work_done < budget) { napi_complete(napi); =20 /* Guarantee no interference with a running reset that otherwise @@ -1258,7 +1250,7 @@ static int grcan_poll(struct napi_struct *napi, int b= udget) spin_unlock_irqrestore(&priv->lock, flags); } =20 - return rx_work_done + tx_work_done; + return work_done; } =20 /* Work tx bug by waiting while for the risky situation to clear. If that = fails, --=20 2.17.1