From patchwork Fri Dec 7 09:26:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 1009285 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IzdXNbB8"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="0pjZpWA1"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43B6hP30Clz9s3q for ; Fri, 7 Dec 2018 20:32:53 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=VoVZr2kReQgxLGN367jYSS51ZBP3pium0xdyFZgBw/4=; b=IzdXNbB8jpQaxKGVR0FiX1jg+G 77vT3EPy7rJcOmd6T0jQJT2x6OerfYvvSZ9vgbwlsW5t4bktosxeiyBAYsy6gfWZ232gZ3Tz2h2HP JFMZtolmHXOUPPG1byL63ZluKtGqwQ1og4XoD3S1TIR+LoI94UZGH6bVrI98IdPbuKEZVbPhk5b9I an0SCjkTQDZONA3MqlB7lErce8s9vR80Afaef6FmEhvmcbp2++lBBvfKq4yQ3COx/Ci78rcqwUnYu JwYywDV1hJMFxi0hh8Yzjp5Ejf5gbfgMD/zkSgM1jYjo+hxEj1DqFYtN4GAWna++eL84gx+0Jps1c 5JgQznAg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gVCV6-0007wt-Hk; Fri, 07 Dec 2018 09:32:48 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gVCQ8-0001my-Qt for linux-mtd@bombadil.infradead.org; Fri, 07 Dec 2018 09:27:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=70dvIM+5diSGdEaEzG1okPy4LWlzqSYTZpFjkHNXXlg=; b=0pjZpWA1MhkG4jShHCr8F5AKz DrgQu7ldCIKkzbgndFtOVjCsZKwVKHW/AvUNeBYYEZJYRBDmU1Wl6wKR3iawnwguzar9359idUxei 256N95I0fFzsSnGOhjlVzITGoDz2ZQdeu+sDkJ77MqpFYSprjPszjO1M9sVpr8twHP+Ex26bw6RxM iOnO7jD2BSE9VLy9YR7DxK2EbmZFh4y8y4RUiCp3K+rE+FPDcCfIvdkLD7Lek+GB99qkCDd7IYe0Z CGZJWOMscYEyoFmnjTGMDLQmp+sSPqkTCpEiuHWtY+iT1vI1Cc2necKMmF3C2O+tiTLC0glP0LhCY nfVh+FFig==; Received: from mail.bootlin.com ([62.4.15.54]) by merlin.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gVCQ4-0005hX-Vn for linux-mtd@lists.infradead.org; Fri, 07 Dec 2018 09:27:38 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 4136C20E2C; Fri, 7 Dec 2018 10:27:08 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT, URIBL_BLOCKED shortcircuit=ham autolearn=disabled version=3.4.2 Received: from localhost.localdomain (aaubervilliers-681-1-79-44.w90-88.abo.wanadoo.fr [90.88.21.44]) by mail.bootlin.com (Postfix) with ESMTPSA id 133A220E31; Fri, 7 Dec 2018 10:26:45 +0100 (CET) From: Boris Brezillon To: Tudor Ambarus , Marek Vasut Subject: [RFC PATCH 34/34] mtd: spi-nor: Add sfdp fixups hooks Date: Fri, 7 Dec 2018 10:26:37 +0100 Message-Id: <20181207092637.18687-35-boris.brezillon@bootlin.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181207092637.18687-1-boris.brezillon@bootlin.com> References: <20181207092637.18687-1-boris.brezillon@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181207_042737_300248_18030F5A X-CRM114-Status: GOOD ( 15.70 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on merlin.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yogesh Narayan Gaur , Vignesh R , Richard Weinberger , Boris Brezillon , linux-mtd@lists.infradead.org, Miquel Raynal , Brian Norris , David Woodhouse MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Experience has proven that SFDP tables are sometimes wrong, and the parsing that is done by the core can lead ton erroneous flash config which can sometimes be harmful. This leaves us 2 options: 1/ set the SPI_NOR_SKIP_SFDP flag and completely ignore SFDP parsing 2/ fix SFDP tables at runtime While #1 should always work, it might implies extra work if most of the SFDP is correct. #2 has the benefit of keeping the generic SFDP parsing logic almost untouched while allowing SPI NOR manufacturer drivers to fix the broken bits. Add three new hooks to do that. Signed-off-by: Boris Brezillon --- drivers/mtd/spi-nor/internals.h | 7 ++++ drivers/mtd/spi-nor/sfdp.c | 57 +++++++++++++++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/internals.h b/drivers/mtd/spi-nor/internals.h index ae3eb40d7241..da71145995d9 100644 --- a/drivers/mtd/spi-nor/internals.h +++ b/drivers/mtd/spi-nor/internals.h @@ -188,6 +188,8 @@ struct sfdp_bfpt { /** * struct spi_nor_fixups - SPI NOR fixup hooks + * @sfdp_hdr: SFDP header fixups + * @sfdp_hdr: SFDP parameter headers fixups * @post_bfpt: called after the BFPT table has been parsed * @post_sfdp: called after SFDP has been parsed (is also called for SPI NORs * that do not support RDSFDP). Typically used to tweak various @@ -199,6 +201,11 @@ struct sfdp_bfpt { * table is broken or not available. */ struct spi_nor_fixups { + int (*sfdp_hdr)(struct spi_nor *nor, + struct sfdp_header *hdr); + int (*sfdp_param_hdrs)(struct spi_nor *nor, + struct sfdp_header *hdr, + struct sfdp_parameter_header *param_hdrs); int (*post_bfpt)(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, const struct sfdp_bfpt *bfpt, diff --git a/drivers/mtd/spi-nor/sfdp.c b/drivers/mtd/spi-nor/sfdp.c index 36343e3e6be0..a8cd070e4ea2 100644 --- a/drivers/mtd/spi-nor/sfdp.c +++ b/drivers/mtd/spi-nor/sfdp.c @@ -534,8 +534,8 @@ static const struct sfdp_bfpt_erase sfdp_bfpt_erases[] = { static int spi_nor_post_bfpt_fixups(struct spi_nor *nor, const struct sfdp_parameter_header *bfpt_header, - const struct sfdp_bfpt *bfpt, - struct spi_nor_flash_parameter *params) + const struct sfdp_bfpt *bfpt, + struct spi_nor_flash_parameter *params) { int ret; @@ -748,6 +748,50 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor, return spi_nor_post_bfpt_fixups(nor, bfpt_header, &bfpt, params); } +static int spi_nor_sfdp_hdr_fixups(struct spi_nor *nor, + struct sfdp_header *hdr) +{ + int ret; + + if (nor->manufacturer && nor->manufacturer->fixups && + nor->manufacturer->fixups->sfdp_hdr) { + ret = nor->manufacturer->fixups->sfdp_hdr(nor, hdr); + if (ret) + return ret; + } + + if (nor->info->fixups && nor->info->fixups->sfdp_hdr) { + ret = nor->info->fixups->sfdp_hdr(nor, hdr); + if (ret) + return ret; + } + + return 0; +} + +static int +spi_nor_sfdp_param_hdrs_fixups(struct spi_nor *nor, struct sfdp_header *hdr, + struct sfdp_parameter_header *param_hdrs) +{ + int ret; + + if (nor->manufacturer && nor->manufacturer->fixups && + nor->manufacturer->fixups->sfdp_param_hdrs) { + ret = nor->manufacturer->fixups->sfdp_param_hdrs(nor, hdr, + param_hdrs); + if (ret) + return ret; + } + + if (nor->info->fixups && nor->info->fixups->sfdp_hdr) { + ret = nor->info->fixups->sfdp_param_hdrs(nor, hdr, param_hdrs); + if (ret) + return ret; + } + + return 0; +} + /** * spi_nor_parse_sfdp() - parse the Serial Flash Discoverable Parameters. * @nor: pointer to a 'struct spi_nor' @@ -777,6 +821,10 @@ int spi_nor_parse_sfdp(struct spi_nor *nor, if (err < 0) return err; + err = spi_nor_sfdp_hdr_fixups(nor, &header); + if (err) + return err; + /* Check the SFDP header version. */ if (le32_to_cpu(header.signature) != SFDP_SIGNATURE || header.major != SFDP_JESD216_MAJOR) @@ -815,6 +863,11 @@ int spi_nor_parse_sfdp(struct spi_nor *nor, dev_err(dev, "failed to read SFDP parameter headers\n"); goto exit; } + + err = spi_nor_sfdp_param_hdrs_fixups(nor, &header, + param_headers); + if (err) + return err; } /*