Skip to content

Commit 90fdc17

Browse files
committed
mt76: use mac80211 txq scheduling
Performance improvement and preparation for adding airtime fairness support Signed-off-by: Felix Fietkau <[email protected]>
1 parent d908d4e commit 90fdc17

File tree

5 files changed

+67
-61
lines changed

5 files changed

+67
-61
lines changed

drivers/net/wireless/mediatek/mt76/dma.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,7 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, enum mt76_txq_id qid, bool flush)
184184
last = readl(&q->regs->dma_idx);
185185
}
186186

187-
if (!flush)
188-
mt76_txq_schedule(dev, sq);
189-
else
187+
if (flush)
190188
mt76_dma_sync_idx(dev, q);
191189

192190
wake = wake && q->stopped &&
@@ -199,6 +197,8 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, enum mt76_txq_id qid, bool flush)
199197

200198
spin_unlock_bh(&q->lock);
201199

200+
if (!flush)
201+
mt76_txq_schedule(dev, qid);
202202
if (wake)
203203
ieee80211_wake_queue(dev->hw, qid);
204204
}

drivers/net/wireless/mediatek/mt76/mac80211.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb)
568568
struct ieee80211_sta *sta;
569569
struct mt76_wcid *wcid = status->wcid;
570570
bool ps;
571+
int i;
571572

572573
if (ieee80211_is_pspoll(hdr->frame_control) && !wcid) {
573574
sta = ieee80211_find_sta_by_ifaddr(dev->hw, hdr->addr2, NULL);
@@ -614,6 +615,20 @@ mt76_check_sta(struct mt76_dev *dev, struct sk_buff *skb)
614615

615616
dev->drv->sta_ps(dev, sta, ps);
616617
ieee80211_sta_ps_transition(sta, ps);
618+
619+
if (ps)
620+
return;
621+
622+
for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
623+
struct mt76_txq *mtxq;
624+
625+
if (!sta->txq[i])
626+
continue;
627+
628+
mtxq = (struct mt76_txq *) sta->txq[i]->drv_priv;
629+
if (!skb_queue_empty(&mtxq->retry_q))
630+
ieee80211_schedule_txq(dev->hw, sta->txq[i]);
631+
}
617632
}
618633

