linux/drivers/net/wireless/mediatek/mt76/mt76x02_debugfs.c
<<
>>
Prefs
   1// SPDX-License-Identifier: ISC
   2/*
   3 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
   4 */
   5
   6#include <linux/debugfs.h>
   7#include "mt76x02.h"
   8
   9static int
  10mt76x02_ampdu_stat_read(struct seq_file *file, void *data)
  11{
  12        struct mt76x02_dev *dev = file->private;
  13        int i, j;
  14
  15        for (i = 0; i < 4; i++) {
  16                seq_puts(file, "Length: ");
  17                for (j = 0; j < 8; j++)
  18                        seq_printf(file, "%8d | ", i * 8 + j + 1);
  19                seq_puts(file, "\n");
  20                seq_puts(file, "Count:  ");
  21                for (j = 0; j < 8; j++)
  22                        seq_printf(file, "%8d | ", dev->aggr_stats[i * 8 + j]);
  23                seq_puts(file, "\n");
  24                seq_puts(file, "--------");
  25                for (j = 0; j < 8; j++)
  26                        seq_puts(file, "-----------");
  27                seq_puts(file, "\n");
  28        }
  29
  30        return 0;
  31}
  32
  33static int
  34mt76x02_ampdu_stat_open(struct inode *inode, struct file *f)
  35{
  36        return single_open(f, mt76x02_ampdu_stat_read, inode->i_private);
  37}
  38
  39static int read_txpower(struct seq_file *file, void *data)
  40{
  41        struct mt76x02_dev *dev = dev_get_drvdata(file->private);
  42
  43        seq_printf(file, "Target power: %d\n", dev->target_power);
  44
  45        mt76_seq_puts_array(file, "Delta", dev->target_power_delta,
  46                            ARRAY_SIZE(dev->target_power_delta));
  47        return 0;
  48}
  49
  50static const struct file_operations fops_ampdu_stat = {
  51        .open = mt76x02_ampdu_stat_open,
  52        .read = seq_read,
  53        .llseek = seq_lseek,
  54        .release = single_release,
  55};
  56
  57static int
  58mt76x02_dfs_stat_read(struct seq_file *file, void *data)
  59{
  60        struct mt76x02_dev *dev = file->private;
  61        struct mt76x02_dfs_pattern_detector *dfs_pd = &dev->dfs_pd;
  62        int i;
  63
  64        seq_printf(file, "allocated sequences:\t%d\n",
  65                   dfs_pd->seq_stats.seq_pool_len);
  66        seq_printf(file, "used sequences:\t\t%d\n",
  67                   dfs_pd->seq_stats.seq_len);
  68        seq_puts(file, "\n");
  69
  70        for (i = 0; i < MT_DFS_NUM_ENGINES; i++) {
  71                seq_printf(file, "engine: %d\n", i);
  72                seq_printf(file, "  hw pattern detected:\t%d\n",
  73                           dfs_pd->stats[i].hw_pattern);
  74                seq_printf(file, "  hw pulse discarded:\t%d\n",
  75                           dfs_pd->stats[i].hw_pulse_discarded);
  76                seq_printf(file, "  sw pattern detected:\t%d\n",
  77                           dfs_pd->stats[i].sw_pattern);
  78        }
  79
  80        return 0;
  81}
  82
  83static int
  84mt76x02_dfs_stat_open(struct inode *inode, struct file *f)
  85{
  86        return single_open(f, mt76x02_dfs_stat_read, inode->i_private);
  87}
  88
  89static const struct file_operations fops_dfs_stat = {
  90        .open = mt76x02_dfs_stat_open,
  91        .read = seq_read,
  92        .llseek = seq_lseek,
  93        .release = single_release,
  94};
  95
  96static int read_agc(struct seq_file *file, void *data)
  97{
  98        struct mt76x02_dev *dev = dev_get_drvdata(file->private);
  99
 100        seq_printf(file, "avg_rssi: %d\n", dev->cal.avg_rssi_all);
 101        seq_printf(file, "low_gain: %d\n", dev->cal.low_gain);
 102        seq_printf(file, "false_cca: %d\n", dev->cal.false_cca);
 103        seq_printf(file, "agc_gain_adjust: %d\n", dev->cal.agc_gain_adjust);
 104
 105        return 0;
 106}
 107
 108static int
 109mt76_edcca_set(void *data, u64 val)
 110{
 111        struct mt76x02_dev *dev = data;
 112        enum nl80211_dfs_regions region = dev->mt76.region;
 113
 114        mutex_lock(&dev->mt76.mutex);
 115
 116        dev->ed_monitor_enabled = !!val;
 117        dev->ed_monitor = dev->ed_monitor_enabled &&
 118                          region == NL80211_DFS_ETSI;
 119        mt76x02_edcca_init(dev);
 120
 121        mutex_unlock(&dev->mt76.mutex);
 122
 123        return 0;
 124}
 125
 126static int
 127mt76_edcca_get(void *data, u64 *val)
 128{
 129        struct mt76x02_dev *dev = data;
 130
 131        *val = dev->ed_monitor_enabled;
 132        return 0;
 133}
 134
 135DEFINE_DEBUGFS_ATTRIBUTE(fops_edcca, mt76_edcca_get, mt76_edcca_set,
 136                         "%lld\n");
 137
 138void mt76x02_init_debugfs(struct mt76x02_dev *dev)
 139{
 140        struct dentry *dir;
 141
 142        dir = mt76_register_debugfs(&dev->mt76);
 143        if (!dir)
 144                return;
 145
 146        debugfs_create_u8("temperature", 0400, dir, &dev->cal.temp);
 147        debugfs_create_bool("tpc", 0600, dir, &dev->enable_tpc);
 148
 149        debugfs_create_file("edcca", 0600, dir, dev, &fops_edcca);
 150        debugfs_create_file("ampdu_stat", 0400, dir, dev, &fops_ampdu_stat);
 151        debugfs_create_file("dfs_stats", 0400, dir, dev, &fops_dfs_stat);
 152        debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir,
 153                                    read_txpower);
 154
 155        debugfs_create_devm_seqfile(dev->mt76.dev, "agc", dir, read_agc);
 156
 157        debugfs_create_u32("tx_hang_reset", 0400, dir, &dev->tx_hang_reset);
 158}
 159EXPORT_SYMBOL_GPL(mt76x02_init_debugfs);
 160