From patchwork Mon May 15 09:44:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13241189 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 5F98AC7EE2E for ; Mon, 15 May 2023 09:50:15 +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=zxVbEjHRo/TJZ+Tr7EdZNKNhzp8Xgi6vGmIUIsXixE4=; b=xLoDsmwi8qv7vG hkXITtiW0YDzSmQn7ESZ55VBtECvmI3R/tU1pUZFYJYBu5/pBkql/Pjq3Ejb844rR0nQj90lKP79H oTDmiD7mOzZvjJ2wiSIi9/PTb7rZY5ePZF4rnHlhlL/fovAXwOP1eHwxJtlUtvGWXL/TIbKYePvLY ojaI1qFYCNlCW7gYfSgtR2LbrxqtaWysSKn5PqNAa18cukI/LBOTx6rPA+w4FF9VJnhDi4UeLSOmJ yXcBHqBJSbNhDGCyQB/20u/EU1jWyAjtPKOVQwf7YQgXuKkxBMogTEfqSk0DwHnPk6SiUrRnn2/jI eCtRTWPOstwdjiKTJhPw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyUqD-001crH-2Y; Mon, 15 May 2023 09:50:05 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyUpy-001cgz-0n; Mon, 15 May 2023 09:49:54 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 915EE5FD16; Mon, 15 May 2023 12:49:41 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1684144181; bh=Dmj6MVlJqsj8zojvHjdvVHURJoWIYhagZNM7JaN5Dds=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Uf/IsyLUdE2c+v5zkfr9jL/h4IMMipF+j4vKH5XLB675lh5wbPAcDL2sN8H3UJLtp xlpIzpPQTpsqwkFr7iVB2tU8JB6Bm3v6gTiF2Emg1kI27sWm+or+dg2kOie66s6sSM nrMUu76TljNs6mZocS7M/ybbzUAqeJ+DqVdk8F7GDKmK+H3MpPO2676qvGwO6U0wF+ kBaCR6iRUe98WX1HlfeDgMKl6NckIRQzd9yLp8zXmym2w8Bdz6zFcXqk8TaGgt+mr2 KX51MxCd7d/0UQY8C8zC8EkLWsJ7AxpQTZm0Mtl+sH1rOyVuH1UYyphQSd3KhzuaZ8 /GaTuToSVdESg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 15 May 2023 12:49:41 +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 v4 1/5] mtd: rawnand: meson: fix command sequence for read/write Date: Mon, 15 May 2023 12:44:35 +0300 Message-ID: <20230515094440.3552094-2-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230515094440.3552094-1-AVKrasnov@sberdevices.ru> References: <20230515094440.3552094-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/05/15 04:03:00 #21308474 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_024950_984402_AC453C93 X-CRM114-Status: GOOD ( 14.79 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org This fixes read/write functionality by: 1) Changing NFC_CMD_RB_INT bit value. 2) Adding extra NAND_CMD_STATUS command on each r/w request. 3) Adding extra idle commands during r/w request. 4) Adding extra NAND_CMD_READ0 on each read request. Without this patch driver works unstable, for example there are a lot of ECC errors. Fixes: 8fae856c5350 ("mtd: rawnand: meson: add support for Amlogic NAND flash controller") Suggested-by: Liang Yang Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 074e14225c06..2f4d8c84186b 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -37,7 +37,7 @@ #define NFC_CMD_SCRAMBLER_ENABLE BIT(19) #define NFC_CMD_SCRAMBLER_DISABLE 0 #define NFC_CMD_SHORTMODE_DISABLE 0 -#define NFC_CMD_RB_INT BIT(14) +#define NFC_CMD_RB_INT ((0xb << 10) | BIT(18) | BIT(16)) #define NFC_CMD_GET_SIZE(x) (((x) >> 22) & GENMASK(4, 0)) @@ -392,7 +392,7 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, } } -static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) +static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms, int cmd_read0) { u32 cmd, cfg; int ret = 0; @@ -407,17 +407,29 @@ static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) reinit_completion(&nfc->completion); + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_STATUS; + writel(cmd, nfc->reg_base + NFC_REG_CMD); + meson_nfc_cmd_idle(nfc, 5); + /* use the max erase time as the maximum clock for waiting R/B */ - cmd = NFC_CMD_RB | NFC_CMD_RB_INT - | nfc->param.chip_select | nfc->timing.tbers_max; + cmd = NFC_CMD_RB | NFC_CMD_RB_INT | nfc->timing.tbers_max; writel(cmd, nfc->reg_base + NFC_REG_CMD); + meson_nfc_cmd_idle(nfc, 2); ret = wait_for_completion_timeout(&nfc->completion, msecs_to_jiffies(timeout_ms)); if (ret == 0) - ret = -1; + return -1; - return ret; + if (!cmd_read0) + return 0; + + cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_READ0; + writel(cmd, nfc->reg_base + NFC_REG_CMD); + meson_nfc_drain_cmd(nfc); + meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); + + return 0; } static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) @@ -623,7 +635,7 @@ static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand, if (in) { nfc->cmdfifo.rw.cmd1 = cs | NFC_CMD_CLE | NAND_CMD_READSTART; writel(nfc->cmdfifo.rw.cmd1, nfc->reg_base + NFC_REG_CMD); - meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tR_max)); + meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tR_max), 1); } else { meson_nfc_cmd_idle(nfc, nfc->timing.tadl); } @@ -669,7 +681,7 @@ static int meson_nfc_write_page_sub(struct nand_chip *nand, 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_queue_rb(nfc, PSEC_TO_MSEC(sdr->tPROG_max), 0); meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_TO_DEVICE); @@ -952,7 +964,7 @@ static int meson_nfc_exec_op(struct nand_chip *nand, break; case NAND_OP_WAITRDY_INSTR: - meson_nfc_queue_rb(nfc, instr->ctx.waitrdy.timeout_ms); + meson_nfc_queue_rb(nfc, instr->ctx.waitrdy.timeout_ms, 1); if (instr->delay_ns) meson_nfc_cmd_idle(nfc, delay_idle); break; From patchwork Mon May 15 09:44:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13241190 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 68558C77B7D for ; Mon, 15 May 2023 09:50:18 +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=pfV50Sytd0M05McDTUJTouzbTOCwysBKZWUhCyBvoN4=; b=UGBv7q+zR1Qs1C EdXNcTJJ6DCUcGacjX0aoNbtGOhsMIS6BBMV7+4EgKBx2UaquAeplTwK9fE50I3k33YumB96bw0/a z4OhYDKFNak1L64iZXXW3CK0ER9SEReDxxXbl4Icj0gcsxMhDIJXDEuxtiq1ljE5VLWeewxM5U6LN 20McPkmNB3cpwD+8tD9SpDHenvesXiC19PFr5hVdJKHhbQiZ8B6FfB90yXEjNoIRvaDhmLJqeuJwI qcR1uG4w5VCcUtiYIgs2dV2V5+L68cY7vhsvu0Eu8SvuR1W834juDAyAEAmvO9hdqDUqsvbQpRMrZ JjGBiXIYnqy8/YrabA1A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyUqI-001cun-1n; Mon, 15 May 2023 09:50:10 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyUpy-001chA-1B; Mon, 15 May 2023 09:49:55 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 74BEC5FD1F; Mon, 15 May 2023 12:49:44 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1684144184; bh=pEF++StqHaJs8BkkLf5RGwoBxGzq/X7P/F6LftuEvCE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=NmkcqmNXqU+04fXViSOwj2ALbT9Fu6Z+dqopvsC4ukgl32qwEN0q2lfR3ARk9J2o3 X9RUzZn8cMTA8APdJ6iJw5rQCDnDVpW6y/8Xshyq3+GVCFdUMTgnjJ42TmOUt4Ciqe JXKlC/g4Jk89p8ziTeg2aQ9n/wdlSXCRWtEcPPWqTgPGn3tdXsXsmIxQiAV1C02vCo 2IvrRdBtzr7HksxAl6q0ph67/gH6UvmtNgEj4JcQ+4TErHUaOWUURaX5JkEoZq5CT5 NKfwUn4N3eKsbLyW3nmzaPJRfb0PgHkgsQKzobPL+4+U/DxnUgUqxRaVIckXdFOmNb XvgtOmn/blHEQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 15 May 2023 12:49:44 +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 v4 2/5] mtd: rawnand: meson: move OOB to non-protected ECC area Date: Mon, 15 May 2023 12:44:36 +0300 Message-ID: <20230515094440.3552094-3-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230515094440.3552094-1-AVKrasnov@sberdevices.ru> References: <20230515094440.3552094-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/05/15 04:03:00 #21308474 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_024950_974772_09DF2915 X-CRM114-Status: GOOD ( 25.92 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org This moves free bytes of OOB to non-protected ECC area. It is needed to make JFFS2 works correctly with this NAND controller. Problem fires when JFFS2 driver writes cleanmarker to some page and later it tries to write to this page - write will be done successfully, but after that such page becomes unreadable due to invalid ECC codes. This happens because second write needs to update ECC codes, but it is impossible to do it correctly without block erase. So idea of this patch is to split accesses to OOB free bytes and data on each page - now both of them does not depends on each other. Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 192 ++++++++++++++++++++++++------ 1 file changed, 155 insertions(+), 37 deletions(-) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 2f4d8c84186b..8526a6b87720 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -108,6 +108,9 @@ #define PER_INFO_BYTE 8 +#define NFC_USER_BYTES 2 +#define NFC_OOB_PER_ECC(nand) ((nand)->ecc.bytes + NFC_USER_BYTES) + struct meson_nfc_nand_chip { struct list_head node; struct nand_chip nand; @@ -122,6 +125,7 @@ struct meson_nfc_nand_chip { u8 *data_buf; __le64 *info_buf; u32 nsels; + u8 *oob_buf; u8 sels[]; }; @@ -338,7 +342,7 @@ static u8 *meson_nfc_oob_ptr(struct nand_chip *nand, int i) struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); int len; - len = nand->ecc.size * (i + 1) + (nand->ecc.bytes + 2) * i; + len = nand->ecc.size * (i + 1) + NFC_OOB_PER_ECC(nand) * i; return meson_chip->data_buf + len; } @@ -349,7 +353,7 @@ static u8 *meson_nfc_data_ptr(struct nand_chip *nand, int i) int len, temp; temp = nand->ecc.size + nand->ecc.bytes; - len = (temp + 2) * i; + len = (temp + NFC_USER_BYTES) * i; return meson_chip->data_buf + len; } @@ -357,29 +361,47 @@ static u8 *meson_nfc_data_ptr(struct nand_chip *nand, int i) static void meson_nfc_get_data_oob(struct nand_chip *nand, u8 *buf, u8 *oobbuf) { + struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); + struct mtd_info *mtd = nand_to_mtd(nand); int i, oob_len = 0; u8 *dsrc, *osrc; + u8 *oobtail; - oob_len = nand->ecc.bytes + 2; + oob_len = NFC_OOB_PER_ECC(nand); for (i = 0; i < nand->ecc.steps; i++) { if (buf) { dsrc = meson_nfc_data_ptr(nand, i); memcpy(buf, dsrc, nand->ecc.size); buf += nand->ecc.size; } - osrc = meson_nfc_oob_ptr(nand, i); - memcpy(oobbuf, osrc, oob_len); - oobbuf += oob_len; + + if (oobbuf) { + osrc = meson_nfc_oob_ptr(nand, i); + memcpy(oobbuf, osrc, oob_len); + oobbuf += oob_len; + } } + + if (!oobbuf) + return; + + oobtail = meson_chip->data_buf + nand->ecc.steps * + (nand->ecc.size + oob_len); + + /* 'oobbuf' if already shifted to the start of unused area. */ + memcpy(oobbuf, oobtail, mtd->oobsize - nand->ecc.steps * oob_len); } static void meson_nfc_set_data_oob(struct nand_chip *nand, const u8 *buf, u8 *oobbuf) { + struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); + struct mtd_info *mtd = nand_to_mtd(nand); int i, oob_len = 0; u8 *dsrc, *osrc; + u8 *oobtail; - oob_len = nand->ecc.bytes + 2; + oob_len = NFC_OOB_PER_ECC(nand); for (i = 0; i < nand->ecc.steps; i++) { if (buf) { dsrc = meson_nfc_data_ptr(nand, i); @@ -390,6 +412,12 @@ static void meson_nfc_set_data_oob(struct nand_chip *nand, memcpy(osrc, oobbuf, oob_len); oobbuf += oob_len; } + + oobtail = meson_chip->data_buf + nand->ecc.steps * + (nand->ecc.size + oob_len); + + /* 'oobbuf' if already shifted to the start of unused area. */ + memcpy(oobtail, oobbuf, mtd->oobsize - nand->ecc.steps * oob_len); } static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms, int cmd_read0) @@ -436,25 +464,12 @@ static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) { struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); __le64 *info; - int i, count; - - for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) { - info = &meson_chip->info_buf[i]; - *info |= oob_buf[count]; - *info |= oob_buf[count + 1] << 8; - } -} - -static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) -{ - struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); - __le64 *info; - int i, count; + int i; - for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) { + for (i = 0; i < nand->ecc.steps; i++) { info = &meson_chip->info_buf[i]; - oob_buf[count] = *info; - oob_buf[count + 1] = *info >> 8; + /* Always ignore user bytes programming. */ + *info |= 0xffff; } } @@ -698,18 +713,92 @@ static int meson_nfc_write_page_raw(struct nand_chip *nand, const u8 *buf, return meson_nfc_write_page_sub(nand, page, 1); } +static u32 meson_nfc_get_oob_bytes(struct nand_chip *nand) +{ + struct mtd_info *mtd = nand_to_mtd(nand); + + return mtd->oobsize - nand->ecc.steps * NFC_OOB_PER_ECC(nand); +} + +static int __meson_nfc_write_oob(struct nand_chip *nand, int page, u8 *oob_buf) +{ + struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); + struct mtd_info *mtd = nand_to_mtd(nand); + u32 page_size = mtd->writesize + mtd->oobsize; + u32 oob_bytes = meson_nfc_get_oob_bytes(nand); + int ret; + + if (!oob_bytes) + return 0; + + ret = nand_prog_page_begin_op(nand, page, 0, NULL, 0); + if (ret) + return ret; + + memcpy(meson_chip->oob_buf, oob_buf + (mtd->oobsize - oob_bytes), + oob_bytes); + + ret = nand_change_write_column_op(nand, page_size - oob_bytes, + meson_chip->oob_buf, + oob_bytes, false); + if (ret) + return ret; + + return nand_prog_page_end_op(nand); +} + +static int __meson_nfc_read_oob(struct nand_chip *nand, int page, + u8 *oob_buf) +{ + struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); + struct mtd_info *mtd = nand_to_mtd(nand); + u32 oob_bytes; + u32 page_size; + int ret; + + oob_bytes = meson_nfc_get_oob_bytes(nand); + + if (!oob_bytes) + return 0; + + ret = nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; + + page_size = mtd->writesize + mtd->oobsize; + + ret = nand_change_read_column_op(nand, page_size - oob_bytes, + meson_chip->oob_buf, + oob_bytes, false); + + if (!ret) + memcpy(oob_buf + (mtd->oobsize - oob_bytes), + meson_chip->oob_buf, + oob_bytes); + + return ret; +} + static int meson_nfc_write_page_hwecc(struct nand_chip *nand, const u8 *buf, int oob_required, int page) { struct mtd_info *mtd = nand_to_mtd(nand); struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); u8 *oob_buf = nand->oob_poi; + int ret; memcpy(meson_chip->data_buf, buf, mtd->writesize); memset(meson_chip->info_buf, 0, nand->ecc.steps * PER_INFO_BYTE); meson_nfc_set_user_byte(nand, oob_buf); - return meson_nfc_write_page_sub(nand, page, 0); + ret = meson_nfc_write_page_sub(nand, page, 0); + if (ret) + return ret; + + if (oob_required) + ret = __meson_nfc_write_oob(nand, page, oob_buf); + + return ret; } static void meson_nfc_check_ecc_pages_valid(struct meson_nfc *nfc, @@ -783,7 +872,7 @@ static int meson_nfc_read_page_raw(struct nand_chip *nand, u8 *buf, if (ret) return ret; - meson_nfc_get_data_oob(nand, buf, oob_buf); + meson_nfc_get_data_oob(nand, buf, oob_required ? oob_buf : NULL); return 0; } @@ -803,12 +892,12 @@ static int meson_nfc_read_page_hwecc(struct nand_chip *nand, u8 *buf, if (ret) return ret; - meson_nfc_get_user_byte(nand, oob_buf); ret = meson_nfc_ecc_correct(nand, &bitflips, &correct_bitmap); if (ret == ECC_CHECK_RETURN_FF) { if (buf) memset(buf, 0xff, mtd->writesize); memset(oob_buf, 0xff, mtd->oobsize); + return bitflips; } else if (ret < 0) { if ((nand->options & NAND_NEED_SCRAMBLING) || !buf) { mtd->ecc_stats.failed++; @@ -820,12 +909,14 @@ static int meson_nfc_read_page_hwecc(struct nand_chip *nand, u8 *buf, for (i = 0; i < nand->ecc.steps ; i++) { u8 *data = buf + i * ecc->size; - u8 *oob = nand->oob_poi + i * (ecc->bytes + 2); + u8 *oob = nand->oob_poi + i * NFC_OOB_PER_ECC(nand); if (correct_bitmap & BIT_ULL(i)) continue; + ret = nand_check_erased_ecc_chunk(data, ecc->size, - oob, ecc->bytes + 2, + oob, + NFC_OOB_PER_ECC(nand), NULL, 0, ecc->strength); if (ret < 0) { @@ -839,17 +930,30 @@ static int meson_nfc_read_page_hwecc(struct nand_chip *nand, u8 *buf, memcpy(buf, meson_chip->data_buf, mtd->writesize); } + if (oob_required) + __meson_nfc_read_oob(nand, page, oob_buf); + return bitflips; } static int meson_nfc_read_oob_raw(struct nand_chip *nand, int page) { - return meson_nfc_read_page_raw(nand, NULL, 1, page); + return __meson_nfc_read_oob(nand, page, nand->oob_poi); } static int meson_nfc_read_oob(struct nand_chip *nand, int page) { - return meson_nfc_read_page_hwecc(nand, NULL, 1, page); + return __meson_nfc_read_oob(nand, page, nand->oob_poi); +} + +static int meson_nfc_write_oob_raw(struct nand_chip *nand, int page) +{ + return __meson_nfc_write_oob(nand, page, nand->oob_poi); +} + +static int meson_nfc_write_oob(struct nand_chip *nand, int page) +{ + return __meson_nfc_write_oob(nand, page, nand->oob_poi); } static bool meson_nfc_is_buffer_dma_safe(const void *buffer) @@ -982,7 +1086,7 @@ static int meson_ooblayout_ecc(struct mtd_info *mtd, int section, if (section >= nand->ecc.steps) return -ERANGE; - oobregion->offset = 2 + (section * (2 + nand->ecc.bytes)); + oobregion->offset = NFC_USER_BYTES + section * NFC_OOB_PER_ECC(nand); oobregion->length = nand->ecc.bytes; return 0; @@ -992,12 +1096,16 @@ static int meson_ooblayout_free(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion) { struct nand_chip *nand = mtd_to_nand(mtd); + u32 oob_bytes = meson_nfc_get_oob_bytes(nand); if (section >= nand->ecc.steps) return -ERANGE; - oobregion->offset = section * (2 + nand->ecc.bytes); - oobregion->length = 2; + /* Split rest of OOB area (not covered by ECC engine) per each + * ECC section. This will be OOB data available to user. + */ + oobregion->offset = (section + nand->ecc.steps) * NFC_OOB_PER_ECC(nand); + oobregion->length = oob_bytes / nand->ecc.steps; return 0; } @@ -1184,6 +1292,9 @@ static int meson_nand_bch_mode(struct nand_chip *nand) static void meson_nand_detach_chip(struct nand_chip *nand) { + struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); + + kfree(meson_chip->oob_buf); meson_nfc_free_buffer(nand); } @@ -1225,9 +1336,9 @@ static int meson_nand_attach_chip(struct nand_chip *nand) nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; nand->ecc.write_page_raw = meson_nfc_write_page_raw; nand->ecc.write_page = meson_nfc_write_page_hwecc; - nand->ecc.write_oob_raw = nand_write_oob_std; - nand->ecc.write_oob = nand_write_oob_std; + nand->ecc.write_oob_raw = meson_nfc_write_oob_raw; + nand->ecc.write_oob = meson_nfc_write_oob; nand->ecc.read_page_raw = meson_nfc_read_page_raw; nand->ecc.read_page = meson_nfc_read_page_hwecc; nand->ecc.read_oob_raw = meson_nfc_read_oob_raw; @@ -1237,9 +1348,16 @@ static int meson_nand_attach_chip(struct nand_chip *nand) dev_err(nfc->dev, "16bits bus width not supported"); return -EINVAL; } + + meson_chip->oob_buf = kmalloc(nand->ecc.bytes, GFP_KERNEL); + if (!meson_chip->oob_buf) + return -ENOMEM; + ret = meson_chip_buffer_init(nand); - if (ret) + if (ret) { + kfree(meson_chip->oob_buf); return -ENOMEM; + } return ret; } From patchwork Mon May 15 09:44:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13241188 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 3B2C6C77B7D for ; Mon, 15 May 2023 09:50:08 +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=iTKX627+SycihNtm1eDbssbC08LmSTcBT7rRe4GsQ1Y=; b=vMIferf8tc7Sd2 47dHhRvHZMK/YIs1kM51MNPxpCEbL4WqN5jo+y2Fq/iAZCEWwlnte9JGmaRAynK61UiEYrEtdMUQE ZvL1Zd80JsJzn2NWfyDJu9Tjv9wzU0hbPEpa5CsbaVlRtXq7Zqdy5FNZXUOHln+NbkOn3XnR2WNMp BKU6BxrgJ6WkX8XB5RA0EfVx1v8Cj+vJNJmI7z+dmXlcaJZPCu1rmPAmAKbwijga1EJdR0I6MCXHR fllctn4xf2ELKgisMeCFlnS2gkD4RFALE+qxyXld5/7xiRs7uz+7csHXhmvBYTEglCZcpg9XWilZV 1arz/+TvspVYq/TcgiQw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyUq9-001coW-06; Mon, 15 May 2023 09:50:01 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyUpy-001chp-1H; Mon, 15 May 2023 09:49:54 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id A1E125FD20; Mon, 15 May 2023 12:49:46 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1684144186; bh=Vz83jCy0spHA1ZRural7ddOQ1iT++4tUqhV7Ue23lk4=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=qcn0IQfHKcGxRJrBonclWUzFGa4XbN3UU6+FFP2AsksiDymQ6qNyJELtmB+wp36eq PGVeFzgUnZww1VpOhjHQc58e5YFXfAN5i8YvvR4CIUctnyZ1aY4dVrn4aGRuy0NQfd m12CbKfAW7nSCh8ufHe4Hct5q1juezSISYESH0Nbt8QI243gw1FewU8wrF5fZ+YVAi lTjuvjuIfvhtsNSDqqR8z+GT+Qb4/2WO/sIIfYliAHUQ9QPFWwmd5Dz09Bm1II3kbW nDBgUSxU1tD1iqMAjGKSpGg4GvssvSm0RyiHy2X3nvvkVeqZqUnoQSXqFXVO08SkuM +nqn2DBNfqqKQ== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 15 May 2023 12:49:46 +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 v4 3/5] mtd: rawnand: meson: always read whole OOB bytes Date: Mon, 15 May 2023 12:44:37 +0300 Message-ID: <20230515094440.3552094-4-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230515094440.3552094-1-AVKrasnov@sberdevices.ru> References: <20230515094440.3552094-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/05/15 04:03:00 #21308474 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_024950_964191_55254E9C X-CRM114-Status: GOOD ( 11.24 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org This changes size of read access to OOB area by reading all bytes of OOB (free bytes + ECC engine bytes). Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index 8526a6b87720..a31106c943d7 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -755,6 +755,30 @@ static int __meson_nfc_read_oob(struct nand_chip *nand, int page, u32 oob_bytes; u32 page_size; int ret; + int i; + + /* Read ECC codes and user bytes. */ + for (i = 0; i < nand->ecc.steps; i++) { + u32 ecc_offs = nand->ecc.size * (i + 1) + + NFC_OOB_PER_ECC(nand) * i; + + ret = nand_read_page_op(nand, page, 0, NULL, 0); + if (ret) + return ret; + + /* Use temporary buffer, because 'nand_change_read_column_op()' + * seems work with some alignment, so we can't read data to + * 'oob_buf' directly. + */ + ret = nand_change_read_column_op(nand, ecc_offs, meson_chip->oob_buf, + NFC_OOB_PER_ECC(nand), false); + if (ret) + return ret; + + memcpy(oob_buf + i * NFC_OOB_PER_ECC(nand), + meson_chip->oob_buf, + NFC_OOB_PER_ECC(nand)); + } oob_bytes = meson_nfc_get_oob_bytes(nand); From patchwork Mon May 15 09:44:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13241186 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 00253C7EE22 for ; Mon, 15 May 2023 09:50:00 +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=W3KKfhpGQSEOFwyU6mXOu7Kbtyp/E6zfhyzHjukKJM0=; b=Ze2l8ZkzwTaIZB A3BkkmhmCIw7WpRvJkVFzBUiMqSssq7HtZo9UvpG6sNg1nYCqrChwjILjs2hmqP01tDHv1P17ZeqR B3hbM9tFbaiTbi96oId3G0mUyvivpUgEGxOgrpGxaS/jYad8CDc2v2KcFzNlgY/pJ1MgXUvB9LoCz 23E17Ldh3jHF07bkUJj7nOEB//1sJdmo+4HeWwEWBYMBhPf3lXjqPLKvVPEZqDFXoPpZVYny9CyC7 hccynSPVACATRN4AfVG5iK5AMcPbfugdG82AJs+wt4E6vdxU5CEwo4P/shhRoUG/knz7MkWLCo3vd PUmsCv9evNUBNxugQmfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyUq1-001ckT-1R; Mon, 15 May 2023 09:49:53 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyUpy-001ciM-1o; Mon, 15 May 2023 09:49:52 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 20FF85FD1C; Mon, 15 May 2023 12:49:49 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1684144189; bh=Cp2WZDhRd14s0/tdC29j8EeRZXPpQXafc9tJ23F+heQ=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=l7S7ZdrQXqsYnJRKqDcjcK4k0LtwGJt3A+e7xQ2o4cCsAyiB93hK7Baf1c/YJdX+i Wwsy07O1y+T7IUo5+qA7KTTEnfj+4DcPQnlLfREnw4aSG6Aq1t/2Wdt2TyFfJqKL9B BwW5FceO+WJ6wy3xZemIyuMMAayBHjGO9ilROrlN/2KsFTifJAGbTk+dW2amRpOQ6d EkXT4cQTPl+ZtguGdLU6AMtm7rxFD44iTG4/IA5k7qZzJ3npLNU8ytt5zI22BX5/nd OaAToqKCbaZ62d//8LExrEU1cFcMDZJhIXfwklFf5yKslbZfGBpi2rY6gKXG5XiafX 377DUbqbHcgMg== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 15 May 2023 12:49:49 +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 v4 4/5] mtd: rawnand: meson: check buffer length Date: Mon, 15 May 2023 12:44:38 +0300 Message-ID: <20230515094440.3552094-5-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230515094440.3552094-1-AVKrasnov@sberdevices.ru> References: <20230515094440.3552094-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/05/15 04:03:00 #21308474 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_024950_959189_E8E4B338 X-CRM114-Status: GOOD ( 13.36 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=archiver.kernel.org@lists.infradead.org This NAND controller has limited buffer length, so check it before command execution to avoid length trim. Also check MTD write size on chip attach. Signed-off-by: Arseniy Krasnov --- drivers/mtd/nand/raw/meson_nand.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/mtd/nand/raw/meson_nand.c b/drivers/mtd/nand/raw/meson_nand.c index a31106c943d7..dc0d7160520b 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -111,6 +111,8 @@ #define NFC_USER_BYTES 2 #define NFC_OOB_PER_ECC(nand) ((nand)->ecc.bytes + NFC_USER_BYTES) +#define NFC_CMD_RAW_LEN GENMASK(13, 0) + struct meson_nfc_nand_chip { struct list_head node; struct nand_chip nand; @@ -284,7 +286,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 | scrambler | DMA_DIR(dir); writel(cmd, nfc->reg_base + NFC_REG_CMD); return; } @@ -562,6 +564,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,7 +576,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; writel(cmd, nfc->reg_base + NFC_REG_CMD); meson_nfc_drain_cmd(nfc); @@ -590,12 +595,15 @@ 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) return ret; - cmd = NFC_CMD_M2N | (len & GENMASK(13, 0)); + cmd = NFC_CMD_M2N | len; writel(cmd, nfc->reg_base + NFC_REG_CMD); meson_nfc_drain_cmd(nfc); @@ -1328,6 +1336,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) { @@ -1339,6 +1348,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 Mon May 15 09:44:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arseniy Krasnov X-Patchwork-Id: 13241191 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 82ED3C77B7D for ; Mon, 15 May 2023 09:50:21 +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=FXUhQ1SQ2IiCrNi4t01cYYdoCmiKkZnG39iE/STWM6A=; b=UoDFAVOJjVG/Hw DHc7hV5VpEFCds7QNn4DUco8LXuHC4xJ9lA9C86hIAScZJE40HFVMfdAC6BinzX73SLx/pNu6G6bQ gaaE1eBHA70c/eqLLPFUkgvCGsF23aeuX2LwGpaI3qRDl7lIW2Mdd8pBZjG4uHkFhoLFQBLVY597n M9gN70e3i2O91Q62VfKYzdLEB2opWyajB/Co7G/hdgx0ouO/pwwSaN89Zuordihl8eK3Tiw8ot4IZ 4R1nKu321OPO8y+t6/M2NoXPvg6p72jrXB85TuIMLPMpJHL3htiMwR0MCqIRJ1+xU7co7vOXQg+j2 QqzFxK2UJ/wLI8L6gk5Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pyUqK-001cwe-1w; Mon, 15 May 2023 09:50:12 +0000 Received: from mx.sberdevices.ru ([45.89.227.171]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pyUq2-001ckN-1f; Mon, 15 May 2023 09:49:55 +0000 Received: from s-lin-edge02.sberdevices.ru (localhost [127.0.0.1]) by mx.sberdevices.ru (Postfix) with ESMTP id 7A8075FD21; Mon, 15 May 2023 12:49:51 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sberdevices.ru; s=mail; t=1684144191; bh=GYMVAyNcEuGbdTw4UQJwZVEs5ZVQ9VYLcOmrazaSGLg=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=J0S+OLmRrYNNCyVmjmzTzVShTLMYzM448WyH5DyT6ZKh7xsGVhIM+z2g9ErLxvTxY ieWStf5ksPqr9gUSQ8J/lajuyAjoFgArwKs5U5ZHZ5grTcvU6klZvqLWY1aJcms7WF HbXrBZnTqZxZRDdjtbRMg3yQNcYHqXbLwIssYcE89FwOU3j/jiblDshxuXCoUI8mWi kMd+ZLpXkh77cNSkV3FuZsG8/Lfoga/JLAcLdTN3DTXZqBslc5VODBGi9PZsEL2pnG YFVdBnvjbNwzPQPwu88u+UF8+PIWyCoSXeOpH1DknQneqNROuHD6hw9GVVv4AI9wCH zDBUkVVXg5r2w== Received: from S-MS-EXCH01.sberdevices.ru (S-MS-EXCH01.sberdevices.ru [172.16.1.4]) by mx.sberdevices.ru (Postfix) with ESMTP; Mon, 15 May 2023 12:49:51 +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 v4 5/5] mtd: rawnand: meson: remove unneeded bitwise OR with zeroes Date: Mon, 15 May 2023 12:44:39 +0300 Message-ID: <20230515094440.3552094-6-AVKrasnov@sberdevices.ru> X-Mailer: git-send-email 2.35.0 In-Reply-To: <20230515094440.3552094-1-AVKrasnov@sberdevices.ru> References: <20230515094440.3552094-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/05/15 04:03:00 #21308474 X-KSMG-AntiVirus-Status: Clean, skipped X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230515_024954_739287_6088D271 X-CRM114-Status: GOOD ( 10.57 ) X-BeenThere: linux-amlogic@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-amlogic" Errors-To: linux-amlogic-bounces+linux-amlogic=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 dc0d7160520b..0aac784075a5 100644 --- a/drivers/mtd/nand/raw/meson_nand.c +++ b/drivers/mtd/nand/raw/meson_nand.c @@ -630,12 +630,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; }