From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03414C433B4 for ; Tue, 18 May 2021 11:50:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D7493610A2 for ; Tue, 18 May 2021 11:50:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348880AbhERLvr (ORCPT ); Tue, 18 May 2021 07:51:47 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:55148 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S241753AbhERLvp (ORCPT ); Tue, 18 May 2021 07:51:45 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14IBkjQf031794; Tue, 18 May 2021 13:50:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=DdKE7jcPLmE85L7BIvJpkrZObmvEJo2niKAbOooRnxo=; b=r2NGqWkTgccIRkM36eSnUH6IR+Doa3zxzRMFmvDqWXy58W9H3P/Zw24YMwmIfVJeVWrk 7SdCgrOVo/6CJ4evAl4LYpnE9altycG5HgzX70tA+myXpNte9RAkknWsI/uk0EZw8HKa PbmwxbnRzpaBR6jeJC1bIYzLci/TSACl1WI5IlThtlLldNuDX6UdAEvTCHjpUi5fiWzr L18uV/et5cb05wttXHKTRzFIOaXmcFQhHq3YlP7gyQwXlOi/hnF2T6VXz+AEoe/7zWuP TMH79t1gGeIR3fNRcVzd/JJ8qOmZe1L5OXE2/jae2K00wKF4qS1T9mrsi3gZPYrdvC7R kQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 38km7pqc18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 May 2021 13:50:15 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DFF6010002A; Tue, 18 May 2021 13:50:14 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id C8ABD2237A4; Tue, 18 May 2021 13:50:14 +0200 (CEST) Received: from lmecxl0573.lme.st.com (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 May 2021 13:50:13 +0200 Subject: Re: [PATCH v3 2/3] mtd: spinand: use the spi-mem poll status APIs To: Boris Brezillon CC: Mark Brown , Miquel Raynal , Vignesh Raghavendra , , Alexandre Torgue , , , , , References: <20210518093951.23136-1-patrice.chotard@foss.st.com> <20210518093951.23136-3-patrice.chotard@foss.st.com> <20210518132850.1558e46b@collabora.com> From: Patrice CHOTARD Message-ID: <84113017-8ba8-4de3-24d8-719c63f458fe@foss.st.com> Date: Tue, 18 May 2021 13:50:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210518132850.1558e46b@collabora.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-18_04:2021-05-18,2021-05-18 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi On 5/18/21 1:28 PM, Boris Brezillon wrote: > On Tue, 18 May 2021 11:39:50 +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 you were reporting for those > that don't have a dedicated STATUS poll block logic, which is great! I will update the commit message by indicating what you mention here. > >> >> Signed-off-by: Patrice Chotard >> Signed-off-by: Christophe Kerello >> --- >> 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 | 11 ++++++++- >> 2 files changed, 42 insertions(+), 14 deletions(-) >> >> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c >> index 17f63f95f4a2..ef2a692ab5b6 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_STATUS_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..180c1fa64e62 100644 >> --- a/include/linux/mtd/spinand.h >> +++ b/include/linux/mtd/spinand.h >> @@ -169,7 +169,16 @@ >> struct spinand_op; >> struct spinand_device; >> >> -#define SPINAND_MAX_ID_LEN 4 >> +#define SPINAND_MAX_ID_LEN 4 >> +#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 > > Could you add a comment explaining where those numbers come from? Sure > >> +#define SPINAND_STATUS_TIMEOUT_MS 400 > > I would name that one SPINAND_WAITRDY_TIMEOUT_MS. Ok > >> >> /** >> * struct spinand_id - SPI NAND id structure > Thanks Patrice From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45984C433ED for ; Tue, 18 May 2021 11:52:41 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 C1A3961002 for ; Tue, 18 May 2021 11:52:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C1A3961002 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=foss.st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:CC:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=+5QWmR+syFeGA4CGzT83UvL6X7sxVsZWZlr/0KM0xbU=; b=mOan7x7S0OJH9XREqtpdON+67 5zRgY+u/knLtMxdf7H1a3rnw//SgGKYRnQl+u73A2TyLrXF0WoNclrBFiB+0A6xjT580ByPtm5loa a+z4dgowOdcxUX4Zph1hYWR4bnh0S2dGm31+UjP+zkcIoJK+9dJyottGL+AeGGCavW3sW7Sj5QyTZ uc+J0AtpMLntH8kwimVwZZpE6yygsu33GYZX/FNy6w8yetu1xhtAcz+0fJyhFL/pihPi+1mTvg8AA Wuk5voQgWiVayfhjEmuB4WjYXn+mlnCnULluw4xFYMrlKZkTXJjzVtaBxS5veTl4xWoglCZf4zZfj yWrwePHdQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1liyG0-000ebk-Vm; Tue, 18 May 2021 11:51:29 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liyEz-000duT-7H; Tue, 18 May 2021 11:50:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:CC:To: Subject:Sender:Reply-To:Content-ID:Content-Description; bh=DdKE7jcPLmE85L7BIvJpkrZObmvEJo2niKAbOooRnxo=; b=QFeQG9gadfAJ8Z1tnFVdm0q0e1 aaPwk3pjjEmdEt+zKyG5XAU+8HA1HSDgwZUZu7wN6QwUKOWPgZWoye4S2F74gf21Fc2Or4KctyWHM 8nhuK6j993hdjFZ36WozAsfJvXiU0xLV9g0nADGyRLJ1xdk17RN8H8l+K8SX19Up3ypR5s3IFfEMN Q1jaJ6PDZ9uH0KiAJVbDqlNvKla7KUiqSnh6gqD16w6ULeu625I0j2UcfpeqSmmPfp9u0hi8T9g/8 febJz+x3RQA/rGx4I6ZBGF/4dOaRcKwH6ldT9hF1vlbpcfA4nxd2y1MpafZLVPzfrCGvmSEpwvty6 PWJYbHAA==; Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liyEv-00EcP3-RS; Tue, 18 May 2021 11:50:23 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14IBkjQf031794; Tue, 18 May 2021 13:50:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=DdKE7jcPLmE85L7BIvJpkrZObmvEJo2niKAbOooRnxo=; b=r2NGqWkTgccIRkM36eSnUH6IR+Doa3zxzRMFmvDqWXy58W9H3P/Zw24YMwmIfVJeVWrk 7SdCgrOVo/6CJ4evAl4LYpnE9altycG5HgzX70tA+myXpNte9RAkknWsI/uk0EZw8HKa PbmwxbnRzpaBR6jeJC1bIYzLci/TSACl1WI5IlThtlLldNuDX6UdAEvTCHjpUi5fiWzr L18uV/et5cb05wttXHKTRzFIOaXmcFQhHq3YlP7gyQwXlOi/hnF2T6VXz+AEoe/7zWuP TMH79t1gGeIR3fNRcVzd/JJ8qOmZe1L5OXE2/jae2K00wKF4qS1T9mrsi3gZPYrdvC7R kQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 38km7pqc18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 May 2021 13:50:15 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DFF6010002A; Tue, 18 May 2021 13:50:14 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id C8ABD2237A4; Tue, 18 May 2021 13:50:14 +0200 (CEST) Received: from lmecxl0573.lme.st.com (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 May 2021 13:50:13 +0200 Subject: Re: [PATCH v3 2/3] mtd: spinand: use the spi-mem poll status APIs To: Boris Brezillon CC: Mark Brown , Miquel Raynal , Vignesh Raghavendra , , Alexandre Torgue , , , , , References: <20210518093951.23136-1-patrice.chotard@foss.st.com> <20210518093951.23136-3-patrice.chotard@foss.st.com> <20210518132850.1558e46b@collabora.com> From: Patrice CHOTARD Message-ID: <84113017-8ba8-4de3-24d8-719c63f458fe@foss.st.com> Date: Tue, 18 May 2021 13:50:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210518132850.1558e46b@collabora.com> Content-Language: en-US X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-18_04:2021-05-18, 2021-05-18 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_045022_206468_03C69D95 X-CRM114-Status: GOOD ( 26.91 ) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-mtd" Errors-To: linux-mtd-bounces+linux-mtd=archiver.kernel.org@lists.infradead.org Hi On 5/18/21 1:28 PM, Boris Brezillon wrote: > On Tue, 18 May 2021 11:39:50 +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 you were reporting for those > that don't have a dedicated STATUS poll block logic, which is great! I will update the commit message by indicating what you mention here. > >> >> Signed-off-by: Patrice Chotard >> Signed-off-by: Christophe Kerello >> --- >> 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 | 11 ++++++++- >> 2 files changed, 42 insertions(+), 14 deletions(-) >> >> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c >> index 17f63f95f4a2..ef2a692ab5b6 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_STATUS_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..180c1fa64e62 100644 >> --- a/include/linux/mtd/spinand.h >> +++ b/include/linux/mtd/spinand.h >> @@ -169,7 +169,16 @@ >> struct spinand_op; >> struct spinand_device; >> >> -#define SPINAND_MAX_ID_LEN 4 >> +#define SPINAND_MAX_ID_LEN 4 >> +#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 > > Could you add a comment explaining where those numbers come from? Sure > >> +#define SPINAND_STATUS_TIMEOUT_MS 400 > > I would name that one SPINAND_WAITRDY_TIMEOUT_MS. Ok > >> >> /** >> * struct spinand_id - SPI NAND id structure > Thanks Patrice ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD22CC433B4 for ; Tue, 18 May 2021 11:53:54 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 2869661002 for ; Tue, 18 May 2021 11:53:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2869661002 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=foss.st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:CC:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=b+7eAQBfJ3I6McL5Lyhpqx2Kn+CbEvpVDYVkTh/Lqj4=; b=ASTb4xaVNcYQ7UcbyZvfP+TVK tu4EaxXSeITuDUXbzqiiexBMMz/sXQarPvvmdtCk/aBQmElZVlf0dhA1iEWOq4MEfYDx1Auw7r/SU ps8zUjw2HRCltE2nFc7ZkOvcFSFugQowpu0KV09GS+yS+Gb78w+q1GIHFE5HEcA3DHb4vdATOAxOd QeaM/9bHEzWsGYZTAtl32IIcFVcGqj9u7SAhrqAKq9JKfK5IXeiPj+9TEetar6555W3viUvh1F+Te IJH2bDDk/8fIiMM8bsyRXR7MFqihH7MP1B3itTfX/QlJut0MUgT8jjOlQOmiIjl8flBvebXOHGEvs Xnop7pByQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1liyGU-000ev0-8Y; Tue, 18 May 2021 11:52:01 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liyEz-000duT-7H; Tue, 18 May 2021 11:50:25 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:CC:To: Subject:Sender:Reply-To:Content-ID:Content-Description; bh=DdKE7jcPLmE85L7BIvJpkrZObmvEJo2niKAbOooRnxo=; b=QFeQG9gadfAJ8Z1tnFVdm0q0e1 aaPwk3pjjEmdEt+zKyG5XAU+8HA1HSDgwZUZu7wN6QwUKOWPgZWoye4S2F74gf21Fc2Or4KctyWHM 8nhuK6j993hdjFZ36WozAsfJvXiU0xLV9g0nADGyRLJ1xdk17RN8H8l+K8SX19Up3ypR5s3IFfEMN Q1jaJ6PDZ9uH0KiAJVbDqlNvKla7KUiqSnh6gqD16w6ULeu625I0j2UcfpeqSmmPfp9u0hi8T9g/8 febJz+x3RQA/rGx4I6ZBGF/4dOaRcKwH6ldT9hF1vlbpcfA4nxd2y1MpafZLVPzfrCGvmSEpwvty6 PWJYbHAA==; Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1liyEv-00EcP3-RS; Tue, 18 May 2021 11:50:23 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14IBkjQf031794; Tue, 18 May 2021 13:50:15 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=selector1; bh=DdKE7jcPLmE85L7BIvJpkrZObmvEJo2niKAbOooRnxo=; b=r2NGqWkTgccIRkM36eSnUH6IR+Doa3zxzRMFmvDqWXy58W9H3P/Zw24YMwmIfVJeVWrk 7SdCgrOVo/6CJ4evAl4LYpnE9altycG5HgzX70tA+myXpNte9RAkknWsI/uk0EZw8HKa PbmwxbnRzpaBR6jeJC1bIYzLci/TSACl1WI5IlThtlLldNuDX6UdAEvTCHjpUi5fiWzr L18uV/et5cb05wttXHKTRzFIOaXmcFQhHq3YlP7gyQwXlOi/hnF2T6VXz+AEoe/7zWuP TMH79t1gGeIR3fNRcVzd/JJ8qOmZe1L5OXE2/jae2K00wKF4qS1T9mrsi3gZPYrdvC7R kQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 38km7pqc18-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 May 2021 13:50:15 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id DFF6010002A; Tue, 18 May 2021 13:50:14 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id C8ABD2237A4; Tue, 18 May 2021 13:50:14 +0200 (CEST) Received: from lmecxl0573.lme.st.com (10.75.127.51) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 May 2021 13:50:13 +0200 Subject: Re: [PATCH v3 2/3] mtd: spinand: use the spi-mem poll status APIs To: Boris Brezillon CC: Mark Brown , Miquel Raynal , Vignesh Raghavendra , , Alexandre Torgue , , , , , References: <20210518093951.23136-1-patrice.chotard@foss.st.com> <20210518093951.23136-3-patrice.chotard@foss.st.com> <20210518132850.1558e46b@collabora.com> From: Patrice CHOTARD Message-ID: <84113017-8ba8-4de3-24d8-719c63f458fe@foss.st.com> Date: Tue, 18 May 2021 13:50:13 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20210518132850.1558e46b@collabora.com> Content-Language: en-US X-Originating-IP: [10.75.127.51] X-ClientProxiedBy: SFHDAG2NODE3.st.com (10.75.127.6) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-18_04:2021-05-18, 2021-05-18 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210518_045022_206468_03C69D95 X-CRM114-Status: GOOD ( 26.91 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi On 5/18/21 1:28 PM, Boris Brezillon wrote: > On Tue, 18 May 2021 11:39:50 +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 you were reporting for those > that don't have a dedicated STATUS poll block logic, which is great! I will update the commit message by indicating what you mention here. > >> >> Signed-off-by: Patrice Chotard >> Signed-off-by: Christophe Kerello >> --- >> 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 | 11 ++++++++- >> 2 files changed, 42 insertions(+), 14 deletions(-) >> >> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c >> index 17f63f95f4a2..ef2a692ab5b6 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_STATUS_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..180c1fa64e62 100644 >> --- a/include/linux/mtd/spinand.h >> +++ b/include/linux/mtd/spinand.h >> @@ -169,7 +169,16 @@ >> struct spinand_op; >> struct spinand_device; >> >> -#define SPINAND_MAX_ID_LEN 4 >> +#define SPINAND_MAX_ID_LEN 4 >> +#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 > > Could you add a comment explaining where those numbers come from? Sure > >> +#define SPINAND_STATUS_TIMEOUT_MS 400 > > I would name that one SPINAND_WAITRDY_TIMEOUT_MS. Ok > >> >> /** >> * struct spinand_id - SPI NAND id structure > Thanks Patrice _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel