From patchwork Mon Jun 19 15:53:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13284753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B5992EB64D9 for ; Mon, 19 Jun 2023 15:54:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=nn7jzvjZXgSNHMP1VOAw1kMWhqQCYnx5uSa/pv5CNg0=; b=VESxsQqpKiW/Xm o6ah4nqIXi2CqoQXmmGmTReoAgDTdUEKKgZAMGab94oKCzaz2IBtdfAAbQhdZu12sv2MZIvjl/xZn EKeAktDWNIpQcraTmWy/CMFC8xc7VC2X+XPGvCqkGu00AgjjJD/R98aPDiR8m0RQSKJz6WU4Poc0y ASkUkwowHHeb1f7ehAJTD5MaLoQY95a1CIGn5Jfs+NzXxicwxeHzI06Qer0Usbitl4rtBa/TDnySI lFsJQMFjsSMsU6C2jHEFicSAqvBooJ0+4yd1DOLyfjuNohiE90IlA0BmC9uhCf/hAuuxoSMCQApcD M2kIfp4Hmx2sTVgjQ9jg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBHCn-008qoK-24; Mon, 19 Jun 2023 15:54:13 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qBHCZ-008qk5-0B for linux-arm-kernel@lists.infradead.org; Mon, 19 Jun 2023 15:54:01 +0000 X-GND-Sasl: miquel.raynal@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687190035; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PhIQmvwCqc8f2ldfvdDwrf5zFPY90uFTbI6lO/wBafo=; b=ZXzrLBsgbSEa2r0CaAMT7Tkop+dVa6ENEoT112qvP15DZzXWqfx08nu9gIxTrjKVJcGlQy Xn/ATd8crYS0Jm2GobR+8EFj2W03ObKiLCcbI4Q92hNGINiNSeKXZmJ4UMj9Lv0JbpHPFm 02q9DHk86SKMg+0SYQ4Q1rw1O2nj1FQklaTWkoYdth+mqgZK/e7O3yPU9hakNGHmFS/AwF vRWe6BkgqqR0m03DwqRaD+h5iFF3rbu6n9VnWVMbA2KgzNs/jlB4mrfH1YTvZhaoVlz7YX treaYYh//jQ2MfZjHMPXqRUadUz5ITezyZZ/OnCjswhJAgTmyQUrXLR9Cc+g7g== X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 1ED2F1BF206; Mon, 19 Jun 2023 15:53:54 +0000 (UTC) From: Miquel Raynal To: Mark Brown , Subject: [PATCH v2 1/3] spi: Create a helper to derive adaptive timeouts Date: Mon, 19 Jun 2023 17:53:47 +0200 Message-Id: <20230619155349.3118420-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230619155349.3118420-1-miquel.raynal@bootlin.com> References: <20230619155349.3118420-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230619_085359_351619_CA29CC17 X-CRM114-Status: GOOD ( 12.83 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Samuel Holland , Chen-Yu Tsai , Jernej Skrabec , Tudor Ambarus , Thomas Petazzoni , Miquel Raynal , linux-sunxi@lists.linux.dev, Claudiu Beznea , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Big transfers might take a bit of time, too constraining timeouts might lead to false positives. In order to simplify the drivers work and with the goal of factorizing code in mind, let's add a helper that can be used by any spi controller driver to derive a relevant per-transfer timeout value. The logic is simple: we know how much time it would take to transfer a byte, we can easily derive the total theoretical amount of time involved for each transfer. We multiply it by two to have a bit of margin and enforce a minimum of 500ms. Suggested-by: Mark Brown Signed-off-by: Miquel Raynal --- include/linux/spi/spi.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index fbf8c0d95968..4d6636c50465 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1186,6 +1186,23 @@ static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw) return false; } +/** + * spi_controller_xfer_timeout - Compute a suitable timeout value + * @ctlr: SPI device + * @xfer: Transfer descriptor + * + * Compute a relevant timeout value for the given transfer. We derive the time + * that it would take on a single data line and take twice this amount of time + * with a minimum of 500ms to avoid false positives on loaded systems. + * + * Returns: Transfer timeout value in milliseconds. + */ +static inline unsigned int spi_controller_xfer_timeout(struct spi_controller *ctlr, + struct spi_transfer *xfer) +{ + return max(xfer->len * 8 * 2 / (xfer->speed_hz / 1000), 500U); +} + /*---------------------------------------------------------------------------*/ /* SPI transfer replacement methods which make use of spi_res */ From patchwork Mon Jun 19 15:53:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13284754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9A87EEB64D9 for ; Mon, 19 Jun 2023 15:54:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=dc6/g2cb8NMOTKpbDW4D/7YfLPRvg20OX6NFnSsSbBE=; b=RH+WEwN7snvXmW 2iHpVKWo9qHZPb6MSTfMTQAxv1fmaP7uay8GQxtxxxXUn00/pxGWWgCjTR+CGcY9X8br8nJjrIMNn rx1b3I81AXIc+MsCL5/gIw/RBsMJyzDZ3ODMlo9Wj+VLYztCgTToA151wlRwEF8Tv4cnTTufX9qRA 89dTn2DXv/TIXfm60VJRvred+4u5EuFh1Ry9hWO9ER7vfxy0GDed6t5fE91aUNlbHifxCFOXbdHS3 zME1SmF4lg89gQ4sMnMo9+SfwJdJsXMlc2+W4JeyXVgQJDWp/a674hGDtC0esuv/shUi2/S4BTlSY Ht+Czi+RnJHK7gYdmBmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBHCo-008qog-0G; Mon, 19 Jun 2023 15:54:14 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qBHCZ-008qkb-0B for linux-arm-kernel@lists.infradead.org; Mon, 19 Jun 2023 15:54:01 +0000 X-GND-Sasl: miquel.raynal@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687190036; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RVl7mcQ2hRFnAGAiMjDiHg2vEcGhnErk/G4vbtij5nQ=; b=N/oKqopIgRPFhHRhcoBJVpXbyRInOqOPNYpdFtIt7iiIu7FsfgS6nrJslb5ep21xvzxikp QRjeYieP5o1uuHdfbflDHwPDQZ/HB7FiFqJdgBkTKKbwDLVC/DV16h1WXdaOj9Ds5SqntA OSW0l9A7GW4PlT2WvBpHNuFTL8W86gbwuwZGINrGJYbVfiBFbJDkqQg+NbKU0u/tPptpPT PfMlDupDsXVRmodLobC5m9JUngqhi8KOAycA04P/5vqbGygVpP5NrC1o7fIQRB2TiDhcEM emiH9h0JWRcrRMCS9T4j0HWDvlKPFojnAibVCGHYV5CNxzjr9Me+ozd1XHWH5w== X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 3EC2A1BF203; Mon, 19 Jun 2023 15:53:55 +0000 (UTC) From: Miquel Raynal To: Mark Brown , Subject: [PATCH v2 2/3] spi: atmel: Prevent false timeouts on long transfers Date: Mon, 19 Jun 2023 17:53:48 +0200 Message-Id: <20230619155349.3118420-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230619155349.3118420-1-miquel.raynal@bootlin.com> References: <20230619155349.3118420-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230619_085359_359104_F9CB2310 X-CRM114-Status: GOOD ( 14.34 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Samuel Holland , Chen-Yu Tsai , Jernej Skrabec , Tudor Ambarus , Thomas Petazzoni , Miquel Raynal , linux-sunxi@lists.linux.dev, Claudiu Beznea , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A slow SPI bus clocks at ~20MHz, which means it would transfer about 2500 bytes per second with a single data line. Big transfers, like when dealing with flashes can easily reach a few MiB. The current DMA timeout is set to 1 second, which means any working transfer of about 4MiB will always be cancelled. With the above derivations, on a slow bus, we can assume every byte will take at most 0.4ms. Said otherwise, we could add 4ms to the 1-second timeout delay every 10kiB. On a 4MiB transfer, it would bring the timeout delay up to 2.6s which still seems rather acceptable for a timeout. The consequence of this is that long transfers might be allowed, which hence requires the need to interrupt the transfer if wanted by the user. We can hence switch to the _interruptible variant of wait_for_completion. This leads to a little bit more handling to also handle the interrupted case but looks really acceptable overall. While at it, we drop the useless, noisy and redundant WARN_ON() call. Signed-off-by: Miquel Raynal --- drivers/spi/spi-atmel.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index c4f22d50dba5..d1743817a5da 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -233,7 +233,8 @@ */ #define DMA_MIN_BYTES 16 -#define SPI_DMA_TIMEOUT (msecs_to_jiffies(1000)) +#define SPI_DMA_MIN_TIMEOUT (msecs_to_jiffies(1000)) +#define SPI_DMA_TIMEOUT_PER_10K (msecs_to_jiffies(4)) #define AUTOSUSPEND_TIMEOUT 2000 @@ -1279,7 +1280,8 @@ static int atmel_spi_one_transfer(struct spi_master *master, struct atmel_spi_device *asd; int timeout; int ret; - unsigned long dma_timeout; + unsigned int dma_timeout; + long ret_timeout; as = spi_master_get_devdata(master); @@ -1333,11 +1335,13 @@ static int atmel_spi_one_transfer(struct spi_master *master, atmel_spi_unlock(as); } - dma_timeout = wait_for_completion_timeout(&as->xfer_completion, - SPI_DMA_TIMEOUT); - if (WARN_ON(dma_timeout == 0)) { - dev_err(&spi->dev, "spi transfer timeout\n"); - as->done_status = -EIO; + dma_timeout = msecs_to_jiffies(spi_controller_xfer_timeout(master, xfer)); + ret_timeout = wait_for_completion_interruptible_timeout(&as->xfer_completion, + dma_timeout); + if (ret_timeout <= 0) { + dev_err(&spi->dev, "spi transfer %s\n", + !ret_timeout ? "timeout" : "canceled"); + as->done_status = ret_timeout < 0 ? ret_timeout : -EIO; } if (as->done_status) From patchwork Mon Jun 19 15:53:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 13284752 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BA4C5EB64DC for ; Mon, 19 Jun 2023 15:54:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; 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=/74K7yVuzimdp+xQXpPLw1HU74UtfYVNY8F2vYUSJiA=; b=PrLcpgZ0/EogB7 LBYZFt3LuzdfHOPC+ghWeSveu7fNDAlaqffoKm2y0GDtAULL9hrn6E4RIgD1loJZrNDvzhVQU+GXm yF6E8UvLz+n55RyTap/N+LdIjbznIpeCwS6zWKChtGEoXpFlgQuqM+EpyhfwMGOIXW+9R+3AZsYkL HCTLiS6HbnkB2Npk8qMu3yIZ1wkIWQ9hJnr7iFOhoFgzOzsItUX0/HD9mLzxmFksU7jsIyT+qggzT SXJYQAXcoGxy6wu5Ygif/wpGy4fpOkF2NYx9ClQ3VLE4/VFNKis8edZq3lgHQZKFSmyQhG8LxQb98 xO1DEnyVT8koKsvE59rA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qBHCb-008qmB-2T; Mon, 19 Jun 2023 15:54:01 +0000 Received: from relay8-d.mail.gandi.net ([217.70.183.201]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qBHCZ-008qkh-0B for linux-arm-kernel@lists.infradead.org; Mon, 19 Jun 2023 15:54:00 +0000 X-GND-Sasl: miquel.raynal@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1687190037; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uIrH6l6h4FVOlNSp29zZGkHu1wVR3pubO6q4OyhE0xo=; b=WwruJTFPXXkT5hNeyj+ooIdhFe+Y3hhZ3Of48GDqkjJ2yK8h0yAAp55/pZJLQ2LZ+1AeED noqMYJEJ5W6eqWn35JuM/CFzlecNsAZm50Q7bBEEzVWsZKHCNz9K7JCtkzlT2TS0JkbtaR HXit51l66818IrnRrsF2NTYhMTBoiChg8KU5A7JxG4lccoyceZRQ06xVSiqTP2z0Wnu5MQ BNec9ai84G+gbV3JvlXjR7BMSp/UurwzAs/E4z+loYbUBXMRReM1+Gb9eft3EbCTwfOWlu sH+ayULL9CgawEzXrPElEO+UPe41Wl7NkSt2We278liiZvYBYCSXncZ5ImVy8g== X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com X-GND-Sasl: miquel.raynal@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id 4B1CC1BF20E; Mon, 19 Jun 2023 15:53:56 +0000 (UTC) From: Miquel Raynal To: Mark Brown , Subject: [PATCH v2 3/3] spi: sun6i: Use the new helper to derive the xfer timeout value Date: Mon, 19 Jun 2023 17:53:49 +0200 Message-Id: <20230619155349.3118420-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230619155349.3118420-1-miquel.raynal@bootlin.com> References: <20230619155349.3118420-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230619_085359_224356_FDF6F184 X-CRM114-Status: GOOD ( 12.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Samuel Holland , Chen-Yu Tsai , Jernej Skrabec , Tudor Ambarus , Thomas Petazzoni , Miquel Raynal , linux-sunxi@lists.linux.dev, Claudiu Beznea , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A helper was recently added to the core to factorize common code between drivers, like the amount of time a driver should wait for a transfer to happen. It is of course possible to use a default value (like eg. 1s) but it is way stronger to adapt this amount of time to the transfer. Indeed, long transfers (eg. 4MiB) on a slow single-spi bus might take more than the usual second of timeout and prevent lengthy transfers. The core helper was heavily inspired by the logic applied in this driver, the only difference being the minimum amount of time which was enlarged from 0.1s to 0.5s. Use this helper instead of open-coding it. Signed-off-by: Miquel Raynal Acked-by: Jernej Skrabec --- drivers/spi/spi-sun6i.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c index 23ad052528db..180094dfae19 100644 --- a/drivers/spi/spi-sun6i.c +++ b/drivers/spi/spi-sun6i.c @@ -422,7 +422,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH); - tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U); + tx_time = spi_controller_xfer_timeout(master, tfr); start = jiffies; timeout = wait_for_completion_timeout(&sspi->done, msecs_to_jiffies(tx_time));