1 // SPDX-License-Identifier: ISC
2 /* Copyright (C) 2020 MediaTek Inc. */
4 #include <linux/etherdevice.h>
9 #define CCK_RATE(_idx, _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)), \
16 #define OFDM_RATE(_idx, _rate) { \
18 .hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx), \
19 .hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx), \
22 static struct ieee80211_rate mt7915_rates[] = {
37 static const struct ieee80211_iface_limit if_limits[] = {
40 .types = BIT(NL80211_IFTYPE_ADHOC)
43 .types = BIT(NL80211_IFTYPE_AP)
44 #ifdef CONFIG_MAC80211_MESH
45 | BIT(NL80211_IFTYPE_MESH_POINT)
48 .max = MT7915_MAX_INTERFACES,
49 .types = BIT(NL80211_IFTYPE_STATION)
53 static const struct ieee80211_iface_combination if_comb[] = {
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),
70 mt7915_regd_notifier(struct wiphy *wiphy,
71 struct regulatory_request *request)
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;
79 dev->mt76.region = request->dfs_region;
81 if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR))
84 mt7915_dfs_init_radar_detector(phy);
88 mt7915_init_wiphy(struct ieee80211_hw *hw)
90 struct mt7915_phy *phy = mt7915_hw_phy(hw);
91 struct wiphy *wiphy = hw->wiphy;
94 hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
95 hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
99 hw->sta_data_size = sizeof(struct mt7915_sta);
100 hw->vif_data_size = sizeof(struct mt7915_vif);
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;
107 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS);
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);
113 hw->max_tx_fragments = 4;
117 mt7915_mac_init_band(struct mt7915_dev *dev, u8 band)
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);
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);
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);
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);
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);
151 static void mt7915_mac_init(struct mt7915_dev *dev)
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);
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);
165 mt7915_mcu_set_rts_thresh(&dev->phy, 0x92b);
168 static int mt7915_txbf_init(struct mt7915_dev *dev)
173 if (dev->dbdc_support) {
174 ret = mt7915_mcu_set_txbf_module(dev);
179 /* trigger sounding packets */
180 ret = mt7915_mcu_set_txbf_sounding(dev);
185 return mt7915_mcu_set_txbf_type(dev);
189 mt7915_init_txpower_band(struct mt7915_dev *dev,
190 struct ieee80211_supported_band *sband)
192 int i, n_chains = hweight8(dev->mphy.antenna_mask);
194 for (i = 0; i < sband->n_channels; i++) {
195 struct ieee80211_channel *chan = &sband->channels[i];
196 u32 target_power = 0;
199 for (j = 0; j < n_chains; j++) {
202 val = mt7915_eeprom_get_target_power(dev, chan, j);
203 target_power = max(target_power, val);
206 chan->max_power = min_t(int, chan->max_reg_power,
208 chan->orig_mpwr = target_power / 2;
212 static void mt7915_init_txpower(struct mt7915_dev *dev)
214 mt7915_init_txpower_band(dev, &dev->mphy.sband_2g.sband);
215 mt7915_init_txpower_band(dev, &dev->mphy.sband_5g.sband);
217 mt7915_eeprom_init_sku(dev);
220 static int mt7915_register_ext_phy(struct mt7915_dev *dev)
222 struct mt7915_phy *phy = mt7915_ext_phy(dev);
223 struct mt76_phy *mphy;
226 if (!dev->dbdc_support)
232 mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7915_ops);
239 mphy->chainmask = dev->chainmask & ~dev->mphy.chainmask;
240 mphy->antenna_mask = BIT(hweight8(mphy->chainmask)) - 1;
241 mt7915_init_wiphy(mphy->hw);
243 INIT_LIST_HEAD(&phy->stats_list);
244 INIT_DELAYED_WORK(&mphy->mac_work, mt7915_mac_work);
246 mt7915_eeprom_parse_band_config(phy);
247 mt7915_set_stream_vht_txbf_caps(phy);
248 mt7915_set_stream_he_caps(phy);
250 memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR2,
252 mt76_eeprom_override(mphy);
254 /* The second interface does not get any packets unless it has a vif */
255 ieee80211_hw_set(mphy->hw, WANT_MONITOR_VIF);
257 ret = mt7915_init_tx_queues(phy, MT7915_TXQ_BAND1,
258 MT7915_TX_RING_SIZE);
262 ret = mt76_register_phy(mphy, true, mt7915_rates,
263 ARRAY_SIZE(mt7915_rates));
270 ieee80211_free_hw(mphy->hw);
274 static void mt7915_init_work(struct work_struct *work)
276 struct mt7915_dev *dev = container_of(work, struct mt7915_dev,
279 mt7915_mcu_set_eeprom(dev);
280 mt7915_mac_init(dev);
281 mt7915_init_txpower(dev);
282 mt7915_txbf_init(dev);
283 mt7915_register_ext_phy(dev);
286 static int mt7915_init_hardware(struct mt7915_dev *dev)
290 mt76_wr(dev, MT_INT_SOURCE_CSR, ~0);
292 INIT_WORK(&dev->init_work, mt7915_init_work);
293 spin_lock_init(&dev->token_lock);
294 idr_init(&dev->token);
296 dev->dbdc_support = !!(mt7915_l1_rr(dev, MT_HW_BOUND) & BIT(5));
298 ret = mt7915_dma_init(dev);
302 set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state);
305 * force firmware operation mode into normal state,
306 * which should be set before firmware download stage.
308 mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE);
310 ret = mt7915_mcu_init(dev);
314 ret = mt7915_eeprom_init(dev);
318 /* Beacon and mgmt frames should occupy wcid 0 */
319 idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7915_WTBL_STA - 1);
323 dev->mt76.global_wcid.idx = idx;
324 dev->mt76.global_wcid.hw_key_idx = -1;
325 dev->mt76.global_wcid.tx_info |= MT_WCID_TX_INFO_SET;
326 rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid);
331 void mt7915_set_stream_vht_txbf_caps(struct mt7915_phy *phy)
333 int nss = hweight8(phy->mt76->chainmask);
334 u32 *cap = &phy->mt76->sband_5g.sband.vht_cap.cap;
336 *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
337 IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE |
338 (3 << IEEE80211_VHT_CAP_BEAMFORMEE_STS_SHIFT);
340 *cap &= ~(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK |
341 IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
342 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE);
347 *cap |= IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
348 IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE |
349 FIELD_PREP(IEEE80211_VHT_CAP_SOUNDING_DIMENSIONS_MASK,
354 mt7915_set_stream_he_txbf_caps(struct ieee80211_sta_he_cap *he_cap,
357 struct ieee80211_he_cap_elem *elem = &he_cap->he_cap_elem;
358 struct ieee80211_he_mcs_nss_supp *mcs = &he_cap->he_mcs_nss_supp;
361 #ifdef CONFIG_MAC80211_MESH
362 if (vif == NL80211_IFTYPE_MESH_POINT)
366 elem->phy_cap_info[3] &= ~IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
367 elem->phy_cap_info[4] &= ~IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
369 c = IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_UNDER_80MHZ_MASK |
370 IEEE80211_HE_PHY_CAP5_BEAMFORMEE_NUM_SND_DIM_ABOVE_80MHZ_MASK;
371 elem->phy_cap_info[5] &= ~c;
373 c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMER_FB |
374 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB;
375 elem->phy_cap_info[6] &= ~c;
377 elem->phy_cap_info[7] &= ~IEEE80211_HE_PHY_CAP7_MAX_NC_MASK;
379 c = IEEE80211_HE_PHY_CAP2_NDP_4x_LTF_AND_3_2US |
380 IEEE80211_HE_PHY_CAP2_UL_MU_FULL_MU_MIMO |
381 IEEE80211_HE_PHY_CAP2_UL_MU_PARTIAL_MU_MIMO;
382 elem->phy_cap_info[2] |= c;
384 c = IEEE80211_HE_PHY_CAP4_SU_BEAMFORMEE |
385 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_UNDER_80MHZ_4 |
386 IEEE80211_HE_PHY_CAP4_BEAMFORMEE_MAX_STS_ABOVE_80MHZ_4;
387 elem->phy_cap_info[4] |= c;
389 /* do not support NG16 due to spec D4.0 changes subcarrier idx */
390 c = IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_42_SU |
391 IEEE80211_HE_PHY_CAP6_CODEBOOK_SIZE_75_MU;
393 if (vif == NL80211_IFTYPE_STATION)
394 c |= IEEE80211_HE_PHY_CAP6_PARTIAL_BANDWIDTH_DL_MUMIMO;
396 elem->phy_cap_info[6] |= c;
401 if (vif != NL80211_IFTYPE_AP)
404 elem->phy_cap_info[3] |= IEEE80211_HE_PHY_CAP3_SU_BEAMFORMER;
405 elem->phy_cap_info[4] |= IEEE80211_HE_PHY_CAP4_MU_BEAMFORMER;
408 c = (nss - 1) | (max_t(int, le16_to_cpu(mcs->tx_mcs_160), 1) << 3);
409 elem->phy_cap_info[5] |= c;
411 c = IEEE80211_HE_PHY_CAP6_TRIG_SU_BEAMFORMER_FB |
412 IEEE80211_HE_PHY_CAP6_TRIG_MU_BEAMFORMER_FB;
413 elem->phy_cap_info[6] |= c;
415 /* the maximum cap is 4 x 3, (Nr, Nc) = (3, 2) */
416 elem->phy_cap_info[7] |= min_t(int, nss - 1, 2) << 3;
420 mt7915_gen_ppe_thresh(u8 *he_ppet, int nss)
422 u8 i, ppet_bits, ppet_size, ru_bit_mask = 0x7; /* HE80 */
423 u8 ppet16_ppet8_ru3_ru0[] = {0x1c, 0xc7, 0x71};
425 he_ppet[0] = FIELD_PREP(IEEE80211_PPE_THRES_NSS_MASK, nss - 1) |
426 FIELD_PREP(IEEE80211_PPE_THRES_RU_INDEX_BITMASK_MASK,
429 ppet_bits = IEEE80211_PPE_THRES_INFO_PPET_SIZE *
430 nss * hweight8(ru_bit_mask) * 2;
431 ppet_size = DIV_ROUND_UP(ppet_bits, 8);
433 for (i = 0; i < ppet_size - 1; i++)
434 he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3];
436 he_ppet[i + 1] = ppet16_ppet8_ru3_ru0[i % 3] &
437 (0xff >> (8 - (ppet_bits - 1) % 8));
441 mt7915_init_he_caps(struct mt7915_phy *phy, enum nl80211_band band,
442 struct ieee80211_sband_iftype_data *data)
444 int i, idx = 0, nss = hweight8(phy->mt76->chainmask);
447 for (i = 0; i < 8; i++) {
449 mcs_map |= (IEEE80211_HE_MCS_SUPPORT_0_11 << (i * 2));
451 mcs_map |= (IEEE80211_HE_MCS_NOT_SUPPORTED << (i * 2));
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;
462 case NL80211_IFTYPE_STATION:
463 case NL80211_IFTYPE_AP:
464 #ifdef CONFIG_MAC80211_MESH
465 case NL80211_IFTYPE_MESH_POINT:
472 data[idx].types_mask = BIT(i);
473 he_cap->has_he = true;
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;
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;
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;
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;
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;
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;
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;
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);
562 mt7915_set_stream_he_txbf_caps(he_cap, i, nss);
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);
569 he_cap_elem->phy_cap_info[9] |=
570 IEEE80211_HE_PHY_CAP9_NOMIMAL_PKT_PADDING_16US;
578 void mt7915_set_stream_he_caps(struct mt7915_phy *phy)
580 struct ieee80211_sband_iftype_data *data;
581 struct ieee80211_supported_band *band;
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);
588 band = &phy->mt76->sband_2g.sband;
589 band->iftype_data = data;
590 band->n_iftype_data = n;
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);
597 band = &phy->mt76->sband_5g.sband;
598 band->iftype_data = data;
599 band->n_iftype_data = n;
603 static void mt7915_unregister_ext_phy(struct mt7915_dev *dev)
605 struct mt7915_phy *phy = mt7915_ext_phy(dev);
606 struct mt76_phy *mphy = dev->mt76.phy2;
611 mt76_unregister_phy(mphy);
612 ieee80211_free_hw(mphy->hw);
615 int mt7915_register_device(struct mt7915_dev *dev)
617 struct ieee80211_hw *hw = mt76_hw(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->mphy.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);
630 init_waitqueue_head(&dev->reset_wait);
631 INIT_WORK(&dev->reset_work, mt7915_mac_reset_work);
633 ret = mt7915_init_hardware(dev);
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->mphy.chainmask;
652 dev->mphy.hw->wiphy->available_antennas_tx = dev->mphy.chainmask;
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;
659 #ifdef CONFIG_NL80211_TESTMODE
660 dev->mt76.test_ops = &mt7915_testmode_ops;
663 ret = mt76_register_device(&dev->mt76, true, mt7915_rates,
664 ARRAY_SIZE(mt7915_rates));
668 ieee80211_queue_work(mt76_hw(dev), &dev->init_work);
670 return mt7915_init_debugfs(dev);
673 void mt7915_unregister_device(struct mt7915_dev *dev)
675 mt7915_unregister_ext_phy(dev);
676 mt76_unregister_device(&dev->mt76);
677 mt7915_mcu_exit(dev);
678 mt7915_dma_cleanup(dev);
680 mt7915_tx_token_put(dev);
682 mt76_free_device(&dev->mt76);