@@ -36,26 +36,6 @@
*
*/
-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;
- bool carrier_link_up;
-#define NETDEV_LED_LINK 0
-#define NETDEV_LED_TX 1
-#define NETDEV_LED_RX 2
-};
-
enum netdev_led_attr {
NETDEV_ATTR_LINK,
NETDEV_ATTR_TX,
@@ -76,7 +56,7 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
if (!trigger_data->carrier_link_up) {
led_set_brightness(led_cdev, LED_OFF);
} else {
- if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
+ if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
led_set_brightness(led_cdev,
led_cdev->blink_brightness);
else
@@ -85,8 +65,8 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
/* 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))
+ if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ||
+ test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode))
schedule_delayed_work(&trigger_data->work, 0);
}
}
@@ -153,13 +133,13 @@ static ssize_t netdev_led_attr_show(struct device *dev, char *buf,
switch (attr) {
case NETDEV_ATTR_LINK:
- bit = NETDEV_LED_LINK;
+ bit = TRIGGER_NETDEV_LINK;
break;
case NETDEV_ATTR_TX:
- bit = NETDEV_LED_TX;
+ bit = TRIGGER_NETDEV_TX;
break;
case NETDEV_ATTR_RX:
- bit = NETDEV_LED_RX;
+ bit = TRIGGER_NETDEV_RX;
break;
default:
return -EINVAL;
@@ -182,13 +162,13 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
switch (attr) {
case NETDEV_ATTR_LINK:
- bit = NETDEV_LED_LINK;
+ bit = TRIGGER_NETDEV_LINK;
break;
case NETDEV_ATTR_TX:
- bit = NETDEV_LED_TX;
+ bit = TRIGGER_NETDEV_TX;
break;
case NETDEV_ATTR_RX:
- bit = NETDEV_LED_RX;
+ bit = TRIGGER_NETDEV_RX;
break;
default:
return -EINVAL;
@@ -358,21 +338,21 @@ static void netdev_trig_work(struct work_struct *work)
}
/* 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))
+ if (!test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) &&
+ !test_bit(TRIGGER_NETDEV_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) ?
+ (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ?
dev_stats->tx_packets : 0) +
- (test_bit(NETDEV_LED_RX, &trigger_data->mode) ?
+ (test_bit(TRIGGER_NETDEV_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);
+ invert = test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode);
interval = jiffies_to_msecs(
atomic_read(&trigger_data->interval));
/* base state is ON (link present) */
@@ -503,6 +503,35 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
#endif /* CONFIG_LEDS_TRIGGERS */
+/* Trigger specific trigger_data used by netdev trigger */
+#ifdef CONFIG_LEDS_TRIGGER_NETDEV
+#include <linux/netdevice.h>
+
+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;
+ bool carrier_link_up;
+};
+
+/* Trigger specific bitmap blink mode used by netdev trigger */
+enum led_trigger_netdev_modes {
+ TRIGGER_NETDEV_LINK,
+ TRIGGER_NETDEV_TX,
+ TRIGGER_NETDEV_RX,
+};
+#endif
+
/* Trigger specific functions */
#ifdef CONFIG_LEDS_TRIGGER_DISK
void ledtrig_disk_activity(bool write);
A LED driver, to support hardware control, requires to support a specific trigger and requires to elaborate his trigger_data struct. Move netdev trigger data struct to leds.h to make it accessible by any LED driver that wants to add support for hardware control for the specific netdev trigger. Also rename NETDEV trigger enum modes to a more symbolic and descriptive name. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com> --- drivers/leds/trigger/ledtrig-netdev.c | 48 ++++++++------------------- include/linux/leds.h | 29 ++++++++++++++++ 2 files changed, 43 insertions(+), 34 deletions(-)