-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mt76: mt7921: introduce mt7921e support
Introduce support for mt7921e 802.11ax (Wi-Fi 6) 2x2:2SS chipset. Co-developed-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Lorenzo Bianconi <[email protected]> Co-developed-by: Soul Huang <[email protected]> Signed-off-by: Soul Huang <[email protected]> Signed-off-by: Sean Wang <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
- Loading branch information
1 parent
e0f9fdd
commit 5c14a5f
Showing
6 changed files
with
449 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# SPDX-License-Identifier: ISC | ||
config MT7921E | ||
tristate "MediaTek MT7921E (PCIe) support" | ||
select MT76_CORE | ||
depends on MAC80211 | ||
depends on PCI | ||
help | ||
This adds support for MT7921E 802.11ax 2x2:2SS wireless devices. | ||
|
||
To compile this driver as a module, choose M here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#SPDX-License-Identifier: ISC | ||
|
||
obj-$(CONFIG_MT7921E) += mt7921e.o | ||
|
||
mt7921e-y := pci.o mac.o mcu.o dma.o eeprom.o main.o init.o debugfs.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
// SPDX-License-Identifier: ISC | ||
/* Copyright (C) 2020 MediaTek Inc. */ | ||
|
||
#include <linux/etherdevice.h> | ||
#include "mt7921.h" | ||
#include "mac.h" | ||
#include "eeprom.h" | ||
|
||
#define CCK_RATE(_idx, _rate) { \ | ||
.bitrate = _rate, \ | ||
.flags = IEEE80211_RATE_SHORT_PREAMBLE, \ | ||
.hw_value = (MT_PHY_TYPE_CCK << 8) | (_idx), \ | ||
.hw_value_short = (MT_PHY_TYPE_CCK << 8) | (4 + (_idx)), \ | ||
} | ||
|
||
#define OFDM_RATE(_idx, _rate) { \ | ||
.bitrate = _rate, \ | ||
.hw_value = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ | ||
.hw_value_short = (MT_PHY_TYPE_OFDM << 8) | (_idx), \ | ||
} | ||
|
||
static struct ieee80211_rate mt7921_rates[] = { | ||
CCK_RATE(0, 10), | ||
CCK_RATE(1, 20), | ||
CCK_RATE(2, 55), | ||
CCK_RATE(3, 110), | ||
OFDM_RATE(11, 60), | ||
OFDM_RATE(15, 90), | ||
OFDM_RATE(10, 120), | ||
OFDM_RATE(14, 180), | ||
OFDM_RATE(9, 240), | ||
OFDM_RATE(13, 360), | ||
OFDM_RATE(8, 480), | ||
OFDM_RATE(12, 540), | ||
}; | ||
|
||
static const struct ieee80211_iface_limit if_limits[] = { | ||
{ | ||
.max = MT7921_MAX_INTERFACES, | ||
.types = BIT(NL80211_IFTYPE_STATION) | ||
} | ||
}; | ||
|
||
static const struct ieee80211_iface_combination if_comb[] = { | ||
{ | ||
.limits = if_limits, | ||
.n_limits = ARRAY_SIZE(if_limits), | ||
.max_interfaces = MT7921_MAX_INTERFACES, | ||
.num_different_channels = 1, | ||
.beacon_int_infra_match = true, | ||
} | ||
}; | ||
|
||
static void | ||
mt7921_init_wiphy(struct ieee80211_hw *hw) | ||
{ | ||
struct mt7921_phy *phy = mt7921_hw_phy(hw); | ||
struct wiphy *wiphy = hw->wiphy; | ||
|
||
hw->queues = 4; | ||
hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; | ||
hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; | ||
|
||
phy->slottime = 9; | ||
|
||
hw->sta_data_size = sizeof(struct mt7921_sta); | ||
hw->vif_data_size = sizeof(struct mt7921_vif); | ||
|
||
wiphy->iface_combinations = if_comb; | ||
wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); | ||
wiphy->max_scan_ie_len = MT7921_SCAN_IE_LEN; | ||
wiphy->max_scan_ssids = 4; | ||
wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; | ||
|
||
wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_SET_SCAN_DWELL); | ||
|
||
ieee80211_hw_set(hw, SINGLE_SCAN_ON_ALL_BANDS); | ||
ieee80211_hw_set(hw, HAS_RATE_CONTROL); | ||
ieee80211_hw_set(hw, SUPPORTS_TX_ENCAP_OFFLOAD); | ||
ieee80211_hw_set(hw, WANT_MONITOR_VIF); | ||
|
||
hw->max_tx_fragments = 4; | ||
} | ||
|
||
static void | ||
mt7921_mac_init_band(struct mt7921_dev *dev, u8 band) | ||
{ | ||
u32 mask, set; | ||
|
||
mt76_rmw_field(dev, MT_TMAC_CTCR0(band), | ||
MT_TMAC_CTCR0_INS_DDLMT_REFTIME, 0x3f); | ||
mt76_set(dev, MT_TMAC_CTCR0(band), | ||
MT_TMAC_CTCR0_INS_DDLMT_VHT_SMPDU_EN | | ||
MT_TMAC_CTCR0_INS_DDLMT_EN); | ||
|
||
mask = MT_MDP_RCFR0_MCU_RX_MGMT | | ||
MT_MDP_RCFR0_MCU_RX_CTL_NON_BAR | | ||
MT_MDP_RCFR0_MCU_RX_CTL_BAR; | ||
set = FIELD_PREP(MT_MDP_RCFR0_MCU_RX_MGMT, MT_MDP_TO_HIF) | | ||
FIELD_PREP(MT_MDP_RCFR0_MCU_RX_CTL_NON_BAR, MT_MDP_TO_HIF) | | ||
FIELD_PREP(MT_MDP_RCFR0_MCU_RX_CTL_BAR, MT_MDP_TO_HIF); | ||
mt76_rmw(dev, MT_MDP_BNRCFR0(band), mask, set); | ||
|
||
mask = MT_MDP_RCFR1_MCU_RX_BYPASS | | ||
MT_MDP_RCFR1_RX_DROPPED_UCAST | | ||
MT_MDP_RCFR1_RX_DROPPED_MCAST; | ||
set = FIELD_PREP(MT_MDP_RCFR1_MCU_RX_BYPASS, MT_MDP_TO_HIF) | | ||
FIELD_PREP(MT_MDP_RCFR1_RX_DROPPED_UCAST, MT_MDP_TO_HIF) | | ||
FIELD_PREP(MT_MDP_RCFR1_RX_DROPPED_MCAST, MT_MDP_TO_HIF); | ||
mt76_rmw(dev, MT_MDP_BNRCFR1(band), mask, set); | ||
|
||
mt76_set(dev, MT_WF_RMAC_MIB_TIME0(band), MT_WF_RMAC_MIB_RXTIME_EN); | ||
mt76_set(dev, MT_WF_RMAC_MIB_AIRTIME0(band), MT_WF_RMAC_MIB_RXTIME_EN); | ||
|
||
mt76_rmw_field(dev, MT_DMA_DCR0(band), MT_DMA_DCR0_MAX_RX_LEN, 1536); | ||
/* disable rx rate report by default due to hw issues */ | ||
mt76_clear(dev, MT_DMA_DCR0(band), MT_DMA_DCR0_RXD_G5_EN); | ||
} | ||
|
||
static void mt7921_mac_init(struct mt7921_dev *dev) | ||
{ | ||
int i; | ||
|
||
mt76_rmw_field(dev, MT_MDP_DCR1, MT_MDP_DCR1_MAX_RX_LEN, 1536); | ||
/* disable hardware de-agg */ | ||
mt76_clear(dev, MT_MDP_DCR0, MT_MDP_DCR0_DAMSDU_EN); | ||
mt76_clear(dev, MT_MDP_DCR0, MT_MDP_DCR0_RX_HDR_TRANS_EN); | ||
|
||
for (i = 0; i < MT7921_WTBL_SIZE; i++) | ||
mt7921_mac_wtbl_update(dev, i, | ||
MT_WTBL_UPDATE_ADM_COUNT_CLEAR); | ||
for (i = 0; i < 2; i++) | ||
mt7921_mac_init_band(dev, i); | ||
|
||
mt7921_mcu_set_rts_thresh(&dev->phy, 0x92b); | ||
} | ||
|
||
static void mt7921_init_work(struct work_struct *work) | ||
{ | ||
struct mt7921_dev *dev = container_of(work, struct mt7921_dev, | ||
init_work); | ||
|
||
mt7921_mcu_set_eeprom(dev); | ||
mt7921_mac_init(dev); | ||
} | ||
|
||
static int mt7921_init_hardware(struct mt7921_dev *dev) | ||
{ | ||
int ret, idx; | ||
|
||
INIT_WORK(&dev->init_work, mt7921_init_work); | ||
spin_lock_init(&dev->token_lock); | ||
idr_init(&dev->token); | ||
|
||
ret = mt7921_dma_init(dev); | ||
if (ret) | ||
return ret; | ||
|
||
set_bit(MT76_STATE_INITIALIZED, &dev->mphy.state); | ||
|
||
/* force firmware operation mode into normal state, | ||
* which should be set before firmware download stage. | ||
*/ | ||
mt76_wr(dev, MT_SWDEF_MODE, MT_SWDEF_NORMAL_MODE); | ||
|
||
ret = mt7921_mcu_init(dev); | ||
if (ret) | ||
return ret; | ||
|
||
ret = mt7921_eeprom_init(dev); | ||
if (ret < 0) | ||
return ret; | ||
|
||
/* Beacon and mgmt frames should occupy wcid 0 */ | ||
idx = mt76_wcid_alloc(dev->mt76.wcid_mask, MT7921_WTBL_STA - 1); | ||
if (idx) | ||
return -ENOSPC; | ||
|
||
dev->mt76.global_wcid.idx = idx; | ||
dev->mt76.global_wcid.hw_key_idx = -1; | ||
dev->mt76.global_wcid.tx_info |= MT_WCID_TX_INFO_SET; | ||
rcu_assign_pointer(dev->mt76.wcid[idx], &dev->mt76.global_wcid); | ||
|
||
return 0; | ||
} | ||
|
||
int mt7921_register_device(struct mt7921_dev *dev) | ||
{ | ||
struct ieee80211_hw *hw = mt76_hw(dev); | ||
int ret; | ||
|
||
dev->phy.dev = dev; | ||
dev->phy.mt76 = &dev->mt76.phy; | ||
dev->mt76.phy.priv = &dev->phy; | ||
INIT_LIST_HEAD(&dev->phy.stats_list); | ||
INIT_DELAYED_WORK(&dev->mphy.mac_work, mt7921_mac_work); | ||
INIT_DELAYED_WORK(&dev->phy.scan_work, mt7921_scan_work); | ||
skb_queue_head_init(&dev->phy.scan_event_list); | ||
INIT_LIST_HEAD(&dev->sta_poll_list); | ||
spin_lock_init(&dev->sta_poll_lock); | ||
|
||
init_waitqueue_head(&dev->reset_wait); | ||
INIT_WORK(&dev->reset_work, mt7921_mac_reset_work); | ||
|
||
ret = mt7921_init_hardware(dev); | ||
if (ret) | ||
return ret; | ||
|
||
mt7921_init_wiphy(hw); | ||
dev->mphy.sband_2g.sband.ht_cap.cap |= | ||
IEEE80211_HT_CAP_LDPC_CODING | | ||
IEEE80211_HT_CAP_MAX_AMSDU; | ||
dev->mphy.sband_5g.sband.ht_cap.cap |= | ||
IEEE80211_HT_CAP_LDPC_CODING | | ||
IEEE80211_HT_CAP_MAX_AMSDU; | ||
dev->mphy.sband_5g.sband.vht_cap.cap |= | ||
IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | | ||
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; | ||
dev->mphy.sband_5g.sband.vht_cap.cap |= | ||
IEEE80211_VHT_CAP_SHORT_GI_160 | | ||
IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; | ||
dev->mphy.hw->wiphy->available_antennas_rx = dev->mphy.chainmask; | ||
dev->mphy.hw->wiphy->available_antennas_tx = dev->mphy.chainmask; | ||
|
||
mt76_set_stream_caps(&dev->mphy, true); | ||
mt7921_set_stream_he_caps(&dev->phy); | ||
|
||
ret = mt76_register_device(&dev->mt76, true, mt7921_rates, | ||
ARRAY_SIZE(mt7921_rates)); | ||
if (ret) | ||
return ret; | ||
|
||
ieee80211_queue_work(mt76_hw(dev), &dev->init_work); | ||
|
||
return 0; | ||
} | ||
|
||
void mt7921_unregister_device(struct mt7921_dev *dev) | ||
{ | ||
mt76_unregister_device(&dev->mt76); | ||
mt7921_mcu_exit(dev); | ||
mt7921_dma_cleanup(dev); | ||
|
||
mt7921_tx_token_put(dev); | ||
|
||
tasklet_disable(&dev->irq_tasklet); | ||
mt76_free_device(&dev->mt76); | ||
} |
Oops, something went wrong.