From patchwork Thu Feb 21 06:17:07 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: 222186 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 845602C008C for ; Thu, 21 Feb 2013 17:18:15 +1100 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U8PT7-0006XX-0f; Thu, 21 Feb 2013 06:17:21 +0000 Received: from inet-tsb5.toshiba.co.jp ([202.33.96.24] helo=imx2.toshiba.co.jp) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U8PT2-0006Wx-Lp for linux-mtd@lists.infradead.org; Thu, 21 Feb 2013 06:17:19 +0000 Received: from tsbmgw-mgw02.tsbmgw-mgw02.toshiba.co.jp ([133.199.200.50]) by imx2.toshiba.co.jp with ESMTP id r1L6HAZj004540 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 21 Feb 2013 15:17:10 +0900 (JST) Received: from tsbmgw-mgw02 (localhost [127.0.0.1]) by tsbmgw-mgw02.tsbmgw-mgw02.toshiba.co.jp (8.13.8/8.14.5) with ESMTP id r1L6HA2Q015548; Thu, 21 Feb 2013 15:17:10 +0900 Received: from localhost ([127.0.0.1]) by tsbmgw-mgw02 (JAMES SMTP Server 2.3.1) with SMTP ID 928; Thu, 21 Feb 2013 15:17:09 +0900 (JST) Received: from arc1.toshiba.co.jp ([133.199.194.235]) by tsbmgw-mgw02.tsbmgw-mgw02.toshiba.co.jp (8.13.8/8.14.5) with ESMTP id r1L6H9D6015545; Thu, 21 Feb 2013 15:17:09 +0900 Received: (from root@localhost) by arc1.toshiba.co.jp id r1L6H9LG012971; Thu, 21 Feb 2013 15:17:09 +0900 (JST) Received: from unknown [133.199.192.144] by arc1.toshiba.co.jp with ESMTP id RAA12969; Thu, 21 Feb 2013 15:17:09 +0900 Received: from mx2.toshiba.co.jp (localhost [127.0.0.1]) by ovp2.toshiba.co.jp with ESMTP id r1L6H9VW007941; Thu, 21 Feb 2013 15:17:09 +0900 (JST) Received: from tgxml329.toshiba.local by toshiba.co.jp id r1L6H80Z028525; Thu, 21 Feb 2013 15:17:09 +0900 (JST) Received: from TGXML341.toshiba.local ([169.254.3.10]) by tgxml329.toshiba.local ([133.199.60.16]) with mapi id 14.02.0328.009; Thu, 21 Feb 2013 15:17:08 +0900 From: To: Subject: [PATCH v2] mtd: nand: support BENAND (Built-in ECC NAND) Thread-Topic: [PATCH v2] mtd: nand: support BENAND (Built-in ECC NAND) Thread-Index: AQHOD/sTNDND7tlbj0mCqly3gFgSzw== Date: Thu, 21 Feb 2013 06:17:07 +0000 Message-ID: Accept-Language: ja-JP, en-US Content-Language: en-US x-originating-ip: [133.199.67.39] msscp.transfermailtomossagent: 103 Content-ID: <00EE9C442EC19D47924A2300411A14C2@toshiba.local> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130221_011717_093017_F3DAA136 X-CRM114-Status: GOOD ( 28.60 ) X-Spam-Score: -4.9 (----) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-4.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [202.33.96.24 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: vikram186@gmail.com, 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 | 7 +++ include/linux/mtd/nand_benand.h | 43 +++++++++++++++ 6 files changed, 200 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..9cbef8c 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] & NAND_ECCENGINE)) + 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 (!IS_ENABLED(CONFIG_MTD_NAND_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..b01c4bf 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; /* @@ -575,6 +577,11 @@ struct nand_chip { #define NAND_MFR_MACRONIX 0xc2 #define NAND_MFR_EON 0x92 +/* + * 5th ID Data + */ +#define NAND_ECCENGINE (1<<7) /* ECC engine on chip */ + /** * struct nand_flash_dev - NAND Flash Device ID Structure * @name: Identify the device type diff --git a/include/linux/mtd/nand_benand.h b/include/linux/mtd/nand_benand.h new file mode 100644 index 0000000..a047b6f --- /dev/null +++ b/include/linux/mtd/nand_benand.h @@ -0,0 +1,43 @@ +/* + * (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) + +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 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__ */