developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 1 | From eb1ff9f088a5f55389f499e53b63b5f183025a61 Mon Sep 17 00:00:00 2001 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 2 | From: Shayne Chen <shayne.chen@mediatek.com> |
| 3 | Date: Tue, 5 Dec 2023 13:56:51 +0800 |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 092/223] mtk: mt76: mt7996: handle mapping for hw and phy |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 5 | |
| 6 | We've used mt7996_band_phy() to do mapping from ieee80211_hw to mt7996_phy, |
| 7 | and this patch is a temporal workaround for opposite direction. |
| 8 | This is a preliminary patch to add MLO support for mt7996 chipsets. |
| 9 | |
| 10 | Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> |
| 11 | --- |
| 12 | mac80211.c | 11 ++++++++++- |
| 13 | mt76.h | 10 ++++++++++ |
| 14 | mt7996/mac.c | 7 +++++-- |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 15 | mt7996/main.c | 45 +++++++++++++++++++++++++++++++++++---------- |
| 16 | 4 files changed, 60 insertions(+), 13 deletions(-) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 17 | |
| 18 | diff --git a/mac80211.c b/mac80211.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 19 | index ec73fe00..03632279 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 20 | --- a/mac80211.c |
| 21 | +++ b/mac80211.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 22 | @@ -823,9 +823,13 @@ EXPORT_SYMBOL_GPL(mt76_has_tx_pending); |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 23 | struct mt76_channel_state * |
| 24 | mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c) |
| 25 | { |
| 26 | + struct mt76_phy *ori_phy = phy; |
| 27 | struct mt76_sband *msband; |
| 28 | int idx; |
| 29 | |
| 30 | + if (phy->main_phy) |
| 31 | + phy = phy->main_phy; |
| 32 | +begin: |
| 33 | if (c->band == NL80211_BAND_2GHZ) |
| 34 | msband = &phy->sband_2g; |
| 35 | else if (c->band == NL80211_BAND_6GHZ) |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 36 | @@ -834,6 +838,11 @@ mt76_channel_state(struct mt76_phy *phy, struct ieee80211_channel *c) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 37 | msband = &phy->sband_5g; |
| 38 | |
| 39 | idx = c - &msband->sband.channels[0]; |
| 40 | + /* TODO: mlo: this is a temp solution, need to come up with a more clever one */ |
| 41 | + if (idx < 0 || idx >= msband->sband.n_channels) { |
| 42 | + phy = ori_phy; |
| 43 | + goto begin; |
| 44 | + } |
| 45 | return &msband->chan[idx]; |
| 46 | } |
| 47 | EXPORT_SYMBOL_GPL(mt76_channel_state); |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 48 | @@ -1098,7 +1107,7 @@ mt76_rx_convert(struct mt76_dev *dev, struct sk_buff *skb, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | *sta = wcid_to_sta(mstat.wcid); |
| 52 | - *hw = mt76_phy_hw(dev, mstat.phy_idx); |
| 53 | + *hw = mt76_main_hw(dev->phys[mstat.phy_idx]); |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 54 | } |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 55 | |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 56 | static void |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 57 | diff --git a/mt76.h b/mt76.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 58 | index 36e92dfe..9fa411cb 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 59 | --- a/mt76.h |
| 60 | +++ b/mt76.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 61 | @@ -843,6 +843,7 @@ struct mt76_vif { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 62 | struct mt76_phy { |
| 63 | struct ieee80211_hw *hw; |
| 64 | struct mt76_dev *dev; |
| 65 | + struct mt76_phy *main_phy; |
| 66 | void *priv; |
| 67 | |
| 68 | unsigned long state; |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 69 | @@ -1321,6 +1322,15 @@ mt76_phy_hw(struct mt76_dev *dev, u8 phy_idx) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 70 | return mt76_dev_phy(dev, phy_idx)->hw; |
| 71 | } |
| 72 | |
| 73 | +static inline struct ieee80211_hw * |
| 74 | +mt76_main_hw(struct mt76_phy *phy) |
| 75 | +{ |
| 76 | + if (phy->main_phy) |
| 77 | + return mt76_dev_phy(phy->dev, phy->main_phy->band_idx)->hw; |
| 78 | + |
| 79 | + return mt76_dev_phy(phy->dev, phy->band_idx)->hw; |
| 80 | +} |
| 81 | + |
| 82 | static inline u8 * |
| 83 | mt76_get_txwi_ptr(struct mt76_dev *dev, struct mt76_txwi_cache *t) |
| 84 | { |
| 85 | diff --git a/mt7996/mac.c b/mt7996/mac.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 86 | index c4cd5bc2..f9aa0e57 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 87 | --- a/mt7996/mac.c |
| 88 | +++ b/mt7996/mac.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 89 | @@ -2394,7 +2394,10 @@ void mt7996_mac_work(struct work_struct *work) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 90 | |
| 91 | mt76_tx_status_check(mdev, false); |
| 92 | |
| 93 | - ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work, |
| 94 | + if (mphy->main_phy && !test_bit(MT76_STATE_RUNNING, &mphy->main_phy->state)) |
| 95 | + return; |
| 96 | + |
| 97 | + ieee80211_queue_delayed_work(mt76_main_hw(mphy), &mphy->mac_work, |
| 98 | MT7996_WATCHDOG_TIME); |
| 99 | } |
| 100 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 101 | @@ -2813,7 +2816,7 @@ mt7996_scan_send_probe(struct mt7996_phy *phy, struct cfg80211_ssid *ssid, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 102 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
| 103 | |
| 104 | rcu_read_lock(); |
| 105 | - if (!ieee80211_tx_prepare_skb(hw, vif, skb, |
| 106 | + if (!ieee80211_tx_prepare_skb(mt76_main_hw(phy->mt76), vif, skb, |
| 107 | phy->scan_chan->band, |
| 108 | NULL)) { |
| 109 | rcu_read_unlock(); |
| 110 | diff --git a/mt7996/main.c b/mt7996/main.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 111 | index 68234032..01c736a9 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 112 | --- a/mt7996/main.c |
| 113 | +++ b/mt7996/main.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 114 | @@ -173,6 +173,7 @@ static void mt7996_stop(struct ieee80211_hw *hw, bool suspend) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 115 | mutex_lock(&dev->mt76.mutex); |
| 116 | mt7996_mcu_set_radio_en(phy, false); |
| 117 | clear_bit(MT76_STATE_RUNNING, &phy->mt76->state); |
| 118 | + phy->mt76->main_phy = NULL; |
| 119 | mutex_unlock(&dev->mt76.mutex); |
| 120 | } |
| 121 | } |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 122 | @@ -542,7 +543,14 @@ static int __mt7996_set_channel(struct mt7996_phy *phy, |
| 123 | phy->noise = 0; |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 124 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 125 | out: |
| 126 | - ieee80211_queue_delayed_work(mphy->hw, &mphy->mac_work, |
| 127 | + clear_bit(MT76_RESET, &phy->mt76->state); |
| 128 | + mutex_unlock(&dev->mt76.mutex); |
| 129 | + |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 130 | + if (phy->mt76 == phy->mt76->main_phy) |
| 131 | + mt76_txq_schedule_all(phy->mt76); |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 132 | + |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 133 | + ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76), |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 134 | + &phy->mt76->mac_work, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 135 | MT7996_WATCHDOG_TIME); |
| 136 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 137 | return ret; |
| 138 | @@ -552,11 +560,11 @@ int mt7996_set_channel(struct mt7996_phy *phy, struct cfg80211_chan_def *chandef |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 139 | { |
| 140 | int ret; |
| 141 | |
| 142 | - ieee80211_stop_queues(phy->mt76->hw); |
| 143 | + ieee80211_stop_queues(mt76_main_hw(phy->mt76)); |
| 144 | ret = __mt7996_set_channel(phy, chandef); |
| 145 | if (ret) |
| 146 | return ret; |
| 147 | - ieee80211_wake_queues(phy->mt76->hw); |
| 148 | + ieee80211_wake_queues(mt76_main_hw(phy->mt76)); |
| 149 | |
| 150 | return 0; |
| 151 | } |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 152 | @@ -729,6 +737,7 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 153 | MT_WF_RFCR1_DROP_CFEND | |
| 154 | MT_WF_RFCR1_DROP_CFACK; |
| 155 | u32 flags = 0; |
| 156 | + u8 band; |
| 157 | |
| 158 | #define MT76_FILTER(_flag, _hw) do { \ |
| 159 | flags |= *total_flags & FIF_##_flag; \ |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 160 | @@ -762,12 +771,26 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 161 | MT_WF_RFCR_DROP_NDPA); |
| 162 | |
| 163 | *total_flags = flags; |
| 164 | - mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter); |
| 165 | |
| 166 | - if (*total_flags & FIF_CONTROL) |
| 167 | - mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); |
| 168 | - else |
| 169 | - mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); |
| 170 | + /* configure rx filter to all affliated phy */ |
| 171 | + for (band = 0; band < __MT_MAX_BAND; band++) { |
| 172 | + struct mt7996_phy *tmp; |
| 173 | + |
| 174 | + if (!hw->wiphy->bands[band]) |
| 175 | + continue; |
| 176 | + |
| 177 | + tmp = dev->mt76.phys[band]->priv; |
| 178 | + if (tmp->mt76->main_phy != phy->mt76) |
| 179 | + continue; |
| 180 | + |
| 181 | + tmp->rxfilter = phy->rxfilter; |
| 182 | + mt76_wr(dev, MT_WF_RFCR(tmp->mt76->band_idx), phy->rxfilter); |
| 183 | + |
| 184 | + if (*total_flags & FIF_CONTROL) |
| 185 | + mt76_clear(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags); |
| 186 | + else |
| 187 | + mt76_set(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags); |
| 188 | + } |
| 189 | |
| 190 | mutex_unlock(&dev->mt76.mutex); |
| 191 | } |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 192 | @@ -2188,7 +2211,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 193 | phy->scan_chan_idx = 0; |
| 194 | mutex_unlock(&phy->dev->mt76.mutex); |
| 195 | |
| 196 | - ieee80211_queue_delayed_work(hw, &phy->scan_work, 0); |
| 197 | + ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76), &phy->scan_work, 0); |
| 198 | |
| 199 | return 0; |
| 200 | } |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 201 | @@ -2205,7 +2228,8 @@ mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 202 | continue; |
| 203 | |
| 204 | phy = mt7996_band_phy(hw, band); |
| 205 | - if (!(test_bit(MT76_SCANNING, &phy->mt76->state))) |
| 206 | + if (!(test_bit(MT76_SCANNING, &phy->mt76->state) && |
| 207 | + phy->mt76->main_phy == hw->priv)) |
| 208 | continue; |
| 209 | |
| 210 | cancel_delayed_work_sync(&phy->scan_work); |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 211 | @@ -2226,6 +2250,7 @@ mt7996_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 212 | wiphy_info(hw->wiphy, "%s: add %u\n", __func__, conf->def.chan->hw_value); |
| 213 | mutex_lock(&phy->dev->mt76.mutex); |
| 214 | |
| 215 | + phy->mt76->main_phy = hw->priv; |
| 216 | if (ctx->assigned) { |
| 217 | mutex_unlock(&phy->dev->mt76.mutex); |
| 218 | return -ENOSPC; |
| 219 | -- |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 220 | 2.45.2 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 221 | |