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.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 5646FC433E2 for ; Mon, 31 Aug 2020 00:07:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33F4B20720 for ; Mon, 31 Aug 2020 00:07:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598832467; bh=ZyMYybuMEAkebYOWDiNvcLUuEsit8Dho7XQFgSOM0m8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=KwpNcQ21fcKFA6RNLnf+OeqV9Xg18Lm4I3d8MxXmw64Q5yA3/DLMdltdDHDY5nOo4 YNvdV77I2mlUM8rHhurjv4D/pFUaneyLO0pG1tPudlsik+LSH2yS9IrtbgZFe9isGS +QllQ85TRAb36Ck7qwxAZfgZdHtGSODO9t7m2Asc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726438AbgHaAHr (ORCPT ); Sun, 30 Aug 2020 20:07:47 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:45389 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726396AbgHaAHo (ORCPT ); Sun, 30 Aug 2020 20:07:44 -0400 Received: by mail-pg1-f194.google.com with SMTP id 67so3335861pgd.12; Sun, 30 Aug 2020 17:07:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8dLIaEgSmpIPRM+QpJKB6VygfCR/Lez/lvI9vbxdOuo=; b=R4giZMs+Oubponj/t6mJMLlqlVgKYT7B3MJp2Ve+W6jNzQ3aawjbSHzxl7xN7764Gf WMeV4uqzknTaGHcFAth15uIqJonqk6e8OQD7Tv5pifEe1ljRmT6yVqqBEZarB+HjQ/VR g9PfBjY/cHSj8tvAZ778x0jvfzUYG99UzG3ay+8JKcVB6U6powGnW2FRMRSkMvOHuJMy Txsgrrxitw96w4Bqb+RT7riIgC4Mr2H/HBj1vk7Fr5RIicwWi4CEg2+ATwv49d1cEpSK ET5nAwlto8PsnBvQpQpfx+eHfzaQsLfId3k5ebcnfgpIlWBs7B2hpbR2/7g7h/N2WPfz yhpg== X-Gm-Message-State: AOAM5322XFPP1Hy6BcTnbFU1zqKjEGECSmhMEFhN1dim4dMAuVXMcnid aGZpjqX4qBi5RDbACqceipM= X-Google-Smtp-Source: ABdhPJym6EJzKUZnyv/CAVuDq43O7DyxXUJ1W8fAlcFWQyh2NOnZIefX0IIP9DViIOabx5g9gTshkQ== X-Received: by 2002:a05:6a00:851:: with SMTP id q17mr7309191pfk.214.1598832463992; Sun, 30 Aug 2020 17:07:43 -0700 (PDT) Received: from localhost ([2601:647:5b00:1161:a4cc:eef9:fbc0:2781]) by smtp.gmail.com with ESMTPSA id u8sm5788366pfm.133.2020.08.30.17.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 17:07:43 -0700 (PDT) Date: Sun, 30 Aug 2020 17:07:42 -0700 From: Moritz Fischer To: Luca Ceresoli Cc: linux-fpga@vger.kernel.org, Moritz Fischer , Tom Rix , Michal Simek , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Anatolij Gustschin Subject: Re: [PATCH v4 3/5] fpga manager: xilinx-spi: fix write_complete timeout handling Message-ID: <20200831000742.GC7421@epycbox.lan> References: <20200830163850.8380-1-luca@lucaceresoli.net> <20200830163850.8380-3-luca@lucaceresoli.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200830163850.8380-3-luca@lucaceresoli.net> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org On Sun, Aug 30, 2020 at 06:38:48PM +0200, Luca Ceresoli wrote: > If this routine sleeps because it was scheduled out, it might miss DONE > going asserted and consider it a timeout. This would potentially make the > code return an error even when programming succeeded. Rewrite the loop to > always check DONE after checking if timeout expired so this cannot happen > anymore. > > While there, also add error checking for gpiod_get_value(). Also avoid > checking the DONE GPIO in two places, which would make the error-checking > code duplicated and more annoying. > > The new loop it written to still guarantee that we apply 8 extra CCLK > cycles after DONE has gone asserted, which is required by the hardware. > > Reported-by: Tom Rix > Reviewed-by: Tom Rix > Signed-off-by: Luca Ceresoli > > --- > > Changes in v4: > - add Reviewed-by Tom Rix > - fix uninitialized variable > (Reported-by: kernel test robot ) > > Changes in v3: > - completely rewrite the loop after Tom pointed out the 'sleep' bug > > This patch is new in v2 > --- > drivers/fpga/xilinx-spi.c | 23 +++++++++++++++-------- > 1 file changed, 15 insertions(+), 8 deletions(-) > > diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c > index 01f494172379..fba8eb4866a7 100644 > --- a/drivers/fpga/xilinx-spi.c > +++ b/drivers/fpga/xilinx-spi.c > @@ -151,22 +151,29 @@ static int xilinx_spi_write_complete(struct fpga_manager *mgr, > struct fpga_image_info *info) > { > struct xilinx_spi_conf *conf = mgr->priv; > - unsigned long timeout; > + unsigned long timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us); > + bool expired = false; > + int done; > int ret; > > - if (gpiod_get_value(conf->done)) > - return xilinx_spi_apply_cclk_cycles(conf); > + /* > + * This loop is carefully written such that if the driver is > + * scheduled out for more than 'timeout', we still check for DONE > + * before giving up and we apply 8 extra CCLK cycles in all cases. > + */ > + while (!expired) { > + expired = time_after(jiffies, timeout); > > - timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us); > - > - while (time_before(jiffies, timeout)) { > + done = get_done_gpio(mgr); > + if (done < 0) > + return done; > > ret = xilinx_spi_apply_cclk_cycles(conf); > if (ret) > return ret; > > - if (gpiod_get_value(conf->done)) > - return xilinx_spi_apply_cclk_cycles(conf); > + if (done) > + return 0; > } > > dev_err(&mgr->dev, "Timeout after config data transfer\n"); > -- > 2.28.0 > Applied to for-next, Thanks 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,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 7B40CC433E2 for ; Mon, 31 Aug 2020 00:09:24 +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 483AE2076D for ; Mon, 31 Aug 2020 00:09:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="qi05CoH8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 483AE2076D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=E7DZoWvMMzXvStLdd0xN+9I0rkhRt9nZZn8ehrZTNhI=; b=qi05CoH8yTMlCbEtI4Y9O175N RVAlK+0ybUVvJntsh7nBEwBtDu6tyFkNTUAXxm+doey5yVhOCtkN99OtohbAQvlY/6kpZcHsuIwOv 9KvV1JpRJMTIGlRUMlctCot85XidodVZPzfKRLSSYfp4PGZwwRmtHt+I/m/Fgr+iSpWZXUsDXV+qT NKl7Jbj7zApBzITYoeG6T5VyxNAxYmGy3Ec4EfH4KkdrsDP5kiMKy2nZh+K6YjdUwRH5DlP0CT1jM a89ROBDfMeGSBUMSTEBvC6EVQAmsj3cjk4NFk7Lj1h+n8I65dzZiNA+3QhBAl/gpY4YhA3rKomTTx siu+LlxjQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCXMS-00067r-BK; Mon, 31 Aug 2020 00:07:48 +0000 Received: from mail-pg1-f195.google.com ([209.85.215.195]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCXMP-00066y-ER for linux-arm-kernel@lists.infradead.org; Mon, 31 Aug 2020 00:07:46 +0000 Received: by mail-pg1-f195.google.com with SMTP id w186so3341049pgb.8 for ; Sun, 30 Aug 2020 17:07:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=8dLIaEgSmpIPRM+QpJKB6VygfCR/Lez/lvI9vbxdOuo=; b=cF2NwGOc7MUx9Pu9hl38WWFIbvoxVqD9TpKYc2UUS+JkL8QRyPqUpf+xUW7L09oBQc yET+rMBOta3+yE4larGqwXJL3qs7HzFxwbM6cC+SmSK+ioaGeCi4kMLm300fIsTf0D9Y T5SNlCwPZj16/Omt9kVp9nWHnI40vRv53qNli9xqPeEmN6xDt7fPv2NJl2y17cALu8zI 9U7PUpJg5mvuwvBVjSLnFkzU/OjDEB6BSydgO6Y3HrJR0THn2o4SCwuecoPtgniIpij5 hKOV67/fHa0xa3kqxjwxlChUnhE+dRhMXhy5kYh/AEM7EglpV5vOgnWJkMIGjbrr3wLy BmOA== X-Gm-Message-State: AOAM533uNDtTeGwkwpXUo/DvipZ1z14y1LmBAVCcJs+zdyRNd61OwmZ7 ORXzgDXf8oVRx/Dk3TlKKD8= X-Google-Smtp-Source: ABdhPJym6EJzKUZnyv/CAVuDq43O7DyxXUJ1W8fAlcFWQyh2NOnZIefX0IIP9DViIOabx5g9gTshkQ== X-Received: by 2002:a05:6a00:851:: with SMTP id q17mr7309191pfk.214.1598832463992; Sun, 30 Aug 2020 17:07:43 -0700 (PDT) Received: from localhost ([2601:647:5b00:1161:a4cc:eef9:fbc0:2781]) by smtp.gmail.com with ESMTPSA id u8sm5788366pfm.133.2020.08.30.17.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Aug 2020 17:07:43 -0700 (PDT) Date: Sun, 30 Aug 2020 17:07:42 -0700 From: Moritz Fischer To: Luca Ceresoli Subject: Re: [PATCH v4 3/5] fpga manager: xilinx-spi: fix write_complete timeout handling Message-ID: <20200831000742.GC7421@epycbox.lan> References: <20200830163850.8380-1-luca@lucaceresoli.net> <20200830163850.8380-3-luca@lucaceresoli.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200830163850.8380-3-luca@lucaceresoli.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200830_200745_510785_F7CEDAB9 X-CRM114-Status: GOOD ( 30.36 ) 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: Tom Rix , linux-fpga@vger.kernel.org, Michal Simek , linux-kernel@vger.kernel.org, Moritz Fischer , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org 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 On Sun, Aug 30, 2020 at 06:38:48PM +0200, Luca Ceresoli wrote: > If this routine sleeps because it was scheduled out, it might miss DONE > going asserted and consider it a timeout. This would potentially make the > code return an error even when programming succeeded. Rewrite the loop to > always check DONE after checking if timeout expired so this cannot happen > anymore. > > While there, also add error checking for gpiod_get_value(). Also avoid > checking the DONE GPIO in two places, which would make the error-checking > code duplicated and more annoying. > > The new loop it written to still guarantee that we apply 8 extra CCLK > cycles after DONE has gone asserted, which is required by the hardware. > > Reported-by: Tom Rix > Reviewed-by: Tom Rix > Signed-off-by: Luca Ceresoli > > --- > > Changes in v4: > - add Reviewed-by Tom Rix > - fix uninitialized variable > (Reported-by: kernel test robot ) > > Changes in v3: > - completely rewrite the loop after Tom pointed out the 'sleep' bug > > This patch is new in v2 > --- > drivers/fpga/xilinx-spi.c | 23 +++++++++++++++-------- > 1 file changed, 15 insertions(+), 8 deletions(-) > > diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c > index 01f494172379..fba8eb4866a7 100644 > --- a/drivers/fpga/xilinx-spi.c > +++ b/drivers/fpga/xilinx-spi.c > @@ -151,22 +151,29 @@ static int xilinx_spi_write_complete(struct fpga_manager *mgr, > struct fpga_image_info *info) > { > struct xilinx_spi_conf *conf = mgr->priv; > - unsigned long timeout; > + unsigned long timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us); > + bool expired = false; > + int done; > int ret; > > - if (gpiod_get_value(conf->done)) > - return xilinx_spi_apply_cclk_cycles(conf); > + /* > + * This loop is carefully written such that if the driver is > + * scheduled out for more than 'timeout', we still check for DONE > + * before giving up and we apply 8 extra CCLK cycles in all cases. > + */ > + while (!expired) { > + expired = time_after(jiffies, timeout); > > - timeout = jiffies + usecs_to_jiffies(info->config_complete_timeout_us); > - > - while (time_before(jiffies, timeout)) { > + done = get_done_gpio(mgr); > + if (done < 0) > + return done; > > ret = xilinx_spi_apply_cclk_cycles(conf); > if (ret) > return ret; > > - if (gpiod_get_value(conf->done)) > - return xilinx_spi_apply_cclk_cycles(conf); > + if (done) > + return 0; > } > > dev_err(&mgr->dev, "Timeout after config data transfer\n"); > -- > 2.28.0 > Applied to for-next, Thanks _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel