Skip to contentSkip to conversation

mt76: mt7603: remove q_rx field from struct mt7603_dev

PATCH In review Felix Fietkau 2 participants 26 messages Sep 26, 2019 – Sep 28, 2019

Subsystems (2)
lore
Share & tools
lore

Felix Fietkau

author maintainer
#0 lore raw

PATCH 1/15 mt76: mt7603: remove q_rx field from struct mt7603_dev

It is no longer used

---
 drivers/net/wireless/mediatek/mt76/mt7603/mt7603.h | 2 --
 1 file changed, 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7603/mt7603.h +0 -2
index fb10adca17f3..17176de4fb23 100644
@@ -118,8 +118,6 @@ struct mt7603_dev {
 
 	ktime_t ed_time;
 
-	struct mt76_queue q_rx;
-
 	spinlock_t ps_lock;
 
 	u8 mac_work_count;
Signature · 1 line
2.17.0
author maintainer
#1 lore raw

PATCH 2/15 mt76: report rx a-mpdu subframe status

This can be used in monitor mode to figure out which subframes were sent as part of which A-MPDU

---
 drivers/net/wireless/mediatek/mt76/mac80211.c     |  1 +
 drivers/net/wireless/mediatek/mt76/mt76.h         |  3 +++
 drivers/net/wireless/mediatek/mt76/mt7603/mac.c   | 14 ++++++++++++++
 .../net/wireless/mediatek/mt76/mt7603/mt7603.h    |  1 +
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c   | 14 ++++++++++++++
 .../net/wireless/mediatek/mt76/mt7615/mt7615.h    |  2 ++
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.c  | 15 +++++++++++++++
 7 files changed, 50 insertions(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -0
index 1a2c143b34d0..cc301216e527 100644
@@ -502,6 +502,7 @@ static struct ieee80211_sta *mt76_rx_convert(struct sk_buff *skb)
 	status->band = mstat.band;
 	status->signal = mstat.signal;
 	status->chains = mstat.chains;
+	status->ampdu_reference = mstat.ampdu_ref;
 
 	BUILD_BUG_ON(sizeof(mstat) > sizeof(skb->cb));
 	BUILD_BUG_ON(sizeof(status->chain_signal) !=
drivers/net/wireless/mediatek/mt76/mt76.h +3 -0
index 331de7c44b6c..173d158d7018 100644
@@ -437,6 +437,7 @@ struct mt76_dev {
 	spinlock_t rx_lock;
 	struct napi_struct napi[__MT_RXQ_MAX];
 	struct sk_buff_head rx_skb[__MT_RXQ_MAX];
+	u32 ampdu_ref;
 
 	struct list_head txwi_cache;
 	struct mt76_sw_queue q_tx[__MT_TXQ_MAX];
@@ -513,6 +514,8 @@ struct mt76_rx_status {
 
 	unsigned long reorder_time;
 
+	u32 ampdu_ref;
+
 	u8 iv[6];
 
 	u8 aggr:1;
drivers/net/wireless/mediatek/mt76/mt7603/mac.c +14 -0
index c52c4bf5597e..44d093943588 100644
@@ -445,6 +445,20 @@ mt7603_mac_fill_rx(struct mt7603_dev *dev, struct sk_buff *skb)
 		status->flag |= RX_FLAG_MMIC_STRIPPED | RX_FLAG_MIC_STRIPPED;
 	}
 
+	if (!(rxd2 & (MT_RXD2_NORMAL_NON_AMPDU_SUB |
+		      MT_RXD2_NORMAL_NON_AMPDU))) {
+		status->flag |= RX_FLAG_AMPDU_DETAILS;
+
+		/* all subframes of an A-MPDU have the same timestamp */
+		if (dev->rx_ampdu_ts != rxd[12]) {
+			if (!++dev->mt76.ampdu_ref)
+				dev->mt76.ampdu_ref++;
+		}
+		dev->rx_ampdu_ts = rxd[12];
+
+		status->ampdu_ref = dev->mt76.ampdu_ref;
+	}
+
 	remove_pad = rxd1 & MT_RXD1_NORMAL_HDR_OFFSET;
 
 	if (rxd2 & MT_RXD2_NORMAL_MAX_LEN_ERROR)
drivers/net/wireless/mediatek/mt76/mt7603/mt7603.h +1 -0
index 17176de4fb23..01b933538c25 100644
@@ -109,6 +109,7 @@ struct mt7603_dev {
 	u32 false_cca_ofdm, false_cca_cck;
 	unsigned long last_cca_adj;
 
+	__le32 rx_ampdu_ts;
 	u8 rssi_offset[3];
 
 	u8 slottime;
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +14 -0
index 237d15521e18..88271524fb83 100644
@@ -93,6 +93,20 @@ int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
 		status->flag |= RX_FLAG_MMIC_STRIPPED | RX_FLAG_MIC_STRIPPED;
 	}
 
+	if (!(rxd2 & (MT_RXD2_NORMAL_NON_AMPDU_SUB |
+		      MT_RXD2_NORMAL_NON_AMPDU))) {
+		status->flag |= RX_FLAG_AMPDU_DETAILS;
+
+		/* all subframes of an A-MPDU have the same timestamp */
+		if (dev->rx_ampdu_ts != rxd[12]) {
+			if (!++dev->mt76.ampdu_ref)
+				dev->mt76.ampdu_ref++;
+		}
+		dev->rx_ampdu_ts = rxd[12];
+
+		status->ampdu_ref = dev->mt76.ampdu_ref;
+	}
+
 	remove_pad = rxd1 & MT_RXD1_NORMAL_HDR_OFFSET;
 
 	if (rxd2 & MT_RXD2_NORMAL_MAX_LEN_ERROR)
drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +2 -0
index 8a6142637bfd..fe084555754b 100644
@@ -81,6 +81,8 @@ struct mt7615_dev {
 	u32 vif_mask;
 	u32 omac_mask;
 
+	__le32 rx_ampdu_ts;
+
 	struct {
 		u8 n_pulses;
 		u32 period;
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +15 -0
index 0d000906b2e1..9d2795c1e943 100644
@@ -789,6 +789,21 @@ int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb,
 	if ((rxinfo & MT_RXINFO_BA) && !(rxinfo & MT_RXINFO_NULL))
 		status->aggr = true;
 
+	if (rxinfo & MT_RXINFO_AMPDU) {
+		status->flag |= RX_FLAG_AMPDU_DETAILS;
+		status->ampdu_ref = dev->mt76.ampdu_ref;
+
+		/*
+		 * When receiving an A-MPDU subframe and RSSI info is not valid,
+		 * we can assume that more subframes belonging to the same A-MPDU
+		 * are coming. The last one will have valid RSSI info
+		 */
+		if (!(rxinfo & MT_RXINFO_RSSI)) {
+			if (!++dev->mt76.ampdu_ref)
+				dev->mt76.ampdu_ref++;
+		}
+	}
+
 	if (WARN_ON_ONCE(len > skb->len))
 		return -EINVAL;
 
Signature · 1 line
2.17.0
author maintainer
#2 lore raw

PATCH 3/15 mt76: rename mt76_driver_ops txwi_flags to drv_flags and include tx aligned4

In reply to Felix Fietkau

This reduces the struct size and is useful for adding more flags later

---
 drivers/net/wireless/mediatek/mt76/dma.c        | 4 ++--
 drivers/net/wireless/mediatek/mt76/mt76.h       | 6 +++---
 drivers/net/wireless/mediatek/mt76/mt7615/pci.c | 2 +-
 drivers/net/wireless/mediatek/mt76/mt76x0/pci.c | 2 +-
 drivers/net/wireless/mediatek/mt76/mt76x2/pci.c | 2 +-
 5 files changed, 8 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/dma.c +2 -2
index c747eb24581c..e2ce59b260c1 100644
@@ -164,7 +164,7 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, enum mt76_txq_id qid, bool flush)
 			dev->drv->tx_complete_skb(dev, qid, &entry);
 
 		if (entry.txwi) {
-			if (!(dev->drv->txwi_flags & MT_TXWI_NO_FREE))
+			if (!(dev->drv->drv_flags & MT_DRV_TXWI_NO_FREE))
 				mt76_put_txwi(dev, entry.txwi);
 			wake = !flush;
 		}
@@ -299,7 +299,7 @@ mt76_dma_tx_queue_skb(struct mt76_dev *dev, enum mt76_txq_id qid,
 	txwi = mt76_get_txwi_ptr(dev, t);
 
 	skb->prev = skb->next = NULL;
-	if (dev->drv->tx_aligned4_skbs)
+	if (dev->drv->drv_flags & MT_DRV_TX_ALIGNED4_SKBS)
 		mt76_insert_hdr_pad(skb);
 
 	len = skb_headlen(skb);
drivers/net/wireless/mediatek/mt76/mt76.h +3 -3
index 173d158d7018..af71773c2d55 100644
@@ -279,11 +279,11 @@ struct mt76_hw_cap {
 	bool has_5ghz;
 };
 
-#define MT_TXWI_NO_FREE			BIT(0)
+#define MT_DRV_TXWI_NO_FREE		BIT(0)
+#define MT_DRV_TX_ALIGNED4_SKBS		BIT(1)
 
 struct mt76_driver_ops {
-	bool tx_aligned4_skbs;
-	u32 txwi_flags;
+	u32 drv_flags;
 	u16 txwi_size;
 
 	void (*update_survey)(struct mt76_dev *dev);
drivers/net/wireless/mediatek/mt76/mt7615/pci.c +1 -1
index e250607e0a80..73744563a573 100644
@@ -72,7 +72,7 @@ static int mt7615_pci_probe(struct pci_dev *pdev,
 	static const struct mt76_driver_ops drv_ops = {
 		/* txwi_size = txd size + txp size */
 		.txwi_size = MT_TXD_SIZE + sizeof(struct mt7615_txp),
-		.txwi_flags = MT_TXWI_NO_FREE,
+		.drv_flags = MT_DRV_TXWI_NO_FREE,
 		.tx_prepare_skb = mt7615_tx_prepare_skb,
 		.tx_complete_skb = mt7615_tx_complete_skb,
 		.rx_skb = mt7615_queue_rx_skb,
drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +1 -1
index 7705e55aa3d1..d20fd40418a7 100644
@@ -155,7 +155,7 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.txwi_size = sizeof(struct mt76x02_txwi),
-		.tx_aligned4_skbs = true,
+		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02_tx_prepare_skb,
 		.tx_complete_skb = mt76x02_tx_complete_skb,
drivers/net/wireless/mediatek/mt76/mt76x2/pci.c +1 -1
index 73c3104f8858..f7a1f82d8320 100644
@@ -21,7 +21,7 @@ mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.txwi_size = sizeof(struct mt76x02_txwi),
-		.tx_aligned4_skbs = true,
+		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02_tx_prepare_skb,
 		.tx_complete_skb = mt76x02_tx_complete_skb,
Signature · 1 line
2.17.0
author maintainer
#3 lore raw

PATCH 4/15 mt76: store current channel survey_state in struct mt76_dev

In reply to Felix Fietkau

Move mt76_channel_state() from mt76.h to mac80211.c
Preparation for updating channel state from more places in the drivers/core

---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 24 +++++++++++++++----
 drivers/net/wireless/mediatek/mt76/mt76.h     | 16 +------------
 .../net/wireless/mediatek/mt76/mt7603/mac.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt7615/mac.c   |  2 +-
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  |  2 +-
 5 files changed, 23 insertions(+), 23 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +19 -5
index cc301216e527..aefdd22d74ef 100644
@@ -180,6 +180,7 @@ mt76_init_sband(struct mt76_dev *dev, struct mt76_sband *msband,
 	sband->bitrates = rates;
 	sband->n_bitrates = n_rates;
 	dev->chandef.chan = &sband->channels[0];
+	dev->chan_state = &msband->chan[0];
 
 	ht_cap = &sband->ht_cap;
 	ht_cap->ht_supported = true;
@@ -398,11 +399,25 @@ bool mt76_has_tx_pending(struct mt76_dev *dev)
 }
 EXPORT_SYMBOL_GPL(mt76_has_tx_pending);
 
+static struct mt76_channel_state *
+mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c)
+{
+	struct mt76_sband *msband;
+	int idx;
+
+	if (c->band == NL80211_BAND_2GHZ)
+		msband = &dev->sband_2g;
+	else
+		msband = &dev->sband_5g;
+
+	idx = c - &msband->sband.channels[0];
+	return &msband->chan[idx];
+}
+
 void mt76_set_channel(struct mt76_dev *dev)
 {
 	struct ieee80211_hw *hw = dev->hw;
 	struct cfg80211_chan_def *chandef = &hw->conf.chandef;
-	struct mt76_channel_state *state;
 	bool offchannel = hw->conf.flags & IEEE80211_CONF_OFFCHANNEL;
 	int timeout = HZ / 5;
 
@@ -412,14 +427,13 @@ void mt76_set_channel(struct mt76_dev *dev)
 		dev->drv->update_survey(dev);
 
 	dev->chandef = *chandef;
+	dev->chan_state = mt76_channel_state(dev, chandef->chan);
 
 	if (!offchannel)
 		dev->main_chan = chandef->chan;
 
-	if (chandef->chan != dev->main_chan) {
-		state = mt76_channel_state(dev, chandef->chan);
-		memset(state, 0, sizeof(*state));
-	}
+	if (chandef->chan != dev->main_chan)
+		memset(dev->chan_state, 0, sizeof(*dev->chan_state));
 }
 EXPORT_SYMBOL_GPL(mt76_set_channel);
 
drivers/net/wireless/mediatek/mt76/mt76.h +1 -15
index af71773c2d55..3e4ababcae9b 100644
@@ -423,6 +423,7 @@ struct mt76_dev {
 	struct cfg80211_chan_def chandef;
 	struct ieee80211_channel *main_chan;
 
+	struct mt76_channel_state *chan_state;
 	spinlock_t lock;
 	spinlock_t cc_lock;
 
@@ -603,21 +604,6 @@ static inline u16 mt76_rev(struct mt76_dev *dev)
 #define mt76_queue_tx_cleanup(dev, ...)	(dev)->mt76.queue_ops->tx_cleanup(&((dev)->mt76), __VA_ARGS__)
 #define mt76_queue_kick(dev, ...)	(dev)->mt76.queue_ops->kick(&((dev)->mt76), __VA_ARGS__)
 
-static inline struct mt76_channel_state *
-mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c)
-{
-	struct mt76_sband *msband;
-	int idx;
-
-	if (c->band == NL80211_BAND_2GHZ)
-		msband = &dev->sband_2g;
-	else
-		msband = &dev->sband_5g;
-
-	idx = c - &msband->sband.channels[0];
-	return &msband->chan[idx];
-}
-
 struct mt76_dev *mt76_alloc_device(struct device *pdev, unsigned int size,
 				   const struct ieee80211_ops *ops,
 				   const struct mt76_driver_ops *drv_ops);
drivers/net/wireless/mediatek/mt76/mt7603/mac.c +1 -1
index 44d093943588..3d160230d929 100644
@@ -1491,7 +1491,7 @@ void mt7603_update_channel(struct mt76_dev *mdev)
 	if (!test_bit(MT76_STATE_RUNNING, &dev->mt76.state))
 		return;
 
-	state = mt76_channel_state(&dev->mt76, dev->mt76.chandef.chan);
+	state = mdev->chan_state;
 	busy = mt76_rr(dev, MT_MIB_STAT_PSCCA);
 
 	spin_lock_bh(&dev->mt76.cc_lock);
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +1 -1
index 88271524fb83..9189a86d7825 100644
@@ -1269,7 +1269,7 @@ void mt7615_update_channel(struct mt76_dev *mdev)
 	if (!test_bit(MT76_STATE_RUNNING, &mdev->state))
 		return;
 
-	state = mt76_channel_state(mdev, mdev->chandef.chan);
+	state = mdev->chan_state;
 	/* TODO: add DBDC support */
 	busy = mt76_get_field(dev, MT_MIB_SDR16(0), MT_MIB_BUSY_MASK);
 
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +1 -1
index 9d2795c1e943..f73ec17e5f47 100644
@@ -986,7 +986,7 @@ void mt76x02_update_channel(struct mt76_dev *mdev)
 	struct mt76_channel_state *state;
 	u32 active, busy;
 
-	state = mt76_channel_state(&dev->mt76, dev->mt76.chandef.chan);
+	state = mdev->chan_state;
 
 	busy = mt76_rr(dev, MT_CH_BUSY);
 	active = busy + mt76_rr(dev, MT_CH_IDLE);
Signature · 1 line
2.17.0
author maintainer
#4 lore raw

PATCH 5/15 mt76: track rx airtime for airtime fairness and survey

In reply to Felix Fietkau

Report total rx airtime for valid stations as BSS rx time in survey

mt7615 is left out for now, it will be supported later by reading hardware counters instead of calculating airtime in software

---
 drivers/net/wireless/mediatek/mt76/Makefile   |   2 +-
 drivers/net/wireless/mediatek/mt76/airtime.c  | 278 ++++++++++++++++++
 drivers/net/wireless/mediatek/mt76/mac80211.c | 109 ++++++-
 drivers/net/wireless/mediatek/mt76/mt76.h     |  64 ++--
 .../net/wireless/mediatek/mt76/mt7603/init.c  |   1 +
 .../net/wireless/mediatek/mt76/mt7603/mac.c   |   2 +-
 .../net/wireless/mediatek/mt76/mt7615/mac.c   |   2 +-
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |   3 +-
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |   1 +
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  |   4 +-
 .../net/wireless/mediatek/mt76/mt76x2/pci.c   |   3 +-
 .../net/wireless/mediatek/mt76/mt76x2/usb.c   |   1 +
 12 files changed, 433 insertions(+), 37 deletions(-)
 create mode 100644 drivers/net/wireless/mediatek/mt76/airtime.c
drivers/net/wireless/mediatek/mt76/Makefile +1 -1
index 4d03596e891f..181af60e32db 100644
@@ -6,7 +6,7 @@ obj-$(CONFIG_MT76x02_USB) += mt76x02-usb.o
 
 mt76-y := \
 	mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o \
-	tx.o agg-rx.o mcu.o
+	tx.o agg-rx.o mcu.o airtime.o
 
 mt76-usb-y := usb.o usb_trace.o
 
drivers/net/wireless/mediatek/mt76/airtime.c new file +278 -0

278 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mac80211.c +104 -5

150 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt76.h +39 -25

106 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7603/init.c +1 -0
index ad2ccdbe7258..a68533684b18 100644
@@ -7,6 +7,7 @@
 
 const struct mt76_driver_ops mt7603_drv_ops = {
 	.txwi_size = MT_TXD_SIZE,
+	.drv_flags = MT_DRV_SW_RX_AIRTIME,
 	.tx_prepare_skb = mt7603_tx_prepare_skb,
 	.tx_complete_skb = mt7603_tx_complete_skb,
 	.rx_skb = mt7603_queue_rx_skb,
drivers/net/wireless/mediatek/mt76/mt7603/mac.c +1 -1
index 3d160230d929..0212384d0d56 100644
@@ -1708,7 +1708,7 @@ void mt7603_mac_work(struct work_struct *work)
 	mutex_lock(&dev->mt76.mutex);
 
 	dev->mac_work_count++;
-	mt7603_update_channel(&dev->mt76);
+	mt76_update_survey(&dev->mt76);
 	mt7603_edcca_check(dev);
 
 	for (i = 0, idx = 0; i < 2; i++) {
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +1 -1
index 9189a86d7825..81f45c4ccc26 100644
@@ -1291,7 +1291,7 @@ void mt7615_mac_work(struct work_struct *work)
 						mac_work.work);
 
 	mutex_lock(&dev->mt76.mutex);
-	mt7615_update_channel(&dev->mt76);
+	mt76_update_survey(&dev->mt76);
 	if (++dev->mac_work_count == 5) {
 		mt7615_mac_scs_check(dev);
 		dev->mac_work_count = 0;
drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +2 -1
index d20fd40418a7..f42450b4319c 100644
@@ -155,7 +155,8 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.txwi_size = sizeof(struct mt76x02_txwi),
-		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS,
+		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
+			     MT_DRV_SW_RX_AIRTIME,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02_tx_prepare_skb,
 		.tx_complete_skb = mt76x02_tx_complete_skb,
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +1 -0
index 4c2b66b53533..54f9c0cc881f 100644
@@ -211,6 +211,7 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
 			 const struct usb_device_id *id)
 {
 	static const struct mt76_driver_ops drv_ops = {
+		.drv_flags = MT_DRV_SW_RX_AIRTIME,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02u_tx_prepare_skb,
 		.tx_complete_skb = mt76x02u_tx_complete_skb,
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +2 -2
index f73ec17e5f47..c987e57db0b4 100644
@@ -798,7 +798,7 @@ int mt76x02_mac_process_rx(struct mt76x02_dev *dev, struct sk_buff *skb,
 		 * we can assume that more subframes belonging to the same A-MPDU
 		 * are coming. The last one will have valid RSSI info
 		 */
-		if (!(rxinfo & MT_RXINFO_RSSI)) {
+		if (rxinfo & MT_RXINFO_RSSI) {
 			if (!++dev->mt76.ampdu_ref)
 				dev->mt76.ampdu_ref++;
 		}
@@ -1130,7 +1130,7 @@ void mt76x02_mac_work(struct work_struct *work)
 
 	mutex_lock(&dev->mt76.mutex);
 
-	mt76x02_update_channel(&dev->mt76);
+	mt76_update_survey(&dev->mt76);
 	for (i = 0, idx = 0; i < 16; i++) {
 		u32 val = mt76_rr(dev, MT_TX_AGG_CNT(i));
 
drivers/net/wireless/mediatek/mt76/mt76x2/pci.c +2 -1
index f7a1f82d8320..5304b6ecda26 100644
@@ -21,7 +21,8 @@ mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.txwi_size = sizeof(struct mt76x02_txwi),
-		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS,
+		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
+			     MT_DRV_SW_RX_AIRTIME,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02_tx_prepare_skb,
 		.tx_complete_skb = mt76x02_tx_complete_skb,
drivers/net/wireless/mediatek/mt76/mt76x2/usb.c +1 -0
index da5e0f9a8bae..81be59c60155 100644
@@ -25,6 +25,7 @@ static int mt76x2u_probe(struct usb_interface *intf,
 			 const struct usb_device_id *id)
 {
 	static const struct mt76_driver_ops drv_ops = {
+		.drv_flags = MT_DRV_SW_RX_AIRTIME,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02u_tx_prepare_skb,
 		.tx_complete_skb = mt76x02u_tx_complete_skb,
Signature · 1 line
2.17.0
#5 lore raw

Re: [PATCH 05/15] mt76: track rx airtime for airtime fairness and survey

Quoted 304 lines · Felix Fietkau

Report total rx airtime for valid stations as BSS rx time in survey

mt7615 is left out for now, it will be supported later by reading hardware counters instead of calculating airtime in software

---
 drivers/net/wireless/mediatek/mt76/Makefile   |   2 +-
 drivers/net/wireless/mediatek/mt76/airtime.c  | 278 ++++++++++++++++++
 drivers/net/wireless/mediatek/mt76/mac80211.c | 109 ++++++-
 drivers/net/wireless/mediatek/mt76/mt76.h     |  64 ++--
 .../net/wireless/mediatek/mt76/mt7603/init.c  |   1 +
 .../net/wireless/mediatek/mt76/mt7603/mac.c   |   2 +-
 .../net/wireless/mediatek/mt76/mt7615/mac.c   |   2 +-
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |   3 +-
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |   1 +
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  |   4 +-
 .../net/wireless/mediatek/mt76/mt76x2/pci.c   |   3 +-
 .../net/wireless/mediatek/mt76/mt76x2/usb.c   |   1 +
 12 files changed, 433 insertions(+), 37 deletions(-)
 create mode 100644 drivers/net/wireless/mediatek/mt76/airtime.c
drivers/net/wireless/mediatek/mt76/Makefile +1 -1
index 4d03596e891f..181af60e32db 100644
@@ -6,7 +6,7 @@ obj-$(CONFIG_MT76x02_USB) += mt76x02-usb.o
 
 mt76-y := \
 	mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o \
-	tx.o agg-rx.o mcu.o
+	tx.o agg-rx.o mcu.o airtime.o
 
 mt76-usb-y := usb.o usb_trace.o
 
drivers/net/wireless/mediatek/mt76/airtime.c new file +263 -0
new file mode 100644
index 000000000000..d5bc4d713a88
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: ISC
+/*
+ * Copyright (C) 2019 Felix Fietkau <[email protected]>
+ */
+
+#include "mt76.h"
+
+#define AVG_PKT_SIZE	1024
+
+/* Number of bits for an average sized packet */
+#define MCS_NBITS (AVG_PKT_SIZE << 3)
+
+/* Number of symbols for a packet with (bps) bits per symbol */
+#define MCS_NSYMS(bps) DIV_ROUND_UP(MCS_NBITS, (bps))
+
+/* Transmission time (1024 usec) for a packet containing (syms) * symbols */
+#define MCS_SYMBOL_TIME(sgi, syms)					\
+	(sgi ?								\
+	  ((syms) * 18 * 1024 + 4 * 1024) / 5 :	/* syms * 3.6 us */	\
+	  ((syms) * 1024) << 2			/* syms * 4 us */	\
+	)
+
+/* Transmit duration for the raw data part of an average sized packet */
+#define MCS_DURATION(streams, sgi, bps) \
+	MCS_SYMBOL_TIME(sgi, MCS_NSYMS((streams) * (bps)))
+
+#define BW_20			0
+#define BW_40			1
+#define BW_80			2
+
+/*
+ * Define group sort order: HT40 -> SGI -> #streams
+ */
+#define MT_MAX_STREAMS		4
+#define MT_HT_STREAM_GROUPS	4 /* BW(=2) * SGI(=2) */
+#define MT_VHT_STREAM_GROUPS	6 /* BW(=3) * SGI(=2) */
+
+#define MT_HT_GROUPS_NB	(MT_MAX_STREAMS *		\
+				 MT_HT_STREAM_GROUPS)
+#define MT_VHT_GROUPS_NB	(MT_MAX_STREAMS *		\
+				 MT_VHT_STREAM_GROUPS)
+#define MT_GROUPS_NB	(MT_HT_GROUPS_NB +	\
+				 MT_VHT_GROUPS_NB)
+
+#define MT_HT_GROUP_0	0
+#define MT_VHT_GROUP_0	(MT_HT_GROUP_0 + MT_HT_GROUPS_NB)
+
+#define MCS_GROUP_RATES		10
+
+#define HT_GROUP_IDX(_streams, _sgi, _ht40)	\
+	MT_HT_GROUP_0 +			\
+	MT_MAX_STREAMS * 2 * _ht40 +	\
+	MT_MAX_STREAMS * _sgi +	\
+	_streams - 1
+
+#define _MAX(a, b) (((a)>(b))?(a):(b))
+
+#define GROUP_SHIFT(duration)						\
+	_MAX(0, 16 - __builtin_clz(duration))
+
+/* MCS rate information for an MCS group */
+#define __MCS_GROUP(_streams, _sgi, _ht40, _s)				\
+	[HT_GROUP_IDX(_streams, _sgi, _ht40)] = {			\
+	.shift = _s,							\
+	.duration = {							\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26) >> _s,	\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 108 : 52) >> _s,	\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 162 : 78) >> _s,	\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 216 : 104) >> _s,	\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 324 : 156) >> _s,	\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 432 : 208) >> _s,	\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 486 : 234) >> _s,	\
+		MCS_DURATION(_streams, _sgi, _ht40 ? 540 : 260) >> _s	\
+	}								\
+}
+
+#define MCS_GROUP_SHIFT(_streams, _sgi, _ht40)				\
+	GROUP_SHIFT(MCS_DURATION(_streams, _sgi, _ht40 ? 54 : 26))
+
+#define MCS_GROUP(_streams, _sgi, _ht40)				\
+	__MCS_GROUP(_streams, _sgi, _ht40,				\
+		    MCS_GROUP_SHIFT(_streams, _sgi, _ht40))
+
+#define VHT_GROUP_IDX(_streams, _sgi, _bw)				\
+	(MT_VHT_GROUP_0 +						\
+	 MT_MAX_STREAMS * 2 * (_bw) +				\
+	 MT_MAX_STREAMS * (_sgi) +				\
+	 (_streams) - 1)
+
+#define BW2VBPS(_bw, r3, r2, r1)					\
+	(_bw == BW_80 ? r3 : _bw == BW_40 ? r2 : r1)
+
+#define __VHT_GROUP(_streams, _sgi, _bw, _s)				\
+	[VHT_GROUP_IDX(_streams, _sgi, _bw)] = {			\
+	.shift = _s,							\
+	.duration = {							\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw,  117,  54,  26)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw,  234, 108,  52)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw,  351, 162,  78)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw,  468, 216, 104)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw,  702, 324, 156)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw,  936, 432, 208)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw, 1053, 486, 234)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw, 1170, 540, 260)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw, 1404, 648, 312)) >> _s,	\
+		MCS_DURATION(_streams, _sgi,				\
+			     BW2VBPS(_bw, 1560, 720, 346)) >> _s	\
+	}								\
+}
+
+#define VHT_GROUP_SHIFT(_streams, _sgi, _bw)				\
+	GROUP_SHIFT(MCS_DURATION(_streams, _sgi,			\
+				 BW2VBPS(_bw,  117,  54,  26)))
+
+#define VHT_GROUP(_streams, _sgi, _bw)					\
+	__VHT_GROUP(_streams, _sgi, _bw,				\
+		    VHT_GROUP_SHIFT(_streams, _sgi, _bw))
+
+struct mcs_group {
+	u8 shift;
+	u16 duration[MCS_GROUP_RATES];
+};
+
+static const struct mcs_group airtime_mcs_groups[] = {
+	MCS_GROUP(1, 0, BW_20),
+	MCS_GROUP(2, 0, BW_20),
+	MCS_GROUP(3, 0, BW_20),
+	MCS_GROUP(4, 0, BW_20),
+
+	MCS_GROUP(1, 1, BW_20),
+	MCS_GROUP(2, 1, BW_20),
+	MCS_GROUP(3, 1, BW_20),
+	MCS_GROUP(4, 1, BW_20),
+
+	MCS_GROUP(1, 0, BW_40),
+	MCS_GROUP(2, 0, BW_40),
+	MCS_GROUP(3, 0, BW_40),
+	MCS_GROUP(4, 0, BW_40),
+
+	MCS_GROUP(1, 1, BW_40),
+	MCS_GROUP(2, 1, BW_40),
+	MCS_GROUP(3, 1, BW_40),
+	MCS_GROUP(4, 1, BW_40),
+
+	VHT_GROUP(1, 0, BW_20),
+	VHT_GROUP(2, 0, BW_20),
+	VHT_GROUP(3, 0, BW_20),
+	VHT_GROUP(4, 0, BW_20),
+
+	VHT_GROUP(1, 1, BW_20),
+	VHT_GROUP(2, 1, BW_20),
+	VHT_GROUP(3, 1, BW_20),
+	VHT_GROUP(4, 1, BW_20),
+
+	VHT_GROUP(1, 0, BW_40),
+	VHT_GROUP(2, 0, BW_40),
+	VHT_GROUP(3, 0, BW_40),
+	VHT_GROUP(4, 0, BW_40),
+
+	VHT_GROUP(1, 1, BW_40),
+	VHT_GROUP(2, 1, BW_40),
+	VHT_GROUP(3, 1, BW_40),
+	VHT_GROUP(4, 1, BW_40),
+
+	VHT_GROUP(1, 0, BW_80),
+	VHT_GROUP(2, 0, BW_80),
+	VHT_GROUP(3, 0, BW_80),
+	VHT_GROUP(4, 0, BW_80),
+
+	VHT_GROUP(1, 1, BW_80),
+	VHT_GROUP(2, 1, BW_80),
+	VHT_GROUP(3, 1, BW_80),
+	VHT_GROUP(4, 1, BW_80),
+};
+
+static u32
+mt76_calc_legacy_rate_duration(const struct ieee80211_rate *rate, bool short_pre,
+			       int len)
+{
+	u32 duration;
+
+	switch (rate->hw_value >> 8) {
+	case MT_PHY_TYPE_CCK:
+		duration = 144 + 48; /* preamble + PLCP */
+		if (short_pre)
+			duration >>= 1;
+
+		duration += 10; /* SIFS */
+		break;
+	case MT_PHY_TYPE_OFDM:
+		duration = 20 + 16; /* premable + SIFS */
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return 0;
+	}
+
+	len <<= 3;
+	duration += (len * 10) / rate->bitrate;
+
+	return duration;
+}
+
+u32 mt76_calc_rx_airtime(struct mt76_dev *dev, struct mt76_rx_status *status,
+			 int len)
+{
+	struct ieee80211_supported_band *sband;
+	const struct ieee80211_rate *rate;
+	bool sgi = status->enc_flags & RX_ENC_FLAG_SHORT_GI;
+	bool sp = status->enc_flags & RX_ENC_FLAG_SHORTPRE;
+	int bw, streams;
+	u32 duration;
+	int group, idx;
+
+	switch (status->bw) {
+	case RATE_INFO_BW_20:
+		bw = BW_20;
+		break;
+	case RATE_INFO_BW_40:
+		bw = BW_40;
+		break;
+	case RATE_INFO_BW_80:
+		bw = BW_80;
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return 0;
+	}
+
+	switch (status->encoding) {
+	case RX_ENC_LEGACY:
+		if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
+			return 0;
+
+		sband = dev->hw->wiphy->bands[status->band];
+		if (!sband || status->rate_idx > sband->n_bitrates)
+			return 0;
+
+		rate = &sband->bitrates[status->rate_idx];
+
+		return mt76_calc_legacy_rate_duration(rate, sp, len);
+	case RX_ENC_VHT:
+		streams = status->nss;
+		idx = status->rate_idx;
+		group = VHT_GROUP_IDX(streams, sgi, bw);
+		break;
+	case RX_ENC_HT:
+		streams = ((status->rate_idx >> 3) & 3) + 1;
+		idx = status->rate_idx & 7;
+		group = HT_GROUP_IDX(streams, sgi, bw);
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return 0;

drivers/net/wireless/mediatek/mt76/airtime.c line 273

Quoted 10 lines
drivers/net/wireless/mediatek/mt76/airtime.c new file +10 -0
+	}
+
+	if (WARN_ON_ONCE(streams > 4))
+		return 0;
+
+	duration = airtime_mcs_groups[group].duration[idx];
+	duration <<= airtime_mcs_groups[group].shift;
+	duration *= len;
+	duration /= AVG_PKT_SIZE;
+	duration /= 1024;

On an earlier patch of mine you expressed concern over divisions in the fast path. Does this mean this is no longer a concern? Or is the compiler doing fancy things with the constant division here? :)

