From patchwork Wed Jul 19 22:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 122855 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2742710vqt; Wed, 19 Jul 2023 15:24:14 -0700 (PDT) X-Google-Smtp-Source: APBJJlHTvuEBqtRgp/cKL9C1nelAKGdxwx1Rji0sqCbRSQ0fH8+czjtZWpxJM7w0xVpXYN/dR1A+ X-Received: by 2002:a05:6358:919c:b0:133:9da:8d9f with SMTP id j28-20020a056358919c00b0013309da8d9fmr9289397rwa.14.1689805454276; Wed, 19 Jul 2023 15:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689805454; cv=none; d=google.com; s=arc-20160816; b=iWvuFxGRhgpoVipzhnvWijX6C7+5qUCtP4gGuOa8EKZwcpgJscD05UG4Z5C1HU442V xMPFEWSA6iDd65meZS/E7MB9nZBd1tQXSwanbTiqC/gq/LKsW8yfjsl75vgXY8YXVNN9 5TPb8Lt320c+UZCu2bwph35ddBUZAf7/zc0lNYq6F93qm3lx/2umySDlqbNZvZQ+wezp X5wF3KuqnXFNd94sqJgixqtmlDvVoJy4FWfmYt2ivPhcttDzXANvh/sTqy+FF5SaKQVj IXKytzBI2b5mp9RmbROU4w1AqNIapopvRjOx2m9zNzE2YKfJNEOWx+OR1/lXu9tljv/B HEIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=VAXBhQigt26PjeBFPqjyjmLBXdATnL0jCOqfvG5AcV0=; fh=O/hjEvlM0nIN8LC6WbIQ4s0L6nmnRMOzajXXMF81As0=; b=gCa/X5+lBA+kpNS8A6NLvBfpgkatUFwmwp0HoiwNZsIaR/gaWtdBsgMZYFXjLiGg0f WP4GJz9BHJrnqWxm5YDY4wJ4GkawV9TFPAv8zkEFtrxBMufcJ4ePqx7G9HxI8fyyzXOB q3/HnnHa67poo1aNlS9IqXqnz3cIDvYOsUkD8Bt5uIN3BJQsb8U2GF1gxTSEAOuJUmWm ziHlT/gm7q3nJ2GV5jzqicDAyK/kIbQ2IFLQtsbMOoJl1Ci3AhO/qvJVifAAlQXHCl9T cr6TcTJd1Q9oDi2unc6mXCuTK1fWVQ5DH5BtsPOf3RoIQDNY0ECkU5BeyXgvk0vDaE9u 6rSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 14-20020a63164e000000b0055ae2071a32si4161842pgw.611.2023.07.19.15.24.01; Wed, 19 Jul 2023 15:24:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230086AbjGSWDL (ORCPT + 99 others); Wed, 19 Jul 2023 18:03:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjGSWDK (ORCPT ); Wed, 19 Jul 2023 18:03:10 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9B801FF6; Wed, 19 Jul 2023 15:03:07 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qMFFf-0008JI-1v; Wed, 19 Jul 2023 22:02:31 +0000 Date: Wed, 19 Jul 2023 23:02:23 +0100 From: Daniel Golle To: Jens Axboe , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dave Chinner , Matthew Wilcox , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Jan Kara , Daniel Golle , Damien Le Moal , Ming Lei , Min Li , Christian Loehle , Adrian Hunter , Hannes Reinecke , Jack Wang , Florian Fainelli , Yeqi Fu , Avri Altman , Hans de Goede , Ye Bin , Greg Kroah-Hartman , =?utf-8?b?UmFmYcWCIE1pxYJl?= =?utf-8?b?Y2tp?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [RFC PATCH 1/6] mmc: core: set card fwnode_handle Message-ID: <42b56531a91e88eea8f57d6be0b01124e67c5232.1689802933.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771889443909770540 X-GMAIL-MSGID: 1771889443909770540 Instead of just populating dev.of_node, also set fwnode in case it isn't set yet and of_node is present. Signed-off-by: Daniel Golle --- drivers/mmc/core/bus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 2c3074a605fc4..ecf6e23e4c307 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -361,6 +361,8 @@ int mmc_add_card(struct mmc_card *card) mmc_add_card_debugfs(card); card->dev.of_node = mmc_of_find_child_device(card->host, 0); + if (card->dev.of_node && !card->dev.fwnode) + card->dev.fwnode = &card->dev.of_node->fwnode; device_enable_async_suspend(&card->dev); From patchwork Wed Jul 19 22:02:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 122861 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2743914vqt; Wed, 19 Jul 2023 15:27:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlF2xJe/BCRq9o86hqUQDk9rkfYlszq0eKOQrn43BkdMjf1bd5uaYcSUP95LLdyiryfuL4Mh X-Received: by 2002:a05:6402:1283:b0:51d:e1cf:dc8a with SMTP id w3-20020a056402128300b0051de1cfdc8amr463996edv.22.1689805634799; Wed, 19 Jul 2023 15:27:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689805634; cv=none; d=google.com; s=arc-20160816; b=K/2W2W3/3lcNBxWxD7cRjSEKZ5H8yUqsyq+T6WUSmO7q8XMRBepeHH35i1nZfBT8ke MGguj8RGl6jiF/I3jI34QQwit/cJ8QDHwJJ8CeZzF2KYhYsChlkWak/Vi3ISOgQZ2Srs PF7xeh8A2RMSsh4Ka4+L2Sv6B5xGuQsjYn2nSFKliX4kNvtbTjstOXLngkBzMeQkwDOZ BcHuqxfpN9B2/nIvVIavVSCeL27LFOxPe03L0rR4piYJdWZfbQjqzIIrL8ZYiclDiazY YocvJfhwxkJG3tmT04TmeTtC0dZzthh2T6WanU3x06XaiCyZm9QiybEppWWIreqYT1WT b+ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=tXYT4uAYKkmC7cZff6dBIrrvsJsYT9JZconVxKgdMQ0=; fh=O/hjEvlM0nIN8LC6WbIQ4s0L6nmnRMOzajXXMF81As0=; b=oCRucd+de//4wafo4N5pFCkSbYhQcUofS1kVYxfHWXZu+C2GI4ixomCHgR3yJng8ko NqQTbe0AXrJanAm5dHClJYx5shtAaYdiZbDCui+ISZOa6DhmGtDvW2QKMMDN1laY2Dsu YUqrzCAo2AphOFQSS75/2lWj5ZQAMtOIkvo51mOdXMzmCNt5p8hYlVF9GOaxGQsqNiH7 VzESJeDnWMRv2cEnhV2Aff1JEqB/LjWcDkqrCkHGsR52W2eY9fO3KN47iEbBQpFP1E+/ 93lnaQ6KGCQZ1tjSbO2ehSPNWwh5Q1LgwBJPbcw+xmH1GbTJVjD2MiaFNhKCfYE9e143 yrKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u19-20020aa7d893000000b00521d23adb1asi802808edq.258.2023.07.19.15.26.51; Wed, 19 Jul 2023 15:27:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230212AbjGSWD1 (ORCPT + 99 others); Wed, 19 Jul 2023 18:03:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230211AbjGSWDY (ORCPT ); Wed, 19 Jul 2023 18:03:24 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88BDA2122; Wed, 19 Jul 2023 15:03:19 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qMFG1-0008Ji-2q; Wed, 19 Jul 2023 22:02:53 +0000 Date: Wed, 19 Jul 2023 23:02:45 +0100 From: Daniel Golle To: Jens Axboe , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dave Chinner , Matthew Wilcox , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Jan Kara , Daniel Golle , Damien Le Moal , Ming Lei , Min Li , Christian Loehle , Adrian Hunter , Hannes Reinecke , Jack Wang , Florian Fainelli , Yeqi Fu , Avri Altman , Hans de Goede , Ye Bin , Greg Kroah-Hartman , =?utf-8?b?UmFmYcWCIE1pxYJl?= =?utf-8?b?Y2tp?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [RFC PATCH 2/6] mmc: block: set fwnode of disk devices Message-ID: <1ce5f56df546cec25ef741f381286f1d7c33d000.1689802933.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771889633452101286 X-GMAIL-MSGID: 1771889633452101286 Set fwnode of disk devices to 'block', 'boot0' and 'boot1' subnodes of the mmc-card. This is done in preparation for having the eMMC act as NVMEM provider. Signed-off-by: Daniel Golle --- drivers/mmc/core/block.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index f701efb1fa785..fc1a9f31bd253 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2413,6 +2413,8 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, int area_type, unsigned int part_type) { + struct fwnode_handle *fwnode; + struct device *ddev; struct mmc_blk_data *md; int devidx, ret; char cap_str[10]; @@ -2509,6 +2511,12 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, blk_queue_write_cache(md->queue.queue, cache_enabled, fua_enabled); + ddev = disk_to_dev(md->disk); + fwnode = device_get_named_child_node(subname ? md->parent->parent : + md->parent, + subname ? subname : "block"); + ddev->fwnode = fwnode; + string_get_size((u64)size, 512, STRING_UNITS_2, cap_str, sizeof(cap_str)); pr_info("%s: %s %s %s%s\n", From patchwork Wed Jul 19 22:03:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 122849 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2738174vqt; Wed, 19 Jul 2023 15:13:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEPHsHKs5umzWt9kzQ9SHQP4on/+DvM3cWnpLm1gHS1Ct2ni5sCw3cMlwYl7fojewIDVOQF X-Received: by 2002:a17:907:2d23:b0:978:90cc:bf73 with SMTP id gs35-20020a1709072d2300b0097890ccbf73mr4074105ejc.48.1689804823778; Wed, 19 Jul 2023 15:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689804823; cv=none; d=google.com; s=arc-20160816; b=scWeG9H/Hwu50UogHcVw7aJk5I01k9go4NbBnV62ifC91+tFKH4kckO6ulkiJ4ONGl kX+sIo2Hvkf4h0066z7yppk+q8Hdec/UblqMCiDTGJb8wxvP6Wnb+3ZgtnS/iitaKGQW DqBt16Msxefen4Hk30ZLW2UYiHtcrIHQ/vH4O7fJwNfrZOFlukK8gZAh8Zqz4EES4nRZ BkHGS8ETIrudALToJyDJsxkW3nGrfSoZUnDtNlW+UZ+qV48DiFE27Dz0J4efQfbYwNG6 jpttm7mHVV+7ugXfj0vDb7AZwWqOuMdpHMqkfiX9IgkQIh52QdT+KRjhHWw++SC6SRIb Qy3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=aI+oONGaegupJ0seogiMq5KOugYmjBNwpl7+MkGhXeY=; fh=O/hjEvlM0nIN8LC6WbIQ4s0L6nmnRMOzajXXMF81As0=; b=rySUH0T8WAcV+Jgdb2O+AgQJIHYktjKMUkBKP8XLB0pl5J7lJz9U/U2kw/UgfxP/Lp H6Vdnx0rlg2Zs6fYjHWS81E0ZFK0xGy1EiInC6aw1d6a9WLG0AMt1/7DPpLxzmQ5kWED jhI6FhIn5YLYvyzhmHcJOXTqxK91QIS7bZeFOb8PzUmzs4OlvwFHkhJ/utL3TvuqfIVl bOPFzcZdjv8UwJ4wqz6PjAeV64e85LAflO2dz93U+xrwCK5mclt0iC5FzophF4tJIj6N F813yZ1fqSBAmAHbGaKK8hOg5Rql+D0P79X3TtXN3mgu0JX/1vAu/ClpCP2H/0vkCuAm t7JA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id xa23-20020a170907b9d700b009938248d370si3652266ejc.2.2023.07.19.15.13.19; Wed, 19 Jul 2023 15:13:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230181AbjGSWDr (ORCPT + 99 others); Wed, 19 Jul 2023 18:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229574AbjGSWDp (ORCPT ); Wed, 19 Jul 2023 18:03:45 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDBB2213D; Wed, 19 Jul 2023 15:03:29 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qMFGL-0008Kc-1x; Wed, 19 Jul 2023 22:03:13 +0000 Date: Wed, 19 Jul 2023 23:03:05 +0100 From: Daniel Golle To: Jens Axboe , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dave Chinner , Matthew Wilcox , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Jan Kara , Daniel Golle , Damien Le Moal , Ming Lei , Min Li , Christian Loehle , Adrian Hunter , Hannes Reinecke , Jack Wang , Florian Fainelli , Yeqi Fu , Avri Altman , Hans de Goede , Ye Bin , Greg Kroah-Hartman , =?utf-8?b?UmFmYcWCIE1pxYJl?= =?utf-8?b?Y2tp?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [RFC PATCH 3/6] block: add new genhd flag GENHD_FL_NO_NVMEM Message-ID: <96510d925cb0ca1a3a132f8f8affd4bbdafd8fc9.1689802933.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771888782752038240 X-GMAIL-MSGID: 1771888782752038240 Add new flag to destinguish block devices which should not act as an NVMEM provider, such as for example an emulated block device on top of an MTD partition which already acts as an NVMEM provider itself. Signed-off-by: Daniel Golle --- include/linux/blkdev.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 2f5371b8482c0..e853d1815be15 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -80,11 +80,14 @@ struct partition_meta_info { * ``GENHD_FL_NO_PART``: partition support is disabled. The kernel will not * scan for partitions from add_disk, and users can't add partitions manually. * + * ``GENHD_FL_NO_NVMEM``: NVMEM emulation is disabled. The kernel will not + * emulate an NVMEM device on top of this disk. */ enum { GENHD_FL_REMOVABLE = 1 << 0, GENHD_FL_HIDDEN = 1 << 1, GENHD_FL_NO_PART = 1 << 2, + GENHD_FL_NO_NVMEM = 1 << 3, }; enum { From patchwork Wed Jul 19 22:03:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 122856 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2743032vqt; Wed, 19 Jul 2023 15:25:05 -0700 (PDT) X-Google-Smtp-Source: APBJJlG2saLCIgUVKvp5v7UsIFdbTSoBewa1wyODtrTkPOIwsozEprTYZAD4BQwo4B+D8ILasSE/ X-Received: by 2002:a17:906:259:b0:988:882b:9a3 with SMTP id 25-20020a170906025900b00988882b09a3mr3129369ejl.36.1689805505617; Wed, 19 Jul 2023 15:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689805505; cv=none; d=google.com; s=arc-20160816; b=KPY5qnJHg5OXimx1eLeeQ4Bzwhw/zJRL0wBH3HPS0o2vfzEdhvRfIuS2EaStSm9ODG DapJEcZEAfdQcyaOfETVwIZfG9nqr9rdUFcI/rhO50zD95SiGTMUZe8+J98tebp+bzei RZC23/46HLMe9Tr/VRwVFQLKJT68L4aDW5qVS0bPrqlpOx+q/zHpwbtamMSgcLcKdGvq rOA/8gClXRMUEm+INxKRGgbgEN0NH4DN7RpaeQwPOWbIJXI1VvPh0GjvsBm8cBO/4Y+z ABB5I6ui5dkaAaAwlUjmtWePgrfyzM6NL06yoUv183mA5/0F0qXSWuWlAEMqXnsye/48 hWMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=iEeYBEjsIBJWhzSbPPgkyfe9pv22ydHcI0JBCsLArbs=; fh=O/hjEvlM0nIN8LC6WbIQ4s0L6nmnRMOzajXXMF81As0=; b=xOMeT29E0WW8kDLpFIsGnfgcsoupngMiHOqpgvNn/e3yWIYNJo+5rChoh7KJ7CNdWe kQkbBqzWZCuK/Dqcpl72kH4h4djA2if163SnbbWImqcyJ0yMlxN/AVQAi9FAkxCaHV50 mPcexugDTIQ9dQWITzeg62B5qk7TJnbivD7GtS1kRioBKNNe4L14X1I7Ny/0ZkzUASzb 2phw/IlyHEUQnIxALb1uUFv5Axz2BNl3UKLcMK+wB1kK5eH+uVwJ1jeQ8auWqJJ72zh0 KJDk3INHdedb55GUF0vqVO+zxfY9f/ehLj/b/0EIf5l75eE9brjelRy1kW874MpolVRe GYvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r2-20020a170906350200b0098decd9e210si3093538eja.19.2023.07.19.15.24.40; Wed, 19 Jul 2023 15:25:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbjGSWEc (ORCPT + 99 others); Wed, 19 Jul 2023 18:04:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbjGSWEa (ORCPT ); Wed, 19 Jul 2023 18:04:30 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EB251FD9; Wed, 19 Jul 2023 15:04:23 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qMFGe-0008Lk-2E; Wed, 19 Jul 2023 22:03:32 +0000 Date: Wed, 19 Jul 2023 23:03:24 +0100 From: Daniel Golle To: Jens Axboe , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dave Chinner , Matthew Wilcox , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Jan Kara , Daniel Golle , Damien Le Moal , Ming Lei , Min Li , Christian Loehle , Adrian Hunter , Hannes Reinecke , Jack Wang , Florian Fainelli , Yeqi Fu , Avri Altman , Hans de Goede , Ye Bin , Greg Kroah-Hartman , =?utf-8?b?UmFmYcWCIE1pxYJl?= =?utf-8?b?Y2tp?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [RFC PATCH 4/6] mtd: blkdevs: set GENHD_FL_NO_NVMEM Message-ID: <65171d5da3daba24315ecdfef6727442baae5bbf.1689802933.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771889498188606722 X-GMAIL-MSGID: 1771889498188606722 As the MTD subsystem already acts as an NVMEM provider, emulated mtdblock devices should not be considered NVMEM providers. Signed-off-by: Daniel Golle Acked-by: Miquel Raynal --- drivers/mtd/mtd_blkdevs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index ff18636e08897..82d5afba6a25a 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -362,6 +362,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new) gd->flags |= GENHD_FL_NO_PART; } + gd->flags |= GENHD_FL_NO_NVMEM; set_capacity(gd, ((u64)new->size * tr->blksize) >> 9); /* Create the request queue */ From patchwork Wed Jul 19 22:03:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 122860 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2743821vqt; Wed, 19 Jul 2023 15:27:02 -0700 (PDT) X-Google-Smtp-Source: APBJJlFNRAbTO++YFuEIikiIH1NBUYHf2Qi3tCYos1BImYgtiyL1s7WVg+u5bkoYRgUtP7YUidMv X-Received: by 2002:aa7:d04a:0:b0:51e:3427:63ea with SMTP id n10-20020aa7d04a000000b0051e342763eamr3568384edo.8.1689805622336; Wed, 19 Jul 2023 15:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689805622; cv=none; d=google.com; s=arc-20160816; b=vkxIf+K/g4iJJl4qQtKMcWB+pmadv54lAvCTvCQiFpB155K+wle36x/DzPBr72PkD/ ElV4jBmS/I6qBjb9uF6tqxZWDCKlAL7keZtvnSqs+xBP0SgIS3tN7PHFmg7L8mA3o/XL SNefcVqSRgDN/YkG9fsvCphzwu0hsvWsD6z9gEj7loustcqzK/o6WtJ56z1B5eUX0WT/ P37Hmme4M1E1qjYtO1JLx/vqGUvjIeC+QSnsjhdiuyh1mgen40BBq2+dbBuxncn/mgaL U/rU3i0FsSKJoiXVtaQYq1Q/78FivQz8Z8mTPo+vJt/Si8xiat8xCYPveh5jqweWN92d mJdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=8T/pGdV18zCBoMdZ9g0wiioI9df4Q4Rox4Haloc5AWk=; fh=O/hjEvlM0nIN8LC6WbIQ4s0L6nmnRMOzajXXMF81As0=; b=beQsAumoFDw1Ai9tc8dt8KNzr1MZnx9+K2afOQBPjmTRl4GHd44KVNgqLrdM0/2xOl TtTa2pY/GdtV5SWPOrWu79nLNCBwvtjbI8b01qQaIDO1gzfC2cAE1v/yGnTIuXhcaoo9 AQNziOQVA1+yXpre4N58Up9+7j4PdA/7wxIirMqE9q/L4xtly9t/nykN17w/039CzNcg AnuCenYEiR6mKWtXVIPSPazG3+KWzFOzEyRl5E3Y/5RLaaeVsXA2jFyz4hQhd6QZX/pr cV1sRpbzvlwQQvCn4mK7cVEWs5r94O1URNEbvgeYwFZVeH9zjhdNKwjzSR0NdnpN9WhA 1XrA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020a50fb05000000b0051e0f20cf13si3517090edq.138.2023.07.19.15.26.38; Wed, 19 Jul 2023 15:27:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230261AbjGSWFN (ORCPT + 99 others); Wed, 19 Jul 2023 18:05:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230253AbjGSWFL (ORCPT ); Wed, 19 Jul 2023 18:05:11 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE5C22699; Wed, 19 Jul 2023 15:04:51 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qMFH4-0008NR-0M; Wed, 19 Jul 2023 22:03:58 +0000 Date: Wed, 19 Jul 2023 23:03:49 +0100 From: Daniel Golle To: Jens Axboe , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dave Chinner , Matthew Wilcox , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Jan Kara , Daniel Golle , Damien Le Moal , Ming Lei , Min Li , Christian Loehle , Adrian Hunter , Hannes Reinecke , Jack Wang , Florian Fainelli , Yeqi Fu , Avri Altman , Hans de Goede , Ye Bin , Greg Kroah-Hartman , =?utf-8?b?UmFmYcWCIE1pxYJl?= =?utf-8?b?Y2tp?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [RFC PATCH 5/6] mtd: ubi: block: set GENHD_FL_NO_NVMEM Message-ID: <077dbe0a6354edc3acded24e2552cfc3f2968903.1689802933.git.daniel@makrotopia.org> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771889620246703617 X-GMAIL-MSGID: 1771889620246703617 As the UBI volumes may already act as a NVMEM providers, emulated ubiblock devices should not be considered NVMEM providers. Signed-off-by: Daniel Golle --- drivers/mtd/ubi/block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c index 1d5148371991b..62d9461395b37 100644 --- a/drivers/mtd/ubi/block.c +++ b/drivers/mtd/ubi/block.c @@ -410,7 +410,7 @@ int ubiblock_create(struct ubi_volume_info *vi) ret = -ENODEV; goto out_cleanup_disk; } - gd->flags |= GENHD_FL_NO_PART; + gd->flags |= GENHD_FL_NO_PART | GENHD_FL_NO_NVMEM; gd->private_data = dev; sprintf(gd->disk_name, "ubiblock%d_%d", dev->ubi_num, dev->vol_id); set_capacity(gd, disk_capacity); From patchwork Wed Jul 19 22:04:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 122857 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2743228vqt; Wed, 19 Jul 2023 15:25:33 -0700 (PDT) X-Google-Smtp-Source: APBJJlFIESLxjaCj9ag1D+x2Sl3z2IuvTOu9aXEmaMIl0HCSzLnSN8+3d8+GS7Tj6MpBMILQcqlJ X-Received: by 2002:a17:907:6d91:b0:986:d833:3cf9 with SMTP id sb17-20020a1709076d9100b00986d8333cf9mr783649ejc.39.1689805532861; Wed, 19 Jul 2023 15:25:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689805532; cv=none; d=google.com; s=arc-20160816; b=tK37+GsHt8jLSB8alWbZUFUD6m16Z8F0CxFjsaVHkCvxeAtO+VobzIWkO0RUGFam34 hGZUhDlsvCxldAqFtDX4F1e+ioKz7fZImm5p2WdhbT2UP+HwgHDh/RYMumjdDYyDTf5X jUXE382yJQvjSqk/LJv+C9NeyUiwf5Sse10zZM74N97puFhiOI5/hUWxLsfoUoBN1gx7 Fq7SGMwCVzRGFGwTY3LZ1SUKj9CAk/0EAHiJpsJ+cxfPJCNG5NtkPpjkSmQgKzst+qs9 N1oOiCSLtR++C6Drf9YX8GRHZb0ammrzhRjUZHqkJhm3As8qclt3mX05IQtor4JMaxKz qFWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=wKkzr6CyH8Vbh0OeUTuqoV75O7/r+NjMY2y7LhkvTSQ=; fh=O/hjEvlM0nIN8LC6WbIQ4s0L6nmnRMOzajXXMF81As0=; b=YStXkGZQY4yQYa/BDZWs/Txq4gxTcxHpBrz8l+X2xs4SvpiZYspDZy1soNjKJZw1Rb OSJTFQ0SnDZVzmZZTqduAjqigQhN2NKUouuxNmG1/z2iPHYsIo+vz/QBNPbqJWsOiHt/ i/gha4SUZ3qCK55VrNptTHCVH9oEFLGtE5uQj1CF5d3QiLOZUjegja2r9eCTthUvEoVs 9b456fci73QMw6aUtyUs8hiKvtbTCI9MDU95uJnxj3lZhwhbbWhm3gnGB0Y55YUcPavw vDPmJUAME/SxMetUlhWvQmBQ+zVnPYfEElfHSDsV5YTGG50p1bFYJtrEkoiu9Q/6vPmH 4aoQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v13-20020a170906338d00b00982817b0858si3326466eja.364.2023.07.19.15.25.09; Wed, 19 Jul 2023 15:25:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230303AbjGSWFV (ORCPT + 99 others); Wed, 19 Jul 2023 18:05:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbjGSWFT (ORCPT ); Wed, 19 Jul 2023 18:05:19 -0400 Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65C0F210C; Wed, 19 Jul 2023 15:04:53 -0700 (PDT) Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1qMFHW-0008Ns-0m; Wed, 19 Jul 2023 22:04:26 +0000 Date: Wed, 19 Jul 2023 23:04:17 +0100 From: Daniel Golle To: Jens Axboe , Ulf Hansson , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Dave Chinner , Matthew Wilcox , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Jan Kara , Daniel Golle , Damien Le Moal , Ming Lei , Min Li , Christian Loehle , Adrian Hunter , Hannes Reinecke , Jack Wang , Florian Fainelli , Yeqi Fu , Avri Altman , Hans de Goede , Ye Bin , Greg Kroah-Hartman , =?utf-8?b?UmFmYcWCIE1pxYJl?= =?utf-8?b?Y2tp?= , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mtd@lists.infradead.org Subject: [RFC PATCH 6/6] block: implement NVMEM provider Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771889526509369766 X-GMAIL-MSGID: 1771889526509369766 On embedded devices using an eMMC it is common that one or more partitions on the eMMC are used to store MAC addresses and Wi-Fi calibration EEPROM data. Allow referencing the partition in device tree for the kernel and Wi-Fi drivers accessing it via the NVMEM layer. Signed-off-by: Daniel Golle --- block/Kconfig | 8 ++ block/Makefile | 1 + block/blk-nvmem.c | 187 ++++++++++++++++++++++++++++++++++++++++ block/blk.h | 13 +++ block/genhd.c | 2 + block/partitions/core.c | 2 + 6 files changed, 213 insertions(+) create mode 100644 block/blk-nvmem.c diff --git a/block/Kconfig b/block/Kconfig index 86122e459fe04..185573877964d 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -218,6 +218,14 @@ config BLK_MQ_VIRTIO config BLK_PM def_bool PM +config BLK_NVMEM + bool "Block device NVMEM provider" + depends on OF + help + Allow block devices (or partitions) to act as NVMEM prodivers, + typically using if an eMMC is used to store MAC addresses or Wi-Fi + calibration data on embedded devices. + # do not use in new code config BLOCK_HOLDER_DEPRECATED bool diff --git a/block/Makefile b/block/Makefile index 46ada9dc8bbfe..03c0bfa8642df 100644 --- a/block/Makefile +++ b/block/Makefile @@ -34,6 +34,7 @@ obj-$(CONFIG_BLK_DEV_ZONED) += blk-zoned.o obj-$(CONFIG_BLK_WBT) += blk-wbt.o obj-$(CONFIG_BLK_DEBUG_FS) += blk-mq-debugfs.o obj-$(CONFIG_BLK_DEBUG_FS_ZONED)+= blk-mq-debugfs-zoned.o +obj-$(CONFIG_BLK_NVMEM) += blk-nvmem.o obj-$(CONFIG_BLK_SED_OPAL) += sed-opal.o obj-$(CONFIG_BLK_PM) += blk-pm.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += blk-crypto.o blk-crypto-profile.o \ diff --git a/block/blk-nvmem.c b/block/blk-nvmem.c new file mode 100644 index 0000000000000..8238511049f56 --- /dev/null +++ b/block/blk-nvmem.c @@ -0,0 +1,187 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * block device NVMEM provider + * + * Copyright (c) 2023 Daniel Golle + * + * Useful on devices using a partition on an eMMC for MAC addresses or + * Wi-Fi calibration EEPROM data. + */ + +#include "blk.h" +#include +#include +#include +#include + +/* List of all NVMEM devices */ +static LIST_HEAD(nvmem_devices); +static DEFINE_MUTEX(devices_mutex); + +struct blk_nvmem { + struct nvmem_device *nvmem; + struct block_device *bdev; + struct list_head list; +}; + +static int blk_nvmem_reg_read(void *priv, unsigned int from, + void *val, size_t bytes) +{ + pgoff_t f_index = from >> PAGE_SHIFT; + struct address_space *mapping; + struct blk_nvmem *bnv = priv; + size_t bytes_left = bytes; + struct folio *folio; + unsigned long offs, to_read; + void *p; + + if (!bnv->bdev) + return -ENODEV; + + offs = from & ((1 << PAGE_SHIFT) - 1); + mapping = bnv->bdev->bd_inode->i_mapping; + + while (bytes_left) { + folio = read_mapping_folio(mapping, f_index++, NULL); + if (IS_ERR(folio)) + return PTR_ERR(folio); + + to_read = min_t(unsigned long, bytes_left, PAGE_SIZE - offs); + p = folio_address(folio) + offset_in_folio(folio, offs); + memcpy(val, p, to_read); + offs = 0; + bytes_left -= to_read; + val += to_read; + folio_put(folio); + } + + return bytes_left == 0 ? 0 : -EIO; +} + +void blk_register_nvmem(struct block_device *bdev) +{ + struct fwnode_handle *fw_parts = NULL, *fw_part_c, *fw_part = NULL; + struct nvmem_config config = {}; + const char *partname, *uuid; + struct device *dev, *p0dev; + struct blk_nvmem *bnv; + u32 reg; + + /* + * skip devices which set GENHD_FL_NO_NVMEM + * + * This flag is used for mtdblock and ubiblock devices because + * both, MTD and UBI already implement their own NVMEM provider. + * To avoid registering multiple NVMEM providers for the same + * device node, skip the block NVMEM provider. + */ + if (bdev->bd_disk->flags & GENHD_FL_NO_NVMEM) + return; + + /* skip too large devices */ + if (bdev_nr_bytes(bdev) > INT_MAX) + return; + + dev = &bdev->bd_device; + if (!bdev_is_partition(bdev)) { + fw_part = dev->fwnode; + + if (!fw_part && dev->parent) + fw_part = dev->parent->fwnode; + + goto no_parts; + } + + p0dev = &bdev->bd_disk->part0->bd_device; + fw_parts = device_get_named_child_node(p0dev, "partitions"); + if (!fw_parts) + fw_parts = device_get_named_child_node(p0dev->parent, "partitions"); + + if (!fw_parts) + return; + + fwnode_for_each_child_node(fw_parts, fw_part_c) { + if (!fwnode_property_read_string(fw_part_c, "uuid", &uuid) && + (!bdev->bd_meta_info || strncmp(uuid, + bdev->bd_meta_info->uuid, + PARTITION_META_INFO_UUIDLTH))) + continue; + + if (!fwnode_property_read_string(fw_part_c, "partname", &partname) && + (!bdev->bd_meta_info || strncmp(partname, + bdev->bd_meta_info->volname, + PARTITION_META_INFO_VOLNAMELTH))) + continue; + + /* + * partition addresses (reg) in device tree greater than + * DISK_MAX_PARTS can be used to match uuid or partname only + */ + if (!fwnode_property_read_u32(fw_part_c, "reg", ®) && + reg < DISK_MAX_PARTS && bdev->bd_partno != reg) + continue; + + fw_part = fw_part_c; + break; + } + +no_parts: + if (!fwnode_device_is_compatible(fw_part, "nvmem-cells")) + return; + + bnv = kzalloc(sizeof(struct blk_nvmem), GFP_KERNEL); + if (!bnv) + return; + + config.id = NVMEM_DEVID_NONE; + config.dev = &bdev->bd_device; + config.name = dev_name(&bdev->bd_device); + config.owner = THIS_MODULE; + config.priv = bnv; + config.reg_read = blk_nvmem_reg_read; + config.size = bdev_nr_bytes(bdev); + config.word_size = 1; + config.stride = 1; + config.read_only = true; + config.root_only = true; + config.ignore_wp = true; + config.of_node = to_of_node(fw_part); + + bnv->bdev = bdev; + bnv->nvmem = nvmem_register(&config); + if (IS_ERR(bnv->nvmem)) { + /* Just ignore if there is no NVMEM support in the kernel */ + if (PTR_ERR(bnv->nvmem) != -EOPNOTSUPP) + dev_err_probe(&bdev->bd_device, PTR_ERR(bnv->nvmem), + "Failed to register NVMEM device\n"); + + kfree(bnv); + return; + } + + mutex_lock(&devices_mutex); + list_add_tail(&bnv->list, &nvmem_devices); + mutex_unlock(&devices_mutex); +} + +void blk_unregister_nvmem(struct block_device *bdev) +{ + struct blk_nvmem *bnv_c, *bnv = NULL; + + mutex_lock(&devices_mutex); + list_for_each_entry(bnv_c, &nvmem_devices, list) + if (bnv_c->bdev == bdev) { + bnv = bnv_c; + break; + } + + if (!bnv) { + mutex_unlock(&devices_mutex); + return; + } + + list_del(&bnv->list); + mutex_unlock(&devices_mutex); + nvmem_unregister(bnv->nvmem); + kfree(bnv); +} diff --git a/block/blk.h b/block/blk.h index 686712e138352..7423d0d5494e9 100644 --- a/block/blk.h +++ b/block/blk.h @@ -515,4 +515,17 @@ static inline int req_ref_read(struct request *req) return atomic_read(&req->ref); } +#ifdef CONFIG_BLK_NVMEM +void blk_register_nvmem(struct block_device *bdev); +void blk_unregister_nvmem(struct block_device *bdev); +#else +static inline void blk_register_nvmem(struct block_device *bdev) +{ +} + +static inline void blk_unregister_nvmem(struct block_device *bdev) +{ +} +#endif + #endif /* BLK_INTERNAL_H */ diff --git a/block/genhd.c b/block/genhd.c index 3d287b32d50df..b306e0f407bb2 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -527,6 +527,7 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, disk_update_readahead(disk); disk_add_events(disk); set_bit(GD_ADDED, &disk->state); + blk_register_nvmem(disk->part0); return 0; out_unregister_bdi: @@ -569,6 +570,7 @@ static void blk_report_disk_dead(struct gendisk *disk) if (bdev->bd_holder_ops && bdev->bd_holder_ops->mark_dead) bdev->bd_holder_ops->mark_dead(bdev); mutex_unlock(&bdev->bd_holder_lock); + blk_unregister_nvmem(bdev); put_device(&bdev->bd_device); rcu_read_lock(); diff --git a/block/partitions/core.c b/block/partitions/core.c index 13a7341299a91..68bd655f5e68e 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -404,6 +404,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, /* suppress uevent if the disk suppresses it */ if (!dev_get_uevent_suppress(ddev)) kobject_uevent(&pdev->kobj, KOBJ_ADD); + + blk_register_nvmem(bdev); return bdev; out_del: