From patchwork Sat Nov 2 09:46:16 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pekon gupta X-Patchwork-Id: 287959 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E85022C00E9 for ; Sat, 2 Nov 2013 20:47:55 +1100 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VcXns-0006Ym-RA; Sat, 02 Nov 2013 09:47:37 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VcXng-0007LP-6O; Sat, 02 Nov 2013 09:47:24 +0000 Received: from arroyo.ext.ti.com ([192.94.94.40]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VcXnV-0007IP-J7 for linux-mtd@lists.infradead.org; Sat, 02 Nov 2013 09:47:16 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id rA29kprY027399; Sat, 2 Nov 2013 04:46:51 -0500 Received: from DLEE71.ent.ti.com ([157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id rA29kpSw000324; Sat, 2 Nov 2013 04:46:51 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.2.342.3; Sat, 2 Nov 2013 04:46:51 -0500 Received: from psplinux063.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id rA29kelk022995; Sat, 2 Nov 2013 04:46:49 -0500 From: Pekon Gupta To: , Subject: [PATCH v3 4/4] mtd: devices: elm: add checks ELM H/W constrains, driver code cleanup Date: Sat, 2 Nov 2013 15:16:16 +0530 Message-ID: <1383385576-26095-5-git-send-email-pekon@ti.com> X-Mailer: git-send-email 1.8.1 In-Reply-To: <1383385576-26095-1-git-send-email-pekon@ti.com> References: <1383385576-26095-1-git-send-email-pekon@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131102_054713_853556_AA9AA47C X-CRM114-Status: GOOD ( 20.56 ) X-Spam-Score: -7.4 (-------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-7.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.94.94.40 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.5 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] Cc: linux-mtd@lists.infradead.org, Pekon Gupta , balbi@ti.com X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org ELM H/W engine is used by BCHx_ECC schemes for detecting and locating bit-flips. However, ELM H/W engine has some constrains like: - ELM can decode errors in chunks of 512 data bytes only - ELM can operate max upto 8 such buffers in parallel This patch - add checks for above constrains - fixes ELM register configs based on number of info->eccsteps - cleans-up elm_load_syndrome() Signed-off-by: Pekon Gupta --- drivers/mtd/devices/elm.c | 122 ++++++++++++++++++++++---------------- drivers/mtd/nand/omap2.c | 2 +- include/linux/platform_data/elm.h | 6 +- 3 files changed, 77 insertions(+), 53 deletions(-) diff --git a/drivers/mtd/devices/elm.c b/drivers/mtd/devices/elm.c index d1dd6a3..2167384 100644 --- a/drivers/mtd/devices/elm.c +++ b/drivers/mtd/devices/elm.c @@ -22,8 +22,11 @@ #include #include #include +#include +#include #include +#define DRIVER_NAME "omap-elm" #define ELM_SYSCONFIG 0x010 #define ELM_IRQSTATUS 0x018 #define ELM_IRQENABLE 0x01c @@ -82,8 +85,10 @@ struct elm_info { void __iomem *elm_base; struct completion elm_completion; struct list_head list; + struct mtd_info *mtd; enum bch_ecc bch_type; struct elm_registers elm_regs; + int eccsteps; }; static LIST_HEAD(elm_devices); @@ -103,19 +108,42 @@ static u32 elm_read_reg(struct elm_info *info, int offset) * @dev: ELM device * @bch_type: Type of BCH ecc */ -int elm_config(struct device *dev, enum bch_ecc bch_type) +int elm_config(struct device *dev, struct mtd_info *mtd, + enum bch_ecc bch_type) { u32 reg_val; - struct elm_info *info = dev_get_drvdata(dev); - + struct elm_info *info; + struct nand_chip *chip; + if (!dev) { + pr_err("%s: ELM device not found\n", DRIVER_NAME); + return -ENODEV; + } + info = dev_get_drvdata(dev); if (!info) { - dev_err(dev, "Unable to configure elm - device not probed?\n"); + pr_err("%s: ELM device data not found\n", DRIVER_NAME); return -ENODEV; } - + if (!mtd) { + pr_err("%s: MTD device not found\n", DRIVER_NAME); + return -ENODEV; + } + chip = mtd->priv; + /* ELM supports error correction in chunks of 512bytes of data only + * where each 512bytes of data has its own ECC syndrome */ + if (chip->ecc.size != 512) { + pr_err("%s: invalid ecc_size configuration", DRIVER_NAME); + return -EINVAL; + } + if (mtd->writesize > 4096) { + pr_err("%s: page-size > 4096 is not supported", DRIVER_NAME); + return -EINVAL; + } + /* ELM eccsteps required to decode complete NAND page */ + info->mtd = mtd; + info->bch_type = bch_type; + info->eccsteps = mtd->writesize / chip->ecc.size; reg_val = (bch_type & ECC_BCH_LEVEL_MASK) | (ELM_ECC_SIZE << 16); elm_write_reg(info, ELM_LOCATION_CONFIG, reg_val); - info->bch_type = bch_type; return 0; } @@ -152,55 +180,51 @@ static void elm_configure_page_mode(struct elm_info *info, int index, * Load syndrome fragment registers with calculated ecc in reverse order. */ static void elm_load_syndrome(struct elm_info *info, - struct elm_errorvec *err_vec, u8 *ecc) + struct elm_errorvec *err_vec, u8 *ecc_calc) { + struct nand_chip *chip = info->mtd->priv; + unsigned int eccbytes = chip->ecc.bytes; + u8 *ecc = ecc_calc; int i, offset; u32 val; - for (i = 0; i < ERROR_VECTOR_MAX; i++) { - + for (i = 0; i < info->eccsteps; i++) { /* Check error reported */ if (err_vec[i].error_reported) { elm_configure_page_mode(info, i, true); - offset = ELM_SYNDROME_FRAGMENT_0 + - SYNDROME_FRAGMENT_REG_SIZE * i; - - /* BCH8 */ - if (info->bch_type) { - - /* syndrome fragment 0 = ecc[9-12B] */ - val = cpu_to_be32(*(u32 *) &ecc[9]); - elm_write_reg(info, offset, val); - - /* syndrome fragment 1 = ecc[5-8B] */ - offset += 4; - val = cpu_to_be32(*(u32 *) &ecc[5]); - elm_write_reg(info, offset, val); - - /* syndrome fragment 2 = ecc[1-4B] */ - offset += 4; - val = cpu_to_be32(*(u32 *) &ecc[1]); - elm_write_reg(info, offset, val); - - /* syndrome fragment 3 = ecc[0B] */ - offset += 4; - val = ecc[0]; - elm_write_reg(info, offset, val); - } else { - /* syndrome fragment 0 = ecc[20-52b] bits */ - val = (cpu_to_be32(*(u32 *) &ecc[3]) >> 4) | - ((ecc[2] & 0xf) << 28); - elm_write_reg(info, offset, val); - - /* syndrome fragment 1 = ecc[0-20b] bits */ - offset += 4; - val = cpu_to_be32(*(u32 *) &ecc[0]) >> 12; - elm_write_reg(info, offset, val); + offset = SYNDROME_FRAGMENT_REG_SIZE * i; + ecc = ecc_calc + (i * eccbytes); + switch (info->bch_type) { + case BCH4_ECC: + val = ((*(ecc + 6) >> 4) & 0x0F) | + *(ecc + 5) << 4 | *(ecc + 4) << 12 | + *(ecc + 3) << 20 | *(ecc + 2) << 28; + elm_write_reg(info, (ELM_SYNDROME_FRAGMENT_0 + + offset), cpu_to_le32(val)); + val = ((*(ecc + 2) >> 4) & 0x0F) | + *(ecc + 1) << 4 | *(ecc + 0) << 12; + elm_write_reg(info, (ELM_SYNDROME_FRAGMENT_1 + + offset), cpu_to_le32(val)); + break; + case BCH8_ECC: + val = *(ecc + 12) << 0 | *(ecc + 11) << 8 | + *(ecc + 10) << 16 | *(ecc + 9) << 24; + elm_write_reg(info, (ELM_SYNDROME_FRAGMENT_0 + + offset), cpu_to_le32(val)); + val = *(ecc + 8) << 0 | *(ecc + 7) << 8 | + *(ecc + 6) << 16 | *(ecc + 5) << 24; + elm_write_reg(info, (ELM_SYNDROME_FRAGMENT_1 + + offset), cpu_to_le32(val)); + val = *(ecc + 4) << 0 | *(ecc + 3) << 8 | + *(ecc + 2) << 16 | *(ecc + 1) << 24; + elm_write_reg(info, (ELM_SYNDROME_FRAGMENT_2 + + offset), cpu_to_le32(val)); + val = *(ecc + 0) << 0 & 0x000000FF; + elm_write_reg(info, (ELM_SYNDROME_FRAGMENT_3 + + offset), cpu_to_le32(val)); + break; } } - - /* Update ecc pointer with ecc byte size */ - ecc += info->bch_type ? BCH8_SIZE : BCH4_SIZE; } } @@ -223,7 +247,7 @@ static void elm_start_processing(struct elm_info *info, * Set syndrome vector valid, so that ELM module * will process it for vectors error is reported */ - for (i = 0; i < ERROR_VECTOR_MAX; i++) { + for (i = 0; i < info->eccsteps; i++) { if (err_vec[i].error_reported) { offset = ELM_SYNDROME_FRAGMENT_6 + SYNDROME_FRAGMENT_REG_SIZE * i; @@ -252,7 +276,7 @@ static void elm_error_correction(struct elm_info *info, int offset; u32 reg_val; - for (i = 0; i < ERROR_VECTOR_MAX; i++) { + for (i = 0; i < info->eccsteps; i++) { /* Check error reported */ if (err_vec[i].error_reported) { @@ -263,14 +287,12 @@ static void elm_error_correction(struct elm_info *info, if (reg_val & ECC_CORRECTABLE_MASK) { offset = ELM_ERROR_LOCATION_0 + ERROR_LOCATION_SIZE * i; - /* Read count of correctable errors */ err_vec[i].error_count = reg_val & ECC_NB_ERRORS_MASK; /* Update the error locations in error vector */ for (j = 0; j < err_vec[i].error_count; j++) { - reg_val = elm_read_reg(info, offset); err_vec[i].error_loc[j] = reg_val & ECC_ERROR_LOCATION_MASK; diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c index 3a99e29..037e9e7 100644 --- a/drivers/mtd/nand/omap2.c +++ b/drivers/mtd/nand/omap2.c @@ -1391,7 +1391,7 @@ static int is_elm_present(struct omap_nand_info *info, } /* ELM module available, now configure it */ info->elm_dev = &pdev->dev; - if (elm_config(info->elm_dev, bch_type)) + if (elm_config(info->elm_dev, &info->mtd, bch_type)) return -ENODEV; return 0; } diff --git a/include/linux/platform_data/elm.h b/include/linux/platform_data/elm.h index bf0a83b..d16465b 100644 --- a/include/linux/platform_data/elm.h +++ b/include/linux/platform_data/elm.h @@ -25,6 +25,7 @@ enum bch_ecc { /* ELM support 8 error syndrome process */ #define ERROR_VECTOR_MAX 8 +#define ELM_MAX_DETECTABLE_ERRORS 16 #define BCH8_ECC_OOB_BYTES 13 #define BCH4_ECC_OOB_BYTES 7 @@ -45,10 +46,11 @@ struct elm_errorvec { bool error_reported; bool error_uncorrectable; int error_count; - int error_loc[ERROR_VECTOR_MAX]; + int error_loc[ELM_MAX_DETECTABLE_ERRORS]; }; void elm_decode_bch_error_page(struct device *dev, u8 *ecc_calc, struct elm_errorvec *err_vec); -int elm_config(struct device *dev, enum bch_ecc bch_type); +int elm_config(struct device *dev, struct mtd_info *mtd, + enum bch_ecc bch_type); #endif /* __ELM_H */