hw.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548
  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. hw,
  90. (u8 *)entry, true, HW_DESC_TXBUFF_ADDR),
  91. skb->len, PCI_DMA_TODEVICE);
  92. kfree_skb(skb);
  93. ring->idx = (ring->idx + 1) % ring->entries;
  94. }
  95. spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
  96. }
  97. static void _rtl88ee_disable_bcn_sub_func(struct ieee80211_hw *hw)
  98. {
  99. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(1), 0);
  100. }
  101. static void _rtl88ee_set_fw_clock_on(struct ieee80211_hw *hw,
  102. u8 rpwm_val, bool b_need_turn_off_ckk)
  103. {
  104. struct rtl_priv *rtlpriv = rtl_priv(hw);
  105. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  106. bool b_support_remote_wake_up;
  107. u32 count = 0, isr_regaddr, content;
  108. bool schedule_timer = b_need_turn_off_ckk;
  109. rtlpriv->cfg->ops->get_hw_reg(hw, HAL_DEF_WOWLAN,
  110. (u8 *)(&b_support_remote_wake_up));
  111. if (!rtlhal->fw_ready)
  112. return;
  113. if (!rtlpriv->psc.fw_current_inpsmode)
  114. return;
  115. while (1) {
  116. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  117. if (rtlhal->fw_clk_change_in_progress) {
  118. while (rtlhal->fw_clk_change_in_progress) {
  119. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  120. count++;
  121. udelay(100);
  122. if (count > 1000)
  123. return;
  124. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  125. }
  126. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  127. } else {
  128. rtlhal->fw_clk_change_in_progress = false;
  129. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  130. break;
  131. }
  132. }
  133. if (IS_IN_LOW_POWER_STATE_88E(rtlhal->fw_ps_state)) {
  134. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val);
  135. if (FW_PS_IS_ACK(rpwm_val)) {
  136. isr_regaddr = REG_HISR;
  137. content = rtl_read_dword(rtlpriv, isr_regaddr);
  138. while (!(content & IMR_CPWM) && (count < 500)) {
  139. udelay(50);
  140. count++;
  141. content = rtl_read_dword(rtlpriv, isr_regaddr);
  142. }
  143. if (content & IMR_CPWM) {
  144. rtl_write_word(rtlpriv, isr_regaddr, 0x0100);
  145. rtlhal->fw_ps_state = FW_PS_STATE_RF_ON_88E;
  146. RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD,
  147. "Receive CPWM INT!!! Set pHalData->FwPSState = %X\n",
  148. rtlhal->fw_ps_state);
  149. }
  150. }
  151. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  152. rtlhal->fw_clk_change_in_progress = false;
  153. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  154. if (schedule_timer) {
  155. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  156. jiffies + MSECS(10));
  157. }
  158. } else {
  159. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  160. rtlhal->fw_clk_change_in_progress = false;
  161. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  162. }
  163. }
  164. static void _rtl88ee_set_fw_clock_off(struct ieee80211_hw *hw,
  165. u8 rpwm_val)
  166. {
  167. struct rtl_priv *rtlpriv = rtl_priv(hw);
  168. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  169. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  170. struct rtl8192_tx_ring *ring;
  171. enum rf_pwrstate rtstate;
  172. bool schedule_timer = false;
  173. u8 queue;
  174. if (!rtlhal->fw_ready)
  175. return;
  176. if (!rtlpriv->psc.fw_current_inpsmode)
  177. return;
  178. if (!rtlhal->allow_sw_to_change_hwclc)
  179. return;
  180. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE, (u8 *)(&rtstate));
  181. if (rtstate == ERFOFF || rtlpriv->psc.inactive_pwrstate == ERFOFF)
  182. return;
  183. for (queue = 0; queue < RTL_PCI_MAX_TX_QUEUE_COUNT; queue++) {
  184. ring = &rtlpci->tx_ring[queue];
  185. if (skb_queue_len(&ring->queue)) {
  186. schedule_timer = true;
  187. break;
  188. }
  189. }
  190. if (schedule_timer) {
  191. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  192. jiffies + MSECS(10));
  193. return;
  194. }
  195. if (FW_PS_STATE(rtlhal->fw_ps_state) !=
  196. FW_PS_STATE_RF_OFF_LOW_PWR_88E) {
  197. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  198. if (!rtlhal->fw_clk_change_in_progress) {
  199. rtlhal->fw_clk_change_in_progress = true;
  200. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  201. rtlhal->fw_ps_state = FW_PS_STATE(rpwm_val);
  202. rtl_write_word(rtlpriv, REG_HISR, 0x0100);
  203. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
  204. &rpwm_val);
  205. spin_lock_bh(&rtlpriv->locks.fw_ps_lock);
  206. rtlhal->fw_clk_change_in_progress = false;
  207. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  208. } else {
  209. spin_unlock_bh(&rtlpriv->locks.fw_ps_lock);
  210. mod_timer(&rtlpriv->works.fw_clockoff_timer,
  211. jiffies + MSECS(10));
  212. }
  213. }
  214. }
  215. static void _rtl88ee_set_fw_ps_rf_on(struct ieee80211_hw *hw)
  216. {
  217. u8 rpwm_val = 0;
  218. rpwm_val |= (FW_PS_STATE_RF_OFF_88E | FW_PS_ACK);
  219. _rtl88ee_set_fw_clock_on(hw, rpwm_val, true);
  220. }
  221. static void _rtl88ee_set_fw_ps_rf_off_low_power(struct ieee80211_hw *hw)
  222. {
  223. u8 rpwm_val = 0;
  224. rpwm_val |= FW_PS_STATE_RF_OFF_LOW_PWR_88E;
  225. _rtl88ee_set_fw_clock_off(hw, rpwm_val);
  226. }
  227. void rtl88ee_fw_clk_off_timer_callback(struct timer_list *t)
  228. {
  229. struct rtl_priv *rtlpriv = from_timer(rtlpriv, t,
  230. works.fw_clockoff_timer);
  231. struct ieee80211_hw *hw = rtlpriv->hw;
  232. _rtl88ee_set_fw_ps_rf_off_low_power(hw);
  233. }
  234. static void _rtl88ee_fwlps_leave(struct ieee80211_hw *hw)
  235. {
  236. struct rtl_priv *rtlpriv = rtl_priv(hw);
  237. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  238. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  239. bool fw_current_inps = false;
  240. u8 rpwm_val = 0, fw_pwrmode = FW_PS_ACTIVE_MODE;
  241. if (ppsc->low_power_enable) {
  242. rpwm_val = (FW_PS_STATE_ALL_ON_88E|FW_PS_ACK);/* RF on */
  243. _rtl88ee_set_fw_clock_on(hw, rpwm_val, false);
  244. rtlhal->allow_sw_to_change_hwclc = false;
  245. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  246. &fw_pwrmode);
  247. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  248. (u8 *)(&fw_current_inps));
  249. } else {
  250. rpwm_val = FW_PS_STATE_ALL_ON_88E; /* RF on */
  251. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val);
  252. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  253. &fw_pwrmode);
  254. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  255. (u8 *)(&fw_current_inps));
  256. }
  257. }
  258. static void _rtl88ee_fwlps_enter(struct ieee80211_hw *hw)
  259. {
  260. struct rtl_priv *rtlpriv = rtl_priv(hw);
  261. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  262. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  263. bool fw_current_inps = true;
  264. u8 rpwm_val;
  265. if (ppsc->low_power_enable) {
  266. rpwm_val = FW_PS_STATE_RF_OFF_LOW_PWR_88E; /* RF off */
  267. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  268. (u8 *)(&fw_current_inps));
  269. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  270. &ppsc->fwctrl_psmode);
  271. rtlhal->allow_sw_to_change_hwclc = true;
  272. _rtl88ee_set_fw_clock_off(hw, rpwm_val);
  273. } else {
  274. rpwm_val = FW_PS_STATE_RF_OFF_88E; /* RF off */
  275. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_FW_PSMODE_STATUS,
  276. (u8 *)(&fw_current_inps));
  277. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  278. &ppsc->fwctrl_psmode);
  279. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, &rpwm_val);
  280. }
  281. }
  282. void rtl88ee_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  283. {
  284. struct rtl_priv *rtlpriv = rtl_priv(hw);
  285. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  286. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  287. switch (variable) {
  288. case HW_VAR_RCR:
  289. *((u32 *)(val)) = rtlpci->receive_config;
  290. break;
  291. case HW_VAR_RF_STATE:
  292. *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
  293. break;
  294. case HW_VAR_FWLPS_RF_ON:{
  295. enum rf_pwrstate rfstate;
  296. u32 val_rcr;
  297. rtlpriv->cfg->ops->get_hw_reg(hw,
  298. HW_VAR_RF_STATE,
  299. (u8 *)(&rfstate));
  300. if (rfstate == ERFOFF) {
  301. *((bool *)(val)) = true;
  302. } else {
  303. val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
  304. val_rcr &= 0x00070000;
  305. if (val_rcr)
  306. *((bool *)(val)) = false;
  307. else
  308. *((bool *)(val)) = true;
  309. }
  310. break; }
  311. case HW_VAR_FW_PSMODE_STATUS:
  312. *((bool *)(val)) = ppsc->fw_current_inpsmode;
  313. break;
  314. case HW_VAR_CORRECT_TSF:{
  315. u64 tsf;
  316. u32 *ptsf_low = (u32 *)&tsf;
  317. u32 *ptsf_high = ((u32 *)&tsf) + 1;
  318. *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
  319. *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
  320. *((u64 *)(val)) = tsf;
  321. break; }
  322. case HAL_DEF_WOWLAN:
  323. break;
  324. default:
  325. pr_err("switch case %#x not processed\n", variable);
  326. break;
  327. }
  328. }
  329. void rtl88ee_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  330. {
  331. struct rtl_priv *rtlpriv = rtl_priv(hw);
  332. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  333. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  334. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  335. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  336. u8 idx;
  337. switch (variable) {
  338. case HW_VAR_ETHER_ADDR:
  339. for (idx = 0; idx < ETH_ALEN; idx++) {
  340. rtl_write_byte(rtlpriv, (REG_MACID + idx),
  341. val[idx]);
  342. }
  343. break;
  344. case HW_VAR_BASIC_RATE:{
  345. u16 b_rate_cfg = ((u16 *)val)[0];
  346. u8 rate_index = 0;
  347. b_rate_cfg = b_rate_cfg & 0x15f;
  348. b_rate_cfg |= 0x01;
  349. rtl_write_byte(rtlpriv, REG_RRSR, b_rate_cfg & 0xff);
  350. rtl_write_byte(rtlpriv, REG_RRSR + 1,
  351. (b_rate_cfg >> 8) & 0xff);
  352. while (b_rate_cfg > 0x1) {
  353. b_rate_cfg = (b_rate_cfg >> 1);
  354. rate_index++;
  355. }
  356. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
  357. rate_index);
  358. break;
  359. }
  360. case HW_VAR_BSSID:
  361. for (idx = 0; idx < ETH_ALEN; idx++) {
  362. rtl_write_byte(rtlpriv, (REG_BSSID + idx),
  363. val[idx]);
  364. }
  365. break;
  366. case HW_VAR_SIFS:
  367. rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
  368. rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
  369. rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
  370. rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
  371. if (!mac->ht_enable)
  372. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  373. 0x0e0e);
  374. else
  375. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  376. *((u16 *)val));
  377. break;
  378. case HW_VAR_SLOT_TIME:{
  379. u8 e_aci;
  380. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  381. "HW_VAR_SLOT_TIME %x\n", val[0]);
  382. rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
  383. for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
  384. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM,
  385. &e_aci);
  386. }
  387. break;
  388. }
  389. case HW_VAR_ACK_PREAMBLE:{
  390. u8 reg_tmp;
  391. u8 short_preamble = (bool)*val;
  392. reg_tmp = rtl_read_byte(rtlpriv, REG_TRXPTCL_CTL+2);
  393. if (short_preamble) {
  394. reg_tmp |= 0x02;
  395. rtl_write_byte(rtlpriv, REG_TRXPTCL_CTL +
  396. 2, reg_tmp);
  397. } else {
  398. reg_tmp |= 0xFD;
  399. rtl_write_byte(rtlpriv, REG_TRXPTCL_CTL +
  400. 2, reg_tmp);
  401. }
  402. break; }
  403. case HW_VAR_WPA_CONFIG:
  404. rtl_write_byte(rtlpriv, REG_SECCFG, *val);
  405. break;
  406. case HW_VAR_AMPDU_MIN_SPACE:{
  407. u8 min_spacing_to_set;
  408. u8 sec_min_space;
  409. min_spacing_to_set = *val;
  410. if (min_spacing_to_set <= 7) {
  411. sec_min_space = 0;
  412. if (min_spacing_to_set < sec_min_space)
  413. min_spacing_to_set = sec_min_space;
  414. mac->min_space_cfg = ((mac->min_space_cfg &
  415. 0xf8) |
  416. min_spacing_to_set);
  417. *val = min_spacing_to_set;
  418. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  419. "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
  420. mac->min_space_cfg);
  421. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  422. mac->min_space_cfg);
  423. }
  424. break; }
  425. case HW_VAR_SHORTGI_DENSITY:{
  426. u8 density_to_set;
  427. density_to_set = *val;
  428. mac->min_space_cfg |= (density_to_set << 3);
  429. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  430. "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
  431. mac->min_space_cfg);
  432. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  433. mac->min_space_cfg);
  434. break;
  435. }
  436. case HW_VAR_AMPDU_FACTOR:{
  437. u8 regtoset_normal[4] = { 0x41, 0xa8, 0x72, 0xb9 };
  438. u8 factor_toset;
  439. u8 *p_regtoset = NULL;
  440. u8 index = 0;
  441. p_regtoset = regtoset_normal;
  442. factor_toset = *val;
  443. if (factor_toset <= 3) {
  444. factor_toset = (1 << (factor_toset + 2));
  445. if (factor_toset > 0xf)
  446. factor_toset = 0xf;
  447. for (index = 0; index < 4; index++) {
  448. if ((p_regtoset[index] & 0xf0) >
  449. (factor_toset << 4))
  450. p_regtoset[index] =
  451. (p_regtoset[index] & 0x0f) |
  452. (factor_toset << 4);
  453. if ((p_regtoset[index] & 0x0f) >
  454. factor_toset)
  455. p_regtoset[index] =
  456. (p_regtoset[index] & 0xf0) |
  457. (factor_toset);
  458. rtl_write_byte(rtlpriv,
  459. (REG_AGGLEN_LMT + index),
  460. p_regtoset[index]);
  461. }
  462. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  463. "Set HW_VAR_AMPDU_FACTOR: %#x\n",
  464. factor_toset);
  465. }
  466. break; }
  467. case HW_VAR_AC_PARAM:{
  468. u8 e_aci = *val;
  469. rtl88e_dm_init_edca_turbo(hw);
  470. if (rtlpci->acm_method != EACMWAY2_SW)
  471. rtlpriv->cfg->ops->set_hw_reg(hw,
  472. HW_VAR_ACM_CTRL,
  473. &e_aci);
  474. break; }
  475. case HW_VAR_ACM_CTRL:{
  476. u8 e_aci = *val;
  477. union aci_aifsn *p_aci_aifsn =
  478. (union aci_aifsn *)(&(mac->ac[0].aifs));
  479. u8 acm = p_aci_aifsn->f.acm;
  480. u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
  481. acm_ctrl = acm_ctrl |
  482. ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
  483. if (acm) {
  484. switch (e_aci) {
  485. case AC0_BE:
  486. acm_ctrl |= ACMHW_BEQEN;
  487. break;
  488. case AC2_VI:
  489. acm_ctrl |= ACMHW_VIQEN;
  490. break;
  491. case AC3_VO:
  492. acm_ctrl |= ACMHW_VOQEN;
  493. break;
  494. default:
  495. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  496. "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
  497. acm);
  498. break;
  499. }
  500. } else {
  501. switch (e_aci) {
  502. case AC0_BE:
  503. acm_ctrl &= (~ACMHW_BEQEN);
  504. break;
  505. case AC2_VI:
  506. acm_ctrl &= (~ACMHW_VIQEN);
  507. break;
  508. case AC3_VO:
  509. acm_ctrl &= (~ACMHW_VOQEN);
  510. break;
  511. default:
  512. pr_err("switch case %#x not processed\n",
  513. e_aci);
  514. break;
  515. }
  516. }
  517. RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
  518. "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
  519. acm_ctrl);
  520. rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
  521. break; }
  522. case HW_VAR_RCR:
  523. rtl_write_dword(rtlpriv, REG_RCR, ((u32 *)(val))[0]);
  524. rtlpci->receive_config = ((u32 *)(val))[0];
  525. break;
  526. case HW_VAR_RETRY_LIMIT:{
  527. u8 retry_limit = *val;
  528. rtl_write_word(rtlpriv, REG_RL,
  529. retry_limit << RETRY_LIMIT_SHORT_SHIFT |
  530. retry_limit << RETRY_LIMIT_LONG_SHIFT);
  531. break; }
  532. case HW_VAR_DUAL_TSF_RST:
  533. rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
  534. break;
  535. case HW_VAR_EFUSE_BYTES:
  536. rtlefuse->efuse_usedbytes = *((u16 *)val);
  537. break;
  538. case HW_VAR_EFUSE_USAGE:
  539. rtlefuse->efuse_usedpercentage = *val;
  540. break;
  541. case HW_VAR_IO_CMD:
  542. rtl88e_phy_set_io_cmd(hw, (*(enum io_type *)val));
  543. break;
  544. case HW_VAR_SET_RPWM:{
  545. u8 rpwm_val;
  546. rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
  547. udelay(1);
  548. if (rpwm_val & BIT(7)) {
  549. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val);
  550. } else {
  551. rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val | BIT(7));
  552. }
  553. break; }
  554. case HW_VAR_H2C_FW_PWRMODE:
  555. rtl88e_set_fw_pwrmode_cmd(hw, *val);
  556. break;
  557. case HW_VAR_FW_PSMODE_STATUS:
  558. ppsc->fw_current_inpsmode = *((bool *)val);
  559. break;
  560. case HW_VAR_RESUME_CLK_ON:
  561. _rtl88ee_set_fw_ps_rf_on(hw);
  562. break;
  563. case HW_VAR_FW_LPS_ACTION:{
  564. bool enter_fwlps = *((bool *)val);
  565. if (enter_fwlps)
  566. _rtl88ee_fwlps_enter(hw);
  567. else
  568. _rtl88ee_fwlps_leave(hw);
  569. break; }
  570. case HW_VAR_H2C_FW_JOINBSSRPT:{
  571. u8 mstatus = *val;
  572. u8 tmp_regcr, tmp_reg422, bcnvalid_reg;
  573. u8 count = 0, dlbcn_count = 0;
  574. bool b_recover = false;
  575. if (mstatus == RT_MEDIA_CONNECT) {
  576. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
  577. NULL);
  578. tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
  579. rtl_write_byte(rtlpriv, REG_CR + 1,
  580. (tmp_regcr | BIT(0)));
  581. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(3));
  582. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(4), 0);
  583. tmp_reg422 =
  584. rtl_read_byte(rtlpriv,
  585. REG_FWHW_TXQ_CTRL + 2);
  586. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
  587. tmp_reg422 & (~BIT(6)));
  588. if (tmp_reg422 & BIT(6))
  589. b_recover = true;
  590. do {
  591. bcnvalid_reg = rtl_read_byte(rtlpriv,
  592. REG_TDECTRL+2);
  593. rtl_write_byte(rtlpriv, REG_TDECTRL+2,
  594. (bcnvalid_reg | BIT(0)));
  595. _rtl88ee_return_beacon_queue_skb(hw);
  596. rtl88e_set_fw_rsvdpagepkt(hw, 0);
  597. bcnvalid_reg = rtl_read_byte(rtlpriv,
  598. REG_TDECTRL+2);
  599. count = 0;
  600. while (!(bcnvalid_reg & BIT(0)) && count < 20) {
  601. count++;
  602. udelay(10);
  603. bcnvalid_reg =
  604. rtl_read_byte(rtlpriv, REG_TDECTRL+2);
  605. }
  606. dlbcn_count++;
  607. } while (!(bcnvalid_reg & BIT(0)) && dlbcn_count < 5);
  608. if (bcnvalid_reg & BIT(0))
  609. rtl_write_byte(rtlpriv, REG_TDECTRL+2, BIT(0));
  610. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  611. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(4));
  612. if (b_recover) {
  613. rtl_write_byte(rtlpriv,
  614. REG_FWHW_TXQ_CTRL + 2,
  615. tmp_reg422);
  616. }
  617. rtl_write_byte(rtlpriv, REG_CR + 1,
  618. (tmp_regcr & ~(BIT(0))));
  619. }
  620. rtl88e_set_fw_joinbss_report_cmd(hw, (*(u8 *)val));
  621. break; }
  622. case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
  623. rtl88e_set_p2p_ps_offload_cmd(hw, *val);
  624. break;
  625. case HW_VAR_AID:{
  626. u16 u2btmp;
  627. u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
  628. u2btmp &= 0xC000;
  629. rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
  630. mac->assoc_id));
  631. break; }
  632. case HW_VAR_CORRECT_TSF:{
  633. u8 btype_ibss = *val;
  634. if (btype_ibss)
  635. _rtl88ee_stop_tx_beacon(hw);
  636. _rtl88ee_set_bcn_ctrl_reg(hw, 0, BIT(3));
  637. rtl_write_dword(rtlpriv, REG_TSFTR,
  638. (u32)(mac->tsf & 0xffffffff));
  639. rtl_write_dword(rtlpriv, REG_TSFTR + 4,
  640. (u32)((mac->tsf >> 32) & 0xffffffff));
  641. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  642. if (btype_ibss)
  643. _rtl88ee_resume_tx_beacon(hw);
  644. break; }
  645. case HW_VAR_KEEP_ALIVE: {
  646. u8 array[2];
  647. array[0] = 0xff;
  648. array[1] = *((u8 *)val);
  649. rtl88e_fill_h2c_cmd(hw, H2C_88E_KEEP_ALIVE_CTRL,
  650. 2, array);
  651. break; }
  652. default:
  653. pr_err("switch case %#x not processed\n", variable);
  654. break;
  655. }
  656. }
  657. static bool _rtl88ee_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
  658. {
  659. struct rtl_priv *rtlpriv = rtl_priv(hw);
  660. bool status = true;
  661. long count = 0;
  662. u32 value = _LLT_INIT_ADDR(address) | _LLT_INIT_DATA(data) |
  663. _LLT_OP(_LLT_WRITE_ACCESS);
  664. rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
  665. do {
  666. value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
  667. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
  668. break;
  669. if (count > POLLING_LLT_THRESHOLD) {
  670. pr_err("Failed to polling write LLT done at address %d!\n",
  671. address);
  672. status = false;
  673. break;
  674. }
  675. } while (++count);
  676. return status;
  677. }
  678. static bool _rtl88ee_llt_table_init(struct ieee80211_hw *hw)
  679. {
  680. struct rtl_priv *rtlpriv = rtl_priv(hw);
  681. unsigned short i;
  682. u8 txpktbuf_bndy;
  683. u8 maxpage;
  684. bool status;
  685. maxpage = 0xAF;
  686. txpktbuf_bndy = 0xAB;
  687. rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x01);
  688. rtl_write_dword(rtlpriv, REG_RQPN, 0x80730d29);
  689. /*0x2600 MaxRxBuff=10k-max(TxReportSize(64*8), WOLPattern(16*24)) */
  690. rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x25FF0000 | txpktbuf_bndy));
  691. rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
  692. rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
  693. rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
  694. rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
  695. rtl_write_byte(rtlpriv, REG_PBP, 0x11);
  696. rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
  697. for (i = 0; i < (txpktbuf_bndy - 1); i++) {
  698. status = _rtl88ee_llt_write(hw, i, i + 1);
  699. if (true != status)
  700. return status;
  701. }
  702. status = _rtl88ee_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
  703. if (true != status)
  704. return status;
  705. for (i = txpktbuf_bndy; i < maxpage; i++) {
  706. status = _rtl88ee_llt_write(hw, i, (i + 1));
  707. if (true != status)
  708. return status;
  709. }
  710. status = _rtl88ee_llt_write(hw, maxpage, txpktbuf_bndy);
  711. if (true != status)
  712. return status;
  713. return true;
  714. }
  715. static void _rtl88ee_gen_refresh_led_state(struct ieee80211_hw *hw)
  716. {
  717. struct rtl_priv *rtlpriv = rtl_priv(hw);
  718. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  719. struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
  720. if (rtlpriv->rtlhal.up_first_time)
  721. return;
  722. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
  723. rtl88ee_sw_led_on(hw, pled0);
  724. else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
  725. rtl88ee_sw_led_on(hw, pled0);
  726. else
  727. rtl88ee_sw_led_off(hw, pled0);
  728. }
  729. static bool _rtl88ee_init_mac(struct ieee80211_hw *hw)
  730. {
  731. struct rtl_priv *rtlpriv = rtl_priv(hw);
  732. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  733. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  734. u8 bytetmp;
  735. u16 wordtmp;
  736. /*Disable XTAL OUTPUT for power saving. YJ,add,111206. */
  737. bytetmp = rtl_read_byte(rtlpriv, REG_XCK_OUT_CTRL) & (~BIT(0));
  738. rtl_write_byte(rtlpriv, REG_XCK_OUT_CTRL, bytetmp);
  739. /*Auto Power Down to CHIP-off State*/
  740. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) & (~BIT(7));
  741. rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
  742. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
  743. /* HW Power on sequence */
  744. if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK,
  745. PWR_FAB_ALL_MSK, PWR_INTF_PCI_MSK,
  746. RTL8188EE_NIC_ENABLE_FLOW)) {
  747. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  748. "init MAC Fail as rtl_hal_pwrseqcmdparsing\n");
  749. return false;
  750. }
  751. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO) | BIT(4);
  752. rtl_write_byte(rtlpriv, REG_APS_FSMCO, bytetmp);
  753. bytetmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG+2);
  754. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+2, bytetmp|BIT(2));
  755. bytetmp = rtl_read_byte(rtlpriv, REG_WATCH_DOG+1);
  756. rtl_write_byte(rtlpriv, REG_WATCH_DOG+1, bytetmp|BIT(7));
  757. bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL_EXT+1);
  758. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL_EXT+1, bytetmp|BIT(1));
  759. bytetmp = rtl_read_byte(rtlpriv, REG_TX_RPT_CTRL);
  760. rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL, bytetmp|BIT(1)|BIT(0));
  761. rtl_write_byte(rtlpriv, REG_TX_RPT_CTRL+1, 2);
  762. rtl_write_word(rtlpriv, REG_TX_RPT_TIME, 0xcdf0);
  763. /*Add for wake up online*/
  764. bytetmp = rtl_read_byte(rtlpriv, REG_SYS_CLKR);
  765. rtl_write_byte(rtlpriv, REG_SYS_CLKR, bytetmp|BIT(3));
  766. bytetmp = rtl_read_byte(rtlpriv, REG_GPIO_MUXCFG+1);
  767. rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG+1, (bytetmp & (~BIT(4))));
  768. rtl_write_byte(rtlpriv, 0x367, 0x80);
  769. rtl_write_word(rtlpriv, REG_CR, 0x2ff);
  770. rtl_write_byte(rtlpriv, REG_CR+1, 0x06);
  771. rtl_write_byte(rtlpriv, MSR, 0x00);
  772. if (!rtlhal->mac_func_enable) {
  773. if (_rtl88ee_llt_table_init(hw) == false) {
  774. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  775. "LLT table init fail\n");
  776. return false;
  777. }
  778. }
  779. rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
  780. rtl_write_dword(rtlpriv, REG_HISRE, 0xffffffff);
  781. wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
  782. wordtmp &= 0xf;
  783. wordtmp |= 0xE771;
  784. rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
  785. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  786. rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xffff);
  787. rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
  788. rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
  789. ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) &
  790. DMA_BIT_MASK(32));
  791. rtl_write_dword(rtlpriv, REG_MGQ_DESA,
  792. (u64) rtlpci->tx_ring[MGNT_QUEUE].dma &
  793. DMA_BIT_MASK(32));
  794. rtl_write_dword(rtlpriv, REG_VOQ_DESA,
  795. (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
  796. rtl_write_dword(rtlpriv, REG_VIQ_DESA,
  797. (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
  798. rtl_write_dword(rtlpriv, REG_BEQ_DESA,
  799. (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
  800. rtl_write_dword(rtlpriv, REG_BKQ_DESA,
  801. (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
  802. rtl_write_dword(rtlpriv, REG_HQ_DESA,
  803. (u64) rtlpci->tx_ring[HIGH_QUEUE].dma &
  804. DMA_BIT_MASK(32));
  805. rtl_write_dword(rtlpriv, REG_RX_DESA,
  806. (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
  807. DMA_BIT_MASK(32));
  808. /* if we want to support 64 bit DMA, we should set it here,
  809. * but now we do not support 64 bit DMA
  810. */
  811. rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
  812. rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
  813. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+1, 0);/*Enable RX DMA */
  814. if (rtlhal->earlymode_enable) {/*Early mode enable*/
  815. bytetmp = rtl_read_byte(rtlpriv, REG_EARLY_MODE_CONTROL);
  816. bytetmp |= 0x1f;
  817. rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL, bytetmp);
  818. rtl_write_byte(rtlpriv, REG_EARLY_MODE_CONTROL+3, 0x81);
  819. }
  820. _rtl88ee_gen_refresh_led_state(hw);
  821. return true;
  822. }
  823. static void _rtl88ee_hw_configure(struct ieee80211_hw *hw)
  824. {
  825. struct rtl_priv *rtlpriv = rtl_priv(hw);
  826. u8 reg_bw_opmode;
  827. u32 reg_ratr, reg_prsr;
  828. reg_bw_opmode = BW_OPMODE_20MHZ;
  829. reg_ratr = RATE_ALL_CCK | RATE_ALL_OFDM_AG |
  830. RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
  831. reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  832. rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
  833. rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
  834. }
  835. static void _rtl88ee_enable_aspm_back_door(struct ieee80211_hw *hw)
  836. {
  837. struct rtl_priv *rtlpriv = rtl_priv(hw);
  838. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  839. u8 tmp1byte = 0;
  840. u32 tmp4byte = 0, count = 0;
  841. rtl_write_word(rtlpriv, 0x354, 0x8104);
  842. rtl_write_word(rtlpriv, 0x358, 0x24);
  843. rtl_write_word(rtlpriv, 0x350, 0x70c);
  844. rtl_write_byte(rtlpriv, 0x352, 0x2);
  845. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  846. count = 0;
  847. while (tmp1byte && count < 20) {
  848. udelay(10);
  849. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  850. count++;
  851. }
  852. if (0 == tmp1byte) {
  853. tmp4byte = rtl_read_dword(rtlpriv, 0x34c);
  854. rtl_write_dword(rtlpriv, 0x348, tmp4byte|BIT(31));
  855. rtl_write_word(rtlpriv, 0x350, 0xf70c);
  856. rtl_write_byte(rtlpriv, 0x352, 0x1);
  857. }
  858. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  859. count = 0;
  860. while (tmp1byte && count < 20) {
  861. udelay(10);
  862. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  863. count++;
  864. }
  865. rtl_write_word(rtlpriv, 0x350, 0x718);
  866. rtl_write_byte(rtlpriv, 0x352, 0x2);
  867. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  868. count = 0;
  869. while (tmp1byte && count < 20) {
  870. udelay(10);
  871. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  872. count++;
  873. }
  874. if (ppsc->support_backdoor || (0 == tmp1byte)) {
  875. tmp4byte = rtl_read_dword(rtlpriv, 0x34c);
  876. rtl_write_dword(rtlpriv, 0x348, tmp4byte|BIT(11)|BIT(12));
  877. rtl_write_word(rtlpriv, 0x350, 0xf718);
  878. rtl_write_byte(rtlpriv, 0x352, 0x1);
  879. }
  880. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  881. count = 0;
  882. while (tmp1byte && count < 20) {
  883. udelay(10);
  884. tmp1byte = rtl_read_byte(rtlpriv, 0x352);
  885. count++;
  886. }
  887. }
  888. void rtl88ee_enable_hw_security_config(struct ieee80211_hw *hw)
  889. {
  890. struct rtl_priv *rtlpriv = rtl_priv(hw);
  891. u8 sec_reg_value;
  892. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  893. "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
  894. rtlpriv->sec.pairwise_enc_algorithm,
  895. rtlpriv->sec.group_enc_algorithm);
  896. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  897. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  898. "not open hw encryption\n");
  899. return;
  900. }
  901. sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE;
  902. if (rtlpriv->sec.use_defaultkey) {
  903. sec_reg_value |= SCR_TXUSEDK;
  904. sec_reg_value |= SCR_RXUSEDK;
  905. }
  906. sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
  907. rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
  908. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  909. "The SECR-value %x\n", sec_reg_value);
  910. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
  911. }
  912. int rtl88ee_hw_init(struct ieee80211_hw *hw)
  913. {
  914. struct rtl_priv *rtlpriv = rtl_priv(hw);
  915. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  916. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  917. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  918. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  919. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  920. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  921. bool rtstatus = true;
  922. int err = 0;
  923. u8 tmp_u1b, u1byte;
  924. unsigned long flags;
  925. rtlpriv->rtlhal.being_init_adapter = true;
  926. /* As this function can take a very long time (up to 350 ms)
  927. * and can be called with irqs disabled, reenable the irqs
  928. * to let the other devices continue being serviced.
  929. *
  930. * It is safe doing so since our own interrupts will only be enabled
  931. * in a subsequent step.
  932. */
  933. local_save_flags(flags);
  934. local_irq_enable();
  935. rtlhal->fw_ready = false;
  936. rtlpriv->intf_ops->disable_aspm(hw);
  937. tmp_u1b = rtl_read_byte(rtlpriv, REG_SYS_CLKR+1);
  938. u1byte = rtl_read_byte(rtlpriv, REG_CR);
  939. if ((tmp_u1b & BIT(3)) && (u1byte != 0 && u1byte != 0xEA)) {
  940. rtlhal->mac_func_enable = true;
  941. } else {
  942. rtlhal->mac_func_enable = false;
  943. rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_88E;
  944. }
  945. rtstatus = _rtl88ee_init_mac(hw);
  946. if (rtstatus != true) {
  947. pr_info("Init MAC failed\n");
  948. err = 1;
  949. goto exit;
  950. }
  951. err = rtl88e_download_fw(hw, false);
  952. if (err) {
  953. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  954. "Failed to download FW. Init HW without FW now..\n");
  955. err = 1;
  956. goto exit;
  957. }
  958. rtlhal->fw_ready = true;
  959. /*fw related variable initialize */
  960. rtlhal->last_hmeboxnum = 0;
  961. rtlhal->fw_ps_state = FW_PS_STATE_ALL_ON_88E;
  962. rtlhal->fw_clk_change_in_progress = false;
  963. rtlhal->allow_sw_to_change_hwclc = false;
  964. ppsc->fw_current_inpsmode = false;
  965. rtl88e_phy_mac_config(hw);
  966. /* because last function modify RCR, so we update
  967. * rcr var here, or TP will unstable for receive_config
  968. * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
  969. * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
  970. */
  971. rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
  972. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  973. rtl88e_phy_bb_config(hw);
  974. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  975. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  976. rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
  977. rtl88e_phy_rf_config(hw);
  978. rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
  979. RF_CHNLBW, RFREG_OFFSET_MASK);
  980. rtlphy->rfreg_chnlval[0] = rtlphy->rfreg_chnlval[0] & 0xfff00fff;
  981. _rtl88ee_hw_configure(hw);
  982. rtl_cam_reset_all_entry(hw);
  983. rtl88ee_enable_hw_security_config(hw);
  984. rtlhal->mac_func_enable = true;
  985. ppsc->rfpwr_state = ERFON;
  986. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  987. _rtl88ee_enable_aspm_back_door(hw);
  988. rtlpriv->intf_ops->enable_aspm(hw);
  989. if (ppsc->rfpwr_state == ERFON) {
  990. if ((rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV) ||
  991. ((rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV) &&
  992. (rtlhal->oem_id == RT_CID_819X_HP))) {
  993. rtl88e_phy_set_rfpath_switch(hw, true);
  994. rtlpriv->dm.fat_table.rx_idle_ant = MAIN_ANT;
  995. } else {
  996. rtl88e_phy_set_rfpath_switch(hw, false);
  997. rtlpriv->dm.fat_table.rx_idle_ant = AUX_ANT;
  998. }
  999. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "rx idle ant %s\n",
  1000. (rtlpriv->dm.fat_table.rx_idle_ant == MAIN_ANT) ?
  1001. ("MAIN_ANT") : ("AUX_ANT"));
  1002. if (rtlphy->iqk_initialized) {
  1003. rtl88e_phy_iq_calibrate(hw, true);
  1004. } else {
  1005. rtl88e_phy_iq_calibrate(hw, false);
  1006. rtlphy->iqk_initialized = true;
  1007. }
  1008. rtl88e_dm_check_txpower_tracking(hw);
  1009. rtl88e_phy_lc_calibrate(hw);
  1010. }
  1011. tmp_u1b = efuse_read_1byte(hw, 0x1FA);
  1012. if (!(tmp_u1b & BIT(0))) {
  1013. rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
  1014. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "PA BIAS path A\n");
  1015. }
  1016. if (!(tmp_u1b & BIT(4))) {
  1017. tmp_u1b = rtl_read_byte(rtlpriv, 0x16);
  1018. tmp_u1b &= 0x0F;
  1019. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
  1020. udelay(10);
  1021. rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
  1022. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "under 1.5V\n");
  1023. }
  1024. rtl_write_byte(rtlpriv, REG_NAV_CTRL+2, ((30000+127)/128));
  1025. rtl88e_dm_init(hw);
  1026. exit:
  1027. local_irq_restore(flags);
  1028. rtlpriv->rtlhal.being_init_adapter = false;
  1029. return err;
  1030. }
  1031. static enum version_8188e _rtl88ee_read_chip_version(struct ieee80211_hw *hw)
  1032. {
  1033. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1034. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1035. enum version_8188e version = VERSION_UNKNOWN;
  1036. u32 value32;
  1037. value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
  1038. if (value32 & TRP_VAUX_EN) {
  1039. version = (enum version_8188e) VERSION_TEST_CHIP_88E;
  1040. } else {
  1041. version = NORMAL_CHIP;
  1042. version = version | ((value32 & TYPE_ID) ? RF_TYPE_2T2R : 0);
  1043. version = version | ((value32 & VENDOR_ID) ?
  1044. CHIP_VENDOR_UMC : 0);
  1045. }
  1046. rtlphy->rf_type = RF_1T1R;
  1047. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1048. "Chip RF Type: %s\n", (rtlphy->rf_type == RF_2T2R) ?
  1049. "RF_2T2R" : "RF_1T1R");
  1050. return version;
  1051. }
  1052. static int _rtl88ee_set_media_status(struct ieee80211_hw *hw,
  1053. enum nl80211_iftype type)
  1054. {
  1055. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1056. u8 bt_msr = rtl_read_byte(rtlpriv, MSR) & 0xfc;
  1057. enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
  1058. u8 mode = MSR_NOLINK;
  1059. switch (type) {
  1060. case NL80211_IFTYPE_UNSPECIFIED:
  1061. mode = MSR_NOLINK;
  1062. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1063. "Set Network type to NO LINK!\n");
  1064. break;
  1065. case NL80211_IFTYPE_ADHOC:
  1066. case NL80211_IFTYPE_MESH_POINT:
  1067. mode = MSR_ADHOC;
  1068. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1069. "Set Network type to Ad Hoc!\n");
  1070. break;
  1071. case NL80211_IFTYPE_STATION:
  1072. mode = MSR_INFRA;
  1073. ledaction = LED_CTL_LINK;
  1074. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1075. "Set Network type to STA!\n");
  1076. break;
  1077. case NL80211_IFTYPE_AP:
  1078. mode = MSR_AP;
  1079. ledaction = LED_CTL_LINK;
  1080. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  1081. "Set Network type to AP!\n");
  1082. break;
  1083. default:
  1084. pr_err("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. WARN_ONCE(true, "rtl8188ee: 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. struct rtl_int *intvec)
  1268. {
  1269. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1270. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1271. intvec->inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
  1272. rtl_write_dword(rtlpriv, ISR, intvec->inta);
  1273. intvec->intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1];
  1274. rtl_write_dword(rtlpriv, REG_HISRE, intvec->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. int params[] = {RTL8188E_EEPROM_ID, EEPROM_VID, EEPROM_DID,
  1591. EEPROM_SVID, EEPROM_SMID, EEPROM_MAC_ADDR,
  1592. EEPROM_CHANNELPLAN, EEPROM_VERSION, EEPROM_CUSTOMER_ID,
  1593. COUNTRY_CODE_WORLD_WIDE_13};
  1594. u8 *hwinfo;
  1595. hwinfo = kzalloc(HWSET_MAX_SIZE, GFP_KERNEL);
  1596. if (!hwinfo)
  1597. return;
  1598. if (rtl_get_hwinfo(hw, rtlpriv, HWSET_MAX_SIZE, hwinfo, params))
  1599. goto exit;
  1600. if (rtlefuse->eeprom_oemid == 0xFF)
  1601. rtlefuse->eeprom_oemid = 0;
  1602. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1603. "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid);
  1604. /* set channel plan from efuse */
  1605. rtlefuse->channel_plan = rtlefuse->eeprom_channelplan;
  1606. /*tx power*/
  1607. _rtl88ee_read_txpower_info_from_hwpg(hw,
  1608. rtlefuse->autoload_failflag,
  1609. hwinfo);
  1610. rtlefuse->txpwr_fromeprom = true;
  1611. rtl8188ee_read_bt_coexist_info_from_hwpg(hw,
  1612. rtlefuse->autoload_failflag,
  1613. hwinfo);
  1614. /*board type*/
  1615. rtlefuse->board_type =
  1616. ((hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0xE0) >> 5);
  1617. rtlhal->board_type = rtlefuse->board_type;
  1618. /*Wake on wlan*/
  1619. rtlefuse->wowlan_enable =
  1620. ((hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & 0x40) >> 6);
  1621. /*parse xtal*/
  1622. rtlefuse->crystalcap = hwinfo[EEPROM_XTAL_88E];
  1623. if (hwinfo[EEPROM_XTAL_88E])
  1624. rtlefuse->crystalcap = 0x20;
  1625. /*antenna diversity*/
  1626. rtlefuse->antenna_div_cfg =
  1627. (hwinfo[EEPROM_RF_BOARD_OPTION_88E] & 0x18) >> 3;
  1628. if (hwinfo[EEPROM_RF_BOARD_OPTION_88E] == 0xFF)
  1629. rtlefuse->antenna_div_cfg = 0;
  1630. if (rtlpriv->btcoexist.eeprom_bt_coexist != 0 &&
  1631. rtlpriv->btcoexist.eeprom_bt_ant_num == ANT_X1)
  1632. rtlefuse->antenna_div_cfg = 0;
  1633. rtlefuse->antenna_div_type = hwinfo[EEPROM_RF_ANTENNA_OPT_88E];
  1634. if (rtlefuse->antenna_div_type == 0xFF)
  1635. rtlefuse->antenna_div_type = 0x01;
  1636. if (rtlefuse->antenna_div_type == CG_TRX_HW_ANTDIV ||
  1637. rtlefuse->antenna_div_type == CGCS_RX_HW_ANTDIV)
  1638. rtlefuse->antenna_div_cfg = 1;
  1639. if (rtlhal->oem_id == RT_CID_DEFAULT) {
  1640. switch (rtlefuse->eeprom_oemid) {
  1641. case EEPROM_CID_DEFAULT:
  1642. if (rtlefuse->eeprom_did == 0x8179) {
  1643. if (rtlefuse->eeprom_svid == 0x1025) {
  1644. rtlhal->oem_id = RT_CID_819X_ACER;
  1645. } else if ((rtlefuse->eeprom_svid == 0x10EC &&
  1646. rtlefuse->eeprom_smid == 0x0179) ||
  1647. (rtlefuse->eeprom_svid == 0x17AA &&
  1648. rtlefuse->eeprom_smid == 0x0179)) {
  1649. rtlhal->oem_id = RT_CID_819X_LENOVO;
  1650. } else if (rtlefuse->eeprom_svid == 0x103c &&
  1651. rtlefuse->eeprom_smid == 0x197d) {
  1652. rtlhal->oem_id = RT_CID_819X_HP;
  1653. } else {
  1654. rtlhal->oem_id = RT_CID_DEFAULT;
  1655. }
  1656. } else {
  1657. rtlhal->oem_id = RT_CID_DEFAULT;
  1658. }
  1659. break;
  1660. case EEPROM_CID_TOSHIBA:
  1661. rtlhal->oem_id = RT_CID_TOSHIBA;
  1662. break;
  1663. case EEPROM_CID_QMI:
  1664. rtlhal->oem_id = RT_CID_819X_QMI;
  1665. break;
  1666. case EEPROM_CID_WHQL:
  1667. default:
  1668. rtlhal->oem_id = RT_CID_DEFAULT;
  1669. break;
  1670. }
  1671. }
  1672. exit:
  1673. kfree(hwinfo);
  1674. }
  1675. static void _rtl88ee_hal_customized_behavior(struct ieee80211_hw *hw)
  1676. {
  1677. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1678. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1679. rtlpriv->ledctl.led_opendrain = true;
  1680. switch (rtlhal->oem_id) {
  1681. case RT_CID_819X_HP:
  1682. rtlpriv->ledctl.led_opendrain = true;
  1683. break;
  1684. case RT_CID_819X_LENOVO:
  1685. case RT_CID_DEFAULT:
  1686. case RT_CID_TOSHIBA:
  1687. case RT_CID_CCX:
  1688. case RT_CID_819X_ACER:
  1689. case RT_CID_WHQL:
  1690. default:
  1691. break;
  1692. }
  1693. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1694. "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
  1695. }
  1696. void rtl88ee_read_eeprom_info(struct ieee80211_hw *hw)
  1697. {
  1698. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1699. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1700. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1701. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1702. u8 tmp_u1b;
  1703. rtlhal->version = _rtl88ee_read_chip_version(hw);
  1704. if (get_rf_type(rtlphy) == RF_1T1R)
  1705. rtlpriv->dm.rfpath_rxenable[0] = true;
  1706. else
  1707. rtlpriv->dm.rfpath_rxenable[0] =
  1708. rtlpriv->dm.rfpath_rxenable[1] = true;
  1709. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
  1710. rtlhal->version);
  1711. tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
  1712. if (tmp_u1b & BIT(4)) {
  1713. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
  1714. rtlefuse->epromtype = EEPROM_93C46;
  1715. } else {
  1716. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
  1717. rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
  1718. }
  1719. if (tmp_u1b & BIT(5)) {
  1720. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1721. rtlefuse->autoload_failflag = false;
  1722. _rtl88ee_read_adapter_info(hw);
  1723. } else {
  1724. pr_err("Autoload ERR!!\n");
  1725. }
  1726. _rtl88ee_hal_customized_behavior(hw);
  1727. }
  1728. static void rtl88ee_update_hal_rate_table(struct ieee80211_hw *hw,
  1729. struct ieee80211_sta *sta)
  1730. {
  1731. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1732. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1733. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1734. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1735. u32 ratr_value;
  1736. u8 ratr_index = 0;
  1737. u8 b_nmode = mac->ht_enable;
  1738. /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
  1739. u16 shortgi_rate;
  1740. u32 tmp_ratr_value;
  1741. u8 curtxbw_40mhz = mac->bw_40;
  1742. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1743. 1 : 0;
  1744. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1745. 1 : 0;
  1746. enum wireless_mode wirelessmode = mac->mode;
  1747. u32 ratr_mask;
  1748. if (rtlhal->current_bandtype == BAND_ON_5G)
  1749. ratr_value = sta->supp_rates[1] << 4;
  1750. else
  1751. ratr_value = sta->supp_rates[0];
  1752. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1753. ratr_value = 0xfff;
  1754. ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1755. sta->ht_cap.mcs.rx_mask[0] << 12);
  1756. switch (wirelessmode) {
  1757. case WIRELESS_MODE_B:
  1758. if (ratr_value & 0x0000000c)
  1759. ratr_value &= 0x0000000d;
  1760. else
  1761. ratr_value &= 0x0000000f;
  1762. break;
  1763. case WIRELESS_MODE_G:
  1764. ratr_value &= 0x00000FF5;
  1765. break;
  1766. case WIRELESS_MODE_N_24G:
  1767. case WIRELESS_MODE_N_5G:
  1768. b_nmode = 1;
  1769. if (get_rf_type(rtlphy) == RF_1T2R ||
  1770. get_rf_type(rtlphy) == RF_1T1R)
  1771. ratr_mask = 0x000ff005;
  1772. else
  1773. ratr_mask = 0x0f0ff005;
  1774. ratr_value &= ratr_mask;
  1775. break;
  1776. default:
  1777. if (rtlphy->rf_type == RF_1T2R)
  1778. ratr_value &= 0x000ff0ff;
  1779. else
  1780. ratr_value &= 0x0f0ff0ff;
  1781. break;
  1782. }
  1783. if ((rtlpriv->btcoexist.bt_coexistence) &&
  1784. (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) &&
  1785. (rtlpriv->btcoexist.bt_cur_state) &&
  1786. (rtlpriv->btcoexist.bt_ant_isolation) &&
  1787. ((rtlpriv->btcoexist.bt_service == BT_SCO) ||
  1788. (rtlpriv->btcoexist.bt_service == BT_BUSY)))
  1789. ratr_value &= 0x0fffcfc0;
  1790. else
  1791. ratr_value &= 0x0FFFFFFF;
  1792. if (b_nmode &&
  1793. ((curtxbw_40mhz && curshortgi_40mhz) ||
  1794. (!curtxbw_40mhz && curshortgi_20mhz))) {
  1795. ratr_value |= 0x10000000;
  1796. tmp_ratr_value = (ratr_value >> 12);
  1797. for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
  1798. if ((1 << shortgi_rate) & tmp_ratr_value)
  1799. break;
  1800. }
  1801. shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
  1802. (shortgi_rate << 4) | (shortgi_rate);
  1803. }
  1804. rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
  1805. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1806. "%x\n", rtl_read_dword(rtlpriv, REG_ARFR0));
  1807. }
  1808. static void rtl88ee_update_hal_rate_mask(struct ieee80211_hw *hw,
  1809. struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
  1810. {
  1811. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1812. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1813. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1814. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1815. struct rtl_sta_info *sta_entry = NULL;
  1816. u32 ratr_bitmap;
  1817. u8 ratr_index;
  1818. u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
  1819. ? 1 : 0;
  1820. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1821. 1 : 0;
  1822. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1823. 1 : 0;
  1824. enum wireless_mode wirelessmode = 0;
  1825. bool b_shortgi = false;
  1826. u8 rate_mask[5];
  1827. u8 macid = 0;
  1828. /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/
  1829. sta_entry = (struct rtl_sta_info *)sta->drv_priv;
  1830. wirelessmode = sta_entry->wireless_mode;
  1831. if (mac->opmode == NL80211_IFTYPE_STATION ||
  1832. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  1833. curtxbw_40mhz = mac->bw_40;
  1834. else if (mac->opmode == NL80211_IFTYPE_AP ||
  1835. mac->opmode == NL80211_IFTYPE_ADHOC)
  1836. macid = sta->aid + 1;
  1837. if (rtlhal->current_bandtype == BAND_ON_5G)
  1838. ratr_bitmap = sta->supp_rates[1] << 4;
  1839. else
  1840. ratr_bitmap = sta->supp_rates[0];
  1841. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1842. ratr_bitmap = 0xfff;
  1843. ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1844. sta->ht_cap.mcs.rx_mask[0] << 12);
  1845. switch (wirelessmode) {
  1846. case WIRELESS_MODE_B:
  1847. ratr_index = RATR_INX_WIRELESS_B;
  1848. if (ratr_bitmap & 0x0000000c)
  1849. ratr_bitmap &= 0x0000000d;
  1850. else
  1851. ratr_bitmap &= 0x0000000f;
  1852. break;
  1853. case WIRELESS_MODE_G:
  1854. ratr_index = RATR_INX_WIRELESS_GB;
  1855. if (rssi_level == 1)
  1856. ratr_bitmap &= 0x00000f00;
  1857. else if (rssi_level == 2)
  1858. ratr_bitmap &= 0x00000ff0;
  1859. else
  1860. ratr_bitmap &= 0x00000ff5;
  1861. break;
  1862. case WIRELESS_MODE_N_24G:
  1863. case WIRELESS_MODE_N_5G:
  1864. ratr_index = RATR_INX_WIRELESS_NGB;
  1865. if (rtlphy->rf_type == RF_1T2R ||
  1866. rtlphy->rf_type == RF_1T1R) {
  1867. if (curtxbw_40mhz) {
  1868. if (rssi_level == 1)
  1869. ratr_bitmap &= 0x000f0000;
  1870. else if (rssi_level == 2)
  1871. ratr_bitmap &= 0x000ff000;
  1872. else
  1873. ratr_bitmap &= 0x000ff015;
  1874. } else {
  1875. if (rssi_level == 1)
  1876. ratr_bitmap &= 0x000f0000;
  1877. else if (rssi_level == 2)
  1878. ratr_bitmap &= 0x000ff000;
  1879. else
  1880. ratr_bitmap &= 0x000ff005;
  1881. }
  1882. } else {
  1883. if (curtxbw_40mhz) {
  1884. if (rssi_level == 1)
  1885. ratr_bitmap &= 0x0f8f0000;
  1886. else if (rssi_level == 2)
  1887. ratr_bitmap &= 0x0f8ff000;
  1888. else
  1889. ratr_bitmap &= 0x0f8ff015;
  1890. } else {
  1891. if (rssi_level == 1)
  1892. ratr_bitmap &= 0x0f8f0000;
  1893. else if (rssi_level == 2)
  1894. ratr_bitmap &= 0x0f8ff000;
  1895. else
  1896. ratr_bitmap &= 0x0f8ff005;
  1897. }
  1898. }
  1899. /*}*/
  1900. if ((curtxbw_40mhz && curshortgi_40mhz) ||
  1901. (!curtxbw_40mhz && curshortgi_20mhz)) {
  1902. if (macid == 0)
  1903. b_shortgi = true;
  1904. else if (macid == 1)
  1905. b_shortgi = false;
  1906. }
  1907. break;
  1908. default:
  1909. ratr_index = RATR_INX_WIRELESS_NGB;
  1910. if (rtlphy->rf_type == RF_1T2R)
  1911. ratr_bitmap &= 0x000ff0ff;
  1912. else
  1913. ratr_bitmap &= 0x0f0ff0ff;
  1914. break;
  1915. }
  1916. sta_entry->ratr_index = ratr_index;
  1917. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1918. "ratr_bitmap :%x\n", ratr_bitmap);
  1919. *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
  1920. (ratr_index << 28);
  1921. rate_mask[4] = macid | (b_shortgi ? 0x20 : 0x00) | 0x80;
  1922. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1923. "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n",
  1924. ratr_index, ratr_bitmap,
  1925. rate_mask[0], rate_mask[1],
  1926. rate_mask[2], rate_mask[3],
  1927. rate_mask[4]);
  1928. rtl88e_fill_h2c_cmd(hw, H2C_88E_RA_MASK, 5, rate_mask);
  1929. _rtl88ee_set_bcn_ctrl_reg(hw, BIT(3), 0);
  1930. }
  1931. void rtl88ee_update_hal_rate_tbl(struct ieee80211_hw *hw,
  1932. struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
  1933. {
  1934. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1935. if (rtlpriv->dm.useramask)
  1936. rtl88ee_update_hal_rate_mask(hw, sta, rssi_level, update_bw);
  1937. else
  1938. rtl88ee_update_hal_rate_table(hw, sta);
  1939. }
  1940. void rtl88ee_update_channel_access_setting(struct ieee80211_hw *hw)
  1941. {
  1942. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1943. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1944. u16 sifs_timer;
  1945. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, &mac->slot_time);
  1946. if (!mac->ht_enable)
  1947. sifs_timer = 0x0a0a;
  1948. else
  1949. sifs_timer = 0x0e0e;
  1950. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
  1951. }
  1952. bool rtl88ee_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
  1953. {
  1954. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1955. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1956. enum rf_pwrstate e_rfpowerstate_toset;
  1957. u32 u4tmp;
  1958. bool b_actuallyset = false;
  1959. if (rtlpriv->rtlhal.being_init_adapter)
  1960. return false;
  1961. if (ppsc->swrf_processing)
  1962. return false;
  1963. spin_lock(&rtlpriv->locks.rf_ps_lock);
  1964. if (ppsc->rfchange_inprogress) {
  1965. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1966. return false;
  1967. } else {
  1968. ppsc->rfchange_inprogress = true;
  1969. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1970. }
  1971. u4tmp = rtl_read_dword(rtlpriv, REG_GPIO_OUTPUT);
  1972. e_rfpowerstate_toset = (u4tmp & BIT(31)) ? ERFON : ERFOFF;
  1973. if (ppsc->hwradiooff && (e_rfpowerstate_toset == ERFON)) {
  1974. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1975. "GPIOChangeRF - HW Radio ON, RF ON\n");
  1976. e_rfpowerstate_toset = ERFON;
  1977. ppsc->hwradiooff = false;
  1978. b_actuallyset = true;
  1979. } else if ((!ppsc->hwradiooff) &&
  1980. (e_rfpowerstate_toset == ERFOFF)) {
  1981. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1982. "GPIOChangeRF - HW Radio OFF, RF OFF\n");
  1983. e_rfpowerstate_toset = ERFOFF;
  1984. ppsc->hwradiooff = true;
  1985. b_actuallyset = true;
  1986. }
  1987. if (b_actuallyset) {
  1988. spin_lock(&rtlpriv->locks.rf_ps_lock);
  1989. ppsc->rfchange_inprogress = false;
  1990. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1991. } else {
  1992. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
  1993. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1994. spin_lock(&rtlpriv->locks.rf_ps_lock);
  1995. ppsc->rfchange_inprogress = false;
  1996. spin_unlock(&rtlpriv->locks.rf_ps_lock);
  1997. }
  1998. *valid = 1;
  1999. return !ppsc->hwradiooff;
  2000. }
  2001. void rtl88ee_set_key(struct ieee80211_hw *hw, u32 key_index,
  2002. u8 *p_macaddr, bool is_group, u8 enc_algo,
  2003. bool is_wepkey, bool clear_all)
  2004. {
  2005. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2006. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2007. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2008. u8 *macaddr = p_macaddr;
  2009. u32 entry_id = 0;
  2010. bool is_pairwise = false;
  2011. static u8 cam_const_addr[4][6] = {
  2012. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  2013. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  2014. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  2015. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  2016. };
  2017. static u8 cam_const_broad[] = {
  2018. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  2019. };
  2020. if (clear_all) {
  2021. u8 idx = 0;
  2022. u8 cam_offset = 0;
  2023. u8 clear_number = 5;
  2024. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  2025. for (idx = 0; idx < clear_number; idx++) {
  2026. rtl_cam_mark_invalid(hw, cam_offset + idx);
  2027. rtl_cam_empty_entry(hw, cam_offset + idx);
  2028. if (idx < 5) {
  2029. memset(rtlpriv->sec.key_buf[idx], 0,
  2030. MAX_KEY_LEN);
  2031. rtlpriv->sec.key_len[idx] = 0;
  2032. }
  2033. }
  2034. } else {
  2035. switch (enc_algo) {
  2036. case WEP40_ENCRYPTION:
  2037. enc_algo = CAM_WEP40;
  2038. break;
  2039. case WEP104_ENCRYPTION:
  2040. enc_algo = CAM_WEP104;
  2041. break;
  2042. case TKIP_ENCRYPTION:
  2043. enc_algo = CAM_TKIP;
  2044. break;
  2045. case AESCCMP_ENCRYPTION:
  2046. enc_algo = CAM_AES;
  2047. break;
  2048. default:
  2049. pr_err("switch case %#x not processed\n",
  2050. enc_algo);
  2051. enc_algo = CAM_TKIP;
  2052. break;
  2053. }
  2054. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  2055. macaddr = cam_const_addr[key_index];
  2056. entry_id = key_index;
  2057. } else {
  2058. if (is_group) {
  2059. macaddr = cam_const_broad;
  2060. entry_id = key_index;
  2061. } else {
  2062. if (mac->opmode == NL80211_IFTYPE_AP ||
  2063. mac->opmode == NL80211_IFTYPE_MESH_POINT) {
  2064. entry_id =
  2065. rtl_cam_get_free_entry(hw, p_macaddr);
  2066. if (entry_id >= TOTAL_CAM_ENTRY) {
  2067. pr_err("Can not find free hw security cam entry\n");
  2068. return;
  2069. }
  2070. } else {
  2071. entry_id = CAM_PAIRWISE_KEY_POSITION;
  2072. }
  2073. key_index = PAIRWISE_KEYIDX;
  2074. is_pairwise = true;
  2075. }
  2076. }
  2077. if (rtlpriv->sec.key_len[key_index] == 0) {
  2078. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2079. "delete one entry, entry_id is %d\n",
  2080. entry_id);
  2081. if (mac->opmode == NL80211_IFTYPE_AP ||
  2082. mac->opmode == NL80211_IFTYPE_MESH_POINT)
  2083. rtl_cam_del_entry(hw, p_macaddr);
  2084. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  2085. } else {
  2086. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2087. "add one entry\n");
  2088. if (is_pairwise) {
  2089. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2090. "set Pairwise key\n");
  2091. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2092. entry_id, enc_algo,
  2093. CAM_CONFIG_NO_USEDK,
  2094. rtlpriv->sec.key_buf[key_index]);
  2095. } else {
  2096. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2097. "set group key\n");
  2098. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  2099. rtl_cam_add_one_entry(hw,
  2100. rtlefuse->dev_addr,
  2101. PAIRWISE_KEYIDX,
  2102. CAM_PAIRWISE_KEY_POSITION,
  2103. enc_algo,
  2104. CAM_CONFIG_NO_USEDK,
  2105. rtlpriv->sec.key_buf
  2106. [entry_id]);
  2107. }
  2108. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2109. entry_id, enc_algo,
  2110. CAM_CONFIG_NO_USEDK,
  2111. rtlpriv->sec.key_buf[entry_id]);
  2112. }
  2113. }
  2114. }
  2115. }
  2116. static void rtl8188ee_bt_var_init(struct ieee80211_hw *hw)
  2117. {
  2118. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2119. rtlpriv->btcoexist.bt_coexistence =
  2120. rtlpriv->btcoexist.eeprom_bt_coexist;
  2121. rtlpriv->btcoexist.bt_ant_num = rtlpriv->btcoexist.eeprom_bt_ant_num;
  2122. rtlpriv->btcoexist.bt_coexist_type = rtlpriv->btcoexist.eeprom_bt_type;
  2123. if (rtlpriv->btcoexist.reg_bt_iso == 2)
  2124. rtlpriv->btcoexist.bt_ant_isolation =
  2125. rtlpriv->btcoexist.eeprom_bt_ant_isol;
  2126. else
  2127. rtlpriv->btcoexist.bt_ant_isolation =
  2128. rtlpriv->btcoexist.reg_bt_iso;
  2129. rtlpriv->btcoexist.bt_radio_shared_type =
  2130. rtlpriv->btcoexist.eeprom_bt_radio_shared;
  2131. if (rtlpriv->btcoexist.bt_coexistence) {
  2132. if (rtlpriv->btcoexist.reg_bt_sco == 1)
  2133. rtlpriv->btcoexist.bt_service = BT_OTHER_ACTION;
  2134. else if (rtlpriv->btcoexist.reg_bt_sco == 2)
  2135. rtlpriv->btcoexist.bt_service = BT_SCO;
  2136. else if (rtlpriv->btcoexist.reg_bt_sco == 4)
  2137. rtlpriv->btcoexist.bt_service = BT_BUSY;
  2138. else if (rtlpriv->btcoexist.reg_bt_sco == 5)
  2139. rtlpriv->btcoexist.bt_service = BT_OTHERBUSY;
  2140. else
  2141. rtlpriv->btcoexist.bt_service = BT_IDLE;
  2142. rtlpriv->btcoexist.bt_edca_ul = 0;
  2143. rtlpriv->btcoexist.bt_edca_dl = 0;
  2144. rtlpriv->btcoexist.bt_rssi_state = 0xff;
  2145. }
  2146. }
  2147. void rtl8188ee_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
  2148. bool auto_load_fail, u8 *hwinfo)
  2149. {
  2150. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2151. u8 value;
  2152. if (!auto_load_fail) {
  2153. rtlpriv->btcoexist.eeprom_bt_coexist =
  2154. ((hwinfo[EEPROM_RF_FEATURE_OPTION_88E] & 0xe0) >> 5);
  2155. if (hwinfo[EEPROM_RF_FEATURE_OPTION_88E] == 0xFF)
  2156. rtlpriv->btcoexist.eeprom_bt_coexist = 0;
  2157. value = hwinfo[EEPROM_RF_BT_SETTING_88E];
  2158. rtlpriv->btcoexist.eeprom_bt_type = ((value & 0xe) >> 1);
  2159. rtlpriv->btcoexist.eeprom_bt_ant_num = (value & 0x1);
  2160. rtlpriv->btcoexist.eeprom_bt_ant_isol = ((value & 0x10) >> 4);
  2161. rtlpriv->btcoexist.eeprom_bt_radio_shared =
  2162. ((value & 0x20) >> 5);
  2163. } else {
  2164. rtlpriv->btcoexist.eeprom_bt_coexist = 0;
  2165. rtlpriv->btcoexist.eeprom_bt_type = BT_2WIRE;
  2166. rtlpriv->btcoexist.eeprom_bt_ant_num = ANT_X2;
  2167. rtlpriv->btcoexist.eeprom_bt_ant_isol = 0;
  2168. rtlpriv->btcoexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
  2169. }
  2170. rtl8188ee_bt_var_init(hw);
  2171. }
  2172. void rtl8188ee_bt_reg_init(struct ieee80211_hw *hw)
  2173. {
  2174. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2175. /* 0:Low, 1:High, 2:From Efuse. */
  2176. rtlpriv->btcoexist.reg_bt_iso = 2;
  2177. /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
  2178. rtlpriv->btcoexist.reg_bt_sco = 3;
  2179. /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
  2180. rtlpriv->btcoexist.reg_bt_sco = 0;
  2181. }
  2182. void rtl8188ee_bt_hw_init(struct ieee80211_hw *hw)
  2183. {
  2184. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2185. struct rtl_phy *rtlphy = &rtlpriv->phy;
  2186. u8 u1_tmp;
  2187. if (rtlpriv->btcoexist.bt_coexistence &&
  2188. ((rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) ||
  2189. rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC8)) {
  2190. if (rtlpriv->btcoexist.bt_ant_isolation)
  2191. rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
  2192. u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) &
  2193. BIT_OFFSET_LEN_MASK_32(0, 1);
  2194. u1_tmp = u1_tmp |
  2195. ((rtlpriv->btcoexist.bt_ant_isolation == 1) ?
  2196. 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
  2197. ((rtlpriv->btcoexist.bt_service == BT_SCO) ?
  2198. 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
  2199. rtl_write_byte(rtlpriv, 0x4fd, u1_tmp);
  2200. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa);
  2201. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040);
  2202. rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010);
  2203. /* Config to 1T1R. */
  2204. if (rtlphy->rf_type == RF_1T1R) {
  2205. u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE);
  2206. u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
  2207. rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp);
  2208. u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE);
  2209. u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
  2210. rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp);
  2211. }
  2212. }
  2213. }
  2214. void rtl88ee_suspend(struct ieee80211_hw *hw)
  2215. {
  2216. }
  2217. void rtl88ee_resume(struct ieee80211_hw *hw)
  2218. {
  2219. }