From nobody Sun Sep 7 12:31:00 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25176C001B0 for ; Mon, 7 Aug 2023 13:22:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233983AbjHGNWs (ORCPT ); Mon, 7 Aug 2023 09:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233941AbjHGNW3 (ORCPT ); Mon, 7 Aug 2023 09:22:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 076441BF3 for ; Mon, 7 Aug 2023 06:22:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 57EA361AE9 for ; Mon, 7 Aug 2023 13:22:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13989C433C8; Mon, 7 Aug 2023 13:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691414531; bh=rvtOy7dnpdWfQpkGSkJU8iwlrHMZ9j+wqgG+HgoebEY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Pn8pAVmWqSGjSRrjhzKWyoTOnuvKN89+fNilZObQ9KkSuN1fnwilTyu7KoQ/Z+LW+ fqimggEdnQykaUEAtLogbPUeZnTGi2F0iVBgMYYHQ9Ik4pmvfBww36ura8MDgX+tDz na2UQrG73ylQ/UYIIFrL61ocNpKPHUf+nZwnFoJvrNVgSFhD953GyUNNpV03PlAlFO 5Y9GluGfnYgjEqE6wFi6Hjf9UvOp5t5dGhQ0+gfNjRbIY/yPiK5SldMHuK0V6xC0mA ApeXTuflBoVPYBGVZkoHr6H3NMZOVgR4pqyaIepxu0OvE/X6BsexlcwYq9hdMyo02X GpZKcbsrIwOuQ== From: Michael Walle Date: Mon, 07 Aug 2023 15:21:03 +0200 Subject: [PATCH 09/41] mtd: spi-nor: push 4k SE handling into spi_nor_select_uniform_erase() MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230807-mtd-flash-info-db-rework-v1-9-3d3d5bef4ba4@kernel.org> References: <20230807-mtd-flash-info-db-rework-v1-0-3d3d5bef4ba4@kernel.org> In-Reply-To: <20230807-mtd-flash-info-db-rework-v1-0-3d3d5bef4ba4@kernel.org> To: Tudor Ambarus , Pratyush Yadav , Michael Walle , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Michael Walle X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4k sector erase sizes are only a thing with uniform erase types. Push the "we want 4k erase sizes" handling into spi_nor_select_uniform_erase(). One might wonder why the former sector_size isn't used anymore. It is because we either search for the largest erase size or if selected through kconfig, the 4k erase size. Now, why is that correct? For this, we have to differentiate between (1) flashes with SFDP and (2) without SFDP. For (1), we just set one (or two if SECT_4K is set) erase types and wanted_size is exactly one of these. For (2) things are a bit more complicated. For flashes which we don't have in our flash_info database, the generic driver is used and sector_size was already 0, which in turn selected the largest erase size. For flashes which had SFDP and an entry in flash_info, sector_size was always the largest sector and thus the largest erase type. Signed-off-by: Michael Walle --- drivers/mtd/spi-nor/core.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c index 015152ba8973..5c6a0edafae2 100644 --- a/drivers/mtd/spi-nor/core.c +++ b/drivers/mtd/spi-nor/core.c @@ -2511,13 +2511,6 @@ static int spi_nor_select_pp(struct spi_nor *nor, /** * spi_nor_select_uniform_erase() - select optimum uniform erase type * @map: the erase map of the SPI NOR - * @wanted_size: the erase type size to search for. Contains the value of - * info->sector_size, the "small sector" size in case - * CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is defined or 0 if - * there is no information about the sector size. The - * latter is the case if the flash parameters are parsed - * solely by SFDP, then the largest supported erase type - * is selected. * * Once the optimum uniform sector erase command is found, disable all the * other. @@ -2525,13 +2518,16 @@ static int spi_nor_select_pp(struct spi_nor *nor, * Return: pointer to erase type on success, NULL otherwise. */ static const struct spi_nor_erase_type * -spi_nor_select_uniform_erase(struct spi_nor_erase_map *map, - const u32 wanted_size) +spi_nor_select_uniform_erase(struct spi_nor_erase_map *map) { const struct spi_nor_erase_type *tested_erase, *erase =3D NULL; int i; u8 uniform_erase_type =3D map->uniform_erase_type; =20 + /* + * Search for the biggest erase size, except for when compiled + * to use 4k erases. + */ for (i =3D SNOR_ERASE_TYPE_MAX - 1; i >=3D 0; i--) { if (!(uniform_erase_type & BIT(i))) continue; @@ -2543,10 +2539,11 @@ spi_nor_select_uniform_erase(struct spi_nor_erase_m= ap *map, continue; =20 /* - * If the current erase size is the one, stop here: + * If the current erase size is the 4k one, stop here, * we have found the right uniform Sector Erase command. */ - if (tested_erase->size =3D=3D wanted_size) { + if (IS_ENABLED(CONFIG_MTD_SPI_NOR_USE_4K_SECTORS) && + tested_erase->size =3D=3D SZ_4K) { erase =3D tested_erase; break; } @@ -2574,7 +2571,6 @@ static int spi_nor_select_erase(struct spi_nor *nor) struct spi_nor_erase_map *map =3D &nor->params->erase_map; const struct spi_nor_erase_type *erase =3D NULL; struct mtd_info *mtd =3D &nor->mtd; - u32 wanted_size =3D nor->info->sector_size; int i; =20 /* @@ -2585,13 +2581,8 @@ static int spi_nor_select_erase(struct spi_nor *nor) * manage the SPI flash memory as uniform with a single erase sector * size, when possible. */ -#ifdef CONFIG_MTD_SPI_NOR_USE_4K_SECTORS - /* prefer "small sector" erase if possible */ - wanted_size =3D 4096u; -#endif - if (spi_nor_has_uniform_erase(nor)) { - erase =3D spi_nor_select_uniform_erase(map, wanted_size); + erase =3D spi_nor_select_uniform_erase(map); if (!erase) return -EINVAL; nor->erase_opcode =3D erase->opcode; --=20 2.39.2