1 From 028f5f8ef44fcf87a456772cbb9f0d90a0a22884 Mon Sep 17 00:00:00 2001
2 From: Ansuel Smith <ansuelsmth@gmail.com>
3 Date: Fri, 14 May 2021 22:59:55 +0200
4 Subject: [PATCH] net: dsa: qca8k: handle error with qca8k_read operation
6 qca8k_read 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 | 73 ++++++++++++++++++++++++++++++++---------
14 1 file changed, 58 insertions(+), 15 deletions(-)
16 --- a/drivers/net/dsa/qca8k.c
17 +++ b/drivers/net/dsa/qca8k.c
18 @@ -231,8 +231,13 @@ static int
19 qca8k_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
21 struct qca8k_priv *priv = (struct qca8k_priv *)ctx;
24 + ret = qca8k_read(priv, reg);
28 - *val = qca8k_read(priv, reg);
33 @@ -300,15 +305,20 @@ qca8k_busy_wait(struct qca8k_priv *priv,
39 qca8k_fdb_read(struct qca8k_priv *priv, struct qca8k_fdb *fdb)
45 /* load the ARL table into an array */
46 - for (i = 0; i < 4; i++)
47 - reg[i] = qca8k_read(priv, QCA8K_REG_ATU_DATA0 + (i * 4));
48 + for (i = 0; i < 4; i++) {
49 + val = qca8k_read(priv, QCA8K_REG_ATU_DATA0 + (i * 4));
57 fdb->vid = (reg[2] >> QCA8K_ATU_VID_S) & QCA8K_ATU_VID_M;
58 @@ -323,6 +333,8 @@ qca8k_fdb_read(struct qca8k_priv *priv,
59 fdb->mac[3] = (reg[0] >> QCA8K_ATU_ADDR3_S) & 0xff;
60 fdb->mac[4] = (reg[0] >> QCA8K_ATU_ADDR4_S) & 0xff;
61 fdb->mac[5] = reg[0] & 0xff;
67 @@ -374,6 +386,8 @@ qca8k_fdb_access(struct qca8k_priv *priv
68 /* Check for table full violation when adding an entry */
69 if (cmd == QCA8K_FDB_LOAD) {
70 reg = qca8k_read(priv, QCA8K_REG_ATU_FUNC);
73 if (reg & QCA8K_ATU_FUNC_FULL)
76 @@ -388,10 +402,10 @@ qca8k_fdb_next(struct qca8k_priv *priv,
78 qca8k_fdb_write(priv, fdb->vid, fdb->port_mask, fdb->mac, fdb->aging);
79 ret = qca8k_fdb_access(priv, QCA8K_FDB_NEXT, port);
81 - qca8k_fdb_read(priv, fdb);
86 + return qca8k_fdb_read(priv, fdb);
90 @@ -449,6 +463,8 @@ qca8k_vlan_access(struct qca8k_priv *pri
91 /* Check for table full violation when adding an entry */
92 if (cmd == QCA8K_VLAN_LOAD) {
93 reg = qca8k_read(priv, QCA8K_REG_VTU_FUNC1);
96 if (reg & QCA8K_VTU_FUNC1_FULL)
99 @@ -475,6 +491,8 @@ qca8k_vlan_add(struct qca8k_priv *priv,
102 reg = qca8k_read(priv, QCA8K_REG_VTU_FUNC0);
105 reg |= QCA8K_VTU_FUNC0_VALID | QCA8K_VTU_FUNC0_IVL_EN;
106 reg &= ~(QCA8K_VTU_FUNC0_EG_MODE_MASK << QCA8K_VTU_FUNC0_EG_MODE_S(port));
108 @@ -506,6 +524,8 @@ qca8k_vlan_del(struct qca8k_priv *priv,
111 reg = qca8k_read(priv, QCA8K_REG_VTU_FUNC0);
114 reg &= ~(3 << QCA8K_VTU_FUNC0_EG_MODE_S(port));
115 reg |= QCA8K_VTU_FUNC0_EG_MODE_NOT <<
116 QCA8K_VTU_FUNC0_EG_MODE_S(port);
117 @@ -621,8 +641,11 @@ qca8k_mdio_read(struct qca8k_priv *priv,
118 QCA8K_MDIO_MASTER_BUSY))
121 - val = (qca8k_read(priv, QCA8K_MDIO_MASTER_CTRL) &
122 - QCA8K_MDIO_MASTER_DATA_MASK);
123 + val = qca8k_read(priv, QCA8K_MDIO_MASTER_CTRL);
127 + val &= QCA8K_MDIO_MASTER_DATA_MASK;
131 @@ -978,6 +1001,8 @@ qca8k_phylink_mac_link_state(struct dsa_
134 reg = qca8k_read(priv, QCA8K_REG_PORT_STATUS(port));
138 state->link = !!(reg & QCA8K_PORT_STATUS_LINK_UP);
139 state->an_complete = state->link;
140 @@ -1078,18 +1103,26 @@ qca8k_get_ethtool_stats(struct dsa_switc
142 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
143 const struct qca8k_mib_desc *mib;
148 for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++) {
149 mib = &ar8327_mib[i];
150 reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
152 - data[i] = qca8k_read(priv, reg);
153 + val = qca8k_read(priv, reg);
157 if (mib->size == 2) {
158 hi = qca8k_read(priv, reg + 4);
159 - data[i] |= hi << 32;
165 + if (mib->size == 2)
166 + data[i] |= hi << 32;
170 @@ -1107,18 +1140,25 @@ qca8k_set_mac_eee(struct dsa_switch *ds,
172 struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
173 u32 lpi_en = QCA8K_REG_EEE_CTRL_LPI_EN(port);
177 mutex_lock(&priv->reg_mutex);
178 reg = qca8k_read(priv, QCA8K_REG_EEE_CTRL);
184 if (eee->eee_enabled)
188 qca8k_write(priv, QCA8K_REG_EEE_CTRL, reg);
189 - mutex_unlock(&priv->reg_mutex);
193 + mutex_unlock(&priv->reg_mutex);
198 @@ -1456,6 +1496,9 @@ qca8k_sw_probe(struct mdio_device *mdiod
200 /* read the switches ID register */
201 id = qca8k_read(priv, QCA8K_REG_MASK_CTRL);
205 id >>= QCA8K_MASK_CTRL_ID_S;
206 id &= QCA8K_MASK_CTRL_ID_M;
207 if (id != QCA8K_ID_QCA8337)