From patchwork Mon Sep 6 13:29:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 1524957 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=bombadil.20210309 header.b=zfSdEAOY; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4H38RT4HQpz9sRf for ; Mon, 6 Sep 2021 23:30:45 +1000 (AEST) 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: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:In-Reply-To:References: List-Owner; bh=TttgGGKonUoXt939luWs7K5NZMmIhrRyCZ+czfnpwY4=; b=zfSdEAOYpUi9sn RJKRL8ghQIDjjsqaYIpvNIP3B7ChQrujIWIviIYDNHn38tMq8lVWxNTXyLzN/Q6Yjtc9Zq25qUmzG Mnc4AoeoQCpGi30k1QnddecUzi+QHyiC5s3W2EfOdKUR/SsFxfqFV2bWr4Putq2VLMdR/JQooDNU1 Cvlp/aVi94X0XKwfsEr2WmKkSFMPc1nWxvfu3NWmjhy4mmZgHahwHcqNjrrl4FaoW2PyyPeMZjCHn z3gSsAjpB/PUnFvhz3vIbVTs+zRflmrIFyGe3fHJ5GqLyJJs3kZMzC+J6EztzcsoNaFGEX38ducb3 oCgEQQCZhDVexdo3/t9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNEh8-000ulQ-7Q; Mon, 06 Sep 2021 13:29:54 +0000 Received: from relay10.mail.gandi.net ([217.70.178.230]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNEh5-000ukX-Jm for linux-mtd@lists.infradead.org; Mon, 06 Sep 2021 13:29:53 +0000 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 53FFE240010; Mon, 6 Sep 2021 13:29:43 +0000 (UTC) From: Miquel Raynal To: Naga Sureshkumar Relli , Michal Simek , Amit Kumar Mahapatra , Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Cc: Thomas Petazzoni , Boris Brezillon , Miquel Raynal Subject: [PATCH 1/3] mtd: rawnand: Add a helper to check if a CHANGE_READ_COLUMN is possible Date: Mon, 6 Sep 2021 15:29:40 +0200 Message-Id: <20210906132942.36972-1-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210906_062951_810455_52014DCE X-CRM114-Status: UNSURE ( 9.93 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Certain controllers are limited and cannot perform all type of CHANGE_READ_COLUMN. Let's add a helper that allows checking this. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 15 +++++++++++++++ include/linux/mtd/rawnand.h | 4 ++++ 2 files changed, 19 insertions(+) Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.70.178.230 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.70.178.230 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Certain controllers are limited and cannot perform all type of CHANGE_READ_COLUMN. Let's add a helper that allows checking this. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 15 +++++++++++++++ include/linux/mtd/rawnand.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 57a583149cc0..7f29f27bb6fd 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -1312,6 +1312,15 @@ int nand_read_param_page_op(struct nand_chip *chip, u8 page, void *buf, int nand_change_read_column_op(struct nand_chip *chip, unsigned int offset_in_page, void *buf, unsigned int len, bool force_8bit) +{ + return nand_check_change_read_column_op(chip, offset_in_page, buf, len, + force_8bit, false); +} + +int nand_check_change_read_column_op(struct nand_chip *chip, + unsigned int offset_in_page, void *buf, + unsigned int len, bool force_8bit, + bool check_only) { struct mtd_info *mtd = nand_to_mtd(chip); @@ -1349,9 +1358,15 @@ int nand_change_read_column_op(struct nand_chip *chip, instrs[3].ctx.data.force_8bit = force_8bit; + if (check_only) + return nand_check_op(chip, &op); + return nand_exec_op(chip, &op); } + if (check_only) + return 0; + chip->legacy.cmdfunc(chip, NAND_CMD_RNDOUT, offset_in_page, -1); if (len) chip->legacy.read_buf(chip, buf, len); diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index b2f9dd3cbd69..a453386aee70 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -1523,6 +1523,10 @@ int nand_read_page_op(struct nand_chip *chip, unsigned int page, int nand_change_read_column_op(struct nand_chip *chip, unsigned int offset_in_page, void *buf, unsigned int len, bool force_8bit); +int nand_check_change_read_column_op(struct nand_chip *chip, + unsigned int offset_in_page, void *buf, + unsigned int len, bool force_8bit, + bool check_only); int nand_read_oob_op(struct nand_chip *chip, unsigned int page, unsigned int offset_in_page, void *buf, unsigned int len); int nand_prog_page_begin_op(struct nand_chip *chip, unsigned int page, From patchwork Mon Sep 6 13:29:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 1524958 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=bombadil.20210309 header.b=EZVoc4ty; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4H38Rl0t7Qz9sRf for ; Mon, 6 Sep 2021 23:30:59 +1000 (AEST) 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=crbaaGEbvAb1gIyXj5DKfhmCYBGkdArHKpIypTAnEZo=; b=EZVoc4tyH34Gy7 9ORl9ffuh53DbBA9QV4Kcj7NKmhHB8JZA+bQfJBJ8ronpKHsvf3cvA7Y2P2G4UIuIrCxDSjL86C+F CjEIVW9P964FamvqEZ/INTRUkh4H6FHGasg6ccKXIoPXGikTgMXLK7JDos5q3jI1FGQg09vBCAVkR 7q5olyUCWfQ1LLLqsh4cfCKYZ7w9LP9YAu1vNblmrzYOydujnYPvb7j7ZjFzLggLuzTOEDWK3u5Rj lxDTfKdk7ugAEdzI+3zMDi/YQrJtHC8/YNgEB4ICahshfEqPL50RvhOvtGObH6Q/AAgzHJIeMVRZQ 5PKoasU/TS72eTmuEfBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNEhX-000unL-Kv; Mon, 06 Sep 2021 13:30:19 +0000 Received: from relay10.mail.gandi.net ([217.70.178.230]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNEh5-000ukY-KQ for linux-mtd@lists.infradead.org; Mon, 06 Sep 2021 13:29:54 +0000 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 72B43240012; Mon, 6 Sep 2021 13:29:45 +0000 (UTC) From: Miquel Raynal To: Naga Sureshkumar Relli , Michal Simek , Amit Kumar Mahapatra , Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Cc: Thomas Petazzoni , Boris Brezillon , Miquel Raynal Subject: [PATCH 2/3] mtd: rawnand: Check the CHANGE_READ_COLUMN from nand_read_subpage() is supported Date: Mon, 6 Sep 2021 15:29:41 +0200 Message-Id: <20210906132942.36972-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210906132942.36972-1-miquel.raynal@bootlin.com> References: <20210906132942.36972-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210906_062951_851149_AF58CAFF X-CRM114-Status: UNSURE ( 9.65 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: There are constraint controllers which do not support CHANGE_READ_COLUMNs at any offset. In particular, the offset alignment might be an issue. Ensure that the operation is supported before trying it. Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.70.178.230 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.70.178.230 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org There are constraint controllers which do not support CHANGE_READ_COLUMNs at any offset. In particular, the offset alignment might be an issue. Ensure that the operation is supported before trying it. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index 7f29f27bb6fd..8175635b9802 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -3065,10 +3065,19 @@ static int nand_read_subpage(struct nand_chip *chip, uint32_t data_offs, (busw - 1)) aligned_len++; - ret = nand_change_read_column_op(chip, - mtd->writesize + aligned_pos, - &chip->oob_poi[aligned_pos], - aligned_len, false); + ret = nand_check_change_read_column_op(chip, + mtd->writesize + aligned_pos, + &chip->oob_poi[aligned_pos], + aligned_len, false, true); + if (!ret) + ret = nand_change_read_column_op(chip, + mtd->writesize + aligned_pos, + &chip->oob_poi[aligned_pos], + aligned_len, false); + else + ret = nand_change_read_column_op(chip, mtd->writesize, + chip->oob_poi, + mtd->oobsize, false); if (ret) return ret; } From patchwork Mon Sep 6 13:29:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 1524956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=bombadil.20210309 header.b=MDabalyt; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4H38RT58lTz9sVw for ; Mon, 6 Sep 2021 23:30:45 +1000 (AEST) 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=UljSWGDiX/hK6MDl/mg5arubH7ywsidqjnQ79peY8XI=; b=MDabalytzgKq0S nbIQBS7XYKFdQmXvden99AmgI7SPmvvUTtfN3rOFRWxkgrrwWMzNWdAXCuS+g11mm+BncMN1cmE3b b/c6mPGOMqIXN57NIFEKsAiKwPFhX4Wj7wZjntE/Y+jQ0PiJe6E7RB51Yyz6+0bF7Qf/jV4Jf2nHC PLAyTDfV2t/4ltTCTG7wuffu/l6o2387xLWth0PgFnuOtgoOM6Rztlxi+aa1hmDzOEWMn8yMnh014 +3ZxZs95gW+m29uCC0M9oPZTfKK5xnpdffstLEFbP0FgJwqllZjW1J3uV3ha6+4VSmlzn//0GqPlm bFIWibR9DiYzzAq8hIxA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNEhK-000umJ-V3; Mon, 06 Sep 2021 13:30:06 +0000 Received: from relay10.mail.gandi.net ([217.70.178.230]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mNEh5-000ukZ-9a for linux-mtd@lists.infradead.org; Mon, 06 Sep 2021 13:29:53 +0000 Received: (Authenticated sender: miquel.raynal@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 79E48240011; Mon, 6 Sep 2021 13:29:46 +0000 (UTC) From: Miquel Raynal To: Naga Sureshkumar Relli , Michal Simek , Amit Kumar Mahapatra , Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Cc: Thomas Petazzoni , Boris Brezillon , Miquel Raynal Subject: [PATCH 3/3] mtd: rawnand: arasan: Provide an additional ->exec_op() check Date: Mon, 6 Sep 2021 15:29:42 +0200 Message-Id: <20210906132942.36972-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210906132942.36972-1-miquel.raynal@bootlin.com> References: <20210906132942.36972-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210906_062951_515887_BE9EF327 X-CRM114-Status: GOOD ( 14.94 ) X-Spam-Score: -0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: The controller only supports data payload requests which are multiple of 4. Rounding up will not work if we reached the end of the device and the controller will just refuse the request. Hence any una [...] Content analysis details: (-0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [217.70.178.230 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [217.70.178.230 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The controller only supports data payload requests which are multiple of 4. Rounding up will not work if we reached the end of the device and the controller will just refuse the request. Hence any unaligned data request that ends at the device boundary should be refused. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/arasan-nand-controller.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/mtd/nand/raw/arasan-nand-controller.c b/drivers/mtd/nand/raw/arasan-nand-controller.c index 9cbcc698c64d..8377994f3c49 100644 --- a/drivers/mtd/nand/raw/arasan-nand-controller.c +++ b/drivers/mtd/nand/raw/arasan-nand-controller.c @@ -891,6 +891,7 @@ static const struct nand_op_parser anfc_op_parser = NAND_OP_PARSER( static int anfc_check_op(struct nand_chip *chip, const struct nand_operation *op) { + struct mtd_info *mtd = nand_to_mtd(chip); const struct nand_op_instr *instr; int op_id; @@ -940,6 +941,35 @@ static int anfc_check_op(struct nand_chip *chip, op->instrs[1].type == NAND_OP_DATA_IN_INSTR) return -ENOTSUPP; + /* + * The controller only supports data payload requests which are a + * multiple of 4. This may confuse the core as the core could request a + * given number of bytes and then another number of bytes without + * re-synchronizing the pointer. In practice, most data accesses are + * 4-byte aligned and thus this is not an issue in practice. However, + * rounding up will not work if we reached the end of the device. Any + * unaligned data request that ends at the device boundary would confuse + * the controller and cannot be performed. + * + * TODO: The nand_op_parser framework should be extended to + * support custom checks on DATA instructions. + */ + if (op->ninstrs == 4 && + op->instrs[0].type == NAND_OP_CMD_INSTR && + op->instrs[1].type == NAND_OP_ADDR_INSTR && + op->instrs[1].ctx.addr.naddrs == 2 && + op->instrs[2].type == NAND_OP_CMD_INSTR && + op->instrs[3].type == NAND_OP_DATA_IN_INSTR) { + unsigned int start_off, end_off; + + start_off = (op->instrs[1].ctx.addr.addrs[1] << 8) + + op->instrs[1].ctx.addr.addrs[0]; + end_off = start_off + round_up(op->instrs[3].ctx.data.len, 4); + + if (end_off >= mtd->writesize + mtd->oobsize) + return -ENOTSUPP; + } + return nand_op_parser_exec_op(chip, &anfc_op_parser, op, true); }