developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 1 | From 55f4ab5ef60b32bb44395dc818b0dbc55fb7d81a 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 | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 104/199] 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 +++++-- |
| 15 | mt7996/main.c | 41 ++++++++++++++++++++++++++++++----------- |
| 16 | 4 files changed, 55 insertions(+), 14 deletions(-) |
| 17 | |
| 18 | diff --git a/mac80211.c b/mac80211.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 19 | index 49834afe..bf7ead01 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 | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 48 | @@ -1073,7 +1082,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 | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 58 | index 6a7752ef..f037284a 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 59 | --- a/mt76.h |
| 60 | +++ b/mt76.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 61 | @@ -829,6 +829,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 | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 69 | @@ -1308,6 +1309,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 | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 86 | index 6d0506fc..c0c0df2f 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 87 | --- a/mt7996/mac.c |
| 88 | +++ b/mt7996/mac.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 89 | @@ -2382,7 +2382,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 | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 101 | @@ -2801,7 +2804,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 | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 111 | index 1ea81d62..331dd4d4 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 112 | --- a/mt7996/main.c |
| 113 | +++ b/mt7996/main.c |
| 114 | @@ -173,6 +173,7 @@ static void mt7996_stop(struct ieee80211_hw *hw) |
| 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 | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 122 | @@ -545,9 +546,10 @@ out: |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 123 | clear_bit(MT76_RESET, &phy->mt76->state); |
| 124 | mutex_unlock(&dev->mt76.mutex); |
| 125 | |
| 126 | - mt76_txq_schedule_all(phy->mt76); |
| 127 | + if (phy->mt76 == phy->mt76->main_phy) |
| 128 | + mt76_txq_schedule_all(phy->mt76); |
| 129 | |
| 130 | - ieee80211_queue_delayed_work(phy->mt76->hw, |
| 131 | + ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76), |
| 132 | &phy->mt76->mac_work, |
| 133 | MT7996_WATCHDOG_TIME); |
| 134 | |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 135 | @@ -558,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] | 136 | { |
| 137 | int ret; |
| 138 | |
| 139 | - ieee80211_stop_queues(phy->mt76->hw); |
| 140 | + ieee80211_stop_queues(mt76_main_hw(phy->mt76)); |
| 141 | ret = __mt7996_set_channel(phy, chandef); |
| 142 | if (ret) |
| 143 | return ret; |
| 144 | - ieee80211_wake_queues(phy->mt76->hw); |
| 145 | + ieee80211_wake_queues(mt76_main_hw(phy->mt76)); |
| 146 | |
| 147 | return 0; |
| 148 | } |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 149 | @@ -735,6 +737,7 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 150 | MT_WF_RFCR1_DROP_CFEND | |
| 151 | MT_WF_RFCR1_DROP_CFACK; |
| 152 | u32 flags = 0; |
| 153 | + u8 band; |
| 154 | |
| 155 | #define MT76_FILTER(_flag, _hw) do { \ |
| 156 | flags |= *total_flags & FIF_##_flag; \ |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 157 | @@ -768,12 +771,26 @@ static void mt7996_configure_filter(struct ieee80211_hw *hw, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 158 | MT_WF_RFCR_DROP_NDPA); |
| 159 | |
| 160 | *total_flags = flags; |
| 161 | - mt76_wr(dev, MT_WF_RFCR(phy->mt76->band_idx), phy->rxfilter); |
| 162 | |
| 163 | - if (*total_flags & FIF_CONTROL) |
| 164 | - mt76_clear(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); |
| 165 | - else |
| 166 | - mt76_set(dev, MT_WF_RFCR1(phy->mt76->band_idx), ctl_flags); |
| 167 | + /* configure rx filter to all affliated phy */ |
| 168 | + for (band = 0; band < __MT_MAX_BAND; band++) { |
| 169 | + struct mt7996_phy *tmp; |
| 170 | + |
| 171 | + if (!hw->wiphy->bands[band]) |
| 172 | + continue; |
| 173 | + |
| 174 | + tmp = dev->mt76.phys[band]->priv; |
| 175 | + if (tmp->mt76->main_phy != phy->mt76) |
| 176 | + continue; |
| 177 | + |
| 178 | + tmp->rxfilter = phy->rxfilter; |
| 179 | + mt76_wr(dev, MT_WF_RFCR(tmp->mt76->band_idx), phy->rxfilter); |
| 180 | + |
| 181 | + if (*total_flags & FIF_CONTROL) |
| 182 | + mt76_clear(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags); |
| 183 | + else |
| 184 | + mt76_set(dev, MT_WF_RFCR1(tmp->mt76->band_idx), ctl_flags); |
| 185 | + } |
| 186 | |
| 187 | mutex_unlock(&dev->mt76.mutex); |
| 188 | } |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 189 | @@ -2190,7 +2207,7 @@ mt7996_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 190 | phy->scan_chan_idx = 0; |
| 191 | mutex_unlock(&phy->dev->mt76.mutex); |
| 192 | |
| 193 | - ieee80211_queue_delayed_work(hw, &phy->scan_work, 0); |
| 194 | + ieee80211_queue_delayed_work(mt76_main_hw(phy->mt76), &phy->scan_work, 0); |
| 195 | |
| 196 | return 0; |
| 197 | } |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 198 | @@ -2207,7 +2224,8 @@ mt7996_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 199 | continue; |
| 200 | |
| 201 | phy = mt7996_band_phy(hw, band); |
| 202 | - if (!(test_bit(MT76_SCANNING, &phy->mt76->state))) |
| 203 | + if (!(test_bit(MT76_SCANNING, &phy->mt76->state) && |
| 204 | + phy->mt76->main_phy == hw->priv)) |
| 205 | continue; |
| 206 | |
| 207 | cancel_delayed_work_sync(&phy->scan_work); |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame^] | 208 | @@ -2228,6 +2246,7 @@ mt7996_add_chanctx(struct ieee80211_hw *hw, struct ieee80211_chanctx_conf *conf) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 209 | wiphy_info(hw->wiphy, "%s: add %u\n", __func__, conf->def.chan->hw_value); |
| 210 | mutex_lock(&phy->dev->mt76.mutex); |
| 211 | |
| 212 | + phy->mt76->main_phy = hw->priv; |
| 213 | if (ctx->assigned) { |
| 214 | mutex_unlock(&phy->dev->mt76.mutex); |
| 215 | return -ENOSPC; |
| 216 | -- |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 217 | 2.18.0 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 218 | |