Skip to content

Commit 21a5d4c

Browse files
Manikanta Pubbisettyjmberg-intel
authored andcommitted
mac80211: add stop/start logic for software TXQs
Sometimes, it is required to stop the transmissions momentarily and resume it later; stopping the txqs becomes very critical in scenarios where the packet transmission has to be ceased completely. For example, during the hardware restart, during off channel operations, when initiating CSA(upon detecting a radar on the DFS channel), etc. The TX queue stop/start logic in mac80211 works well in stopping the TX when drivers make use of netdev queues, i.e, when Qdiscs in network layer take care of traffic scheduling. Since the devices implementing wake_tx_queue can run without Qdiscs, packets will be handed to mac80211 directly without queueing them in the netdev queues. Also, mac80211 does not invoke any of the netif_stop_*/netif_wake_* APIs if wake_tx_queue is implemented. Since the queues are not stopped in this case, transmissions can continue and this will impact negatively on the operation of the wireless device. For example, During hardware restart, we stop the netdev queues so that packets are not sent to the driver. Since ath10k implements wake_tx_queue, TX queues will not be stopped and packets might reach the hardware while it is restarting; this can make hardware unresponsive and the only possible option for recovery is to reboot the entire system. There is another problem to this, it is observed that the packets were sent on the DFS channel for a prolonged duration after radar detection impacting the channel closing time. We can still invoke netif stop/wake APIs when wake_tx_queue is implemented but this could lead to packet drops in network layer; adding stop/start logic for software TXQs in mac80211 instead makes more sense; the change proposed adds the same in mac80211. Signed-off-by: Manikanta Pubbisetty <[email protected]> Signed-off-by: Johannes Berg <[email protected]>
1 parent 7417844 commit 21a5d4c

File tree

5 files changed

+125
-7
lines changed

5 files changed

+125
-7
lines changed

include/net/mac80211.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,8 @@ enum ieee80211_vif_flags {
15041504
* @drv_priv: data area for driver use, will always be aligned to
15051505
* sizeof(void \*).
15061506
* @txq: the multicast data TX queue (if driver uses the TXQ abstraction)
1507+
* @txqs_stopped: per AC flag to indicate that intermediate TXQs are stopped,
1508+
* protected by fq->lock.
15071509
*/
15081510
struct ieee80211_vif {
15091511
enum nl80211_iftype type;
@@ -1528,6 +1530,8 @@ struct ieee80211_vif {
15281530

15291531
unsigned int probe_req_reg;
15301532

1533+
bool txqs_stopped[IEEE80211_NUM_ACS];
1534+
15311535
/* must be last */
15321536
u8 drv_priv[0] __aligned(sizeof(void *));
15331537
};

net/mac80211/ieee80211_i.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ enum txq_info_flags {
818818
IEEE80211_TXQ_STOP,
819819
IEEE80211_TXQ_AMPDU,
820820
IEEE80211_TXQ_NO_AMSDU,
821+
IEEE80211_TXQ_STOP_NETIF_TX,
821822
};
822823

823824
/**
@@ -1226,6 +1227,7 @@ struct ieee80211_local {
12261227

12271228
struct sk_buff_head pending[IEEE80211_MAX_QUEUES];
12281229
struct tasklet_struct tx_pending_tasklet;
1230+
struct tasklet_struct wake_txqs_tasklet;
12291231

12301232
atomic_t agg_queue_stop[IEEE80211_MAX_QUEUES];
12311233

@@ -2038,6 +2040,7 @@ void ieee80211_txq_remove_vlan(struct ieee80211_local *local,
20382040
struct ieee80211_sub_if_data *sdata);
20392041
void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats,
20402042
struct txq_info *txqi);
2043+
void ieee80211_wake_txqs(unsigned long data);
20412044
void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
20422045
u16 transaction, u16 auth_alg, u16 status,
20432046
const u8 *extra, size_t extra_len, const u8 *bssid,

net/mac80211/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,10 @@ struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
668668
tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
669669
(unsigned long)local);
670670

671+
if (ops->wake_tx_queue)
672+
tasklet_init(&local->wake_txqs_tasklet, ieee80211_wake_txqs,
673+
(unsigned long)local);
674+
671675
tasklet_init(&local->tasklet,
672676
ieee80211_tasklet_handler,
673677
(unsigned long) local);

net/mac80211/tx.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,13 +3466,19 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
34663466
struct ieee80211_tx_info *info;
34673467
struct ieee80211_tx_data tx;
34683468
ieee80211_tx_result r;
3469-
struct ieee80211_vif *vif;
3469+
struct ieee80211_vif *vif = txq->vif;
34703470

34713471
spin_lock_bh(&fq->lock);
34723472

3473-
if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags))
3473+
if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags) ||
3474+
test_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags))
34743475
goto out;
34753476

3477+
if (vif->txqs_stopped[ieee80211_ac_from_tid(txq->tid)]) {
3478+
set_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags);
3479+
goto out;
3480+
}
3481+
34763482
/* Make sure fragments stay together. */
34773483
skb = __skb_dequeue(&txqi->frags);
34783484
if (skb)
@@ -3567,6 +3573,7 @@ struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
35673573
}
35683574

35693575
IEEE80211_SKB_CB(skb)->control.vif = vif;
3576+
35703577
out:
35713578
spin_unlock_bh(&fq->lock);
35723579

net/mac80211/util.c

Lines changed: 105 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,99 @@ __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
240240
}
241241
EXPORT_SYMBOL(ieee80211_ctstoself_duration);
242242

