Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2292128rwd; Wed, 14 Jun 2023 00:17:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5kk4aS4abz4upI/cdG5l40fs/MrSoclwbrXBKwcGaRVMIxFQ/cNtqXY5oi1XjDX/zUx4te X-Received: by 2002:a17:90a:354:b0:259:bf40:b571 with SMTP id 20-20020a17090a035400b00259bf40b571mr795768pjf.45.1686727053989; Wed, 14 Jun 2023 00:17:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686727053; cv=none; d=google.com; s=arc-20160816; b=w1UmR+x+5WYhVgfbTyf3PS9tETHT8QCC6dMBeNd2mvmP4GguPK1K8rKtgIYNyqgfG4 IsCsE5Of/GGrWYACFzKNgUhef9oyL7ugX43cVPZIRanniZRNKLQ0vpFBipEtI/E4ia7A QXyYD6yxMdh2MWkPr1Bd3QhZh+CpAnafXaRIxtIiU1L2et/43EUVZFZCf+frePdVw6uV TJ6f3B/zq+N7KbwLZttLl9vEy/qauRaQflvZ9869qsfO0k5CLPCcLUKBoUfYeRzqjpBK Z4lUpxCE06wKRicF9014jaerGd18go8fUxiIeKnDXsgt+qn9lVk9Xj0niC9wNtN0HyTy WOeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=u0S2MZjC6mUVtAE3YRvix8D/3CsE/ryR3ZfV+65rfos=; b=soqo/PCHbHhm7ntISwK7jpHVNUB9hCZvkVFXUoDB8s83WR/J/Q6pGkTDS/3xubqOMT SAoAFf6Opu1YQnd5MUglvC2M0T/ZmBtlg/KTaLNIghyeIwC9qNly2LzSIrnGXxb2+0Ye oE4nJrj3YyYjQRpnXfOeLJiT+7vlYGyj3cVWn7+ZZ7xTP4Ap8824Ecl4eo+hhVpMcLyY kcSLJtSiQwfb5134ihluPRrEY14pYVpBleYffLJ3a25gM7tjrFJvtx/xbFDzKTyh1fdg EpqEzaJimSjmAGKtTznPx8NAm6sZZMcJF4LwIi/0K2O8js8Oiqi0W6EcKXl0FIpTj9zE Zviw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id mt6-20020a17090b230600b0025bbcf3c080si5794595pjb.143.2023.06.14.00.17.22; Wed, 14 Jun 2023 00:17:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243260AbjFNHEc (ORCPT + 99 others); Wed, 14 Jun 2023 03:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243261AbjFNHEI (ORCPT ); Wed, 14 Jun 2023 03:04:08 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA2571FDE for ; Wed, 14 Jun 2023 00:03:33 -0700 (PDT) Received: from moin.white.stw.pengutronix.de ([2a0a:edc0:0:b01:1d::7b] helo=bjornoya.blackshift.org) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q9KWz-0000gR-KF; Wed, 14 Jun 2023 09:03:01 +0200 Received: from pengutronix.de (unknown [172.20.34.65]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: mkl-all@blackshift.org) by smtp.blackshift.org (Postfix) with ESMTPSA id 459681D919C; Wed, 14 Jun 2023 07:02:57 +0000 (UTC) Date: Wed, 14 Jun 2023 09:02:56 +0200 From: Marc Kleine-Budde To: Judith Mendez Cc: Chandrasekar Ramakrishnan , linux-can@vger.kernel.org, Wolfgang Grandegger , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Schuyler Patton , Tero Kristo , Rob Herring , Krzysztof Kozlowski , devicetree@vger.kernel.org, Oliver Hartkopp , Simon Horman , Conor Dooley , Tony Lindgren Subject: Re: [PATCH v8 2/2] can: m_can: Add hrtimer to generate software interrupt Message-ID: <20230614-creasing-moneybags-c7a9654b72b9-mkl@pengutronix.de> References: <20230530224820.303619-1-jm@ti.com> <20230530224820.303619-3-jm@ti.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="phdc7smsj34rlft4" Content-Disposition: inline In-Reply-To: <20230530224820.303619-3-jm@ti.com> X-SA-Exim-Connect-IP: 2a0a:edc0:0:b01:1d::7b X-SA-Exim-Mail-From: mkl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --phdc7smsj34rlft4 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 30.05.2023 17:48:20, Judith Mendez wrote: > Introduce timer polling method to MCAN since some SoCs may not > have M_CAN interrupt routed to A53 Linux and do not have > interrupt property in device tree M_CAN node. >=20 > On AM62x SoC, MCANs on MCU domain do not have hardware interrupt > routed to A53 Linux, instead they will use timer polling method. >=20 > Add an hrtimer to MCAN class device. Each MCAN will have its own > hrtimer instantiated if there is no hardware interrupt found in > device tree M_CAN node. The timer will generate a software > interrupt every 1 ms. In hrtimer callback, we check if there is > a transaction pending by reading a register, then process by > calling the isr if there is. >=20 > Signed-off-by: Judith Mendez > --- > Changelog: > v8: > - Cancel hrtimer after interrupts in m_can_stop > - Move assignment of hrtimer_callback to m_can_class_register() > - Initialize irq =3D 0 if polling mode is used > - Add reson for polling mode in commit msg > - Remove unrelated change > - Remove polling flag > v7: > - Clean up m_can_platform.c if/else section after removing poll-interval > - Remove poll-interval from patch description > v6: > - Move hrtimer stop/start function calls to m_can_open and m_can_close to > support power suspend/resume > v5: > - Change dev_dbg to dev_info if hardware interrupt exists and polling > is enabled > v4: > - No changes > v3: > - Create a define for 1 ms polling interval > - Change plarform_get_irq to optional to not print error msg > v2: > - Add functionality to check for 'poll-interval' property in MCAN node=20 > - Add 'polling' flag in driver to check if device is using polling method > - Check for timer polling and hardware interrupt cases, default to > hardware interrupt method > - Change ns_to_ktime() to ms_to_ktime() > --- > drivers/net/can/m_can/m_can.c | 34 ++++++++++++++++++++++++-- > drivers/net/can/m_can/m_can.h | 3 +++ > drivers/net/can/m_can/m_can_platform.c | 24 +++++++++++++++--- > 3 files changed, 56 insertions(+), 5 deletions(-) >=20 > diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c > index a5003435802b..d1d1de94e590 100644 > --- a/drivers/net/can/m_can/m_can.c > +++ b/drivers/net/can/m_can/m_can.c > @@ -11,6 +11,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -308,6 +309,9 @@ enum m_can_reg { > #define TX_EVENT_MM_MASK GENMASK(31, 24) > #define TX_EVENT_TXTS_MASK GENMASK(15, 0) > =20 > +/* Hrtimer polling interval */ > +#define HRTIMER_POLL_INTERVAL 1 Please add _MS to the macro name. > + > /* The ID and DLC registers are adjacent in M_CAN FIFO memory, > * and we can save a (potentially slow) bus round trip by combining > * reads and writes to them. > @@ -1414,6 +1418,12 @@ static int m_can_start(struct net_device *dev) > =20 > m_can_enable_all_interrupts(cdev); > =20 > + if (dev->irq =3D=3D 0) { if (!dev->irq) { > + dev_dbg(cdev->dev, "Start hrtimer\n"); > + hrtimer_start(&cdev->hrtimer, ms_to_ktime(HRTIMER_POLL_INTERVAL), > + HRTIMER_MODE_REL_PINNED); > + } > + > return 0; > } > =20 > @@ -1568,6 +1578,11 @@ static void m_can_stop(struct net_device *dev) > { > struct m_can_classdev *cdev =3D netdev_priv(dev); > =20 > + if (dev->irq =3D=3D 0) { if (!dev->irq) { > + dev_dbg(cdev->dev, "Stop hrtimer\n"); > + hrtimer_cancel(&cdev->hrtimer); > + } > + > /* disable all interrupts */ > m_can_disable_all_interrupts(cdev); > =20 > @@ -1793,6 +1808,18 @@ static netdev_tx_t m_can_start_xmit(struct sk_buff= *skb, > return NETDEV_TX_OK; > } > =20 > +static enum hrtimer_restart hrtimer_callback(struct hrtimer *timer) > +{ > + struct m_can_classdev *cdev =3D container_of(timer, struct > + m_can_classdev, hrtimer); > + > + m_can_isr(0, cdev->net); > + > + hrtimer_forward_now(timer, ms_to_ktime(HRTIMER_POLL_INTERVAL)); > + > + return HRTIMER_RESTART; > +} > + > static int m_can_open(struct net_device *dev) > { > struct m_can_classdev *cdev =3D netdev_priv(dev); > @@ -1831,10 +1858,10 @@ static int m_can_open(struct net_device *dev) > err =3D request_threaded_irq(dev->irq, NULL, m_can_isr, > IRQF_ONESHOT, > dev->name, dev); > - } else { > + } > + if (dev->irq > 0) I think you broke the peripheral case. Should be: } else if (dev->irq) { ... } > err =3D request_irq(dev->irq, m_can_isr, IRQF_SHARED, dev->name, > dev); > - } > =20 > if (err < 0) { > netdev_err(dev, "failed to request interrupt\n"); > @@ -2027,6 +2054,9 @@ int m_can_class_register(struct m_can_classdev *cde= v) > goto clk_disable; > } > =20 > + if (cdev->net->irq =3D=3D 0) if (!cdev->net->irq) > + cdev->hrtimer.function =3D &hrtimer_callback; > + > ret =3D m_can_dev_setup(cdev); > if (ret) > goto rx_offload_del; > diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h > index a839dc71dc9b..2ac18ac867a4 100644 > --- a/drivers/net/can/m_can/m_can.h > +++ b/drivers/net/can/m_can/m_can.h > @@ -15,6 +15,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -93,6 +94,8 @@ struct m_can_classdev { > int is_peripheral; > =20 > struct mram_cfg mcfg[MRAM_CFG_NUM]; > + > + struct hrtimer hrtimer; > }; > =20 > struct m_can_classdev *m_can_class_allocate_dev(struct device *dev, int = sizeof_priv); > diff --git a/drivers/net/can/m_can/m_can_platform.c b/drivers/net/can/m_c= an/m_can_platform.c > index 94dc82644113..a7ab2c8b55d1 100644 > --- a/drivers/net/can/m_can/m_can_platform.c > +++ b/drivers/net/can/m_can/m_can_platform.c > @@ -5,6 +5,7 @@ > // > // Copyright (C) 2018-19 Texas Instruments Incorporated - http://www.ti.= com/ > =20 > +#include > #include > #include > =20 > @@ -96,12 +97,29 @@ static int m_can_plat_probe(struct platform_device *p= dev) > goto probe_fail; > =20 > addr =3D devm_platform_ioremap_resource_byname(pdev, "m_can"); > - irq =3D platform_get_irq_byname(pdev, "int0"); > - if (IS_ERR(addr) || irq < 0) { > - ret =3D -EINVAL; > + if (IS_ERR(addr)) { > + ret =3D PTR_ERR(addr); > goto probe_fail; > } > =20 > + if (device_property_present(mcan_class->dev, "interrupts") || > + device_property_present(mcan_class->dev, "interrupt-names")) { > + irq =3D platform_get_irq_byname(pdev, "int0"); > + if (irq =3D=3D -EPROBE_DEFER) { > + ret =3D -EPROBE_DEFER; > + goto probe_fail; > + } > + if (irq < 0) { > + ret =3D -EINVAL; please return the original error value. > + goto probe_fail; > + } > + } else { > + irq =3D 0; Please initialize irq as 0 during declaration. > + dev_dbg(mcan_class->dev, "Polling enabled, initialize hrtimer"); > + hrtimer_init(&mcan_class->hrtimer, CLOCK_MONOTONIC, > + HRTIMER_MODE_REL_PINNED); > + } > + > /* message ram could be shared */ > res =3D platform_get_resource_byname(pdev, IORESOURCE_MEM, "message_ram= "); > if (!res) { > --=20 > 2.34.1 >=20 >=20 regards, Marc --=20 Pengutronix e.K. | Marc Kleine-Budde | Embedded Linux | https://www.pengutronix.de | Vertretung N=C3=BCrnberg | Phone: +49-5121-206917-129 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 | --phdc7smsj34rlft4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEDs2BvajyNKlf9TJQvlAcSiqKBOgFAmSJZh0ACgkQvlAcSiqK BOiXZAgAlfjQ3XR49L3QUorwMohaEwpMi15/PJ8fibvcgBibGEFG0nNp9p1DJM73 4NsJqxEyBuZ1ov+C0U3fBHOUVzfJdU5ih1FTsR9ufr3gaelvzNXtoq2Sby6m0JW5 psxpZnoIk1gHjwVAZt3CGNsMcojw556fdA2fYy0FA3BK7tVjy27YadzcGTcK/uYZ uA+Dey5k2uy/Drat4S8mIVXN2SYOrCX2Eo5FnsqyFkuajpriuy+axeSi1/SudgtN T3ATneDdIRJFVc8yhDaBHTYoNlyyaGGfl1Oy0m0wkXMST3nAq54qIdDs8DhS6qew ZM3U8L649h6bbXsXLMJeftNJb7w+Ow== =a8Iz -----END PGP SIGNATURE----- --phdc7smsj34rlft4--