ath9k: add debug parameters for spectral scan
authorSimon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>
Wed, 23 Jan 2013 16:38:04 +0000 (17:38 +0100)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 30 Jan 2013 20:06:40 +0000 (15:06 -0500)
Export the various parameters to userspace.

Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath9k/ath9k.h
drivers/net/wireless/ath/ath9k/debug.c
drivers/net/wireless/ath/ath9k/init.c
drivers/net/wireless/ath/ath9k/main.c

index b2d6c18d1678961a9efe838f43ed1bffb3216a23..342edc54366594ef0cb5b82ca641af11fcb9b896 100644 (file)
@@ -754,6 +754,7 @@ struct ath_softc {
        /* relay(fs) channel for spectral scan */
        struct rchan *rfs_chan_spec_scan;
        enum spectral_mode spectral_mode;
+       struct ath_spec_scan spec_config;
        int scanning;
 
 #ifdef CONFIG_PM_SLEEP
index 6c5d313ebcb7eda614d350a718faa518625f9adb..012446d27bc0f3a550e033e55e6c9b6e16c17b31 100644 (file)
@@ -1035,6 +1035,182 @@ static const struct file_operations fops_spec_scan_ctl = {
        .llseek = default_llseek,
 };
 
+static ssize_t read_file_spectral_short_repeat(struct file *file,
+                                              char __user *user_buf,
+                                              size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       char buf[32];
+       unsigned int len;
+
+       len = sprintf(buf, "%d\n", sc->spec_config.short_repeat);
+       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t write_file_spectral_short_repeat(struct file *file,
+                                               const char __user *user_buf,
+                                               size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       unsigned long val;
+       char buf[32];
+       ssize_t len;
+
+       len = min(count, sizeof(buf) - 1);
+       if (copy_from_user(buf, user_buf, len))
+               return -EFAULT;
+
+       buf[len] = '\0';
+       if (kstrtoul(buf, 0, &val))
+               return -EINVAL;
+
+       if (val < 0 || val > 1)
+               return -EINVAL;
+
+       sc->spec_config.short_repeat = val;
+       return count;
+}
+
+static const struct file_operations fops_spectral_short_repeat = {
+       .read = read_file_spectral_short_repeat,
+       .write = write_file_spectral_short_repeat,
+       .open = simple_open,
+       .owner = THIS_MODULE,
+       .llseek = default_llseek,
+};
+
+static ssize_t read_file_spectral_count(struct file *file,
+                                       char __user *user_buf,
+                                       size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       char buf[32];
+       unsigned int len;
+
+       len = sprintf(buf, "%d\n", sc->spec_config.count);
+       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t write_file_spectral_count(struct file *file,
+                                        const char __user *user_buf,
+                                        size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       unsigned long val;
+       char buf[32];
+       ssize_t len;
+
+       len = min(count, sizeof(buf) - 1);
+       if (copy_from_user(buf, user_buf, len))
+               return -EFAULT;
+
+       buf[len] = '\0';
+       if (kstrtoul(buf, 0, &val))
+               return -EINVAL;
+
+       if (val < 0 || val > 255)
+               return -EINVAL;
+
+       sc->spec_config.count = val;
+       return count;
+}
+
+static const struct file_operations fops_spectral_count = {
+       .read = read_file_spectral_count,
+       .write = write_file_spectral_count,
+       .open = simple_open,
+       .owner = THIS_MODULE,
+       .llseek = default_llseek,
+};
+
+static ssize_t read_file_spectral_period(struct file *file,
+                                        char __user *user_buf,
+                                        size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       char buf[32];
+       unsigned int len;
+
+       len = sprintf(buf, "%d\n", sc->spec_config.period);
+       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t write_file_spectral_period(struct file *file,
+                                         const char __user *user_buf,
+                                         size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       unsigned long val;
+       char buf[32];
+       ssize_t len;
+
+       len = min(count, sizeof(buf) - 1);
+       if (copy_from_user(buf, user_buf, len))
+               return -EFAULT;
+
+       buf[len] = '\0';
+       if (kstrtoul(buf, 0, &val))
+               return -EINVAL;
+
+       if (val < 0 || val > 255)
+               return -EINVAL;
+
+       sc->spec_config.period = val;
+       return count;
+}
+
+static const struct file_operations fops_spectral_period = {
+       .read = read_file_spectral_period,
+       .write = write_file_spectral_period,
+       .open = simple_open,
+       .owner = THIS_MODULE,
+       .llseek = default_llseek,
+};
+
+static ssize_t read_file_spectral_fft_period(struct file *file,
+                                            char __user *user_buf,
+                                            size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       char buf[32];
+       unsigned int len;
+
+       len = sprintf(buf, "%d\n", sc->spec_config.fft_period);
+       return simple_read_from_buffer(user_buf, count, ppos, buf, len);
+}
+
+static ssize_t write_file_spectral_fft_period(struct file *file,
+                                             const char __user *user_buf,
+                                             size_t count, loff_t *ppos)
+{
+       struct ath_softc *sc = file->private_data;
+       unsigned long val;
+       char buf[32];
+       ssize_t len;
+
+       len = min(count, sizeof(buf) - 1);
+       if (copy_from_user(buf, user_buf, len))
+               return -EFAULT;
+
+       buf[len] = '\0';
+       if (kstrtoul(buf, 0, &val))
+               return -EINVAL;
+
+       if (val < 0 || val > 15)
+               return -EINVAL;
+
+       sc->spec_config.fft_period = val;
+       return count;
+}
+
+static const struct file_operations fops_spectral_fft_period = {
+       .read = read_file_spectral_fft_period,
+       .write = write_file_spectral_fft_period,
+       .open = simple_open,
+       .owner = THIS_MODULE,
+       .llseek = default_llseek,
+};
+
 static struct dentry *create_buf_file_handler(const char *filename,
                                              struct dentry *parent,
                                              umode_t mode,
@@ -1893,6 +2069,16 @@ int ath9k_init_debug(struct ath_hw *ah)
        debugfs_create_file("spectral_scan_ctl", S_IRUSR | S_IWUSR,
                            sc->debug.debugfs_phy, sc,
                            &fops_spec_scan_ctl);
+       debugfs_create_file("spectral_short_repeat", S_IRUSR | S_IWUSR,
+                           sc->debug.debugfs_phy, sc,
+                           &fops_spectral_short_repeat);
+       debugfs_create_file("spectral_count", S_IRUSR | S_IWUSR,
+                           sc->debug.debugfs_phy, sc, &fops_spectral_count);
+       debugfs_create_file("spectral_period", S_IRUSR | S_IWUSR,
+                           sc->debug.debugfs_phy, sc, &fops_spectral_period);
+       debugfs_create_file("spectral_fft_period", S_IRUSR | S_IWUSR,
+                           sc->debug.debugfs_phy, sc,
+                           &fops_spectral_fft_period);
 
 #ifdef CONFIG_ATH9K_MAC_DEBUG
        debugfs_create_file("samples", S_IRUSR, sc->debug.debugfs_phy, sc,
index 4b1abc7da98c559fcda19845caa036c246d5b444..c7d116c2c615d6166d91f147b0120010be4b1c1b 100644 (file)
@@ -497,6 +497,13 @@ static void ath9k_init_misc(struct ath_softc *sc)
 
        if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
                sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
+
+       sc->spec_config.enabled = 0;
+       sc->spec_config.short_repeat = true;
+       sc->spec_config.count = 8;
+       sc->spec_config.endless = false;
+       sc->spec_config.period = 0xFF;
+       sc->spec_config.fft_period = 0xF;
 }
 
 static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
index 4b72b660f1800d25d9416668649260996afc411a..5432f1247e2e437fdcc10b56adc40e28a82b101d 100644 (file)
@@ -1099,45 +1099,34 @@ int ath9k_spectral_scan_config(struct ieee80211_hw *hw,
        struct ath_softc *sc = hw->priv;
        struct ath_hw *ah = sc->sc_ah;
        struct ath_common *common = ath9k_hw_common(ah);
-       struct ath_spec_scan param;
 
        if (!ath9k_hw_ops(ah)->spectral_scan_trigger) {
                ath_err(common, "spectrum analyzer not implemented on this hardware\n");
                return -1;
        }
 
-       /* NOTE: this will generate a few samples ...
-        *
-        * TODO: review default parameters, and/or define an interface to set
-        * them.
-        */
-       param.enabled = 1;
-       param.short_repeat = true;
-       param.count = 8;
-       param.endless = false;
-       param.period = 0xFF;
-       param.fft_period = 0xF;
-
        switch (spectral_mode) {
        case SPECTRAL_DISABLED:
-               param.enabled = 0;
+               sc->spec_config.enabled = 0;
                break;
        case SPECTRAL_BACKGROUND:
                /* send endless samples.
                 * TODO: is this really useful for "background"?
                 */
-               param.endless = 1;
+               sc->spec_config.endless = 1;
+               sc->spec_config.enabled = 1;
                break;
        case SPECTRAL_CHANSCAN:
-               break;
        case SPECTRAL_MANUAL:
+               sc->spec_config.endless = 0;
+               sc->spec_config.enabled = 1;
                break;
        default:
                return -1;
        }
 
        ath9k_ps_wakeup(sc);
-       ath9k_hw_ops(ah)->spectral_scan_config(ah, &param);
+       ath9k_hw_ops(ah)->spectral_scan_config(ah, &sc->spec_config);
        ath9k_ps_restore(sc);
 
        sc->spectral_mode = spectral_mode;