From patchwork Thu Dec 10 03:22:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YouChing Lin X-Patchwork-Id: 1413792 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 (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mxic.com.tw Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=f2Zllnie; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CrzmB6gqmz9sWK for ; Thu, 10 Dec 2020 14:24:10 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.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=JfJvkUDQy6bxS/y7noQCRVEGvWrpQV3MqUfAOzjmgMs=; b=f2ZllnieuoA5dNdOJHepvkpL6c WBWvuJXvJJbLJc9LOcnhvyECk5sxuGhdcy3DPP1cZZ/sBWKALb9H8YP9PcS1HAvCAMt3TqgL4PSrL ya1yMQOi3623LfHWNkLdg0STmEONwtITshHzqYg64mu0gxDDkvwAyx86xUNDBCp6EvOewnVdAcy0h KE4fDv87ZWxKmTsrKSYbVkTut32MMtGqtRU72ciCjdwDNwjQTMLMk4twRDZgXGYDMm26sHaY8NkKO mG7Yl2gky72uTqO0wdKTqNRIBLuSYbrI9kDJLq5UhTGS47rvN+1Gppe62u2VFpLUtnQ1zsdqqiC2R 6yQZNNYg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knCXk-0002Js-1x; Thu, 10 Dec 2020 03:23:00 +0000 Received: from twhmllg3.macronix.com ([211.75.127.131]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knCXg-0002IS-1a for linux-mtd@lists.infradead.org; Thu, 10 Dec 2020 03:22:57 +0000 Received: from localhost.localdomain ([172.17.195.95]) by TWHMLLG3.macronix.com with ESMTP id 0BA3MURf011440; Thu, 10 Dec 2020 11:22:36 +0800 (GMT-8) (envelope-from ycllin@mxic.com.tw) From: YouChing Lin To: miquel.raynal@bootlin.com, vigneshr@ti.com Subject: [PATCH 1/2] mtd: nand: ecc-bch: Fix the size of calc_buf/code_buf of the BCH Date: Thu, 10 Dec 2020 11:22:08 +0800 Message-Id: <1607570529-22341-2-git-send-email-ycllin@mxic.com.tw> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1607570529-22341-1-git-send-email-ycllin@mxic.com.tw> References: <1607570529-22341-1-git-send-email-ycllin@mxic.com.tw> X-MAIL: TWHMLLG3.macronix.com 0BA3MURf011440 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201209_222256_522315_C0C4D6A0 X-CRM114-Status: GOOD ( 11.88 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [211.75.127.131 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: juliensu@mxic.com.tw, ycllin@mxic.com.tw, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org If eccbyte exceeds 64 bytes, the read operation will get wrong results. For example: Flash with a page size of 4096 bytes (eccbyte: 104 bytes). During the read operation, after executing nand_ecc_sw_bch_calculate(), since the calc_buf/code_buf ranges overlap each other, the last three steps of ecc_code (read from oob) will be changed. The root cause is that the size of calc_buf/code_buf is limited to 64 bytes, although sizeof(mtd->oobsize) returns 4, kzalloc() will allocate 64 bytes (cache size alignment). So we correct the size of calc_buf/code_buf to mtd->oobsize. Signed-off-by: YouChing Lin --- drivers/mtd/nand/ecc-sw-bch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/ecc-sw-bch.c b/drivers/mtd/nand/ecc-sw-bch.c index 4d8a979..0a0ac11 100644 --- a/drivers/mtd/nand/ecc-sw-bch.c +++ b/drivers/mtd/nand/ecc-sw-bch.c @@ -237,8 +237,8 @@ int nand_ecc_sw_bch_init_ctx(struct nand_device *nand) engine_conf->code_size = code_size; engine_conf->nsteps = nsteps; - engine_conf->calc_buf = kzalloc(sizeof(mtd->oobsize), GFP_KERNEL); - engine_conf->code_buf = kzalloc(sizeof(mtd->oobsize), GFP_KERNEL); + engine_conf->calc_buf = kzalloc(mtd->oobsize, GFP_KERNEL); + engine_conf->code_buf = kzalloc(mtd->oobsize, GFP_KERNEL); if (!engine_conf->calc_buf || !engine_conf->code_buf) { ret = -ENOMEM; goto free_bufs; From patchwork Thu Dec 10 03:22:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: YouChing Lin X-Patchwork-Id: 1413791 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mxic.com.tw Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=efqGVGMa; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CrzmC0CMdz9sWL for ; Thu, 10 Dec 2020 14:24:11 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.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=V2dZmQs2xTNn49dIYoHBYYkmYA22XMhQgMv+ZnGPdPI=; b=efqGVGMajNHNg9Octhh4YlOX/C XVRC+qhJ2oG/v35vP1zYyksECJCJAYavX5EEeR0apogQRlyDiuBgzGqpE0bHoYsC152saHv8lJmxT DK62bpo7vATYfdt9szebd3O1K6r5BC4iSz2VTZVkn8pMOTLD9g++VWE9atypll3m7UfVCFOIVtCZd QRIXmkLgzpGiuhBzScCTfhWBUCA/HdM392UKUkykWHARmKZgFza2zeVD/yV5e1WYi0huGecywHvGy OHtDyP6q0h2Jr4xe1/yWEbGNCBNzh0OTCecCMzuChkdkl8Zv4qZviZ0JE1qhZNe5kM3eFBDwWLW+U PV59xttA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1knCXl-0002K5-3T; Thu, 10 Dec 2020 03:23:01 +0000 Received: from twhmllg3.macronix.com ([211.75.127.131]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1knCXg-0002IU-MH for linux-mtd@lists.infradead.org; Thu, 10 Dec 2020 03:22:57 +0000 Received: from localhost.localdomain ([172.17.195.95]) by TWHMLLG3.macronix.com with ESMTP id 0BA3MURg011440; Thu, 10 Dec 2020 11:22:39 +0800 (GMT-8) (envelope-from ycllin@mxic.com.tw) From: YouChing Lin To: miquel.raynal@bootlin.com, vigneshr@ti.com Subject: [PATCH 2/2] mtd: spinand: macronix: Add support for MX35LFxG24AD Date: Thu, 10 Dec 2020 11:22:09 +0800 Message-Id: <1607570529-22341-3-git-send-email-ycllin@mxic.com.tw> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1607570529-22341-1-git-send-email-ycllin@mxic.com.tw> References: <1607570529-22341-1-git-send-email-ycllin@mxic.com.tw> X-MAIL: TWHMLLG3.macronix.com 0BA3MURg011440 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201209_222257_173565_42DC54DA X-CRM114-Status: UNSURE ( 8.71 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [211.75.127.131 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: juliensu@mxic.com.tw, ycllin@mxic.com.tw, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The Macronix MX35LF1G24AD(/2G24AD/4G24AD) are 3V, 1G/2G/4Gbit serial SLC NAND flash device (without on-die ECC). Validated by read, erase, read back, write, read back on Xilinx Zynq PicoZed FPGA board which included Macronix SPI Host(drivers/spi/spi-mxic.c) & S/W BCH ecc(drivers/mtd/nand/ecc-sw-bch.c) with bug fixing patch (mtd: nand: ecc-bch: Fix the size of calc_buf/code_buf of the BCH). Signed-off-by: YouChing Lin --- drivers/mtd/nand/spi/macronix.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/mtd/nand/spi/macronix.c b/drivers/mtd/nand/spi/macronix.c index 3786b1b..6701aaa 100644 --- a/drivers/mtd/nand/spi/macronix.c +++ b/drivers/mtd/nand/spi/macronix.c @@ -139,6 +139,33 @@ static int mx35lf1ge4ab_ecc_get_status(struct spinand_device *spinand, 0, SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, mx35lf1ge4ab_ecc_get_status)), + SPINAND_INFO("MX35LF1G24AD", + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x14), + NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1), + NAND_ECCREQ(8, 512), + SPINAND_INFO_OP_VARIANTS(&read_cache_variants, + &write_cache_variants, + &update_cache_variants), + 0, + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)), + SPINAND_INFO("MX35LF2G24AD", + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x24), + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1), + NAND_ECCREQ(8, 512), + SPINAND_INFO_OP_VARIANTS(&read_cache_variants, + &write_cache_variants, + &update_cache_variants), + 0, + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)), + SPINAND_INFO("MX35LF4G24AD", + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35), + NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 2, 1, 1), + NAND_ECCREQ(8, 512), + SPINAND_INFO_OP_VARIANTS(&read_cache_variants, + &write_cache_variants, + &update_cache_variants), + 0, + SPINAND_ECCINFO(&mx35lfxge4ab_ooblayout, NULL)), SPINAND_INFO("MX31LF1GE4BC", SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x1e), NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),