Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1677991pxj; Wed, 19 May 2021 11:15:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1REoJ2fdMYqDTcpXk5+asQvLW1i2xmfwkfXl76yWC3qIVJPnjlnZMCtaA5wr3kudatme8 X-Received: by 2002:a05:6e02:1b07:: with SMTP id i7mr296463ilv.121.1621448124909; Wed, 19 May 2021 11:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621448124; cv=none; d=google.com; s=arc-20160816; b=J04EGoH16vJpvZJjuEU3I0folO4yY9AEAh/QN3BDHMV8B0cMWizx8cmD685m8JnBqm jErg2TR3X38hynMICybhN7qzuV+l9O/zC9voAfNacrw7j5riNM9P8zTRPuwozoV8N4OY /wkJ7ilO7z3ndeEyNbEoHkEMTj1Y8oNZZYYx5TDoPL1HXEttw2wBnh7jHWz0Ol+F5uKs VwGhdLPEFF9esNyK6+8QIoKifYITSz88wFcLluZqs1f8ZnZoTwT8Bo1SsCtJ4K5FkTvI GiGql5nh7rhJeumqy+qzXHAUKTop7TYbqxI4oySI0mhzPRJHt7X9QuesEeQ8cf+l0zO5 CNuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=SMXfLYG6Qf4hKKnI/SEzkpcqiaGM7M+QTnwnG9aje1s=; b=IH0dacE3KJaxkPhMfxRAkIoF7qc5NZtkC3CghaHWqFpR8J635jzlLrBxijftJknuFE 55+zy5An9UIzwx6sYrQB1MdwdPgeLZ3bXeyfoOr9S1kmpc6znNydZIZh8ZfM2iecvJ+i uFngYp5cOs0qAE6+EhWdL7N53VQQzWaZ/77ruoY70CFVyEHwKmr6JE40GInzJFlqvjnJ vk9M2Jk17gTRtRgkfZj2CbZ8BFDeGXh2a4PgFdicZ/s2RRSLdL2fLo3V/Jt3JFOYjmVH vfLvzBwPXdZF6MVA1e8HLRYC+b9/JO2p986A2ec4DVISJ+J/WrLq4q3tH9ARZ/lZf28X 3bLw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 23si24778317iof.89.2021.05.19.11.15.12; Wed, 19 May 2021 11:15:24 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349940AbhEROUs (ORCPT + 99 others); Tue, 18 May 2021 10:20:48 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:40890 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243610AbhEROUp (ORCPT ); Tue, 18 May 2021 10:20:45 -0400 Received: from localhost (unknown [IPv6:2a01:e0a:2c:6930:5cf4:84a1:2763:fe0d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: bbrezillon) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id 57F1B1F42B04; Tue, 18 May 2021 15:19:26 +0100 (BST) Date: Tue, 18 May 2021 16:19:23 +0200 From: Boris Brezillon To: Cc: Mark Brown , Miquel Raynal , Vignesh Raghavendra , , Alexandre Torgue , , , , , Subject: Re: [PATCH v4 2/3] mtd: spinand: use the spi-mem poll status APIs Message-ID: <20210518161923.3bf75a25@collabora.com> In-Reply-To: <20210518134332.17826-3-patrice.chotard@foss.st.com> References: <20210518134332.17826-1-patrice.chotard@foss.st.com> <20210518134332.17826-3-patrice.chotard@foss.st.com> Organization: Collabora X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 May 2021 15:43:31 +0200 wrote: > From: Patrice Chotard > > Make use of spi-mem poll status APIs to let advanced controllers > optimize wait operations. > This should also fix the high CPU usage for system that don't have > a dedicated STATUS poll block logic. > > Signed-off-by: Patrice Chotard > Signed-off-by: Christophe Kerello Reviewed-by: Boris Brezillon > --- > Changes in v4: > - Update commit message. > - Add comment which explains how delays has been calculated. > - Rename SPINAND_STATUS_TIMEOUT_MS to SPINAND_WAITRDY_TIMEOUT_MS. > > Changes in v3: > - Add initial_delay_us and polling_delay_us parameters to spinand_wait() > - Add SPINAND_READ/WRITE/ERASE/RESET_INITIAL_DELAY_US and > SPINAND_READ/WRITE/ERASE/RESET_POLL_DELAY_US defines. > > Changes in v2: > - non-offload case is now managed by spi_mem_poll_status() > > drivers/mtd/nand/spi/core.c | 45 ++++++++++++++++++++++++++----------- > include/linux/mtd/spinand.h | 22 ++++++++++++++++++ > 2 files changed, 54 insertions(+), 13 deletions(-) > > diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c > index 17f63f95f4a2..3131fae0c715 100644 > --- a/drivers/mtd/nand/spi/core.c > +++ b/drivers/mtd/nand/spi/core.c > @@ -473,20 +473,26 @@ static int spinand_erase_op(struct spinand_device *spinand, > return spi_mem_exec_op(spinand->spimem, &op); > } > > -static int spinand_wait(struct spinand_device *spinand, u8 *s) > +static int spinand_wait(struct spinand_device *spinand, > + unsigned long initial_delay_us, > + unsigned long poll_delay_us, > + u8 *s) > { > - unsigned long timeo = jiffies + msecs_to_jiffies(400); > + struct spi_mem_op op = SPINAND_GET_FEATURE_OP(REG_STATUS, > + spinand->scratchbuf); > u8 status; > int ret; > > - do { > - ret = spinand_read_status(spinand, &status); > - if (ret) > - return ret; > + ret = spi_mem_poll_status(spinand->spimem, &op, STATUS_BUSY, 0, > + initial_delay_us, > + poll_delay_us, > + SPINAND_WAITRDY_TIMEOUT_MS); > + if (ret) > + return ret; > > - if (!(status & STATUS_BUSY)) > - goto out; > - } while (time_before(jiffies, timeo)); > + status = *spinand->scratchbuf; > + if (!(status & STATUS_BUSY)) > + goto out; > > /* > * Extra read, just in case the STATUS_READY bit has changed > @@ -526,7 +532,10 @@ static int spinand_reset_op(struct spinand_device *spinand) > if (ret) > return ret; > > - return spinand_wait(spinand, NULL); > + return spinand_wait(spinand, > + SPINAND_RESET_INITIAL_DELAY_US, > + SPINAND_RESET_POLL_DELAY_US, > + NULL); > } > > static int spinand_lock_block(struct spinand_device *spinand, u8 lock) > @@ -549,7 +558,10 @@ static int spinand_read_page(struct spinand_device *spinand, > if (ret) > return ret; > > - ret = spinand_wait(spinand, &status); > + ret = spinand_wait(spinand, > + SPINAND_READ_INITIAL_DELAY_US, > + SPINAND_READ_POLL_DELAY_US, > + &status); > if (ret < 0) > return ret; > > @@ -585,7 +597,10 @@ static int spinand_write_page(struct spinand_device *spinand, > if (ret) > return ret; > > - ret = spinand_wait(spinand, &status); > + ret = spinand_wait(spinand, > + SPINAND_WRITE_INITIAL_DELAY_US, > + SPINAND_WRITE_POLL_DELAY_US, > + &status); > if (!ret && (status & STATUS_PROG_FAILED)) > return -EIO; > > @@ -768,7 +783,11 @@ static int spinand_erase(struct nand_device *nand, const struct nand_pos *pos) > if (ret) > return ret; > > - ret = spinand_wait(spinand, &status); > + ret = spinand_wait(spinand, > + SPINAND_ERASE_INITIAL_DELAY_US, > + SPINAND_ERASE_POLL_DELAY_US, > + &status); > + > if (!ret && (status & STATUS_ERASE_FAILED)) > ret = -EIO; > > diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h > index 6bb92f26833e..6988956b8492 100644 > --- a/include/linux/mtd/spinand.h > +++ b/include/linux/mtd/spinand.h > @@ -170,6 +170,28 @@ struct spinand_op; > struct spinand_device; > > #define SPINAND_MAX_ID_LEN 4 > +/* > + * For erase, write and read operation, we got the following timings : > + * tBERS (erase) 1ms to 4ms > + * tPROG 300us to 400us > + * tREAD 25us to 100us > + * In order to minimize latency, the min value is divided by 4 for the > + * initial delay, and dividing by 20 for the poll delay. > + * For reset, 5us/10us/500us if the device is respectively > + * reading/programming/erasing when the RESET occurs. Since we always > + * issue a RESET when the device is IDLE, 5us is selected for both initial > + * and poll delay. > + */ > +#define SPINAND_READ_INITIAL_DELAY_US 6 > +#define SPINAND_READ_POLL_DELAY_US 5 > +#define SPINAND_RESET_INITIAL_DELAY_US 5 > +#define SPINAND_RESET_POLL_DELAY_US 5 > +#define SPINAND_WRITE_INITIAL_DELAY_US 75 > +#define SPINAND_WRITE_POLL_DELAY_US 15 > +#define SPINAND_ERASE_INITIAL_DELAY_US 250 > +#define SPINAND_ERASE_POLL_DELAY_US 50 > + > +#define SPINAND_WAITRDY_TIMEOUT_MS 400 > > /** > * struct spinand_id - SPI NAND id structure