@@ -253,10 +253,8 @@ static int qca8k_read_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
qca8k_mdio_header_fill_seq_num(skb, mgmt_eth_data->seq);
mgmt_eth_data->ack = false;
- dev_queue_xmit(skb);
-
- ret = dsa_inband_wait_for_completion(&mgmt_eth_data->inband,
- QCA8K_ETHERNET_TIMEOUT);
+ ret = dsa_inband_request(&mgmt_eth_data->inband, skb,
+ QCA8K_ETHERNET_TIMEOUT);
*val = mgmt_eth_data->data[0];
if (len > QCA_HDR_MGMT_DATA1_LEN)
@@ -303,10 +301,8 @@ static int qca8k_write_eth(struct qca8k_priv *priv, u32 reg, u32 *val, int len)
qca8k_mdio_header_fill_seq_num(skb, mgmt_eth_data->seq);
mgmt_eth_data->ack = false;
- dev_queue_xmit(skb);
-
- ret = dsa_inband_wait_for_completion(&mgmt_eth_data->inband,
- QCA8K_ETHERNET_TIMEOUT);
+ ret = dsa_inband_request(&mgmt_eth_data->inband, skb,
+ QCA8K_ETHERNET_TIMEOUT);
ack = mgmt_eth_data->ack;
@@ -449,10 +445,8 @@ qca8k_phy_eth_busy_wait(struct qca8k_mgmt_eth_data *mgmt_eth_data,
qca8k_mdio_header_fill_seq_num(skb, mgmt_eth_data->seq);
mgmt_eth_data->ack = false;
- dev_queue_xmit(skb);
-
- ret = dsa_inband_wait_for_completion(&mgmt_eth_data->inband,
- QCA8K_ETHERNET_TIMEOUT);
+ ret = dsa_inband_request(&mgmt_eth_data->inband, skb,
+ QCA8K_ETHERNET_TIMEOUT);
ack = mgmt_eth_data->ack;
@@ -539,10 +533,8 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
qca8k_mdio_header_fill_seq_num(write_skb, mgmt_eth_data->seq);
mgmt_eth_data->ack = false;
- dev_queue_xmit(write_skb);
-
- ret = dsa_inband_wait_for_completion(&mgmt_eth_data->inband,
- QCA8K_ETHERNET_TIMEOUT);
+ ret = dsa_inband_request(&mgmt_eth_data->inband, write_skb,
+ QCA8K_ETHERNET_TIMEOUT);
ack = mgmt_eth_data->ack;
@@ -574,10 +566,8 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
qca8k_mdio_header_fill_seq_num(read_skb, mgmt_eth_data->seq);
mgmt_eth_data->ack = false;
- dev_queue_xmit(read_skb);
-
- ret = dsa_inband_wait_for_completion(&mgmt_eth_data->inband,
- QCA8K_ETHERNET_TIMEOUT);
+ ret = dsa_inband_request(&mgmt_eth_data->inband, read_skb,
+ QCA8K_ETHERNET_TIMEOUT);
ack = mgmt_eth_data->ack;
@@ -601,8 +591,6 @@ qca8k_phy_eth_command(struct qca8k_priv *priv, bool read, int phy,
qca8k_mdio_header_fill_seq_num(clear_skb, mgmt_eth_data->seq);
mgmt_eth_data->ack = false;
- dev_queue_xmit(clear_skb);
-
dsa_inband_wait_for_completion(&mgmt_eth_data->inband,
QCA8K_ETHERNET_TIMEOUT);
@@ -1313,6 +1313,8 @@ struct dsa_inband {
void dsa_inband_init(struct dsa_inband *inband);
void dsa_inband_complete(struct dsa_inband *inband);
+int dsa_inband_request(struct dsa_inband *inband, struct sk_buff *skb,
+ int timeout_ms);
int dsa_inband_wait_for_completion(struct dsa_inband *inband, int timeout_ms);
/* Keep inline for faster access in hot path */
@@ -540,6 +540,22 @@ int dsa_inband_wait_for_completion(struct dsa_inband *inband, int timeout_ms)
}
EXPORT_SYMBOL_GPL(dsa_inband_wait_for_completion);
+/* Cannot use dsa_inband_wait_completion since the completion needs to be
+ * reinitialized before the skb is queue to avoid races.
+ */
+int dsa_inband_request(struct dsa_inband *inband, struct sk_buff *skb,
+ int timeout_ms)
+{
+ unsigned long jiffies = msecs_to_jiffies(timeout_ms);
+
+ reinit_completion(&inband->completion);
+
+ dev_queue_xmit(skb);
+
+ return wait_for_completion_timeout(&inband->completion, jiffies);
+}
+EXPORT_SYMBOL_GPL(dsa_inband_request);
+
static int __init dsa_init_module(void)
{
int rc;
Combine the queuing of the request and waiting for the completion into one core helper. Add the function dsa_rmu_request() to perform this. Access to statistics is not a strict request/reply, so the dsa_rmu_wait_for_completion needs to be kept. It is also no possible to combine dsa_rmu_request() and dsa_rmu_wait_for_completion() since we need to avoid the race of sending the request, receiving a reply, and the completion has not been reinitialised because the schedule at decided to do other things. Signed-off-by: Andrew Lunn <andrew@lunn.ch> --- drivers/net/dsa/qca/qca8k-8xxx.c | 32 ++++++++++---------------------- include/net/dsa.h | 2 ++ net/dsa/dsa.c | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 22 deletions(-)