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