hw.c 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2014 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 "dm.h"
  36. #include "fw.h"
  37. #include "led.h"
  38. #include "hw.h"
  39. #include "../pwrseqcmd.h"
  40. #include "pwrseq.h"
  41. #define LLT_CONFIG 5
  42. static void _rtl92ee_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 _rtl92ee_stop_tx_beacon(struct ieee80211_hw *hw)
  52. {
  53. struct rtl_priv *rtlpriv = rtl_priv(hw);
  54. u8 tmp;
  55. tmp = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  56. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp & (~BIT(6)));
  57. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
  58. tmp = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  59. tmp &= ~(BIT(0));
  60. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp);
  61. }
  62. static void _rtl92ee_resume_tx_beacon(struct ieee80211_hw *hw)
  63. {
  64. struct rtl_priv *rtlpriv = rtl_priv(hw);
  65. u8 tmp;
  66. tmp = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  67. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp | BIT(6));
  68. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  69. tmp = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  70. tmp |= BIT(0);
  71. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp);
  72. }
  73. static void _rtl92ee_enable_bcn_sub_func(struct ieee80211_hw *hw)
  74. {
  75. _rtl92ee_set_bcn_ctrl_reg(hw, 0, BIT(1));
  76. }
  77. static void _rtl92ee_disable_bcn_sub_func(struct ieee80211_hw *hw)
  78. {
  79. _rtl92ee_set_bcn_ctrl_reg(hw, BIT(1), 0);
  80. }
  81. static void _rtl92ee_set_fw_clock_on(struct ieee80211_hw *hw,
  82. u8 rpwm_val, bool b_need_turn_off_ckk)
  83. {
  84. struct rtl_priv *rtlpriv = rtl_priv(hw);
  85. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  86. bool b_support_remote_wake_up;
  87. u32 count = 0, isr_regaddr, content;
  88. bool b_schedule_timer = b_need_turn_off_ckk;
  89. rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
  90. (u8 *)(&b_support_remote_wake_up));
  91. if (!rtlhal->fw_ready)
  92. return;
  93. if (!rtlpriv->psc.fw_current_inpsmode)
  94. return;
  95. while (1) {
  96. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  97. if (rtlhal->fw_clk_change_in_progress) {
  98. while (rtlhal->fw_clk_change_in_progress) {
  99. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  100. count++;
  101. udelay(100);
  102. if (count > 1000)
  103. return;
  104. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  105. }
  106. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  107. } else {
  108. rtlhal->fw_clk_change_in_progress = false;
  109. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  110. break;
  111. }
  112. }
  113. if (IS_IN_LOW_POWER_STATE_92E(rtlhal->fw_ps_state)) {
  114. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_SET_RPWM,
  115. (u8 *)(&rpwm_val));
  116. if (FW_PS_IS_ACK(rpwm_val)) {
  117. isr_regaddr = REG_HISR;
  118. content = rtl_read_dword(rtlpriv, isr_regaddr);
  119. while (!(content & IMR_CPWM) && (count < 500)) {
  120. udelay(50);
  121. count++;
  122. content = rtl_read_dword(rtlpriv, isr_regaddr);
  123. }
  124. if (content & IMR_CPWM) {
  125. rtl_write_word(rtlpriv, isr_regaddr, 0x0100);
  126. rtlhal->fw_ps_state = FW_PS_STATE_RF_ON_92E;
  127. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  128. "Receive CPWM INT!!! PSState = %X\n",
  129. rtlhal->fw_ps_state);
  130. }
  131. }
  132. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  133. rtlhal->fw_clk_change_in_progress = false;
  134. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  135. if (b_schedule_timer) {
  136. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  137. jiffies + MSECS(10));
  138. }
  139. } else {
  140. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  141. rtlhal->fw_clk_change_in_progress = false;
  142. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  143. }
  144. }
  145. static void _rtl92ee_set_fw_clock_off(struct ieee80211_hw *hw, u8 rpwm_val)
  146. {
  147. struct rtl_priv *rtlpriv = rtl_priv(hw);
  148. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  149. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  150. struct rtl8192_tx_ring *ring;
  151. enum rf_pwrstate rtstate;
  152. bool b_schedule_timer = false;
  153. u8 queue;
  154. if (!rtlhal->fw_ready)
  155. return;
  156. if (!rtlpriv->psc.fw_current_inpsmode)
  157. return;
  158. if (!rtlhal->allow_sw_to_change_hwclc)
  159. return;
  160. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE, (u8 *)(&rtstate));
  161. if (rtstate == ERFOFF || rtlpriv->psc.inactive_pwrstate == ERFOFF)
  162. return;
  163. for (queue = 0; queue < RTL_PCI_MAX_TX_QUEUE_COUNT; queue++) {
  164. ring = &rtlpci->tx_ring[queue];
  165. if (skb_queue_len(&ring->queue)) {
  166. b_schedule_timer = true;
  167. break;
  168. }
  169. }
  170. if (b_schedule_timer) {
  171. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  172. jiffies + MSECS(10));
  173. return;
  174. }
  175. if (FW_PS_STATE(rtlhal->fw_ps_state) != FW_PS_STATE_RF_OFF_LOW_PWR) {
  176. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  177. if (!rtlhal->fw_clk_change_in_progress) {
  178. rtlhal->fw_clk_change_in_progress = true;
  179. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  180. rtlhal->fw_ps_state = FW_PS_STATE(rpwm_val);
  181. rtl_write_word(rtlpriv, REG_HISR, 0x0100);
  182. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
  183. (u8 *)(&rpwm_val));
  184. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  185. rtlhal->fw_clk_change_in_progress = false;
  186. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  187. } else {
  188. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  189. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  190. jiffies + MSECS(10));
  191. }
  192. }
  193. }
  194. static void _rtl92ee_set_fw_ps_rf_on(struct ieee80211_hw *hw)
  195. {
  196. u8 rpwm_val = 0;
  197. rpwm_val |= (FW_PS_STATE_RF_OFF_92E | FW_PS_ACK);
  198. _rtl92ee_set_fw_clock_on(hw, rpwm_val, true);
  199. }
  200. static void _rtl92ee_set_fw_ps_rf_off_low_power(struct ieee80211_hw *hw)
  201. {
  202. u8 rpwm_val = 0;
  203. rpwm_val |= FW_PS_STATE_RF_OFF_LOW_PWR;
  204. _rtl92ee_set_fw_clock_off(hw, rpwm_val);
  205. }
  206. void rtl92ee_fw_clk_off_timer_callback(unsigned long data)
  207. {
  208. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  209. _rtl92ee_set_fw_ps_rf_off_low_power(hw);
  210. }
  211. static void _rtl92ee_fwlps_leave(struct ieee80211_hw *hw)
  212. {
  213. struct rtl_priv *rtlpriv = rtl_priv(hw);
  214. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  215. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  216. bool fw_current_inps = false;
  217. u8 rpwm_val = 0, fw_pwrmode = FW_PS_ACTIVE_MODE;
  218. if (ppsc->low_power_enable) {
  219. rpwm_val = (FW_PS_STATE_ALL_ON_92E | FW_PS_ACK);/* RF on */
  220. _rtl92ee_set_fw_clock_on(hw, rpwm_val, false);
  221. rtlhal->allow_sw_to_change_hwclc = false;
  222. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  223. (u8 *)(&fw_pwrmode));
  224. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  225. (u8 *)(&fw_current_inps));
  226. } else {
  227. rpwm_val = FW_PS_STATE_ALL_ON_92E; /* RF on */
  228. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
  229. (u8 *)(&rpwm_val));
  230. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  231. (u8 *)(&fw_pwrmode));
  232. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  233. (u8 *)(&fw_current_inps));
  234. }
  235. }
  236. static void _rtl92ee_fwlps_enter(struct ieee80211_hw *hw)
  237. {
  238. struct rtl_priv *rtlpriv = rtl_priv(hw);
  239. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  240. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  241. bool fw_current_inps = true;
  242. u8 rpwm_val;
  243. if (ppsc->low_power_enable) {
  244. rpwm_val = FW_PS_STATE_RF_OFF_LOW_PWR; /* RF off */
  245. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  246. (u8 *)(&fw_current_inps));
  247. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  248. (u8 *)(&ppsc->fwctrl_psmode));
  249. rtlhal->allow_sw_to_change_hwclc = true;
  250. _rtl92ee_set_fw_clock_off(hw, rpwm_val);
  251. } else {
  252. rpwm_val = FW_PS_STATE_RF_OFF_92E; /* RF off */
  253. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  254. (u8 *)(&fw_current_inps));
  255. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  256. (u8 *)(&ppsc->fwctrl_psmode));
  257. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
  258. (u8 *)(&rpwm_val));
  259. }
  260. }
  261. void rtl92ee_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  262. {
  263. struct rtl_priv *rtlpriv = rtl_priv(hw);
  264. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  265. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  266. switch (variable) {
  267. case HW_VAR_RCR:
  268. *((u32 *)(val)) = rtlpci->receive_config;
  269. break;
  270. case HW_VAR_RF_STATE:
  271. *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
  272. break;
  273. case HW_VAR_FWLPS_RF_ON:{
  274. enum rf_pwrstate rfstate;
  275. u32 val_rcr;
  276. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE,
  277. (u8 *)(&rfstate));
  278. if (rfstate == ERFOFF) {
  279. *((bool *)(val)) = true;
  280. } else {
  281. val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
  282. val_rcr &= 0x00070000;
  283. if (val_rcr)
  284. *((bool *)(val)) = false;
  285. else
  286. *((bool *)(val)) = true;
  287. }
  288. }
  289. break;
  290. case HW_VAR_FW_PSMODE_STATUS:
  291. *((bool *)(val)) = ppsc->fw_current_inpsmode;
  292. break;
  293. case HW_VAR_CORRECT_TSF:{
  294. u64 tsf;
  295. u32 *ptsf_low = (u32 *)&tsf;
  296. u32 *ptsf_high = ((u32 *)&tsf) + 1;
  297. *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
  298. *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
  299. *((u64 *)(val)) = tsf;
  300. }
  301. break;
  302. default:
  303. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  304. "switch case not process %x\n", variable);
  305. break;
  306. }
  307. }
  308. static void _rtl92ee_download_rsvd_page(struct ieee80211_hw *hw)
  309. {
  310. struct rtl_priv *rtlpriv = rtl_priv(hw);
  311. u8 tmp_regcr, tmp_reg422;
  312. u8 bcnvalid_reg, txbc_reg;
  313. u8 count = 0, dlbcn_count = 0;
  314. bool b_recover = false;
  315. /*Set REG_CR bit 8. DMA beacon by SW.*/
  316. tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
  317. rtl_write_byte(rtlpriv, REG_CR + 1, tmp_regcr | BIT(0));
  318. /* Disable Hw protection for a time which revserd for Hw sending beacon.
  319. * Fix download reserved page packet fail
  320. * that access collision with the protection time.
  321. * 2010.05.11. Added by tynli.
  322. */
  323. _rtl92ee_set_bcn_ctrl_reg(hw, 0, BIT(3));
  324. _rtl92ee_set_bcn_ctrl_reg(hw, BIT(4), 0);
  325. /* Set FWHW_TXQ_CTRL 0x422[6]=0 to
  326. * tell Hw the packet is not a real beacon frame.
  327. */
  328. tmp_reg422 = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  329. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp_reg422 & (~BIT(6)));
  330. if (tmp_reg422 & BIT(6))
  331. b_recover = true;
  332. do {
  333. /* Clear beacon valid check bit */
  334. bcnvalid_reg = rtl_read_byte(rtlpriv, REG_DWBCN0_CTRL + 2);
  335. rtl_write_byte(rtlpriv, REG_DWBCN0_CTRL + 2,
  336. bcnvalid_reg | BIT(0));
  337. /* download rsvd page */
  338. rtl92ee_set_fw_rsvdpagepkt(hw, false);
  339. txbc_reg = rtl_read_byte(rtlpriv, REG_MGQ_TXBD_NUM + 3);
  340. count = 0;
  341. while ((txbc_reg & BIT(4)) && count < 20) {
  342. count++;
  343. udelay(10);
  344. txbc_reg = rtl_read_byte(rtlpriv, REG_MGQ_TXBD_NUM + 3);
  345. }
  346. rtl_write_byte(rtlpriv, REG_MGQ_TXBD_NUM + 3,
  347. txbc_reg | BIT(4));
  348. /* check rsvd page download OK. */
  349. bcnvalid_reg = rtl_read_byte(rtlpriv, REG_DWBCN0_CTRL + 2);
  350. count = 0;
  351. while (!(bcnvalid_reg & BIT(0)) && count < 20) {
  352. count++;
  353. udelay(50);
  354. bcnvalid_reg = rtl_read_byte(rtlpriv,
  355. REG_DWBCN0_CTRL + 2);
  356. }
  357. if (bcnvalid_reg & BIT(0))
  358. rtl_write_byte(rtlpriv, REG_DWBCN0_CTRL + 2, BIT(0));
  359. dlbcn_count++;
  360. } while (!(bcnvalid_reg & BIT(0)) && dlbcn_count < 5);
  361. if (!(bcnvalid_reg & BIT(0)))
  362. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  363. "Download RSVD page failed!\n");
  364. /* Enable Bcn */
  365. _rtl92ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  366. _rtl92ee_set_bcn_ctrl_reg(hw, 0, BIT(4));
  367. if (b_recover)
  368. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp_reg422);
  369. tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
  370. rtl_write_byte(rtlpriv, REG_CR + 1, tmp_regcr & (~BIT(0)));
  371. }
  372. void rtl92ee_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  373. {
  374. struct rtl_priv *rtlpriv = rtl_priv(hw);
  375. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  376. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  377. struct rtl_efuse *efuse = rtl_efuse(rtl_priv(hw));
  378. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  379. u8 idx;
  380. switch (variable) {
  381. case HW_VAR_ETHER_ADDR:
  382. for (idx = 0; idx < ETH_ALEN; idx++)
  383. rtl_write_byte(rtlpriv, (REG_MACID + idx), val[idx]);
  384. break;
  385. case HW_VAR_BASIC_RATE:{
  386. u16 b_rate_cfg = ((u16 *)val)[0];
  387. b_rate_cfg = b_rate_cfg & 0x15f;
  388. b_rate_cfg |= 0x01;
  389. b_rate_cfg = (b_rate_cfg | 0xd) & (~BIT(1));
  390. rtl_write_byte(rtlpriv, REG_RRSR, b_rate_cfg & 0xff);
  391. rtl_write_byte(rtlpriv, REG_RRSR + 1, (b_rate_cfg >> 8) & 0xff);
  392. break; }
  393. case HW_VAR_BSSID:
  394. for (idx = 0; idx < ETH_ALEN; idx++)
  395. rtl_write_byte(rtlpriv, (REG_BSSID + idx), val[idx]);
  396. break;
  397. case HW_VAR_SIFS:
  398. rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
  399. rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
  400. rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
  401. rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
  402. if (!mac->ht_enable)
  403. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM, 0x0e0e);
  404. else
  405. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  406. *((u16 *)val));
  407. break;
  408. case HW_VAR_SLOT_TIME:{
  409. u8 e_aci;
  410. RT_TRACE(rtlpriv, COMP_MLME, DBG_TRACE,
  411. "HW_VAR_SLOT_TIME %x\n", val[0]);
  412. rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
  413. for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
  414. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM,
  415. (u8 *)(&e_aci));
  416. }
  417. break; }
  418. case HW_VAR_ACK_PREAMBLE:{
  419. u8 reg_tmp;
  420. u8 short_preamble = (bool)(*(u8 *)val);
  421. reg_tmp = (rtlpriv->mac80211.cur_40_prime_sc) << 5;
  422. if (short_preamble)
  423. reg_tmp |= 0x80;
  424. rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
  425. rtlpriv->mac80211.short_preamble = short_preamble;
  426. }
  427. break;
  428. case HW_VAR_WPA_CONFIG:
  429. rtl_write_byte(rtlpriv, REG_SECCFG, *((u8 *)val));
  430. break;
  431. case HW_VAR_AMPDU_FACTOR:{
  432. u8 regtoset_normal[4] = { 0x41, 0xa8, 0x72, 0xb9 };
  433. u8 fac;
  434. u8 *reg = NULL;
  435. u8 i = 0;
  436. reg = regtoset_normal;
  437. fac = *((u8 *)val);
  438. if (fac <= 3) {
  439. fac = (1 << (fac + 2));
  440. if (fac > 0xf)
  441. fac = 0xf;
  442. for (i = 0; i < 4; i++) {
  443. if ((reg[i] & 0xf0) > (fac << 4))
  444. reg[i] = (reg[i] & 0x0f) |
  445. (fac << 4);
  446. if ((reg[i] & 0x0f) > fac)
  447. reg[i] = (reg[i] & 0xf0) | fac;
  448. rtl_write_byte(rtlpriv,
  449. (REG_AGGLEN_LMT + i),
  450. reg[i]);
  451. }
  452. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  453. "Set HW_VAR_AMPDU_FACTOR:%#x\n", fac);
  454. }
  455. }
  456. break;
  457. case HW_VAR_AC_PARAM:{
  458. u8 e_aci = *((u8 *)val);
  459. if (rtlpci->acm_method != EACMWAY2_SW)
  460. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACM_CTRL,
  461. (u8 *)(&e_aci));
  462. }
  463. break;
  464. case HW_VAR_ACM_CTRL:{
  465. u8 e_aci = *((u8 *)val);
  466. union aci_aifsn *aifs = (union aci_aifsn *)(&mac->ac[0].aifs);
  467. u8 acm = aifs->f.acm;
  468. u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
  469. acm_ctrl = acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
  470. if (acm) {
  471. switch (e_aci) {
  472. case AC0_BE:
  473. acm_ctrl |= ACMHW_BEQEN;
  474. break;
  475. case AC2_VI:
  476. acm_ctrl |= ACMHW_VIQEN;
  477. break;
  478. case AC3_VO:
  479. acm_ctrl |= ACMHW_VOQEN;
  480. break;
  481. default:
  482. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  483. "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
  484. acm);
  485. break;
  486. }
  487. } else {
  488. switch (e_aci) {
  489. case AC0_BE:
  490. acm_ctrl &= (~ACMHW_BEQEN);
  491. break;
  492. case AC2_VI:
  493. acm_ctrl &= (~ACMHW_VIQEN);
  494. break;
  495. case AC3_VO:
  496. acm_ctrl &= (~ACMHW_VOQEN);
  497. break;
  498. default:
  499. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  500. "switch case not process\n");
  501. break;
  502. }
  503. }
  504. RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
  505. "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
  506. acm_ctrl);
  507. rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
  508. }
  509. break;
  510. case HW_VAR_RCR:{
  511. rtl_write_dword(rtlpriv, REG_RCR, ((u32 *)(val))[0]);
  512. rtlpci->receive_config = ((u32 *)(val))[0];
  513. }
  514. break;
  515. case HW_VAR_RETRY_LIMIT:{
  516. u8 retry_limit = ((u8 *)(val))[0];
  517. rtl_write_word(rtlpriv, REG_RETRY_LIMIT,
  518. retry_limit << RETRY_LIMIT_SHORT_SHIFT |
  519. retry_limit << RETRY_LIMIT_LONG_SHIFT);
  520. }
  521. break;
  522. case HW_VAR_DUAL_TSF_RST:
  523. rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
  524. break;
  525. case HW_VAR_EFUSE_BYTES:
  526. efuse->efuse_usedbytes = *((u16 *)val);
  527. break;
  528. case HW_VAR_EFUSE_USAGE:
  529. efuse->efuse_usedpercentage = *((u8 *)val);
  530. break;
  531. case HW_VAR_IO_CMD:
  532. rtl92ee_phy_set_io_cmd(hw, (*(enum io_type *)val));
  533. break;
  534. case HW_VAR_SET_RPWM:{
  535. u8 rpwm_val;
  536. rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
  537. udelay(1);
  538. if (rpwm_val & BIT(7)) {
  539. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, (*(u8 *)val));
  540. } else {
  541. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
  542. ((*(u8 *)val) | BIT(7)));
  543. }
  544. }
  545. break;
  546. case HW_VAR_H2C_FW_PWRMODE:
  547. rtl92ee_set_fw_pwrmode_cmd(hw, (*(u8 *)val));
  548. break;
  549. case HW_VAR_FW_PSMODE_STATUS:
  550. ppsc->fw_current_inpsmode = *((bool *)val);
  551. break;
  552. case HW_VAR_RESUME_CLK_ON:
  553. _rtl92ee_set_fw_ps_rf_on(hw);
  554. break;
  555. case HW_VAR_FW_LPS_ACTION:{
  556. bool b_enter_fwlps = *((bool *)val);
  557. if (b_enter_fwlps)
  558. _rtl92ee_fwlps_enter(hw);
  559. else
  560. _rtl92ee_fwlps_leave(hw);
  561. }
  562. break;
  563. case HW_VAR_H2C_FW_JOINBSSRPT:{
  564. u8 mstatus = (*(u8 *)val);
  565. if (mstatus == RT_MEDIA_CONNECT) {
  566. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID, NULL);
  567. _rtl92ee_download_rsvd_page(hw);
  568. }
  569. rtl92ee_set_fw_media_status_rpt_cmd(hw, mstatus);
  570. }
  571. break;
  572. case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
  573. rtl92ee_set_p2p_ps_offload_cmd(hw, (*(u8 *)val));
  574. break;
  575. case HW_VAR_AID:{
  576. u16 u2btmp;
  577. u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
  578. u2btmp &= 0xC000;
  579. rtl_write_word(rtlpriv, REG_BCN_PSR_RPT,
  580. (u2btmp | mac->assoc_id));
  581. }
  582. break;
  583. case HW_VAR_CORRECT_TSF:{
  584. u8 btype_ibss = ((u8 *)(val))[0];
  585. if (btype_ibss)
  586. _rtl92ee_stop_tx_beacon(hw);
  587. _rtl92ee_set_bcn_ctrl_reg(hw, 0, BIT(3));
  588. rtl_write_dword(rtlpriv, REG_TSFTR,
  589. (u32)(mac->tsf & 0xffffffff));
  590. rtl_write_dword(rtlpriv, REG_TSFTR + 4,
  591. (u32)((mac->tsf >> 32) & 0xffffffff));
  592. _rtl92ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  593. if (btype_ibss)
  594. _rtl92ee_resume_tx_beacon(hw);
  595. }
  596. break;
  597. case HW_VAR_KEEP_ALIVE: {
  598. u8 array[2];
  599. array[0] = 0xff;
  600. array[1] = *((u8 *)val);
  601. rtl92ee_fill_h2c_cmd(hw, H2C_92E_KEEP_ALIVE_CTRL, 2, array);
  602. }
  603. break;
  604. default:
  605. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  606. "switch case not process %x\n", variable);
  607. break;
  608. }
  609. }
  610. static bool _rtl92ee_llt_table_init(struct ieee80211_hw *hw)
  611. {
  612. struct rtl_priv *rtlpriv = rtl_priv(hw);
  613. u8 txpktbuf_bndy;
  614. u8 u8tmp, testcnt = 0;
  615. txpktbuf_bndy = 0xFA;
  616. rtl_write_dword(rtlpriv, REG_RQPN, 0x80E90808);
  617. rtl_write_byte(rtlpriv, REG_TRXFF_BNDY, txpktbuf_bndy);
  618. rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x3d00 - 1);
  619. rtl_write_byte(rtlpriv, REG_DWBCN0_CTRL + 1, txpktbuf_bndy);
  620. rtl_write_byte(rtlpriv, REG_DWBCN1_CTRL + 1, txpktbuf_bndy);
  621. rtl_write_byte(rtlpriv, REG_BCNQ_BDNY, txpktbuf_bndy);
  622. rtl_write_byte(rtlpriv, REG_BCNQ1_BDNY, txpktbuf_bndy);
  623. rtl_write_byte(rtlpriv, REG_MGQ_BDNY, txpktbuf_bndy);
  624. rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
  625. rtl_write_byte(rtlpriv, REG_PBP, 0x31);
  626. rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
  627. u8tmp = rtl_read_byte(rtlpriv, REG_AUTO_LLT + 2);
  628. rtl_write_byte(rtlpriv, REG_AUTO_LLT + 2, u8tmp | BIT(0));
  629. while (u8tmp & BIT(0)) {
  630. u8tmp = rtl_read_byte(rtlpriv, REG_AUTO_LLT + 2);
  631. udelay(10);
  632. testcnt++;
  633. if (testcnt > 10)
  634. break;
  635. }
  636. return true;
  637. }
  638. static void _rtl92ee_gen_refresh_led_state(struct ieee80211_hw *hw)
  639. {
  640. struct rtl_priv *rtlpriv = rtl_priv(hw);
  641. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  642. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  643. struct rtl_led *pled0 = &pcipriv->ledctl.sw_led0;
  644. if (rtlpriv->rtlhal.up_first_time)
  645. return;
  646. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
  647. rtl92ee_sw_led_on(hw, pled0);
  648. else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
  649. rtl92ee_sw_led_on(hw, pled0);
  650. else
  651. rtl92ee_sw_led_off(hw, pled0);
  652. }
  653. static bool _rtl92ee_init_mac(struct ieee80211_hw *hw)
  654. {
  655. struct rtl_priv *rtlpriv = rtl_priv(hw);
  656. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  657. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  658. u8 bytetmp;
  659. u16 wordtmp;
  660. u32 dwordtmp;
  661. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0);
  662. dwordtmp = rtl_read_dword(rtlpriv, REG_SYS_CFG1);
  663. if (dwordtmp & BIT(24)) {
  664. rtl_write_byte(rtlpriv, 0x7c, 0xc3);
  665. } else {
  666. bytetmp = rtl_read_byte(rtlpriv, 0x16);
  667. rtl_write_byte(rtlpriv, 0x16, bytetmp | BIT(4) | BIT(6));
  668. rtl_write_byte(rtlpriv, 0x7c, 0x83);
  669. }
  670. /* 1. 40Mhz crystal source*/
  671. bytetmp = rtl_read_byte(rtlpriv, REG_AFE_CTRL2);
  672. bytetmp &= 0xfb;
  673. rtl_write_byte(rtlpriv, REG_AFE_CTRL2, bytetmp);
  674. dwordtmp = rtl_read_dword(rtlpriv, REG_AFE_CTRL4);
  675. dwordtmp &= 0xfffffc7f;
  676. rtl_write_dword(rtlpriv, REG_AFE_CTRL4, dwordtmp);
  677. /* 2. 92E AFE parameter
  678. * MP chip then check version
  679. */
  680. bytetmp = rtl_read_byte(rtlpriv, REG_AFE_CTRL2);
  681. bytetmp &= 0xbf;
  682. rtl_write_byte(rtlpriv, REG_AFE_CTRL2, bytetmp);
  683. dwordtmp = rtl_read_dword(rtlpriv, REG_AFE_CTRL4);
  684. dwordtmp &= 0xffdfffff;
  685. rtl_write_dword(rtlpriv, REG_AFE_CTRL4, dwordtmp);
  686. /* HW Power on sequence */
  687. if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  688. PWR_INTF_PCI_MSK,
  689. RTL8192E_NIC_ENABLE_FLOW)) {
  690. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  691. "init MAC Fail as rtl_hal_pwrseqcmdparsing\n");
  692. return false;
  693. }
  694. /* Release MAC IO register reset */
  695. bytetmp = rtl_read_byte(rtlpriv, REG_CR);
  696. bytetmp = 0xff;
  697. rtl_write_byte(rtlpriv, REG_CR, bytetmp);
  698. mdelay(2);
  699. bytetmp = 0x7f;
  700. rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, bytetmp);
  701. mdelay(2);
  702. /* Add for wakeup online */
  703. bytetmp = rtl_read_byte(rtlpriv, REG_SYS_CLKR);
  704. rtl_write_byte(rtlpriv, REG_SYS_CLKR, bytetmp | BIT(3));
  705. bytetmp = rtl_read_byte(rtlpriv, REG_GPIO_MUXCFG + 1);
  706. rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG + 1, bytetmp & (~BIT(4)));
  707. /* Release MAC IO register reset */
  708. rtl_write_word(rtlpriv, REG_CR, 0x2ff);
  709. if (!rtlhal->mac_func_enable) {
  710. if (_rtl92ee_llt_table_init(hw) == false) {
  711. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  712. "LLT table init fail\n");
  713. return false;
  714. }
  715. }
  716. rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
  717. rtl_write_dword(rtlpriv, REG_HISRE, 0xffffffff);
  718. wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
  719. wordtmp &= 0xf;
  720. wordtmp |= 0xF5B1;
  721. rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
  722. /* Reported Tx status from HW for rate adaptive.*/
  723. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
  724. /* Set RCR register */
  725. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  726. rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xffff);
  727. /* Set TCR register */
  728. rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
  729. /* Set TX/RX descriptor physical address(from OS API). */
  730. rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
  731. ((u64)rtlpci->tx_ring[BEACON_QUEUE].buffer_desc_dma) &
  732. DMA_BIT_MASK(32));
  733. rtl_write_dword(rtlpriv, REG_MGQ_DESA,
  734. (u64)rtlpci->tx_ring[MGNT_QUEUE].buffer_desc_dma &
  735. DMA_BIT_MASK(32));
  736. rtl_write_dword(rtlpriv, REG_VOQ_DESA,
  737. (u64)rtlpci->tx_ring[VO_QUEUE].buffer_desc_dma &
  738. DMA_BIT_MASK(32));
  739. rtl_write_dword(rtlpriv, REG_VIQ_DESA,
  740. (u64)rtlpci->tx_ring[VI_QUEUE].buffer_desc_dma &
  741. DMA_BIT_MASK(32));
  742. rtl_write_dword(rtlpriv, REG_BEQ_DESA,
  743. (u64)rtlpci->tx_ring[BE_QUEUE].buffer_desc_dma &
  744. DMA_BIT_MASK(32));
  745. dwordtmp = rtl_read_dword(rtlpriv, REG_BEQ_DESA);
  746. rtl_write_dword(rtlpriv, REG_BKQ_DESA,
  747. (u64)rtlpci->tx_ring[BK_QUEUE].buffer_desc_dma &
  748. DMA_BIT_MASK(32));
  749. rtl_write_dword(rtlpriv, REG_HQ0_DESA,
  750. (u64)rtlpci->tx_ring[HIGH_QUEUE].buffer_desc_dma &
  751. DMA_BIT_MASK(32));
  752. rtl_write_dword(rtlpriv, REG_RX_DESA,
  753. (u64)rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
  754. DMA_BIT_MASK(32));
  755. /* if we want to support 64 bit DMA, we should set it here,
  756. * but now we do not support 64 bit DMA
  757. */
  758. rtl_write_dword(rtlpriv, REG_TSFTIMER_HCI, 0x3fffffff);
  759. bytetmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG + 3);
  760. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, bytetmp | 0xF7);
  761. rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
  762. rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
  763. rtl_write_word(rtlpriv, REG_MGQ_TXBD_NUM,
  764. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  765. rtl_write_word(rtlpriv, REG_VOQ_TXBD_NUM,
  766. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  767. rtl_write_word(rtlpriv, REG_VIQ_TXBD_NUM,
  768. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  769. rtl_write_word(rtlpriv, REG_BEQ_TXBD_NUM,
  770. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  771. rtl_write_word(rtlpriv, REG_VOQ_TXBD_NUM,
  772. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  773. rtl_write_word(rtlpriv, REG_BKQ_TXBD_NUM,
  774. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  775. rtl_write_word(rtlpriv, REG_HI0Q_TXBD_NUM,
  776. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  777. rtl_write_word(rtlpriv, REG_HI1Q_TXBD_NUM,
  778. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  779. rtl_write_word(rtlpriv, REG_HI2Q_TXBD_NUM,
  780. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  781. rtl_write_word(rtlpriv, REG_HI3Q_TXBD_NUM,
  782. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  783. rtl_write_word(rtlpriv, REG_HI4Q_TXBD_NUM,
  784. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  785. rtl_write_word(rtlpriv, REG_HI5Q_TXBD_NUM,
  786. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  787. rtl_write_word(rtlpriv, REG_HI6Q_TXBD_NUM,
  788. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  789. rtl_write_word(rtlpriv, REG_HI7Q_TXBD_NUM,
  790. TX_DESC_NUM_92E | ((RTL8192EE_SEG_NUM << 12) & 0x3000));
  791. /*Rx*/
  792. #if (DMA_IS_64BIT == 1)
  793. rtl_write_word(rtlpriv, REG_RX_RXBD_NUM,
  794. RX_DESC_NUM_92E |
  795. ((RTL8192EE_SEG_NUM << 13) & 0x6000) | 0x8000);
  796. #else
  797. rtl_write_word(rtlpriv, REG_RX_RXBD_NUM,
  798. RX_DESC_NUM_92E |
  799. ((RTL8192EE_SEG_NUM << 13) & 0x6000) | 0x0000);
  800. #endif
  801. rtl_write_dword(rtlpriv, REG_TSFTIMER_HCI, 0XFFFFFFFF);
  802. _rtl92ee_gen_refresh_led_state(hw);
  803. return true;
  804. }
  805. static void _rtl92ee_hw_configure(struct ieee80211_hw *hw)
  806. {
  807. struct rtl_priv *rtlpriv = rtl_priv(hw);
  808. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  809. u32 reg_rrsr;
  810. reg_rrsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  811. /* Init value for RRSR. */
  812. rtl_write_dword(rtlpriv, REG_RRSR, reg_rrsr);
  813. /* ARFB table 9 for 11ac 5G 2SS */
  814. rtl_write_dword(rtlpriv, REG_ARFR0, 0x00000010);
  815. rtl_write_dword(rtlpriv, REG_ARFR0 + 4, 0x3e0ff000);
  816. /* ARFB table 10 for 11ac 5G 1SS */
  817. rtl_write_dword(rtlpriv, REG_ARFR1, 0x00000010);
  818. rtl_write_dword(rtlpriv, REG_ARFR1 + 4, 0x000ff000);
  819. /* Set SLOT time */
  820. rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
  821. /* CF-End setting. */
  822. rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
  823. /* Set retry limit */
  824. rtl_write_word(rtlpriv, REG_RETRY_LIMIT, 0x0707);
  825. /* BAR settings */
  826. rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x0201ffff);
  827. /* Set Data / Response auto rate fallack retry count */
  828. rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
  829. rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
  830. rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
  831. rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
  832. /* Beacon related, for rate adaptive */
  833. rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
  834. rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
  835. rtlpci->reg_bcn_ctrl_val = 0x1d;
  836. rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
  837. /* Marked out by Bruce, 2010-09-09.
  838. * This register is configured for the 2nd Beacon (multiple BSSID).
  839. * We shall disable this register if we only support 1 BSSID.
  840. * vivi guess 92d also need this, also 92d now doesnot set this reg
  841. */
  842. rtl_write_byte(rtlpriv, REG_BCN_CTRL_1, 0);
  843. /* TBTT prohibit hold time. Suggested by designer TimChen. */
  844. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff); /* 8 ms */
  845. rtl_write_byte(rtlpriv, REG_PIFS, 0);
  846. rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
  847. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0040);
  848. rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x08ff);
  849. /* For Rx TP. Suggested by SD1 Richard. Added by tynli. 2010.04.12.*/
  850. rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
  851. /* ACKTO for IOT issue. */
  852. rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
  853. /* Set Spec SIFS (used in NAV) */
  854. rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x100a);
  855. rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x100a);
  856. /* Set SIFS for CCK */
  857. rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x100a);
  858. /* Set SIFS for OFDM */
  859. rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x100a);
  860. /* Note Data sheet don't define */
  861. rtl_write_word(rtlpriv, 0x4C7, 0x80);
  862. rtl_write_byte(rtlpriv, REG_RX_PKT_LIMIT, 0x20);
  863. rtl_write_word(rtlpriv, REG_MAX_AGGR_NUM, 0x1717);
  864. /* Set Multicast Address. 2009.01.07. by tynli. */
  865. rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
  866. rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
  867. }
  868. static void _rtl92ee_enable_aspm_back_door(struct ieee80211_hw *hw)
  869. {
  870. struct rtl_priv *rtlpriv = rtl_priv(hw);
  871. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  872. u32 tmp32 = 0, count = 0;
  873. u8 tmp8 = 0;
  874. rtl_write_word(rtlpriv, REG_BACKDOOR_DBI_DATA, 0x78);
  875. rtl_write_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2, 0x2);
  876. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  877. count = 0;
  878. while (tmp8 && count < 20) {
  879. udelay(10);
  880. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  881. count++;
  882. }
  883. if (0 == tmp8) {
  884. tmp32 = rtl_read_dword(rtlpriv, REG_BACKDOOR_DBI_RDATA);
  885. if ((tmp32 & 0xff00) != 0x2000) {
  886. tmp32 &= 0xffff00ff;
  887. rtl_write_dword(rtlpriv, REG_BACKDOOR_DBI_WDATA,
  888. tmp32 | BIT(13));
  889. rtl_write_word(rtlpriv, REG_BACKDOOR_DBI_DATA, 0xf078);
  890. rtl_write_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2, 0x1);
  891. tmp8 = rtl_read_byte(rtlpriv,
  892. REG_BACKDOOR_DBI_DATA + 2);
  893. count = 0;
  894. while (tmp8 && count < 20) {
  895. udelay(10);
  896. tmp8 = rtl_read_byte(rtlpriv,
  897. REG_BACKDOOR_DBI_DATA + 2);
  898. count++;
  899. }
  900. }
  901. }
  902. rtl_write_word(rtlpriv, REG_BACKDOOR_DBI_DATA, 0x70c);
  903. rtl_write_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2, 0x2);
  904. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  905. count = 0;
  906. while (tmp8 && count < 20) {
  907. udelay(10);
  908. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  909. count++;
  910. }
  911. if (0 == tmp8) {
  912. tmp32 = rtl_read_dword(rtlpriv, REG_BACKDOOR_DBI_RDATA);
  913. rtl_write_dword(rtlpriv, REG_BACKDOOR_DBI_WDATA,
  914. tmp32 | BIT(31));
  915. rtl_write_word(rtlpriv, REG_BACKDOOR_DBI_DATA, 0xf70c);
  916. rtl_write_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2, 0x1);
  917. }
  918. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  919. count = 0;
  920. while (tmp8 && count < 20) {
  921. udelay(10);
  922. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  923. count++;
  924. }
  925. rtl_write_word(rtlpriv, REG_BACKDOOR_DBI_DATA, 0x718);
  926. rtl_write_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2, 0x2);
  927. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  928. count = 0;
  929. while (tmp8 && count < 20) {
  930. udelay(10);
  931. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  932. count++;
  933. }
  934. if (ppsc->support_backdoor || (0 == tmp8)) {
  935. tmp32 = rtl_read_dword(rtlpriv, REG_BACKDOOR_DBI_RDATA);
  936. rtl_write_dword(rtlpriv, REG_BACKDOOR_DBI_WDATA,
  937. tmp32 | BIT(11) | BIT(12));
  938. rtl_write_word(rtlpriv, REG_BACKDOOR_DBI_DATA, 0xf718);
  939. rtl_write_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2, 0x1);
  940. }
  941. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  942. count = 0;
  943. while (tmp8 && count < 20) {
  944. udelay(10);
  945. tmp8 = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 2);
  946. count++;
  947. }
  948. }
  949. void rtl92ee_enable_hw_security_config(struct ieee80211_hw *hw)
  950. {
  951. struct rtl_priv *rtlpriv = rtl_priv(hw);
  952. u8 sec_reg_value;
  953. u8 tmp;
  954. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  955. "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
  956. rtlpriv->sec.pairwise_enc_algorithm,
  957. rtlpriv->sec.group_enc_algorithm);
  958. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  959. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  960. "not open hw encryption\n");
  961. return;
  962. }
  963. sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE;
  964. if (rtlpriv->sec.use_defaultkey) {
  965. sec_reg_value |= SCR_TXUSEDK;
  966. sec_reg_value |= SCR_RXUSEDK;
  967. }
  968. sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
  969. tmp = rtl_read_byte(rtlpriv, REG_CR + 1);
  970. rtl_write_byte(rtlpriv, REG_CR + 1, tmp | BIT(1));
  971. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  972. "The SECR-value %x\n", sec_reg_value);
  973. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
  974. }
  975. static bool _rtl8192ee_check_pcie_dma_hang(struct rtl_priv *rtlpriv)
  976. {
  977. u8 tmp;
  978. /* write reg 0x350 Bit[26]=1. Enable debug port. */
  979. tmp = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 3);
  980. if (!(tmp & BIT(2))) {
  981. rtl_write_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 3,
  982. tmp | BIT(2));
  983. mdelay(100); /* Suggested by DD Justin_tsai. */
  984. }
  985. /* read reg 0x350 Bit[25] if 1 : RX hang
  986. * read reg 0x350 Bit[24] if 1 : TX hang
  987. */
  988. tmp = rtl_read_byte(rtlpriv, REG_BACKDOOR_DBI_DATA + 3);
  989. if ((tmp & BIT(0)) || (tmp & BIT(1))) {
  990. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  991. "CheckPcieDMAHang8192EE(): true!!\n");
  992. return true;
  993. }
  994. return false;
  995. }
  996. static void _rtl8192ee_reset_pcie_interface_dma(struct rtl_priv *rtlpriv,
  997. bool mac_power_on)
  998. {
  999. u8 tmp;
  1000. bool release_mac_rx_pause;
  1001. u8 backup_pcie_dma_pause;
  1002. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1003. "ResetPcieInterfaceDMA8192EE()\n");
  1004. /* Revise Note: Follow the document "PCIe RX DMA Hang Reset Flow_v03"
  1005. * released by SD1 Alan.
  1006. */
  1007. /* 1. disable register write lock
  1008. * write 0x1C bit[1:0] = 2'h0
  1009. * write 0xCC bit[2] = 1'b1
  1010. */
  1011. tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL);
  1012. tmp &= ~(BIT(1) | BIT(0));
  1013. rtl_write_byte(rtlpriv, REG_RSV_CTRL, tmp);
  1014. tmp = rtl_read_byte(rtlpriv, REG_PMC_DBG_CTRL2);
  1015. tmp |= BIT(2);
  1016. rtl_write_byte(rtlpriv, REG_PMC_DBG_CTRL2, tmp);
  1017. /* 2. Check and pause TRX DMA
  1018. * write 0x284 bit[18] = 1'b1
  1019. * write 0x301 = 0xFF
  1020. */
  1021. tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
  1022. if (tmp & BIT(2)) {
  1023. /* Already pause before the function for another reason. */
  1024. release_mac_rx_pause = false;
  1025. } else {
  1026. rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL, (tmp | BIT(2)));
  1027. release_mac_rx_pause = true;
  1028. }
  1029. backup_pcie_dma_pause = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG + 1);
  1030. if (backup_pcie_dma_pause != 0xFF)
  1031. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0xFF);
  1032. if (mac_power_on) {
  1033. /* 3. reset TRX function
  1034. * write 0x100 = 0x00
  1035. */
  1036. rtl_write_byte(rtlpriv, REG_CR, 0);
  1037. }
  1038. /* 4. Reset PCIe DMA
  1039. * write 0x003 bit[0] = 0
  1040. */
  1041. tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  1042. tmp &= ~(BIT(0));
  1043. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmp);
  1044. /* 5. Enable PCIe DMA
  1045. * write 0x003 bit[0] = 1
  1046. */
  1047. tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  1048. tmp |= BIT(0);
  1049. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmp);
  1050. if (mac_power_on) {
  1051. /* 6. enable TRX function
  1052. * write 0x100 = 0xFF
  1053. */
  1054. rtl_write_byte(rtlpriv, REG_CR, 0xFF);
  1055. /* We should init LLT & RQPN and
  1056. * prepare Tx/Rx descrptor address later
  1057. * because MAC function is reset.
  1058. */
  1059. }
  1060. /* 7. Restore PCIe autoload down bit
  1061. * write 0xF8 bit[17] = 1'b1
  1062. */
  1063. tmp = rtl_read_byte(rtlpriv, REG_MAC_PHY_CTRL_NORMAL + 2);
  1064. tmp |= BIT(1);
  1065. rtl_write_byte(rtlpriv, REG_MAC_PHY_CTRL_NORMAL + 2, tmp);
  1066. /* In MAC power on state, BB and RF maybe in ON state,
  1067. * if we release TRx DMA here
  1068. * it will cause packets to be started to Tx/Rx,
  1069. * so we release Tx/Rx DMA later.
  1070. */
  1071. if (!mac_power_on) {
  1072. /* 8. release TRX DMA
  1073. * write 0x284 bit[18] = 1'b0
  1074. * write 0x301 = 0x00
  1075. */
  1076. if (release_mac_rx_pause) {
  1077. tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
  1078. rtl_write_byte(rtlpriv, REG_RXDMA_CONTROL,
  1079. (tmp & (~BIT(2))));
  1080. }
  1081. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1,
  1082. backup_pcie_dma_pause);
  1083. }
  1084. /* 9. lock system register
  1085. * write 0xCC bit[2] = 1'b0
  1086. */
  1087. tmp = rtl_read_byte(rtlpriv, REG_PMC_DBG_CTRL2);
  1088. tmp &= ~(BIT(2));
  1089. rtl_write_byte(rtlpriv, REG_PMC_DBG_CTRL2, tmp);
  1090. }
  1091. int rtl92ee_hw_init(struct ieee80211_hw *hw)
  1092. {
  1093. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1094. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1095. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1096. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1097. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1098. bool rtstatus = true;
  1099. int err = 0;
  1100. u8 tmp_u1b, u1byte;
  1101. u32 tmp_u4b;
  1102. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, " Rtl8192EE hw init\n");
  1103. rtlpriv->rtlhal.being_init_adapter = true;
  1104. rtlpriv->intf_ops->disable_aspm(hw);
  1105. tmp_u1b = rtl_read_byte(rtlpriv, REG_SYS_CLKR+1);
  1106. u1byte = rtl_read_byte(rtlpriv, REG_CR);
  1107. if ((tmp_u1b & BIT(3)) && (u1byte != 0 && u1byte != 0xEA)) {
  1108. rtlhal->mac_func_enable = true;
  1109. } else {
  1110. rtlhal->mac_func_enable = false;
  1111. rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_92E;
  1112. }
  1113. if (_rtl8192ee_check_pcie_dma_hang(rtlpriv)) {
  1114. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "92ee dma hang!\n");
  1115. _rtl8192ee_reset_pcie_interface_dma(rtlpriv,
  1116. rtlhal->mac_func_enable);
  1117. rtlhal->mac_func_enable = false;
  1118. }
  1119. rtstatus = _rtl92ee_init_mac(hw);
  1120. rtl_write_byte(rtlpriv, 0x577, 0x03);
  1121. /*for Crystal 40 Mhz setting */
  1122. rtl_write_byte(rtlpriv, REG_AFE_CTRL4, 0x2A);
  1123. rtl_write_byte(rtlpriv, REG_AFE_CTRL4 + 1, 0x00);
  1124. rtl_write_byte(rtlpriv, REG_AFE_CTRL2, 0x83);
  1125. /*Forced the antenna b to wifi */
  1126. if (rtlpriv->btcoexist.btc_info.btcoexist == 1) {
  1127. rtl_write_byte(rtlpriv, 0x64, 0);
  1128. rtl_write_byte(rtlpriv, 0x65, 1);
  1129. }
  1130. if (!rtstatus) {
  1131. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n");
  1132. err = 1;
  1133. return err;
  1134. }
  1135. rtlhal->rx_tag = 0;
  1136. rtl_write_word(rtlpriv, REG_PCIE_CTRL_REG, 0x8000);
  1137. err = rtl92ee_download_fw(hw, false);
  1138. if (err) {
  1139. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1140. "Failed to download FW. Init HW without FW now..\n");
  1141. err = 1;
  1142. rtlhal->fw_ready = false;
  1143. return err;
  1144. }
  1145. rtlhal->fw_ready = true;
  1146. /*fw related variable initialize */
  1147. ppsc->fw_current_inpsmode = false;
  1148. rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_92E;
  1149. rtlhal->fw_clk_change_in_progress = false;
  1150. rtlhal->allow_sw_to_change_hwclc = false;
  1151. rtlhal->last_hmeboxnum = 0;
  1152. rtl92ee_phy_mac_config(hw);
  1153. rtl92ee_phy_bb_config(hw);
  1154. rtl92ee_phy_rf_config(hw);
  1155. rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, RF90_PATH_A,
  1156. RF_CHNLBW, RFREG_OFFSET_MASK);
  1157. rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, RF90_PATH_B,
  1158. RF_CHNLBW, RFREG_OFFSET_MASK);
  1159. rtlphy->backup_rf_0x1a = (u32)rtl_get_rfreg(hw, RF90_PATH_A, RF_RX_G1,
  1160. RFREG_OFFSET_MASK);
  1161. rtlphy->rfreg_chnlval[0] = (rtlphy->rfreg_chnlval[0] & 0xfffff3ff) |
  1162. BIT(10) | BIT(11);
  1163. rtl_set_rfreg(hw, RF90_PATH_A, RF_CHNLBW, RFREG_OFFSET_MASK,
  1164. rtlphy->rfreg_chnlval[0]);
  1165. rtl_set_rfreg(hw, RF90_PATH_B, RF_CHNLBW, RFREG_OFFSET_MASK,
  1166. rtlphy->rfreg_chnlval[0]);
  1167. /*---- Set CCK and OFDM Block "ON"----*/
  1168. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  1169. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  1170. /* Must set this,
  1171. * otherwise the rx sensitivity will be very pool. Maddest
  1172. */
  1173. rtl_set_rfreg(hw, RF90_PATH_A, 0xB1, RFREG_OFFSET_MASK, 0x54418);
  1174. /*Set Hardware(MAC default setting.)*/
  1175. _rtl92ee_hw_configure(hw);
  1176. rtlhal->mac_func_enable = true;
  1177. rtl_cam_reset_all_entry(hw);
  1178. rtl92ee_enable_hw_security_config(hw);
  1179. ppsc->rfpwr_state = ERFON;
  1180. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  1181. _rtl92ee_enable_aspm_back_door(hw);
  1182. rtlpriv->intf_ops->enable_aspm(hw);
  1183. rtl92ee_bt_hw_init(hw);
  1184. rtlpriv->rtlhal.being_init_adapter = false;
  1185. if (ppsc->rfpwr_state == ERFON) {
  1186. if (rtlphy->iqk_initialized) {
  1187. rtl92ee_phy_iq_calibrate(hw, true);
  1188. } else {
  1189. rtl92ee_phy_iq_calibrate(hw, false);
  1190. rtlphy->iqk_initialized = true;
  1191. }
  1192. }
  1193. rtlphy->rfpath_rx_enable[0] = true;
  1194. if (rtlphy->rf_type == RF_2T2R)
  1195. rtlphy->rfpath_rx_enable[1] = true;
  1196. efuse_one_byte_read(hw, 0x1FA, &tmp_u1b);
  1197. if (!(tmp_u1b & BIT(0))) {
  1198. rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
  1199. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "PA BIAS path A\n");
  1200. }
  1201. if ((!(tmp_u1b & BIT(1))) && (rtlphy->rf_type == RF_2T2R)) {
  1202. rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0F, 0x05);
  1203. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "PA BIAS path B\n");
  1204. }
  1205. rtl_write_byte(rtlpriv, REG_NAV_UPPER, ((30000 + 127) / 128));
  1206. /*Fixed LDPC rx hang issue. */
  1207. tmp_u4b = rtl_read_dword(rtlpriv, REG_SYS_SWR_CTRL1);
  1208. rtl_write_byte(rtlpriv, REG_SYS_SWR_CTRL2, 0x75);
  1209. tmp_u4b = (tmp_u4b & 0xfff00fff) | (0x7E << 12);
  1210. rtl_write_dword(rtlpriv, REG_SYS_SWR_CTRL1, tmp_u4b);
  1211. rtl92ee_dm_init(hw);
  1212. rtl_write_dword(rtlpriv, 0x4fc, 0);
  1213. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1214. "end of Rtl8192EE hw init %x\n", err);
  1215. return 0;
  1216. }
  1217. static enum version_8192e _rtl92ee_read_chip_version(struct ieee80211_hw *hw)
  1218. {
  1219. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1220. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1221. enum version_8192e version = VERSION_UNKNOWN;
  1222. u32 value32;
  1223. rtlphy->rf_type = RF_2T2R;
  1224. value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG1);
  1225. if (value32 & TRP_VAUX_EN)
  1226. version = (enum version_8192e)VERSION_TEST_CHIP_2T2R_8192E;
  1227. else
  1228. version = (enum version_8192e)VERSION_NORMAL_CHIP_2T2R_8192E;
  1229. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1230. "Chip RF Type: %s\n", (rtlphy->rf_type == RF_2T2R) ?
  1231. "RF_2T2R" : "RF_1T1R");
  1232. return version;
  1233. }
  1234. static int _rtl92ee_set_media_status(struct ieee80211_hw *hw,
  1235. enum nl80211_iftype type)
  1236. {
  1237. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1238. u8 bt_msr = rtl_read_byte(rtlpriv, MSR) & 0xfc;
  1239. enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
  1240. u8 mode = MSR_NOLINK;
  1241. switch (type) {
  1242. case NL80211_IFTYPE_UNSPECIFIED:
  1243. mode = MSR_NOLINK;
  1244. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1245. "Set Network type to NO LINK!\n");
  1246. break;
  1247. case NL80211_IFTYPE_ADHOC:
  1248. case NL80211_IFTYPE_MESH_POINT:
  1249. mode = MSR_ADHOC;
  1250. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1251. "Set Network type to Ad Hoc!\n");
  1252. break;
  1253. case NL80211_IFTYPE_STATION:
  1254. mode = MSR_INFRA;
  1255. ledaction = LED_CTL_LINK;
  1256. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1257. "Set Network type to STA!\n");
  1258. break;
  1259. case NL80211_IFTYPE_AP:
  1260. mode = MSR_AP;
  1261. ledaction = LED_CTL_LINK;
  1262. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1263. "Set Network type to AP!\n");
  1264. break;
  1265. default:
  1266. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1267. "Network type %d not support!\n", type);
  1268. return 1;
  1269. }
  1270. /* MSR_INFRA == Link in infrastructure network;
  1271. * MSR_ADHOC == Link in ad hoc network;
  1272. * Therefore, check link state is necessary.
  1273. *
  1274. * MSR_AP == AP mode; link state is not cared here.
  1275. */
  1276. if (mode != MSR_AP && rtlpriv->mac80211.link_state < MAC80211_LINKED) {
  1277. mode = MSR_NOLINK;
  1278. ledaction = LED_CTL_NO_LINK;
  1279. }
  1280. if (mode == MSR_NOLINK || mode == MSR_INFRA) {
  1281. _rtl92ee_stop_tx_beacon(hw);
  1282. _rtl92ee_enable_bcn_sub_func(hw);
  1283. } else if (mode == MSR_ADHOC || mode == MSR_AP) {
  1284. _rtl92ee_resume_tx_beacon(hw);
  1285. _rtl92ee_disable_bcn_sub_func(hw);
  1286. } else {
  1287. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1288. "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
  1289. mode);
  1290. }
  1291. rtl_write_byte(rtlpriv, MSR, bt_msr | mode);
  1292. rtlpriv->cfg->ops->led_control(hw, ledaction);
  1293. if (mode == MSR_AP)
  1294. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
  1295. else
  1296. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
  1297. return 0;
  1298. }
  1299. void rtl92ee_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
  1300. {
  1301. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1302. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1303. u32 reg_rcr = rtlpci->receive_config;
  1304. if (rtlpriv->psc.rfpwr_state != ERFON)
  1305. return;
  1306. if (check_bssid) {
  1307. reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
  1308. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
  1309. (u8 *)(&reg_rcr));
  1310. _rtl92ee_set_bcn_ctrl_reg(hw, 0, BIT(4));
  1311. } else {
  1312. reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
  1313. _rtl92ee_set_bcn_ctrl_reg(hw, BIT(4), 0);
  1314. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
  1315. (u8 *)(&reg_rcr));
  1316. }
  1317. }
  1318. int rtl92ee_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
  1319. {
  1320. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1321. if (_rtl92ee_set_media_status(hw, type))
  1322. return -EOPNOTSUPP;
  1323. if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
  1324. if (type != NL80211_IFTYPE_AP &&
  1325. type != NL80211_IFTYPE_MESH_POINT)
  1326. rtl92ee_set_check_bssid(hw, true);
  1327. } else {
  1328. rtl92ee_set_check_bssid(hw, false);
  1329. }
  1330. return 0;
  1331. }
  1332. /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
  1333. void rtl92ee_set_qos(struct ieee80211_hw *hw, int aci)
  1334. {
  1335. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1336. rtl92ee_dm_init_edca_turbo(hw);
  1337. switch (aci) {
  1338. case AC1_BK:
  1339. rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
  1340. break;
  1341. case AC0_BE:
  1342. /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
  1343. break;
  1344. case AC2_VI:
  1345. rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
  1346. break;
  1347. case AC3_VO:
  1348. rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
  1349. break;
  1350. default:
  1351. RT_ASSERT(false, "invalid aci: %d !\n", aci);
  1352. break;
  1353. }
  1354. }
  1355. void rtl92ee_enable_interrupt(struct ieee80211_hw *hw)
  1356. {
  1357. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1358. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1359. rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF);
  1360. rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF);
  1361. rtlpci->irq_enabled = true;
  1362. }
  1363. void rtl92ee_disable_interrupt(struct ieee80211_hw *hw)
  1364. {
  1365. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1366. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1367. rtl_write_dword(rtlpriv, REG_HIMR, IMR_DISABLED);
  1368. rtl_write_dword(rtlpriv, REG_HIMRE, IMR_DISABLED);
  1369. rtlpci->irq_enabled = false;
  1370. /*synchronize_irq(rtlpci->pdev->irq);*/
  1371. }
  1372. static void _rtl92ee_poweroff_adapter(struct ieee80211_hw *hw)
  1373. {
  1374. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1375. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1376. u8 u1b_tmp;
  1377. rtlhal->mac_func_enable = false;
  1378. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "POWER OFF adapter\n");
  1379. /* Run LPS WL RFOFF flow */
  1380. rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  1381. PWR_INTF_PCI_MSK, RTL8192E_NIC_LPS_ENTER_FLOW);
  1382. /* turn off RF */
  1383. rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
  1384. /* ==== Reset digital sequence ====== */
  1385. if ((rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) && rtlhal->fw_ready)
  1386. rtl92ee_firmware_selfreset(hw);
  1387. /* Reset MCU */
  1388. u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  1389. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, (u1b_tmp & (~BIT(2))));
  1390. /* reset MCU ready status */
  1391. rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
  1392. /* HW card disable configuration. */
  1393. rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  1394. PWR_INTF_PCI_MSK, RTL8192E_NIC_DISABLE_FLOW);
  1395. /* Reset MCU IO Wrapper */
  1396. u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
  1397. rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp & (~BIT(0))));
  1398. u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
  1399. rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp | BIT(0)));
  1400. /* lock ISO/CLK/Power control register */
  1401. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0E);
  1402. }
  1403. void rtl92ee_card_disable(struct ieee80211_hw *hw)
  1404. {
  1405. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1406. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1407. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1408. enum nl80211_iftype opmode;
  1409. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "RTL8192ee card disable\n");
  1410. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1411. mac->link_state = MAC80211_NOLINK;
  1412. opmode = NL80211_IFTYPE_UNSPECIFIED;
  1413. _rtl92ee_set_media_status(hw, opmode);
  1414. if (rtlpriv->rtlhal.driver_is_goingto_unload ||
  1415. ppsc->rfoff_reason > RF_CHANGE_BY_PS)
  1416. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1417. _rtl92ee_poweroff_adapter(hw);
  1418. /* after power off we should do iqk again */
  1419. rtlpriv->phy.iqk_initialized = false;
  1420. }
  1421. void rtl92ee_interrupt_recognized(struct ieee80211_hw *hw,
  1422. u32 *p_inta, u32 *p_intb)
  1423. {
  1424. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1425. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1426. *p_inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
  1427. rtl_write_dword(rtlpriv, ISR, *p_inta);
  1428. *p_intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1];
  1429. rtl_write_dword(rtlpriv, REG_HISRE, *p_intb);
  1430. }
  1431. void rtl92ee_set_beacon_related_registers(struct ieee80211_hw *hw)
  1432. {
  1433. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1434. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1435. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1436. u16 bcn_interval, atim_window;
  1437. bcn_interval = mac->beacon_interval;
  1438. atim_window = 2; /*FIX MERGE */
  1439. rtl92ee_disable_interrupt(hw);
  1440. rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
  1441. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1442. rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
  1443. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
  1444. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
  1445. rtl_write_byte(rtlpriv, 0x606, 0x30);
  1446. rtlpci->reg_bcn_ctrl_val |= BIT(3);
  1447. rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8)rtlpci->reg_bcn_ctrl_val);
  1448. }
  1449. void rtl92ee_set_beacon_interval(struct ieee80211_hw *hw)
  1450. {
  1451. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1452. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1453. u16 bcn_interval = mac->beacon_interval;
  1454. RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
  1455. "beacon_interval:%d\n", bcn_interval);
  1456. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1457. }
  1458. void rtl92ee_update_interrupt_mask(struct ieee80211_hw *hw,
  1459. u32 add_msr, u32 rm_msr)
  1460. {
  1461. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1462. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1463. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
  1464. "add_msr:%x, rm_msr:%x\n", add_msr, rm_msr);
  1465. if (add_msr)
  1466. rtlpci->irq_mask[0] |= add_msr;
  1467. if (rm_msr)
  1468. rtlpci->irq_mask[0] &= (~rm_msr);
  1469. rtl92ee_disable_interrupt(hw);
  1470. rtl92ee_enable_interrupt(hw);
  1471. }
  1472. static u8 _rtl92ee_get_chnl_group(u8 chnl)
  1473. {
  1474. u8 group = 0;
  1475. if (chnl <= 14) {
  1476. if (1 <= chnl && chnl <= 2)
  1477. group = 0;
  1478. else if (3 <= chnl && chnl <= 5)
  1479. group = 1;
  1480. else if (6 <= chnl && chnl <= 8)
  1481. group = 2;
  1482. else if (9 <= chnl && chnl <= 11)
  1483. group = 3;
  1484. else if (12 <= chnl && chnl <= 14)
  1485. group = 4;
  1486. } else {
  1487. if (36 <= chnl && chnl <= 42)
  1488. group = 0;
  1489. else if (44 <= chnl && chnl <= 48)
  1490. group = 1;
  1491. else if (50 <= chnl && chnl <= 58)
  1492. group = 2;
  1493. else if (60 <= chnl && chnl <= 64)
  1494. group = 3;
  1495. else if (100 <= chnl && chnl <= 106)
  1496. group = 4;
  1497. else if (108 <= chnl && chnl <= 114)
  1498. group = 5;
  1499. else if (116 <= chnl && chnl <= 122)
  1500. group = 6;
  1501. else if (124 <= chnl && chnl <= 130)
  1502. group = 7;
  1503. else if (132 <= chnl && chnl <= 138)
  1504. group = 8;
  1505. else if (140 <= chnl && chnl <= 144)
  1506. group = 9;
  1507. else if (149 <= chnl && chnl <= 155)
  1508. group = 10;
  1509. else if (157 <= chnl && chnl <= 161)
  1510. group = 11;
  1511. else if (165 <= chnl && chnl <= 171)
  1512. group = 12;
  1513. else if (173 <= chnl && chnl <= 177)
  1514. group = 13;
  1515. }
  1516. return group;
  1517. }
  1518. static void _rtl8192ee_read_power_value_fromprom(struct ieee80211_hw *hw,
  1519. struct txpower_info_2g *pwr2g,
  1520. struct txpower_info_5g *pwr5g,
  1521. bool autoload_fail, u8 *hwinfo)
  1522. {
  1523. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1524. u32 rf, addr = EEPROM_TX_PWR_INX, group, i = 0;
  1525. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1526. "hal_ReadPowerValueFromPROM92E(): PROMContent[0x%x]=0x%x\n",
  1527. (addr + 1), hwinfo[addr + 1]);
  1528. if (0xFF == hwinfo[addr+1]) /*YJ,add,120316*/
  1529. autoload_fail = true;
  1530. if (autoload_fail) {
  1531. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1532. "auto load fail : Use Default value!\n");
  1533. for (rf = 0 ; rf < MAX_RF_PATH ; rf++) {
  1534. /* 2.4G default value */
  1535. for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) {
  1536. pwr2g->index_cck_base[rf][group] = 0x2D;
  1537. pwr2g->index_bw40_base[rf][group] = 0x2D;
  1538. }
  1539. for (i = 0; i < MAX_TX_COUNT; i++) {
  1540. if (i == 0) {
  1541. pwr2g->bw20_diff[rf][0] = 0x02;
  1542. pwr2g->ofdm_diff[rf][0] = 0x04;
  1543. } else {
  1544. pwr2g->bw20_diff[rf][i] = 0xFE;
  1545. pwr2g->bw40_diff[rf][i] = 0xFE;
  1546. pwr2g->cck_diff[rf][i] = 0xFE;
  1547. pwr2g->ofdm_diff[rf][i] = 0xFE;
  1548. }
  1549. }
  1550. /*5G default value*/
  1551. for (group = 0 ; group < MAX_CHNL_GROUP_5G; group++)
  1552. pwr5g->index_bw40_base[rf][group] = 0x2A;
  1553. for (i = 0; i < MAX_TX_COUNT; i++) {
  1554. if (i == 0) {
  1555. pwr5g->ofdm_diff[rf][0] = 0x04;
  1556. pwr5g->bw20_diff[rf][0] = 0x00;
  1557. pwr5g->bw80_diff[rf][0] = 0xFE;
  1558. pwr5g->bw160_diff[rf][0] = 0xFE;
  1559. } else {
  1560. pwr5g->ofdm_diff[rf][0] = 0xFE;
  1561. pwr5g->bw20_diff[rf][0] = 0xFE;
  1562. pwr5g->bw40_diff[rf][0] = 0xFE;
  1563. pwr5g->bw80_diff[rf][0] = 0xFE;
  1564. pwr5g->bw160_diff[rf][0] = 0xFE;
  1565. }
  1566. }
  1567. }
  1568. return;
  1569. }
  1570. rtl_priv(hw)->efuse.txpwr_fromeprom = true;
  1571. for (rf = 0 ; rf < MAX_RF_PATH ; rf++) {
  1572. /*2.4G default value*/
  1573. for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) {
  1574. pwr2g->index_cck_base[rf][group] = hwinfo[addr++];
  1575. if (pwr2g->index_cck_base[rf][group] == 0xFF)
  1576. pwr2g->index_cck_base[rf][group] = 0x2D;
  1577. }
  1578. for (group = 0 ; group < MAX_CHNL_GROUP_24G - 1; group++) {
  1579. pwr2g->index_bw40_base[rf][group] = hwinfo[addr++];
  1580. if (pwr2g->index_bw40_base[rf][group] == 0xFF)
  1581. pwr2g->index_bw40_base[rf][group] = 0x2D;
  1582. }
  1583. for (i = 0; i < MAX_TX_COUNT; i++) {
  1584. if (i == 0) {
  1585. pwr2g->bw40_diff[rf][i] = 0;
  1586. if (hwinfo[addr] == 0xFF) {
  1587. pwr2g->bw20_diff[rf][i] = 0x02;
  1588. } else {
  1589. pwr2g->bw20_diff[rf][i] = (hwinfo[addr]
  1590. & 0xf0) >> 4;
  1591. if (pwr2g->bw20_diff[rf][i] & BIT(3))
  1592. pwr2g->bw20_diff[rf][i] |= 0xF0;
  1593. }
  1594. if (hwinfo[addr] == 0xFF) {
  1595. pwr2g->ofdm_diff[rf][i] = 0x04;
  1596. } else {
  1597. pwr2g->ofdm_diff[rf][i] = (hwinfo[addr]
  1598. & 0x0f);
  1599. if (pwr2g->ofdm_diff[rf][i] & BIT(3))
  1600. pwr2g->ofdm_diff[rf][i] |= 0xF0;
  1601. }
  1602. pwr2g->cck_diff[rf][i] = 0;
  1603. addr++;
  1604. } else {
  1605. if (hwinfo[addr] == 0xFF) {
  1606. pwr2g->bw40_diff[rf][i] = 0xFE;
  1607. } else {
  1608. pwr2g->bw40_diff[rf][i] = (hwinfo[addr]
  1609. & 0xf0) >> 4;
  1610. if (pwr2g->bw40_diff[rf][i] & BIT(3))
  1611. pwr2g->bw40_diff[rf][i] |= 0xF0;
  1612. }
  1613. if (hwinfo[addr] == 0xFF) {
  1614. pwr2g->bw20_diff[rf][i] = 0xFE;
  1615. } else {
  1616. pwr2g->bw20_diff[rf][i] = (hwinfo[addr]
  1617. & 0x0f);
  1618. if (pwr2g->bw20_diff[rf][i] & BIT(3))
  1619. pwr2g->bw20_diff[rf][i] |= 0xF0;
  1620. }
  1621. addr++;
  1622. if (hwinfo[addr] == 0xFF) {
  1623. pwr2g->ofdm_diff[rf][i] = 0xFE;
  1624. } else {
  1625. pwr2g->ofdm_diff[rf][i] = (hwinfo[addr]
  1626. & 0xf0) >> 4;
  1627. if (pwr2g->ofdm_diff[rf][i] & BIT(3))
  1628. pwr2g->ofdm_diff[rf][i] |= 0xF0;
  1629. }
  1630. if (hwinfo[addr] == 0xFF) {
  1631. pwr2g->cck_diff[rf][i] = 0xFE;
  1632. } else {
  1633. pwr2g->cck_diff[rf][i] = (hwinfo[addr]
  1634. & 0x0f);
  1635. if (pwr2g->cck_diff[rf][i] & BIT(3))
  1636. pwr2g->cck_diff[rf][i] |= 0xF0;
  1637. }
  1638. addr++;
  1639. }
  1640. }
  1641. /*5G default value*/
  1642. for (group = 0 ; group < MAX_CHNL_GROUP_5G; group++) {
  1643. pwr5g->index_bw40_base[rf][group] = hwinfo[addr++];
  1644. if (pwr5g->index_bw40_base[rf][group] == 0xFF)
  1645. pwr5g->index_bw40_base[rf][group] = 0xFE;
  1646. }
  1647. for (i = 0; i < MAX_TX_COUNT; i++) {
  1648. if (i == 0) {
  1649. pwr5g->bw40_diff[rf][i] = 0;
  1650. if (hwinfo[addr] == 0xFF) {
  1651. pwr5g->bw20_diff[rf][i] = 0;
  1652. } else {
  1653. pwr5g->bw20_diff[rf][0] = (hwinfo[addr]
  1654. & 0xf0) >> 4;
  1655. if (pwr5g->bw20_diff[rf][i] & BIT(3))
  1656. pwr5g->bw20_diff[rf][i] |= 0xF0;
  1657. }
  1658. if (hwinfo[addr] == 0xFF) {
  1659. pwr5g->ofdm_diff[rf][i] = 0x04;
  1660. } else {
  1661. pwr5g->ofdm_diff[rf][0] = (hwinfo[addr]
  1662. & 0x0f);
  1663. if (pwr5g->ofdm_diff[rf][i] & BIT(3))
  1664. pwr5g->ofdm_diff[rf][i] |= 0xF0;
  1665. }
  1666. addr++;
  1667. } else {
  1668. if (hwinfo[addr] == 0xFF) {
  1669. pwr5g->bw40_diff[rf][i] = 0xFE;
  1670. } else {
  1671. pwr5g->bw40_diff[rf][i] = (hwinfo[addr]
  1672. & 0xf0) >> 4;
  1673. if (pwr5g->bw40_diff[rf][i] & BIT(3))
  1674. pwr5g->bw40_diff[rf][i] |= 0xF0;
  1675. }
  1676. if (hwinfo[addr] == 0xFF) {
  1677. pwr5g->bw20_diff[rf][i] = 0xFE;
  1678. } else {
  1679. pwr5g->bw20_diff[rf][i] = (hwinfo[addr]
  1680. & 0x0f);
  1681. if (pwr5g->bw20_diff[rf][i] & BIT(3))
  1682. pwr5g->bw20_diff[rf][i] |= 0xF0;
  1683. }
  1684. addr++;
  1685. }
  1686. }
  1687. if (hwinfo[addr] == 0xFF) {
  1688. pwr5g->ofdm_diff[rf][1] = 0xFE;
  1689. pwr5g->ofdm_diff[rf][2] = 0xFE;
  1690. } else {
  1691. pwr5g->ofdm_diff[rf][1] = (hwinfo[addr] & 0xf0) >> 4;
  1692. pwr5g->ofdm_diff[rf][2] = (hwinfo[addr] & 0x0f);
  1693. }
  1694. addr++;
  1695. if (hwinfo[addr] == 0xFF)
  1696. pwr5g->ofdm_diff[rf][3] = 0xFE;
  1697. else
  1698. pwr5g->ofdm_diff[rf][3] = (hwinfo[addr] & 0x0f);
  1699. addr++;
  1700. for (i = 1; i < MAX_TX_COUNT; i++) {
  1701. if (pwr5g->ofdm_diff[rf][i] == 0xFF)
  1702. pwr5g->ofdm_diff[rf][i] = 0xFE;
  1703. else if (pwr5g->ofdm_diff[rf][i] & BIT(3))
  1704. pwr5g->ofdm_diff[rf][i] |= 0xF0;
  1705. }
  1706. for (i = 0; i < MAX_TX_COUNT; i++) {
  1707. if (hwinfo[addr] == 0xFF) {
  1708. pwr5g->bw80_diff[rf][i] = 0xFE;
  1709. } else {
  1710. pwr5g->bw80_diff[rf][i] = (hwinfo[addr] & 0xf0)
  1711. >> 4;
  1712. if (pwr5g->bw80_diff[rf][i] & BIT(3))
  1713. pwr5g->bw80_diff[rf][i] |= 0xF0;
  1714. }
  1715. if (hwinfo[addr] == 0xFF) {
  1716. pwr5g->bw160_diff[rf][i] = 0xFE;
  1717. } else {
  1718. pwr5g->bw160_diff[rf][i] =
  1719. (hwinfo[addr] & 0x0f);
  1720. if (pwr5g->bw160_diff[rf][i] & BIT(3))
  1721. pwr5g->bw160_diff[rf][i] |= 0xF0;
  1722. }
  1723. addr++;
  1724. }
  1725. }
  1726. }
  1727. static void _rtl92ee_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
  1728. bool autoload_fail, u8 *hwinfo)
  1729. {
  1730. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1731. struct rtl_efuse *efu = rtl_efuse(rtl_priv(hw));
  1732. struct txpower_info_2g pwr2g;
  1733. struct txpower_info_5g pwr5g;
  1734. u8 channel5g[CHANNEL_MAX_NUMBER_5G] = {
  1735. 36, 38, 40, 42, 44, 46, 48, 50, 52, 54,
  1736. 56, 58, 60, 62, 64, 100, 102, 104, 106,
  1737. 108, 110, 112, 114, 116, 118, 120, 122,
  1738. 124, 126, 128, 130, 132, 134, 136, 138,
  1739. 140, 142, 144, 149, 151, 153, 155, 157,
  1740. 159, 161, 163, 165, 167, 168, 169, 171,
  1741. 173, 175, 177
  1742. };
  1743. u8 channel5g_80m[CHANNEL_MAX_NUMBER_5G_80M] = {
  1744. 42, 58, 106, 122, 138, 155, 171
  1745. };
  1746. u8 rf, idx;
  1747. u8 i;
  1748. _rtl8192ee_read_power_value_fromprom(hw, &pwr2g, &pwr5g,
  1749. autoload_fail, hwinfo);
  1750. for (rf = 0; rf < MAX_RF_PATH; rf++) {
  1751. for (i = 0; i < 14; i++) {
  1752. idx = _rtl92ee_get_chnl_group(i + 1);
  1753. if (i == CHANNEL_MAX_NUMBER_2G - 1) {
  1754. efu->txpwrlevel_cck[rf][i] =
  1755. pwr2g.index_cck_base[rf][5];
  1756. efu->txpwrlevel_ht40_1s[rf][i] =
  1757. pwr2g.index_bw40_base[rf][idx];
  1758. } else {
  1759. efu->txpwrlevel_cck[rf][i] =
  1760. pwr2g.index_cck_base[rf][idx];
  1761. efu->txpwrlevel_ht40_1s[rf][i] =
  1762. pwr2g.index_bw40_base[rf][idx];
  1763. }
  1764. }
  1765. for (i = 0; i < CHANNEL_MAX_NUMBER_5G; i++) {
  1766. idx = _rtl92ee_get_chnl_group(channel5g[i]);
  1767. efu->txpwr_5g_bw40base[rf][i] =
  1768. pwr5g.index_bw40_base[rf][idx];
  1769. }
  1770. for (i = 0; i < CHANNEL_MAX_NUMBER_5G_80M; i++) {
  1771. u8 upper, lower;
  1772. idx = _rtl92ee_get_chnl_group(channel5g_80m[i]);
  1773. upper = pwr5g.index_bw40_base[rf][idx];
  1774. lower = pwr5g.index_bw40_base[rf][idx + 1];
  1775. efu->txpwr_5g_bw80base[rf][i] = (upper + lower) / 2;
  1776. }
  1777. for (i = 0; i < MAX_TX_COUNT; i++) {
  1778. efu->txpwr_cckdiff[rf][i] = pwr2g.cck_diff[rf][i];
  1779. efu->txpwr_legacyhtdiff[rf][i] = pwr2g.ofdm_diff[rf][i];
  1780. efu->txpwr_ht20diff[rf][i] = pwr2g.bw20_diff[rf][i];
  1781. efu->txpwr_ht40diff[rf][i] = pwr2g.bw40_diff[rf][i];
  1782. efu->txpwr_5g_ofdmdiff[rf][i] = pwr5g.ofdm_diff[rf][i];
  1783. efu->txpwr_5g_bw20diff[rf][i] = pwr5g.bw20_diff[rf][i];
  1784. efu->txpwr_5g_bw40diff[rf][i] = pwr5g.bw40_diff[rf][i];
  1785. efu->txpwr_5g_bw80diff[rf][i] = pwr5g.bw80_diff[rf][i];
  1786. }
  1787. }
  1788. if (!autoload_fail)
  1789. efu->eeprom_thermalmeter = hwinfo[EEPROM_THERMAL_METER_92E];
  1790. else
  1791. efu->eeprom_thermalmeter = EEPROM_DEFAULT_THERMALMETER;
  1792. if (efu->eeprom_thermalmeter == 0xff || autoload_fail) {
  1793. efu->apk_thermalmeterignore = true;
  1794. efu->eeprom_thermalmeter = EEPROM_DEFAULT_THERMALMETER;
  1795. }
  1796. efu->thermalmeter[0] = efu->eeprom_thermalmeter;
  1797. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1798. "thermalmeter = 0x%x\n", efu->eeprom_thermalmeter);
  1799. if (!autoload_fail) {
  1800. efu->eeprom_regulatory = hwinfo[EEPROM_RF_BOARD_OPTION_92E]
  1801. & 0x07;
  1802. if (hwinfo[EEPROM_RF_BOARD_OPTION_92E] == 0xFF)
  1803. efu->eeprom_regulatory = 0;
  1804. } else {
  1805. efu->eeprom_regulatory = 0;
  1806. }
  1807. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1808. "eeprom_regulatory = 0x%x\n", efu->eeprom_regulatory);
  1809. }
  1810. static void _rtl92ee_read_adapter_info(struct ieee80211_hw *hw)
  1811. {
  1812. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1813. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1814. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1815. u16 i, usvalue;
  1816. u8 hwinfo[HWSET_MAX_SIZE];
  1817. u16 eeprom_id;
  1818. if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
  1819. rtl_efuse_shadow_map_update(hw);
  1820. memcpy(hwinfo, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
  1821. HWSET_MAX_SIZE);
  1822. } else if (rtlefuse->epromtype == EEPROM_93C46) {
  1823. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1824. "RTL819X Not boot from eeprom, check it !!");
  1825. return;
  1826. } else {
  1827. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1828. "boot from neither eeprom nor efuse, check it !!");
  1829. return;
  1830. }
  1831. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP\n",
  1832. hwinfo, HWSET_MAX_SIZE);
  1833. eeprom_id = *((u16 *)&hwinfo[0]);
  1834. if (eeprom_id != RTL8192E_EEPROM_ID) {
  1835. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1836. "EEPROM ID(%#x) is invalid!!\n", eeprom_id);
  1837. rtlefuse->autoload_failflag = true;
  1838. } else {
  1839. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1840. rtlefuse->autoload_failflag = false;
  1841. }
  1842. if (rtlefuse->autoload_failflag)
  1843. return;
  1844. /*VID DID SVID SDID*/
  1845. rtlefuse->eeprom_vid = *(u16 *)&hwinfo[EEPROM_VID];
  1846. rtlefuse->eeprom_did = *(u16 *)&hwinfo[EEPROM_DID];
  1847. rtlefuse->eeprom_svid = *(u16 *)&hwinfo[EEPROM_SVID];
  1848. rtlefuse->eeprom_smid = *(u16 *)&hwinfo[EEPROM_SMID];
  1849. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "EEPROMId = 0x%4x\n", eeprom_id);
  1850. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1851. "EEPROM VID = 0x%4x\n", rtlefuse->eeprom_vid);
  1852. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1853. "EEPROM DID = 0x%4x\n", rtlefuse->eeprom_did);
  1854. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1855. "EEPROM SVID = 0x%4x\n", rtlefuse->eeprom_svid);
  1856. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1857. "EEPROM SMID = 0x%4x\n", rtlefuse->eeprom_smid);
  1858. /*customer ID*/
  1859. rtlefuse->eeprom_oemid = *(u8 *)&hwinfo[EEPROM_CUSTOMER_ID];
  1860. if (rtlefuse->eeprom_oemid == 0xFF)
  1861. rtlefuse->eeprom_oemid = 0;
  1862. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1863. "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid);
  1864. /*EEPROM version*/
  1865. rtlefuse->eeprom_version = *(u8 *)&hwinfo[EEPROM_VERSION];
  1866. /*mac address*/
  1867. for (i = 0; i < 6; i += 2) {
  1868. usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
  1869. *((u16 *)(&rtlefuse->dev_addr[i])) = usvalue;
  1870. }
  1871. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1872. "dev_addr: %pM\n", rtlefuse->dev_addr);
  1873. /*channel plan */
  1874. rtlefuse->eeprom_channelplan = *(u8 *)&hwinfo[EEPROM_CHANNELPLAN];
  1875. /* set channel plan from efuse */
  1876. rtlefuse->channel_plan = rtlefuse->eeprom_channelplan;
  1877. /*tx power*/
  1878. _rtl92ee_read_txpower_info_from_hwpg(hw, rtlefuse->autoload_failflag,
  1879. hwinfo);
  1880. rtl92ee_read_bt_coexist_info_from_hwpg(hw, rtlefuse->autoload_failflag,
  1881. hwinfo);
  1882. /*board type*/
  1883. rtlefuse->board_type = (((*(u8 *)&hwinfo[EEPROM_RF_BOARD_OPTION_92E])
  1884. & 0xE0) >> 5);
  1885. if ((*(u8 *)&hwinfo[EEPROM_RF_BOARD_OPTION_92E]) == 0xFF)
  1886. rtlefuse->board_type = 0;
  1887. rtlhal->board_type = rtlefuse->board_type;
  1888. /*parse xtal*/
  1889. rtlefuse->crystalcap = hwinfo[EEPROM_XTAL_92E];
  1890. if (hwinfo[EEPROM_XTAL_92E] == 0xFF)
  1891. rtlefuse->crystalcap = 0x20;
  1892. /*antenna diversity*/
  1893. rtlefuse->antenna_div_type = NO_ANTDIV;
  1894. rtlefuse->antenna_div_cfg = 0;
  1895. if (rtlhal->oem_id == RT_CID_DEFAULT) {
  1896. switch (rtlefuse->eeprom_oemid) {
  1897. case EEPROM_CID_DEFAULT:
  1898. if (rtlefuse->eeprom_did == 0x818B) {
  1899. if ((rtlefuse->eeprom_svid == 0x10EC) &&
  1900. (rtlefuse->eeprom_smid == 0x001B))
  1901. rtlhal->oem_id = RT_CID_819X_LENOVO;
  1902. } else {
  1903. rtlhal->oem_id = RT_CID_DEFAULT;
  1904. }
  1905. break;
  1906. default:
  1907. rtlhal->oem_id = RT_CID_DEFAULT;
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. static void _rtl92ee_hal_customized_behavior(struct ieee80211_hw *hw)
  1913. {
  1914. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1915. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1916. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1917. pcipriv->ledctl.led_opendrain = true;
  1918. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1919. "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
  1920. }
  1921. void rtl92ee_read_eeprom_info(struct ieee80211_hw *hw)
  1922. {
  1923. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1924. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1925. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1926. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1927. u8 tmp_u1b;
  1928. rtlhal->version = _rtl92ee_read_chip_version(hw);
  1929. if (get_rf_type(rtlphy) == RF_1T1R) {
  1930. rtlpriv->dm.rfpath_rxenable[0] = true;
  1931. } else {
  1932. rtlpriv->dm.rfpath_rxenable[0] = true;
  1933. rtlpriv->dm.rfpath_rxenable[1] = true;
  1934. }
  1935. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
  1936. rtlhal->version);
  1937. tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
  1938. if (tmp_u1b & BIT(4)) {
  1939. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
  1940. rtlefuse->epromtype = EEPROM_93C46;
  1941. } else {
  1942. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
  1943. rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
  1944. }
  1945. if (tmp_u1b & BIT(5)) {
  1946. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1947. rtlefuse->autoload_failflag = false;
  1948. _rtl92ee_read_adapter_info(hw);
  1949. } else {
  1950. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Autoload ERR!!\n");
  1951. }
  1952. _rtl92ee_hal_customized_behavior(hw);
  1953. rtlphy->rfpath_rx_enable[0] = true;
  1954. if (rtlphy->rf_type == RF_2T2R)
  1955. rtlphy->rfpath_rx_enable[1] = true;
  1956. }
  1957. static u8 _rtl92ee_mrate_idx_to_arfr_id(struct ieee80211_hw *hw, u8 rate_index)
  1958. {
  1959. u8 ret = 0;
  1960. switch (rate_index) {
  1961. case RATR_INX_WIRELESS_NGB:
  1962. ret = 0;
  1963. break;
  1964. case RATR_INX_WIRELESS_N:
  1965. case RATR_INX_WIRELESS_NG:
  1966. ret = 4;
  1967. break;
  1968. case RATR_INX_WIRELESS_NB:
  1969. ret = 2;
  1970. break;
  1971. case RATR_INX_WIRELESS_GB:
  1972. ret = 6;
  1973. break;
  1974. case RATR_INX_WIRELESS_G:
  1975. ret = 7;
  1976. break;
  1977. case RATR_INX_WIRELESS_B:
  1978. ret = 8;
  1979. break;
  1980. default:
  1981. ret = 0;
  1982. break;
  1983. }
  1984. return ret;
  1985. }
  1986. static void rtl92ee_update_hal_rate_mask(struct ieee80211_hw *hw,
  1987. struct ieee80211_sta *sta,
  1988. u8 rssi_level)
  1989. {
  1990. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1991. struct rtl_phy *rtlphy = &rtlpriv->phy;
  1992. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1993. struct rtl_sta_info *sta_entry = NULL;
  1994. u32 ratr_bitmap;
  1995. u8 ratr_index;
  1996. u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
  1997. ? 1 : 0;
  1998. u8 b_curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1999. 1 : 0;
  2000. u8 b_curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  2001. 1 : 0;
  2002. enum wireless_mode wirelessmode = 0;
  2003. bool b_shortgi = false;
  2004. u8 rate_mask[7] = {0};
  2005. u8 macid = 0;
  2006. /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
  2007. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  2008. wirelessmode = sta_entry->wireless_mode;
  2009. if (mac->opmode == NL80211_IFTYPE_STATION ||
  2010. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  2011. curtxbw_40mhz = mac->bw_40;
  2012. else if (mac->opmode == NL80211_IFTYPE_AP ||
  2013. mac->opmode == NL80211_IFTYPE_ADHOC)
  2014. macid = sta->aid + 1;
  2015. ratr_bitmap = sta->supp_rates[0];
  2016. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  2017. ratr_bitmap = 0xfff;
  2018. ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  2019. sta->ht_cap.mcs.rx_mask[0] << 12);
  2020. switch (wirelessmode) {
  2021. case WIRELESS_MODE_B:
  2022. ratr_index = RATR_INX_WIRELESS_B;
  2023. if (ratr_bitmap & 0x0000000c)
  2024. ratr_bitmap &= 0x0000000d;
  2025. else
  2026. ratr_bitmap &= 0x0000000f;
  2027. break;
  2028. case WIRELESS_MODE_G:
  2029. ratr_index = RATR_INX_WIRELESS_GB;
  2030. if (rssi_level == 1)
  2031. ratr_bitmap &= 0x00000f00;
  2032. else if (rssi_level == 2)
  2033. ratr_bitmap &= 0x00000ff0;
  2034. else
  2035. ratr_bitmap &= 0x00000ff5;
  2036. break;
  2037. case WIRELESS_MODE_N_24G:
  2038. if (curtxbw_40mhz)
  2039. ratr_index = RATR_INX_WIRELESS_NGB;
  2040. else
  2041. ratr_index = RATR_INX_WIRELESS_NB;
  2042. if (rtlphy->rf_type == RF_1T1R) {
  2043. if (curtxbw_40mhz) {
  2044. if (rssi_level == 1)
  2045. ratr_bitmap &= 0x000f0000;
  2046. else if (rssi_level == 2)
  2047. ratr_bitmap &= 0x000ff000;
  2048. else
  2049. ratr_bitmap &= 0x000ff015;
  2050. } else {
  2051. if (rssi_level == 1)
  2052. ratr_bitmap &= 0x000f0000;
  2053. else if (rssi_level == 2)
  2054. ratr_bitmap &= 0x000ff000;
  2055. else
  2056. ratr_bitmap &= 0x000ff005;
  2057. }
  2058. } else {
  2059. if (curtxbw_40mhz) {
  2060. if (rssi_level == 1)
  2061. ratr_bitmap &= 0x0f8f0000;
  2062. else if (rssi_level == 2)
  2063. ratr_bitmap &= 0x0ffff000;
  2064. else
  2065. ratr_bitmap &= 0x0ffff015;
  2066. } else {
  2067. if (rssi_level == 1)
  2068. ratr_bitmap &= 0x0f8f0000;
  2069. else if (rssi_level == 2)
  2070. ratr_bitmap &= 0x0ffff000;
  2071. else
  2072. ratr_bitmap &= 0x0ffff005;
  2073. }
  2074. }
  2075. if ((curtxbw_40mhz && b_curshortgi_40mhz) ||
  2076. (!curtxbw_40mhz && b_curshortgi_20mhz)) {
  2077. if (macid == 0)
  2078. b_shortgi = true;
  2079. else if (macid == 1)
  2080. b_shortgi = false;
  2081. }
  2082. break;
  2083. default:
  2084. ratr_index = RATR_INX_WIRELESS_NGB;
  2085. if (rtlphy->rf_type == RF_1T1R)
  2086. ratr_bitmap &= 0x000ff0ff;
  2087. else
  2088. ratr_bitmap &= 0x0f8ff0ff;
  2089. break;
  2090. }
  2091. ratr_index = _rtl92ee_mrate_idx_to_arfr_id(hw, ratr_index);
  2092. sta_entry->ratr_index = ratr_index;
  2093. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  2094. "ratr_bitmap :%x\n", ratr_bitmap);
  2095. *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
  2096. (ratr_index << 28);
  2097. rate_mask[0] = macid;
  2098. rate_mask[1] = ratr_index | (b_shortgi ? 0x80 : 0x00);
  2099. rate_mask[2] = curtxbw_40mhz;
  2100. rate_mask[3] = (u8)(ratr_bitmap & 0x000000ff);
  2101. rate_mask[4] = (u8)((ratr_bitmap & 0x0000ff00) >> 8);
  2102. rate_mask[5] = (u8)((ratr_bitmap & 0x00ff0000) >> 16);
  2103. rate_mask[6] = (u8)((ratr_bitmap & 0xff000000) >> 24);
  2104. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  2105. "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x:%x:%x\n",
  2106. ratr_index, ratr_bitmap, rate_mask[0], rate_mask[1],
  2107. rate_mask[2], rate_mask[3], rate_mask[4],
  2108. rate_mask[5], rate_mask[6]);
  2109. rtl92ee_fill_h2c_cmd(hw, H2C_92E_RA_MASK, 7, rate_mask);
  2110. _rtl92ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  2111. }
  2112. void rtl92ee_update_hal_rate_tbl(struct ieee80211_hw *hw,
  2113. struct ieee80211_sta *sta, u8 rssi_level)
  2114. {
  2115. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2116. if (rtlpriv->dm.useramask)
  2117. rtl92ee_update_hal_rate_mask(hw, sta, rssi_level);
  2118. }
  2119. void rtl92ee_update_channel_access_setting(struct ieee80211_hw *hw)
  2120. {
  2121. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2122. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2123. u16 sifs_timer;
  2124. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  2125. (u8 *)&mac->slot_time);
  2126. if (!mac->ht_enable)
  2127. sifs_timer = 0x0a0a;
  2128. else
  2129. sifs_timer = 0x0e0e;
  2130. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
  2131. }
  2132. bool rtl92ee_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
  2133. {
  2134. *valid = 1;
  2135. return true;
  2136. }
  2137. void rtl92ee_set_key(struct ieee80211_hw *hw, u32 key_index,
  2138. u8 *p_macaddr, bool is_group, u8 enc_algo,
  2139. bool is_wepkey, bool clear_all)
  2140. {
  2141. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2142. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2143. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2144. u8 *macaddr = p_macaddr;
  2145. u32 entry_id = 0;
  2146. bool is_pairwise = false;
  2147. static u8 cam_const_addr[4][6] = {
  2148. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  2149. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  2150. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  2151. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  2152. };
  2153. static u8 cam_const_broad[] = {
  2154. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  2155. };
  2156. if (clear_all) {
  2157. u8 idx = 0;
  2158. u8 cam_offset = 0;
  2159. u8 clear_number = 5;
  2160. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  2161. for (idx = 0; idx < clear_number; idx++) {
  2162. rtl_cam_mark_invalid(hw, cam_offset + idx);
  2163. rtl_cam_empty_entry(hw, cam_offset + idx);
  2164. if (idx < 5) {
  2165. memset(rtlpriv->sec.key_buf[idx], 0,
  2166. MAX_KEY_LEN);
  2167. rtlpriv->sec.key_len[idx] = 0;
  2168. }
  2169. }
  2170. } else {
  2171. switch (enc_algo) {
  2172. case WEP40_ENCRYPTION:
  2173. enc_algo = CAM_WEP40;
  2174. break;
  2175. case WEP104_ENCRYPTION:
  2176. enc_algo = CAM_WEP104;
  2177. break;
  2178. case TKIP_ENCRYPTION:
  2179. enc_algo = CAM_TKIP;
  2180. break;
  2181. case AESCCMP_ENCRYPTION:
  2182. enc_algo = CAM_AES;
  2183. break;
  2184. default:
  2185. RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
  2186. "switch case not process\n");
  2187. enc_algo = CAM_TKIP;
  2188. break;
  2189. }
  2190. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  2191. macaddr = cam_const_addr[key_index];
  2192. entry_id = key_index;
  2193. } else {
  2194. if (is_group) {
  2195. macaddr = cam_const_broad;
  2196. entry_id = key_index;
  2197. } else {
  2198. if (mac->opmode == NL80211_IFTYPE_AP ||
  2199. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  2200. entry_id = rtl_cam_get_free_entry(hw,
  2201. p_macaddr);
  2202. if (entry_id >= TOTAL_CAM_ENTRY) {
  2203. RT_TRACE(rtlpriv, COMP_SEC,
  2204. DBG_EMERG,
  2205. "Can not find free hw security cam entry\n");
  2206. return;
  2207. }
  2208. } else {
  2209. entry_id = CAM_PAIRWISE_KEY_POSITION;
  2210. }
  2211. key_index = PAIRWISE_KEYIDX;
  2212. is_pairwise = true;
  2213. }
  2214. }
  2215. if (rtlpriv->sec.key_len[key_index] == 0) {
  2216. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2217. "delete one entry, entry_id is %d\n",
  2218. entry_id);
  2219. if (mac->opmode == NL80211_IFTYPE_AP ||
  2220. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  2221. rtl_cam_del_entry(hw, p_macaddr);
  2222. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  2223. } else {
  2224. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2225. "add one entry\n");
  2226. if (is_pairwise) {
  2227. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2228. "set Pairwiase key\n");
  2229. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2230. entry_id, enc_algo,
  2231. CAM_CONFIG_NO_USEDK,
  2232. rtlpriv->sec.key_buf[key_index]);
  2233. } else {
  2234. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2235. "set group key\n");
  2236. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  2237. rtl_cam_add_one_entry(hw,
  2238. rtlefuse->dev_addr,
  2239. PAIRWISE_KEYIDX,
  2240. CAM_PAIRWISE_KEY_POSITION,
  2241. enc_algo, CAM_CONFIG_NO_USEDK,
  2242. rtlpriv->sec.key_buf[entry_id]);
  2243. }
  2244. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2245. entry_id, enc_algo,
  2246. CAM_CONFIG_NO_USEDK,
  2247. rtlpriv->sec.key_buf[entry_id]);
  2248. }
  2249. }
  2250. }
  2251. }
  2252. void rtl92ee_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
  2253. bool auto_load_fail, u8 *hwinfo)
  2254. {
  2255. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2256. u8 value;
  2257. if (!auto_load_fail) {
  2258. value = hwinfo[EEPROM_RF_BOARD_OPTION_92E];
  2259. if (((value & 0xe0) >> 5) == 0x1)
  2260. rtlpriv->btcoexist.btc_info.btcoexist = 1;
  2261. else
  2262. rtlpriv->btcoexist.btc_info.btcoexist = 0;
  2263. rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8192E;
  2264. rtlpriv->btcoexist.btc_info.ant_num = ANT_TOTAL_X2;
  2265. } else {
  2266. rtlpriv->btcoexist.btc_info.btcoexist = 1;
  2267. rtlpriv->btcoexist.btc_info.bt_type = BT_RTL8192E;
  2268. rtlpriv->btcoexist.btc_info.ant_num = ANT_TOTAL_X1;
  2269. }
  2270. }
  2271. void rtl92ee_bt_reg_init(struct ieee80211_hw *hw)
  2272. {
  2273. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2274. /* 0:Low, 1:High, 2:From Efuse. */
  2275. rtlpriv->btcoexist.reg_bt_iso = 2;
  2276. /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
  2277. rtlpriv->btcoexist.reg_bt_sco = 3;
  2278. /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
  2279. rtlpriv->btcoexist.reg_bt_sco = 0;
  2280. }
  2281. void rtl92ee_bt_hw_init(struct ieee80211_hw *hw)
  2282. {
  2283. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2284. if (rtlpriv->cfg->ops->get_btc_status())
  2285. rtlpriv->btcoexist.btc_ops->btc_init_hw_config(rtlpriv);
  2286. }
  2287. void rtl92ee_suspend(struct ieee80211_hw *hw)
  2288. {
  2289. }
  2290. void rtl92ee_resume(struct ieee80211_hw *hw)
  2291. {
  2292. }
  2293. /* Turn on AAP (RCR:bit 0) for promicuous mode. */
  2294. void rtl92ee_allow_all_destaddr(struct ieee80211_hw *hw,
  2295. bool allow_all_da, bool write_into_reg)
  2296. {
  2297. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2298. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  2299. if (allow_all_da) /* Set BIT0 */
  2300. rtlpci->receive_config |= RCR_AAP;
  2301. else /* Clear BIT0 */
  2302. rtlpci->receive_config &= ~RCR_AAP;
  2303. if (write_into_reg)
  2304. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  2305. RT_TRACE(rtlpriv, COMP_TURBO | COMP_INIT, DBG_LOUD,
  2306. "receive_config=0x%08X, write_into_reg=%d\n",
  2307. rtlpci->receive_config, write_into_reg);
  2308. }