-Toke

author maintainer
#6 lore raw

Re: [PATCH 05/15] mt76: track rx airtime for airtime fairness and survey

Quoted 32 lines · Toke Høiland-Jørgensen
Quoted 31 lines · Felix Fietkau
drivers/net/wireless/mediatek/mt76/airtime.c new file +31 -0
+	switch (status->encoding) {
+	case RX_ENC_LEGACY:
+		if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
+			return 0;
+
+		sband = dev->hw->wiphy->bands[status->band];
+		if (!sband || status->rate_idx > sband->n_bitrates)
+			return 0;
+
+		rate = &sband->bitrates[status->rate_idx];
+
+		return mt76_calc_legacy_rate_duration(rate, sp, len);
+	case RX_ENC_VHT:
+		streams = status->nss;
+		idx = status->rate_idx;
+		group = VHT_GROUP_IDX(streams, sgi, bw);
+		break;
+	case RX_ENC_HT:
+		streams = ((status->rate_idx >> 3) & 3) + 1;
+		idx = status->rate_idx & 7;
+		group = HT_GROUP_IDX(streams, sgi, bw);
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return 0;
+	}
+
+	if (WARN_ON_ONCE(streams > 4))
+		return 0;
+
+	duration = airtime_mcs_groups[group].duration[idx];
Quoted 8 lines

