mirror of
https://github.com/outbackdingo/mt76.git
synced 2026-10-24 13:26:48 +00:00
move tx scheduling code to common
Signed-off-by: Felix Fietkau <[email protected]>
This commit is contained in:
@@ -3,7 +3,7 @@ EXTRA_CFLAGS += -Werror
|
||||
obj-m := mt76.o mt76x2e.o mt7603e.o
|
||||
|
||||
mt76-y := \
|
||||
mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o
|
||||
mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o tx.o
|
||||
|
||||
mt76x2e-y := \
|
||||
mt76x2_pci.o mt76x2_dma.o \
|
||||
|
||||
@@ -225,4 +225,22 @@ static inline void mt76_eeprom_override(struct mt76_dev *dev)
|
||||
|
||||
int mt76_eeprom_init(struct mt76_dev *dev, int len);
|
||||
|
||||
static inline struct ieee80211_txq *
|
||||
mtxq_to_txq(struct mt76_txq *mtxq)
|
||||
{
|
||||
void *ptr = mtxq;
|
||||
return container_of(ptr, struct ieee80211_txq, drv_priv);
|
||||
}
|
||||
|
||||
void mt76_txq_init(struct mt76_dev *dev, struct ieee80211_txq *txq);
|
||||
void mt76_txq_remove(struct mt76_dev *dev, struct ieee80211_txq *txq);
|
||||
void mt76_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
|
||||
void mt76_stop_tx_queues(struct mt76_dev *dev, struct ieee80211_sta *sta);
|
||||
void mt76_txq_schedule(struct mt76_dev *dev, struct mt76_queue *hwq);
|
||||
void mt76_release_buffered_frames(struct ieee80211_hw *hw,
|
||||
struct ieee80211_sta *sta,
|
||||
u16 tids, int nframes,
|
||||
enum ieee80211_frame_release_type reason,
|
||||
bool more_data);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -152,7 +152,7 @@ struct mt76x2_vif {
|
||||
};
|
||||
|
||||
struct mt76x2_sta {
|
||||
struct mt76_wcid wcid;
|
||||
struct mt76_wcid wcid; /* must be first */
|
||||
|
||||
struct mt76x2_tx_status status;
|
||||
int n_frames;
|
||||
@@ -184,13 +184,6 @@ static inline void mt76x2_irq_disable(struct mt76x2_dev *dev, u32 mask)
|
||||
mt76x2_set_irq_mask(dev, mask, 0);
|
||||
}
|
||||
|
||||
static inline struct ieee80211_txq *
|
||||
mtxq_to_txq(struct mt76_txq *mtxq)
|
||||
{
|
||||
void *ptr = mtxq;
|
||||
return container_of(ptr, struct ieee80211_txq, drv_priv);
|
||||
}
|
||||
|
||||
extern const struct ieee80211_ops mt76x2_ops;
|
||||
|
||||
struct mt76x2_dev *mt76x2_alloc_device(struct device *pdev);
|
||||
@@ -238,16 +231,5 @@ void mt76x2_tx_complete(struct mt76x2_dev *dev, struct sk_buff *skb);
|
||||
void mt76x2_pre_tbtt_tasklet(unsigned long data);
|
||||
|
||||
void mt76x2_txq_init(struct mt76x2_dev *dev, struct ieee80211_txq *txq);
|
||||
void mt76x2_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq);
|
||||
void mt76x2_txq_remove(struct mt76x2_dev *dev, struct ieee80211_txq *txq);
|
||||
void mt76x2_txq_schedule(struct mt76x2_dev *dev, struct mt76_queue *hwq);
|
||||
|
||||
void mt76x2_release_buffered_frames(struct ieee80211_hw *hw,
|
||||
struct ieee80211_sta *sta,
|
||||
u16 tids, int nframes,
|
||||
enum ieee80211_frame_release_type reason,
|
||||
bool more_data);
|
||||
|
||||
void mt76x2_stop_tx_queues(struct mt76x2_dev *dev, struct ieee80211_sta *sta);
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -256,7 +256,7 @@ mt76_tx_cleanup(struct mt76x2_dev *dev, struct mt76_queue *q, bool flush)
|
||||
spin_lock_bh(&q->lock);
|
||||
mt76_queue_cleanup(dev, q, flush, mt76x2_tx_cleanup_entry);
|
||||
if (!flush)
|
||||
mt76x2_txq_schedule(dev, q);
|
||||
mt76_txq_schedule(&dev->mt76, q);
|
||||
spin_unlock_bh(&q->lock);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -92,7 +92,7 @@ mt76x2_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
|
||||
{
|
||||
struct mt76x2_dev *dev = hw->priv;
|
||||
|
||||
mt76x2_txq_remove(dev, vif->txq);
|
||||
mt76_txq_remove(&dev->mt76, vif->txq);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -256,7 +256,7 @@ mt76x2_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
|
||||
mutex_lock(&dev->mutex);
|
||||
rcu_assign_pointer(dev->wcid[idx], NULL);
|
||||
for (i = 0; i < ARRAY_SIZE(sta->txq); i++)
|
||||
mt76x2_txq_remove(dev, sta->txq[i]);
|
||||
mt76_txq_remove(&dev->mt76, sta->txq[i]);
|
||||
mt76_set(dev, MT_WCID_DROP(idx), MT_WCID_DROP_MASK(idx));
|
||||
dev->wcid_mask[idx / BITS_PER_LONG] &= ~BIT(idx % BITS_PER_LONG);
|
||||
mt76x2_mac_wcid_setup(dev, idx, 0, NULL);
|
||||
@@ -277,7 +277,7 @@ mt76x2_sta_notify(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
|
||||
case STA_NOTIFY_SLEEP:
|
||||
msta->sleeping = true;
|
||||
mt76_set(dev, MT_WCID_DROP(idx), MT_WCID_DROP_MASK(idx));
|
||||
mt76x2_stop_tx_queues(dev, sta);
|
||||
mt76_stop_tx_queues(&dev->mt76, sta);
|
||||
break;
|
||||
case STA_NOTIFY_AWAKE:
|
||||
mt76_clear(dev, MT_WCID_DROP(idx), MT_WCID_DROP_MASK(idx));
|
||||
@@ -486,9 +486,9 @@ const struct ieee80211_ops mt76x2_ops = {
|
||||
.flush = mt76x2_flush,
|
||||
.ampdu_action = mt76x2_ampdu_action,
|
||||
.get_txpower = mt76x2_get_txpower,
|
||||
.wake_tx_queue = mt76x2_wake_tx_queue,
|
||||
.wake_tx_queue = mt76_wake_tx_queue,
|
||||
.sta_rate_tbl_update = mt76x2_sta_rate_tbl_update,
|
||||
.release_buffered_frames = mt76x2_release_buffered_frames,
|
||||
.release_buffered_frames = mt76_release_buffered_frames,
|
||||
.set_coverage_class = mt76x2_set_coverage_class,
|
||||
};
|
||||
|
||||
|
||||
+3
-308
@@ -96,17 +96,6 @@ mt76x2_update_beacon_iter(void *priv, u8 *mac, struct ieee80211_vif *vif)
|
||||
mt76x2_mac_set_beacon(dev, mvif->idx, skb);
|
||||
}
|
||||
|
||||
static void
|
||||
mt76x2_skb_set_moredata(struct sk_buff *skb, bool enable)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
|
||||
if (enable)
|
||||
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
|
||||
else
|
||||
hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
|
||||
}
|
||||
|
||||
static void
|
||||
mt76x2_add_buffered_bc(void *priv, u8 *mac, struct ieee80211_vif *vif)
|
||||
{
|
||||
@@ -126,7 +115,7 @@ mt76x2_add_buffered_bc(void *priv, u8 *mac, struct ieee80211_vif *vif)
|
||||
info = IEEE80211_SKB_CB(skb);
|
||||
info->control.vif = vif;
|
||||
info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
|
||||
mt76x2_skb_set_moredata(skb, true);
|
||||
mt76_skb_set_moredata(skb, true);
|
||||
__skb_queue_tail(&data->q, skb);
|
||||
data->tail[mvif->idx] = skb;
|
||||
}
|
||||
@@ -160,7 +149,7 @@ void mt76x2_pre_tbtt_tasklet(unsigned long arg)
|
||||
if (!data.tail[i])
|
||||
continue;
|
||||
|
||||
mt76x2_skb_set_moredata(data.tail[i], false);
|
||||
mt76_skb_set_moredata(data.tail[i], false);
|
||||
}
|
||||
|
||||
spin_lock_bh(&q->lock);
|
||||
@@ -174,246 +163,6 @@ void mt76x2_pre_tbtt_tasklet(unsigned long arg)
|
||||
spin_unlock_bh(&q->lock);
|
||||
}
|
||||
|
||||
static int
|
||||
mt76x2_txq_get_qid(struct ieee80211_txq *txq)
|
||||
{
|
||||
if (!txq->sta)
|
||||
return MT_TXQ_BE;
|
||||
|
||||
return txq->ac;
|
||||
}
|
||||
|
||||
static struct sk_buff *
|
||||
mt76x2_txq_dequeue(struct mt76x2_dev *dev, struct mt76_txq *mtxq, bool ps)
|
||||
{
|
||||
struct ieee80211_txq *txq = mtxq_to_txq(mtxq);
|
||||
struct sk_buff *skb;
|
||||
|
||||
skb = skb_dequeue(&mtxq->retry_q);
|
||||
if (skb) {
|
||||
u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
|
||||
|
||||
if (ps && skb_queue_empty(&mtxq->retry_q));
|
||||
ieee80211_sta_set_buffered(txq->sta, tid, false);
|
||||
|
||||
return skb;
|
||||
}
|
||||
|
||||
skb = ieee80211_tx_dequeue(mt76_hw(dev), txq);
|
||||
if (!skb)
|
||||
return NULL;
|
||||
|
||||
return skb;
|
||||
}
|
||||
|
||||
static void
|
||||
mt76x2_check_agg_ssn(struct mt76_txq *mtxq, struct sk_buff *skb)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
|
||||
if (!ieee80211_is_data_qos(hdr->frame_control))
|
||||
return;
|
||||
|
||||
mtxq->agg_ssn = le16_to_cpu(hdr->seq_ctrl) + 0x10;
|
||||
}
|
||||
|
||||
static void
|
||||
mt76x2_queue_ps_skb(struct mt76x2_dev *dev, struct ieee80211_sta *sta,
|
||||
struct sk_buff *skb, bool last)
|
||||
{
|
||||
struct mt76x2_sta *msta = (struct mt76x2_sta *) sta->drv_priv;
|
||||
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
|
||||
struct mt76_queue *hwq = &dev->mt76.q_tx[MT_TXQ_PSD];
|
||||
struct mt76_wcid *wcid = &msta->wcid;
|
||||
|
||||
info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
|
||||
if (last)
|
||||
info->flags |= IEEE80211_TX_STATUS_EOSP;
|
||||
|
||||
mt76x2_skb_set_moredata(skb, !last);
|
||||
mt76_tx_queue_skb(&dev->mt76, hwq, skb, wcid, sta);
|
||||
}
|
||||
|
||||
void
|
||||
mt76x2_release_buffered_frames(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
|
||||
u16 tids, int nframes,
|
||||
enum ieee80211_frame_release_type reason,
|
||||
bool more_data)
|
||||
{
|
||||
struct mt76x2_dev *dev = hw->priv;
|
||||
struct sk_buff *last_skb = NULL;
|
||||
struct mt76_queue *hwq = &dev->mt76.q_tx[MT_TXQ_PSD];
|
||||
int i;
|
||||
|
||||
for (i = 0; tids && nframes; i++, tids >>= 1) {
|
||||
struct ieee80211_txq *txq = sta->txq[i];
|
||||
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
struct sk_buff *skb;
|
||||
|
||||
if (!(tids & 1))
|
||||
continue;
|
||||
|
||||
do {
|
||||
skb = mt76x2_txq_dequeue(dev, mtxq, true);
|
||||
if (!skb)
|
||||
break;
|
||||
|
||||
if (mtxq->aggr)
|
||||
mt76x2_check_agg_ssn(mtxq, skb);
|
||||
|
||||
nframes--;
|
||||
if (last_skb) {
|
||||
mt76x2_queue_ps_skb(dev, sta, last_skb, false);
|
||||
last_skb = skb;
|
||||
}
|
||||
} while (nframes);
|
||||
}
|
||||
|
||||
if (!last_skb)
|
||||
return;
|
||||
|
||||
mt76x2_queue_ps_skb(dev, sta, last_skb, true);
|
||||
mt76_queue_kick(dev, hwq);
|
||||
}
|
||||
|
||||
static int
|
||||
mt76x2_txq_send_burst(struct mt76x2_dev *dev, struct mt76_queue *hwq,
|
||||
struct mt76_txq *mtxq, bool *empty)
|
||||
{
|
||||
struct ieee80211_txq *txq = mtxq_to_txq(mtxq);
|
||||
struct ieee80211_tx_info *info;
|
||||
struct mt76_wcid *wcid = mtxq->wcid;
|
||||
struct sk_buff *skb = NULL;
|
||||
int n_frames = 1, limit;
|
||||
struct ieee80211_tx_rate tx_rate;
|
||||
bool ampdu;
|
||||
bool probe;
|
||||
int idx;
|
||||
|
||||
skb = mt76x2_txq_dequeue(dev, mtxq, false);
|
||||
if (!skb) {
|
||||
*empty = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
info = IEEE80211_SKB_CB(skb);
|
||||
if (!wcid->tx_rate_set)
|
||||
ieee80211_get_tx_rates(txq->vif, txq->sta, skb,
|
||||
info->control.rates, 1);
|
||||
tx_rate = info->control.rates[0];
|
||||
|
||||
probe = (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE);
|
||||
ampdu = IEEE80211_SKB_CB(skb)->flags & IEEE80211_TX_CTL_AMPDU;
|
||||
limit = ampdu ? 16 : 3;
|
||||
|
||||
if (ampdu)
|
||||
mt76x2_check_agg_ssn(mtxq, skb);
|
||||
|
||||
idx = mt76_tx_queue_skb(&dev->mt76, hwq, skb, wcid, txq->sta);
|
||||
|
||||
if (idx < 0)
|
||||
return idx;
|
||||
|
||||
do {
|
||||
bool cur_ampdu;
|
||||
|
||||
if (probe)
|
||||
break;
|
||||
|
||||
skb = mt76x2_txq_dequeue(dev, mtxq, false);
|
||||
if (!skb) {
|
||||
*empty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
cur_ampdu = info->flags & IEEE80211_TX_CTL_AMPDU;
|
||||
|
||||
if (ampdu != cur_ampdu ||
|
||||
(info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)) {
|
||||
skb_queue_tail(&mtxq->retry_q, skb);
|
||||
break;
|
||||
}
|
||||
|
||||
info = IEEE80211_SKB_CB(skb);
|
||||
info->control.rates[0] = tx_rate;
|
||||
|
||||
if (cur_ampdu)
|
||||
mt76x2_check_agg_ssn(mtxq, skb);
|
||||
|
||||
idx = mt76_tx_queue_skb(&dev->mt76, hwq, skb, wcid, txq->sta);
|
||||
if (idx < 0)
|
||||
return idx;
|
||||
|
||||
n_frames++;
|
||||
} while (n_frames < limit);
|
||||
|
||||
if (!probe) {
|
||||
hwq->swq_queued++;
|
||||
hwq->entry[idx].schedule = true;
|
||||
}
|
||||
|
||||
mt76_queue_kick(dev, hwq);
|
||||
|
||||
return n_frames;
|
||||
}
|
||||
|
||||
static int
|
||||
mt76x2_txq_schedule_list(struct mt76x2_dev *dev, struct mt76_queue *hwq)
|
||||
{
|
||||
struct mt76_txq *mtxq, *mtxq_last;
|
||||
int len = 0;
|
||||
|
||||
restart:
|
||||
mtxq_last = list_last_entry(&hwq->swq, struct mt76_txq, list);
|
||||
while (!list_empty(&hwq->swq)) {
|
||||
bool empty = false;
|
||||
int cur;
|
||||
|
||||
mtxq = list_first_entry(&hwq->swq, struct mt76_txq, list);
|
||||
if (mtxq->send_bar && mtxq->aggr) {
|
||||
struct ieee80211_txq *txq = mtxq_to_txq(mtxq);
|
||||
struct ieee80211_sta *sta = txq->sta;
|
||||
struct ieee80211_vif *vif = txq->vif;
|
||||
u16 agg_ssn = mtxq->agg_ssn;
|
||||
u8 tid = txq->tid;
|
||||
|
||||
mtxq->send_bar = false;
|
||||
spin_unlock_bh(&hwq->lock);
|
||||
ieee80211_send_bar(vif, sta->addr, tid, agg_ssn);
|
||||
spin_lock_bh(&hwq->lock);
|
||||
goto restart;
|
||||
}
|
||||
|
||||
list_del_init(&mtxq->list);
|
||||
|
||||
cur = mt76x2_txq_send_burst(dev, hwq, mtxq, &empty);
|
||||
if (!empty)
|
||||
list_add_tail(&mtxq->list, &hwq->swq);
|
||||
|
||||
if (cur < 0)
|
||||
return cur;
|
||||
|
||||
len += cur;
|
||||
|
||||
if (mtxq == mtxq_last)
|
||||
break;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void mt76x2_txq_schedule(struct mt76x2_dev *dev, struct mt76_queue *hwq)
|
||||
{
|
||||
int len;
|
||||
|
||||
do {
|
||||
if (hwq->swq_queued >= 4 || list_empty(&hwq->swq))
|
||||
break;
|
||||
|
||||
len = mt76x2_txq_schedule_list(dev, hwq);
|
||||
} while (len > 0);
|
||||
}
|
||||
|
||||
void mt76x2_txq_init(struct mt76x2_dev *dev, struct ieee80211_txq *txq)
|
||||
{
|
||||
struct mt76_txq *mtxq;
|
||||
@@ -422,11 +171,6 @@ void mt76x2_txq_init(struct mt76x2_dev *dev, struct ieee80211_txq *txq)
|
||||
return;
|
||||
|
||||
mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
INIT_LIST_HEAD(&mtxq->list);
|
||||
skb_queue_head_init(&mtxq->retry_q);
|
||||
|
||||
mtxq->hwq = &dev->mt76.q_tx[mt76x2_txq_get_qid(txq)];
|
||||
|
||||
if (txq->sta) {
|
||||
struct mt76x2_sta *sta = (struct mt76x2_sta *) txq->sta->drv_priv;
|
||||
mtxq->wcid = &sta->wcid;
|
||||
@@ -434,55 +178,6 @@ void mt76x2_txq_init(struct mt76x2_dev *dev, struct ieee80211_txq *txq)
|
||||
struct mt76x2_vif *mvif = (struct mt76x2_vif *) txq->vif->drv_priv;
|
||||
mtxq->wcid = &mvif->group_wcid;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mt76x2_stop_tx_queues(struct mt76x2_dev *dev, struct ieee80211_sta *sta)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
|
||||
struct ieee80211_txq *txq = sta->txq[i];
|
||||
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
|
||||
spin_lock_bh(&mtxq->hwq->lock);
|
||||
mtxq->send_bar = mtxq->aggr;
|
||||
if (!list_empty(&mtxq->list))
|
||||
list_del_init(&mtxq->list);
|
||||
spin_unlock_bh(&mtxq->hwq->lock);
|
||||
}
|
||||
}
|
||||
|
||||
void mt76x2_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
|
||||
{
|
||||
struct mt76x2_dev *dev = hw->priv;
|
||||
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
struct mt76_queue *hwq = mtxq->hwq;
|
||||
|
||||
spin_lock_bh(&hwq->lock);
|
||||
if (list_empty(&mtxq->list))
|
||||
list_add_tail(&mtxq->list, &hwq->swq);
|
||||
mt76x2_txq_schedule(dev, hwq);
|
||||
spin_unlock_bh(&hwq->lock);
|
||||
}
|
||||
|
||||
void mt76x2_txq_remove(struct mt76x2_dev *dev, struct ieee80211_txq *txq)
|
||||
{
|
||||
struct mt76_txq *mtxq;
|
||||
struct mt76_queue *hwq;
|
||||
struct sk_buff *skb;
|
||||
|
||||
if (!txq)
|
||||
return;
|
||||
|
||||
mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
hwq = mtxq->hwq;
|
||||
|
||||
spin_lock_bh(&hwq->lock);
|
||||
if (!list_empty(&mtxq->list))
|
||||
list_del(&mtxq->list);
|
||||
spin_unlock_bh(&hwq->lock);
|
||||
|
||||
while ((skb = skb_dequeue(&mtxq->retry_q)) != NULL)
|
||||
ieee80211_free_txskb(mt76_hw(dev), skb);
|
||||
mt76_txq_init(&dev->mt76, txq);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* Copyright (C) 2015 Felix Fietkau <[email protected]>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2
|
||||
* as published by the Free Software Foundation
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "mt76.h"
|
||||
|
||||
static int
|
||||
mt76_txq_get_qid(struct ieee80211_txq *txq)
|
||||
{
|
||||
if (!txq->sta)
|
||||
return MT_TXQ_BE;
|
||||
|
||||
return txq->ac;
|
||||
}
|
||||
|
||||
static struct sk_buff *
|
||||
mt76_txq_dequeue(struct mt76_dev *dev, struct mt76_txq *mtxq, bool ps)
|
||||
{
|
||||
struct ieee80211_txq *txq = mtxq_to_txq(mtxq);
|
||||
struct sk_buff *skb;
|
||||
|
||||
skb = skb_dequeue(&mtxq->retry_q);
|
||||
if (skb) {
|
||||
u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
|
||||
|
||||
if (ps && skb_queue_empty(&mtxq->retry_q));
|
||||
ieee80211_sta_set_buffered(txq->sta, tid, false);
|
||||
|
||||
return skb;
|
||||
}
|
||||
|
||||
skb = ieee80211_tx_dequeue(dev->hw, txq);
|
||||
if (!skb)
|
||||
return NULL;
|
||||
|
||||
return skb;
|
||||
}
|
||||
|
||||
static void
|
||||
mt76_check_agg_ssn(struct mt76_txq *mtxq, struct sk_buff *skb)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
|
||||
if (!ieee80211_is_data_qos(hdr->frame_control))
|
||||
return;
|
||||
|
||||
mtxq->agg_ssn = le16_to_cpu(hdr->seq_ctrl) + 0x10;
|
||||
}
|
||||
|
||||
static void
|
||||
mt76_queue_ps_skb(struct mt76_dev *dev, struct ieee80211_sta *sta,
|
||||
struct sk_buff *skb, bool last)
|
||||
{
|
||||
struct mt76_wcid *wcid = (struct mt76_wcid *) sta->drv_priv;
|
||||
struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
|
||||
struct mt76_queue *hwq = &dev->q_tx[MT_TXQ_PSD];
|
||||
|
||||
info->control.flags |= IEEE80211_TX_CTRL_PS_RESPONSE;
|
||||
if (last)
|
||||
info->flags |= IEEE80211_TX_STATUS_EOSP;
|
||||
|
||||
mt76_skb_set_moredata(skb, !last);
|
||||
mt76_tx_queue_skb(dev, hwq, skb, wcid, sta);
|
||||
}
|
||||
|
||||
void
|
||||
mt76_release_buffered_frames(struct ieee80211_hw *hw, struct ieee80211_sta *sta,
|
||||
u16 tids, int nframes,
|
||||
enum ieee80211_frame_release_type reason,
|
||||
bool more_data)
|
||||
{
|
||||
struct mt76_dev *dev = hw->priv;
|
||||
struct sk_buff *last_skb = NULL;
|
||||
struct mt76_queue *hwq = &dev->q_tx[MT_TXQ_PSD];
|
||||
int i;
|
||||
|
||||
for (i = 0; tids && nframes; i++, tids >>= 1) {
|
||||
struct ieee80211_txq *txq = sta->txq[i];
|
||||
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
struct sk_buff *skb;
|
||||
|
||||
if (!(tids & 1))
|
||||
continue;
|
||||
|
||||
do {
|
||||
skb = mt76_txq_dequeue(dev, mtxq, true);
|
||||
if (!skb)
|
||||
break;
|
||||
|
||||
if (mtxq->aggr)
|
||||
mt76_check_agg_ssn(mtxq, skb);
|
||||
|
||||
nframes--;
|
||||
if (last_skb) {
|
||||
mt76_queue_ps_skb(dev, sta, last_skb, false);
|
||||
last_skb = skb;
|
||||
}
|
||||
} while (nframes);
|
||||
}
|
||||
|
||||
if (!last_skb)
|
||||
return;
|
||||
|
||||
mt76_queue_ps_skb(dev, sta, last_skb, true);
|
||||
dev->queue_ops->kick(dev, hwq);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_release_buffered_frames);
|
||||
|
||||
static int
|
||||
mt76_txq_send_burst(struct mt76_dev *dev, struct mt76_queue *hwq,
|
||||
struct mt76_txq *mtxq, bool *empty)
|
||||
{
|
||||
struct ieee80211_txq *txq = mtxq_to_txq(mtxq);
|
||||
struct ieee80211_tx_info *info;
|
||||
struct mt76_wcid *wcid = mtxq->wcid;
|
||||
struct sk_buff *skb = NULL;
|
||||
int n_frames = 1, limit;
|
||||
struct ieee80211_tx_rate tx_rate;
|
||||
bool ampdu;
|
||||
bool probe;
|
||||
int idx;
|
||||
|
||||
skb = mt76_txq_dequeue(dev, mtxq, false);
|
||||
if (!skb) {
|
||||
*empty = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
info = IEEE80211_SKB_CB(skb);
|
||||
if (!wcid->tx_rate_set)
|
||||
ieee80211_get_tx_rates(txq->vif, txq->sta, skb,
|
||||
info->control.rates, 1);
|
||||
tx_rate = info->control.rates[0];
|
||||
|
||||
probe = (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE);
|
||||
ampdu = IEEE80211_SKB_CB(skb)->flags & IEEE80211_TX_CTL_AMPDU;
|
||||
limit = ampdu ? 16 : 3;
|
||||
|
||||
if (ampdu)
|
||||
mt76_check_agg_ssn(mtxq, skb);
|
||||
|
||||
idx = mt76_tx_queue_skb(dev, hwq, skb, wcid, txq->sta);
|
||||
|
||||
if (idx < 0)
|
||||
return idx;
|
||||
|
||||
do {
|
||||
bool cur_ampdu;
|
||||
|
||||
if (probe)
|
||||
break;
|
||||
|
||||
skb = mt76_txq_dequeue(dev, mtxq, false);
|
||||
if (!skb) {
|
||||
*empty = true;
|
||||
break;
|
||||
}
|
||||
|
||||
cur_ampdu = info->flags & IEEE80211_TX_CTL_AMPDU;
|
||||
|
||||
if (ampdu != cur_ampdu ||
|
||||
(info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE)) {
|
||||
skb_queue_tail(&mtxq->retry_q, skb);
|
||||
break;
|
||||
}
|
||||
|
||||
info = IEEE80211_SKB_CB(skb);
|
||||
info->control.rates[0] = tx_rate;
|
||||
|
||||
if (cur_ampdu)
|
||||
mt76_check_agg_ssn(mtxq, skb);
|
||||
|
||||
idx = mt76_tx_queue_skb(dev, hwq, skb, wcid, txq->sta);
|
||||
if (idx < 0)
|
||||
return idx;
|
||||
|
||||
n_frames++;
|
||||
} while (n_frames < limit);
|
||||
|
||||
if (!probe) {
|
||||
hwq->swq_queued++;
|
||||
hwq->entry[idx].schedule = true;
|
||||
}
|
||||
|
||||
dev->queue_ops->kick(dev, hwq);
|
||||
|
||||
return n_frames;
|
||||
}
|
||||
|
||||
static int
|
||||
mt76_txq_schedule_list(struct mt76_dev *dev, struct mt76_queue *hwq)
|
||||
{
|
||||
struct mt76_txq *mtxq, *mtxq_last;
|
||||
int len = 0;
|
||||
|
||||
restart:
|
||||
mtxq_last = list_last_entry(&hwq->swq, struct mt76_txq, list);
|
||||
while (!list_empty(&hwq->swq)) {
|
||||
bool empty = false;
|
||||
int cur;
|
||||
|
||||
mtxq = list_first_entry(&hwq->swq, struct mt76_txq, list);
|
||||
if (mtxq->send_bar && mtxq->aggr) {
|
||||
struct ieee80211_txq *txq = mtxq_to_txq(mtxq);
|
||||
struct ieee80211_sta *sta = txq->sta;
|
||||
struct ieee80211_vif *vif = txq->vif;
|
||||
u16 agg_ssn = mtxq->agg_ssn;
|
||||
u8 tid = txq->tid;
|
||||
|
||||
mtxq->send_bar = false;
|
||||
spin_unlock_bh(&hwq->lock);
|
||||
ieee80211_send_bar(vif, sta->addr, tid, agg_ssn);
|
||||
spin_lock_bh(&hwq->lock);
|
||||
goto restart;
|
||||
}
|
||||
|
||||
list_del_init(&mtxq->list);
|
||||
|
||||
cur = mt76_txq_send_burst(dev, hwq, mtxq, &empty);
|
||||
if (!empty)
|
||||
list_add_tail(&mtxq->list, &hwq->swq);
|
||||
|
||||
if (cur < 0)
|
||||
return cur;
|
||||
|
||||
len += cur;
|
||||
|
||||
if (mtxq == mtxq_last)
|
||||
break;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void mt76_txq_schedule(struct mt76_dev *dev, struct mt76_queue *hwq)
|
||||
{
|
||||
int len;
|
||||
|
||||
do {
|
||||
if (hwq->swq_queued >= 4 || list_empty(&hwq->swq))
|
||||
break;
|
||||
|
||||
len = mt76_txq_schedule_list(dev, hwq);
|
||||
} while (len > 0);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_txq_schedule);
|
||||
|
||||
void mt76_stop_tx_queues(struct mt76_dev *dev, struct ieee80211_sta *sta)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(sta->txq); i++) {
|
||||
struct ieee80211_txq *txq = sta->txq[i];
|
||||
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
|
||||
spin_lock_bh(&mtxq->hwq->lock);
|
||||
mtxq->send_bar = mtxq->aggr;
|
||||
if (!list_empty(&mtxq->list))
|
||||
list_del_init(&mtxq->list);
|
||||
spin_unlock_bh(&mtxq->hwq->lock);
|
||||
}
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_stop_tx_queues);
|
||||
|
||||
void mt76_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq)
|
||||
{
|
||||
struct mt76_dev *dev = hw->priv;
|
||||
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
struct mt76_queue *hwq = mtxq->hwq;
|
||||
|
||||
spin_lock_bh(&hwq->lock);
|
||||
if (list_empty(&mtxq->list))
|
||||
list_add_tail(&mtxq->list, &hwq->swq);
|
||||
mt76_txq_schedule(dev, hwq);
|
||||
spin_unlock_bh(&hwq->lock);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_wake_tx_queue);
|
||||
|
||||
void mt76_txq_remove(struct mt76_dev *dev, struct ieee80211_txq *txq)
|
||||
{
|
||||
struct mt76_txq *mtxq;
|
||||
struct mt76_queue *hwq;
|
||||
struct sk_buff *skb;
|
||||
|
||||
if (!txq)
|
||||
return;
|
||||
|
||||
mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
hwq = mtxq->hwq;
|
||||
|
||||
spin_lock_bh(&hwq->lock);
|
||||
if (!list_empty(&mtxq->list))
|
||||
list_del(&mtxq->list);
|
||||
spin_unlock_bh(&hwq->lock);
|
||||
|
||||
while ((skb = skb_dequeue(&mtxq->retry_q)) != NULL)
|
||||
ieee80211_free_txskb(dev->hw, skb);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_txq_remove);
|
||||
|
||||
void mt76_txq_init(struct mt76_dev *dev, struct ieee80211_txq *txq)
|
||||
{
|
||||
struct mt76_txq *mtxq = (struct mt76_txq *) txq->drv_priv;
|
||||
|
||||
INIT_LIST_HEAD(&mtxq->list);
|
||||
skb_queue_head_init(&mtxq->retry_q);
|
||||
|
||||
mtxq->hwq = &dev->q_tx[mt76_txq_get_qid(txq)];
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mt76_txq_init);
|
||||
@@ -83,4 +83,15 @@
|
||||
int mt76_insert_hdr_pad(struct sk_buff *skb);
|
||||
void mt76_remove_hdr_pad(struct sk_buff *skb);
|
||||
|
||||
static inline void
|
||||
mt76_skb_set_moredata(struct sk_buff *skb, bool enable)
|
||||
{
|
||||
struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
|
||||
|
||||
if (enable)
|
||||
hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREDATA);
|
||||
else
|
||||
hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_MOREDATA);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user