From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AB01E40E8C9 for ; Fri, 5 Jun 2026 13:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780665428; cv=none; b=NgpEnrHEwES7vH6/dDghFM5mrDpUj3lx1WXvasunSjAJLv5i4LaujM8fg+zwSZ71rSJipmBrADBwXaIK/qZl4TbkDsDOGLvWNunrNGnIxWQKmkM9mfIW7jPcq3U1s4HJvoWFILDtr4cmUNEKGzRQAC/bR0qm7/rYz2eto1/erGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780665428; c=relaxed/simple; bh=7i45nhE1oWBGRsr0FHr311uoJabsUptbRMlDmJsEz6c=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=qBphoGmgmzqIq7n86vuqZMXRARo5KXh3nSyeMUDi0TRCRCyJV5qmK/9rVUzy4Xf3vmw56HWdsI7Ibjte+0eEcNgAzXCNaNDxXD3+Fqmb6cC2c1iCGq9iifedhkZqROX2k840oLg8qGBA9bpubZyESMec/obmtEGxjQJ9K+NCopc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=jmTGwUAD; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jmTGwUAD" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4905529b933so19231255e9.0 for ; Fri, 05 Jun 2026 06:17:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1780665425; x=1781270225; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WlSe6xaIhW4lMQuBjyY7xNSqPkDFaBjnxZVNeHOSqXk=; b=jmTGwUADCVJlSEZ1waHBAN3hFupLH7pixL0IMNzdhJbZwrEtZON58t6ahjEhahzmk4 SERECgy8VBGaa9+u46uZC8FfQkQI1DD3FoBx1R714mh0RJ0xhWHCZ0wyngK2vIhrqFQR +MT4rve3KQlbOqxWslaT4+/mRIoDwrGp9/+qhpdBeq7JfyLlyPTar+ygik24OrMPsvf2 VWoMtz/FCIwE5RpEYDYiZ/LxkYsWKZxqXprVNZli7Fq8HkokYFRvf6v9VS3QOgV6KHpb ePJ6/RLvSumUTPID/p6JatnB1tWzwBjbh3JQwEWmE9vtToXDLplaWEYU6OFLu5Mv1sgO sLDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780665425; x=1781270225; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=WlSe6xaIhW4lMQuBjyY7xNSqPkDFaBjnxZVNeHOSqXk=; b=XGwmktn4v1glcp8Ba8lkClZsnnHcOCJV0ZluaTLjOXeuLEb37UD2rYQ6PVmO50P4Ku szunk20yiRmMPJonjc+Ny8rpCLwi6ro3zmStpueVx0vJ+k5IixXmJYjnWgArEwq/wU+2 Rrpy0rqQDvUg0ELGSzanNrLrlwjuZj75YHyfsLHor/ZJCBrdpJOeccRSrcvn7vlJVK2B eELxbBTekfICABgh0sTJ5i5AD0mQMMIvajduY1sAFrjXL4V+bPI/NpZizqPshyD2/vqq Jp+pR5U8tVFl7UTApav7RWwZ5TnP+G8lkykF2i8AGP75TIWpYwcf49l9cauUmzfI0js/ fnKA== X-Forwarded-Encrypted: i=1; AFNElJ+RwvLU5+C3SAbA97mMYiA46nkFiid5zB23sbishqjZph4keVknUjNU3v4N0zx88sSC9tK/Mir4xAfat48=@vger.kernel.org X-Gm-Message-State: AOJu0YyUHBtXU+cOwhFAqvZ6wiT8kv3AKidAE6JM8mRF324/oaP9WT2X Trxo1IU6H2IL7whs+N4mPcFXXbF6gixvSFE5tXmKs9ipnSs1Nvq6I77zchCGqRP//sw= X-Gm-Gg: Acq92OGxyv+qvyGBRk4bF0SzXuyetES4wkJdJYPaJtEhm4B8/BZu2vjnL8lKcGQZPUN 3Vaf7MonMfUUkfAYc/ebVELqQsN1FPQvXGY1FgQ62++lSP/bFS2H2I1ScmLr3NLeaz4mo60+6aD +75U2k5IBjYnJYzRiCEz02Zzn9a40YMwL9oCmEZmsh/3d/KYL1FK90gbaxEixSsEkOyPKn0cjVd tjdc+z9bPAuQ4DGCp0wfWXrH2gds3GY5mUuzCZFmyJmr+debkGYnB5ZoYbSgqZ+pDY6c1W4FqEt WgbgkzK/FOvBDgcBQXjOmFpbLtrOBVIo22ZgqafmmLeg5RoTh7/fYDi013qze0HkIlOXeA3jZEK PNFFuUmwXoXNnDAkX3hLxYAnLjviXmdkto22c8tPrkYajmX1x4KiShbzjXhLl3zxb9quGk9FM3I J2YsO22outkG9lMTXeA0JlF3oHuw5lLZZ76QY9zqfSkg== X-Received: by 2002:a05:600c:468c:b0:490:469c:556b with SMTP id 5b1f17b1804b1-490c257c3c8mr60453765e9.12.1780665424977; Fri, 05 Jun 2026 06:17:04 -0700 (PDT) Received: from [10.11.12.110] ([82.76.215.73]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490bc3fcf5bsm177946265e9.9.2026.06.05.06.17.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Jun 2026 06:17:04 -0700 (PDT) Message-ID: Date: Fri, 5 Jun 2026 16:17:02 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 3/3] mtd: spi-nor: rework flash parameter initialization To: Michael Walle , Pratyush Yadav , Takahiro Kuwano , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra Cc: linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org References: <20260601125438.3481722-1-mwalle@kernel.org> <20260601125438.3481722-4-mwalle@kernel.org> Content-Language: en-US From: Tudor Ambarus In-Reply-To: <20260601125438.3481722-4-mwalle@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 6/1/26 3:52 PM, Michael Walle wrote: > Rework how the flash parameters are initialized. It used to make a > difference whether a flash is in the in-kernel database, whether it > supports multi I/O and so on. Recently, that makes more and more > problems because flash IDs are reused among legacy flashes (w/o SFDP > support) and newer flashes [1,2,3,4]. > > Simplify the whole parameter initialization, by starting with the > parameters we have in the in-kernel database and the try to parse SFDP > (and let it override any settings). You need to specify here as well about the potential problem of issuing an unsupported command (rdsfdp), although practice showed us it's okay. I can't remember who raised first the potential of issuing unsupported commands. Was it macronix, sst? > > [1] https://lore.kernel.org/linux-mtd/CAAyq3SYX9UPwhC_Ume_S2yxhQwimRvB=Y6O_+FFqokhNmw7jQg@mail.gmail.com/ > [2] https://lore.kernel.org/linux-mtd/DGB4745HRCFI.1DRYTHXURWZJO@kernel.org/ > [3] https://lore.kernel.org/linux-mtd/DD10GE4EOCD7.CPTN7198QFUV@kernel.org/ > [4] https://lore.kernel.org/linux-mtd/DD6SI06QNEE4.2YCRTWJHEAAQM@kernel.org/ > > Signed-off-by: Michael Walle > --- > drivers/mtd/spi-nor/core.c | 65 +++++++++++++------------------------- > drivers/mtd/spi-nor/core.h | 1 - > 2 files changed, 22 insertions(+), 44 deletions(-) > > diff --git a/drivers/mtd/spi-nor/core.c b/drivers/mtd/spi-nor/core.c > index fbf8c2d9c6b5..67e0377b606f 100644 > --- a/drivers/mtd/spi-nor/core.c > +++ b/drivers/mtd/spi-nor/core.c > @@ -2868,11 +2868,10 @@ static void spi_nor_manufacturer_init_params(struct spi_nor *nor) > > /** > * spi_nor_no_sfdp_init_params() - Initialize the flash's parameters and > - * settings based on nor->info->sfdp_flags. This method should be called only by > - * flashes that do not define SFDP tables. If the flash supports SFDP but the > - * information is wrong and the settings from this function can not be retrieved > - * by parsing SFDP, one should instead use the fixup hooks and update the wrong > - * bits. > + * settings based on nor->info->sfdp_flags. > + * If the flash supports SFDP but the information is wrong and the settings from > + * this function can not be retrieved by parsing SFDP, one should instead use > + * the fixup hooks and update the wrong bits. > * @nor: pointer to a 'struct spi_nor'. > */ > static void spi_nor_no_sfdp_init_params(struct spi_nor *nor) > @@ -3053,43 +3052,25 @@ static int spi_nor_late_init_params(struct spi_nor *nor) > } > > /** > - * spi_nor_sfdp_init_params_deprecated() - Deprecated way of initializing flash > - * parameters and settings based on JESD216 SFDP standard. > + * spi_nor_try_parse_sfdp() - Tries to parse flash parameters based > + * on JESD216 SFDP standard. > * @nor: pointer to a 'struct spi_nor'. > * > * The method has a roll-back mechanism: in case the SFDP parsing fails, the > - * legacy flash parameters and settings will be restored. > + * flash parameters and settings will be restored. > */ > -static void spi_nor_sfdp_init_params_deprecated(struct spi_nor *nor) > +static int spi_nor_try_parse_sfdp(struct spi_nor *nor) > { > struct spi_nor_flash_parameter sfdp_params; > + int ret; > > memcpy(&sfdp_params, nor->params, sizeof(sfdp_params)); > > - if (spi_nor_parse_sfdp(nor)) > + ret = spi_nor_parse_sfdp(nor); > + if (ret) > memcpy(nor->params, &sfdp_params, sizeof(*nor->params)); > -} > - > -/** > - * spi_nor_init_params_deprecated() - Deprecated way of initializing flash > - * parameters and settings. > - * @nor: pointer to a 'struct spi_nor'. > - * > - * The method assumes that flash doesn't support SFDP so it initializes flash > - * parameters in spi_nor_no_sfdp_init_params() which later on can be overwritten > - * when parsing SFDP, if supported. > - */ > -static void spi_nor_init_params_deprecated(struct spi_nor *nor) > -{ > - spi_nor_no_sfdp_init_params(nor); > > - spi_nor_manufacturer_init_params(nor); > - > - if (nor->info->no_sfdp_flags & (SPI_NOR_DUAL_READ | > - SPI_NOR_QUAD_READ | > - SPI_NOR_OCTAL_READ | > - SPI_NOR_OCTAL_DTR_READ)) > - spi_nor_sfdp_init_params_deprecated(nor); > + return ret; > } > > /** > @@ -3152,7 +3133,8 @@ static void spi_nor_init_default_params(struct spi_nor *nor) > * > * 1/ Default flash parameters initialization. The initializations are done > * based on nor->info data: > - * spi_nor_info_init_params() > + * spi_nor_init_default_params() > + * spi_nor_no_sfdp_init_params() > * > * which can be overwritten by: > * 2/ Manufacturer flash parameters initialization. The initializations are > @@ -3163,7 +3145,7 @@ static void spi_nor_init_default_params(struct spi_nor *nor) > * which can be overwritten by: > * 3/ SFDP flash parameters initialization. JESD216 SFDP is a standard and > * should be more accurate that the above. > - * spi_nor_parse_sfdp() or spi_nor_no_sfdp_init_params() > + * spi_nor_try_parse_sfdp() > * > * Please note that there is a ->post_bfpt() fixup hook that can overwrite > * the flash parameters and settings immediately after parsing the Basic > @@ -3189,17 +3171,14 @@ static int spi_nor_init_params(struct spi_nor *nor) > return -ENOMEM; > > spi_nor_init_default_params(nor); > + spi_nor_no_sfdp_init_params(nor); > + spi_nor_manufacturer_init_params(nor); > > - if (spi_nor_needs_sfdp(nor)) { > - ret = spi_nor_parse_sfdp(nor); > - if (ret) { > - dev_err(nor->dev, "BFPT parsing failed. Please consider using SPI_NOR_SKIP_SFDP when declaring the flash\n"); > - return ret; > - } > - } else if (nor->info->no_sfdp_flags & SPI_NOR_SKIP_SFDP) { > - spi_nor_no_sfdp_init_params(nor); > - } else { > - spi_nor_init_params_deprecated(nor); > + ret = spi_nor_try_parse_sfdp(nor); I find it fine. I'm concerned about the inconsistent rollback mechanism, but this is a preexisting problem. Reviewed-by: Tudor Ambarus > + if (ret && spi_nor_needs_sfdp(nor)) { > + dev_err(nor->dev, > + "SFDP parsing failed. You need to manually declare the flash parameters.\n"); > + return ret; > } > > ret = spi_nor_late_init_params(nor); > diff --git a/drivers/mtd/spi-nor/core.h b/drivers/mtd/spi-nor/core.h > index 2ebc5c3caca1..3d7c31bff5cb 100644 > --- a/drivers/mtd/spi-nor/core.h > +++ b/drivers/mtd/spi-nor/core.h > @@ -548,7 +548,6 @@ struct flash_info { > #define SPI_NOR_HAS_CMP BIT(10) > > u8 no_sfdp_flags; > -#define SPI_NOR_SKIP_SFDP BIT(0) sashiko says you need to grep this further and remove all instances. > #define SECT_4K BIT(1) > #define SPI_NOR_DUAL_READ BIT(3) > #define SPI_NOR_QUAD_READ BIT(4)