blob: e21fa8bdace44d0796bbab945a4378667feef25a [file] [log] [blame]
developere35b8e42023-10-16 11:04:00 +08001From 50d93c608b1cfe0750fa98c1fbafe6ad6ed3212d Mon Sep 17 00:00:00 2001
developer281084d2023-06-19 12:03:50 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Wed, 19 Apr 2023 18:32:41 +0800
developere35b8e42023-10-16 11:04:00 +08004Subject: [PATCH 67/98] wifi: mt76: add random early drop support
developer281084d2023-06-19 12:03:50 +08005
6---
developere35b8e42023-10-16 11:04:00 +08007 mt7996/mcu.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++--
developer281084d2023-06-19 12:03:50 +08008 mt7996/mcu.h | 4 ++-
9 mt7996/mt7996.h | 1 +
developere35b8e42023-10-16 11:04:00 +080010 3 files changed, 83 insertions(+), 3 deletions(-)
developer281084d2023-06-19 12:03:50 +080011
12diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developere35b8e42023-10-16 11:04:00 +080013index b8d26ec..6589610 100644
developer281084d2023-06-19 12:03:50 +080014--- a/mt7996/mcu.c
15+++ b/mt7996/mcu.c
developere35b8e42023-10-16 11:04:00 +080016@@ -3012,8 +3012,8 @@ int mt7996_mcu_init_firmware(struct mt7996_dev *dev)
developer281084d2023-06-19 12:03:50 +080017 if (ret)
18 return ret;
19
20- return mt7996_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
21- MCU_WA_PARAM_RED, 0, 0);
22+ return mt7996_mcu_red_config(dev,
23+ mtk_wed_device_active(&dev->mt76.mmio.wed));
24 }
25
26 int mt7996_mcu_init(struct mt7996_dev *dev)
developere35b8e42023-10-16 11:04:00 +080027@@ -3045,6 +3045,83 @@ out:
developer281084d2023-06-19 12:03:50 +080028 skb_queue_purge(&dev->mt76.mcu.res_q);
29 }
30
31+static int mt7996_mcu_wa_red_config(struct mt7996_dev *dev)
32+{
33+#define RED_TOKEN_SRC_CNT 4
34+#define RED_TOKEN_CONFIG 2
35+ struct {
36+ __le32 arg0;
37+ __le32 arg1;
38+ __le32 arg2;
39+
40+ u8 mode;
41+ u8 version;
42+ u8 _rsv[4];
43+ __le16 len;
44+
45+ __le16 tcp_offset;
46+ __le16 priority_offset;
47+ __le16 token_per_src[RED_TOKEN_SRC_CNT];
48+ __le16 token_thr_per_src[RED_TOKEN_SRC_CNT];
49+
50+ u8 _rsv2[604];
51+ } __packed req = {
52+ .arg0 = cpu_to_le32(MCU_WA_PARAM_RED_CONFIG),
53+
54+ .mode = RED_TOKEN_CONFIG,
55+ .len = cpu_to_le16(sizeof(req) - sizeof(__le32) * 3),
56+
57+ .tcp_offset = cpu_to_le16(200),
58+ .priority_offset = cpu_to_le16(255),
59+ };
60+ u8 i;
61+
62+ for (i = 0; i < RED_TOKEN_SRC_CNT; i++) {
63+ req.token_per_src[i] = cpu_to_le16(MT7996_TOKEN_SIZE);
64+ req.token_thr_per_src[i] = cpu_to_le16(MT7996_TOKEN_SIZE);
65+ }
66+
developere35b8e42023-10-16 11:04:00 +080067+ if (!mtk_wed_device_active(&dev->mt76.mmio.wed))
68+ req.token_per_src[RED_TOKEN_SRC_CNT - 1] =
69+ cpu_to_le16(MT7996_TOKEN_SIZE - MT7996_HW_TOKEN_SIZE);
70+
developer281084d2023-06-19 12:03:50 +080071+ return mt76_mcu_send_msg(&dev->mt76, MCU_WA_PARAM_CMD(SET),
72+ &req, sizeof(req), false);
73+}
74+
75+int mt7996_mcu_red_config(struct mt7996_dev *dev, bool enable)
76+{
77+#define RED_DISABLE 0
78+#define RED_BY_WA_ENABLE 2
79+ struct {
80+ u8 __rsv1[4];
81+
82+ __le16 tag;
83+ __le16 len;
84+ u8 enable;
85+ u8 __rsv2[3];
86+ } __packed req = {
87+ .tag = cpu_to_le16(UNI_VOW_RED_ENABLE),
88+ .len = cpu_to_le16(sizeof(req) - 4),
89+ .enable = enable ? RED_BY_WA_ENABLE : RED_DISABLE,
90+ };
91+ int ret;
92+
93+ ret = mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(VOW), &req,
94+ sizeof(req), true);
95+
96+ if (ret)
97+ return ret;
98+
99+ ret = mt7996_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET),
100+ MCU_WA_PARAM_RED_EN, enable, 0);
101+
102+ if (ret || !enable)
103+ return ret;
104+
105+ return mt7996_mcu_wa_red_config(dev);
106+}
107+
108 int mt7996_mcu_set_hdr_trans(struct mt7996_dev *dev, bool hdr_trans)
109 {
110 struct {
111diff --git a/mt7996/mcu.h b/mt7996/mcu.h
developere35b8e42023-10-16 11:04:00 +0800112index bb876f3..666216a 100644
developer281084d2023-06-19 12:03:50 +0800113--- a/mt7996/mcu.h
114+++ b/mt7996/mcu.h
developere35b8e42023-10-16 11:04:00 +0800115@@ -287,8 +287,9 @@ enum {
developer281084d2023-06-19 12:03:50 +0800116 enum {
117 MCU_WA_PARAM_PDMA_RX = 0x04,
118 MCU_WA_PARAM_CPU_UTIL = 0x0b,
119- MCU_WA_PARAM_RED = 0x0e,
120+ MCU_WA_PARAM_RED_EN = 0x0e,
121 MCU_WA_PARAM_HW_PATH_HIF_VER = 0x2f,
122+ MCU_WA_PARAM_RED_CONFIG = 0x40,
123 };
124
125 enum mcu_mmps_mode {
developere35b8e42023-10-16 11:04:00 +0800126@@ -817,6 +818,7 @@ enum {
developer281084d2023-06-19 12:03:50 +0800127 UNI_VOW_DRR_CTRL,
128 UNI_VOW_RX_AT_AIRTIME_EN = 0x0b,
129 UNI_VOW_RX_AT_AIRTIME_CLR_EN = 0x0e,
130+ UNI_VOW_RED_ENABLE = 0x18,
131 };
132
133 enum {
134diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developere35b8e42023-10-16 11:04:00 +0800135index 6775360..bba1364 100644
developer281084d2023-06-19 12:03:50 +0800136--- a/mt7996/mt7996.h
137+++ b/mt7996/mt7996.h
developere35b8e42023-10-16 11:04:00 +0800138@@ -654,6 +654,7 @@ int mt7996_mcu_rf_regval(struct mt7996_dev *dev, u32 regidx, u32 *val, bool set)
developer281084d2023-06-19 12:03:50 +0800139 int mt7996_mcu_set_hdr_trans(struct mt7996_dev *dev, bool hdr_trans);
140 int mt7996_mcu_set_rro(struct mt7996_dev *dev, u16 tag, u8 val);
141 int mt7996_mcu_wa_cmd(struct mt7996_dev *dev, int cmd, u32 a1, u32 a2, u32 a3);
142+int mt7996_mcu_red_config(struct mt7996_dev *dev, bool enable);
143 int mt7996_mcu_fw_log_2_host(struct mt7996_dev *dev, u8 type, u8 ctrl);
144 int mt7996_mcu_fw_dbg_ctrl(struct mt7996_dev *dev, u32 module, u8 level);
145 int mt7996_mcu_trigger_assert(struct mt7996_dev *dev);
146--
developere35b8e42023-10-16 11:04:00 +08001472.18.0
developer281084d2023-06-19 12:03:50 +0800148