From aa3b6a08c5616fdebd3b219f021a9674533a6519 Mon Sep 17 00:00:00 2001 From: Hauke Mehrtens Date: Wed, 14 Nov 2018 21:22:39 +0100 Subject: [PATCH] kernel: Replace ledtrig-netdev with upstream backport The ledtrig-netdev was added to upstream Linux kernel 4.16, replace our own version with the patch based on the upstream version. This will remove the ledtrig-netdev support from kernel 3.18, because I not want to spend time on backporting it to 3.18. This will make it easier to use the upstream version with kernel 4.19, by just not applying this patch. Signed-off-by: Hauke Mehrtens --- package/kernel/linux/modules/leds.mk | 2 +- .../009-adm5120_leds_switch_trigger.patch | 4 +- ...s-trigger-Introduce-a-NETDEV-trigger.patch | 588 ++++++++++++++++++ ...s-trigger-Introduce-a-NETDEV-trigger.patch | 588 ++++++++++++++++++ .../files/drivers/leds/ledtrig-netdev.c | 444 ------------- .../pending-3.18/831-ledtrig_netdev.patch | 21 - .../pending-4.14/831-ledtrig_netdev.patch | 74 --- .../pending-4.9/831-ledtrig_netdev.patch | 74 --- 8 files changed, 1179 insertions(+), 616 deletions(-) create mode 100644 target/linux/generic/backport-4.14/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch create mode 100644 target/linux/generic/backport-4.9/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch delete mode 100644 target/linux/generic/files/drivers/leds/ledtrig-netdev.c delete mode 100644 target/linux/generic/pending-3.18/831-ledtrig_netdev.patch delete mode 100644 target/linux/generic/pending-4.14/831-ledtrig_netdev.patch delete mode 100644 target/linux/generic/pending-4.9/831-ledtrig_netdev.patch diff --git a/package/kernel/linux/modules/leds.mk b/package/kernel/linux/modules/leds.mk index 7019f04779..59ea6edbcd 100644 --- a/package/kernel/linux/modules/leds.mk +++ b/package/kernel/linux/modules/leds.mk @@ -58,7 +58,7 @@ define KernelPackage/ledtrig-netdev SUBMENU:=$(LEDS_MENU) TITLE:=LED NETDEV Trigger KCONFIG:=CONFIG_LEDS_TRIGGER_NETDEV - FILES:=$(LINUX_DIR)/drivers/leds/ledtrig-netdev.ko + FILES:=$(LINUX_DIR)/drivers/leds/trigger/ledtrig-netdev.ko AUTOLOAD:=$(call AutoLoad,50,ledtrig-netdev) endef diff --git a/target/linux/adm5120/patches-3.18/009-adm5120_leds_switch_trigger.patch b/target/linux/adm5120/patches-3.18/009-adm5120_leds_switch_trigger.patch index f6dbdfc87d..4e37616f81 100644 --- a/target/linux/adm5120/patches-3.18/009-adm5120_leds_switch_trigger.patch +++ b/target/linux/adm5120/patches-3.18/009-adm5120_leds_switch_trigger.patch @@ -15,8 +15,8 @@ endif # NEW_LEDS --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile -@@ -63,3 +63,4 @@ obj-$(CONFIG_LEDS_DAC124S085) += leds-d +@@ -62,3 +62,4 @@ obj-$(CONFIG_LEDS_DAC124S085) += leds-d + # LED Triggers obj-$(CONFIG_LEDS_TRIGGERS) += trigger/ - obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o +obj-$(CONFIG_LEDS_TRIGGER_ADM5120_SWITCH) += ledtrig-adm5120-switch.o diff --git a/target/linux/generic/backport-4.14/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch b/target/linux/generic/backport-4.14/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch new file mode 100644 index 0000000000..b7d680a11b --- /dev/null +++ b/target/linux/generic/backport-4.14/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch @@ -0,0 +1,588 @@ +From 06f502f57d0d7728f9fa0f157ec5e4111ddb98f6 Mon Sep 17 00:00:00 2001 +From: Ben Whitten +Date: Sun, 10 Dec 2017 21:17:55 +0000 +Subject: [PATCH] leds: trigger: Introduce a NETDEV trigger + +This commit introduces a NETDEV trigger for named device +activity. Available triggers are link, rx, and tx. + +Signed-off-by: Ben Whitten +Acked-by: Pavel Machek +Signed-off-by: Jacek Anaszewski +--- + .../ABI/testing/sysfs-class-led-trigger-netdev | 45 ++ + drivers/leds/trigger/Kconfig | 7 + + drivers/leds/trigger/Makefile | 1 + + drivers/leds/trigger/ledtrig-netdev.c | 496 +++++++++++++++++++++ + 4 files changed, 549 insertions(+) + create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-netdev + create mode 100644 drivers/leds/trigger/ledtrig-netdev.c + +--- /dev/null ++++ b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev +@@ -0,0 +1,45 @@ ++What: /sys/class/leds//device_name ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Specifies the network device name to monitor. ++ ++What: /sys/class/leds//interval ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Specifies the duration of the LED blink in milliseconds. ++ Defaults to 50 ms. ++ ++What: /sys/class/leds//link ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Signal the link state 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 the link state ++ of the named network device. ++ Setting this value also immediately changes the LED state. ++ ++What: /sys/class/leds//tx ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Signal transmission of data on the named network device. ++ If set to 0 (default), the LED will not blink on transmission. ++ If set to 1, the LED will blink for the milliseconds specified ++ in interval to signal transmission. ++ ++What: /sys/class/leds//rx ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Signal reception of data on the named network device. ++ If set to 0 (default), the LED will not blink on reception. ++ If set to 1, the LED will blink for the milliseconds specified ++ in interval to signal reception. +--- a/drivers/leds/trigger/Kconfig ++++ b/drivers/leds/trigger/Kconfig +@@ -126,4 +126,11 @@ config LEDS_TRIGGER_PANIC + a different trigger. + If unsure, say Y. + ++config LEDS_TRIGGER_NETDEV ++ tristate "LED Netdev Trigger" ++ depends on NET && LEDS_TRIGGERS ++ help ++ This allows LEDs to be controlled by network device activity. ++ If unsure, say Y. ++ + endif # LEDS_TRIGGERS +--- a/drivers/leds/trigger/Makefile ++++ b/drivers/leds/trigger/Makefile +@@ -11,3 +11,4 @@ obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += + 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_NETDEV) += ledtrig-netdev.o +--- /dev/null ++++ b/drivers/leds/trigger/ledtrig-netdev.c +@@ -0,0 +1,496 @@ ++// SPDX-License-Identifier: GPL-2.0 ++// Copyright 2017 Ben Whitten ++// Copyright 2007 Oliver Jowett ++// ++// LED Kernel Netdev Trigger ++// ++// Toggles the LED to reflect the link and traffic state of a named net device ++// ++// Derived from ledtrig-timer.c which is: ++// Copyright 2005-2006 Openedhand Ltd. ++// Author: Richard Purdie ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "../leds.h" ++ ++/* ++ * Configurable sysfs attributes: ++ * ++ * device_name - network device name to monitor ++ * interval - duration of LED blink, in milliseconds ++ * link - LED's normal state reflects whether the link is up ++ * (has carrier) or not ++ * tx - LED blinks on transmitted data ++ * rx - LED blinks on receive data ++ * ++ */ ++ ++struct led_netdev_data { ++ spinlock_t lock; ++ ++ struct delayed_work work; ++ struct notifier_block notifier; ++ ++ struct led_classdev *led_cdev; ++ struct net_device *net_dev; ++ ++ char device_name[IFNAMSIZ]; ++ atomic_t interval; ++ unsigned int last_activity; ++ ++ unsigned long mode; ++#define NETDEV_LED_LINK 0 ++#define NETDEV_LED_TX 1 ++#define NETDEV_LED_RX 2 ++#define NETDEV_LED_MODE_LINKUP 3 ++}; ++ ++enum netdev_led_attr { ++ NETDEV_ATTR_LINK, ++ NETDEV_ATTR_TX, ++ NETDEV_ATTR_RX ++}; ++ ++static void set_baseline_state(struct led_netdev_data *trigger_data) ++{ ++ int current_brightness; ++ struct led_classdev *led_cdev = trigger_data->led_cdev; ++ ++ current_brightness = led_cdev->brightness; ++ if (current_brightness) ++ led_cdev->blink_brightness = current_brightness; ++ if (!led_cdev->blink_brightness) ++ led_cdev->blink_brightness = led_cdev->max_brightness; ++ ++ if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode)) ++ led_set_brightness(led_cdev, LED_OFF); ++ else { ++ if (test_bit(NETDEV_LED_LINK, &trigger_data->mode)) ++ led_set_brightness(led_cdev, ++ led_cdev->blink_brightness); ++ else ++ led_set_brightness(led_cdev, LED_OFF); ++ ++ /* If we are looking for RX/TX start periodically ++ * checking stats ++ */ ++ if (test_bit(NETDEV_LED_TX, &trigger_data->mode) || ++ test_bit(NETDEV_LED_RX, &trigger_data->mode)) ++ schedule_delayed_work(&trigger_data->work, 0); ++ } ++} ++ ++static ssize_t device_name_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ssize_t len; ++ ++ spin_lock_bh(&trigger_data->lock); ++ len = sprintf(buf, "%s\n", trigger_data->device_name); ++ spin_unlock_bh(&trigger_data->lock); ++ ++ return len; ++} ++ ++static ssize_t device_name_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, ++ size_t size) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ++ if (size >= IFNAMSIZ) ++ return -EINVAL; ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ spin_lock_bh(&trigger_data->lock); ++ ++ if (trigger_data->net_dev) { ++ dev_put(trigger_data->net_dev); ++ trigger_data->net_dev = NULL; ++ } ++ ++ strncpy(trigger_data->device_name, buf, size); ++ if (size > 0 && trigger_data->device_name[size - 1] == '\n') ++ trigger_data->device_name[size - 1] = 0; ++ ++ if (trigger_data->device_name[0] != 0) ++ trigger_data->net_dev = ++ dev_get_by_name(&init_net, trigger_data->device_name); ++ ++ clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ if (trigger_data->net_dev != NULL) ++ if (netif_carrier_ok(trigger_data->net_dev)) ++ set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ ++ trigger_data->last_activity = 0; ++ ++ set_baseline_state(trigger_data); ++ spin_unlock_bh(&trigger_data->lock); ++ ++ return size; ++} ++ ++static DEVICE_ATTR_RW(device_name); ++ ++static ssize_t netdev_led_attr_show(struct device *dev, char *buf, ++ enum netdev_led_attr attr) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ int bit; ++ ++ switch (attr) { ++ case NETDEV_ATTR_LINK: ++ bit = NETDEV_LED_LINK; ++ break; ++ case NETDEV_ATTR_TX: ++ bit = NETDEV_LED_TX; ++ break; ++ case NETDEV_ATTR_RX: ++ bit = NETDEV_LED_RX; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ return sprintf(buf, "%u\n", test_bit(bit, &trigger_data->mode)); ++} ++ ++static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, ++ size_t size, enum netdev_led_attr attr) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ unsigned long state; ++ int ret; ++ int bit; ++ ++ ret = kstrtoul(buf, 0, &state); ++ if (ret) ++ return ret; ++ ++ switch (attr) { ++ case NETDEV_ATTR_LINK: ++ bit = NETDEV_LED_LINK; ++ break; ++ case NETDEV_ATTR_TX: ++ bit = NETDEV_LED_TX; ++ break; ++ case NETDEV_ATTR_RX: ++ bit = NETDEV_LED_RX; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ if (state) ++ set_bit(bit, &trigger_data->mode); ++ else ++ clear_bit(bit, &trigger_data->mode); ++ ++ set_baseline_state(trigger_data); ++ ++ return size; ++} ++ ++static ssize_t link_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK); ++} ++ ++static ssize_t link_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, size_t size) ++{ ++ return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK); ++} ++ ++static DEVICE_ATTR_RW(link); ++ ++static ssize_t tx_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX); ++} ++ ++static ssize_t tx_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, size_t size) ++{ ++ return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX); ++} ++ ++static DEVICE_ATTR_RW(tx); ++ ++static ssize_t rx_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX); ++} ++ ++static ssize_t rx_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, size_t size) ++{ ++ return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX); ++} ++ ++static DEVICE_ATTR_RW(rx); ++ ++static ssize_t interval_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ++ return sprintf(buf, "%u\n", ++ jiffies_to_msecs(atomic_read(&trigger_data->interval))); ++} ++ ++static ssize_t interval_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, ++ size_t size) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ unsigned long value; ++ int ret; ++ ++ ret = kstrtoul(buf, 0, &value); ++ if (ret) ++ return ret; ++ ++ /* impose some basic bounds on the timer interval */ ++ if (value >= 5 && value <= 10000) { ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ atomic_set(&trigger_data->interval, msecs_to_jiffies(value)); ++ set_baseline_state(trigger_data); /* resets timer */ ++ } ++ ++ return size; ++} ++ ++static DEVICE_ATTR_RW(interval); ++ ++static int netdev_trig_notify(struct notifier_block *nb, ++ unsigned long evt, void *dv) ++{ ++ struct net_device *dev = ++ netdev_notifier_info_to_dev((struct netdev_notifier_info *)dv); ++ struct led_netdev_data *trigger_data = container_of(nb, ++ struct ++ led_netdev_data, ++ notifier); ++ ++ if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE ++ && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER ++ && evt != NETDEV_CHANGENAME) ++ return NOTIFY_DONE; ++ ++ if (strcmp(dev->name, trigger_data->device_name)) ++ return NOTIFY_DONE; ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ spin_lock_bh(&trigger_data->lock); ++ ++ clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ switch (evt) { ++ case NETDEV_REGISTER: ++ if (trigger_data->net_dev) ++ dev_put(trigger_data->net_dev); ++ dev_hold(dev); ++ trigger_data->net_dev = dev; ++ break; ++ case NETDEV_CHANGENAME: ++ case NETDEV_UNREGISTER: ++ if (trigger_data->net_dev) { ++ dev_put(trigger_data->net_dev); ++ trigger_data->net_dev = NULL; ++ } ++ break; ++ case NETDEV_UP: ++ case NETDEV_CHANGE: ++ if (netif_carrier_ok(dev)) ++ set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ break; ++ } ++ ++ set_baseline_state(trigger_data); ++ ++ spin_unlock_bh(&trigger_data->lock); ++ ++ return NOTIFY_DONE; ++} ++ ++/* here's the real work! */ ++static void netdev_trig_work(struct work_struct *work) ++{ ++ struct led_netdev_data *trigger_data = container_of(work, ++ struct ++ led_netdev_data, ++ work.work); ++ struct rtnl_link_stats64 *dev_stats; ++ unsigned int new_activity; ++ struct rtnl_link_stats64 temp; ++ unsigned long interval; ++ int invert; ++ ++ /* If we dont have a device, insure we are off */ ++ if (!trigger_data->net_dev) { ++ led_set_brightness(trigger_data->led_cdev, LED_OFF); ++ return; ++ } ++ ++ /* If we are not looking for RX/TX then return */ ++ if (!test_bit(NETDEV_LED_TX, &trigger_data->mode) && ++ !test_bit(NETDEV_LED_RX, &trigger_data->mode)) ++ return; ++ ++ dev_stats = dev_get_stats(trigger_data->net_dev, &temp); ++ new_activity = ++ (test_bit(NETDEV_LED_TX, &trigger_data->mode) ? ++ dev_stats->tx_packets : 0) + ++ (test_bit(NETDEV_LED_RX, &trigger_data->mode) ? ++ dev_stats->rx_packets : 0); ++ ++ if (trigger_data->last_activity != new_activity) { ++ led_stop_software_blink(trigger_data->led_cdev); ++ ++ invert = test_bit(NETDEV_LED_LINK, &trigger_data->mode); ++ interval = jiffies_to_msecs( ++ atomic_read(&trigger_data->interval)); ++ /* base state is ON (link present) */ ++ led_blink_set_oneshot(trigger_data->led_cdev, ++ &interval, ++ &interval, ++ invert); ++ trigger_data->last_activity = new_activity; ++ } ++ ++ schedule_delayed_work(&trigger_data->work, ++ (atomic_read(&trigger_data->interval)*2)); ++} ++ ++static void netdev_trig_activate(struct led_classdev *led_cdev) ++{ ++ struct led_netdev_data *trigger_data; ++ int rc; ++ ++ trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); ++ if (!trigger_data) ++ return; ++ ++ spin_lock_init(&trigger_data->lock); ++ ++ trigger_data->notifier.notifier_call = netdev_trig_notify; ++ trigger_data->notifier.priority = 10; ++ ++ INIT_DELAYED_WORK(&trigger_data->work, netdev_trig_work); ++ ++ trigger_data->led_cdev = led_cdev; ++ trigger_data->net_dev = NULL; ++ trigger_data->device_name[0] = 0; ++ ++ trigger_data->mode = 0; ++ atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); ++ trigger_data->last_activity = 0; ++ ++ led_cdev->trigger_data = trigger_data; ++ ++ rc = device_create_file(led_cdev->dev, &dev_attr_device_name); ++ if (rc) ++ goto err_out; ++ rc = device_create_file(led_cdev->dev, &dev_attr_link); ++ if (rc) ++ goto err_out_device_name; ++ rc = device_create_file(led_cdev->dev, &dev_attr_rx); ++ if (rc) ++ goto err_out_link; ++ rc = device_create_file(led_cdev->dev, &dev_attr_tx); ++ if (rc) ++ goto err_out_rx; ++ rc = device_create_file(led_cdev->dev, &dev_attr_interval); ++ if (rc) ++ goto err_out_tx; ++ rc = register_netdevice_notifier(&trigger_data->notifier); ++ if (rc) ++ goto err_out_interval; ++ return; ++ ++err_out_interval: ++ device_remove_file(led_cdev->dev, &dev_attr_interval); ++err_out_tx: ++ device_remove_file(led_cdev->dev, &dev_attr_tx); ++err_out_rx: ++ device_remove_file(led_cdev->dev, &dev_attr_rx); ++err_out_link: ++ device_remove_file(led_cdev->dev, &dev_attr_link); ++err_out_device_name: ++ device_remove_file(led_cdev->dev, &dev_attr_device_name); ++err_out: ++ led_cdev->trigger_data = NULL; ++ kfree(trigger_data); ++} ++ ++static void netdev_trig_deactivate(struct led_classdev *led_cdev) ++{ ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ++ if (trigger_data) { ++ unregister_netdevice_notifier(&trigger_data->notifier); ++ ++ device_remove_file(led_cdev->dev, &dev_attr_device_name); ++ device_remove_file(led_cdev->dev, &dev_attr_link); ++ device_remove_file(led_cdev->dev, &dev_attr_rx); ++ device_remove_file(led_cdev->dev, &dev_attr_tx); ++ device_remove_file(led_cdev->dev, &dev_attr_interval); ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ if (trigger_data->net_dev) ++ dev_put(trigger_data->net_dev); ++ ++ kfree(trigger_data); ++ } ++} ++ ++static struct led_trigger netdev_led_trigger = { ++ .name = "netdev", ++ .activate = netdev_trig_activate, ++ .deactivate = netdev_trig_deactivate, ++}; ++ ++static int __init netdev_trig_init(void) ++{ ++ return led_trigger_register(&netdev_led_trigger); ++} ++ ++static void __exit netdev_trig_exit(void) ++{ ++ led_trigger_unregister(&netdev_led_trigger); ++} ++ ++module_init(netdev_trig_init); ++module_exit(netdev_trig_exit); ++ ++MODULE_AUTHOR("Ben Whitten "); ++MODULE_AUTHOR("Oliver Jowett "); ++MODULE_DESCRIPTION("Netdev LED trigger"); ++MODULE_LICENSE("GPL v2"); diff --git a/target/linux/generic/backport-4.9/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch b/target/linux/generic/backport-4.9/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch new file mode 100644 index 0000000000..bd58df63c0 --- /dev/null +++ b/target/linux/generic/backport-4.9/400-v4.16-leds-trigger-Introduce-a-NETDEV-trigger.patch @@ -0,0 +1,588 @@ +From 06f502f57d0d7728f9fa0f157ec5e4111ddb98f6 Mon Sep 17 00:00:00 2001 +From: Ben Whitten +Date: Sun, 10 Dec 2017 21:17:55 +0000 +Subject: [PATCH] leds: trigger: Introduce a NETDEV trigger + +This commit introduces a NETDEV trigger for named device +activity. Available triggers are link, rx, and tx. + +Signed-off-by: Ben Whitten +Acked-by: Pavel Machek +Signed-off-by: Jacek Anaszewski +--- + .../ABI/testing/sysfs-class-led-trigger-netdev | 45 ++ + drivers/leds/trigger/Kconfig | 7 + + drivers/leds/trigger/Makefile | 1 + + drivers/leds/trigger/ledtrig-netdev.c | 496 +++++++++++++++++++++ + 4 files changed, 549 insertions(+) + create mode 100644 Documentation/ABI/testing/sysfs-class-led-trigger-netdev + create mode 100644 drivers/leds/trigger/ledtrig-netdev.c + +--- /dev/null ++++ b/Documentation/ABI/testing/sysfs-class-led-trigger-netdev +@@ -0,0 +1,45 @@ ++What: /sys/class/leds//device_name ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Specifies the network device name to monitor. ++ ++What: /sys/class/leds//interval ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Specifies the duration of the LED blink in milliseconds. ++ Defaults to 50 ms. ++ ++What: /sys/class/leds//link ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Signal the link state 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 the link state ++ of the named network device. ++ Setting this value also immediately changes the LED state. ++ ++What: /sys/class/leds//tx ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Signal transmission of data on the named network device. ++ If set to 0 (default), the LED will not blink on transmission. ++ If set to 1, the LED will blink for the milliseconds specified ++ in interval to signal transmission. ++ ++What: /sys/class/leds//rx ++Date: Dec 2017 ++KernelVersion: 4.16 ++Contact: linux-leds@vger.kernel.org ++Description: ++ Signal reception of data on the named network device. ++ If set to 0 (default), the LED will not blink on reception. ++ If set to 1, the LED will blink for the milliseconds specified ++ in interval to signal reception. +--- a/drivers/leds/trigger/Kconfig ++++ b/drivers/leds/trigger/Kconfig +@@ -126,4 +126,11 @@ config LEDS_TRIGGER_PANIC + a different trigger. + If unsure, say Y. + ++config LEDS_TRIGGER_NETDEV ++ tristate "LED Netdev Trigger" ++ depends on NET && LEDS_TRIGGERS ++ help ++ This allows LEDs to be controlled by network device activity. ++ If unsure, say Y. ++ + endif # LEDS_TRIGGERS +--- a/drivers/leds/trigger/Makefile ++++ b/drivers/leds/trigger/Makefile +@@ -10,3 +10,4 @@ obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += + 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_NETDEV) += ledtrig-netdev.o +--- /dev/null ++++ b/drivers/leds/trigger/ledtrig-netdev.c +@@ -0,0 +1,496 @@ ++// SPDX-License-Identifier: GPL-2.0 ++// Copyright 2017 Ben Whitten ++// Copyright 2007 Oliver Jowett ++// ++// LED Kernel Netdev Trigger ++// ++// Toggles the LED to reflect the link and traffic state of a named net device ++// ++// Derived from ledtrig-timer.c which is: ++// Copyright 2005-2006 Openedhand Ltd. ++// Author: Richard Purdie ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "../leds.h" ++ ++/* ++ * Configurable sysfs attributes: ++ * ++ * device_name - network device name to monitor ++ * interval - duration of LED blink, in milliseconds ++ * link - LED's normal state reflects whether the link is up ++ * (has carrier) or not ++ * tx - LED blinks on transmitted data ++ * rx - LED blinks on receive data ++ * ++ */ ++ ++struct led_netdev_data { ++ spinlock_t lock; ++ ++ struct delayed_work work; ++ struct notifier_block notifier; ++ ++ struct led_classdev *led_cdev; ++ struct net_device *net_dev; ++ ++ char device_name[IFNAMSIZ]; ++ atomic_t interval; ++ unsigned int last_activity; ++ ++ unsigned long mode; ++#define NETDEV_LED_LINK 0 ++#define NETDEV_LED_TX 1 ++#define NETDEV_LED_RX 2 ++#define NETDEV_LED_MODE_LINKUP 3 ++}; ++ ++enum netdev_led_attr { ++ NETDEV_ATTR_LINK, ++ NETDEV_ATTR_TX, ++ NETDEV_ATTR_RX ++}; ++ ++static void set_baseline_state(struct led_netdev_data *trigger_data) ++{ ++ int current_brightness; ++ struct led_classdev *led_cdev = trigger_data->led_cdev; ++ ++ current_brightness = led_cdev->brightness; ++ if (current_brightness) ++ led_cdev->blink_brightness = current_brightness; ++ if (!led_cdev->blink_brightness) ++ led_cdev->blink_brightness = led_cdev->max_brightness; ++ ++ if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode)) ++ led_set_brightness(led_cdev, LED_OFF); ++ else { ++ if (test_bit(NETDEV_LED_LINK, &trigger_data->mode)) ++ led_set_brightness(led_cdev, ++ led_cdev->blink_brightness); ++ else ++ led_set_brightness(led_cdev, LED_OFF); ++ ++ /* If we are looking for RX/TX start periodically ++ * checking stats ++ */ ++ if (test_bit(NETDEV_LED_TX, &trigger_data->mode) || ++ test_bit(NETDEV_LED_RX, &trigger_data->mode)) ++ schedule_delayed_work(&trigger_data->work, 0); ++ } ++} ++ ++static ssize_t device_name_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ssize_t len; ++ ++ spin_lock_bh(&trigger_data->lock); ++ len = sprintf(buf, "%s\n", trigger_data->device_name); ++ spin_unlock_bh(&trigger_data->lock); ++ ++ return len; ++} ++ ++static ssize_t device_name_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, ++ size_t size) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ++ if (size >= IFNAMSIZ) ++ return -EINVAL; ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ spin_lock_bh(&trigger_data->lock); ++ ++ if (trigger_data->net_dev) { ++ dev_put(trigger_data->net_dev); ++ trigger_data->net_dev = NULL; ++ } ++ ++ strncpy(trigger_data->device_name, buf, size); ++ if (size > 0 && trigger_data->device_name[size - 1] == '\n') ++ trigger_data->device_name[size - 1] = 0; ++ ++ if (trigger_data->device_name[0] != 0) ++ trigger_data->net_dev = ++ dev_get_by_name(&init_net, trigger_data->device_name); ++ ++ clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ if (trigger_data->net_dev != NULL) ++ if (netif_carrier_ok(trigger_data->net_dev)) ++ set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ ++ trigger_data->last_activity = 0; ++ ++ set_baseline_state(trigger_data); ++ spin_unlock_bh(&trigger_data->lock); ++ ++ return size; ++} ++ ++static DEVICE_ATTR_RW(device_name); ++ ++static ssize_t netdev_led_attr_show(struct device *dev, char *buf, ++ enum netdev_led_attr attr) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ int bit; ++ ++ switch (attr) { ++ case NETDEV_ATTR_LINK: ++ bit = NETDEV_LED_LINK; ++ break; ++ case NETDEV_ATTR_TX: ++ bit = NETDEV_LED_TX; ++ break; ++ case NETDEV_ATTR_RX: ++ bit = NETDEV_LED_RX; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ return sprintf(buf, "%u\n", test_bit(bit, &trigger_data->mode)); ++} ++ ++static ssize_t netdev_led_attr_store(struct device *dev, const char *buf, ++ size_t size, enum netdev_led_attr attr) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ unsigned long state; ++ int ret; ++ int bit; ++ ++ ret = kstrtoul(buf, 0, &state); ++ if (ret) ++ return ret; ++ ++ switch (attr) { ++ case NETDEV_ATTR_LINK: ++ bit = NETDEV_LED_LINK; ++ break; ++ case NETDEV_ATTR_TX: ++ bit = NETDEV_LED_TX; ++ break; ++ case NETDEV_ATTR_RX: ++ bit = NETDEV_LED_RX; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ if (state) ++ set_bit(bit, &trigger_data->mode); ++ else ++ clear_bit(bit, &trigger_data->mode); ++ ++ set_baseline_state(trigger_data); ++ ++ return size; ++} ++ ++static ssize_t link_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ return netdev_led_attr_show(dev, buf, NETDEV_ATTR_LINK); ++} ++ ++static ssize_t link_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, size_t size) ++{ ++ return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_LINK); ++} ++ ++static DEVICE_ATTR_RW(link); ++ ++static ssize_t tx_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ return netdev_led_attr_show(dev, buf, NETDEV_ATTR_TX); ++} ++ ++static ssize_t tx_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, size_t size) ++{ ++ return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_TX); ++} ++ ++static DEVICE_ATTR_RW(tx); ++ ++static ssize_t rx_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ return netdev_led_attr_show(dev, buf, NETDEV_ATTR_RX); ++} ++ ++static ssize_t rx_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, size_t size) ++{ ++ return netdev_led_attr_store(dev, buf, size, NETDEV_ATTR_RX); ++} ++ ++static DEVICE_ATTR_RW(rx); ++ ++static ssize_t interval_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ++ return sprintf(buf, "%u\n", ++ jiffies_to_msecs(atomic_read(&trigger_data->interval))); ++} ++ ++static ssize_t interval_store(struct device *dev, ++ struct device_attribute *attr, const char *buf, ++ size_t size) ++{ ++ struct led_classdev *led_cdev = dev_get_drvdata(dev); ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ unsigned long value; ++ int ret; ++ ++ ret = kstrtoul(buf, 0, &value); ++ if (ret) ++ return ret; ++ ++ /* impose some basic bounds on the timer interval */ ++ if (value >= 5 && value <= 10000) { ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ atomic_set(&trigger_data->interval, msecs_to_jiffies(value)); ++ set_baseline_state(trigger_data); /* resets timer */ ++ } ++ ++ return size; ++} ++ ++static DEVICE_ATTR_RW(interval); ++ ++static int netdev_trig_notify(struct notifier_block *nb, ++ unsigned long evt, void *dv) ++{ ++ struct net_device *dev = ++ netdev_notifier_info_to_dev((struct netdev_notifier_info *)dv); ++ struct led_netdev_data *trigger_data = container_of(nb, ++ struct ++ led_netdev_data, ++ notifier); ++ ++ if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE ++ && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER ++ && evt != NETDEV_CHANGENAME) ++ return NOTIFY_DONE; ++ ++ if (strcmp(dev->name, trigger_data->device_name)) ++ return NOTIFY_DONE; ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ spin_lock_bh(&trigger_data->lock); ++ ++ clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ switch (evt) { ++ case NETDEV_REGISTER: ++ if (trigger_data->net_dev) ++ dev_put(trigger_data->net_dev); ++ dev_hold(dev); ++ trigger_data->net_dev = dev; ++ break; ++ case NETDEV_CHANGENAME: ++ case NETDEV_UNREGISTER: ++ if (trigger_data->net_dev) { ++ dev_put(trigger_data->net_dev); ++ trigger_data->net_dev = NULL; ++ } ++ break; ++ case NETDEV_UP: ++ case NETDEV_CHANGE: ++ if (netif_carrier_ok(dev)) ++ set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode); ++ break; ++ } ++ ++ set_baseline_state(trigger_data); ++ ++ spin_unlock_bh(&trigger_data->lock); ++ ++ return NOTIFY_DONE; ++} ++ ++/* here's the real work! */ ++static void netdev_trig_work(struct work_struct *work) ++{ ++ struct led_netdev_data *trigger_data = container_of(work, ++ struct ++ led_netdev_data, ++ work.work); ++ struct rtnl_link_stats64 *dev_stats; ++ unsigned int new_activity; ++ struct rtnl_link_stats64 temp; ++ unsigned long interval; ++ int invert; ++ ++ /* If we dont have a device, insure we are off */ ++ if (!trigger_data->net_dev) { ++ led_set_brightness(trigger_data->led_cdev, LED_OFF); ++ return; ++ } ++ ++ /* If we are not looking for RX/TX then return */ ++ if (!test_bit(NETDEV_LED_TX, &trigger_data->mode) && ++ !test_bit(NETDEV_LED_RX, &trigger_data->mode)) ++ return; ++ ++ dev_stats = dev_get_stats(trigger_data->net_dev, &temp); ++ new_activity = ++ (test_bit(NETDEV_LED_TX, &trigger_data->mode) ? ++ dev_stats->tx_packets : 0) + ++ (test_bit(NETDEV_LED_RX, &trigger_data->mode) ? ++ dev_stats->rx_packets : 0); ++ ++ if (trigger_data->last_activity != new_activity) { ++ led_stop_software_blink(trigger_data->led_cdev); ++ ++ invert = test_bit(NETDEV_LED_LINK, &trigger_data->mode); ++ interval = jiffies_to_msecs( ++ atomic_read(&trigger_data->interval)); ++ /* base state is ON (link present) */ ++ led_blink_set_oneshot(trigger_data->led_cdev, ++ &interval, ++ &interval, ++ invert); ++ trigger_data->last_activity = new_activity; ++ } ++ ++ schedule_delayed_work(&trigger_data->work, ++ (atomic_read(&trigger_data->interval)*2)); ++} ++ ++static void netdev_trig_activate(struct led_classdev *led_cdev) ++{ ++ struct led_netdev_data *trigger_data; ++ int rc; ++ ++ trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); ++ if (!trigger_data) ++ return; ++ ++ spin_lock_init(&trigger_data->lock); ++ ++ trigger_data->notifier.notifier_call = netdev_trig_notify; ++ trigger_data->notifier.priority = 10; ++ ++ INIT_DELAYED_WORK(&trigger_data->work, netdev_trig_work); ++ ++ trigger_data->led_cdev = led_cdev; ++ trigger_data->net_dev = NULL; ++ trigger_data->device_name[0] = 0; ++ ++ trigger_data->mode = 0; ++ atomic_set(&trigger_data->interval, msecs_to_jiffies(50)); ++ trigger_data->last_activity = 0; ++ ++ led_cdev->trigger_data = trigger_data; ++ ++ rc = device_create_file(led_cdev->dev, &dev_attr_device_name); ++ if (rc) ++ goto err_out; ++ rc = device_create_file(led_cdev->dev, &dev_attr_link); ++ if (rc) ++ goto err_out_device_name; ++ rc = device_create_file(led_cdev->dev, &dev_attr_rx); ++ if (rc) ++ goto err_out_link; ++ rc = device_create_file(led_cdev->dev, &dev_attr_tx); ++ if (rc) ++ goto err_out_rx; ++ rc = device_create_file(led_cdev->dev, &dev_attr_interval); ++ if (rc) ++ goto err_out_tx; ++ rc = register_netdevice_notifier(&trigger_data->notifier); ++ if (rc) ++ goto err_out_interval; ++ return; ++ ++err_out_interval: ++ device_remove_file(led_cdev->dev, &dev_attr_interval); ++err_out_tx: ++ device_remove_file(led_cdev->dev, &dev_attr_tx); ++err_out_rx: ++ device_remove_file(led_cdev->dev, &dev_attr_rx); ++err_out_link: ++ device_remove_file(led_cdev->dev, &dev_attr_link); ++err_out_device_name: ++ device_remove_file(led_cdev->dev, &dev_attr_device_name); ++err_out: ++ led_cdev->trigger_data = NULL; ++ kfree(trigger_data); ++} ++ ++static void netdev_trig_deactivate(struct led_classdev *led_cdev) ++{ ++ struct led_netdev_data *trigger_data = led_cdev->trigger_data; ++ ++ if (trigger_data) { ++ unregister_netdevice_notifier(&trigger_data->notifier); ++ ++ device_remove_file(led_cdev->dev, &dev_attr_device_name); ++ device_remove_file(led_cdev->dev, &dev_attr_link); ++ device_remove_file(led_cdev->dev, &dev_attr_rx); ++ device_remove_file(led_cdev->dev, &dev_attr_tx); ++ device_remove_file(led_cdev->dev, &dev_attr_interval); ++ ++ cancel_delayed_work_sync(&trigger_data->work); ++ ++ if (trigger_data->net_dev) ++ dev_put(trigger_data->net_dev); ++ ++ kfree(trigger_data); ++ } ++} ++ ++static struct led_trigger netdev_led_trigger = { ++ .name = "netdev", ++ .activate = netdev_trig_activate, ++ .deactivate = netdev_trig_deactivate, ++}; ++ ++static int __init netdev_trig_init(void) ++{ ++ return led_trigger_register(&netdev_led_trigger); ++} ++ ++static void __exit netdev_trig_exit(void) ++{ ++ led_trigger_unregister(&netdev_led_trigger); ++} ++ ++module_init(netdev_trig_init); ++module_exit(netdev_trig_exit); ++ ++MODULE_AUTHOR("Ben Whitten "); ++MODULE_AUTHOR("Oliver Jowett "); ++MODULE_DESCRIPTION("Netdev LED trigger"); ++MODULE_LICENSE("GPL v2"); diff --git a/target/linux/generic/files/drivers/leds/ledtrig-netdev.c b/target/linux/generic/files/drivers/leds/ledtrig-netdev.c deleted file mode 100644 index 8d3249010d..0000000000 --- a/target/linux/generic/files/drivers/leds/ledtrig-netdev.c +++ /dev/null @@ -1,444 +0,0 @@ -/* - * LED Kernel Netdev Trigger - * - * Toggles the LED to reflect the link and traffic state of a named net device - * - * Copyright 2007 Oliver Jowett - * - * Derived from ledtrig-timer.c which is: - * Copyright 2005-2006 Openedhand Ltd. - * Author: Richard Purdie - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "leds.h" - -/* - * Configurable sysfs attributes: - * - * device_name - network device name to monitor - * - * interval - duration of LED blink, in milliseconds - * - * mode - either "none" (LED is off) or a space separated list of one or more of: - * link: LED's normal state reflects whether the link is up (has carrier) or not - * tx: LED blinks on transmitted data - * rx: LED blinks on receive data - * - * Some suggestions: - * - * Simple link status LED: - * $ echo netdev >someled/trigger - * $ echo eth0 >someled/device_name - * $ echo link >someled/mode - * - * Ethernet-style link/activity LED: - * $ echo netdev >someled/trigger - * $ echo eth0 >someled/device_name - * $ echo "link tx rx" >someled/mode - * - * Modem-style tx/rx LEDs: - * $ echo netdev >led1/trigger - * $ echo ppp0 >led1/device_name - * $ echo tx >led1/mode - * $ echo netdev >led2/trigger - * $ echo ppp0 >led2/device_name - * $ echo rx >led2/mode - * - */ - -#define MODE_LINK 1 -#define MODE_TX 2 -#define MODE_RX 4 - -struct led_netdev_data { - spinlock_t lock; - - struct delayed_work work; - struct notifier_block notifier; - - struct led_classdev *led_cdev; - struct net_device *net_dev; - - char device_name[IFNAMSIZ]; - unsigned interval; - unsigned mode; - unsigned link_up; - unsigned last_activity; -}; - -static void set_baseline_state(struct led_netdev_data *trigger_data) -{ - if ((trigger_data->mode & MODE_LINK) != 0 && trigger_data->link_up) - led_set_brightness(trigger_data->led_cdev, LED_FULL); - else - led_set_brightness(trigger_data->led_cdev, LED_OFF); - - if ((trigger_data->mode & (MODE_TX | MODE_RX)) != 0 && trigger_data->link_up) - schedule_delayed_work(&trigger_data->work, trigger_data->interval); -} - -static ssize_t led_device_name_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct led_netdev_data *trigger_data = led_cdev->trigger_data; - - spin_lock_bh(&trigger_data->lock); - sprintf(buf, "%s\n", trigger_data->device_name); - spin_unlock_bh(&trigger_data->lock); - - return strlen(buf) + 1; -} - -static ssize_t led_device_name_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct led_netdev_data *trigger_data = led_cdev->trigger_data; - - if (size >= IFNAMSIZ) - return -EINVAL; - - cancel_delayed_work_sync(&trigger_data->work); - - spin_lock_bh(&trigger_data->lock); - - strcpy(trigger_data->device_name, buf); - if (size > 0 && trigger_data->device_name[size-1] == '\n') - trigger_data->device_name[size-1] = 0; - trigger_data->link_up = 0; - trigger_data->last_activity = 0; - - if (trigger_data->device_name[0] != 0) { - /* check for existing device to update from */ - trigger_data->net_dev = dev_get_by_name(&init_net, trigger_data->device_name); - if (trigger_data->net_dev != NULL) - trigger_data->link_up = (dev_get_flags(trigger_data->net_dev) & IFF_LOWER_UP) != 0; - } - - set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); - - return size; -} - -static DEVICE_ATTR(device_name, 0644, led_device_name_show, led_device_name_store); - -static ssize_t led_mode_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct led_netdev_data *trigger_data = led_cdev->trigger_data; - - spin_lock_bh(&trigger_data->lock); - - if (trigger_data->mode == 0) { - strcpy(buf, "none\n"); - } else { - if (trigger_data->mode & MODE_LINK) - strcat(buf, "link "); - if (trigger_data->mode & MODE_TX) - strcat(buf, "tx "); - if (trigger_data->mode & MODE_RX) - strcat(buf, "rx "); - strcat(buf, "\n"); - } - - spin_unlock_bh(&trigger_data->lock); - - return strlen(buf)+1; -} - -static ssize_t led_mode_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct led_netdev_data *trigger_data = led_cdev->trigger_data; - char copybuf[128]; - int new_mode = -1; - char *p, *token; - - /* take a copy since we don't want to trash the inbound buffer when using strsep */ - strncpy(copybuf, buf, sizeof(copybuf)); - copybuf[sizeof(copybuf) - 1] = 0; - p = copybuf; - - while ((token = strsep(&p, " \t\n")) != NULL) { - if (!*token) - continue; - - if (new_mode == -1) - new_mode = 0; - - if (!strcmp(token, "none")) - new_mode = 0; - else if (!strcmp(token, "tx")) - new_mode |= MODE_TX; - else if (!strcmp(token, "rx")) - new_mode |= MODE_RX; - else if (!strcmp(token, "link")) - new_mode |= MODE_LINK; - else - return -EINVAL; - } - - if (new_mode == -1) - return -EINVAL; - - cancel_delayed_work_sync(&trigger_data->work); - - spin_lock_bh(&trigger_data->lock); - trigger_data->mode = new_mode; - set_baseline_state(trigger_data); - spin_unlock_bh(&trigger_data->lock); - - return size; -} - -static DEVICE_ATTR(mode, 0644, led_mode_show, led_mode_store); - -static ssize_t led_interval_show(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct led_netdev_data *trigger_data = led_cdev->trigger_data; - - spin_lock_bh(&trigger_data->lock); - sprintf(buf, "%u\n", jiffies_to_msecs(trigger_data->interval)); - spin_unlock_bh(&trigger_data->lock); - - return strlen(buf) + 1; -} - -static ssize_t led_interval_store(struct device *dev, - struct device_attribute *attr, const char *buf, size_t size) -{ - struct led_classdev *led_cdev = dev_get_drvdata(dev); - struct led_netdev_data *trigger_data = led_cdev->trigger_data; - int ret = -EINVAL; - char *after; - unsigned long value = simple_strtoul(buf, &after, 10); - size_t count = after - buf; - - if (isspace(*after)) - count++; - - /* impose some basic bounds on the timer interval */ - if (count == size && value >= 5 && value <= 10000) { - cancel_delayed_work_sync(&trigger_data->work); - - spin_lock_bh(&trigger_data->lock); - trigger_data->interval = msecs_to_jiffies(value); - set_baseline_state(trigger_data); /* resets timer */ - spin_unlock_bh(&trigger_data->lock); - - ret = count; - } - - return ret; -} - -static DEVICE_ATTR(interval, 0644, led_interval_show, led_interval_store); - -static int netdev_trig_notify(struct notifier_block *nb, - unsigned long evt, - void *dv) -{ - struct net_device *dev = netdev_notifier_info_to_dev((struct netdev_notifier_info *) dv); - struct led_netdev_data *trigger_data = container_of(nb, struct led_netdev_data, notifier); - - if (evt != NETDEV_UP && evt != NETDEV_DOWN && evt != NETDEV_CHANGE && evt != NETDEV_REGISTER && evt != NETDEV_UNREGISTER && evt != NETDEV_CHANGENAME) - return NOTIFY_DONE; - - if (strcmp(dev->name, trigger_data->device_name)) - return NOTIFY_DONE; - - cancel_delayed_work_sync(&trigger_data->work); - - spin_lock_bh(&trigger_data->lock); - - if (evt == NETDEV_REGISTER || evt == NETDEV_CHANGENAME) { - if (trigger_data->net_dev != NULL) - dev_put(trigger_data->net_dev); - - dev_hold(dev); - trigger_data->net_dev = dev; - trigger_data->link_up = 0; - goto done; - } - - if (evt == NETDEV_UNREGISTER && trigger_data->net_dev != NULL) { - dev_put(trigger_data->net_dev); - trigger_data->net_dev = NULL; - goto done; - } - - /* UP / DOWN / CHANGE */ - - trigger_data->link_up = (evt != NETDEV_DOWN && netif_carrier_ok(dev)); - set_baseline_state(trigger_data); - -done: - spin_unlock_bh(&trigger_data->lock); - return NOTIFY_DONE; -} - -/* here's the real work! */ -static void netdev_trig_work(struct work_struct *work) -{ - struct led_netdev_data *trigger_data = container_of(work, struct led_netdev_data, work.work); - struct rtnl_link_stats64 *dev_stats; - unsigned new_activity; - struct rtnl_link_stats64 temp; - - if (!trigger_data->link_up || !trigger_data->net_dev || (trigger_data->mode & (MODE_TX | MODE_RX)) == 0) { - /* we don't need to do timer work, just reflect link state. */ - led_set_brightness(trigger_data->led_cdev, ((trigger_data->mode & MODE_LINK) != 0 && trigger_data->link_up) ? LED_FULL : LED_OFF); - return; - } - - dev_stats = dev_get_stats(trigger_data->net_dev, &temp); - new_activity = - ((trigger_data->mode & MODE_TX) ? dev_stats->tx_packets : 0) + - ((trigger_data->mode & MODE_RX) ? dev_stats->rx_packets : 0); - - if (trigger_data->mode & MODE_LINK) { - /* base state is ON (link present) */ - /* if there's no link, we don't get this far and the LED is off */ - - /* OFF -> ON always */ - /* ON -> OFF on activity */ - if (trigger_data->led_cdev->brightness == LED_OFF) { - led_set_brightness(trigger_data->led_cdev, LED_FULL); - } else if (trigger_data->last_activity != new_activity) { - led_set_brightness(trigger_data->led_cdev, LED_OFF); - } - } else { - /* base state is OFF */ - /* ON -> OFF always */ - /* OFF -> ON on activity */ - if (trigger_data->led_cdev->brightness == LED_FULL) { - led_set_brightness(trigger_data->led_cdev, LED_OFF); - } else if (trigger_data->last_activity != new_activity) { - led_set_brightness(trigger_data->led_cdev, LED_FULL); - } - } - - trigger_data->last_activity = new_activity; - schedule_delayed_work(&trigger_data->work, trigger_data->interval); -} - -static void netdev_trig_activate(struct led_classdev *led_cdev) -{ - struct led_netdev_data *trigger_data; - int rc; - - trigger_data = kzalloc(sizeof(struct led_netdev_data), GFP_KERNEL); - if (!trigger_data) - return; - - spin_lock_init(&trigger_data->lock); - - trigger_data->notifier.notifier_call = netdev_trig_notify; - trigger_data->notifier.priority = 10; - - INIT_DELAYED_WORK(&trigger_data->work, netdev_trig_work); - - trigger_data->led_cdev = led_cdev; - trigger_data->net_dev = NULL; - trigger_data->device_name[0] = 0; - - trigger_data->mode = 0; - trigger_data->interval = msecs_to_jiffies(50); - trigger_data->link_up = 0; - trigger_data->last_activity = 0; - - led_cdev->trigger_data = trigger_data; - - rc = device_create_file(led_cdev->dev, &dev_attr_device_name); - if (rc) - goto err_out; - rc = device_create_file(led_cdev->dev, &dev_attr_mode); - if (rc) - goto err_out_device_name; - rc = device_create_file(led_cdev->dev, &dev_attr_interval); - if (rc) - goto err_out_mode; - - register_netdevice_notifier(&trigger_data->notifier); - return; - -err_out_mode: - device_remove_file(led_cdev->dev, &dev_attr_mode); -err_out_device_name: - device_remove_file(led_cdev->dev, &dev_attr_device_name); -err_out: - led_cdev->trigger_data = NULL; - kfree(trigger_data); -} - -static void netdev_trig_deactivate(struct led_classdev *led_cdev) -{ - struct led_netdev_data *trigger_data = led_cdev->trigger_data; - - if (trigger_data) { - unregister_netdevice_notifier(&trigger_data->notifier); - - device_remove_file(led_cdev->dev, &dev_attr_device_name); - device_remove_file(led_cdev->dev, &dev_attr_mode); - device_remove_file(led_cdev->dev, &dev_attr_interval); - - cancel_delayed_work_sync(&trigger_data->work); - - spin_lock_bh(&trigger_data->lock); - - if (trigger_data->net_dev) { - dev_put(trigger_data->net_dev); - trigger_data->net_dev = NULL; - } - - spin_unlock_bh(&trigger_data->lock); - - kfree(trigger_data); - } -} - -static struct led_trigger netdev_led_trigger = { - .name = "netdev", - .activate = netdev_trig_activate, - .deactivate = netdev_trig_deactivate, -}; - -static int __init netdev_trig_init(void) -{ - return led_trigger_register(&netdev_led_trigger); -} - -static void __exit netdev_trig_exit(void) -{ - led_trigger_unregister(&netdev_led_trigger); -} - -module_init(netdev_trig_init); -module_exit(netdev_trig_exit); - -MODULE_AUTHOR("Oliver Jowett "); -MODULE_DESCRIPTION("Netdev LED trigger"); -MODULE_LICENSE("GPL"); diff --git a/target/linux/generic/pending-3.18/831-ledtrig_netdev.patch b/target/linux/generic/pending-3.18/831-ledtrig_netdev.patch deleted file mode 100644 index 3b46b4a9f4..0000000000 --- a/target/linux/generic/pending-3.18/831-ledtrig_netdev.patch +++ /dev/null @@ -1,21 +0,0 @@ ---- a/drivers/leds/trigger/Kconfig -+++ b/drivers/leds/trigger/Kconfig -@@ -108,4 +108,11 @@ config LEDS_TRIGGER_CAMERA - This enables direct flash/torch on/off by the driver, kernel space. - If unsure, say Y. - -+config LEDS_TRIGGER_NETDEV -+ tristate "LED Netdev Trigger" -+ depends on NET && LEDS_TRIGGERS -+ help -+ This allows LEDs to be controlled by network device activity. -+ If unsure, say Y. -+ - endif # LEDS_TRIGGERS ---- a/drivers/leds/Makefile -+++ b/drivers/leds/Makefile -@@ -62,3 +62,4 @@ obj-$(CONFIG_LEDS_DAC124S085) += leds-d - - # LED Triggers - obj-$(CONFIG_LEDS_TRIGGERS) += trigger/ -+obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o diff --git a/target/linux/generic/pending-4.14/831-ledtrig_netdev.patch b/target/linux/generic/pending-4.14/831-ledtrig_netdev.patch deleted file mode 100644 index a12e6dba96..0000000000 --- a/target/linux/generic/pending-4.14/831-ledtrig_netdev.patch +++ /dev/null @@ -1,74 +0,0 @@ -From: Alexey Brodkin -Subject: usb: Remove annoying warning about bogus URB - -When ath9k-htc Wi-Fi dongle is used with generic OHCI controller -infinite stream of warnings appears in debug console like this: --------------------------->8---------------------- -usb 1-1: new full-speed USB device number 2 using ohci-platform -usb 1-1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested -usb 1-1: ath9k_htc: Transferred FW: ath9k_htc/htc_9271-1.4.0.fw, size: -51008 -------------[ cut here ]------------ -WARNING: CPU: 0 PID: 19 at drivers/usb/core/urb.c:449 -usb_submit_urb+0x1b4/0x498() -usb 1-1: BOGUS urb xfer, pipe 1 != type 3 -Modules linked in: -CPU: 0 PID: 19 Comm: kworker/0:1 Not tainted -4.4.0-rc4-00017-g00e2d79-dirty #3 -Workqueue: events request_firmware_work_func - -Stack Trace: -arc_unwind_core.constprop.1+0xa4/0x110 ----[ end trace 649ef8c342817fc2 ]--- -------------[ cut here ]------------ -WARNING: CPU: 0 PID: 19 at drivers/usb/core/urb.c:449 -usb_submit_urb+0x1b4/0x498() -usb 1-1: BOGUS urb xfer, pipe 1 != type 3 -Modules linked in: -CPU: 0 PID: 19 Comm: kworker/0:1 Tainted: G W -4.4.0-rc4-00017-g00e2d79-dirty #3 -Workqueue: events request_firmware_work_func - -Stack Trace: -arc_unwind_core.constprop.1+0xa4/0x110 ----[ end trace 649ef8c342817fc3 ]--- -------------[ cut here ]------------ --------------------------->8---------------------- - -There're some discussions in mailing lists proposing to disable -that particular check alltogether and magically all seem to work -fine with muted warning. - -Anyways new thread on that regard could be found here: -http://lists.infradead.org/pipermail/linux-snps-arc/2016-July/001310.html - -Let's see what comes out of that new discussion, hopefully patching -of generic USB stuff won't be required then. - -Signed-off-by: Alexey Brodkin ---- - drivers/leds/Makefile | 1 + - drivers/leds/trigger/Kconfig | 7 +++++++ - 2 files changed, 8 insertions(+) - ---- a/drivers/leds/Makefile -+++ b/drivers/leds/Makefile -@@ -82,3 +82,4 @@ obj-$(CONFIG_LEDS_USER) += uleds.o - - # LED Triggers - obj-$(CONFIG_LEDS_TRIGGERS) += trigger/ -+obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o ---- a/drivers/leds/trigger/Kconfig -+++ b/drivers/leds/trigger/Kconfig -@@ -126,4 +126,11 @@ config LEDS_TRIGGER_PANIC - a different trigger. - If unsure, say Y. - -+config LEDS_TRIGGER_NETDEV -+ tristate "LED Netdev Trigger" -+ depends on NET && LEDS_TRIGGERS -+ help -+ This allows LEDs to be controlled by network device activity. -+ If unsure, say Y. -+ - endif # LEDS_TRIGGERS diff --git a/target/linux/generic/pending-4.9/831-ledtrig_netdev.patch b/target/linux/generic/pending-4.9/831-ledtrig_netdev.patch deleted file mode 100644 index 037ec9bb2d..0000000000 --- a/target/linux/generic/pending-4.9/831-ledtrig_netdev.patch +++ /dev/null @@ -1,74 +0,0 @@ -From: Alexey Brodkin -Subject: usb: Remove annoying warning about bogus URB - -When ath9k-htc Wi-Fi dongle is used with generic OHCI controller -infinite stream of warnings appears in debug console like this: --------------------------->8---------------------- -usb 1-1: new full-speed USB device number 2 using ohci-platform -usb 1-1: ath9k_htc: Firmware ath9k_htc/htc_9271-1.4.0.fw requested -usb 1-1: ath9k_htc: Transferred FW: ath9k_htc/htc_9271-1.4.0.fw, size: -51008 -------------[ cut here ]------------ -WARNING: CPU: 0 PID: 19 at drivers/usb/core/urb.c:449 -usb_submit_urb+0x1b4/0x498() -usb 1-1: BOGUS urb xfer, pipe 1 != type 3 -Modules linked in: -CPU: 0 PID: 19 Comm: kworker/0:1 Not tainted -4.4.0-rc4-00017-g00e2d79-dirty #3 -Workqueue: events request_firmware_work_func - -Stack Trace: -arc_unwind_core.constprop.1+0xa4/0x110 ----[ end trace 649ef8c342817fc2 ]--- -------------[ cut here ]------------ -WARNING: CPU: 0 PID: 19 at drivers/usb/core/urb.c:449 -usb_submit_urb+0x1b4/0x498() -usb 1-1: BOGUS urb xfer, pipe 1 != type 3 -Modules linked in: -CPU: 0 PID: 19 Comm: kworker/0:1 Tainted: G W -4.4.0-rc4-00017-g00e2d79-dirty #3 -Workqueue: events request_firmware_work_func - -Stack Trace: -arc_unwind_core.constprop.1+0xa4/0x110 ----[ end trace 649ef8c342817fc3 ]--- -------------[ cut here ]------------ --------------------------->8---------------------- - -There're some discussions in mailing lists proposing to disable -that particular check alltogether and magically all seem to work -fine with muted warning. - -Anyways new thread on that regard could be found here: -http://lists.infradead.org/pipermail/linux-snps-arc/2016-July/001310.html - -Let's see what comes out of that new discussion, hopefully patching -of generic USB stuff won't be required then. - -Signed-off-by: Alexey Brodkin ---- - drivers/leds/Makefile | 1 + - drivers/leds/trigger/Kconfig | 7 +++++++ - 2 files changed, 8 insertions(+) - ---- a/drivers/leds/Makefile -+++ b/drivers/leds/Makefile -@@ -77,3 +77,4 @@ obj-$(CONFIG_LEDS_DAC124S085) += leds-d - - # LED Triggers - obj-$(CONFIG_LEDS_TRIGGERS) += trigger/ -+obj-$(CONFIG_LEDS_TRIGGER_NETDEV) += ledtrig-netdev.o ---- a/drivers/leds/trigger/Kconfig -+++ b/drivers/leds/trigger/Kconfig -@@ -126,4 +126,11 @@ config LEDS_TRIGGER_PANIC - a different trigger. - If unsure, say Y. - -+config LEDS_TRIGGER_NETDEV -+ tristate "LED Netdev Trigger" -+ depends on NET && LEDS_TRIGGERS -+ help -+ This allows LEDs to be controlled by network device activity. -+ If unsure, say Y. -+ - endif # LEDS_TRIGGERS -- 2.25.1