From patchwork Wed Apr 12 06:16:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13208541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 062C4C77B6E for ; Wed, 12 Apr 2023 06:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=6bo3767j6q7jCnh1EyXikxIGAcFeM8xSHYIcO+aUMeY=; b=yhsL9VElFv8UC9 RKAp7LX1MBSWz8rrpE1LNAHOlp2WOaqb0zIQWE3ecMi2mib3QCDd6yw5lcIUIM2MG2zbjakDTD4fB VS+FPjHM2yJptIfJXOSZE9fJRtbQ440SppAcwq3j4oQltC+LMYmCExyWpACcjUTXjZZ8E8FmPh6s2 bIrDPZA/pGZnRRoRqah1a1g/Mrp079R4gSx2D6Sm9DSBiJjc+T/rSeWPU0REm7S43vzLJJdeKVsZx 0Ez+zqTV4AeGYAxcEDHU8ORtSqrHUJ85hs4LNtRg1cOqtDMJREmWlRrf+8XiYF5GqTjdg7BvsaxDr XdF/CjJ1h0agycze00Og==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmTrI-001vrM-1y; Wed, 12 Apr 2023 06:21:32 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmTr8-001vk8-0L; Wed, 12 Apr 2023 06:21:25 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 42AA65FD5F; Wed, 12 Apr 2023 09:21:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1681280476; bh=HsWlt2hUmy9E6I75trQqDK7lPoanqWGp8KNo6fzJ1jI=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=YFdUhvFyHk5aOUP3MDGRfbzpNbVzBXqw1nuttiGdWrLiiv+IU1qCK7DnsUplTPcSl LgNpg8Eg83npIAUsxAylbmFczuAE9E/RpIgLC5T6yAxe/ylu9LfUu/VM5vw45vGwqP +t5cnuXYfDhtwuiYeXHwJrRqJ3lPSYOMmacBhS/pWxLyu9GgKp4RGtbudAop1uEoL0 oFkGxukYEvbEKHyEUyKSxiliB/vsBdo1r0SmY7fXiXmKaPlqJ/apTEpTZkxfYlTapR DuhO8FcYiq7d2i2aAP5P0PI//bGrv0AKmVV601OLbiWSYyM64NVBHVwfX1jHbgFlV5 ILf4QKqfa71/A== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 12 Apr 2023 09:21:16 +0300 (MSK) From: Arseniy Krasnov To: Liang Yang , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yixun Lan , Jianxin Pan CC: , , Arseniy Krasnov , , , , Subject: [PATCH v1 1/5] mtd: rawnand: meson: fix NAND access for read/write Date: Wed, 12 Apr 2023 09:16:55 +0300 Message-ID: <20230412061700.1492474-2-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> References: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/04/12 04:12:00 #21090163 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_232122_631546_FE9B5135 X-CRM114-Status: GOOD ( 16.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This fixes read/write functionality. New command sequences were ported from old vendor's driver. Without this patch driver works unstable. This change is tested with 'nanddump'/'nandwrite' utilities and mounting JFFS2 filesystem on AXG family (A113X SoC). Fixes: 8fae856c5350 ("mtd: rawnand: meson: add support for Amlogic NAND flash controller") Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 116 ++++++++++++++++++++++++++---- 1 file changed, 101 insertions(+), 15 deletions(-) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 074e14225c06..256c37c76526 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -26,6 +26,7 @@ #define NFC_CMD_IDLE (0xc << 14) #define NFC_CMD_CLE (0x5 << 14) #define NFC_CMD_ALE (0x6 << 14) +#define NFC_CMD_DRD (0x8 << 14) #define NFC_CMD_ADL ((0 << 16) | (3 << 20)) #define NFC_CMD_ADH ((1 << 16) | (3 << 20)) #define NFC_CMD_AIL ((2 << 16) | (3 << 20)) @@ -84,6 +85,7 @@ #define DMA_BUSY_TIMEOUT 0x100000 #define CMD_FIFO_EMPTY_TIMEOUT 1000 +#define DEVICE_READY_TIMEOUT 1000 #define MAX_CE_NUM 2 @@ -255,8 +257,26 @@ static void meson_nfc_select_chip(struct nand_chip *nand, int chip) } } +static int meson_nfc_wait_cmd_finish(struct meson_nfc *nfc, + unsigned int timeout_ms) +{ + u32 cmd_size = 0; + int ret; + + /* wait cmd fifo is empty */ + ret = readl_relaxed_poll_timeout(nfc->reg_base + NFC_REG_CMD, cmd_size, + !NFC_CMD_GET_SIZE(cmd_size), + 10, timeout_ms * 1000); + if (ret) + dev_err(nfc->dev, "wait for empty CMD FIFO timed out\n"); + + return ret; +} + static void meson_nfc_cmd_idle(struct meson_nfc *nfc, u32 time) { + meson_nfc_wait_cmd_finish(nfc, 0); + writel(nfc->param.chip_select | NFC_CMD_IDLE | (time & 0x3ff), nfc->reg_base + NFC_REG_CMD); } @@ -308,23 +328,9 @@ static void meson_nfc_drain_cmd(struct meson_nfc *nfc) */ meson_nfc_cmd_idle(nfc, 0); meson_nfc_cmd_idle(nfc, 0); + meson_nfc_wait_cmd_finish(nfc, 1000); } -static int meson_nfc_wait_cmd_finish(struct meson_nfc *nfc, - unsigned int timeout_ms) -{ - u32 cmd_size = 0; - int ret; - - /* wait cmd fifo is empty */ - ret = readl_relaxed_poll_timeout(nfc->reg_base + NFC_REG_CMD, cmd_size, - !NFC_CMD_GET_SIZE(cmd_size), - 10, timeout_ms * 1000); - if (ret) - dev_err(nfc->dev, "wait for empty CMD FIFO time out\n"); - - return ret; -} static int meson_nfc_wait_dma_finish(struct meson_nfc *nfc) { @@ -631,6 +637,48 @@ static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand, return 0; } +static uint8_t meson_nfc_read_byte(struct nand_chip *nand) +{ + struct meson_nfc *nfc = nand_get_controller_data(nand); + + writel(NFC_CMD_DRD, nfc->reg_base + NFC_REG_CMD); + meson_nfc_cmd_idle(nfc, nfc->timing.twb); + meson_nfc_drain_cmd(nfc); + + return readl(nfc->reg_base + NFC_REG_BUF); +} + +static int meson_nfc_wait_dev_ready(struct nand_chip *nand) +{ + struct meson_nfc *nfc = nand_get_controller_data(nand); + u32 cs = nfc->param.chip_select; + unsigned long cnt = 0; + + meson_nfc_drain_cmd(nfc); + + writel(cs | NFC_CMD_CLE | NAND_CMD_STATUS, nfc->reg_base + NFC_REG_CMD); + + /* 10 ms. */ + while (cnt < DEVICE_READY_TIMEOUT) { + uint8_t status; + + status = meson_nfc_read_byte(nand); + + if (status & NAND_STATUS_READY) + break; + + usleep_range(10, 11); + cnt++; + } + + if (cnt == DEVICE_READY_TIMEOUT) { + dev_err(nfc->dev, "device ready timeout\n"); + return -ETIMEDOUT; + } + + return 0; +} + static int meson_nfc_write_page_sub(struct nand_chip *nand, int page, int raw) { @@ -643,6 +691,10 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand, u32 cmd; int ret; + ret = meson_nfc_wait_dev_ready(nand); + if (ret) + return ret; + meson_nfc_select_chip(nand, nand->cur_cs); data_len = mtd->writesize + mtd->oobsize; @@ -667,12 +719,20 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand, NFC_CMD_SCRAMBLER_DISABLE); } + ret = meson_nfc_wait_dma_finish(nfc); + if (ret) + return ret; + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_PAGEPROG; writel(cmd, nfc->reg_base + NFC_REG_CMD); meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tPROG_max)); meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_TO_DEVICE); + ret = meson_nfc_wait_dev_ready(nand); + if (ret) + return ret; + return ret; } @@ -720,6 +780,21 @@ static void meson_nfc_check_ecc_pages_valid(struct meson_nfc *nfc, } while (!ret); } +static inline int meson_nfc_send_read(struct nand_chip *nand) +{ + struct meson_nfc *nfc = nand_get_controller_data(nand); + u32 cs = nfc->param.chip_select; + int ret; + + ret = meson_nfc_wait_dev_ready(nand); + if (ret) + return ret; + + writel(cs | NFC_CMD_CLE | NAND_CMD_READ0, nfc->reg_base + NFC_REG_CMD); + + return 0; +} + static int meson_nfc_read_page_sub(struct nand_chip *nand, int page, int raw) { @@ -734,10 +809,18 @@ static int meson_nfc_read_page_sub(struct nand_chip *nand, data_len = mtd->writesize + mtd->oobsize; info_len = nand->ecc.steps * PER_INFO_BYTE; + ret = meson_nfc_wait_dev_ready(nand); + if (ret) + return ret; + ret = meson_nfc_rw_cmd_prepare_and_execute(nand, page, DIRREAD); if (ret) return ret; + ret = meson_nfc_send_read(nand); + if (ret) + return ret; + ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf, data_len, meson_chip->info_buf, info_len, DMA_FROM_DEVICE); @@ -754,6 +837,9 @@ static int meson_nfc_read_page_sub(struct nand_chip *nand, } ret = meson_nfc_wait_dma_finish(nfc); + if (ret) + return ret; + meson_nfc_check_ecc_pages_valid(nfc, nand, raw); meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_FROM_DEVICE); From patchwork Wed Apr 12 06:16:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13208540 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0D1D8C77B6E for ; Wed, 12 Apr 2023 06:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=90hdvab9BLJrC89Zi4AALTUpXgtW4gVUiYsMG8w25oo=; b=yfNv4Wdsl5tF6v aOZhnbCOSderpL2a/WjGHE0AeROC0BleX7xMN+ATeTj+rYnmBROXicjl6/WK8Lx5QygdfRiWipu72 rcbBwkOd+cX0Dh4QenJe1EzPoxbHODg7O9daEf2wO/MXLl8qiS/ToCXLSew7uSTvMsuJRyD59QO00 iGfeqt6IezbSlBHFxsDb0ryGt/OQn388tfYTkRaLVzgKxvGWZnpqDSq5suaoeOzj/RxYHf+HvN87H +43YpPt39++9jYFnUrauJ6AdBDYo2x55+eKTRU/4FGb1dPdjZ+iORMGYxQLLu52qiihThP0JLvkoI 2Ckhou+WTgmfk2JVUekw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmTrD-001voM-2y; Wed, 12 Apr 2023 06:21:27 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmTr8-001vks-0L; Wed, 12 Apr 2023 06:21:24 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id B13835FD61; Wed, 12 Apr 2023 09:21:18 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1681280478; bh=Y/eHmQmhsT9LVvYGckzElMjsdyU8uNoVK685QSt2va4=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=QJZ3f3x5ssA86aHvq/VV7bMRBW5rB4ErigDHPJ2d6T+cJ8hv+Z+nkz3Ogu+NXHtS0 rTn0nr2hmkY79UMmCHF5cwaeh5Q2ZErJ/HrPaw40dlDbYqjn+2BiPStVG3Wn0Q+P7W d6LWPZvfUSCSCV9EzSMUbDhTFHxJbDtFlNYlqZK4QhHRzoJrHXLlc9htE0wlVJqByD MsCv3RScLlUh+PMCosHsnL2L06PLiQ+vFbN1KY5xPi4Ys7937k8U030/UsG0M2gEND VZd6kAU0eP81v+Njuoqma19DrpV4UD4gqucJVdlgwb+8Euc+2hP/2LkzWHKsQLwUIE LKrZ9JtHlQ/Lw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 12 Apr 2023 09:21:18 +0300 (MSK) From: Arseniy Krasnov To: Liang Yang , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yixun Lan , Jianxin Pan CC: , , Arseniy Krasnov , , , , Subject: [PATCH v1 2/5] mtd: rawnand: meson: replace GENMASK() macro with define Date: Wed, 12 Apr 2023 09:16:56 +0300 Message-ID: <20230412061700.1492474-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> References: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/04/12 04:12:00 #21090163 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_232122_629943_81F5A24B X-CRM114-Status: GOOD ( 11.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 256c37c76526..45b53d420aed 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -110,6 +110,8 @@ #define PER_INFO_BYTE 8 +#define NFC_CMD_RAW_LEN (GENMASK(13, 0)) + struct meson_nfc_nand_chip { struct list_head node; struct nand_chip nand; @@ -300,7 +302,7 @@ static void meson_nfc_cmd_access(struct nand_chip *nand, int raw, bool dir, if (raw) { len = mtd->writesize + mtd->oobsize; - cmd = (len & GENMASK(13, 0)) | scrambler | DMA_DIR(dir); + cmd = (len & NFC_CMD_RAW_LEN) | scrambler | DMA_DIR(dir); writel(cmd, nfc->reg_base + NFC_REG_CMD); return; } @@ -550,7 +552,7 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) if (ret) goto out; - cmd = NFC_CMD_N2M | (len & GENMASK(13, 0)); + cmd = NFC_CMD_N2M | (len & NFC_CMD_RAW_LEN); writel(cmd, nfc->reg_base + NFC_REG_CMD); meson_nfc_drain_cmd(nfc); @@ -574,7 +576,7 @@ static int meson_nfc_write_buf(struct nand_chip *nand, u8 *buf, int len) if (ret) return ret; - cmd = NFC_CMD_M2N | (len & GENMASK(13, 0)); + cmd = NFC_CMD_M2N | (len & NFC_CMD_RAW_LEN); writel(cmd, nfc->reg_base + NFC_REG_CMD); meson_nfc_drain_cmd(nfc); From patchwork Wed Apr 12 06:16:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13208543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E8783C77B6E for ; Wed, 12 Apr 2023 06:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ChlQWa1AThu7z2F15rUTG5Yb7xD3DqSXrApSNy+R3rk=; b=INRWNWh/V8a7bZ sxR9QVpA/1U+9mjwKiNWhFiToSjV3Q9XwBO4OCdpDgHMkylk5Am3tNnJlj/1TnIxjZDuA/2HmR1fg VvEyQGd2Eoy4aRl6Y8h8MbUnBHK0KKA6jlLHYhOhKejB7V3494mTLVOeEqdsMbFd+/BICK1hlxrTV dVfFQlUtSgF1PGqEMSzdNkd4jWQJ3R3MIXJl/Gdd4LQoveYOMCbbXZFQ95PPhe6yrx4KaMmrOp/OJ QHwFIAVmJ+zIq6SNjNateNdssQE0xjA6kk0ldvF0YXSu4IjwsUdN8FyfJhUisZp0cy1YfJ5cU2K1l ni+OFaM9iwTJ4prFYErw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmTrH-001vqZ-1N; Wed, 12 Apr 2023 06:21:31 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmTr8-001vl6-1S; Wed, 12 Apr 2023 06:21:25 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 0E3E35FD62; Wed, 12 Apr 2023 09:21:21 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1681280481; bh=ijR0GjfEvDOCR18/yaVWHDk9s/uQwtd45e8HbVoRBEQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PfZzkCq9CfP69XL505bFICG6fQTHQzkN70Rkt6pEOLy6eMuNbijDMoHHDAOY49mQo q1cXnKYiwWKg2qrhAHi2oC4sHDDazFy2C7SO+2qlfiiuBMjh7uJqfRu1jI+84xxHF3 RF4PLF+/2LCXHbjA6gFaB408oiHijSXmao+vbdqEvGulBHdb/RSVLuv54sEjRLZ9Lv tw8a/fB/sM9YPQQbl/x2Q0HNBBDLq0gNraT/NUC8T+NVAmscMoSkGh/ZWaCsZurxau CQBrljvgymE+ZEguk0nVtlfO62vqMQIdoETUXJR+hQI4RahO7T1cBjLn0uwEbsp9Fu ix43OXeg9E9Wg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 12 Apr 2023 09:21:21 +0300 (MSK) From: Arseniy Krasnov To: Liang Yang , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yixun Lan , Jianxin Pan CC: , , Arseniy Krasnov , , , , Subject: [PATCH v1 3/5] mtd: rawnand: meson: check buffer length Date: Wed, 12 Apr 2023 09:16:57 +0300 Message-ID: <20230412061700.1492474-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> References: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/04/12 04:12:00 #21090163 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_232122_829754_352E180F X-CRM114-Status: GOOD ( 10.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org With this chip, buffer length is limited by hardware, so check it before command execution to avoid length trim. Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 45b53d420aed..f84a10238e4d 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -543,6 +543,9 @@ static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) u32 cmd; u8 *info; + if (len > NFC_CMD_RAW_LEN) + return -EINVAL; + info = kzalloc(PER_INFO_BYTE, GFP_KERNEL); if (!info) return -ENOMEM; @@ -571,6 +574,9 @@ static int meson_nfc_write_buf(struct nand_chip *nand, u8 *buf, int len) int ret = 0; u32 cmd; + if (len > NFC_CMD_RAW_LEN) + return -EINVAL; + ret = meson_nfc_dma_buffer_setup(nand, buf, len, NULL, 0, DMA_TO_DEVICE); if (ret) @@ -1269,6 +1275,7 @@ static int meson_nand_attach_chip(struct nand_chip *nand) struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); struct mtd_info *mtd = nand_to_mtd(nand); int nsectors = mtd->writesize / 1024; + int raw_writesize; int ret; if (!mtd->name) { @@ -1280,6 +1287,13 @@ static int meson_nand_attach_chip(struct nand_chip *nand) return -ENOMEM; } + raw_writesize = mtd->writesize + mtd->oobsize; + if (raw_writesize > NFC_CMD_RAW_LEN) { + dev_err(nfc->dev, "too big write size in raw mode: %d > %ld\n", + raw_writesize, NFC_CMD_RAW_LEN); + return -EINVAL; + } + if (nand->bbt_options & NAND_BBT_USE_FLASH) nand->bbt_options |= NAND_BBT_NO_OOB; From patchwork Wed Apr 12 06:16:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13208542 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BF350C77B73 for ; Wed, 12 Apr 2023 06:22:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FhWR96iDR90+qGYSg/nQIajt2RQxuNfmuWIUS2XCrnY=; b=LNBmG08mx7WelD aZgZe8V+Z/UUQW9JvagF4uYtuyDwOdir5sYCGwItn5kvTIkLWp+xUiW0BauhWlK/V+7Fo2H46CNbp 5mAQa1YmJ4Wjg+34302BzoYfwhWv5xFPcc/8nslct2n7VgDUQ6MsgxG9Cplzzy+5hijsejycQw+cO ffh6pv7UvuyaPhZEFyJmlHiNsOWUuSnKnr3UoZnW6yWS7HDyiZTHGqfddOJv/uE8RqlUWMwp+/OGR qIylolKP8kXHtnHgLKMTmiq4FYgPd60Lvk94P5gVQYYU6qfGQomOhLGvWQ+yUWrss460pmTVwvs1Y TC/Tggjddwg6epSWT0KA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmTrL-001vtL-1c; Wed, 12 Apr 2023 06:21:35 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmTrA-001vm4-1d; Wed, 12 Apr 2023 06:21:26 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 03AF45FD63; Wed, 12 Apr 2023 09:21:23 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1681280483; bh=yOrNA4RDuoM2vY5YhSP/eGA0DmXdgsqQqlqaL/M6BtI=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=SmeasOpRVy5aK9D7zQO00XNQdh/v8N9hvNJ2Zj0L995muidQCpGzGjWGdqdtdt4KD GoM+st3GB75u96nvynvGqdmcCzYVgGePL46Z55tt7LYKE3J+lDhPeBv/4DncerKkTP Y1/wJ3GFslOsHrhGLC/wS6w8/pg6roJQwAFJfdIo2lCyo0ky3p+1a1HUrg1i3itj/i ek9GaBfFEtZiu0sDwxoh0Phh5eHCcLvP1jTGRzw/mcounSc+4+AgF/FAVVW7YJwGKh 0bhEE3QWKl6gZ6I1WW9gzHEPLoagteTuCzYvGKxi969Yt9nqvs+0gABPK1h23JX/UG qe8haXiN1aXOg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 12 Apr 2023 09:21:22 +0300 (MSK) From: Arseniy Krasnov To: Liang Yang , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Jianxin Pan , Yixun Lan CC: , , Arseniy Krasnov , , , , Subject: [PATCH v1 4/5] mtd: rawnand: meson: clear OOB buffer before read Date: Wed, 12 Apr 2023 09:16:58 +0300 Message-ID: <20230412061700.1492474-5-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> References: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/04/12 04:12:00 #21090163 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_232124_890806_0B4AA0E4 X-CRM114-Status: GOOD ( 10.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This NAND reads only few user's bytes in ECC mode (not full OOB), so fill OOB buffer with zeroes to not return garbage from previous reads to user. Otherwise 'nanddump' utility prints something like this for just erased page: ... 0x000007f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff OOB Data: ff ff ff ff 00 00 ff ff 80 cf 22 99 cb ad d3 be OOB Data: 63 27 ae 06 16 0a 2f eb bb dd 46 74 41 8e 88 6e OOB Data: 38 a1 2d e6 77 d4 05 06 f2 a5 7e 25 eb 34 7c ff OOB Data: 38 ea de 14 10 de 9b 40 33 16 6a cc 9d aa 2f 5e Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index f84a10238e4d..f2f2472cb511 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -858,9 +858,12 @@ static int meson_nfc_read_page_sub(struct nand_chip *nand, static int meson_nfc_read_page_raw(struct nand_chip *nand, u8 *buf, int oob_required, int page) { + struct mtd_info *mtd = nand_to_mtd(nand); u8 *oob_buf = nand->oob_poi; int ret; + memset(oob_buf, 0, mtd->oobsize); + ret = meson_nfc_read_page_sub(nand, page, 1); if (ret) return ret; @@ -881,6 +884,8 @@ static int meson_nfc_read_page_hwecc(struct nand_chip *nand, u8 *buf, u8 *oob_buf = nand->oob_poi; int ret, i; + memset(oob_buf, 0, mtd->oobsize); + ret = meson_nfc_read_page_sub(nand, page, 0); if (ret) return ret; From patchwork Wed Apr 12 06:16:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13208544 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D6783C7619A for ; Wed, 12 Apr 2023 06:22:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LoszDAjzuk7nO8mJDAPGN8KouofKCNhZ2M4h8yh8EWk=; b=Yb+OSv+6cRTDIx Ckk+gAZ+k6Q52oxAPT6cPPvsKACQqKBur24etcEvOW9RMLquk/klhgX2F5B8u+1KPUsLeR1KMHbra 0F6BZjd2U6JfAmfsOcBfdxCZ+m3TCWivAkmlyp4ScfZU6n+aKdVKWxWUR36qVTs63uhTkrb/g9f7z 5T+RK4CQ1NmS8M6S9y0wOQ0zgBcd3W3wXzo7gGtgT2JkVp/hDrPQMB06VVunexU8PoHmNqsK4ad9Y VGB6dBfMc9wjMbaEmUxbujzO33aNDYpbbE+y6LwLIISI9kVgiTRA1l6vU+hjKSahYiF9Bw6lEBy15 pJuzrf3Mtz+dMJblVPEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pmTrO-001vwL-2g; Wed, 12 Apr 2023 06:21:38 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pmTrC-001vmy-24; Wed, 12 Apr 2023 06:21:27 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 287CA5FD5E; Wed, 12 Apr 2023 09:21:25 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1681280485; bh=LO7pNly68Ih3sc3StizhIculbRddDBriZg8uwOnKxL4=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=pg4D5A1FKYj6OdmHRb3KvNJ5byOcm5ZDqyX9APpnV4K5+kIOdB7PG4dl7yQRKDh+z bbwtvtvxSd1juCOQ6K6yBUnMFAx4Z4sr7EFzPVxJd378p3uj7ISIYRB4k7exD/6nvz 1WM24AITDzsW7xzV21UFJd4unaV+5Gspeyu6eFnsme4JpaofR63Ydji8i6DrAnjDNN WMWwS2/8IfnkXBbduOPEWB5m8H2smr2umJ5ny39CqXBZtGnqoe0jU6gw3VbqlRUfE5 mn7wqrj+vHTyFFeVdfaNLN7eoMlA/J09QLcmJ0kMjw+hTxJ1yxM1mmdz30ndBy/QB9 8NazJeVldbzgw== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Wed, 12 Apr 2023 09:21:25 +0300 (MSK) From: Arseniy Krasnov To: Liang Yang , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Neil Armstrong , Kevin Hilman , Jerome Brunet , Martin Blumenstingl , Yixun Lan , Jianxin Pan CC: , , Arseniy Krasnov , , , , Subject: [PATCH v1 5/5] mtd: rawnand: meson: remove unneeded bitwise OR with zeroes Date: Wed, 12 Apr 2023 09:16:59 +0300 Message-ID: <20230412061700.1492474-6-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> References: <20230412061700.1492474-1-AVKrasnov@sberdevices.ru> MIME-Version: 1.0 X-Originating-IP: [172.16.1.6] X-ClientProxiedBy: S-MS-EXCH01.sberdevices.ru (172.16.1.4) To S-MS-EXCH01.sberdevices.ru (172.16.1.4) X-KSMG-Rule-ID: 4 X-KSMG-Message-Action: clean X-KSMG-AntiSpam-Status: not scanned, disabled by settings X-KSMG-AntiSpam-Interceptor-Info: not scanned X-KSMG-AntiPhishing: not scanned, disabled by settings X-KSMG-AntiVirus: Kaspersky Secure Mail Gateway, version 1.1.2.30, bases: 2023/04/12 04:12:00 #21090163 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230411_232126_858061_98B0F9F4 X-CRM114-Status: GOOD ( 11.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Both operations have no effect. Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index f2f2472cb511..f0486aba5f41 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -609,12 +609,12 @@ static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand, cmd0 = in ? NAND_CMD_READ0 : NAND_CMD_SEQIN; nfc->cmdfifo.rw.cmd0 = cs | NFC_CMD_CLE | cmd0; - addrs[0] = cs | NFC_CMD_ALE | 0; + addrs[0] = cs | NFC_CMD_ALE; if (mtd->writesize <= 512) { cmd_num--; row_start = 1; } else { - addrs[1] = cs | NFC_CMD_ALE | 0; + addrs[1] = cs | NFC_CMD_ALE; row_start = 2; }