1 /******************************************************************************
3 * Copyright(c) 2009-2013 Realtek Corporation.
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 <linux/vmalloc.h>
27 #include <linux/module.h>
30 #include "halbt_precomp.h"
32 static struct rtl_btc_ops rtl_btc_operation = {
33 .btc_init_variables = rtl_btc_init_variables,
34 .btc_init_variables_wifi_only = rtl_btc_init_variables_wifi_only,
35 .btc_deinit_variables = rtl_btc_deinit_variables,
36 .btc_init_hal_vars = rtl_btc_init_hal_vars,
37 .btc_power_on_setting = rtl_btc_power_on_setting,
38 .btc_init_hw_config = rtl_btc_init_hw_config,
39 .btc_init_hw_config_wifi_only = rtl_btc_init_hw_config_wifi_only,
40 .btc_ips_notify = rtl_btc_ips_notify,
41 .btc_lps_notify = rtl_btc_lps_notify,
42 .btc_scan_notify = rtl_btc_scan_notify,
43 .btc_scan_notify_wifi_only = rtl_btc_scan_notify_wifi_only,
44 .btc_connect_notify = rtl_btc_connect_notify,
45 .btc_mediastatus_notify = rtl_btc_mediastatus_notify,
46 .btc_periodical = rtl_btc_periodical,
47 .btc_halt_notify = rtl_btc_halt_notify,
48 .btc_btinfo_notify = rtl_btc_btinfo_notify,
49 .btc_btmpinfo_notify = rtl_btc_btmpinfo_notify,
50 .btc_is_limited_dig = rtl_btc_is_limited_dig,
51 .btc_is_disable_edca_turbo = rtl_btc_is_disable_edca_turbo,
52 .btc_is_bt_disabled = rtl_btc_is_bt_disabled,
53 .btc_special_packet_notify = rtl_btc_special_packet_notify,
54 .btc_switch_band_notify = rtl_btc_switch_band_notify,
55 .btc_switch_band_notify_wifi_only = rtl_btc_switch_band_notify_wifionly,
56 .btc_record_pwr_mode = rtl_btc_record_pwr_mode,
57 .btc_get_lps_val = rtl_btc_get_lps_val,
58 .btc_get_rpwm_val = rtl_btc_get_rpwm_val,
59 .btc_is_bt_ctrl_lps = rtl_btc_is_bt_ctrl_lps,
60 .btc_is_bt_lps_on = rtl_btc_is_bt_lps_on,
61 .btc_get_ampdu_cfg = rtl_btc_get_ampdu_cfg,
62 .btc_display_bt_coex_info = rtl_btc_display_bt_coex_info,
65 void rtl_btc_display_bt_coex_info(struct rtl_priv *rtlpriv, struct seq_file *m)
67 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
70 seq_puts(m, "btc_coexist context is NULL!\n");
74 exhalbtc_display_bt_coex_info(btcoexist, m);
77 void rtl_btc_record_pwr_mode(struct rtl_priv *rtlpriv, u8 *buf, u8 len)
79 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
85 safe_len = sizeof(btcoexist->pwr_mode_val);
90 memcpy(btcoexist->pwr_mode_val, buf, safe_len);
93 u8 rtl_btc_get_lps_val(struct rtl_priv *rtlpriv)
95 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
100 return btcoexist->bt_info.lps_val;
103 u8 rtl_btc_get_rpwm_val(struct rtl_priv *rtlpriv)
105 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
110 return btcoexist->bt_info.rpwm_val;
113 bool rtl_btc_is_bt_ctrl_lps(struct rtl_priv *rtlpriv)
115 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
120 return btcoexist->bt_info.bt_ctrl_lps;
123 bool rtl_btc_is_bt_lps_on(struct rtl_priv *rtlpriv)
125 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
130 return btcoexist->bt_info.bt_lps_on;
133 void rtl_btc_get_ampdu_cfg(struct rtl_priv *rtlpriv, u8 *reject_agg,
134 u8 *ctrl_agg_size, u8 *agg_size)
136 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
140 *ctrl_agg_size = false;
145 *reject_agg = btcoexist->bt_info.reject_agg_pkt;
147 *ctrl_agg_size = btcoexist->bt_info.bt_ctrl_agg_buf_size;
149 *agg_size = btcoexist->bt_info.agg_buf_size;
152 static void rtl_btc_alloc_variable(struct rtl_priv *rtlpriv, bool wifi_only)
155 rtlpriv->btcoexist.wifi_only_context =
156 kzalloc(sizeof(struct wifi_only_cfg), GFP_KERNEL);
158 rtlpriv->btcoexist.btc_context =
159 kzalloc(sizeof(struct btc_coexist), GFP_KERNEL);
162 static void rtl_btc_free_variable(struct rtl_priv *rtlpriv)
164 kfree(rtlpriv->btcoexist.btc_context);
165 rtlpriv->btcoexist.btc_context = NULL;
167 kfree(rtlpriv->btcoexist.wifi_only_context);
168 rtlpriv->btcoexist.wifi_only_context = NULL;
171 void rtl_btc_init_variables(struct rtl_priv *rtlpriv)
173 rtl_btc_alloc_variable(rtlpriv, false);
175 exhalbtc_initlize_variables(rtlpriv);
176 exhalbtc_bind_bt_coex_withadapter(rtlpriv);
179 void rtl_btc_init_variables_wifi_only(struct rtl_priv *rtlpriv)
181 rtl_btc_alloc_variable(rtlpriv, true);
183 exhalbtc_initlize_variables_wifi_only(rtlpriv);
186 void rtl_btc_deinit_variables(struct rtl_priv *rtlpriv)
188 rtl_btc_free_variable(rtlpriv);
191 void rtl_btc_init_hal_vars(struct rtl_priv *rtlpriv)
193 /* move ant_num, bt_type and single_ant_path to
194 * exhalbtc_bind_bt_coex_withadapter()
198 void rtl_btc_power_on_setting(struct rtl_priv *rtlpriv)
200 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
205 exhalbtc_power_on_setting(btcoexist);
208 void rtl_btc_init_hw_config(struct rtl_priv *rtlpriv)
210 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
214 bt_exist = rtl_get_hwpg_bt_exist(rtlpriv);
215 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
216 "%s, bt_exist is %d\n", __func__, bt_exist);
221 exhalbtc_init_hw_config(btcoexist, !bt_exist);
222 exhalbtc_init_coex_dm(btcoexist);
225 void rtl_btc_init_hw_config_wifi_only(struct rtl_priv *rtlpriv)
227 struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
232 exhalbtc_init_hw_config_wifi_only(wifionly_cfg);
235 void rtl_btc_ips_notify(struct rtl_priv *rtlpriv, u8 type)
237 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
242 exhalbtc_ips_notify(btcoexist, type);
245 /* In some situation, it doesn't scan after leaving IPS, and
246 * this will cause btcoex in wrong state.
248 exhalbtc_scan_notify(btcoexist, 1);
249 exhalbtc_scan_notify(btcoexist, 0);
253 void rtl_btc_lps_notify(struct rtl_priv *rtlpriv, u8 type)
255 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
260 exhalbtc_lps_notify(btcoexist, type);
263 void rtl_btc_scan_notify(struct rtl_priv *rtlpriv, u8 scantype)
265 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
270 exhalbtc_scan_notify(btcoexist, scantype);
273 void rtl_btc_scan_notify_wifi_only(struct rtl_priv *rtlpriv, u8 scantype)
275 struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
276 struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
277 u8 is_5g = (rtlhal->current_bandtype == BAND_ON_5G);
282 exhalbtc_scan_notify_wifi_only(wifionly_cfg, is_5g);
285 void rtl_btc_connect_notify(struct rtl_priv *rtlpriv, u8 action)
287 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
292 exhalbtc_connect_notify(btcoexist, action);
295 void rtl_btc_mediastatus_notify(struct rtl_priv *rtlpriv,
296 enum rt_media_status mstatus)
298 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
303 exhalbtc_mediastatus_notify(btcoexist, mstatus);
306 void rtl_btc_periodical(struct rtl_priv *rtlpriv)
308 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
313 /*rtl_bt_dm_monitor();*/
314 exhalbtc_periodical(btcoexist);
317 void rtl_btc_halt_notify(struct rtl_priv *rtlpriv)
319 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
324 exhalbtc_halt_notify(btcoexist);
327 void rtl_btc_btinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
329 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
334 exhalbtc_bt_info_notify(btcoexist, tmp_buf, length);
337 void rtl_btc_btmpinfo_notify(struct rtl_priv *rtlpriv, u8 *tmp_buf, u8 length)
339 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
348 if ((length < 4) || (!tmp_buf))
352 /* not response from BT FW then exit*/
353 if (extid != 1) /* C2H_TRIG_BY_BT_FW = 1 */
356 len = tmp_buf[1] >> 4;
357 seq = tmp_buf[2] >> 4;
360 /* BT Firmware version response */
362 case BT_SEQ_GET_BT_VERSION:
363 bt_real_fw_ver = tmp_buf[3] | (tmp_buf[4] << 8);
364 bt_fw_ver = tmp_buf[5];
366 btcoexist->bt_info.bt_real_fw_ver = bt_real_fw_ver;
367 btcoexist->bt_info.bt_fw_ver = bt_fw_ver;
369 case BT_SEQ_GET_AFH_MAP_L:
370 btcoexist->bt_info.afh_map_l = le32_to_cpu(*(__le32 *)data);
372 case BT_SEQ_GET_AFH_MAP_M:
373 btcoexist->bt_info.afh_map_m = le32_to_cpu(*(__le32 *)data);
375 case BT_SEQ_GET_AFH_MAP_H:
376 btcoexist->bt_info.afh_map_h = le16_to_cpu(*(__le16 *)data);
378 case BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE:
379 btcoexist->bt_info.bt_supported_feature = tmp_buf[3] |
382 case BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION:
383 btcoexist->bt_info.bt_supported_version = tmp_buf[3] |
386 case BT_SEQ_GET_BT_ANT_DET_VAL:
387 btcoexist->bt_info.bt_ant_det_val = tmp_buf[3];
389 case BT_SEQ_GET_BT_BLE_SCAN_PARA:
390 btcoexist->bt_info.bt_ble_scan_para = tmp_buf[3] |
395 case BT_SEQ_GET_BT_BLE_SCAN_TYPE:
396 btcoexist->bt_info.bt_ble_scan_type = tmp_buf[3];
398 case BT_SEQ_GET_BT_DEVICE_INFO:
399 btcoexist->bt_info.bt_device_info =
400 le32_to_cpu(*(__le32 *)data);
402 case BT_OP_GET_BT_FORBIDDEN_SLOT_VAL:
403 btcoexist->bt_info.bt_forb_slot_val =
404 le32_to_cpu(*(__le32 *)data);
408 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
409 "btmpinfo complete req_num=%d\n", seq);
411 complete(&btcoexist->bt_mp_comp);
414 bool rtl_btc_is_limited_dig(struct rtl_priv *rtlpriv)
416 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
421 return btcoexist->bt_info.limited_dig;
424 bool rtl_btc_is_disable_edca_turbo(struct rtl_priv *rtlpriv)
426 bool bt_change_edca = false;
428 u32 edca_bt_hs_uplink = 0x5ea42b, edca_bt_hs_downlink = 0x5ea42b;
430 u32 edca_addr = 0x504;
432 cur_edca_val = rtl_read_dword(rtlpriv, edca_addr);
433 if (halbtc_is_wifi_uplink(rtlpriv)) {
434 if (cur_edca_val != edca_bt_hs_uplink) {
435 edca_hs = edca_bt_hs_uplink;
436 bt_change_edca = true;
439 if (cur_edca_val != edca_bt_hs_downlink) {
440 edca_hs = edca_bt_hs_downlink;
441 bt_change_edca = true;
446 rtl_write_dword(rtlpriv, edca_addr, edca_hs);
451 bool rtl_btc_is_bt_disabled(struct rtl_priv *rtlpriv)
453 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
458 /* It seems 'bt_disabled' is never be initialized or set. */
459 if (btcoexist->bt_info.bt_disabled)
465 void rtl_btc_special_packet_notify(struct rtl_priv *rtlpriv, u8 pkt_type)
467 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
472 return exhalbtc_special_packet_notify(btcoexist, pkt_type);
475 void rtl_btc_switch_band_notify(struct rtl_priv *rtlpriv, u8 band_type,
478 struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
479 u8 type = BTC_NOT_SWITCH;
487 type = BTC_SWITCH_TO_24G;
489 type = BTC_SWITCH_TO_24G_NOFORSCAN;
493 type = BTC_SWITCH_TO_5G;
497 if (type != BTC_NOT_SWITCH)
498 exhalbtc_switch_band_notify(btcoexist, type);
501 void rtl_btc_switch_band_notify_wifionly(struct rtl_priv *rtlpriv, u8 band_type,
504 struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
505 u8 is_5g = (band_type == BAND_ON_5G);
510 exhalbtc_switch_band_notify_wifi_only(wifionly_cfg, is_5g);
513 struct rtl_btc_ops *rtl_btc_get_ops_pointer(void)
515 return &rtl_btc_operation;
517 EXPORT_SYMBOL(rtl_btc_get_ops_pointer);
520 enum rt_media_status mgnt_link_status_query(struct ieee80211_hw *hw)
522 struct rtl_priv *rtlpriv = rtl_priv(hw);
523 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
524 enum rt_media_status m_status = RT_MEDIA_DISCONNECT;
526 u8 bibss = (mac->opmode == NL80211_IFTYPE_ADHOC) ? 1 : 0;
528 if (bibss || rtlpriv->mac80211.link_state >= MAC80211_LINKED)
529 m_status = RT_MEDIA_CONNECT;
534 u8 rtl_get_hwpg_bt_exist(struct rtl_priv *rtlpriv)
536 return rtlpriv->btcoexist.btc_info.btcoexist;
539 MODULE_AUTHOR("Page He <page_he@realsil.com.cn>");
540 MODULE_AUTHOR("Realtek WlanFAE <wlanfae@realtek.com>");
541 MODULE_AUTHOR("Larry Finger <Larry.FInger@lwfinger.net>");
542 MODULE_LICENSE("GPL");
543 MODULE_DESCRIPTION("Realtek 802.11n PCI wireless core");
545 static int __init rtl_btcoexist_module_init(void)
550 static void __exit rtl_btcoexist_module_exit(void)
555 module_init(rtl_btcoexist_module_init);
556 module_exit(rtl_btcoexist_module_exit);