From patchwork Tue Nov 13 10:22:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lubomir Rintel X-Patchwork-Id: 10680215 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9462913B5 for ; Tue, 13 Nov 2018 10:24:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 815F629C5B for ; Tue, 13 Nov 2018 10:24:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7580F29C6D; Tue, 13 Nov 2018 10:24:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E56C029C5B for ; Tue, 13 Nov 2018 10:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=CUhJgvyaUqEblfhVhPc/IiWLdIsR3qEesgIg3w5YP8g=; b=cyssu+KFozEsed dfDMg5ohh9OKZVXeDmEn1CQVRf6buqpIz+HeAyv9bGD5DDDaMGoHH8qMmPkgZUj9Y45aCL0cwqjDE jlq4EMj2eZAUPWjzeO/NCk9cPuS1uYxMnSx6HGm/KQYLsMijumHr/sYMKpaDDwXvi+oaDuuwoQTwb GJ0Uo/UQHamgmlWdeNMMSt4FSvDjzFx78QtH5wMmtHAxT/IsZry4XSsIqxWpZumMWJ7XDhYOAEGBZ cYvarIHFsf1DRQoGxq/p01yxrXy0y7MdbPuqb/rKg/SDXkSsgHxhqDhcZffs+Unhiu/zB9kcRi/gD 8PzPdUVewoN/sNxCetzg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVrY-0003f7-4E; Tue, 13 Nov 2018 10:24:04 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqn-0002vX-9m for linux-arm-kernel@bombadil.infradead.org; Tue, 13 Nov 2018 10:23:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=jraHQ8BJMlW7ZqvKNK2kXJUV6TICbe7Bt2MI9dpugUs=; b=jDYE0UMiwdCsICftP5eWvfsEtC RC27Kgx58DctXphHi/kwhHm0FUxxkgr03gMm4O8ktAvpYZ+wWkCajjgtBir0mcoYW5/fPm/vT/rLB JMVZhNIvynp+sY9/3Js/FsKu+s3MD8YKVTg/2rHknL9MFf+t9zyLKdnnqDFb4kcqVLu8OdqNtw52p gCj6HsGAcDP2QDzDW3BWxam1DpyCGwZ9aYpYYvordRKmwtPnnAOmXeg72y2S0KWKAyzCNy+wzOkCQ 48fQkdVFh1YGdwZgxCCOGj99Wy5su0hXGcooj3pMLKX4N9wLioegg04xhfG4Gkh4fMbNjYoV6qxn5 1bR0G0rA==; Received: from shell.v3.sk ([90.176.6.54]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gMVqh-00065W-HV for linux-arm-kernel@lists.infradead.org; Tue, 13 Nov 2018 10:23:15 +0000 Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id D0BB9C6B30; Tue, 13 Nov 2018 11:23:01 +0100 (CET) Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id H8x7nBaP2HEV; Tue, 13 Nov 2018 11:22:46 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by zimbra.v3.sk (Postfix) with ESMTP id 159DFC677C; Tue, 13 Nov 2018 11:22:45 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.v3.sk Received: from shell.v3.sk ([127.0.0.1]) by localhost (zimbra.v3.sk [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id V23aKxyqXD7u; Tue, 13 Nov 2018 11:22:41 +0100 (CET) Received: from belphegor.brq.redhat.com (nat-pool-brq-t.redhat.com [213.175.37.10]) by zimbra.v3.sk (Postfix) with ESMTPSA id 28E5BC6B1F; Tue, 13 Nov 2018 11:22:41 +0100 (CET) From: Lubomir Rintel To: Mark Brown , Geert Uytterhoeven Subject: [PATCH v3 2/6] spi: Deal with slaves that return from transfer_one() unfinished Date: Tue, 13 Nov 2018 11:22:24 +0100 Message-Id: <20181113102228.820214-3-lkundrak@v3.sk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181113102228.820214-1-lkundrak@v3.sk> References: <20181113102228.820214-1-lkundrak@v3.sk> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181113_102311_932683_A7A20558 X-CRM114-Status: GOOD ( 15.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Eric Miao , James Cameron , linux-kernel@vger.kernel.org, Haojian Zhuang , linux-spi@vger.kernel.org, Lubomir Rintel , Rob Herring , linux-arm-kernel@lists.infradead.org, Robert Jarzmik , Daniel Mack Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some drivers, such as spi-pxa2xx return from the transfer_one callback immediately, idicating that the transfer will be finished asynchronously. Normally, spi_transfer_one_message() synchronously waits for the transfer to finish with wait_for_completion_timeout(). For slaves, we don't want the transaction to time out as it can complete in a long time in future. Use wait_for_completion_interruptible() instead. Signed-off-by: Lubomir Rintel Acked-by: Pavel Machek Reviewed-by: Geert Uytterhoeven --- Changed since v2: - Corrected the spi_transfer_wait() return value handling to avoid early bail out without the necessary cleanup (thanks Geert Uytterhoeven) drivers/spi/spi.c | 62 +++++++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 6ca59406b0b7..498d3b9bf3ae 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -1037,6 +1037,42 @@ static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg) return __spi_map_msg(ctlr, msg); } +static int spi_transfer_wait(struct spi_controller *ctlr, + struct spi_message *msg, + struct spi_transfer *xfer) +{ + struct spi_statistics *statm = &ctlr->statistics; + struct spi_statistics *stats = &msg->spi->statistics; + unsigned long long ms = 1; + + if (spi_controller_is_slave(ctlr)) { + if (wait_for_completion_interruptible(&ctlr->xfer_completion)) { + dev_dbg(&msg->spi->dev, "SPI transfer interrupted\n"); + return -EINTR; + } + } else { + ms = 8LL * 1000LL * xfer->len; + do_div(ms, xfer->speed_hz); + ms += ms + 200; /* some tolerance */ + + if (ms > UINT_MAX) + ms = UINT_MAX; + + ms = wait_for_completion_timeout(&ctlr->xfer_completion, + msecs_to_jiffies(ms)); + + if (ms == 0) { + SPI_STATISTICS_INCREMENT_FIELD(statm, timedout); + SPI_STATISTICS_INCREMENT_FIELD(stats, timedout); + dev_err(&msg->spi->dev, + "SPI transfer timed out\n"); + return -ETIMEDOUT; + } + } + + return 0; +} + /* * spi_transfer_one_message - Default implementation of transfer_one_message() * @@ -1050,7 +1086,6 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, struct spi_transfer *xfer; bool keep_cs = false; int ret = 0; - unsigned long long ms = 1; struct spi_statistics *statm = &ctlr->statistics; struct spi_statistics *stats = &msg->spi->statistics; @@ -1079,28 +1114,9 @@ static int spi_transfer_one_message(struct spi_controller *ctlr, goto out; } - if (ret > 0) { - ret = 0; - ms = 8LL * 1000LL * xfer->len; - do_div(ms, xfer->speed_hz); - ms += ms + 200; /* some tolerance */ - - if (ms > UINT_MAX) - ms = UINT_MAX; - - ms = wait_for_completion_timeout(&ctlr->xfer_completion, - msecs_to_jiffies(ms)); - } - - if (ms == 0) { - SPI_STATISTICS_INCREMENT_FIELD(statm, - timedout); - SPI_STATISTICS_INCREMENT_FIELD(stats, - timedout); - dev_err(&msg->spi->dev, - "SPI transfer timed out\n"); - msg->status = -ETIMEDOUT; - } + ret = spi_transfer_wait(ctlr, msg, xfer); + if (ret < 0) + msg->status = ret; } else { if (xfer->len) dev_err(&msg->spi->dev,