xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/phl_acs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 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  *****************************************************************************/
15 #define _PHL_ACS_C_
16 #include "phl_headers.h"
17 
18 #ifdef CONFIG_RTW_ACS
phl_acs_mntr_trigger(struct phl_info_t * phl_info,u8 idx,u16 channel,u16 monitor_time)19 void phl_acs_mntr_trigger(struct phl_info_t *phl_info, u8 idx, u16 channel, u16 monitor_time)
20 {
21 	struct auto_chan_sel *acs = &phl_info->acs;
22 
23 	if ((idx < 0) || (idx >= MAX_CHANNEL_NUM)) {
24 		PHL_ERR("[ACS][%s] idx(%d) invalid\n", __func__, idx);
25 		return;
26 	} else if (idx == 0) {
27 		_os_mem_set(phl_to_drvpriv(phl_info), acs, 0, sizeof(struct auto_chan_sel));
28 	}
29 
30 	acs->curr_idx = idx;
31 	acs->chset[idx] = channel;
32 
33 	rtw_hal_acs_mntr_trigger(phl_info->hal, monitor_time);
34 }
35 
phl_acs_mntr_result(struct phl_info_t * phl_info)36 void phl_acs_mntr_result(struct phl_info_t *phl_info)
37 {
38 	struct auto_chan_sel *acs = &phl_info->acs;
39 	u8 idx = acs->curr_idx;
40 	enum rtw_hal_status status;
41 	struct auto_chan_sel_report rpt = {0};
42 
43 	status = rtw_hal_acs_mntr_result(phl_info->hal, &rpt);
44 
45 
46 	if (idx >= MAX_CHANNEL_NUM) {
47 		PHL_ERR("[ACS][%s] idx(%d) invalid\n", __func__, idx);
48 		return;
49 	}
50 
51 	if (status == RTW_HAL_STATUS_SUCCESS) {
52 		acs->clm_ratio[idx] = rpt.clm_ratio;
53 		acs->nhm_pwr[idx] = rpt.nhm_pwr;
54 	}
55 }
56 
rtw_phl_acs_get_channel_by_idx(void * phl,u8 idx)57 u16 rtw_phl_acs_get_channel_by_idx(void *phl, u8 idx)
58 {
59 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
60 	struct auto_chan_sel *acs = &phl_info->acs;
61 
62 	if (idx >= MAX_CHANNEL_NUM) {
63 		PHL_ERR("[ACS][%s] idx(%d) invalid\n", __func__, idx);
64 		return 0;
65 	}
66 
67 	return acs->chset[idx];
68 }
69 
rtw_phl_acs_get_clm_ratio_by_idx(void * phl,u8 idx)70 u8 rtw_phl_acs_get_clm_ratio_by_idx(void *phl, u8 idx)
71 {
72 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
73 	struct auto_chan_sel *acs = &phl_info->acs;
74 
75 	if (idx >= MAX_CHANNEL_NUM) {
76 		PHL_ERR("%s [ACS] idx(%d) is invalid\n", __func__, idx);
77 		return 0;
78 	}
79 
80 	return acs->clm_ratio[idx];
81 }
82 
rtw_phl_noise_query_by_idx(void * phl,u8 idx)83 s8 rtw_phl_noise_query_by_idx(void *phl, u8 idx)
84 {
85 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
86 	struct auto_chan_sel *acs = &phl_info->acs;
87 
88 	if (idx >= MAX_CHANNEL_NUM) {
89 		PHL_ERR("%s [ACS] idx(%d) is invalid\n", __func__, idx);
90 		return 0;
91 	}
92 
93 	/* dBm = RPL - 110 */
94 	return acs->nhm_pwr[idx] - 110;
95 }
96 #endif /* CONFIG_RTW_ACS */
97 
rtw_phl_get_env_rpt(void * phl,struct rtw_env_report * env_rpt,struct rtw_wifi_role_t * wrole)98 void rtw_phl_get_env_rpt(void *phl, struct rtw_env_report *env_rpt, struct rtw_wifi_role_t *wrole)
99 {
100 	struct phl_info_t *phl_info = (struct phl_info_t *)phl;
101 	struct rtw_hal_com_t *hal_com = rtw_hal_get_halcom(phl_info->hal);
102 
103 	rtw_hal_env_rpt(hal_com, env_rpt, wrole);
104 
105 }
106