From patchwork Tue Feb 12 00:25:54 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: katsuki.uwatoko@toshiba.co.jp X-Patchwork-Id: 219707 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6DA202C0292 for ; Tue, 12 Feb 2013 11:28:04 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U53hN-0000nB-7q; Tue, 12 Feb 2013 00:26:13 +0000 Received: from imx12.toshiba.co.jp ([61.202.160.132]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U53hI-0000mN-Ha for linux-mtd@lists.infradead.org; Tue, 12 Feb 2013 00:26:11 +0000 Received: from tsbmgw-mgw01.tsbmgw-mgw01.toshiba.co.jp ([133.199.232.103]) by imx12.toshiba.co.jp with ESMTP id r1C0Q0Hm006973 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 12 Feb 2013 09:26:01 +0900 (JST) Received: from tsbmgw-mgw01 (localhost [127.0.0.1]) by tsbmgw-mgw01.tsbmgw-mgw01.toshiba.co.jp (8.13.8/8.14.5) with ESMTP id r1C0Q02Y016283; Tue, 12 Feb 2013 09:26:00 +0900 Received: from localhost ([127.0.0.1]) by tsbmgw-mgw01 (JAMES SMTP Server 2.3.1) with SMTP ID 565; Tue, 12 Feb 2013 09:26:00 +0900 (JST) Received: from arc11.toshiba.co.jp ([133.199.90.127]) by tsbmgw-mgw01.tsbmgw-mgw01.toshiba.co.jp (8.13.8/8.14.5) with ESMTP id r1C0Q0Jf016280; Tue, 12 Feb 2013 09:26:00 +0900 Received: (from root@localhost) by arc11.toshiba.co.jp id r1C0Q09E013877; Tue, 12 Feb 2013 09:26:00 +0900 (JST) Received: from ovp11.toshiba.co.jp [133.199.90.148] by arc11.toshiba.co.jp with ESMTP id KAA13876; Tue, 12 Feb 2013 09:26:00 +0900 Received: from mx.toshiba.co.jp (localhost [127.0.0.1]) by ovp11.toshiba.co.jp with ESMTP id r1C0PxoF006352; Tue, 12 Feb 2013 09:26:00 +0900 (JST) Received: from tgxml307.toshiba.local by toshiba.co.jp id r1C0Pi8J013526; Tue, 12 Feb 2013 09:25:59 +0900 (JST) Received: from TGXML316.toshiba.local ([169.254.4.113]) by tgxml307.toshiba.local ([133.199.66.202]) with mapi id 14.02.0318.004; Tue, 12 Feb 2013 09:25:54 +0900 From: To: Subject: [PATCH] mtd: nand: support BENAND (Built-in ECC NAND) Thread-Topic: [PATCH] mtd: nand: support BENAND (Built-in ECC NAND) Thread-Index: AQHOCLeFY58r5dA6rkeqRIy7rnDdOw== Date: Tue, 12 Feb 2013 00:25:54 +0000 Message-ID: Accept-Language: ja-JP, en-US Content-Language: en-US x-originating-ip: [133.114.87.204] msscp.transfermailtomossagent: 103 Content-ID: <64C8DD7EA6537B43ABF55906E74CAC28@toshiba.local> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130211_192609_153220_D8C3713B X-CRM114-Status: GOOD ( 27.62 ) X-Spam-Score: -7.6 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [61.202.160.132 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines Cc: dedekind1@gmail.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This enables support for BENAND, which is an SLC NAND flash solution with embedded error correction code (ECC), currently supports only 128bytes OOB type. In the read sequence, "status read command" is executed to check the ECC status after read data. If bitflips occur, these are automatically corrected by BENAND and the status indicates the result. The write sequence is the same as raw write and the ECC data are automatically written to OOB by BENAND. Signed-off-by: UWATOKO Katsuki --- drivers/mtd/nand/Kconfig | 11 ++++ drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/nand_base.c | 25 +++++++++ drivers/mtd/nand/nand_benand.c | 113 +++++++++++++++++++++++++++++++++++++++ include/linux/mtd/nand.h | 2 + include/linux/mtd/nand_benand.h | 47 ++++++++++++++++ 6 files changed, 199 insertions(+), 0 deletions(-) create mode 100644 drivers/mtd/nand/nand_benand.c create mode 100644 include/linux/mtd/nand_benand.h diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig index 4883139..acf0c25 100644 --- a/drivers/mtd/nand/Kconfig +++ b/drivers/mtd/nand/Kconfig @@ -37,6 +37,17 @@ config MTD_NAND_ECC_BCH ECC codes. They are used with NAND devices requiring more than 1 bit of error correction. +config MTD_NAND_BENAND + bool "Support BENAND (embedded ECC NAND)" + default n + help + This enables support for BENAND, which is an SLC NAND flash + solution with embedded error correction code (ECC). + currently supports only 128bytes OOB type. + In the read sequence, "status read command" is executed to check + the ECC status after read data. + The write sequence is the same as raw write. + config MTD_SM_COMMON tristate default n diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index 2cbd091..f58dee8 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_MTD_NAND) += nand.o obj-$(CONFIG_MTD_NAND_ECC) += nand_ecc.o obj-$(CONFIG_MTD_NAND_BCH) += nand_bch.o +obj-$(CONFIG_MTD_NAND_BENAND) += nand_benand.o obj-$(CONFIG_MTD_NAND_IDS) += nand_ids.o obj-$(CONFIG_MTD_SM_COMMON) += sm_common.o diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 1a03b7f..2b0c178 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -3076,6 +3077,11 @@ static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, extid >>= 2; /* Get buswidth information */ *busw = (extid & 0x01) ? NAND_BUSWIDTH_16 : 0; + + /* check BENAND (embedded ECC) */ + if (id_data[0] == NAND_MFR_TOSHIBA && + (id_data[4] & 1 << 7)) + nand_benand_setupecc(mtd, &(chip->ecc.mode)); } } @@ -3530,6 +3536,25 @@ int nand_scan_tail(struct mtd_info *mtd) chip->ecc.bytes * 8 / fls(8 * chip->ecc.size); break; + case NAND_ECC_BENAND: + if (!mtd_nand_has_benand()) { + pr_warn("CONFIG_MTD_BENAND not enabled\n"); + BUG(); + } + + chip->ecc.read_page = nand_read_page_benand; + chip->ecc.write_page = nand_write_page_raw; + chip->ecc.read_page_raw = nand_read_page_raw; + chip->ecc.write_page_raw = nand_write_page_raw; + chip->ecc.read_oob = nand_read_oob_std; + chip->ecc.write_oob = nand_write_oob_std; + + if (nand_benand_init(mtd)) { + pr_warn("BENAND initialization failed!\n"); + BUG(); + } + break; + case NAND_ECC_NONE: pr_warn("NAND_ECC_NONE selected by board driver. " "This is not recommended!\n"); diff --git a/drivers/mtd/nand/nand_benand.c b/drivers/mtd/nand/nand_benand.c new file mode 100644 index 0000000..fe8008d --- /dev/null +++ b/drivers/mtd/nand/nand_benand.c @@ -0,0 +1,113 @@ +/* + * This file provides functions for BENAND, which is an SLC NAND flash + * solution with embedded error correction code (ECC). + * + * (C) Copyright TOSHIBA CORPORATION 2013 + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static struct nand_ecclayout benand_oob_128 = { + .oobfree = { + {.offset = 2, .length = 3}, + {.offset = 18, .length = 3}, + {.offset = 34, .length = 3}, + {.offset = 50, .length = 3}, + {.offset = 66, .length = 3}, + {.offset = 82, .length = 3}, + {.offset = 98, .length = 3}, + {.offset = 114, .length = 3}, + } +}; + +/** + * nand_read_page_raw - [Intern] read raw page data with benand. + * @mtd: mtd info structure + * @chip: nand chip info structure + * @buf: buffer to store read data + * @oob_required: caller requires OOB data read to chip->oob_poi + * @page: page number to read + * + * Not for syndrome calculating ECC controllers, which use a special oob layout. + */ + +int nand_read_page_benand(struct mtd_info *mtd, struct nand_chip *chip, + uint8_t *buf, int oob_required, int page) +{ + u8 status; + unsigned int max_bitflips = 0; + + chip->ecc.read_page_raw(mtd, chip, buf, oob_required, page); + + /* Check Read Status */ + + chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); + status = chip->read_byte(mtd); + + if (status & NAND_STATUS_FAIL) + /* uncorrectable error */ + mtd->ecc_stats.failed++; + else if (status & NAND_CHIP_READ_STATUS) { + /* correctable error + How many bits have been corrected is unknown. + therefore bitflips is set to ecc.strength. */ + mtd->ecc_stats.corrected += chip->ecc.strength; + max_bitflips = chip->ecc.strength; + } + + return max_bitflips; +} +EXPORT_SYMBOL(nand_read_page_benand); + +void nand_benand_setupecc(struct mtd_info *mtd, nand_ecc_modes_t *mode) +{ + /* support only 128bytes OOB type */ + if (mtd->oobsize == 128) + *mode = NAND_ECC_BENAND; +} + +int nand_benand_init(struct mtd_info *mtd) +{ + struct nand_chip *chip = mtd->priv; + + chip->ecc.size = mtd->writesize; + + if (mtd->oobsize == 128) { + chip->ecc.layout = &benand_oob_128; + chip->ecc.bytes = 72; /* 9B * (4096B/512B) */ + chip->ecc.strength = 32; /* 4b * (4096B/512B) */ + } else { + pr_warn("%d unsupported oobsize in benand_init\n", + mtd->oobsize); + return -EINVAL; + } + + return 0; +} +EXPORT_SYMBOL(nand_benand_init); + +MODULE_AUTHOR("TOSHIBA Corporation"); +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("BENAND (embedded ECC NAND) support"); diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 24e9159..2163ae9 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -129,6 +129,7 @@ extern int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len); /* Status bits */ #define NAND_STATUS_FAIL 0x01 #define NAND_STATUS_FAIL_N1 0x02 +#define NAND_CHIP_READ_STATUS 0x08 /* for BENAND */ #define NAND_STATUS_TRUE_READY 0x20 #define NAND_STATUS_READY 0x40 #define NAND_STATUS_WP 0x80 @@ -143,6 +144,7 @@ typedef enum { NAND_ECC_HW_SYNDROME, NAND_ECC_HW_OOB_FIRST, NAND_ECC_SOFT_BCH, + NAND_ECC_BENAND, } nand_ecc_modes_t; /* diff --git a/include/linux/mtd/nand_benand.h b/include/linux/mtd/nand_benand.h new file mode 100644 index 0000000..ac043e5 --- /dev/null +++ b/include/linux/mtd/nand_benand.h @@ -0,0 +1,47 @@ +/* + * (C) Copyright TOSHIBA CORPORATION 2013 + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This file is the header for the NAND BENAND implementation. + */ + +#ifndef __MTD_NAND_BENAND_H__ +#define __MTD_NAND_BENAND_H__ + +#if defined(CONFIG_MTD_NAND_BENAND) + +static inline int mtd_nand_has_benand(void) { return 1; } + +void nand_benand_setupecc(struct mtd_info *mtd, nand_ecc_modes_t *mode); + +int nand_read_page_benand(struct mtd_info *mtd, struct nand_chip *chip, + uint8_t *buf, int oob_required, int page); + +int nand_benand_init(struct mtd_info *mtd); + +#else /* !CONFIG_MTD_NAND_BENAND */ + +static inline int mtd_nand_has_benand(void) { return 0; } + +static inline void nand_benand_setupecc(struct mtd_info *mtd, + nand_ecc_modes_t *mode) {} + +static inline int nand_read_page_benand(struct mtd_info *mtd, + struct nand_chip *chip, + uint8_t *buf, int oob_required, + int page) +{ + return -1; +} + +static inline int nand_benand_init(struct mtd_info *mtd) +{ + return -1; +} + +#endif /* CONFIG_MTD_NAND_BENAND */ +#endif /* __MTD_NAND_BENAND_H__ */