From patchwork Thu Mar 23 00:17:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 95876 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp497920qgd; Wed, 22 Mar 2017 17:36:42 -0700 (PDT) X-Received: by 10.99.177.6 with SMTP id r6mr47074461pgf.61.1490229402632; Wed, 22 Mar 2017 17:36:42 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id d2si3537718pgf.249.2017.03.22.17.36.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Mar 2017 17:36:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) client-ip=65.50.211.133; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.infradead.org; dkim=neutral (body hash did not verify) header.i=@infradead.org; dkim=neutral (body hash did not verify) header.i=@nifty.com; spf=pass (google.com: best guess record for domain of linux-mtd-bounces+patch=linaro.org@lists.infradead.org designates 65.50.211.133 as permitted sender) smtp.mailfrom=linux-mtd-bounces+patch=linaro.org@lists.infradead.org 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=UJUKPVyh4jvhEcrsTUtV1BXhZhApXOoRsXLEsfebK0I=; b=ML9dT+HrpKhjMfVDKK/cJPVTWb YYFzdzi86MCUN3JohzV0hNIMAHbdFRzcI8yggrVO/W+yn35zDcnnCQDSysXOsWMGFJkyjuaQKmH0g 7VlJxZLaEdz6Qb+UGkC04gcU0lig0bjMadzoAByc3cbVeNeKiIlDsaEn5ROYWEcbbsPE2EJc3esgq CQffZ7cFdvdgrlM0YfI+tfUBNg56TIbxCeYBk0toaGA6gICoaQ5Rqktec7pwDfbBwj4kU+BypoN20 kbNaqUzDzuQEJI3hiUiv/4WITdRyz6XaABUGunEARIPuKq58eDmOYuVE0iwOutwDx6kg7fYbguntc TVKufaMA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cqqjx-0007rD-RV; Thu, 23 Mar 2017 00:36:33 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqqj2-0005Jp-E6 for linux-mtd@bombadil.infradead.org; Thu, 23 Mar 2017 00:35:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=rimhvshIxOulT44dZKoza656M92w3Q967+cF1v5fjno=; b=T3QWx+ge4Ni3Uwk94S9muVs/a mGEayC8kCSqqzRFalA1vTv1ioShjlOe6zvDcM0Azyb1f3eqAVd8czmWzQyaHd2HFk4Qai39kucMAV i36XL7cVxfZGpLAp/1jy3xPCm0ONWbjpYIA/oThQG3NTbakhNz8bLpuRCmygWJx3Hp2sEDTgP1QWp axotp1x+y1dKzCLNRGzZyRmTAgJ85GxReoOFtA4Ib7GgAwhIcGcELCO7enKKLAxfCr5bMCNWKCWKy hY2lgdPD1DZvxoCTLkgM3EagXlIovBoV5veMTB8I5tLbcGZWlsRyuiKiWeCi6X0i+dqjSQlyyxjqk Ffm0BalIA==; Received: from conuserg-09.nifty.com ([210.131.2.76]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cqqTT-0001GS-AI for linux-mtd@lists.infradead.org; Thu, 23 Mar 2017 00:19:33 +0000 Received: from grover.sesame (FL1-111-169-71-157.osk.mesh.ad.jp [111.169.71.157]) (authenticated) by conuserg-09.nifty.com with ESMTP id v2N0I4c1008011; Thu, 23 Mar 2017 09:18:32 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v2N0I4c1008011 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490228313; bh=rimhvshIxOulT44dZKoza656M92w3Q967+cF1v5fjno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OTnC6zwyiRWXGDkwIgu3iSthQ5Qdn1N3CgmUexcCZ2LzTtnbdx4CRxxQE3JZfokcn tpJzHf7PUhtPgrCotlsU2HW8Quba3BOxCjQWU+z5RXEN+kl4ppPssyTsy5hqEYGLnn Zv3QsVBdu2/MkAs2UYfU5ueUUjaBL7LfL8KR4t9EH3H+NvRJvUoJuAz6BFs+eSpO/C GYPqy+uP3/DBxVvmi0O3OvwyDs1tjfacRx+H4LzCQp5WQkbcSXKUEQje2d+LdoQEia GsGL6Mj1PaZ4V6m5TwpyPng4WGGORulxoNMWL7qM3V7ToEra/mK7kOxS+8VvzzJqkx 8FQdT/ebmtV+Q== X-Nifty-SrcIP: [111.169.71.157] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [RESEND PATCH v2 49/53] mtd: nand: denali: support hardware-assisted erased page detection Date: Thu, 23 Mar 2017 09:17:58 +0900 Message-Id: <1490228282-10805-23-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490228282-10805-1-git-send-email-yamada.masahiro@socionext.com> References: <1490228282-10805-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170323_001931_862602_B154C32C X-CRM114-Status: GOOD ( 16.52 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.7 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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 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: laurent.monat@idquantique.com, Boris Brezillon , thorsten.christiansson@idquantique.com, Dinh Nguyen , Enrico Jorns , Artem Bityutskiy , Marek Vasut , Masahiro Yamada , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , Brian Norris , David Woodhouse , Rob Herring , Graham Moore MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org Recent versions of this IP support automatic erased page detection. If an erased page is detected on reads, the controller does not set INTR__ECC_UNCOR_ERR, but INTR__ERASED_PAGE. If this feature is supported, the driver can use this information instead of calling nand_check_erased_ecc_chunk(). The detection of erased page is based on the number of zeros in the page; if the number of zeros is less than the value in the field ERASED_THRESHOLD, the page is assumed as erased. Set the ERASED_THRESHOLD to (chip->ecc.strength + 1). This is the worst case where all the bitflips come from the same ECC sector. This field is Reserved for older IP versions, so this commit has no impact on them. One thing worth mentioning is the driver still needs to fill the buffer with 0xff in the case because the ECC correction engine has already manipulated the data in the buffer. Signed-off-by: Masahiro Yamada --- Changes in v2: - Newly added drivers/mtd/nand/denali.c | 10 +++++++++- drivers/mtd/nand/denali.h | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c index 1b0e79c..c3a7f7b 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -559,6 +559,9 @@ static int denali_pio_read(struct denali_nand_info *denali, void *buf, if (!(irq_status & INTR__PAGE_XFER_INC)) return -EIO; + if (irq_status & INTR__ERASED_PAGE) + memset(buf, 0xff, size); + return irq_status & ecc_err_mask ? -EBADMSG : 0; } @@ -631,6 +634,9 @@ static int denali_dma_xfer(struct denali_nand_info *denali, void *buf, denali_enable_dma(denali, false); dma_sync_single_for_cpu(denali->dev, dma_addr, size, dir); + if (irq_status & INTR__ERASED_PAGE) + memset(buf, 0xff, size); + return ret; } @@ -1423,7 +1429,9 @@ int denali_init(struct denali_nand_info *denali) chip->ecc.bytes = denali_calc_ecc_bytes(chip->ecc.size, chip->ecc.strength); - iowrite32(chip->ecc.strength, denali->flash_reg + ECC_CORRECTION); + iowrite32(MAKE_ECC_CORRECTION(chip->ecc.strength, + chip->ecc.strength + 1), + denali->flash_reg + ECC_CORRECTION); iowrite32(mtd->erasesize / mtd->writesize, denali->flash_reg + PAGES_PER_BLOCK); iowrite32(denali->nand.options & NAND_BUSWIDTH_16 ? 1 : 0, diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h index 4696fd6..ecbec33 100644 --- a/drivers/mtd/nand/denali.h +++ b/drivers/mtd/nand/denali.h @@ -109,6 +109,10 @@ #define ECC_CORRECTION 0x1b0 #define ECC_CORRECTION__VALUE GENMASK(4, 0) +#define ECC_CORRECTION__ERASE_THRESHOLD GENMASK(31, 16) +#define MAKE_ECC_CORRECTION(val, thresh) \ + (((val) & (ECC_CORRECTION__VALUE)) | \ + (((thresh) << 16) & (ECC_CORRECTION__ERASE_THRESHOLD))) #define READ_MODE 0x1c0 #define READ_MODE__VALUE GENMASK(3, 0) @@ -237,6 +241,7 @@ #define INTR__RST_COMP BIT(13) #define INTR__PIPE_CMD_ERR BIT(14) #define INTR__PAGE_XFER_INC BIT(15) +#define INTR__ERASED_PAGE BIT(16) #define PAGE_CNT(bank) (0x430 + (bank) * 0x50) #define ERR_PAGE_ADDR(bank) (0x440 + (bank) * 0x50)