From patchwork Thu Mar 30 08:15:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 96257 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp127989qgd; Thu, 30 Mar 2017 01:16:26 -0700 (PDT) X-Received: by 10.98.49.1 with SMTP id x1mr4910329pfx.26.1490861786826; Thu, 30 Mar 2017 01:16:26 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id c11si1457399pgn.188.2017.03.30.01.16.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 01:16:26 -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=@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=P/SMaPvdygtUOZtuuHip7+pvfFz3+cH3D6GUvfESQiw=; b=YgALJcyA3ClX9I94jYLl5R/V7m vdqin20RymREAGPf7ILJouppoPRcau7LKamPVabLmLrMWBpy98o8If4U1O3raN499+q8Iqsk+Pq85 FjwKEMHNMvv7zX0T0Cun9bB7qa5yvOf9VURYbL0UKwqEZVejzIH0rJJ4qlRLlND7x3FW0KO+mSOkk PC3DLyB58b30UCeYbFQdskDvI6MSq+UCZNYW62Z5/8lcvd0QN2Bj6cjtgwuG9uDsS/H/l3syyXNEL EmCp3hBLLXoi48Vy/XtdRZPNqIFdNxhJUR9JMevUsHPSSN6E9vvM1uOR08sAB6d+LqXL6DTupjjZ6 8rMLM7bQ==; 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 1ctVFq-00041C-05; Thu, 30 Mar 2017 08:16:26 +0000 Received: from conuserg-09.nifty.com ([210.131.2.76]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctVFd-0003of-PX for linux-mtd@lists.infradead.org; Thu, 30 Mar 2017 08:16:15 +0000 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v2U8FQ9f018607; Thu, 30 Mar 2017 17:15:28 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v2U8FQ9f018607 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490861729; bh=jF/PpbxgywvDVaWEd6JHE+81rh7xMvDUVOh1VN6XU5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UhLyMI2Mkzu3uwqpvR8Y+54O6AN8ZkxV+QXUPfFyFKlVTXSUonOQ/jxYGA5+83vZY 5t2FsqJHCKnBNwq2X6rZZqy4BsCUzZSCBmXSGq+xtdM9MyjGI1UrQ8IALHsNIrT5R7 oVCjUn7uaTFzxBc4Itv3CUk8YpfPV6gqD8fiHSPPk0OcN0hA4NAN4Z3bFGu2pqNIS1 QLONLSzuD/0vuxZiWAWWpSaC3RJXF56jJ9FfTdKu5DdI2Uc5iaGfvsCzpLnT0bmdFC fhdP5UKv9eLx+jn6Uo2+vIwbX8gaDKyR2Ey5O/Ntiw/vT/9V6/j3Ajy67ISiqcfI+z 2qBMDBsSMVCoA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [PATCH v3 32/37] mtd: nand: denali: support hardware-assisted erased page detection Date: Thu, 30 Mar 2017 17:15:03 +0900 Message-Id: <1490861708-27813-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> References: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_011614_093537_D4D8530D X-CRM114-Status: GOOD ( 13.17 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.2 points) 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Boris Brezillon , Marek Vasut , Enrico Jorns , Artem Bityutskiy , linux-kernel@vger.kernel.org, Dinh Nguyen , Masahiro Yamada , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , David Woodhouse , 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 v3: None 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 51e8a9a..9ee0f30 100644 --- a/drivers/mtd/nand/denali.c +++ b/drivers/mtd/nand/denali.c @@ -604,6 +604,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; } @@ -676,6 +679,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; } @@ -1475,7 +1481,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 f92b9db..b5ea8d7 100644 --- a/drivers/mtd/nand/denali.h +++ b/drivers/mtd/nand/denali.h @@ -110,6 +110,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) @@ -233,6 +237,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) From patchwork Thu Mar 30 08:15:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 96256 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp127977qgd; Thu, 30 Mar 2017 01:16:24 -0700 (PDT) X-Received: by 10.98.153.11 with SMTP id d11mr4864060pfe.15.1490861784721; Thu, 30 Mar 2017 01:16:24 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [65.50.211.133]) by mx.google.com with ESMTPS id i63si1446492pge.321.2017.03.30.01.16.24 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Mar 2017 01:16:24 -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=@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=3xAqDNQbFCJ+DGGg11ydkSNkQdl7YeX9WyWHGnrgLCI=; b=ZdwHlFs7yw7HoZ/1cTL+8lvhoc jXPRfVfRNygAFloDuHGVIzckMLDaZ3CqcGNm7h7PQUeLZHElaDkaKEUW59znaqXNa0S300/ugEVYb I5nRxsZXlntxzxYWVNHtH+nfx4kDWfzDshezMmmHPVQcGTxqyNDE/yl5d+RjfYK+rWhqszJVuRsVO EiJ4hzeNbrqDTzBNBDNtkJ2F4b+UIboEt75bhTlXoJ605rMpzeu6tm2DbIY28G79j9w9oMhgtqOQO wcHTmYlsk2FVPr1ddyV9x10koP3LthRmphSCBbo7brir7dF39czjuJTfX1wXx+CdaAzPaRFzDiS4V hUdKljuA==; 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 1ctVFh-0003qV-Fj; Thu, 30 Mar 2017 08:16:17 +0000 Received: from conuserg-09.nifty.com ([210.131.2.76]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctVFd-0003og-PW for linux-mtd@lists.infradead.org; Thu, 30 Mar 2017 08:16:15 +0000 Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-09.nifty.com with ESMTP id v2U8FQ9g018607; Thu, 30 Mar 2017 17:15:29 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-09.nifty.com v2U8FQ9g018607 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1490861730; bh=IOrRGFWxoDPYCwyqFkpr8IGkTaZKj8twEnnJUl4yrk0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VdB0ev6Q0iaJQAxtcXhlNp20oZB+EDSFFPxnvzjS8InNZKKzSHuHwcFhDbkwZ8TYp okTGJ2/FQX58X9auZbAlBUluI0v2p52c+mfrrmQhC1oJLjAJKJqu7/xqW76WouvOzu CN0pa3/0JzYefj+Wrbe1A3ZFWOHH/UvtDaH8SxIDtAuaVAG8U+7D9SWTT0TA5Lp3VP 2imkLMjyCHYEtSV5GvGdx0XiLb5RXjZZSn/yD2F+Nfboa5k7fRjKxtSWscDRhFcsvy O2prWTNTCReEXpUlygyOMGHYYnwfWbYn30clnJxN0r0s/iTAkVIBdnE0duRBt0cFaD 2Sm8j91pmdSKg== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-mtd@lists.infradead.org Subject: [PATCH v3 33/37] mtd: nand: allocate aligned buffers if NAND_OWN_BUFFERS is unset Date: Thu, 30 Mar 2017 17:15:04 +0900 Message-Id: <1490861708-27813-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> References: <1490861708-27813-1-git-send-email-yamada.masahiro@socionext.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_011614_111690_BC9B9FE9 X-CRM114-Status: GOOD ( 11.07 ) X-Spam-Score: -1.2 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.2 points) 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_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: Boris Brezillon , Marek Vasut , Enrico Jorns , Artem Bityutskiy , linux-kernel@vger.kernel.org, Dinh Nguyen , Masahiro Yamada , Masami Hiramatsu , Chuanxiao Dong , Jassi Brar , David Woodhouse , Graham Moore MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+patch=linaro.org@lists.infradead.org Some NAND controllers are using DMA engine requiring a specific buffer alignment. The core provides no guarantee on the nand_buffers pointers, which forces some drivers to allocate their own buffers and pass the NAND_OWN_BUFFERS flag. Rework the nand_buffers allocation logic to allocate each buffer independently. This should make most NAND controllers/DMA engine happy, and allow us to get rid of these custom buf allocation in NAND controller drivers. Signed-off-by: Masahiro Yamada --- Changes in v3: - Reword git-log Changes in v2: - Newly added drivers/mtd/nand/nand_base.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) -- 2.7.4 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/ diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index f828ad7..e9d3195 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -4613,13 +4613,25 @@ int nand_scan_tail(struct mtd_info *mtd) } if (!(chip->options & NAND_OWN_BUFFERS)) { - nbuf = kzalloc(sizeof(*nbuf) + mtd->writesize - + mtd->oobsize * 3, GFP_KERNEL); + nbuf = kzalloc(sizeof(*nbuf), GFP_KERNEL); if (!nbuf) return -ENOMEM; - nbuf->ecccalc = (uint8_t *)(nbuf + 1); - nbuf->ecccode = nbuf->ecccalc + mtd->oobsize; - nbuf->databuf = nbuf->ecccode + mtd->oobsize; + nbuf->ecccalc = kmalloc(mtd->oobsize, GFP_KERNEL); + if (!nbuf->ecccalc) { + ret = -EINVAL; + goto err_free; + } + nbuf->ecccode = kmalloc(mtd->oobsize, GFP_KERNEL); + if (!nbuf->ecccode) { + ret = -EINVAL; + goto err_free; + } + nbuf->databuf = kmalloc(mtd->writesize + mtd->oobsize, + GFP_KERNEL); + if (!nbuf->databuf) { + ret = -EINVAL; + goto err_free; + } chip->buffers = nbuf; } else { @@ -4862,8 +4874,12 @@ int nand_scan_tail(struct mtd_info *mtd) /* Build bad block table */ return chip->scan_bbt(mtd); err_free: - if (!(chip->options & NAND_OWN_BUFFERS)) + if (!(chip->options & NAND_OWN_BUFFERS)) { + kfree(chip->buffers->databuf); + kfree(chip->buffers->ecccode); + kfree(chip->buffers->ecccalc); kfree(chip->buffers); + } return ret; } EXPORT_SYMBOL(nand_scan_tail); @@ -4914,8 +4930,12 @@ void nand_cleanup(struct nand_chip *chip) /* Free bad block table memory */ kfree(chip->bbt); - if (!(chip->options & NAND_OWN_BUFFERS)) + if (!(chip->options & NAND_OWN_BUFFERS)) { + kfree(chip->buffers->databuf); + kfree(chip->buffers->ecccode); + kfree(chip->buffers->ecccalc); kfree(chip->buffers); + } /* Free bad block descriptor memory */ if (chip->badblock_pattern && chip->badblock_pattern->options