243+
static void __ieee80211_wake_txqs(struct ieee80211_sub_if_data *sdata, int ac)
244+
{
245+
struct ieee80211_local *local = sdata->local;
246+
struct ieee80211_vif *vif = &sdata->vif;
247+
struct fq *fq = &local->fq;
248+
struct ps_data *ps = NULL;
249+
struct txq_info *txqi;
250+
struct sta_info *sta;
251+
int i;
252+
253+
spin_lock_bh(&fq->lock);
254+
255+
if (sdata->vif.type == NL80211_IFTYPE_AP)
256+
ps = &sdata->bss->ps;
257+
258+
sdata->vif.txqs_stopped[ac] = false;
259+
260+
list_for_each_entry_rcu(sta, &local->sta_list, list) {
261+
if (sdata != sta->sdata)
262+
continue;
263+
264+
for (i = 0; i < ARRAY_SIZE(sta->sta.txq); i++) {
265+
struct ieee80211_txq *txq = sta->sta.txq[i];
266+
267+
txqi = to_txq_info(txq);
268+
269+
if (ac != txq->ac)
270+
continue;
271+
272+
if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX,
273+
&txqi->flags))
274+
continue;
275+
276+
spin_unlock_bh(&fq->lock);
277+
drv_wake_tx_queue(local, txqi);
278+
spin_lock_bh(&fq->lock);
279+
}
280+
}
281+
282+
if (!vif->txq)
283+
goto out;
284+
285+
txqi = to_txq_info(vif->txq);
286+
287+
if (!test_and_clear_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags) ||
288+
(ps && atomic_read(&ps->num_sta_ps)) || ac != vif->txq->ac)
289+
goto out;
290+
291+
spin_unlock_bh(&fq->lock);
292+
293+
drv_wake_tx_queue(local, txqi);
294+
return;
295+
out:
296+
spin_unlock_bh(&fq->lock);
297+
}
298+
299+
void ieee80211_wake_txqs(unsigned long data)
300+
{
301+
struct ieee80211_local *local = (struct ieee80211_local *)data;
302+
struct ieee80211_sub_if_data *sdata;
303+
int n_acs = IEEE80211_NUM_ACS;
304+
unsigned long flags;
305+
int i;
306+
307+
rcu_read_lock();
308+
spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
309+
310+
if (local->hw.queues < IEEE80211_NUM_ACS)
311+
n_acs = 1;
312+
313+
for (i = 0; i < local->hw.queues; i++) {
314+
if (local->queue_stop_reasons[i])
315+
continue;
316+
317+
spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
318+
list_for_each_entry_rcu(sdata, &local->interfaces, list) {
319+
int ac;
320+
321+
for (ac = 0; ac < n_acs; ac++) {
322+
int ac_queue = sdata->vif.hw_queue[ac];
323+
324+
if (ac_queue == i ||
325+
sdata->vif.cab_queue == i)
326+
__ieee80211_wake_txqs(sdata, ac);
327+
}
328+
}
329+
spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
330+
}
331+
332+
spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
333+
rcu_read_unlock();
334+
}
335+
243336
void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
244337
{
245338
struct ieee80211_sub_if_data *sdata;
@@ -308,6 +401,9 @@ static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
308401
rcu_read_unlock();
309402
} else
310403
tasklet_schedule(&local->tx_pending_tasklet);
404+
405+
if (local->ops->wake_tx_queue)
406+
tasklet_schedule(&local->wake_txqs_tasklet);
311407
}
312408

313409
void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
@@ -351,9 +447,6 @@ static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
351447
if (__test_and_set_bit(reason, &local->queue_stop_reasons[queue]))
352448
return;
353449

354-
if (local->ops->wake_tx_queue)
355-
return;
356-
357450
if (local->hw.queues < IEEE80211_NUM_ACS)
358451
n_acs = 1;
359452

@@ -366,8 +459,15 @@ static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
366459

367460
for (ac = 0; ac < n_acs; ac++) {
368461
if (sdata->vif.hw_queue[ac] == queue ||
369-
sdata->vif.cab_queue == queue)
370-
netif_stop_subqueue(sdata->dev, ac);
462+
sdata->vif.cab_queue == queue) {
463+
if (!local->ops->wake_tx_queue) {
464+
netif_stop_subqueue(sdata->dev, ac);
465+
continue;
466+
}
467+
spin_lock(&local->fq.lock);
468+
sdata->vif.txqs_stopped[ac] = true;
469+
spin_unlock(&local->fq.lock);
470+
}
371471
}
372472
}
373473
rcu_read_unlock();

0 commit comments

Comments
 (0)