drivers/leds/trigger/ledtrig-netdev.c
Source file repositories/reference/linux-study-clean/drivers/leds/trigger/ledtrig-netdev.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/trigger/ledtrig-netdev.c- Extension
.c- Size
- 22013 bytes
- Lines
- 771
- Domain
- Driver Families
- Bucket
- drivers/leds
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/ctype.hlinux/device.hlinux/ethtool.hlinux/init.hlinux/jiffies.hlinux/kernel.hlinux/leds.hlinux/linkmode.hlinux/list.hlinux/module.hlinux/netdevice.hlinux/mutex.hlinux/phy.hlinux/rtnetlink.hlinux/timer.hnet/netdev_lock.h../leds.h
Detected Declarations
struct led_netdev_datafunction set_baseline_statefunction supports_hw_controlfunction validate_net_devfunction can_hw_controlfunction get_device_statefunction device_name_showfunction set_device_namefunction device_name_storefunction netdev_led_attr_showfunction netdev_led_attr_storefunction interval_showfunction interval_storefunction offloaded_showfunction netdev_trig_link_speed_visiblefunction netdev_trig_notifyfunction netdev_trig_workfunction netdev_trig_activatefunction netdev_trig_deactivate
Annotated Snippet
struct led_netdev_data {
struct mutex 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;
int link_speed;
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported_link_modes);
u8 duplex;
bool carrier_link_up;
bool hw_control;
};
static const struct attribute_group netdev_trig_link_speed_attrs_group;
static void set_baseline_state(struct led_netdev_data *trigger_data)
{
int current_brightness;
struct led_classdev *led_cdev = trigger_data->led_cdev;
/* Already validated, hw control is possible with the requested mode */
if (trigger_data->hw_control) {
led_cdev->hw_control_set(led_cdev, trigger_data->mode);
return;
}
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 (!trigger_data->carrier_link_up) {
led_set_brightness(led_cdev, LED_OFF);
} else {
bool blink_on = false;
if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
blink_on = true;
if (test_bit(TRIGGER_NETDEV_LINK_10, &trigger_data->mode) &&
trigger_data->link_speed == SPEED_10)
blink_on = true;
if (test_bit(TRIGGER_NETDEV_LINK_100, &trigger_data->mode) &&
trigger_data->link_speed == SPEED_100)
blink_on = true;
if (test_bit(TRIGGER_NETDEV_LINK_1000, &trigger_data->mode) &&
trigger_data->link_speed == SPEED_1000)
blink_on = true;
if (test_bit(TRIGGER_NETDEV_LINK_2500, &trigger_data->mode) &&
trigger_data->link_speed == SPEED_2500)
blink_on = true;
if (test_bit(TRIGGER_NETDEV_LINK_5000, &trigger_data->mode) &&
trigger_data->link_speed == SPEED_5000)
blink_on = true;
if (test_bit(TRIGGER_NETDEV_LINK_10000, &trigger_data->mode) &&
trigger_data->link_speed == SPEED_10000)
blink_on = true;
if (test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &trigger_data->mode) &&
trigger_data->duplex == DUPLEX_HALF)
blink_on = true;
if (test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &trigger_data->mode) &&
trigger_data->duplex == DUPLEX_FULL)
blink_on = true;
if (blink_on)
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
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/ctype.h`, `linux/device.h`, `linux/ethtool.h`, `linux/init.h`, `linux/jiffies.h`, `linux/kernel.h`, `linux/leds.h`.
- Detected declarations: `struct led_netdev_data`, `function set_baseline_state`, `function supports_hw_control`, `function validate_net_dev`, `function can_hw_control`, `function get_device_state`, `function device_name_show`, `function set_device_name`, `function device_name_store`, `function netdev_led_attr_show`.
- Atlas domain: Driver Families / drivers/leds.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.