1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /****************************************************************************** 3 * 4 * Copyright(c) 2016 - 2017 Realtek Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of version 2 of the GNU General Public License as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 *****************************************************************************/ 16 17 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) 18 19 #if (RTL8723B_SUPPORT == 1) 20 /* ******************************************* 21 * The following is for 8723B 1ANT BT Co-exist definition 22 * ******************************************* */ 23 #define BT_AUTO_REPORT_ONLY_8723B_1ANT 1 24 25 #define BT_INFO_8723B_1ANT_B_FTP BIT(7) 26 #define BT_INFO_8723B_1ANT_B_A2DP BIT(6) 27 #define BT_INFO_8723B_1ANT_B_HID BIT(5) 28 #define BT_INFO_8723B_1ANT_B_SCO_BUSY BIT(4) 29 #define BT_INFO_8723B_1ANT_B_ACL_BUSY BIT(3) 30 #define BT_INFO_8723B_1ANT_B_INQ_PAGE BIT(2) 31 #define BT_INFO_8723B_1ANT_B_SCO_ESCO BIT(1) 32 #define BT_INFO_8723B_1ANT_B_CONNECTION BIT(0) 33 34 #define BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ 35 (((_BT_INFO_EXT_&BIT(0))) ? true : false) 36 37 #define BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT 2 38 39 #define BT_8723B_1ANT_WIFI_NOISY_THRESH 50 /* 30 /max: 255 */ 40 41 /* for Antenna detection */ 42 #define BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 43 #define BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 44 #define BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 48 45 #define BT_8723B_1ANT_ANTDET_PSDTHRES_1ANT 32 46 #define BT_8723B_1ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ 47 #define BT_8723B_1ANT_ANTDET_SWEEPPOINT_DELAY 40000 48 #define BT_8723B_1ANT_ANTDET_ENABLE 1 49 #define BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE 1 50 #define BT_8723B_1ANT_ANTDET_BTTXTIME 100 51 #define BT_8723B_1ANT_ANTDET_BTTXCHANNEL 39 52 53 enum bt_info_src_8723b_1ant { 54 BT_INFO_SRC_8723B_1ANT_WIFI_FW = 0x0, 55 BT_INFO_SRC_8723B_1ANT_BT_RSP = 0x1, 56 BT_INFO_SRC_8723B_1ANT_BT_ACTIVE_SEND = 0x2, 57 BT_INFO_SRC_8723B_1ANT_MAX 58 }; 59 60 enum bt_8723b_1ant_bt_status { 61 BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, 62 BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, 63 BT_8723B_1ANT_BT_STATUS_INQ_PAGE = 0x2, 64 BT_8723B_1ANT_BT_STATUS_ACL_BUSY = 0x3, 65 BT_8723B_1ANT_BT_STATUS_SCO_BUSY = 0x4, 66 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, 67 BT_8723B_1ANT_BT_STATUS_MAX 68 }; 69 70 enum bt_8723b_1ant_wifi_status { 71 BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, 72 BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, 73 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, 74 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, 75 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, 76 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, 77 BT_8723B_1ANT_WIFI_STATUS_MAX 78 }; 79 80 enum bt_8723b_1ant_coex_algo { 81 BT_8723B_1ANT_COEX_ALGO_UNDEFINED = 0x0, 82 BT_8723B_1ANT_COEX_ALGO_SCO = 0x1, 83 BT_8723B_1ANT_COEX_ALGO_HID = 0x2, 84 BT_8723B_1ANT_COEX_ALGO_A2DP = 0x3, 85 BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, 86 BT_8723B_1ANT_COEX_ALGO_PANEDR = 0x5, 87 BT_8723B_1ANT_COEX_ALGO_PANHS = 0x6, 88 BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, 89 BT_8723B_1ANT_COEX_ALGO_PANEDR_HID = 0x8, 90 BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, 91 BT_8723B_1ANT_COEX_ALGO_HID_A2DP = 0xa, 92 BT_8723B_1ANT_COEX_ALGO_MAX = 0xb, 93 }; 94 95 struct coex_dm_8723b_1ant { 96 /* hw setting */ 97 u8 pre_ant_pos_type; 98 u8 cur_ant_pos_type; 99 /* fw mechanism */ 100 boolean cur_ignore_wlan_act; 101 boolean pre_ignore_wlan_act; 102 u8 pre_ps_tdma; 103 u8 cur_ps_tdma; 104 u8 ps_tdma_para[5]; 105 u8 ps_tdma_du_adj_type; 106 boolean auto_tdma_adjust; 107 boolean pre_ps_tdma_on; 108 boolean cur_ps_tdma_on; 109 boolean pre_bt_auto_report; 110 boolean cur_bt_auto_report; 111 u8 pre_lps; 112 u8 cur_lps; 113 u8 pre_rpwm; 114 u8 cur_rpwm; 115 116 /* sw mechanism */ 117 boolean pre_low_penalty_ra; 118 boolean cur_low_penalty_ra; 119 u32 cur_val0x6c0; 120 u32 cur_val0x6c4; 121 u32 cur_val0x6c8; 122 u8 cur_val0x6cc; 123 124 u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ 125 u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ 126 u16 backup_retry_limit; 127 u8 backup_ampdu_max_time; 128 129 /* algorithm related */ 130 u8 bt_status; 131 u8 wifi_chnl_info[3]; 132 133 u32 pre_ra_mask; 134 u32 cur_ra_mask; 135 u8 pre_arfr_type; 136 u8 cur_arfr_type; 137 u8 pre_retry_limit_type; 138 u8 cur_retry_limit_type; 139 u8 pre_ampdu_time_type; 140 u8 cur_ampdu_time_type; 141 u32 arp_cnt; 142 143 u8 error_condition; 144 u32 setting_tdma; 145 }; 146 147 struct coex_sta_8723b_1ant { 148 boolean bt_disabled; 149 boolean bt_enable_disable_change; 150 boolean bt_link_exist; 151 boolean sco_exist; 152 boolean a2dp_exist; 153 boolean hid_exist; 154 boolean pan_exist; 155 boolean bt_hi_pri_link_exist; 156 u8 num_of_profile; 157 boolean bt_abnormal_scan; 158 159 boolean under_lps; 160 boolean under_ips; 161 u32 specific_pkt_period_cnt; 162 u8 connect_ap_period_cnt; 163 u32 high_priority_tx; 164 u32 high_priority_rx; 165 u32 low_priority_tx; 166 u32 low_priority_rx; 167 s8 bt_rssi; 168 boolean bt_tx_rx_mask; 169 boolean c2h_bt_info_req_sent; 170 u8 bt_info_c2h[BT_INFO_SRC_8723B_1ANT_MAX][10]; 171 u32 bt_info_c2h_cnt[BT_INFO_SRC_8723B_1ANT_MAX]; 172 boolean bt_whck_test; 173 boolean c2h_bt_inquiry_page; 174 boolean c2h_bt_remote_name_req; 175 boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ 176 u8 bt_retry_cnt; 177 u8 bt_info_ext; 178 u32 pop_event_cnt; 179 u8 scan_ap_num; 180 181 u32 crc_ok_cck; 182 u32 crc_ok_11g; 183 u32 crc_ok_11n; 184 u32 crc_ok_11n_vht; 185 186 u32 crc_err_cck; 187 u32 crc_err_11g; 188 u32 crc_err_11n; 189 u32 crc_err_11n_vht; 190 191 boolean cck_lock; 192 boolean pre_ccklock; 193 boolean cck_ever_lock; 194 u8 coex_table_type; 195 196 boolean force_lps_on; 197 u32 wrong_profile_notification; 198 u32 bt_coex_supported_version; 199 u8 a2dp_bit_pool; 200 u8 cut_version; 201 u8 hid_busy_num; 202 u8 bt_info_ext2; 203 }; 204 205 #define BT_8723B_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ 206 #define BT_8723B_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ 207 #define BT_8723B_1ANT_ANTDET_BUF_LEN 16 208 209 struct psdscan_sta_8723b_1ant { 210 211 u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ 212 u32 ant_det_bt_tx_time; 213 u32 ant_det_pre_psdscan_peak_val; 214 boolean ant_det_is_ant_det_available; 215 u32 ant_det_psd_scan_peak_val; 216 boolean ant_det_is_btreply_available; 217 u32 ant_det_psd_scan_peak_freq; 218 219 u8 ant_det_result; 220 u8 ant_det_peak_val[BT_8723B_1ANT_ANTDET_BUF_LEN]; 221 u8 ant_det_peak_freq[BT_8723B_1ANT_ANTDET_BUF_LEN]; 222 u32 ant_det_try_count; 223 u32 ant_det_fail_count; 224 u32 ant_det_inteval_count; 225 u32 ant_det_thres_offset; 226 227 u32 real_cent_freq; 228 s32 real_offset; 229 u32 real_span; 230 231 u32 psd_band_width; /* unit: Hz */ 232 u32 psd_point; /* 128/256/512/1024 */ 233 u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ 234 u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ 235 u32 psd_start_point; 236 u32 psd_stop_point; 237 u32 psd_max_value_point; 238 u32 psd_max_value; 239 u32 psd_start_base; 240 u32 psd_avg_num; /* 1/8/16/32 */ 241 u32 psd_gen_count; 242 boolean is_psd_running; 243 boolean is_psd_show_max_only; 244 }; 245 246 /* ******************************************* 247 * The following is interface which will notify coex module. 248 * ******************************************* */ 249 void ex_halbtc8723b1ant_power_on_setting(IN struct btc_coexist *btcoexist); 250 void ex_halbtc8723b1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); 251 void ex_halbtc8723b1ant_init_hw_config(IN struct btc_coexist *btcoexist, 252 IN boolean wifi_only); 253 void ex_halbtc8723b1ant_init_coex_dm(IN struct btc_coexist *btcoexist); 254 void ex_halbtc8723b1ant_ips_notify(IN struct btc_coexist *btcoexist, 255 IN u8 type); 256 void ex_halbtc8723b1ant_lps_notify(IN struct btc_coexist *btcoexist, 257 IN u8 type); 258 void ex_halbtc8723b1ant_scan_notify(IN struct btc_coexist *btcoexist, 259 IN u8 type); 260 void ex_halbtc8723b1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, 261 IN u8 type); 262 void ex_halbtc8723b1ant_connect_notify(IN struct btc_coexist *btcoexist, 263 IN u8 type); 264 void ex_halbtc8723b1ant_media_status_notify(IN struct btc_coexist *btcoexist, 265 IN u8 type); 266 void ex_halbtc8723b1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, 267 IN u8 type); 268 void ex_halbtc8723b1ant_bt_info_notify(IN struct btc_coexist *btcoexist, 269 IN u8 *tmp_buf, IN u8 length); 270 void ex_halbtc8723b1ant_rf_status_notify(IN struct btc_coexist *btcoexist, 271 IN u8 type); 272 void ex_halbtc8723b1ant_halt_notify(IN struct btc_coexist *btcoexist); 273 void ex_halbtc8723b1ant_pnp_notify(IN struct btc_coexist *btcoexist, 274 IN u8 pnp_state); 275 void ex_halbtc8723b1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); 276 void ex_halbtc8723b1ant_periodical(IN struct btc_coexist *btcoexist); 277 void ex_halbtc8723b1ant_display_coex_info(IN struct btc_coexist *btcoexist); 278 void ex_halbtc8723b1ant_antenna_detection(IN struct btc_coexist *btcoexist, 279 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 280 281 void ex_halbtc8723b1ant_display_ant_detection(IN struct btc_coexist *btcoexist); 282 283 #else 284 #define ex_halbtc8723b1ant_power_on_setting(btcoexist) 285 #define ex_halbtc8723b1ant_pre_load_firmware(btcoexist) 286 #define ex_halbtc8723b1ant_init_hw_config(btcoexist, wifi_only) 287 #define ex_halbtc8723b1ant_init_coex_dm(btcoexist) 288 #define ex_halbtc8723b1ant_ips_notify(btcoexist, type) 289 #define ex_halbtc8723b1ant_lps_notify(btcoexist, type) 290 #define ex_halbtc8723b1ant_scan_notify(btcoexist, type) 291 #define ex_halbtc8723b1ant_set_antenna_notify(btcoexist, type) 292 #define ex_halbtc8723b1ant_connect_notify(btcoexist, type) 293 #define ex_halbtc8723b1ant_media_status_notify(btcoexist, type) 294 #define ex_halbtc8723b1ant_specific_packet_notify(btcoexist, type) 295 #define ex_halbtc8723b1ant_bt_info_notify(btcoexist, tmp_buf, length) 296 #define ex_halbtc8723b1ant_rf_status_notify(btcoexist, type) 297 #define ex_halbtc8723b1ant_halt_notify(btcoexist) 298 #define ex_halbtc8723b1ant_pnp_notify(btcoexist, pnp_state) 299 #define ex_halbtc8723b1ant_coex_dm_reset(btcoexist) 300 #define ex_halbtc8723b1ant_periodical(btcoexist) 301 #define ex_halbtc8723b1ant_display_coex_info(btcoexist) 302 #define ex_halbtc8723b1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) 303 #define ex_halbtc8723b1ant_display_ant_detection(btcoexist) 304 305 #endif 306 307 #endif 308 309