hw.c 64 KB

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