linux/drivers/net/wireless/rtlwifi/btcoexist/halbtcoutsrc.c
<<
>>
Prefs
   1/******************************************************************************
   2 *
   3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
   4 *
   5 * This program is free software; you can redistribute it and/or modify it
   6 * under the terms of version 2 of the GNU General Public License as
   7 * published by the Free Software Foundation.
   8 *
   9 * This program is distributed in the hope that it will be useful, but WITHOUT
  10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12 * more details.
  13 *
  14 * The full GNU General Public License is included in this distribution in the
  15 * file called LICENSE.
  16 *
  17 * Contact Information:
  18 * wlanfae <wlanfae@realtek.com>
  19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20 * Hsinchu 300, Taiwan.
  21 *
  22 * Larry Finger <Larry.Finger@lwfinger.net>
  23 *
  24 ******************************************************************************/
  25
  26#include "halbt_precomp.h"
  27
  28/***********************************************
  29 *              Global variables
  30 ***********************************************/
  31
  32struct btc_coexist gl_bt_coexist;
  33
  34u32 btc_dbg_type[BTC_MSG_MAX];
  35static u8 btc_dbg_buf[100];
  36
  37/***************************************************
  38 *              Debug related function
  39 ***************************************************/
  40static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
  41{
  42        if (!btcoexist->binded || NULL == btcoexist->adapter)
  43                return false;
  44
  45        return true;
  46}
  47
  48static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
  49{
  50        if (rtlpriv->link_info.busytraffic)
  51                return true;
  52        else
  53                return false;
  54}
  55
  56static void halbtc_dbg_init(void)
  57{
  58        u8 i;
  59
  60        for (i = 0; i < BTC_MSG_MAX; i++)
  61                btc_dbg_type[i] = 0;
  62
  63        btc_dbg_type[BTC_MSG_INTERFACE] =
  64/*                      INTF_INIT                               | */
  65/*                      INTF_NOTIFY                             | */
  66                        0;
  67
  68        btc_dbg_type[BTC_MSG_ALGORITHM] =
  69/*                      ALGO_BT_RSSI_STATE                      | */
  70/*                      ALGO_WIFI_RSSI_STATE                    | */
  71/*                      ALGO_BT_MONITOR                         | */
  72/*                      ALGO_TRACE                              | */
  73/*                      ALGO_TRACE_FW                           | */
  74/*                      ALGO_TRACE_FW_DETAIL                    | */
  75/*                      ALGO_TRACE_FW_EXEC                      | */
  76/*                      ALGO_TRACE_SW                           | */
  77/*                      ALGO_TRACE_SW_DETAIL                    | */
  78/*                      ALGO_TRACE_SW_EXEC                      | */
  79                        0;
  80}
  81
  82static bool halbtc_is_bt40(struct rtl_priv *adapter)
  83{
  84        struct rtl_priv *rtlpriv = adapter;
  85        struct rtl_phy *rtlphy = &(rtlpriv->phy);
  86        bool is_ht40 = true;
  87        enum ht_channel_width bw = rtlphy->current_chan_bw;
  88
  89        if (bw == HT_CHANNEL_WIDTH_20)
  90                is_ht40 = false;
  91        else if (bw == HT_CHANNEL_WIDTH_20_40)
  92                is_ht40 = true;
  93
  94        return is_ht40;
  95}
  96
  97static bool halbtc_legacy(struct rtl_priv *adapter)
  98{
  99        struct rtl_priv *rtlpriv = adapter;
 100        struct rtl_mac *mac = rtl_mac(rtlpriv);
 101
 102        bool is_legacy = false;
 103
 104        if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_B))
 105                is_legacy = true;
 106
 107        return is_legacy;
 108}
 109
 110bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
 111{
 112        struct rtl_priv *rtlpriv = adapter;
 113
 114        if (rtlpriv->link_info.tx_busy_traffic)
 115                return true;
 116        else
 117                return false;
 118}
 119
 120static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
 121{
 122        struct rtl_priv *rtlpriv =
 123                (struct rtl_priv *)btcoexist->adapter;
 124        u32 wifi_bw = BTC_WIFI_BW_HT20;
 125
 126        if (halbtc_is_bt40(rtlpriv)) {
 127                wifi_bw = BTC_WIFI_BW_HT40;
 128        } else {
 129                if (halbtc_legacy(rtlpriv))
 130                        wifi_bw = BTC_WIFI_BW_LEGACY;
 131                else
 132                        wifi_bw = BTC_WIFI_BW_HT20;
 133        }
 134        return wifi_bw;
 135}
 136
 137static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
 138{
 139        struct rtl_priv *rtlpriv = btcoexist->adapter;
 140        struct rtl_phy  *rtlphy = &(rtlpriv->phy);
 141        u8 chnl = 1;
 142
 143        if (rtlphy->current_channel != 0)
 144                chnl = rtlphy->current_channel;
 145        BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
 146                  "static halbtc_get_wifi_central_chnl:%d\n", chnl);
 147        return chnl;
 148}
 149
 150static void halbtc_leave_lps(struct btc_coexist *btcoexist)
 151{
 152        struct rtl_priv *rtlpriv;
 153        struct rtl_ps_ctl *ppsc;
 154        bool ap_enable = false;
 155
 156        rtlpriv = btcoexist->adapter;
 157        ppsc = rtl_psc(rtlpriv);
 158
 159        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
 160                           &ap_enable);
 161
 162        if (ap_enable) {
 163                pr_info("halbtc_leave_lps()<--dont leave lps under AP mode\n");
 164                return;
 165        }
 166
 167        btcoexist->bt_info.bt_ctrl_lps = true;
 168        btcoexist->bt_info.bt_lps_on = false;
 169}
 170
 171static void halbtc_enter_lps(struct btc_coexist *btcoexist)
 172{
 173        struct rtl_priv *rtlpriv;
 174        struct rtl_ps_ctl *ppsc;
 175        bool ap_enable = false;
 176
 177        rtlpriv = btcoexist->adapter;
 178        ppsc = rtl_psc(rtlpriv);
 179
 180        btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
 181                           &ap_enable);
 182
 183        if (ap_enable) {
 184                pr_info("halbtc_enter_lps()<--dont enter lps under AP mode\n");
 185                return;
 186        }
 187
 188        btcoexist->bt_info.bt_ctrl_lps = true;
 189        btcoexist->bt_info.bt_lps_on = false;
 190}
 191
 192static void halbtc_normal_lps(struct btc_coexist *btcoexist)
 193{
 194        if (btcoexist->bt_info.bt_ctrl_lps) {
 195                btcoexist->bt_info.bt_lps_on = false;
 196                btcoexist->bt_info.bt_ctrl_lps = false;
 197        }
 198}
 199
 200static void halbtc_leave_low_power(void)
 201{
 202}
 203
 204static void halbtc_nomal_low_power(void)
 205{
 206}
 207
 208static void halbtc_disable_low_power(void)
 209{
 210}
 211
 212static void halbtc_aggregation_check(void)
 213{
 214}
 215
 216static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
 217{
 218        return 0;
 219}
 220
 221static s32 halbtc_get_wifi_rssi(struct rtl_priv *adapter)
 222{
 223        struct rtl_priv *rtlpriv = adapter;
 224        s32     undec_sm_pwdb = 0;
 225
 226        if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
 227                undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
 228        else /* associated entry pwdb */
 229                undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
 230        return undec_sm_pwdb;
 231}
 232
 233static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
 234{
 235        struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
 236        struct rtl_priv *rtlpriv = btcoexist->adapter;
 237        struct rtl_phy *rtlphy = &(rtlpriv->phy);
 238        struct rtl_mac *mac = rtl_mac(rtlpriv);
 239        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 240        bool *bool_tmp = (bool *)out_buf;
 241        int *s32_tmp = (int *)out_buf;
 242        u32 *u32_tmp = (u32 *)out_buf;
 243        u8 *u8_tmp = (u8 *)out_buf;
 244        bool tmp = false;
 245
 246        if (!halbtc_is_bt_coexist_available(btcoexist))
 247                return false;
 248
 249        switch (get_type) {
 250        case BTC_GET_BL_HS_OPERATION:
 251                *bool_tmp = false;
 252                break;
 253        case BTC_GET_BL_HS_CONNECTING:
 254                *bool_tmp = false;
 255                break;
 256        case BTC_GET_BL_WIFI_CONNECTED:
 257                if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
 258                        tmp = true;
 259                *bool_tmp = tmp;
 260                break;
 261        case BTC_GET_BL_WIFI_BUSY:
 262                if (halbtc_is_wifi_busy(rtlpriv))
 263                        *bool_tmp = true;
 264                else
 265                        *bool_tmp = false;
 266                break;
 267        case BTC_GET_BL_WIFI_SCAN:
 268                if (mac->act_scanning)
 269                        *bool_tmp = true;
 270                else
 271                        *bool_tmp = false;
 272                break;
 273        case BTC_GET_BL_WIFI_LINK:
 274                if (mac->link_state == MAC80211_LINKING)
 275                        *bool_tmp = true;
 276                else
 277                        *bool_tmp = false;
 278                break;
 279        case BTC_GET_BL_WIFI_ROAM:      /*TODO*/
 280                if (mac->link_state == MAC80211_LINKING)
 281                        *bool_tmp = true;
 282                else
 283                        *bool_tmp = false;
 284                break;
 285        case BTC_GET_BL_WIFI_4_WAY_PROGRESS:    /*TODO*/
 286                        *bool_tmp = false;
 287
 288                break;
 289        case BTC_GET_BL_WIFI_UNDER_5G:
 290                *bool_tmp = false; /*TODO*/
 291
 292        case BTC_GET_BL_WIFI_DHCP:      /*TODO*/
 293                break;
 294        case BTC_GET_BL_WIFI_SOFTAP_IDLE:
 295                *bool_tmp = true;
 296                break;
 297        case BTC_GET_BL_WIFI_SOFTAP_LINKING:
 298                *bool_tmp = false;
 299                break;
 300        case BTC_GET_BL_WIFI_IN_EARLY_SUSPEND:
 301                *bool_tmp = false;
 302                break;
 303        case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
 304                *bool_tmp = false;
 305                break;
 306        case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
 307                if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
 308                        *bool_tmp = false;
 309                else
 310                        *bool_tmp = true;
 311                break;
 312        case BTC_GET_BL_WIFI_UNDER_B_MODE:
 313                *bool_tmp = false; /*TODO*/
 314                break;
 315        case BTC_GET_BL_EXT_SWITCH:
 316                *bool_tmp = false;
 317                break;
 318        case BTC_GET_S4_WIFI_RSSI:
 319                *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
 320                break;
 321        case BTC_GET_S4_HS_RSSI:        /*TODO*/
 322                *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
 323                break;
 324        case BTC_GET_U4_WIFI_BW:
 325                *u32_tmp = halbtc_get_wifi_bw(btcoexist);
 326                break;
 327        case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
 328                if (halbtc_is_wifi_uplink(rtlpriv))
 329                        *u32_tmp = BTC_WIFI_TRAFFIC_TX;
 330                else
 331                        *u32_tmp = BTC_WIFI_TRAFFIC_RX;
 332                break;
 333        case BTC_GET_U4_WIFI_FW_VER:
 334                *u32_tmp = rtlhal->fw_version;
 335                break;
 336        case BTC_GET_U4_BT_PATCH_VER:
 337                *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
 338                break;
 339        case BTC_GET_U1_WIFI_DOT11_CHNL:
 340                *u8_tmp = rtlphy->current_channel;
 341                break;
 342        case BTC_GET_U1_WIFI_CENTRAL_CHNL:
 343                *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
 344                break;
 345        case BTC_GET_U1_WIFI_HS_CHNL:
 346                *u8_tmp = 1;/*BT_OperateChnl(rtlpriv);*/
 347                break;
 348        case BTC_GET_U1_MAC_PHY_MODE:
 349                *u8_tmp = BTC_MP_UNKNOWN;
 350                break;
 351
 352                /************* 1Ant **************/
 353        case BTC_GET_U1_LPS_MODE:
 354                *u8_tmp = btcoexist->pwr_mode_val[0];
 355                break;
 356
 357        default:
 358                break;
 359        }
 360
 361        return true;
 362}
 363
 364static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
 365{
 366        struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
 367        bool *bool_tmp = (bool *)in_buf;
 368        u8 *u8_tmp = (u8 *)in_buf;
 369        u32 *u32_tmp = (u32 *)in_buf;
 370
 371        if (!halbtc_is_bt_coexist_available(btcoexist))
 372                return false;
 373
 374        switch (set_type) {
 375        /* set some bool type variables. */
 376        case BTC_SET_BL_BT_DISABLE:
 377                btcoexist->bt_info.bt_disabled = *bool_tmp;
 378                break;
 379        case BTC_SET_BL_BT_TRAFFIC_BUSY:
 380                btcoexist->bt_info.bt_busy = *bool_tmp;
 381                break;
 382        case BTC_SET_BL_BT_LIMITED_DIG:
 383                btcoexist->bt_info.limited_dig = *bool_tmp;
 384                break;
 385        case BTC_SET_BL_FORCE_TO_ROAM:
 386                btcoexist->bt_info.force_to_roam = *bool_tmp;
 387                break;
 388        case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
 389                btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
 390                break;
 391        case BTC_SET_BL_BT_CTRL_AGG_SIZE:
 392                btcoexist->bt_info.b_bt_ctrl_buf_size = *bool_tmp;
 393                break;
 394        case BTC_SET_BL_INC_SCAN_DEV_NUM:
 395                btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
 396                break;
 397                /* set some u1Byte type variables. */
 398        case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
 399                btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
 400                break;
 401        case BTC_SET_U1_AGG_BUF_SIZE:
 402                btcoexist->bt_info.agg_buf_size = *u8_tmp;
 403                break;
 404                /* the following are some action which will be triggered */
 405        case BTC_SET_ACT_GET_BT_RSSI:
 406                /*BTHCI_SendGetBtRssiEvent(rtlpriv);*/
 407                break;
 408        case BTC_SET_ACT_AGGREGATE_CTRL:
 409                halbtc_aggregation_check();
 410                break;
 411
 412                /* 1Ant */
 413        case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
 414                btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
 415                break;
 416        case BTC_SET_UI_SCAN_SIG_COMPENSATION:
 417        /*      rtlpriv->mlmepriv.scan_compensation = *u8_tmp;  */
 418                break;
 419        case BTC_SET_U1_1ANT_LPS:
 420                btcoexist->bt_info.lps_1ant = *u8_tmp;
 421                break;
 422        case BTC_SET_U1_1ANT_RPWM:
 423                btcoexist->bt_info.rpwm_1ant = *u8_tmp;
 424                break;
 425        /* the following are some action which will be triggered  */
 426        case BTC_SET_ACT_LEAVE_LPS:
 427                halbtc_leave_lps(btcoexist);
 428                break;
 429        case BTC_SET_ACT_ENTER_LPS:
 430                halbtc_enter_lps(btcoexist);
 431                break;
 432        case BTC_SET_ACT_NORMAL_LPS:
 433                halbtc_normal_lps(btcoexist);
 434                break;
 435        case BTC_SET_ACT_DISABLE_LOW_POWER:
 436                halbtc_disable_low_power();
 437                break;
 438        case BTC_SET_ACT_UPDATE_ra_mask:
 439                btcoexist->bt_info.ra_mask = *u32_tmp;
 440                break;
 441        case BTC_SET_ACT_SEND_MIMO_PS:
 442                break;
 443        case BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT:
 444                btcoexist->bt_info.force_exec_pwr_cmd_cnt++;
 445                break;
 446        case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
 447                break;
 448        case BTC_SET_ACT_CTRL_BT_COEX:
 449                break;
 450        default:
 451                break;
 452        }
 453
 454        return true;
 455}
 456
 457static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist)
 458{
 459}
 460
 461static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist)
 462{
 463}
 464
 465static void halbtc_display_bt_fw_info(struct btc_coexist *btcoexist)
 466{
 467}
 468
 469static void halbtc_display_fw_pwr_mode_cmd(struct btc_coexist *btcoexist)
 470{
 471}
 472
 473/************************************************************
 474 *              IO related function
 475 ************************************************************/
 476static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
 477{
 478        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 479        struct rtl_priv *rtlpriv = btcoexist->adapter;
 480
 481        return  rtl_read_byte(rtlpriv, reg_addr);
 482}
 483
 484static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
 485{
 486        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 487        struct rtl_priv *rtlpriv = btcoexist->adapter;
 488
 489        return  rtl_read_word(rtlpriv, reg_addr);
 490}
 491
 492static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
 493{
 494        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 495        struct rtl_priv *rtlpriv = btcoexist->adapter;
 496
 497        return  rtl_read_dword(rtlpriv, reg_addr);
 498}
 499
 500static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u8 data)
 501{
 502        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 503        struct rtl_priv *rtlpriv = btcoexist->adapter;
 504
 505        rtl_write_byte(rtlpriv, reg_addr, data);
 506}
 507
 508static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
 509                                       u32 bit_mask, u8 data)
 510{
 511        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 512        struct rtl_priv *rtlpriv = btcoexist->adapter;
 513        u8 original_value, bit_shift = 0;
 514        u8 i;
 515
 516        if (bit_mask != MASKDWORD) {/*if not "double word" write*/
 517                original_value = rtl_read_byte(rtlpriv, reg_addr);
 518                for (i = 0; i <= 7; i++) {
 519                        if ((bit_mask>>i) & 0x1)
 520                                break;
 521                }
 522                bit_shift = i;
 523                data = (original_value & (~bit_mask)) |
 524                        ((data << bit_shift) & bit_mask);
 525        }
 526        rtl_write_byte(rtlpriv, reg_addr, data);
 527}
 528
 529static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
 530{
 531        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 532        struct rtl_priv *rtlpriv = btcoexist->adapter;
 533
 534        rtl_write_word(rtlpriv, reg_addr, data);
 535}
 536
 537static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
 538{
 539        struct btc_coexist *btcoexist =
 540                (struct btc_coexist *)bt_context;
 541        struct rtl_priv *rtlpriv = btcoexist->adapter;
 542
 543        rtl_write_dword(rtlpriv, reg_addr, data);
 544}
 545
 546static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
 547                             u32 data)
 548{
 549        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 550        struct rtl_priv *rtlpriv = btcoexist->adapter;
 551
 552        rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
 553}
 554
 555static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
 556{
 557        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 558        struct rtl_priv *rtlpriv = btcoexist->adapter;
 559
 560        return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
 561}
 562
 563static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
 564                             u32 bit_mask, u32 data)
 565{
 566        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 567        struct rtl_priv *rtlpriv = btcoexist->adapter;
 568
 569        rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
 570}
 571
 572static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
 573                            u32 bit_mask)
 574{
 575        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 576        struct rtl_priv *rtlpriv = btcoexist->adapter;
 577
 578        return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
 579}
 580
 581static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
 582                                u32 cmd_len, u8 *cmd_buf)
 583{
 584        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 585        struct rtl_priv *rtlpriv = btcoexist->adapter;
 586
 587        rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
 588                                        cmd_len, cmd_buf);
 589}
 590
 591static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type)
 592{
 593        struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
 594        switch (disp_type) {
 595        case BTC_DBG_DISP_COEX_STATISTICS:
 596                halbtc_display_coex_statistics(btcoexist);
 597                break;
 598        case BTC_DBG_DISP_BT_LINK_INFO:
 599                halbtc_display_bt_link_info(btcoexist);
 600                break;
 601        case BTC_DBG_DISP_BT_FW_VER:
 602                halbtc_display_bt_fw_info(btcoexist);
 603                break;
 604        case BTC_DBG_DISP_FW_PWR_MODE_CMD:
 605                halbtc_display_fw_pwr_mode_cmd(btcoexist);
 606                break;
 607        default:
 608                break;
 609        }
 610}
 611
 612/*****************************************************************
 613 *         Extern functions called by other module
 614 *****************************************************************/
 615bool exhalbtc_initlize_variables(struct rtl_priv *adapter)
 616{
 617        struct btc_coexist *btcoexist = &gl_bt_coexist;
 618
 619        btcoexist->statistics.cnt_bind++;
 620
 621        halbtc_dbg_init();
 622
 623        if (btcoexist->binded)
 624                return false;
 625        else
 626                btcoexist->binded = true;
 627
 628        btcoexist->chip_interface = BTC_INTF_UNKNOWN;
 629
 630        if (NULL == btcoexist->adapter)
 631                btcoexist->adapter = adapter;
 632
 633        btcoexist->stack_info.profile_notified = false;
 634
 635        btcoexist->btc_read_1byte = halbtc_read_1byte;
 636        btcoexist->btc_write_1byte = halbtc_write_1byte;
 637        btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
 638        btcoexist->btc_read_2byte = halbtc_read_2byte;
 639        btcoexist->btc_write_2byte = halbtc_write_2byte;
 640        btcoexist->btc_read_4byte = halbtc_read_4byte;
 641        btcoexist->btc_write_4byte = halbtc_write_4byte;
 642
 643        btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
 644        btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
 645
 646        btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
 647        btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
 648
 649        btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
 650        btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
 651
 652        btcoexist->btc_get = halbtc_get;
 653        btcoexist->btc_set = halbtc_set;
 654
 655        btcoexist->cli_buf = &btc_dbg_buf[0];
 656
 657        btcoexist->bt_info.b_bt_ctrl_buf_size = false;
 658        btcoexist->bt_info.agg_buf_size = 5;
 659
 660        btcoexist->bt_info.increase_scan_dev_num = false;
 661        return true;
 662}
 663
 664void exhalbtc_init_hw_config(struct btc_coexist *btcoexist)
 665{
 666        struct rtl_priv *rtlpriv = btcoexist->adapter;
 667        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 668
 669        if (!halbtc_is_bt_coexist_available(btcoexist))
 670                return;
 671
 672        btcoexist->statistics.cnt_init_hw_config++;
 673
 674        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 675                ex_halbtc8723b2ant_init_hwconfig(btcoexist);
 676}
 677
 678void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
 679{
 680        struct rtl_priv *rtlpriv = btcoexist->adapter;
 681        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 682
 683        if (!halbtc_is_bt_coexist_available(btcoexist))
 684                return;
 685
 686        btcoexist->statistics.cnt_init_coex_dm++;
 687
 688        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 689                ex_halbtc8723b2ant_init_coex_dm(btcoexist);
 690
 691        btcoexist->initilized = true;
 692}
 693
 694void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
 695{
 696        struct rtl_priv *rtlpriv = btcoexist->adapter;
 697        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 698        u8 ips_type;
 699
 700        if (!halbtc_is_bt_coexist_available(btcoexist))
 701                return;
 702        btcoexist->statistics.cnt_ips_notify++;
 703        if (btcoexist->manual_control)
 704                return;
 705
 706        if (ERFOFF == type)
 707                ips_type = BTC_IPS_ENTER;
 708        else
 709                ips_type = BTC_IPS_LEAVE;
 710
 711        halbtc_leave_low_power();
 712
 713        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 714                ex_halbtc8723b2ant_ips_notify(btcoexist, ips_type);
 715
 716        halbtc_nomal_low_power();
 717}
 718
 719void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
 720{
 721        struct rtl_priv *rtlpriv = btcoexist->adapter;
 722        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 723        u8 lps_type;
 724
 725        if (!halbtc_is_bt_coexist_available(btcoexist))
 726                return;
 727        btcoexist->statistics.cnt_lps_notify++;
 728        if (btcoexist->manual_control)
 729                return;
 730
 731        if (EACTIVE == type)
 732                lps_type = BTC_LPS_DISABLE;
 733        else
 734                lps_type = BTC_LPS_ENABLE;
 735
 736        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 737                ex_halbtc8723b2ant_lps_notify(btcoexist, lps_type);
 738}
 739
 740void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
 741{
 742        struct rtl_priv *rtlpriv = btcoexist->adapter;
 743        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 744        u8 scan_type;
 745
 746        if (!halbtc_is_bt_coexist_available(btcoexist))
 747                return;
 748        btcoexist->statistics.cnt_scan_notify++;
 749        if (btcoexist->manual_control)
 750                return;
 751
 752        if (type)
 753                scan_type = BTC_SCAN_START;
 754        else
 755                scan_type = BTC_SCAN_FINISH;
 756
 757        halbtc_leave_low_power();
 758
 759        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 760                ex_halbtc8723b2ant_scan_notify(btcoexist, scan_type);
 761
 762        halbtc_nomal_low_power();
 763}
 764
 765void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
 766{
 767        struct rtl_priv *rtlpriv = btcoexist->adapter;
 768        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 769        u8 asso_type;
 770
 771        if (!halbtc_is_bt_coexist_available(btcoexist))
 772                return;
 773        btcoexist->statistics.cnt_connect_notify++;
 774        if (btcoexist->manual_control)
 775                return;
 776
 777        if (action)
 778                asso_type = BTC_ASSOCIATE_START;
 779        else
 780                asso_type = BTC_ASSOCIATE_FINISH;
 781
 782        halbtc_leave_low_power();
 783
 784        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 785                ex_halbtc8723b2ant_connect_notify(btcoexist, asso_type);
 786}
 787
 788void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
 789                                 enum _RT_MEDIA_STATUS media_status)
 790{
 791        struct rtl_priv *rtlpriv = btcoexist->adapter;
 792        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 793        u8 status;
 794
 795        if (!halbtc_is_bt_coexist_available(btcoexist))
 796                return;
 797        btcoexist->statistics.cnt_media_status_notify++;
 798        if (btcoexist->manual_control)
 799                return;
 800
 801        if (RT_MEDIA_CONNECT == media_status)
 802                status = BTC_MEDIA_CONNECT;
 803        else
 804                status = BTC_MEDIA_DISCONNECT;
 805
 806        halbtc_leave_low_power();
 807
 808        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 809                btc8723b_med_stat_notify(btcoexist, status);
 810
 811        halbtc_nomal_low_power();
 812}
 813
 814void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
 815{
 816        struct rtl_priv *rtlpriv = btcoexist->adapter;
 817        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 818        u8 packet_type;
 819
 820        if (!halbtc_is_bt_coexist_available(btcoexist))
 821                return;
 822        btcoexist->statistics.cnt_special_packet_notify++;
 823        if (btcoexist->manual_control)
 824                return;
 825
 826        packet_type = BTC_PACKET_DHCP;
 827
 828        halbtc_leave_low_power();
 829
 830        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 831                ex_halbtc8723b2ant_special_packet_notify(btcoexist,
 832                                                         packet_type);
 833
 834        halbtc_nomal_low_power();
 835}
 836
 837void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
 838                             u8 *tmp_buf, u8 length)
 839{
 840        struct rtl_priv *rtlpriv = btcoexist->adapter;
 841        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 842        if (!halbtc_is_bt_coexist_available(btcoexist))
 843                return;
 844        btcoexist->statistics.cnt_bt_info_notify++;
 845
 846        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 847                ex_halbtc8723b2ant_bt_info_notify(btcoexist, tmp_buf, length);
 848}
 849
 850void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
 851{
 852        struct rtl_priv *rtlpriv = btcoexist->adapter;
 853        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 854        u8 stack_op_type;
 855
 856        if (!halbtc_is_bt_coexist_available(btcoexist))
 857                return;
 858        btcoexist->statistics.cnt_stack_operation_notify++;
 859        if (btcoexist->manual_control)
 860                return;
 861
 862        stack_op_type = BTC_STACK_OP_NONE;
 863
 864        halbtc_leave_low_power();
 865
 866        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 867                ex_halbtc8723b2ant_stack_operation_notify(btcoexist,
 868                                                          stack_op_type);
 869
 870        halbtc_nomal_low_power();
 871}
 872
 873void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
 874{
 875        struct rtl_priv *rtlpriv = btcoexist->adapter;
 876        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 877        if (!halbtc_is_bt_coexist_available(btcoexist))
 878                return;
 879
 880        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 881                ex_halbtc8723b2ant_halt_notify(btcoexist);
 882}
 883
 884void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
 885{
 886        if (!halbtc_is_bt_coexist_available(btcoexist))
 887                return;
 888}
 889
 890void exhalbtc_periodical(struct btc_coexist *btcoexist)
 891{
 892        struct rtl_priv *rtlpriv = btcoexist->adapter;
 893        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 894        if (!halbtc_is_bt_coexist_available(btcoexist))
 895                return;
 896        btcoexist->statistics.cnt_periodical++;
 897
 898        halbtc_leave_low_power();
 899
 900        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
 901                ex_halbtc8723b2ant_periodical(btcoexist);
 902
 903        halbtc_nomal_low_power();
 904}
 905
 906void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
 907                          u8 code, u8 len, u8 *data)
 908{
 909        if (!halbtc_is_bt_coexist_available(btcoexist))
 910                return;
 911        btcoexist->statistics.cnt_dbg_ctrl++;
 912}
 913
 914void exhalbtc_stack_update_profile_info(void)
 915{
 916}
 917
 918void exhalbtc_update_min_bt_rssi(char bt_rssi)
 919{
 920        struct btc_coexist *btcoexist = &gl_bt_coexist;
 921
 922        if (!halbtc_is_bt_coexist_available(btcoexist))
 923                return;
 924
 925        btcoexist->stack_info.min_bt_rssi = bt_rssi;
 926}
 927
 928void exhalbtc_set_hci_version(u16 hci_version)
 929{
 930        struct btc_coexist *btcoexist = &gl_bt_coexist;
 931
 932        if (!halbtc_is_bt_coexist_available(btcoexist))
 933                return;
 934
 935        btcoexist->stack_info.hci_version = hci_version;
 936}
 937
 938void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version)
 939{
 940        struct btc_coexist *btcoexist = &gl_bt_coexist;
 941
 942        if (!halbtc_is_bt_coexist_available(btcoexist))
 943                return;
 944
 945        btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
 946        btcoexist->bt_info.bt_hci_ver = bt_hci_version;
 947}
 948
 949void exhalbtc_set_bt_exist(bool bt_exist)
 950{
 951        gl_bt_coexist.board_info.bt_exist = bt_exist;
 952}
 953
 954void exhalbtc_set_chip_type(u8 chip_type)
 955{
 956        switch (chip_type) {
 957        default:
 958        case BT_2WIRE:
 959        case BT_ISSC_3WIRE:
 960        case BT_ACCEL:
 961        case BT_RTL8756:
 962                gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
 963                break;
 964        case BT_CSR_BC4:
 965                gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
 966                break;
 967        case BT_CSR_BC8:
 968                gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
 969                break;
 970        case BT_RTL8723A:
 971                gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
 972                break;
 973        case BT_RTL8821A:
 974                gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
 975                break;
 976        case BT_RTL8723B:
 977                gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
 978                break;
 979        }
 980}
 981
 982void exhalbtc_set_ant_num(u8 type, u8 ant_num)
 983{
 984        if (BT_COEX_ANT_TYPE_PG == type) {
 985                gl_bt_coexist.board_info.pg_ant_num = ant_num;
 986                gl_bt_coexist.board_info.btdm_ant_num = ant_num;
 987        } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
 988                gl_bt_coexist.board_info.btdm_ant_num = ant_num;
 989        }
 990}
 991
 992void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist)
 993{
 994        struct rtl_priv *rtlpriv = btcoexist->adapter;
 995        struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
 996        if (!halbtc_is_bt_coexist_available(btcoexist))
 997                return;
 998
 999        if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
1000                ex_halbtc8723b2ant_display_coex_info(btcoexist);
1001}
1002