blob: ecad61f64021849a774c6f1a9f6589b7b2ac7eea [file] [log] [blame]
developer20d67712022-03-02 14:09:32 +08001From 623e57c672ee85f8a4a9455888237d09df405962 Mon Sep 17 00:00:00 2001
2From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Mon, 28 Jun 2021 10:46:39 +0800
4Subject: [PATCH 1105/1112] mt76: mt7915: add off channel scan support in
5 testmode
6
7Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
8---
9 .../wireless/mediatek/mt76/mt7915/testmode.c | 72 +++++++++++++++++++
10 .../wireless/mediatek/mt76/mt7915/testmode.h | 10 +++
11 2 files changed, 82 insertions(+)
12
13diff --git a/mt7915/testmode.c b/mt7915/testmode.c
14index 98431d6..08bb700 100644
15--- a/mt7915/testmode.c
16+++ b/mt7915/testmode.c
17@@ -10,6 +10,7 @@ enum {
18 TM_CHANGED_TXPOWER,
19 TM_CHANGED_FREQ_OFFSET,
20 TM_CHANGED_CFG,
21+ TM_CHANGED_OFF_CH_SCAN_CH,
22
23 /* must be last */
24 NUM_TM_CHANGED
25@@ -19,6 +20,7 @@ static const u8 tm_change_map[] = {
26 [TM_CHANGED_TXPOWER] = MT76_TM_ATTR_TX_POWER,
27 [TM_CHANGED_FREQ_OFFSET] = MT76_TM_ATTR_FREQ_OFFSET,
28 [TM_CHANGED_CFG] = MT76_TM_ATTR_CFG,
29+ [TM_CHANGED_OFF_CH_SCAN_CH] = MT76_TM_ATTR_OFF_CH_SCAN_CH,
30 };
31
32 struct reg_band {
33@@ -36,6 +38,25 @@ struct reg_band {
34 static struct reg_band reg_backup_list[TM_REG_MAX_ID];
35
36
37+static u8 mt7915_tm_chan_bw(enum nl80211_chan_width width)
38+{
39+ static const u8 width_to_bw[] = {
40+ [NL80211_CHAN_WIDTH_40] = TM_CBW_40MHZ,
41+ [NL80211_CHAN_WIDTH_80] = TM_CBW_80MHZ,
42+ [NL80211_CHAN_WIDTH_80P80] = TM_CBW_8080MHZ,
43+ [NL80211_CHAN_WIDTH_160] = TM_CBW_160MHZ,
44+ [NL80211_CHAN_WIDTH_5] = TM_CBW_5MHZ,
45+ [NL80211_CHAN_WIDTH_10] = TM_CBW_10MHZ,
46+ [NL80211_CHAN_WIDTH_20] = TM_CBW_20MHZ,
47+ [NL80211_CHAN_WIDTH_20_NOHT] = TM_CBW_20MHZ,
48+ };
49+
50+ if (width >= ARRAY_SIZE(width_to_bw))
51+ return 0;
52+
53+ return width_to_bw[width];
54+}
55+
56 static int
57 mt7915_tm_set_tx_power(struct mt7915_phy *phy)
58 {
59@@ -206,6 +227,55 @@ mt7915_tm_set_cfg(struct mt7915_phy *phy)
60 sizeof(req), false);
61 }
62
63+static int
64+mt7915_tm_set_off_channel_scan(struct mt7915_phy *phy)
65+{
66+#define OFF_CH_SCAN_SIMPLE_RX 2
67+ struct mt76_testmode_data *td = &phy->mt76->test;
68+ struct mt7915_dev *dev = phy->dev;
69+ struct cfg80211_chan_def *chandef = &phy->mt76->chandef;
70+ int freq1 = chandef->center_freq1;
71+ struct {
72+ u8 cur_pri_ch;
73+ u8 cur_center_ch;
74+ u8 cur_bw;
75+ u8 cur_tx_path;
76+ u8 cur_rx_path;
77+
78+ u8 scan_pri_ch;
79+ u8 scan_center_ch;
80+ u8 scan_bw;
81+ u8 scan_tx_path;
82+ u8 scan_rx_path;
83+
84+ u8 enable;
85+ u8 band_idx;
86+ u8 type;
87+ u8 is_5g;
88+ u8 _rsv[2];
89+ } __packed req = {
90+ .cur_pri_ch = chandef->chan->hw_value,
91+ .cur_center_ch = ieee80211_frequency_to_channel(freq1),
92+ .cur_bw = mt7915_tm_chan_bw(chandef->width),
93+ .cur_tx_path = td->tx_antenna_mask,
94+ .cur_rx_path = td->tx_antenna_mask,
95+
96+ .scan_pri_ch = td->off_ch_scan_ch,
97+ .scan_center_ch = td->off_ch_scan_center_ch,
98+ .scan_bw = td->off_ch_scan_bw,
99+ .scan_tx_path = td->off_ch_scan_path,
100+ .scan_rx_path = td->off_ch_scan_path,
101+
102+ .enable = !!td->off_ch_scan_ch,
103+ .band_idx = phy != &dev->phy,
104+ .type = OFF_CH_SCAN_SIMPLE_RX,
105+ .is_5g = td->off_ch_scan_ch > 14 ? 1 : 0,
106+ };
107+
108+ return mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD(OFFCH_SCAN_CTRL), &req,
109+ sizeof(req), false);
110+}
111+
112 static int
113 mt7915_tm_set_wmm_qid(struct mt7915_dev *dev, u8 qid, u8 aifs, u8 cw_min,
114 u16 cw_max, u16 txop)
115@@ -753,6 +823,8 @@ mt7915_tm_update_params(struct mt7915_phy *phy, u32 changed)
116 mt7915_tm_set_tx_power(phy);
117 if (changed & BIT(TM_CHANGED_CFG))
118 mt7915_tm_set_cfg(phy);
119+ if (changed & BIT(TM_CHANGED_OFF_CH_SCAN_CH))
120+ mt7915_tm_set_off_channel_scan(phy);
121 }
122
123 static int
124diff --git a/mt7915/testmode.h b/mt7915/testmode.h
125index a1c54c8..d22aabe 100644
126--- a/mt7915/testmode.h
127+++ b/mt7915/testmode.h
128@@ -130,4 +130,14 @@ struct mt7915_tm_rx_stat_band {
129 __le16 mdrdy_cnt_ofdm;
130 };
131
132+enum {
133+ TM_CBW_20MHZ,
134+ TM_CBW_40MHZ,
135+ TM_CBW_80MHZ,
136+ TM_CBW_10MHZ,
137+ TM_CBW_5MHZ,
138+ TM_CBW_160MHZ,
139+ TM_CBW_8080MHZ,
140+};
141+
142 #endif
143--
1442.25.1
145