From patchwork Thu Feb 21 12:58:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 1046159 X-Patchwork-Delegate: miquel.raynal@bootlin.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="b8nKLmLh"; 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 444vlV2KfJz9s6w for ; Fri, 22 Feb 2019 00:02:46 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=IFO2moLGTlsBwkWpZXzaasvtMNsVPwUK5X5mHXxElg4=; b=b8nKLmLh9vs8Is CsV4XYLVVXlmveHQo6hXZxpCOTsp4VT0jDL12oOM5vndhI/Q8YRWhP5JsNW9aNuDC36KIKRbi59lB jPUZ6GP1YVfn31rJUywt7YASn1oX30AvDSwd4qieScvxg/YUtM6FjD4sjuegQ7bT2U3dpL//hSRnM 38fhnMwEua2ggOpo6pQJRZSPsr+2eZEeSbVF8+RL9AIcP7iAnQohaxNVmabJ5A/kmw7pbNu+Vbr2J jTejCLaEqMQGK3tZS+9zaoQqCY2J78rVyBzynvq2+BUEiN+9AOi2T5p2+U+b3+K1hqP286MxNctVI FL05aitOQpBQqZTOESrQ==; 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 1gwnzr-0000rL-5w; Thu, 21 Feb 2019 13:02:39 +0000 Received: from relay6-d.mail.gandi.net ([217.70.183.198]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwnwE-0003OG-4Y; Thu, 21 Feb 2019 12:59:20 +0000 X-Originating-IP: 90.88.23.190 Received: from localhost.localdomain (aaubervilliers-681-1-81-190.w90-88.abo.wanadoo.fr [90.88.23.190]) (Authenticated sender: miquel.raynal@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 1EAC2C000C; Thu, 21 Feb 2019 12:58:49 +0000 (UTC) From: Miquel Raynal To: Boris Brezillon , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Tudor Ambarus Subject: [RFC PATCH 24/27] mtd: spinand: Instantiate a SPI-NAND on-die ECC engine Date: Thu, 21 Feb 2019 13:58:03 +0100 Message-Id: <20190221125806.28875-12-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190221125806.28875-1-miquel.raynal@bootlin.com> References: <20190221125806.28875-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190221_045855_454816_4AB9ED82 X-CRM114-Status: GOOD ( 20.39 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [217.70.183.198 listed in list.dnswl.org] -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: Vignesh R , Tudor Ambarus , Julien Su , Schrempf Frieder , linux-mtd@lists.infradead.org, Thomas Petazzoni , Miquel Raynal , Mason Yang , linux-arm-kernel@lists.infradead.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Make use of the existing functions taken from the SPI-NAND core to instantiate an on-die ECC engine specific to the SPI-NAND core. The next step will be to tweak the core to use this object instead of calling the helpers directly. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/spi/on-die-ecc-engine.c | 105 +++++++++++++++++++++ include/linux/mtd/nand-spi-on-die-engine.h | 35 +++++++ include/linux/mtd/nand.h | 1 + 3 files changed, 141 insertions(+) create mode 100644 include/linux/mtd/nand-spi-on-die-engine.h diff --git a/drivers/mtd/nand/spi/on-die-ecc-engine.c b/drivers/mtd/nand/spi/on-die-ecc-engine.c index 3d5b83238e14..515b9e3efc93 100644 --- a/drivers/mtd/nand/spi/on-die-ecc-engine.c +++ b/drivers/mtd/nand/spi/on-die-ecc-engine.c @@ -45,3 +45,108 @@ int spinand_check_ecc_status(struct spinand_device *spinand, u8 status) return -EINVAL; } + +static int spinand_noecc_ooblayout_ecc(struct mtd_info *mtd, int section, + struct mtd_oob_region *region) +{ + return -ERANGE; +} + +static int spinand_noecc_ooblayout_free(struct mtd_info *mtd, int section, + struct mtd_oob_region *region) +{ + if (section) + return -ERANGE; + + /* Reserve 2 bytes for the BBM. */ + region->offset = 2; + region->length = 62; + + return 0; +} + +static const struct mtd_ooblayout_ops spinand_noecc_ooblayout = { + .ecc = spinand_noecc_ooblayout_ecc, + .free = spinand_noecc_ooblayout_free, +}; + +static int ecc_spinand_ondie_init_ctx(struct nand_device *nand) +{ + struct spinand_device *spinand = nand_to_spinand(nand); + struct mtd_info *mtd = nanddev_to_mtd(nand); + struct ecc_sw_hamming_conf *engine_conf; + + nand->ecc.ctx.conf.step_size = nand->ecc.requirements.step_size; + nand->ecc.ctx.conf.strength = nand->ecc.requirements.strength; + + engine_conf = kzalloc(sizeof(*engine_conf), GFP_KERNEL); + if (!engine_conf) + return -ENOMEM; + + nand->ecc.ctx.priv = engine_conf; + + if (spinand->eccinfo.ooblayout) + mtd_set_ooblayout(mtd, spinand->eccinfo.ooblayout); + else + mtd_set_ooblayout(mtd, &spinand_noecc_ooblayout); + + return 0; +} + +static void ecc_spinand_ondie_cleanup_ctx(struct nand_device *nand) +{ + kfree(nand->ecc.ctx.priv); +} + +static int ecc_spinand_ondie_prepare_io_req(struct nand_device *nand, + struct nand_page_io_req *req, + void *oobbuf) +{ + struct spinand_device *spinand = nand_to_spinand(nand); + bool enable = (req->mode != MTD_OPS_RAW); + + /* Only enable or disable the engine */ + return spinand_ecc_enable(spinand, enable); +} + +static int ecc_spinand_ondie_finish_io_req(struct nand_device *nand, + struct nand_page_io_req *req, + void *oobbuf) +{ + struct ecc_spinand_ondie_conf *engine_conf = nand->ecc.ctx.priv; + struct spinand_device *spinand = nand_to_spinand(nand); + + if (req->mode == MTD_OPS_RAW) + return 0; + + /* Nothing to do when finishing a page write */ + if (req->type == NAND_PAGE_WRITE) + return 0; + + /* Finish a page write: check the status, report errors/bitflips */ + return spinand_check_ecc_status(spinand, engine_conf->status); +} + +static struct nand_ecc_engine_ops spinand_ondie_engine_ops = { + .init_ctx = ecc_spinand_ondie_init_ctx, + .cleanup_ctx = ecc_spinand_ondie_cleanup_ctx, + .prepare_io_req = ecc_spinand_ondie_prepare_io_req, + .finish_io_req = ecc_spinand_ondie_finish_io_req, +}; + +static struct nand_ecc_engine spinand_ondie_engine = { + .ops = &spinand_ondie_engine_ops, +}; + +void spinand_ondie_ecc_save_status(struct nand_device *nand, u8 status) +{ + struct ecc_spinand_ondie_conf *engine_conf = nand->ecc.ctx.priv; + + if (nand->ecc.engine == &spinand_ondie_engine && engine_conf) + engine_conf->status = status; +} + +struct nand_ecc_engine *spinand_ondie_ecc_get_engine(void) +{ + return &spinand_ondie_engine; +} diff --git a/include/linux/mtd/nand-spi-on-die-engine.h b/include/linux/mtd/nand-spi-on-die-engine.h new file mode 100644 index 000000000000..33e466b81583 --- /dev/null +++ b/include/linux/mtd/nand-spi-on-die-engine.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2019 Macronix + * Author: + * Miquèl RAYNAL + * + * This file is the header for the SPI-NAND on-die ECC implementation. + */ + +#ifndef __MTD_NAND_SPI_ON_DIE_H__ +#define __MTD_NAND_SPI_ON_DIE_H__ + +#if IS_ENABLED(CONFIG_MTD_SPI_NAND) + +/** + * struct ecc_spinand_ondie_conf - private SPI-NAND on-die ECC engine structure + * @status: status of the last wait operation that will be used in case + * ->get_status() is not populated by the spinand device. + */ +struct ecc_spinand_ondie_conf { + u8 status; +}; + +struct nand_ecc_engine *spinand_ondie_ecc_get_engine(void); +void spinand_ondie_ecc_save_status(struct nand_device *nand, u8 status); + +#else /* !CONFIG_MTD_SPI_NAND */ + +static inline struct nand_ecc_engine *spinand_ondie_ecc_get_engine(void) +{ + return NULL; +} +#endif /* CONFIG_MTD_SPI_NAND */ + +#endif /* __MTD_NAND_SPI_ON_DIE_H__ */ diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h index 3abe113e4f06..534c07fab9de 100644 --- a/include/linux/mtd/nand.h +++ b/include/linux/mtd/nand.h @@ -13,6 +13,7 @@ #include #include #include +#include struct nand_device;