1f1d2b4d3SLarry Finger /****************************************************************************** 2f1d2b4d3SLarry Finger * 3f1d2b4d3SLarry Finger * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved. 4f1d2b4d3SLarry Finger * 5f1d2b4d3SLarry Finger * This program is free software; you can redistribute it and/or modify it 6f1d2b4d3SLarry Finger * under the terms of version 2 of the GNU General Public License as 7f1d2b4d3SLarry Finger * published by the Free Software Foundation. 8f1d2b4d3SLarry Finger * 9f1d2b4d3SLarry Finger * This program is distributed in the hope that it will be useful, but WITHOUT 10f1d2b4d3SLarry Finger * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11f1d2b4d3SLarry Finger * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12f1d2b4d3SLarry Finger * more details. 13f1d2b4d3SLarry Finger * 14f1d2b4d3SLarry Finger * The full GNU General Public License is included in this distribution in the 15f1d2b4d3SLarry Finger * file called LICENSE. 16f1d2b4d3SLarry Finger * 17f1d2b4d3SLarry Finger * Contact Information: 18f1d2b4d3SLarry Finger * wlanfae <wlanfae@realtek.com> 19f1d2b4d3SLarry Finger * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 20f1d2b4d3SLarry Finger * Hsinchu 300, Taiwan. 21f1d2b4d3SLarry Finger * 22f1d2b4d3SLarry Finger * Larry Finger <Larry.Finger@lwfinger.net> 23f1d2b4d3SLarry Finger * 24f1d2b4d3SLarry Finger ******************************************************************************/ 25f1d2b4d3SLarry Finger 26f1d2b4d3SLarry Finger #include "halbt_precomp.h" 27f1d2b4d3SLarry Finger 28f1d2b4d3SLarry Finger /*********************************************** 29f1d2b4d3SLarry Finger * Global variables 30f1d2b4d3SLarry Finger ***********************************************/ 31f1d2b4d3SLarry Finger 32f1d2b4d3SLarry Finger struct btc_coexist gl_bt_coexist; 33f1d2b4d3SLarry Finger 34f1d2b4d3SLarry Finger u32 btc_dbg_type[BTC_MSG_MAX]; 35f1d2b4d3SLarry Finger 36f1d2b4d3SLarry Finger /*************************************************** 37f1d2b4d3SLarry Finger * Debug related function 38f1d2b4d3SLarry Finger ***************************************************/ 39c42ea613SYan-Hsuan Chuang 40c42ea613SYan-Hsuan Chuang const char *const gl_btc_wifi_bw_string[] = { 41c42ea613SYan-Hsuan Chuang "11bg", 42c42ea613SYan-Hsuan Chuang "HT20", 43c42ea613SYan-Hsuan Chuang "HT40", 44c42ea613SYan-Hsuan Chuang "HT80", 45c42ea613SYan-Hsuan Chuang "HT160" 46c42ea613SYan-Hsuan Chuang }; 47c42ea613SYan-Hsuan Chuang 48c42ea613SYan-Hsuan Chuang const char *const gl_btc_wifi_freq_string[] = { 49c42ea613SYan-Hsuan Chuang "2.4G", 50c42ea613SYan-Hsuan Chuang "5G" 51c42ea613SYan-Hsuan Chuang }; 52c42ea613SYan-Hsuan Chuang 53f1d2b4d3SLarry Finger static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist) 54f1d2b4d3SLarry Finger { 55f1d2b4d3SLarry Finger if (!btcoexist->binded || NULL == btcoexist->adapter) 56f1d2b4d3SLarry Finger return false; 57f1d2b4d3SLarry Finger 58f1d2b4d3SLarry Finger return true; 59f1d2b4d3SLarry Finger } 60f1d2b4d3SLarry Finger 61f1d2b4d3SLarry Finger static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv) 62f1d2b4d3SLarry Finger { 63f1d2b4d3SLarry Finger if (rtlpriv->link_info.busytraffic) 64f1d2b4d3SLarry Finger return true; 65f1d2b4d3SLarry Finger else 66f1d2b4d3SLarry Finger return false; 67f1d2b4d3SLarry Finger } 68f1d2b4d3SLarry Finger 69f1d2b4d3SLarry Finger static void halbtc_dbg_init(void) 70f1d2b4d3SLarry Finger { 71c42ea613SYan-Hsuan Chuang } 72f1d2b4d3SLarry Finger 73c42ea613SYan-Hsuan Chuang /*************************************************** 74c42ea613SYan-Hsuan Chuang * helper function 75c42ea613SYan-Hsuan Chuang ***************************************************/ 76c42ea613SYan-Hsuan Chuang static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist) 77c42ea613SYan-Hsuan Chuang { 78c42ea613SYan-Hsuan Chuang struct rtl_priv *rtlpriv = btcoexist->adapter; 79c42ea613SYan-Hsuan Chuang struct rtl_mac *mac = rtl_mac(rtlpriv); 80c42ea613SYan-Hsuan Chuang struct rtl_sta_info *drv_priv; 81c42ea613SYan-Hsuan Chuang u8 cnt = 0; 82f1d2b4d3SLarry Finger 83c42ea613SYan-Hsuan Chuang if (mac->opmode == NL80211_IFTYPE_ADHOC || 84c42ea613SYan-Hsuan Chuang mac->opmode == NL80211_IFTYPE_MESH_POINT || 85c42ea613SYan-Hsuan Chuang mac->opmode == NL80211_IFTYPE_AP) { 86c42ea613SYan-Hsuan Chuang if (in_interrupt() > 0) { 87c42ea613SYan-Hsuan Chuang list_for_each_entry(drv_priv, &rtlpriv->entry_list, 88c42ea613SYan-Hsuan Chuang list) { 89c42ea613SYan-Hsuan Chuang cnt++; 90c42ea613SYan-Hsuan Chuang } 91c42ea613SYan-Hsuan Chuang } else { 92c42ea613SYan-Hsuan Chuang spin_lock_bh(&rtlpriv->locks.entry_list_lock); 93c42ea613SYan-Hsuan Chuang list_for_each_entry(drv_priv, &rtlpriv->entry_list, 94c42ea613SYan-Hsuan Chuang list) { 95c42ea613SYan-Hsuan Chuang cnt++; 96c42ea613SYan-Hsuan Chuang } 97c42ea613SYan-Hsuan Chuang spin_unlock_bh(&rtlpriv->locks.entry_list_lock); 98c42ea613SYan-Hsuan Chuang } 99c42ea613SYan-Hsuan Chuang } 100c42ea613SYan-Hsuan Chuang if (cnt > 0) 101c42ea613SYan-Hsuan Chuang return true; 102c42ea613SYan-Hsuan Chuang else 103c42ea613SYan-Hsuan Chuang return false; 104f1d2b4d3SLarry Finger } 105f1d2b4d3SLarry Finger 106f1d2b4d3SLarry Finger static bool halbtc_is_bt40(struct rtl_priv *adapter) 107f1d2b4d3SLarry Finger { 108f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = adapter; 109f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 110f1d2b4d3SLarry Finger bool is_ht40 = true; 111f1d2b4d3SLarry Finger enum ht_channel_width bw = rtlphy->current_chan_bw; 112f1d2b4d3SLarry Finger 113f1d2b4d3SLarry Finger if (bw == HT_CHANNEL_WIDTH_20) 114f1d2b4d3SLarry Finger is_ht40 = false; 115f1d2b4d3SLarry Finger else if (bw == HT_CHANNEL_WIDTH_20_40) 116f1d2b4d3SLarry Finger is_ht40 = true; 117f1d2b4d3SLarry Finger 118f1d2b4d3SLarry Finger return is_ht40; 119f1d2b4d3SLarry Finger } 120f1d2b4d3SLarry Finger 121f1d2b4d3SLarry Finger static bool halbtc_legacy(struct rtl_priv *adapter) 122f1d2b4d3SLarry Finger { 123f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = adapter; 124f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtlpriv); 125f1d2b4d3SLarry Finger 126f1d2b4d3SLarry Finger bool is_legacy = false; 127f1d2b4d3SLarry Finger 128f1d2b4d3SLarry Finger if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G)) 129f1d2b4d3SLarry Finger is_legacy = true; 130f1d2b4d3SLarry Finger 131f1d2b4d3SLarry Finger return is_legacy; 132f1d2b4d3SLarry Finger } 133f1d2b4d3SLarry Finger 134f1d2b4d3SLarry Finger bool halbtc_is_wifi_uplink(struct rtl_priv *adapter) 135f1d2b4d3SLarry Finger { 136f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = adapter; 137f1d2b4d3SLarry Finger 138f1d2b4d3SLarry Finger if (rtlpriv->link_info.tx_busy_traffic) 139f1d2b4d3SLarry Finger return true; 140f1d2b4d3SLarry Finger else 141f1d2b4d3SLarry Finger return false; 142f1d2b4d3SLarry Finger } 143f1d2b4d3SLarry Finger 144f1d2b4d3SLarry Finger static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist) 145f1d2b4d3SLarry Finger { 146f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = 147f1d2b4d3SLarry Finger (struct rtl_priv *)btcoexist->adapter; 148f1d2b4d3SLarry Finger u32 wifi_bw = BTC_WIFI_BW_HT20; 149f1d2b4d3SLarry Finger 150f1d2b4d3SLarry Finger if (halbtc_is_bt40(rtlpriv)) { 151f1d2b4d3SLarry Finger wifi_bw = BTC_WIFI_BW_HT40; 152f1d2b4d3SLarry Finger } else { 153f1d2b4d3SLarry Finger if (halbtc_legacy(rtlpriv)) 154f1d2b4d3SLarry Finger wifi_bw = BTC_WIFI_BW_LEGACY; 155f1d2b4d3SLarry Finger else 156f1d2b4d3SLarry Finger wifi_bw = BTC_WIFI_BW_HT20; 157f1d2b4d3SLarry Finger } 158f1d2b4d3SLarry Finger return wifi_bw; 159f1d2b4d3SLarry Finger } 160f1d2b4d3SLarry Finger 161f1d2b4d3SLarry Finger static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist) 162f1d2b4d3SLarry Finger { 163f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 164f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 165f1d2b4d3SLarry Finger u8 chnl = 1; 166f1d2b4d3SLarry Finger 167f1d2b4d3SLarry Finger if (rtlphy->current_channel != 0) 168f1d2b4d3SLarry Finger chnl = rtlphy->current_channel; 16941880bb3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 170f1d2b4d3SLarry Finger "static halbtc_get_wifi_central_chnl:%d\n", chnl); 171f1d2b4d3SLarry Finger return chnl; 172f1d2b4d3SLarry Finger } 173f1d2b4d3SLarry Finger 174db8cb009SPing-Ke Shih u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv) 175db8cb009SPing-Ke Shih { 176db8cb009SPing-Ke Shih return rtlpriv->btcoexist.btc_info.single_ant_path; 177db8cb009SPing-Ke Shih } 178db8cb009SPing-Ke Shih 179e0215c14SPing-Ke Shih u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv) 180e0215c14SPing-Ke Shih { 181e0215c14SPing-Ke Shih return rtlpriv->btcoexist.btc_info.bt_type; 182e0215c14SPing-Ke Shih } 183e0215c14SPing-Ke Shih 1840de9b5dbSPing-Ke Shih u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv) 1850de9b5dbSPing-Ke Shih { 1860de9b5dbSPing-Ke Shih u8 num; 1870de9b5dbSPing-Ke Shih 1880de9b5dbSPing-Ke Shih if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2) 1890de9b5dbSPing-Ke Shih num = 2; 1900de9b5dbSPing-Ke Shih else 1910de9b5dbSPing-Ke Shih num = 1; 1920de9b5dbSPing-Ke Shih 1930de9b5dbSPing-Ke Shih return num; 1940de9b5dbSPing-Ke Shih } 1950de9b5dbSPing-Ke Shih 1967fe1fe75SPing-Ke Shih u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv) 1977fe1fe75SPing-Ke Shih { 1987fe1fe75SPing-Ke Shih struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 1997fe1fe75SPing-Ke Shih 2007fe1fe75SPing-Ke Shih return rtlhal->package_type; 2017fe1fe75SPing-Ke Shih } 2027fe1fe75SPing-Ke Shih 203f1d2b4d3SLarry Finger static void halbtc_leave_lps(struct btc_coexist *btcoexist) 204f1d2b4d3SLarry Finger { 205f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv; 206f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc; 207f1d2b4d3SLarry Finger bool ap_enable = false; 208f1d2b4d3SLarry Finger 209f1d2b4d3SLarry Finger rtlpriv = btcoexist->adapter; 210f1d2b4d3SLarry Finger ppsc = rtl_psc(rtlpriv); 211f1d2b4d3SLarry Finger 212f1d2b4d3SLarry Finger btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 213f1d2b4d3SLarry Finger &ap_enable); 214f1d2b4d3SLarry Finger 215f1d2b4d3SLarry Finger if (ap_enable) { 216c42ea613SYan-Hsuan Chuang RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, 217c42ea613SYan-Hsuan Chuang "%s()<--dont leave lps under AP mode\n", __func__); 218f1d2b4d3SLarry Finger return; 219f1d2b4d3SLarry Finger } 220f1d2b4d3SLarry Finger 221f1d2b4d3SLarry Finger btcoexist->bt_info.bt_ctrl_lps = true; 222f1d2b4d3SLarry Finger btcoexist->bt_info.bt_lps_on = false; 223c42ea613SYan-Hsuan Chuang rtl_lps_leave(rtlpriv->mac80211.hw); 224f1d2b4d3SLarry Finger } 225f1d2b4d3SLarry Finger 226f1d2b4d3SLarry Finger static void halbtc_enter_lps(struct btc_coexist *btcoexist) 227f1d2b4d3SLarry Finger { 228f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv; 229f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc; 230f1d2b4d3SLarry Finger bool ap_enable = false; 231f1d2b4d3SLarry Finger 232f1d2b4d3SLarry Finger rtlpriv = btcoexist->adapter; 233f1d2b4d3SLarry Finger ppsc = rtl_psc(rtlpriv); 234f1d2b4d3SLarry Finger 235f1d2b4d3SLarry Finger btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 236f1d2b4d3SLarry Finger &ap_enable); 237f1d2b4d3SLarry Finger 238f1d2b4d3SLarry Finger if (ap_enable) { 239c42ea613SYan-Hsuan Chuang RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG, 240c42ea613SYan-Hsuan Chuang "%s()<--dont enter lps under AP mode\n", __func__); 241f1d2b4d3SLarry Finger return; 242f1d2b4d3SLarry Finger } 243f1d2b4d3SLarry Finger 244f1d2b4d3SLarry Finger btcoexist->bt_info.bt_ctrl_lps = true; 245f1d2b4d3SLarry Finger btcoexist->bt_info.bt_lps_on = false; 246c42ea613SYan-Hsuan Chuang rtl_lps_enter(rtlpriv->mac80211.hw); 247f1d2b4d3SLarry Finger } 248f1d2b4d3SLarry Finger 249f1d2b4d3SLarry Finger static void halbtc_normal_lps(struct btc_coexist *btcoexist) 250f1d2b4d3SLarry Finger { 251f1d2b4d3SLarry Finger if (btcoexist->bt_info.bt_ctrl_lps) { 252f1d2b4d3SLarry Finger btcoexist->bt_info.bt_lps_on = false; 253f1d2b4d3SLarry Finger btcoexist->bt_info.bt_ctrl_lps = false; 254f1d2b4d3SLarry Finger } 255f1d2b4d3SLarry Finger } 256f1d2b4d3SLarry Finger 2577937f02dSYan-Hsuan Chuang static void halbtc_leave_low_power(struct btc_coexist *btcoexist) 258f1d2b4d3SLarry Finger { 259f1d2b4d3SLarry Finger } 260f1d2b4d3SLarry Finger 2617937f02dSYan-Hsuan Chuang static void halbtc_normal_low_power(struct btc_coexist *btcoexist) 262f1d2b4d3SLarry Finger { 263f1d2b4d3SLarry Finger } 264f1d2b4d3SLarry Finger 265c42ea613SYan-Hsuan Chuang static void halbtc_disable_low_power(struct btc_coexist *btcoexist, 266c42ea613SYan-Hsuan Chuang bool low_pwr_disable) 267f1d2b4d3SLarry Finger { 268c42ea613SYan-Hsuan Chuang /* TODO: original/leave 32k low power */ 269c42ea613SYan-Hsuan Chuang btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable; 270f1d2b4d3SLarry Finger } 271f1d2b4d3SLarry Finger 272c42ea613SYan-Hsuan Chuang static void halbtc_aggregation_check(struct btc_coexist *btcoexist) 273f1d2b4d3SLarry Finger { 274c42ea613SYan-Hsuan Chuang bool need_to_act = false; 275c42ea613SYan-Hsuan Chuang 276c42ea613SYan-Hsuan Chuang /* To void continuous deleteBA=>addBA=>deleteBA=>addBA 277c42ea613SYan-Hsuan Chuang * This function is not allowed to continuous called 278c42ea613SYan-Hsuan Chuang * It can only be called after 8 seconds 279c42ea613SYan-Hsuan Chuang */ 280c42ea613SYan-Hsuan Chuang 281c42ea613SYan-Hsuan Chuang if (btcoexist->bt_info.reject_agg_pkt) { 282c42ea613SYan-Hsuan Chuang ;/* TODO: reject */ 283c42ea613SYan-Hsuan Chuang btcoexist->bt_info.pre_reject_agg_pkt = 284c42ea613SYan-Hsuan Chuang btcoexist->bt_info.reject_agg_pkt; 285c42ea613SYan-Hsuan Chuang } else { 286c42ea613SYan-Hsuan Chuang if (btcoexist->bt_info.pre_reject_agg_pkt) { 287c42ea613SYan-Hsuan Chuang need_to_act = true; 288c42ea613SYan-Hsuan Chuang btcoexist->bt_info.pre_reject_agg_pkt = 289c42ea613SYan-Hsuan Chuang btcoexist->bt_info.reject_agg_pkt; 290c42ea613SYan-Hsuan Chuang } 291c42ea613SYan-Hsuan Chuang 292c42ea613SYan-Hsuan Chuang if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size != 293c42ea613SYan-Hsuan Chuang btcoexist->bt_info.bt_ctrl_agg_buf_size) { 294c42ea613SYan-Hsuan Chuang need_to_act = true; 295c42ea613SYan-Hsuan Chuang btcoexist->bt_info.pre_bt_ctrl_agg_buf_size = 296c42ea613SYan-Hsuan Chuang btcoexist->bt_info.bt_ctrl_agg_buf_size; 297c42ea613SYan-Hsuan Chuang } 298c42ea613SYan-Hsuan Chuang 299c42ea613SYan-Hsuan Chuang if (btcoexist->bt_info.bt_ctrl_agg_buf_size) { 300c42ea613SYan-Hsuan Chuang if (btcoexist->bt_info.pre_agg_buf_size != 301c42ea613SYan-Hsuan Chuang btcoexist->bt_info.agg_buf_size) { 302c42ea613SYan-Hsuan Chuang need_to_act = true; 303c42ea613SYan-Hsuan Chuang } 304c42ea613SYan-Hsuan Chuang btcoexist->bt_info.pre_agg_buf_size = 305c42ea613SYan-Hsuan Chuang btcoexist->bt_info.agg_buf_size; 306c42ea613SYan-Hsuan Chuang } 307c42ea613SYan-Hsuan Chuang } 308c42ea613SYan-Hsuan Chuang 309f1d2b4d3SLarry Finger } 310f1d2b4d3SLarry Finger 311f1d2b4d3SLarry Finger static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist) 312f1d2b4d3SLarry Finger { 313f1d2b4d3SLarry Finger return 0; 314f1d2b4d3SLarry Finger } 315f1d2b4d3SLarry Finger 316c42ea613SYan-Hsuan Chuang u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist) 317f1d2b4d3SLarry Finger { 318c42ea613SYan-Hsuan Chuang /* return value: 319c42ea613SYan-Hsuan Chuang * [31:16] => connected port number 320c42ea613SYan-Hsuan Chuang * [15:0] => port connected bit define 321c42ea613SYan-Hsuan Chuang */ 322c42ea613SYan-Hsuan Chuang struct rtl_priv *rtlpriv = btcoexist->adapter; 323c42ea613SYan-Hsuan Chuang struct rtl_mac *mac = rtl_mac(rtlpriv); 324c42ea613SYan-Hsuan Chuang u32 ret_val = 0; 325c42ea613SYan-Hsuan Chuang u32 port_connected_status = 0, num_of_connected_port = 0; 326c42ea613SYan-Hsuan Chuang 327c42ea613SYan-Hsuan Chuang if (mac->opmode == NL80211_IFTYPE_STATION && 328c42ea613SYan-Hsuan Chuang mac->link_state >= MAC80211_LINKED) { 329c42ea613SYan-Hsuan Chuang port_connected_status |= WIFI_STA_CONNECTED; 330c42ea613SYan-Hsuan Chuang num_of_connected_port++; 331c42ea613SYan-Hsuan Chuang } 332c42ea613SYan-Hsuan Chuang /* AP & ADHOC & MESH */ 333c42ea613SYan-Hsuan Chuang if (is_any_client_connect_to_ap(btcoexist)) { 334c42ea613SYan-Hsuan Chuang port_connected_status |= WIFI_AP_CONNECTED; 335c42ea613SYan-Hsuan Chuang num_of_connected_port++; 336c42ea613SYan-Hsuan Chuang } 337c42ea613SYan-Hsuan Chuang /* TODO: P2P Connected Status */ 338c42ea613SYan-Hsuan Chuang 339c42ea613SYan-Hsuan Chuang ret_val = (num_of_connected_port << 16) | port_connected_status; 340c42ea613SYan-Hsuan Chuang 341c42ea613SYan-Hsuan Chuang return ret_val; 342c42ea613SYan-Hsuan Chuang } 343c42ea613SYan-Hsuan Chuang 344c42ea613SYan-Hsuan Chuang static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv) 345c42ea613SYan-Hsuan Chuang { 346c42ea613SYan-Hsuan Chuang int undec_sm_pwdb = 0; 347f1d2b4d3SLarry Finger 348f1d2b4d3SLarry Finger if (rtlpriv->mac80211.link_state >= MAC80211_LINKED) 349f1d2b4d3SLarry Finger undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; 350f1d2b4d3SLarry Finger else /* associated entry pwdb */ 351f1d2b4d3SLarry Finger undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; 352f1d2b4d3SLarry Finger return undec_sm_pwdb; 353f1d2b4d3SLarry Finger } 354f1d2b4d3SLarry Finger 355f1d2b4d3SLarry Finger static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf) 356f1d2b4d3SLarry Finger { 357f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist; 358f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 359f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 360f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtlpriv); 361f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtlpriv); 362f1d2b4d3SLarry Finger bool *bool_tmp = (bool *)out_buf; 363f1d2b4d3SLarry Finger int *s32_tmp = (int *)out_buf; 364f1d2b4d3SLarry Finger u32 *u32_tmp = (u32 *)out_buf; 365f1d2b4d3SLarry Finger u8 *u8_tmp = (u8 *)out_buf; 366f1d2b4d3SLarry Finger bool tmp = false; 367f1d2b4d3SLarry Finger 368f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 369f1d2b4d3SLarry Finger return false; 370f1d2b4d3SLarry Finger 371f1d2b4d3SLarry Finger switch (get_type) { 372f1d2b4d3SLarry Finger case BTC_GET_BL_HS_OPERATION: 373f1d2b4d3SLarry Finger *bool_tmp = false; 374f1d2b4d3SLarry Finger break; 375f1d2b4d3SLarry Finger case BTC_GET_BL_HS_CONNECTING: 376f1d2b4d3SLarry Finger *bool_tmp = false; 377f1d2b4d3SLarry Finger break; 378f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_CONNECTED: 379c42ea613SYan-Hsuan Chuang if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION && 380c42ea613SYan-Hsuan Chuang rtlpriv->mac80211.link_state >= MAC80211_LINKED) 381c42ea613SYan-Hsuan Chuang tmp = true; 382c42ea613SYan-Hsuan Chuang if (is_any_client_connect_to_ap(btcoexist)) 383f1d2b4d3SLarry Finger tmp = true; 384f1d2b4d3SLarry Finger *bool_tmp = tmp; 385f1d2b4d3SLarry Finger break; 386f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_BUSY: 387f1d2b4d3SLarry Finger if (halbtc_is_wifi_busy(rtlpriv)) 388f1d2b4d3SLarry Finger *bool_tmp = true; 389f1d2b4d3SLarry Finger else 390f1d2b4d3SLarry Finger *bool_tmp = false; 391f1d2b4d3SLarry Finger break; 392f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_SCAN: 393f1d2b4d3SLarry Finger if (mac->act_scanning) 394f1d2b4d3SLarry Finger *bool_tmp = true; 395f1d2b4d3SLarry Finger else 396f1d2b4d3SLarry Finger *bool_tmp = false; 397f1d2b4d3SLarry Finger break; 398f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_LINK: 399f1d2b4d3SLarry Finger if (mac->link_state == MAC80211_LINKING) 400f1d2b4d3SLarry Finger *bool_tmp = true; 401f1d2b4d3SLarry Finger else 402f1d2b4d3SLarry Finger *bool_tmp = false; 403f1d2b4d3SLarry Finger break; 404c42ea613SYan-Hsuan Chuang case BTC_GET_BL_WIFI_ROAM: 405f1d2b4d3SLarry Finger if (mac->link_state == MAC80211_LINKING) 406f1d2b4d3SLarry Finger *bool_tmp = true; 407f1d2b4d3SLarry Finger else 408f1d2b4d3SLarry Finger *bool_tmp = false; 409f1d2b4d3SLarry Finger break; 410c42ea613SYan-Hsuan Chuang case BTC_GET_BL_WIFI_4_WAY_PROGRESS: 411c42ea613SYan-Hsuan Chuang /* TODO */ 412f1d2b4d3SLarry Finger *bool_tmp = false; 413f1d2b4d3SLarry Finger break; 414f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_UNDER_5G: 415c42ea613SYan-Hsuan Chuang /* TODO */ 416f1d2b4d3SLarry Finger *bool_tmp = false; 417f1d2b4d3SLarry Finger break; 418f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_AP_MODE_ENABLE: 419f1d2b4d3SLarry Finger *bool_tmp = false; 420f1d2b4d3SLarry Finger break; 421f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION: 422f1d2b4d3SLarry Finger if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm) 423f1d2b4d3SLarry Finger *bool_tmp = false; 424f1d2b4d3SLarry Finger else 425f1d2b4d3SLarry Finger *bool_tmp = true; 426f1d2b4d3SLarry Finger break; 427f1d2b4d3SLarry Finger case BTC_GET_BL_WIFI_UNDER_B_MODE: 428c42ea613SYan-Hsuan Chuang if (rtlpriv->mac80211.mode == WIRELESS_MODE_B) 429c42ea613SYan-Hsuan Chuang *bool_tmp = true; 430c42ea613SYan-Hsuan Chuang else 431c42ea613SYan-Hsuan Chuang *bool_tmp = false; 432f1d2b4d3SLarry Finger break; 433f1d2b4d3SLarry Finger case BTC_GET_BL_EXT_SWITCH: 434f1d2b4d3SLarry Finger *bool_tmp = false; 435f1d2b4d3SLarry Finger break; 436c42ea613SYan-Hsuan Chuang case BTC_GET_BL_WIFI_IS_IN_MP_MODE: 437c42ea613SYan-Hsuan Chuang *bool_tmp = false; 438c42ea613SYan-Hsuan Chuang break; 439c42ea613SYan-Hsuan Chuang case BTC_GET_BL_IS_ASUS_8723B: 440c42ea613SYan-Hsuan Chuang *bool_tmp = false; 441c42ea613SYan-Hsuan Chuang break; 442f1d2b4d3SLarry Finger case BTC_GET_S4_WIFI_RSSI: 443f1d2b4d3SLarry Finger *s32_tmp = halbtc_get_wifi_rssi(rtlpriv); 444f1d2b4d3SLarry Finger break; 445c42ea613SYan-Hsuan Chuang case BTC_GET_S4_HS_RSSI: 446c42ea613SYan-Hsuan Chuang /* TODO */ 447f1d2b4d3SLarry Finger *s32_tmp = halbtc_get_wifi_rssi(rtlpriv); 448f1d2b4d3SLarry Finger break; 449f1d2b4d3SLarry Finger case BTC_GET_U4_WIFI_BW: 450f1d2b4d3SLarry Finger *u32_tmp = halbtc_get_wifi_bw(btcoexist); 451f1d2b4d3SLarry Finger break; 452f1d2b4d3SLarry Finger case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: 453f1d2b4d3SLarry Finger if (halbtc_is_wifi_uplink(rtlpriv)) 454f1d2b4d3SLarry Finger *u32_tmp = BTC_WIFI_TRAFFIC_TX; 455f1d2b4d3SLarry Finger else 456f1d2b4d3SLarry Finger *u32_tmp = BTC_WIFI_TRAFFIC_RX; 457f1d2b4d3SLarry Finger break; 458f1d2b4d3SLarry Finger case BTC_GET_U4_WIFI_FW_VER: 459c42ea613SYan-Hsuan Chuang *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion; 460c42ea613SYan-Hsuan Chuang break; 461c42ea613SYan-Hsuan Chuang case BTC_GET_U4_WIFI_LINK_STATUS: 462c42ea613SYan-Hsuan Chuang *u32_tmp = halbtc_get_wifi_link_status(btcoexist); 463f1d2b4d3SLarry Finger break; 464f1d2b4d3SLarry Finger case BTC_GET_U4_BT_PATCH_VER: 465f1d2b4d3SLarry Finger *u32_tmp = halbtc_get_bt_patch_version(btcoexist); 466f1d2b4d3SLarry Finger break; 4671a281473SPing-Ke Shih case BTC_GET_U4_VENDOR: 4681a281473SPing-Ke Shih *u32_tmp = BTC_VENDOR_OTHER; 4691a281473SPing-Ke Shih break; 470f1d2b4d3SLarry Finger case BTC_GET_U1_WIFI_DOT11_CHNL: 471f1d2b4d3SLarry Finger *u8_tmp = rtlphy->current_channel; 472f1d2b4d3SLarry Finger break; 473f1d2b4d3SLarry Finger case BTC_GET_U1_WIFI_CENTRAL_CHNL: 474f1d2b4d3SLarry Finger *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist); 475f1d2b4d3SLarry Finger break; 476f1d2b4d3SLarry Finger case BTC_GET_U1_WIFI_HS_CHNL: 477c42ea613SYan-Hsuan Chuang *u8_tmp = 1; 478f1d2b4d3SLarry Finger break; 479c42ea613SYan-Hsuan Chuang case BTC_GET_U1_AP_NUM: 480c42ea613SYan-Hsuan Chuang /* driver do not know AP num, 481c42ea613SYan-Hsuan Chuang * so the return value here is not right 482c42ea613SYan-Hsuan Chuang */ 483c42ea613SYan-Hsuan Chuang *u8_tmp = 1; 484c42ea613SYan-Hsuan Chuang break; 485c42ea613SYan-Hsuan Chuang case BTC_GET_U1_ANT_TYPE: 486c42ea613SYan-Hsuan Chuang *u8_tmp = (u8)BTC_ANT_TYPE_0; 487c42ea613SYan-Hsuan Chuang break; 488c42ea613SYan-Hsuan Chuang case BTC_GET_U1_IOT_PEER: 489c42ea613SYan-Hsuan Chuang *u8_tmp = 0; 490f1d2b4d3SLarry Finger break; 491f1d2b4d3SLarry Finger 492f1d2b4d3SLarry Finger /************* 1Ant **************/ 493f1d2b4d3SLarry Finger case BTC_GET_U1_LPS_MODE: 494f1d2b4d3SLarry Finger *u8_tmp = btcoexist->pwr_mode_val[0]; 495f1d2b4d3SLarry Finger break; 496f1d2b4d3SLarry Finger 497f1d2b4d3SLarry Finger default: 498f1d2b4d3SLarry Finger break; 499f1d2b4d3SLarry Finger } 500f1d2b4d3SLarry Finger 501f1d2b4d3SLarry Finger return true; 502f1d2b4d3SLarry Finger } 503f1d2b4d3SLarry Finger 504f1d2b4d3SLarry Finger static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf) 505f1d2b4d3SLarry Finger { 506f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist; 507f1d2b4d3SLarry Finger bool *bool_tmp = (bool *)in_buf; 508f1d2b4d3SLarry Finger u8 *u8_tmp = (u8 *)in_buf; 509f1d2b4d3SLarry Finger u32 *u32_tmp = (u32 *)in_buf; 510f1d2b4d3SLarry Finger 511f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 512f1d2b4d3SLarry Finger return false; 513f1d2b4d3SLarry Finger 514f1d2b4d3SLarry Finger switch (set_type) { 515f1d2b4d3SLarry Finger /* set some bool type variables. */ 516f1d2b4d3SLarry Finger case BTC_SET_BL_BT_DISABLE: 517f1d2b4d3SLarry Finger btcoexist->bt_info.bt_disabled = *bool_tmp; 518f1d2b4d3SLarry Finger break; 519f1d2b4d3SLarry Finger case BTC_SET_BL_BT_TRAFFIC_BUSY: 520f1d2b4d3SLarry Finger btcoexist->bt_info.bt_busy = *bool_tmp; 521f1d2b4d3SLarry Finger break; 522f1d2b4d3SLarry Finger case BTC_SET_BL_BT_LIMITED_DIG: 523f1d2b4d3SLarry Finger btcoexist->bt_info.limited_dig = *bool_tmp; 524f1d2b4d3SLarry Finger break; 525f1d2b4d3SLarry Finger case BTC_SET_BL_FORCE_TO_ROAM: 526f1d2b4d3SLarry Finger btcoexist->bt_info.force_to_roam = *bool_tmp; 527f1d2b4d3SLarry Finger break; 528f1d2b4d3SLarry Finger case BTC_SET_BL_TO_REJ_AP_AGG_PKT: 529f1d2b4d3SLarry Finger btcoexist->bt_info.reject_agg_pkt = *bool_tmp; 530f1d2b4d3SLarry Finger break; 531f1d2b4d3SLarry Finger case BTC_SET_BL_BT_CTRL_AGG_SIZE: 532c42ea613SYan-Hsuan Chuang btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp; 533f1d2b4d3SLarry Finger break; 534f1d2b4d3SLarry Finger case BTC_SET_BL_INC_SCAN_DEV_NUM: 535f1d2b4d3SLarry Finger btcoexist->bt_info.increase_scan_dev_num = *bool_tmp; 536f1d2b4d3SLarry Finger break; 537c42ea613SYan-Hsuan Chuang case BTC_SET_BL_BT_TX_RX_MASK: 538c42ea613SYan-Hsuan Chuang btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp; 539c42ea613SYan-Hsuan Chuang break; 540c42ea613SYan-Hsuan Chuang case BTC_SET_BL_MIRACAST_PLUS_BT: 541c42ea613SYan-Hsuan Chuang btcoexist->bt_info.miracast_plus_bt = *bool_tmp; 542c42ea613SYan-Hsuan Chuang break; 543f1d2b4d3SLarry Finger /* set some u1Byte type variables. */ 544f1d2b4d3SLarry Finger case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON: 545f1d2b4d3SLarry Finger btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp; 546f1d2b4d3SLarry Finger break; 547f1d2b4d3SLarry Finger case BTC_SET_U1_AGG_BUF_SIZE: 548f1d2b4d3SLarry Finger btcoexist->bt_info.agg_buf_size = *u8_tmp; 549f1d2b4d3SLarry Finger break; 550c42ea613SYan-Hsuan Chuang 551f1d2b4d3SLarry Finger /* the following are some action which will be triggered */ 552f1d2b4d3SLarry Finger case BTC_SET_ACT_GET_BT_RSSI: 553f1d2b4d3SLarry Finger break; 554f1d2b4d3SLarry Finger case BTC_SET_ACT_AGGREGATE_CTRL: 555c42ea613SYan-Hsuan Chuang halbtc_aggregation_check(btcoexist); 556f1d2b4d3SLarry Finger break; 557f1d2b4d3SLarry Finger 558f1d2b4d3SLarry Finger /* 1Ant */ 559f1d2b4d3SLarry Finger case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE: 560f1d2b4d3SLarry Finger btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp; 561f1d2b4d3SLarry Finger break; 562f1d2b4d3SLarry Finger case BTC_SET_UI_SCAN_SIG_COMPENSATION: 563f1d2b4d3SLarry Finger break; 564c42ea613SYan-Hsuan Chuang case BTC_SET_U1_LPS_VAL: 565f1d2b4d3SLarry Finger btcoexist->bt_info.lps_val = *u8_tmp; 566f1d2b4d3SLarry Finger break; 567c42ea613SYan-Hsuan Chuang case BTC_SET_U1_RPWM_VAL: 568f1d2b4d3SLarry Finger btcoexist->bt_info.rpwm_val = *u8_tmp; 569f1d2b4d3SLarry Finger break; 570f1d2b4d3SLarry Finger /* the following are some action which will be triggered */ 571f1d2b4d3SLarry Finger case BTC_SET_ACT_LEAVE_LPS: 572f1d2b4d3SLarry Finger halbtc_leave_lps(btcoexist); 573f1d2b4d3SLarry Finger break; 574f1d2b4d3SLarry Finger case BTC_SET_ACT_ENTER_LPS: 575f1d2b4d3SLarry Finger halbtc_enter_lps(btcoexist); 576f1d2b4d3SLarry Finger break; 577f1d2b4d3SLarry Finger case BTC_SET_ACT_NORMAL_LPS: 578f1d2b4d3SLarry Finger halbtc_normal_lps(btcoexist); 579f1d2b4d3SLarry Finger break; 580f1d2b4d3SLarry Finger case BTC_SET_ACT_DISABLE_LOW_POWER: 581c42ea613SYan-Hsuan Chuang halbtc_disable_low_power(btcoexist, *bool_tmp); 582f1d2b4d3SLarry Finger break; 583c6821613SYan-Hsuan Chuang case BTC_SET_ACT_UPDATE_RAMASK: 584f1d2b4d3SLarry Finger btcoexist->bt_info.ra_mask = *u32_tmp; 585f1d2b4d3SLarry Finger break; 586f1d2b4d3SLarry Finger case BTC_SET_ACT_SEND_MIMO_PS: 587f1d2b4d3SLarry Finger break; 588f1d2b4d3SLarry Finger case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/ 589f1d2b4d3SLarry Finger break; 590f1d2b4d3SLarry Finger case BTC_SET_ACT_CTRL_BT_COEX: 591f1d2b4d3SLarry Finger break; 592c42ea613SYan-Hsuan Chuang case BTC_SET_ACT_CTRL_8723B_ANT: 593c42ea613SYan-Hsuan Chuang break; 594f1d2b4d3SLarry Finger default: 595f1d2b4d3SLarry Finger break; 596f1d2b4d3SLarry Finger } 597f1d2b4d3SLarry Finger 598f1d2b4d3SLarry Finger return true; 599f1d2b4d3SLarry Finger } 600f1d2b4d3SLarry Finger 601f1d2b4d3SLarry Finger /************************************************************ 602f1d2b4d3SLarry Finger * IO related function 603f1d2b4d3SLarry Finger ************************************************************/ 604f1d2b4d3SLarry Finger static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr) 605f1d2b4d3SLarry Finger { 606f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 607f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 608f1d2b4d3SLarry Finger 609f1d2b4d3SLarry Finger return rtl_read_byte(rtlpriv, reg_addr); 610f1d2b4d3SLarry Finger } 611f1d2b4d3SLarry Finger 612f1d2b4d3SLarry Finger static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr) 613f1d2b4d3SLarry Finger { 614f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 615f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 616f1d2b4d3SLarry Finger 617f1d2b4d3SLarry Finger return rtl_read_word(rtlpriv, reg_addr); 618f1d2b4d3SLarry Finger } 619f1d2b4d3SLarry Finger 620f1d2b4d3SLarry Finger static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr) 621f1d2b4d3SLarry Finger { 622f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 623f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 624f1d2b4d3SLarry Finger 625f1d2b4d3SLarry Finger return rtl_read_dword(rtlpriv, reg_addr); 626f1d2b4d3SLarry Finger } 627f1d2b4d3SLarry Finger 628f1d2b4d3SLarry Finger static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data) 629f1d2b4d3SLarry Finger { 630f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 631f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 632f1d2b4d3SLarry Finger 633f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, reg_addr, data); 634f1d2b4d3SLarry Finger } 635f1d2b4d3SLarry Finger 636f1d2b4d3SLarry Finger static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr, 637f1d2b4d3SLarry Finger u32 bit_mask, u8 data) 638f1d2b4d3SLarry Finger { 639f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 640f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 641f1d2b4d3SLarry Finger u8 original_value, bit_shift = 0; 642f1d2b4d3SLarry Finger u8 i; 643f1d2b4d3SLarry Finger 644f1d2b4d3SLarry Finger if (bit_mask != MASKDWORD) {/*if not "double word" write*/ 645f1d2b4d3SLarry Finger original_value = rtl_read_byte(rtlpriv, reg_addr); 646f1d2b4d3SLarry Finger for (i = 0; i <= 7; i++) { 647f1d2b4d3SLarry Finger if ((bit_mask>>i) & 0x1) 648f1d2b4d3SLarry Finger break; 649f1d2b4d3SLarry Finger } 650f1d2b4d3SLarry Finger bit_shift = i; 651f1d2b4d3SLarry Finger data = (original_value & (~bit_mask)) | 652f1d2b4d3SLarry Finger ((data << bit_shift) & bit_mask); 653f1d2b4d3SLarry Finger } 654f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, reg_addr, data); 655f1d2b4d3SLarry Finger } 656f1d2b4d3SLarry Finger 657f1d2b4d3SLarry Finger static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data) 658f1d2b4d3SLarry Finger { 659f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 660f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 661f1d2b4d3SLarry Finger 662f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, reg_addr, data); 663f1d2b4d3SLarry Finger } 664f1d2b4d3SLarry Finger 665f1d2b4d3SLarry Finger static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data) 666f1d2b4d3SLarry Finger { 667f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = 668f1d2b4d3SLarry Finger (struct btc_coexist *)bt_context; 669f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 670f1d2b4d3SLarry Finger 671f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, reg_addr, data); 672f1d2b4d3SLarry Finger } 673f1d2b4d3SLarry Finger 674c42ea613SYan-Hsuan Chuang void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr, u8 data) 675c42ea613SYan-Hsuan Chuang { 676c42ea613SYan-Hsuan Chuang struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 677c42ea613SYan-Hsuan Chuang struct rtl_priv *rtlpriv = btcoexist->adapter; 678c42ea613SYan-Hsuan Chuang 679c42ea613SYan-Hsuan Chuang if (btcoexist->chip_interface == BTC_INTF_SDIO) 680c42ea613SYan-Hsuan Chuang ; 681c42ea613SYan-Hsuan Chuang else if (btcoexist->chip_interface == BTC_INTF_PCI) 682c42ea613SYan-Hsuan Chuang rtl_write_byte(rtlpriv, reg_addr, data); 683c42ea613SYan-Hsuan Chuang else if (btcoexist->chip_interface == BTC_INTF_USB) 684c42ea613SYan-Hsuan Chuang rtl_write_byte(rtlpriv, reg_addr, data); 685c42ea613SYan-Hsuan Chuang } 686c42ea613SYan-Hsuan Chuang 687c42ea613SYan-Hsuan Chuang void halbtc_set_macreg(void *btc_context, u32 reg_addr, u32 bit_mask, u32 data) 688c42ea613SYan-Hsuan Chuang { 689c42ea613SYan-Hsuan Chuang struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 690c42ea613SYan-Hsuan Chuang struct rtl_priv *rtlpriv = btcoexist->adapter; 691c42ea613SYan-Hsuan Chuang 692c42ea613SYan-Hsuan Chuang rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data); 693c42ea613SYan-Hsuan Chuang } 694c42ea613SYan-Hsuan Chuang 695c42ea613SYan-Hsuan Chuang u32 halbtc_get_macreg(void *btc_context, u32 reg_addr, u32 bit_mask) 696c42ea613SYan-Hsuan Chuang { 697c42ea613SYan-Hsuan Chuang struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 698c42ea613SYan-Hsuan Chuang struct rtl_priv *rtlpriv = btcoexist->adapter; 699c42ea613SYan-Hsuan Chuang 700c42ea613SYan-Hsuan Chuang return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask); 701c42ea613SYan-Hsuan Chuang } 702c42ea613SYan-Hsuan Chuang 703f1d2b4d3SLarry Finger static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask, 704f1d2b4d3SLarry Finger u32 data) 705f1d2b4d3SLarry Finger { 706f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 707f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 708f1d2b4d3SLarry Finger 709f1d2b4d3SLarry Finger rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data); 710f1d2b4d3SLarry Finger } 711f1d2b4d3SLarry Finger 712f1d2b4d3SLarry Finger static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask) 713f1d2b4d3SLarry Finger { 714f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 715f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 716f1d2b4d3SLarry Finger 717f1d2b4d3SLarry Finger return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask); 718f1d2b4d3SLarry Finger } 719f1d2b4d3SLarry Finger 720f1d2b4d3SLarry Finger static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, 721f1d2b4d3SLarry Finger u32 bit_mask, u32 data) 722f1d2b4d3SLarry Finger { 723f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 724f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 725f1d2b4d3SLarry Finger 726f1d2b4d3SLarry Finger rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data); 727f1d2b4d3SLarry Finger } 728f1d2b4d3SLarry Finger 729f1d2b4d3SLarry Finger static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, 730f1d2b4d3SLarry Finger u32 bit_mask) 731f1d2b4d3SLarry Finger { 732f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 733f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 734f1d2b4d3SLarry Finger 735f1d2b4d3SLarry Finger return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask); 736f1d2b4d3SLarry Finger } 737f1d2b4d3SLarry Finger 738f1d2b4d3SLarry Finger static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id, 739f1d2b4d3SLarry Finger u32 cmd_len, u8 *cmd_buf) 740f1d2b4d3SLarry Finger { 741f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context; 742f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 743f1d2b4d3SLarry Finger 744f1d2b4d3SLarry Finger rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id, 745f1d2b4d3SLarry Finger cmd_len, cmd_buf); 746f1d2b4d3SLarry Finger } 747f1d2b4d3SLarry Finger 748c42ea613SYan-Hsuan Chuang void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val) 749c42ea613SYan-Hsuan Chuang { 750c42ea613SYan-Hsuan Chuang struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context; 751c42ea613SYan-Hsuan Chuang struct rtl_priv *rtlpriv = btcoexist->adapter; 752c42ea613SYan-Hsuan Chuang u8 cmd_buffer1[4] = {0}; 753c42ea613SYan-Hsuan Chuang u8 cmd_buffer2[4] = {0}; 754c42ea613SYan-Hsuan Chuang u8 *addr_to_set = (u8 *)&offset; 755c42ea613SYan-Hsuan Chuang u8 *value_to_set = (u8 *)&set_val; 756c42ea613SYan-Hsuan Chuang u8 oper_ver = 0; 757c42ea613SYan-Hsuan Chuang u8 req_num = 0; 758c42ea613SYan-Hsuan Chuang 759c42ea613SYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 760c42ea613SYan-Hsuan Chuang cmd_buffer1[0] |= (oper_ver & 0x0f); /* Set OperVer */ 761c42ea613SYan-Hsuan Chuang cmd_buffer1[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */ 762c42ea613SYan-Hsuan Chuang cmd_buffer1[1] = 0x0d; /* OpCode: BT_LO_OP_WRITE_REG_VALUE */ 763c42ea613SYan-Hsuan Chuang cmd_buffer1[2] = value_to_set[0]; /* Set WriteRegValue */ 764c42ea613SYan-Hsuan Chuang rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4, 765c42ea613SYan-Hsuan Chuang &cmd_buffer1[0]); 766c42ea613SYan-Hsuan Chuang 767c42ea613SYan-Hsuan Chuang msleep(200); 768c42ea613SYan-Hsuan Chuang req_num++; 769c42ea613SYan-Hsuan Chuang 770c42ea613SYan-Hsuan Chuang cmd_buffer2[0] |= (oper_ver & 0x0f); /* Set OperVer */ 771c42ea613SYan-Hsuan Chuang cmd_buffer2[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */ 772c42ea613SYan-Hsuan Chuang cmd_buffer2[1] = 0x0c; /* OpCode: BT_LO_OP_WRITE_REG_ADDR */ 773c42ea613SYan-Hsuan Chuang cmd_buffer2[3] = addr_to_set[0]; /* Set WriteRegAddr */ 774c42ea613SYan-Hsuan Chuang rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, 4, 775c42ea613SYan-Hsuan Chuang &cmd_buffer2[0]); 776c42ea613SYan-Hsuan Chuang } 777c42ea613SYan-Hsuan Chuang } 778c42ea613SYan-Hsuan Chuang 7797937f02dSYan-Hsuan Chuang bool halbtc_under_ips(struct btc_coexist *btcoexist) 7807937f02dSYan-Hsuan Chuang { 7817937f02dSYan-Hsuan Chuang struct rtl_priv *rtlpriv = btcoexist->adapter; 7827937f02dSYan-Hsuan Chuang struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv); 7837937f02dSYan-Hsuan Chuang enum rf_pwrstate rtstate; 7847937f02dSYan-Hsuan Chuang 7857937f02dSYan-Hsuan Chuang if (ppsc->inactiveps) { 7867937f02dSYan-Hsuan Chuang rtstate = ppsc->rfpwr_state; 7877937f02dSYan-Hsuan Chuang 7887937f02dSYan-Hsuan Chuang if (rtstate != ERFON && 7897937f02dSYan-Hsuan Chuang ppsc->rfoff_reason == RF_CHANGE_BY_IPS) { 7907937f02dSYan-Hsuan Chuang return true; 7917937f02dSYan-Hsuan Chuang } 7927937f02dSYan-Hsuan Chuang } 7937937f02dSYan-Hsuan Chuang 7947937f02dSYan-Hsuan Chuang return false; 7957937f02dSYan-Hsuan Chuang } 7967937f02dSYan-Hsuan Chuang 797f1d2b4d3SLarry Finger /***************************************************************** 798f1d2b4d3SLarry Finger * Extern functions called by other module 799f1d2b4d3SLarry Finger *****************************************************************/ 800c42ea613SYan-Hsuan Chuang bool exhalbtc_initlize_variables(void) 801f1d2b4d3SLarry Finger { 802f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = &gl_bt_coexist; 803f1d2b4d3SLarry Finger 804f1d2b4d3SLarry Finger halbtc_dbg_init(); 805f1d2b4d3SLarry Finger 806f1d2b4d3SLarry Finger btcoexist->chip_interface = BTC_INTF_UNKNOWN; 807f1d2b4d3SLarry Finger 808f1d2b4d3SLarry Finger btcoexist->btc_read_1byte = halbtc_read_1byte; 809f1d2b4d3SLarry Finger btcoexist->btc_write_1byte = halbtc_write_1byte; 810f1d2b4d3SLarry Finger btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte; 811f1d2b4d3SLarry Finger btcoexist->btc_read_2byte = halbtc_read_2byte; 812f1d2b4d3SLarry Finger btcoexist->btc_write_2byte = halbtc_write_2byte; 813f1d2b4d3SLarry Finger btcoexist->btc_read_4byte = halbtc_read_4byte; 814f1d2b4d3SLarry Finger btcoexist->btc_write_4byte = halbtc_write_4byte; 815c42ea613SYan-Hsuan Chuang btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte; 816f1d2b4d3SLarry Finger 817f1d2b4d3SLarry Finger btcoexist->btc_set_bb_reg = halbtc_set_bbreg; 818f1d2b4d3SLarry Finger btcoexist->btc_get_bb_reg = halbtc_get_bbreg; 819f1d2b4d3SLarry Finger 820f1d2b4d3SLarry Finger btcoexist->btc_set_rf_reg = halbtc_set_rfreg; 821f1d2b4d3SLarry Finger btcoexist->btc_get_rf_reg = halbtc_get_rfreg; 822f1d2b4d3SLarry Finger 823f1d2b4d3SLarry Finger btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd; 824f1d2b4d3SLarry Finger 825f1d2b4d3SLarry Finger btcoexist->btc_get = halbtc_get; 826f1d2b4d3SLarry Finger btcoexist->btc_set = halbtc_set; 827c42ea613SYan-Hsuan Chuang btcoexist->btc_set_bt_reg = halbtc_set_bt_reg; 828c42ea613SYan-Hsuan Chuang 829f1d2b4d3SLarry Finger 830f1d2b4d3SLarry Finger btcoexist->bt_info.bt_ctrl_buf_size = false; 831f1d2b4d3SLarry Finger btcoexist->bt_info.agg_buf_size = 5; 832f1d2b4d3SLarry Finger 833f1d2b4d3SLarry Finger btcoexist->bt_info.increase_scan_dev_num = false; 834f1d2b4d3SLarry Finger return true; 835f1d2b4d3SLarry Finger } 836f1d2b4d3SLarry Finger 8370199103eSYan-Hsuan Chuang bool exhalbtc_bind_bt_coex_withadapter(void *adapter) 8380199103eSYan-Hsuan Chuang { 8390199103eSYan-Hsuan Chuang struct btc_coexist *btcoexist = &gl_bt_coexist; 8400199103eSYan-Hsuan Chuang struct rtl_priv *rtlpriv = adapter; 8410199103eSYan-Hsuan Chuang u8 ant_num = 2, chip_type, single_ant_path = 0; 8420199103eSYan-Hsuan Chuang 8430199103eSYan-Hsuan Chuang if (btcoexist->binded) 8440199103eSYan-Hsuan Chuang return false; 8450199103eSYan-Hsuan Chuang 8460199103eSYan-Hsuan Chuang btcoexist->binded = true; 8470199103eSYan-Hsuan Chuang btcoexist->statistics.cnt_bind++; 8480199103eSYan-Hsuan Chuang 8490199103eSYan-Hsuan Chuang btcoexist->adapter = adapter; 8500199103eSYan-Hsuan Chuang 8510199103eSYan-Hsuan Chuang btcoexist->stack_info.profile_notified = false; 8520199103eSYan-Hsuan Chuang 8530199103eSYan-Hsuan Chuang btcoexist->bt_info.bt_ctrl_agg_buf_size = false; 8540199103eSYan-Hsuan Chuang btcoexist->bt_info.agg_buf_size = 5; 8550199103eSYan-Hsuan Chuang 8560199103eSYan-Hsuan Chuang btcoexist->bt_info.increase_scan_dev_num = false; 8570199103eSYan-Hsuan Chuang btcoexist->bt_info.miracast_plus_bt = false; 8580199103eSYan-Hsuan Chuang 8590199103eSYan-Hsuan Chuang chip_type = rtl_get_hwpg_bt_type(rtlpriv); 8600199103eSYan-Hsuan Chuang exhalbtc_set_chip_type(chip_type); 8610199103eSYan-Hsuan Chuang ant_num = rtl_get_hwpg_ant_num(rtlpriv); 8620199103eSYan-Hsuan Chuang exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num); 8630199103eSYan-Hsuan Chuang 8640199103eSYan-Hsuan Chuang /* set default antenna position to main port */ 8650199103eSYan-Hsuan Chuang btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; 8660199103eSYan-Hsuan Chuang 8670199103eSYan-Hsuan Chuang single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv); 8680199103eSYan-Hsuan Chuang exhalbtc_set_single_ant_path(single_ant_path); 8690199103eSYan-Hsuan Chuang 8700199103eSYan-Hsuan Chuang if (rtl_get_hwpg_package_type(rtlpriv) == 0) 8710199103eSYan-Hsuan Chuang btcoexist->board_info.tfbga_package = false; 8720199103eSYan-Hsuan Chuang else if (rtl_get_hwpg_package_type(rtlpriv) == 1) 8730199103eSYan-Hsuan Chuang btcoexist->board_info.tfbga_package = false; 8740199103eSYan-Hsuan Chuang else 8750199103eSYan-Hsuan Chuang btcoexist->board_info.tfbga_package = true; 8760199103eSYan-Hsuan Chuang 8770199103eSYan-Hsuan Chuang if (btcoexist->board_info.tfbga_package) 8780199103eSYan-Hsuan Chuang RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 8790199103eSYan-Hsuan Chuang "[BTCoex], Package Type = TFBGA\n"); 8800199103eSYan-Hsuan Chuang else 8810199103eSYan-Hsuan Chuang RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 8820199103eSYan-Hsuan Chuang "[BTCoex], Package Type = Non-TFBGA\n"); 8830199103eSYan-Hsuan Chuang 8840199103eSYan-Hsuan Chuang return true; 8850199103eSYan-Hsuan Chuang } 8860199103eSYan-Hsuan Chuang 88760f44100SYan-Hsuan Chuang void exhalbtc_power_on_setting(struct btc_coexist *btcoexist) 88860f44100SYan-Hsuan Chuang { 88960f44100SYan-Hsuan Chuang if (!halbtc_is_bt_coexist_available(btcoexist)) 89060f44100SYan-Hsuan Chuang return; 89160f44100SYan-Hsuan Chuang 89260f44100SYan-Hsuan Chuang btcoexist->statistics.cnt_power_on++; 89360f44100SYan-Hsuan Chuang 89460f44100SYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 89560f44100SYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 89660f44100SYan-Hsuan Chuang ex_btc8723b2ant_power_on_setting(btcoexist); 89760f44100SYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 89860f44100SYan-Hsuan Chuang ex_btc8723b1ant_power_on_setting(btcoexist); 89960f44100SYan-Hsuan Chuang } 90060f44100SYan-Hsuan Chuang } 90160f44100SYan-Hsuan Chuang 9026fbbc82aSYan-Hsuan Chuang void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist) 9036fbbc82aSYan-Hsuan Chuang { 9046fbbc82aSYan-Hsuan Chuang if (!halbtc_is_bt_coexist_available(btcoexist)) 9056fbbc82aSYan-Hsuan Chuang return; 9066fbbc82aSYan-Hsuan Chuang 9076fbbc82aSYan-Hsuan Chuang btcoexist->statistics.cnt_pre_load_firmware++; 9086fbbc82aSYan-Hsuan Chuang 9096fbbc82aSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 9106fbbc82aSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 9116fbbc82aSYan-Hsuan Chuang ex_btc8723b2ant_pre_load_firmware(btcoexist); 9126fbbc82aSYan-Hsuan Chuang } 9136fbbc82aSYan-Hsuan Chuang } 9146fbbc82aSYan-Hsuan Chuang 915f1d2b4d3SLarry Finger void exhalbtc_init_hw_config(struct btc_coexist *btcoexist) 916f1d2b4d3SLarry Finger { 9177937f02dSYan-Hsuan Chuang bool wifi_only = true; 918f1d2b4d3SLarry Finger 919f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 920f1d2b4d3SLarry Finger return; 921f1d2b4d3SLarry Finger 922f1d2b4d3SLarry Finger btcoexist->statistics.cnt_init_hw_config++; 923f1d2b4d3SLarry Finger 9247937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 9257937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 9267937f02dSYan-Hsuan Chuang ex_btc8821a2ant_init_hwconfig(btcoexist); 9277937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 9287937f02dSYan-Hsuan Chuang ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only); 9297937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 9307937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 931f1d2b4d3SLarry Finger ex_btc8723b2ant_init_hwconfig(btcoexist); 9327937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 9337937f02dSYan-Hsuan Chuang ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only); 9347937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) { 9357937f02dSYan-Hsuan Chuang /* 8723A has no this function */ 9367937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 9377937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 9387937f02dSYan-Hsuan Chuang ex_btc8192e2ant_init_hwconfig(btcoexist); 9397937f02dSYan-Hsuan Chuang } 940f1d2b4d3SLarry Finger } 941f1d2b4d3SLarry Finger 942f1d2b4d3SLarry Finger void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist) 943f1d2b4d3SLarry Finger { 944f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 945f1d2b4d3SLarry Finger return; 946f1d2b4d3SLarry Finger 947f1d2b4d3SLarry Finger btcoexist->statistics.cnt_init_coex_dm++; 948f1d2b4d3SLarry Finger 9497937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 9507937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 9517937f02dSYan-Hsuan Chuang ex_btc8821a2ant_init_coex_dm(btcoexist); 9527937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 9537937f02dSYan-Hsuan Chuang ex_btc8821a1ant_init_coex_dm(btcoexist); 9547937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 9557937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 956f1d2b4d3SLarry Finger ex_btc8723b2ant_init_coex_dm(btcoexist); 9577937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 9587937f02dSYan-Hsuan Chuang ex_btc8723b1ant_init_coex_dm(btcoexist); 9597937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 9607937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 9617937f02dSYan-Hsuan Chuang ex_btc8192e2ant_init_coex_dm(btcoexist); 9627937f02dSYan-Hsuan Chuang } 963f1d2b4d3SLarry Finger 964f1d2b4d3SLarry Finger btcoexist->initilized = true; 965f1d2b4d3SLarry Finger } 966f1d2b4d3SLarry Finger 967f1d2b4d3SLarry Finger void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type) 968f1d2b4d3SLarry Finger { 969f1d2b4d3SLarry Finger u8 ips_type; 970f1d2b4d3SLarry Finger 971f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 972f1d2b4d3SLarry Finger return; 973f1d2b4d3SLarry Finger btcoexist->statistics.cnt_ips_notify++; 974f1d2b4d3SLarry Finger if (btcoexist->manual_control) 975f1d2b4d3SLarry Finger return; 976f1d2b4d3SLarry Finger 977f1d2b4d3SLarry Finger if (ERFOFF == type) 978f1d2b4d3SLarry Finger ips_type = BTC_IPS_ENTER; 979f1d2b4d3SLarry Finger else 980f1d2b4d3SLarry Finger ips_type = BTC_IPS_LEAVE; 981f1d2b4d3SLarry Finger 9827937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 983f1d2b4d3SLarry Finger 9847937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 9857937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 9867937f02dSYan-Hsuan Chuang ex_btc8821a2ant_ips_notify(btcoexist, ips_type); 9877937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 9887937f02dSYan-Hsuan Chuang ex_btc8821a1ant_ips_notify(btcoexist, ips_type); 9897937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 9907937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 991f1d2b4d3SLarry Finger ex_btc8723b2ant_ips_notify(btcoexist, ips_type); 9927937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 9937937f02dSYan-Hsuan Chuang ex_btc8723b1ant_ips_notify(btcoexist, ips_type); 9947937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 9957937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 9967937f02dSYan-Hsuan Chuang ex_btc8192e2ant_ips_notify(btcoexist, ips_type); 9977937f02dSYan-Hsuan Chuang } 998f1d2b4d3SLarry Finger 9997937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 1000f1d2b4d3SLarry Finger } 1001f1d2b4d3SLarry Finger 1002f1d2b4d3SLarry Finger void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type) 1003f1d2b4d3SLarry Finger { 1004f1d2b4d3SLarry Finger u8 lps_type; 1005f1d2b4d3SLarry Finger 1006f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1007f1d2b4d3SLarry Finger return; 1008f1d2b4d3SLarry Finger btcoexist->statistics.cnt_lps_notify++; 1009f1d2b4d3SLarry Finger if (btcoexist->manual_control) 1010f1d2b4d3SLarry Finger return; 1011f1d2b4d3SLarry Finger 1012f1d2b4d3SLarry Finger if (EACTIVE == type) 1013f1d2b4d3SLarry Finger lps_type = BTC_LPS_DISABLE; 1014f1d2b4d3SLarry Finger else 1015f1d2b4d3SLarry Finger lps_type = BTC_LPS_ENABLE; 1016f1d2b4d3SLarry Finger 10177937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 10187937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 10197937f02dSYan-Hsuan Chuang ex_btc8821a2ant_lps_notify(btcoexist, lps_type); 10207937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 10217937f02dSYan-Hsuan Chuang ex_btc8821a1ant_lps_notify(btcoexist, lps_type); 10227937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 10237937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1024f1d2b4d3SLarry Finger ex_btc8723b2ant_lps_notify(btcoexist, lps_type); 10257937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 10267937f02dSYan-Hsuan Chuang ex_btc8723b1ant_lps_notify(btcoexist, lps_type); 10277937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 10287937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 10297937f02dSYan-Hsuan Chuang ex_btc8192e2ant_lps_notify(btcoexist, lps_type); 10307937f02dSYan-Hsuan Chuang } 1031f1d2b4d3SLarry Finger } 1032f1d2b4d3SLarry Finger 1033f1d2b4d3SLarry Finger void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type) 1034f1d2b4d3SLarry Finger { 1035f1d2b4d3SLarry Finger u8 scan_type; 1036f1d2b4d3SLarry Finger 1037f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1038f1d2b4d3SLarry Finger return; 1039f1d2b4d3SLarry Finger btcoexist->statistics.cnt_scan_notify++; 1040f1d2b4d3SLarry Finger if (btcoexist->manual_control) 1041f1d2b4d3SLarry Finger return; 1042f1d2b4d3SLarry Finger 1043f1d2b4d3SLarry Finger if (type) 1044f1d2b4d3SLarry Finger scan_type = BTC_SCAN_START; 1045f1d2b4d3SLarry Finger else 1046f1d2b4d3SLarry Finger scan_type = BTC_SCAN_FINISH; 1047f1d2b4d3SLarry Finger 10487937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 1049f1d2b4d3SLarry Finger 10507937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 10517937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 10527937f02dSYan-Hsuan Chuang ex_btc8821a2ant_scan_notify(btcoexist, scan_type); 10537937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 10547937f02dSYan-Hsuan Chuang ex_btc8821a1ant_scan_notify(btcoexist, scan_type); 10557937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 10567937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1057f1d2b4d3SLarry Finger ex_btc8723b2ant_scan_notify(btcoexist, scan_type); 10587937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 10597937f02dSYan-Hsuan Chuang ex_btc8723b1ant_scan_notify(btcoexist, scan_type); 10607937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 10617937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 10627937f02dSYan-Hsuan Chuang ex_btc8192e2ant_scan_notify(btcoexist, scan_type); 10637937f02dSYan-Hsuan Chuang } 1064f1d2b4d3SLarry Finger 10657937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 1066f1d2b4d3SLarry Finger } 1067f1d2b4d3SLarry Finger 1068f1d2b4d3SLarry Finger void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action) 1069f1d2b4d3SLarry Finger { 1070f1d2b4d3SLarry Finger u8 asso_type; 1071f1d2b4d3SLarry Finger 1072f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1073f1d2b4d3SLarry Finger return; 1074f1d2b4d3SLarry Finger btcoexist->statistics.cnt_connect_notify++; 1075f1d2b4d3SLarry Finger if (btcoexist->manual_control) 1076f1d2b4d3SLarry Finger return; 1077f1d2b4d3SLarry Finger 1078f1d2b4d3SLarry Finger if (action) 1079f1d2b4d3SLarry Finger asso_type = BTC_ASSOCIATE_START; 1080f1d2b4d3SLarry Finger else 1081f1d2b4d3SLarry Finger asso_type = BTC_ASSOCIATE_FINISH; 1082f1d2b4d3SLarry Finger 10837937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 1084f1d2b4d3SLarry Finger 10857937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 10867937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 10877937f02dSYan-Hsuan Chuang ex_btc8821a2ant_connect_notify(btcoexist, asso_type); 10887937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 10897937f02dSYan-Hsuan Chuang ex_btc8821a1ant_connect_notify(btcoexist, asso_type); 10907937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 10917937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1092f1d2b4d3SLarry Finger ex_btc8723b2ant_connect_notify(btcoexist, asso_type); 10937937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 10947937f02dSYan-Hsuan Chuang ex_btc8723b1ant_connect_notify(btcoexist, asso_type); 10957937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 10967937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 10977937f02dSYan-Hsuan Chuang ex_btc8192e2ant_connect_notify(btcoexist, asso_type); 10987937f02dSYan-Hsuan Chuang } 10997937f02dSYan-Hsuan Chuang 11007937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 1101f1d2b4d3SLarry Finger } 1102f1d2b4d3SLarry Finger 1103f1d2b4d3SLarry Finger void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist, 1104f1d2b4d3SLarry Finger enum rt_media_status media_status) 1105f1d2b4d3SLarry Finger { 1106f1d2b4d3SLarry Finger u8 status; 1107f1d2b4d3SLarry Finger 1108f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1109f1d2b4d3SLarry Finger return; 1110f1d2b4d3SLarry Finger btcoexist->statistics.cnt_media_status_notify++; 1111f1d2b4d3SLarry Finger if (btcoexist->manual_control) 1112f1d2b4d3SLarry Finger return; 1113f1d2b4d3SLarry Finger 1114f1d2b4d3SLarry Finger if (RT_MEDIA_CONNECT == media_status) 1115f1d2b4d3SLarry Finger status = BTC_MEDIA_CONNECT; 1116f1d2b4d3SLarry Finger else 1117f1d2b4d3SLarry Finger status = BTC_MEDIA_DISCONNECT; 1118f1d2b4d3SLarry Finger 11197937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 1120f1d2b4d3SLarry Finger 11217937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 11227937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 11237937f02dSYan-Hsuan Chuang ex_btc8821a2ant_media_status_notify(btcoexist, status); 11247937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 11257937f02dSYan-Hsuan Chuang ex_btc8821a1ant_media_status_notify(btcoexist, status); 11267937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 11277937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 11287937f02dSYan-Hsuan Chuang ex_btc8723b2ant_media_status_notify(btcoexist, status); 11297937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 11307937f02dSYan-Hsuan Chuang ex_btc8723b1ant_media_status_notify(btcoexist, status); 11317937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 11327937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 11337937f02dSYan-Hsuan Chuang ex_btc8192e2ant_media_status_notify(btcoexist, status); 11347937f02dSYan-Hsuan Chuang } 11357937f02dSYan-Hsuan Chuang 11367937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 1137f1d2b4d3SLarry Finger } 1138f1d2b4d3SLarry Finger 1139f1d2b4d3SLarry Finger void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type) 1140f1d2b4d3SLarry Finger { 1141f1d2b4d3SLarry Finger u8 packet_type; 1142f1d2b4d3SLarry Finger 1143f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1144f1d2b4d3SLarry Finger return; 1145f1d2b4d3SLarry Finger btcoexist->statistics.cnt_special_packet_notify++; 1146f1d2b4d3SLarry Finger if (btcoexist->manual_control) 1147f1d2b4d3SLarry Finger return; 1148f1d2b4d3SLarry Finger 11497937f02dSYan-Hsuan Chuang if (pkt_type == PACKET_DHCP) { 1150f1d2b4d3SLarry Finger packet_type = BTC_PACKET_DHCP; 11517937f02dSYan-Hsuan Chuang } else if (pkt_type == PACKET_EAPOL) { 11527937f02dSYan-Hsuan Chuang packet_type = BTC_PACKET_EAPOL; 11537937f02dSYan-Hsuan Chuang } else if (pkt_type == PACKET_ARP) { 11547937f02dSYan-Hsuan Chuang packet_type = BTC_PACKET_ARP; 11557937f02dSYan-Hsuan Chuang } else { 11567937f02dSYan-Hsuan Chuang packet_type = BTC_PACKET_UNKNOWN; 11577937f02dSYan-Hsuan Chuang return; 11587937f02dSYan-Hsuan Chuang } 1159f1d2b4d3SLarry Finger 11607937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 1161f1d2b4d3SLarry Finger 11627937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 11637937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 11647937f02dSYan-Hsuan Chuang ex_btc8821a2ant_special_packet_notify(btcoexist, 11657937f02dSYan-Hsuan Chuang packet_type); 11667937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 11677937f02dSYan-Hsuan Chuang ex_btc8821a1ant_special_packet_notify(btcoexist, 11687937f02dSYan-Hsuan Chuang packet_type); 11697937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 11707937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1171f1d2b4d3SLarry Finger ex_btc8723b2ant_special_packet_notify(btcoexist, 1172f1d2b4d3SLarry Finger packet_type); 11737937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 11747937f02dSYan-Hsuan Chuang ex_btc8723b1ant_special_packet_notify(btcoexist, 11757937f02dSYan-Hsuan Chuang packet_type); 11767937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 11777937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 11787937f02dSYan-Hsuan Chuang ex_btc8192e2ant_special_packet_notify(btcoexist, 11797937f02dSYan-Hsuan Chuang packet_type); 11807937f02dSYan-Hsuan Chuang } 1181f1d2b4d3SLarry Finger 11827937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 1183f1d2b4d3SLarry Finger } 1184f1d2b4d3SLarry Finger 1185f1d2b4d3SLarry Finger void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist, 1186f1d2b4d3SLarry Finger u8 *tmp_buf, u8 length) 1187f1d2b4d3SLarry Finger { 1188f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1189f1d2b4d3SLarry Finger return; 1190f1d2b4d3SLarry Finger btcoexist->statistics.cnt_bt_info_notify++; 1191f1d2b4d3SLarry Finger 11927937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 11937937f02dSYan-Hsuan Chuang 11947937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 11957937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 11967937f02dSYan-Hsuan Chuang ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf, 11977937f02dSYan-Hsuan Chuang length); 11987937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 11997937f02dSYan-Hsuan Chuang ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf, 12007937f02dSYan-Hsuan Chuang length); 12017937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 12027937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 12037937f02dSYan-Hsuan Chuang ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf, 12047937f02dSYan-Hsuan Chuang length); 12057937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 12067937f02dSYan-Hsuan Chuang ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf, 12077937f02dSYan-Hsuan Chuang length); 12087937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 12097937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 12107937f02dSYan-Hsuan Chuang ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf, 12117937f02dSYan-Hsuan Chuang length); 12127937f02dSYan-Hsuan Chuang } 12137937f02dSYan-Hsuan Chuang 12147937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 12157937f02dSYan-Hsuan Chuang } 12167937f02dSYan-Hsuan Chuang 12177937f02dSYan-Hsuan Chuang void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type) 12187937f02dSYan-Hsuan Chuang { 12197937f02dSYan-Hsuan Chuang if (!halbtc_is_bt_coexist_available(btcoexist)) 12207937f02dSYan-Hsuan Chuang return; 12217937f02dSYan-Hsuan Chuang 12227937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 12237937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 12247937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 1) 12257937f02dSYan-Hsuan Chuang ex_btc8723b1ant_rf_status_notify(btcoexist, type); 12267937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 12277937f02dSYan-Hsuan Chuang } 1228f1d2b4d3SLarry Finger } 1229f1d2b4d3SLarry Finger 1230f1d2b4d3SLarry Finger void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type) 1231f1d2b4d3SLarry Finger { 1232f1d2b4d3SLarry Finger u8 stack_op_type; 1233f1d2b4d3SLarry Finger 1234f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1235f1d2b4d3SLarry Finger return; 1236f1d2b4d3SLarry Finger btcoexist->statistics.cnt_stack_operation_notify++; 1237f1d2b4d3SLarry Finger if (btcoexist->manual_control) 1238f1d2b4d3SLarry Finger return; 1239f1d2b4d3SLarry Finger 12407937f02dSYan-Hsuan Chuang if ((type == HCI_BT_OP_INQUIRY_START) || 12417937f02dSYan-Hsuan Chuang (type == HCI_BT_OP_PAGING_START) || 12427937f02dSYan-Hsuan Chuang (type == HCI_BT_OP_PAIRING_START)) { 12437937f02dSYan-Hsuan Chuang stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START; 12447937f02dSYan-Hsuan Chuang } else if ((type == HCI_BT_OP_INQUIRY_FINISH) || 12457937f02dSYan-Hsuan Chuang (type == HCI_BT_OP_PAGING_SUCCESS) || 12467937f02dSYan-Hsuan Chuang (type == HCI_BT_OP_PAGING_UNSUCCESS) || 12477937f02dSYan-Hsuan Chuang (type == HCI_BT_OP_PAIRING_FINISH)) { 12487937f02dSYan-Hsuan Chuang stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH; 12497937f02dSYan-Hsuan Chuang } else { 1250f1d2b4d3SLarry Finger stack_op_type = BTC_STACK_OP_NONE; 12517937f02dSYan-Hsuan Chuang } 1252f1d2b4d3SLarry Finger } 1253f1d2b4d3SLarry Finger 1254f1d2b4d3SLarry Finger void exhalbtc_halt_notify(struct btc_coexist *btcoexist) 1255f1d2b4d3SLarry Finger { 1256f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1257f1d2b4d3SLarry Finger return; 1258f1d2b4d3SLarry Finger 12597937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 12607937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 12617937f02dSYan-Hsuan Chuang ex_btc8821a2ant_halt_notify(btcoexist); 12627937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 12637937f02dSYan-Hsuan Chuang ex_btc8821a1ant_halt_notify(btcoexist); 12647937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 12657937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1266f1d2b4d3SLarry Finger ex_btc8723b2ant_halt_notify(btcoexist); 12677937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 12687937f02dSYan-Hsuan Chuang ex_btc8723b1ant_halt_notify(btcoexist); 12697937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 12707937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 12717937f02dSYan-Hsuan Chuang ex_btc8192e2ant_halt_notify(btcoexist); 12727937f02dSYan-Hsuan Chuang } 12737937f02dSYan-Hsuan Chuang 12747937f02dSYan-Hsuan Chuang btcoexist->binded = false; 1275f1d2b4d3SLarry Finger } 1276f1d2b4d3SLarry Finger 1277f1d2b4d3SLarry Finger void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state) 1278f1d2b4d3SLarry Finger { 1279f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1280f1d2b4d3SLarry Finger return; 128186f9ab2eSYan-Hsuan Chuang 128286f9ab2eSYan-Hsuan Chuang /* currently only 1ant we have to do the notification, 128386f9ab2eSYan-Hsuan Chuang * once pnp is notified to sleep state, we have to leave LPS that 128486f9ab2eSYan-Hsuan Chuang * we can sleep normally. 128586f9ab2eSYan-Hsuan Chuang */ 128686f9ab2eSYan-Hsuan Chuang 128786f9ab2eSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 128886f9ab2eSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 1) 128986f9ab2eSYan-Hsuan Chuang ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state); 129086f9ab2eSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 2) 129186f9ab2eSYan-Hsuan Chuang ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state); 129286f9ab2eSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 129386f9ab2eSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 1) 129486f9ab2eSYan-Hsuan Chuang ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state); 129586f9ab2eSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 2) 129686f9ab2eSYan-Hsuan Chuang ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state); 129786f9ab2eSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 129886f9ab2eSYan-Hsuan Chuang } 1299f1d2b4d3SLarry Finger } 1300f1d2b4d3SLarry Finger 13017937f02dSYan-Hsuan Chuang void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist) 1302f1d2b4d3SLarry Finger { 1303f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = btcoexist->adapter; 13047937f02dSYan-Hsuan Chuang 13057937f02dSYan-Hsuan Chuang if (!halbtc_is_bt_coexist_available(btcoexist)) 13067937f02dSYan-Hsuan Chuang return; 13077937f02dSYan-Hsuan Chuang btcoexist->statistics.cnt_coex_dm_switch++; 13087937f02dSYan-Hsuan Chuang 13097937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 13107937f02dSYan-Hsuan Chuang 13117937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 13127937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 1) { 13137937f02dSYan-Hsuan Chuang btcoexist->stop_coex_dm = true; 13147937f02dSYan-Hsuan Chuang ex_btc8723b1ant_coex_dm_reset(btcoexist); 13157937f02dSYan-Hsuan Chuang exhalbtc_set_ant_num(rtlpriv, 13167937f02dSYan-Hsuan Chuang BT_COEX_ANT_TYPE_DETECTED, 2); 13177937f02dSYan-Hsuan Chuang ex_btc8723b2ant_init_hwconfig(btcoexist); 13187937f02dSYan-Hsuan Chuang ex_btc8723b2ant_init_coex_dm(btcoexist); 13197937f02dSYan-Hsuan Chuang btcoexist->stop_coex_dm = false; 13207937f02dSYan-Hsuan Chuang } 13217937f02dSYan-Hsuan Chuang } 13227937f02dSYan-Hsuan Chuang 13237937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 13247937f02dSYan-Hsuan Chuang } 13257937f02dSYan-Hsuan Chuang 13267937f02dSYan-Hsuan Chuang void exhalbtc_periodical(struct btc_coexist *btcoexist) 13277937f02dSYan-Hsuan Chuang { 1328f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1329f1d2b4d3SLarry Finger return; 1330f1d2b4d3SLarry Finger btcoexist->statistics.cnt_periodical++; 1331f1d2b4d3SLarry Finger 13327937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 1333f1d2b4d3SLarry Finger 13347937f02dSYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 13357937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 13367937f02dSYan-Hsuan Chuang ex_btc8821a2ant_periodical(btcoexist); 13377937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 13387937f02dSYan-Hsuan Chuang if (!halbtc_under_ips(btcoexist)) 13397937f02dSYan-Hsuan Chuang ex_btc8821a1ant_periodical(btcoexist); 13407937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 13417937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1342f1d2b4d3SLarry Finger ex_btc8723b2ant_periodical(btcoexist); 13437937f02dSYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 13447937f02dSYan-Hsuan Chuang ex_btc8723b1ant_periodical(btcoexist); 13457937f02dSYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 13467937f02dSYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 13477937f02dSYan-Hsuan Chuang ex_btc8192e2ant_periodical(btcoexist); 13487937f02dSYan-Hsuan Chuang } 1349f1d2b4d3SLarry Finger 13507937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 1351f1d2b4d3SLarry Finger } 1352f1d2b4d3SLarry Finger 1353f1d2b4d3SLarry Finger void exhalbtc_dbg_control(struct btc_coexist *btcoexist, 1354f1d2b4d3SLarry Finger u8 code, u8 len, u8 *data) 1355f1d2b4d3SLarry Finger { 1356f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1357f1d2b4d3SLarry Finger return; 1358f1d2b4d3SLarry Finger btcoexist->statistics.cnt_dbg_ctrl++; 13597937f02dSYan-Hsuan Chuang 13607937f02dSYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 13617937f02dSYan-Hsuan Chuang 13627937f02dSYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 13637937f02dSYan-Hsuan Chuang } 13647937f02dSYan-Hsuan Chuang 13657937f02dSYan-Hsuan Chuang void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq, 13667937f02dSYan-Hsuan Chuang u32 offset, u32 span, u32 seconds) 13677937f02dSYan-Hsuan Chuang { 13687937f02dSYan-Hsuan Chuang if (!halbtc_is_bt_coexist_available(btcoexist)) 13697937f02dSYan-Hsuan Chuang return; 1370f1d2b4d3SLarry Finger } 1371f1d2b4d3SLarry Finger 1372f1d2b4d3SLarry Finger void exhalbtc_stack_update_profile_info(void) 1373f1d2b4d3SLarry Finger { 1374f1d2b4d3SLarry Finger } 1375f1d2b4d3SLarry Finger 137608aba42fSArnd Bergmann void exhalbtc_update_min_bt_rssi(s8 bt_rssi) 1377f1d2b4d3SLarry Finger { 1378f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = &gl_bt_coexist; 1379f1d2b4d3SLarry Finger 1380f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1381f1d2b4d3SLarry Finger return; 1382f1d2b4d3SLarry Finger 1383f1d2b4d3SLarry Finger btcoexist->stack_info.min_bt_rssi = bt_rssi; 1384f1d2b4d3SLarry Finger } 1385f1d2b4d3SLarry Finger 1386f1d2b4d3SLarry Finger void exhalbtc_set_hci_version(u16 hci_version) 1387f1d2b4d3SLarry Finger { 1388f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = &gl_bt_coexist; 1389f1d2b4d3SLarry Finger 1390f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1391f1d2b4d3SLarry Finger return; 1392f1d2b4d3SLarry Finger 1393f1d2b4d3SLarry Finger btcoexist->stack_info.hci_version = hci_version; 1394f1d2b4d3SLarry Finger } 1395f1d2b4d3SLarry Finger 1396f1d2b4d3SLarry Finger void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version) 1397f1d2b4d3SLarry Finger { 1398f1d2b4d3SLarry Finger struct btc_coexist *btcoexist = &gl_bt_coexist; 1399f1d2b4d3SLarry Finger 1400f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1401f1d2b4d3SLarry Finger return; 1402f1d2b4d3SLarry Finger 1403f1d2b4d3SLarry Finger btcoexist->bt_info.bt_real_fw_ver = bt_patch_version; 1404f1d2b4d3SLarry Finger btcoexist->bt_info.bt_hci_ver = bt_hci_version; 1405f1d2b4d3SLarry Finger } 1406f1d2b4d3SLarry Finger 1407f1d2b4d3SLarry Finger void exhalbtc_set_chip_type(u8 chip_type) 1408f1d2b4d3SLarry Finger { 1409f1d2b4d3SLarry Finger switch (chip_type) { 1410f1d2b4d3SLarry Finger default: 1411f1d2b4d3SLarry Finger case BT_2WIRE: 1412f1d2b4d3SLarry Finger case BT_ISSC_3WIRE: 1413f1d2b4d3SLarry Finger case BT_ACCEL: 1414f1d2b4d3SLarry Finger case BT_RTL8756: 1415f1d2b4d3SLarry Finger gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF; 1416f1d2b4d3SLarry Finger break; 1417f1d2b4d3SLarry Finger case BT_CSR_BC4: 1418f1d2b4d3SLarry Finger gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4; 1419f1d2b4d3SLarry Finger break; 1420f1d2b4d3SLarry Finger case BT_CSR_BC8: 1421f1d2b4d3SLarry Finger gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8; 1422f1d2b4d3SLarry Finger break; 1423f1d2b4d3SLarry Finger case BT_RTL8723A: 1424f1d2b4d3SLarry Finger gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A; 1425f1d2b4d3SLarry Finger break; 1426f1d2b4d3SLarry Finger case BT_RTL8821A: 1427f1d2b4d3SLarry Finger gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821; 1428f1d2b4d3SLarry Finger break; 1429f1d2b4d3SLarry Finger case BT_RTL8723B: 1430f1d2b4d3SLarry Finger gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B; 1431f1d2b4d3SLarry Finger break; 1432f1d2b4d3SLarry Finger } 1433f1d2b4d3SLarry Finger } 1434f1d2b4d3SLarry Finger 1435baa17022SLarry Finger void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num) 1436f1d2b4d3SLarry Finger { 1437f1d2b4d3SLarry Finger if (BT_COEX_ANT_TYPE_PG == type) { 1438f1d2b4d3SLarry Finger gl_bt_coexist.board_info.pg_ant_num = ant_num; 1439f1d2b4d3SLarry Finger gl_bt_coexist.board_info.btdm_ant_num = ant_num; 1440f1d2b4d3SLarry Finger } else if (BT_COEX_ANT_TYPE_ANTDIV == type) { 1441f1d2b4d3SLarry Finger gl_bt_coexist.board_info.btdm_ant_num = ant_num; 1442baa17022SLarry Finger } else if (type == BT_COEX_ANT_TYPE_DETECTED) { 1443baa17022SLarry Finger gl_bt_coexist.board_info.btdm_ant_num = ant_num; 1444baa17022SLarry Finger if (rtlpriv->cfg->mod_params->ant_sel == 1) 1445baa17022SLarry Finger gl_bt_coexist.board_info.btdm_ant_pos = 1446baa17022SLarry Finger BTC_ANTENNA_AT_AUX_PORT; 1447baa17022SLarry Finger else 1448baa17022SLarry Finger gl_bt_coexist.board_info.btdm_ant_pos = 1449baa17022SLarry Finger BTC_ANTENNA_AT_MAIN_PORT; 1450f1d2b4d3SLarry Finger } 1451f1d2b4d3SLarry Finger } 1452f1d2b4d3SLarry Finger 14530199103eSYan-Hsuan Chuang /* Currently used by 8723b only, S0 or S1 */ 14540199103eSYan-Hsuan Chuang void exhalbtc_set_single_ant_path(u8 single_ant_path) 14550199103eSYan-Hsuan Chuang { 14560199103eSYan-Hsuan Chuang gl_bt_coexist.board_info.single_ant_path = single_ant_path; 14570199103eSYan-Hsuan Chuang } 14580199103eSYan-Hsuan Chuang 1459f1d2b4d3SLarry Finger void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist) 1460f1d2b4d3SLarry Finger { 1461f1d2b4d3SLarry Finger if (!halbtc_is_bt_coexist_available(btcoexist)) 1462f1d2b4d3SLarry Finger return; 1463f1d2b4d3SLarry Finger 1464c42ea613SYan-Hsuan Chuang halbtc_leave_low_power(btcoexist); 1465c42ea613SYan-Hsuan Chuang 1466c42ea613SYan-Hsuan Chuang if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) { 1467c42ea613SYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1468c42ea613SYan-Hsuan Chuang ex_btc8821a2ant_display_coex_info(btcoexist); 1469c42ea613SYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 1470c42ea613SYan-Hsuan Chuang ex_btc8821a1ant_display_coex_info(btcoexist); 1471c42ea613SYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) { 1472c42ea613SYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1473f1d2b4d3SLarry Finger ex_btc8723b2ant_display_coex_info(btcoexist); 1474c42ea613SYan-Hsuan Chuang else if (btcoexist->board_info.btdm_ant_num == 1) 1475c42ea613SYan-Hsuan Chuang ex_btc8723b1ant_display_coex_info(btcoexist); 1476c42ea613SYan-Hsuan Chuang } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) { 1477c42ea613SYan-Hsuan Chuang if (btcoexist->board_info.btdm_ant_num == 2) 1478c42ea613SYan-Hsuan Chuang ex_btc8192e2ant_display_coex_info(btcoexist); 1479c42ea613SYan-Hsuan Chuang } 1480c42ea613SYan-Hsuan Chuang 1481c42ea613SYan-Hsuan Chuang halbtc_normal_low_power(btcoexist); 1482f1d2b4d3SLarry Finger } 1483