drivers/net/wireless/mediatek/mt76/airtime.c line 273

Quoted 4 lines
drivers/net/wireless/mediatek/mt76/airtime.c new file +4 -0
+	duration <<= airtime_mcs_groups[group].shift;
+	duration *= len;
+	duration /= AVG_PKT_SIZE;
+	duration /= 1024;

On an earlier patch of mine you expressed concern over divisions in the fast path. Does this mean this is no longer a concern? Or is the compiler doing fancy things with the constant division here? :)

I made the constants power-of-2, so that the compiler can turn them into bit shifts. I verified the disassembly: no divisions left in the code.

- Felix

#7 lore raw

Re: [PATCH 05/15] mt76: track rx airtime for airtime fairness and survey

Quoted 41 lines · Felix Fietkau
Quoted 32 lines · Toke Høiland-Jørgensen
Quoted 31 lines · Felix Fietkau
drivers/net/wireless/mediatek/mt76/airtime.c new file +31 -0
+	switch (status->encoding) {
+	case RX_ENC_LEGACY:
+		if (WARN_ON_ONCE(status->band > NL80211_BAND_5GHZ))
+			return 0;
+
+		sband = dev->hw->wiphy->bands[status->band];
+		if (!sband || status->rate_idx > sband->n_bitrates)
+			return 0;
+
+		rate = &sband->bitrates[status->rate_idx];
+
+		return mt76_calc_legacy_rate_duration(rate, sp, len);
+	case RX_ENC_VHT:
+		streams = status->nss;
+		idx = status->rate_idx;
+		group = VHT_GROUP_IDX(streams, sgi, bw);
+		break;
+	case RX_ENC_HT:
+		streams = ((status->rate_idx >> 3) & 3) + 1;
+		idx = status->rate_idx & 7;
+		group = HT_GROUP_IDX(streams, sgi, bw);
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return 0;
+	}
+
+	if (WARN_ON_ONCE(streams > 4))
+		return 0;
+
+	duration = airtime_mcs_groups[group].duration[idx];
Quoted 8 lines

