Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4004395imm; Mon, 14 May 2018 00:49:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZozf5UwxWvt659pk6MZqdUR6Oc1Q4sLe49DmVEfND3/8sblZnJPf81A0nAaswl+uq3y77Nx X-Received: by 2002:a63:bc0a:: with SMTP id q10-v6mr5922913pge.141.1526284173712; Mon, 14 May 2018 00:49:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526284173; cv=none; d=google.com; s=arc-20160816; b=r1BXCeVxhFtKeFP3TZ4RcN3NVxMkqMLT3V+Y0DPVsFvWt4mOzvIX0VzOKQVrJBJfa0 MOwz1ZPUkxqMRCtELAdGcFJ3fSyHl9zmQAXcnc+A8LLjVuqbU0g03fvBiRMb13nw+D8A NS4Uk4CDFBNNkP4jXOgkmtg7O4i06I5NmT7DekE0+dPNvqG7VWFtzAH1jyiB6XCyFLEO y4x85w0lDBpju+A+KIw5tnLk3PuoWEvD19ldKOILjpwJUU/xtt2nz18V3TMmS1VANLj8 rYbfoysWtjLAfRmCy5+L994qXhOA54OwR+xIkrJid2x0BkvqRXQhcOVsKiD4SOLQ7CiF XJSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=4bpoFyvsKVejTAK8I0RH8f2hTvLWdLc61EGijFdqck0=; b=KhcHAk2IAfP2+eR3IZ6m2kANac+212qXDTb46k9pIrp4Gr99asBHyilU7+6ZDlPDsQ 8lUMijCqTEQIwvknECnsNP3Vx8cvamACoW1YMUfsH5/WXIN7lO1vVwnS8DzSMYL68P7/ sqP5rja2Qts7Q4EAc0S9y6ZzOlLLeWGPDsnHLKKxFHH7vPlrtYuqoEloAPMROYHaYgNQ J7FuCPUIWfH6TRvaBEy3IEepAzcEymOvZWTRscb+QxWwv/xoKhLOABNjxpsuSXGHzYNi MC20kt0zrYR9tq33iW7I25JMqocDmEHMnQFfQVZnomxhBEH0PYLSiVzAnkrsrEKeWaxD BhjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XciqZukR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x191-v6si7709894pgx.83.2018.05.14.00.49.19; Mon, 14 May 2018 00:49:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XciqZukR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752576AbeENHtI (ORCPT + 99 others); Mon, 14 May 2018 03:49:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:57722 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751927AbeENGvA (ORCPT ); Mon, 14 May 2018 02:51:00 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A87B721746; Mon, 14 May 2018 06:50:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526280660; bh=uWlPBlX8AvIjlD+5BkCRbLnycH++0GzA5sce8/eaHEg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XciqZukRPvEH3JVRNM9MAwR7spj5tNJJBNaeyReLALcTUMkbS4zGxhfjz4pb+0fSY /iKC4ebc9J3gTKQI4xeTRZow/4Pmi0nD8aNrUZzpgmYI+JcPZ2K39+IBXNx7jtLvTD O6GMSWJ4wmdwOsfcgHOvT2bsu3alDHwxCWN+0kOg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Markus Pargmann , Stefan Christ , Han xu , Boris Brezillon , Sascha Hauer Subject: [PATCH 4.4 10/56] gpmi-nand: Handle ECC Errors in erased pages Date: Mon, 14 May 2018 08:48:15 +0200 Message-Id: <20180514064756.042499971@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514064754.853201981@linuxfoundation.org> References: <20180514064754.853201981@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Markus Pargmann commit bd2e778c9ee361c23ccb2b10591712e129d97893 upstream. ECC is only calculated for written pages. As erased pages are not actively written the ECC is always invalid. For this purpose the Hardware BCH unit is able to check for erased pages and does not raise an ECC error in this case. This behaviour can be influenced using the BCH_MODE register which sets the number of allowed bitflips in an erased page. Unfortunately the unit is not capable of fixing the bitflips in memory. To avoid complete software checks for erased pages, we can simply check buffers with uncorrectable ECC errors because we know that any erased page with errors is uncorrectable by the BCH unit. This patch adds the generic nand_check_erased_ecc_chunk() to gpmi-nand to correct erased pages. To have the valid data in the buffer before using them, this patch moves the read_page_swap_end() call before the ECC status checking for-loop. Signed-off-by: Markus Pargmann [Squashed patches by Stefan and Boris to check ECC area] Tested-by: Stefan Christ Acked-by: Han xu Signed-off-by: Boris Brezillon Cc: Sascha Hauer Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/nand/gpmi-nand/gpmi-nand.c | 78 ++++++++++++++++++++++++++++++--- 1 file changed, 73 insertions(+), 5 deletions(-) --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c @@ -1032,14 +1032,87 @@ static int gpmi_ecc_read_page(struct mtd /* Loop over status bytes, accumulating ECC status. */ status = auxiliary_virt + nfc_geo->auxiliary_status_offset; + read_page_swap_end(this, buf, nfc_geo->payload_size, + this->payload_virt, this->payload_phys, + nfc_geo->payload_size, + payload_virt, payload_phys); + for (i = 0; i < nfc_geo->ecc_chunk_count; i++, status++) { if ((*status == STATUS_GOOD) || (*status == STATUS_ERASED)) continue; if (*status == STATUS_UNCORRECTABLE) { + int eccbits = nfc_geo->ecc_strength * nfc_geo->gf_len; + u8 *eccbuf = this->raw_buffer; + int offset, bitoffset; + int eccbytes; + int flips; + + /* Read ECC bytes into our internal raw_buffer */ + offset = nfc_geo->metadata_size * 8; + offset += ((8 * nfc_geo->ecc_chunk_size) + eccbits) * (i + 1); + offset -= eccbits; + bitoffset = offset % 8; + eccbytes = DIV_ROUND_UP(offset + eccbits, 8); + offset /= 8; + eccbytes -= offset; + chip->cmdfunc(mtd, NAND_CMD_RNDOUT, offset, -1); + chip->read_buf(mtd, eccbuf, eccbytes); + + /* + * ECC data are not byte aligned and we may have + * in-band data in the first and last byte of + * eccbuf. Set non-eccbits to one so that + * nand_check_erased_ecc_chunk() does not count them + * as bitflips. + */ + if (bitoffset) + eccbuf[0] |= GENMASK(bitoffset - 1, 0); + + bitoffset = (bitoffset + eccbits) % 8; + if (bitoffset) + eccbuf[eccbytes - 1] |= GENMASK(7, bitoffset); + + /* + * The ECC hardware has an uncorrectable ECC status + * code in case we have bitflips in an erased page. As + * nothing was written into this subpage the ECC is + * obviously wrong and we can not trust it. We assume + * at this point that we are reading an erased page and + * try to correct the bitflips in buffer up to + * ecc_strength bitflips. If this is a page with random + * data, we exceed this number of bitflips and have a + * ECC failure. Otherwise we use the corrected buffer. + */ + if (i == 0) { + /* The first block includes metadata */ + flips = nand_check_erased_ecc_chunk( + buf + i * nfc_geo->ecc_chunk_size, + nfc_geo->ecc_chunk_size, + eccbuf, eccbytes, + auxiliary_virt, + nfc_geo->metadata_size, + nfc_geo->ecc_strength); + } else { + flips = nand_check_erased_ecc_chunk( + buf + i * nfc_geo->ecc_chunk_size, + nfc_geo->ecc_chunk_size, + eccbuf, eccbytes, + NULL, 0, + nfc_geo->ecc_strength); + } + + if (flips > 0) { + max_bitflips = max_t(unsigned int, max_bitflips, + flips); + mtd->ecc_stats.corrected += flips; + continue; + } + mtd->ecc_stats.failed++; continue; } + mtd->ecc_stats.corrected += *status; max_bitflips = max_t(unsigned int, max_bitflips, *status); } @@ -1062,11 +1135,6 @@ static int gpmi_ecc_read_page(struct mtd chip->oob_poi[0] = ((uint8_t *) auxiliary_virt)[0]; } - read_page_swap_end(this, buf, nfc_geo->payload_size, - this->payload_virt, this->payload_phys, - nfc_geo->payload_size, - payload_virt, payload_phys); - return max_bitflips; }