kernel: backport ethtool_puts
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 818-v6.5-13-net-dsa-qca8k-add-op-to-get-ports-netdev.patch
1 From 4f53c27f772e27e4cf4e5507d6f4d5980002cb6a Mon Sep 17 00:00:00 2001
2 From: Andrew Lunn <andrew@lunn.ch>
3 Date: Mon, 29 May 2023 18:32:43 +0200
4 Subject: [PATCH 13/13] net: dsa: qca8k: add op to get ports netdev
5
6 In order that the LED trigger can blink the switch MAC ports LED, it
7 needs to know the netdev associated to the port. Add the callback to
8 return the struct device of the netdev.
9
10 Add an helper function qca8k_phy_to_port() to convert the phy back to
11 dsa_port index, as we reference LED port based on the internal PHY
12 index and needs to be converted back.
13
14 Signed-off-by: Andrew Lunn <andrew@lunn.ch>
15 Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
17 ---
18 drivers/net/dsa/qca/qca8k-leds.c | 27 +++++++++++++++++++++++++++
19 1 file changed, 27 insertions(+)
20
21 --- a/drivers/net/dsa/qca/qca8k-leds.c
22 +++ b/drivers/net/dsa/qca/qca8k-leds.c
23 @@ -5,6 +5,18 @@
24 #include "qca8k.h"
25 #include "qca8k_leds.h"
26
27 +static u32 qca8k_phy_to_port(int phy)
28 +{
29 + /* Internal PHY 0 has port at index 1.
30 + * Internal PHY 1 has port at index 2.
31 + * Internal PHY 2 has port at index 3.
32 + * Internal PHY 3 has port at index 4.
33 + * Internal PHY 4 has port at index 5.
34 + */
35 +
36 + return phy + 1;
37 +}
38 +
39 static int
40 qca8k_get_enable_led_reg(int port_num, int led_num, struct qca8k_led_pattern_en *reg_info)
41 {
42 @@ -314,6 +326,20 @@ qca8k_cled_hw_control_get(struct led_cla
43 return 0;
44 }
45
46 +static struct device *qca8k_cled_hw_control_get_device(struct led_classdev *ldev)
47 +{
48 + struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev);
49 + struct qca8k_priv *priv = led->priv;
50 + struct dsa_port *dp;
51 +
52 + dp = dsa_to_port(priv->ds, qca8k_phy_to_port(led->port_num));
53 + if (!dp)
54 + return NULL;
55 + if (dp->slave)
56 + return &dp->slave->dev;
57 + return NULL;
58 +}
59 +
60 static int
61 qca8k_parse_port_leds(struct qca8k_priv *priv, struct fwnode_handle *port, int port_num)
62 {
63 @@ -377,6 +403,7 @@ qca8k_parse_port_leds(struct qca8k_priv
64 port_led->cdev.hw_control_is_supported = qca8k_cled_hw_control_is_supported;
65 port_led->cdev.hw_control_set = qca8k_cled_hw_control_set;
66 port_led->cdev.hw_control_get = qca8k_cled_hw_control_get;
67 + port_led->cdev.hw_control_get_device = qca8k_cled_hw_control_get_device;
68 port_led->cdev.hw_control_trigger = "netdev";
69 init_data.default_label = ":port";
70 init_data.fwnode = led;