blob: 6c348a4481d672f59a16e386573cf60f701c248e [file] [log] [blame]
developer43a264f2024-03-26 14:09:54 +08001From fcad28acd81313d08e6c187a5cfe689345e40c2e Mon Sep 17 00:00:00 2001
2From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Mon, 4 Mar 2024 11:29:06 +0800
4Subject: [PATCH 1049/1051] wifi: mt76: mt7915: add background radar hw cap
5 check
6
7Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
8---
9 mt7915/debugfs.c | 5 +++++
10 mt7915/eeprom.h | 30 ++++++++++++++++++++++++++++++
11 mt7915/init.c | 7 ++++---
12 3 files changed, 39 insertions(+), 3 deletions(-)
13
14diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c
15index 017d43d7..599a794c 100644
16--- a/mt7915/debugfs.c
17+++ b/mt7915/debugfs.c
18@@ -459,6 +459,11 @@ mt7915_rdd_monitor(struct seq_file *s, void *data)
19
20 mutex_lock(&dev->mt76.mutex);
21
22+ if (!mt7915_get_background_radar_cap(dev)) {
23+ seq_puts(s, "no background radar capability\n");
24+ goto out;
25+ }
26+
27 if (!cfg80211_chandef_valid(chandef)) {
28 ret = -EINVAL;
29 goto out;
30diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
31index 70fca0b3..adeee104 100644
32--- a/mt7915/eeprom.h
33+++ b/mt7915/eeprom.h
34@@ -55,6 +55,7 @@ enum mt7915_eeprom_field {
35 #define MT_EE_CAL_DPD_SIZE_V2_7981 (102 * MT_EE_CAL_UNIT) /* no 6g dpd data */
36
37 #define MT_EE_WIFI_CONF0_TX_PATH GENMASK(2, 0)
38+#define MT_EE_WIFI_CONF0_RX_PATH GENMASK(5, 3)
39 #define MT_EE_WIFI_CONF0_BAND_SEL GENMASK(7, 6)
40 #define MT_EE_WIFI_CONF1_BAND_SEL GENMASK(7, 6)
41 #define MT_EE_WIFI_CONF_STREAM_NUM GENMASK(7, 5)
42@@ -206,6 +207,35 @@ mt7915_get_cal_dpd_size(struct mt7915_dev *dev)
43 return MT_EE_CAL_DPD_SIZE_V2;
44 }
45
46+static inline bool
47+mt7915_get_background_radar_cap(struct mt7915_dev *dev)
48+{
49+ u8 buf[MT7915_EEPROM_BLOCK_SIZE];
50+ int val, band_sel, tx_path, rx_path, offs = MT_EE_WIFI_CONF + 1;
51+
52+ switch (mt76_chip(&dev->mt76)) {
53+ case 0x7915:
54+ return 1;
55+ case 0x7906:
56+ if (!mt7915_mcu_get_eeprom(dev, offs, buf)) {
57+ val = buf[offs % MT7915_EEPROM_BLOCK_SIZE];
58+ band_sel = FIELD_GET(MT_EE_WIFI_CONF0_BAND_SEL, val);
59+ rx_path = FIELD_GET(MT_EE_WIFI_CONF0_RX_PATH, val);
60+ tx_path = FIELD_GET(MT_EE_WIFI_CONF0_TX_PATH, val);
61+
62+ return (band_sel == MT_EE_V2_BAND_SEL_5GHZ &&
63+ tx_path == rx_path && rx_path == 2);
64+ }
65+ break;
66+ case 0x7981:
67+ case 0x7986:
68+ default:
69+ break;
70+ }
71+
72+ return 0;
73+}
74+
75 extern const u8 mt7915_sku_group_len[MAX_SKU_RATE_GROUP_NUM];
76
77 #endif
78diff --git a/mt7915/init.c b/mt7915/init.c
79index c052b927..f5daf024 100644
80--- a/mt7915/init.c
81+++ b/mt7915/init.c
82@@ -404,9 +404,10 @@ mt7915_init_wiphy(struct mt7915_phy *phy)
83 if (!is_mt7915(&dev->mt76))
84 wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_STA_TX_PWR);
85
86- if (!mdev->dev->of_node ||
87- !of_property_read_bool(mdev->dev->of_node,
88- "mediatek,disable-radar-background"))
89+ if (mt7915_get_background_radar_cap(phy->dev) &&
90+ (!mdev->dev->of_node ||
91+ !of_property_read_bool(mdev->dev->of_node,
92+ "mediatek,disable-radar-background")))
93 wiphy_ext_feature_set(wiphy,
94 NL80211_EXT_FEATURE_RADAR_BACKGROUND);
95
96--
972.18.0
98