halbtcoutsrc.c 26 KB

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