leds: trigger: Introduce an USB port trigger
Subsystems (2)
PATCH v4 1/1 leds: trigger: Introduce an USB port trigger
From: Rafał Miłecki <[email protected]>
This commit adds a new trigger responsible for turning on LED when USB device gets connected to the specified USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.
The trigger gets its documentation file but basically it just requires specifying USB port in a Linux format (e.g. echo 1-1 > new_port).
During work on this trigger there was a plan to add DT bindings for it, but there wasn't an agreement on the format yet. This can be worked on later, a sysfs interface is needed anyway for platforms not using DT.
Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.
---
V2: Trying to add DT support, idea postponed as it will take more time
to discuss the bindings.
V3: Fix typos in commit and Documentation (thanks Jacek!)
Use "ports" sysfs file for adding and removing USB ports (thx Jacek) Check if there is USB device connected after adding new USB port Fix memory leak or two
V3.5: Fix e-mail address (thanks Matthias)
Simplify conditions in usbport_trig_notify (thx Matthias) Make "ports" a subdirectory with file per port, to match one value per file sysfs rule (thanks Greg)
As "ports" couldn't be used for adding and removing ports anymore, there are now "new_port" and "remove_port". Having them makes this API also common with e.g. pci and usb buses.
V4: Add Documentation/ABI/testing/sysfs-class-led-trigger-usbport and
reference it in Documentation/leds/ledtrig-usbport.txt to avoid doc duplication.
--- .../ABI/testing/sysfs-class-led-trigger-usbport | 25 ++ Documentation/leds/ledtrig-usbport.txt | 46 +++ drivers/leds/trigger/Kconfig | 8 + drivers/leds/trigger/Makefile | 1 + drivers/leds/trigger/ledtrig-usbport.c | 309 +++++++++++++++++++++ 5 files changed, 389 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-usbport create mode 100644 Documentation/leds/ledtrig-usbport.txt create mode 100644 drivers/leds/trigger/ledtrig-usbport.c
Documentation/ABI/testing/sysfs-class-led-trigger-usbport new file +25 -0
@@ -0,0 +1,25 @@ +What: /sys/class/leds/<led>/new_port +Date: August 2016 +KernelVersion: 4.9 +Contact: [email protected] +Description: + Adds USB port (specified by a name using Linux format, e.g. 1-1) + to the list of observable ones. This will have immediate effect + if there is device already connected. This will also make + trigger checking for a match on every USB (dis)connection event. + +What: /sys/class/leds/<led>/remove_port +Date: August 2016 +KernelVersion: 4.9 +Contact: [email protected] +Description: + This allows removing USB port from the list of observable ones. + +What: /sys/class/leds/<led>/ports/<port> +Date: August 2016 +KernelVersion: 4.9 +Contact: [email protected] +Description: + Every port entry is a name (in Linux format) of USB port that is + being observed by the usbport trigger. It's useful for checking + the current state of trigger setup.
Documentation/leds/ledtrig-usbport.txt new file +46 -0
46 lines not on this page · raw message
drivers/leds/trigger/Kconfig +8 -0
@@ -126,4 +126,12 @@ config LEDS_TRIGGER_PANIC a different trigger. If unsure, say Y. +config LEDS_TRIGGER_USBPORT + tristate "USB port LED trigger" + depends on LEDS_TRIGGERS && USB + help + This allows LEDs to be controlled by USB events. Enabling this option + allows specifying list of USB ports that should turn on LED when some + USB device gets connected. + endif # LEDS_TRIGGERS
drivers/leds/trigger/Makefile +1 -0
@@ -10,3 +10,4 @@ obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o obj-$(CONFIG_LEDS_TRIGGER_PANIC) += ledtrig-panic.o +obj-$(CONFIG_LEDS_TRIGGER_USBPORT) += ledtrig-usbport.o
drivers/leds/trigger/ledtrig-usbport.c new file +309 -0
309 lines not on this page · raw message
Signature · 1 line
2.9.3
Quoted 4 lines · Rafał Miłecki
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+static void usbport_trig_activate (struct led_classdev *led_cdev) +{ +struct usbport_trig_data *usbport_data; +int err;
drivers/leds/trigger/ledtrig-usbport.c line 236
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+ + usbport_data =kzalloc (sizeof (*usbport_data),GFP_KERNEL ); +if (!usbport_data) +return ; + usbport_data->led_cdev = led_cdev; + +/* Storing ports */ +INIT_LIST_HEAD (&usbport_data->ports); + usbport_data->ports_dir =kobject_create_and_add ("ports" , + &led_cdev->dev->kobj);
If you _ever_ find yourself in a driver having to use kobject calls, it's a HUGE hint that you are doing something wrong.
Hint, you are doing this wrong :)
Use an attribute group if you need a subdirectory in sysfs, using a "raw" kobject like this hides it from all userspace tools and so no userspace program can see it (hint, try using libudev to access these files attached to the device...)
drivers/leds/trigger/ledtrig-usbport.c line 246
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+if (!usbport_data->ports_dir) + goto err_free; + +/* API for ports management */ + err =device_create_file (led_cdev->dev, &dev_attr_new_port); +if (err) + goto err_put_ports; + err =device_create_file (led_cdev->dev, &dev_attr_remove_port); +if (err) + goto err_remove_new_port;
Doesn't this race with userspace and fail? Shouldn't the led core be creating your leds for you?
drivers/leds/trigger/ledtrig-usbport.c line 251
Quoted 5 lines
drivers/leds/trigger/ledtrig-usbport.c new file +5
-0+ +/* Notifications */ + usbport_data->nb.notifier_call = usbport_trig_notify, + led_cdev->trigger_data = usbport_data; +usb_register_notify (&usbport_data->nb);
Don't abuse the USB notifier chain with stuff like this please, is that really necessary? Why can't your hardware just tell you what USB ports are in use "out of band"?
drivers/leds/trigger/ledtrig-usbport.c line 262
Quoted 11 lines
drivers/leds/trigger/ledtrig-usbport.c new file +11
-0+ + led_cdev->activated = true; +return ; + +err_remove_new_port: +device_remove_file (led_cdev->dev, &dev_attr_new_port); +err_put_ports: +kobject_put (usbport_data->ports_dir); +err_free: +kfree (usbport_data); +}
And again, why is this USB specific? Why can't you use this same userspace api and codebase for PCI ports? For a sdcard port? For a thunderbolt port?
thanks,
greg k-h
Quoted 19 lines · Greg KH
Quoted 4 lines · Rafał Miłecki
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+static void usbport_trig_activate (struct led_classdev *led_cdev) +{ +struct usbport_trig_data *usbport_data; +int err;drivers/leds/trigger/ledtrig-usbport.c line 236
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+ + usbport_data =kzalloc (sizeof (*usbport_data),GFP_KERNEL ); +if (!usbport_data) +return ; + usbport_data->led_cdev = led_cdev; + +/* Storing ports */ +INIT_LIST_HEAD (&usbport_data->ports); + usbport_data->ports_dir =kobject_create_and_add ("ports" , + &led_cdev->dev->kobj);If you _ever_ find yourself in a driver having to use kobject calls, it's a HUGE hint that you are doing something wrong.
Quoted 6 lines
Hint, you are doing this wrong :)
Use an attribute group if you need a subdirectory in sysfs, using a "raw" kobject like this hides it from all userspace tools and so no userspace program can see it (hint, try using libudev to access these files attached to the device...)
Oops. Thanks for pointing groups to me. I was looking at sysfs.h earlier but I didn't realize group can be a subdirectory. I can see these sysfs_create_group(s) and friends now, thanks.
Quoted 11 lines
drivers/leds/trigger/ledtrig-usbport.c line 246
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+if (!usbport_data->ports_dir) + goto err_free; + +/* API for ports management */ + err =device_create_file (led_cdev->dev, &dev_attr_new_port); +if (err) + goto err_put_ports; + err =device_create_file (led_cdev->dev, &dev_attr_remove_port); +if (err) + goto err_remove_new_port;
Quoted 2 lines
Doesn't this race with userspace and fail? Shouldn't the led core be creating your leds for you?
These questions aren't clear to me. What kind of race? Doing echo usbport > trigger
results in trigger core calling usbport_trig_activate. We create new attributes and then we return.
I'm also not creating any leds there. This already has to be LED available if you want to assign some trigger to it.
Quoted 9 lines
drivers/leds/trigger/ledtrig-usbport.c line 251
Quoted 5 lines
drivers/leds/trigger/ledtrig-usbport.c new file +5
-0+ +/* Notifications */ + usbport_data->nb.notifier_call = usbport_trig_notify, + led_cdev->trigger_data = usbport_data; +usb_register_notify (&usbport_data->nb);Don't abuse the USB notifier chain with stuff like this please, is that really necessary? Why can't your hardware just tell you what USB ports are in use "out of band"?
I totally don't understand this part. This LED trigger is supposed to react to USB devices appearing at specified ports. How else can I know there is a new USB device if not by notifications?
I'm wondering if we are on the same page. Could it be my idea of this LED trigger is not clear at all? Could you take a look at commit message again, please? Mostly this part:
Quoted 4 lines
This commit adds a new trigger responsible for turning on LED when USB device gets connected to the specified USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.
Can I add something more to make it clear what this trigger is responsible for?
Quoted 7 lines
Quoted 7 lines
drivers/leds/trigger/ledtrig-usbport.c new file +7
-0+ + led_cdev->activated = true; +return ; + +err_remove_new_port: +device_remove_file (led_cdev->dev, &dev_attr_new_port); +err_put_ports:
Quoted 8 lines
drivers/leds/trigger/ledtrig-usbport.c line 262
Quoted 4 lines
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+kobject_put (usbport_data->ports_dir); +err_free: +kfree (usbport_data); +}And again, why is this USB specific? Why can't you use this same userspace api and codebase for PCI ports? For a sdcard port? For a thunderbolt port?
I'm leaving this one unanswered as discussion on this continued in V3.5 thread below my reply:
Quoted 4 lines · Rafał Miłecki
Good question. I would like to extend this USB port trigger in the future by reacting to USB activity. This involves playing with URBs and I believe that at that point it'd be getting too much USB specific to /rule them all/.
Signature · 1 line
Rafał
Quoted 22 lines · Rafał Miłecki
Quoted 21 lines · Greg KH
Quoted 4 lines · Rafał Miłecki
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+static void usbport_trig_activate (struct led_classdev *led_cdev) +{ +struct usbport_trig_data *usbport_data; +int err;drivers/leds/trigger/ledtrig-usbport.c line 236
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+ + usbport_data =kzalloc (sizeof (*usbport_data),GFP_KERNEL ); +if (!usbport_data) +return ; + usbport_data->led_cdev = led_cdev; + +/* Storing ports */ +INIT_LIST_HEAD (&usbport_data->ports); + usbport_data->ports_dir =kobject_create_and_add ("ports" , + &led_cdev->dev->kobj);If you _ever_ find yourself in a driver having to use kobject calls, it's a HUGE hint that you are doing something wrong.
Hint, you are doing this wrong :)
Quoted 8 lines
Quoted 4 lines
Use an attribute group if you need a subdirectory in sysfs, using a "raw" kobject like this hides it from all userspace tools and so no userspace program can see it (hint, try using libudev to access these files attached to the device...)
Oops. Thanks for pointing groups to me. I was looking at
sysfs.hearlier but I didn't realize group can be a subdirectory. I can see thesesysfs_create_group(s)and friends now, thanks.
No, use an attribute group, and name it, and the subdir will be created automagically for you.
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+if (!usbport_data->ports_dir) + goto err_free; + +/* API for ports management */ + err =device_create_file (led_cdev->dev, &dev_attr_new_port); +if (err) + goto err_put_ports; + err =device_create_file (led_cdev->dev, &dev_attr_remove_port); +if (err) + goto err_remove_new_port;
Quoted 7 lines
Quoted 2 lines
Doesn't this race with userspace and fail? Shouldn't the led core be creating your leds for you?
These questions aren't clear to me. What kind of race? Doing echo usbport > trigger
results in trigger core callingusbport_trig_activate. We create new attributes and then we return.
Why aren't the attributes present when the device is found? What is "trigger" for?
Quoted 2 lines
I'm also not creating any leds there. This already has to be LED available if you want to assign some trigger to it.
That sounds really odd...
Quoted 16 lines
Quoted 9 lines
drivers/leds/trigger/ledtrig-usbport.c line 251
Quoted 5 lines
drivers/leds/trigger/ledtrig-usbport.c new file +5
-0+ +/* Notifications */ + usbport_data->nb.notifier_call = usbport_trig_notify, + led_cdev->trigger_data = usbport_data; +usb_register_notify (&usbport_data->nb);Don't abuse the USB notifier chain with stuff like this please, is that really necessary? Why can't your hardware just tell you what USB ports are in use "out of band"?
I totally don't understand this part. This LED trigger is supposed to react to USB devices appearing at specified ports. How else can I know there is a new USB device if not by notifications?
I'm wondering if we are on the same page. Could it be my idea of this LED trigger is not clear at all? Could you take a look at commit message again, please? Mostly this part:
Quoted 6 lines
Quoted 4 lines
This commit adds a new trigger responsible for turning on LED when USB device gets connected to the specified USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.
Can I add something more to make it clear what this trigger is responsible for?
Yes please, as I totally missed that.
And the USB notifier was created for some "special" parts of the USB core to use, this feels like an abuse of that in some way. But it's hard to define, I know...
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/leds/trigger/ledtrig-usbport.c new file +7
-0+ + led_cdev->activated = true; +return ; + +err_remove_new_port: +device_remove_file (led_cdev->dev, &dev_attr_new_port); +err_put_ports:Quoted 8 lines
drivers/leds/trigger/ledtrig-usbport.c line 262
Quoted 4 lines
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+kobject_put (usbport_data->ports_dir); +err_free: +kfree (usbport_data); +}And again, why is this USB specific? Why can't you use this same userspace api and codebase for PCI ports? For a sdcard port? For a thunderbolt port?
Quoted 7 lines
I'm leaving this one unanswered as discussion on this continued in V3.5 thread below my reply:
Quoted 4 lines · Rafał Miłecki
Good question. I would like to extend this USB port trigger in the future by reacting to USB activity. This involves playing with URBs and I believe that at that point it'd be getting too much USB specific to /rule them all/.
No, I mean why not have this specific activity LED work for all types of devices, not just USB.
Not that this specific LED works for other types of USB activity.
thanks,
greg k-h
Quoted 28 lines · Greg KH
Quoted 27 lines · Rafał Miłecki
Quoted 25 lines · Greg KH
Quoted 4 lines · Rafał Miłecki
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+static void usbport_trig_activate (struct led_classdev *led_cdev) +{ +struct usbport_trig_data *usbport_data; +int err;drivers/leds/trigger/ledtrig-usbport.c line 236
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+ + usbport_data =kzalloc (sizeof (*usbport_data),GFP_KERNEL ); +if (!usbport_data) +return ; + usbport_data->led_cdev = led_cdev; + +/* Storing ports */ +INIT_LIST_HEAD (&usbport_data->ports); + usbport_data->ports_dir =kobject_create_and_add ("ports" , + &led_cdev->dev->kobj);If you _ever_ find yourself in a driver having to use kobject calls, it's a HUGE hint that you are doing something wrong.
Hint, you are doing this wrong :)
Use an attribute group if you need a subdirectory in sysfs, using a "raw" kobject like this hides it from all userspace tools and so no userspace program can see it (hint, try using libudev to access these files attached to the device...)
Quoted 6 lines
Quoted 3 lines
Oops. Thanks for pointing groups to me. I was looking at
sysfs.hearlier but I didn't realize group can be a subdirectory. I can see thesesysfs_create_group(s)and friends now, thanks.No, use an attribute group, and name it, and the subdir will be created automagically for you.
Oh, so I got it wrong again. Thanks for explaining.
Quoted 19 lines
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
drivers/leds/trigger/ledtrig-usbport.c new file +10
-0+if (!usbport_data->ports_dir) + goto err_free; + +/* API for ports management */ + err =device_create_file (led_cdev->dev, &dev_attr_new_port); +if (err) + goto err_put_ports; + err =device_create_file (led_cdev->dev, &dev_attr_remove_port); +if (err) + goto err_remove_new_port;Quoted 7 lines
Quoted 2 lines
Doesn't this race with userspace and fail? Shouldn't the led core be creating your leds for you?
These questions aren't clear to me. What kind of race? Doing echo usbport > trigger
results in trigger core callingusbport_trig_activate. We create new attributes and then we return.
Quoted 7 lines
Why aren't the attributes present when the device is found? What is "trigger" for?
Quoted 2 lines
I'm also not creating any leds there. This already has to be LED available if you want to assign some trigger to it.
That sounds really odd...
Please take a look at Documentation to get some idea of LED triggers:Documentation/leds/leds-class.txt
Basically a LED (/sys/class/leds/foo/) can be controller with "brightness" sysfs file like this:
echo 0 > brightness
echo 5 > brightness
echo 255 > brightness
(most LEDs react only 0 and non-0 values).
As you quite often need more complex LED management, there are triggers that were introduced in 2006 by c3bc9956ec52f ("[PATCH] LED:
add LED trigger tupport"). Some triggers are trivial and could be implemented in userspace as well (e.g. "timer"). Some had to be implemented in kernelspace (CPU activity, MTD activity, etc.). Having few triggers compiled, you can assign them to LEDs at it pleases you. Your hardware may have generic LED (not labeled) and you can dynamically assign various triggers to it, depending e.g. on user actions. E.g. if user (using GUI or whatever) wants to see flash activity, your userspace script should do:
echo mtd > /sys/class/leds/foo/trigger
I hope it explains things a big and you can see know why trigger code is independent of creating LEDs. It's about layers and making things generic I believe.
There is a place for LED driver that is responsible for creating "struct led_classdev" with proper callback setting brightness. It provides LED name, but is unaware of the way it should be lighted/turned off.
There is LED subsystem.
There are triggers that are unaware of LED hardware details and only set LED brightness using generic API.
I'm obviously not author of all of that and I can't explain some design decisions, but I hope I gave you a clue how it works.
Quoted 21 lines
Quoted 21 lines
Quoted 9 lines
drivers/leds/trigger/ledtrig-usbport.c line 251
Quoted 5 lines
drivers/leds/trigger/ledtrig-usbport.c new file +5
-0+ +/* Notifications */ + usbport_data->nb.notifier_call = usbport_trig_notify, + led_cdev->trigger_data = usbport_data; +usb_register_notify (&usbport_data->nb);Don't abuse the USB notifier chain with stuff like this please, is that really necessary? Why can't your hardware just tell you what USB ports are in use "out of band"?
I totally don't understand this part. This LED trigger is supposed to react to USB devices appearing at specified ports. How else can I know there is a new USB device if not by notifications?
I'm wondering if we are on the same page. Could it be my idea of this LED trigger is not clear at all? Could you take a look at commit message again, please? Mostly this part:Quoted 4 lines
This commit adds a new trigger responsible for turning on LED when USB device gets connected to the specified USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.
Quoted 7 lines
Quoted 1 line
Can I add something more to make it clear what this trigger is responsible for?
Yes please, as I totally missed that.
And the USB notifier was created for some "special" parts of the USB core to use, this feels like an abuse of that in some way. But it's hard to define, I know...
I didn't mean to abuse this USB notifier, can you think of any other way to achieve the same result? We could think about modifying USB core to call some symbol from the trigger driver (see usage of ledtrig_mtd_activity symbol) but is it any better than using notification block?
Quoted 24 lines
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/leds/trigger/ledtrig-usbport.c new file +7
-0+ + led_cdev->activated = true; +return ; + +err_remove_new_port: +device_remove_file (led_cdev->dev, &dev_attr_new_port); +err_put_ports:Quoted 8 lines
drivers/leds/trigger/ledtrig-usbport.c line 262
Quoted 4 lines
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+kobject_put (usbport_data->ports_dir); +err_free: +kfree (usbport_data); +}And again, why is this USB specific? Why can't you use this same userspace api and codebase for PCI ports? For a sdcard port? For a thunderbolt port?
Quoted 7 lines
I'm leaving this one unanswered as discussion on this continued in V3.5 thread below my reply:
Quoted 4 lines · Rafał Miłecki
Good question. I would like to extend this USB port trigger in the future by reacting to USB activity. This involves playing with URBs and I believe that at that point it'd be getting too much USB specific to /rule them all/.
Quoted 4 lines
No, I mean why not have this specific activity LED work for all types of devices, not just USB.
Not that this specific LED works for other types of USB activity.
Sorry, I'm really trying my best, but I may be missing some point. I'm not sure if I'll answer your question as you expected.
This patch adds only 1 trigger some users may be interested in, user is still free to assign any trigger he wants to any LED it has on his hardware. One day I plan to work on more triggers, so user can pick the one he wants (e.g. when using generic not-labeled LED):
echo none > trigger
echo usbport > trigger
echo foo > trigger
Signature · 1 line
Rafał
Quoted 10 lines · Rafał Miłecki
Please take a look at Documentation to get some idea of LED triggers:
Documentation/leds/leds-class.txtBasically a LED (
/sys/class/leds/foo/) can be controller with "brightness" sysfs file like this:
echo 0 > brightness
echo 5 > brightness
echo 255 > brightness
(most LEDs react only 0 and non-0 values).
Quoted 11 lines
As you quite often need more complex LED management, there are triggers that were introduced in 2006 by
c3bc9956ec52f("[PATCH] LED:
add LED trigger tupport"). Some triggers are trivial and could be implemented in userspace as well (e.g. "timer"). Some had to be implemented in kernelspace (CPU activity, MTD activity, etc.). Having few triggers compiled, you can assign them to LEDs at it pleases you. Your hardware may have generic LED (not labeled) and you can dynamically assign various triggers to it, depending e.g. on user actions. E.g. if user (using GUI or whatever) wants to see flash activity, your userspace script should do:
echo mtd >/sys/class/leds/foo/trigger
So for example, you might want to do:
echo usb1-4 >/sys/class/leds/foo/trigger
and then have the "foo" LED toggle whenever an URB was submitted or completed for a device attached to the 1-4 port. Right?
Quoted 43 lines
I hope it explains things a big and you can see know why trigger code is independent of creating LEDs. It's about layers and making things generic I believe.
There is a place for LED driver that is responsible for creating "struct
led_classdev" with proper callback setting brightness. It provides LED name, but is unaware of the way it should be lighted/turned off.
There is LED subsystem.
There are triggers that are unaware of LED hardware details and only set LED brightness using generic API.I'm obviously not author of all of that and I can't explain some design decisions, but I hope I gave you a clue how it works.
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
drivers/leds/trigger/ledtrig-usbport.c line 251
Quoted 4 lines
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+/* Notifications */ + usbport_data->nb.notifier_call = usbport_trig_notify, + led_cdev->trigger_data = usbport_data; +usb_register_notify (&usbport_data->nb);Don't abuse the USB notifier chain with stuff like this please, is that really necessary? Why can't your hardware just tell you what USB ports are in use "out of band"?
I totally don't understand this part. This LED trigger is supposed to react to USB devices appearing at specified ports. How else can I know there is a new USB device if not by notifications?
I'm wondering if we are on the same page. Could it be my idea of this LED trigger is not clear at all? Could you take a look at commit message again, please? Mostly this part:Quoted 4 lines
This commit adds a new trigger responsible for turning on LED when USB device gets connected to the specified USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.
Quoted 7 lines
Quoted 1 line
Can I add something more to make it clear what this trigger is responsible for?
Yes please, as I totally missed that.
And the USB notifier was created for some "special" parts of the USB core to use, this feels like an abuse of that in some way. But it's hard to define, I know...
Quoted 5 lines
I didn't mean to abuse this USB notifier, can you think of any other way to achieve the same result? We could think about modifying USB core to call some symbol from the trigger driver (see usage of
ledtrig_mtd_activitysymbol) but is it any better than using notification block?
I don't think this is such a bad use of the USB notifier. All you need to know is when a device is attached to or unplugged from an LED's port. Neither of these is a very frequent event.
However, there is still the question of how to know when an URB is submitted or completed for the device in question. Obviously the USB core would have to call an LED routine. But how would you determine which LED(s) to toggle? Go through the entire list, looking for ones that are bound to the USB device in question? This seems inefficient. Use a hash table?
Alan Stern
Quoted 24 lines · Alan Stern
Quoted 10 lines · Rafał Miłecki
Please take a look at Documentation to get some idea of LED triggers:
Documentation/leds/leds-class.txtBasically a LED (
/sys/class/leds/foo/) can be controller with "brightness" sysfs file like this:
echo 0 > brightness
echo 5 > brightness
echo 255 > brightness
(most LEDs react only 0 and non-0 values).Quoted 11 lines
As you quite often need more complex LED management, there are triggers that were introduced in 2006 by
c3bc9956ec52f("[PATCH] LED:
add LED trigger tupport"). Some triggers are trivial and could be implemented in userspace as well (e.g. "timer"). Some had to be implemented in kernelspace (CPU activity, MTD activity, etc.). Having few triggers compiled, you can assign them to LEDs at it pleases you. Your hardware may have generic LED (not labeled) and you can dynamically assign various triggers to it, depending e.g. on user actions. E.g. if user (using GUI or whatever) wants to see flash activity, your userspace script should do:
echo mtd >/sys/class/leds/foo/trigger
Quoted 6 lines
So for example, you might want to do:
echo usb1-4 >/sys/class/leds/foo/trigger
and then have the "foo" LED toggle whenever an URB was submitted or completed for a device attached to the 1-4 port. Right?
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" > /sys/class/leds/foo/trigger
This was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").
Quoted 53 lines
Quoted 43 lines
I hope it explains things a big and you can see know why trigger code is independent of creating LEDs. It's about layers and making things generic I believe.
There is a place for LED driver that is responsible for creating "struct
led_classdev" with proper callback setting brightness. It provides LED name, but is unaware of the way it should be lighted/turned off.
There is LED subsystem.
There are triggers that are unaware of LED hardware details and only set LED brightness using generic API.I'm obviously not author of all of that and I can't explain some design decisions, but I hope I gave you a clue how it works.
Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
drivers/leds/trigger/ledtrig-usbport.c line 251
Quoted 4 lines
drivers/leds/trigger/ledtrig-usbport.c new file +4
-0+/* Notifications */ + usbport_data->nb.notifier_call = usbport_trig_notify, + led_cdev->trigger_data = usbport_data; +usb_register_notify (&usbport_data->nb);Don't abuse the USB notifier chain with stuff like this please, is that really necessary? Why can't your hardware just tell you what USB ports are in use "out of band"?
I totally don't understand this part. This LED trigger is supposed to react to USB devices appearing at specified ports. How else can I know there is a new USB device if not by notifications?
I'm wondering if we are on the same page. Could it be my idea of this LED trigger is not clear at all? Could you take a look at commit message again, please? Mostly this part:Quoted 4 lines
This commit adds a new trigger responsible for turning on LED when USB device gets connected to the specified USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.
Quoted 7 lines
Quoted 1 line
Can I add something more to make it clear what this trigger is responsible for?
Yes please, as I totally missed that.
And the USB notifier was created for some "special" parts of the USB core to use, this feels like an abuse of that in some way. But it's hard to define, I know...
Quoted 5 lines
I didn't mean to abuse this USB notifier, can you think of any other way to achieve the same result? We could think about modifying USB core to call some symbol from the trigger driver (see usage of
ledtrig_mtd_activitysymbol) but is it any better than using notification block?I don't think this is such a bad use of the USB notifier. All you need to know is when a device is attached to or unplugged from an LED's port. Neither of these is a very frequent event.
Quoted 6 lines
However, there is still the question of how to know when an URB is submitted or completed for the device in question. Obviously the USB core would have to call an LED routine. But how would you determine which LED(s) to toggle? Go through the entire list, looking for ones that are bound to the USB device in question? This seems inefficient. Use a hash table?
I was hoping to bring it to discussion later, as it seems even the basic version of this trigger causes many design problems.
Signature · 1 line
Rafał
Quoted 26 lines · Rafał Miłecki
Quoted 12 lines
Quoted 11 lines
As you quite often need more complex LED management, there are triggers that were introduced in 2006 by
c3bc9956ec52f("[PATCH] LED:
add LED trigger tupport"). Some triggers are trivial and could be implemented in userspace as well (e.g. "timer"). Some had to be implemented in kernelspace (CPU activity, MTD activity, etc.). Having few triggers compiled, you can assign them to LEDs at it pleases you. Your hardware may have generic LED (not labeled) and you can dynamically assign various triggers to it, depending e.g. on user actions. E.g. if user (using GUI or whatever) wants to see flash activity, your userspace script should do:
echo mtd >/sys/class/leds/foo/triggerQuoted 6 lines
So for example, you might want to do:
echo usb1-4 >/sys/class/leds/foo/trigger
and then have the "foo" LED toggle whenever an URB was submitted or completed for a device attached to the 1-4 port. Right?
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" >/sys/class/leds/foo/trigger
Quoted 4 lines
This was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").
The code for a bunch of triggers must already be written. What would the user do if he wanted to flash a single LED in response to both CPU activity and MTD activity? If not
echo "cpu mtd" >/sys/class/leds/foo/trigger
then what?
Alan Stern
Quoted 33 lines · Alan Stern
Quoted 26 lines · Rafał Miłecki
Quoted 12 lines
Quoted 11 lines
As you quite often need more complex LED management, there are triggers that were introduced in 2006 by
c3bc9956ec52f("[PATCH] LED:
add LED trigger tupport"). Some triggers are trivial and could be implemented in userspace as well (e.g. "timer"). Some had to be implemented in kernelspace (CPU activity, MTD activity, etc.). Having few triggers compiled, you can assign them to LEDs at it pleases you. Your hardware may have generic LED (not labeled) and you can dynamically assign various triggers to it, depending e.g. on user actions. E.g. if user (using GUI or whatever) wants to see flash activity, your userspace script should do:
echo mtd >/sys/class/leds/foo/triggerQuoted 6 lines
So for example, you might want to do:
echo usb1-4 >/sys/class/leds/foo/trigger
and then have the "foo" LED toggle whenever an URB was submitted or completed for a device attached to the 1-4 port. Right?
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" >/sys/class/leds/foo/triggerQuoted 4 lines
This was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").
Quoted 7 lines
The code for a bunch of triggers must already be written. What would the user do if he wanted to flash a single LED in response to both CPU activity and MTD activity? If not
echo "cpu mtd" >/sys/class/leds/foo/trigger
then what?
Well, it sounds like a new feature then. Shall we add an extra API with a request function for turning LED on? It could internally count how many requests were raised and keep LED on as long as there is at least 1 left. I guess we should implement it in trigger "subsystem" (if I can call it so). Does it sound like a good plan?
Signature · 1 line
Rafał
Quoted 20 lines · Rafał Miłecki
Quoted 19 lines · Alan Stern
Quoted 11 lines · Rafał Miłecki
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" >/sys/class/leds/foo/triggerThis was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").The code for a bunch of triggers must already be written. What would the user do if he wanted to flash a single LED in response to both CPU activity and MTD activity? If not
echo "cpu mtd" >/sys/class/leds/foo/trigger
Quoted 7 lines
Quoted 1 line
then what?
Well, it sounds like a new feature then. Shall we add an extra API with a request function for turning LED on? It could internally count how many requests were raised and keep LED on as long as there is at least 1 left. I guess we should implement it in trigger "subsystem" (if I can call it so). Does it sound like a good plan?
I'm pretty sure noone ever planned to have more than 1 trigger assigned to a single LED. I just realized there will be a problem with proposed solution: sysfs files conflict.
Consider 2 existing triggers for a moment:
1) oneshot: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_off/sys/class/leds/foo/invert/sys/class/leds/foo/shot
2) timer: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_off
Activating both of them will probably cause a WARNING in sysfs. They can't coexist :(
We should probably have per-trigger subdirs, e.g.:/sys/class/leds/foo/trigger-oneshot/delay_on /sys/class/leds/foo/trigger-oneshot/delay_off /sys/class/leds/foo/trigger-oneshot/invert /sys/class/leds/foo/trigger-oneshot/shot /sys/class/leds/foo/trigger-timer/delay_on /sys/class/leds/foo/trigger-timer/delay_off but implementing it now would break the ABI.
One workaround I can see is doing triggers V2, they:
1) Would put sysfs files in /sys/class/leds/foo/trigger-bar/
2) Use new API for *requesting* LED to be on/off
3) There would be a counter of requests in V2 API
4) Multiple triggers V2 would be allowed to be used (assigned) at the same time
Signature · 1 line
Rafał
Quoted 55 lines · Rafał Miłecki
Quoted 20 lines · Rafał Miłecki
Quoted 19 lines · Alan Stern
Quoted 11 lines · Rafał Miłecki
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" >/sys/class/leds/foo/triggerThis was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").The code for a bunch of triggers must already be written. What would the user do if he wanted to flash a single LED in response to both CPU activity and MTD activity? If not
echo "cpu mtd" >/sys/class/leds/foo/trigger
Quoted 7 lines
Quoted 1 line
then what?
Well, it sounds like a new feature then. Shall we add an extra API with a request function for turning LED on? It could internally count how many requests were raised and keep LED on as long as there is at least 1 left. I guess we should implement it in trigger "subsystem" (if I can call it so). Does it sound like a good plan?
I'm pretty sure noone ever planned to have more than 1 trigger assigned to a single LED. I just realized there will be a problem with proposed solution: sysfs files conflict.
Consider 2 existing triggers for a moment:
1) oneshot: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_off/sys/class/leds/foo/invert/sys/class/leds/foo/shot
2) timer: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_offActivating both of them will probably cause a WARNING in sysfs. They can't coexist :(
We should probably have per-trigger subdirs, e.g.:
/sys/class/leds/foo/trigger-oneshot/delay_on/sys/class/leds/foo/trigger-oneshot/delay_off/sys/class/leds/foo/trigger-oneshot/invert/sys/class/leds/foo/trigger-oneshot/shot/sys/class/leds/foo/trigger-timer/delay_on/sys/class/leds/foo/trigger-timer/delay_offbut implementing it now would break the ABI.
Quoted 5 lines
One workaround I can see is doing triggers V2, they:
1) Would put sysfs files in/sys/class/leds/foo/trigger-bar/
2) Use new API for *requesting* LED to be on/off
3) There would be a counter of requests in V2 API
4) Multiple triggers V2 would be allowed to be used (assigned) at the same time
Currently we support only triggers dedicated to specific type of devices. Even in case of triggers that don't expose custom sysfs attributes, registered with led_trigger_register_simple(), device drivers have to generate trigger event with dedicated function, e.g:
- ledtrig-cpu: void ledtrig_cpu(enum cpu_led_event ledevt)
- ledtrig-disk: void ledtrig_disk_activity(void)
- ledtrig-mtd: void ledtrig_mtd_activity(void)
If one wanted to have the LED notified by different type of devices, then they would have to implement a trigger that would exposed all required types of API.
Unfortunately, there are many possible combinations of triggers and that doesn't sound sane to add a new one when someone will find it useful. Of course it would entail adding a call to the new trigger API in the drivers, which doesn't seem like something acceptable in the mainline.
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 75 lines · Jacek Anaszewski
Quoted 55 lines · Rafał Miłecki
Quoted 20 lines · Rafał Miłecki
Quoted 19 lines · Alan Stern
Quoted 11 lines · Rafał Miłecki
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" >/sys/class/leds/foo/triggerThis was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").The code for a bunch of triggers must already be written. What would the user do if he wanted to flash a single LED in response to both CPU activity and MTD activity? If not
echo "cpu mtd" >/sys/class/leds/foo/trigger
Quoted 7 lines
Quoted 1 line
then what?
Well, it sounds like a new feature then. Shall we add an extra API with a request function for turning LED on? It could internally count how many requests were raised and keep LED on as long as there is at least 1 left. I guess we should implement it in trigger "subsystem" (if I can call it so). Does it sound like a good plan?
I'm pretty sure noone ever planned to have more than 1 trigger assigned to a single LED. I just realized there will be a problem with proposed solution: sysfs files conflict.
Consider 2 existing triggers for a moment:
1) oneshot: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_off/sys/class/leds/foo/invert/sys/class/leds/foo/shot
2) timer: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_offActivating both of them will probably cause a WARNING in sysfs. They can't coexist :(
We should probably have per-trigger subdirs, e.g.:
/sys/class/leds/foo/trigger-oneshot/delay_on/sys/class/leds/foo/trigger-oneshot/delay_off/sys/class/leds/foo/trigger-oneshot/invert/sys/class/leds/foo/trigger-oneshot/shot/sys/class/leds/foo/trigger-timer/delay_on/sys/class/leds/foo/trigger-timer/delay_offbut implementing it now would break the ABI.Quoted 5 lines
One workaround I can see is doing triggers V2, they:
1) Would put sysfs files in/sys/class/leds/foo/trigger-bar/
2) Use new API for *requesting* LED to be on/off
3) There would be a counter of requests in V2 API
4) Multiple triggers V2 would be allowed to be used (assigned) at the same timeCurrently we support only triggers dedicated to specific type of devices. Even in case of triggers that don't expose custom sysfs attributes, registered with
led_trigger_register_simple(), device drivers have to generate trigger event with dedicated function, e.g:- ledtrig-cpu: void
ledtrig_cpu(enum cpu_led_event ledevt)
- ledtrig-disk: voidledtrig_disk_activity(void)
- ledtrig-mtd: voidledtrig_mtd_activity(void)If one wanted to have the LED notified by different type of devices, then they would have to implement a trigger that would exposed all required types of API.
Quoted 5 lines
Unfortunately, there are many possible combinations of triggers and that doesn't sound sane to add a new one when someone will find it useful. Of course it would entail adding a call to the new trigger API in the drivers, which doesn't seem like something acceptable in the mainline.
Maybe it would make more sense, in this case, to allow only three possibilities for a USB port activity trigger. Toggle the LED whenever:
There is activity on the specified port, or
There is any activity on any port on the specified hub, or
There is any USB activity on any port.
That ought to cover most of the normal use cases, and it would be simple enough to implement.
Alan Stern
Quoted 87 lines · Alan Stern
Quoted 75 lines · Jacek Anaszewski
Quoted 55 lines · Rafał Miłecki
Quoted 20 lines · Rafał Miłecki
Quoted 19 lines · Alan Stern
Quoted 11 lines · Rafał Miłecki
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" >/sys/class/leds/foo/triggerThis was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").The code for a bunch of triggers must already be written. What would the user do if he wanted to flash a single LED in response to both CPU activity and MTD activity? If not
echo "cpu mtd" >/sys/class/leds/foo/trigger
Quoted 7 lines
Quoted 1 line
then what?
Well, it sounds like a new feature then. Shall we add an extra API with a request function for turning LED on? It could internally count how many requests were raised and keep LED on as long as there is at least 1 left. I guess we should implement it in trigger "subsystem" (if I can call it so). Does it sound like a good plan?
I'm pretty sure noone ever planned to have more than 1 trigger assigned to a single LED. I just realized there will be a problem with proposed solution: sysfs files conflict.
Consider 2 existing triggers for a moment:
1) oneshot: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_off/sys/class/leds/foo/invert/sys/class/leds/foo/shot
2) timer: it creates following sysfs files:/sys/class/leds/foo/delay_on/sys/class/leds/foo/delay_offActivating both of them will probably cause a WARNING in sysfs. They can't coexist :(
We should probably have per-trigger subdirs, e.g.:
/sys/class/leds/foo/trigger-oneshot/delay_on/sys/class/leds/foo/trigger-oneshot/delay_off/sys/class/leds/foo/trigger-oneshot/invert/sys/class/leds/foo/trigger-oneshot/shot/sys/class/leds/foo/trigger-timer/delay_on/sys/class/leds/foo/trigger-timer/delay_offbut implementing it now would break the ABI.Quoted 5 lines
One workaround I can see is doing triggers V2, they:
1) Would put sysfs files in/sys/class/leds/foo/trigger-bar/
2) Use new API for *requesting* LED to be on/off
3) There would be a counter of requests in V2 API
4) Multiple triggers V2 would be allowed to be used (assigned) at the same timeCurrently we support only triggers dedicated to specific type of devices. Even in case of triggers that don't expose custom sysfs attributes, registered with
led_trigger_register_simple(), device drivers have to generate trigger event with dedicated function, e.g:- ledtrig-cpu: void
ledtrig_cpu(enum cpu_led_event ledevt)
- ledtrig-disk: voidledtrig_disk_activity(void)
- ledtrig-mtd: voidledtrig_mtd_activity(void)If one wanted to have the LED notified by different type of devices, then they would have to implement a trigger that would exposed all required types of API.
Quoted 5 lines
Unfortunately, there are many possible combinations of triggers and that doesn't sound sane to add a new one when someone will find it useful. Of course it would entail adding a call to the new trigger API in the drivers, which doesn't seem like something acceptable in the mainline.
Maybe it would make more sense, in this case, to allow only three possibilities for a USB port activity trigger. Toggle the LED whenever:
Quoted 8 lines
There is activity on the specified port, or
There is any activity on any port on the specified hub, or
There is any USB activity on any port.
That ought to cover most of the normal use cases, and it would be simple enough to implement.
What would be the benefit of having a USB port activity trigger, for which we would be specifying the port to observe, but in the same time we would react on any activity on any port (cases 1 and 3)?
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 3 lines · Jacek Anaszewski
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I'm pretty sure noone ever planned to have more than 1 trigger assigned to a single LED. I just realized there will be a problem with proposed solution: sysfs files conflict.
...
Quoted 27 lines
Quoted 27 lines
Quoted 13 lines
Currently we support only triggers dedicated to specific type of devices. Even in case of triggers that don't expose custom sysfs attributes, registered with
led_trigger_register_simple(), device drivers have to generate trigger event with dedicated function, e.g:- ledtrig-cpu: void
ledtrig_cpu(enum cpu_led_event ledevt)
- ledtrig-disk: voidledtrig_disk_activity(void)
- ledtrig-mtd: voidledtrig_mtd_activity(void)If one wanted to have the LED notified by different type of devices, then they would have to implement a trigger that would exposed all required types of API.
Quoted 5 lines
Unfortunately, there are many possible combinations of triggers and that doesn't sound sane to add a new one when someone will find it useful. Of course it would entail adding a call to the new trigger API in the drivers, which doesn't seem like something acceptable in the mainline.
Maybe it would make more sense, in this case, to allow only three possibilities for a USB port activity trigger. Toggle the LED whenever:
There is activity on the specified port, or
There is any activity on any port on the specified hub, or
Quoted 8 lines
Quoted 4 lines
There is any USB activity on any port.
That ought to cover most of the normal use cases, and it would be simple enough to implement.
What would be the benefit of having a USB port activity trigger, for which we would be specifying the port to observe, but in the same time we would react on any activity on any port (cases 1 and 3)?
I meant these three cases to be mutually exclusive. For a given LED, you could have only one of those trigger types (like mentioned above, only one trigger per LED). For example, you might accept any one of:
echo usb1-4.2 >/sys/class/led/foo/trigger
echo hub1-4 >/sys/class/led/foo/trigger
echo usb >/sys/class/led/foo/trigger
Yes, it would be possible to have a port-specific trigger for one LED and an overall USB activity trigger for another LED. I don't know how useful this would be -- you could probably imagine some unlikely scenario.
The point is that doing things this way wouldn't require any API violations, and it would allow users to do almost all of the things they are likely to want.
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 54 lines · Alan Stern
Quoted 3 lines · Jacek Anaszewski
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
I'm pretty sure noone ever planned to have more than 1 trigger assigned to a single LED. I just realized there will be a problem with proposed solution: sysfs files conflict.
...
Quoted 27 lines
Quoted 27 lines
Quoted 13 lines
Currently we support only triggers dedicated to specific type of devices. Even in case of triggers that don't expose custom sysfs attributes, registered with
led_trigger_register_simple(), device drivers have to generate trigger event with dedicated function, e.g:- ledtrig-cpu: void
ledtrig_cpu(enum cpu_led_event ledevt)
- ledtrig-disk: voidledtrig_disk_activity(void)
- ledtrig-mtd: voidledtrig_mtd_activity(void)If one wanted to have the LED notified by different type of devices, then they would have to implement a trigger that would exposed all required types of API.
Quoted 5 lines
Unfortunately, there are many possible combinations of triggers and that doesn't sound sane to add a new one when someone will find it useful. Of course it would entail adding a call to the new trigger API in the drivers, which doesn't seem like something acceptable in the mainline.
Maybe it would make more sense, in this case, to allow only three possibilities for a USB port activity trigger. Toggle the LED whenever:
There is activity on the specified port, or
There is any activity on any port on the specified hub, or
Quoted 8 lines
Quoted 4 lines
There is any USB activity on any port.
That ought to cover most of the normal use cases, and it would be simple enough to implement.
What would be the benefit of having a USB port activity trigger, for which we would be specifying the port to observe, but in the same time we would react on any activity on any port (cases 1 and 3)?
I meant these three cases to be mutually exclusive. For a given LED, you could have only one of those trigger types (like mentioned above, only one trigger per LED). For example, you might accept any one of:
echo usb1-4.2 >/sys/class/led/foo/trigger
echo hub1-4 >/sys/class/led/foo/trigger
echo usb >/sys/class/led/foo/trigger
Quoted 8 lines
Yes, it would be possible to have a port-specific trigger for one LED and an overall USB activity trigger for another LED. I don't know how useful this would be -- you could probably imagine some unlikely scenario.
The point is that doing things this way wouldn't require any API violations, and it would allow users to do almost all of the things they are likely to want.
We'd have to define single API for generating USB trigger event, so as not enforce addition of three different API calls to the USB drivers. The type of USB events that the LED should react upon could be defined by parsing the value written to the sysfs file.
This of course implies, that we should have single LED USB port trigger.
The remaining issue is the sysfs interface design for defining and presenting multiple USB ports. I'm still in favour of a single attribute with space separated list. This scheme is commonly used in existing interfaces.
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 32 lines · Jacek Anaszewski
Quoted 32 lines
Quoted 8 lines
Quoted 8 lines
Maybe it would make more sense, in this case, to allow only three possibilities for a USB port activity trigger. Toggle the LED whenever:
There is activity on the specified port, or
There is any activity on any port on the specified hub, or
Quoted 8 lines
Quoted 4 lines
There is any USB activity on any port.
That ought to cover most of the normal use cases, and it would be simple enough to implement.
What would be the benefit of having a USB port activity trigger, for which we would be specifying the port to observe, but in the same time we would react on any activity on any port (cases 1 and 3)?
I meant these three cases to be mutually exclusive. For a given LED, you could have only one of those trigger types (like mentioned above, only one trigger per LED). For example, you might accept any one of:
echo usb1-4.2 >/sys/class/led/foo/trigger
echo hub1-4 >/sys/class/led/foo/trigger
echo usb >/sys/class/led/foo/trigger
Yes, it would be possible to have a port-specific trigger for one LED and an overall USB activity trigger for another LED. I don't know how useful this would be -- you could probably imagine some unlikely scenario.
Quoted 7 lines
Quoted 3 lines
The point is that doing things this way wouldn't require any API violations, and it would allow users to do almost all of the things they are likely to want.
We'd have to define single API for generating USB trigger event, so as not enforce addition of three different API calls to the USB drivers.
The USB core would need only one LED-API call, which it would make upon the completion of an URB. The trigger code should be able to handle all the rest (i.e., see which LEDs should be triggered by that URB).
Quoted 2 lines
The type of USB events that the LED should react upon could be
defined by parsing the value written to the sysfs file.
There is only one type of event: completion of an URB. Triggers would differ depending only on the device/port that the URB was aimed at. _That_ information could be defined by parsing the value written to the sysfs file.
Quoted 6 lines
This of course implies, that we should have single LED USB port trigger.
The remaining issue is the sysfs interface design for defining and presenting multiple USB ports. I'm still in favour of a single attribute with space separated list. This scheme is commonly used in existing interfaces.
No such interface is needed if you do things the way I outlined above. Each trigger would require the user to specify either one port, one hub, or nothing at all. Multiple ports would not be used.
Alan Stern
Quoted 34 lines · Alan Stern
Quoted 32 lines · Jacek Anaszewski
Quoted 32 lines
Quoted 8 lines
Quoted 8 lines
Maybe it would make more sense, in this case, to allow only three possibilities for a USB port activity trigger. Toggle the LED whenever:
There is activity on the specified port, or
There is any activity on any port on the specified hub, or
Quoted 8 lines
Quoted 4 lines
There is any USB activity on any port.
That ought to cover most of the normal use cases, and it would be simple enough to implement.
What would be the benefit of having a USB port activity trigger, for which we would be specifying the port to observe, but in the same time we would react on any activity on any port (cases 1 and 3)?
I meant these three cases to be mutually exclusive. For a given LED, you could have only one of those trigger types (like mentioned above, only one trigger per LED). For example, you might accept any one of:
echo usb1-4.2 >/sys/class/led/foo/trigger
echo hub1-4 >/sys/class/led/foo/trigger
echo usb >/sys/class/led/foo/trigger
Yes, it would be possible to have a port-specific trigger for one LED and an overall USB activity trigger for another LED. I don't know how useful this would be -- you could probably imagine some unlikely scenario.
Quoted 7 lines
Quoted 7 lines
Quoted 3 lines
The point is that doing things this way wouldn't require any API violations, and it would allow users to do almost all of the things they are likely to want.
We'd have to define single API for generating USB trigger event, so as not enforce addition of three different API calls to the USB drivers.
Of course this trigger represents yet another type of triggers, that don't require exposing an API for generating events, but instead register as listeners to some notifiers. I missed that initially.
Quoted 3 lines
The USB core would need only one LED-API call, which it would make upon the completion of an URB. The trigger code should be able to handle all the rest (i.e., see which LEDs should be triggered by that URB).
This is assured by the LED trigger core.
Quoted 11 lines
Quoted 3 lines
The type of USB events that the LED should react upon could be
defined by parsing the value written to the sysfs file.There is only one type of event: completion of an URB. Triggers would differ depending only on the device/port that the URB was aimed at. _That_ information could be defined by parsing the value written to the sysfs file.
Quoted 2 lines
This of course implies, that we should have single LED USB port trigger.
Quoted 8 lines
Quoted 4 lines
The remaining issue is the sysfs interface design for defining and presenting multiple USB ports. I'm still in favour of a single attribute with space separated list. This scheme is commonly used in existing interfaces.
No such interface is needed if you do things the way I outlined above. Each trigger would require the user to specify either one port, one hub, or nothing at all. Multiple ports would not be used.
The patch assumes that it is possible to register trigger for many ports.
Signature · 2 lines
Best regards, Jacek Anaszewski
Quoted 11 lines · Jacek Anaszewski
Quoted 8 lines
Quoted 4 lines
The remaining issue is the sysfs interface design for defining and presenting multiple USB ports. I'm still in favour of a single attribute with space separated list. This scheme is commonly used in existing interfaces.
No such interface is needed if you do things the way I outlined above. Each trigger would require the user to specify either one port, one hub, or nothing at all. Multiple ports would not be used.
The patch assumes that it is possible to register trigger for many ports.
The patch could be changed to remove that assumption.
Alan Stern
Quoted 7 lines · Alan Stern
Quoted 5 lines · Jacek Anaszewski
Quoted 5 lines
Quoted 4 lines
The remaining issue is the sysfs interface design for defining and presenting multiple USB ports. I'm still in favour of a single attribute with space separated list. This scheme is commonly used in existing interfaces.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
No such interface is needed if you do things the way I outlined above. Each trigger would require the user to specify either one port, one hub, or nothing at all. Multiple ports would not be used.
The patch assumes that it is possible to register trigger for many ports.
The patch could be changed to remove that assumption.
I did this assumption for a reason. There are many devices with more than 1 USB port and these ports are handled by the same controllers, just different ports. Let me share USB details of my SmartRG SR400ac device with 2 physical USB ports:
Physical USB 3.0 port is handled by following controllers and their root hub ports:
1) OHCI's port 1
2) EHCI's port 1
3) XHCI's port 1
Physical USB 2.0 port is handled by following controllers and their root hub ports:
1) OHCI's port 2
2) EHCI's port 2
This devices has 3 separated LEDs. I'll list them and tell which ports should be assigned to them:
bcm53xx:green:usb3 should have assigned:
1) OHCI's port 1
2) EHCI's port 1
bcm53xx:white:usb3 should have assigned:
1) XHCI's port 1
bcm53xx:white:usb2 should have assigned:
1) OHCI's port 2
2) EHCI's port 2
As you can see, I need to specify ports precisely. Assigning a single port is not enough. Assigning whole hub is too much. So none of:
Quoted 3 lines
echo usb1-4.2 >/sys/class/led/foo/trigger
echo hub1-4 >/sys/class/led/foo/trigger
echo usb >/sys/class/led/foo/trigger
would be sufficient here :(
Signature · 1 line
Rafał
Quoted 33 lines · Alan Stern
Quoted 26 lines · Rafał Miłecki
Quoted 12 lines
Quoted 11 lines
As you quite often need more complex LED management, there are triggers that were introduced in 2006 by
c3bc9956ec52f("[PATCH] LED:
add LED trigger tupport"). Some triggers are trivial and could be implemented in userspace as well (e.g. "timer"). Some had to be implemented in kernelspace (CPU activity, MTD activity, etc.). Having few triggers compiled, you can assign them to LEDs at it pleases you. Your hardware may have generic LED (not labeled) and you can dynamically assign various triggers to it, depending e.g. on user actions. E.g. if user (using GUI or whatever) wants to see flash activity, your userspace script should do:
echo mtd >/sys/class/leds/foo/triggerQuoted 6 lines
So for example, you might want to do:
echo usb1-4 >/sys/class/leds/foo/trigger
and then have the "foo" LED toggle whenever an URB was submitted or completed for a device attached to the 1-4 port. Right?
Not really as it won't cover some pretty common use cases. Many home routers have few USB ports (2-5) and only 1 USB LED. It has to be possible to assign few USB ports to a single LED (trigger). That way LED should be turned on (and kept on) if there is at least 1 USB device connected. You obviously can't do:
echo "usb1-1 usb1-2 usb2-1" >/sys/class/leds/foo/triggerQuoted 4 lines
This was already brought up by Rob (who mentioned CPU trigger) and I replied him pretty much the same way in:
https://lkml.org/lkml/2016/7/29/38
(reply starts with "Anyway, the serious limitation I see").
Quoted 5 lines
The code for a bunch of triggers must already be written. What would the user do if he wanted to flash a single LED in response to both CPU activity and MTD activity? If not
echo "cpu mtd" >/sys/class/leds/foo/trigger
Lets not overcomplicate this... What if user wanted to blink only when there's both cpu and mtd activity?
I mean, there are way too many possible combinations, but we should not implement everything. "Heartbeat" for example is nice demo and nice test case, but ...
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Hi!
Quoted 8 lines
This commit adds a new trigger responsible for turning on LED when USB device gets connected to the specified USB port. This can can useful for various home routers that have USB port(s) and a proper LED telling user a device is connected.
The trigger gets its documentation file but basically it just requires specifying USB port in a Linux format (e.g. echo 1-1 >
new_port).
Quoted 8 lines
During work on this trigger there was a plan to add DT bindings for it, but there wasn't an agreement on the format yet. This can be worked on later, a sysfs interface is needed anyway for platforms not using DT.
Another planned feature is support for LED reacting to the USB activity. This can be implemented with another sysfs file for setting mode. The default mode wouldn't change so there won't be ABI breakage and such feature can be safely implemented later.
Actually... USB device plugs/unplugs are pretty rare events... Can we just do this in userspace using udevd?
Pavel
Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html