Skip to content

Commit

Permalink
generic: 6.6: update NVMEM-on-MMC series
Browse files Browse the repository at this point in the history
Allow a wider audience to test this pending series.

Use about to be submitted v3 which factors out block notification support.
Apart from dropping the no longer needed (and problematic) fallback for
for the 'partitions' node being present at the device parent there are
no intended functional changes.

As opening a block device as file is not supported yet in Kernel v6.6,
use the previous method as backporting seems a bit too involving.

Fixes: openwrt#15642
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
  • Loading branch information
dangowrt committed Jun 16, 2024
1 parent 4fd4be6 commit 94e0190
Show file tree
Hide file tree
Showing 12 changed files with 259 additions and 92 deletions.
3 changes: 2 additions & 1 deletion target/linux/generic/config-6.6
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
# CONFIG_BLK_DEV_UBLK is not set
# CONFIG_BLK_DEV_ZONED is not set
# CONFIG_BLK_INLINE_ENCRYPTION is not set
# CONFIG_BLK_NVMEM is not set
# CONFIG_BLOCK_NOTIFIERS is not set
# CONFIG_BLK_SED_OPAL is not set
# CONFIG_BLK_WBT is not set
CONFIG_BLOCK=y
Expand Down Expand Up @@ -4323,6 +4323,7 @@ CONFIG_NLS_DEFAULT="iso8859-1"
# CONFIG_NVIDIA_CARMEL_CNP_ERRATUM is not set
# CONFIG_NVMEM is not set
# CONFIG_NVMEM_BCM_OCOTP is not set
# CONFIG_NVMEM_BLOCK is not set
# CONFIG_NVMEM_IMX_OCOTP is not set
# CONFIG_NVMEM_LAYOUT_ONIE_TLV is not set
# CONFIG_NVMEM_LAYOUT_SL28_VPD is not set
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
From 9ffc1d7d73609a89eb264d6066340f8b7b3b0ebe Mon Sep 17 00:00:00 2001
From 3245921a87154bdfbe7a55d743ea62dd559a8fb0 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Mon, 7 Aug 2023 21:19:45 +0100
Subject: [PATCH 08/15] dt-bindings: block: add basic bindings for block
devices
Date: Thu, 30 May 2024 03:13:09 +0100
Subject: [PATCH 1/9] dt-bindings: block: add basic bindings for block devices

Add bindings for block devices which are used to allow referencing
nvmem bits on them.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
.../bindings/block/block-device.yaml | 22 ++++++++
.../devicetree/bindings/block/partition.yaml | 50 +++++++++++++++++++
.../devicetree/bindings/block/partition.yaml | 51 +++++++++++++++++++
.../devicetree/bindings/block/partitions.yaml | 20 ++++++++
3 files changed, 92 insertions(+)
3 files changed, 93 insertions(+)
create mode 100644 Documentation/devicetree/bindings/block/block-device.yaml
create mode 100644 Documentation/devicetree/bindings/block/partition.yaml
create mode 100644 Documentation/devicetree/bindings/block/partitions.yaml
Expand Down Expand Up @@ -44,7 +43,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+unevaluatedProperties: false
--- /dev/null
+++ b/Documentation/devicetree/bindings/block/partition.yaml
@@ -0,0 +1,50 @@
@@ -0,0 +1,51 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
Expand All @@ -66,16 +65,17 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+ pattern: '^block-partition-.+$'
+
+ partnum:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ description:
+ Matches partition by number if present.
+
+ partname:
+ "$ref": "/schemas/types.yaml#/definitions/string"
+ $ref: /schemas/types.yaml#/definitions/string
+ description:
+ Matches partition by PARTNAME if present.
+
+ uuid:
+ "$ref": "/schemas/types.yaml#/definitions/string"
+ partuuid:
+ $ref: /schemas/types.yaml#/definitions/string
+ description:
+ Matches partition by PARTUUID if present.
+
Expand All @@ -86,13 +86,13 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+
+anyOf:
+ - required:
+ - partnum
+ - partnum
+
+ - required:
+ - partname
+ - partname
+
+ - required:
+ - uuid
+ - partuuid
+
+unevaluatedProperties: false
--- /dev/null
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 614f4f6fdda09e30ecf7ef6c8091579db15018cb Mon Sep 17 00:00:00 2001
From 7f4c9c534aabe1315669e076d3fe0af0fd374cda Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Fri, 21 Jul 2023 17:51:03 +0100
Subject: [PATCH 09/15] block: partitions: populate fwnode
Date: Thu, 30 May 2024 03:13:19 +0100
Subject: [PATCH 2/9] block: partitions: populate fwnode

Let block partitions to be represented by a firmware node and hence
allow them to being referenced e.g. for use with blk-nvmem.
Expand All @@ -22,7 +22,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
#include "check.h"

