linux/drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtcoutsrc.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright(c) 2007-2013  Realtek Corporation.*/
   3
   4#include "halbt_precomp.h"
   5
   6/***************************************************
   7 *              Debug related function
   8 ***************************************************/
   9
  10static const char *const gl_btc_wifi_bw_string[] = {
  11        "11bg",
  12        "HT20",
  13        "HT40",
  14        "HT80",
  15        "HT160"
  16};
  17
  18static const char *const gl_btc_wifi_freq_string[] = {
  19        "2.4G",
  20        "5G"
  21};
  22
  23static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
  24{
  25        if (!btcoexist->binded || NULL == btcoexist->adapter)
  26                return false;
  27
  28        return true;
  29}
  30
  31static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
  32{
  33        if (rtlpriv->link_info.busytraffic)
  34                return true;
  35        else
  36                return false;
  37}
  38
  39static void halbtc_dbg_init(void)
  40{
  41}
  42
  43/***************************************************
  44 *              helper function
  45 ***************************************************/
  46static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
  47{
  48        struct rtl_priv *rtlpriv = btcoexist->adapter;
  49        struct rtl_mac *mac = rtl_mac(rtlpriv);
  50        struct rtl_sta_info *drv_priv;
  51        u8 cnt = 0;
  52
  53        if (mac->opmode == NL80211_IFTYPE_ADHOC ||
  54            mac->opmode == NL80211_IFTYPE_MESH_POINT ||
  55            mac->opmode == NL80211_IFTYPE_AP) {
  56                if (in_interrupt() > 0) {
  57                        list_for_each_entry(drv_priv, &rtlpriv->entry_list,
  58                                            list) {
  59                                cnt++;
  60                        }
  61                } else {
  62                        spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  63                        list_for_each_entry(drv_priv, &rtlpriv->entry_list,
  64                                            list) {
  65                                cnt++;
  66                        }
  67                        spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  68                }
  69        }
  70        if (cnt > 0)
  71                return true;
  72        else
  73                return false;
  74}
  75
  76static bool halbtc_legacy(struct rtl_priv *adapter)
  77{
  78        struct rtl_priv *rtlpriv = adapter;
  79        struct rtl_mac *mac = rtl_mac(rtlpriv);
  80
  81        bool is_legacy = false;
  82
  83        if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
  84                is_legacy = true;
  85
  86        return is_legacy;
  87}
  88
  89bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
  90{
  91        struct rtl_priv *rtlpriv = adapter;
  92
  93        if (rtlpriv->link_info.tx_busy_traffic)
  94                return true;
  95        else
  96                return false;
  97}
  98
  99static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
 100{
 101        struct rtl_priv *rtlpriv = btcoexist->adapter;
 102        struct rtl_phy *rtlphy = &rtlpriv->phy;
 103        u32 wifi_bw = BTC_WIFI_BW_HT20;
 104
 105        if (halbtc_legacy(rtlpriv)) {
 106                wifi_bw = BTC_WIFI_BW_LEGACY;
 107        } else {
 108                switch (rtlphy->current_chan_bw) {
 109                case HT_CHANNEL_WIDTH_20:
 110                        wifi_bw = BTC_WIFI_BW_HT20;
 111                        break;
 112                case HT_CHANNEL_WIDTH_20_40:
 113                        wifi_bw = BTC_WIFI_BW_HT40;
 114                        break;
 115                case HT_CHANNEL_WIDTH_80:
 116                        wifi_bw = BTC_WIFI_BW_HT80;
 117                        break;
 118                }
 119        }
 120
 121        return wifi_bw;
 122}
 123
 124static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
 125{
 126        struct rtl_priv *rtlpriv = btcoexist->adapter;
 127        struct rtl_phy  *rtlphy = &(rtlpriv->phy);
 128        u8 chnl = 1;
 129
 130        if (rtlphy->current_channel != 0)
 131                chnl = rtlphy->current_channel;
 132        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
 133                 "static halbtc_get_wifi_central_chnl:%d\n", chnl);
 134        return chnl;
 135}
 136
 137static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
 138{
 139        return rtlpriv->btcoexist.btc_info.single_ant_path;
 140}
 141
 142static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
 143{
 144        return rtlpriv->btcoexist.btc_info.bt_type;
 145}
 146
 147static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
 148{
 149        u8 num;
 150
 151        if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
 152                num = 2;
 153        else
 154                num = 1;
 155
 156        return num;
 157}
 158
 159static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
 160{
 161        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 162
 163        return rtlhal->package_type;
 164}
 165
 166static
 167u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
 168{
 169        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 170
 171        return rtlhal->rfe_type;
 172}
 173
 174static
 175bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
 176{
 177        if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
 178                return false;
 179        else
 180                return true;
 181}
 182
 183static
 184bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
 185                                 u8 *cmd, u32 len, unsigned long wait_ms)
 186{
 187        struct rtl_priv *rtlpriv;
 188        const u8 oper_ver = 0;
 189        u8 req_num;
 190
 191        if (!halbtc_is_hw_mailbox_exist(btcoexist))
 192                return false;
 193
 194        if (wait_ms)    /* before h2c to avoid race condition */
 195                reinit_completion(&btcoexist->bt_mp_comp);
 196
 197        rtlpriv = btcoexist->adapter;
 198
 199        /* fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
 200         * to know message type
 201         */
 202        switch (op_code) {
 203        case BT_OP_GET_BT_VERSION:
 204                req_num = BT_SEQ_GET_BT_VERSION;
 205                break;
 206        case BT_OP_GET_AFH_MAP_L:
 207                req_num = BT_SEQ_GET_AFH_MAP_L;
 208                break;
 209        case BT_OP_GET_AFH_MAP_M:
 210                req_num = BT_SEQ_GET_AFH_MAP_M;
 211                break;
 212        case BT_OP_GET_AFH_MAP_H:
 213                req_num = BT_SEQ_GET_AFH_MAP_H;
 214                break;
 215        case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
 216                req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
 217                break;
 218        case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
 219                req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
 220                break;
 221        case BT_OP_GET_BT_ANT_DET_VAL:
 222                req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
 223                break;
 224        case BT_OP_GET_BT_BLE_SCAN_PARA:
 225                req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
 226                break;
 227        case BT_OP_GET_BT_BLE_SCAN_TYPE:
 228                req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
 229                break;
 230        case BT_OP_GET_BT_DEVICE_INFO:
 231                req_num = BT_SEQ_GET_BT_DEVICE_INFO;
 232                break;
 233        case BT_OP_GET_BT_FORBIDDEN_SLOT_VAL:
 234                req_num = BT_SEQ_GET_BT_FORB_SLOT_VAL;
 235                break;
 236        case BT_OP_WRITE_REG_ADDR:
 237        case BT_OP_WRITE_REG_VALUE:
 238        case BT_OP_READ_REG:
 239        default:
 240                req_num = BT_SEQ_DONT_CARE;
 241                break;
 242        }
 243
 244        cmd[0] |= (oper_ver & 0x0f);            /* Set OperVer */
 245        cmd[0] |= ((req_num << 4) & 0xf0);      /* Set ReqNum */
 246        cmd[1] = op_code;
 247        rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
 248
 249        /* wait? */
 250        if (!wait_ms)
 251                return true;
 252
 253        RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
 254                 "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
 255
 256        if (in_interrupt())
 257                return false;
 258
 259        if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
 260                                        msecs_to_jiffies(wait_ms)) == 0) {
 261                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
 262                         "btmpinfo wait (req_num=%d) timeout\n", req_num);
 263
 264                return false;   /* timeout */
 265        }
 266
 267        return true;
 268}
 269
 270static void halbtc_leave_lps(struct btc_coexist *btcoexist)
 271{
 272        struct rtl_priv *rtlpriv;
 273        bool ap_enable = false;
 274
 275        rtlpriv = btcoexist->adapter;
 276
 277        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
 278                           &ap_enable);
 279
 280        if (ap_enable) {
 281                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
 282                         "%s()<--dont leave lps under AP mode\n", __func__);
 283                return;
 284        }
 285
 286        btcoexist->bt_info.bt_ctrl_lps = true;
 287        btcoexist->bt_info.bt_lps_on = false;
 288        rtl_lps_leave(rtlpriv->mac80211.hw);
 289}
 290
 291static void halbtc_enter_lps(struct btc_coexist *btcoexist)
 292{
 293        struct rtl_priv *rtlpriv;
 294        bool ap_enable = false;
 295
 296        rtlpriv = btcoexist->adapter;
 297
 298        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
 299                           &ap_enable);
 300
 301        if (ap_enable) {
 302                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
 303                         "%s()<--dont enter lps under AP mode\n", __func__);
 304                return;
 305        }
 306
 307        btcoexist->bt_info.bt_ctrl_lps = true;
 308        btcoexist->bt_info.bt_lps_on = true;
 309        rtl_lps_enter(rtlpriv->mac80211.hw);
 310}
 311
 312static void halbtc_normal_lps(struct btc_coexist *btcoexist)
 313{
 314        struct rtl_priv *rtlpriv;
 315
 316        rtlpriv = btcoexist->adapter;
 317
 318        if (btcoexist->bt_info.bt_ctrl_lps) {
 319                btcoexist->bt_info.bt_lps_on = false;
 320                rtl_lps_leave(rtlpriv->mac80211.hw);
 321                btcoexist->bt_info.bt_ctrl_lps = false;
 322        }
 323}
 324
 325static void halbtc_pre_normal_lps(struct btc_coexist *btcoexist)
 326{
 327        struct rtl_priv *rtlpriv = btcoexist->adapter;
 328
 329        if (btcoexist->bt_info.bt_ctrl_lps) {
 330                btcoexist->bt_info.bt_lps_on = false;
 331                rtl_lps_leave(rtlpriv->mac80211.hw);
 332        }
 333}
 334
 335static void halbtc_post_normal_lps(struct btc_coexist *btcoexist)
 336{
 337        if (btcoexist->bt_info.bt_ctrl_lps)
 338                btcoexist->bt_info.bt_ctrl_lps = false;
 339}
 340
 341static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
 342{
 343}
 344
 345static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
 346{
 347}
 348
 349static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
 350                                     bool low_pwr_disable)
 351{
 352        /* TODO: original/leave 32k low power */
 353        btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
 354}
 355
 356static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
 357{
 358        bool need_to_act = false;
 359        static unsigned long pre_time;
 360        unsigned long cur_time = 0;
 361        struct rtl_priv *rtlpriv = btcoexist->adapter;
 362
 363        /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
 364         * This function is not allowed to continuous called
 365         * It can only be called after 8 seconds
 366         */
 367
 368        cur_time = jiffies;
 369        if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
 370                /* over 8 seconds you can execute this function again. */
 371                return;
 372        }
 373        pre_time = cur_time;
 374
 375        if (btcoexist->bt_info.reject_agg_pkt) {
 376                need_to_act = true;
 377                btcoexist->bt_info.pre_reject_agg_pkt =
 378                        btcoexist->bt_info.reject_agg_pkt;
 379        } else {
 380                if (btcoexist->bt_info.pre_reject_agg_pkt) {
 381                        need_to_act = true;
 382                        btcoexist->bt_info.pre_reject_agg_pkt =
 383                                btcoexist->bt_info.reject_agg_pkt;
 384                }
 385
 386                if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
 387                    btcoexist->bt_info.bt_ctrl_agg_buf_size) {
 388                        need_to_act = true;
 389                        btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
 390                                btcoexist->bt_info.bt_ctrl_agg_buf_size;
 391                }
 392
 393                if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
 394                        if (btcoexist->bt_info.pre_agg_buf_size !=
 395                            btcoexist->bt_info.agg_buf_size) {
 396                                need_to_act = true;
 397                        }
 398                        btcoexist->bt_info.pre_agg_buf_size =
 399                                btcoexist->bt_info.agg_buf_size;
 400                }
 401
 402                if (need_to_act)
 403                        rtl_rx_ampdu_apply(rtlpriv);
 404        }
 405}
 406
 407static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
 408{
 409        u8 cmd_buffer[4] = {0};
 410
 411        if (btcoexist->bt_info.bt_real_fw_ver)
 412                goto label_done;
 413
 414        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
 415        halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
 416                                    cmd_buffer, 4, 200);
 417
 418label_done:
 419        return btcoexist->bt_info.bt_real_fw_ver;
 420}
 421
 422static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
 423{
 424        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
 425        u8 cmd_buffer[4] = {0};
 426
 427        if (btcoexist->bt_info.bt_supported_feature)
 428                goto label_done;
 429
 430        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
 431        halbtc_send_bt_mp_operation(btcoexist,
 432                                    BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
 433                                    cmd_buffer, 4, 200);
 434
 435label_done:
 436        return btcoexist->bt_info.bt_supported_feature;
 437}
 438
 439static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
 440{
 441        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
 442        u8 cmd_buffer[4] = {0};
 443
 444        if (btcoexist->bt_info.bt_supported_version)
 445                goto label_done;
 446
 447        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
 448        halbtc_send_bt_mp_operation(btcoexist,
 449                                    BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
 450                                    cmd_buffer, 4, 200);
 451
 452label_done:
 453        return btcoexist->bt_info.bt_supported_version;
 454}
 455
 456static u32 halbtc_get_bt_device_info(void *btc_context)
 457{
 458        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
 459        u8 cmd_buffer[4] = {0};
 460
 461        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
 462        halbtc_send_bt_mp_operation(btcoexist,
 463                                    BT_OP_GET_BT_DEVICE_INFO,
 464                                    cmd_buffer, 4, 200);
 465
 466        return btcoexist->bt_info.bt_device_info;
 467}
 468
 469static u32 halbtc_get_bt_forbidden_slot_val(void *btc_context)
 470{
 471        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
 472        u8 cmd_buffer[4] = {0};
 473
 474        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
 475        halbtc_send_bt_mp_operation(btcoexist,
 476                                    BT_OP_GET_BT_FORBIDDEN_SLOT_VAL,
 477                                    cmd_buffer, 4, 200);
 478
 479        return btcoexist->bt_info.bt_forb_slot_val;
 480}
 481
 482static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
 483{
 484        /* return value:
 485         * [31:16] => connected port number
 486         * [15:0]  => port connected bit define
 487         */
 488        struct rtl_priv *rtlpriv = btcoexist->adapter;
 489        struct rtl_mac *mac = rtl_mac(rtlpriv);
 490        u32 ret_val = 0;
 491        u32 port_connected_status = 0, num_of_connected_port = 0;
 492
 493        if (mac->opmode == NL80211_IFTYPE_STATION &&
 494            mac->link_state >= MAC80211_LINKED) {
 495                port_connected_status |= WIFI_STA_CONNECTED;
 496                num_of_connected_port++;
 497        }
 498        /* AP & ADHOC & MESH */
 499        if (is_any_client_connect_to_ap(btcoexist)) {
 500                port_connected_status |= WIFI_AP_CONNECTED;
 501                num_of_connected_port++;
 502        }
 503        /* TODO: P2P Connected Status */
 504
 505        ret_val = (num_of_connected_port << 16) | port_connected_status;
 506
 507        return ret_val;
 508}
 509
 510static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
 511{
 512        int undec_sm_pwdb = 0;
 513
 514        if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
 515                undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
 516        else /* associated entry pwdb */
 517                undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
 518        return undec_sm_pwdb;
 519}
 520
 521static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
 522{
 523        struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
 524        struct rtl_priv *rtlpriv = btcoexist->adapter;
 525        struct rtl_phy *rtlphy = &(rtlpriv->phy);
 526        struct rtl_mac *mac = rtl_mac(rtlpriv);
 527        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 528        bool *bool_tmp = (bool *)out_buf;
 529        int *s32_tmp = (int *)out_buf;
 530        u32 *u32_tmp = (u32 *)out_buf;
 531        u8 *u8_tmp = (u8 *)out_buf;
 532        bool tmp = false;
 533        bool ret = true;
 534
 535        if (!halbtc_is_bt_coexist_available(btcoexist))
 536                return false;
 537
 538        switch (get_type) {
 539        case BTC_GET_BL_HS_OPERATION:
 540                *bool_tmp = false;
 541                ret = false;
 542                break;
 543        case BTC_GET_BL_HS_CONNECTING:
 544                *bool_tmp = false;
 545                ret = false;
 546                break;
 547        case BTC_GET_BL_WIFI_CONNECTED:
 548                if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
 549                    rtlpriv->mac80211.link_state >= MAC80211_LINKED)
 550                        tmp = true;
 551                if (is_any_client_connect_to_ap(btcoexist))
 552                        tmp = true;
 553                *bool_tmp = tmp;
 554                break;
 555        case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
 556                *u8_tmp = BTC_MULTIPORT_SCC;
 557                break;
 558        case BTC_GET_BL_WIFI_BUSY:
 559                if (halbtc_is_wifi_busy(rtlpriv))
 560                        *bool_tmp = true;
 561                else
 562                        *bool_tmp = false;
 563                break;
 564        case BTC_GET_BL_WIFI_SCAN:
 565                if (mac->act_scanning)
 566                        *bool_tmp = true;
 567                else
 568                        *bool_tmp = false;
 569                break;
 570        case BTC_GET_BL_WIFI_LINK:
 571                if (mac->link_state == MAC80211_LINKING)
 572                        *bool_tmp = true;
 573                else
 574                        *bool_tmp = false;
 575                break;
 576        case BTC_GET_BL_WIFI_ROAM:
 577                if (mac->link_state == MAC80211_LINKING)
 578                        *bool_tmp = true;
 579                else
 580                        *bool_tmp = false;
 581                break;
 582        case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
 583                *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
 584                break;
 585        case BTC_GET_BL_WIFI_UNDER_5G:
 586                if (rtlhal->current_bandtype == BAND_ON_5G)
 587                        *bool_tmp = true;
 588                else
 589                        *bool_tmp = false;
 590                break;
 591        case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
 592                if (mac->opmode == NL80211_IFTYPE_AP)
 593                        *bool_tmp = true;
 594                else
 595                        *bool_tmp = false;
 596                break;
 597        case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
 598                if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
 599                        *bool_tmp = false;
 600                else
 601                        *bool_tmp = true;
 602                break;
 603        case BTC_GET_BL_WIFI_UNDER_B_MODE:
 604                if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
 605                        *bool_tmp = true;
 606                else
 607                        *bool_tmp = false;
 608                break;
 609        case BTC_GET_BL_EXT_SWITCH:
 610                *bool_tmp = false;
 611                break;
 612        case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
 613                *bool_tmp = false;
 614                break;
 615        case BTC_GET_BL_IS_ASUS_8723B:
 616                *bool_tmp = false;
 617                break;
 618        case BTC_GET_BL_RF4CE_CONNECTED:
 619                *bool_tmp = false;
 620                break;
 621        case BTC_GET_S4_WIFI_RSSI:
 622                *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
 623                break;
 624        case BTC_GET_S4_HS_RSSI:
 625                *s32_tmp = 0;
 626                ret = false;
 627                break;
 628        case BTC_GET_U4_WIFI_BW:
 629                *u32_tmp = halbtc_get_wifi_bw(btcoexist);
 630                break;
 631        case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
 632                if (halbtc_is_wifi_uplink(rtlpriv))
 633                        *u32_tmp = BTC_WIFI_TRAFFIC_TX;
 634                else
 635                        *u32_tmp = BTC_WIFI_TRAFFIC_RX;
 636                break;
 637        case BTC_GET_U4_WIFI_FW_VER:
 638                *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
 639                break;
 640        case BTC_GET_U4_WIFI_LINK_STATUS:
 641                *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
 642                break;
 643        case BTC_GET_U4_BT_PATCH_VER:
 644                *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
 645                break;
 646        case BTC_GET_U4_VENDOR:
 647                *u32_tmp = BTC_VENDOR_OTHER;
 648                break;
 649        case BTC_GET_U4_SUPPORTED_VERSION:
 650                *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
 651                break;
 652        case BTC_GET_U4_SUPPORTED_FEATURE:
 653                *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
 654                break;
 655        case BTC_GET_U4_BT_DEVICE_INFO:
 656                *u32_tmp = halbtc_get_bt_device_info(btcoexist);
 657                break;
 658        case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
 659                *u32_tmp = halbtc_get_bt_forbidden_slot_val(btcoexist);
 660                break;
 661        case BTC_GET_U4_WIFI_IQK_TOTAL:
 662                *u32_tmp =
 663                        btcoexist->btc_phydm_query_phy_counter(btcoexist,
 664                                                               DM_INFO_IQK_ALL);
 665                break;
 666        case BTC_GET_U4_WIFI_IQK_OK:
 667                *u32_tmp =
 668                        btcoexist->btc_phydm_query_phy_counter(btcoexist,
 669                                                               DM_INFO_IQK_OK);
 670                break;
 671        case BTC_GET_U4_WIFI_IQK_FAIL:
 672                *u32_tmp =
 673                        btcoexist->btc_phydm_query_phy_counter(btcoexist,
 674                                                               DM_INFO_IQK_NG);
 675                break;
 676        case BTC_GET_U1_WIFI_DOT11_CHNL:
 677                *u8_tmp = rtlphy->current_channel;
 678                break;
 679        case BTC_GET_U1_WIFI_CENTRAL_CHNL:
 680                *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
 681                break;
 682        case BTC_GET_U1_WIFI_HS_CHNL:
 683                *u8_tmp = 0;
 684                ret = false;
 685                break;
 686        case BTC_GET_U1_AP_NUM:
 687                *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
 688                break;
 689        case BTC_GET_U1_ANT_TYPE:
 690                *u8_tmp = (u8)BTC_ANT_TYPE_0;
 691                break;
 692        case BTC_GET_U1_IOT_PEER:
 693                *u8_tmp = 0;
 694                break;
 695
 696                /************* 1Ant **************/
 697        case BTC_GET_U1_LPS_MODE:
 698                *u8_tmp = btcoexist->pwr_mode_val[0];
 699                break;
 700
 701        default:
 702                ret = false;
 703                break;
 704        }
 705
 706        return ret;
 707}
 708
 709static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
 710{
 711        struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
 712        bool *bool_tmp = (bool *)in_buf;
 713        u8 *u8_tmp = (u8 *)in_buf;
 714        u32 *u32_tmp = (u32 *)in_buf;
 715        bool ret = true;
 716
 717        if (!halbtc_is_bt_coexist_available(btcoexist))
 718                return false;
 719
 720        switch (set_type) {
 721        /* set some bool type variables. */
 722        case BTC_SET_BL_BT_DISABLE:
 723                btcoexist->bt_info.bt_disabled = *bool_tmp;
 724                break;
 725        case BTC_SET_BL_BT_TRAFFIC_BUSY:
 726                btcoexist->bt_info.bt_busy = *bool_tmp;
 727                break;
 728        case BTC_SET_BL_BT_LIMITED_DIG:
 729                btcoexist->bt_info.limited_dig = *bool_tmp;
 730                break;
 731        case BTC_SET_BL_FORCE_TO_ROAM:
 732                btcoexist->bt_info.force_to_roam = *bool_tmp;
 733                break;
 734        case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
 735                btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
 736                break;
 737        case BTC_SET_BL_BT_CTRL_AGG_SIZE:
 738                btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
 739                break;
 740        case BTC_SET_BL_INC_SCAN_DEV_NUM:
 741                btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
 742                break;
 743        case BTC_SET_BL_BT_TX_RX_MASK:
 744                btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
 745                break;
 746        case BTC_SET_BL_MIRACAST_PLUS_BT:
 747                btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
 748                break;
 749                /* set some u1Byte type variables. */
 750        case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
 751                btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
 752                break;
 753        case BTC_SET_U1_AGG_BUF_SIZE:
 754                btcoexist->bt_info.agg_buf_size = *u8_tmp;
 755                break;
 756
 757        /* the following are some action which will be triggered */
 758        case BTC_SET_ACT_GET_BT_RSSI:
 759                ret = false;
 760                break;
 761        case BTC_SET_ACT_AGGREGATE_CTRL:
 762                halbtc_aggregation_check(btcoexist);
 763                break;
 764
 765        /* 1Ant */
 766        case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
 767                btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
 768                break;
 769        case BTC_SET_UI_SCAN_SIG_COMPENSATION:
 770                break;
 771        case BTC_SET_U1_LPS_VAL:
 772                btcoexist->bt_info.lps_val = *u8_tmp;
 773                break;
 774        case BTC_SET_U1_RPWM_VAL:
 775                btcoexist->bt_info.rpwm_val = *u8_tmp;
 776                break;
 777        /* the following are some action which will be triggered  */
 778        case BTC_SET_ACT_LEAVE_LPS:
 779                halbtc_leave_lps(btcoexist);
 780                break;
 781        case BTC_SET_ACT_ENTER_LPS:
 782                halbtc_enter_lps(btcoexist);
 783                break;
 784        case BTC_SET_ACT_NORMAL_LPS:
 785                halbtc_normal_lps(btcoexist);
 786                break;
 787        case BTC_SET_ACT_PRE_NORMAL_LPS:
 788                halbtc_pre_normal_lps(btcoexist);
 789                break;
 790        case BTC_SET_ACT_POST_NORMAL_LPS:
 791                halbtc_post_normal_lps(btcoexist);
 792                break;
 793        case BTC_SET_ACT_DISABLE_LOW_POWER:
 794                halbtc_disable_low_power(btcoexist, *bool_tmp);
 795                break;
 796        case BTC_SET_ACT_UPDATE_RAMASK:
 797                btcoexist->bt_info.ra_mask = *u32_tmp;
 798                break;
 799        case BTC_SET_ACT_SEND_MIMO_PS:
 800                break;
 801        case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
 802                break;
 803        case BTC_SET_ACT_CTRL_BT_COEX:
 804                break;
 805        case BTC_SET_ACT_CTRL_8723B_ANT:
 806                break;
 807        default:
 808                break;
 809        }
 810
 811        return ret;
 812}
 813
 814static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
 815                                           struct seq_file *m)
 816{
 817}
 818
 819static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
 820                                        struct seq_file *m)
 821{
 822}
 823
 824static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
 825                                       struct seq_file *m)
 826{
 827        struct rtl_priv *rtlpriv = btcoexist->adapter;
 828        s32 wifi_rssi = 0, bt_hs_rssi = 0;
 829        bool scan = false, link = false, roam = false, wifi_busy = false;
 830        bool wifi_under_b_mode = false;
 831        bool wifi_under_5g = false;
 832        u32 wifi_bw = BTC_WIFI_BW_HT20;
 833        u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
 834        u32 wifi_freq = BTC_FREQ_2_4G;
 835        u32 wifi_link_status = 0x0;
 836        bool bt_hs_on = false, under_ips = false, under_lps = false;
 837        bool low_power = false, dc_mode = false;
 838        u8 wifi_chnl = 0, wifi_hs_chnl = 0;
 839        u8 ap_num = 0;
 840
 841        wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
 842        seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
 843                   "STA/vWifi/HS/p2pGo/p2pGc",
 844                   ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
 845                   ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
 846                   ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
 847                   ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
 848                   ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
 849
 850        btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
 851        btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
 852        btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
 853        seq_printf(m, "\n %-35s = %d / %d(%d)",
 854                   "Dot11 channel / HsChnl(High Speed)",
 855                   wifi_chnl, wifi_hs_chnl, bt_hs_on);
 856
 857        btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
 858        btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
 859        seq_printf(m, "\n %-35s = %d/ %d",
 860                   "Wifi rssi/ HS rssi",
 861                   wifi_rssi - 100, bt_hs_rssi - 100);
 862
 863        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
 864        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
 865        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
 866        seq_printf(m, "\n %-35s = %d/ %d/ %d ",
 867                   "Wifi link/ roam/ scan",
 868                   link, roam, scan);
 869
 870        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
 871        btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
 872        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
 873        btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
 874                           &wifi_traffic_dir);
 875        btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
 876        wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
 877        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
 878                           &wifi_under_b_mode);
 879
 880        seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
 881                   "Wifi freq/ bw/ traffic",
 882                   gl_btc_wifi_freq_string[wifi_freq],
 883                   ((wifi_under_b_mode) ? "11b" :
 884                    gl_btc_wifi_bw_string[wifi_bw]),
 885                   ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
 886                                              wifi_traffic_dir) ? "uplink" :
 887                                             "downlink")),
 888                   ap_num);
 889
 890        /* power status  */
 891        dc_mode = true; /*TODO*/
 892        under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
 893        under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
 894        low_power = 0; /*TODO*/
 895        seq_printf(m, "\n %-35s = %s%s%s%s",
 896                   "Power Status",
 897                   (dc_mode ? "DC mode" : "AC mode"),
 898                   (under_ips ? ", IPS ON" : ""),
 899                   (under_lps ? ", LPS ON" : ""),
 900                   (low_power ? ", 32k" : ""));
 901
 902        seq_printf(m,
 903                   "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
 904                   "Power mode cmd(lps/rpwm)",
 905                   btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
 906                   btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
 907                   btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
 908                   btcoexist->bt_info.lps_val,
 909                   btcoexist->bt_info.rpwm_val);
 910}
 911
 912/************************************************************
 913 *              IO related function
 914 ************************************************************/
 915static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
 916{
 917        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 918        struct rtl_priv *rtlpriv = btcoexist->adapter;
 919
 920        return  rtl_read_byte(rtlpriv, reg_addr);
 921}
 922
 923static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
 924{
 925        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 926        struct rtl_priv *rtlpriv = btcoexist->adapter;
 927
 928        return  rtl_read_word(rtlpriv, reg_addr);
 929}
 930
 931static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
 932{
 933        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 934        struct rtl_priv *rtlpriv = btcoexist->adapter;
 935
 936        return  rtl_read_dword(rtlpriv, reg_addr);
 937}
 938
 939static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
 940{
 941        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 942        struct rtl_priv *rtlpriv = btcoexist->adapter;
 943
 944        rtl_write_byte(rtlpriv, reg_addr, data);
 945}
 946
 947static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
 948                                       u32 bit_mask, u8 data)
 949{
 950        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 951        struct rtl_priv *rtlpriv = btcoexist->adapter;
 952        u8 original_value, bit_shift = 0;
 953        u8 i;
 954
 955        if (bit_mask != MASKDWORD) {/*if not "double word" write*/
 956                original_value = rtl_read_byte(rtlpriv, reg_addr);
 957                for (i = 0; i <= 7; i++) {
 958                        if ((bit_mask>>i) & 0x1)
 959                                break;
 960                }
 961                bit_shift = i;
 962                data = (original_value & (~bit_mask)) |
 963                        ((data << bit_shift) & bit_mask);
 964        }
 965        rtl_write_byte(rtlpriv, reg_addr, data);
 966}
 967
 968static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
 969{
 970        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 971        struct rtl_priv *rtlpriv = btcoexist->adapter;
 972
 973        rtl_write_word(rtlpriv, reg_addr, data);
 974}
 975
 976static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
 977{
 978        struct btc_coexist *btcoexist =
 979                (struct btc_coexist *)bt_context;
 980        struct rtl_priv *rtlpriv = btcoexist->adapter;
 981
 982        rtl_write_dword(rtlpriv, reg_addr, data);
 983}
 984
 985static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
 986                                         u8 data)
 987{
 988        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
 989        struct rtl_priv *rtlpriv = btcoexist->adapter;
 990
 991        if (btcoexist->chip_interface == BTC_INTF_SDIO)
 992                ;
 993        else if (btcoexist->chip_interface == BTC_INTF_PCI)
 994                rtl_write_byte(rtlpriv, reg_addr, data);
 995        else if (btcoexist->chip_interface == BTC_INTF_USB)
 996                rtl_write_byte(rtlpriv, reg_addr, data);
 997}
 998
 999static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
