From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09E24C433E1 for ; Wed, 29 Jul 2020 02:28:07 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CAE942070B for ; Wed, 29 Jul 2020 02:28:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nHd5UgaY"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="F8T9JCyS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CAE942070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References:Message-ID:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=/2j846uSAb7FL6ZenJmf6hYfmAkBIt1VmihM1Rthxxc=; b=nHd5UgaYkYKiTZ1h6VBPmP0PE wtUn5vPEyHpzeC4awuPNwbdO1lL+erA6CK3Mi+jRWTlrreanUC0QPoNtZC29IaN8filWmPea+Yd3s SPepd93KoOaM2knFB/sC8NbQv9Qw+cAWzHbqpVfI9t3rC8D05RR8Lf1SyGJWIA/wUrS7IMiv1pb+j VK99t6KLPgpFEjjpkdYmy/Cxn7beIZer4FThtBYomXC4y/Fo0cjy88+jFNt+1XLDDWkRtCz9mvC4p VKkL44dYIHsJdlXDwX4T2SIWuaGDPP7ZpfOHXJLaua0x+Man8s7ho19S2bHFSqeWBTwAFvG7trvYE 8ONiHJkSg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0bnk-00055r-66; Wed, 29 Jul 2020 02:26:40 +0000 Received: from mail-am6eur05on2063.outbound.protection.outlook.com ([40.107.22.63] helo=EUR05-AM6-obe.outbound.protection.outlook.com) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1k0bnh-00054O-0K for linux-arm-kernel@lists.infradead.org; Wed, 29 Jul 2020 02:26:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bQdc5c7ZylctSMDsHCguuN7Bp5VQM5tBEV9LRo7NPGYwzcFPFq4a9t3GhjjB8mD1lC7dvTDf4QCuyVrYMemNg2uxgA64f+nuU6bs3LpGjiZKifBou+E3TaISM21OA9oFsrVQNfyrCka3GI9R07OWYNQGTQq3vQ0ypnNcf/vAiRJ4Wab/rpTa8Q520+uFYdanl8P908Ri/U9IHx3fsVVxbsvAwrGutH3auK0QGVB94kB63ePWWHNxqAc23cV9kdDnRk2dOd5Q5UrfXZtl6+3pgzImFm3I8o6q9qfyfxXQct0pCaN148X0R6792p5jzATyuuWt5M1JO/O0LRJ4IZLNJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YONlEwMA6CnCGfLpk0tRPQecJeVfXgQV3PfGkmU5HFk=; b=Xcl4EaUMYdhbA4X1/xi4Lyk7hqsAO/CVKsyqfW0n9AxSZN8cQxZOWb/k3RH7qS4rHgkdq8ccOTwd2dXwKAN9IDrf2f0HlYwYcHvdGjVWfOs2x0diG0NorDV3cxC4XN41BC7tWbIEQeOZYvD6D98QspK2QAC9Fk2+JHRLOlRhrvdK8Ryn/YH3hNvGarioZVvKMlKG9I3GlSFLvphv4Iw1it8lNGe/NZYT87Z929TxXi4SOmlysB3ZVAn6KgbLG4gDkmNB/trTkC3SLygW6rpbjxDPo49KKdO/XDADOKJvG4G+Dk3MIYfzDA54wpjBdQBuq8DfrovaNMtGtaE3+MGwqw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YONlEwMA6CnCGfLpk0tRPQecJeVfXgQV3PfGkmU5HFk=; b=F8T9JCySUxMOmdMscLQfpgHH399FDm0blVYDOoeQkU7MfGWFYiqW+4cHBeeC1QCQ/rgk97SkYF3alyPefqNchCqbdbs0KvXOn0ZzPJludhvnN0ntjwDCC809M6mjOh8gHGvJJq/aAzyh2C1gF7KDEa179ar+tnqfY9xgGxB+RhU= Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com (2603:10a6:8:10::18) by DB6PR0401MB2536.eurprd04.prod.outlook.com (2603:10a6:4:36::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3216.26; Wed, 29 Jul 2020 02:26:33 +0000 Received: from DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::49f8:20ce:cf20:80b3]) by DB3PR0402MB3916.eurprd04.prod.outlook.com ([fe80::49f8:20ce:cf20:80b3%6]) with mapi id 15.20.3216.034; Wed, 29 Jul 2020 02:26:33 +0000 From: Anson Huang To: Guenter Roeck , "wim@linux-watchdog.org" , "shawnguo@kernel.org" , "s.hauer@pengutronix.de" , "kernel@pengutronix.de" , "festevam@gmail.com" , "linux-watchdog@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH 1/2] watchdog: imx7ulp: Strictly follow the sequence for wdog operations Thread-Topic: [PATCH 1/2] watchdog: imx7ulp: Strictly follow the sequence for wdog operations Thread-Index: AQHWZKrocghDMpUaBEu/lC3XXGngDakdDvaAgACUUzCAADIzYA== Date: Wed, 29 Jul 2020 02:26:33 +0000 Message-ID: References: <1595918567-2017-1-git-send-email-Anson.Huang@nxp.com> <566adde7-c397-72f1-145d-fbca9de77cd7@roeck-us.net> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: roeck-us.net; dkim=none (message not signed) header.d=none;roeck-us.net; dmarc=none action=none header.from=nxp.com; x-originating-ip: [119.31.174.67] x-ms-publictraffictype: Email x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 33e89742-b3f0-4c1d-39f1-08d83366cf88 x-ms-traffictypediagnostic: DB6PR0401MB2536: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 2jsD4j9XrEGFo9kFA0xIAGCmGqs99+qoSXkQlAgdYSB4eiIy7bj3Ed+HUEraw0wgQI1Xfab1lOt1bgL5+si573EyE4t21mXmdSuTtA2SQqJWlg4stP3qjnBhzMUqTxwiuCbq+eLmzdYw8sdy6yqlSNC6J+I7pMZO9roi53BLKZ3/2xhqkOk4wWetbkVTR/WiRj4DJc1seIMY9t5SIDx708iQFojUABJHVbs6ze4BlJycPibdAgcaxjNp1ldPMcmqDSRVbQDtwPQrm+bo7JJVzlIFgSPRklEGRo5st/w6WAoNwbzLNK1IY8qPlozMb2BF6Uooxt8gs4Y2wgXA36tihQ== x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DB3PR0402MB3916.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFTY:; SFS:(4636009)(376002)(346002)(136003)(396003)(366004)(39860400002)(33656002)(86362001)(110136005)(5660300002)(71200400001)(4326008)(2906002)(316002)(478600001)(52536014)(83380400001)(186003)(66946007)(64756008)(76116006)(7696005)(9686003)(8936002)(66446008)(26005)(55016002)(44832011)(66476007)(66556008)(8676002)(6506007)(53546011); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata: Bl/JkE3Je4qclvkYpM6xyvqCghHLFmD7bUPO9pO9N4ujWiYprwVQWzhWyrlyv2ZfNUFMkTkavLKnTJDdBoij/zS+lQiJyiuG6Qo+s3VDgGST9SludkdKvY9oAspjTIc0jSGLHZpuFsz3iujQxvUD8uxoi+3H0iiceiotNYGJzuyARJraX9/+1Plkea/jmTcfFf9+t0ZLxnu5xJtjDEYELNQfBMY0NR5O/sdhFWkCqaUvLbMOz1ZTyifA7/imM8yN71MO3QpTyFWbfwwkzmk7l9HBb+WA+SgrSdhPK5j/ZSV38p+VOeFArR6EJ1vddORux5fSZkEyhiQStsawrMRGkUuEGx1lU2DcTlvjmBgpgehB4Vj5B7hn3x0vdozqIY7X5cDgRrie32TS6NTx1UkbWcPDPN541w4mgY/WJJvemR27W5JGO/k5TWO1TIsuwNUMBO+FVEtXDmMbf6GeF8bAjuqQUCtNCvD7WQpL87nxtY4= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DB3PR0402MB3916.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33e89742-b3f0-4c1d-39f1-08d83366cf88 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Jul 2020 02:26:33.3148 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 5FLpL+ov3AWd0EvidSW5IO67a253hpTEaMgHxSkQLDzXFbskXM/eK8TWKyGrwOsuJmh3mmN0iXMKJbH8SFpDeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0401MB2536 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200728_222637_101142_AD346E2B X-CRM114-Status: GOOD ( 33.64 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dl-linux-imx Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, Guenter > Subject: RE: [PATCH 1/2] watchdog: imx7ulp: Strictly follow the sequence for > wdog operations > > Hi, Guenter > > > > Subject: Re: [PATCH 1/2] watchdog: imx7ulp: Strictly follow the > > sequence for wdog operations > > > > On 7/27/20 11:42 PM, Anson Huang wrote: > > > According to reference manual, the i.MX7ULP WDOG's operations should > > > follow below sequence: > > > > > > 1. disable global interrupts; > > > 2. unlock the wdog and wait unlock bit set; 3. reconfigure the wdog > > > and wait for reconfiguration bit set; 4. enabel global interrupts. > > > > > > Strictly follow the recommended sequence can make it more robust. > > > > > > Signed-off-by: Anson Huang > > > --- > > > drivers/watchdog/imx7ulp_wdt.c | 29 +++++++++++++++++++++++++++++ > > > 1 file changed, 29 insertions(+) > > > > > > diff --git a/drivers/watchdog/imx7ulp_wdt.c > > > b/drivers/watchdog/imx7ulp_wdt.c index 7993c8c..b414ecf 100644 > > > --- a/drivers/watchdog/imx7ulp_wdt.c > > > +++ b/drivers/watchdog/imx7ulp_wdt.c > > > @@ -4,6 +4,7 @@ > > > */ > > > > > > #include > > > +#include > > > #include > > > #include > > > #include > > > @@ -48,17 +49,32 @@ struct imx7ulp_wdt_device { > > > struct clk *clk; > > > }; > > > > > > +static inline void imx7ulp_wdt_wait(void __iomem *base, u32 mask) { > > > + int retries = 100; > > > + > > > + do { > > > + if (readl_relaxed(base + WDOG_CS) & mask) > > > + return; > > > + usleep_range(200, 1000); > > > + } while (retries--); > > > > Sleep with interrupts disabled ? I can not imagine that this works > > well in a single CPU system. On top of that, it seems quite pointless. > > Either you don't want to be interrupted or you do, but sleeping with > > interrupts disabled really doesn't make sense. And does it really take > > 200-1000 uS for the watchdog subsystem to react, and sometimes up to > > 200 * 100 = 20 mS ? That seems highly unlikely. If such a delay loop > > is indeed needed, it should be limited by a time, not by number of > repetitions. > > > > Unless there is evidence that there is a problem that needs to be > > solved, I am not going to accept this code. > > > > Oops, this is a mistake of using sleep with interrupt disabled, sorry for that. > The best option is to use readl_relaxed_poll_timeout_atomic() to poll the > status bit, however, the i.MX7ULP watchdog is very special that the unlock > window ONLY open for several cycles, that means the unlock status bit will be > set and then clear automatically after those cycles, using > readl_relaxed_poll_timeout_atomic() will fail since there are many timeout > handle code in it and the unlock window is open and close during this timeout > handle interval, so it fail to catch the unlock bit. > > The ideal option is using atomic polling without any other timeout check to > make sure the unlock window is NOT missed, but I think Linux kernel will NOT > accept a while loop without timeout, and that is why I tried to use > usleep_ranges(), but obviously I made a mistake of using it with IRQ disabled. > > Do you have any suggestion of how to handle such case? If the hardware ONLY > unlock the register for a small window, how to poll the status bit with timeout > handle and also make sure the timeout handle code as quick as possible to > NOT miss the window? > I did more experiment and found that below readl_poll_timeout_atomic() is actually working, so I sent a V2 with it, please help review, thank you. + u32 val = readl(base + WDOG_CS); + + if (!(val & mask)) + WARN_ON(readl_poll_timeout_atomic(base + WDOG_CS, val, + val & mask, 0, + WDOG_WAIT_TIMEOUT)); Thanks, Anson _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel