hw.c 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #include "../wifi.h"
  26. #include "../efuse.h"
  27. #include "../base.h"
  28. #include "../regd.h"
  29. #include "../cam.h"
  30. #include "../ps.h"
  31. #include "../pci.h"
  32. #include "reg.h"
  33. #include "def.h"
  34. #include "phy.h"
  35. #include "dm.h"
  36. #include "fw.h"
  37. #include "led.h"
  38. #include "sw.h"
  39. #include "hw.h"
  40. u32 rtl92de_read_dword_dbi(struct ieee80211_hw *hw, u16 offset, u8 direct)
  41. {
  42. struct rtl_priv *rtlpriv = rtl_priv(hw);
  43. u32 value;
  44. rtl_write_word(rtlpriv, REG_DBI_CTRL, (offset & 0xFFC));
  45. rtl_write_byte(rtlpriv, REG_DBI_FLAG, BIT(1) | direct);
  46. udelay(10);
  47. value = rtl_read_dword(rtlpriv, REG_DBI_RDATA);
  48. return value;
  49. }
  50. void rtl92de_write_dword_dbi(struct ieee80211_hw *hw,
  51. u16 offset, u32 value, u8 direct)
  52. {
  53. struct rtl_priv *rtlpriv = rtl_priv(hw);
  54. rtl_write_word(rtlpriv, REG_DBI_CTRL, ((offset & 0xFFC) | 0xF000));
  55. rtl_write_dword(rtlpriv, REG_DBI_WDATA, value);
  56. rtl_write_byte(rtlpriv, REG_DBI_FLAG, BIT(0) | direct);
  57. }
  58. static void _rtl92de_set_bcn_ctrl_reg(struct ieee80211_hw *hw,
  59. u8 set_bits, u8 clear_bits)
  60. {
  61. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  62. struct rtl_priv *rtlpriv = rtl_priv(hw);
  63. rtlpci->reg_bcn_ctrl_val |= set_bits;
  64. rtlpci->reg_bcn_ctrl_val &= ~clear_bits;
  65. rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val);
  66. }
  67. static void _rtl92de_stop_tx_beacon(struct ieee80211_hw *hw)
  68. {
  69. struct rtl_priv *rtlpriv = rtl_priv(hw);
  70. u8 tmp1byte;
  71. tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  72. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6)));
  73. rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
  74. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
  75. tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  76. tmp1byte &= ~(BIT(0));
  77. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
  78. }
  79. static void _rtl92de_resume_tx_beacon(struct ieee80211_hw *hw)
  80. {
  81. struct rtl_priv *rtlpriv = rtl_priv(hw);
  82. u8 tmp1byte;
  83. tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
  84. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6));
  85. rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0x0a);
  86. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  87. tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
  88. tmp1byte |= BIT(0);
  89. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
  90. }
  91. static void _rtl92de_enable_bcn_sub_func(struct ieee80211_hw *hw)
  92. {
  93. _rtl92de_set_bcn_ctrl_reg(hw, 0, BIT(1));
  94. }
  95. static void _rtl92de_disable_bcn_sub_func(struct ieee80211_hw *hw)
  96. {
  97. _rtl92de_set_bcn_ctrl_reg(hw, BIT(1), 0);
  98. }
  99. void rtl92de_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  100. {
  101. struct rtl_priv *rtlpriv = rtl_priv(hw);
  102. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  103. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  104. switch (variable) {
  105. case HW_VAR_RCR:
  106. *((u32 *) (val)) = rtlpci->receive_config;
  107. break;
  108. case HW_VAR_RF_STATE:
  109. *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
  110. break;
  111. case HW_VAR_FWLPS_RF_ON:{
  112. enum rf_pwrstate rfState;
  113. u32 val_rcr;
  114. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RF_STATE,
  115. (u8 *) (&rfState));
  116. if (rfState == ERFOFF) {
  117. *((bool *) (val)) = true;
  118. } else {
  119. val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
  120. val_rcr &= 0x00070000;
  121. if (val_rcr)
  122. *((bool *) (val)) = false;
  123. else
  124. *((bool *) (val)) = true;
  125. }
  126. break;
  127. }
  128. case HW_VAR_FW_PSMODE_STATUS:
  129. *((bool *) (val)) = ppsc->fw_current_inpsmode;
  130. break;
  131. case HW_VAR_CORRECT_TSF:{
  132. u64 tsf;
  133. u32 *ptsf_low = (u32 *)&tsf;
  134. u32 *ptsf_high = ((u32 *)&tsf) + 1;
  135. *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
  136. *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
  137. *((u64 *) (val)) = tsf;
  138. break;
  139. }
  140. case HW_VAR_INT_MIGRATION:
  141. *((bool *)(val)) = rtlpriv->dm.interrupt_migration;
  142. break;
  143. case HW_VAR_INT_AC:
  144. *((bool *)(val)) = rtlpriv->dm.disable_tx_int;
  145. break;
  146. case HAL_DEF_WOWLAN:
  147. break;
  148. default:
  149. pr_err("switch case %#x not processed\n", variable);
  150. break;
  151. }
  152. }
  153. void rtl92de_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  154. {
  155. struct rtl_priv *rtlpriv = rtl_priv(hw);
  156. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  157. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  158. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  159. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  160. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  161. u8 idx;
  162. switch (variable) {
  163. case HW_VAR_ETHER_ADDR:
  164. for (idx = 0; idx < ETH_ALEN; idx++) {
  165. rtl_write_byte(rtlpriv, (REG_MACID + idx),
  166. val[idx]);
  167. }
  168. break;
  169. case HW_VAR_BASIC_RATE: {
  170. u16 rate_cfg = ((u16 *) val)[0];
  171. u8 rate_index = 0;
  172. rate_cfg = rate_cfg & 0x15f;
  173. if (mac->vendor == PEER_CISCO &&
  174. ((rate_cfg & 0x150) == 0))
  175. rate_cfg |= 0x01;
  176. rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff);
  177. rtl_write_byte(rtlpriv, REG_RRSR + 1,
  178. (rate_cfg >> 8) & 0xff);
  179. while (rate_cfg > 0x1) {
  180. rate_cfg = (rate_cfg >> 1);
  181. rate_index++;
  182. }
  183. if (rtlhal->fw_version > 0xe)
  184. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
  185. rate_index);
  186. break;
  187. }
  188. case HW_VAR_BSSID:
  189. for (idx = 0; idx < ETH_ALEN; idx++) {
  190. rtl_write_byte(rtlpriv, (REG_BSSID + idx),
  191. val[idx]);
  192. }
  193. break;
  194. case HW_VAR_SIFS:
  195. rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
  196. rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
  197. rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
  198. rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
  199. if (!mac->ht_enable)
  200. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  201. 0x0e0e);
  202. else
  203. rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
  204. *((u16 *) val));
  205. break;
  206. case HW_VAR_SLOT_TIME: {
  207. u8 e_aci;
  208. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  209. "HW_VAR_SLOT_TIME %x\n", val[0]);
  210. rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
  211. for (e_aci = 0; e_aci < AC_MAX; e_aci++)
  212. rtlpriv->cfg->ops->set_hw_reg(hw,
  213. HW_VAR_AC_PARAM,
  214. (&e_aci));
  215. break;
  216. }
  217. case HW_VAR_ACK_PREAMBLE: {
  218. u8 reg_tmp;
  219. u8 short_preamble = (bool) (*val);
  220. reg_tmp = (mac->cur_40_prime_sc) << 5;
  221. if (short_preamble)
  222. reg_tmp |= 0x80;
  223. rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
  224. break;
  225. }
  226. case HW_VAR_AMPDU_MIN_SPACE: {
  227. u8 min_spacing_to_set;
  228. u8 sec_min_space;
  229. min_spacing_to_set = *val;
  230. if (min_spacing_to_set <= 7) {
  231. sec_min_space = 0;
  232. if (min_spacing_to_set < sec_min_space)
  233. min_spacing_to_set = sec_min_space;
  234. mac->min_space_cfg = ((mac->min_space_cfg & 0xf8) |
  235. min_spacing_to_set);
  236. *val = min_spacing_to_set;
  237. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  238. "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
  239. mac->min_space_cfg);
  240. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  241. mac->min_space_cfg);
  242. }
  243. break;
  244. }
  245. case HW_VAR_SHORTGI_DENSITY: {
  246. u8 density_to_set;
  247. density_to_set = *val;
  248. mac->min_space_cfg = rtlpriv->rtlhal.minspace_cfg;
  249. mac->min_space_cfg |= (density_to_set << 3);
  250. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  251. "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
  252. mac->min_space_cfg);
  253. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
  254. mac->min_space_cfg);
  255. break;
  256. }
  257. case HW_VAR_AMPDU_FACTOR: {
  258. u8 factor_toset;
  259. u32 regtoSet;
  260. u8 *ptmp_byte = NULL;
  261. u8 index;
  262. if (rtlhal->macphymode == DUALMAC_DUALPHY)
  263. regtoSet = 0xb9726641;
  264. else if (rtlhal->macphymode == DUALMAC_SINGLEPHY)
  265. regtoSet = 0x66626641;
  266. else
  267. regtoSet = 0xb972a841;
  268. factor_toset = *val;
  269. if (factor_toset <= 3) {
  270. factor_toset = (1 << (factor_toset + 2));
  271. if (factor_toset > 0xf)
  272. factor_toset = 0xf;
  273. for (index = 0; index < 4; index++) {
  274. ptmp_byte = (u8 *) (&regtoSet) + index;
  275. if ((*ptmp_byte & 0xf0) >
  276. (factor_toset << 4))
  277. *ptmp_byte = (*ptmp_byte & 0x0f)
  278. | (factor_toset << 4);
  279. if ((*ptmp_byte & 0x0f) > factor_toset)
  280. *ptmp_byte = (*ptmp_byte & 0xf0)
  281. | (factor_toset);
  282. }
  283. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, regtoSet);
  284. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  285. "Set HW_VAR_AMPDU_FACTOR: %#x\n",
  286. factor_toset);
  287. }
  288. break;
  289. }
  290. case HW_VAR_AC_PARAM: {
  291. u8 e_aci = *val;
  292. rtl92d_dm_init_edca_turbo(hw);
  293. if (rtlpci->acm_method != EACMWAY2_SW)
  294. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACM_CTRL,
  295. &e_aci);
  296. break;
  297. }
  298. case HW_VAR_ACM_CTRL: {
  299. u8 e_aci = *val;
  300. union aci_aifsn *p_aci_aifsn =
  301. (union aci_aifsn *)(&(mac->ac[0].aifs));
  302. u8 acm = p_aci_aifsn->f.acm;
  303. u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
  304. acm_ctrl = acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
  305. if (acm) {
  306. switch (e_aci) {
  307. case AC0_BE:
  308. acm_ctrl |= ACMHW_BEQEN;
  309. break;
  310. case AC2_VI:
  311. acm_ctrl |= ACMHW_VIQEN;
  312. break;
  313. case AC3_VO:
  314. acm_ctrl |= ACMHW_VOQEN;
  315. break;
  316. default:
  317. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  318. "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
  319. acm);
  320. break;
  321. }
  322. } else {
  323. switch (e_aci) {
  324. case AC0_BE:
  325. acm_ctrl &= (~ACMHW_BEQEN);
  326. break;
  327. case AC2_VI:
  328. acm_ctrl &= (~ACMHW_VIQEN);
  329. break;
  330. case AC3_VO:
  331. acm_ctrl &= (~ACMHW_VOQEN);
  332. break;
  333. default:
  334. pr_err("switch case %#x not processed\n",
  335. e_aci);
  336. break;
  337. }
  338. }
  339. RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
  340. "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
  341. acm_ctrl);
  342. rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
  343. break;
  344. }
  345. case HW_VAR_RCR:
  346. rtl_write_dword(rtlpriv, REG_RCR, ((u32 *) (val))[0]);
  347. rtlpci->receive_config = ((u32 *) (val))[0];
  348. break;
  349. case HW_VAR_RETRY_LIMIT: {
  350. u8 retry_limit = val[0];
  351. rtl_write_word(rtlpriv, REG_RL,
  352. retry_limit << RETRY_LIMIT_SHORT_SHIFT |
  353. retry_limit << RETRY_LIMIT_LONG_SHIFT);
  354. break;
  355. }
  356. case HW_VAR_DUAL_TSF_RST:
  357. rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
  358. break;
  359. case HW_VAR_EFUSE_BYTES:
  360. rtlefuse->efuse_usedbytes = *((u16 *) val);
  361. break;
  362. case HW_VAR_EFUSE_USAGE:
  363. rtlefuse->efuse_usedpercentage = *val;
  364. break;
  365. case HW_VAR_IO_CMD:
  366. rtl92d_phy_set_io_cmd(hw, (*(enum io_type *)val));
  367. break;
  368. case HW_VAR_WPA_CONFIG:
  369. rtl_write_byte(rtlpriv, REG_SECCFG, *val);
  370. break;
  371. case HW_VAR_SET_RPWM:
  372. rtl92d_fill_h2c_cmd(hw, H2C_PWRM, 1, (val));
  373. break;
  374. case HW_VAR_H2C_FW_PWRMODE:
  375. break;
  376. case HW_VAR_FW_PSMODE_STATUS:
  377. ppsc->fw_current_inpsmode = *((bool *) val);
  378. break;
  379. case HW_VAR_H2C_FW_JOINBSSRPT: {
  380. u8 mstatus = (*val);
  381. u8 tmp_regcr, tmp_reg422;
  382. bool recover = false;
  383. if (mstatus == RT_MEDIA_CONNECT) {
  384. rtlpriv->cfg->ops->set_hw_reg(hw,
  385. HW_VAR_AID, NULL);
  386. tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
  387. rtl_write_byte(rtlpriv, REG_CR + 1,
  388. (tmp_regcr | BIT(0)));
  389. _rtl92de_set_bcn_ctrl_reg(hw, 0, BIT(3));
  390. _rtl92de_set_bcn_ctrl_reg(hw, BIT(4), 0);
  391. tmp_reg422 = rtl_read_byte(rtlpriv,
  392. REG_FWHW_TXQ_CTRL + 2);
  393. if (tmp_reg422 & BIT(6))
  394. recover = true;
  395. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
  396. tmp_reg422 & (~BIT(6)));
  397. rtl92d_set_fw_rsvdpagepkt(hw, 0);
  398. _rtl92de_set_bcn_ctrl_reg(hw, BIT(3), 0);
  399. _rtl92de_set_bcn_ctrl_reg(hw, 0, BIT(4));
  400. if (recover)
  401. rtl_write_byte(rtlpriv,
  402. REG_FWHW_TXQ_CTRL + 2,
  403. tmp_reg422);
  404. rtl_write_byte(rtlpriv, REG_CR + 1,
  405. (tmp_regcr & ~(BIT(0))));
  406. }
  407. rtl92d_set_fw_joinbss_report_cmd(hw, (*val));
  408. break;
  409. }
  410. case HW_VAR_AID: {
  411. u16 u2btmp;
  412. u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
  413. u2btmp &= 0xC000;
  414. rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
  415. mac->assoc_id));
  416. break;
  417. }
  418. case HW_VAR_CORRECT_TSF: {
  419. u8 btype_ibss = val[0];
  420. if (btype_ibss)
  421. _rtl92de_stop_tx_beacon(hw);
  422. _rtl92de_set_bcn_ctrl_reg(hw, 0, BIT(3));
  423. rtl_write_dword(rtlpriv, REG_TSFTR,
  424. (u32) (mac->tsf & 0xffffffff));
  425. rtl_write_dword(rtlpriv, REG_TSFTR + 4,
  426. (u32) ((mac->tsf >> 32) & 0xffffffff));
  427. _rtl92de_set_bcn_ctrl_reg(hw, BIT(3), 0);
  428. if (btype_ibss)
  429. _rtl92de_resume_tx_beacon(hw);
  430. break;
  431. }
  432. case HW_VAR_INT_MIGRATION: {
  433. bool int_migration = *(bool *) (val);
  434. if (int_migration) {
  435. /* Set interrupt migration timer and
  436. * corresponding Tx/Rx counter.
  437. * timer 25ns*0xfa0=100us for 0xf packets.
  438. * 0x306:Rx, 0x307:Tx */
  439. rtl_write_dword(rtlpriv, REG_INT_MIG, 0xfe000fa0);
  440. rtlpriv->dm.interrupt_migration = int_migration;
  441. } else {
  442. /* Reset all interrupt migration settings. */
  443. rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
  444. rtlpriv->dm.interrupt_migration = int_migration;
  445. }
  446. break;
  447. }
  448. case HW_VAR_INT_AC: {
  449. bool disable_ac_int = *((bool *) val);
  450. /* Disable four ACs interrupts. */
  451. if (disable_ac_int) {
  452. /* Disable VO, VI, BE and BK four AC interrupts
  453. * to gain more efficient CPU utilization.
  454. * When extremely highly Rx OK occurs,
  455. * we will disable Tx interrupts.
  456. */
  457. rtlpriv->cfg->ops->update_interrupt_mask(hw, 0,
  458. RT_AC_INT_MASKS);
  459. rtlpriv->dm.disable_tx_int = disable_ac_int;
  460. /* Enable four ACs interrupts. */
  461. } else {
  462. rtlpriv->cfg->ops->update_interrupt_mask(hw,
  463. RT_AC_INT_MASKS, 0);
  464. rtlpriv->dm.disable_tx_int = disable_ac_int;
  465. }
  466. break;
  467. }
  468. default:
  469. pr_err("switch case %#x not processed\n", variable);
  470. break;
  471. }
  472. }
  473. static bool _rtl92de_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
  474. {
  475. struct rtl_priv *rtlpriv = rtl_priv(hw);
  476. bool status = true;
  477. long count = 0;
  478. u32 value = _LLT_INIT_ADDR(address) |
  479. _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
  480. rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
  481. do {
  482. value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
  483. if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
  484. break;
  485. if (count > POLLING_LLT_THRESHOLD) {
  486. pr_err("Failed to polling write LLT done at address %d!\n",
  487. address);
  488. status = false;
  489. break;
  490. }
  491. } while (++count);
  492. return status;
  493. }
  494. static bool _rtl92de_llt_table_init(struct ieee80211_hw *hw)
  495. {
  496. struct rtl_priv *rtlpriv = rtl_priv(hw);
  497. unsigned short i;
  498. u8 txpktbuf_bndy;
  499. u8 maxPage;
  500. bool status;
  501. u32 value32; /* High+low page number */
  502. u8 value8; /* normal page number */
  503. if (rtlpriv->rtlhal.macphymode == SINGLEMAC_SINGLEPHY) {
  504. maxPage = 255;
  505. txpktbuf_bndy = 246;
  506. value8 = 0;
  507. value32 = 0x80bf0d29;
  508. } else {
  509. maxPage = 127;
  510. txpktbuf_bndy = 123;
  511. value8 = 0;
  512. value32 = 0x80750005;
  513. }
  514. /* Set reserved page for each queue */
  515. /* 11. RQPN 0x200[31:0] = 0x80BD1C1C */
  516. /* load RQPN */
  517. rtl_write_byte(rtlpriv, REG_RQPN_NPQ, value8);
  518. rtl_write_dword(rtlpriv, REG_RQPN, value32);
  519. /* 12. TXRKTBUG_PG_BNDY 0x114[31:0] = 0x27FF00F6 */
  520. /* TXRKTBUG_PG_BNDY */
  521. rtl_write_dword(rtlpriv, REG_TRXFF_BNDY,
  522. (rtl_read_word(rtlpriv, REG_TRXFF_BNDY + 2) << 16 |
  523. txpktbuf_bndy));
  524. /* 13. TDECTRL[15:8] 0x209[7:0] = 0xF6 */
  525. /* Beacon Head for TXDMA */
  526. rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
  527. /* 14. BCNQ_PGBNDY 0x424[7:0] = 0xF6 */
  528. /* BCNQ_PGBNDY */
  529. rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
  530. rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
  531. /* 15. WMAC_LBK_BF_HD 0x45D[7:0] = 0xF6 */
  532. /* WMAC_LBK_BF_HD */
  533. rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
  534. /* Set Tx/Rx page size (Tx must be 128 Bytes, */
  535. /* Rx can be 64,128,256,512,1024 bytes) */
  536. /* 16. PBP [7:0] = 0x11 */
  537. /* TRX page size */
  538. rtl_write_byte(rtlpriv, REG_PBP, 0x11);
  539. /* 17. DRV_INFO_SZ = 0x04 */
  540. rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
  541. /* 18. LLT_table_init(Adapter); */
  542. for (i = 0; i < (txpktbuf_bndy - 1); i++) {
  543. status = _rtl92de_llt_write(hw, i, i + 1);
  544. if (true != status)
  545. return status;
  546. }
  547. /* end of list */
  548. status = _rtl92de_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
  549. if (true != status)
  550. return status;
  551. /* Make the other pages as ring buffer */
  552. /* This ring buffer is used as beacon buffer if we */
  553. /* config this MAC as two MAC transfer. */
  554. /* Otherwise used as local loopback buffer. */
  555. for (i = txpktbuf_bndy; i < maxPage; i++) {
  556. status = _rtl92de_llt_write(hw, i, (i + 1));
  557. if (true != status)
  558. return status;
  559. }
  560. /* Let last entry point to the start entry of ring buffer */
  561. status = _rtl92de_llt_write(hw, maxPage, txpktbuf_bndy);
  562. if (true != status)
  563. return status;
  564. return true;
  565. }
  566. static void _rtl92de_gen_refresh_led_state(struct ieee80211_hw *hw)
  567. {
  568. struct rtl_priv *rtlpriv = rtl_priv(hw);
  569. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  570. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  571. struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0;
  572. if (rtlpci->up_first_time)
  573. return;
  574. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
  575. rtl92de_sw_led_on(hw, pled0);
  576. else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
  577. rtl92de_sw_led_on(hw, pled0);
  578. else
  579. rtl92de_sw_led_off(hw, pled0);
  580. }
  581. static bool _rtl92de_init_mac(struct ieee80211_hw *hw)
  582. {
  583. struct rtl_priv *rtlpriv = rtl_priv(hw);
  584. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  585. unsigned char bytetmp;
  586. unsigned short wordtmp;
  587. u16 retry;
  588. rtl92d_phy_set_poweron(hw);
  589. /* Add for resume sequence of power domain according
  590. * to power document V11. Chapter V.11.... */
  591. /* 0. RSV_CTRL 0x1C[7:0] = 0x00 */
  592. /* unlock ISO/CLK/Power control register */
  593. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
  594. rtl_write_byte(rtlpriv, REG_LDOA15_CTRL, 0x05);
  595. /* 1. AFE_XTAL_CTRL [7:0] = 0x0F enable XTAL */
  596. /* 2. SPS0_CTRL 0x11[7:0] = 0x2b enable SPS into PWM mode */
  597. /* 3. delay (1ms) this is not necessary when initially power on */
  598. /* C. Resume Sequence */
  599. /* a. SPS0_CTRL 0x11[7:0] = 0x2b */
  600. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
  601. /* b. AFE_XTAL_CTRL [7:0] = 0x0F */
  602. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0F);
  603. /* c. DRV runs power on init flow */
  604. /* auto enable WLAN */
  605. /* 4. APS_FSMCO 0x04[8] = 1; wait till 0x04[8] = 0 */
  606. /* Power On Reset for MAC Block */
  607. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) | BIT(0);
  608. udelay(2);
  609. rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
  610. udelay(2);
  611. /* 5. Wait while 0x04[8] == 0 goto 2, otherwise goto 1 */
  612. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
  613. udelay(50);
  614. retry = 0;
  615. while ((bytetmp & BIT(0)) && retry < 1000) {
  616. retry++;
  617. bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
  618. udelay(50);
  619. }
  620. /* Enable Radio off, GPIO, and LED function */
  621. /* 6. APS_FSMCO 0x04[15:0] = 0x0012 when enable HWPDN */
  622. rtl_write_word(rtlpriv, REG_APS_FSMCO, 0x1012);
  623. /* release RF digital isolation */
  624. /* 7. SYS_ISO_CTRL 0x01[1] = 0x0; */
  625. /*Set REG_SYS_ISO_CTRL 0x1=0x82 to prevent wake# problem. */
  626. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x82);
  627. udelay(2);
  628. /* make sure that BB reset OK. */
  629. /* rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE3); */
  630. /* Disable REG_CR before enable it to assure reset */
  631. rtl_write_word(rtlpriv, REG_CR, 0x0);
  632. /* Release MAC IO register reset */
  633. rtl_write_word(rtlpriv, REG_CR, 0x2ff);
  634. /* clear stopping tx/rx dma */
  635. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0x0);
  636. /* rtl_write_word(rtlpriv,REG_CR+2, 0x2); */
  637. /* System init */
  638. /* 18. LLT_table_init(Adapter); */
  639. if (!_rtl92de_llt_table_init(hw))
  640. return false;
  641. /* Clear interrupt and enable interrupt */
  642. /* 19. HISR 0x124[31:0] = 0xffffffff; */
  643. /* HISRE 0x12C[7:0] = 0xFF */
  644. rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
  645. rtl_write_byte(rtlpriv, REG_HISRE, 0xff);
  646. /* 20. HIMR 0x120[31:0] |= [enable INT mask bit map]; */
  647. /* 21. HIMRE 0x128[7:0] = [enable INT mask bit map] */
  648. /* The IMR should be enabled later after all init sequence
  649. * is finished. */
  650. /* 22. PCIE configuration space configuration */
  651. /* 23. Ensure PCIe Device 0x80[15:0] = 0x0143 (ASPM+CLKREQ), */
  652. /* and PCIe gated clock function is enabled. */
  653. /* PCIE configuration space will be written after
  654. * all init sequence.(Or by BIOS) */
  655. rtl92d_phy_config_maccoexist_rfpage(hw);
  656. /* THe below section is not related to power document Vxx . */
  657. /* This is only useful for driver and OS setting. */
  658. /* -------------------Software Relative Setting---------------------- */
  659. wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
  660. wordtmp &= 0xf;
  661. wordtmp |= 0xF771;
  662. rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
  663. /* Reported Tx status from HW for rate adaptive. */
  664. /* This should be realtive to power on step 14. But in document V11 */
  665. /* still not contain the description.!!! */
  666. rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
  667. /* Set Tx/Rx page size (Tx must be 128 Bytes,
  668. * Rx can be 64,128,256,512,1024 bytes) */
  669. /* rtl_write_byte(rtlpriv,REG_PBP, 0x11); */
  670. /* Set RCR register */
  671. rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
  672. /* rtl_write_byte(rtlpriv,REG_RX_DRVINFO_SZ, 4); */
  673. /* Set TCR register */
  674. rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
  675. /* disable earlymode */
  676. rtl_write_byte(rtlpriv, 0x4d0, 0x0);
  677. /* Set TX/RX descriptor physical address(from OS API). */
  678. rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
  679. rtlpci->tx_ring[BEACON_QUEUE].dma);
  680. rtl_write_dword(rtlpriv, REG_MGQ_DESA, rtlpci->tx_ring[MGNT_QUEUE].dma);
  681. rtl_write_dword(rtlpriv, REG_VOQ_DESA, rtlpci->tx_ring[VO_QUEUE].dma);
  682. rtl_write_dword(rtlpriv, REG_VIQ_DESA, rtlpci->tx_ring[VI_QUEUE].dma);
  683. rtl_write_dword(rtlpriv, REG_BEQ_DESA, rtlpci->tx_ring[BE_QUEUE].dma);
  684. rtl_write_dword(rtlpriv, REG_BKQ_DESA, rtlpci->tx_ring[BK_QUEUE].dma);
  685. rtl_write_dword(rtlpriv, REG_HQ_DESA, rtlpci->tx_ring[HIGH_QUEUE].dma);
  686. /* Set RX Desc Address */
  687. rtl_write_dword(rtlpriv, REG_RX_DESA,
  688. rtlpci->rx_ring[RX_MPDU_QUEUE].dma);
  689. /* if we want to support 64 bit DMA, we should set it here,
  690. * but now we do not support 64 bit DMA*/
  691. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x33);
  692. /* Reset interrupt migration setting when initialization */
  693. rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
  694. /* Reconsider when to do this operation after asking HWSD. */
  695. bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
  696. rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6));
  697. do {
  698. retry++;
  699. bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
  700. } while ((retry < 200) && !(bytetmp & BIT(7)));
  701. /* After MACIO reset,we must refresh LED state. */
  702. _rtl92de_gen_refresh_led_state(hw);
  703. /* Reset H2C protection register */
  704. rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
  705. return true;
  706. }
  707. static void _rtl92de_hw_configure(struct ieee80211_hw *hw)
  708. {
  709. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  710. struct rtl_priv *rtlpriv = rtl_priv(hw);
  711. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  712. u8 reg_bw_opmode = BW_OPMODE_20MHZ;
  713. u32 reg_rrsr;
  714. reg_rrsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  715. rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8);
  716. rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
  717. rtl_write_dword(rtlpriv, REG_RRSR, reg_rrsr);
  718. rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
  719. rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0);
  720. rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
  721. rtl_write_word(rtlpriv, REG_RL, 0x0707);
  722. rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802);
  723. rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
  724. rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
  725. rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
  726. rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
  727. rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
  728. /* Aggregation threshold */
  729. if (rtlhal->macphymode == DUALMAC_DUALPHY)
  730. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb9726641);
  731. else if (rtlhal->macphymode == DUALMAC_SINGLEPHY)
  732. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x66626641);
  733. else
  734. rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
  735. rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
  736. rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0x0a);
  737. rtlpci->reg_bcn_ctrl_val = 0x1f;
  738. rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
  739. rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
  740. rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
  741. rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
  742. rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
  743. /* For throughput */
  744. rtl_write_word(rtlpriv, REG_FAST_EDCA_CTRL, 0x6666);
  745. /* ACKTO for IOT issue. */
  746. rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
  747. /* Set Spec SIFS (used in NAV) */
  748. rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010);
  749. rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010);
  750. /* Set SIFS for CCK */
  751. rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010);
  752. /* Set SIFS for OFDM */
  753. rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010);
  754. /* Set Multicast Address. */
  755. rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
  756. rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
  757. switch (rtlpriv->phy.rf_type) {
  758. case RF_1T2R:
  759. case RF_1T1R:
  760. rtlhal->minspace_cfg = (MAX_MSS_DENSITY_1T << 3);
  761. break;
  762. case RF_2T2R:
  763. case RF_2T2R_GREEN:
  764. rtlhal->minspace_cfg = (MAX_MSS_DENSITY_2T << 3);
  765. break;
  766. }
  767. }
  768. static void _rtl92de_enable_aspm_back_door(struct ieee80211_hw *hw)
  769. {
  770. struct rtl_priv *rtlpriv = rtl_priv(hw);
  771. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  772. rtl_write_byte(rtlpriv, 0x34b, 0x93);
  773. rtl_write_word(rtlpriv, 0x350, 0x870c);
  774. rtl_write_byte(rtlpriv, 0x352, 0x1);
  775. if (ppsc->support_backdoor)
  776. rtl_write_byte(rtlpriv, 0x349, 0x1b);
  777. else
  778. rtl_write_byte(rtlpriv, 0x349, 0x03);
  779. rtl_write_word(rtlpriv, 0x350, 0x2718);
  780. rtl_write_byte(rtlpriv, 0x352, 0x1);
  781. }
  782. void rtl92de_enable_hw_security_config(struct ieee80211_hw *hw)
  783. {
  784. struct rtl_priv *rtlpriv = rtl_priv(hw);
  785. u8 sec_reg_value;
  786. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  787. "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
  788. rtlpriv->sec.pairwise_enc_algorithm,
  789. rtlpriv->sec.group_enc_algorithm);
  790. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  791. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  792. "not open hw encryption\n");
  793. return;
  794. }
  795. sec_reg_value = SCR_TXENCENABLE | SCR_RXENCENABLE;
  796. if (rtlpriv->sec.use_defaultkey) {
  797. sec_reg_value |= SCR_TXUSEDK;
  798. sec_reg_value |= SCR_RXUSEDK;
  799. }
  800. sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
  801. rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
  802. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  803. "The SECR-value %x\n", sec_reg_value);
  804. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
  805. }
  806. int rtl92de_hw_init(struct ieee80211_hw *hw)
  807. {
  808. struct rtl_priv *rtlpriv = rtl_priv(hw);
  809. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  810. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  811. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  812. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  813. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  814. bool rtstatus = true;
  815. u8 tmp_u1b;
  816. int i;
  817. int err;
  818. unsigned long flags;
  819. rtlpci->being_init_adapter = true;
  820. rtlpci->init_ready = false;
  821. spin_lock_irqsave(&globalmutex_for_power_and_efuse, flags);
  822. /* we should do iqk after disable/enable */
  823. rtl92d_phy_reset_iqk_result(hw);
  824. /* rtlpriv->intf_ops->disable_aspm(hw); */
  825. rtstatus = _rtl92de_init_mac(hw);
  826. if (!rtstatus) {
  827. pr_err("Init MAC failed\n");
  828. err = 1;
  829. spin_unlock_irqrestore(&globalmutex_for_power_and_efuse, flags);
  830. return err;
  831. }
  832. err = rtl92d_download_fw(hw);
  833. spin_unlock_irqrestore(&globalmutex_for_power_and_efuse, flags);
  834. if (err) {
  835. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  836. "Failed to download FW. Init HW without FW..\n");
  837. return 1;
  838. }
  839. rtlhal->last_hmeboxnum = 0;
  840. rtlpriv->psc.fw_current_inpsmode = false;
  841. tmp_u1b = rtl_read_byte(rtlpriv, 0x605);
  842. tmp_u1b = tmp_u1b | 0x30;
  843. rtl_write_byte(rtlpriv, 0x605, tmp_u1b);
  844. if (rtlhal->earlymode_enable) {
  845. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  846. "EarlyMode Enabled!!!\n");
  847. tmp_u1b = rtl_read_byte(rtlpriv, 0x4d0);
  848. tmp_u1b = tmp_u1b | 0x1f;
  849. rtl_write_byte(rtlpriv, 0x4d0, tmp_u1b);
  850. rtl_write_byte(rtlpriv, 0x4d3, 0x80);
  851. tmp_u1b = rtl_read_byte(rtlpriv, 0x605);
  852. tmp_u1b = tmp_u1b | 0x40;
  853. rtl_write_byte(rtlpriv, 0x605, tmp_u1b);
  854. }
  855. if (mac->rdg_en) {
  856. rtl_write_byte(rtlpriv, REG_RD_CTRL, 0xff);
  857. rtl_write_word(rtlpriv, REG_RD_NAV_NXT, 0x200);
  858. rtl_write_byte(rtlpriv, REG_RD_RESP_PKT_TH, 0x05);
  859. }
  860. rtl92d_phy_mac_config(hw);
  861. /* because last function modify RCR, so we update
  862. * rcr var here, or TP will unstable for receive_config
  863. * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
  864. * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252*/
  865. rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
  866. rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
  867. rtl92d_phy_bb_config(hw);
  868. rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
  869. /* set before initialize RF */
  870. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0x00f00000, 0xf);
  871. /* config RF */
  872. rtl92d_phy_rf_config(hw);
  873. /* After read predefined TXT, we must set BB/MAC/RF
  874. * register as our requirement */
  875. /* After load BB,RF params,we need do more for 92D. */
  876. rtl92d_update_bbrf_configuration(hw);
  877. /* set default value after initialize RF, */
  878. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0x00f00000, 0);
  879. rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
  880. RF_CHNLBW, RFREG_OFFSET_MASK);
  881. rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1,
  882. RF_CHNLBW, RFREG_OFFSET_MASK);
  883. /*---- Set CCK and OFDM Block "ON"----*/
  884. if (rtlhal->current_bandtype == BAND_ON_2_4G)
  885. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  886. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  887. if (rtlhal->interfaceindex == 0) {
  888. /* RFPGA0_ANALOGPARAMETER2: cck clock select,
  889. * set to 20MHz by default */
  890. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10) |
  891. BIT(11), 3);
  892. } else {
  893. /* Mac1 */
  894. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(11) |
  895. BIT(10), 3);
  896. }
  897. _rtl92de_hw_configure(hw);
  898. /* reset hw sec */
  899. rtl_cam_reset_all_entry(hw);
  900. rtl92de_enable_hw_security_config(hw);
  901. /* Read EEPROM TX power index and PHY_REG_PG.txt to capture correct */
  902. /* TX power index for different rate set. */
  903. rtl92d_phy_get_hw_reg_originalvalue(hw);
  904. rtl92d_phy_set_txpower_level(hw, rtlphy->current_channel);
  905. ppsc->rfpwr_state = ERFON;
  906. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
  907. _rtl92de_enable_aspm_back_door(hw);
  908. /* rtlpriv->intf_ops->enable_aspm(hw); */
  909. rtl92d_dm_init(hw);
  910. rtlpci->being_init_adapter = false;
  911. if (ppsc->rfpwr_state == ERFON) {
  912. rtl92d_phy_lc_calibrate(hw);
  913. /* 5G and 2.4G must wait sometime to let RF LO ready */
  914. if (rtlhal->macphymode == DUALMAC_DUALPHY) {
  915. u32 tmp_rega;
  916. for (i = 0; i < 10000; i++) {
  917. udelay(MAX_STALL_TIME);
  918. tmp_rega = rtl_get_rfreg(hw,
  919. (enum radio_path)RF90_PATH_A,
  920. 0x2a, MASKDWORD);
  921. if (((tmp_rega & BIT(11)) == BIT(11)))
  922. break;
  923. }
  924. /* check that loop was successful. If not, exit now */
  925. if (i == 10000) {
  926. rtlpci->init_ready = false;
  927. return 1;
  928. }
  929. }
  930. }
  931. rtlpci->init_ready = true;
  932. return err;
  933. }
  934. static enum version_8192d _rtl92de_read_chip_version(struct ieee80211_hw *hw)
  935. {
  936. struct rtl_priv *rtlpriv = rtl_priv(hw);
  937. enum version_8192d version = VERSION_NORMAL_CHIP_92D_SINGLEPHY;
  938. u32 value32;
  939. value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
  940. if (!(value32 & 0x000f0000)) {
  941. version = VERSION_TEST_CHIP_92D_SINGLEPHY;
  942. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "TEST CHIP!!!\n");
  943. } else {
  944. version = VERSION_NORMAL_CHIP_92D_SINGLEPHY;
  945. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Normal CHIP!!!\n");
  946. }
  947. return version;
  948. }
  949. static int _rtl92de_set_media_status(struct ieee80211_hw *hw,
  950. enum nl80211_iftype type)
  951. {
  952. struct rtl_priv *rtlpriv = rtl_priv(hw);
  953. u8 bt_msr = rtl_read_byte(rtlpriv, MSR);
  954. enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
  955. u8 bcnfunc_enable;
  956. bt_msr &= 0xfc;
  957. if (type == NL80211_IFTYPE_UNSPECIFIED ||
  958. type == NL80211_IFTYPE_STATION) {
  959. _rtl92de_stop_tx_beacon(hw);
  960. _rtl92de_enable_bcn_sub_func(hw);
  961. } else if (type == NL80211_IFTYPE_ADHOC ||
  962. type == NL80211_IFTYPE_AP) {
  963. _rtl92de_resume_tx_beacon(hw);
  964. _rtl92de_disable_bcn_sub_func(hw);
  965. } else {
  966. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  967. "Set HW_VAR_MEDIA_STATUS: No such media status(%x)\n",
  968. type);
  969. }
  970. bcnfunc_enable = rtl_read_byte(rtlpriv, REG_BCN_CTRL);
  971. switch (type) {
  972. case NL80211_IFTYPE_UNSPECIFIED:
  973. bt_msr |= MSR_NOLINK;
  974. ledaction = LED_CTL_LINK;
  975. bcnfunc_enable &= 0xF7;
  976. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  977. "Set Network type to NO LINK!\n");
  978. break;
  979. case NL80211_IFTYPE_ADHOC:
  980. bt_msr |= MSR_ADHOC;
  981. bcnfunc_enable |= 0x08;
  982. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  983. "Set Network type to Ad Hoc!\n");
  984. break;
  985. case NL80211_IFTYPE_STATION:
  986. bt_msr |= MSR_INFRA;
  987. ledaction = LED_CTL_LINK;
  988. bcnfunc_enable &= 0xF7;
  989. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  990. "Set Network type to STA!\n");
  991. break;
  992. case NL80211_IFTYPE_AP:
  993. bt_msr |= MSR_AP;
  994. bcnfunc_enable |= 0x08;
  995. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  996. "Set Network type to AP!\n");
  997. break;
  998. default:
  999. pr_err("Network type %d not supported!\n", type);
  1000. return 1;
  1001. }
  1002. rtl_write_byte(rtlpriv, MSR, bt_msr);
  1003. rtlpriv->cfg->ops->led_control(hw, ledaction);
  1004. if ((bt_msr & MSR_MASK) == MSR_AP)
  1005. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
  1006. else
  1007. rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
  1008. return 0;
  1009. }
  1010. void rtl92de_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
  1011. {
  1012. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1013. u32 reg_rcr;
  1014. if (rtlpriv->psc.rfpwr_state != ERFON)
  1015. return;
  1016. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
  1017. if (check_bssid) {
  1018. reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
  1019. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
  1020. _rtl92de_set_bcn_ctrl_reg(hw, 0, BIT(4));
  1021. } else if (!check_bssid) {
  1022. reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
  1023. _rtl92de_set_bcn_ctrl_reg(hw, BIT(4), 0);
  1024. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
  1025. }
  1026. }
  1027. int rtl92de_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
  1028. {
  1029. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1030. if (_rtl92de_set_media_status(hw, type))
  1031. return -EOPNOTSUPP;
  1032. /* check bssid */
  1033. if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
  1034. if (type != NL80211_IFTYPE_AP)
  1035. rtl92de_set_check_bssid(hw, true);
  1036. } else {
  1037. rtl92de_set_check_bssid(hw, false);
  1038. }
  1039. return 0;
  1040. }
  1041. /* do iqk or reload iqk */
  1042. /* windows just rtl92d_phy_reload_iqk_setting in set channel,
  1043. * but it's very strict for time sequence so we add
  1044. * rtl92d_phy_reload_iqk_setting here */
  1045. void rtl92d_linked_set_reg(struct ieee80211_hw *hw)
  1046. {
  1047. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1048. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1049. u8 indexforchannel;
  1050. u8 channel = rtlphy->current_channel;
  1051. indexforchannel = rtl92d_get_rightchnlplace_for_iqk(channel);
  1052. if (!rtlphy->iqk_matrix[indexforchannel].iqk_done) {
  1053. RT_TRACE(rtlpriv, COMP_SCAN | COMP_INIT, DBG_DMESG,
  1054. "Do IQK for channel:%d\n", channel);
  1055. rtl92d_phy_iq_calibrate(hw);
  1056. }
  1057. }
  1058. /* don't set REG_EDCA_BE_PARAM here because
  1059. * mac80211 will send pkt when scan */
  1060. void rtl92de_set_qos(struct ieee80211_hw *hw, int aci)
  1061. {
  1062. rtl92d_dm_init_edca_turbo(hw);
  1063. }
  1064. void rtl92de_enable_interrupt(struct ieee80211_hw *hw)
  1065. {
  1066. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1067. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1068. rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF);
  1069. rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF);
  1070. rtlpci->irq_enabled = true;
  1071. }
  1072. void rtl92de_disable_interrupt(struct ieee80211_hw *hw)
  1073. {
  1074. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1075. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1076. rtl_write_dword(rtlpriv, REG_HIMR, IMR8190_DISABLED);
  1077. rtl_write_dword(rtlpriv, REG_HIMRE, IMR8190_DISABLED);
  1078. rtlpci->irq_enabled = false;
  1079. }
  1080. static void _rtl92de_poweroff_adapter(struct ieee80211_hw *hw)
  1081. {
  1082. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1083. u8 u1b_tmp;
  1084. unsigned long flags;
  1085. rtlpriv->intf_ops->enable_aspm(hw);
  1086. rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
  1087. rtl_set_bbreg(hw, RFPGA0_XCD_RFPARAMETER, BIT(3), 0);
  1088. rtl_set_bbreg(hw, RFPGA0_XCD_RFPARAMETER, BIT(15), 0);
  1089. /* 0x20:value 05-->04 */
  1090. rtl_write_byte(rtlpriv, REG_LDOA15_CTRL, 0x04);
  1091. /* ==== Reset digital sequence ====== */
  1092. rtl92d_firmware_selfreset(hw);
  1093. /* f. SYS_FUNC_EN 0x03[7:0]=0x51 reset MCU, MAC register, DCORE */
  1094. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, 0x51);
  1095. /* g. MCUFWDL 0x80[1:0]=0 reset MCU ready status */
  1096. rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
  1097. /* ==== Pull GPIO PIN to balance level and LED control ====== */
  1098. /* h. GPIO_PIN_CTRL 0x44[31:0]=0x000 */
  1099. rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00000000);
  1100. /* i. Value = GPIO_PIN_CTRL[7:0] */
  1101. u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL);
  1102. /* j. GPIO_PIN_CTRL 0x44[31:0] = 0x00FF0000 | (value <<8); */
  1103. /* write external PIN level */
  1104. rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL,
  1105. 0x00FF0000 | (u1b_tmp << 8));
  1106. /* k. GPIO_MUXCFG 0x42 [15:0] = 0x0780 */
  1107. rtl_write_word(rtlpriv, REG_GPIO_IO_SEL, 0x0790);
  1108. /* l. LEDCFG 0x4C[15:0] = 0x8080 */
  1109. rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080);
  1110. /* ==== Disable analog sequence === */
  1111. /* m. AFE_PLL_CTRL[7:0] = 0x80 disable PLL */
  1112. rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80);
  1113. /* n. SPS0_CTRL 0x11[7:0] = 0x22 enter PFM mode */
  1114. rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23);
  1115. /* o. AFE_XTAL_CTRL 0x24[7:0] = 0x0E disable XTAL, if No BT COEX */
  1116. rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0e);
  1117. /* p. RSV_CTRL 0x1C[7:0] = 0x0E lock ISO/CLK/Power control register */
  1118. rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
  1119. /* ==== interface into suspend === */
  1120. /* q. APS_FSMCO[15:8] = 0x58 PCIe suspend mode */
  1121. /* According to power document V11, we need to set this */
  1122. /* value as 0x18. Otherwise, we may not L0s sometimes. */
  1123. /* This indluences power consumption. Bases on SD1's test, */
  1124. /* set as 0x00 do not affect power current. And if it */
  1125. /* is set as 0x18, they had ever met auto load fail problem. */
  1126. rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x10);
  1127. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1128. "In PowerOff,reg0x%x=%X\n",
  1129. REG_SPS0_CTRL, rtl_read_byte(rtlpriv, REG_SPS0_CTRL));
  1130. /* r. Note: for PCIe interface, PON will not turn */
  1131. /* off m-bias and BandGap in PCIe suspend mode. */
  1132. /* 0x17[7] 1b': power off in process 0b' : power off over */
  1133. if (rtlpriv->rtlhal.macphymode != SINGLEMAC_SINGLEPHY) {
  1134. spin_lock_irqsave(&globalmutex_power, flags);
  1135. u1b_tmp = rtl_read_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS);
  1136. u1b_tmp &= (~BIT(7));
  1137. rtl_write_byte(rtlpriv, REG_POWER_OFF_IN_PROCESS, u1b_tmp);
  1138. spin_unlock_irqrestore(&globalmutex_power, flags);
  1139. }
  1140. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "<=======\n");
  1141. }
  1142. void rtl92de_card_disable(struct ieee80211_hw *hw)
  1143. {
  1144. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1145. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1146. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1147. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1148. enum nl80211_iftype opmode;
  1149. mac->link_state = MAC80211_NOLINK;
  1150. opmode = NL80211_IFTYPE_UNSPECIFIED;
  1151. _rtl92de_set_media_status(hw, opmode);
  1152. if (rtlpci->driver_is_goingto_unload ||
  1153. ppsc->rfoff_reason > RF_CHANGE_BY_PS)
  1154. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1155. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1156. /* Power sequence for each MAC. */
  1157. /* a. stop tx DMA */
  1158. /* b. close RF */
  1159. /* c. clear rx buf */
  1160. /* d. stop rx DMA */
  1161. /* e. reset MAC */
  1162. /* a. stop tx DMA */
  1163. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0xFE);
  1164. udelay(50);
  1165. /* b. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue */
  1166. /* c. ========RF OFF sequence========== */
  1167. /* 0x88c[23:20] = 0xf. */
  1168. rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER4, 0x00f00000, 0xf);
  1169. rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
  1170. /* APSD_CTRL 0x600[7:0] = 0x40 */
  1171. rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
  1172. /* Close antenna 0,0xc04,0xd04 */
  1173. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE, MASKBYTE0, 0);
  1174. rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE, BDWORD, 0);
  1175. /* SYS_FUNC_EN 0x02[7:0] = 0xE2 reset BB state machine */
  1176. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
  1177. /* Mac0 can not do Global reset. Mac1 can do. */
  1178. /* SYS_FUNC_EN 0x02[7:0] = 0xE0 reset BB state machine */
  1179. if (rtlpriv->rtlhal.interfaceindex == 1)
  1180. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE0);
  1181. udelay(50);
  1182. /* d. stop tx/rx dma before disable REG_CR (0x100) to fix */
  1183. /* dma hang issue when disable/enable device. */
  1184. rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 1, 0xff);
  1185. udelay(50);
  1186. rtl_write_byte(rtlpriv, REG_CR, 0x0);
  1187. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "==> Do power off.......\n");
  1188. if (rtl92d_phy_check_poweroff(hw))
  1189. _rtl92de_poweroff_adapter(hw);
  1190. return;
  1191. }
  1192. void rtl92de_interrupt_recognized(struct ieee80211_hw *hw,
  1193. struct rtl_int *intvec)
  1194. {
  1195. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1196. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1197. intvec->inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
  1198. rtl_write_dword(rtlpriv, ISR, intvec->inta);
  1199. }
  1200. void rtl92de_set_beacon_related_registers(struct ieee80211_hw *hw)
  1201. {
  1202. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1203. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1204. u16 bcn_interval, atim_window;
  1205. bcn_interval = mac->beacon_interval;
  1206. atim_window = 2;
  1207. rtl92de_disable_interrupt(hw);
  1208. rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
  1209. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1210. rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
  1211. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x20);
  1212. if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G)
  1213. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x30);
  1214. else
  1215. rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x20);
  1216. rtl_write_byte(rtlpriv, 0x606, 0x30);
  1217. }
  1218. void rtl92de_set_beacon_interval(struct ieee80211_hw *hw)
  1219. {
  1220. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1221. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1222. u16 bcn_interval = mac->beacon_interval;
  1223. RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
  1224. "beacon_interval:%d\n", bcn_interval);
  1225. rtl92de_disable_interrupt(hw);
  1226. rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
  1227. rtl92de_enable_interrupt(hw);
  1228. }
  1229. void rtl92de_update_interrupt_mask(struct ieee80211_hw *hw,
  1230. u32 add_msr, u32 rm_msr)
  1231. {
  1232. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1233. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1234. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, "add_msr:%x, rm_msr:%x\n",
  1235. add_msr, rm_msr);
  1236. if (add_msr)
  1237. rtlpci->irq_mask[0] |= add_msr;
  1238. if (rm_msr)
  1239. rtlpci->irq_mask[0] &= (~rm_msr);
  1240. rtl92de_disable_interrupt(hw);
  1241. rtl92de_enable_interrupt(hw);
  1242. }
  1243. static void _rtl92de_readpowervalue_fromprom(struct txpower_info *pwrinfo,
  1244. u8 *rom_content, bool autoLoadfail)
  1245. {
  1246. u32 rfpath, eeaddr, group, offset1, offset2;
  1247. u8 i;
  1248. memset(pwrinfo, 0, sizeof(struct txpower_info));
  1249. if (autoLoadfail) {
  1250. for (group = 0; group < CHANNEL_GROUP_MAX; group++) {
  1251. for (rfpath = 0; rfpath < RF6052_MAX_PATH; rfpath++) {
  1252. if (group < CHANNEL_GROUP_MAX_2G) {
  1253. pwrinfo->cck_index[rfpath][group] =
  1254. EEPROM_DEFAULT_TXPOWERLEVEL_2G;
  1255. pwrinfo->ht40_1sindex[rfpath][group] =
  1256. EEPROM_DEFAULT_TXPOWERLEVEL_2G;
  1257. } else {
  1258. pwrinfo->ht40_1sindex[rfpath][group] =
  1259. EEPROM_DEFAULT_TXPOWERLEVEL_5G;
  1260. }
  1261. pwrinfo->ht40_2sindexdiff[rfpath][group] =
  1262. EEPROM_DEFAULT_HT40_2SDIFF;
  1263. pwrinfo->ht20indexdiff[rfpath][group] =
  1264. EEPROM_DEFAULT_HT20_DIFF;
  1265. pwrinfo->ofdmindexdiff[rfpath][group] =
  1266. EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF;
  1267. pwrinfo->ht40maxoffset[rfpath][group] =
  1268. EEPROM_DEFAULT_HT40_PWRMAXOFFSET;
  1269. pwrinfo->ht20maxoffset[rfpath][group] =
  1270. EEPROM_DEFAULT_HT20_PWRMAXOFFSET;
  1271. }
  1272. }
  1273. for (i = 0; i < 3; i++) {
  1274. pwrinfo->tssi_a[i] = EEPROM_DEFAULT_TSSI;
  1275. pwrinfo->tssi_b[i] = EEPROM_DEFAULT_TSSI;
  1276. }
  1277. return;
  1278. }
  1279. /* Maybe autoload OK,buf the tx power index value is not filled.
  1280. * If we find it, we set it to default value. */
  1281. for (rfpath = 0; rfpath < RF6052_MAX_PATH; rfpath++) {
  1282. for (group = 0; group < CHANNEL_GROUP_MAX_2G; group++) {
  1283. eeaddr = EEPROM_CCK_TX_PWR_INX_2G + (rfpath * 3)
  1284. + group;
  1285. pwrinfo->cck_index[rfpath][group] =
  1286. (rom_content[eeaddr] == 0xFF) ?
  1287. (eeaddr > 0x7B ?
  1288. EEPROM_DEFAULT_TXPOWERLEVEL_5G :
  1289. EEPROM_DEFAULT_TXPOWERLEVEL_2G) :
  1290. rom_content[eeaddr];
  1291. }
  1292. }
  1293. for (rfpath = 0; rfpath < RF6052_MAX_PATH; rfpath++) {
  1294. for (group = 0; group < CHANNEL_GROUP_MAX; group++) {
  1295. offset1 = group / 3;
  1296. offset2 = group % 3;
  1297. eeaddr = EEPROM_HT40_1S_TX_PWR_INX_2G + (rfpath * 3) +
  1298. offset2 + offset1 * 21;
  1299. pwrinfo->ht40_1sindex[rfpath][group] =
  1300. (rom_content[eeaddr] == 0xFF) ? (eeaddr > 0x7B ?
  1301. EEPROM_DEFAULT_TXPOWERLEVEL_5G :
  1302. EEPROM_DEFAULT_TXPOWERLEVEL_2G) :
  1303. rom_content[eeaddr];
  1304. }
  1305. }
  1306. /* These just for 92D efuse offset. */
  1307. for (group = 0; group < CHANNEL_GROUP_MAX; group++) {
  1308. for (rfpath = 0; rfpath < RF6052_MAX_PATH; rfpath++) {
  1309. int base1 = EEPROM_HT40_2S_TX_PWR_INX_DIFF_2G;
  1310. offset1 = group / 3;
  1311. offset2 = group % 3;
  1312. if (rom_content[base1 + offset2 + offset1 * 21] != 0xFF)
  1313. pwrinfo->ht40_2sindexdiff[rfpath][group] =
  1314. (rom_content[base1 +
  1315. offset2 + offset1 * 21] >> (rfpath * 4))
  1316. & 0xF;
  1317. else
  1318. pwrinfo->ht40_2sindexdiff[rfpath][group] =
  1319. EEPROM_DEFAULT_HT40_2SDIFF;
  1320. if (rom_content[EEPROM_HT20_TX_PWR_INX_DIFF_2G + offset2
  1321. + offset1 * 21] != 0xFF)
  1322. pwrinfo->ht20indexdiff[rfpath][group] =
  1323. (rom_content[EEPROM_HT20_TX_PWR_INX_DIFF_2G
  1324. + offset2 + offset1 * 21] >> (rfpath * 4))
  1325. & 0xF;
  1326. else
  1327. pwrinfo->ht20indexdiff[rfpath][group] =
  1328. EEPROM_DEFAULT_HT20_DIFF;
  1329. if (rom_content[EEPROM_OFDM_TX_PWR_INX_DIFF_2G + offset2
  1330. + offset1 * 21] != 0xFF)
  1331. pwrinfo->ofdmindexdiff[rfpath][group] =
  1332. (rom_content[EEPROM_OFDM_TX_PWR_INX_DIFF_2G
  1333. + offset2 + offset1 * 21] >> (rfpath * 4))
  1334. & 0xF;
  1335. else
  1336. pwrinfo->ofdmindexdiff[rfpath][group] =
  1337. EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF;
  1338. if (rom_content[EEPROM_HT40_MAX_PWR_OFFSET_2G + offset2
  1339. + offset1 * 21] != 0xFF)
  1340. pwrinfo->ht40maxoffset[rfpath][group] =
  1341. (rom_content[EEPROM_HT40_MAX_PWR_OFFSET_2G
  1342. + offset2 + offset1 * 21] >> (rfpath * 4))
  1343. & 0xF;
  1344. else
  1345. pwrinfo->ht40maxoffset[rfpath][group] =
  1346. EEPROM_DEFAULT_HT40_PWRMAXOFFSET;
  1347. if (rom_content[EEPROM_HT20_MAX_PWR_OFFSET_2G + offset2
  1348. + offset1 * 21] != 0xFF)
  1349. pwrinfo->ht20maxoffset[rfpath][group] =
  1350. (rom_content[EEPROM_HT20_MAX_PWR_OFFSET_2G +
  1351. offset2 + offset1 * 21] >> (rfpath * 4)) &
  1352. 0xF;
  1353. else
  1354. pwrinfo->ht20maxoffset[rfpath][group] =
  1355. EEPROM_DEFAULT_HT20_PWRMAXOFFSET;
  1356. }
  1357. }
  1358. if (rom_content[EEPROM_TSSI_A_5G] != 0xFF) {
  1359. /* 5GL */
  1360. pwrinfo->tssi_a[0] = rom_content[EEPROM_TSSI_A_5G] & 0x3F;
  1361. pwrinfo->tssi_b[0] = rom_content[EEPROM_TSSI_B_5G] & 0x3F;
  1362. /* 5GM */
  1363. pwrinfo->tssi_a[1] = rom_content[EEPROM_TSSI_AB_5G] & 0x3F;
  1364. pwrinfo->tssi_b[1] =
  1365. (rom_content[EEPROM_TSSI_AB_5G] & 0xC0) >> 6 |
  1366. (rom_content[EEPROM_TSSI_AB_5G + 1] & 0x0F) << 2;
  1367. /* 5GH */
  1368. pwrinfo->tssi_a[2] = (rom_content[EEPROM_TSSI_AB_5G + 1] &
  1369. 0xF0) >> 4 |
  1370. (rom_content[EEPROM_TSSI_AB_5G + 2] & 0x03) << 4;
  1371. pwrinfo->tssi_b[2] = (rom_content[EEPROM_TSSI_AB_5G + 2] &
  1372. 0xFC) >> 2;
  1373. } else {
  1374. for (i = 0; i < 3; i++) {
  1375. pwrinfo->tssi_a[i] = EEPROM_DEFAULT_TSSI;
  1376. pwrinfo->tssi_b[i] = EEPROM_DEFAULT_TSSI;
  1377. }
  1378. }
  1379. }
  1380. static void _rtl92de_read_txpower_info(struct ieee80211_hw *hw,
  1381. bool autoload_fail, u8 *hwinfo)
  1382. {
  1383. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1384. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1385. struct txpower_info pwrinfo;
  1386. u8 tempval[2], i, pwr, diff;
  1387. u32 ch, rfPath, group;
  1388. _rtl92de_readpowervalue_fromprom(&pwrinfo, hwinfo, autoload_fail);
  1389. if (!autoload_fail) {
  1390. /* bit0~2 */
  1391. rtlefuse->eeprom_regulatory = (hwinfo[EEPROM_RF_OPT1] & 0x7);
  1392. rtlefuse->eeprom_thermalmeter =
  1393. hwinfo[EEPROM_THERMAL_METER] & 0x1f;
  1394. rtlefuse->crystalcap = hwinfo[EEPROM_XTAL_K];
  1395. tempval[0] = hwinfo[EEPROM_IQK_DELTA] & 0x03;
  1396. tempval[1] = (hwinfo[EEPROM_LCK_DELTA] & 0x0C) >> 2;
  1397. rtlefuse->txpwr_fromeprom = true;
  1398. if (IS_92D_D_CUT(rtlpriv->rtlhal.version) ||
  1399. IS_92D_E_CUT(rtlpriv->rtlhal.version)) {
  1400. rtlefuse->internal_pa_5g[0] =
  1401. !((hwinfo[EEPROM_TSSI_A_5G] & BIT(6)) >> 6);
  1402. rtlefuse->internal_pa_5g[1] =
  1403. !((hwinfo[EEPROM_TSSI_B_5G] & BIT(6)) >> 6);
  1404. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
  1405. "Is D cut,Internal PA0 %d Internal PA1 %d\n",
  1406. rtlefuse->internal_pa_5g[0],
  1407. rtlefuse->internal_pa_5g[1]);
  1408. }
  1409. rtlefuse->eeprom_c9 = hwinfo[EEPROM_RF_OPT6];
  1410. rtlefuse->eeprom_cc = hwinfo[EEPROM_RF_OPT7];
  1411. } else {
  1412. rtlefuse->eeprom_regulatory = 0;
  1413. rtlefuse->eeprom_thermalmeter = EEPROM_DEFAULT_THERMALMETER;
  1414. rtlefuse->crystalcap = EEPROM_DEFAULT_CRYSTALCAP;
  1415. tempval[0] = tempval[1] = 3;
  1416. }
  1417. /* Use default value to fill parameters if
  1418. * efuse is not filled on some place. */
  1419. /* ThermalMeter from EEPROM */
  1420. if (rtlefuse->eeprom_thermalmeter < 0x06 ||
  1421. rtlefuse->eeprom_thermalmeter > 0x1c)
  1422. rtlefuse->eeprom_thermalmeter = 0x12;
  1423. rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
  1424. /* check XTAL_K */
  1425. if (rtlefuse->crystalcap == 0xFF)
  1426. rtlefuse->crystalcap = 0;
  1427. if (rtlefuse->eeprom_regulatory > 3)
  1428. rtlefuse->eeprom_regulatory = 0;
  1429. for (i = 0; i < 2; i++) {
  1430. switch (tempval[i]) {
  1431. case 0:
  1432. tempval[i] = 5;
  1433. break;
  1434. case 1:
  1435. tempval[i] = 4;
  1436. break;
  1437. case 2:
  1438. tempval[i] = 3;
  1439. break;
  1440. case 3:
  1441. default:
  1442. tempval[i] = 0;
  1443. break;
  1444. }
  1445. }
  1446. rtlefuse->delta_iqk = tempval[0];
  1447. if (tempval[1] > 0)
  1448. rtlefuse->delta_lck = tempval[1] - 1;
  1449. if (rtlefuse->eeprom_c9 == 0xFF)
  1450. rtlefuse->eeprom_c9 = 0x00;
  1451. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
  1452. "EEPROMRegulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
  1453. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
  1454. "ThermalMeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
  1455. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
  1456. "CrystalCap = 0x%x\n", rtlefuse->crystalcap);
  1457. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
  1458. "Delta_IQK = 0x%x Delta_LCK = 0x%x\n",
  1459. rtlefuse->delta_iqk, rtlefuse->delta_lck);
  1460. for (rfPath = 0; rfPath < RF6052_MAX_PATH; rfPath++) {
  1461. for (ch = 0; ch < CHANNEL_MAX_NUMBER; ch++) {
  1462. group = rtl92d_get_chnlgroup_fromarray((u8) ch);
  1463. if (ch < CHANNEL_MAX_NUMBER_2G)
  1464. rtlefuse->txpwrlevel_cck[rfPath][ch] =
  1465. pwrinfo.cck_index[rfPath][group];
  1466. rtlefuse->txpwrlevel_ht40_1s[rfPath][ch] =
  1467. pwrinfo.ht40_1sindex[rfPath][group];
  1468. rtlefuse->txpwr_ht20diff[rfPath][ch] =
  1469. pwrinfo.ht20indexdiff[rfPath][group];
  1470. rtlefuse->txpwr_legacyhtdiff[rfPath][ch] =
  1471. pwrinfo.ofdmindexdiff[rfPath][group];
  1472. rtlefuse->pwrgroup_ht20[rfPath][ch] =
  1473. pwrinfo.ht20maxoffset[rfPath][group];
  1474. rtlefuse->pwrgroup_ht40[rfPath][ch] =
  1475. pwrinfo.ht40maxoffset[rfPath][group];
  1476. pwr = pwrinfo.ht40_1sindex[rfPath][group];
  1477. diff = pwrinfo.ht40_2sindexdiff[rfPath][group];
  1478. rtlefuse->txpwrlevel_ht40_2s[rfPath][ch] =
  1479. (pwr > diff) ? (pwr - diff) : 0;
  1480. }
  1481. }
  1482. }
  1483. static void _rtl92de_read_macphymode_from_prom(struct ieee80211_hw *hw,
  1484. u8 *content)
  1485. {
  1486. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1487. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1488. u8 macphy_crvalue = content[EEPROM_MAC_FUNCTION];
  1489. if (macphy_crvalue & BIT(3)) {
  1490. rtlhal->macphymode = SINGLEMAC_SINGLEPHY;
  1491. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1492. "MacPhyMode SINGLEMAC_SINGLEPHY\n");
  1493. } else {
  1494. rtlhal->macphymode = DUALMAC_DUALPHY;
  1495. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1496. "MacPhyMode DUALMAC_DUALPHY\n");
  1497. }
  1498. }
  1499. static void _rtl92de_read_macphymode_and_bandtype(struct ieee80211_hw *hw,
  1500. u8 *content)
  1501. {
  1502. _rtl92de_read_macphymode_from_prom(hw, content);
  1503. rtl92d_phy_config_macphymode(hw);
  1504. rtl92d_phy_config_macphymode_info(hw);
  1505. }
  1506. static void _rtl92de_efuse_update_chip_version(struct ieee80211_hw *hw)
  1507. {
  1508. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1509. enum version_8192d chipver = rtlpriv->rtlhal.version;
  1510. u8 cutvalue[2];
  1511. u16 chipvalue;
  1512. rtlpriv->intf_ops->read_efuse_byte(hw, EEPROME_CHIP_VERSION_H,
  1513. &cutvalue[1]);
  1514. rtlpriv->intf_ops->read_efuse_byte(hw, EEPROME_CHIP_VERSION_L,
  1515. &cutvalue[0]);
  1516. chipvalue = (cutvalue[1] << 8) | cutvalue[0];
  1517. switch (chipvalue) {
  1518. case 0xAA55:
  1519. chipver |= CHIP_92D_C_CUT;
  1520. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "C-CUT!!!\n");
  1521. break;
  1522. case 0x9966:
  1523. chipver |= CHIP_92D_D_CUT;
  1524. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "D-CUT!!!\n");
  1525. break;
  1526. case 0xCC33:
  1527. chipver |= CHIP_92D_E_CUT;
  1528. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "E-CUT!!!\n");
  1529. break;
  1530. default:
  1531. chipver |= CHIP_92D_D_CUT;
  1532. pr_err("Unknown CUT!\n");
  1533. break;
  1534. }
  1535. rtlpriv->rtlhal.version = chipver;
  1536. }
  1537. static void _rtl92de_read_adapter_info(struct ieee80211_hw *hw)
  1538. {
  1539. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1540. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1541. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1542. int params[] = {RTL8190_EEPROM_ID, EEPROM_VID, EEPROM_DID,
  1543. EEPROM_SVID, EEPROM_SMID, EEPROM_MAC_ADDR_MAC0_92D,
  1544. EEPROM_CHANNEL_PLAN, EEPROM_VERSION, EEPROM_CUSTOMER_ID,
  1545. COUNTRY_CODE_WORLD_WIDE_13};
  1546. int i;
  1547. u16 usvalue;
  1548. u8 *hwinfo;
  1549. hwinfo = kzalloc(HWSET_MAX_SIZE, GFP_KERNEL);
  1550. if (!hwinfo)
  1551. return;
  1552. if (rtl_get_hwinfo(hw, rtlpriv, HWSET_MAX_SIZE, hwinfo, params))
  1553. goto exit;
  1554. _rtl92de_efuse_update_chip_version(hw);
  1555. _rtl92de_read_macphymode_and_bandtype(hw, hwinfo);
  1556. /* Read Permanent MAC address for 2nd interface */
  1557. if (rtlhal->interfaceindex != 0) {
  1558. for (i = 0; i < 6; i += 2) {
  1559. usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR_MAC1_92D + i];
  1560. *((u16 *) (&rtlefuse->dev_addr[i])) = usvalue;
  1561. }
  1562. }
  1563. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR,
  1564. rtlefuse->dev_addr);
  1565. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "%pM\n", rtlefuse->dev_addr);
  1566. _rtl92de_read_txpower_info(hw, rtlefuse->autoload_failflag, hwinfo);
  1567. /* Read Channel Plan */
  1568. switch (rtlhal->bandset) {
  1569. case BAND_ON_2_4G:
  1570. rtlefuse->channel_plan = COUNTRY_CODE_TELEC;
  1571. break;
  1572. case BAND_ON_5G:
  1573. rtlefuse->channel_plan = COUNTRY_CODE_FCC;
  1574. break;
  1575. case BAND_ON_BOTH:
  1576. rtlefuse->channel_plan = COUNTRY_CODE_FCC;
  1577. break;
  1578. default:
  1579. rtlefuse->channel_plan = COUNTRY_CODE_FCC;
  1580. break;
  1581. }
  1582. rtlefuse->txpwr_fromeprom = true;
  1583. exit:
  1584. kfree(hwinfo);
  1585. }
  1586. void rtl92de_read_eeprom_info(struct ieee80211_hw *hw)
  1587. {
  1588. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1589. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1590. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1591. u8 tmp_u1b;
  1592. rtlhal->version = _rtl92de_read_chip_version(hw);
  1593. tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
  1594. rtlefuse->autoload_status = tmp_u1b;
  1595. if (tmp_u1b & BIT(4)) {
  1596. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
  1597. rtlefuse->epromtype = EEPROM_93C46;
  1598. } else {
  1599. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
  1600. rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
  1601. }
  1602. if (tmp_u1b & BIT(5)) {
  1603. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1604. rtlefuse->autoload_failflag = false;
  1605. _rtl92de_read_adapter_info(hw);
  1606. } else {
  1607. pr_err("Autoload ERR!!\n");
  1608. }
  1609. return;
  1610. }
  1611. static void rtl92de_update_hal_rate_table(struct ieee80211_hw *hw,
  1612. struct ieee80211_sta *sta)
  1613. {
  1614. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1615. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1616. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1617. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1618. u32 ratr_value;
  1619. u8 ratr_index = 0;
  1620. u8 nmode = mac->ht_enable;
  1621. u8 mimo_ps = IEEE80211_SMPS_OFF;
  1622. u16 shortgi_rate;
  1623. u32 tmp_ratr_value;
  1624. u8 curtxbw_40mhz = mac->bw_40;
  1625. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1626. 1 : 0;
  1627. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1628. 1 : 0;
  1629. enum wireless_mode wirelessmode = mac->mode;
  1630. if (rtlhal->current_bandtype == BAND_ON_5G)
  1631. ratr_value = sta->supp_rates[1] << 4;
  1632. else
  1633. ratr_value = sta->supp_rates[0];
  1634. ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1635. sta->ht_cap.mcs.rx_mask[0] << 12);
  1636. switch (wirelessmode) {
  1637. case WIRELESS_MODE_A:
  1638. ratr_value &= 0x00000FF0;
  1639. break;
  1640. case WIRELESS_MODE_B:
  1641. if (ratr_value & 0x0000000c)
  1642. ratr_value &= 0x0000000d;
  1643. else
  1644. ratr_value &= 0x0000000f;
  1645. break;
  1646. case WIRELESS_MODE_G:
  1647. ratr_value &= 0x00000FF5;
  1648. break;
  1649. case WIRELESS_MODE_N_24G:
  1650. case WIRELESS_MODE_N_5G:
  1651. nmode = 1;
  1652. if (mimo_ps == IEEE80211_SMPS_STATIC) {
  1653. ratr_value &= 0x0007F005;
  1654. } else {
  1655. u32 ratr_mask;
  1656. if (get_rf_type(rtlphy) == RF_1T2R ||
  1657. get_rf_type(rtlphy) == RF_1T1R) {
  1658. ratr_mask = 0x000ff005;
  1659. } else {
  1660. ratr_mask = 0x0f0ff005;
  1661. }
  1662. ratr_value &= ratr_mask;
  1663. }
  1664. break;
  1665. default:
  1666. if (rtlphy->rf_type == RF_1T2R)
  1667. ratr_value &= 0x000ff0ff;
  1668. else
  1669. ratr_value &= 0x0f0ff0ff;
  1670. break;
  1671. }
  1672. ratr_value &= 0x0FFFFFFF;
  1673. if (nmode && ((curtxbw_40mhz && curshortgi_40mhz) ||
  1674. (!curtxbw_40mhz && curshortgi_20mhz))) {
  1675. ratr_value |= 0x10000000;
  1676. tmp_ratr_value = (ratr_value >> 12);
  1677. for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
  1678. if ((1 << shortgi_rate) & tmp_ratr_value)
  1679. break;
  1680. }
  1681. shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
  1682. (shortgi_rate << 4) | (shortgi_rate);
  1683. }
  1684. rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
  1685. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n",
  1686. rtl_read_dword(rtlpriv, REG_ARFR0));
  1687. }
  1688. static void rtl92de_update_hal_rate_mask(struct ieee80211_hw *hw,
  1689. struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
  1690. {
  1691. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1692. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1693. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1694. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1695. struct rtl_sta_info *sta_entry = NULL;
  1696. u32 ratr_bitmap;
  1697. u8 ratr_index;
  1698. u8 curtxbw_40mhz = (sta->bandwidth >= IEEE80211_STA_RX_BW_40) ? 1 : 0;
  1699. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1700. 1 : 0;
  1701. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1702. 1 : 0;
  1703. enum wireless_mode wirelessmode = 0;
  1704. bool shortgi = false;
  1705. u32 value[2];
  1706. u8 macid = 0;
  1707. u8 mimo_ps = IEEE80211_SMPS_OFF;
  1708. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  1709. mimo_ps = sta_entry->mimo_ps;
  1710. wirelessmode = sta_entry->wireless_mode;
  1711. if (mac->opmode == NL80211_IFTYPE_STATION)
  1712. curtxbw_40mhz = mac->bw_40;
  1713. else if (mac->opmode == NL80211_IFTYPE_AP ||
  1714. mac->opmode == NL80211_IFTYPE_ADHOC)
  1715. macid = sta->aid + 1;
  1716. if (rtlhal->current_bandtype == BAND_ON_5G)
  1717. ratr_bitmap = sta->supp_rates[1] << 4;
  1718. else
  1719. ratr_bitmap = sta->supp_rates[0];
  1720. ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1721. sta->ht_cap.mcs.rx_mask[0] << 12);
  1722. switch (wirelessmode) {
  1723. case WIRELESS_MODE_B:
  1724. ratr_index = RATR_INX_WIRELESS_B;
  1725. if (ratr_bitmap & 0x0000000c)
  1726. ratr_bitmap &= 0x0000000d;
  1727. else
  1728. ratr_bitmap &= 0x0000000f;
  1729. break;
  1730. case WIRELESS_MODE_G:
  1731. ratr_index = RATR_INX_WIRELESS_GB;
  1732. if (rssi_level == 1)
  1733. ratr_bitmap &= 0x00000f00;
  1734. else if (rssi_level == 2)
  1735. ratr_bitmap &= 0x00000ff0;
  1736. else
  1737. ratr_bitmap &= 0x00000ff5;
  1738. break;
  1739. case WIRELESS_MODE_A:
  1740. ratr_index = RATR_INX_WIRELESS_G;
  1741. ratr_bitmap &= 0x00000ff0;
  1742. break;
  1743. case WIRELESS_MODE_N_24G:
  1744. case WIRELESS_MODE_N_5G:
  1745. if (wirelessmode == WIRELESS_MODE_N_24G)
  1746. ratr_index = RATR_INX_WIRELESS_NGB;
  1747. else
  1748. ratr_index = RATR_INX_WIRELESS_NG;
  1749. if (mimo_ps == IEEE80211_SMPS_STATIC) {
  1750. if (rssi_level == 1)
  1751. ratr_bitmap &= 0x00070000;
  1752. else if (rssi_level == 2)
  1753. ratr_bitmap &= 0x0007f000;
  1754. else
  1755. ratr_bitmap &= 0x0007f005;
  1756. } else {
  1757. if (rtlphy->rf_type == RF_1T2R ||
  1758. rtlphy->rf_type == RF_1T1R) {
  1759. if (curtxbw_40mhz) {
  1760. if (rssi_level == 1)
  1761. ratr_bitmap &= 0x000f0000;
  1762. else if (rssi_level == 2)
  1763. ratr_bitmap &= 0x000ff000;
  1764. else
  1765. ratr_bitmap &= 0x000ff015;
  1766. } else {
  1767. if (rssi_level == 1)
  1768. ratr_bitmap &= 0x000f0000;
  1769. else if (rssi_level == 2)
  1770. ratr_bitmap &= 0x000ff000;
  1771. else
  1772. ratr_bitmap &= 0x000ff005;
  1773. }
  1774. } else {
  1775. if (curtxbw_40mhz) {
  1776. if (rssi_level == 1)
  1777. ratr_bitmap &= 0x0f0f0000;
  1778. else if (rssi_level == 2)
  1779. ratr_bitmap &= 0x0f0ff000;
  1780. else
  1781. ratr_bitmap &= 0x0f0ff015;
  1782. } else {
  1783. if (rssi_level == 1)
  1784. ratr_bitmap &= 0x0f0f0000;
  1785. else if (rssi_level == 2)
  1786. ratr_bitmap &= 0x0f0ff000;
  1787. else
  1788. ratr_bitmap &= 0x0f0ff005;
  1789. }
  1790. }
  1791. }
  1792. if ((curtxbw_40mhz && curshortgi_40mhz) ||
  1793. (!curtxbw_40mhz && curshortgi_20mhz)) {
  1794. if (macid == 0)
  1795. shortgi = true;
  1796. else if (macid == 1)
  1797. shortgi = false;
  1798. }
  1799. break;
  1800. default:
  1801. ratr_index = RATR_INX_WIRELESS_NGB;
  1802. if (rtlphy->rf_type == RF_1T2R)
  1803. ratr_bitmap &= 0x000ff0ff;
  1804. else
  1805. ratr_bitmap &= 0x0f0ff0ff;
  1806. break;
  1807. }
  1808. value[0] = (ratr_bitmap & 0x0fffffff) | (ratr_index << 28);
  1809. value[1] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
  1810. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
  1811. "ratr_bitmap :%x value0:%x value1:%x\n",
  1812. ratr_bitmap, value[0], value[1]);
  1813. rtl92d_fill_h2c_cmd(hw, H2C_RA_MASK, 5, (u8 *) value);
  1814. if (macid != 0)
  1815. sta_entry->ratr_index = ratr_index;
  1816. }
  1817. void rtl92de_update_hal_rate_tbl(struct ieee80211_hw *hw,
  1818. struct ieee80211_sta *sta, u8 rssi_level, bool update_bw)
  1819. {
  1820. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1821. if (rtlpriv->dm.useramask)
  1822. rtl92de_update_hal_rate_mask(hw, sta, rssi_level, update_bw);
  1823. else
  1824. rtl92de_update_hal_rate_table(hw, sta);
  1825. }
  1826. void rtl92de_update_channel_access_setting(struct ieee80211_hw *hw)
  1827. {
  1828. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1829. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1830. u16 sifs_timer;
  1831. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  1832. &mac->slot_time);
  1833. if (!mac->ht_enable)
  1834. sifs_timer = 0x0a0a;
  1835. else
  1836. sifs_timer = 0x1010;
  1837. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
  1838. }
  1839. bool rtl92de_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
  1840. {
  1841. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1842. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1843. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1844. enum rf_pwrstate e_rfpowerstate_toset;
  1845. u8 u1tmp;
  1846. bool actuallyset = false;
  1847. unsigned long flag;
  1848. if (rtlpci->being_init_adapter)
  1849. return false;
  1850. if (ppsc->swrf_processing)
  1851. return false;
  1852. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1853. if (ppsc->rfchange_inprogress) {
  1854. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1855. return false;
  1856. } else {
  1857. ppsc->rfchange_inprogress = true;
  1858. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1859. }
  1860. rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, rtl_read_byte(rtlpriv,
  1861. REG_MAC_PINMUX_CFG) & ~(BIT(3)));
  1862. u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL);
  1863. e_rfpowerstate_toset = (u1tmp & BIT(3)) ? ERFON : ERFOFF;
  1864. if (ppsc->hwradiooff && (e_rfpowerstate_toset == ERFON)) {
  1865. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1866. "GPIOChangeRF - HW Radio ON, RF ON\n");
  1867. e_rfpowerstate_toset = ERFON;
  1868. ppsc->hwradiooff = false;
  1869. actuallyset = true;
  1870. } else if (!ppsc->hwradiooff && (e_rfpowerstate_toset == ERFOFF)) {
  1871. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1872. "GPIOChangeRF - HW Radio OFF, RF OFF\n");
  1873. e_rfpowerstate_toset = ERFOFF;
  1874. ppsc->hwradiooff = true;
  1875. actuallyset = true;
  1876. }
  1877. if (actuallyset) {
  1878. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1879. ppsc->rfchange_inprogress = false;
  1880. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1881. } else {
  1882. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
  1883. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1884. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1885. ppsc->rfchange_inprogress = false;
  1886. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1887. }
  1888. *valid = 1;
  1889. return !ppsc->hwradiooff;
  1890. }
  1891. void rtl92de_set_key(struct ieee80211_hw *hw, u32 key_index,
  1892. u8 *p_macaddr, bool is_group, u8 enc_algo,
  1893. bool is_wepkey, bool clear_all)
  1894. {
  1895. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1896. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1897. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1898. u8 *macaddr = p_macaddr;
  1899. u32 entry_id;
  1900. bool is_pairwise = false;
  1901. static u8 cam_const_addr[4][6] = {
  1902. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  1903. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  1904. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  1905. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  1906. };
  1907. static u8 cam_const_broad[] = {
  1908. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  1909. };
  1910. if (clear_all) {
  1911. u8 idx;
  1912. u8 cam_offset = 0;
  1913. u8 clear_number = 5;
  1914. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  1915. for (idx = 0; idx < clear_number; idx++) {
  1916. rtl_cam_mark_invalid(hw, cam_offset + idx);
  1917. rtl_cam_empty_entry(hw, cam_offset + idx);
  1918. if (idx < 5) {
  1919. memset(rtlpriv->sec.key_buf[idx], 0,
  1920. MAX_KEY_LEN);
  1921. rtlpriv->sec.key_len[idx] = 0;
  1922. }
  1923. }
  1924. } else {
  1925. switch (enc_algo) {
  1926. case WEP40_ENCRYPTION:
  1927. enc_algo = CAM_WEP40;
  1928. break;
  1929. case WEP104_ENCRYPTION:
  1930. enc_algo = CAM_WEP104;
  1931. break;
  1932. case TKIP_ENCRYPTION:
  1933. enc_algo = CAM_TKIP;
  1934. break;
  1935. case AESCCMP_ENCRYPTION:
  1936. enc_algo = CAM_AES;
  1937. break;
  1938. default:
  1939. pr_err("switch case %#x not processed\n",
  1940. enc_algo);
  1941. enc_algo = CAM_TKIP;
  1942. break;
  1943. }
  1944. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  1945. macaddr = cam_const_addr[key_index];
  1946. entry_id = key_index;
  1947. } else {
  1948. if (is_group) {
  1949. macaddr = cam_const_broad;
  1950. entry_id = key_index;
  1951. } else {
  1952. if (mac->opmode == NL80211_IFTYPE_AP) {
  1953. entry_id = rtl_cam_get_free_entry(hw,
  1954. p_macaddr);
  1955. if (entry_id >= TOTAL_CAM_ENTRY) {
  1956. pr_err("Can not find free hw security cam entry\n");
  1957. return;
  1958. }
  1959. } else {
  1960. entry_id = CAM_PAIRWISE_KEY_POSITION;
  1961. }
  1962. key_index = PAIRWISE_KEYIDX;
  1963. is_pairwise = true;
  1964. }
  1965. }
  1966. if (rtlpriv->sec.key_len[key_index] == 0) {
  1967. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1968. "delete one entry, entry_id is %d\n",
  1969. entry_id);
  1970. if (mac->opmode == NL80211_IFTYPE_AP)
  1971. rtl_cam_del_entry(hw, p_macaddr);
  1972. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  1973. } else {
  1974. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  1975. "The insert KEY length is %d\n",
  1976. rtlpriv->sec.key_len[PAIRWISE_KEYIDX]);
  1977. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
  1978. "The insert KEY is %x %x\n",
  1979. rtlpriv->sec.key_buf[0][0],
  1980. rtlpriv->sec.key_buf[0][1]);
  1981. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1982. "add one entry\n");
  1983. if (is_pairwise) {
  1984. RT_PRINT_DATA(rtlpriv, COMP_SEC, DBG_LOUD,
  1985. "Pairwise Key content",
  1986. rtlpriv->sec.pairwise_key,
  1987. rtlpriv->
  1988. sec.key_len[PAIRWISE_KEYIDX]);
  1989. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1990. "set Pairwise key\n");
  1991. rtl_cam_add_one_entry(hw, macaddr, key_index,
  1992. entry_id, enc_algo,
  1993. CAM_CONFIG_NO_USEDK,
  1994. rtlpriv->
  1995. sec.key_buf[key_index]);
  1996. } else {
  1997. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  1998. "set group key\n");
  1999. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  2000. rtl_cam_add_one_entry(hw,
  2001. rtlefuse->dev_addr,
  2002. PAIRWISE_KEYIDX,
  2003. CAM_PAIRWISE_KEY_POSITION,
  2004. enc_algo, CAM_CONFIG_NO_USEDK,
  2005. rtlpriv->sec.key_buf[entry_id]);
  2006. }
  2007. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2008. entry_id, enc_algo,
  2009. CAM_CONFIG_NO_USEDK,
  2010. rtlpriv->sec.key_buf
  2011. [entry_id]);
  2012. }
  2013. }
  2014. }
  2015. }
  2016. void rtl92de_suspend(struct ieee80211_hw *hw)
  2017. {
  2018. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2019. rtlpriv->rtlhal.macphyctl_reg = rtl_read_byte(rtlpriv,
  2020. REG_MAC_PHY_CTRL_NORMAL);
  2021. }
  2022. void rtl92de_resume(struct ieee80211_hw *hw)
  2023. {
  2024. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2025. rtl_write_byte(rtlpriv, REG_MAC_PHY_CTRL_NORMAL,
  2026. rtlpriv->rtlhal.macphyctl_reg);
  2027. }