xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8188fu/hal/phydm/phydm_ccx.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2017  Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
12  * more details.
13  *
14  * The full GNU General Public License is included in this distribution in the
15  * file called LICENSE.
16  *
17  * Contact Information:
18  * wlanfae <wlanfae@realtek.com>
19  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20  * Hsinchu 300, Taiwan.
21  *
22  * Larry Finger <Larry.Finger@lwfinger.net>
23  *
24  *****************************************************************************/
25 
26 #ifndef __PHYDMCCX_H__
27 #define __PHYDMCCX_H__
28 
29 /* 2020.01.10 add nhm_pwr for new nhm utility*/
30 #define CCX_VERSION "3.7"
31 
32 /* @1 ============================================================
33  * 1  Definition
34  * 1 ============================================================
35  */
36 #define CCX_EN 1
37 
38 #define	MAX_ENV_MNTR_TIME	8	/*second*/
39 #define	IGI_TO_NHM_TH_MULTIPLIER 2
40 #define	MS_TO_US		1000
41 #define	MS_TO_4US_RATIO		250
42 #define	CCA_CAP			14
43 #define	CLM_MAX_REPORT_TIME	10
44 #define	DEVIDER_ERROR		0xffff
45 #define	CLM_PERIOD_MAX		65535
46 #define	IFS_CLM_PERIOD_MAX	65535
47 #define	NHM_PERIOD_MAX		65534
48 #define	NHM_TH_NUM		11	/*threshold number of NHM*/
49 #define	NHM_RPT_NUM		12
50 #define	IFS_CLM_NUM		4
51 #ifdef NHM_DYM_PW_TH_SUPPORT
52 #define	DYM_PWTH_CCA_CAP	24
53 #endif
54 
55 #define	IGI_2_NHM_TH(igi)	((igi) << 1)/*NHM_threshold = IGI * 2*/
56 #define	NTH_TH_2_RSSI(th)	((th >> 1) - 10)
57 
58 /*@FAHM*/
59 #define	FAHM_INCLD_FA		BIT(0)
60 #define	FAHM_INCLD_CRC_OK	BIT(1)
61 #define	FAHM_INCLD_CRC_ER	BIT(2)
62 
63 #define NHM_SUCCESS		BIT(0)
64 #define CLM_SUCCESS		BIT(1)
65 #define FAHM_SUCCESS		BIT(2)
66 #define IFS_CLM_SUCCESS		BIT(3)
67 #define	ENV_MNTR_FAIL		0xff
68 
69 /* @1 ============================================================
70  * 1 enumrate
71  * 1 ============================================================
72  */
73 enum phydm_clm_level {
74 	CLM_RELEASE		= 0,
75 	CLM_LV_1		= 1,	/* @Low Priority function */
76 	CLM_LV_2		= 2,	/* @Middle Priority function */
77 	CLM_LV_3		= 3,	/* @High priority function (ex: Check hang function) */
78 	CLM_LV_4		= 4,	/* @Debug function (the highest priority) */
79 	CLM_MAX_NUM		= 5
80 };
81 
82 enum phydm_nhm_level {
83 	NHM_RELEASE		= 0,
84 	NHM_LV_1		= 1,	/* @Low Priority function */
85 	NHM_LV_2		= 2,	/* @Middle Priority function */
86 	NHM_LV_3		= 3,	/* @High priority function (ex: Check hang function) */
87 	NHM_LV_4		= 4,	/* @Debug function (the highest priority) */
88 	NHM_MAX_NUM		= 5
89 };
90 
91 enum phydm_ifs_clm_level {
92 	IFS_CLM_RELEASE		= 0,
93 	IFS_CLM_LV_1		= 1,	/* @Low Priority function */
94 	IFS_CLM_LV_2		= 2,	/* @Middle Priority function */
95 	IFS_CLM_LV_3		= 3,	/* @High priority function (ex: Check hang function) */
96 	IFS_CLM_LV_4		= 4,	/* @Debug function (the highest priority) */
97 	IFS_CLM_MAX_NUM		= 5
98 };
99 
100 enum nhm_divider_opt_all {
101 	NHM_CNT_ALL		= 0,	/*nhm SUM report <= 255*/
102 	NHM_VALID		= 1,	/*nhm SUM report = 255*/
103 	NHM_CNT_INIT
104 };
105 
106 enum nhm_setting {
107 	SET_NHM_SETTING,
108 	STORE_NHM_SETTING,
109 	RESTORE_NHM_SETTING
110 };
111 
112 enum nhm_option_cca_all {
113 	NHM_EXCLUDE_CCA		= 0,
114 	NHM_INCLUDE_CCA		= 1,
115 	NHM_CCA_INIT
116 };
117 
118 enum nhm_option_txon_all {
119 	NHM_EXCLUDE_TXON	= 0,
120 	NHM_INCLUDE_TXON	= 1,
121 	NHM_TXON_INIT
122 };
123 
124 enum nhm_application {
125 	NHM_BACKGROUND		= 0,/*@default*/
126 	NHM_ACS			= 1,
127 	IEEE_11K_HIGH		= 2,
128 	IEEE_11K_LOW		= 3,
129 	INTEL_XBOX		= 4,
130 	NHM_DBG			= 5, /*@manual trigger*/
131 };
132 
133 enum clm_application {
134 	CLM_BACKGROUND		= 0,/*@default*/
135 	CLM_ACS			= 1,
136 };
137 
138 enum ifs_clm_application {
139 	IFS_CLM_BACKGROUND		= 0,/*default*/
140 	IFS_CLM_HP_TAS			= 1,
141 	HP_TAS				= 2,
142 	IFS_CLM_DBG			= 3
143 };
144 
145 enum clm_monitor_mode {
146 	CLM_DRIVER_MNTR		= 1,
147 	CLM_FW_MNTR		= 2
148 };
149 
150 enum phydm_ifs_clm_unit {
151 	IFS_CLM_4		= 0,	/*4us*/
152 	IFS_CLM_8		= 1,	/*8us*/
153 	IFS_CLM_12		= 2,	/*12us*/
154 	IFS_CLM_16		= 3,	/*16us*/
155 	IFS_CLM_INIT
156 };
157 
158 /* @1 ============================================================
159  * 1  structure
160  * 1 ============================================================
161  */
162 struct env_trig_rpt {
163 	u8			nhm_rpt_stamp;
164 	u8			clm_rpt_stamp;
165 };
166 
167 
168 struct env_mntr_rpt {
169 	u8			nhm_ratio;
170 	u8			nhm_result[NHM_RPT_NUM];
171 	u8			clm_ratio;
172 	u8			nhm_rpt_stamp;
173 	u8			clm_rpt_stamp;
174 	u8			nhm_noise_pwr; /*including r[0]~r[10]*/
175 	u8			nhm_pwr; /*including r[0]~r[11]*/
176 };
177 
178 struct enhance_mntr_trig_rpt {
179 	u8			ifs_clm_rpt_stamp;
180 };
181 
182 
183 struct enhance_mntr_rpt {
184 	u8			ifs_clm_rpt_stamp;
185 	u8			ifs_clm_tx_ratio;
186 	u8			ifs_clm_edcca_excl_cca_ratio;
187 	u8			ifs_clm_fa_ratio;
188 	u8			ifs_clm_cca_excl_fa_ratio;
189 };
190 
191 struct nhm_para_info {
192 	enum nhm_option_txon_all	incld_txon;	/*@Include TX on*/
193 	enum nhm_option_cca_all		incld_cca;	/*@Include CCA*/
194 	enum nhm_divider_opt_all	div_opt;	/*@divider option*/
195 	enum nhm_application		nhm_app;
196 	enum phydm_nhm_level		nhm_lv;
197 	u16				mntr_time;	/*@0~262 unit ms*/
198 	boolean				en_1db_mode;
199 	u8				nhm_th0_manual;	/* for 1-db mode*/
200 };
201 
202 struct clm_para_info {
203 	enum clm_application		clm_app;
204 	enum phydm_clm_level		clm_lv;
205 	u16				mntr_time;	/*@0~262 unit ms*/
206 };
207 
208 struct ifs_clm_para_info {
209 	enum ifs_clm_application	ifs_clm_app;
210 	enum phydm_ifs_clm_level	ifs_clm_lv;
211 	enum phydm_ifs_clm_unit		ifs_clm_ctrl_unit;	/*unit*/
212 	u16				mntr_time;	/*ms*/
213 	boolean				ifs_clm_th_en[IFS_CLM_NUM];
214 	u16				ifs_clm_th_low[IFS_CLM_NUM];
215 	u16				ifs_clm_th_high[IFS_CLM_NUM];
216 	s16				th_shift;
217 };
218 
219 struct ccx_info {
220 	u32			nhm_trigger_time;
221 	u32			clm_trigger_time;
222 	u32			ifs_clm_trigger_time;
223 	u64			start_time;	/*@monitor for the test duration*/
224 #ifdef NHM_SUPPORT
225 	enum nhm_application		nhm_app;
226 	enum nhm_option_txon_all	nhm_include_txon;
227 	enum nhm_option_cca_all		nhm_include_cca;
228 	enum nhm_divider_opt_all 	nhm_divider_opt;
229 	/*Report*/
230 	u8			nhm_th[NHM_TH_NUM];
231 	u8			nhm_result[NHM_RPT_NUM];
232 	u16			nhm_period;	/* @4us per unit */
233 	u8			nhm_igi;
234 	u8			nhm_manual_ctrl;
235 	u8			nhm_ratio;	/*@1% per nuit, it means the interference igi can't overcome.*/
236 	u8			nhm_rpt_sum;
237 	u16			nhm_duration;	/*@Real time of NHM_VALID */
238 	u8			nhm_set_lv;
239 	boolean			nhm_ongoing;
240 	u8			nhm_rpt_stamp;
241 	u8			nhm_level; /*including r[0]~r[10]*/
242 	u8			nhm_level_valid;
243 	u8			nhm_pwr; /*including r[0]~r[11]*/
244 #ifdef NHM_DYM_PW_TH_SUPPORT
245 	boolean			nhm_dym_pw_th_en;
246 	boolean			dym_pwth_manual_ctrl;
247 	u8			pw_th_rf20_ori;
248 	u8			pw_th_rf20_cur;
249 	u8			nhm_pw_th_max;
250 	u8			nhm_period_decre;
251 	u8			nhm_sl_pw_th;
252 #endif
253 #endif
254 
255 #ifdef CLM_SUPPORT
256 	enum clm_application	clm_app;
257 	u8			clm_manual_ctrl;
258 	u8			clm_set_lv;
259 	boolean			clm_ongoing;
260 	u16			clm_period;	/* @4us per unit */
261 	u16			clm_result;
262 	u8			clm_ratio;
263 	u32			clm_fw_result_acc;
264 	u8			clm_fw_result_cnt;
265 	enum clm_monitor_mode	clm_mntr_mode;
266 	u8			clm_rpt_stamp;
267 #endif
268 #ifdef FAHM_SUPPORT
269 	boolean			fahm_ongoing;
270 	u8			env_mntr_igi;
271 	u8			fahm_nume_sel;	/*@fahm_numerator_sel: select {FA, CRCOK, CRC_fail} */
272 	u8			fahm_denom_sel;	/*@fahm_denominator_sel: select {FA, CRCOK, CRC_fail} */
273 	u16			fahm_period;	/*unit: 4us*/
274 #endif
275 #ifdef IFS_CLM_SUPPORT
276 	enum ifs_clm_application	ifs_clm_app;
277 	/*Control*/
278 	enum phydm_ifs_clm_unit ifs_clm_ctrl_unit; /*4,8,12,16us per unit*/
279 	u16			ifs_clm_period;
280 	boolean			ifs_clm_th_en[IFS_CLM_NUM];
281 	u16			ifs_clm_th_low[IFS_CLM_NUM];
282 	u16			ifs_clm_th_high[IFS_CLM_NUM];
283 	/*Flow control*/
284 	u8			ifs_clm_set_lv;
285 	u8			ifs_clm_manual_ctrl;
286 	boolean			ifs_clm_ongoing;
287 	/*Report*/
288 	u8			ifs_clm_rpt_stamp;
289 	u16			ifs_clm_tx;
290 	u16			ifs_clm_edcca_excl_cca;
291 	u16			ifs_clm_ofdmfa;
292 	u16			ifs_clm_ofdmcca_excl_fa;
293 	u16			ifs_clm_cckfa;
294 	u16			ifs_clm_cckcca_excl_fa;
295 	u8			ifs_clm_his[IFS_CLM_NUM];	/*trx_neg_edge to CCA/FA posedge per times*/
296 	u16			ifs_clm_total_cca;
297 	u16			ifs_clm_avg[IFS_CLM_NUM];	/*4,8,12,16us per unit*/
298 	u16			ifs_clm_avg_cca[IFS_CLM_NUM];	/*4,8,12,16us per unit*/
299 	u8			ifs_clm_tx_ratio;
300 	u8			ifs_clm_edcca_excl_cca_ratio;
301 	u8			ifs_clm_fa_ratio;
302 	u8			ifs_clm_cca_excl_fa_ratio;
303 #endif
304 };
305 
306 /* @1 ============================================================
307  * 1 Function Prototype
308  * 1 ============================================================
309  */
310 
311 #ifdef FAHM_SUPPORT
312 void phydm_fahm_init(void *dm_void);
313 
314 void phydm_fahm_dbg(void *dm_void, char input[][16], u32 *_used, char *output,
315 		    u32 *_out_len);
316 #endif
317 
318 #ifdef NHM_SUPPORT
319 void phydm_nhm_dbg(void *dm_void, char input[][16], u32 *_used, char *output,
320 		   u32 *_out_len);
321 u8 phydm_get_igi(void *dm_void, enum bb_path path);
322 #endif
323 
324 #ifdef CLM_SUPPORT
325 void phydm_clm_c2h_report_handler(void *dm_void, u8 *cmd_buf, u8 cmd_len);
326 
327 void phydm_clm_dbg(void *dm_void, char input[][16], u32 *_used, char *output,
328 		   u32 *_out_len);
329 #endif
330 
331 u8 phydm_env_mntr_trigger(void *dm_void, struct nhm_para_info *nhm_para,
332 			  struct clm_para_info *clm_para,
333 			  struct env_trig_rpt *rpt);
334 
335 u8 phydm_env_mntr_result(void *dm_void, struct env_mntr_rpt *rpt);
336 
337 void phydm_env_mntr_watchdog(void *dm_void);
338 
339 void phydm_env_monitor_init(void *dm_void);
340 
341 void phydm_env_mntr_dbg(void *dm_void, char input[][16], u32 *_used,
342 			char *output, u32 *_out_len);
343 
344 #ifdef IFS_CLM_SUPPORT
345 void phydm_ifs_clm_dbg(void *dm_void, char input[][16], u32 *_used,
346 		       char *output, u32 *_out_len);
347 #endif
348 
349 u8 phydm_enhance_mntr_trigger(void *dm_void,
350 			      struct ifs_clm_para_info *ifs_clm_para,
351 			      struct enhance_mntr_trig_rpt *trig_rpt);
352 
353 void phydm_enhance_mntr_result(void *dm_void, struct enhance_mntr_rpt *rpt);
354 
355 void phydm_enhance_mntr_watchdog(void *dm_void);
356 
357 void phydm_enhance_monitor_init(void *dm_void);
358 #endif
359