halbtcoutsrc.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048
  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. * Debug related function
  28. ***************************************************/
  29. static const char *const gl_btc_wifi_bw_string[] = {
  30. "11bg",
  31. "HT20",
  32. "HT40",
  33. "HT80",
  34. "HT160"
  35. };
  36. static const char *const gl_btc_wifi_freq_string[] = {
  37. "2.4G",
  38. "5G"
  39. };
  40. static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
  41. {
  42. if (!btcoexist->binded || NULL == btcoexist->adapter)
  43. return false;
  44. return true;
  45. }
  46. static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
  47. {
  48. if (rtlpriv->link_info.busytraffic)
  49. return true;
  50. else
  51. return false;
  52. }
  53. static void halbtc_dbg_init(void)
  54. {
  55. }
  56. /***************************************************
  57. * helper function
  58. ***************************************************/
  59. static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
  60. {
  61. struct rtl_priv *rtlpriv = btcoexist->adapter;
  62. struct rtl_mac *mac = rtl_mac(rtlpriv);
  63. struct rtl_sta_info *drv_priv;
  64. u8 cnt = 0;
  65. if (mac->opmode == NL80211_IFTYPE_ADHOC ||
  66. mac->opmode == NL80211_IFTYPE_MESH_POINT ||
  67. mac->opmode == NL80211_IFTYPE_AP) {
  68. if (in_interrupt() > 0) {
  69. list_for_each_entry(drv_priv, &rtlpriv->entry_list,
  70. list) {
  71. cnt++;
  72. }
  73. } else {
  74. spin_lock_bh(&rtlpriv->locks.entry_list_lock);
  75. list_for_each_entry(drv_priv, &rtlpriv->entry_list,
  76. list) {
  77. cnt++;
  78. }
  79. spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
  80. }
  81. }
  82. if (cnt > 0)
  83. return true;
  84. else
  85. return false;
  86. }
  87. static bool halbtc_legacy(struct rtl_priv *adapter)
  88. {
  89. struct rtl_priv *rtlpriv = adapter;
  90. struct rtl_mac *mac = rtl_mac(rtlpriv);
  91. bool is_legacy = false;
  92. if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
  93. is_legacy = true;
  94. return is_legacy;
  95. }
  96. bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
  97. {
  98. struct rtl_priv *rtlpriv = adapter;
  99. if (rtlpriv->link_info.tx_busy_traffic)
  100. return true;
  101. else
  102. return false;
  103. }
  104. static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
  105. {
  106. struct rtl_priv *rtlpriv = btcoexist->adapter;
  107. struct rtl_phy *rtlphy = &rtlpriv->phy;
  108. u32 wifi_bw = BTC_WIFI_BW_HT20;
  109. if (halbtc_legacy(rtlpriv)) {
  110. wifi_bw = BTC_WIFI_BW_LEGACY;
  111. } else {
  112. switch (rtlphy->current_chan_bw) {
  113. case HT_CHANNEL_WIDTH_20:
  114. wifi_bw = BTC_WIFI_BW_HT20;
  115. break;
  116. case HT_CHANNEL_WIDTH_20_40:
  117. wifi_bw = BTC_WIFI_BW_HT40;
  118. break;
  119. case HT_CHANNEL_WIDTH_80:
  120. wifi_bw = BTC_WIFI_BW_HT80;
  121. break;
  122. }
  123. }
  124. return wifi_bw;
  125. }
  126. static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
  127. {
  128. struct rtl_priv *rtlpriv = btcoexist->adapter;
  129. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  130. u8 chnl = 1;
  131. if (rtlphy->current_channel != 0)
  132. chnl = rtlphy->current_channel;
  133. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  134. "static halbtc_get_wifi_central_chnl:%d\n", chnl);
  135. return chnl;
  136. }
  137. static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
  138. {
  139. return rtlpriv->btcoexist.btc_info.single_ant_path;
  140. }
  141. static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
  142. {
  143. return rtlpriv->btcoexist.btc_info.bt_type;
  144. }
  145. static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
  146. {
  147. u8 num;
  148. if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
  149. num = 2;
  150. else
  151. num = 1;
  152. return num;
  153. }
  154. static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
  155. {
  156. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  157. return rtlhal->package_type;
  158. }
  159. static
  160. u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
  161. {
  162. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  163. return rtlhal->rfe_type;
  164. }
  165. static
  166. bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
  167. {
  168. if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
  169. return false;
  170. else
  171. return true;
  172. }
  173. static
  174. bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
  175. u8 *cmd, u32 len, unsigned long wait_ms)
  176. {
  177. struct rtl_priv *rtlpriv;
  178. const u8 oper_ver = 0;
  179. u8 req_num;
  180. if (!halbtc_is_hw_mailbox_exist(btcoexist))
  181. return false;
  182. if (wait_ms) /* before h2c to avoid race condition */
  183. reinit_completion(&btcoexist->bt_mp_comp);
  184. rtlpriv = btcoexist->adapter;
  185. /* fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
  186. * to know message type
  187. */
  188. switch (op_code) {
  189. case BT_OP_GET_BT_VERSION:
  190. req_num = BT_SEQ_GET_BT_VERSION;
  191. break;
  192. case BT_OP_GET_AFH_MAP_L:
  193. req_num = BT_SEQ_GET_AFH_MAP_L;
  194. break;
  195. case BT_OP_GET_AFH_MAP_M:
  196. req_num = BT_SEQ_GET_AFH_MAP_M;
  197. break;
  198. case BT_OP_GET_AFH_MAP_H:
  199. req_num = BT_SEQ_GET_AFH_MAP_H;
  200. break;
  201. case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
  202. req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
  203. break;
  204. case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
  205. req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
  206. break;
  207. case BT_OP_GET_BT_ANT_DET_VAL:
  208. req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
  209. break;
  210. case BT_OP_GET_BT_BLE_SCAN_PARA:
  211. req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
  212. break;
  213. case BT_OP_GET_BT_BLE_SCAN_TYPE:
  214. req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
  215. break;
  216. case BT_OP_GET_BT_DEVICE_INFO:
  217. req_num = BT_SEQ_GET_BT_DEVICE_INFO;
  218. break;
  219. case BT_OP_GET_BT_FORBIDDEN_SLOT_VAL:
  220. req_num = BT_SEQ_GET_BT_FORB_SLOT_VAL;
  221. break;
  222. case BT_OP_WRITE_REG_ADDR:
  223. case BT_OP_WRITE_REG_VALUE:
  224. case BT_OP_READ_REG:
  225. default:
  226. req_num = BT_SEQ_DONT_CARE;
  227. break;
  228. }
  229. cmd[0] |= (oper_ver & 0x0f); /* Set OperVer */
  230. cmd[0] |= ((req_num << 4) & 0xf0); /* Set ReqNum */
  231. cmd[1] = op_code;
  232. rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
  233. /* wait? */
  234. if (!wait_ms)
  235. return true;
  236. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  237. "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
  238. if (in_interrupt())
  239. return false;
  240. if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
  241. msecs_to_jiffies(wait_ms)) == 0) {
  242. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
  243. "btmpinfo wait (req_num=%d) timeout\n", req_num);
  244. return false; /* timeout */
  245. }
  246. return true;
  247. }
  248. static void halbtc_leave_lps(struct btc_coexist *btcoexist)
  249. {
  250. struct rtl_priv *rtlpriv;
  251. struct rtl_ps_ctl *ppsc;
  252. bool ap_enable = false;
  253. rtlpriv = btcoexist->adapter;
  254. ppsc = rtl_psc(rtlpriv);
  255. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  256. &ap_enable);
  257. if (ap_enable) {
  258. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
  259. "%s()<--dont leave lps under AP mode\n", __func__);
  260. return;
  261. }
  262. btcoexist->bt_info.bt_ctrl_lps = true;
  263. btcoexist->bt_info.bt_lps_on = false;
  264. rtl_lps_leave(rtlpriv->mac80211.hw);
  265. }
  266. static void halbtc_enter_lps(struct btc_coexist *btcoexist)
  267. {
  268. struct rtl_priv *rtlpriv;
  269. struct rtl_ps_ctl *ppsc;
  270. bool ap_enable = false;
  271. rtlpriv = btcoexist->adapter;
  272. ppsc = rtl_psc(rtlpriv);
  273. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  274. &ap_enable);
  275. if (ap_enable) {
  276. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
  277. "%s()<--dont enter lps under AP mode\n", __func__);
  278. return;
  279. }
  280. btcoexist->bt_info.bt_ctrl_lps = true;
  281. btcoexist->bt_info.bt_lps_on = true;
  282. rtl_lps_enter(rtlpriv->mac80211.hw);
  283. }
  284. static void halbtc_normal_lps(struct btc_coexist *btcoexist)
  285. {
  286. struct rtl_priv *rtlpriv;
  287. rtlpriv = btcoexist->adapter;
  288. if (btcoexist->bt_info.bt_ctrl_lps) {
  289. btcoexist->bt_info.bt_lps_on = false;
  290. rtl_lps_leave(rtlpriv->mac80211.hw);
  291. btcoexist->bt_info.bt_ctrl_lps = false;
  292. }
  293. }
  294. static void halbtc_pre_normal_lps(struct btc_coexist *btcoexist)
  295. {
  296. struct rtl_priv *rtlpriv = btcoexist->adapter;
  297. if (btcoexist->bt_info.bt_ctrl_lps) {
  298. btcoexist->bt_info.bt_lps_on = false;
  299. rtl_lps_leave(rtlpriv->mac80211.hw);
  300. }
  301. }
  302. static void halbtc_post_normal_lps(struct btc_coexist *btcoexist)
  303. {
  304. if (btcoexist->bt_info.bt_ctrl_lps)
  305. btcoexist->bt_info.bt_ctrl_lps = false;
  306. }
  307. static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
  308. {
  309. }
  310. static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
  311. {
  312. }
  313. static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
  314. bool low_pwr_disable)
  315. {
  316. /* TODO: original/leave 32k low power */
  317. btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
  318. }
  319. static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
  320. {
  321. bool need_to_act = false;
  322. static unsigned long pre_time;
  323. unsigned long cur_time = 0;
  324. struct rtl_priv *rtlpriv = btcoexist->adapter;
  325. /* To void continuous deleteBA=>addBA=>deleteBA=>addBA
  326. * This function is not allowed to continuous called
  327. * It can only be called after 8 seconds
  328. */
  329. cur_time = jiffies;
  330. if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
  331. /* over 8 seconds you can execute this function again. */
  332. return;
  333. }
  334. pre_time = cur_time;
  335. if (btcoexist->bt_info.reject_agg_pkt) {
  336. need_to_act = true;
  337. btcoexist->bt_info.pre_reject_agg_pkt =
  338. btcoexist->bt_info.reject_agg_pkt;
  339. } else {
  340. if (btcoexist->bt_info.pre_reject_agg_pkt) {
  341. need_to_act = true;
  342. btcoexist->bt_info.pre_reject_agg_pkt =
  343. btcoexist->bt_info.reject_agg_pkt;
  344. }
  345. if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
  346. btcoexist->bt_info.bt_ctrl_agg_buf_size) {
  347. need_to_act = true;
  348. btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
  349. btcoexist->bt_info.bt_ctrl_agg_buf_size;
  350. }
  351. if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
  352. if (btcoexist->bt_info.pre_agg_buf_size !=
  353. btcoexist->bt_info.agg_buf_size) {
  354. need_to_act = true;
  355. }
  356. btcoexist->bt_info.pre_agg_buf_size =
  357. btcoexist->bt_info.agg_buf_size;
  358. }
  359. if (need_to_act)
  360. rtl_rx_ampdu_apply(rtlpriv);
  361. }
  362. }
  363. static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
  364. {
  365. u8 cmd_buffer[4] = {0};
  366. if (btcoexist->bt_info.bt_real_fw_ver)
  367. goto label_done;
  368. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  369. halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
  370. cmd_buffer, 4, 200);
  371. label_done:
  372. return btcoexist->bt_info.bt_real_fw_ver;
  373. }
  374. static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
  375. {
  376. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  377. u8 cmd_buffer[4] = {0};
  378. if (btcoexist->bt_info.bt_supported_feature)
  379. goto label_done;
  380. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  381. halbtc_send_bt_mp_operation(btcoexist,
  382. BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
  383. cmd_buffer, 4, 200);
  384. label_done:
  385. return btcoexist->bt_info.bt_supported_feature;
  386. }
  387. static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
  388. {
  389. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  390. u8 cmd_buffer[4] = {0};
  391. if (btcoexist->bt_info.bt_supported_version)
  392. goto label_done;
  393. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  394. halbtc_send_bt_mp_operation(btcoexist,
  395. BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
  396. cmd_buffer, 4, 200);
  397. label_done:
  398. return btcoexist->bt_info.bt_supported_version;
  399. }
  400. static u32 halbtc_get_bt_device_info(void *btc_context)
  401. {
  402. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  403. u8 cmd_buffer[4] = {0};
  404. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  405. halbtc_send_bt_mp_operation(btcoexist,
  406. BT_OP_GET_BT_DEVICE_INFO,
  407. cmd_buffer, 4, 200);
  408. return btcoexist->bt_info.bt_device_info;
  409. }
  410. static u32 halbtc_get_bt_forbidden_slot_val(void *btc_context)
  411. {
  412. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  413. u8 cmd_buffer[4] = {0};
  414. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  415. halbtc_send_bt_mp_operation(btcoexist,
  416. BT_OP_GET_BT_FORBIDDEN_SLOT_VAL,
  417. cmd_buffer, 4, 200);
  418. return btcoexist->bt_info.bt_forb_slot_val;
  419. }
  420. static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
  421. {
  422. /* return value:
  423. * [31:16] => connected port number
  424. * [15:0] => port connected bit define
  425. */
  426. struct rtl_priv *rtlpriv = btcoexist->adapter;
  427. struct rtl_mac *mac = rtl_mac(rtlpriv);
  428. u32 ret_val = 0;
  429. u32 port_connected_status = 0, num_of_connected_port = 0;
  430. if (mac->opmode == NL80211_IFTYPE_STATION &&
  431. mac->link_state >= MAC80211_LINKED) {
  432. port_connected_status |= WIFI_STA_CONNECTED;
  433. num_of_connected_port++;
  434. }
  435. /* AP & ADHOC & MESH */
  436. if (is_any_client_connect_to_ap(btcoexist)) {
  437. port_connected_status |= WIFI_AP_CONNECTED;
  438. num_of_connected_port++;
  439. }
  440. /* TODO: P2P Connected Status */
  441. ret_val = (num_of_connected_port << 16) | port_connected_status;
  442. return ret_val;
  443. }
  444. static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
  445. {
  446. int undec_sm_pwdb = 0;
  447. if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
  448. undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
  449. else /* associated entry pwdb */
  450. undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb;
  451. return undec_sm_pwdb;
  452. }
  453. static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
  454. {
  455. struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
  456. struct rtl_priv *rtlpriv = btcoexist->adapter;
  457. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  458. struct rtl_mac *mac = rtl_mac(rtlpriv);
  459. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  460. bool *bool_tmp = (bool *)out_buf;
  461. int *s32_tmp = (int *)out_buf;
  462. u32 *u32_tmp = (u32 *)out_buf;
  463. u8 *u8_tmp = (u8 *)out_buf;
  464. bool tmp = false;
  465. bool ret = true;
  466. if (!halbtc_is_bt_coexist_available(btcoexist))
  467. return false;
  468. switch (get_type) {
  469. case BTC_GET_BL_HS_OPERATION:
  470. *bool_tmp = false;
  471. ret = false;
  472. break;
  473. case BTC_GET_BL_HS_CONNECTING:
  474. *bool_tmp = false;
  475. ret = false;
  476. break;
  477. case BTC_GET_BL_WIFI_CONNECTED:
  478. if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
  479. rtlpriv->mac80211.link_state >= MAC80211_LINKED)
  480. tmp = true;
  481. if (is_any_client_connect_to_ap(btcoexist))
  482. tmp = true;
  483. *bool_tmp = tmp;
  484. break;
  485. case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
  486. *u8_tmp = BTC_MULTIPORT_SCC;
  487. break;
  488. case BTC_GET_BL_WIFI_BUSY:
  489. if (halbtc_is_wifi_busy(rtlpriv))
  490. *bool_tmp = true;
  491. else
  492. *bool_tmp = false;
  493. break;
  494. case BTC_GET_BL_WIFI_SCAN:
  495. if (mac->act_scanning)
  496. *bool_tmp = true;
  497. else
  498. *bool_tmp = false;
  499. break;
  500. case BTC_GET_BL_WIFI_LINK:
  501. if (mac->link_state == MAC80211_LINKING)
  502. *bool_tmp = true;
  503. else
  504. *bool_tmp = false;
  505. break;
  506. case BTC_GET_BL_WIFI_ROAM:
  507. if (mac->link_state == MAC80211_LINKING)
  508. *bool_tmp = true;
  509. else
  510. *bool_tmp = false;
  511. break;
  512. case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
  513. *bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
  514. break;
  515. case BTC_GET_BL_WIFI_UNDER_5G:
  516. if (rtlhal->current_bandtype == BAND_ON_5G)
  517. *bool_tmp = true;
  518. else
  519. *bool_tmp = false;
  520. break;
  521. case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
  522. if (mac->opmode == NL80211_IFTYPE_AP)
  523. *bool_tmp = true;
  524. else
  525. *bool_tmp = false;
  526. break;
  527. case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
  528. if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
  529. *bool_tmp = false;
  530. else
  531. *bool_tmp = true;
  532. break;
  533. case BTC_GET_BL_WIFI_UNDER_B_MODE:
  534. if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
  535. *bool_tmp = true;
  536. else
  537. *bool_tmp = false;
  538. break;
  539. case BTC_GET_BL_EXT_SWITCH:
  540. *bool_tmp = false;
  541. break;
  542. case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
  543. *bool_tmp = false;
  544. break;
  545. case BTC_GET_BL_IS_ASUS_8723B:
  546. *bool_tmp = false;
  547. break;
  548. case BTC_GET_BL_RF4CE_CONNECTED:
  549. *bool_tmp = false;
  550. break;
  551. case BTC_GET_S4_WIFI_RSSI:
  552. *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
  553. break;
  554. case BTC_GET_S4_HS_RSSI:
  555. *s32_tmp = 0;
  556. ret = false;
  557. break;
  558. case BTC_GET_U4_WIFI_BW:
  559. *u32_tmp = halbtc_get_wifi_bw(btcoexist);
  560. break;
  561. case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
  562. if (halbtc_is_wifi_uplink(rtlpriv))
  563. *u32_tmp = BTC_WIFI_TRAFFIC_TX;
  564. else
  565. *u32_tmp = BTC_WIFI_TRAFFIC_RX;
  566. break;
  567. case BTC_GET_U4_WIFI_FW_VER:
  568. *u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
  569. break;
  570. case BTC_GET_U4_WIFI_LINK_STATUS:
  571. *u32_tmp = halbtc_get_wifi_link_status(btcoexist);
  572. break;
  573. case BTC_GET_U4_BT_PATCH_VER:
  574. *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
  575. break;
  576. case BTC_GET_U4_VENDOR:
  577. *u32_tmp = BTC_VENDOR_OTHER;
  578. break;
  579. case BTC_GET_U4_SUPPORTED_VERSION:
  580. *u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
  581. break;
  582. case BTC_GET_U4_SUPPORTED_FEATURE:
  583. *u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
  584. break;
  585. case BTC_GET_U4_BT_DEVICE_INFO:
  586. *u32_tmp = halbtc_get_bt_device_info(btcoexist);
  587. break;
  588. case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
  589. *u32_tmp = halbtc_get_bt_forbidden_slot_val(btcoexist);
  590. break;
  591. case BTC_GET_U4_WIFI_IQK_TOTAL:
  592. *u32_tmp =
  593. btcoexist->btc_phydm_query_phy_counter(btcoexist,
  594. DM_INFO_IQK_ALL);
  595. break;
  596. case BTC_GET_U4_WIFI_IQK_OK:
  597. *u32_tmp =
  598. btcoexist->btc_phydm_query_phy_counter(btcoexist,
  599. DM_INFO_IQK_OK);
  600. break;
  601. case BTC_GET_U4_WIFI_IQK_FAIL:
  602. *u32_tmp =
  603. btcoexist->btc_phydm_query_phy_counter(btcoexist,
  604. DM_INFO_IQK_NG);
  605. break;
  606. case BTC_GET_U1_WIFI_DOT11_CHNL:
  607. *u8_tmp = rtlphy->current_channel;
  608. break;
  609. case BTC_GET_U1_WIFI_CENTRAL_CHNL:
  610. *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
  611. break;
  612. case BTC_GET_U1_WIFI_HS_CHNL:
  613. *u8_tmp = 0;
  614. ret = false;
  615. break;
  616. case BTC_GET_U1_AP_NUM:
  617. *u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
  618. break;
  619. case BTC_GET_U1_ANT_TYPE:
  620. *u8_tmp = (u8)BTC_ANT_TYPE_0;
  621. break;
  622. case BTC_GET_U1_IOT_PEER:
  623. *u8_tmp = 0;
  624. break;
  625. /************* 1Ant **************/
  626. case BTC_GET_U1_LPS_MODE:
  627. *u8_tmp = btcoexist->pwr_mode_val[0];
  628. break;
  629. default:
  630. ret = false;
  631. break;
  632. }
  633. return ret;
  634. }
  635. static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
  636. {
  637. struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
  638. bool *bool_tmp = (bool *)in_buf;
  639. u8 *u8_tmp = (u8 *)in_buf;
  640. u32 *u32_tmp = (u32 *)in_buf;
  641. bool ret = true;
  642. if (!halbtc_is_bt_coexist_available(btcoexist))
  643. return false;
  644. switch (set_type) {
  645. /* set some bool type variables. */
  646. case BTC_SET_BL_BT_DISABLE:
  647. btcoexist->bt_info.bt_disabled = *bool_tmp;
  648. break;
  649. case BTC_SET_BL_BT_TRAFFIC_BUSY:
  650. btcoexist->bt_info.bt_busy = *bool_tmp;
  651. break;
  652. case BTC_SET_BL_BT_LIMITED_DIG:
  653. btcoexist->bt_info.limited_dig = *bool_tmp;
  654. break;
  655. case BTC_SET_BL_FORCE_TO_ROAM:
  656. btcoexist->bt_info.force_to_roam = *bool_tmp;
  657. break;
  658. case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
  659. btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
  660. break;
  661. case BTC_SET_BL_BT_CTRL_AGG_SIZE:
  662. btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
  663. break;
  664. case BTC_SET_BL_INC_SCAN_DEV_NUM:
  665. btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
  666. break;
  667. case BTC_SET_BL_BT_TX_RX_MASK:
  668. btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
  669. break;
  670. case BTC_SET_BL_MIRACAST_PLUS_BT:
  671. btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
  672. break;
  673. /* set some u1Byte type variables. */
  674. case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
  675. btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
  676. break;
  677. case BTC_SET_U1_AGG_BUF_SIZE:
  678. btcoexist->bt_info.agg_buf_size = *u8_tmp;
  679. break;
  680. /* the following are some action which will be triggered */
  681. case BTC_SET_ACT_GET_BT_RSSI:
  682. ret = false;
  683. break;
  684. case BTC_SET_ACT_AGGREGATE_CTRL:
  685. halbtc_aggregation_check(btcoexist);
  686. break;
  687. /* 1Ant */
  688. case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
  689. btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
  690. break;
  691. case BTC_SET_UI_SCAN_SIG_COMPENSATION:
  692. break;
  693. case BTC_SET_U1_LPS_VAL:
  694. btcoexist->bt_info.lps_val = *u8_tmp;
  695. break;
  696. case BTC_SET_U1_RPWM_VAL:
  697. btcoexist->bt_info.rpwm_val = *u8_tmp;
  698. break;
  699. /* the following are some action which will be triggered */
  700. case BTC_SET_ACT_LEAVE_LPS:
  701. halbtc_leave_lps(btcoexist);
  702. break;
  703. case BTC_SET_ACT_ENTER_LPS:
  704. halbtc_enter_lps(btcoexist);
  705. break;
  706. case BTC_SET_ACT_NORMAL_LPS:
  707. halbtc_normal_lps(btcoexist);
  708. break;
  709. case BTC_SET_ACT_PRE_NORMAL_LPS:
  710. halbtc_pre_normal_lps(btcoexist);
  711. break;
  712. case BTC_SET_ACT_POST_NORMAL_LPS:
  713. halbtc_post_normal_lps(btcoexist);
  714. break;
  715. case BTC_SET_ACT_DISABLE_LOW_POWER:
  716. halbtc_disable_low_power(btcoexist, *bool_tmp);
  717. break;
  718. case BTC_SET_ACT_UPDATE_RAMASK:
  719. btcoexist->bt_info.ra_mask = *u32_tmp;
  720. break;
  721. case BTC_SET_ACT_SEND_MIMO_PS:
  722. break;
  723. case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
  724. break;
  725. case BTC_SET_ACT_CTRL_BT_COEX:
  726. break;
  727. case BTC_SET_ACT_CTRL_8723B_ANT:
  728. break;
  729. default:
  730. break;
  731. }
  732. return ret;
  733. }
  734. static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
  735. struct seq_file *m)
  736. {
  737. }
  738. static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
  739. struct seq_file *m)
  740. {
  741. }
  742. static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
  743. struct seq_file *m)
  744. {
  745. struct rtl_priv *rtlpriv = btcoexist->adapter;
  746. s32 wifi_rssi = 0, bt_hs_rssi = 0;
  747. bool scan = false, link = false, roam = false, wifi_busy = false;
  748. bool wifi_under_b_mode = false;
  749. bool wifi_under_5g = false;
  750. u32 wifi_bw = BTC_WIFI_BW_HT20;
  751. u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
  752. u32 wifi_freq = BTC_FREQ_2_4G;
  753. u32 wifi_link_status = 0x0;
  754. bool bt_hs_on = false, under_ips = false, under_lps = false;
  755. bool low_power = false, dc_mode = false;
  756. u8 wifi_chnl = 0, wifi_hs_chnl = 0;
  757. u8 ap_num = 0;
  758. wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
  759. seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
  760. "STA/vWifi/HS/p2pGo/p2pGc",
  761. ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
  762. ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
  763. ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
  764. ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
  765. ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
  766. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  767. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
  768. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
  769. seq_printf(m, "\n %-35s = %d / %d(%d)",
  770. "Dot11 channel / HsChnl(High Speed)",
  771. wifi_chnl, wifi_hs_chnl, bt_hs_on);
  772. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  773. btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
  774. seq_printf(m, "\n %-35s = %d/ %d",
  775. "Wifi rssi/ HS rssi",
  776. wifi_rssi - 100, bt_hs_rssi - 100);
  777. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  778. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  779. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  780. seq_printf(m, "\n %-35s = %d/ %d/ %d ",
  781. "Wifi link/ roam/ scan",
  782. link, roam, scan);
  783. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  784. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  785. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  786. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
  787. &wifi_traffic_dir);
  788. btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
  789. wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
  790. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
  791. &wifi_under_b_mode);
  792. seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
  793. "Wifi freq/ bw/ traffic",
  794. gl_btc_wifi_freq_string[wifi_freq],
  795. ((wifi_under_b_mode) ? "11b" :
  796. gl_btc_wifi_bw_string[wifi_bw]),
  797. ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
  798. wifi_traffic_dir) ? "uplink" :
  799. "downlink")),
  800. ap_num);
  801. /* power status */
  802. dc_mode = true; /*TODO*/
  803. under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
  804. under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
  805. low_power = 0; /*TODO*/
  806. seq_printf(m, "\n %-35s = %s%s%s%s",
  807. "Power Status",
  808. (dc_mode ? "DC mode" : "AC mode"),
  809. (under_ips ? ", IPS ON" : ""),
  810. (under_lps ? ", LPS ON" : ""),
  811. (low_power ? ", 32k" : ""));
  812. seq_printf(m,
  813. "\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)",
  814. "Power mode cmd(lps/rpwm)",
  815. btcoexist->pwr_mode_val[0], btcoexist->pwr_mode_val[1],
  816. btcoexist->pwr_mode_val[2], btcoexist->pwr_mode_val[3],
  817. btcoexist->pwr_mode_val[4], btcoexist->pwr_mode_val[5],
  818. btcoexist->bt_info.lps_val,
  819. btcoexist->bt_info.rpwm_val);
  820. }
  821. /************************************************************
  822. * IO related function
  823. ************************************************************/
  824. static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
  825. {
  826. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  827. struct rtl_priv *rtlpriv = btcoexist->adapter;
  828. return rtl_read_byte(rtlpriv, reg_addr);
  829. }
  830. static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
  831. {
  832. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  833. struct rtl_priv *rtlpriv = btcoexist->adapter;
  834. return rtl_read_word(rtlpriv, reg_addr);
  835. }
  836. static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
  837. {
  838. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  839. struct rtl_priv *rtlpriv = btcoexist->adapter;
  840. return rtl_read_dword(rtlpriv, reg_addr);
  841. }
  842. static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
  843. {
  844. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  845. struct rtl_priv *rtlpriv = btcoexist->adapter;
  846. rtl_write_byte(rtlpriv, reg_addr, data);
  847. }
  848. static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
  849. u32 bit_mask, u8 data)
  850. {
  851. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  852. struct rtl_priv *rtlpriv = btcoexist->adapter;
  853. u8 original_value, bit_shift = 0;
  854. u8 i;
  855. if (bit_mask != MASKDWORD) {/*if not "double word" write*/
  856. original_value = rtl_read_byte(rtlpriv, reg_addr);
  857. for (i = 0; i <= 7; i++) {
  858. if ((bit_mask>>i) & 0x1)
  859. break;
  860. }
  861. bit_shift = i;
  862. data = (original_value & (~bit_mask)) |
  863. ((data << bit_shift) & bit_mask);
  864. }
  865. rtl_write_byte(rtlpriv, reg_addr, data);
  866. }
  867. static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
  868. {
  869. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  870. struct rtl_priv *rtlpriv = btcoexist->adapter;
  871. rtl_write_word(rtlpriv, reg_addr, data);
  872. }
  873. static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
  874. {
  875. struct btc_coexist *btcoexist =
  876. (struct btc_coexist *)bt_context;
  877. struct rtl_priv *rtlpriv = btcoexist->adapter;
  878. rtl_write_dword(rtlpriv, reg_addr, data);
  879. }
  880. static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
  881. u8 data)
  882. {
  883. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  884. struct rtl_priv *rtlpriv = btcoexist->adapter;
  885. if (btcoexist->chip_interface == BTC_INTF_SDIO)
  886. ;
  887. else if (btcoexist->chip_interface == BTC_INTF_PCI)
  888. rtl_write_byte(rtlpriv, reg_addr, data);
  889. else if (btcoexist->chip_interface == BTC_INTF_USB)
  890. rtl_write_byte(rtlpriv, reg_addr, data);
  891. }
  892. static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
  893. u32 data)
  894. {
  895. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  896. struct rtl_priv *rtlpriv = btcoexist->adapter;
  897. rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
  898. }
  899. static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
  900. {
  901. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  902. struct rtl_priv *rtlpriv = btcoexist->adapter;
  903. return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
  904. }
  905. static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
  906. u32 bit_mask, u32 data)
  907. {
  908. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  909. struct rtl_priv *rtlpriv = btcoexist->adapter;
  910. rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
  911. }
  912. static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
  913. u32 bit_mask)
  914. {
  915. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  916. struct rtl_priv *rtlpriv = btcoexist->adapter;
  917. return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
  918. }
  919. static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
  920. u32 cmd_len, u8 *cmd_buf)
  921. {
  922. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  923. struct rtl_priv *rtlpriv = btcoexist->adapter;
  924. rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
  925. cmd_len, cmd_buf);
  926. }
  927. void halbtc_send_wifi_port_id_cmd(void *bt_context)
  928. {
  929. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  930. struct rtl_priv *rtlpriv = btcoexist->adapter;
  931. u8 cmd_buf[1] = {0}; /* port id [2:0] = 0 */
  932. rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, H2C_BT_PORT_ID,
  933. 1, cmd_buf);
  934. }
  935. void halbtc_set_default_port_id_cmd(void *bt_context)
  936. {
  937. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  938. struct rtl_priv *rtlpriv = btcoexist->adapter;
  939. struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
  940. if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
  941. return;
  942. rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
  943. }
  944. static
  945. void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
  946. {
  947. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  948. u8 cmd_buffer1[4] = {0};
  949. u8 cmd_buffer2[4] = {0};
  950. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  951. *((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
  952. if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
  953. cmd_buffer1, 4, 200))
  954. return;
  955. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  956. cmd_buffer2[2] = reg_type;
  957. *((u8 *)&cmd_buffer2[3]) = (u8)offset;
  958. halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
  959. cmd_buffer2, 4, 200);
  960. }
  961. static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
  962. struct seq_file *m)
  963. {
  964. struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
  965. switch (disp_type) {
  966. case BTC_DBG_DISP_COEX_STATISTICS:
  967. halbtc_display_coex_statistics(btcoexist, m);
  968. break;
  969. case BTC_DBG_DISP_BT_LINK_INFO:
  970. halbtc_display_bt_link_info(btcoexist, m);
  971. break;
  972. case BTC_DBG_DISP_WIFI_STATUS:
  973. halbtc_display_wifi_status(btcoexist, m);
  974. break;
  975. default:
  976. break;
  977. }
  978. }
  979. static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
  980. {
  981. return 0;
  982. }
  983. static bool halbtc_under_ips(struct btc_coexist *btcoexist)
  984. {
  985. struct rtl_priv *rtlpriv = btcoexist->adapter;
  986. struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
  987. enum rf_pwrstate rtstate;
  988. if (ppsc->inactiveps) {
  989. rtstate = ppsc->rfpwr_state;
  990. if (rtstate != ERFON &&
  991. ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
  992. return true;
  993. }
  994. }
  995. return false;
  996. }
  997. static
  998. u32 halbtc_get_phydm_version(void *btc_context)
  999. {
  1000. return 0;
  1001. }
  1002. static
  1003. void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
  1004. u8 ra_offset_direction,
  1005. u8 ra_threshold_offset)
  1006. {
  1007. }
  1008. static
  1009. u32 halbtc_phydm_query_phy_counter(void *btc_context, enum dm_info_query dm_id)
  1010. {
  1011. return 0;
  1012. }
  1013. static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
  1014. {
  1015. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  1016. u8 cmd_buffer[4] = {0};
  1017. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  1018. halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
  1019. cmd_buffer, 4, 200);
  1020. /* need wait completion to return correct value */
  1021. return btcoexist->bt_info.bt_ant_det_val;
  1022. }
  1023. static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
  1024. {
  1025. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  1026. u8 cmd_buffer[4] = {0};
  1027. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  1028. halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
  1029. cmd_buffer, 4, 200);
  1030. /* need wait completion to return correct value */
  1031. return btcoexist->bt_info.bt_ble_scan_type;
  1032. }
  1033. static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
  1034. {
  1035. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  1036. u8 cmd_buffer[4] = {0};
  1037. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  1038. halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
  1039. cmd_buffer, 4, 200);
  1040. /* need wait completion to return correct value */
  1041. return btcoexist->bt_info.bt_ble_scan_para;
  1042. }
  1043. static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
  1044. u8 *afh_map)
  1045. {
  1046. struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
  1047. u8 cmd_buffer[2] = {0};
  1048. bool ret;
  1049. u32 *afh_map_l = (u32 *)afh_map;
  1050. u32 *afh_map_m = (u32 *)(afh_map + 4);
  1051. u16 *afh_map_h = (u16 *)(afh_map + 8);
  1052. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  1053. ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
  1054. cmd_buffer, 2, 200);
  1055. if (!ret)
  1056. goto exit;
  1057. *afh_map_l = btcoexist->bt_info.afh_map_l;
  1058. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  1059. ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
  1060. cmd_buffer, 2, 200);
  1061. if (!ret)
  1062. goto exit;
  1063. *afh_map_m = btcoexist->bt_info.afh_map_m;
  1064. /* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
  1065. ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
  1066. cmd_buffer, 2, 200);
  1067. if (!ret)
  1068. goto exit;
  1069. *afh_map_h = btcoexist->bt_info.afh_map_h;
  1070. exit:
  1071. return ret;
  1072. }
  1073. /*****************************************************************
  1074. * Extern functions called by other module
  1075. *****************************************************************/
  1076. bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
  1077. {
  1078. struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
  1079. if (!btcoexist)
  1080. return false;
  1081. halbtc_dbg_init();
  1082. btcoexist->btc_read_1byte = halbtc_read_1byte;
  1083. btcoexist->btc_write_1byte = halbtc_write_1byte;
  1084. btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
  1085. btcoexist->btc_read_2byte = halbtc_read_2byte;
  1086. btcoexist->btc_write_2byte = halbtc_write_2byte;
  1087. btcoexist->btc_read_4byte = halbtc_read_4byte;
  1088. btcoexist->btc_write_4byte = halbtc_write_4byte;
  1089. btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
  1090. btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
  1091. btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
  1092. btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
  1093. btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
  1094. btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
  1095. btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
  1096. btcoexist->btc_get = halbtc_get;
  1097. btcoexist->btc_set = halbtc_set;
  1098. btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
  1099. btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
  1100. btcoexist->bt_info.bt_ctrl_buf_size = false;
  1101. btcoexist->bt_info.agg_buf_size = 5;
  1102. btcoexist->bt_info.increase_scan_dev_num = false;
  1103. btcoexist->btc_get_bt_coex_supported_feature =
  1104. halbtc_get_bt_coex_supported_feature;
  1105. btcoexist->btc_get_bt_coex_supported_version =
  1106. halbtc_get_bt_coex_supported_version;
  1107. btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
  1108. btcoexist->btc_phydm_modify_ra_pcr_threshold =
  1109. halbtc_phydm_modify_ra_pcr_threshold;
  1110. btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
  1111. btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
  1112. btcoexist->btc_get_ble_scan_type_from_bt =
  1113. halbtc_get_ble_scan_type_from_bt;
  1114. btcoexist->btc_get_ble_scan_para_from_bt =
  1115. halbtc_get_ble_scan_para_from_bt;
  1116. btcoexist->btc_get_bt_afh_map_from_bt =
  1117. halbtc_get_bt_afh_map_from_bt;
  1118. init_completion(&btcoexist->bt_mp_comp);
  1119. return true;
  1120. }
  1121. bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
  1122. {
  1123. struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
  1124. struct wifi_only_haldata *wifionly_haldata;
  1125. if (!wifionly_cfg)
  1126. return false;
  1127. wifionly_cfg->adapter = rtlpriv;
  1128. switch (rtlpriv->rtlhal.interface) {
  1129. case INTF_PCI:
  1130. wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
  1131. break;
  1132. case INTF_USB:
  1133. wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
  1134. break;
  1135. default:
  1136. wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
  1137. break;
  1138. }
  1139. wifionly_haldata = &wifionly_cfg->haldata_info;
  1140. wifionly_haldata->customer_id = CUSTOMER_NORMAL;
  1141. wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
  1142. wifionly_haldata->efuse_pg_antpath =
  1143. rtl_get_hwpg_single_ant_path(rtlpriv);
  1144. wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
  1145. wifionly_haldata->ant_div_cfg = 0;
  1146. return true;
  1147. }
  1148. bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
  1149. {
  1150. struct rtl_priv *rtlpriv = adapter;
  1151. struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
  1152. u8 ant_num = 2, chip_type, single_ant_path = 0;
  1153. if (!btcoexist)
  1154. return false;
  1155. if (btcoexist->binded)
  1156. return false;
  1157. switch (rtlpriv->rtlhal.interface) {
  1158. case INTF_PCI:
  1159. btcoexist->chip_interface = BTC_INTF_PCI;
  1160. break;
  1161. case INTF_USB:
  1162. btcoexist->chip_interface = BTC_INTF_USB;
  1163. break;
  1164. default:
  1165. btcoexist->chip_interface = BTC_INTF_UNKNOWN;
  1166. break;
  1167. }
  1168. btcoexist->binded = true;
  1169. btcoexist->statistics.cnt_bind++;
  1170. btcoexist->adapter = adapter;
  1171. btcoexist->stack_info.profile_notified = false;
  1172. btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
  1173. btcoexist->bt_info.agg_buf_size = 5;
  1174. btcoexist->bt_info.increase_scan_dev_num = false;
  1175. btcoexist->bt_info.miracast_plus_bt = false;
  1176. chip_type = rtl_get_hwpg_bt_type(rtlpriv);
  1177. exhalbtc_set_chip_type(btcoexist, chip_type);
  1178. ant_num = rtl_get_hwpg_ant_num(rtlpriv);
  1179. exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
  1180. /* set default antenna position to main port */
  1181. btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
  1182. single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
  1183. exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
  1184. if (rtl_get_hwpg_package_type(rtlpriv) == 0)
  1185. btcoexist->board_info.tfbga_package = false;
  1186. else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
  1187. btcoexist->board_info.tfbga_package = false;
  1188. else
  1189. btcoexist->board_info.tfbga_package = true;
  1190. if (btcoexist->board_info.tfbga_package)
  1191. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1192. "[BTCoex], Package Type = TFBGA\n");
  1193. else
  1194. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
  1195. "[BTCoex], Package Type = Non-TFBGA\n");
  1196. btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
  1197. btcoexist->board_info.ant_div_cfg = 0;
  1198. return true;
  1199. }
  1200. void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
  1201. {
  1202. if (!halbtc_is_bt_coexist_available(btcoexist))
  1203. return;
  1204. btcoexist->statistics.cnt_power_on++;
  1205. if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1206. if (btcoexist->board_info.btdm_ant_num == 2)
  1207. ex_btc8723b2ant_power_on_setting(btcoexist);
  1208. else if (btcoexist->board_info.btdm_ant_num == 1)
  1209. ex_btc8723b1ant_power_on_setting(btcoexist);
  1210. }
  1211. }
  1212. void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
  1213. {
  1214. if (!halbtc_is_bt_coexist_available(btcoexist))
  1215. return;
  1216. btcoexist->statistics.cnt_pre_load_firmware++;
  1217. if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1218. if (btcoexist->board_info.btdm_ant_num == 2)
  1219. ex_btc8723b2ant_pre_load_firmware(btcoexist);
  1220. }
  1221. }
  1222. void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
  1223. {
  1224. if (!halbtc_is_bt_coexist_available(btcoexist))
  1225. return;
  1226. btcoexist->statistics.cnt_init_hw_config++;
  1227. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1228. if (btcoexist->board_info.btdm_ant_num == 2)
  1229. ex_btc8821a2ant_init_hwconfig(btcoexist);
  1230. else if (btcoexist->board_info.btdm_ant_num == 1)
  1231. ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
  1232. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1233. if (btcoexist->board_info.btdm_ant_num == 2)
  1234. ex_btc8723b2ant_init_hwconfig(btcoexist);
  1235. else if (btcoexist->board_info.btdm_ant_num == 1)
  1236. ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
  1237. } else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
  1238. /* 8723A has no this function */
  1239. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1240. if (btcoexist->board_info.btdm_ant_num == 2)
  1241. ex_btc8192e2ant_init_hwconfig(btcoexist);
  1242. }
  1243. }
  1244. void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
  1245. {
  1246. }
  1247. void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
  1248. {
  1249. if (!halbtc_is_bt_coexist_available(btcoexist))
  1250. return;
  1251. btcoexist->statistics.cnt_init_coex_dm++;
  1252. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1253. if (btcoexist->board_info.btdm_ant_num == 2)
  1254. ex_btc8821a2ant_init_coex_dm(btcoexist);
  1255. else if (btcoexist->board_info.btdm_ant_num == 1)
  1256. ex_btc8821a1ant_init_coex_dm(btcoexist);
  1257. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1258. if (btcoexist->board_info.btdm_ant_num == 2)
  1259. ex_btc8723b2ant_init_coex_dm(btcoexist);
  1260. else if (btcoexist->board_info.btdm_ant_num == 1)
  1261. ex_btc8723b1ant_init_coex_dm(btcoexist);
  1262. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1263. if (btcoexist->board_info.btdm_ant_num == 2)
  1264. ex_btc8192e2ant_init_coex_dm(btcoexist);
  1265. }
  1266. btcoexist->initilized = true;
  1267. }
  1268. void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
  1269. {
  1270. u8 ips_type;
  1271. if (!halbtc_is_bt_coexist_available(btcoexist))
  1272. return;
  1273. btcoexist->statistics.cnt_ips_notify++;
  1274. if (btcoexist->manual_control)
  1275. return;
  1276. if (ERFOFF == type)
  1277. ips_type = BTC_IPS_ENTER;
  1278. else
  1279. ips_type = BTC_IPS_LEAVE;
  1280. halbtc_leave_low_power(btcoexist);
  1281. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1282. if (btcoexist->board_info.btdm_ant_num == 2)
  1283. ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
  1284. else if (btcoexist->board_info.btdm_ant_num == 1)
  1285. ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
  1286. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1287. if (btcoexist->board_info.btdm_ant_num == 2)
  1288. ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
  1289. else if (btcoexist->board_info.btdm_ant_num == 1)
  1290. ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
  1291. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1292. if (btcoexist->board_info.btdm_ant_num == 2)
  1293. ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
  1294. }
  1295. halbtc_normal_low_power(btcoexist);
  1296. }
  1297. void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
  1298. {
  1299. u8 lps_type;
  1300. if (!halbtc_is_bt_coexist_available(btcoexist))
  1301. return;
  1302. btcoexist->statistics.cnt_lps_notify++;
  1303. if (btcoexist->manual_control)
  1304. return;
  1305. if (EACTIVE == type)
  1306. lps_type = BTC_LPS_DISABLE;
  1307. else
  1308. lps_type = BTC_LPS_ENABLE;
  1309. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1310. if (btcoexist->board_info.btdm_ant_num == 2)
  1311. ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
  1312. else if (btcoexist->board_info.btdm_ant_num == 1)
  1313. ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
  1314. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1315. if (btcoexist->board_info.btdm_ant_num == 2)
  1316. ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
  1317. else if (btcoexist->board_info.btdm_ant_num == 1)
  1318. ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
  1319. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1320. if (btcoexist->board_info.btdm_ant_num == 2)
  1321. ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
  1322. }
  1323. }
  1324. void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
  1325. {
  1326. u8 scan_type;
  1327. if (!halbtc_is_bt_coexist_available(btcoexist))
  1328. return;
  1329. btcoexist->statistics.cnt_scan_notify++;
  1330. if (btcoexist->manual_control)
  1331. return;
  1332. if (type)
  1333. scan_type = BTC_SCAN_START;
  1334. else
  1335. scan_type = BTC_SCAN_FINISH;
  1336. halbtc_leave_low_power(btcoexist);
  1337. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1338. if (btcoexist->board_info.btdm_ant_num == 2)
  1339. ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
  1340. else if (btcoexist->board_info.btdm_ant_num == 1)
  1341. ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
  1342. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1343. if (btcoexist->board_info.btdm_ant_num == 2)
  1344. ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
  1345. else if (btcoexist->board_info.btdm_ant_num == 1)
  1346. ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
  1347. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1348. if (btcoexist->board_info.btdm_ant_num == 2)
  1349. ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
  1350. }
  1351. halbtc_normal_low_power(btcoexist);
  1352. }
  1353. void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
  1354. u8 is_5g)
  1355. {
  1356. }
  1357. void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
  1358. {
  1359. u8 asso_type, asso_type_v2;
  1360. bool wifi_under_5g;
  1361. if (!halbtc_is_bt_coexist_available(btcoexist))
  1362. return;
  1363. btcoexist->statistics.cnt_connect_notify++;
  1364. if (btcoexist->manual_control)
  1365. return;
  1366. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  1367. if (action) {
  1368. asso_type = BTC_ASSOCIATE_START;
  1369. asso_type_v2 = wifi_under_5g ? BTC_ASSOCIATE_5G_START :
  1370. BTC_ASSOCIATE_START;
  1371. } else {
  1372. asso_type = BTC_ASSOCIATE_FINISH;
  1373. asso_type_v2 = wifi_under_5g ? BTC_ASSOCIATE_5G_FINISH :
  1374. BTC_ASSOCIATE_FINISH;
  1375. }
  1376. halbtc_leave_low_power(btcoexist);
  1377. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1378. if (btcoexist->board_info.btdm_ant_num == 2)
  1379. ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
  1380. else if (btcoexist->board_info.btdm_ant_num == 1)
  1381. ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
  1382. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1383. if (btcoexist->board_info.btdm_ant_num == 2)
  1384. ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
  1385. else if (btcoexist->board_info.btdm_ant_num == 1)
  1386. ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
  1387. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1388. if (btcoexist->board_info.btdm_ant_num == 2)
  1389. ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
  1390. }
  1391. halbtc_normal_low_power(btcoexist);
  1392. }
  1393. void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
  1394. enum rt_media_status media_status)
  1395. {
  1396. u8 status;
  1397. if (!halbtc_is_bt_coexist_available(btcoexist))
  1398. return;
  1399. btcoexist->statistics.cnt_media_status_notify++;
  1400. if (btcoexist->manual_control)
  1401. return;
  1402. if (RT_MEDIA_CONNECT == media_status)
  1403. status = BTC_MEDIA_CONNECT;
  1404. else
  1405. status = BTC_MEDIA_DISCONNECT;
  1406. halbtc_leave_low_power(btcoexist);
  1407. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1408. if (btcoexist->board_info.btdm_ant_num == 2)
  1409. ex_btc8821a2ant_media_status_notify(btcoexist, status);
  1410. else if (btcoexist->board_info.btdm_ant_num == 1)
  1411. ex_btc8821a1ant_media_status_notify(btcoexist, status);
  1412. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1413. if (btcoexist->board_info.btdm_ant_num == 2)
  1414. ex_btc8723b2ant_media_status_notify(btcoexist, status);
  1415. else if (btcoexist->board_info.btdm_ant_num == 1)
  1416. ex_btc8723b1ant_media_status_notify(btcoexist, status);
  1417. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1418. if (btcoexist->board_info.btdm_ant_num == 2)
  1419. ex_btc8192e2ant_media_status_notify(btcoexist, status);
  1420. }
  1421. halbtc_normal_low_power(btcoexist);
  1422. }
  1423. void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
  1424. {
  1425. u8 packet_type;
  1426. if (!halbtc_is_bt_coexist_available(btcoexist))
  1427. return;
  1428. btcoexist->statistics.cnt_special_packet_notify++;
  1429. if (btcoexist->manual_control)
  1430. return;
  1431. if (pkt_type == PACKET_DHCP) {
  1432. packet_type = BTC_PACKET_DHCP;
  1433. } else if (pkt_type == PACKET_EAPOL) {
  1434. packet_type = BTC_PACKET_EAPOL;
  1435. } else if (pkt_type == PACKET_ARP) {
  1436. packet_type = BTC_PACKET_ARP;
  1437. } else {
  1438. packet_type = BTC_PACKET_UNKNOWN;
  1439. return;
  1440. }
  1441. halbtc_leave_low_power(btcoexist);
  1442. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1443. if (btcoexist->board_info.btdm_ant_num == 2)
  1444. ex_btc8821a2ant_special_packet_notify(btcoexist,
  1445. packet_type);
  1446. else if (btcoexist->board_info.btdm_ant_num == 1)
  1447. ex_btc8821a1ant_special_packet_notify(btcoexist,
  1448. packet_type);
  1449. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1450. if (btcoexist->board_info.btdm_ant_num == 2)
  1451. ex_btc8723b2ant_special_packet_notify(btcoexist,
  1452. packet_type);
  1453. else if (btcoexist->board_info.btdm_ant_num == 1)
  1454. ex_btc8723b1ant_special_packet_notify(btcoexist,
  1455. packet_type);
  1456. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1457. if (btcoexist->board_info.btdm_ant_num == 2)
  1458. ex_btc8192e2ant_special_packet_notify(btcoexist,
  1459. packet_type);
  1460. }
  1461. halbtc_normal_low_power(btcoexist);
  1462. }
  1463. void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
  1464. u8 *tmp_buf, u8 length)
  1465. {
  1466. if (!halbtc_is_bt_coexist_available(btcoexist))
  1467. return;
  1468. btcoexist->statistics.cnt_bt_info_notify++;
  1469. halbtc_leave_low_power(btcoexist);
  1470. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1471. if (btcoexist->board_info.btdm_ant_num == 2)
  1472. ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
  1473. length);
  1474. else if (btcoexist->board_info.btdm_ant_num == 1)
  1475. ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
  1476. length);
  1477. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1478. if (btcoexist->board_info.btdm_ant_num == 2)
  1479. ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
  1480. length);
  1481. else if (btcoexist->board_info.btdm_ant_num == 1)
  1482. ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
  1483. length);
  1484. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1485. if (btcoexist->board_info.btdm_ant_num == 2)
  1486. ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
  1487. length);
  1488. }
  1489. halbtc_normal_low_power(btcoexist);
  1490. }
  1491. void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
  1492. {
  1493. if (!halbtc_is_bt_coexist_available(btcoexist))
  1494. return;
  1495. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1496. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1497. if (btcoexist->board_info.btdm_ant_num == 1)
  1498. ex_btc8723b1ant_rf_status_notify(btcoexist, type);
  1499. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1500. }
  1501. }
  1502. void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
  1503. {
  1504. u8 stack_op_type;
  1505. if (!halbtc_is_bt_coexist_available(btcoexist))
  1506. return;
  1507. btcoexist->statistics.cnt_stack_operation_notify++;
  1508. if (btcoexist->manual_control)
  1509. return;
  1510. if ((type == HCI_BT_OP_INQUIRY_START) ||
  1511. (type == HCI_BT_OP_PAGING_START) ||
  1512. (type == HCI_BT_OP_PAIRING_START)) {
  1513. stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_START;
  1514. } else if ((type == HCI_BT_OP_INQUIRY_FINISH) ||
  1515. (type == HCI_BT_OP_PAGING_SUCCESS) ||
  1516. (type == HCI_BT_OP_PAGING_UNSUCCESS) ||
  1517. (type == HCI_BT_OP_PAIRING_FINISH)) {
  1518. stack_op_type = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
  1519. } else {
  1520. stack_op_type = BTC_STACK_OP_NONE;
  1521. }
  1522. }
  1523. void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
  1524. {
  1525. if (!halbtc_is_bt_coexist_available(btcoexist))
  1526. return;
  1527. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1528. if (btcoexist->board_info.btdm_ant_num == 2)
  1529. ex_btc8821a2ant_halt_notify(btcoexist);
  1530. else if (btcoexist->board_info.btdm_ant_num == 1)
  1531. ex_btc8821a1ant_halt_notify(btcoexist);
  1532. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1533. if (btcoexist->board_info.btdm_ant_num == 2)
  1534. ex_btc8723b2ant_halt_notify(btcoexist);
  1535. else if (btcoexist->board_info.btdm_ant_num == 1)
  1536. ex_btc8723b1ant_halt_notify(btcoexist);
  1537. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1538. if (btcoexist->board_info.btdm_ant_num == 2)
  1539. ex_btc8192e2ant_halt_notify(btcoexist);
  1540. }
  1541. btcoexist->binded = false;
  1542. }
  1543. void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
  1544. {
  1545. if (!halbtc_is_bt_coexist_available(btcoexist))
  1546. return;
  1547. /* currently only 1ant we have to do the notification,
  1548. * once pnp is notified to sleep state, we have to leave LPS that
  1549. * we can sleep normally.
  1550. */
  1551. if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1552. if (btcoexist->board_info.btdm_ant_num == 1)
  1553. ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
  1554. else if (btcoexist->board_info.btdm_ant_num == 2)
  1555. ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
  1556. } else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1557. if (btcoexist->board_info.btdm_ant_num == 1)
  1558. ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
  1559. else if (btcoexist->board_info.btdm_ant_num == 2)
  1560. ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
  1561. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1562. }
  1563. }
  1564. void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
  1565. {
  1566. struct rtl_priv *rtlpriv = btcoexist->adapter;
  1567. if (!halbtc_is_bt_coexist_available(btcoexist))
  1568. return;
  1569. btcoexist->statistics.cnt_coex_dm_switch++;
  1570. halbtc_leave_low_power(btcoexist);
  1571. if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1572. if (btcoexist->board_info.btdm_ant_num == 1) {
  1573. btcoexist->stop_coex_dm = true;
  1574. ex_btc8723b1ant_coex_dm_reset(btcoexist);
  1575. exhalbtc_set_ant_num(rtlpriv,
  1576. BT_COEX_ANT_TYPE_DETECTED, 2);
  1577. ex_btc8723b2ant_init_hwconfig(btcoexist);
  1578. ex_btc8723b2ant_init_coex_dm(btcoexist);
  1579. btcoexist->stop_coex_dm = false;
  1580. }
  1581. }
  1582. halbtc_normal_low_power(btcoexist);
  1583. }
  1584. void exhalbtc_periodical(struct btc_coexist *btcoexist)
  1585. {
  1586. if (!halbtc_is_bt_coexist_available(btcoexist))
  1587. return;
  1588. btcoexist->statistics.cnt_periodical++;
  1589. halbtc_leave_low_power(btcoexist);
  1590. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1591. if (btcoexist->board_info.btdm_ant_num == 2)
  1592. ex_btc8821a2ant_periodical(btcoexist);
  1593. else if (btcoexist->board_info.btdm_ant_num == 1)
  1594. if (!halbtc_under_ips(btcoexist))
  1595. ex_btc8821a1ant_periodical(btcoexist);
  1596. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1597. if (btcoexist->board_info.btdm_ant_num == 2)
  1598. ex_btc8723b2ant_periodical(btcoexist);
  1599. else if (btcoexist->board_info.btdm_ant_num == 1)
  1600. ex_btc8723b1ant_periodical(btcoexist);
  1601. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1602. if (btcoexist->board_info.btdm_ant_num == 2)
  1603. ex_btc8192e2ant_periodical(btcoexist);
  1604. }
  1605. halbtc_normal_low_power(btcoexist);
  1606. }
  1607. void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
  1608. u8 code, u8 len, u8 *data)
  1609. {
  1610. if (!halbtc_is_bt_coexist_available(btcoexist))
  1611. return;
  1612. btcoexist->statistics.cnt_dbg_ctrl++;
  1613. halbtc_leave_low_power(btcoexist);
  1614. halbtc_normal_low_power(btcoexist);
  1615. }
  1616. void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
  1617. u32 offset, u32 span, u32 seconds)
  1618. {
  1619. if (!halbtc_is_bt_coexist_available(btcoexist))
  1620. return;
  1621. }
  1622. void exhalbtc_stack_update_profile_info(void)
  1623. {
  1624. }
  1625. void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
  1626. {
  1627. if (!halbtc_is_bt_coexist_available(btcoexist))
  1628. return;
  1629. btcoexist->stack_info.min_bt_rssi = bt_rssi;
  1630. }
  1631. void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
  1632. {
  1633. if (!halbtc_is_bt_coexist_available(btcoexist))
  1634. return;
  1635. btcoexist->stack_info.hci_version = hci_version;
  1636. }
  1637. void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
  1638. u16 bt_hci_version, u16 bt_patch_version)
  1639. {
  1640. if (!halbtc_is_bt_coexist_available(btcoexist))
  1641. return;
  1642. btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
  1643. btcoexist->bt_info.bt_hci_ver = bt_hci_version;
  1644. }
  1645. void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
  1646. {
  1647. switch (chip_type) {
  1648. default:
  1649. case BT_2WIRE:
  1650. case BT_ISSC_3WIRE:
  1651. case BT_ACCEL:
  1652. case BT_RTL8756:
  1653. btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
  1654. break;
  1655. case BT_CSR_BC4:
  1656. btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
  1657. break;
  1658. case BT_CSR_BC8:
  1659. btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
  1660. break;
  1661. case BT_RTL8723A:
  1662. btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
  1663. break;
  1664. case BT_RTL8821A:
  1665. btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
  1666. break;
  1667. case BT_RTL8723B:
  1668. btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
  1669. break;
  1670. }
  1671. }
  1672. void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
  1673. {
  1674. struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
  1675. if (!btcoexist)
  1676. return;
  1677. if (BT_COEX_ANT_TYPE_PG == type) {
  1678. btcoexist->board_info.pg_ant_num = ant_num;
  1679. btcoexist->board_info.btdm_ant_num = ant_num;
  1680. } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
  1681. btcoexist->board_info.btdm_ant_num = ant_num;
  1682. } else if (type == BT_COEX_ANT_TYPE_DETECTED) {
  1683. btcoexist->board_info.btdm_ant_num = ant_num;
  1684. if (rtlpriv->cfg->mod_params->ant_sel == 1)
  1685. btcoexist->board_info.btdm_ant_pos =
  1686. BTC_ANTENNA_AT_AUX_PORT;
  1687. else
  1688. btcoexist->board_info.btdm_ant_pos =
  1689. BTC_ANTENNA_AT_MAIN_PORT;
  1690. }
  1691. }
  1692. /* Currently used by 8723b only, S0 or S1 */
  1693. void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
  1694. u8 single_ant_path)
  1695. {
  1696. btcoexist->board_info.single_ant_path = single_ant_path;
  1697. }
  1698. void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
  1699. struct seq_file *m)
  1700. {
  1701. if (!halbtc_is_bt_coexist_available(btcoexist))
  1702. return;
  1703. halbtc_leave_low_power(btcoexist);
  1704. if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
  1705. if (btcoexist->board_info.btdm_ant_num == 2)
  1706. ex_btc8821a2ant_display_coex_info(btcoexist, m);
  1707. else if (btcoexist->board_info.btdm_ant_num == 1)
  1708. ex_btc8821a1ant_display_coex_info(btcoexist, m);
  1709. } else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
  1710. if (btcoexist->board_info.btdm_ant_num == 2)
  1711. ex_btc8723b2ant_display_coex_info(btcoexist, m);
  1712. else if (btcoexist->board_info.btdm_ant_num == 1)
  1713. ex_btc8723b1ant_display_coex_info(btcoexist, m);
  1714. } else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
  1715. if (btcoexist->board_info.btdm_ant_num == 2)
  1716. ex_btc8192e2ant_display_coex_info(btcoexist, m);
  1717. }
  1718. halbtc_normal_low_power(btcoexist);
  1719. }
  1720. void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
  1721. {
  1722. if (!halbtc_is_bt_coexist_available(btcoexist))
  1723. return;
  1724. if (btcoexist->manual_control)
  1725. return;
  1726. halbtc_leave_low_power(btcoexist);
  1727. halbtc_normal_low_power(btcoexist);
  1728. }
  1729. void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
  1730. u8 is_5g)
  1731. {
  1732. }