1 /******************************************************************************
3 * Copyright(c) 2009-2012 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 *****************************************************************************/
42 #include "../rtl8192ce/hw.h"
47 static void _rtl92cu_phy_param_tab_init(struct ieee80211_hw
*hw
)
49 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
50 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
51 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtlpriv
);
53 rtlphy
->hwparam_tables
[MAC_REG
].length
= RTL8192CUMAC_2T_ARRAYLENGTH
;
54 rtlphy
->hwparam_tables
[MAC_REG
].pdata
= RTL8192CUMAC_2T_ARRAY
;
55 if (IS_HIGHT_PA(rtlefuse
->board_type
)) {
56 rtlphy
->hwparam_tables
[PHY_REG_PG
].length
=
57 RTL8192CUPHY_REG_Array_PG_HPLength
;
58 rtlphy
->hwparam_tables
[PHY_REG_PG
].pdata
=
59 RTL8192CUPHY_REG_Array_PG_HP
;
61 rtlphy
->hwparam_tables
[PHY_REG_PG
].length
=
62 RTL8192CUPHY_REG_ARRAY_PGLENGTH
;
63 rtlphy
->hwparam_tables
[PHY_REG_PG
].pdata
=
64 RTL8192CUPHY_REG_ARRAY_PG
;
67 rtlphy
->hwparam_tables
[PHY_REG_2T
].length
=
68 RTL8192CUPHY_REG_2TARRAY_LENGTH
;
69 rtlphy
->hwparam_tables
[PHY_REG_2T
].pdata
=
70 RTL8192CUPHY_REG_2TARRAY
;
71 rtlphy
->hwparam_tables
[RADIOA_2T
].length
=
72 RTL8192CURADIOA_2TARRAYLENGTH
;
73 rtlphy
->hwparam_tables
[RADIOA_2T
].pdata
=
74 RTL8192CURADIOA_2TARRAY
;
75 rtlphy
->hwparam_tables
[RADIOB_2T
].length
=
76 RTL8192CURADIOB_2TARRAYLENGTH
;
77 rtlphy
->hwparam_tables
[RADIOB_2T
].pdata
=
78 RTL8192CU_RADIOB_2TARRAY
;
79 rtlphy
->hwparam_tables
[AGCTAB_2T
].length
=
80 RTL8192CUAGCTAB_2TARRAYLENGTH
;
81 rtlphy
->hwparam_tables
[AGCTAB_2T
].pdata
=
82 RTL8192CUAGCTAB_2TARRAY
;
84 if (IS_HIGHT_PA(rtlefuse
->board_type
)) {
85 rtlphy
->hwparam_tables
[PHY_REG_1T
].length
=
86 RTL8192CUPHY_REG_1T_HPArrayLength
;
87 rtlphy
->hwparam_tables
[PHY_REG_1T
].pdata
=
88 RTL8192CUPHY_REG_1T_HPArray
;
89 rtlphy
->hwparam_tables
[RADIOA_1T
].length
=
90 RTL8192CURadioA_1T_HPArrayLength
;
91 rtlphy
->hwparam_tables
[RADIOA_1T
].pdata
=
92 RTL8192CURadioA_1T_HPArray
;
93 rtlphy
->hwparam_tables
[RADIOB_1T
].length
=
94 RTL8192CURADIOB_1TARRAYLENGTH
;
95 rtlphy
->hwparam_tables
[RADIOB_1T
].pdata
=
96 RTL8192CU_RADIOB_1TARRAY
;
97 rtlphy
->hwparam_tables
[AGCTAB_1T
].length
=
98 RTL8192CUAGCTAB_1T_HPArrayLength
;
99 rtlphy
->hwparam_tables
[AGCTAB_1T
].pdata
=
100 Rtl8192CUAGCTAB_1T_HPArray
;
102 rtlphy
->hwparam_tables
[PHY_REG_1T
].length
=
103 RTL8192CUPHY_REG_1TARRAY_LENGTH
;
104 rtlphy
->hwparam_tables
[PHY_REG_1T
].pdata
=
105 RTL8192CUPHY_REG_1TARRAY
;
106 rtlphy
->hwparam_tables
[RADIOA_1T
].length
=
107 RTL8192CURADIOA_1TARRAYLENGTH
;
108 rtlphy
->hwparam_tables
[RADIOA_1T
].pdata
=
109 RTL8192CU_RADIOA_1TARRAY
;
110 rtlphy
->hwparam_tables
[RADIOB_1T
].length
=
111 RTL8192CURADIOB_1TARRAYLENGTH
;
112 rtlphy
->hwparam_tables
[RADIOB_1T
].pdata
=
113 RTL8192CU_RADIOB_1TARRAY
;
114 rtlphy
->hwparam_tables
[AGCTAB_1T
].length
=
115 RTL8192CUAGCTAB_1TARRAYLENGTH
;
116 rtlphy
->hwparam_tables
[AGCTAB_1T
].pdata
=
117 RTL8192CUAGCTAB_1TARRAY
;
121 static void _rtl92cu_read_txpower_info_from_hwpg(struct ieee80211_hw
*hw
,
125 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
126 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
127 u8 rf_path
, index
, tempval
;
130 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
131 for (i
= 0; i
< 3; i
++) {
132 if (!autoload_fail
) {
134 eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
135 hwinfo
[EEPROM_TXPOWERCCK
+ rf_path
* 3 + i
];
137 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
138 hwinfo
[EEPROM_TXPOWERHT40_1S
+ rf_path
* 3 +
142 eeprom_chnlarea_txpwr_cck
[rf_path
][i
] =
143 EEPROM_DEFAULT_TXPOWERLEVEL
;
145 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
] =
146 EEPROM_DEFAULT_TXPOWERLEVEL
;
150 for (i
= 0; i
< 3; i
++) {
152 tempval
= hwinfo
[EEPROM_TXPOWERHT40_2SDIFF
+ i
];
154 tempval
= EEPROM_DEFAULT_HT40_2SDIFF
;
155 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[RF90_PATH_A
][i
] =
157 rtlefuse
->eprom_chnl_txpwr_ht40_2sdf
[RF90_PATH_B
][i
] =
158 ((tempval
& 0xf0) >> 4);
160 for (rf_path
= 0; rf_path
< 2; rf_path
++)
161 for (i
= 0; i
< 3; i
++)
162 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
163 "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
166 eeprom_chnlarea_txpwr_cck
[rf_path
][i
]);
167 for (rf_path
= 0; rf_path
< 2; rf_path
++)
168 for (i
= 0; i
< 3; i
++)
169 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
170 "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
173 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][i
]);
174 for (rf_path
= 0; rf_path
< 2; rf_path
++)
175 for (i
= 0; i
< 3; i
++)
176 RTPRINT(rtlpriv
, FINIT
, INIT_EEPROM
,
177 "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
180 eprom_chnl_txpwr_ht40_2sdf
[rf_path
][i
]);
181 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
182 for (i
= 0; i
< 14; i
++) {
183 index
= _rtl92c_get_chnl_group((u8
) i
);
184 rtlefuse
->txpwrlevel_cck
[rf_path
][i
] =
185 rtlefuse
->eeprom_chnlarea_txpwr_cck
[rf_path
][index
];
186 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
] =
188 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][index
];
190 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
][index
] -
192 eprom_chnl_txpwr_ht40_2sdf
[rf_path
][index
])
194 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] =
196 eeprom_chnlarea_txpwr_ht40_1s
[rf_path
]
198 eprom_chnl_txpwr_ht40_2sdf
[rf_path
]
201 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
] = 0;
204 for (i
= 0; i
< 14; i
++) {
205 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
206 "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n", rf_path
, i
,
207 rtlefuse
->txpwrlevel_cck
[rf_path
][i
],
208 rtlefuse
->txpwrlevel_ht40_1s
[rf_path
][i
],
209 rtlefuse
->txpwrlevel_ht40_2s
[rf_path
][i
]);
212 for (i
= 0; i
< 3; i
++) {
213 if (!autoload_fail
) {
214 rtlefuse
->eeprom_pwrlimit_ht40
[i
] =
215 hwinfo
[EEPROM_TXPWR_GROUP
+ i
];
216 rtlefuse
->eeprom_pwrlimit_ht20
[i
] =
217 hwinfo
[EEPROM_TXPWR_GROUP
+ 3 + i
];
219 rtlefuse
->eeprom_pwrlimit_ht40
[i
] = 0;
220 rtlefuse
->eeprom_pwrlimit_ht20
[i
] = 0;
223 for (rf_path
= 0; rf_path
< 2; rf_path
++) {
224 for (i
= 0; i
< 14; i
++) {
225 index
= _rtl92c_get_chnl_group((u8
) i
);
226 if (rf_path
== RF90_PATH_A
) {
227 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
228 (rtlefuse
->eeprom_pwrlimit_ht20
[index
]
230 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
231 (rtlefuse
->eeprom_pwrlimit_ht40
[index
]
233 } else if (rf_path
== RF90_PATH_B
) {
234 rtlefuse
->pwrgroup_ht20
[rf_path
][i
] =
235 ((rtlefuse
->eeprom_pwrlimit_ht20
[index
]
237 rtlefuse
->pwrgroup_ht40
[rf_path
][i
] =
238 ((rtlefuse
->eeprom_pwrlimit_ht40
[index
]
241 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
242 "RF-%d pwrgroup_ht20[%d] = 0x%x\n",
244 rtlefuse
->pwrgroup_ht20
[rf_path
][i
]);
245 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
246 "RF-%d pwrgroup_ht40[%d] = 0x%x\n",
248 rtlefuse
->pwrgroup_ht40
[rf_path
][i
]);
251 for (i
= 0; i
< 14; i
++) {
252 index
= _rtl92c_get_chnl_group((u8
) i
);
254 tempval
= hwinfo
[EEPROM_TXPOWERHT20DIFF
+ index
];
256 tempval
= EEPROM_DEFAULT_HT20_DIFF
;
257 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
258 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] =
259 ((tempval
>> 4) & 0xF);
260 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] & BIT(3))
261 rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
] |= 0xF0;
262 if (rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] & BIT(3))
263 rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
] |= 0xF0;
264 index
= _rtl92c_get_chnl_group((u8
) i
);
266 tempval
= hwinfo
[EEPROM_TXPOWER_OFDMDIFF
+ index
];
268 tempval
= EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF
;
269 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
] = (tempval
& 0xF);
270 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
] =
271 ((tempval
>> 4) & 0xF);
273 rtlefuse
->legacy_ht_txpowerdiff
=
274 rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][7];
275 for (i
= 0; i
< 14; i
++)
276 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
277 "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
278 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_A
][i
]);
279 for (i
= 0; i
< 14; i
++)
280 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
281 "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n",
282 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_A
][i
]);
283 for (i
= 0; i
< 14; i
++)
284 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
285 "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n",
286 i
, rtlefuse
->txpwr_ht20diff
[RF90_PATH_B
][i
]);
287 for (i
= 0; i
< 14; i
++)
288 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
289 "RF-B Legacy to HT40 Diff[%d] = 0x%x\n",
290 i
, rtlefuse
->txpwr_legacyhtdiff
[RF90_PATH_B
][i
]);
292 rtlefuse
->eeprom_regulatory
= (hwinfo
[RF_OPTION1
] & 0x7);
294 rtlefuse
->eeprom_regulatory
= 0;
295 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
296 "eeprom_regulatory = 0x%x\n", rtlefuse
->eeprom_regulatory
);
297 if (!autoload_fail
) {
298 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = hwinfo
[EEPROM_TSSI_A
];
299 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = hwinfo
[EEPROM_TSSI_B
];
301 rtlefuse
->eeprom_tssi
[RF90_PATH_A
] = EEPROM_DEFAULT_TSSI
;
302 rtlefuse
->eeprom_tssi
[RF90_PATH_B
] = EEPROM_DEFAULT_TSSI
;
304 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
305 "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
306 rtlefuse
->eeprom_tssi
[RF90_PATH_A
],
307 rtlefuse
->eeprom_tssi
[RF90_PATH_B
]);
309 tempval
= hwinfo
[EEPROM_THERMAL_METER
];
311 tempval
= EEPROM_DEFAULT_THERMALMETER
;
312 rtlefuse
->eeprom_thermalmeter
= (tempval
& 0x1f);
313 if (rtlefuse
->eeprom_thermalmeter
< 0x06 ||
314 rtlefuse
->eeprom_thermalmeter
> 0x1c)
315 rtlefuse
->eeprom_thermalmeter
= 0x12;
316 if (rtlefuse
->eeprom_thermalmeter
== 0x1f || autoload_fail
)
317 rtlefuse
->apk_thermalmeterignore
= true;
318 rtlefuse
->thermalmeter
[0] = rtlefuse
->eeprom_thermalmeter
;
319 RTPRINT(rtlpriv
, FINIT
, INIT_TXPOWER
,
320 "thermalmeter = 0x%x\n", rtlefuse
->eeprom_thermalmeter
);
323 static void _rtl92cu_read_board_type(struct ieee80211_hw
*hw
, u8
*contents
)
325 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
326 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
329 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
330 boardType
= ((contents
[EEPROM_RF_OPT1
]) &
331 BOARD_TYPE_NORMAL_MASK
) >> 5; /*bit[7:5]*/
333 boardType
= contents
[EEPROM_RF_OPT4
];
334 boardType
&= BOARD_TYPE_TEST_MASK
;
336 rtlefuse
->board_type
= boardType
;
337 if (IS_HIGHT_PA(rtlefuse
->board_type
))
338 rtlefuse
->external_pa
= 1;
339 pr_info("Board Type %x\n", rtlefuse
->board_type
);
342 static void _rtl92cu_read_adapter_info(struct ieee80211_hw
*hw
)
344 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
345 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
346 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
348 u8 hwinfo
[HWSET_MAX_SIZE
] = {0};
351 if (rtlefuse
->epromtype
== EEPROM_BOOT_EFUSE
) {
352 rtl_efuse_shadow_map_update(hw
);
353 memcpy((void *)hwinfo
,
354 (void *)&rtlefuse
->efuse_map
[EFUSE_INIT_MAP
][0],
356 } else if (rtlefuse
->epromtype
== EEPROM_93C46
) {
357 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
358 "RTL819X Not boot from eeprom, check it !!\n");
360 RT_PRINT_DATA(rtlpriv
, COMP_INIT
, DBG_LOUD
, "MAP",
361 hwinfo
, HWSET_MAX_SIZE
);
362 eeprom_id
= le16_to_cpu(*((__le16
*)&hwinfo
[0]));
363 if (eeprom_id
!= RTL8190_EEPROM_ID
) {
364 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
365 "EEPROM ID(%#x) is invalid!!\n", eeprom_id
);
366 rtlefuse
->autoload_failflag
= true;
368 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload OK\n");
369 rtlefuse
->autoload_failflag
= false;
371 if (rtlefuse
->autoload_failflag
)
373 for (i
= 0; i
< 6; i
+= 2) {
374 usvalue
= *(u16
*)&hwinfo
[EEPROM_MAC_ADDR
+ i
];
375 *((u16
*) (&rtlefuse
->dev_addr
[i
])) = usvalue
;
377 pr_info("MAC address: %pM\n", rtlefuse
->dev_addr
);
378 _rtl92cu_read_txpower_info_from_hwpg(hw
,
379 rtlefuse
->autoload_failflag
, hwinfo
);
380 rtlefuse
->eeprom_vid
= le16_to_cpu(*(__le16
*)&hwinfo
[EEPROM_VID
]);
381 rtlefuse
->eeprom_did
= le16_to_cpu(*(__le16
*)&hwinfo
[EEPROM_DID
]);
382 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, " VID = 0x%02x PID = 0x%02x\n",
383 rtlefuse
->eeprom_vid
, rtlefuse
->eeprom_did
);
384 rtlefuse
->eeprom_channelplan
= hwinfo
[EEPROM_CHANNELPLAN
];
385 rtlefuse
->eeprom_version
=
386 le16_to_cpu(*(__le16
*)&hwinfo
[EEPROM_VERSION
]);
387 rtlefuse
->txpwr_fromeprom
= true;
388 rtlefuse
->eeprom_oemid
= hwinfo
[EEPROM_CUSTOMER_ID
];
389 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "EEPROM Customer ID: 0x%2x\n",
390 rtlefuse
->eeprom_oemid
);
391 if (rtlhal
->oem_id
== RT_CID_DEFAULT
) {
392 switch (rtlefuse
->eeprom_oemid
) {
393 case EEPROM_CID_DEFAULT
:
394 if (rtlefuse
->eeprom_did
== 0x8176) {
395 if ((rtlefuse
->eeprom_svid
== 0x103C &&
396 rtlefuse
->eeprom_smid
== 0x1629))
397 rtlhal
->oem_id
= RT_CID_819x_HP
;
399 rtlhal
->oem_id
= RT_CID_DEFAULT
;
401 rtlhal
->oem_id
= RT_CID_DEFAULT
;
404 case EEPROM_CID_TOSHIBA
:
405 rtlhal
->oem_id
= RT_CID_TOSHIBA
;
408 rtlhal
->oem_id
= RT_CID_819x_QMI
;
410 case EEPROM_CID_WHQL
:
412 rtlhal
->oem_id
= RT_CID_DEFAULT
;
416 _rtl92cu_read_board_type(hw
, hwinfo
);
419 static void _rtl92cu_hal_customized_behavior(struct ieee80211_hw
*hw
)
421 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
422 struct rtl_usb_priv
*usb_priv
= rtl_usbpriv(hw
);
423 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
425 switch (rtlhal
->oem_id
) {
427 usb_priv
->ledctl
.led_opendrain
= true;
429 case RT_CID_819x_Lenovo
:
433 case RT_CID_819x_Acer
:
438 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "RT Customized ID: 0x%02X\n",
442 void rtl92cu_read_eeprom_info(struct ieee80211_hw
*hw
)
445 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
446 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
447 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
450 if (!IS_NORMAL_CHIP(rtlhal
->version
))
452 tmp_u1b
= rtl_read_byte(rtlpriv
, REG_9346CR
);
453 rtlefuse
->epromtype
= (tmp_u1b
& BOOT_FROM_EEPROM
) ?
454 EEPROM_93C46
: EEPROM_BOOT_EFUSE
;
455 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
, "Boot from %s\n",
456 tmp_u1b
& BOOT_FROM_EEPROM
? "EERROM" : "EFUSE");
457 rtlefuse
->autoload_failflag
= (tmp_u1b
& EEPROM_EN
) ? false : true;
458 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
, "Autoload %s\n",
459 tmp_u1b
& EEPROM_EN
? "OK!!" : "ERR!!");
460 _rtl92cu_read_adapter_info(hw
);
461 _rtl92cu_hal_customized_behavior(hw
);
465 static int _rtl92cu_init_power_on(struct ieee80211_hw
*hw
)
467 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
471 /* polling autoload done. */
472 u32 pollingCount
= 0;
475 if (rtl_read_byte(rtlpriv
, REG_APS_FSMCO
) & PFM_ALDN
) {
476 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
480 if (pollingCount
++ > 100) {
481 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
482 "Failed to polling REG_APS_FSMCO[PFM_ALDN] done!\n");
486 /* 0. RSV_CTRL 0x1C[7:0] = 0 unlock ISO/CLK/Power control register */
487 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0);
488 /* Power on when re-enter from IPS/Radio off/card disable */
489 /* enable SPS into PWM mode */
490 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x2b);
492 value8
= rtl_read_byte(rtlpriv
, REG_LDOV12D_CTRL
);
493 if (0 == (value8
& LDV12_EN
)) {
495 rtl_write_byte(rtlpriv
, REG_LDOV12D_CTRL
, value8
);
496 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_DMESG
,
497 " power-on :REG_LDOV12D_CTRL Reg0x21:0x%02x\n",
500 value8
= rtl_read_byte(rtlpriv
, REG_SYS_ISO_CTRL
);
501 value8
&= ~ISO_MD2PP
;
502 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, value8
);
504 /* auto enable WLAN */
506 value16
= rtl_read_word(rtlpriv
, REG_APS_FSMCO
);
507 value16
|= APFM_ONMAC
;
508 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, value16
);
510 if (!(rtl_read_word(rtlpriv
, REG_APS_FSMCO
) & APFM_ONMAC
)) {
511 pr_info("MAC auto ON okay!\n");
514 if (pollingCount
++ > 100) {
515 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
,
516 "Failed to polling REG_APS_FSMCO[APFM_ONMAC] done!\n");
520 /* Enable Radio ,GPIO ,and LED function */
521 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, 0x0812);
522 /* release RF digital isolation */
523 value16
= rtl_read_word(rtlpriv
, REG_SYS_ISO_CTRL
);
524 value16
&= ~ISO_DIOR
;
525 rtl_write_word(rtlpriv
, REG_SYS_ISO_CTRL
, value16
);
526 /* Reconsider when to do this operation after asking HWSD. */
528 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, (rtl_read_byte(rtlpriv
,
529 REG_APSD_CTRL
) & ~BIT(6)));
532 } while ((pollingCount
< 200) &&
533 (rtl_read_byte(rtlpriv
, REG_APSD_CTRL
) & BIT(7)));
534 /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */
535 value16
= rtl_read_word(rtlpriv
, REG_CR
);
536 value16
|= (HCI_TXDMA_EN
| HCI_RXDMA_EN
| TXDMA_EN
| RXDMA_EN
|
537 PROTOCOL_EN
| SCHEDULE_EN
| MACTXEN
| MACRXEN
| ENSEC
);
538 rtl_write_word(rtlpriv
, REG_CR
, value16
);
542 static void _rtl92cu_init_queue_reserved_page(struct ieee80211_hw
*hw
,
547 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
548 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
549 bool isChipN
= IS_NORMAL_CHIP(rtlhal
->version
);
550 u32 outEPNum
= (u32
)out_ep_num
;
557 u32 txQPageNum
, txQPageUnit
, txQRemainPage
;
560 numPubQ
= (isChipN
) ? CHIP_B_PAGE_NUM_PUBQ
:
561 CHIP_A_PAGE_NUM_PUBQ
;
562 txQPageNum
= TX_TOTAL_PAGE_NUMBER
- numPubQ
;
564 txQPageUnit
= txQPageNum
/outEPNum
;
565 txQRemainPage
= txQPageNum
% outEPNum
;
566 if (queue_sel
& TX_SELE_HQ
)
568 if (queue_sel
& TX_SELE_LQ
)
570 /* HIGH priority queue always present in the configuration of
571 * 2 out-ep. Remainder pages have assigned to High queue */
572 if ((outEPNum
> 1) && (txQRemainPage
))
573 numHQ
+= txQRemainPage
;
574 /* NOTE: This step done before writting REG_RQPN. */
576 if (queue_sel
& TX_SELE_NQ
)
578 value8
= (u8
)_NPQ(numNQ
);
579 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, value8
);
582 /* for WMM ,number of out-ep must more than or equal to 2! */
583 numPubQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_PUBQ
:
584 WMM_CHIP_A_PAGE_NUM_PUBQ
;
585 if (queue_sel
& TX_SELE_HQ
) {
586 numHQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_HPQ
:
587 WMM_CHIP_A_PAGE_NUM_HPQ
;
589 if (queue_sel
& TX_SELE_LQ
) {
590 numLQ
= isChipN
? WMM_CHIP_B_PAGE_NUM_LPQ
:
591 WMM_CHIP_A_PAGE_NUM_LPQ
;
593 /* NOTE: This step done before writting REG_RQPN. */
595 if (queue_sel
& TX_SELE_NQ
)
596 numNQ
= WMM_CHIP_B_PAGE_NUM_NPQ
;
597 value8
= (u8
)_NPQ(numNQ
);
598 rtl_write_byte(rtlpriv
, REG_RQPN_NPQ
, value8
);
602 value32
= _HPQ(numHQ
) | _LPQ(numLQ
) | _PUBQ(numPubQ
) | LD_RQPN
;
603 rtl_write_dword(rtlpriv
, REG_RQPN
, value32
);
606 static void _rtl92c_init_trx_buffer(struct ieee80211_hw
*hw
, bool wmm_enable
)
608 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
609 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
614 txpktbuf_bndy
= TX_PAGE_BOUNDARY
;
616 txpktbuf_bndy
= (IS_NORMAL_CHIP(rtlhal
->version
))
617 ? WMM_CHIP_B_TX_PAGE_BOUNDARY
618 : WMM_CHIP_A_TX_PAGE_BOUNDARY
;
619 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_BCNQ_BDNY
, txpktbuf_bndy
);
620 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_MGQ_BDNY
, txpktbuf_bndy
);
621 rtl_write_byte(rtlpriv
, REG_TXPKTBUF_WMAC_LBK_BF_HD
, txpktbuf_bndy
);
622 rtl_write_byte(rtlpriv
, REG_TRXFF_BNDY
, txpktbuf_bndy
);
623 rtl_write_byte(rtlpriv
, REG_TDECTRL
+1, txpktbuf_bndy
);
624 rtl_write_word(rtlpriv
, (REG_TRXFF_BNDY
+ 2), 0x27FF);
625 value8
= _PSRX(RX_PAGE_SIZE_REG_VALUE
) | _PSTX(PBP_128
);
626 rtl_write_byte(rtlpriv
, REG_PBP
, value8
);
629 static void _rtl92c_init_chipN_reg_priority(struct ieee80211_hw
*hw
, u16 beQ
,
630 u16 bkQ
, u16 viQ
, u16 voQ
,
633 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
634 u16 value16
= (rtl_read_word(rtlpriv
, REG_TRXDMA_CTRL
) & 0x7);
636 value16
|= _TXDMA_BEQ_MAP(beQ
) | _TXDMA_BKQ_MAP(bkQ
) |
637 _TXDMA_VIQ_MAP(viQ
) | _TXDMA_VOQ_MAP(voQ
) |
638 _TXDMA_MGQ_MAP(mgtQ
) | _TXDMA_HIQ_MAP(hiQ
);
639 rtl_write_word(rtlpriv
, REG_TRXDMA_CTRL
, value16
);
642 static void _rtl92cu_init_chipN_one_out_ep_priority(struct ieee80211_hw
*hw
,
646 u16
uninitialized_var(value
);
656 value
= QUEUE_NORMAL
;
659 WARN_ON(1); /* Shall not reach here! */
662 _rtl92c_init_chipN_reg_priority(hw
, value
, value
, value
, value
,
664 pr_info("Tx queue select: 0x%02x\n", queue_sel
);
667 static void _rtl92cu_init_chipN_two_out_ep_priority(struct ieee80211_hw
*hw
,
671 u16 beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
;
672 u16
uninitialized_var(valueHi
);
673 u16
uninitialized_var(valueLow
);
676 case (TX_SELE_HQ
| TX_SELE_LQ
):
677 valueHi
= QUEUE_HIGH
;
678 valueLow
= QUEUE_LOW
;
680 case (TX_SELE_NQ
| TX_SELE_LQ
):
681 valueHi
= QUEUE_NORMAL
;
682 valueLow
= QUEUE_LOW
;
684 case (TX_SELE_HQ
| TX_SELE_NQ
):
685 valueHi
= QUEUE_HIGH
;
686 valueLow
= QUEUE_NORMAL
;
699 } else {/* for WMM ,CONFIG_OUT_EP_WIFI_MODE */
707 _rtl92c_init_chipN_reg_priority(hw
, beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
);
708 pr_info("Tx queue select: 0x%02x\n", queue_sel
);
711 static void _rtl92cu_init_chipN_three_out_ep_priority(struct ieee80211_hw
*hw
,
715 u16 beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
;
716 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
718 if (!wmm_enable
) { /* typical setting */
725 } else { /* for WMM */
733 _rtl92c_init_chipN_reg_priority(hw
, beQ
, bkQ
, viQ
, voQ
, mgtQ
, hiQ
);
734 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
, "Tx queue select :0x%02x..\n",
738 static void _rtl92cu_init_chipN_queue_priority(struct ieee80211_hw
*hw
,
743 switch (out_ep_num
) {
745 _rtl92cu_init_chipN_one_out_ep_priority(hw
, wmm_enable
,
749 _rtl92cu_init_chipN_two_out_ep_priority(hw
, wmm_enable
,
753 _rtl92cu_init_chipN_three_out_ep_priority(hw
, wmm_enable
,
757 WARN_ON(1); /* Shall not reach here! */
762 static void _rtl92cu_init_chipT_queue_priority(struct ieee80211_hw
*hw
,
768 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
770 switch (out_ep_num
) {
771 case 2: /* (TX_SELE_HQ|TX_SELE_LQ) */
772 if (!wmm_enable
) /* typical setting */
773 hq_sele
= HQSEL_VOQ
| HQSEL_VIQ
| HQSEL_MGTQ
|
776 hq_sele
= HQSEL_VOQ
| HQSEL_BEQ
| HQSEL_MGTQ
|
780 if (TX_SELE_LQ
== queue_sel
) {
781 /* map all endpoint to Low queue */
783 } else if (TX_SELE_HQ
== queue_sel
) {
784 /* map all endpoint to High queue */
785 hq_sele
= HQSEL_VOQ
| HQSEL_VIQ
| HQSEL_BEQ
|
786 HQSEL_BKQ
| HQSEL_MGTQ
| HQSEL_HIQ
;
790 WARN_ON(1); /* Shall not reach here! */
793 rtl_write_byte(rtlpriv
, (REG_TRXDMA_CTRL
+1), hq_sele
);
794 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_EMERG
, "Tx queue select :0x%02x..\n",
798 static void _rtl92cu_init_queue_priority(struct ieee80211_hw
*hw
,
803 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
804 if (IS_NORMAL_CHIP(rtlhal
->version
))
805 _rtl92cu_init_chipN_queue_priority(hw
, wmm_enable
, out_ep_num
,
808 _rtl92cu_init_chipT_queue_priority(hw
, wmm_enable
, out_ep_num
,
812 static void _rtl92cu_init_usb_aggregation(struct ieee80211_hw
*hw
)
816 static void _rtl92cu_init_wmac_setting(struct ieee80211_hw
*hw
)
820 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
821 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
823 mac
->rx_conf
= (RCR_APM
| RCR_AM
| RCR_ADF
| RCR_AB
| RCR_APPFCS
|
824 RCR_APP_ICV
| RCR_AMF
| RCR_HTC_LOC_CTRL
|
825 RCR_APP_MIC
| RCR_APP_PHYSTS
| RCR_ACRC32
);
826 rtl_write_dword(rtlpriv
, REG_RCR
, mac
->rx_conf
);
827 /* Accept all multicast address */
828 rtl_write_dword(rtlpriv
, REG_MAR
, 0xFFFFFFFF);
829 rtl_write_dword(rtlpriv
, REG_MAR
+ 4, 0xFFFFFFFF);
830 /* Accept all management frames */
832 rtl92c_set_mgt_filter(hw
, value16
);
833 /* Reject all control frame - default value is 0 */
834 rtl92c_set_ctrl_filter(hw
, 0x0);
835 /* Accept all data frames */
837 rtl92c_set_data_filter(hw
, value16
);
840 static int _rtl92cu_init_mac(struct ieee80211_hw
*hw
)
842 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
843 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
844 struct rtl_usb_priv
*usb_priv
= rtl_usbpriv(hw
);
845 struct rtl_usb
*rtlusb
= rtl_usbdev(usb_priv
);
848 u8 wmm_enable
= false; /* TODO */
849 u8 out_ep_nums
= rtlusb
->out_ep_nums
;
850 u8 queue_sel
= rtlusb
->out_queue_sel
;
851 err
= _rtl92cu_init_power_on(hw
);
854 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
855 "Failed to init power on!\n");
859 boundary
= TX_PAGE_BOUNDARY
;
860 } else { /* for WMM */
861 boundary
= (IS_NORMAL_CHIP(rtlhal
->version
))
862 ? WMM_CHIP_B_TX_PAGE_BOUNDARY
863 : WMM_CHIP_A_TX_PAGE_BOUNDARY
;
865 if (false == rtl92c_init_llt_table(hw
, boundary
)) {
866 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
867 "Failed to init LLT Table!\n");
870 _rtl92cu_init_queue_reserved_page(hw
, wmm_enable
, out_ep_nums
,
872 _rtl92c_init_trx_buffer(hw
, wmm_enable
);
873 _rtl92cu_init_queue_priority(hw
, wmm_enable
, out_ep_nums
,
875 /* Get Rx PHY status in order to report RSSI and others. */
876 rtl92c_init_driver_info_size(hw
, RTL92C_DRIVER_INFO_SIZE
);
877 rtl92c_init_interrupt(hw
);
878 rtl92c_init_network_type(hw
);
879 _rtl92cu_init_wmac_setting(hw
);
880 rtl92c_init_adaptive_ctrl(hw
);
881 rtl92c_init_edca(hw
);
882 rtl92c_init_rate_fallback(hw
);
883 rtl92c_init_retry_function(hw
);
884 _rtl92cu_init_usb_aggregation(hw
);
885 rtlpriv
->cfg
->ops
->set_bw_mode(hw
, NL80211_CHAN_HT20
);
886 rtl92c_set_min_space(hw
, IS_92C_SERIAL(rtlhal
->version
));
887 rtl92c_init_beacon_parameters(hw
, rtlhal
->version
);
888 rtl92c_init_ampdu_aggregation(hw
);
889 rtl92c_init_beacon_max_error(hw
, true);
893 void rtl92cu_enable_hw_security_config(struct ieee80211_hw
*hw
)
895 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
896 u8 sec_reg_value
= 0x0;
897 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
899 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_LOUD
,
900 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
901 rtlpriv
->sec
.pairwise_enc_algorithm
,
902 rtlpriv
->sec
.group_enc_algorithm
);
903 if (rtlpriv
->cfg
->mod_params
->sw_crypto
|| rtlpriv
->sec
.use_sw_sec
) {
904 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_DMESG
,
905 "not open sw encryption\n");
908 sec_reg_value
= SCR_TxEncEnable
| SCR_RxDecEnable
;
909 if (rtlpriv
->sec
.use_defaultkey
) {
910 sec_reg_value
|= SCR_TxUseDK
;
911 sec_reg_value
|= SCR_RxUseDK
;
913 if (IS_NORMAL_CHIP(rtlhal
->version
))
914 sec_reg_value
|= (SCR_RXBCUSEDK
| SCR_TXBCUSEDK
);
915 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
916 RT_TRACE(rtlpriv
, COMP_SEC
, DBG_LOUD
, "The SECR-value %x\n",
918 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_WPA_CONFIG
, &sec_reg_value
);
921 static void _rtl92cu_hw_configure(struct ieee80211_hw
*hw
)
923 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
924 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
926 /* To Fix MAC loopback mode fail. */
927 rtl_write_byte(rtlpriv
, REG_LDOHCI12_CTRL
, 0x0f);
928 rtl_write_byte(rtlpriv
, 0x15, 0xe9);
930 /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */
931 rtl_write_byte(rtlpriv
, REG_HWSEQ_CTRL
, 0xFF);
932 /* fixed USB interface interference issue */
933 rtl_write_byte(rtlpriv
, 0xfe40, 0xe0);
934 rtl_write_byte(rtlpriv
, 0xfe41, 0x8d);
935 rtl_write_byte(rtlpriv
, 0xfe42, 0x80);
936 rtlusb
->reg_bcn_ctrl_val
= 0x18;
937 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
)rtlusb
->reg_bcn_ctrl_val
);
940 static void _InitPABias(struct ieee80211_hw
*hw
)
942 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
943 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
946 /* FIXED PA current issue */
947 pa_setting
= efuse_read_1byte(hw
, 0x1FA);
948 if (!(pa_setting
& BIT(0))) {
949 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x0F406);
950 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x4F406);
951 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0x8F406);
952 rtl_set_rfreg(hw
, RF90_PATH_A
, 0x15, 0x0FFFFF, 0xCF406);
954 if (!(pa_setting
& BIT(1)) && IS_NORMAL_CHIP(rtlhal
->version
) &&
955 IS_92C_SERIAL(rtlhal
->version
)) {
956 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x0F406);
957 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x4F406);
958 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0x8F406);
959 rtl_set_rfreg(hw
, RF90_PATH_B
, 0x15, 0x0FFFFF, 0xCF406);
961 if (!(pa_setting
& BIT(4))) {
962 pa_setting
= rtl_read_byte(rtlpriv
, 0x16);
964 rtl_write_byte(rtlpriv
, 0x16, pa_setting
| 0x90);
968 static void _update_mac_setting(struct ieee80211_hw
*hw
)
970 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
971 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
973 mac
->rx_conf
= rtl_read_dword(rtlpriv
, REG_RCR
);
974 mac
->rx_mgt_filter
= rtl_read_word(rtlpriv
, REG_RXFLTMAP0
);
975 mac
->rx_ctrl_filter
= rtl_read_word(rtlpriv
, REG_RXFLTMAP1
);
976 mac
->rx_data_filter
= rtl_read_word(rtlpriv
, REG_RXFLTMAP2
);
979 int rtl92cu_hw_init(struct ieee80211_hw
*hw
)
981 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
982 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
983 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
984 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
985 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
987 static bool iqk_initialized
;
990 /* As this function can take a very long time (up to 350 ms)
991 * and can be called with irqs disabled, reenable the irqs
992 * to let the other devices continue being serviced.
994 * It is safe doing so since our own interrupts will only be enabled
995 * in a subsequent step.
997 local_save_flags(flags
);
1000 rtlhal
->hw_type
= HARDWARE_TYPE_RTL8192CU
;
1001 err
= _rtl92cu_init_mac(hw
);
1003 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
, "init mac failed!\n");
1006 err
= rtl92c_download_fw(hw
);
1008 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1009 "Failed to download FW. Init HW without FW now..\n");
1013 rtlhal
->last_hmeboxnum
= 0; /* h2c */
1014 _rtl92cu_phy_param_tab_init(hw
);
1015 rtl92cu_phy_mac_config(hw
);
1016 rtl92cu_phy_bb_config(hw
);
1017 rtlphy
->rf_mode
= RF_OP_BY_SW_3WIRE
;
1018 rtl92c_phy_rf_config(hw
);
1019 if (IS_VENDOR_UMC_A_CUT(rtlhal
->version
) &&
1020 !IS_92C_SERIAL(rtlhal
->version
)) {
1021 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G1
, MASKDWORD
, 0x30255);
1022 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_RX_G2
, MASKDWORD
, 0x50a00);
1024 rtlphy
->rfreg_chnlval
[0] = rtl_get_rfreg(hw
, (enum radio_path
)0,
1025 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1026 rtlphy
->rfreg_chnlval
[1] = rtl_get_rfreg(hw
, (enum radio_path
)1,
1027 RF_CHNLBW
, RFREG_OFFSET_MASK
);
1028 rtl92cu_bb_block_on(hw
);
1029 rtl_cam_reset_all_entry(hw
);
1030 rtl92cu_enable_hw_security_config(hw
);
1031 ppsc
->rfpwr_state
= ERFON
;
1032 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_ETHER_ADDR
, mac
->mac_addr
);
1033 if (ppsc
->rfpwr_state
== ERFON
) {
1034 rtl92c_phy_set_rfpath_switch(hw
, 1);
1035 if (iqk_initialized
) {
1036 rtl92c_phy_iq_calibrate(hw
, false);
1038 rtl92c_phy_iq_calibrate(hw
, false);
1039 iqk_initialized
= true;
1041 rtl92c_dm_check_txpower_tracking(hw
);
1042 rtl92c_phy_lc_calibrate(hw
);
1044 _rtl92cu_hw_configure(hw
);
1046 _update_mac_setting(hw
);
1049 local_irq_restore(flags
);
1053 static void _DisableRFAFEAndResetBB(struct ieee80211_hw
*hw
)
1055 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1056 /**************************************
1057 a. TXPAUSE 0x522[7:0] = 0xFF Pause MAC TX queue
1058 b. RF path 0 offset 0x00 = 0x00 disable RF
1059 c. APSD_CTRL 0x600[7:0] = 0x40
1060 d. SYS_FUNC_EN 0x02[7:0] = 0x16 reset BB state machine
1061 e. SYS_FUNC_EN 0x02[7:0] = 0x14 reset BB state machine
1062 ***************************************/
1063 u8 eRFPath
= 0, value8
= 0;
1064 rtl_write_byte(rtlpriv
, REG_TXPAUSE
, 0xFF);
1065 rtl_set_rfreg(hw
, (enum radio_path
)eRFPath
, 0x0, MASKBYTE0
, 0x0);
1068 rtl_write_byte(rtlpriv
, REG_APSD_CTRL
, value8
); /*0x40*/
1070 value8
|= (FEN_USBD
| FEN_USBA
| FEN_BB_GLB_RSTn
);
1071 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, value8
);/*0x16*/
1072 value8
&= (~FEN_BB_GLB_RSTn
);
1073 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
, value8
); /*0x14*/
1076 static void _ResetDigitalProcedure1(struct ieee80211_hw
*hw
, bool bWithoutHWSM
)
1078 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1079 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1081 if (rtlhal
->fw_version
<= 0x20) {
1082 /*****************************
1083 f. MCUFWDL 0x80[7:0]=0 reset MCU ready status
1084 g. SYS_FUNC_EN 0x02[10]= 0 reset MCU reg, (8051 reset)
1085 h. SYS_FUNC_EN 0x02[15-12]= 5 reset MAC reg, DCORE
1086 i. SYS_FUNC_EN 0x02[10]= 1 enable MCU reg, (8051 enable)
1087 ******************************/
1090 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1091 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1092 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
&
1093 (~FEN_CPUEN
))); /* reset MCU ,8051 */
1094 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
)&0x0FFF;
1095 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
|
1096 (FEN_HWPDN
|FEN_ELDR
))); /* reset MAC */
1097 valu16
= rtl_read_word(rtlpriv
, REG_SYS_FUNC_EN
);
1098 rtl_write_word(rtlpriv
, REG_SYS_FUNC_EN
, (valu16
|
1099 FEN_CPUEN
)); /* enable MCU ,8051 */
1103 /* IF fw in RAM code, do reset */
1104 if (rtl_read_byte(rtlpriv
, REG_MCUFWDL
) & BIT(1)) {
1105 /* reset MCU ready status */
1106 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1107 /* 8051 reset by self */
1108 rtl_write_byte(rtlpriv
, REG_HMETFR
+3, 0x20);
1109 while ((retry_cnts
++ < 100) &&
1110 (FEN_CPUEN
& rtl_read_word(rtlpriv
,
1111 REG_SYS_FUNC_EN
))) {
1114 if (retry_cnts
>= 100) {
1115 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1116 "#####=> 8051 reset failed!.........................\n");
1117 /* if 8051 reset fail, reset MAC. */
1118 rtl_write_byte(rtlpriv
,
1119 REG_SYS_FUNC_EN
+ 1,
1124 /* Reset MAC and Enable 8051 */
1125 rtl_write_byte(rtlpriv
, REG_SYS_FUNC_EN
+ 1, 0x54);
1126 rtl_write_byte(rtlpriv
, REG_MCUFWDL
, 0);
1129 /*****************************
1130 Without HW auto state machine
1131 g.SYS_CLKR 0x08[15:0] = 0x30A3 disable MAC clock
1132 h.AFE_PLL_CTRL 0x28[7:0] = 0x80 disable AFE PLL
1133 i.AFE_XTAL_CTRL 0x24[15:0] = 0x880F gated AFE DIG_CLOCK
1134 j.SYS_ISu_CTRL 0x00[7:0] = 0xF9 isolated digital to PON
1135 ******************************/
1136 rtl_write_word(rtlpriv
, REG_SYS_CLKR
, 0x70A3);
1137 rtl_write_byte(rtlpriv
, REG_AFE_PLL_CTRL
, 0x80);
1138 rtl_write_word(rtlpriv
, REG_AFE_XTAL_CTRL
, 0x880F);
1139 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
, 0xF9);
1143 static void _ResetDigitalProcedure2(struct ieee80211_hw
*hw
)
1145 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1146 /*****************************
1147 k. SYS_FUNC_EN 0x03[7:0] = 0x44 disable ELDR runction
1148 l. SYS_CLKR 0x08[15:0] = 0x3083 disable ELDR clock
1149 m. SYS_ISO_CTRL 0x01[7:0] = 0x83 isolated ELDR to PON
1150 ******************************/
1151 rtl_write_word(rtlpriv
, REG_SYS_CLKR
, 0x70A3);
1152 rtl_write_byte(rtlpriv
, REG_SYS_ISO_CTRL
+1, 0x82);
1155 static void _DisableGPIO(struct ieee80211_hw
*hw
)
1157 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1158 /***************************************
1159 j. GPIO_PIN_CTRL 0x44[31:0]=0x000
1160 k. Value = GPIO_PIN_CTRL[7:0]
1161 l. GPIO_PIN_CTRL 0x44[31:0] = 0x00FF0000 | (value <<8); write ext PIN level
1162 m. GPIO_MUXCFG 0x42 [15:0] = 0x0780
1163 n. LEDCFG 0x4C[15:0] = 0x8080
1164 ***************************************/
1169 /* 1. Disable GPIO[7:0] */
1170 rtl_write_word(rtlpriv
, REG_GPIO_PIN_CTRL
+2, 0x0000);
1171 value32
= rtl_read_dword(rtlpriv
, REG_GPIO_PIN_CTRL
) & 0xFFFF00FF;
1172 value8
= (u8
) (value32
&0x000000FF);
1173 value32
|= ((value8
<<8) | 0x00FF0000);
1174 rtl_write_dword(rtlpriv
, REG_GPIO_PIN_CTRL
, value32
);
1175 /* 2. Disable GPIO[10:8] */
1176 rtl_write_byte(rtlpriv
, REG_GPIO_MUXCFG
+3, 0x00);
1177 value16
= rtl_read_word(rtlpriv
, REG_GPIO_MUXCFG
+2) & 0xFF0F;
1178 value8
= (u8
) (value16
&0x000F);
1179 value16
|= ((value8
<<4) | 0x0780);
1180 rtl_write_word(rtlpriv
, REG_GPIO_PIN_CTRL
+2, value16
);
1181 /* 3. Disable LED0 & 1 */
1182 rtl_write_word(rtlpriv
, REG_LEDCFG0
, 0x8080);
1185 static void _DisableAnalog(struct ieee80211_hw
*hw
, bool bWithoutHWSM
)
1187 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1192 /*****************************
1193 n. LDOA15_CTRL 0x20[7:0] = 0x04 disable A15 power
1194 o. LDOV12D_CTRL 0x21[7:0] = 0x54 disable digital core power
1195 r. When driver call disable, the ASIC will turn off remaining
1197 ******************************/
1198 rtl_write_byte(rtlpriv
, REG_LDOA15_CTRL
, 0x04);
1199 value8
= rtl_read_byte(rtlpriv
, REG_LDOV12D_CTRL
);
1200 value8
&= (~LDV12_EN
);
1201 rtl_write_byte(rtlpriv
, REG_LDOV12D_CTRL
, value8
);
1204 /*****************************
1205 h. SPS0_CTRL 0x11[7:0] = 0x23 enter PFM mode
1206 i. APS_FSMCO 0x04[15:0] = 0x4802 set USB suspend
1207 ******************************/
1208 rtl_write_byte(rtlpriv
, REG_SPS0_CTRL
, 0x23);
1209 value16
|= (APDM_HOST
| AFSM_HSUS
| PFM_ALDN
);
1210 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, (u16
)value16
);
1211 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0E);
1214 static void _CardDisableHWSM(struct ieee80211_hw
*hw
)
1216 /* ==== RF Off Sequence ==== */
1217 _DisableRFAFEAndResetBB(hw
);
1218 /* ==== Reset digital sequence ====== */
1219 _ResetDigitalProcedure1(hw
, false);
1220 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1222 /* ==== Disable analog sequence === */
1223 _DisableAnalog(hw
, false);
1226 static void _CardDisableWithoutHWSM(struct ieee80211_hw
*hw
)
1228 /*==== RF Off Sequence ==== */
1229 _DisableRFAFEAndResetBB(hw
);
1230 /* ==== Reset digital sequence ====== */
1231 _ResetDigitalProcedure1(hw
, true);
1232 /* ==== Pull GPIO PIN to balance level and LED control ====== */
1234 /* ==== Reset digital sequence ====== */
1235 _ResetDigitalProcedure2(hw
);
1236 /* ==== Disable analog sequence === */
1237 _DisableAnalog(hw
, true);
1240 static void _rtl92cu_set_bcn_ctrl_reg(struct ieee80211_hw
*hw
,
1241 u8 set_bits
, u8 clear_bits
)
1243 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1244 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1246 rtlusb
->reg_bcn_ctrl_val
|= set_bits
;
1247 rtlusb
->reg_bcn_ctrl_val
&= ~clear_bits
;
1248 rtl_write_byte(rtlpriv
, REG_BCN_CTRL
, (u8
) rtlusb
->reg_bcn_ctrl_val
);
1251 static void _rtl92cu_stop_tx_beacon(struct ieee80211_hw
*hw
)
1253 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1254 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1256 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1257 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
1258 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1259 tmp1byte
& (~BIT(6)));
1260 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0x64);
1261 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
1262 tmp1byte
&= ~(BIT(0));
1263 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
1265 rtl_write_byte(rtlpriv
, REG_TXPAUSE
,
1266 rtl_read_byte(rtlpriv
, REG_TXPAUSE
) | BIT(6));
1270 static void _rtl92cu_resume_tx_beacon(struct ieee80211_hw
*hw
)
1272 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1273 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1276 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1277 tmp1byte
= rtl_read_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2);
1278 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1280 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 1, 0xff);
1281 tmp1byte
= rtl_read_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2);
1283 rtl_write_byte(rtlpriv
, REG_TBTT_PROHIBIT
+ 2, tmp1byte
);
1285 rtl_write_byte(rtlpriv
, REG_TXPAUSE
,
1286 rtl_read_byte(rtlpriv
, REG_TXPAUSE
) & (~BIT(6)));
1290 static void _rtl92cu_enable_bcn_sub_func(struct ieee80211_hw
*hw
)
1292 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1293 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1295 if (IS_NORMAL_CHIP(rtlhal
->version
))
1296 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(1));
1298 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1301 static void _rtl92cu_disable_bcn_sub_func(struct ieee80211_hw
*hw
)
1303 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1304 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1306 if (IS_NORMAL_CHIP(rtlhal
->version
))
1307 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(1), 0);
1309 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1312 static int _rtl92cu_set_media_status(struct ieee80211_hw
*hw
,
1313 enum nl80211_iftype type
)
1315 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1316 u8 bt_msr
= rtl_read_byte(rtlpriv
, MSR
);
1317 enum led_ctl_mode ledaction
= LED_CTL_NO_LINK
;
1320 rtl_write_byte(rtlpriv
, REG_BCN_MAX_ERR
, 0xFF);
1321 if (type
== NL80211_IFTYPE_UNSPECIFIED
|| type
==
1322 NL80211_IFTYPE_STATION
) {
1323 _rtl92cu_stop_tx_beacon(hw
);
1324 _rtl92cu_enable_bcn_sub_func(hw
);
1325 } else if (type
== NL80211_IFTYPE_ADHOC
|| type
== NL80211_IFTYPE_AP
) {
1326 _rtl92cu_resume_tx_beacon(hw
);
1327 _rtl92cu_disable_bcn_sub_func(hw
);
1329 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1330 "Set HW_VAR_MEDIA_STATUS:No such media status(%x)\n",
1334 case NL80211_IFTYPE_UNSPECIFIED
:
1335 bt_msr
|= MSR_NOLINK
;
1336 ledaction
= LED_CTL_LINK
;
1337 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1338 "Set Network type to NO LINK!\n");
1340 case NL80211_IFTYPE_ADHOC
:
1341 bt_msr
|= MSR_ADHOC
;
1342 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1343 "Set Network type to Ad Hoc!\n");
1345 case NL80211_IFTYPE_STATION
:
1346 bt_msr
|= MSR_INFRA
;
1347 ledaction
= LED_CTL_LINK
;
1348 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1349 "Set Network type to STA!\n");
1351 case NL80211_IFTYPE_AP
:
1353 RT_TRACE(rtlpriv
, COMP_INIT
, DBG_TRACE
,
1354 "Set Network type to AP!\n");
1357 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1358 "Network type %d not supported!\n", type
);
1361 rtl_write_byte(rtlpriv
, (MSR
), bt_msr
);
1362 rtlpriv
->cfg
->ops
->led_control(hw
, ledaction
);
1363 if ((bt_msr
& 0xfc) == MSR_AP
)
1364 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x00);
1366 rtl_write_byte(rtlpriv
, REG_BCNTCFG
+ 1, 0x66);
1372 void rtl92cu_card_disable(struct ieee80211_hw
*hw
)
1374 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1375 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1376 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1377 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1378 enum nl80211_iftype opmode
;
1380 mac
->link_state
= MAC80211_NOLINK
;
1381 opmode
= NL80211_IFTYPE_UNSPECIFIED
;
1382 _rtl92cu_set_media_status(hw
, opmode
);
1383 rtlpriv
->cfg
->ops
->led_control(hw
, LED_CTL_POWER_OFF
);
1384 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_HALT_NIC
);
1385 if (rtlusb
->disableHWSM
)
1386 _CardDisableHWSM(hw
);
1388 _CardDisableWithoutHWSM(hw
);
1391 void rtl92cu_set_check_bssid(struct ieee80211_hw
*hw
, bool check_bssid
)
1393 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1394 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1395 u32 reg_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
1397 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
1402 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1403 reg_rcr
|= (RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1406 reg_rcr
|= RCR_CBSSID
;
1407 tmp
= BIT(4) | BIT(5);
1409 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_RCR
,
1411 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, tmp
);
1414 if (IS_NORMAL_CHIP(rtlhal
->version
)) {
1415 reg_rcr
&= ~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
);
1418 reg_rcr
&= ~RCR_CBSSID
;
1419 tmp
= BIT(4) | BIT(5);
1421 reg_rcr
&= (~(RCR_CBSSID_DATA
| RCR_CBSSID_BCN
));
1422 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1423 HW_VAR_RCR
, (u8
*) (®_rcr
));
1424 _rtl92cu_set_bcn_ctrl_reg(hw
, tmp
, 0);
1428 /*========================================================================== */
1430 int rtl92cu_set_network_type(struct ieee80211_hw
*hw
, enum nl80211_iftype type
)
1432 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1434 if (_rtl92cu_set_media_status(hw
, type
))
1437 if (rtlpriv
->mac80211
.link_state
== MAC80211_LINKED
) {
1438 if (type
!= NL80211_IFTYPE_AP
)
1439 rtl92cu_set_check_bssid(hw
, true);
1441 rtl92cu_set_check_bssid(hw
, false);
1447 static void _InitBeaconParameters(struct ieee80211_hw
*hw
)
1449 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1450 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
1452 rtl_write_word(rtlpriv
, REG_BCN_CTRL
, 0x1010);
1454 /* TODO: Remove these magic number */
1455 rtl_write_word(rtlpriv
, REG_TBTT_PROHIBIT
, 0x6404);
1456 rtl_write_byte(rtlpriv
, REG_DRVERLYINT
, DRIVER_EARLY_INT_TIME
);
1457 rtl_write_byte(rtlpriv
, REG_BCNDMATIM
, BCN_DMA_ATIME_INT_TIME
);
1458 /* Change beacon AIFS to the largest number
1459 * beacause test chip does not contension before sending beacon. */
1460 if (IS_NORMAL_CHIP(rtlhal
->version
))
1461 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x660F);
1463 rtl_write_word(rtlpriv
, REG_BCNTCFG
, 0x66FF);
1466 static void _beacon_function_enable(struct ieee80211_hw
*hw
, bool Enable
,
1469 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1471 _rtl92cu_set_bcn_ctrl_reg(hw
, (BIT(4) | BIT(3) | BIT(1)), 0x00);
1472 rtl_write_byte(rtlpriv
, REG_RD_CTRL
+1, 0x6F);
1475 void rtl92cu_set_beacon_related_registers(struct ieee80211_hw
*hw
)
1478 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1479 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1480 u16 bcn_interval
, atim_window
;
1483 bcn_interval
= mac
->beacon_interval
;
1484 atim_window
= 2; /*FIX MERGE */
1485 rtl_write_word(rtlpriv
, REG_ATIMWND
, atim_window
);
1486 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1487 _InitBeaconParameters(hw
);
1488 rtl_write_byte(rtlpriv
, REG_SLOT
, 0x09);
1490 * Force beacon frame transmission even after receiving beacon frame
1491 * from other ad hoc STA
1494 * Reset TSF Timer to zero, added by Roger. 2008.06.24
1496 value32
= rtl_read_dword(rtlpriv
, REG_TCR
);
1498 rtl_write_dword(rtlpriv
, REG_TCR
, value32
);
1500 rtl_write_dword(rtlpriv
, REG_TCR
, value32
);
1501 RT_TRACE(rtlpriv
, COMP_INIT
|COMP_BEACON
, DBG_LOUD
,
1502 "SetBeaconRelatedRegisters8192CUsb(): Set TCR(%x)\n",
1504 /* TODO: Modify later (Find the right parameters)
1505 * NOTE: Fix test chip's bug (about contention windows's randomness) */
1506 if ((mac
->opmode
== NL80211_IFTYPE_ADHOC
) ||
1507 (mac
->opmode
== NL80211_IFTYPE_AP
)) {
1508 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_CCK
, 0x50);
1509 rtl_write_byte(rtlpriv
, REG_RXTSF_OFFSET_OFDM
, 0x50);
1511 _beacon_function_enable(hw
, true, true);
1514 void rtl92cu_set_beacon_interval(struct ieee80211_hw
*hw
)
1516 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1517 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1518 u16 bcn_interval
= mac
->beacon_interval
;
1520 RT_TRACE(rtlpriv
, COMP_BEACON
, DBG_DMESG
, "beacon_interval:%d\n",
1522 rtl_write_word(rtlpriv
, REG_BCN_INTERVAL
, bcn_interval
);
1525 void rtl92cu_update_interrupt_mask(struct ieee80211_hw
*hw
,
1526 u32 add_msr
, u32 rm_msr
)
1530 void rtl92cu_get_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
1532 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1533 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1534 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1538 *((u32
*)(val
)) = mac
->rx_conf
;
1540 case HW_VAR_RF_STATE
:
1541 *((enum rf_pwrstate
*)(val
)) = ppsc
->rfpwr_state
;
1543 case HW_VAR_FWLPS_RF_ON
:{
1544 enum rf_pwrstate rfState
;
1547 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_RF_STATE
,
1549 if (rfState
== ERFOFF
) {
1550 *((bool *) (val
)) = true;
1552 val_rcr
= rtl_read_dword(rtlpriv
, REG_RCR
);
1553 val_rcr
&= 0x00070000;
1555 *((bool *) (val
)) = false;
1557 *((bool *) (val
)) = true;
1561 case HW_VAR_FW_PSMODE_STATUS
:
1562 *((bool *) (val
)) = ppsc
->fw_current_inpsmode
;
1564 case HW_VAR_CORRECT_TSF
:{
1566 u32
*ptsf_low
= (u32
*)&tsf
;
1567 u32
*ptsf_high
= ((u32
*)&tsf
) + 1;
1569 *ptsf_high
= rtl_read_dword(rtlpriv
, (REG_TSFTR
+ 4));
1570 *ptsf_low
= rtl_read_dword(rtlpriv
, REG_TSFTR
);
1571 *((u64
*)(val
)) = tsf
;
1574 case HW_VAR_MGT_FILTER
:
1575 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP0
);
1577 case HW_VAR_CTRL_FILTER
:
1578 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP1
);
1580 case HW_VAR_DATA_FILTER
:
1581 *((u16
*) (val
)) = rtl_read_word(rtlpriv
, REG_RXFLTMAP2
);
1584 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1585 "switch case not processed\n");
1590 void rtl92cu_set_hw_reg(struct ieee80211_hw
*hw
, u8 variable
, u8
*val
)
1592 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1593 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1594 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1595 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
1596 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1597 struct rtl_usb
*rtlusb
= rtl_usbdev(rtl_usbpriv(hw
));
1598 enum wireless_mode wirelessmode
= mac
->mode
;
1602 case HW_VAR_ETHER_ADDR
:{
1603 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
1604 rtl_write_byte(rtlpriv
, (REG_MACID
+ idx
),
1609 case HW_VAR_BASIC_RATE
:{
1610 u16 rate_cfg
= ((u16
*) val
)[0];
1615 /* if (mac->current_network.vender == HT_IOT_PEER_CISCO
1616 * && ((rate_cfg & 0x150) == 0)) {
1617 * rate_cfg |= 0x010;
1620 rtl_write_byte(rtlpriv
, REG_RRSR
, rate_cfg
& 0xff);
1621 rtl_write_byte(rtlpriv
, REG_RRSR
+ 1,
1622 (rate_cfg
>> 8) & 0xff);
1623 while (rate_cfg
> 0x1) {
1627 rtl_write_byte(rtlpriv
, REG_INIRTS_RATE_SEL
,
1632 for (idx
= 0; idx
< ETH_ALEN
; idx
++) {
1633 rtl_write_byte(rtlpriv
, (REG_BSSID
+ idx
),
1639 rtl_write_byte(rtlpriv
, REG_SIFS_CCK
+ 1, val
[0]);
1640 rtl_write_byte(rtlpriv
, REG_SIFS_OFDM
+ 1, val
[1]);
1641 rtl_write_byte(rtlpriv
, REG_SPEC_SIFS
+ 1, val
[0]);
1642 rtl_write_byte(rtlpriv
, REG_MAC_SPEC_SIFS
+ 1, val
[0]);
1643 rtl_write_byte(rtlpriv
, REG_R2T_SIFS
+1, val
[0]);
1644 rtl_write_byte(rtlpriv
, REG_T2T_SIFS
+1, val
[0]);
1645 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
, "HW_VAR_SIFS\n");
1648 case HW_VAR_SLOT_TIME
:{
1652 rtl_write_byte(rtlpriv
, REG_SLOT
, val
[0]);
1653 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1654 "HW_VAR_SLOT_TIME %x\n", val
[0]);
1656 for (e_aci
= 0; e_aci
< AC_MAX
; e_aci
++)
1657 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1664 if (IS_WIRELESS_MODE_A(wirelessmode
) ||
1665 IS_WIRELESS_MODE_N_24G(wirelessmode
) ||
1666 IS_WIRELESS_MODE_N_5G(wirelessmode
))
1670 u1bAIFS
= sifstime
+ (2 * val
[0]);
1671 rtl_write_byte(rtlpriv
, REG_EDCA_VO_PARAM
,
1673 rtl_write_byte(rtlpriv
, REG_EDCA_VI_PARAM
,
1675 rtl_write_byte(rtlpriv
, REG_EDCA_BE_PARAM
,
1677 rtl_write_byte(rtlpriv
, REG_EDCA_BK_PARAM
,
1682 case HW_VAR_ACK_PREAMBLE
:{
1684 u8 short_preamble
= (bool)*val
;
1688 rtl_write_byte(rtlpriv
, REG_RRSR
+ 2, reg_tmp
);
1691 case HW_VAR_AMPDU_MIN_SPACE
:{
1692 u8 min_spacing_to_set
;
1695 min_spacing_to_set
= *val
;
1696 if (min_spacing_to_set
<= 7) {
1697 switch (rtlpriv
->sec
.pairwise_enc_algorithm
) {
1699 case AESCCMP_ENCRYPTION
:
1702 case WEP40_ENCRYPTION
:
1703 case WEP104_ENCRYPTION
:
1704 case TKIP_ENCRYPTION
:
1711 if (min_spacing_to_set
< sec_min_space
)
1712 min_spacing_to_set
= sec_min_space
;
1713 mac
->min_space_cfg
= ((mac
->min_space_cfg
&
1715 min_spacing_to_set
);
1716 *val
= min_spacing_to_set
;
1717 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1718 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
1719 mac
->min_space_cfg
);
1720 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
1721 mac
->min_space_cfg
);
1725 case HW_VAR_SHORTGI_DENSITY
:{
1728 density_to_set
= *val
;
1729 density_to_set
&= 0x1f;
1730 mac
->min_space_cfg
&= 0x07;
1731 mac
->min_space_cfg
|= (density_to_set
<< 3);
1732 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1733 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
1734 mac
->min_space_cfg
);
1735 rtl_write_byte(rtlpriv
, REG_AMPDU_MIN_SPACE
,
1736 mac
->min_space_cfg
);
1739 case HW_VAR_AMPDU_FACTOR
:{
1740 u8 regtoset_normal
[4] = {0x41, 0xa8, 0x72, 0xb9};
1742 u8
*p_regtoset
= NULL
;
1745 p_regtoset
= regtoset_normal
;
1746 factor_toset
= *val
;
1747 if (factor_toset
<= 3) {
1748 factor_toset
= (1 << (factor_toset
+ 2));
1749 if (factor_toset
> 0xf)
1751 for (index
= 0; index
< 4; index
++) {
1752 if ((p_regtoset
[index
] & 0xf0) >
1753 (factor_toset
<< 4))
1755 (p_regtoset
[index
] & 0x0f)
1756 | (factor_toset
<< 4);
1757 if ((p_regtoset
[index
] & 0x0f) >
1760 (p_regtoset
[index
] & 0xf0)
1762 rtl_write_byte(rtlpriv
,
1763 (REG_AGGLEN_LMT
+ index
),
1766 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1767 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
1772 case HW_VAR_AC_PARAM
:{
1775 u16 cw_min
= le16_to_cpu(mac
->ac
[e_aci
].cw_min
);
1776 u16 cw_max
= le16_to_cpu(mac
->ac
[e_aci
].cw_max
);
1777 u16 tx_op
= le16_to_cpu(mac
->ac
[e_aci
].tx_op
);
1779 u4b_ac_param
= (u32
) mac
->ac
[e_aci
].aifs
;
1780 u4b_ac_param
|= (u32
) ((cw_min
& 0xF) <<
1781 AC_PARAM_ECW_MIN_OFFSET
);
1782 u4b_ac_param
|= (u32
) ((cw_max
& 0xF) <<
1783 AC_PARAM_ECW_MAX_OFFSET
);
1784 u4b_ac_param
|= (u32
) tx_op
<< AC_PARAM_TXOP_OFFSET
;
1785 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_LOUD
,
1786 "queue:%x, ac_param:%x\n",
1787 e_aci
, u4b_ac_param
);
1790 rtl_write_dword(rtlpriv
, REG_EDCA_BK_PARAM
,
1794 rtl_write_dword(rtlpriv
, REG_EDCA_BE_PARAM
,
1798 rtl_write_dword(rtlpriv
, REG_EDCA_VI_PARAM
,
1802 rtl_write_dword(rtlpriv
, REG_EDCA_VO_PARAM
,
1807 "SetHwReg8185(): invalid aci: %d !\n",
1811 if (rtlusb
->acm_method
!= eAcmWay2_SW
)
1812 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1813 HW_VAR_ACM_CTRL
, &e_aci
);
1816 case HW_VAR_ACM_CTRL
:{
1818 union aci_aifsn
*p_aci_aifsn
= (union aci_aifsn
*)
1819 (&(mac
->ac
[0].aifs
));
1820 u8 acm
= p_aci_aifsn
->f
.acm
;
1821 u8 acm_ctrl
= rtl_read_byte(rtlpriv
, REG_ACMHWCTRL
);
1824 acm_ctrl
| ((rtlusb
->acm_method
== 2) ? 0x0 : 0x1);
1828 acm_ctrl
|= AcmHw_BeqEn
;
1831 acm_ctrl
|= AcmHw_ViqEn
;
1834 acm_ctrl
|= AcmHw_VoqEn
;
1837 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_WARNING
,
1838 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
1845 acm_ctrl
&= (~AcmHw_BeqEn
);
1848 acm_ctrl
&= (~AcmHw_ViqEn
);
1851 acm_ctrl
&= (~AcmHw_BeqEn
);
1854 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1855 "switch case not processed\n");
1859 RT_TRACE(rtlpriv
, COMP_QOS
, DBG_TRACE
,
1860 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
1862 rtl_write_byte(rtlpriv
, REG_ACMHWCTRL
, acm_ctrl
);
1866 rtl_write_dword(rtlpriv
, REG_RCR
, ((u32
*) (val
))[0]);
1867 mac
->rx_conf
= ((u32
*) (val
))[0];
1868 RT_TRACE(rtlpriv
, COMP_RECV
, DBG_DMESG
,
1869 "### Set RCR(0x%08x) ###\n", mac
->rx_conf
);
1872 case HW_VAR_RETRY_LIMIT
:{
1873 u8 retry_limit
= val
[0];
1875 rtl_write_word(rtlpriv
, REG_RL
,
1876 retry_limit
<< RETRY_LIMIT_SHORT_SHIFT
|
1877 retry_limit
<< RETRY_LIMIT_LONG_SHIFT
);
1878 RT_TRACE(rtlpriv
, COMP_MLME
, DBG_DMESG
,
1879 "Set HW_VAR_RETRY_LIMIT(0x%08x)\n",
1883 case HW_VAR_DUAL_TSF_RST
:
1884 rtl_write_byte(rtlpriv
, REG_DUAL_TSF_RST
, (BIT(0) | BIT(1)));
1886 case HW_VAR_EFUSE_BYTES
:
1887 rtlefuse
->efuse_usedbytes
= *((u16
*) val
);
1889 case HW_VAR_EFUSE_USAGE
:
1890 rtlefuse
->efuse_usedpercentage
= *val
;
1893 rtl92c_phy_set_io_cmd(hw
, (*(enum io_type
*)val
));
1895 case HW_VAR_WPA_CONFIG
:
1896 rtl_write_byte(rtlpriv
, REG_SECCFG
, *val
);
1898 case HW_VAR_SET_RPWM
:{
1899 u8 rpwm_val
= rtl_read_byte(rtlpriv
, REG_USB_HRPWM
);
1901 if (rpwm_val
& BIT(7))
1902 rtl_write_byte(rtlpriv
, REG_USB_HRPWM
, *val
);
1904 rtl_write_byte(rtlpriv
, REG_USB_HRPWM
,
1908 case HW_VAR_H2C_FW_PWRMODE
:{
1911 if ((psmode
!= FW_PS_ACTIVE_MODE
) &&
1912 (!IS_92C_SERIAL(rtlhal
->version
)))
1913 rtl92c_dm_rf_saving(hw
, true);
1914 rtl92c_set_fw_pwrmode_cmd(hw
, (*val
));
1917 case HW_VAR_FW_PSMODE_STATUS
:
1918 ppsc
->fw_current_inpsmode
= *((bool *) val
);
1920 case HW_VAR_H2C_FW_JOINBSSRPT
:{
1923 bool recover
= false;
1925 if (mstatus
== RT_MEDIA_CONNECT
) {
1926 rtlpriv
->cfg
->ops
->set_hw_reg(hw
,
1928 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x03);
1929 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(3));
1930 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(4), 0);
1931 tmp_reg422
= rtl_read_byte(rtlpriv
,
1932 REG_FWHW_TXQ_CTRL
+ 2);
1933 if (tmp_reg422
& BIT(6))
1935 rtl_write_byte(rtlpriv
, REG_FWHW_TXQ_CTRL
+ 2,
1936 tmp_reg422
& (~BIT(6)));
1937 rtl92c_set_fw_rsvdpagepkt(hw
, 0);
1938 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(3), 0);
1939 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(4));
1941 rtl_write_byte(rtlpriv
,
1942 REG_FWHW_TXQ_CTRL
+ 2,
1943 tmp_reg422
| BIT(6));
1944 rtl_write_byte(rtlpriv
, REG_CR
+ 1, 0x02);
1946 rtl92c_set_fw_joinbss_report_cmd(hw
, (*val
));
1952 u2btmp
= rtl_read_word(rtlpriv
, REG_BCN_PSR_RPT
);
1954 rtl_write_word(rtlpriv
, REG_BCN_PSR_RPT
,
1955 (u2btmp
| mac
->assoc_id
));
1958 case HW_VAR_CORRECT_TSF
:{
1959 u8 btype_ibss
= val
[0];
1962 _rtl92cu_stop_tx_beacon(hw
);
1963 _rtl92cu_set_bcn_ctrl_reg(hw
, 0, BIT(3));
1964 rtl_write_dword(rtlpriv
, REG_TSFTR
, (u32
)(mac
->tsf
&
1966 rtl_write_dword(rtlpriv
, REG_TSFTR
+ 4,
1967 (u32
)((mac
->tsf
>> 32) & 0xffffffff));
1968 _rtl92cu_set_bcn_ctrl_reg(hw
, BIT(3), 0);
1970 _rtl92cu_resume_tx_beacon(hw
);
1973 case HW_VAR_MGT_FILTER
:
1974 rtl_write_word(rtlpriv
, REG_RXFLTMAP0
, *(u16
*)val
);
1976 case HW_VAR_CTRL_FILTER
:
1977 rtl_write_word(rtlpriv
, REG_RXFLTMAP1
, *(u16
*)val
);
1979 case HW_VAR_DATA_FILTER
:
1980 rtl_write_word(rtlpriv
, REG_RXFLTMAP2
, *(u16
*)val
);
1983 RT_TRACE(rtlpriv
, COMP_ERR
, DBG_EMERG
,
1984 "switch case not processed\n");
1989 static void rtl92cu_update_hal_rate_table(struct ieee80211_hw
*hw
,
1990 struct ieee80211_sta
*sta
)
1992 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1993 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
1994 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1995 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1998 u8 nmode
= mac
->ht_enable
;
1999 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2002 u8 curtxbw_40mhz
= mac
->bw_40
;
2003 u8 curshortgi_40mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2005 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2007 enum wireless_mode wirelessmode
= mac
->mode
;
2009 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2010 ratr_value
= sta
->supp_rates
[1] << 4;
2012 ratr_value
= sta
->supp_rates
[0];
2013 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2016 ratr_value
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2017 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2018 switch (wirelessmode
) {
2019 case WIRELESS_MODE_B
:
2020 if (ratr_value
& 0x0000000c)
2021 ratr_value
&= 0x0000000d;
2023 ratr_value
&= 0x0000000f;
2025 case WIRELESS_MODE_G
:
2026 ratr_value
&= 0x00000FF5;
2028 case WIRELESS_MODE_N_24G
:
2029 case WIRELESS_MODE_N_5G
:
2031 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2032 ratr_value
&= 0x0007F005;
2036 if (get_rf_type(rtlphy
) == RF_1T2R
||
2037 get_rf_type(rtlphy
) == RF_1T1R
)
2038 ratr_mask
= 0x000ff005;
2040 ratr_mask
= 0x0f0ff005;
2042 ratr_value
&= ratr_mask
;
2046 if (rtlphy
->rf_type
== RF_1T2R
)
2047 ratr_value
&= 0x000ff0ff;
2049 ratr_value
&= 0x0f0ff0ff;
2054 ratr_value
&= 0x0FFFFFFF;
2056 if (nmode
&& ((curtxbw_40mhz
&&
2057 curshortgi_40mhz
) || (!curtxbw_40mhz
&&
2058 curshortgi_20mhz
))) {
2060 ratr_value
|= 0x10000000;
2061 tmp_ratr_value
= (ratr_value
>> 12);
2063 for (shortgi_rate
= 15; shortgi_rate
> 0; shortgi_rate
--) {
2064 if ((1 << shortgi_rate
) & tmp_ratr_value
)
2068 shortgi_rate
= (shortgi_rate
<< 12) | (shortgi_rate
<< 8) |
2069 (shortgi_rate
<< 4) | (shortgi_rate
);
2072 rtl_write_dword(rtlpriv
, REG_ARFR0
+ ratr_index
* 4, ratr_value
);
2074 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
, "%x\n",
2075 rtl_read_dword(rtlpriv
, REG_ARFR0
));
2078 static void rtl92cu_update_hal_rate_mask(struct ieee80211_hw
*hw
,
2079 struct ieee80211_sta
*sta
,
2082 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2083 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
2084 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2085 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2086 struct rtl_sta_info
*sta_entry
= NULL
;
2089 u8 curtxbw_40mhz
= (sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
) ? 1 : 0;
2090 u8 curshortgi_40mhz
= curtxbw_40mhz
&&
2091 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
) ?
2093 u8 curshortgi_20mhz
= (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
) ?
2095 enum wireless_mode wirelessmode
= 0;
2096 bool shortgi
= false;
2099 u8 mimo_ps
= IEEE80211_SMPS_OFF
;
2101 sta_entry
= (struct rtl_sta_info
*) sta
->drv_priv
;
2102 wirelessmode
= sta_entry
->wireless_mode
;
2103 if (mac
->opmode
== NL80211_IFTYPE_STATION
||
2104 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
)
2105 curtxbw_40mhz
= mac
->bw_40
;
2106 else if (mac
->opmode
== NL80211_IFTYPE_AP
||
2107 mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2108 macid
= sta
->aid
+ 1;
2110 if (rtlhal
->current_bandtype
== BAND_ON_5G
)
2111 ratr_bitmap
= sta
->supp_rates
[1] << 4;
2113 ratr_bitmap
= sta
->supp_rates
[0];
2114 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
)
2115 ratr_bitmap
= 0xfff;
2116 ratr_bitmap
|= (sta
->ht_cap
.mcs
.rx_mask
[1] << 20 |
2117 sta
->ht_cap
.mcs
.rx_mask
[0] << 12);
2118 switch (wirelessmode
) {
2119 case WIRELESS_MODE_B
:
2120 ratr_index
= RATR_INX_WIRELESS_B
;
2121 if (ratr_bitmap
& 0x0000000c)
2122 ratr_bitmap
&= 0x0000000d;
2124 ratr_bitmap
&= 0x0000000f;
2126 case WIRELESS_MODE_G
:
2127 ratr_index
= RATR_INX_WIRELESS_GB
;
2129 if (rssi_level
== 1)
2130 ratr_bitmap
&= 0x00000f00;
2131 else if (rssi_level
== 2)
2132 ratr_bitmap
&= 0x00000ff0;
2134 ratr_bitmap
&= 0x00000ff5;
2136 case WIRELESS_MODE_A
:
2137 ratr_index
= RATR_INX_WIRELESS_A
;
2138 ratr_bitmap
&= 0x00000ff0;
2140 case WIRELESS_MODE_N_24G
:
2141 case WIRELESS_MODE_N_5G
:
2142 ratr_index
= RATR_INX_WIRELESS_NGB
;
2144 if (mimo_ps
== IEEE80211_SMPS_STATIC
) {
2145 if (rssi_level
== 1)
2146 ratr_bitmap
&= 0x00070000;
2147 else if (rssi_level
== 2)
2148 ratr_bitmap
&= 0x0007f000;
2150 ratr_bitmap
&= 0x0007f005;
2152 if (rtlphy
->rf_type
== RF_1T2R
||
2153 rtlphy
->rf_type
== RF_1T1R
) {
2154 if (curtxbw_40mhz
) {
2155 if (rssi_level
== 1)
2156 ratr_bitmap
&= 0x000f0000;
2157 else if (rssi_level
== 2)
2158 ratr_bitmap
&= 0x000ff000;
2160 ratr_bitmap
&= 0x000ff015;
2162 if (rssi_level
== 1)
2163 ratr_bitmap
&= 0x000f0000;
2164 else if (rssi_level
== 2)
2165 ratr_bitmap
&= 0x000ff000;
2167 ratr_bitmap
&= 0x000ff005;
2170 if (curtxbw_40mhz
) {
2171 if (rssi_level
== 1)
2172 ratr_bitmap
&= 0x0f0f0000;
2173 else if (rssi_level
== 2)
2174 ratr_bitmap
&= 0x0f0ff000;
2176 ratr_bitmap
&= 0x0f0ff015;
2178 if (rssi_level
== 1)
2179 ratr_bitmap
&= 0x0f0f0000;
2180 else if (rssi_level
== 2)
2181 ratr_bitmap
&= 0x0f0ff000;
2183 ratr_bitmap
&= 0x0f0ff005;
2188 if ((curtxbw_40mhz
&& curshortgi_40mhz
) ||
2189 (!curtxbw_40mhz
&& curshortgi_20mhz
)) {
2193 else if (macid
== 1)
2198 ratr_index
= RATR_INX_WIRELESS_NGB
;
2200 if (rtlphy
->rf_type
== RF_1T2R
)
2201 ratr_bitmap
&= 0x000ff0ff;
2203 ratr_bitmap
&= 0x0f0ff0ff;
2206 sta_entry
->ratr_index
= ratr_index
;
2208 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2209 "ratr_bitmap :%x\n", ratr_bitmap
);
2210 *(u32
*)&rate_mask
= (ratr_bitmap
& 0x0fffffff) |
2212 rate_mask
[4] = macid
| (shortgi
? 0x20 : 0x00) | 0x80;
2213 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
2214 "Rate_index:%x, ratr_val:%x, %5phC\n",
2215 ratr_index
, ratr_bitmap
, rate_mask
);
2216 memcpy(rtlpriv
->rate_mask
, rate_mask
, 5);
2217 /* rtl92c_fill_h2c_cmd() does USB I/O and will result in a
2218 * "scheduled while atomic" if called directly */
2219 schedule_work(&rtlpriv
->works
.fill_h2c_cmd
);
2222 sta_entry
->ratr_index
= ratr_index
;
2225 void rtl92cu_update_hal_rate_tbl(struct ieee80211_hw
*hw
,
2226 struct ieee80211_sta
*sta
,
2229 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2231 if (rtlpriv
->dm
.useramask
)
2232 rtl92cu_update_hal_rate_mask(hw
, sta
, rssi_level
);
2234 rtl92cu_update_hal_rate_table(hw
, sta
);
2237 void rtl92cu_update_channel_access_setting(struct ieee80211_hw
*hw
)
2239 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2240 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
2243 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SLOT_TIME
,
2245 if (!mac
->ht_enable
)
2246 sifs_timer
= 0x0a0a;
2248 sifs_timer
= 0x0e0e;
2249 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_SIFS
, (u8
*)&sifs_timer
);
2252 bool rtl92cu_gpio_radio_on_off_checking(struct ieee80211_hw
*hw
, u8
* valid
)
2254 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
2255 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
2256 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
2257 enum rf_pwrstate e_rfpowerstate_toset
, cur_rfstate
;
2259 bool actuallyset
= false;
2260 unsigned long flag
= 0;
2261 /* to do - usb autosuspend */
2262 u8 usb_autosuspend
= 0;
2264 if (ppsc
->swrf_processing
)
2266 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2267 if (ppsc
->rfchange_inprogress
) {
2268 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2271 ppsc
->rfchange_inprogress
= true;
2272 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2274 cur_rfstate
= ppsc
->rfpwr_state
;
2275 if (usb_autosuspend
) {
2276 /* to do................... */
2278 if (ppsc
->pwrdown_mode
) {
2279 u1tmp
= rtl_read_byte(rtlpriv
, REG_HSISR
);
2280 e_rfpowerstate_toset
= (u1tmp
& BIT(7)) ?
2282 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
2283 "pwrdown, 0x5c(BIT7)=%02x\n", u1tmp
);
2285 rtl_write_byte(rtlpriv
, REG_MAC_PINMUX_CFG
,
2286 rtl_read_byte(rtlpriv
,
2287 REG_MAC_PINMUX_CFG
) & ~(BIT(3)));
2288 u1tmp
= rtl_read_byte(rtlpriv
, REG_GPIO_IO_SEL
);
2289 e_rfpowerstate_toset
= (u1tmp
& BIT(3)) ?
2291 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_DMESG
,
2292 "GPIO_IN=%02x\n", u1tmp
);
2294 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
, "N-SS RF =%x\n",
2295 e_rfpowerstate_toset
);
2297 if ((ppsc
->hwradiooff
) && (e_rfpowerstate_toset
== ERFON
)) {
2298 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2299 "GPIOChangeRF - HW Radio ON, RF ON\n");
2300 ppsc
->hwradiooff
= false;
2302 } else if ((!ppsc
->hwradiooff
) && (e_rfpowerstate_toset
==
2304 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2305 "GPIOChangeRF - HW Radio OFF\n");
2306 ppsc
->hwradiooff
= true;
2309 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
2310 "pHalData->bHwRadioOff and eRfPowerStateToSet do not match: pHalData->bHwRadioOff %x, eRfPowerStateToSet %x\n",
2311 ppsc
->hwradiooff
, e_rfpowerstate_toset
);
2314 ppsc
->hwradiooff
= true;
2315 if (e_rfpowerstate_toset
== ERFON
) {
2316 if ((ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
) &&
2317 RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
))
2318 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2319 else if ((ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2320 && RT_IN_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
))
2321 RT_CLEAR_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2323 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2324 ppsc
->rfchange_inprogress
= false;
2325 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2326 /* For power down module, we need to enable register block
2327 * contrl reg at 0x1c. Then enable power down control bit
2328 * of register 0x04 BIT4 and BIT15 as 1.
2330 if (ppsc
->pwrdown_mode
&& e_rfpowerstate_toset
== ERFOFF
) {
2331 /* Enable register area 0x0-0xc. */
2332 rtl_write_byte(rtlpriv
, REG_RSV_CTRL
, 0x0);
2333 if (IS_HARDWARE_TYPE_8723U(rtlhal
)) {
2335 * We should configure HW PDn source for WiFi
2336 * ONLY, and then our HW will be set in
2337 * power-down mode if PDn source from all
2338 * functions are configured.
2340 u1tmp
= rtl_read_byte(rtlpriv
,
2341 REG_MULTI_FUNC_CTRL
);
2342 rtl_write_byte(rtlpriv
, REG_MULTI_FUNC_CTRL
,
2343 (u1tmp
|WL_HWPDN_EN
));
2345 rtl_write_word(rtlpriv
, REG_APS_FSMCO
, 0x8812);
2348 if (e_rfpowerstate_toset
== ERFOFF
) {
2349 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
)
2350 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2351 else if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2352 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2354 } else if (e_rfpowerstate_toset
== ERFOFF
|| cur_rfstate
== ERFOFF
) {
2355 /* Enter D3 or ASPM after GPIO had been done. */
2356 if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_ASPM
)
2357 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_ASPM
);
2358 else if (ppsc
->reg_rfps_level
& RT_RF_OFF_LEVL_PCI_D3
)
2359 RT_SET_PS_LEVEL(ppsc
, RT_RF_OFF_LEVL_PCI_D3
);
2360 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2361 ppsc
->rfchange_inprogress
= false;
2362 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2364 spin_lock_irqsave(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2365 ppsc
->rfchange_inprogress
= false;
2366 spin_unlock_irqrestore(&rtlpriv
->locks
.rf_ps_lock
, flag
);
2369 return !ppsc
->hwradiooff
;