From aa3837418d91044bb7eabafa9d42bd50ba88c3a2 Mon Sep 17 00:00:00 2001
From: Peter Chiu <chui-hao.chiu@mediatek.com>
Date: Thu, 20 Apr 2023 08:10:12 +0800
Subject: [PATCH 3009/3010] wifi: mt76: mt7996: add debugfs knob for random
 early drop

---
 mt7996/mt7996.h        |  1 +
 mt7996/mtk_debugfs_i.c | 23 +++++++++++++++++++++++
 mt7996/mtk_mcu_i.c     | 25 +++++++++++++++++++++++++
 mt7996/mtk_mcu_i.h     | 23 +++++++++++++++++++++++
 4 files changed, 72 insertions(+)

diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
index 55731f7..79edf2a 100644
--- a/mt7996/mt7996.h
+++ b/mt7996/mt7996.h
@@ -939,6 +939,7 @@ int mt7996_mtk_init_all_debugfs_internal(struct mt7996_phy *phy, struct dentry *
 
 int mt7996_mcu_set_muru_cmd(struct mt7996_dev *dev, u16 action, int val);
 int mt7996_mcu_muru_set_prot_frame_thr(struct mt7996_dev *dev, u32 val);
+int mt7996_mcu_set_vow_drr_dbg(struct mt7996_dev *dev, u32 val);
 #endif
 
 #endif
diff --git a/mt7996/mtk_debugfs_i.c b/mt7996/mtk_debugfs_i.c
index d255233..306783b 100644
--- a/mt7996/mtk_debugfs_i.c
+++ b/mt7996/mtk_debugfs_i.c
@@ -1690,6 +1690,27 @@ mt7996_bf_pfmu_tag_read_set(void *data, u64 wlan_idx)
 DEFINE_DEBUGFS_ATTRIBUTE(fops_bf_pfmu_tag_read, NULL,
 			 mt7996_bf_pfmu_tag_read_set, "%lld\n");
 
+static int
+mt7996_red_config_set(void *data, u64 val)
+{
+	struct mt7996_dev *dev = data;
+
+	return mt7996_mcu_red_config(dev, !!val);
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(fops_red_config, NULL,
+			 mt7996_red_config_set, "%lld\n");
+
+static int
+mt7996_vow_drr_dbg(void *data, u64 val)
+{
+	struct mt7996_dev *dev = data;
+
+	return mt7996_mcu_set_vow_drr_dbg(dev, (u32)val);
+}
+DEFINE_DEBUGFS_ATTRIBUTE(fops_vow_drr_dbg, NULL,
+			 mt7996_vow_drr_dbg, "%lld\n");
+
 static int
 mt7996_muru_fixed_rate_set(void *data, u64 val)
 {
@@ -1801,6 +1822,8 @@ int mt7996_mtk_init_debugfs_internal(struct mt7996_phy *phy, struct dentry *dir)
 	debugfs_create_devm_seqfile(dev->mt76.dev, "pse_info", dir,
 				    mt7996_pseinfo_read);
 
+	debugfs_create_file("red", 0200, dir, dev, &fops_red_config);
+	debugfs_create_file("vow_drr_dbg", 0200, dir, dev, &fops_vow_drr_dbg);
 	debugfs_create_u32("token_idx", 0600, dir, &dev->dbg.token_idx);
 	debugfs_create_devm_seqfile(dev->mt76.dev, "token", dir,
 				    mt7996_token_read);
diff --git a/mt7996/mtk_mcu_i.c b/mt7996/mtk_mcu_i.c
index c12245f..84eb892 100644
--- a/mt7996/mtk_mcu_i.c
+++ b/mt7996/mtk_mcu_i.c
@@ -700,4 +700,29 @@ error:
 	return -EINVAL;
 }
 
+int mt7996_mcu_set_vow_drr_dbg(struct mt7996_dev *dev, u32 val)
+{
+#define MT7996_VOW_DEBUG_MODE	0xe
+	struct {
+		u8 __rsv1[4];
+
+		__le16 tag;
+		__le16 len;
+		u8 __rsv2[4];
+		__le32 action;
+		__le32 val;
+		u8 __rsv3[8];
+	} __packed req = {
+		.tag = cpu_to_le16(UNI_VOW_DRR_CTRL),
+		.len = cpu_to_le16(sizeof(req) - 4),
+		.action = cpu_to_le32(MT7996_VOW_DEBUG_MODE),
+		.val = cpu_to_le32(val),
+	};
+
+	if (val & ~VOW_DRR_DBG_FLAGS)
+		return -EINVAL;
+
+	return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(VOW), &req,
+				 sizeof(req), true);
+}
 #endif
diff --git a/mt7996/mtk_mcu_i.h b/mt7996/mtk_mcu_i.h
index a8a210a..3d305f5 100644
--- a/mt7996/mtk_mcu_i.h
+++ b/mt7996/mtk_mcu_i.h
@@ -509,6 +509,29 @@ enum {
 	BF_SND_CFG_TXOP_SND
 };
 
+enum {
+	VOW_DRR_DBG_DUMP_BMP = BIT(0),
+	VOW_DRR_DBG_EST_AT_PRINT = BIT(1),
+	VOW_DRR_DBG_ADJ_GLOBAL_THLD = BIT(21),
+	VOW_DRR_DBG_PRN_LOUD = BIT(22),
+	VOW_DRR_DBG_PRN_ADJ_STA = BIT(23),
+	VOW_DRR_DBG_FIX_CR = GENMASK(27, 24),
+	VOW_DRR_DBG_CLR_FIX_CR = BIT(28),
+	VOW_DRR_DBG_DISABLE = BIT(29),
+	VOW_DRR_DBG_DUMP_CR = BIT(30),
+	VOW_DRR_DBG_PRN = BIT(31)
+};
+
+#define VOW_DRR_DBG_FLAGS (VOW_DRR_DBG_DUMP_BMP |	\
+			  VOW_DRR_DBG_EST_AT_PRINT |	\
+			  VOW_DRR_DBG_ADJ_GLOBAL_THLD |	\
+			  VOW_DRR_DBG_PRN_LOUD |	\
+			  VOW_DRR_DBG_PRN_ADJ_STA |	\
+			  VOW_DRR_DBG_FIX_CR |		\
+			  VOW_DRR_DBG_CLR_FIX_CR |	\
+			  VOW_DRR_DBG_DISABLE |		\
+			  VOW_DRR_DBG_DUMP_CR |		\
+			  VOW_DRR_DBG_PRN)
 #endif
 
 #endif
-- 
2.18.0

