1 /******************************************************************************
3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 ******************************************************************************/
26 #include "halbt_precomp.h"
28 /***********************************************
30 ***********************************************/
32 struct btc_coexist gl_bt_coexist
;
34 u32 btc_dbg_type
[BTC_MSG_MAX
];
35 static u8 btc_dbg_buf
[100];
37 /***************************************************
38 * Debug related function
39 ***************************************************/
40 static bool halbtc_is_bt_coexist_available(struct btc_coexist
*btcoexist
)
42 if (!btcoexist
->binded
|| NULL
== btcoexist
->adapter
)
48 static bool halbtc_is_wifi_busy(struct rtl_priv
*rtlpriv
)
50 if (rtlpriv
->link_info
.busytraffic
)
56 static void halbtc_dbg_init(void)
60 for (i
= 0; i
< BTC_MSG_MAX
; i
++)
63 btc_dbg_type
[BTC_MSG_INTERFACE
] =
68 btc_dbg_type
[BTC_MSG_ALGORITHM
] =
69 /* ALGO_BT_RSSI_STATE | */
70 /* ALGO_WIFI_RSSI_STATE | */
71 /* ALGO_BT_MONITOR | */
74 /* ALGO_TRACE_FW_DETAIL | */
75 /* ALGO_TRACE_FW_EXEC | */
77 /* ALGO_TRACE_SW_DETAIL | */
78 /* ALGO_TRACE_SW_EXEC | */
82 static bool halbtc_is_bt40(struct rtl_priv
*adapter
)
84 struct rtl_priv
*rtlpriv
= adapter
;
85 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
87 enum ht_channel_width bw
= rtlphy
->current_chan_bw
;
89 if (bw
== HT_CHANNEL_WIDTH_20
)
91 else if (bw
== HT_CHANNEL_WIDTH_20_40
)
97 static bool halbtc_legacy(struct rtl_priv
*adapter
)
99 struct rtl_priv
*rtlpriv
= adapter
;
100 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
102 bool is_legacy
= false;
104 if ((mac
->mode
== WIRELESS_MODE_B
) || (mac
->mode
== WIRELESS_MODE_B
))
110 bool halbtc_is_wifi_uplink(struct rtl_priv
*adapter
)
112 struct rtl_priv
*rtlpriv
= adapter
;
114 if (rtlpriv
->link_info
.tx_busy_traffic
)
120 static u32
halbtc_get_wifi_bw(struct btc_coexist
*btcoexist
)
122 struct rtl_priv
*rtlpriv
=
123 (struct rtl_priv
*)btcoexist
->adapter
;
124 u32 wifi_bw
= BTC_WIFI_BW_HT20
;
126 if (halbtc_is_bt40(rtlpriv
)) {
127 wifi_bw
= BTC_WIFI_BW_HT40
;
129 if (halbtc_legacy(rtlpriv
))
130 wifi_bw
= BTC_WIFI_BW_LEGACY
;
132 wifi_bw
= BTC_WIFI_BW_HT20
;
137 static u8
halbtc_get_wifi_central_chnl(struct btc_coexist
*btcoexist
)
139 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
140 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
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
);
150 static void halbtc_leave_lps(struct btc_coexist
*btcoexist
)
152 struct rtl_priv
*rtlpriv
;
153 struct rtl_ps_ctl
*ppsc
;
154 bool ap_enable
= false;
156 rtlpriv
= btcoexist
->adapter
;
157 ppsc
= rtl_psc(rtlpriv
);
159 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
163 pr_info("halbtc_leave_lps()<--dont leave lps under AP mode\n");
167 btcoexist
->bt_info
.bt_ctrl_lps
= true;
168 btcoexist
->bt_info
.bt_lps_on
= false;
171 static void halbtc_enter_lps(struct btc_coexist
*btcoexist
)
173 struct rtl_priv
*rtlpriv
;
174 struct rtl_ps_ctl
*ppsc
;
175 bool ap_enable
= false;
177 rtlpriv
= btcoexist
->adapter
;
178 ppsc
= rtl_psc(rtlpriv
);
180 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
184 pr_info("halbtc_enter_lps()<--dont enter lps under AP mode\n");
188 btcoexist
->bt_info
.bt_ctrl_lps
= true;
189 btcoexist
->bt_info
.bt_lps_on
= false;
192 static void halbtc_normal_lps(struct btc_coexist
*btcoexist
)
194 if (btcoexist
->bt_info
.bt_ctrl_lps
) {
195 btcoexist
->bt_info
.bt_lps_on
= false;
196 btcoexist
->bt_info
.bt_ctrl_lps
= false;
200 static void halbtc_leave_low_power(void)
204 static void halbtc_nomal_low_power(void)
208 static void halbtc_disable_low_power(void)
212 static void halbtc_aggregation_check(void)
216 static u32
halbtc_get_bt_patch_version(struct btc_coexist
*btcoexist
)
221 static s32
halbtc_get_wifi_rssi(struct rtl_priv
*adapter
)
223 struct rtl_priv
*rtlpriv
= adapter
;
224 s32 undec_sm_pwdb
= 0;
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
;
233 static bool halbtc_get(void *void_btcoexist
, u8 get_type
, void *out_buf
)
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
;
246 if (!halbtc_is_bt_coexist_available(btcoexist
))
250 case BTC_GET_BL_HS_OPERATION
:
253 case BTC_GET_BL_HS_CONNECTING
:
256 case BTC_GET_BL_WIFI_CONNECTED
:
257 if (rtlpriv
->mac80211
.link_state
>= MAC80211_LINKED
)
261 case BTC_GET_BL_WIFI_BUSY
:
262 if (halbtc_is_wifi_busy(rtlpriv
))
267 case BTC_GET_BL_WIFI_SCAN
:
268 if (mac
->act_scanning
)
273 case BTC_GET_BL_WIFI_LINK
:
274 if (mac
->link_state
== MAC80211_LINKING
)
279 case BTC_GET_BL_WIFI_ROAM
: /*TODO*/
280 if (mac
->link_state
== MAC80211_LINKING
)
285 case BTC_GET_BL_WIFI_4_WAY_PROGRESS
: /*TODO*/
289 case BTC_GET_BL_WIFI_UNDER_5G
:
290 *bool_tmp
= false; /*TODO*/
292 case BTC_GET_BL_WIFI_DHCP
: /*TODO*/
294 case BTC_GET_BL_WIFI_SOFTAP_IDLE
:
297 case BTC_GET_BL_WIFI_SOFTAP_LINKING
:
300 case BTC_GET_BL_WIFI_IN_EARLY_SUSPEND
:
303 case BTC_GET_BL_WIFI_AP_MODE_ENABLE
:
306 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION
:
307 if (NO_ENCRYPTION
== rtlpriv
->sec
.pairwise_enc_algorithm
)
312 case BTC_GET_BL_WIFI_UNDER_B_MODE
:
313 *bool_tmp
= false; /*TODO*/
315 case BTC_GET_BL_EXT_SWITCH
:
318 case BTC_GET_S4_WIFI_RSSI
:
319 *s32_tmp
= halbtc_get_wifi_rssi(rtlpriv
);
321 case BTC_GET_S4_HS_RSSI
: /*TODO*/
322 *s32_tmp
= halbtc_get_wifi_rssi(rtlpriv
);
324 case BTC_GET_U4_WIFI_BW
:
325 *u32_tmp
= halbtc_get_wifi_bw(btcoexist
);
327 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
:
328 if (halbtc_is_wifi_uplink(rtlpriv
))
329 *u32_tmp
= BTC_WIFI_TRAFFIC_TX
;
331 *u32_tmp
= BTC_WIFI_TRAFFIC_RX
;
333 case BTC_GET_U4_WIFI_FW_VER
:
334 *u32_tmp
= rtlhal
->fw_version
;
336 case BTC_GET_U4_BT_PATCH_VER
:
337 *u32_tmp
= halbtc_get_bt_patch_version(btcoexist
);
339 case BTC_GET_U1_WIFI_DOT11_CHNL
:
340 *u8_tmp
= rtlphy
->current_channel
;
342 case BTC_GET_U1_WIFI_CENTRAL_CHNL
:
343 *u8_tmp
= halbtc_get_wifi_central_chnl(btcoexist
);
345 case BTC_GET_U1_WIFI_HS_CHNL
:
346 *u8_tmp
= 1;/*BT_OperateChnl(rtlpriv);*/
348 case BTC_GET_U1_MAC_PHY_MODE
:
349 *u8_tmp
= BTC_MP_UNKNOWN
;
352 /************* 1Ant **************/
353 case BTC_GET_U1_LPS_MODE
:
354 *u8_tmp
= btcoexist
->pwr_mode_val
[0];
364 static bool halbtc_set(void *void_btcoexist
, u8 set_type
, void *in_buf
)
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
;
371 if (!halbtc_is_bt_coexist_available(btcoexist
))
375 /* set some bool type variables. */
376 case BTC_SET_BL_BT_DISABLE
:
377 btcoexist
->bt_info
.bt_disabled
= *bool_tmp
;
379 case BTC_SET_BL_BT_TRAFFIC_BUSY
:
380 btcoexist
->bt_info
.bt_busy
= *bool_tmp
;
382 case BTC_SET_BL_BT_LIMITED_DIG
:
383 btcoexist
->bt_info
.limited_dig
= *bool_tmp
;
385 case BTC_SET_BL_FORCE_TO_ROAM
:
386 btcoexist
->bt_info
.force_to_roam
= *bool_tmp
;
388 case BTC_SET_BL_TO_REJ_AP_AGG_PKT
:
389 btcoexist
->bt_info
.reject_agg_pkt
= *bool_tmp
;
391 case BTC_SET_BL_BT_CTRL_AGG_SIZE
:
392 btcoexist
->bt_info
.b_bt_ctrl_buf_size
= *bool_tmp
;
394 case BTC_SET_BL_INC_SCAN_DEV_NUM
:
395 btcoexist
->bt_info
.increase_scan_dev_num
= *bool_tmp
;
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
;
401 case BTC_SET_U1_AGG_BUF_SIZE
:
402 btcoexist
->bt_info
.agg_buf_size
= *u8_tmp
;
404 /* the following are some action which will be triggered */
405 case BTC_SET_ACT_GET_BT_RSSI
:
406 /*BTHCI_SendGetBtRssiEvent(rtlpriv);*/
408 case BTC_SET_ACT_AGGREGATE_CTRL
:
409 halbtc_aggregation_check();
413 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE
:
414 btcoexist
->bt_info
.rssi_adjust_for_1ant_coex_type
= *u8_tmp
;
416 case BTC_SET_UI_SCAN_SIG_COMPENSATION
:
417 /* rtlpriv->mlmepriv.scan_compensation = *u8_tmp; */
419 case BTC_SET_U1_1ANT_LPS
:
420 btcoexist
->bt_info
.lps_1ant
= *u8_tmp
;
422 case BTC_SET_U1_1ANT_RPWM
:
423 btcoexist
->bt_info
.rpwm_1ant
= *u8_tmp
;
425 /* the following are some action which will be triggered */
426 case BTC_SET_ACT_LEAVE_LPS
:
427 halbtc_leave_lps(btcoexist
);
429 case BTC_SET_ACT_ENTER_LPS
:
430 halbtc_enter_lps(btcoexist
);
432 case BTC_SET_ACT_NORMAL_LPS
:
433 halbtc_normal_lps(btcoexist
);
435 case BTC_SET_ACT_DISABLE_LOW_POWER
:
436 halbtc_disable_low_power();
438 case BTC_SET_ACT_UPDATE_ra_mask
:
439 btcoexist
->bt_info
.ra_mask
= *u32_tmp
;
441 case BTC_SET_ACT_SEND_MIMO_PS
:
443 case BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT
:
444 btcoexist
->bt_info
.force_exec_pwr_cmd_cnt
++;
446 case BTC_SET_ACT_CTRL_BT_INFO
: /*wait for 8812/8821*/
448 case BTC_SET_ACT_CTRL_BT_COEX
:
457 static void halbtc_display_coex_statistics(struct btc_coexist
*btcoexist
)
461 static void halbtc_display_bt_link_info(struct btc_coexist
*btcoexist
)
465 static void halbtc_display_bt_fw_info(struct btc_coexist
*btcoexist
)
469 static void halbtc_display_fw_pwr_mode_cmd(struct btc_coexist
*btcoexist
)
473 /************************************************************
474 * IO related function
475 ************************************************************/
476 static u8
halbtc_read_1byte(void *bt_context
, u32 reg_addr
)
478 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
479 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
481 return rtl_read_byte(rtlpriv
, reg_addr
);
484 static u16
halbtc_read_2byte(void *bt_context
, u32 reg_addr
)
486 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
487 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
489 return rtl_read_word(rtlpriv
, reg_addr
);
492 static u32
halbtc_read_4byte(void *bt_context
, u32 reg_addr
)
494 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
495 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
497 return rtl_read_dword(rtlpriv
, reg_addr
);
500 static void halbtc_write_1byte(void *bt_context
, u32 reg_addr
, u8 data
)
502 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
503 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
505 rtl_write_byte(rtlpriv
, reg_addr
, data
);
508 static void halbtc_bitmask_write_1byte(void *bt_context
, u32 reg_addr
,
509 u32 bit_mask
, u8 data
)
511 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
512 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
513 u8 original_value
, bit_shift
= 0;
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)
523 data
= (original_value
& (~bit_mask
)) |
524 ((data
<< bit_shift
) & bit_mask
);
526 rtl_write_byte(rtlpriv
, reg_addr
, data
);
529 static void halbtc_write_2byte(void *bt_context
, u32 reg_addr
, u16 data
)
531 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
532 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
534 rtl_write_word(rtlpriv
, reg_addr
, data
);
537 static void halbtc_write_4byte(void *bt_context
, u32 reg_addr
, u32 data
)
539 struct btc_coexist
*btcoexist
=
540 (struct btc_coexist
*)bt_context
;
541 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
543 rtl_write_dword(rtlpriv
, reg_addr
, data
);
546 static void halbtc_set_bbreg(void *bt_context
, u32 reg_addr
, u32 bit_mask
,
549 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
550 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
552 rtl_set_bbreg(rtlpriv
->mac80211
.hw
, reg_addr
, bit_mask
, data
);
555 static u32
halbtc_get_bbreg(void *bt_context
, u32 reg_addr
, u32 bit_mask
)
557 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
558 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
560 return rtl_get_bbreg(rtlpriv
->mac80211
.hw
, reg_addr
, bit_mask
);
563 static void halbtc_set_rfreg(void *bt_context
, u8 rf_path
, u32 reg_addr
,
564 u32 bit_mask
, u32 data
)
566 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
567 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
569 rtl_set_rfreg(rtlpriv
->mac80211
.hw
, rf_path
, reg_addr
, bit_mask
, data
);
572 static u32
halbtc_get_rfreg(void *bt_context
, u8 rf_path
, u32 reg_addr
,
575 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
576 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
578 return rtl_get_rfreg(rtlpriv
->mac80211
.hw
, rf_path
, reg_addr
, bit_mask
);
581 static void halbtc_fill_h2c_cmd(void *bt_context
, u8 element_id
,
582 u32 cmd_len
, u8
*cmd_buf
)
584 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
585 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
587 rtlpriv
->cfg
->ops
->fill_h2c_cmd(rtlpriv
->mac80211
.hw
, element_id
,
591 static void halbtc_display_dbg_msg(void *bt_context
, u8 disp_type
)
593 struct btc_coexist
*btcoexist
= (struct btc_coexist
*)bt_context
;
595 case BTC_DBG_DISP_COEX_STATISTICS
:
596 halbtc_display_coex_statistics(btcoexist
);
598 case BTC_DBG_DISP_BT_LINK_INFO
:
599 halbtc_display_bt_link_info(btcoexist
);
601 case BTC_DBG_DISP_BT_FW_VER
:
602 halbtc_display_bt_fw_info(btcoexist
);
604 case BTC_DBG_DISP_FW_PWR_MODE_CMD
:
605 halbtc_display_fw_pwr_mode_cmd(btcoexist
);
612 /*****************************************************************
613 * Extern functions called by other module
614 *****************************************************************/
615 bool exhalbtc_initlize_variables(struct rtl_priv
*adapter
)
617 struct btc_coexist
*btcoexist
= &gl_bt_coexist
;
619 btcoexist
->statistics
.cnt_bind
++;
623 if (btcoexist
->binded
)
626 btcoexist
->binded
= true;
628 #if (defined(CONFIG_PCI_HCI))
629 btcoexist
->chip_interface
= BTC_INTF_PCI
;
630 #elif (defined(CONFIG_USB_HCI))
631 btcoexist
->chip_interface
= BTC_INTF_USB
;
632 #elif (defined(CONFIG_SDIO_HCI))
633 btcoexist
->chip_interface
= BTC_INTF_SDIO
;
634 #elif (defined(CONFIG_GSPI_HCI))
635 btcoexist
->chip_interface
= BTC_INTF_GSPI
;
637 btcoexist
->chip_interface
= BTC_INTF_UNKNOWN
;
640 if (NULL
== btcoexist
->adapter
)
641 btcoexist
->adapter
= adapter
;
643 btcoexist
->stack_info
.profile_notified
= false;
645 btcoexist
->btc_read_1byte
= halbtc_read_1byte
;
646 btcoexist
->btc_write_1byte
= halbtc_write_1byte
;
647 btcoexist
->btc_write_1byte_bitmask
= halbtc_bitmask_write_1byte
;
648 btcoexist
->btc_read_2byte
= halbtc_read_2byte
;
649 btcoexist
->btc_write_2byte
= halbtc_write_2byte
;
650 btcoexist
->btc_read_4byte
= halbtc_read_4byte
;
651 btcoexist
->btc_write_4byte
= halbtc_write_4byte
;
653 btcoexist
->btc_set_bb_reg
= halbtc_set_bbreg
;
654 btcoexist
->btc_get_bb_reg
= halbtc_get_bbreg
;
656 btcoexist
->btc_set_rf_reg
= halbtc_set_rfreg
;
657 btcoexist
->btc_get_rf_reg
= halbtc_get_rfreg
;
659 btcoexist
->btc_fill_h2c
= halbtc_fill_h2c_cmd
;
660 btcoexist
->btc_disp_dbg_msg
= halbtc_display_dbg_msg
;
662 btcoexist
->btc_get
= halbtc_get
;
663 btcoexist
->btc_set
= halbtc_set
;
665 btcoexist
->cli_buf
= &btc_dbg_buf
[0];
667 btcoexist
->bt_info
.b_bt_ctrl_buf_size
= false;
668 btcoexist
->bt_info
.agg_buf_size
= 5;
670 btcoexist
->bt_info
.increase_scan_dev_num
= false;
674 void exhalbtc_init_hw_config(struct btc_coexist
*btcoexist
)
676 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
677 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
679 if (!halbtc_is_bt_coexist_available(btcoexist
))
682 btcoexist
->statistics
.cnt_init_hw_config
++;
684 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
685 ex_halbtc8723b2ant_init_hwconfig(btcoexist
);
688 void exhalbtc_init_coex_dm(struct btc_coexist
*btcoexist
)
690 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
691 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
693 if (!halbtc_is_bt_coexist_available(btcoexist
))
696 btcoexist
->statistics
.cnt_init_coex_dm
++;
698 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
699 ex_halbtc8723b2ant_init_coex_dm(btcoexist
);
701 btcoexist
->initilized
= true;
704 void exhalbtc_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
706 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
707 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
710 if (!halbtc_is_bt_coexist_available(btcoexist
))
712 btcoexist
->statistics
.cnt_ips_notify
++;
713 if (btcoexist
->manual_control
)
717 ips_type
= BTC_IPS_ENTER
;
719 ips_type
= BTC_IPS_LEAVE
;
721 halbtc_leave_low_power();
723 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
724 ex_halbtc8723b2ant_ips_notify(btcoexist
, ips_type
);
726 halbtc_nomal_low_power();
729 void exhalbtc_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
731 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
732 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
735 if (!halbtc_is_bt_coexist_available(btcoexist
))
737 btcoexist
->statistics
.cnt_lps_notify
++;
738 if (btcoexist
->manual_control
)
742 lps_type
= BTC_LPS_DISABLE
;
744 lps_type
= BTC_LPS_ENABLE
;
746 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
747 ex_halbtc8723b2ant_lps_notify(btcoexist
, lps_type
);
750 void exhalbtc_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
752 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
753 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
756 if (!halbtc_is_bt_coexist_available(btcoexist
))
758 btcoexist
->statistics
.cnt_scan_notify
++;
759 if (btcoexist
->manual_control
)
763 scan_type
= BTC_SCAN_START
;
765 scan_type
= BTC_SCAN_FINISH
;
767 halbtc_leave_low_power();
769 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
770 ex_halbtc8723b2ant_scan_notify(btcoexist
, scan_type
);
772 halbtc_nomal_low_power();
775 void exhalbtc_connect_notify(struct btc_coexist
*btcoexist
, u8 action
)
777 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
778 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
781 if (!halbtc_is_bt_coexist_available(btcoexist
))
783 btcoexist
->statistics
.cnt_connect_notify
++;
784 if (btcoexist
->manual_control
)
788 asso_type
= BTC_ASSOCIATE_START
;
790 asso_type
= BTC_ASSOCIATE_FINISH
;
792 halbtc_leave_low_power();
794 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
795 ex_halbtc8723b2ant_connect_notify(btcoexist
, asso_type
);
798 void exhalbtc_mediastatus_notify(struct btc_coexist
*btcoexist
,
799 enum _RT_MEDIA_STATUS media_status
)
801 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
802 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
805 if (!halbtc_is_bt_coexist_available(btcoexist
))
807 btcoexist
->statistics
.cnt_media_status_notify
++;
808 if (btcoexist
->manual_control
)
811 if (RT_MEDIA_CONNECT
== media_status
)
812 status
= BTC_MEDIA_CONNECT
;
814 status
= BTC_MEDIA_DISCONNECT
;
816 halbtc_leave_low_power();
818 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
819 btc8723b_med_stat_notify(btcoexist
, status
);
821 halbtc_nomal_low_power();
824 void exhalbtc_special_packet_notify(struct btc_coexist
*btcoexist
, u8 pkt_type
)
826 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
827 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
830 if (!halbtc_is_bt_coexist_available(btcoexist
))
832 btcoexist
->statistics
.cnt_special_packet_notify
++;
833 if (btcoexist
->manual_control
)
836 packet_type
= BTC_PACKET_DHCP
;
838 halbtc_leave_low_power();
840 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
841 ex_halbtc8723b2ant_special_packet_notify(btcoexist
,
844 halbtc_nomal_low_power();
847 void exhalbtc_bt_info_notify(struct btc_coexist
*btcoexist
,
848 u8
*tmp_buf
, u8 length
)
850 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
851 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
852 if (!halbtc_is_bt_coexist_available(btcoexist
))
854 btcoexist
->statistics
.cnt_bt_info_notify
++;
856 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
857 ex_halbtc8723b2ant_bt_info_notify(btcoexist
, tmp_buf
, length
);
860 void exhalbtc_stack_operation_notify(struct btc_coexist
*btcoexist
, u8 type
)
862 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
863 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
866 if (!halbtc_is_bt_coexist_available(btcoexist
))
868 btcoexist
->statistics
.cnt_stack_operation_notify
++;
869 if (btcoexist
->manual_control
)
872 stack_op_type
= BTC_STACK_OP_NONE
;
874 halbtc_leave_low_power();
876 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
877 ex_halbtc8723b2ant_stack_operation_notify(btcoexist
,
880 halbtc_nomal_low_power();
883 void exhalbtc_halt_notify(struct btc_coexist
*btcoexist
)
885 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
886 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
887 if (!halbtc_is_bt_coexist_available(btcoexist
))
890 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
891 ex_halbtc8723b2ant_halt_notify(btcoexist
);
894 void exhalbtc_pnp_notify(struct btc_coexist
*btcoexist
, u8 pnp_state
)
896 if (!halbtc_is_bt_coexist_available(btcoexist
))
900 void exhalbtc_periodical(struct btc_coexist
*btcoexist
)
902 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
903 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
904 if (!halbtc_is_bt_coexist_available(btcoexist
))
906 btcoexist
->statistics
.cnt_periodical
++;
908 halbtc_leave_low_power();
910 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
911 ex_halbtc8723b2ant_periodical(btcoexist
);
913 halbtc_nomal_low_power();
916 void exhalbtc_dbg_control(struct btc_coexist
*btcoexist
,
917 u8 code
, u8 len
, u8
*data
)
919 if (!halbtc_is_bt_coexist_available(btcoexist
))
921 btcoexist
->statistics
.cnt_dbg_ctrl
++;
924 void exhalbtc_stack_update_profile_info(void)
928 void exhalbtc_update_min_bt_rssi(char bt_rssi
)
930 struct btc_coexist
*btcoexist
= &gl_bt_coexist
;
932 if (!halbtc_is_bt_coexist_available(btcoexist
))
935 btcoexist
->stack_info
.min_bt_rssi
= bt_rssi
;
938 void exhalbtc_set_hci_version(u16 hci_version
)
940 struct btc_coexist
*btcoexist
= &gl_bt_coexist
;
942 if (!halbtc_is_bt_coexist_available(btcoexist
))
945 btcoexist
->stack_info
.hci_version
= hci_version
;
948 void exhalbtc_set_bt_patch_version(u16 bt_hci_version
, u16 bt_patch_version
)
950 struct btc_coexist
*btcoexist
= &gl_bt_coexist
;
952 if (!halbtc_is_bt_coexist_available(btcoexist
))
955 btcoexist
->bt_info
.bt_real_fw_ver
= bt_patch_version
;
956 btcoexist
->bt_info
.bt_hci_ver
= bt_hci_version
;
959 void exhalbtc_set_bt_exist(bool bt_exist
)
961 gl_bt_coexist
.board_info
.bt_exist
= bt_exist
;
964 void exhalbtc_set_chip_type(u8 chip_type
)
972 gl_bt_coexist
.board_info
.bt_chip_type
= BTC_CHIP_UNDEF
;
975 gl_bt_coexist
.board_info
.bt_chip_type
= BTC_CHIP_CSR_BC4
;
978 gl_bt_coexist
.board_info
.bt_chip_type
= BTC_CHIP_CSR_BC8
;
981 gl_bt_coexist
.board_info
.bt_chip_type
= BTC_CHIP_RTL8723A
;
984 gl_bt_coexist
.board_info
.bt_chip_type
= BTC_CHIP_RTL8821
;
987 gl_bt_coexist
.board_info
.bt_chip_type
= BTC_CHIP_RTL8723B
;
992 void exhalbtc_set_ant_num(u8 type
, u8 ant_num
)
994 if (BT_COEX_ANT_TYPE_PG
== type
) {
995 gl_bt_coexist
.board_info
.pg_ant_num
= ant_num
;
996 gl_bt_coexist
.board_info
.btdm_ant_num
= ant_num
;
997 } else if (BT_COEX_ANT_TYPE_ANTDIV
== type
) {
998 gl_bt_coexist
.board_info
.btdm_ant_num
= ant_num
;
1002 void exhalbtc_display_bt_coex_info(struct btc_coexist
*btcoexist
)
1004 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1005 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1006 if (!halbtc_is_bt_coexist_available(btcoexist
))
1009 if (rtlhal
->hw_type
== HARDWARE_TYPE_RTL8723BE
)
1010 ex_halbtc8723b2ant_display_coex_info(btcoexist
);