2 * Copyright (C) 2016 Lorenzo Bianconi <lorenzo.bianconi83@gmail.com>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #ifndef __MT76x02_DFS_H
18 #define __MT76x02_DFS_H
20 #include <linux/types.h>
21 #include <linux/nl80211.h>
23 #define MT_DFS_GP_INTERVAL (10 << 4) /* 64 us unit */
24 #define MT_DFS_NUM_ENGINES 4
27 #define MT_DFS_SYM_ROUND 0
28 #define MT_DFS_DELTA_DELAY 2
29 #define MT_DFS_VGA_MASK 0
30 #define MT_DFS_PWR_GAIN_OFFSET 3
31 #define MT_DFS_PWR_DOWN_TIME 0xf
32 #define MT_DFS_RX_PE_MASK 0xff
33 #define MT_DFS_PKT_END_MASK 0
34 #define MT_DFS_CH_EN 0xf
36 /* sw detector params */
37 #define MT_DFS_EVENT_LOOP 64
38 #define MT_DFS_SW_TIMEOUT (HZ / 20)
39 #define MT_DFS_EVENT_WINDOW (HZ / 5)
40 #define MT_DFS_SEQUENCE_WINDOW (200 * (1 << 20))
41 #define MT_DFS_EVENT_TIME_MARGIN 2000
42 #define MT_DFS_PRI_MARGIN 4
43 #define MT_DFS_SEQUENCE_TH 6
45 #define MT_DFS_FCC_MAX_PRI ((28570 << 1) + 1000)
46 #define MT_DFS_FCC_MIN_PRI (3000 - 2)
47 #define MT_DFS_JP_MAX_PRI ((80000 << 1) + 1000)
48 #define MT_DFS_JP_MIN_PRI (28500 - 2)
49 #define MT_DFS_ETSI_MAX_PRI (133333 + 125000 + 117647 + 1000)
50 #define MT_DFS_ETSI_MIN_PRI (4500 - 20)
52 struct mt76x02_radar_specs {
69 #define MT_DFS_CHECK_EVENT(x) ((x) != GENMASK(31, 0))
70 #define MT_DFS_EVENT_ENGINE(x) (((x) & BIT(31)) ? 2 : 0)
71 #define MT_DFS_EVENT_TIMESTAMP(x) ((x) & GENMASK(21, 0))
72 #define MT_DFS_EVENT_WIDTH(x) ((x) & GENMASK(11, 0))
73 struct mt76x02_dfs_event {
74 unsigned long fetch_ts;
80 #define MT_DFS_EVENT_BUFLEN 256
81 struct mt76x02_dfs_event_rb {
82 struct mt76x02_dfs_event data[MT_DFS_EVENT_BUFLEN];
86 struct mt76x02_dfs_sequence {
87 struct list_head head;
95 struct mt76x02_dfs_hw_pulse {
103 struct mt76x02_dfs_sw_detector_params {
109 struct mt76x02_dfs_engine_stats {
111 u32 hw_pulse_discarded;
115 struct mt76x02_dfs_seq_stats {
120 struct mt76x02_dfs_pattern_detector {
124 struct mt76x02_dfs_sw_detector_params sw_dpd_params;
125 struct mt76x02_dfs_event_rb event_rb[2];
127 struct list_head sequences;
128 struct list_head seq_pool;
129 struct mt76x02_dfs_seq_stats seq_stats;
131 unsigned long last_sw_check;
134 struct mt76x02_dfs_engine_stats stats[MT_DFS_NUM_ENGINES];
135 struct tasklet_struct dfs_tasklet;
138 void mt76x02_dfs_init_params(struct mt76x02_dev *dev);
139 void mt76x02_dfs_init_detector(struct mt76x02_dev *dev);
140 void mt76x02_regd_notifier(struct wiphy *wiphy,
141 struct regulatory_request *request);
142 void mt76x02_phy_dfs_adjust_agc(struct mt76x02_dev *dev);
143 #endif /* __MT76x02_DFS_H */