halbtcoutsrc.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  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. #include "halbt_precomp.h"
  26. /***********************************************
  27. * Global variables
  28. ***********************************************/
  29. struct btc_coexist gl_bt_coexist;
  30. u32 btc_dbg_type[BTC_MSG_MAX];
  31. /***************************************************
  32. * Debug related function
  33. ***************************************************/
  34. static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
  35. {
  36. if (!btcoexist->binded || NULL == btcoexist->adapter)
  37. return false;
  38. return true;
  39. }
  40. static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
  41. {
  42. if (rtlpriv->link_info.busytraffic)
  43. return true;
  44. else
  45. return false;
  46. }
  47. static void halbtc_dbg_init(void)
  48. {
  49. u8 i;
  50. for (i = 0; i < BTC_MSG_MAX; i++)
  51. btc_dbg_type[i] = 0;
  52. btc_dbg_type[BTC_MSG_INTERFACE] =
  53. /* INTF_INIT | */
  54. /* INTF_NOTIFY | */
  55. 0;
  56. btc_dbg_type[BTC_MSG_ALGORITHM] =
  57. /* ALGO_BT_RSSI_STATE | */
  58. /* ALGO_WIFI_RSSI_STATE | */
  59. /* ALGO_BT_MONITOR | */
  60. /* ALGO_TRACE | */
  61. /* ALGO_TRACE_FW | */
  62. /* ALGO_TRACE_FW_DETAIL | */
  63. /* ALGO_TRACE_FW_EXEC | */
  64. /* ALGO_TRACE_SW | */
  65. /* ALGO_TRACE_SW_DETAIL | */
  66. /* ALGO_TRACE_SW_EXEC | */
  67. 0;
  68. }
  69. static bool halbtc_is_bt40(struct rtl_priv *adapter)
  70. {
  71. struct rtl_priv *rtlpriv = adapter;
  72. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  73. bool is_ht40 = true;
  74. enum ht_channel_width bw = rtlphy->current_chan_bw;
  75. if (bw == HT_CHANNEL_WIDTH_20)
  76. is_ht40 = false;
  77. else if (bw == HT_CHANNEL_WIDTH_20_40)
  78. is_ht40 = true;
  79. return is_ht40;
  80. }
  81. static bool halbtc_legacy(struct rtl_priv *adapter)
  82. {
  83. struct rtl_priv *rtlpriv = adapter;
  84. struct rtl_mac *mac = rtl_mac(rtlpriv);
  85. bool is_legacy = false;
  86. if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
  87. is_legacy = true;
  88. return is_legacy;
  89. }
  90. bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
  91. {
  92. struct rtl_priv *rtlpriv = adapter;
  93. if (rtlpriv->link_info.tx_busy_traffic)
  94. return true;
  95. else
  96. return false;
  97. }
  98. static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
  99. {
  100. struct rtl_priv *rtlpriv =
  101. (struct rtl_priv *)btcoexist->adapter;
  102. u32 wifi_bw = BTC_WIFI_BW_HT20;
  103. if (halbtc_is_bt40(rtlpriv)) {
  104. wifi_bw = BTC_WIFI_BW_HT40;
  105. } else {
  106. if (halbtc_legacy(rtlpriv))
  107. wifi_bw = BTC_WIFI_BW_LEGACY;
  108. else
  109. wifi_bw = BTC_WIFI_BW_HT20;
  110. }
  111. return wifi_bw;
  112. }
  113. static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
  114. {
  115. struct rtl_priv *rtlpriv = btcoexist->adapter;
  116. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  117. u8 chnl = 1;
  118. if (rtlphy->current_channel != 0)
  119. chnl = rtlphy->current_channel;
  120. BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE,
  121. "static halbtc_get_wifi_central_chnl:%d\n", chnl);
  122. return chnl;
  123. }
  124. static void halbtc_leave_lps(struct btc_coexist *btcoexist)
  125. {
  126. struct rtl_priv *rtlpriv;
  127. struct rtl_ps_ctl *ppsc;
  128. bool ap_enable = false;
  129. rtlpriv = btcoexist->adapter;
  130. ppsc = rtl_psc(rtlpriv);
  131. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  132. &ap_enable);
  133. if (ap_enable) {
  134. pr_info("halbtc_leave_lps()<--dont leave lps under AP mode\n");
  135. return;
  136. }
  137. btcoexist->bt_info.bt_ctrl_lps = true;
  138. btcoexist->bt_info.bt_lps_on = false;
  139. }
  140. static void halbtc_enter_lps(struct btc_coexist *btcoexist)
  141. {
  142. struct rtl_priv *rtlpriv;
  143. struct rtl_ps_ctl *ppsc;
  144. bool ap_enable = false;
  145. rtlpriv = btcoexist->adapter;
  146. ppsc = rtl_psc(rtlpriv);
  147. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  148. &ap_enable);
  149. if (ap_enable) {
  150. pr_info("halbtc_enter_lps()<--dont enter lps under AP mode\n");
  151. return;
  152. }
  153. btcoexist->bt_info.bt_ctrl_lps = true;
  154. btcoexist->bt_info.bt_lps_on = false;
  155. }
  156. static void halbtc_normal_lps(struct btc_coexist *btcoexist)
  157. {
  158. if (btcoexist->bt_info.bt_ctrl_lps) {
  159. btcoexist->bt_info.bt_lps_on = false;
  160. btcoexist->bt_info.bt_ctrl_lps = false;
  161. }
  162. }
  163. static void halbtc_leave_low_power(void)
  164. {
  165. }
  166. static void halbtc_nomal_low_power(void)
  167. {
  168. }
  169. static void halbtc_disable_low_power(void)
  170. {
  171. }
  172. static void halbtc_aggregation_check(void)
  173. {
  174. }
  175. static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
  176. {
  177. return 0;
  178. }
  179. static s32 halbtc_get_wifi_rssi(struct rtl_priv *adapter)
  180. {
  181. struct rtl_priv *rtlpriv = adapter;
  182. s32 undec_sm_pwdb = 0;
  183. if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
  184. undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
  185. else /* associated entry pwdb */
  186. undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
  187. return undec_sm_pwdb;
  188. }
  189. static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
  190. {
  191. struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
  192. struct rtl_priv *rtlpriv = btcoexist->adapter;
  193. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  194. struct rtl_mac *mac = rtl_mac(rtlpriv);
  195. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  196. bool *bool_tmp = (bool *)out_buf;
  197. int *s32_tmp = (int *)out_buf;
  198. u32 *u32_tmp = (u32 *)out_buf;
  199. u8 *u8_tmp = (u8 *)out_buf;
  200. bool tmp = false;
  201. if (!halbtc_is_bt_coexist_available(btcoexist))
  202. return false;
  203. switch (get_type) {
  204. case BTC_GET_BL_HS_OPERATION:
  205. *bool_tmp = false;
  206. break;
  207. case BTC_GET_BL_HS_CONNECTING:
  208. *bool_tmp = false;
  209. break;
  210. case BTC_GET_BL_WIFI_CONNECTED:
  211. if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
  212. tmp = true;
  213. *bool_tmp = tmp;
  214. break;
  215. case BTC_GET_BL_WIFI_BUSY:
  216. if (halbtc_is_wifi_busy(rtlpriv))
  217. *bool_tmp = true;
  218. else
  219. *bool_tmp = false;
  220. break;
  221. case BTC_GET_BL_WIFI_SCAN:
  222. if (mac->act_scanning)
  223. *bool_tmp = true;
  224. else
  225. *bool_tmp = false;
  226. break;
  227. case BTC_GET_BL_WIFI_LINK:
  228. if (mac->link_state == MAC80211_LINKING)
  229. *bool_tmp = true;
  230. else
  231. *bool_tmp = false;
  232. break;
  233. case BTC_GET_BL_WIFI_ROAM: /*TODO*/
  234. if (mac->link_state == MAC80211_LINKING)
  235. *bool_tmp = true;
  236. else
  237. *bool_tmp = false;
  238. break;
  239. case BTC_GET_BL_WIFI_4_WAY_PROGRESS: /*TODO*/
  240. *bool_tmp = false;
  241. break;
  242. case BTC_GET_BL_WIFI_UNDER_5G:
  243. *bool_tmp = false; /*TODO*/
  244. case BTC_GET_BL_WIFI_DHCP: /*TODO*/
  245. break;
  246. case BTC_GET_BL_WIFI_SOFTAP_IDLE:
  247. *bool_tmp = true;
  248. break;
  249. case BTC_GET_BL_WIFI_SOFTAP_LINKING:
  250. *bool_tmp = false;
  251. break;
  252. case BTC_GET_BL_WIFI_IN_EARLY_SUSPEND:
  253. *bool_tmp = false;
  254. break;
  255. case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
  256. *bool_tmp = false;
  257. break;
  258. case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
  259. if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
  260. *bool_tmp = false;
  261. else
  262. *bool_tmp = true;
  263. break;
  264. case BTC_GET_BL_WIFI_UNDER_B_MODE:
  265. *bool_tmp = false; /*TODO*/
  266. break;
  267. case BTC_GET_BL_EXT_SWITCH:
  268. *bool_tmp = false;
  269. break;
  270. case BTC_GET_S4_WIFI_RSSI:
  271. *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
  272. break;
  273. case BTC_GET_S4_HS_RSSI: /*TODO*/
  274. *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
  275. break;
  276. case BTC_GET_U4_WIFI_BW:
  277. *u32_tmp = halbtc_get_wifi_bw(btcoexist);
  278. break;
  279. case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
  280. if (halbtc_is_wifi_uplink(rtlpriv))
  281. *u32_tmp = BTC_WIFI_TRAFFIC_TX;
  282. else
  283. *u32_tmp = BTC_WIFI_TRAFFIC_RX;
  284. break;
  285. case BTC_GET_U4_WIFI_FW_VER:
  286. *u32_tmp = rtlhal->fw_version;
  287. break;
  288. case BTC_GET_U4_BT_PATCH_VER:
  289. *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
  290. break;
  291. case BTC_GET_U1_WIFI_DOT11_CHNL:
  292. *u8_tmp = rtlphy->current_channel;
  293. break;
  294. case BTC_GET_U1_WIFI_CENTRAL_CHNL:
  295. *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
  296. break;
  297. case BTC_GET_U1_WIFI_HS_CHNL:
  298. *u8_tmp = 1;/*BT_OperateChnl(rtlpriv);*/
  299. break;
  300. case BTC_GET_U1_MAC_PHY_MODE:
  301. *u8_tmp = BTC_MP_UNKNOWN;
  302. break;
  303. /************* 1Ant **************/
  304. case BTC_GET_U1_LPS_MODE:
  305. *u8_tmp = btcoexist->pwr_mode_val[0];
  306. break;
  307. default:
  308. break;
  309. }
  310. return true;
  311. }
  312. static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
  313. {
  314. struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
  315. bool *bool_tmp = (bool *)in_buf;
  316. u8 *u8_tmp = (u8 *)in_buf;
  317. u32 *u32_tmp = (u32 *)in_buf;
  318. if (!halbtc_is_bt_coexist_available(btcoexist))
  319. return false;
  320. switch (set_type) {
  321. /* set some bool type variables. */
  322. case BTC_SET_BL_BT_DISABLE:
  323. btcoexist->bt_info.bt_disabled = *bool_tmp;
  324. break;
  325. case BTC_SET_BL_BT_TRAFFIC_BUSY:
  326. btcoexist->bt_info.bt_busy = *bool_tmp;
  327. break;
  328. case BTC_SET_BL_BT_LIMITED_DIG:
  329. btcoexist->bt_info.limited_dig = *bool_tmp;
  330. break;
  331. case BTC_SET_BL_FORCE_TO_ROAM:
  332. btcoexist->bt_info.force_to_roam = *bool_tmp;
  333. break;
  334. case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
  335. btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
  336. break;
  337. case BTC_SET_BL_BT_CTRL_AGG_SIZE:
  338. btcoexist->bt_info.bt_ctrl_buf_size = *bool_tmp;
  339. break;
  340. case BTC_SET_BL_INC_SCAN_DEV_NUM:
  341. btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
  342. break;
  343. /* set some u1Byte type variables. */
  344. case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
  345. btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
  346. break;
  347. case BTC_SET_U1_AGG_BUF_SIZE:
  348. btcoexist->bt_info.agg_buf_size = *u8_tmp;
  349. break;
  350. /* the following are some action which will be triggered */
  351. case BTC_SET_ACT_GET_BT_RSSI:
  352. /*BTHCI_SendGetBtRssiEvent(rtlpriv);*/
  353. break;
  354. case BTC_SET_ACT_AGGREGATE_CTRL:
  355. halbtc_aggregation_check();
  356. break;
  357. /* 1Ant */
  358. case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
  359. btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
  360. break;
  361. case BTC_SET_UI_SCAN_SIG_COMPENSATION:
  362. /* rtlpriv->mlmepriv.scan_compensation = *u8_tmp; */
  363. break;
  364. case BTC_SET_U1_1ANT_LPS:
  365. btcoexist->bt_info.lps_val = *u8_tmp;
  366. break;
  367. case BTC_SET_U1_1ANT_RPWM:
  368. btcoexist->bt_info.rpwm_val = *u8_tmp;
  369. break;
  370. /* the following are some action which will be triggered */
  371. case BTC_SET_ACT_LEAVE_LPS:
  372. halbtc_leave_lps(btcoexist);
  373. break;
  374. case BTC_SET_ACT_ENTER_LPS:
  375. halbtc_enter_lps(btcoexist);
  376. break;
  377. case BTC_SET_ACT_NORMAL_LPS:
  378. halbtc_normal_lps(btcoexist);
  379. break;
  380. case BTC_SET_ACT_DISABLE_LOW_POWER:
  381. halbtc_disable_low_power();
  382. break;
  383. case BTC_SET_ACT_UPDATE_ra_mask:
  384. btcoexist->bt_info.ra_mask = *u32_tmp;
  385. break;
  386. case BTC_SET_ACT_SEND_MIMO_PS:
  387. break;
  388. case BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT:
  389. btcoexist->bt_info.force_exec_pwr_cmd_cnt++;
  390. break;
  391. case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
  392. break;
  393. case BTC_SET_ACT_CTRL_BT_COEX:
  394. break;
  395. default:
  396. break;
  397. }
  398. return true;
  399. }
  400. static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist)
  401. {
  402. }
  403. static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist)
  404. {
  405. }
  406. static void halbtc_display_bt_fw_info(struct btc_coexist *btcoexist)
  407. {
  408. }
  409. static void halbtc_display_fw_pwr_mode_cmd(struct btc_coexist *btcoexist)
  410. {
  411. }
  412. /************************************************************
  413. * IO related function
  414. ************************************************************/
  415. static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
  416. {
  417. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  418. struct rtl_priv *rtlpriv = btcoexist->adapter;
  419. return rtl_read_byte(rtlpriv, reg_addr);
  420. }
  421. static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
  422. {
  423. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  424. struct rtl_priv *rtlpriv = btcoexist->adapter;
  425. return rtl_read_word(rtlpriv, reg_addr);
  426. }
  427. static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
  428. {
  429. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  430. struct rtl_priv *rtlpriv = btcoexist->adapter;
  431. return rtl_read_dword(rtlpriv, reg_addr);
  432. }
  433. static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
  434. {
  435. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  436. struct rtl_priv *rtlpriv = btcoexist->adapter;
  437. rtl_write_byte(rtlpriv, reg_addr, data);
  438. }
  439. static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
  440. u32 bit_mask, u8 data)
  441. {
  442. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  443. struct rtl_priv *rtlpriv = btcoexist->adapter;
  444. u8 original_value, bit_shift = 0;
  445. u8 i;
  446. if (bit_mask != MASKDWORD) {/*if not "double word" write*/
  447. original_value = rtl_read_byte(rtlpriv, reg_addr);
  448. for (i = 0; i <= 7; i++) {
  449. if ((bit_mask>>i) & 0x1)
  450. break;
  451. }
  452. bit_shift = i;
  453. data = (original_value & (~bit_mask)) |
  454. ((data << bit_shift) & bit_mask);
  455. }
  456. rtl_write_byte(rtlpriv, reg_addr, data);
  457. }
  458. static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
  459. {
  460. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  461. struct rtl_priv *rtlpriv = btcoexist->adapter;
  462. rtl_write_word(rtlpriv, reg_addr, data);
  463. }
  464. static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
  465. {
  466. struct btc_coexist *btcoexist =
  467. (struct btc_coexist *)bt_context;
  468. struct rtl_priv *rtlpriv = btcoexist->adapter;
  469. rtl_write_dword(rtlpriv, reg_addr, data);
  470. }
  471. static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
  472. u32 data)
  473. {
  474. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  475. struct rtl_priv *rtlpriv = btcoexist->adapter;
  476. rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
  477. }
  478. static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
  479. {
  480. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  481. struct rtl_priv *rtlpriv = btcoexist->adapter;
  482. return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
  483. }
  484. static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
  485. u32 bit_mask, u32 data)
  486. {
  487. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  488. struct rtl_priv *rtlpriv = btcoexist->adapter;
  489. rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
  490. }
  491. static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
  492. u32 bit_mask)
  493. {
  494. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  495. struct rtl_priv *rtlpriv = btcoexist->adapter;
  496. return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
  497. }
  498. static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
  499. u32 cmd_len, u8 *cmd_buf)
  500. {
  501. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  502. struct rtl_priv *rtlpriv = btcoexist->adapter;
  503. rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
  504. cmd_len, cmd_buf);
  505. }
  506. static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type)
  507. {
  508. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  509. switch (disp_type) {
  510. case BTC_DBG_DISP_COEX_STATISTICS:
  511. halbtc_display_coex_statistics(btcoexist);
  512. break;
  513. case BTC_DBG_DISP_BT_LINK_INFO:
  514. halbtc_display_bt_link_info(btcoexist);
  515. break;
  516. case BTC_DBG_DISP_BT_FW_VER:
  517. halbtc_display_bt_fw_info(btcoexist);
  518. break;
  519. case BTC_DBG_DISP_FW_PWR_MODE_CMD:
  520. halbtc_display_fw_pwr_mode_cmd(btcoexist);
  521. break;
  522. default:
  523. break;
  524. }
  525. }
  526. /*****************************************************************
  527. * Extern functions called by other module
  528. *****************************************************************/
  529. bool exhalbtc_initlize_variables(struct rtl_priv *adapter)
  530. {
  531. struct btc_coexist *btcoexist = &gl_bt_coexist;
  532. btcoexist->statistics.cnt_bind++;
  533. halbtc_dbg_init();
  534. if (btcoexist->binded)
  535. return false;
  536. else
  537. btcoexist->binded = true;
  538. btcoexist->chip_interface = BTC_INTF_UNKNOWN;
  539. if (NULL == btcoexist->adapter)
  540. btcoexist->adapter = adapter;
  541. btcoexist->stack_info.profile_notified = false;
  542. btcoexist->btc_read_1byte = halbtc_read_1byte;
  543. btcoexist->btc_write_1byte = halbtc_write_1byte;
  544. btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
  545. btcoexist->btc_read_2byte = halbtc_read_2byte;
  546. btcoexist->btc_write_2byte = halbtc_write_2byte;
  547. btcoexist->btc_read_4byte = halbtc_read_4byte;
  548. btcoexist->btc_write_4byte = halbtc_write_4byte;
  549. btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
  550. btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
  551. btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
  552. btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
  553. btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
  554. btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
  555. btcoexist->btc_get = halbtc_get;
  556. btcoexist->btc_set = halbtc_set;
  557. btcoexist->bt_info.bt_ctrl_buf_size = false;
  558. btcoexist->bt_info.agg_buf_size = 5;
  559. btcoexist->bt_info.increase_scan_dev_num = false;
  560. return true;
  561. }
  562. void exhalbtc_init_hw_config(struct btc_coexist *btcoexist)
  563. {
  564. struct rtl_priv *rtlpriv = btcoexist->adapter;
  565. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  566. if (!halbtc_is_bt_coexist_available(btcoexist))
  567. return;
  568. btcoexist->statistics.cnt_init_hw_config++;
  569. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  570. ex_btc8723b2ant_init_hwconfig(btcoexist);
  571. }
  572. void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
  573. {
  574. struct rtl_priv *rtlpriv = btcoexist->adapter;
  575. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  576. if (!halbtc_is_bt_coexist_available(btcoexist))
  577. return;
  578. btcoexist->statistics.cnt_init_coex_dm++;
  579. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  580. ex_btc8723b2ant_init_coex_dm(btcoexist);
  581. btcoexist->initilized = true;
  582. }
  583. void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
  584. {
  585. struct rtl_priv *rtlpriv = btcoexist->adapter;
  586. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  587. u8 ips_type;
  588. if (!halbtc_is_bt_coexist_available(btcoexist))
  589. return;
  590. btcoexist->statistics.cnt_ips_notify++;
  591. if (btcoexist->manual_control)
  592. return;
  593. if (ERFOFF == type)
  594. ips_type = BTC_IPS_ENTER;
  595. else
  596. ips_type = BTC_IPS_LEAVE;
  597. halbtc_leave_low_power();
  598. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  599. ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
  600. halbtc_nomal_low_power();
  601. }
  602. void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
  603. {
  604. struct rtl_priv *rtlpriv = btcoexist->adapter;
  605. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  606. u8 lps_type;
  607. if (!halbtc_is_bt_coexist_available(btcoexist))
  608. return;
  609. btcoexist->statistics.cnt_lps_notify++;
  610. if (btcoexist->manual_control)
  611. return;
  612. if (EACTIVE == type)
  613. lps_type = BTC_LPS_DISABLE;
  614. else
  615. lps_type = BTC_LPS_ENABLE;
  616. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  617. ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
  618. }
  619. void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
  620. {
  621. struct rtl_priv *rtlpriv = btcoexist->adapter;
  622. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  623. u8 scan_type;
  624. if (!halbtc_is_bt_coexist_available(btcoexist))
  625. return;
  626. btcoexist->statistics.cnt_scan_notify++;
  627. if (btcoexist->manual_control)
  628. return;
  629. if (type)
  630. scan_type = BTC_SCAN_START;
  631. else
  632. scan_type = BTC_SCAN_FINISH;
  633. halbtc_leave_low_power();
  634. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  635. ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
  636. halbtc_nomal_low_power();
  637. }
  638. void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
  639. {
  640. struct rtl_priv *rtlpriv = btcoexist->adapter;
  641. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  642. u8 asso_type;
  643. if (!halbtc_is_bt_coexist_available(btcoexist))
  644. return;
  645. btcoexist->statistics.cnt_connect_notify++;
  646. if (btcoexist->manual_control)
  647. return;
  648. if (action)
  649. asso_type = BTC_ASSOCIATE_START;
  650. else
  651. asso_type = BTC_ASSOCIATE_FINISH;
  652. halbtc_leave_low_power();
  653. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  654. ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
  655. }
  656. void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
  657. enum rt_media_status media_status)
  658. {
  659. u8 status;
  660. if (!halbtc_is_bt_coexist_available(btcoexist))
  661. return;
  662. btcoexist->statistics.cnt_media_status_notify++;
  663. if (btcoexist->manual_control)
  664. return;
  665. if (RT_MEDIA_CONNECT == media_status)
  666. status = BTC_MEDIA_CONNECT;
  667. else
  668. status = BTC_MEDIA_DISCONNECT;
  669. halbtc_leave_low_power();
  670. halbtc_nomal_low_power();
  671. }
  672. void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
  673. {
  674. struct rtl_priv *rtlpriv = btcoexist->adapter;
  675. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  676. u8 packet_type;
  677. if (!halbtc_is_bt_coexist_available(btcoexist))
  678. return;
  679. btcoexist->statistics.cnt_special_packet_notify++;
  680. if (btcoexist->manual_control)
  681. return;
  682. packet_type = BTC_PACKET_DHCP;
  683. halbtc_leave_low_power();
  684. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  685. ex_btc8723b2ant_special_packet_notify(btcoexist,
  686. packet_type);
  687. halbtc_nomal_low_power();
  688. }
  689. void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
  690. u8 *tmp_buf, u8 length)
  691. {
  692. struct rtl_priv *rtlpriv = btcoexist->adapter;
  693. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  694. if (!halbtc_is_bt_coexist_available(btcoexist))
  695. return;
  696. btcoexist->statistics.cnt_bt_info_notify++;
  697. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  698. ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf, length);
  699. }
  700. void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
  701. {
  702. u8 stack_op_type;
  703. if (!halbtc_is_bt_coexist_available(btcoexist))
  704. return;
  705. btcoexist->statistics.cnt_stack_operation_notify++;
  706. if (btcoexist->manual_control)
  707. return;
  708. stack_op_type = BTC_STACK_OP_NONE;
  709. halbtc_leave_low_power();
  710. halbtc_nomal_low_power();
  711. }
  712. void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
  713. {
  714. struct rtl_priv *rtlpriv = btcoexist->adapter;
  715. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  716. if (!halbtc_is_bt_coexist_available(btcoexist))
  717. return;
  718. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  719. ex_btc8723b2ant_halt_notify(btcoexist);
  720. }
  721. void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
  722. {
  723. if (!halbtc_is_bt_coexist_available(btcoexist))
  724. return;
  725. }
  726. void exhalbtc_periodical(struct btc_coexist *btcoexist)
  727. {
  728. struct rtl_priv *rtlpriv = btcoexist->adapter;
  729. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  730. if (!halbtc_is_bt_coexist_available(btcoexist))
  731. return;
  732. btcoexist->statistics.cnt_periodical++;
  733. halbtc_leave_low_power();
  734. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  735. ex_btc8723b2ant_periodical(btcoexist);
  736. halbtc_nomal_low_power();
  737. }
  738. void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
  739. u8 code, u8 len, u8 *data)
  740. {
  741. if (!halbtc_is_bt_coexist_available(btcoexist))
  742. return;
  743. btcoexist->statistics.cnt_dbg_ctrl++;
  744. }
  745. void exhalbtc_stack_update_profile_info(void)
  746. {
  747. }
  748. void exhalbtc_update_min_bt_rssi(char bt_rssi)
  749. {
  750. struct btc_coexist *btcoexist = &gl_bt_coexist;
  751. if (!halbtc_is_bt_coexist_available(btcoexist))
  752. return;
  753. btcoexist->stack_info.min_bt_rssi = bt_rssi;
  754. }
  755. void exhalbtc_set_hci_version(u16 hci_version)
  756. {
  757. struct btc_coexist *btcoexist = &gl_bt_coexist;
  758. if (!halbtc_is_bt_coexist_available(btcoexist))
  759. return;
  760. btcoexist->stack_info.hci_version = hci_version;
  761. }
  762. void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version)
  763. {
  764. struct btc_coexist *btcoexist = &gl_bt_coexist;
  765. if (!halbtc_is_bt_coexist_available(btcoexist))
  766. return;
  767. btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
  768. btcoexist->bt_info.bt_hci_ver = bt_hci_version;
  769. }
  770. void exhalbtc_set_bt_exist(bool bt_exist)
  771. {
  772. gl_bt_coexist.board_info.bt_exist = bt_exist;
  773. }
  774. void exhalbtc_set_chip_type(u8 chip_type)
  775. {
  776. switch (chip_type) {
  777. default:
  778. case BT_2WIRE:
  779. case BT_ISSC_3WIRE:
  780. case BT_ACCEL:
  781. case BT_RTL8756:
  782. gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
  783. break;
  784. case BT_CSR_BC4:
  785. gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
  786. break;
  787. case BT_CSR_BC8:
  788. gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
  789. break;
  790. case BT_RTL8723A:
  791. gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
  792. break;
  793. case BT_RTL8821A:
  794. gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
  795. break;
  796. case BT_RTL8723B:
  797. gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
  798. break;
  799. }
  800. }
  801. void exhalbtc_set_ant_num(u8 type, u8 ant_num)
  802. {
  803. if (BT_COEX_ANT_TYPE_PG == type) {
  804. gl_bt_coexist.board_info.pg_ant_num = ant_num;
  805. gl_bt_coexist.board_info.btdm_ant_num = ant_num;
  806. } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
  807. gl_bt_coexist.board_info.btdm_ant_num = ant_num;
  808. }
  809. }
  810. void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist)
  811. {
  812. struct rtl_priv *rtlpriv = btcoexist->adapter;
  813. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  814. if (!halbtc_is_bt_coexist_available(btcoexist))
  815. return;
  816. if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE)
  817. ex_btc8723b2ant_display_coex_info(btcoexist);
  818. }