net:wireless:Support eswin usb wifi ECR6600U
[platform/kernel/linux-starfive.git] / drivers / net / wireless / eswin / ecrnx_radar.h
1 /**
2  ******************************************************************************
3  *
4  * @file ecrnx_radar.h
5  *
6  * @brief Functions to handle radar detection
7  *
8  *
9  * Copyright (C) ESWIN 2015-2020
10  *
11  ******************************************************************************
12  */
13 #ifndef _ECRNX_RADAR_H_
14 #define _ECRNX_RADAR_H_
15
16 #include <linux/nl80211.h>
17
18 struct ecrnx_vif;
19 struct ecrnx_hw;
20
21 enum ecrnx_radar_chain {
22     ECRNX_RADAR_RIU = 0,
23     ECRNX_RADAR_FCU,
24     ECRNX_RADAR_LAST
25 };
26
27 enum ecrnx_radar_detector {
28     ECRNX_RADAR_DETECT_DISABLE = 0, /* Ignore radar pulses */
29     ECRNX_RADAR_DETECT_ENABLE  = 1, /* Process pattern detection but do not
30                                       report radar to upper layer (for test) */
31     ECRNX_RADAR_DETECT_REPORT  = 2  /* Process pattern detection and report
32                                       radar to upper layer. */
33 };
34
35 #ifdef CONFIG_ECRNX_RADAR
36 #include <linux/workqueue.h>
37 #include <linux/spinlock.h>
38
39 #define ECRNX_RADAR_PULSE_MAX  32
40
41 /**
42  * struct ecrnx_radar_pulses - List of pulses reported by HW
43  * @index: write index
44  * @count: number of valid pulses
45  * @buffer: buffer of pulses
46  */
47 struct ecrnx_radar_pulses {
48     /* Last radar pulses received */
49     int index;
50     int count;
51     u32 buffer[ECRNX_RADAR_PULSE_MAX];
52 };
53
54 /**
55  * struct dfs_pattern_detector - DFS pattern detector
56  * @region: active DFS region, NL80211_DFS_UNSET until set
57  * @num_radar_types: number of different radar types
58  * @last_pulse_ts: time stamp of last valid pulse in usecs
59  * @prev_jiffies:
60  * @radar_detector_specs: array of radar detection specs
61  * @channel_detectors: list connecting channel_detector elements
62  */
63 struct dfs_pattern_detector {
64     u8 enabled;
65     enum nl80211_dfs_regions region;
66     u8 num_radar_types;
67     u64 last_pulse_ts;
68     u32 prev_jiffies;
69     const struct radar_detector_specs *radar_spec;
70     struct list_head detectors[];
71 };
72
73 #define NX_NB_RADAR_DETECTED 4
74
75 /**
76  * struct ecrnx_radar_detected - List of radar detected
77  */
78 struct ecrnx_radar_detected {
79     u16 index;
80     u16 count;
81     s64 time[NX_NB_RADAR_DETECTED];
82     s16 freq[NX_NB_RADAR_DETECTED];
83 };
84
85
86 struct ecrnx_radar {
87     struct ecrnx_radar_pulses pulses[ECRNX_RADAR_LAST];
88     struct dfs_pattern_detector *dpd[ECRNX_RADAR_LAST];
89     struct ecrnx_radar_detected detected[ECRNX_RADAR_LAST];
90     struct work_struct detection_work;  /* Work used to process radar pulses */
91     spinlock_t lock;                    /* lock for pulses processing */
92
93     /* In softmac cac is handled by mac80211 */
94 #ifdef CONFIG_ECRNX_FULLMAC
95     struct delayed_work cac_work;       /* Work used to handle CAC */
96     struct ecrnx_vif *cac_vif;           /* vif on which we started CAC */
97 #endif
98 };
99
100 bool ecrnx_radar_detection_init(struct ecrnx_radar *radar);
101 void ecrnx_radar_detection_deinit(struct ecrnx_radar *radar);
102 bool ecrnx_radar_set_domain(struct ecrnx_radar *radar,
103                            enum nl80211_dfs_regions region);
104 void ecrnx_radar_detection_enable(struct ecrnx_radar *radar, u8 enable, u8 chain);
105 bool ecrnx_radar_detection_is_enable(struct ecrnx_radar *radar, u8 chain);
106 void ecrnx_radar_start_cac(struct ecrnx_radar *radar, u32 cac_time_ms,
107                           struct ecrnx_vif *vif);
108 void ecrnx_radar_cancel_cac(struct ecrnx_radar *radar);
109 void ecrnx_radar_detection_enable_on_cur_channel(struct ecrnx_hw *ecrnx_hw);
110 int  ecrnx_radar_dump_pattern_detector(char *buf, size_t len,
111                                       struct ecrnx_radar *radar, u8 chain);
112 int  ecrnx_radar_dump_radar_detected(char *buf, size_t len,
113                                     struct ecrnx_radar *radar, u8 chain);
114
115 #else
116
117 struct ecrnx_radar {
118 };
119
120 static inline bool ecrnx_radar_detection_init(struct ecrnx_radar *radar)
121 {return true;}
122
123 static inline void ecrnx_radar_detection_deinit(struct ecrnx_radar *radar)
124 {}
125
126 static inline bool ecrnx_radar_set_domain(struct ecrnx_radar *radar,
127                                          enum nl80211_dfs_regions region)
128 {return true;}
129
130 static inline void ecrnx_radar_detection_enable(struct ecrnx_radar *radar,
131                                                u8 enable, u8 chain)
132 {}
133
134 static inline bool ecrnx_radar_detection_is_enable(struct ecrnx_radar *radar,
135                                                  u8 chain)
136 {return false;}
137
138 static inline void ecrnx_radar_start_cac(struct ecrnx_radar *radar,
139                                         u32 cac_time_ms, struct ecrnx_vif *vif)
140 {}
141
142 static inline void ecrnx_radar_cancel_cac(struct ecrnx_radar *radar)
143 {}
144
145 static inline void ecrnx_radar_detection_enable_on_cur_channel(struct ecrnx_hw *ecrnx_hw)
146 {}
147
148 static inline int ecrnx_radar_dump_pattern_detector(char *buf, size_t len,
149                                                    struct ecrnx_radar *radar,
150                                                    u8 chain)
151 {return 0;}
152
153 static inline int ecrnx_radar_dump_radar_detected(char *buf, size_t len,
154                                                  struct ecrnx_radar *radar,
155                                                  u8 chain)
156 {return 0;}
157
158 #endif /* CONFIG_ECRNX_RADAR */
159
160 #endif // _ECRNX_RADAR_H_