hw.c 69 KB

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