halbtc8821a1ant.c 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256
  1. /* ************************************************************
  2. * Description:
  3. *
  4. * This file is for 8821A_1ANT Co-exist mechanism
  5. *
  6. * History
  7. * 2012/11/15 Cosa first check in.
  8. *
  9. * ************************************************************
  10. * SY modify 2015/04/27
  11. * ************************************************************
  12. * include files
  13. * ************************************************************ */
  14. #include "mp_precomp.h"
  15. #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
  16. #if (RTL8821A_SUPPORT == 1)
  17. /* ************************************************************
  18. * Global variables, these are static variables
  19. * ************************************************************ */
  20. static u8 *trace_buf = &gl_btc_trace_buf[0];
  21. static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant;
  22. static struct coex_dm_8821a_1ant *coex_dm = &glcoex_dm_8821a_1ant;
  23. static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant;
  24. static struct coex_sta_8821a_1ant *coex_sta = &glcoex_sta_8821a_1ant;
  25. const char *const glbt_info_src_8821a_1ant[] = {
  26. "BT Info[wifi fw]",
  27. "BT Info[bt rsp]",
  28. "BT Info[bt auto report]",
  29. };
  30. u32 glcoex_ver_date_8821a_1ant = 20161128;
  31. u32 glcoex_ver_8821a_1ant = 0x64;
  32. u32 glcoex_ver_btdesired_8821a_1ant = 0x62;
  33. /* ************************************************************
  34. * local function proto type if needed
  35. * ************************************************************
  36. * ************************************************************
  37. * local function start with halbtc8821a1ant_
  38. * ************************************************************ */
  39. u8 halbtc8821a1ant_bt_rssi_state(u8 level_num, u8 rssi_thresh, u8 rssi_thresh1)
  40. {
  41. s32 bt_rssi = 0;
  42. u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
  43. bt_rssi = coex_sta->bt_rssi;
  44. if (level_num == 2) {
  45. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  46. (coex_sta->pre_bt_rssi_state ==
  47. BTC_RSSI_STATE_STAY_LOW)) {
  48. if (bt_rssi >= (rssi_thresh +
  49. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
  50. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  51. else
  52. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  53. } else {
  54. if (bt_rssi < rssi_thresh)
  55. bt_rssi_state = BTC_RSSI_STATE_LOW;
  56. else
  57. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  58. }
  59. } else if (level_num == 3) {
  60. if (rssi_thresh > rssi_thresh1) {
  61. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  62. "[BTCoex], BT Rssi thresh error!!\n");
  63. BTC_TRACE(trace_buf);
  64. return coex_sta->pre_bt_rssi_state;
  65. }
  66. if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
  67. (coex_sta->pre_bt_rssi_state ==
  68. BTC_RSSI_STATE_STAY_LOW)) {
  69. if (bt_rssi >= (rssi_thresh +
  70. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
  71. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  72. else
  73. bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  74. } else if ((coex_sta->pre_bt_rssi_state ==
  75. BTC_RSSI_STATE_MEDIUM) ||
  76. (coex_sta->pre_bt_rssi_state ==
  77. BTC_RSSI_STATE_STAY_MEDIUM)) {
  78. if (bt_rssi >= (rssi_thresh1 +
  79. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
  80. bt_rssi_state = BTC_RSSI_STATE_HIGH;
  81. else if (bt_rssi < rssi_thresh)
  82. bt_rssi_state = BTC_RSSI_STATE_LOW;
  83. else
  84. bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  85. } else {
  86. if (bt_rssi < rssi_thresh1)
  87. bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
  88. else
  89. bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  90. }
  91. }
  92. coex_sta->pre_bt_rssi_state = bt_rssi_state;
  93. return bt_rssi_state;
  94. }
  95. u8 halbtc8821a1ant_wifi_rssi_state(IN struct btc_coexist *btcoexist,
  96. IN u8 index, IN u8 level_num, IN u8 rssi_thresh, IN u8 rssi_thresh1)
  97. {
  98. s32 wifi_rssi = 0;
  99. u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
  100. btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
  101. if (level_num == 2) {
  102. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  103. ||
  104. (coex_sta->pre_wifi_rssi_state[index] ==
  105. BTC_RSSI_STATE_STAY_LOW)) {
  106. if (wifi_rssi >= (rssi_thresh +
  107. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
  108. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  109. else
  110. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  111. } else {
  112. if (wifi_rssi < rssi_thresh)
  113. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  114. else
  115. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  116. }
  117. } else if (level_num == 3) {
  118. if (rssi_thresh > rssi_thresh1) {
  119. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  120. "[BTCoex], wifi RSSI thresh error!!\n");
  121. BTC_TRACE(trace_buf);
  122. return coex_sta->pre_wifi_rssi_state[index];
  123. }
  124. if ((coex_sta->pre_wifi_rssi_state[index] == BTC_RSSI_STATE_LOW)
  125. ||
  126. (coex_sta->pre_wifi_rssi_state[index] ==
  127. BTC_RSSI_STATE_STAY_LOW)) {
  128. if (wifi_rssi >= (rssi_thresh +
  129. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
  130. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  131. else
  132. wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
  133. } else if ((coex_sta->pre_wifi_rssi_state[index] ==
  134. BTC_RSSI_STATE_MEDIUM) ||
  135. (coex_sta->pre_wifi_rssi_state[index] ==
  136. BTC_RSSI_STATE_STAY_MEDIUM)) {
  137. if (wifi_rssi >= (rssi_thresh1 +
  138. BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))
  139. wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  140. else if (wifi_rssi < rssi_thresh)
  141. wifi_rssi_state = BTC_RSSI_STATE_LOW;
  142. else
  143. wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
  144. } else {
  145. if (wifi_rssi < rssi_thresh1)
  146. wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
  147. else
  148. wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
  149. }
  150. }
  151. coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
  152. return wifi_rssi_state;
  153. }
  154. void halbtc8821a1ant_update_ra_mask(IN struct btc_coexist *btcoexist,
  155. IN boolean force_exec, IN u32 dis_rate_mask)
  156. {
  157. coex_dm->cur_ra_mask = dis_rate_mask;
  158. if (force_exec || (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask))
  159. btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
  160. &coex_dm->cur_ra_mask);
  161. coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
  162. }
  163. void halbtc8821a1ant_auto_rate_fallback_retry(IN struct btc_coexist *btcoexist,
  164. IN boolean force_exec, IN u8 type)
  165. {
  166. boolean wifi_under_b_mode = false;
  167. coex_dm->cur_arfr_type = type;
  168. if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
  169. switch (coex_dm->cur_arfr_type) {
  170. case 0: /* normal mode */
  171. btcoexist->btc_write_4byte(btcoexist, 0x430,
  172. coex_dm->backup_arfr_cnt1);
  173. btcoexist->btc_write_4byte(btcoexist, 0x434,
  174. coex_dm->backup_arfr_cnt2);
  175. break;
  176. case 1:
  177. btcoexist->btc_get(btcoexist,
  178. BTC_GET_BL_WIFI_UNDER_B_MODE,
  179. &wifi_under_b_mode);
  180. if (wifi_under_b_mode) {
  181. btcoexist->btc_write_4byte(btcoexist,
  182. 0x430, 0x0);
  183. btcoexist->btc_write_4byte(btcoexist,
  184. 0x434, 0x01010101);
  185. } else {
  186. btcoexist->btc_write_4byte(btcoexist,
  187. 0x430, 0x0);
  188. btcoexist->btc_write_4byte(btcoexist,
  189. 0x434, 0x04030201);
  190. }
  191. break;
  192. default:
  193. break;
  194. }
  195. }
  196. coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
  197. }
  198. void halbtc8821a1ant_retry_limit(IN struct btc_coexist *btcoexist,
  199. IN boolean force_exec, IN u8 type)
  200. {
  201. coex_dm->cur_retry_limit_type = type;
  202. if (force_exec ||
  203. (coex_dm->pre_retry_limit_type !=
  204. coex_dm->cur_retry_limit_type)) {
  205. switch (coex_dm->cur_retry_limit_type) {
  206. case 0: /* normal mode */
  207. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  208. coex_dm->backup_retry_limit);
  209. break;
  210. case 1: /* retry limit=8 */
  211. btcoexist->btc_write_2byte(btcoexist, 0x42a,
  212. 0x0808);
  213. break;
  214. default:
  215. break;
  216. }
  217. }
  218. coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
  219. }
  220. void halbtc8821a1ant_ampdu_max_time(IN struct btc_coexist *btcoexist,
  221. IN boolean force_exec, IN u8 type)
  222. {
  223. coex_dm->cur_ampdu_time_type = type;
  224. if (force_exec ||
  225. (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
  226. switch (coex_dm->cur_ampdu_time_type) {
  227. case 0: /* normal mode */
  228. btcoexist->btc_write_1byte(btcoexist, 0x456,
  229. coex_dm->backup_ampdu_max_time);
  230. break;
  231. case 1: /* AMPDU timw = 0x38 * 32us */
  232. btcoexist->btc_write_1byte(btcoexist, 0x456,
  233. 0x38);
  234. break;
  235. default:
  236. break;
  237. }
  238. }
  239. coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
  240. }
  241. void halbtc8821a1ant_limited_tx(IN struct btc_coexist *btcoexist,
  242. IN boolean force_exec, IN u8 ra_mask_type, IN u8 arfr_type,
  243. IN u8 retry_limit_type, IN u8 ampdu_time_type)
  244. {
  245. switch (ra_mask_type) {
  246. case 0: /* normal mode */
  247. halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
  248. 0x0);
  249. break;
  250. case 1: /* disable cck 1/2 */
  251. halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
  252. 0x00000003);
  253. break;
  254. case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
  255. halbtc8821a1ant_update_ra_mask(btcoexist, force_exec,
  256. 0x0001f1f7);
  257. break;
  258. default:
  259. break;
  260. }
  261. halbtc8821a1ant_auto_rate_fallback_retry(btcoexist, force_exec,
  262. arfr_type);
  263. halbtc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
  264. halbtc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
  265. }
  266. /* true/xxxx/x:1
  267. * false/false/x: 64
  268. * false/true/x:x */
  269. void halbtc8821a1ant_limited_rx(IN struct btc_coexist *btcoexist,
  270. IN boolean force_exec, IN boolean rej_ap_agg_pkt,
  271. IN boolean bt_ctrl_agg_buf_size, IN u8 agg_buf_size)
  272. {
  273. boolean reject_rx_agg = rej_ap_agg_pkt;
  274. boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
  275. u8 rx_agg_size = agg_buf_size;
  276. /* ============================================ */
  277. /* Rx Aggregation related setting */
  278. /* ============================================ */
  279. btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
  280. &reject_rx_agg);
  281. /* decide BT control aggregation buf size or not */
  282. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
  283. &bt_ctrl_rx_agg_size);
  284. /* aggregation buf size, only work when BT control Rx aggregation size. */
  285. btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
  286. /* real update aggregation setting */
  287. btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
  288. }
  289. void halbtc8821a1ant_monitor_bt_ctr(IN struct btc_coexist *btcoexist)
  290. {
  291. u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
  292. u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
  293. #if 0
  294. /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
  295. if (!(btcoexist->btc_read_1byte(btcoexist, 0x76e) & 0x8)) {
  296. coex_sta->high_priority_tx = 65535;
  297. coex_sta->high_priority_rx = 65535;
  298. coex_sta->low_priority_tx = 65535;
  299. coex_sta->low_priority_rx = 65535;
  300. return;
  301. }
  302. #endif
  303. reg_hp_txrx = 0x770;
  304. reg_lp_txrx = 0x774;
  305. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
  306. reg_hp_tx = u32tmp & MASKLWORD;
  307. reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
  308. u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
  309. reg_lp_tx = u32tmp & MASKLWORD;
  310. reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
  311. coex_sta->high_priority_tx = reg_hp_tx;
  312. coex_sta->high_priority_rx = reg_hp_rx;
  313. coex_sta->low_priority_tx = reg_lp_tx;
  314. coex_sta->low_priority_rx = reg_lp_rx;
  315. /* reset counter */
  316. btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
  317. }
  318. void halbtc8821a1ant_monitor_wifi_ctr(IN struct btc_coexist *btcoexist)
  319. {
  320. #if 1
  321. coex_sta->crc_ok_cck = btcoexist->btc_phydm_query_PHY_counter(
  322. btcoexist,
  323. PHYDM_INFO_CRC32_OK_CCK);
  324. coex_sta->crc_ok_11g = btcoexist->btc_phydm_query_PHY_counter(
  325. btcoexist,
  326. PHYDM_INFO_CRC32_OK_LEGACY);
  327. coex_sta->crc_ok_11n = btcoexist->btc_phydm_query_PHY_counter(
  328. btcoexist,
  329. PHYDM_INFO_CRC32_OK_HT);
  330. coex_sta->crc_ok_11n_vht =
  331. btcoexist->btc_phydm_query_PHY_counter(
  332. btcoexist,
  333. PHYDM_INFO_CRC32_OK_VHT);
  334. coex_sta->crc_err_cck = btcoexist->btc_phydm_query_PHY_counter(
  335. btcoexist,
  336. PHYDM_INFO_CRC32_ERROR_CCK);
  337. coex_sta->crc_err_11g = btcoexist->btc_phydm_query_PHY_counter(
  338. btcoexist,
  339. PHYDM_INFO_CRC32_ERROR_LEGACY);
  340. coex_sta->crc_err_11n = btcoexist->btc_phydm_query_PHY_counter(
  341. btcoexist,
  342. PHYDM_INFO_CRC32_ERROR_HT);
  343. coex_sta->crc_err_11n_vht =
  344. btcoexist->btc_phydm_query_PHY_counter(
  345. btcoexist,
  346. PHYDM_INFO_CRC32_ERROR_VHT);
  347. #endif
  348. }
  349. void halbtc8821a1ant_query_bt_info(IN struct btc_coexist *btcoexist)
  350. {
  351. u8 h2c_parameter[1] = {0};
  352. coex_sta->c2h_bt_info_req_sent = true;
  353. h2c_parameter[0] |= BIT(0); /* trigger */
  354. btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
  355. }
  356. boolean halbtc8821a1ant_is_wifi_status_changed(IN struct btc_coexist *btcoexist)
  357. {
  358. static boolean pre_wifi_busy = false, pre_under_4way = false,
  359. pre_bt_hs_on = false;
  360. boolean wifi_busy = false, under_4way = false, bt_hs_on = false;
  361. boolean wifi_connected = false;
  362. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  363. &wifi_connected);
  364. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  365. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  366. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  367. &under_4way);
  368. if (wifi_connected) {
  369. if (wifi_busy != pre_wifi_busy) {
  370. pre_wifi_busy = wifi_busy;
  371. return true;
  372. }
  373. if (under_4way != pre_under_4way) {
  374. pre_under_4way = under_4way;
  375. return true;
  376. }
  377. if (bt_hs_on != pre_bt_hs_on) {
  378. pre_bt_hs_on = bt_hs_on;
  379. return true;
  380. }
  381. }
  382. return false;
  383. }
  384. void halbtc8821a1ant_update_bt_link_info(IN struct btc_coexist *btcoexist)
  385. {
  386. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  387. boolean bt_hs_on = false;
  388. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  389. bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
  390. bt_link_info->sco_exist = coex_sta->sco_exist;
  391. bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
  392. bt_link_info->pan_exist = coex_sta->pan_exist;
  393. bt_link_info->hid_exist = coex_sta->hid_exist;
  394. /* work around for HS mode. */
  395. if (bt_hs_on) {
  396. bt_link_info->pan_exist = true;
  397. bt_link_info->bt_link_exist = true;
  398. }
  399. /* check if Sco only */
  400. if (bt_link_info->sco_exist &&
  401. !bt_link_info->a2dp_exist &&
  402. !bt_link_info->pan_exist &&
  403. !bt_link_info->hid_exist)
  404. bt_link_info->sco_only = true;
  405. else
  406. bt_link_info->sco_only = false;
  407. /* check if A2dp only */
  408. if (!bt_link_info->sco_exist &&
  409. bt_link_info->a2dp_exist &&
  410. !bt_link_info->pan_exist &&
  411. !bt_link_info->hid_exist)
  412. bt_link_info->a2dp_only = true;
  413. else
  414. bt_link_info->a2dp_only = false;
  415. /* check if Pan only */
  416. if (!bt_link_info->sco_exist &&
  417. !bt_link_info->a2dp_exist &&
  418. bt_link_info->pan_exist &&
  419. !bt_link_info->hid_exist)
  420. bt_link_info->pan_only = true;
  421. else
  422. bt_link_info->pan_only = false;
  423. /* check if Hid only */
  424. if (!bt_link_info->sco_exist &&
  425. !bt_link_info->a2dp_exist &&
  426. !bt_link_info->pan_exist &&
  427. bt_link_info->hid_exist)
  428. bt_link_info->hid_only = true;
  429. else
  430. bt_link_info->hid_only = false;
  431. }
  432. u8 halbtc8821a1ant_action_algorithm(IN struct btc_coexist *btcoexist)
  433. {
  434. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  435. boolean bt_hs_on = false;
  436. u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED;
  437. u8 num_of_diff_profile = 0;
  438. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  439. if (!bt_link_info->bt_link_exist) {
  440. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  441. "[BTCoex], No BT link exists!!!\n");
  442. BTC_TRACE(trace_buf);
  443. return algorithm;
  444. }
  445. if (bt_link_info->sco_exist)
  446. num_of_diff_profile++;
  447. if (bt_link_info->hid_exist)
  448. num_of_diff_profile++;
  449. if (bt_link_info->pan_exist)
  450. num_of_diff_profile++;
  451. if (bt_link_info->a2dp_exist)
  452. num_of_diff_profile++;
  453. if (num_of_diff_profile == 1) {
  454. if (bt_link_info->sco_exist) {
  455. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  456. "[BTCoex], BT Profile = SCO only\n");
  457. BTC_TRACE(trace_buf);
  458. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  459. } else {
  460. if (bt_link_info->hid_exist) {
  461. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  462. "[BTCoex], BT Profile = HID only\n");
  463. BTC_TRACE(trace_buf);
  464. algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
  465. } else if (bt_link_info->a2dp_exist) {
  466. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  467. "[BTCoex], BT Profile = A2DP only\n");
  468. BTC_TRACE(trace_buf);
  469. algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;
  470. } else if (bt_link_info->pan_exist) {
  471. if (bt_hs_on) {
  472. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  473. "[BTCoex], BT Profile = PAN(HS) only\n");
  474. BTC_TRACE(trace_buf);
  475. algorithm =
  476. BT_8821A_1ANT_COEX_ALGO_PANHS;
  477. } else {
  478. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  479. "[BTCoex], BT Profile = PAN(EDR) only\n");
  480. BTC_TRACE(trace_buf);
  481. algorithm =
  482. BT_8821A_1ANT_COEX_ALGO_PANEDR;
  483. }
  484. }
  485. }
  486. } else if (num_of_diff_profile == 2) {
  487. if (bt_link_info->sco_exist) {
  488. if (bt_link_info->hid_exist) {
  489. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  490. "[BTCoex], BT Profile = SCO + HID\n");
  491. BTC_TRACE(trace_buf);
  492. algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
  493. } else if (bt_link_info->a2dp_exist) {
  494. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  495. "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
  496. BTC_TRACE(trace_buf);
  497. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  498. } else if (bt_link_info->pan_exist) {
  499. if (bt_hs_on) {
  500. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  501. "[BTCoex], BT Profile = SCO + PAN(HS)\n");
  502. BTC_TRACE(trace_buf);
  503. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  504. } else {
  505. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  506. "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
  507. BTC_TRACE(trace_buf);
  508. algorithm =
  509. BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  510. }
  511. }
  512. } else {
  513. if (bt_link_info->hid_exist &&
  514. bt_link_info->a2dp_exist) {
  515. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  516. "[BTCoex], BT Profile = HID + A2DP\n");
  517. BTC_TRACE(trace_buf);
  518. algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  519. } else if (bt_link_info->hid_exist &&
  520. bt_link_info->pan_exist) {
  521. if (bt_hs_on) {
  522. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  523. "[BTCoex], BT Profile = HID + PAN(HS)\n");
  524. BTC_TRACE(trace_buf);
  525. algorithm =
  526. BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  527. } else {
  528. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  529. "[BTCoex], BT Profile = HID + PAN(EDR)\n");
  530. BTC_TRACE(trace_buf);
  531. algorithm =
  532. BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  533. }
  534. } else if (bt_link_info->pan_exist &&
  535. bt_link_info->a2dp_exist) {
  536. if (bt_hs_on) {
  537. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  538. "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
  539. BTC_TRACE(trace_buf);
  540. algorithm =
  541. BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;
  542. } else {
  543. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  544. "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
  545. BTC_TRACE(trace_buf);
  546. algorithm =
  547. BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;
  548. }
  549. }
  550. }
  551. } else if (num_of_diff_profile == 3) {
  552. if (bt_link_info->sco_exist) {
  553. if (bt_link_info->hid_exist &&
  554. bt_link_info->a2dp_exist) {
  555. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  556. "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
  557. BTC_TRACE(trace_buf);
  558. algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
  559. } else if (bt_link_info->hid_exist &&
  560. bt_link_info->pan_exist) {
  561. if (bt_hs_on) {
  562. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  563. "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
  564. BTC_TRACE(trace_buf);
  565. algorithm =
  566. BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  567. } else {
  568. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  569. "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
  570. BTC_TRACE(trace_buf);
  571. algorithm =
  572. BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  573. }
  574. } else if (bt_link_info->pan_exist &&
  575. bt_link_info->a2dp_exist) {
  576. if (bt_hs_on) {
  577. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  578. "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
  579. BTC_TRACE(trace_buf);
  580. algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
  581. } else {
  582. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  583. "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
  584. BTC_TRACE(trace_buf);
  585. algorithm =
  586. BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  587. }
  588. }
  589. } else {
  590. if (bt_link_info->hid_exist &&
  591. bt_link_info->pan_exist &&
  592. bt_link_info->a2dp_exist) {
  593. if (bt_hs_on) {
  594. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  595. "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
  596. BTC_TRACE(trace_buf);
  597. algorithm =
  598. BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
  599. } else {
  600. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  601. "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
  602. BTC_TRACE(trace_buf);
  603. algorithm =
  604. BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
  605. }
  606. }
  607. }
  608. } else if (num_of_diff_profile >= 3) {
  609. if (bt_link_info->sco_exist) {
  610. if (bt_link_info->hid_exist &&
  611. bt_link_info->pan_exist &&
  612. bt_link_info->a2dp_exist) {
  613. if (bt_hs_on) {
  614. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  615. "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
  616. BTC_TRACE(trace_buf);
  617. } else {
  618. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  619. "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
  620. BTC_TRACE(trace_buf);
  621. algorithm =
  622. BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
  623. }
  624. }
  625. }
  626. }
  627. return algorithm;
  628. }
  629. void halbtc8821a1ant_set_bt_auto_report(IN struct btc_coexist *btcoexist,
  630. IN boolean enable_auto_report)
  631. {
  632. u8 h2c_parameter[1] = {0};
  633. h2c_parameter[0] = 0;
  634. if (enable_auto_report)
  635. h2c_parameter[0] |= BIT(0);
  636. btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
  637. }
  638. void halbtc8821a1ant_bt_auto_report(IN struct btc_coexist *btcoexist,
  639. IN boolean force_exec, IN boolean enable_auto_report)
  640. {
  641. coex_dm->cur_bt_auto_report = enable_auto_report;
  642. if (!force_exec) {
  643. if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
  644. return;
  645. }
  646. halbtc8821a1ant_set_bt_auto_report(btcoexist,
  647. coex_dm->cur_bt_auto_report);
  648. coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
  649. }
  650. void halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(IN struct btc_coexist
  651. *btcoexist, IN boolean low_penalty_ra)
  652. {
  653. u8 h2c_parameter[6] = {0};
  654. h2c_parameter[0] = 0x6; /* op_code, 0x6= Retry_Penalty */
  655. if (low_penalty_ra) {
  656. h2c_parameter[1] |= BIT(0);
  657. h2c_parameter[2] =
  658. 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
  659. h2c_parameter[3] = 0xf5; /* MCS7 or OFDM54 */
  660. h2c_parameter[4] = 0xa0; /* MCS6 or OFDM48 */
  661. h2c_parameter[5] = 0xa0; /* MCS5 or OFDM36 */
  662. }
  663. btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
  664. }
  665. void halbtc8821a1ant_low_penalty_ra(IN struct btc_coexist *btcoexist,
  666. IN boolean force_exec, IN boolean low_penalty_ra)
  667. {
  668. coex_dm->cur_low_penalty_ra = low_penalty_ra;
  669. if (!force_exec) {
  670. if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
  671. return;
  672. }
  673. halbtc8821a1ant_set_sw_penalty_tx_rate_adaptive(btcoexist,
  674. coex_dm->cur_low_penalty_ra);
  675. coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
  676. }
  677. void halbtc8821a1ant_sw_mechanism(IN struct btc_coexist *btcoexist,
  678. IN boolean low_penalty_ra)
  679. {
  680. halbtc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
  681. }
  682. void halbtc8821a1ant_set_coex_table(IN struct btc_coexist *btcoexist,
  683. IN u32 val0x6c0, IN u32 val0x6c4, IN u32 val0x6c8, IN u8 val0x6cc)
  684. {
  685. btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
  686. btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
  687. btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
  688. btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
  689. }
  690. void halbtc8821a1ant_coex_table(IN struct btc_coexist *btcoexist,
  691. IN boolean force_exec, IN u32 val0x6c0, IN u32 val0x6c4,
  692. IN u32 val0x6c8, IN u8 val0x6cc)
  693. {
  694. coex_dm->cur_val0x6c0 = val0x6c0;
  695. coex_dm->cur_val0x6c4 = val0x6c4;
  696. coex_dm->cur_val0x6c8 = val0x6c8;
  697. coex_dm->cur_val0x6cc = val0x6cc;
  698. if (!force_exec) {
  699. if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
  700. (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
  701. (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
  702. (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
  703. return;
  704. }
  705. halbtc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, val0x6c8,
  706. val0x6cc);
  707. coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
  708. coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
  709. coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
  710. coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
  711. }
  712. void halbtc8821a1ant_coex_table_with_type(IN struct btc_coexist *btcoexist,
  713. IN boolean force_exec, IN u8 type)
  714. {
  715. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  716. "[BTCoex], ********** CoexTable(%d) **********\n", type);
  717. BTC_TRACE(trace_buf);
  718. switch (type) {
  719. case 0:
  720. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  721. 0x55555555, 0x55555555, 0xffffff, 0x3);
  722. break;
  723. case 1:
  724. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  725. 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
  726. break;
  727. case 2:
  728. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  729. 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
  730. break;
  731. case 3:
  732. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  733. 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);
  734. break;
  735. case 4:
  736. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  737. 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
  738. break;
  739. case 5:
  740. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  741. 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);
  742. break;
  743. case 6:
  744. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  745. 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
  746. break;
  747. case 7:
  748. halbtc8821a1ant_coex_table(btcoexist, force_exec,
  749. 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
  750. break;
  751. default:
  752. break;
  753. }
  754. }
  755. void halbtc8821a1ant_set_fw_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  756. IN boolean enable)
  757. {
  758. u8 h2c_parameter[1] = {0};
  759. if (enable)
  760. h2c_parameter[0] |= BIT(0); /* function enable */
  761. btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
  762. }
  763. void halbtc8821a1ant_ignore_wlan_act(IN struct btc_coexist *btcoexist,
  764. IN boolean force_exec, IN boolean enable)
  765. {
  766. coex_dm->cur_ignore_wlan_act = enable;
  767. if (!force_exec) {
  768. if (coex_dm->pre_ignore_wlan_act ==
  769. coex_dm->cur_ignore_wlan_act)
  770. return;
  771. }
  772. halbtc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
  773. coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
  774. }
  775. void halbtc8821a1ant_set_lps_rpwm(IN struct btc_coexist *btcoexist,
  776. IN u8 lps_val, IN u8 rpwm_val)
  777. {
  778. u8 lps = lps_val;
  779. u8 rpwm = rpwm_val;
  780. btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
  781. btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
  782. }
  783. void halbtc8821a1ant_lps_rpwm(IN struct btc_coexist *btcoexist,
  784. IN boolean force_exec, IN u8 lps_val, IN u8 rpwm_val)
  785. {
  786. coex_dm->cur_lps = lps_val;
  787. coex_dm->cur_rpwm = rpwm_val;
  788. if (!force_exec) {
  789. if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
  790. (coex_dm->pre_rpwm == coex_dm->cur_rpwm))
  791. return;
  792. }
  793. halbtc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
  794. coex_dm->pre_lps = coex_dm->cur_lps;
  795. coex_dm->pre_rpwm = coex_dm->cur_rpwm;
  796. }
  797. void halbtc8821a1ant_set_ant_path(IN struct btc_coexist *btcoexist,
  798. IN u8 ant_pos_type, IN boolean init_hwcfg, IN boolean wifi_off)
  799. {
  800. struct btc_board_info *board_info = &btcoexist->board_info;
  801. u32 u32tmp = 0;
  802. u8 h2c_parameter[2] = {0};
  803. if (init_hwcfg) {
  804. /* 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT */
  805. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  806. u32tmp &= ~BIT(23);
  807. u32tmp |= BIT(24);
  808. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  809. /* 0x765 = 0x18 */
  810. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
  811. if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
  812. /* tell firmware "antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
  813. h2c_parameter[0] = 1;
  814. h2c_parameter[1] = 1;
  815. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  816. h2c_parameter);
  817. /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x1); */ /*Main Ant to BT for IPS case 0x4c[23]=1 */
  818. } else {
  819. /* tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix */
  820. h2c_parameter[0] = 0;
  821. h2c_parameter[1] = 1;
  822. btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
  823. h2c_parameter);
  824. /* btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x0); */ /*Aux Ant to BT for IPS case 0x4c[23]=1 */
  825. }
  826. } else if (wifi_off) {
  827. /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac=0xf002 */
  828. u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  829. u32tmp &= ~BIT(23);
  830. u32tmp &= ~BIT(24);
  831. btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
  832. /* 0x765 = 0x18 */
  833. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x3);
  834. } else {
  835. /* 0x765 = 0x0 */
  836. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x765, 0x18, 0x0);
  837. }
  838. /* ext switch setting */
  839. switch (ant_pos_type) {
  840. case BTC_ANT_PATH_WIFI:
  841. btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
  842. if (board_info->btdm_ant_pos ==
  843. BTC_ANTENNA_AT_MAIN_PORT)
  844. btcoexist->btc_write_1byte_bitmask(btcoexist,
  845. 0xcb7, 0x30, 0x1);
  846. else
  847. btcoexist->btc_write_1byte_bitmask(btcoexist,
  848. 0xcb7, 0x30, 0x2);
  849. break;
  850. case BTC_ANT_PATH_BT:
  851. btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
  852. if (board_info->btdm_ant_pos ==
  853. BTC_ANTENNA_AT_MAIN_PORT)
  854. btcoexist->btc_write_1byte_bitmask(btcoexist,
  855. 0xcb7, 0x30, 0x2);
  856. else
  857. btcoexist->btc_write_1byte_bitmask(btcoexist,
  858. 0xcb7, 0x30, 0x1);
  859. break;
  860. default:
  861. case BTC_ANT_PATH_PTA:
  862. btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x66);
  863. if (board_info->btdm_ant_pos ==
  864. BTC_ANTENNA_AT_MAIN_PORT)
  865. btcoexist->btc_write_1byte_bitmask(btcoexist,
  866. 0xcb7, 0x30, 0x1);
  867. else
  868. btcoexist->btc_write_1byte_bitmask(btcoexist,
  869. 0xcb7, 0x30, 0x2);
  870. break;
  871. }
  872. }
  873. void halbtc8821a1ant_ps_tdma_check_for_power_save_state(
  874. IN struct btc_coexist *btcoexist, IN boolean new_ps_state)
  875. {
  876. u8 lps_mode = 0x0;
  877. u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
  878. btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
  879. if (lps_mode) { /* already under LPS state */
  880. if (new_ps_state) {
  881. /* keep state under LPS, do nothing. */
  882. } else {
  883. /* will leave LPS state, turn off psTdma first */
  884. /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,8); */
  885. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  886. h2c_parameter);
  887. }
  888. } else { /* NO PS state */
  889. if (new_ps_state) {
  890. /* will enter LPS state, turn off psTdma first */
  891. /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,8); */
  892. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5,
  893. h2c_parameter);
  894. } else {
  895. /* keep state under NO PS state, do nothing. */
  896. }
  897. }
  898. }
  899. void halbtc8821a1ant_power_save_state(IN struct btc_coexist *btcoexist,
  900. IN u8 ps_type, IN u8 lps_val, IN u8 rpwm_val)
  901. {
  902. boolean low_pwr_disable = false;
  903. switch (ps_type) {
  904. case BTC_PS_WIFI_NATIVE:
  905. /* recover to original 32k low power setting */
  906. low_pwr_disable = false;
  907. btcoexist->btc_set(btcoexist,
  908. BTC_SET_ACT_DISABLE_LOW_POWER,
  909. &low_pwr_disable);
  910. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  911. NULL);
  912. break;
  913. case BTC_PS_LPS_ON:
  914. halbtc8821a1ant_ps_tdma_check_for_power_save_state(
  915. btcoexist, true);
  916. halbtc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC,
  917. lps_val, rpwm_val);
  918. /* when coex force to enter LPS, do not enter 32k low power. */
  919. low_pwr_disable = true;
  920. btcoexist->btc_set(btcoexist,
  921. BTC_SET_ACT_DISABLE_LOW_POWER,
  922. &low_pwr_disable);
  923. /* power save must executed before psTdma. */
  924. btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS,
  925. NULL);
  926. break;
  927. case BTC_PS_LPS_OFF:
  928. halbtc8821a1ant_ps_tdma_check_for_power_save_state(
  929. btcoexist, false);
  930. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  931. NULL);
  932. break;
  933. default:
  934. break;
  935. }
  936. }
  937. void halbtc8821a1ant_set_fw_pstdma(IN struct btc_coexist *btcoexist,
  938. IN u8 byte1, IN u8 byte2, IN u8 byte3, IN u8 byte4, IN u8 byte5)
  939. {
  940. u8 h2c_parameter[5] = {0};
  941. u8 real_byte1 = byte1, real_byte5 = byte5;
  942. boolean ap_enable = false;
  943. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  944. &ap_enable);
  945. if (ap_enable) {
  946. if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  947. real_byte1 &= ~BIT(4);
  948. real_byte1 |= BIT(5);
  949. real_byte5 |= BIT(5);
  950. real_byte5 &= ~BIT(6);
  951. halbtc8821a1ant_power_save_state(btcoexist,
  952. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  953. }
  954. } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
  955. halbtc8821a1ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 0x4);
  956. } else {
  957. halbtc8821a1ant_power_save_state(btcoexist,
  958. BTC_PS_WIFI_NATIVE, 0x0, 0x0);
  959. }
  960. h2c_parameter[0] = real_byte1;
  961. h2c_parameter[1] = byte2;
  962. h2c_parameter[2] = byte3;
  963. h2c_parameter[3] = byte4;
  964. h2c_parameter[4] = real_byte5;
  965. coex_dm->ps_tdma_para[0] = real_byte1;
  966. coex_dm->ps_tdma_para[1] = byte2;
  967. coex_dm->ps_tdma_para[2] = byte3;
  968. coex_dm->ps_tdma_para[3] = byte4;
  969. coex_dm->ps_tdma_para[4] = real_byte5;
  970. btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
  971. }
  972. void halbtc8821a1ant_ps_tdma(IN struct btc_coexist *btcoexist,
  973. IN boolean force_exec, IN boolean turn_on, IN u8 type)
  974. {
  975. u8 rssi_adjust_val = 0;
  976. /* u32 fw_ver=0; */
  977. coex_dm->cur_ps_tdma_on = turn_on;
  978. coex_dm->cur_ps_tdma = type;
  979. if (coex_dm->cur_ps_tdma_on) {
  980. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  981. "[BTCoex], ********** TDMA(on, %d) **********\n",
  982. coex_dm->cur_ps_tdma);
  983. BTC_TRACE(trace_buf);
  984. } else {
  985. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  986. "[BTCoex], ********** TDMA(off, %d) **********\n",
  987. coex_dm->cur_ps_tdma);
  988. BTC_TRACE(trace_buf);
  989. }
  990. if (!force_exec) {
  991. if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
  992. (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
  993. return;
  994. }
  995. if (turn_on) {
  996. switch (type) {
  997. default:
  998. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  999. 0x1a, 0x1a, 0x0, 0x50);
  1000. break;
  1001. case 1:
  1002. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1003. 0x3a, 0x03, 0x10, 0x50);
  1004. rssi_adjust_val = 11;
  1005. break;
  1006. case 2:
  1007. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1008. 0x2b, 0x03, 0x10, 0x50);
  1009. rssi_adjust_val = 14;
  1010. break;
  1011. case 3:
  1012. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1013. 0x1d, 0x1d, 0x0, 0x52);
  1014. break;
  1015. case 4:
  1016. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
  1017. 0x15, 0x3, 0x14, 0x0);
  1018. rssi_adjust_val = 17;
  1019. break;
  1020. case 5:
  1021. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
  1022. 0x15, 0x3, 0x11, 0x10);
  1023. break;
  1024. case 6:
  1025. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
  1026. 0x20, 0x3, 0x11, 0x13);
  1027. break;
  1028. case 7:
  1029. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
  1030. 0xc, 0x5, 0x0, 0x0);
  1031. break;
  1032. case 8:
  1033. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
  1034. 0x25, 0x3, 0x10, 0x0);
  1035. break;
  1036. case 9:
  1037. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1038. 0x21, 0x3, 0x10, 0x50);
  1039. rssi_adjust_val = 18;
  1040. break;
  1041. case 10:
  1042. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
  1043. 0xa, 0xa, 0x0, 0x40);
  1044. break;
  1045. case 11:
  1046. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1047. 0x15, 0x03, 0x10, 0x50);
  1048. rssi_adjust_val = 20;
  1049. break;
  1050. case 12:
  1051. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1052. 0x0a, 0x0a, 0x0, 0x50);
  1053. break;
  1054. case 13:
  1055. if (coex_sta->scan_ap_num <= 5)
  1056. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1057. 0x40, 0x3, 0x10, 0x50);
  1058. else
  1059. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1060. 0x12, 0x12, 0x0, 0x50);
  1061. break;
  1062. case 14:
  1063. if (coex_sta->scan_ap_num <= 5)
  1064. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1065. 0x30, 0x3, 0x10, 0x50);
  1066. else
  1067. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1068. 0x1e, 0x3, 0x10, 0x14);
  1069. break;
  1070. case 15:
  1071. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x13,
  1072. 0xa, 0x3, 0x8, 0x0);
  1073. break;
  1074. case 16:
  1075. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
  1076. 0x15, 0x3, 0x10, 0x0);
  1077. rssi_adjust_val = 18;
  1078. break;
  1079. case 18:
  1080. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x93,
  1081. 0x25, 0x3, 0x10, 0x0);
  1082. rssi_adjust_val = 14;
  1083. break;
  1084. case 20:
  1085. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
  1086. 0x35, 0x03, 0x11, 0x10);
  1087. break;
  1088. case 21:
  1089. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
  1090. 0x25, 0x03, 0x11, 0x11);
  1091. break;
  1092. case 22:
  1093. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
  1094. 0x25, 0x03, 0x11, 0x10);
  1095. break;
  1096. case 23:
  1097. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1098. 0x25, 0x3, 0x31, 0x18);
  1099. rssi_adjust_val = 22;
  1100. break;
  1101. case 24:
  1102. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1103. 0x15, 0x3, 0x31, 0x18);
  1104. rssi_adjust_val = 22;
  1105. break;
  1106. case 25:
  1107. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1108. 0xa, 0x3, 0x31, 0x18);
  1109. rssi_adjust_val = 22;
  1110. break;
  1111. case 26:
  1112. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1113. 0xa, 0x3, 0x31, 0x18);
  1114. rssi_adjust_val = 22;
  1115. break;
  1116. case 27:
  1117. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xe3,
  1118. 0x25, 0x3, 0x31, 0x98);
  1119. rssi_adjust_val = 22;
  1120. break;
  1121. case 28:
  1122. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x69,
  1123. 0x25, 0x3, 0x31, 0x0);
  1124. break;
  1125. case 29:
  1126. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xab,
  1127. 0x1a, 0x1a, 0x1, 0x10);
  1128. break;
  1129. case 30:
  1130. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1131. 0x30, 0x3, 0x10, 0x10);
  1132. break;
  1133. case 31:
  1134. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
  1135. 0x1a, 0x1a, 0, 0x58);
  1136. break;
  1137. case 32:
  1138. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x61,
  1139. 0x35, 0x3, 0x11, 0x11);
  1140. break;
  1141. case 33:
  1142. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xa3,
  1143. 0x25, 0x3, 0x30, 0x90);
  1144. break;
  1145. case 34:
  1146. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x53,
  1147. 0x1a, 0x1a, 0x0, 0x10);
  1148. break;
  1149. case 35:
  1150. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x63,
  1151. 0x1a, 0x1a, 0x0, 0x10);
  1152. break;
  1153. case 36:
  1154. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0xd3,
  1155. 0x12, 0x3, 0x14, 0x50);
  1156. break;
  1157. case 40: /* SoftAP only with no sta associated,BT disable ,TDMA mode for power saving */
  1158. /* here softap mode screen off will cost 70-80mA for phone */
  1159. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x23,
  1160. 0x18, 0x00, 0x10, 0x24);
  1161. break;
  1162. case 41:
  1163. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1164. 0x15, 0x3, 0x11, 0x11);
  1165. break;
  1166. case 42:
  1167. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1168. 0x20, 0x3, 0x11, 0x11);
  1169. break;
  1170. case 43:
  1171. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x51,
  1172. 0x30, 0x3, 0x10, 0x11);
  1173. break;
  1174. }
  1175. } else {
  1176. /* disable PS tdma */
  1177. switch (type) {
  1178. case 8: /* PTA Control */
  1179. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x8,
  1180. 0x0, 0x0, 0x0, 0x0);
  1181. halbtc8821a1ant_set_ant_path(btcoexist,
  1182. BTC_ANT_PATH_PTA, false, false);
  1183. break;
  1184. case 0:
  1185. default: /* Software control, Antenna at BT side */
  1186. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
  1187. 0x0, 0x0, 0x0, 0x0);
  1188. halbtc8821a1ant_set_ant_path(btcoexist,
  1189. BTC_ANT_PATH_BT, false, false);
  1190. break;
  1191. case 9: /* Software control, Antenna at WiFi side */
  1192. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
  1193. 0x0, 0x0, 0x0, 0x0);
  1194. halbtc8821a1ant_set_ant_path(btcoexist,
  1195. BTC_ANT_PATH_WIFI, false, false);
  1196. break;
  1197. case 10: /* under 5G */
  1198. halbtc8821a1ant_set_fw_pstdma(btcoexist, 0x0,
  1199. 0x0, 0x0, 0x8, 0x0);
  1200. halbtc8821a1ant_set_ant_path(btcoexist,
  1201. BTC_ANT_PATH_BT, false, false);
  1202. break;
  1203. }
  1204. }
  1205. rssi_adjust_val = 0;
  1206. btcoexist->btc_set(btcoexist,
  1207. BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
  1208. /* update pre state */
  1209. coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
  1210. coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
  1211. }
  1212. void halbtc8821a1ant_coex_all_off(IN struct btc_coexist *btcoexist)
  1213. {
  1214. /* sw all off */
  1215. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1216. /* hw all off */
  1217. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1218. }
  1219. boolean halbtc8821a1ant_is_common_action(IN struct btc_coexist *btcoexist)
  1220. {
  1221. boolean common = false, wifi_connected = false, wifi_busy = false;
  1222. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1223. &wifi_connected);
  1224. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1225. if (!wifi_connected &&
  1226. BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1227. coex_dm->bt_status) {
  1228. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1229. "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
  1230. BTC_TRACE(trace_buf);
  1231. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1232. common = true;
  1233. } else if (wifi_connected &&
  1234. (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  1235. coex_dm->bt_status)) {
  1236. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1237. "[BTCoex], Wifi connected + BT non connected-idle!!\n");
  1238. BTC_TRACE(trace_buf);
  1239. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1240. common = true;
  1241. } else if (!wifi_connected &&
  1242. (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
  1243. coex_dm->bt_status)) {
  1244. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1245. "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
  1246. BTC_TRACE(trace_buf);
  1247. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1248. common = true;
  1249. } else if (wifi_connected &&
  1250. (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
  1251. coex_dm->bt_status)) {
  1252. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1253. "[BTCoex], Wifi connected + BT connected-idle!!\n");
  1254. BTC_TRACE(trace_buf);
  1255. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1256. common = true;
  1257. } else if (!wifi_connected &&
  1258. (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE !=
  1259. coex_dm->bt_status)) {
  1260. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1261. "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
  1262. BTC_TRACE(trace_buf);
  1263. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1264. common = true;
  1265. } else {
  1266. if (wifi_busy) {
  1267. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1268. "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
  1269. BTC_TRACE(trace_buf);
  1270. } else {
  1271. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1272. "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
  1273. BTC_TRACE(trace_buf);
  1274. }
  1275. common = false;
  1276. }
  1277. return common;
  1278. }
  1279. /* *********************************************
  1280. *
  1281. * Software Coex Mechanism start
  1282. *
  1283. * ********************************************* */
  1284. void halbtc8821a1ant_action_bt_whck_test(IN struct btc_coexist *btcoexist)
  1285. {
  1286. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1287. /* halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, false, false); */
  1288. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, false, false);
  1289. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1290. }
  1291. /* SCO only or SCO+PAN(HS) */
  1292. void halbtc8821a1ant_action_sco(IN struct btc_coexist *btcoexist)
  1293. {
  1294. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1295. }
  1296. void halbtc8821a1ant_action_hid(IN struct btc_coexist *btcoexist)
  1297. {
  1298. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1299. }
  1300. /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
  1301. void halbtc8821a1ant_action_a2dp(IN struct btc_coexist *btcoexist)
  1302. {
  1303. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1304. }
  1305. void halbtc8821a1ant_action_a2dp_pan_hs(IN struct btc_coexist *btcoexist)
  1306. {
  1307. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1308. }
  1309. void halbtc8821a1ant_action_pan_edr(IN struct btc_coexist *btcoexist)
  1310. {
  1311. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1312. }
  1313. /* PAN(HS) only */
  1314. void halbtc8821a1ant_action_pan_hs(IN struct btc_coexist *btcoexist)
  1315. {
  1316. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1317. }
  1318. /* PAN(EDR)+A2DP */
  1319. void halbtc8821a1ant_action_pan_edr_a2dp(IN struct btc_coexist *btcoexist)
  1320. {
  1321. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1322. }
  1323. void halbtc8821a1ant_action_pan_edr_hid(IN struct btc_coexist *btcoexist)
  1324. {
  1325. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1326. }
  1327. /* HID+A2DP+PAN(EDR) */
  1328. void halbtc8821a1ant_action_hid_a2dp_pan_edr(IN struct btc_coexist *btcoexist)
  1329. {
  1330. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1331. }
  1332. void halbtc8821a1ant_action_hid_a2dp(IN struct btc_coexist *btcoexist)
  1333. {
  1334. halbtc8821a1ant_sw_mechanism(btcoexist, true);
  1335. }
  1336. /* *********************************************
  1337. *
  1338. * Non-Software Coex Mechanism start
  1339. *
  1340. * ********************************************* */
  1341. void halbtc8821a1ant_action_hs(IN struct btc_coexist *btcoexist)
  1342. {
  1343. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
  1344. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1345. }
  1346. void halbtc8821a1ant_action_bt_inquiry(IN struct btc_coexist *btcoexist)
  1347. {
  1348. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1349. boolean wifi_connected = false, ap_enable = false, wifi_busy = false,
  1350. bt_busy = false;
  1351. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1352. &ap_enable);
  1353. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1354. &wifi_connected);
  1355. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1356. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  1357. if ((!wifi_connected) && (!coex_sta->wifi_is_high_pri_task)) {
  1358. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1359. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1360. }
  1361. /* sy modify */
  1362. else if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1363. (bt_link_info->a2dp_exist)) {
  1364. /* SCO/HID/A2DP busy */
  1365. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1366. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1367. }
  1368. /* sy modify */
  1369. else if ((bt_link_info->a2dp_exist) &&
  1370. (bt_link_info->hid_exist)) {
  1371. /* A2DP+HID busy */
  1372. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1373. 14);
  1374. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1375. NORMAL_EXEC, 1);
  1376. }
  1377. else if ((bt_link_info->pan_exist) || (wifi_busy)) {
  1378. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1379. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1380. } else {
  1381. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1382. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
  1383. }
  1384. }
  1385. void halbtc8821a1ant_action_bt_sco_hid_only_busy(IN struct btc_coexist
  1386. *btcoexist, IN u8 wifi_status)
  1387. {
  1388. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1389. boolean wifi_connected = false;
  1390. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1391. &wifi_connected);
  1392. /* tdma and coex table */
  1393. if (bt_link_info->sco_exist) {
  1394. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 41);
  1395. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1396. } else { /* HID */
  1397. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 42);
  1398. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1399. }
  1400. }
  1401. void halbtc8821a1ant_coex_under_5g(IN struct btc_coexist *btcoexist)
  1402. {
  1403. halbtc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
  1404. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10);
  1405. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1406. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1407. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
  1408. }
  1409. void halbtc8821a1ant_action_wifi_only(IN struct btc_coexist *btcoexist)
  1410. {
  1411. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1412. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
  1413. }
  1414. void halbtc8821a1ant_monitor_bt_enable_disable(IN struct btc_coexist *btcoexist)
  1415. {
  1416. static u32 bt_disable_cnt = 0;
  1417. boolean bt_active = true, bt_disabled = false;
  1418. /* This function check if bt is disabled */
  1419. if (coex_sta->high_priority_tx == 0 &&
  1420. coex_sta->high_priority_rx == 0 &&
  1421. coex_sta->low_priority_tx == 0 &&
  1422. coex_sta->low_priority_rx == 0)
  1423. bt_active = false;
  1424. if (coex_sta->high_priority_tx == 0xffff &&
  1425. coex_sta->high_priority_rx == 0xffff &&
  1426. coex_sta->low_priority_tx == 0xffff &&
  1427. coex_sta->low_priority_rx == 0xffff)
  1428. bt_active = false;
  1429. if (bt_active) {
  1430. bt_disable_cnt = 0;
  1431. bt_disabled = false;
  1432. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1433. &bt_disabled);
  1434. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1435. "[BTCoex], BT is enabled !!\n");
  1436. BTC_TRACE(trace_buf);
  1437. } else {
  1438. bt_disable_cnt++;
  1439. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1440. "[BTCoex], bt all counters=0, %d times!!\n",
  1441. bt_disable_cnt);
  1442. BTC_TRACE(trace_buf);
  1443. if (bt_disable_cnt >= 10) {
  1444. bt_disabled = true;
  1445. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
  1446. &bt_disabled);
  1447. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1448. "[BTCoex], BT is disabled !!\n");
  1449. BTC_TRACE(trace_buf);
  1450. halbtc8821a1ant_action_wifi_only(btcoexist);
  1451. }
  1452. }
  1453. if (coex_sta->bt_disabled != bt_disabled) {
  1454. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1455. "[BTCoex], BT is from %s to %s!!\n",
  1456. (coex_sta->bt_disabled ? "disabled" : "enabled"),
  1457. (bt_disabled ? "disabled" : "enabled"));
  1458. BTC_TRACE(trace_buf);
  1459. coex_sta->bt_disabled = bt_disabled;
  1460. if (!bt_disabled) {
  1461. } else {
  1462. btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
  1463. NULL);
  1464. btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
  1465. NULL);
  1466. }
  1467. }
  1468. }
  1469. void halbtc8821a1ant_action_wifi_multi_port(IN struct btc_coexist *btcoexist)
  1470. {
  1471. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1472. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1473. }
  1474. void halbtc8821a1ant_action_wifi_connected_bt_acl_busy(IN struct btc_coexist
  1475. *btcoexist, IN u8 wifi_status)
  1476. {
  1477. u8 bt_rssi_state;
  1478. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1479. bt_rssi_state = halbtc8821a1ant_bt_rssi_state(2, 28, 0);
  1480. if (bt_link_info->hid_only) { /* HID */
  1481. halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1482. wifi_status);
  1483. coex_dm->auto_tdma_adjust = false;
  1484. return;
  1485. } else if (bt_link_info->a2dp_only) { /* A2DP */
  1486. if (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifi_status) {
  1487. /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8); */
  1488. /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); */
  1489. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1490. 32);
  1491. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1492. NORMAL_EXEC, 1);
  1493. coex_dm->auto_tdma_adjust = false;
  1494. } else if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  1495. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  1496. /* halbtc8821a1ant_tdma_duration_adjust_for_acl(btcoexist, wifi_status); */
  1497. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1498. 14);
  1499. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1500. NORMAL_EXEC, 1);
  1501. } else { /* for low BT RSSI */
  1502. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1503. 14);
  1504. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1505. NORMAL_EXEC, 1);
  1506. coex_dm->auto_tdma_adjust = false;
  1507. }
  1508. } else if (bt_link_info->hid_exist &&
  1509. bt_link_info->a2dp_exist) { /* HID+A2DP */
  1510. if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
  1511. (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  1512. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1513. 14);
  1514. coex_dm->auto_tdma_adjust = false;
  1515. } else { /* for low BT RSSI */
  1516. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1517. 14);
  1518. coex_dm->auto_tdma_adjust = false;
  1519. }
  1520. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1521. } else if ((bt_link_info->pan_only) || (bt_link_info->hid_exist &&
  1522. bt_link_info->pan_exist)) { /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
  1523. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
  1524. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
  1525. coex_dm->auto_tdma_adjust = false;
  1526. } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
  1527. (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
  1528. bt_link_info->pan_exist)) { /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
  1529. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 43);
  1530. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1531. coex_dm->auto_tdma_adjust = false;
  1532. } else {
  1533. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
  1534. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1535. coex_dm->auto_tdma_adjust = false;
  1536. }
  1537. }
  1538. void halbtc8821a1ant_action_wifi_not_connected(IN struct btc_coexist *btcoexist)
  1539. {
  1540. /* tdma and coex table */
  1541. halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
  1542. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  1543. }
  1544. void halbtc8821a1ant_action_wifi_not_connected_scan(IN struct btc_coexist
  1545. *btcoexist)
  1546. {
  1547. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1548. /* tdma and coex table */
  1549. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1550. if (bt_link_info->a2dp_exist) {
  1551. /* sy modify */
  1552. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1553. 14);
  1554. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1555. NORMAL_EXEC, 1);
  1556. } else if (bt_link_info->a2dp_exist &&
  1557. bt_link_info->pan_exist) {
  1558. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1559. 22);
  1560. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1561. NORMAL_EXEC, 4);
  1562. } else {
  1563. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1564. 20);
  1565. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1566. NORMAL_EXEC, 4);
  1567. }
  1568. } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1569. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1570. coex_dm->bt_status)) {
  1571. halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1572. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1573. } else {
  1574. /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
  1575. /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
  1576. /* Bryant Add */
  1577. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1578. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1579. }
  1580. }
  1581. void halbtc8821a1ant_action_wifi_not_connected_asso_auth(
  1582. IN struct btc_coexist *btcoexist)
  1583. {
  1584. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1585. /* tdma and coex table */
  1586. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist)) {
  1587. /* sy modify */
  1588. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
  1589. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
  1590. } else if ((bt_link_info->a2dp_exist) || (bt_link_info->pan_exist)) {
  1591. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1592. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1593. } else {
  1594. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1595. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1596. }
  1597. }
  1598. void halbtc8821a1ant_action_wifi_connected_scan(IN struct btc_coexist
  1599. *btcoexist)
  1600. {
  1601. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1602. /* tdma and coex table */
  1603. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1604. if (bt_link_info->a2dp_exist) {
  1605. /* sy modify */
  1606. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1607. 14);
  1608. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1609. NORMAL_EXEC, 1);
  1610. } else if (bt_link_info->a2dp_exist &&
  1611. bt_link_info->pan_exist) {
  1612. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1613. 22);
  1614. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1615. NORMAL_EXEC, 4);
  1616. } else {
  1617. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1618. 20);
  1619. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1620. NORMAL_EXEC, 4);
  1621. }
  1622. } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1623. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1624. coex_dm->bt_status)) {
  1625. halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1626. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
  1627. } else {
  1628. /* halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20); */
  1629. /* halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1); */
  1630. /* Bryant Add */
  1631. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1632. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1633. }
  1634. }
  1635. void halbtc8821a1ant_action_wifi_connected_specific_packet(
  1636. IN struct btc_coexist *btcoexist)
  1637. {
  1638. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1639. /* tdma and coex table */
  1640. /* sy modify */
  1641. if ((bt_link_info->sco_exist) || (bt_link_info->hid_exist) ||
  1642. (bt_link_info->a2dp_exist)) {
  1643. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
  1644. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1645. }
  1646. if ((bt_link_info->hid_exist) && (bt_link_info->a2dp_exist)) {
  1647. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
  1648. 14);
  1649. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1650. NORMAL_EXEC, 1);
  1651. }
  1652. else if (bt_link_info->pan_exist) {
  1653. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
  1654. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
  1655. } else {
  1656. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
  1657. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  1658. }
  1659. }
  1660. void halbtc8821a1ant_action_wifi_connected(IN struct btc_coexist *btcoexist)
  1661. {
  1662. boolean wifi_busy = false;
  1663. boolean scan = false, link = false, roam = false;
  1664. boolean under_4way = false, ap_enable = false;
  1665. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1666. "[BTCoex], CoexForWifiConnect()===>\n");
  1667. BTC_TRACE(trace_buf);
  1668. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
  1669. &under_4way);
  1670. if (under_4way) {
  1671. halbtc8821a1ant_action_wifi_connected_specific_packet(
  1672. btcoexist);
  1673. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1674. "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
  1675. BTC_TRACE(trace_buf);
  1676. return;
  1677. }
  1678. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1679. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1680. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1681. if (scan || link || roam) {
  1682. if (scan)
  1683. halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
  1684. else
  1685. halbtc8821a1ant_action_wifi_connected_specific_packet(
  1686. btcoexist);
  1687. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1688. "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
  1689. BTC_TRACE(trace_buf);
  1690. return;
  1691. }
  1692. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
  1693. &ap_enable);
  1694. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
  1695. /* tdma and coex table */
  1696. if (!wifi_busy) {
  1697. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1698. halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
  1699. btcoexist,
  1700. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1701. } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
  1702. coex_dm->bt_status) ||
  1703. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1704. coex_dm->bt_status)) {
  1705. halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1706. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
  1707. } else {
  1708. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1709. 8);
  1710. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1711. NORMAL_EXEC, 2);
  1712. }
  1713. } else {
  1714. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
  1715. halbtc8821a1ant_action_wifi_connected_bt_acl_busy(
  1716. btcoexist,
  1717. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1718. } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
  1719. coex_dm->bt_status) ||
  1720. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
  1721. coex_dm->bt_status)) {
  1722. halbtc8821a1ant_action_bt_sco_hid_only_busy(btcoexist,
  1723. BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
  1724. } else {
  1725. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false,
  1726. 8);
  1727. halbtc8821a1ant_coex_table_with_type(btcoexist,
  1728. NORMAL_EXEC, 2);
  1729. }
  1730. }
  1731. }
  1732. void halbtc8821a1ant_run_sw_coexist_mechanism(IN struct btc_coexist *btcoexist)
  1733. {
  1734. u8 algorithm = 0;
  1735. algorithm = halbtc8821a1ant_action_algorithm(btcoexist);
  1736. coex_dm->cur_algorithm = algorithm;
  1737. if (halbtc8821a1ant_is_common_action(btcoexist)) {
  1738. } else {
  1739. switch (coex_dm->cur_algorithm) {
  1740. case BT_8821A_1ANT_COEX_ALGO_SCO:
  1741. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1742. "[BTCoex], Action algorithm = SCO.\n");
  1743. BTC_TRACE(trace_buf);
  1744. halbtc8821a1ant_action_sco(btcoexist);
  1745. break;
  1746. case BT_8821A_1ANT_COEX_ALGO_HID:
  1747. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1748. "[BTCoex], Action algorithm = HID.\n");
  1749. BTC_TRACE(trace_buf);
  1750. halbtc8821a1ant_action_hid(btcoexist);
  1751. break;
  1752. case BT_8821A_1ANT_COEX_ALGO_A2DP:
  1753. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1754. "[BTCoex], Action algorithm = A2DP.\n");
  1755. BTC_TRACE(trace_buf);
  1756. halbtc8821a1ant_action_a2dp(btcoexist);
  1757. break;
  1758. case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:
  1759. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1760. "[BTCoex], Action algorithm = A2DP+PAN(HS).\n");
  1761. BTC_TRACE(trace_buf);
  1762. halbtc8821a1ant_action_a2dp_pan_hs(btcoexist);
  1763. break;
  1764. case BT_8821A_1ANT_COEX_ALGO_PANEDR:
  1765. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1766. "[BTCoex], Action algorithm = PAN(EDR).\n");
  1767. BTC_TRACE(trace_buf);
  1768. halbtc8821a1ant_action_pan_edr(btcoexist);
  1769. break;
  1770. case BT_8821A_1ANT_COEX_ALGO_PANHS:
  1771. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1772. "[BTCoex], Action algorithm = HS mode.\n");
  1773. BTC_TRACE(trace_buf);
  1774. halbtc8821a1ant_action_pan_hs(btcoexist);
  1775. break;
  1776. case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:
  1777. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1778. "[BTCoex], Action algorithm = PAN+A2DP.\n");
  1779. BTC_TRACE(trace_buf);
  1780. halbtc8821a1ant_action_pan_edr_a2dp(btcoexist);
  1781. break;
  1782. case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:
  1783. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1784. "[BTCoex], Action algorithm = PAN(EDR)+HID.\n");
  1785. BTC_TRACE(trace_buf);
  1786. halbtc8821a1ant_action_pan_edr_hid(btcoexist);
  1787. break;
  1788. case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
  1789. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1790. "[BTCoex], Action algorithm = HID+A2DP+PAN.\n");
  1791. BTC_TRACE(trace_buf);
  1792. halbtc8821a1ant_action_hid_a2dp_pan_edr(
  1793. btcoexist);
  1794. break;
  1795. case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:
  1796. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1797. "[BTCoex], Action algorithm = HID+A2DP.\n");
  1798. BTC_TRACE(trace_buf);
  1799. halbtc8821a1ant_action_hid_a2dp(btcoexist);
  1800. break;
  1801. default:
  1802. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1803. "[BTCoex], Action algorithm = coexist All Off!!\n");
  1804. BTC_TRACE(trace_buf);
  1805. /* halbtc8821a1ant_coex_all_off(btcoexist); */
  1806. break;
  1807. }
  1808. coex_dm->pre_algorithm = coex_dm->cur_algorithm;
  1809. }
  1810. }
  1811. void halbtc8821a1ant_run_coexist_mechanism(IN struct btc_coexist *btcoexist)
  1812. {
  1813. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  1814. boolean wifi_connected = false, bt_hs_on = false;
  1815. boolean increase_scan_dev_num = false;
  1816. boolean bt_ctrl_agg_buf_size = false;
  1817. u8 agg_buf_size = 5;
  1818. u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
  1819. u32 wifi_link_status = 0;
  1820. u32 num_of_wifi_link = 0;
  1821. boolean wifi_under_5g = false;
  1822. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1823. "[BTCoex], RunCoexistMechanism()===>\n");
  1824. BTC_TRACE(trace_buf);
  1825. if (btcoexist->manual_control) {
  1826. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1827. "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
  1828. BTC_TRACE(trace_buf);
  1829. return;
  1830. }
  1831. if (btcoexist->stop_coex_dm) {
  1832. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1833. "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
  1834. BTC_TRACE(trace_buf);
  1835. return;
  1836. }
  1837. if (coex_sta->under_ips) {
  1838. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1839. "[BTCoex], wifi is under IPS !!!\n");
  1840. BTC_TRACE(trace_buf);
  1841. return;
  1842. }
  1843. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  1844. if (wifi_under_5g) {
  1845. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1846. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  1847. BTC_TRACE(trace_buf);
  1848. halbtc8821a1ant_coex_under_5g(btcoexist);
  1849. return;
  1850. }
  1851. if (coex_sta->bt_whck_test) {
  1852. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1853. "[BTCoex], BT is under WHCK TEST!!!\n");
  1854. BTC_TRACE(trace_buf);
  1855. halbtc8821a1ant_action_bt_whck_test(btcoexist);
  1856. return;
  1857. }
  1858. if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  1859. (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  1860. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  1861. increase_scan_dev_num = true;
  1862. btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
  1863. &increase_scan_dev_num);
  1864. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  1865. &wifi_connected);
  1866. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  1867. &wifi_link_status);
  1868. num_of_wifi_link = wifi_link_status >> 16;
  1869. if ((num_of_wifi_link >= 2) ||
  1870. (wifi_link_status & WIFI_P2P_GO_CONNECTED)) {
  1871. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1872. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1873. bt_ctrl_agg_buf_size, agg_buf_size);
  1874. halbtc8821a1ant_action_wifi_multi_port(btcoexist);
  1875. return;
  1876. }
  1877. if (!bt_link_info->sco_exist && !bt_link_info->hid_exist)
  1878. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  1879. else {
  1880. if (wifi_connected) {
  1881. wifi_rssi_state = halbtc8821a1ant_wifi_rssi_state(
  1882. btcoexist, 1, 2, 30, 0);
  1883. if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
  1884. (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
  1885. /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
  1886. halbtc8821a1ant_limited_tx(btcoexist,
  1887. NORMAL_EXEC, 1, 1, 0, 1);
  1888. } else {
  1889. /* halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 1, 1, 1, 1); */
  1890. halbtc8821a1ant_limited_tx(btcoexist,
  1891. NORMAL_EXEC, 1, 1, 0, 1);
  1892. }
  1893. } else
  1894. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0,
  1895. 0, 0);
  1896. }
  1897. if (bt_link_info->sco_exist) {
  1898. bt_ctrl_agg_buf_size = true;
  1899. agg_buf_size = 0x3;
  1900. } else if (bt_link_info->hid_exist) {
  1901. bt_ctrl_agg_buf_size = true;
  1902. agg_buf_size = 0x5;
  1903. } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
  1904. bt_ctrl_agg_buf_size = true;
  1905. agg_buf_size = 0x8;
  1906. }
  1907. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  1908. bt_ctrl_agg_buf_size, agg_buf_size);
  1909. halbtc8821a1ant_run_sw_coexist_mechanism(btcoexist);
  1910. /* low pelnaty ra in pcr ra */
  1911. btcoexist->btc_phydm_modify_RA_PCR_threshold(btcoexist, 0, 25);
  1912. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  1913. if (coex_sta->c2h_bt_inquiry_page) {
  1914. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  1915. return;
  1916. } else if (bt_hs_on) {
  1917. halbtc8821a1ant_action_hs(btcoexist);
  1918. return;
  1919. }
  1920. if (!wifi_connected) {
  1921. boolean scan = false, link = false, roam = false;
  1922. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1923. "[BTCoex], wifi is non connected-idle !!!\n");
  1924. BTC_TRACE(trace_buf);
  1925. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
  1926. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
  1927. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
  1928. if (scan || link || roam) {
  1929. if (scan)
  1930. halbtc8821a1ant_action_wifi_not_connected_scan(
  1931. btcoexist);
  1932. else
  1933. halbtc8821a1ant_action_wifi_not_connected_asso_auth(
  1934. btcoexist);
  1935. } else
  1936. halbtc8821a1ant_action_wifi_not_connected(btcoexist);
  1937. } else /* wifi LPS/Busy */
  1938. halbtc8821a1ant_action_wifi_connected(btcoexist);
  1939. }
  1940. void halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  1941. {
  1942. /* force to reset coex mechanism */
  1943. /* sw all off */
  1944. halbtc8821a1ant_sw_mechanism(btcoexist, false);
  1945. /* halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8); */
  1946. halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  1947. }
  1948. void halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  1949. IN boolean back_up, IN boolean wifi_only)
  1950. {
  1951. u8 u8tmp = 0;
  1952. boolean wifi_under_5g = false;
  1953. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  1954. "[BTCoex], 1Ant Init HW Config!!\n");
  1955. BTC_TRACE(trace_buf);
  1956. if (wifi_only)
  1957. return;
  1958. if (back_up) {
  1959. coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
  1960. 0x430);
  1961. coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
  1962. 0x434);
  1963. coex_dm->backup_retry_limit = btcoexist->btc_read_2byte(
  1964. btcoexist, 0x42a);
  1965. coex_dm->backup_ampdu_max_time = btcoexist->btc_read_1byte(
  1966. btcoexist, 0x456);
  1967. }
  1968. /* 0x790[5:0]=0x5 */
  1969. u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
  1970. u8tmp &= 0xc0;
  1971. u8tmp |= 0x5;
  1972. btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp);
  1973. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  1974. /* Give bt_coex_supported_version the default value */
  1975. coex_sta->bt_coex_supported_version = 0;
  1976. /* 0xf0[15:12] --> Chip Cut information */
  1977. coex_sta->cut_version = (btcoexist->btc_read_1byte(btcoexist,
  1978. 0xf1) & 0xf0) >> 4;
  1979. /* Antenna config */
  1980. if (wifi_under_5g)
  1981. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, true,
  1982. false);
  1983. else
  1984. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, true,
  1985. false);
  1986. /* PTA parameter */
  1987. halbtc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
  1988. /* Enable counter statistics */
  1989. btcoexist->btc_write_1byte(btcoexist, 0x76e,
  1990. 0xc); /* 0x76e[3] =1, WLAN_Act control by PTA */
  1991. btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
  1992. btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
  1993. }
  1994. /* ************************************************************
  1995. * work around function start with wa_halbtc8821a1ant_
  1996. * ************************************************************
  1997. * ************************************************************
  1998. * extern function start with ex_halbtc8821a1ant_
  1999. * ************************************************************ */
  2000. void ex_halbtc8821a1ant_power_on_setting(IN struct btc_coexist *btcoexist)
  2001. {
  2002. }
  2003. void ex_halbtc8821a1ant_init_hw_config(IN struct btc_coexist *btcoexist,
  2004. IN boolean wifi_only)
  2005. {
  2006. halbtc8821a1ant_init_hw_config(btcoexist, true, wifi_only);
  2007. }
  2008. void ex_halbtc8821a1ant_init_coex_dm(IN struct btc_coexist *btcoexist)
  2009. {
  2010. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2011. "[BTCoex], Coex Mechanism Init!!\n");
  2012. BTC_TRACE(trace_buf);
  2013. btcoexist->stop_coex_dm = false;
  2014. halbtc8821a1ant_init_coex_dm(btcoexist);
  2015. halbtc8821a1ant_query_bt_info(btcoexist);
  2016. }
  2017. void ex_halbtc8821a1ant_display_coex_info(IN struct btc_coexist *btcoexist)
  2018. {
  2019. struct btc_board_info *board_info = &btcoexist->board_info;
  2020. struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
  2021. u8 *cli_buf = btcoexist->cli_buf;
  2022. u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
  2023. u16 u16tmp[4];
  2024. u32 u32tmp[4];
  2025. u32 fw_ver = 0, bt_patch_ver = 0;
  2026. u32 bt_coex_ver = 0;
  2027. u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
  2028. u32 phyver = 0;
  2029. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2030. "\r\n ============[BT Coexist info]============");
  2031. CL_PRINTF(cli_buf);
  2032. if (btcoexist->manual_control) {
  2033. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2034. "\r\n ============[Under Manual Control]============");
  2035. CL_PRINTF(cli_buf);
  2036. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2037. "\r\n ==========================================");
  2038. CL_PRINTF(cli_buf);
  2039. }
  2040. if (btcoexist->stop_coex_dm) {
  2041. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2042. "\r\n ============[Coex is STOPPED]============");
  2043. CL_PRINTF(cli_buf);
  2044. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2045. "\r\n ==========================================");
  2046. CL_PRINTF(cli_buf);
  2047. }
  2048. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d",
  2049. "Ant PG Num/ Ant Mech/ Ant Pos:",
  2050. board_info->pg_ant_num, board_info->btdm_ant_num,
  2051. board_info->btdm_ant_pos);
  2052. CL_PRINTF(cli_buf);
  2053. /* btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); */
  2054. bt_patch_ver = btcoexist->bt_info.bt_get_fw_ver;
  2055. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
  2056. phyver = btcoexist->btc_get_bt_phydm_version(btcoexist);
  2057. bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
  2058. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2059. "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
  2060. "CoexVer WL/ BT_Desired/ BT_Report",
  2061. glcoex_ver_date_8821a_1ant, glcoex_ver_8821a_1ant,
  2062. glcoex_ver_btdesired_8821a_1ant,
  2063. bt_coex_ver,
  2064. (bt_coex_ver == 0xff ? "Unknown" :
  2065. (bt_coex_ver >= glcoex_ver_btdesired_8821a_1ant ?
  2066. "Match" : "Mis-Match")));
  2067. CL_PRINTF(cli_buf);
  2068. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2069. "\r\n %-35s = 0x%x/ 0x%x/ v%d/ %c",
  2070. "W_FW/ B_FW/ Phy/ Kt",
  2071. fw_ver, bt_patch_ver, phyver,
  2072. coex_sta->cut_version + 65);
  2073. CL_PRINTF(cli_buf);
  2074. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ",
  2075. "Wifi channel informed to BT",
  2076. coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
  2077. coex_dm->wifi_chnl_info[2]);
  2078. CL_PRINTF(cli_buf);
  2079. /* wifi status */
  2080. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2081. "============[Wifi Status]============");
  2082. CL_PRINTF(cli_buf);
  2083. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_WIFI_STATUS);
  2084. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2085. "============[BT Status]============");
  2086. CL_PRINTF(cli_buf);
  2087. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ",
  2088. "BT [status/ rssi/ retryCnt]",
  2089. ((coex_sta->bt_disabled) ? ("disabled") : ((
  2090. coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan")
  2091. : ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
  2092. coex_dm->bt_status) ? "non-connected idle" :
  2093. ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status)
  2094. ? "connected-idle" : "busy")))),
  2095. coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
  2096. CL_PRINTF(cli_buf);
  2097. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d",
  2098. "SCO/HID/PAN/A2DP",
  2099. bt_link_info->sco_exist, bt_link_info->hid_exist,
  2100. bt_link_info->pan_exist, bt_link_info->a2dp_exist);
  2101. CL_PRINTF(cli_buf);
  2102. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
  2103. bt_info_ext = coex_sta->bt_info_ext;
  2104. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
  2105. "BT Info A2DP rate",
  2106. (bt_info_ext & BIT(0)) ? "Basic rate" : "EDR rate");
  2107. CL_PRINTF(cli_buf);
  2108. for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) {
  2109. if (coex_sta->bt_info_c2h_cnt[i]) {
  2110. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2111. "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)",
  2112. glbt_info_src_8821a_1ant[i],
  2113. coex_sta->bt_info_c2h[i][0],
  2114. coex_sta->bt_info_c2h[i][1],
  2115. coex_sta->bt_info_c2h[i][2],
  2116. coex_sta->bt_info_c2h[i][3],
  2117. coex_sta->bt_info_c2h[i][4],
  2118. coex_sta->bt_info_c2h[i][5],
  2119. coex_sta->bt_info_c2h[i][6],
  2120. coex_sta->bt_info_c2h_cnt[i]);
  2121. CL_PRINTF(cli_buf);
  2122. }
  2123. }
  2124. if (!btcoexist->manual_control) {
  2125. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
  2126. "SM[LowPenaltyRA]",
  2127. coex_dm->cur_low_penalty_ra);
  2128. CL_PRINTF(cli_buf);
  2129. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2130. "============[mechanisms]============");
  2131. CL_PRINTF(cli_buf);
  2132. ps_tdma_case = coex_dm->cur_ps_tdma;
  2133. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2134. "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)",
  2135. "PS TDMA",
  2136. coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
  2137. coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
  2138. coex_dm->ps_tdma_para[4], ps_tdma_case,
  2139. coex_dm->auto_tdma_adjust);
  2140. CL_PRINTF(cli_buf);
  2141. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ",
  2142. "IgnWlanAct",
  2143. coex_dm->cur_ignore_wlan_act);
  2144. CL_PRINTF(cli_buf);
  2145. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ",
  2146. "Latest error condition(should be 0)",
  2147. coex_dm->error_condition);
  2148. CL_PRINTF(cli_buf);
  2149. }
  2150. /* Hw setting */
  2151. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
  2152. "============[Hw setting]============");
  2153. CL_PRINTF(cli_buf);
  2154. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  2155. "backup ARFR1/ARFR2/RL/AMaxTime",
  2156. coex_dm->backup_arfr_cnt1, coex_dm->backup_arfr_cnt2,
  2157. coex_dm->backup_retry_limit,
  2158. coex_dm->backup_ampdu_max_time);
  2159. CL_PRINTF(cli_buf);
  2160. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
  2161. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
  2162. u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
  2163. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
  2164. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
  2165. "0x430/0x434/0x42a/0x456",
  2166. u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
  2167. CL_PRINTF(cli_buf);
  2168. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
  2169. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58);
  2170. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  2171. "0x778/ 0xc58[29:25]",
  2172. u8tmp[0], (u32tmp[0] & 0x3e000000) >> 25);
  2173. CL_PRINTF(cli_buf);
  2174. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
  2175. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]",
  2176. ((u8tmp[0] & 0x60) >> 5));
  2177. CL_PRINTF(cli_buf);
  2178. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975);
  2179. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
  2180. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2181. "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
  2182. (u32tmp[0] & 0x30000000) >> 28, u32tmp[0] & 0xff,
  2183. u8tmp[0] & 0x3);
  2184. CL_PRINTF(cli_buf);
  2185. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
  2186. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
  2187. u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
  2188. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2189. "0x40/0x4c[24:23]/0x64[0]",
  2190. u8tmp[0], ((u32tmp[0] & 0x01800000) >> 23), u8tmp[1] & 0x1);
  2191. CL_PRINTF(cli_buf);
  2192. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
  2193. u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
  2194. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
  2195. "0x550(bcn ctrl)/0x522",
  2196. u32tmp[0], u8tmp[0]);
  2197. CL_PRINTF(cli_buf);
  2198. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
  2199. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)",
  2200. u32tmp[0] & 0xff);
  2201. CL_PRINTF(cli_buf);
  2202. fa_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  2203. PHYDM_INFO_FA_OFDM);
  2204. fa_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  2205. PHYDM_INFO_FA_CCK);
  2206. cca_ofdm = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  2207. PHYDM_INFO_CCA_OFDM);
  2208. cca_cck = btcoexist->btc_phydm_query_PHY_counter(btcoexist,
  2209. PHYDM_INFO_CCA_CCK);
  2210. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
  2211. "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
  2212. "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
  2213. cca_cck, fa_cck, cca_ofdm, fa_ofdm);
  2214. CL_PRINTF(cli_buf);
  2215. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  2216. "CRC_OK CCK/11g/11n/11n-agg",
  2217. coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
  2218. coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
  2219. CL_PRINTF(cli_buf);
  2220. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
  2221. "CRC_Err CCK/11g/11n/11n-agg",
  2222. coex_sta->crc_err_cck, coex_sta->crc_err_11g,
  2223. coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
  2224. CL_PRINTF(cli_buf);
  2225. u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
  2226. u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
  2227. u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
  2228. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
  2229. "0x6c0/0x6c4/0x6c8(coexTable)",
  2230. u32tmp[0], u32tmp[1], u32tmp[2]);
  2231. CL_PRINTF(cli_buf);
  2232. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  2233. "0x770(high-pri rx/tx)",
  2234. coex_sta->high_priority_rx, coex_sta->high_priority_tx);
  2235. CL_PRINTF(cli_buf);
  2236. CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
  2237. "0x774(low-pri rx/tx)",
  2238. coex_sta->low_priority_rx, coex_sta->low_priority_tx);
  2239. CL_PRINTF(cli_buf);
  2240. #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)
  2241. halbtc8821a1ant_monitor_bt_ctr(btcoexist);
  2242. #endif
  2243. btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
  2244. }
  2245. void ex_halbtc8821a1ant_ips_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  2246. {
  2247. boolean wifi_under_5g = false;
  2248. if (btcoexist->manual_control || btcoexist->stop_coex_dm)
  2249. return;
  2250. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
  2251. &wifi_under_5g);
  2252. if (wifi_under_5g) {
  2253. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2254. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2255. BTC_TRACE(trace_buf);
  2256. halbtc8821a1ant_coex_under_5g(btcoexist);
  2257. return;
  2258. }
  2259. if (BTC_IPS_ENTER == type) {
  2260. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2261. "[BTCoex], IPS ENTER notify\n");
  2262. BTC_TRACE(trace_buf);
  2263. coex_sta->under_ips = true;
  2264. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2265. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
  2266. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
  2267. true);
  2268. /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
  2269. } else if (BTC_IPS_LEAVE == type) {
  2270. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2271. "[BTCoex], IPS LEAVE notify\n");
  2272. BTC_TRACE(trace_buf);
  2273. coex_sta->under_ips = false;
  2274. halbtc8821a1ant_init_hw_config(btcoexist, false, false);
  2275. halbtc8821a1ant_init_coex_dm(btcoexist);
  2276. halbtc8821a1ant_query_bt_info(btcoexist);
  2277. }
  2278. }
  2279. void ex_halbtc8821a1ant_lps_notify(IN struct btc_coexist *btcoexist, IN u8 type)
  2280. {
  2281. if (BTC_LPS_ENABLE == type) {
  2282. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2283. "[BTCoex], LPS ENABLE notify\n");
  2284. BTC_TRACE(trace_buf);
  2285. coex_sta->under_lps = true;
  2286. } else if (BTC_LPS_DISABLE == type) {
  2287. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2288. "[BTCoex], LPS DISABLE notify\n");
  2289. BTC_TRACE(trace_buf);
  2290. coex_sta->under_lps = false;
  2291. }
  2292. }
  2293. void ex_halbtc8821a1ant_scan_notify(IN struct btc_coexist *btcoexist,
  2294. IN u8 type)
  2295. {
  2296. boolean wifi_connected = false, bt_hs_on = false;
  2297. u32 wifi_link_status = 0;
  2298. u32 num_of_wifi_link = 0;
  2299. boolean bt_ctrl_agg_buf_size = false;
  2300. u8 agg_buf_size = 5;
  2301. boolean wifi_under_5g = false;
  2302. if (btcoexist->manual_control ||
  2303. btcoexist->stop_coex_dm)
  2304. return;
  2305. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2306. if (wifi_under_5g) {
  2307. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2308. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2309. BTC_TRACE(trace_buf);
  2310. halbtc8821a1ant_coex_under_5g(btcoexist);
  2311. return;
  2312. }
  2313. if (BTC_SCAN_START == type) {
  2314. coex_sta->wifi_is_high_pri_task = true;
  2315. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2316. "[BTCoex], SCAN START notify\n");
  2317. BTC_TRACE(trace_buf);
  2318. halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  2319. 8); /* Force antenna setup for no scan result issue */
  2320. } else {
  2321. coex_sta->wifi_is_high_pri_task = false;
  2322. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2323. "[BTCoex], SCAN FINISH notify\n");
  2324. BTC_TRACE(trace_buf);
  2325. }
  2326. if (coex_sta->bt_disabled)
  2327. return;
  2328. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2329. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2330. &wifi_connected);
  2331. halbtc8821a1ant_query_bt_info(btcoexist);
  2332. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2333. &wifi_link_status);
  2334. num_of_wifi_link = wifi_link_status >> 16;
  2335. if (num_of_wifi_link >= 2) {
  2336. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2337. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2338. bt_ctrl_agg_buf_size, agg_buf_size);
  2339. halbtc8821a1ant_action_wifi_multi_port(btcoexist);
  2340. return;
  2341. }
  2342. if (coex_sta->c2h_bt_inquiry_page) {
  2343. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  2344. return;
  2345. } else if (bt_hs_on) {
  2346. halbtc8821a1ant_action_hs(btcoexist);
  2347. return;
  2348. }
  2349. if (BTC_SCAN_START == type) {
  2350. if (!wifi_connected) /* non-connected scan */
  2351. halbtc8821a1ant_action_wifi_not_connected_scan(
  2352. btcoexist);
  2353. else /* wifi is connected */
  2354. halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
  2355. } else if (BTC_SCAN_FINISH == type) {
  2356. if (!wifi_connected) /* non-connected scan */
  2357. halbtc8821a1ant_action_wifi_not_connected(btcoexist);
  2358. else
  2359. halbtc8821a1ant_action_wifi_connected(btcoexist);
  2360. }
  2361. }
  2362. /* copy scan notify content to switch band notify */
  2363. void ex_halbtc8821a1ant_switchband_notify(IN struct btc_coexist *btcoexist,
  2364. IN u8 type)
  2365. {
  2366. boolean wifi_connected = false, bt_hs_on = false;
  2367. u32 wifi_link_status = 0;
  2368. u32 num_of_wifi_link = 0;
  2369. boolean bt_ctrl_agg_buf_size = false;
  2370. u8 agg_buf_size = 5;
  2371. boolean wifi_under_5g = false;
  2372. if (btcoexist->manual_control ||
  2373. btcoexist->stop_coex_dm)
  2374. return;
  2375. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2376. if (wifi_under_5g) {
  2377. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2378. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2379. BTC_TRACE(trace_buf);
  2380. halbtc8821a1ant_coex_under_5g(btcoexist);
  2381. return;
  2382. }
  2383. if (BTC_SCAN_START == type) {
  2384. coex_sta->wifi_is_high_pri_task = true;
  2385. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2386. "[BTCoex], SCAN START notify\n");
  2387. BTC_TRACE(trace_buf);
  2388. halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false,
  2389. 8); /* Force antenna setup for no scan result issue */
  2390. } else {
  2391. coex_sta->wifi_is_high_pri_task = false;
  2392. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2393. "[BTCoex], SCAN FINISH notify\n");
  2394. BTC_TRACE(trace_buf);
  2395. }
  2396. if (coex_sta->bt_disabled)
  2397. return;
  2398. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2399. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2400. &wifi_connected);
  2401. halbtc8821a1ant_query_bt_info(btcoexist);
  2402. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2403. &wifi_link_status);
  2404. num_of_wifi_link = wifi_link_status >> 16;
  2405. if (num_of_wifi_link >= 2) {
  2406. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2407. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2408. bt_ctrl_agg_buf_size, agg_buf_size);
  2409. halbtc8821a1ant_action_wifi_multi_port(btcoexist);
  2410. return;
  2411. }
  2412. if (coex_sta->c2h_bt_inquiry_page) {
  2413. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  2414. return;
  2415. } else if (bt_hs_on) {
  2416. halbtc8821a1ant_action_hs(btcoexist);
  2417. return;
  2418. }
  2419. if (BTC_SCAN_START == type) {
  2420. if (!wifi_connected) /* non-connected scan */
  2421. halbtc8821a1ant_action_wifi_not_connected_scan(
  2422. btcoexist);
  2423. else /* wifi is connected */
  2424. halbtc8821a1ant_action_wifi_connected_scan(btcoexist);
  2425. } else if (BTC_SCAN_FINISH == type) {
  2426. if (!wifi_connected) /* non-connected scan */
  2427. halbtc8821a1ant_action_wifi_not_connected(btcoexist);
  2428. else
  2429. halbtc8821a1ant_action_wifi_connected(btcoexist);
  2430. }
  2431. }
  2432. void ex_halbtc8821a1ant_connect_notify(IN struct btc_coexist *btcoexist,
  2433. IN u8 type)
  2434. {
  2435. boolean wifi_connected = false, bt_hs_on = false;
  2436. u32 wifi_link_status = 0;
  2437. u32 num_of_wifi_link = 0;
  2438. boolean bt_ctrl_agg_buf_size = false;
  2439. u8 agg_buf_size = 5;
  2440. boolean wifi_under_5g = false;
  2441. if (btcoexist->manual_control ||
  2442. btcoexist->stop_coex_dm ||
  2443. coex_sta->bt_disabled)
  2444. return;
  2445. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2446. if (wifi_under_5g) {
  2447. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2448. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2449. BTC_TRACE(trace_buf);
  2450. halbtc8821a1ant_coex_under_5g(btcoexist);
  2451. return;
  2452. }
  2453. if (BTC_ASSOCIATE_START == type) {
  2454. coex_sta->wifi_is_high_pri_task = true;
  2455. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2456. "[BTCoex], CONNECT START notify\n");
  2457. BTC_TRACE(trace_buf);
  2458. coex_dm->arp_cnt = 0;
  2459. } else {
  2460. coex_sta->wifi_is_high_pri_task = false;
  2461. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2462. "[BTCoex], CONNECT FINISH notify\n");
  2463. BTC_TRACE(trace_buf);
  2464. coex_dm->arp_cnt = 0;
  2465. }
  2466. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2467. &wifi_link_status);
  2468. num_of_wifi_link = wifi_link_status >> 16;
  2469. if (num_of_wifi_link >= 2) {
  2470. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2471. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2472. bt_ctrl_agg_buf_size, agg_buf_size);
  2473. halbtc8821a1ant_action_wifi_multi_port(btcoexist);
  2474. return;
  2475. }
  2476. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2477. if (coex_sta->c2h_bt_inquiry_page) {
  2478. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  2479. return;
  2480. } else if (bt_hs_on) {
  2481. halbtc8821a1ant_action_hs(btcoexist);
  2482. return;
  2483. }
  2484. if (BTC_ASSOCIATE_START == type)
  2485. halbtc8821a1ant_action_wifi_not_connected_asso_auth(btcoexist);
  2486. else if (BTC_ASSOCIATE_FINISH == type) {
  2487. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2488. &wifi_connected);
  2489. if (!wifi_connected) /* non-connected scan */
  2490. halbtc8821a1ant_action_wifi_not_connected(btcoexist);
  2491. else
  2492. halbtc8821a1ant_action_wifi_connected(btcoexist);
  2493. }
  2494. }
  2495. void ex_halbtc8821a1ant_media_status_notify(IN struct btc_coexist *btcoexist,
  2496. IN u8 type)
  2497. {
  2498. u8 h2c_parameter[3] = {0};
  2499. u32 wifi_bw;
  2500. u8 wifi_central_chnl;
  2501. boolean wifi_under_5g = false;
  2502. if (btcoexist->manual_control ||
  2503. btcoexist->stop_coex_dm ||
  2504. coex_sta->bt_disabled)
  2505. return;
  2506. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2507. if (wifi_under_5g) {
  2508. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2509. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2510. BTC_TRACE(trace_buf);
  2511. halbtc8821a1ant_coex_under_5g(btcoexist);
  2512. return;
  2513. }
  2514. if (BTC_MEDIA_CONNECT == type) {
  2515. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2516. "[BTCoex], MEDIA connect notify\n");
  2517. BTC_TRACE(trace_buf);
  2518. } else {
  2519. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2520. "[BTCoex], MEDIA disconnect notify\n");
  2521. BTC_TRACE(trace_buf);
  2522. coex_dm->arp_cnt = 0;
  2523. }
  2524. /* only 2.4G we need to inform bt the chnl mask */
  2525. btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
  2526. &wifi_central_chnl);
  2527. if ((BTC_MEDIA_CONNECT == type) &&
  2528. (wifi_central_chnl <= 14)) {
  2529. /* h2c_parameter[0] = 0x1; */
  2530. h2c_parameter[0] = 0x0;
  2531. h2c_parameter[1] = wifi_central_chnl;
  2532. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
  2533. if (BTC_WIFI_BW_HT40 == wifi_bw)
  2534. h2c_parameter[2] = 0x30;
  2535. else
  2536. h2c_parameter[2] = 0x20;
  2537. }
  2538. coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
  2539. coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
  2540. coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
  2541. btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
  2542. }
  2543. void ex_halbtc8821a1ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
  2544. IN u8 type)
  2545. {
  2546. boolean bt_hs_on = false;
  2547. u32 wifi_link_status = 0;
  2548. u32 num_of_wifi_link = 0;
  2549. boolean bt_ctrl_agg_buf_size = false;
  2550. u8 agg_buf_size = 5;
  2551. boolean wifi_under_5g = false;
  2552. if (btcoexist->manual_control ||
  2553. btcoexist->stop_coex_dm ||
  2554. coex_sta->bt_disabled)
  2555. return;
  2556. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2557. if (wifi_under_5g) {
  2558. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2559. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2560. BTC_TRACE(trace_buf);
  2561. halbtc8821a1ant_coex_under_5g(btcoexist);
  2562. return;
  2563. }
  2564. if (BTC_PACKET_DHCP == type ||
  2565. BTC_PACKET_EAPOL == type ||
  2566. BTC_PACKET_ARP == type) {
  2567. coex_sta->wifi_is_high_pri_task = true;
  2568. if (BTC_PACKET_ARP == type) {
  2569. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2570. "[BTCoex], specific Packet ARP notify\n");
  2571. BTC_TRACE(trace_buf);
  2572. } else {
  2573. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2574. "[BTCoex], specific Packet DHCP or EAPOL notify\n");
  2575. BTC_TRACE(trace_buf);
  2576. }
  2577. } else {
  2578. coex_sta->wifi_is_high_pri_task = false;
  2579. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2580. "[BTCoex], specific Packet [Type = %d] notify\n", type);
  2581. BTC_TRACE(trace_buf);
  2582. }
  2583. coex_sta->specific_pkt_period_cnt = 0;
  2584. btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
  2585. &wifi_link_status);
  2586. num_of_wifi_link = wifi_link_status >> 16;
  2587. if (num_of_wifi_link >= 2) {
  2588. halbtc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
  2589. halbtc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
  2590. bt_ctrl_agg_buf_size, agg_buf_size);
  2591. halbtc8821a1ant_action_wifi_multi_port(btcoexist);
  2592. return;
  2593. }
  2594. btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
  2595. if (coex_sta->c2h_bt_inquiry_page) {
  2596. halbtc8821a1ant_action_bt_inquiry(btcoexist);
  2597. return;
  2598. } else if (bt_hs_on) {
  2599. halbtc8821a1ant_action_hs(btcoexist);
  2600. return;
  2601. }
  2602. if (BTC_PACKET_DHCP == type ||
  2603. BTC_PACKET_EAPOL == type ||
  2604. BTC_PACKET_ARP == type) {
  2605. if (BTC_PACKET_ARP == type) {
  2606. coex_dm->arp_cnt++;
  2607. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2608. "[BTCoex], ARP Packet Count = %d\n",
  2609. coex_dm->arp_cnt);
  2610. BTC_TRACE(trace_buf);
  2611. if (coex_dm->arp_cnt >=
  2612. 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecificPacket(btcoexist) */
  2613. return;
  2614. }
  2615. halbtc8821a1ant_action_wifi_connected_specific_packet(
  2616. btcoexist);
  2617. }
  2618. }
  2619. void ex_halbtc8821a1ant_bt_info_notify(IN struct btc_coexist *btcoexist,
  2620. IN u8 *tmp_buf, IN u8 length)
  2621. {
  2622. u8 bt_info = 0;
  2623. u8 i, rsp_source = 0;
  2624. boolean wifi_connected = false;
  2625. boolean bt_busy = false;
  2626. boolean wifi_under_5g = false;
  2627. coex_sta->c2h_bt_info_req_sent = false;
  2628. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2629. rsp_source = tmp_buf[0] & 0xf;
  2630. if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX)
  2631. rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW;
  2632. coex_sta->bt_info_c2h_cnt[rsp_source]++;
  2633. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2634. "[BTCoex], Bt info[%d], length=%d, hex data=[", rsp_source,
  2635. length);
  2636. BTC_TRACE(trace_buf);
  2637. for (i = 0; i < length; i++) {
  2638. coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
  2639. if (i == 1)
  2640. bt_info = tmp_buf[i];
  2641. if (i == length - 1) {
  2642. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x]\n",
  2643. tmp_buf[i]);
  2644. BTC_TRACE(trace_buf);
  2645. } else {
  2646. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "0x%02x, ",
  2647. tmp_buf[i]);
  2648. BTC_TRACE(trace_buf);
  2649. }
  2650. }
  2651. /* if 0xff, it means BT is under WHCK test */
  2652. if (bt_info == 0xff)
  2653. coex_sta->bt_whck_test = true;
  2654. else
  2655. coex_sta->bt_whck_test = false;
  2656. if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) {
  2657. coex_sta->bt_retry_cnt = /* [3:0] */
  2658. coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
  2659. if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
  2660. coex_sta->c2h_bt_page = true;
  2661. else
  2662. coex_sta->c2h_bt_page = false;
  2663. coex_sta->bt_rssi =
  2664. coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10;
  2665. coex_sta->bt_info_ext =
  2666. coex_sta->bt_info_c2h[rsp_source][4];
  2667. coex_sta->bt_tx_rx_mask = (coex_sta->bt_info_c2h[rsp_source][2]
  2668. & 0x40);
  2669. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
  2670. &coex_sta->bt_tx_rx_mask);
  2671. if (!coex_sta->bt_tx_rx_mask) {
  2672. /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
  2673. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2674. "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
  2675. BTC_TRACE(trace_buf);
  2676. btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
  2677. 0x3c, 0x15);
  2678. }
  2679. /* Here we need to resend some wifi info to BT */
  2680. /* because bt is reset and loss of the info. */
  2681. if (coex_sta->bt_info_ext & BIT(1)) {
  2682. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2683. "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
  2684. BTC_TRACE(trace_buf);
  2685. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
  2686. &wifi_connected);
  2687. if (wifi_connected)
  2688. ex_halbtc8821a1ant_media_status_notify(
  2689. btcoexist, BTC_MEDIA_CONNECT);
  2690. else
  2691. ex_halbtc8821a1ant_media_status_notify(
  2692. btcoexist, BTC_MEDIA_DISCONNECT);
  2693. }
  2694. if ((coex_sta->bt_info_ext & BIT(3)) && !wifi_under_5g) {
  2695. if (!btcoexist->manual_control &&
  2696. !btcoexist->stop_coex_dm) {
  2697. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2698. "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
  2699. BTC_TRACE(trace_buf);
  2700. halbtc8821a1ant_ignore_wlan_act(btcoexist,
  2701. FORCE_EXEC, false);
  2702. }
  2703. } else {
  2704. /* BT already NOT ignore Wlan active, do nothing here. */
  2705. }
  2706. #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
  2707. if ((coex_sta->bt_info_ext & BIT(4))) {
  2708. /* BT auto report already enabled, do nothing */
  2709. } else
  2710. halbtc8821a1ant_bt_auto_report(btcoexist, FORCE_EXEC,
  2711. true);
  2712. #endif
  2713. }
  2714. /* check BIT2 first ==> check if bt is under inquiry or page scan */
  2715. if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE)
  2716. coex_sta->c2h_bt_inquiry_page = true;
  2717. else
  2718. coex_sta->c2h_bt_inquiry_page = false;
  2719. /* set link exist status */
  2720. if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
  2721. coex_sta->bt_link_exist = false;
  2722. coex_sta->pan_exist = false;
  2723. coex_sta->a2dp_exist = false;
  2724. coex_sta->hid_exist = false;
  2725. coex_sta->sco_exist = false;
  2726. } else { /* connection exists */
  2727. coex_sta->bt_link_exist = true;
  2728. if (bt_info & BT_INFO_8821A_1ANT_B_FTP)
  2729. coex_sta->pan_exist = true;
  2730. else
  2731. coex_sta->pan_exist = false;
  2732. if (bt_info & BT_INFO_8821A_1ANT_B_A2DP)
  2733. coex_sta->a2dp_exist = true;
  2734. else
  2735. coex_sta->a2dp_exist = false;
  2736. if (bt_info & BT_INFO_8821A_1ANT_B_HID)
  2737. coex_sta->hid_exist = true;
  2738. else
  2739. coex_sta->hid_exist = false;
  2740. if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO)
  2741. coex_sta->sco_exist = true;
  2742. else
  2743. coex_sta->sco_exist = false;
  2744. }
  2745. halbtc8821a1ant_update_bt_link_info(btcoexist);
  2746. bt_info = bt_info &
  2747. 0x1f; /* mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41) */
  2748. if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
  2749. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
  2750. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2751. "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
  2752. BTC_TRACE(trace_buf);
  2753. } else if (bt_info ==
  2754. BT_INFO_8821A_1ANT_B_CONNECTION) { /* connection exists but no busy */
  2755. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;
  2756. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2757. "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
  2758. BTC_TRACE(trace_buf);
  2759. } else if ((bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO) ||
  2760. (bt_info & BT_INFO_8821A_1ANT_B_SCO_BUSY)) {
  2761. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;
  2762. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2763. "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
  2764. BTC_TRACE(trace_buf);
  2765. } else if (bt_info & BT_INFO_8821A_1ANT_B_ACL_BUSY) {
  2766. if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
  2767. coex_dm->auto_tdma_adjust = false;
  2768. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;
  2769. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2770. "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
  2771. BTC_TRACE(trace_buf);
  2772. } else {
  2773. coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX;
  2774. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2775. "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
  2776. BTC_TRACE(trace_buf);
  2777. }
  2778. if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
  2779. (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
  2780. (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
  2781. bt_busy = true;
  2782. else
  2783. bt_busy = false;
  2784. btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
  2785. halbtc8821a1ant_run_coexist_mechanism(btcoexist);
  2786. }
  2787. void ex_halbtc8821a1ant_halt_notify(IN struct btc_coexist *btcoexist)
  2788. {
  2789. boolean wifi_under_5g = false;
  2790. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2791. if (wifi_under_5g) {
  2792. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2793. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2794. BTC_TRACE(trace_buf);
  2795. halbtc8821a1ant_coex_under_5g(btcoexist);
  2796. return;
  2797. }
  2798. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
  2799. BTC_TRACE(trace_buf);
  2800. halbtc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
  2801. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
  2802. /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
  2803. halbtc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
  2804. ex_halbtc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
  2805. btcoexist->stop_coex_dm = true;
  2806. }
  2807. void ex_halbtc8821a1ant_pnp_notify(IN struct btc_coexist *btcoexist,
  2808. IN u8 pnp_state)
  2809. {
  2810. boolean wifi_under_5g = false;
  2811. btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
  2812. if (wifi_under_5g) {
  2813. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2814. "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
  2815. BTC_TRACE(trace_buf);
  2816. halbtc8821a1ant_coex_under_5g(btcoexist);
  2817. return;
  2818. }
  2819. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Pnp notify\n");
  2820. BTC_TRACE(trace_buf);
  2821. if (BTC_WIFI_PNP_SLEEP == pnp_state) {
  2822. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2823. "[BTCoex], Pnp notify to SLEEP\n");
  2824. BTC_TRACE(trace_buf);
  2825. halbtc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
  2826. halbtc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
  2827. halbtc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false,
  2828. true);
  2829. /* halbtc8821a1ant_set_ant_path_d_cut(btcoexist, false, false, false, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF); */
  2830. /* Sinda 20150819, workaround for driver skip leave IPS/LPS to speed up sleep time. */
  2831. /* Driver do not leave IPS/LPS when driver is going to sleep, so BTCoexistence think wifi is still under IPS/LPS */
  2832. /* BT should clear UnderIPS/UnderLPS state to avoid mismatch state after wakeup. */
  2833. coex_sta->under_ips = false;
  2834. coex_sta->under_lps = false;
  2835. btcoexist->stop_coex_dm = true;
  2836. } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
  2837. BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
  2838. "[BTCoex], Pnp notify to WAKE UP\n");
  2839. BTC_TRACE(trace_buf);
  2840. btcoexist->stop_coex_dm = false;
  2841. halbtc8821a1ant_init_hw_config(btcoexist, false, false);
  2842. halbtc8821a1ant_init_coex_dm(btcoexist);
  2843. halbtc8821a1ant_query_bt_info(btcoexist);
  2844. }
  2845. }
  2846. void ex_halbtc8821a1ant_periodical(IN struct btc_coexist *btcoexist)
  2847. {
  2848. u32 bt_patch_ver;
  2849. if (((coex_sta->bt_coex_supported_version == 0) ||
  2850. (coex_sta->bt_coex_supported_version == 0xffff)) && (!coex_sta->bt_disabled))
  2851. btcoexist->btc_get(btcoexist, BTC_GET_U4_SUPPORTED_VERSION, &coex_sta->bt_coex_supported_version);
  2852. btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
  2853. btcoexist->bt_info.bt_get_fw_ver = bt_patch_ver;
  2854. #if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
  2855. halbtc8821a1ant_query_bt_info(btcoexist);
  2856. halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
  2857. #else
  2858. halbtc8821a1ant_monitor_bt_ctr(btcoexist);
  2859. halbtc8821a1ant_monitor_wifi_ctr(btcoexist);
  2860. halbtc8821a1ant_monitor_bt_enable_disable(btcoexist);
  2861. if (halbtc8821a1ant_is_wifi_status_changed(btcoexist) ||
  2862. coex_dm->auto_tdma_adjust) {
  2863. /* if(coex_sta->specific_pkt_period_cnt > 2) */
  2864. /* { */
  2865. halbtc8821a1ant_run_coexist_mechanism(btcoexist);
  2866. /* } */
  2867. }
  2868. coex_sta->specific_pkt_period_cnt++;
  2869. #endif
  2870. }
  2871. #endif
  2872. #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */