mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-27 03:10:12 +00:00
Immutable branch between LEDs and netdev due for the v6.5 merge window
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEdrbJNaO+IJqU8IdIUa+KL4f8d2EFAmRvQw8ACgkQUa+KL4f8 d2GwdA/+LcxQ8qoNe6TmVcf/VTHwFhUmLVPTIT54i6Qdh8sDcXcwIyd/Yb/qGGz4 /DAeDBYkovwns9belGcdf3K4A6v+VgCV2yJhwU83Ikjm5TaA7iOkav4BLY/54zww nWZr+UH9QTGGXiJF6GmkgpRgw6nR19pkZzmkbrooMCowv7Xbw1d0T9N4oIrT6ffQ JZwlstPBra0kYh92vbpl8XY6HUdRZRTXCTpnueCZGnicPkFRcyYULHhemkcym6e8 IFay08lRB2AetjwJkzgvLfH8L3rHLykM2rM5L5xyyoC3IFMzO1Z/BM2dyLOe9dE3 P611nMY12/aFzOACt8msvq3ACHci3U4amc/13b+MasZM21m5HqO4XGURgifJ0NY6 MfjyslF6EUOupSLl/LWrpiK1gZVfPbQR40Jpu2s8uXr22CcfMaYbOX8hbvjX9SRZ gRpChFyykXDSFlASRglSGvjFtxQ/9nUSlLjWO54G6l8Zm09L4kwvOB1B9tSvsS/N 2TV/lyk7KvEhHpGOqPvLmLw+UEvo1iUqCOI9olenouSmztnzbwJx4S7YqwNO7puj 67bUG6jT57F1Dcn6/ft+/CavvaFvuhAGAcOPIMmWtvXqRyTkV53cUPjCSD7zojXH x3xJEYTLgEoXmhajQV/r5cYkAXMNFiYEVPhQ9BBG97fRtJDfmR4= =oefJ -----END PGP SIGNATURE----- Merge tag 'ib-leds-netdev-v6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds Lee Jones says: ==================== Immutable branch between LEDs and netdev due for the v6.5 merge window Andrew Lunn says: Christian Marangi and I will be continuing the work of offloading LED blinking to Ethernet MAC and PHY LED controllers. The next set of patches is again cross subsystem, LEDs and netdev. It also requires some patches you have in for-leds-next: a286befc24e8 leds: trigger: netdev: Use mutex instead of spinlocks 509412749002 leds: trigger: netdev: Convert device attr to macro 0fd93ac85826 leds: trigger: netdev: Rename add namespace to netdev trigger enum modes eb31ca4531a0 leds: trigger: netdev: Drop NETDEV_LED_MODE_LINKUP from mode 3fc498cf54b4 leds: trigger: netdev: Recheck NETDEV_LED_MODE_LINKUP on dev rename I'm assuming the new series will get nerged via netdev, with your Acked-by. Could you create a stable branch with these patches which can be pulled into netdev? * tag 'ib-leds-netdev-v6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/leds: leds: trigger: netdev: Use mutex instead of spinlocks leds: trigger: netdev: Convert device attr to macro leds: trigger: netdev: Rename add namespace to netdev trigger enum modes leds: trigger: netdev: Drop NETDEV_LED_MODE_LINKUP from mode leds: trigger: netdev: Recheck NETDEV_LED_MODE_LINKUP on dev rename ==================== Link: https://lore.kernel.org/r/20230525111521.GA411262@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
commit
78dbc2468d
1 changed files with 58 additions and 91 deletions
|
@ -20,7 +20,7 @@
|
|||
#include <linux/list.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/timer.h>
|
||||
#include "../leds.h"
|
||||
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
struct led_netdev_data {
|
||||
spinlock_t lock;
|
||||
struct mutex lock;
|
||||
|
||||
struct delayed_work work;
|
||||
struct notifier_block notifier;
|
||||
|
@ -50,16 +50,16 @@ struct led_netdev_data {
|
|||
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
|
||||
bool carrier_link_up;
|
||||
};
|
||||
|
||||
enum netdev_led_attr {
|
||||
NETDEV_ATTR_LINK,
|
||||
NETDEV_ATTR_TX,
|
||||
NETDEV_ATTR_RX
|
||||
enum led_trigger_netdev_modes {
|
||||
TRIGGER_NETDEV_LINK = 0,
|
||||
TRIGGER_NETDEV_TX,
|
||||
TRIGGER_NETDEV_RX,
|
||||
|
||||
/* Keep last */
|
||||
__TRIGGER_NETDEV_MAX,
|
||||
};
|
||||
|
||||
static void set_baseline_state(struct led_netdev_data *trigger_data)
|
||||
|
@ -73,10 +73,10 @@ static void set_baseline_state(struct led_netdev_data *trigger_data)
|
|||
if (!led_cdev->blink_brightness)
|
||||
led_cdev->blink_brightness = led_cdev->max_brightness;
|
||||
|
||||
if (!test_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode))
|
||||
if (!trigger_data->carrier_link_up) {
|
||||
led_set_brightness(led_cdev, LED_OFF);
|
||||
else {
|
||||
if (test_bit(NETDEV_LED_LINK, &trigger_data->mode))
|
||||
} else {
|
||||
if (test_bit(TRIGGER_NETDEV_LINK, &trigger_data->mode))
|
||||
led_set_brightness(led_cdev,
|
||||
led_cdev->blink_brightness);
|
||||
else
|
||||
|
@ -85,8 +85,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);
|
||||
}
|
||||
}
|
||||
|
@ -97,9 +97,9 @@ static ssize_t device_name_show(struct device *dev,
|
|||
struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
|
||||
ssize_t len;
|
||||
|
||||
spin_lock_bh(&trigger_data->lock);
|
||||
mutex_lock(&trigger_data->lock);
|
||||
len = sprintf(buf, "%s\n", trigger_data->device_name);
|
||||
spin_unlock_bh(&trigger_data->lock);
|
||||
mutex_unlock(&trigger_data->lock);
|
||||
|
||||
return len;
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ static ssize_t device_name_store(struct device *dev,
|
|||
|
||||
cancel_delayed_work_sync(&trigger_data->work);
|
||||
|
||||
spin_lock_bh(&trigger_data->lock);
|
||||
mutex_lock(&trigger_data->lock);
|
||||
|
||||
if (trigger_data->net_dev) {
|
||||
dev_put(trigger_data->net_dev);
|
||||
|
@ -131,15 +131,14 @@ static ssize_t device_name_store(struct device *dev,
|
|||
trigger_data->net_dev =
|
||||
dev_get_by_name(&init_net, trigger_data->device_name);
|
||||
|
||||
clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
|
||||
trigger_data->carrier_link_up = false;
|
||||
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->carrier_link_up = netif_carrier_ok(trigger_data->net_dev);
|
||||
|
||||
trigger_data->last_activity = 0;
|
||||
|
||||
set_baseline_state(trigger_data);
|
||||
spin_unlock_bh(&trigger_data->lock);
|
||||
mutex_unlock(&trigger_data->lock);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
@ -147,20 +146,16 @@ static ssize_t device_name_store(struct device *dev,
|
|||
static DEVICE_ATTR_RW(device_name);
|
||||
|
||||
static ssize_t netdev_led_attr_show(struct device *dev, char *buf,
|
||||
enum netdev_led_attr attr)
|
||||
enum led_trigger_netdev_modes attr)
|
||||
{
|
||||
struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
|
||||
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;
|
||||
case TRIGGER_NETDEV_LINK:
|
||||
case TRIGGER_NETDEV_TX:
|
||||
case TRIGGER_NETDEV_RX:
|
||||
bit = attr;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
|
@ -170,7 +165,7 @@ static ssize_t netdev_led_attr_show(struct device *dev, char *buf,
|
|||
}
|
||||
|
||||
static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
|
||||
size_t size, enum netdev_led_attr attr)
|
||||
size_t size, enum led_trigger_netdev_modes attr)
|
||||
{
|
||||
struct led_netdev_data *trigger_data = led_trigger_get_drvdata(dev);
|
||||
unsigned long state;
|
||||
|
@ -182,14 +177,10 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
|
|||
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;
|
||||
case TRIGGER_NETDEV_LINK:
|
||||
case TRIGGER_NETDEV_TX:
|
||||
case TRIGGER_NETDEV_RX:
|
||||
bit = attr;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
|
@ -207,47 +198,22 @@ static ssize_t netdev_led_attr_store(struct device *dev, const char *buf,
|
|||
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);
|
||||
}
|
||||
#define DEFINE_NETDEV_TRIGGER(trigger_name, trigger) \
|
||||
static ssize_t trigger_name##_show(struct device *dev, \
|
||||
struct device_attribute *attr, char *buf) \
|
||||
{ \
|
||||
return netdev_led_attr_show(dev, buf, trigger); \
|
||||
} \
|
||||
static ssize_t trigger_name##_store(struct device *dev, \
|
||||
struct device_attribute *attr, const char *buf, size_t size) \
|
||||
{ \
|
||||
return netdev_led_attr_store(dev, buf, size, trigger); \
|
||||
} \
|
||||
static DEVICE_ATTR_RW(trigger_name)
|
||||
|
||||
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);
|
||||
DEFINE_NETDEV_TRIGGER(link, TRIGGER_NETDEV_LINK);
|
||||
DEFINE_NETDEV_TRIGGER(tx, TRIGGER_NETDEV_TX);
|
||||
DEFINE_NETDEV_TRIGGER(rx, TRIGGER_NETDEV_RX);
|
||||
|
||||
static ssize_t interval_show(struct device *dev,
|
||||
struct device_attribute *attr, char *buf)
|
||||
|
@ -313,11 +279,13 @@ static int netdev_trig_notify(struct notifier_block *nb,
|
|||
|
||||
cancel_delayed_work_sync(&trigger_data->work);
|
||||
|
||||
spin_lock_bh(&trigger_data->lock);
|
||||
mutex_lock(&trigger_data->lock);
|
||||
|
||||
clear_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
|
||||
trigger_data->carrier_link_up = false;
|
||||
switch (evt) {
|
||||
case NETDEV_CHANGENAME:
|
||||
trigger_data->carrier_link_up = netif_carrier_ok(dev);
|
||||
fallthrough;
|
||||
case NETDEV_REGISTER:
|
||||
if (trigger_data->net_dev)
|
||||
dev_put(trigger_data->net_dev);
|
||||
|
@ -330,14 +298,13 @@ static int netdev_trig_notify(struct notifier_block *nb,
|
|||
break;
|
||||
case NETDEV_UP:
|
||||
case NETDEV_CHANGE:
|
||||
if (netif_carrier_ok(dev))
|
||||
set_bit(NETDEV_LED_MODE_LINKUP, &trigger_data->mode);
|
||||
trigger_data->carrier_link_up = netif_carrier_ok(dev);
|
||||
break;
|
||||
}
|
||||
|
||||
set_baseline_state(trigger_data);
|
||||
|
||||
spin_unlock_bh(&trigger_data->lock);
|
||||
mutex_unlock(&trigger_data->lock);
|
||||
|
||||
return NOTIFY_DONE;
|
||||
}
|
||||
|
@ -360,21 +327,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) */
|
||||
|
@ -398,7 +365,7 @@ static int netdev_trig_activate(struct led_classdev *led_cdev)
|
|||
if (!trigger_data)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_init(&trigger_data->lock);
|
||||
mutex_init(&trigger_data->lock);
|
||||
|
||||
trigger_data->notifier.notifier_call = netdev_trig_notify;
|
||||
trigger_data->notifier.priority = 10;
|
||||
|
|
Loading…
Reference in a new issue