hw.c 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549
  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 "hw.h"
  43. void rtl92se_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  44. {
  45. struct rtl_priv *rtlpriv = rtl_priv(hw);
  46. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  47. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  48. switch (variable) {
  49. case HW_VAR_RCR: {
  50. *((u32 *) (val)) = rtlpci->receive_config;
  51. break;
  52. }
  53. case HW_VAR_RF_STATE: {
  54. *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
  55. break;
  56. }
  57. case HW_VAR_FW_PSMODE_STATUS: {
  58. *((bool *) (val)) = ppsc->fw_current_inpsmode;
  59. break;
  60. }
  61. case HW_VAR_CORRECT_TSF: {
  62. u64 tsf;
  63. u32 *ptsf_low = (u32 *)&tsf;
  64. u32 *ptsf_high = ((u32 *)&tsf) + 1;
  65. *ptsf_high = rtl_read_dword(rtlpriv, (TSFR + 4));
  66. *ptsf_low = rtl_read_dword(rtlpriv, TSFR);
  67. *((u64 *) (val)) = tsf;
  68. break;
  69. }
  70. case HW_VAR_MRC: {
  71. *((bool *)(val)) = rtlpriv->dm.current_mrc_switch;
  72. break;
  73. }
  74. default: {
  75. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  76. "switch case not processed\n");
  77. break;
  78. }
  79. }
  80. }
  81. void rtl92se_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
  82. {
  83. struct rtl_priv *rtlpriv = rtl_priv(hw);
  84. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  85. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  86. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  87. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  88. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  89. switch (variable) {
  90. case HW_VAR_ETHER_ADDR:{
  91. rtl_write_dword(rtlpriv, IDR0, ((u32 *)(val))[0]);
  92. rtl_write_word(rtlpriv, IDR4, ((u16 *)(val + 4))[0]);
  93. break;
  94. }
  95. case HW_VAR_BASIC_RATE:{
  96. u16 rate_cfg = ((u16 *) val)[0];
  97. u8 rate_index = 0;
  98. if (rtlhal->version == VERSION_8192S_ACUT)
  99. rate_cfg = rate_cfg & 0x150;
  100. else
  101. rate_cfg = rate_cfg & 0x15f;
  102. rate_cfg |= 0x01;
  103. rtl_write_byte(rtlpriv, RRSR, rate_cfg & 0xff);
  104. rtl_write_byte(rtlpriv, RRSR + 1,
  105. (rate_cfg >> 8) & 0xff);
  106. while (rate_cfg > 0x1) {
  107. rate_cfg = (rate_cfg >> 1);
  108. rate_index++;
  109. }
  110. rtl_write_byte(rtlpriv, INIRTSMCS_SEL, rate_index);
  111. break;
  112. }
  113. case HW_VAR_BSSID:{
  114. rtl_write_dword(rtlpriv, BSSIDR, ((u32 *)(val))[0]);
  115. rtl_write_word(rtlpriv, BSSIDR + 4,
  116. ((u16 *)(val + 4))[0]);
  117. break;
  118. }
  119. case HW_VAR_SIFS:{
  120. rtl_write_byte(rtlpriv, SIFS_OFDM, val[0]);
  121. rtl_write_byte(rtlpriv, SIFS_OFDM + 1, val[1]);
  122. break;
  123. }
  124. case HW_VAR_SLOT_TIME:{
  125. u8 e_aci;
  126. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  127. "HW_VAR_SLOT_TIME %x\n", val[0]);
  128. rtl_write_byte(rtlpriv, SLOT_TIME, val[0]);
  129. for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
  130. rtlpriv->cfg->ops->set_hw_reg(hw,
  131. HW_VAR_AC_PARAM,
  132. (&e_aci));
  133. }
  134. break;
  135. }
  136. case HW_VAR_ACK_PREAMBLE:{
  137. u8 reg_tmp;
  138. u8 short_preamble = (bool) (*val);
  139. reg_tmp = (mac->cur_40_prime_sc) << 5;
  140. if (short_preamble)
  141. reg_tmp |= 0x80;
  142. rtl_write_byte(rtlpriv, RRSR + 2, reg_tmp);
  143. break;
  144. }
  145. case HW_VAR_AMPDU_MIN_SPACE:{
  146. u8 min_spacing_to_set;
  147. u8 sec_min_space;
  148. min_spacing_to_set = *val;
  149. if (min_spacing_to_set <= 7) {
  150. if (rtlpriv->sec.pairwise_enc_algorithm ==
  151. NO_ENCRYPTION)
  152. sec_min_space = 0;
  153. else
  154. sec_min_space = 1;
  155. if (min_spacing_to_set < sec_min_space)
  156. min_spacing_to_set = sec_min_space;
  157. if (min_spacing_to_set > 5)
  158. min_spacing_to_set = 5;
  159. mac->min_space_cfg =
  160. ((mac->min_space_cfg & 0xf8) |
  161. min_spacing_to_set);
  162. *val = min_spacing_to_set;
  163. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  164. "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
  165. mac->min_space_cfg);
  166. rtl_write_byte(rtlpriv, AMPDU_MIN_SPACE,
  167. mac->min_space_cfg);
  168. }
  169. break;
  170. }
  171. case HW_VAR_SHORTGI_DENSITY:{
  172. u8 density_to_set;
  173. density_to_set = *val;
  174. mac->min_space_cfg = rtlpriv->rtlhal.minspace_cfg;
  175. mac->min_space_cfg |= (density_to_set << 3);
  176. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  177. "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
  178. mac->min_space_cfg);
  179. rtl_write_byte(rtlpriv, AMPDU_MIN_SPACE,
  180. mac->min_space_cfg);
  181. break;
  182. }
  183. case HW_VAR_AMPDU_FACTOR:{
  184. u8 factor_toset;
  185. u8 regtoset;
  186. u8 factorlevel[18] = {
  187. 2, 4, 4, 7, 7, 13, 13,
  188. 13, 2, 7, 7, 13, 13,
  189. 15, 15, 15, 15, 0};
  190. u8 index = 0;
  191. factor_toset = *val;
  192. if (factor_toset <= 3) {
  193. factor_toset = (1 << (factor_toset + 2));
  194. if (factor_toset > 0xf)
  195. factor_toset = 0xf;
  196. for (index = 0; index < 17; index++) {
  197. if (factorlevel[index] > factor_toset)
  198. factorlevel[index] =
  199. factor_toset;
  200. }
  201. for (index = 0; index < 8; index++) {
  202. regtoset = ((factorlevel[index * 2]) |
  203. (factorlevel[index *
  204. 2 + 1] << 4));
  205. rtl_write_byte(rtlpriv,
  206. AGGLEN_LMT_L + index,
  207. regtoset);
  208. }
  209. regtoset = ((factorlevel[16]) |
  210. (factorlevel[17] << 4));
  211. rtl_write_byte(rtlpriv, AGGLEN_LMT_H, regtoset);
  212. RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
  213. "Set HW_VAR_AMPDU_FACTOR: %#x\n",
  214. factor_toset);
  215. }
  216. break;
  217. }
  218. case HW_VAR_AC_PARAM:{
  219. u8 e_aci = *val;
  220. rtl92s_dm_init_edca_turbo(hw);
  221. if (rtlpci->acm_method != EACMWAY2_SW)
  222. rtlpriv->cfg->ops->set_hw_reg(hw,
  223. HW_VAR_ACM_CTRL,
  224. &e_aci);
  225. break;
  226. }
  227. case HW_VAR_ACM_CTRL:{
  228. u8 e_aci = *val;
  229. union aci_aifsn *p_aci_aifsn = (union aci_aifsn *)(&(
  230. mac->ac[0].aifs));
  231. u8 acm = p_aci_aifsn->f.acm;
  232. u8 acm_ctrl = rtl_read_byte(rtlpriv, AcmHwCtrl);
  233. acm_ctrl = acm_ctrl | ((rtlpci->acm_method == 2) ?
  234. 0x0 : 0x1);
  235. if (acm) {
  236. switch (e_aci) {
  237. case AC0_BE:
  238. acm_ctrl |= AcmHw_BeqEn;
  239. break;
  240. case AC2_VI:
  241. acm_ctrl |= AcmHw_ViqEn;
  242. break;
  243. case AC3_VO:
  244. acm_ctrl |= AcmHw_VoqEn;
  245. break;
  246. default:
  247. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  248. "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
  249. acm);
  250. break;
  251. }
  252. } else {
  253. switch (e_aci) {
  254. case AC0_BE:
  255. acm_ctrl &= (~AcmHw_BeqEn);
  256. break;
  257. case AC2_VI:
  258. acm_ctrl &= (~AcmHw_ViqEn);
  259. break;
  260. case AC3_VO:
  261. acm_ctrl &= (~AcmHw_VoqEn);
  262. break;
  263. default:
  264. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  265. "switch case not processed\n");
  266. break;
  267. }
  268. }
  269. RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
  270. "HW_VAR_ACM_CTRL Write 0x%X\n", acm_ctrl);
  271. rtl_write_byte(rtlpriv, AcmHwCtrl, acm_ctrl);
  272. break;
  273. }
  274. case HW_VAR_RCR:{
  275. rtl_write_dword(rtlpriv, RCR, ((u32 *) (val))[0]);
  276. rtlpci->receive_config = ((u32 *) (val))[0];
  277. break;
  278. }
  279. case HW_VAR_RETRY_LIMIT:{
  280. u8 retry_limit = val[0];
  281. rtl_write_word(rtlpriv, RETRY_LIMIT,
  282. retry_limit << RETRY_LIMIT_SHORT_SHIFT |
  283. retry_limit << RETRY_LIMIT_LONG_SHIFT);
  284. break;
  285. }
  286. case HW_VAR_DUAL_TSF_RST: {
  287. break;
  288. }
  289. case HW_VAR_EFUSE_BYTES: {
  290. rtlefuse->efuse_usedbytes = *((u16 *) val);
  291. break;
  292. }
  293. case HW_VAR_EFUSE_USAGE: {
  294. rtlefuse->efuse_usedpercentage = *val;
  295. break;
  296. }
  297. case HW_VAR_IO_CMD: {
  298. break;
  299. }
  300. case HW_VAR_WPA_CONFIG: {
  301. rtl_write_byte(rtlpriv, REG_SECR, *val);
  302. break;
  303. }
  304. case HW_VAR_SET_RPWM:{
  305. break;
  306. }
  307. case HW_VAR_H2C_FW_PWRMODE:{
  308. break;
  309. }
  310. case HW_VAR_FW_PSMODE_STATUS: {
  311. ppsc->fw_current_inpsmode = *((bool *) val);
  312. break;
  313. }
  314. case HW_VAR_H2C_FW_JOINBSSRPT:{
  315. break;
  316. }
  317. case HW_VAR_AID:{
  318. break;
  319. }
  320. case HW_VAR_CORRECT_TSF:{
  321. break;
  322. }
  323. case HW_VAR_MRC: {
  324. bool bmrc_toset = *((bool *)val);
  325. u8 u1bdata = 0;
  326. if (bmrc_toset) {
  327. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE,
  328. MASKBYTE0, 0x33);
  329. u1bdata = (u8)rtl_get_bbreg(hw,
  330. ROFDM1_TRXPATHENABLE,
  331. MASKBYTE0);
  332. rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE,
  333. MASKBYTE0,
  334. ((u1bdata & 0xf0) | 0x03));
  335. u1bdata = (u8)rtl_get_bbreg(hw,
  336. ROFDM0_TRXPATHENABLE,
  337. MASKBYTE1);
  338. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE,
  339. MASKBYTE1,
  340. (u1bdata | 0x04));
  341. /* Update current settings. */
  342. rtlpriv->dm.current_mrc_switch = bmrc_toset;
  343. } else {
  344. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE,
  345. MASKBYTE0, 0x13);
  346. u1bdata = (u8)rtl_get_bbreg(hw,
  347. ROFDM1_TRXPATHENABLE,
  348. MASKBYTE0);
  349. rtl_set_bbreg(hw, ROFDM1_TRXPATHENABLE,
  350. MASKBYTE0,
  351. ((u1bdata & 0xf0) | 0x01));
  352. u1bdata = (u8)rtl_get_bbreg(hw,
  353. ROFDM0_TRXPATHENABLE,
  354. MASKBYTE1);
  355. rtl_set_bbreg(hw, ROFDM0_TRXPATHENABLE,
  356. MASKBYTE1, (u1bdata & 0xfb));
  357. /* Update current settings. */
  358. rtlpriv->dm.current_mrc_switch = bmrc_toset;
  359. }
  360. break;
  361. }
  362. case HW_VAR_FW_LPS_ACTION: {
  363. bool enter_fwlps = *((bool *)val);
  364. u8 rpwm_val, fw_pwrmode;
  365. bool fw_current_inps;
  366. if (enter_fwlps) {
  367. rpwm_val = 0x02; /* RF off */
  368. fw_current_inps = true;
  369. rtlpriv->cfg->ops->set_hw_reg(hw,
  370. HW_VAR_FW_PSMODE_STATUS,
  371. (u8 *)(&fw_current_inps));
  372. rtlpriv->cfg->ops->set_hw_reg(hw,
  373. HW_VAR_H2C_FW_PWRMODE,
  374. &ppsc->fwctrl_psmode);
  375. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
  376. &rpwm_val);
  377. } else {
  378. rpwm_val = 0x0C; /* RF on */
  379. fw_pwrmode = FW_PS_ACTIVE_MODE;
  380. fw_current_inps = false;
  381. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
  382. &rpwm_val);
  383. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
  384. &fw_pwrmode);
  385. rtlpriv->cfg->ops->set_hw_reg(hw,
  386. HW_VAR_FW_PSMODE_STATUS,
  387. (u8 *)(&fw_current_inps));
  388. }
  389. break; }
  390. default:
  391. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  392. "switch case not processed\n");
  393. break;
  394. }
  395. }
  396. void rtl92se_enable_hw_security_config(struct ieee80211_hw *hw)
  397. {
  398. struct rtl_priv *rtlpriv = rtl_priv(hw);
  399. u8 sec_reg_value = 0x0;
  400. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  401. "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
  402. rtlpriv->sec.pairwise_enc_algorithm,
  403. rtlpriv->sec.group_enc_algorithm);
  404. if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
  405. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  406. "not open hw encryption\n");
  407. return;
  408. }
  409. sec_reg_value = SCR_TXENCENABLE | SCR_RXENCENABLE;
  410. if (rtlpriv->sec.use_defaultkey) {
  411. sec_reg_value |= SCR_TXUSEDK;
  412. sec_reg_value |= SCR_RXUSEDK;
  413. }
  414. RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD, "The SECR-value %x\n",
  415. sec_reg_value);
  416. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
  417. }
  418. static u8 _rtl92se_halset_sysclk(struct ieee80211_hw *hw, u8 data)
  419. {
  420. struct rtl_priv *rtlpriv = rtl_priv(hw);
  421. u8 waitcount = 100;
  422. bool bresult = false;
  423. u8 tmpvalue;
  424. rtl_write_byte(rtlpriv, SYS_CLKR + 1, data);
  425. /* Wait the MAC synchronized. */
  426. udelay(400);
  427. /* Check if it is set ready. */
  428. tmpvalue = rtl_read_byte(rtlpriv, SYS_CLKR + 1);
  429. bresult = ((tmpvalue & BIT(7)) == (data & BIT(7)));
  430. if ((data & (BIT(6) | BIT(7))) == false) {
  431. waitcount = 100;
  432. tmpvalue = 0;
  433. while (1) {
  434. waitcount--;
  435. tmpvalue = rtl_read_byte(rtlpriv, SYS_CLKR + 1);
  436. if ((tmpvalue & BIT(6)))
  437. break;
  438. pr_err("wait for BIT(6) return value %x\n", tmpvalue);
  439. if (waitcount == 0)
  440. break;
  441. udelay(10);
  442. }
  443. if (waitcount == 0)
  444. bresult = false;
  445. else
  446. bresult = true;
  447. }
  448. return bresult;
  449. }
  450. void rtl8192se_gpiobit3_cfg_inputmode(struct ieee80211_hw *hw)
  451. {
  452. struct rtl_priv *rtlpriv = rtl_priv(hw);
  453. u8 u1tmp;
  454. /* The following config GPIO function */
  455. rtl_write_byte(rtlpriv, MAC_PINMUX_CFG, (GPIOMUX_EN | GPIOSEL_GPIO));
  456. u1tmp = rtl_read_byte(rtlpriv, GPIO_IO_SEL);
  457. /* config GPIO3 to input */
  458. u1tmp &= HAL_8192S_HW_GPIO_OFF_MASK;
  459. rtl_write_byte(rtlpriv, GPIO_IO_SEL, u1tmp);
  460. }
  461. static u8 _rtl92se_rf_onoff_detect(struct ieee80211_hw *hw)
  462. {
  463. struct rtl_priv *rtlpriv = rtl_priv(hw);
  464. u8 u1tmp;
  465. u8 retval = ERFON;
  466. /* The following config GPIO function */
  467. rtl_write_byte(rtlpriv, MAC_PINMUX_CFG, (GPIOMUX_EN | GPIOSEL_GPIO));
  468. u1tmp = rtl_read_byte(rtlpriv, GPIO_IO_SEL);
  469. /* config GPIO3 to input */
  470. u1tmp &= HAL_8192S_HW_GPIO_OFF_MASK;
  471. rtl_write_byte(rtlpriv, GPIO_IO_SEL, u1tmp);
  472. /* On some of the platform, driver cannot read correct
  473. * value without delay between Write_GPIO_SEL and Read_GPIO_IN */
  474. mdelay(10);
  475. /* check GPIO3 */
  476. u1tmp = rtl_read_byte(rtlpriv, GPIO_IN_SE);
  477. retval = (u1tmp & HAL_8192S_HW_GPIO_OFF_BIT) ? ERFON : ERFOFF;
  478. return retval;
  479. }
  480. static void _rtl92se_macconfig_before_fwdownload(struct ieee80211_hw *hw)
  481. {
  482. struct rtl_priv *rtlpriv = rtl_priv(hw);
  483. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  484. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  485. u8 i;
  486. u8 tmpu1b;
  487. u16 tmpu2b;
  488. u8 pollingcnt = 20;
  489. if (rtlpci->first_init) {
  490. /* Reset PCIE Digital */
  491. tmpu1b = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  492. tmpu1b &= 0xFE;
  493. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmpu1b);
  494. udelay(1);
  495. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmpu1b | BIT(0));
  496. }
  497. /* Switch to SW IO control */
  498. tmpu1b = rtl_read_byte(rtlpriv, (SYS_CLKR + 1));
  499. if (tmpu1b & BIT(7)) {
  500. tmpu1b &= ~(BIT(6) | BIT(7));
  501. /* Set failed, return to prevent hang. */
  502. if (!_rtl92se_halset_sysclk(hw, tmpu1b))
  503. return;
  504. }
  505. rtl_write_byte(rtlpriv, AFE_PLL_CTRL, 0x0);
  506. udelay(50);
  507. rtl_write_byte(rtlpriv, LDOA15_CTRL, 0x34);
  508. udelay(50);
  509. /* Clear FW RPWM for FW control LPS.*/
  510. rtl_write_byte(rtlpriv, RPWM, 0x0);
  511. /* Reset MAC-IO and CPU and Core Digital BIT(10)/11/15 */
  512. tmpu1b = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  513. tmpu1b &= 0x73;
  514. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmpu1b);
  515. /* wait for BIT 10/11/15 to pull high automatically!! */
  516. mdelay(1);
  517. rtl_write_byte(rtlpriv, CMDR, 0);
  518. rtl_write_byte(rtlpriv, TCR, 0);
  519. /* Data sheet not define 0x562!!! Copy from WMAC!!!!! */
  520. tmpu1b = rtl_read_byte(rtlpriv, 0x562);
  521. tmpu1b |= 0x08;
  522. rtl_write_byte(rtlpriv, 0x562, tmpu1b);
  523. tmpu1b &= ~(BIT(3));
  524. rtl_write_byte(rtlpriv, 0x562, tmpu1b);
  525. /* Enable AFE clock source */
  526. tmpu1b = rtl_read_byte(rtlpriv, AFE_XTAL_CTRL);
  527. rtl_write_byte(rtlpriv, AFE_XTAL_CTRL, (tmpu1b | 0x01));
  528. /* Delay 1.5ms */
  529. mdelay(2);
  530. tmpu1b = rtl_read_byte(rtlpriv, AFE_XTAL_CTRL + 1);
  531. rtl_write_byte(rtlpriv, AFE_XTAL_CTRL + 1, (tmpu1b & 0xfb));
  532. /* Enable AFE Macro Block's Bandgap */
  533. tmpu1b = rtl_read_byte(rtlpriv, AFE_MISC);
  534. rtl_write_byte(rtlpriv, AFE_MISC, (tmpu1b | BIT(0)));
  535. mdelay(1);
  536. /* Enable AFE Mbias */
  537. tmpu1b = rtl_read_byte(rtlpriv, AFE_MISC);
  538. rtl_write_byte(rtlpriv, AFE_MISC, (tmpu1b | 0x02));
  539. mdelay(1);
  540. /* Enable LDOA15 block */
  541. tmpu1b = rtl_read_byte(rtlpriv, LDOA15_CTRL);
  542. rtl_write_byte(rtlpriv, LDOA15_CTRL, (tmpu1b | BIT(0)));
  543. /* Set Digital Vdd to Retention isolation Path. */
  544. tmpu2b = rtl_read_word(rtlpriv, REG_SYS_ISO_CTRL);
  545. rtl_write_word(rtlpriv, REG_SYS_ISO_CTRL, (tmpu2b | BIT(11)));
  546. /* For warm reboot NIC disappera bug. */
  547. tmpu2b = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
  548. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (tmpu2b | BIT(13)));
  549. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x68);
  550. /* Enable AFE PLL Macro Block */
  551. /* We need to delay 100u before enabling PLL. */
  552. udelay(200);
  553. tmpu1b = rtl_read_byte(rtlpriv, AFE_PLL_CTRL);
  554. rtl_write_byte(rtlpriv, AFE_PLL_CTRL, (tmpu1b | BIT(0) | BIT(4)));
  555. /* for divider reset */
  556. udelay(100);
  557. rtl_write_byte(rtlpriv, AFE_PLL_CTRL, (tmpu1b | BIT(0) |
  558. BIT(4) | BIT(6)));
  559. udelay(10);
  560. rtl_write_byte(rtlpriv, AFE_PLL_CTRL, (tmpu1b | BIT(0) | BIT(4)));
  561. udelay(10);
  562. /* Enable MAC 80MHZ clock */
  563. tmpu1b = rtl_read_byte(rtlpriv, AFE_PLL_CTRL + 1);
  564. rtl_write_byte(rtlpriv, AFE_PLL_CTRL + 1, (tmpu1b | BIT(0)));
  565. mdelay(1);
  566. /* Release isolation AFE PLL & MD */
  567. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL, 0xA6);
  568. /* Enable MAC clock */
  569. tmpu2b = rtl_read_word(rtlpriv, SYS_CLKR);
  570. rtl_write_word(rtlpriv, SYS_CLKR, (tmpu2b | BIT(12) | BIT(11)));
  571. /* Enable Core digital and enable IOREG R/W */
  572. tmpu2b = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
  573. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (tmpu2b | BIT(11)));
  574. tmpu1b = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  575. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmpu1b & ~(BIT(7)));
  576. /* enable REG_EN */
  577. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (tmpu2b | BIT(11) | BIT(15)));
  578. /* Switch the control path. */
  579. tmpu2b = rtl_read_word(rtlpriv, SYS_CLKR);
  580. rtl_write_word(rtlpriv, SYS_CLKR, (tmpu2b & (~BIT(2))));
  581. tmpu1b = rtl_read_byte(rtlpriv, (SYS_CLKR + 1));
  582. tmpu1b = ((tmpu1b | BIT(7)) & (~BIT(6)));
  583. if (!_rtl92se_halset_sysclk(hw, tmpu1b))
  584. return; /* Set failed, return to prevent hang. */
  585. rtl_write_word(rtlpriv, CMDR, 0x07FC);
  586. /* MH We must enable the section of code to prevent load IMEM fail. */
  587. /* Load MAC register from WMAc temporarily We simulate macreg. */
  588. /* txt HW will provide MAC txt later */
  589. rtl_write_byte(rtlpriv, 0x6, 0x30);
  590. rtl_write_byte(rtlpriv, 0x49, 0xf0);
  591. rtl_write_byte(rtlpriv, 0x4b, 0x81);
  592. rtl_write_byte(rtlpriv, 0xb5, 0x21);
  593. rtl_write_byte(rtlpriv, 0xdc, 0xff);
  594. rtl_write_byte(rtlpriv, 0xdd, 0xff);
  595. rtl_write_byte(rtlpriv, 0xde, 0xff);
  596. rtl_write_byte(rtlpriv, 0xdf, 0xff);
  597. rtl_write_byte(rtlpriv, 0x11a, 0x00);
  598. rtl_write_byte(rtlpriv, 0x11b, 0x00);
  599. for (i = 0; i < 32; i++)
  600. rtl_write_byte(rtlpriv, INIMCS_SEL + i, 0x1b);
  601. rtl_write_byte(rtlpriv, 0x236, 0xff);
  602. rtl_write_byte(rtlpriv, 0x503, 0x22);
  603. if (ppsc->support_aspm && !ppsc->support_backdoor)
  604. rtl_write_byte(rtlpriv, 0x560, 0x40);
  605. else
  606. rtl_write_byte(rtlpriv, 0x560, 0x00);
  607. rtl_write_byte(rtlpriv, DBG_PORT, 0x91);
  608. /* Set RX Desc Address */
  609. rtl_write_dword(rtlpriv, RDQDA, rtlpci->rx_ring[RX_MPDU_QUEUE].dma);
  610. rtl_write_dword(rtlpriv, RCDA, rtlpci->rx_ring[RX_CMD_QUEUE].dma);
  611. /* Set TX Desc Address */
  612. rtl_write_dword(rtlpriv, TBKDA, rtlpci->tx_ring[BK_QUEUE].dma);
  613. rtl_write_dword(rtlpriv, TBEDA, rtlpci->tx_ring[BE_QUEUE].dma);
  614. rtl_write_dword(rtlpriv, TVIDA, rtlpci->tx_ring[VI_QUEUE].dma);
  615. rtl_write_dword(rtlpriv, TVODA, rtlpci->tx_ring[VO_QUEUE].dma);
  616. rtl_write_dword(rtlpriv, TBDA, rtlpci->tx_ring[BEACON_QUEUE].dma);
  617. rtl_write_dword(rtlpriv, TCDA, rtlpci->tx_ring[TXCMD_QUEUE].dma);
  618. rtl_write_dword(rtlpriv, TMDA, rtlpci->tx_ring[MGNT_QUEUE].dma);
  619. rtl_write_dword(rtlpriv, THPDA, rtlpci->tx_ring[HIGH_QUEUE].dma);
  620. rtl_write_dword(rtlpriv, HDA, rtlpci->tx_ring[HCCA_QUEUE].dma);
  621. rtl_write_word(rtlpriv, CMDR, 0x37FC);
  622. /* To make sure that TxDMA can ready to download FW. */
  623. /* We should reset TxDMA if IMEM RPT was not ready. */
  624. do {
  625. tmpu1b = rtl_read_byte(rtlpriv, TCR);
  626. if ((tmpu1b & TXDMA_INIT_VALUE) == TXDMA_INIT_VALUE)
  627. break;
  628. udelay(5);
  629. } while (pollingcnt--);
  630. if (pollingcnt <= 0) {
  631. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  632. "Polling TXDMA_INIT_VALUE timeout!! Current TCR(%#x)\n",
  633. tmpu1b);
  634. tmpu1b = rtl_read_byte(rtlpriv, CMDR);
  635. rtl_write_byte(rtlpriv, CMDR, tmpu1b & (~TXDMA_EN));
  636. udelay(2);
  637. /* Reset TxDMA */
  638. rtl_write_byte(rtlpriv, CMDR, tmpu1b | TXDMA_EN);
  639. }
  640. /* After MACIO reset,we must refresh LED state. */
  641. if ((ppsc->rfoff_reason == RF_CHANGE_BY_IPS) ||
  642. (ppsc->rfoff_reason == 0)) {
  643. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  644. struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
  645. enum rf_pwrstate rfpwr_state_toset;
  646. rfpwr_state_toset = _rtl92se_rf_onoff_detect(hw);
  647. if (rfpwr_state_toset == ERFON)
  648. rtl92se_sw_led_on(hw, pLed0);
  649. }
  650. }
  651. static void _rtl92se_macconfig_after_fwdownload(struct ieee80211_hw *hw)
  652. {
  653. struct rtl_priv *rtlpriv = rtl_priv(hw);
  654. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  655. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  656. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  657. u8 i;
  658. u16 tmpu2b;
  659. /* 1. System Configure Register (Offset: 0x0000 - 0x003F) */
  660. /* 2. Command Control Register (Offset: 0x0040 - 0x004F) */
  661. /* Turn on 0x40 Command register */
  662. rtl_write_word(rtlpriv, CMDR, (BBRSTN | BB_GLB_RSTN |
  663. SCHEDULE_EN | MACRXEN | MACTXEN | DDMA_EN | FW2HW_EN |
  664. RXDMA_EN | TXDMA_EN | HCI_RXDMA_EN | HCI_TXDMA_EN));
  665. /* Set TCR TX DMA pre 2 FULL enable bit */
  666. rtl_write_dword(rtlpriv, TCR, rtl_read_dword(rtlpriv, TCR) |
  667. TXDMAPRE2FULL);
  668. /* Set RCR */
  669. rtl_write_dword(rtlpriv, RCR, rtlpci->receive_config);
  670. /* 3. MACID Setting Register (Offset: 0x0050 - 0x007F) */
  671. /* 4. Timing Control Register (Offset: 0x0080 - 0x009F) */
  672. /* Set CCK/OFDM SIFS */
  673. /* CCK SIFS shall always be 10us. */
  674. rtl_write_word(rtlpriv, SIFS_CCK, 0x0a0a);
  675. rtl_write_word(rtlpriv, SIFS_OFDM, 0x1010);
  676. /* Set AckTimeout */
  677. rtl_write_byte(rtlpriv, ACK_TIMEOUT, 0x40);
  678. /* Beacon related */
  679. rtl_write_word(rtlpriv, BCN_INTERVAL, 100);
  680. rtl_write_word(rtlpriv, ATIMWND, 2);
  681. /* 5. FIFO Control Register (Offset: 0x00A0 - 0x015F) */
  682. /* 5.1 Initialize Number of Reserved Pages in Firmware Queue */
  683. /* Firmware allocate now, associate with FW internal setting.!!! */
  684. /* 5.2 Setting TX/RX page size 0/1/2/3/4=64/128/256/512/1024 */
  685. /* 5.3 Set driver info, we only accept PHY status now. */
  686. /* 5.4 Set RXDMA arbitration to control RXDMA/MAC/FW R/W for RXFIFO */
  687. rtl_write_byte(rtlpriv, RXDMA, rtl_read_byte(rtlpriv, RXDMA) | BIT(6));
  688. /* 6. Adaptive Control Register (Offset: 0x0160 - 0x01CF) */
  689. /* Set RRSR to all legacy rate and HT rate
  690. * CCK rate is supported by default.
  691. * CCK rate will be filtered out only when associated
  692. * AP does not support it.
  693. * Only enable ACK rate to OFDM 24M
  694. * Disable RRSR for CCK rate in A-Cut */
  695. if (rtlhal->version == VERSION_8192S_ACUT)
  696. rtl_write_byte(rtlpriv, RRSR, 0xf0);
  697. else if (rtlhal->version == VERSION_8192S_BCUT)
  698. rtl_write_byte(rtlpriv, RRSR, 0xff);
  699. rtl_write_byte(rtlpriv, RRSR + 1, 0x01);
  700. rtl_write_byte(rtlpriv, RRSR + 2, 0x00);
  701. /* A-Cut IC do not support CCK rate. We forbid ARFR to */
  702. /* fallback to CCK rate */
  703. for (i = 0; i < 8; i++) {
  704. /*Disable RRSR for CCK rate in A-Cut */
  705. if (rtlhal->version == VERSION_8192S_ACUT)
  706. rtl_write_dword(rtlpriv, ARFR0 + i * 4, 0x1f0ff0f0);
  707. }
  708. /* Different rate use different AMPDU size */
  709. /* MCS32/ MCS15_SG use max AMPDU size 15*2=30K */
  710. rtl_write_byte(rtlpriv, AGGLEN_LMT_H, 0x0f);
  711. /* MCS0/1/2/3 use max AMPDU size 4*2=8K */
  712. rtl_write_word(rtlpriv, AGGLEN_LMT_L, 0x7442);
  713. /* MCS4/5 use max AMPDU size 8*2=16K 6/7 use 10*2=20K */
  714. rtl_write_word(rtlpriv, AGGLEN_LMT_L + 2, 0xddd7);
  715. /* MCS8/9 use max AMPDU size 8*2=16K 10/11 use 10*2=20K */
  716. rtl_write_word(rtlpriv, AGGLEN_LMT_L + 4, 0xd772);
  717. /* MCS12/13/14/15 use max AMPDU size 15*2=30K */
  718. rtl_write_word(rtlpriv, AGGLEN_LMT_L + 6, 0xfffd);
  719. /* Set Data / Response auto rate fallack retry count */
  720. rtl_write_dword(rtlpriv, DARFRC, 0x04010000);
  721. rtl_write_dword(rtlpriv, DARFRC + 4, 0x09070605);
  722. rtl_write_dword(rtlpriv, RARFRC, 0x04010000);
  723. rtl_write_dword(rtlpriv, RARFRC + 4, 0x09070605);
  724. /* 7. EDCA Setting Register (Offset: 0x01D0 - 0x01FF) */
  725. /* Set all rate to support SG */
  726. rtl_write_word(rtlpriv, SG_RATE, 0xFFFF);
  727. /* 8. WMAC, BA, and CCX related Register (Offset: 0x0200 - 0x023F) */
  728. /* Set NAV protection length */
  729. rtl_write_word(rtlpriv, NAV_PROT_LEN, 0x0080);
  730. /* CF-END Threshold */
  731. rtl_write_byte(rtlpriv, CFEND_TH, 0xFF);
  732. /* Set AMPDU minimum space */
  733. rtl_write_byte(rtlpriv, AMPDU_MIN_SPACE, 0x07);
  734. /* Set TXOP stall control for several queue/HI/BCN/MGT/ */
  735. rtl_write_byte(rtlpriv, TXOP_STALL_CTRL, 0x00);
  736. /* 9. Security Control Register (Offset: 0x0240 - 0x025F) */
  737. /* 10. Power Save Control Register (Offset: 0x0260 - 0x02DF) */
  738. /* 11. General Purpose Register (Offset: 0x02E0 - 0x02FF) */
  739. /* 12. Host Interrupt Status Register (Offset: 0x0300 - 0x030F) */
  740. /* 13. Test Mode and Debug Control Register (Offset: 0x0310 - 0x034F) */
  741. /* 14. Set driver info, we only accept PHY status now. */
  742. rtl_write_byte(rtlpriv, RXDRVINFO_SZ, 4);
  743. /* 15. For EEPROM R/W Workaround */
  744. /* 16. For EFUSE to share REG_SYS_FUNC_EN with EEPROM!!! */
  745. tmpu2b = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN);
  746. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, tmpu2b | BIT(13));
  747. tmpu2b = rtl_read_byte(rtlpriv, REG_SYS_ISO_CTRL);
  748. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL, tmpu2b & (~BIT(8)));
  749. /* 17. For EFUSE */
  750. /* We may R/W EFUSE in EEPROM mode */
  751. if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
  752. u8 tempval;
  753. tempval = rtl_read_byte(rtlpriv, REG_SYS_ISO_CTRL + 1);
  754. tempval &= 0xFE;
  755. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, tempval);
  756. /* Change Program timing */
  757. rtl_write_byte(rtlpriv, REG_EFUSE_CTRL + 3, 0x72);
  758. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "EFUSE CONFIG OK\n");
  759. }
  760. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "OK\n");
  761. }
  762. static void _rtl92se_hw_configure(struct ieee80211_hw *hw)
  763. {
  764. struct rtl_priv *rtlpriv = rtl_priv(hw);
  765. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  766. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  767. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  768. u8 reg_bw_opmode = 0;
  769. u32 reg_rrsr = 0;
  770. u8 regtmp = 0;
  771. reg_bw_opmode = BW_OPMODE_20MHZ;
  772. reg_rrsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
  773. regtmp = rtl_read_byte(rtlpriv, INIRTSMCS_SEL);
  774. reg_rrsr = ((reg_rrsr & 0x000fffff) << 8) | regtmp;
  775. rtl_write_dword(rtlpriv, INIRTSMCS_SEL, reg_rrsr);
  776. rtl_write_byte(rtlpriv, BW_OPMODE, reg_bw_opmode);
  777. /* Set Retry Limit here */
  778. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
  779. (u8 *)(&rtlpci->shortretry_limit));
  780. rtl_write_byte(rtlpriv, MLT, 0x8f);
  781. /* For Min Spacing configuration. */
  782. switch (rtlphy->rf_type) {
  783. case RF_1T2R:
  784. case RF_1T1R:
  785. rtlhal->minspace_cfg = (MAX_MSS_DENSITY_1T << 3);
  786. break;
  787. case RF_2T2R:
  788. case RF_2T2R_GREEN:
  789. rtlhal->minspace_cfg = (MAX_MSS_DENSITY_2T << 3);
  790. break;
  791. }
  792. rtl_write_byte(rtlpriv, AMPDU_MIN_SPACE, rtlhal->minspace_cfg);
  793. }
  794. int rtl92se_hw_init(struct ieee80211_hw *hw)
  795. {
  796. struct rtl_priv *rtlpriv = rtl_priv(hw);
  797. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  798. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  799. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  800. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  801. u8 tmp_byte = 0;
  802. unsigned long flags;
  803. bool rtstatus = true;
  804. u8 tmp_u1b;
  805. int err = false;
  806. u8 i;
  807. int wdcapra_add[] = {
  808. EDCAPARA_BE, EDCAPARA_BK,
  809. EDCAPARA_VI, EDCAPARA_VO};
  810. u8 secr_value = 0x0;
  811. rtlpci->being_init_adapter = true;
  812. /* As this function can take a very long time (up to 350 ms)
  813. * and can be called with irqs disabled, reenable the irqs
  814. * to let the other devices continue being serviced.
  815. *
  816. * It is safe doing so since our own interrupts will only be enabled
  817. * in a subsequent step.
  818. */
  819. local_save_flags(flags);
  820. local_irq_enable();
  821. rtlpriv->intf_ops->disable_aspm(hw);
  822. /* 1. MAC Initialize */
  823. /* Before FW download, we have to set some MAC register */
  824. _rtl92se_macconfig_before_fwdownload(hw);
  825. rtlhal->version = (enum version_8192s)((rtl_read_dword(rtlpriv,
  826. PMC_FSM) >> 16) & 0xF);
  827. rtl8192se_gpiobit3_cfg_inputmode(hw);
  828. /* 2. download firmware */
  829. rtstatus = rtl92s_download_fw(hw);
  830. if (!rtstatus) {
  831. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  832. "Failed to download FW. Init HW without FW now... "
  833. "Please copy FW into /lib/firmware/rtlwifi\n");
  834. err = 1;
  835. goto exit;
  836. }
  837. /* After FW download, we have to reset MAC register */
  838. _rtl92se_macconfig_after_fwdownload(hw);
  839. /*Retrieve default FW Cmd IO map. */
  840. rtlhal->fwcmd_iomap = rtl_read_word(rtlpriv, LBUS_MON_ADDR);
  841. rtlhal->fwcmd_ioparam = rtl_read_dword(rtlpriv, LBUS_ADDR_MASK);
  842. /* 3. Initialize MAC/PHY Config by MACPHY_reg.txt */
  843. if (!rtl92s_phy_mac_config(hw)) {
  844. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "MAC Config failed\n");
  845. err = rtstatus;
  846. goto exit;
  847. }
  848. /* because last function modify RCR, so we update
  849. * rcr var here, or TP will unstable for receive_config
  850. * is wrong, RX RCR_ACRC32 will cause TP unstabel & Rx
  851. * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
  852. */
  853. rtlpci->receive_config = rtl_read_dword(rtlpriv, RCR);
  854. rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
  855. rtl_write_dword(rtlpriv, RCR, rtlpci->receive_config);
  856. /* Make sure BB/RF write OK. We should prevent enter IPS. radio off. */
  857. /* We must set flag avoid BB/RF config period later!! */
  858. rtl_write_dword(rtlpriv, CMDR, 0x37FC);
  859. /* 4. Initialize BB After MAC Config PHY_reg.txt, AGC_Tab.txt */
  860. if (!rtl92s_phy_bb_config(hw)) {
  861. RT_TRACE(rtlpriv, COMP_INIT, DBG_EMERG, "BB Config failed\n");
  862. err = rtstatus;
  863. goto exit;
  864. }
  865. /* 5. Initiailze RF RAIO_A.txt RF RAIO_B.txt */
  866. /* Before initalizing RF. We can not use FW to do RF-R/W. */
  867. rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
  868. /* Before RF-R/W we must execute the IO from Scott's suggestion. */
  869. rtl_write_byte(rtlpriv, AFE_XTAL_CTRL + 1, 0xDB);
  870. if (rtlhal->version == VERSION_8192S_ACUT)
  871. rtl_write_byte(rtlpriv, SPS1_CTRL + 3, 0x07);
  872. else
  873. rtl_write_byte(rtlpriv, RF_CTRL, 0x07);
  874. if (!rtl92s_phy_rf_config(hw)) {
  875. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "RF Config failed\n");
  876. err = rtstatus;
  877. goto exit;
  878. }
  879. /* After read predefined TXT, we must set BB/MAC/RF
  880. * register as our requirement */
  881. rtlphy->rfreg_chnlval[0] = rtl92s_phy_query_rf_reg(hw,
  882. (enum radio_path)0,
  883. RF_CHNLBW,
  884. RFREG_OFFSET_MASK);
  885. rtlphy->rfreg_chnlval[1] = rtl92s_phy_query_rf_reg(hw,
  886. (enum radio_path)1,
  887. RF_CHNLBW,
  888. RFREG_OFFSET_MASK);
  889. /*---- Set CCK and OFDM Block "ON"----*/
  890. rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
  891. rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
  892. /*3 Set Hardware(Do nothing now) */
  893. _rtl92se_hw_configure(hw);
  894. /* Read EEPROM TX power index and PHY_REG_PG.txt to capture correct */
  895. /* TX power index for different rate set. */
  896. /* Get original hw reg values */
  897. rtl92s_phy_get_hw_reg_originalvalue(hw);
  898. /* Write correct tx power index */
  899. rtl92s_phy_set_txpower(hw, rtlphy->current_channel);
  900. /* We must set MAC address after firmware download. */
  901. for (i = 0; i < 6; i++)
  902. rtl_write_byte(rtlpriv, MACIDR0 + i, rtlefuse->dev_addr[i]);
  903. /* EEPROM R/W workaround */
  904. tmp_u1b = rtl_read_byte(rtlpriv, MAC_PINMUX_CFG);
  905. rtl_write_byte(rtlpriv, MAC_PINMUX_CFG, tmp_u1b & (~BIT(3)));
  906. rtl_write_byte(rtlpriv, 0x4d, 0x0);
  907. if (hal_get_firmwareversion(rtlpriv) >= 0x49) {
  908. tmp_byte = rtl_read_byte(rtlpriv, FW_RSVD_PG_CRTL) & (~BIT(4));
  909. tmp_byte = tmp_byte | BIT(5);
  910. rtl_write_byte(rtlpriv, FW_RSVD_PG_CRTL, tmp_byte);
  911. rtl_write_dword(rtlpriv, TXDESC_MSK, 0xFFFFCFFF);
  912. }
  913. /* We enable high power and RA related mechanism after NIC
  914. * initialized. */
  915. if (hal_get_firmwareversion(rtlpriv) >= 0x35) {
  916. /* Fw v.53 and later. */
  917. rtl92s_phy_set_fw_cmd(hw, FW_CMD_RA_INIT);
  918. } else if (hal_get_firmwareversion(rtlpriv) == 0x34) {
  919. /* Fw v.52. */
  920. rtl_write_dword(rtlpriv, WFM5, FW_RA_INIT);
  921. rtl92s_phy_chk_fwcmd_iodone(hw);
  922. } else {
  923. /* Compatible earlier FW version. */
  924. rtl_write_dword(rtlpriv, WFM5, FW_RA_RESET);
  925. rtl92s_phy_chk_fwcmd_iodone(hw);
  926. rtl_write_dword(rtlpriv, WFM5, FW_RA_ACTIVE);
  927. rtl92s_phy_chk_fwcmd_iodone(hw);
  928. rtl_write_dword(rtlpriv, WFM5, FW_RA_REFRESH);
  929. rtl92s_phy_chk_fwcmd_iodone(hw);
  930. }
  931. /* Add to prevent ASPM bug. */
  932. /* Always enable hst and NIC clock request. */
  933. rtl92s_phy_switch_ephy_parameter(hw);
  934. /* Security related
  935. * 1. Clear all H/W keys.
  936. * 2. Enable H/W encryption/decryption. */
  937. rtl_cam_reset_all_entry(hw);
  938. secr_value |= SCR_TXENCENABLE;
  939. secr_value |= SCR_RXENCENABLE;
  940. secr_value |= SCR_NOSKMC;
  941. rtl_write_byte(rtlpriv, REG_SECR, secr_value);
  942. for (i = 0; i < 4; i++)
  943. rtl_write_dword(rtlpriv, wdcapra_add[i], 0x5e4322);
  944. if (rtlphy->rf_type == RF_1T2R) {
  945. bool mrc2set = true;
  946. /* Turn on B-Path */
  947. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_MRC, (u8 *)&mrc2set);
  948. }
  949. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_ON);
  950. rtl92s_dm_init(hw);
  951. exit:
  952. local_irq_restore(flags);
  953. rtlpci->being_init_adapter = false;
  954. return err;
  955. }
  956. void rtl92se_set_mac_addr(struct rtl_io *io, const u8 *addr)
  957. {
  958. /* This is a stub. */
  959. }
  960. void rtl92se_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
  961. {
  962. struct rtl_priv *rtlpriv = rtl_priv(hw);
  963. u32 reg_rcr;
  964. if (rtlpriv->psc.rfpwr_state != ERFON)
  965. return;
  966. rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
  967. if (check_bssid) {
  968. reg_rcr |= (RCR_CBSSID);
  969. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
  970. } else if (!check_bssid) {
  971. reg_rcr &= (~RCR_CBSSID);
  972. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
  973. }
  974. }
  975. static int _rtl92se_set_media_status(struct ieee80211_hw *hw,
  976. enum nl80211_iftype type)
  977. {
  978. struct rtl_priv *rtlpriv = rtl_priv(hw);
  979. u8 bt_msr = rtl_read_byte(rtlpriv, MSR);
  980. u32 temp;
  981. bt_msr &= ~MSR_LINK_MASK;
  982. switch (type) {
  983. case NL80211_IFTYPE_UNSPECIFIED:
  984. bt_msr |= (MSR_LINK_NONE << MSR_LINK_SHIFT);
  985. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  986. "Set Network type to NO LINK!\n");
  987. break;
  988. case NL80211_IFTYPE_ADHOC:
  989. bt_msr |= (MSR_LINK_ADHOC << MSR_LINK_SHIFT);
  990. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  991. "Set Network type to Ad Hoc!\n");
  992. break;
  993. case NL80211_IFTYPE_STATION:
  994. bt_msr |= (MSR_LINK_MANAGED << MSR_LINK_SHIFT);
  995. RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
  996. "Set Network type to STA!\n");
  997. break;
  998. case NL80211_IFTYPE_AP:
  999. bt_msr |= (MSR_LINK_MASTER << MSR_LINK_SHIFT);
  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. }
  1008. if (type != NL80211_IFTYPE_AP &&
  1009. rtlpriv->mac80211.link_state < MAC80211_LINKED)
  1010. bt_msr = rtl_read_byte(rtlpriv, MSR) & ~MSR_LINK_MASK;
  1011. rtl_write_byte(rtlpriv, MSR, bt_msr);
  1012. temp = rtl_read_dword(rtlpriv, TCR);
  1013. rtl_write_dword(rtlpriv, TCR, temp & (~BIT(8)));
  1014. rtl_write_dword(rtlpriv, TCR, temp | BIT(8));
  1015. return 0;
  1016. }
  1017. /* HW_VAR_MEDIA_STATUS & HW_VAR_CECHK_BSSID */
  1018. int rtl92se_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
  1019. {
  1020. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1021. if (_rtl92se_set_media_status(hw, type))
  1022. return -EOPNOTSUPP;
  1023. if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
  1024. if (type != NL80211_IFTYPE_AP)
  1025. rtl92se_set_check_bssid(hw, true);
  1026. } else {
  1027. rtl92se_set_check_bssid(hw, false);
  1028. }
  1029. return 0;
  1030. }
  1031. /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
  1032. void rtl92se_set_qos(struct ieee80211_hw *hw, int aci)
  1033. {
  1034. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1035. rtl92s_dm_init_edca_turbo(hw);
  1036. switch (aci) {
  1037. case AC1_BK:
  1038. rtl_write_dword(rtlpriv, EDCAPARA_BK, 0xa44f);
  1039. break;
  1040. case AC0_BE:
  1041. /* rtl_write_dword(rtlpriv, EDCAPARA_BE, u4b_ac_param); */
  1042. break;
  1043. case AC2_VI:
  1044. rtl_write_dword(rtlpriv, EDCAPARA_VI, 0x5e4322);
  1045. break;
  1046. case AC3_VO:
  1047. rtl_write_dword(rtlpriv, EDCAPARA_VO, 0x2f3222);
  1048. break;
  1049. default:
  1050. RT_ASSERT(false, "invalid aci: %d !\n", aci);
  1051. break;
  1052. }
  1053. }
  1054. void rtl92se_enable_interrupt(struct ieee80211_hw *hw)
  1055. {
  1056. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1057. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1058. rtl_write_dword(rtlpriv, INTA_MASK, rtlpci->irq_mask[0]);
  1059. /* Support Bit 32-37(Assign as Bit 0-5) interrupt setting now */
  1060. rtl_write_dword(rtlpriv, INTA_MASK + 4, rtlpci->irq_mask[1] & 0x3F);
  1061. rtlpci->irq_enabled = true;
  1062. }
  1063. void rtl92se_disable_interrupt(struct ieee80211_hw *hw)
  1064. {
  1065. struct rtl_priv *rtlpriv;
  1066. struct rtl_pci *rtlpci;
  1067. rtlpriv = rtl_priv(hw);
  1068. /* if firmware not available, no interrupts */
  1069. if (!rtlpriv || !rtlpriv->max_fw_size)
  1070. return;
  1071. rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1072. rtl_write_dword(rtlpriv, INTA_MASK, 0);
  1073. rtl_write_dword(rtlpriv, INTA_MASK + 4, 0);
  1074. rtlpci->irq_enabled = false;
  1075. }
  1076. static u8 _rtl92s_set_sysclk(struct ieee80211_hw *hw, u8 data)
  1077. {
  1078. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1079. u8 waitcnt = 100;
  1080. bool result = false;
  1081. u8 tmp;
  1082. rtl_write_byte(rtlpriv, SYS_CLKR + 1, data);
  1083. /* Wait the MAC synchronized. */
  1084. udelay(400);
  1085. /* Check if it is set ready. */
  1086. tmp = rtl_read_byte(rtlpriv, SYS_CLKR + 1);
  1087. result = ((tmp & BIT(7)) == (data & BIT(7)));
  1088. if ((data & (BIT(6) | BIT(7))) == false) {
  1089. waitcnt = 100;
  1090. tmp = 0;
  1091. while (1) {
  1092. waitcnt--;
  1093. tmp = rtl_read_byte(rtlpriv, SYS_CLKR + 1);
  1094. if ((tmp & BIT(6)))
  1095. break;
  1096. pr_err("wait for BIT(6) return value %x\n", tmp);
  1097. if (waitcnt == 0)
  1098. break;
  1099. udelay(10);
  1100. }
  1101. if (waitcnt == 0)
  1102. result = false;
  1103. else
  1104. result = true;
  1105. }
  1106. return result;
  1107. }
  1108. static void _rtl92s_phy_set_rfhalt(struct ieee80211_hw *hw)
  1109. {
  1110. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1111. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1112. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1113. u8 u1btmp;
  1114. if (rtlhal->driver_going2unload)
  1115. rtl_write_byte(rtlpriv, 0x560, 0x0);
  1116. /* Power save for BB/RF */
  1117. u1btmp = rtl_read_byte(rtlpriv, LDOV12D_CTRL);
  1118. u1btmp |= BIT(0);
  1119. rtl_write_byte(rtlpriv, LDOV12D_CTRL, u1btmp);
  1120. rtl_write_byte(rtlpriv, SPS1_CTRL, 0x0);
  1121. rtl_write_byte(rtlpriv, TXPAUSE, 0xFF);
  1122. rtl_write_word(rtlpriv, CMDR, 0x57FC);
  1123. udelay(100);
  1124. rtl_write_word(rtlpriv, CMDR, 0x77FC);
  1125. rtl_write_byte(rtlpriv, PHY_CCA, 0x0);
  1126. udelay(10);
  1127. rtl_write_word(rtlpriv, CMDR, 0x37FC);
  1128. udelay(10);
  1129. rtl_write_word(rtlpriv, CMDR, 0x77FC);
  1130. udelay(10);
  1131. rtl_write_word(rtlpriv, CMDR, 0x57FC);
  1132. rtl_write_word(rtlpriv, CMDR, 0x0000);
  1133. if (rtlhal->driver_going2unload) {
  1134. u1btmp = rtl_read_byte(rtlpriv, (REG_SYS_FUNC_EN + 1));
  1135. u1btmp &= ~(BIT(0));
  1136. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, u1btmp);
  1137. }
  1138. u1btmp = rtl_read_byte(rtlpriv, (SYS_CLKR + 1));
  1139. /* Add description. After switch control path. register
  1140. * after page1 will be invisible. We can not do any IO
  1141. * for register>0x40. After resume&MACIO reset, we need
  1142. * to remember previous reg content. */
  1143. if (u1btmp & BIT(7)) {
  1144. u1btmp &= ~(BIT(6) | BIT(7));
  1145. if (!_rtl92s_set_sysclk(hw, u1btmp)) {
  1146. pr_err("Switch ctrl path fail\n");
  1147. return;
  1148. }
  1149. }
  1150. /* Power save for MAC */
  1151. if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS &&
  1152. !rtlhal->driver_going2unload) {
  1153. /* enable LED function */
  1154. rtl_write_byte(rtlpriv, 0x03, 0xF9);
  1155. /* SW/HW radio off or halt adapter!! For example S3/S4 */
  1156. } else {
  1157. /* LED function disable. Power range is about 8mA now. */
  1158. /* if write 0xF1 disconnet_pci power
  1159. * ifconfig wlan0 down power are both high 35:70 */
  1160. /* if write oxF9 disconnet_pci power
  1161. * ifconfig wlan0 down power are both low 12:45*/
  1162. rtl_write_byte(rtlpriv, 0x03, 0xF9);
  1163. }
  1164. rtl_write_byte(rtlpriv, SYS_CLKR + 1, 0x70);
  1165. rtl_write_byte(rtlpriv, AFE_PLL_CTRL + 1, 0x68);
  1166. rtl_write_byte(rtlpriv, AFE_PLL_CTRL, 0x00);
  1167. rtl_write_byte(rtlpriv, LDOA15_CTRL, 0x34);
  1168. rtl_write_byte(rtlpriv, AFE_XTAL_CTRL, 0x0E);
  1169. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  1170. }
  1171. static void _rtl92se_gen_refreshledstate(struct ieee80211_hw *hw)
  1172. {
  1173. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1174. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1175. struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
  1176. struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
  1177. if (rtlpci->up_first_time == 1)
  1178. return;
  1179. if (rtlpriv->psc.rfoff_reason == RF_CHANGE_BY_IPS)
  1180. rtl92se_sw_led_on(hw, pLed0);
  1181. else
  1182. rtl92se_sw_led_off(hw, pLed0);
  1183. }
  1184. static void _rtl92se_power_domain_init(struct ieee80211_hw *hw)
  1185. {
  1186. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1187. u16 tmpu2b;
  1188. u8 tmpu1b;
  1189. rtlpriv->psc.pwrdomain_protect = true;
  1190. tmpu1b = rtl_read_byte(rtlpriv, (SYS_CLKR + 1));
  1191. if (tmpu1b & BIT(7)) {
  1192. tmpu1b &= ~(BIT(6) | BIT(7));
  1193. if (!_rtl92s_set_sysclk(hw, tmpu1b)) {
  1194. rtlpriv->psc.pwrdomain_protect = false;
  1195. return;
  1196. }
  1197. }
  1198. rtl_write_byte(rtlpriv, AFE_PLL_CTRL, 0x0);
  1199. rtl_write_byte(rtlpriv, LDOA15_CTRL, 0x34);
  1200. /* Reset MAC-IO and CPU and Core Digital BIT10/11/15 */
  1201. tmpu1b = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN + 1);
  1202. /* If IPS we need to turn LED on. So we not
  1203. * not disable BIT 3/7 of reg3. */
  1204. if (rtlpriv->psc.rfoff_reason & (RF_CHANGE_BY_IPS | RF_CHANGE_BY_HW))
  1205. tmpu1b &= 0xFB;
  1206. else
  1207. tmpu1b &= 0x73;
  1208. rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, tmpu1b);
  1209. /* wait for BIT 10/11/15 to pull high automatically!! */
  1210. mdelay(1);
  1211. rtl_write_byte(rtlpriv, CMDR, 0);
  1212. rtl_write_byte(rtlpriv, TCR, 0);
  1213. /* Data sheet not define 0x562!!! Copy from WMAC!!!!! */
  1214. tmpu1b = rtl_read_byte(rtlpriv, 0x562);
  1215. tmpu1b |= 0x08;
  1216. rtl_write_byte(rtlpriv, 0x562, tmpu1b);
  1217. tmpu1b &= ~(BIT(3));
  1218. rtl_write_byte(rtlpriv, 0x562, tmpu1b);
  1219. /* Enable AFE clock source */
  1220. tmpu1b = rtl_read_byte(rtlpriv, AFE_XTAL_CTRL);
  1221. rtl_write_byte(rtlpriv, AFE_XTAL_CTRL, (tmpu1b | 0x01));
  1222. /* Delay 1.5ms */
  1223. udelay(1500);
  1224. tmpu1b = rtl_read_byte(rtlpriv, AFE_XTAL_CTRL + 1);
  1225. rtl_write_byte(rtlpriv, AFE_XTAL_CTRL + 1, (tmpu1b & 0xfb));
  1226. /* Enable AFE Macro Block's Bandgap */
  1227. tmpu1b = rtl_read_byte(rtlpriv, AFE_MISC);
  1228. rtl_write_byte(rtlpriv, AFE_MISC, (tmpu1b | BIT(0)));
  1229. mdelay(1);
  1230. /* Enable AFE Mbias */
  1231. tmpu1b = rtl_read_byte(rtlpriv, AFE_MISC);
  1232. rtl_write_byte(rtlpriv, AFE_MISC, (tmpu1b | 0x02));
  1233. mdelay(1);
  1234. /* Enable LDOA15 block */
  1235. tmpu1b = rtl_read_byte(rtlpriv, LDOA15_CTRL);
  1236. rtl_write_byte(rtlpriv, LDOA15_CTRL, (tmpu1b | BIT(0)));
  1237. /* Set Digital Vdd to Retention isolation Path. */
  1238. tmpu2b = rtl_read_word(rtlpriv, REG_SYS_ISO_CTRL);
  1239. rtl_write_word(rtlpriv, REG_SYS_ISO_CTRL, (tmpu2b | BIT(11)));
  1240. /* For warm reboot NIC disappera bug. */
  1241. tmpu2b = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
  1242. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (tmpu2b | BIT(13)));
  1243. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x68);
  1244. /* Enable AFE PLL Macro Block */
  1245. tmpu1b = rtl_read_byte(rtlpriv, AFE_PLL_CTRL);
  1246. rtl_write_byte(rtlpriv, AFE_PLL_CTRL, (tmpu1b | BIT(0) | BIT(4)));
  1247. /* Enable MAC 80MHZ clock */
  1248. tmpu1b = rtl_read_byte(rtlpriv, AFE_PLL_CTRL + 1);
  1249. rtl_write_byte(rtlpriv, AFE_PLL_CTRL + 1, (tmpu1b | BIT(0)));
  1250. mdelay(1);
  1251. /* Release isolation AFE PLL & MD */
  1252. rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL, 0xA6);
  1253. /* Enable MAC clock */
  1254. tmpu2b = rtl_read_word(rtlpriv, SYS_CLKR);
  1255. rtl_write_word(rtlpriv, SYS_CLKR, (tmpu2b | BIT(12) | BIT(11)));
  1256. /* Enable Core digital and enable IOREG R/W */
  1257. tmpu2b = rtl_read_word(rtlpriv, REG_SYS_FUNC_EN);
  1258. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (tmpu2b | BIT(11)));
  1259. /* enable REG_EN */
  1260. rtl_write_word(rtlpriv, REG_SYS_FUNC_EN, (tmpu2b | BIT(11) | BIT(15)));
  1261. /* Switch the control path. */
  1262. tmpu2b = rtl_read_word(rtlpriv, SYS_CLKR);
  1263. rtl_write_word(rtlpriv, SYS_CLKR, (tmpu2b & (~BIT(2))));
  1264. tmpu1b = rtl_read_byte(rtlpriv, (SYS_CLKR + 1));
  1265. tmpu1b = ((tmpu1b | BIT(7)) & (~BIT(6)));
  1266. if (!_rtl92s_set_sysclk(hw, tmpu1b)) {
  1267. rtlpriv->psc.pwrdomain_protect = false;
  1268. return;
  1269. }
  1270. rtl_write_word(rtlpriv, CMDR, 0x37FC);
  1271. /* After MACIO reset,we must refresh LED state. */
  1272. _rtl92se_gen_refreshledstate(hw);
  1273. rtlpriv->psc.pwrdomain_protect = false;
  1274. }
  1275. void rtl92se_card_disable(struct ieee80211_hw *hw)
  1276. {
  1277. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1278. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1279. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1280. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1281. enum nl80211_iftype opmode;
  1282. u8 wait = 30;
  1283. rtlpriv->intf_ops->enable_aspm(hw);
  1284. if (rtlpci->driver_is_goingto_unload ||
  1285. ppsc->rfoff_reason > RF_CHANGE_BY_PS)
  1286. rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
  1287. /* we should chnge GPIO to input mode
  1288. * this will drop away current about 25mA*/
  1289. rtl8192se_gpiobit3_cfg_inputmode(hw);
  1290. /* this is very important for ips power save */
  1291. while (wait-- >= 10 && rtlpriv->psc.pwrdomain_protect) {
  1292. if (rtlpriv->psc.pwrdomain_protect)
  1293. mdelay(20);
  1294. else
  1295. break;
  1296. }
  1297. mac->link_state = MAC80211_NOLINK;
  1298. opmode = NL80211_IFTYPE_UNSPECIFIED;
  1299. _rtl92se_set_media_status(hw, opmode);
  1300. _rtl92s_phy_set_rfhalt(hw);
  1301. udelay(100);
  1302. }
  1303. void rtl92se_interrupt_recognized(struct ieee80211_hw *hw, u32 *p_inta,
  1304. u32 *p_intb)
  1305. {
  1306. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1307. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1308. *p_inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
  1309. rtl_write_dword(rtlpriv, ISR, *p_inta);
  1310. *p_intb = rtl_read_dword(rtlpriv, ISR + 4) & rtlpci->irq_mask[1];
  1311. rtl_write_dword(rtlpriv, ISR + 4, *p_intb);
  1312. }
  1313. void rtl92se_set_beacon_related_registers(struct ieee80211_hw *hw)
  1314. {
  1315. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1316. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1317. u16 bcntime_cfg = 0;
  1318. u16 bcn_cw = 6, bcn_ifs = 0xf;
  1319. u16 atim_window = 2;
  1320. /* ATIM Window (in unit of TU). */
  1321. rtl_write_word(rtlpriv, ATIMWND, atim_window);
  1322. /* Beacon interval (in unit of TU). */
  1323. rtl_write_word(rtlpriv, BCN_INTERVAL, mac->beacon_interval);
  1324. /* DrvErlyInt (in unit of TU). (Time to send
  1325. * interrupt to notify driver to change
  1326. * beacon content) */
  1327. rtl_write_word(rtlpriv, BCN_DRV_EARLY_INT, 10 << 4);
  1328. /* BcnDMATIM(in unit of us). Indicates the
  1329. * time before TBTT to perform beacon queue DMA */
  1330. rtl_write_word(rtlpriv, BCN_DMATIME, 256);
  1331. /* Force beacon frame transmission even
  1332. * after receiving beacon frame from
  1333. * other ad hoc STA */
  1334. rtl_write_byte(rtlpriv, BCN_ERR_THRESH, 100);
  1335. /* Beacon Time Configuration */
  1336. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1337. bcntime_cfg |= (bcn_cw << BCN_TCFG_CW_SHIFT);
  1338. /* TODO: bcn_ifs may required to be changed on ASIC */
  1339. bcntime_cfg |= bcn_ifs << BCN_TCFG_IFS;
  1340. /*for beacon changed */
  1341. rtl92s_phy_set_beacon_hwreg(hw, mac->beacon_interval);
  1342. }
  1343. void rtl92se_set_beacon_interval(struct ieee80211_hw *hw)
  1344. {
  1345. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1346. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1347. u16 bcn_interval = mac->beacon_interval;
  1348. /* Beacon interval (in unit of TU). */
  1349. rtl_write_word(rtlpriv, BCN_INTERVAL, bcn_interval);
  1350. /* 2008.10.24 added by tynli for beacon changed. */
  1351. rtl92s_phy_set_beacon_hwreg(hw, bcn_interval);
  1352. }
  1353. void rtl92se_update_interrupt_mask(struct ieee80211_hw *hw,
  1354. u32 add_msr, u32 rm_msr)
  1355. {
  1356. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1357. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1358. RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, "add_msr:%x, rm_msr:%x\n",
  1359. add_msr, rm_msr);
  1360. if (add_msr)
  1361. rtlpci->irq_mask[0] |= add_msr;
  1362. if (rm_msr)
  1363. rtlpci->irq_mask[0] &= (~rm_msr);
  1364. rtl92se_disable_interrupt(hw);
  1365. rtl92se_enable_interrupt(hw);
  1366. }
  1367. static void _rtl8192se_get_IC_Inferiority(struct ieee80211_hw *hw)
  1368. {
  1369. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1370. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1371. u8 efuse_id;
  1372. rtlhal->ic_class = IC_INFERIORITY_A;
  1373. /* Only retrieving while using EFUSE. */
  1374. if ((rtlefuse->epromtype == EEPROM_BOOT_EFUSE) &&
  1375. !rtlefuse->autoload_failflag) {
  1376. efuse_id = efuse_read_1byte(hw, EFUSE_IC_ID_OFFSET);
  1377. if (efuse_id == 0xfe)
  1378. rtlhal->ic_class = IC_INFERIORITY_B;
  1379. }
  1380. }
  1381. static void _rtl92se_read_adapter_info(struct ieee80211_hw *hw)
  1382. {
  1383. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1384. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1385. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1386. u16 i, usvalue;
  1387. u16 eeprom_id;
  1388. u8 tempval;
  1389. u8 hwinfo[HWSET_MAX_SIZE_92S];
  1390. u8 rf_path, index;
  1391. if (rtlefuse->epromtype == EEPROM_93C46) {
  1392. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  1393. "RTL819X Not boot from eeprom, check it !!\n");
  1394. } else if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
  1395. rtl_efuse_shadow_map_update(hw);
  1396. memcpy((void *)hwinfo, (void *)
  1397. &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
  1398. HWSET_MAX_SIZE_92S);
  1399. }
  1400. RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP",
  1401. hwinfo, HWSET_MAX_SIZE_92S);
  1402. eeprom_id = *((u16 *)&hwinfo[0]);
  1403. if (eeprom_id != RTL8190_EEPROM_ID) {
  1404. RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
  1405. "EEPROM ID(%#x) is invalid!!\n", eeprom_id);
  1406. rtlefuse->autoload_failflag = true;
  1407. } else {
  1408. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1409. rtlefuse->autoload_failflag = false;
  1410. }
  1411. if (rtlefuse->autoload_failflag)
  1412. return;
  1413. _rtl8192se_get_IC_Inferiority(hw);
  1414. /* Read IC Version && Channel Plan */
  1415. /* VID, DID SE 0xA-D */
  1416. rtlefuse->eeprom_vid = *(u16 *)&hwinfo[EEPROM_VID];
  1417. rtlefuse->eeprom_did = *(u16 *)&hwinfo[EEPROM_DID];
  1418. rtlefuse->eeprom_svid = *(u16 *)&hwinfo[EEPROM_SVID];
  1419. rtlefuse->eeprom_smid = *(u16 *)&hwinfo[EEPROM_SMID];
  1420. rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
  1421. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1422. "EEPROMId = 0x%4x\n", eeprom_id);
  1423. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1424. "EEPROM VID = 0x%4x\n", rtlefuse->eeprom_vid);
  1425. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1426. "EEPROM DID = 0x%4x\n", rtlefuse->eeprom_did);
  1427. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1428. "EEPROM SVID = 0x%4x\n", rtlefuse->eeprom_svid);
  1429. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1430. "EEPROM SMID = 0x%4x\n", rtlefuse->eeprom_smid);
  1431. for (i = 0; i < 6; i += 2) {
  1432. usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
  1433. *((u16 *) (&rtlefuse->dev_addr[i])) = usvalue;
  1434. }
  1435. for (i = 0; i < 6; i++)
  1436. rtl_write_byte(rtlpriv, MACIDR0 + i, rtlefuse->dev_addr[i]);
  1437. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "%pM\n", rtlefuse->dev_addr);
  1438. /* Get Tx Power Level by Channel */
  1439. /* Read Tx power of Channel 1 ~ 14 from EEPROM. */
  1440. /* 92S suupport RF A & B */
  1441. for (rf_path = 0; rf_path < 2; rf_path++) {
  1442. for (i = 0; i < 3; i++) {
  1443. /* Read CCK RF A & B Tx power */
  1444. rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][i] =
  1445. hwinfo[EEPROM_TXPOWERBASE + rf_path * 3 + i];
  1446. /* Read OFDM RF A & B Tx power for 1T */
  1447. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
  1448. hwinfo[EEPROM_TXPOWERBASE + 6 + rf_path * 3 + i];
  1449. /* Read OFDM RF A & B Tx power for 2T */
  1450. rtlefuse->eprom_chnl_txpwr_ht40_2sdf[rf_path][i]
  1451. = hwinfo[EEPROM_TXPOWERBASE + 12 +
  1452. rf_path * 3 + i];
  1453. }
  1454. }
  1455. for (rf_path = 0; rf_path < 2; rf_path++)
  1456. for (i = 0; i < 3; i++)
  1457. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1458. "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
  1459. rf_path, i,
  1460. rtlefuse->eeprom_chnlarea_txpwr_cck
  1461. [rf_path][i]);
  1462. for (rf_path = 0; rf_path < 2; rf_path++)
  1463. for (i = 0; i < 3; i++)
  1464. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1465. "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
  1466. rf_path, i,
  1467. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
  1468. [rf_path][i]);
  1469. for (rf_path = 0; rf_path < 2; rf_path++)
  1470. for (i = 0; i < 3; i++)
  1471. RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
  1472. "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
  1473. rf_path, i,
  1474. rtlefuse->eprom_chnl_txpwr_ht40_2sdf
  1475. [rf_path][i]);
  1476. for (rf_path = 0; rf_path < 2; rf_path++) {
  1477. /* Assign dedicated channel tx power */
  1478. for (i = 0; i < 14; i++) {
  1479. /* channel 1~3 use the same Tx Power Level. */
  1480. if (i < 3)
  1481. index = 0;
  1482. /* Channel 4-8 */
  1483. else if (i < 8)
  1484. index = 1;
  1485. /* Channel 9-14 */
  1486. else
  1487. index = 2;
  1488. /* Record A & B CCK /OFDM - 1T/2T Channel area
  1489. * tx power */
  1490. rtlefuse->txpwrlevel_cck[rf_path][i] =
  1491. rtlefuse->eeprom_chnlarea_txpwr_cck
  1492. [rf_path][index];
  1493. rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
  1494. rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
  1495. [rf_path][index];
  1496. rtlefuse->txpwrlevel_ht40_2s[rf_path][i] =
  1497. rtlefuse->eprom_chnl_txpwr_ht40_2sdf
  1498. [rf_path][index];
  1499. }
  1500. for (i = 0; i < 14; i++) {
  1501. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1502. "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
  1503. rf_path, i,
  1504. rtlefuse->txpwrlevel_cck[rf_path][i],
  1505. rtlefuse->txpwrlevel_ht40_1s[rf_path][i],
  1506. rtlefuse->txpwrlevel_ht40_2s[rf_path][i]);
  1507. }
  1508. }
  1509. for (rf_path = 0; rf_path < 2; rf_path++) {
  1510. for (i = 0; i < 3; i++) {
  1511. /* Read Power diff limit. */
  1512. rtlefuse->eeprom_pwrgroup[rf_path][i] =
  1513. hwinfo[EEPROM_TXPWRGROUP + rf_path * 3 + i];
  1514. }
  1515. }
  1516. for (rf_path = 0; rf_path < 2; rf_path++) {
  1517. /* Fill Pwr group */
  1518. for (i = 0; i < 14; i++) {
  1519. /* Chanel 1-3 */
  1520. if (i < 3)
  1521. index = 0;
  1522. /* Channel 4-8 */
  1523. else if (i < 8)
  1524. index = 1;
  1525. /* Channel 9-13 */
  1526. else
  1527. index = 2;
  1528. rtlefuse->pwrgroup_ht20[rf_path][i] =
  1529. (rtlefuse->eeprom_pwrgroup[rf_path][index] &
  1530. 0xf);
  1531. rtlefuse->pwrgroup_ht40[rf_path][i] =
  1532. ((rtlefuse->eeprom_pwrgroup[rf_path][index] &
  1533. 0xf0) >> 4);
  1534. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1535. "RF-%d pwrgroup_ht20[%d] = 0x%x\n",
  1536. rf_path, i,
  1537. rtlefuse->pwrgroup_ht20[rf_path][i]);
  1538. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1539. "RF-%d pwrgroup_ht40[%d] = 0x%x\n",
  1540. rf_path, i,
  1541. rtlefuse->pwrgroup_ht40[rf_path][i]);
  1542. }
  1543. }
  1544. for (i = 0; i < 14; i++) {
  1545. /* Read tx power difference between HT OFDM 20/40 MHZ */
  1546. /* channel 1-3 */
  1547. if (i < 3)
  1548. index = 0;
  1549. /* Channel 4-8 */
  1550. else if (i < 8)
  1551. index = 1;
  1552. /* Channel 9-14 */
  1553. else
  1554. index = 2;
  1555. tempval = hwinfo[EEPROM_TX_PWR_HT20_DIFF + index] & 0xff;
  1556. rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF);
  1557. rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] =
  1558. ((tempval >> 4) & 0xF);
  1559. /* Read OFDM<->HT tx power diff */
  1560. /* Channel 1-3 */
  1561. if (i < 3)
  1562. index = 0;
  1563. /* Channel 4-8 */
  1564. else if (i < 8)
  1565. index = 0x11;
  1566. /* Channel 9-14 */
  1567. else
  1568. index = 1;
  1569. tempval = hwinfo[EEPROM_TX_PWR_OFDM_DIFF + index] & 0xff;
  1570. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] =
  1571. (tempval & 0xF);
  1572. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] =
  1573. ((tempval >> 4) & 0xF);
  1574. tempval = hwinfo[TX_PWR_SAFETY_CHK];
  1575. rtlefuse->txpwr_safetyflag = (tempval & 0x01);
  1576. }
  1577. rtlefuse->eeprom_regulatory = 0;
  1578. if (rtlefuse->eeprom_version >= 2) {
  1579. /* BIT(0)~2 */
  1580. if (rtlefuse->eeprom_version >= 4)
  1581. rtlefuse->eeprom_regulatory =
  1582. (hwinfo[EEPROM_REGULATORY] & 0x7);
  1583. else /* BIT(0) */
  1584. rtlefuse->eeprom_regulatory =
  1585. (hwinfo[EEPROM_REGULATORY] & 0x1);
  1586. }
  1587. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1588. "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
  1589. for (i = 0; i < 14; i++)
  1590. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1591. "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
  1592. i, rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]);
  1593. for (i = 0; i < 14; i++)
  1594. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1595. "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
  1596. i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]);
  1597. for (i = 0; i < 14; i++)
  1598. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1599. "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
  1600. i, rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]);
  1601. for (i = 0; i < 14; i++)
  1602. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1603. "RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
  1604. i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]);
  1605. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1606. "TxPwrSafetyFlag = %d\n", rtlefuse->txpwr_safetyflag);
  1607. /* Read RF-indication and Tx Power gain
  1608. * index diff of legacy to HT OFDM rate. */
  1609. tempval = hwinfo[EEPROM_RFIND_POWERDIFF] & 0xff;
  1610. rtlefuse->eeprom_txpowerdiff = tempval;
  1611. rtlefuse->legacy_httxpowerdiff =
  1612. rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][0];
  1613. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1614. "TxPowerDiff = %#x\n", rtlefuse->eeprom_txpowerdiff);
  1615. /* Get TSSI value for each path. */
  1616. usvalue = *(u16 *)&hwinfo[EEPROM_TSSI_A];
  1617. rtlefuse->eeprom_tssi[RF90_PATH_A] = (u8)((usvalue & 0xff00) >> 8);
  1618. usvalue = hwinfo[EEPROM_TSSI_B];
  1619. rtlefuse->eeprom_tssi[RF90_PATH_B] = (u8)(usvalue & 0xff);
  1620. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
  1621. rtlefuse->eeprom_tssi[RF90_PATH_A],
  1622. rtlefuse->eeprom_tssi[RF90_PATH_B]);
  1623. /* Read antenna tx power offset of B/C/D to A from EEPROM */
  1624. /* and read ThermalMeter from EEPROM */
  1625. tempval = hwinfo[EEPROM_THERMALMETER];
  1626. rtlefuse->eeprom_thermalmeter = tempval;
  1627. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1628. "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
  1629. /* ThermalMeter, BIT(0)~3 for RFIC1, BIT(4)~7 for RFIC2 */
  1630. rtlefuse->thermalmeter[0] = (rtlefuse->eeprom_thermalmeter & 0x1f);
  1631. rtlefuse->tssi_13dbm = rtlefuse->eeprom_thermalmeter * 100;
  1632. /* Read CrystalCap from EEPROM */
  1633. tempval = hwinfo[EEPROM_CRYSTALCAP] >> 4;
  1634. rtlefuse->eeprom_crystalcap = tempval;
  1635. /* CrystalCap, BIT(12)~15 */
  1636. rtlefuse->crystalcap = rtlefuse->eeprom_crystalcap;
  1637. /* Read IC Version && Channel Plan */
  1638. /* Version ID, Channel plan */
  1639. rtlefuse->eeprom_channelplan = hwinfo[EEPROM_CHANNELPLAN];
  1640. rtlefuse->txpwr_fromeprom = true;
  1641. RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
  1642. "EEPROM ChannelPlan = 0x%4x\n", rtlefuse->eeprom_channelplan);
  1643. /* Read Customer ID or Board Type!!! */
  1644. tempval = hwinfo[EEPROM_BOARDTYPE];
  1645. /* Change RF type definition */
  1646. if (tempval == 0)
  1647. rtlphy->rf_type = RF_2T2R;
  1648. else if (tempval == 1)
  1649. rtlphy->rf_type = RF_1T2R;
  1650. else if (tempval == 2)
  1651. rtlphy->rf_type = RF_1T2R;
  1652. else if (tempval == 3)
  1653. rtlphy->rf_type = RF_1T1R;
  1654. /* 1T2R but 1SS (1x1 receive combining) */
  1655. rtlefuse->b1x1_recvcombine = false;
  1656. if (rtlphy->rf_type == RF_1T2R) {
  1657. tempval = rtl_read_byte(rtlpriv, 0x07);
  1658. if (!(tempval & BIT(0))) {
  1659. rtlefuse->b1x1_recvcombine = true;
  1660. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
  1661. "RF_TYPE=1T2R but only 1SS\n");
  1662. }
  1663. }
  1664. rtlefuse->b1ss_support = rtlefuse->b1x1_recvcombine;
  1665. rtlefuse->eeprom_oemid = *&hwinfo[EEPROM_CUSTOMID];
  1666. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "EEPROM Customer ID: 0x%2x",
  1667. rtlefuse->eeprom_oemid);
  1668. /* set channel paln to world wide 13 */
  1669. rtlefuse->channel_plan = COUNTRY_CODE_WORLD_WIDE_13;
  1670. }
  1671. void rtl92se_read_eeprom_info(struct ieee80211_hw *hw)
  1672. {
  1673. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1674. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  1675. u8 tmp_u1b = 0;
  1676. tmp_u1b = rtl_read_byte(rtlpriv, EPROM_CMD);
  1677. if (tmp_u1b & BIT(4)) {
  1678. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
  1679. rtlefuse->epromtype = EEPROM_93C46;
  1680. } else {
  1681. RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
  1682. rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
  1683. }
  1684. if (tmp_u1b & BIT(5)) {
  1685. RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
  1686. rtlefuse->autoload_failflag = false;
  1687. _rtl92se_read_adapter_info(hw);
  1688. } else {
  1689. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Autoload ERR!!\n");
  1690. rtlefuse->autoload_failflag = true;
  1691. }
  1692. }
  1693. static void rtl92se_update_hal_rate_table(struct ieee80211_hw *hw,
  1694. struct ieee80211_sta *sta)
  1695. {
  1696. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1697. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1698. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1699. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1700. u32 ratr_value;
  1701. u8 ratr_index = 0;
  1702. u8 nmode = mac->ht_enable;
  1703. u8 mimo_ps = IEEE80211_SMPS_OFF;
  1704. u16 shortgi_rate = 0;
  1705. u32 tmp_ratr_value = 0;
  1706. u8 curtxbw_40mhz = mac->bw_40;
  1707. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1708. 1 : 0;
  1709. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1710. 1 : 0;
  1711. enum wireless_mode wirelessmode = mac->mode;
  1712. if (rtlhal->current_bandtype == BAND_ON_5G)
  1713. ratr_value = sta->supp_rates[1] << 4;
  1714. else
  1715. ratr_value = sta->supp_rates[0];
  1716. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1717. ratr_value = 0xfff;
  1718. ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1719. sta->ht_cap.mcs.rx_mask[0] << 12);
  1720. switch (wirelessmode) {
  1721. case WIRELESS_MODE_B:
  1722. ratr_value &= 0x0000000D;
  1723. break;
  1724. case WIRELESS_MODE_G:
  1725. ratr_value &= 0x00000FF5;
  1726. break;
  1727. case WIRELESS_MODE_N_24G:
  1728. case WIRELESS_MODE_N_5G:
  1729. nmode = 1;
  1730. if (mimo_ps == IEEE80211_SMPS_STATIC) {
  1731. ratr_value &= 0x0007F005;
  1732. } else {
  1733. u32 ratr_mask;
  1734. if (get_rf_type(rtlphy) == RF_1T2R ||
  1735. get_rf_type(rtlphy) == RF_1T1R) {
  1736. if (curtxbw_40mhz)
  1737. ratr_mask = 0x000ff015;
  1738. else
  1739. ratr_mask = 0x000ff005;
  1740. } else {
  1741. if (curtxbw_40mhz)
  1742. ratr_mask = 0x0f0ff015;
  1743. else
  1744. ratr_mask = 0x0f0ff005;
  1745. }
  1746. ratr_value &= ratr_mask;
  1747. }
  1748. break;
  1749. default:
  1750. if (rtlphy->rf_type == RF_1T2R)
  1751. ratr_value &= 0x000ff0ff;
  1752. else
  1753. ratr_value &= 0x0f0ff0ff;
  1754. break;
  1755. }
  1756. if (rtlpriv->rtlhal.version >= VERSION_8192S_BCUT)
  1757. ratr_value &= 0x0FFFFFFF;
  1758. else if (rtlpriv->rtlhal.version == VERSION_8192S_ACUT)
  1759. ratr_value &= 0x0FFFFFF0;
  1760. if (nmode && ((curtxbw_40mhz &&
  1761. curshortgi_40mhz) || (!curtxbw_40mhz &&
  1762. curshortgi_20mhz))) {
  1763. ratr_value |= 0x10000000;
  1764. tmp_ratr_value = (ratr_value >> 12);
  1765. for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
  1766. if ((1 << shortgi_rate) & tmp_ratr_value)
  1767. break;
  1768. }
  1769. shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
  1770. (shortgi_rate << 4) | (shortgi_rate);
  1771. rtl_write_byte(rtlpriv, SG_RATE, shortgi_rate);
  1772. }
  1773. rtl_write_dword(rtlpriv, ARFR0 + ratr_index * 4, ratr_value);
  1774. if (ratr_value & 0xfffff000)
  1775. rtl92s_phy_set_fw_cmd(hw, FW_CMD_RA_REFRESH_N);
  1776. else
  1777. rtl92s_phy_set_fw_cmd(hw, FW_CMD_RA_REFRESH_BG);
  1778. RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n",
  1779. rtl_read_dword(rtlpriv, ARFR0));
  1780. }
  1781. static void rtl92se_update_hal_rate_mask(struct ieee80211_hw *hw,
  1782. struct ieee80211_sta *sta,
  1783. u8 rssi_level)
  1784. {
  1785. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1786. struct rtl_phy *rtlphy = &(rtlpriv->phy);
  1787. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1788. struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
  1789. struct rtl_sta_info *sta_entry = NULL;
  1790. u32 ratr_bitmap;
  1791. u8 ratr_index = 0;
  1792. u8 curtxbw_40mhz = (sta->bandwidth >= IEEE80211_STA_RX_BW_40) ? 1 : 0;
  1793. u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
  1794. 1 : 0;
  1795. u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
  1796. 1 : 0;
  1797. enum wireless_mode wirelessmode = 0;
  1798. bool shortgi = false;
  1799. u32 ratr_value = 0;
  1800. u8 shortgi_rate = 0;
  1801. u32 mask = 0;
  1802. u32 band = 0;
  1803. bool bmulticast = false;
  1804. u8 macid = 0;
  1805. u8 mimo_ps = IEEE80211_SMPS_OFF;
  1806. sta_entry = (struct rtl_sta_info *) sta->drv_priv;
  1807. wirelessmode = sta_entry->wireless_mode;
  1808. if (mac->opmode == NL80211_IFTYPE_STATION)
  1809. curtxbw_40mhz = mac->bw_40;
  1810. else if (mac->opmode == NL80211_IFTYPE_AP ||
  1811. mac->opmode == NL80211_IFTYPE_ADHOC)
  1812. macid = sta->aid + 1;
  1813. if (rtlhal->current_bandtype == BAND_ON_5G)
  1814. ratr_bitmap = sta->supp_rates[1] << 4;
  1815. else
  1816. ratr_bitmap = sta->supp_rates[0];
  1817. if (mac->opmode == NL80211_IFTYPE_ADHOC)
  1818. ratr_bitmap = 0xfff;
  1819. ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
  1820. sta->ht_cap.mcs.rx_mask[0] << 12);
  1821. switch (wirelessmode) {
  1822. case WIRELESS_MODE_B:
  1823. band |= WIRELESS_11B;
  1824. ratr_index = RATR_INX_WIRELESS_B;
  1825. if (ratr_bitmap & 0x0000000c)
  1826. ratr_bitmap &= 0x0000000d;
  1827. else
  1828. ratr_bitmap &= 0x0000000f;
  1829. break;
  1830. case WIRELESS_MODE_G:
  1831. band |= (WIRELESS_11G | WIRELESS_11B);
  1832. ratr_index = RATR_INX_WIRELESS_GB;
  1833. if (rssi_level == 1)
  1834. ratr_bitmap &= 0x00000f00;
  1835. else if (rssi_level == 2)
  1836. ratr_bitmap &= 0x00000ff0;
  1837. else
  1838. ratr_bitmap &= 0x00000ff5;
  1839. break;
  1840. case WIRELESS_MODE_A:
  1841. band |= WIRELESS_11A;
  1842. ratr_index = RATR_INX_WIRELESS_A;
  1843. ratr_bitmap &= 0x00000ff0;
  1844. break;
  1845. case WIRELESS_MODE_N_24G:
  1846. case WIRELESS_MODE_N_5G:
  1847. band |= (WIRELESS_11N | WIRELESS_11G | WIRELESS_11B);
  1848. ratr_index = RATR_INX_WIRELESS_NGB;
  1849. if (mimo_ps == IEEE80211_SMPS_STATIC) {
  1850. if (rssi_level == 1)
  1851. ratr_bitmap &= 0x00070000;
  1852. else if (rssi_level == 2)
  1853. ratr_bitmap &= 0x0007f000;
  1854. else
  1855. ratr_bitmap &= 0x0007f005;
  1856. } else {
  1857. if (rtlphy->rf_type == RF_1T2R ||
  1858. rtlphy->rf_type == RF_1T1R) {
  1859. if (rssi_level == 1) {
  1860. ratr_bitmap &= 0x000f0000;
  1861. } else if (rssi_level == 3) {
  1862. ratr_bitmap &= 0x000fc000;
  1863. } else if (rssi_level == 5) {
  1864. ratr_bitmap &= 0x000ff000;
  1865. } else {
  1866. if (curtxbw_40mhz)
  1867. ratr_bitmap &= 0x000ff015;
  1868. else
  1869. ratr_bitmap &= 0x000ff005;
  1870. }
  1871. } else {
  1872. if (rssi_level == 1) {
  1873. ratr_bitmap &= 0x0f8f0000;
  1874. } else if (rssi_level == 3) {
  1875. ratr_bitmap &= 0x0f8fc000;
  1876. } else if (rssi_level == 5) {
  1877. ratr_bitmap &= 0x0f8ff000;
  1878. } else {
  1879. if (curtxbw_40mhz)
  1880. ratr_bitmap &= 0x0f8ff015;
  1881. else
  1882. ratr_bitmap &= 0x0f8ff005;
  1883. }
  1884. }
  1885. }
  1886. if ((curtxbw_40mhz && curshortgi_40mhz) ||
  1887. (!curtxbw_40mhz && curshortgi_20mhz)) {
  1888. if (macid == 0)
  1889. shortgi = true;
  1890. else if (macid == 1)
  1891. shortgi = false;
  1892. }
  1893. break;
  1894. default:
  1895. band |= (WIRELESS_11N | WIRELESS_11G | WIRELESS_11B);
  1896. ratr_index = RATR_INX_WIRELESS_NGB;
  1897. if (rtlphy->rf_type == RF_1T2R)
  1898. ratr_bitmap &= 0x000ff0ff;
  1899. else
  1900. ratr_bitmap &= 0x0f8ff0ff;
  1901. break;
  1902. }
  1903. sta_entry->ratr_index = ratr_index;
  1904. if (rtlpriv->rtlhal.version >= VERSION_8192S_BCUT)
  1905. ratr_bitmap &= 0x0FFFFFFF;
  1906. else if (rtlpriv->rtlhal.version == VERSION_8192S_ACUT)
  1907. ratr_bitmap &= 0x0FFFFFF0;
  1908. if (shortgi) {
  1909. ratr_bitmap |= 0x10000000;
  1910. /* Get MAX MCS available. */
  1911. ratr_value = (ratr_bitmap >> 12);
  1912. for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
  1913. if ((1 << shortgi_rate) & ratr_value)
  1914. break;
  1915. }
  1916. shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
  1917. (shortgi_rate << 4) | (shortgi_rate);
  1918. rtl_write_byte(rtlpriv, SG_RATE, shortgi_rate);
  1919. }
  1920. mask |= (bmulticast ? 1 : 0) << 9 | (macid & 0x1f) << 4 | (band & 0xf);
  1921. RT_TRACE(rtlpriv, COMP_RATR, DBG_TRACE, "mask = %x, bitmap = %x\n",
  1922. mask, ratr_bitmap);
  1923. rtl_write_dword(rtlpriv, 0x2c4, ratr_bitmap);
  1924. rtl_write_dword(rtlpriv, WFM5, (FW_RA_UPDATE_MASK | (mask << 8)));
  1925. if (macid != 0)
  1926. sta_entry->ratr_index = ratr_index;
  1927. }
  1928. void rtl92se_update_hal_rate_tbl(struct ieee80211_hw *hw,
  1929. struct ieee80211_sta *sta, u8 rssi_level)
  1930. {
  1931. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1932. if (rtlpriv->dm.useramask)
  1933. rtl92se_update_hal_rate_mask(hw, sta, rssi_level);
  1934. else
  1935. rtl92se_update_hal_rate_table(hw, sta);
  1936. }
  1937. void rtl92se_update_channel_access_setting(struct ieee80211_hw *hw)
  1938. {
  1939. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1940. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  1941. u16 sifs_timer;
  1942. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
  1943. &mac->slot_time);
  1944. sifs_timer = 0x0e0e;
  1945. rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
  1946. }
  1947. /* this ifunction is for RFKILL, it's different with windows,
  1948. * because UI will disable wireless when GPIO Radio Off.
  1949. * And here we not check or Disable/Enable ASPM like windows*/
  1950. bool rtl92se_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
  1951. {
  1952. struct rtl_priv *rtlpriv = rtl_priv(hw);
  1953. struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
  1954. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  1955. enum rf_pwrstate rfpwr_toset /*, cur_rfstate */;
  1956. unsigned long flag = 0;
  1957. bool actuallyset = false;
  1958. bool turnonbypowerdomain = false;
  1959. /* just 8191se can check gpio before firstup, 92c/92d have fixed it */
  1960. if ((rtlpci->up_first_time == 1) || (rtlpci->being_init_adapter))
  1961. return false;
  1962. if (ppsc->swrf_processing)
  1963. return false;
  1964. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1965. if (ppsc->rfchange_inprogress) {
  1966. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1967. return false;
  1968. } else {
  1969. ppsc->rfchange_inprogress = true;
  1970. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1971. }
  1972. /* cur_rfstate = ppsc->rfpwr_state;*/
  1973. /* because after _rtl92s_phy_set_rfhalt, all power
  1974. * closed, so we must open some power for GPIO check,
  1975. * or we will always check GPIO RFOFF here,
  1976. * And we should close power after GPIO check */
  1977. if (RT_IN_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC)) {
  1978. _rtl92se_power_domain_init(hw);
  1979. turnonbypowerdomain = true;
  1980. }
  1981. rfpwr_toset = _rtl92se_rf_onoff_detect(hw);
  1982. if ((ppsc->hwradiooff) && (rfpwr_toset == ERFON)) {
  1983. RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
  1984. "RFKILL-HW Radio ON, RF ON\n");
  1985. rfpwr_toset = ERFON;
  1986. ppsc->hwradiooff = false;
  1987. actuallyset = true;
  1988. } else if ((!ppsc->hwradiooff) && (rfpwr_toset == ERFOFF)) {
  1989. RT_TRACE(rtlpriv, COMP_RF,
  1990. DBG_DMESG, "RFKILL-HW Radio OFF, RF OFF\n");
  1991. rfpwr_toset = ERFOFF;
  1992. ppsc->hwradiooff = true;
  1993. actuallyset = true;
  1994. }
  1995. if (actuallyset) {
  1996. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  1997. ppsc->rfchange_inprogress = false;
  1998. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  1999. /* this not include ifconfig wlan0 down case */
  2000. /* } else if (rfpwr_toset == ERFOFF || cur_rfstate == ERFOFF) { */
  2001. } else {
  2002. /* because power_domain_init may be happen when
  2003. * _rtl92s_phy_set_rfhalt, this will open some powers
  2004. * and cause current increasing about 40 mA for ips,
  2005. * rfoff and ifconfig down, so we set
  2006. * _rtl92s_phy_set_rfhalt again here */
  2007. if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC &&
  2008. turnonbypowerdomain) {
  2009. _rtl92s_phy_set_rfhalt(hw);
  2010. RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
  2011. }
  2012. spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
  2013. ppsc->rfchange_inprogress = false;
  2014. spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
  2015. }
  2016. *valid = 1;
  2017. return !ppsc->hwradiooff;
  2018. }
  2019. /* Is_wepkey just used for WEP used as group & pairwise key
  2020. * if pairwise is AES ang group is WEP Is_wepkey == false.*/
  2021. void rtl92se_set_key(struct ieee80211_hw *hw, u32 key_index, u8 *p_macaddr,
  2022. bool is_group, u8 enc_algo, bool is_wepkey, bool clear_all)
  2023. {
  2024. struct rtl_priv *rtlpriv = rtl_priv(hw);
  2025. struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
  2026. struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
  2027. u8 *macaddr = p_macaddr;
  2028. u32 entry_id = 0;
  2029. bool is_pairwise = false;
  2030. static u8 cam_const_addr[4][6] = {
  2031. {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
  2032. {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
  2033. {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
  2034. {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
  2035. };
  2036. static u8 cam_const_broad[] = {
  2037. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  2038. };
  2039. if (clear_all) {
  2040. u8 idx = 0;
  2041. u8 cam_offset = 0;
  2042. u8 clear_number = 5;
  2043. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
  2044. for (idx = 0; idx < clear_number; idx++) {
  2045. rtl_cam_mark_invalid(hw, cam_offset + idx);
  2046. rtl_cam_empty_entry(hw, cam_offset + idx);
  2047. if (idx < 5) {
  2048. memset(rtlpriv->sec.key_buf[idx], 0,
  2049. MAX_KEY_LEN);
  2050. rtlpriv->sec.key_len[idx] = 0;
  2051. }
  2052. }
  2053. } else {
  2054. switch (enc_algo) {
  2055. case WEP40_ENCRYPTION:
  2056. enc_algo = CAM_WEP40;
  2057. break;
  2058. case WEP104_ENCRYPTION:
  2059. enc_algo = CAM_WEP104;
  2060. break;
  2061. case TKIP_ENCRYPTION:
  2062. enc_algo = CAM_TKIP;
  2063. break;
  2064. case AESCCMP_ENCRYPTION:
  2065. enc_algo = CAM_AES;
  2066. break;
  2067. default:
  2068. RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
  2069. "switch case not processed\n");
  2070. enc_algo = CAM_TKIP;
  2071. break;
  2072. }
  2073. if (is_wepkey || rtlpriv->sec.use_defaultkey) {
  2074. macaddr = cam_const_addr[key_index];
  2075. entry_id = key_index;
  2076. } else {
  2077. if (is_group) {
  2078. macaddr = cam_const_broad;
  2079. entry_id = key_index;
  2080. } else {
  2081. if (mac->opmode == NL80211_IFTYPE_AP) {
  2082. entry_id = rtl_cam_get_free_entry(hw,
  2083. p_macaddr);
  2084. if (entry_id >= TOTAL_CAM_ENTRY) {
  2085. RT_TRACE(rtlpriv,
  2086. COMP_SEC, DBG_EMERG,
  2087. "Can not find free hw security cam entry\n");
  2088. return;
  2089. }
  2090. } else {
  2091. entry_id = CAM_PAIRWISE_KEY_POSITION;
  2092. }
  2093. key_index = PAIRWISE_KEYIDX;
  2094. is_pairwise = true;
  2095. }
  2096. }
  2097. if (rtlpriv->sec.key_len[key_index] == 0) {
  2098. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2099. "delete one entry, entry_id is %d\n",
  2100. entry_id);
  2101. if (mac->opmode == NL80211_IFTYPE_AP)
  2102. rtl_cam_del_entry(hw, p_macaddr);
  2103. rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
  2104. } else {
  2105. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2106. "add one entry\n");
  2107. if (is_pairwise) {
  2108. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2109. "set Pairwise key\n");
  2110. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2111. entry_id, enc_algo,
  2112. CAM_CONFIG_NO_USEDK,
  2113. rtlpriv->sec.key_buf[key_index]);
  2114. } else {
  2115. RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
  2116. "set group key\n");
  2117. if (mac->opmode == NL80211_IFTYPE_ADHOC) {
  2118. rtl_cam_add_one_entry(hw,
  2119. rtlefuse->dev_addr,
  2120. PAIRWISE_KEYIDX,
  2121. CAM_PAIRWISE_KEY_POSITION,
  2122. enc_algo, CAM_CONFIG_NO_USEDK,
  2123. rtlpriv->sec.key_buf[entry_id]);
  2124. }
  2125. rtl_cam_add_one_entry(hw, macaddr, key_index,
  2126. entry_id, enc_algo,
  2127. CAM_CONFIG_NO_USEDK,
  2128. rtlpriv->sec.key_buf[entry_id]);
  2129. }
  2130. }
  2131. }
  2132. }
  2133. void rtl92se_suspend(struct ieee80211_hw *hw)
  2134. {
  2135. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  2136. rtlpci->up_first_time = true;
  2137. }
  2138. void rtl92se_resume(struct ieee80211_hw *hw)
  2139. {
  2140. struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
  2141. u32 val;
  2142. pci_read_config_dword(rtlpci->pdev, 0x40, &val);
  2143. if ((val & 0x0000ff00) != 0)
  2144. pci_write_config_dword(rtlpci->pdev, 0x40,
  2145. val & 0xffff00ff);
  2146. }