xref: /linux/drivers/net/wireless/ath/dfs_pattern_detector.h (revision 3eb66e91a25497065c5322b1268cbc3953642227)
1 /*
2  * Copyright (c) 2012 Neratec Solutions AG
3  *
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.
7  *
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.
15  */
16 
17 #ifndef DFS_PATTERN_DETECTOR_H
18 #define DFS_PATTERN_DETECTOR_H
19 
20 #include <linux/types.h>
21 #include <linux/list.h>
22 #include <linux/nl80211.h>
23 
24 /* tolerated deviation of radar time stamp in usecs on both sides
25  * TODO: this might need to be HW-dependent
26  */
27 #define PRI_TOLERANCE	16
28 
29 /**
30  * struct ath_dfs_pool_stats - DFS Statistics for global pools
31  */
32 struct ath_dfs_pool_stats {
33 	u32 pool_reference;
34 	u32 pulse_allocated;
35 	u32 pulse_alloc_error;
36 	u32 pulse_used;
37 	u32 pseq_allocated;
38 	u32 pseq_alloc_error;
39 	u32 pseq_used;
40 };
41 
42 /**
43  * struct pulse_event - describing pulses reported by PHY
44  * @ts: pulse time stamp in us
45  * @freq: channel frequency in MHz
46  * @width: pulse duration in us
47  * @rssi: rssi of radar event
48  * @chirp: chirp detected in pulse
49  */
50 struct pulse_event {
51 	u64 ts;
52 	u16 freq;
53 	u8 width;
54 	u8 rssi;
55 	bool chirp;
56 };
57 
58 /**
59  * struct radar_detector_specs - detector specs for a radar pattern type
60  * @type_id: pattern type, as defined by regulatory
61  * @width_min: minimum radar pulse width in [us]
62  * @width_max: maximum radar pulse width in [us]
63  * @pri_min: minimum pulse repetition interval in [us] (including tolerance)
64  * @pri_max: minimum pri in [us] (including tolerance)
65  * @num_pri: maximum number of different pri for this type
66  * @ppb: pulses per bursts for this type
67  * @ppb_thresh: number of pulses required to trigger detection
68  * @max_pri_tolerance: pulse time stamp tolerance on both sides [us]
69  * @chirp: chirp required for the radar pattern
70  */
71 struct radar_detector_specs {
72 	u8 type_id;
73 	u8 width_min;
74 	u8 width_max;
75 	u16 pri_min;
76 	u16 pri_max;
77 	u8 num_pri;
78 	u8 ppb;
79 	u8 ppb_thresh;
80 	u8 max_pri_tolerance;
81 	bool chirp;
82 };
83 
84 /**
85  * struct dfs_pattern_detector - DFS pattern detector
86  * @exit(): destructor
87  * @set_dfs_domain(): set DFS domain, resets detector lines upon domain changes
88  * @add_pulse(): add radar pulse to detector, returns true on detection
89  * @region: active DFS region, NL80211_DFS_UNSET until set
90  * @num_radar_types: number of different radar types
91  * @last_pulse_ts: time stamp of last valid pulse in usecs
92  * @radar_detector_specs: array of radar detection specs
93  * @channel_detectors: list connecting channel_detector elements
94  */
95 struct dfs_pattern_detector {
96 	void (*exit)(struct dfs_pattern_detector *dpd);
97 	bool (*set_dfs_domain)(struct dfs_pattern_detector *dpd,
98 			   enum nl80211_dfs_regions region);
99 	bool (*add_pulse)(struct dfs_pattern_detector *dpd,
100 			  struct pulse_event *pe,
101 			  struct radar_detector_specs *rs);
102 
103 	struct ath_dfs_pool_stats (*get_stats)(struct dfs_pattern_detector *dpd);
104 	enum nl80211_dfs_regions region;
105 	u8 num_radar_types;
106 	u64 last_pulse_ts;
107 	/* needed for ath_dbg() */
108 	struct ath_common *common;
109 
110 	const struct radar_detector_specs *radar_spec;
111 	struct list_head channel_detectors;
112 };
113 
114 /**
115  * dfs_pattern_detector_init() - constructor for pattern detector class
116  * @param region: DFS domain to be used, can be NL80211_DFS_UNSET at creation
117  * @return instance pointer on success, NULL otherwise
118  */
119 extern struct dfs_pattern_detector *
120 dfs_pattern_detector_init(struct ath_common *common,
121 			  enum nl80211_dfs_regions region);
122 #endif /* DFS_PATTERN_DETECTOR_H */
123