This patch series is obviously missing documentation, MAINTAINERS
entries, etc., but I'd like to solicit some basic feedback on whether
this approach makes sense at all before I proceed. If it does, the
naming is also very much open for bikeshedding - I'm not too happy with
"notify-device".
The basic problem that the notify-device tries to solve is the
synchronization of firmware loading readiness between the Marvell/NXP
WLAN and Bluetooth drivers, but it may also be applicable to other
drivers.
The WLAN and Bluetooth adapters are handled by separate drivers, and may
be connected to the CPU using different interfaces (for example SDIO for
WLAN and UART for Bluetooth). However, both adapters share a single
firmware that may be uploaded via either interface.
For the SDIO+UART case, uploading the firmware via SDIO is usually
preferable, but even when the interface doesn't matter, it seems like a
good idea to clearly define which driver should handle it. To avoid
making the Bluetooth driver more complicated than necessary in this case,
we'd like to defer the probing of the driver until the firmware is ready.
For this purpose, we are introducing a notify-device, with the following
properties:
- The device is created by a driver as soon as some "readiness
condition" is satisfied
- Creating the device also binds a stub driver, so deferred probes are
triggered
- Looking up the notify device is possible via OF node / phandle reference
This approach avoids a hard dependency between the WLAN and Bluetooth
driver, and works regardless of the driver load order.
The first patch implementes the notify-device driver itself, and the
rest shows how the device could be hooked up to the mwifiex and hci_mrvl
drivers. A device tree making use of the notify-device could look like
the following:
&sdhci1 {
wifi@1 {
compatible = "marvell,sd8987";
reg = <1>;
wifi_firmware: firmware-notifier {};
};
};
&main_uart3 {
bluetooth {
compatible = "marvell,sd8987-bt";
firmware-ready = <&wifi_firmware>;
};
};
Matthias Schiffer (5):
misc: introduce notify-device driver
wireless: mwifiex: signal firmware readiness using notify-device
bluetooth: hci_mrvl: select firmwares to load by match data
bluetooth: hci_mrvl: add support for SD8987
bluetooth: hci_mrvl: allow waiting for firmware load using
notify-device
drivers/bluetooth/hci_mrvl.c | 77 ++++++++++++--
drivers/misc/Kconfig | 4 +
drivers/misc/Makefile | 1 +
drivers/misc/notify-device.c | 109 ++++++++++++++++++++
drivers/net/wireless/marvell/mwifiex/main.c | 14 +++
drivers/net/wireless/marvell/mwifiex/main.h | 1 +
include/linux/notify-device.h | 33 ++++++
7 files changed, 228 insertions(+), 11 deletions(-)
create mode 100644 drivers/misc/notify-device.c
create mode 100644 include/linux/notify-device.h
--
2.25.1
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 <redacted>
---
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
On Wed, Oct 26, 2022 at 03:15:30PM +0200, Matthias Schiffer wrote:
quoted hunk
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 <redacted>
---
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
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:
quoted
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 <redacted>
---
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
[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
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:
quoted
On Wed, Oct 26, 2022 at 03:15:30PM +0200, Matthias Schiffer wrote:
quoted
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 <redacted>
---
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
[Pruning the CC list a bit, to avoid clogging people's inboxes]
quoted
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.
quoted
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.
quoted
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:
quoted
On Wed, 2022-10-26 at 16:37 +0200, Greg Kroah-Hartman wrote:
quoted
On Wed, Oct 26, 2022 at 03:15:30PM +0200, Matthias Schiffer wrote:
quoted
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 <redacted>
---
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
[Pruning the CC list a bit, to avoid clogging people's inboxes]
quoted
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.
quoted
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.
quoted
quoted
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.
quoted
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 :)
quoted
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
Make the driver more generic by adding a driver info struct. We also add
support for devices without firmware (for example when the firmware is
loaded by the WLAN driver on a combined module).
Signed-off-by: Matthias Schiffer <redacted>
---
drivers/bluetooth/hci_mrvl.c | 57 +++++++++++++++++++++++++++++-------
1 file changed, 46 insertions(+), 11 deletions(-)
@@ -353,18 +369,29 @@ static int mrvl_load_firmware(struct hci_dev *hdev, const char *name)staticintmrvl_setup(structhci_uart*hu){+conststructmrvl_driver_info*info;interr;-hci_uart_set_flow_control(hu,true);+if(hu->serdev){+structmrvl_serdev*mrvldev=serdev_device_get_drvdata(hu->serdev);-err=mrvl_load_firmware(hu->hdev,"mrvl/helper_uart_3000000.bin");-if(err){-bt_dev_err(hu->hdev,"Unable to download firmware helper");-return-EINVAL;+info=mrvldev->info;+}else{+info=mrvl_driver_info_default;}-/* Let the final ack go out before switching the baudrate */-hci_uart_wait_until_sent(hu);+if(info->firmware_helper){+hci_uart_set_flow_control(hu,true);++err=mrvl_load_firmware(hu->hdev,info->firmware_helper);+if(err){+bt_dev_err(hu->hdev,"Unable to download firmware helper");+return-EINVAL;+}++/* Let the final ack go out before switching the baudrate */+hci_uart_wait_until_sent(hu);+}if(hu->serdev)serdev_device_set_baudrate(hu->serdev,3000000);
@@ -373,9 +400,11 @@ static int mrvl_setup(struct hci_uart *hu)hci_uart_set_flow_control(hu,false);-err=mrvl_load_firmware(hu->hdev,"mrvl/uart8897_bt.bin");-if(err)-returnerr;+if(info->firmware){+err=mrvl_load_firmware(hu->hdev,info->firmware);+if(err)+returnerr;+}return0;}
@@ -401,6 +430,12 @@ static int mrvl_serdev_probe(struct serdev_device *serdev)if(!mrvldev)return-ENOMEM;+if(IS_ENABLED(CONFIG_OF)){+mrvldev->info=of_device_get_match_data(&serdev->dev);+if(!mrvldev->info)+return-ENODEV;+}+mrvldev->hu.serdev=serdev;serdev_device_set_drvdata(serdev,mrvldev);
Do not load any firmwares, and instead expect the firmware to be
initialized by the WLAN driver.
Signed-off-by: Matthias Schiffer <redacted>
---
drivers/bluetooth/hci_mrvl.c | 3 +++
1 file changed, 3 insertions(+)
@@ -433,9 +434,25 @@ static int mrvl_serdev_probe(struct serdev_device *serdev)return-ENOMEM;if(IS_ENABLED(CONFIG_OF)){+structdevice_node*firmware_ready_node;+structdevice*firmware_ready;+mrvldev->info=of_device_get_match_data(&serdev->dev);if(!mrvldev->info)return-ENODEV;++firmware_ready_node=of_parse_phandle(serdev->dev.of_node,+"firmware-ready",0);
So you want us to go through five patches, find properties and OF-code,
create in our minds bindings you think about and comment on that
imaginary bindings.
I think it should work otherwise - send bindings for all of your DT
properties.
Best regards,
Krzysztof