halbtcoutsrc.c 25 KB

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