From patchwork Fri Aug 28 19:58:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11743693 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 BD65C13B1 for ; Fri, 28 Aug 2020 19:59:55 +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 9744320825 for ; Fri, 28 Aug 2020 19:59:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="1GdJz7S1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9744320825 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=3mxbihXnsM/SuKJZTWVVtVKeG4OTZMjwp2RjE+nFeQ8=; b=1GdJz7S1TtKd/83jpkjipPIp1Z sQuwMMgLQy8sw3TumejztoCZtemWpT2NHUnJhncB990QdJ0JzcZGT9EnrCSgysygsO7GManfT1Rh9 IQb+AbmVia21YMKhCLw0glObVhGr0gF/qVEovLXJPmy2bz1v68gwCLbCkNdDdrx6BUjBn9lDG+YWs 6PTwsfn5TxxaGvXogM6lGi7OCMpOG2Kdp+sVbYwSLrleNmlYnl6CvgPv4u0vduvWZk6Fx9cEF7Tla lIGmpt0CGJCfoYnG6FBH3LKhvFj2J8SrzdCAO+edcSsESlOBESM45w71tDKYD5T22E3BfCmhQnEhF R6orMlTQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBkWG-00037O-JD; Fri, 28 Aug 2020 19:58:40 +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 1kBkW2-00033N-66 for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 19:58:28 +0000 Received: from [78.134.86.56] (port=54992 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kBkVv-0008I1-Ur; Fri, 28 Aug 2020 21:58:20 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v3 1/5] fpga manager: xilinx-spi: remove stray comment Date: Fri, 28 Aug 2020 21:58:04 +0200 Message-Id: <20200828195808.27975-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-20200828_155826_459967_4061D50D X-CRM114-Status: UNSURE ( 7.38 ) 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") Signed-off-by: Luca Ceresoli --- 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 Fri Aug 28 19:58:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11743681 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 370E11752 for ; Fri, 28 Aug 2020 19:58:48 +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 12347208A9 for ; Fri, 28 Aug 2020 19:58:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Cv+7MTdM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 12347208A9 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=OrKcthOLUB4e76X+KPgawcFaSk+hPph8tS5Tvlw1d/0=; b=Cv+7MTdMwzu9NIrDwOws2uIdZ Mo9US8IZky4eJkL7UikmSSUcBIjtQ//lsFLkYHAJEUHgxq3nNUM2a5tSt7iphQn0J0rn9uX24l3GU fL3zfA5U45URb82kxCl/4EHFwYZMp+GcclCkpDfWvA4VyaQh8Llw7wnjoB2Svk/iSLbw7jNq30Exs n19aqpfEeGbVUM3KolIKBIyolgoC7zWyZPANC9eq8SsBaKRjn0ldDJP4huHvOyp/pBc5hGXyBj326 SNuW0MP5dc2j3v0bX1AW3DIE5cpQk/wxKpni7Z4QTxDCKpexaewu44sB4tgyGB1zAAbVI8RO4W0oy 4Az7z7ooQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBkWD-00036w-Rg; Fri, 28 Aug 2020 19:58:37 +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 1kBkW2-00033M-5Z for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 19:58:28 +0000 Received: from [78.134.86.56] (port=54992 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kBkVw-0008I1-8V; Fri, 28 Aug 2020 21:58:20 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v3 2/5] fpga manager: xilinx-spi: remove final dot from dev_err() strings Date: Fri, 28 Aug 2020 21:58:05 +0200 Message-Id: <20200828195808.27975-2-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200828195808.27975-1-luca@lucaceresoli.net> References: <20200828195808.27975-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-20200828_155826_490941_41440B90 X-CRM114-Status: UNSURE ( 9.32 ) 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. Signed-off-by: Luca Ceresoli --- 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 Fri Aug 28 19:58:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11743683 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 E8690913 for ; Fri, 28 Aug 2020 19:58:52 +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 C27EB20E65 for ; Fri, 28 Aug 2020 19:58:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="nX22hssM" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C27EB20E65 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=cxTSL9Uq9xqbkQRNBLYyapA34iszLx4BY5ozAEMd2Qk=; b=nX22hssM9a5dil/KX8lxsL+Xw 2kifzl9gOiRijMGmBC9D9U8wfRoP1KoevRaMoPdXlgTW7dkZczprzjPAVJSIHoWXSrkodDIKmimdb aKOLA/JSWvv+5fblkuH7V8S5LD9QObktyvxsdacFJT7PnJV9s9sHd10eK61ccHmSriuy84OXTOO6f ojAKZI4zESpeGyEi/zhovq+UmfDcqisGBh4PJupIS+BLDq4RFtr0+8pLFLmQIOQYV/0N9UL2EBLTo EWonJraS5lwu6f+kNnlFzByotvV+nLAK55n6DIXHWZ6SufAftx5XCQoVtADaQmpHIf8aQXtYVC5f7 03NmM+ReA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBkWI-00037r-9R; Fri, 28 Aug 2020 19:58:42 +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 1kBkW2-00033P-6e for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 19:58:28 +0000 Received: from [78.134.86.56] (port=54992 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kBkVw-0008I1-I6; Fri, 28 Aug 2020 21:58:20 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v3 3/5] fpga manager: xilinx-spi: fix write_complete timeout handling Date: Fri, 28 Aug 2020 21:58:06 +0200 Message-Id: <20200828195808.27975-3-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200828195808.27975-1-luca@lucaceresoli.net> References: <20200828195808.27975-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-20200828_155826_519992_59D1BECC X-CRM114-Status: GOOD ( 15.23 ) 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 Signed-off-by: Luca Ceresoli --- 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..a7b919eb0b2a 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; + 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 Fri Aug 28 19:58:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11743695 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 CDC51913 for ; Fri, 28 Aug 2020 19:59:55 +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 A7FC2208A9 for ; Fri, 28 Aug 2020 19:59:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZZ4zOzu1" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7FC2208A9 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=sq1o2rFDJs3ELD0EaHq3gKUxurdB1r8oK8GPbFuicwE=; b=ZZ4zOzu1CQcPCQe2aAA7GVydi fdHQGlmzZc2rOQNLVmR1nseuKTnyk5C0w2eOGDFRAoy+zDdNedQPy0Yc+foVvaZ6i78WgZmcxoDCS dO6+hNe6Kek6wStdAJQhsrW3k6jZbTZe1Ke3NDv9tPKCDAo3WVi//VmbOnv3zNFvIAvLlcKy205BP USM2pG1jXNZ6HkER+oMQheRF6G7iYubgAcO8XudlaY/gLxHBdfi0N3Tj+eWJyrJDyhETqQabPMimq LkELQ+/3Z9OY9maZg6R4eHDgNdVL6zBF9zvkhSeYLpt3L5yUtT247ZKXY5poguGRpksBB+QjUGJpO gIMZvySNw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBkW6-00035O-ML; Fri, 28 Aug 2020 19:58:30 +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 1kBkW2-00033O-4V for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 19:58:27 +0000 Received: from [78.134.86.56] (port=54992 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kBkVw-0008I1-Qo; Fri, 28 Aug 2020 21:58:20 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v3 4/5] fpga manager: xilinx-spi: add error checking after gpiod_get_value() Date: Fri, 28 Aug 2020 21:58:07 +0200 Message-Id: <20200828195808.27975-4-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200828195808.27975-1-luca@lucaceresoli.net> References: <20200828195808.27975-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-20200828_155826_297652_9DDCD660 X-CRM114-Status: GOOD ( 13.37 ) 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 Signed-off-by: Luca Ceresoli Reported-by: kernel test robot --- 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 a7b919eb0b2a..9488c8fbaefd 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 Fri Aug 28 19:58:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luca Ceresoli X-Patchwork-Id: 11743679 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 247F91575 for ; Fri, 28 Aug 2020 19:58:48 +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 F02D520897 for ; Fri, 28 Aug 2020 19:58:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="H/B4CjQL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F02D520897 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=A05EtBbwe4xd3oiew2NFQlQY0wDje/RmCnYgWoZprgw=; b=H/B4CjQL903FSikDgIPS5rAQW jBC7xeqITE0MKh75VxRZyNt7+pjuJNTgfLCZftX4cVbgU32zIS1t7xJ/qO4UyTVOebpkNNwKorsCg IoTnHnAiCKz8lHPHN3290daKrCb37hdu2YBlxsMZK2HRK5wdNwd6BzB5OPtc6nS1BYNiBBr2OALlx LoCxJxN+VZHVCa3TkZiGCs4RWCdz8SOW307wsWxa/ItF4YqTi+3H1DyXd39KJuA+OIqKq4dEREg9M lxdO0enyDLq1oU2igmClaNzCrAjebZfBamDKTW+E1aUQxv+1WRjaWV+DuEFMk2LWn6nxx0e9REuv6 i6LsTxSiQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBkW5-00035B-5j; Fri, 28 Aug 2020 19:58:29 +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 1kBkW2-00033L-52 for linux-arm-kernel@lists.infradead.org; Fri, 28 Aug 2020 19:58:27 +0000 Received: from [78.134.86.56] (port=54992 helo=melee.dev.aim) by hostingweb31.netsons.net with esmtpa (Exim 4.93) (envelope-from ) id 1kBkVx-0008I1-2h; Fri, 28 Aug 2020 21:58:21 +0200 From: Luca Ceresoli To: linux-fpga@vger.kernel.org Subject: [PATCH v3 5/5] fpga manager: xilinx-spi: provide better diagnostics on programming failure Date: Fri, 28 Aug 2020 21:58:08 +0200 Message-Id: <20200828195808.27975-5-luca@lucaceresoli.net> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200828195808.27975-1-luca@lucaceresoli.net> References: <20200828195808.27975-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-20200828_155826_382116_A95AD636 X-CRM114-Status: GOOD ( 10.61 ) 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. Signed-off-by: Luca Ceresoli 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 9488c8fbaefd..c2e0a42cd4f2 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; }