kernel: backport fixes for realtek r8152
[openwrt/openwrt.git] / target / linux / generic / backport-5.15 / 769-v5.19-02-net-dsa-qca8k-drop-port_sts-from-qca8k_priv.patch
1 From 2b8fd87af7f156942971789abac8ee2bb60c03bc Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Sat, 16 Apr 2022 01:30:13 +0200
4 Subject: [PATCH 2/6] net: dsa: qca8k: drop port_sts from qca8k_priv
5
6 Port_sts is a thing of the past for this driver. It was something
7 present on the initial implementation of this driver and parts of the
8 original struct were dropped over time. Using an array of int to store if
9 a port is enabled or not to handle PM operation seems overkill. Switch
10 and use a simple u8 to store the port status where each bit correspond
11 to a port. (bit is set port is enabled, bit is not set, port is disabled)
12 Also add some comments to better describe why we need to track port
13 status.
14
15 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
16 Reviewed-by: Vladimir Oltean <olteanv@gmail.com>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
18 ---
19 drivers/net/dsa/qca8k.c | 15 +++++++++------
20 drivers/net/dsa/qca8k.h | 9 ++++-----
21 2 files changed, 13 insertions(+), 11 deletions(-)
22
23 --- a/drivers/net/dsa/qca8k.c
24 +++ b/drivers/net/dsa/qca8k.c
25 @@ -2494,7 +2494,7 @@ qca8k_port_enable(struct dsa_switch *ds,
26 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
27
28 qca8k_port_set_status(priv, port, 1);
29 - priv->port_sts[port].enabled = 1;
30 + priv->port_enabled_map |= BIT(port);
31
32 if (dsa_is_user_port(ds, port))
33 phy_support_asym_pause(phy);
34 @@ -2508,7 +2508,7 @@ qca8k_port_disable(struct dsa_switch *ds
35 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
36
37 qca8k_port_set_status(priv, port, 0);
38 - priv->port_sts[port].enabled = 0;
39 + priv->port_enabled_map &= ~BIT(port);
40 }
41
42 static int
43 @@ -2531,19 +2531,19 @@ qca8k_port_change_mtu(struct dsa_switch
44 * Turn off both cpu ports before applying the new value to prevent
45 * this.
46 */
47 - if (priv->port_sts[0].enabled)
48 + if (priv->port_enabled_map & BIT(0))
49 qca8k_port_set_status(priv, 0, 0);
50
51 - if (priv->port_sts[6].enabled)
52 + if (priv->port_enabled_map & BIT(6))
53 qca8k_port_set_status(priv, 6, 0);
54
55 /* Include L2 header / FCS length */
56 ret = qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, new_mtu + ETH_HLEN + ETH_FCS_LEN);
57
58 - if (priv->port_sts[0].enabled)
59 + if (priv->port_enabled_map & BIT(0))
60 qca8k_port_set_status(priv, 0, 1);
61
62 - if (priv->port_sts[6].enabled)
63 + if (priv->port_enabled_map & BIT(6))
64 qca8k_port_set_status(priv, 6, 1);
65
66 return ret;
67 @@ -3199,13 +3199,16 @@ static void qca8k_sw_shutdown(struct mdi
68 static void
69 qca8k_set_pm(struct qca8k_priv *priv, int enable)
70 {
71 - int i;
72 + int port;
73
74 - for (i = 0; i < QCA8K_NUM_PORTS; i++) {
75 - if (!priv->port_sts[i].enabled)
76 + for (port = 0; port < QCA8K_NUM_PORTS; port++) {
77 + /* Do not enable on resume if the port was
78 + * disabled before.
79 + */
80 + if (!(priv->port_enabled_map & BIT(port)))
81 continue;
82
83 - qca8k_port_set_status(priv, i, enable);
84 + qca8k_port_set_status(priv, port, enable);
85 }
86 }
87
88 --- a/drivers/net/dsa/qca8k.h
89 +++ b/drivers/net/dsa/qca8k.h
90 @@ -324,10 +324,6 @@ enum qca8k_mid_cmd {
91 QCA8K_MIB_CAST = 3,
92 };
93
94 -struct ar8xxx_port_status {
95 - int enabled;
96 -};
97 -
98 struct qca8k_match_data {
99 u8 id;
100 bool reduced_package;
101 @@ -382,11 +378,14 @@ struct qca8k_priv {
102 u8 mirror_rx;
103 u8 mirror_tx;
104 u8 lag_hash_mode;
105 + /* Each bit correspond to a port. This switch can support a max of 7 port.
106 + * Bit 1: port enabled. Bit 0: port disabled.
107 + */
108 + u8 port_enabled_map;
109 bool legacy_phy_port_mapping;
110 struct qca8k_ports_config ports_config;
111 struct regmap *regmap;
112 struct mii_bus *bus;
113 - struct ar8xxx_port_status port_sts[QCA8K_NUM_PORTS];
114 struct dsa_switch *ds;
115 struct mutex reg_mutex;
116 struct device *dev;