@@ -286,6 +286,7 @@ struct wpan_phy {
/* Transmission monitoring and control */
atomic_t ongoing_txs;
atomic_t hold_txs;
+ wait_queue_head_t sync_txq;
char priv[] __aligned(NETDEV_ALIGN);
};
@@ -129,6 +129,7 @@ wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size)
wpan_phy_net_set(&rdev->wpan_phy, &init_net);
init_waitqueue_head(&rdev->dev_wait);
+ init_waitqueue_head(&rdev->wpan_phy.sync_txq);
return &rdev->wpan_phy;
}
@@ -46,8 +46,7 @@ static int ieee802154_suspend(struct wpan_phy *wpan_phy)
if (!local->open_count)
goto suspend;
- atomic_inc(&wpan_phy->hold_txs);
- ieee802154_stop_queue(&local->hw);
+ ieee802154_sync_and_stop_tx(local);
synchronize_net();
/* stop hardware - this must stop RX */
@@ -73,7 +72,7 @@ static int ieee802154_resume(struct wpan_phy *wpan_phy)
return ret;
wake_up:
- if (!atomic_dec_and_test(&wpan_phy->hold_txs))
+ if (!atomic_read(&wpan_phy->hold_txs))
ieee802154_wake_queue(&local->hw);
local->suspended = false;
return 0;
@@ -122,6 +122,7 @@ extern struct ieee802154_mlme_ops mac802154_mlme_wpan;
void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb);
void ieee802154_xmit_sync_worker(struct work_struct *work);
+void ieee802154_sync_and_stop_tx(struct ieee802154_local *local);
netdev_tx_t
ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev);
netdev_tx_t
@@ -47,7 +47,8 @@ void ieee802154_xmit_sync_worker(struct work_struct *work)
ieee802154_wake_queue(&local->hw);
kfree_skb(skb);
- atomic_dec(&local->phy->ongoing_txs);
+ if (!atomic_dec_and_test(&local->phy->ongoing_txs))
+ wake_up(&local->phy->sync_txq);
netdev_dbg(dev, "transmission failed\n");
}
@@ -117,6 +118,14 @@ ieee802154_hot_tx(struct ieee802154_local *local, struct sk_buff *skb)
return ieee802154_tx(local, skb);
}
+void ieee802154_sync_and_stop_tx(struct ieee802154_local *local)
+{
+ atomic_inc(&local->phy->hold_txs);
+ ieee802154_stop_queue(&local->hw);
+ wait_event(local->phy->sync_txq, !atomic_read(&local->phy->ongoing_txs));
+ atomic_dec(&local->phy->hold_txs);
+}
+
netdev_tx_t
ieee802154_monitor_start_xmit(struct sk_buff *skb, struct net_device *dev)
{
@@ -94,7 +94,8 @@ void ieee802154_xmit_complete(struct ieee802154_hw *hw, struct sk_buff *skb,
ieee802154_wakeup_after_xmit_done(hw, skb, ifs_handling);
dev_consume_skb_any(skb);
- atomic_dec(&hw->phy->ongoing_txs);
+ if (!atomic_dec_and_test(&hw->phy->ongoing_txs))
+ wake_up(&hw->phy->sync_txq);
}
EXPORT_SYMBOL(ieee802154_xmit_complete);
Right now we are able to stop a queue but we have no indication if a transmission is ongoing or not. Thanks to recent additions, we can track the number of ongoing transmissions so we know if the last transmission is over. Adding on top of it an internal wait queue also allows to be woken up asynchronously when this happens. If, beforehands, we marked the queue to be held and stopped it, we end up flushing and stopping the tx queue. Thanks to this feature, we will soon be able to introduce a synchronous transmit API. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> --- include/net/cfg802154.h | 1 + net/ieee802154/core.c | 1 + net/mac802154/cfg.c | 5 ++--- net/mac802154/ieee802154_i.h | 1 + net/mac802154/tx.c | 11 ++++++++++- net/mac802154/util.c | 3 ++- 6 files changed, 17 insertions(+), 5 deletions(-)