hw.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "../wifi.h"
  26. #include "../efuse.h"
  27. #include "../base.h"
  28. #include "../regd.h"
  29. #include "../cam.h"
  30. #include "../ps.h"
  31. #include "../pci.h"
  32. #include "reg.h"
  33. #include "def.h"
  34. #include "phy.h"
  35. #include "../rtl8723com/phy_common.h"
  36. #include "dm.h"
  37. #include "../rtl8723com/dm_common.h"
  38. #include "fw.h"
  39. #include "../rtl8723com/fw_common.h"
  40. #include "led.h"
  41. #include "hw.h"
  42. #include "../pwrseqcmd.h"
  43. #include "pwrseq.h"
  44. #include "btc.h"
  45. #define LLT_CONFIG 5
  46. static void _rtl8723e_set_bcn_ctrl_reg(struct ieee80211_hw *hw,
  47. u8 set_bits, u8 clear_bits)
  48. {
  49. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  50. struct rtl_priv *rtlpriv = rtl_priv(hw);
  51. rtlpci->reg_bcn_ctrl_val |= set_bits;
  52. rtlpci->reg_bcn_ctrl_val &= ~clear_bits;
  53. rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val);
  54. }
  55. static void _rtl8723e_stop_tx_beacon(struct ieee80211_hw *hw)
  56. {
  57. struct rtl_priv *rtlpriv = rtl_priv(hw);
  58. u8 tmp1byte;
  59. tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  60. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6)));
  61. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
  62. tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  63. tmp1byte &= ~(BIT(0));
  64. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
  65. }
  66. static void _rtl8723e_resume_tx_beacon(struct ieee80211_hw *hw)
  67. {
  68. struct rtl_priv *rtlpriv = rtl_priv(hw);
  69. u8 tmp1byte;
  70. tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  71. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6));
  72. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  73. tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  74. tmp1byte |= BIT(1);
  75. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
  76. }
  77. static void _rtl8723e_enable_bcn_sub_func(struct ieee80211_hw *hw)
  78. {
  79. _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(1));
  80. }
  81. static void _rtl8723e_disable_bcn_sub_func(struct ieee80211_hw *hw)
  82. {
  83. _rtl8723e_set_bcn_ctrl_reg(hw, BIT(1), 0);
  84. }
  85. void rtl8723e_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  86. {
  87. struct rtl_priv *rtlpriv = rtl_priv(hw);
  88. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  89. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  90. switch (variable) {
  91. case HW_VAR_RCR:
  92. *((u32 *)(val)) = rtlpci->receive_config;
  93. break;
  94. case HW_VAR_RF_STATE:
  95. *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
  96. break;
  97. case HW_VAR_FWLPS_RF_ON:{
  98. enum rf_pwrstate rfstate;
  99. u32 val_rcr;
  100. rtlpriv->cfg->ops->get_hw_reg(hw,
  101. HW_VAR_RF_STATE,
  102. (u8 *)(&rfstate));
  103. if (rfstate == ERFOFF) {
  104. *((bool *)(val)) = true;
  105. } else {
  106. val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
  107. val_rcr &= 0x00070000;
  108. if (val_rcr)
  109. *((bool *)(val)) = false;
  110. else
  111. *((bool *)(val)) = true;
  112. }
  113. break;
  114. }
  115. case HW_VAR_FW_PSMODE_STATUS:
  116. *((bool *)(val)) = ppsc->fw_current_inpsmode;
  117. break;
  118. case HW_VAR_CORRECT_TSF:{
  119. u64 tsf;
  120. u32 *ptsf_low = (u32 *)&tsf;
  121. u32 *ptsf_high = ((u32 *)&tsf) + 1;
  122. *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
  123. *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
  124. *((u64 *)(val)) = tsf;
  125. break;
  126. }
  127. default:
  128. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  129. "switch case not process\n");
  130. break;
  131. }
  132. }
  133. void rtl8723e_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  134. {
  135. struct rtl_priv *rtlpriv = rtl_priv(hw);
  136. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  137. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  138. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  139. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  140. u8 idx;
  141. switch (variable) {
  142. case HW_VAR_ETHER_ADDR:{
  143. for (idx = 0; idx < ETH_ALEN; idx++) {
  144. rtl_write_byte(rtlpriv, (REG_MACID + idx),
  145. val[idx]);
  146. }
  147. break;
  148. }
  149. case HW_VAR_BASIC_RATE:{
  150. u16 b_rate_cfg = ((u16 *)val)[0];
  151. u8 rate_index = 0;
  152. b_rate_cfg = b_rate_cfg & 0x15f;
  153. b_rate_cfg |= 0x01;
  154. rtl_write_byte(rtlpriv, REG_RRSR, b_rate_cfg & 0xff);
  155. rtl_write_byte(rtlpriv, REG_RRSR + 1,
  156. (b_rate_cfg >> 8) & 0xff);
  157. while (b_rate_cfg > 0x1) {
  158. b_rate_cfg = (b_rate_cfg >> 1);
  159. rate_index++;
  160. }
  161. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
  162. rate_index);
  163. break;
  164. }
  165. case HW_VAR_BSSID:{
  166. for (idx = 0; idx < ETH_ALEN; idx++) {
  167. rtl_write_byte(rtlpriv, (REG_BSSID + idx),
  168. val[idx]);
  169. }
  170. break;
  171. }
  172. case HW_VAR_SIFS:{
  173. rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
  174. rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
  175. rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
  176. rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
  177. if (!mac->ht_enable)
  178. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  179. 0x0e0e);
  180. else
  181. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  182. *((u16 *)val));
  183. break;
  184. }
  185. case HW_VAR_SLOT_TIME:{
  186. u8 e_aci;
  187. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  188. "HW_VAR_SLOT_TIME %x\n", val[0]);
  189. rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
  190. for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
  191. rtlpriv->cfg->ops->set_hw_reg(hw,
  192. HW_VAR_AC_PARAM,
  193. (u8 *)(&e_aci));
  194. }
  195. break;
  196. }
  197. case HW_VAR_ACK_PREAMBLE:{
  198. u8 reg_tmp;
  199. u8 short_preamble = (bool)(*(u8 *)val);
  200. reg_tmp = (mac->cur_40_prime_sc) << 5;
  201. if (short_preamble)
  202. reg_tmp |= 0x80;
  203. rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
  204. break;
  205. }
  206. case HW_VAR_AMPDU_MIN_SPACE:{
  207. u8 min_spacing_to_set;
  208. u8 sec_min_space;
  209. min_spacing_to_set = *((u8 *)val);
  210. if (min_spacing_to_set <= 7) {
  211. sec_min_space = 0;
  212. if (min_spacing_to_set < sec_min_space)
  213. min_spacing_to_set = sec_min_space;
  214. mac->min_space_cfg = ((mac->min_space_cfg &
  215. 0xf8) |
  216. min_spacing_to_set);
  217. *val = min_spacing_to_set;
  218. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  219. "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
  220. mac->min_space_cfg);
  221. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  222. mac->min_space_cfg);
  223. }
  224. break;
  225. }
  226. case HW_VAR_SHORTGI_DENSITY:{
  227. u8 density_to_set;
  228. density_to_set = *((u8 *)val);
  229. mac->min_space_cfg |= (density_to_set << 3);
  230. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  231. "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
  232. mac->min_space_cfg);
  233. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  234. mac->min_space_cfg);
  235. break;
  236. }
  237. case HW_VAR_AMPDU_FACTOR:{
  238. u8 regtoset_normal[4] = { 0x41, 0xa8, 0x72, 0xb9 };
  239. u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97};
  240. u8 factor_toset;
  241. u8 *p_regtoset = NULL;
  242. u8 index = 0;
  243. if ((rtlpriv->btcoexist.bt_coexistence) &&
  244. (rtlpriv->btcoexist.bt_coexist_type ==
  245. BT_CSR_BC4))
  246. p_regtoset = regtoset_bt;
  247. else
  248. p_regtoset = regtoset_normal;
  249. factor_toset = *((u8 *)val);
  250. if (factor_toset <= 3) {
  251. factor_toset = (1 << (factor_toset + 2));
  252. if (factor_toset > 0xf)
  253. factor_toset = 0xf;
  254. for (index = 0; index < 4; index++) {
  255. if ((p_regtoset[index] & 0xf0) >
  256. (factor_toset << 4))
  257. p_regtoset[index] =
  258. (p_regtoset[index] & 0x0f) |
  259. (factor_toset << 4);
  260. if ((p_regtoset[index] & 0x0f) >
  261. factor_toset)
  262. p_regtoset[index] =
  263. (p_regtoset[index] & 0xf0) |
  264. (factor_toset);
  265. rtl_write_byte(rtlpriv,
  266. (REG_AGGLEN_LMT + index),
  267. p_regtoset[index]);
  268. }
  269. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  270. "Set HW_VAR_AMPDU_FACTOR: %#x\n",
  271. factor_toset);
  272. }
  273. break;
  274. }
  275. case HW_VAR_AC_PARAM:{
  276. u8 e_aci = *((u8 *)val);
  277. rtl8723_dm_init_edca_turbo(hw);
  278. if (rtlpci->acm_method != EACMWAY2_SW)
  279. rtlpriv->cfg->ops->set_hw_reg(hw,
  280. HW_VAR_ACM_CTRL,
  281. (u8 *)(&e_aci));
  282. break;
  283. }
  284. case HW_VAR_ACM_CTRL:{
  285. u8 e_aci = *((u8 *)val);
  286. union aci_aifsn *p_aci_aifsn =
  287. (union aci_aifsn *)(&mac->ac[0].aifs);
  288. u8 acm = p_aci_aifsn->f.acm;
  289. u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
  290. acm_ctrl =
  291. acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
  292. if (acm) {
  293. switch (e_aci) {
  294. case AC0_BE:
  295. acm_ctrl |= ACMHW_BEQEN;
  296. break;
  297. case AC2_VI:
  298. acm_ctrl |= ACMHW_VIQEN;
  299. break;
  300. case AC3_VO:
  301. acm_ctrl |= ACMHW_VOQEN;
  302. break;
  303. default:
  304. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  305. "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
  306. acm);
  307. break;
  308. }
  309. } else {
  310. switch (e_aci) {
  311. case AC0_BE:
  312. acm_ctrl &= (~ACMHW_BEQEN);
  313. break;
  314. case AC2_VI:
  315. acm_ctrl &= (~ACMHW_VIQEN);
  316. break;
  317. case AC3_VO:
  318. acm_ctrl &= (~ACMHW_VOQEN);
  319. break;
  320. default:
  321. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  322. "switch case not process\n");
  323. break;
  324. }
  325. }
  326. RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
  327. "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
  328. acm_ctrl);
  329. rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
  330. break;
  331. }
  332. case HW_VAR_RCR:{
  333. rtl_write_dword(rtlpriv, REG_RCR, ((u32 *)(val))[0]);
  334. rtlpci->receive_config = ((u32 *)(val))[0];
  335. break;
  336. }
  337. case HW_VAR_RETRY_LIMIT:{
  338. u8 retry_limit = ((u8 *)(val))[0];
  339. rtl_write_word(rtlpriv, REG_RL,
  340. retry_limit << RETRY_LIMIT_SHORT_SHIFT |
  341. retry_limit << RETRY_LIMIT_LONG_SHIFT);
  342. break;
  343. }
  344. case HW_VAR_DUAL_TSF_RST:
  345. rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
  346. break;
  347. case HW_VAR_EFUSE_BYTES:
  348. rtlefuse->efuse_usedbytes = *((u16 *)val);
  349. break;
  350. case HW_VAR_EFUSE_USAGE:
  351. rtlefuse->efuse_usedpercentage = *((u8 *)val);
  352. break;
  353. case HW_VAR_IO_CMD:
  354. rtl8723e_phy_set_io_cmd(hw, (*(enum io_type *)val));
  355. break;
  356. case HW_VAR_WPA_CONFIG:
  357. rtl_write_byte(rtlpriv, REG_SECCFG, *((u8 *)val));
  358. break;
  359. case HW_VAR_SET_RPWM:{
  360. u8 rpwm_val;
  361. rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
  362. udelay(1);
  363. if (rpwm_val & BIT(7)) {
  364. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
  365. (*(u8 *)val));
  366. } else {
  367. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
  368. ((*(u8 *)val) | BIT(7)));
  369. }
  370. break;
  371. }
  372. case HW_VAR_H2C_FW_PWRMODE:{
  373. u8 psmode = (*(u8 *)val);
  374. if (psmode != FW_PS_ACTIVE_MODE)
  375. rtl8723e_dm_rf_saving(hw, true);
  376. rtl8723e_set_fw_pwrmode_cmd(hw, (*(u8 *)val));
  377. break;
  378. }
  379. case HW_VAR_FW_PSMODE_STATUS:
  380. ppsc->fw_current_inpsmode = *((bool *)val);
  381. break;
  382. case HW_VAR_H2C_FW_JOINBSSRPT:{
  383. u8 mstatus = (*(u8 *)val);
  384. u8 tmp_regcr, tmp_reg422;
  385. bool b_recover = false;
  386. if (mstatus == RT_MEDIA_CONNECT) {
  387. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
  388. NULL);
  389. tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
  390. rtl_write_byte(rtlpriv, REG_CR + 1,
  391. (tmp_regcr | BIT(0)));
  392. _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(3));
  393. _rtl8723e_set_bcn_ctrl_reg(hw, BIT(4), 0);
  394. tmp_reg422 =
  395. rtl_read_byte(rtlpriv,
  396. REG_FWHW_TXQ_CTRL + 2);
  397. if (tmp_reg422 & BIT(6))
  398. b_recover = true;
  399. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
  400. tmp_reg422 & (~BIT(6)));
  401. rtl8723e_set_fw_rsvdpagepkt(hw, 0);
  402. _rtl8723e_set_bcn_ctrl_reg(hw, BIT(3), 0);
  403. _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(4));
  404. if (b_recover) {
  405. rtl_write_byte(rtlpriv,
  406. REG_FWHW_TXQ_CTRL + 2,
  407. tmp_reg422);
  408. }
  409. rtl_write_byte(rtlpriv, REG_CR + 1,
  410. (tmp_regcr & ~(BIT(0))));
  411. }
  412. rtl8723e_set_fw_joinbss_report_cmd(hw, (*(u8 *)val));
  413. break;
  414. }
  415. case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:{
  416. rtl8723e_set_p2p_ps_offload_cmd(hw, (*(u8 *)val));
  417. break;
  418. }
  419. case HW_VAR_AID:{
  420. u16 u2btmp;
  421. u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
  422. u2btmp &= 0xC000;
  423. rtl_write_word(rtlpriv, REG_BCN_PSR_RPT,
  424. (u2btmp | mac->assoc_id));
  425. break;
  426. }
  427. case HW_VAR_CORRECT_TSF:{
  428. u8 btype_ibss = ((u8 *)(val))[0];
  429. if (btype_ibss)
  430. _rtl8723e_stop_tx_beacon(hw);
  431. _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(3));
  432. rtl_write_dword(rtlpriv, REG_TSFTR,
  433. (u32)(mac->tsf & 0xffffffff));
  434. rtl_write_dword(rtlpriv, REG_TSFTR + 4,
  435. (u32)((mac->tsf >> 32) & 0xffffffff));
  436. _rtl8723e_set_bcn_ctrl_reg(hw, BIT(3), 0);
  437. if (btype_ibss)
  438. _rtl8723e_resume_tx_beacon(hw);
  439. break;
  440. }
  441. case HW_VAR_FW_LPS_ACTION:{
  442. bool b_enter_fwlps = *((bool *)val);
  443. u8 rpwm_val, fw_pwrmode;
  444. bool fw_current_inps;
  445. if (b_enter_fwlps) {
  446. rpwm_val = 0x02; /* RF off */
  447. fw_current_inps = true;
  448. rtlpriv->cfg->ops->set_hw_reg(hw,
  449. HW_VAR_FW_PSMODE_STATUS,
  450. (u8 *)(&fw_current_inps));
  451. rtlpriv->cfg->ops->set_hw_reg(hw,
  452. HW_VAR_H2C_FW_PWRMODE,
  453. (u8 *)(&ppsc->fwctrl_psmode));
  454. rtlpriv->cfg->ops->set_hw_reg(hw,
  455. HW_VAR_SET_RPWM,
  456. (u8 *)(&rpwm_val));
  457. } else {
  458. rpwm_val = 0x0C; /* RF on */
  459. fw_pwrmode = FW_PS_ACTIVE_MODE;
  460. fw_current_inps = false;
  461. rtlpriv->cfg->ops->set_hw_reg(hw,
  462. HW_VAR_SET_RPWM,
  463. (u8 *)(&rpwm_val));
  464. rtlpriv->cfg->ops->set_hw_reg(hw,
  465. HW_VAR_H2C_FW_PWRMODE,
  466. (u8 *)(&fw_pwrmode));
  467. rtlpriv->cfg->ops->set_hw_reg(hw,
  468. HW_VAR_FW_PSMODE_STATUS,
  469. (u8 *)(&fw_current_inps));
  470. }
  471. break;
  472. }
  473. default:
  474. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  475. "switch case not process\n");
  476. break;
  477. }
  478. }
  479. static bool _rtl8723e_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
  480. {
  481. struct rtl_priv *rtlpriv = rtl_priv(hw);
  482. bool status = true;
  483. long count = 0;
  484. u32 value = _LLT_INIT_ADDR(address) |
  485. _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
  486. rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
  487. do {
  488. value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
  489. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
  490. break;
  491. if (count > POLLING_LLT_THRESHOLD) {
  492. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  493. "Failed to polling write LLT done at address %d!\n",
  494. address);
  495. status = false;
  496. break;
  497. }
  498. } while (++count);
  499. return status;
  500. }
  501. static bool _rtl8723e_llt_table_init(struct ieee80211_hw *hw)
  502. {
  503. struct rtl_priv *rtlpriv = rtl_priv(hw);
  504. unsigned short i;
  505. u8 txpktbuf_bndy;
  506. u8 maxpage;
  507. bool status;
  508. u8 ubyte;
  509. #if LLT_CONFIG == 1
  510. maxpage = 255;
  511. txpktbuf_bndy = 252;
  512. #elif LLT_CONFIG == 2
  513. maxpage = 127;
  514. txpktbuf_bndy = 124;
  515. #elif LLT_CONFIG == 3
  516. maxpage = 255;
  517. txpktbuf_bndy = 174;
  518. #elif LLT_CONFIG == 4
  519. maxpage = 255;
  520. txpktbuf_bndy = 246;
  521. #elif LLT_CONFIG == 5
  522. maxpage = 255;
  523. txpktbuf_bndy = 246;
  524. #endif
  525. rtl_write_byte(rtlpriv, REG_CR, 0x8B);
  526. #if LLT_CONFIG == 1
  527. rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x1c);
  528. rtl_write_dword(rtlpriv, REG_RQPN, 0x80a71c1c);
  529. #elif LLT_CONFIG == 2
  530. rtl_write_dword(rtlpriv, REG_RQPN, 0x845B1010);
  531. #elif LLT_CONFIG == 3
  532. rtl_write_dword(rtlpriv, REG_RQPN, 0x84838484);
  533. #elif LLT_CONFIG == 4
  534. rtl_write_dword(rtlpriv, REG_RQPN, 0x80bd1c1c);
  535. #elif LLT_CONFIG == 5
  536. rtl_write_word(rtlpriv, REG_RQPN_NPQ, 0x0000);
  537. rtl_write_dword(rtlpriv, REG_RQPN, 0x80ac1c29);
  538. rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x03);
  539. #endif
  540. rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x27FF0000 | txpktbuf_bndy));
  541. rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
  542. rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
  543. rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
  544. rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
  545. rtl_write_byte(rtlpriv, REG_PBP, 0x11);
  546. rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
  547. for (i = 0; i < (txpktbuf_bndy - 1); i++) {
  548. status = _rtl8723e_llt_write(hw, i, i + 1);
  549. if (true != status)
  550. return status;
  551. }
  552. status = _rtl8723e_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
  553. if (true != status)
  554. return status;
  555. for (i = txpktbuf_bndy; i < maxpage; i++) {
  556. status = _rtl8723e_llt_write(hw, i, (i + 1));
  557. if (true != status)
  558. return status;
  559. }
  560. status = _rtl8723e_llt_write(hw, maxpage, txpktbuf_bndy);
  561. if (true != status)
  562. return status;
  563. rtl_write_byte(rtlpriv, REG_CR, 0xff);
  564. ubyte = rtl_read_byte(rtlpriv, REG_RQPN + 3);
  565. rtl_write_byte(rtlpriv, REG_RQPN + 3, ubyte | BIT(7));
  566. return true;
  567. }
  568. static void _rtl8723e_gen_refresh_led_state(struct ieee80211_hw *hw)
  569. {
  570. struct rtl_priv *rtlpriv = rtl_priv(hw);
  571. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  572. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  573. struct rtl_led *pled0 = &pcipriv->ledctl.sw_led0;
  574. if (rtlpriv->rtlhal.up_first_time)
  575. return;
  576. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
  577. rtl8723e_sw_led_on(hw, pled0);
  578. else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
  579. rtl8723e_sw_led_on(hw, pled0);
  580. else
  581. rtl8723e_sw_led_off(hw, pled0);
  582. }
  583. static bool _rtl8712e_init_mac(struct ieee80211_hw *hw)
  584. {
  585. struct rtl_priv *rtlpriv = rtl_priv(hw);
  586. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  587. unsigned char bytetmp;
  588. unsigned short wordtmp;
  589. u16 retry = 0;
  590. u16 tmpu2b;
  591. bool mac_func_enable;
  592. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
  593. bytetmp = rtl_read_byte(rtlpriv, REG_CR);
  594. if (bytetmp == 0xFF)
  595. mac_func_enable = true;
  596. else
  597. mac_func_enable = false;
  598. /* HW Power on sequence */
  599. if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  600. PWR_INTF_PCI_MSK, Rtl8723_NIC_ENABLE_FLOW))
  601. return false;
  602. bytetmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG+2);
  603. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+2, bytetmp | BIT(4));
  604. /* eMAC time out function enable, 0x369[7]=1 */
  605. bytetmp = rtl_read_byte(rtlpriv, 0x369);
  606. rtl_write_byte(rtlpriv, 0x369, bytetmp | BIT(7));
  607. /* ePHY reg 0x1e bit[4]=1 using MDIO interface,
  608. * we should do this before Enabling ASPM backdoor.
  609. */
  610. do {
  611. rtl_write_word(rtlpriv, 0x358, 0x5e);
  612. udelay(100);
  613. rtl_write_word(rtlpriv, 0x356, 0xc280);
  614. rtl_write_word(rtlpriv, 0x354, 0xc290);
  615. rtl_write_word(rtlpriv, 0x358, 0x3e);
  616. udelay(100);
  617. rtl_write_word(rtlpriv, 0x358, 0x5e);
  618. udelay(100);
  619. tmpu2b = rtl_read_word(rtlpriv, 0x356);
  620. retry++;
  621. } while (tmpu2b != 0xc290 && retry < 100);
  622. if (retry >= 100) {
  623. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  624. "InitMAC(): ePHY configure fail!!!\n");
  625. return false;
  626. }
  627. rtl_write_word(rtlpriv, REG_CR, 0x2ff);
  628. rtl_write_word(rtlpriv, REG_CR + 1, 0x06);
  629. if (!mac_func_enable) {
  630. if (!_rtl8723e_llt_table_init(hw))
  631. return false;
  632. }
  633. rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
  634. rtl_write_byte(rtlpriv, REG_HISRE, 0xff);
  635. rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x27ff);
  636. wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
  637. wordtmp &= 0xf;
  638. wordtmp |= 0xF771;
  639. rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
  640. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
  641. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  642. rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xFFFF);
  643. rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
  644. rtl_write_byte(rtlpriv, 0x4d0, 0x0);
  645. rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
  646. ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) &
  647. DMA_BIT_MASK(32));
  648. rtl_write_dword(rtlpriv, REG_MGQ_DESA,
  649. (u64) rtlpci->tx_ring[MGNT_QUEUE].dma &
  650. DMA_BIT_MASK(32));
  651. rtl_write_dword(rtlpriv, REG_VOQ_DESA,
  652. (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
  653. rtl_write_dword(rtlpriv, REG_VIQ_DESA,
  654. (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
  655. rtl_write_dword(rtlpriv, REG_BEQ_DESA,
  656. (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
  657. rtl_write_dword(rtlpriv, REG_BKQ_DESA,
  658. (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
  659. rtl_write_dword(rtlpriv, REG_HQ_DESA,
  660. (u64) rtlpci->tx_ring[HIGH_QUEUE].dma &
  661. DMA_BIT_MASK(32));
  662. rtl_write_dword(rtlpriv, REG_RX_DESA,
  663. (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
  664. DMA_BIT_MASK(32));
  665. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x74);
  666. rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
  667. bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
  668. rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6));
  669. do {
  670. retry++;
  671. bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
  672. } while ((retry < 200) && (bytetmp & BIT(7)));
  673. _rtl8723e_gen_refresh_led_state(hw);
  674. rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
  675. return true;
  676. }
  677. static void _rtl8723e_hw_configure(struct ieee80211_hw *hw)
  678. {
  679. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  680. struct rtl_priv *rtlpriv = rtl_priv(hw);
  681. u8 reg_bw_opmode;
  682. u32 reg_ratr, reg_prsr;
  683. reg_bw_opmode = BW_OPMODE_20MHZ;
  684. reg_ratr = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
  685. RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  686. reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  687. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8);
  688. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  689. rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
  690. rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
  691. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0);
  692. rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
  693. rtl_write_word(rtlpriv, REG_RL, 0x0707);
  694. rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802);
  695. rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
  696. rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
  697. rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
  698. rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
  699. rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
  700. if ((rtlpriv->btcoexist.bt_coexistence) &&
  701. (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4))
  702. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431);
  703. else
  704. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
  705. rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
  706. rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
  707. rtlpci->reg_bcn_ctrl_val = 0x1f;
  708. rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
  709. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  710. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  711. rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
  712. rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
  713. if ((rtlpriv->btcoexist.bt_coexistence) &&
  714. (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4)) {
  715. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
  716. rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402);
  717. } else {
  718. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
  719. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
  720. }
  721. if ((rtlpriv->btcoexist.bt_coexistence) &&
  722. (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4))
  723. rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
  724. else
  725. rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666);
  726. rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
  727. rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010);
  728. rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010);
  729. rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010);
  730. rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010);
  731. rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
  732. rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
  733. rtl_write_dword(rtlpriv, 0x394, 0x1);
  734. }
  735. static void _rtl8723e_enable_aspm_back_door(struct ieee80211_hw *hw)
  736. {
  737. struct rtl_priv *rtlpriv = rtl_priv(hw);
  738. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  739. rtl_write_byte(rtlpriv, 0x34b, 0x93);
  740. rtl_write_word(rtlpriv, 0x350, 0x870c);
  741. rtl_write_byte(rtlpriv, 0x352, 0x1);
  742. if (ppsc->support_backdoor)
  743. rtl_write_byte(rtlpriv, 0x349, 0x1b);
  744. else
  745. rtl_write_byte(rtlpriv, 0x349, 0x03);
  746. rtl_write_word(rtlpriv, 0x350, 0x2718);
  747. rtl_write_byte(rtlpriv, 0x352, 0x1);
  748. }
  749. void rtl8723e_enable_hw_security_config(struct ieee80211_hw *hw)
  750. {
  751. struct rtl_priv *rtlpriv = rtl_priv(hw);
  752. u8 sec_reg_value;
  753. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  754. "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
  755. rtlpriv->sec.pairwise_enc_algorithm,
  756. rtlpriv->sec.group_enc_algorithm);
  757. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  758. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  759. "not open hw encryption\n");
  760. return;
  761. }
  762. sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE;
  763. if (rtlpriv->sec.use_defaultkey) {
  764. sec_reg_value |= SCR_TXUSEDK;
  765. sec_reg_value |= SCR_RXUSEDK;
  766. }
  767. sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
  768. rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
  769. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  770. "The SECR-value %x\n", sec_reg_value);
  771. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
  772. }
  773. int rtl8723e_hw_init(struct ieee80211_hw *hw)
  774. {
  775. struct rtl_priv *rtlpriv = rtl_priv(hw);
  776. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  777. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  778. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  779. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  780. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  781. bool rtstatus = true;
  782. int err;
  783. u8 tmp_u1b;
  784. unsigned long flags;
  785. rtlpriv->rtlhal.being_init_adapter = true;
  786. /* As this function can take a very long time (up to 350 ms)
  787. * and can be called with irqs disabled, reenable the irqs
  788. * to let the other devices continue being serviced.
  789. *
  790. * It is safe doing so since our own interrupts will only be enabled
  791. * in a subsequent step.
  792. */
  793. local_save_flags(flags);
  794. local_irq_enable();
  795. rtlhal->fw_ready = false;
  796. rtlpriv->intf_ops->disable_aspm(hw);
  797. rtstatus = _rtl8712e_init_mac(hw);
  798. if (rtstatus != true) {
  799. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n");
  800. err = 1;
  801. goto exit;
  802. }
  803. err = rtl8723_download_fw(hw, false, FW_8723A_POLLING_TIMEOUT_COUNT);
  804. if (err) {
  805. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  806. "Failed to download FW. Init HW without FW now..\n");
  807. err = 1;
  808. goto exit;
  809. }
  810. rtlhal->fw_ready = true;
  811. rtlhal->last_hmeboxnum = 0;
  812. rtl8723e_phy_mac_config(hw);
  813. /* because last function modify RCR, so we update
  814. * rcr var here, or TP will unstable for receive_config
  815. * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx
  816. * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
  817. */
  818. rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
  819. rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
  820. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  821. rtl8723e_phy_bb_config(hw);
  822. rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
  823. rtl8723e_phy_rf_config(hw);
  824. if (IS_VENDOR_UMC_A_CUT(rtlhal->version)) {
  825. rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD, 0x30255);
  826. rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G2, MASKDWORD, 0x50a00);
  827. } else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version)) {
  828. rtl_set_rfreg(hw, RF90_PATH_A, 0x0C, MASKDWORD, 0x894AE);
  829. rtl_set_rfreg(hw, RF90_PATH_A, 0x0A, MASKDWORD, 0x1AF31);
  830. rtl_set_rfreg(hw, RF90_PATH_A, RF_IPA, MASKDWORD, 0x8F425);
  831. rtl_set_rfreg(hw, RF90_PATH_A, RF_SYN_G2, MASKDWORD, 0x4F200);
  832. rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK1, MASKDWORD, 0x44053);
  833. rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK2, MASKDWORD, 0x80201);
  834. }
  835. rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
  836. RF_CHNLBW, RFREG_OFFSET_MASK);
  837. rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1,
  838. RF_CHNLBW, RFREG_OFFSET_MASK);
  839. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  840. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  841. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
  842. _rtl8723e_hw_configure(hw);
  843. rtl_cam_reset_all_entry(hw);
  844. rtl8723e_enable_hw_security_config(hw);
  845. ppsc->rfpwr_state = ERFON;
  846. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  847. _rtl8723e_enable_aspm_back_door(hw);
  848. rtlpriv->intf_ops->enable_aspm(hw);
  849. rtl8723e_bt_hw_init(hw);
  850. if (ppsc->rfpwr_state == ERFON) {
  851. rtl8723e_phy_set_rfpath_switch(hw, 1);
  852. if (rtlphy->iqk_initialized) {
  853. rtl8723e_phy_iq_calibrate(hw, true);
  854. } else {
  855. rtl8723e_phy_iq_calibrate(hw, false);
  856. rtlphy->iqk_initialized = true;
  857. }
  858. rtl8723e_dm_check_txpower_tracking(hw);
  859. rtl8723e_phy_lc_calibrate(hw);
  860. }
  861. tmp_u1b = efuse_read_1byte(hw, 0x1FA);
  862. if (!(tmp_u1b & BIT(0))) {
  863. rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
  864. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path A\n");
  865. }
  866. if (!(tmp_u1b & BIT(4))) {
  867. tmp_u1b = rtl_read_byte(rtlpriv, 0x16);
  868. tmp_u1b &= 0x0F;
  869. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
  870. udelay(10);
  871. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
  872. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n");
  873. }
  874. rtl8723e_dm_init(hw);
  875. exit:
  876. local_irq_restore(flags);
  877. rtlpriv->rtlhal.being_init_adapter = false;
  878. return err;
  879. }
  880. static enum version_8723e _rtl8723e_read_chip_version(struct ieee80211_hw *hw)
  881. {
  882. struct rtl_priv *rtlpriv = rtl_priv(hw);
  883. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  884. enum version_8723e version = 0x0000;
  885. u32 value32;
  886. value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
  887. if (value32 & TRP_VAUX_EN) {
  888. version = (enum version_8723e)(version |
  889. ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
  890. /* RTL8723 with BT function. */
  891. version = (enum version_8723e)(version |
  892. ((value32 & BT_FUNC) ? CHIP_8723 : 0));
  893. } else {
  894. /* Normal mass production chip. */
  895. version = (enum version_8723e) NORMAL_CHIP;
  896. version = (enum version_8723e)(version |
  897. ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
  898. /* RTL8723 with BT function. */
  899. version = (enum version_8723e)(version |
  900. ((value32 & BT_FUNC) ? CHIP_8723 : 0));
  901. if (IS_CHIP_VENDOR_UMC(version))
  902. version = (enum version_8723e)(version |
  903. ((value32 & CHIP_VER_RTL_MASK)));/* IC version (CUT) */
  904. if (IS_8723_SERIES(version)) {
  905. value32 = rtl_read_dword(rtlpriv, REG_GPIO_OUTSTS);
  906. /* ROM code version. */
  907. version = (enum version_8723e)(version |
  908. ((value32 & RF_RL_ID)>>20));
  909. }
  910. }
  911. if (IS_8723_SERIES(version)) {
  912. value32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL);
  913. rtlphy->polarity_ctl = ((value32 & WL_HWPDN_SL) ?
  914. RT_POLARITY_HIGH_ACT :
  915. RT_POLARITY_LOW_ACT);
  916. }
  917. switch (version) {
  918. case VERSION_TEST_UMC_CHIP_8723:
  919. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  920. "Chip Version ID: VERSION_TEST_UMC_CHIP_8723.\n");
  921. break;
  922. case VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT:
  923. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  924. "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT.\n");
  925. break;
  926. case VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT:
  927. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  928. "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT.\n");
  929. break;
  930. default:
  931. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  932. "Chip Version ID: Unknown. Bug?\n");
  933. break;
  934. }
  935. if (IS_8723_SERIES(version))
  936. rtlphy->rf_type = RF_1T1R;
  937. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Chip RF Type: %s\n",
  938. (rtlphy->rf_type == RF_2T2R) ? "RF_2T2R" : "RF_1T1R");
  939. return version;
  940. }
  941. static int _rtl8723e_set_media_status(struct ieee80211_hw *hw,
  942. enum nl80211_iftype type)
  943. {
  944. struct rtl_priv *rtlpriv = rtl_priv(hw);
  945. u8 bt_msr = rtl_read_byte(rtlpriv, MSR) & 0xfc;
  946. enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
  947. u8 mode = MSR_NOLINK;
  948. rtl_write_dword(rtlpriv, REG_BCN_CTRL, 0);
  949. RT_TRACE(rtlpriv, COMP_BEACON, DBG_LOUD,
  950. "clear 0x550 when set HW_VAR_MEDIA_STATUS\n");
  951. switch (type) {
  952. case NL80211_IFTYPE_UNSPECIFIED:
  953. mode = MSR_NOLINK;
  954. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  955. "Set Network type to NO LINK!\n");
  956. break;
  957. case NL80211_IFTYPE_ADHOC:
  958. mode = MSR_ADHOC;
  959. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  960. "Set Network type to Ad Hoc!\n");
  961. break;
  962. case NL80211_IFTYPE_STATION:
  963. mode = MSR_INFRA;
  964. ledaction = LED_CTL_LINK;
  965. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  966. "Set Network type to STA!\n");
  967. break;
  968. case NL80211_IFTYPE_AP:
  969. mode = MSR_AP;
  970. ledaction = LED_CTL_LINK;
  971. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  972. "Set Network type to AP!\n");
  973. break;
  974. default:
  975. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  976. "Network type %d not support!\n", type);
  977. return 1;
  978. break;
  979. }
  980. /* MSR_INFRA == Link in infrastructure network;
  981. * MSR_ADHOC == Link in ad hoc network;
  982. * Therefore, check link state is necessary.
  983. *
  984. * MSR_AP == AP mode; link state is not cared here.
  985. */
  986. if (mode != MSR_AP &&
  987. rtlpriv->mac80211.link_state < MAC80211_LINKED) {
  988. mode = MSR_NOLINK;
  989. ledaction = LED_CTL_NO_LINK;
  990. }
  991. if (mode == MSR_NOLINK || mode == MSR_INFRA) {
  992. _rtl8723e_stop_tx_beacon(hw);
  993. _rtl8723e_enable_bcn_sub_func(hw);
  994. } else if (mode == MSR_ADHOC || mode == MSR_AP) {
  995. _rtl8723e_resume_tx_beacon(hw);
  996. _rtl8723e_disable_bcn_sub_func(hw);
  997. } else {
  998. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  999. "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
  1000. mode);
  1001. }
  1002. rtl_write_byte(rtlpriv, MSR, bt_msr | mode);
  1003. rtlpriv->cfg->ops->led_control(hw, ledaction);
  1004. if (mode == MSR_AP)
  1005. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
  1006. else
  1007. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
  1008. return 0;
  1009. }
  1010. void rtl8723e_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
  1011. {
  1012. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1013. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1014. u32 reg_rcr = rtlpci->receive_config;
  1015. if (rtlpriv->psc.rfpwr_state != ERFON)
  1016. return;
  1017. if (check_bssid) {
  1018. reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
  1019. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
  1020. (u8 *)(&reg_rcr));
  1021. _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(4));
  1022. } else if (!check_bssid) {
  1023. reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
  1024. _rtl8723e_set_bcn_ctrl_reg(hw, BIT(4), 0);
  1025. rtlpriv->cfg->ops->set_hw_reg(hw,
  1026. HW_VAR_RCR, (u8 *)(&reg_rcr));
  1027. }
  1028. }
  1029. int rtl8723e_set_network_type(struct ieee80211_hw *hw,
  1030. enum nl80211_iftype type)
  1031. {
  1032. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1033. if (_rtl8723e_set_media_status(hw, type))
  1034. return -EOPNOTSUPP;
  1035. if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
  1036. if (type != NL80211_IFTYPE_AP)
  1037. rtl8723e_set_check_bssid(hw, true);
  1038. } else {
  1039. rtl8723e_set_check_bssid(hw, false);
  1040. }
  1041. return 0;
  1042. }
  1043. /* don't set REG_EDCA_BE_PARAM here
  1044. * because mac80211 will send pkt when scan
  1045. */
  1046. void rtl8723e_set_qos(struct ieee80211_hw *hw, int aci)
  1047. {
  1048. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1049. rtl8723_dm_init_edca_turbo(hw);
  1050. switch (aci) {
  1051. case AC1_BK:
  1052. rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
  1053. break;
  1054. case AC0_BE:
  1055. break;
  1056. case AC2_VI:
  1057. rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
  1058. break;
  1059. case AC3_VO:
  1060. rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
  1061. break;
  1062. default:
  1063. RT_ASSERT(false, "invalid aci: %d !\n", aci);
  1064. break;
  1065. }
  1066. }
  1067. void rtl8723e_enable_interrupt(struct ieee80211_hw *hw)
  1068. {
  1069. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1070. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1071. rtl_write_dword(rtlpriv, 0x3a8, rtlpci->irq_mask[0] & 0xFFFFFFFF);
  1072. rtl_write_dword(rtlpriv, 0x3ac, rtlpci->irq_mask[1] & 0xFFFFFFFF);
  1073. rtlpci->irq_enabled = true;
  1074. }
  1075. void rtl8723e_disable_interrupt(struct ieee80211_hw *hw)
  1076. {
  1077. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1078. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1079. rtl_write_dword(rtlpriv, 0x3a8, IMR8190_DISABLED);
  1080. rtl_write_dword(rtlpriv, 0x3ac, IMR8190_DISABLED);
  1081. rtlpci->irq_enabled = false;
  1082. /*synchronize_irq(rtlpci->pdev->irq);*/
  1083. }
  1084. static void _rtl8723e_poweroff_adapter(struct ieee80211_hw *hw)
  1085. {
  1086. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1087. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1088. u8 u1b_tmp;
  1089. /* Combo (PCIe + USB) Card and PCIe-MF Card */
  1090. /* 1. Run LPS WL RFOFF flow */
  1091. rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  1092. PWR_INTF_PCI_MSK, Rtl8723_NIC_LPS_ENTER_FLOW);
  1093. /* 2. 0x1F[7:0] = 0 */
  1094. /* turn off RF */
  1095. rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
  1096. if ((rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) &&
  1097. rtlhal->fw_ready) {
  1098. rtl8723ae_firmware_selfreset(hw);
  1099. }
  1100. /* Reset MCU. Suggested by Filen. */
  1101. u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1);
  1102. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN+1, (u1b_tmp & (~BIT(2))));
  1103. /* g. MCUFWDL 0x80[1:0]=0 */
  1104. /* reset MCU ready status */
  1105. rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
  1106. /* HW card disable configuration. */
  1107. rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  1108. PWR_INTF_PCI_MSK, Rtl8723_NIC_DISABLE_FLOW);
  1109. /* Reset MCU IO Wrapper */
  1110. u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
  1111. rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp & (~BIT(0))));
  1112. u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
  1113. rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, u1b_tmp | BIT(0));
  1114. /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
  1115. /* lock ISO/CLK/Power control register */
  1116. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
  1117. }
  1118. void rtl8723e_card_disable(struct ieee80211_hw *hw)
  1119. {
  1120. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1121. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1122. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1123. enum nl80211_iftype opmode;
  1124. mac->link_state = MAC80211_NOLINK;
  1125. opmode = NL80211_IFTYPE_UNSPECIFIED;
  1126. _rtl8723e_set_media_status(hw, opmode);
  1127. if (rtlpriv->rtlhal.driver_is_goingto_unload ||
  1128. ppsc->rfoff_reason > RF_CHANGE_BY_PS)
  1129. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1130. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1131. _rtl8723e_poweroff_adapter(hw);
  1132. /* after power off we should do iqk again */
  1133. rtlpriv->phy.iqk_initialized = false;
  1134. }
  1135. void rtl8723e_interrupt_recognized(struct ieee80211_hw *hw,
  1136. u32 *p_inta, u32 *p_intb)
  1137. {
  1138. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1139. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1140. *p_inta = rtl_read_dword(rtlpriv, 0x3a0) & rtlpci->irq_mask[0];
  1141. rtl_write_dword(rtlpriv, 0x3a0, *p_inta);
  1142. }
  1143. void rtl8723e_set_beacon_related_registers(struct ieee80211_hw *hw)
  1144. {
  1145. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1146. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1147. u16 bcn_interval, atim_window;
  1148. bcn_interval = mac->beacon_interval;
  1149. atim_window = 2; /*FIX MERGE */
  1150. rtl8723e_disable_interrupt(hw);
  1151. rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
  1152. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1153. rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
  1154. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
  1155. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
  1156. rtl_write_byte(rtlpriv, 0x606, 0x30);
  1157. rtl8723e_enable_interrupt(hw);
  1158. }
  1159. void rtl8723e_set_beacon_interval(struct ieee80211_hw *hw)
  1160. {
  1161. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1162. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1163. u16 bcn_interval = mac->beacon_interval;
  1164. RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
  1165. "beacon_interval:%d\n", bcn_interval);
  1166. rtl8723e_disable_interrupt(hw);
  1167. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1168. rtl8723e_enable_interrupt(hw);
  1169. }
  1170. void rtl8723e_update_interrupt_mask(struct ieee80211_hw *hw,
  1171. u32 add_msr, u32 rm_msr)
  1172. {
  1173. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1174. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1175. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
  1176. "add_msr:%x, rm_msr:%x\n", add_msr, rm_msr);
  1177. if (add_msr)
  1178. rtlpci->irq_mask[0] |= add_msr;
  1179. if (rm_msr)
  1180. rtlpci->irq_mask[0] &= (~rm_msr);
  1181. rtl8723e_disable_interrupt(hw);
  1182. rtl8723e_enable_interrupt(hw);
  1183. }
  1184. static u8 _rtl8723e_get_chnl_group(u8 chnl)
  1185. {
  1186. u8 group;
  1187. if (chnl < 3)
  1188. group = 0;
  1189. else if (chnl < 9)
  1190. group = 1;
  1191. else
  1192. group = 2;
  1193. return group;
  1194. }
  1195. static void _rtl8723e_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
  1196. bool autoload_fail,
  1197. u8 *hwinfo)
  1198. {
  1199. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1200. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1201. u8 rf_path, index, tempval;
  1202. u16 i;
  1203. for (rf_path = 0; rf_path < 1; rf_path++) {
  1204. for (i = 0; i < 3; i++) {
  1205. if (!autoload_fail) {
  1206. rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][i] =
  1207. hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i];
  1208. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
  1209. hwinfo[EEPROM_TXPOWERHT40_1S + rf_path * 3 + i];
  1210. } else {
  1211. rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][i] =
  1212. EEPROM_DEFAULT_TXPOWERLEVEL;
  1213. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
  1214. EEPROM_DEFAULT_TXPOWERLEVEL;
  1215. }
  1216. }
  1217. }
  1218. for (i = 0; i < 3; i++) {
  1219. if (!autoload_fail)
  1220. tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i];
  1221. else
  1222. tempval = EEPROM_DEFAULT_HT40_2SDIFF;
  1223. rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_A][i] =
  1224. (tempval & 0xf);
  1225. rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_B][i] =
  1226. ((tempval & 0xf0) >> 4);
  1227. }
  1228. for (rf_path = 0; rf_path < 2; rf_path++)
  1229. for (i = 0; i < 3; i++)
  1230. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1231. "RF(%d) EEPROM CCK Area(%d) = 0x%x\n", rf_path,
  1232. i, rtlefuse->eeprom_chnlarea_txpwr_cck
  1233. [rf_path][i]);
  1234. for (rf_path = 0; rf_path < 2; rf_path++)
  1235. for (i = 0; i < 3; i++)
  1236. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1237. "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
  1238. rf_path, i,
  1239. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
  1240. [rf_path][i]);
  1241. for (rf_path = 0; rf_path < 2; rf_path++)
  1242. for (i = 0; i < 3; i++)
  1243. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1244. "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
  1245. rf_path, i,
  1246. rtlefuse->eprom_chnl_txpwr_ht40_2sdf
  1247. [rf_path][i]);
  1248. for (rf_path = 0; rf_path < 2; rf_path++) {
  1249. for (i = 0; i < 14; i++) {
  1250. index = _rtl8723e_get_chnl_group((u8)i);
  1251. rtlefuse->txpwrlevel_cck[rf_path][i] =
  1252. rtlefuse->eeprom_chnlarea_txpwr_cck
  1253. [rf_path][index];
  1254. rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
  1255. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
  1256. [rf_path][index];
  1257. if ((rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
  1258. [rf_path][index] -
  1259. rtlefuse->eprom_chnl_txpwr_ht40_2sdf
  1260. [rf_path][index]) > 0) {
  1261. rtlefuse->txpwrlevel_ht40_2s[rf_path][i] =
  1262. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
  1263. [rf_path][index] -
  1264. rtlefuse->eprom_chnl_txpwr_ht40_2sdf
  1265. [rf_path][index];
  1266. } else {
  1267. rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0;
  1268. }
  1269. }
  1270. for (i = 0; i < 14; i++) {
  1271. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1272. "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
  1273. rf_path, i,
  1274. rtlefuse->txpwrlevel_cck[rf_path][i],
  1275. rtlefuse->txpwrlevel_ht40_1s[rf_path][i],
  1276. rtlefuse->txpwrlevel_ht40_2s[rf_path][i]);
  1277. }
  1278. }
  1279. for (i = 0; i < 3; i++) {
  1280. if (!autoload_fail) {
  1281. rtlefuse->eeprom_pwrlimit_ht40[i] =
  1282. hwinfo[EEPROM_TXPWR_GROUP + i];
  1283. rtlefuse->eeprom_pwrlimit_ht20[i] =
  1284. hwinfo[EEPROM_TXPWR_GROUP + 3 + i];
  1285. } else {
  1286. rtlefuse->eeprom_pwrlimit_ht40[i] = 0;
  1287. rtlefuse->eeprom_pwrlimit_ht20[i] = 0;
  1288. }
  1289. }
  1290. for (rf_path = 0; rf_path < 2; rf_path++) {
  1291. for (i = 0; i < 14; i++) {
  1292. index = _rtl8723e_get_chnl_group((u8)i);
  1293. if (rf_path == RF90_PATH_A) {
  1294. rtlefuse->pwrgroup_ht20[rf_path][i] =
  1295. (rtlefuse->eeprom_pwrlimit_ht20[index] & 0xf);
  1296. rtlefuse->pwrgroup_ht40[rf_path][i] =
  1297. (rtlefuse->eeprom_pwrlimit_ht40[index] & 0xf);
  1298. } else if (rf_path == RF90_PATH_B) {
  1299. rtlefuse->pwrgroup_ht20[rf_path][i] =
  1300. ((rtlefuse->eeprom_pwrlimit_ht20[index] &
  1301. 0xf0) >> 4);
  1302. rtlefuse->pwrgroup_ht40[rf_path][i] =
  1303. ((rtlefuse->eeprom_pwrlimit_ht40[index] &
  1304. 0xf0) >> 4);
  1305. }
  1306. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1307. "RF-%d pwrgroup_ht20[%d] = 0x%x\n", rf_path, i,
  1308. rtlefuse->pwrgroup_ht20[rf_path][i]);
  1309. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1310. "RF-%d pwrgroup_ht40[%d] = 0x%x\n", rf_path, i,
  1311. rtlefuse->pwrgroup_ht40[rf_path][i]);
  1312. }
  1313. }
  1314. for (i = 0; i < 14; i++) {
  1315. index = _rtl8723e_get_chnl_group((u8)i);
  1316. if (!autoload_fail)
  1317. tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index];
  1318. else
  1319. tempval = EEPROM_DEFAULT_HT20_DIFF;
  1320. rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF);
  1321. rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] =
  1322. ((tempval >> 4) & 0xF);
  1323. if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3))
  1324. rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0;
  1325. if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3))
  1326. rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0;
  1327. index = _rtl8723e_get_chnl_group((u8)i);
  1328. if (!autoload_fail)
  1329. tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index];
  1330. else
  1331. tempval = EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF;
  1332. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF);
  1333. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] =
  1334. ((tempval >> 4) & 0xF);
  1335. }
  1336. rtlefuse->legacy_ht_txpowerdiff =
  1337. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7];
  1338. for (i = 0; i < 14; i++)
  1339. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1340. "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", i,
  1341. rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]);
  1342. for (i = 0; i < 14; i++)
  1343. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1344. "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", i,
  1345. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]);
  1346. for (i = 0; i < 14; i++)
  1347. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1348. "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", i,
  1349. rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]);
  1350. for (i = 0; i < 14; i++)
  1351. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1352. "RF-B Legacy to HT40 Diff[%d] = 0x%x\n", i,
  1353. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]);
  1354. if (!autoload_fail)
  1355. rtlefuse->eeprom_regulatory = (hwinfo[RF_OPTION1] & 0x7);
  1356. else
  1357. rtlefuse->eeprom_regulatory = 0;
  1358. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1359. "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
  1360. if (!autoload_fail)
  1361. rtlefuse->eeprom_tssi[RF90_PATH_A] = hwinfo[EEPROM_TSSI_A];
  1362. else
  1363. rtlefuse->eeprom_tssi[RF90_PATH_A] = EEPROM_DEFAULT_TSSI;
  1364. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1365. "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
  1366. rtlefuse->eeprom_tssi[RF90_PATH_A],
  1367. rtlefuse->eeprom_tssi[RF90_PATH_B]);
  1368. if (!autoload_fail)
  1369. tempval = hwinfo[EEPROM_THERMAL_METER];
  1370. else
  1371. tempval = EEPROM_DEFAULT_THERMALMETER;
  1372. rtlefuse->eeprom_thermalmeter = (tempval & 0x1f);
  1373. if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail)
  1374. rtlefuse->apk_thermalmeterignore = true;
  1375. rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
  1376. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1377. "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
  1378. }
  1379. static void _rtl8723e_read_adapter_info(struct ieee80211_hw *hw,
  1380. bool b_pseudo_test)
  1381. {
  1382. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1383. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1384. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1385. u16 i, usvalue;
  1386. u8 hwinfo[HWSET_MAX_SIZE];
  1387. u16 eeprom_id;
  1388. if (b_pseudo_test) {
  1389. /* need add */
  1390. return;
  1391. }
  1392. if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
  1393. rtl_efuse_shadow_map_update(hw);
  1394. memcpy(hwinfo, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
  1395. HWSET_MAX_SIZE);
  1396. } else if (rtlefuse->epromtype == EEPROM_93C46) {
  1397. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1398. "RTL819X Not boot from eeprom, check it !!");
  1399. }
  1400. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP\n",
  1401. hwinfo, HWSET_MAX_SIZE);
  1402. eeprom_id = *((u16 *)&hwinfo[0]);
  1403. if (eeprom_id != RTL8190_EEPROM_ID) {
  1404. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1405. "EEPROM ID(%#x) is invalid!!\n", eeprom_id);
  1406. rtlefuse->autoload_failflag = true;
  1407. } else {
  1408. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1409. rtlefuse->autoload_failflag = false;
  1410. }
  1411. if (rtlefuse->autoload_failflag)
  1412. return;
  1413. rtlefuse->eeprom_vid = *(u16 *)&hwinfo[EEPROM_VID];
  1414. rtlefuse->eeprom_did = *(u16 *)&hwinfo[EEPROM_DID];
  1415. rtlefuse->eeprom_svid = *(u16 *)&hwinfo[EEPROM_SVID];
  1416. rtlefuse->eeprom_smid = *(u16 *)&hwinfo[EEPROM_SMID];
  1417. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1418. "EEPROMId = 0x%4x\n", eeprom_id);
  1419. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1420. "EEPROM VID = 0x%4x\n", rtlefuse->eeprom_vid);
  1421. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1422. "EEPROM DID = 0x%4x\n", rtlefuse->eeprom_did);
  1423. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1424. "EEPROM SVID = 0x%4x\n", rtlefuse->eeprom_svid);
  1425. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1426. "EEPROM SMID = 0x%4x\n", rtlefuse->eeprom_smid);
  1427. for (i = 0; i < 6; i += 2) {
  1428. usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
  1429. *((u16 *)(&rtlefuse->dev_addr[i])) = usvalue;
  1430. }
  1431. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1432. "dev_addr: %pM\n", rtlefuse->dev_addr);
  1433. _rtl8723e_read_txpower_info_from_hwpg(hw, rtlefuse->autoload_failflag,
  1434. hwinfo);
  1435. rtl8723e_read_bt_coexist_info_from_hwpg(hw,
  1436. rtlefuse->autoload_failflag, hwinfo);
  1437. rtlefuse->eeprom_channelplan = hwinfo[EEPROM_CHANNELPLAN];
  1438. rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
  1439. rtlefuse->txpwr_fromeprom = true;
  1440. rtlefuse->eeprom_oemid = hwinfo[EEPROM_CUSTOMER_ID];
  1441. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1442. "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid);
  1443. /* set channel paln to world wide 13 */
  1444. rtlefuse->channel_plan = COUNTRY_CODE_WORLD_WIDE_13;
  1445. if (rtlhal->oem_id == RT_CID_DEFAULT) {
  1446. switch (rtlefuse->eeprom_oemid) {
  1447. case EEPROM_CID_DEFAULT:
  1448. if (rtlefuse->eeprom_did == 0x8176) {
  1449. if (CHK_SVID_SMID(0x10EC, 0x6151) ||
  1450. CHK_SVID_SMID(0x10EC, 0x6152) ||
  1451. CHK_SVID_SMID(0x10EC, 0x6154) ||
  1452. CHK_SVID_SMID(0x10EC, 0x6155) ||
  1453. CHK_SVID_SMID(0x10EC, 0x6177) ||
  1454. CHK_SVID_SMID(0x10EC, 0x6178) ||
  1455. CHK_SVID_SMID(0x10EC, 0x6179) ||
  1456. CHK_SVID_SMID(0x10EC, 0x6180) ||
  1457. CHK_SVID_SMID(0x10EC, 0x7151) ||
  1458. CHK_SVID_SMID(0x10EC, 0x7152) ||
  1459. CHK_SVID_SMID(0x10EC, 0x7154) ||
  1460. CHK_SVID_SMID(0x10EC, 0x7155) ||
  1461. CHK_SVID_SMID(0x10EC, 0x7177) ||
  1462. CHK_SVID_SMID(0x10EC, 0x7178) ||
  1463. CHK_SVID_SMID(0x10EC, 0x7179) ||
  1464. CHK_SVID_SMID(0x10EC, 0x7180) ||
  1465. CHK_SVID_SMID(0x10EC, 0x8151) ||
  1466. CHK_SVID_SMID(0x10EC, 0x8152) ||
  1467. CHK_SVID_SMID(0x10EC, 0x8154) ||
  1468. CHK_SVID_SMID(0x10EC, 0x8155) ||
  1469. CHK_SVID_SMID(0x10EC, 0x8181) ||
  1470. CHK_SVID_SMID(0x10EC, 0x8182) ||
  1471. CHK_SVID_SMID(0x10EC, 0x8184) ||
  1472. CHK_SVID_SMID(0x10EC, 0x8185) ||
  1473. CHK_SVID_SMID(0x10EC, 0x9151) ||
  1474. CHK_SVID_SMID(0x10EC, 0x9152) ||
  1475. CHK_SVID_SMID(0x10EC, 0x9154) ||
  1476. CHK_SVID_SMID(0x10EC, 0x9155) ||
  1477. CHK_SVID_SMID(0x10EC, 0x9181) ||
  1478. CHK_SVID_SMID(0x10EC, 0x9182) ||
  1479. CHK_SVID_SMID(0x10EC, 0x9184) ||
  1480. CHK_SVID_SMID(0x10EC, 0x9185))
  1481. rtlhal->oem_id = RT_CID_TOSHIBA;
  1482. else if (rtlefuse->eeprom_svid == 0x1025)
  1483. rtlhal->oem_id = RT_CID_819X_ACER;
  1484. else if (CHK_SVID_SMID(0x10EC, 0x6191) ||
  1485. CHK_SVID_SMID(0x10EC, 0x6192) ||
  1486. CHK_SVID_SMID(0x10EC, 0x6193) ||
  1487. CHK_SVID_SMID(0x10EC, 0x7191) ||
  1488. CHK_SVID_SMID(0x10EC, 0x7192) ||
  1489. CHK_SVID_SMID(0x10EC, 0x7193) ||
  1490. CHK_SVID_SMID(0x10EC, 0x8191) ||
  1491. CHK_SVID_SMID(0x10EC, 0x8192) ||
  1492. CHK_SVID_SMID(0x10EC, 0x8193) ||
  1493. CHK_SVID_SMID(0x10EC, 0x9191) ||
  1494. CHK_SVID_SMID(0x10EC, 0x9192) ||
  1495. CHK_SVID_SMID(0x10EC, 0x9193))
  1496. rtlhal->oem_id = RT_CID_819X_SAMSUNG;
  1497. else if (CHK_SVID_SMID(0x10EC, 0x8195) ||
  1498. CHK_SVID_SMID(0x10EC, 0x9195) ||
  1499. CHK_SVID_SMID(0x10EC, 0x7194) ||
  1500. CHK_SVID_SMID(0x10EC, 0x8200) ||
  1501. CHK_SVID_SMID(0x10EC, 0x8201) ||
  1502. CHK_SVID_SMID(0x10EC, 0x8202) ||
  1503. CHK_SVID_SMID(0x10EC, 0x9200))
  1504. rtlhal->oem_id = RT_CID_819X_LENOVO;
  1505. else if (CHK_SVID_SMID(0x10EC, 0x8197) ||
  1506. CHK_SVID_SMID(0x10EC, 0x9196))
  1507. rtlhal->oem_id = RT_CID_819X_CLEVO;
  1508. else if (CHK_SVID_SMID(0x1028, 0x8194) ||
  1509. CHK_SVID_SMID(0x1028, 0x8198) ||
  1510. CHK_SVID_SMID(0x1028, 0x9197) ||
  1511. CHK_SVID_SMID(0x1028, 0x9198))
  1512. rtlhal->oem_id = RT_CID_819X_DELL;
  1513. else if (CHK_SVID_SMID(0x103C, 0x1629))
  1514. rtlhal->oem_id = RT_CID_819X_HP;
  1515. else if (CHK_SVID_SMID(0x1A32, 0x2315))
  1516. rtlhal->oem_id = RT_CID_819X_QMI;
  1517. else if (CHK_SVID_SMID(0x10EC, 0x8203))
  1518. rtlhal->oem_id = RT_CID_819X_PRONETS;
  1519. else if (CHK_SVID_SMID(0x1043, 0x84B5))
  1520. rtlhal->oem_id =
  1521. RT_CID_819X_EDIMAX_ASUS;
  1522. else
  1523. rtlhal->oem_id = RT_CID_DEFAULT;
  1524. } else if (rtlefuse->eeprom_did == 0x8178) {
  1525. if (CHK_SVID_SMID(0x10EC, 0x6181) ||
  1526. CHK_SVID_SMID(0x10EC, 0x6182) ||
  1527. CHK_SVID_SMID(0x10EC, 0x6184) ||
  1528. CHK_SVID_SMID(0x10EC, 0x6185) ||
  1529. CHK_SVID_SMID(0x10EC, 0x7181) ||
  1530. CHK_SVID_SMID(0x10EC, 0x7182) ||
  1531. CHK_SVID_SMID(0x10EC, 0x7184) ||
  1532. CHK_SVID_SMID(0x10EC, 0x7185) ||
  1533. CHK_SVID_SMID(0x10EC, 0x8181) ||
  1534. CHK_SVID_SMID(0x10EC, 0x8182) ||
  1535. CHK_SVID_SMID(0x10EC, 0x8184) ||
  1536. CHK_SVID_SMID(0x10EC, 0x8185) ||
  1537. CHK_SVID_SMID(0x10EC, 0x9181) ||
  1538. CHK_SVID_SMID(0x10EC, 0x9182) ||
  1539. CHK_SVID_SMID(0x10EC, 0x9184) ||
  1540. CHK_SVID_SMID(0x10EC, 0x9185))
  1541. rtlhal->oem_id = RT_CID_TOSHIBA;
  1542. else if (rtlefuse->eeprom_svid == 0x1025)
  1543. rtlhal->oem_id = RT_CID_819X_ACER;
  1544. else if (CHK_SVID_SMID(0x10EC, 0x8186))
  1545. rtlhal->oem_id = RT_CID_819X_PRONETS;
  1546. else if (CHK_SVID_SMID(0x1043, 0x8486))
  1547. rtlhal->oem_id =
  1548. RT_CID_819X_EDIMAX_ASUS;
  1549. else
  1550. rtlhal->oem_id = RT_CID_DEFAULT;
  1551. } else {
  1552. rtlhal->oem_id = RT_CID_DEFAULT;
  1553. }
  1554. break;
  1555. case EEPROM_CID_TOSHIBA:
  1556. rtlhal->oem_id = RT_CID_TOSHIBA;
  1557. break;
  1558. case EEPROM_CID_CCX:
  1559. rtlhal->oem_id = RT_CID_CCX;
  1560. break;
  1561. case EEPROM_CID_QMI:
  1562. rtlhal->oem_id = RT_CID_819X_QMI;
  1563. break;
  1564. case EEPROM_CID_WHQL:
  1565. break;
  1566. default:
  1567. rtlhal->oem_id = RT_CID_DEFAULT;
  1568. break;
  1569. }
  1570. }
  1571. }
  1572. static void _rtl8723e_hal_customized_behavior(struct ieee80211_hw *hw)
  1573. {
  1574. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1575. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1576. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1577. pcipriv->ledctl.led_opendrain = true;
  1578. switch (rtlhal->oem_id) {
  1579. case RT_CID_819X_HP:
  1580. pcipriv->ledctl.led_opendrain = true;
  1581. break;
  1582. case RT_CID_819X_LENOVO:
  1583. case RT_CID_DEFAULT:
  1584. case RT_CID_TOSHIBA:
  1585. case RT_CID_CCX:
  1586. case RT_CID_819X_ACER:
  1587. case RT_CID_WHQL:
  1588. default:
  1589. break;
  1590. }
  1591. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1592. "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
  1593. }
  1594. void rtl8723e_read_eeprom_info(struct ieee80211_hw *hw)
  1595. {
  1596. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1597. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1598. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1599. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1600. u8 tmp_u1b;
  1601. u32 value32;
  1602. value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST]);
  1603. value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0);
  1604. rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST], value32);
  1605. rtlhal->version = _rtl8723e_read_chip_version(hw);
  1606. if (get_rf_type(rtlphy) == RF_1T1R)
  1607. rtlpriv->dm.rfpath_rxenable[0] = true;
  1608. else
  1609. rtlpriv->dm.rfpath_rxenable[0] =
  1610. rtlpriv->dm.rfpath_rxenable[1] = true;
  1611. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
  1612. rtlhal->version);
  1613. tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
  1614. if (tmp_u1b & BIT(4)) {
  1615. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
  1616. rtlefuse->epromtype = EEPROM_93C46;
  1617. } else {
  1618. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
  1619. rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
  1620. }
  1621. if (tmp_u1b & BIT(5)) {
  1622. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1623. rtlefuse->autoload_failflag = false;
  1624. _rtl8723e_read_adapter_info(hw, false);
  1625. } else {
  1626. rtlefuse->autoload_failflag = true;
  1627. _rtl8723e_read_adapter_info(hw, false);
  1628. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Autoload ERR!!\n");
  1629. }
  1630. _rtl8723e_hal_customized_behavior(hw);
  1631. }
  1632. static void rtl8723e_update_hal_rate_table(struct ieee80211_hw *hw,
  1633. struct ieee80211_sta *sta)
  1634. {
  1635. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1636. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1637. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1638. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1639. u32 ratr_value;
  1640. u8 ratr_index = 0;
  1641. u8 b_nmode = mac->ht_enable;
  1642. u16 shortgi_rate;
  1643. u32 tmp_ratr_value;
  1644. u8 curtxbw_40mhz = mac->bw_40;
  1645. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1646. 1 : 0;
  1647. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1648. 1 : 0;
  1649. enum wireless_mode wirelessmode = mac->mode;
  1650. u32 ratr_mask;
  1651. if (rtlhal->current_bandtype == BAND_ON_5G)
  1652. ratr_value = sta->supp_rates[1] << 4;
  1653. else
  1654. ratr_value = sta->supp_rates[0];
  1655. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1656. ratr_value = 0xfff;
  1657. ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1658. sta->ht_cap.mcs.rx_mask[0] << 12);
  1659. switch (wirelessmode) {
  1660. case WIRELESS_MODE_B:
  1661. if (ratr_value & 0x0000000c)
  1662. ratr_value &= 0x0000000d;
  1663. else
  1664. ratr_value &= 0x0000000f;
  1665. break;
  1666. case WIRELESS_MODE_G:
  1667. ratr_value &= 0x00000FF5;
  1668. break;
  1669. case WIRELESS_MODE_N_24G:
  1670. case WIRELESS_MODE_N_5G:
  1671. b_nmode = 1;
  1672. if (get_rf_type(rtlphy) == RF_1T2R ||
  1673. get_rf_type(rtlphy) == RF_1T1R)
  1674. ratr_mask = 0x000ff005;
  1675. else
  1676. ratr_mask = 0x0f0ff005;
  1677. ratr_value &= ratr_mask;
  1678. break;
  1679. default:
  1680. if (rtlphy->rf_type == RF_1T2R)
  1681. ratr_value &= 0x000ff0ff;
  1682. else
  1683. ratr_value &= 0x0f0ff0ff;
  1684. break;
  1685. }
  1686. if ((rtlpriv->btcoexist.bt_coexistence) &&
  1687. (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) &&
  1688. (rtlpriv->btcoexist.bt_cur_state) &&
  1689. (rtlpriv->btcoexist.bt_ant_isolation) &&
  1690. ((rtlpriv->btcoexist.bt_service == BT_SCO) ||
  1691. (rtlpriv->btcoexist.bt_service == BT_BUSY)))
  1692. ratr_value &= 0x0fffcfc0;
  1693. else
  1694. ratr_value &= 0x0FFFFFFF;
  1695. if (b_nmode &&
  1696. ((curtxbw_40mhz && curshortgi_40mhz) ||
  1697. (!curtxbw_40mhz && curshortgi_20mhz))) {
  1698. ratr_value |= 0x10000000;
  1699. tmp_ratr_value = (ratr_value >> 12);
  1700. for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
  1701. if ((1 << shortgi_rate) & tmp_ratr_value)
  1702. break;
  1703. }
  1704. shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
  1705. (shortgi_rate << 4) | (shortgi_rate);
  1706. }
  1707. rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
  1708. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1709. "%x\n", rtl_read_dword(rtlpriv, REG_ARFR0));
  1710. }
  1711. static void rtl8723e_update_hal_rate_mask(struct ieee80211_hw *hw,
  1712. struct ieee80211_sta *sta,
  1713. u8 rssi_level)
  1714. {
  1715. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1716. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1717. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1718. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1719. struct rtl_sta_info *sta_entry = NULL;
  1720. u32 ratr_bitmap;
  1721. u8 ratr_index;
  1722. u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
  1723. ? 1 : 0;
  1724. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1725. 1 : 0;
  1726. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1727. 1 : 0;
  1728. enum wireless_mode wirelessmode = 0;
  1729. bool shortgi = false;
  1730. u8 rate_mask[5];
  1731. u8 macid = 0;
  1732. /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
  1733. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1734. wirelessmode = sta_entry->wireless_mode;
  1735. if (mac->opmode == NL80211_IFTYPE_STATION)
  1736. curtxbw_40mhz = mac->bw_40;
  1737. else if (mac->opmode == NL80211_IFTYPE_AP ||
  1738. mac->opmode == NL80211_IFTYPE_ADHOC)
  1739. macid = sta->aid + 1;
  1740. if (rtlhal->current_bandtype == BAND_ON_5G)
  1741. ratr_bitmap = sta->supp_rates[1] << 4;
  1742. else
  1743. ratr_bitmap = sta->supp_rates[0];
  1744. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1745. ratr_bitmap = 0xfff;
  1746. ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1747. sta->ht_cap.mcs.rx_mask[0] << 12);
  1748. switch (wirelessmode) {
  1749. case WIRELESS_MODE_B:
  1750. ratr_index = RATR_INX_WIRELESS_B;
  1751. if (ratr_bitmap & 0x0000000c)
  1752. ratr_bitmap &= 0x0000000d;
  1753. else
  1754. ratr_bitmap &= 0x0000000f;
  1755. break;
  1756. case WIRELESS_MODE_G:
  1757. ratr_index = RATR_INX_WIRELESS_GB;
  1758. if (rssi_level == 1)
  1759. ratr_bitmap &= 0x00000f00;
  1760. else if (rssi_level == 2)
  1761. ratr_bitmap &= 0x00000ff0;
  1762. else
  1763. ratr_bitmap &= 0x00000ff5;
  1764. break;
  1765. case WIRELESS_MODE_A:
  1766. ratr_index = RATR_INX_WIRELESS_G;
  1767. ratr_bitmap &= 0x00000ff0;
  1768. break;
  1769. case WIRELESS_MODE_N_24G:
  1770. case WIRELESS_MODE_N_5G:
  1771. ratr_index = RATR_INX_WIRELESS_NGB;
  1772. if (rtlphy->rf_type == RF_1T2R ||
  1773. rtlphy->rf_type == RF_1T1R) {
  1774. if (curtxbw_40mhz) {
  1775. if (rssi_level == 1)
  1776. ratr_bitmap &= 0x000f0000;
  1777. else if (rssi_level == 2)
  1778. ratr_bitmap &= 0x000ff000;
  1779. else
  1780. ratr_bitmap &= 0x000ff015;
  1781. } else {
  1782. if (rssi_level == 1)
  1783. ratr_bitmap &= 0x000f0000;
  1784. else if (rssi_level == 2)
  1785. ratr_bitmap &= 0x000ff000;
  1786. else
  1787. ratr_bitmap &= 0x000ff005;
  1788. }
  1789. } else {
  1790. if (curtxbw_40mhz) {
  1791. if (rssi_level == 1)
  1792. ratr_bitmap &= 0x0f0f0000;
  1793. else if (rssi_level == 2)
  1794. ratr_bitmap &= 0x0f0ff000;
  1795. else
  1796. ratr_bitmap &= 0x0f0ff015;
  1797. } else {
  1798. if (rssi_level == 1)
  1799. ratr_bitmap &= 0x0f0f0000;
  1800. else if (rssi_level == 2)
  1801. ratr_bitmap &= 0x0f0ff000;
  1802. else
  1803. ratr_bitmap &= 0x0f0ff005;
  1804. }
  1805. }
  1806. if ((curtxbw_40mhz && curshortgi_40mhz) ||
  1807. (!curtxbw_40mhz && curshortgi_20mhz)) {
  1808. if (macid == 0)
  1809. shortgi = true;
  1810. else if (macid == 1)
  1811. shortgi = false;
  1812. }
  1813. break;
  1814. default:
  1815. ratr_index = RATR_INX_WIRELESS_NGB;
  1816. if (rtlphy->rf_type == RF_1T2R)
  1817. ratr_bitmap &= 0x000ff0ff;
  1818. else
  1819. ratr_bitmap &= 0x0f0ff0ff;
  1820. break;
  1821. }
  1822. sta_entry->ratr_index = ratr_index;
  1823. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1824. "ratr_bitmap :%x\n", ratr_bitmap);
  1825. *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
  1826. (ratr_index << 28);
  1827. rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
  1828. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1829. "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n",
  1830. ratr_index, ratr_bitmap,
  1831. rate_mask[0], rate_mask[1],
  1832. rate_mask[2], rate_mask[3],
  1833. rate_mask[4]);
  1834. rtl8723e_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask);
  1835. }
  1836. void rtl8723e_update_hal_rate_tbl(struct ieee80211_hw *hw,
  1837. struct ieee80211_sta *sta, u8 rssi_level)
  1838. {
  1839. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1840. if (rtlpriv->dm.useramask)
  1841. rtl8723e_update_hal_rate_mask(hw, sta, rssi_level);
  1842. else
  1843. rtl8723e_update_hal_rate_table(hw, sta);
  1844. }
  1845. void rtl8723e_update_channel_access_setting(struct ieee80211_hw *hw)
  1846. {
  1847. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1848. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1849. u16 sifs_timer;
  1850. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, &mac->slot_time);
  1851. if (!mac->ht_enable)
  1852. sifs_timer = 0x0a0a;
  1853. else
  1854. sifs_timer = 0x1010;
  1855. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
  1856. }
  1857. bool rtl8723e_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
  1858. {
  1859. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1860. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1861. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1862. enum rf_pwrstate e_rfpowerstate_toset, cur_rfstate;
  1863. u8 u1tmp;
  1864. bool b_actuallyset = false;
  1865. if (rtlpriv->rtlhal.being_init_adapter)
  1866. return false;
  1867. if (ppsc->swrf_processing)
  1868. return false;
  1869. spin_lock(&rtlpriv->locks.rf_ps_lock);
  1870. if (ppsc->rfchange_inprogress) {
  1871. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1872. return false;
  1873. } else {
  1874. ppsc->rfchange_inprogress = true;
  1875. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1876. }
  1877. cur_rfstate = ppsc->rfpwr_state;
  1878. rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL_2,
  1879. rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL_2)&~(BIT(1)));
  1880. u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL_2);
  1881. if (rtlphy->polarity_ctl)
  1882. e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFOFF : ERFON;
  1883. else
  1884. e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFON : ERFOFF;
  1885. if (ppsc->hwradiooff && (e_rfpowerstate_toset == ERFON)) {
  1886. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1887. "GPIOChangeRF - HW Radio ON, RF ON\n");
  1888. e_rfpowerstate_toset = ERFON;
  1889. ppsc->hwradiooff = false;
  1890. b_actuallyset = true;
  1891. } else if (!ppsc->hwradiooff && (e_rfpowerstate_toset == ERFOFF)) {
  1892. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1893. "GPIOChangeRF - HW Radio OFF, RF OFF\n");
  1894. e_rfpowerstate_toset = ERFOFF;
  1895. ppsc->hwradiooff = true;
  1896. b_actuallyset = true;
  1897. }
  1898. if (b_actuallyset) {
  1899. spin_lock(&rtlpriv->locks.rf_ps_lock);
  1900. ppsc->rfchange_inprogress = false;
  1901. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1902. } else {
  1903. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
  1904. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1905. spin_lock(&rtlpriv->locks.rf_ps_lock);
  1906. ppsc->rfchange_inprogress = false;
  1907. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1908. }
  1909. *valid = 1;
  1910. return !ppsc->hwradiooff;
  1911. }
  1912. void rtl8723e_set_key(struct ieee80211_hw *hw, u32 key_index,
  1913. u8 *p_macaddr, bool is_group, u8 enc_algo,
  1914. bool is_wepkey, bool clear_all)
  1915. {
  1916. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1917. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1918. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1919. u8 *macaddr = p_macaddr;
  1920. u32 entry_id = 0;
  1921. bool is_pairwise = false;
  1922. static u8 cam_const_addr[4][6] = {
  1923. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  1924. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  1925. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  1926. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  1927. };
  1928. static u8 cam_const_broad[] = {
  1929. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  1930. };
  1931. if (clear_all) {
  1932. u8 idx = 0;
  1933. u8 cam_offset = 0;
  1934. u8 clear_number = 5;
  1935. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  1936. for (idx = 0; idx < clear_number; idx++) {
  1937. rtl_cam_mark_invalid(hw, cam_offset + idx);
  1938. rtl_cam_empty_entry(hw, cam_offset + idx);
  1939. if (idx < 5) {
  1940. memset(rtlpriv->sec.key_buf[idx], 0,
  1941. MAX_KEY_LEN);
  1942. rtlpriv->sec.key_len[idx] = 0;
  1943. }
  1944. }
  1945. } else {
  1946. switch (enc_algo) {
  1947. case WEP40_ENCRYPTION:
  1948. enc_algo = CAM_WEP40;
  1949. break;
  1950. case WEP104_ENCRYPTION:
  1951. enc_algo = CAM_WEP104;
  1952. break;
  1953. case TKIP_ENCRYPTION:
  1954. enc_algo = CAM_TKIP;
  1955. break;
  1956. case AESCCMP_ENCRYPTION:
  1957. enc_algo = CAM_AES;
  1958. break;
  1959. default:
  1960. RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
  1961. "switch case not process\n");
  1962. enc_algo = CAM_TKIP;
  1963. break;
  1964. }
  1965. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  1966. macaddr = cam_const_addr[key_index];
  1967. entry_id = key_index;
  1968. } else {
  1969. if (is_group) {
  1970. macaddr = cam_const_broad;
  1971. entry_id = key_index;
  1972. } else {
  1973. if (mac->opmode == NL80211_IFTYPE_AP) {
  1974. entry_id =
  1975. rtl_cam_get_free_entry(hw, p_macaddr);
  1976. if (entry_id >= TOTAL_CAM_ENTRY) {
  1977. RT_TRACE(rtlpriv, COMP_SEC,
  1978. DBG_EMERG,
  1979. "Can not find free hw security cam entry\n");
  1980. return;
  1981. }
  1982. } else {
  1983. entry_id = CAM_PAIRWISE_KEY_POSITION;
  1984. }
  1985. key_index = PAIRWISE_KEYIDX;
  1986. is_pairwise = true;
  1987. }
  1988. }
  1989. if (rtlpriv->sec.key_len[key_index] == 0) {
  1990. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1991. "delete one entry, entry_id is %d\n",
  1992. entry_id);
  1993. if (mac->opmode == NL80211_IFTYPE_AP)
  1994. rtl_cam_del_entry(hw, p_macaddr);
  1995. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  1996. } else {
  1997. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1998. "add one entry\n");
  1999. if (is_pairwise) {
  2000. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2001. "set Pairwiase key\n");
  2002. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2003. entry_id, enc_algo,
  2004. CAM_CONFIG_NO_USEDK,
  2005. rtlpriv->sec.key_buf[key_index]);
  2006. } else {
  2007. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2008. "set group key\n");
  2009. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  2010. rtl_cam_add_one_entry(hw,
  2011. rtlefuse->dev_addr,
  2012. PAIRWISE_KEYIDX,
  2013. CAM_PAIRWISE_KEY_POSITION,
  2014. enc_algo,
  2015. CAM_CONFIG_NO_USEDK,
  2016. rtlpriv->sec.key_buf
  2017. [entry_id]);
  2018. }
  2019. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2020. entry_id, enc_algo,
  2021. CAM_CONFIG_NO_USEDK,
  2022. rtlpriv->sec.key_buf[entry_id]);
  2023. }
  2024. }
  2025. }
  2026. }
  2027. static void rtl8723e_bt_var_init(struct ieee80211_hw *hw)
  2028. {
  2029. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2030. rtlpriv->btcoexist.bt_coexistence =
  2031. rtlpriv->btcoexist.eeprom_bt_coexist;
  2032. rtlpriv->btcoexist.bt_ant_num =
  2033. rtlpriv->btcoexist.eeprom_bt_ant_num;
  2034. rtlpriv->btcoexist.bt_coexist_type =
  2035. rtlpriv->btcoexist.eeprom_bt_type;
  2036. rtlpriv->btcoexist.bt_ant_isolation =
  2037. rtlpriv->btcoexist.eeprom_bt_ant_isol;
  2038. rtlpriv->btcoexist.bt_radio_shared_type =
  2039. rtlpriv->btcoexist.eeprom_bt_radio_shared;
  2040. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2041. "BT Coexistance = 0x%x\n",
  2042. rtlpriv->btcoexist.bt_coexistence);
  2043. if (rtlpriv->btcoexist.bt_coexistence) {
  2044. rtlpriv->btcoexist.bt_busy_traffic = false;
  2045. rtlpriv->btcoexist.bt_traffic_mode_set = false;
  2046. rtlpriv->btcoexist.bt_non_traffic_mode_set = false;
  2047. rtlpriv->btcoexist.cstate = 0;
  2048. rtlpriv->btcoexist.previous_state = 0;
  2049. if (rtlpriv->btcoexist.bt_ant_num == ANT_X2) {
  2050. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2051. "BlueTooth BT_Ant_Num = Antx2\n");
  2052. } else if (rtlpriv->btcoexist.bt_ant_num == ANT_X1) {
  2053. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2054. "BlueTooth BT_Ant_Num = Antx1\n");
  2055. }
  2056. switch (rtlpriv->btcoexist.bt_coexist_type) {
  2057. case BT_2WIRE:
  2058. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2059. "BlueTooth BT_CoexistType = BT_2Wire\n");
  2060. break;
  2061. case BT_ISSC_3WIRE:
  2062. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2063. "BlueTooth BT_CoexistType = BT_ISSC_3Wire\n");
  2064. break;
  2065. case BT_ACCEL:
  2066. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2067. "BlueTooth BT_CoexistType = BT_ACCEL\n");
  2068. break;
  2069. case BT_CSR_BC4:
  2070. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2071. "BlueTooth BT_CoexistType = BT_CSR_BC4\n");
  2072. break;
  2073. case BT_CSR_BC8:
  2074. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2075. "BlueTooth BT_CoexistType = BT_CSR_BC8\n");
  2076. break;
  2077. case BT_RTL8756:
  2078. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2079. "BlueTooth BT_CoexistType = BT_RTL8756\n");
  2080. break;
  2081. default:
  2082. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2083. "BlueTooth BT_CoexistType = Unknown\n");
  2084. break;
  2085. }
  2086. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2087. "BlueTooth BT_Ant_isolation = %d\n",
  2088. rtlpriv->btcoexist.bt_ant_isolation);
  2089. RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
  2090. "BT_RadioSharedType = 0x%x\n",
  2091. rtlpriv->btcoexist.bt_radio_shared_type);
  2092. rtlpriv->btcoexist.bt_active_zero_cnt = 0;
  2093. rtlpriv->btcoexist.cur_bt_disabled = false;
  2094. rtlpriv->btcoexist.pre_bt_disabled = false;
  2095. }
  2096. }
  2097. void rtl8723e_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
  2098. bool auto_load_fail, u8 *hwinfo)
  2099. {
  2100. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2101. u8 value;
  2102. u32 tmpu_32;
  2103. if (!auto_load_fail) {
  2104. tmpu_32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL);
  2105. if (tmpu_32 & BIT(18))
  2106. rtlpriv->btcoexist.eeprom_bt_coexist = 1;
  2107. else
  2108. rtlpriv->btcoexist.eeprom_bt_coexist = 0;
  2109. value = hwinfo[RF_OPTION4];
  2110. rtlpriv->btcoexist.eeprom_bt_type = BT_RTL8723A;
  2111. rtlpriv->btcoexist.eeprom_bt_ant_num = (value & 0x1);
  2112. rtlpriv->btcoexist.eeprom_bt_ant_isol = ((value & 0x10) >> 4);
  2113. rtlpriv->btcoexist.eeprom_bt_radio_shared =
  2114. ((value & 0x20) >> 5);
  2115. } else {
  2116. rtlpriv->btcoexist.eeprom_bt_coexist = 0;
  2117. rtlpriv->btcoexist.eeprom_bt_type = BT_RTL8723A;
  2118. rtlpriv->btcoexist.eeprom_bt_ant_num = ANT_X2;
  2119. rtlpriv->btcoexist.eeprom_bt_ant_isol = 0;
  2120. rtlpriv->btcoexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
  2121. }
  2122. rtl8723e_bt_var_init(hw);
  2123. }
  2124. void rtl8723e_bt_reg_init(struct ieee80211_hw *hw)
  2125. {
  2126. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2127. /* 0:Low, 1:High, 2:From Efuse. */
  2128. rtlpriv->btcoexist.reg_bt_iso = 2;
  2129. /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
  2130. rtlpriv->btcoexist.reg_bt_sco = 3;
  2131. /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
  2132. rtlpriv->btcoexist.reg_bt_sco = 0;
  2133. }
  2134. void rtl8723e_bt_hw_init(struct ieee80211_hw *hw)
  2135. {
  2136. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2137. if (rtlpriv->cfg->ops->get_btc_status())
  2138. rtlpriv->btcoexist.btc_ops->btc_init_hw_config(rtlpriv);
  2139. }
  2140. void rtl8723e_suspend(struct ieee80211_hw *hw)
  2141. {
  2142. }
  2143. void rtl8723e_resume(struct ieee80211_hw *hw)
  2144. {
  2145. }