drivers/net/ethernet/realtek/r8169_leds.c
Source file repositories/reference/linux-study-clean/drivers/net/ethernet/realtek/r8169_leds.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ethernet/realtek/r8169_leds.c- Extension
.c- Size
- 7711 bytes
- Lines
- 276
- Domain
- Driver Families
- Bucket
- drivers/net
- 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.
- 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/leds.hlinux/netdevice.huapi/linux/uleds.hr8169.h
Detected Declarations
struct r8169_led_classdevfunction r8169_trigger_mode_is_validfunction rtl8168_led_hw_control_is_supportedfunction rtl8168_led_hw_control_setfunction rtl8168_led_hw_control_getfunction r8169_led_hw_control_get_devicefunction rtl8168_setup_ldevfunction rtl8125_led_hw_control_is_supportedfunction rtl8125_led_hw_control_setfunction rtl8125_led_hw_control_getfunction rtl8125_setup_led_ldevfunction r8169_remove_leds
Annotated Snippet
struct r8169_led_classdev {
struct led_classdev led;
struct net_device *ndev;
int index;
};
#define lcdev_to_r8169_ldev(lcdev) container_of(lcdev, struct r8169_led_classdev, led)
static bool r8169_trigger_mode_is_valid(unsigned long flags)
{
bool rx, tx;
if (flags & BIT(TRIGGER_NETDEV_HALF_DUPLEX))
return false;
if (flags & BIT(TRIGGER_NETDEV_FULL_DUPLEX))
return false;
rx = flags & BIT(TRIGGER_NETDEV_RX);
tx = flags & BIT(TRIGGER_NETDEV_TX);
return rx == tx;
}
static int rtl8168_led_hw_control_is_supported(struct led_classdev *led_cdev,
unsigned long flags)
{
struct r8169_led_classdev *ldev = lcdev_to_r8169_ldev(led_cdev);
struct rtl8169_private *tp = netdev_priv(ldev->ndev);
int shift = ldev->index * 4;
if (!r8169_trigger_mode_is_valid(flags)) {
/* Switch LED off to indicate that mode isn't supported */
rtl8168_led_mod_ctrl(tp, 0x000f << shift, 0);
return -EOPNOTSUPP;
}
return 0;
}
static int rtl8168_led_hw_control_set(struct led_classdev *led_cdev,
unsigned long flags)
{
struct r8169_led_classdev *ldev = lcdev_to_r8169_ldev(led_cdev);
struct rtl8169_private *tp = netdev_priv(ldev->ndev);
int shift = ldev->index * 4;
u16 mode = 0;
if (flags & BIT(TRIGGER_NETDEV_LINK_10))
mode |= RTL8168_LED_CTRL_LINK_10;
if (flags & BIT(TRIGGER_NETDEV_LINK_100))
mode |= RTL8168_LED_CTRL_LINK_100;
if (flags & BIT(TRIGGER_NETDEV_LINK_1000))
mode |= RTL8168_LED_CTRL_LINK_1000;
if (flags & BIT(TRIGGER_NETDEV_TX))
mode |= RTL8168_LED_CTRL_ACT;
return rtl8168_led_mod_ctrl(tp, 0x000f << shift, mode << shift);
}
static int rtl8168_led_hw_control_get(struct led_classdev *led_cdev,
unsigned long *flags)
{
struct r8169_led_classdev *ldev = lcdev_to_r8169_ldev(led_cdev);
struct rtl8169_private *tp = netdev_priv(ldev->ndev);
int shift = ldev->index * 4;
int mode;
mode = rtl8168_get_led_mode(tp);
if (mode < 0)
return mode;
if (mode & RTL8168_LED_CTRL_OPTION2) {
rtl8168_led_mod_ctrl(tp, RTL8168_LED_CTRL_OPTION2, 0);
netdev_notice(ldev->ndev, "Deactivating unsupported Option2 LED mode\n");
}
mode = (mode >> shift) & 0x000f;
if (mode & RTL8168_LED_CTRL_ACT)
*flags |= BIT(TRIGGER_NETDEV_TX) | BIT(TRIGGER_NETDEV_RX);
if (mode & RTL8168_LED_CTRL_LINK_10)
*flags |= BIT(TRIGGER_NETDEV_LINK_10);
if (mode & RTL8168_LED_CTRL_LINK_100)
*flags |= BIT(TRIGGER_NETDEV_LINK_100);
if (mode & RTL8168_LED_CTRL_LINK_1000)
*flags |= BIT(TRIGGER_NETDEV_LINK_1000);
return 0;
}
Annotation
- Immediate include surface: `linux/leds.h`, `linux/netdevice.h`, `uapi/linux/uleds.h`, `r8169.h`.
- Detected declarations: `struct r8169_led_classdev`, `function r8169_trigger_mode_is_valid`, `function rtl8168_led_hw_control_is_supported`, `function rtl8168_led_hw_control_set`, `function rtl8168_led_hw_control_get`, `function r8169_led_hw_control_get_device`, `function rtl8168_setup_ldev`, `function rtl8125_led_hw_control_is_supported`, `function rtl8125_led_hw_control_set`, `function rtl8125_led_hw_control_get`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
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.