xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/phl/test/phl_dbg_cmd.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 - 2020 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  * Author: vincent_fann@realtek.com
15  *
16  *****************************************************************************/
17 #define _PHL_DBG_CMD_C_
18 #include "phl_dbg_cmd.h"
19 #include "phl_ps_dbg_cmd.h"
20 
21 /*
22  * proc debug command of core
23  */
24 enum PHL_DBG__CORE_CMD_ID {
25 	PHL_DBG_CORE_HELP,
26 	PHL_DBG_CORE_GIT_INFO
27 };
28 
29 static const struct phl_dbg_cmd_info phl_dbg_core_cmd_i[] = {
30 	{"git_info", PHL_DBG_CORE_GIT_INFO}
31 };
32 
phl_dbg_git_info(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)33 void phl_dbg_git_info(struct phl_info_t *phl_info, char input[][MAX_ARGV],
34 		      u32 input_num, char *output, u32 out_len)
35 {
36 /* #REMOVE BEGIN */
37 #if CONFIG_GEN_GIT_INFO
38 #include "../phl_git_info.h"
39 
40 	u32 used = 0;
41 
42 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
43 		"\ncore_ver   : %s\n", RTK_CORE_TAGINFO);
44 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
45 		"phl_ver    : %s\n", RTK_PHL_TAGINFO);
46 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
47 		"halmac_ver : %s\n", RTK_HALMAC_TAGINFO);
48 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
49 		"halbb_ver  : %s\n", RTK_HALBB_TAGINFO);
50 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
51 		"halrf_ver  : %s\n", RTK_HALRF_TAGINFO);
52 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
53 		"btc_ver    : %s\n", RTK_BTC_TAGINFO);
54 
55 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
56 		"\ncore_sha1  : %s\n", RTK_CORE_SHA1);
57 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
58 		"phl_sha1   : %s\n", RTK_PHL_SHA1);
59 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
60 		"halmac_sha1: %s\n", RTK_HALMAC_SHA1);
61 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
62 		"halbb_sha1 : %s\n", RTK_HALBB_SHA1);
63 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
64 		"halrf_sha1 : %s\n", RTK_HALRF_SHA1);
65 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
66 		"btc_sha1   : %s\n", RTK_BTC_SHA1);
67 #endif /* CONFIG_GEN_GIT_INFO */
68 /* #REMOVE END */
69 }
70 
phl_dbg_core_cmd_parser(void * phl,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)71 void phl_dbg_core_cmd_parser(void *phl, char input[][MAX_ARGV],
72 		        u32 input_num, char *output, u32 out_len)
73 {
74 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
75 	u8 id = 0;
76 	u32 i;
77 	u32 used = 0;
78 	u32 phl_ary_size = sizeof(phl_dbg_core_cmd_i) /
79 			   sizeof(struct phl_dbg_cmd_info);
80 
81 	if (phl_ary_size == 0)
82 		return;
83 
84 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used, "\n");
85 	/* Parsing Cmd ID */
86 	if (input_num) {
87 		for (i = 0; i < phl_ary_size; i++) {
88 			if (_os_strcmp(phl_dbg_core_cmd_i[i].name, input[0]) == 0) {
89 				id = phl_dbg_core_cmd_i[i].id;
90 				PHL_INFO("[%s]===>\n", phl_dbg_core_cmd_i[i].name);
91 				break;
92 			}
93 		}
94 		if (i == phl_ary_size) {
95 			PHL_DBG_MON_INFO(out_len, used, output + used,
96 				out_len - used, "PHL CMD not found!\n");
97 			return;
98 		}
99 	}
100 
101 	switch (id) {
102 	case PHL_DBG_CORE_HELP:
103 	{
104 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
105 				 "phl_dbg_core_cmd_parser : PHL_DBG_CORE_HELP \n");
106 		for (i = 0; i < phl_ary_size - 2; i++)
107 			PHL_DBG_MON_INFO(out_len, used, output + used,
108 					 out_len - used, "%-5d: %s\n",
109 			          (int)i, phl_dbg_core_cmd_i[i + 2].name);
110 
111 	}
112 	break;
113 	case PHL_DBG_CORE_GIT_INFO:
114 	{
115 		phl_dbg_git_info(phl_info, input, input_num, output, out_len);
116 	}
117 	break;
118 	default:
119 		PHL_DBG_MON_INFO(out_len, used, output + used,
120 			out_len - used, "[DBG] Do not support this command\n");
121 		break;
122 	}
123 }
124 
125 s32
phl_dbg_core_proc_cmd(struct phl_info_t * phl_info,char * input,char * output,u32 out_len)126 phl_dbg_core_proc_cmd(struct phl_info_t *phl_info,
127 		 char *input, char *output, u32 out_len)
128 {
129 	char *token;
130 	u32 argc = 0;
131 	char argv[MAX_ARGC][MAX_ARGV];
132 
133 	do {
134 		token = _os_strsep(&input, ", ");
135 		if (token) {
136 			if (_os_strlen((u8 *)token) <= MAX_ARGV)
137 				_os_strcpy(argv[argc], token);
138 
139 			argc++;
140 		} else {
141 			break;
142 		}
143 	} while (argc < MAX_ARGC);
144 
145 	if (argc == 1)
146 		argv[0][_os_strlen((u8 *)argv[0])] = '\0';
147 
148 	phl_dbg_core_cmd_parser(phl_info, argv, argc, output, out_len);
149 
150 	return 0;
151 }
152 
153 enum rtw_phl_status
rtw_phl_dbg_core_cmd(struct phl_info_t * phl_info,struct rtw_proc_cmd * incmd,char * output,u32 out_len)154 rtw_phl_dbg_core_cmd(struct phl_info_t *phl_info,
155 		     struct rtw_proc_cmd *incmd,
156 		     char *output,
157 		     u32 out_len)
158 {
159 	if (incmd->in_type == RTW_ARG_TYPE_BUF) {
160 		phl_dbg_core_proc_cmd(phl_info, incmd->in.buf, output, out_len);
161 	} else if(incmd->in_type == RTW_ARG_TYPE_ARRAY){
162 		phl_dbg_core_cmd_parser(phl_info, incmd->in.vector,
163 				   incmd->in_cnt_len, output, out_len);
164 	}
165 	return RTW_PHL_STATUS_SUCCESS;
166 }
167 
168 #ifdef CONFIG_PHL_TEST_SUITE
169 bool
_is_hex_digit(char ch_tmp)170 _is_hex_digit(char ch_tmp)
171 {
172 	if( (ch_tmp >= '0' && ch_tmp <= '9') ||
173 		(ch_tmp >= 'a' && ch_tmp <= 'f') ||
174 		(ch_tmp >= 'A' && ch_tmp <= 'F') ) {
175 		return true;
176 	} else {
177 		return false;
178 	}
179 }
180 
181 
182 u32
_map_char_to_hex_digit(char ch_tmp)183 _map_char_to_hex_digit(char ch_tmp)
184 {
185 	if(ch_tmp >= '0' && ch_tmp <= '9')
186 		return (ch_tmp - '0');
187 	else if(ch_tmp >= 'a' && ch_tmp <= 'f')
188 		return (10 + (ch_tmp - 'a'));
189 	else if(ch_tmp >= 'A' && ch_tmp <= 'F')
190 		return (10 + (ch_tmp - 'A'));
191 	else
192 		return 0;
193 }
194 
195 
196 bool
_get_hex_from_string(char * szstr,u32 * val)197 _get_hex_from_string(char *szstr, u32 *val)
198 {
199 	char *sz_scan = szstr;
200 
201 	/* Check input parameter.*/
202 	if (szstr == NULL || val == NULL) {
203 		PHL_TRACE(COMP_PHL_DBG, _PHL_WARNING_,
204 			"_get_hex_from_string(): Invalid inpur argumetns! szStr: %p, pu4bVal: %p \n",
205 			 szstr, val);
206 		return false;
207 	}
208 
209 	/* Initialize output. */
210 	*val = 0;
211 
212 	/* Skip leading space. */
213 	while(*sz_scan != '\0' && (*sz_scan == ' ' || *sz_scan == '\t')) {
214 		sz_scan++;
215 	}
216 
217 	/* Skip leading '0x' or '0X'. */
218 	if (*sz_scan == '0' && (*(sz_scan+1) == 'x' || *(sz_scan+1) == 'X')) {
219 		sz_scan += 2;
220 	}
221 
222 	if (!_is_hex_digit(*sz_scan)) {
223 		return false;
224 	}
225 
226 	do {
227 		(*val) <<= 4;
228 		*val += _map_char_to_hex_digit(*sz_scan);
229 
230 		sz_scan++;
231 	} while (_is_hex_digit(*sz_scan));
232 
233 	return true;
234 }
235 
236 void
_phl_dbg_cmd_switch_chbw(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)237 _phl_dbg_cmd_switch_chbw(struct phl_info_t *phl_info, char input[][MAX_ARGV],
238 			 u32 input_num, char *output, u32 out_len)
239 {
240 	u32 band = 0;
241 	u32 bw = 0;
242 	u32 offset = 0;
243 	u32 ch = 36;
244 	u32 used = 0;
245 	struct rtw_chan_def chdef = {0};
246 
247 	do {
248 		if (input_num < 5){
249 			PHL_DBG_MON_INFO(out_len, used, output + used,
250 					 out_len - used,
251 					 "\n[DBG] echo phl set_ch [band(0,1)] [ch(hex)] [bw(0,1,2,3)] [offset(0,1,2,3)]\n");
252 			break;
253 		}
254 
255 		if (!_get_hex_from_string(input[1], &band))
256 			break;
257 
258 		if (band > 1)
259 			break;
260 
261 		if (!_get_hex_from_string(input[2], &ch))
262 			break;
263 
264 
265 		if (!_get_hex_from_string(input[3], &bw))
266 			break;
267 
268 
269 		if (!_get_hex_from_string(input[4], &offset))
270 			break;
271 
272 		PHL_DBG_MON_INFO(out_len, used, output + used,
273 				 out_len - used,
274 				 "\n[DBG] PHL_DBG_SET_CH_BW ==> band = %d\n",
275 				 (int)band);
276 		PHL_DBG_MON_INFO(out_len, used, output + used,
277 				 out_len - used,
278 				 "[DBG] PHL_DBG_SET_CH_BW ==> ch = %d\n",
279 				 (int)ch);
280 		PHL_DBG_MON_INFO(out_len, used, output + used,
281 				 out_len - used,
282 				 "[DBG] PHL_DBG_SET_CH_BW ==> bw = %d\n",
283 				 (int)bw);
284 		PHL_DBG_MON_INFO(out_len, used, output + used,
285 				 out_len - used,
286 				 "[DBG] PHL_DBG_SET_CH_BW ==> offset = %d\n",
287 				 (int)offset);
288 
289 		chdef.chan = (u8)ch;
290 		chdef.band = rtw_phl_get_band_type(chdef.chan);
291 		chdef.bw = (enum channel_width)bw;
292 		chdef.offset = (enum chan_offset)offset;
293 
294 		rtw_hal_set_ch_bw(phl_info->hal, (u8)band, &chdef, false);
295 
296 	} while (0);
297 }
298 
_dump_wifi_role(struct phl_info_t * phl_info,char * output,u32 out_len)299 void _dump_wifi_role(struct phl_info_t *phl_info, char *output, u32 out_len)
300 {
301 	struct rtw_wifi_role_t *wrole = NULL;
302 	struct rtw_phl_stainfo_t *sta_info = NULL;
303 	u32 used = 0;
304 	u8 j = 0;
305 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
306 				"==> PHL_DBG_DUMP_WROLE CH/BW information\n");
307 	for( j = 0; j < MAX_WIFI_ROLE_NUMBER; j++) {
308 		wrole = rtw_phl_get_wrole_by_ridx(phl_info->phl_com, j);
309 		if (NULL == wrole)
310 			continue;
311 		PHL_DBG_MON_INFO(out_len, used, output + used,
312 				 out_len - used, "wrole idx = 0x%x \n", j);
313 		PHL_DBG_MON_INFO(out_len, used, output + used,
314 				 out_len - used, "wrole->type = 0x%x \n",
315 				 wrole->type);
316 		/* debug_dump_mac_addr(wrole->mac_addr); */
317 		PHL_DBG_MON_INFO(out_len, used, output + used,
318 				 out_len - used, "wrole->chandef.bw = 0x%x \n",
319 				 wrole->chandef.bw);
320 		PHL_DBG_MON_INFO(out_len, used, output + used,
321 				 out_len - used, "wrole->chandef.band = 0x%x \n",
322 				 wrole->chandef.band);
323 		PHL_DBG_MON_INFO(out_len, used, output + used,
324 				 out_len - used, "wrole->chandef.center_ch = 0x%x \n",
325 				 wrole->chandef.center_ch);
326 		PHL_DBG_MON_INFO(out_len, used, output + used,
327 				 out_len - used, "wrole->chandef.chan = 0x%x \n",
328 				 wrole->chandef.chan);
329 		PHL_DBG_MON_INFO(out_len, used, output + used,
330 				 out_len - used, "wrole->chandef.center_freq1 = %u \n",
331 				 (int)wrole->chandef.center_freq1);
332 		PHL_DBG_MON_INFO(out_len, used, output + used,
333 				 out_len - used, "wrole->chandef.center_freq2 = %u \n",
334 				 (int)wrole->chandef.center_freq2);
335 		PHL_DBG_MON_INFO(out_len, used, output + used,
336 				 out_len - used, "wrole->chandef.offset = 0x%x \n",
337 				 wrole->chandef.offset);
338 
339 		sta_info = rtw_phl_get_stainfo_self(phl_info, wrole);
340 		if (NULL == sta_info)
341 			continue;
342 		PHL_DBG_MON_INFO(out_len, used, output + used,
343 				 out_len - used, "sta_info->macid = 0x%x \n",
344 				 sta_info->macid);
345 		PHL_DBG_MON_INFO(out_len, used, output + used,
346 				 out_len - used, "sta_info->aid = 0x%x \n",
347 				 sta_info->aid);
348 		PHL_DBG_MON_INFO(out_len, used, output + used,
349 				 out_len - used, "mac_addr : %02x-%02x-%02x-%02x-%02x-%02x- \n",
350 				 sta_info->mac_addr[0], sta_info->mac_addr[1],
351 				 sta_info->mac_addr[2], sta_info->mac_addr[3],
352 				 sta_info->mac_addr[4], sta_info->mac_addr[5]);
353 		PHL_DBG_MON_INFO(out_len, used, output + used,
354 				 out_len - used, "sta_info->wmode = 0x%x \n",
355 				 sta_info->wmode);
356 		PHL_DBG_MON_INFO(out_len, used, output + used,
357 					out_len - used, "-----------------------------\n");
358 	}
359 }
360 
_dump_rx_rate(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)361 void _dump_rx_rate(struct phl_info_t *phl_info, char input[][MAX_ARGV],
362 		      u32 input_num, char *output, u32 out_len)
363 {
364 	u32 ctrl = 0;
365 	u32 used = 0;
366 	struct rtw_stats *rx_stat = &phl_info->phl_com->phl_stats;
367 	if(input_num < 2)
368 		return;
369 	_get_hex_from_string(input[1], &ctrl);
370 
371 	if (ctrl == 2) {
372 		/*TODO: Clear Counter*/
373 		return;
374 	}
375 
376 	PHL_DBG_MON_INFO(out_len, used, output + used,
377 			out_len - used, "\nOFDM 6M = %d ; OFDM 24M = %d ; OFDM 54M = %d\n",
378 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_OFDM6],
379 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_OFDM24],
380 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_OFDM54]);
381 
382 	PHL_DBG_MON_INFO(out_len, used, output + used,
383 			out_len - used, "VHT 1SS\
384 			\nMCS0 = %d ; MCS1 = %d ; MCS2 = %d ;\
385 			\nMCS3 = %d ; MCS4 = %d ; MCS5 = %d ;\
386 			\nMCS6 = %d ; MCS7 = %d ; MCS8 = %d ;\
387 			\nMCS9 = %d ;\n",
388 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS0],
389 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS1],
390 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS2],
391 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS3],
392 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS4],
393 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS5],
394 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS6],
395 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS7],
396 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS8],
397 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS1_MCS9]
398 			);
399 	PHL_DBG_MON_INFO(out_len, used, output + used,
400 			out_len - used, "VHT 2SS\
401 			\nMCS0 = %d ; MCS1 = %d ; MCS2 = %d ;\
402 			\nMCS3 = %d ; MCS4 = %d ; MCS5 = %d ;\
403 			\nMCS6 = %d ; MCS7 = %d ; MCS8 = %d ;\
404 			\nMCS9 = %d ;\n",
405 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS0],
406 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS1],
407 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS2],
408 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS3],
409 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS4],
410 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS5],
411 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS6],
412 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS7],
413 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS8],
414 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_VHT_NSS2_MCS9]
415 			);
416 	PHL_DBG_MON_INFO(out_len, used, output + used,
417 			out_len - used, "HE 1SS\
418 			\nMCS0 = %d ; MCS1 = %d ; MCS2 = %d ;\
419 			\nMCS3 = %d ; MCS4 = %d ; MCS5 = %d ;\
420 			\nMCS6 = %d ; MCS7 = %d ; MCS8 = %d ;\
421 			\nMCS9 = %d ; MCS10 = %d ; MCS11 = %d;\n",
422 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS0],
423 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS1],
424 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS2],
425 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS3],
426 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS4],
427 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS5],
428 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS6],
429 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS7],
430 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS8],
431 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS9],
432 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS10],
433 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS1_MCS11]);
434 	PHL_DBG_MON_INFO(out_len, used, output + used,
435 			out_len - used, "HE 2SS\
436 			\nMCS0 = %d ; MCS1 = %d ; MCS2 = %d ;\
437 			\nMCS3 = %d ; MCS4 = %d ; MCS5 = %d ;\
438 			\nMCS6 = %d ; MCS7 = %d ; MCS8 = %d ;\
439 			\nMCS9 = %d ; MCS10 = %d ; MCS11 = %d ;\n",
440 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS0],
441 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS1],
442 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS2],
443 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS3],
444 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS4],
445 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS5],
446 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS6],
447 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS7],
448 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS8],
449 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS9],
450 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS10],
451 			(int)rx_stat->rx_rate_nmr[RTW_DATA_RATE_HE_NSS2_MCS11]
452 			);
453 
454 }
455 
_get_mac_pwr_st_str(enum rtw_mac_pwr_st st)456 static const char *_get_mac_pwr_st_str(enum rtw_mac_pwr_st st)
457 {
458 	switch (st) {
459 	case RTW_MAC_PWR_OFF:
460 		return "off";
461 	case RTW_MAC_PWR_ON:
462 		return "on";
463 	case RTW_MAC_PWR_LPS:
464 		return "lps";
465 	default:
466 		return "n/a";
467 	}
468 }
469 
_get_wow_opmode_str(enum rtw_wow_op_mode mode)470 static const char *_get_wow_opmode_str(enum rtw_wow_op_mode mode)
471 {
472 	switch (mode) {
473 	case RTW_WOW_OP_PWR_DOWN:
474 		return "power down";
475 	case RTW_WOW_OP_DISCONNECT_STBY:
476 		return "disconnected standby";
477 	case RTW_WOW_OP_CONNECT_STBY:
478 		return "connected standby";
479 	default:
480 		return "n/a";
481 	}
482 }
483 
_dump_wow_stats(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)484 void _dump_wow_stats(struct phl_info_t *phl_info, char input[][MAX_ARGV],
485 	u32 input_num, char *output, u32 out_len)
486 {
487 #ifdef CONFIG_WOWLAN
488 	struct phl_wow_info *wow_info = phl_to_wow_info(phl_info);
489 	struct phl_wow_stat *wow_stat = &wow_info->wow_stat;
490 	u32 used = 0;
491 
492 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
493 					 "\n%-20s : op_mode = %s, func_en = %s, mac pwr = %s, wake_rsn = %s\
494 					 \n%-20s : keep_alive_en = %d, disc_det_en = %d, arp_en = %d, ndp_en = %d, gtk_en = %d, dot11w_en = %d\
495 					 \n%-20s : init err = 0x%x, deinit err = 0x%x\
496 					 \n%-20s : aoac_rpt_fail_cnt = 0x%x\n",
497 	"[wow information]",
498 	_get_wow_opmode_str(wow_stat->op_mode), (wow_stat->func_en == 1 ? "yes" : "no"),
499 	_get_mac_pwr_st_str(wow_stat->mac_pwr), rtw_phl_get_wow_rsn_str(phl_info, wow_stat->wake_rsn),
500 	"[wow function]",
501 	wow_stat->keep_alive_en, wow_stat->disc_det_en, wow_stat->arp_en, wow_stat->ndp_en, wow_stat->gtk_en, wow_stat->dot11w_en,
502 	"[wow error]",
503 	wow_stat->err.init, wow_stat->err.deinit,
504 	"[wow aoac]",
505 	wow_stat->aoac_rpt_fail_cnt);
506 #endif /* CONFIG_WOWLAN */
507 }
508 
509 #ifdef CONFIG_MCC_SUPPORT
_dump_mcc_info(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)510 void _dump_mcc_info(struct phl_info_t *phl_info, char input[][MAX_ARGV],
511 	u32 input_num, char *output, u32 out_len)
512 {
513 	bool get_ok = false;
514 	struct rtw_phl_mcc_en_info en_info = {0};
515 	enum rtw_phl_tdmra_wmode mcc_mode;
516 	enum rtw_phl_mcc_state state;
517 	enum rtw_phl_mcc_coex_mode coex_mode;
518 	struct rtw_phl_mcc_bt_info bt_info = {0};
519 	struct rtw_phl_mcc_role *mrole = NULL;
520 	struct rtw_chan_def *chdef = NULL;
521 	struct rtw_phl_mcc_dur_info *dur_i = NULL;
522 	struct rtw_phl_mcc_pattern *m_pattern = NULL;
523 	struct rtw_phl_mcc_dbg_slot_info *dbg_slot_i = NULL;
524 	u32 used = 0;
525 	u8 i = 0;
526 
527 	get_ok = rtw_phl_mcc_get_dbg_info(phl_info, 0, MCC_DBG_STATE, &state);
528 	if (false == get_ok) {
529 		PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "_dump_mcc_info(): get MCC_DBG_STATE fail\n");
530 		goto exit;
531 	}
532 	get_ok = rtw_phl_mcc_get_dbg_info(phl_info, 0, MCC_DBG_OP_MODE, &mcc_mode);
533 	if (false == get_ok) {
534 		PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "_dump_mcc_info(): get MCC_DBG_OP_MODE fail\n");
535 		goto exit;
536 	}
537 	get_ok = rtw_phl_mcc_get_dbg_info(phl_info, 0, MCC_DBG_COEX_MODE, &coex_mode);
538 	if (false == get_ok) {
539 		PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "_dump_mcc_info(): get MCC_DBG_COEX_MODE fail\n");
540 		goto exit;
541 	}
542 	PHL_DBG_MON_INFO(out_len, used, output + used,
543 			out_len - used, "\n======== MCC Info ========\n");
544 	PHL_DBG_MON_INFO(out_len, used, output + used,
545 			out_len - used, "MCC Info: State(%s, %d), Mode(%s, %d), Coex(%s, %d)\n",
546 			((state == MCC_NONE) ? "None" :
547 			((state == MCC_TRIGGER_FW_EN) ? "Trig_Fw_En" :
548 			((state == MCC_FW_EN_FAIL) ? "Fw_En_Fail" :
549 			((state == MCC_RUNING) ? "Runing" :
550 			((state == MCC_TRIGGER_FW_DIS) ? "Trig_Fw_Dis" :
551 			((state == MCC_FW_DIS_FAIL) ? "Fw_Dis_Fail" :
552 			((state == MCC_STOP) ? "Fw_Stop" : "Unknown"))))))),
553 			state,
554 			((mcc_mode == RTW_PHL_TDMRA_WMODE_NONE) ? "None" :
555 			((mcc_mode == RTW_PHL_TDMRA_AP_CLIENT_WMODE) ? "AP_Client" :
556 			((mcc_mode == RTW_PHL_TDMRA_2CLIENTS_WMODE) ? "2Clients" :
557 			((mcc_mode == RTW_PHL_TDMRA_AP_WMODE) ? "AP" : "Unknown")))),
558 			mcc_mode,
559 			((coex_mode == RTW_PHL_MCC_COEX_MODE_NONE) ? "None" :
560 			((coex_mode == RTW_PHL_MCC_COEX_MODE_BT_MASTER) ? "BT_M" :
561 			((coex_mode == RTW_PHL_MCC_COEX_MODE_WIFI_MASTER) ? "Wifi_M" :
562 			((coex_mode == RTW_PHL_MCC_COEX_MODE_BT_WIFI_BALANCE) ? "Balance" : "Unknown")))),
563 			coex_mode);
564 	get_ok = rtw_phl_mcc_get_dbg_info(phl_info, 0, MCC_DBG_BT_INFO, &bt_info);
565 	if (false == get_ok) {
566 		PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "_dump_mcc_info(): get MCC_DBG_BT_INFO fail\n");
567 		goto exit;
568 	}
569 	if (bt_info.bt_seg_num <= BT_SEG_NUM) {
570 		PHL_DBG_MON_INFO(out_len, used, output + used,
571 				out_len - used, "MCC Info: Bt_dur(%d), Add_Bt_Role(%d), Seg_Num(%d), bt_seg[0](%d), bt_seg[1](%d)\n",
572 				bt_info.bt_dur, bt_info.add_bt_role,
573 				bt_info.bt_seg_num, bt_info.bt_seg[0],
574 				bt_info.bt_seg[1]);
575 	}
576 	get_ok = rtw_phl_mcc_get_dbg_info(phl_info, 0, MCC_DBG_EN_INFO, &en_info);
577 	if (false == get_ok) {
578 		PHL_TRACE(COMP_PHL_MCC, _PHL_ERR_, "_dump_mcc_info(): get MCC_DBG_EN_INFO fail\n");
579 		goto exit;
580 	}
581 	m_pattern = &en_info.m_pattern;
582 	PHL_DBG_MON_INFO(out_len, used, output + used,
583 				out_len - used, "MCC Info: mcc_intvl(%d), Start_tsf(0x%04x%04x %04x%04x), bcns_offset(%d), tob_r(%d), toa_r(%d), tob_a(%d), toa_a(%d)\n",
584 				en_info.mcc_intvl, (u16)(en_info.tsf_high >> 16),
585 				(u16)(en_info.tsf_high),
586 				(u16)(en_info.tsf_low >> 16),
587 				(u16)(en_info.tsf_low), m_pattern->bcns_offset,
588 				m_pattern->tob_r, m_pattern->toa_r,
589 				m_pattern->tob_a, m_pattern->toa_a);
590 	PHL_DBG_MON_INFO(out_len, used, output + used,
591 			out_len - used, "\n======== MCC Role Info ========\n");
592 	for (i = 0; i < en_info.mrole_num; i++) {
593 		mrole = &en_info.mcc_role[i];
594 		chdef = mrole->chandef;
595 		dur_i = &mrole->policy.dur_info;
596 		if (NULL == chdef)
597 			break;
598 		PHL_DBG_MON_INFO(out_len, used, output + used,
599 				out_len - used, "MCC Info: Role(%d): macid(0x%x), Bcn_intvl(%d), band(%d), chan(%d), center_ch(%d), bw(%d), offset(%d)\n",
600 				i, mrole->macid, mrole->bcn_intvl, chdef->band,
601 				chdef->chan, chdef->center_ch, chdef->bw,
602 				chdef->offset);
603 		PHL_DBG_MON_INFO(out_len, used, output + used,
604 				out_len - used, "MCC Info: Role(%d): dur(0x%x), lim_en(%d), tag(%d), max_dur(%d), max_toa(%d), max_tob(%d)\n\n",
605 				i, dur_i->dur, dur_i->dur_limit.enable,
606 				dur_i->dur_limit.tag, dur_i->dur_limit.max_dur,
607 				dur_i->dur_limit.max_toa,
608 				dur_i->dur_limit.max_tob);
609 	}
610 	PHL_DBG_MON_INFO(out_len, used, output + used,
611 			out_len - used, "======== Hal MCC Info ========\n");
612 	PHL_DBG_MON_INFO(out_len, used, output + used,
613 			out_len - used, "MCC Info: btc_in_group(%d)\n",
614 			en_info.dbg_hal_i.btc_in_group);
615 	for (i = 0; i < en_info.dbg_hal_i.slot_num; i++) {
616 		dbg_slot_i = &en_info.dbg_hal_i.dbg_slot_i[i];
617 		PHL_DBG_MON_INFO(out_len, used, output + used,
618 				out_len - used, "MCC Info: FW Slot(%d), BT_Role(%d), Dur(%d), Ch(%d), Macid(0x%x)\n",
619 				i, dbg_slot_i->bt_role, dbg_slot_i->dur,
620 				dbg_slot_i->ch, dbg_slot_i->macid);
621 	}
622 exit:
623 	return;
624 }
625 #endif
phl_dbg_cmd_snd(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)626 void phl_dbg_cmd_snd(struct phl_info_t *phl_info, char input[][MAX_ARGV],
627 		      u32 input_num, char *output, u32 out_len)
628 {
629 	u32 role_idx;
630 	u32 ctrl;
631 	u32 used = 0;
632 
633 	if (input_num < 2)
634 		return;
635 
636 	_get_hex_from_string(input[1], &ctrl);
637 	_get_hex_from_string(input[2], &role_idx);
638 
639 	PHL_DBG_MON_INFO(out_len, used, output + used,
640 			 out_len - used, "ctrl 0x%x with role_idx 0x%x!!\n",
641 			 (int)ctrl, (int)role_idx);
642 
643 	if (1 == ctrl) {
644 		rtw_phl_sound_start(phl_info, (u8)role_idx, 0, 200,
645 				    PHL_SND_TEST_F_ONE_TIME |
646 				    PHL_SND_TEST_F_PASS_STS_CHK);
647 		PHL_DBG_MON_INFO(out_len, used, output + used,
648 			out_len - used, "SOUND START(once) : wrole %d !!\n", (int)role_idx);
649 	} else if (2 == ctrl) {
650 		rtw_phl_sound_abort(phl_info);
651 		PHL_DBG_MON_INFO(out_len, used, output + used,
652 			out_len - used, "SOUND ABORT!!\n");
653 	} else if (3 == ctrl) {
654 		rtw_phl_sound_start(phl_info, (u8)role_idx, 0, 200,
655 				    PHL_SND_TEST_F_PASS_STS_CHK);
656 		PHL_DBG_MON_INFO(out_len, used, output + used,
657 			out_len - used, "SOUND START(loop) : wrole %d !!\n", (int)role_idx);
658 	} else if(9 == ctrl) {
659 		PHL_DBG_MON_INFO(out_len, used, output + used,
660 			out_len - used, "DUMP BF Entry in debugview\n");
661 			rtw_hal_bf_dbg_dump_entry_all(phl_info->hal);
662 	} else {
663 		PHL_DBG_MON_INFO(out_len, used, output + used,
664 			out_len - used, "SOUND TEST CMD not found!\n");
665 	}
666 }
667 
_convert_tx_rate(enum hal_rate_mode mode,u8 mcs_ss_idx,char * str,u32 str_len)668 void _convert_tx_rate(enum hal_rate_mode mode, u8 mcs_ss_idx, char *str, u32 str_len)
669 {
670 	switch (mode) {
671 	case HAL_LEGACY_MODE:
672 		switch (mcs_ss_idx) {
673 		case RTW_DATA_RATE_CCK1:	_os_snprintf(str, str_len,"CCK 1"); break;
674 		case RTW_DATA_RATE_CCK2:	_os_snprintf(str, str_len,"CCK 2"); break;
675 		case RTW_DATA_RATE_CCK5_5:	_os_snprintf(str, str_len,"CCK 5_5"); break;
676 		case RTW_DATA_RATE_CCK11:	_os_snprintf(str, str_len,"CCK 11"); break;
677 		case RTW_DATA_RATE_OFDM6:	_os_snprintf(str, str_len,"OFDM 6"); break;
678 		case RTW_DATA_RATE_OFDM9:	_os_snprintf(str, str_len,"OFDM 9"); break;
679 		case RTW_DATA_RATE_OFDM12:	_os_snprintf(str, str_len,"OFDM 12"); break;
680 		case RTW_DATA_RATE_OFDM18:	_os_snprintf(str, str_len,"OFDM 18"); break;
681 		case RTW_DATA_RATE_OFDM24:	_os_snprintf(str, str_len,"OFDM 24"); break;
682 		case RTW_DATA_RATE_OFDM36:	_os_snprintf(str, str_len,"OFDM 36"); break;
683 		case RTW_DATA_RATE_OFDM48:	_os_snprintf(str, str_len,"OFDM 48"); break;
684 		case RTW_DATA_RATE_OFDM54:	_os_snprintf(str, str_len,"OFDM 54"); break;
685 		default:
686 			_os_snprintf(str, str_len,"Unkown rate(0x%01x)", mcs_ss_idx);
687 			break;
688 		}
689 		break;
690 	case HAL_HT_MODE:
691 		_os_snprintf(str, str_len,"MCS%d", mcs_ss_idx);
692 		break;
693 	case HAL_VHT_MODE:
694 	case HAL_HE_MODE:
695 		_os_snprintf(str, str_len,"%dSS MCS%d",
696 		             ((mcs_ss_idx & 0x70)>> 4) + 1,
697 		             (mcs_ss_idx & 0x0F));
698 		break;
699 	default:
700 		_os_snprintf(str, str_len,"Unknown mode(0x%01x)", mode);
701 		break;
702 	}
703 }
704 
_convert_rx_rate(u32 rx_rate,char * str,u32 str_len)705 void _convert_rx_rate(u32 rx_rate, char *str, u32 str_len)
706 {
707 	switch(rx_rate) {
708 	case RTW_DATA_RATE_CCK1:	_os_snprintf(str, str_len,"CCK 1"); break;
709 	case RTW_DATA_RATE_CCK2:	_os_snprintf(str, str_len,"CCK 2"); break;
710 	case RTW_DATA_RATE_CCK5_5:	_os_snprintf(str, str_len,"CCK 5_5"); break;
711 	case RTW_DATA_RATE_CCK11:	_os_snprintf(str, str_len,"CCK 11"); break;
712 	case RTW_DATA_RATE_OFDM6:	_os_snprintf(str, str_len,"OFDM 6"); break;
713 	case RTW_DATA_RATE_OFDM9:	_os_snprintf(str, str_len,"OFDM 9"); break;
714 	case RTW_DATA_RATE_OFDM12:	_os_snprintf(str, str_len,"OFDM 12"); break;
715 	case RTW_DATA_RATE_OFDM18:	_os_snprintf(str, str_len,"OFDM 18"); break;
716 	case RTW_DATA_RATE_OFDM24:	_os_snprintf(str, str_len,"OFDM 24"); break;
717 	case RTW_DATA_RATE_OFDM36:	_os_snprintf(str, str_len,"OFDM 36"); break;
718 	case RTW_DATA_RATE_OFDM48:	_os_snprintf(str, str_len,"OFDM 48"); break;
719 	case RTW_DATA_RATE_OFDM54:	_os_snprintf(str, str_len,"OFDM 54"); break;
720 
721 	case RTW_DATA_RATE_MCS0:	_os_snprintf(str, str_len,"MCS 0"); break;
722 	case RTW_DATA_RATE_MCS1:	_os_snprintf(str, str_len,"MCS 1"); break;
723 	case RTW_DATA_RATE_MCS2:	_os_snprintf(str, str_len,"MCS 2"); break;
724 	case RTW_DATA_RATE_MCS3:	_os_snprintf(str, str_len,"MCS 3"); break;
725 	case RTW_DATA_RATE_MCS4:	_os_snprintf(str, str_len,"MCS 4"); break;
726 	case RTW_DATA_RATE_MCS5:	_os_snprintf(str, str_len,"MCS 5"); break;
727 	case RTW_DATA_RATE_MCS6:	_os_snprintf(str, str_len,"MCS 6"); break;
728 	case RTW_DATA_RATE_MCS7:	_os_snprintf(str, str_len,"MCS 7"); break;
729 	case RTW_DATA_RATE_MCS8:	_os_snprintf(str, str_len,"MCS 8"); break;
730 	case RTW_DATA_RATE_MCS9:	_os_snprintf(str, str_len,"MCS 9"); break;
731 	case RTW_DATA_RATE_MCS10:	_os_snprintf(str, str_len,"MCS 10"); break;
732 	case RTW_DATA_RATE_MCS11:	_os_snprintf(str, str_len,"MCS 11"); break;
733 	case RTW_DATA_RATE_MCS12:	_os_snprintf(str, str_len,"MCS 12"); break;
734 	case RTW_DATA_RATE_MCS13:	_os_snprintf(str, str_len,"MCS 13"); break;
735 	case RTW_DATA_RATE_MCS14:	_os_snprintf(str, str_len,"MCS 14"); break;
736 	case RTW_DATA_RATE_MCS15:	_os_snprintf(str, str_len,"MCS 15"); break;
737 	case RTW_DATA_RATE_MCS16:	_os_snprintf(str, str_len,"MCS 16"); break;
738 	case RTW_DATA_RATE_MCS17:	_os_snprintf(str, str_len,"MCS 17"); break;
739 	case RTW_DATA_RATE_MCS18:	_os_snprintf(str, str_len,"MCS 18"); break;
740 	case RTW_DATA_RATE_MCS19:	_os_snprintf(str, str_len,"MCS 19"); break;
741 	case RTW_DATA_RATE_MCS20:	_os_snprintf(str, str_len,"MCS 20"); break;
742 	case RTW_DATA_RATE_MCS21:	_os_snprintf(str, str_len,"MCS 21"); break;
743 	case RTW_DATA_RATE_MCS22:	_os_snprintf(str, str_len,"MCS 22"); break;
744 	case RTW_DATA_RATE_MCS23:	_os_snprintf(str, str_len,"MCS 23"); break;
745 	case RTW_DATA_RATE_MCS24:	_os_snprintf(str, str_len,"MCS 24"); break;
746 	case RTW_DATA_RATE_MCS25:	_os_snprintf(str, str_len,"MCS 25"); break;
747 	case RTW_DATA_RATE_MCS26:	_os_snprintf(str, str_len,"MCS 26"); break;
748 	case RTW_DATA_RATE_MCS27:	_os_snprintf(str, str_len,"MCS 27"); break;
749 	case RTW_DATA_RATE_MCS28:	_os_snprintf(str, str_len,"MCS 28"); break;
750 	case RTW_DATA_RATE_MCS29:	_os_snprintf(str, str_len,"MCS 29"); break;
751 	case RTW_DATA_RATE_MCS30:	_os_snprintf(str, str_len,"MCS 30"); break;
752 	case RTW_DATA_RATE_MCS31:	_os_snprintf(str, str_len,"MCS 31"); break;
753 
754 	case RTW_DATA_RATE_VHT_NSS1_MCS0:	_os_snprintf(str, str_len,"NSS1_MCS0"); break;
755 	case RTW_DATA_RATE_VHT_NSS1_MCS1:	_os_snprintf(str, str_len,"NSS1_MCS1"); break;
756 	case RTW_DATA_RATE_VHT_NSS1_MCS2:	_os_snprintf(str, str_len,"NSS1_MCS2"); break;
757 	case RTW_DATA_RATE_VHT_NSS1_MCS3:	_os_snprintf(str, str_len,"NSS1_MCS3"); break;
758 	case RTW_DATA_RATE_VHT_NSS1_MCS4:	_os_snprintf(str, str_len,"NSS1_MCS4"); break;
759 	case RTW_DATA_RATE_VHT_NSS1_MCS5:	_os_snprintf(str, str_len,"NSS1_MCS5"); break;
760 	case RTW_DATA_RATE_VHT_NSS1_MCS6:	_os_snprintf(str, str_len,"NSS1_MCS6"); break;
761 	case RTW_DATA_RATE_VHT_NSS1_MCS7:	_os_snprintf(str, str_len,"NSS1_MCS7"); break;
762 	case RTW_DATA_RATE_VHT_NSS1_MCS8:	_os_snprintf(str, str_len,"NSS1_MCS8"); break;
763 	case RTW_DATA_RATE_VHT_NSS1_MCS9:	_os_snprintf(str, str_len,"NSS1_MCS9"); break;
764 	case RTW_DATA_RATE_VHT_NSS2_MCS0:	_os_snprintf(str, str_len,"NSS2_MCS0"); break;
765 	case RTW_DATA_RATE_VHT_NSS2_MCS1:	_os_snprintf(str, str_len,"NSS2_MCS1"); break;
766 	case RTW_DATA_RATE_VHT_NSS2_MCS2:	_os_snprintf(str, str_len,"NSS2_MCS2"); break;
767 	case RTW_DATA_RATE_VHT_NSS2_MCS3:	_os_snprintf(str, str_len,"NSS2_MCS3"); break;
768 	case RTW_DATA_RATE_VHT_NSS2_MCS4:	_os_snprintf(str, str_len,"NSS2_MCS4"); break;
769 	case RTW_DATA_RATE_VHT_NSS2_MCS5:	_os_snprintf(str, str_len,"NSS2_MCS5"); break;
770 	case RTW_DATA_RATE_VHT_NSS2_MCS6:	_os_snprintf(str, str_len,"NSS2_MCS6"); break;
771 	case RTW_DATA_RATE_VHT_NSS2_MCS7:	_os_snprintf(str, str_len,"NSS2_MCS7"); break;
772 	case RTW_DATA_RATE_VHT_NSS2_MCS8:	_os_snprintf(str, str_len,"NSS2_MCS8"); break;
773 	case RTW_DATA_RATE_VHT_NSS2_MCS9:	_os_snprintf(str, str_len,"NSS2_MCS9"); break;
774 
775 	case RTW_DATA_RATE_VHT_NSS3_MCS0:	_os_snprintf(str, str_len,"NSS3_MCS0"); break;
776 	case RTW_DATA_RATE_VHT_NSS3_MCS1:	_os_snprintf(str, str_len,"NSS3_MCS1"); break;
777 	case RTW_DATA_RATE_VHT_NSS3_MCS2:	_os_snprintf(str, str_len,"NSS3_MCS2"); break;
778 	case RTW_DATA_RATE_VHT_NSS3_MCS3:	_os_snprintf(str, str_len,"NSS3_MCS3"); break;
779 	case RTW_DATA_RATE_VHT_NSS3_MCS4:	_os_snprintf(str, str_len,"NSS3_MCS4"); break;
780 	case RTW_DATA_RATE_VHT_NSS3_MCS5:	_os_snprintf(str, str_len,"NSS3_MCS5"); break;
781 	case RTW_DATA_RATE_VHT_NSS3_MCS6:	_os_snprintf(str, str_len,"NSS3_MCS6"); break;
782 	case RTW_DATA_RATE_VHT_NSS3_MCS7:	_os_snprintf(str, str_len,"NSS3_MCS7"); break;
783 	case RTW_DATA_RATE_VHT_NSS3_MCS8:	_os_snprintf(str, str_len,"NSS3_MCS8"); break;
784 	case RTW_DATA_RATE_VHT_NSS3_MCS9:	_os_snprintf(str, str_len,"NSS3_MCS9"); break;
785 	case RTW_DATA_RATE_VHT_NSS4_MCS0:	_os_snprintf(str, str_len,"NSS4_MCS0"); break;
786 	case RTW_DATA_RATE_VHT_NSS4_MCS1:	_os_snprintf(str, str_len,"NSS4_MCS1"); break;
787 	case RTW_DATA_RATE_VHT_NSS4_MCS2:	_os_snprintf(str, str_len,"NSS4_MCS2"); break;
788 	case RTW_DATA_RATE_VHT_NSS4_MCS3:	_os_snprintf(str, str_len,"NSS4_MCS3"); break;
789 	case RTW_DATA_RATE_VHT_NSS4_MCS4:	_os_snprintf(str, str_len,"NSS4_MCS4"); break;
790 	case RTW_DATA_RATE_VHT_NSS4_MCS5:	_os_snprintf(str, str_len,"NSS4_MCS5"); break;
791 	case RTW_DATA_RATE_VHT_NSS4_MCS6:	_os_snprintf(str, str_len,"NSS4_MCS6"); break;
792 	case RTW_DATA_RATE_VHT_NSS4_MCS7:	_os_snprintf(str, str_len,"NSS4_MCS7"); break;
793 	case RTW_DATA_RATE_VHT_NSS4_MCS8:	_os_snprintf(str, str_len,"NSS4_MCS8"); break;
794 	case RTW_DATA_RATE_VHT_NSS4_MCS9:	_os_snprintf(str, str_len,"NSS4_MCS9"); break;
795 
796 	case RTW_DATA_RATE_HE_NSS1_MCS0:	_os_snprintf(str, str_len,"HE_NSS1_MCS0"); break;
797 	case RTW_DATA_RATE_HE_NSS1_MCS1:	_os_snprintf(str, str_len,"HE_NSS1_MCS1"); break;
798 	case RTW_DATA_RATE_HE_NSS1_MCS2:	_os_snprintf(str, str_len,"HE_NSS1_MCS2"); break;
799 	case RTW_DATA_RATE_HE_NSS1_MCS3:	_os_snprintf(str, str_len,"HE_NSS1_MCS3"); break;
800 	case RTW_DATA_RATE_HE_NSS1_MCS4:	_os_snprintf(str, str_len,"HE_NSS1_MCS4"); break;
801 	case RTW_DATA_RATE_HE_NSS1_MCS5:	_os_snprintf(str, str_len,"HE_NSS1_MCS5"); break;
802 	case RTW_DATA_RATE_HE_NSS1_MCS6:	_os_snprintf(str, str_len,"HE_NSS1_MCS6"); break;
803 	case RTW_DATA_RATE_HE_NSS1_MCS7:	_os_snprintf(str, str_len,"HE_NSS1_MCS7"); break;
804 	case RTW_DATA_RATE_HE_NSS1_MCS8:	_os_snprintf(str, str_len,"HE_NSS1_MCS8"); break;
805 	case RTW_DATA_RATE_HE_NSS1_MCS9:	_os_snprintf(str, str_len,"HE_NSS1_MCS9"); break;
806 	case RTW_DATA_RATE_HE_NSS1_MCS10:	_os_snprintf(str, str_len,"HE_NSS1_MCS10"); break;
807 	case RTW_DATA_RATE_HE_NSS1_MCS11:	_os_snprintf(str, str_len,"HE_NSS1_MCS11"); break;
808 
809 	case RTW_DATA_RATE_HE_NSS2_MCS0:	_os_snprintf(str, str_len,"HE_NSS2_MCS0"); break;
810 	case RTW_DATA_RATE_HE_NSS2_MCS1:	_os_snprintf(str, str_len,"HE_NSS2_MCS1"); break;
811 	case RTW_DATA_RATE_HE_NSS2_MCS2:	_os_snprintf(str, str_len,"HE_NSS2_MCS2"); break;
812 	case RTW_DATA_RATE_HE_NSS2_MCS3:	_os_snprintf(str, str_len,"HE_NSS2_MCS3"); break;
813 	case RTW_DATA_RATE_HE_NSS2_MCS4:	_os_snprintf(str, str_len,"HE_NSS2_MCS4"); break;
814 	case RTW_DATA_RATE_HE_NSS2_MCS5:	_os_snprintf(str, str_len,"HE_NSS2_MCS5"); break;
815 	case RTW_DATA_RATE_HE_NSS2_MCS6:	_os_snprintf(str, str_len,"HE_NSS2_MCS6"); break;
816 	case RTW_DATA_RATE_HE_NSS2_MCS7:	_os_snprintf(str, str_len,"HE_NSS2_MCS7"); break;
817 	case RTW_DATA_RATE_HE_NSS2_MCS8:	_os_snprintf(str, str_len,"HE_NSS2_MCS8"); break;
818 	case RTW_DATA_RATE_HE_NSS2_MCS9:	_os_snprintf(str, str_len,"HE_NSS2_MCS9"); break;
819 	case RTW_DATA_RATE_HE_NSS2_MCS10:	_os_snprintf(str, str_len,"HE_NSS2_MCS10"); break;
820 	case RTW_DATA_RATE_HE_NSS2_MCS11:	_os_snprintf(str, str_len,"HE_NSS2_MCS11"); break;
821 
822 	case RTW_DATA_RATE_HE_NSS3_MCS0:	_os_snprintf(str, str_len,"HE_NSS3_MCS0"); break;
823 	case RTW_DATA_RATE_HE_NSS3_MCS1:	_os_snprintf(str, str_len,"HE_NSS3_MCS1"); break;
824 	case RTW_DATA_RATE_HE_NSS3_MCS2:	_os_snprintf(str, str_len,"HE_NSS3_MCS2"); break;
825 	case RTW_DATA_RATE_HE_NSS3_MCS3:	_os_snprintf(str, str_len,"HE_NSS3_MCS3"); break;
826 	case RTW_DATA_RATE_HE_NSS3_MCS4:	_os_snprintf(str, str_len,"HE_NSS3_MCS4"); break;
827 	case RTW_DATA_RATE_HE_NSS3_MCS5:	_os_snprintf(str, str_len,"HE_NSS3_MCS5"); break;
828 	case RTW_DATA_RATE_HE_NSS3_MCS6:	_os_snprintf(str, str_len,"HE_NSS3_MCS6"); break;
829 	case RTW_DATA_RATE_HE_NSS3_MCS7:	_os_snprintf(str, str_len,"HE_NSS3_MCS7"); break;
830 	case RTW_DATA_RATE_HE_NSS3_MCS8:	_os_snprintf(str, str_len,"HE_NSS3_MCS8"); break;
831 	case RTW_DATA_RATE_HE_NSS3_MCS9:	_os_snprintf(str, str_len,"HE_NSS3_MCS9"); break;
832 	case RTW_DATA_RATE_HE_NSS3_MCS10:	_os_snprintf(str, str_len,"HE_NSS3_MCS10"); break;
833 	case RTW_DATA_RATE_HE_NSS3_MCS11:	_os_snprintf(str, str_len,"HE_NSS3_MCS11"); break;
834 
835 	case RTW_DATA_RATE_HE_NSS4_MCS0:	_os_snprintf(str, str_len,"HE_NSS4_MCS0"); break;
836 	case RTW_DATA_RATE_HE_NSS4_MCS1:	_os_snprintf(str, str_len,"HE_NSS4_MCS1"); break;
837 	case RTW_DATA_RATE_HE_NSS4_MCS2:	_os_snprintf(str, str_len,"HE_NSS4_MCS2"); break;
838 	case RTW_DATA_RATE_HE_NSS4_MCS3:	_os_snprintf(str, str_len,"HE_NSS4_MCS3"); break;
839 	case RTW_DATA_RATE_HE_NSS4_MCS4:	_os_snprintf(str, str_len,"HE_NSS4_MCS4"); break;
840 	case RTW_DATA_RATE_HE_NSS4_MCS5:	_os_snprintf(str, str_len,"HE_NSS4_MCS5"); break;
841 	case RTW_DATA_RATE_HE_NSS4_MCS6:	_os_snprintf(str, str_len,"HE_NSS4_MCS6"); break;
842 	case RTW_DATA_RATE_HE_NSS4_MCS7:	_os_snprintf(str, str_len,"HE_NSS4_MCS7"); break;
843 	case RTW_DATA_RATE_HE_NSS4_MCS8:	_os_snprintf(str, str_len,"HE_NSS4_MCS8"); break;
844 	case RTW_DATA_RATE_HE_NSS4_MCS9:	_os_snprintf(str, str_len,"HE_NSS4_MCS9"); break;
845 	case RTW_DATA_RATE_HE_NSS4_MCS10:	_os_snprintf(str, str_len,"HE_NSS4_MCS10"); break;
846 	case RTW_DATA_RATE_HE_NSS4_MCS11:	_os_snprintf(str, str_len,"HE_NSS4_MCS11"); break;
847 
848 	case RTW_DATA_RATE_MAX:			_os_snprintf(str, str_len,"RATE_MAX"); break;
849 	default:
850 		_os_snprintf(str, str_len,"Unknown rate(0x%01x)", (unsigned int)rx_rate);
851 		break;
852 	}
853 }
854 
phl_dbg_cmd_asoc_sta(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)855 void phl_dbg_cmd_asoc_sta(struct phl_info_t *phl_info, char input[][MAX_ARGV],
856 		      u32 input_num, char *output, u32 out_len)
857 {
858 	u32 ctrl = 0, wrole_idx = 0;
859 	u32 used = 0;
860 	struct rtw_wifi_role_t *wrole = NULL;
861 	struct rtw_phl_stainfo_t *n, *psta;
862 	void *drv = phl_to_drvpriv(phl_info);
863 	char tx_rate_str[32] = {0};
864 	char rx_rate_str[32] = {0};
865 	u8 path_idx = 0;
866 	u16 rssi = 0;
867 
868 	struct rtw_hal_com_t *hal_com = rtw_hal_get_halcom(phl_info->hal);
869 
870 	PHL_DBG_MON_INFO(out_len, used, output + used,
871 			out_len - used, "\nDUMP Associate STA infomations\n");
872 	if(input_num < 2) {
873 		PHL_DBG_MON_INFO(out_len, used, output + used,
874 			out_len - used, "phl asoc_sta [wrole index] [1=dump list basic information]\n");
875 		return;
876 	}
877 	_get_hex_from_string(input[1], &ctrl);
878 	_get_hex_from_string(input[2], &wrole_idx);
879 	if (wrole_idx >= MAX_WIFI_ROLE_NUMBER) {
880 		PHL_DBG_MON_INFO(out_len, used, output + used,
881 			out_len - used, "Wrole Index shall < 5\n");
882 		return;
883 	}
884 	wrole = rtw_phl_get_wrole_by_ridx(phl_info->phl_com, (u8)wrole_idx);
885 	if (1 == ctrl) {
886 		_os_spinlock(drv, &wrole->assoc_sta_queue.lock, _bh, NULL);
887 		phl_list_for_loop_safe(psta, n, struct rtw_phl_stainfo_t,
888 			       &wrole->assoc_sta_queue.queue, list) {
889 			PHL_DBG_MON_INFO(out_len, used, output + used,
890 				out_len - used, "\nmac_id 0x%x ; aid 0x%x ; mac addr %02x-%02x-%02x-%02x-%02x-%02x ; AX_Support %d\n",
891 				(int)psta->macid, (int)psta->aid,
892 				psta->mac_addr[0], psta->mac_addr[1],
893 				psta->mac_addr[2], psta->mac_addr[3],
894 				psta->mac_addr[4], psta->mac_addr[5],
895 				(psta->wmode&WLAN_MD_11AX) ? 1 : 0);
896 
897 			PHL_DBG_MON_INFO(out_len, used, output + used,
898 				out_len - used, "WROLE-IDX:%d wlan_mode:0x%02x, chan:%d, bw%d\n",
899 				psta->wrole->id, psta->wmode, psta->chandef.chan, psta->chandef.bw);
900 
901 			PHL_DBG_MON_INFO(out_len, used, output + used,
902 				out_len - used, "[Stats] Tput -[Tx:%d KBits Rx :%d KBits]\n",
903 				(int)psta->stats.tx_tp_kbits, (int)psta->stats.rx_tp_kbits);
904 			PHL_DBG_MON_INFO(out_len, used, output + used,
905 					 out_len - used, "[Stats] MA SNR:%d\n",
906 					 psta->hal_sta->rssi_stat.snr_ma >> PHL_RSSI_MA_H );
907 
908 			PHL_DBG_MON_INFO(out_len, used, output + used,
909 				out_len - used, "[Stats] RSSI:%d(dBm)\n",
910 				psta->hal_sta->rssi_stat.ma_rssi - PHL_MAX_RSSI);
911 
912 			for (path_idx = 0; path_idx < hal_com->rfpath_rx_num; path_idx++) {
913 				rssi = (psta->hal_sta->rssi_stat.rssi_ma_path[path_idx] >> 5) & 0x7f;
914 				PHL_DBG_MON_INFO(out_len, used, output + used,
915 						 out_len - used, "[Stats] Path[%d] MA RSSI:%d(dBm)\n",
916 						 path_idx, rssi - PHL_MAX_RSSI);
917 
918 				rssi = (psta->hal_sta->rssi_stat.rssi_bcn_ma_path[path_idx] >> 5) & 0x7f;
919 				PHL_DBG_MON_INFO(out_len, used, output + used,
920 						 out_len - used, "[Stats] Path[%d] BCN MA RSSI:%d(dBm)\n",
921 						 path_idx, rssi - PHL_MAX_RSSI);
922 			}
923 
924 			_convert_tx_rate( psta->hal_sta->ra_info.rpt_rt_i.mode,
925 					psta->hal_sta->ra_info.rpt_rt_i.mcs_ss_idx,
926 			 		tx_rate_str, 32);
927 			PHL_DBG_MON_INFO(out_len, used, output + used,
928 				out_len - used, "[Stats] Tx Rate :%s\n",
929 				tx_rate_str);
930 
931 			_convert_rx_rate(psta->stats.rx_rate, rx_rate_str, 32);
932 			PHL_DBG_MON_INFO(out_len, used, output + used,
933 				out_len - used, "[Stats] Rx Rate :%s\n",
934 				rx_rate_str);
935 
936 			PHL_DBG_MON_INFO(out_len, used, output + used,
937 				out_len - used, "[Stats] rx_ok_cnt:%d rx_err_cnt:%d\n",
938 				(int)psta->hal_sta->trx_stat.rx_ok_cnt,
939 				(int)psta->hal_sta->trx_stat.rx_err_cnt);
940 
941 			PHL_DBG_MON_INFO(out_len, used, output + used,
942 					 out_len - used, "[Stats] tx retry ratio:%d %%\n",
943 					 (u8)psta->hal_sta->ra_info.curr_retry_ratio);
944 
945 		}
946 		_os_spinunlock(drv, &wrole->assoc_sta_queue.lock, _bh, NULL);
947 	}
948 }
949 
950 #ifdef CONFIG_PCI_HCI
_dbg_tx_stats_pcie(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len,u32 * used,u32 ctrl,u32 ch)951 void _dbg_tx_stats_pcie(struct phl_info_t *phl_info, char input[][MAX_ARGV],
952 			u32 input_num, char *output, u32 out_len, u32 *used,
953 			u32 ctrl, u32 ch)
954 
955 {
956 	struct hci_info_t *hci_info = (struct hci_info_t *)phl_info->hci;
957 	struct rtw_hal_com_t *hal_com = rtw_hal_get_halcom(phl_info->hal);
958 	struct rtw_wp_rpt_stats *rpt_stats = NULL;
959 
960 	rpt_stats = (struct rtw_wp_rpt_stats *)hal_com->trx_stat.wp_rpt_stats;
961 
962 	if (ch >= hci_info->total_txch_num) {
963 		PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
964 				 "\n Invalid channel number\n");
965 		return;
966 	}
967 	if (0xFF == ctrl) {
968 		rpt_stats[ch].tx_ok_cnt = 0;
969 		rpt_stats[ch].rty_fail_cnt = 0;
970 		rpt_stats[ch].lifetime_drop_cnt = 0;
971 		rpt_stats[ch].macid_drop_cnt = 0;
972 		rpt_stats[ch].sw_drop_cnt = 0;
973 		rpt_stats[ch].recycle_fail_cnt = 0;
974 		rpt_stats[ch].delay_tx_ok_cnt = 0;
975 		rpt_stats[ch].delay_rty_fail_cnt = 0;
976 		rpt_stats[ch].delay_lifetime_drop_cnt = 0;
977 		rpt_stats[ch].delay_macid_drop_cnt = 0;
978 		return;
979 	}
980 
981 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
982 		"\n== wp report statistics == \n");
983 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
984 		"ch			: %u\n", (int)ch);
985 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
986 		"busy count		: %u\n", (int)rpt_stats[ch].busy_cnt);
987 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
988 		"ok count		: %u\n", (int)rpt_stats[ch].tx_ok_cnt);
989 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
990 		"retry fail count	: %u\n",
991 			 (int)rpt_stats[ch].rty_fail_cnt);
992 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
993 		"lifetime drop count	: %u\n",
994 			 (int)rpt_stats[ch].lifetime_drop_cnt);
995 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
996 		"macid drop count	: %u\n",
997 			 (int)rpt_stats[ch].macid_drop_cnt);
998 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
999 		"sw drop count		: %u\n",
1000 			 (int)rpt_stats[ch].sw_drop_cnt);
1001 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
1002 		"recycle fail count	: %u\n",
1003 			 (int)rpt_stats[ch].recycle_fail_cnt);
1004 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
1005 		"delay ok count			: %u\n",
1006 			 (int)rpt_stats[ch].delay_tx_ok_cnt);
1007 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
1008 		"delay retry fail count		: %u\n",
1009 			 (int)rpt_stats[ch].delay_rty_fail_cnt);
1010 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
1011 		"delay lifetime drop count	: %u\n",
1012 			 (int)rpt_stats[ch].delay_lifetime_drop_cnt);
1013 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
1014 		"delay macid drop count		: %u\n",
1015 			 (int)rpt_stats[ch].delay_macid_drop_cnt);
1016 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
1017 		"ltr tx delay count		: %u\n",
1018 			 (int)hal_com->trx_stat.ltr_tx_dly_count);
1019 	PHL_DBG_MON_INFO(out_len, *used, output + *used, out_len - *used,
1020 		"ltr last tx delay time	: %u\n",
1021 			 (int)hal_com->trx_stat.ltr_last_tx_dly_time);
1022 }
1023 #endif
1024 
phl_dbg_ltr_stats(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)1025 void phl_dbg_ltr_stats(struct phl_info_t *phl_info, char input[][MAX_ARGV],
1026 		       u32 input_num, char *output, u32 out_len)
1027 {
1028 	#ifdef CONFIG_PCI_HCI
1029 	u32 used = 0;
1030 	#ifdef RTW_WKARD_DYNAMIC_LTR
1031 		if (input_num == 3) {
1032 			if (0 == _os_strcmp(input[1], "set")) {
1033 					if (0 == _os_strcmp(input[2], "disable")) {
1034 						phl_ltr_hw_ctrl(phl_info->phl_com, false);
1035 						phl_ltr_sw_ctrl(phl_info->phl_com, phl_info->hal, false);
1036 					} else if (0 == _os_strcmp(input[2], "enable")) {
1037 						phl_ltr_hw_ctrl(phl_info->phl_com, true);
1038 						phl_ltr_sw_ctrl(phl_info->phl_com, phl_info->hal, true);
1039 					} else {
1040 						return;
1041 					}
1042 			}
1043 			return;
1044 		}
1045 
1046 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1047 		"\nltr sw ctrl   	   : %u\n",
1048 				rtw_hal_ltr_is_sw_ctrl(phl_info->phl_com, phl_info->hal) ? 1 : 0);
1049 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1050 		"ltr hw ctrl   	   : %u\n",
1051 				rtw_hal_ltr_is_hw_ctrl(phl_info->phl_com, phl_info->hal) ? 1 : 0);
1052 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1053 		"ltr current state   : %u\n",
1054 				phl_ltr_get_cur_state(phl_info->phl_com));
1055 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1056 		"ltr last trigger time : %lu\n",
1057 				phl_ltr_get_last_trigger_time(phl_info->phl_com));
1058 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1059 		"ltr active trigger cnt: %lu\n",
1060 				phl_ltr_get_tri_cnt(phl_info->phl_com, RTW_PCIE_LTR_SW_ACT));
1061 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1062 		"ltr idle trigger cnt: %lu\n",
1063 				phl_ltr_get_tri_cnt(phl_info->phl_com, RTW_PCIE_LTR_SW_IDLE));
1064 	#else
1065 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1066 		"Not Support Dynamical LTR\n");
1067 	#endif
1068 	#endif
1069 }
1070 
phl_dbg_trx_stats(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)1071 void phl_dbg_trx_stats(struct phl_info_t *phl_info, char input[][MAX_ARGV],
1072 		       u32 input_num, char *output, u32 out_len)
1073 {
1074  	struct rtw_phl_com_t *phl_com = phl_info->phl_com;
1075 	struct rtw_stats *phl_stats = &phl_com->phl_stats;
1076 	u32 used = 0;
1077 	u32 ctrl = 0;
1078 	u32 ch = 0;
1079 
1080 	if (input_num < 2) {
1081 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1082 		"Invalid Input\n");
1083 		return;
1084 	}
1085 	_get_hex_from_string(input[1], &ch);
1086 
1087 	if (input_num == 3) {
1088 		_get_hex_from_string(input[2], &ctrl);
1089 	}
1090 
1091 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1092 		"\nunicast tx bytes	: %llu\n", phl_stats->tx_byte_uni);
1093 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1094 		"total tx bytes		: %llu\n", phl_stats->tx_byte_total);
1095 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1096 		 "tx throughput		: %d(kbps)\n",
1097 			 (int)phl_stats->tx_tp_kbits);
1098 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1099 		"last tx time		: %d(ms)\n",
1100 			 (int)phl_stats->last_tx_time_ms);
1101 
1102 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1103 		"tx request num to phl	: %d\n",
1104 			 (int)phl_stats->txreq_num);
1105 
1106 #ifdef CONFIG_PCI_HCI
1107 	_dbg_tx_stats_pcie(phl_info, input, input_num, output, out_len, &used,
1108 			   ctrl, ch);
1109 #endif
1110 
1111 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1112 		"\nunicast rx bytes	: %llu\n", phl_stats->rx_byte_uni);
1113 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1114 		"total rx bytes		: %llu\n", phl_stats->rx_byte_total);
1115 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1116 		 "rx throughput		: %d(kbps)\n",
1117 			 (int)phl_stats->rx_tp_kbits);
1118 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1119 		"last rx time		: %d(ms)\n",
1120 			 (int)phl_stats->last_rx_time_ms);
1121 }
1122 
phl_dbg_cmd_show_rssi(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)1123 void phl_dbg_cmd_show_rssi(struct phl_info_t *phl_info, char input[][MAX_ARGV],
1124 		 	   u32 input_num, char *output, u32 out_len)
1125 {
1126 	u32 used = 0;
1127 	struct rtw_phl_rssi_stat *rssi_stat = NULL;
1128 	struct rtw_phl_stainfo_t *psta = NULL;
1129 	struct rtw_phl_com_t *phl_com = NULL;
1130 	u32 macid = 0;
1131 
1132 	if (NULL == phl_info)
1133 		return;
1134 
1135 	rssi_stat = &phl_info->phl_com->rssi_stat;
1136 	phl_com = phl_info->phl_com;
1137 
1138 	_os_spinlock(phl_com->drv_priv,
1139 		     &(phl_com->rssi_stat.lock), _bh, NULL);
1140 
1141 	PHL_DBG_MON_INFO(out_len, used, output + used,
1142 			 out_len - used, "\nShow Moving Average RSSI Statistics Informations\n");
1143 
1144 	PHL_DBG_MON_INFO(out_len, used, output + used,
1145 			 out_len - used,
1146 			 "DATA (A1 Match, AddrCam Valid) : %d\n",
1147 			 rssi_stat->ma_rssi[RTW_RSSI_DATA_ACAM_A1M]);
1148 	PHL_DBG_MON_INFO(out_len, used, output + used,
1149 			 out_len - used,
1150 			 "DATA (A1 Not Match, AddrCam Valid) : %d\n",
1151 			 rssi_stat->ma_rssi[RTW_RSSI_DATA_ACAM]);
1152 	PHL_DBG_MON_INFO(out_len, used, output + used,
1153 			 out_len - used,
1154 			 "DATA (other) : %d\n",
1155 			 rssi_stat->ma_rssi[RTW_RSSI_DATA_OTHER]);
1156 
1157 	PHL_DBG_MON_INFO(out_len, used, output + used,
1158 			 out_len - used,
1159 			 "MGNT (A1 Match, AddrCam Valid) : %d\n",
1160 			 rssi_stat->ma_rssi[RTW_RSSI_MGNT_ACAM_A1M]);
1161 	PHL_DBG_MON_INFO(out_len, used, output + used,
1162 			 out_len - used,
1163 			 "MGNT (A1 Not Match, AddrCam Valid) : %d\n",
1164 			 rssi_stat->ma_rssi[RTW_RSSI_MGNT_ACAM]);
1165 	PHL_DBG_MON_INFO(out_len, used, output + used,
1166 			 out_len - used,
1167 			 "MGNT (other) : %d\n",
1168 			 rssi_stat->ma_rssi[RTW_RSSI_MGNT_OTHER]);
1169 
1170 	PHL_DBG_MON_INFO(out_len, used, output + used,
1171 			 out_len - used,
1172 			 "CTRL (A1 Match, AddrCam Valid) : %d\n",
1173 			 rssi_stat->ma_rssi[RTW_RSSI_CTRL_ACAM_A1M]);
1174 	PHL_DBG_MON_INFO(out_len, used, output + used,
1175 			 out_len - used,
1176 			 "CTRL (A1 Not Match, AddrCam Valid) : %d\n",
1177 			 rssi_stat->ma_rssi[RTW_RSSI_CTRL_ACAM]);
1178 	PHL_DBG_MON_INFO(out_len, used, output + used,
1179 			 out_len - used,
1180 			 "CTRL (other) : %d\n",
1181 			 rssi_stat->ma_rssi[RTW_RSSI_CTRL_OTHER]);
1182 
1183 	PHL_DBG_MON_INFO(out_len, used, output + used,
1184 			 out_len - used,
1185 			 "Unknown : %d\n",
1186 			 rssi_stat->ma_rssi[RTW_RSSI_UNKNOWN]);
1187 	_os_spinunlock(phl_com->drv_priv,
1188 		     &(phl_com->rssi_stat.lock), _bh, NULL);
1189 
1190 	if(input_num > 1) {
1191 		_get_hex_from_string(input[1], &macid);
1192 		psta = rtw_phl_get_stainfo_by_macid(phl_info, (u16)macid);
1193 		if (psta != NULL) {
1194 			PHL_DBG_MON_INFO(out_len, used, output + used,
1195 			 out_len - used,
1196 			 "STA macid : %d ; mv_avg_rssi = %d ; asoc_rssi = %d (bb : %d, %d)\n",
1197 			 (int)macid, (int)psta->hal_sta->rssi_stat.ma_rssi,
1198 			 (int)psta->hal_sta->rssi_stat.assoc_rssi,
1199 			 (int)(psta->hal_sta->rssi_stat.rssi >> 1),
1200 			 (int)(psta->hal_sta->rssi_stat.rssi_ma >> 5));
1201 		}
1202 	}
1203 
1204 }
1205 
1206 #ifdef CONFIG_RTW_DEBUG
_phl_set_level(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)1207 static void _phl_set_level(struct phl_info_t *phl_info, char input[][MAX_ARGV],
1208 			 u32 input_num, char *output, u32 out_len)
1209 {
1210 	u32 ctrl = 0;
1211 	u32 dbg_level = 0;
1212 	u32 used = 0;
1213 
1214 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1215 			"[DBG] PHL_DBG_LEVEL [0=set value, 1=show] \n");
1216 
1217 	if (input_num <= 1)
1218 		return;
1219 
1220 	_get_hex_from_string(input[1], &ctrl);
1221 	if (ctrl > 1)
1222 		return;
1223 	_get_hex_from_string(input[2], &dbg_level);
1224 	if (dbg_level >= _PHL_MAX_)
1225 		return;
1226 
1227 	if (ctrl == 0)
1228 		phl_log_level = (u8)dbg_level;
1229 	else if (ctrl == 1)
1230 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1231 				 "phl_log_level=%u\n", phl_log_level);
1232 	else
1233 		PHL_DBG_MON_INFO(out_len, used, output + used,
1234 				out_len - used, "PHL CMD not found!\n");
1235 }
1236 #endif /*CONFIG_RTW_DEBUG*/
1237 
phl_dbg_cmd_parser(struct phl_info_t * phl_info,char input[][MAX_ARGV],u32 input_num,char * output,u32 out_len)1238 void phl_dbg_cmd_parser(struct phl_info_t *phl_info, char input[][MAX_ARGV],
1239 		        u32 input_num, char *output, u32 out_len)
1240 {
1241 	u8 id = 0;
1242 	u32 i;
1243 	u32 used = 0;
1244 	u32 phl_ary_size = sizeof(phl_dbg_cmd_i) /
1245 			   sizeof(struct phl_dbg_cmd_info);
1246 
1247 	if (phl_ary_size == 0)
1248 		return;
1249 
1250 	PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used, "\n");
1251 	/* Parsing Cmd ID */
1252 	if (input_num) {
1253 		for (i = 0; i < phl_ary_size; i++) {
1254 			if (_os_strcmp(phl_dbg_cmd_i[i].name, input[0]) == 0) {
1255 				id = phl_dbg_cmd_i[i].id;
1256 				PHL_DBG("[%s]===>\n", phl_dbg_cmd_i[i].name);
1257 				break;
1258 			}
1259 		}
1260 		if (i == phl_ary_size) {
1261 			PHL_DBG_MON_INFO(out_len, used, output + used,
1262 				out_len - used, "PHL CMD not found!\n");
1263 			return;
1264 		}
1265 	}
1266 
1267 	switch (id) {
1268 	case PHL_DBG_MON_HELP:
1269 	{
1270 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1271 				 "phl_dbg_cmd_parser : PHL_DBG_MON_HELP \n");
1272 		for (i = 0; i < phl_ary_size - 2; i++)
1273 			PHL_DBG_MON_INFO(out_len, used, output + used,
1274 					 out_len - used, "%-5d: %s\n",
1275 			          (int)i, phl_dbg_cmd_i[i + 2].name);
1276 
1277 	}
1278 	break;
1279 	case PHL_DBG_MON_TEST:
1280 	{
1281 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1282 				 "[DBG] PHL_DBG_MON_TEST (SAMPLE) \n");
1283 	}
1284 	break;
1285 	case PHL_DBG_COMP:
1286 	{
1287 		u32 ctrl = 0, comp = 0;
1288 		u32 ret = 0;
1289 
1290 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1291 			"[DBG] PHL_DBG_COMP [1=set comp_bit, 2=clear comp_bit, 4=set value]\n");
1292 		if (input_num <= 2)
1293 			break;
1294 		_get_hex_from_string(input[1], &ctrl);
1295 		_get_hex_from_string(input[2], &comp);
1296 
1297 		ret = rtw_phl_dbg_ctrl_comp((u8)ctrl, comp);
1298 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1299 			"[DBG] PHL_DBG_COMP (COMP = 0x%x) \n", (int)ret);
1300 	}
1301 	break;
1302 	case PHL_DBG_DUMP_WROLE:
1303 	{
1304 		_dump_wifi_role(phl_info, output, out_len);
1305 	}
1306 	break;
1307 	case PHL_DBG_SET_CH_BW:
1308 	{
1309 		_phl_dbg_cmd_switch_chbw(phl_info, input, input_num,
1310 					 output, out_len);
1311 	}
1312 	break;
1313 	case PHL_DBG_SHOW_RX_RATE:
1314 	{
1315 		_dump_rx_rate(phl_info, input, input_num, output, out_len);
1316 	}
1317 	break;
1318 	case PHL_DBG_SOUND :
1319 	{
1320 		phl_dbg_cmd_snd(phl_info, input, input_num, output, out_len);
1321 	}
1322 	break;
1323 	case PHL_DBG_ASOC_STA:
1324 	{
1325 		phl_dbg_cmd_asoc_sta(phl_info, input, input_num, output, out_len);
1326 	}
1327 	break;
1328 	#ifdef CONFIG_FSM
1329 	case PHL_DBG_FSM:
1330 	{
1331 		phl_fsm_dbg(phl_info, input, input_num, output, out_len);
1332 	}
1333 	break;
1334 	#endif
1335 	case PHL_DBG_TRX_STATS:
1336 	{
1337 		phl_dbg_trx_stats(phl_info, input, input_num, output, out_len);
1338 	}
1339 	break;
1340 	case PHL_DBG_LTR:
1341 	{
1342 		phl_dbg_ltr_stats(phl_info, input, input_num, output, out_len);
1343 	}
1344 	break;
1345 	case PHL_SHOW_RSSI_STAT :
1346 	{
1347 		phl_dbg_cmd_show_rssi(phl_info, input, input_num, output, out_len);
1348 	}
1349 	break;
1350 	case PHL_DBG_SER:
1351 	{
1352 		phl_ser_cmd_parser(phl_info, input, input_num, output, out_len);
1353 	}
1354 	break;
1355 	case PHL_DBG_WOW:
1356 	{
1357 		_dump_wow_stats(phl_info, input, input_num, output, out_len);
1358 	}
1359 	break;
1360 #ifdef CONFIG_POWER_SAVE
1361 	case PHL_DBG_PS:
1362 	{
1363 		phl_ps_cmd_parser(phl_info, input, input_num, output, out_len);
1364 	}
1365 	break;
1366 #endif
1367 #ifdef CONFIG_MCC_SUPPORT
1368 	case PHL_DBG_MCC:
1369 	{
1370 		_dump_mcc_info(phl_info, input, input_num, output, out_len);
1371 	}
1372 	break;
1373 #endif /* CONFIG_MCC_SUPPORT */
1374 
1375 	case PHL_DBG_ECSA:
1376 	{
1377 #ifdef CONFIG_PHL_ECSA
1378 		struct rtw_wifi_role_t *role = NULL;
1379 		struct rtw_phl_ecsa_param param = {0};
1380 		int chan = 0;
1381 		int bw = 0;
1382 		int offset = 0;
1383 		int count = 0;
1384 		int op_class = 0;
1385 		int mode = 0;
1386 		int delay_start_ms = 0;
1387 		if (input_num <= 7)
1388 			break;
1389 		_os_sscanf(input[1], "%d", &chan);
1390 		_os_sscanf(input[2], "%d", &bw);
1391 		_os_sscanf(input[3], "%d", &offset);
1392 		_os_sscanf(input[4], "%d", &count);
1393 		_os_sscanf(input[5], "%d", &op_class);
1394 		_os_sscanf(input[6], "%d", &mode);
1395 		_os_sscanf(input[7], "%d", &delay_start_ms);
1396 		role = rtw_phl_get_wrole_by_ridx(phl_info->phl_com, 2);
1397 		if(role){
1398 			param.ecsa_type = ECSA_TYPE_AP;
1399 			param.ch = (u8)chan;
1400 			param.count = (u8)count;
1401 			param.flag = 0;
1402 			param.mode = (u8)mode;
1403 			param.op_class = (u8)op_class;
1404 			param.delay_start_ms = delay_start_ms;
1405 			param.new_chan_def.chan = (u8)chan;
1406 			param.new_chan_def.bw = (u8)bw;
1407 			param.new_chan_def.offset = (u8)offset;
1408 
1409 			rtw_phl_ecsa_start(phl_info, role, &param);
1410 		}
1411 		else
1412 			PHL_DBG_MON_INFO(out_len, used, output + used,
1413 			out_len - used, "[DBG] Role 2 is NULL\n");
1414 #else
1415 		PHL_DBG_MON_INFO(out_len, used, output + used,
1416 			out_len - used, "[DBG] ECSA not support!\n");
1417 #endif /* CONFIG_PHL_ECSA */
1418 	}
1419 	break;
1420 	case PHL_DBG_CFG_TX_DUTY:
1421 	{
1422 		int tx_duty = 100;
1423 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1424 			"[DBG] PHL_DBG_CFG_TX_DUTY [100-30] \n");
1425 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1426 			"[DBG] TX duty interval = 100ms \n");
1427 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1428 			"[DBG] No TX duty control: 100 \n");
1429 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1430 			"[DBG] Minimum TX duty control: 30 (TX 30ms pause TX 70ms)\n");
1431 		if (input_num <= 1)
1432 			break;
1433 		_os_sscanf(input[1], "%d", &tx_duty);
1434 		if (tx_duty < 30 || tx_duty > 100) {
1435 			PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1436 				"[DBG] TX duty should be 30~100 \n");
1437 			break;
1438 		}
1439 		if (tx_duty == 100)
1440 			phl_thermal_protect_stop_tx_duty(phl_info);
1441 		else
1442 			phl_thermal_protect_cfg_tx_duty(phl_info, 100, (u8)tx_duty);
1443 
1444 		PHL_DBG_MON_INFO(out_len, used, output + used, out_len - used,
1445 			"[DBG] Current TX duty control: %d \n", tx_duty);
1446 	}
1447 	break;
1448 
1449 	case PHL_DBG_SET_LEVEL:
1450 	#ifdef CONFIG_RTW_DEBUG
1451 		_phl_set_level(phl_info, input, input_num, output, out_len);
1452 	#endif /*CONFIG_RTW_DEBUG*/
1453 	break;
1454 
1455 	default:
1456 		PHL_DBG_MON_INFO(out_len, used, output + used,
1457 			out_len - used, "[DBG] Do not support this command\n");
1458 		break;
1459 	}
1460 }
1461 
1462 s32
phl_dbg_proc_cmd(struct phl_info_t * phl_info,char * input,char * output,u32 out_len)1463 phl_dbg_proc_cmd(struct phl_info_t *phl_info,
1464 		 char *input, char *output, u32 out_len)
1465 {
1466 	char *token;
1467 	u32 argc = 0;
1468 	char argv[MAX_ARGC][MAX_ARGV];
1469 
1470 	do {
1471 		token = _os_strsep(&input, ", ");
1472 		if (token) {
1473 			if (_os_strlen((u8 *)token) <= MAX_ARGV)
1474 				_os_strcpy(argv[argc], token);
1475 
1476 			argc++;
1477 		} else {
1478 			break;
1479 		}
1480 	} while (argc < MAX_ARGC);
1481 
1482 	if (argc == 1)
1483 		argv[0][_os_strlen((u8 *)argv[0])] = '\0';
1484 
1485 	phl_dbg_cmd_parser(phl_info, argv, argc, output, out_len);
1486 
1487 	return 0;
1488 }
1489 
1490 enum rtw_hal_status
rtw_phl_dbg_proc_cmd(struct phl_info_t * phl_info,struct rtw_proc_cmd * incmd,char * output,u32 out_len)1491 rtw_phl_dbg_proc_cmd(struct phl_info_t *phl_info,
1492 		     struct rtw_proc_cmd *incmd,
1493 		     char *output,
1494 		     u32 out_len)
1495 {
1496 	if (incmd->in_type == RTW_ARG_TYPE_BUF) {
1497 		phl_dbg_proc_cmd(phl_info, incmd->in.buf, output, out_len);
1498 	} else if(incmd->in_type == RTW_ARG_TYPE_ARRAY){
1499 		phl_dbg_cmd_parser(phl_info, incmd->in.vector,
1500 				   incmd->in_cnt_len, output, out_len);
1501 	}
1502 	return RTW_HAL_STATUS_SUCCESS;
1503 }
1504 
1505 #endif
1506