1 /******************************************************************************
3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
21 #include "halbt_precomp.h"
23 /*#if(BT_30_SUPPORT == 1)*/
25 /***********************************************
27 ***********************************************/
28 static const char *const bt_profile_string[] = {
36 static const char *const bt_spec_string[] = {
46 static const char *const bt_link_role_string[] = {
51 static const char *const h2c_state_string[] = {
58 static const char *const io_state_string[] = {
60 "IO_STATUS_FAIL_CANNOT_IO",
61 "IO_STATUS_FAIL_RF_OFF",
62 "IO_STATUS_FAIL_FW_READ_CLEAR_TIMEOUT",
63 "IO_STATUS_FAIL_WAIT_IO_EVENT_TIMEOUT",
64 "IO_STATUS_INVALID_LEN",
65 "IO_STATUS_IO_IDLE_QUEUE_EMPTY",
66 "IO_STATUS_IO_INSERT_WAIT_QUEUE_FAIL",
67 "IO_STATUS_UNKNOWN_FAIL",
68 "IO_STATUS_WRONG_LEVEL",
69 "IO_STATUS_H2C_STOPPED",
72 struct btc_coexist gl_bt_coexist;
74 u32 btc_dbg_type[BTC_MSG_MAX];
75 static u8 btc_dbg_buf[100];
77 /***************************************************
78 * Debug related function
79 ***************************************************/
80 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
82 if (!btcoexist->binded || NULL == btcoexist->adapter)
88 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
91 if (rtlpriv->link_info.b_busytraffic)
98 static void halbtc_dbg_init(void)
102 for (i = 0; i < BTC_MSG_MAX; i++)
105 btc_dbg_type[BTC_MSG_INTERFACE] = \
110 btc_dbg_type[BTC_MSG_ALGORITHM] = \
111 // ALGO_BT_RSSI_STATE |
112 // ALGO_WIFI_RSSI_STATE |
116 // ALGO_TRACE_FW_DETAIL |
117 // ALGO_TRACE_FW_EXEC |
119 // ALGO_TRACE_SW_DETAIL |
120 // ALGO_TRACE_SW_EXEC |
124 static bool halbtc_is_bt40(struct rtl_priv *adapter)
126 struct rtl_priv *rtlpriv = adapter;
127 struct rtl_phy *rtlphy = &(rtlpriv->phy);
129 enum ht_channel_width bw = rtlphy->current_chan_bw;
132 if (bw == HT_CHANNEL_WIDTH_20)
134 else if (bw == HT_CHANNEL_WIDTH_20_40)
140 static bool halbtc_legacy(struct rtl_priv *adapter)
142 struct rtl_priv *rtlpriv = adapter;
143 struct rtl_mac *mac = rtl_mac(rtlpriv);
145 bool is_legacy = false;
147 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_B))
153 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
155 struct rtl_priv *rtlpriv = adapter;
157 if (rtlpriv->link_info.b_tx_busy_traffic)
163 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
165 struct rtl_priv *rtlpriv =
166 (struct rtl_priv *)btcoexist->adapter;
167 u32 wifi_bw = BTC_WIFI_BW_HT20;
169 if (halbtc_is_bt40(rtlpriv)){
170 wifi_bw = BTC_WIFI_BW_HT40;
172 if(halbtc_legacy(rtlpriv))
173 wifi_bw = BTC_WIFI_BW_LEGACY;
175 wifi_bw = BTC_WIFI_BW_HT20;
180 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
182 struct rtl_priv *rtlpriv = btcoexist->adapter;
183 struct rtl_phy *rtlphy = &(rtlpriv->phy);
187 if (rtlphy->current_channel != 0)
188 chnl = rtlphy->current_channel;
189 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
190 "halbtc_get_wifi_central_chnl:%d\n",chnl);
194 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
196 struct rtl_priv *rtlpriv;
197 struct rtl_ps_ctl *ppsc;
198 bool ap_enable = false;
200 rtlpriv = btcoexist->adapter;
201 ppsc = rtl_psc(rtlpriv);
203 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
207 printk("halbtc_leave_lps()<--dont leave lps under AP mode\n");
211 btcoexist->bt_info.bt_ctrl_lps = true;
212 btcoexist->bt_info.bt_lps_on = false;
215 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
217 struct rtl_priv *rtlpriv;
218 struct rtl_ps_ctl *ppsc;
219 bool ap_enable = false;
221 rtlpriv = btcoexist->adapter;
222 ppsc = rtl_psc(rtlpriv);
224 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
228 printk("halbtc_enter_lps()<--dont enter lps under AP mode\n");
232 btcoexist->bt_info.bt_ctrl_lps = true;
233 btcoexist->bt_info.bt_lps_on = false;
236 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
238 if (btcoexist->bt_info.bt_ctrl_lps) {
239 btcoexist->bt_info.bt_lps_on = false;
240 btcoexist->bt_info.bt_ctrl_lps = false;
245 static void halbtc_leave_low_power(void)
249 static void halbtc_nomal_low_power(void)
253 static void halbtc_disable_low_power(void)
257 static void halbtc_aggregation_check(void)
262 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
267 static s32 halbtc_get_wifi_rssi(struct rtl_priv *adapter)
269 struct rtl_priv *rtlpriv = adapter;
270 s32 undecorated_smoothed_pwdb = 0;
272 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
273 undecorated_smoothed_pwdb =
274 rtlpriv->dm.undecorated_smoothed_pwdb;
275 else /* associated entry pwdb */
276 undecorated_smoothed_pwdb =
277 rtlpriv->dm.undecorated_smoothed_pwdb;
278 return undecorated_smoothed_pwdb;
281 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
283 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
284 struct rtl_priv *rtlpriv = btcoexist->adapter;
285 struct rtl_phy *rtlphy = &(rtlpriv->phy);
286 struct rtl_mac *mac = rtl_mac(rtlpriv);
287 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
288 bool *bool_tmp = (bool*)out_buf;
289 int *s32_tmp = (int*)out_buf;
290 u32 *u32_tmp = (u32*)out_buf;
291 u8 *u8_tmp = (u8*)out_buf;
295 if (!halbtc_is_bt_coexist_available(btcoexist))
300 case BTC_GET_BL_HS_OPERATION:
303 case BTC_GET_BL_HS_CONNECTING:
306 case BTC_GET_BL_WIFI_CONNECTED:
307 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
312 case BTC_GET_BL_WIFI_BUSY:
313 if(halbtc_is_wifi_busy(rtlpriv))
318 case BTC_GET_BL_WIFI_SCAN:
319 if (mac->act_scanning == true)
324 case BTC_GET_BL_WIFI_LINK:
325 if (mac->link_state == MAC80211_LINKING)
330 case BTC_GET_BL_WIFI_ROAM: /*TODO*/
331 if (mac->link_state == MAC80211_LINKING)
336 case BTC_GET_BL_WIFI_4_WAY_PROGRESS: /*TODO*/
340 case BTC_GET_BL_WIFI_UNDER_5G:
341 *bool_tmp = false; /*TODO*/
343 case BTC_GET_BL_WIFI_DHCP: /*TODO*/
345 case BTC_GET_BL_WIFI_SOFTAP_IDLE:
348 case BTC_GET_BL_WIFI_SOFTAP_LINKING:
351 case BTC_GET_BL_WIFI_IN_EARLY_SUSPEND:
354 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
357 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
358 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
363 case BTC_GET_BL_WIFI_UNDER_B_MODE:
364 *bool_tmp = false; /*TODO*/
366 case BTC_GET_BL_EXT_SWITCH:
369 case BTC_GET_S4_WIFI_RSSI:
370 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
372 case BTC_GET_S4_HS_RSSI: /*TODO*/
373 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
375 case BTC_GET_U4_WIFI_BW:
376 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
378 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
379 if (halbtc_is_wifi_uplink(rtlpriv))
380 *u32_tmp = BTC_WIFI_TRAFFIC_TX;
382 *u32_tmp = BTC_WIFI_TRAFFIC_RX;
384 case BTC_GET_U4_WIFI_FW_VER:
385 *u32_tmp = rtlhal->fw_version;
387 case BTC_GET_U4_BT_PATCH_VER:
388 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
390 case BTC_GET_U1_WIFI_DOT11_CHNL:
391 *u8_tmp = rtlphy->current_channel;
393 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
394 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
396 case BTC_GET_U1_WIFI_HS_CHNL:
397 *u8_tmp = 1;/* BT_OperateChnl(rtlpriv); */
399 case BTC_GET_U1_MAC_PHY_MODE:
400 *u8_tmp = BTC_MP_UNKNOWN;
402 case BTC_GET_U1_AP_NUM:
403 /* driver don't know AP num in Linux,
404 * So, the return value here is not right */
405 *u8_tmp = 1;/* pDefMgntInfo->NumBssDesc4Query; */
408 /************* 1Ant **************/
409 case BTC_GET_U1_LPS_MODE:
410 *u8_tmp = btcoexist->pwr_mode_val[0];
420 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
422 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
423 bool *bool_tmp = (bool *)in_buf;
424 u8 *u8_tmp = (u8 *)in_buf;
425 u32 *u32_tmp = (u32 *)in_buf;
428 if (!halbtc_is_bt_coexist_available(btcoexist))
432 /* set some bool type variables. */
433 case BTC_SET_BL_BT_DISABLE:
434 btcoexist->bt_info.bt_disabled = *bool_tmp;
436 case BTC_SET_BL_BT_TRAFFIC_BUSY:
437 btcoexist->bt_info.bt_busy = *bool_tmp;
439 case BTC_SET_BL_BT_LIMITED_DIG:
440 btcoexist->bt_info.limited_dig = *bool_tmp;
442 case BTC_SET_BL_FORCE_TO_ROAM:
443 btcoexist->bt_info.force_to_roam = *bool_tmp;
445 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
446 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
448 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
449 btcoexist->bt_info.b_bt_ctrl_buf_size = *bool_tmp;
451 case BTC_SET_BL_INC_SCAN_DEV_NUM:
452 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
454 /* set some u1Byte type variables. */
455 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
456 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
458 case BTC_SET_U1_AGG_BUF_SIZE:
459 btcoexist->bt_info.agg_buf_size = *u8_tmp;
461 /* the following are some action which will be triggered */
462 case BTC_SET_ACT_GET_BT_RSSI:
463 /*BTHCI_SendGetBtRssiEvent(rtlpriv);*/
465 case BTC_SET_ACT_AGGREGATE_CTRL:
466 halbtc_aggregation_check();
470 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
471 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
473 case BTC_SET_UI_SCAN_SIG_COMPENSATION:
474 /* rtlpriv->mlmepriv.scan_compensation = *u8_tmp; */
476 case BTC_SET_U1_1ANT_LPS:
477 btcoexist->bt_info.lps_1ant = *u8_tmp;
479 case BTC_SET_U1_1ANT_RPWM:
480 btcoexist->bt_info.rpwm_1ant = *u8_tmp;
482 /* the following are some action which will be triggered */
483 case BTC_SET_ACT_LEAVE_LPS:
484 halbtc_leave_lps(btcoexist);
486 case BTC_SET_ACT_ENTER_LPS:
487 halbtc_enter_lps(btcoexist);
489 case BTC_SET_ACT_NORMAL_LPS:
490 halbtc_normal_lps(btcoexist);
492 case BTC_SET_ACT_DISABLE_LOW_POWER:
493 halbtc_disable_low_power();
495 case BTC_SET_ACT_UPDATE_ra_mask:
496 btcoexist->bt_info.ra_mask = *u32_tmp;
498 case BTC_SET_ACT_SEND_MIMO_PS:
500 case BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT:
501 btcoexist->bt_info.force_exec_pwr_cmd_cnt++;
503 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
505 case BTC_SET_ACT_CTRL_BT_COEX:
514 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist)
518 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist)
522 static void halbtc_display_bt_fw_info(struct btc_coexist *btcoexist)
526 static void halbtc_display_fw_pwr_mode_cmd(struct btc_coexist *btcoexist)
530 /************************************************************
531 * IO related function
532 ************************************************************/
533 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
535 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
536 struct rtl_priv *rtlpriv = btcoexist->adapter;
538 return rtl_read_byte(rtlpriv, reg_addr);
542 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
544 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
545 struct rtl_priv *rtlpriv = btcoexist->adapter;
547 return rtl_read_word(rtlpriv, reg_addr);
551 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
553 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
554 struct rtl_priv *rtlpriv = btcoexist->adapter;
556 return rtl_read_dword(rtlpriv, reg_addr);
560 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u8 data)
562 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
563 struct rtl_priv *rtlpriv = btcoexist->adapter;
565 rtl_write_byte(rtlpriv, reg_addr, data);
568 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
569 u8 bit_mask, u8 data)
571 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
572 struct rtl_priv *rtlpriv = btcoexist->adapter;
573 u8 original_value, bit_shift = 0;
576 if (bit_mask != MASKDWORD) {/*if not "double word" write*/
577 original_value = rtl_read_byte(rtlpriv, reg_addr);
578 for (i=0; i<=7; i++) {
579 if((bit_mask>>i)&0x1)
583 data = (original_value & (~bit_mask)) |
584 ((data << bit_shift) & bit_mask);
586 rtl_write_byte(rtlpriv, reg_addr, data);
590 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
592 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
593 struct rtl_priv *rtlpriv = btcoexist->adapter;
595 rtl_write_word(rtlpriv, reg_addr, data);
599 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
601 struct btc_coexist *btcoexist =
602 (struct btc_coexist *)bt_context;
603 struct rtl_priv *rtlpriv = btcoexist->adapter;
605 rtl_write_dword(rtlpriv, reg_addr, data);
608 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr,
609 u32 bit_mask, u32 data)
611 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
612 struct rtl_priv *rtlpriv = btcoexist->adapter;
614 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
618 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
620 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
621 struct rtl_priv *rtlpriv = btcoexist->adapter;
623 return rtl_get_bbreg(rtlpriv->mac80211.hw,reg_addr, bit_mask);
627 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
628 u32 bit_mask, u32 data)
630 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
631 struct rtl_priv *rtlpriv = btcoexist->adapter;
633 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
637 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path,
638 u32 reg_addr, u32 bit_mask)
640 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
641 struct rtl_priv *rtlpriv = btcoexist->adapter;
643 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
647 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
648 u32 cmd_len, u8 *cmd_buf)
650 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
651 struct rtl_priv *rtlpriv = btcoexist->adapter;
653 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
657 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type)
659 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
661 case BTC_DBG_DISP_COEX_STATISTICS:
662 halbtc_display_coex_statistics(btcoexist);
664 case BTC_DBG_DISP_BT_LINK_INFO:
665 halbtc_display_bt_link_info(btcoexist);
667 case BTC_DBG_DISP_BT_FW_VER:
668 halbtc_display_bt_fw_info(btcoexist);
670 case BTC_DBG_DISP_FW_PWR_MODE_CMD:
671 halbtc_display_fw_pwr_mode_cmd(btcoexist);
678 /*****************************************************************
679 * Extern functions called by other module
680 *****************************************************************/
681 bool exhalbtc_initlize_variables(struct rtl_priv *adapter)
683 struct btc_coexist *btcoexist = &gl_bt_coexist;
685 btcoexist->statistics.cnt_bind++;
689 if (btcoexist->binded)
692 btcoexist->binded = true;
694 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
696 if (NULL == btcoexist->adapter)
697 btcoexist->adapter = adapter;
699 btcoexist->stack_info.profile_notified = false;
701 btcoexist->btc_read_1byte = halbtc_read_1byte;
702 btcoexist->btc_write_1byte = halbtc_write_1byte;
703 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
704 btcoexist->btc_read_2byte = halbtc_read_2byte;
705 btcoexist->btc_write_2byte = halbtc_write_2byte;
706 btcoexist->btc_read_4byte = halbtc_read_4byte;
707 btcoexist->btc_write_4byte = halbtc_write_4byte;
709 btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
710 btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
712 btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
713 btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
715 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
716 btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
718 btcoexist->btc_get = halbtc_get;
719 btcoexist->btc_set = halbtc_set;
721 btcoexist->cli_buf = &btc_dbg_buf[0];
723 btcoexist->bt_info.b_bt_ctrl_buf_size = false;
724 btcoexist->bt_info.agg_buf_size = 5;
726 btcoexist->bt_info.increase_scan_dev_num = false;
730 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist)
732 struct rtl_priv *rtlpriv = btcoexist->adapter;
733 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
735 if (!halbtc_is_bt_coexist_available(btcoexist))
738 btcoexist->statistics.cnt_init_hw_config++;
740 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
741 if (btcoexist->board_info.btdm_ant_num == 2)
742 ex_halbtc8723b2ant_init_hwconfig(btcoexist);
743 else if(btcoexist->board_info.btdm_ant_num == 1)
744 ex_halbtc8723b1ant_init_hwconfig(btcoexist);
745 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
746 ex_halbtc8192e2ant_init_hwconfig(btcoexist);
751 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
753 struct rtl_priv *rtlpriv = btcoexist->adapter;
754 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
756 if (!halbtc_is_bt_coexist_available(btcoexist))
759 btcoexist->statistics.cnt_init_coex_dm++;
761 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
762 if (btcoexist->board_info.btdm_ant_num == 2)
763 ex_halbtc8723b2ant_init_coex_dm(btcoexist);
764 else if(btcoexist->board_info.btdm_ant_num == 1)
765 ex_halbtc8723b1ant_init_coex_dm(btcoexist);
766 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
767 ex_halbtc8192e2ant_init_coex_dm(btcoexist);
770 btcoexist->initilized = true;
773 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
775 struct rtl_priv *rtlpriv = btcoexist->adapter;
776 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
779 if (!halbtc_is_bt_coexist_available(btcoexist))
781 btcoexist->statistics.cnt_ips_notify++;
782 if (btcoexist->manual_control)
786 ips_type = BTC_IPS_ENTER;
788 ips_type = BTC_IPS_LEAVE;
790 halbtc_leave_low_power();
792 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
793 if (btcoexist->board_info.btdm_ant_num == 2)
794 ex_halbtc8723b2ant_ips_notify(btcoexist, ips_type);
795 else if(btcoexist->board_info.btdm_ant_num == 1)
796 ex_halbtc8723b1ant_ips_notify(btcoexist, ips_type);
797 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
798 ex_halbtc8192e2ant_ips_notify(btcoexist, ips_type);
801 halbtc_nomal_low_power();
804 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
806 struct rtl_priv *rtlpriv = btcoexist->adapter;
807 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
810 if (!halbtc_is_bt_coexist_available(btcoexist))
812 btcoexist->statistics.cnt_lps_notify++;
813 if (btcoexist->manual_control)
817 lps_type = BTC_LPS_DISABLE;
819 lps_type = BTC_LPS_ENABLE;
821 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
822 if (btcoexist->board_info.btdm_ant_num == 2)
823 ex_halbtc8723b2ant_lps_notify(btcoexist, lps_type);
824 else if(btcoexist->board_info.btdm_ant_num == 1)
825 ex_halbtc8723b1ant_lps_notify(btcoexist, lps_type);
826 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
827 ex_halbtc8192e2ant_lps_notify(btcoexist, lps_type);
831 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
833 struct rtl_priv *rtlpriv = btcoexist->adapter;
834 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
837 if (!halbtc_is_bt_coexist_available(btcoexist))
839 btcoexist->statistics.cnt_scan_notify++;
840 if (btcoexist->manual_control)
844 scan_type = BTC_SCAN_START;
846 scan_type = BTC_SCAN_FINISH;
848 halbtc_leave_low_power();
850 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
851 if (btcoexist->board_info.btdm_ant_num == 2)
852 ex_halbtc8723b2ant_scan_notify(btcoexist, scan_type);
853 else if(btcoexist->board_info.btdm_ant_num == 1)
854 ex_halbtc8723b1ant_scan_notify(btcoexist, scan_type);
855 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
856 ex_halbtc8192e2ant_scan_notify(btcoexist, scan_type);
859 halbtc_nomal_low_power();
862 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
864 struct rtl_priv *rtlpriv = btcoexist->adapter;
865 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
868 if (!halbtc_is_bt_coexist_available(btcoexist))
870 btcoexist->statistics.cnt_connect_notify++;
871 if (btcoexist->manual_control)
875 asso_type = BTC_ASSOCIATE_START;
877 asso_type = BTC_ASSOCIATE_FINISH;
879 halbtc_leave_low_power();
881 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
882 if (btcoexist->board_info.btdm_ant_num == 2)
883 ex_halbtc8723b2ant_connect_notify(btcoexist, asso_type);
884 else if(btcoexist->board_info.btdm_ant_num == 1)
885 ex_halbtc8723b1ant_connect_notify(btcoexist, asso_type);
886 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
887 ex_halbtc8192e2ant_connect_notify(btcoexist, asso_type);
890 halbtc_nomal_low_power();
893 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
894 enum rt_media_status media_status)
896 struct rtl_priv *rtlpriv = btcoexist->adapter;
897 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
900 if (!halbtc_is_bt_coexist_available(btcoexist))
902 btcoexist->statistics.cnt_media_status_notify++;
903 if (btcoexist->manual_control)
906 if (RT_MEDIA_CONNECT == media_status)
907 status = BTC_MEDIA_CONNECT;
909 status = BTC_MEDIA_DISCONNECT;
911 halbtc_leave_low_power();
913 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
914 if (btcoexist->board_info.btdm_ant_num == 2)
915 ex_halbtc8723b2ant_media_status_notify(btcoexist, status);
916 else if(btcoexist->board_info.btdm_ant_num == 1)
917 ex_halbtc8723b1ant_media_status_notify(btcoexist, status);
918 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
919 ex_halbtc8192e2ant_media_status_notify(btcoexist, status);
922 halbtc_nomal_low_power();
925 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
929 if (!halbtc_is_bt_coexist_available(btcoexist))
931 btcoexist->statistics.cnt_special_packet_notify++;
932 if (btcoexist->manual_control)
935 /*if(PACKET_DHCP == pkt_type)*/
936 packet_type = BTC_PACKET_DHCP;
937 /*else if(PACKET_EAPOL == pkt_type)
938 packet_type = BTC_PACKET_EAPOL;
940 packet_type = BTC_PACKET_UNKNOWN;*/
942 halbtc_leave_low_power();
944 if (btcoexist->board_info.btdm_ant_num == 2)
945 ex_halbtc8723b2ant_special_packet_notify(btcoexist,
947 else if (btcoexist->board_info.btdm_ant_num == 1)
948 ex_halbtc8723b1ant_special_packet_notify(btcoexist,
951 halbtc_nomal_low_power();
954 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
955 u8 *tmp_buf, u8 length)
957 struct rtl_priv *rtlpriv = btcoexist->adapter;
958 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
959 if (!halbtc_is_bt_coexist_available(btcoexist))
961 btcoexist->statistics.cnt_bt_info_notify++;
963 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
964 if (btcoexist->board_info.btdm_ant_num == 2)
965 ex_halbtc8723b2ant_bt_info_notify(btcoexist, tmp_buf, length);
966 else if(btcoexist->board_info.btdm_ant_num == 1)
967 ex_halbtc8723b1ant_bt_info_notify(btcoexist, tmp_buf, length);
968 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
969 // ex_halbtc8192e2ant_bt_info_notify(btcoexist, tmp_buf, length);
973 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
977 if (!halbtc_is_bt_coexist_available(btcoexist))
979 btcoexist->statistics.cnt_stack_operation_notify++;
980 if (btcoexist->manual_control)
983 stack_op_type = BTC_STACK_OP_NONE;
986 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
988 struct rtl_priv *rtlpriv = btcoexist->adapter;
989 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
990 if (!halbtc_is_bt_coexist_available(btcoexist))
993 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
994 if (btcoexist->board_info.btdm_ant_num == 2)
995 ex_halbtc8723b2ant_halt_notify(btcoexist);
996 else if(btcoexist->board_info.btdm_ant_num == 1)
997 ex_halbtc8723b1ant_halt_notify(btcoexist);
998 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
999 ex_halbtc8192e2ant_halt_notify(btcoexist);
1003 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1005 if (!halbtc_is_bt_coexist_available(btcoexist))
1009 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1011 struct rtl_priv *rtlpriv = btcoexist->adapter;
1012 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1013 if (!halbtc_is_bt_coexist_available(btcoexist))
1015 btcoexist->statistics.cnt_periodical++;
1017 halbtc_leave_low_power();
1019 if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
1020 if (btcoexist->board_info.btdm_ant_num == 2)
1021 ex_halbtc8723b2ant_periodical(btcoexist);
1022 else if(btcoexist->board_info.btdm_ant_num == 1)
1023 ex_halbtc8723b1ant_periodical(btcoexist);
1024 } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
1025 ex_halbtc8192e2ant_periodical(btcoexist);
1028 halbtc_nomal_low_power();
1031 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1032 u8 code, u8 len, u8 *data)
1034 if (!halbtc_is_bt_coexist_available(btcoexist))
1036 btcoexist->statistics.cnt_dbg_ctrl++;
1039 void exhalbtc_stack_update_profile_info(void)
1043 void exhalbtc_update_min_bt_rssi(char bt_rssi)
1045 struct btc_coexist *btcoexist = &gl_bt_coexist;
1047 if (!halbtc_is_bt_coexist_available(btcoexist))
1050 btcoexist->stack_info.min_bt_rssi = bt_rssi;
1054 void exhalbtc_set_hci_version(u16 hci_version)
1056 struct btc_coexist *btcoexist = &gl_bt_coexist;
1058 if (!halbtc_is_bt_coexist_available(btcoexist))
1061 btcoexist->stack_info.hci_version = hci_version;
1064 void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version)
1066 struct btc_coexist *btcoexist = &gl_bt_coexist;
1068 if (!halbtc_is_bt_coexist_available(btcoexist))
1071 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1072 btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1075 void exhalbtc_set_bt_exist(bool bt_exist)
1077 gl_bt_coexist.board_info.bt_exist = bt_exist;
1080 void exhalbtc_set_chip_type(u8 chip_type)
1082 switch (chip_type) {
1088 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
1091 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1094 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1097 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1100 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
1103 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1108 void exhalbtc_set_ant_num(u8 type, u8 ant_num)
1110 if (BT_COEX_ANT_TYPE_PG == type) {
1111 gl_bt_coexist.board_info.pg_ant_num = ant_num;
1112 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1113 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1114 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1118 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist)
1120 if (!halbtc_is_bt_coexist_available(btcoexist))
1123 if (btcoexist->board_info.btdm_ant_num == 2)
1124 ex_halbtc8723b2ant_display_coex_info(btcoexist);
1125 else if (btcoexist->board_info.btdm_ant_num == 1)
1126 ex_halbtc8723b1ant_display_coex_info(btcoexist);