From patchwork Tue Jul 3 21:59:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10505349 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 34EFE60225 for ; Tue, 3 Jul 2018 22:01:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2277228421 for ; Tue, 3 Jul 2018 22:01:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 14BBD28740; Tue, 3 Jul 2018 22:01:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B0C3C28421 for ; Tue, 3 Jul 2018 22:01:53 +0000 (UTC) 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=fn3yKSUg7JkLaykagSaQPzhpfQilcCo++HUnIrphBWg=; b=BUu4X5hxHt42CVmLJVjYYiDOdX y+5KLx1TVz4JP3gnKnQL6jDXy4HG4Jrqe6IusfkIAXsTSG6rBubLOf39D9sJtfrEcsBNwzbPhkcb/ /6JnzdxzgtmuFCc7iX7TNgNIE87dszSN7DiqTTbw4B5T5kdmBNpvp5R88BX4+fCg9nsfPDY1S12ce twMuEiEZtKR86zcd+hOmCVDT1fVzuJsjkO4snWxEpK1f/YG/8nZ883mVK1TvPnQE8Yq6KwLdhVb/0 wokzwRgKbhatFpR6avT+e8oNVgKSfpwqRW64QCncCZjthLtsSQsXK1mMGC7V6GBkok0ws1WcMOn0P dpzO0zlA==; 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 1faTMt-000592-0L for patchwork-linux-mediatek@patchwork.kernel.org; Tue, 03 Jul 2018 22:01:51 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1faTLv-0004PQ-Ki; Tue, 03 Jul 2018 22:00:54 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 78406207DA; Wed, 4 Jul 2018 00:00:40 +0200 (CEST) Received: from localhost.localdomain (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id 0CCF820719; Wed, 4 Jul 2018 00:00:39 +0200 (CEST) From: Miquel Raynal To: Wenyou Yang , Josh Wu , Tudor Ambarus , Boris Brezillon , Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Nicolas Ferre , Alexandre Belloni , Kamal Dasu , Masahiro Yamada , Han Xu , Harvey Hunt , Vladimir Zapolskiy , Sylvain Lemieux , Xiaolei Li , Matthias Brugger , Maxime Ripard , Chen-Yu Tsai , Marc Gonzalez , Mans Rullgard , Stefan Agner Subject: [PATCH v2 01/32] mtd: rawnand: add hooks that may be called during nand_scan() Date: Tue, 3 Jul 2018 23:59:58 +0200 Message-Id: <20180703220029.19565-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703220029.19565-1-miquel.raynal@bootlin.com> References: <20180703220029.19565-1-miquel.raynal@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180703_150052_005375_0C9EDC64 X-CRM114-Status: GOOD ( 21.39 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: bcm-kernel-feedback-list@broadcom.com, linux-mediatek@lists.infradead.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In order to remove the limitation that forbids dynamic allocation in nand_scan_ident(), we must create a path that will be the same for all controller drivers. The idea is to use nand_scan() instead of the widely implemented nand_scan_ident()/nand_scan_tail() couple. In order to achieve this, controller drivers will need to adjust some parameters between these two functions depending on the NAND chip wired on them. For that, a hook called ->attach_chip() is created in the nand_hw_control structure. This structure may be referenced by two ways: 1/ if the driver does not implement its own controller, the chip->controller hook is not populated before nand_scan() so it cannot be dereferenced: use chip->hwcontrol instead (which is statically allocated and will be referenced later by chip->controller anyway). 2/ through chip->controller if the driver implements its own controller. Another hook, ->detach_chip() is also introduced in order to clean the controller driver's potential allocations in case of failure of nand_scan_tail(). There is no need for the controller driver to call the ->detach_chip() hook directly upon error after a successful nand_scan(). In this situation, calling nand_release() as before is enough. Signed-off-by: Miquel Raynal --- drivers/mtd/nand/raw/nand_base.c | 21 +++++++++++++++++++-- include/linux/mtd/rawnand.h | 6 ++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_base.c b/drivers/mtd/nand/raw/nand_base.c index faac82b1e058..97a74d48b0cf 100644 --- a/drivers/mtd/nand/raw/nand_base.c +++ b/drivers/mtd/nand/raw/nand_base.c @@ -6712,11 +6712,23 @@ EXPORT_SYMBOL(nand_scan_tail); int nand_scan_with_ids(struct mtd_info *mtd, int maxchips, struct nand_flash_dev *ids) { + struct nand_chip *chip = mtd_to_nand(mtd); int ret; ret = nand_scan_ident(mtd, maxchips, ids); - if (!ret) - ret = nand_scan_tail(mtd); + if (ret) + return ret; + + if (chip->controller->attach_chip) { + ret = chip->controller->attach_chip(chip); + if (ret) + return ret; + } + + ret = nand_scan_tail(mtd); + if (ret && chip->controller->detach_chip) + chip->controller->detach_chip(chip); + return ret; } EXPORT_SYMBOL(nand_scan_with_ids); @@ -6744,7 +6756,12 @@ void nand_cleanup(struct nand_chip *chip) /* Free manufacturer priv data. */ nand_manufacturer_cleanup(chip); + + /* Free controller specific allocations after chip identification */ + if (chip->controller->detach_chip) + chip->controller->detach_chip(chip); } + EXPORT_SYMBOL_GPL(nand_cleanup); /** diff --git a/include/linux/mtd/rawnand.h b/include/linux/mtd/rawnand.h index 0c6fb316b409..81654211e520 100644 --- a/include/linux/mtd/rawnand.h +++ b/include/linux/mtd/rawnand.h @@ -517,11 +517,17 @@ struct nand_id { * @wq: wait queue to sleep on if a NAND operation is in * progress used instead of the per chip wait queue * when a hw controller is available. + * @attach_chip: Callback that may be called between nand_detect() and + * nand_scan_tail() during nand_scan() (optional). + * @detach_chip: Callback that may be called if nand_scan_tail() fails + * (optional). */ struct nand_hw_control { spinlock_t lock; struct nand_chip *active; wait_queue_head_t wq; + int (*attach_chip)(struct nand_chip *chip); + void (*detach_chip)(struct nand_chip *chip); }; static inline void nand_hw_control_init(struct nand_hw_control *nfc)