Lines Matching +full:- +full:- +full:mode +full:- +full:-
1 // SPDX-License-Identifier: GPL-2.0
9 // Derived from ledtrig-timer.c which is:
10 // Copyright 2005-2006 Openedhand Ltd.
36 * device_name - network device name to monitor
37 * interval - duration of LED blink, in milliseconds
38 * link - LED's normal state reflects whether the link is up
40 * tx - LED blinks on transmitted data
41 * rx - LED blinks on receive data
42 * tx_err - LED blinks on transmit error
43 * rx_err - LED blinks on receive error
45 * Note: If the user selects a mode that is not supported by hw, default
50 * mode isn't supported by hw. This could be switching off the LED or any
51 * hw blink mode. If software control fallback isn't possible, we return
52 * -EOPNOTSUPP to the user, but still store the selected mode. This is needed
53 * in case an intermediate unsupported mode is necessary to switch from one
54 * supported mode to another.
70 unsigned long mode; member
84 struct led_classdev *led_cdev = trigger_data->led_cdev; in set_baseline_state()
86 /* Already validated, hw control is possible with the requested mode */ in set_baseline_state()
87 if (trigger_data->hw_control) { in set_baseline_state()
88 led_cdev->hw_control_set(led_cdev, trigger_data->mode); in set_baseline_state()
93 current_brightness = led_cdev->brightness; in set_baseline_state()
95 led_cdev->blink_brightness = current_brightness; in set_baseline_state()
96 if (!led_cdev->blink_brightness) in set_baseline_state()
97 led_cdev->blink_brightness = led_cdev->max_brightness; in set_baseline_state()
99 if (!trigger_data->carrier_link_up) { in set_baseline_state()
104 if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode)) in set_baseline_state()
107 if (test_bit(TRIGGER_NETDEV_LINK_10, &trigger_data->mode) && in set_baseline_state()
108 trigger_data->link_speed == SPEED_10) in set_baseline_state()
111 if (test_bit(TRIGGER_NETDEV_LINK_100, &trigger_data->mode) && in set_baseline_state()
112 trigger_data->link_speed == SPEED_100) in set_baseline_state()
115 if (test_bit(TRIGGER_NETDEV_LINK_1000, &trigger_data->mode) && in set_baseline_state()
116 trigger_data->link_speed == SPEED_1000) in set_baseline_state()
119 if (test_bit(TRIGGER_NETDEV_LINK_2500, &trigger_data->mode) && in set_baseline_state()
120 trigger_data->link_speed == SPEED_2500) in set_baseline_state()
123 if (test_bit(TRIGGER_NETDEV_LINK_5000, &trigger_data->mode) && in set_baseline_state()
124 trigger_data->link_speed == SPEED_5000) in set_baseline_state()
127 if (test_bit(TRIGGER_NETDEV_LINK_10000, &trigger_data->mode) && in set_baseline_state()
128 trigger_data->link_speed == SPEED_10000) in set_baseline_state()
131 if (test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &trigger_data->mode) && in set_baseline_state()
132 trigger_data->duplex == DUPLEX_HALF) in set_baseline_state()
135 if (test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &trigger_data->mode) && in set_baseline_state()
136 trigger_data->duplex == DUPLEX_FULL) in set_baseline_state()
141 led_cdev->blink_brightness); in set_baseline_state()
148 if (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) || in set_baseline_state()
149 test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) || in set_baseline_state()
150 test_bit(TRIGGER_NETDEV_TX_ERR, &trigger_data->mode) || in set_baseline_state()
151 test_bit(TRIGGER_NETDEV_RX_ERR, &trigger_data->mode)) in set_baseline_state()
152 schedule_delayed_work(&trigger_data->work, 0); in set_baseline_state()
158 if (!led_cdev->hw_control_get || !led_cdev->hw_control_set || in supports_hw_control()
159 !led_cdev->hw_control_is_supported) in supports_hw_control()
162 return !strcmp(led_cdev->hw_control_trigger, led_cdev->trigger->name); in supports_hw_control()
172 struct device *dev = led_cdev->hw_control_get_device(led_cdev); in validate_net_dev()
186 unsigned int interval = atomic_read(&trigger_data->interval); in can_hw_control()
187 struct led_classdev *led_cdev = trigger_data->led_cdev; in can_hw_control()
208 if (!validate_net_dev(led_cdev, trigger_data->net_dev)) in can_hw_control()
211 /* Check if the requested mode is supported */ in can_hw_control()
212 ret = led_cdev->hw_control_is_supported(led_cdev, trigger_data->mode); in can_hw_control()
214 if (ret == -EOPNOTSUPP) in can_hw_control()
217 dev_warn(led_cdev->dev, in can_hw_control()
218 "Current mode check failed with error %d\n", ret); in can_hw_control()
229 trigger_data->carrier_link_up = netif_carrier_ok(trigger_data->net_dev); in get_device_state()
231 if (__ethtool_get_link_ksettings(trigger_data->net_dev, &cmd)) in get_device_state()
234 if (trigger_data->carrier_link_up) { in get_device_state()
235 trigger_data->link_speed = cmd.base.speed; in get_device_state()
236 trigger_data->duplex = cmd.base.duplex; in get_device_state()
243 linkmode_copy(trigger_data->supported_link_modes, cmd.link_modes.supported); in get_device_state()
252 mutex_lock(&trigger_data->lock); in device_name_show()
253 len = sprintf(buf, "%s\n", trigger_data->device_name); in device_name_show()
254 mutex_unlock(&trigger_data->lock); in device_name_show()
263 return -EINVAL; in set_device_name()
265 cancel_delayed_work_sync(&trigger_data->work); in set_device_name()
272 mutex_lock(&trigger_data->lock); in set_device_name()
274 if (trigger_data->net_dev) { in set_device_name()
275 dev_put(trigger_data->net_dev); in set_device_name()
276 trigger_data->net_dev = NULL; in set_device_name()
279 memcpy(trigger_data->device_name, name, size); in set_device_name()
280 trigger_data->device_name[size] = 0; in set_device_name()
281 if (size > 0 && trigger_data->device_name[size - 1] == '\n') in set_device_name()
282 trigger_data->device_name[size - 1] = 0; in set_device_name()
284 if (trigger_data->device_name[0] != 0) in set_device_name()
285 trigger_data->net_dev = in set_device_name()
286 dev_get_by_name(&init_net, trigger_data->device_name); in set_device_name()
288 trigger_data->carrier_link_up = false; in set_device_name()
289 trigger_data->link_speed = SPEED_UNKNOWN; in set_device_name()
290 trigger_data->duplex = DUPLEX_UNKNOWN; in set_device_name()
291 if (trigger_data->net_dev) in set_device_name()
294 trigger_data->last_activity = 0; in set_device_name()
297 if (!trigger_data->hw_control || led_get_trigger_data(trigger_data->led_cdev)) in set_device_name()
300 mutex_unlock(&trigger_data->lock); in set_device_name()
319 sysfs_update_group(&dev->kobj, &netdev_trig_link_speed_attrs_group); in device_name_store()
349 return -EINVAL; in netdev_led_attr_show()
352 return sprintf(buf, "%u\n", test_bit(bit, &trigger_data->mode)); in netdev_led_attr_show()
359 struct led_classdev *led_cdev = trigger_data->led_cdev; in netdev_led_attr_store()
360 unsigned long state, mode = trigger_data->mode; in netdev_led_attr_store() local
385 return -EINVAL; in netdev_led_attr_store()
389 set_bit(bit, &mode); in netdev_led_attr_store()
391 clear_bit(bit, &mode); in netdev_led_attr_store()
393 if (test_bit(TRIGGER_NETDEV_LINK, &mode) && in netdev_led_attr_store()
394 (test_bit(TRIGGER_NETDEV_LINK_10, &mode) || in netdev_led_attr_store()
395 test_bit(TRIGGER_NETDEV_LINK_100, &mode) || in netdev_led_attr_store()
396 test_bit(TRIGGER_NETDEV_LINK_1000, &mode) || in netdev_led_attr_store()
397 test_bit(TRIGGER_NETDEV_LINK_2500, &mode) || in netdev_led_attr_store()
398 test_bit(TRIGGER_NETDEV_LINK_5000, &mode) || in netdev_led_attr_store()
399 test_bit(TRIGGER_NETDEV_LINK_10000, &mode))) in netdev_led_attr_store()
400 return -EINVAL; in netdev_led_attr_store()
402 cancel_delayed_work_sync(&trigger_data->work); in netdev_led_attr_store()
404 trigger_data->mode = mode; in netdev_led_attr_store()
405 trigger_data->hw_control = can_hw_control(trigger_data); in netdev_led_attr_store()
407 if (!led_cdev->brightness_set && !led_cdev->brightness_set_blocking && in netdev_led_attr_store()
408 !trigger_data->hw_control) in netdev_led_attr_store()
409 return -EOPNOTSUPP; in netdev_led_attr_store()
449 jiffies_to_msecs(atomic_read(&trigger_data->interval))); in interval_show()
460 if (trigger_data->hw_control) in interval_store()
461 return -EINVAL; in interval_store()
469 cancel_delayed_work_sync(&trigger_data->work); in interval_store()
471 atomic_set(&trigger_data->interval, msecs_to_jiffies(value)); in interval_store()
485 return sprintf(buf, "%d\n", trigger_data->hw_control); in offloaded_show()
494 return attr->mode; \
503 u32 mode; in netdev_trig_link_speed_visible() local
506 supported_link_modes = trigger_data->supported_link_modes; in netdev_trig_link_speed_visible()
509 * Search in the supported link mode mask a matching supported mode. in netdev_trig_link_speed_visible()
513 for_each_set_bit(mode, supported_link_modes, __ETHTOOL_LINK_MODE_MASK_NBITS) { in netdev_trig_link_speed_visible()
516 ethtool_params_from_link_mode(&link_ksettings, mode); in netdev_trig_link_speed_visible()
575 struct led_classdev *led_cdev = trigger_data->led_cdev; in netdev_trig_notify()
582 if (!(dev == trigger_data->net_dev || in netdev_trig_notify()
583 (evt == NETDEV_CHANGENAME && !strcmp(dev->name, trigger_data->device_name)) || in netdev_trig_notify()
584 (evt == NETDEV_REGISTER && !strcmp(dev->name, trigger_data->device_name)))) in netdev_trig_notify()
587 cancel_delayed_work_sync(&trigger_data->work); in netdev_trig_notify()
589 mutex_lock(&trigger_data->lock); in netdev_trig_notify()
591 trigger_data->carrier_link_up = false; in netdev_trig_notify()
592 trigger_data->link_speed = SPEED_UNKNOWN; in netdev_trig_notify()
593 trigger_data->duplex = DUPLEX_UNKNOWN; in netdev_trig_notify()
597 dev_put(trigger_data->net_dev); in netdev_trig_notify()
599 trigger_data->net_dev = dev; in netdev_trig_notify()
604 dev_put(trigger_data->net_dev); in netdev_trig_notify()
605 trigger_data->net_dev = NULL; in netdev_trig_notify()
612 sysfs_update_group(&led_cdev->dev->kobj, in netdev_trig_notify()
619 mutex_unlock(&trigger_data->lock); in netdev_trig_notify()
636 if (!trigger_data->net_dev) { in netdev_trig_work()
637 led_set_brightness(trigger_data->led_cdev, LED_OFF); in netdev_trig_work()
642 if (!test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) && in netdev_trig_work()
643 !test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) && in netdev_trig_work()
644 !test_bit(TRIGGER_NETDEV_TX_ERR, &trigger_data->mode) && in netdev_trig_work()
645 !test_bit(TRIGGER_NETDEV_RX_ERR, &trigger_data->mode)) in netdev_trig_work()
648 dev_stats = dev_get_stats(trigger_data->net_dev, &temp); in netdev_trig_work()
650 (test_bit(TRIGGER_NETDEV_TX, &trigger_data->mode) ? in netdev_trig_work()
651 dev_stats->tx_packets : 0) + in netdev_trig_work()
652 (test_bit(TRIGGER_NETDEV_RX, &trigger_data->mode) ? in netdev_trig_work()
653 dev_stats->rx_packets : 0) + in netdev_trig_work()
654 (test_bit(TRIGGER_NETDEV_TX_ERR, &trigger_data->mode) ? in netdev_trig_work()
655 dev_stats->tx_errors : 0) + in netdev_trig_work()
656 (test_bit(TRIGGER_NETDEV_RX_ERR, &trigger_data->mode) ? in netdev_trig_work()
657 dev_stats->rx_errors : 0); in netdev_trig_work()
659 if (trigger_data->last_activity != new_activity) { in netdev_trig_work()
660 led_stop_software_blink(trigger_data->led_cdev); in netdev_trig_work()
662 invert = test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode) || in netdev_trig_work()
663 test_bit(TRIGGER_NETDEV_LINK_10, &trigger_data->mode) || in netdev_trig_work()
664 test_bit(TRIGGER_NETDEV_LINK_100, &trigger_data->mode) || in netdev_trig_work()
665 test_bit(TRIGGER_NETDEV_LINK_1000, &trigger_data->mode) || in netdev_trig_work()
666 test_bit(TRIGGER_NETDEV_LINK_2500, &trigger_data->mode) || in netdev_trig_work()
667 test_bit(TRIGGER_NETDEV_LINK_5000, &trigger_data->mode) || in netdev_trig_work()
668 test_bit(TRIGGER_NETDEV_LINK_10000, &trigger_data->mode) || in netdev_trig_work()
669 test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &trigger_data->mode) || in netdev_trig_work()
670 test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &trigger_data->mode); in netdev_trig_work()
672 atomic_read(&trigger_data->interval)); in netdev_trig_work()
674 led_blink_set_oneshot(trigger_data->led_cdev, in netdev_trig_work()
678 trigger_data->last_activity = new_activity; in netdev_trig_work()
681 schedule_delayed_work(&trigger_data->work, in netdev_trig_work()
682 (atomic_read(&trigger_data->interval)*2)); in netdev_trig_work()
688 unsigned long mode = 0; in netdev_trig_activate() local
694 return -ENOMEM; in netdev_trig_activate()
696 mutex_init(&trigger_data->lock); in netdev_trig_activate()
698 trigger_data->notifier.notifier_call = netdev_trig_notify; in netdev_trig_activate()
699 trigger_data->notifier.priority = 10; in netdev_trig_activate()
701 INIT_DELAYED_WORK(&trigger_data->work, netdev_trig_work); in netdev_trig_activate()
703 trigger_data->led_cdev = led_cdev; in netdev_trig_activate()
704 trigger_data->net_dev = NULL; in netdev_trig_activate()
705 trigger_data->device_name[0] = 0; in netdev_trig_activate()
707 trigger_data->mode = 0; in netdev_trig_activate()
708 atomic_set(&trigger_data->interval, msecs_to_jiffies(NETDEV_LED_DEFAULT_INTERVAL)); in netdev_trig_activate()
709 trigger_data->last_activity = 0; in netdev_trig_activate()
712 * Init already enabled mode in hw control. in netdev_trig_activate()
715 dev = led_cdev->hw_control_get_device(led_cdev); in netdev_trig_activate()
719 trigger_data->hw_control = true; in netdev_trig_activate()
722 rc = led_cdev->hw_control_get(led_cdev, &mode); in netdev_trig_activate()
724 trigger_data->mode = mode; in netdev_trig_activate()
730 rc = register_netdevice_notifier(&trigger_data->notifier); in netdev_trig_activate()
741 unregister_netdevice_notifier(&trigger_data->notifier); in netdev_trig_deactivate()
743 cancel_delayed_work_sync(&trigger_data->work); in netdev_trig_deactivate()
745 dev_put(trigger_data->net_dev); in netdev_trig_deactivate()