Message ID | db30127ab4741d4e71b768881197f4791174f545.1666786471.git.matthias.schiffer@ew.tq-group.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp263175wru; Wed, 26 Oct 2022 06:19:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7FdkxZzGN9GiIzLciR7enHi4H8pQvVTIXLyj2Tggghqur/mDba6rr8BkRgPmls4QRTKyz8 X-Received: by 2002:a63:1e56:0:b0:462:970:e0de with SMTP id p22-20020a631e56000000b004620970e0demr2817959pgm.90.1666790373565; Wed, 26 Oct 2022 06:19:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666790373; cv=none; d=google.com; s=arc-20160816; b=bH5b3NrDAvYycLNToupSqlXbhx3QWsxthhmAEg5x8ckY/M2od26xOu0mQCEElm4XTB 6JIy+lJi0ei4AouiNRfH3kpiJHjlKW0ax/JUKAsI0d0sa/j3Rq6RXcLQ+r+DObbk4ilX hv9n7/rLvMqX3PePm2C4jAxaDCHisoECkGKwNknqG35bdOfGh+WJ2K7LhlEbeAL9SaRW EYB/6ZcUhbcx2Z9ZSh6tZCzFHeNZY2PTClWztCyEnAaNl33qe4bGrfHq6wLO9jXwax7R PFj+DBoNawXtKmE0byRoaIEGq2Bzgetxkdjy4/bR5rPhytuJtuzi9dJOOuDbBFiVoDS3 1GKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:dkim-signature; bh=rmV74reOQIhMVx3wfFt0WNHhPTZ+EE2t0X4nueZsE3E=; b=ky0Vii2cD/DTEzANoQsnHlfMb6QiHOepy+9Dn0B8mfGVnG8s+VriPq0B/19q8nwXde fItf8GVbjy5W6h1IrXvWCVatAlTQY0Bl3gq/ds5dD3eJ+vgUmozAFCLqcOsKg7d4IdLC GQkBIg7L1HMoWwJa260LJePcu42Xz6YvNdPxVEQSiEu+oPr1TXHik61p6s6WzvsEFqFJ bXMmrSuZfyeaRCpcoMGkmJWqRzBOEweVUlBCJfGtT0wZnaCme1wWSnvLU/PKcfK0XL6Q Jcha7DSu1YovA525h23WD8iPuwWOnjSrgjE3Wv9oPqKj7bA9XFzs3QSYiQQ3jx+SqH34 gfCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tq-group.com header.s=key1 header.b="lwV9B2/G"; dkim=pass header.i=@tq-group.com header.s=key1 header.b=FXDp8xAA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n18-20020a170902d2d200b0017cca111726si7855278plc.432.2022.10.26.06.19.18; Wed, 26 Oct 2022 06:19:33 -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; dkim=pass header.i=@tq-group.com header.s=key1 header.b="lwV9B2/G"; dkim=pass header.i=@tq-group.com header.s=key1 header.b=FXDp8xAA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=tq-group.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233153AbiJZNQs (ORCPT <rfc822;pwkd43@gmail.com> + 99 others); Wed, 26 Oct 2022 09:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234034AbiJZNQh (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 26 Oct 2022 09:16:37 -0400 Received: from mx1.tq-group.com (mx1.tq-group.com [93.104.207.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 548118306F; Wed, 26 Oct 2022 06:16:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1666790196; x=1698326196; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rmV74reOQIhMVx3wfFt0WNHhPTZ+EE2t0X4nueZsE3E=; b=lwV9B2/GGH8BD3LR4e9svhvvx7RNQizqm6gj1u8lWwh2uS3mbd2h7m77 fFIeenw0jw/sk36Jn7aB0/3WrSp0hL8FXfH2ZmWULWIKn+xthB/wfu0o+ ZBsxG0dMlFqe2vKriIiEh9HpznGjM3EH8yUW1KIryzddTvbzCcTwpW7MJ NF7GBKeuu/1t0Cinlw6WPO1PYp5Jvbv9lpEOZkAP0uBqIMbpc0lL3Rk4I dZlsGK1d153gvSVyeNXgRCb1NPTwDbtBfJtG0cofHZfv5BNuWtn0A0PW5 f7weVBgDd80tPnUa8YQLJgSzJCqUt9KtMF+Wg70X6SeXKVXrXJCCscCTv A==; X-IronPort-AV: E=Sophos;i="5.95,214,1661810400"; d="scan'208";a="26988469" Received: from unknown (HELO tq-pgp-pr1.tq-net.de) ([192.168.6.15]) by mx1-pgp.tq-group.com with ESMTP; 26 Oct 2022 15:16:31 +0200 Received: from mx1.tq-group.com ([192.168.6.7]) by tq-pgp-pr1.tq-net.de (PGP Universal service); Wed, 26 Oct 2022 15:16:31 +0200 X-PGP-Universal: processed; by tq-pgp-pr1.tq-net.de on Wed, 26 Oct 2022 15:16:31 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tq-group.com; i=@tq-group.com; q=dns/txt; s=key1; t=1666790191; x=1698326191; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=rmV74reOQIhMVx3wfFt0WNHhPTZ+EE2t0X4nueZsE3E=; b=FXDp8xAAIqGd6/RL9y8KrOnNq0i/vgBaqMYdKGbnkXh0qoMQa68LPoQ3 5JBbE5FQHNkEgB0edF+VAwEUnlpvFXIynS+aBvLjzFu9ClGKITol5aLab Ndh6731IPrB2/3d+OG5sVUbsWvU1m+RVoRpmf0Te2jM0r7qI/AbPip9n6 vIT5zrl4QaS8x9eUdclxXUnA52znNWj8c64Y1PODYEuhDJQbzJxOyxBEb sfl/JUUIDDL5qJ9wr+Wo2UCO8p3YPG5kx2eclsonv9VPs9hEOMxZnvT44 CD2caRrZVFM8riiFR/i0e115nWeWRJjm7jJyc6udD37yC8gx/F7vDMAyU g==; X-IronPort-AV: E=Sophos;i="5.95,214,1661810400"; d="scan'208";a="26988468" Received: from vtuxmail01.tq-net.de ([10.115.0.20]) by mx1.tq-group.com with ESMTP; 26 Oct 2022 15:16:31 +0200 Received: from localhost.localdomain (SCHIFFERM-M2.tq-net.de [10.121.49.14]) by vtuxmail01.tq-net.de (Postfix) with ESMTPA id 21BFC280072; Wed, 26 Oct 2022 15:16:30 +0200 (CEST) From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> To: Arnd Bergmann <arnd@arndb.de>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org> Cc: Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, Luiz Augusto von Dentz <luiz.dentz@gmail.com>, Amitkumar Karwar <amitkarwar@gmail.com>, Ganapathi Bhat <ganapathi017@gmail.com>, Sharvari Harisangam <sharvari.harisangam@nxp.com>, Xinming Hu <huxinming820@gmail.com>, Kalle Valo <kvalo@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux@ew.tq-group.com, Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Subject: [RFC 1/5] misc: introduce notify-device driver Date: Wed, 26 Oct 2022 15:15:30 +0200 Message-Id: <db30127ab4741d4e71b768881197f4791174f545.1666786471.git.matthias.schiffer@ew.tq-group.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <cover.1666786471.git.matthias.schiffer@ew.tq-group.com> References: <cover.1666786471.git.matthias.schiffer@ew.tq-group.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747756382570906229?= X-GMAIL-MSGID: =?utf-8?q?1747756382570906229?= |
Series |
"notify-device" for cross-driver readiness notification
|
|
Commit Message
Matthias Schiffer
Oct. 26, 2022, 1:15 p.m. UTC
A notify-device is a synchronization facility that allows to query
"readiness" across drivers, without creating a direct dependency between
the driver modules. The notify-device can also be used to trigger deferred
probes.
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
---
drivers/misc/Kconfig | 4 ++
drivers/misc/Makefile | 1 +
drivers/misc/notify-device.c | 109 ++++++++++++++++++++++++++++++++++
include/linux/notify-device.h | 33 ++++++++++
4 files changed, 147 insertions(+)
create mode 100644 drivers/misc/notify-device.c
create mode 100644 include/linux/notify-device.h
Comments
On Wed, Oct 26, 2022 at 03:15:30PM +0200, Matthias Schiffer wrote: > A notify-device is a synchronization facility that allows to query > "readiness" across drivers, without creating a direct dependency between > the driver modules. The notify-device can also be used to trigger deferred > probes. > > Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> > --- > drivers/misc/Kconfig | 4 ++ > drivers/misc/Makefile | 1 + > drivers/misc/notify-device.c | 109 ++++++++++++++++++++++++++++++++++ > include/linux/notify-device.h | 33 ++++++++++ > 4 files changed, 147 insertions(+) > create mode 100644 drivers/misc/notify-device.c > create mode 100644 include/linux/notify-device.h > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > index 358ad56f6524..63559e9f854c 100644 > --- a/drivers/misc/Kconfig > +++ b/drivers/misc/Kconfig > @@ -496,6 +496,10 @@ config VCPU_STALL_DETECTOR > > If you do not intend to run this kernel as a guest, say N. > > +config NOTIFY_DEVICE > + tristate "Notify device" > + depends on OF > + > source "drivers/misc/c2port/Kconfig" > source "drivers/misc/eeprom/Kconfig" > source "drivers/misc/cb710/Kconfig" > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > index ac9b3e757ba1..1e8012112b43 100644 > --- a/drivers/misc/Makefile > +++ b/drivers/misc/Makefile > @@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o > obj-$(CONFIG_OPEN_DICE) += open-dice.o > obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ > obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o > +obj-$(CONFIG_NOTIFY_DEVICE) += notify-device.o > diff --git a/drivers/misc/notify-device.c b/drivers/misc/notify-device.c > new file mode 100644 > index 000000000000..42e0980394ea > --- /dev/null > +++ b/drivers/misc/notify-device.c > @@ -0,0 +1,109 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > + > +#include <linux/device/class.h> > +#include <linux/kernel.h> > +#include <linux/module.h> > +#include <linux/notify-device.h> > +#include <linux/platform_device.h> > +#include <linux/slab.h> > + > +static void notify_device_release(struct device *dev) > +{ > + of_node_put(dev->of_node); > + kfree(dev); > +} > + > +static struct class notify_device_class = { > + .name = "notify-device", > + .owner = THIS_MODULE, > + .dev_release = notify_device_release, > +}; > + > +static struct platform_driver notify_device_driver = { Ick, wait, this is NOT a platform device, nor driver, so it shouldn't be either here. Worst case, it's a virtual device on the virtual bus. But why is this a class at all? Classes are a representation of a type of device that userspace can see, how is this anything that userspace cares about? Doesn't the device link stuff handle all of this type of "when this device is done being probed, now I can" problems? Why is a whole new thing needed? thanks, greg k-h
On Wed, 2022-10-26 at 16:37 +0200, Greg Kroah-Hartman wrote: > On Wed, Oct 26, 2022 at 03:15:30PM +0200, Matthias Schiffer wrote: > > A notify-device is a synchronization facility that allows to query > > "readiness" across drivers, without creating a direct dependency between > > the driver modules. The notify-device can also be used to trigger deferred > > probes. > > > > Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> > > --- > > drivers/misc/Kconfig | 4 ++ > > drivers/misc/Makefile | 1 + > > drivers/misc/notify-device.c | 109 ++++++++++++++++++++++++++++++++++ > > include/linux/notify-device.h | 33 ++++++++++ > > 4 files changed, 147 insertions(+) > > create mode 100644 drivers/misc/notify-device.c > > create mode 100644 include/linux/notify-device.h > > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > > index 358ad56f6524..63559e9f854c 100644 > > --- a/drivers/misc/Kconfig > > +++ b/drivers/misc/Kconfig > > @@ -496,6 +496,10 @@ config VCPU_STALL_DETECTOR > > > > If you do not intend to run this kernel as a guest, say N. > > > > +config NOTIFY_DEVICE > > + tristate "Notify device" > > + depends on OF > > + > > source "drivers/misc/c2port/Kconfig" > > source "drivers/misc/eeprom/Kconfig" > > source "drivers/misc/cb710/Kconfig" > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > > index ac9b3e757ba1..1e8012112b43 100644 > > --- a/drivers/misc/Makefile > > +++ b/drivers/misc/Makefile > > @@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o > > obj-$(CONFIG_OPEN_DICE) += open-dice.o > > obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ > > obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o > > +obj-$(CONFIG_NOTIFY_DEVICE) += notify-device.o > > diff --git a/drivers/misc/notify-device.c b/drivers/misc/notify-device.c > > new file mode 100644 > > index 000000000000..42e0980394ea > > --- /dev/null > > +++ b/drivers/misc/notify-device.c > > @@ -0,0 +1,109 @@ > > +// SPDX-License-Identifier: GPL-2.0-or-later > > + > > +#include <linux/device/class.h> > > +#include <linux/kernel.h> > > +#include <linux/module.h> > > +#include <linux/notify-device.h> > > +#include <linux/platform_device.h> > > +#include <linux/slab.h> > > + > > +static void notify_device_release(struct device *dev) > > +{ > > + of_node_put(dev->of_node); > > + kfree(dev); > > +} > > + > > +static struct class notify_device_class = { > > + .name = "notify-device", > > + .owner = THIS_MODULE, > > + .dev_release = notify_device_release, > > +}; > > + > > +static struct platform_driver notify_device_driver = { [Pruning the CC list a bit, to avoid clogging people's inboxes] > > Ick, wait, this is NOT a platform device, nor driver, so it shouldn't be > either here. Worst case, it's a virtual device on the virtual bus. This part of the code is inspired by mac80211_hwsim, which uses a platform driver in a similar way, for a plain struct device. Should this rather use a plain struct device_driver? Also, what's the virtual bus? Grepping the Linux code and documentation didn't turn up anything. > > But why is this a class at all? Classes are a representation of a type > of device that userspace can see, how is this anything that userspace > cares about? Makes sense, I will remove the class. > > Doesn't the device link stuff handle all of this type of "when this > device is done being probed, now I can" problems? Why is a whole new > thing needed? The issue here is that (as I understand it) the device link and deferred probing infrastructore only cares about whether the supplier device has been probed successfully. This is insuffient in the case of the dependency between mwifiex and hci_uart/hci_mrvl that I want to express: mwifiex loads its firmware asynchronously, so finishing the mwifiex probe is too early to retry probing the Bluetooth driver. While mwifiex does create a few devices (ieee80211, netdevice) when the firmware has loaded, none of these bind to a driver, so they don't trigger the deferred probes. Using their existence as a condition for allowing the Bluetooth driver to probe also seems ugly too me (ieee80211 currently can't be looked up by OF node, and netdevices can be created and deleted dynamically). Because of this, I came to the conclusion that creating and binding a device specifically for this purpose is a good solution, as it solves two problems at once: - The driver bind triggers deferred probes - The driver allows to look up the device by OF node Integrating this with device links might make sense as well, but I haven't looked much into that yet. Thanks, Matthias > > thanks, > > greg k-h
On Thu, Oct 27, 2022 at 06:33:33PM +0200, Matthias Schiffer wrote: > On Wed, 2022-10-26 at 16:37 +0200, Greg Kroah-Hartman wrote: > > On Wed, Oct 26, 2022 at 03:15:30PM +0200, Matthias Schiffer wrote: > > > A notify-device is a synchronization facility that allows to query > > > "readiness" across drivers, without creating a direct dependency between > > > the driver modules. The notify-device can also be used to trigger deferred > > > probes. > > > > > > Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> > > > --- > > > drivers/misc/Kconfig | 4 ++ > > > drivers/misc/Makefile | 1 + > > > drivers/misc/notify-device.c | 109 ++++++++++++++++++++++++++++++++++ > > > include/linux/notify-device.h | 33 ++++++++++ > > > 4 files changed, 147 insertions(+) > > > create mode 100644 drivers/misc/notify-device.c > > > create mode 100644 include/linux/notify-device.h > > > > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > > > index 358ad56f6524..63559e9f854c 100644 > > > --- a/drivers/misc/Kconfig > > > +++ b/drivers/misc/Kconfig > > > @@ -496,6 +496,10 @@ config VCPU_STALL_DETECTOR > > > > > > If you do not intend to run this kernel as a guest, say N. > > > > > > +config NOTIFY_DEVICE > > > + tristate "Notify device" > > > + depends on OF > > > + > > > source "drivers/misc/c2port/Kconfig" > > > source "drivers/misc/eeprom/Kconfig" > > > source "drivers/misc/cb710/Kconfig" > > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > > > index ac9b3e757ba1..1e8012112b43 100644 > > > --- a/drivers/misc/Makefile > > > +++ b/drivers/misc/Makefile > > > @@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o > > > obj-$(CONFIG_OPEN_DICE) += open-dice.o > > > obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ > > > obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o > > > +obj-$(CONFIG_NOTIFY_DEVICE) += notify-device.o > > > diff --git a/drivers/misc/notify-device.c b/drivers/misc/notify-device.c > > > new file mode 100644 > > > index 000000000000..42e0980394ea > > > --- /dev/null > > > +++ b/drivers/misc/notify-device.c > > > @@ -0,0 +1,109 @@ > > > +// SPDX-License-Identifier: GPL-2.0-or-later > > > + > > > +#include <linux/device/class.h> > > > +#include <linux/kernel.h> > > > +#include <linux/module.h> > > > +#include <linux/notify-device.h> > > > +#include <linux/platform_device.h> > > > +#include <linux/slab.h> > > > + > > > +static void notify_device_release(struct device *dev) > > > +{ > > > + of_node_put(dev->of_node); > > > + kfree(dev); > > > +} > > > + > > > +static struct class notify_device_class = { > > > + .name = "notify-device", > > > + .owner = THIS_MODULE, > > > + .dev_release = notify_device_release, > > > +}; > > > + > > > +static struct platform_driver notify_device_driver = { > > [Pruning the CC list a bit, to avoid clogging people's inboxes] > > > > > Ick, wait, this is NOT a platform device, nor driver, so it shouldn't be > > either here. Worst case, it's a virtual device on the virtual bus. > > This part of the code is inspired by mac80211_hwsim, which uses a > platform driver in a similar way, for a plain struct device. Should > this rather use a plain struct device_driver? It should NOT be using a platform device. Again, a platform device should NEVER be used as a child of a device in the tree that is on a discoverable bus. Use the aux bus code if you don't want to create virtual devices with no real bus, that is what it is there for. > Also, what's the virtual bus? Grepping the Linux code and documentation > didn't turn up anything. Look at the stuff that ends up in /sys/devices/virtual/ Lots of users there. > > But why is this a class at all? Classes are a representation of a type > > of device that userspace can see, how is this anything that userspace > > cares about? > > Makes sense, I will remove the class. > > > > > Doesn't the device link stuff handle all of this type of "when this > > device is done being probed, now I can" problems? Why is a whole new > > thing needed? > > The issue here is that (as I understand it) the device link and > deferred probing infrastructore only cares about whether the supplier > device has been probed successfully. > > This is insuffient in the case of the dependency between mwifiex and > hci_uart/hci_mrvl that I want to express: mwifiex loads its firmware > asynchronously, so finishing the mwifiex probe is too early to retry > probing the Bluetooth driver. Welcome to deferred probing hell :) > While mwifiex does create a few devices (ieee80211, netdevice) when the > firmware has loaded, none of these bind to a driver, so they don't > trigger the deferred probes. Using their existence as a condition for > allowing the Bluetooth driver to probe also seems ugly too me > (ieee80211 currently can't be looked up by OF node, and netdevices can > be created and deleted dynamically). > > Because of this, I came to the conclusion that creating and binding a > device specifically for this purpose is a good solution, as it solves > two problems at once: > - The driver bind triggers deferred probes > - The driver allows to look up the device by OF node > > Integrating this with device links might make sense as well, but I > haven't looked much into that yet. Try looking at device links, I think this fits exactly what that solves. If not, please figure out why. thanks, greg k-h
On Thu, 2022-10-27 at 18:48 +0200, Greg Kroah-Hartman wrote: > On Thu, Oct 27, 2022 at 06:33:33PM +0200, Matthias Schiffer wrote: > > On Wed, 2022-10-26 at 16:37 +0200, Greg Kroah-Hartman wrote: > > > On Wed, Oct 26, 2022 at 03:15:30PM +0200, Matthias Schiffer wrote: > > > > A notify-device is a synchronization facility that allows to query > > > > "readiness" across drivers, without creating a direct dependency between > > > > the driver modules. The notify-device can also be used to trigger deferred > > > > probes. > > > > > > > > Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> > > > > --- > > > > drivers/misc/Kconfig | 4 ++ > > > > drivers/misc/Makefile | 1 + > > > > drivers/misc/notify-device.c | 109 ++++++++++++++++++++++++++++++++++ > > > > include/linux/notify-device.h | 33 ++++++++++ > > > > 4 files changed, 147 insertions(+) > > > > create mode 100644 drivers/misc/notify-device.c > > > > create mode 100644 include/linux/notify-device.h > > > > > > > > diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig > > > > index 358ad56f6524..63559e9f854c 100644 > > > > --- a/drivers/misc/Kconfig > > > > +++ b/drivers/misc/Kconfig > > > > @@ -496,6 +496,10 @@ config VCPU_STALL_DETECTOR > > > > > > > > If you do not intend to run this kernel as a guest, say N. > > > > > > > > +config NOTIFY_DEVICE > > > > + tristate "Notify device" > > > > + depends on OF > > > > + > > > > source "drivers/misc/c2port/Kconfig" > > > > source "drivers/misc/eeprom/Kconfig" > > > > source "drivers/misc/cb710/Kconfig" > > > > diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile > > > > index ac9b3e757ba1..1e8012112b43 100644 > > > > --- a/drivers/misc/Makefile > > > > +++ b/drivers/misc/Makefile > > > > @@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o > > > > obj-$(CONFIG_OPEN_DICE) += open-dice.o > > > > obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ > > > > obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o > > > > +obj-$(CONFIG_NOTIFY_DEVICE) += notify-device.o > > > > diff --git a/drivers/misc/notify-device.c b/drivers/misc/notify-device.c > > > > new file mode 100644 > > > > index 000000000000..42e0980394ea > > > > --- /dev/null > > > > +++ b/drivers/misc/notify-device.c > > > > @@ -0,0 +1,109 @@ > > > > +// SPDX-License-Identifier: GPL-2.0-or-later > > > > + > > > > +#include <linux/device/class.h> > > > > +#include <linux/kernel.h> > > > > +#include <linux/module.h> > > > > +#include <linux/notify-device.h> > > > > +#include <linux/platform_device.h> > > > > +#include <linux/slab.h> > > > > + > > > > +static void notify_device_release(struct device *dev) > > > > +{ > > > > + of_node_put(dev->of_node); > > > > + kfree(dev); > > > > +} > > > > + > > > > +static struct class notify_device_class = { > > > > + .name = "notify-device", > > > > + .owner = THIS_MODULE, > > > > + .dev_release = notify_device_release, > > > > +}; > > > > + > +static struct platform_driver notify_device_driver = { > > > > [Pruning the CC list a bit, to avoid clogging people's inboxes] > > > > > Ick, wait, this is NOT a platform device, nor driver, so it shouldn't be > > > either here. Worst case, it's a virtual device on the virtual bus. > > > > This part of the code is inspired by mac80211_hwsim, which uses a > > platform driver in a similar way, for a plain struct device. Should > > this rather use a plain struct device_driver? > > It should NOT be using a platform device. > > Again, a platform device should NEVER be used as a child of a device in > the tree that is on a discoverable bus. > > Use the aux bus code if you don't want to create virtual devices with no > real bus, that is what it is there for. Thanks, the auxiliary bus seems to be what I'm looking for. > > > Also, what's the virtual bus? Grepping the Linux code and documentation > > didn't turn up anything. > > Look at the stuff that ends up in /sys/devices/virtual/ Lots of users > there. > > > > But why is this a class at all? Classes are a representation of a type > > > of device that userspace can see, how is this anything that userspace > > > cares about? > > > > Makes sense, I will remove the class. > > > > > Doesn't the device link stuff handle all of this type of "when this > > > device is done being probed, now I can" problems? Why is a whole new > > > thing needed? > > > > The issue here is that (as I understand it) the device link and > > deferred probing infrastructore only cares about whether the supplier > > device has been probed successfully. > > > > This is insuffient in the case of the dependency between mwifiex and > > hci_uart/hci_mrvl that I want to express: mwifiex loads its firmware > > asynchronously, so finishing the mwifiex probe is too early to retry > > probing the Bluetooth driver. > > Welcome to deferred probing hell :) > > > While mwifiex does create a few devices (ieee80211, netdevice) when the > > firmware has loaded, none of these bind to a driver, so they don't > > trigger the deferred probes. Using their existence as a condition for > > allowing the Bluetooth driver to probe also seems ugly too me > > (ieee80211 currently can't be looked up by OF node, and netdevices can > > be created and deleted dynamically). > > > > Because of this, I came to the conclusion that creating and binding a > > device specifically for this purpose is a good solution, as it solves > > two problems at once: > > - The driver bind triggers deferred probes > > - The driver allows to look up the device by OF node > > > > Integrating this with device links might make sense as well, but I > > haven't looked much into that yet. > > Try looking at device links, I think this fits exactly what that solves. > If not, please figure out why. According to [1], what triggers device link state changes is the binding of drivers. As mentioned, this doesn't help in the mwifiex case: The mwifiex probe does not wait for the firmware to load, as the probe would otherwise take too long (see [2]). So unless we want to extend the device link facility with a manual mode where the supplier explicitly sets the link to a "ready" state, we still need to extend mwifiex with a child device to attach the link to, triggering the state change by binding it to a driver at the right moment. Which is what this patch implements in a generic way (just without device links so far). Thanks, Matthias [1] https://www.kernel.org/doc/html/latest/driver-api/device_link.html#state-machine [2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=59a4cc2539076f868f2a3fcd7a3385a26928a27a
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index 358ad56f6524..63559e9f854c 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -496,6 +496,10 @@ config VCPU_STALL_DETECTOR If you do not intend to run this kernel as a guest, say N. +config NOTIFY_DEVICE + tristate "Notify device" + depends on OF + source "drivers/misc/c2port/Kconfig" source "drivers/misc/eeprom/Kconfig" source "drivers/misc/cb710/Kconfig" diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index ac9b3e757ba1..1e8012112b43 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -62,3 +62,4 @@ obj-$(CONFIG_HI6421V600_IRQ) += hi6421v600-irq.o obj-$(CONFIG_OPEN_DICE) += open-dice.o obj-$(CONFIG_GP_PCI1XXXX) += mchp_pci1xxxx/ obj-$(CONFIG_VCPU_STALL_DETECTOR) += vcpu_stall_detector.o +obj-$(CONFIG_NOTIFY_DEVICE) += notify-device.o diff --git a/drivers/misc/notify-device.c b/drivers/misc/notify-device.c new file mode 100644 index 000000000000..42e0980394ea --- /dev/null +++ b/drivers/misc/notify-device.c @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <linux/device/class.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/notify-device.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +static void notify_device_release(struct device *dev) +{ + of_node_put(dev->of_node); + kfree(dev); +} + +static struct class notify_device_class = { + .name = "notify-device", + .owner = THIS_MODULE, + .dev_release = notify_device_release, +}; + +static struct platform_driver notify_device_driver = { + .driver = { + .name = "notify-device", + }, +}; + +struct device *notify_device_create(struct device *parent, const char *child) +{ + struct device_node *node; + struct device *dev; + int err; + + if (!parent->of_node) + return ERR_PTR(-EINVAL); + + node = of_get_child_by_name(parent->of_node, child); + if (!node) + return NULL; + + dev = kzalloc(sizeof(*dev), GFP_KERNEL); + if (!dev) { + of_node_put(node); + return ERR_PTR(-ENOMEM); + } + + dev_set_name(dev, "%s:%s", dev_name(parent), child); + dev->class = ¬ify_device_class; + dev->parent = parent; + dev->of_node = node; + err = device_register(dev); + if (err) { + put_device(dev); + return ERR_PTR(err); + } + + dev->driver = ¬ify_device_driver.driver; + err = device_bind_driver(dev); + if (err) { + device_unregister(dev); + return ERR_PTR(err); + } + + return dev; +} +EXPORT_SYMBOL_GPL(notify_device_create); + +void notify_device_destroy(struct device *dev) +{ + if (!dev) + return; + + device_release_driver(dev); + device_unregister(dev); +} +EXPORT_SYMBOL_GPL(notify_device_destroy); + +struct device *notify_device_find_by_of_node(struct device_node *node) +{ + return class_find_device_by_of_node(¬ify_device_class, node); +} +EXPORT_SYMBOL_GPL(notify_device_find_by_of_node); + +static int __init notify_device_init(void) +{ + int err; + + err = class_register(¬ify_device_class); + if (err) + return err; + + err = platform_driver_register(¬ify_device_driver); + if (err) { + class_unregister(¬ify_device_class); + return err; + } + + return 0; +} + +static void __exit notify_device_exit(void) +{ + platform_driver_unregister(¬ify_device_driver); + class_unregister(¬ify_device_class); +} + +module_init(notify_device_init); +module_exit(notify_device_exit); +MODULE_LICENSE("GPL"); diff --git a/include/linux/notify-device.h b/include/linux/notify-device.h new file mode 100644 index 000000000000..f8c3e15d3b8f --- /dev/null +++ b/include/linux/notify-device.h @@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _LINUX_NOTIFY_DEVICE_H +#define _LINUX_NOTIFY_DEVICE_H +#include <linux/device.h> +#include <linux/of.h> + +#ifdef CONFIG_NOTIFY_DEVICE + +struct device *notify_device_create(struct device *parent, const char *child); +void notify_device_destroy(struct device *dev); +struct device *notify_device_find_by_of_node(struct device_node *node); + +#else + +static inline struct device *notify_device_create(struct device *parent, + const char *child) +{ + return NULL; +} + +static inline void notify_device_destroy(struct device *dev) +{ +} + +static inline struct device *notify_device_find_by_of_node(struct device_node *node) +{ + return NULL; +} + +#endif + +#endif /* _LINUX_NOTIFY_DEVICE_H */