hw.c 73 KB

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