developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 1 | From 496377bfa726689b334d0c73da0f09089c1698ff Mon Sep 17 00:00:00 2001 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 2 | From: Bo Jiao <Bo.Jiao@mediatek.com> |
| 3 | Date: Tue, 11 Jan 2022 12:03:23 +0800 |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1002/1031] wifi: mt76: mt7915: air monitor support |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 5 | |
| 6 | --- |
developer | 5ce5ea4 | 2022-08-31 14:12:29 +0800 | [diff] [blame] | 7 | mt76_connac_mcu.h | 2 + |
| 8 | mt7915/mac.c | 4 + |
| 9 | mt7915/main.c | 3 + |
| 10 | mt7915/mt7915.h | 34 +++++ |
| 11 | mt7915/vendor.c | 359 ++++++++++++++++++++++++++++++++++++++++++++++ |
| 12 | mt7915/vendor.h | 38 +++++ |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 13 | 6 files changed, 440 insertions(+) |
| 14 | |
| 15 | diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 16 | index 13214452..411911c0 100644 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 17 | --- a/mt76_connac_mcu.h |
| 18 | +++ b/mt76_connac_mcu.h |
developer | 4f0d84b | 2023-03-03 14:21:44 +0800 | [diff] [blame] | 19 | @@ -1194,6 +1194,8 @@ enum { |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 20 | MCU_EXT_CMD_GROUP_PRE_CAL_INFO = 0xab, |
| 21 | MCU_EXT_CMD_DPD_PRE_CAL_INFO = 0xac, |
| 22 | MCU_EXT_CMD_PHY_STAT_INFO = 0xad, |
| 23 | + /* for vendor csi and air monitor */ |
| 24 | + MCU_EXT_CMD_SMESH_CTRL = 0xae, |
| 25 | MCU_EXT_CMD_CSI_CTRL = 0xc2, |
| 26 | }; |
| 27 | |
| 28 | diff --git a/mt7915/mac.c b/mt7915/mac.c |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 29 | index 5bac45a3..ad5895de 100644 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 30 | --- a/mt7915/mac.c |
| 31 | +++ b/mt7915/mac.c |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame] | 32 | @@ -547,6 +547,10 @@ mt7915_mac_fill_rx(struct mt7915_dev *dev, struct sk_buff *skb, |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 33 | seq_ctrl = le16_to_cpu(hdr->seq_ctrl); |
| 34 | qos_ctl = *ieee80211_get_qos_ctl(hdr); |
| 35 | } |
| 36 | +#ifdef CONFIG_MTK_VENDOR |
| 37 | + if (phy->amnt_ctrl.enable) |
| 38 | + mt7915_vendor_amnt_fill_rx(phy, skb); |
| 39 | +#endif |
| 40 | } else { |
| 41 | status->flag |= RX_FLAG_8023; |
developer | 144824b | 2022-11-25 21:27:43 +0800 | [diff] [blame] | 42 | mt7915_wed_check_ppe(dev, &dev->mt76.q_rx[q], msta, skb, |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 43 | diff --git a/mt7915/main.c b/mt7915/main.c |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 44 | index 0777663e..3d9635f4 100644 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 45 | --- a/mt7915/main.c |
| 46 | +++ b/mt7915/main.c |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 47 | @@ -704,6 +704,9 @@ int mt7915_mac_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif, |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 48 | if (ret) |
| 49 | return ret; |
| 50 | |
| 51 | +#ifdef CONFIG_MTK_VENDOR |
| 52 | + mt7915_vendor_amnt_sta_remove(mvif->phy, sta); |
| 53 | +#endif |
| 54 | return mt7915_mcu_add_rate_ctrl(dev, vif, sta, false); |
| 55 | } |
| 56 | |
| 57 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 58 | index a4cdc8df..eec37f78 100644 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 59 | --- a/mt7915/mt7915.h |
| 60 | +++ b/mt7915/mt7915.h |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame] | 61 | @@ -250,6 +250,35 @@ struct mt7915_hif { |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 62 | int irq; |
| 63 | }; |
| 64 | |
| 65 | +#ifdef CONFIG_MTK_VENDOR |
| 66 | +#define MT7915_AIR_MONITOR_MAX_ENTRY 16 |
| 67 | +#define MT7915_AIR_MONITOR_MAX_GROUP MT7915_AIR_MONITOR_MAX_ENTRY >> 2 |
| 68 | + |
| 69 | +struct mt7915_air_monitor_group { |
| 70 | + bool enable; |
| 71 | + bool used[2]; |
| 72 | +}; |
| 73 | + |
| 74 | +struct mt7915_air_monitor_entry { |
| 75 | + bool enable; |
| 76 | + |
| 77 | + u8 group_idx; |
| 78 | + u8 group_used_idx; |
| 79 | + u8 muar_idx; |
| 80 | + u8 addr[ETH_ALEN]; |
| 81 | + unsigned int last_seen; |
| 82 | + s8 rssi[4]; |
| 83 | + struct ieee80211_sta *sta; |
| 84 | +}; |
| 85 | + |
| 86 | +struct mt7915_air_monitor_ctrl { |
| 87 | + u8 enable; |
| 88 | + |
| 89 | + struct mt7915_air_monitor_group group[MT7915_AIR_MONITOR_MAX_GROUP]; |
| 90 | + struct mt7915_air_monitor_entry entry[MT7915_AIR_MONITOR_MAX_ENTRY]; |
| 91 | +}; |
| 92 | +#endif |
| 93 | + |
| 94 | struct mt7915_phy { |
| 95 | struct mt76_phy *mt76; |
| 96 | struct mt7915_dev *dev; |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame] | 97 | @@ -307,6 +336,8 @@ struct mt7915_phy { |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 98 | u32 interval; |
| 99 | u32 last_record; |
| 100 | } csi; |
| 101 | + |
| 102 | + struct mt7915_air_monitor_ctrl amnt_ctrl; |
| 103 | #endif |
| 104 | }; |
| 105 | |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 106 | @@ -694,6 +725,9 @@ int mt7915_mmio_wed_init(struct mt7915_dev *dev, void *pdev_ptr, |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 107 | void mt7915_vendor_register(struct mt7915_phy *phy); |
| 108 | int mt7915_mcu_set_csi(struct mt7915_phy *phy, u8 mode, |
| 109 | u8 cfg, u8 v1, u32 v2, u8 *mac_addr); |
| 110 | +void mt7915_vendor_amnt_fill_rx(struct mt7915_phy *phy, struct sk_buff *skb); |
| 111 | +int mt7915_vendor_amnt_sta_remove(struct mt7915_phy *phy, |
| 112 | + struct ieee80211_sta *sta); |
| 113 | #endif |
| 114 | |
| 115 | #ifdef MTK_DEBUG |
| 116 | diff --git a/mt7915/vendor.c b/mt7915/vendor.c |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame] | 117 | index 98fd9c2d..b94d787e 100644 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 118 | --- a/mt7915/vendor.c |
| 119 | +++ b/mt7915/vendor.c |
| 120 | @@ -430,6 +430,353 @@ out: |
| 121 | return err; |
| 122 | } |
| 123 | |
| 124 | +static const struct nla_policy |
| 125 | +amnt_ctrl_policy[NUM_MTK_VENDOR_ATTRS_AMNT_CTRL] = { |
| 126 | + [MTK_VENDOR_ATTR_AMNT_CTRL_SET] = {.type = NLA_NESTED }, |
| 127 | + [MTK_VENDOR_ATTR_AMNT_CTRL_DUMP] = { .type = NLA_NESTED }, |
| 128 | +}; |
| 129 | + |
| 130 | +static const struct nla_policy |
| 131 | +amnt_set_policy[NUM_MTK_VENDOR_ATTRS_AMNT_SET] = { |
| 132 | + [MTK_VENDOR_ATTR_AMNT_SET_INDEX] = {.type = NLA_U8 }, |
| 133 | + [MTK_VENDOR_ATTR_AMNT_SET_MACADDR] = { .type = NLA_NESTED }, |
| 134 | +}; |
| 135 | + |
| 136 | +static const struct nla_policy |
| 137 | +amnt_dump_policy[NUM_MTK_VENDOR_ATTRS_AMNT_DUMP] = { |
| 138 | + [MTK_VENDOR_ATTR_AMNT_DUMP_INDEX] = {.type = NLA_U8 }, |
| 139 | + [MTK_VENDOR_ATTR_AMNT_DUMP_LEN] = { .type = NLA_U8 }, |
| 140 | + [MTK_VENDOR_ATTR_AMNT_DUMP_RESULT] = { .type = NLA_NESTED }, |
| 141 | +}; |
| 142 | + |
| 143 | +struct mt7915_amnt_data { |
| 144 | + u8 idx; |
| 145 | + u8 addr[ETH_ALEN]; |
| 146 | + s8 rssi[4]; |
| 147 | + u32 last_seen; |
| 148 | +}; |
| 149 | + |
| 150 | +struct mt7915_smesh { |
| 151 | + u8 band; |
| 152 | + u8 write; |
| 153 | + u8 enable; |
| 154 | + bool a2; |
| 155 | + bool a1; |
| 156 | + bool data; |
| 157 | + bool mgnt; |
| 158 | + bool ctrl; |
| 159 | +} __packed; |
| 160 | + |
| 161 | +struct mt7915_smesh_event { |
| 162 | + u8 band; |
| 163 | + __le32 value; |
| 164 | +} __packed; |
| 165 | + |
| 166 | +static int |
| 167 | +mt7915_vendor_smesh_ctrl(struct mt7915_phy *phy, u8 write, |
| 168 | + u8 enable, u32 *value) |
| 169 | +{ |
| 170 | + struct mt7915_dev *dev = phy->dev; |
| 171 | + struct mt7915_smesh req = { |
| 172 | + .band = phy != &dev->phy, |
| 173 | + .write = write, |
| 174 | + .enable = enable, |
| 175 | + .a2 = 1, |
| 176 | + .a1 = 1, |
| 177 | + .data = 1, |
| 178 | + }; |
| 179 | + struct mt7915_smesh_event *res; |
| 180 | + struct sk_buff *skb; |
| 181 | + int ret = 0; |
| 182 | + |
| 183 | + ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_CMD(SMESH_CTRL), |
| 184 | + &req, sizeof(req), !write, &skb); |
| 185 | + |
| 186 | + if (ret || write) |
| 187 | + return ret; |
| 188 | + |
| 189 | + res = (struct mt7915_smesh_event *) skb->data; |
| 190 | + |
| 191 | + if (!value) |
| 192 | + return -EINVAL; |
| 193 | + |
| 194 | + *value = res->value; |
| 195 | + |
| 196 | + dev_kfree_skb(skb); |
| 197 | + |
| 198 | + return 0; |
| 199 | +} |
| 200 | + |
| 201 | +static int |
| 202 | +mt7915_vendor_amnt_muar(struct mt7915_phy *phy, u8 muar_idx, u8 *addr) |
| 203 | +{ |
| 204 | + struct mt7915_dev *dev = phy->dev; |
| 205 | + struct { |
| 206 | + u8 mode; |
| 207 | + u8 force_clear; |
| 208 | + u8 clear_bitmap[8]; |
| 209 | + u8 entry_count; |
| 210 | + u8 write; |
| 211 | + u8 band; |
| 212 | + |
| 213 | + u8 index; |
| 214 | + u8 bssid; |
| 215 | + u8 addr[ETH_ALEN]; |
| 216 | + } __packed req = { |
| 217 | + .entry_count = 1, |
| 218 | + .write = 1, |
| 219 | + .band = phy != &dev->phy, |
| 220 | + .index = muar_idx, |
| 221 | + }; |
| 222 | + |
| 223 | + ether_addr_copy(req.addr, addr); |
| 224 | + |
| 225 | + return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MUAR_UPDATE), &req, |
| 226 | + sizeof(req), true); |
| 227 | +} |
| 228 | + |
| 229 | +static int |
| 230 | +mt7915_vendor_amnt_set_en(struct mt7915_phy *phy, u8 enable) |
| 231 | +{ |
| 232 | + u32 status; |
| 233 | + int ret; |
| 234 | + |
| 235 | + ret = mt7915_vendor_smesh_ctrl(phy, 0, enable, &status); |
| 236 | + if (ret) |
| 237 | + return ret; |
| 238 | + |
| 239 | + status = status & 0xff; |
| 240 | + |
| 241 | + if (status == enable) |
| 242 | + return 0; |
| 243 | + |
| 244 | + ret = mt7915_vendor_smesh_ctrl(phy, 1, enable, &status); |
| 245 | + if (ret) |
| 246 | + return ret; |
| 247 | + |
| 248 | + return 0; |
| 249 | +} |
| 250 | + |
| 251 | +static int |
| 252 | +mt7915_vendor_amnt_set_addr(struct mt7915_phy *phy, u8 index, u8 *addr) |
| 253 | +{ |
| 254 | + struct mt7915_air_monitor_ctrl *amnt_ctrl = &phy->amnt_ctrl; |
| 255 | + struct mt7915_air_monitor_group *group; |
| 256 | + struct mt7915_air_monitor_entry *entry = &amnt_ctrl->entry[index]; |
| 257 | + const u8 zero_addr[ETH_ALEN] = {}; |
| 258 | + int enable = !ether_addr_equal(addr, zero_addr); |
| 259 | + int ret, i, j; |
| 260 | + |
| 261 | + if (enable == 1 && entry->enable == 1) { |
| 262 | + ether_addr_copy(entry->addr, addr); |
| 263 | + } else if (enable == 1 && entry->enable == 0){ |
| 264 | + for (i = 0; i < MT7915_AIR_MONITOR_MAX_GROUP; i++) { |
| 265 | + group = &(amnt_ctrl->group[i]); |
| 266 | + if (group->used[0] == 0) |
| 267 | + j = 0; |
| 268 | + else |
| 269 | + j = 1; |
| 270 | + |
| 271 | + group->enable = 1; |
| 272 | + group->used[j] = 1; |
| 273 | + entry->enable = 1; |
| 274 | + entry->group_idx = i; |
| 275 | + entry->group_used_idx = j; |
| 276 | + entry->muar_idx = 32 + 2 * i + 2 * i + 2 * j; |
| 277 | + ether_addr_copy(entry->addr, addr); |
| 278 | + break; |
| 279 | + } |
| 280 | + } else { |
| 281 | + group = &(amnt_ctrl->group[entry->group_idx]); |
| 282 | + |
| 283 | + group->used[entry->group_used_idx] = 0; |
| 284 | + if (group->used[0] == 0 && group->used[1] == 0) |
| 285 | + group->enable = 0; |
| 286 | + |
| 287 | + entry->enable = 0; |
| 288 | + ether_addr_copy(entry->addr, addr); |
| 289 | + } |
| 290 | + |
| 291 | + amnt_ctrl->enable &= ~(1 << entry->group_idx); |
| 292 | + amnt_ctrl->enable |= entry->enable << entry->group_idx; |
| 293 | + ret = mt7915_vendor_amnt_muar(phy, entry->muar_idx, addr); |
| 294 | + if (ret) |
| 295 | + return ret; |
| 296 | + |
| 297 | + return mt7915_vendor_amnt_set_en(phy, amnt_ctrl->enable); |
| 298 | +} |
| 299 | + |
| 300 | +void mt7915_vendor_amnt_fill_rx(struct mt7915_phy *phy, struct sk_buff *skb) |
| 301 | +{ |
| 302 | + struct mt76_rx_status *status = (struct mt76_rx_status *)skb->cb; |
| 303 | + struct mt7915_air_monitor_ctrl *ctrl = &phy->amnt_ctrl; |
| 304 | + struct ieee80211_hdr *hdr = mt76_skb_get_hdr(skb); |
| 305 | + __le16 fc = hdr->frame_control; |
| 306 | + u8 addr[ETH_ALEN]; |
| 307 | + int i; |
| 308 | + |
| 309 | + if (!ieee80211_has_fromds(fc)) |
| 310 | + ether_addr_copy(addr, hdr->addr2); |
| 311 | + else if (ieee80211_has_tods(fc)) |
| 312 | + ether_addr_copy(addr, hdr->addr4); |
| 313 | + else |
| 314 | + ether_addr_copy(addr, hdr->addr3); |
| 315 | + |
| 316 | + for (i = 0; i < MT7915_AIR_MONITOR_MAX_ENTRY; i++) { |
| 317 | + struct mt7915_air_monitor_entry *entry; |
| 318 | + |
| 319 | + if (ether_addr_equal(addr, ctrl->entry[i].addr)) { |
| 320 | + entry = &ctrl->entry[i]; |
| 321 | + entry->rssi[0] = status->chain_signal[0]; |
| 322 | + entry->rssi[1] = status->chain_signal[1]; |
| 323 | + entry->rssi[2] = status->chain_signal[2]; |
| 324 | + entry->rssi[3] = status->chain_signal[3]; |
| 325 | + entry->last_seen = jiffies; |
| 326 | + } |
| 327 | + } |
| 328 | + |
| 329 | + if (ieee80211_has_tods(fc) && |
| 330 | + !ether_addr_equal(hdr->addr3, phy->mt76->macaddr)) |
| 331 | + return; |
| 332 | + else if (!ether_addr_equal(hdr->addr1, phy->mt76->macaddr)) |
| 333 | + return; |
| 334 | +} |
| 335 | + |
| 336 | +int mt7915_vendor_amnt_sta_remove(struct mt7915_phy *phy, |
| 337 | + struct ieee80211_sta *sta) |
| 338 | +{ |
| 339 | + u8 zero[ETH_ALEN] = {}; |
| 340 | + int i; |
| 341 | + |
| 342 | + if (!phy->amnt_ctrl.enable) |
| 343 | + return 0; |
| 344 | + |
| 345 | + for (i = 0; i < MT7915_AIR_MONITOR_MAX_ENTRY; i++) |
| 346 | + if (ether_addr_equal(sta->addr, phy->amnt_ctrl.entry[i].addr)) |
| 347 | + return mt7915_vendor_amnt_set_addr(phy, i, zero); |
| 348 | + |
| 349 | + return 0; |
| 350 | +} |
| 351 | + |
| 352 | +static int |
| 353 | +mt7915_vendor_amnt_ctrl(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 354 | + const void *data, int data_len) |
| 355 | +{ |
| 356 | + struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 357 | + struct mt7915_phy *phy = mt7915_hw_phy(hw); |
| 358 | + struct nlattr *tb1[NUM_MTK_VENDOR_ATTRS_AMNT_CTRL]; |
| 359 | + struct nlattr *tb2[NUM_MTK_VENDOR_ATTRS_AMNT_SET]; |
| 360 | + struct nlattr *cur; |
| 361 | + u8 index = 0, i = 0; |
| 362 | + u8 mac_addr[ETH_ALEN] = {}; |
| 363 | + int err, rem; |
| 364 | + |
| 365 | + err = nla_parse(tb1, MTK_VENDOR_ATTR_AMNT_CTRL_MAX, data, data_len, |
| 366 | + amnt_ctrl_policy, NULL); |
| 367 | + if (err) |
| 368 | + return err; |
| 369 | + |
| 370 | + if (!tb1[MTK_VENDOR_ATTR_AMNT_CTRL_SET]) |
| 371 | + return -EINVAL; |
| 372 | + |
| 373 | + err = nla_parse_nested(tb2, MTK_VENDOR_ATTR_AMNT_SET_MAX, |
| 374 | + tb1[MTK_VENDOR_ATTR_AMNT_CTRL_SET], amnt_set_policy, NULL); |
| 375 | + |
| 376 | + if (!tb2[MTK_VENDOR_ATTR_AMNT_SET_INDEX] || |
| 377 | + !tb2[MTK_VENDOR_ATTR_AMNT_SET_MACADDR]) |
| 378 | + return -EINVAL; |
| 379 | + |
| 380 | + index = nla_get_u8(tb2[MTK_VENDOR_ATTR_AMNT_SET_INDEX]); |
| 381 | + nla_for_each_nested(cur, tb2[MTK_VENDOR_ATTR_AMNT_SET_MACADDR], rem) { |
| 382 | + mac_addr[i++] = nla_get_u8(cur); |
| 383 | + } |
| 384 | + |
| 385 | + return mt7915_vendor_amnt_set_addr(phy, index, mac_addr); |
| 386 | +} |
| 387 | + |
| 388 | +static int |
| 389 | +mt7915_amnt_dump(struct mt7915_phy *phy, struct sk_buff *skb, |
| 390 | + u8 amnt_idx, int *attrtype) |
| 391 | +{ |
| 392 | + struct mt7915_air_monitor_entry *entry = |
| 393 | + &phy->amnt_ctrl.entry[amnt_idx]; |
| 394 | + struct mt7915_amnt_data data; |
| 395 | + u32 last_seen = 0; |
| 396 | + |
| 397 | + if (entry->enable == 0) |
| 398 | + return 0; |
| 399 | + |
| 400 | + last_seen = jiffies_to_msecs(jiffies - entry->last_seen); |
| 401 | + |
| 402 | + data.idx = amnt_idx; |
| 403 | + ether_addr_copy(data.addr, entry->addr); |
| 404 | + data.rssi[0] = entry->rssi[0]; |
| 405 | + data.rssi[1] = entry->rssi[1]; |
| 406 | + data.rssi[2] = entry->rssi[2]; |
| 407 | + data.rssi[3] = entry->rssi[3]; |
| 408 | + data.last_seen = last_seen; |
| 409 | + |
| 410 | + nla_put(skb, (*attrtype)++, sizeof(struct mt7915_amnt_data), &data); |
| 411 | + |
| 412 | + return 1; |
| 413 | +} |
| 414 | + |
| 415 | +static int |
| 416 | +mt7915_vendor_amnt_ctrl_dump(struct wiphy *wiphy, struct wireless_dev *wdev, |
| 417 | + struct sk_buff *skb, const void *data, int data_len, |
| 418 | + unsigned long *storage) |
| 419 | +{ |
| 420 | + struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
| 421 | + struct mt7915_phy *phy = mt7915_hw_phy(hw); |
| 422 | + struct nlattr *tb1[NUM_MTK_VENDOR_ATTRS_AMNT_CTRL]; |
| 423 | + struct nlattr *tb2[NUM_MTK_VENDOR_ATTRS_AMNT_DUMP]; |
| 424 | + void *a, *b; |
| 425 | + int err = 0, attrtype = 0, i, len = 0; |
| 426 | + u8 amnt_idx; |
| 427 | + |
| 428 | + if (*storage == 1) |
| 429 | + return -ENOENT; |
| 430 | + *storage = 1; |
| 431 | + |
| 432 | + err = nla_parse(tb1, MTK_VENDOR_ATTR_AMNT_CTRL_MAX, data, data_len, |
| 433 | + amnt_ctrl_policy, NULL); |
| 434 | + if (err) |
| 435 | + return err; |
| 436 | + |
| 437 | + if (!tb1[MTK_VENDOR_ATTR_AMNT_CTRL_DUMP]) |
| 438 | + return -EINVAL; |
| 439 | + |
| 440 | + err = nla_parse_nested(tb2, MTK_VENDOR_ATTR_AMNT_DUMP_MAX, |
| 441 | + tb1[MTK_VENDOR_ATTR_AMNT_CTRL_DUMP], |
| 442 | + amnt_dump_policy, NULL); |
| 443 | + if (err) |
| 444 | + return err; |
| 445 | + |
| 446 | + if (!tb2[MTK_VENDOR_ATTR_AMNT_DUMP_INDEX]) |
| 447 | + return -EINVAL; |
| 448 | + |
| 449 | + amnt_idx = nla_get_u8(tb2[MTK_VENDOR_ATTR_AMNT_DUMP_INDEX]); |
| 450 | + |
| 451 | + a = nla_nest_start(skb, MTK_VENDOR_ATTR_AMNT_CTRL_DUMP); |
| 452 | + b = nla_nest_start(skb, MTK_VENDOR_ATTR_AMNT_DUMP_RESULT); |
| 453 | + |
| 454 | + if (amnt_idx != 0xff) { |
| 455 | + len += mt7915_amnt_dump(phy, skb, amnt_idx, &attrtype); |
| 456 | + } else { |
| 457 | + for (i = 0; i < MT7915_AIR_MONITOR_MAX_ENTRY; i++) { |
| 458 | + len += mt7915_amnt_dump(phy, skb, i, &attrtype); |
| 459 | + } |
| 460 | + } |
| 461 | + |
| 462 | + nla_nest_end(skb, b); |
| 463 | + |
| 464 | + nla_put_u8(skb, MTK_VENDOR_ATTR_AMNT_DUMP_LEN, len); |
| 465 | + |
| 466 | + nla_nest_end(skb, a); |
| 467 | + |
| 468 | + return len + 1; |
| 469 | +} |
| 470 | + |
| 471 | static const struct wiphy_vendor_command mt7915_vendor_commands[] = { |
| 472 | { |
| 473 | .info = { |
| 474 | @@ -442,6 +789,18 @@ static const struct wiphy_vendor_command mt7915_vendor_commands[] = { |
| 475 | .dumpit = mt7915_vendor_csi_ctrl_dump, |
| 476 | .policy = csi_ctrl_policy, |
| 477 | .maxattr = MTK_VENDOR_ATTR_CSI_CTRL_MAX, |
| 478 | + }, |
| 479 | + { |
| 480 | + .info = { |
| 481 | + .vendor_id = MTK_NL80211_VENDOR_ID, |
| 482 | + .subcmd = MTK_NL80211_VENDOR_SUBCMD_AMNT_CTRL, |
| 483 | + }, |
| 484 | + .flags = WIPHY_VENDOR_CMD_NEED_NETDEV | |
| 485 | + WIPHY_VENDOR_CMD_NEED_RUNNING, |
| 486 | + .doit = mt7915_vendor_amnt_ctrl, |
| 487 | + .dumpit = mt7915_vendor_amnt_ctrl_dump, |
| 488 | + .policy = amnt_ctrl_policy, |
| 489 | + .maxattr = MTK_VENDOR_ATTR_AMNT_CTRL_MAX, |
| 490 | } |
| 491 | }; |
| 492 | |
| 493 | diff --git a/mt7915/vendor.h b/mt7915/vendor.h |
developer | c04f540 | 2023-02-03 09:22:26 +0800 | [diff] [blame] | 494 | index 9d3db2a7..976817f3 100644 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 495 | --- a/mt7915/vendor.h |
| 496 | +++ b/mt7915/vendor.h |
| 497 | @@ -4,6 +4,7 @@ |
| 498 | #define MTK_NL80211_VENDOR_ID 0x0ce7 |
| 499 | |
| 500 | enum mtk_nl80211_vendor_subcmds { |
| 501 | + MTK_NL80211_VENDOR_SUBCMD_AMNT_CTRL = 0xae, |
| 502 | MTK_NL80211_VENDOR_SUBCMD_CSI_CTRL = 0xc2, |
| 503 | }; |
| 504 | |
| 505 | @@ -57,4 +58,41 @@ enum mtk_vendor_attr_csi_data { |
| 506 | NUM_MTK_VENDOR_ATTRS_CSI_DATA - 1 |
| 507 | }; |
| 508 | |
| 509 | +enum mtk_vendor_attr_mnt_ctrl { |
| 510 | + MTK_VENDOR_ATTR_AMNT_CTRL_UNSPEC, |
| 511 | + |
| 512 | + MTK_VENDOR_ATTR_AMNT_CTRL_SET, |
| 513 | + MTK_VENDOR_ATTR_AMNT_CTRL_DUMP, |
| 514 | + |
| 515 | + /* keep last */ |
| 516 | + NUM_MTK_VENDOR_ATTRS_AMNT_CTRL, |
| 517 | + MTK_VENDOR_ATTR_AMNT_CTRL_MAX = |
| 518 | + NUM_MTK_VENDOR_ATTRS_AMNT_CTRL - 1 |
| 519 | +}; |
| 520 | + |
| 521 | +enum mtk_vendor_attr_mnt_set { |
| 522 | + MTK_VENDOR_ATTR_AMNT_SET_UNSPEC, |
| 523 | + |
| 524 | + MTK_VENDOR_ATTR_AMNT_SET_INDEX, |
| 525 | + MTK_VENDOR_ATTR_AMNT_SET_MACADDR, |
| 526 | + |
| 527 | + /* keep last */ |
| 528 | + NUM_MTK_VENDOR_ATTRS_AMNT_SET, |
| 529 | + MTK_VENDOR_ATTR_AMNT_SET_MAX = |
| 530 | + NUM_MTK_VENDOR_ATTRS_AMNT_SET - 1 |
| 531 | +}; |
| 532 | + |
| 533 | +enum mtk_vendor_attr_mnt_dump { |
| 534 | + MTK_VENDOR_ATTR_AMNT_DUMP_UNSPEC, |
| 535 | + |
| 536 | + MTK_VENDOR_ATTR_AMNT_DUMP_INDEX, |
| 537 | + MTK_VENDOR_ATTR_AMNT_DUMP_LEN, |
| 538 | + MTK_VENDOR_ATTR_AMNT_DUMP_RESULT, |
| 539 | + |
| 540 | + /* keep last */ |
| 541 | + NUM_MTK_VENDOR_ATTRS_AMNT_DUMP, |
| 542 | + MTK_VENDOR_ATTR_AMNT_DUMP_MAX = |
| 543 | + NUM_MTK_VENDOR_ATTRS_AMNT_DUMP - 1 |
| 544 | +}; |
| 545 | + |
| 546 | #endif |
| 547 | -- |
developer | c923344 | 2023-04-04 06:06:17 +0800 | [diff] [blame] | 548 | 2.39.0 |
developer | e2cc0fa | 2022-03-29 17:31:03 +0800 | [diff] [blame] | 549 | |