developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 1 | From 721ea64eb33f3708435f86501121602666d2caec Mon Sep 17 00:00:00 2001 |
| 2 | From: Howard Hsu <howard-yh.hsu@mediatek.com> |
| 3 | Date: Tue, 13 Jun 2023 14:49:02 +0800 |
| 4 | Subject: [PATCH 048/199] mtk: mt76: mt7996: add build the following MURU mcu |
| 5 | command tlvs |
| 6 | |
| 7 | It includes the following tlvs: |
| 8 | 1. MURU tlv id 0x10, 0x33, 0xC8, 0xC9, 0xCA, 0xCC, 0xCD |
| 9 | 2. BF tlv id 0x1c |
| 10 | |
| 11 | --- |
| 12 | mt7996/mcu.h | 1 + |
| 13 | mt7996/mt7996.h | 3 ++ |
| 14 | mt7996/mtk_debugfs.c | 123 +++++++++++++++++++++++++++++++++++++++++++ |
| 15 | mt7996/mtk_mcu.c | 78 +++++++++++++++++++++++++++ |
| 16 | mt7996/mtk_mcu.h | 14 +++++ |
| 17 | 5 files changed, 219 insertions(+) |
| 18 | |
| 19 | diff --git a/mt7996/mcu.h b/mt7996/mcu.h |
| 20 | index 8a718513..a98b174e 100644 |
| 21 | --- a/mt7996/mcu.h |
| 22 | +++ b/mt7996/mcu.h |
| 23 | @@ -776,6 +776,7 @@ enum { |
| 24 | BF_MOD_EN_CTRL = 20, |
| 25 | BF_FBRPT_DBG_INFO_READ = 23, |
| 26 | BF_TXSND_INFO = 24, |
| 27 | + BF_CFG_PHY = 28, |
| 28 | }; |
| 29 | |
| 30 | enum { |
| 31 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
| 32 | index 8935ef22..45ce7db7 100644 |
| 33 | --- a/mt7996/mt7996.h |
| 34 | +++ b/mt7996/mt7996.h |
| 35 | @@ -821,6 +821,9 @@ void mt7996_mcu_rx_bf_event(struct mt7996_dev *dev, struct sk_buff *skb); |
| 36 | int mt7996_mcu_set_muru_fixed_rate_enable(struct mt7996_dev *dev, u8 action, int val); |
| 37 | int mt7996_mcu_set_muru_fixed_rate_parameter(struct mt7996_dev *dev, u8 action, void *para); |
| 38 | int mt7996_mcu_set_txbf_snd_info(struct mt7996_phy *phy, void *para); |
| 39 | +int mt7996_mcu_set_muru_cmd(struct mt7996_dev *dev, u16 action, int val); |
| 40 | +int mt7996_mcu_muru_set_prot_frame_thr(struct mt7996_dev *dev, u32 val); |
| 41 | +int mt7996_mcu_set_bypass_smthint(struct mt7996_phy *phy, u8 val); |
| 42 | #endif |
| 43 | |
| 44 | #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| 45 | diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
| 46 | index b3cc8119..0e029d5d 100644 |
| 47 | --- a/mt7996/mtk_debugfs.c |
| 48 | +++ b/mt7996/mtk_debugfs.c |
| 49 | @@ -2912,6 +2912,127 @@ mt7996_sr_scene_cond_show(struct seq_file *file, void *data) |
| 50 | } |
| 51 | DEFINE_SHOW_ATTRIBUTE(mt7996_sr_scene_cond); |
| 52 | |
| 53 | +static int |
| 54 | +mt7996_starec_bf_read_set(void *data, u64 wlan_idx) |
| 55 | +{ |
| 56 | + struct mt7996_phy *phy = data; |
| 57 | + |
| 58 | + return mt7996_mcu_set_txbf_internal(phy, BF_STA_REC_READ, wlan_idx); |
| 59 | +} |
| 60 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_starec_bf_read, NULL, |
| 61 | + mt7996_starec_bf_read_set, "%lld\n"); |
| 62 | + |
| 63 | +static ssize_t |
| 64 | +mt7996_bf_txsnd_info_set(struct file *file, |
| 65 | + const char __user *user_buf, |
| 66 | + size_t count, loff_t *ppos) |
| 67 | +{ |
| 68 | + struct mt7996_phy *phy = file->private_data; |
| 69 | + char buf[40]; |
| 70 | + int ret; |
| 71 | + |
| 72 | + if (count >= sizeof(buf)) |
| 73 | + return -EINVAL; |
| 74 | + |
| 75 | + if (copy_from_user(buf, user_buf, count)) |
| 76 | + return -EFAULT; |
| 77 | + |
| 78 | + if (count && buf[count - 1] == '\n') |
| 79 | + buf[count - 1] = '\0'; |
| 80 | + else |
| 81 | + buf[count] = '\0'; |
| 82 | + |
| 83 | + ret = mt7996_mcu_set_txbf_snd_info(phy, buf); |
| 84 | + |
| 85 | + if (ret) return -EFAULT; |
| 86 | + |
| 87 | + return count; |
| 88 | +} |
| 89 | + |
| 90 | +static const struct file_operations fops_bf_txsnd_info = { |
| 91 | + .write = mt7996_bf_txsnd_info_set, |
| 92 | + .read = NULL, |
| 93 | + .open = simple_open, |
| 94 | + .llseek = default_llseek, |
| 95 | +}; |
| 96 | + |
| 97 | +static int |
| 98 | +mt7996_bf_fbk_rpt_set(void *data, u64 wlan_idx) |
| 99 | +{ |
| 100 | + struct mt7996_phy *phy = data; |
| 101 | + |
| 102 | + return mt7996_mcu_set_txbf_internal(phy, BF_FBRPT_DBG_INFO_READ, wlan_idx); |
| 103 | +} |
| 104 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_bf_fbk_rpt, NULL, |
| 105 | + mt7996_bf_fbk_rpt_set, "%lld\n"); |
| 106 | + |
| 107 | +static int |
| 108 | +mt7996_bf_pfmu_tag_read_set(void *data, u64 wlan_idx) |
| 109 | +{ |
| 110 | + struct mt7996_phy *phy = data; |
| 111 | + |
| 112 | + return mt7996_mcu_set_txbf_internal(phy, BF_PFMU_TAG_READ, wlan_idx); |
| 113 | +} |
| 114 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_bf_pfmu_tag_read, NULL, |
| 115 | + mt7996_bf_pfmu_tag_read_set, "%lld\n"); |
| 116 | + |
| 117 | +static int |
| 118 | +mt7996_muru_fixed_rate_set(void *data, u64 val) |
| 119 | +{ |
| 120 | + struct mt7996_dev *dev = data; |
| 121 | + |
| 122 | + return mt7996_mcu_set_muru_fixed_rate_enable(dev, UNI_CMD_MURU_FIXED_RATE_CTRL, |
| 123 | + val); |
| 124 | +} |
| 125 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_muru_fixed_rate_enable, NULL, |
| 126 | + mt7996_muru_fixed_rate_set, "%lld\n"); |
| 127 | + |
| 128 | +static ssize_t |
| 129 | +mt7996_muru_fixed_rate_parameter_set(struct file *file, |
| 130 | + const char __user *user_buf, |
| 131 | + size_t count, loff_t *ppos) |
| 132 | +{ |
| 133 | + struct mt7996_dev *dev = file->private_data; |
| 134 | + char buf[40]; |
| 135 | + int ret; |
| 136 | + |
| 137 | + if (count >= sizeof(buf)) |
| 138 | + return -EINVAL; |
| 139 | + |
| 140 | + if (copy_from_user(buf, user_buf, count)) |
| 141 | + return -EFAULT; |
| 142 | + |
| 143 | + if (count && buf[count - 1] == '\n') |
| 144 | + buf[count - 1] = '\0'; |
| 145 | + else |
| 146 | + buf[count] = '\0'; |
| 147 | + |
| 148 | + |
| 149 | + ret = mt7996_mcu_set_muru_fixed_rate_parameter(dev, UNI_CMD_MURU_FIXED_GROUP_RATE_CTRL, |
| 150 | + buf); |
| 151 | + |
| 152 | + if (ret) return -EFAULT; |
| 153 | + |
| 154 | + return count; |
| 155 | +} |
| 156 | + |
| 157 | +static const struct file_operations fops_muru_fixed_group_rate = { |
| 158 | + .write = mt7996_muru_fixed_rate_parameter_set, |
| 159 | + .read = NULL, |
| 160 | + .open = simple_open, |
| 161 | + .llseek = default_llseek, |
| 162 | +}; |
| 163 | + |
| 164 | +static int mt7996_muru_prot_thr_set(void *data, u64 val) |
| 165 | +{ |
| 166 | + struct mt7996_phy *phy = data; |
| 167 | + |
| 168 | + return mt7996_mcu_muru_set_prot_frame_thr(phy->dev, (u32)val); |
| 169 | +} |
| 170 | + |
| 171 | +DEFINE_DEBUGFS_ATTRIBUTE(fops_muru_prot_thr, NULL, |
| 172 | + mt7996_muru_prot_thr_set, "%lld\n"); |
| 173 | + |
| 174 | int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 175 | { |
| 176 | struct mt7996_dev *dev = phy->dev; |
| 177 | @@ -3006,6 +3127,8 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 178 | debugfs_create_file("bf_fbk_rpt", 0600, dir, phy, &fops_bf_fbk_rpt); |
| 179 | debugfs_create_file("pfmu_tag_read", 0600, dir, phy, &fops_bf_pfmu_tag_read); |
| 180 | |
| 181 | + debugfs_create_file("muru_prot_thr", 0200, dir, phy, &fops_muru_prot_thr); |
| 182 | + |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | diff --git a/mt7996/mtk_mcu.c b/mt7996/mtk_mcu.c |
| 187 | index 6b2cdad6..68650623 100644 |
| 188 | --- a/mt7996/mtk_mcu.c |
| 189 | +++ b/mt7996/mtk_mcu.c |
| 190 | @@ -904,4 +904,82 @@ error: |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | +/** |
| 195 | + * This function can be used to build the following commands |
| 196 | + * MURU_SUTX_CTRL (0x10) |
| 197 | + * SET_FORCE_MU (0x33) |
| 198 | + * SET_MUDL_ACK_POLICY (0xC8) |
| 199 | + * SET_TRIG_TYPE (0xC9) |
| 200 | + * SET_20M_DYN_ALGO (0xCA) |
| 201 | + * SET_CERT_MU_EDCA_OVERRIDE (0xCD) |
| 202 | + */ |
| 203 | +int mt7996_mcu_set_muru_cmd(struct mt7996_dev *dev, u16 action, int val) |
| 204 | +{ |
| 205 | + struct { |
| 206 | + u8 _rsv[4]; |
| 207 | + |
| 208 | + __le16 tag; |
| 209 | + __le16 len; |
| 210 | + |
| 211 | + u8 config; |
| 212 | + u8 rsv[3]; |
| 213 | + } __packed data = { |
| 214 | + .tag = cpu_to_le16(action), |
| 215 | + .len = cpu_to_le16(sizeof(data) - 4), |
| 216 | + .config = (u8) val, |
| 217 | + }; |
| 218 | + |
| 219 | + return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(MURU), &data, sizeof(data), |
| 220 | + false); |
| 221 | +} |
| 222 | + |
| 223 | +int mt7996_mcu_muru_set_prot_frame_thr(struct mt7996_dev *dev, u32 val) |
| 224 | +{ |
| 225 | + struct { |
| 226 | + u8 _rsv[4]; |
| 227 | + |
| 228 | + __le16 tag; |
| 229 | + __le16 len; |
| 230 | + |
| 231 | + __le32 prot_frame_thr; |
| 232 | + } __packed data = { |
| 233 | + .tag = cpu_to_le16(UNI_CMD_MURU_PROT_FRAME_THR), |
| 234 | + .len = cpu_to_le16(sizeof(data) - 4), |
| 235 | + .prot_frame_thr = cpu_to_le32(val), |
| 236 | + }; |
| 237 | + |
| 238 | + return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(MURU), &data, sizeof(data), |
| 239 | + false); |
| 240 | +} |
| 241 | + |
| 242 | +int mt7996_mcu_set_bypass_smthint(struct mt7996_phy *phy, u8 val) |
| 243 | +{ |
| 244 | +#define BF_PHY_SMTH_INT_BYPASS 0 |
| 245 | +#define BYPASS_VAL 1 |
| 246 | + struct mt7996_dev *dev = phy->dev; |
| 247 | + struct { |
| 248 | + u8 _rsv[4]; |
| 249 | + |
| 250 | + u16 tag; |
| 251 | + u16 len; |
| 252 | + |
| 253 | + u8 action; |
| 254 | + u8 band_idx; |
| 255 | + u8 smthintbypass; |
| 256 | + u8 __rsv2[5]; |
| 257 | + } __packed data = { |
| 258 | + .tag = cpu_to_le16(BF_CFG_PHY), |
| 259 | + .len = cpu_to_le16(sizeof(data) - 4), |
| 260 | + .action = BF_PHY_SMTH_INT_BYPASS, |
| 261 | + .band_idx = phy->mt76->band_idx, |
| 262 | + .smthintbypass = val, |
| 263 | + }; |
| 264 | + |
| 265 | + if (val != BYPASS_VAL) |
| 266 | + return -EINVAL; |
| 267 | + |
| 268 | + return mt76_mcu_send_msg(&dev->mt76, MCU_WM_UNI_CMD(BF), &data, sizeof(data), |
| 269 | + true); |
| 270 | +} |
| 271 | + |
| 272 | #endif |
| 273 | diff --git a/mt7996/mtk_mcu.h b/mt7996/mtk_mcu.h |
| 274 | index 27d6a05b..d9686ebb 100644 |
| 275 | --- a/mt7996/mtk_mcu.h |
| 276 | +++ b/mt7996/mtk_mcu.h |
| 277 | @@ -119,6 +119,20 @@ enum { |
| 278 | EDCCA_FCC = 1, |
| 279 | EDCCA_ETSI = 2, |
| 280 | EDCCA_JAPAN = 3 |
| 281 | +}; |
| 282 | + |
| 283 | +enum { |
| 284 | + UNI_CMD_MURU_SUTX_CTRL = 0x10, |
| 285 | + UNI_CMD_MURU_FIXED_RATE_CTRL, |
| 286 | + UNI_CMD_MURU_FIXED_GROUP_RATE_CTRL, |
| 287 | + UNI_CMD_MURU_SET_FORCE_MU = 0x33, |
| 288 | + UNI_CMD_MURU_MUNUAL_CONFIG = 0x64, |
| 289 | + UNI_CMD_MURU_SET_MUDL_ACK_POLICY = 0xC9, |
| 290 | + UNI_CMD_MURU_SET_TRIG_TYPE, |
| 291 | + UNI_CMD_MURU_SET_20M_DYN_ALGO, |
| 292 | + UNI_CMD_MURU_PROT_FRAME_THR = 0xCC, |
| 293 | + UNI_CMD_MURU_SET_CERT_MU_EDCA_OVERRIDE, |
| 294 | +}; |
| 295 | |
| 296 | struct bf_pfmu_tag { |
| 297 | __le16 tag; |
| 298 | -- |
| 299 | 2.18.0 |
| 300 | |