blob: f4a098ac1405d7da601a3790777f62b83236ed10 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From e6fcd98cab30ba065534890cdb5f0775db054fcd Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Wed, 5 Jul 2023 10:00:17 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 034/199] mtk: mt76: mt7996: support eagle ZWDFS on iFEM
developer66e89bc2024-04-23 14:50:01 +08005
6Fix the case that control channel is not first chan during first
7interface setup.
8Refactor ifem adie logic (if/else to switch, use sku_type & fem_type)
9
developer66e89bc2024-04-23 14:50:01 +080010Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
11---
12 mt7996/main.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++---
13 mt7996/mcu.c | 6 +++--
14 mt7996/mt7996.h | 1 +
15 3 files changed, 67 insertions(+), 5 deletions(-)
16
17diff --git a/mt7996/main.c b/mt7996/main.c
developer05f3b2b2024-08-19 19:17:34 +080018index 5a6ba6a6..5b1984ac 100644
developer66e89bc2024-04-23 14:50:01 +080019--- a/mt7996/main.c
20+++ b/mt7996/main.c
developer05f3b2b2024-08-19 19:17:34 +080021@@ -1448,6 +1448,61 @@ mt7996_twt_teardown_request(struct ieee80211_hw *hw,
developer66e89bc2024-04-23 14:50:01 +080022 mutex_unlock(&dev->mt76.mutex);
23 }
24
25+static void
26+mt7996_background_radar_handle_7975_ifem(struct ieee80211_hw *hw,
27+ struct cfg80211_chan_def *user_chandef,
28+ struct cfg80211_chan_def *fw_chandef)
29+{
30+ struct mt7996_dev *dev = mt7996_hw_dev(hw);
31+ struct cfg80211_chan_def *c = user_chandef;
32+ struct ieee80211_channel *first_chan;
33+ bool is_ifem_adie, expand = false;
34+
35+ switch (mt76_chip(&dev->mt76)) {
36+ case 0x7990:
37+ is_ifem_adie = dev->fem_type == MT7996_FEM_INT &&
38+ dev->chip_sku != MT7996_SKU_233;
39+ break;
40+ case 0x7992:
41+ is_ifem_adie = dev->chip_sku == MT7992_SKU_44 &&
42+ dev->fem_type != MT7996_FEM_EXT;
43+ break;
44+ default:
45+ return;
46+ }
47+
48+ if (!user_chandef || !is_ifem_adie)
49+ goto out;
50+
51+ if (user_chandef->width == NL80211_CHAN_WIDTH_160) {
52+ first_chan = ieee80211_get_channel(hw->wiphy, user_chandef->center_freq1 - 70);
53+ if (dev->bg_nxt_freq)
54+ goto out;
55+
56+ if (first_chan->flags & IEEE80211_CHAN_RADAR)
57+ dev->bg_nxt_freq = first_chan->center_freq;
58+ else
59+ c = fw_chandef;
60+
61+ c->chan = ieee80211_get_channel(hw->wiphy, first_chan->center_freq + 80);
62+ } else {
63+ if (!dev->bg_nxt_freq)
64+ goto out;
65+
66+ c->chan = ieee80211_get_channel(hw->wiphy, dev->bg_nxt_freq);
67+ dev->bg_nxt_freq = 0;
68+ expand = true;
69+ }
70+ c->width = NL80211_CHAN_WIDTH_80;
71+ c->center_freq1 = c->chan->center_freq + 30;
72+
73+ if (c == user_chandef)
74+ cfg80211_background_radar_update_channel(hw->wiphy, c, expand);
75+ return;
76+out:
77+ dev->bg_nxt_freq = 0;
78+}
79+
80 static int
81 mt7996_set_radar_background(struct ieee80211_hw *hw,
82 struct cfg80211_chan_def *chandef)
developer05f3b2b2024-08-19 19:17:34 +080083@@ -1456,6 +1511,7 @@ mt7996_set_radar_background(struct ieee80211_hw *hw,
developer66e89bc2024-04-23 14:50:01 +080084 struct mt7996_dev *dev = phy->dev;
85 int ret = -EINVAL;
86 bool running;
87+ struct cfg80211_chan_def ifem_chandef = {};
88
89 mutex_lock(&dev->mt76.mutex);
90
developer05f3b2b2024-08-19 19:17:34 +080091@@ -1468,13 +1524,14 @@ mt7996_set_radar_background(struct ieee80211_hw *hw,
developer66e89bc2024-04-23 14:50:01 +080092 goto out;
93 }
94
95+ mt7996_background_radar_handle_7975_ifem(hw, chandef, &ifem_chandef);
96+
97 /* rdd2 already configured on a radar channel */
98 running = dev->rdd2_phy &&
99 cfg80211_chandef_valid(&dev->rdd2_chandef) &&
100 !!(dev->rdd2_chandef.chan->flags & IEEE80211_CHAN_RADAR);
101
102- if (!chandef || running ||
103- !(chandef->chan->flags & IEEE80211_CHAN_RADAR)) {
104+ if (!chandef || running) {
105 ret = mt7996_mcu_rdd_background_enable(phy, NULL);
106 if (ret)
107 goto out;
developer05f3b2b2024-08-19 19:17:34 +0800108@@ -1483,7 +1540,9 @@ mt7996_set_radar_background(struct ieee80211_hw *hw,
developer66e89bc2024-04-23 14:50:01 +0800109 goto update_phy;
110 }
111
112- ret = mt7996_mcu_rdd_background_enable(phy, chandef);
113+ ret = mt7996_mcu_rdd_background_enable(phy,
114+ ifem_chandef.chan ?
115+ &ifem_chandef : chandef);
116 if (ret)
117 goto out;
118
119diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developer05f3b2b2024-08-19 19:17:34 +0800120index 3b4c45bb..8ac7adf6 100644
developer66e89bc2024-04-23 14:50:01 +0800121--- a/mt7996/mcu.c
122+++ b/mt7996/mcu.c
123@@ -372,12 +372,14 @@ mt7996_mcu_rx_radar_detected(struct mt7996_dev *dev, struct sk_buff *skb)
124 if (!mphy)
125 return;
126
127- if (r->band_idx == MT_RX_SEL2)
128+ if (r->band_idx == MT_RX_SEL2) {
129+ dev->bg_nxt_freq = 0;
130 cfg80211_background_radar_event(mphy->hw->wiphy,
131 &dev->rdd2_chandef,
132 GFP_ATOMIC);
133- else
134+ } else {
135 ieee80211_radar_detected(mphy->hw);
136+ }
137 dev->hw_pattern++;
138 }
139
140diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developer05f3b2b2024-08-19 19:17:34 +0800141index 70aafb29..439c57f4 100644
developer66e89bc2024-04-23 14:50:01 +0800142--- a/mt7996/mt7996.h
143+++ b/mt7996/mt7996.h
developer05f3b2b2024-08-19 19:17:34 +0800144@@ -397,6 +397,7 @@ struct mt7996_dev {
developer66e89bc2024-04-23 14:50:01 +0800145 bool testmode_enable;
146 bool bin_file_mode;
147 u8 eeprom_mode;
148+ u32 bg_nxt_freq;
149
150 bool ibf;
151 u8 fw_debug_wm;
152--
developer9237f442024-06-14 17:13:04 +08001532.18.0
developer66e89bc2024-04-23 14:50:01 +0800154