From patchwork Sun Aug 30 16:38:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11745241 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E5ED13B1 for ; Sun, 30 Aug 2020 16:40:40 +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 EBBA2206E3 for ; Sun, 30 Aug 2020 16:40:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="3RWc7nDt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EBBA2206E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lucaceresoli.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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: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:In-Reply-To:References:List-Owner; bh=KAzmFtzRPI7BgyLXJ4yEO2ISxLdCiFSYnqIDyDqRYDk=; b=3RWc7nDtA8Uu9iLTX47In/7Twx tG2MtNmfjjYqwUptLWLE4eaK7U6HztscHng6p6C4ekQOe8abQ7/ewfPhNk3fHTEuvMnEBgDaK0WEj 4+Tcs7xv0kegReDPRQ0lLosuC0IbptuF2CzAnsdvkZ1AEQSKFrNUC7atyvd950HKvMQhGkJHOL0Qu 9Y67HFCBHYj2adnMhTenotcx1WuCwLEVim1S2eM1vFC8Ij+kfyvPMAUHM/eO993DMxR5AN/InmBlz YFYIa1NDqg/SM5q2tO4NZ5bZbWTlWKeBVA7cphK3N9OhpsBwV7diXxPPq1uP4TXNICpSzJwnZbMMn 1pkfedZQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMQ-0005OX-Ms; Sun, 30 Aug 2020 16:39:18 +0000 Received: from hostingweb31-40.netsons.net ([89.40.174.40]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMF-0005Kz-0p for linux-arm-kernel@lists.infradead.org; Sun, 30 Aug 2020 16:39:08 +0000 Received: from [78.134.86.56] (port=34202 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kCQMB-000E3G-O1; Sun, 30 Aug 2020 18:39:03 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v4 1/5] fpga manager: xilinx-spi: remove stray comment Date: Sun, 30 Aug 2020 18:38:46 +0200 Message-Id: <20200830163850.8380-1-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200830_123907_350233_E4D5FACF X-CRM114-Status: UNSURE ( 7.51 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [89.40.174.40 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 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 , Michal Simek , linux-kernel@vger.kernel.org, Moritz Fischer , Luca Ceresoli , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Remove comment committed by mistake. Fixes: dd2784c01d93 ("fpga manager: xilinx-spi: check INIT_B pin during write_init") Reviewed-by: Tom Rix Signed-off-by: Luca Ceresoli --- Changes in v4: - add Reviewed-by Tom Rix Changes in v3: none. Changes in v2: none. --- drivers/fpga/xilinx-spi.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c index 2967aa2a74e2..502fae0d1d85 100644 --- a/drivers/fpga/xilinx-spi.c +++ b/drivers/fpga/xilinx-spi.c @@ -57,7 +57,6 @@ static int wait_for_init_b(struct fpga_manager *mgr, int value, if (conf->init_b) { while (time_before(jiffies, timeout)) { - /* dump_state(conf, "wait for init_d .."); */ if (gpiod_get_value(conf->init_b) == value) return 0; usleep_range(100, 400); From patchwork Sun Aug 30 16:38:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11745243 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BDA5722 for ; Sun, 30 Aug 2020 16:40:41 +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 3521A206E3 for ; Sun, 30 Aug 2020 16:40:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="NLSQ6AcO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3521A206E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lucaceresoli.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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:References:In-Reply-To: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=teRVLNnGfTs6vEH2E6d+0BRFjfQha5bfA6xaWHnrhKE=; b=NLSQ6AcO+wDDotedAMBtxvA8w i0GXWPnTqz0j6ke22/Xh/mMtz75wGaJkyCUb1hGTKcTaX6vMpMKDRTpQxJHU5go6FDSkIrujJCNWm bYowf/thK88OUhzQnaXcgfgd5UogeDnzwQVptZXSH7YGswJ+CVV0mo/t5XQ1kM+sgjRtYojrLeZMM 5visITEoEew7ggZx9hW2P8HMn6T9Cfk+0/4I1e0Xeg+DUdauu21wT8krITCE3UndYcWO4hp9Hs609 4on2cU7Rm5/6L31qTIefUByhE7CzC/9wYsLk8otg+kZ2ZIYgaR1NaPrugVtqMcKvYGOFZz8IV5Xv5 M3ndqZ9bw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMM-0005Nq-II; Sun, 30 Aug 2020 16:39:14 +0000 Received: from hostingweb31-40.netsons.net ([89.40.174.40]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMF-0005Kx-0p for linux-arm-kernel@lists.infradead.org; Sun, 30 Aug 2020 16:39:08 +0000 Received: from [78.134.86.56] (port=34202 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kCQMC-000E3G-2F; Sun, 30 Aug 2020 18:39:04 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v4 2/5] fpga manager: xilinx-spi: remove final dot from dev_err() strings Date: Sun, 30 Aug 2020 18:38:47 +0200 Message-Id: <20200830163850.8380-2-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830163850.8380-1-luca@lucaceresoli.net> References: <20200830163850.8380-1-luca@lucaceresoli.net> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200830_123907_205530_8BA88F97 X-CRM114-Status: UNSURE ( 9.21 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [89.40.174.40 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 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 , Michal Simek , linux-kernel@vger.kernel.org, Moritz Fischer , Luca Ceresoli , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Most dev_err messages in this file have no final dot. Remove the only two exceptions to make them consistent. Reviewed-by: Tom Rix Signed-off-by: Luca Ceresoli --- Changes in v4: - add Reviewed-by Tom Rix Changes in v3: none. Changes in v2: - move before the "provide better diagnostics on programming failure" patch for clarity --- drivers/fpga/xilinx-spi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c index 502fae0d1d85..01f494172379 100644 --- a/drivers/fpga/xilinx-spi.c +++ b/drivers/fpga/xilinx-spi.c @@ -77,7 +77,7 @@ static int xilinx_spi_write_init(struct fpga_manager *mgr, int err; if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) { - dev_err(&mgr->dev, "Partial reconfiguration not supported.\n"); + dev_err(&mgr->dev, "Partial reconfiguration not supported\n"); return -EINVAL; } @@ -169,7 +169,7 @@ static int xilinx_spi_write_complete(struct fpga_manager *mgr, return xilinx_spi_apply_cclk_cycles(conf); } - dev_err(&mgr->dev, "Timeout after config data transfer.\n"); + dev_err(&mgr->dev, "Timeout after config data transfer\n"); return -ETIMEDOUT; } From patchwork Sun Aug 30 16:38:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11745239 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E4456722 for ; Sun, 30 Aug 2020 16:39:30 +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 BD58E20714 for ; Sun, 30 Aug 2020 16:39:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="avEfDwJq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BD58E20714 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lucaceresoli.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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:References:In-Reply-To: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=9arx8gzSw+xdjLywhHbceTKmH6xstO1AGiF/+pRHxhY=; b=avEfDwJqpi8tPitimb2G/CnVQ g2tnsPWYpGqmrGJkZ7aPT11ftmoKDgdUGidGdxwlxnzHZrBocd5ZG8s7/SbDal6A3P8TK72KVds2w ikH6sbswEsGA2QCNOyh8+ga+D47OCkpp8+gTLAheM+MGWjQAYdBcsHeUp8FkBtKZfq5e8OEpYOUzZ 8F0KfUaU20Mp1mTtByXpY1VTLh4/Sjb4fC7/DzveFcIyV5OXKyOdj20MCTixgeJ5ym/OzPCHxBrwk dS0X06mS2xUrv1esSQrPXum0q5MEekl2IWUUTsqyweiTV45q+BZY9DKmevggiIfLMLzIo2cJ6iouQ Qli25FuHA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMO-0005OG-NN; Sun, 30 Aug 2020 16:39:16 +0000 Received: from hostingweb31-40.netsons.net ([89.40.174.40]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMF-0005Ky-0j for linux-arm-kernel@lists.infradead.org; Sun, 30 Aug 2020 16:39:08 +0000 Received: from [78.134.86.56] (port=34202 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kCQMC-000E3G-Dm; Sun, 30 Aug 2020 18:39:04 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v4 3/5] fpga manager: xilinx-spi: fix write_complete timeout handling Date: Sun, 30 Aug 2020 18:38:48 +0200 Message-Id: <20200830163850.8380-3-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830163850.8380-1-luca@lucaceresoli.net> References: <20200830163850.8380-1-luca@lucaceresoli.net> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200830_123907_341473_7EFDA0D2 X-CRM114-Status: GOOD ( 15.53 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [89.40.174.40 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 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 , Michal Simek , linux-kernel@vger.kernel.org, Moritz Fischer , Luca Ceresoli , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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"); From patchwork Sun Aug 30 16:38:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11745245 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59A4413B1 for ; Sun, 30 Aug 2020 16:40:43 +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 3284F206E3 for ; Sun, 30 Aug 2020 16:40:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TzCsHyW+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3284F206E3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lucaceresoli.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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:References:In-Reply-To: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=YYT8eMBaOQ8ZBEudyDoXFDluq8V+fStNvgxrNXo5w+k=; b=TzCsHyW+fRJPw8wcwEJEwvrSp NxqFOVFXDoInmjTMbdo/2keQ2nl2aJ9h0xSaT7yWTISx4d5tT7iXtbuIK8U+RYHAdlMSjNCmRGR2Y QSd9lfdqpykFBfb9q+Ibx0dRfwgsnKFdX/UmC6rRyNaR2yh6iRsqCQXcV+TwM43qm/eTytE+40kyi EONXMPePN0Y/yKc+Q/mdSIR9X+L0t4VMaq3ZeIcAvKCV+zYuWgEMK+irWwX5YYPdGVClw0lB4Bl7a bRCTkdnzgsvCvrNK/P21oWCLUrGzidkQ0sg2b3WkEXFZSHJFz1pVpb+V+Timxnbns9NVPeDd8rOUF 5ZdTALZIw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMI-0005Mu-5j; Sun, 30 Aug 2020 16:39:10 +0000 Received: from hostingweb31-40.netsons.net ([89.40.174.40]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMF-0005L0-0h for linux-arm-kernel@lists.infradead.org; Sun, 30 Aug 2020 16:39:08 +0000 Received: from [78.134.86.56] (port=34202 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kCQMC-000E3G-Of; Sun, 30 Aug 2020 18:39:04 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v4 4/5] fpga manager: xilinx-spi: add error checking after gpiod_get_value() Date: Sun, 30 Aug 2020 18:38:49 +0200 Message-Id: <20200830163850.8380-4-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830163850.8380-1-luca@lucaceresoli.net> References: <20200830163850.8380-1-luca@lucaceresoli.net> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200830_123907_355720_3DC75EFF X-CRM114-Status: GOOD ( 13.35 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [89.40.174.40 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 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 , Michal Simek , linux-kernel@vger.kernel.org, Moritz Fischer , Luca Ceresoli , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Current code calls gpiod_get_value() without error checking. Should the GPIO controller fail, execution would continue without any error message. Fix by checking for negative error values. Reported-by: Tom Rix Reviewed-by: Tom Rix Signed-off-by: Luca Ceresoli --- Changes in v4: - add Reviewed-by Tom Rix Changes in v3: - rebase on previous patches This patch is new in v2 --- drivers/fpga/xilinx-spi.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c index fba8eb4866a7..52aab5a1f0ba 100644 --- a/drivers/fpga/xilinx-spi.c +++ b/drivers/fpga/xilinx-spi.c @@ -27,11 +27,22 @@ struct xilinx_spi_conf { struct gpio_desc *done; }; -static enum fpga_mgr_states xilinx_spi_state(struct fpga_manager *mgr) +static int get_done_gpio(struct fpga_manager *mgr) { struct xilinx_spi_conf *conf = mgr->priv; + int ret; + + ret = gpiod_get_value(conf->done); + + if (ret < 0) + dev_err(&mgr->dev, "Error reading DONE (%d)\n", ret); - if (!gpiod_get_value(conf->done)) + return ret; +} + +static enum fpga_mgr_states xilinx_spi_state(struct fpga_manager *mgr) +{ + if (!get_done_gpio(mgr)) return FPGA_MGR_STATE_RESET; return FPGA_MGR_STATE_UNKNOWN; @@ -57,10 +68,21 @@ static int wait_for_init_b(struct fpga_manager *mgr, int value, if (conf->init_b) { while (time_before(jiffies, timeout)) { - if (gpiod_get_value(conf->init_b) == value) + int ret = gpiod_get_value(conf->init_b); + + if (ret == value) return 0; + + if (ret < 0) { + dev_err(&mgr->dev, "Error reading INIT_B (%d)\n", ret); + return ret; + } + usleep_range(100, 400); } + + dev_err(&mgr->dev, "Timeout waiting for INIT_B to %s\n", + value ? "assert" : "deassert"); return -ETIMEDOUT; } @@ -85,7 +107,6 @@ static int xilinx_spi_write_init(struct fpga_manager *mgr, err = wait_for_init_b(mgr, 1, 1); /* min is 500 ns */ if (err) { - dev_err(&mgr->dev, "INIT_B pin did not go low\n"); gpiod_set_value(conf->prog_b, 0); return err; } @@ -93,12 +114,10 @@ static int xilinx_spi_write_init(struct fpga_manager *mgr, gpiod_set_value(conf->prog_b, 0); err = wait_for_init_b(mgr, 0, 0); - if (err) { - dev_err(&mgr->dev, "INIT_B pin did not go high\n"); + if (err) return err; - } - if (gpiod_get_value(conf->done)) { + if (get_done_gpio(mgr)) { dev_err(&mgr->dev, "Unexpected DONE pin state...\n"); return -EIO; } From patchwork Sun Aug 30 16:38:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11745237 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D9C8313B1 for ; Sun, 30 Aug 2020 16:39:28 +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 B164720714 for ; Sun, 30 Aug 2020 16:39:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="2odE9yvO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B164720714 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lucaceresoli.net Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.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:References:In-Reply-To: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=S100rJLgARzuEDbzorBsVFgL1OaJNm08X4mWjCqKgP4=; b=2odE9yvOg+QBVm5rIr+3w6RCm +cywNiIUtAbC3rA7siSWTVJKXxnLORRWG8gt0VOvNIqsSCVpPL0PQLE7s3gKJG7nD0//7Ud2p2EwD tuQaSYm3cpyVfoTO1nINawhAC+BEbF+kM52uikfq/U63PVWJYCjfHYGtdgCN1bPQp9EycDjueZ7yN o+zuHBb0O+X/jjjB9XW2MYYzfbOuzwFCkW7gjvhQIHMXkgWwzG/9AtyuhoH9kjvMQvViFlKH/XnmW fp+tob/En7Y23+evK7G0kIR7rUdYE1KJ43g639z8zUTrZ+BuRgdQfx3SEWXfzZS6/Ew8BwUwMe44C toXdscMcA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMJ-0005N4-Gi; Sun, 30 Aug 2020 16:39:11 +0000 Received: from hostingweb31-40.netsons.net ([89.40.174.40]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kCQMF-0005L2-0p for linux-arm-kernel@lists.infradead.org; Sun, 30 Aug 2020 16:39:08 +0000 Received: from [78.134.86.56] (port=34202 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kCQMD-000E3G-0X; Sun, 30 Aug 2020 18:39:05 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v4 5/5] fpga manager: xilinx-spi: provide better diagnostics on programming failure Date: Sun, 30 Aug 2020 18:38:50 +0200 Message-Id: <20200830163850.8380-5-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200830163850.8380-1-luca@lucaceresoli.net> References: <20200830163850.8380-1-luca@lucaceresoli.net> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - hostingweb31.netsons.net X-AntiAbuse: Original Domain - lists.infradead.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca+lucaceresoli.net/only user confirmed/virtual account not confirmed X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200830_123907_346015_3DF7F6EB X-CRM114-Status: GOOD ( 10.58 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [89.40.174.40 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 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 , Michal Simek , linux-kernel@vger.kernel.org, Moritz Fischer , Luca Ceresoli , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org When the DONE pin does not go high after programming to confirm programming success, the INIT_B pin provides some info on the reason. Use it if available to provide a more explanatory error message. Reviewed-by: Tom Rix Signed-off-by: Luca Ceresoli --- Changes in v4: - add Reviewed-by Tom Rix Changes in v3: none. Changes in v2: - also check for gpiod_get_value() errors (Tom Rix) --- drivers/fpga/xilinx-spi.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c index 52aab5a1f0ba..824abbbd631e 100644 --- a/drivers/fpga/xilinx-spi.c +++ b/drivers/fpga/xilinx-spi.c @@ -195,7 +195,21 @@ static int xilinx_spi_write_complete(struct fpga_manager *mgr, return 0; } - dev_err(&mgr->dev, "Timeout after config data transfer\n"); + if (conf->init_b) { + ret = gpiod_get_value(conf->init_b); + + if (ret < 0) { + dev_err(&mgr->dev, "Error reading INIT_B (%d)\n", ret); + return ret; + } + + dev_err(&mgr->dev, + ret ? "CRC error or invalid device\n" + : "Missing sync word or incomplete bitstream\n"); + } else { + dev_err(&mgr->dev, "Timeout after config data transfer\n"); + } + return -ETIMEDOUT; }