From patchwork Thu Jun 21 10:33:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 932671 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 (mailfrom) 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=alliedtelesis.co.nz Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GysOLJaz"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="AYuZybFG"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41BJ4T0BPfz9s1B for ; Thu, 21 Jun 2018 20:35:21 +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=gEBG6KF5VWIpoqOhRsDeub+hj7QGgkPpW3MIAyloRfg=; b=GysOLJazekxaymu0AAQN0AVCf/ aR+5TvoAJ08G4pU2EDZLHh7UxRZ83smwbsyr6alRmhbxE3W+yec5j6PCSFoUfFaQeODTABBPYt0Xd aQZZWO4P4Cf/vi+EqXCr5vZAKUWfvDRacGo4rOXBSJRGwikRRBut6Vf9G+e7SnkIsnNZA9IeSDCrX cWdbVD0n5c2MhUVKqp6J8xEK6ExJhYU982WZeQGx2ETEVnSN0TL1NFT9STvWdoaNuoVorn9xeUpba QGvHwIniXqgS2YIjxchXovAH9sDQKglobyK9zlS+EAy9xR6y2xqSv93g+LEuj/5gJK6xca4xDToEF Znk603yQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVwvn-0004Ub-Hp; Thu, 21 Jun 2018 10:35:11 +0000 Received: from gate2.alliedtelesis.co.nz ([202.36.163.20]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fVwut-0003lS-Rl for linux-mtd@lists.infradead.org; Thu, 21 Jun 2018 10:34:19 +0000 Received: from mmarshal3.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 6D0FE8365A; Thu, 21 Jun 2018 22:33:41 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail; t=1529577221; bh=1FHpdOz1S8wmGyZiSv8ykuwHpjR2OIkWG10yzzFVs/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AYuZybFGf5roX8thZOGugi8oZzC1IFLaoTIaS9cvuayXw8pTAUfyF0yb/oicfHPYy SlA66Fp+p/MSPaL2yUqoPYUHL7UxP5d9qZYpj8poYNM4532yU/xDEUnAg/uocFP/7T Oypy1JSrc1CbF4Rj9tFyG7SnwMNs/sp1JcRsd1XA= Received: from smtp (Not Verified[10.32.16.33]) by mmarshal3.atlnz.lc with Trustwave SEG (v7, 5, 8, 10121) id ; Thu, 21 Jun 2018 22:33:41 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by smtp (Postfix) with ESMTP id 8FBF213EFC4; Thu, 21 Jun 2018 22:33:40 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 5BDC71E2626; Thu, 21 Jun 2018 22:33:37 +1200 (NZST) From: Chris Packham To: miquel.raynal@bootlin.com, boris.brezillon@bootlin.com, dwmw2@infradead.org, computersforpeace@gmail.com, linux-mtd@lists.infradead.org Subject: [PATCH v4 5/6] mtd: rawnand: micron: support 8/512 on-die ECC Date: Thu, 21 Jun 2018 22:33:27 +1200 Message-Id: <20180621103328.28206-6-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180621103328.28206-1-chris.packham@alliedtelesis.co.nz> References: <20180621103328.28206-1-chris.packham@alliedtelesis.co.nz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180621_033416_262115_F774B4EA X-CRM114-Status: GOOD ( 15.95 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [202.36.163.20 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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 X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Weinberger , Chris Packham , linux-kernel@vger.kernel.org, Marek Vasut MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Micron MT29F1G08ABAFAWP-ITE:F supports an on-die ECC with 8 bits per 512 bytes. Add support for this combination. Signed-off-by: Chris Packham --- Changes in v2: - New Changes in v3: - Handle reporting of corrected errors that don't require a rewrite, expand comment for the ECC status bits. Changes in v4: - Use a switch statement for handling ECC status - Update ecc_stats.corrected drivers/mtd/nand/raw/nand_micron.c | 68 ++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_micron.c b/drivers/mtd/nand/raw/nand_micron.c index d30bd4df9b12..f1ecd4986b50 100644 --- a/drivers/mtd/nand/raw/nand_micron.c +++ b/drivers/mtd/nand/raw/nand_micron.c @@ -18,10 +18,28 @@ #include /* - * Special Micron status bit that indicates when the block has been - * corrected by on-die ECC and should be rewritten + * Special Micron status bit 3 indicates that the block has been + * corrected by on-die ECC and should be rewritten. + * + * On chips with 8-bit ECC and additional bit can be used to distinguish + * cases where a errors were corrected without needing a rewrite + * + * Bit 4 Bit 3 Bit 0 Description + * ----- ----- ----- ----------- + * 0 0 0 No Errors + * 0 0 1 Multiple uncorrected errors + * 0 1 0 4 - 6 errors corrected, recommend rewrite + * 0 1 1 Reserved + * 1 0 0 1 - 3 errors corrected + * 1 0 1 Reserved + * 1 1 0 7 - 8 errors corrected, recommend rewrite */ -#define NAND_STATUS_WRITE_RECOMMENDED BIT(3) +#define NAND_STATUS_MASK (BIT(4) | BIT(3) | BIT(0)) +#define NAND_STATUS_NO_ERRORS 0 +#define NAND_STATUS_UNCORRECTABLE BIT(0) +#define NAND_STATUS_4_6_CORRECTED BIT(3) +#define NAND_STATUS_1_3_CORRECTED BIT(4) +#define NAND_STATUS_7_8_CORRECTED (BIT(4) | BIT(3)) struct nand_onfi_vendor_micron { u8 two_plane_read; @@ -137,18 +155,31 @@ micron_nand_read_page_on_die_ecc(struct mtd_info *mtd, struct nand_chip *chip, if (ret) goto out; - if (status & NAND_STATUS_FAIL) { + /* + * The internal ECC doesn't tell us the number of bitflips + * that have been corrected, but tells us if it recommends to + * rewrite the block. If it's the case, then we pretend we had + * a number of bitflips equal to the ECC strength, which will + * hint the NAND core to rewrite the block. + */ + switch (status & NAND_STATUS_MASK) { + case NAND_STATUS_UNCORRECTABLE: mtd->ecc_stats.failed++; - } else if (status & NAND_STATUS_WRITE_RECOMMENDED) { - /* - * The internal ECC doesn't tell us the number of bitflips - * that have been corrected, but tells us if it recommends to - * rewrite the block. If it's the case, then we pretend we had - * a number of bitflips equal to the ECC strength, which will - * hint the NAND core to rewrite the block. - */ - mtd->ecc_stats.corrected += chip->ecc.strength; + break; + case NAND_STATUS_1_3_CORRECTED: + mtd->ecc_stats.corrected++; + max_bitflips = 1; + break; + case NAND_STATUS_4_6_CORRECTED: + mtd->ecc_stats.corrected += 4; + /* rewrite recommended */ + max_bitflips = chip->ecc.strength; + break; + case NAND_STATUS_7_8_CORRECTED: + mtd->ecc_stats.corrected += 7; + /* rewrite recommended */ max_bitflips = chip->ecc.strength; + break; } ret = nand_read_data_op(chip, buf, mtd->writesize, false); @@ -239,13 +270,6 @@ static int micron_supports_on_die_ecc(struct nand_chip *chip) if (feature[0] & ONFI_FEATURE_ON_DIE_ECC_EN) return MICRON_ON_DIE_MANDATORY; - /* - * Some Micron NANDs have an on-die ECC of 4/512, some other - * 8/512. We only support the former. - */ - if (chip->ecc_strength_ds != 4) - return MICRON_ON_DIE_UNSUPPORTED; - return MICRON_ON_DIE_SUPPORTED; } @@ -275,9 +299,9 @@ static int micron_nand_init(struct nand_chip *chip) return -EINVAL; } - chip->ecc.bytes = 8; + chip->ecc.bytes = chip->ecc_strength_ds * 2; chip->ecc.size = 512; - chip->ecc.strength = 4; + chip->ecc.strength = chip->ecc_strength_ds; chip->ecc.algo = NAND_ECC_BCH; chip->ecc.read_page = micron_nand_read_page_on_die_ecc; chip->ecc.write_page = micron_nand_write_page_on_die_ecc;