mt76: mt7615: add radar pattern test knob to debugfs
authorLorenzo Bianconi <lorenzo@kernel.org>
Sat, 29 Jun 2019 10:36:11 +0000 (12:36 +0200)
committerFelix Fietkau <nbd@nbd.name>
Thu, 5 Sep 2019 15:42:28 +0000 (17:42 +0200)
Introduce mt7615_mcu_rdd_send_pattern routine to trigger a radar pattern
detection. Moreover move debugfs related routines in a dedicated source
file.

Suggested-by: Ryder Lee <ryder.lee@mediatek.com>
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
drivers/net/wireless/mediatek/mt76/mt7615/Makefile
drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c [new file with mode: 0644]
drivers/net/wireless/mediatek/mt76/mt7615/init.c
drivers/net/wireless/mediatek/mt76/mt7615/mcu.c
drivers/net/wireless/mediatek/mt76/mt7615/mcu.h
drivers/net/wireless/mediatek/mt76/mt7615/mt7615.h

index 6397552f6ee311aa174d4a6628370339efab422c..5aaac69849d65953ae4b4f51cdbf06aa2c48b561 100644 (file)
@@ -2,4 +2,5 @@
 
 obj-$(CONFIG_MT7615E) += mt7615e.o
 
-mt7615e-y := pci.o init.o dma.o eeprom.o main.o mcu.o mac.o
+mt7615e-y := pci.o init.o dma.o eeprom.o main.o mcu.o mac.o \
+            debugfs.o
diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt7615/debugfs.c
new file mode 100644 (file)
index 0000000..ed605fc
--- /dev/null
@@ -0,0 +1,38 @@
+/* SPDX-License-Identifier: ISC */
+
+#include "mt7615.h"
+
+static int
+mt7615_radar_pattern_set(void *data, u64 val)
+{
+       struct mt7615_dev *dev = data;
+
+       return mt7615_mcu_rdd_send_pattern(dev);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_radar_pattern, NULL,
+                        mt7615_radar_pattern_set, "%lld\n");
+
+int mt7615_init_debugfs(struct mt7615_dev *dev)
+{
+       struct dentry *dir;
+
+       dir = mt76_register_debugfs(&dev->mt76);
+       if (!dir)
+               return -ENOMEM;
+
+       debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern);
+       /* test pattern knobs */
+       debugfs_create_u8("pattern_len", 0600, dir,
+                         &dev->radar_pattern.n_pulses);
+       debugfs_create_u32("pulse_period", 0600, dir,
+                          &dev->radar_pattern.period);
+       debugfs_create_u16("pulse_width", 0600, dir,
+                          &dev->radar_pattern.width);
+       debugfs_create_u16("pulse_power", 0600, dir,
+                          &dev->radar_pattern.power);
+       debugfs_create_file("radar_trigger", 0200, dir, dev,
+                           &fops_radar_pattern);
+
+       return 0;
+}
index 095b22671e7193a1b0ffcc4f93b96ed7ad5a9c53..a6c2a132f96089510db1b77e265b1bca0fed9d28 100644 (file)
@@ -155,19 +155,6 @@ static const struct ieee80211_iface_combination if_comb[] = {
        }
 };
 
-static int mt7615_init_debugfs(struct mt7615_dev *dev)
-{
-       struct dentry *dir;
-
-       dir = mt76_register_debugfs(&dev->mt76);
-       if (!dir)
-               return -ENOMEM;
-
-       debugfs_create_u32("dfs_hw_pattern", 0400, dir, &dev->hw_pattern);
-
-       return 0;
-}
-
 static void
 mt7615_init_txpower(struct mt7615_dev *dev,
                    struct ieee80211_supported_band *sband)
index 951849e4dd09fcd443ca1be7a4b4fa4a9ef05ba6..06d146198e331c87302bd67068bfa9e6c1f42b26 100644 (file)
@@ -1294,6 +1294,37 @@ int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
                                   &req, sizeof(req), true);
 }
 
+int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev)
+{
+       struct {
+               u8 pulse_num;
+               u8 rsv[3];
+               struct {
+                       u32 start_time;
+                       u16 width;
+                       s16 power;
+               } pattern[32];
+       } req = {
+               .pulse_num = dev->radar_pattern.n_pulses,
+       };
+       u32 start_time = ktime_to_ms(ktime_get_boottime());
+       int i;
+
+       if (dev->radar_pattern.n_pulses > ARRAY_SIZE(req.pattern))
+               return -EINVAL;
+
+       /* TODO: add some noise here */
+       for (i = 0; i < dev->radar_pattern.n_pulses; i++) {
+               req.pattern[i].width = dev->radar_pattern.width;
+               req.pattern[i].power = dev->radar_pattern.power;
+               req.pattern[i].start_time = start_time +
+                                           i * dev->radar_pattern.period;
+       }
+
+       return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_SET_RDD_PATTERN,
+                                  &req, sizeof(req), false);
+}
+
 int mt7615_mcu_set_channel(struct mt7615_dev *dev)
 {
        struct cfg80211_chan_def *chandef = &dev->mt76.chandef;
index 73ce9fe8bfed86a5dd94f8fd9790e63ea809742b..17d22bfb1722bb2af37373dcd6009145babbcfa3 100644 (file)
@@ -104,6 +104,7 @@ enum {
        MCU_EXT_CMD_MAC_INIT_CTRL = 0x46,
        MCU_EXT_CMD_BCN_OFFLOAD = 0x49,
        MCU_EXT_CMD_SET_RX_PATH = 0x4e,
+       MCU_EXT_CMD_SET_RDD_PATTERN = 0x7d,
 };
 
 enum {
index d113fa30115ee6d24972943c57da79faddc72dcc..3713db874ef48567344d8b2be79fdf24212f7a33 100644 (file)
@@ -68,6 +68,12 @@ struct mt7615_dev {
        u32 vif_mask;
        u32 omac_mask;
 
+       struct {
+               u8 n_pulses;
+               u32 period;
+               u16 width;
+               s16 power;
+       } radar_pattern;
        u32 hw_pattern;
        int dfs_state;
 
@@ -177,6 +183,7 @@ int mt7615_mcu_rdd_cmd(struct mt7615_dev *dev,
                       u8 rx_sel, u8 val);
 int mt7615_dfs_start_radar_detector(struct mt7615_dev *dev);
 int mt7615_dfs_stop_radar_detector(struct mt7615_dev *dev);
+int mt7615_mcu_rdd_send_pattern(struct mt7615_dev *dev);
 
 static inline void mt7615_dfs_check_channel(struct mt7615_dev *dev)
 {
@@ -240,4 +247,6 @@ void mt7615_txp_skb_unmap(struct mt76_dev *dev,
 int mt76_dfs_start_rdd(struct mt7615_dev *dev, bool force);
 int mt7615_dfs_init_radar_detector(struct mt7615_dev *dev);
 
+int mt7615_init_debugfs(struct mt7615_dev *dev);
+
 #endif