Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1507116pxf; Fri, 12 Mar 2021 11:07:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJzny0x6vw2azzIWFRDU2/E1voVTUdYjy9gw1MzcJ0gmdP0TBR8lKDi+kcx2Uwp6kCkfMTqk X-Received: by 2002:a50:eb8f:: with SMTP id y15mr16081745edr.115.1615576072245; Fri, 12 Mar 2021 11:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615576072; cv=none; d=google.com; s=arc-20160816; b=f3yOVHoTvqfxthyAzdxh03hmw9dykV67yHS61qGBy2eFon2/39DtefBoHznyc0IXDM F7H+c8bcDsPiFMvTkFrqtlx6Twv8Of8RpcM3hqyf960Fr2UXdxH7cfpBfjz/JKxbE6+H 4DRJ6aJx0QZiWWDvaNeGiPuQESFyQFmjKsBjk/jyaZOocbu1lkbhG9cSOzTGMITrdZQg ecuzIKKkTkoXBYS5m2XounkA31Xyc55rLi28iShP72juvxiIsVyApcOAFkxdU1Q9+wE8 7mWDKLvhoavncfoxLJSZKX+TuJct98AweLmgNQRK7BQOR0IbjEjXsm57dHy9txUqUXZG sJ3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6+KxuP01OXn0P4BC96DpLPW6zDJBUCK1si/Mhm3vETY=; b=arIiu98NHmmmey3pWiYtNvigZwcIR9SVOceqYJsV+yttHX+7TR9RqmEUkDrdl+HYq3 6oG3l9DCQ4y0G5t6LukZJTKsTSx+n/Zx5XP564GmBVOqoVaw+6c8XcX1quZ1S+kXCfUN glMLZ4pkW4wLcQidwEUCvTkeyF8MHmhOM/96qa+ntuLaPYaEI8hrYpMX8lPM9mZjFF3N vHClDRodRjT5o44NIH6/3aesOiEiHBahwKoOe2cdwV9gLM+/x87uwIvZ+WmEqgy0FtqG afKRmc7UtPASLPNTSrwl+VEgoEO2JS/IkViznn0DRVrawE66TyGajdmCvqEijtqpahl/ XztA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=uFdxA+J9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u1si4684709edp.42.2021.03.12.11.07.29; Fri, 12 Mar 2021 11:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@walle.cc header.s=mail2016061301 header.b=uFdxA+J9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234124AbhCLTGf (ORCPT + 99 others); Fri, 12 Mar 2021 14:06:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234103AbhCLTGG (ORCPT ); Fri, 12 Mar 2021 14:06:06 -0500 Received: from ssl.serverraum.org (ssl.serverraum.org [IPv6:2a01:4f8:151:8464::1:2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37965C061574 for ; Fri, 12 Mar 2021 11:06:06 -0800 (PST) Received: from mwalle01.fritz.box (unknown [IPv6:2a02:810c:c200:2e91:fa59:71ff:fe9b:b851]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ssl.serverraum.org (Postfix) with ESMTPSA id 18E5D22246; Fri, 12 Mar 2021 20:06:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=walle.cc; s=mail2016061301; t=1615575964; 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=6+KxuP01OXn0P4BC96DpLPW6zDJBUCK1si/Mhm3vETY=; b=uFdxA+J9wKJe1up+L2tmP70GjgkcwqQqLn6rrQw8tKjaXfNZFxVMRY8Z1PPQepdLHJ6KU7 M0qeo3lfCOZ22IQpR5UCM606r48VpNrIIVR0CK36y7J18Eik51gNtSQOHhF9uPqyOKDQQQ NOKXiEjw0U3gdEq8k8JoVnMrzWpom8w= From: Michael Walle To: linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Cc: Tudor Ambarus , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Michael Walle Subject: [RFC PATCH 1/3] mtd: spi-nor: sfdp: remember sfdp_size Date: Fri, 12 Mar 2021 20:05:46 +0100 Message-Id: <20210312190548.6954-2-michael@walle.cc> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210312190548.6954-1-michael@walle.cc> References: <20210312190548.6954-1-michael@walle.cc> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Save the sftp_size in the spi_nor struct so we can use it to dump the SFDP table without parsing the headers again. Signed-off-by: Michael Walle --- drivers/mtd/spi-nor/sfdp.c | 12 ++++++++++++ include/linux/mtd/spi-nor.h | 1 + 2 files changed, 13 insertions(+) diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index 25142ec4737b..b1814afefc33 100644 --- a/drivers/mtd/spi-nor/sfdp.c +++ b/drivers/mtd/spi-nor/sfdp.c @@ -16,6 +16,7 @@ (((p)->parameter_table_pointer[2] << 16) | \ ((p)->parameter_table_pointer[1] << 8) | \ ((p)->parameter_table_pointer[0] << 0)) +#define SFDP_PARAM_HEADER_PARAM_LEN(p) ((p)->length * 4) #define SFDP_BFPT_ID 0xff00 /* Basic Flash Parameter Table */ #define SFDP_SECTOR_MAP_ID 0xff81 /* Sector Map Table */ @@ -1263,6 +1264,7 @@ int spi_nor_parse_sfdp(struct spi_nor *nor, struct sfdp_parameter_header *param_headers = NULL; struct sfdp_header header; struct device *dev = nor->dev; + size_t param_max_offset; size_t psize; int i, err; @@ -1285,6 +1287,9 @@ int spi_nor_parse_sfdp(struct spi_nor *nor, bfpt_header->major != SFDP_JESD216_MAJOR) return -EINVAL; + nor->sfdp_size = SFDP_PARAM_HEADER_PTP(bfpt_header) + + SFDP_PARAM_HEADER_PARAM_LEN(bfpt_header); + /* * Allocate memory then read all parameter headers with a single * Read SFDP command. These parameter headers will actually be parsed @@ -1311,6 +1316,13 @@ int spi_nor_parse_sfdp(struct spi_nor *nor, } } + for (i = 0; i < header.nph; i++) { + param_header = ¶m_headers[i]; + param_max_offset = SFDP_PARAM_HEADER_PTP(param_header) + + SFDP_PARAM_HEADER_PARAM_LEN(param_header); + nor->sfdp_size = max(nor->sfdp_size, param_max_offset); + } + /* * Check other parameter headers to get the latest revision of * the basic flash parameter table. diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index a0d572855444..a58118b8b002 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -404,6 +404,7 @@ struct spi_nor { bool sst_write_second; u32 flags; enum spi_nor_cmd_ext cmd_ext_type; + size_t sfdp_size; const struct spi_nor_controller_ops *controller_ops; -- 2.20.1