1000                             u32 data)
1001{
1002        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1003        struct rtl_priv *rtlpriv = btcoexist->adapter;
1004
1005        rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
1006}
1007
1008static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
1009{
1010        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1011        struct rtl_priv *rtlpriv = btcoexist->adapter;
1012
1013        return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
1014}
1015
1016static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
1017                             u32 bit_mask, u32 data)
1018{
1019        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1020        struct rtl_priv *rtlpriv = btcoexist->adapter;
1021
1022        rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
1023}
1024
1025static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
1026                            u32 bit_mask)
1027{
1028        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1029        struct rtl_priv *rtlpriv = btcoexist->adapter;
1030
1031        return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
1032}
1033
1034static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
1035                                u32 cmd_len, u8 *cmd_buf)
1036{
1037        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1038        struct rtl_priv *rtlpriv = btcoexist->adapter;
1039
1040        rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
1041                                        cmd_len, cmd_buf);
1042}
1043
1044void halbtc_send_wifi_port_id_cmd(void *bt_context)
1045{
1046        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1047        struct rtl_priv *rtlpriv = btcoexist->adapter;
1048        u8 cmd_buf[1] = {0};    /* port id [2:0] = 0 */
1049
1050        rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, H2C_BT_PORT_ID,
1051                                        1, cmd_buf);
1052}
1053
1054void halbtc_set_default_port_id_cmd(void *bt_context)
1055{
1056        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1057        struct rtl_priv *rtlpriv = btcoexist->adapter;
1058        struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1059
1060        if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1061                return;
1062
1063        rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1064}
1065
1066static
1067void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1068{
1069        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1070        u8 cmd_buffer1[4] = {0};
1071        u8 cmd_buffer2[4] = {0};
1072
1073        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1074        *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1075        if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1076                                         cmd_buffer1, 4, 200))
1077                return;
1078
1079        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1080        cmd_buffer2[2] = reg_type;
1081        *((u8 *)&cmd_buffer2[3]) = (u8)offset;
1082        halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1083                                    cmd_buffer2, 4, 200);
1084}
1085
1086static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1087                                   struct seq_file *m)
1088{
1089        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1090
1091        switch (disp_type) {
1092        case BTC_DBG_DISP_COEX_STATISTICS:
1093                halbtc_display_coex_statistics(btcoexist, m);
1094                break;
1095        case BTC_DBG_DISP_BT_LINK_INFO:
1096                halbtc_display_bt_link_info(btcoexist, m);
1097                break;
1098        case BTC_DBG_DISP_WIFI_STATUS:
1099                halbtc_display_wifi_status(btcoexist, m);
1100                break;
1101        default:
1102                break;
1103        }
1104}
1105
1106static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1107{
1108        return 0;
1109}
1110
1111static bool halbtc_under_ips(struct btc_coexist *btcoexist)
1112{
1113        struct rtl_priv *rtlpriv = btcoexist->adapter;
1114        struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
1115        enum rf_pwrstate rtstate;
1116
1117        if (ppsc->inactiveps) {
1118                rtstate = ppsc->rfpwr_state;
1119
1120                if (rtstate != ERFON &&
1121                    ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
1122                        return true;
1123                }
1124        }
1125
1126        return false;
1127}
1128
1129static
1130u32 halbtc_get_phydm_version(void *btc_context)
1131{
1132        return 0;
1133}
1134
1135static
1136void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1137                                          u8 ra_offset_direction,
1138                                          u8 ra_threshold_offset)
1139{
1140}
1141
1142static
1143u32 halbtc_phydm_query_phy_counter(void *btc_context, enum dm_info_query dm_id)
1144{
1145        return 0;
1146}
1147
1148static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1149{
1150        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1151        u8 cmd_buffer[4] = {0};
1152
1153        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1154        halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1155                                    cmd_buffer, 4, 200);
1156
1157        /* need wait completion to return correct value */
1158
1159        return btcoexist->bt_info.bt_ant_det_val;
1160}
1161
1162static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1163{
1164        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1165        u8 cmd_buffer[4] = {0};
1166
1167        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1168        halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1169                                    cmd_buffer, 4, 200);
1170
1171        /* need wait completion to return correct value */
1172
1173        return btcoexist->bt_info.bt_ble_scan_type;
1174}
1175
1176static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1177{
1178        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1179        u8 cmd_buffer[4] = {0};
1180
1181        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1182        halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1183                                    cmd_buffer, 4, 200);
1184
1185        /* need wait completion to return correct value */
1186
1187        return btcoexist->bt_info.bt_ble_scan_para;
1188}
1189
1190static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1191                                          u8 *afh_map)
1192{
1193        struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1194        u8 cmd_buffer[2] = {0};
1195        bool ret;
1196        u32 *afh_map_l = (u32 *)afh_map;
1197        u32 *afh_map_m = (u32 *)(afh_map + 4);
1198        u16 *afh_map_h = (u16 *)(afh_map + 8);
1199
1200        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1201        ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1202                                          cmd_buffer, 2, 200);
1203        if (!ret)
1204                goto exit;
1205
1206        *afh_map_l = btcoexist->bt_info.afh_map_l;
1207
1208        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1209        ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1210                                          cmd_buffer, 2, 200);
1211        if (!ret)
1212                goto exit;
1213
1214        *afh_map_m = btcoexist->bt_info.afh_map_m;
1215
1216        /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1217        ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1218                                          cmd_buffer, 2, 200);
1219        if (!ret)
1220                goto exit;
1221
1222        *afh_map_h = btcoexist->bt_info.afh_map_h;
1223
1224exit:
1225        return ret;
1226}
1227
1228/*****************************************************************
1229 *         Extern functions called by other module
1230 *****************************************************************/
1231bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1232{
1233        struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1234
1235        if (!btcoexist)
1236                return false;
1237
1238        halbtc_dbg_init();
1239
1240        btcoexist->btc_read_1byte = halbtc_read_1byte;
1241        btcoexist->btc_write_1byte = halbtc_write_1byte;
1242        btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1243        btcoexist->btc_read_2byte = halbtc_read_2byte;
1244        btcoexist->btc_write_2byte = halbtc_write_2byte;
1245        btcoexist->btc_read_4byte = halbtc_read_4byte;
1246        btcoexist->btc_write_4byte = halbtc_write_4byte;
1247        btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1248
1249        btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1250        btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1251
1252        btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1253        btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1254
1255        btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1256        btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1257
1258        btcoexist->btc_get = halbtc_get;
1259        btcoexist->btc_set = halbtc_set;
1260        btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1261        btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1262
1263        btcoexist->bt_info.bt_ctrl_buf_size = false;
1264        btcoexist->bt_info.agg_buf_size = 5;
1265
1266        btcoexist->bt_info.increase_scan_dev_num = false;
1267
1268        btcoexist->btc_get_bt_coex_supported_feature =
1269                                        halbtc_get_bt_coex_supported_feature;
1270        btcoexist->btc_get_bt_coex_supported_version =
1271                                        halbtc_get_bt_coex_supported_version;
1272        btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1273        btcoexist->btc_phydm_modify_ra_pcr_threshold =
1274                                        halbtc_phydm_modify_ra_pcr_threshold;
1275        btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1276        btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1277        btcoexist->btc_get_ble_scan_type_from_bt =
1278                                        halbtc_get_ble_scan_type_from_bt;
1279        btcoexist->btc_get_ble_scan_para_from_bt =
1280                                        halbtc_get_ble_scan_para_from_bt;
1281        btcoexist->btc_get_bt_afh_map_from_bt =
1282                                        halbtc_get_bt_afh_map_from_bt;
1283
1284        init_completion(&btcoexist->bt_mp_comp);
1285
1286        return true;
1287}
1288
1289bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1290{
1291        struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1292        struct wifi_only_haldata *wifionly_haldata;
1293
1294        if (!wifionly_cfg)
1295                return false;
1296
1297        wifionly_cfg->adapter = rtlpriv;
1298
1299        switch (rtlpriv->rtlhal.interface) {
1300        case INTF_PCI:
1301                wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
1302                break;
1303        case INTF_USB:
1304                wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
1305                break;
1306        default:
1307                wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
1308                break;
1309        }
1310
1311        wifionly_haldata = &wifionly_cfg->haldata_info;
1312
1313        wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1314        wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1315        wifionly_haldata->efuse_pg_antpath =
1316                                        rtl_get_hwpg_single_ant_path(rtlpriv);
1317        wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1318        wifionly_haldata->ant_div_cfg = 0;
1319
1320        return true;
1321}
1322
1323bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1324{
1325        struct rtl_priv *rtlpriv = adapter;
1326        struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1327        u8 ant_num = 2, chip_type, single_ant_path = 0;
1328
1329        if (!btcoexist)
1330                return false;
1331
1332        if (btcoexist->binded)
1333                return false;
1334
1335        switch (rtlpriv->rtlhal.interface) {
1336        case INTF_PCI:
1337                btcoexist->chip_interface = BTC_INTF_PCI;
1338                break;
1339        case INTF_USB:
1340                btcoexist->chip_interface = BTC_INTF_USB;
1341                break;
1342        default:
1343                btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1344                break;
1345        }
1346
1347        btcoexist->binded = true;
1348        btcoexist->statistics.cnt_bind++;
1349
1350        btcoexist->adapter = adapter;
1351
1352        btcoexist->stack_info.profile_notified = false;
1353
1354        btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1355        btcoexist->bt_info.agg_buf_size = 5;
1356
1357        btcoexist->bt_info.increase_scan_dev_num = false;
1358        btcoexist->bt_info.miracast_plus_bt = false;
1359
1360        chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1361        exhalbtc_set_chip_type(btcoexist, chip_type);
1362        ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1363        exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1364
1365        /* set default antenna position to main  port */
1366        btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1367
1368        single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1369        exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1370
1371        if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1372                btcoexist->board_info.tfbga_package = false;
1373        else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1374                btcoexist->board_info.tfbga_package = false;
1375        else
1376                btcoexist->board_info.tfbga_package = true;
1377
1378        if (btcoexist->board_info.tfbga_package)
1379                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1380                         "[BTCoex], Package Type = TFBGA\n");
1381        else
1382                RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1383                         "[BTCoex], Package Type = Non-TFBGA\n");
1384
1385        btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1386        btcoexist->board_info.ant_div_cfg = 0;
1387
1388        return true;
1389}
1390
1391void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1392{
1393        if (!halbtc_is_bt_coexist_available(btcoexist))
1394                return;
1395
1396        btcoexist->statistics.cnt_power_on++;
1397
1398        if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1399                if (btcoexist->board_info.btdm_ant_num == 2)
1400                        ex_btc8723b2ant_power_on_setting(btcoexist);
1401                else if (btcoexist->board_info.btdm_ant_num == 1)
1402                        ex_btc8723b1ant_power_on_setting(btcoexist);
1403        }
1404}
1405
1406void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1407{
1408        if (!halbtc_is_bt_coexist_available(btcoexist))
1409                return;
1410
1411        btcoexist->statistics.cnt_pre_load_firmware++;
1412
1413        if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1414                if (btcoexist->board_info.btdm_ant_num == 2)
1415                        ex_btc8723b2ant_pre_load_firmware(btcoexist);
1416        }
1417}
1418
1419void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1420{
1421        if (!halbtc_is_bt_coexist_available(btcoexist))
1422                return;
1423
1424        btcoexist->statistics.cnt_init_hw_config++;
1425
1426        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1427                if (btcoexist->board_info.btdm_ant_num == 2)
1428                        ex_btc8821a2ant_init_hwconfig(btcoexist);
1429                else if (btcoexist->board_info.btdm_ant_num == 1)
1430                        ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
1431        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1432                if (btcoexist->board_info.btdm_ant_num == 2)
1433                        ex_btc8723b2ant_init_hwconfig(btcoexist);
1434                else if (btcoexist->board_info.btdm_ant_num == 1)
1435                        ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
1436        } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
1437                /* 8723A has no this function */
1438        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1439                if (btcoexist->board_info.btdm_ant_num == 2)
1440                        ex_btc8192e2ant_init_hwconfig(btcoexist);
1441        }
1442}
1443
1444void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1445{
1446}
1447
1448void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1449{
1450        if (!halbtc_is_bt_coexist_available(btcoexist))
1451                return;
1452
1453        btcoexist->statistics.cnt_init_coex_dm++;
1454
1455        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1456                if (btcoexist->board_info.btdm_ant_num == 2)
1457                        ex_btc8821a2ant_init_coex_dm(btcoexist);
1458                else if (btcoexist->board_info.btdm_ant_num == 1)
1459                        ex_btc8821a1ant_init_coex_dm(btcoexist);
1460        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1461                if (btcoexist->board_info.btdm_ant_num == 2)
1462                        ex_btc8723b2ant_init_coex_dm(btcoexist);
1463                else if (btcoexist->board_info.btdm_ant_num == 1)
1464                        ex_btc8723b1ant_init_coex_dm(btcoexist);
1465        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1466                if (btcoexist->board_info.btdm_ant_num == 2)
1467                        ex_btc8192e2ant_init_coex_dm(btcoexist);
1468        }
1469
1470        btcoexist->initilized = true;
1471}
1472
1473void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1474{
1475        u8 ips_type;
1476
1477        if (!halbtc_is_bt_coexist_available(btcoexist))
1478                return;
1479        btcoexist->statistics.cnt_ips_notify++;
1480        if (btcoexist->manual_control)
1481                return;
1482
1483        if (ERFOFF == type)
1484                ips_type = BTC_IPS_ENTER;
1485        else
1486                ips_type = BTC_IPS_LEAVE;
1487
1488        halbtc_leave_low_power(btcoexist);
1489
1490        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1491                if (btcoexist->board_info.btdm_ant_num == 2)
1492                        ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
1493                else if (btcoexist->board_info.btdm_ant_num == 1)
1494                        ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
1495        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1496                if (btcoexist->board_info.btdm_ant_num == 2)
1497                        ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
1498                else if (btcoexist->board_info.btdm_ant_num == 1)
1499                        ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
1500        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1501                if (btcoexist->board_info.btdm_ant_num == 2)
1502                        ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
1503        }
1504
1505        halbtc_normal_low_power(btcoexist);
1506}
1507
1508void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1509{
1510        u8 lps_type;
1511
1512        if (!halbtc_is_bt_coexist_available(btcoexist))
1513                return;
1514        btcoexist->statistics.cnt_lps_notify++;
1515        if (btcoexist->manual_control)
1516                return;
1517
1518        if (EACTIVE == type)
1519                lps_type = BTC_LPS_DISABLE;
1520        else
1521                lps_type = BTC_LPS_ENABLE;
1522
1523        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1524                if (btcoexist->board_info.btdm_ant_num == 2)
1525                        ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
1526                else if (btcoexist->board_info.btdm_ant_num == 1)
1527                        ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
1528        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1529                if (btcoexist->board_info.btdm_ant_num == 2)
1530                        ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
1531                else if (btcoexist->board_info.btdm_ant_num == 1)
1532                        ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
1533        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1534                if (btcoexist->board_info.btdm_ant_num == 2)
1535                        ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
1536        }
1537}
1538
1539void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1540{
1541        u8 scan_type;
1542
1543        if (!halbtc_is_bt_coexist_available(btcoexist))
1544                return;
1545        btcoexist->statistics.cnt_scan_notify++;
1546        if (btcoexist->manual_control)
1547                return;
1548
1549        if (type)
1550                scan_type = BTC_SCAN_START;
1551        else
1552                scan_type = BTC_SCAN_FINISH;
1553
1554        halbtc_leave_low_power(btcoexist);
1555
1556        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1557                if (btcoexist->board_info.btdm_ant_num == 2)
1558                        ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
1559                else if (btcoexist->board_info.btdm_ant_num == 1)
1560                        ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
1561        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1562                if (btcoexist->board_info.btdm_ant_num == 2)
1563                        ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
1564                else if (btcoexist->board_info.btdm_ant_num == 1)
1565                        ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
1566        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1567                if (btcoexist->board_info.btdm_ant_num == 2)
1568                        ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
1569        }
1570
1571        halbtc_normal_low_power(btcoexist);
1572}
1573
1574void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1575                                    u8 is_5g)
1576{
1577}
1578
1579void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1580{
1581        u8 asso_type;
1582        bool wifi_under_5g;
1583
1584        if (!halbtc_is_bt_coexist_available(btcoexist))
1585                return;
1586        btcoexist->statistics.cnt_connect_notify++;
1587        if (btcoexist->manual_control)
1588                return;
1589
1590        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1591
1592        if (action)
1593                asso_type = BTC_ASSOCIATE_START;
1594        else
1595                asso_type = BTC_ASSOCIATE_FINISH;
1596
1597        halbtc_leave_low_power(btcoexist);
1598
1599        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1600                if (btcoexist->board_info.btdm_ant_num == 2)
1601                        ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
1602                else if (btcoexist->board_info.btdm_ant_num == 1)
1603                        ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
1604        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1605                if (btcoexist->board_info.btdm_ant_num == 2)
1606                        ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
1607                else if (btcoexist->board_info.btdm_ant_num == 1)
1608                        ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
1609        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1610                if (btcoexist->board_info.btdm_ant_num == 2)
1611                        ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
1612        }
1613
1614        halbtc_normal_low_power(btcoexist);
1615}
1616
1617void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1618                                 enum rt_media_status media_status)
1619{
1620        u8 status;
1621
1622        if (!halbtc_is_bt_coexist_available(btcoexist))
1623                return;
1624        btcoexist->statistics.cnt_media_status_notify++;
1625        if (btcoexist->manual_control)
1626                return;
1627
1628        if (RT_MEDIA_CONNECT == media_status)
1629                status = BTC_MEDIA_CONNECT;
1630        else
1631                status = BTC_MEDIA_DISCONNECT;
1632
1633        halbtc_leave_low_power(btcoexist);
1634
1635        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1636                if (btcoexist->board_info.btdm_ant_num == 2)
1637                        ex_btc8821a2ant_media_status_notify(btcoexist, status);
1638                else if (btcoexist->board_info.btdm_ant_num == 1)
1639                        ex_btc8821a1ant_media_status_notify(btcoexist, status);
1640        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1641                if (btcoexist->board_info.btdm_ant_num == 2)
1642                        ex_btc8723b2ant_media_status_notify(btcoexist, status);
1643                else if (btcoexist->board_info.btdm_ant_num == 1)
1644                        ex_btc8723b1ant_media_status_notify(btcoexist, status);
1645        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1646                if (btcoexist->board_info.btdm_ant_num == 2)
1647                        ex_btc8192e2ant_media_status_notify(btcoexist, status);
1648        }
1649
1650        halbtc_normal_low_power(btcoexist);
1651}
1652
1653void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1654{
1655        u8 packet_type;
1656
1657        if (!halbtc_is_bt_coexist_available(btcoexist))
1658                return;
1659        btcoexist->statistics.cnt_special_packet_notify++;
1660        if (btcoexist->manual_control)
1661                return;
1662
1663        if (pkt_type == PACKET_DHCP) {
1664                packet_type = BTC_PACKET_DHCP;
1665        } else if (pkt_type == PACKET_EAPOL) {
1666                packet_type = BTC_PACKET_EAPOL;
1667        } else if (pkt_type == PACKET_ARP) {
1668                packet_type = BTC_PACKET_ARP;
1669        } else {
1670                packet_type = BTC_PACKET_UNKNOWN;
1671                return;
1672        }
1673
1674        halbtc_leave_low_power(btcoexist);
1675
1676        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1677                if (btcoexist->board_info.btdm_ant_num == 2)
1678                        ex_btc8821a2ant_special_packet_notify(btcoexist,
1679                                                              packet_type);
1680                else if (btcoexist->board_info.btdm_ant_num == 1)
1681                        ex_btc8821a1ant_special_packet_notify(btcoexist,
1682                                                              packet_type);
1683        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1684                if (btcoexist->board_info.btdm_ant_num == 2)
1685                        ex_btc8723b2ant_special_packet_notify(btcoexist,
1686                                                              packet_type);
1687                else if (btcoexist->board_info.btdm_ant_num == 1)
1688                        ex_btc8723b1ant_special_packet_notify(btcoexist,
1689                                                              packet_type);
1690        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1691                if (btcoexist->board_info.btdm_ant_num == 2)
1692                        ex_btc8192e2ant_special_packet_notify(btcoexist,
1693                                                              packet_type);
1694        }
1695
1696        halbtc_normal_low_power(btcoexist);
1697}
1698
1699void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1700                             u8 *tmp_buf, u8 length)
1701{
1702        if (!halbtc_is_bt_coexist_available(btcoexist))
1703                return;
1704        btcoexist->statistics.cnt_bt_info_notify++;
1705
1706        halbtc_leave_low_power(btcoexist);
1707
1708        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1709                if (btcoexist->board_info.btdm_ant_num == 2)
1710                        ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
1711                                                       length);
1712                else if (btcoexist->board_info.btdm_ant_num == 1)
1713                        ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
1714                                                       length);
1715        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1716                if (btcoexist->board_info.btdm_ant_num == 2)
1717                        ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
1718                                                       length);
1719                else if (btcoexist->board_info.btdm_ant_num == 1)
1720                        ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
1721                                                       length);
1722        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1723                if (btcoexist->board_info.btdm_ant_num == 2)
1724                        ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
1725                                                       length);
1726        }
1727
1728        halbtc_normal_low_power(btcoexist);
1729}
1730
1731void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1732{
1733        if (!halbtc_is_bt_coexist_available(btcoexist))
1734                return;
1735
1736        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1737        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1738                if (btcoexist->board_info.btdm_ant_num == 1)
1739                        ex_btc8723b1ant_rf_status_notify(btcoexist, type);
1740        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1741        }
1742}
1743
1744void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1745{
1746        if (!halbtc_is_bt_coexist_available(btcoexist))
1747                return;
1748
1749        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1750                if (btcoexist->board_info.btdm_ant_num == 2)
1751                        ex_btc8821a2ant_halt_notify(btcoexist);
1752                else if (btcoexist->board_info.btdm_ant_num == 1)
1753                        ex_btc8821a1ant_halt_notify(btcoexist);
1754        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1755                if (btcoexist->board_info.btdm_ant_num == 2)
1756                        ex_btc8723b2ant_halt_notify(btcoexist);
1757                else if (btcoexist->board_info.btdm_ant_num == 1)
1758                        ex_btc8723b1ant_halt_notify(btcoexist);
1759        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1760                if (btcoexist->board_info.btdm_ant_num == 2)
1761                        ex_btc8192e2ant_halt_notify(btcoexist);
1762        }
1763
1764        btcoexist->binded = false;
1765}
1766
1767void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1768{
1769        if (!halbtc_is_bt_coexist_available(btcoexist))
1770                return;
1771
1772        /* currently only 1ant we have to do the notification,
1773         * once pnp is notified to sleep state, we have to leave LPS that
1774         * we can sleep normally.
1775         */
1776
1777        if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1778                if (btcoexist->board_info.btdm_ant_num == 1)
1779                        ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
1780                else if (btcoexist->board_info.btdm_ant_num == 2)
1781                        ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
1782        } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1783                if (btcoexist->board_info.btdm_ant_num == 1)
1784                        ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
1785                else if (btcoexist->board_info.btdm_ant_num == 2)
1786                        ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
1787        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1788        }
1789}
1790
1791void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1792{
1793        struct rtl_priv *rtlpriv = btcoexist->adapter;
1794
1795        if (!halbtc_is_bt_coexist_available(btcoexist))
1796                return;
1797        btcoexist->statistics.cnt_coex_dm_switch++;
1798
1799        halbtc_leave_low_power(btcoexist);
1800
1801        if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1802                if (btcoexist->board_info.btdm_ant_num == 1) {
1803                        btcoexist->stop_coex_dm = true;
1804                        ex_btc8723b1ant_coex_dm_reset(btcoexist);
1805                        exhalbtc_set_ant_num(rtlpriv,
1806                                             BT_COEX_ANT_TYPE_DETECTED, 2);
1807                        ex_btc8723b2ant_init_hwconfig(btcoexist);
1808                        ex_btc8723b2ant_init_coex_dm(btcoexist);
1809                        btcoexist->stop_coex_dm = false;
1810                }
1811        }
1812
1813        halbtc_normal_low_power(btcoexist);
1814}
1815
1816void exhalbtc_periodical(struct btc_coexist *btcoexist)
1817{
1818        if (!halbtc_is_bt_coexist_available(btcoexist))
1819                return;
1820        btcoexist->statistics.cnt_periodical++;
1821
1822        halbtc_leave_low_power(btcoexist);
1823
1824        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1825                if (btcoexist->board_info.btdm_ant_num == 2)
1826                        ex_btc8821a2ant_periodical(btcoexist);
1827                else if (btcoexist->board_info.btdm_ant_num == 1)
1828                        if (!halbtc_under_ips(btcoexist))
1829                                ex_btc8821a1ant_periodical(btcoexist);
1830        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1831                if (btcoexist->board_info.btdm_ant_num == 2)
1832                        ex_btc8723b2ant_periodical(btcoexist);
1833                else if (btcoexist->board_info.btdm_ant_num == 1)
1834                        ex_btc8723b1ant_periodical(btcoexist);
1835        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1836                if (btcoexist->board_info.btdm_ant_num == 2)
1837                        ex_btc8192e2ant_periodical(btcoexist);
1838        }
1839
1840        halbtc_normal_low_power(btcoexist);
1841}
1842
1843void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1844                          u8 code, u8 len, u8 *data)
1845{
1846        if (!halbtc_is_bt_coexist_available(btcoexist))
1847                return;
1848        btcoexist->statistics.cnt_dbg_ctrl++;
1849
1850        halbtc_leave_low_power(btcoexist);
1851
1852        halbtc_normal_low_power(btcoexist);
1853}
1854
1855void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1856                                u32 offset, u32 span, u32 seconds)
1857{
1858        if (!halbtc_is_bt_coexist_available(btcoexist))
1859                return;
1860}
1861
1862void exhalbtc_stack_update_profile_info(void)
1863{
1864}
1865
1866void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1867{
1868        if (!halbtc_is_bt_coexist_available(btcoexist))
1869                return;
1870
1871        btcoexist->stack_info.min_bt_rssi = bt_rssi;
1872}
1873
1874void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1875{
1876        if (!halbtc_is_bt_coexist_available(btcoexist))
1877                return;
1878
1879        btcoexist->stack_info.hci_version = hci_version;
1880}
1881
1882void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1883                                   u16 bt_hci_version, u16 bt_patch_version)
1884{
1885        if (!halbtc_is_bt_coexist_available(btcoexist))
1886                return;
1887
1888        btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1889        btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1890}
1891
1892void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1893{
1894        switch (chip_type) {
1895        default:
1896        case BT_2WIRE:
1897        case BT_ISSC_3WIRE:
1898        case BT_ACCEL:
1899        case BT_RTL8756:
1900                btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1901                break;
1902        case BT_CSR_BC4:
1903                btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1904                break;
1905        case BT_CSR_BC8:
1906                btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1907                break;
1908        case BT_RTL8723A:
1909                btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1910                break;
1911        case BT_RTL8821A:
1912                btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1913                break;
1914        case BT_RTL8723B:
1915                btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1916                break;
1917        }
1918}
1919
1920void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1921{
1922        struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1923
1924        if (!btcoexist)
1925                return;
1926
1927        if (BT_COEX_ANT_TYPE_PG == type) {
1928                btcoexist->board_info.pg_ant_num = ant_num;
1929                btcoexist->board_info.btdm_ant_num = ant_num;
1930        } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1931                btcoexist->board_info.btdm_ant_num = ant_num;
1932        } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1933                btcoexist->board_info.btdm_ant_num = ant_num;
1934                if (rtlpriv->cfg->mod_params->ant_sel == 1)
1935                        btcoexist->board_info.btdm_ant_pos =
1936                                BTC_ANTENNA_AT_AUX_PORT;
1937                else
1938                        btcoexist->board_info.btdm_ant_pos =
1939                                BTC_ANTENNA_AT_MAIN_PORT;
1940        }
1941}
1942
1943/* Currently used by 8723b only, S0 or S1 */
1944void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1945                                  u8 single_ant_path)
1946{
1947        btcoexist->board_info.single_ant_path = single_ant_path;
1948}
1949
1950void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1951                                   struct seq_file *m)
1952{
1953        if (!halbtc_is_bt_coexist_available(btcoexist))
1954                return;
1955
1956        halbtc_leave_low_power(btcoexist);
1957
1958        if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1959                if (btcoexist->board_info.btdm_ant_num == 2)
1960                        ex_btc8821a2ant_display_coex_info(btcoexist, m);
1961                else if (btcoexist->board_info.btdm_ant_num == 1)
1962                        ex_btc8821a1ant_display_coex_info(btcoexist, m);
1963        } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1964                if (btcoexist->board_info.btdm_ant_num == 2)
1965                        ex_btc8723b2ant_display_coex_info(btcoexist, m);
1966                else if (btcoexist->board_info.btdm_ant_num == 1)
1967                        ex_btc8723b1ant_display_coex_info(btcoexist, m);
1968        } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1969                if (btcoexist->board_info.btdm_ant_num == 2)
1970                        ex_btc8192e2ant_display_coex_info(btcoexist, m);
1971        }
1972
1973        halbtc_normal_low_power(btcoexist);
1974}
1975
1976void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1977{
1978        if (!halbtc_is_bt_coexist_available(btcoexist))
1979                return;
1980
1981        if (btcoexist->manual_control)
1982                return;
1983
1984        halbtc_leave_low_power(btcoexist);
1985
1986        halbtc_normal_low_power(btcoexist);
1987}
1988
1989void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1990                                           u8 is_5g)
1991{
1992}
1993