1 // SPDX-License-Identifier: ISC 2 /* Copyright (C) 2020 MediaTek Inc. */ 3 4 #include <linux/etherdevice.h> 5 #include "mt7915.h" 6 #include "mac.h" 7 #include "eeprom.h" 8 9 #define CCK_RATE(_idx, _rate) { \ 10 .bitrate = _rate, \ 11 .flags = IEEE80211_RATE_SHORT_PREAMBLE, \ 12 .hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx), \ 13 .hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + (_idx)), \ 14 } 15 16 #define OFDM_RATE(_idx, _rate) { \ 17 .bitrate = _rate, \ 18 .hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 19 .hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 20 } 21 22 static struct ieee80211_rate mt7915_rates[] = { 23 CCK_RATE(0, 10), 24 CCK_RATE(1, 20), 25 CCK_RATE(2, 55), 26 CCK_RATE(3, 110), 27 OFDM_RATE(11, 60), 28 OFDM_RATE(15, 90), 29 OFDM_RATE(10, 120), 30 OFDM_RATE(14, 180), 31 OFDM_RATE(9, 240), 32 OFDM_RATE(13, 360), 33 OFDM_RATE(8, 480), 34 OFDM_RATE(12, 540), 35 }; 36 37 static const struct ieee80211_iface_limit if_limits[] = { 38 { 39 .max = 1, 40 .types = BIT(NL80211_IFTYPE_ADHOC) 41 }, { 42 .max = 16, 43 .types = BIT(NL80211_IFTYPE_AP) | 44 #ifdef CONFIG_MAC80211_MESH 45 BIT(NL80211_IFTYPE_MESH_POINT) 46 #endif 47 }, { 48 .max = MT7915_MAX_INTERFACES, 49 .types = BIT(NL80211_IFTYPE_STATION) 50 } 51 }; 52 53 static const struct ieee80211_iface_combination if_comb[] = { 54 { 55 .limits = if_limits, 56 .n_limits = ARRAY_SIZE(if_limits), 57 .max_interfaces = MT7915_MAX_INTERFACES, 58 .num_different_channels = 1, 59 .beacon_int_infra_match = true, 60 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 61 BIT(NL80211_CHAN_WIDTH_20) | 62 BIT(NL80211_CHAN_WIDTH_40) | 63 BIT(NL80211_CHAN_WIDTH_80) | 64 BIT(NL80211_CHAN_WIDTH_160) | 65 BIT(NL80211_CHAN_WIDTH_80P80), 66 } 67 }; 68 69 static void 70 mt7915_regd_notifier(struct wiphy *wiphy, 71 struct regulatory_request *request) 72 { 73 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 74 struct mt7915_dev *dev = mt7915_hw_dev(hw); 75 struct mt76_phy *mphy = hw->priv; 76 struct mt7915_phy *phy = mphy->priv; 77 struct cfg80211_chan_def *chandef = &mphy->chandef; 78 79 dev->mt76.region = request->dfs_region; 80 81 if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR)) 82 return; 83 84 mt7915_dfs_init_radar_detector(phy); 85 } 86 87 static void 88 mt7915_init_wiphy(struct ieee80211_hw *hw) 89 { 90 struct mt7915_phy *phy = mt7915_hw_phy(hw); 91 struct wiphy *wiphy = hw->wiphy; 92 93 hw->queues = 4; 94 hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; 95 hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; 96 97 phy->slottime = 9; 98 99 hw->sta_data_size = sizeof(struct mt7915_sta); 100 hw->vif_data_size = sizeof(struct mt7915_vif); 101 102 wiphy->iface_combinations = if_comb; 103 wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); 104 wiphy->reg_notifier = mt7915_regd_notifier; 105 wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; 106 107 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 108 109 ieee80211_hw_set(hw, HAS_RATE_CONTROL); 110 ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD); 111 ieee80211_hw_set(hw, WANT_MONITOR_VIF); 112 113 hw->max_tx_fragments = 4; 114 } 115 116 static void 117 mt7915_mac_init_band(struct mt7915_dev *dev, u8 band) 118 { 119 u32 mask, set; 120 121 mt76_rmw_field(dev, MT_TMAC_CTCR0(band), 122 MT_TMAC_CTCR0_INS_DDLMT_REFTIME, 0x3f); 123 mt76_set(dev, MT_TMAC_CTCR0(band), 124 MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN | 125 MT_TMAC_CTCR0_INS_DDLMT_EN); 126 127 mask = MT_MDP_RCFR0_MCU_RX_MGMT | 128 MT_MDP_RCFR0_MCU_RX_CTL_NON_BAR | 129 MT_MDP_RCFR0_MCU_RX_CTL_BAR; 130 set = FIELD_PREP(MT_MDP_RCFR0_MCU_RX_MGMT, MT_MDP_TO_HIF) | 131 FIELD_PREP(MT_MDP_RCFR0_MCU_RX_CTL_NON_BAR, MT_MDP_TO_HIF) | 132 FIELD_PREP(MT_MDP_RCFR0_MCU_RX_CTL_BAR, MT_MDP_TO_HIF); 133 mt76_rmw(dev, MT_MDP_BNRCFR0(band), mask, set); 134 135 mask = MT_MDP_RCFR1_MCU_RX_BYPASS | 136 MT_MDP_RCFR1_RX_DROPPED_UCAST | 137 MT_MDP_RCFR1_RX_DROPPED_MCAST; 138 set = FIELD_PREP(MT_MDP_RCFR1_MCU_RX_BYPASS, MT_MDP_TO_HIF) | 139 FIELD_PREP(MT_MDP_RCFR1_RX_DROPPED_UCAST, MT_MDP_TO_HIF) | 140 FIELD_PREP(MT_MDP_RCFR1_RX_DROPPED_MCAST, MT_MDP_TO_HIF); 141 mt76_rmw(dev, MT_MDP_BNRCFR1(band), mask, set); 142 143 mt76_set(dev, MT_WF_RMAC_MIB_TIME0(band), MT_WF_RMAC_MIB_RXTIME_EN); 144 mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0(band), MT_WF_RMAC_MIB_RXTIME_EN); 145 146 mt76_rmw_field(dev, MT_DMA_DCR0(band), MT_DMA_DCR0_MAX_RX_LEN, 1536); 147 /* disable rx rate report by default due to hw issues */ 148 mt76_clear(dev, MT_DMA_DCR0(band), MT_DMA_DCR0_RXD_G5_EN); 149 } 150 151 static void mt7915_mac_init(struct mt7915_dev *dev) 152 { 153 int i; 154 155 mt76_rmw_field(dev, MT_MDP_DCR1, MT_MDP_DCR1_MAX_RX_LEN, 1536); 156 /* disable hardware de-agg */ 157 mt76_clear(dev, MT_MDP_DCR0, MT_MDP_DCR0_DAMSDU_EN); 158 159 for (i = 0; i < MT7915_WTBL_SIZE; i++) 160 mt7915_mac_wtbl_update(dev, i, 161 MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 162 for (i = 0; i < 2; i++) 163 mt7915_mac_init_band(dev, i); 164 165 mt7915_mcu_set_rts_thresh(&dev->phy, 0x92b); 166 } 167 168 static int mt7915_txbf_init(struct mt7915_dev *dev) 169 { 170 int ret; 171 172 /* 173 * TODO: DBDC & check whether iBF phase calibration data has 174 * been stored in eeprom offset 0x651~0x7b8, then write down 175 * 0x1111 into 0x651 and 0x651 to trigger iBF. 176 */ 177 178 /* trigger sounding packets */ 179 ret = mt7915_mcu_set_txbf_sounding(dev); 180 if (ret) 181 return ret; 182 183 /* enable iBF & eBF */ 184 return mt7915_mcu_set_txbf_type(dev); 185 } 186 187 static void 188 mt7915_init_txpower_band(struct mt7915_dev *dev, 189 struct ieee80211_supported_band *sband) 190 { 191 int i, n_chains = hweight8(dev->mphy.antenna_mask); 192 193 for (i = 0; i < sband->n_channels; i++) { 194 struct ieee80211_channel *chan = &sband->channels[i]; 195 u32 target_power = 0; 196 int j; 197 198 for (j = 0; j < n_chains; j++) { 199 u32 val; 200 201 val = mt7915_eeprom_get_target_power(dev, chan, j); 202 target_power = max(target_power, val); 203 } 204 205 chan->max_power = min_t(int, chan->max_reg_power, 206 target_power / 2); 207 chan->orig_mpwr = target_power / 2; 208 } 209 } 210 211 static void mt7915_init_txpower(struct mt7915_dev *dev) 212 { 213 mt7915_init_txpower_band(dev, &dev->mphy.sband_2g.sband); 214 mt7915_init_txpower_band(dev, &dev->mphy.sband_5g.sband); 215 216 mt7915_eeprom_init_sku(dev); 217 } 218 219 static int mt7915_register_ext_phy(struct mt7915_dev *dev) 220 { 221 struct mt7915_phy *phy = mt7915_ext_phy(dev); 222 struct mt76_phy *mphy; 223 int ret; 224 225 if (!dev->dbdc_support) 226 return 0; 227 228 if (phy) 229 return 0; 230 231 mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7915_ops); 232 if (!mphy) 233 return -ENOMEM; 234 235 phy = mphy->priv; 236 phy->dev = dev; 237 phy->mt76 = mphy; 238 phy->chainmask = dev->chainmask & ~dev->phy.chainmask; 239 mphy->antenna_mask = BIT(hweight8(phy->chainmask)) - 1; 240 mt7915_init_wiphy(mphy->hw); 241 242 INIT_LIST_HEAD(&phy->stats_list); 243 INIT_DELAYED_WORK(&phy->mac_work, mt7915_mac_work); 244 245 mt7915_eeprom_parse_band_config(phy); 246 mt7915_set_stream_vht_txbf_caps(phy); 247 mt7915_set_stream_he_caps(phy); 248 249 memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR2, 250 ETH_ALEN); 251 mt76_eeprom_override(mphy); 252 253 /* The second interface does not get any packets unless it has a vif */ 254 ieee80211_hw_set(mphy->hw, WANT_MONITOR_VIF); 255 256 ret = mt7915_init_tx_queues(phy, MT7915_TXQ_BAND1, 257 MT7915_TX_RING_SIZE); 258 if (ret) 259 goto error; 260 261 ret = mt76_register_phy(mphy, true, mt7915_rates, 262 ARRAY_SIZE(mt7915_rates)); 263 if (ret) 264 goto error; 265 266 return 0; 267 268 error: 269 ieee80211_free_hw(mphy->hw); 270 return ret; 271 } 272 273 static void mt7915_init_work(struct work_struct *work) 274 { 275 struct mt7915_dev *dev = container_of(work, struct mt7915_dev, 276 init_work); 277 278 mt7915_mcu_set_eeprom(dev); 279 mt7915_mac_init(dev); 280 mt7915_init_txpower(dev); 281 mt7915_txbf_init(dev); 282 mt7915_register_ext_phy(dev); 283 } 284 285 static int mt7915_init_hardware(struct mt7915_dev *dev) 286 { 287 int ret, idx; 288 289 mt76_wr(dev, MT_INT_SOURCE_CSR, ~0); 290 291 INIT_WORK(&dev->init_work, mt7915_init_work); 292 spin_lock_init(&dev->token_lock); 293 idr_init(&dev->token); 294 295 dev->dbdc_support = !!(mt7915_l1_rr(dev, MT_HW_BOUND) & BIT(5)); 296 297 ret = mt7915_dma_init(dev); 298 if (ret) 299 return ret; 300 301 set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state); 302 303 /* 304 * force firmware operation mode into normal state, 305 * which should be set before firmware download stage. 306 */ 307 mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE); 308 309 ret = mt7915_mcu_init(dev); 310 if (ret) 311 return ret; 312 313 ret = mt7915_eeprom_init(dev); 314 if (ret < 0) 315 return ret; 316 317 /* Beacon and mgmt frames should occupy wcid 0 */ 318 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA - 1); 319 if (idx) 320 return -ENOSPC; 321 322 dev->mt76.global_wcid.idx = idx; 323 dev->mt76.global_wcid.hw_key_idx = -1; 324 dev->mt76.global_wcid.tx_info |= MT_WCID_TX_INFO_SET; 325 rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid); 326 327 return 0; 328 } 329 330 void mt7915_set_stream_vht_txbf_caps(struct mt7915_phy *phy) 331 { 332 int nss = hweight8(phy->chainmask); 333 u32 *cap = &phy->mt76->sband_5g.sband.vht_cap.cap; 334 335 *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE | 336 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE | 337 (3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT); 338 339 *cap &= ~(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK | 340 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | 341 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE); 342 343 if (nss < 2) 344 return; 345 346 *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE | 347 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE | 348 FIELD_PREP(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK, 349 nss - 1); 350 } 351 352 static void 353 mt7915_set_stream_he_txbf_caps(struct ieee80211_sta_he_cap *he_cap, 354 int vif, int nss) 355 { 356 struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem; 357 struct ieee80211_he_mcs_nss_supp *mcs = &he_cap->he_mcs_nss_supp; 358 u8 c; 359 360 #ifdef CONFIG_MAC80211_MESH 361 if (vif == NL80211_IFTYPE_MESH_POINT) 362 return; 363 #endif 364 365 elem->phy_cap_info[3] &= ~IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER; 366 elem->phy_cap_info[4] &= ~IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; 367 368 c = IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK | 369 IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK; 370 elem->phy_cap_info[5] &= ~c; 371 372 c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMER_FB | 373 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB; 374 elem->phy_cap_info[6] &= ~c; 375 376 elem->phy_cap_info[7] &= ~IEEE80211_HE_PHY_CAP7_MAX_NC_MASK; 377 378 c = IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US | 379 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO | 380 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO; 381 elem->phy_cap_info[2] |= c; 382 383 c = IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE | 384 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 | 385 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4; 386 elem->phy_cap_info[4] |= c; 387 388 /* do not support NG16 due to spec D4.0 changes subcarrier idx */ 389 c = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU | 390 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU; 391 392 if (vif == NL80211_IFTYPE_STATION) 393 c |= IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO; 394 395 elem->phy_cap_info[6] |= c; 396 397 if (nss < 2) 398 return; 399 400 if (vif != NL80211_IFTYPE_AP) 401 return; 402 403 elem->phy_cap_info[3] |= IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER; 404 elem->phy_cap_info[4] |= IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER; 405 406 /* num_snd_dim */ 407 c = (nss - 1) | (max_t(int, le16_to_cpu(mcs->tx_mcs_160), 1) << 3); 408 elem->phy_cap_info[5] |= c; 409 410 c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMER_FB | 411 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB; 412 elem->phy_cap_info[6] |= c; 413 414 /* the maximum cap is 4 x 3, (Nr, Nc) = (3, 2) */ 415 elem->phy_cap_info[7] |= min_t(int, nss - 1, 2) << 3; 416 } 417 418 static void 419 mt7915_gen_ppe_thresh(u8 *he_ppet, int nss) 420 { 421 u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */ 422 u8 ppet16_ppet8_ru3_ru0[] = {0x1c, 0xc7, 0x71}; 423 424 he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) | 425 FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK, 426 ru_bit_mask); 427 428 ppet_bits = IEEE80211_PPE_THRES_INFO_PPET_SIZE * 429 nss * hweight8(ru_bit_mask) * 2; 430 ppet_size = DIV_ROUND_UP(ppet_bits, 8); 431 432 for (i = 0; i < ppet_size - 1; i++) 433 he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3]; 434 435 he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3] & 436 (0xff >> (8 - (ppet_bits - 1) % 8)); 437 } 438 439 static int 440 mt7915_init_he_caps(struct mt7915_phy *phy, enum nl80211_band band, 441 struct ieee80211_sband_iftype_data *data) 442 { 443 int i, idx = 0; 444 int nss = hweight8(phy->chainmask); 445 u16 mcs_map = 0; 446 447 for (i = 0; i < 8; i++) { 448 if (i < nss) 449 mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2)); 450 else 451 mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2)); 452 } 453 454 for (i = 0; i < NUM_NL80211_IFTYPES; i++) { 455 struct ieee80211_sta_he_cap *he_cap = &data[idx].he_cap; 456 struct ieee80211_he_cap_elem *he_cap_elem = 457 &he_cap->he_cap_elem; 458 struct ieee80211_he_mcs_nss_supp *he_mcs = 459 &he_cap->he_mcs_nss_supp; 460 461 switch (i) { 462 case NL80211_IFTYPE_STATION: 463 case NL80211_IFTYPE_AP: 464 #ifdef CONFIG_MAC80211_MESH 465 case NL80211_IFTYPE_MESH_POINT: 466 #endif 467 break; 468 default: 469 continue; 470 } 471 472 data[idx].types_mask = BIT(i); 473 he_cap->has_he = true; 474 475 he_cap_elem->mac_cap_info[0] = 476 IEEE80211_HE_MAC_CAP0_HTC_HE; 477 he_cap_elem->mac_cap_info[3] = 478 IEEE80211_HE_MAC_CAP3_OMI_CONTROL | 479 IEEE80211_HE_MAC_CAP3_MAX_AMPDU_LEN_EXP_RESERVED; 480 he_cap_elem->mac_cap_info[4] = 481 IEEE80211_HE_MAC_CAP4_AMDSU_IN_AMPDU; 482 483 if (band == NL80211_BAND_2GHZ) 484 he_cap_elem->phy_cap_info[0] = 485 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G; 486 else if (band == NL80211_BAND_5GHZ) 487 he_cap_elem->phy_cap_info[0] = 488 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G | 489 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G | 490 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G; 491 492 he_cap_elem->phy_cap_info[1] = 493 IEEE80211_HE_PHY_CAP1_LDPC_CODING_IN_PAYLOAD; 494 he_cap_elem->phy_cap_info[2] = 495 IEEE80211_HE_PHY_CAP2_STBC_TX_UNDER_80MHZ | 496 IEEE80211_HE_PHY_CAP2_STBC_RX_UNDER_80MHZ; 497 498 switch (i) { 499 case NL80211_IFTYPE_AP: 500 he_cap_elem->mac_cap_info[0] |= 501 IEEE80211_HE_MAC_CAP0_TWT_RES; 502 he_cap_elem->mac_cap_info[2] |= 503 IEEE80211_HE_MAC_CAP2_BSR; 504 he_cap_elem->mac_cap_info[4] |= 505 IEEE80211_HE_MAC_CAP4_BQR; 506 he_cap_elem->mac_cap_info[5] |= 507 IEEE80211_HE_MAC_CAP5_OM_CTRL_UL_MU_DATA_DIS_RX; 508 he_cap_elem->phy_cap_info[3] |= 509 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK | 510 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK; 511 he_cap_elem->phy_cap_info[6] |= 512 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT; 513 break; 514 case NL80211_IFTYPE_STATION: 515 he_cap_elem->mac_cap_info[0] |= 516 IEEE80211_HE_MAC_CAP0_TWT_REQ; 517 he_cap_elem->mac_cap_info[1] |= 518 IEEE80211_HE_MAC_CAP1_TF_MAC_PAD_DUR_16US; 519 520 if (band == NL80211_BAND_2GHZ) 521 he_cap_elem->phy_cap_info[0] |= 522 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_2G; 523 else if (band == NL80211_BAND_5GHZ) 524 he_cap_elem->phy_cap_info[0] |= 525 IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_RU_MAPPING_IN_5G; 526 527 he_cap_elem->phy_cap_info[1] |= 528 IEEE80211_HE_PHY_CAP1_DEVICE_CLASS_A | 529 IEEE80211_HE_PHY_CAP1_HE_LTF_AND_GI_FOR_HE_PPDUS_0_8US; 530 he_cap_elem->phy_cap_info[3] |= 531 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_TX_QPSK | 532 IEEE80211_HE_PHY_CAP3_DCM_MAX_CONST_RX_QPSK; 533 he_cap_elem->phy_cap_info[6] |= 534 IEEE80211_HE_PHY_CAP6_TRIG_CQI_FB | 535 IEEE80211_HE_PHY_CAP6_PARTIAL_BW_EXT_RANGE | 536 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT; 537 he_cap_elem->phy_cap_info[7] |= 538 IEEE80211_HE_PHY_CAP7_POWER_BOOST_FACTOR_AR | 539 IEEE80211_HE_PHY_CAP7_HE_SU_MU_PPDU_4XLTF_AND_08_US_GI; 540 he_cap_elem->phy_cap_info[8] |= 541 IEEE80211_HE_PHY_CAP8_20MHZ_IN_40MHZ_HE_PPDU_IN_2G | 542 IEEE80211_HE_PHY_CAP8_20MHZ_IN_160MHZ_HE_PPDU | 543 IEEE80211_HE_PHY_CAP8_80MHZ_IN_160MHZ_HE_PPDU | 544 IEEE80211_HE_PHY_CAP8_DCM_MAX_RU_484; 545 he_cap_elem->phy_cap_info[9] |= 546 IEEE80211_HE_PHY_CAP9_LONGER_THAN_16_SIGB_OFDM_SYM | 547 IEEE80211_HE_PHY_CAP9_NON_TRIGGERED_CQI_FEEDBACK | 548 IEEE80211_HE_PHY_CAP9_TX_1024_QAM_LESS_THAN_242_TONE_RU | 549 IEEE80211_HE_PHY_CAP9_RX_1024_QAM_LESS_THAN_242_TONE_RU | 550 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_COMP_SIGB | 551 IEEE80211_HE_PHY_CAP9_RX_FULL_BW_SU_USING_MU_WITH_NON_COMP_SIGB; 552 break; 553 } 554 555 he_mcs->rx_mcs_80 = cpu_to_le16(mcs_map); 556 he_mcs->tx_mcs_80 = cpu_to_le16(mcs_map); 557 he_mcs->rx_mcs_160 = cpu_to_le16(mcs_map); 558 he_mcs->tx_mcs_160 = cpu_to_le16(mcs_map); 559 he_mcs->rx_mcs_80p80 = cpu_to_le16(mcs_map); 560 he_mcs->tx_mcs_80p80 = cpu_to_le16(mcs_map); 561 562 mt7915_set_stream_he_txbf_caps(he_cap, i, nss); 563 564 memset(he_cap->ppe_thres, 0, sizeof(he_cap->ppe_thres)); 565 if (he_cap_elem->phy_cap_info[6] & 566 IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { 567 mt7915_gen_ppe_thresh(he_cap->ppe_thres, nss); 568 } else { 569 he_cap_elem->phy_cap_info[9] |= 570 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US; 571 } 572 idx++; 573 } 574 575 return idx; 576 } 577 578 void mt7915_set_stream_he_caps(struct mt7915_phy *phy) 579 { 580 struct ieee80211_sband_iftype_data *data; 581 struct ieee80211_supported_band *band; 582 int n; 583 584 if (phy->mt76->cap.has_2ghz) { 585 data = phy->iftype[NL80211_BAND_2GHZ]; 586 n = mt7915_init_he_caps(phy, NL80211_BAND_2GHZ, data); 587 588 band = &phy->mt76->sband_2g.sband; 589 band->iftype_data = data; 590 band->n_iftype_data = n; 591 } 592 593 if (phy->mt76->cap.has_5ghz) { 594 data = phy->iftype[NL80211_BAND_5GHZ]; 595 n = mt7915_init_he_caps(phy, NL80211_BAND_5GHZ, data); 596 597 band = &phy->mt76->sband_5g.sband; 598 band->iftype_data = data; 599 band->n_iftype_data = n; 600 } 601 } 602 603 static void mt7915_unregister_ext_phy(struct mt7915_dev *dev) 604 { 605 struct mt7915_phy *phy = mt7915_ext_phy(dev); 606 struct mt76_phy *mphy = dev->mt76.phy2; 607 608 if (!phy) 609 return; 610 611 mt76_unregister_phy(mphy); 612 ieee80211_free_hw(mphy->hw); 613 } 614 615 int mt7915_register_device(struct mt7915_dev *dev) 616 { 617 struct ieee80211_hw *hw = mt76_hw(dev); 618 int ret; 619 620 dev->phy.dev = dev; 621 dev->phy.mt76 = &dev->mt76.phy; 622 dev->mt76.phy.priv = &dev->phy; 623 INIT_LIST_HEAD(&dev->phy.stats_list); 624 INIT_WORK(&dev->rc_work, mt7915_mac_sta_rc_work); 625 INIT_DELAYED_WORK(&dev->phy.mac_work, mt7915_mac_work); 626 INIT_LIST_HEAD(&dev->sta_rc_list); 627 INIT_LIST_HEAD(&dev->sta_poll_list); 628 spin_lock_init(&dev->sta_poll_lock); 629 630 init_waitqueue_head(&dev->reset_wait); 631 INIT_WORK(&dev->reset_work, mt7915_mac_reset_work); 632 633 ret = mt7915_init_hardware(dev); 634 if (ret) 635 return ret; 636 637 mt7915_init_wiphy(hw); 638 dev->mphy.sband_2g.sband.ht_cap.cap |= 639 IEEE80211_HT_CAP_LDPC_CODING | 640 IEEE80211_HT_CAP_MAX_AMSDU; 641 dev->mphy.sband_5g.sband.ht_cap.cap |= 642 IEEE80211_HT_CAP_LDPC_CODING | 643 IEEE80211_HT_CAP_MAX_AMSDU; 644 dev->mphy.sband_5g.sband.vht_cap.cap |= 645 IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | 646 IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; 647 if (!dev->dbdc_support) 648 dev->mphy.sband_5g.sband.vht_cap.cap |= 649 IEEE80211_VHT_CAP_SHORT_GI_160 | 650 IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; 651 dev->mphy.hw->wiphy->available_antennas_rx = dev->phy.chainmask; 652 dev->mphy.hw->wiphy->available_antennas_tx = dev->phy.chainmask; 653 654 mt76_set_stream_caps(&dev->mphy, true); 655 mt7915_set_stream_vht_txbf_caps(&dev->phy); 656 mt7915_set_stream_he_caps(&dev->phy); 657 dev->phy.dfs_state = -1; 658 659 #ifdef CONFIG_NL80211_TESTMODE 660 dev->mt76.test_ops = &mt7915_testmode_ops; 661 #endif 662 663 ret = mt76_register_device(&dev->mt76, true, mt7915_rates, 664 ARRAY_SIZE(mt7915_rates)); 665 if (ret) 666 return ret; 667 668 ieee80211_queue_work(mt76_hw(dev), &dev->init_work); 669 670 return mt7915_init_debugfs(dev); 671 } 672 673 void mt7915_unregister_device(struct mt7915_dev *dev) 674 { 675 struct mt76_txwi_cache *txwi; 676 int id; 677 678 mt7915_unregister_ext_phy(dev); 679 mt76_unregister_device(&dev->mt76); 680 mt7915_mcu_exit(dev); 681 mt7915_dma_cleanup(dev); 682 683 spin_lock_bh(&dev->token_lock); 684 idr_for_each_entry(&dev->token, txwi, id) { 685 mt7915_txp_skb_unmap(&dev->mt76, txwi); 686 if (txwi->skb) { 687 struct ieee80211_hw *hw; 688 689 hw = mt76_tx_status_get_hw(&dev->mt76, txwi->skb); 690 ieee80211_free_txskb(hw, txwi->skb); 691 } 692 mt76_put_txwi(&dev->mt76, txwi); 693 dev->token_count--; 694 } 695 spin_unlock_bh(&dev->token_lock); 696 idr_destroy(&dev->token); 697 698 mt76_free_device(&dev->mt76); 699 } 700