1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation. All rights reserved.
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.
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
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
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
44 #include "../rtl8192ce/hw.h"
49 static void _rtl92cu_phy_param_tab_init(struct ieee80211_hw
*hw
)
51 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
52 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
53 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtlpriv
);
55 rtlphy
->hwparam_tables
[MAC_REG
].length
= RTL8192CUMAC_2T_ARRAYLENGTH
;
56 rtlphy
->hwparam_tables
[MAC_REG
].pdata
= RTL8192CUMAC_2T_ARRAY
;
57 if (IS_HIGHT_PA(rtlefuse
->board_type
)) {
58 rtlphy
->hwparam_tables
[PHY_REG_PG
].length
=
59 RTL8192CUPHY_REG_Array_PG_HPLength
;
60 rtlphy
->hwparam_tables
[PHY_REG_PG
].pdata
=
61 RTL8192CUPHY_REG_Array_PG_HP
;
63 rtlphy
->hwparam_tables
[PHY_REG_PG
].length
=
64 RTL8192CUPHY_REG_ARRAY_PGLENGTH
;
65 rtlphy
->hwparam_tables
[PHY_REG_PG
].pdata
=
66 RTL8192CUPHY_REG_ARRAY_PG
;
69 rtlphy
->hwparam_tables
[PHY_REG_2T
].length
=
70 RTL8192CUPHY_REG_2TARRAY_LENGTH
;
71 rtlphy
->hwparam_tables
[PHY_REG_2T
].pdata
=
72 RTL8192CUPHY_REG_2TARRAY
;
73 rtlphy
->hwparam_tables
[RADIOA_2T
].length
=
74 RTL8192CURADIOA_2TARRAYLENGTH
;
75 rtlphy
->hwparam_tables
[RADIOA_2T
].pdata
=
76 RTL8192CURADIOA_2TARRAY
;
77 rtlphy
->hwparam_tables
[RADIOB_2T
].length
=
78 RTL8192CURADIOB_2TARRAYLENGTH
;
79 rtlphy
->hwparam_tables
[RADIOB_2T
].pdata
=
80 RTL8192CU_RADIOB_2TARRAY
;
81 rtlphy
->hwparam_tables
[AGCTAB_2T
].length
=
82 RTL8192CUAGCTAB_2TARRAYLENGTH
;
83 rtlphy
->hwparam_tables
[AGCTAB_2T
].pdata
=
84 RTL8192CUAGCTAB_2TARRAY
;
86 if (IS_HIGHT_PA(rtlefuse
->board_type
)) {
87 rtlphy
->hwparam_tables
[PHY_REG_1T
].length
=
88 RTL8192CUPHY_REG_1T_HPArrayLength
;
89 rtlphy
->hwparam_tables
[PHY_REG_1T
].pdata
=
90 RTL8192CUPHY_REG_1T_HPArray
;
91 rtlphy
->hwparam_tables
[RADIOA_1T
].length
=
92 RTL8192CURadioA_1T_HPArrayLength
;
93 rtlphy
->hwparam_tables
[RADIOA_1T
].pdata
=
94 RTL8192CURadioA_1T_HPArray
;
95 rtlphy
->hwparam_tables
[RADIOB_1T
].length
=
96 RTL8192CURADIOB_1TARRAYLENGTH
;
97 rtlphy
->hwparam_tables
[RADIOB_1T
].pdata
=
98 RTL8192CU_RADIOB_1TARRAY
;
99 rtlphy
->hwparam_tables
[AGCTAB_1T
].length
=
100 RTL8192CUAGCTAB_1T_HPArrayLength
;
101 rtlphy
->hwparam_tables
[AGCTAB_1T
].pdata
=
102 Rtl8192CUAGCTAB_1T_HPArray
;
104 rtlphy
->hwparam_tables
[PHY_REG_1T
].length
=
105 RTL8192CUPHY_REG_1TARRAY_LENGTH
;
106 rtlphy
->hwparam_tables
[PHY_REG_1T
].pdata
=
107 RTL8192CUPHY_REG_1TARRAY
;
108 rtlphy
->hwparam_tables
[RADIOA_1T
].length
=
109 RTL8192CURADIOA_1TARRAYLENGTH
;
110 rtlphy
->hwparam_tables
[RADIOA_1T
].pdata
=
111 RTL8192CU_RADIOA_1TARRAY
;
112 rtlphy
->hwparam_tables
[RADIOB_1T
].length
=
113 RTL8192CURADIOB_1TARRAYLENGTH
;
114 rtlphy
->hwparam_tables
[RADIOB_1T
].pdata
=
115 RTL8192CU_RADIOB_1TARRAY
;
116 rtlphy
->hwparam_tables
[AGCTAB_1T
].length
=
117 RTL8192CUAGCTAB_1TARRAYLENGTH
;
118 rtlphy
->hwparam_tables
[AGCTAB_1T
].pdata
=
119 RTL8192CUAGCTAB_1TARRAY
;
123 static void _rtl92cu_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
127 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
128 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
129 u8 rf_path
, index
, tempval
;
132 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
133 for (i
= 0; i
< 3; i
++) {
134 if (!autoload_fail
) {
136 eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
137 hwinfo
[EEPROM_TXPOWERCCK
+ rf_path
* 3 + i
];
139 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
140 hwinfo
[EEPROM_TXPOWERHT40_1S
+ rf_path
* 3 +
144 eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
145 EEPROM_DEFAULT_TXPOWERLEVEL
;
147 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
148 EEPROM_DEFAULT_TXPOWERLEVEL
;
152 for (i
= 0; i
< 3; i
++) {
154 tempval
= hwinfo
[EEPROM_TXPOWERHT40_2SDIFF
+ i
];
156 tempval
= EEPROM_DEFAULT_HT40_2SDIFF
;
157 rtlefuse
->eeprom_chnlarea_txpwr_ht40_2sdiif
[RF90_PATH_A
][i
] =
159 rtlefuse
->eeprom_chnlarea_txpwr_ht40_2sdiif
[RF90_PATH_B
][i
] =
160 ((tempval
& 0xf0) >> 4);
162 for (rf_path
= 0; rf_path
< 2; rf_path
++)
163 for (i
= 0; i
< 3; i
++)
164 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
165 ("RF(%d) EEPROM CCK Area(%d) = 0x%x\n", rf_path
,
167 eeprom_chnlarea_txpwr_cck
[rf_path
][i
]));
168 for (rf_path
= 0; rf_path
< 2; rf_path
++)
169 for (i
= 0; i
< 3; i
++)
170 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
171 ("RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
174 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
]));
175 for (rf_path
= 0; rf_path
< 2; rf_path
++)
176 for (i
= 0; i
< 3; i
++)
177 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
178 ("RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
181 eeprom_chnlarea_txpwr_ht40_2sdiif
[rf_path
]
183 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
184 for (i
= 0; i
< 14; i
++) {
185 index
= _rtl92c_get_chnl_group((u8
) i
);
186 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
187 rtlefuse
->eeprom_chnlarea_txpwr_cck
[rf_path
][index
];
188 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
190 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][index
];
192 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][index
] -
194 eeprom_chnlarea_txpwr_ht40_2sdiif
[rf_path
][index
])
196 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] =
198 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
]
200 eeprom_chnlarea_txpwr_ht40_2sdiif
[rf_path
]
203 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] = 0;
206 for (i
= 0; i
< 14; i
++) {
207 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
208 ("RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = "
209 "[0x%x / 0x%x / 0x%x]\n", rf_path
, i
,
210 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
211 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
],
212 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
]));
215 for (i
= 0; i
< 3; i
++) {
216 if (!autoload_fail
) {
217 rtlefuse
->eeprom_pwrlimit_ht40
[i
] =
218 hwinfo
[EEPROM_TXPWR_GROUP
+ i
];
219 rtlefuse
->eeprom_pwrlimit_ht20
[i
] =
220 hwinfo
[EEPROM_TXPWR_GROUP
+ 3 + i
];
222 rtlefuse
->eeprom_pwrlimit_ht40
[i
] = 0;
223 rtlefuse
->eeprom_pwrlimit_ht20
[i
] = 0;
226 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
227 for (i
= 0; i
< 14; i
++) {
228 index
= _rtl92c_get_chnl_group((u8
) i
);
229 if (rf_path
== RF90_PATH_A
) {
230 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
231 (rtlefuse
->eeprom_pwrlimit_ht20
[index
]
233 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
234 (rtlefuse
->eeprom_pwrlimit_ht40
[index
]
236 } else if (rf_path
== RF90_PATH_B
) {
237 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
238 ((rtlefuse
->eeprom_pwrlimit_ht20
[index
]
240 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
241 ((rtlefuse
->eeprom_pwrlimit_ht40
[index
]
244 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
245 ("RF-%d pwrgroup_ht20[%d] = 0x%x\n",
247 rtlefuse
->pwrgroup_ht20
[rf_path
][i
]));
248 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
249 ("RF-%d pwrgroup_ht40[%d] = 0x%x\n",
251 rtlefuse
->pwrgroup_ht40
[rf_path
][i
]));
254 for (i
= 0; i
< 14; i
++) {
255 index
= _rtl92c_get_chnl_group((u8
) i
);
257 tempval
= hwinfo
[EEPROM_TXPOWERHT20DIFF
+ index
];
259 tempval
= EEPROM_DEFAULT_HT20_DIFF
;
260 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
261 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] =
262 ((tempval
>> 4) & 0xF);
263 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] & BIT(3))
264 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] |= 0xF0;
265 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] & BIT(3))
266 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] |= 0xF0;
267 index
= _rtl92c_get_chnl_group((u8
) i
);
269 tempval
= hwinfo
[EEPROM_TXPOWER_OFDMDIFF
+ index
];
271 tempval
= EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF
;
272 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
273 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
] =
274 ((tempval
>> 4) & 0xF);
276 rtlefuse
->legacy_ht_txpowerdiff
=
277 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][7];
278 for (i
= 0; i
< 14; i
++)
279 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
280 ("RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", i
,
281 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
]));
282 for (i
= 0; i
< 14; i
++)
283 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
284 ("RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", i
,
285 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
]));
286 for (i
= 0; i
< 14; i
++)
287 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
288 ("RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", i
,
289 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
]));
290 for (i
= 0; i
< 14; i
++)
291 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
292 ("RF-B Legacy to HT40 Diff[%d] = 0x%x\n", i
,
293 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
]));
295 rtlefuse
->eeprom_regulatory
= (hwinfo
[RF_OPTION1
] & 0x7);
297 rtlefuse
->eeprom_regulatory
= 0;
298 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
299 ("eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
));
300 if (!autoload_fail
) {
301 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = hwinfo
[EEPROM_TSSI_A
];
302 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = hwinfo
[EEPROM_TSSI_B
];
304 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = EEPROM_DEFAULT_TSSI
;
305 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = EEPROM_DEFAULT_TSSI
;
307 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
308 ("TSSI_A = 0x%x, TSSI_B = 0x%x\n",
309 rtlefuse
->eeprom_tssi
[RF90_PATH_A
],
310 rtlefuse
->eeprom_tssi
[RF90_PATH_B
]));
312 tempval
= hwinfo
[EEPROM_THERMAL_METER
];
314 tempval
= EEPROM_DEFAULT_THERMALMETER
;
315 rtlefuse
->eeprom_thermalmeter
= (tempval
& 0x1f);
316 if (rtlefuse
->eeprom_thermalmeter
< 0x06 ||
317 rtlefuse
->eeprom_thermalmeter
> 0x1c)
318 rtlefuse
->eeprom_thermalmeter
= 0x12;
319 if (rtlefuse
->eeprom_thermalmeter
== 0x1f || autoload_fail
)
320 rtlefuse
->apk_thermalmeterignore
= true;
321 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
322 RTPRINT(rtlpriv
, FINIT
, INIT_TxPower
,
323 ("thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
));
326 static void _rtl92cu_read_board_type(struct ieee80211_hw
*hw
, u8
*contents
)
328 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
329 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
332 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
333 boardType
= ((contents
[EEPROM_RF_OPT1
]) &
334 BOARD_TYPE_NORMAL_MASK
) >> 5; /*bit[7:5]*/
336 boardType
= contents
[EEPROM_RF_OPT4
];
337 boardType
&= BOARD_TYPE_TEST_MASK
;
339 rtlefuse
->board_type
= boardType
;
340 if (IS_HIGHT_PA(rtlefuse
->board_type
))
341 rtlefuse
->external_pa
= 1;
342 pr_info("Board Type %x\n", rtlefuse
->board_type
);
344 #ifdef CONFIG_ANTENNA_DIVERSITY
345 /* Antenna Diversity setting. */
346 if (registry_par
->antdiv_cfg
== 2) /* 2: From Efuse */
347 rtl_efuse
->antenna_cfg
= (contents
[EEPROM_RF_OPT1
]&0x18)>>3;
349 rtl_efuse
->antenna_cfg
= registry_par
->antdiv_cfg
; /* 0:OFF, */
351 pr_info("Antenna Config %x\n", rtl_efuse
->antenna_cfg
);
355 #ifdef CONFIG_BT_COEXIST
356 static void _update_bt_param(_adapter
*padapter
)
358 struct btcoexist_priv
*pbtpriv
= &(padapter
->halpriv
.bt_coexist
);
359 struct registry_priv
*registry_par
= &padapter
->registrypriv
;
360 if (2 != registry_par
->bt_iso
) {
361 /* 0:Low, 1:High, 2:From Efuse */
362 pbtpriv
->BT_Ant_isolation
= registry_par
->bt_iso
;
364 if (registry_par
->bt_sco
== 1) {
365 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter, 4.Busy,
367 pbtpriv
->BT_Service
= BT_OtherAction
;
368 } else if (registry_par
->bt_sco
== 2) {
369 pbtpriv
->BT_Service
= BT_SCO
;
370 } else if (registry_par
->bt_sco
== 4) {
371 pbtpriv
->BT_Service
= BT_Busy
;
372 } else if (registry_par
->bt_sco
== 5) {
373 pbtpriv
->BT_Service
= BT_OtherBusy
;
375 pbtpriv
->BT_Service
= BT_Idle
;
377 pbtpriv
->BT_Ampdu
= registry_par
->bt_ampdu
;
378 pbtpriv
->bCOBT
= _TRUE
;
379 pbtpriv
->BtEdcaUL
= 0;
380 pbtpriv
->BtEdcaDL
= 0;
381 pbtpriv
->BtRssiState
= 0xff;
382 pbtpriv
->bInitSet
= _FALSE
;
383 pbtpriv
->bBTBusyTraffic
= _FALSE
;
384 pbtpriv
->bBTTrafficModeSet
= _FALSE
;
385 pbtpriv
->bBTNonTrafficModeSet
= _FALSE
;
386 pbtpriv
->CurrentState
= 0;
387 pbtpriv
->PreviousState
= 0;
388 pr_info("BT Coexistance = %s\n",
389 (pbtpriv
->BT_Coexist
== _TRUE
) ? "enable" : "disable");
390 if (pbtpriv
->BT_Coexist
) {
391 if (pbtpriv
->BT_Ant_Num
== Ant_x2
)
392 pr_info("BlueTooth BT_Ant_Num = Antx2\n");
393 else if (pbtpriv
->BT_Ant_Num
== Ant_x1
)
394 pr_info("BlueTooth BT_Ant_Num = Antx1\n");
395 switch (pbtpriv
->BT_CoexistType
) {
397 pr_info("BlueTooth BT_CoexistType = BT_2Wire\n");
400 pr_info("BlueTooth BT_CoexistType = BT_ISSC_3Wire\n");
403 pr_info("BlueTooth BT_CoexistType = BT_Accel\n");
406 pr_info("BlueTooth BT_CoexistType = BT_CSR_BC4\n");
409 pr_info("BlueTooth BT_CoexistType = BT_CSR_BC8\n");
412 pr_info("BlueTooth BT_CoexistType = BT_RTL8756\n");
415 pr_info("BlueTooth BT_CoexistType = Unknown\n");
418 pr_info("BlueTooth BT_Ant_isolation = %d\n",
419 pbtpriv
->BT_Ant_isolation
);
420 switch (pbtpriv
->BT_Service
) {
422 pr_info("BlueTooth BT_Service = BT_OtherAction\n");
425 pr_info("BlueTooth BT_Service = BT_SCO\n");
428 pr_info("BlueTooth BT_Service = BT_Busy\n");
431 pr_info("BlueTooth BT_Service = BT_OtherBusy\n");
434 pr_info("BlueTooth BT_Service = BT_Idle\n");
437 pr_info("BT_RadioSharedType = 0x%x\n",
438 pbtpriv
->BT_RadioSharedType
);
442 #define GET_BT_COEXIST(priv) (&priv->bt_coexist)
444 static void _rtl92cu_read_bluetooth_coexistInfo(struct ieee80211_hw
*hw
,
446 bool bautoloadfailed
);
448 HAL_DATA_TYPE
*pHalData
= GET_HAL_DATA(Adapter
);
449 bool isNormal
= IS_NORMAL_CHIP(pHalData
->VersionID
);
450 struct btcoexist_priv
*pbtpriv
= &pHalData
->bt_coexist
;
453 _rtw_memset(pbtpriv
, 0, sizeof(struct btcoexist_priv
));
455 pbtpriv
->BT_Coexist
= _FALSE
;
456 pbtpriv
->BT_CoexistType
= BT_2Wire
;
457 pbtpriv
->BT_Ant_Num
= Ant_x2
;
458 pbtpriv
->BT_Ant_isolation
= 0;
459 pbtpriv
->BT_RadioSharedType
= BT_Radio_Shared
;
463 if (pHalData
->BoardType
== BOARD_USB_COMBO
)
464 pbtpriv
->BT_Coexist
= _TRUE
;
466 pbtpriv
->BT_Coexist
= ((PROMContent
[EEPROM_RF_OPT3
] &
467 0x20) >> 5); /* bit[5] */
468 rf_opt4
= PROMContent
[EEPROM_RF_OPT4
];
469 pbtpriv
->BT_CoexistType
= ((rf_opt4
&0xe)>>1); /* bit [3:1] */
470 pbtpriv
->BT_Ant_Num
= (rf_opt4
&0x1); /* bit [0] */
471 pbtpriv
->BT_Ant_isolation
= ((rf_opt4
&0x10)>>4); /* bit [4] */
472 pbtpriv
->BT_RadioSharedType
= ((rf_opt4
&0x20)>>5); /* bit [5] */
474 pbtpriv
->BT_Coexist
= (PROMContent
[EEPROM_RF_OPT4
] >> 4) ?
477 _update_bt_param(Adapter
);
481 static void _rtl92cu_read_adapter_info(struct ieee80211_hw
*hw
)
483 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
484 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
485 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
487 u8 hwinfo
[HWSET_MAX_SIZE
] = {0};
490 if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
491 rtl_efuse_shadow_map_update(hw
);
492 memcpy((void *)hwinfo
,
493 (void *)&rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
495 } else if (rtlefuse
->epromtype
== EEPROM_93C46
) {
496 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
497 ("RTL819X Not boot from eeprom, check it !!"));
499 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("MAP\n"),
500 hwinfo
, HWSET_MAX_SIZE
);
501 eeprom_id
= *((u16
*)&hwinfo
[0]);
502 if (eeprom_id
!= RTL8190_EEPROM_ID
) {
503 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
504 ("EEPROM ID(%#x) is invalid!!\n", eeprom_id
));
505 rtlefuse
->autoload_failflag
= true;
507 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("Autoload OK\n"));
508 rtlefuse
->autoload_failflag
= false;
510 if (rtlefuse
->autoload_failflag
)
512 for (i
= 0; i
< 6; i
+= 2) {
513 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
514 *((u16
*) (&rtlefuse
->dev_addr
[i
])) = usvalue
;
516 pr_info("MAC address: %pM\n", rtlefuse
->dev_addr
);
517 _rtl92cu_read_txpower_info_from_hwpg(hw
,
518 rtlefuse
->autoload_failflag
, hwinfo
);
519 rtlefuse
->eeprom_vid
= *(u16
*)&hwinfo
[EEPROM_VID
];
520 rtlefuse
->eeprom_did
= *(u16
*)&hwinfo
[EEPROM_DID
];
521 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
522 (" VID = 0x%02x PID = 0x%02x\n",
523 rtlefuse
->eeprom_vid
, rtlefuse
->eeprom_did
));
524 rtlefuse
->eeprom_channelplan
= *(u8
*)&hwinfo
[EEPROM_CHANNELPLAN
];
525 rtlefuse
->eeprom_version
= *(u16
*)&hwinfo
[EEPROM_VERSION
];
526 rtlefuse
->txpwr_fromeprom
= true;
527 rtlefuse
->eeprom_oemid
= *(u8
*)&hwinfo
[EEPROM_CUSTOMER_ID
];
528 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
529 ("EEPROM Customer ID: 0x%2x\n", rtlefuse
->eeprom_oemid
));
530 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
531 switch (rtlefuse
->eeprom_oemid
) {
532 case EEPROM_CID_DEFAULT
:
533 if (rtlefuse
->eeprom_did
== 0x8176) {
534 if ((rtlefuse
->eeprom_svid
== 0x103C &&
535 rtlefuse
->eeprom_smid
== 0x1629))
536 rtlhal
->oem_id
= RT_CID_819x_HP
;
538 rtlhal
->oem_id
= RT_CID_DEFAULT
;
540 rtlhal
->oem_id
= RT_CID_DEFAULT
;
543 case EEPROM_CID_TOSHIBA
:
544 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
547 rtlhal
->oem_id
= RT_CID_819x_QMI
;
549 case EEPROM_CID_WHQL
:
551 rtlhal
->oem_id
= RT_CID_DEFAULT
;
555 _rtl92cu_read_board_type(hw
, hwinfo
);
556 #ifdef CONFIG_BT_COEXIST
557 _rtl92cu_read_bluetooth_coexistInfo(hw
, hwinfo
,
558 rtlefuse
->autoload_failflag
);
562 static void _rtl92cu_hal_customized_behavior(struct ieee80211_hw
*hw
)
564 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
565 struct rtl_usb_priv
*usb_priv
= rtl_usbpriv(hw
);
566 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
568 switch (rtlhal
->oem_id
) {
570 usb_priv
->ledctl
.led_opendrain
= true;
572 case RT_CID_819x_Lenovo
:
576 case RT_CID_819x_Acer
:
581 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
582 ("RT Customized ID: 0x%02X\n", rtlhal
->oem_id
));
585 void rtl92cu_read_eeprom_info(struct ieee80211_hw
*hw
)
588 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
589 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
590 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
593 if (!IS_NORMAL_CHIP(rtlhal
->version
))
595 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
596 rtlefuse
->epromtype
= (tmp_u1b
& BOOT_FROM_EEPROM
) ?
597 EEPROM_93C46
: EEPROM_BOOT_EFUSE
;
598 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, ("Boot from %s\n",
599 (tmp_u1b
& BOOT_FROM_EEPROM
) ? "EERROM" : "EFUSE"));
600 rtlefuse
->autoload_failflag
= (tmp_u1b
& EEPROM_EN
) ? false : true;
601 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, ("Autoload %s\n",
602 (tmp_u1b
& EEPROM_EN
) ? "OK!!" : "ERR!!"));
603 _rtl92cu_read_adapter_info(hw
);
604 _rtl92cu_hal_customized_behavior(hw
);
608 static int _rtl92cu_init_power_on(struct ieee80211_hw
*hw
)
610 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
614 /* polling autoload done. */
615 u32 pollingCount
= 0;
618 if (rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) & PFM_ALDN
) {
619 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
620 ("Autoload Done!\n"));
623 if (pollingCount
++ > 100) {
624 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
625 ("Failed to polling REG_APS_FSMCO[PFM_ALDN]"
630 /* 0. RSV_CTRL 0x1C[7:0] = 0 unlock ISO/CLK/Power control register */
631 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0);
632 /* Power on when re-enter from IPS/Radio off/card disable */
633 /* enable SPS into PWM mode */
634 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
636 value8
= rtl_read_byte(rtlpriv
, REG_LDOV12D_CTRL
);
637 if (0 == (value8
& LDV12_EN
)) {
639 rtl_write_byte(rtlpriv
, REG_LDOV12D_CTRL
, value8
);
640 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
641 (" power-on :REG_LDOV12D_CTRL Reg0x21:0x%02x.\n",
644 value8
= rtl_read_byte(rtlpriv
, REG_SYS_ISO_CTRL
);
645 value8
&= ~ISO_MD2PP
;
646 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, value8
);
648 /* auto enable WLAN */
650 value16
= rtl_read_word(rtlpriv
, REG_APS_FSMCO
);
651 value16
|= APFM_ONMAC
;
652 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, value16
);
654 if (!(rtl_read_word(rtlpriv
, REG_APS_FSMCO
) & APFM_ONMAC
)) {
655 pr_info("MAC auto ON okay!\n");
658 if (pollingCount
++ > 100) {
659 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
660 ("Failed to polling REG_APS_FSMCO[APFM_ONMAC]"
665 /* Enable Radio ,GPIO ,and LED function */
666 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, 0x0812);
667 /* release RF digital isolation */
668 value16
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
669 value16
&= ~ISO_DIOR
;
670 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, value16
);
671 /* Reconsider when to do this operation after asking HWSD. */
673 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, (rtl_read_byte(rtlpriv
,
674 REG_APSD_CTRL
) & ~BIT(6)));
677 } while ((pollingCount
< 200) &&
678 (rtl_read_byte(rtlpriv
, REG_APSD_CTRL
) & BIT(7)));
679 /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */
680 value16
= rtl_read_word(rtlpriv
, REG_CR
);
681 value16
|= (HCI_TXDMA_EN
| HCI_RXDMA_EN
| TXDMA_EN
| RXDMA_EN
|
682 PROTOCOL_EN
| SCHEDULE_EN
| MACTXEN
| MACRXEN
| ENSEC
);
683 rtl_write_word(rtlpriv
, REG_CR
, value16
);
687 static void _rtl92cu_init_queue_reserved_page(struct ieee80211_hw
*hw
,
692 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
693 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
694 bool isChipN
= IS_NORMAL_CHIP(rtlhal
->version
);
695 u32 outEPNum
= (u32
)out_ep_num
;
702 u32 txQPageNum
, txQPageUnit
, txQRemainPage
;
705 numPubQ
= (isChipN
) ? CHIP_B_PAGE_NUM_PUBQ
:
706 CHIP_A_PAGE_NUM_PUBQ
;
707 txQPageNum
= TX_TOTAL_PAGE_NUMBER
- numPubQ
;
709 txQPageUnit
= txQPageNum
/outEPNum
;
710 txQRemainPage
= txQPageNum
% outEPNum
;
711 if (queue_sel
& TX_SELE_HQ
)
713 if (queue_sel
& TX_SELE_LQ
)
715 /* HIGH priority queue always present in the configuration of
716 * 2 out-ep. Remainder pages have assigned to High queue */
717 if ((outEPNum
> 1) && (txQRemainPage
))
718 numHQ
+= txQRemainPage
;
719 /* NOTE: This step done before writting REG_RQPN. */
721 if (queue_sel
& TX_SELE_NQ
)
723 value8
= (u8
)_NPQ(numNQ
);
724 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, value8
);
727 /* for WMM ,number of out-ep must more than or equal to 2! */
728 numPubQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_PUBQ
:
729 WMM_CHIP_A_PAGE_NUM_PUBQ
;
730 if (queue_sel
& TX_SELE_HQ
) {
731 numHQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_HPQ
:
732 WMM_CHIP_A_PAGE_NUM_HPQ
;
734 if (queue_sel
& TX_SELE_LQ
) {
735 numLQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_LPQ
:
736 WMM_CHIP_A_PAGE_NUM_LPQ
;
738 /* NOTE: This step done before writting REG_RQPN. */
740 if (queue_sel
& TX_SELE_NQ
)
741 numNQ
= WMM_CHIP_B_PAGE_NUM_NPQ
;
742 value8
= (u8
)_NPQ(numNQ
);
743 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, value8
);
747 value32
= _HPQ(numHQ
) | _LPQ(numLQ
) | _PUBQ(numPubQ
) | LD_RQPN
;
748 rtl_write_dword(rtlpriv
, REG_RQPN
, value32
);
751 static void _rtl92c_init_trx_buffer(struct ieee80211_hw
*hw
, bool wmm_enable
)
753 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
754 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
759 txpktbuf_bndy
= TX_PAGE_BOUNDARY
;
761 txpktbuf_bndy
= (IS_NORMAL_CHIP(rtlhal
->version
))
762 ? WMM_CHIP_B_TX_PAGE_BOUNDARY
763 : WMM_CHIP_A_TX_PAGE_BOUNDARY
;
764 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
765 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
766 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_WMAC_LBK_BF_HD
, txpktbuf_bndy
);
767 rtl_write_byte(rtlpriv
, REG_TRXFF_BNDY
, txpktbuf_bndy
);
768 rtl_write_byte(rtlpriv
, REG_TDECTRL
+1, txpktbuf_bndy
);
769 rtl_write_word(rtlpriv
, (REG_TRXFF_BNDY
+ 2), 0x27FF);
770 value8
= _PSRX(RX_PAGE_SIZE_REG_VALUE
) | _PSTX(PBP_128
);
771 rtl_write_byte(rtlpriv
, REG_PBP
, value8
);
774 static void _rtl92c_init_chipN_reg_priority(struct ieee80211_hw
*hw
, u16 beQ
,
775 u16 bkQ
, u16 viQ
, u16 voQ
,
778 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
779 u16 value16
= (rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
) & 0x7);
781 value16
|= _TXDMA_BEQ_MAP(beQ
) | _TXDMA_BKQ_MAP(bkQ
) |
782 _TXDMA_VIQ_MAP(viQ
) | _TXDMA_VOQ_MAP(voQ
) |
783 _TXDMA_MGQ_MAP(mgtQ
) | _TXDMA_HIQ_MAP(hiQ
);
784 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, value16
);
787 static void _rtl92cu_init_chipN_one_out_ep_priority(struct ieee80211_hw
*hw
,
791 u16
uninitialized_var(value
);
801 value
= QUEUE_NORMAL
;
804 WARN_ON(1); /* Shall not reach here! */
807 _rtl92c_init_chipN_reg_priority(hw
, value
, value
, value
, value
,
809 pr_info("Tx queue select: 0x%02x\n", queue_sel
);
812 static void _rtl92cu_init_chipN_two_out_ep_priority(struct ieee80211_hw
*hw
,
816 u16 beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
;
817 u16
uninitialized_var(valueHi
);
818 u16
uninitialized_var(valueLow
);
821 case (TX_SELE_HQ
| TX_SELE_LQ
):
822 valueHi
= QUEUE_HIGH
;
823 valueLow
= QUEUE_LOW
;
825 case (TX_SELE_NQ
| TX_SELE_LQ
):
826 valueHi
= QUEUE_NORMAL
;
827 valueLow
= QUEUE_LOW
;
829 case (TX_SELE_HQ
| TX_SELE_NQ
):
830 valueHi
= QUEUE_HIGH
;
831 valueLow
= QUEUE_NORMAL
;
844 } else {/* for WMM ,CONFIG_OUT_EP_WIFI_MODE */
852 _rtl92c_init_chipN_reg_priority(hw
, beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
);
853 pr_info("Tx queue select: 0x%02x\n", queue_sel
);
856 static void _rtl92cu_init_chipN_three_out_ep_priority(struct ieee80211_hw
*hw
,
860 u16 beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
;
861 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
863 if (!wmm_enable
) { /* typical setting */
870 } else { /* for WMM */
878 _rtl92c_init_chipN_reg_priority(hw
, beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
);
879 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
880 ("Tx queue select :0x%02x..\n", queue_sel
));
883 static void _rtl92cu_init_chipN_queue_priority(struct ieee80211_hw
*hw
,
888 switch (out_ep_num
) {
890 _rtl92cu_init_chipN_one_out_ep_priority(hw
, wmm_enable
,
894 _rtl92cu_init_chipN_two_out_ep_priority(hw
, wmm_enable
,
898 _rtl92cu_init_chipN_three_out_ep_priority(hw
, wmm_enable
,
902 WARN_ON(1); /* Shall not reach here! */
907 static void _rtl92cu_init_chipT_queue_priority(struct ieee80211_hw
*hw
,
913 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
915 switch (out_ep_num
) {
916 case 2: /* (TX_SELE_HQ|TX_SELE_LQ) */
917 if (!wmm_enable
) /* typical setting */
918 hq_sele
= HQSEL_VOQ
| HQSEL_VIQ
| HQSEL_MGTQ
|
921 hq_sele
= HQSEL_VOQ
| HQSEL_BEQ
| HQSEL_MGTQ
|
925 if (TX_SELE_LQ
== queue_sel
) {
926 /* map all endpoint to Low queue */
928 } else if (TX_SELE_HQ
== queue_sel
) {
929 /* map all endpoint to High queue */
930 hq_sele
= HQSEL_VOQ
| HQSEL_VIQ
| HQSEL_BEQ
|
931 HQSEL_BKQ
| HQSEL_MGTQ
| HQSEL_HIQ
;
935 WARN_ON(1); /* Shall not reach here! */
938 rtl_write_byte(rtlpriv
, (REG_TRXDMA_CTRL
+1), hq_sele
);
939 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
940 ("Tx queue select :0x%02x..\n", hq_sele
));
943 static void _rtl92cu_init_queue_priority(struct ieee80211_hw
*hw
,
948 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
949 if (IS_NORMAL_CHIP(rtlhal
->version
))
950 _rtl92cu_init_chipN_queue_priority(hw
, wmm_enable
, out_ep_num
,
953 _rtl92cu_init_chipT_queue_priority(hw
, wmm_enable
, out_ep_num
,
957 static void _rtl92cu_init_usb_aggregation(struct ieee80211_hw
*hw
)
961 static void _rtl92cu_init_wmac_setting(struct ieee80211_hw
*hw
)
965 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
966 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
968 mac
->rx_conf
= (RCR_APM
| RCR_AM
| RCR_ADF
| RCR_AB
| RCR_APPFCS
|
969 RCR_APP_ICV
| RCR_AMF
| RCR_HTC_LOC_CTRL
|
970 RCR_APP_MIC
| RCR_APP_PHYSTS
| RCR_ACRC32
);
971 rtl_write_dword(rtlpriv
, REG_RCR
, mac
->rx_conf
);
972 /* Accept all multicast address */
973 rtl_write_dword(rtlpriv
, REG_MAR
, 0xFFFFFFFF);
974 rtl_write_dword(rtlpriv
, REG_MAR
+ 4, 0xFFFFFFFF);
975 /* Accept all management frames */
977 rtl92c_set_mgt_filter(hw
, value16
);
978 /* Reject all control frame - default value is 0 */
979 rtl92c_set_ctrl_filter(hw
, 0x0);
980 /* Accept all data frames */
982 rtl92c_set_data_filter(hw
, value16
);
985 static int _rtl92cu_init_mac(struct ieee80211_hw
*hw
)
987 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
988 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
989 struct rtl_usb_priv
*usb_priv
= rtl_usbpriv(hw
);
990 struct rtl_usb
*rtlusb
= rtl_usbdev(usb_priv
);
993 u8 wmm_enable
= false; /* TODO */
994 u8 out_ep_nums
= rtlusb
->out_ep_nums
;
995 u8 queue_sel
= rtlusb
->out_queue_sel
;
996 err
= _rtl92cu_init_power_on(hw
);
999 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1000 ("Failed to init power on!\n"));
1004 boundary
= TX_PAGE_BOUNDARY
;
1005 } else { /* for WMM */
1006 boundary
= (IS_NORMAL_CHIP(rtlhal
->version
))
1007 ? WMM_CHIP_B_TX_PAGE_BOUNDARY
1008 : WMM_CHIP_A_TX_PAGE_BOUNDARY
;
1010 if (false == rtl92c_init_llt_table(hw
, boundary
)) {
1011 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1012 ("Failed to init LLT Table!\n"));
1015 _rtl92cu_init_queue_reserved_page(hw
, wmm_enable
, out_ep_nums
,
1017 _rtl92c_init_trx_buffer(hw
, wmm_enable
);
1018 _rtl92cu_init_queue_priority(hw
, wmm_enable
, out_ep_nums
,
1020 /* Get Rx PHY status in order to report RSSI and others. */
1021 rtl92c_init_driver_info_size(hw
, RTL92C_DRIVER_INFO_SIZE
);
1022 rtl92c_init_interrupt(hw
);
1023 rtl92c_init_network_type(hw
);
1024 _rtl92cu_init_wmac_setting(hw
);
1025 rtl92c_init_adaptive_ctrl(hw
);
1026 rtl92c_init_edca(hw
);
1027 rtl92c_init_rate_fallback(hw
);
1028 rtl92c_init_retry_function(hw
);
1029 _rtl92cu_init_usb_aggregation(hw
);
1030 rtlpriv
->cfg
->ops
->set_bw_mode(hw
, NL80211_CHAN_HT20
);
1031 rtl92c_set_min_space(hw
, IS_92C_SERIAL(rtlhal
->version
));
1032 rtl92c_init_beacon_parameters(hw
, rtlhal
->version
);
1033 rtl92c_init_ampdu_aggregation(hw
);
1034 rtl92c_init_beacon_max_error(hw
, true);
1038 void rtl92cu_enable_hw_security_config(struct ieee80211_hw
*hw
)
1040 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1041 u8 sec_reg_value
= 0x0;
1042 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1044 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
1045 ("PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
1046 rtlpriv
->sec
.pairwise_enc_algorithm
,
1047 rtlpriv
->sec
.group_enc_algorithm
));
1048 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
1049 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
1050 ("not open sw encryption\n"));
1053 sec_reg_value
= SCR_TxEncEnable
| SCR_RxDecEnable
;
1054 if (rtlpriv
->sec
.use_defaultkey
) {
1055 sec_reg_value
|= SCR_TxUseDK
;
1056 sec_reg_value
|= SCR_RxUseDK
;
1058 if (IS_NORMAL_CHIP(rtlhal
->version
))
1059 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
1060 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1061 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_LOUD
,
1062 ("The SECR-value %x\n", sec_reg_value
));
1063 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
1066 static void _rtl92cu_hw_configure(struct ieee80211_hw
*hw
)
1068 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1069 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1071 /* To Fix MAC loopback mode fail. */
1072 rtl_write_byte(rtlpriv
, REG_LDOHCI12_CTRL
, 0x0f);
1073 rtl_write_byte(rtlpriv
, 0x15, 0xe9);
1075 /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */
1076 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, 0xFF);
1077 /* fixed USB interface interference issue */
1078 rtl_write_byte(rtlpriv
, 0xfe40, 0xe0);
1079 rtl_write_byte(rtlpriv
, 0xfe41, 0x8d);
1080 rtl_write_byte(rtlpriv
, 0xfe42, 0x80);
1081 rtlusb
->reg_bcn_ctrl_val
= 0x18;
1082 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlusb
->reg_bcn_ctrl_val
);
1085 static void _InitPABias(struct ieee80211_hw
*hw
)
1087 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1088 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1091 /* FIXED PA current issue */
1092 pa_setting
= efuse_read_1byte(hw
, 0x1FA);
1093 if (!(pa_setting
& BIT(0))) {
1094 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x0F406);
1095 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x4F406);
1096 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x8F406);
1097 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0xCF406);
1099 if (!(pa_setting
& BIT(1)) && IS_NORMAL_CHIP(rtlhal
->version
) &&
1100 IS_92C_SERIAL(rtlhal
->version
)) {
1101 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x0F406);
1102 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x4F406);
1103 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x8F406);
1104 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0xCF406);
1106 if (!(pa_setting
& BIT(4))) {
1107 pa_setting
= rtl_read_byte(rtlpriv
, 0x16);
1109 rtl_write_byte(rtlpriv
, 0x16, pa_setting
| 0x90);
1113 static void _InitAntenna_Selection(struct ieee80211_hw
*hw
)
1115 #ifdef CONFIG_ANTENNA_DIVERSITY
1116 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1117 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1118 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1120 if (pHalData
->AntDivCfg
== 0)
1123 if (rtlphy
->rf_type
== RF_1T1R
) {
1124 rtl_write_dword(rtlpriv
, REG_LEDCFG0
,
1125 rtl_read_dword(rtlpriv
,
1126 REG_LEDCFG0
)|BIT(23));
1127 rtl_set_bbreg(hw
, rFPGA0_XAB_RFPARAMETER
, BIT(13), 0x01);
1128 if (rtl_get_bbreg(hw
, RFPGA0_XA_RFINTERFACEOE
, 0x300) ==
1130 pHalData
->CurAntenna
= Antenna_A
;
1132 pHalData
->CurAntenna
= Antenna_B
;
1137 static void _dump_registers(struct ieee80211_hw
*hw
)
1141 static void _update_mac_setting(struct ieee80211_hw
*hw
)
1143 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1144 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1146 mac
->rx_conf
= rtl_read_dword(rtlpriv
, REG_RCR
);
1147 mac
->rx_mgt_filter
= rtl_read_word(rtlpriv
, REG_RXFLTMAP0
);
1148 mac
->rx_ctrl_filter
= rtl_read_word(rtlpriv
, REG_RXFLTMAP1
);
1149 mac
->rx_data_filter
= rtl_read_word(rtlpriv
, REG_RXFLTMAP2
);
1152 int rtl92cu_hw_init(struct ieee80211_hw
*hw
)
1154 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1155 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1156 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1157 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1158 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1160 static bool iqk_initialized
;
1162 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192CU
;
1163 err
= _rtl92cu_init_mac(hw
);
1165 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("init mac failed!\n"));
1168 err
= rtl92c_download_fw(hw
);
1170 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1171 ("Failed to download FW. Init HW without FW now..\n"));
1173 rtlhal
->fw_ready
= false;
1176 rtlhal
->fw_ready
= true;
1178 rtlhal
->last_hmeboxnum
= 0; /* h2c */
1179 _rtl92cu_phy_param_tab_init(hw
);
1180 rtl92cu_phy_mac_config(hw
);
1181 rtl92cu_phy_bb_config(hw
);
1182 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1183 rtl92c_phy_rf_config(hw
);
1184 if (IS_VENDOR_UMC_A_CUT(rtlhal
->version
) &&
1185 !IS_92C_SERIAL(rtlhal
->version
)) {
1186 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G1
, MASKDWORD
, 0x30255);
1187 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G2
, MASKDWORD
, 0x50a00);
1189 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1190 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1191 rtlphy
->rfreg_chnlval
[1] = rtl_get_rfreg(hw
, (enum radio_path
)1,
1192 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1193 rtl92cu_bb_block_on(hw
);
1194 rtl_cam_reset_all_entry(hw
);
1195 rtl92cu_enable_hw_security_config(hw
);
1196 ppsc
->rfpwr_state
= ERFON
;
1197 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1198 if (ppsc
->rfpwr_state
== ERFON
) {
1199 rtl92c_phy_set_rfpath_switch(hw
, 1);
1200 if (iqk_initialized
) {
1201 rtl92c_phy_iq_calibrate(hw
, false);
1203 rtl92c_phy_iq_calibrate(hw
, false);
1204 iqk_initialized
= true;
1206 rtl92c_dm_check_txpower_tracking(hw
);
1207 rtl92c_phy_lc_calibrate(hw
);
1209 _rtl92cu_hw_configure(hw
);
1211 _InitAntenna_Selection(hw
);
1212 _update_mac_setting(hw
);
1214 _dump_registers(hw
);
1218 static void _DisableRFAFEAndResetBB(struct ieee80211_hw
*hw
)
1220 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1221 /**************************************
1222 a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue
1223 b. RF path 0 offset 0x00 = 0x00 disable RF
1224 c. APSD_CTRL 0x600[7:0] = 0x40
1225 d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine
1226 e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine
1227 ***************************************/
1228 u8 eRFPath
= 0, value8
= 0;
1229 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
1230 rtl_set_rfreg(hw
, (enum radio_path
)eRFPath
, 0x0, MASKBYTE0
, 0x0);
1233 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, value8
); /*0x40*/
1235 value8
|= (FEN_USBD
| FEN_USBA
| FEN_BB_GLB_RSTn
);
1236 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, value8
);/*0x16*/
1237 value8
&= (~FEN_BB_GLB_RSTn
);
1238 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, value8
); /*0x14*/
1241 static void _ResetDigitalProcedure1(struct ieee80211_hw
*hw
, bool bWithoutHWSM
)
1243 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1244 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1246 if (rtlhal
->fw_version
<= 0x20) {
1247 /*****************************
1248 f. MCUFWDL 0x80[7:0]=0 reset MCU ready status
1249 g. SYS_FUNC_EN 0x02[10]= 0 reset MCU reg, (8051 reset)
1250 h. SYS_FUNC_EN 0x02[15-12]= 5 reset MAC reg, DCORE
1251 i. SYS_FUNC_EN 0x02[10]= 1 enable MCU reg, (8051 enable)
1252 ******************************/
1255 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1256 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1257 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
&
1258 (~FEN_CPUEN
))); /* reset MCU ,8051 */
1259 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
)&0x0FFF;
1260 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
|
1261 (FEN_HWPDN
|FEN_ELDR
))); /* reset MAC */
1262 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1263 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
|
1264 FEN_CPUEN
)); /* enable MCU ,8051 */
1268 /* IF fw in RAM code, do reset */
1269 if (rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(1)) {
1270 /* reset MCU ready status */
1271 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1272 if (rtlhal
->fw_ready
) {
1273 /* 8051 reset by self */
1274 rtl_write_byte(rtlpriv
, REG_HMETFR
+3, 0x20);
1275 while ((retry_cnts
++ < 100) &&
1276 (FEN_CPUEN
& rtl_read_word(rtlpriv
,
1277 REG_SYS_FUNC_EN
))) {
1280 if (retry_cnts
>= 100) {
1281 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1282 ("#####=> 8051 reset failed!.."
1283 ".......................\n"););
1284 /* if 8051 reset fail, reset MAC. */
1285 rtl_write_byte(rtlpriv
,
1286 REG_SYS_FUNC_EN
+ 1,
1292 /* Reset MAC and Enable 8051 */
1293 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, 0x54);
1294 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1297 /*****************************
1298 Without HW auto state machine
1299 g.SYS_CLKR 0x08[15:0] = 0x30A3 disable MAC clock
1300 h.AFE_PLL_CTRL 0x28[7:0] = 0x80 disable AFE PLL
1301 i.AFE_XTAL_CTRL 0x24[15:0] = 0x880F gated AFE DIG_CLOCK
1302 j.SYS_ISu_CTRL 0x00[7:0] = 0xF9 isolated digital to PON
1303 ******************************/
1304 rtl_write_word(rtlpriv
, REG_SYS_CLKR
, 0x70A3);
1305 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
, 0x80);
1306 rtl_write_word(rtlpriv
, REG_AFE_XTAL_CTRL
, 0x880F);
1307 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xF9);
1311 static void _ResetDigitalProcedure2(struct ieee80211_hw
*hw
)
1313 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1314 /*****************************
1315 k. SYS_FUNC_EN 0x03[7:0] = 0x44 disable ELDR runction
1316 l. SYS_CLKR 0x08[15:0] = 0x3083 disable ELDR clock
1317 m. SYS_ISO_CTRL 0x01[7:0] = 0x83 isolated ELDR to PON
1318 ******************************/
1319 rtl_write_word(rtlpriv
, REG_SYS_CLKR
, 0x70A3);
1320 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+1, 0x82);
1323 static void _DisableGPIO(struct ieee80211_hw
*hw
)
1325 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1326 /***************************************
1327 j. GPIO_PIN_CTRL 0x44[31:0]=0x000
1328 k. Value = GPIO_PIN_CTRL[7:0]
1329 l. GPIO_PIN_CTRL 0x44[31:0] = 0x00FF0000 | (value <<8); write ext PIN level
1330 m. GPIO_MUXCFG 0x42 [15:0] = 0x0780
1331 n. LEDCFG 0x4C[15:0] = 0x8080
1332 ***************************************/
1337 /* 1. Disable GPIO[7:0] */
1338 rtl_write_word(rtlpriv
, REG_GPIO_PIN_CTRL
+2, 0x0000);
1339 value32
= rtl_read_dword(rtlpriv
, REG_GPIO_PIN_CTRL
) & 0xFFFF00FF;
1340 value8
= (u8
) (value32
&0x000000FF);
1341 value32
|= ((value8
<<8) | 0x00FF0000);
1342 rtl_write_dword(rtlpriv
, REG_GPIO_PIN_CTRL
, value32
);
1343 /* 2. Disable GPIO[10:8] */
1344 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+3, 0x00);
1345 value16
= rtl_read_word(rtlpriv
, REG_GPIO_MUXCFG
+2) & 0xFF0F;
1346 value8
= (u8
) (value16
&0x000F);
1347 value16
|= ((value8
<<4) | 0x0780);
1348 rtl_write_word(rtlpriv
, REG_GPIO_PIN_CTRL
+2, value16
);
1349 /* 3. Disable LED0 & 1 */
1350 rtl_write_word(rtlpriv
, REG_LEDCFG0
, 0x8080);
1353 static void _DisableAnalog(struct ieee80211_hw
*hw
, bool bWithoutHWSM
)
1355 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1360 /*****************************
1361 n. LDOA15_CTRL 0x20[7:0] = 0x04 disable A15 power
1362 o. LDOV12D_CTRL 0x21[7:0] = 0x54 disable digital core power
1363 r. When driver call disable, the ASIC will turn off remaining
1365 ******************************/
1366 rtl_write_byte(rtlpriv
, REG_LDOA15_CTRL
, 0x04);
1367 value8
= rtl_read_byte(rtlpriv
, REG_LDOV12D_CTRL
);
1368 value8
&= (~LDV12_EN
);
1369 rtl_write_byte(rtlpriv
, REG_LDOV12D_CTRL
, value8
);
1372 /*****************************
1373 h. SPS0_CTRL 0x11[7:0] = 0x23 enter PFM mode
1374 i. APS_FSMCO 0x04[15:0] = 0x4802 set USB suspend
1375 ******************************/
1376 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x23);
1377 value16
|= (APDM_HOST
| AFSM_HSUS
| PFM_ALDN
);
1378 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, (u16
)value16
);
1379 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0E);
1382 static void _CardDisableHWSM(struct ieee80211_hw
*hw
)
1384 /* ==== RF Off Sequence ==== */
1385 _DisableRFAFEAndResetBB(hw
);
1386 /* ==== Reset digital sequence ====== */
1387 _ResetDigitalProcedure1(hw
, false);
1388 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1390 /* ==== Disable analog sequence === */
1391 _DisableAnalog(hw
, false);
1394 static void _CardDisableWithoutHWSM(struct ieee80211_hw
*hw
)
1396 /*==== RF Off Sequence ==== */
1397 _DisableRFAFEAndResetBB(hw
);
1398 /* ==== Reset digital sequence ====== */
1399 _ResetDigitalProcedure1(hw
, true);
1400 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1402 /* ==== Reset digital sequence ====== */
1403 _ResetDigitalProcedure2(hw
);
1404 /* ==== Disable analog sequence === */
1405 _DisableAnalog(hw
, true);
1408 static void _rtl92cu_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
1409 u8 set_bits
, u8 clear_bits
)
1411 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1412 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1414 rtlusb
->reg_bcn_ctrl_val
|= set_bits
;
1415 rtlusb
->reg_bcn_ctrl_val
&= ~clear_bits
;
1416 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlusb
->reg_bcn_ctrl_val
);
1419 static void _rtl92cu_stop_tx_beacon(struct ieee80211_hw
*hw
)
1421 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1422 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1424 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1425 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
1426 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1427 tmp1byte
& (~BIT(6)));
1428 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
1429 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
1430 tmp1byte
&= ~(BIT(0));
1431 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
1433 rtl_write_byte(rtlpriv
, REG_TXPAUSE
,
1434 rtl_read_byte(rtlpriv
, REG_TXPAUSE
) | BIT(6));
1438 static void _rtl92cu_resume_tx_beacon(struct ieee80211_hw
*hw
)
1440 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1441 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1444 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1445 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
1446 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1448 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
1449 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
1451 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
1453 rtl_write_byte(rtlpriv
, REG_TXPAUSE
,
1454 rtl_read_byte(rtlpriv
, REG_TXPAUSE
) & (~BIT(6)));
1458 static void _rtl92cu_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
1460 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1461 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1463 if (IS_NORMAL_CHIP(rtlhal
->version
))
1464 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(1));
1466 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1469 static void _rtl92cu_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
1471 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1472 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1474 if (IS_NORMAL_CHIP(rtlhal
->version
))
1475 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(1), 0);
1477 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1480 static int _rtl92cu_set_media_status(struct ieee80211_hw
*hw
,
1481 enum nl80211_iftype type
)
1483 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1484 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
1485 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1488 rtl_write_byte(rtlpriv
, REG_BCN_MAX_ERR
, 0xFF);
1489 if (type
== NL80211_IFTYPE_UNSPECIFIED
|| type
==
1490 NL80211_IFTYPE_STATION
) {
1491 _rtl92cu_stop_tx_beacon(hw
);
1492 _rtl92cu_enable_bcn_sub_func(hw
);
1493 } else if (type
== NL80211_IFTYPE_ADHOC
|| type
== NL80211_IFTYPE_AP
) {
1494 _rtl92cu_resume_tx_beacon(hw
);
1495 _rtl92cu_disable_bcn_sub_func(hw
);
1497 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
, ("Set HW_VAR_MEDIA_"
1498 "STATUS:No such media status(%x).\n", type
));
1501 case NL80211_IFTYPE_UNSPECIFIED
:
1502 bt_msr
|= MSR_NOLINK
;
1503 ledaction
= LED_CTL_LINK
;
1504 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1505 ("Set Network type to NO LINK!\n"));
1507 case NL80211_IFTYPE_ADHOC
:
1508 bt_msr
|= MSR_ADHOC
;
1509 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1510 ("Set Network type to Ad Hoc!\n"));
1512 case NL80211_IFTYPE_STATION
:
1513 bt_msr
|= MSR_INFRA
;
1514 ledaction
= LED_CTL_LINK
;
1515 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1516 ("Set Network type to STA!\n"));
1518 case NL80211_IFTYPE_AP
:
1520 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1521 ("Set Network type to AP!\n"));
1524 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1525 ("Network type %d not support!\n", type
));
1528 rtl_write_byte(rtlpriv
, (MSR
), bt_msr
);
1529 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1530 if ((bt_msr
& 0xfc) == MSR_AP
)
1531 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1533 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1539 void rtl92cu_card_disable(struct ieee80211_hw
*hw
)
1541 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1542 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1543 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1544 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1545 enum nl80211_iftype opmode
;
1547 mac
->link_state
= MAC80211_NOLINK
;
1548 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1549 _rtl92cu_set_media_status(hw
, opmode
);
1550 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1551 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1552 if (rtlusb
->disableHWSM
)
1553 _CardDisableHWSM(hw
);
1555 _CardDisableWithoutHWSM(hw
);
1558 void rtl92cu_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1560 /* dummy routine needed for callback from rtl_op_configure_filter() */
1563 /*========================================================================== */
1565 static void _rtl92cu_set_check_bssid(struct ieee80211_hw
*hw
,
1566 enum nl80211_iftype type
)
1568 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1569 u32 reg_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
1570 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1571 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1572 u8 filterout_non_associated_bssid
= false;
1575 case NL80211_IFTYPE_ADHOC
:
1576 case NL80211_IFTYPE_STATION
:
1577 filterout_non_associated_bssid
= true;
1579 case NL80211_IFTYPE_UNSPECIFIED
:
1580 case NL80211_IFTYPE_AP
:
1584 if (filterout_non_associated_bssid
) {
1585 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1586 switch (rtlphy
->current_io_type
) {
1587 case IO_CMD_RESUME_DM_BY_SCAN
:
1588 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1589 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1590 HW_VAR_RCR
, (u8
*)(®_rcr
));
1591 /* enable update TSF */
1592 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1594 case IO_CMD_PAUSE_DM_BY_SCAN
:
1595 reg_rcr
&= ~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1596 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1597 HW_VAR_RCR
, (u8
*)(®_rcr
));
1598 /* disable update TSF */
1599 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1603 reg_rcr
|= (RCR_CBSSID
);
1604 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1606 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, (BIT(4)|BIT(5)));
1608 } else if (filterout_non_associated_bssid
== false) {
1609 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1610 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1611 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1613 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1615 reg_rcr
&= (~RCR_CBSSID
);
1616 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1618 _rtl92cu_set_bcn_ctrl_reg(hw
, (BIT(4)|BIT(5)), 0);
1623 int rtl92cu_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
1625 if (_rtl92cu_set_media_status(hw
, type
))
1627 _rtl92cu_set_check_bssid(hw
, type
);
1631 static void _InitBeaconParameters(struct ieee80211_hw
*hw
)
1633 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1634 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1636 rtl_write_word(rtlpriv
, REG_BCN_CTRL
, 0x1010);
1638 /* TODO: Remove these magic number */
1639 rtl_write_word(rtlpriv
, REG_TBTT_PROHIBIT
, 0x6404);
1640 rtl_write_byte(rtlpriv
, REG_DRVERLYINT
, DRIVER_EARLY_INT_TIME
);
1641 rtl_write_byte(rtlpriv
, REG_BCNDMATIM
, BCN_DMA_ATIME_INT_TIME
);
1642 /* Change beacon AIFS to the largest number
1643 * beacause test chip does not contension before sending beacon. */
1644 if (IS_NORMAL_CHIP(rtlhal
->version
))
1645 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660F);
1647 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x66FF);
1650 static void _beacon_function_enable(struct ieee80211_hw
*hw
, bool Enable
,
1653 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1655 _rtl92cu_set_bcn_ctrl_reg(hw
, (BIT(4) | BIT(3) | BIT(1)), 0x00);
1656 rtl_write_byte(rtlpriv
, REG_RD_CTRL
+1, 0x6F);
1659 void rtl92cu_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1662 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1663 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1664 u16 bcn_interval
, atim_window
;
1667 bcn_interval
= mac
->beacon_interval
;
1668 atim_window
= 2; /*FIX MERGE */
1669 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1670 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1671 _InitBeaconParameters(hw
);
1672 rtl_write_byte(rtlpriv
, REG_SLOT
, 0x09);
1674 * Force beacon frame transmission even after receiving beacon frame
1675 * from other ad hoc STA
1678 * Reset TSF Timer to zero, added by Roger. 2008.06.24
1680 value32
= rtl_read_dword(rtlpriv
, REG_TCR
);
1682 rtl_write_dword(rtlpriv
, REG_TCR
, value32
);
1684 rtl_write_dword(rtlpriv
, REG_TCR
, value32
);
1685 RT_TRACE(rtlpriv
, COMP_INIT
|COMP_BEACON
, DBG_LOUD
,
1686 ("SetBeaconRelatedRegisters8192CUsb(): Set TCR(%x)\n",
1688 /* TODO: Modify later (Find the right parameters)
1689 * NOTE: Fix test chip's bug (about contention windows's randomness) */
1690 if ((mac
->opmode
== NL80211_IFTYPE_ADHOC
) ||
1691 (mac
->opmode
== NL80211_IFTYPE_AP
)) {
1692 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x50);
1693 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x50);
1695 _beacon_function_enable(hw
, true, true);
1698 void rtl92cu_set_beacon_interval(struct ieee80211_hw
*hw
)
1700 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1701 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1702 u16 bcn_interval
= mac
->beacon_interval
;
1704 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
,
1705 ("beacon_interval:%d\n", bcn_interval
));
1706 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1709 void rtl92cu_update_interrupt_mask(struct ieee80211_hw
*hw
,
1710 u32 add_msr
, u32 rm_msr
)
1714 void rtl92cu_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
1716 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1717 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1718 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1722 *((u32
*)(val
)) = mac
->rx_conf
;
1724 case HW_VAR_RF_STATE
:
1725 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
1727 case HW_VAR_FWLPS_RF_ON
:{
1728 enum rf_pwrstate rfState
;
1731 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
,
1733 if (rfState
== ERFOFF
) {
1734 *((bool *) (val
)) = true;
1736 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
1737 val_rcr
&= 0x00070000;
1739 *((bool *) (val
)) = false;
1741 *((bool *) (val
)) = true;
1745 case HW_VAR_FW_PSMODE_STATUS
:
1746 *((bool *) (val
)) = ppsc
->fw_current_inpsmode
;
1748 case HW_VAR_CORRECT_TSF
:{
1750 u32
*ptsf_low
= (u32
*)&tsf
;
1751 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
1753 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
1754 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
1755 *((u64
*)(val
)) = tsf
;
1758 case HW_VAR_MGT_FILTER
:
1759 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP0
);
1761 case HW_VAR_CTRL_FILTER
:
1762 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP1
);
1764 case HW_VAR_DATA_FILTER
:
1765 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP2
);
1768 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1769 ("switch case not process\n"));
1774 void rtl92cu_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
1776 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1777 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1778 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1779 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1780 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1781 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1782 enum wireless_mode wirelessmode
= mac
->mode
;
1786 case HW_VAR_ETHER_ADDR
:{
1787 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
1788 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
1793 case HW_VAR_BASIC_RATE
:{
1794 u16 rate_cfg
= ((u16
*) val
)[0];
1799 /* if (mac->current_network.vender == HT_IOT_PEER_CISCO
1800 * && ((rate_cfg & 0x150) == 0)) {
1801 * rate_cfg |= 0x010;
1804 rtl_write_byte(rtlpriv
, REG_RRSR
, rate_cfg
& 0xff);
1805 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1,
1806 (rate_cfg
>> 8) & 0xff);
1807 while (rate_cfg
> 0x1) {
1811 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
,
1816 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
1817 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
1823 rtl_write_byte(rtlpriv
, REG_SIFS_CCK
+ 1, val
[0]);
1824 rtl_write_byte(rtlpriv
, REG_SIFS_OFDM
+ 1, val
[1]);
1825 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
1826 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
1827 rtl_write_byte(rtlpriv
, REG_R2T_SIFS
+1, val
[0]);
1828 rtl_write_byte(rtlpriv
, REG_T2T_SIFS
+1, val
[0]);
1829 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1833 case HW_VAR_SLOT_TIME
:{
1837 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
1838 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1839 ("HW_VAR_SLOT_TIME %x\n", val
[0]));
1841 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++)
1842 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1849 if (IS_WIRELESS_MODE_A(wirelessmode
) ||
1850 IS_WIRELESS_MODE_N_24G(wirelessmode
) ||
1851 IS_WIRELESS_MODE_N_5G(wirelessmode
))
1855 u1bAIFS
= sifstime
+ (2 * val
[0]);
1856 rtl_write_byte(rtlpriv
, REG_EDCA_VO_PARAM
,
1858 rtl_write_byte(rtlpriv
, REG_EDCA_VI_PARAM
,
1860 rtl_write_byte(rtlpriv
, REG_EDCA_BE_PARAM
,
1862 rtl_write_byte(rtlpriv
, REG_EDCA_BK_PARAM
,
1867 case HW_VAR_ACK_PREAMBLE
:{
1869 u8 short_preamble
= (bool) (*(u8
*) val
);
1873 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_tmp
);
1876 case HW_VAR_AMPDU_MIN_SPACE
:{
1877 u8 min_spacing_to_set
;
1880 min_spacing_to_set
= *((u8
*) val
);
1881 if (min_spacing_to_set
<= 7) {
1882 switch (rtlpriv
->sec
.pairwise_enc_algorithm
) {
1884 case AESCCMP_ENCRYPTION
:
1887 case WEP40_ENCRYPTION
:
1888 case WEP104_ENCRYPTION
:
1889 case TKIP_ENCRYPTION
:
1896 if (min_spacing_to_set
< sec_min_space
)
1897 min_spacing_to_set
= sec_min_space
;
1898 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
1900 min_spacing_to_set
);
1901 *val
= min_spacing_to_set
;
1902 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1903 ("Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
1904 mac
->min_space_cfg
));
1905 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
1906 mac
->min_space_cfg
);
1910 case HW_VAR_SHORTGI_DENSITY
:{
1913 density_to_set
= *((u8
*) val
);
1914 density_to_set
&= 0x1f;
1915 mac
->min_space_cfg
&= 0x07;
1916 mac
->min_space_cfg
|= (density_to_set
<< 3);
1917 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1918 ("Set HW_VAR_SHORTGI_DENSITY: %#x\n",
1919 mac
->min_space_cfg
));
1920 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
1921 mac
->min_space_cfg
);
1924 case HW_VAR_AMPDU_FACTOR
:{
1925 u8 regtoset_normal
[4] = {0x41, 0xa8, 0x72, 0xb9};
1927 u8
*p_regtoset
= NULL
;
1930 p_regtoset
= regtoset_normal
;
1931 factor_toset
= *((u8
*) val
);
1932 if (factor_toset
<= 3) {
1933 factor_toset
= (1 << (factor_toset
+ 2));
1934 if (factor_toset
> 0xf)
1936 for (index
= 0; index
< 4; index
++) {
1937 if ((p_regtoset
[index
] & 0xf0) >
1938 (factor_toset
<< 4))
1940 (p_regtoset
[index
] & 0x0f)
1941 | (factor_toset
<< 4);
1942 if ((p_regtoset
[index
] & 0x0f) >
1945 (p_regtoset
[index
] & 0xf0)
1947 rtl_write_byte(rtlpriv
,
1948 (REG_AGGLEN_LMT
+ index
),
1951 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1952 ("Set HW_VAR_AMPDU_FACTOR: %#x\n",
1957 case HW_VAR_AC_PARAM
:{
1958 u8 e_aci
= *((u8
*) val
);
1960 u16 cw_min
= le16_to_cpu(mac
->ac
[e_aci
].cw_min
);
1961 u16 cw_max
= le16_to_cpu(mac
->ac
[e_aci
].cw_max
);
1962 u16 tx_op
= le16_to_cpu(mac
->ac
[e_aci
].tx_op
);
1964 u4b_ac_param
= (u32
) mac
->ac
[e_aci
].aifs
;
1965 u4b_ac_param
|= (u32
) ((cw_min
& 0xF) <<
1966 AC_PARAM_ECW_MIN_OFFSET
);
1967 u4b_ac_param
|= (u32
) ((cw_max
& 0xF) <<
1968 AC_PARAM_ECW_MAX_OFFSET
);
1969 u4b_ac_param
|= (u32
) tx_op
<< AC_PARAM_TXOP_OFFSET
;
1970 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1971 ("queue:%x, ac_param:%x\n", e_aci
,
1975 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
,
1979 rtl_write_dword(rtlpriv
, REG_EDCA_BE_PARAM
,
1983 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
,
1987 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
,
1991 RT_ASSERT(false, ("SetHwReg8185(): invalid"
1992 " aci: %d !\n", e_aci
));
1995 if (rtlusb
->acm_method
!= eAcmWay2_SW
)
1996 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1997 HW_VAR_ACM_CTRL
, (u8
*)(&e_aci
));
2000 case HW_VAR_ACM_CTRL
:{
2001 u8 e_aci
= *((u8
*) val
);
2002 union aci_aifsn
*p_aci_aifsn
= (union aci_aifsn
*)
2003 (&(mac
->ac
[0].aifs
));
2004 u8 acm
= p_aci_aifsn
->f
.acm
;
2005 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
2008 acm_ctrl
| ((rtlusb
->acm_method
== 2) ? 0x0 : 0x1);
2012 acm_ctrl
|= AcmHw_BeqEn
;
2015 acm_ctrl
|= AcmHw_ViqEn
;
2018 acm_ctrl
|= AcmHw_VoqEn
;
2021 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
2022 ("HW_VAR_ACM_CTRL acm set "
2023 "failed: eACI is %d\n", acm
));
2029 acm_ctrl
&= (~AcmHw_BeqEn
);
2032 acm_ctrl
&= (~AcmHw_ViqEn
);
2035 acm_ctrl
&= (~AcmHw_BeqEn
);
2038 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
2039 ("switch case not process\n"));
2043 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
2044 ("SetHwReg8190pci(): [HW_VAR_ACM_CTRL] "
2045 "Write 0x%X\n", acm_ctrl
));
2046 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
2050 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*) (val
))[0]);
2051 mac
->rx_conf
= ((u32
*) (val
))[0];
2052 RT_TRACE(rtlpriv
, COMP_RECV
, DBG_DMESG
,
2053 ("### Set RCR(0x%08x) ###\n", mac
->rx_conf
));
2056 case HW_VAR_RETRY_LIMIT
:{
2057 u8 retry_limit
= ((u8
*) (val
))[0];
2059 rtl_write_word(rtlpriv
, REG_RL
,
2060 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
2061 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
2062 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_DMESG
, ("Set HW_VAR_R"
2063 "ETRY_LIMIT(0x%08x)\n", retry_limit
));
2066 case HW_VAR_DUAL_TSF_RST
:
2067 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
2069 case HW_VAR_EFUSE_BYTES
:
2070 rtlefuse
->efuse_usedbytes
= *((u16
*) val
);
2072 case HW_VAR_EFUSE_USAGE
:
2073 rtlefuse
->efuse_usedpercentage
= *((u8
*) val
);
2076 rtl92c_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
2078 case HW_VAR_WPA_CONFIG
:
2079 rtl_write_byte(rtlpriv
, REG_SECCFG
, *((u8
*) val
));
2081 case HW_VAR_SET_RPWM
:{
2082 u8 rpwm_val
= rtl_read_byte(rtlpriv
, REG_USB_HRPWM
);
2084 if (rpwm_val
& BIT(7))
2085 rtl_write_byte(rtlpriv
, REG_USB_HRPWM
,
2088 rtl_write_byte(rtlpriv
, REG_USB_HRPWM
,
2089 ((*(u8
*)val
) | BIT(7)));
2092 case HW_VAR_H2C_FW_PWRMODE
:{
2093 u8 psmode
= (*(u8
*) val
);
2095 if ((psmode
!= FW_PS_ACTIVE_MODE
) &&
2096 (!IS_92C_SERIAL(rtlhal
->version
)))
2097 rtl92c_dm_rf_saving(hw
, true);
2098 rtl92c_set_fw_pwrmode_cmd(hw
, (*(u8
*) val
));
2101 case HW_VAR_FW_PSMODE_STATUS
:
2102 ppsc
->fw_current_inpsmode
= *((bool *) val
);
2104 case HW_VAR_H2C_FW_JOINBSSRPT
:{
2105 u8 mstatus
= (*(u8
*) val
);
2107 bool recover
= false;
2109 if (mstatus
== RT_MEDIA_CONNECT
) {
2110 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
2112 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x03);
2113 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(3));
2114 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
2115 tmp_reg422
= rtl_read_byte(rtlpriv
,
2116 REG_FWHW_TXQ_CTRL
+ 2);
2117 if (tmp_reg422
& BIT(6))
2119 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
2120 tmp_reg422
& (~BIT(6)));
2121 rtl92c_set_fw_rsvdpagepkt(hw
, 0);
2122 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(3), 0);
2123 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(4));
2125 rtl_write_byte(rtlpriv
,
2126 REG_FWHW_TXQ_CTRL
+ 2,
2127 tmp_reg422
| BIT(6));
2128 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
2130 rtl92c_set_fw_joinbss_report_cmd(hw
, (*(u8
*) val
));
2136 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
2138 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
,
2139 (u2btmp
| mac
->assoc_id
));
2142 case HW_VAR_CORRECT_TSF
:{
2143 u8 btype_ibss
= ((u8
*) (val
))[0];
2146 _rtl92cu_stop_tx_beacon(hw
);
2147 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(3));
2148 rtl_write_dword(rtlpriv
, REG_TSFTR
, (u32
)(mac
->tsf
&
2150 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
2151 (u32
)((mac
->tsf
>> 32) & 0xffffffff));
2152 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(3), 0);
2154 _rtl92cu_resume_tx_beacon(hw
);
2157 case HW_VAR_MGT_FILTER
:
2158 rtl_write_word(rtlpriv
, REG_RXFLTMAP0
, *(u16
*)val
);
2160 case HW_VAR_CTRL_FILTER
:
2161 rtl_write_word(rtlpriv
, REG_RXFLTMAP1
, *(u16
*)val
);
2163 case HW_VAR_DATA_FILTER
:
2164 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, *(u16
*)val
);
2167 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, ("switch case "
2173 void rtl92cu_update_hal_rate_table(struct ieee80211_hw
*hw
,
2174 struct ieee80211_sta
*sta
,
2177 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2178 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2179 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2180 u32 ratr_value
= (u32
) mac
->basic_rates
;
2181 u8
*mcsrate
= mac
->mcs
;
2183 u8 nmode
= mac
->ht_enable
;
2185 u16 shortgi_rate
= 0;
2186 u32 tmp_ratr_value
= 0;
2187 u8 curtxbw_40mhz
= mac
->bw_40
;
2188 u8 curshortgi_40mhz
= mac
->sgi_40
;
2189 u8 curshortgi_20mhz
= mac
->sgi_20
;
2190 enum wireless_mode wirelessmode
= mac
->mode
;
2192 ratr_value
|= ((*(u16
*) (mcsrate
))) << 12;
2193 switch (wirelessmode
) {
2194 case WIRELESS_MODE_B
:
2195 if (ratr_value
& 0x0000000c)
2196 ratr_value
&= 0x0000000d;
2198 ratr_value
&= 0x0000000f;
2200 case WIRELESS_MODE_G
:
2201 ratr_value
&= 0x00000FF5;
2203 case WIRELESS_MODE_N_24G
:
2204 case WIRELESS_MODE_N_5G
:
2207 ratr_value
&= 0x0007F005;
2211 if (get_rf_type(rtlphy
) == RF_1T2R
||
2212 get_rf_type(rtlphy
) == RF_1T1R
)
2213 ratr_mask
= 0x000ff005;
2215 ratr_mask
= 0x0f0ff005;
2217 ratr_mask
|= 0x00000010;
2218 ratr_value
&= ratr_mask
;
2222 if (rtlphy
->rf_type
== RF_1T2R
)
2223 ratr_value
&= 0x000ff0ff;
2225 ratr_value
&= 0x0f0ff0ff;
2228 ratr_value
&= 0x0FFFFFFF;
2229 if (nmode
&& ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2230 (!curtxbw_40mhz
&& curshortgi_20mhz
))) {
2231 ratr_value
|= 0x10000000;
2232 tmp_ratr_value
= (ratr_value
>> 12);
2233 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2234 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2237 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2238 (shortgi_rate
<< 4) | (shortgi_rate
);
2240 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
2241 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
, ("%x\n", rtl_read_dword(rtlpriv
,
2245 void rtl92cu_update_hal_rate_mask(struct ieee80211_hw
*hw
, u8 rssi_level
)
2247 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2248 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2249 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2250 u32 ratr_bitmap
= (u32
) mac
->basic_rates
;
2251 u8
*p_mcsrate
= mac
->mcs
;
2253 u8 curtxbw_40mhz
= mac
->bw_40
;
2254 u8 curshortgi_40mhz
= mac
->sgi_40
;
2255 u8 curshortgi_20mhz
= mac
->sgi_20
;
2256 enum wireless_mode wirelessmode
= mac
->mode
;
2257 bool shortgi
= false;
2262 ratr_bitmap
|= (p_mcsrate
[1] << 20) | (p_mcsrate
[0] << 12);
2263 switch (wirelessmode
) {
2264 case WIRELESS_MODE_B
:
2265 ratr_index
= RATR_INX_WIRELESS_B
;
2266 if (ratr_bitmap
& 0x0000000c)
2267 ratr_bitmap
&= 0x0000000d;
2269 ratr_bitmap
&= 0x0000000f;
2271 case WIRELESS_MODE_G
:
2272 ratr_index
= RATR_INX_WIRELESS_GB
;
2273 if (rssi_level
== 1)
2274 ratr_bitmap
&= 0x00000f00;
2275 else if (rssi_level
== 2)
2276 ratr_bitmap
&= 0x00000ff0;
2278 ratr_bitmap
&= 0x00000ff5;
2280 case WIRELESS_MODE_A
:
2281 ratr_index
= RATR_INX_WIRELESS_A
;
2282 ratr_bitmap
&= 0x00000ff0;
2284 case WIRELESS_MODE_N_24G
:
2285 case WIRELESS_MODE_N_5G
:
2286 ratr_index
= RATR_INX_WIRELESS_NGB
;
2288 if (rssi_level
== 1)
2289 ratr_bitmap
&= 0x00070000;
2290 else if (rssi_level
== 2)
2291 ratr_bitmap
&= 0x0007f000;
2293 ratr_bitmap
&= 0x0007f005;
2295 if (rtlphy
->rf_type
== RF_1T2R
||
2296 rtlphy
->rf_type
== RF_1T1R
) {
2297 if (curtxbw_40mhz
) {
2298 if (rssi_level
== 1)
2299 ratr_bitmap
&= 0x000f0000;
2300 else if (rssi_level
== 2)
2301 ratr_bitmap
&= 0x000ff000;
2303 ratr_bitmap
&= 0x000ff015;
2305 if (rssi_level
== 1)
2306 ratr_bitmap
&= 0x000f0000;
2307 else if (rssi_level
== 2)
2308 ratr_bitmap
&= 0x000ff000;
2310 ratr_bitmap
&= 0x000ff005;
2313 if (curtxbw_40mhz
) {
2314 if (rssi_level
== 1)
2315 ratr_bitmap
&= 0x0f0f0000;
2316 else if (rssi_level
== 2)
2317 ratr_bitmap
&= 0x0f0ff000;
2319 ratr_bitmap
&= 0x0f0ff015;
2321 if (rssi_level
== 1)
2322 ratr_bitmap
&= 0x0f0f0000;
2323 else if (rssi_level
== 2)
2324 ratr_bitmap
&= 0x0f0ff000;
2326 ratr_bitmap
&= 0x0f0ff005;
2330 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2331 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2334 else if (macid
== 1)
2339 ratr_index
= RATR_INX_WIRELESS_NGB
;
2340 if (rtlphy
->rf_type
== RF_1T2R
)
2341 ratr_bitmap
&= 0x000ff0ff;
2343 ratr_bitmap
&= 0x0f0ff0ff;
2346 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
, ("ratr_bitmap :%x\n",
2348 *(u32
*)&rate_mask
= ((ratr_bitmap
& 0x0fffffff) |
2350 rate_mask
[4] = macid
| (shortgi
? 0x20 : 0x00) | 0x80;
2351 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
, ("Rate_index:%x, "
2352 "ratr_val:%x, %x:%x:%x:%x:%x\n",
2353 ratr_index
, ratr_bitmap
,
2354 rate_mask
[0], rate_mask
[1],
2355 rate_mask
[2], rate_mask
[3],
2357 rtl92c_fill_h2c_cmd(hw
, H2C_RA_MASK
, 5, rate_mask
);
2360 void rtl92cu_update_channel_access_setting(struct ieee80211_hw
*hw
)
2362 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2363 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2366 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2367 (u8
*)&mac
->slot_time
);
2368 if (!mac
->ht_enable
)
2369 sifs_timer
= 0x0a0a;
2371 sifs_timer
= 0x0e0e;
2372 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2375 bool rtl92cu_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
* valid
)
2377 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2378 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2379 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2380 enum rf_pwrstate e_rfpowerstate_toset
, cur_rfstate
;
2382 bool actuallyset
= false;
2383 unsigned long flag
= 0;
2384 /* to do - usb autosuspend */
2385 u8 usb_autosuspend
= 0;
2387 if (ppsc
->swrf_processing
)
2389 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2390 if (ppsc
->rfchange_inprogress
) {
2391 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2394 ppsc
->rfchange_inprogress
= true;
2395 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2397 cur_rfstate
= ppsc
->rfpwr_state
;
2398 if (usb_autosuspend
) {
2399 /* to do................... */
2401 if (ppsc
->pwrdown_mode
) {
2402 u1tmp
= rtl_read_byte(rtlpriv
, REG_HSISR
);
2403 e_rfpowerstate_toset
= (u1tmp
& BIT(7)) ?
2405 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
2406 ("pwrdown, 0x5c(BIT7)=%02x\n", u1tmp
));
2408 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
,
2409 rtl_read_byte(rtlpriv
,
2410 REG_MAC_PINMUX_CFG
) & ~(BIT(3)));
2411 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
);
2412 e_rfpowerstate_toset
= (u1tmp
& BIT(3)) ?
2414 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
2415 ("GPIO_IN=%02x\n", u1tmp
));
2417 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, ("N-SS RF =%x\n",
2418 e_rfpowerstate_toset
));
2420 if ((ppsc
->hwradiooff
) && (e_rfpowerstate_toset
== ERFON
)) {
2421 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, ("GPIOChangeRF - HW "
2422 "Radio ON, RF ON\n"));
2423 ppsc
->hwradiooff
= false;
2425 } else if ((!ppsc
->hwradiooff
) && (e_rfpowerstate_toset
==
2427 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, ("GPIOChangeRF - HW"
2429 ppsc
->hwradiooff
= true;
2432 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2433 ("pHalData->bHwRadioOff and eRfPowerStateToSet do not"
2434 " match: pHalData->bHwRadioOff %x, eRfPowerStateToSet "
2435 "%x\n", ppsc
->hwradiooff
, e_rfpowerstate_toset
));
2438 ppsc
->hwradiooff
= 1;
2439 if (e_rfpowerstate_toset
== ERFON
) {
2440 if ((ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
) &&
2441 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
))
2442 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2443 else if ((ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2444 && RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
))
2445 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2447 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2448 ppsc
->rfchange_inprogress
= false;
2449 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2450 /* For power down module, we need to enable register block
2451 * contrl reg at 0x1c. Then enable power down control bit
2452 * of register 0x04 BIT4 and BIT15 as 1.
2454 if (ppsc
->pwrdown_mode
&& e_rfpowerstate_toset
== ERFOFF
) {
2455 /* Enable register area 0x0-0xc. */
2456 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0);
2457 if (IS_HARDWARE_TYPE_8723U(rtlhal
)) {
2459 * We should configure HW PDn source for WiFi
2460 * ONLY, and then our HW will be set in
2461 * power-down mode if PDn source from all
2462 * functions are configured.
2464 u1tmp
= rtl_read_byte(rtlpriv
,
2465 REG_MULTI_FUNC_CTRL
);
2466 rtl_write_byte(rtlpriv
, REG_MULTI_FUNC_CTRL
,
2467 (u1tmp
|WL_HWPDN_EN
));
2469 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, 0x8812);
2472 if (e_rfpowerstate_toset
== ERFOFF
) {
2473 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
)
2474 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2475 else if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2476 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2478 } else if (e_rfpowerstate_toset
== ERFOFF
|| cur_rfstate
== ERFOFF
) {
2479 /* Enter D3 or ASPM after GPIO had been done. */
2480 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
)
2481 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2482 else if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2483 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2484 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2485 ppsc
->rfchange_inprogress
= false;
2486 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2488 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2489 ppsc
->rfchange_inprogress
= false;
2490 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2493 return !ppsc
->hwradiooff
;