hw.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427
  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. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #include "../wifi.h"
  30. #include "../efuse.h"
  31. #include "../base.h"
  32. #include "../regd.h"
  33. #include "../cam.h"
  34. #include "../ps.h"
  35. #include "../pci.h"
  36. #include "reg.h"
  37. #include "def.h"
  38. #include "phy.h"
  39. #include "../rtl8192c/dm_common.h"
  40. #include "../rtl8192c/fw_common.h"
  41. #include "../rtl8192c/phy_common.h"
  42. #include "dm.h"
  43. #include "led.h"
  44. #include "hw.h"
  45. #define LLT_CONFIG 5
  46. static void _rtl92ce_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 _rtl92ce_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 _rtl92ce_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(0);
  75. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
  76. }
  77. static void _rtl92ce_enable_bcn_sub_func(struct ieee80211_hw *hw)
  78. {
  79. _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(1));
  80. }
  81. static void _rtl92ce_disable_bcn_sub_func(struct ieee80211_hw *hw)
  82. {
  83. _rtl92ce_set_bcn_ctrl_reg(hw, BIT(1), 0);
  84. }
  85. void rtl92ce_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_EMERG,
  129. "switch case not processed\n");
  130. break;
  131. }
  132. }
  133. void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  134. {
  135. struct rtl_priv *rtlpriv = rtl_priv(hw);
  136. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  137. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  138. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  139. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  140. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  141. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  142. u8 idx;
  143. switch (variable) {
  144. case HW_VAR_ETHER_ADDR:{
  145. for (idx = 0; idx < ETH_ALEN; idx++) {
  146. rtl_write_byte(rtlpriv, (REG_MACID + idx),
  147. val[idx]);
  148. }
  149. break;
  150. }
  151. case HW_VAR_BASIC_RATE:{
  152. u16 rate_cfg = ((u16 *) val)[0];
  153. u8 rate_index = 0;
  154. rate_cfg &= 0x15f;
  155. rate_cfg |= 0x01;
  156. rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff);
  157. rtl_write_byte(rtlpriv, REG_RRSR + 1,
  158. (rate_cfg >> 8) & 0xff);
  159. while (rate_cfg > 0x1) {
  160. rate_cfg = (rate_cfg >> 1);
  161. rate_index++;
  162. }
  163. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
  164. rate_index);
  165. break;
  166. }
  167. case HW_VAR_BSSID:{
  168. for (idx = 0; idx < ETH_ALEN; idx++) {
  169. rtl_write_byte(rtlpriv, (REG_BSSID + idx),
  170. val[idx]);
  171. }
  172. break;
  173. }
  174. case HW_VAR_SIFS:{
  175. rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
  176. rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
  177. rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
  178. rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
  179. if (!mac->ht_enable)
  180. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  181. 0x0e0e);
  182. else
  183. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  184. *((u16 *) val));
  185. break;
  186. }
  187. case HW_VAR_SLOT_TIME:{
  188. u8 e_aci;
  189. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  190. "HW_VAR_SLOT_TIME %x\n", val[0]);
  191. rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
  192. for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
  193. rtlpriv->cfg->ops->set_hw_reg(hw,
  194. HW_VAR_AC_PARAM,
  195. &e_aci);
  196. }
  197. break;
  198. }
  199. case HW_VAR_ACK_PREAMBLE:{
  200. u8 reg_tmp;
  201. u8 short_preamble = (bool)*val;
  202. reg_tmp = (mac->cur_40_prime_sc) << 5;
  203. if (short_preamble)
  204. reg_tmp |= 0x80;
  205. rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
  206. break;
  207. }
  208. case HW_VAR_AMPDU_MIN_SPACE:{
  209. u8 min_spacing_to_set;
  210. u8 sec_min_space;
  211. min_spacing_to_set = *val;
  212. if (min_spacing_to_set <= 7) {
  213. sec_min_space = 0;
  214. if (min_spacing_to_set < sec_min_space)
  215. min_spacing_to_set = sec_min_space;
  216. mac->min_space_cfg = ((mac->min_space_cfg &
  217. 0xf8) |
  218. min_spacing_to_set);
  219. *val = min_spacing_to_set;
  220. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  221. "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
  222. mac->min_space_cfg);
  223. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  224. mac->min_space_cfg);
  225. }
  226. break;
  227. }
  228. case HW_VAR_SHORTGI_DENSITY:{
  229. u8 density_to_set;
  230. density_to_set = *val;
  231. mac->min_space_cfg |= (density_to_set << 3);
  232. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  233. "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
  234. mac->min_space_cfg);
  235. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  236. mac->min_space_cfg);
  237. break;
  238. }
  239. case HW_VAR_AMPDU_FACTOR:{
  240. u8 regtoset_normal[4] = {0x41, 0xa8, 0x72, 0xb9};
  241. u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97};
  242. u8 factor_toset;
  243. u8 *p_regtoset = NULL;
  244. u8 index = 0;
  245. if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
  246. (rtlpcipriv->bt_coexist.bt_coexist_type ==
  247. BT_CSR_BC4))
  248. p_regtoset = regtoset_bt;
  249. else
  250. p_regtoset = regtoset_normal;
  251. factor_toset = *(val);
  252. if (factor_toset <= 3) {
  253. factor_toset = (1 << (factor_toset + 2));
  254. if (factor_toset > 0xf)
  255. factor_toset = 0xf;
  256. for (index = 0; index < 4; index++) {
  257. if ((p_regtoset[index] & 0xf0) >
  258. (factor_toset << 4))
  259. p_regtoset[index] =
  260. (p_regtoset[index] & 0x0f) |
  261. (factor_toset << 4);
  262. if ((p_regtoset[index] & 0x0f) >
  263. factor_toset)
  264. p_regtoset[index] =
  265. (p_regtoset[index] & 0xf0) |
  266. (factor_toset);
  267. rtl_write_byte(rtlpriv,
  268. (REG_AGGLEN_LMT + index),
  269. p_regtoset[index]);
  270. }
  271. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  272. "Set HW_VAR_AMPDU_FACTOR: %#x\n",
  273. factor_toset);
  274. }
  275. break;
  276. }
  277. case HW_VAR_AC_PARAM:{
  278. u8 e_aci = *(val);
  279. rtl92c_dm_init_edca_turbo(hw);
  280. if (rtlpci->acm_method != EACMWAY2_SW)
  281. rtlpriv->cfg->ops->set_hw_reg(hw,
  282. HW_VAR_ACM_CTRL,
  283. (&e_aci));
  284. break;
  285. }
  286. case HW_VAR_ACM_CTRL:{
  287. u8 e_aci = *(val);
  288. union aci_aifsn *p_aci_aifsn =
  289. (union aci_aifsn *)(&(mac->ac[0].aifs));
  290. u8 acm = p_aci_aifsn->f.acm;
  291. u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
  292. acm_ctrl =
  293. acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
  294. if (acm) {
  295. switch (e_aci) {
  296. case AC0_BE:
  297. acm_ctrl |= AcmHw_BeqEn;
  298. break;
  299. case AC2_VI:
  300. acm_ctrl |= AcmHw_ViqEn;
  301. break;
  302. case AC3_VO:
  303. acm_ctrl |= AcmHw_VoqEn;
  304. break;
  305. default:
  306. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  307. "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
  308. acm);
  309. break;
  310. }
  311. } else {
  312. switch (e_aci) {
  313. case AC0_BE:
  314. acm_ctrl &= (~AcmHw_BeqEn);
  315. break;
  316. case AC2_VI:
  317. acm_ctrl &= (~AcmHw_ViqEn);
  318. break;
  319. case AC3_VO:
  320. acm_ctrl &= (~AcmHw_VoqEn);
  321. break;
  322. default:
  323. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  324. "switch case not processed\n");
  325. break;
  326. }
  327. }
  328. RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
  329. "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
  330. acm_ctrl);
  331. rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
  332. break;
  333. }
  334. case HW_VAR_RCR:{
  335. rtl_write_dword(rtlpriv, REG_RCR, ((u32 *) (val))[0]);
  336. rtlpci->receive_config = ((u32 *) (val))[0];
  337. break;
  338. }
  339. case HW_VAR_RETRY_LIMIT:{
  340. u8 retry_limit = val[0];
  341. rtl_write_word(rtlpriv, REG_RL,
  342. retry_limit << RETRY_LIMIT_SHORT_SHIFT |
  343. retry_limit << RETRY_LIMIT_LONG_SHIFT);
  344. break;
  345. }
  346. case HW_VAR_DUAL_TSF_RST:
  347. rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
  348. break;
  349. case HW_VAR_EFUSE_BYTES:
  350. rtlefuse->efuse_usedbytes = *((u16 *) val);
  351. break;
  352. case HW_VAR_EFUSE_USAGE:
  353. rtlefuse->efuse_usedpercentage = *val;
  354. break;
  355. case HW_VAR_IO_CMD:
  356. rtl92c_phy_set_io_cmd(hw, (*(enum io_type *)val));
  357. break;
  358. case HW_VAR_WPA_CONFIG:
  359. rtl_write_byte(rtlpriv, REG_SECCFG, *val);
  360. break;
  361. case HW_VAR_SET_RPWM:{
  362. u8 rpwm_val;
  363. rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
  364. udelay(1);
  365. if (rpwm_val & BIT(7)) {
  366. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val);
  367. } else {
  368. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
  369. *val | BIT(7));
  370. }
  371. break;
  372. }
  373. case HW_VAR_H2C_FW_PWRMODE:{
  374. u8 psmode = *val;
  375. if ((psmode != FW_PS_ACTIVE_MODE) &&
  376. (!IS_92C_SERIAL(rtlhal->version))) {
  377. rtl92c_dm_rf_saving(hw, true);
  378. }
  379. rtl92c_set_fw_pwrmode_cmd(hw, *val);
  380. break;
  381. }
  382. case HW_VAR_FW_PSMODE_STATUS:
  383. ppsc->fw_current_inpsmode = *((bool *) val);
  384. break;
  385. case HW_VAR_H2C_FW_JOINBSSRPT:{
  386. u8 mstatus = *val;
  387. u8 tmp_regcr, tmp_reg422;
  388. bool recover = false;
  389. if (mstatus == RT_MEDIA_CONNECT) {
  390. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
  391. NULL);
  392. tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
  393. rtl_write_byte(rtlpriv, REG_CR + 1,
  394. (tmp_regcr | BIT(0)));
  395. _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
  396. _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
  397. tmp_reg422 =
  398. rtl_read_byte(rtlpriv,
  399. REG_FWHW_TXQ_CTRL + 2);
  400. if (tmp_reg422 & BIT(6))
  401. recover = true;
  402. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
  403. tmp_reg422 & (~BIT(6)));
  404. rtl92c_set_fw_rsvdpagepkt(hw, NULL);
  405. _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
  406. _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
  407. if (recover) {
  408. rtl_write_byte(rtlpriv,
  409. REG_FWHW_TXQ_CTRL + 2,
  410. tmp_reg422);
  411. }
  412. rtl_write_byte(rtlpriv, REG_CR + 1,
  413. (tmp_regcr & ~(BIT(0))));
  414. }
  415. rtl92c_set_fw_joinbss_report_cmd(hw, *val);
  416. break;
  417. }
  418. case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
  419. rtl92c_set_p2p_ps_offload_cmd(hw, *val);
  420. break;
  421. case HW_VAR_AID:{
  422. u16 u2btmp;
  423. u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
  424. u2btmp &= 0xC000;
  425. rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
  426. mac->assoc_id));
  427. break;
  428. }
  429. case HW_VAR_CORRECT_TSF:{
  430. u8 btype_ibss = val[0];
  431. if (btype_ibss)
  432. _rtl92ce_stop_tx_beacon(hw);
  433. _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
  434. rtl_write_dword(rtlpriv, REG_TSFTR,
  435. (u32) (mac->tsf & 0xffffffff));
  436. rtl_write_dword(rtlpriv, REG_TSFTR + 4,
  437. (u32) ((mac->tsf >> 32) & 0xffffffff));
  438. _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
  439. if (btype_ibss)
  440. _rtl92ce_resume_tx_beacon(hw);
  441. break;
  442. }
  443. case HW_VAR_FW_LPS_ACTION: {
  444. bool enter_fwlps = *((bool *)val);
  445. u8 rpwm_val, fw_pwrmode;
  446. bool fw_current_inps;
  447. if (enter_fwlps) {
  448. rpwm_val = 0x02; /* RF off */
  449. fw_current_inps = true;
  450. rtlpriv->cfg->ops->set_hw_reg(hw,
  451. HW_VAR_FW_PSMODE_STATUS,
  452. (u8 *)(&fw_current_inps));
  453. rtlpriv->cfg->ops->set_hw_reg(hw,
  454. HW_VAR_H2C_FW_PWRMODE,
  455. &ppsc->fwctrl_psmode);
  456. rtlpriv->cfg->ops->set_hw_reg(hw,
  457. HW_VAR_SET_RPWM,
  458. &rpwm_val);
  459. } else {
  460. rpwm_val = 0x0C; /* RF on */
  461. fw_pwrmode = FW_PS_ACTIVE_MODE;
  462. fw_current_inps = false;
  463. rtlpriv->cfg->ops->set_hw_reg(hw,
  464. HW_VAR_SET_RPWM,
  465. &rpwm_val);
  466. rtlpriv->cfg->ops->set_hw_reg(hw,
  467. HW_VAR_H2C_FW_PWRMODE,
  468. &fw_pwrmode);
  469. rtlpriv->cfg->ops->set_hw_reg(hw,
  470. HW_VAR_FW_PSMODE_STATUS,
  471. (u8 *)(&fw_current_inps));
  472. }
  473. break; }
  474. case HW_VAR_KEEP_ALIVE: {
  475. u8 array[2];
  476. array[0] = 0xff;
  477. array[1] = *((u8 *)val);
  478. rtl92c_fill_h2c_cmd(hw, H2C_92C_KEEP_ALIVE_CTRL, 2, array);
  479. break; }
  480. default:
  481. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  482. "switch case %d not processed\n", variable);
  483. break;
  484. }
  485. }
  486. static bool _rtl92ce_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
  487. {
  488. struct rtl_priv *rtlpriv = rtl_priv(hw);
  489. bool status = true;
  490. long count = 0;
  491. u32 value = _LLT_INIT_ADDR(address) |
  492. _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
  493. rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
  494. do {
  495. value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
  496. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
  497. break;
  498. if (count > POLLING_LLT_THRESHOLD) {
  499. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  500. "Failed to polling write LLT done at address %d!\n",
  501. address);
  502. status = false;
  503. break;
  504. }
  505. } while (++count);
  506. return status;
  507. }
  508. static bool _rtl92ce_llt_table_init(struct ieee80211_hw *hw)
  509. {
  510. struct rtl_priv *rtlpriv = rtl_priv(hw);
  511. unsigned short i;
  512. u8 txpktbuf_bndy;
  513. u8 maxPage;
  514. bool status;
  515. #if LLT_CONFIG == 1
  516. maxPage = 255;
  517. txpktbuf_bndy = 252;
  518. #elif LLT_CONFIG == 2
  519. maxPage = 127;
  520. txpktbuf_bndy = 124;
  521. #elif LLT_CONFIG == 3
  522. maxPage = 255;
  523. txpktbuf_bndy = 174;
  524. #elif LLT_CONFIG == 4
  525. maxPage = 255;
  526. txpktbuf_bndy = 246;
  527. #elif LLT_CONFIG == 5
  528. maxPage = 255;
  529. txpktbuf_bndy = 246;
  530. #endif
  531. #if LLT_CONFIG == 1
  532. rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x1c);
  533. rtl_write_dword(rtlpriv, REG_RQPN, 0x80a71c1c);
  534. #elif LLT_CONFIG == 2
  535. rtl_write_dword(rtlpriv, REG_RQPN, 0x845B1010);
  536. #elif LLT_CONFIG == 3
  537. rtl_write_dword(rtlpriv, REG_RQPN, 0x84838484);
  538. #elif LLT_CONFIG == 4
  539. rtl_write_dword(rtlpriv, REG_RQPN, 0x80bd1c1c);
  540. #elif LLT_CONFIG == 5
  541. rtl_write_word(rtlpriv, REG_RQPN_NPQ, 0x0000);
  542. rtl_write_dword(rtlpriv, REG_RQPN, 0x80b01c29);
  543. #endif
  544. rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x27FF0000 | txpktbuf_bndy));
  545. rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
  546. rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
  547. rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
  548. rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
  549. rtl_write_byte(rtlpriv, REG_PBP, 0x11);
  550. rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
  551. for (i = 0; i < (txpktbuf_bndy - 1); i++) {
  552. status = _rtl92ce_llt_write(hw, i, i + 1);
  553. if (true != status)
  554. return status;
  555. }
  556. status = _rtl92ce_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
  557. if (true != status)
  558. return status;
  559. for (i = txpktbuf_bndy; i < maxPage; i++) {
  560. status = _rtl92ce_llt_write(hw, i, (i + 1));
  561. if (true != status)
  562. return status;
  563. }
  564. status = _rtl92ce_llt_write(hw, maxPage, txpktbuf_bndy);
  565. if (true != status)
  566. return status;
  567. return true;
  568. }
  569. static void _rtl92ce_gen_refresh_led_state(struct ieee80211_hw *hw)
  570. {
  571. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  572. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  573. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  574. struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
  575. if (rtlpci->up_first_time)
  576. return;
  577. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
  578. rtl92ce_sw_led_on(hw, pLed0);
  579. else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
  580. rtl92ce_sw_led_on(hw, pLed0);
  581. else
  582. rtl92ce_sw_led_off(hw, pLed0);
  583. }
  584. static bool _rtl92ce_init_mac(struct ieee80211_hw *hw)
  585. {
  586. struct rtl_priv *rtlpriv = rtl_priv(hw);
  587. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  588. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  589. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  590. unsigned char bytetmp;
  591. unsigned short wordtmp;
  592. u16 retry;
  593. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
  594. if (rtlpcipriv->bt_coexist.bt_coexistence) {
  595. u32 value32;
  596. value32 = rtl_read_dword(rtlpriv, REG_APS_FSMCO);
  597. value32 |= (SOP_ABG | SOP_AMB | XOP_BTCK);
  598. rtl_write_dword(rtlpriv, REG_APS_FSMCO, value32);
  599. }
  600. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
  601. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0F);
  602. if (rtlpcipriv->bt_coexist.bt_coexistence) {
  603. u32 u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
  604. u4b_tmp &= (~0x00024800);
  605. rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
  606. }
  607. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) | BIT(0);
  608. udelay(2);
  609. rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
  610. udelay(2);
  611. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
  612. udelay(2);
  613. retry = 0;
  614. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "reg0xec:%x:%x\n",
  615. rtl_read_dword(rtlpriv, 0xEC), bytetmp);
  616. while ((bytetmp & BIT(0)) && retry < 1000) {
  617. retry++;
  618. udelay(50);
  619. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
  620. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "reg0xec:%x:%x\n",
  621. rtl_read_dword(rtlpriv, 0xEC), bytetmp);
  622. udelay(50);
  623. }
  624. rtl_write_word(rtlpriv, REG_APS_FSMCO, 0x1012);
  625. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x82);
  626. udelay(2);
  627. if (rtlpcipriv->bt_coexist.bt_coexistence) {
  628. bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL+2) & 0xfd;
  629. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL+2, bytetmp);
  630. }
  631. rtl_write_word(rtlpriv, REG_CR, 0x2ff);
  632. if (!_rtl92ce_llt_table_init(hw))
  633. return false;
  634. rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
  635. rtl_write_byte(rtlpriv, REG_HISRE, 0xff);
  636. rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x27ff);
  637. wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
  638. wordtmp &= 0xf;
  639. wordtmp |= 0xF771;
  640. rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
  641. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
  642. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  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. if (IS_92C_SERIAL(rtlhal->version))
  666. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x77);
  667. else
  668. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x22);
  669. rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
  670. bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
  671. rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6));
  672. do {
  673. retry++;
  674. bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
  675. } while ((retry < 200) && (bytetmp & BIT(7)));
  676. _rtl92ce_gen_refresh_led_state(hw);
  677. rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
  678. return true;
  679. }
  680. static void _rtl92ce_hw_configure(struct ieee80211_hw *hw)
  681. {
  682. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  683. struct rtl_priv *rtlpriv = rtl_priv(hw);
  684. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  685. u8 reg_bw_opmode;
  686. u32 reg_prsr;
  687. reg_bw_opmode = BW_OPMODE_20MHZ;
  688. reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  689. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8);
  690. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  691. rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
  692. rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
  693. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0);
  694. rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
  695. rtl_write_word(rtlpriv, REG_RL, 0x0707);
  696. rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802);
  697. rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
  698. rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
  699. rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
  700. rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
  701. rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
  702. if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
  703. (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
  704. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431);
  705. else
  706. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
  707. rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
  708. rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
  709. rtlpci->reg_bcn_ctrl_val = 0x1f;
  710. rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
  711. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  712. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  713. rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
  714. rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
  715. if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
  716. (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4)) {
  717. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
  718. rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402);
  719. } else {
  720. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
  721. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
  722. }
  723. if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
  724. (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
  725. rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
  726. else
  727. rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666);
  728. rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
  729. rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010);
  730. rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010);
  731. rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010);
  732. rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010);
  733. rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
  734. rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
  735. }
  736. static void _rtl92ce_enable_aspm_back_door(struct ieee80211_hw *hw)
  737. {
  738. struct rtl_priv *rtlpriv = rtl_priv(hw);
  739. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  740. rtl_write_byte(rtlpriv, 0x34b, 0x93);
  741. rtl_write_word(rtlpriv, 0x350, 0x870c);
  742. rtl_write_byte(rtlpriv, 0x352, 0x1);
  743. if (ppsc->support_backdoor)
  744. rtl_write_byte(rtlpriv, 0x349, 0x1b);
  745. else
  746. rtl_write_byte(rtlpriv, 0x349, 0x03);
  747. rtl_write_word(rtlpriv, 0x350, 0x2718);
  748. rtl_write_byte(rtlpriv, 0x352, 0x1);
  749. }
  750. void rtl92ce_enable_hw_security_config(struct ieee80211_hw *hw)
  751. {
  752. struct rtl_priv *rtlpriv = rtl_priv(hw);
  753. u8 sec_reg_value;
  754. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  755. "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
  756. rtlpriv->sec.pairwise_enc_algorithm,
  757. rtlpriv->sec.group_enc_algorithm);
  758. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  759. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  760. "not open hw encryption\n");
  761. return;
  762. }
  763. sec_reg_value = SCR_TxEncEnable | SCR_RxDecEnable;
  764. if (rtlpriv->sec.use_defaultkey) {
  765. sec_reg_value |= SCR_TxUseDK;
  766. sec_reg_value |= SCR_RxUseDK;
  767. }
  768. sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
  769. rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
  770. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  771. "The SECR-value %x\n", sec_reg_value);
  772. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
  773. }
  774. int rtl92ce_hw_init(struct ieee80211_hw *hw)
  775. {
  776. struct rtl_priv *rtlpriv = rtl_priv(hw);
  777. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  778. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  779. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  780. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  781. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  782. bool rtstatus = true;
  783. bool is92c;
  784. int err;
  785. u8 tmp_u1b;
  786. unsigned long flags;
  787. rtlpci->being_init_adapter = true;
  788. /* Since this function can take a very long time (up to 350 ms)
  789. * and can be called with irqs disabled, reenable the irqs
  790. * to let the other devices continue being serviced.
  791. *
  792. * It is safe doing so since our own interrupts will only be enabled
  793. * in a subsequent step.
  794. */
  795. local_save_flags(flags);
  796. local_irq_enable();
  797. rtlhal->fw_ready = false;
  798. rtlpriv->intf_ops->disable_aspm(hw);
  799. rtstatus = _rtl92ce_init_mac(hw);
  800. if (!rtstatus) {
  801. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n");
  802. err = 1;
  803. goto exit;
  804. }
  805. err = rtl92c_download_fw(hw);
  806. if (err) {
  807. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  808. "Failed to download FW. Init HW without FW now..\n");
  809. err = 1;
  810. goto exit;
  811. }
  812. rtlhal->fw_ready = true;
  813. rtlhal->last_hmeboxnum = 0;
  814. rtl92c_phy_mac_config(hw);
  815. /* because last function modify RCR, so we update
  816. * rcr var here, or TP will unstable for receive_config
  817. * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
  818. * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252*/
  819. rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
  820. rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
  821. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  822. rtl92c_phy_bb_config(hw);
  823. rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
  824. rtl92c_phy_rf_config(hw);
  825. if (IS_VENDOR_UMC_A_CUT(rtlhal->version) &&
  826. !IS_92C_SERIAL(rtlhal->version)) {
  827. rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD, 0x30255);
  828. rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G2, MASKDWORD, 0x50a00);
  829. } else if (IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version)) {
  830. rtl_set_rfreg(hw, RF90_PATH_A, 0x0C, MASKDWORD, 0x894AE);
  831. rtl_set_rfreg(hw, RF90_PATH_A, 0x0A, MASKDWORD, 0x1AF31);
  832. rtl_set_rfreg(hw, RF90_PATH_A, RF_IPA, MASKDWORD, 0x8F425);
  833. rtl_set_rfreg(hw, RF90_PATH_A, RF_SYN_G2, MASKDWORD, 0x4F200);
  834. rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK1, MASKDWORD, 0x44053);
  835. rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK2, MASKDWORD, 0x80201);
  836. }
  837. rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
  838. RF_CHNLBW, RFREG_OFFSET_MASK);
  839. rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1,
  840. RF_CHNLBW, RFREG_OFFSET_MASK);
  841. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  842. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  843. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
  844. _rtl92ce_hw_configure(hw);
  845. rtl_cam_reset_all_entry(hw);
  846. rtl92ce_enable_hw_security_config(hw);
  847. ppsc->rfpwr_state = ERFON;
  848. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  849. _rtl92ce_enable_aspm_back_door(hw);
  850. rtlpriv->intf_ops->enable_aspm(hw);
  851. rtl8192ce_bt_hw_init(hw);
  852. if (ppsc->rfpwr_state == ERFON) {
  853. rtl92c_phy_set_rfpath_switch(hw, 1);
  854. if (rtlphy->iqk_initialized) {
  855. rtl92c_phy_iq_calibrate(hw, true);
  856. } else {
  857. rtl92c_phy_iq_calibrate(hw, false);
  858. rtlphy->iqk_initialized = true;
  859. }
  860. rtl92c_dm_check_txpower_tracking(hw);
  861. rtl92c_phy_lc_calibrate(hw);
  862. }
  863. is92c = IS_92C_SERIAL(rtlhal->version);
  864. tmp_u1b = efuse_read_1byte(hw, 0x1FA);
  865. if (!(tmp_u1b & BIT(0))) {
  866. rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
  867. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path A\n");
  868. }
  869. if (!(tmp_u1b & BIT(1)) && is92c) {
  870. rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0F, 0x05);
  871. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path B\n");
  872. }
  873. if (!(tmp_u1b & BIT(4))) {
  874. tmp_u1b = rtl_read_byte(rtlpriv, 0x16);
  875. tmp_u1b &= 0x0F;
  876. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
  877. udelay(10);
  878. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
  879. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n");
  880. }
  881. rtl92c_dm_init(hw);
  882. exit:
  883. local_irq_restore(flags);
  884. rtlpci->being_init_adapter = false;
  885. return err;
  886. }
  887. static enum version_8192c _rtl92ce_read_chip_version(struct ieee80211_hw *hw)
  888. {
  889. struct rtl_priv *rtlpriv = rtl_priv(hw);
  890. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  891. enum version_8192c version = VERSION_UNKNOWN;
  892. u32 value32;
  893. const char *versionid;
  894. value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
  895. if (value32 & TRP_VAUX_EN) {
  896. version = (value32 & TYPE_ID) ? VERSION_A_CHIP_92C :
  897. VERSION_A_CHIP_88C;
  898. } else {
  899. version = (enum version_8192c) (CHIP_VER_B |
  900. ((value32 & TYPE_ID) ? CHIP_92C_BITMASK : 0) |
  901. ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
  902. if ((!IS_CHIP_VENDOR_UMC(version)) && (value32 &
  903. CHIP_VER_RTL_MASK)) {
  904. version = (enum version_8192c)(version |
  905. ((((value32 & CHIP_VER_RTL_MASK) == BIT(12))
  906. ? CHIP_VENDOR_UMC_B_CUT : CHIP_UNKNOWN) |
  907. CHIP_VENDOR_UMC));
  908. }
  909. if (IS_92C_SERIAL(version)) {
  910. value32 = rtl_read_dword(rtlpriv, REG_HPON_FSM);
  911. version = (enum version_8192c)(version |
  912. ((CHIP_BONDING_IDENTIFIER(value32)
  913. == CHIP_BONDING_92C_1T2R) ?
  914. RF_TYPE_1T2R : 0));
  915. }
  916. }
  917. switch (version) {
  918. case VERSION_B_CHIP_92C:
  919. versionid = "B_CHIP_92C";
  920. break;
  921. case VERSION_B_CHIP_88C:
  922. versionid = "B_CHIP_88C";
  923. break;
  924. case VERSION_A_CHIP_92C:
  925. versionid = "A_CHIP_92C";
  926. break;
  927. case VERSION_A_CHIP_88C:
  928. versionid = "A_CHIP_88C";
  929. break;
  930. case VERSION_NORMAL_UMC_CHIP_92C_1T2R_A_CUT:
  931. versionid = "A_CUT_92C_1T2R";
  932. break;
  933. case VERSION_NORMAL_UMC_CHIP_92C_A_CUT:
  934. versionid = "A_CUT_92C";
  935. break;
  936. case VERSION_NORMAL_UMC_CHIP_88C_A_CUT:
  937. versionid = "A_CUT_88C";
  938. break;
  939. case VERSION_NORMAL_UMC_CHIP_92C_1T2R_B_CUT:
  940. versionid = "B_CUT_92C_1T2R";
  941. break;
  942. case VERSION_NORMAL_UMC_CHIP_92C_B_CUT:
  943. versionid = "B_CUT_92C";
  944. break;
  945. case VERSION_NORMAL_UMC_CHIP_88C_B_CUT:
  946. versionid = "B_CUT_88C";
  947. break;
  948. default:
  949. versionid = "Unknown. Bug?";
  950. break;
  951. }
  952. RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG,
  953. "Chip Version ID: %s\n", versionid);
  954. switch (version & 0x3) {
  955. case CHIP_88C:
  956. rtlphy->rf_type = RF_1T1R;
  957. break;
  958. case CHIP_92C:
  959. rtlphy->rf_type = RF_2T2R;
  960. break;
  961. case CHIP_92C_1T2R:
  962. rtlphy->rf_type = RF_1T2R;
  963. break;
  964. default:
  965. rtlphy->rf_type = RF_1T1R;
  966. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  967. "ERROR RF_Type is set!!\n");
  968. break;
  969. }
  970. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Chip RF Type: %s\n",
  971. rtlphy->rf_type == RF_2T2R ? "RF_2T2R" : "RF_1T1R");
  972. return version;
  973. }
  974. static int _rtl92ce_set_media_status(struct ieee80211_hw *hw,
  975. enum nl80211_iftype type)
  976. {
  977. struct rtl_priv *rtlpriv = rtl_priv(hw);
  978. u8 bt_msr = rtl_read_byte(rtlpriv, MSR);
  979. enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
  980. u8 mode = MSR_NOLINK;
  981. bt_msr &= 0xfc;
  982. switch (type) {
  983. case NL80211_IFTYPE_UNSPECIFIED:
  984. mode = MSR_NOLINK;
  985. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  986. "Set Network type to NO LINK!\n");
  987. break;
  988. case NL80211_IFTYPE_ADHOC:
  989. mode = MSR_ADHOC;
  990. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  991. "Set Network type to Ad Hoc!\n");
  992. break;
  993. case NL80211_IFTYPE_STATION:
  994. mode = MSR_INFRA;
  995. ledaction = LED_CTL_LINK;
  996. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  997. "Set Network type to STA!\n");
  998. break;
  999. case NL80211_IFTYPE_AP:
  1000. mode = MSR_AP;
  1001. ledaction = LED_CTL_LINK;
  1002. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1003. "Set Network type to AP!\n");
  1004. break;
  1005. case NL80211_IFTYPE_MESH_POINT:
  1006. mode = MSR_ADHOC;
  1007. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1008. "Set Network type to Mesh Point!\n");
  1009. break;
  1010. default:
  1011. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1012. "Network type %d not supported!\n", type);
  1013. return 1;
  1014. }
  1015. /* MSR_INFRA == Link in infrastructure network;
  1016. * MSR_ADHOC == Link in ad hoc network;
  1017. * Therefore, check link state is necessary.
  1018. *
  1019. * MSR_AP == AP mode; link state does not matter here.
  1020. */
  1021. if (mode != MSR_AP &&
  1022. rtlpriv->mac80211.link_state < MAC80211_LINKED) {
  1023. mode = MSR_NOLINK;
  1024. ledaction = LED_CTL_NO_LINK;
  1025. }
  1026. if (mode == MSR_NOLINK || mode == MSR_INFRA) {
  1027. _rtl92ce_stop_tx_beacon(hw);
  1028. _rtl92ce_enable_bcn_sub_func(hw);
  1029. } else if (mode == MSR_ADHOC || mode == MSR_AP) {
  1030. _rtl92ce_resume_tx_beacon(hw);
  1031. _rtl92ce_disable_bcn_sub_func(hw);
  1032. } else {
  1033. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1034. "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
  1035. mode);
  1036. }
  1037. rtl_write_byte(rtlpriv, MSR, bt_msr | mode);
  1038. rtlpriv->cfg->ops->led_control(hw, ledaction);
  1039. if (mode == MSR_AP)
  1040. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
  1041. else
  1042. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
  1043. return 0;
  1044. }
  1045. void rtl92ce_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
  1046. {
  1047. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1048. u32 reg_rcr;
  1049. if (rtlpriv->psc.rfpwr_state != ERFON)
  1050. return;
  1051. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
  1052. if (check_bssid) {
  1053. reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
  1054. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
  1055. (u8 *) (&reg_rcr));
  1056. _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
  1057. } else if (!check_bssid) {
  1058. reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
  1059. _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
  1060. rtlpriv->cfg->ops->set_hw_reg(hw,
  1061. HW_VAR_RCR, (u8 *) (&reg_rcr));
  1062. }
  1063. }
  1064. int rtl92ce_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
  1065. {
  1066. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1067. if (_rtl92ce_set_media_status(hw, type))
  1068. return -EOPNOTSUPP;
  1069. if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
  1070. if (type != NL80211_IFTYPE_AP &&
  1071. type != NL80211_IFTYPE_MESH_POINT)
  1072. rtl92ce_set_check_bssid(hw, true);
  1073. } else {
  1074. rtl92ce_set_check_bssid(hw, false);
  1075. }
  1076. return 0;
  1077. }
  1078. /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
  1079. void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci)
  1080. {
  1081. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1082. rtl92c_dm_init_edca_turbo(hw);
  1083. switch (aci) {
  1084. case AC1_BK:
  1085. rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
  1086. break;
  1087. case AC0_BE:
  1088. /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
  1089. break;
  1090. case AC2_VI:
  1091. rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
  1092. break;
  1093. case AC3_VO:
  1094. rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
  1095. break;
  1096. default:
  1097. RT_ASSERT(false, "invalid aci: %d !\n", aci);
  1098. break;
  1099. }
  1100. }
  1101. void rtl92ce_enable_interrupt(struct ieee80211_hw *hw)
  1102. {
  1103. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1104. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1105. rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF);
  1106. rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF);
  1107. rtlpci->irq_enabled = true;
  1108. }
  1109. void rtl92ce_disable_interrupt(struct ieee80211_hw *hw)
  1110. {
  1111. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1112. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1113. rtl_write_dword(rtlpriv, REG_HIMR, IMR8190_DISABLED);
  1114. rtl_write_dword(rtlpriv, REG_HIMRE, IMR8190_DISABLED);
  1115. rtlpci->irq_enabled = false;
  1116. }
  1117. static void _rtl92ce_poweroff_adapter(struct ieee80211_hw *hw)
  1118. {
  1119. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1120. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  1121. struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
  1122. u8 u1b_tmp;
  1123. u32 u4b_tmp;
  1124. rtlpriv->intf_ops->enable_aspm(hw);
  1125. rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
  1126. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
  1127. rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
  1128. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  1129. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  1130. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE0);
  1131. if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7))
  1132. rtl92c_firmware_selfreset(hw);
  1133. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, 0x51);
  1134. rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
  1135. rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00000000);
  1136. u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL);
  1137. if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
  1138. ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
  1139. (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8))) {
  1140. rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00F30000 |
  1141. (u1b_tmp << 8));
  1142. } else {
  1143. rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00FF0000 |
  1144. (u1b_tmp << 8));
  1145. }
  1146. rtl_write_word(rtlpriv, REG_GPIO_IO_SEL, 0x0790);
  1147. rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080);
  1148. rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80);
  1149. if (!IS_81XXC_VENDOR_UMC_B_CUT(rtlhal->version))
  1150. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23);
  1151. if (rtlpcipriv->bt_coexist.bt_coexistence) {
  1152. u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
  1153. u4b_tmp |= 0x03824800;
  1154. rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
  1155. } else {
  1156. rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, 0x0e);
  1157. }
  1158. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
  1159. rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x10);
  1160. }
  1161. void rtl92ce_card_disable(struct ieee80211_hw *hw)
  1162. {
  1163. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1164. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1165. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1166. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1167. enum nl80211_iftype opmode;
  1168. mac->link_state = MAC80211_NOLINK;
  1169. opmode = NL80211_IFTYPE_UNSPECIFIED;
  1170. _rtl92ce_set_media_status(hw, opmode);
  1171. if (rtlpci->driver_is_goingto_unload ||
  1172. ppsc->rfoff_reason > RF_CHANGE_BY_PS)
  1173. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1174. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1175. _rtl92ce_poweroff_adapter(hw);
  1176. /* after power off we should do iqk again */
  1177. rtlpriv->phy.iqk_initialized = false;
  1178. }
  1179. void rtl92ce_interrupt_recognized(struct ieee80211_hw *hw,
  1180. u32 *p_inta, u32 *p_intb)
  1181. {
  1182. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1183. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1184. *p_inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
  1185. rtl_write_dword(rtlpriv, ISR, *p_inta);
  1186. /*
  1187. * *p_intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1];
  1188. * rtl_write_dword(rtlpriv, ISR + 4, *p_intb);
  1189. */
  1190. }
  1191. void rtl92ce_set_beacon_related_registers(struct ieee80211_hw *hw)
  1192. {
  1193. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1194. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1195. u16 bcn_interval, atim_window;
  1196. bcn_interval = mac->beacon_interval;
  1197. atim_window = 2; /*FIX MERGE */
  1198. rtl92ce_disable_interrupt(hw);
  1199. rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
  1200. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1201. rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
  1202. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
  1203. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
  1204. rtl_write_byte(rtlpriv, 0x606, 0x30);
  1205. rtl92ce_enable_interrupt(hw);
  1206. }
  1207. void rtl92ce_set_beacon_interval(struct ieee80211_hw *hw)
  1208. {
  1209. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1210. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1211. u16 bcn_interval = mac->beacon_interval;
  1212. RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
  1213. "beacon_interval:%d\n", bcn_interval);
  1214. rtl92ce_disable_interrupt(hw);
  1215. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1216. rtl92ce_enable_interrupt(hw);
  1217. }
  1218. void rtl92ce_update_interrupt_mask(struct ieee80211_hw *hw,
  1219. u32 add_msr, u32 rm_msr)
  1220. {
  1221. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1222. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1223. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, "add_msr:%x, rm_msr:%x\n",
  1224. add_msr, rm_msr);
  1225. if (add_msr)
  1226. rtlpci->irq_mask[0] |= add_msr;
  1227. if (rm_msr)
  1228. rtlpci->irq_mask[0] &= (~rm_msr);
  1229. rtl92ce_disable_interrupt(hw);
  1230. rtl92ce_enable_interrupt(hw);
  1231. }
  1232. static void _rtl92ce_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
  1233. bool autoload_fail,
  1234. u8 *hwinfo)
  1235. {
  1236. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1237. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1238. u8 rf_path, index, tempval;
  1239. u16 i;
  1240. for (rf_path = 0; rf_path < 2; rf_path++) {
  1241. for (i = 0; i < 3; i++) {
  1242. if (!autoload_fail) {
  1243. rtlefuse->
  1244. eeprom_chnlarea_txpwr_cck[rf_path][i] =
  1245. hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i];
  1246. rtlefuse->
  1247. eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
  1248. hwinfo[EEPROM_TXPOWERHT40_1S + rf_path * 3 +
  1249. i];
  1250. } else {
  1251. rtlefuse->
  1252. eeprom_chnlarea_txpwr_cck[rf_path][i] =
  1253. EEPROM_DEFAULT_TXPOWERLEVEL;
  1254. rtlefuse->
  1255. eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
  1256. EEPROM_DEFAULT_TXPOWERLEVEL;
  1257. }
  1258. }
  1259. }
  1260. for (i = 0; i < 3; i++) {
  1261. if (!autoload_fail)
  1262. tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i];
  1263. else
  1264. tempval = EEPROM_DEFAULT_HT40_2SDIFF;
  1265. rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_A][i] =
  1266. (tempval & 0xf);
  1267. rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_B][i] =
  1268. ((tempval & 0xf0) >> 4);
  1269. }
  1270. for (rf_path = 0; rf_path < 2; rf_path++)
  1271. for (i = 0; i < 3; i++)
  1272. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1273. "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
  1274. rf_path, i,
  1275. rtlefuse->
  1276. eeprom_chnlarea_txpwr_cck[rf_path][i]);
  1277. for (rf_path = 0; rf_path < 2; rf_path++)
  1278. for (i = 0; i < 3; i++)
  1279. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1280. "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
  1281. rf_path, i,
  1282. rtlefuse->
  1283. eeprom_chnlarea_txpwr_ht40_1s[rf_path][i]);
  1284. for (rf_path = 0; rf_path < 2; rf_path++)
  1285. for (i = 0; i < 3; i++)
  1286. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1287. "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
  1288. rf_path, i,
  1289. rtlefuse->
  1290. eprom_chnl_txpwr_ht40_2sdf[rf_path][i]);
  1291. for (rf_path = 0; rf_path < 2; rf_path++) {
  1292. for (i = 0; i < 14; i++) {
  1293. index = rtl92c_get_chnl_group((u8)i);
  1294. rtlefuse->txpwrlevel_cck[rf_path][i] =
  1295. rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][index];
  1296. rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
  1297. rtlefuse->
  1298. eeprom_chnlarea_txpwr_ht40_1s[rf_path][index];
  1299. if ((rtlefuse->
  1300. eeprom_chnlarea_txpwr_ht40_1s[rf_path][index] -
  1301. rtlefuse->
  1302. eprom_chnl_txpwr_ht40_2sdf[rf_path][index])
  1303. > 0) {
  1304. rtlefuse->txpwrlevel_ht40_2s[rf_path][i] =
  1305. rtlefuse->
  1306. eeprom_chnlarea_txpwr_ht40_1s[rf_path]
  1307. [index] -
  1308. rtlefuse->
  1309. eprom_chnl_txpwr_ht40_2sdf[rf_path]
  1310. [index];
  1311. } else {
  1312. rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0;
  1313. }
  1314. }
  1315. for (i = 0; i < 14; i++) {
  1316. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1317. "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
  1318. rf_path, i,
  1319. rtlefuse->txpwrlevel_cck[rf_path][i],
  1320. rtlefuse->txpwrlevel_ht40_1s[rf_path][i],
  1321. rtlefuse->txpwrlevel_ht40_2s[rf_path][i]);
  1322. }
  1323. }
  1324. for (i = 0; i < 3; i++) {
  1325. if (!autoload_fail) {
  1326. rtlefuse->eeprom_pwrlimit_ht40[i] =
  1327. hwinfo[EEPROM_TXPWR_GROUP + i];
  1328. rtlefuse->eeprom_pwrlimit_ht20[i] =
  1329. hwinfo[EEPROM_TXPWR_GROUP + 3 + i];
  1330. } else {
  1331. rtlefuse->eeprom_pwrlimit_ht40[i] = 0;
  1332. rtlefuse->eeprom_pwrlimit_ht20[i] = 0;
  1333. }
  1334. }
  1335. for (rf_path = 0; rf_path < 2; rf_path++) {
  1336. for (i = 0; i < 14; i++) {
  1337. index = rtl92c_get_chnl_group((u8)i);
  1338. if (rf_path == RF90_PATH_A) {
  1339. rtlefuse->pwrgroup_ht20[rf_path][i] =
  1340. (rtlefuse->eeprom_pwrlimit_ht20[index]
  1341. & 0xf);
  1342. rtlefuse->pwrgroup_ht40[rf_path][i] =
  1343. (rtlefuse->eeprom_pwrlimit_ht40[index]
  1344. & 0xf);
  1345. } else if (rf_path == RF90_PATH_B) {
  1346. rtlefuse->pwrgroup_ht20[rf_path][i] =
  1347. ((rtlefuse->eeprom_pwrlimit_ht20[index]
  1348. & 0xf0) >> 4);
  1349. rtlefuse->pwrgroup_ht40[rf_path][i] =
  1350. ((rtlefuse->eeprom_pwrlimit_ht40[index]
  1351. & 0xf0) >> 4);
  1352. }
  1353. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1354. "RF-%d pwrgroup_ht20[%d] = 0x%x\n",
  1355. rf_path, i,
  1356. rtlefuse->pwrgroup_ht20[rf_path][i]);
  1357. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1358. "RF-%d pwrgroup_ht40[%d] = 0x%x\n",
  1359. rf_path, i,
  1360. rtlefuse->pwrgroup_ht40[rf_path][i]);
  1361. }
  1362. }
  1363. for (i = 0; i < 14; i++) {
  1364. index = rtl92c_get_chnl_group((u8)i);
  1365. if (!autoload_fail)
  1366. tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index];
  1367. else
  1368. tempval = EEPROM_DEFAULT_HT20_DIFF;
  1369. rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF);
  1370. rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] =
  1371. ((tempval >> 4) & 0xF);
  1372. if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3))
  1373. rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0;
  1374. if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3))
  1375. rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0;
  1376. index = rtl92c_get_chnl_group((u8)i);
  1377. if (!autoload_fail)
  1378. tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index];
  1379. else
  1380. tempval = EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF;
  1381. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF);
  1382. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] =
  1383. ((tempval >> 4) & 0xF);
  1384. }
  1385. rtlefuse->legacy_ht_txpowerdiff =
  1386. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7];
  1387. for (i = 0; i < 14; i++)
  1388. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1389. "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
  1390. i, rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]);
  1391. for (i = 0; i < 14; i++)
  1392. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1393. "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
  1394. i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]);
  1395. for (i = 0; i < 14; i++)
  1396. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1397. "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
  1398. i, rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]);
  1399. for (i = 0; i < 14; i++)
  1400. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1401. "RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
  1402. i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]);
  1403. if (!autoload_fail)
  1404. rtlefuse->eeprom_regulatory = (hwinfo[RF_OPTION1] & 0x7);
  1405. else
  1406. rtlefuse->eeprom_regulatory = 0;
  1407. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1408. "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
  1409. if (!autoload_fail) {
  1410. rtlefuse->eeprom_tssi[RF90_PATH_A] = hwinfo[EEPROM_TSSI_A];
  1411. rtlefuse->eeprom_tssi[RF90_PATH_B] = hwinfo[EEPROM_TSSI_B];
  1412. } else {
  1413. rtlefuse->eeprom_tssi[RF90_PATH_A] = EEPROM_DEFAULT_TSSI;
  1414. rtlefuse->eeprom_tssi[RF90_PATH_B] = EEPROM_DEFAULT_TSSI;
  1415. }
  1416. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
  1417. rtlefuse->eeprom_tssi[RF90_PATH_A],
  1418. rtlefuse->eeprom_tssi[RF90_PATH_B]);
  1419. if (!autoload_fail)
  1420. tempval = hwinfo[EEPROM_THERMAL_METER];
  1421. else
  1422. tempval = EEPROM_DEFAULT_THERMALMETER;
  1423. rtlefuse->eeprom_thermalmeter = (tempval & 0x1f);
  1424. if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail)
  1425. rtlefuse->apk_thermalmeterignore = true;
  1426. rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
  1427. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1428. "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
  1429. }
  1430. static void _rtl92ce_read_adapter_info(struct ieee80211_hw *hw)
  1431. {
  1432. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1433. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1434. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1435. u16 i, usvalue;
  1436. u8 hwinfo[HWSET_MAX_SIZE];
  1437. u16 eeprom_id;
  1438. if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
  1439. rtl_efuse_shadow_map_update(hw);
  1440. memcpy((void *)hwinfo,
  1441. (void *)&rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
  1442. HWSET_MAX_SIZE);
  1443. } else if (rtlefuse->epromtype == EEPROM_93C46) {
  1444. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1445. "RTL819X Not boot from eeprom, check it !!");
  1446. }
  1447. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP",
  1448. hwinfo, HWSET_MAX_SIZE);
  1449. eeprom_id = *((u16 *)&hwinfo[0]);
  1450. if (eeprom_id != RTL8190_EEPROM_ID) {
  1451. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1452. "EEPROM ID(%#x) is invalid!!\n", eeprom_id);
  1453. rtlefuse->autoload_failflag = true;
  1454. } else {
  1455. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1456. rtlefuse->autoload_failflag = false;
  1457. }
  1458. if (rtlefuse->autoload_failflag)
  1459. return;
  1460. rtlefuse->eeprom_vid = *(u16 *)&hwinfo[EEPROM_VID];
  1461. rtlefuse->eeprom_did = *(u16 *)&hwinfo[EEPROM_DID];
  1462. rtlefuse->eeprom_svid = *(u16 *)&hwinfo[EEPROM_SVID];
  1463. rtlefuse->eeprom_smid = *(u16 *)&hwinfo[EEPROM_SMID];
  1464. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1465. "EEPROMId = 0x%4x\n", eeprom_id);
  1466. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1467. "EEPROM VID = 0x%4x\n", rtlefuse->eeprom_vid);
  1468. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1469. "EEPROM DID = 0x%4x\n", rtlefuse->eeprom_did);
  1470. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1471. "EEPROM SVID = 0x%4x\n", rtlefuse->eeprom_svid);
  1472. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1473. "EEPROM SMID = 0x%4x\n", rtlefuse->eeprom_smid);
  1474. for (i = 0; i < 6; i += 2) {
  1475. usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
  1476. *((u16 *) (&rtlefuse->dev_addr[i])) = usvalue;
  1477. }
  1478. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "%pM\n", rtlefuse->dev_addr);
  1479. _rtl92ce_read_txpower_info_from_hwpg(hw,
  1480. rtlefuse->autoload_failflag,
  1481. hwinfo);
  1482. rtl8192ce_read_bt_coexist_info_from_hwpg(hw,
  1483. rtlefuse->autoload_failflag,
  1484. hwinfo);
  1485. rtlefuse->eeprom_channelplan = *&hwinfo[EEPROM_CHANNELPLAN];
  1486. rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
  1487. rtlefuse->txpwr_fromeprom = true;
  1488. rtlefuse->eeprom_oemid = *&hwinfo[EEPROM_CUSTOMER_ID];
  1489. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1490. "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid);
  1491. /* set channel paln to world wide 13 */
  1492. rtlefuse->channel_plan = COUNTRY_CODE_WORLD_WIDE_13;
  1493. if (rtlhal->oem_id == RT_CID_DEFAULT) {
  1494. switch (rtlefuse->eeprom_oemid) {
  1495. case EEPROM_CID_DEFAULT:
  1496. if (rtlefuse->eeprom_did == 0x8176) {
  1497. if ((rtlefuse->eeprom_svid == 0x103C &&
  1498. rtlefuse->eeprom_smid == 0x1629))
  1499. rtlhal->oem_id = RT_CID_819X_HP;
  1500. else
  1501. rtlhal->oem_id = RT_CID_DEFAULT;
  1502. } else {
  1503. rtlhal->oem_id = RT_CID_DEFAULT;
  1504. }
  1505. break;
  1506. case EEPROM_CID_TOSHIBA:
  1507. rtlhal->oem_id = RT_CID_TOSHIBA;
  1508. break;
  1509. case EEPROM_CID_QMI:
  1510. rtlhal->oem_id = RT_CID_819X_QMI;
  1511. break;
  1512. case EEPROM_CID_WHQL:
  1513. default:
  1514. rtlhal->oem_id = RT_CID_DEFAULT;
  1515. break;
  1516. }
  1517. }
  1518. }
  1519. static void _rtl92ce_hal_customized_behavior(struct ieee80211_hw *hw)
  1520. {
  1521. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1522. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1523. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1524. switch (rtlhal->oem_id) {
  1525. case RT_CID_819X_HP:
  1526. pcipriv->ledctl.led_opendrain = true;
  1527. break;
  1528. case RT_CID_819X_LENOVO:
  1529. case RT_CID_DEFAULT:
  1530. case RT_CID_TOSHIBA:
  1531. case RT_CID_CCX:
  1532. case RT_CID_819X_ACER:
  1533. case RT_CID_WHQL:
  1534. default:
  1535. break;
  1536. }
  1537. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1538. "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
  1539. }
  1540. void rtl92ce_read_eeprom_info(struct ieee80211_hw *hw)
  1541. {
  1542. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1543. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1544. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1545. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1546. u8 tmp_u1b;
  1547. rtlhal->version = _rtl92ce_read_chip_version(hw);
  1548. if (get_rf_type(rtlphy) == RF_1T1R)
  1549. rtlpriv->dm.rfpath_rxenable[0] = true;
  1550. else
  1551. rtlpriv->dm.rfpath_rxenable[0] =
  1552. rtlpriv->dm.rfpath_rxenable[1] = true;
  1553. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
  1554. rtlhal->version);
  1555. tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
  1556. if (tmp_u1b & BIT(4)) {
  1557. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
  1558. rtlefuse->epromtype = EEPROM_93C46;
  1559. } else {
  1560. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
  1561. rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
  1562. }
  1563. if (tmp_u1b & BIT(5)) {
  1564. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1565. rtlefuse->autoload_failflag = false;
  1566. _rtl92ce_read_adapter_info(hw);
  1567. } else {
  1568. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Autoload ERR!!\n");
  1569. }
  1570. _rtl92ce_hal_customized_behavior(hw);
  1571. }
  1572. static void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw,
  1573. struct ieee80211_sta *sta)
  1574. {
  1575. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1576. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  1577. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1578. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1579. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1580. u32 ratr_value;
  1581. u8 ratr_index = 0;
  1582. u8 nmode = mac->ht_enable;
  1583. u16 shortgi_rate;
  1584. u32 tmp_ratr_value;
  1585. u8 curtxbw_40mhz = mac->bw_40;
  1586. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1587. 1 : 0;
  1588. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1589. 1 : 0;
  1590. enum wireless_mode wirelessmode = mac->mode;
  1591. u32 ratr_mask;
  1592. if (rtlhal->current_bandtype == BAND_ON_5G)
  1593. ratr_value = sta->supp_rates[1] << 4;
  1594. else
  1595. ratr_value = sta->supp_rates[0];
  1596. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1597. ratr_value = 0xfff;
  1598. ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1599. sta->ht_cap.mcs.rx_mask[0] << 12);
  1600. switch (wirelessmode) {
  1601. case WIRELESS_MODE_B:
  1602. if (ratr_value & 0x0000000c)
  1603. ratr_value &= 0x0000000d;
  1604. else
  1605. ratr_value &= 0x0000000f;
  1606. break;
  1607. case WIRELESS_MODE_G:
  1608. ratr_value &= 0x00000FF5;
  1609. break;
  1610. case WIRELESS_MODE_N_24G:
  1611. case WIRELESS_MODE_N_5G:
  1612. nmode = 1;
  1613. if (get_rf_type(rtlphy) == RF_1T2R ||
  1614. get_rf_type(rtlphy) == RF_1T1R)
  1615. ratr_mask = 0x000ff005;
  1616. else
  1617. ratr_mask = 0x0f0ff005;
  1618. ratr_value &= ratr_mask;
  1619. break;
  1620. default:
  1621. if (rtlphy->rf_type == RF_1T2R)
  1622. ratr_value &= 0x000ff0ff;
  1623. else
  1624. ratr_value &= 0x0f0ff0ff;
  1625. break;
  1626. }
  1627. if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
  1628. (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) &&
  1629. (rtlpcipriv->bt_coexist.bt_cur_state) &&
  1630. (rtlpcipriv->bt_coexist.bt_ant_isolation) &&
  1631. ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ||
  1632. (rtlpcipriv->bt_coexist.bt_service == BT_BUSY)))
  1633. ratr_value &= 0x0fffcfc0;
  1634. else
  1635. ratr_value &= 0x0FFFFFFF;
  1636. if (nmode && ((curtxbw_40mhz &&
  1637. curshortgi_40mhz) || (!curtxbw_40mhz &&
  1638. curshortgi_20mhz))) {
  1639. ratr_value |= 0x10000000;
  1640. tmp_ratr_value = (ratr_value >> 12);
  1641. for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
  1642. if ((1 << shortgi_rate) & tmp_ratr_value)
  1643. break;
  1644. }
  1645. shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
  1646. (shortgi_rate << 4) | (shortgi_rate);
  1647. }
  1648. rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
  1649. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n",
  1650. rtl_read_dword(rtlpriv, REG_ARFR0));
  1651. }
  1652. static void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw,
  1653. struct ieee80211_sta *sta, u8 rssi_level)
  1654. {
  1655. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1656. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1657. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1658. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1659. struct rtl_sta_info *sta_entry = NULL;
  1660. u32 ratr_bitmap;
  1661. u8 ratr_index;
  1662. u8 curtxbw_40mhz = (sta->ht_cap.cap &
  1663. IEEE80211_HT_CAP_SUP_WIDTH_20_40) ? 1 : 0;
  1664. u8 curshortgi_40mhz = (sta->ht_cap.cap &
  1665. IEEE80211_HT_CAP_SGI_40) ? 1 : 0;
  1666. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1667. 1 : 0;
  1668. enum wireless_mode wirelessmode = 0;
  1669. bool shortgi = false;
  1670. u8 rate_mask[5];
  1671. u8 macid = 0;
  1672. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  1673. wirelessmode = sta_entry->wireless_mode;
  1674. if (mac->opmode == NL80211_IFTYPE_STATION ||
  1675. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  1676. curtxbw_40mhz = mac->bw_40;
  1677. else if (mac->opmode == NL80211_IFTYPE_AP ||
  1678. mac->opmode == NL80211_IFTYPE_ADHOC)
  1679. macid = sta->aid + 1;
  1680. if (rtlhal->current_bandtype == BAND_ON_5G)
  1681. ratr_bitmap = sta->supp_rates[1] << 4;
  1682. else
  1683. ratr_bitmap = sta->supp_rates[0];
  1684. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1685. ratr_bitmap = 0xfff;
  1686. ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1687. sta->ht_cap.mcs.rx_mask[0] << 12);
  1688. switch (wirelessmode) {
  1689. case WIRELESS_MODE_B:
  1690. ratr_index = RATR_INX_WIRELESS_B;
  1691. if (ratr_bitmap & 0x0000000c)
  1692. ratr_bitmap &= 0x0000000d;
  1693. else
  1694. ratr_bitmap &= 0x0000000f;
  1695. break;
  1696. case WIRELESS_MODE_G:
  1697. ratr_index = RATR_INX_WIRELESS_GB;
  1698. if (rssi_level == 1)
  1699. ratr_bitmap &= 0x00000f00;
  1700. else if (rssi_level == 2)
  1701. ratr_bitmap &= 0x00000ff0;
  1702. else
  1703. ratr_bitmap &= 0x00000ff5;
  1704. break;
  1705. case WIRELESS_MODE_A:
  1706. ratr_index = RATR_INX_WIRELESS_A;
  1707. ratr_bitmap &= 0x00000ff0;
  1708. break;
  1709. case WIRELESS_MODE_N_24G:
  1710. case WIRELESS_MODE_N_5G:
  1711. ratr_index = RATR_INX_WIRELESS_NGB;
  1712. if (rtlphy->rf_type == RF_1T2R ||
  1713. rtlphy->rf_type == RF_1T1R) {
  1714. if (curtxbw_40mhz) {
  1715. if (rssi_level == 1)
  1716. ratr_bitmap &= 0x000f0000;
  1717. else if (rssi_level == 2)
  1718. ratr_bitmap &= 0x000ff000;
  1719. else
  1720. ratr_bitmap &= 0x000ff015;
  1721. } else {
  1722. if (rssi_level == 1)
  1723. ratr_bitmap &= 0x000f0000;
  1724. else if (rssi_level == 2)
  1725. ratr_bitmap &= 0x000ff000;
  1726. else
  1727. ratr_bitmap &= 0x000ff005;
  1728. }
  1729. } else {
  1730. if (curtxbw_40mhz) {
  1731. if (rssi_level == 1)
  1732. ratr_bitmap &= 0x0f0f0000;
  1733. else if (rssi_level == 2)
  1734. ratr_bitmap &= 0x0f0ff000;
  1735. else
  1736. ratr_bitmap &= 0x0f0ff015;
  1737. } else {
  1738. if (rssi_level == 1)
  1739. ratr_bitmap &= 0x0f0f0000;
  1740. else if (rssi_level == 2)
  1741. ratr_bitmap &= 0x0f0ff000;
  1742. else
  1743. ratr_bitmap &= 0x0f0ff005;
  1744. }
  1745. }
  1746. if ((curtxbw_40mhz && curshortgi_40mhz) ||
  1747. (!curtxbw_40mhz && curshortgi_20mhz)) {
  1748. if (macid == 0)
  1749. shortgi = true;
  1750. else if (macid == 1)
  1751. shortgi = false;
  1752. }
  1753. break;
  1754. default:
  1755. ratr_index = RATR_INX_WIRELESS_NGB;
  1756. if (rtlphy->rf_type == RF_1T2R)
  1757. ratr_bitmap &= 0x000ff0ff;
  1758. else
  1759. ratr_bitmap &= 0x0f0ff0ff;
  1760. break;
  1761. }
  1762. sta_entry->ratr_index = ratr_index;
  1763. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1764. "ratr_bitmap :%x\n", ratr_bitmap);
  1765. *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
  1766. (ratr_index << 28);
  1767. rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
  1768. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1769. "Rate_index:%x, ratr_val:%x, %5phC\n",
  1770. ratr_index, ratr_bitmap, rate_mask);
  1771. rtl92c_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask);
  1772. }
  1773. void rtl92ce_update_hal_rate_tbl(struct ieee80211_hw *hw,
  1774. struct ieee80211_sta *sta, u8 rssi_level)
  1775. {
  1776. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1777. if (rtlpriv->dm.useramask)
  1778. rtl92ce_update_hal_rate_mask(hw, sta, rssi_level);
  1779. else
  1780. rtl92ce_update_hal_rate_table(hw, sta);
  1781. }
  1782. void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw)
  1783. {
  1784. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1785. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1786. u16 sifs_timer;
  1787. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  1788. &mac->slot_time);
  1789. if (!mac->ht_enable)
  1790. sifs_timer = 0x0a0a;
  1791. else
  1792. sifs_timer = 0x1010;
  1793. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
  1794. }
  1795. bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
  1796. {
  1797. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1798. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1799. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1800. enum rf_pwrstate e_rfpowerstate_toset;
  1801. u8 u1tmp;
  1802. bool actuallyset = false;
  1803. unsigned long flag;
  1804. if (rtlpci->being_init_adapter)
  1805. return false;
  1806. if (ppsc->swrf_processing)
  1807. return false;
  1808. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1809. if (ppsc->rfchange_inprogress) {
  1810. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1811. return false;
  1812. } else {
  1813. ppsc->rfchange_inprogress = true;
  1814. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1815. }
  1816. rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, rtl_read_byte(rtlpriv,
  1817. REG_MAC_PINMUX_CFG)&~(BIT(3)));
  1818. u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL);
  1819. e_rfpowerstate_toset = (u1tmp & BIT(3)) ? ERFON : ERFOFF;
  1820. if ((ppsc->hwradiooff) && (e_rfpowerstate_toset == ERFON)) {
  1821. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1822. "GPIOChangeRF - HW Radio ON, RF ON\n");
  1823. e_rfpowerstate_toset = ERFON;
  1824. ppsc->hwradiooff = false;
  1825. actuallyset = true;
  1826. } else if (!ppsc->hwradiooff && (e_rfpowerstate_toset == ERFOFF)) {
  1827. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1828. "GPIOChangeRF - HW Radio OFF, RF OFF\n");
  1829. e_rfpowerstate_toset = ERFOFF;
  1830. ppsc->hwradiooff = true;
  1831. actuallyset = true;
  1832. }
  1833. if (actuallyset) {
  1834. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1835. ppsc->rfchange_inprogress = false;
  1836. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1837. } else {
  1838. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
  1839. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1840. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1841. ppsc->rfchange_inprogress = false;
  1842. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1843. }
  1844. *valid = 1;
  1845. return !ppsc->hwradiooff;
  1846. }
  1847. void rtl92ce_set_key(struct ieee80211_hw *hw, u32 key_index,
  1848. u8 *p_macaddr, bool is_group, u8 enc_algo,
  1849. bool is_wepkey, bool clear_all)
  1850. {
  1851. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1852. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1853. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1854. u8 *macaddr = p_macaddr;
  1855. u32 entry_id = 0;
  1856. bool is_pairwise = false;
  1857. static u8 cam_const_addr[4][6] = {
  1858. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  1859. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  1860. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  1861. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  1862. };
  1863. static u8 cam_const_broad[] = {
  1864. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  1865. };
  1866. if (clear_all) {
  1867. u8 idx = 0;
  1868. u8 cam_offset = 0;
  1869. u8 clear_number = 5;
  1870. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  1871. for (idx = 0; idx < clear_number; idx++) {
  1872. rtl_cam_mark_invalid(hw, cam_offset + idx);
  1873. rtl_cam_empty_entry(hw, cam_offset + idx);
  1874. if (idx < 5) {
  1875. memset(rtlpriv->sec.key_buf[idx], 0,
  1876. MAX_KEY_LEN);
  1877. rtlpriv->sec.key_len[idx] = 0;
  1878. }
  1879. }
  1880. } else {
  1881. switch (enc_algo) {
  1882. case WEP40_ENCRYPTION:
  1883. enc_algo = CAM_WEP40;
  1884. break;
  1885. case WEP104_ENCRYPTION:
  1886. enc_algo = CAM_WEP104;
  1887. break;
  1888. case TKIP_ENCRYPTION:
  1889. enc_algo = CAM_TKIP;
  1890. break;
  1891. case AESCCMP_ENCRYPTION:
  1892. enc_algo = CAM_AES;
  1893. break;
  1894. default:
  1895. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1896. "switch case not processed\n");
  1897. enc_algo = CAM_TKIP;
  1898. break;
  1899. }
  1900. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  1901. macaddr = cam_const_addr[key_index];
  1902. entry_id = key_index;
  1903. } else {
  1904. if (is_group) {
  1905. macaddr = cam_const_broad;
  1906. entry_id = key_index;
  1907. } else {
  1908. if (mac->opmode == NL80211_IFTYPE_AP ||
  1909. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  1910. entry_id = rtl_cam_get_free_entry(hw,
  1911. p_macaddr);
  1912. if (entry_id >= TOTAL_CAM_ENTRY) {
  1913. RT_TRACE(rtlpriv, COMP_SEC,
  1914. DBG_EMERG,
  1915. "Can not find free hw security cam entry\n");
  1916. return;
  1917. }
  1918. } else {
  1919. entry_id = CAM_PAIRWISE_KEY_POSITION;
  1920. }
  1921. key_index = PAIRWISE_KEYIDX;
  1922. is_pairwise = true;
  1923. }
  1924. }
  1925. if (rtlpriv->sec.key_len[key_index] == 0) {
  1926. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1927. "delete one entry, entry_id is %d\n",
  1928. entry_id);
  1929. if (mac->opmode == NL80211_IFTYPE_AP ||
  1930. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  1931. rtl_cam_del_entry(hw, p_macaddr);
  1932. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  1933. } else {
  1934. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  1935. "The insert KEY length is %d\n",
  1936. rtlpriv->sec.key_len[PAIRWISE_KEYIDX]);
  1937. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  1938. "The insert KEY is %x %x\n",
  1939. rtlpriv->sec.key_buf[0][0],
  1940. rtlpriv->sec.key_buf[0][1]);
  1941. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1942. "add one entry\n");
  1943. if (is_pairwise) {
  1944. RT_PRINT_DATA(rtlpriv, COMP_SEC, DBG_LOUD,
  1945. "Pairwise Key content",
  1946. rtlpriv->sec.pairwise_key,
  1947. rtlpriv->sec.
  1948. key_len[PAIRWISE_KEYIDX]);
  1949. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1950. "set Pairwise key\n");
  1951. rtl_cam_add_one_entry(hw, macaddr, key_index,
  1952. entry_id, enc_algo,
  1953. CAM_CONFIG_NO_USEDK,
  1954. rtlpriv->sec.
  1955. key_buf[key_index]);
  1956. } else {
  1957. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1958. "set group key\n");
  1959. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  1960. rtl_cam_add_one_entry(hw,
  1961. rtlefuse->dev_addr,
  1962. PAIRWISE_KEYIDX,
  1963. CAM_PAIRWISE_KEY_POSITION,
  1964. enc_algo,
  1965. CAM_CONFIG_NO_USEDK,
  1966. rtlpriv->sec.key_buf
  1967. [entry_id]);
  1968. }
  1969. rtl_cam_add_one_entry(hw, macaddr, key_index,
  1970. entry_id, enc_algo,
  1971. CAM_CONFIG_NO_USEDK,
  1972. rtlpriv->sec.key_buf[entry_id]);
  1973. }
  1974. }
  1975. }
  1976. }
  1977. static void rtl8192ce_bt_var_init(struct ieee80211_hw *hw)
  1978. {
  1979. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  1980. rtlpcipriv->bt_coexist.bt_coexistence =
  1981. rtlpcipriv->bt_coexist.eeprom_bt_coexist;
  1982. rtlpcipriv->bt_coexist.bt_ant_num =
  1983. rtlpcipriv->bt_coexist.eeprom_bt_ant_num;
  1984. rtlpcipriv->bt_coexist.bt_coexist_type =
  1985. rtlpcipriv->bt_coexist.eeprom_bt_type;
  1986. if (rtlpcipriv->bt_coexist.reg_bt_iso == 2)
  1987. rtlpcipriv->bt_coexist.bt_ant_isolation =
  1988. rtlpcipriv->bt_coexist.eeprom_bt_ant_isol;
  1989. else
  1990. rtlpcipriv->bt_coexist.bt_ant_isolation =
  1991. rtlpcipriv->bt_coexist.reg_bt_iso;
  1992. rtlpcipriv->bt_coexist.bt_radio_shared_type =
  1993. rtlpcipriv->bt_coexist.eeprom_bt_radio_shared;
  1994. if (rtlpcipriv->bt_coexist.bt_coexistence) {
  1995. if (rtlpcipriv->bt_coexist.reg_bt_sco == 1)
  1996. rtlpcipriv->bt_coexist.bt_service = BT_OTHER_ACTION;
  1997. else if (rtlpcipriv->bt_coexist.reg_bt_sco == 2)
  1998. rtlpcipriv->bt_coexist.bt_service = BT_SCO;
  1999. else if (rtlpcipriv->bt_coexist.reg_bt_sco == 4)
  2000. rtlpcipriv->bt_coexist.bt_service = BT_BUSY;
  2001. else if (rtlpcipriv->bt_coexist.reg_bt_sco == 5)
  2002. rtlpcipriv->bt_coexist.bt_service = BT_OTHERBUSY;
  2003. else
  2004. rtlpcipriv->bt_coexist.bt_service = BT_IDLE;
  2005. rtlpcipriv->bt_coexist.bt_edca_ul = 0;
  2006. rtlpcipriv->bt_coexist.bt_edca_dl = 0;
  2007. rtlpcipriv->bt_coexist.bt_rssi_state = 0xff;
  2008. }
  2009. }
  2010. void rtl8192ce_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
  2011. bool auto_load_fail, u8 *hwinfo)
  2012. {
  2013. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  2014. u8 val;
  2015. if (!auto_load_fail) {
  2016. rtlpcipriv->bt_coexist.eeprom_bt_coexist =
  2017. ((hwinfo[RF_OPTION1] & 0xe0) >> 5);
  2018. val = hwinfo[RF_OPTION4];
  2019. rtlpcipriv->bt_coexist.eeprom_bt_type = ((val & 0xe) >> 1);
  2020. rtlpcipriv->bt_coexist.eeprom_bt_ant_num = (val & 0x1);
  2021. rtlpcipriv->bt_coexist.eeprom_bt_ant_isol = ((val & 0x10) >> 4);
  2022. rtlpcipriv->bt_coexist.eeprom_bt_radio_shared =
  2023. ((val & 0x20) >> 5);
  2024. } else {
  2025. rtlpcipriv->bt_coexist.eeprom_bt_coexist = 0;
  2026. rtlpcipriv->bt_coexist.eeprom_bt_type = BT_2WIRE;
  2027. rtlpcipriv->bt_coexist.eeprom_bt_ant_num = ANT_X2;
  2028. rtlpcipriv->bt_coexist.eeprom_bt_ant_isol = 0;
  2029. rtlpcipriv->bt_coexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
  2030. }
  2031. rtl8192ce_bt_var_init(hw);
  2032. }
  2033. void rtl8192ce_bt_reg_init(struct ieee80211_hw *hw)
  2034. {
  2035. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  2036. /* 0:Low, 1:High, 2:From Efuse. */
  2037. rtlpcipriv->bt_coexist.reg_bt_iso = 2;
  2038. /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
  2039. rtlpcipriv->bt_coexist.reg_bt_sco = 3;
  2040. /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
  2041. rtlpcipriv->bt_coexist.reg_bt_sco = 0;
  2042. }
  2043. void rtl8192ce_bt_hw_init(struct ieee80211_hw *hw)
  2044. {
  2045. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2046. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  2047. struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
  2048. u8 u1_tmp;
  2049. if (rtlpcipriv->bt_coexist.bt_coexistence &&
  2050. ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
  2051. rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8)) {
  2052. if (rtlpcipriv->bt_coexist.bt_ant_isolation)
  2053. rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
  2054. u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) &
  2055. BIT_OFFSET_LEN_MASK_32(0, 1);
  2056. u1_tmp = u1_tmp |
  2057. ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ?
  2058. 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
  2059. ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ?
  2060. 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
  2061. rtl_write_byte(rtlpriv, 0x4fd, u1_tmp);
  2062. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa);
  2063. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040);
  2064. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010);
  2065. /* Config to 1T1R. */
  2066. if (rtlphy->rf_type == RF_1T1R) {
  2067. u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE);
  2068. u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
  2069. rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp);
  2070. u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE);
  2071. u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
  2072. rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp);
  2073. }
  2074. }
  2075. }
  2076. void rtl92ce_suspend(struct ieee80211_hw *hw)
  2077. {
  2078. }
  2079. void rtl92ce_resume(struct ieee80211_hw *hw)
  2080. {
  2081. }