Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1676622pxj; Wed, 19 May 2021 11:13:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM7FZ53XKJcuNf/c9axtoMM0Gcnb96ExvilvKlUDdRBLt/D89u9ZW7p73Bq/273P4ZU6/6 X-Received: by 2002:a05:6402:35c5:: with SMTP id z5mr377591edc.210.1621448014876; Wed, 19 May 2021 11:13:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621448014; cv=none; d=google.com; s=arc-20160816; b=XjqX73mgWB8BG/JzJlnmFenSNNUAH/0E13BdK63WQdhlGOqFM0dm0jnmoa3+dHdUt0 L9XM3z2DBk1DngnoT8oZkcNagzDqp4Kpc/9KFEKMIQitsXJDEonU+Q5EMduVmGdnyMAg TeZlZm5XRhdqw2r89nDy77Amm8lVr/Tu2LjZdV2V2NEHQE+OyLOtudMg9eaXyT75z5Uv F2cLhexQll8ZAn2utNHEX81tv84cxFPjF2oiJNndSxxVmkUnzU1To0iIcsd4ZXWM0NwD a+Edy0zrFW+TJgAseVExyjLJEDHwBnb7bZud8vZXtIygfEsrK27cS7NZKzgnw1qWdK7f 7awA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=QTm61m8uz4pOmK3NZoHfZ4HyFmOCc0S7R8oD/Tz+mR0=; b=heXPbyqn6QwfcsIOHPV5Fesy2CxNvoW9d3z9ZG/2kJynAam84CNu0UGETsPAF8y74P 2MRfxQ716VpTbEGm7DvTpybDIQw9Vc3jTm8bpqC9EMz/8eRdwkBs7luay4Uw5jF66PkS qJ4b7m5GuGHghEi5RBGuG2paV2T72BuQI/YoCOo9VJxXFTWvm44HHjpp6T0a5a1+Pksh OHSt/whgRUvAjhKj6PybgdRpQN/lD4jdKV+/b7tlvs4Qk1nEpOdBlafgb6b6xAQuRD4k 0WZmDLsaU6RBeZWvU6wUW5CMAUWbW/n7N98IGXhXSvx+QAYFkbCdLmzpSspDTWzySav+ MlFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="R0QLtP/r"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v24si17476840edy.327.2021.05.19.11.13.11; Wed, 19 May 2021 11:13:34 -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; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="R0QLtP/r"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233782AbhERNpR (ORCPT + 99 others); Tue, 18 May 2021 09:45:17 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:58130 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232806AbhERNpG (ORCPT ); Tue, 18 May 2021 09:45:06 -0400 Received: from pps.filterd (m0241204.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14IDVs6D032044; Tue, 18 May 2021 15:43:36 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=QTm61m8uz4pOmK3NZoHfZ4HyFmOCc0S7R8oD/Tz+mR0=; b=R0QLtP/rtYDlzV7b7lFB+EFdLQk7IJ4wG6xTmBpiCzLB+CNSjtJLd8mEYfFYOG/NSGwg 69LMyd36D1Q8LxI88iWu3t1bNItUMndCvwNNci/ZudiArH97FFr+D4yJO5sgOAHYfI44 GlvcDrss3Ttv9Wn1XV4cn96BfasFTyOSd0Txxafo1uu9Jpl9Rn/bCGb+XbCA2H+HrVUT n8We65/6x//4EXmOWfkBsLgwgR9TLy6kJS2oB1ux1FWUL9I+ryRkh2bR8TBIBbXgTgWu vRGNAh89qTnfxl7ezoS/i5nNzTCgiZNGeWJw+X+UAYQ3IJFgwgQy96gKmF6/gUrGP1rA jQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 38m4673mpr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 18 May 2021 15:43:36 +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 8F8D510002A; Tue, 18 May 2021 15:43:35 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 7ED2E227D8B; Tue, 18 May 2021 15:43:35 +0200 (CEST) Received: from localhost (10.75.127.49) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 18 May 2021 15:43:34 +0200 From: To: Mark Brown , Miquel Raynal , Vignesh Raghavendra , Boris Brezillon , , Alexandre Torgue , , , , CC: , Subject: [PATCH v4 2/3] mtd: spinand: use the spi-mem poll status APIs Date: Tue, 18 May 2021 15:43:31 +0200 Message-ID: <20210518134332.17826-3-patrice.chotard@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210518134332.17826-1-patrice.chotard@foss.st.com> References: <20210518134332.17826-1-patrice.chotard@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.49] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) 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 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 --- 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 -- 2.17.1