developer | 0f312e8 | 2022-11-01 12:31:52 +0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: ISC |
| 2 | /* Copyright (C) 2020 MediaTek Inc. */ |
| 3 | |
| 4 | #include <linux/fs.h> |
| 5 | #include "mt7915.h" |
| 6 | #include "mcu.h" |
| 7 | #include "mac.h" |
| 8 | #include "eeprom.h" |
| 9 | |
| 10 | #define fw_name(_dev, name, ...) ({ \ |
| 11 | char *_fw; \ |
| 12 | switch (mt76_chip(&(_dev)->mt76)) { \ |
| 13 | case 0x7915: \ |
| 14 | _fw = MT7915_##name; \ |
| 15 | break; \ |
| 16 | case 0x7986: \ |
| 17 | _fw = MT7986_##name##__VA_ARGS__; \ |
| 18 | break; \ |
| 19 | default: \ |
| 20 | _fw = MT7916_##name; \ |
| 21 | break; \ |
| 22 | } \ |
| 23 | _fw; \ |
| 24 | }) |
| 25 | |
| 26 | #define fw_name_var(_dev, name) (mt7915_check_adie(dev, false) ? \ |
| 27 | fw_name(_dev, name) : \ |
| 28 | fw_name(_dev, name, _MT7975)) |
| 29 | |
| 30 | #define MCU_PATCH_ADDRESS 0x200000 |
| 31 | |
| 32 | #define HE_PHY(p, c) u8_get_bits(c, IEEE80211_HE_PHY_##p) |
| 33 | #define HE_MAC(m, c) u8_get_bits(c, IEEE80211_HE_MAC_##m) |
| 34 | |
| 35 | static u8 |
| 36 | mt7915_mcu_get_sta_nss(u16 mcs_map) |
| 37 | { |
| 38 | u8 nss; |
| 39 | |
| 40 | for (nss = 8; nss > 0; nss--) { |
| 41 | u8 nss_mcs = (mcs_map >> (2 * (nss - 1))) & 3; |
| 42 | |
| 43 | if (nss_mcs != IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 44 | break; |
| 45 | } |
| 46 | |
| 47 | return nss - 1; |
| 48 | } |
| 49 | |
| 50 | static void |
| 51 | mt7915_mcu_set_sta_he_mcs(struct ieee80211_sta *sta, __le16 *he_mcs, |
| 52 | u16 mcs_map) |
| 53 | { |
| 54 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 55 | struct mt7915_dev *dev = msta->vif->phy->dev; |
| 56 | enum nl80211_band band = msta->vif->phy->mt76->chandef.chan->band; |
| 57 | const u16 *mask = msta->vif->bitrate_mask.control[band].he_mcs; |
| 58 | int nss, max_nss = sta->rx_nss > 3 ? 4 : sta->rx_nss; |
| 59 | |
| 60 | for (nss = 0; nss < max_nss; nss++) { |
| 61 | int mcs; |
| 62 | |
| 63 | switch ((mcs_map >> (2 * nss)) & 0x3) { |
| 64 | case IEEE80211_HE_MCS_SUPPORT_0_11: |
| 65 | mcs = GENMASK(11, 0); |
| 66 | break; |
| 67 | case IEEE80211_HE_MCS_SUPPORT_0_9: |
| 68 | mcs = GENMASK(9, 0); |
| 69 | break; |
| 70 | case IEEE80211_HE_MCS_SUPPORT_0_7: |
| 71 | mcs = GENMASK(7, 0); |
| 72 | break; |
| 73 | default: |
| 74 | mcs = 0; |
| 75 | } |
| 76 | |
| 77 | mcs = mcs ? fls(mcs & mask[nss]) - 1 : -1; |
| 78 | |
| 79 | switch (mcs) { |
| 80 | case 0 ... 7: |
| 81 | mcs = IEEE80211_HE_MCS_SUPPORT_0_7; |
| 82 | break; |
| 83 | case 8 ... 9: |
| 84 | mcs = IEEE80211_HE_MCS_SUPPORT_0_9; |
| 85 | break; |
| 86 | case 10 ... 11: |
| 87 | mcs = IEEE80211_HE_MCS_SUPPORT_0_11; |
| 88 | break; |
| 89 | default: |
| 90 | mcs = IEEE80211_HE_MCS_NOT_SUPPORTED; |
| 91 | break; |
| 92 | } |
| 93 | mcs_map &= ~(0x3 << (nss * 2)); |
| 94 | mcs_map |= mcs << (nss * 2); |
| 95 | |
| 96 | /* only support 2ss on 160MHz for mt7915 */ |
| 97 | if (is_mt7915(&dev->mt76) && nss > 1 && |
| 98 | sta->bandwidth == IEEE80211_STA_RX_BW_160) |
| 99 | break; |
| 100 | } |
| 101 | |
| 102 | *he_mcs = cpu_to_le16(mcs_map); |
| 103 | } |
| 104 | |
| 105 | static void |
| 106 | mt7915_mcu_set_sta_vht_mcs(struct ieee80211_sta *sta, __le16 *vht_mcs, |
| 107 | const u16 *mask) |
| 108 | { |
| 109 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 110 | struct mt7915_dev *dev = msta->vif->phy->dev; |
| 111 | u16 mcs_map = le16_to_cpu(sta->vht_cap.vht_mcs.rx_mcs_map); |
| 112 | int nss, max_nss = sta->rx_nss > 3 ? 4 : sta->rx_nss; |
| 113 | u16 mcs; |
| 114 | |
| 115 | for (nss = 0; nss < max_nss; nss++, mcs_map >>= 2) { |
| 116 | switch (mcs_map & 0x3) { |
| 117 | case IEEE80211_VHT_MCS_SUPPORT_0_9: |
| 118 | mcs = GENMASK(9, 0); |
| 119 | break; |
| 120 | case IEEE80211_VHT_MCS_SUPPORT_0_8: |
| 121 | mcs = GENMASK(8, 0); |
| 122 | break; |
| 123 | case IEEE80211_VHT_MCS_SUPPORT_0_7: |
| 124 | mcs = GENMASK(7, 0); |
| 125 | break; |
| 126 | default: |
| 127 | mcs = 0; |
| 128 | } |
| 129 | |
| 130 | vht_mcs[nss] = cpu_to_le16(mcs & mask[nss]); |
| 131 | |
| 132 | /* only support 2ss on 160MHz for mt7915 */ |
| 133 | if (is_mt7915(&dev->mt76) && nss > 1 && |
| 134 | sta->bandwidth == IEEE80211_STA_RX_BW_160) |
| 135 | break; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | static void |
| 140 | mt7915_mcu_set_sta_ht_mcs(struct ieee80211_sta *sta, u8 *ht_mcs, |
| 141 | const u8 *mask) |
| 142 | { |
| 143 | int nss, max_nss = sta->rx_nss > 3 ? 4 : sta->rx_nss; |
| 144 | |
| 145 | for (nss = 0; nss < max_nss; nss++) |
| 146 | ht_mcs[nss] = sta->ht_cap.mcs.rx_mask[nss] & mask[nss]; |
| 147 | } |
| 148 | |
| 149 | static int |
| 150 | mt7915_mcu_parse_response(struct mt76_dev *mdev, int cmd, |
| 151 | struct sk_buff *skb, int seq) |
| 152 | { |
| 153 | struct mt76_connac2_mcu_rxd *rxd; |
| 154 | int ret = 0; |
| 155 | |
| 156 | if (!skb) { |
| 157 | dev_err(mdev->dev, "Message %08x (seq %d) timeout\n", |
| 158 | cmd, seq); |
| 159 | return -ETIMEDOUT; |
| 160 | } |
| 161 | |
| 162 | rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| 163 | if (seq != rxd->seq) |
| 164 | return -EAGAIN; |
| 165 | |
| 166 | if (cmd == MCU_CMD(PATCH_SEM_CONTROL)) { |
| 167 | skb_pull(skb, sizeof(*rxd) - 4); |
| 168 | ret = *skb->data; |
| 169 | } else if (cmd == MCU_EXT_CMD(THERMAL_CTRL)) { |
| 170 | skb_pull(skb, sizeof(*rxd) + 4); |
| 171 | ret = le32_to_cpu(*(__le32 *)skb->data); |
| 172 | } else { |
| 173 | skb_pull(skb, sizeof(struct mt76_connac2_mcu_rxd)); |
| 174 | } |
| 175 | |
| 176 | return ret; |
| 177 | } |
| 178 | |
| 179 | static int |
| 180 | mt7915_mcu_send_message(struct mt76_dev *mdev, struct sk_buff *skb, |
| 181 | int cmd, int *wait_seq) |
| 182 | { |
| 183 | struct mt7915_dev *dev = container_of(mdev, struct mt7915_dev, mt76); |
| 184 | enum mt76_mcuq_id qid; |
| 185 | int ret; |
| 186 | |
| 187 | ret = mt76_connac2_mcu_fill_message(mdev, skb, cmd, wait_seq); |
| 188 | if (ret) |
| 189 | return ret; |
| 190 | |
| 191 | if (cmd == MCU_CMD(FW_SCATTER)) |
| 192 | qid = MT_MCUQ_FWDL; |
| 193 | else if (test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state)) |
| 194 | qid = MT_MCUQ_WA; |
| 195 | else |
| 196 | qid = MT_MCUQ_WM; |
| 197 | |
| 198 | return mt76_tx_queue_skb_raw(dev, mdev->q_mcu[qid], skb, 0); |
| 199 | } |
| 200 | |
| 201 | int mt7915_mcu_wa_cmd(struct mt7915_dev *dev, int cmd, u32 a1, u32 a2, u32 a3) |
| 202 | { |
| 203 | struct { |
| 204 | __le32 args[3]; |
| 205 | } req = { |
| 206 | .args = { |
| 207 | cpu_to_le32(a1), |
| 208 | cpu_to_le32(a2), |
| 209 | cpu_to_le32(a3), |
| 210 | }, |
| 211 | }; |
| 212 | |
| 213 | return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), false); |
| 214 | } |
| 215 | |
| 216 | static void |
| 217 | mt7915_mcu_csa_finish(void *priv, u8 *mac, struct ieee80211_vif *vif) |
| 218 | { |
| 219 | if (vif->csa_active) |
| 220 | ieee80211_csa_finish(vif); |
| 221 | } |
| 222 | |
| 223 | static void |
| 224 | mt7915_mcu_rx_csa_notify(struct mt7915_dev *dev, struct sk_buff *skb) |
| 225 | { |
| 226 | struct mt76_phy *mphy = &dev->mt76.phy; |
| 227 | struct mt7915_mcu_csa_notify *c; |
| 228 | |
| 229 | c = (struct mt7915_mcu_csa_notify *)skb->data; |
| 230 | |
| 231 | if ((c->band_idx && !dev->phy.band_idx) && dev->mt76.phys[MT_BAND1]) |
| 232 | mphy = dev->mt76.phys[MT_BAND1]; |
| 233 | |
| 234 | ieee80211_iterate_active_interfaces_atomic(mphy->hw, |
| 235 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 236 | mt7915_mcu_csa_finish, mphy->hw); |
| 237 | } |
| 238 | |
| 239 | static void |
| 240 | mt7915_mcu_rx_thermal_notify(struct mt7915_dev *dev, struct sk_buff *skb) |
| 241 | { |
| 242 | struct mt76_phy *mphy = &dev->mt76.phy; |
| 243 | struct mt7915_mcu_thermal_notify *t; |
| 244 | struct mt7915_phy *phy; |
| 245 | |
| 246 | t = (struct mt7915_mcu_thermal_notify *)skb->data; |
| 247 | if (t->ctrl.ctrl_id != THERMAL_PROTECT_ENABLE) |
| 248 | return; |
| 249 | |
| 250 | if ((t->ctrl.band_idx && !dev->phy.band_idx) && dev->mt76.phys[MT_BAND1]) |
| 251 | mphy = dev->mt76.phys[MT_BAND1]; |
| 252 | |
| 253 | phy = (struct mt7915_phy *)mphy->priv; |
| 254 | phy->throttle_state = t->ctrl.duty.duty_cycle; |
| 255 | } |
| 256 | |
| 257 | static void |
| 258 | mt7915_mcu_rx_radar_detected(struct mt7915_dev *dev, struct sk_buff *skb) |
| 259 | { |
| 260 | struct mt76_phy *mphy = &dev->mt76.phy; |
| 261 | struct mt7915_mcu_rdd_report *r; |
| 262 | |
| 263 | r = (struct mt7915_mcu_rdd_report *)skb->data; |
| 264 | |
| 265 | if ((r->band_idx && !dev->phy.band_idx) && dev->mt76.phys[MT_BAND1]) |
| 266 | mphy = dev->mt76.phys[MT_BAND1]; |
| 267 | |
| 268 | if (r->band_idx == MT_RX_SEL2) |
| 269 | cfg80211_background_radar_event(mphy->hw->wiphy, |
| 270 | &dev->rdd2_chandef, |
| 271 | GFP_ATOMIC); |
| 272 | else |
| 273 | ieee80211_radar_detected(mphy->hw); |
| 274 | dev->hw_pattern++; |
| 275 | } |
| 276 | |
| 277 | static void |
| 278 | mt7915_mcu_rx_log_message(struct mt7915_dev *dev, struct sk_buff *skb) |
| 279 | { |
| 280 | struct mt76_connac2_mcu_rxd *rxd; |
| 281 | int len = skb->len - sizeof(*rxd); |
| 282 | const char *data, *type; |
| 283 | |
| 284 | rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| 285 | data = (char *)&rxd[1]; |
| 286 | |
| 287 | switch (rxd->s2d_index) { |
| 288 | case 0: |
| 289 | if (mt7915_debugfs_rx_log(dev, data, len)) |
| 290 | return; |
| 291 | |
| 292 | type = "WM"; |
| 293 | break; |
| 294 | case 2: |
| 295 | type = "WA"; |
| 296 | break; |
| 297 | default: |
| 298 | type = "unknown"; |
| 299 | break; |
| 300 | } |
| 301 | |
| 302 | wiphy_info(mt76_hw(dev)->wiphy, "%s: %.*s", type, len, data); |
| 303 | } |
| 304 | |
| 305 | static void |
| 306 | mt7915_mcu_cca_finish(void *priv, u8 *mac, struct ieee80211_vif *vif) |
| 307 | { |
| 308 | if (!vif->color_change_active) |
| 309 | return; |
| 310 | |
| 311 | ieee80211_color_change_finish(vif); |
| 312 | } |
| 313 | |
| 314 | static void |
| 315 | mt7915_mcu_rx_bcc_notify(struct mt7915_dev *dev, struct sk_buff *skb) |
| 316 | { |
| 317 | struct mt76_phy *mphy = &dev->mt76.phy; |
| 318 | struct mt7915_mcu_bcc_notify *b; |
| 319 | |
| 320 | b = (struct mt7915_mcu_bcc_notify *)skb->data; |
| 321 | |
| 322 | if ((b->band_idx && !dev->phy.band_idx) && dev->mt76.phys[MT_BAND1]) |
| 323 | mphy = dev->mt76.phys[MT_BAND1]; |
| 324 | |
| 325 | ieee80211_iterate_active_interfaces_atomic(mphy->hw, |
| 326 | IEEE80211_IFACE_ITER_RESUME_ALL, |
| 327 | mt7915_mcu_cca_finish, mphy->hw); |
| 328 | } |
| 329 | |
| 330 | static void |
| 331 | mt7915_mcu_rx_ext_event(struct mt7915_dev *dev, struct sk_buff *skb) |
| 332 | { |
| 333 | struct mt76_connac2_mcu_rxd *rxd; |
| 334 | |
| 335 | rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| 336 | switch (rxd->ext_eid) { |
| 337 | case MCU_EXT_EVENT_THERMAL_PROTECT: |
| 338 | mt7915_mcu_rx_thermal_notify(dev, skb); |
| 339 | break; |
| 340 | case MCU_EXT_EVENT_RDD_REPORT: |
| 341 | mt7915_mcu_rx_radar_detected(dev, skb); |
| 342 | break; |
| 343 | case MCU_EXT_EVENT_CSA_NOTIFY: |
| 344 | mt7915_mcu_rx_csa_notify(dev, skb); |
| 345 | break; |
| 346 | case MCU_EXT_EVENT_FW_LOG_2_HOST: |
| 347 | mt7915_mcu_rx_log_message(dev, skb); |
| 348 | break; |
| 349 | case MCU_EXT_EVENT_BCC_NOTIFY: |
| 350 | mt7915_mcu_rx_bcc_notify(dev, skb); |
| 351 | break; |
| 352 | default: |
| 353 | break; |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | static void |
| 358 | mt7915_mcu_rx_unsolicited_event(struct mt7915_dev *dev, struct sk_buff *skb) |
| 359 | { |
| 360 | struct mt76_connac2_mcu_rxd *rxd; |
| 361 | |
| 362 | rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| 363 | switch (rxd->eid) { |
| 364 | case MCU_EVENT_EXT: |
| 365 | mt7915_mcu_rx_ext_event(dev, skb); |
| 366 | break; |
| 367 | default: |
| 368 | break; |
| 369 | } |
| 370 | dev_kfree_skb(skb); |
| 371 | } |
| 372 | |
| 373 | void mt7915_mcu_rx_event(struct mt7915_dev *dev, struct sk_buff *skb) |
| 374 | { |
| 375 | struct mt76_connac2_mcu_rxd *rxd; |
| 376 | |
| 377 | rxd = (struct mt76_connac2_mcu_rxd *)skb->data; |
| 378 | if (rxd->ext_eid == MCU_EXT_EVENT_THERMAL_PROTECT || |
| 379 | rxd->ext_eid == MCU_EXT_EVENT_FW_LOG_2_HOST || |
| 380 | rxd->ext_eid == MCU_EXT_EVENT_ASSERT_DUMP || |
| 381 | rxd->ext_eid == MCU_EXT_EVENT_PS_SYNC || |
| 382 | rxd->ext_eid == MCU_EXT_EVENT_BCC_NOTIFY || |
| 383 | !rxd->seq) |
| 384 | mt7915_mcu_rx_unsolicited_event(dev, skb); |
| 385 | else |
| 386 | mt76_mcu_rx_event(&dev->mt76, skb); |
| 387 | } |
| 388 | |
| 389 | static struct tlv * |
| 390 | mt7915_mcu_add_nested_subtlv(struct sk_buff *skb, int sub_tag, int sub_len, |
| 391 | __le16 *sub_ntlv, __le16 *len) |
| 392 | { |
| 393 | struct tlv *ptlv, tlv = { |
| 394 | .tag = cpu_to_le16(sub_tag), |
| 395 | .len = cpu_to_le16(sub_len), |
| 396 | }; |
| 397 | |
| 398 | ptlv = skb_put(skb, sub_len); |
| 399 | memcpy(ptlv, &tlv, sizeof(tlv)); |
| 400 | |
| 401 | le16_add_cpu(sub_ntlv, 1); |
| 402 | le16_add_cpu(len, sub_len); |
| 403 | |
| 404 | return ptlv; |
| 405 | } |
| 406 | |
| 407 | /** bss info **/ |
| 408 | struct mt7915_he_obss_narrow_bw_ru_data { |
| 409 | bool tolerated; |
| 410 | }; |
| 411 | |
| 412 | static void mt7915_check_he_obss_narrow_bw_ru_iter(struct wiphy *wiphy, |
| 413 | struct cfg80211_bss *bss, |
| 414 | void *_data) |
| 415 | { |
| 416 | struct mt7915_he_obss_narrow_bw_ru_data *data = _data; |
| 417 | const struct element *elem; |
| 418 | |
| 419 | rcu_read_lock(); |
| 420 | elem = ieee80211_bss_get_elem(bss, WLAN_EID_EXT_CAPABILITY); |
| 421 | |
| 422 | if (!elem || elem->datalen <= 10 || |
| 423 | !(elem->data[10] & |
| 424 | WLAN_EXT_CAPA10_OBSS_NARROW_BW_RU_TOLERANCE_SUPPORT)) |
| 425 | data->tolerated = false; |
| 426 | |
| 427 | rcu_read_unlock(); |
| 428 | } |
| 429 | |
| 430 | static bool mt7915_check_he_obss_narrow_bw_ru(struct ieee80211_hw *hw, |
| 431 | struct ieee80211_vif *vif) |
| 432 | { |
| 433 | struct mt7915_he_obss_narrow_bw_ru_data iter_data = { |
| 434 | .tolerated = true, |
| 435 | }; |
| 436 | |
| 437 | if (!(vif->bss_conf.chandef.chan->flags & IEEE80211_CHAN_RADAR)) |
| 438 | return false; |
| 439 | |
| 440 | cfg80211_bss_iter(hw->wiphy, &vif->bss_conf.chandef, |
| 441 | mt7915_check_he_obss_narrow_bw_ru_iter, |
| 442 | &iter_data); |
| 443 | |
| 444 | /* |
| 445 | * If there is at least one AP on radar channel that cannot |
| 446 | * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU. |
| 447 | */ |
| 448 | return !iter_data.tolerated; |
| 449 | } |
| 450 | |
| 451 | static void |
| 452 | mt7915_mcu_bss_rfch_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, |
| 453 | struct mt7915_phy *phy) |
| 454 | { |
| 455 | struct cfg80211_chan_def *chandef = &phy->mt76->chandef; |
| 456 | struct bss_info_rf_ch *ch; |
| 457 | struct tlv *tlv; |
| 458 | int freq1 = chandef->center_freq1; |
| 459 | |
| 460 | tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_RF_CH, sizeof(*ch)); |
| 461 | |
| 462 | ch = (struct bss_info_rf_ch *)tlv; |
| 463 | ch->pri_ch = chandef->chan->hw_value; |
| 464 | ch->center_ch0 = ieee80211_frequency_to_channel(freq1); |
| 465 | ch->bw = mt76_connac_chan_bw(chandef); |
| 466 | |
| 467 | if (chandef->width == NL80211_CHAN_WIDTH_80P80) { |
| 468 | int freq2 = chandef->center_freq2; |
| 469 | |
| 470 | ch->center_ch1 = ieee80211_frequency_to_channel(freq2); |
| 471 | } |
| 472 | |
| 473 | if (vif->bss_conf.he_support && vif->type == NL80211_IFTYPE_STATION) { |
| 474 | struct mt76_phy *mphy = phy->mt76; |
| 475 | |
| 476 | ch->he_ru26_block = |
| 477 | mt7915_check_he_obss_narrow_bw_ru(mphy->hw, vif); |
| 478 | ch->he_all_disable = false; |
| 479 | } else { |
| 480 | ch->he_all_disable = true; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | static void |
| 485 | mt7915_mcu_bss_ra_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, |
| 486 | struct mt7915_phy *phy) |
| 487 | { |
| 488 | int max_nss = hweight8(phy->mt76->antenna_mask); |
| 489 | struct bss_info_ra *ra; |
| 490 | struct tlv *tlv; |
| 491 | |
| 492 | tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_RA, sizeof(*ra)); |
| 493 | |
| 494 | ra = (struct bss_info_ra *)tlv; |
| 495 | ra->op_mode = vif->type == NL80211_IFTYPE_AP; |
| 496 | ra->adhoc_en = vif->type == NL80211_IFTYPE_ADHOC; |
| 497 | ra->short_preamble = true; |
| 498 | ra->tx_streams = max_nss; |
| 499 | ra->rx_streams = max_nss; |
| 500 | ra->algo = 4; |
| 501 | ra->train_up_rule = 2; |
| 502 | ra->train_up_high_thres = 110; |
| 503 | ra->train_up_rule_rssi = -70; |
| 504 | ra->low_traffic_thres = 2; |
| 505 | ra->phy_cap = cpu_to_le32(0xfdf); |
| 506 | ra->interval = cpu_to_le32(500); |
| 507 | ra->fast_interval = cpu_to_le32(100); |
| 508 | } |
| 509 | |
| 510 | static void |
| 511 | mt7915_mcu_bss_he_tlv(struct sk_buff *skb, struct ieee80211_vif *vif, |
| 512 | struct mt7915_phy *phy) |
| 513 | { |
| 514 | #define DEFAULT_HE_PE_DURATION 4 |
| 515 | #define DEFAULT_HE_DURATION_RTS_THRES 1023 |
| 516 | const struct ieee80211_sta_he_cap *cap; |
| 517 | struct bss_info_he *he; |
| 518 | struct tlv *tlv; |
| 519 | |
| 520 | cap = mt76_connac_get_he_phy_cap(phy->mt76, vif); |
| 521 | |
| 522 | tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_HE_BASIC, sizeof(*he)); |
| 523 | |
| 524 | he = (struct bss_info_he *)tlv; |
| 525 | he->he_pe_duration = vif->bss_conf.htc_trig_based_pkt_ext; |
| 526 | if (!he->he_pe_duration) |
| 527 | he->he_pe_duration = DEFAULT_HE_PE_DURATION; |
| 528 | |
| 529 | he->he_rts_thres = cpu_to_le16(vif->bss_conf.frame_time_rts_th); |
| 530 | if (!he->he_rts_thres) |
| 531 | he->he_rts_thres = cpu_to_le16(DEFAULT_HE_DURATION_RTS_THRES); |
| 532 | |
| 533 | he->max_nss_mcs[CMD_HE_MCS_BW80] = cap->he_mcs_nss_supp.tx_mcs_80; |
| 534 | he->max_nss_mcs[CMD_HE_MCS_BW160] = cap->he_mcs_nss_supp.tx_mcs_160; |
| 535 | he->max_nss_mcs[CMD_HE_MCS_BW8080] = cap->he_mcs_nss_supp.tx_mcs_80p80; |
| 536 | } |
| 537 | |
| 538 | static void |
| 539 | mt7915_mcu_bss_hw_amsdu_tlv(struct sk_buff *skb) |
| 540 | { |
| 541 | #define TXD_CMP_MAP1 GENMASK(15, 0) |
| 542 | #define TXD_CMP_MAP2 (GENMASK(31, 0) & ~BIT(23)) |
| 543 | struct bss_info_hw_amsdu *amsdu; |
| 544 | struct tlv *tlv; |
| 545 | |
| 546 | tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_HW_AMSDU, sizeof(*amsdu)); |
| 547 | |
| 548 | amsdu = (struct bss_info_hw_amsdu *)tlv; |
| 549 | amsdu->cmp_bitmap_0 = cpu_to_le32(TXD_CMP_MAP1); |
| 550 | amsdu->cmp_bitmap_1 = cpu_to_le32(TXD_CMP_MAP2); |
| 551 | amsdu->trig_thres = cpu_to_le16(2); |
| 552 | amsdu->enable = true; |
| 553 | } |
| 554 | |
| 555 | static void |
| 556 | mt7915_mcu_bss_bmc_tlv(struct sk_buff *skb, struct mt7915_phy *phy) |
| 557 | { |
| 558 | struct bss_info_bmc_rate *bmc; |
| 559 | struct cfg80211_chan_def *chandef = &phy->mt76->chandef; |
| 560 | enum nl80211_band band = chandef->chan->band; |
| 561 | struct tlv *tlv; |
| 562 | |
| 563 | tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_BMC_RATE, sizeof(*bmc)); |
| 564 | |
| 565 | bmc = (struct bss_info_bmc_rate *)tlv; |
| 566 | if (band == NL80211_BAND_2GHZ) { |
| 567 | bmc->short_preamble = true; |
| 568 | } else { |
| 569 | bmc->bc_trans = cpu_to_le16(0x2000); |
| 570 | bmc->mc_trans = cpu_to_le16(0x2080); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | static int |
| 575 | mt7915_mcu_muar_config(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 576 | bool bssid, bool enable) |
| 577 | { |
| 578 | struct mt7915_dev *dev = phy->dev; |
| 579 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 580 | u32 idx = mvif->mt76.omac_idx - REPEATER_BSSID_START; |
| 581 | u32 mask = phy->omac_mask >> 32 & ~BIT(idx); |
| 582 | const u8 *addr = vif->addr; |
| 583 | struct { |
| 584 | u8 mode; |
| 585 | u8 force_clear; |
| 586 | u8 clear_bitmap[8]; |
| 587 | u8 entry_count; |
| 588 | u8 write; |
| 589 | u8 band; |
| 590 | |
| 591 | u8 index; |
| 592 | u8 bssid; |
| 593 | u8 addr[ETH_ALEN]; |
| 594 | } __packed req = { |
| 595 | .mode = !!mask || enable, |
| 596 | .entry_count = 1, |
| 597 | .write = 1, |
| 598 | .band = phy != &dev->phy, |
| 599 | .index = idx * 2 + bssid, |
| 600 | }; |
| 601 | |
| 602 | if (bssid) |
| 603 | addr = vif->bss_conf.bssid; |
| 604 | |
| 605 | if (enable) |
| 606 | ether_addr_copy(req.addr, addr); |
| 607 | |
| 608 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MUAR_UPDATE), &req, |
| 609 | sizeof(req), true); |
| 610 | } |
| 611 | |
| 612 | int mt7915_mcu_add_bss_info(struct mt7915_phy *phy, |
| 613 | struct ieee80211_vif *vif, int enable) |
| 614 | { |
| 615 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 616 | struct mt7915_dev *dev = phy->dev; |
| 617 | struct sk_buff *skb; |
| 618 | |
| 619 | if (mvif->mt76.omac_idx >= REPEATER_BSSID_START) { |
| 620 | mt7915_mcu_muar_config(phy, vif, false, enable); |
| 621 | mt7915_mcu_muar_config(phy, vif, true, enable); |
| 622 | } |
| 623 | |
| 624 | skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, NULL, |
| 625 | MT7915_BSS_UPDATE_MAX_SIZE); |
| 626 | if (IS_ERR(skb)) |
| 627 | return PTR_ERR(skb); |
| 628 | |
| 629 | /* bss_omac must be first */ |
| 630 | if (enable) |
| 631 | mt76_connac_mcu_bss_omac_tlv(skb, vif); |
| 632 | |
| 633 | mt76_connac_mcu_bss_basic_tlv(skb, vif, NULL, phy->mt76, |
| 634 | mvif->sta.wcid.idx, enable); |
| 635 | |
| 636 | if (vif->type == NL80211_IFTYPE_MONITOR) |
| 637 | goto out; |
| 638 | |
| 639 | if (enable) { |
| 640 | mt7915_mcu_bss_rfch_tlv(skb, vif, phy); |
| 641 | mt7915_mcu_bss_bmc_tlv(skb, phy); |
| 642 | mt7915_mcu_bss_ra_tlv(skb, vif, phy); |
| 643 | mt7915_mcu_bss_hw_amsdu_tlv(skb); |
| 644 | |
| 645 | if (vif->bss_conf.he_support) |
| 646 | mt7915_mcu_bss_he_tlv(skb, vif, phy); |
| 647 | |
| 648 | if (mvif->mt76.omac_idx >= EXT_BSSID_START && |
| 649 | mvif->mt76.omac_idx < REPEATER_BSSID_START) |
| 650 | mt76_connac_mcu_bss_ext_tlv(skb, &mvif->mt76); |
| 651 | } |
| 652 | out: |
| 653 | return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 654 | MCU_EXT_CMD(BSS_INFO_UPDATE), true); |
| 655 | } |
| 656 | |
| 657 | /** starec & wtbl **/ |
| 658 | int mt7915_mcu_add_tx_ba(struct mt7915_dev *dev, |
| 659 | struct ieee80211_ampdu_params *params, |
| 660 | bool enable) |
| 661 | { |
| 662 | struct mt7915_sta *msta = (struct mt7915_sta *)params->sta->drv_priv; |
| 663 | struct mt7915_vif *mvif = msta->vif; |
| 664 | |
| 665 | if (enable && !params->amsdu) |
| 666 | msta->wcid.amsdu = false; |
| 667 | |
| 668 | return mt76_connac_mcu_sta_ba(&dev->mt76, &mvif->mt76, params, |
| 669 | MCU_EXT_CMD(STA_REC_UPDATE), |
| 670 | enable, true); |
| 671 | } |
| 672 | |
| 673 | int mt7915_mcu_add_rx_ba(struct mt7915_dev *dev, |
| 674 | struct ieee80211_ampdu_params *params, |
| 675 | bool enable) |
| 676 | { |
| 677 | struct mt7915_sta *msta = (struct mt7915_sta *)params->sta->drv_priv; |
| 678 | struct mt7915_vif *mvif = msta->vif; |
| 679 | |
| 680 | return mt76_connac_mcu_sta_ba(&dev->mt76, &mvif->mt76, params, |
| 681 | MCU_EXT_CMD(STA_REC_UPDATE), |
| 682 | enable, false); |
| 683 | } |
| 684 | |
| 685 | static void |
| 686 | mt7915_mcu_sta_he_tlv(struct sk_buff *skb, struct ieee80211_sta *sta, |
| 687 | struct ieee80211_vif *vif) |
| 688 | { |
| 689 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 690 | struct ieee80211_he_cap_elem *elem = &sta->he_cap.he_cap_elem; |
| 691 | struct ieee80211_he_mcs_nss_supp mcs_map; |
| 692 | struct sta_rec_he *he; |
| 693 | struct tlv *tlv; |
| 694 | u32 cap = 0; |
| 695 | |
| 696 | if (!sta->he_cap.has_he) |
| 697 | return; |
| 698 | |
| 699 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HE, sizeof(*he)); |
| 700 | |
| 701 | he = (struct sta_rec_he *)tlv; |
| 702 | |
| 703 | if (elem->mac_cap_info[0] & IEEE80211_HE_MAC_CAP0_HTC_HE) |
| 704 | cap |= STA_REC_HE_CAP_HTC; |
| 705 | |
| 706 | if (elem->mac_cap_info[2] & IEEE80211_HE_MAC_CAP2_BSR) |
| 707 | cap |= STA_REC_HE_CAP_BSR; |
| 708 | |
| 709 | if (elem->mac_cap_info[3] & IEEE80211_HE_MAC_CAP3_OMI_CONTROL) |
| 710 | cap |= STA_REC_HE_CAP_OM; |
| 711 | |
| 712 | if (elem->mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_AMSDU_IN_AMPDU) |
| 713 | cap |= STA_REC_HE_CAP_AMSDU_IN_AMPDU; |
| 714 | |
| 715 | if (elem->mac_cap_info[4] & IEEE80211_HE_MAC_CAP4_BQR) |
| 716 | cap |= STA_REC_HE_CAP_BQR; |
| 717 | |
| 718 | if (elem->phy_cap_info[0] & |
| 719 | (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G | |
| 720 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G)) |
| 721 | cap |= STA_REC_HE_CAP_BW20_RU242_SUPPORT; |
| 722 | |
| 723 | if (mvif->cap.he_ldpc && |
| 724 | (elem->phy_cap_info[1] & |
| 725 | IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD)) |
| 726 | cap |= STA_REC_HE_CAP_LDPC; |
| 727 | |
| 728 | if (elem->phy_cap_info[1] & |
| 729 | IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US) |
| 730 | cap |= STA_REC_HE_CAP_SU_PPDU_1LTF_8US_GI; |
| 731 | |
| 732 | if (elem->phy_cap_info[2] & |
| 733 | IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US) |
| 734 | cap |= STA_REC_HE_CAP_NDP_4LTF_3DOT2MS_GI; |
| 735 | |
| 736 | if (elem->phy_cap_info[2] & |
| 737 | IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ) |
| 738 | cap |= STA_REC_HE_CAP_LE_EQ_80M_TX_STBC; |
| 739 | |
| 740 | if (elem->phy_cap_info[2] & |
| 741 | IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ) |
| 742 | cap |= STA_REC_HE_CAP_LE_EQ_80M_RX_STBC; |
| 743 | |
| 744 | if (elem->phy_cap_info[6] & |
| 745 | IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB) |
| 746 | cap |= STA_REC_HE_CAP_TRIG_CQI_FK; |
| 747 | |
| 748 | if (elem->phy_cap_info[6] & |
| 749 | IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE) |
| 750 | cap |= STA_REC_HE_CAP_PARTIAL_BW_EXT_RANGE; |
| 751 | |
| 752 | if (elem->phy_cap_info[7] & |
| 753 | IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI) |
| 754 | cap |= STA_REC_HE_CAP_SU_MU_PPDU_4LTF_8US_GI; |
| 755 | |
| 756 | if (elem->phy_cap_info[7] & |
| 757 | IEEE80211_HE_PHY_CAP7_STBC_TX_ABOVE_80MHZ) |
| 758 | cap |= STA_REC_HE_CAP_GT_80M_TX_STBC; |
| 759 | |
| 760 | if (elem->phy_cap_info[7] & |
| 761 | IEEE80211_HE_PHY_CAP7_STBC_RX_ABOVE_80MHZ) |
| 762 | cap |= STA_REC_HE_CAP_GT_80M_RX_STBC; |
| 763 | |
| 764 | if (elem->phy_cap_info[8] & |
| 765 | IEEE80211_HE_PHY_CAP8_HE_ER_SU_PPDU_4XLTF_AND_08_US_GI) |
| 766 | cap |= STA_REC_HE_CAP_ER_SU_PPDU_4LTF_8US_GI; |
| 767 | |
| 768 | if (elem->phy_cap_info[8] & |
| 769 | IEEE80211_HE_PHY_CAP8_HE_ER_SU_1XLTF_AND_08_US_GI) |
| 770 | cap |= STA_REC_HE_CAP_ER_SU_PPDU_1LTF_8US_GI; |
| 771 | |
| 772 | if (elem->phy_cap_info[9] & |
| 773 | IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU) |
| 774 | cap |= STA_REC_HE_CAP_TX_1024QAM_UNDER_RU242; |
| 775 | |
| 776 | if (elem->phy_cap_info[9] & |
| 777 | IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU) |
| 778 | cap |= STA_REC_HE_CAP_RX_1024QAM_UNDER_RU242; |
| 779 | |
| 780 | he->he_cap = cpu_to_le32(cap); |
| 781 | |
| 782 | mcs_map = sta->he_cap.he_mcs_nss_supp; |
| 783 | switch (sta->bandwidth) { |
| 784 | case IEEE80211_STA_RX_BW_160: |
| 785 | if (elem->phy_cap_info[0] & |
| 786 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) |
| 787 | mt7915_mcu_set_sta_he_mcs(sta, |
| 788 | &he->max_nss_mcs[CMD_HE_MCS_BW8080], |
| 789 | le16_to_cpu(mcs_map.rx_mcs_80p80)); |
| 790 | |
| 791 | mt7915_mcu_set_sta_he_mcs(sta, |
| 792 | &he->max_nss_mcs[CMD_HE_MCS_BW160], |
| 793 | le16_to_cpu(mcs_map.rx_mcs_160)); |
| 794 | fallthrough; |
| 795 | default: |
| 796 | mt7915_mcu_set_sta_he_mcs(sta, |
| 797 | &he->max_nss_mcs[CMD_HE_MCS_BW80], |
| 798 | le16_to_cpu(mcs_map.rx_mcs_80)); |
| 799 | break; |
| 800 | } |
| 801 | |
| 802 | he->t_frame_dur = |
| 803 | HE_MAC(CAP1_TF_MAC_PAD_DUR_MASK, elem->mac_cap_info[1]); |
| 804 | he->max_ampdu_exp = |
| 805 | HE_MAC(CAP3_MAX_AMPDU_LEN_EXP_MASK, elem->mac_cap_info[3]); |
| 806 | |
| 807 | he->bw_set = |
| 808 | HE_PHY(CAP0_CHANNEL_WIDTH_SET_MASK, elem->phy_cap_info[0]); |
| 809 | he->device_class = |
| 810 | HE_PHY(CAP1_DEVICE_CLASS_A, elem->phy_cap_info[1]); |
| 811 | he->punc_pream_rx = |
| 812 | HE_PHY(CAP1_PREAMBLE_PUNC_RX_MASK, elem->phy_cap_info[1]); |
| 813 | |
| 814 | he->dcm_tx_mode = |
| 815 | HE_PHY(CAP3_DCM_MAX_CONST_TX_MASK, elem->phy_cap_info[3]); |
| 816 | he->dcm_tx_max_nss = |
| 817 | HE_PHY(CAP3_DCM_MAX_TX_NSS_2, elem->phy_cap_info[3]); |
| 818 | he->dcm_rx_mode = |
| 819 | HE_PHY(CAP3_DCM_MAX_CONST_RX_MASK, elem->phy_cap_info[3]); |
| 820 | he->dcm_rx_max_nss = |
| 821 | HE_PHY(CAP3_DCM_MAX_RX_NSS_2, elem->phy_cap_info[3]); |
| 822 | he->dcm_rx_max_nss = |
| 823 | HE_PHY(CAP8_DCM_MAX_RU_MASK, elem->phy_cap_info[8]); |
| 824 | |
| 825 | he->pkt_ext = 2; |
| 826 | } |
| 827 | |
| 828 | static void |
| 829 | mt7915_mcu_sta_muru_tlv(struct mt7915_dev *dev, struct sk_buff *skb, |
| 830 | struct ieee80211_sta *sta, struct ieee80211_vif *vif) |
| 831 | { |
| 832 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 833 | struct ieee80211_he_cap_elem *elem = &sta->he_cap.he_cap_elem; |
| 834 | struct sta_rec_muru *muru; |
| 835 | struct tlv *tlv; |
| 836 | |
| 837 | if (vif->type != NL80211_IFTYPE_STATION && |
| 838 | vif->type != NL80211_IFTYPE_AP) |
| 839 | return; |
| 840 | |
| 841 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_MURU, sizeof(*muru)); |
| 842 | |
| 843 | muru = (struct sta_rec_muru *)tlv; |
| 844 | |
| 845 | muru->cfg.mimo_dl_en = mvif->cap.he_mu_ebfer || |
| 846 | mvif->cap.vht_mu_ebfer || |
| 847 | mvif->cap.vht_mu_ebfee; |
| 848 | if (!is_mt7915(&dev->mt76)) |
| 849 | muru->cfg.mimo_ul_en = true; |
| 850 | muru->cfg.ofdma_dl_en = true; |
| 851 | |
| 852 | if (sta->vht_cap.vht_supported) |
| 853 | muru->mimo_dl.vht_mu_bfee = |
| 854 | !!(sta->vht_cap.cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 855 | |
| 856 | if (!sta->he_cap.has_he) |
| 857 | return; |
| 858 | |
| 859 | muru->mimo_dl.partial_bw_dl_mimo = |
| 860 | HE_PHY(CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO, elem->phy_cap_info[6]); |
| 861 | |
| 862 | muru->mimo_ul.full_ul_mimo = |
| 863 | HE_PHY(CAP2_UL_MU_FULL_MU_MIMO, elem->phy_cap_info[2]); |
| 864 | muru->mimo_ul.partial_ul_mimo = |
| 865 | HE_PHY(CAP2_UL_MU_PARTIAL_MU_MIMO, elem->phy_cap_info[2]); |
| 866 | |
| 867 | muru->ofdma_dl.punc_pream_rx = |
| 868 | HE_PHY(CAP1_PREAMBLE_PUNC_RX_MASK, elem->phy_cap_info[1]); |
| 869 | muru->ofdma_dl.he_20m_in_40m_2g = |
| 870 | HE_PHY(CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G, elem->phy_cap_info[8]); |
| 871 | muru->ofdma_dl.he_20m_in_160m = |
| 872 | HE_PHY(CAP8_20MHZ_IN_160MHZ_HE_PPDU, elem->phy_cap_info[8]); |
| 873 | muru->ofdma_dl.he_80m_in_160m = |
| 874 | HE_PHY(CAP8_80MHZ_IN_160MHZ_HE_PPDU, elem->phy_cap_info[8]); |
| 875 | |
| 876 | muru->ofdma_ul.t_frame_dur = |
| 877 | HE_MAC(CAP1_TF_MAC_PAD_DUR_MASK, elem->mac_cap_info[1]); |
| 878 | muru->ofdma_ul.mu_cascading = |
| 879 | HE_MAC(CAP2_MU_CASCADING, elem->mac_cap_info[2]); |
| 880 | muru->ofdma_ul.uo_ra = |
| 881 | HE_MAC(CAP3_OFDMA_RA, elem->mac_cap_info[3]); |
| 882 | } |
| 883 | |
| 884 | static void |
| 885 | mt7915_mcu_sta_ht_tlv(struct sk_buff *skb, struct ieee80211_sta *sta) |
| 886 | { |
| 887 | struct sta_rec_ht *ht; |
| 888 | struct tlv *tlv; |
| 889 | |
| 890 | if (!sta->ht_cap.ht_supported) |
| 891 | return; |
| 892 | |
| 893 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HT, sizeof(*ht)); |
| 894 | |
| 895 | ht = (struct sta_rec_ht *)tlv; |
| 896 | ht->ht_cap = cpu_to_le16(sta->ht_cap.cap); |
| 897 | } |
| 898 | |
| 899 | static void |
| 900 | mt7915_mcu_sta_vht_tlv(struct sk_buff *skb, struct ieee80211_sta *sta) |
| 901 | { |
| 902 | struct sta_rec_vht *vht; |
| 903 | struct tlv *tlv; |
| 904 | |
| 905 | if (!sta->vht_cap.vht_supported) |
| 906 | return; |
| 907 | |
| 908 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_VHT, sizeof(*vht)); |
| 909 | |
| 910 | vht = (struct sta_rec_vht *)tlv; |
| 911 | vht->vht_cap = cpu_to_le32(sta->vht_cap.cap); |
| 912 | vht->vht_rx_mcs_map = sta->vht_cap.vht_mcs.rx_mcs_map; |
| 913 | vht->vht_tx_mcs_map = sta->vht_cap.vht_mcs.tx_mcs_map; |
| 914 | } |
| 915 | |
| 916 | static void |
| 917 | mt7915_mcu_sta_amsdu_tlv(struct mt7915_dev *dev, struct sk_buff *skb, |
| 918 | struct ieee80211_vif *vif, struct ieee80211_sta *sta) |
| 919 | { |
| 920 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 921 | struct sta_rec_amsdu *amsdu; |
| 922 | struct tlv *tlv; |
| 923 | |
| 924 | if (vif->type != NL80211_IFTYPE_STATION && |
| 925 | vif->type != NL80211_IFTYPE_AP) |
| 926 | return; |
| 927 | |
| 928 | if (!sta->max_amsdu_len) |
| 929 | return; |
| 930 | |
| 931 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_HW_AMSDU, sizeof(*amsdu)); |
| 932 | amsdu = (struct sta_rec_amsdu *)tlv; |
| 933 | amsdu->max_amsdu_num = 8; |
| 934 | amsdu->amsdu_en = true; |
| 935 | msta->wcid.amsdu = true; |
| 936 | |
| 937 | switch (sta->max_amsdu_len) { |
| 938 | case IEEE80211_MAX_MPDU_LEN_VHT_11454: |
| 939 | if (!is_mt7915(&dev->mt76)) { |
| 940 | amsdu->max_mpdu_size = |
| 941 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454; |
| 942 | return; |
| 943 | } |
| 944 | fallthrough; |
| 945 | case IEEE80211_MAX_MPDU_LEN_HT_7935: |
| 946 | case IEEE80211_MAX_MPDU_LEN_VHT_7991: |
| 947 | amsdu->max_mpdu_size = IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991; |
| 948 | return; |
| 949 | default: |
| 950 | amsdu->max_mpdu_size = IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_3895; |
| 951 | return; |
| 952 | } |
| 953 | } |
| 954 | |
| 955 | static int |
| 956 | mt7915_mcu_sta_wtbl_tlv(struct mt7915_dev *dev, struct sk_buff *skb, |
| 957 | struct ieee80211_vif *vif, struct ieee80211_sta *sta) |
| 958 | { |
| 959 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 960 | struct mt7915_sta *msta; |
| 961 | struct wtbl_req_hdr *wtbl_hdr; |
| 962 | struct mt76_wcid *wcid; |
| 963 | struct tlv *tlv; |
| 964 | |
| 965 | msta = sta ? (struct mt7915_sta *)sta->drv_priv : &mvif->sta; |
| 966 | wcid = sta ? &msta->wcid : NULL; |
| 967 | |
| 968 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_WTBL, sizeof(struct tlv)); |
| 969 | wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(&dev->mt76, &msta->wcid, |
| 970 | WTBL_RESET_AND_SET, tlv, |
| 971 | &skb); |
| 972 | if (IS_ERR(wtbl_hdr)) |
| 973 | return PTR_ERR(wtbl_hdr); |
| 974 | |
| 975 | mt76_connac_mcu_wtbl_generic_tlv(&dev->mt76, skb, vif, sta, tlv, |
| 976 | wtbl_hdr); |
| 977 | mt76_connac_mcu_wtbl_hdr_trans_tlv(skb, vif, wcid, tlv, wtbl_hdr); |
| 978 | if (sta) |
| 979 | mt76_connac_mcu_wtbl_ht_tlv(&dev->mt76, skb, sta, tlv, |
| 980 | wtbl_hdr, mvif->cap.ht_ldpc, |
| 981 | mvif->cap.vht_ldpc); |
| 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
| 986 | static inline bool |
| 987 | mt7915_is_ebf_supported(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 988 | struct ieee80211_sta *sta, bool bfee) |
| 989 | { |
| 990 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 991 | int tx_ant = hweight8(phy->mt76->chainmask) - 1; |
| 992 | |
| 993 | if (vif->type != NL80211_IFTYPE_STATION && |
| 994 | vif->type != NL80211_IFTYPE_AP) |
| 995 | return false; |
| 996 | |
| 997 | if (!bfee && tx_ant < 2) |
| 998 | return false; |
| 999 | |
| 1000 | if (sta->he_cap.has_he) { |
| 1001 | struct ieee80211_he_cap_elem *pe = &sta->he_cap.he_cap_elem; |
| 1002 | |
| 1003 | if (bfee) |
| 1004 | return mvif->cap.he_su_ebfee && |
| 1005 | HE_PHY(CAP3_SU_BEAMFORMER, pe->phy_cap_info[3]); |
| 1006 | else |
| 1007 | return mvif->cap.he_su_ebfer && |
| 1008 | HE_PHY(CAP4_SU_BEAMFORMEE, pe->phy_cap_info[4]); |
| 1009 | } |
| 1010 | |
| 1011 | if (sta->vht_cap.vht_supported) { |
| 1012 | u32 cap = sta->vht_cap.cap; |
| 1013 | |
| 1014 | if (bfee) |
| 1015 | return mvif->cap.vht_su_ebfee && |
| 1016 | (cap & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); |
| 1017 | else |
| 1018 | return mvif->cap.vht_su_ebfer && |
| 1019 | (cap & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE); |
| 1020 | } |
| 1021 | |
| 1022 | return false; |
| 1023 | } |
| 1024 | |
| 1025 | static void |
| 1026 | mt7915_mcu_sta_sounding_rate(struct sta_rec_bf *bf) |
| 1027 | { |
| 1028 | bf->sounding_phy = MT_PHY_TYPE_OFDM; |
| 1029 | bf->ndp_rate = 0; /* mcs0 */ |
| 1030 | bf->ndpa_rate = MT7915_CFEND_RATE_DEFAULT; /* ofdm 24m */ |
| 1031 | bf->rept_poll_rate = MT7915_CFEND_RATE_DEFAULT; /* ofdm 24m */ |
| 1032 | } |
| 1033 | |
| 1034 | static void |
| 1035 | mt7915_mcu_sta_bfer_ht(struct ieee80211_sta *sta, struct mt7915_phy *phy, |
| 1036 | struct sta_rec_bf *bf) |
| 1037 | { |
| 1038 | struct ieee80211_mcs_info *mcs = &sta->ht_cap.mcs; |
| 1039 | u8 n = 0; |
| 1040 | |
| 1041 | bf->tx_mode = MT_PHY_TYPE_HT; |
| 1042 | |
| 1043 | if ((mcs->tx_params & IEEE80211_HT_MCS_TX_RX_DIFF) && |
| 1044 | (mcs->tx_params & IEEE80211_HT_MCS_TX_DEFINED)) |
| 1045 | n = FIELD_GET(IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK, |
| 1046 | mcs->tx_params); |
| 1047 | else if (mcs->rx_mask[3]) |
| 1048 | n = 3; |
| 1049 | else if (mcs->rx_mask[2]) |
| 1050 | n = 2; |
| 1051 | else if (mcs->rx_mask[1]) |
| 1052 | n = 1; |
| 1053 | |
| 1054 | bf->nrow = hweight8(phy->mt76->chainmask) - 1; |
| 1055 | bf->ncol = min_t(u8, bf->nrow, n); |
| 1056 | bf->ibf_ncol = n; |
| 1057 | } |
| 1058 | |
| 1059 | static void |
| 1060 | mt7915_mcu_sta_bfer_vht(struct ieee80211_sta *sta, struct mt7915_phy *phy, |
| 1061 | struct sta_rec_bf *bf, bool explicit) |
| 1062 | { |
| 1063 | struct ieee80211_sta_vht_cap *pc = &sta->vht_cap; |
| 1064 | struct ieee80211_sta_vht_cap *vc = &phy->mt76->sband_5g.sband.vht_cap; |
| 1065 | u16 mcs_map = le16_to_cpu(pc->vht_mcs.rx_mcs_map); |
| 1066 | u8 nss_mcs = mt7915_mcu_get_sta_nss(mcs_map); |
| 1067 | u8 tx_ant = hweight8(phy->mt76->chainmask) - 1; |
| 1068 | |
| 1069 | bf->tx_mode = MT_PHY_TYPE_VHT; |
| 1070 | |
| 1071 | if (explicit) { |
| 1072 | u8 sts, snd_dim; |
| 1073 | |
| 1074 | mt7915_mcu_sta_sounding_rate(bf); |
| 1075 | |
| 1076 | sts = FIELD_GET(IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK, |
| 1077 | pc->cap); |
| 1078 | snd_dim = FIELD_GET(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK, |
| 1079 | vc->cap); |
| 1080 | bf->nrow = min_t(u8, min_t(u8, snd_dim, sts), tx_ant); |
| 1081 | bf->ncol = min_t(u8, nss_mcs, bf->nrow); |
| 1082 | bf->ibf_ncol = bf->ncol; |
| 1083 | |
| 1084 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) |
| 1085 | bf->nrow = 1; |
| 1086 | } else { |
| 1087 | bf->nrow = tx_ant; |
| 1088 | bf->ncol = min_t(u8, nss_mcs, bf->nrow); |
| 1089 | bf->ibf_ncol = nss_mcs; |
| 1090 | |
| 1091 | if (sta->bandwidth == IEEE80211_STA_RX_BW_160) |
| 1092 | bf->ibf_nrow = 1; |
| 1093 | } |
| 1094 | } |
| 1095 | |
| 1096 | static void |
| 1097 | mt7915_mcu_sta_bfer_he(struct ieee80211_sta *sta, struct ieee80211_vif *vif, |
| 1098 | struct mt7915_phy *phy, struct sta_rec_bf *bf) |
| 1099 | { |
| 1100 | struct ieee80211_sta_he_cap *pc = &sta->he_cap; |
| 1101 | struct ieee80211_he_cap_elem *pe = &pc->he_cap_elem; |
| 1102 | const struct ieee80211_sta_he_cap *vc = |
| 1103 | mt76_connac_get_he_phy_cap(phy->mt76, vif); |
| 1104 | const struct ieee80211_he_cap_elem *ve = &vc->he_cap_elem; |
| 1105 | u16 mcs_map = le16_to_cpu(pc->he_mcs_nss_supp.rx_mcs_80); |
| 1106 | u8 nss_mcs = mt7915_mcu_get_sta_nss(mcs_map); |
| 1107 | u8 snd_dim, sts; |
| 1108 | |
| 1109 | bf->tx_mode = MT_PHY_TYPE_HE_SU; |
| 1110 | |
| 1111 | mt7915_mcu_sta_sounding_rate(bf); |
| 1112 | |
| 1113 | bf->trigger_su = HE_PHY(CAP6_TRIG_SU_BEAMFORMING_FB, |
| 1114 | pe->phy_cap_info[6]); |
| 1115 | bf->trigger_mu = HE_PHY(CAP6_TRIG_MU_BEAMFORMING_PARTIAL_BW_FB, |
| 1116 | pe->phy_cap_info[6]); |
| 1117 | snd_dim = HE_PHY(CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK, |
| 1118 | ve->phy_cap_info[5]); |
| 1119 | sts = HE_PHY(CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_MASK, |
| 1120 | pe->phy_cap_info[4]); |
| 1121 | bf->nrow = min_t(u8, snd_dim, sts); |
| 1122 | bf->ncol = min_t(u8, nss_mcs, bf->nrow); |
| 1123 | bf->ibf_ncol = bf->ncol; |
| 1124 | |
| 1125 | if (sta->bandwidth != IEEE80211_STA_RX_BW_160) |
| 1126 | return; |
| 1127 | |
| 1128 | /* go over for 160MHz and 80p80 */ |
| 1129 | if (pe->phy_cap_info[0] & |
| 1130 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G) { |
| 1131 | mcs_map = le16_to_cpu(pc->he_mcs_nss_supp.rx_mcs_160); |
| 1132 | nss_mcs = mt7915_mcu_get_sta_nss(mcs_map); |
| 1133 | |
| 1134 | bf->ncol_gt_bw80 = nss_mcs; |
| 1135 | } |
| 1136 | |
| 1137 | if (pe->phy_cap_info[0] & |
| 1138 | IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G) { |
| 1139 | mcs_map = le16_to_cpu(pc->he_mcs_nss_supp.rx_mcs_80p80); |
| 1140 | nss_mcs = mt7915_mcu_get_sta_nss(mcs_map); |
| 1141 | |
| 1142 | if (bf->ncol_gt_bw80) |
| 1143 | bf->ncol_gt_bw80 = min_t(u8, bf->ncol_gt_bw80, nss_mcs); |
| 1144 | else |
| 1145 | bf->ncol_gt_bw80 = nss_mcs; |
| 1146 | } |
| 1147 | |
| 1148 | snd_dim = HE_PHY(CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK, |
| 1149 | ve->phy_cap_info[5]); |
| 1150 | sts = HE_PHY(CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_MASK, |
| 1151 | pe->phy_cap_info[4]); |
| 1152 | |
| 1153 | bf->nrow_gt_bw80 = min_t(int, snd_dim, sts); |
| 1154 | } |
| 1155 | |
| 1156 | static void |
| 1157 | mt7915_mcu_sta_bfer_tlv(struct mt7915_dev *dev, struct sk_buff *skb, |
| 1158 | struct ieee80211_vif *vif, struct ieee80211_sta *sta) |
| 1159 | { |
| 1160 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1161 | struct mt7915_phy *phy = mvif->phy; |
| 1162 | int tx_ant = hweight8(phy->mt76->chainmask) - 1; |
| 1163 | struct sta_rec_bf *bf; |
| 1164 | struct tlv *tlv; |
| 1165 | const u8 matrix[4][4] = { |
| 1166 | {0, 0, 0, 0}, |
| 1167 | {1, 1, 0, 0}, /* 2x1, 2x2, 2x3, 2x4 */ |
| 1168 | {2, 4, 4, 0}, /* 3x1, 3x2, 3x3, 3x4 */ |
| 1169 | {3, 5, 6, 0} /* 4x1, 4x2, 4x3, 4x4 */ |
| 1170 | }; |
| 1171 | bool ebf; |
| 1172 | |
| 1173 | if (!(sta->ht_cap.ht_supported || sta->he_cap.has_he)) |
| 1174 | return; |
| 1175 | |
| 1176 | ebf = mt7915_is_ebf_supported(phy, vif, sta, false); |
| 1177 | if (!ebf && !dev->ibf) |
| 1178 | return; |
| 1179 | |
| 1180 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BF, sizeof(*bf)); |
| 1181 | bf = (struct sta_rec_bf *)tlv; |
| 1182 | |
| 1183 | /* he: eBF only, in accordance with spec |
| 1184 | * vht: support eBF and iBF |
| 1185 | * ht: iBF only, since mac80211 lacks of eBF support |
| 1186 | */ |
| 1187 | if (sta->he_cap.has_he && ebf) |
| 1188 | mt7915_mcu_sta_bfer_he(sta, vif, phy, bf); |
| 1189 | else if (sta->vht_cap.vht_supported) |
| 1190 | mt7915_mcu_sta_bfer_vht(sta, phy, bf, ebf); |
| 1191 | else if (sta->ht_cap.ht_supported) |
| 1192 | mt7915_mcu_sta_bfer_ht(sta, phy, bf); |
| 1193 | else |
| 1194 | return; |
| 1195 | |
| 1196 | bf->bf_cap = ebf ? ebf : dev->ibf << 1; |
| 1197 | bf->bw = sta->bandwidth; |
| 1198 | bf->ibf_dbw = sta->bandwidth; |
| 1199 | bf->ibf_nrow = tx_ant; |
| 1200 | |
| 1201 | if (!ebf && sta->bandwidth <= IEEE80211_STA_RX_BW_40 && !bf->ncol) |
| 1202 | bf->ibf_timeout = 0x48; |
| 1203 | else |
| 1204 | bf->ibf_timeout = 0x18; |
| 1205 | |
| 1206 | if (ebf && bf->nrow != tx_ant) |
| 1207 | bf->mem_20m = matrix[tx_ant][bf->ncol]; |
| 1208 | else |
| 1209 | bf->mem_20m = matrix[bf->nrow][bf->ncol]; |
| 1210 | |
| 1211 | switch (sta->bandwidth) { |
| 1212 | case IEEE80211_STA_RX_BW_160: |
| 1213 | case IEEE80211_STA_RX_BW_80: |
| 1214 | bf->mem_total = bf->mem_20m * 2; |
| 1215 | break; |
| 1216 | case IEEE80211_STA_RX_BW_40: |
| 1217 | bf->mem_total = bf->mem_20m; |
| 1218 | break; |
| 1219 | case IEEE80211_STA_RX_BW_20: |
| 1220 | default: |
| 1221 | break; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | static void |
| 1226 | mt7915_mcu_sta_bfee_tlv(struct mt7915_dev *dev, struct sk_buff *skb, |
| 1227 | struct ieee80211_vif *vif, struct ieee80211_sta *sta) |
| 1228 | { |
| 1229 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1230 | struct mt7915_phy *phy = mvif->phy; |
| 1231 | int tx_ant = hweight8(phy->mt76->chainmask) - 1; |
| 1232 | struct sta_rec_bfee *bfee; |
| 1233 | struct tlv *tlv; |
| 1234 | u8 nrow = 0; |
| 1235 | |
| 1236 | if (!(sta->vht_cap.vht_supported || sta->he_cap.has_he)) |
| 1237 | return; |
| 1238 | |
| 1239 | if (!mt7915_is_ebf_supported(phy, vif, sta, true)) |
| 1240 | return; |
| 1241 | |
| 1242 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_BFEE, sizeof(*bfee)); |
| 1243 | bfee = (struct sta_rec_bfee *)tlv; |
| 1244 | |
| 1245 | if (sta->he_cap.has_he) { |
| 1246 | struct ieee80211_he_cap_elem *pe = &sta->he_cap.he_cap_elem; |
| 1247 | |
| 1248 | nrow = HE_PHY(CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK, |
| 1249 | pe->phy_cap_info[5]); |
| 1250 | } else if (sta->vht_cap.vht_supported) { |
| 1251 | struct ieee80211_sta_vht_cap *pc = &sta->vht_cap; |
| 1252 | |
| 1253 | nrow = FIELD_GET(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK, |
| 1254 | pc->cap); |
| 1255 | } |
| 1256 | |
| 1257 | /* reply with identity matrix to avoid 2x2 BF negative gain */ |
| 1258 | bfee->fb_identity_matrix = (nrow == 1 && tx_ant == 2); |
| 1259 | } |
| 1260 | |
| 1261 | static enum mcu_mmps_mode |
| 1262 | mt7915_mcu_get_mmps_mode(enum ieee80211_smps_mode smps) |
| 1263 | { |
| 1264 | switch (smps) { |
| 1265 | case IEEE80211_SMPS_OFF: |
| 1266 | return MCU_MMPS_DISABLE; |
| 1267 | case IEEE80211_SMPS_STATIC: |
| 1268 | return MCU_MMPS_STATIC; |
| 1269 | case IEEE80211_SMPS_DYNAMIC: |
| 1270 | return MCU_MMPS_DYNAMIC; |
| 1271 | default: |
| 1272 | return MCU_MMPS_DISABLE; |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | int mt7915_mcu_set_fixed_rate_ctrl(struct mt7915_dev *dev, |
| 1277 | struct ieee80211_vif *vif, |
| 1278 | struct ieee80211_sta *sta, |
| 1279 | void *data, u32 field) |
| 1280 | { |
| 1281 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1282 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 1283 | struct sta_phy *phy = data; |
| 1284 | struct sta_rec_ra_fixed *ra; |
| 1285 | struct sk_buff *skb; |
| 1286 | struct tlv *tlv; |
| 1287 | |
| 1288 | skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, |
| 1289 | &msta->wcid); |
| 1290 | if (IS_ERR(skb)) |
| 1291 | return PTR_ERR(skb); |
| 1292 | |
| 1293 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_RA_UPDATE, sizeof(*ra)); |
| 1294 | ra = (struct sta_rec_ra_fixed *)tlv; |
| 1295 | |
| 1296 | switch (field) { |
| 1297 | case RATE_PARAM_AUTO: |
| 1298 | break; |
| 1299 | case RATE_PARAM_FIXED: |
| 1300 | case RATE_PARAM_FIXED_MCS: |
| 1301 | case RATE_PARAM_FIXED_GI: |
| 1302 | case RATE_PARAM_FIXED_HE_LTF: |
| 1303 | if (phy) |
| 1304 | ra->phy = *phy; |
| 1305 | break; |
| 1306 | case RATE_PARAM_MMPS_UPDATE: |
| 1307 | ra->mmps_mode = mt7915_mcu_get_mmps_mode(sta->smps_mode); |
| 1308 | break; |
| 1309 | case RATE_PARAM_SPE_UPDATE: |
| 1310 | ra->spe_idx = *(u8 *)data; |
| 1311 | break; |
| 1312 | default: |
| 1313 | break; |
| 1314 | } |
| 1315 | ra->field = cpu_to_le32(field); |
| 1316 | |
| 1317 | return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 1318 | MCU_EXT_CMD(STA_REC_UPDATE), true); |
| 1319 | } |
| 1320 | |
| 1321 | int mt7915_mcu_add_smps(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 1322 | struct ieee80211_sta *sta) |
| 1323 | { |
| 1324 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1325 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 1326 | struct wtbl_req_hdr *wtbl_hdr; |
| 1327 | struct tlv *sta_wtbl; |
| 1328 | struct sk_buff *skb; |
| 1329 | int ret; |
| 1330 | |
| 1331 | skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, |
| 1332 | &msta->wcid); |
| 1333 | if (IS_ERR(skb)) |
| 1334 | return PTR_ERR(skb); |
| 1335 | |
| 1336 | sta_wtbl = mt76_connac_mcu_add_tlv(skb, STA_REC_WTBL, |
| 1337 | sizeof(struct tlv)); |
| 1338 | wtbl_hdr = mt76_connac_mcu_alloc_wtbl_req(&dev->mt76, &msta->wcid, |
| 1339 | WTBL_SET, sta_wtbl, &skb); |
| 1340 | if (IS_ERR(wtbl_hdr)) |
| 1341 | return PTR_ERR(wtbl_hdr); |
| 1342 | |
| 1343 | mt76_connac_mcu_wtbl_smps_tlv(skb, sta, sta_wtbl, wtbl_hdr); |
| 1344 | |
| 1345 | ret = mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 1346 | MCU_EXT_CMD(STA_REC_UPDATE), true); |
| 1347 | if (ret) |
| 1348 | return ret; |
| 1349 | |
| 1350 | return mt7915_mcu_set_fixed_rate_ctrl(dev, vif, sta, NULL, |
| 1351 | RATE_PARAM_MMPS_UPDATE); |
| 1352 | } |
| 1353 | |
| 1354 | static int |
| 1355 | mt7915_mcu_set_spe_idx(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 1356 | struct ieee80211_sta *sta) |
| 1357 | { |
| 1358 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1359 | struct mt76_phy *mphy = mvif->phy->mt76; |
| 1360 | u8 spe_idx = mt76_connac_spe_idx(mphy->antenna_mask); |
| 1361 | |
| 1362 | return mt7915_mcu_set_fixed_rate_ctrl(dev, vif, sta, &spe_idx, |
| 1363 | RATE_PARAM_SPE_UPDATE); |
| 1364 | } |
| 1365 | |
| 1366 | static int |
| 1367 | mt7915_mcu_add_rate_ctrl_fixed(struct mt7915_dev *dev, |
| 1368 | struct ieee80211_vif *vif, |
| 1369 | struct ieee80211_sta *sta) |
| 1370 | { |
| 1371 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1372 | struct cfg80211_chan_def *chandef = &mvif->phy->mt76->chandef; |
| 1373 | struct cfg80211_bitrate_mask *mask = &mvif->bitrate_mask; |
| 1374 | enum nl80211_band band = chandef->chan->band; |
| 1375 | struct sta_phy phy = {}; |
| 1376 | int ret, nrates = 0; |
| 1377 | |
| 1378 | #define __sta_phy_bitrate_mask_check(_mcs, _gi, _ht, _he) \ |
| 1379 | do { \ |
| 1380 | u8 i, gi = mask->control[band]._gi; \ |
| 1381 | gi = (_he) ? gi : gi == NL80211_TXRATE_FORCE_SGI; \ |
| 1382 | for (i = 0; i <= sta->bandwidth; i++) { \ |
| 1383 | phy.sgi |= gi << (i << (_he)); \ |
| 1384 | phy.he_ltf |= mask->control[band].he_ltf << (i << (_he));\ |
| 1385 | } \ |
| 1386 | for (i = 0; i < ARRAY_SIZE(mask->control[band]._mcs); i++) { \ |
| 1387 | if (!mask->control[band]._mcs[i]) \ |
| 1388 | continue; \ |
| 1389 | nrates += hweight16(mask->control[band]._mcs[i]); \ |
| 1390 | phy.mcs = ffs(mask->control[band]._mcs[i]) - 1; \ |
| 1391 | if (_ht) \ |
| 1392 | phy.mcs += 8 * i; \ |
| 1393 | } \ |
| 1394 | } while (0) |
| 1395 | |
| 1396 | if (sta->he_cap.has_he) { |
| 1397 | __sta_phy_bitrate_mask_check(he_mcs, he_gi, 0, 1); |
| 1398 | } else if (sta->vht_cap.vht_supported) { |
| 1399 | __sta_phy_bitrate_mask_check(vht_mcs, gi, 0, 0); |
| 1400 | } else if (sta->ht_cap.ht_supported) { |
| 1401 | __sta_phy_bitrate_mask_check(ht_mcs, gi, 1, 0); |
| 1402 | } else { |
| 1403 | nrates = hweight32(mask->control[band].legacy); |
| 1404 | phy.mcs = ffs(mask->control[band].legacy) - 1; |
| 1405 | } |
| 1406 | #undef __sta_phy_bitrate_mask_check |
| 1407 | |
| 1408 | /* fall back to auto rate control */ |
| 1409 | if (mask->control[band].gi == NL80211_TXRATE_DEFAULT_GI && |
| 1410 | mask->control[band].he_gi == GENMASK(7, 0) && |
| 1411 | mask->control[band].he_ltf == GENMASK(7, 0) && |
| 1412 | nrates != 1) |
| 1413 | return 0; |
| 1414 | |
| 1415 | /* fixed single rate */ |
| 1416 | if (nrates == 1) { |
| 1417 | ret = mt7915_mcu_set_fixed_rate_ctrl(dev, vif, sta, &phy, |
| 1418 | RATE_PARAM_FIXED_MCS); |
| 1419 | if (ret) |
| 1420 | return ret; |
| 1421 | } |
| 1422 | |
| 1423 | /* fixed GI */ |
| 1424 | if (mask->control[band].gi != NL80211_TXRATE_DEFAULT_GI || |
| 1425 | mask->control[band].he_gi != GENMASK(7, 0)) { |
| 1426 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 1427 | u32 addr; |
| 1428 | |
| 1429 | /* firmware updates only TXCMD but doesn't take WTBL into |
| 1430 | * account, so driver should update here to reflect the |
| 1431 | * actual txrate hardware sends out. |
| 1432 | */ |
| 1433 | addr = mt7915_mac_wtbl_lmac_addr(dev, msta->wcid.idx, 7); |
| 1434 | if (sta->he_cap.has_he) |
| 1435 | mt76_rmw_field(dev, addr, GENMASK(31, 24), phy.sgi); |
| 1436 | else |
| 1437 | mt76_rmw_field(dev, addr, GENMASK(15, 12), phy.sgi); |
| 1438 | |
| 1439 | ret = mt7915_mcu_set_fixed_rate_ctrl(dev, vif, sta, &phy, |
| 1440 | RATE_PARAM_FIXED_GI); |
| 1441 | if (ret) |
| 1442 | return ret; |
| 1443 | } |
| 1444 | |
| 1445 | /* fixed HE_LTF */ |
| 1446 | if (mask->control[band].he_ltf != GENMASK(7, 0)) { |
| 1447 | ret = mt7915_mcu_set_fixed_rate_ctrl(dev, vif, sta, &phy, |
| 1448 | RATE_PARAM_FIXED_HE_LTF); |
| 1449 | if (ret) |
| 1450 | return ret; |
| 1451 | } |
| 1452 | |
| 1453 | return mt7915_mcu_set_spe_idx(dev, vif, sta); |
| 1454 | } |
| 1455 | |
| 1456 | static void |
| 1457 | mt7915_mcu_sta_rate_ctrl_tlv(struct sk_buff *skb, struct mt7915_dev *dev, |
| 1458 | struct ieee80211_vif *vif, struct ieee80211_sta *sta) |
| 1459 | { |
| 1460 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1461 | struct mt76_phy *mphy = mvif->phy->mt76; |
| 1462 | struct cfg80211_chan_def *chandef = &mphy->chandef; |
| 1463 | struct cfg80211_bitrate_mask *mask = &mvif->bitrate_mask; |
| 1464 | enum nl80211_band band = chandef->chan->band; |
| 1465 | struct sta_rec_ra *ra; |
| 1466 | struct tlv *tlv; |
| 1467 | u32 supp_rate = sta->supp_rates[band]; |
| 1468 | u32 cap = sta->wme ? STA_CAP_WMM : 0; |
| 1469 | |
| 1470 | tlv = mt76_connac_mcu_add_tlv(skb, STA_REC_RA, sizeof(*ra)); |
| 1471 | ra = (struct sta_rec_ra *)tlv; |
| 1472 | |
| 1473 | ra->valid = true; |
| 1474 | ra->auto_rate = true; |
| 1475 | ra->phy_mode = mt76_connac_get_phy_mode(mphy, vif, band, sta); |
| 1476 | ra->channel = chandef->chan->hw_value; |
| 1477 | ra->bw = sta->bandwidth; |
| 1478 | ra->phy.bw = sta->bandwidth; |
| 1479 | ra->mmps_mode = mt7915_mcu_get_mmps_mode(sta->smps_mode); |
| 1480 | |
| 1481 | if (supp_rate) { |
| 1482 | supp_rate &= mask->control[band].legacy; |
| 1483 | ra->rate_len = hweight32(supp_rate); |
| 1484 | |
| 1485 | if (band == NL80211_BAND_2GHZ) { |
| 1486 | ra->supp_mode = MODE_CCK; |
| 1487 | ra->supp_cck_rate = supp_rate & GENMASK(3, 0); |
| 1488 | |
| 1489 | if (ra->rate_len > 4) { |
| 1490 | ra->supp_mode |= MODE_OFDM; |
| 1491 | ra->supp_ofdm_rate = supp_rate >> 4; |
| 1492 | } |
| 1493 | } else { |
| 1494 | ra->supp_mode = MODE_OFDM; |
| 1495 | ra->supp_ofdm_rate = supp_rate; |
| 1496 | } |
| 1497 | } |
| 1498 | |
| 1499 | if (sta->ht_cap.ht_supported) { |
| 1500 | ra->supp_mode |= MODE_HT; |
| 1501 | ra->af = sta->ht_cap.ampdu_factor; |
| 1502 | ra->ht_gf = !!(sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD); |
| 1503 | |
| 1504 | cap |= STA_CAP_HT; |
| 1505 | if (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) |
| 1506 | cap |= STA_CAP_SGI_20; |
| 1507 | if (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) |
| 1508 | cap |= STA_CAP_SGI_40; |
| 1509 | if (sta->ht_cap.cap & IEEE80211_HT_CAP_TX_STBC) |
| 1510 | cap |= STA_CAP_TX_STBC; |
| 1511 | if (sta->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC) |
| 1512 | cap |= STA_CAP_RX_STBC; |
| 1513 | if (mvif->cap.ht_ldpc && |
| 1514 | (sta->ht_cap.cap & IEEE80211_HT_CAP_LDPC_CODING)) |
| 1515 | cap |= STA_CAP_LDPC; |
| 1516 | |
| 1517 | mt7915_mcu_set_sta_ht_mcs(sta, ra->ht_mcs, |
| 1518 | mask->control[band].ht_mcs); |
| 1519 | ra->supp_ht_mcs = *(__le32 *)ra->ht_mcs; |
| 1520 | } |
| 1521 | |
| 1522 | if (sta->vht_cap.vht_supported) { |
| 1523 | u8 af; |
| 1524 | |
| 1525 | ra->supp_mode |= MODE_VHT; |
| 1526 | af = FIELD_GET(IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK, |
| 1527 | sta->vht_cap.cap); |
| 1528 | ra->af = max_t(u8, ra->af, af); |
| 1529 | |
| 1530 | cap |= STA_CAP_VHT; |
| 1531 | if (sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_80) |
| 1532 | cap |= STA_CAP_VHT_SGI_80; |
| 1533 | if (sta->vht_cap.cap & IEEE80211_VHT_CAP_SHORT_GI_160) |
| 1534 | cap |= STA_CAP_VHT_SGI_160; |
| 1535 | if (sta->vht_cap.cap & IEEE80211_VHT_CAP_TXSTBC) |
| 1536 | cap |= STA_CAP_VHT_TX_STBC; |
| 1537 | if (sta->vht_cap.cap & IEEE80211_VHT_CAP_RXSTBC_1) |
| 1538 | cap |= STA_CAP_VHT_RX_STBC; |
| 1539 | if (mvif->cap.vht_ldpc && |
| 1540 | (sta->vht_cap.cap & IEEE80211_VHT_CAP_RXLDPC)) |
| 1541 | cap |= STA_CAP_VHT_LDPC; |
| 1542 | |
| 1543 | mt7915_mcu_set_sta_vht_mcs(sta, ra->supp_vht_mcs, |
| 1544 | mask->control[band].vht_mcs); |
| 1545 | } |
| 1546 | |
| 1547 | if (sta->he_cap.has_he) { |
| 1548 | ra->supp_mode |= MODE_HE; |
| 1549 | cap |= STA_CAP_HE; |
| 1550 | |
| 1551 | if (sta->he_6ghz_capa.capa) |
| 1552 | ra->af = le16_get_bits(sta->he_6ghz_capa.capa, |
| 1553 | IEEE80211_HE_6GHZ_CAP_MAX_AMPDU_LEN_EXP); |
| 1554 | } |
| 1555 | |
| 1556 | ra->sta_cap = cpu_to_le32(cap); |
| 1557 | } |
| 1558 | |
| 1559 | int mt7915_mcu_add_rate_ctrl(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 1560 | struct ieee80211_sta *sta, bool changed) |
| 1561 | { |
| 1562 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1563 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 1564 | struct sk_buff *skb; |
| 1565 | int ret; |
| 1566 | |
| 1567 | skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, |
| 1568 | &msta->wcid); |
| 1569 | if (IS_ERR(skb)) |
| 1570 | return PTR_ERR(skb); |
| 1571 | |
| 1572 | /* firmware rc algorithm refers to sta_rec_he for HE control. |
| 1573 | * once dev->rc_work changes the settings driver should also |
| 1574 | * update sta_rec_he here. |
| 1575 | */ |
| 1576 | if (changed) |
| 1577 | mt7915_mcu_sta_he_tlv(skb, sta, vif); |
| 1578 | |
| 1579 | /* sta_rec_ra accommodates BW, NSS and only MCS range format |
| 1580 | * i.e 0-{7,8,9} for VHT. |
| 1581 | */ |
| 1582 | mt7915_mcu_sta_rate_ctrl_tlv(skb, dev, vif, sta); |
| 1583 | |
| 1584 | ret = mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 1585 | MCU_EXT_CMD(STA_REC_UPDATE), true); |
| 1586 | if (ret) |
| 1587 | return ret; |
| 1588 | |
| 1589 | /* sta_rec_ra_fixed accommodates single rate, (HE)GI and HE_LTE, |
| 1590 | * and updates as peer fixed rate parameters, which overrides |
| 1591 | * sta_rec_ra and firmware rate control algorithm. |
| 1592 | */ |
| 1593 | return mt7915_mcu_add_rate_ctrl_fixed(dev, vif, sta); |
| 1594 | } |
| 1595 | |
| 1596 | static int |
| 1597 | mt7915_mcu_add_group(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 1598 | struct ieee80211_sta *sta) |
| 1599 | { |
| 1600 | #define MT_STA_BSS_GROUP 1 |
| 1601 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1602 | struct mt7915_sta *msta; |
| 1603 | struct { |
| 1604 | __le32 action; |
| 1605 | u8 wlan_idx_lo; |
| 1606 | u8 status; |
| 1607 | u8 wlan_idx_hi; |
| 1608 | u8 rsv0[5]; |
| 1609 | __le32 val; |
| 1610 | u8 rsv1[8]; |
| 1611 | } __packed req = { |
| 1612 | .action = cpu_to_le32(MT_STA_BSS_GROUP), |
| 1613 | .val = cpu_to_le32(mvif->mt76.idx % 16), |
| 1614 | }; |
| 1615 | |
| 1616 | msta = sta ? (struct mt7915_sta *)sta->drv_priv : &mvif->sta; |
| 1617 | req.wlan_idx_lo = to_wcid_lo(msta->wcid.idx); |
| 1618 | req.wlan_idx_hi = to_wcid_hi(msta->wcid.idx); |
| 1619 | |
| 1620 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_DRR_CTRL), &req, |
| 1621 | sizeof(req), true); |
| 1622 | } |
| 1623 | |
| 1624 | int mt7915_mcu_add_sta(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 1625 | struct ieee80211_sta *sta, bool enable) |
| 1626 | { |
| 1627 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1628 | struct mt7915_sta *msta; |
| 1629 | struct sk_buff *skb; |
| 1630 | int ret; |
| 1631 | |
| 1632 | msta = sta ? (struct mt7915_sta *)sta->drv_priv : &mvif->sta; |
| 1633 | |
| 1634 | skb = mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, |
| 1635 | &msta->wcid); |
| 1636 | if (IS_ERR(skb)) |
| 1637 | return PTR_ERR(skb); |
| 1638 | |
| 1639 | /* starec basic */ |
| 1640 | mt76_connac_mcu_sta_basic_tlv(skb, vif, sta, enable, |
| 1641 | !rcu_access_pointer(dev->mt76.wcid[msta->wcid.idx])); |
| 1642 | if (!enable) |
| 1643 | goto out; |
| 1644 | |
| 1645 | /* tag order is in accordance with firmware dependency. */ |
| 1646 | if (sta) { |
| 1647 | /* starec bfer */ |
| 1648 | mt7915_mcu_sta_bfer_tlv(dev, skb, vif, sta); |
| 1649 | /* starec ht */ |
| 1650 | mt7915_mcu_sta_ht_tlv(skb, sta); |
| 1651 | /* starec vht */ |
| 1652 | mt7915_mcu_sta_vht_tlv(skb, sta); |
| 1653 | /* starec uapsd */ |
| 1654 | mt76_connac_mcu_sta_uapsd(skb, vif, sta); |
| 1655 | } |
| 1656 | |
| 1657 | ret = mt7915_mcu_sta_wtbl_tlv(dev, skb, vif, sta); |
| 1658 | if (ret) { |
| 1659 | dev_kfree_skb(skb); |
| 1660 | return ret; |
| 1661 | } |
| 1662 | |
| 1663 | if (sta) { |
| 1664 | /* starec amsdu */ |
| 1665 | mt7915_mcu_sta_amsdu_tlv(dev, skb, vif, sta); |
| 1666 | /* starec he */ |
| 1667 | mt7915_mcu_sta_he_tlv(skb, sta, vif); |
| 1668 | /* starec muru */ |
| 1669 | mt7915_mcu_sta_muru_tlv(dev, skb, sta, vif); |
| 1670 | /* starec bfee */ |
| 1671 | mt7915_mcu_sta_bfee_tlv(dev, skb, vif, sta); |
| 1672 | } |
| 1673 | |
| 1674 | ret = mt7915_mcu_add_group(dev, vif, sta); |
| 1675 | if (ret) { |
| 1676 | dev_kfree_skb(skb); |
| 1677 | return ret; |
| 1678 | } |
| 1679 | out: |
| 1680 | return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 1681 | MCU_EXT_CMD(STA_REC_UPDATE), true); |
| 1682 | } |
| 1683 | |
| 1684 | int mt7915_mcu_add_dev_info(struct mt7915_phy *phy, |
| 1685 | struct ieee80211_vif *vif, bool enable) |
| 1686 | { |
| 1687 | struct mt7915_dev *dev = phy->dev; |
| 1688 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1689 | struct { |
| 1690 | struct req_hdr { |
| 1691 | u8 omac_idx; |
| 1692 | u8 dbdc_idx; |
| 1693 | __le16 tlv_num; |
| 1694 | u8 is_tlv_append; |
| 1695 | u8 rsv[3]; |
| 1696 | } __packed hdr; |
| 1697 | struct req_tlv { |
| 1698 | __le16 tag; |
| 1699 | __le16 len; |
| 1700 | u8 active; |
| 1701 | u8 dbdc_idx; |
| 1702 | u8 omac_addr[ETH_ALEN]; |
| 1703 | } __packed tlv; |
| 1704 | } data = { |
| 1705 | .hdr = { |
| 1706 | .omac_idx = mvif->mt76.omac_idx, |
| 1707 | .dbdc_idx = mvif->mt76.band_idx, |
| 1708 | .tlv_num = cpu_to_le16(1), |
| 1709 | .is_tlv_append = 1, |
| 1710 | }, |
| 1711 | .tlv = { |
| 1712 | .tag = cpu_to_le16(DEV_INFO_ACTIVE), |
| 1713 | .len = cpu_to_le16(sizeof(struct req_tlv)), |
| 1714 | .active = enable, |
| 1715 | .dbdc_idx = mvif->mt76.band_idx, |
| 1716 | }, |
| 1717 | }; |
| 1718 | |
| 1719 | if (mvif->mt76.omac_idx >= REPEATER_BSSID_START) |
| 1720 | return mt7915_mcu_muar_config(phy, vif, false, enable); |
| 1721 | |
| 1722 | memcpy(data.tlv.omac_addr, vif->addr, ETH_ALEN); |
| 1723 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(DEV_INFO_UPDATE), |
| 1724 | &data, sizeof(data), true); |
| 1725 | } |
| 1726 | |
| 1727 | static void |
| 1728 | mt7915_mcu_beacon_cntdwn(struct ieee80211_vif *vif, struct sk_buff *rskb, |
| 1729 | struct sk_buff *skb, struct bss_info_bcn *bcn, |
| 1730 | struct ieee80211_mutable_offsets *offs) |
| 1731 | { |
| 1732 | struct bss_info_bcn_cntdwn *info; |
| 1733 | struct tlv *tlv; |
| 1734 | int sub_tag; |
| 1735 | |
| 1736 | if (!offs->cntdwn_counter_offs[0]) |
| 1737 | return; |
| 1738 | |
| 1739 | sub_tag = vif->csa_active ? BSS_INFO_BCN_CSA : BSS_INFO_BCN_BCC; |
| 1740 | tlv = mt7915_mcu_add_nested_subtlv(rskb, sub_tag, sizeof(*info), |
| 1741 | &bcn->sub_ntlv, &bcn->len); |
| 1742 | info = (struct bss_info_bcn_cntdwn *)tlv; |
| 1743 | info->cnt = skb->data[offs->cntdwn_counter_offs[0]]; |
| 1744 | } |
| 1745 | |
| 1746 | static void |
| 1747 | mt7915_mcu_beacon_mbss(struct sk_buff *rskb, struct sk_buff *skb, |
| 1748 | struct ieee80211_vif *vif, struct bss_info_bcn *bcn, |
| 1749 | struct ieee80211_mutable_offsets *offs) |
| 1750 | { |
| 1751 | struct bss_info_bcn_mbss *mbss; |
| 1752 | const struct element *elem; |
| 1753 | struct tlv *tlv; |
| 1754 | |
| 1755 | if (!vif->bss_conf.bssid_indicator) |
| 1756 | return; |
| 1757 | |
| 1758 | tlv = mt7915_mcu_add_nested_subtlv(rskb, BSS_INFO_BCN_MBSSID, |
| 1759 | sizeof(*mbss), &bcn->sub_ntlv, |
| 1760 | &bcn->len); |
| 1761 | |
| 1762 | mbss = (struct bss_info_bcn_mbss *)tlv; |
| 1763 | mbss->offset[0] = cpu_to_le16(offs->tim_offset); |
| 1764 | mbss->bitmap = cpu_to_le32(1); |
| 1765 | |
| 1766 | for_each_element_id(elem, WLAN_EID_MULTIPLE_BSSID, |
| 1767 | &skb->data[offs->mbssid_off], |
| 1768 | skb->len - offs->mbssid_off) { |
| 1769 | const struct element *sub_elem; |
| 1770 | |
| 1771 | if (elem->datalen < 2) |
| 1772 | continue; |
| 1773 | |
| 1774 | for_each_element(sub_elem, elem->data + 1, elem->datalen - 1) { |
| 1775 | const struct ieee80211_bssid_index *idx; |
| 1776 | const u8 *idx_ie; |
| 1777 | |
| 1778 | if (sub_elem->id || sub_elem->datalen < 4) |
| 1779 | continue; /* not a valid BSS profile */ |
| 1780 | |
| 1781 | /* Find WLAN_EID_MULTI_BSSID_IDX |
| 1782 | * in the merged nontransmitted profile |
| 1783 | */ |
| 1784 | idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, |
| 1785 | sub_elem->data, |
| 1786 | sub_elem->datalen); |
| 1787 | if (!idx_ie || idx_ie[1] < sizeof(*idx)) |
| 1788 | continue; |
| 1789 | |
| 1790 | idx = (void *)(idx_ie + 2); |
| 1791 | if (!idx->bssid_index || idx->bssid_index > 31) |
| 1792 | continue; |
| 1793 | |
| 1794 | mbss->offset[idx->bssid_index] = |
| 1795 | cpu_to_le16(idx_ie - skb->data); |
| 1796 | mbss->bitmap |= cpu_to_le32(BIT(idx->bssid_index)); |
| 1797 | } |
| 1798 | } |
| 1799 | } |
| 1800 | |
| 1801 | static void |
| 1802 | mt7915_mcu_beacon_cont(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 1803 | struct sk_buff *rskb, struct sk_buff *skb, |
| 1804 | struct bss_info_bcn *bcn, |
| 1805 | struct ieee80211_mutable_offsets *offs) |
| 1806 | { |
| 1807 | struct mt76_wcid *wcid = &dev->mt76.global_wcid; |
| 1808 | struct bss_info_bcn_cont *cont; |
| 1809 | struct tlv *tlv; |
| 1810 | u8 *buf; |
| 1811 | int len = sizeof(*cont) + MT_TXD_SIZE + skb->len; |
| 1812 | |
| 1813 | len = (len & 0x3) ? ((len | 0x3) + 1) : len; |
| 1814 | tlv = mt7915_mcu_add_nested_subtlv(rskb, BSS_INFO_BCN_CONTENT, |
| 1815 | len, &bcn->sub_ntlv, &bcn->len); |
| 1816 | |
| 1817 | cont = (struct bss_info_bcn_cont *)tlv; |
| 1818 | cont->pkt_len = cpu_to_le16(MT_TXD_SIZE + skb->len); |
| 1819 | cont->tim_ofs = cpu_to_le16(offs->tim_offset); |
| 1820 | |
| 1821 | if (offs->cntdwn_counter_offs[0]) { |
| 1822 | u16 offset = offs->cntdwn_counter_offs[0]; |
| 1823 | |
| 1824 | if (vif->csa_active) |
| 1825 | cont->csa_ofs = cpu_to_le16(offset - 4); |
| 1826 | if (vif->color_change_active) |
| 1827 | cont->bcc_ofs = cpu_to_le16(offset - 3); |
| 1828 | } |
| 1829 | |
| 1830 | buf = (u8 *)tlv + sizeof(*cont); |
| 1831 | mt7915_mac_write_txwi(&dev->mt76, (__le32 *)buf, skb, wcid, 0, NULL, |
| 1832 | 0, BSS_CHANGED_BEACON); |
| 1833 | memcpy(buf + MT_TXD_SIZE, skb->data, skb->len); |
| 1834 | } |
| 1835 | |
| 1836 | static void |
| 1837 | mt7915_mcu_beacon_check_caps(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 1838 | struct sk_buff *skb) |
| 1839 | { |
| 1840 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1841 | struct mt7915_vif_cap *vc = &mvif->cap; |
| 1842 | const struct ieee80211_he_cap_elem *he; |
| 1843 | const struct ieee80211_vht_cap *vht; |
| 1844 | const struct ieee80211_ht_cap *ht; |
| 1845 | struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data; |
| 1846 | const u8 *ie; |
| 1847 | u32 len, bc; |
| 1848 | |
| 1849 | /* Check missing configuration options to allow AP mode in mac80211 |
| 1850 | * to remain in sync with hostapd settings, and get a subset of |
| 1851 | * beacon and hardware capabilities. |
| 1852 | */ |
| 1853 | if (WARN_ON_ONCE(skb->len <= (mgmt->u.beacon.variable - skb->data))) |
| 1854 | return; |
| 1855 | |
| 1856 | memset(vc, 0, sizeof(*vc)); |
| 1857 | |
| 1858 | len = skb->len - (mgmt->u.beacon.variable - skb->data); |
| 1859 | |
| 1860 | ie = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, mgmt->u.beacon.variable, |
| 1861 | len); |
| 1862 | if (ie && ie[1] >= sizeof(*ht)) { |
| 1863 | ht = (void *)(ie + 2); |
| 1864 | vc->ht_ldpc = !!(le16_to_cpu(ht->cap_info) & |
| 1865 | IEEE80211_HT_CAP_LDPC_CODING); |
| 1866 | } |
| 1867 | |
| 1868 | ie = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, mgmt->u.beacon.variable, |
| 1869 | len); |
| 1870 | if (ie && ie[1] >= sizeof(*vht)) { |
| 1871 | u32 pc = phy->mt76->sband_5g.sband.vht_cap.cap; |
| 1872 | |
| 1873 | vht = (void *)(ie + 2); |
| 1874 | bc = le32_to_cpu(vht->vht_cap_info); |
| 1875 | |
| 1876 | vc->vht_ldpc = !!(bc & IEEE80211_VHT_CAP_RXLDPC); |
| 1877 | vc->vht_su_ebfer = |
| 1878 | (bc & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE) && |
| 1879 | (pc & IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE); |
| 1880 | vc->vht_su_ebfee = |
| 1881 | (bc & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE) && |
| 1882 | (pc & IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE); |
| 1883 | vc->vht_mu_ebfer = |
| 1884 | (bc & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE) && |
| 1885 | (pc & IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); |
| 1886 | vc->vht_mu_ebfee = |
| 1887 | (bc & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) && |
| 1888 | (pc & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE); |
| 1889 | } |
| 1890 | |
| 1891 | ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_CAPABILITY, |
| 1892 | mgmt->u.beacon.variable, len); |
| 1893 | if (ie && ie[1] >= sizeof(*he) + 1) { |
| 1894 | const struct ieee80211_sta_he_cap *pc = |
| 1895 | mt76_connac_get_he_phy_cap(phy->mt76, vif); |
| 1896 | const struct ieee80211_he_cap_elem *pe = &pc->he_cap_elem; |
| 1897 | |
| 1898 | he = (void *)(ie + 3); |
| 1899 | |
| 1900 | vc->he_ldpc = |
| 1901 | HE_PHY(CAP1_LDPC_CODING_IN_PAYLOAD, pe->phy_cap_info[1]); |
| 1902 | vc->he_su_ebfer = |
| 1903 | HE_PHY(CAP3_SU_BEAMFORMER, he->phy_cap_info[3]) && |
| 1904 | HE_PHY(CAP3_SU_BEAMFORMER, pe->phy_cap_info[3]); |
| 1905 | vc->he_su_ebfee = |
| 1906 | HE_PHY(CAP4_SU_BEAMFORMEE, he->phy_cap_info[4]) && |
| 1907 | HE_PHY(CAP4_SU_BEAMFORMEE, pe->phy_cap_info[4]); |
| 1908 | vc->he_mu_ebfer = |
| 1909 | HE_PHY(CAP4_MU_BEAMFORMER, he->phy_cap_info[4]) && |
| 1910 | HE_PHY(CAP4_MU_BEAMFORMER, pe->phy_cap_info[4]); |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | static void |
| 1915 | mt7915_mcu_beacon_inband_discov(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 1916 | struct sk_buff *rskb, struct bss_info_bcn *bcn, |
| 1917 | u32 changed) |
| 1918 | { |
| 1919 | #define OFFLOAD_TX_MODE_SU BIT(0) |
| 1920 | #define OFFLOAD_TX_MODE_MU BIT(1) |
| 1921 | struct ieee80211_hw *hw = mt76_hw(dev); |
| 1922 | struct mt7915_phy *phy = mt7915_hw_phy(hw); |
| 1923 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1924 | struct cfg80211_chan_def *chandef = &mvif->phy->mt76->chandef; |
| 1925 | enum nl80211_band band = chandef->chan->band; |
| 1926 | struct mt76_wcid *wcid = &dev->mt76.global_wcid; |
| 1927 | struct bss_info_inband_discovery *discov; |
| 1928 | struct ieee80211_tx_info *info; |
| 1929 | struct sk_buff *skb = NULL; |
| 1930 | struct tlv *tlv; |
| 1931 | bool ext_phy = phy != &dev->phy; |
| 1932 | u8 *buf, interval; |
| 1933 | int len; |
| 1934 | |
| 1935 | if (changed & BSS_CHANGED_FILS_DISCOVERY && |
| 1936 | vif->bss_conf.fils_discovery.max_interval) { |
| 1937 | interval = vif->bss_conf.fils_discovery.max_interval; |
| 1938 | skb = ieee80211_get_fils_discovery_tmpl(hw, vif); |
| 1939 | } else if (changed & BSS_CHANGED_UNSOL_BCAST_PROBE_RESP && |
| 1940 | vif->bss_conf.unsol_bcast_probe_resp_interval) { |
| 1941 | interval = vif->bss_conf.unsol_bcast_probe_resp_interval; |
| 1942 | skb = ieee80211_get_unsol_bcast_probe_resp_tmpl(hw, vif); |
| 1943 | } |
| 1944 | |
| 1945 | if (!skb) |
| 1946 | return; |
| 1947 | |
| 1948 | info = IEEE80211_SKB_CB(skb); |
| 1949 | info->control.vif = vif; |
| 1950 | info->band = band; |
| 1951 | |
| 1952 | info->hw_queue |= FIELD_PREP(MT_TX_HW_QUEUE_PHY, ext_phy); |
| 1953 | |
| 1954 | len = sizeof(*discov) + MT_TXD_SIZE + skb->len; |
| 1955 | len = (len & 0x3) ? ((len | 0x3) + 1) : len; |
| 1956 | |
| 1957 | if (len > (MT7915_MAX_BSS_OFFLOAD_SIZE - rskb->len)) { |
| 1958 | dev_err(dev->mt76.dev, "inband discovery size limit exceed\n"); |
| 1959 | dev_kfree_skb(skb); |
| 1960 | return; |
| 1961 | } |
| 1962 | |
| 1963 | tlv = mt7915_mcu_add_nested_subtlv(rskb, BSS_INFO_BCN_DISCOV, |
| 1964 | len, &bcn->sub_ntlv, &bcn->len); |
| 1965 | discov = (struct bss_info_inband_discovery *)tlv; |
| 1966 | discov->tx_mode = OFFLOAD_TX_MODE_SU; |
| 1967 | /* 0: UNSOL PROBE RESP, 1: FILS DISCOV */ |
| 1968 | discov->tx_type = !!(changed & BSS_CHANGED_FILS_DISCOVERY); |
| 1969 | discov->tx_interval = interval; |
| 1970 | discov->prob_rsp_len = cpu_to_le16(MT_TXD_SIZE + skb->len); |
| 1971 | discov->enable = true; |
| 1972 | |
| 1973 | buf = (u8 *)tlv + sizeof(*discov); |
| 1974 | |
| 1975 | mt7915_mac_write_txwi(&dev->mt76, (__le32 *)buf, skb, wcid, 0, NULL, |
| 1976 | 0, changed); |
| 1977 | memcpy(buf + MT_TXD_SIZE, skb->data, skb->len); |
| 1978 | |
| 1979 | dev_kfree_skb(skb); |
| 1980 | } |
| 1981 | |
| 1982 | int mt7915_mcu_add_beacon(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| 1983 | int en, u32 changed) |
| 1984 | { |
| 1985 | struct mt7915_dev *dev = mt7915_hw_dev(hw); |
| 1986 | struct mt7915_phy *phy = mt7915_hw_phy(hw); |
| 1987 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 1988 | struct ieee80211_mutable_offsets offs; |
| 1989 | struct ieee80211_tx_info *info; |
| 1990 | struct sk_buff *skb, *rskb; |
| 1991 | struct tlv *tlv; |
| 1992 | struct bss_info_bcn *bcn; |
| 1993 | int len = MT7915_MAX_BSS_OFFLOAD_SIZE; |
| 1994 | bool ext_phy = phy != &dev->phy; |
| 1995 | |
| 1996 | if (vif->bss_conf.nontransmitted) |
| 1997 | return 0; |
| 1998 | |
| 1999 | rskb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, |
| 2000 | NULL, len); |
| 2001 | if (IS_ERR(rskb)) |
| 2002 | return PTR_ERR(rskb); |
| 2003 | |
| 2004 | tlv = mt76_connac_mcu_add_tlv(rskb, BSS_INFO_OFFLOAD, sizeof(*bcn)); |
| 2005 | bcn = (struct bss_info_bcn *)tlv; |
| 2006 | bcn->enable = en; |
| 2007 | |
| 2008 | if (!en) |
| 2009 | goto out; |
| 2010 | |
| 2011 | skb = ieee80211_beacon_get_template(hw, vif, &offs); |
| 2012 | if (!skb) |
| 2013 | return -EINVAL; |
| 2014 | |
| 2015 | if (skb->len > MT7915_MAX_BEACON_SIZE - MT_TXD_SIZE) { |
| 2016 | dev_err(dev->mt76.dev, "Bcn size limit exceed\n"); |
| 2017 | dev_kfree_skb(skb); |
| 2018 | return -EINVAL; |
| 2019 | } |
| 2020 | |
| 2021 | info = IEEE80211_SKB_CB(skb); |
| 2022 | info->hw_queue = FIELD_PREP(MT_TX_HW_QUEUE_PHY, ext_phy); |
| 2023 | |
| 2024 | mt7915_mcu_beacon_check_caps(phy, vif, skb); |
| 2025 | |
| 2026 | mt7915_mcu_beacon_cntdwn(vif, rskb, skb, bcn, &offs); |
| 2027 | mt7915_mcu_beacon_mbss(rskb, skb, vif, bcn, &offs); |
| 2028 | mt7915_mcu_beacon_cont(dev, vif, rskb, skb, bcn, &offs); |
| 2029 | dev_kfree_skb(skb); |
| 2030 | |
| 2031 | if (changed & BSS_CHANGED_UNSOL_BCAST_PROBE_RESP || |
| 2032 | changed & BSS_CHANGED_FILS_DISCOVERY) |
| 2033 | mt7915_mcu_beacon_inband_discov(dev, vif, rskb, |
| 2034 | bcn, changed); |
| 2035 | |
| 2036 | out: |
| 2037 | return mt76_mcu_skb_send_msg(&phy->dev->mt76, rskb, |
| 2038 | MCU_EXT_CMD(BSS_INFO_UPDATE), true); |
| 2039 | } |
| 2040 | |
| 2041 | static int mt7915_driver_own(struct mt7915_dev *dev, u8 band) |
| 2042 | { |
| 2043 | mt76_wr(dev, MT_TOP_LPCR_HOST_BAND(band), MT_TOP_LPCR_HOST_DRV_OWN); |
| 2044 | if (!mt76_poll_msec(dev, MT_TOP_LPCR_HOST_BAND(band), |
| 2045 | MT_TOP_LPCR_HOST_FW_OWN_STAT, 0, 500)) { |
| 2046 | dev_err(dev->mt76.dev, "Timeout for driver own\n"); |
| 2047 | return -EIO; |
| 2048 | } |
| 2049 | |
| 2050 | /* clear irq when the driver own success */ |
| 2051 | mt76_wr(dev, MT_TOP_LPCR_HOST_BAND_IRQ_STAT(band), |
| 2052 | MT_TOP_LPCR_HOST_BAND_STAT); |
| 2053 | |
| 2054 | return 0; |
| 2055 | } |
| 2056 | |
| 2057 | static int |
| 2058 | mt7915_firmware_state(struct mt7915_dev *dev, bool wa) |
| 2059 | { |
| 2060 | u32 state = FIELD_PREP(MT_TOP_MISC_FW_STATE, |
| 2061 | wa ? FW_STATE_RDY : FW_STATE_FW_DOWNLOAD); |
| 2062 | |
| 2063 | if (!mt76_poll_msec(dev, MT_TOP_MISC, MT_TOP_MISC_FW_STATE, |
| 2064 | state, 1000)) { |
| 2065 | dev_err(dev->mt76.dev, "Timeout for initializing firmware\n"); |
| 2066 | return -EIO; |
| 2067 | } |
| 2068 | return 0; |
| 2069 | } |
| 2070 | |
| 2071 | static int mt7915_load_firmware(struct mt7915_dev *dev) |
| 2072 | { |
| 2073 | int ret; |
| 2074 | |
| 2075 | /* make sure fw is download state */ |
| 2076 | if (mt7915_firmware_state(dev, false)) { |
| 2077 | /* restart firmware once */ |
| 2078 | __mt76_mcu_restart(&dev->mt76); |
| 2079 | ret = mt7915_firmware_state(dev, false); |
| 2080 | if (ret) { |
| 2081 | dev_err(dev->mt76.dev, |
| 2082 | "Firmware is not ready for download\n"); |
| 2083 | return ret; |
| 2084 | } |
| 2085 | } |
| 2086 | |
| 2087 | ret = mt76_connac2_load_patch(&dev->mt76, fw_name_var(dev, ROM_PATCH)); |
| 2088 | if (ret) |
| 2089 | return ret; |
| 2090 | |
| 2091 | ret = mt76_connac2_load_ram(&dev->mt76, fw_name_var(dev, FIRMWARE_WM), |
| 2092 | fw_name(dev, FIRMWARE_WA)); |
| 2093 | if (ret) |
| 2094 | return ret; |
| 2095 | |
| 2096 | ret = mt7915_firmware_state(dev, true); |
| 2097 | if (ret) |
| 2098 | return ret; |
| 2099 | |
| 2100 | mt76_queue_tx_cleanup(dev, dev->mt76.q_mcu[MT_MCUQ_FWDL], false); |
| 2101 | |
| 2102 | dev_dbg(dev->mt76.dev, "Firmware init done\n"); |
| 2103 | |
| 2104 | return 0; |
| 2105 | } |
| 2106 | |
| 2107 | int mt7915_mcu_fw_log_2_host(struct mt7915_dev *dev, u8 type, u8 ctrl) |
| 2108 | { |
| 2109 | struct { |
| 2110 | u8 ctrl_val; |
| 2111 | u8 pad[3]; |
| 2112 | } data = { |
| 2113 | .ctrl_val = ctrl |
| 2114 | }; |
| 2115 | |
| 2116 | if (type == MCU_FW_LOG_WA) |
| 2117 | return mt76_mcu_send_msg(&dev->mt76, MCU_WA_EXT_CMD(FW_LOG_2_HOST), |
| 2118 | &data, sizeof(data), true); |
| 2119 | |
| 2120 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(FW_LOG_2_HOST), &data, |
| 2121 | sizeof(data), true); |
| 2122 | } |
| 2123 | |
| 2124 | int mt7915_mcu_fw_dbg_ctrl(struct mt7915_dev *dev, u32 module, u8 level) |
| 2125 | { |
| 2126 | struct { |
| 2127 | u8 ver; |
| 2128 | u8 pad; |
| 2129 | __le16 len; |
| 2130 | u8 level; |
| 2131 | u8 rsv[3]; |
| 2132 | __le32 module_idx; |
| 2133 | } data = { |
| 2134 | .module_idx = cpu_to_le32(module), |
| 2135 | .level = level, |
| 2136 | }; |
| 2137 | |
| 2138 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(FW_DBG_CTRL), &data, |
| 2139 | sizeof(data), false); |
| 2140 | } |
| 2141 | |
| 2142 | int mt7915_mcu_muru_debug_set(struct mt7915_dev *dev, bool enabled) |
| 2143 | { |
| 2144 | struct { |
| 2145 | __le32 cmd; |
| 2146 | u8 enable; |
| 2147 | } data = { |
| 2148 | .cmd = cpu_to_le32(MURU_SET_TXC_TX_STATS_EN), |
| 2149 | .enable = enabled, |
| 2150 | }; |
| 2151 | |
| 2152 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &data, |
| 2153 | sizeof(data), false); |
| 2154 | } |
| 2155 | |
| 2156 | int mt7915_mcu_muru_debug_get(struct mt7915_phy *phy, void *ms) |
| 2157 | { |
| 2158 | struct mt7915_dev *dev = phy->dev; |
| 2159 | struct sk_buff *skb; |
| 2160 | struct mt7915_mcu_muru_stats *mu_stats = |
| 2161 | (struct mt7915_mcu_muru_stats *)ms; |
| 2162 | int ret; |
| 2163 | |
| 2164 | struct { |
| 2165 | __le32 cmd; |
| 2166 | u8 band_idx; |
| 2167 | } req = { |
| 2168 | .cmd = cpu_to_le32(MURU_GET_TXC_TX_STATS), |
| 2169 | .band_idx = phy->band_idx, |
| 2170 | }; |
| 2171 | |
| 2172 | ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), |
| 2173 | &req, sizeof(req), true, &skb); |
| 2174 | if (ret) |
| 2175 | return ret; |
| 2176 | |
| 2177 | memcpy(mu_stats, skb->data, sizeof(struct mt7915_mcu_muru_stats)); |
| 2178 | dev_kfree_skb(skb); |
| 2179 | |
| 2180 | return 0; |
| 2181 | } |
| 2182 | |
| 2183 | static int mt7915_mcu_set_mwds(struct mt7915_dev *dev, bool enabled) |
| 2184 | { |
| 2185 | struct { |
| 2186 | u8 enable; |
| 2187 | u8 _rsv[3]; |
| 2188 | } __packed req = { |
| 2189 | .enable = enabled |
| 2190 | }; |
| 2191 | |
| 2192 | return mt76_mcu_send_msg(&dev->mt76, MCU_WA_EXT_CMD(MWDS_SUPPORT), &req, |
| 2193 | sizeof(req), false); |
| 2194 | } |
| 2195 | |
| 2196 | int mt7915_mcu_set_muru_ctrl(struct mt7915_dev *dev, u32 cmd, u32 val) |
| 2197 | { |
| 2198 | struct { |
| 2199 | __le32 cmd; |
| 2200 | u8 val[4]; |
| 2201 | } __packed req = { |
| 2202 | .cmd = cpu_to_le32(cmd), |
| 2203 | }; |
| 2204 | |
| 2205 | put_unaligned_le32(val, req.val); |
| 2206 | |
| 2207 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MURU_CTRL), &req, |
| 2208 | sizeof(req), false); |
| 2209 | } |
| 2210 | |
| 2211 | static int |
| 2212 | mt7915_mcu_init_rx_airtime(struct mt7915_dev *dev) |
| 2213 | { |
| 2214 | #define RX_AIRTIME_FEATURE_CTRL 1 |
| 2215 | #define RX_AIRTIME_BITWISE_CTRL 2 |
| 2216 | #define RX_AIRTIME_CLEAR_EN 1 |
| 2217 | struct { |
| 2218 | __le16 field; |
| 2219 | __le16 sub_field; |
| 2220 | __le32 set_status; |
| 2221 | __le32 get_status; |
| 2222 | u8 _rsv[12]; |
| 2223 | |
| 2224 | bool airtime_en; |
| 2225 | bool mibtime_en; |
| 2226 | bool earlyend_en; |
| 2227 | u8 _rsv1[9]; |
| 2228 | |
| 2229 | bool airtime_clear; |
| 2230 | bool mibtime_clear; |
| 2231 | u8 _rsv2[98]; |
| 2232 | } __packed req = { |
| 2233 | .field = cpu_to_le16(RX_AIRTIME_BITWISE_CTRL), |
| 2234 | .sub_field = cpu_to_le16(RX_AIRTIME_CLEAR_EN), |
| 2235 | .airtime_clear = true, |
| 2236 | }; |
| 2237 | int ret; |
| 2238 | |
| 2239 | ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_AIRTIME_CTRL), &req, |
| 2240 | sizeof(req), true); |
| 2241 | if (ret) |
| 2242 | return ret; |
| 2243 | |
| 2244 | req.field = cpu_to_le16(RX_AIRTIME_FEATURE_CTRL); |
| 2245 | req.sub_field = cpu_to_le16(RX_AIRTIME_CLEAR_EN); |
| 2246 | req.airtime_en = true; |
| 2247 | |
| 2248 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_AIRTIME_CTRL), &req, |
| 2249 | sizeof(req), true); |
| 2250 | } |
| 2251 | |
| 2252 | int mt7915_mcu_init(struct mt7915_dev *dev) |
| 2253 | { |
| 2254 | static const struct mt76_mcu_ops mt7915_mcu_ops = { |
| 2255 | .headroom = sizeof(struct mt76_connac2_mcu_txd), |
| 2256 | .mcu_skb_send_msg = mt7915_mcu_send_message, |
| 2257 | .mcu_parse_response = mt7915_mcu_parse_response, |
| 2258 | .mcu_restart = mt76_connac_mcu_restart, |
| 2259 | }; |
| 2260 | int ret; |
| 2261 | |
| 2262 | dev->mt76.mcu_ops = &mt7915_mcu_ops; |
| 2263 | |
| 2264 | /* force firmware operation mode into normal state, |
| 2265 | * which should be set before firmware download stage. |
| 2266 | */ |
| 2267 | mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE); |
| 2268 | |
| 2269 | ret = mt7915_driver_own(dev, 0); |
| 2270 | if (ret) |
| 2271 | return ret; |
| 2272 | /* set driver own for band1 when two hif exist */ |
| 2273 | if (dev->hif2) { |
| 2274 | ret = mt7915_driver_own(dev, 1); |
| 2275 | if (ret) |
| 2276 | return ret; |
| 2277 | } |
| 2278 | |
| 2279 | ret = mt7915_load_firmware(dev); |
| 2280 | if (ret) |
| 2281 | return ret; |
| 2282 | |
| 2283 | set_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); |
| 2284 | ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WM, 0); |
| 2285 | if (ret) |
| 2286 | return ret; |
| 2287 | |
| 2288 | ret = mt7915_mcu_fw_log_2_host(dev, MCU_FW_LOG_WA, 0); |
| 2289 | if (ret) |
| 2290 | return ret; |
| 2291 | |
| 2292 | if (mtk_wed_device_active(&dev->mt76.mmio.wed) && is_mt7915(&dev->mt76)) |
| 2293 | mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(CAPABILITY), 0, 0, 0); |
| 2294 | |
| 2295 | ret = mt7915_mcu_set_mwds(dev, 1); |
| 2296 | if (ret) |
| 2297 | return ret; |
| 2298 | |
| 2299 | ret = mt7915_mcu_set_muru_ctrl(dev, MURU_SET_PLATFORM_TYPE, |
| 2300 | MURU_PLATFORM_TYPE_PERF_LEVEL_2); |
| 2301 | if (ret) |
| 2302 | return ret; |
| 2303 | |
| 2304 | ret = mt7915_mcu_init_rx_airtime(dev); |
| 2305 | if (ret) |
| 2306 | return ret; |
| 2307 | |
| 2308 | return mt7915_mcu_wa_cmd(dev, MCU_WA_PARAM_CMD(SET), |
| 2309 | MCU_WA_PARAM_RED, 0, 0); |
| 2310 | } |
| 2311 | |
| 2312 | void mt7915_mcu_exit(struct mt7915_dev *dev) |
| 2313 | { |
| 2314 | __mt76_mcu_restart(&dev->mt76); |
| 2315 | if (mt7915_firmware_state(dev, false)) { |
| 2316 | dev_err(dev->mt76.dev, "Failed to exit mcu\n"); |
| 2317 | return; |
| 2318 | } |
| 2319 | |
| 2320 | mt76_wr(dev, MT_TOP_LPCR_HOST_BAND(0), MT_TOP_LPCR_HOST_FW_OWN); |
| 2321 | if (dev->hif2) |
| 2322 | mt76_wr(dev, MT_TOP_LPCR_HOST_BAND(1), |
| 2323 | MT_TOP_LPCR_HOST_FW_OWN); |
| 2324 | skb_queue_purge(&dev->mt76.mcu.res_q); |
| 2325 | } |
| 2326 | |
| 2327 | static int |
| 2328 | mt7915_mcu_set_rx_hdr_trans_blacklist(struct mt7915_dev *dev, int band) |
| 2329 | { |
| 2330 | struct { |
| 2331 | u8 operation; |
| 2332 | u8 count; |
| 2333 | u8 _rsv[2]; |
| 2334 | u8 index; |
| 2335 | u8 enable; |
| 2336 | __le16 etype; |
| 2337 | } req = { |
| 2338 | .operation = 1, |
| 2339 | .count = 1, |
| 2340 | .enable = 1, |
| 2341 | .etype = cpu_to_le16(ETH_P_PAE), |
| 2342 | }; |
| 2343 | |
| 2344 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_HDR_TRANS), |
| 2345 | &req, sizeof(req), false); |
| 2346 | } |
| 2347 | |
| 2348 | int mt7915_mcu_set_mac(struct mt7915_dev *dev, int band, |
| 2349 | bool enable, bool hdr_trans) |
| 2350 | { |
| 2351 | struct { |
| 2352 | u8 operation; |
| 2353 | u8 enable; |
| 2354 | u8 check_bssid; |
| 2355 | u8 insert_vlan; |
| 2356 | u8 remove_vlan; |
| 2357 | u8 tid; |
| 2358 | u8 mode; |
| 2359 | u8 rsv; |
| 2360 | } __packed req_trans = { |
| 2361 | .enable = hdr_trans, |
| 2362 | }; |
| 2363 | struct { |
| 2364 | u8 enable; |
| 2365 | u8 band; |
| 2366 | u8 rsv[2]; |
| 2367 | } __packed req_mac = { |
| 2368 | .enable = enable, |
| 2369 | .band = band, |
| 2370 | }; |
| 2371 | int ret; |
| 2372 | |
| 2373 | ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RX_HDR_TRANS), |
| 2374 | &req_trans, sizeof(req_trans), false); |
| 2375 | if (ret) |
| 2376 | return ret; |
| 2377 | |
| 2378 | if (hdr_trans) |
| 2379 | mt7915_mcu_set_rx_hdr_trans_blacklist(dev, band); |
| 2380 | |
| 2381 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(MAC_INIT_CTRL), |
| 2382 | &req_mac, sizeof(req_mac), true); |
| 2383 | } |
| 2384 | |
| 2385 | int mt7915_mcu_update_edca(struct mt7915_dev *dev, void *param) |
| 2386 | { |
| 2387 | struct mt7915_mcu_tx *req = (struct mt7915_mcu_tx *)param; |
| 2388 | u8 num = req->total; |
| 2389 | size_t len = sizeof(*req) - |
| 2390 | (IEEE80211_NUM_ACS - num) * sizeof(struct edca); |
| 2391 | |
| 2392 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EDCA_UPDATE), req, |
| 2393 | len, true); |
| 2394 | } |
| 2395 | |
| 2396 | int mt7915_mcu_set_tx(struct mt7915_dev *dev, struct ieee80211_vif *vif) |
| 2397 | { |
| 2398 | #define TX_CMD_MODE 1 |
| 2399 | struct mt7915_mcu_tx req = { |
| 2400 | .valid = true, |
| 2401 | .mode = TX_CMD_MODE, |
| 2402 | .total = IEEE80211_NUM_ACS, |
| 2403 | }; |
| 2404 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 2405 | int ac; |
| 2406 | |
| 2407 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 2408 | struct ieee80211_tx_queue_params *q = &mvif->queue_params[ac]; |
| 2409 | struct edca *e = &req.edca[ac]; |
| 2410 | |
| 2411 | e->set = WMM_PARAM_SET; |
| 2412 | e->queue = ac + mvif->mt76.wmm_idx * MT76_CONNAC_MAX_WMM_SETS; |
| 2413 | e->aifs = q->aifs; |
| 2414 | e->txop = cpu_to_le16(q->txop); |
| 2415 | |
| 2416 | if (q->cw_min) |
| 2417 | e->cw_min = fls(q->cw_min); |
| 2418 | else |
| 2419 | e->cw_min = 5; |
| 2420 | |
| 2421 | if (q->cw_max) |
| 2422 | e->cw_max = cpu_to_le16(fls(q->cw_max)); |
| 2423 | else |
| 2424 | e->cw_max = cpu_to_le16(10); |
| 2425 | } |
| 2426 | |
| 2427 | return mt7915_mcu_update_edca(dev, &req); |
| 2428 | } |
| 2429 | |
| 2430 | int mt7915_mcu_set_fcc5_lpn(struct mt7915_dev *dev, int val) |
| 2431 | { |
| 2432 | struct { |
| 2433 | __le32 tag; |
| 2434 | __le16 min_lpn; |
| 2435 | u8 rsv[2]; |
| 2436 | } __packed req = { |
| 2437 | .tag = cpu_to_le32(0x1), |
| 2438 | .min_lpn = cpu_to_le16(val), |
| 2439 | }; |
| 2440 | |
| 2441 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_RDD_TH), &req, |
| 2442 | sizeof(req), true); |
| 2443 | } |
| 2444 | |
| 2445 | int mt7915_mcu_set_pulse_th(struct mt7915_dev *dev, |
| 2446 | const struct mt7915_dfs_pulse *pulse) |
| 2447 | { |
| 2448 | struct { |
| 2449 | __le32 tag; |
| 2450 | |
| 2451 | __le32 max_width; /* us */ |
| 2452 | __le32 max_pwr; /* dbm */ |
| 2453 | __le32 min_pwr; /* dbm */ |
| 2454 | __le32 min_stgr_pri; /* us */ |
| 2455 | __le32 max_stgr_pri; /* us */ |
| 2456 | __le32 min_cr_pri; /* us */ |
| 2457 | __le32 max_cr_pri; /* us */ |
| 2458 | } __packed req = { |
| 2459 | .tag = cpu_to_le32(0x3), |
| 2460 | |
| 2461 | #define __req_field(field) .field = cpu_to_le32(pulse->field) |
| 2462 | __req_field(max_width), |
| 2463 | __req_field(max_pwr), |
| 2464 | __req_field(min_pwr), |
| 2465 | __req_field(min_stgr_pri), |
| 2466 | __req_field(max_stgr_pri), |
| 2467 | __req_field(min_cr_pri), |
| 2468 | __req_field(max_cr_pri), |
| 2469 | #undef __req_field |
| 2470 | }; |
| 2471 | |
| 2472 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_RDD_TH), &req, |
| 2473 | sizeof(req), true); |
| 2474 | } |
| 2475 | |
| 2476 | int mt7915_mcu_set_radar_th(struct mt7915_dev *dev, int index, |
| 2477 | const struct mt7915_dfs_pattern *pattern) |
| 2478 | { |
| 2479 | struct { |
| 2480 | __le32 tag; |
| 2481 | __le16 radar_type; |
| 2482 | |
| 2483 | u8 enb; |
| 2484 | u8 stgr; |
| 2485 | u8 min_crpn; |
| 2486 | u8 max_crpn; |
| 2487 | u8 min_crpr; |
| 2488 | u8 min_pw; |
| 2489 | __le32 min_pri; |
| 2490 | __le32 max_pri; |
| 2491 | u8 max_pw; |
| 2492 | u8 min_crbn; |
| 2493 | u8 max_crbn; |
| 2494 | u8 min_stgpn; |
| 2495 | u8 max_stgpn; |
| 2496 | u8 min_stgpr; |
| 2497 | u8 rsv[2]; |
| 2498 | __le32 min_stgpr_diff; |
| 2499 | } __packed req = { |
| 2500 | .tag = cpu_to_le32(0x2), |
| 2501 | .radar_type = cpu_to_le16(index), |
| 2502 | |
| 2503 | #define __req_field_u8(field) .field = pattern->field |
| 2504 | #define __req_field_u32(field) .field = cpu_to_le32(pattern->field) |
| 2505 | __req_field_u8(enb), |
| 2506 | __req_field_u8(stgr), |
| 2507 | __req_field_u8(min_crpn), |
| 2508 | __req_field_u8(max_crpn), |
| 2509 | __req_field_u8(min_crpr), |
| 2510 | __req_field_u8(min_pw), |
| 2511 | __req_field_u32(min_pri), |
| 2512 | __req_field_u32(max_pri), |
| 2513 | __req_field_u8(max_pw), |
| 2514 | __req_field_u8(min_crbn), |
| 2515 | __req_field_u8(max_crbn), |
| 2516 | __req_field_u8(min_stgpn), |
| 2517 | __req_field_u8(max_stgpn), |
| 2518 | __req_field_u8(min_stgpr), |
| 2519 | __req_field_u32(min_stgpr_diff), |
| 2520 | #undef __req_field_u8 |
| 2521 | #undef __req_field_u32 |
| 2522 | }; |
| 2523 | |
| 2524 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_RDD_TH), &req, |
| 2525 | sizeof(req), true); |
| 2526 | } |
| 2527 | |
| 2528 | static int |
| 2529 | mt7915_mcu_background_chain_ctrl(struct mt7915_phy *phy, |
| 2530 | struct cfg80211_chan_def *chandef, |
| 2531 | int cmd) |
| 2532 | { |
| 2533 | struct mt7915_dev *dev = phy->dev; |
| 2534 | struct mt76_phy *mphy = phy->mt76; |
| 2535 | struct ieee80211_channel *chan = mphy->chandef.chan; |
| 2536 | int freq = mphy->chandef.center_freq1; |
| 2537 | struct mt7915_mcu_background_chain_ctrl req = { |
| 2538 | .monitor_scan_type = 2, /* simple rx */ |
| 2539 | }; |
| 2540 | |
| 2541 | if (!chandef && cmd != CH_SWITCH_BACKGROUND_SCAN_STOP) |
| 2542 | return -EINVAL; |
| 2543 | |
| 2544 | if (!cfg80211_chandef_valid(&mphy->chandef)) |
| 2545 | return -EINVAL; |
| 2546 | |
| 2547 | switch (cmd) { |
| 2548 | case CH_SWITCH_BACKGROUND_SCAN_START: { |
| 2549 | req.chan = chan->hw_value; |
| 2550 | req.central_chan = ieee80211_frequency_to_channel(freq); |
| 2551 | req.bw = mt76_connac_chan_bw(&mphy->chandef); |
| 2552 | req.monitor_chan = chandef->chan->hw_value; |
| 2553 | req.monitor_central_chan = |
| 2554 | ieee80211_frequency_to_channel(chandef->center_freq1); |
| 2555 | req.monitor_bw = mt76_connac_chan_bw(chandef); |
| 2556 | req.band_idx = phy != &dev->phy; |
| 2557 | req.scan_mode = 1; |
| 2558 | break; |
| 2559 | } |
| 2560 | case CH_SWITCH_BACKGROUND_SCAN_RUNNING: |
| 2561 | req.monitor_chan = chandef->chan->hw_value; |
| 2562 | req.monitor_central_chan = |
| 2563 | ieee80211_frequency_to_channel(chandef->center_freq1); |
| 2564 | req.band_idx = phy != &dev->phy; |
| 2565 | req.scan_mode = 2; |
| 2566 | break; |
| 2567 | case CH_SWITCH_BACKGROUND_SCAN_STOP: |
| 2568 | req.chan = chan->hw_value; |
| 2569 | req.central_chan = ieee80211_frequency_to_channel(freq); |
| 2570 | req.bw = mt76_connac_chan_bw(&mphy->chandef); |
| 2571 | req.tx_stream = hweight8(mphy->antenna_mask); |
| 2572 | req.rx_stream = mphy->antenna_mask; |
| 2573 | break; |
| 2574 | default: |
| 2575 | return -EINVAL; |
| 2576 | } |
| 2577 | req.band = chandef ? chandef->chan->band == NL80211_BAND_5GHZ : 1; |
| 2578 | |
| 2579 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(OFFCH_SCAN_CTRL), |
| 2580 | &req, sizeof(req), false); |
| 2581 | } |
| 2582 | |
| 2583 | int mt7915_mcu_rdd_background_enable(struct mt7915_phy *phy, |
| 2584 | struct cfg80211_chan_def *chandef) |
| 2585 | { |
| 2586 | struct mt7915_dev *dev = phy->dev; |
| 2587 | int err, region; |
| 2588 | |
| 2589 | if (!chandef) { /* disable offchain */ |
| 2590 | err = mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_STOP, MT_RX_SEL2, |
| 2591 | 0, 0); |
| 2592 | if (err) |
| 2593 | return err; |
| 2594 | |
| 2595 | return mt7915_mcu_background_chain_ctrl(phy, NULL, |
| 2596 | CH_SWITCH_BACKGROUND_SCAN_STOP); |
| 2597 | } |
| 2598 | |
| 2599 | err = mt7915_mcu_background_chain_ctrl(phy, chandef, |
| 2600 | CH_SWITCH_BACKGROUND_SCAN_START); |
| 2601 | if (err) |
| 2602 | return err; |
| 2603 | |
| 2604 | switch (dev->mt76.region) { |
| 2605 | case NL80211_DFS_ETSI: |
| 2606 | region = 0; |
| 2607 | break; |
| 2608 | case NL80211_DFS_JP: |
| 2609 | region = 2; |
| 2610 | break; |
| 2611 | case NL80211_DFS_FCC: |
| 2612 | default: |
| 2613 | region = 1; |
| 2614 | break; |
| 2615 | } |
| 2616 | |
| 2617 | return mt76_connac_mcu_rdd_cmd(&dev->mt76, RDD_START, MT_RX_SEL2, |
| 2618 | 0, region); |
| 2619 | } |
| 2620 | |
| 2621 | int mt7915_mcu_set_chan_info(struct mt7915_phy *phy, int cmd) |
| 2622 | { |
| 2623 | static const u8 ch_band[] = { |
| 2624 | [NL80211_BAND_2GHZ] = 0, |
| 2625 | [NL80211_BAND_5GHZ] = 1, |
| 2626 | [NL80211_BAND_6GHZ] = 2, |
| 2627 | }; |
| 2628 | struct mt7915_dev *dev = phy->dev; |
| 2629 | struct cfg80211_chan_def *chandef = &phy->mt76->chandef; |
| 2630 | int freq1 = chandef->center_freq1; |
| 2631 | struct { |
| 2632 | u8 control_ch; |
| 2633 | u8 center_ch; |
| 2634 | u8 bw; |
| 2635 | u8 tx_streams_num; |
| 2636 | u8 rx_streams; /* mask or num */ |
| 2637 | u8 switch_reason; |
| 2638 | u8 band_idx; |
| 2639 | u8 center_ch2; /* for 80+80 only */ |
| 2640 | __le16 cac_case; |
| 2641 | u8 channel_band; |
| 2642 | u8 rsv0; |
| 2643 | __le32 outband_freq; |
| 2644 | u8 txpower_drop; |
| 2645 | u8 ap_bw; |
| 2646 | u8 ap_center_ch; |
| 2647 | u8 rsv1[57]; |
| 2648 | } __packed req = { |
| 2649 | .control_ch = chandef->chan->hw_value, |
| 2650 | .center_ch = ieee80211_frequency_to_channel(freq1), |
| 2651 | .bw = mt76_connac_chan_bw(chandef), |
| 2652 | .tx_streams_num = hweight8(phy->mt76->antenna_mask), |
| 2653 | .rx_streams = phy->mt76->antenna_mask, |
| 2654 | .band_idx = phy->band_idx, |
| 2655 | .channel_band = ch_band[chandef->chan->band], |
| 2656 | }; |
| 2657 | |
| 2658 | #ifdef CONFIG_NL80211_TESTMODE |
| 2659 | if (phy->mt76->test.tx_antenna_mask && |
| 2660 | mt76_testmode_enabled(phy->mt76)) { |
| 2661 | req.tx_streams_num = fls(phy->mt76->test.tx_antenna_mask); |
| 2662 | req.rx_streams = phy->mt76->test.tx_antenna_mask; |
| 2663 | } |
| 2664 | #endif |
| 2665 | |
| 2666 | if (mt76_connac_spe_idx(phy->mt76->antenna_mask)) |
| 2667 | req.tx_streams_num = fls(phy->mt76->antenna_mask); |
| 2668 | |
| 2669 | if (cmd == MCU_EXT_CMD(SET_RX_PATH) || |
| 2670 | dev->mt76.hw->conf.flags & IEEE80211_CONF_MONITOR) |
| 2671 | req.switch_reason = CH_SWITCH_NORMAL; |
| 2672 | else if (phy->mt76->hw->conf.flags & IEEE80211_CONF_OFFCHANNEL) |
| 2673 | req.switch_reason = CH_SWITCH_SCAN_BYPASS_DPD; |
| 2674 | else if (!cfg80211_reg_can_beacon(phy->mt76->hw->wiphy, chandef, |
| 2675 | NL80211_IFTYPE_AP)) |
| 2676 | req.switch_reason = CH_SWITCH_DFS; |
| 2677 | else |
| 2678 | req.switch_reason = CH_SWITCH_NORMAL; |
| 2679 | |
| 2680 | if (cmd == MCU_EXT_CMD(CHANNEL_SWITCH)) |
| 2681 | req.rx_streams = hweight8(req.rx_streams); |
| 2682 | |
| 2683 | if (chandef->width == NL80211_CHAN_WIDTH_80P80) { |
| 2684 | int freq2 = chandef->center_freq2; |
| 2685 | |
| 2686 | req.center_ch2 = ieee80211_frequency_to_channel(freq2); |
| 2687 | } |
| 2688 | |
| 2689 | return mt76_mcu_send_msg(&dev->mt76, cmd, &req, sizeof(req), true); |
| 2690 | } |
| 2691 | |
| 2692 | static int mt7915_mcu_set_eeprom_flash(struct mt7915_dev *dev) |
| 2693 | { |
| 2694 | #define MAX_PAGE_IDX_MASK GENMASK(7, 5) |
| 2695 | #define PAGE_IDX_MASK GENMASK(4, 2) |
| 2696 | #define PER_PAGE_SIZE 0x400 |
| 2697 | struct mt7915_mcu_eeprom req = { .buffer_mode = EE_MODE_BUFFER }; |
| 2698 | u16 eeprom_size = mt7915_eeprom_size(dev); |
| 2699 | u8 total = DIV_ROUND_UP(eeprom_size, PER_PAGE_SIZE); |
| 2700 | u8 *eep = (u8 *)dev->mt76.eeprom.data; |
| 2701 | int eep_len; |
| 2702 | int i; |
| 2703 | |
| 2704 | for (i = 0; i < total; i++, eep += eep_len) { |
| 2705 | struct sk_buff *skb; |
| 2706 | int ret; |
| 2707 | |
| 2708 | if (i == total - 1 && !!(eeprom_size % PER_PAGE_SIZE)) |
| 2709 | eep_len = eeprom_size % PER_PAGE_SIZE; |
| 2710 | else |
| 2711 | eep_len = PER_PAGE_SIZE; |
| 2712 | |
| 2713 | skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, |
| 2714 | sizeof(req) + eep_len); |
| 2715 | if (!skb) |
| 2716 | return -ENOMEM; |
| 2717 | |
| 2718 | req.format = FIELD_PREP(MAX_PAGE_IDX_MASK, total - 1) | |
| 2719 | FIELD_PREP(PAGE_IDX_MASK, i) | EE_FORMAT_WHOLE; |
| 2720 | req.len = cpu_to_le16(eep_len); |
| 2721 | |
| 2722 | skb_put_data(skb, &req, sizeof(req)); |
| 2723 | skb_put_data(skb, eep, eep_len); |
| 2724 | |
| 2725 | ret = mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 2726 | MCU_EXT_CMD(EFUSE_BUFFER_MODE), true); |
| 2727 | if (ret) |
| 2728 | return ret; |
| 2729 | } |
| 2730 | |
| 2731 | return 0; |
| 2732 | } |
| 2733 | |
| 2734 | int mt7915_mcu_set_eeprom(struct mt7915_dev *dev) |
| 2735 | { |
| 2736 | struct mt7915_mcu_eeprom req = { |
| 2737 | .buffer_mode = EE_MODE_EFUSE, |
| 2738 | .format = EE_FORMAT_WHOLE, |
| 2739 | }; |
| 2740 | |
| 2741 | if (dev->flash_mode) |
| 2742 | return mt7915_mcu_set_eeprom_flash(dev); |
| 2743 | |
| 2744 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(EFUSE_BUFFER_MODE), |
| 2745 | &req, sizeof(req), true); |
| 2746 | } |
| 2747 | |
| 2748 | int mt7915_mcu_get_eeprom(struct mt7915_dev *dev, u32 offset) |
| 2749 | { |
| 2750 | struct mt7915_mcu_eeprom_info req = { |
| 2751 | .addr = cpu_to_le32(round_down(offset, |
| 2752 | MT7915_EEPROM_BLOCK_SIZE)), |
| 2753 | }; |
| 2754 | struct mt7915_mcu_eeprom_info *res; |
| 2755 | struct sk_buff *skb; |
| 2756 | int ret; |
| 2757 | u8 *buf; |
| 2758 | |
| 2759 | ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(EFUSE_ACCESS), &req, |
| 2760 | sizeof(req), true, &skb); |
| 2761 | if (ret) |
| 2762 | return ret; |
| 2763 | |
| 2764 | res = (struct mt7915_mcu_eeprom_info *)skb->data; |
| 2765 | buf = dev->mt76.eeprom.data + le32_to_cpu(res->addr); |
| 2766 | memcpy(buf, res->data, MT7915_EEPROM_BLOCK_SIZE); |
| 2767 | dev_kfree_skb(skb); |
| 2768 | |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | int mt7915_mcu_get_eeprom_free_block(struct mt7915_dev *dev, u8 *block_num) |
| 2773 | { |
| 2774 | struct { |
| 2775 | u8 _rsv; |
| 2776 | u8 version; |
| 2777 | u8 die_idx; |
| 2778 | u8 _rsv2; |
| 2779 | } __packed req = { |
| 2780 | .version = 1, |
| 2781 | }; |
| 2782 | struct sk_buff *skb; |
| 2783 | int ret; |
| 2784 | |
| 2785 | ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(EFUSE_FREE_BLOCK), &req, |
| 2786 | sizeof(req), true, &skb); |
| 2787 | if (ret) |
| 2788 | return ret; |
| 2789 | |
| 2790 | *block_num = *(u8 *)skb->data; |
| 2791 | dev_kfree_skb(skb); |
| 2792 | |
| 2793 | return 0; |
| 2794 | } |
| 2795 | |
| 2796 | static int mt7915_mcu_set_pre_cal(struct mt7915_dev *dev, u8 idx, |
| 2797 | u8 *data, u32 len, int cmd) |
| 2798 | { |
| 2799 | struct { |
| 2800 | u8 dir; |
| 2801 | u8 valid; |
| 2802 | __le16 bitmap; |
| 2803 | s8 precal; |
| 2804 | u8 action; |
| 2805 | u8 band; |
| 2806 | u8 idx; |
| 2807 | u8 rsv[4]; |
| 2808 | __le32 len; |
| 2809 | } req = {}; |
| 2810 | struct sk_buff *skb; |
| 2811 | |
| 2812 | skb = mt76_mcu_msg_alloc(&dev->mt76, NULL, sizeof(req) + len); |
| 2813 | if (!skb) |
| 2814 | return -ENOMEM; |
| 2815 | |
| 2816 | req.idx = idx; |
| 2817 | req.len = cpu_to_le32(len); |
| 2818 | skb_put_data(skb, &req, sizeof(req)); |
| 2819 | skb_put_data(skb, data, len); |
| 2820 | |
| 2821 | return mt76_mcu_skb_send_msg(&dev->mt76, skb, cmd, false); |
| 2822 | } |
| 2823 | |
| 2824 | int mt7915_mcu_apply_group_cal(struct mt7915_dev *dev) |
| 2825 | { |
| 2826 | u8 idx = 0, *cal = dev->cal, *eep = dev->mt76.eeprom.data; |
| 2827 | u32 total = MT_EE_CAL_GROUP_SIZE; |
| 2828 | |
| 2829 | if (1 || !(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_GROUP)) |
| 2830 | return 0; |
| 2831 | |
| 2832 | /* |
| 2833 | * Items: Rx DCOC, RSSI DCOC, Tx TSSI DCOC, Tx LPFG |
| 2834 | * Tx FDIQ, Tx DCIQ, Rx FDIQ, Rx FIIQ, ADCDCOC |
| 2835 | */ |
| 2836 | while (total > 0) { |
| 2837 | int ret, len; |
| 2838 | |
| 2839 | len = min_t(u32, total, MT_EE_CAL_UNIT); |
| 2840 | |
| 2841 | ret = mt7915_mcu_set_pre_cal(dev, idx, cal, len, |
| 2842 | MCU_EXT_CMD(GROUP_PRE_CAL_INFO)); |
| 2843 | if (ret) |
| 2844 | return ret; |
| 2845 | |
| 2846 | total -= len; |
| 2847 | cal += len; |
| 2848 | idx++; |
| 2849 | } |
| 2850 | |
| 2851 | return 0; |
| 2852 | } |
| 2853 | |
| 2854 | static int mt7915_find_freq_idx(const u16 *freqs, int n_freqs, u16 cur) |
| 2855 | { |
| 2856 | int i; |
| 2857 | |
| 2858 | for (i = 0; i < n_freqs; i++) |
| 2859 | if (cur == freqs[i]) |
| 2860 | return i; |
| 2861 | |
| 2862 | return -1; |
| 2863 | } |
| 2864 | |
| 2865 | static int mt7915_dpd_freq_idx(u16 freq, u8 bw) |
| 2866 | { |
| 2867 | static const u16 freq_list[] = { |
| 2868 | 5180, 5200, 5220, 5240, |
| 2869 | 5260, 5280, 5300, 5320, |
| 2870 | 5500, 5520, 5540, 5560, |
| 2871 | 5580, 5600, 5620, 5640, |
| 2872 | 5660, 5680, 5700, 5745, |
| 2873 | 5765, 5785, 5805, 5825 |
| 2874 | }; |
| 2875 | int offset_2g = ARRAY_SIZE(freq_list); |
| 2876 | int idx; |
| 2877 | |
| 2878 | if (freq < 4000) { |
| 2879 | if (freq < 2432) |
| 2880 | return offset_2g; |
| 2881 | if (freq < 2457) |
| 2882 | return offset_2g + 1; |
| 2883 | |
| 2884 | return offset_2g + 2; |
| 2885 | } |
| 2886 | |
| 2887 | if (bw == NL80211_CHAN_WIDTH_80P80 || bw == NL80211_CHAN_WIDTH_160) |
| 2888 | return -1; |
| 2889 | |
| 2890 | if (bw != NL80211_CHAN_WIDTH_20) { |
| 2891 | idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), |
| 2892 | freq + 10); |
| 2893 | if (idx >= 0) |
| 2894 | return idx; |
| 2895 | |
| 2896 | idx = mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), |
| 2897 | freq - 10); |
| 2898 | if (idx >= 0) |
| 2899 | return idx; |
| 2900 | } |
| 2901 | |
| 2902 | return mt7915_find_freq_idx(freq_list, ARRAY_SIZE(freq_list), freq); |
| 2903 | } |
| 2904 | |
| 2905 | int mt7915_mcu_apply_tx_dpd(struct mt7915_phy *phy) |
| 2906 | { |
| 2907 | struct mt7915_dev *dev = phy->dev; |
| 2908 | struct cfg80211_chan_def *chandef = &phy->mt76->chandef; |
| 2909 | u16 total = 2, center_freq = chandef->center_freq1; |
| 2910 | u8 *cal = dev->cal, *eep = dev->mt76.eeprom.data; |
| 2911 | int idx; |
| 2912 | |
| 2913 | if (1 || !(eep[MT_EE_DO_PRE_CAL] & MT_EE_WIFI_CAL_DPD)) |
| 2914 | return 0; |
| 2915 | |
| 2916 | idx = mt7915_dpd_freq_idx(center_freq, chandef->width); |
| 2917 | if (idx < 0) |
| 2918 | return -EINVAL; |
| 2919 | |
| 2920 | /* Items: Tx DPD, Tx Flatness */ |
| 2921 | idx = idx * 2; |
| 2922 | cal += MT_EE_CAL_GROUP_SIZE; |
| 2923 | |
| 2924 | while (total--) { |
| 2925 | int ret; |
| 2926 | |
| 2927 | cal += (idx * MT_EE_CAL_UNIT); |
| 2928 | ret = mt7915_mcu_set_pre_cal(dev, idx, cal, MT_EE_CAL_UNIT, |
| 2929 | MCU_EXT_CMD(DPD_PRE_CAL_INFO)); |
| 2930 | if (ret) |
| 2931 | return ret; |
| 2932 | |
| 2933 | idx++; |
| 2934 | } |
| 2935 | |
| 2936 | return 0; |
| 2937 | } |
| 2938 | |
| 2939 | int mt7915_mcu_get_chan_mib_info(struct mt7915_phy *phy, bool chan_switch) |
| 2940 | { |
| 2941 | /* strict order */ |
| 2942 | static const u32 offs[] = { |
| 2943 | MIB_BUSY_TIME, MIB_TX_TIME, MIB_RX_TIME, MIB_OBSS_AIRTIME, |
| 2944 | MIB_BUSY_TIME_V2, MIB_TX_TIME_V2, MIB_RX_TIME_V2, |
| 2945 | MIB_OBSS_AIRTIME_V2 |
| 2946 | }; |
| 2947 | struct mt76_channel_state *state = phy->mt76->chan_state; |
| 2948 | struct mt76_channel_state *state_ts = &phy->state_ts; |
| 2949 | struct mt7915_dev *dev = phy->dev; |
| 2950 | struct mt7915_mcu_mib *res, req[4]; |
| 2951 | struct sk_buff *skb; |
| 2952 | int i, ret, start = 0, ofs = 20; |
| 2953 | |
| 2954 | if (!is_mt7915(&dev->mt76)) { |
| 2955 | start = 4; |
| 2956 | ofs = 0; |
| 2957 | } |
| 2958 | |
| 2959 | for (i = 0; i < 4; i++) { |
| 2960 | req[i].band = cpu_to_le32(phy != &dev->phy); |
| 2961 | req[i].offs = cpu_to_le32(offs[i + start]); |
| 2962 | } |
| 2963 | |
| 2964 | ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_CMD(GET_MIB_INFO), |
| 2965 | req, sizeof(req), true, &skb); |
| 2966 | if (ret) |
| 2967 | return ret; |
| 2968 | |
| 2969 | res = (struct mt7915_mcu_mib *)(skb->data + ofs); |
| 2970 | |
| 2971 | if (chan_switch) |
| 2972 | goto out; |
| 2973 | |
| 2974 | #define __res_u64(s) le64_to_cpu(res[s].data) |
| 2975 | state->cc_busy += __res_u64(0) - state_ts->cc_busy; |
| 2976 | state->cc_tx += __res_u64(1) - state_ts->cc_tx; |
| 2977 | state->cc_bss_rx += __res_u64(2) - state_ts->cc_bss_rx; |
| 2978 | state->cc_rx += __res_u64(2) + __res_u64(3) - state_ts->cc_rx; |
| 2979 | |
| 2980 | out: |
| 2981 | state_ts->cc_busy = __res_u64(0); |
| 2982 | state_ts->cc_tx = __res_u64(1); |
| 2983 | state_ts->cc_bss_rx = __res_u64(2); |
| 2984 | state_ts->cc_rx = __res_u64(2) + __res_u64(3); |
| 2985 | #undef __res_u64 |
| 2986 | |
| 2987 | dev_kfree_skb(skb); |
| 2988 | |
| 2989 | return 0; |
| 2990 | } |
| 2991 | |
| 2992 | int mt7915_mcu_get_temperature(struct mt7915_phy *phy) |
| 2993 | { |
| 2994 | struct mt7915_dev *dev = phy->dev; |
| 2995 | struct { |
| 2996 | u8 ctrl_id; |
| 2997 | u8 action; |
| 2998 | u8 dbdc_idx; |
| 2999 | u8 rsv[5]; |
| 3000 | } req = { |
| 3001 | .ctrl_id = THERMAL_SENSOR_TEMP_QUERY, |
| 3002 | .dbdc_idx = phy != &dev->phy, |
| 3003 | }; |
| 3004 | |
| 3005 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_CTRL), &req, |
| 3006 | sizeof(req), true); |
| 3007 | } |
| 3008 | |
| 3009 | int mt7915_mcu_set_thermal_throttling(struct mt7915_phy *phy, u8 state) |
| 3010 | { |
| 3011 | struct mt7915_dev *dev = phy->dev; |
| 3012 | struct { |
| 3013 | struct mt7915_mcu_thermal_ctrl ctrl; |
| 3014 | |
| 3015 | __le32 trigger_temp; |
| 3016 | __le32 restore_temp; |
| 3017 | __le16 sustain_time; |
| 3018 | u8 rsv[2]; |
| 3019 | } __packed req = { |
| 3020 | .ctrl = { |
| 3021 | .band_idx = phy->band_idx, |
| 3022 | }, |
| 3023 | }; |
| 3024 | int level; |
| 3025 | |
| 3026 | if (!state) { |
| 3027 | req.ctrl.ctrl_id = THERMAL_PROTECT_DISABLE; |
| 3028 | goto out; |
| 3029 | } |
| 3030 | |
| 3031 | /* set duty cycle and level */ |
| 3032 | for (level = 0; level < 4; level++) { |
| 3033 | int ret; |
| 3034 | |
| 3035 | req.ctrl.ctrl_id = THERMAL_PROTECT_DUTY_CONFIG; |
| 3036 | req.ctrl.duty.duty_level = level; |
| 3037 | req.ctrl.duty.duty_cycle = state; |
| 3038 | state /= 2; |
| 3039 | |
| 3040 | ret = mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT), |
| 3041 | &req, sizeof(req.ctrl), false); |
| 3042 | if (ret) |
| 3043 | return ret; |
| 3044 | } |
| 3045 | |
| 3046 | /* set high-temperature trigger threshold */ |
| 3047 | req.ctrl.ctrl_id = THERMAL_PROTECT_ENABLE; |
| 3048 | /* add a safety margin ~10 */ |
| 3049 | req.restore_temp = cpu_to_le32(phy->throttle_temp[0] - 10); |
| 3050 | req.trigger_temp = cpu_to_le32(phy->throttle_temp[1]); |
| 3051 | req.sustain_time = cpu_to_le16(10); |
| 3052 | |
| 3053 | out: |
| 3054 | req.ctrl.type.protect_type = 1; |
| 3055 | req.ctrl.type.trigger_type = 1; |
| 3056 | |
| 3057 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(THERMAL_PROT), |
| 3058 | &req, sizeof(req), false); |
| 3059 | } |
| 3060 | |
| 3061 | int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy) |
| 3062 | { |
| 3063 | struct mt7915_dev *dev = phy->dev; |
| 3064 | struct mt76_phy *mphy = phy->mt76; |
| 3065 | struct ieee80211_hw *hw = mphy->hw; |
| 3066 | struct mt7915_sku_val { |
| 3067 | u8 format_id; |
| 3068 | u8 limit_type; |
| 3069 | u8 dbdc_idx; |
| 3070 | s8 val[MT7915_SKU_RATE_NUM]; |
| 3071 | } __packed req = { |
| 3072 | .format_id = 4, |
| 3073 | .dbdc_idx = phy != &dev->phy, |
| 3074 | }; |
| 3075 | struct mt76_power_limits limits_array; |
| 3076 | s8 *la = (s8 *)&limits_array; |
| 3077 | int i, idx, n_chains = hweight8(mphy->antenna_mask); |
| 3078 | int tx_power = hw->conf.power_level * 2; |
| 3079 | |
| 3080 | tx_power = mt76_get_sar_power(mphy, mphy->chandef.chan, |
| 3081 | tx_power); |
| 3082 | tx_power -= mt76_tx_power_nss_delta(n_chains); |
| 3083 | tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan, |
| 3084 | &limits_array, tx_power); |
| 3085 | mphy->txpower_cur = tx_power; |
| 3086 | |
| 3087 | for (i = 0, idx = 0; i < ARRAY_SIZE(mt7915_sku_group_len); i++) { |
| 3088 | u8 mcs_num, len = mt7915_sku_group_len[i]; |
| 3089 | int j; |
| 3090 | |
| 3091 | if (i >= SKU_HT_BW20 && i <= SKU_VHT_BW160) { |
| 3092 | mcs_num = 10; |
| 3093 | |
| 3094 | if (i == SKU_HT_BW20 || i == SKU_VHT_BW20) |
| 3095 | la = (s8 *)&limits_array + 12; |
| 3096 | } else { |
| 3097 | mcs_num = len; |
| 3098 | } |
| 3099 | |
| 3100 | for (j = 0; j < min_t(u8, mcs_num, len); j++) |
| 3101 | req.val[idx + j] = la[j]; |
| 3102 | |
| 3103 | la += mcs_num; |
| 3104 | idx += len; |
| 3105 | } |
| 3106 | |
| 3107 | return mt76_mcu_send_msg(&dev->mt76, |
| 3108 | MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req, |
| 3109 | sizeof(req), true); |
| 3110 | } |
| 3111 | |
| 3112 | int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len) |
| 3113 | { |
| 3114 | #define RATE_POWER_INFO 2 |
| 3115 | struct mt7915_dev *dev = phy->dev; |
| 3116 | struct { |
| 3117 | u8 format_id; |
| 3118 | u8 category; |
| 3119 | u8 band; |
| 3120 | u8 _rsv; |
| 3121 | } __packed req = { |
| 3122 | .format_id = 7, |
| 3123 | .category = RATE_POWER_INFO, |
| 3124 | .band = phy != &dev->phy, |
| 3125 | }; |
| 3126 | s8 res[MT7915_SKU_RATE_NUM][2]; |
| 3127 | struct sk_buff *skb; |
| 3128 | int ret, i; |
| 3129 | |
| 3130 | ret = mt76_mcu_send_and_get_msg(&dev->mt76, |
| 3131 | MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), |
| 3132 | &req, sizeof(req), true, &skb); |
| 3133 | if (ret) |
| 3134 | return ret; |
| 3135 | |
| 3136 | memcpy(res, skb->data + 4, sizeof(res)); |
| 3137 | for (i = 0; i < len; i++) |
| 3138 | txpower[i] = res[i][req.band]; |
| 3139 | |
| 3140 | dev_kfree_skb(skb); |
| 3141 | |
| 3142 | return 0; |
| 3143 | } |
| 3144 | |
| 3145 | int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode, |
| 3146 | u8 en) |
| 3147 | { |
| 3148 | struct { |
| 3149 | u8 test_mode_en; |
| 3150 | u8 param_idx; |
| 3151 | u8 _rsv[2]; |
| 3152 | |
| 3153 | u8 enable; |
| 3154 | u8 _rsv2[3]; |
| 3155 | |
| 3156 | u8 pad[8]; |
| 3157 | } __packed req = { |
| 3158 | .test_mode_en = test_mode, |
| 3159 | .param_idx = param, |
| 3160 | .enable = en, |
| 3161 | }; |
| 3162 | |
| 3163 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(ATE_CTRL), &req, |
| 3164 | sizeof(req), false); |
| 3165 | } |
| 3166 | |
| 3167 | int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable) |
| 3168 | { |
| 3169 | struct mt7915_dev *dev = phy->dev; |
| 3170 | struct mt7915_sku { |
| 3171 | u8 format_id; |
| 3172 | u8 sku_enable; |
| 3173 | u8 dbdc_idx; |
| 3174 | u8 rsv; |
| 3175 | } __packed req = { |
| 3176 | .format_id = 0, |
| 3177 | .dbdc_idx = phy != &dev->phy, |
| 3178 | .sku_enable = enable, |
| 3179 | }; |
| 3180 | |
| 3181 | return mt76_mcu_send_msg(&dev->mt76, |
| 3182 | MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req, |
| 3183 | sizeof(req), true); |
| 3184 | } |
| 3185 | |
| 3186 | int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band) |
| 3187 | { |
| 3188 | struct { |
| 3189 | u8 action; |
| 3190 | u8 set; |
| 3191 | u8 band; |
| 3192 | u8 rsv; |
| 3193 | } req = { |
| 3194 | .action = action, |
| 3195 | .set = set, |
| 3196 | .band = band, |
| 3197 | }; |
| 3198 | |
| 3199 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_SER_TRIGGER), |
| 3200 | &req, sizeof(req), false); |
| 3201 | } |
| 3202 | |
| 3203 | int mt7915_mcu_set_txbf(struct mt7915_dev *dev, u8 action) |
| 3204 | { |
| 3205 | struct { |
| 3206 | u8 action; |
| 3207 | union { |
| 3208 | struct { |
| 3209 | u8 snd_mode; |
| 3210 | u8 sta_num; |
| 3211 | u8 rsv; |
| 3212 | u8 wlan_idx[4]; |
| 3213 | __le32 snd_period; /* ms */ |
| 3214 | } __packed snd; |
| 3215 | struct { |
| 3216 | bool ebf; |
| 3217 | bool ibf; |
| 3218 | u8 rsv; |
| 3219 | } __packed type; |
| 3220 | struct { |
| 3221 | u8 bf_num; |
| 3222 | u8 bf_bitmap; |
| 3223 | u8 bf_sel[8]; |
| 3224 | u8 rsv[5]; |
| 3225 | } __packed mod; |
| 3226 | }; |
| 3227 | } __packed req = { |
| 3228 | .action = action, |
| 3229 | }; |
| 3230 | |
| 3231 | #define MT_BF_PROCESSING 4 |
| 3232 | switch (action) { |
| 3233 | case MT_BF_SOUNDING_ON: |
| 3234 | req.snd.snd_mode = MT_BF_PROCESSING; |
| 3235 | break; |
| 3236 | case MT_BF_TYPE_UPDATE: |
| 3237 | req.type.ebf = true; |
| 3238 | req.type.ibf = dev->ibf; |
| 3239 | break; |
| 3240 | case MT_BF_MODULE_UPDATE: |
| 3241 | req.mod.bf_num = 2; |
| 3242 | req.mod.bf_bitmap = GENMASK(1, 0); |
| 3243 | break; |
| 3244 | default: |
| 3245 | return -EINVAL; |
| 3246 | } |
| 3247 | |
| 3248 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TXBF_ACTION), &req, |
| 3249 | sizeof(req), true); |
| 3250 | } |
| 3251 | |
| 3252 | int mt7915_mcu_add_obss_spr(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 3253 | bool enable) |
| 3254 | { |
| 3255 | #define MT_SPR_ENABLE 1 |
| 3256 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 3257 | struct { |
| 3258 | u8 action; |
| 3259 | u8 arg_num; |
| 3260 | u8 band_idx; |
| 3261 | u8 status; |
| 3262 | u8 drop_tx_idx; |
| 3263 | u8 sta_idx; /* 256 sta */ |
| 3264 | u8 rsv[2]; |
| 3265 | __le32 val; |
| 3266 | } __packed req = { |
| 3267 | .action = MT_SPR_ENABLE, |
| 3268 | .arg_num = 1, |
| 3269 | .band_idx = mvif->mt76.band_idx, |
| 3270 | .val = cpu_to_le32(enable), |
| 3271 | }; |
| 3272 | |
| 3273 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(SET_SPR), &req, |
| 3274 | sizeof(req), true); |
| 3275 | } |
| 3276 | |
| 3277 | int mt7915_mcu_get_rx_rate(struct mt7915_phy *phy, struct ieee80211_vif *vif, |
| 3278 | struct ieee80211_sta *sta, struct rate_info *rate) |
| 3279 | { |
| 3280 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 3281 | struct mt7915_sta *msta = (struct mt7915_sta *)sta->drv_priv; |
| 3282 | struct mt7915_dev *dev = phy->dev; |
| 3283 | struct mt76_phy *mphy = phy->mt76; |
| 3284 | struct { |
| 3285 | u8 category; |
| 3286 | u8 band; |
| 3287 | __le16 wcid; |
| 3288 | } __packed req = { |
| 3289 | .category = MCU_PHY_STATE_CONTENTION_RX_RATE, |
| 3290 | .band = mvif->mt76.band_idx, |
| 3291 | .wcid = cpu_to_le16(msta->wcid.idx), |
| 3292 | }; |
| 3293 | struct ieee80211_supported_band *sband; |
| 3294 | struct mt7915_mcu_phy_rx_info *res; |
| 3295 | struct sk_buff *skb; |
| 3296 | int ret; |
| 3297 | bool cck = false; |
| 3298 | |
| 3299 | ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_CMD(PHY_STAT_INFO), |
| 3300 | &req, sizeof(req), true, &skb); |
| 3301 | if (ret) |
| 3302 | return ret; |
| 3303 | |
| 3304 | res = (struct mt7915_mcu_phy_rx_info *)skb->data; |
| 3305 | |
| 3306 | rate->mcs = res->rate; |
| 3307 | rate->nss = res->nsts + 1; |
| 3308 | |
| 3309 | switch (res->mode) { |
| 3310 | case MT_PHY_TYPE_CCK: |
| 3311 | cck = true; |
| 3312 | fallthrough; |
| 3313 | case MT_PHY_TYPE_OFDM: |
| 3314 | if (mphy->chandef.chan->band == NL80211_BAND_5GHZ) |
| 3315 | sband = &mphy->sband_5g.sband; |
| 3316 | else if (mphy->chandef.chan->band == NL80211_BAND_6GHZ) |
| 3317 | sband = &mphy->sband_6g.sband; |
| 3318 | else |
| 3319 | sband = &mphy->sband_2g.sband; |
| 3320 | |
| 3321 | rate->mcs = mt76_get_rate(&dev->mt76, sband, rate->mcs, cck); |
| 3322 | rate->legacy = sband->bitrates[rate->mcs].bitrate; |
| 3323 | break; |
| 3324 | case MT_PHY_TYPE_HT: |
| 3325 | case MT_PHY_TYPE_HT_GF: |
| 3326 | if (rate->mcs > 31) { |
| 3327 | ret = -EINVAL; |
| 3328 | goto out; |
| 3329 | } |
| 3330 | |
| 3331 | rate->flags = RATE_INFO_FLAGS_MCS; |
| 3332 | if (res->gi) |
| 3333 | rate->flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 3334 | break; |
| 3335 | case MT_PHY_TYPE_VHT: |
| 3336 | if (rate->mcs > 9) { |
| 3337 | ret = -EINVAL; |
| 3338 | goto out; |
| 3339 | } |
| 3340 | |
| 3341 | rate->flags = RATE_INFO_FLAGS_VHT_MCS; |
| 3342 | if (res->gi) |
| 3343 | rate->flags |= RATE_INFO_FLAGS_SHORT_GI; |
| 3344 | break; |
| 3345 | case MT_PHY_TYPE_HE_SU: |
| 3346 | case MT_PHY_TYPE_HE_EXT_SU: |
| 3347 | case MT_PHY_TYPE_HE_TB: |
| 3348 | case MT_PHY_TYPE_HE_MU: |
| 3349 | if (res->gi > NL80211_RATE_INFO_HE_GI_3_2 || rate->mcs > 11) { |
| 3350 | ret = -EINVAL; |
| 3351 | goto out; |
| 3352 | } |
| 3353 | rate->he_gi = res->gi; |
| 3354 | rate->flags = RATE_INFO_FLAGS_HE_MCS; |
| 3355 | break; |
| 3356 | default: |
| 3357 | ret = -EINVAL; |
| 3358 | goto out; |
| 3359 | } |
| 3360 | |
| 3361 | switch (res->bw) { |
| 3362 | case IEEE80211_STA_RX_BW_160: |
| 3363 | rate->bw = RATE_INFO_BW_160; |
| 3364 | break; |
| 3365 | case IEEE80211_STA_RX_BW_80: |
| 3366 | rate->bw = RATE_INFO_BW_80; |
| 3367 | break; |
| 3368 | case IEEE80211_STA_RX_BW_40: |
| 3369 | rate->bw = RATE_INFO_BW_40; |
| 3370 | break; |
| 3371 | default: |
| 3372 | rate->bw = RATE_INFO_BW_20; |
| 3373 | break; |
| 3374 | } |
| 3375 | |
| 3376 | out: |
| 3377 | dev_kfree_skb(skb); |
| 3378 | |
| 3379 | return ret; |
| 3380 | } |
| 3381 | |
| 3382 | int mt7915_mcu_update_bss_color(struct mt7915_dev *dev, struct ieee80211_vif *vif, |
| 3383 | struct cfg80211_he_bss_color *he_bss_color) |
| 3384 | { |
| 3385 | int len = sizeof(struct sta_req_hdr) + sizeof(struct bss_info_color); |
| 3386 | struct mt7915_vif *mvif = (struct mt7915_vif *)vif->drv_priv; |
| 3387 | struct bss_info_color *bss_color; |
| 3388 | struct sk_buff *skb; |
| 3389 | struct tlv *tlv; |
| 3390 | |
| 3391 | skb = __mt76_connac_mcu_alloc_sta_req(&dev->mt76, &mvif->mt76, |
| 3392 | NULL, len); |
| 3393 | if (IS_ERR(skb)) |
| 3394 | return PTR_ERR(skb); |
| 3395 | |
| 3396 | tlv = mt76_connac_mcu_add_tlv(skb, BSS_INFO_BSS_COLOR, |
| 3397 | sizeof(*bss_color)); |
| 3398 | bss_color = (struct bss_info_color *)tlv; |
| 3399 | bss_color->disable = !he_bss_color->enabled; |
| 3400 | bss_color->color = he_bss_color->color; |
| 3401 | |
| 3402 | return mt76_mcu_skb_send_msg(&dev->mt76, skb, |
| 3403 | MCU_EXT_CMD(BSS_INFO_UPDATE), true); |
| 3404 | } |
| 3405 | |
| 3406 | #define TWT_AGRT_TRIGGER BIT(0) |
| 3407 | #define TWT_AGRT_ANNOUNCE BIT(1) |
| 3408 | #define TWT_AGRT_PROTECT BIT(2) |
| 3409 | |
| 3410 | int mt7915_mcu_twt_agrt_update(struct mt7915_dev *dev, |
| 3411 | struct mt7915_vif *mvif, |
| 3412 | struct mt7915_twt_flow *flow, |
| 3413 | int cmd) |
| 3414 | { |
| 3415 | struct { |
| 3416 | u8 tbl_idx; |
| 3417 | u8 cmd; |
| 3418 | u8 own_mac_idx; |
| 3419 | u8 flowid; /* 0xff for group id */ |
| 3420 | __le16 peer_id; /* specify the peer_id (msb=0) |
| 3421 | * or group_id (msb=1) |
| 3422 | */ |
| 3423 | u8 duration; /* 256 us */ |
| 3424 | u8 bss_idx; |
| 3425 | __le64 start_tsf; |
| 3426 | __le16 mantissa; |
| 3427 | u8 exponent; |
| 3428 | u8 is_ap; |
| 3429 | u8 agrt_params; |
| 3430 | u8 rsv[23]; |
| 3431 | } __packed req = { |
| 3432 | .tbl_idx = flow->table_id, |
| 3433 | .cmd = cmd, |
| 3434 | .own_mac_idx = mvif->mt76.omac_idx, |
| 3435 | .flowid = flow->id, |
| 3436 | .peer_id = cpu_to_le16(flow->wcid), |
| 3437 | .duration = flow->duration, |
| 3438 | .bss_idx = mvif->mt76.idx, |
| 3439 | .start_tsf = cpu_to_le64(flow->tsf), |
| 3440 | .mantissa = flow->mantissa, |
| 3441 | .exponent = flow->exp, |
| 3442 | .is_ap = true, |
| 3443 | }; |
| 3444 | |
| 3445 | if (flow->protection) |
| 3446 | req.agrt_params |= TWT_AGRT_PROTECT; |
| 3447 | if (!flow->flowtype) |
| 3448 | req.agrt_params |= TWT_AGRT_ANNOUNCE; |
| 3449 | if (flow->trigger) |
| 3450 | req.agrt_params |= TWT_AGRT_TRIGGER; |
| 3451 | |
| 3452 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(TWT_AGRT_UPDATE), |
| 3453 | &req, sizeof(req), true); |
| 3454 | } |
| 3455 | |
| 3456 | int mt7915_mcu_rf_regval(struct mt7915_dev *dev, u32 regidx, u32 *val, bool set) |
| 3457 | { |
| 3458 | struct { |
| 3459 | __le32 idx; |
| 3460 | __le32 ofs; |
| 3461 | __le32 data; |
| 3462 | } __packed req = { |
| 3463 | .idx = cpu_to_le32(u32_get_bits(regidx, GENMASK(31, 24))), |
| 3464 | .ofs = cpu_to_le32(u32_get_bits(regidx, GENMASK(23, 0))), |
| 3465 | .data = set ? cpu_to_le32(*val) : 0, |
| 3466 | }; |
| 3467 | struct sk_buff *skb; |
| 3468 | int ret; |
| 3469 | |
| 3470 | if (set) |
| 3471 | return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(RF_REG_ACCESS), |
| 3472 | &req, sizeof(req), false); |
| 3473 | |
| 3474 | ret = mt76_mcu_send_and_get_msg(&dev->mt76, MCU_EXT_QUERY(RF_REG_ACCESS), |
| 3475 | &req, sizeof(req), true, &skb); |
| 3476 | if (ret) |
| 3477 | return ret; |
| 3478 | |
| 3479 | *val = le32_to_cpu(*(__le32 *)(skb->data + 8)); |
| 3480 | dev_kfree_skb(skb); |
| 3481 | |
| 3482 | return 0; |
| 3483 | } |