* [PATCH net-next v2 1/7] dsa: move call to driver port_setup after creation of netdev.
2024-03-30 18:31 [PATCH net-next v2 0/7] net: Add generic support for netdev LEDs Andrew Lunn
@ 2024-03-30 18:31 ` Andrew Lunn
2024-03-30 18:31 ` [PATCH net-next v2 2/7] net: Add helpers for netdev LEDs Andrew Lunn
` (5 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Andrew Lunn @ 2024-03-30 18:31 UTC (permalink / raw)
To: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev, Andrew Lunn
The drivers call port_setup() is a good place to add the LEDs of a
port to the netdev representing the port. However, when port_setup()
is called in dsa_port_devlink_setup() the netdev does not exist
yet. That only happens in dsa_user_create() which is latter in
dsa_port_setup().
Move the call to port_setup() out of dsa_port_devlink_setup() and to
the end of dsa_port_setup() where the netdev will exist.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
net/dsa/devlink.c | 17 +----------------
net/dsa/dsa.c | 3 +++
2 files changed, 4 insertions(+), 16 deletions(-)
diff --git a/net/dsa/devlink.c b/net/dsa/devlink.c
index 431bf52290a1..9c3dc6319269 100644
--- a/net/dsa/devlink.c
+++ b/net/dsa/devlink.c
@@ -294,20 +294,12 @@ int dsa_port_devlink_setup(struct dsa_port *dp)
struct dsa_switch_tree *dst = dp->ds->dst;
struct devlink_port_attrs attrs = {};
struct devlink *dl = dp->ds->devlink;
- struct dsa_switch *ds = dp->ds;
const unsigned char *id;
unsigned char len;
- int err;
memset(dlp, 0, sizeof(*dlp));
devlink_port_init(dl, dlp);
- if (ds->ops->port_setup) {
- err = ds->ops->port_setup(ds, dp->index);
- if (err)
- return err;
- }
-
id = (const unsigned char *)&dst->index;
len = sizeof(dst->index);
@@ -331,14 +323,7 @@ int dsa_port_devlink_setup(struct dsa_port *dp)
}
devlink_port_attrs_set(dlp, &attrs);
- err = devlink_port_register(dl, dlp, dp->index);
- if (err) {
- if (ds->ops->port_teardown)
- ds->ops->port_teardown(ds, dp->index);
- return err;
- }
-
- return 0;
+ return devlink_port_register(dl, dlp, dp->index);
}
void dsa_port_devlink_teardown(struct dsa_port *dp)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 09d2f5d4b3dd..6ffee2a7de94 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -520,6 +520,9 @@ static int dsa_port_setup(struct dsa_port *dp)
break;
}
+ if (ds->ops->port_setup)
+ err = ds->ops->port_setup(ds, dp->index);
+
if (err && dsa_port_enabled)
dsa_port_disable(dp);
if (err && dsa_port_link_registered)
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v2 2/7] net: Add helpers for netdev LEDs
2024-03-30 18:31 [PATCH net-next v2 0/7] net: Add generic support for netdev LEDs Andrew Lunn
2024-03-30 18:31 ` [PATCH net-next v2 1/7] dsa: move call to driver port_setup after creation of netdev Andrew Lunn
@ 2024-03-30 18:31 ` Andrew Lunn
2024-03-30 18:32 ` [PATCH net-next v2 3/7] net: dsa: mv88e6xxx: Add helpers for 6352 LED blink and brightness Andrew Lunn
` (4 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Andrew Lunn @ 2024-03-30 18:31 UTC (permalink / raw)
To: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev, Andrew Lunn
Add a set of helpers for parsing the standard device tree properties
for LEDs as part of an ethernet device, and registering them with the
LED subsystem. This code can be used by any sort of netdev driver,
including plain MAC, DSA switches or pure switchdev switch driver.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
include/net/netdev_leds.h | 45 +++++++++++
net/Kconfig | 11 +++
net/core/Makefile | 1 +
net/core/netdev-leds.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 258 insertions(+)
diff --git a/include/net/netdev_leds.h b/include/net/netdev_leds.h
new file mode 100644
index 000000000000..239f492f29f5
--- /dev/null
+++ b/include/net/netdev_leds.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Helpers used for creating and managing LEDs on a netdev MAC
+ * driver.
+ */
+
+#ifndef _NET_NETDEV_LEDS_H
+#define _NET_NETDEV_LEDS_H
+
+struct netdev_leds_ops {
+ int (*brightness_set)(struct net_device *ndev, u8 led,
+ enum led_brightness brightness);
+ int (*blink_set)(struct net_device *ndev, u8 led,
+ unsigned long *delay_on, unsigned long *delay_off);
+ int (*hw_control_is_supported)(struct net_device *ndev, u8 led,
+ unsigned long flags);
+ int (*hw_control_set)(struct net_device *ndev, u8 led,
+ unsigned long flags);
+ int (*hw_control_get)(struct net_device *ndev, u8 led,
+ unsigned long *flags);
+};
+
+#ifdef CONFIG_NETDEV_LEDS
+int netdev_leds_setup(struct net_device *ndev, struct device_node *np,
+ struct list_head *list, struct netdev_leds_ops *ops,
+ int max_leds);
+
+void netdev_leds_teardown(struct list_head *list, struct net_device *ndev);
+
+#else
+static inline int netdev_leds_setup(struct net_device *ndev,
+ struct device_node *np,
+ struct list_head *list,
+ struct netdev_leds_ops *ops)
+{
+ return 0;
+}
+
+static inline void netdev_leds_teardown(struct list_head *list,
+ struct net_device *ndev)
+{
+}
+#endif /* CONFIG_NETDEV_LEDS */
+
+#endif /* _NET_PORT_LEDS_H */
diff --git a/net/Kconfig b/net/Kconfig
index 3e57ccf0da27..96b1543b5c6f 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -516,4 +516,15 @@ config NET_TEST
If unsure, say N.
+config NETDEV_LEDS
+ bool "NETDEV helper code for MAC LEDs"
+ depends on LEDS_CLASS
+ select LEDS_TRIGGERS
+ select LEDS_TRIGGER_NETDEV
+ help
+ NICs and Switches often contain LED controllers. When the LEDs
+ are part of the MAC, the MAC driver, aka netdev driver, should
+ make the LEDs available. NETDEV_LEDS offers a small library
+ of code to help MAC drivers do this.
+
endif # if NET
diff --git a/net/core/Makefile b/net/core/Makefile
index 6e6548011fae..9d887af68837 100644
--- a/net/core/Makefile
+++ b/net/core/Makefile
@@ -42,3 +42,4 @@ obj-$(CONFIG_BPF_SYSCALL) += sock_map.o
obj-$(CONFIG_BPF_SYSCALL) += bpf_sk_storage.o
obj-$(CONFIG_OF) += of_net.o
obj-$(CONFIG_NET_TEST) += gso_test.o
+obj-$(CONFIG_NETDEV_LEDS) += netdev-leds.o
diff --git a/net/core/netdev-leds.c b/net/core/netdev-leds.c
new file mode 100644
index 000000000000..802dd819a991
--- /dev/null
+++ b/net/core/netdev-leds.c
@@ -0,0 +1,201 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/leds.h>
+#include <linux/netdevice.h>
+#include <linux/of.h>
+#include <linux/slab.h>
+#include <net/netdev_leds.h>
+
+struct netdev_led {
+ struct list_head led_list;
+ struct led_classdev led_cdev;
+ struct netdev_leds_ops *ops;
+ struct net_device *ndev;
+ u8 index;
+};
+
+#define to_netdev_led(d) container_of(d, struct netdev_led, led_cdev)
+
+static int netdev_brightness_set(struct led_classdev *led_cdev,
+ enum led_brightness value)
+{
+ struct netdev_led *netdev_led = to_netdev_led(led_cdev);
+
+ return netdev_led->ops->brightness_set(netdev_led->ndev,
+ netdev_led->index,
+ value);
+}
+
+static int netdev_blink_set(struct led_classdev *led_cdev,
+ unsigned long *delay_on, unsigned long *delay_off)
+{
+ struct netdev_led *netdev_led = to_netdev_led(led_cdev);
+
+ return netdev_led->ops->blink_set(netdev_led->ndev,
+ netdev_led->index,
+ delay_on, delay_off);
+}
+
+static __maybe_unused int
+netdev_hw_control_is_supported(struct led_classdev *led_cdev,
+ unsigned long flags)
+{
+ struct netdev_led *netdev_led = to_netdev_led(led_cdev);
+
+ return netdev_led->ops->hw_control_is_supported(netdev_led->ndev,
+ netdev_led->index,
+ flags);
+}
+
+static __maybe_unused int netdev_hw_control_set(struct led_classdev *led_cdev,
+ unsigned long flags)
+{
+ struct netdev_led *netdev_led = to_netdev_led(led_cdev);
+
+ return netdev_led->ops->hw_control_set(netdev_led->ndev,
+ netdev_led->index,
+ flags);
+}
+
+static __maybe_unused int netdev_hw_control_get(struct led_classdev *led_cdev,
+ unsigned long *flags)
+{
+ struct netdev_led *netdev_led = to_netdev_led(led_cdev);
+
+ return netdev_led->ops->hw_control_get(netdev_led->ndev,
+ netdev_led->index,
+ flags);
+}
+
+static struct device *
+netdev_hw_control_get_device(struct led_classdev *led_cdev)
+{
+ struct netdev_led *netdev_led = to_netdev_led(led_cdev);
+
+ return &netdev_led->ndev->dev;
+}
+
+static int netdev_led_setup(struct net_device *ndev, struct device_node *led,
+ struct list_head *list, struct netdev_leds_ops *ops,
+ int max_leds)
+{
+ struct led_init_data init_data = {};
+ struct device *dev = &ndev->dev;
+ struct netdev_led *netdev_led;
+ struct led_classdev *cdev;
+ u32 index;
+ int err;
+
+ netdev_led = devm_kzalloc(dev, sizeof(*netdev_led), GFP_KERNEL);
+ if (!netdev_led)
+ return -ENOMEM;
+
+ netdev_led->ndev = ndev;
+ netdev_led->ops = ops;
+ cdev = &netdev_led->led_cdev;
+
+ err = of_property_read_u32(led, "reg", &index);
+ if (err)
+ return err;
+
+ if (index >= max_leds)
+ return -EINVAL;
+
+ netdev_led->index = index;
+
+ if (ops->brightness_set)
+ cdev->brightness_set_blocking = netdev_brightness_set;
+ if (ops->blink_set)
+ cdev->blink_set = netdev_blink_set;
+#ifdef CONFIG_LEDS_TRIGGERS
+ if (ops->hw_control_is_supported)
+ cdev->hw_control_is_supported = netdev_hw_control_is_supported;
+ if (ops->hw_control_set)
+ cdev->hw_control_set = netdev_hw_control_set;
+ if (ops->hw_control_get)
+ cdev->hw_control_get = netdev_hw_control_get;
+ cdev->hw_control_trigger = "netdev";
+#endif
+ cdev->hw_control_get_device = netdev_hw_control_get_device;
+ cdev->max_brightness = 1;
+ init_data.fwnode = of_fwnode_handle(led);
+ init_data.devname_mandatory = true;
+
+ init_data.devicename = dev_name(dev);
+ err = devm_led_classdev_register_ext(dev, cdev, &init_data);
+ if (err)
+ return err;
+
+ INIT_LIST_HEAD(&netdev_led->led_list);
+ list_add(&netdev_led->led_list, list);
+
+ return 0;
+}
+
+/**
+ * netdev_leds_setup - Parse DT node and create LEDs for netdev
+ *
+ * @ndev: struct netdev for the MAC
+ * @np: ethernet-node in device tree
+ * @list: list to add LEDs to
+ * @ops: structure of ops to manipulate the LED.
+ * @max_leds: maximum number of LEDs support by netdev.
+ *
+ * Parse the device tree node, as described in
+ * ethernet-controller.yaml, and find any LEDs. For each LED found,
+ * ensure the reg value is less than max_leds, create an LED and
+ * register it with the LED subsystem. The LED will be added to the
+ * list, which can be shared by all netdevs of the device. The ops
+ * structure contains the callbacks needed to control the LEDs.
+ *
+ * Return 0 in success, otherwise an negative error code.
+ */
+int netdev_leds_setup(struct net_device *ndev, struct device_node *np,
+ struct list_head *list, struct netdev_leds_ops *ops,
+ int max_leds)
+{
+ struct device_node *leds, *led;
+ int err;
+
+ leds = of_get_child_by_name(np, "leds");
+ if (!leds)
+ return 0;
+
+ for_each_available_child_of_node(leds, led) {
+ err = netdev_led_setup(ndev, led, list, ops, max_leds);
+ if (err) {
+ of_node_put(led);
+ return err;
+ }
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(netdev_leds_setup);
+
+/**
+ * netdev_leds_teardown - Remove LEDs for a netdev
+ *
+ * @list: list to add LEDs to teardown
+ * @ndev: The netdev for which LEDs should be removed
+ *
+ * Unregister all LEDs for a given netdev, freeing up any allocated
+ * memory.
+ */
+void netdev_leds_teardown(struct list_head *list, struct net_device *ndev)
+{
+ struct netdev_led *netdev_led;
+ struct led_classdev *cdev;
+ struct device *dev;
+
+ list_for_each_entry(netdev_led, list, led_list) {
+ if (netdev_led->ndev != ndev)
+ continue;
+ dev = &netdev_led->ndev->dev;
+ cdev = &netdev_led->led_cdev;
+ devm_led_classdev_unregister(dev, cdev);
+ }
+}
+EXPORT_SYMBOL_GPL(netdev_leds_teardown);
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v2 3/7] net: dsa: mv88e6xxx: Add helpers for 6352 LED blink and brightness
2024-03-30 18:31 [PATCH net-next v2 0/7] net: Add generic support for netdev LEDs Andrew Lunn
2024-03-30 18:31 ` [PATCH net-next v2 1/7] dsa: move call to driver port_setup after creation of netdev Andrew Lunn
2024-03-30 18:31 ` [PATCH net-next v2 2/7] net: Add helpers for netdev LEDs Andrew Lunn
@ 2024-03-30 18:32 ` Andrew Lunn
2024-03-30 18:32 ` [PATCH net-next v2 4/7] net: dsa: mv88e6xxx: Tie the low level LED functions to device ops Andrew Lunn
` (3 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Andrew Lunn @ 2024-03-30 18:32 UTC (permalink / raw)
To: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev, Andrew Lunn
The 6352 family has two LEDs per port for ports 0-4. Ports 5 and 6
share a couple of LEDs. Add support functions to set the brightness,
i.e. on or off, and to make the LEDs blink at a fixed rate.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/net/dsa/mv88e6xxx/port.c | 93 ++++++++++++++++++++++++++++++++++++++++
drivers/net/dsa/mv88e6xxx/port.h | 76 +++++++++++++++++++++++++++++++-
2 files changed, 168 insertions(+), 1 deletion(-)
diff --git a/drivers/net/dsa/mv88e6xxx/port.c b/drivers/net/dsa/mv88e6xxx/port.c
index 5394a8cf7bf1..37315a4aa9cf 100644
--- a/drivers/net/dsa/mv88e6xxx/port.c
+++ b/drivers/net/dsa/mv88e6xxx/port.c
@@ -1723,3 +1723,96 @@ int mv88e6393x_port_set_policy(struct mv88e6xxx_chip *chip, int port,
return mv88e6393x_port_policy_write(chip, port, ptr, reg);
}
+
+/* Offset 0x16: LED Control Register */
+
+static int mv88e6352_port_led_write(struct mv88e6xxx_chip *chip, int port,
+ u16 pointer, u16 data)
+{
+ u16 reg = MV88E6352_PORT_LED_CTL_UPDATE | pointer | data;
+
+ return mv88e6xxx_port_write(chip, port, MV88E6352_PORT_LED_CTL, reg);
+}
+
+static int mv88e6352_port_led_read(struct mv88e6xxx_chip *chip, int port,
+ u16 pointer, u16 *data)
+{
+ int err;
+ u16 val;
+
+ err = mv88e6xxx_port_write(chip, port, MV88E6352_PORT_LED_CTL, pointer);
+ if (err)
+ return err;
+
+ err = mv88e6xxx_port_read(chip, port, MV88E6352_PORT_LED_CTL, &val);
+ if (err)
+ return err;
+
+ *data = val & MV88E6352_PORT_LED_CTL_DATA_MASK;
+
+ return 0;
+}
+
+int mv88e6352_port_led_brightness_set(struct mv88e6xxx_chip *chip, int port,
+ u8 led, enum led_brightness value)
+{
+ int err;
+ u16 val;
+
+ if (port > 5)
+ return -EOPNOTSUPP;
+
+ err = mv88e6352_port_led_read(chip, port,
+ MV88E6352_PORT_LED_CTL_PTR_LED01,
+ &val);
+ if (err)
+ return err;
+
+ if (led == 0) {
+ val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK;
+ if (value)
+ val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_ON;
+ else
+ val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_OFF;
+ } else {
+ val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK;
+ if (value)
+ val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ON;
+ else
+ val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_OFF;
+ }
+ return mv88e6352_port_led_write(chip, port,
+ MV88E6352_PORT_LED_CTL_PTR_LED01,
+ val);
+}
+
+int mv88e6352_port_led_blink_set(struct mv88e6xxx_chip *chip, int port, u8 led,
+ unsigned long *delay_on,
+ unsigned long *delay_off)
+{
+ int err;
+ u16 val;
+
+ if (port > 5)
+ return -EOPNOTSUPP;
+
+ /* Reset default is 84ms */
+ *delay_on = 84 / 2;
+ *delay_off = 84 / 2;
+ err = mv88e6352_port_led_read(chip, port,
+ MV88E6352_PORT_LED_CTL_PTR_LED01,
+ &val);
+ if (err)
+ return err;
+
+ if (led == 0) {
+ val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK;
+ val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_BLINK;
+ } else {
+ val &= ~MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK;
+ val |= MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_BLINK;
+ }
+ return mv88e6352_port_led_write(chip, port,
+ MV88E6352_PORT_LED_CTL_PTR_LED01,
+ val);
+}
diff --git a/drivers/net/dsa/mv88e6xxx/port.h b/drivers/net/dsa/mv88e6xxx/port.h
index 86deeb347cbc..72556e4d154c 100644
--- a/drivers/net/dsa/mv88e6xxx/port.h
+++ b/drivers/net/dsa/mv88e6xxx/port.h
@@ -294,6 +294,76 @@
/* Offset 0x13: OutFiltered Counter */
#define MV88E6XXX_PORT_OUT_FILTERED 0x13
+/* Offset 0x16: LED Control */
+#define MV88E6352_PORT_LED_CTL 0x16
+#define MV88E6352_PORT_LED_CTL_UPDATE 0x8000
+#define MV88E6352_PORT_LED_CTL_PTR_LED01 0x0000
+#define MV88E6352_PORT_LED_CTL_PTR_STRETCH_BLINK 0x6000
+#define MV88E6352_PORT_LED_CTL_PTR_SPECIAL 0x7000
+#define MV88E6352_PORT_LED_CTL_DATA_MASK 0x03ff
+/* Ports 0-4 */
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_P2_SPECIAL 0x0000
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_100_ACT 0x0010
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_1000 0x0030
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_P1_SPECIAL 0x0040
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_1000_ACT 0x0060
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_1000 0x0070
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ACT 0x0080
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_100 0x0090
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_100_ACT 0x00A0
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_10_100 0x00B0
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_PTP_ACT 0x00C0
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_BLINK 0x00D0
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_OFF 0x00E0
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_ON 0x00F0
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_MASK 0x00F0
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED1_LINK_ACT 0x0000
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_100_1000_ACT 0x0001
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_1000_ACT 0x0002
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_LINK_ACT 0x0003
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_P0_SPECIAL 0x0004
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_DUPLEX_COL 0x0006
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10_1000_ACT 0x0007
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_LINK 0x0008
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10 0x0009
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_10_ACT 0x000A
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_100_1000 0x000B
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_PTP_ACT 0x000C
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_BLINK 0x000D
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_OFF 0x000E
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_ON 0x000F
+#define MV88E6352_PORT_LED_CTL_DATA_LED01_LED0_MASK 0x000F
+
+/* Port 5 */
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_ACT 0x0000
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER_1000_ACT 0x0010
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER_100_ACT 0x0020
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_FIBER 0x0030
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P5_ACT 0x0040
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_LINK 0x0050
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_DUPLEX_COL 0x0060
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_LINK_ACT 0x0070
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P0_SPECIAL 0x0080
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P1_SPECIAL 0x0090
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P2_SPECIAL 0x00A0
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P6_PTP_ACT 0x00C0
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_BLINK 0x00D0
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_OFF 0x00E0
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_ON 0x00F0
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED1_P5_LINK_ACT 0x0000
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_FIBER_100_ACT 0x0001
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_FIBER_1000_ACT 0x0002
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P0_SPECIAL 0x0003
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P1_SPECIAL 0x0004
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P2_SPECIAL 0x0005
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P5_DUPLEX_COL 0x0006
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P5_LINK_ACT 0x0007
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_P6_LINK_ACT 0x0008
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_BLINK 0x000D
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_OFF 0x000E
+#define MV88E6352_PORT_LED_CTL_DATA5_LED01_LED0_ON 0x000F
+/* Port 6 does not have any LEDs */
+
/* Offset 0x18: IEEE Priority Mapping Table */
#define MV88E6390_PORT_IEEE_PRIO_MAP_TABLE 0x18
#define MV88E6390_PORT_IEEE_PRIO_MAP_TABLE_UPDATE 0x8000
@@ -459,5 +529,9 @@ int mv88e6xxx_port_hidden_write(struct mv88e6xxx_chip *chip, int block,
int mv88e6xxx_port_hidden_wait(struct mv88e6xxx_chip *chip);
int mv88e6xxx_port_hidden_read(struct mv88e6xxx_chip *chip, int block, int port,
int reg, u16 *val);
-
+int mv88e6352_port_led_brightness_set(struct mv88e6xxx_chip *chip, int port,
+ u8 led, enum led_brightness value);
+int mv88e6352_port_led_blink_set(struct mv88e6xxx_chip *chip, int port, u8 led,
+ unsigned long *delay_on,
+ unsigned long *delay_off);
#endif /* _MV88E6XXX_PORT_H */
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v2 4/7] net: dsa: mv88e6xxx: Tie the low level LED functions to device ops
2024-03-30 18:31 [PATCH net-next v2 0/7] net: Add generic support for netdev LEDs Andrew Lunn
` (2 preceding siblings ...)
2024-03-30 18:32 ` [PATCH net-next v2 3/7] net: dsa: mv88e6xxx: Add helpers for 6352 LED blink and brightness Andrew Lunn
@ 2024-03-30 18:32 ` Andrew Lunn
2024-03-30 18:32 ` [PATCH net-next v2 5/7] net: dsa: Add helpers to convert netdev to ds or port index Andrew Lunn
` (2 subsequent siblings)
6 siblings, 0 replies; 11+ messages in thread
From: Andrew Lunn @ 2024-03-30 18:32 UTC (permalink / raw)
To: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev, Andrew Lunn
Make the LED brightness and blink helpers available for the 6352
family via their ops structure.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/net/dsa/mv88e6xxx/chip.c | 8 ++++++++
drivers/net/dsa/mv88e6xxx/chip.h | 7 +++++++
2 files changed, 15 insertions(+)
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 9ed1821184ec..3d7e4aa9293a 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -4526,6 +4526,8 @@ static const struct mv88e6xxx_ops mv88e6172_ops = {
.gpio_ops = &mv88e6352_gpio_ops,
.phylink_get_caps = mv88e6352_phylink_get_caps,
.pcs_ops = &mv88e6352_pcs_ops,
+ .led_brightness_set = mv88e6352_port_led_brightness_set,
+ .led_blink_set = mv88e6352_port_led_blink_set,
};
static const struct mv88e6xxx_ops mv88e6175_ops = {
@@ -4628,6 +4630,8 @@ static const struct mv88e6xxx_ops mv88e6176_ops = {
.gpio_ops = &mv88e6352_gpio_ops,
.phylink_get_caps = mv88e6352_phylink_get_caps,
.pcs_ops = &mv88e6352_pcs_ops,
+ .led_brightness_set = mv88e6352_port_led_brightness_set,
+ .led_blink_set = mv88e6352_port_led_blink_set,
};
static const struct mv88e6xxx_ops mv88e6185_ops = {
@@ -4897,6 +4901,8 @@ static const struct mv88e6xxx_ops mv88e6240_ops = {
.ptp_ops = &mv88e6352_ptp_ops,
.phylink_get_caps = mv88e6352_phylink_get_caps,
.pcs_ops = &mv88e6352_pcs_ops,
+ .led_brightness_set = mv88e6352_port_led_brightness_set,
+ .led_blink_set = mv88e6352_port_led_blink_set,
};
static const struct mv88e6xxx_ops mv88e6250_ops = {
@@ -5310,6 +5316,8 @@ static const struct mv88e6xxx_ops mv88e6352_ops = {
.serdes_set_tx_amplitude = mv88e6352_serdes_set_tx_amplitude,
.phylink_get_caps = mv88e6352_phylink_get_caps,
.pcs_ops = &mv88e6352_pcs_ops,
+ .led_brightness_set = mv88e6352_port_led_brightness_set,
+ .led_blink_set = mv88e6352_port_led_blink_set,
};
static const struct mv88e6xxx_ops mv88e6390_ops = {
diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h
index 85eb293381a7..64f8bde68ccf 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.h
+++ b/drivers/net/dsa/mv88e6xxx/chip.h
@@ -661,6 +661,13 @@ struct mv88e6xxx_ops {
/* Max Frame Size */
int (*set_max_frame_size)(struct mv88e6xxx_chip *chip, int mtu);
+
+ /* LEDs */
+ int (*led_brightness_set)(struct mv88e6xxx_chip *chip, int port,
+ u8 led, enum led_brightness value);
+ int (*led_blink_set)(struct mv88e6xxx_chip *chip, int port, u8 led,
+ unsigned long *delay_on,
+ unsigned long *delay_off);
};
struct mv88e6xxx_irq_ops {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v2 5/7] net: dsa: Add helpers to convert netdev to ds or port index
2024-03-30 18:31 [PATCH net-next v2 0/7] net: Add generic support for netdev LEDs Andrew Lunn
` (3 preceding siblings ...)
2024-03-30 18:32 ` [PATCH net-next v2 4/7] net: dsa: mv88e6xxx: Tie the low level LED functions to device ops Andrew Lunn
@ 2024-03-30 18:32 ` Andrew Lunn
2024-03-30 18:32 ` [PATCH net-next v2 6/7] dsa: mv88e6xxx: Create port/netdev LEDs Andrew Lunn
2024-03-30 18:32 ` [PATCH net-next v2 7/7] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs Andrew Lunn
6 siblings, 0 replies; 11+ messages in thread
From: Andrew Lunn @ 2024-03-30 18:32 UTC (permalink / raw)
To: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev, Andrew Lunn
The LED helpers make use of a struct netdev. Add helpers a DSA driver
can use to convert a netdev to a struct dsa_switch and the port index.
To do this, dsa_user_to_port() has to be made available out side of
net/dev, to convert the inline function in net/dsa/user.h into a
normal function, and export it.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
include/net/dsa.h | 17 +++++++++++++++++
net/dsa/user.c | 8 ++++++++
net/dsa/user.h | 7 -------
3 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 7c0da9effe4e..1fbfada6678d 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -1359,6 +1359,23 @@ int dsa_register_switch(struct dsa_switch *ds);
void dsa_switch_shutdown(struct dsa_switch *ds);
struct dsa_switch *dsa_switch_find(int tree_index, int sw_index);
void dsa_flush_workqueue(void);
+
+struct dsa_port *dsa_user_to_port(const struct net_device *dev);
+
+static inline struct dsa_switch *dsa_user_to_ds(const struct net_device *ndev)
+{
+ struct dsa_port *dp = dsa_user_to_port(ndev);
+
+ return dp->ds;
+}
+
+static inline unsigned int dsa_user_to_index(const struct net_device *ndev)
+{
+ struct dsa_port *dp = dsa_user_to_port(ndev);
+
+ return dp->index;
+}
+
#ifdef CONFIG_PM_SLEEP
int dsa_switch_suspend(struct dsa_switch *ds);
int dsa_switch_resume(struct dsa_switch *ds);
diff --git a/net/dsa/user.c b/net/dsa/user.c
index 16d395bb1a1f..bbee3f63e2c7 100644
--- a/net/dsa/user.c
+++ b/net/dsa/user.c
@@ -3699,3 +3699,11 @@ void dsa_user_unregister_notifier(void)
if (err)
pr_err("DSA: failed to unregister user notifier (%d)\n", err);
}
+
+struct dsa_port *dsa_user_to_port(const struct net_device *dev)
+{
+ struct dsa_user_priv *p = netdev_priv(dev);
+
+ return p->dp;
+}
+EXPORT_SYMBOL_GPL(dsa_user_to_port);
diff --git a/net/dsa/user.h b/net/dsa/user.h
index 996069130bea..b6bcf027643e 100644
--- a/net/dsa/user.h
+++ b/net/dsa/user.h
@@ -51,13 +51,6 @@ int dsa_user_change_conduit(struct net_device *dev, struct net_device *conduit,
int dsa_user_manage_vlan_filtering(struct net_device *dev,
bool vlan_filtering);
-static inline struct dsa_port *dsa_user_to_port(const struct net_device *dev)
-{
- struct dsa_user_priv *p = netdev_priv(dev);
-
- return p->dp;
-}
-
static inline struct net_device *
dsa_user_to_conduit(const struct net_device *dev)
{
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* [PATCH net-next v2 6/7] dsa: mv88e6xxx: Create port/netdev LEDs
2024-03-30 18:31 [PATCH net-next v2 0/7] net: Add generic support for netdev LEDs Andrew Lunn
` (4 preceding siblings ...)
2024-03-30 18:32 ` [PATCH net-next v2 5/7] net: dsa: Add helpers to convert netdev to ds or port index Andrew Lunn
@ 2024-03-30 18:32 ` Andrew Lunn
2024-03-31 15:55 ` Russell King (Oracle)
2024-03-30 18:32 ` [PATCH net-next v2 7/7] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs Andrew Lunn
6 siblings, 1 reply; 11+ messages in thread
From: Andrew Lunn @ 2024-03-30 18:32 UTC (permalink / raw)
To: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev, Andrew Lunn
Make use of the helpers to add LEDs to the user ports when the port is
setup.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
drivers/net/dsa/mv88e6xxx/Kconfig | 1 +
drivers/net/dsa/mv88e6xxx/chip.c | 117 +++++++++++++++++++++++++++++++++++++-
drivers/net/dsa/mv88e6xxx/chip.h | 12 ++++
3 files changed, 129 insertions(+), 1 deletion(-)
diff --git a/drivers/net/dsa/mv88e6xxx/Kconfig b/drivers/net/dsa/mv88e6xxx/Kconfig
index e3181d5471df..ded5c6b9132b 100644
--- a/drivers/net/dsa/mv88e6xxx/Kconfig
+++ b/drivers/net/dsa/mv88e6xxx/Kconfig
@@ -5,6 +5,7 @@ config NET_DSA_MV88E6XXX
select IRQ_DOMAIN
select NET_DSA_TAG_EDSA
select NET_DSA_TAG_DSA
+ select NETDEV_LEDS
help
This driver adds support for most of the Marvell 88E6xxx models of
Ethernet switch chips, except 88E6060.
diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 3d7e4aa9293a..b8e39dcad2da 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -31,6 +31,7 @@
#include <linux/gpio/consumer.h>
#include <linux/phylink.h>
#include <net/dsa.h>
+#include <net/netdev_leds.h>
#include "chip.h"
#include "devlink.h"
@@ -3129,6 +3130,105 @@ static int mv88e6xxx_switch_reset(struct mv88e6xxx_chip *chip)
return mv88e6xxx_software_reset(chip);
}
+static int mv88e6xxx_led_brightness_set(struct net_device *ndev,
+ u8 led, enum led_brightness value)
+{
+ struct dsa_switch *ds = dsa_user_to_ds(ndev);
+ struct mv88e6xxx_chip *chip = ds->priv;
+ int port = dsa_user_to_index(ndev);
+ int err;
+
+ if (chip->info->ops->led_brightness_set) {
+ mv88e6xxx_reg_lock(chip);
+ err = chip->info->ops->led_brightness_set(chip, port, led,
+ value);
+ mv88e6xxx_reg_unlock(chip);
+ return err;
+ }
+ return -EOPNOTSUPP;
+}
+
+static int mv88e6xxx_led_blink_set(struct net_device *ndev, u8 led,
+ unsigned long *delay_on,
+ unsigned long *delay_off)
+{
+ struct dsa_switch *ds = dsa_user_to_ds(ndev);
+ struct mv88e6xxx_chip *chip = ds->priv;
+ int port = dsa_user_to_index(ndev);
+ int err;
+
+ if (chip->info->ops->led_blink_set) {
+ mv88e6xxx_reg_lock(chip);
+ err = chip->info->ops->led_blink_set(chip, port, led,
+ delay_on, delay_off);
+ mv88e6xxx_reg_unlock(chip);
+ return err;
+ }
+ return -EOPNOTSUPP;
+}
+
+static int mv88e6xxx_led_hw_control_is_supported(struct net_device *ndev,
+ u8 led, unsigned long flags)
+{
+ struct dsa_switch *ds = dsa_user_to_ds(ndev);
+ struct mv88e6xxx_chip *chip = ds->priv;
+ int port = dsa_user_to_index(ndev);
+ int err;
+
+ if (chip->info->ops->led_hw_control_is_supported) {
+ mv88e6xxx_reg_lock(chip);
+ err = chip->info->ops->led_hw_control_is_supported(chip, port,
+ led, flags);
+ mv88e6xxx_reg_unlock(chip);
+ return err;
+ }
+ return -EOPNOTSUPP;
+}
+
+static int mv88e6xxx_led_hw_control_set(struct net_device *ndev, u8 led,
+ unsigned long flags)
+{
+ struct dsa_switch *ds = dsa_user_to_ds(ndev);
+ struct mv88e6xxx_chip *chip = ds->priv;
+ int port = dsa_user_to_index(ndev);
+ int err;
+
+ if (chip->info->ops->led_hw_control_set) {
+ mv88e6xxx_reg_lock(chip);
+ err = chip->info->ops->led_hw_control_set(chip, port,
+ led, flags);
+ mv88e6xxx_reg_unlock(chip);
+ return err;
+ }
+ return -EOPNOTSUPP;
+}
+
+static int mv88e6xxx_led_hw_control_get(struct net_device *ndev,
+ u8 led, unsigned long *flags)
+{
+ struct dsa_switch *ds = dsa_user_to_ds(ndev);
+ struct mv88e6xxx_chip *chip = ds->priv;
+ int port = dsa_user_to_index(ndev);
+ int err;
+
+ if (chip->info->ops->led_hw_control_get) {
+ mv88e6xxx_reg_lock(chip);
+ err = chip->info->ops->led_hw_control_get(chip, port,
+ led, flags);
+ mv88e6xxx_reg_unlock(chip);
+ return err;
+ }
+ return -EOPNOTSUPP;
+}
+
+static struct netdev_leds_ops mv88e6xxx_netdev_leds_ops = {
+ .brightness_set = mv88e6xxx_led_brightness_set,
+ .blink_set = mv88e6xxx_led_blink_set,
+ .hw_control_is_supported = mv88e6xxx_led_hw_control_is_supported,
+ .hw_control_set = mv88e6xxx_led_hw_control_set,
+ .hw_control_get = mv88e6xxx_led_hw_control_get,
+};
+
static int mv88e6xxx_set_port_mode(struct mv88e6xxx_chip *chip, int port,
enum mv88e6xxx_frame_mode frame,
enum mv88e6xxx_egress_mode egress, u16 etype)
@@ -4006,6 +4106,7 @@ static int mv88e6xxx_setup(struct dsa_switch *ds)
static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
{
+ struct dsa_port *dp = dsa_to_port(ds, port);
struct mv88e6xxx_chip *chip = ds->priv;
int err;
@@ -4016,13 +4117,26 @@ static int mv88e6xxx_port_setup(struct dsa_switch *ds, int port)
return err;
}
- return mv88e6xxx_setup_devlink_regions_port(ds, port);
+ err = mv88e6xxx_setup_devlink_regions_port(ds, port);
+ if (err)
+ return err;
+
+ if (dp->dn) {
+ err = netdev_leds_setup(dp->user, dp->dn, &chip->leds,
+ &mv88e6xxx_netdev_leds_ops, 2);
+ if (err)
+ mv88e6xxx_teardown_devlink_regions_port(ds, port);
+ }
+ return err;
}
static void mv88e6xxx_port_teardown(struct dsa_switch *ds, int port)
{
+ struct dsa_port *dp = dsa_to_port(ds, port);
struct mv88e6xxx_chip *chip = ds->priv;
+ netdev_leds_teardown(&chip->leds, dp->user);
+
mv88e6xxx_teardown_devlink_regions_port(ds, port);
if (chip->info->ops->pcs_ops &&
@@ -6397,6 +6511,7 @@ static struct mv88e6xxx_chip *mv88e6xxx_alloc_chip(struct device *dev)
INIT_LIST_HEAD(&chip->mdios);
idr_init(&chip->policies);
INIT_LIST_HEAD(&chip->msts);
+ INIT_LIST_HEAD(&chip->leds);
return chip;
}
diff --git a/drivers/net/dsa/mv88e6xxx/chip.h b/drivers/net/dsa/mv88e6xxx/chip.h
index 64f8bde68ccf..b70e74203b31 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.h
+++ b/drivers/net/dsa/mv88e6xxx/chip.h
@@ -432,6 +432,9 @@ struct mv88e6xxx_chip {
/* Bridge MST to SID mappings */
struct list_head msts;
+
+ /* LEDs associated to the ports */
+ struct list_head leds;
};
struct mv88e6xxx_bus_ops {
@@ -668,6 +671,15 @@ struct mv88e6xxx_ops {
int (*led_blink_set)(struct mv88e6xxx_chip *chip, int port, u8 led,
unsigned long *delay_on,
unsigned long *delay_off);
+ int (*led_hw_control_is_supported)(struct mv88e6xxx_chip *chip,
+ int port, u8 led,
+ unsigned long flags);
+ int (*led_hw_control_set)(struct mv88e6xxx_chip *chip,
+ int port, u8 led,
+ unsigned long flags);
+ int (*led_hw_control_get)(struct mv88e6xxx_chip *chip,
+ int port, u8 led,
+ unsigned long *flags);
};
struct mv88e6xxx_irq_ops {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net-next v2 6/7] dsa: mv88e6xxx: Create port/netdev LEDs
2024-03-30 18:32 ` [PATCH net-next v2 6/7] dsa: mv88e6xxx: Create port/netdev LEDs Andrew Lunn
@ 2024-03-31 15:55 ` Russell King (Oracle)
2024-04-01 12:43 ` Andrew Lunn
0 siblings, 1 reply; 11+ messages in thread
From: Russell King (Oracle) @ 2024-03-31 15:55 UTC (permalink / raw)
To: Andrew Lunn
Cc: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Gregory Clement, netdev
On Sat, Mar 30, 2024 at 01:32:03PM -0500, Andrew Lunn wrote:
> +static int mv88e6xxx_led_brightness_set(struct net_device *ndev,
> + u8 led, enum led_brightness value)
> +{
> + struct dsa_switch *ds = dsa_user_to_ds(ndev);
> + struct mv88e6xxx_chip *chip = ds->priv;
> + int port = dsa_user_to_index(ndev);
This breaks the model that the DSA layer contains shims to translate
stuff to a dsa_switch pointer and port index. That's not a complaint.
I think it's the right way forward, because the shim later feels like
it makes maintenance needlessly more complex.
I have been thinking whether to do the same for the various phylink
functions - having DSA drivers provide the phylink_mac_ops themselves
where they implement the phylink ops, and convert from the "config"
to dsa_switch+port or whatever is suitable for them where necessary.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH net-next v2 6/7] dsa: mv88e6xxx: Create port/netdev LEDs
2024-03-31 15:55 ` Russell King (Oracle)
@ 2024-04-01 12:43 ` Andrew Lunn
0 siblings, 0 replies; 11+ messages in thread
From: Andrew Lunn @ 2024-04-01 12:43 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Gregory Clement, netdev
On Sun, Mar 31, 2024 at 04:55:44PM +0100, Russell King (Oracle) wrote:
> On Sat, Mar 30, 2024 at 01:32:03PM -0500, Andrew Lunn wrote:
>
> > +static int mv88e6xxx_led_brightness_set(struct net_device *ndev,
> > + u8 led, enum led_brightness value)
> > +{
> > + struct dsa_switch *ds = dsa_user_to_ds(ndev);
> > + struct mv88e6xxx_chip *chip = ds->priv;
> > + int port = dsa_user_to_index(ndev);
>
> This breaks the model that the DSA layer contains shims to translate
> stuff to a dsa_switch pointer and port index. That's not a complaint.
> I think it's the right way forward, because the shim later feels like
> it makes maintenance needlessly more complex.
It was something Vladimir requested after reviewing a patchset trying
to reuse parts of a DSA driver in a pure switchdev driver. He wanted
more generic building blocks which could be put together in different
ways. It does result in more boilerplate code in each callback, but
the helpers i added keep it down.
> I have been thinking whether to do the same for the various phylink
> functions - having DSA drivers provide the phylink_mac_ops themselves
> where they implement the phylink ops, and convert from the "config"
> to dsa_switch+port or whatever is suitable for them where necessary.
If it helps, do it. But i would suggest adding helpers to try to keep
the boilerplate down. That is mostly what the wrappers in the DSA core
do, centralise the boilerplate so we only have one copy.
Andrew
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH net-next v2 7/7] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs
2024-03-30 18:31 [PATCH net-next v2 0/7] net: Add generic support for netdev LEDs Andrew Lunn
` (5 preceding siblings ...)
2024-03-30 18:32 ` [PATCH net-next v2 6/7] dsa: mv88e6xxx: Create port/netdev LEDs Andrew Lunn
@ 2024-03-30 18:32 ` Andrew Lunn
2024-03-31 16:35 ` Florian Fainelli
6 siblings, 1 reply; 11+ messages in thread
From: Andrew Lunn @ 2024-03-30 18:32 UTC (permalink / raw)
To: Florian Fainelli, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev, Andrew Lunn
List the front panel Ethernet LEDs in the switch section of the
device tree. They can then be controlled via /sys/class/led/
The node contains a label property to influence the name of the LED.
Without it, all the LEDs get the name lan:white, which classes, and so
some get a number appended. lan:white_1, lan:white_2, etc. Using the
label the LEDs are named lan1:front, lan2:front, lan3:front, where
lanX indicates the interface name, and front indicates they are on the
front of the box.
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
---
.../boot/dts/marvell/armada-xp-linksys-mamba.dts | 66 ++++++++++++++++++++++
1 file changed, 66 insertions(+)
diff --git a/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts b/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts
index ea859f7ea042..90d5a47a608e 100644
--- a/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts
+++ b/arch/arm/boot/dts/marvell/armada-xp-linksys-mamba.dts
@@ -19,6 +19,7 @@
/dts-v1/;
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>
+#include <dt-bindings/leds/common.h>
#include "armada-xp-mv78230.dtsi"
/ {
@@ -276,26 +277,91 @@ ethernet-ports {
ethernet-port@0 {
reg = <0>;
label = "lan4";
+
+ leds {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_WHITE>;
+ function = LED_FUNCTION_LAN;
+ label = "front";
+ default-state = "keep";
+ };
+ };
};
ethernet-port@1 {
reg = <1>;
label = "lan3";
+
+ leds {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_WHITE>;
+ function = LED_FUNCTION_LAN;
+ label = "front";
+ default-state = "keep";
+ };
+ };
};
ethernet-port@2 {
reg = <2>;
label = "lan2";
+
+ leds {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_WHITE>;
+ function = LED_FUNCTION_LAN;
+ label = "front";
+ default-state = "keep";
+ };
+ };
};
ethernet-port@3 {
reg = <3>;
label = "lan1";
+
+ leds {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_WHITE>;
+ function = LED_FUNCTION_LAN;
+ label = "front";
+ default-state = "keep";
+ };
+ };
};
ethernet-port@4 {
reg = <4>;
label = "internet";
+
+ leds {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_WHITE>;
+ function = LED_FUNCTION_LAN;
+ label = "front";
+ default-state = "keep";
+ };
+ };
};
ethernet-port@5 {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH net-next v2 7/7] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs
2024-03-30 18:32 ` [PATCH net-next v2 7/7] arm: boot: dts: mvebu: linksys-mamba: Add Ethernet LEDs Andrew Lunn
@ 2024-03-31 16:35 ` Florian Fainelli
0 siblings, 0 replies; 11+ messages in thread
From: Florian Fainelli @ 2024-03-31 16:35 UTC (permalink / raw)
To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Russell King, Gregory Clement
Cc: netdev
On 3/30/2024 11:32 AM, Andrew Lunn wrote:
> List the front panel Ethernet LEDs in the switch section of the
> device tree. They can then be controlled via /sys/class/led/
>
> The node contains a label property to influence the name of the LED.
> Without it, all the LEDs get the name lan:white, which classes, and so
> some get a number appended. lan:white_1, lan:white_2, etc. Using the
> label the LEDs are named lan1:front, lan2:front, lan3:front, where
> lanX indicates the interface name, and front indicates they are on the
> front of the box.
>
> Signed-off-by: Andrew Lunn <andrew@lunn.ch>
> ---
[snip]
> ethernet-port@4 {
> reg = <4>;
> label = "internet";
> +
> + leds {
> + #address-cells = <1>;
> + #size-cells = <0>;
> +
> + led@0 {
> + reg = <0>;
> + color = <LED_COLOR_ID_WHITE>;
> + function = LED_FUNCTION_LAN;
Should this be LED_FUNCTION_WAN since this is the "internet" label?
--
Florian
^ permalink raw reply [flat|nested] 11+ messages in thread