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 18 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) 19 20 #if (RTL8723D_SUPPORT == 1) 21 22 /* ******************************************* 23 * The following is for 8723D 1ANT BT Co-exist definition 24 * ******************************************* */ 25 #define BT_8723D_1ANT_COEX_DBG 0 26 #define BT_AUTO_REPORT_ONLY_8723D_1ANT 1 27 28 #define BT_INFO_8723D_1ANT_B_FTP BIT(7) 29 #define BT_INFO_8723D_1ANT_B_A2DP BIT(6) 30 #define BT_INFO_8723D_1ANT_B_HID BIT(5) 31 #define BT_INFO_8723D_1ANT_B_SCO_BUSY BIT(4) 32 #define BT_INFO_8723D_1ANT_B_ACL_BUSY BIT(3) 33 #define BT_INFO_8723D_1ANT_B_INQ_PAGE BIT(2) 34 #define BT_INFO_8723D_1ANT_B_SCO_ESCO BIT(1) 35 #define BT_INFO_8723D_1ANT_B_CONNECTION BIT(0) 36 37 #define BT_INFO_8723D_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ 38 (((_BT_INFO_EXT_&BIT(0))) ? TRUE : FALSE) 39 40 #define BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT 2 41 42 #define BT_8723D_1ANT_WIFI_NOISY_THRESH 30 /* max: 255 */ 43 #define BT_8723D_1ANT_DEFAULT_ISOLATION 15 /* unit: dB */ 44 45 46 /* for Antenna detection */ 47 #define BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 48 #define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 49 #define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 50 #define BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT 35 51 #define BT_8723D_1ANT_ANTDET_RETRY_INTERVAL 10 /* retry timer if ant det is fail, unit: second */ 52 #define BT_8723D_1ANT_ANTDET_SWEEPPOINT_DELAY 60000 53 #define BT_8723D_1ANT_ANTDET_ENABLE 1 54 #define BT_8723D_1ANT_ANTDET_BTTXTIME 100 55 #define BT_8723D_1ANT_ANTDET_BTTXCHANNEL 39 56 #define BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT 50 57 58 #define BT_8723D_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 59 60 enum bt_8723d_1ant_signal_state { 61 BT_8723D_1ANT_SIG_STA_SET_TO_LOW = 0x0, 62 BT_8723D_1ANT_SIG_STA_SET_BY_HW = 0x0, 63 BT_8723D_1ANT_SIG_STA_SET_TO_HIGH = 0x1, 64 BT_8723D_1ANT_SIG_STA_MAX 65 }; 66 67 enum bt_8723d_1ant_path_ctrl_owner { 68 BT_8723D_1ANT_PCO_BTSIDE = 0x0, 69 BT_8723D_1ANT_PCO_WLSIDE = 0x1, 70 BT_8723D_1ANT_PCO_MAX 71 }; 72 73 enum bt_8723d_1ant_gnt_ctrl_type { 74 BT_8723D_1ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, 75 BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW = 0x1, 76 BT_8723D_1ANT_GNT_TYPE_MAX 77 }; 78 79 enum bt_8723d_1ant_gnt_ctrl_block { 80 BT_8723D_1ANT_GNT_BLOCK_RFC_BB = 0x0, 81 BT_8723D_1ANT_GNT_BLOCK_RFC = 0x1, 82 BT_8723D_1ANT_GNT_BLOCK_BB = 0x2, 83 BT_8723D_1ANT_GNT_BLOCK_MAX 84 }; 85 86 enum bt_8723d_1ant_lte_coex_table_type { 87 BT_8723D_1ANT_CTT_WL_VS_LTE = 0x0, 88 BT_8723D_1ANT_CTT_BT_VS_LTE = 0x1, 89 BT_8723D_1ANT_CTT_MAX 90 }; 91 92 enum bt_8723d_1ant_lte_break_table_type { 93 BT_8723D_1ANT_LBTT_WL_BREAK_LTE = 0x0, 94 BT_8723D_1ANT_LBTT_BT_BREAK_LTE = 0x1, 95 BT_8723D_1ANT_LBTT_LTE_BREAK_WL = 0x2, 96 BT_8723D_1ANT_LBTT_LTE_BREAK_BT = 0x3, 97 BT_8723D_1ANT_LBTT_MAX 98 }; 99 100 enum bt_info_src_8723d_1ant { 101 BT_INFO_SRC_8723D_1ANT_WIFI_FW = 0x0, 102 BT_INFO_SRC_8723D_1ANT_BT_RSP = 0x1, 103 BT_INFO_SRC_8723D_1ANT_BT_ACTIVE_SEND = 0x2, 104 BT_INFO_SRC_8723D_1ANT_MAX 105 }; 106 107 enum bt_8723d_1ant_bt_status { 108 BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, 109 BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, 110 BT_8723D_1ANT_BT_STATUS_INQ_PAGE = 0x2, 111 BT_8723D_1ANT_BT_STATUS_ACL_BUSY = 0x3, 112 BT_8723D_1ANT_BT_STATUS_SCO_BUSY = 0x4, 113 BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, 114 BT_8723D_1ANT_BT_STATUS_MAX 115 }; 116 117 enum bt_8723d_1ant_wifi_status { 118 BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, 119 BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, 120 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, 121 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, 122 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, 123 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, 124 BT_8723D_1ANT_WIFI_STATUS_MAX 125 }; 126 127 enum bt_8723d_1ant_coex_algo { 128 BT_8723D_1ANT_COEX_ALGO_UNDEFINED = 0x0, 129 BT_8723D_1ANT_COEX_ALGO_SCO = 0x1, 130 BT_8723D_1ANT_COEX_ALGO_HID = 0x2, 131 BT_8723D_1ANT_COEX_ALGO_A2DP = 0x3, 132 BT_8723D_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, 133 BT_8723D_1ANT_COEX_ALGO_PANEDR = 0x5, 134 BT_8723D_1ANT_COEX_ALGO_PANHS = 0x6, 135 BT_8723D_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, 136 BT_8723D_1ANT_COEX_ALGO_PANEDR_HID = 0x8, 137 BT_8723D_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, 138 BT_8723D_1ANT_COEX_ALGO_HID_A2DP = 0xa, 139 BT_8723D_1ANT_COEX_ALGO_MAX = 0xb, 140 }; 141 142 enum bt_8723d_1ant_phase { 143 BT_8723D_1ANT_PHASE_COEX_INIT = 0x0, 144 BT_8723D_1ANT_PHASE_WLANONLY_INIT = 0x1, 145 BT_8723D_1ANT_PHASE_WLAN_OFF = 0x2, 146 BT_8723D_1ANT_PHASE_2G_RUNTIME = 0x3, 147 BT_8723D_1ANT_PHASE_5G_RUNTIME = 0x4, 148 BT_8723D_1ANT_PHASE_BTMPMODE = 0x5, 149 BT_8723D_1ANT_PHASE_ANTENNA_DET = 0x6, 150 BT_8723D_1ANT_PHASE_COEX_POWERON = 0x7, 151 BT_8723D_1ANT_PHASE_MAX 152 }; 153 154 enum bt_8723d_1ant_Scoreboard { 155 BT_8723D_1ANT_SCOREBOARD_ACTIVE = BIT(0), 156 BT_8723D_1ANT_SCOREBOARD_ONOFF = BIT(1), 157 BT_8723D_1ANT_SCOREBOARD_SCAN = BIT(2), 158 BT_8723D_1ANT_SCOREBOARD_UNDERTEST = BIT(3), 159 BT_8723D_1ANT_SCOREBOARD_WLBUSY = BIT(6) 160 }; 161 162 struct coex_dm_8723d_1ant { 163 /* hw setting */ 164 u8 pre_ant_pos_type; 165 u8 cur_ant_pos_type; 166 /* fw mechanism */ 167 boolean cur_ignore_wlan_act; 168 boolean pre_ignore_wlan_act; 169 u8 pre_ps_tdma; 170 u8 cur_ps_tdma; 171 u8 ps_tdma_para[5]; 172 u8 ps_tdma_du_adj_type; 173 boolean pre_ps_tdma_on; 174 boolean cur_ps_tdma_on; 175 boolean pre_bt_auto_report; 176 boolean cur_bt_auto_report; 177 u8 pre_lps; 178 u8 cur_lps; 179 u8 pre_rpwm; 180 u8 cur_rpwm; 181 182 /* sw mechanism */ 183 boolean pre_low_penalty_ra; 184 boolean cur_low_penalty_ra; 185 u32 pre_val0x6c0; 186 u32 cur_val0x6c0; 187 u32 pre_val0x6c4; 188 u32 cur_val0x6c4; 189 u32 pre_val0x6c8; 190 u32 cur_val0x6c8; 191 u8 pre_val0x6cc; 192 u8 cur_val0x6cc; 193 boolean limited_dig; 194 195 u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ 196 u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ 197 u16 backup_retry_limit; 198 u8 backup_ampdu_max_time; 199 200 /* algorithm related */ 201 u8 pre_algorithm; 202 u8 cur_algorithm; 203 u8 bt_status; 204 u8 wifi_chnl_info[3]; 205 206 u32 pre_ra_mask; 207 u32 cur_ra_mask; 208 u8 pre_arfr_type; 209 u8 cur_arfr_type; 210 u8 pre_retry_limit_type; 211 u8 cur_retry_limit_type; 212 u8 pre_ampdu_time_type; 213 u8 cur_ampdu_time_type; 214 u32 arp_cnt; 215 216 u8 error_condition; 217 }; 218 219 struct coex_sta_8723d_1ant { 220 boolean bt_disabled; 221 boolean bt_link_exist; 222 boolean sco_exist; 223 boolean a2dp_exist; 224 boolean hid_exist; 225 boolean pan_exist; 226 boolean bt_hi_pri_link_exist; 227 u8 num_of_profile; 228 229 boolean under_lps; 230 boolean under_ips; 231 u32 specific_pkt_period_cnt; 232 u32 high_priority_tx; 233 u32 high_priority_rx; 234 u32 low_priority_tx; 235 u32 low_priority_rx; 236 boolean is_hiPri_rx_overhead; 237 s8 bt_rssi; 238 boolean bt_tx_rx_mask; 239 u8 pre_bt_rssi_state; 240 u8 pre_wifi_rssi_state[4]; 241 u8 bt_info_c2h[BT_INFO_SRC_8723D_1ANT_MAX][10]; 242 u32 bt_info_c2h_cnt[BT_INFO_SRC_8723D_1ANT_MAX]; 243 boolean bt_whck_test; 244 boolean c2h_bt_inquiry_page; 245 boolean c2h_bt_remote_name_req; 246 boolean c2h_bt_page; /* Add for win8.1 page out issue */ 247 boolean wifi_is_high_pri_task; /* Add for win8.1 page out issue */ 248 u8 bt_retry_cnt; 249 u8 bt_info_ext; 250 u8 bt_info_ext2; 251 u32 pop_event_cnt; 252 u8 scan_ap_num; 253 254 u32 crc_ok_cck; 255 u32 crc_ok_11g; 256 u32 crc_ok_11n; 257 u32 crc_ok_11n_vht; 258 259 u32 crc_err_cck; 260 u32 crc_err_11g; 261 u32 crc_err_11n; 262 u32 crc_err_11n_vht; 263 264 boolean cck_lock; 265 boolean cck_lock_ever; 266 boolean cck_lock_warn; 267 268 u8 coex_table_type; 269 boolean force_lps_ctrl; 270 boolean concurrent_rx_mode_on; 271 272 u16 score_board; 273 u8 isolation_btween_wb; /* 0~ 50 */ 274 275 u8 a2dp_bit_pool; 276 u8 cut_version; 277 boolean acl_busy; 278 boolean bt_create_connection; 279 280 u32 bt_coex_supported_feature; 281 u32 bt_coex_supported_version; 282 283 u8 bt_ble_scan_type; 284 u32 bt_ble_scan_para[3]; 285 286 boolean run_time_state; 287 boolean freeze_coexrun_by_btinfo; 288 289 boolean is_A2DP_3M; 290 boolean voice_over_HOGP; 291 u8 bt_info; 292 boolean is_autoslot; 293 u8 forbidden_slot; 294 u8 hid_busy_num; 295 u8 hid_pair_cnt; 296 297 u32 cnt_RemoteNameReq; 298 u32 cnt_setupLink; 299 u32 cnt_ReInit; 300 u32 cnt_IgnWlanAct; 301 u32 cnt_Page; 302 u32 cnt_RoleSwitch; 303 304 u16 bt_reg_vendor_ac; 305 u16 bt_reg_vendor_ae; 306 307 boolean is_setupLink; 308 u8 wl_noisy_level; 309 u32 gnt_error_cnt; 310 311 u8 bt_afh_map[10]; 312 u8 bt_relink_downcount; 313 boolean is_tdma_btautoslot; 314 boolean is_tdma_btautoslot_hang; 315 316 boolean is_rf_state_off; 317 318 boolean is_hid_low_pri_tx_overhead; 319 boolean is_bt_multi_link; 320 boolean is_bt_a2dp_sink; 321 322 u8 wl_fw_dbg_info[10]; 323 u8 wl_rx_rate; 324 u8 wl_rts_rx_rate; 325 326 u16 score_board_WB; 327 }; 328 329 #define BT_8723D_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ 330 #define BT_8723D_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ 331 #define BT_8723D_1ANT_ANTDET_BUF_LEN 16 332 333 struct psdscan_sta_8723d_1ant { 334 335 u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ 336 u32 ant_det_bt_tx_time; 337 u32 ant_det_pre_psdscan_peak_val; 338 boolean ant_det_is_ant_det_available; 339 u32 ant_det_psd_scan_peak_val; 340 boolean ant_det_is_btreply_available; 341 u32 ant_det_psd_scan_peak_freq; 342 343 u8 ant_det_result; 344 u8 ant_det_peak_val[BT_8723D_1ANT_ANTDET_BUF_LEN]; 345 u8 ant_det_peak_freq[BT_8723D_1ANT_ANTDET_BUF_LEN]; 346 u32 ant_det_try_count; 347 u32 ant_det_fail_count; 348 u32 ant_det_inteval_count; 349 u32 ant_det_thres_offset; 350 351 u32 real_cent_freq; 352 s32 real_offset; 353 u32 real_span; 354 355 u32 psd_band_width; /* unit: Hz */ 356 u32 psd_point; /* 128/256/512/1024 */ 357 u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ 358 u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ 359 u32 psd_start_point; 360 u32 psd_stop_point; 361 u32 psd_max_value_point; 362 u32 psd_max_value; 363 u32 psd_max_value2; 364 u32 psd_avg_value; /* filter loop_max_value that below BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT, and average the rest*/ 365 u32 psd_loop_max_value[BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT]; /*max value in each loop */ 366 u32 psd_start_base; 367 u32 psd_avg_num; /* 1/8/16/32 */ 368 u32 psd_gen_count; 369 boolean is_AntDet_running; 370 boolean is_psd_show_max_only; 371 }; 372 373 /* ******************************************* 374 * The following is interface which will notify coex module. 375 * ******************************************* */ 376 void ex_halbtc8723d1ant_power_on_setting(IN struct btc_coexist *btcoexist); 377 void ex_halbtc8723d1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); 378 void ex_halbtc8723d1ant_init_hw_config(IN struct btc_coexist *btcoexist, 379 IN boolean wifi_only); 380 void ex_halbtc8723d1ant_init_coex_dm(IN struct btc_coexist *btcoexist); 381 void ex_halbtc8723d1ant_ips_notify(IN struct btc_coexist *btcoexist, 382 IN u8 type); 383 void ex_halbtc8723d1ant_lps_notify(IN struct btc_coexist *btcoexist, 384 IN u8 type); 385 void ex_halbtc8723d1ant_scan_notify(IN struct btc_coexist *btcoexist, 386 IN u8 type); 387 void ex_halbtc8723d1ant_connect_notify(IN struct btc_coexist *btcoexist, 388 IN u8 type); 389 void ex_halbtc8723d1ant_media_status_notify(IN struct btc_coexist *btcoexist, 390 IN u8 type); 391 void ex_halbtc8723d1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, 392 IN u8 type); 393 void ex_halbtc8723d1ant_bt_info_notify(IN struct btc_coexist *btcoexist, 394 IN u8 *tmp_buf, IN u8 length); 395 void ex_halbtc8723d1ant_wl_fwdbginfo_notify(IN struct btc_coexist *btcoexist, 396 IN u8 *tmp_buf, IN u8 length); 397 void ex_halbtc8723d1ant_rx_rate_change_notify(IN struct btc_coexist *btcoexist, 398 IN BOOLEAN is_data_frame, IN u8 btc_rate_id); 399 void ex_halbtc8723d1ant_rf_status_notify(IN struct btc_coexist *btcoexist, 400 IN u8 type); 401 void ex_halbtc8723d1ant_halt_notify(IN struct btc_coexist *btcoexist); 402 void ex_halbtc8723d1ant_pnp_notify(IN struct btc_coexist *btcoexist, 403 IN u8 pnp_state); 404 void ex_halbtc8723d1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); 405 void ex_halbtc8723d1ant_periodical(IN struct btc_coexist *btcoexist); 406 void ex_halbtc8723d1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, 407 IN u8 type); 408 void ex_halbtc8723d1ant_display_coex_info(IN struct btc_coexist *btcoexist); 409 void ex_halbtc8723d1ant_antenna_detection(IN struct btc_coexist *btcoexist, 410 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 411 void ex_halbtc8723d1ant_antenna_isolation(IN struct btc_coexist *btcoexist, 412 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 413 414 void ex_halbtc8723d1ant_psd_scan(IN struct btc_coexist *btcoexist, 415 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 416 void ex_halbtc8723d1ant_display_ant_detection(IN struct btc_coexist *btcoexist); 417 418 #else 419 #define ex_halbtc8723d1ant_power_on_setting(btcoexist) 420 #define ex_halbtc8723d1ant_pre_load_firmware(btcoexist) 421 #define ex_halbtc8723d1ant_init_hw_config(btcoexist, wifi_only) 422 #define ex_halbtc8723d1ant_init_coex_dm(btcoexist) 423 #define ex_halbtc8723d1ant_ips_notify(btcoexist, type) 424 #define ex_halbtc8723d1ant_lps_notify(btcoexist, type) 425 #define ex_halbtc8723d1ant_scan_notify(btcoexist, type) 426 #define ex_halbtc8723d1ant_connect_notify(btcoexist, type) 427 #define ex_halbtc8723d1ant_media_status_notify(btcoexist, type) 428 #define ex_halbtc8723d1ant_specific_packet_notify(btcoexist, type) 429 #define ex_halbtc8723d1ant_bt_info_notify(btcoexist, tmp_buf, length) 430 #define ex_halbtc8723d1ant_wl_fwdbginfo_notify(btcoexist, tmp_buf, length) 431 #define ex_halbtc8723d1ant_rx_rate_change_notify(btcoexist, is_data_frame, btc_rate_id) 432 #define ex_halbtc8723d1ant_rf_status_notify(btcoexist, type) 433 #define ex_halbtc8723d1ant_halt_notify(btcoexist) 434 #define ex_halbtc8723d1ant_pnp_notify(btcoexist, pnp_state) 435 #define ex_halbtc8723d1ant_coex_dm_reset(btcoexist) 436 #define ex_halbtc8723d1ant_periodical(btcoexist) 437 #define ex_halbtc8723d1ant_display_coex_info(btcoexist) 438 #define ex_halbtc8723d1ant_set_antenna_notify(btcoexist, type) 439 #define ex_halbtc8723d1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) 440 #define ex_halbtc8723d1ant_antenna_isolation(btcoexist, cent_freq, offset, span, seconds) 441 #define ex_halbtc8723d1ant_psd_scan(btcoexist, cent_freq, offset, span, seconds) 442 #define ex_halbtc8723d1ant_display_ant_detection(btcoexist) 443 #endif 444 445 #endif 446 447