hw.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2013 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 "../pwrseqcmd.h"
  33. #include "reg.h"
  34. #include "def.h"
  35. #include "phy.h"
  36. #include "dm.h"
  37. #include "fw.h"
  38. #include "led.h"
  39. #include "hw.h"
  40. #include "pwrseq.h"
  41. #define LLT_CONFIG 5
  42. static void _rtl88ee_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 _rtl88ee_stop_tx_beacon(struct ieee80211_hw *hw)
  52. {
  53. struct rtl_priv *rtlpriv = rtl_priv(hw);
  54. u8 tmp1byte;
  55. tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  56. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6)));
  57. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
  58. tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  59. tmp1byte &= ~(BIT(0));
  60. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
  61. }
  62. static void _rtl88ee_resume_tx_beacon(struct ieee80211_hw *hw)
  63. {
  64. struct rtl_priv *rtlpriv = rtl_priv(hw);
  65. u8 tmp1byte;
  66. tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  67. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6));
  68. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  69. tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  70. tmp1byte |= BIT(0);
  71. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
  72. }
  73. static void _rtl88ee_enable_bcn_sub_func(struct ieee80211_hw *hw)
  74. {
  75. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(1));
  76. }
  77. static void _rtl88ee_return_beacon_queue_skb(struct ieee80211_hw *hw)
  78. {
  79. struct rtl_priv *rtlpriv = rtl_priv(hw);
  80. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  81. struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[BEACON_QUEUE];
  82. unsigned long flags;
  83. spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
  84. while (skb_queue_len(&ring->queue)) {
  85. struct rtl_tx_desc *entry = &ring->desc[ring->idx];
  86. struct sk_buff *skb = __skb_dequeue(&ring->queue);
  87. pci_unmap_single(rtlpci->pdev,
  88. rtlpriv->cfg->ops->get_desc(
  89. (u8 *)entry, true, HW_DESC_TXBUFF_ADDR),
  90. skb->len, PCI_DMA_TODEVICE);
  91. kfree_skb(skb);
  92. ring->idx = (ring->idx + 1) % ring->entries;
  93. }
  94. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  95. }
  96. static void _rtl88ee_disable_bcn_sub_func(struct ieee80211_hw *hw)
  97. {
  98. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(1), 0);
  99. }
  100. static void _rtl88ee_set_fw_clock_on(struct ieee80211_hw *hw,
  101. u8 rpwm_val, bool b_need_turn_off_ckk)
  102. {
  103. struct rtl_priv *rtlpriv = rtl_priv(hw);
  104. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  105. bool b_support_remote_wake_up;
  106. u32 count = 0, isr_regaddr, content;
  107. bool schedule_timer = b_need_turn_off_ckk;
  108. rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
  109. (u8 *)(&b_support_remote_wake_up));
  110. if (!rtlhal->fw_ready)
  111. return;
  112. if (!rtlpriv->psc.fw_current_inpsmode)
  113. return;
  114. while (1) {
  115. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  116. if (rtlhal->fw_clk_change_in_progress) {
  117. while (rtlhal->fw_clk_change_in_progress) {
  118. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  119. count++;
  120. udelay(100);
  121. if (count > 1000)
  122. return;
  123. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  124. }
  125. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  126. } else {
  127. rtlhal->fw_clk_change_in_progress = false;
  128. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  129. break;
  130. }
  131. }
  132. if (IS_IN_LOW_POWER_STATE_88E(rtlhal->fw_ps_state)) {
  133. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val);
  134. if (FW_PS_IS_ACK(rpwm_val)) {
  135. isr_regaddr = REG_HISR;
  136. content = rtl_read_dword(rtlpriv, isr_regaddr);
  137. while (!(content & IMR_CPWM) && (count < 500)) {
  138. udelay(50);
  139. count++;
  140. content = rtl_read_dword(rtlpriv, isr_regaddr);
  141. }
  142. if (content & IMR_CPWM) {
  143. rtl_write_word(rtlpriv, isr_regaddr, 0x0100);
  144. rtlhal->fw_ps_state = FW_PS_STATE_RF_ON_88E;
  145. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  146. "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n",
  147. rtlhal->fw_ps_state);
  148. }
  149. }
  150. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  151. rtlhal->fw_clk_change_in_progress = false;
  152. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  153. if (schedule_timer) {
  154. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  155. jiffies + MSECS(10));
  156. }
  157. } else {
  158. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  159. rtlhal->fw_clk_change_in_progress = false;
  160. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  161. }
  162. }
  163. static void _rtl88ee_set_fw_clock_off(struct ieee80211_hw *hw,
  164. u8 rpwm_val)
  165. {
  166. struct rtl_priv *rtlpriv = rtl_priv(hw);
  167. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  168. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  169. struct rtl8192_tx_ring *ring;
  170. enum rf_pwrstate rtstate;
  171. bool schedule_timer = false;
  172. u8 queue;
  173. if (!rtlhal->fw_ready)
  174. return;
  175. if (!rtlpriv->psc.fw_current_inpsmode)
  176. return;
  177. if (!rtlhal->allow_sw_to_change_hwclc)
  178. return;
  179. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE, (u8 *)(&rtstate));
  180. if (rtstate == ERFOFF || rtlpriv->psc.inactive_pwrstate == ERFOFF)
  181. return;
  182. for (queue = 0; queue < RTL_PCI_MAX_TX_QUEUE_COUNT; queue++) {
  183. ring = &rtlpci->tx_ring[queue];
  184. if (skb_queue_len(&ring->queue)) {
  185. schedule_timer = true;
  186. break;
  187. }
  188. }
  189. if (schedule_timer) {
  190. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  191. jiffies + MSECS(10));
  192. return;
  193. }
  194. if (FW_PS_STATE(rtlhal->fw_ps_state) !=
  195. FW_PS_STATE_RF_OFF_LOW_PWR_88E) {
  196. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  197. if (!rtlhal->fw_clk_change_in_progress) {
  198. rtlhal->fw_clk_change_in_progress = true;
  199. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  200. rtlhal->fw_ps_state = FW_PS_STATE(rpwm_val);
  201. rtl_write_word(rtlpriv, REG_HISR, 0x0100);
  202. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
  203. &rpwm_val);
  204. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  205. rtlhal->fw_clk_change_in_progress = false;
  206. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  207. } else {
  208. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  209. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  210. jiffies + MSECS(10));
  211. }
  212. }
  213. }
  214. static void _rtl88ee_set_fw_ps_rf_on(struct ieee80211_hw *hw)
  215. {
  216. u8 rpwm_val = 0;
  217. rpwm_val |= (FW_PS_STATE_RF_OFF_88E | FW_PS_ACK);
  218. _rtl88ee_set_fw_clock_on(hw, rpwm_val, true);
  219. }
  220. static void _rtl88ee_set_fw_ps_rf_off_low_power(struct ieee80211_hw *hw)
  221. {
  222. u8 rpwm_val = 0;
  223. rpwm_val |= FW_PS_STATE_RF_OFF_LOW_PWR_88E;
  224. _rtl88ee_set_fw_clock_off(hw, rpwm_val);
  225. }
  226. void rtl88ee_fw_clk_off_timer_callback(unsigned long data)
  227. {
  228. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  229. _rtl88ee_set_fw_ps_rf_off_low_power(hw);
  230. }
  231. static void _rtl88ee_fwlps_leave(struct ieee80211_hw *hw)
  232. {
  233. struct rtl_priv *rtlpriv = rtl_priv(hw);
  234. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  235. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  236. bool fw_current_inps = false;
  237. u8 rpwm_val = 0, fw_pwrmode = FW_PS_ACTIVE_MODE;
  238. if (ppsc->low_power_enable) {
  239. rpwm_val = (FW_PS_STATE_ALL_ON_88E|FW_PS_ACK);/* RF on */
  240. _rtl88ee_set_fw_clock_on(hw, rpwm_val, false);
  241. rtlhal->allow_sw_to_change_hwclc = false;
  242. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  243. &fw_pwrmode);
  244. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  245. (u8 *)(&fw_current_inps));
  246. } else {
  247. rpwm_val = FW_PS_STATE_ALL_ON_88E; /* RF on */
  248. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val);
  249. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  250. &fw_pwrmode);
  251. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  252. (u8 *)(&fw_current_inps));
  253. }
  254. }
  255. static void _rtl88ee_fwlps_enter(struct ieee80211_hw *hw)
  256. {
  257. struct rtl_priv *rtlpriv = rtl_priv(hw);
  258. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  259. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  260. bool fw_current_inps = true;
  261. u8 rpwm_val;
  262. if (ppsc->low_power_enable) {
  263. rpwm_val = FW_PS_STATE_RF_OFF_LOW_PWR_88E; /* RF off */
  264. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  265. (u8 *)(&fw_current_inps));
  266. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  267. &ppsc->fwctrl_psmode);
  268. rtlhal->allow_sw_to_change_hwclc = true;
  269. _rtl88ee_set_fw_clock_off(hw, rpwm_val);
  270. } else {
  271. rpwm_val = FW_PS_STATE_RF_OFF_88E; /* RF off */
  272. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  273. (u8 *)(&fw_current_inps));
  274. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  275. &ppsc->fwctrl_psmode);
  276. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val);
  277. }
  278. }
  279. void rtl88ee_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  280. {
  281. struct rtl_priv *rtlpriv = rtl_priv(hw);
  282. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  283. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  284. switch (variable) {
  285. case HW_VAR_RCR:
  286. *((u32 *)(val)) = rtlpci->receive_config;
  287. break;
  288. case HW_VAR_RF_STATE:
  289. *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
  290. break;
  291. case HW_VAR_FWLPS_RF_ON:{
  292. enum rf_pwrstate rfstate;
  293. u32 val_rcr;
  294. rtlpriv->cfg->ops->get_hw_reg(hw,
  295. HW_VAR_RF_STATE,
  296. (u8 *)(&rfstate));
  297. if (rfstate == ERFOFF) {
  298. *((bool *)(val)) = true;
  299. } else {
  300. val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
  301. val_rcr &= 0x00070000;
  302. if (val_rcr)
  303. *((bool *)(val)) = false;
  304. else
  305. *((bool *)(val)) = true;
  306. }
  307. break; }
  308. case HW_VAR_FW_PSMODE_STATUS:
  309. *((bool *)(val)) = ppsc->fw_current_inpsmode;
  310. break;
  311. case HW_VAR_CORRECT_TSF:{
  312. u64 tsf;
  313. u32 *ptsf_low = (u32 *)&tsf;
  314. u32 *ptsf_high = ((u32 *)&tsf) + 1;
  315. *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
  316. *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
  317. *((u64 *)(val)) = tsf;
  318. break; }
  319. default:
  320. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  321. "switch case not process %x\n", variable);
  322. break;
  323. }
  324. }
  325. void rtl88ee_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  326. {
  327. struct rtl_priv *rtlpriv = rtl_priv(hw);
  328. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  329. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  330. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  331. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  332. u8 idx;
  333. switch (variable) {
  334. case HW_VAR_ETHER_ADDR:
  335. for (idx = 0; idx < ETH_ALEN; idx++) {
  336. rtl_write_byte(rtlpriv, (REG_MACID + idx),
  337. val[idx]);
  338. }
  339. break;
  340. case HW_VAR_BASIC_RATE:{
  341. u16 b_rate_cfg = ((u16 *)val)[0];
  342. u8 rate_index = 0;
  343. b_rate_cfg = b_rate_cfg & 0x15f;
  344. b_rate_cfg |= 0x01;
  345. rtl_write_byte(rtlpriv, REG_RRSR, b_rate_cfg & 0xff);
  346. rtl_write_byte(rtlpriv, REG_RRSR + 1,
  347. (b_rate_cfg >> 8) & 0xff);
  348. while (b_rate_cfg > 0x1) {
  349. b_rate_cfg = (b_rate_cfg >> 1);
  350. rate_index++;
  351. }
  352. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
  353. rate_index);
  354. break;
  355. }
  356. case HW_VAR_BSSID:
  357. for (idx = 0; idx < ETH_ALEN; idx++) {
  358. rtl_write_byte(rtlpriv, (REG_BSSID + idx),
  359. val[idx]);
  360. }
  361. break;
  362. case HW_VAR_SIFS:
  363. rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
  364. rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
  365. rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
  366. rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
  367. if (!mac->ht_enable)
  368. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  369. 0x0e0e);
  370. else
  371. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  372. *((u16 *)val));
  373. break;
  374. case HW_VAR_SLOT_TIME:{
  375. u8 e_aci;
  376. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  377. "HW_VAR_SLOT_TIME %x\n", val[0]);
  378. rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
  379. for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
  380. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM,
  381. &e_aci);
  382. }
  383. break;
  384. }
  385. case HW_VAR_ACK_PREAMBLE:{
  386. u8 reg_tmp;
  387. u8 short_preamble = (bool)*val;
  388. reg_tmp = rtl_read_byte(rtlpriv, REG_TRXPTCL_CTL+2);
  389. if (short_preamble) {
  390. reg_tmp |= 0x02;
  391. rtl_write_byte(rtlpriv, REG_TRXPTCL_CTL +
  392. 2, reg_tmp);
  393. } else {
  394. reg_tmp |= 0xFD;
  395. rtl_write_byte(rtlpriv, REG_TRXPTCL_CTL +
  396. 2, reg_tmp);
  397. }
  398. break; }
  399. case HW_VAR_WPA_CONFIG:
  400. rtl_write_byte(rtlpriv, REG_SECCFG, *val);
  401. break;
  402. case HW_VAR_AMPDU_MIN_SPACE:{
  403. u8 min_spacing_to_set;
  404. u8 sec_min_space;
  405. min_spacing_to_set = *val;
  406. if (min_spacing_to_set <= 7) {
  407. sec_min_space = 0;
  408. if (min_spacing_to_set < sec_min_space)
  409. min_spacing_to_set = sec_min_space;
  410. mac->min_space_cfg = ((mac->min_space_cfg &
  411. 0xf8) |
  412. min_spacing_to_set);
  413. *val = min_spacing_to_set;
  414. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  415. "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
  416. mac->min_space_cfg);
  417. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  418. mac->min_space_cfg);
  419. }
  420. break; }
  421. case HW_VAR_SHORTGI_DENSITY:{
  422. u8 density_to_set;
  423. density_to_set = *val;
  424. mac->min_space_cfg |= (density_to_set << 3);
  425. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  426. "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
  427. mac->min_space_cfg);
  428. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  429. mac->min_space_cfg);
  430. break;
  431. }
  432. case HW_VAR_AMPDU_FACTOR:{
  433. u8 regtoset_normal[4] = { 0x41, 0xa8, 0x72, 0xb9 };
  434. u8 factor_toset;
  435. u8 *p_regtoset = NULL;
  436. u8 index = 0;
  437. p_regtoset = regtoset_normal;
  438. factor_toset = *val;
  439. if (factor_toset <= 3) {
  440. factor_toset = (1 << (factor_toset + 2));
  441. if (factor_toset > 0xf)
  442. factor_toset = 0xf;
  443. for (index = 0; index < 4; index++) {
  444. if ((p_regtoset[index] & 0xf0) >
  445. (factor_toset << 4))
  446. p_regtoset[index] =
  447. (p_regtoset[index] & 0x0f) |
  448. (factor_toset << 4);
  449. if ((p_regtoset[index] & 0x0f) >
  450. factor_toset)
  451. p_regtoset[index] =
  452. (p_regtoset[index] & 0xf0) |
  453. (factor_toset);
  454. rtl_write_byte(rtlpriv,
  455. (REG_AGGLEN_LMT + index),
  456. p_regtoset[index]);
  457. }
  458. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  459. "Set HW_VAR_AMPDU_FACTOR: %#x\n",
  460. factor_toset);
  461. }
  462. break; }
  463. case HW_VAR_AC_PARAM:{
  464. u8 e_aci = *val;
  465. rtl88e_dm_init_edca_turbo(hw);
  466. if (rtlpci->acm_method != EACMWAY2_SW)
  467. rtlpriv->cfg->ops->set_hw_reg(hw,
  468. HW_VAR_ACM_CTRL,
  469. &e_aci);
  470. break; }
  471. case HW_VAR_ACM_CTRL:{
  472. u8 e_aci = *val;
  473. union aci_aifsn *p_aci_aifsn =
  474. (union aci_aifsn *)(&(mac->ac[0].aifs));
  475. u8 acm = p_aci_aifsn->f.acm;
  476. u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
  477. acm_ctrl = acm_ctrl |
  478. ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
  479. if (acm) {
  480. switch (e_aci) {
  481. case AC0_BE:
  482. acm_ctrl |= ACMHW_BEQEN;
  483. break;
  484. case AC2_VI:
  485. acm_ctrl |= ACMHW_VIQEN;
  486. break;
  487. case AC3_VO:
  488. acm_ctrl |= ACMHW_VOQEN;
  489. break;
  490. default:
  491. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  492. "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
  493. acm);
  494. break;
  495. }
  496. } else {
  497. switch (e_aci) {
  498. case AC0_BE:
  499. acm_ctrl &= (~ACMHW_BEQEN);
  500. break;
  501. case AC2_VI:
  502. acm_ctrl &= (~ACMHW_VIQEN);
  503. break;
  504. case AC3_VO:
  505. acm_ctrl &= (~ACMHW_VOQEN);
  506. break;
  507. default:
  508. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  509. "switch case not process\n");
  510. break;
  511. }
  512. }
  513. RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
  514. "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
  515. acm_ctrl);
  516. rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
  517. break; }
  518. case HW_VAR_RCR:
  519. rtl_write_dword(rtlpriv, REG_RCR, ((u32 *)(val))[0]);
  520. rtlpci->receive_config = ((u32 *)(val))[0];
  521. break;
  522. case HW_VAR_RETRY_LIMIT:{
  523. u8 retry_limit = *val;
  524. rtl_write_word(rtlpriv, REG_RL,
  525. retry_limit << RETRY_LIMIT_SHORT_SHIFT |
  526. retry_limit << RETRY_LIMIT_LONG_SHIFT);
  527. break; }
  528. case HW_VAR_DUAL_TSF_RST:
  529. rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
  530. break;
  531. case HW_VAR_EFUSE_BYTES:
  532. rtlefuse->efuse_usedbytes = *((u16 *)val);
  533. break;
  534. case HW_VAR_EFUSE_USAGE:
  535. rtlefuse->efuse_usedpercentage = *val;
  536. break;
  537. case HW_VAR_IO_CMD:
  538. rtl88e_phy_set_io_cmd(hw, (*(enum io_type *)val));
  539. break;
  540. case HW_VAR_SET_RPWM:{
  541. u8 rpwm_val;
  542. rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
  543. udelay(1);
  544. if (rpwm_val & BIT(7)) {
  545. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val);
  546. } else {
  547. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val | BIT(7));
  548. }
  549. break; }
  550. case HW_VAR_H2C_FW_PWRMODE:
  551. rtl88e_set_fw_pwrmode_cmd(hw, *val);
  552. break;
  553. case HW_VAR_FW_PSMODE_STATUS:
  554. ppsc->fw_current_inpsmode = *((bool *)val);
  555. break;
  556. case HW_VAR_RESUME_CLK_ON:
  557. _rtl88ee_set_fw_ps_rf_on(hw);
  558. break;
  559. case HW_VAR_FW_LPS_ACTION:{
  560. bool enter_fwlps = *((bool *)val);
  561. if (enter_fwlps)
  562. _rtl88ee_fwlps_enter(hw);
  563. else
  564. _rtl88ee_fwlps_leave(hw);
  565. break; }
  566. case HW_VAR_H2C_FW_JOINBSSRPT:{
  567. u8 mstatus = *val;
  568. u8 tmp_regcr, tmp_reg422, bcnvalid_reg;
  569. u8 count = 0, dlbcn_count = 0;
  570. bool b_recover = false;
  571. if (mstatus == RT_MEDIA_CONNECT) {
  572. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
  573. NULL);
  574. tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
  575. rtl_write_byte(rtlpriv, REG_CR + 1,
  576. (tmp_regcr | BIT(0)));
  577. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(3));
  578. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(4), 0);
  579. tmp_reg422 =
  580. rtl_read_byte(rtlpriv,
  581. REG_FWHW_TXQ_CTRL + 2);
  582. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
  583. tmp_reg422 & (~BIT(6)));
  584. if (tmp_reg422 & BIT(6))
  585. b_recover = true;
  586. do {
  587. bcnvalid_reg = rtl_read_byte(rtlpriv,
  588. REG_TDECTRL+2);
  589. rtl_write_byte(rtlpriv, REG_TDECTRL+2,
  590. (bcnvalid_reg | BIT(0)));
  591. _rtl88ee_return_beacon_queue_skb(hw);
  592. rtl88e_set_fw_rsvdpagepkt(hw, 0);
  593. bcnvalid_reg = rtl_read_byte(rtlpriv,
  594. REG_TDECTRL+2);
  595. count = 0;
  596. while (!(bcnvalid_reg & BIT(0)) && count < 20) {
  597. count++;
  598. udelay(10);
  599. bcnvalid_reg =
  600. rtl_read_byte(rtlpriv, REG_TDECTRL+2);
  601. }
  602. dlbcn_count++;
  603. } while (!(bcnvalid_reg & BIT(0)) && dlbcn_count < 5);
  604. if (bcnvalid_reg & BIT(0))
  605. rtl_write_byte(rtlpriv, REG_TDECTRL+2, BIT(0));
  606. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  607. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(4));
  608. if (b_recover) {
  609. rtl_write_byte(rtlpriv,
  610. REG_FWHW_TXQ_CTRL + 2,
  611. tmp_reg422);
  612. }
  613. rtl_write_byte(rtlpriv, REG_CR + 1,
  614. (tmp_regcr & ~(BIT(0))));
  615. }
  616. rtl88e_set_fw_joinbss_report_cmd(hw, (*(u8 *)val));
  617. break; }
  618. case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
  619. rtl88e_set_p2p_ps_offload_cmd(hw, *val);
  620. break;
  621. case HW_VAR_AID:{
  622. u16 u2btmp;
  623. u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
  624. u2btmp &= 0xC000;
  625. rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
  626. mac->assoc_id));
  627. break; }
  628. case HW_VAR_CORRECT_TSF:{
  629. u8 btype_ibss = *val;
  630. if (btype_ibss)
  631. _rtl88ee_stop_tx_beacon(hw);
  632. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(3));
  633. rtl_write_dword(rtlpriv, REG_TSFTR,
  634. (u32)(mac->tsf & 0xffffffff));
  635. rtl_write_dword(rtlpriv, REG_TSFTR + 4,
  636. (u32)((mac->tsf >> 32) & 0xffffffff));
  637. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  638. if (btype_ibss)
  639. _rtl88ee_resume_tx_beacon(hw);
  640. break; }
  641. case HW_VAR_KEEP_ALIVE: {
  642. u8 array[2];
  643. array[0] = 0xff;
  644. array[1] = *((u8 *)val);
  645. rtl88e_fill_h2c_cmd(hw, H2C_88E_KEEP_ALIVE_CTRL,
  646. 2, array);
  647. break; }
  648. default:
  649. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  650. "switch case not process %x\n", variable);
  651. break;
  652. }
  653. }
  654. static bool _rtl88ee_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
  655. {
  656. struct rtl_priv *rtlpriv = rtl_priv(hw);
  657. bool status = true;
  658. long count = 0;
  659. u32 value = _LLT_INIT_ADDR(address) | _LLT_INIT_DATA(data) |
  660. _LLT_OP(_LLT_WRITE_ACCESS);
  661. rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
  662. do {
  663. value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
  664. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
  665. break;
  666. if (count > POLLING_LLT_THRESHOLD) {
  667. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  668. "Failed to polling write LLT done at address %d!\n",
  669. address);
  670. status = false;
  671. break;
  672. }
  673. } while (++count);
  674. return status;
  675. }
  676. static bool _rtl88ee_llt_table_init(struct ieee80211_hw *hw)
  677. {
  678. struct rtl_priv *rtlpriv = rtl_priv(hw);
  679. unsigned short i;
  680. u8 txpktbuf_bndy;
  681. u8 maxpage;
  682. bool status;
  683. maxpage = 0xAF;
  684. txpktbuf_bndy = 0xAB;
  685. rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x01);
  686. rtl_write_dword(rtlpriv, REG_RQPN, 0x80730d29);
  687. /*0x2600 MaxRxBuff=10k-max(TxReportSize(64*8), WOLPattern(16*24)) */
  688. rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x25FF0000 | txpktbuf_bndy));
  689. rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
  690. rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
  691. rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
  692. rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
  693. rtl_write_byte(rtlpriv, REG_PBP, 0x11);
  694. rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
  695. for (i = 0; i < (txpktbuf_bndy - 1); i++) {
  696. status = _rtl88ee_llt_write(hw, i, i + 1);
  697. if (true != status)
  698. return status;
  699. }
  700. status = _rtl88ee_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
  701. if (true != status)
  702. return status;
  703. for (i = txpktbuf_bndy; i < maxpage; i++) {
  704. status = _rtl88ee_llt_write(hw, i, (i + 1));
  705. if (true != status)
  706. return status;
  707. }
  708. status = _rtl88ee_llt_write(hw, maxpage, txpktbuf_bndy);
  709. if (true != status)
  710. return status;
  711. return true;
  712. }
  713. static void _rtl88ee_gen_refresh_led_state(struct ieee80211_hw *hw)
  714. {
  715. struct rtl_priv *rtlpriv = rtl_priv(hw);
  716. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  717. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  718. struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
  719. if (rtlpriv->rtlhal.up_first_time)
  720. return;
  721. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
  722. rtl88ee_sw_led_on(hw, pLed0);
  723. else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
  724. rtl88ee_sw_led_on(hw, pLed0);
  725. else
  726. rtl88ee_sw_led_off(hw, pLed0);
  727. }
  728. static bool _rtl88ee_init_mac(struct ieee80211_hw *hw)
  729. {
  730. struct rtl_priv *rtlpriv = rtl_priv(hw);
  731. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  732. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  733. u8 bytetmp;
  734. u16 wordtmp;
  735. /*Disable XTAL OUTPUT for power saving. YJ,add,111206. */
  736. bytetmp = rtl_read_byte(rtlpriv, REG_XCK_OUT_CTRL) & (~BIT(0));
  737. rtl_write_byte(rtlpriv, REG_XCK_OUT_CTRL, bytetmp);
  738. /*Auto Power Down to CHIP-off State*/
  739. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) & (~BIT(7));
  740. rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
  741. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
  742. /* HW Power on sequence */
  743. if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK,
  744. PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK,
  745. RTL8188EE_NIC_ENABLE_FLOW)) {
  746. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  747. "init MAC Fail as rtl_hal_pwrseqcmdparsing\n");
  748. return false;
  749. }
  750. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO) | BIT(4);
  751. rtl_write_byte(rtlpriv, REG_APS_FSMCO, bytetmp);
  752. bytetmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG+2);
  753. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+2, bytetmp|BIT(2));
  754. bytetmp = rtl_read_byte(rtlpriv, REG_WATCH_DOG+1);
  755. rtl_write_byte(rtlpriv, REG_WATCH_DOG+1, bytetmp|BIT(7));
  756. bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL_EXT+1);
  757. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL_EXT+1, bytetmp|BIT(1));
  758. bytetmp = rtl_read_byte(rtlpriv, REG_TX_RPT_CTRL);
  759. rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL, bytetmp|BIT(1)|BIT(0));
  760. rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL+1, 2);
  761. rtl_write_word(rtlpriv, REG_TX_RPT_TIME, 0xcdf0);
  762. /*Add for wake up online*/
  763. bytetmp = rtl_read_byte(rtlpriv, REG_SYS_CLKR);
  764. rtl_write_byte(rtlpriv, REG_SYS_CLKR, bytetmp|BIT(3));
  765. bytetmp = rtl_read_byte(rtlpriv, REG_GPIO_MUXCFG+1);
  766. rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG+1, (bytetmp & (~BIT(4))));
  767. rtl_write_byte(rtlpriv, 0x367, 0x80);
  768. rtl_write_word(rtlpriv, REG_CR, 0x2ff);
  769. rtl_write_byte(rtlpriv, REG_CR+1, 0x06);
  770. rtl_write_byte(rtlpriv, MSR, 0x00);
  771. if (!rtlhal->mac_func_enable) {
  772. if (_rtl88ee_llt_table_init(hw) == false) {
  773. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  774. "LLT table init fail\n");
  775. return false;
  776. }
  777. }
  778. rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
  779. rtl_write_dword(rtlpriv, REG_HISRE, 0xffffffff);
  780. wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
  781. wordtmp &= 0xf;
  782. wordtmp |= 0xE771;
  783. rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
  784. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  785. rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xffff);
  786. rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
  787. rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
  788. ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) &
  789. DMA_BIT_MASK(32));
  790. rtl_write_dword(rtlpriv, REG_MGQ_DESA,
  791. (u64) rtlpci->tx_ring[MGNT_QUEUE].dma &
  792. DMA_BIT_MASK(32));
  793. rtl_write_dword(rtlpriv, REG_VOQ_DESA,
  794. (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
  795. rtl_write_dword(rtlpriv, REG_VIQ_DESA,
  796. (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
  797. rtl_write_dword(rtlpriv, REG_BEQ_DESA,
  798. (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
  799. rtl_write_dword(rtlpriv, REG_BKQ_DESA,
  800. (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
  801. rtl_write_dword(rtlpriv, REG_HQ_DESA,
  802. (u64) rtlpci->tx_ring[HIGH_QUEUE].dma &
  803. DMA_BIT_MASK(32));
  804. rtl_write_dword(rtlpriv, REG_RX_DESA,
  805. (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
  806. DMA_BIT_MASK(32));
  807. /* if we want to support 64 bit DMA, we should set it here,
  808. * but now we do not support 64 bit DMA
  809. */
  810. rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
  811. rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
  812. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+1, 0);/*Enable RX DMA */
  813. if (rtlhal->earlymode_enable) {/*Early mode enable*/
  814. bytetmp = rtl_read_byte(rtlpriv, REG_EARLY_MODE_CONTROL);
  815. bytetmp |= 0x1f;
  816. rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL, bytetmp);
  817. rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL+3, 0x81);
  818. }
  819. _rtl88ee_gen_refresh_led_state(hw);
  820. return true;
  821. }
  822. static void _rtl88ee_hw_configure(struct ieee80211_hw *hw)
  823. {
  824. struct rtl_priv *rtlpriv = rtl_priv(hw);
  825. u8 reg_bw_opmode;
  826. u32 reg_ratr, reg_prsr;
  827. reg_bw_opmode = BW_OPMODE_20MHZ;
  828. reg_ratr = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
  829. RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  830. reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  831. rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
  832. rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
  833. }
  834. static void _rtl88ee_enable_aspm_back_door(struct ieee80211_hw *hw)
  835. {
  836. struct rtl_priv *rtlpriv = rtl_priv(hw);
  837. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  838. u8 tmp1byte = 0;
  839. u32 tmp4byte = 0, count = 0;
  840. rtl_write_word(rtlpriv, 0x354, 0x8104);
  841. rtl_write_word(rtlpriv, 0x358, 0x24);
  842. rtl_write_word(rtlpriv, 0x350, 0x70c);
  843. rtl_write_byte(rtlpriv, 0x352, 0x2);
  844. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  845. count = 0;
  846. while (tmp1byte && count < 20) {
  847. udelay(10);
  848. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  849. count++;
  850. }
  851. if (0 == tmp1byte) {
  852. tmp4byte = rtl_read_dword(rtlpriv, 0x34c);
  853. rtl_write_dword(rtlpriv, 0x348, tmp4byte|BIT(31));
  854. rtl_write_word(rtlpriv, 0x350, 0xf70c);
  855. rtl_write_byte(rtlpriv, 0x352, 0x1);
  856. }
  857. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  858. count = 0;
  859. while (tmp1byte && count < 20) {
  860. udelay(10);
  861. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  862. count++;
  863. }
  864. rtl_write_word(rtlpriv, 0x350, 0x718);
  865. rtl_write_byte(rtlpriv, 0x352, 0x2);
  866. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  867. count = 0;
  868. while (tmp1byte && count < 20) {
  869. udelay(10);
  870. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  871. count++;
  872. }
  873. if (ppsc->support_backdoor || (0 == tmp1byte)) {
  874. tmp4byte = rtl_read_dword(rtlpriv, 0x34c);
  875. rtl_write_dword(rtlpriv, 0x348, tmp4byte|BIT(11)|BIT(12));
  876. rtl_write_word(rtlpriv, 0x350, 0xf718);
  877. rtl_write_byte(rtlpriv, 0x352, 0x1);
  878. }
  879. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  880. count = 0;
  881. while (tmp1byte && count < 20) {
  882. udelay(10);
  883. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  884. count++;
  885. }
  886. }
  887. void rtl88ee_enable_hw_security_config(struct ieee80211_hw *hw)
  888. {
  889. struct rtl_priv *rtlpriv = rtl_priv(hw);
  890. u8 sec_reg_value;
  891. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  892. "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
  893. rtlpriv->sec.pairwise_enc_algorithm,
  894. rtlpriv->sec.group_enc_algorithm);
  895. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  896. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  897. "not open hw encryption\n");
  898. return;
  899. }
  900. sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE;
  901. if (rtlpriv->sec.use_defaultkey) {
  902. sec_reg_value |= SCR_TXUSEDK;
  903. sec_reg_value |= SCR_RXUSEDK;
  904. }
  905. sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
  906. rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
  907. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  908. "The SECR-value %x\n", sec_reg_value);
  909. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
  910. }
  911. int rtl88ee_hw_init(struct ieee80211_hw *hw)
  912. {
  913. struct rtl_priv *rtlpriv = rtl_priv(hw);
  914. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  915. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  916. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  917. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  918. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  919. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  920. bool rtstatus = true;
  921. int err = 0;
  922. u8 tmp_u1b, u1byte;
  923. unsigned long flags;
  924. rtlpriv->rtlhal.being_init_adapter = true;
  925. /* As this function can take a very long time (up to 350 ms)
  926. * and can be called with irqs disabled, reenable the irqs
  927. * to let the other devices continue being serviced.
  928. *
  929. * It is safe doing so since our own interrupts will only be enabled
  930. * in a subsequent step.
  931. */
  932. local_save_flags(flags);
  933. local_irq_enable();
  934. rtlhal->fw_ready = false;
  935. rtlpriv->intf_ops->disable_aspm(hw);
  936. tmp_u1b = rtl_read_byte(rtlpriv, REG_SYS_CLKR+1);
  937. u1byte = rtl_read_byte(rtlpriv, REG_CR);
  938. if ((tmp_u1b & BIT(3)) && (u1byte != 0 && u1byte != 0xEA)) {
  939. rtlhal->mac_func_enable = true;
  940. } else {
  941. rtlhal->mac_func_enable = false;
  942. rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_88E;
  943. }
  944. rtstatus = _rtl88ee_init_mac(hw);
  945. if (rtstatus != true) {
  946. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n");
  947. err = 1;
  948. goto exit;
  949. }
  950. err = rtl88e_download_fw(hw, false);
  951. if (err) {
  952. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  953. "Failed to download FW. Init HW without FW now..\n");
  954. err = 1;
  955. goto exit;
  956. }
  957. rtlhal->fw_ready = true;
  958. /*fw related variable initialize */
  959. rtlhal->last_hmeboxnum = 0;
  960. rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_88E;
  961. rtlhal->fw_clk_change_in_progress = false;
  962. rtlhal->allow_sw_to_change_hwclc = false;
  963. ppsc->fw_current_inpsmode = false;
  964. rtl88e_phy_mac_config(hw);
  965. /* because last function modify RCR, so we update
  966. * rcr var here, or TP will unstable for receive_config
  967. * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
  968. * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
  969. */
  970. rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
  971. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  972. rtl88e_phy_bb_config(hw);
  973. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  974. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  975. rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
  976. rtl88e_phy_rf_config(hw);
  977. rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
  978. RF_CHNLBW, RFREG_OFFSET_MASK);
  979. rtlphy->rfreg_chnlval[0] = rtlphy->rfreg_chnlval[0] & 0xfff00fff;
  980. _rtl88ee_hw_configure(hw);
  981. rtl_cam_reset_all_entry(hw);
  982. rtl88ee_enable_hw_security_config(hw);
  983. rtlhal->mac_func_enable = true;
  984. ppsc->rfpwr_state = ERFON;
  985. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  986. _rtl88ee_enable_aspm_back_door(hw);
  987. rtlpriv->intf_ops->enable_aspm(hw);
  988. if (ppsc->rfpwr_state == ERFON) {
  989. if ((rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV) ||
  990. ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) &&
  991. (rtlhal->oem_id == RT_CID_819X_HP))) {
  992. rtl88e_phy_set_rfpath_switch(hw, true);
  993. rtlpriv->dm.fat_table.rx_idle_ant = MAIN_ANT;
  994. } else {
  995. rtl88e_phy_set_rfpath_switch(hw, false);
  996. rtlpriv->dm.fat_table.rx_idle_ant = AUX_ANT;
  997. }
  998. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "rx idle ant %s\n",
  999. (rtlpriv->dm.fat_table.rx_idle_ant == MAIN_ANT) ?
  1000. ("MAIN_ANT") : ("AUX_ANT"));
  1001. if (rtlphy->iqk_initialized) {
  1002. rtl88e_phy_iq_calibrate(hw, true);
  1003. } else {
  1004. rtl88e_phy_iq_calibrate(hw, false);
  1005. rtlphy->iqk_initialized = true;
  1006. }
  1007. rtl88e_dm_check_txpower_tracking(hw);
  1008. rtl88e_phy_lc_calibrate(hw);
  1009. }
  1010. tmp_u1b = efuse_read_1byte(hw, 0x1FA);
  1011. if (!(tmp_u1b & BIT(0))) {
  1012. rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
  1013. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "PA BIAS path A\n");
  1014. }
  1015. if (!(tmp_u1b & BIT(4))) {
  1016. tmp_u1b = rtl_read_byte(rtlpriv, 0x16);
  1017. tmp_u1b &= 0x0F;
  1018. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
  1019. udelay(10);
  1020. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
  1021. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "under 1.5V\n");
  1022. }
  1023. rtl_write_byte(rtlpriv, REG_NAV_CTRL+2, ((30000+127)/128));
  1024. rtl88e_dm_init(hw);
  1025. exit:
  1026. local_irq_restore(flags);
  1027. rtlpriv->rtlhal.being_init_adapter = false;
  1028. return err;
  1029. }
  1030. static enum version_8188e _rtl88ee_read_chip_version(struct ieee80211_hw *hw)
  1031. {
  1032. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1033. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1034. enum version_8188e version = VERSION_UNKNOWN;
  1035. u32 value32;
  1036. value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
  1037. if (value32 & TRP_VAUX_EN) {
  1038. version = (enum version_8188e) VERSION_TEST_CHIP_88E;
  1039. } else {
  1040. version = NORMAL_CHIP;
  1041. version = version | ((value32 & TYPE_ID) ? RF_TYPE_2T2R : 0);
  1042. version = version | ((value32 & VENDOR_ID) ?
  1043. CHIP_VENDOR_UMC : 0);
  1044. }
  1045. rtlphy->rf_type = RF_1T1R;
  1046. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1047. "Chip RF Type: %s\n", (rtlphy->rf_type == RF_2T2R) ?
  1048. "RF_2T2R" : "RF_1T1R");
  1049. return version;
  1050. }
  1051. static int _rtl88ee_set_media_status(struct ieee80211_hw *hw,
  1052. enum nl80211_iftype type)
  1053. {
  1054. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1055. u8 bt_msr = rtl_read_byte(rtlpriv, MSR) & 0xfc;
  1056. enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
  1057. u8 mode = MSR_NOLINK;
  1058. switch (type) {
  1059. case NL80211_IFTYPE_UNSPECIFIED:
  1060. mode = MSR_NOLINK;
  1061. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1062. "Set Network type to NO LINK!\n");
  1063. break;
  1064. case NL80211_IFTYPE_ADHOC:
  1065. case NL80211_IFTYPE_MESH_POINT:
  1066. mode = MSR_ADHOC;
  1067. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1068. "Set Network type to Ad Hoc!\n");
  1069. break;
  1070. case NL80211_IFTYPE_STATION:
  1071. mode = MSR_INFRA;
  1072. ledaction = LED_CTL_LINK;
  1073. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1074. "Set Network type to STA!\n");
  1075. break;
  1076. case NL80211_IFTYPE_AP:
  1077. mode = MSR_AP;
  1078. ledaction = LED_CTL_LINK;
  1079. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1080. "Set Network type to AP!\n");
  1081. break;
  1082. default:
  1083. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1084. "Network type %d not support!\n", type);
  1085. return 1;
  1086. break;
  1087. }
  1088. /* MSR_INFRA == Link in infrastructure network;
  1089. * MSR_ADHOC == Link in ad hoc network;
  1090. * Therefore, check link state is necessary.
  1091. *
  1092. * MSR_AP == AP mode; link state is not cared here.
  1093. */
  1094. if (mode != MSR_AP && rtlpriv->mac80211.link_state < MAC80211_LINKED) {
  1095. mode = MSR_NOLINK;
  1096. ledaction = LED_CTL_NO_LINK;
  1097. }
  1098. if (mode == MSR_NOLINK || mode == MSR_INFRA) {
  1099. _rtl88ee_stop_tx_beacon(hw);
  1100. _rtl88ee_enable_bcn_sub_func(hw);
  1101. } else if (mode == MSR_ADHOC || mode == MSR_AP) {
  1102. _rtl88ee_resume_tx_beacon(hw);
  1103. _rtl88ee_disable_bcn_sub_func(hw);
  1104. } else {
  1105. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1106. "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
  1107. mode);
  1108. }
  1109. rtl_write_byte(rtlpriv, MSR, bt_msr | mode);
  1110. rtlpriv->cfg->ops->led_control(hw, ledaction);
  1111. if (mode == MSR_AP)
  1112. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
  1113. else
  1114. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
  1115. return 0;
  1116. }
  1117. void rtl88ee_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
  1118. {
  1119. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1120. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1121. u32 reg_rcr = rtlpci->receive_config;
  1122. if (rtlpriv->psc.rfpwr_state != ERFON)
  1123. return;
  1124. if (check_bssid == true) {
  1125. reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
  1126. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
  1127. (u8 *)(&reg_rcr));
  1128. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(4));
  1129. } else if (check_bssid == false) {
  1130. reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
  1131. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(4), 0);
  1132. rtlpriv->cfg->ops->set_hw_reg(hw,
  1133. HW_VAR_RCR, (u8 *)(&reg_rcr));
  1134. }
  1135. }
  1136. int rtl88ee_set_network_type(struct ieee80211_hw *hw,
  1137. enum nl80211_iftype type)
  1138. {
  1139. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1140. if (_rtl88ee_set_media_status(hw, type))
  1141. return -EOPNOTSUPP;
  1142. if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
  1143. if (type != NL80211_IFTYPE_AP &&
  1144. type != NL80211_IFTYPE_MESH_POINT)
  1145. rtl88ee_set_check_bssid(hw, true);
  1146. } else {
  1147. rtl88ee_set_check_bssid(hw, false);
  1148. }
  1149. return 0;
  1150. }
  1151. /* don't set REG_EDCA_BE_PARAM here
  1152. * because mac80211 will send pkt when scan
  1153. */
  1154. void rtl88ee_set_qos(struct ieee80211_hw *hw, int aci)
  1155. {
  1156. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1157. rtl88e_dm_init_edca_turbo(hw);
  1158. switch (aci) {
  1159. case AC1_BK:
  1160. rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
  1161. break;
  1162. case AC0_BE:
  1163. break;
  1164. case AC2_VI:
  1165. rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
  1166. break;
  1167. case AC3_VO:
  1168. rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
  1169. break;
  1170. default:
  1171. RT_ASSERT(false, "invalid aci: %d !\n", aci);
  1172. break;
  1173. }
  1174. }
  1175. void rtl88ee_enable_interrupt(struct ieee80211_hw *hw)
  1176. {
  1177. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1178. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1179. rtl_write_dword(rtlpriv, REG_HIMR,
  1180. rtlpci->irq_mask[0] & 0xFFFFFFFF);
  1181. rtl_write_dword(rtlpriv, REG_HIMRE,
  1182. rtlpci->irq_mask[1] & 0xFFFFFFFF);
  1183. rtlpci->irq_enabled = true;
  1184. /* there are some C2H CMDs have been sent
  1185. * before system interrupt is enabled, e.g., C2H, CPWM.
  1186. * So we need to clear all C2H events that FW has notified,
  1187. * otherwise FW won't schedule any commands anymore.
  1188. */
  1189. rtl_write_byte(rtlpriv, REG_C2HEVT_CLEAR, 0);
  1190. /*enable system interrupt*/
  1191. rtl_write_dword(rtlpriv, REG_HSIMR,
  1192. rtlpci->sys_irq_mask & 0xFFFFFFFF);
  1193. }
  1194. void rtl88ee_disable_interrupt(struct ieee80211_hw *hw)
  1195. {
  1196. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1197. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1198. rtl_write_dword(rtlpriv, REG_HIMR, IMR_DISABLED);
  1199. rtl_write_dword(rtlpriv, REG_HIMRE, IMR_DISABLED);
  1200. rtlpci->irq_enabled = false;
  1201. /*synchronize_irq(rtlpci->pdev->irq);*/
  1202. }
  1203. static void _rtl88ee_poweroff_adapter(struct ieee80211_hw *hw)
  1204. {
  1205. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1206. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1207. u8 u1b_tmp;
  1208. u32 count = 0;
  1209. rtlhal->mac_func_enable = false;
  1210. rtlpriv->intf_ops->enable_aspm(hw);
  1211. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "POWER OFF adapter\n");
  1212. u1b_tmp = rtl_read_byte(rtlpriv, REG_TX_RPT_CTRL);
  1213. rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL, u1b_tmp & (~BIT(1)));
  1214. u1b_tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
  1215. while (!(u1b_tmp & BIT(1)) && (count++ < 100)) {
  1216. udelay(10);
  1217. u1b_tmp = rtl_read_byte(rtlpriv, REG_RXDMA_CONTROL);
  1218. count++;
  1219. }
  1220. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+1, 0xFF);
  1221. rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  1222. PWR_INTF_PCI_MSK,
  1223. RTL8188EE_NIC_LPS_ENTER_FLOW);
  1224. rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
  1225. if ((rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) && rtlhal->fw_ready)
  1226. rtl88e_firmware_selfreset(hw);
  1227. u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1);
  1228. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, (u1b_tmp & (~BIT(2))));
  1229. rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
  1230. u1b_tmp = rtl_read_byte(rtlpriv, REG_32K_CTRL);
  1231. rtl_write_byte(rtlpriv, REG_32K_CTRL, (u1b_tmp & (~BIT(0))));
  1232. rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
  1233. PWR_INTF_PCI_MSK, RTL8188EE_NIC_DISABLE_FLOW);
  1234. u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1);
  1235. rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp & (~BIT(3))));
  1236. u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL+1);
  1237. rtl_write_byte(rtlpriv, REG_RSV_CTRL+1, (u1b_tmp | BIT(3)));
  1238. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0E);
  1239. u1b_tmp = rtl_read_byte(rtlpriv, GPIO_IN);
  1240. rtl_write_byte(rtlpriv, GPIO_OUT, u1b_tmp);
  1241. rtl_write_byte(rtlpriv, GPIO_IO_SEL, 0x7F);
  1242. u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL);
  1243. rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL, (u1b_tmp << 4) | u1b_tmp);
  1244. u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL+1);
  1245. rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL+1, u1b_tmp | 0x0F);
  1246. rtl_write_dword(rtlpriv, REG_GPIO_IO_SEL_2+2, 0x00080808);
  1247. }
  1248. void rtl88ee_card_disable(struct ieee80211_hw *hw)
  1249. {
  1250. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1251. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1252. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1253. enum nl80211_iftype opmode;
  1254. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "RTL8188ee card disable\n");
  1255. mac->link_state = MAC80211_NOLINK;
  1256. opmode = NL80211_IFTYPE_UNSPECIFIED;
  1257. _rtl88ee_set_media_status(hw, opmode);
  1258. if (rtlpriv->rtlhal.driver_is_goingto_unload ||
  1259. ppsc->rfoff_reason > RF_CHANGE_BY_PS)
  1260. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1261. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1262. _rtl88ee_poweroff_adapter(hw);
  1263. /* after power off we should do iqk again */
  1264. rtlpriv->phy.iqk_initialized = false;
  1265. }
  1266. void rtl88ee_interrupt_recognized(struct ieee80211_hw *hw,
  1267. u32 *p_inta, u32 *p_intb)
  1268. {
  1269. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1270. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1271. *p_inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
  1272. rtl_write_dword(rtlpriv, ISR, *p_inta);
  1273. *p_intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1];
  1274. rtl_write_dword(rtlpriv, REG_HISRE, *p_intb);
  1275. }
  1276. void rtl88ee_set_beacon_related_registers(struct ieee80211_hw *hw)
  1277. {
  1278. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1279. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1280. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1281. u16 bcn_interval, atim_window;
  1282. bcn_interval = mac->beacon_interval;
  1283. atim_window = 2; /*FIX MERGE */
  1284. rtl88ee_disable_interrupt(hw);
  1285. rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
  1286. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1287. rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
  1288. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
  1289. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
  1290. rtl_write_byte(rtlpriv, 0x606, 0x30);
  1291. rtlpci->reg_bcn_ctrl_val |= BIT(3);
  1292. rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val);
  1293. /*rtl88ee_enable_interrupt(hw);*/
  1294. }
  1295. void rtl88ee_set_beacon_interval(struct ieee80211_hw *hw)
  1296. {
  1297. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1298. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1299. u16 bcn_interval = mac->beacon_interval;
  1300. RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
  1301. "beacon_interval:%d\n", bcn_interval);
  1302. /*rtl88ee_disable_interrupt(hw);*/
  1303. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1304. /*rtl88ee_enable_interrupt(hw);*/
  1305. }
  1306. void rtl88ee_update_interrupt_mask(struct ieee80211_hw *hw,
  1307. u32 add_msr, u32 rm_msr)
  1308. {
  1309. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1310. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1311. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
  1312. "add_msr:%x, rm_msr:%x\n", add_msr, rm_msr);
  1313. if (add_msr)
  1314. rtlpci->irq_mask[0] |= add_msr;
  1315. if (rm_msr)
  1316. rtlpci->irq_mask[0] &= (~rm_msr);
  1317. rtl88ee_disable_interrupt(hw);
  1318. rtl88ee_enable_interrupt(hw);
  1319. }
  1320. static u8 _rtl88e_get_chnl_group(u8 chnl)
  1321. {
  1322. u8 group = 0;
  1323. if (chnl < 3)
  1324. group = 0;
  1325. else if (chnl < 6)
  1326. group = 1;
  1327. else if (chnl < 9)
  1328. group = 2;
  1329. else if (chnl < 12)
  1330. group = 3;
  1331. else if (chnl < 14)
  1332. group = 4;
  1333. else if (chnl == 14)
  1334. group = 5;
  1335. return group;
  1336. }
  1337. static void set_24g_base(struct txpower_info_2g *pwrinfo24g, u32 rfpath)
  1338. {
  1339. int group, txcnt;
  1340. for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) {
  1341. pwrinfo24g->index_cck_base[rfpath][group] = 0x2D;
  1342. pwrinfo24g->index_bw40_base[rfpath][group] = 0x2D;
  1343. }
  1344. for (txcnt = 0; txcnt < MAX_TX_COUNT; txcnt++) {
  1345. if (txcnt == 0) {
  1346. pwrinfo24g->bw20_diff[rfpath][0] = 0x02;
  1347. pwrinfo24g->ofdm_diff[rfpath][0] = 0x04;
  1348. } else {
  1349. pwrinfo24g->bw20_diff[rfpath][txcnt] = 0xFE;
  1350. pwrinfo24g->bw40_diff[rfpath][txcnt] = 0xFE;
  1351. pwrinfo24g->cck_diff[rfpath][txcnt] = 0xFE;
  1352. pwrinfo24g->ofdm_diff[rfpath][txcnt] = 0xFE;
  1353. }
  1354. }
  1355. }
  1356. static void read_power_value_fromprom(struct ieee80211_hw *hw,
  1357. struct txpower_info_2g *pwrinfo24g,
  1358. struct txpower_info_5g *pwrinfo5g,
  1359. bool autoload_fail, u8 *hwinfo)
  1360. {
  1361. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1362. u32 rfpath, eeaddr = EEPROM_TX_PWR_INX, group, txcnt = 0;
  1363. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1364. "hal_ReadPowerValueFromPROM88E():PROMContent[0x%x]=0x%x\n",
  1365. (eeaddr+1), hwinfo[eeaddr+1]);
  1366. if (0xFF == hwinfo[eeaddr+1]) /*YJ,add,120316*/
  1367. autoload_fail = true;
  1368. if (autoload_fail) {
  1369. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1370. "auto load fail : Use Default value!\n");
  1371. for (rfpath = 0 ; rfpath < MAX_RF_PATH ; rfpath++) {
  1372. /* 2.4G default value */
  1373. set_24g_base(pwrinfo24g, rfpath);
  1374. }
  1375. return;
  1376. }
  1377. for (rfpath = 0 ; rfpath < MAX_RF_PATH ; rfpath++) {
  1378. /*2.4G default value*/
  1379. for (group = 0 ; group < MAX_CHNL_GROUP_24G; group++) {
  1380. pwrinfo24g->index_cck_base[rfpath][group] =
  1381. hwinfo[eeaddr++];
  1382. if (pwrinfo24g->index_cck_base[rfpath][group] == 0xFF)
  1383. pwrinfo24g->index_cck_base[rfpath][group] =
  1384. 0x2D;
  1385. }
  1386. for (group = 0 ; group < MAX_CHNL_GROUP_24G-1; group++) {
  1387. pwrinfo24g->index_bw40_base[rfpath][group] =
  1388. hwinfo[eeaddr++];
  1389. if (pwrinfo24g->index_bw40_base[rfpath][group] == 0xFF)
  1390. pwrinfo24g->index_bw40_base[rfpath][group] =
  1391. 0x2D;
  1392. }
  1393. pwrinfo24g->bw40_diff[rfpath][0] = 0;
  1394. if (hwinfo[eeaddr] == 0xFF) {
  1395. pwrinfo24g->bw20_diff[rfpath][0] = 0x02;
  1396. } else {
  1397. pwrinfo24g->bw20_diff[rfpath][0] =
  1398. (hwinfo[eeaddr]&0xf0)>>4;
  1399. /*bit sign number to 8 bit sign number*/
  1400. if (pwrinfo24g->bw20_diff[rfpath][0] & BIT(3))
  1401. pwrinfo24g->bw20_diff[rfpath][0] |= 0xF0;
  1402. }
  1403. if (hwinfo[eeaddr] == 0xFF) {
  1404. pwrinfo24g->ofdm_diff[rfpath][0] = 0x04;
  1405. } else {
  1406. pwrinfo24g->ofdm_diff[rfpath][0] =
  1407. (hwinfo[eeaddr]&0x0f);
  1408. /*bit sign number to 8 bit sign number*/
  1409. if (pwrinfo24g->ofdm_diff[rfpath][0] & BIT(3))
  1410. pwrinfo24g->ofdm_diff[rfpath][0] |= 0xF0;
  1411. }
  1412. pwrinfo24g->cck_diff[rfpath][0] = 0;
  1413. eeaddr++;
  1414. for (txcnt = 1; txcnt < MAX_TX_COUNT; txcnt++) {
  1415. if (hwinfo[eeaddr] == 0xFF) {
  1416. pwrinfo24g->bw40_diff[rfpath][txcnt] = 0xFE;
  1417. } else {
  1418. pwrinfo24g->bw40_diff[rfpath][txcnt] =
  1419. (hwinfo[eeaddr]&0xf0)>>4;
  1420. if (pwrinfo24g->bw40_diff[rfpath][txcnt] &
  1421. BIT(3))
  1422. pwrinfo24g->bw40_diff[rfpath][txcnt] |=
  1423. 0xF0;
  1424. }
  1425. if (hwinfo[eeaddr] == 0xFF) {
  1426. pwrinfo24g->bw20_diff[rfpath][txcnt] =
  1427. 0xFE;
  1428. } else {
  1429. pwrinfo24g->bw20_diff[rfpath][txcnt] =
  1430. (hwinfo[eeaddr]&0x0f);
  1431. if (pwrinfo24g->bw20_diff[rfpath][txcnt] &
  1432. BIT(3))
  1433. pwrinfo24g->bw20_diff[rfpath][txcnt] |=
  1434. 0xF0;
  1435. }
  1436. eeaddr++;
  1437. if (hwinfo[eeaddr] == 0xFF) {
  1438. pwrinfo24g->ofdm_diff[rfpath][txcnt] = 0xFE;
  1439. } else {
  1440. pwrinfo24g->ofdm_diff[rfpath][txcnt] =
  1441. (hwinfo[eeaddr]&0xf0)>>4;
  1442. if (pwrinfo24g->ofdm_diff[rfpath][txcnt] &
  1443. BIT(3))
  1444. pwrinfo24g->ofdm_diff[rfpath][txcnt] |=
  1445. 0xF0;
  1446. }
  1447. if (hwinfo[eeaddr] == 0xFF) {
  1448. pwrinfo24g->cck_diff[rfpath][txcnt] = 0xFE;
  1449. } else {
  1450. pwrinfo24g->cck_diff[rfpath][txcnt] =
  1451. (hwinfo[eeaddr]&0x0f);
  1452. if (pwrinfo24g->cck_diff[rfpath][txcnt] &
  1453. BIT(3))
  1454. pwrinfo24g->cck_diff[rfpath][txcnt] |=
  1455. 0xF0;
  1456. }
  1457. eeaddr++;
  1458. }
  1459. /*5G default value*/
  1460. for (group = 0 ; group < MAX_CHNL_GROUP_5G; group++) {
  1461. pwrinfo5g->index_bw40_base[rfpath][group] =
  1462. hwinfo[eeaddr++];
  1463. if (pwrinfo5g->index_bw40_base[rfpath][group] == 0xFF)
  1464. pwrinfo5g->index_bw40_base[rfpath][group] =
  1465. 0xFE;
  1466. }
  1467. pwrinfo5g->bw40_diff[rfpath][0] = 0;
  1468. if (hwinfo[eeaddr] == 0xFF) {
  1469. pwrinfo5g->bw20_diff[rfpath][0] = 0;
  1470. } else {
  1471. pwrinfo5g->bw20_diff[rfpath][0] =
  1472. (hwinfo[eeaddr]&0xf0)>>4;
  1473. if (pwrinfo5g->bw20_diff[rfpath][0] & BIT(3))
  1474. pwrinfo5g->bw20_diff[rfpath][0] |= 0xF0;
  1475. }
  1476. if (hwinfo[eeaddr] == 0xFF) {
  1477. pwrinfo5g->ofdm_diff[rfpath][0] = 0x04;
  1478. } else {
  1479. pwrinfo5g->ofdm_diff[rfpath][0] = (hwinfo[eeaddr]&0x0f);
  1480. if (pwrinfo5g->ofdm_diff[rfpath][0] & BIT(3))
  1481. pwrinfo5g->ofdm_diff[rfpath][0] |= 0xF0;
  1482. }
  1483. eeaddr++;
  1484. for (txcnt = 1; txcnt < MAX_TX_COUNT; txcnt++) {
  1485. if (hwinfo[eeaddr] == 0xFF) {
  1486. pwrinfo5g->bw40_diff[rfpath][txcnt] = 0xFE;
  1487. } else {
  1488. pwrinfo5g->bw40_diff[rfpath][txcnt] =
  1489. (hwinfo[eeaddr]&0xf0)>>4;
  1490. if (pwrinfo5g->bw40_diff[rfpath][txcnt] &
  1491. BIT(3))
  1492. pwrinfo5g->bw40_diff[rfpath][txcnt] |=
  1493. 0xF0;
  1494. }
  1495. if (hwinfo[eeaddr] == 0xFF) {
  1496. pwrinfo5g->bw20_diff[rfpath][txcnt] = 0xFE;
  1497. } else {
  1498. pwrinfo5g->bw20_diff[rfpath][txcnt] =
  1499. (hwinfo[eeaddr]&0x0f);
  1500. if (pwrinfo5g->bw20_diff[rfpath][txcnt] &
  1501. BIT(3))
  1502. pwrinfo5g->bw20_diff[rfpath][txcnt] |=
  1503. 0xF0;
  1504. }
  1505. eeaddr++;
  1506. }
  1507. if (hwinfo[eeaddr] == 0xFF) {
  1508. pwrinfo5g->ofdm_diff[rfpath][1] = 0xFE;
  1509. pwrinfo5g->ofdm_diff[rfpath][2] = 0xFE;
  1510. } else {
  1511. pwrinfo5g->ofdm_diff[rfpath][1] =
  1512. (hwinfo[eeaddr]&0xf0)>>4;
  1513. pwrinfo5g->ofdm_diff[rfpath][2] =
  1514. (hwinfo[eeaddr]&0x0f);
  1515. }
  1516. eeaddr++;
  1517. if (hwinfo[eeaddr] == 0xFF)
  1518. pwrinfo5g->ofdm_diff[rfpath][3] = 0xFE;
  1519. else
  1520. pwrinfo5g->ofdm_diff[rfpath][3] = (hwinfo[eeaddr]&0x0f);
  1521. eeaddr++;
  1522. for (txcnt = 1; txcnt < MAX_TX_COUNT; txcnt++) {
  1523. if (pwrinfo5g->ofdm_diff[rfpath][txcnt] == 0xFF)
  1524. pwrinfo5g->ofdm_diff[rfpath][txcnt] = 0xFE;
  1525. else if (pwrinfo5g->ofdm_diff[rfpath][txcnt] & BIT(3))
  1526. pwrinfo5g->ofdm_diff[rfpath][txcnt] |= 0xF0;
  1527. }
  1528. }
  1529. }
  1530. static void _rtl88ee_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
  1531. bool autoload_fail,
  1532. u8 *hwinfo)
  1533. {
  1534. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1535. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1536. struct txpower_info_2g pwrinfo24g;
  1537. struct txpower_info_5g pwrinfo5g;
  1538. u8 rf_path, index;
  1539. u8 i;
  1540. read_power_value_fromprom(hw, &pwrinfo24g,
  1541. &pwrinfo5g, autoload_fail, hwinfo);
  1542. for (rf_path = 0; rf_path < 2; rf_path++) {
  1543. for (i = 0; i < 14; i++) {
  1544. index = _rtl88e_get_chnl_group(i+1);
  1545. rtlefuse->txpwrlevel_cck[rf_path][i] =
  1546. pwrinfo24g.index_cck_base[rf_path][index];
  1547. rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
  1548. pwrinfo24g.index_bw40_base[rf_path][index];
  1549. rtlefuse->txpwr_ht20diff[rf_path][i] =
  1550. pwrinfo24g.bw20_diff[rf_path][0];
  1551. rtlefuse->txpwr_legacyhtdiff[rf_path][i] =
  1552. pwrinfo24g.ofdm_diff[rf_path][0];
  1553. }
  1554. for (i = 0; i < 14; i++) {
  1555. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1556. "RF(%d)-Ch(%d) [CCK / HT40_1S ] = [0x%x / 0x%x ]\n",
  1557. rf_path, i,
  1558. rtlefuse->txpwrlevel_cck[rf_path][i],
  1559. rtlefuse->txpwrlevel_ht40_1s[rf_path][i]);
  1560. }
  1561. }
  1562. if (!autoload_fail)
  1563. rtlefuse->eeprom_thermalmeter =
  1564. hwinfo[EEPROM_THERMAL_METER_88E];
  1565. else
  1566. rtlefuse->eeprom_thermalmeter = EEPROM_DEFAULT_THERMALMETER;
  1567. if (rtlefuse->eeprom_thermalmeter == 0xff || autoload_fail) {
  1568. rtlefuse->apk_thermalmeterignore = true;
  1569. rtlefuse->eeprom_thermalmeter = EEPROM_DEFAULT_THERMALMETER;
  1570. }
  1571. rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
  1572. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1573. "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
  1574. if (!autoload_fail) {
  1575. rtlefuse->eeprom_regulatory =
  1576. hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0x07;/*bit0~2*/
  1577. if (hwinfo[EEPROM_RF_BOARD_OPTION_88E] == 0xFF)
  1578. rtlefuse->eeprom_regulatory = 0;
  1579. } else {
  1580. rtlefuse->eeprom_regulatory = 0;
  1581. }
  1582. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1583. "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
  1584. }
  1585. static void _rtl88ee_read_adapter_info(struct ieee80211_hw *hw)
  1586. {
  1587. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1588. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1589. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1590. u16 i, usvalue;
  1591. u8 hwinfo[HWSET_MAX_SIZE];
  1592. u16 eeprom_id;
  1593. if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
  1594. rtl_efuse_shadow_map_update(hw);
  1595. memcpy(hwinfo, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
  1596. HWSET_MAX_SIZE);
  1597. } else if (rtlefuse->epromtype == EEPROM_93C46) {
  1598. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1599. "RTL819X Not boot from eeprom, check it !!");
  1600. return;
  1601. } else {
  1602. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1603. "boot from neither eeprom nor efuse, check it !!");
  1604. return;
  1605. }
  1606. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP\n",
  1607. hwinfo, HWSET_MAX_SIZE);
  1608. eeprom_id = *((u16 *)&hwinfo[0]);
  1609. if (eeprom_id != RTL8188E_EEPROM_ID) {
  1610. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1611. "EEPROM ID(%#x) is invalid!!\n", eeprom_id);
  1612. rtlefuse->autoload_failflag = true;
  1613. } else {
  1614. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1615. rtlefuse->autoload_failflag = false;
  1616. }
  1617. if (rtlefuse->autoload_failflag == true)
  1618. return;
  1619. /*VID DID SVID SDID*/
  1620. rtlefuse->eeprom_vid = *(u16 *)&hwinfo[EEPROM_VID];
  1621. rtlefuse->eeprom_did = *(u16 *)&hwinfo[EEPROM_DID];
  1622. rtlefuse->eeprom_svid = *(u16 *)&hwinfo[EEPROM_SVID];
  1623. rtlefuse->eeprom_smid = *(u16 *)&hwinfo[EEPROM_SMID];
  1624. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1625. "EEPROMId = 0x%4x\n", eeprom_id);
  1626. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1627. "EEPROM VID = 0x%4x\n", rtlefuse->eeprom_vid);
  1628. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1629. "EEPROM DID = 0x%4x\n", rtlefuse->eeprom_did);
  1630. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1631. "EEPROM SVID = 0x%4x\n", rtlefuse->eeprom_svid);
  1632. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1633. "EEPROM SMID = 0x%4x\n", rtlefuse->eeprom_smid);
  1634. /*customer ID*/
  1635. rtlefuse->eeprom_oemid = hwinfo[EEPROM_CUSTOMER_ID];
  1636. if (rtlefuse->eeprom_oemid == 0xFF)
  1637. rtlefuse->eeprom_oemid = 0;
  1638. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1639. "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid);
  1640. /*EEPROM version*/
  1641. rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
  1642. /*mac address*/
  1643. for (i = 0; i < 6; i += 2) {
  1644. usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
  1645. *((u16 *)(&rtlefuse->dev_addr[i])) = usvalue;
  1646. }
  1647. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1648. "dev_addr: %pM\n", rtlefuse->dev_addr);
  1649. /*channel plan */
  1650. rtlefuse->eeprom_channelplan = hwinfo[EEPROM_CHANNELPLAN];
  1651. /* set channel plan from efuse */
  1652. rtlefuse->channel_plan = rtlefuse->eeprom_channelplan;
  1653. /*tx power*/
  1654. _rtl88ee_read_txpower_info_from_hwpg(hw,
  1655. rtlefuse->autoload_failflag,
  1656. hwinfo);
  1657. rtlefuse->txpwr_fromeprom = true;
  1658. rtl8188ee_read_bt_coexist_info_from_hwpg(hw,
  1659. rtlefuse->autoload_failflag,
  1660. hwinfo);
  1661. /*board type*/
  1662. rtlefuse->board_type =
  1663. ((hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0xE0) >> 5);
  1664. rtlhal->board_type = rtlefuse->board_type;
  1665. /*Wake on wlan*/
  1666. rtlefuse->wowlan_enable =
  1667. ((hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & 0x40) >> 6);
  1668. /*parse xtal*/
  1669. rtlefuse->crystalcap = hwinfo[EEPROM_XTAL_88E];
  1670. if (hwinfo[EEPROM_XTAL_88E])
  1671. rtlefuse->crystalcap = 0x20;
  1672. /*antenna diversity*/
  1673. rtlefuse->antenna_div_cfg =
  1674. (hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0x18) >> 3;
  1675. if (hwinfo[EEPROM_RF_BOARD_OPTION_88E] == 0xFF)
  1676. rtlefuse->antenna_div_cfg = 0;
  1677. if (rtlpriv->btcoexist.eeprom_bt_coexist != 0 &&
  1678. rtlpriv->btcoexist.eeprom_bt_ant_num == ANT_X1)
  1679. rtlefuse->antenna_div_cfg = 0;
  1680. rtlefuse->antenna_div_type = hwinfo[EEPROM_RF_ANTENNA_OPT_88E];
  1681. if (rtlefuse->antenna_div_type == 0xFF)
  1682. rtlefuse->antenna_div_type = 0x01;
  1683. if (rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV ||
  1684. rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)
  1685. rtlefuse->antenna_div_cfg = 1;
  1686. if (rtlhal->oem_id == RT_CID_DEFAULT) {
  1687. switch (rtlefuse->eeprom_oemid) {
  1688. case EEPROM_CID_DEFAULT:
  1689. if (rtlefuse->eeprom_did == 0x8179) {
  1690. if (rtlefuse->eeprom_svid == 0x1025) {
  1691. rtlhal->oem_id = RT_CID_819X_ACER;
  1692. } else if ((rtlefuse->eeprom_svid == 0x10EC &&
  1693. rtlefuse->eeprom_smid == 0x0179) ||
  1694. (rtlefuse->eeprom_svid == 0x17AA &&
  1695. rtlefuse->eeprom_smid == 0x0179)) {
  1696. rtlhal->oem_id = RT_CID_819X_LENOVO;
  1697. } else if (rtlefuse->eeprom_svid == 0x103c &&
  1698. rtlefuse->eeprom_smid == 0x197d) {
  1699. rtlhal->oem_id = RT_CID_819X_HP;
  1700. } else {
  1701. rtlhal->oem_id = RT_CID_DEFAULT;
  1702. }
  1703. } else {
  1704. rtlhal->oem_id = RT_CID_DEFAULT;
  1705. }
  1706. break;
  1707. case EEPROM_CID_TOSHIBA:
  1708. rtlhal->oem_id = RT_CID_TOSHIBA;
  1709. break;
  1710. case EEPROM_CID_QMI:
  1711. rtlhal->oem_id = RT_CID_819X_QMI;
  1712. break;
  1713. case EEPROM_CID_WHQL:
  1714. default:
  1715. rtlhal->oem_id = RT_CID_DEFAULT;
  1716. break;
  1717. }
  1718. }
  1719. }
  1720. static void _rtl88ee_hal_customized_behavior(struct ieee80211_hw *hw)
  1721. {
  1722. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1723. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1724. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1725. pcipriv->ledctl.led_opendrain = true;
  1726. switch (rtlhal->oem_id) {
  1727. case RT_CID_819X_HP:
  1728. pcipriv->ledctl.led_opendrain = true;
  1729. break;
  1730. case RT_CID_819X_LENOVO:
  1731. case RT_CID_DEFAULT:
  1732. case RT_CID_TOSHIBA:
  1733. case RT_CID_CCX:
  1734. case RT_CID_819X_ACER:
  1735. case RT_CID_WHQL:
  1736. default:
  1737. break;
  1738. }
  1739. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1740. "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
  1741. }
  1742. void rtl88ee_read_eeprom_info(struct ieee80211_hw *hw)
  1743. {
  1744. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1745. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1746. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1747. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1748. u8 tmp_u1b;
  1749. rtlhal->version = _rtl88ee_read_chip_version(hw);
  1750. if (get_rf_type(rtlphy) == RF_1T1R)
  1751. rtlpriv->dm.rfpath_rxenable[0] = true;
  1752. else
  1753. rtlpriv->dm.rfpath_rxenable[0] =
  1754. rtlpriv->dm.rfpath_rxenable[1] = true;
  1755. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
  1756. rtlhal->version);
  1757. tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
  1758. if (tmp_u1b & BIT(4)) {
  1759. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
  1760. rtlefuse->epromtype = EEPROM_93C46;
  1761. } else {
  1762. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
  1763. rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
  1764. }
  1765. if (tmp_u1b & BIT(5)) {
  1766. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1767. rtlefuse->autoload_failflag = false;
  1768. _rtl88ee_read_adapter_info(hw);
  1769. } else {
  1770. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Autoload ERR!!\n");
  1771. }
  1772. _rtl88ee_hal_customized_behavior(hw);
  1773. }
  1774. static void rtl88ee_update_hal_rate_table(struct ieee80211_hw *hw,
  1775. struct ieee80211_sta *sta)
  1776. {
  1777. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1778. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1779. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1780. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1781. u32 ratr_value;
  1782. u8 ratr_index = 0;
  1783. u8 b_nmode = mac->ht_enable;
  1784. /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
  1785. u16 shortgi_rate;
  1786. u32 tmp_ratr_value;
  1787. u8 curtxbw_40mhz = mac->bw_40;
  1788. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1789. 1 : 0;
  1790. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1791. 1 : 0;
  1792. enum wireless_mode wirelessmode = mac->mode;
  1793. u32 ratr_mask;
  1794. if (rtlhal->current_bandtype == BAND_ON_5G)
  1795. ratr_value = sta->supp_rates[1] << 4;
  1796. else
  1797. ratr_value = sta->supp_rates[0];
  1798. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1799. ratr_value = 0xfff;
  1800. ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1801. sta->ht_cap.mcs.rx_mask[0] << 12);
  1802. switch (wirelessmode) {
  1803. case WIRELESS_MODE_B:
  1804. if (ratr_value & 0x0000000c)
  1805. ratr_value &= 0x0000000d;
  1806. else
  1807. ratr_value &= 0x0000000f;
  1808. break;
  1809. case WIRELESS_MODE_G:
  1810. ratr_value &= 0x00000FF5;
  1811. break;
  1812. case WIRELESS_MODE_N_24G:
  1813. case WIRELESS_MODE_N_5G:
  1814. b_nmode = 1;
  1815. if (get_rf_type(rtlphy) == RF_1T2R ||
  1816. get_rf_type(rtlphy) == RF_1T1R)
  1817. ratr_mask = 0x000ff005;
  1818. else
  1819. ratr_mask = 0x0f0ff005;
  1820. ratr_value &= ratr_mask;
  1821. break;
  1822. default:
  1823. if (rtlphy->rf_type == RF_1T2R)
  1824. ratr_value &= 0x000ff0ff;
  1825. else
  1826. ratr_value &= 0x0f0ff0ff;
  1827. break;
  1828. }
  1829. if ((rtlpriv->btcoexist.bt_coexistence) &&
  1830. (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) &&
  1831. (rtlpriv->btcoexist.bt_cur_state) &&
  1832. (rtlpriv->btcoexist.bt_ant_isolation) &&
  1833. ((rtlpriv->btcoexist.bt_service == BT_SCO) ||
  1834. (rtlpriv->btcoexist.bt_service == BT_BUSY)))
  1835. ratr_value &= 0x0fffcfc0;
  1836. else
  1837. ratr_value &= 0x0FFFFFFF;
  1838. if (b_nmode &&
  1839. ((curtxbw_40mhz && curshortgi_40mhz) ||
  1840. (!curtxbw_40mhz && curshortgi_20mhz))) {
  1841. ratr_value |= 0x10000000;
  1842. tmp_ratr_value = (ratr_value >> 12);
  1843. for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
  1844. if ((1 << shortgi_rate) & tmp_ratr_value)
  1845. break;
  1846. }
  1847. shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
  1848. (shortgi_rate << 4) | (shortgi_rate);
  1849. }
  1850. rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
  1851. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1852. "%x\n", rtl_read_dword(rtlpriv, REG_ARFR0));
  1853. }
  1854. static void rtl88ee_update_hal_rate_mask(struct ieee80211_hw *hw,
  1855. struct ieee80211_sta *sta, u8 rssi_level)
  1856. {
  1857. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1858. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1859. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1860. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1861. struct rtl_sta_info *sta_entry = NULL;
  1862. u32 ratr_bitmap;
  1863. u8 ratr_index;
  1864. u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
  1865. ? 1 : 0;
  1866. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1867. 1 : 0;
  1868. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1869. 1 : 0;
  1870. enum wireless_mode wirelessmode = 0;
  1871. bool b_shortgi = false;
  1872. u8 rate_mask[5];
  1873. u8 macid = 0;
  1874. /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
  1875. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1876. wirelessmode = sta_entry->wireless_mode;
  1877. if (mac->opmode == NL80211_IFTYPE_STATION ||
  1878. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  1879. curtxbw_40mhz = mac->bw_40;
  1880. else if (mac->opmode == NL80211_IFTYPE_AP ||
  1881. mac->opmode == NL80211_IFTYPE_ADHOC)
  1882. macid = sta->aid + 1;
  1883. if (rtlhal->current_bandtype == BAND_ON_5G)
  1884. ratr_bitmap = sta->supp_rates[1] << 4;
  1885. else
  1886. ratr_bitmap = sta->supp_rates[0];
  1887. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1888. ratr_bitmap = 0xfff;
  1889. ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1890. sta->ht_cap.mcs.rx_mask[0] << 12);
  1891. switch (wirelessmode) {
  1892. case WIRELESS_MODE_B:
  1893. ratr_index = RATR_INX_WIRELESS_B;
  1894. if (ratr_bitmap & 0x0000000c)
  1895. ratr_bitmap &= 0x0000000d;
  1896. else
  1897. ratr_bitmap &= 0x0000000f;
  1898. break;
  1899. case WIRELESS_MODE_G:
  1900. ratr_index = RATR_INX_WIRELESS_GB;
  1901. if (rssi_level == 1)
  1902. ratr_bitmap &= 0x00000f00;
  1903. else if (rssi_level == 2)
  1904. ratr_bitmap &= 0x00000ff0;
  1905. else
  1906. ratr_bitmap &= 0x00000ff5;
  1907. break;
  1908. case WIRELESS_MODE_N_24G:
  1909. case WIRELESS_MODE_N_5G:
  1910. ratr_index = RATR_INX_WIRELESS_NGB;
  1911. if (rtlphy->rf_type == RF_1T2R ||
  1912. rtlphy->rf_type == RF_1T1R) {
  1913. if (curtxbw_40mhz) {
  1914. if (rssi_level == 1)
  1915. ratr_bitmap &= 0x000f0000;
  1916. else if (rssi_level == 2)
  1917. ratr_bitmap &= 0x000ff000;
  1918. else
  1919. ratr_bitmap &= 0x000ff015;
  1920. } else {
  1921. if (rssi_level == 1)
  1922. ratr_bitmap &= 0x000f0000;
  1923. else if (rssi_level == 2)
  1924. ratr_bitmap &= 0x000ff000;
  1925. else
  1926. ratr_bitmap &= 0x000ff005;
  1927. }
  1928. } else {
  1929. if (curtxbw_40mhz) {
  1930. if (rssi_level == 1)
  1931. ratr_bitmap &= 0x0f8f0000;
  1932. else if (rssi_level == 2)
  1933. ratr_bitmap &= 0x0f8ff000;
  1934. else
  1935. ratr_bitmap &= 0x0f8ff015;
  1936. } else {
  1937. if (rssi_level == 1)
  1938. ratr_bitmap &= 0x0f8f0000;
  1939. else if (rssi_level == 2)
  1940. ratr_bitmap &= 0x0f8ff000;
  1941. else
  1942. ratr_bitmap &= 0x0f8ff005;
  1943. }
  1944. }
  1945. /*}*/
  1946. if ((curtxbw_40mhz && curshortgi_40mhz) ||
  1947. (!curtxbw_40mhz && curshortgi_20mhz)) {
  1948. if (macid == 0)
  1949. b_shortgi = true;
  1950. else if (macid == 1)
  1951. b_shortgi = false;
  1952. }
  1953. break;
  1954. default:
  1955. ratr_index = RATR_INX_WIRELESS_NGB;
  1956. if (rtlphy->rf_type == RF_1T2R)
  1957. ratr_bitmap &= 0x000ff0ff;
  1958. else
  1959. ratr_bitmap &= 0x0f0ff0ff;
  1960. break;
  1961. }
  1962. sta_entry->ratr_index = ratr_index;
  1963. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1964. "ratr_bitmap :%x\n", ratr_bitmap);
  1965. *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
  1966. (ratr_index << 28);
  1967. rate_mask[4] = macid | (b_shortgi ? 0x20 : 0x00) | 0x80;
  1968. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1969. "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n",
  1970. ratr_index, ratr_bitmap,
  1971. rate_mask[0], rate_mask[1],
  1972. rate_mask[2], rate_mask[3],
  1973. rate_mask[4]);
  1974. rtl88e_fill_h2c_cmd(hw, H2C_88E_RA_MASK, 5, rate_mask);
  1975. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  1976. }
  1977. void rtl88ee_update_hal_rate_tbl(struct ieee80211_hw *hw,
  1978. struct ieee80211_sta *sta, u8 rssi_level)
  1979. {
  1980. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1981. if (rtlpriv->dm.useramask)
  1982. rtl88ee_update_hal_rate_mask(hw, sta, rssi_level);
  1983. else
  1984. rtl88ee_update_hal_rate_table(hw, sta);
  1985. }
  1986. void rtl88ee_update_channel_access_setting(struct ieee80211_hw *hw)
  1987. {
  1988. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1989. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1990. u16 sifs_timer;
  1991. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, &mac->slot_time);
  1992. if (!mac->ht_enable)
  1993. sifs_timer = 0x0a0a;
  1994. else
  1995. sifs_timer = 0x0e0e;
  1996. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
  1997. }
  1998. bool rtl88ee_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
  1999. {
  2000. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2001. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  2002. enum rf_pwrstate e_rfpowerstate_toset, cur_rfstate;
  2003. u32 u4tmp;
  2004. bool b_actuallyset = false;
  2005. if (rtlpriv->rtlhal.being_init_adapter)
  2006. return false;
  2007. if (ppsc->swrf_processing)
  2008. return false;
  2009. spin_lock(&rtlpriv->locks.rf_ps_lock);
  2010. if (ppsc->rfchange_inprogress) {
  2011. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  2012. return false;
  2013. } else {
  2014. ppsc->rfchange_inprogress = true;
  2015. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  2016. }
  2017. cur_rfstate = ppsc->rfpwr_state;
  2018. u4tmp = rtl_read_dword(rtlpriv, REG_GPIO_OUTPUT);
  2019. e_rfpowerstate_toset = (u4tmp & BIT(31)) ? ERFON : ERFOFF;
  2020. if (ppsc->hwradiooff && (e_rfpowerstate_toset == ERFON)) {
  2021. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  2022. "GPIOChangeRF - HW Radio ON, RF ON\n");
  2023. e_rfpowerstate_toset = ERFON;
  2024. ppsc->hwradiooff = false;
  2025. b_actuallyset = true;
  2026. } else if ((!ppsc->hwradiooff) &&
  2027. (e_rfpowerstate_toset == ERFOFF)) {
  2028. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  2029. "GPIOChangeRF - HW Radio OFF, RF OFF\n");
  2030. e_rfpowerstate_toset = ERFOFF;
  2031. ppsc->hwradiooff = true;
  2032. b_actuallyset = true;
  2033. }
  2034. if (b_actuallyset) {
  2035. spin_lock(&rtlpriv->locks.rf_ps_lock);
  2036. ppsc->rfchange_inprogress = false;
  2037. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  2038. } else {
  2039. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
  2040. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  2041. spin_lock(&rtlpriv->locks.rf_ps_lock);
  2042. ppsc->rfchange_inprogress = false;
  2043. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  2044. }
  2045. *valid = 1;
  2046. return !ppsc->hwradiooff;
  2047. }
  2048. void rtl88ee_set_key(struct ieee80211_hw *hw, u32 key_index,
  2049. u8 *p_macaddr, bool is_group, u8 enc_algo,
  2050. bool is_wepkey, bool clear_all)
  2051. {
  2052. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2053. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2054. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2055. u8 *macaddr = p_macaddr;
  2056. u32 entry_id = 0;
  2057. bool is_pairwise = false;
  2058. static u8 cam_const_addr[4][6] = {
  2059. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  2060. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  2061. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  2062. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  2063. };
  2064. static u8 cam_const_broad[] = {
  2065. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  2066. };
  2067. if (clear_all) {
  2068. u8 idx = 0;
  2069. u8 cam_offset = 0;
  2070. u8 clear_number = 5;
  2071. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  2072. for (idx = 0; idx < clear_number; idx++) {
  2073. rtl_cam_mark_invalid(hw, cam_offset + idx);
  2074. rtl_cam_empty_entry(hw, cam_offset + idx);
  2075. if (idx < 5) {
  2076. memset(rtlpriv->sec.key_buf[idx], 0,
  2077. MAX_KEY_LEN);
  2078. rtlpriv->sec.key_len[idx] = 0;
  2079. }
  2080. }
  2081. } else {
  2082. switch (enc_algo) {
  2083. case WEP40_ENCRYPTION:
  2084. enc_algo = CAM_WEP40;
  2085. break;
  2086. case WEP104_ENCRYPTION:
  2087. enc_algo = CAM_WEP104;
  2088. break;
  2089. case TKIP_ENCRYPTION:
  2090. enc_algo = CAM_TKIP;
  2091. break;
  2092. case AESCCMP_ENCRYPTION:
  2093. enc_algo = CAM_AES;
  2094. break;
  2095. default:
  2096. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  2097. "switch case not process\n");
  2098. enc_algo = CAM_TKIP;
  2099. break;
  2100. }
  2101. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  2102. macaddr = cam_const_addr[key_index];
  2103. entry_id = key_index;
  2104. } else {
  2105. if (is_group) {
  2106. macaddr = cam_const_broad;
  2107. entry_id = key_index;
  2108. } else {
  2109. if (mac->opmode == NL80211_IFTYPE_AP ||
  2110. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  2111. entry_id =
  2112. rtl_cam_get_free_entry(hw, p_macaddr);
  2113. if (entry_id >= TOTAL_CAM_ENTRY) {
  2114. RT_TRACE(rtlpriv, COMP_SEC,
  2115. DBG_EMERG,
  2116. "Can not find free hw security cam entry\n");
  2117. return;
  2118. }
  2119. } else {
  2120. entry_id = CAM_PAIRWISE_KEY_POSITION;
  2121. }
  2122. key_index = PAIRWISE_KEYIDX;
  2123. is_pairwise = true;
  2124. }
  2125. }
  2126. if (rtlpriv->sec.key_len[key_index] == 0) {
  2127. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2128. "delete one entry, entry_id is %d\n",
  2129. entry_id);
  2130. if (mac->opmode == NL80211_IFTYPE_AP ||
  2131. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  2132. rtl_cam_del_entry(hw, p_macaddr);
  2133. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  2134. } else {
  2135. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2136. "add one entry\n");
  2137. if (is_pairwise) {
  2138. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2139. "set Pairwise key\n");
  2140. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2141. entry_id, enc_algo,
  2142. CAM_CONFIG_NO_USEDK,
  2143. rtlpriv->sec.key_buf[key_index]);
  2144. } else {
  2145. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2146. "set group key\n");
  2147. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  2148. rtl_cam_add_one_entry(hw,
  2149. rtlefuse->dev_addr,
  2150. PAIRWISE_KEYIDX,
  2151. CAM_PAIRWISE_KEY_POSITION,
  2152. enc_algo,
  2153. CAM_CONFIG_NO_USEDK,
  2154. rtlpriv->sec.key_buf
  2155. [entry_id]);
  2156. }
  2157. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2158. entry_id, enc_algo,
  2159. CAM_CONFIG_NO_USEDK,
  2160. rtlpriv->sec.key_buf[entry_id]);
  2161. }
  2162. }
  2163. }
  2164. }
  2165. static void rtl8188ee_bt_var_init(struct ieee80211_hw *hw)
  2166. {
  2167. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2168. rtlpriv->btcoexist.bt_coexistence =
  2169. rtlpriv->btcoexist.eeprom_bt_coexist;
  2170. rtlpriv->btcoexist.bt_ant_num = rtlpriv->btcoexist.eeprom_bt_ant_num;
  2171. rtlpriv->btcoexist.bt_coexist_type = rtlpriv->btcoexist.eeprom_bt_type;
  2172. if (rtlpriv->btcoexist.reg_bt_iso == 2)
  2173. rtlpriv->btcoexist.bt_ant_isolation =
  2174. rtlpriv->btcoexist.eeprom_bt_ant_isol;
  2175. else
  2176. rtlpriv->btcoexist.bt_ant_isolation =
  2177. rtlpriv->btcoexist.reg_bt_iso;
  2178. rtlpriv->btcoexist.bt_radio_shared_type =
  2179. rtlpriv->btcoexist.eeprom_bt_radio_shared;
  2180. if (rtlpriv->btcoexist.bt_coexistence) {
  2181. if (rtlpriv->btcoexist.reg_bt_sco == 1)
  2182. rtlpriv->btcoexist.bt_service = BT_OTHER_ACTION;
  2183. else if (rtlpriv->btcoexist.reg_bt_sco == 2)
  2184. rtlpriv->btcoexist.bt_service = BT_SCO;
  2185. else if (rtlpriv->btcoexist.reg_bt_sco == 4)
  2186. rtlpriv->btcoexist.bt_service = BT_BUSY;
  2187. else if (rtlpriv->btcoexist.reg_bt_sco == 5)
  2188. rtlpriv->btcoexist.bt_service = BT_OTHERBUSY;
  2189. else
  2190. rtlpriv->btcoexist.bt_service = BT_IDLE;
  2191. rtlpriv->btcoexist.bt_edca_ul = 0;
  2192. rtlpriv->btcoexist.bt_edca_dl = 0;
  2193. rtlpriv->btcoexist.bt_rssi_state = 0xff;
  2194. }
  2195. }
  2196. void rtl8188ee_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
  2197. bool auto_load_fail, u8 *hwinfo)
  2198. {
  2199. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2200. u8 value;
  2201. if (!auto_load_fail) {
  2202. rtlpriv->btcoexist.eeprom_bt_coexist =
  2203. ((hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & 0xe0) >> 5);
  2204. if (hwinfo[EEPROM_RF_FEATURE_OPTION_88E] == 0xFF)
  2205. rtlpriv->btcoexist.eeprom_bt_coexist = 0;
  2206. value = hwinfo[EEPROM_RF_BT_SETTING_88E];
  2207. rtlpriv->btcoexist.eeprom_bt_type = ((value & 0xe) >> 1);
  2208. rtlpriv->btcoexist.eeprom_bt_ant_num = (value & 0x1);
  2209. rtlpriv->btcoexist.eeprom_bt_ant_isol = ((value & 0x10) >> 4);
  2210. rtlpriv->btcoexist.eeprom_bt_radio_shared =
  2211. ((value & 0x20) >> 5);
  2212. } else {
  2213. rtlpriv->btcoexist.eeprom_bt_coexist = 0;
  2214. rtlpriv->btcoexist.eeprom_bt_type = BT_2WIRE;
  2215. rtlpriv->btcoexist.eeprom_bt_ant_num = ANT_X2;
  2216. rtlpriv->btcoexist.eeprom_bt_ant_isol = 0;
  2217. rtlpriv->btcoexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
  2218. }
  2219. rtl8188ee_bt_var_init(hw);
  2220. }
  2221. void rtl8188ee_bt_reg_init(struct ieee80211_hw *hw)
  2222. {
  2223. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2224. /* 0:Low, 1:High, 2:From Efuse. */
  2225. rtlpriv->btcoexist.reg_bt_iso = 2;
  2226. /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
  2227. rtlpriv->btcoexist.reg_bt_sco = 3;
  2228. /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
  2229. rtlpriv->btcoexist.reg_bt_sco = 0;
  2230. }
  2231. void rtl8188ee_bt_hw_init(struct ieee80211_hw *hw)
  2232. {
  2233. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2234. struct rtl_phy *rtlphy = &rtlpriv->phy;
  2235. u8 u1_tmp;
  2236. if (rtlpriv->btcoexist.bt_coexistence &&
  2237. ((rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) ||
  2238. rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC8)) {
  2239. if (rtlpriv->btcoexist.bt_ant_isolation)
  2240. rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
  2241. u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) &
  2242. BIT_OFFSET_LEN_MASK_32(0, 1);
  2243. u1_tmp = u1_tmp |
  2244. ((rtlpriv->btcoexist.bt_ant_isolation == 1) ?
  2245. 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
  2246. ((rtlpriv->btcoexist.bt_service == BT_SCO) ?
  2247. 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
  2248. rtl_write_byte(rtlpriv, 0x4fd, u1_tmp);
  2249. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa);
  2250. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040);
  2251. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010);
  2252. /* Config to 1T1R. */
  2253. if (rtlphy->rf_type == RF_1T1R) {
  2254. u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE);
  2255. u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
  2256. rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp);
  2257. u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE);
  2258. u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
  2259. rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp);
  2260. }
  2261. }
  2262. }
  2263. void rtl88ee_suspend(struct ieee80211_hw *hw)
  2264. {
  2265. }
  2266. void rtl88ee_resume(struct ieee80211_hw *hw)
  2267. {
  2268. }