From: Felix Fietkau <nbd@nbd.name>
To: linux-wireless@vger.kernel.org
Subject: [PATCH 1/3] mt76: improve tx queue stop/wake
Date: Sat, 21 Nov 2020 18:33:24 +0100 [thread overview]
Message-ID: <20201121173326.88208-1-nbd@nbd.name> (raw)
Instead of stopping and waking only a single queue, handle all phy tx queues
mapped ot the same hardware queue.
Also allow the driver to block tx queues
Signed-off-by: Felix Fietkau <nbd@nbd.name>
---
drivers/net/wireless/mediatek/mt76/dma.c | 10 ----
drivers/net/wireless/mediatek/mt76/mt76.h | 1 +
drivers/net/wireless/mediatek/mt76/tx.c | 60 ++++++++++++++++++++---
3 files changed, 55 insertions(+), 16 deletions(-)
diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c
index bab961ebdf1c..6255f4f0a455 100644
--- a/drivers/net/wireless/mediatek/mt76/dma.c
+++ b/drivers/net/wireless/mediatek/mt76/dma.c
@@ -220,7 +220,6 @@ static void
mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush)
{
struct mt76_queue_entry entry;
- bool wake = false;
int last;
if (!q)
@@ -238,7 +237,6 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush)
if (entry.txwi) {
if (!(dev->drv->drv_flags & MT_DRV_TXWI_NO_FREE))
mt76_put_txwi(dev, entry.txwi);
- wake = !flush;
}
if (!flush && q->tail == last)
@@ -253,16 +251,8 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush)
spin_unlock_bh(&q->lock);
}
- wake = wake && q->stopped &&
- q->qid < IEEE80211_NUM_ACS && q->queued < q->ndesc - 8;
- if (wake)
- q->stopped = false;
-
if (!q->queued)
wake_up(&dev->tx_wait);
-
- if (wake)
- ieee80211_wake_queue(dev->hw, q->qid);
}
static void *
diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h
index 15d52af24d12..ea80ae188dd6 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76.h
@@ -136,6 +136,7 @@ struct mt76_queue {
int queued;
int buf_size;
bool stopped;
+ bool blocked;
u8 buf_offset;
u8 hw_idx;
diff --git a/drivers/net/wireless/mediatek/mt76/tx.c b/drivers/net/wireless/mediatek/mt76/tx.c
index 65360067b8fa..41dd0a8064cf 100644
--- a/drivers/net/wireless/mediatek/mt76/tx.c
+++ b/drivers/net/wireless/mediatek/mt76/tx.c
@@ -291,12 +291,6 @@ mt76_tx(struct mt76_phy *phy, struct ieee80211_sta *sta,
spin_lock_bh(&q->lock);
__mt76_tx_queue_skb(phy, qid, skb, wcid, sta, NULL);
dev->queue_ops->kick(dev, q);
-
- if (q->queued > q->ndesc - 8 && !q->stopped) {
- ieee80211_stop_queue(phy->hw, skb_get_queue_mapping(skb));
- q->stopped = true;
- }
-
spin_unlock_bh(&q->lock);
}
EXPORT_SYMBOL_GPL(mt76_tx);
@@ -463,6 +457,9 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid)
break;
}
+ if (q->stopped || q->blocked)
+ break;
+
if (q->queued + MT_TXQ_FREE_THR >= q->ndesc)
break;
@@ -496,13 +493,60 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid)
return ret;
}
+
+static void
+__mt76_tx_check_hwq_stop(struct mt76_phy *phy, struct mt76_queue *q,
+ bool stopped)
+{
+ int i;
+
+ for (i = 0; i < IEEE80211_NUM_ACS; i++) {
+ if (phy->q_tx[i] != q)
+ continue;
+
+ if (stopped)
+ ieee80211_stop_queue(phy->hw, i);
+ else
+ ieee80211_wake_queue(phy->hw, i);
+ }
+}
+
+static bool
+mt76_tx_check_hwq_stop(struct mt76_dev *dev, struct mt76_queue *q)
+{
+ return q->blocked || q->queued >= q->ndesc - MT_TXQ_FREE_THR;
+}
+
+static void
+mt76_tx_update_hwq_stop(struct mt76_dev *dev, struct mt76_queue *q)
+{
+ bool stopped, prev_stopped;
+
+ stopped = mt76_tx_check_hwq_stop(dev, q);
+ prev_stopped = q->stopped;
+ q->stopped = stopped;
+
+ if (stopped == prev_stopped)
+ return;
+
+ __mt76_tx_check_hwq_stop(&dev->phy, q, stopped);
+ if (dev->phy2)
+ __mt76_tx_check_hwq_stop(dev->phy2, q, stopped);
+}
+
void mt76_txq_schedule(struct mt76_phy *phy, enum mt76_txq_id qid)
{
+ struct mt76_queue *q;
int len;
if (qid >= 4)
return;
+ q = phy->q_tx[qid];
+ spin_lock_bh(&q->lock);
+ mt76_tx_update_hwq_stop(phy->dev, q);
+ spin_unlock_bh(&q->lock);
+
rcu_read_lock();
do {
@@ -623,6 +667,10 @@ void mt76_queue_tx_complete(struct mt76_dev *dev, struct mt76_queue *q,
spin_lock_bh(&q->lock);
q->tail = (q->tail + 1) % q->ndesc;
q->queued--;
+
+ if (q->stopped && !mt76_tx_check_hwq_stop(dev, q))
+ mt76_worker_schedule(&dev->tx_worker);
+
spin_unlock_bh(&q->lock);
}
EXPORT_SYMBOL_GPL(mt76_queue_tx_complete);
--
2.28.0
next reply other threads:[~2020-11-21 17:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-21 17:33 Felix Fietkau [this message]
2020-11-21 17:33 ` [PATCH 2/3] mt76: mt7915: stop queues when running out of tx tokens Felix Fietkau
2020-11-21 17:33 ` [PATCH 3/3] mt76: attempt to free up more room when filling the tx queue Felix Fietkau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201121173326.88208-1-nbd@nbd.name \
--to=nbd@nbd.name \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox