Skip to content

Commit

Permalink
wifi: mt76: change txpower init to per-phy
Browse files Browse the repository at this point in the history
Use per-phy structure for maximum txpower value initializing, since each
phy may have a different chainmask, which can impact the calculation of
power gain.

Co-developed-by: Allen Ye <allen.ye@mediatek.com>
Signed-off-by: Allen Ye <allen.ye@mediatek.com>
Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
Signed-off-by: Felix Fietkau <nbd@nbd.name>
  • Loading branch information
Shayne Chen authored and Felix Fietkau committed Dec 7, 2023
1 parent 1e3f387 commit 11a60bd
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 29 deletions.
30 changes: 20 additions & 10 deletions drivers/net/wireless/mediatek/mt76/mt7915/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ static void mt7915_led_set_brightness(struct led_classdev *led_cdev,
mt7915_led_set_config(led_cdev, 0xff, 0);
}

void mt7915_init_txpower(struct mt7915_dev *dev,
struct ieee80211_supported_band *sband)
static void __mt7915_init_txpower(struct mt7915_phy *phy,
struct ieee80211_supported_band *sband)
{
int i, n_chains = hweight8(dev->mphy.antenna_mask);
struct mt7915_dev *dev = phy->dev;
int i, n_chains = hweight16(phy->mt76->chainmask);
int nss_delta = mt76_tx_power_nss_delta(n_chains);
int pwr_delta = mt7915_eeprom_get_power_delta(dev, sband->band);
struct mt76_power_limits limits;
Expand All @@ -296,7 +297,7 @@ void mt7915_init_txpower(struct mt7915_dev *dev,
}

target_power += pwr_delta;
target_power = mt76_get_rate_power_limits(&dev->mphy, chan,
target_power = mt76_get_rate_power_limits(phy->mt76, chan,
&limits,
target_power);
target_power += nss_delta;
Expand All @@ -307,6 +308,19 @@ void mt7915_init_txpower(struct mt7915_dev *dev,
}
}

void mt7915_init_txpower(struct mt7915_phy *phy)
{
if (!phy)
return;

if (phy->mt76->cap.has_2ghz)
__mt7915_init_txpower(phy, &phy->mt76->sband_2g.sband);
if (phy->mt76->cap.has_5ghz)
__mt7915_init_txpower(phy, &phy->mt76->sband_5g.sband);
if (phy->mt76->cap.has_6ghz)
__mt7915_init_txpower(phy, &phy->mt76->sband_6g.sband);
}

static void
mt7915_regd_notifier(struct wiphy *wiphy,
struct regulatory_request *request)
Expand All @@ -322,9 +336,7 @@ mt7915_regd_notifier(struct wiphy *wiphy,
if (dev->mt76.region == NL80211_DFS_UNSET)
mt7915_mcu_rdd_background_enable(phy, NULL);

mt7915_init_txpower(dev, &mphy->sband_2g.sband);
mt7915_init_txpower(dev, &mphy->sband_5g.sband);
mt7915_init_txpower(dev, &mphy->sband_6g.sband);
mt7915_init_txpower(phy);

mphy->dfs_state = MT_DFS_STATE_UNKNOWN;
mt7915_dfs_init_radar_detector(phy);
Expand Down Expand Up @@ -442,6 +454,7 @@ mt7915_init_wiphy(struct mt7915_phy *phy)
mt76_set_stream_caps(phy->mt76, true);
mt7915_set_stream_vht_txbf_caps(phy);
mt7915_set_stream_he_caps(phy);
mt7915_init_txpower(phy);

wiphy->available_antennas_rx = phy->mt76->antenna_mask;
wiphy->available_antennas_tx = phy->mt76->antenna_mask;
Expand Down Expand Up @@ -703,9 +716,6 @@ static void mt7915_init_work(struct work_struct *work)

mt7915_mcu_set_eeprom(dev);
mt7915_mac_init(dev);
mt7915_init_txpower(dev, &dev->mphy.sband_2g.sband);
mt7915_init_txpower(dev, &dev->mphy.sband_5g.sband);
mt7915_init_txpower(dev, &dev->mphy.sband_6g.sband);
mt7915_txbf_init(dev);
}

Expand Down
4 changes: 2 additions & 2 deletions drivers/net/wireless/mediatek/mt76/mt7915/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1401,8 +1401,8 @@ mt7915_mac_restart(struct mt7915_dev *dev)
goto out;

mt7915_mac_init(dev);
mt7915_init_txpower(dev, &dev->mphy.sband_2g.sband);
mt7915_init_txpower(dev, &dev->mphy.sband_5g.sband);
mt7915_init_txpower(&dev->phy);
mt7915_init_txpower(phy2);
ret = mt7915_txbf_init(dev);

if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/wireless/mediatek/mt76/mt7915/mt7915.h
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,7 @@ void mt7915_dma_cleanup(struct mt7915_dev *dev);
int mt7915_dma_reset(struct mt7915_dev *dev, bool force);
int mt7915_dma_start(struct mt7915_dev *dev, bool reset, bool wed_reset);
int mt7915_txbf_init(struct mt7915_dev *dev);
void mt7915_init_txpower(struct mt7915_dev *dev,
struct ieee80211_supported_band *sband);
void mt7915_init_txpower(struct mt7915_phy *phy);
void mt7915_reset(struct mt7915_dev *dev);
int mt7915_run(struct ieee80211_hw *hw);
int mt7915_mcu_init(struct mt7915_dev *dev);
Expand Down
30 changes: 20 additions & 10 deletions drivers/net/wireless/mediatek/mt76/mt7996/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,11 @@ static void mt7996_led_set_brightness(struct led_classdev *led_cdev,
mt7996_led_set_config(led_cdev, 0xff, 0);
}

void mt7996_init_txpower(struct mt7996_dev *dev,
struct ieee80211_supported_band *sband)
static void __mt7996_init_txpower(struct mt7996_phy *phy,
struct ieee80211_supported_band *sband)
{
int i, nss = hweight8(dev->mphy.antenna_mask);
struct mt7996_dev *dev = phy->dev;
int i, nss = hweight16(phy->mt76->chainmask);
int nss_delta = mt76_tx_power_nss_delta(nss);
int pwr_delta = mt7996_eeprom_get_power_delta(dev, sband->band);
struct mt76_power_limits limits;
Expand All @@ -301,7 +302,7 @@ void mt7996_init_txpower(struct mt7996_dev *dev,
int target_power = mt7996_eeprom_get_target_power(dev, chan);

target_power += pwr_delta;
target_power = mt76_get_rate_power_limits(&dev->mphy, chan,
target_power = mt76_get_rate_power_limits(phy->mt76, chan,
&limits,
target_power);
target_power += nss_delta;
Expand All @@ -312,6 +313,19 @@ void mt7996_init_txpower(struct mt7996_dev *dev,
}
}

void mt7996_init_txpower(struct mt7996_phy *phy)
{
if (!phy)
return;

if (phy->mt76->cap.has_2ghz)
__mt7996_init_txpower(phy, &phy->mt76->sband_2g.sband);
if (phy->mt76->cap.has_5ghz)
__mt7996_init_txpower(phy, &phy->mt76->sband_5g.sband);
if (phy->mt76->cap.has_6ghz)
__mt7996_init_txpower(phy, &phy->mt76->sband_6g.sband);
}

static void
mt7996_regd_notifier(struct wiphy *wiphy,
struct regulatory_request *request)
Expand All @@ -326,9 +340,7 @@ mt7996_regd_notifier(struct wiphy *wiphy,
if (dev->mt76.region == NL80211_DFS_UNSET)
mt7996_mcu_rdd_background_enable(phy, NULL);

mt7996_init_txpower(dev, &phy->mt76->sband_2g.sband);
mt7996_init_txpower(dev, &phy->mt76->sband_5g.sband);
mt7996_init_txpower(dev, &phy->mt76->sband_6g.sband);
mt7996_init_txpower(phy);

phy->mt76->dfs_state = MT_DFS_STATE_UNKNOWN;
mt7996_dfs_init_radar_detector(phy);
Expand Down Expand Up @@ -424,6 +436,7 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
mt76_set_stream_caps(phy->mt76, true);
mt7996_set_stream_vht_txbf_caps(phy);
mt7996_set_stream_he_eht_caps(phy);
mt7996_init_txpower(phy);

wiphy->available_antennas_rx = phy->mt76->antenna_mask;
wiphy->available_antennas_tx = phy->mt76->antenna_mask;
Expand Down Expand Up @@ -656,9 +669,6 @@ static void mt7996_init_work(struct work_struct *work)

mt7996_mcu_set_eeprom(dev);
mt7996_mac_init(dev);
mt7996_init_txpower(dev, &dev->mphy.sband_2g.sband);
mt7996_init_txpower(dev, &dev->mphy.sband_5g.sband);
mt7996_init_txpower(dev, &dev->mphy.sband_6g.sband);
mt7996_txbf_init(dev);
}

Expand Down
6 changes: 3 additions & 3 deletions drivers/net/wireless/mediatek/mt76/mt7996/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1755,9 +1755,9 @@ mt7996_mac_restart(struct mt7996_dev *dev)
goto out;

mt7996_mac_init(dev);
mt7996_init_txpower(dev, &dev->mphy.sband_2g.sband);
mt7996_init_txpower(dev, &dev->mphy.sband_5g.sband);
mt7996_init_txpower(dev, &dev->mphy.sband_6g.sband);
mt7996_init_txpower(&dev->phy);
mt7996_init_txpower(phy2);
mt7996_init_txpower(phy3);
ret = mt7996_txbf_init(dev);

if (test_bit(MT76_STATE_RUNNING, &dev->mphy.state)) {
Expand Down
3 changes: 1 addition & 2 deletions drivers/net/wireless/mediatek/mt76/mt7996/mt7996.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,7 @@ void mt7996_dma_cleanup(struct mt7996_dev *dev);
void mt7996_dma_start(struct mt7996_dev *dev, bool reset, bool wed_reset);
int mt7996_init_tx_queues(struct mt7996_phy *phy, int idx,
int n_desc, int ring_base, struct mtk_wed_device *wed);
void mt7996_init_txpower(struct mt7996_dev *dev,
struct ieee80211_supported_band *sband);
void mt7996_init_txpower(struct mt7996_phy *phy);
int mt7996_txbf_init(struct mt7996_dev *dev);
void mt7996_reset(struct mt7996_dev *dev);
int mt7996_run(struct ieee80211_hw *hw);
Expand Down

0 comments on commit 11a60bd

Please sign in to comment.