Commit 65dec62f authored by Bo Jiao's avatar Bo Jiao Committed by Felix Fietkau

mt76: mt7915: rework eeprom.c to adapt mt7916 changes

This is an intermediate patch to add mt7916 support.
Co-developed-by: default avatarSujuan Chen <sujuan.chen@mediatek.com>
Signed-off-by: default avatarSujuan Chen <sujuan.chen@mediatek.com>
Co-developed-by: default avatarRyder Lee <ryder.lee@mediatek.com>
Signed-off-by: default avatarRyder Lee <ryder.lee@mediatek.com>
Signed-off-by: default avatarBo Jiao <Bo.Jiao@mediatek.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 1c7393e6
...@@ -10,6 +10,7 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) ...@@ -10,6 +10,7 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
struct mt76_dev *mdev = &dev->mt76; struct mt76_dev *mdev = &dev->mt76;
u8 *eeprom = mdev->eeprom.data; u8 *eeprom = mdev->eeprom.data;
u32 val = eeprom[MT_EE_DO_PRE_CAL]; u32 val = eeprom[MT_EE_DO_PRE_CAL];
u32 offs;
if (!dev->flash_mode) if (!dev->flash_mode)
return 0; return 0;
...@@ -22,7 +23,9 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) ...@@ -22,7 +23,9 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
if (!dev->cal) if (!dev->cal)
return -ENOMEM; return -ENOMEM;
return mt76_get_of_eeprom(mdev, dev->cal, MT_EE_PRECAL, val); offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2;
return mt76_get_of_eeprom(mdev, dev->cal, offs, val);
} }
static int mt7915_check_eeprom(struct mt7915_dev *dev) static int mt7915_check_eeprom(struct mt7915_dev *dev)
...@@ -98,7 +101,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) ...@@ -98,7 +101,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
return mt7915_check_eeprom(dev); return mt7915_check_eeprom(dev);
} }
void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy) static void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy)
{ {
struct mt7915_dev *dev = phy->dev; struct mt7915_dev *dev = phy->dev;
bool ext_phy = phy != &dev->phy; bool ext_phy = phy != &dev->phy;
...@@ -124,32 +127,55 @@ void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy) ...@@ -124,32 +127,55 @@ void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy)
} }
} }
static void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev) void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev,
struct mt7915_phy *phy)
{ {
u8 nss, nss_band, *eeprom = dev->mt76.eeprom.data; u8 nss, nss_band, *eeprom = dev->mt76.eeprom.data;
struct mt76_phy *mphy = phy->mt76;
bool ext_phy = phy != &dev->phy;
mt7915_eeprom_parse_band_config(&dev->phy); mt7915_eeprom_parse_band_config(phy);
/* read tx/rx mask from eeprom */
if (is_mt7915(&dev->mt76)) {
nss = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH,
eeprom[MT_EE_WIFI_CONF]);
} else {
nss = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH,
eeprom[MT_EE_WIFI_CONF + ext_phy]);
}
/* read tx mask from eeprom */
nss = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH, eeprom[MT_EE_WIFI_CONF]);
if (!nss || nss > 4) if (!nss || nss > 4)
nss = 4; nss = 4;
/* read tx/rx stream */
nss_band = nss; nss_band = nss;
if (dev->dbdc_support) { if (dev->dbdc_support) {
if (is_mt7915(&dev->mt76)) {
nss_band = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B0, nss_band = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B0,
eeprom[MT_EE_WIFI_CONF + 3]); eeprom[MT_EE_WIFI_CONF + 3]);
if (ext_phy)
nss_band = FIELD_GET(MT_EE_WIFI_CONF3_TX_PATH_B1,
eeprom[MT_EE_WIFI_CONF + 3]);
} else {
nss_band = FIELD_GET(MT_EE_WIFI_CONF_STREAM_NUM,
eeprom[MT_EE_WIFI_CONF + 2 + ext_phy]);
}
if (!nss_band || nss_band > 2) if (!nss_band || nss_band > 2)
nss_band = 2; nss_band = 2;
}
if (nss_band >= nss) if (nss_band > nss) {
nss = 4; dev_err(dev->mt76.dev,
"nss mismatch, nss(%d) nss_band(%d) ext_phy(%d)\n",
nss, nss_band, ext_phy);
nss = nss_band;
} }
dev->chainmask = BIT(nss) - 1; mphy->chainmask = ext_phy ? (BIT(nss_band) - 1) << 2 : (BIT(nss_band) - 1);
dev->mphy.antenna_mask = BIT(nss_band) - 1; mphy->antenna_mask = BIT(hweight8(mphy->chainmask)) - 1;
dev->mphy.chainmask = dev->mphy.antenna_mask; dev->chainmask |= mphy->chainmask;
} }
int mt7915_eeprom_init(struct mt7915_dev *dev) int mt7915_eeprom_init(struct mt7915_dev *dev)
...@@ -171,7 +197,7 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) ...@@ -171,7 +197,7 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
if (ret) if (ret)
return ret; return ret;
mt7915_eeprom_parse_hw_cap(dev); mt7915_eeprom_parse_hw_cap(dev, &dev->phy);
memcpy(dev->mphy.macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR, memcpy(dev->mphy.macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
ETH_ALEN); ETH_ALEN);
...@@ -194,15 +220,20 @@ int mt7915_eeprom_get_target_power(struct mt7915_dev *dev, ...@@ -194,15 +220,20 @@ int mt7915_eeprom_get_target_power(struct mt7915_dev *dev,
tssi_on = mt7915_tssi_enabled(dev, chan->band); tssi_on = mt7915_tssi_enabled(dev, chan->band);
if (chan->band == NL80211_BAND_2GHZ) { if (chan->band == NL80211_BAND_2GHZ) {
index = MT_EE_TX0_POWER_2G + chain_idx * 3; u32 power = is_mt7915(&dev->mt76) ?
MT_EE_TX0_POWER_2G : MT_EE_TX0_POWER_2G_V2;
index = power + chain_idx * 3;
target_power = eeprom[index]; target_power = eeprom[index];
if (!tssi_on) if (!tssi_on)
target_power += eeprom[index + 1]; target_power += eeprom[index + 1];
} else { } else {
int group = mt7915_get_channel_group(chan->hw_value); int group = mt7915_get_channel_group(chan->hw_value);
u32 power = is_mt7915(&dev->mt76) ?
MT_EE_TX0_POWER_5G : MT_EE_TX0_POWER_5G_V2;
index = MT_EE_TX0_POWER_5G + chain_idx * 12; index = power + chain_idx * 12;
target_power = eeprom[index + group]; target_power = eeprom[index + group];
if (!tssi_on) if (!tssi_on)
...@@ -217,11 +248,18 @@ s8 mt7915_eeprom_get_power_delta(struct mt7915_dev *dev, int band) ...@@ -217,11 +248,18 @@ s8 mt7915_eeprom_get_power_delta(struct mt7915_dev *dev, int band)
u8 *eeprom = dev->mt76.eeprom.data; u8 *eeprom = dev->mt76.eeprom.data;
u32 val; u32 val;
s8 delta; s8 delta;
u32 rate_2g, rate_5g;
rate_2g = is_mt7915(&dev->mt76) ?
MT_EE_RATE_DELTA_2G : MT_EE_RATE_DELTA_2G_V2;
rate_5g = is_mt7915(&dev->mt76) ?
MT_EE_RATE_DELTA_5G : MT_EE_RATE_DELTA_5G_V2;
if (band == NL80211_BAND_2GHZ) if (band == NL80211_BAND_2GHZ)
val = eeprom[MT_EE_RATE_DELTA_2G]; val = eeprom[rate_2g];
else else
val = eeprom[MT_EE_RATE_DELTA_5G]; val = eeprom[rate_5g];
if (!(val & MT_EE_RATE_DELTA_EN)) if (!(val & MT_EE_RATE_DELTA_EN))
return 0; return 0;
......
...@@ -23,11 +23,17 @@ enum mt7915_eeprom_field { ...@@ -23,11 +23,17 @@ enum mt7915_eeprom_field {
MT_EE_RATE_DELTA_5G = 0x29d, MT_EE_RATE_DELTA_5G = 0x29d,
MT_EE_TX0_POWER_2G = 0x2fc, MT_EE_TX0_POWER_2G = 0x2fc,
MT_EE_TX0_POWER_5G = 0x34b, MT_EE_TX0_POWER_5G = 0x34b,
MT_EE_RATE_DELTA_2G_V2 = 0x7d3,
MT_EE_RATE_DELTA_5G_V2 = 0x81e,
MT_EE_TX0_POWER_2G_V2 = 0x441,
MT_EE_TX0_POWER_5G_V2 = 0x445,
MT_EE_ADIE_FT_VERSION = 0x9a0, MT_EE_ADIE_FT_VERSION = 0x9a0,
__MT_EE_MAX = 0xe00, __MT_EE_MAX = 0xe00,
__MT_EE_MAX_V2 = 0x1000,
/* 0xe10 ~ 0x5780 used to save group cal data */ /* 0xe10 ~ 0x5780 used to save group cal data */
MT_EE_PRECAL = 0xe10 MT_EE_PRECAL = 0xe10,
MT_EE_PRECAL_V2 = 0x1010
}; };
#define MT_EE_WIFI_CAL_GROUP BIT(0) #define MT_EE_WIFI_CAL_GROUP BIT(0)
...@@ -39,6 +45,7 @@ enum mt7915_eeprom_field { ...@@ -39,6 +45,7 @@ enum mt7915_eeprom_field {
#define MT_EE_WIFI_CONF0_TX_PATH GENMASK(2, 0) #define MT_EE_WIFI_CONF0_TX_PATH GENMASK(2, 0)
#define MT_EE_WIFI_CONF0_BAND_SEL GENMASK(7, 6) #define MT_EE_WIFI_CONF0_BAND_SEL GENMASK(7, 6)
#define MT_EE_WIFI_CONF1_BAND_SEL GENMASK(7, 6) #define MT_EE_WIFI_CONF1_BAND_SEL GENMASK(7, 6)
#define MT_EE_WIFI_CONF_STREAM_NUM GENMASK(7, 5)
#define MT_EE_WIFI_CONF3_TX_PATH_B0 GENMASK(1, 0) #define MT_EE_WIFI_CONF3_TX_PATH_B0 GENMASK(1, 0)
#define MT_EE_WIFI_CONF3_TX_PATH_B1 GENMASK(5, 4) #define MT_EE_WIFI_CONF3_TX_PATH_B1 GENMASK(5, 4)
#define MT_EE_WIFI_CONF7_TSSI0_2G BIT(0) #define MT_EE_WIFI_CONF7_TSSI0_2G BIT(0)
......
...@@ -307,6 +307,7 @@ mt7915_init_wiphy(struct ieee80211_hw *hw) ...@@ -307,6 +307,7 @@ mt7915_init_wiphy(struct ieee80211_hw *hw)
{ {
struct mt7915_phy *phy = mt7915_hw_phy(hw); struct mt7915_phy *phy = mt7915_hw_phy(hw);
struct wiphy *wiphy = hw->wiphy; struct wiphy *wiphy = hw->wiphy;
struct mt7915_dev *dev = phy->dev;
hw->queues = 4; hw->queues = 4;
hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF; hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
...@@ -349,14 +350,34 @@ mt7915_init_wiphy(struct ieee80211_hw *hw) ...@@ -349,14 +350,34 @@ mt7915_init_wiphy(struct ieee80211_hw *hw)
phy->mt76->sband_5g.sband.ht_cap.cap |= phy->mt76->sband_5g.sband.ht_cap.cap |=
IEEE80211_HT_CAP_LDPC_CODING | IEEE80211_HT_CAP_LDPC_CODING |
IEEE80211_HT_CAP_MAX_AMSDU; IEEE80211_HT_CAP_MAX_AMSDU;
if (is_mt7915(&dev->mt76)) {
phy->mt76->sband_5g.sband.vht_cap.cap |= phy->mt76->sband_5g.sband.vht_cap.cap |=
IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 | IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_7991 |
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
if (!dev->dbdc_support)
phy->mt76->sband_5g.sband.vht_cap.cap |=
IEEE80211_VHT_CAP_SHORT_GI_160 |
IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
} else {
phy->mt76->sband_5g.sband.vht_cap.cap |=
IEEE80211_VHT_CAP_MAX_MPDU_LENGTH_11454 |
IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK;
/* mt7916 dbdc with 2g 2x2 bw40 and 5g 2x2 bw160c */
phy->mt76->sband_5g.sband.vht_cap.cap |=
IEEE80211_VHT_CAP_SHORT_GI_160 |
IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
}
} }
mt76_set_stream_caps(phy->mt76, true); mt76_set_stream_caps(phy->mt76, true);
mt7915_set_stream_vht_txbf_caps(phy); mt7915_set_stream_vht_txbf_caps(phy);
mt7915_set_stream_he_caps(phy); mt7915_set_stream_he_caps(phy);
wiphy->available_antennas_rx = phy->mt76->antenna_mask;
wiphy->available_antennas_tx = phy->mt76->antenna_mask;
} }
static void static void
...@@ -456,18 +477,26 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev) ...@@ -456,18 +477,26 @@ static int mt7915_register_ext_phy(struct mt7915_dev *dev)
phy = mphy->priv; phy = mphy->priv;
phy->dev = dev; phy->dev = dev;
phy->mt76 = mphy; phy->mt76 = mphy;
mphy->chainmask = dev->chainmask & ~dev->mphy.chainmask;
mphy->antenna_mask = BIT(hweight8(mphy->chainmask)) - 1;
INIT_DELAYED_WORK(&mphy->mac_work, mt7915_mac_work); INIT_DELAYED_WORK(&mphy->mac_work, mt7915_mac_work);
mt7915_eeprom_parse_band_config(phy); mt7915_eeprom_parse_hw_cap(dev, phy);
mt7915_init_wiphy(mphy->hw);
memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR2, memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR2,
ETH_ALEN); ETH_ALEN);
/* Make the secondary PHY MAC address local without overlapping with
* the usual MAC address allocation scheme on multiple virtual interfaces
*/
if (!is_valid_ether_addr(mphy->macaddr)) {
memcpy(mphy->macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR,
ETH_ALEN);
mphy->macaddr[0] |= 2;
mphy->macaddr[0] ^= BIT(7);
}
mt76_eeprom_override(mphy); mt76_eeprom_override(mphy);
/* init wiphy according to mphy and phy */
mt7915_init_wiphy(mphy->hw);
ret = mt7915_init_tx_queues(phy, MT_TXQ_ID(1), ret = mt7915_init_tx_queues(phy, MT_TXQ_ID(1),
MT7915_TX_RING_SIZE, MT7915_TX_RING_SIZE,
MT_TXQ_RING_BASE(1)); MT_TXQ_RING_BASE(1));
...@@ -561,7 +590,9 @@ static int mt7915_init_hardware(struct mt7915_dev *dev) ...@@ -561,7 +590,9 @@ static int mt7915_init_hardware(struct mt7915_dev *dev)
mt76_wr(dev, MT_INT_SOURCE_CSR, ~0); mt76_wr(dev, MT_INT_SOURCE_CSR, ~0);
INIT_WORK(&dev->init_work, mt7915_init_work); INIT_WORK(&dev->init_work, mt7915_init_work);
dev->dbdc_support = !!(mt76_rr(dev, MT_HW_BOUND) & BIT(5));
dev->dbdc_support = is_mt7915(&dev->mt76) ?
!!(mt76_rr(dev, MT_HW_BOUND) & BIT(5)) : true;
/* If MCU was already running, it is likely in a bad state */ /* If MCU was already running, it is likely in a bad state */
if (mt76_get_field(dev, MT_TOP_MISC, MT_TOP_MISC_FW_STATE) > if (mt76_get_field(dev, MT_TOP_MISC, MT_TOP_MISC_FW_STATE) >
...@@ -588,7 +619,6 @@ static int mt7915_init_hardware(struct mt7915_dev *dev) ...@@ -588,7 +619,6 @@ static int mt7915_init_hardware(struct mt7915_dev *dev)
if (ret < 0) if (ret < 0)
return ret; return ret;
if (dev->flash_mode) { if (dev->flash_mode) {
ret = mt7915_mcu_apply_group_cal(dev); ret = mt7915_mcu_apply_group_cal(dev);
if (ret) if (ret)
...@@ -935,13 +965,6 @@ int mt7915_register_device(struct mt7915_dev *dev) ...@@ -935,13 +965,6 @@ int mt7915_register_device(struct mt7915_dev *dev)
mt7915_init_wiphy(hw); mt7915_init_wiphy(hw);
if (!dev->dbdc_support)
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;
dev->phy.dfs_state = -1; dev->phy.dfs_state = -1;
#ifdef CONFIG_NL80211_TESTMODE #ifdef CONFIG_NL80211_TESTMODE
......
...@@ -389,7 +389,8 @@ u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif); ...@@ -389,7 +389,8 @@ u64 __mt7915_get_tsf(struct ieee80211_hw *hw, struct mt7915_vif *mvif);
int mt7915_register_device(struct mt7915_dev *dev); int mt7915_register_device(struct mt7915_dev *dev);
void mt7915_unregister_device(struct mt7915_dev *dev); void mt7915_unregister_device(struct mt7915_dev *dev);
int mt7915_eeprom_init(struct mt7915_dev *dev); int mt7915_eeprom_init(struct mt7915_dev *dev);
void mt7915_eeprom_parse_band_config(struct mt7915_phy *phy); void mt7915_eeprom_parse_hw_cap(struct mt7915_dev *dev,
struct mt7915_phy *phy);
int mt7915_eeprom_get_target_power(struct mt7915_dev *dev, int mt7915_eeprom_get_target_power(struct mt7915_dev *dev,
struct ieee80211_channel *chan, struct ieee80211_channel *chan,
u8 chain_idx); u8 chain_idx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment