From patchwork Mon May 18 13:59:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 1292545 X-Patchwork-Delegate: miquel.raynal@bootlin.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=t+bxEy6t; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=gNX8Gb7t; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Qgdk4ckkz9sTg for ; Tue, 19 May 2020 00:00:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=1S0EVOE0QqYBKXEgaOvLdz708QMoSKiwUC6hirsbWOU=; b=t+bxEy6trJBy8hyoOVvUOvLIN9 yMWYdels47NMEdJhgLNRz+dfBfHwAl/FuliKViU+dl+XjZuujJfDxwX6HlTrsuT+qW8Cx+mGDpW4k A1mUYdTyX5Jpc+7ihxAUGIAPdY1Asq/QvMwtaxqitMK4GtugW0zTg4xwk3ZyqUDz8oNoi/jCQ3gPE lfsq9l16Oh0GIRq+elKV/bXyUjom7w+ehwesgAXaQ+foHVm6u2XCEe6UqfZasKeKCU/BpiVeVFdOk D/0LKgLl7r4KcvMAUXwjixn4oPEgfRJg+VhilVyLiDK8/845yCB30HrSfK0ais0Jb00l9x92k8Pe3 iefOHl2Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagJa-0003OV-4g; Mon, 18 May 2020 14:00:22 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagJE-0000kE-Gr for linux-mtd@lists.infradead.org; Mon, 18 May 2020 14:00:02 +0000 Received: by mail-wm1-x344.google.com with SMTP id h4so9413282wmb.4 for ; Mon, 18 May 2020 07:00:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A4qhrGBB7f1ImMUQjw2ZKgOqKWcJqgmHu7USuIdXtmw=; b=gNX8Gb7t9f+17Sh19oR1/FX3dDWfwcfjItzuTVm38fPjpBZL5rxAWBVfbBDcXfzqo+ k9HBb0COHY0yTFuvcnwXC5s+tg8JiI3ChmbqhegauSCBPY4lgLCZEANVggSE4h1h++WL OeXJsMcN3fDmNgSEP0KBUlFjZenjg6iHt62Yi5WRgjwdj+V8DfWllTXH7GjxdsUombjb x++S50iPIAAuh2vN6g03F2bWnyyWwWbVcnFmsxsWByR8hrPDbf2U0RGwfZrPHyrMwECx tsIF9LXL4nWDYuYJTtiwQyy0yW+0cfOkluGsBW1r70EPWL69VM02NrC3gH/re2arOqTS PN2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A4qhrGBB7f1ImMUQjw2ZKgOqKWcJqgmHu7USuIdXtmw=; b=XnHSEACEqzffm0FT15GCKMDUuHEMVy306srD6DlLDNE5TxBn6INq2tv15FXtunA/Eq XaS7m7aCvV+ZacU/twsY7WNbMJDWUVgXPcJzzUX4ze73TWsZOt2E4Pl7CobVDqpXxsXQ q7nyD8OFR72kYtP9veVUKWaWGgoNWwHeNcx+uyDGH+NL/raG7nc+eYJ9zDbdGMzeyvhK aRxHNUZpHaDNJHDzFfAqBGQfDZ7eizO1Os9EvxbPi3LYssEs+k5bfJOuJt7xrWjghRR7 a0oiPxEjnxQOHezbhfM+LonrXGQqCAm2LtzbQGD2RdccMglXEz8l97YlRxxApYf0gYcj NKLg== X-Gm-Message-State: AOAM533w9y/zskK5YtrDN5m94aV6qgqpa3vj2K5b3eOA/cVg8CONc/xj 8Asyj3YkQuBMLBSb1HVSJmA= X-Google-Smtp-Source: ABdhPJyP45bp1eWh7BiyaIVzUGYccuxpamtBvBAzxpeKAO3mHVctImD0ZM8YbGrC4n+t3BpKwZIzaw== X-Received: by 2002:a7b:c41a:: with SMTP id k26mr19981506wmi.85.1589810398945; Mon, 18 May 2020 06:59:58 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:b884:8d4:84ab:c471:b6eb:fcab]) by smtp.gmail.com with ESMTPSA id 81sm18114519wme.16.2020.05.18.06.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 06:59:58 -0700 (PDT) From: Bean Huo To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, s.hauer@pengutronix.de, boris.brezillon@collabora.com, derosier@gmail.com Subject: [PATCH v4 1/5] mtd: rawnand: group all NAND specific ops into new nand_chip_ops Date: Mon, 18 May 2020 15:59:39 +0200 Message-Id: <20200518135943.11749-2-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200518135943.11749-1-huobean@gmail.com> References: <20200518135943.11749-1-huobean@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_070000_558730_C7C9ED8A X-CRM114-Status: GOOD ( 17.64 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:344 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [huobean[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huobean@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Bean Huo MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bean Huo This patch is to create a new structure nand_chip_ops, and take all NAND specific functions out from nand_chip and put them in this new structure. Signed-off-by: Bean Huo --- drivers/mtd/nand/raw/nand_base.c | 20 +++++++++--------- drivers/mtd/nand/raw/nand_hynix.c | 2 +- drivers/mtd/nand/raw/nand_macronix.c | 10 ++++----- drivers/mtd/nand/raw/nand_micron.c | 2 +- include/linux/mtd/rawnand.h | 31 +++++++++++++++++----------- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 2d2a216af120..7af21cf49290 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3234,10 +3234,10 @@ static int nand_setup_read_retry(struct nand_chip *chip, int retry_mode) if (retry_mode >= chip->read_retries) return -EINVAL; - if (!chip->setup_read_retry) + if (!chip->ops.setup_read_retry) return -EOPNOTSUPP; - return chip->setup_read_retry(chip, retry_mode); + return chip->ops.setup_read_retry(chip, retry_mode); } static void nand_wait_readrdy(struct nand_chip *chip) @@ -4481,8 +4481,8 @@ static int nand_suspend(struct mtd_info *mtd) int ret = 0; mutex_lock(&chip->lock); - if (chip->suspend) - ret = chip->suspend(chip); + if (chip->ops.suspend) + ret = chip->ops.suspend(chip); if (!ret) chip->suspended = 1; mutex_unlock(&chip->lock); @@ -4500,8 +4500,8 @@ static void nand_resume(struct mtd_info *mtd) mutex_lock(&chip->lock); if (chip->suspended) { - if (chip->resume) - chip->resume(chip); + if (chip->ops.resume) + chip->ops.resume(chip); chip->suspended = 0; } else { pr_err("%s called for a chip which is not in suspended state\n", @@ -4530,10 +4530,10 @@ static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct nand_chip *chip = mtd_to_nand(mtd); - if (!chip->lock_area) + if (!chip->ops.lock_area) return -ENOTSUPP; - return chip->lock_area(chip, ofs, len); + return chip->ops.lock_area(chip, ofs, len); } /** @@ -4546,10 +4546,10 @@ static int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { struct nand_chip *chip = mtd_to_nand(mtd); - if (!chip->unlock_area) + if (!chip->ops.unlock_area) return -ENOTSUPP; - return chip->unlock_area(chip, ofs, len); + return chip->ops.unlock_area(chip, ofs, len); } /* Set default functions */ diff --git a/drivers/mtd/nand/raw/nand_hynix.c b/drivers/mtd/nand/raw/nand_hynix.c index 7caedaa5b9e5..7d1be53f27f3 100644 --- a/drivers/mtd/nand/raw/nand_hynix.c +++ b/drivers/mtd/nand/raw/nand_hynix.c @@ -337,7 +337,7 @@ static int hynix_mlc_1xnm_rr_init(struct nand_chip *chip, rr->nregs = nregs; rr->regs = hynix_1xnm_mlc_read_retry_regs; hynix->read_retry = rr; - chip->setup_read_retry = hynix_nand_setup_read_retry; + chip->ops.setup_read_retry = hynix_nand_setup_read_retry; chip->read_retries = nmodes; out: diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c index 09c254c97b5c..1472f925f386 100644 --- a/drivers/mtd/nand/raw/nand_macronix.c +++ b/drivers/mtd/nand/raw/nand_macronix.c @@ -130,7 +130,7 @@ static void macronix_nand_onfi_init(struct nand_chip *chip) return; chip->read_retries = MACRONIX_NUM_READ_RETRY_MODES; - chip->setup_read_retry = macronix_nand_setup_read_retry; + chip->ops.setup_read_retry = macronix_nand_setup_read_retry; if (p->supports_set_get_features) { bitmap_set(p->set_feature_list, @@ -242,8 +242,8 @@ static void macronix_nand_block_protection_support(struct nand_chip *chip) bitmap_set(chip->parameters.set_feature_list, ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1); - chip->lock_area = mxic_nand_lock; - chip->unlock_area = mxic_nand_unlock; + chip->ops.lock_area = mxic_nand_lock; + chip->ops.unlock_area = mxic_nand_unlock; } static int nand_power_down_op(struct nand_chip *chip) @@ -312,8 +312,8 @@ static void macronix_nand_deep_power_down_support(struct nand_chip *chip) if (i < 0) return; - chip->suspend = mxic_nand_suspend; - chip->resume = mxic_nand_resume; + chip->ops.suspend = mxic_nand_suspend; + chip->ops.resume = mxic_nand_resume; } static int macronix_nand_init(struct nand_chip *chip) diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c index b2b047b245f4..b3485b0995ad 100644 --- a/drivers/mtd/nand/raw/nand_micron.c +++ b/drivers/mtd/nand/raw/nand_micron.c @@ -84,7 +84,7 @@ static int micron_nand_onfi_init(struct nand_chip *chip) struct nand_onfi_vendor_micron *micron = (void *)p->onfi->vendor; chip->read_retries = micron->read_retry_options; - chip->setup_read_retry = micron_nand_setup_read_retry; + chip->ops.setup_read_retry = micron_nand_setup_read_retry; } if (p->supports_set_get_features) { diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 0f45b6984ad1..62932cc3ed8d 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1025,6 +1025,23 @@ struct nand_legacy { struct nand_controller dummy_controller; }; +/** + * struct nand_chip_ops - NAND Chip specific operations + * @suspend: [REPLACEABLE] specific NAND device suspend operation + * @resume: [REPLACEABLE] specific NAND device resume operation + * @lock_area: [REPLACEABLE] specific NAND chip lock operation + * @unlock_area: [REPLACEABLE] specific NAND chip unlock operation + * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for + * setting the read-retry mode. Mostly needed for MLC NAND. + */ +struct nand_chip_ops { + int (*suspend)(struct nand_chip *chip); + void (*resume)(struct nand_chip *chip); + int (*lock_area)(struct nand_chip *chip, loff_t ofs, u64 len); + int (*unlock_area)(struct nand_chip *chip, loff_t ofs, u64 len); + int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); +}; + /** * struct nand_chip - NAND Private Flash Chip Data * @base: Inherit from the generic NAND device @@ -1033,8 +1050,6 @@ struct nand_legacy { * you're modifying an existing driver that is using those * fields/hooks, you should consider reworking the driver * avoid using them. - * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for - * setting the read-retry mode. Mostly needed for MLC NAND. * @ecc: [BOARDSPECIFIC] ECC control structure * @buf_align: minimum buffer alignment required by a platform * @oob_poi: "poison value buffer," used for laying out OOB data @@ -1079,8 +1094,6 @@ struct nand_legacy { * @lock: lock protecting the suspended field. Also used to * serialize accesses to the NAND device. * @suspended: set to 1 when the device is suspended, 0 when it's not. - * @suspend: [REPLACEABLE] specific NAND device suspend operation - * @resume: [REPLACEABLE] specific NAND device resume operation * @bbt: [INTERN] bad block table pointer * @bbt_td: [REPLACEABLE] bad block table descriptor for flash * lookup. @@ -1094,8 +1107,7 @@ struct nand_legacy { * @manufacturer: [INTERN] Contains manufacturer information * @manufacturer.desc: [INTERN] Contains manufacturer's description * @manufacturer.priv: [INTERN] Contains manufacturer private information - * @lock_area: [REPLACEABLE] specific NAND chip lock operation - * @unlock_area: [REPLACEABLE] specific NAND chip unlock operation + * @ops: NAND-specific operations description structure */ struct nand_chip { @@ -1103,8 +1115,6 @@ struct nand_chip { struct nand_legacy legacy; - int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); - unsigned int options; unsigned int bbt_options; @@ -1136,8 +1146,6 @@ struct nand_chip { struct mutex lock; unsigned int suspended : 1; - int (*suspend)(struct nand_chip *chip); - void (*resume)(struct nand_chip *chip); uint8_t *oob_poi; struct nand_controller *controller; @@ -1158,8 +1166,7 @@ struct nand_chip { void *priv; } manufacturer; - int (*lock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); - int (*unlock_area)(struct nand_chip *chip, loff_t ofs, uint64_t len); + struct nand_chip_ops ops; }; extern const struct mtd_ooblayout_ops nand_ooblayout_sp_ops; From patchwork Mon May 18 13:59:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 1292546 X-Patchwork-Delegate: miquel.raynal@bootlin.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=Q/Wfi/r8; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=cYf9JHC+; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Qgdk6ffWz9sTh for ; Tue, 19 May 2020 00:00:42 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=9MqiK9hNbLqydDraibofyiuUaNgCVamN0Kd2WzFIa+0=; b=Q/Wfi/r83hGPdXQY+x/rJfmBYr IFJd7uVSo0P5JYO/q6Ttvue5yGclI9eZcIPXlYI71b3wv3MCuJ6GwOPd95AyyGeUBYeihUB228hhh bkao6QCS6vR/dOtuAoca22NX++zzvt4KAF/ynR/BmdUKgYk3IkZhj/WGMiTzDWl4pcYiGG2V266Zj pGIrzvQnZzODtKiDUOAgIngz9HrtLDYEbQNzvGCLj9MSSpssEtu+9Su1m7LuLjw3UXWC3QBOn7xbj NgtmGcitJp2kNPFanc1MnJc2ts3Si0jy3IvA0c2m7MHLp0+724NiMKr78CHcbW2zcykOBqUMeXFKJ Qjw/Wg3g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagJs-0003fv-6i; Mon, 18 May 2020 14:00:40 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagJG-0000lN-8C for linux-mtd@lists.infradead.org; Mon, 18 May 2020 14:00:04 +0000 Received: by mail-wm1-x344.google.com with SMTP id f134so9419823wmf.1 for ; Mon, 18 May 2020 07:00:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zgSEgyu5An5GyigcNkf1Yhsncd+sLucumkdkFEyxqlE=; b=cYf9JHC+73yCMVT342d6rL9GyqewbyYRsjqMCwiojwe8y3EPfjk/tOSYZipRAHdIYI SPnYWG245PFUoHKp1G4FRD9y8QfNkRVI4+hDa1ag2g6mNDeCbjQsmfma5N4bjZq7Yarx +Qmh24WOPdeYQMoTEg26Pir/LmhRFca8dVHwELaUTf0FbAx4tNUa3ogb7Gtn7Ty/pkLo W/B0FsoLM7LgVirbOoJiXyJnStqLlmVgnyaOo6awM3nkj3WcYRg2YaKgies9DJk8+nk2 uRGK9cdYH8TsqHAhnv3k8Offqy6zatzwpI+TSuDuPptiW9rKfAP7ux9GdzkJPp9N1Tbw 6JDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zgSEgyu5An5GyigcNkf1Yhsncd+sLucumkdkFEyxqlE=; b=f1+FDh/yjK/myKwylyt5Dd4kjr/ivy5ntBpTKMysq0ruKCQtusgkfRUFfXQ8XeRA+y QJs12/rQvRay1QzT8H+r3t+hommD+YVJoonLpZjNPq+zz3sefnWo9yXtD6uPVkFpyNpe wPcZNOdKPDMTgpEPjEtHfjGe8p/Seo8j7cwCDuryrg01/QZINiyrDWdFfpYkV1wKZmOf Ap9k01RQ/SZXOneooIO+BHFacXT5jB298izD7I6HkYIzpXDJuJ+XeQ+ZT4tVuR7+7pyZ tVnGABgpMVeDoAWx07f7Cmidl3sx7h9MtCyipjPv6uj4iW2/4tOxAcnr8kYyumSMmYLQ erOg== X-Gm-Message-State: AOAM5323TCBqLDAQZ5QfLn8FywHTVU/70ncfQt0nYbDkT3azKo3FLqfj k/SyPt/CdFfGFwPzqYxJggY= X-Google-Smtp-Source: ABdhPJwvj4hXlFStwBw2Qb0K7mZR4VXIsX8iG99gZxRvvtkMB5O4D4+yb/tNyI90pJT7X8xqkBfQTw== X-Received: by 2002:a1c:cc1a:: with SMTP id h26mr18838818wmb.127.1589810401059; Mon, 18 May 2020 07:00:01 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:b884:8d4:84ab:c471:b6eb:fcab]) by smtp.gmail.com with ESMTPSA id 81sm18114519wme.16.2020.05.18.06.59.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 07:00:00 -0700 (PDT) From: Bean Huo To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, s.hauer@pengutronix.de, boris.brezillon@collabora.com, derosier@gmail.com Subject: [PATCH v4 2/5] mtd: rawnand: Add {pre, post}_erase hooks in nand_chip_ops Date: Mon, 18 May 2020 15:59:40 +0200 Message-Id: <20200518135943.11749-3-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200518135943.11749-1-huobean@gmail.com> References: <20200518135943.11749-1-huobean@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_070002_337044_A766FA14 X-CRM114-Status: GOOD ( 11.76 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:344 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [huobean[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huobean@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Bean Huo MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bean Huo Add {pre,post}_erase hooks in the structure nand_chip_ops: pre_erase will be called before a block is physically erased. post_erase will be called after a block is erased. Signed-off-by: Bean Huo --- drivers/mtd/nand/raw/nand_base.c | 18 +++++++++++++----- include/linux/mtd/rawnand.h | 16 ++++++++++------ 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 7af21cf49290..e90b7ae878e2 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4318,7 +4318,7 @@ static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr, int allowbbt) { - int page, pages_per_block, ret, chipnr; + int page, pages_per_block, ret, chipnr, eb; loff_t len; pr_debug("%s: start = 0x%012llx, len = %llu\n", @@ -4372,16 +4372,24 @@ int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr, (page + pages_per_block)) chip->pagecache.page = -1; - ret = nand_erase_op(chip, (page & chip->pagemask) >> - (chip->phys_erase_shift - chip->page_shift)); + eb = (page & chip->pagemask) >> + (chip->phys_erase_shift - chip->page_shift); + + if (chip->ops.pre_erase) + chip->ops.pre_erase(chip, eb); + + ret = nand_erase_op(chip, eb); if (ret) { - pr_debug("%s: failed erase, page 0x%08x\n", - __func__, page); + pr_debug("%s: failed erase block %d, page 0x%08x\n", + __func__, eb, page); instr->fail_addr = ((loff_t)page << chip->page_shift); goto erase_exit; } + if (chip->ops.post_erase) + chip->ops.post_erase(chip, eb); + /* Increment page address and decrement length */ len -= (1ULL << chip->phys_erase_shift); page += pages_per_block; diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 62932cc3ed8d..df3d4b3ef2f6 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1027,12 +1027,14 @@ struct nand_legacy { /** * struct nand_chip_ops - NAND Chip specific operations - * @suspend: [REPLACEABLE] specific NAND device suspend operation - * @resume: [REPLACEABLE] specific NAND device resume operation - * @lock_area: [REPLACEABLE] specific NAND chip lock operation - * @unlock_area: [REPLACEABLE] specific NAND chip unlock operation - * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for - * setting the read-retry mode. Mostly needed for MLC NAND. + * @suspend: [REPLACEABLE] specific NAND device suspend operation + * @resume: [REPLACEABLE] specific NAND device resume operation + * @lock_area: [REPLACEABLE] specific NAND chip lock operation + * @unlock_area: [REPLACEABLE] specific NAND chip unlock operation + * @setup_read_retry: [FLASHSPECIFIC] flash (vendor) specific function for + * setting the read-retry mode. Mostly needed for MLC NAND. + * @pre_erase: [FLASHSPECIFIC] prepare a physical erase block + * @post_erase: [FLASHSPECIFIC] physical block erase post */ struct nand_chip_ops { int (*suspend)(struct nand_chip *chip); @@ -1040,6 +1042,8 @@ struct nand_chip_ops { int (*lock_area)(struct nand_chip *chip, loff_t ofs, u64 len); int (*unlock_area)(struct nand_chip *chip, loff_t ofs, u64 len); int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); + int (*pre_erase)(struct nand_chip *chip, u32 eraseblock); + int (*post_erase)(struct nand_chip *chip, u32 eraseblock); }; /** From patchwork Mon May 18 13:59:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 1292548 X-Patchwork-Delegate: miquel.raynal@bootlin.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=BJGwh3gK; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=g0ui3OTS; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Qgf61s6Zz9sTN for ; Tue, 19 May 2020 00:01:02 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Q2ncklAOSIwv20mK0Fm0ka8gKwJwMfprrkQUQ6jc9WU=; b=BJGwh3gK+W6qdqPzee6QSHNaSJ FHQNE9bTT+NN+NkIJ5oZc1eH4KrEaaRVevvOePA8mc8zvupTV1fVV1n7lXXcjQXApbrPzpM7fmQq2 ddHYEW7zYrqFy18de8sIPrcgEAg7fDpihSaQJ0c/K944UU7e2mXcWC/zhJp6kZl8pFQAvC6NHqG6p /wspUuDZ8SO78xnaLvaof1GMWsqRuM3NTRERcAGxBZibwAxCy2Ry8D5K2wzjZhscUzVCRjByA33+S UYkvAIRXu/2oZAg1Kj5pPBP76abTfyaoQoET5lOZQLBQghp4m1wiIE6TmtJH29xpKOstkPcTSrf+p t3utpjFg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagK9-0003wD-Tr; Mon, 18 May 2020 14:00:57 +0000 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagJI-00014c-Gw for linux-mtd@lists.infradead.org; Mon, 18 May 2020 14:00:06 +0000 Received: by mail-wm1-x341.google.com with SMTP id z72so10581482wmc.2 for ; Mon, 18 May 2020 07:00:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=A0dzsFd7YATdAmh4B3Ufb/iHlKjHhY14r5pPPWljdn0=; b=g0ui3OTSkdJShadSlw+WcDWAUcm6y3J7YghKX95julkcaI4O4wZrMf3JOkUqdcFx35 aEuXbH1XbUYj+PmfcTNHJS7b7me4PympHBUltaCtxkINQzPHpSFbSyPDEo9g7dA+rxsR kF3sPnA0Op4R4UZT+Q4taN8bonFab/1kXD2qIwRHeyqQCjncj2KcggBjVh9EHvqMiQe5 PujuqQ/m04AYJ9lRwbKp+RR0H8yZVQFTV7NoNiHstGXtegRo72BvuwWllGlksiFSKrqx 4BvTDXOzxjiMZkz2BaC+pxrj1/9H5ku4SlL7Zb6cYkijKPFn9G6wFzGOkypMjYYscJ2Q xVvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=A0dzsFd7YATdAmh4B3Ufb/iHlKjHhY14r5pPPWljdn0=; b=HJF63VhlbOGniWpwSduZ/KrV8xoP8jE/TxvQqHmMTfCG1T5eVJNXT8fmlT0bhwIfLo cpDUfYtsE8EwtXhaWE1K+JWSvpKzfI1euCfWsF8g5A3lqdZyHKeU0H/v7ORj4Ybz011n cfMysl32UZ7DEsaVskD3j67UrRxDkP3elNXd6TmlElc224B/3FiHeImwxjFs48uMX+as nCTk7sxF0R6Q2+b4iCFqfuDdd0ssr65Tp67OZtIByHlil2YDRj240yETx9T9A/4utp3U 7ny0kPRJPo0JbpVlTM9YzcmU5umMpZoVNus8yPMxcpbKzlicdQPPxIRt2Lcv0ghm1dzR wL+Q== X-Gm-Message-State: AOAM530M8qB1SszYud/CrxCiW/3lvAfovR8+g1t4bGrZ1zuJHU/DWE88 N2z5B/2RCcUltZbEa+yGJ523E6OR X-Google-Smtp-Source: ABdhPJzJM6UZDI0PriKylI2w6FhVHwt18WruFbLtc9Ca+rp2Dmr/RFDUJjS8WsGgVPhIfCXSAlD8wg== X-Received: by 2002:a1c:7305:: with SMTP id d5mr20288874wmb.85.1589810403095; Mon, 18 May 2020 07:00:03 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:b884:8d4:84ab:c471:b6eb:fcab]) by smtp.gmail.com with ESMTPSA id 81sm18114519wme.16.2020.05.18.07.00.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 07:00:02 -0700 (PDT) From: Bean Huo To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, s.hauer@pengutronix.de, boris.brezillon@collabora.com, derosier@gmail.com Subject: [PATCH v4 3/5] mtd: rawnand: Add write_oob hook in nand_chip_ops Date: Mon, 18 May 2020 15:59:41 +0200 Message-Id: <20200518135943.11749-4-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200518135943.11749-1-huobean@gmail.com> References: <20200518135943.11749-1-huobean@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_070004_587829_BA8F8342 X-CRM114-Status: GOOD ( 12.49 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:341 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [huobean[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huobean@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Bean Huo MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bean Huo Break the function nand_write_oob() into two functions, and one of them is named nand_write_oob_nand(), which will be assigned to new added hook write_oob by default. The hook write_oob will be overwritten in the NAND vendor lower-level driver if needed. Signed-off-by: Miquel Raynal Signed-off-by: Bean Huo --- drivers/mtd/nand/raw/internals.h | 3 ++- drivers/mtd/nand/raw/nand_base.c | 9 +++++++++ include/linux/mtd/rawnand.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/nand/raw/internals.h b/drivers/mtd/nand/raw/internals.h index 03866b0aadea..94d300a207ac 100644 --- a/drivers/mtd/nand/raw/internals.h +++ b/drivers/mtd/nand/raw/internals.h @@ -99,7 +99,8 @@ int nand_read_param_page_op(struct nand_chip *chip, u8 page, void *buf, void nand_decode_ext_id(struct nand_chip *chip); void panic_nand_wait(struct nand_chip *chip, unsigned long timeo); void sanitize_string(uint8_t *s, size_t len); - +int nand_write_oob_nand(struct nand_chip *chip, loff_t to, + struct mtd_oob_ops *ops); static inline bool nand_has_exec_op(struct nand_chip *chip) { if (!chip->controller || !chip->controller->ops || diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index e90b7ae878e2..09ee490c08a9 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -4267,6 +4267,13 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) { struct nand_chip *chip = mtd_to_nand(mtd); + + return chip->ops.write_oob(chip, to, ops); +} + +int nand_write_oob_nand(struct nand_chip *chip, loff_t to, + struct mtd_oob_ops *ops) +{ int ret; ops->retlen = 0; @@ -4573,6 +4580,8 @@ static void nand_set_defaults(struct nand_chip *chip) if (!chip->buf_align) chip->buf_align = 1; + + chip->ops.write_oob = nand_write_oob_nand; } /* Sanitize ONFI strings so we can safely print them */ diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index df3d4b3ef2f6..3d75e50e5b75 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1035,6 +1035,7 @@ struct nand_legacy { * setting the read-retry mode. Mostly needed for MLC NAND. * @pre_erase: [FLASHSPECIFIC] prepare a physical erase block * @post_erase: [FLASHSPECIFIC] physical block erase post + * @write_oob: [REPLACEABLE] Raw NAND write operation */ struct nand_chip_ops { int (*suspend)(struct nand_chip *chip); @@ -1044,6 +1045,8 @@ struct nand_chip_ops { int (*setup_read_retry)(struct nand_chip *chip, int retry_mode); int (*pre_erase)(struct nand_chip *chip, u32 eraseblock); int (*post_erase)(struct nand_chip *chip, u32 eraseblock); + int (*write_oob)(struct nand_chip *chip, loff_t to, + struct mtd_oob_ops *ops); }; /** From patchwork Mon May 18 13:59:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 1292549 X-Patchwork-Delegate: miquel.raynal@bootlin.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=DLvXjoGw; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=fvwBdK3J; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Qgfd1KXMz9sT6 for ; Tue, 19 May 2020 00:01:29 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=WxKbg3K405E3juDFAoP7FzgOyGFbQtP43J8fhXQbMNY=; b=DLvXjoGwokxanZt/lsROpCj7sx cOLzRawsqNslRvCm6eDSoul6SOj+OriOKmi3CQzwUuon+MtgdBNm8IVcF2wsqRdotUmhFKBXIOEqv GsyAilL4aFmyW7tKp91f0XQiGdy0ForhK0u2aX429Zi2PCiym33xopti2ZUwtvj/pU8Czen8ydMtv LQHV7Bn1KDWktdM12D595QdFAItglPWiCoEFe5FHX/g8uzA9jS9RSFWlwWZVF50ZVe4VxPtdH+qP9 Kg1YJDXK+kJEL9es2LkWl0jVe/0ILwd4KCs+V1iR0gHPdp0Smcrtl29/3L8sigrJrOIPwfvwjl2kY F5rdtNyQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagKR-0004Ab-8j; Mon, 18 May 2020 14:01:15 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagJK-0001NH-CI for linux-mtd@lists.infradead.org; Mon, 18 May 2020 14:00:08 +0000 Received: by mail-wm1-x343.google.com with SMTP id u188so10555333wmu.1 for ; Mon, 18 May 2020 07:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FX8TNCptGGK3iFTps84rr7nd+amFy6w3yf6z9n1Ntbk=; b=fvwBdK3JrAS72Dg6AZKgn0+tDykNrwg7gBBpffsQZ1vQJ0XMc/ibB4ETfko3UFcvST wXEiRcfmAFxQk1Ap53rY1dn8+X5QKy3BM6uQlY303heMxa2vmCiQKYw1oaGrlW9D5DFt Fk/uURXAqymSJp/MsSIAaWuQtrIMI3Na2Z000BEEd5hINmqMOu6abWDn48bd7VOcE5s+ u97yG3gsaeqvHfIK6Bc4JXtWeInBjO9fGvS1oiosg9mcB0Q7/JjkgP8ece6UfwzsShyk HRDrV4NAy3UiHCStXLEzW3uI9OW1Jh19OiO3rYAtTLU/HmAE4eCbWOOJrUl/qxzQLSWf bJdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FX8TNCptGGK3iFTps84rr7nd+amFy6w3yf6z9n1Ntbk=; b=W5EwKyLm4/gCQgTCsD2XXXGSYQC3J7MialuBEMzpddpI+Yt/cw3vGvRZ4ACoiKEHQg 3GtfyIdISgmwHRcB8uBFOCXEUexIAxrKLIl5y8ZUnK1wJ+1iUwTpOFC1Rn2BZfS6knib q8tZHY87GC+X5WL38/JBRmhH9UAamUyAzwW8pZRazzuNbkEsTmg0pcTAM3s5OqsBpGup NlYyD9GbTtjnY5wK4AhsXu6Po4C+LJH67bvxEPMiGacPJuhBCHw6JjE8uCFJVuUecz+d 3bXKUrqoT5R6F49ILyup3phZpZejP2D116msCH9uJCxlITSP8AZhaMu2EnOhr5dVWAjv 95Ww== X-Gm-Message-State: AOAM533om0v1W6oFowN5zEQvjLYvrqc+fqhZEsHEoJN7lVj0AI3Dvct9 J4V+xunt1GahY5KmyE3JKiE= X-Google-Smtp-Source: ABdhPJwQczAFkXPerpxOthlTabAANkJyTxrBuMCTEbYwFXhB9QX9Ob73IFV5eoS0xDp0Z2eDCKOEqA== X-Received: by 2002:a1c:cc1a:: with SMTP id h26mr18839093wmb.127.1589810404636; Mon, 18 May 2020 07:00:04 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:b884:8d4:84ab:c471:b6eb:fcab]) by smtp.gmail.com with ESMTPSA id 81sm18114519wme.16.2020.05.18.07.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 07:00:04 -0700 (PDT) From: Bean Huo To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, s.hauer@pengutronix.de, boris.brezillon@collabora.com, derosier@gmail.com Subject: [PATCH v4 4/5] mtd: rawnand: Introduce a new function nand_check_is_erased_page() Date: Mon, 18 May 2020 15:59:42 +0200 Message-Id: <20200518135943.11749-5-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200518135943.11749-1-huobean@gmail.com> References: <20200518135943.11749-1-huobean@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_070006_450443_8309A621 X-CRM114-Status: GOOD ( 12.10 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:343 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [huobean[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huobean@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Bean Huo MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bean Huo Add a new function nand_check_is_erased_page() in nand_base.c, which is used to check whether one programmable page is empty or already programmed. Signed-off-by: Bean Huo Reported-by: kbuild test robot --- drivers/mtd/nand/raw/nand_base.c | 41 ++++++++++++++++++++++++++++++++ include/linux/mtd/rawnand.h | 2 ++ 2 files changed, 43 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 09ee490c08a9..2b9862d9979b 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -2646,6 +2646,47 @@ int nand_check_erased_ecc_chunk(void *data, int datalen, } EXPORT_SYMBOL(nand_check_erased_ecc_chunk); +/** + * nand_check_is_erased_page - check if this page is a empty page + * @chip: nand chip info structure + * @page_data: data buffer containing the data in the page being checked + * @oob: indicate if chip->oob_poi points to oob date of the page + * + * Returns true if this is an un-programmed page, false otherwise. + */ +int nand_check_is_erased_page(struct nand_chip *chip, u8 *page_data, bool oob) +{ + struct mtd_info *mtd = nand_to_mtd(chip); + int ret, i; + u8 *databuf, *eccbuf = NULL; + struct mtd_oob_region oobregion; + int datasize, eccbytes = 0; + + databuf = page_data; + datasize = chip->ecc.size; + + if (oob) { + mtd_ooblayout_ecc(mtd, 0, &oobregion); + eccbuf = chip->oob_poi + oobregion.offset; + eccbytes = chip->ecc.bytes; + } + max_bitflips = 0; + + for (i = 0; i < chip->ecc.steps; i++) { + ret = nand_check_erased_ecc_chunk(databuf, datasize, + eccbuf, eccbytes, + NULL, 0, chip->ecc.strength); + if (ret < 0) + return false; + + databuf += chip->ecc.size; + eccbuf += chip->ecc.bytes; + } + + return ret; +} +EXPORT_SYMBOL(nand_check_is_erased_page); + /** * nand_read_page_raw_notsupp - dummy read raw page function * @chip: nand chip info structure diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 3d75e50e5b75..718ce81eb111 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1337,6 +1337,8 @@ int nand_check_erased_ecc_chunk(void *data, int datalen, void *extraoob, int extraooblen, int threshold); +int nand_check_is_erased_page(struct nand_chip *chip, u8 *page_data, bool oob); + int nand_ecc_choose_conf(struct nand_chip *chip, const struct nand_ecc_caps *caps, int oobavail); From patchwork Mon May 18 13:59:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bean Huo X-Patchwork-Id: 1292550 X-Patchwork-Delegate: miquel.raynal@bootlin.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20170209 header.b=iPMGi99Z; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=WKQZ9JFW; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49Qgfy4CW2z9sT6 for ; Tue, 19 May 2020 00:01:46 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Nnem3NrHRpL55bseZltqZyuPKgLvRkg/LgBYVgom3Ic=; b=iPMGi99Z2f1yFqbbsslAOA/3gd 4FbJEZ3+iSUM1t5Km2/FRZjV21nRbJQ2nIw/MFkzC9/WfeCbxXE8Ex69Bx47fZ6njy4THeVKLflvf X5qSu/QKUEwWZlqMsh6nD4ljHrr+GiSOaJoV0A0EFTUWpHfJPpUwLigit7SDI7wI2E8NYGN2CU9yI czQnod6WpDmS1fsp+eXCRG3eygDuXdq4PPHBB1jJiNfHBHrDu4Rnq84Dke5BZqZFhtjP+vIiudsvf lYqpOITGAe48EeH6KfK3ONDR4N8Ijz+Op1QZgJ4LCtGKQJ/FfOkYQXIIMbTK/2ClAv1AIgDWIdYzH rBFw9MtA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagKj-0004be-T7; Mon, 18 May 2020 14:01:33 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jagJM-0001jF-0y for linux-mtd@lists.infradead.org; Mon, 18 May 2020 14:00:10 +0000 Received: by mail-wm1-x342.google.com with SMTP id f134so9420212wmf.1 for ; Mon, 18 May 2020 07:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PhOLQ/F7J+2sphUowl9P4vwRtY+FxXOHsvwRgin0evk=; b=WKQZ9JFWOHdV8WWzQocLGVLzoReM/ZedGXcLLw8+YoYe6Q4L9KAVAA8SX9tICGQzeq K38lphcNq2lE1b+iTCVArrTsM2/Zm3upAuWjywCncQYgVjaToV/wSBByHr0ITAZU65LT QEL07I11p3c4uhKMv98clhSCdXlLz2yIeYyLLT5bRaoEx+K6NMwTLRoRjMS59/njZVtE bvIHIATFIw8ek6pavS1ZPaQhUyu5ueGeFSUV2KawD8vzeVjVBdZ0O2+tO9Cj6dbkFF3d bSJvJWqYgzl75yY7NwtOrFolYmHW/DiueAEEqQ13gtC00No+Nf5e0Hd+k/P9hYEfjZAE E7XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PhOLQ/F7J+2sphUowl9P4vwRtY+FxXOHsvwRgin0evk=; b=BzuIeNVBlAJMy3/jMDoiJPAufDT1pobs0nsCRGmXs53VOkumVpWUZ+Hl2d4oQgDp5T g5DY36rRx4irrgoWI6GpHR1rkv2ewiS1IK0mL53IRzaEU/cTLyOL2GtQuucejeNVhHY6 Mljvp/pP8Xi6RjRw6nVCty4N2zd0cQhfKUqKMDhRs9F/j1S0NT1VT2ycOYaR9GjQrdu7 k8LoH8CR9+MOmdwEZ+MvaU3Rg8X5+BhmPPJID9/JynkAgEAf3+jSCisIR9KhFQcAnb00 s/unVgv/oN9sI6BGozVOL8DCqA2agKaHqlItMtZeiulXA3L23z4PoRROxrQOUmNnTLQK oA5w== X-Gm-Message-State: AOAM533cKXdZgnhFdU0FRlueLdG7mu3gMfYfSen/sg2YgVpJcUabVpgJ zsW+wQtgVacTk/3HTLSvvTQ= X-Google-Smtp-Source: ABdhPJwf/izDyQzKSJzf1hjJEznws4GoqoGbO8gOts8s5E+Xb0j4JqNt8isF4fvY/LzfENgZYCu/Uw== X-Received: by 2002:a1c:3b87:: with SMTP id i129mr20512200wma.38.1589810406758; Mon, 18 May 2020 07:00:06 -0700 (PDT) Received: from localhost.localdomain ([2a01:598:b884:8d4:84ab:c471:b6eb:fcab]) by smtp.gmail.com with ESMTPSA id 81sm18114519wme.16.2020.05.18.07.00.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 May 2020 07:00:06 -0700 (PDT) From: Bean Huo To: miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, s.hauer@pengutronix.de, boris.brezillon@collabora.com, derosier@gmail.com Subject: [PATCH v4 5/5] mtd: rawnand: micron: Micron SLC NAND filling block Date: Mon, 18 May 2020 15:59:43 +0200 Message-Id: <20200518135943.11749-6-huobean@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200518135943.11749-1-huobean@gmail.com> References: <20200518135943.11749-1-huobean@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200518_070008_252271_E0E0D345 X-CRM114-Status: GOOD ( 15.37 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:342 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [huobean[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: huobean@gmail.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, Bean Huo MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Bean Huo On some legacy planar 2D Micron NAND devices when a block erase command is issued, occasionally even though a block erase operation completes and returns a pass status, the flash block may not be completely erased. Subsequent operations to this block on very rare cases can result in subtle failures or corruption. These extremely rare cases should nevertheless be considered. These rare occurrences have been observed on partially written blocks. To avoid this rare occurrence, we should make sure that at least 15 pages have been programmed to a block before it is erased. In case we find that less than 15 pages have been programmed, we will rewrite first 15 pages of block. Signed-off-by: Bean Huo --- drivers/mtd/nand/raw/nand_micron.c | 102 +++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c index b3485b0995ad..c5fd9e60f46d 100644 --- a/drivers/mtd/nand/raw/nand_micron.c +++ b/drivers/mtd/nand/raw/nand_micron.c @@ -36,6 +36,9 @@ #define NAND_ECC_STATUS_1_3_CORRECTED BIT(4) #define NAND_ECC_STATUS_7_8_CORRECTED (BIT(4) | BIT(3)) +#define MICRON_SHALLOW_ERASE_MIN_PAGE 15 +#define MICRON_PAGE_MASK_TRIGGER GENMASK(MICRON_SHALLOW_ERASE_MIN_PAGE, 0) + struct nand_onfi_vendor_micron { u8 two_plane_read; u8 read_cache; @@ -64,6 +67,7 @@ struct micron_on_die_ecc { struct micron_nand { struct micron_on_die_ecc ecc; + u16 *writtenp; }; static int micron_nand_setup_read_retry(struct nand_chip *chip, int retry_mode) @@ -429,6 +433,93 @@ static int micron_supports_on_die_ecc(struct nand_chip *chip) return MICRON_ON_DIE_SUPPORTED; } +static int micron_nand_pre_erase(struct nand_chip *chip, u32 eraseblock) +{ + struct micron_nand *micron = nand_get_manufacturer_data(chip); + struct mtd_info *mtd = nand_to_mtd(chip); + u8 last_page = MICRON_SHALLOW_ERASE_MIN_PAGE - 1; + u32 page; + u8 *data_buf; + int ret, i; + + data_buf = nand_get_data_buf(chip); + WARN_ON(!data_buf); + + if (likely(micron->writtenp[eraseblock] & BIT(last_page))) + return 0; + + page = eraseblock << (chip->phys_erase_shift - chip->page_shift); + + if (unlikely(micron->writtenp[eraseblock] == 0)) { + ret = nand_read_page_raw(chip, data_buf, 1, page + last_page); + if (ret) + return ret; /* Read error */ + ret = nand_check_is_erased_page(chip, data_buf, true); + if (!ret) + return 0; + } + + memset(data_buf, 0x00, mtd->writesize); + + for (i = 0; i < MICRON_SHALLOW_ERASE_MIN_PAGE; i++) { + ret = nand_write_page_raw(chip, data_buf, false, page + i); + if (ret) + return ret; + } + + return 0; +} + +static int micron_nand_post_erase(struct nand_chip *chip, u32 eraseblock) +{ + struct micron_nand *micron = nand_get_manufacturer_data(chip); + + if (!micron) + return -EINVAL; + + micron->writtenp[eraseblock] = 0; + + return 0; +} + +static int micron_nand_write_oob(struct nand_chip *chip, loff_t to, + struct mtd_oob_ops *ops) +{ + struct micron_nand *micron = nand_get_manufacturer_data(chip); + u32 eb_sz = nanddev_eraseblock_size(&chip->base); + u32 p_sz = nanddev_page_size(&chip->base); + u32 ppeb = nanddev_pages_per_eraseblock(&chip->base); + u32 nb_p_tot = ops->len / p_sz; + u32 first_eb = DIV_ROUND_DOWN_ULL(to, eb_sz); + u32 first_p = DIV_ROUND_UP_ULL(to - (first_eb * eb_sz), p_sz); + u32 nb_eb = DIV_ROUND_UP_ULL(first_p + nb_p_tot, ppeb); + u32 remaining_p, eb, nb_p; + int ret; + + ret = nand_write_oob_nand(chip, to, ops); + + if (ret || ops->len != ops->retlen) + return ret; + + /* Mark the last pages of the first erase block to write */ + nb_p = min(nb_p_tot, ppeb - first_p); + micron->writtenp[first_eb] |= GENMASK(first_p + nb_p, 0) & + MICRON_PAGE_MASK_TRIGGER; + remaining_p = nb_p_tot - nb_p; + + /* Mark all the pages of all "in-the-middle" erase blocks */ + for (eb = first_eb + 1; eb < first_eb + nb_eb - 1; eb++) { + micron->writtenp[eb] |= MICRON_PAGE_MASK_TRIGGER; + remaining_p -= ppeb; + } + + /* Mark the first pages of the last erase block to write */ + if (remaining_p) + micron->writtenp[eb] |= GENMASK(remaining_p - 1, 0) & + MICRON_PAGE_MASK_TRIGGER; + return 0; +} + static int micron_nand_init(struct nand_chip *chip) { struct mtd_info *mtd = nand_to_mtd(chip); @@ -515,6 +606,17 @@ static int micron_nand_init(struct nand_chip *chip) } } + if (nand_is_slc(chip)) { + micron->writtenp = kcalloc(nanddev_neraseblocks(&chip->base), + sizeof(u16), GFP_KERNEL); + if (!micron->writtenp) + goto err_free_manuf_data; + + chip->ops.write_oob = micron_nand_write_oob; + chip->ops.pre_erase = micron_nand_pre_erase; + chip->ops.post_erase = micron_nand_post_erase; + } + return 0; err_free_manuf_data: