Collisions on link does not fit into one of the existing netdev triggers. Add TRIGGER_NETDEV_COLLISION in the enum led_trigger_netdev_modes. Add its definition in Documentation. Add its handling in ledtrig-netdev, it can only be supported by hardware so no software fallback is implemented. Signed-off-by: Bastien Curutchet <bastien.curutchet@xxxxxxxxxxx> --- .../ABI/testing/sysfs-class-led-trigger-netdev | 11 +++++++++++ drivers/leds/trigger/ledtrig-netdev.c | 4 ++++ include/linux/leds.h | 1 + 3 files changed, 16 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev index a6c307c4befa..fbb2bc1d6108 100644 --- a/Documentation/ABI/testing/sysfs-class-led-trigger-netdev +++ b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev @@ -178,3 +178,14 @@ Description: If set to 1, the LED's normal state reflects the link full duplex state of the named network device. Setting this value also immediately changes the LED state. + +What: /sys/class/leds/<led>/collision +Date: Feb 2024 +KernelVersion: 6.8 +Contact: linux-leds@xxxxxxxxxxxxxxx +Description: + Signal collision of the named network device. + + If set to 0 (default), the LED's normal state is off. + + If set to 1, the LED's normal state reflects collisions. diff --git a/drivers/leds/trigger/ledtrig-netdev.c b/drivers/leds/trigger/ledtrig-netdev.c index 8e5475819590..5c17b8e27d5c 100644 --- a/drivers/leds/trigger/ledtrig-netdev.c +++ b/drivers/leds/trigger/ledtrig-netdev.c @@ -318,6 +318,7 @@ static ssize_t netdev_led_attr_show(struct device *dev, char *buf, case TRIGGER_NETDEV_FULL_DUPLEX: case TRIGGER_NETDEV_TX: case TRIGGER_NETDEV_RX: + case TRIGGER_NETDEV_COLLISION: bit = attr; break; default: @@ -352,6 +353,7 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, case TRIGGER_NETDEV_FULL_DUPLEX: case TRIGGER_NETDEV_TX: case TRIGGER_NETDEV_RX: + case TRIGGER_NETDEV_COLLISION: bit = attr; break; default: @@ -410,6 +412,7 @@ DEFINE_NETDEV_TRIGGER(half_duplex, TRIGGER_NETDEV_HALF_DUPLEX); DEFINE_NETDEV_TRIGGER(full_duplex, TRIGGER_NETDEV_FULL_DUPLEX); DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX); DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX); +DEFINE_NETDEV_TRIGGER(collision, TRIGGER_NETDEV_COLLISION); static ssize_t interval_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -473,6 +476,7 @@ static struct attribute *netdev_trig_attrs[] = { &dev_attr_tx.attr, &dev_attr_interval.attr, &dev_attr_offloaded.attr, + &dev_attr_collision.attr, NULL }; ATTRIBUTE_GROUPS(netdev_trig); diff --git a/include/linux/leds.h b/include/linux/leds.h index 4754b02d3a2c..8864d6ce8185 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -578,6 +578,7 @@ enum led_trigger_netdev_modes { TRIGGER_NETDEV_FULL_DUPLEX, TRIGGER_NETDEV_TX, TRIGGER_NETDEV_RX, + TRIGGER_NETDEV_COLLISION, /* Keep last */ __TRIGGER_NETDEV_MAX, -- 2.43.0