static int (*const check_part[])(struct parsed_partitions *) = {
@@ -292,6 +294,43 @@ static ssize_t whole_disk_show(struct de
@@ -292,6 +294,40 @@ static ssize_t whole_disk_show(struct de
}
static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);

Expand All @@ -35,9 +35,6 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
+
+ fw_parts = device_get_named_child_node(ddev, "partitions");
+ if (!fw_parts)
+ fw_parts = device_get_named_child_node(ddev->parent, "partitions");
+
+ if (!fw_parts)
+ return NULL;
+
+ fwnode_for_each_child_node(fw_parts, fw_part) {
Expand Down Expand Up @@ -66,7 +63,7 @@ Signed-off-by: Daniel Golle <daniel@makrotopia.org>
/*
* Must be called either with open_mutex held, before a disk can be opened or
* after all disk users are gone.
@@ -374,6 +413,8 @@ static struct block_device *add_partitio
@@ -374,6 +410,8 @@ static struct block_device *add_partitio
goto out_put;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
From e07ace307ce598847074a096f408bec0e3a392ed Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Thu, 30 May 2024 03:14:34 +0100
Subject: [PATCH 3/9] block: add support for notifications

Add notifier block to notify other subsystems about the addition or
removal of block devices.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
block/Kconfig | 6 +++
block/Makefile | 1 +
block/blk-notify.c | 88 ++++++++++++++++++++++++++++++++++++++++++
include/linux/blkdev.h | 8 ++++
4 files changed, 103 insertions(+)
create mode 100644 block/blk-notify.c

--- a/block/Kconfig
+++ b/block/Kconfig
@@ -208,6 +208,12 @@ config BLK_INLINE_ENCRYPTION_FALLBACK
by falling back to the kernel crypto API when inline
encryption hardware is not present.

+config BLOCK_NOTIFIERS
+ bool "Enable support for notifications in block layer"
+ help
+ Enable this option to provide notifiers for other subsystems
+ upon addition or removal of block devices.
+
source "block/partitions/Kconfig"

config BLK_MQ_PCI
--- a/block/Makefile
+++ b/block/Makefile
@@ -40,3 +40,4 @@ obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += b
blk-crypto-sysfs.o
obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o
obj-$(CONFIG_BLOCK_HOLDER_DEPRECATED) += holder.o
+obj-$(CONFIG_BLOCK_NOTIFIERS) += blk-notify.o
--- /dev/null
+++ b/block/blk-notify.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Notifiers for addition and removal of block devices
+ *
+ * Copyright (c) 2024 Daniel Golle <daniel@makrotopia.org>
+ */
+
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/notifier.h>
+
+#include "blk.h"
+
+struct blk_device_list {
+ struct device *dev;
+ struct list_head list;
+};
+
+static RAW_NOTIFIER_HEAD(blk_notifier_list);
+static DEFINE_MUTEX(blk_notifier_lock);
+static LIST_HEAD(blk_devices);
+
+void blk_register_notify(struct notifier_block *nb)
+{
+ struct blk_device_list *existing_blkdev;
+
+ mutex_lock(&blk_notifier_lock);
+ raw_notifier_chain_register(&blk_notifier_list, nb);
+
+ list_for_each_entry(existing_blkdev, &blk_devices, list)
+ nb->notifier_call(nb, BLK_DEVICE_ADD, existing_blkdev->dev);
+
+ mutex_unlock(&blk_notifier_lock);
+}
+EXPORT_SYMBOL_GPL(blk_register_notify);
+
+void blk_unregister_notify(struct notifier_block *nb)
+{
+ mutex_lock(&blk_notifier_lock);
+ raw_notifier_chain_unregister(&blk_notifier_list, nb);
+ mutex_unlock(&blk_notifier_lock);
+}
+EXPORT_SYMBOL_GPL(blk_unregister_notify);
+
+static int blk_call_notifier_add(struct device *dev)
+{
+ struct blk_device_list *new_blkdev;
+
+ new_blkdev = kmalloc(sizeof(*new_blkdev), GFP_KERNEL);
+ if (!new_blkdev)
+ return -ENOMEM;
+
+ new_blkdev->dev = dev;
+ mutex_lock(&blk_notifier_lock);
+ list_add_tail(&new_blkdev->list, &blk_devices);
+ raw_notifier_call_chain(&blk_notifier_list, BLK_DEVICE_ADD, dev);
+ mutex_unlock(&blk_notifier_lock);
+
+ return 0;
+}
+
+static void blk_call_notifier_remove(struct device *dev)
+{
+ struct blk_device_list *old_blkdev, *tmp;
+
+ mutex_lock(&blk_notifier_lock);
+ list_for_each_entry_safe(old_blkdev, tmp, &blk_devices, list) {
+ if (old_blkdev->dev != dev)
+ continue;
+
+ list_del(&old_blkdev->list);
+ kfree(old_blkdev);
+ }
+ raw_notifier_call_chain(&blk_notifier_list, BLK_DEVICE_REMOVE, dev);
+ mutex_unlock(&blk_notifier_lock);
+}
+
+static struct class_interface blk_notifications_bus_interface __refdata = {
+ .class = &block_class,
+ .add_dev = &blk_call_notifier_add,
+ .remove_dev = &blk_call_notifier_remove,
+};
+
+static int __init blk_notifications_init(void)
+{
+ return class_interface_register(&blk_notifications_bus_interface);
+}
+device_initcall(blk_notifications_init);
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -1564,4 +1564,12 @@ struct io_comp_batch {

#define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { }

+
+#ifdef CONFIG_BLOCK_NOTIFIERS
+#define BLK_DEVICE_ADD 1
+#define BLK_DEVICE_REMOVE 2
+void blk_register_notify(struct notifier_block *nb);
+void blk_unregister_notify(struct notifier_block *nb);
+#endif
+
#endif /* _LINUX_BLKDEV_H */
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 65f3ff9672ccd5ee78937047e7a2fc696eee1c8f Mon Sep 17 00:00:00 2001
From f4487fa1cb7e55b3c17a33f41b9c9d66f4f853b7 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Thu, 13 Jul 2023 04:07:16 +0100
Subject: [PATCH 10/15] block: add new genhd flag GENHD_FL_NVMEM
Date: Thu, 30 May 2024 03:14:49 +0100
Subject: [PATCH 4/9] block: add new genhd flag GENHD_FL_NVMEM

Add new flag to destinguish block devices which may act as an NVMEM
provider.
Expand Down
Loading

0 comments on commit 94e0190

Please sign in to comment.