| From 4a201eaadf0009c0ee7e4fc2c35e398e1558892b Mon Sep 17 00:00:00 2001 |
| From: Shayne Chen <shayne.chen@mediatek.com> |
| Date: Fri, 1 Dec 2023 16:01:53 +0800 |
| Subject: [PATCH 107/120] wifi: mt76: mt7996: introduce mt7996_band_phy() for |
| ch band and phy mapping |
| |
| For MLO devices, one ieee80211_hw can be mapped to several bands, and |
| thus several mt76_phy. Add mt7996_band_phy() to temporarily do the |
| mapping. |
| This is a preliminary patch to add MLO support for mt7996 chipsets. |
| |
| Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> |
| --- |
| mt7996/main.c | 150 +++++++++++++++++++++++++++++------------------- |
| mt7996/mt7996.h | 22 +++++++ |
| 2 files changed, 113 insertions(+), 59 deletions(-) |
| |
| diff --git a/mt7996/main.c b/mt7996/main.c |
| index a0c34aa88..49406dba5 100644 |
| --- a/mt7996/main.c |
| +++ b/mt7996/main.c |
| @@ -41,9 +41,8 @@ static void mt7996_testmode_disable_all(struct mt7996_dev *dev) |
| int mt7996_run(struct ieee80211_hw *hw) |
| { |
| struct mt7996_dev *dev = mt7996_hw_dev(hw); |
| - struct mt7996_phy *phy = mt7996_hw_phy(hw); |
| bool running; |
| - int ret; |
| + int band, ret; |
| |
| running = mt7996_dev_running(dev); |
| if (!running) { |
| @@ -62,65 +61,76 @@ int mt7996_run(struct ieee80211_hw *hw) |
| |
| mt7996_testmode_disable_all(dev); |
| |
| - mt7996_mac_enable_nf(dev, phy->mt76->band_idx); |
| + for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| + struct mt7996_phy *phy; |
| |
| - ret = mt7996_mcu_set_rts_thresh(phy, 0x92b); |
| - if (ret) |
| - goto out; |
| + if (!hw->wiphy->bands[band]) |
| + continue; |
| |
| - ret = mt7996_mcu_set_radio_en(phy, true); |
| - if (ret) |
| - goto out; |
| + phy = mt7996_band_phy(hw, band); |
| |
| - ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH); |
| - if (ret) |
| - goto out; |
| + if (!phy || test_bit(MT76_STATE_RUNNING, &phy->mt76->state)) |
| + continue; |
| |
| - /* set a parking channel */ |
| - ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_SWITCH); |
| - if (ret) |
| - goto out; |
| + mt7996_mac_enable_nf(dev, phy->mt76->band_idx); |
| |
| - ret = mt7996_mcu_set_thermal_throttling(phy, MT7996_THERMAL_THROTTLE_MAX); |
| - if (ret) |
| - goto out; |
| + ret = mt7996_mcu_set_rts_thresh(phy, 0x92b); |
| + if (ret) |
| + goto out; |
| |
| - ret = mt7996_mcu_set_thermal_protect(phy, true); |
| - if (ret) |
| - goto out; |
| + ret = mt7996_mcu_set_radio_en(phy, true); |
| + if (ret) |
| + goto out; |
| |
| - ret = mt7996_mcu_set_scs(phy, SCS_ENABLE); |
| - if (ret) |
| - goto out; |
| + ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_RX_PATH); |
| + if (ret) |
| + goto out; |
| + |
| + /* set a parking channel */ |
| + ret = mt7996_mcu_set_chan_info(phy, UNI_CHANNEL_SWITCH); |
| + if (ret) |
| + goto out; |
| + |
| + ret = mt7996_mcu_set_thermal_throttling(phy, MT7996_THERMAL_THROTTLE_MAX); |
| + if (ret) |
| + goto out; |
| + |
| + ret = mt7996_mcu_set_thermal_protect(phy, true); |
| + if (ret) |
| + goto out; |
| + |
| + ret = mt7996_mcu_set_scs(phy, SCS_ENABLE); |
| + if (ret) |
| + goto out; |
| |
| #ifdef CONFIG_MTK_DEBUG |
| - phy->sr_enable = true; |
| - phy->enhanced_sr_enable = true; |
| - phy->thermal_protection_enable = true; |
| - ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL, |
| - dev->dbg.sku_disable ? 0 : phy->sku_limit_en); |
| - |
| - ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_BACKOFF_POWER_LIMIT_CTRL, |
| - dev->dbg.sku_disable ? 0 : phy->sku_path_en); |
| + phy->sr_enable = true; |
| + phy->enhanced_sr_enable = true; |
| + phy->thermal_protection_enable = true; |
| + ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL, |
| + dev->dbg.sku_disable ? 0 : phy->sku_limit_en); |
| + |
| + ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_BACKOFF_POWER_LIMIT_CTRL, |
| + dev->dbg.sku_disable ? 0 : phy->sku_path_en); |
| #else |
| - ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL, |
| - phy->sku_limit_en); |
| - ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_BACKOFF_POWER_LIMIT_CTRL, |
| - phy->sku_path_en); |
| + ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL, |
| + phy->sku_limit_en); |
| + ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_BACKOFF_POWER_LIMIT_CTRL, |
| + phy->sku_path_en); |
| #endif |
| - if (ret) |
| - goto out; |
| - |
| - set_bit(MT76_STATE_RUNNING, &phy->mt76->state); |
| + if (ret) |
| + goto out; |
| |
| - ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, |
| - MT7996_WATCHDOG_TIME); |
| + set_bit(MT76_STATE_RUNNING, &phy->mt76->state); |
| |
| - ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ); |
| + ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work, |
| + MT7996_WATCHDOG_TIME); |
| |
| - if (!running) |
| - mt7996_mac_reset_counters(phy); |
| + if (!running) |
| + mt7996_mac_reset_counters(phy); |
| + } |
| |
| + ieee80211_queue_delayed_work(mt76_hw(dev), &dev->scs_work, HZ); |
| out: |
| return ret; |
| } |
| @@ -142,18 +152,29 @@ static int mt7996_start(struct ieee80211_hw *hw) |
| static void mt7996_stop(struct ieee80211_hw *hw) |
| { |
| struct mt7996_dev *dev = mt7996_hw_dev(hw); |
| - struct mt7996_phy *phy = mt7996_hw_phy(hw); |
| + int band; |
| |
| - cancel_delayed_work_sync(&phy->mt76->mac_work); |
| cancel_delayed_work_sync(&dev->scs_work); |
| |
| - mutex_lock(&dev->mt76.mutex); |
| + for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| + struct mt7996_phy *phy; |
| |
| - mt7996_mcu_set_radio_en(phy, false); |
| + if (!hw->wiphy->bands[band]) |
| + continue; |
| |
| - clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); |
| + phy = mt7996_band_phy(hw, band); |
| |
| - mutex_unlock(&dev->mt76.mutex); |
| + if (!phy || !test_bit(MT76_STATE_RUNNING, &phy->mt76->state) || |
| + (phy->chanctx && phy->chanctx->nbss_assigned)) |
| + continue; |
| + |
| + cancel_delayed_work_sync(&phy->mt76->mac_work); |
| + |
| + mutex_lock(&dev->mt76.mutex); |
| + mt7996_mcu_set_radio_en(phy, false); |
| + clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); |
| + mutex_unlock(&dev->mt76.mutex); |
| + } |
| } |
| |
| static inline int get_free_idx(u32 mask, u8 start, u8 end) |
| @@ -2054,7 +2075,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| struct ieee80211_scan_request *hw_req) |
| { |
| struct cfg80211_scan_request *req = &hw_req->req; |
| - struct mt7996_phy *phy = mt7996_hw_phy(hw); |
| + struct mt7996_phy *phy = mt7996_band_phy(hw, req->channels[0]->band); |
| |
| mutex_lock(&phy->dev->mt76.mutex); |
| if (WARN_ON(phy->scan_req || phy->scan_chan)) { |
| @@ -2076,19 +2097,30 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
| static void |
| mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
| { |
| - struct mt7996_phy *phy = mt7996_hw_phy(hw); |
| + int band; |
| |
| - cancel_delayed_work_sync(&phy->scan_work); |
| + for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| + struct mt7996_phy *phy; |
| |
| - mutex_lock(&phy->dev->mt76.mutex); |
| - mt7996_scan_complete(phy, true); |
| - mutex_unlock(&phy->dev->mt76.mutex); |
| + if (!hw->wiphy->bands[band]) |
| + continue; |
| + |
| + phy = mt7996_band_phy(hw, band); |
| + if (!(test_bit(MT76_SCANNING, &phy->mt76->state))) |
| + continue; |
| + |
| + cancel_delayed_work_sync(&phy->scan_work); |
| + |
| + mutex_lock(&phy->dev->mt76.mutex); |
| + mt7996_scan_complete(phy, true); |
| + mutex_unlock(&phy->dev->mt76.mutex); |
| + } |
| } |
| |
| static int |
| mt7996_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf) |
| { |
| - struct mt7996_phy *phy = mt7996_hw_phy(hw); |
| + struct mt7996_phy *phy = mt7996_band_phy(hw, conf->def.chan->band); |
| struct mt7996_chanctx *ctx = mt7996_chanctx_get(conf); |
| int ret; |
| |
| diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
| index 69e7f64a5..2932ab8d5 100644 |
| --- a/mt7996/mt7996.h |
| +++ b/mt7996/mt7996.h |
| @@ -784,6 +784,28 @@ mt7996_get_background_radar_cap(struct mt7996_dev *dev) |
| return 1; |
| } |
| |
| +static inline struct mt7996_phy * |
| +mt7996_band_phy(struct ieee80211_hw *hw, enum nl80211_band band) |
| +{ |
| + struct mt76_phy *phy = hw->priv; |
| + |
| + if (!(hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO)) |
| + return phy->priv; |
| + |
| + /* TODO: mlo: temporarily hardcode */ |
| + if (band == NL80211_BAND_6GHZ) |
| + phy = phy->dev->phys[MT_BAND2]; |
| + else if (band == NL80211_BAND_5GHZ) |
| + phy = phy->dev->phys[MT_BAND1]; |
| + else |
| + phy = phy->dev->phys[MT_BAND0]; |
| + |
| + if (!phy) |
| + phy = hw->priv; |
| + |
| + return phy->priv; |
| +} |
| + |
| static inline struct mt7996_chanctx * |
| mt7996_chanctx_get(struct ieee80211_chanctx_conf *ctx) |
| { |
| -- |
| 2.39.2 |
| |