Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp409168ybm; Fri, 29 May 2020 03:16:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx+b0weYFzEjr3chIxiHAIqjPAUDJ7MLgOcZop4Zorv63xKjKWtxw1So9rj2qa6UWtf3Cls X-Received: by 2002:a05:6402:642:: with SMTP id u2mr7102296edx.59.1590747377246; Fri, 29 May 2020 03:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590747377; cv=none; d=google.com; s=arc-20160816; b=E7yxzm8vkPlGS/5APXoi/iinaIeabbVfaIp6x5Xvib0xlv+w11osP78Wmp2b8Rb4S4 yGfcoYhARCPTih3bYNEw9Y8+OtRKgKEdksqUNC5k2aiaVCtWyfsYGHKB5Zgfy5XjH8El KV3ZABEL15vJRHIxW3HlaTvI4UPt4kFCTaXFe8JzEVJb8eaZ3NS5BILDH9QB6GZQNtff 5TfKzVaQ9UULbXKNs7J3u8ewRqLn3lCNIO696BxjupAoGpSD9fC5sV75VYfbZgRW1hed nowNcgCDxKOZmsqsA72abh19IPi1cOh1gp8s2a+Rjk5gB4Rx2xPPlqkAfW2+oWnzV9hf rZTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=RPaadCEZp3PupOPILsIQJZuaEJyZ6n7rig/IMKX1h2w=; b=Bs1n+pqxUbRFF0oHcVxClhLYvl6PH/DgA/PNNFPgr3++9tgJltSlUfWpy4kn/ORpMv Hwb5npsvPwUXGYCKl3QTuYyU3zT4/VopLI18Rb8bGGZ13PgfwGLT9Bzr+033nx6UNFle hgyPJRPDxheGkI8eZyvSI5Tki1hxOul7VE2dxP5+Q+oKt6KPsIQUqcabP6u4XgAGswXI Q+0jtDTbktxIaQl0MA4wnV8BIgRDBDOfp21IUq9ziBBp0CSm4raaRv1vNlRpMZm5Auhj 643Ftzgv1y71ErHvILeTNtQ5p9Z8RE98EebYv+h7Y7AwSylUT9mT4HJAde2YC3oNh3ir zmzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t15si5178319edw.497.2020.05.29.03.15.54; Fri, 29 May 2020 03:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726816AbgE2KNg (ORCPT + 99 others); Fri, 29 May 2020 06:13:36 -0400 Received: from mail.baikalelectronics.com ([87.245.175.226]:47046 "EHLO mail.baikalelectronics.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725790AbgE2KNe (ORCPT ); Fri, 29 May 2020 06:13:34 -0400 Received: from localhost (unknown [127.0.0.1]) by mail.baikalelectronics.ru (Postfix) with ESMTP id B76A780307C7; Fri, 29 May 2020 10:13:30 +0000 (UTC) X-Virus-Scanned: amavisd-new at baikalelectronics.ru Received: from mail.baikalelectronics.ru ([127.0.0.1]) by localhost (mail.baikalelectronics.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id c3ZiIxZjxY7z; Fri, 29 May 2020 13:13:30 +0300 (MSK) Date: Fri, 29 May 2020 13:13:28 +0300 From: Serge Semin To: Andy Shevchenko CC: Serge Semin , Mark Brown , Grant Likely , Linus Walleij , Feng Tang , Alan Cox , Vinod Koul , Georgy Vlasov , Ramil Zaripov , Alexey Malahov , Thomas Bogendoerfer , Arnd Bergmann , Rob Herring , , , , Subject: Re: [PATCH v5 05/16] spi: dw: Add SPI Rx-done wait method to DMA-based transfer Message-ID: <20200529101328.bfoyyvmwm5gfflxv@mobilestation> References: <20200529035915.20790-1-Sergey.Semin@baikalelectronics.ru> <20200529035915.20790-6-Sergey.Semin@baikalelectronics.ru> <20200529094648.GY1634618@smile.fi.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20200529094648.GY1634618@smile.fi.intel.com> X-ClientProxiedBy: MAIL.baikal.int (192.168.51.25) To mail (192.168.51.25) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 29, 2020 at 12:46:48PM +0300, Andy Shevchenko wrote: > On Fri, May 29, 2020 at 06:59:03AM +0300, Serge Semin wrote: > > Having any data left in the Rx FIFO after the DMA engine claimed it has > > finished all DMA transactions is an abnormal situation, since the DW SPI > > controller driver expects to have all the data being fetched and placed > > into the SPI Rx buffer at that moment. In case if this has happened we > > assume that DMA engine still may be doing the data fetching, thus we give > > it sometime to finish. If after a short period of time the data is still > > left in the Rx FIFO, the driver will give up waiting and return an error > > indicating that the SPI controller/DMA engine must have hung up or failed > > at some point of doing their duties. > > ... > > > +static int dw_spi_dma_wait_rx_done(struct dw_spi *dws) > > +{ > > + int retry = WAIT_RETRIES; > > + struct spi_delay delay; > > + unsigned long ns, us; > > + u32 nents; > > + > > + /* > > + * It's unlikely that DMA engine is still doing the data fetching, but > > + * if it's let's give it some reasonable time. The timeout calculation > > + * is based on the synchronous APB/SSI reference clock rate, on a > > + * number of data entries left in the Rx FIFO, times a number of clock > > + * periods normally needed for a single APB read/write transaction > > + * without PREADY signal utilized (which is true for the DW APB SSI > > + * controller). > > + */ > > + nents = dw_readl(dws, DW_SPI_RXFLR); > > > + ns = NSEC_PER_SEC / dws->max_freq * 4 * nents; > > I think we may slightly increase precision by writing this like > > ns = 4 * NSEC_PER_SEC / dws->max_freq * nents; Good point. Although both 4 and NSEC_PER_SEC are signed. The later is 1000000000L. Formally speaking on x32 systems (4 * 1000 000 000L) equals to a negative value. Though overflow still won't happen so the result will be correct. Anyway to be on a safe side it would be better to use an explicit unsigned literal: + ns = 4U * NSEC_PER_SEC / dws->max_freq * nents; -Sergey > > > > + if (ns <= NSEC_PER_USEC) { > > + delay.unit = SPI_DELAY_UNIT_NSECS; > > + delay.value = ns; > > + } else { > > + us = DIV_ROUND_UP(ns, NSEC_PER_USEC); > > + delay.unit = SPI_DELAY_UNIT_USECS; > > + delay.value = clamp_val(us, 0, USHRT_MAX); > > + } > > + > > + while (dw_spi_dma_rx_busy(dws) && retry--) > > + spi_delay_exec(&delay, NULL); > > + > > + if (retry < 0) { > > + dev_err(&dws->master->dev, "Rx hanged up\n"); > > + return -EIO; > > + } > > + > > + return 0; > > +} > > -- > With Best Regards, > Andy Shevchenko > >