@@ -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,
@@ -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];
};
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@lunn.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(-)