drivers/net/wireless/mediatek/mt76/airtime.c line 273

Quoted 4 lines
drivers/net/wireless/mediatek/mt76/airtime.c new file +4 -0
+	duration <<= airtime_mcs_groups[group].shift;
+	duration *= len;
+	duration /= AVG_PKT_SIZE;
+	duration /= 1024;

On an earlier patch of mine you expressed concern over divisions in the fast path. Does this mean this is no longer a concern? Or is the compiler doing fancy things with the constant division here? :)

Quoted 2 lines

I made the constants power-of-2, so that the compiler can turn them into bit shifts. I verified the disassembly: no divisions left in the code.

I see. Neat :)

There's still a regular division in the legacy rate calc further up, though, right? But I guess that doesn't happen so often?

-Toke

author maintainer
#8 lore raw

PATCH 6/15 mt76: mt7603: track tx airtime for airtime fairness and survey

In reply to Felix Fietkau

Poll per-station hardware counters after tx status events

---
 drivers/net/wireless/mediatek/mt76/mac80211.c |  2 +
 drivers/net/wireless/mediatek/mt76/mt76.h     |  2 +
 .../net/wireless/mediatek/mt76/mt7603/dma.c   |  2 +
 .../net/wireless/mediatek/mt76/mt7603/init.c  |  3 +
 .../net/wireless/mediatek/mt76/mt7603/mac.c   | 86 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7603/main.c  |  7 ++
 .../wireless/mediatek/mt76/mt7603/mt7603.h    |  7 ++
 7 files changed, 109 insertions(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +2 -0
index aab181bc6eb2..5fcadd712f89 100644
@@ -481,6 +481,7 @@ int mt76_get_survey(struct ieee80211_hw *hw, int idx,
 	memset(survey, 0, sizeof(*survey));
 	survey->channel = chan;
 	survey->filled = SURVEY_INFO_TIME | SURVEY_INFO_TIME_BUSY;
+	survey->filled |= dev->drv->survey_flags;
 	if (chan == dev->main_chan) {
 		survey->filled |= SURVEY_INFO_IN_USE;
 
@@ -492,6 +493,7 @@ int mt76_get_survey(struct ieee80211_hw *hw, int idx,
 	survey->time = div_u64(state->cc_active, 1000);
 	survey->time_busy = div_u64(state->cc_busy, 1000);
 	survey->time_bss_rx = div_u64(state->cc_bss_rx, 1000);
+	survey->time_tx = div_u64(state->cc_tx, 1000);
 	spin_unlock_bh(&dev->cc_lock);
 
 	return ret;
drivers/net/wireless/mediatek/mt76/mt76.h +2 -0
index 911347bd272c..4f3849b4f677 100644
@@ -285,6 +285,7 @@ struct mt76_hw_cap {
 
 struct mt76_driver_ops {
 	u32 drv_flags;
+	u32 survey_flags;
 	u16 txwi_size;
 
 	void (*update_survey)(struct mt76_dev *dev);
@@ -321,6 +322,7 @@ struct mt76_channel_state {
 	u64 cc_active;
 	u64 cc_busy;
 	u64 cc_bss_rx;
+	u64 cc_tx;
 };
 
 struct mt76_sband {
drivers/net/wireless/mediatek/mt76/mt7603/dma.c +2 -0
index 24d82a20d046..a6ab73060aad 100644
@@ -152,6 +152,8 @@ static int mt7603_poll_tx(struct napi_struct *napi, int budget)
 	for (i = MT_TXQ_MCU; i >= 0; i--)
 		mt76_queue_tx_cleanup(dev, i, false);
 
+	mt7603_mac_sta_poll(dev);
+
 	tasklet_schedule(&dev->mt76.tx_tasklet);
 
 	return 0;
drivers/net/wireless/mediatek/mt76/mt7603/init.c +3 -0
index a68533684b18..3a2927a524c3 100644
@@ -8,6 +8,7 @@
 const struct mt76_driver_ops mt7603_drv_ops = {
 	.txwi_size = MT_TXD_SIZE,
 	.drv_flags = MT_DRV_SW_RX_AIRTIME,
+	.survey_flags = SURVEY_INFO_TIME_TX,
 	.tx_prepare_skb = mt7603_tx_prepare_skb,
 	.tx_complete_skb = mt7603_tx_complete_skb,
 	.rx_skb = mt7603_queue_rx_skb,
@@ -525,6 +526,8 @@ int mt7603_register_device(struct mt7603_dev *dev)
 	bus_ops->rmw = mt7603_rmw;
 	dev->mt76.bus = bus_ops;
 
+	INIT_LIST_HEAD(&dev->sta_poll_list);
+	spin_lock_init(&dev->sta_poll_lock);
 	spin_lock_init(&dev->ps_lock);
 
 	INIT_DELAYED_WORK(&dev->mt76.mac_work, mt7603_mac_work);
drivers/net/wireless/mediatek/mt76/mt7603/mac.c +86 -0

104 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7603/main.c +7 -0
index e7b57f20b629..180eb6bb781a 100644
@@ -66,6 +66,7 @@ mt7603_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
 
 	idx = MT7603_WTBL_RESERVED - 1 - mvif->idx;
 	dev->vif_mask |= BIT(mvif->idx);
+	INIT_LIST_HEAD(&mvif->sta.poll_list);
 	mvif->sta.wcid.idx = idx;
 	mvif->sta.wcid.hw_key_idx = -1;
 
@@ -325,6 +326,7 @@ mt7603_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	if (idx < 0)
 		return -ENOSPC;
 
+	INIT_LIST_HEAD(&msta->poll_list);
 	__skb_queue_head_init(&msta->psq);
 	msta->ps = ~0;
 	msta->smps = ~0;
@@ -361,6 +363,11 @@ mt7603_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	mt7603_filter_tx(dev, wcid->idx, true);
 	spin_unlock_bh(&dev->ps_lock);
 
+	spin_lock_bh(&dev->sta_poll_lock);
+	if (!list_empty(&msta->poll_list))
+		list_del_init(&msta->poll_list);
+	spin_unlock_bh(&dev->sta_poll_lock);
+
 	mt7603_wtbl_clear(dev, wcid->idx);
 }
 
drivers/net/wireless/mediatek/mt76/mt7603/mt7603.h +7 -0
index 01b933538c25..ab54b0612e98 100644
@@ -61,6 +61,9 @@ struct mt7603_sta {
 
 	struct mt7603_vif *vif;
 
+	struct list_head poll_list;
+	u32 tx_airtime_ac[4];
+
 	struct sk_buff_head psq;
 
 	struct ieee80211_tx_rate rates[4];
@@ -103,6 +106,9 @@ struct mt7603_dev {
 
 	u8 vif_mask;
 
+	struct list_head sta_poll_list;
+	spinlock_t sta_poll_lock;
+
 	struct mt7603_sta global_sta;
 
 	u32 agc0, agc3;
@@ -202,6 +208,7 @@ void mt7603_mac_add_txs(struct mt7603_dev *dev, void *data);
 void mt7603_mac_rx_ba_reset(struct mt7603_dev *dev, void *addr, u8 tid);
 void mt7603_mac_tx_ba_reset(struct mt7603_dev *dev, int wcid, int tid,
 			    int ba_size);
+void mt7603_mac_sta_poll(struct mt7603_dev *dev);
 
 void mt7603_pse_client_reset(struct mt7603_dev *dev);
 
Signature · 1 line
2.17.0
author maintainer
#9 lore raw

PATCH 7/15 mt76: mt7603: switch to a different counter for survey busy time

In reply to Felix Fietkau

MT_MIB_STAT_PSCCA only counts rx CCA busy time, which does not include tx time. MT_MIB_STAT_CCA counts full busy time, including Rx, Tx and NAV

---
 drivers/net/wireless/mediatek/mt76/mt7603/mac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt7603/mac.c +1 -1
index caa1456adc50..8e6568d4505b 100644
@@ -1578,7 +1578,7 @@ void mt7603_update_channel(struct mt76_dev *mdev)
 		return;
 
 	state = mdev->chan_state;
-	busy = mt76_rr(dev, MT_MIB_STAT_PSCCA);
+	busy = mt76_rr(dev, MT_MIB_STAT_CCA);
 
 	spin_lock_bh(&dev->mt76.cc_lock);
 	cur_time = ktime_get_boottime();
Signature · 1 line
2.17.0
author maintainer
#10 lore raw

PATCH 8/15 mt76: unify channel survey update code

In reply to Felix Fietkau

Host time is used to calculate the channel active time on mt7603 and mt7615. Use the same on mt76x02 and move the lock to core code to get rid of some duplicated code.

---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 16 +++++++++++++--
 .../net/wireless/mediatek/mt76/mt7603/mac.c   | 15 +-------------
 .../net/wireless/mediatek/mt76/mt7615/mac.c   | 18 +++--------------
 .../net/wireless/mediatek/mt76/mt76x0/main.c  |  5 +----
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 20 ++++++++++---------
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  1 +
 .../wireless/mediatek/mt76/mt76x2/pci_main.c  |  5 +----
 .../wireless/mediatek/mt76/mt76x2/usb_main.c  |  5 +----
 8 files changed, 33 insertions(+), 52 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +14 -2
index 5fcadd712f89..5aba8bc0b086 100644
@@ -416,13 +416,25 @@ mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c)
 
 void mt76_update_survey(struct mt76_dev *dev)
 {
-	struct mt76_channel_state *state;
+	struct mt76_channel_state *state = dev->chan_state;
+	ktime_t cur_time;
+
+	if (!test_bit(MT76_STATE_RUNNING, &dev->state))
+		return;
+
+	spin_lock_bh(&dev->cc_lock);
 
 	if (dev->drv->update_survey)
 		dev->drv->update_survey(dev);
 
+	cur_time = ktime_get_boottime();
+	state->cc_active += ktime_to_us(ktime_sub(cur_time,
+						  dev->survey_time));
+	dev->survey_time = cur_time;
+
+	spin_unlock_bh(&dev->cc_lock);
+
 	if (dev->drv->drv_flags & MT_DRV_SW_RX_AIRTIME) {
-		state = mt76_channel_state(dev, dev->chandef.chan);
 		spin_lock_bh(&dev->rx_lock);
 		spin_lock(&dev->cc_lock);
 		state->cc_bss_rx += dev->cur_cc_bss_rx;
drivers/net/wireless/mediatek/mt76/mt7603/mac.c +1 -14
index 8e6568d4505b..1497d5ec649e 100644
@@ -1571,22 +1571,9 @@ void mt7603_update_channel(struct mt76_dev *mdev)
 {
 	struct mt7603_dev *dev = container_of(mdev, struct mt7603_dev, mt76);
 	struct mt76_channel_state *state;
-	ktime_t cur_time;
-	u32 busy;
-
-	if (!test_bit(MT76_STATE_RUNNING, &dev->mt76.state))
-		return;
 
 	state = mdev->chan_state;
-	busy = mt76_rr(dev, MT_MIB_STAT_CCA);
-
-	spin_lock_bh(&dev->mt76.cc_lock);
-	cur_time = ktime_get_boottime();
-	state->cc_busy += busy;
-	state->cc_active += ktime_to_us(ktime_sub(cur_time,
-						  dev->mt76.survey_time));
-	dev->mt76.survey_time = cur_time;
-	spin_unlock_bh(&dev->mt76.cc_lock);
+	state->cc_busy += mt76_rr(dev, MT_MIB_STAT_CCA);
 }
 
 void
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +3 -15
index 81f45c4ccc26..271f36f4acb3 100644
@@ -1263,23 +1263,11 @@ void mt7615_update_channel(struct mt76_dev *mdev)
 {
 	struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
 	struct mt76_channel_state *state;
-	ktime_t cur_time;
-	u32 busy;
 
-	if (!test_bit(MT76_STATE_RUNNING, &mdev->state))
-		return;
-
-	state = mdev->chan_state;
 	/* TODO: add DBDC support */
-	busy = mt76_get_field(dev, MT_MIB_SDR16(0), MT_MIB_BUSY_MASK);
-
-	spin_lock_bh(&mdev->cc_lock);
-	cur_time = ktime_get_boottime();
-	state->cc_busy += busy;
-	state->cc_active += ktime_to_us(ktime_sub(cur_time,
-						  mdev->survey_time));
-	mdev->survey_time = cur_time;
-	spin_unlock_bh(&mdev->cc_lock);
+	state = mdev->chan_state;
+	state->cc_busy += mt76_get_field(dev, MT_MIB_SDR16(0),
+					 MT_MIB_BUSY_MASK);
 }
 
 void mt7615_mac_work(struct work_struct *work)
drivers/net/wireless/mediatek/mt76/mt76x0/main.c +1 -4
index efb7ca93863d..f7682bd2e5a8 100644
@@ -19,10 +19,7 @@ mt76x0_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
 	mt76_set_channel(&dev->mt76);
 	mt76x0_phy_set_channel(dev, chandef);
 
-	/* channel cycle counters read-and-clear */
-	mt76_rr(dev, MT_CH_IDLE);
-	mt76_rr(dev, MT_CH_BUSY);
-
+	mt76x02_mac_cc_reset(dev);
 	mt76x02_edcca_init(dev);
 
 	if (mt76_is_mmio(dev)) {
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +11 -9
index c987e57db0b4..e49d0136adbc 100644
@@ -984,17 +984,9 @@ void mt76x02_update_channel(struct mt76_dev *mdev)
 {
 	struct mt76x02_dev *dev = container_of(mdev, struct mt76x02_dev, mt76);
 	struct mt76_channel_state *state;
-	u32 active, busy;
 
 	state = mdev->chan_state;
-
-	busy = mt76_rr(dev, MT_CH_BUSY);
-	active = busy + mt76_rr(dev, MT_CH_IDLE);
-
-	spin_lock_bh(&dev->mt76.cc_lock);
-	state->cc_busy += busy;
-	state->cc_active += active;
-	spin_unlock_bh(&dev->mt76.cc_lock);
+	state->cc_busy += mt76_rr(dev, MT_CH_BUSY);
 }
 EXPORT_SYMBOL_GPL(mt76x02_update_channel);
 
@@ -1152,6 +1144,16 @@ void mt76x02_mac_work(struct work_struct *work)
 				     MT_MAC_WORK_INTERVAL);
 }
 
+void mt76x02_mac_cc_reset(struct mt76x02_dev *dev)
+{
+	dev->mt76.survey_time = ktime_get_boottime();
+
+	/* channel cycle counters read-and-clear */
+	mt76_rr(dev, MT_CH_BUSY);
+	mt76_rr(dev, MT_CH_IDLE);
+}
+EXPORT_SYMBOL_GPL(mt76x02_mac_cc_reset);
+
 void mt76x02_mac_set_bssid(struct mt76x02_dev *dev, u8 idx, const u8 *addr)
 {
 	idx &= 7;
drivers/net/wireless/mediatek/mt76/mt76x02_mac.h +1 -0
index b687341236c0..48de8eb82856 100644
@@ -193,6 +193,7 @@ void mt76x02_tx_complete_skb(struct mt76_dev *mdev, enum mt76_txq_id qid,
 void mt76x02_update_channel(struct mt76_dev *mdev);
 void mt76x02_mac_work(struct work_struct *work);
 
+void mt76x02_mac_cc_reset(struct mt76x02_dev *dev);
 void mt76x02_mac_set_bssid(struct mt76x02_dev *dev, u8 idx, const u8 *addr);
 int mt76x02_mac_set_beacon(struct mt76x02_dev *dev, u8 vif_idx,
 			   struct sk_buff *skb);
drivers/net/wireless/mediatek/mt76/mt76x2/pci_main.c +1 -4
index 385960dca906..1387f3172d7f 100644
@@ -52,10 +52,7 @@ mt76x2_set_channel(struct mt76x02_dev *dev, struct cfg80211_chan_def *chandef)
 	mt76x2_mac_stop(dev, true);
 	ret = mt76x2_phy_set_channel(dev, chandef);
 
-	/* channel cycle counters read-and-clear */
-	mt76_rr(dev, MT_CH_IDLE);
-	mt76_rr(dev, MT_CH_BUSY);
-
+	mt76x02_mac_cc_reset(dev);
 	mt76x02_dfs_init_params(dev);
 
 	mt76x2_mac_resume(dev);
drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c +1 -4
index 1e6f78760dd8..a76a40dcd261 100644
@@ -49,10 +49,7 @@ mt76x2u_set_channel(struct mt76x02_dev *dev,
 
 	err = mt76x2u_phy_set_channel(dev, chandef);
 
-	/* channel cycle counters read-and-clear */
-	mt76_rr(dev, MT_CH_IDLE);
-	mt76_rr(dev, MT_CH_BUSY);
-
+	mt76x02_mac_cc_reset(dev);
 	mt76x2_mac_resume(dev);
 
 	clear_bit(MT76_RESET, &dev->mt76.state);
Signature · 1 line
2.17.0
author maintainer
#11 lore raw

PATCH 9/15 mt76: mt76x02: move MT_CH_TIME_CFG init to mt76x02_mac_cc_reset

In reply to Felix Fietkau

Reduces code duplication and adds missing bits for USB variants

---
 drivers/net/wireless/mediatek/mt76/mt76x0/pci.c      | 9 ---------
 drivers/net/wireless/mediatek/mt76/mt76x0/usb.c      | 7 -------
 drivers/net/wireless/mediatek/mt76/mt76x02_mac.c     | 9 +++++++++
 drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c | 9 ---------
 drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c | 7 -------
 5 files changed, 9 insertions(+), 32 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +0 -9
index f42450b4319c..9f224f0f7c00 100644
@@ -132,15 +132,6 @@ static int mt76x0e_register_device(struct mt76x02_dev *dev)
 	mt76_clear(dev, 0x110, BIT(9));
 	mt76_set(dev, MT_MAX_LEN_CFG, BIT(13));
 
-	mt76_wr(dev, MT_CH_TIME_CFG,
-		MT_CH_TIME_CFG_TIMER_EN |
-		MT_CH_TIME_CFG_TX_AS_BUSY |
-		MT_CH_TIME_CFG_RX_AS_BUSY |
-		MT_CH_TIME_CFG_NAV_AS_BUSY |
-		MT_CH_TIME_CFG_EIFS_AS_BUSY |
-		MT_CH_CCA_RC_EN |
-		FIELD_PREP(MT_CH_TIME_CFG_CH_TIMER_CLR, 1));
-
 	err = mt76x0_register_device(dev);
 	if (err < 0)
 		return err;
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +0 -7
index 54f9c0cc881f..259bd2a55b23 100644
@@ -165,13 +165,6 @@ static int mt76x0u_init_hardware(struct mt76x02_dev *dev, bool reset)
 		FIELD_PREP(MT_TXOP_TRUN_EN, 0x3f) |
 		FIELD_PREP(MT_TXOP_EXT_CCA_DLY, 0x58));
 
-	mt76_wr(dev, MT_CH_TIME_CFG,
-		MT_CH_TIME_CFG_TIMER_EN |
-		MT_CH_TIME_CFG_TX_AS_BUSY |
-		MT_CH_TIME_CFG_RX_AS_BUSY |
-		MT_CH_TIME_CFG_NAV_AS_BUSY |
-		MT_CH_TIME_CFG_EIFS_AS_BUSY);
-
 	return 0;
 }
 
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +9 -0
index e49d0136adbc..d32efc0b100d 100644
@@ -1148,6 +1148,15 @@ void mt76x02_mac_cc_reset(struct mt76x02_dev *dev)
 {
 	dev->mt76.survey_time = ktime_get_boottime();
 
+	mt76_wr(dev, MT_CH_TIME_CFG,
+		MT_CH_TIME_CFG_TIMER_EN |
+		MT_CH_TIME_CFG_TX_AS_BUSY |
+		MT_CH_TIME_CFG_RX_AS_BUSY |
+		MT_CH_TIME_CFG_NAV_AS_BUSY |
+		MT_CH_TIME_CFG_EIFS_AS_BUSY |
+		MT_CH_CCA_RC_EN |
+		FIELD_PREP(MT_CH_TIME_CFG_CH_TIMER_CLR, 1));
+
 	/* channel cycle counters read-and-clear */
 	mt76_rr(dev, MT_CH_BUSY);
 	mt76_rr(dev, MT_CH_IDLE);
drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c +0 -9
index 3cf54963854a..33fcec9179b2 100644
@@ -133,15 +133,6 @@ int mt76x2_mac_reset(struct mt76x02_dev *dev, bool hard)
 	for (i = 0; i < 16; i++)
 		mt76_rr(dev, MT_TX_STAT_FIFO);
 
-	mt76_wr(dev, MT_CH_TIME_CFG,
-		MT_CH_TIME_CFG_TIMER_EN |
-		MT_CH_TIME_CFG_TX_AS_BUSY |
-		MT_CH_TIME_CFG_RX_AS_BUSY |
-		MT_CH_TIME_CFG_NAV_AS_BUSY |
-		MT_CH_TIME_CFG_EIFS_AS_BUSY |
-		MT_CH_CCA_RC_EN |
-		FIELD_PREP(MT_CH_TIME_CFG_CH_TIMER_CLR, 1));
-
 	mt76x02_set_tx_ackto(dev);
 
 	return 0;
drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c +0 -7
index e305b374c904..2910068f4e79 100644
@@ -184,13 +184,6 @@ int mt76x2u_init_hardware(struct mt76x02_dev *dev)
 	mt76x02_phy_set_rxpath(dev);
 	mt76x02_phy_set_txdac(dev);
 
-	mt76_wr(dev, MT_CH_TIME_CFG,
-		MT_CH_TIME_CFG_TIMER_EN |
-		MT_CH_TIME_CFG_TX_AS_BUSY |
-		MT_CH_TIME_CFG_RX_AS_BUSY |
-		MT_CH_TIME_CFG_NAV_AS_BUSY |
-		MT_CH_TIME_CFG_EIFS_AS_BUSY);
-
 	return mt76x2u_mac_stop(dev);
 }
 
Signature · 1 line
2.17.0
author maintainer
#12 lore raw

PATCH 10/15 mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

In reply to Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

---
 drivers/net/wireless/mediatek/mt76/airtime.c  | 48 ++++++++++++++++++
 drivers/net/wireless/mediatek/mt76/mt76.h     |  2 +
 .../net/wireless/mediatek/mt76/mt76x0/pci.c   |  1 +
 .../net/wireless/mediatek/mt76/mt76x0/usb.c   |  1 +
 drivers/net/wireless/mediatek/mt76/mt76x02.h  |  1 +
 .../net/wireless/mediatek/mt76/mt76x02_mac.c  | 49 ++++++++++++++++---
 .../net/wireless/mediatek/mt76/mt76x02_mac.h  |  6 +++
 .../net/wireless/mediatek/mt76/mt76x02_txrx.c | 10 +++-
 .../wireless/mediatek/mt76/mt76x02_usb_core.c |  4 +-
 .../net/wireless/mediatek/mt76/mt76x02_util.c |  1 +
 .../net/wireless/mediatek/mt76/mt76x2/pci.c   |  1 +
 .../net/wireless/mediatek/mt76/mt76x2/usb.c   |  1 +
 12 files changed, 117 insertions(+), 8 deletions(-)
drivers/net/wireless/mediatek/mt76/airtime.c +48 -0
index d5bc4d713a88..55116f395f9a 100644
@@ -276,3 +276,51 @@ u32 mt76_calc_rx_airtime(struct mt76_dev *dev, struct mt76_rx_status *status,
 
 	return duration;
 }
+
+u32 mt76_calc_tx_airtime(struct mt76_dev *dev, struct ieee80211_tx_info *info,
+			 int len)
+{
+	struct mt76_rx_status stat = {
+		.band = info->band,
+	};
+	u32 duration = 0;
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(info->status.rates); i++) {
+		struct ieee80211_tx_rate *rate = &info->status.rates[i];
+		u32 cur_duration;
+
+		if (rate->idx < 0 || !rate->count)
+			break;
+
+		if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
+			stat.bw = RATE_INFO_BW_80;
+		else if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
+			stat.bw = RATE_INFO_BW_40;
+		else
+			stat.bw = RATE_INFO_BW_20;
+
+		stat.enc_flags = 0;
+		if (rate->flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE)
+			stat.enc_flags |= RX_ENC_FLAG_SHORTPRE;
+		if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
+			stat.enc_flags |= RX_ENC_FLAG_SHORT_GI;
+
+		stat.rate_idx = rate->idx;
+		if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
+			stat.encoding = RX_ENC_VHT;
+			stat.rate_idx = ieee80211_rate_get_vht_mcs(rate);
+			stat.nss = ieee80211_rate_get_vht_nss(rate);
+		} else if (rate->flags & IEEE80211_TX_RC_MCS) {
+			stat.encoding = RX_ENC_HT;
+		} else {
+			stat.encoding = RX_ENC_LEGACY;
+		}
+
+		cur_duration = mt76_calc_rx_airtime(dev, &stat, len);
+		duration += cur_duration * rate->count;
+	}
+
+	return duration;
+}
+EXPORT_SYMBOL_GPL(mt76_calc_tx_airtime);
drivers/net/wireless/mediatek/mt76/mt76.h +2 -0
index 4f3849b4f677..49511bd06fd9 100644
@@ -770,6 +770,8 @@ void mt76_sw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 		  const u8 *mac);
 void mt76_sw_scan_complete(struct ieee80211_hw *hw,
 			   struct ieee80211_vif *vif);
+u32 mt76_calc_tx_airtime(struct mt76_dev *dev, struct ieee80211_tx_info *info,
+			 int len);
 
 /* internal */
 void mt76_tx_free(struct mt76_dev *dev);
drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +1 -0
index 9f224f0f7c00..9621e7b16eaf 100644
@@ -148,6 +148,7 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		.txwi_size = sizeof(struct mt76x02_txwi),
 		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
 			     MT_DRV_SW_RX_AIRTIME,
+		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02_tx_prepare_skb,
 		.tx_complete_skb = mt76x02_tx_complete_skb,
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +1 -0
index 259bd2a55b23..ade6312c7367 100644
@@ -205,6 +205,7 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.drv_flags = MT_DRV_SW_RX_AIRTIME,
+		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02u_tx_prepare_skb,
 		.tx_complete_skb = mt76x02u_tx_complete_skb,
drivers/net/wireless/mediatek/mt76/mt76x02.h +1 -0
index 50b0131f85bf..0ca0bbfe8769 100644
@@ -81,6 +81,7 @@ struct mt76x02_dev {
 	u8 txdone_seq;
 	DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status);
 	spinlock_t txstatus_fifo_lock;
+	u32 tx_airtime;
 
 	struct sk_buff *rx_head;
 
drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +43 -6

99 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt76x02_mac.h +6 -0
index 48de8eb82856..7d946aa77182 100644
@@ -23,11 +23,16 @@ struct mt76x02_tx_status {
 #define MT_VIF_WCID(_n)		(254 - ((_n) & 7))
 #define MT_MAX_VIFS		8
 
+#define MT_PKTID_RATE		GENMASK(4, 0)
+#define MT_PKTID_AC		GENMASK(6, 5)
+
 struct mt76x02_vif {
 	struct mt76_wcid group_wcid; /* must be first */
 	u8 idx;
 };
 
+DECLARE_EWMA(pktlen, 8, 8);
+
 struct mt76x02_sta {
 	struct mt76_wcid wcid; /* must be first */
 
@@ -35,6 +40,7 @@ struct mt76x02_sta {
 	struct mt76x02_tx_status status;
 	int n_frames;
 
+	struct ewma_pktlen pktlen;
 };
 
 #define MT_RXINFO_BA			BIT(0)
drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c +9 -1
index f27aade34c1e..13825f642087 100644
@@ -158,7 +158,9 @@ int mt76x02_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 	/* encode packet rate for no-skb packet id to fix up status reporting */
 	if (pid == MT_PACKET_ID_NO_SKB)
 		pid = MT_PACKET_ID_HAS_RATE |
-		      (le16_to_cpu(txwi->rate) & MT_RXWI_RATE_INDEX);
+		      (le16_to_cpu(txwi->rate) & MT_RXWI_RATE_INDEX) |
+		      FIELD_PREP(MT_PKTID_AC,
+				 skb_get_queue_mapping(tx_info->skb));
 
 	txwi->pktid = pid;
 
@@ -171,6 +173,12 @@ int mt76x02_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
 	if (!wcid || wcid->hw_key_idx == 0xff || wcid->sw_iv)
 		tx_info->info |= MT_TXD_INFO_WIV;
 
+	if (sta) {
+		struct mt76x02_sta *msta = (struct mt76x02_sta *)sta->drv_priv;
+
+		ewma_pktlen_add(&msta->pktlen, tx_info->skb->len);
+	}
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(mt76x02_tx_prepare_skb);
drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c +3 -1
index 203420087ac4..4294ffc0478b 100644
@@ -104,7 +104,9 @@ int mt76x02u_tx_prepare_skb(struct mt76_dev *mdev, void *data,
 	/* encode packet rate for no-skb packet id to fix up status reporting */
 	if (pid == MT_PACKET_ID_NO_SKB)
 		pid = MT_PACKET_ID_HAS_RATE |
-		      (le16_to_cpu(txwi->rate) & MT_RXWI_RATE_INDEX);
+		      (le16_to_cpu(txwi->rate) & MT_PKTID_RATE) |
+		      FIELD_PREP(MT_PKTID_AC,
+				 skb_get_queue_mapping(tx_info->skb));
 
 	txwi->pktid = pid;
 
drivers/net/wireless/mediatek/mt76/mt76x02_util.c +1 -0
index aec73a0295e8..f5695ebdb225 100644
@@ -264,6 +264,7 @@ int mt76x02_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	msta->wcid.hw_key_idx = -1;
 	mt76x02_mac_wcid_setup(dev, idx, mvif->idx, sta->addr);
 	mt76x02_mac_wcid_set_drop(dev, idx, false);
+	ewma_pktlen_init(&msta->pktlen);
 
 	if (vif->type == NL80211_IFTYPE_AP)
 		set_bit(MT_WCID_FLAG_CHECK_PS, &msta->wcid.flags);
drivers/net/wireless/mediatek/mt76/mt76x2/pci.c +1 -0
index 5304b6ecda26..6253ec5fbd72 100644
@@ -23,6 +23,7 @@ mt76pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		.txwi_size = sizeof(struct mt76x02_txwi),
 		.drv_flags = MT_DRV_TX_ALIGNED4_SKBS |
 			     MT_DRV_SW_RX_AIRTIME,
+		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02_tx_prepare_skb,
 		.tx_complete_skb = mt76x02_tx_complete_skb,
drivers/net/wireless/mediatek/mt76/mt76x2/usb.c +1 -0
index 81be59c60155..e6d778456e5e 100644
@@ -26,6 +26,7 @@ static int mt76x2u_probe(struct usb_interface *intf,
 {
 	static const struct mt76_driver_ops drv_ops = {
 		.drv_flags = MT_DRV_SW_RX_AIRTIME,
+		.survey_flags = SURVEY_INFO_TIME_TX,
 		.update_survey = mt76x02_update_channel,
 		.tx_prepare_skb = mt76x02u_tx_prepare_skb,
 		.tx_complete_skb = mt76x02u_tx_complete_skb,
Signature · 1 line
2.17.0
#13 lore raw

Re: [PATCH 10/15] mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

Quoted 2 lines · Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

Would it make sense to move some of this code into mac80211? If we're going to do airtime estimation for queue limiting it may make sense to use this instead of the simplistic estimate I used in my RFC patch?

-Toke

author maintainer
#14 lore raw

Re: [PATCH 10/15] mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 2 lines · Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

Would it make sense to move some of this code into mac80211? If we're going to do airtime estimation for queue limiting it may make sense to use this instead of the simplistic estimate I used in my RFC patch?

Sure. I mainly put it in the driver because I wanted to get it working, tested and merged first without having to wait for a mac80211-next -> wireless-drivers-next merge.

If we move it to mac80211, we can also make ath9k use it. My implementation should be faster than the ath9k duration calculation.

- Felix

#15 lore raw

Re: [PATCH 10/15] mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

Quoted 6 lines · Felix Fietkau
Quoted 5 lines · Toke Høiland-Jørgensen
Quoted 2 lines · Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

Quoted 6 lines
Quoted 3 lines

Would it make sense to move some of this code into mac80211? If we're going to do airtime estimation for queue limiting it may make sense to use this instead of the simplistic estimate I used in my RFC patch?

Sure. I mainly put it in the driver because I wanted to get it working, tested and merged first without having to wait for a mac80211-next -> wireless-drivers-next merge.

Right, OK. So that means another patch set on top of this to move it afterwards? Don't suppose you can be convinced to take care of that as well? :)

Quoted 2 lines

If we move it to mac80211, we can also make ath9k use it. My implementation should be faster than the ath9k duration calculation.

SGTM!

-Toke

author maintainer
#16 lore raw

Re: [PATCH 10/15] mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

Quoted 11 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Felix Fietkau
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 2 lines · Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

Would it make sense to move some of this code into mac80211? If we're going to do airtime estimation for queue limiting it may make sense to use this instead of the simplistic estimate I used in my RFC patch?

Quoted 7 lines
Quoted 3 lines

Sure. I mainly put it in the driver because I wanted to get it working, tested and merged first without having to wait for a mac80211-next -> wireless-drivers-next merge.

Right, OK. So that means another patch set on top of this to move it afterwards? Don't suppose you can be convinced to take care of that as well? :)

I could, but I don't know when I will have time for it, since my plate is pretty full at the moment.

- Felix

#17 lore raw

Re: [PATCH 10/15] mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

Quoted 16 lines · Felix Fietkau
Quoted 15 lines · Toke Høiland-Jørgensen
Quoted 12 lines · Felix Fietkau
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 2 lines · Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

Would it make sense to move some of this code into mac80211? If we're going to do airtime estimation for queue limiting it may make sense to use this instead of the simplistic estimate I used in my RFC patch?

Sure. I mainly put it in the driver because I wanted to get it working, tested and merged first without having to wait for a mac80211-next -> wireless-drivers-next merge.

Quoted 5 lines
Quoted 3 lines

Right, OK. So that means another patch set on top of this to move it afterwards? Don't suppose you can be convinced to take care of that as well? :)

I could, but I don't know when I will have time for it, since my plate is pretty full at the moment.

Heh, I was afraid you'd say that. That makes two of us; guess we'll see who gets around to it first, then :)

Is there anything in your new airtime.c that is mt76-specific apart from the struct mt76_dev and struct mt76_rx_status parameters?

-Toke

author maintainer
#18 lore raw

Re: [PATCH 10/15] mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

Quoted 21 lines · Toke Høiland-Jørgensen
Quoted 19 lines · Felix Fietkau
Quoted 18 lines · Toke Høiland-Jørgensen
Quoted 6 lines · Felix Fietkau
Quoted 5 lines · Toke Høiland-Jørgensen
Quoted 2 lines · Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

Quoted 6 lines
Quoted 3 lines

Would it make sense to move some of this code into mac80211? If we're going to do airtime estimation for queue limiting it may make sense to use this instead of the simplistic estimate I used in my RFC patch?

Sure. I mainly put it in the driver because I wanted to get it working, tested and merged first without having to wait for a mac80211-next -> wireless-drivers-next merge.

Right, OK. So that means another patch set on top of this to move it afterwards? Don't suppose you can be convinced to take care of that as well? :)

Quoted 8 lines
Quoted 2 lines

I could, but I don't know when I will have time for it, since my plate is pretty full at the moment.

Heh, I was afraid you'd say that. That makes two of us; guess we'll see who gets around to it first, then :)

Is there anything in your new airtime.c that is mt76-specific apart from the struct mt76_dev and struct mt76_rx_status parameters?

No, I made it as generic as possible to make it easy to move to mac80211. mt76_rx_status mirrors ieee80211_rx_status very closely, and going from mt76_dev to ieee80211_hw is easy as well.

- Felix

#19 lore raw

Re: [PATCH 10/15] mt76: mt76x02: track approximate tx airtime for airtime fairness and survey

Quoted 25 lines · Felix Fietkau
Quoted 24 lines · Toke Høiland-Jørgensen
Quoted 21 lines · Felix Fietkau
Quoted 11 lines · Toke Høiland-Jørgensen
Quoted 9 lines · Felix Fietkau
Quoted 8 lines · Toke Høiland-Jørgensen
Quoted 2 lines · Felix Fietkau

Estimate by calculating duration for EWMA packet size + estimated A-MPDU length on tx status events

Would it make sense to move some of this code into mac80211? If we're going to do airtime estimation for queue limiting it may make sense to use this instead of the simplistic estimate I used in my RFC patch?

Quoted 7 lines
Quoted 3 lines

Sure. I mainly put it in the driver because I wanted to get it working, tested and merged first without having to wait for a mac80211-next -> wireless-drivers-next merge.

Right, OK. So that means another patch set on top of this to move it afterwards? Don't suppose you can be convinced to take care of that as well? :)

I could, but I don't know when I will have time for it, since my plate is pretty full at the moment.

Quoted 8 lines
Quoted 5 lines

Heh, I was afraid you'd say that. That makes two of us; guess we'll see who gets around to it first, then :)

Is there anything in your new airtime.c that is mt76-specific apart from the struct mt76_dev and struct mt76_rx_status parameters?

No, I made it as generic as possible to make it easy to move to mac80211. mt76_rx_status mirrors ieee80211_rx_status very closely, and going from mt76_dev to ieee80211_hw is easy as well.

Awesome, thanks!

-Toke

author maintainer
#20 lore raw

PATCH 11/15 mt76: mt7615: report tx_time, bss_rx and busy time to mac80211

In reply to Felix Fietkau

From: Lorenzo Bianconi <[email protected]>

Report tx time/rx time and obss time from hw mib counters to fill survey info requested by mac80211

---
 drivers/net/wireless/mediatek/mt76/mac80211.c |  1 +
 drivers/net/wireless/mediatek/mt76/mt76.h     |  1 +
 .../net/wireless/mediatek/mt76/mt7615/init.c  |  2 ++
 .../net/wireless/mediatek/mt76/mt7615/mac.c   | 26 +++++++++++++++++--
 .../net/wireless/mediatek/mt76/mt7615/main.c  |  4 +--
 .../net/wireless/mediatek/mt76/mt7615/pci.c   |  3 +++
 .../net/wireless/mediatek/mt76/mt7615/regs.h  | 12 +++++++++
 7 files changed, 45 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -0
index 5aba8bc0b086..fd64172ca785 100644
@@ -505,6 +505,7 @@ int mt76_get_survey(struct ieee80211_hw *hw, int idx,
 	survey->time = div_u64(state->cc_active, 1000);
 	survey->time_busy = div_u64(state->cc_busy, 1000);
 	survey->time_bss_rx = div_u64(state->cc_bss_rx, 1000);
+	survey->time_rx = div_u64(state->cc_rx, 1000);
 	survey->time_tx = div_u64(state->cc_tx, 1000);
 	spin_unlock_bh(&dev->cc_lock);
 
drivers/net/wireless/mediatek/mt76/mt76.h +1 -0
index 49511bd06fd9..8bcc7f21e83c 100644
@@ -321,6 +321,7 @@ struct mt76_driver_ops {
 struct mt76_channel_state {
 	u64 cc_active;
 	u64 cc_busy;
+	u64 cc_rx;
 	u64 cc_bss_rx;
 	u64 cc_tx;
 };
drivers/net/wireless/mediatek/mt76/mt7615/init.c +2 -0
index ad94a7ce2e10..05a9e1154dd5 100644
@@ -96,6 +96,8 @@ static void mt7615_mac_init(struct mt7615_dev *dev)
 	      FIELD_PREP(MT_DMA_RCFR0_RX_DROPPED_MCAST, 2);
 	mt76_rmw(dev, MT_DMA_BN0RCFR0, mask, set);
 	mt76_rmw(dev, MT_DMA_BN1RCFR0, mask, set);
+
+	mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_EN);
 }
 
 static int mt7615_init_hardware(struct mt7615_dev *dev)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +24 -2
index 271f36f4acb3..9b113037c4f2 100644
@@ -49,6 +49,14 @@ void mt7615_mac_reset_counters(struct mt7615_dev *dev)
 		mt76_rr(dev, MT_TX_AGG_CNT(i));
 
 	memset(dev->mt76.aggr_stats, 0, sizeof(dev->mt76.aggr_stats));
+
+	/* TODO: add DBDC support */
+
+	/* reset airtime counters */
+	mt76_rr(dev, MT_MIB_SDR16(0));
+	mt76_rr(dev, MT_MIB_SDR36(0));
+	mt76_rr(dev, MT_MIB_SDR37(0));
+	mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_CLR);
 }
 
 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
@@ -1263,11 +1271,25 @@ void mt7615_update_channel(struct mt76_dev *mdev)
 {
 	struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
 	struct mt76_channel_state *state;
+	u64 busy_time, tx_time, rx_time, obss_time;
 
 	/* TODO: add DBDC support */
+	busy_time = mt76_get_field(dev, MT_MIB_SDR16(0), MT_MIB_BUSY_MASK);
+	tx_time = mt76_get_field(dev, MT_MIB_SDR36(0),
+				 MT_MIB_SDR36_TXTIME_MASK);
+	rx_time = mt76_get_field(dev, MT_MIB_SDR37(0),
+				 MT_MIB_SDR37_RXTIME_MASK);
+	obss_time = mt76_get_field(dev, MT_WF_RMAC_MIB_TIME5,
+				   MT_MIB_OBSSTIME_MASK);
+
 	state = mdev->chan_state;
-	state->cc_busy += mt76_get_field(dev, MT_MIB_SDR16(0),
-					 MT_MIB_BUSY_MASK);
+	state->cc_busy += busy_time;
+	state->cc_tx += tx_time;
+	state->cc_rx += rx_time + obss_time;
+	state->cc_bss_rx += rx_time;
+
+	/* reset obss airtime */
+	mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_CLR);
 }
 
 void mt7615_mac_work(struct work_struct *work)
drivers/net/wireless/mediatek/mt76/mt7615/main.c +2 -2
index 61df2988ca10..9707fa8b5485 100644
@@ -153,8 +153,8 @@ static int mt7615_set_channel(struct mt7615_dev *dev)
 	ret = mt7615_dfs_init_radar_detector(dev);
 	mt7615_mac_cca_stats_reset(dev);
 	dev->mt76.survey_time = ktime_get_boottime();
-	/* TODO: add DBDC support */
-	mt76_rr(dev, MT_MIB_SDR16(0));
+
+	mt7615_mac_reset_counters(dev);
 
 out:
 	clear_bit(MT76_RESET, &dev->mt76.state);
drivers/net/wireless/mediatek/mt76/mt7615/pci.c +3 -0
index 73744563a573..1eb1eb659c3f 100644
@@ -73,6 +73,9 @@ static int mt7615_pci_probe(struct pci_dev *pdev,
 		/* txwi_size = txd size + txp size */
 		.txwi_size = MT_TXD_SIZE + sizeof(struct mt7615_txp),
 		.drv_flags = MT_DRV_TXWI_NO_FREE,
+		.survey_flags = SURVEY_INFO_TIME_TX |
+				SURVEY_INFO_TIME_RX |
+				SURVEY_INFO_TIME_BSS_RX,
 		.tx_prepare_skb = mt7615_tx_prepare_skb,
 		.tx_complete_skb = mt7615_tx_complete_skb,
 		.rx_skb = mt7615_queue_rx_skb,
drivers/net/wireless/mediatek/mt76/mt7615/regs.h +12 -0
index 643b8bd17850..9a2ff1f3a68c 100644
@@ -198,6 +198,13 @@
 #define MT_WF_RFCR1_DROP_CFEND		BIT(7)
 #define MT_WF_RFCR1_DROP_CFACK		BIT(8)
 
+#define MT_WF_RMAC_MIB_TIME0		MT_WF_RMAC(0x03c4)
+#define MT_WF_RMAC_MIB_RXTIME_CLR	BIT(31)
+#define MT_WF_RMAC_MIB_RXTIME_EN	BIT(30)
+
+#define MT_WF_RMAC_MIB_TIME5		MT_WF_RMAC(0x03d8)
+#define MT_MIB_OBSSTIME_MASK		GENMASK(23, 0)
+
 #define MT_WF_DMA_BASE			0x21800
 #define MT_WF_DMA(ofs)			(MT_WF_DMA_BASE + (ofs))
 
@@ -289,6 +296,11 @@
 #define MT_MIB_SDR16(n)			MT_WF_MIB(0x48 + ((n) << 9))
 #define MT_MIB_BUSY_MASK		GENMASK(23, 0)
 
+#define MT_MIB_SDR36(n)			MT_WF_MIB(0x098 + ((n) << 9))
+#define MT_MIB_SDR36_TXTIME_MASK	GENMASK(23, 0)
+#define MT_MIB_SDR37(n)			MT_WF_MIB(0x09c + ((n) << 9))
+#define MT_MIB_SDR37_RXTIME_MASK	GENMASK(23, 0)
+
 #define MT_TX_AGG_CNT(n)		MT_WF_MIB(0xa8 + ((n) << 2))
 
 #define MT_EFUSE_BASE			0x81070000
Signature · 1 line
2.17.0
author maintainer
#21 lore raw

PATCH 12/15 mt76: mt7615: fix survey channel busy time

In reply to Felix Fietkau

Like on mt7603, MIB status register 16 tracks CCA time, but does not include tx time. Switch to status register 9 to includ NAV and tx time as well.

---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c  | 5 +++--
 drivers/net/wireless/mediatek/mt76/mt7615/regs.h | 7 +++++--
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +3 -2
index 9b113037c4f2..f688390bfd3a 100644
@@ -53,7 +53,7 @@ void mt7615_mac_reset_counters(struct mt7615_dev *dev)
 	/* TODO: add DBDC support */
 
 	/* reset airtime counters */
-	mt76_rr(dev, MT_MIB_SDR16(0));
+	mt76_rr(dev, MT_MIB_SDR9(0));
 	mt76_rr(dev, MT_MIB_SDR36(0));
 	mt76_rr(dev, MT_MIB_SDR37(0));
 	mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_CLR);
@@ -1274,7 +1274,8 @@ void mt7615_update_channel(struct mt76_dev *mdev)
 	u64 busy_time, tx_time, rx_time, obss_time;
 
 	/* TODO: add DBDC support */
-	busy_time = mt76_get_field(dev, MT_MIB_SDR16(0), MT_MIB_BUSY_MASK);
+	busy_time = mt76_get_field(dev, MT_MIB_SDR9(0),
+				   MT_MIB_SDR9_BUSY_MASK);
 	tx_time = mt76_get_field(dev, MT_MIB_SDR36(0),
 				 MT_MIB_SDR36_TXTIME_MASK);
 	rx_time = mt76_get_field(dev, MT_MIB_SDR37(0),
drivers/net/wireless/mediatek/mt76/mt7615/regs.h +5 -2
index 9a2ff1f3a68c..226b9ada89f6 100644
@@ -293,8 +293,11 @@
 #define MT_MIB_RTS_RETRIES_COUNT_MASK	GENMASK(31, 16)
 #define MT_MIB_RTS_COUNT_MASK		GENMASK(15, 0)
 
-#define MT_MIB_SDR16(n)			MT_WF_MIB(0x48 + ((n) << 9))
-#define MT_MIB_BUSY_MASK		GENMASK(23, 0)
+#define MT_MIB_SDR9(n)			MT_WF_MIB(0x02c + ((n) << 9))
+#define MT_MIB_SDR9_BUSY_MASK		GENMASK(23, 0)
+
+#define MT_MIB_SDR16(n)			MT_WF_MIB(0x048 + ((n) << 9))
+#define MT_MIB_SDR16_BUSY_MASK		GENMASK(23, 0)
 
 #define MT_MIB_SDR36(n)			MT_WF_MIB(0x098 + ((n) << 9))
 #define MT_MIB_SDR36_TXTIME_MASK	GENMASK(23, 0)
Signature · 1 line
2.17.0
author maintainer
#22 lore raw

PATCH 13/15 mt76: mt7615: introduce mt7615_mac_wtbl_update routine

In reply to Felix Fietkau

From: Lorenzo Bianconi <[email protected]>

Introduce mt7615_mac_wtbl_update utility routine in order to update WTBL update register

---
 drivers/net/wireless/mediatek/mt76/mt7615/mac.c  | 16 +++++++++++-----
 .../net/wireless/mediatek/mt76/mt7615/mt7615.h   |  1 +
 2 files changed, 12 insertions(+), 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +11 -5
index f688390bfd3a..2e36b3289fa6 100644
@@ -492,6 +492,15 @@ static u32 mt7615_mac_wtbl_addr(int wcid)
 	return MT_WTBL_BASE + wcid * MT_WTBL_ENTRY_SIZE;
 }
 
+bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask)
+{
+	mt76_rmw(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_WLAN_IDX,
+		 FIELD_PREP(MT_WTBL_UPDATE_WLAN_IDX, idx) | mask);
+
+	return mt76_poll(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_BUSY,
+			 0, 5000);
+}
+
 void mt7615_mac_set_rates(struct mt7615_dev *dev, struct mt7615_sta *sta,
 			  struct ieee80211_tx_rate *probe_rate,
 			  struct ieee80211_tx_rate *rates)
@@ -724,11 +733,8 @@ mt7615_mac_wtbl_update_pk(struct mt7615_dev *dev, struct mt76_wcid *wcid,
 	mt76_wr(dev, MT_WTBL_RICR0, w0);
 	mt76_wr(dev, MT_WTBL_RICR1, w1);
 
-	mt76_wr(dev, MT_WTBL_UPDATE,
-		FIELD_PREP(MT_WTBL_UPDATE_WLAN_IDX, wcid->idx) |
-		MT_WTBL_UPDATE_RXINFO_UPDATE);
-
-	if (!mt76_poll(dev, MT_WTBL_UPDATE, MT_WTBL_UPDATE_BUSY, 0, 5000))
+	if (!mt7615_mac_wtbl_update(dev, wcid->idx,
+				    MT_WTBL_UPDATE_RXINFO_UPDATE))
 		return -ETIMEDOUT;
 
 	return 0;
drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +1 -0
index fe084555754b..070afba63e43 100644
@@ -231,6 +231,7 @@ static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
 }
 
 void mt7615_update_channel(struct mt76_dev *mdev);
+bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
 void mt7615_mac_reset_counters(struct mt7615_dev *dev);
 void mt7615_mac_cca_stats_reset(struct mt7615_dev *dev);
 void mt7615_mac_set_scs(struct mt7615_dev *dev, bool enable);
Signature · 1 line
2.17.0
author maintainer
#23 lore raw

PATCH 14/15 mt76: mt7615: track tx/rx airtime for airtime fairness

In reply to Felix Fietkau

From: Lorenzo Bianconi <[email protected]>

Poll per-station hardware counters available in WTBL after tx/rx status events in order to report tx/rx airtime to mac80211 layer

---
 .../net/wireless/mediatek/mt76/mt7615/dma.c   |  2 +
 .../net/wireless/mediatek/mt76/mt7615/init.c  | 12 ++-
 .../net/wireless/mediatek/mt76/mt7615/mac.c   | 92 +++++++++++++++++++
 .../net/wireless/mediatek/mt76/mt7615/main.c  | 16 ++++
 .../wireless/mediatek/mt76/mt7615/mt7615.h    |  7 ++
 .../net/wireless/mediatek/mt76/mt7615/regs.h  |  3 +
 6 files changed, 130 insertions(+), 2 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/dma.c +2 -0
index fe532cecbbdd..285d4f1d6178 100644
@@ -110,6 +110,8 @@ static int mt7615_poll_tx(struct napi_struct *napi, int budget)
 	for (i = 0; i < ARRAY_SIZE(queue_map); i++)
 		mt76_queue_tx_cleanup(dev, queue_map[i], false);
 
+	mt7615_mac_sta_poll(dev);
+
 	tasklet_schedule(&dev->mt76.tx_tasklet);
 
 	return 0;
drivers/net/wireless/mediatek/mt76/mt7615/init.c +10 -2
index 05a9e1154dd5..1e7723aceee2 100644
@@ -21,6 +21,7 @@ static void mt7615_phy_init(struct mt7615_dev *dev)
 static void mt7615_mac_init(struct mt7615_dev *dev)
 {
 	u32 val, mask, set;
+	int i;
 
 	/* enable band 0/1 clk */
 	mt76_set(dev, MT_CFG_CCR,
@@ -97,7 +98,12 @@ static void mt7615_mac_init(struct mt7615_dev *dev)
 	mt76_rmw(dev, MT_DMA_BN0RCFR0, mask, set);
 	mt76_rmw(dev, MT_DMA_BN1RCFR0, mask, set);
 
+	for (i = 0; i < MT7615_WTBL_SIZE; i++)
+		mt7615_mac_wtbl_update(dev, i,
+				       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+
 	mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_EN);
+	mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0, MT_WF_RMAC_MIB_RXTIME_EN);
 }
 
 static int mt7615_init_hardware(struct mt7615_dev *dev)
@@ -262,12 +268,14 @@ int mt7615_register_device(struct mt7615_dev *dev)
 	struct wiphy *wiphy = hw->wiphy;
 	int ret;
 
+	INIT_DELAYED_WORK(&dev->mt76.mac_work, mt7615_mac_work);
+	INIT_LIST_HEAD(&dev->sta_poll_list);
+	spin_lock_init(&dev->sta_poll_lock);
+
 	ret = mt7615_init_hardware(dev);
 	if (ret)
 		return ret;
 
-	INIT_DELAYED_WORK(&dev->mt76.mac_work, mt7615_mac_work);
-
 	hw->queues = 4;
 	hw->max_rates = 3;
 	hw->max_report_rates = 7;
drivers/net/wireless/mediatek/mt76/mt7615/mac.c +92 -0

116 lines not on this page · raw message

drivers/net/wireless/mediatek/mt76/mt7615/main.c +16 -0
index 9707fa8b5485..942076b6d1ad 100644
@@ -99,8 +99,12 @@ static int mt7615_add_interface(struct ieee80211_hw *hw,
 	dev->vif_mask |= BIT(mvif->idx);
 	dev->omac_mask |= BIT(mvif->omac_idx);
 	idx = MT7615_WTBL_RESERVED - mvif->idx;
+
+	INIT_LIST_HEAD(&mvif->sta.poll_list);
 	mvif->sta.wcid.idx = idx;
 	mvif->sta.wcid.hw_key_idx = -1;
+	mt7615_mac_wtbl_update(dev, idx,
+			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 
 	rcu_assign_pointer(dev->mt76.wcid[idx], &mvif->sta.wcid);
 	mtxq = (struct mt76_txq *)vif->txq->drv_priv;
@@ -360,9 +364,12 @@ int mt7615_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 	if (idx < 0)
 		return -ENOSPC;
 
+	INIT_LIST_HEAD(&msta->poll_list);
 	msta->vif = mvif;
 	msta->wcid.sta = 1;
 	msta->wcid.idx = idx;
+	mt7615_mac_wtbl_update(dev, idx,
+			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
 
 	mt7615_mcu_add_wtbl(dev, vif, sta);
 	mt7615_mcu_set_sta_rec(dev, vif, sta, 1);
@@ -383,9 +390,18 @@ void mt7615_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
 		       struct ieee80211_sta *sta)
 {
 	struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
+	struct mt7615_sta *msta = (struct mt7615_sta *)sta->drv_priv;
 
 	mt7615_mcu_set_sta_rec(dev, vif, sta, 0);
 	mt7615_mcu_del_wtbl(dev, sta);
+
+	mt7615_mac_wtbl_update(dev, msta->wcid.idx,
+			       MT_WTBL_UPDATE_ADM_COUNT_CLEAR);
+
+	spin_lock_bh(&dev->sta_poll_lock);
+	if (!list_empty(&msta->poll_list))
+		list_del_init(&msta->poll_list);
+	spin_unlock_bh(&dev->sta_poll_lock);
 }
 
 static void mt7615_sta_rate_tbl_update(struct ieee80211_hw *hw,
drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h +7 -0
index 070afba63e43..d537f68c5531 100644
@@ -56,6 +56,9 @@ struct mt7615_sta {
 
 	struct mt7615_vif *vif;
 
+	struct list_head poll_list;
+	u32 airtime_ac[8];
+
 	struct ieee80211_tx_rate rates[4];
 
 	struct mt7615_rate_set rateset[2];
@@ -83,6 +86,9 @@ struct mt7615_dev {
 
 	__le32 rx_ampdu_ts;
 
+	struct list_head sta_poll_list;
+	spinlock_t sta_poll_lock;
+
 	struct {
 		u8 n_pulses;
 		u32 period;
@@ -235,6 +241,7 @@ bool mt7615_mac_wtbl_update(struct mt7615_dev *dev, int idx, u32 mask);
 void mt7615_mac_reset_counters(struct mt7615_dev *dev);
 void mt7615_mac_cca_stats_reset(struct mt7615_dev *dev);
 void mt7615_mac_set_scs(struct mt7615_dev *dev, bool enable);
+void mt7615_mac_sta_poll(struct mt7615_dev *dev);
 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
 			  struct sk_buff *skb, struct mt76_wcid *wcid,
 			  struct ieee80211_sta *sta, int pid,
drivers/net/wireless/mediatek/mt76/mt7615/regs.h +3 -0
index 226b9ada89f6..99bd5939d33f 100644
@@ -202,6 +202,8 @@
 #define MT_WF_RMAC_MIB_RXTIME_CLR	BIT(31)
 #define MT_WF_RMAC_MIB_RXTIME_EN	BIT(30)
 
+#define MT_WF_RMAC_MIB_AIRTIME0		MT_WF_RMAC(0x0380)
+
 #define MT_WF_RMAC_MIB_TIME5		MT_WF_RMAC(0x03d8)
 #define MT_MIB_OBSSTIME_MASK		GENMASK(23, 0)
 
@@ -236,6 +238,7 @@
 #define MT_WTBL_UPDATE			MT_WTBL_OFF(0x030)
 #define MT_WTBL_UPDATE_WLAN_IDX		GENMASK(7, 0)
 #define MT_WTBL_UPDATE_RXINFO_UPDATE	BIT(11)
+#define MT_WTBL_UPDATE_ADM_COUNT_CLEAR	BIT(12)
 #define MT_WTBL_UPDATE_RATE_UPDATE	BIT(13)
 #define MT_WTBL_UPDATE_TX_COUNT_CLEAR	BIT(14)
 #define MT_WTBL_UPDATE_BUSY		BIT(31)
Signature · 1 line
2.17.0
author maintainer
#24 lore raw

PATCH 15/15 mt76: enable airtime fairness

In reply to Felix Fietkau

It is supported by all hardware drivers now

---
 drivers/net/wireless/mediatek/mt76/mac80211.c | 1 +
 1 file changed, 1 insertion(+)
drivers/net/wireless/mediatek/mt76/mac80211.c +1 -0
index fd64172ca785..9a59a1b54c97 100644
@@ -307,6 +307,7 @@ int mt76_register_device(struct mt76_dev *dev, bool vht,
 	wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
 
 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
+	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
 
 	wiphy->available_antennas_tx = dev->antenna_mask;
 	wiphy->available_antennas_rx = dev->antenna_mask;
Signature · 1 line
2.17.0