619634
void mt76_rx_complete(struct mt76_dev *dev, struct sk_buff_head *frames,

drivers/net/wireless/mediatek/mt76/mt76.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ struct mt76_wcid {
216216
};
217217

218218
struct mt76_txq {
219-
struct list_head list;
220219
struct mt76_sw_queue *swq;
221220
struct mt76_wcid *wcid;
222221

@@ -676,7 +675,7 @@ void mt76_txq_remove(struct mt76_dev *dev, struct ieee80211_txq *txq);
676675
void mt76_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
677676
void mt76_stop_tx_queues(struct mt76_dev *dev, struct ieee80211_sta *sta,
678677
bool send_bar);
679-
void mt76_txq_schedule(struct mt76_dev *dev, struct mt76_sw_queue *sq);
678+
void mt76_txq_schedule(struct mt76_dev *dev, enum mt76_txq_id qid);
680679
void mt76_txq_schedule_all(struct mt76_dev *dev);
681680
void mt76_release_buffered_frames(struct ieee80211_hw *hw,
682681
struct ieee80211_sta *sta,

drivers/net/wireless/mediatek/mt76/tx.c

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -479,23 +479,37 @@ mt76_txq_send_burst(struct mt76_dev *dev, struct mt76_sw_queue *sq,
479479
}
480480

481481
static int
482-
mt76_txq_schedule_list(struct mt76_dev *dev, struct mt76_sw_queue *sq)
482+
mt76_txq_schedule_list(struct mt76_dev *dev, enum mt76_txq_id qid)
483483
{
484+
struct mt76_sw_queue *sq = &dev->q_tx[qid];
484485
struct mt76_queue *hwq = sq->q;
485-
struct mt76_txq *mtxq, *mtxq_last;
486-
int len = 0;
486+
struct ieee80211_txq *txq;
487+
struct mt76_txq *mtxq;
488+
struct mt76_wcid *wcid;
489+
int ret = 0;
487490

488-
restart:
489-
mtxq_last = list_last_entry(&sq->swq, struct mt76_txq, list);
490-
while (!list_empty(&sq->swq)) {
491+
spin_lock_bh(&hwq->lock);
492+
while (1) {
491493
bool empty = false;
492-
int cur;
494+
495+
if (sq->swq_queued >= 4)
496+
break;
493497

494498
if (test_bit(MT76_OFFCHANNEL, &dev->state) ||
495-
test_bit(MT76_RESET, &dev->state))
496-
return -EBUSY;
499+
test_bit(MT76_RESET, &dev->state)) {
500+
ret = -EBUSY;
501+
break;
502+
}
503+
504+
txq = ieee80211_next_txq(dev->hw, qid);
505+
if (!txq)
506+
break;
507+
508+
mtxq = (struct mt76_txq *)txq->drv_priv;
509+
wcid = mtxq->wcid;
510+
if (wcid && test_bit(MT_WCID_FLAG_PS, &wcid->flags))
511+
continue;
497512

498-
mtxq = list_first_entry(&sq->swq, struct mt76_txq, list);
499513
if (mtxq->send_bar && mtxq->aggr) {
500514
struct ieee80211_txq *txq = mtxq_to_txq(mtxq);
501515
struct ieee80211_sta *sta = txq->sta;
@@ -507,38 +521,37 @@ mt76_txq_schedule_list(struct mt76_dev *dev, struct mt76_sw_queue *sq)
507521
spin_unlock_bh(&hwq->lock);
508522
ieee80211_send_bar(vif, sta->addr, tid, agg_ssn);
509523
spin_lock_bh(&hwq->lock);
510-
goto restart;
511524
}
512525

513-
list_del_init(&mtxq->list);
514-
515-
cur = mt76_txq_send_burst(dev, sq, mtxq, &empty);
516-
if (!empty)
517-
list_add_tail(&mtxq->list, &sq->swq);
518-
519-
if (cur < 0)
520-
return cur;
521-
522-
len += cur;
523-
524-
if (mtxq == mtxq_last)
525-
break;
526+
ret += mt76_txq_send_burst(dev, sq, mtxq, &empty);
527+
if (skb_queue_empty(&mtxq->retry_q))
528+
empty = true;
529+
ieee80211_return_txq(dev->hw, txq, !empty);
526530
}
531+
spin_unlock_bh(&hwq->lock);
527532

528-
return len;
533+
return ret;
529534
}
530535

531-
void mt76_txq_schedule(struct mt76_dev *dev, struct mt76_sw_queue *sq)
536+
void mt76_txq_schedule(struct mt76_dev *dev, enum mt76_txq_id qid)
532537
{
538+
struct mt76_sw_queue *sq = &dev->q_tx[qid];
533539
int len;
534540

541+
if (qid >= 4)
542+
return;
543+
544+
if (sq->swq_queued >= 4)
545+
return;
546+
535547
rcu_read_lock();
536-
do {
537-
if (sq->swq_queued >= 4 || list_empty(&sq->swq))
538-
break;
539548

540-
len = mt76_txq_schedule_list(dev, sq);
549+
do {
550+
ieee80211_txq_schedule_start(dev->hw, qid);
551+
len = mt76_txq_schedule_list(dev, qid);
552+
ieee80211_txq_schedule_end(dev->hw, qid);
541553
} while (len > 0);
554+
542555
rcu_read_unlock();
543556
}
544557
EXPORT_SYMBOL_GPL(mt76_txq_schedule);
@@ -547,13 +560,8 @@ void mt76_txq_schedule_all(struct mt76_dev *dev)
547560
{
548561
int i;
549562

550-
for (i = 0; i <= MT_TXQ_BK; i++) {
551-
struct mt76_queue *q = dev->q_tx[i].q;
552-
553-
spin_lock_bh(&q->lock);
554-
mt76_txq_schedule(dev, &dev->q_tx[i]);
555-
spin_unlock_bh(&q->lock);
556-
}
563+
for (i = 0; i <= MT_TXQ_BK; i++)
564+
mt76_txq_schedule(dev, i);
557565
}
558566
EXPORT_SYMBOL_GPL(mt76_txq_schedule_all);
559567

@@ -575,8 +583,6 @@ void mt76_stop_tx_queues(struct mt76_dev *dev, struct ieee80211_sta *sta,
575583

576584
spin_lock_bh(&hwq->lock);
577585
mtxq->send_bar = mtxq->aggr && send_bar;
578-
if (!list_empty(&mtxq->list))
579-
list_del_init(&mtxq->list);
580586
spin_unlock_bh(&hwq->lock);
581587
}
582588
}
@@ -585,37 +591,23 @@ EXPORT_SYMBOL_GPL(mt76_stop_tx_queues);
585591
void mt76_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
586592
{
587593
struct mt76_dev *dev = hw->priv;
588-
struct mt76_txq *mtxq = (struct mt76_txq *)txq->drv_priv;
589-
struct mt76_sw_queue *sq = mtxq->swq;
590-
struct mt76_queue *hwq = sq->q;
591594

592595
if (!test_bit(MT76_STATE_RUNNING, &dev->state))
593596
return;
594597

595-
spin_lock_bh(&hwq->lock);
596-
if (list_empty(&mtxq->list))
597-
list_add_tail(&mtxq->list, &sq->swq);
598-
mt76_txq_schedule(dev, sq);
599-
spin_unlock_bh(&hwq->lock);
598+
mt76_txq_schedule(dev, txq->ac);
600599
}
601600
EXPORT_SYMBOL_GPL(mt76_wake_tx_queue);
602601

603602
void mt76_txq_remove(struct mt76_dev *dev, struct ieee80211_txq *txq)
604603
{
605-
struct mt76_queue *hwq;
606604
struct mt76_txq *mtxq;
607605
struct sk_buff *skb;
608606

609607
if (!txq)
610608
return;
611609

612610
mtxq = (struct mt76_txq *) txq->drv_priv;
613-
hwq = mtxq->swq->q;
614-
615-
spin_lock_bh(&hwq->lock);
616-
if (!list_empty(&mtxq->list))
617-
list_del_init(&mtxq->list);
618-
spin_unlock_bh(&hwq->lock);
619611

620612
while ((skb = skb_dequeue(&mtxq->retry_q)) != NULL)
621613
ieee80211_free_txskb(dev->hw, skb);
@@ -626,7 +618,6 @@ void mt76_txq_init(struct mt76_dev *dev, struct ieee80211_txq *txq)
626618
{
627619
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
628620

629-
INIT_LIST_HEAD(&mtxq->list);
630621
skb_queue_head_init(&mtxq->retry_q);
631622

632623
mtxq->swq = &dev->q_tx[mt76_txq_get_qid(txq)];

drivers/net/wireless/mediatek/mt76/usb.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,6 @@ static void mt76u_tx_tasklet(unsigned long data)
645645
dev->drv->tx_complete_skb(dev, i, &entry);
646646
spin_lock_bh(&q->lock);
647647
}
648-
mt76_txq_schedule(dev, sq);
649648

650649
wake = q->stopped && q->queued < q->ndesc - 8;
651650
if (wake)
@@ -656,6 +655,8 @@ static void mt76u_tx_tasklet(unsigned long data)
656655

657656
spin_unlock_bh(&q->lock);
658657

658+
mt76_txq_schedule(dev, i);
659+
659660
if (!test_and_set_bit(MT76_READING_STATS, &dev->state))
660661
ieee80211_queue_delayed_work(dev->hw,
661662
&dev->usb.stat_work,

0 commit comments

Comments
 (0)