1 From aaf421425cbdec4eb6fd75a29e65c2867b0b7bbd Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Fri, 14 May 2021 22:59:57 +0200
4 Subject: [PATCH] net: dsa: qca8k: handle error with qca8k_rmw operation
6 qca8k_rmw can fail. Rework any user to handle error values and
7 correctly return. Change qca8k_rmw to return the error code or 0 instead
8 of the reg value. The reg returned by qca8k_rmw wasn't used anywhere,
9 so this doesn't cause any functional change.
11 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
12 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
13 Signed-off-by: David S. Miller <davem@davemloft.net>
15 drivers/net/dsa/qca8k.c | 133 +++++++++++++++++++++++++---------------
16 1 file changed, 83 insertions(+), 50 deletions(-)
18 --- a/drivers/net/dsa/qca8k.c
19 +++ b/drivers/net/dsa/qca8k.c
20 @@ -190,12 +190,13 @@ exit:
25 -qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 val)
27 +qca8k_rmw(struct qca8k_priv *priv, u32 reg, u32 mask, u32 write_val)
29 struct mii_bus *bus = priv->bus;
35 qca8k_split_addr(reg, &r1, &r2, &page);
37 @@ -205,10 +206,15 @@ qca8k_rmw(struct qca8k_priv *priv, u32 r
41 - ret = qca8k_mii_read32(bus, 0x10 | r2, r1);
44 - qca8k_mii_write32(bus, 0x10 | r2, r1, ret);
45 + val = qca8k_mii_read32(bus, 0x10 | r2, r1);
53 + qca8k_mii_write32(bus, 0x10 | r2, r1, val);
56 mutex_unlock(&bus->mdio_lock);
57 @@ -216,16 +222,16 @@ exit:
63 qca8k_reg_set(struct qca8k_priv *priv, u32 reg, u32 val)
65 - qca8k_rmw(priv, reg, 0, val);
66 + return qca8k_rmw(priv, reg, 0, val);
71 qca8k_reg_clear(struct qca8k_priv *priv, u32 reg, u32 val)
73 - qca8k_rmw(priv, reg, val, 0);
74 + return qca8k_rmw(priv, reg, val, 0);
78 @@ -570,12 +576,19 @@ qca8k_mib_init(struct qca8k_priv *priv)
81 mutex_lock(&priv->reg_mutex);
82 - qca8k_reg_set(priv, QCA8K_REG_MIB, QCA8K_MIB_FLUSH | QCA8K_MIB_BUSY);
83 + ret = qca8k_reg_set(priv, QCA8K_REG_MIB, QCA8K_MIB_FLUSH | QCA8K_MIB_BUSY);
87 qca8k_busy_wait(priv, QCA8K_REG_MIB, QCA8K_MIB_BUSY);
88 - qca8k_reg_set(priv, QCA8K_REG_MIB, QCA8K_MIB_CPU_KEEP);
90 + ret = qca8k_reg_set(priv, QCA8K_REG_MIB, QCA8K_MIB_CPU_KEEP);
94 ret = qca8k_write(priv, QCA8K_REG_MODULE_EN, QCA8K_MODULE_EN_MIB);
97 mutex_unlock(&priv->reg_mutex);
100 @@ -747,9 +760,8 @@ qca8k_setup_mdio_bus(struct qca8k_priv *
101 * a dt-overlay and driver reload changed the configuration
104 - qca8k_reg_clear(priv, QCA8K_MDIO_MASTER_CTRL,
105 - QCA8K_MDIO_MASTER_EN);
107 + return qca8k_reg_clear(priv, QCA8K_MDIO_MASTER_CTRL,
108 + QCA8K_MDIO_MASTER_EN);
111 priv->ops.phy_read = qca8k_phy_read;
112 @@ -782,8 +794,12 @@ qca8k_setup(struct dsa_switch *ds)
115 /* Enable CPU Port */
116 - qca8k_reg_set(priv, QCA8K_REG_GLOBAL_FW_CTRL0,
117 - QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN);
118 + ret = qca8k_reg_set(priv, QCA8K_REG_GLOBAL_FW_CTRL0,
119 + QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN);
121 + dev_err(priv->dev, "failed enabling CPU port");
125 /* Enable MIB counters */
126 ret = qca8k_mib_init(priv);
127 @@ -800,9 +816,12 @@ qca8k_setup(struct dsa_switch *ds)
130 /* Disable forwarding by default on all ports */
131 - for (i = 0; i < QCA8K_NUM_PORTS; i++)
132 - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
133 - QCA8K_PORT_LOOKUP_MEMBER, 0);
134 + for (i = 0; i < QCA8K_NUM_PORTS; i++) {
135 + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
136 + QCA8K_PORT_LOOKUP_MEMBER, 0);
141 /* Disable MAC by default on all ports */
142 for (i = 1; i < QCA8K_NUM_PORTS; i++)
143 @@ -821,28 +840,37 @@ qca8k_setup(struct dsa_switch *ds)
144 for (i = 0; i < QCA8K_NUM_PORTS; i++) {
145 /* CPU port gets connected to all user ports of the switch */
146 if (dsa_is_cpu_port(ds, i)) {
147 - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(QCA8K_CPU_PORT),
148 - QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds));
149 + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(QCA8K_CPU_PORT),
150 + QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds));
155 /* Individual user ports get connected to CPU port only */
156 if (dsa_is_user_port(ds, i)) {
157 int shift = 16 * (i % 2);
159 - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
160 - QCA8K_PORT_LOOKUP_MEMBER,
161 - BIT(QCA8K_CPU_PORT));
162 + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i),
163 + QCA8K_PORT_LOOKUP_MEMBER,
164 + BIT(QCA8K_CPU_PORT));
168 /* Enable ARP Auto-learning by default */
169 - qca8k_reg_set(priv, QCA8K_PORT_LOOKUP_CTRL(i),
170 - QCA8K_PORT_LOOKUP_LEARN);
171 + ret = qca8k_reg_set(priv, QCA8K_PORT_LOOKUP_CTRL(i),
172 + QCA8K_PORT_LOOKUP_LEARN);
176 /* For port based vlans to work we need to set the
179 - qca8k_rmw(priv, QCA8K_EGRESS_VLAN(i),
181 - QCA8K_PORT_VID_DEF << shift);
182 + ret = qca8k_rmw(priv, QCA8K_EGRESS_VLAN(i),
184 + QCA8K_PORT_VID_DEF << shift);
188 ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(i),
189 QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
190 QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
191 @@ -1234,7 +1262,7 @@ qca8k_port_bridge_join(struct dsa_switch
193 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
194 int port_mask = BIT(QCA8K_CPU_PORT);
198 for (i = 1; i < QCA8K_NUM_PORTS; i++) {
199 if (dsa_to_port(ds, i)->bridge_dev != br)
200 @@ -1242,17 +1270,20 @@ qca8k_port_bridge_join(struct dsa_switch
201 /* Add this port to the portvlan mask of the other ports
204 - qca8k_reg_set(priv,
205 - QCA8K_PORT_LOOKUP_CTRL(i),
207 + ret = qca8k_reg_set(priv,
208 + QCA8K_PORT_LOOKUP_CTRL(i),
216 /* Add all other ports to this ports portvlan mask */
217 - qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
218 - QCA8K_PORT_LOOKUP_MEMBER, port_mask);
219 + ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(port),
220 + QCA8K_PORT_LOOKUP_MEMBER, port_mask);