18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: ISC 28c2ecf20Sopenharmony_ci/* Copyright (C) 2019 MediaTek Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Author: Roy Luo <royluo@google.com> 58c2ecf20Sopenharmony_ci * Ryder Lee <ryder.lee@mediatek.com> 68c2ecf20Sopenharmony_ci * Felix Fietkau <nbd@nbd.name> 78c2ecf20Sopenharmony_ci * Lorenzo Bianconi <lorenzo@kernel.org> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/etherdevice.h> 118c2ecf20Sopenharmony_ci#include "mt7615.h" 128c2ecf20Sopenharmony_ci#include "mac.h" 138c2ecf20Sopenharmony_ci#include "eeprom.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_civoid mt7615_phy_init(struct mt7615_dev *dev) 168c2ecf20Sopenharmony_ci{ 178c2ecf20Sopenharmony_ci /* disable rf low power beacon mode */ 188c2ecf20Sopenharmony_ci mt76_set(dev, MT_WF_PHY_WF2_RFCTRL0(0), MT_WF_PHY_WF2_RFCTRL0_LPBCN_EN); 198c2ecf20Sopenharmony_ci mt76_set(dev, MT_WF_PHY_WF2_RFCTRL0(1), MT_WF_PHY_WF2_RFCTRL0_LPBCN_EN); 208c2ecf20Sopenharmony_ci} 218c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_phy_init); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic void 248c2ecf20Sopenharmony_cimt7615_init_mac_chain(struct mt7615_dev *dev, int chain) 258c2ecf20Sopenharmony_ci{ 268c2ecf20Sopenharmony_ci u32 val; 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci if (!chain) 298c2ecf20Sopenharmony_ci val = MT_CFG_CCR_MAC_D0_1X_GC_EN | MT_CFG_CCR_MAC_D0_2X_GC_EN; 308c2ecf20Sopenharmony_ci else 318c2ecf20Sopenharmony_ci val = MT_CFG_CCR_MAC_D1_1X_GC_EN | MT_CFG_CCR_MAC_D1_2X_GC_EN; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci /* enable band 0/1 clk */ 348c2ecf20Sopenharmony_ci mt76_set(dev, MT_CFG_CCR, val); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci mt76_rmw(dev, MT_TMAC_TRCR(chain), 378c2ecf20Sopenharmony_ci MT_TMAC_TRCR_CCA_SEL | MT_TMAC_TRCR_SEC_CCA_SEL, 388c2ecf20Sopenharmony_ci FIELD_PREP(MT_TMAC_TRCR_CCA_SEL, 2) | 398c2ecf20Sopenharmony_ci FIELD_PREP(MT_TMAC_TRCR_SEC_CCA_SEL, 0)); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci mt76_wr(dev, MT_AGG_ACR(chain), 428c2ecf20Sopenharmony_ci MT_AGG_ACR_PKT_TIME_EN | MT_AGG_ACR_NO_BA_AR_RULE | 438c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ACR_CFEND_RATE, MT7615_CFEND_RATE_DEFAULT) | 448c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ACR_BAR_RATE, MT7615_BAR_RATE_DEFAULT)); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci mt76_wr(dev, MT_AGG_ARUCR(chain), 478c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), 7) | 488c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(1), 2) | 498c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(2), 2) | 508c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(3), 2) | 518c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(4), 1) | 528c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(5), 1) | 538c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(6), 1) | 548c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(7), 1)); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci mt76_wr(dev, MT_AGG_ARDCR(chain), 578c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(0), MT7615_RATE_RETRY - 1) | 588c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(1), MT7615_RATE_RETRY - 1) | 598c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(2), MT7615_RATE_RETRY - 1) | 608c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(3), MT7615_RATE_RETRY - 1) | 618c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(4), MT7615_RATE_RETRY - 1) | 628c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(5), MT7615_RATE_RETRY - 1) | 638c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(6), MT7615_RATE_RETRY - 1) | 648c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARxCR_LIMIT(7), MT7615_RATE_RETRY - 1)); 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_ci mt76_clear(dev, MT_DMA_RCFR0(chain), MT_DMA_RCFR0_MCU_RX_TDLS); 678c2ecf20Sopenharmony_ci if (!mt7615_firmware_offload(dev)) { 688c2ecf20Sopenharmony_ci u32 mask, set; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci mask = MT_DMA_RCFR0_MCU_RX_MGMT | 718c2ecf20Sopenharmony_ci MT_DMA_RCFR0_MCU_RX_CTL_NON_BAR | 728c2ecf20Sopenharmony_ci MT_DMA_RCFR0_MCU_RX_CTL_BAR | 738c2ecf20Sopenharmony_ci MT_DMA_RCFR0_MCU_RX_BYPASS | 748c2ecf20Sopenharmony_ci MT_DMA_RCFR0_RX_DROPPED_UCAST | 758c2ecf20Sopenharmony_ci MT_DMA_RCFR0_RX_DROPPED_MCAST; 768c2ecf20Sopenharmony_ci set = FIELD_PREP(MT_DMA_RCFR0_RX_DROPPED_UCAST, 2) | 778c2ecf20Sopenharmony_ci FIELD_PREP(MT_DMA_RCFR0_RX_DROPPED_MCAST, 2); 788c2ecf20Sopenharmony_ci mt76_rmw(dev, MT_DMA_RCFR0(chain), mask, set); 798c2ecf20Sopenharmony_ci } 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_civoid mt7615_mac_init(struct mt7615_dev *dev) 838c2ecf20Sopenharmony_ci{ 848c2ecf20Sopenharmony_ci int i; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci mt7615_init_mac_chain(dev, 0); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci mt76_rmw_field(dev, MT_TMAC_CTCR0, 898c2ecf20Sopenharmony_ci MT_TMAC_CTCR0_INS_DDLMT_REFTIME, 0x3f); 908c2ecf20Sopenharmony_ci mt76_rmw_field(dev, MT_TMAC_CTCR0, 918c2ecf20Sopenharmony_ci MT_TMAC_CTCR0_INS_DDLMT_DENSITY, 0x3); 928c2ecf20Sopenharmony_ci mt76_rmw(dev, MT_TMAC_CTCR0, 938c2ecf20Sopenharmony_ci MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN | 948c2ecf20Sopenharmony_ci MT_TMAC_CTCR0_INS_DDLMT_EN, 958c2ecf20Sopenharmony_ci MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN | 968c2ecf20Sopenharmony_ci MT_TMAC_CTCR0_INS_DDLMT_EN); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci mt7615_mcu_set_rts_thresh(&dev->phy, 0x92b); 998c2ecf20Sopenharmony_ci mt7615_mac_set_scs(&dev->phy, true); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci mt76_rmw(dev, MT_AGG_SCR, MT_AGG_SCR_NLNAV_MID_PTEC_DIS, 1028c2ecf20Sopenharmony_ci MT_AGG_SCR_NLNAV_MID_PTEC_DIS); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci mt76_wr(dev, MT_AGG_ARCR, 1058c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARCR_RTS_RATE_THR, 2) | 1068c2ecf20Sopenharmony_ci MT_AGG_ARCR_RATE_DOWN_RATIO_EN | 1078c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARCR_RATE_DOWN_RATIO, 1) | 1088c2ecf20Sopenharmony_ci FIELD_PREP(MT_AGG_ARCR_RATE_UP_EXTRA_TH, 4)); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci for (i = 0; i < MT7615_WTBL_SIZE; i++) 1118c2ecf20Sopenharmony_ci mt7615_mac_wtbl_update(dev, i, 1128c2ecf20Sopenharmony_ci MT_WTBL_UPDATE_ADM_COUNT_CLEAR); 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_ci mt76_set(dev, MT_WF_RMAC_MIB_TIME0, MT_WF_RMAC_MIB_RXTIME_EN); 1158c2ecf20Sopenharmony_ci mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0, MT_WF_RMAC_MIB_RXTIME_EN); 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci /* disable hdr translation and hw AMSDU */ 1188c2ecf20Sopenharmony_ci mt76_wr(dev, MT_DMA_DCR0, 1198c2ecf20Sopenharmony_ci FIELD_PREP(MT_DMA_DCR0_MAX_RX_LEN, 3072) | 1208c2ecf20Sopenharmony_ci MT_DMA_DCR0_RX_VEC_DROP); 1218c2ecf20Sopenharmony_ci /* disable TDLS filtering */ 1228c2ecf20Sopenharmony_ci mt76_clear(dev, MT_WF_PFCR, MT_WF_PFCR_TDLS_EN); 1238c2ecf20Sopenharmony_ci mt76_set(dev, MT_WF_MIB_SCR0, MT_MIB_SCR0_AGG_CNT_RANGE_EN); 1248c2ecf20Sopenharmony_ci if (is_mt7663(&dev->mt76)) { 1258c2ecf20Sopenharmony_ci mt76_wr(dev, MT_WF_AGG(0x160), 0x5c341c02); 1268c2ecf20Sopenharmony_ci mt76_wr(dev, MT_WF_AGG(0x164), 0x70708040); 1278c2ecf20Sopenharmony_ci } else { 1288c2ecf20Sopenharmony_ci mt7615_init_mac_chain(dev, 1); 1298c2ecf20Sopenharmony_ci } 1308c2ecf20Sopenharmony_ci} 1318c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_mac_init); 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_civoid mt7615_check_offload_capability(struct mt7615_dev *dev) 1348c2ecf20Sopenharmony_ci{ 1358c2ecf20Sopenharmony_ci struct ieee80211_hw *hw = mt76_hw(dev); 1368c2ecf20Sopenharmony_ci struct wiphy *wiphy = hw->wiphy; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci if (mt7615_firmware_offload(dev)) { 1398c2ecf20Sopenharmony_ci ieee80211_hw_set(hw, SUPPORTS_PS); 1408c2ecf20Sopenharmony_ci ieee80211_hw_set(hw, SUPPORTS_DYNAMIC_PS); 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci wiphy->max_remain_on_channel_duration = 5000; 1438c2ecf20Sopenharmony_ci wiphy->features |= NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR | 1448c2ecf20Sopenharmony_ci NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR | 1458c2ecf20Sopenharmony_ci WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL | 1468c2ecf20Sopenharmony_ci NL80211_FEATURE_P2P_GO_CTWIN | 1478c2ecf20Sopenharmony_ci NL80211_FEATURE_P2P_GO_OPPPS; 1488c2ecf20Sopenharmony_ci } else { 1498c2ecf20Sopenharmony_ci dev->ops->hw_scan = NULL; 1508c2ecf20Sopenharmony_ci dev->ops->cancel_hw_scan = NULL; 1518c2ecf20Sopenharmony_ci dev->ops->sched_scan_start = NULL; 1528c2ecf20Sopenharmony_ci dev->ops->sched_scan_stop = NULL; 1538c2ecf20Sopenharmony_ci dev->ops->set_rekey_data = NULL; 1548c2ecf20Sopenharmony_ci dev->ops->remain_on_channel = NULL; 1558c2ecf20Sopenharmony_ci dev->ops->cancel_remain_on_channel = NULL; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci wiphy->max_sched_scan_plan_interval = 0; 1588c2ecf20Sopenharmony_ci wiphy->max_sched_scan_ie_len = 0; 1598c2ecf20Sopenharmony_ci wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; 1608c2ecf20Sopenharmony_ci wiphy->max_sched_scan_ssids = 0; 1618c2ecf20Sopenharmony_ci wiphy->max_match_sets = 0; 1628c2ecf20Sopenharmony_ci wiphy->max_sched_scan_reqs = 0; 1638c2ecf20Sopenharmony_ci } 1648c2ecf20Sopenharmony_ci} 1658c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_check_offload_capability); 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_cibool mt7615_wait_for_mcu_init(struct mt7615_dev *dev) 1688c2ecf20Sopenharmony_ci{ 1698c2ecf20Sopenharmony_ci flush_work(&dev->mcu_work); 1708c2ecf20Sopenharmony_ci 1718c2ecf20Sopenharmony_ci return test_bit(MT76_STATE_MCU_RUNNING, &dev->mphy.state); 1728c2ecf20Sopenharmony_ci} 1738c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_wait_for_mcu_init); 1748c2ecf20Sopenharmony_ci 1758c2ecf20Sopenharmony_ci#define CCK_RATE(_idx, _rate) { \ 1768c2ecf20Sopenharmony_ci .bitrate = _rate, \ 1778c2ecf20Sopenharmony_ci .flags = IEEE80211_RATE_SHORT_PREAMBLE, \ 1788c2ecf20Sopenharmony_ci .hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx), \ 1798c2ecf20Sopenharmony_ci .hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + (_idx)), \ 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci#define OFDM_RATE(_idx, _rate) { \ 1838c2ecf20Sopenharmony_ci .bitrate = _rate, \ 1848c2ecf20Sopenharmony_ci .hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 1858c2ecf20Sopenharmony_ci .hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ 1868c2ecf20Sopenharmony_ci} 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_cistruct ieee80211_rate mt7615_rates[] = { 1898c2ecf20Sopenharmony_ci CCK_RATE(0, 10), 1908c2ecf20Sopenharmony_ci CCK_RATE(1, 20), 1918c2ecf20Sopenharmony_ci CCK_RATE(2, 55), 1928c2ecf20Sopenharmony_ci CCK_RATE(3, 110), 1938c2ecf20Sopenharmony_ci OFDM_RATE(11, 60), 1948c2ecf20Sopenharmony_ci OFDM_RATE(15, 90), 1958c2ecf20Sopenharmony_ci OFDM_RATE(10, 120), 1968c2ecf20Sopenharmony_ci OFDM_RATE(14, 180), 1978c2ecf20Sopenharmony_ci OFDM_RATE(9, 240), 1988c2ecf20Sopenharmony_ci OFDM_RATE(13, 360), 1998c2ecf20Sopenharmony_ci OFDM_RATE(8, 480), 2008c2ecf20Sopenharmony_ci OFDM_RATE(12, 540), 2018c2ecf20Sopenharmony_ci}; 2028c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_rates); 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_cistatic const struct ieee80211_iface_limit if_limits[] = { 2058c2ecf20Sopenharmony_ci { 2068c2ecf20Sopenharmony_ci .max = 1, 2078c2ecf20Sopenharmony_ci .types = BIT(NL80211_IFTYPE_ADHOC) 2088c2ecf20Sopenharmony_ci }, { 2098c2ecf20Sopenharmony_ci .max = MT7615_MAX_INTERFACES, 2108c2ecf20Sopenharmony_ci .types = BIT(NL80211_IFTYPE_AP) | 2118c2ecf20Sopenharmony_ci#ifdef CONFIG_MAC80211_MESH 2128c2ecf20Sopenharmony_ci BIT(NL80211_IFTYPE_MESH_POINT) | 2138c2ecf20Sopenharmony_ci#endif 2148c2ecf20Sopenharmony_ci BIT(NL80211_IFTYPE_P2P_CLIENT) | 2158c2ecf20Sopenharmony_ci BIT(NL80211_IFTYPE_P2P_GO) | 2168c2ecf20Sopenharmony_ci BIT(NL80211_IFTYPE_STATION) 2178c2ecf20Sopenharmony_ci } 2188c2ecf20Sopenharmony_ci}; 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_cistatic const struct ieee80211_iface_combination if_comb_radar[] = { 2218c2ecf20Sopenharmony_ci { 2228c2ecf20Sopenharmony_ci .limits = if_limits, 2238c2ecf20Sopenharmony_ci .n_limits = ARRAY_SIZE(if_limits), 2248c2ecf20Sopenharmony_ci .max_interfaces = 4, 2258c2ecf20Sopenharmony_ci .num_different_channels = 1, 2268c2ecf20Sopenharmony_ci .beacon_int_infra_match = true, 2278c2ecf20Sopenharmony_ci .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | 2288c2ecf20Sopenharmony_ci BIT(NL80211_CHAN_WIDTH_20) | 2298c2ecf20Sopenharmony_ci BIT(NL80211_CHAN_WIDTH_40) | 2308c2ecf20Sopenharmony_ci BIT(NL80211_CHAN_WIDTH_80) | 2318c2ecf20Sopenharmony_ci BIT(NL80211_CHAN_WIDTH_160) | 2328c2ecf20Sopenharmony_ci BIT(NL80211_CHAN_WIDTH_80P80), 2338c2ecf20Sopenharmony_ci } 2348c2ecf20Sopenharmony_ci}; 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_cistatic const struct ieee80211_iface_combination if_comb[] = { 2378c2ecf20Sopenharmony_ci { 2388c2ecf20Sopenharmony_ci .limits = if_limits, 2398c2ecf20Sopenharmony_ci .n_limits = ARRAY_SIZE(if_limits), 2408c2ecf20Sopenharmony_ci .max_interfaces = 4, 2418c2ecf20Sopenharmony_ci .num_different_channels = 1, 2428c2ecf20Sopenharmony_ci .beacon_int_infra_match = true, 2438c2ecf20Sopenharmony_ci } 2448c2ecf20Sopenharmony_ci}; 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_civoid mt7615_init_txpower(struct mt7615_dev *dev, 2478c2ecf20Sopenharmony_ci struct ieee80211_supported_band *sband) 2488c2ecf20Sopenharmony_ci{ 2498c2ecf20Sopenharmony_ci int i, n_chains = hweight8(dev->mphy.antenna_mask), target_chains; 2508c2ecf20Sopenharmony_ci int delta_idx, delta = mt76_tx_power_nss_delta(n_chains); 2518c2ecf20Sopenharmony_ci u8 *eep = (u8 *)dev->mt76.eeprom.data; 2528c2ecf20Sopenharmony_ci enum nl80211_band band = sband->band; 2538c2ecf20Sopenharmony_ci u8 rate_val; 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci delta_idx = mt7615_eeprom_get_power_delta_index(dev, band); 2568c2ecf20Sopenharmony_ci rate_val = eep[delta_idx]; 2578c2ecf20Sopenharmony_ci if ((rate_val & ~MT_EE_RATE_POWER_MASK) == 2588c2ecf20Sopenharmony_ci (MT_EE_RATE_POWER_EN | MT_EE_RATE_POWER_SIGN)) 2598c2ecf20Sopenharmony_ci delta += rate_val & MT_EE_RATE_POWER_MASK; 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci if (!is_mt7663(&dev->mt76) && mt7615_ext_pa_enabled(dev, band)) 2628c2ecf20Sopenharmony_ci target_chains = 1; 2638c2ecf20Sopenharmony_ci else 2648c2ecf20Sopenharmony_ci target_chains = n_chains; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci for (i = 0; i < sband->n_channels; i++) { 2678c2ecf20Sopenharmony_ci struct ieee80211_channel *chan = &sband->channels[i]; 2688c2ecf20Sopenharmony_ci u8 target_power = 0; 2698c2ecf20Sopenharmony_ci int j; 2708c2ecf20Sopenharmony_ci 2718c2ecf20Sopenharmony_ci for (j = 0; j < target_chains; j++) { 2728c2ecf20Sopenharmony_ci int index; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci index = mt7615_eeprom_get_target_power_index(dev, chan, j); 2758c2ecf20Sopenharmony_ci if (index < 0) 2768c2ecf20Sopenharmony_ci continue; 2778c2ecf20Sopenharmony_ci 2788c2ecf20Sopenharmony_ci target_power = max(target_power, eep[index]); 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci 2818c2ecf20Sopenharmony_ci target_power = DIV_ROUND_UP(target_power + delta, 2); 2828c2ecf20Sopenharmony_ci chan->max_power = min_t(int, chan->max_reg_power, 2838c2ecf20Sopenharmony_ci target_power); 2848c2ecf20Sopenharmony_ci chan->orig_mpwr = target_power; 2858c2ecf20Sopenharmony_ci } 2868c2ecf20Sopenharmony_ci} 2878c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_init_txpower); 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_cistatic void 2908c2ecf20Sopenharmony_cimt7615_regd_notifier(struct wiphy *wiphy, 2918c2ecf20Sopenharmony_ci struct regulatory_request *request) 2928c2ecf20Sopenharmony_ci{ 2938c2ecf20Sopenharmony_ci struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); 2948c2ecf20Sopenharmony_ci struct mt7615_dev *dev = mt7615_hw_dev(hw); 2958c2ecf20Sopenharmony_ci struct mt76_phy *mphy = hw->priv; 2968c2ecf20Sopenharmony_ci struct mt7615_phy *phy = mphy->priv; 2978c2ecf20Sopenharmony_ci struct cfg80211_chan_def *chandef = &mphy->chandef; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci dev->mt76.region = request->dfs_region; 3008c2ecf20Sopenharmony_ci 3018c2ecf20Sopenharmony_ci if (!(chandef->chan->flags & IEEE80211_CHAN_RADAR)) 3028c2ecf20Sopenharmony_ci return; 3038c2ecf20Sopenharmony_ci 3048c2ecf20Sopenharmony_ci mt7615_mutex_acquire(dev); 3058c2ecf20Sopenharmony_ci mt7615_dfs_init_radar_detector(phy); 3068c2ecf20Sopenharmony_ci mt7615_mutex_release(dev); 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistatic void 3108c2ecf20Sopenharmony_cimt7615_init_wiphy(struct ieee80211_hw *hw) 3118c2ecf20Sopenharmony_ci{ 3128c2ecf20Sopenharmony_ci struct mt7615_phy *phy = mt7615_hw_phy(hw); 3138c2ecf20Sopenharmony_ci struct wiphy *wiphy = hw->wiphy; 3148c2ecf20Sopenharmony_ci 3158c2ecf20Sopenharmony_ci hw->queues = 4; 3168c2ecf20Sopenharmony_ci hw->max_rates = 3; 3178c2ecf20Sopenharmony_ci hw->max_report_rates = 7; 3188c2ecf20Sopenharmony_ci hw->max_rate_tries = 11; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci phy->slottime = 9; 3218c2ecf20Sopenharmony_ci 3228c2ecf20Sopenharmony_ci hw->sta_data_size = sizeof(struct mt7615_sta); 3238c2ecf20Sopenharmony_ci hw->vif_data_size = sizeof(struct mt7615_vif); 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci if (is_mt7663(&phy->dev->mt76)) { 3268c2ecf20Sopenharmony_ci wiphy->iface_combinations = if_comb; 3278c2ecf20Sopenharmony_ci wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); 3288c2ecf20Sopenharmony_ci } else { 3298c2ecf20Sopenharmony_ci wiphy->iface_combinations = if_comb_radar; 3308c2ecf20Sopenharmony_ci wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_radar); 3318c2ecf20Sopenharmony_ci } 3328c2ecf20Sopenharmony_ci wiphy->reg_notifier = mt7615_regd_notifier; 3338c2ecf20Sopenharmony_ci 3348c2ecf20Sopenharmony_ci wiphy->max_sched_scan_plan_interval = MT7615_MAX_SCHED_SCAN_INTERVAL; 3358c2ecf20Sopenharmony_ci wiphy->max_sched_scan_ie_len = IEEE80211_MAX_DATA_LEN; 3368c2ecf20Sopenharmony_ci wiphy->max_scan_ie_len = MT7615_SCAN_IE_LEN; 3378c2ecf20Sopenharmony_ci wiphy->max_sched_scan_ssids = MT7615_MAX_SCHED_SCAN_SSID; 3388c2ecf20Sopenharmony_ci wiphy->max_match_sets = MT7615_MAX_SCAN_MATCH; 3398c2ecf20Sopenharmony_ci wiphy->max_sched_scan_reqs = 1; 3408c2ecf20Sopenharmony_ci wiphy->max_scan_ssids = 4; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SET_SCAN_DWELL); 3438c2ecf20Sopenharmony_ci wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_VHT_IBSS); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); 3468c2ecf20Sopenharmony_ci ieee80211_hw_set(hw, TX_STATUS_NO_AMPDU_LEN); 3478c2ecf20Sopenharmony_ci ieee80211_hw_set(hw, WANT_MONITOR_VIF); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci if (is_mt7615(&phy->dev->mt76)) 3508c2ecf20Sopenharmony_ci hw->max_tx_fragments = MT_TXP_MAX_BUF_NUM; 3518c2ecf20Sopenharmony_ci else 3528c2ecf20Sopenharmony_ci hw->max_tx_fragments = MT_HW_TXP_MAX_BUF_NUM; 3538c2ecf20Sopenharmony_ci} 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_cistatic void 3568c2ecf20Sopenharmony_cimt7615_cap_dbdc_enable(struct mt7615_dev *dev) 3578c2ecf20Sopenharmony_ci{ 3588c2ecf20Sopenharmony_ci dev->mphy.sband_5g.sband.vht_cap.cap &= 3598c2ecf20Sopenharmony_ci ~(IEEE80211_VHT_CAP_SHORT_GI_160 | 3608c2ecf20Sopenharmony_ci IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ); 3618c2ecf20Sopenharmony_ci if (dev->chainmask == 0xf) 3628c2ecf20Sopenharmony_ci dev->mphy.antenna_mask = dev->chainmask >> 2; 3638c2ecf20Sopenharmony_ci else 3648c2ecf20Sopenharmony_ci dev->mphy.antenna_mask = dev->chainmask >> 1; 3658c2ecf20Sopenharmony_ci dev->phy.chainmask = dev->mphy.antenna_mask; 3668c2ecf20Sopenharmony_ci dev->mphy.hw->wiphy->available_antennas_rx = dev->phy.chainmask; 3678c2ecf20Sopenharmony_ci dev->mphy.hw->wiphy->available_antennas_tx = dev->phy.chainmask; 3688c2ecf20Sopenharmony_ci mt76_set_stream_caps(&dev->mphy, true); 3698c2ecf20Sopenharmony_ci} 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_cistatic void 3728c2ecf20Sopenharmony_cimt7615_cap_dbdc_disable(struct mt7615_dev *dev) 3738c2ecf20Sopenharmony_ci{ 3748c2ecf20Sopenharmony_ci dev->mphy.sband_5g.sband.vht_cap.cap |= 3758c2ecf20Sopenharmony_ci IEEE80211_VHT_CAP_SHORT_GI_160 | 3768c2ecf20Sopenharmony_ci IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; 3778c2ecf20Sopenharmony_ci dev->mphy.antenna_mask = dev->chainmask; 3788c2ecf20Sopenharmony_ci dev->phy.chainmask = dev->chainmask; 3798c2ecf20Sopenharmony_ci dev->mphy.hw->wiphy->available_antennas_rx = dev->chainmask; 3808c2ecf20Sopenharmony_ci dev->mphy.hw->wiphy->available_antennas_tx = dev->chainmask; 3818c2ecf20Sopenharmony_ci mt76_set_stream_caps(&dev->mphy, true); 3828c2ecf20Sopenharmony_ci} 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ciint mt7615_register_ext_phy(struct mt7615_dev *dev) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci struct mt7615_phy *phy = mt7615_ext_phy(dev); 3878c2ecf20Sopenharmony_ci struct mt76_phy *mphy; 3888c2ecf20Sopenharmony_ci int ret; 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci if (!is_mt7615(&dev->mt76)) 3918c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 3928c2ecf20Sopenharmony_ci 3938c2ecf20Sopenharmony_ci if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) 3948c2ecf20Sopenharmony_ci return -EINVAL; 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci if (phy) 3978c2ecf20Sopenharmony_ci return 0; 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci mt7615_cap_dbdc_enable(dev); 4008c2ecf20Sopenharmony_ci mphy = mt76_alloc_phy(&dev->mt76, sizeof(*phy), &mt7615_ops); 4018c2ecf20Sopenharmony_ci if (!mphy) 4028c2ecf20Sopenharmony_ci return -ENOMEM; 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci phy = mphy->priv; 4058c2ecf20Sopenharmony_ci phy->dev = dev; 4068c2ecf20Sopenharmony_ci phy->mt76 = mphy; 4078c2ecf20Sopenharmony_ci phy->chainmask = dev->chainmask & ~dev->phy.chainmask; 4088c2ecf20Sopenharmony_ci mphy->antenna_mask = BIT(hweight8(phy->chainmask)) - 1; 4098c2ecf20Sopenharmony_ci mt7615_init_wiphy(mphy->hw); 4108c2ecf20Sopenharmony_ci 4118c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&phy->mac_work, mt7615_mac_work); 4128c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&phy->scan_work, mt7615_scan_work); 4138c2ecf20Sopenharmony_ci skb_queue_head_init(&phy->scan_event_list); 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci INIT_WORK(&phy->roc_work, mt7615_roc_work); 4168c2ecf20Sopenharmony_ci timer_setup(&phy->roc_timer, mt7615_roc_timer, 0); 4178c2ecf20Sopenharmony_ci init_waitqueue_head(&phy->roc_wait); 4188c2ecf20Sopenharmony_ci 4198c2ecf20Sopenharmony_ci mt7615_mac_set_scs(phy, true); 4208c2ecf20Sopenharmony_ci 4218c2ecf20Sopenharmony_ci /* 4228c2ecf20Sopenharmony_ci * Make the secondary PHY MAC address local without overlapping with 4238c2ecf20Sopenharmony_ci * the usual MAC address allocation scheme on multiple virtual interfaces 4248c2ecf20Sopenharmony_ci */ 4258c2ecf20Sopenharmony_ci mphy->hw->wiphy->perm_addr[0] |= 2; 4268c2ecf20Sopenharmony_ci mphy->hw->wiphy->perm_addr[0] ^= BIT(7); 4278c2ecf20Sopenharmony_ci 4288c2ecf20Sopenharmony_ci /* second phy can only handle 5 GHz */ 4298c2ecf20Sopenharmony_ci mphy->sband_2g.sband.n_channels = 0; 4308c2ecf20Sopenharmony_ci mphy->hw->wiphy->bands[NL80211_BAND_2GHZ] = NULL; 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci ret = mt76_register_phy(mphy); 4338c2ecf20Sopenharmony_ci if (ret) 4348c2ecf20Sopenharmony_ci ieee80211_free_hw(mphy->hw); 4358c2ecf20Sopenharmony_ci 4368c2ecf20Sopenharmony_ci return ret; 4378c2ecf20Sopenharmony_ci} 4388c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_register_ext_phy); 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_civoid mt7615_unregister_ext_phy(struct mt7615_dev *dev) 4418c2ecf20Sopenharmony_ci{ 4428c2ecf20Sopenharmony_ci struct mt7615_phy *phy = mt7615_ext_phy(dev); 4438c2ecf20Sopenharmony_ci struct mt76_phy *mphy = dev->mt76.phy2; 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci if (!phy) 4468c2ecf20Sopenharmony_ci return; 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci mt7615_cap_dbdc_disable(dev); 4498c2ecf20Sopenharmony_ci mt76_unregister_phy(mphy); 4508c2ecf20Sopenharmony_ci ieee80211_free_hw(mphy->hw); 4518c2ecf20Sopenharmony_ci} 4528c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_unregister_ext_phy); 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_civoid mt7615_init_device(struct mt7615_dev *dev) 4558c2ecf20Sopenharmony_ci{ 4568c2ecf20Sopenharmony_ci struct ieee80211_hw *hw = mt76_hw(dev); 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci dev->phy.dev = dev; 4598c2ecf20Sopenharmony_ci dev->phy.mt76 = &dev->mt76.phy; 4608c2ecf20Sopenharmony_ci dev->mt76.phy.priv = &dev->phy; 4618c2ecf20Sopenharmony_ci 4628c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&dev->pm.ps_work, mt7615_pm_power_save_work); 4638c2ecf20Sopenharmony_ci INIT_WORK(&dev->pm.wake_work, mt7615_pm_wake_work); 4648c2ecf20Sopenharmony_ci init_completion(&dev->pm.wake_cmpl); 4658c2ecf20Sopenharmony_ci spin_lock_init(&dev->pm.txq_lock); 4668c2ecf20Sopenharmony_ci set_bit(MT76_STATE_PM, &dev->mphy.state); 4678c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&dev->phy.mac_work, mt7615_mac_work); 4688c2ecf20Sopenharmony_ci INIT_DELAYED_WORK(&dev->phy.scan_work, mt7615_scan_work); 4698c2ecf20Sopenharmony_ci skb_queue_head_init(&dev->phy.scan_event_list); 4708c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&dev->sta_poll_list); 4718c2ecf20Sopenharmony_ci spin_lock_init(&dev->sta_poll_lock); 4728c2ecf20Sopenharmony_ci init_waitqueue_head(&dev->reset_wait); 4738c2ecf20Sopenharmony_ci init_waitqueue_head(&dev->phy.roc_wait); 4748c2ecf20Sopenharmony_ci 4758c2ecf20Sopenharmony_ci INIT_WORK(&dev->reset_work, mt7615_mac_reset_work); 4768c2ecf20Sopenharmony_ci INIT_WORK(&dev->phy.roc_work, mt7615_roc_work); 4778c2ecf20Sopenharmony_ci timer_setup(&dev->phy.roc_timer, mt7615_roc_timer, 0); 4788c2ecf20Sopenharmony_ci 4798c2ecf20Sopenharmony_ci mt7615_init_wiphy(hw); 4808c2ecf20Sopenharmony_ci dev->pm.idle_timeout = MT7615_PM_TIMEOUT; 4818c2ecf20Sopenharmony_ci dev->mphy.sband_2g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; 4828c2ecf20Sopenharmony_ci dev->mphy.sband_5g.sband.ht_cap.cap |= IEEE80211_HT_CAP_LDPC_CODING; 4838c2ecf20Sopenharmony_ci dev->mphy.sband_5g.sband.vht_cap.cap |= 4848c2ecf20Sopenharmony_ci IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | 4858c2ecf20Sopenharmony_ci IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; 4868c2ecf20Sopenharmony_ci mt7615_cap_dbdc_disable(dev); 4878c2ecf20Sopenharmony_ci dev->phy.dfs_state = -1; 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci#ifdef CONFIG_NL80211_TESTMODE 4908c2ecf20Sopenharmony_ci dev->mt76.test_ops = &mt7615_testmode_ops; 4918c2ecf20Sopenharmony_ci#endif 4928c2ecf20Sopenharmony_ci} 4938c2ecf20Sopenharmony_ciEXPORT_SYMBOL_GPL(mt7615_init_device); 494