[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220922175821.4184622-8-andrew@lunn.ch>
Date: Thu, 22 Sep 2022 19:58:18 +0200
From: Andrew Lunn <andrew@...n.ch>
To: netdev <netdev@...r.kernel.org>
Cc: mattias.forsblad@...il.com,
Florian Fainelli <f.fainelli@...il.com>,
Vladimir Oltean <vladimir.oltean@....com>,
Christian Marangi <ansuelsmth@...il.com>,
Andrew Lunn <andrew@...n.ch>
Subject: [PATCH rfc v2 07/10] net: dsa: qca8k: Refactor sequence number mismatch to use error code
Replace the boolean that the sequence numbers matches with an error
code. Now that responses with the wrong sequence number are dropped,
this is actually unused in this driver. However, other devices can
perform additional validation of a response with the correct sequence
number and potentially return -EPROTO to indicate some other sort of
error.
The value is only safe to use if the completion happens. Ensure the
return from the completion is always considered, and if it fails, a
timeout error is returned.
This is a preparation step to moving the error tracking into the DSA
core. This intermediate step is a bit ugly, but that all gets cleaned
up in the next patch.
Signed-off-by: Andrew Lunn <andrew@...n.ch>
---
v2
-ret -> err
Extended commit message warning the code is ugly
Point out it is not actually used by this driver
---
drivers/net/dsa/qca/qca8k-8xxx.c | 46 +++++++++++++-------------------
drivers/net/dsa/qca/qca8k.h | 2 +-
2 files changed, 20 insertions(+), 28 deletions(-)
diff --git a/drivers/net/dsa/qca/qca8k-8xxx.c b/drivers/net/dsa/qca/qca8k-8xxx.c
index 35dbb16f9d62..1127fa138960 100644
--- a/drivers/net/dsa/qca/qca8k-8xxx.c
+++ b/drivers/net/dsa/qca/qca8k-8xxx.c
@@ -229,7 +229,7 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
{
struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data;
struct sk_buff *skb;
- bool ack;
+ int err;
int ret;
skb = qca8k_alloc_mdio_header(MDIO_READ, reg, NULL,
@@ -247,7 +247,6 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
}
skb->dev = priv->mgmt_master;
- mgmt_eth_data->ack = false;
ret = dsa_inband_request(&mgmt_eth_data->inband, skb,
qca8k_mdio_header_fill_seq_num,
@@ -257,15 +256,15 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
if (len > QCA_HDR_MGMT_DATA1_LEN)
memcpy(val + 1, mgmt_eth_data->data + 1, len - QCA_HDR_MGMT_DATA1_LEN);
- ack = mgmt_eth_data->ack;
+ err = mgmt_eth_data->err;
mutex_unlock(&mgmt_eth_data->mutex);
if (ret)
return ret;
- if (!ack)
- return -EINVAL;
+ if (err)
+ return err;
return 0;
}
@@ -274,7 +273,7 @@ static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
{
struct qca8k_mgmt_eth_data *mgmt_eth_data = &priv->mgmt_eth_data;
struct sk_buff *skb;
- bool ack;
+ int err;
int ret;
skb = qca8k_alloc_mdio_header(MDIO_WRITE, reg, val,
@@ -292,21 +291,20 @@ static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
}
skb->dev = priv->mgmt_master;
- mgmt_eth_data->ack = false;
ret = dsa_inband_request(&mgmt_eth_data->inband, skb,
qca8k_mdio_header_fill_seq_num,
QCA8K_ETHERNET_TIMEOUT);
- ack = mgmt_eth_data->ack;
+ err = mgmt_eth_data->err;
mutex_unlock(&mgmt_eth_data->mutex);
if (ret)
return ret;
- if (!ack)
- return -EINVAL;
+ if (err)
+ return err;
return 0;
}
@@ -431,22 +429,20 @@ qca8k_phy_eth_busy_wait(struct qca8k_mgmt_eth_data *mgmt_eth_data,
struct sk_buff *read_skb, u32 *val)
{
struct sk_buff *skb = skb_copy(read_skb, GFP_KERNEL);
- bool ack;
+ int err;
int ret;
- mgmt_eth_data->ack = false;
-
ret = dsa_inband_request(&mgmt_eth_data->inband, skb,
qca8k_mdio_header_fill_seq_num,
QCA8K_ETHERNET_TIMEOUT);
- ack = mgmt_eth_data->ack;
+ err = mgmt_eth_data->err;
if (ret)
return ret;
- if (!ack)
- return -EINVAL;
+ if (err)
+ return err;
*val = mgmt_eth_data->data[0];
@@ -462,7 +458,7 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
u32 write_val, clear_val = 0, val;
struct net_device *mgmt_master;
int ret, ret1;
- bool ack;
+ int err;
if (regnum >= QCA8K_MDIO_MASTER_MAX_REG)
return -EINVAL;
@@ -519,21 +515,20 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
read_skb->dev = mgmt_master;
clear_skb->dev = mgmt_master;
write_skb->dev = mgmt_master;
- mgmt_eth_data->ack = false;
ret = dsa_inband_request(&mgmt_eth_data->inband, write_skb,
qca8k_mdio_header_fill_seq_num,
QCA8K_ETHERNET_TIMEOUT);
- ack = mgmt_eth_data->ack;
+ err = mgmt_eth_data->err;
if (ret) {
kfree_skb(read_skb);
goto exit;
}
- if (!ack) {
- ret = -EINVAL;
+ if (err) {
+ ret = err;
kfree_skb(read_skb);
goto exit;
}
@@ -549,19 +544,17 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
}
if (read) {
- mgmt_eth_data->ack = false;
-
ret = dsa_inband_request(&mgmt_eth_data->inband, read_skb,
qca8k_mdio_header_fill_seq_num,
QCA8K_ETHERNET_TIMEOUT);
- ack = mgmt_eth_data->ack;
+ err = mgmt_eth_data->err;
if (ret)
goto exit;
- if (!ack) {
- ret = -EINVAL;
+ if (err) {
+ ret = err;
goto exit;
}
@@ -570,7 +563,6 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
kfree_skb(read_skb);
}
exit:
- mgmt_eth_data->ack = false;
/* This is expected to fail sometimes, so don't check return value. */
dsa_inband_request(&mgmt_eth_data->inband, clear_skb,
diff --git a/drivers/net/dsa/qca/qca8k.h b/drivers/net/dsa/qca/qca8k.h
index ae5815365a86..7b928c160c0e 100644
--- a/drivers/net/dsa/qca/qca8k.h
+++ b/drivers/net/dsa/qca/qca8k.h
@@ -348,7 +348,7 @@ enum {
struct qca8k_mgmt_eth_data {
struct dsa_inband inband;
struct mutex mutex; /* Enforce one mdio read/write at time */
- bool ack;
+ int err;
u32 data[4];
};
--
2.37.2
Powered by blists - more mailing lists