From nobody Tue Sep 29 06:47:13 2026 Received: from mail.fris.de (mail.fris.de [116.203.77.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A69B244C657; Tue, 11 Aug 2026 16:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.77.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786465380; cv=none; b=K0bnJgrMyWqNghXT1MXO/vm4yUBSiASHGPGJiNpxu5Zk6LCNXhY/ZHjKGvYznhmaDdPoDOXwF6y4t2yKXWRq9bQ0pcjooMosTq252AgIa7p06nxTNMQBqat9JI5nUPor9y33FHlL1hQZdlddh6Wj3r6uGLEwNZr3t1L7hshMzCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786465380; c=relaxed/simple; bh=BfZqAzvxhZmc0IKOFPXFz0YHHCiMhHvyiJmAZ4TsNng=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AHzUjyaWYma/hDjsMrguZdnAFVTPjdFHWB3svBaPX8/XJTwZY7cJPP28US9BBOgTlMcnVDhGOzU51mTkLPZjVhatQrX14Pfny9jLD3UWcgvlCPx9lBcZJOAmuYPDh3hKoI4ZTk82O6EUA9Nmn7r8Cr4uHYdiWRX3HyUESb/Gwlc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fris.de; spf=pass smtp.mailfrom=fris.de; dkim=pass (2048-bit key) header.d=fris.de header.i=@fris.de header.b=1WHHUG6x; arc=none smtp.client-ip=116.203.77.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fris.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fris.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fris.de header.i=@fris.de header.b="1WHHUG6x" From: Frieder Schrempf DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=mail; t=1786464835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RIpDx1Ttmz3Npv9FiPzjlhwVqmLLeI+zGyViDkfASDU=; b=1WHHUG6x5waiMagWbnmIgclFpEYeWoo5RmcPmN4ZUdBc2bMsqLbeZPT+WV1WNUHTDPrh+C 5RTYHYLuDJdv0/rk8mLiHlnFM14fFKgNMo2CG1dNgvyJjuCmFlo0HivnsbcHm3VkJkqRbi SZajrWk9XMNZ7ODIuHyarUmpxtXiHaZI/AfxZMfsm2KQxYYUAlAwn9mZx5EoZ59ilIax1a hR6DRxZzXQVLuAt1QjKVze9TZhSxsyO4Ao4yNcansxHnHH/jaYYdOYHf9J6LGD1Ak6Il8T 6KU1daTof2nPNeUuItBa8F4qybdFyvJbgpcgF0hSDcfjr//cKm0nPxKrX76uCw== To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Mikhail Kshevetskiy , stable@vger.kernel.org, Frieder Schrempf , David LaPorte , Gabor Juhos , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.12.y 1/3] mtd: spinand: fix direct mapping creation sizes Date: Tue, 11 Aug 2026 18:13:36 +0200 Message-ID: <20260811161342.533280-2-frieder@fris.de> In-Reply-To: <20260811161342.533280-1-frieder@fris.de> References: <20260811161342.533280-1-frieder@fris.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mikhail Kshevetskiy [ Upstream commit e4a0cf9f1d90e6888e5373da3314f761024f6c97 ] Continuous mode is only supported for data reads, thus writing requires only single flash page mapping. Cc: stable@vger.kernel.org Signed-off-by: Mikhail Kshevetskiy Signed-off-by: Miquel Raynal Signed-off-by: Frieder Schrempf Acked-by: Miquel Raynal --- drivers/mtd/nand/spi/core.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 48ac009cbaad2..a480243385e2e 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1036,18 +1036,13 @@ static int spinand_create_dirmap(struct spinand_dev= ice *spinand, unsigned int plane) { struct nand_device *nand =3D spinand_to_nand(spinand); - struct spi_mem_dirmap_info info =3D { - .length =3D nanddev_page_size(nand) + - nanddev_per_page_oobsize(nand), - }; + struct spi_mem_dirmap_info info =3D { 0 }; struct spi_mem_dirmap_desc *desc; =20 - if (spinand->cont_read_possible) - info.length =3D nanddev_eraseblock_size(nand); - /* The plane number is passed in MSB just above the column address */ info.offset =3D plane << fls(nand->memorg.pagesize); =20 + info.length =3D nanddev_page_size(nand) + nanddev_per_page_oobsize(nand); info.op_tmpl =3D *spinand->op_templates.update_cache; desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, spinand->spimem, &info); @@ -1056,6 +1051,8 @@ static int spinand_create_dirmap(struct spinand_devic= e *spinand, =20 spinand->dirmaps[plane].wdesc =3D desc; =20 + if (spinand->cont_read_possible) + info.length =3D nanddev_eraseblock_size(nand); info.op_tmpl =3D *spinand->op_templates.read_cache; desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, spinand->spimem, &info); @@ -1071,6 +1068,7 @@ static int spinand_create_dirmap(struct spinand_devic= e *spinand, return 0; } =20 + info.length =3D nanddev_page_size(nand) + nanddev_per_page_oobsize(nand); info.op_tmpl =3D *spinand->op_templates.update_cache; info.op_tmpl.data.ecc =3D true; desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, @@ -1080,6 +1078,8 @@ static int spinand_create_dirmap(struct spinand_devic= e *spinand, =20 spinand->dirmaps[plane].wdesc_ecc =3D desc; =20 + if (spinand->cont_read_possible) + info.length =3D nanddev_eraseblock_size(nand); info.op_tmpl =3D *spinand->op_templates.read_cache; info.op_tmpl.data.ecc =3D true; desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, --=20 2.55.0 From nobody Tue Sep 29 06:47:13 2026 Received: from mail.fris.de (mail.fris.de [116.203.77.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6A5644CAE4; Tue, 11 Aug 2026 16:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.77.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786465379; cv=none; b=IrB8WYz9+Dyah5/p6KH+Q5epwKLjnkn7pA/fjxoJIe7pX7ccAE0ORHoHbuux9PllGoA+fGMxKIwbmdo2wtx8zGvhdUG2kWOt752y27E6bZ7TCzXK45C8u6h8Dx/RHo1VL7yErkN85RTfmv8vKGpSLpC1m7LVOzNTO2Dk1NEHDMo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786465379; c=relaxed/simple; bh=SAz60KA6fPW0pMBKmcoL8uUAuWXd11PScU2zfii4/LQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ImRnrJhjLjrT4kuU8u4x4Kk8sTOp/8ccrkNvugqMfpNl749MlclAL1Bahtplzr9bMj0FesSI3gPeG5Kk6Dg664z6sHyCMZnUwM2eMGBFpJ/2Uvsse/adDt/BzrhxqvlkOMXx9aecTwaT3s1cXC6zK6O5RZiFI7IeJPs847hd+zo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fris.de; spf=pass smtp.mailfrom=fris.de; dkim=pass (2048-bit key) header.d=fris.de header.i=@fris.de header.b=2BDPjDrU; arc=none smtp.client-ip=116.203.77.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fris.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fris.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fris.de header.i=@fris.de header.b="2BDPjDrU" From: Frieder Schrempf DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=mail; t=1786464835; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=a29yc6HZhwWPN+sxY5uQGFTrpGPENuXFgdlITogn3PI=; b=2BDPjDrU3f8zXBhPZ7lXvkPqeAOAXQzbjmFj9AgmUpJX3/774+T4mcOfM2/LR6teQlYcAX G1DV6SYMLiFZPTstxrLO9WvfgEJ41W6zhHP/NIX5gatLqyQTFQxChTS3bMgpRUyFlKkRpR ppJDBIBME3au3nflhUSBhHCvL/Y8wxwGdmAHlRQkGm6IP0yJ9F//4rEn4Mvf4SUk5/6JsO DBhsm3QNza9P3coK1DQ6iKySGOwzmjZIlSTHebV6tcr232gRlODA3Iz6R/CwrbGwQuQwBc OezsoPz7RRHSaVu/02y0mOl3ocxTTqrpDKh6e08KgfLagaDG66uMngLEyxTylg== To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Mikhail Kshevetskiy , stable@vger.kernel.org, Frieder Schrempf , David LaPorte , Gabor Juhos , Pratyush Yadav , Sasha Levin Subject: [PATCH 6.12.y 2/3] mtd: spinand: try a regular dirmap if creating a dirmap for continuous reading fails Date: Tue, 11 Aug 2026 18:13:37 +0200 Message-ID: <20260811161342.533280-3-frieder@fris.de> In-Reply-To: <20260811161342.533280-1-frieder@fris.de> References: <20260811161342.533280-1-frieder@fris.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mikhail Kshevetskiy [ Upstream commit 004f8ea0d9917398aabff7388b3bf62a84a4088b ] Continuous reading may result in multiple flash pages reading in one operation. Typically only one flash page has read/written (a little bit more than 2-4 Kb), but continuous reading requires the spi controller to read up to 512 Kb in one operation without toggling CS in beetween. Roughly speaking spi controllers can be divided on 2 categories: * spi controllers without dirmap acceleration support * spi controllers with dirmap acceleration support Firt of them will have issues with continuous reading if restriction on the transfer length is implemented in the adjust_op_size() handler. Second group often supports acceleration of single page only reading. Thus enabling of continuous reading can break flash reading. This patch tries to create dirmap for continuous reading first and fallback to regular reading if spi controller refuses to create it. Cc: stable@vger.kernel.org Signed-off-by: Mikhail Kshevetskiy Signed-off-by: Miquel Raynal Signed-off-by: Frieder Schrempf Acked-by: Miquel Raynal --- drivers/mtd/nand/spi/core.c | 43 ++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index a480243385e2e..10339209e7322 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -1032,6 +1032,39 @@ static int spinand_mtd_block_isreserved(struct mtd_i= nfo *mtd, loff_t offs) return ret; } =20 +static struct spi_mem_dirmap_desc *spinand_create_rdesc( + struct spinand_device *spinand, + struct spi_mem_dirmap_info *info) +{ + struct nand_device *nand =3D spinand_to_nand(spinand); + struct spi_mem_dirmap_desc *desc =3D NULL; + + if (spinand->cont_read_possible) { + /* + * spi controller may return an error if info->length is + * too large + */ + info->length =3D nanddev_eraseblock_size(nand); + desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, + spinand->spimem, info); + } + + if (IS_ERR_OR_NULL(desc)) { + /* + * continuous reading is not supported by flash or + * its spi controller, use regular reading + */ + spinand->cont_read_possible =3D false; + + info->length =3D nanddev_page_size(nand) + + nanddev_per_page_oobsize(nand); + desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, + spinand->spimem, info); + } + + return desc; +} + static int spinand_create_dirmap(struct spinand_device *spinand, unsigned int plane) { @@ -1051,11 +1084,8 @@ static int spinand_create_dirmap(struct spinand_devi= ce *spinand, =20 spinand->dirmaps[plane].wdesc =3D desc; =20 - if (spinand->cont_read_possible) - info.length =3D nanddev_eraseblock_size(nand); info.op_tmpl =3D *spinand->op_templates.read_cache; - desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, - spinand->spimem, &info); + desc =3D spinand_create_rdesc(spinand, &info); if (IS_ERR(desc)) return PTR_ERR(desc); =20 @@ -1078,12 +1108,9 @@ static int spinand_create_dirmap(struct spinand_devi= ce *spinand, =20 spinand->dirmaps[plane].wdesc_ecc =3D desc; =20 - if (spinand->cont_read_possible) - info.length =3D nanddev_eraseblock_size(nand); info.op_tmpl =3D *spinand->op_templates.read_cache; info.op_tmpl.data.ecc =3D true; - desc =3D devm_spi_mem_dirmap_create(&spinand->spimem->spi->dev, - spinand->spimem, &info); + desc =3D spinand_create_rdesc(spinand, &info); if (IS_ERR(desc)) return PTR_ERR(desc); =20 --=20 2.55.0 From nobody Tue Sep 29 06:47:13 2026 Received: from mail.fris.de (mail.fris.de [116.203.77.234]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A6B1844CAF9; Tue, 11 Aug 2026 16:22:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.77.234 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786465379; cv=none; b=HXMPHOgYhuwprYvhNSO9lM+xxxan1sLYwzS9uPvqFa3a8zP3PNw0LYZ1Umfl+r0DiXWU6WkJywoKQUlKjVGirke42D9KIYBlkopnGK7+QcABhHBpOkr4Fm974M6BPLIhhlLxerjclbuPT1TQUl4hfTUVHrRU2F9dLfe+Xqb7FWA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786465379; c=relaxed/simple; bh=dIklY3UfrxdjUEYYWqpLDVjZe71HM6zRddPIFCZnKhk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aJaR1PAdjB3MmEPh9grprEX08pBKHZb8x2iW3XKtgTiaqjQWqd+G2yUS+R/gelF4yFyea3v1whICBUg13rj6T87jojn+IiQIHpGsEvyOywGoGykV8u1hFNn5fvZStyX7lzg6emELDktwTuKULD+G4v2eJV3wEgCHoqNHiTRJ1n8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fris.de; spf=pass smtp.mailfrom=fris.de; dkim=pass (2048-bit key) header.d=fris.de header.i=@fris.de header.b=ed+aIs38; arc=none smtp.client-ip=116.203.77.234 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=fris.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fris.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=fris.de header.i=@fris.de header.b="ed+aIs38" From: Frieder Schrempf DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fris.de; s=mail; t=1786464836; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FB8jUzAk4vdr/He6IOGom269wrMDPlwN0Q03T1SXJcA=; b=ed+aIs38d2opKY7m9NHGGlutggYTEoU3swZhBgeiVJf8Yeq+ZIlg7GMcikNCzsOyUCqzpe o174B6SglLL+s9lsMCwgXM0GvZ4dJSWS5X5CBmIcLpcc0H+Gf7G5SqS2WuwWOT46o+VCmh q2i8uzqExjk8o/Ta7UYnBZ+uS6xODx/r2Nb5heIUVSMN96VmOMzWcf+lr2xjdVzpZFhpPe vxNOEP730V0Qm/QywRWcLdS2mbjzv6BVTloMrzgREnvwlZ/FNyaQuF2g3a9Q4ttDRGDcx3 iEabvQOTwQNGq5sdjH90JIV6Vv7xD+z1Wn/oBKxyAyxmIwIJxquRZZzK/jBfqg== To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: Mikhail Kshevetskiy , stable@vger.kernel.org, Frieder Schrempf , David LaPorte , Gabor Juhos , Pratyush Yadav , Sasha Levin Subject: [PATCH 6.12.y 3/3] mtd: spinand: repeat reading in regular mode if continuous reading fails Date: Tue, 11 Aug 2026 18:13:38 +0200 Message-ID: <20260811161342.533280-4-frieder@fris.de> In-Reply-To: <20260811161342.533280-1-frieder@fris.de> References: <20260811161342.533280-1-frieder@fris.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Mikhail Kshevetskiy [ Upstream commit 010dc7f2dd6a0078ade3f88f627ed5fbf45ceb94 ] Continuous reading may result in multiple flash pages reading in one operation. Unfortunately, not all spinand controllers support such large reading. They will read less data. Unfortunately, the operation can't be continued. In this case: * disable continuous reading on this (not good enough) spi controller * repeat reading in regular mode. Cc: stable@vger.kernel.org Signed-off-by: Mikhail Kshevetskiy Signed-off-by: Miquel Raynal Signed-off-by: Frieder Schrempf Acked-by: Miquel Raynal --- drivers/mtd/nand/spi/core.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c index 10339209e7322..bf16901b77b64 100644 --- a/drivers/mtd/nand/spi/core.c +++ b/drivers/mtd/nand/spi/core.c @@ -427,8 +427,16 @@ static int spinand_read_from_cache_op(struct spinand_d= evice *spinand, * Dirmap accesses are allowed to toggle the CS. * Toggling the CS during a continuous read is forbidden. */ - if (nbytes && req->continuous) - return -EIO; + if (nbytes && req->continuous) { + /* + * Spi controller with broken support of continuous + * reading was detected. Disable future use of + * continuous reading and return -EAGAIN to retry + * reading within regular mode. + */ + spinand->cont_read_possible =3D false; + return -EAGAIN; + } } =20 if (req->datalen) @@ -849,10 +857,19 @@ static int spinand_mtd_read(struct mtd_info *mtd, lof= f_t from, =20 old_stats =3D mtd->ecc_stats; =20 - if (spinand_use_cont_read(mtd, from, ops)) + if (spinand_use_cont_read(mtd, from, ops)) { ret =3D spinand_mtd_continuous_page_read(mtd, from, ops, &max_bitflips); - else + if (ret =3D=3D -EAGAIN && !spinand->cont_read_possible) { + /* + * Spi controller with broken support of continuous + * reading was detected (see spinand_read_from_cache_op()), + * repeat reading in regular mode. + */ + ret =3D spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips); + } + } else { ret =3D spinand_mtd_regular_page_read(mtd, from, ops, &max_bitflips); + } =20 if (ops->stats) { ops->stats->uncorrectable_errors +=3D --=20 2.55.0