From patchwork Wed Sep 29 11:54:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1534335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=uAWKEhc1; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=VRFSmCsu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HKFDl1Z4Xz9tkD for ; Wed, 29 Sep 2021 21:55:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sjeRzaGCwSNZoflvG4iYaOeYZpKQ08oLcFRP6fL6qSI=; b=uAWKEhc1LUWXgF nFBH71Mrn7c6kHYXtobw+HvPandril2YzyBFbXkVcdENJGtwhEiutQH8YzD1yvAFhNX9QdVemVWEn X0CDrpw9D0YtkuArtezOEPSlJpsltE3Q9EICSg+E1sq/ZPqiO1x/MjyD1BwgLkyblJ7ATPMRP1Hpo TKEgjkyx1W6EGpWdcbtG8i067+VPG5tDoVCSoukK3pzJdX8z12ZZ7TndARh70YAjD4+/4naWCjMJ0 PfR/mDFjAbnhb5GzvxBULpjwFCPJfyx7i+flCWTqkHnvDDtcvjPMfyhsyzF+0X3p3slFpwj+A4I+i K8hjZQv4e83FhXNDdcrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYAQ-00Atz0-0l; Wed, 29 Sep 2021 11:54:30 +0000 Received: from thorn.bewilderbeest.net ([2605:2700:0:5::4713:9cab]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYAM-00AtwL-4R for linux-mtd@lists.infradead.org; Wed, 29 Sep 2021 11:54:27 +0000 Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 0769E703; Wed, 29 Sep 2021 04:54:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1632916464; bh=TO54FDsoCMWCMt79Pdb9/ZG9fjkHhkFEnzaM9kEuuFY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VRFSmCsuA73GFLA2ZHn1JHXvx/nQv0K/qCNkNKiFrd2PdnRnKilrKd5z0zpb3mwwH mSZgbq9RE1MUVuwlHAVYZi9Rp3ApmmZLsJOloly5AU1DJZgNyb0U4dHpnVjvDRVb5a 8eBWHqXed0OrO6Yx+f50VYXSZriDiFVU7p46SiRU= From: Zev Weiss To: openbmc@lists.ozlabs.org Cc: Greg Kroah-Hartman , Jeremy Kerr , Joel Stanley , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Zev Weiss , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/6] mtd: core: clear out unregistered devices a bit more Date: Wed, 29 Sep 2021 04:54:04 -0700 Message-Id: <20210929115409.21254-3-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210929115409.21254-1-zev@bewilderbeest.net> References: <20210929115409.21254-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210929_045426_226019_6609B553 X-CRM114-Status: GOOD ( 10.68 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: This allows an MTD device that has been unregistered to be easily re-registered later without triggering "already registered" warnings in mtd_device_parse_register() and add_mtd_device(). Signed-off-by: Zev Weiss --- drivers/mtd/mtdcore.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This allows an MTD device that has been unregistered to be easily re-registered later without triggering "already registered" warnings in mtd_device_parse_register() and add_mtd_device(). Signed-off-by: Zev Weiss --- drivers/mtd/mtdcore.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c8fd7f758938..e22266f63ae9 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -747,6 +747,9 @@ int del_mtd_device(struct mtd_info *mtd) device_unregister(&mtd->dev); + /* Clear dev so mtd can be safely re-registered later if desired */ + memset(&mtd->dev, 0, sizeof(mtd->dev)); + idr_remove(&mtd_idr, mtd->index); of_node_put(mtd_get_of_node(mtd)); @@ -1018,8 +1021,10 @@ int mtd_device_unregister(struct mtd_info *master) { int err; - if (master->_reboot) + if (master->_reboot) { unregister_reboot_notifier(&master->reboot_notifier); + memset(&master->reboot_notifier, 0, sizeof(master->reboot_notifier)); + } if (master->otp_user_nvmem) nvmem_unregister(master->otp_user_nvmem); From patchwork Wed Sep 29 11:54:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1534342 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: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=q/P/L0X0; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=TPHBvzSo; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HKFGm683jz9ssD for ; Wed, 29 Sep 2021 21:57:04 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OSCcNMHp/bi+4AzJOKtji8u7VqeBc41i7RhdnCYsvxI=; b=q/P/L0X0ui3Dgp HqRmxP8UR+REumXjhwMZ7FBln5WxMjsIoqBaJ20dVeRfN+mUiLRNQNQRPH9SOxSIonE8Efvv2G7dw q4aUAQW7QFDIiRbvybCgCdxDXYZ/lfKuHLhwhIwfV6QDkHdihlyUjvMlyYYlOJIh1Re3JnSrCHKED Q9X+uKZ6ERKcSLrMCzUvSHGx3rXB8xktOQ5sbMrAUyxFUVjTVET8dpqpLVvmz0MGbsAAC3x0a86hZ 6a4UMHZT9ptFWY30oPGSh4G1sjQEFf+fZ2G6OKEv4qzM5e9wyC798sILTbDV9PErZTWgJJITF0Bwe dAm4f8t1slS2P6odM+Ow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYCF-00AucY-JW; Wed, 29 Sep 2021 11:56:23 +0000 Received: from thorn.bewilderbeest.net ([2605:2700:0:5::4713:9cab]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYAM-00AtwX-4d; Wed, 29 Sep 2021 11:54:29 +0000 Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 5AD49C20; Wed, 29 Sep 2021 04:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1632916465; bh=gWhuqV+M1Tlbi05phPKIzczuXxjec79mm6Htp3ec2Fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TPHBvzSoAHCSQnD3bL2UL4TNhvWQeplNlEAzdi66LW/EUSsZHaD8j+grZQ+lI2rPL eCkgGN+VYhA8AV5DkC4Shr4g/Hu70PSi+JCPV/MV1HNEtnkphvooWRgWmWSiRA5E23 67EO2AZnjt3cdiI2zXmGhZBitG81BlaRm1fHmeno= From: Zev Weiss To: openbmc@lists.ozlabs.org Cc: Greg Kroah-Hartman , Jeremy Kerr , Joel Stanley , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Zev Weiss , Tudor Ambarus , Michael Walle , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Andrew Jeffery , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/6] mtd: spi-nor: aspeed: Refactor registration/unregistration Date: Wed, 29 Sep 2021 04:54:05 -0700 Message-Id: <20210929115409.21254-4-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210929115409.21254-1-zev@bewilderbeest.net> References: <20210929115409.21254-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210929_045426_262506_EDAB36C5 X-CRM114-Status: GOOD ( 21.28 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: We now have separate functions for registering and unregistering individual flash chips, instead of the entire controller. This is a preparatory step for allowing userspace to request that a specific [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org We now have separate functions for registering and unregistering individual flash chips, instead of the entire controller. This is a preparatory step for allowing userspace to request that a specific chip be attached or detached at runtime. Signed-off-by: Zev Weiss --- drivers/mtd/spi-nor/controllers/aspeed-smc.c | 73 ++++++++++++-------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/drivers/mtd/spi-nor/controllers/aspeed-smc.c b/drivers/mtd/spi-nor/controllers/aspeed-smc.c index 7225870e8b18..3c153104a905 100644 --- a/drivers/mtd/spi-nor/controllers/aspeed-smc.c +++ b/drivers/mtd/spi-nor/controllers/aspeed-smc.c @@ -107,9 +107,10 @@ struct aspeed_smc_controller { const struct aspeed_smc_info *info; /* type info of controller */ void __iomem *regs; /* controller registers */ void __iomem *ahb_base; /* per-chip windows resource */ + struct resource *ahb_res; /* resource for AHB address space */ u32 ahb_window_size; /* full mapping window size */ - struct aspeed_smc_chip *chips[]; /* pointers to attached chips */ + struct aspeed_smc_chip *chips[]; /* pointers to connected chips */ }; /* @@ -399,15 +400,24 @@ static ssize_t aspeed_smc_write_user(struct spi_nor *nor, loff_t to, return len; } +static int aspeed_smc_unregister_chip(struct aspeed_smc_chip *chip) +{ + return mtd_device_unregister(&chip->nor.mtd); +} + static int aspeed_smc_unregister(struct aspeed_smc_controller *controller) { struct aspeed_smc_chip *chip; - int n; + int n, ret; for (n = 0; n < controller->info->nce; n++) { chip = controller->chips[n]; - if (chip) - mtd_device_unregister(&chip->nor.mtd); + if (chip) { + ret = aspeed_smc_unregister_chip(chip); + if (ret) + dev_warn(controller->dev, "failed to unregister CS%d: %d\n", + n, ret); + } } return 0; @@ -756,14 +766,39 @@ static const struct spi_nor_controller_ops aspeed_smc_controller_ops = { .write = aspeed_smc_write_user, }; -static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, - struct device_node *np, struct resource *r) +static int aspeed_smc_register_chip(struct aspeed_smc_chip *chip) { - const struct spi_nor_hwcaps hwcaps = { + static const struct spi_nor_hwcaps hwcaps = { .mask = SNOR_HWCAPS_READ | SNOR_HWCAPS_READ_FAST | SNOR_HWCAPS_PP, }; + int ret; + + ret = aspeed_smc_chip_setup_init(chip, chip->controller->ahb_res); + if (ret) + goto out; + + /* + * TODO: Add support for Dual and Quad SPI protocols attach when board + * support is present as determined by of property. + */ + ret = spi_nor_scan(&chip->nor, NULL, &hwcaps); + if (ret) + goto out; + + ret = aspeed_smc_chip_setup_finish(chip); + if (ret) + goto out; + + ret = mtd_device_register(&chip->nor.mtd, NULL, 0); +out: + return ret; +} + +static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, + struct device_node *np, struct resource *r) +{ const struct aspeed_smc_info *info = controller->info; struct device *dev = controller->dev; struct device_node *child; @@ -773,7 +808,6 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, for_each_available_child_of_node(np, child) { struct aspeed_smc_chip *chip; struct spi_nor *nor; - struct mtd_info *mtd; /* This driver does not support NAND or NOR flash devices. */ if (!of_device_is_compatible(child, "jedec,spi-nor")) @@ -810,35 +844,17 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, chip->cs = cs; nor = &chip->nor; - mtd = &nor->mtd; nor->dev = dev; nor->priv = chip; spi_nor_set_flash_node(nor, child); nor->controller_ops = &aspeed_smc_controller_ops; - ret = aspeed_smc_chip_setup_init(chip, r); - if (ret) - break; - - /* - * TODO: Add support for Dual and Quad SPI protocols - * attach when board support is present as determined - * by of property. - */ - ret = spi_nor_scan(nor, NULL, &hwcaps); - if (ret) - break; - - ret = aspeed_smc_chip_setup_finish(chip); - if (ret) - break; + controller->chips[cs] = chip; - ret = mtd_device_register(mtd, NULL, 0); + ret = aspeed_smc_register_chip(chip); if (ret) break; - - controller->chips[cs] = chip; } if (ret) { @@ -881,6 +897,7 @@ static int aspeed_smc_probe(struct platform_device *pdev) return PTR_ERR(controller->regs); res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + controller->ahb_res = res; controller->ahb_base = devm_ioremap_resource(dev, res); if (IS_ERR(controller->ahb_base)) return PTR_ERR(controller->ahb_base); From patchwork Wed Sep 29 11:54:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1534348 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: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=G+V+sfxF; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=HH/p5S6h; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HKFJZ1Q2Sz9ssD for ; Wed, 29 Sep 2021 21:58:38 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TvgMybGKs37pETSN+8Wfa2w8ePf5G5bS302K4H0wgzw=; b=G+V+sfxFxLm5jR P7Hc8YTBAXF72rmSSpLi9sDxobYhQX0ySopn73aH1G3p1H37KTJQP/pbWXFYmCzsBTiXAOHtjdXkt SQ6reT1ucLVr+3v+I+rHQc1hMnCCBF3+OmeEyp4L3A2xnLM0K+1+UXA1O82OcNaZNHdG8WbVIzSrx w2pLwCqUYhNbDUHeGVgCSf7wkMA4aNqKvdUkyK9P/7H5agYbqmAe6LcnRULGwWQ6guy+JT7LCscIm 0PYuxDur5KAMUivgaNq2bu3LsWXrPDdQtYsfeNEO6Kh5/5pP85Jt3/mtrcuFWUV+Dd71ASw/TWGyb UsVRqbV86jiuSQ4OTL2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYDq-00AvC1-1X; Wed, 29 Sep 2021 11:58:02 +0000 Received: from thorn.bewilderbeest.net ([2605:2700:0:5::4713:9cab]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYAP-00Atyc-1I; Wed, 29 Sep 2021 11:54:30 +0000 Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id 716C3C53; Wed, 29 Sep 2021 04:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1632916468; bh=R1j5OVnuaawARx/Lb+7fwJs4wNisTGf3IZegQlGAoXI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HH/p5S6hIH7hSeX9tW5puYJY+vGYxS34mcVMsTAgDy7++ub7A3jZ4QaCh0Eprp3qU joAq/DCFX+t1h2e2LUCYdtsPSrw36FErbV1vTgKxuFPuOS5/FWOYOPbNqSy+g1SbyW K8eZWPDr/29Fh6fJAd5JWm0QFX+Rh9FinrBtpD+Y= From: Zev Weiss To: openbmc@lists.ozlabs.org Cc: Greg Kroah-Hartman , Jeremy Kerr , Joel Stanley , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Zev Weiss , Andrew Jeffery , Tudor Ambarus , Michael Walle , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [PATCH 4/6] mtd: spi-nor: aspeed: Allow attaching & detaching chips at runtime Date: Wed, 29 Sep 2021 04:54:06 -0700 Message-Id: <20210929115409.21254-5-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210929115409.21254-1-zev@bewilderbeest.net> References: <20210929115409.21254-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210929_045429_133699_5466D275 X-CRM114-Status: GOOD ( 22.77 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: There are now two new sysfs attributes, attach_chip and detach_chip, into which a chip select number can be written to attach or detach the corresponding chip. Signed-off-by: Zev Weiss --- .../ABI/stable/sysfs-driver-aspeed-smc | 17 +++ drivers/mtd/spi-nor/controllers/aspeed-smc.c | 101 +++++++++++++++++- 2 files changed, 115 insertio [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org There are now two new sysfs attributes, attach_chip and detach_chip, into which a chip select number can be written to attach or detach the corresponding chip. Signed-off-by: Zev Weiss --- .../ABI/stable/sysfs-driver-aspeed-smc | 17 +++ drivers/mtd/spi-nor/controllers/aspeed-smc.c | 101 +++++++++++++++++- 2 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 Documentation/ABI/stable/sysfs-driver-aspeed-smc diff --git a/Documentation/ABI/stable/sysfs-driver-aspeed-smc b/Documentation/ABI/stable/sysfs-driver-aspeed-smc new file mode 100644 index 000000000000..871b4d65ccb2 --- /dev/null +++ b/Documentation/ABI/stable/sysfs-driver-aspeed-smc @@ -0,0 +1,17 @@ +What: /sys/bus/platform/drivers/aspeed-smc/*/attach_chip +Date: September 2021 +Contact: Zev Weiss +Description: A chip select number may be written into this file to + request that the corresponding chip be attached by the + driver. +Users: OpenBMC. Proposed changes should be mailed to + openbmc@lists.ozlabs.org + +What: /sys/bus/platform/drivers/aspeed-smc/*/detach_chip +Date: September 2021 +Contact: Zev Weiss +Description: A chip select number may be written into this file to + request that the corresponding chip be detached by the + driver. +Users: OpenBMC. Proposed changes should be mailed to + openbmc@lists.ozlabs.org diff --git a/drivers/mtd/spi-nor/controllers/aspeed-smc.c b/drivers/mtd/spi-nor/controllers/aspeed-smc.c index 3c153104a905..da49192a8220 100644 --- a/drivers/mtd/spi-nor/controllers/aspeed-smc.c +++ b/drivers/mtd/spi-nor/controllers/aspeed-smc.c @@ -91,6 +91,7 @@ struct aspeed_smc_controller; struct aspeed_smc_chip { int cs; + bool attached; struct aspeed_smc_controller *controller; void __iomem *ctl; /* control register */ void __iomem *ahb_base; /* base of chip window */ @@ -402,7 +403,15 @@ static ssize_t aspeed_smc_write_user(struct spi_nor *nor, loff_t to, static int aspeed_smc_unregister_chip(struct aspeed_smc_chip *chip) { - return mtd_device_unregister(&chip->nor.mtd); + int ret = -ENOENT; + mutex_lock(&chip->controller->mutex); + if (chip->attached) { + ret = mtd_device_unregister(&chip->nor.mtd); + if (!ret) + chip->attached = false; + } + mutex_unlock(&chip->controller->mutex); + return ret; } static int aspeed_smc_unregister(struct aspeed_smc_controller *controller) @@ -412,7 +421,7 @@ static int aspeed_smc_unregister(struct aspeed_smc_controller *controller) for (n = 0; n < controller->info->nce; n++) { chip = controller->chips[n]; - if (chip) { + if (chip && chip->attached) { ret = aspeed_smc_unregister_chip(chip); if (ret) dev_warn(controller->dev, "failed to unregister CS%d: %d\n", @@ -775,6 +784,13 @@ static int aspeed_smc_register_chip(struct aspeed_smc_chip *chip) }; int ret; + mutex_lock(&chip->controller->mutex); + + if (chip->attached) { + ret = -EEXIST; + goto out; + } + ret = aspeed_smc_chip_setup_init(chip, chip->controller->ahb_res); if (ret) goto out; @@ -792,7 +808,12 @@ static int aspeed_smc_register_chip(struct aspeed_smc_chip *chip) goto out; ret = mtd_device_register(&chip->nor.mtd, NULL, 0); + if (ret) + goto out; + + chip->attached = true; out: + mutex_unlock(&chip->controller->mutex); return ret; } @@ -865,6 +886,72 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, return ret; } +static inline struct aspeed_smc_controller *to_aspeed_smc_controller(struct device *dev) +{ + struct platform_device *pdev = container_of(dev, struct platform_device, dev); + return platform_get_drvdata(pdev); +} + +static ssize_t attach_chip_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long cs; + struct aspeed_smc_controller *controller; + struct aspeed_smc_chip *chip; + ssize_t ret = kstrtoul(buf, 0, &cs); + if (ret) + return ret; + + controller = to_aspeed_smc_controller(dev); + if (cs >= controller->info->nce) + return -EINVAL; + + chip = controller->chips[cs]; + + if (!chip) + return -ENODEV; + + ret = aspeed_smc_register_chip(chip); + + return ret ? ret : count; +} +static DEVICE_ATTR_WO(attach_chip); + +static ssize_t detach_chip_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + unsigned long cs; + struct aspeed_smc_controller *controller; + struct aspeed_smc_chip *chip; + ssize_t ret = kstrtoul(buf, 0, &cs); + if (ret) + return ret; + + controller = to_aspeed_smc_controller(dev); + if (cs >= controller->info->nce) + return -EINVAL; + + chip = controller->chips[cs]; + + if (!chip) + return -ENODEV; + + ret = aspeed_smc_unregister_chip(chip); + + return ret ? ret : count; +} +static DEVICE_ATTR_WO(detach_chip); + +static struct attribute *aspeed_smc_sysfs_attrs[] = { + &dev_attr_attach_chip.attr, + &dev_attr_detach_chip.attr, + NULL, +}; + +static const struct attribute_group aspeed_smc_sysfs_attr_group = { + .attrs = aspeed_smc_sysfs_attrs, +}; + static int aspeed_smc_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -905,8 +992,16 @@ static int aspeed_smc_probe(struct platform_device *pdev) controller->ahb_window_size = resource_size(res); ret = aspeed_smc_setup_flash(controller, np, res); - if (ret) + if (ret) { dev_err(dev, "Aspeed SMC probe failed %d\n", ret); + return ret; + } + + ret = devm_device_add_group(dev, &aspeed_smc_sysfs_attr_group); + if (ret) { + dev_err(dev, "Failed to create sysfs files\n"); + aspeed_smc_unregister(controller); + } return ret; } From patchwork Wed Sep 29 11:54:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zev Weiss X-Patchwork-Id: 1534350 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: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=cVFsF4LV; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=bewilderbeest.net header.i=@bewilderbeest.net header.a=rsa-sha256 header.s=thorn header.b=e1JR3ccg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) 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=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HKFLT07fcz9ssD for ; Wed, 29 Sep 2021 22:00:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FuHFmN2Q8ZcO06duQyUzvkclbl1z3wcliNSjx8rhsug=; b=cVFsF4LVUpYPYk +X6qmdxiy4JKX3Yl2LWMSDwLNBA+d12IsX7B9ExAC6qAfqACSCYDrWVVJfrxkQ8YIuRm5FYRFxoB3 P+5TXDr48eeBkKdw+a4NGSV5583L+266f3ADTyCSFF7mquRxmfYQV06u3u+Yp+HvzTg9gL+74RWI7 5wZY/jqbQyjpvpZ2kMKhYCrOWyl1rWNJbOHihaBJxUc5x3bMau9zEONGjhwdTHPx75ru+Tkia5z0I 4e22YpoogDAwOjOQ9zKWze2NDQM5K8cIBznF9ueg+aFqxPORT9H0lPZBUa/6/kOX8AZK+5Vlgd3qN 9/yhrHsaEJ7jHoMazyDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYFU-00AvkI-82; Wed, 29 Sep 2021 11:59:44 +0000 Received: from thorn.bewilderbeest.net ([2605:2700:0:5::4713:9cab]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mVYAQ-00Atzb-Ge; Wed, 29 Sep 2021 11:54:32 +0000 Received: from hatter.bewilderbeest.net (71-212-29-146.tukw.qwest.net [71.212.29.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: zev) by thorn.bewilderbeest.net (Postfix) with ESMTPSA id E8698C81; Wed, 29 Sep 2021 04:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bewilderbeest.net; s=thorn; t=1632916470; bh=Y009K+RO8RDHvkwOXnnVGdcXcV27deDObF+gK4oQAV0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e1JR3ccgRHn33ud6tMgC1CMeeRisKIlAAgrBRm7eb6hSGpyGrdolKwcy7HVnjgYQk PNAz2XS/8sH8jKzNjRq3hHsPjLgkukc3El2ZdjBfGCg1RbDxoUuzgZfUkDPi+piwd/ RC1TN5yznTetYwWE5qOhl0+22V/KcVmBL31QXIEc= From: Zev Weiss To: openbmc@lists.ozlabs.org Cc: Greg Kroah-Hartman , Jeremy Kerr , Joel Stanley , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Zev Weiss , Tudor Ambarus , Michael Walle , Pratyush Yadav , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Andrew Jeffery , linux-mtd@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] mtd: spi-nor: aspeed: Don't automatically attach reserved chips Date: Wed, 29 Sep 2021 04:54:07 -0700 Message-Id: <20210929115409.21254-6-zev@bewilderbeest.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210929115409.21254-1-zev@bewilderbeest.net> References: <20210929115409.21254-1-zev@bewilderbeest.net> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210929_045430_601407_ABA5B8A0 X-CRM114-Status: GOOD ( 15.35 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: With this change, any flash chips under the controller that are marked with a DT status of "reserved" will be created, but not automatically attached. Userspace can later request that they be attached [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org With this change, any flash chips under the controller that are marked with a DT status of "reserved" will be created, but not automatically attached. Userspace can later request that they be attached using the attach_chip sysfs file. This is to accommodate situations where a chip may be (for example) shared with another controller external to the SoC and require userspace to arbitrate access to it prior to actually attaching it. (such as a firmware SPI flash shared between a BMC and the host system). Signed-off-by: Zev Weiss --- drivers/mtd/spi-nor/controllers/aspeed-smc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/controllers/aspeed-smc.c b/drivers/mtd/spi-nor/controllers/aspeed-smc.c index da49192a8220..328b008fafb2 100644 --- a/drivers/mtd/spi-nor/controllers/aspeed-smc.c +++ b/drivers/mtd/spi-nor/controllers/aspeed-smc.c @@ -826,10 +826,14 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, unsigned int cs; int ret = -ENODEV; - for_each_available_child_of_node(np, child) { + for_each_child_of_node(np, child) { struct aspeed_smc_chip *chip; struct spi_nor *nor; + /* Skip disabled nodes, but include reserved ones for later attachment */ + if (!of_device_is_available(child) && !of_device_is_reserved(child)) + continue; + /* This driver does not support NAND or NOR flash devices. */ if (!of_device_is_compatible(child, "jedec,spi-nor")) continue; @@ -873,6 +877,9 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, controller->chips[cs] = chip; + if (of_device_is_reserved(child)) + continue; + ret = aspeed_smc_register_chip(chip); if (ret) break;