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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 ******************************************************************************/
26 #include "halbt_precomp.h"
28 /***************************************************
29 * Debug related function
30 ***************************************************/
32 static const char *const gl_btc_wifi_bw_string[] = {
40 static const char *const gl_btc_wifi_freq_string[] = {
45 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
47 if (!btcoexist->binded || NULL == btcoexist->adapter)
53 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
55 if (rtlpriv->link_info.busytraffic)
61 static void halbtc_dbg_init(void)
65 /***************************************************
67 ***************************************************/
68 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
70 struct rtl_priv *rtlpriv = btcoexist->adapter;
71 struct rtl_mac *mac = rtl_mac(rtlpriv);
72 struct rtl_sta_info *drv_priv;
75 if (mac->opmode == NL80211_IFTYPE_ADHOC ||
76 mac->opmode == NL80211_IFTYPE_MESH_POINT ||
77 mac->opmode == NL80211_IFTYPE_AP) {
78 if (in_interrupt() > 0) {
79 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
84 spin_lock_bh(&rtlpriv->locks.entry_list_lock);
85 list_for_each_entry(drv_priv, &rtlpriv->entry_list,
89 spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
98 static bool halbtc_legacy(struct rtl_priv *adapter)
100 struct rtl_priv *rtlpriv = adapter;
101 struct rtl_mac *mac = rtl_mac(rtlpriv);
103 bool is_legacy = false;
105 if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
111 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
113 struct rtl_priv *rtlpriv = adapter;
115 if (rtlpriv->link_info.tx_busy_traffic)
121 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
123 struct rtl_priv *rtlpriv =
124 (struct rtl_priv *)btcoexist->adapter;
125 struct rtl_phy *rtlphy = &rtlpriv->phy;
126 u32 wifi_bw = BTC_WIFI_BW_HT20;
128 if (halbtc_legacy(rtlpriv)) {
129 wifi_bw = BTC_WIFI_BW_LEGACY;
131 switch (rtlphy->current_chan_bw) {
132 case HT_CHANNEL_WIDTH_20:
133 wifi_bw = BTC_WIFI_BW_HT20;
135 case HT_CHANNEL_WIDTH_20_40:
136 wifi_bw = BTC_WIFI_BW_HT40;
138 case HT_CHANNEL_WIDTH_80:
139 wifi_bw = BTC_WIFI_BW_HT80;
147 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
149 struct rtl_priv *rtlpriv = btcoexist->adapter;
150 struct rtl_phy *rtlphy = &rtlpriv->phy;
153 if (rtlphy->current_channel != 0)
154 chnl = rtlphy->current_channel;
155 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
156 "%s:%d\n", __func__, chnl);
160 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
162 return rtlpriv->btcoexist.btc_info.single_ant_path;
165 static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
167 return rtlpriv->btcoexist.btc_info.bt_type;
170 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
174 if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
182 static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
184 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
186 return rtlhal->package_type;
190 u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
192 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
194 return rtlhal->rfe_type;
197 /* ************************************
198 * Hal helper function
199 * ************************************
202 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
204 if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
211 bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
212 u8 *cmd, u32 len, unsigned long wait_ms)
214 struct rtl_priv *rtlpriv;
215 const u8 oper_ver = 0;
218 if (!halbtc_is_hw_mailbox_exist(btcoexist))
221 if (wait_ms) /* before h2c to avoid race condition */
222 reinit_completion(&btcoexist->bt_mp_comp);
224 rtlpriv = btcoexist->adapter;
227 * fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
228 * to know message type
231 case BT_OP_GET_BT_VERSION:
232 req_num = BT_SEQ_GET_BT_VERSION;
234 case BT_OP_GET_AFH_MAP_L:
235 req_num = BT_SEQ_GET_AFH_MAP_L;
237 case BT_OP_GET_AFH_MAP_M:
238 req_num = BT_SEQ_GET_AFH_MAP_M;
240 case BT_OP_GET_AFH_MAP_H:
241 req_num = BT_SEQ_GET_AFH_MAP_H;
243 case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
244 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
246 case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
247 req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
249 case BT_OP_GET_BT_ANT_DET_VAL:
250 req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
252 case BT_OP_GET_BT_BLE_SCAN_PARA:
253 req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
255 case BT_OP_GET_BT_BLE_SCAN_TYPE:
256 req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
258 case BT_OP_WRITE_REG_ADDR:
259 case BT_OP_WRITE_REG_VALUE:
262 req_num = BT_SEQ_DONT_CARE;
266 cmd[0] |= (oper_ver & 0x0f); /* Set OperVer */
267 cmd[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
269 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
275 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
276 "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
281 if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
282 msecs_to_jiffies(wait_ms)) == 0) {
283 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
284 "btmpinfo wait (req_num=%d) timeout\n", req_num);
286 return false; /* timeout */
292 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
294 struct rtl_priv *rtlpriv;
295 struct rtl_ps_ctl *ppsc;
296 bool ap_enable = false;
298 rtlpriv = btcoexist->adapter;
299 ppsc = rtl_psc(rtlpriv);
301 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
305 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
306 "%s()<--dont leave lps under AP mode\n", __func__);
310 btcoexist->bt_info.bt_ctrl_lps = true;
311 btcoexist->bt_info.bt_lps_on = false;
312 rtl_lps_leave(rtlpriv->mac80211.hw);
315 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
317 struct rtl_priv *rtlpriv;
318 struct rtl_ps_ctl *ppsc;
319 bool ap_enable = false;
321 rtlpriv = btcoexist->adapter;
322 ppsc = rtl_psc(rtlpriv);
324 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
328 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
329 "%s()<--dont enter lps under AP mode\n", __func__);
333 btcoexist->bt_info.bt_ctrl_lps = true;
334 btcoexist->bt_info.bt_lps_on = true;
335 rtl_lps_enter(rtlpriv->mac80211.hw);
338 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
340 struct rtl_priv *rtlpriv;
342 rtlpriv = btcoexist->adapter;
344 if (btcoexist->bt_info.bt_ctrl_lps) {
345 btcoexist->bt_info.bt_lps_on = false;
346 rtl_lps_leave(rtlpriv->mac80211.hw);
347 btcoexist->bt_info.bt_ctrl_lps = false;
351 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
355 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
359 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
360 bool low_pwr_disable)
362 /* TODO: original/leave 32k low power */
363 btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
366 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
368 bool need_to_act = false;
369 static unsigned long pre_time;
370 unsigned long cur_time = 0;
371 struct rtl_priv *rtlpriv = btcoexist->adapter;
373 /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
374 * This function is not allowed to continuous called
375 * It can only be called after 8 seconds
379 if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
380 /* over 8 seconds you can execute this function again. */
385 if (btcoexist->bt_info.reject_agg_pkt) {
387 btcoexist->bt_info.pre_reject_agg_pkt =
388 btcoexist->bt_info.reject_agg_pkt;
390 if (btcoexist->bt_info.pre_reject_agg_pkt) {
392 btcoexist->bt_info.pre_reject_agg_pkt =
393 btcoexist->bt_info.reject_agg_pkt;
396 if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
397 btcoexist->bt_info.bt_ctrl_agg_buf_size) {
399 btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
400 btcoexist->bt_info.bt_ctrl_agg_buf_size;
403 if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
404 if (btcoexist->bt_info.pre_agg_buf_size !=
405 btcoexist->bt_info.agg_buf_size) {
408 btcoexist->bt_info.pre_agg_buf_size =
409 btcoexist->bt_info.agg_buf_size;
413 rtl_rx_ampdu_apply(rtlpriv);
417 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
419 u8 cmd_buffer[4] = {0};
421 if (btcoexist->bt_info.bt_real_fw_ver)
424 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
425 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
429 return btcoexist->bt_info.bt_real_fw_ver;
432 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
434 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
435 u8 cmd_buffer[4] = {0};
437 if (btcoexist->bt_info.bt_supported_feature)
440 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
441 halbtc_send_bt_mp_operation(btcoexist,
442 BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
446 return btcoexist->bt_info.bt_supported_feature;
449 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
451 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
452 u8 cmd_buffer[4] = {0};
454 if (btcoexist->bt_info.bt_supported_version)
457 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
458 halbtc_send_bt_mp_operation(btcoexist,
459 BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
463 return btcoexist->bt_info.bt_supported_version;
466 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
469 * [31:16] => connected port number
470 * [15:0] => port connected bit define
472 struct rtl_priv *rtlpriv = btcoexist->adapter;
473 struct rtl_mac *mac = rtl_mac(rtlpriv);
475 u32 port_connected_status = 0, num_of_connected_port = 0;
477 if (mac->opmode == NL80211_IFTYPE_STATION &&
478 mac->link_state >= MAC80211_LINKED) {
479 port_connected_status |= WIFI_STA_CONNECTED;
480 num_of_connected_port++;
482 /* AP & ADHOC & MESH */
483 if (is_any_client_connect_to_ap(btcoexist)) {
484 port_connected_status |= WIFI_AP_CONNECTED;
485 num_of_connected_port++;
487 /* TODO: P2P Connected Status */
489 ret_val = (num_of_connected_port << 16) | port_connected_status;
494 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
496 int undec_sm_pwdb = 0;
498 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
499 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
500 else /* associated entry pwdb */
501 undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
502 return undec_sm_pwdb;
505 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
507 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
508 struct rtl_priv *rtlpriv = btcoexist->adapter;
509 struct rtl_phy *rtlphy = &rtlpriv->phy;
510 struct rtl_mac *mac = rtl_mac(rtlpriv);
511 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
512 bool *bool_tmp = (bool *)out_buf;
513 int *s32_tmp = (int *)out_buf;
514 u32 *u32_tmp = (u32 *)out_buf;
515 u8 *u8_tmp = (u8 *)out_buf;
519 if (!halbtc_is_bt_coexist_available(btcoexist))
523 case BTC_GET_BL_HS_OPERATION:
527 case BTC_GET_BL_HS_CONNECTING:
531 case BTC_GET_BL_WIFI_CONNECTED:
532 if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
533 rtlpriv->mac80211.link_state >= MAC80211_LINKED)
535 if (is_any_client_connect_to_ap(btcoexist))
539 case BTC_GET_BL_WIFI_BUSY:
540 if (halbtc_is_wifi_busy(rtlpriv))
545 case BTC_GET_BL_WIFI_SCAN:
546 if (mac->act_scanning)
551 case BTC_GET_BL_WIFI_LINK:
552 if (mac->link_state == MAC80211_LINKING)
557 case BTC_GET_BL_WIFI_ROAM:
558 if (mac->link_state == MAC80211_LINKING)
563 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
564 *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
566 case BTC_GET_BL_WIFI_UNDER_5G:
567 if (rtlhal->current_bandtype == BAND_ON_5G)
572 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
573 if (mac->opmode == NL80211_IFTYPE_AP)
578 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
579 if (rtlpriv->sec.pairwise_enc_algorithm == NO_ENCRYPTION)
584 case BTC_GET_BL_WIFI_UNDER_B_MODE:
585 if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
590 case BTC_GET_BL_EXT_SWITCH:
593 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
596 case BTC_GET_BL_IS_ASUS_8723B:
599 case BTC_GET_BL_RF4CE_CONNECTED:
602 case BTC_GET_S4_WIFI_RSSI:
603 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
605 case BTC_GET_S4_HS_RSSI:
609 case BTC_GET_U4_WIFI_BW:
610 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
612 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
613 if (halbtc_is_wifi_uplink(rtlpriv))
614 *u32_tmp = BTC_WIFI_TRAFFIC_TX;
616 *u32_tmp = BTC_WIFI_TRAFFIC_RX;
618 case BTC_GET_U4_WIFI_FW_VER:
619 *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
621 case BTC_GET_U4_WIFI_LINK_STATUS:
622 *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
624 case BTC_GET_U4_BT_PATCH_VER:
625 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
627 case BTC_GET_U4_VENDOR:
628 *u32_tmp = BTC_VENDOR_OTHER;
630 case BTC_GET_U4_SUPPORTED_VERSION:
631 *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
633 case BTC_GET_U4_SUPPORTED_FEATURE:
634 *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
636 case BTC_GET_U4_WIFI_IQK_TOTAL:
637 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
640 case BTC_GET_U4_WIFI_IQK_OK:
641 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
644 case BTC_GET_U4_WIFI_IQK_FAIL:
645 *u32_tmp = btcoexist->btc_phydm_query_phy_counter(btcoexist,
648 case BTC_GET_U1_WIFI_DOT11_CHNL:
649 *u8_tmp = rtlphy->current_channel;
651 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
652 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
654 case BTC_GET_U1_WIFI_HS_CHNL:
658 case BTC_GET_U1_AP_NUM:
659 *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
661 case BTC_GET_U1_ANT_TYPE:
662 *u8_tmp = (u8)BTC_ANT_TYPE_0;
664 case BTC_GET_U1_IOT_PEER:
668 /************* 1Ant **************/
669 case BTC_GET_U1_LPS_MODE:
670 *u8_tmp = btcoexist->pwr_mode_val[0];
681 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
683 struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
684 bool *bool_tmp = (bool *)in_buf;
685 u8 *u8_tmp = (u8 *)in_buf;
686 u32 *u32_tmp = (u32 *)in_buf;
689 if (!halbtc_is_bt_coexist_available(btcoexist))
693 /* set some bool type variables. */
694 case BTC_SET_BL_BT_DISABLE:
695 btcoexist->bt_info.bt_disabled = *bool_tmp;
697 case BTC_SET_BL_BT_TRAFFIC_BUSY:
698 btcoexist->bt_info.bt_busy = *bool_tmp;
700 case BTC_SET_BL_BT_LIMITED_DIG:
701 btcoexist->bt_info.limited_dig = *bool_tmp;
703 case BTC_SET_BL_FORCE_TO_ROAM:
704 btcoexist->bt_info.force_to_roam = *bool_tmp;
706 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
707 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
709 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
710 btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
712 case BTC_SET_BL_INC_SCAN_DEV_NUM:
713 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
715 case BTC_SET_BL_BT_TX_RX_MASK:
716 btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
718 case BTC_SET_BL_MIRACAST_PLUS_BT:
719 btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
721 /* set some u1Byte type variables. */
722 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
723 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
725 case BTC_SET_U1_AGG_BUF_SIZE:
726 btcoexist->bt_info.agg_buf_size = *u8_tmp;
729 /* the following are some action which will be triggered */
730 case BTC_SET_ACT_GET_BT_RSSI:
733 case BTC_SET_ACT_AGGREGATE_CTRL:
734 halbtc_aggregation_check(btcoexist);
738 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
739 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
741 case BTC_SET_UI_SCAN_SIG_COMPENSATION:
743 case BTC_SET_U1_LPS_VAL:
744 btcoexist->bt_info.lps_val = *u8_tmp;
746 case BTC_SET_U1_RPWM_VAL:
747 btcoexist->bt_info.rpwm_val = *u8_tmp;
749 /* the following are some action which will be triggered */
750 case BTC_SET_ACT_LEAVE_LPS:
751 halbtc_leave_lps(btcoexist);
753 case BTC_SET_ACT_ENTER_LPS:
754 halbtc_enter_lps(btcoexist);
756 case BTC_SET_ACT_NORMAL_LPS:
757 halbtc_normal_lps(btcoexist);
759 case BTC_SET_ACT_DISABLE_LOW_POWER:
760 halbtc_disable_low_power(btcoexist, *bool_tmp);
762 case BTC_SET_ACT_UPDATE_RAMASK:
763 btcoexist->bt_info.ra_mask = *u32_tmp;
765 case BTC_SET_ACT_SEND_MIMO_PS:
767 case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
769 case BTC_SET_ACT_CTRL_BT_COEX:
771 case BTC_SET_ACT_CTRL_8723B_ANT:
780 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
785 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
790 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
793 struct rtl_priv *rtlpriv = btcoexist->adapter;
794 s32 wifi_rssi = 0, bt_hs_rssi = 0;
795 bool scan = false, link = false, roam = false, wifi_busy = false;
796 bool wifi_under_b_mode = false, wifi_under_5g = false;
797 u32 wifi_bw = BTC_WIFI_BW_HT20;
798 u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
799 u32 wifi_freq = BTC_FREQ_2_4G;
800 u32 wifi_link_status = 0x0;
801 bool bt_hs_on = false, under_ips = false, under_lps = false;
802 bool low_power = false, dc_mode = false;
803 u8 wifi_chnl = 0, wifi_hs_chnl = 0, fw_ps_state;
806 wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
807 seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
808 "STA/vWifi/HS/p2pGo/p2pGc",
809 ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
810 ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
811 ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
812 ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
813 ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
815 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
816 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
817 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
818 seq_printf(m, "\n %-35s = %d / %d(%d)",
819 "Dot11 channel / HsChnl(High Speed)",
820 wifi_chnl, wifi_hs_chnl, bt_hs_on);
822 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
823 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
824 seq_printf(m, "\n %-35s = %d/ %d",
825 "Wifi rssi/ HS rssi",
826 wifi_rssi - 100, bt_hs_rssi - 100);
828 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
829 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
830 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
831 seq_printf(m, "\n %-35s = %d/ %d/ %d ",
832 "Wifi link/ roam/ scan",
835 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
836 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
837 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
838 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
840 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
841 wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
842 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
845 seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
846 "Wifi freq/ bw/ traffic",
847 gl_btc_wifi_freq_string[wifi_freq],
848 ((wifi_under_b_mode) ? "11b" :
849 gl_btc_wifi_bw_string[wifi_bw]),
850 ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
851 wifi_traffic_dir) ? "uplink" :
856 dc_mode = true; /*TODO*/
857 under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
858 under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
860 low_power = 0; /*TODO*/
861 seq_printf(m, "\n %-35s = %s%s%s%s",
863 (dc_mode ? "DC mode" : "AC mode"),
864 (under_ips ? ", IPS ON" : ""),
865 (under_lps ? ", LPS ON" : ""),
866 (low_power ? ", 32k" : ""));
869 "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
870 "Power mode cmd(lps/rpwm)",
871 btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
872 btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
873 btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
874 btcoexist->bt_info.lps_val,
875 btcoexist->bt_info.rpwm_val);
878 /************************************************************
879 * IO related function
880 ************************************************************/
881 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
883 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
884 struct rtl_priv *rtlpriv = btcoexist->adapter;
886 return rtl_read_byte(rtlpriv, reg_addr);
889 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
891 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
892 struct rtl_priv *rtlpriv = btcoexist->adapter;
894 return rtl_read_word(rtlpriv, reg_addr);
897 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
899 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
900 struct rtl_priv *rtlpriv = btcoexist->adapter;
902 return rtl_read_dword(rtlpriv, reg_addr);
905 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
907 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
908 struct rtl_priv *rtlpriv = btcoexist->adapter;
910 rtl_write_byte(rtlpriv, reg_addr, data);
913 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
914 u32 bit_mask, u8 data)
916 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
917 struct rtl_priv *rtlpriv = btcoexist->adapter;
918 u8 original_value, bit_shift = 0;
921 if (bit_mask != MASKDWORD) {/*if not "double word" write*/
922 original_value = rtl_read_byte(rtlpriv, reg_addr);
923 for (i = 0; i <= 7; i++) {
924 if ((bit_mask >> i) & 0x1)
928 data = (original_value & (~bit_mask)) |
929 ((data << bit_shift) & bit_mask);
931 rtl_write_byte(rtlpriv, reg_addr, data);
934 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
936 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
937 struct rtl_priv *rtlpriv = btcoexist->adapter;
939 rtl_write_word(rtlpriv, reg_addr, data);
942 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
944 struct btc_coexist *btcoexist =
945 (struct btc_coexist *)bt_context;
946 struct rtl_priv *rtlpriv = btcoexist->adapter;
948 rtl_write_dword(rtlpriv, reg_addr, data);
951 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
954 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
955 struct rtl_priv *rtlpriv = btcoexist->adapter;
957 if (btcoexist->chip_interface == BTC_INTF_SDIO)
959 else if (btcoexist->chip_interface == BTC_INTF_PCI)
960 rtl_write_byte(rtlpriv, reg_addr, data);
961 else if (btcoexist->chip_interface == BTC_INTF_USB)
962 rtl_write_byte(rtlpriv, reg_addr, data);
965 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
968 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
969 struct rtl_priv *rtlpriv = btcoexist->adapter;
971 rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
974 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
976 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
977 struct rtl_priv *rtlpriv = btcoexist->adapter;
979 return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
982 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
983 u32 bit_mask, u32 data)
985 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
986 struct rtl_priv *rtlpriv = btcoexist->adapter;
988 rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
991 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
994 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
995 struct rtl_priv *rtlpriv = btcoexist->adapter;
997 return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
1000 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
1001 u32 cmd_len, u8 *cmd_buf)
1003 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1004 struct rtl_priv *rtlpriv = btcoexist->adapter;
1006 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
1010 static void halbtc_send_wifi_port_id_cmd(void *bt_context)
1012 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1013 struct rtl_priv *rtlpriv = btcoexist->adapter;
1014 u8 cmd_buf[1] = {0}; /* port id [2:0] = 0 */
1016 rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x71, 1,
1020 static void halbtc_set_default_port_id_cmd(void *bt_context)
1022 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1023 struct rtl_priv *rtlpriv = btcoexist->adapter;
1024 struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1026 if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1029 rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1033 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1035 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1036 u8 cmd_buffer1[4] = {0};
1037 u8 cmd_buffer2[4] = {0};
1039 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1040 *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1041 if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1042 cmd_buffer1, 4, 200))
1045 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1046 cmd_buffer2[2] = reg_type;
1047 *((u8 *)&cmd_buffer2[3]) = (u8)offset;
1048 halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1049 cmd_buffer2, 4, 200);
1052 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1055 struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1057 switch (disp_type) {
1058 case BTC_DBG_DISP_COEX_STATISTICS:
1059 halbtc_display_coex_statistics(btcoexist, m);
1061 case BTC_DBG_DISP_BT_LINK_INFO:
1062 halbtc_display_bt_link_info(btcoexist, m);
1064 case BTC_DBG_DISP_WIFI_STATUS:
1065 halbtc_display_wifi_status(btcoexist, m);
1072 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1078 u32 halbtc_get_phydm_version(void *btc_context)
1080 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1081 struct rtl_priv *rtlpriv = btcoexist->adapter;
1083 if (rtlpriv->phydm.ops)
1084 return rtlpriv->phydm.ops->phydm_get_version(rtlpriv);
1090 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1091 u8 ra_offset_direction,
1092 u8 ra_threshold_offset)
1094 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1095 struct rtl_priv *rtlpriv = btcoexist->adapter;
1096 struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1099 phydm_ops->phydm_modify_ra_pcr_threshold(rtlpriv,
1100 ra_offset_direction,
1101 ra_threshold_offset);
1105 u32 halbtc_phydm_query_phy_counter(void *btc_context, const char *info_type)
1107 /* info_type may be strings below:
1108 * PHYDM_INFO_FA_OFDM, PHYDM_INFO_FA_CCK, PHYDM_INFO_CCA_OFDM,
1109 * PHYDM_INFO_CCA_CCK
1110 * IQK_TOTAL, IQK_OK, IQK_FAIL
1113 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1114 struct rtl_priv *rtlpriv = btcoexist->adapter;
1115 struct rtl_phydm_ops *phydm_ops = rtlpriv->phydm.ops;
1118 return phydm_ops->phydm_query_counter(rtlpriv, info_type);
1123 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1125 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1126 u8 cmd_buffer[4] = {0};
1128 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1129 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1130 cmd_buffer, 4, 200);
1132 /* need wait completion to return correct value */
1134 return btcoexist->bt_info.bt_ant_det_val;
1137 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1139 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1140 u8 cmd_buffer[4] = {0};
1142 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1143 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1144 cmd_buffer, 4, 200);
1146 /* need wait completion to return correct value */
1148 return btcoexist->bt_info.bt_ble_scan_type;
1151 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1153 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1154 u8 cmd_buffer[4] = {0};
1156 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1157 halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1158 cmd_buffer, 4, 200);
1160 /* need wait completion to return correct value */
1162 return btcoexist->bt_info.bt_ble_scan_para;
1165 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1168 struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1169 u8 cmd_buffer[2] = {0};
1171 u32 *afh_map_l = (u32 *)afh_map;
1172 u32 *afh_map_m = (u32 *)(afh_map + 4);
1173 u16 *afh_map_h = (u16 *)(afh_map + 8);
1175 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1176 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1177 cmd_buffer, 2, 200);
1181 *afh_map_l = btcoexist->bt_info.afh_map_l;
1183 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1184 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1185 cmd_buffer, 2, 200);
1189 *afh_map_m = btcoexist->bt_info.afh_map_m;
1191 /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1192 ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1193 cmd_buffer, 2, 200);
1197 *afh_map_h = btcoexist->bt_info.afh_map_h;
1203 /*****************************************************************
1204 * Extern functions called by other module
1205 *****************************************************************/
1206 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1208 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1215 btcoexist->btc_read_1byte = halbtc_read_1byte;
1216 btcoexist->btc_write_1byte = halbtc_write_1byte;
1217 btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1218 btcoexist->btc_read_2byte = halbtc_read_2byte;
1219 btcoexist->btc_write_2byte = halbtc_write_2byte;
1220 btcoexist->btc_read_4byte = halbtc_read_4byte;
1221 btcoexist->btc_write_4byte = halbtc_write_4byte;
1222 btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1224 btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1225 btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1227 btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1228 btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1230 btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1231 btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1233 btcoexist->btc_get = halbtc_get;
1234 btcoexist->btc_set = halbtc_set;
1235 btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1236 btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1238 btcoexist->bt_info.bt_ctrl_buf_size = false;
1239 btcoexist->bt_info.agg_buf_size = 5;
1241 btcoexist->bt_info.increase_scan_dev_num = false;
1243 btcoexist->btc_get_bt_coex_supported_feature =
1244 halbtc_get_bt_coex_supported_feature;
1245 btcoexist->btc_get_bt_coex_supported_version =
1246 halbtc_get_bt_coex_supported_version;
1247 btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1248 btcoexist->btc_phydm_modify_ra_pcr_threshold =
1249 halbtc_phydm_modify_ra_pcr_threshold;
1250 btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1251 btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1252 btcoexist->btc_get_ble_scan_type_from_bt =
1253 halbtc_get_ble_scan_type_from_bt;
1254 btcoexist->btc_get_ble_scan_para_from_bt =
1255 halbtc_get_ble_scan_para_from_bt;
1256 btcoexist->btc_get_bt_afh_map_from_bt =
1257 halbtc_get_bt_afh_map_from_bt;
1259 init_completion(&btcoexist->bt_mp_comp);
1264 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1266 struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1267 struct wifi_only_haldata *wifionly_haldata;
1272 wifionly_cfg->adapter = rtlpriv;
1274 switch (rtlpriv->rtlhal.interface) {
1276 wifionly_cfg->chip_interface = BTC_INTF_PCI;
1279 wifionly_cfg->chip_interface = BTC_INTF_USB;
1282 wifionly_cfg->chip_interface = BTC_INTF_UNKNOWN;
1286 wifionly_haldata = &wifionly_cfg->haldata_info;
1288 wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1289 wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1290 wifionly_haldata->efuse_pg_antpath =
1291 rtl_get_hwpg_single_ant_path(rtlpriv);
1292 wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1293 wifionly_haldata->ant_div_cfg = 0;
1298 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1300 struct rtl_priv *rtlpriv = adapter;
1301 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1302 u8 ant_num = 2, chip_type, single_ant_path = 0;
1307 if (btcoexist->binded)
1310 switch (rtlpriv->rtlhal.interface) {
1312 btcoexist->chip_interface = BTC_INTF_PCI;
1315 btcoexist->chip_interface = BTC_INTF_USB;
1318 btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1322 btcoexist->binded = true;
1323 btcoexist->statistics.cnt_bind++;
1325 btcoexist->adapter = adapter;
1327 btcoexist->stack_info.profile_notified = false;
1329 btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1330 btcoexist->bt_info.agg_buf_size = 5;
1332 btcoexist->bt_info.increase_scan_dev_num = false;
1333 btcoexist->bt_info.miracast_plus_bt = false;
1335 chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1336 exhalbtc_set_chip_type(btcoexist, chip_type);
1337 ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1338 exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1340 /* set default antenna position to main port */
1341 btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1343 single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1344 exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1346 if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1347 btcoexist->board_info.tfbga_package = false;
1348 else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1349 btcoexist->board_info.tfbga_package = false;
1351 btcoexist->board_info.tfbga_package = true;
1353 if (btcoexist->board_info.tfbga_package)
1354 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1355 "[BTCoex], Package Type = TFBGA\n");
1357 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1358 "[BTCoex], Package Type = Non-TFBGA\n");
1360 btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1361 btcoexist->board_info.ant_div_cfg = 0;
1366 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1368 if (!halbtc_is_bt_coexist_available(btcoexist))
1371 btcoexist->statistics.cnt_power_on++;
1373 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1374 if (btcoexist->board_info.btdm_ant_num == 1)
1375 ex_btc8822b1ant_power_on_setting(btcoexist);
1376 else if (btcoexist->board_info.btdm_ant_num == 2)
1377 ex_btc8822b2ant_power_on_setting(btcoexist);
1381 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1383 if (!halbtc_is_bt_coexist_available(btcoexist))
1386 btcoexist->statistics.cnt_pre_load_firmware++;
1388 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1389 if (btcoexist->board_info.btdm_ant_num == 1)
1390 ex_btc8822b1ant_pre_load_firmware(btcoexist);
1391 else if (btcoexist->board_info.btdm_ant_num == 2)
1392 ex_btc8822b2ant_pre_load_firmware(btcoexist);
1396 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1398 if (!halbtc_is_bt_coexist_available(btcoexist))
1401 btcoexist->statistics.cnt_init_hw_config++;
1403 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1404 if (btcoexist->board_info.btdm_ant_num == 1)
1405 ex_btc8822b1ant_init_hw_config(btcoexist, wifi_only);
1406 else if (btcoexist->board_info.btdm_ant_num == 2)
1407 ex_btc8822b2ant_init_hw_config(btcoexist, wifi_only);
1409 halbtc_set_default_port_id_cmd(btcoexist);
1410 halbtc_send_wifi_port_id_cmd(btcoexist);
1414 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1416 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1417 ex_hal8822b_wifi_only_hw_config(wifionly_cfg);
1420 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1422 if (!halbtc_is_bt_coexist_available(btcoexist))
1425 btcoexist->statistics.cnt_init_coex_dm++;
1427 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1428 if (btcoexist->board_info.btdm_ant_num == 1)
1429 ex_btc8822b1ant_init_coex_dm(btcoexist);
1430 else if (btcoexist->board_info.btdm_ant_num == 2)
1431 ex_btc8822b2ant_init_coex_dm(btcoexist);
1434 btcoexist->initilized = true;
1437 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1441 if (!halbtc_is_bt_coexist_available(btcoexist))
1443 btcoexist->statistics.cnt_ips_notify++;
1444 if (btcoexist->manual_control)
1448 ips_type = BTC_IPS_ENTER;
1450 ips_type = BTC_IPS_LEAVE;
1452 halbtc_leave_low_power(btcoexist);
1454 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1455 if (btcoexist->board_info.btdm_ant_num == 1)
1456 ex_btc8822b1ant_ips_notify(btcoexist, ips_type);
1457 else if (btcoexist->board_info.btdm_ant_num == 2)
1458 ex_btc8822b2ant_ips_notify(btcoexist, ips_type);
1461 halbtc_normal_low_power(btcoexist);
1464 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1468 if (!halbtc_is_bt_coexist_available(btcoexist))
1470 btcoexist->statistics.cnt_lps_notify++;
1471 if (btcoexist->manual_control)
1474 if (type == EACTIVE)
1475 lps_type = BTC_LPS_DISABLE;
1477 lps_type = BTC_LPS_ENABLE;
1479 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1480 if (btcoexist->board_info.btdm_ant_num == 1)
1481 ex_btc8822b1ant_lps_notify(btcoexist, lps_type);
1482 else if (btcoexist->board_info.btdm_ant_num == 2)
1483 ex_btc8822b2ant_lps_notify(btcoexist, lps_type);
1487 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1491 if (!halbtc_is_bt_coexist_available(btcoexist))
1493 btcoexist->statistics.cnt_scan_notify++;
1494 if (btcoexist->manual_control)
1498 scan_type = BTC_SCAN_START;
1500 scan_type = BTC_SCAN_FINISH;
1502 halbtc_leave_low_power(btcoexist);
1504 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1505 if (btcoexist->board_info.btdm_ant_num == 1)
1506 ex_btc8822b1ant_scan_notify(btcoexist, scan_type);
1507 else if (btcoexist->board_info.btdm_ant_num == 2)
1508 ex_btc8822b2ant_scan_notify(btcoexist, scan_type);
1511 halbtc_normal_low_power(btcoexist);
1514 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1517 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1518 ex_hal8822b_wifi_only_scannotify(wifionly_cfg, is_5g);
1521 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1525 if (!halbtc_is_bt_coexist_available(btcoexist))
1527 btcoexist->statistics.cnt_connect_notify++;
1528 if (btcoexist->manual_control)
1532 asso_type = BTC_ASSOCIATE_START;
1534 asso_type = BTC_ASSOCIATE_FINISH;
1536 halbtc_leave_low_power(btcoexist);
1538 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1539 if (btcoexist->board_info.btdm_ant_num == 1)
1540 ex_btc8822b1ant_connect_notify(btcoexist, asso_type);
1541 else if (btcoexist->board_info.btdm_ant_num == 2)
1542 ex_btc8822b2ant_connect_notify(btcoexist, asso_type);
1545 halbtc_normal_low_power(btcoexist);
1548 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1549 enum rt_media_status media_status)
1553 if (!halbtc_is_bt_coexist_available(btcoexist))
1555 btcoexist->statistics.cnt_media_status_notify++;
1556 if (btcoexist->manual_control)
1559 if (media_status == RT_MEDIA_CONNECT)
1560 status = BTC_MEDIA_CONNECT;
1562 status = BTC_MEDIA_DISCONNECT;
1564 halbtc_leave_low_power(btcoexist);
1566 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1567 if (btcoexist->board_info.btdm_ant_num == 1)
1568 ex_btc8822b1ant_media_status_notify(btcoexist, status);
1569 else if (btcoexist->board_info.btdm_ant_num == 2)
1570 ex_btc8822b2ant_media_status_notify(btcoexist, status);
1573 halbtc_normal_low_power(btcoexist);
1576 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1580 if (!halbtc_is_bt_coexist_available(btcoexist))
1582 btcoexist->statistics.cnt_special_packet_notify++;
1583 if (btcoexist->manual_control)
1586 if (pkt_type == PACKET_DHCP) {
1587 packet_type = BTC_PACKET_DHCP;
1588 } else if (pkt_type == PACKET_EAPOL) {
1589 packet_type = BTC_PACKET_EAPOL;
1590 } else if (pkt_type == PACKET_ARP) {
1591 packet_type = BTC_PACKET_ARP;
1593 packet_type = BTC_PACKET_UNKNOWN;
1597 halbtc_leave_low_power(btcoexist);
1599 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1600 if (btcoexist->board_info.btdm_ant_num == 1)
1601 ex_btc8822b1ant_specific_packet_notify(btcoexist,
1603 else if (btcoexist->board_info.btdm_ant_num == 2)
1604 ex_btc8822b2ant_specific_packet_notify(btcoexist,
1608 halbtc_normal_low_power(btcoexist);
1611 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1612 u8 *tmp_buf, u8 length)
1614 if (!halbtc_is_bt_coexist_available(btcoexist))
1616 btcoexist->statistics.cnt_bt_info_notify++;
1618 halbtc_leave_low_power(btcoexist);
1620 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1621 if (btcoexist->board_info.btdm_ant_num == 1)
1622 ex_btc8822b1ant_bt_info_notify(btcoexist, tmp_buf,
1624 else if (btcoexist->board_info.btdm_ant_num == 2)
1625 ex_btc8822b2ant_bt_info_notify(btcoexist, tmp_buf,
1629 halbtc_normal_low_power(btcoexist);
1632 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1634 if (!halbtc_is_bt_coexist_available(btcoexist))
1637 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1638 if (btcoexist->board_info.btdm_ant_num == 1)
1639 ex_btc8822b1ant_rf_status_notify(btcoexist, type);
1640 else if (btcoexist->board_info.btdm_ant_num == 2)
1641 ex_btc8822b2ant_rf_status_notify(btcoexist, type);
1645 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1649 if (!halbtc_is_bt_coexist_available(btcoexist))
1651 btcoexist->statistics.cnt_stack_operation_notify++;
1652 if (btcoexist->manual_control)
1655 if ((type == HCI_BT_OP_INQUIRY_START) ||
1656 (type == HCI_BT_OP_PAGING_START) ||
1657 (type == HCI_BT_OP_PAIRING_START)) {
1658 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START;
1659 } else if ((type == HCI_BT_OP_INQUIRY_FINISH) ||
1660 (type == HCI_BT_OP_PAGING_SUCCESS) ||
1661 (type == HCI_BT_OP_PAGING_UNSUCCESS) ||
1662 (type == HCI_BT_OP_PAIRING_FINISH)) {
1663 stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
1665 stack_op_type = BTC_STACK_OP_NONE;
1669 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1671 if (!halbtc_is_bt_coexist_available(btcoexist))
1674 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1675 if (btcoexist->board_info.btdm_ant_num == 1)
1676 ex_btc8822b1ant_halt_notify(btcoexist);
1677 else if (btcoexist->board_info.btdm_ant_num == 2)
1678 ex_btc8822b2ant_halt_notify(btcoexist);
1681 btcoexist->binded = false;
1684 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1686 if (!halbtc_is_bt_coexist_available(btcoexist))
1689 /* currently only 1ant we have to do the notification,
1690 * once pnp is notified to sleep state, we have to leave LPS that
1691 * we can sleep normally.
1694 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1695 if (btcoexist->board_info.btdm_ant_num == 1)
1696 ex_btc8822b1ant_pnp_notify(btcoexist, pnp_state);
1697 else if (btcoexist->board_info.btdm_ant_num == 2)
1698 ex_btc8822b2ant_pnp_notify(btcoexist, pnp_state);
1702 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1704 if (!halbtc_is_bt_coexist_available(btcoexist))
1706 btcoexist->statistics.cnt_coex_dm_switch++;
1708 halbtc_leave_low_power(btcoexist);
1710 halbtc_normal_low_power(btcoexist);
1713 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1715 if (!halbtc_is_bt_coexist_available(btcoexist))
1717 btcoexist->statistics.cnt_periodical++;
1719 halbtc_leave_low_power(btcoexist);
1721 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1722 if (btcoexist->board_info.btdm_ant_num == 1)
1723 ex_btc8822b1ant_periodical(btcoexist);
1724 else if (btcoexist->board_info.btdm_ant_num == 2)
1725 ex_btc8822b2ant_periodical(btcoexist);
1728 halbtc_normal_low_power(btcoexist);
1731 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1732 u8 code, u8 len, u8 *data)
1734 if (!halbtc_is_bt_coexist_available(btcoexist))
1736 btcoexist->statistics.cnt_dbg_ctrl++;
1738 halbtc_leave_low_power(btcoexist);
1740 halbtc_normal_low_power(btcoexist);
1743 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1744 u32 offset, u32 span, u32 seconds)
1746 if (!halbtc_is_bt_coexist_available(btcoexist))
1750 void exhalbtc_stack_update_profile_info(void)
1754 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1756 if (!halbtc_is_bt_coexist_available(btcoexist))
1759 btcoexist->stack_info.min_bt_rssi = bt_rssi;
1762 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1764 if (!halbtc_is_bt_coexist_available(btcoexist))
1767 btcoexist->stack_info.hci_version = hci_version;
1770 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1771 u16 bt_hci_version, u16 bt_patch_version)
1773 if (!halbtc_is_bt_coexist_available(btcoexist))
1776 btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1777 btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1780 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1782 switch (chip_type) {
1788 btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1791 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1794 btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1797 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1800 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1803 btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1808 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1810 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1815 if (type == BT_COEX_ANT_TYPE_PG) {
1816 btcoexist->board_info.pg_ant_num = ant_num;
1817 btcoexist->board_info.btdm_ant_num = ant_num;
1818 } else if (type == BT_COEX_ANT_TYPE_ANTDIV) {
1819 btcoexist->board_info.btdm_ant_num = ant_num;
1820 } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1821 btcoexist->board_info.btdm_ant_num = ant_num;
1822 if (rtlpriv->cfg->mod_params->ant_sel == 1)
1823 btcoexist->board_info.btdm_ant_pos =
1824 BTC_ANTENNA_AT_AUX_PORT;
1826 btcoexist->board_info.btdm_ant_pos =
1827 BTC_ANTENNA_AT_MAIN_PORT;
1831 /* Currently used by 8723b only, S0 or S1 */
1832 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1835 btcoexist->board_info.single_ant_path = single_ant_path;
1838 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1841 if (!halbtc_is_bt_coexist_available(btcoexist))
1844 halbtc_leave_low_power(btcoexist);
1846 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1847 if (btcoexist->board_info.btdm_ant_num == 1)
1848 ex_btc8822b1ant_display_coex_info(btcoexist, m);
1849 else if (btcoexist->board_info.btdm_ant_num == 2)
1850 ex_btc8822b2ant_display_coex_info(btcoexist, m);
1853 halbtc_normal_low_power(btcoexist);
1856 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1858 if (!halbtc_is_bt_coexist_available(btcoexist))
1861 if (btcoexist->manual_control)
1864 halbtc_leave_low_power(btcoexist);
1866 if (IS_HARDWARE_TYPE_8822B(btcoexist->adapter)) {
1867 if (btcoexist->board_info.btdm_ant_num == 1)
1868 ex_btc8822b1ant_switchband_notify(btcoexist, type);
1869 else if (btcoexist->board_info.btdm_ant_num == 2)
1870 ex_btc8822b2ant_switchband_notify(btcoexist, type);
1873 halbtc_normal_low_power(btcoexist);
1876 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1879 if (IS_HARDWARE_TYPE_8822B(wifionly_cfg->adapter))
1880 ex_hal8822b_wifi_only_switchbandnotify(wifionly_cfg, is_5g);