1 From d7805757c75c76e9518fc1023a29f0c4eed5b581 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Fri, 14 May 2021 22:59:56 +0200
4 Subject: [PATCH] net: dsa: qca8k: handle error with qca8k_write operation
6 qca8k_write can fail. Rework any user to handle error values and
9 Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
10 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
11 Signed-off-by: David S. Miller <davem@davemloft.net>
13 drivers/net/dsa/qca8k.c | 102 ++++++++++++++++++++++++++--------------
14 1 file changed, 67 insertions(+), 35 deletions(-)
16 --- a/drivers/net/dsa/qca8k.c
17 +++ b/drivers/net/dsa/qca8k.c
18 @@ -168,7 +168,7 @@ exit:
24 qca8k_write(struct qca8k_priv *priv, u32 reg, u32 val)
26 struct mii_bus *bus = priv->bus;
27 @@ -187,6 +187,7 @@ qca8k_write(struct qca8k_priv *priv, u32
30 mutex_unlock(&bus->mdio_lock);
35 @@ -247,9 +248,7 @@ qca8k_regmap_write(void *ctx, uint32_t r
37 struct qca8k_priv *priv = (struct qca8k_priv *)ctx;
39 - qca8k_write(priv, reg, val);
42 + return qca8k_write(priv, reg, val);
45 static const struct regmap_range qca8k_readable_ranges[] = {
46 @@ -367,6 +366,7 @@ static int
47 qca8k_fdb_access(struct qca8k_priv *priv, enum qca8k_fdb_cmd cmd, int port)
52 /* Set the command and FDB index */
53 reg = QCA8K_ATU_FUNC_BUSY;
54 @@ -377,7 +377,9 @@ qca8k_fdb_access(struct qca8k_priv *priv
57 /* Write the function register triggering the table access */
58 - qca8k_write(priv, QCA8K_REG_ATU_FUNC, reg);
59 + ret = qca8k_write(priv, QCA8K_REG_ATU_FUNC, reg);
63 /* wait for completion */
64 if (qca8k_busy_wait(priv, QCA8K_REG_ATU_FUNC, QCA8K_ATU_FUNC_BUSY))
65 @@ -447,6 +449,7 @@ static int
66 qca8k_vlan_access(struct qca8k_priv *priv, enum qca8k_vlan_cmd cmd, u16 vid)
71 /* Set the command and VLAN index */
72 reg = QCA8K_VTU_FUNC1_BUSY;
73 @@ -454,7 +457,9 @@ qca8k_vlan_access(struct qca8k_priv *pri
74 reg |= vid << QCA8K_VTU_FUNC1_VID_S;
76 /* Write the function register triggering the table access */
77 - qca8k_write(priv, QCA8K_REG_VTU_FUNC1, reg);
78 + ret = qca8k_write(priv, QCA8K_REG_VTU_FUNC1, reg);
82 /* wait for completion */
83 if (qca8k_busy_wait(priv, QCA8K_REG_VTU_FUNC1, QCA8K_VTU_FUNC1_BUSY))
84 @@ -502,7 +507,9 @@ qca8k_vlan_add(struct qca8k_priv *priv,
85 reg |= QCA8K_VTU_FUNC0_EG_MODE_TAG <<
86 QCA8K_VTU_FUNC0_EG_MODE_S(port);
88 - qca8k_write(priv, QCA8K_REG_VTU_FUNC0, reg);
89 + ret = qca8k_write(priv, QCA8K_REG_VTU_FUNC0, reg);
92 ret = qca8k_vlan_access(priv, QCA8K_VLAN_LOAD, vid);
95 @@ -545,7 +552,9 @@ qca8k_vlan_del(struct qca8k_priv *priv,
97 ret = qca8k_vlan_access(priv, QCA8K_VLAN_PURGE, vid);
99 - qca8k_write(priv, QCA8K_REG_VTU_FUNC0, reg);
100 + ret = qca8k_write(priv, QCA8K_REG_VTU_FUNC0, reg);
103 ret = qca8k_vlan_access(priv, QCA8K_VLAN_LOAD, vid);
106 @@ -555,15 +564,20 @@ out:
112 qca8k_mib_init(struct qca8k_priv *priv)
116 mutex_lock(&priv->reg_mutex);
117 qca8k_reg_set(priv, QCA8K_REG_MIB, QCA8K_MIB_FLUSH | QCA8K_MIB_BUSY);
118 qca8k_busy_wait(priv, QCA8K_REG_MIB, QCA8K_MIB_BUSY);
119 qca8k_reg_set(priv, QCA8K_REG_MIB, QCA8K_MIB_CPU_KEEP);
120 - qca8k_write(priv, QCA8K_REG_MODULE_EN, QCA8K_MODULE_EN_MIB);
122 + ret = qca8k_write(priv, QCA8K_REG_MODULE_EN, QCA8K_MODULE_EN_MIB);
124 mutex_unlock(&priv->reg_mutex);
129 @@ -600,6 +614,7 @@ static int
130 qca8k_mdio_write(struct qca8k_priv *priv, int port, u32 regnum, u16 data)
135 if (regnum >= QCA8K_MDIO_MASTER_MAX_REG)
137 @@ -613,7 +628,9 @@ qca8k_mdio_write(struct qca8k_priv *priv
138 QCA8K_MDIO_MASTER_REG_ADDR(regnum) |
139 QCA8K_MDIO_MASTER_DATA(data);
141 - qca8k_write(priv, QCA8K_MDIO_MASTER_CTRL, val);
142 + ret = qca8k_write(priv, QCA8K_MDIO_MASTER_CTRL, val);
146 return qca8k_busy_wait(priv, QCA8K_MDIO_MASTER_CTRL,
147 QCA8K_MDIO_MASTER_BUSY);
148 @@ -623,6 +640,7 @@ static int
149 qca8k_mdio_read(struct qca8k_priv *priv, int port, u32 regnum)
154 if (regnum >= QCA8K_MDIO_MASTER_MAX_REG)
156 @@ -635,7 +653,9 @@ qca8k_mdio_read(struct qca8k_priv *priv,
157 QCA8K_MDIO_MASTER_READ | QCA8K_MDIO_MASTER_PHY_ADDR(phy) |
158 QCA8K_MDIO_MASTER_REG_ADDR(regnum);
160 - qca8k_write(priv, QCA8K_MDIO_MASTER_CTRL, val);
161 + ret = qca8k_write(priv, QCA8K_MDIO_MASTER_CTRL, val);
165 if (qca8k_busy_wait(priv, QCA8K_MDIO_MASTER_CTRL,
166 QCA8K_MDIO_MASTER_BUSY))
167 @@ -766,12 +786,18 @@ qca8k_setup(struct dsa_switch *ds)
168 QCA8K_GLOBAL_FW_CTRL0_CPU_PORT_EN);
170 /* Enable MIB counters */
171 - qca8k_mib_init(priv);
172 + ret = qca8k_mib_init(priv);
174 + dev_warn(priv->dev, "mib init failed");
176 /* Enable QCA header mode on the cpu port */
177 - qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(QCA8K_CPU_PORT),
178 - QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_TX_S |
179 - QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_RX_S);
180 + ret = qca8k_write(priv, QCA8K_REG_PORT_HDR_CTRL(QCA8K_CPU_PORT),
181 + QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_TX_S |
182 + QCA8K_PORT_HDR_CTRL_ALL << QCA8K_PORT_HDR_CTRL_RX_S);
184 + dev_err(priv->dev, "failed enabling QCA header mode");
188 /* Disable forwarding by default on all ports */
189 for (i = 0; i < QCA8K_NUM_PORTS; i++)
190 @@ -783,11 +809,13 @@ qca8k_setup(struct dsa_switch *ds)
191 qca8k_port_set_status(priv, i, 0);
193 /* Forward all unknown frames to CPU port for Linux processing */
194 - qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
195 - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S |
196 - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_BC_DP_S |
197 - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_MC_DP_S |
198 - BIT(0) << QCA8K_GLOBAL_FW_CTRL1_UC_DP_S);
199 + ret = qca8k_write(priv, QCA8K_REG_GLOBAL_FW_CTRL1,
200 + BIT(0) << QCA8K_GLOBAL_FW_CTRL1_IGMP_DP_S |
201 + BIT(0) << QCA8K_GLOBAL_FW_CTRL1_BC_DP_S |
202 + BIT(0) << QCA8K_GLOBAL_FW_CTRL1_MC_DP_S |
203 + BIT(0) << QCA8K_GLOBAL_FW_CTRL1_UC_DP_S);
207 /* Setup connection between CPU port & user ports */
208 for (i = 0; i < QCA8K_NUM_PORTS; i++) {
209 @@ -815,16 +843,20 @@ qca8k_setup(struct dsa_switch *ds)
210 qca8k_rmw(priv, QCA8K_EGRESS_VLAN(i),
212 QCA8K_PORT_VID_DEF << shift);
213 - qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(i),
214 - QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
215 - QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
216 + ret = qca8k_write(priv, QCA8K_REG_PORT_VLAN_CTRL0(i),
217 + QCA8K_PORT_VLAN_CVID(QCA8K_PORT_VID_DEF) |
218 + QCA8K_PORT_VLAN_SVID(QCA8K_PORT_VID_DEF));
224 /* Setup our port MTUs to match power on defaults */
225 for (i = 0; i < QCA8K_NUM_PORTS; i++)
226 priv->port_mtu[i] = ETH_FRAME_LEN + ETH_FCS_LEN;
227 - qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, ETH_FRAME_LEN + ETH_FCS_LEN);
228 + ret = qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, ETH_FRAME_LEN + ETH_FCS_LEN);
230 + dev_warn(priv->dev, "failed setting MTU settings");
232 /* Flush the FDB table */
233 qca8k_fdb_flush(priv);
234 @@ -1140,8 +1172,8 @@ qca8k_set_mac_eee(struct dsa_switch *ds,
236 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
237 u32 lpi_en = QCA8K_REG_EEE_CTRL_LPI_EN(port);
242 mutex_lock(&priv->reg_mutex);
243 reg = qca8k_read(priv, QCA8K_REG_EEE_CTRL);
244 @@ -1154,7 +1186,7 @@ qca8k_set_mac_eee(struct dsa_switch *ds,
248 - qca8k_write(priv, QCA8K_REG_EEE_CTRL, reg);
249 + ret = qca8k_write(priv, QCA8K_REG_EEE_CTRL, reg);
252 mutex_unlock(&priv->reg_mutex);
253 @@ -1284,9 +1316,7 @@ qca8k_port_change_mtu(struct dsa_switch
254 mtu = priv->port_mtu[i];
256 /* Include L2 header / FCS length */
257 - qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, mtu + ETH_HLEN + ETH_FCS_LEN);
260 + return qca8k_write(priv, QCA8K_MAX_FRAME_SIZE, mtu + ETH_HLEN + ETH_FCS_LEN);