eb21cc3912461c6fb2e507790c1b5d2292a8939e
[openwrt/staging/ldir.git] /
1 From cddbec19466a1dfb4d45ddd507d9f09f991d54ae Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Wed, 2 Feb 2022 01:03:28 +0100
4 Subject: [PATCH 09/16] net: dsa: qca8k: add tracking state of master port
5
6 MDIO/MIB Ethernet require the master port and the tagger availabale to
7 correctly work. Use the new api master_state_change to track when master
8 is operational or not and set a bool in qca8k_priv.
9 We cache the first cached master available and we check if other cpu
10 port are operational when the cached one goes down.
11 This cached master will later be used by mdio read/write and mib request to
12 correctly use the working function.
13
14 qca8k implementation for MDIO/MIB Ethernet is bad. CPU port0 is the only
15 one that answers with the ack packet or sends MIB Ethernet packets. For
16 this reason the master_state_change ignore CPU port6 and only checks
17 CPU port0 if it's operational and enables this mode.
18
19 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
20 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
21 Signed-off-by: David S. Miller <davem@davemloft.net>
22 ---
23 drivers/net/dsa/qca8k.c | 15 +++++++++++++++
24 drivers/net/dsa/qca8k.h | 1 +
25 2 files changed, 16 insertions(+)
26
27 --- a/drivers/net/dsa/qca8k.c
28 +++ b/drivers/net/dsa/qca8k.c
29 @@ -2401,6 +2401,20 @@ qca8k_port_lag_leave(struct dsa_switch *
30 return qca8k_lag_refresh_portmap(ds, port, lag, true);
31 }
32
33 +static void
34 +qca8k_master_change(struct dsa_switch *ds, const struct net_device *master,
35 + bool operational)
36 +{
37 + struct dsa_port *dp = master->dsa_ptr;
38 + struct qca8k_priv *priv = ds->priv;
39 +
40 + /* Ethernet MIB/MDIO is only supported for CPU port 0 */
41 + if (dp->index != 0)
42 + return;
43 +
44 + priv->mgmt_master = operational ? (struct net_device *)master : NULL;
45 +}
46 +
47 static const struct dsa_switch_ops qca8k_switch_ops = {
48 .get_tag_protocol = qca8k_get_tag_protocol,
49 .setup = qca8k_setup,
50 @@ -2436,6 +2450,7 @@ static const struct dsa_switch_ops qca8k
51 .get_phy_flags = qca8k_get_phy_flags,
52 .port_lag_join = qca8k_port_lag_join,
53 .port_lag_leave = qca8k_port_lag_leave,
54 + .master_state_change = qca8k_master_change,
55 };
56
57 static int qca8k_read_switch_id(struct qca8k_priv *priv)
58 --- a/drivers/net/dsa/qca8k.h
59 +++ b/drivers/net/dsa/qca8k.h
60 @@ -353,6 +353,7 @@ struct qca8k_priv {
61 struct dsa_switch_ops ops;
62 struct gpio_desc *reset_gpio;
63 unsigned int port_mtu[QCA8K_NUM_PORTS];
64 + struct net_device *mgmt_master; /* Track if mdio/mib Ethernet is available */
65 };
66
67 struct qca8k_mib_desc {