Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp4681689rwl; Wed, 28 Dec 2022 07:27:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXtskPRVXwTX6iNapd758xgcrc3Vnn7agRf3qkj4uUhlOy0A3i9wjTCJ4YhZgq59NJwYk4XQ X-Received: by 2002:a05:6a00:1f0d:b0:573:d183:4218 with SMTP id be13-20020a056a001f0d00b00573d1834218mr39824037pfb.10.1672241270418; Wed, 28 Dec 2022 07:27:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672241270; cv=none; d=google.com; s=arc-20160816; b=NHB+et75afh69YPeVzcl4i3g8xQ9gu8Pa+MAyGt8iDjZGlr9VF7PlnXSlHpnA/zNFs 6G+Kooulbs5sRCZF6OI5AFiuTzDG5DYu+cT7pNG+a2JBtMlbDgRQokw7m24ndzoN6DOs ckgJnZfw8L/JZuLhDJvnz6bodlO7uuNZCv42cSUF4rcn5LI4XraXkLtpEkT42JfxNzty n5lc1a1oz7PYo+as10LEP9tE2qnLnXo6v0pCkDr4iScD+6un+iW8IFctYfYEQhKb5vs6 ev7OHccpvHKzW47dVv/OOaCtpCqcte/4J7u4ClXaJ9RTGeXcEESkw8LzJNq+7LdiC1qg YXhQ== 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:dkim-signature; bh=xB2XFnAhAdowZNGHQX1Mln7IzDwaxkNCBUPKdAZQjg4=; b=OyxanxyiOrQKq5qUWvZCAiVhf9Ma4DcZBakLVtVNjXPn6gvO2EZ0ZtRmNqGzl5bDCj 9AVnFD7EnS50BFMkDk78omhgBaA0OFQPcf240q2b6u/srshUBNojALMB0BUjVLhkFECI 5W9iwPPGyeykMGT83VHq8srDSYSfGKaynCyL5xNki7fd1FxEWPAImvtegaokBue8Gkpy s/li4uYCaC09wDppcrXTe4WE/Z73kTK9RwoJNxMSYMmzAj79S2KuzNFcx4Nd1Tk3CI3i LdYsfQvf0a8t3y3jFiU7OC0IJ7mq/wka6kHr6JhV/P6JRH0iNRXAnJqP8CnRavs9kcny Rnfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ofOAEPdZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g11-20020a056a0023cb00b005778bad9750si17451674pfc.17.2022.12.28.07.27.42; Wed, 28 Dec 2022 07:27:50 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ofOAEPdZ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233088AbiL1OuL (ORCPT + 64 others); Wed, 28 Dec 2022 09:50:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233073AbiL1OuJ (ORCPT ); Wed, 28 Dec 2022 09:50:09 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 71F43B41; Wed, 28 Dec 2022 06:50:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 280DAB81719; Wed, 28 Dec 2022 14:50:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C1E29C43392; Wed, 28 Dec 2022 14:50:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672239005; bh=st2aZQPAZqAuDALvTWTipwWXG6nYNaBsVrFY+I38dvI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ofOAEPdZyAJC7JdDAOCuIJpI6P+fWDwLPcYpxLpr5FGTdDnHy3LthFzsXs3rh/51p +85Ch9sVoMMsvm4ethsInCcexgUgdJvojnkFFzGhrJCkW/7xYNOBVmEh41ShswcoH/ vblTeN6/hXiTVvIeYb0WrqO1hPG/Cn2wx83DUdqs2AaJkvwQG56d3WiZNUXCyqPNfM z57YH0XdvrcJefzT3u186GAp71cQ1GD4rPJ8GPtyOiSh2x4ATx1oJcdBWqQT/2c9dQ 7IAWOziFN31upes6c7/7JF2qH+mU1htKziX0gOut4mnY+Yvj/pueNyFVAHQOXnVrYw hEgBoh+Fjry8g== Date: Wed, 28 Dec 2022 14:50:01 +0000 From: Conor Dooley To: Ivan Bornyakov Cc: Conor Dooley , Moritz Fischer , Wu Hao , Xu Yilun , Tom Rix , Ilpo =?iso-8859-1?Q?J=E4rvinen?= , linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, system@metrotek.ru Subject: Re: [PATCH v3 2/3] fpga: microchip-spi: rewrite status polling in a time measurable way Message-ID: References: <20221227100450.2257-1-i.bornyakov@metrotek.ru> <20221227100450.2257-3-i.bornyakov@metrotek.ru> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="+k8pTdWXhUpj/t3q" Content-Disposition: inline In-Reply-To: <20221227100450.2257-3-i.bornyakov@metrotek.ru> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham 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 --+k8pTdWXhUpj/t3q Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Dec 27, 2022 at 01:04:49PM +0300, Ivan Bornyakov wrote: > Original busy loop with retries count in mpf_poll_status() is not too > reliable, as it takes different times on different systems. Replace it > with read_poll_timeout() macro. >=20 > While at it, fix polling stop condition to met function's original > intention declared in the comment. The issue with original polling stop > condition is that it stops if any of mask bits is set, while intention > was to stop if all mask bits is set. This was not noticible because only > MPF_STATUS_READY is passed as mask argument and it is BIT(1). >=20 > Fixes: 5f8d4a900830 ("fpga: microchip-spi: add Microchip MPF FPGA manager= ") > Signed-off-by: Ivan Bornyakov > --- > drivers/fpga/microchip-spi.c | 24 ++++++++++-------------- > 1 file changed, 10 insertions(+), 14 deletions(-) >=20 > diff --git a/drivers/fpga/microchip-spi.c b/drivers/fpga/microchip-spi.c > index e72fedd93a27..8d1d9476d0cc 100644 > --- a/drivers/fpga/microchip-spi.c > +++ b/drivers/fpga/microchip-spi.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -33,7 +34,7 @@ > =20 > #define MPF_BITS_PER_COMPONENT_SIZE 22 > =20 > -#define MPF_STATUS_POLL_RETRIES 10000 > +#define MPF_STATUS_POLL_TIMEOUT (2 * USEC_PER_SEC) > #define MPF_STATUS_BUSY BIT(0) > #define MPF_STATUS_READY BIT(1) > #define MPF_STATUS_SPI_VIOLATION BIT(2) > @@ -197,21 +198,16 @@ static int mpf_ops_parse_header(struct fpga_manager= *mgr, > /* Poll HW status until busy bit is cleared and mask bits are set. */ > static int mpf_poll_status(struct mpf_priv *priv, u8 mask) > { > - int status, retries =3D MPF_STATUS_POLL_RETRIES; > + int ret, status; > =20 > - while (retries--) { > - status =3D mpf_read_status(priv); > - if (status < 0) > - return status; > - > - if (status & MPF_STATUS_BUSY) > - continue; > - > - if (!mask || (status & mask)) > - return status; > - } Would you mind moving the small comment before the function down to here and mentioning handling the failure case? The current implementation is a bit easier to understand than the new version that's wrapped in read_poll_timeout(). Otherwise, change seems like a good idea. Acked-by: Conor Dooley > + ret =3D read_poll_timeout(mpf_read_status, status, > + (status < 0) || > + ((status & (MPF_STATUS_BUSY | mask)) =3D=3D mask), > + if (ret < 0) > + return ret; > =20 > - return -EBUSY; > + return status; > } > =20 > static int mpf_spi_write(struct mpf_priv *priv, const void *buf, size_t = buf_size) > --=20 > 2.38.2 >=20 >=20 --+k8pTdWXhUpj/t3q Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iHUEABYIAB0WIQRh246EGq/8RLhDjO14tDGHoIJi0gUCY6xXmQAKCRB4tDGHoIJi 0ojBAQDaodmMFhTX1JcUQ7P9gZqx73+VFueROx+yv3Msvec1ngD/Q6BW5eZ1I22Y Icgcw/pWs3wHFbUeZ4cIeuuc+wQtMwk= =Qpli -----END PGP SIGNATURE----- --+k8pTdWXhUpj/t3q--