mt76: mt7615: collect aggregation stats
authorLorenzo Bianconi <lorenzo@kernel.org>
Fri, 13 Sep 2019 07:05:53 +0000 (09:05 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 20 Nov 2019 12:23:48 +0000 (13:23 +0100)
Introduce ampdu_stat entry in mt7615 debugfs in order to dump 802.11
aggr cumulative statistics

Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c
drivers/net/wireless/mediatek/mt76/mt7615/mac.c
drivers/net/wireless/mediatek/mt76/mt7615/main.c
drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h
drivers/net/wireless/mediatek/mt76/mt7615/regs.h

index 1dc68d4aee57fd9b36f767bcdba4f6c6626d8409..f6b75f832e6a13e594a68840e525af71e9ee1290 100644 (file)
@@ -36,6 +36,44 @@ mt7615_scs_get(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(fops_scs, mt7615_scs_get,
                         mt7615_scs_set, "%lld\n");
 
+static int
+mt7615_ampdu_stat_read(struct seq_file *file, void *data)
+{
+       struct mt7615_dev *dev = file->private;
+       int bound[7], i, range;
+
+       range = mt76_rr(dev, MT_AGG_ASRCR0);
+       for (i = 0; i < 4; i++)
+               bound[i] = MT_AGG_ASRCR_RANGE(range, i) + 1;
+       range = mt76_rr(dev, MT_AGG_ASRCR1);
+       for (i = 0; i < 3; i++)
+               bound[i + 4] = MT_AGG_ASRCR_RANGE(range, i) + 1;
+
+       seq_printf(file, "Length: %8d | ", bound[0]);
+       for (i = 0; i < ARRAY_SIZE(bound) - 1; i++)
+               seq_printf(file, "%3d -%3d | ",
+                          bound[i], bound[i + 1]);
+       seq_puts(file, "\nCount:  ");
+       for (i = 0; i < ARRAY_SIZE(bound); i++)
+               seq_printf(file, "%8d | ", dev->mt76.aggr_stats[i]);
+       seq_puts(file, "\n");
+
+       return 0;
+}
+
+static int
+mt7615_ampdu_stat_open(struct inode *inode, struct file *f)
+{
+       return single_open(f, mt7615_ampdu_stat_read, inode->i_private);
+}
+
+static const struct file_operations fops_ampdu_stat = {
+       .open = mt7615_ampdu_stat_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = single_release,
+};
+
 static int
 mt7615_radio_read(struct seq_file *s, void *data)
 {
@@ -130,6 +168,7 @@ int mt7615_init_debugfs(struct mt7615_dev *dev)
                                    mt7615_queues_read);
        debugfs_create_devm_seqfile(dev->mt76.dev, "acq", dir,
                                    mt7615_queues_acq);
+       debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat);
        debugfs_create_file("scs", 0600, dir, dev, &fops_scs);
        debugfs_create_devm_seqfile(dev->mt76.dev, "radio", dir,
                                    mt7615_radio_read);
index e07ce2c100133b1e4a659c59d5bd410409b4b657..237d15521e18fec82f2b2e1682cd0563ed92e205 100644 (file)
@@ -41,6 +41,16 @@ static struct mt76_wcid *mt7615_rx_get_wcid(struct mt7615_dev *dev,
        return &sta->vif->sta.wcid;
 }
 
+void mt7615_mac_reset_counters(struct mt7615_dev *dev)
+{
+       int i;
+
+       for (i = 0; i < 4; i++)
+               mt76_rr(dev, MT_TX_AGG_CNT(i));
+
+       memset(dev->mt76.aggr_stats, 0, sizeof(dev->mt76.aggr_stats));
+}
+
 int mt7615_mac_fill_rx(struct mt7615_dev *dev, struct sk_buff *skb)
 {
        struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb;
@@ -1261,6 +1271,7 @@ void mt7615_update_channel(struct mt76_dev *mdev)
 void mt7615_mac_work(struct work_struct *work)
 {
        struct mt7615_dev *dev;
+       int i, idx;
 
        dev = (struct mt7615_dev *)container_of(work, struct mt76_dev,
                                                mac_work.work);
@@ -1271,6 +1282,13 @@ void mt7615_mac_work(struct work_struct *work)
                mt7615_mac_scs_check(dev);
                dev->mac_work_count = 0;
        }
+
+       for (i = 0, idx = 0; i < 4; i++) {
+               u32 val = mt76_rr(dev, MT_TX_AGG_CNT(i));
+
+               dev->mt76.aggr_stats[idx++] += val & 0xffff;
+               dev->mt76.aggr_stats[idx++] += val >> 16;
+       }
        mutex_unlock(&dev->mt76.mutex);
 
        mt76_tx_status_check(&dev->mt76, NULL, false);
index 7252423a89fabd932fd30ea6713907b89862ecdb..6949cda9df0b06913a43b1bd5c56512422841f45 100644 (file)
@@ -16,6 +16,8 @@ static int mt7615_start(struct ieee80211_hw *hw)
 {
        struct mt7615_dev *dev = hw->priv;
 
+       mt7615_mac_reset_counters(dev);
+
        dev->mt76.survey_time = ktime_get_boottime();
        set_bit(MT76_STATE_RUNNING, &dev->mt76.state);
        ieee80211_queue_delayed_work(mt76_hw(dev), &dev->mt76.mac_work,
index 7963e302d705d3ded5ac8f62292b723c56ad2f93..efb8be29c3926e3e082ed5cc0444654a41bfade3 100644 (file)
@@ -229,6 +229,7 @@ static inline void mt7615_irq_disable(struct mt7615_dev *dev, u32 mask)
 }
 
 void mt7615_update_channel(struct mt76_dev *mdev);
+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);
 int mt7615_mac_write_txwi(struct mt7615_dev *dev, __le32 *txwi,
index 43676736a807c7ac3cdc3b292fc97353db0902a7..643b8bd178508226bab3c97ec04135981cff609c 100644 (file)
                                        MT_AGG_ARxCR_LIMIT_SHIFT(_n), \
                                        MT_AGG_ARxCR_LIMIT_SHIFT(_n))
 
+#define MT_AGG_ASRCR0                  MT_WF_AGG(0x060)
+#define MT_AGG_ASRCR1                  MT_WF_AGG(0x064)
+#define MT_AGG_ASRCR_RANGE(val, n)     (((val) >> ((n) << 3)) & GENMASK(5, 0))
+
 #define MT_AGG_ACR0                    MT_WF_AGG(0x070)
 #define MT_AGG_ACR1                    MT_WF_AGG(0x170)
 #define MT_AGG_ACR_NO_BA_RULE          BIT(0)
 #define MT_MIB_SDR16(n)                        MT_WF_MIB(0x48 + ((n) << 9))
 #define MT_MIB_BUSY_MASK               GENMASK(23, 0)
 
+#define MT_TX_AGG_CNT(n)               MT_WF_MIB(0xa8 + ((n) << 2))
+
 #define MT_EFUSE_BASE                  0x81070000
 #define MT_EFUSE_BASE_CTRL             0x000
 #define MT_EFUSE_BASE_CTRL_EMPTY       BIT(30)