1 /*
2  * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include "osdep.h"
19 #include "wmi.h"
20 #include "wmi_unified_priv.h"
21 
22 /**
23  * extract_dcs_interference_type_tlv() - extract dcs interference type
24  * from event
25  * @wmi_handle: wmi handle
26  * @evt_buf: pointer to event buffer
27  * @param: Pointer to hold dcs interference param
28  *
29  * Return: 0 for success or error code
30  */
extract_dcs_interference_type_tlv(wmi_unified_t wmi_handle,void * evt_buf,struct wlan_host_dcs_interference_param * param)31 static QDF_STATUS extract_dcs_interference_type_tlv(
32 		wmi_unified_t wmi_handle,
33 		void *evt_buf, struct wlan_host_dcs_interference_param *param)
34 {
35 	WMI_DCS_INTERFERENCE_EVENTID_param_tlvs *param_buf;
36 
37 	param_buf = (WMI_DCS_INTERFERENCE_EVENTID_param_tlvs *)evt_buf;
38 	if (!param_buf) {
39 		wmi_err("Invalid dcs interference event buffer");
40 		return QDF_STATUS_E_INVAL;
41 	}
42 
43 	if (!param_buf->fixed_param) {
44 		wmi_err("Invalid fixed param");
45 		return QDF_STATUS_E_INVAL;
46 	}
47 
48 	param->interference_type = param_buf->fixed_param->interference_type;
49 	/* Just support tlv currently */
50 	param->pdev_id = wmi_handle->ops->convert_target_pdev_id_to_host(
51 					wmi_handle,
52 					param_buf->fixed_param->pdev_id);
53 
54 	return QDF_STATUS_SUCCESS;
55 }
56 
57 /**
58  * extract_dcs_im_tgt_stats_tlv() - extract dcs im target stats from event
59  * @wmi_handle: wmi handle
60  * @evt_buf: pointer to event buffer
61  * @wlan_stat: Pointer to hold wlan stats
62  *
63  * Return: 0 for success or error code
64  */
extract_dcs_im_tgt_stats_tlv(wmi_unified_t wmi_handle,void * evt_buf,struct wlan_host_dcs_im_tgt_stats * wlan_stat)65 static QDF_STATUS extract_dcs_im_tgt_stats_tlv(
66 			wmi_unified_t wmi_handle,
67 			void *evt_buf,
68 			struct wlan_host_dcs_im_tgt_stats *wlan_stat)
69 {
70 	WMI_DCS_INTERFERENCE_EVENTID_param_tlvs *param_buf;
71 	wlan_dcs_im_tgt_stats_t *ev;
72 
73 	param_buf = (WMI_DCS_INTERFERENCE_EVENTID_param_tlvs *)evt_buf;
74 	if (!param_buf) {
75 		wmi_err("Invalid dcs interference event buffer");
76 		return QDF_STATUS_E_INVAL;
77 	}
78 
79 	ev = param_buf->wlan_stat;
80 	if (!ev) {
81 		wmi_err("Invalid wlan stat");
82 		return QDF_STATUS_E_INVAL;
83 	}
84 
85 	wlan_stat->reg_tsf32 = ev->reg_tsf32;
86 	wlan_stat->last_ack_rssi = ev->last_ack_rssi;
87 	wlan_stat->tx_waste_time = ev->tx_waste_time;
88 	wlan_stat->rx_time = ev->rx_time;
89 	wlan_stat->phyerr_cnt = ev->phyerr_cnt;
90 	wlan_stat->mib_stats.listen_time = ev->listen_time;
91 	wlan_stat->mib_stats.reg_tx_frame_cnt = ev->reg_tx_frame_cnt;
92 	wlan_stat->mib_stats.reg_rx_frame_cnt = ev->reg_rx_frame_cnt;
93 	wlan_stat->mib_stats.reg_rxclr_cnt = ev->reg_rxclr_cnt;
94 	wlan_stat->mib_stats.reg_cycle_cnt = ev->reg_cycle_cnt;
95 	wlan_stat->mib_stats.reg_rxclr_ext_cnt = ev->reg_rxclr_ext_cnt;
96 	wlan_stat->mib_stats.reg_ofdm_phyerr_cnt = ev->reg_ofdm_phyerr_cnt;
97 	wlan_stat->mib_stats.reg_cck_phyerr_cnt = ev->reg_cck_phyerr_cnt;
98 	wlan_stat->chan_nf = ev->chan_nf;
99 	wlan_stat->my_bss_rx_cycle_count = ev->my_bss_rx_cycle_count;
100 
101 	return QDF_STATUS_SUCCESS;
102 }
103 
104 /*
105  * extract_dcs_awgn_info_tlv() - extract DCS AWGN interference from event
106  * @wmi_handle: wmi handle
107  * @param evt_buf: pointer to event buffer
108  * @param awgn_info: Pointer to hold cw interference
109  *
110  * Return: QDF_STATUS_SUCCESS for success or QDF_STATUS_E_* for error
111  */
112 static QDF_STATUS
extract_dcs_awgn_info_tlv(wmi_unified_t wmi_handle,void * evt_buf,struct wlan_host_dcs_awgn_info * awgn_info)113 extract_dcs_awgn_info_tlv(wmi_unified_t wmi_handle, void *evt_buf,
114 			  struct wlan_host_dcs_awgn_info *awgn_info)
115 {
116 	WMI_DCS_INTERFERENCE_EVENTID_param_tlvs *param_buf;
117 	wmi_dcs_awgn_int_t *ev;
118 
119 	param_buf = evt_buf;
120 	if (!param_buf)
121 		return QDF_STATUS_E_INVAL;
122 
123 	ev = param_buf->awgn_int;
124 	if (!ev) {
125 		wmi_err("Invalid awgn info");
126 		return QDF_STATUS_E_INVAL;
127 	}
128 
129 	awgn_info->channel_width = wmi_map_ch_width(ev->channel_width);
130 	awgn_info->center_freq = (qdf_freq_t)ev->chan_freq;
131 	awgn_info->center_freq0 = (qdf_freq_t)ev->center_freq0;
132 	awgn_info->center_freq1 = (qdf_freq_t)ev->center_freq1;
133 	awgn_info->chan_bw_intf_bitmap = ev->chan_bw_interference_bitmap;
134 	wmi_debug("width: %u, freq: %u, freq0: %u, freq1: %u, bitmap: 0x%x",
135 		  awgn_info->channel_width, awgn_info->center_freq,
136 		  awgn_info->center_freq0, awgn_info->center_freq1,
137 		  awgn_info->chan_bw_intf_bitmap);
138 
139 	return QDF_STATUS_SUCCESS;
140 }
141 
wmi_dcs_attach_tlv(wmi_unified_t wmi_handle)142 void wmi_dcs_attach_tlv(wmi_unified_t wmi_handle)
143 {
144 	struct wmi_ops *ops = wmi_handle->ops;
145 
146 	ops->extract_dcs_interference_type = extract_dcs_interference_type_tlv;
147 	ops->extract_dcs_im_tgt_stats = extract_dcs_im_tgt_stats_tlv;
148 	ops->extract_dcs_awgn_info = extract_dcs_awgn_info_tlv;
149 }
150 
151