OMAPDSS: VENC: fix NULL pointer dereference in DSS2 VENC sysfs debug attr on OMAP4
[zen-stable.git] / drivers / net / wireless / rtlwifi / rtl8192ce / hw.c
blobb603289bd0a30aa5e052363db9f23b836275cd65
1 /******************************************************************************
3 * Copyright(c) 2009-2010 Realtek Corporation.
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
12 * more details.
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 #include "../wifi.h"
31 #include "../efuse.h"
32 #include "../base.h"
33 #include "../regd.h"
34 #include "../cam.h"
35 #include "../ps.h"
36 #include "../pci.h"
37 #include "reg.h"
38 #include "def.h"
39 #include "phy.h"
40 #include "../rtl8192c/fw_common.h"
41 #include "dm.h"
42 #include "led.h"
43 #include "hw.h"
45 #define LLT_CONFIG 5
47 static void _rtl92ce_set_bcn_ctrl_reg(struct ieee80211_hw *hw,
48 u8 set_bits, u8 clear_bits)
50 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
51 struct rtl_priv *rtlpriv = rtl_priv(hw);
53 rtlpci->reg_bcn_ctrl_val |= set_bits;
54 rtlpci->reg_bcn_ctrl_val &= ~clear_bits;
56 rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val);
59 static void _rtl92ce_stop_tx_beacon(struct ieee80211_hw *hw)
61 struct rtl_priv *rtlpriv = rtl_priv(hw);
62 u8 tmp1byte;
64 tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
65 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6)));
66 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
67 tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
68 tmp1byte &= ~(BIT(0));
69 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
72 static void _rtl92ce_resume_tx_beacon(struct ieee80211_hw *hw)
74 struct rtl_priv *rtlpriv = rtl_priv(hw);
75 u8 tmp1byte;
77 tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
78 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6));
79 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
80 tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
81 tmp1byte |= BIT(0);
82 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
85 static void _rtl92ce_enable_bcn_sub_func(struct ieee80211_hw *hw)
87 _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(1));
90 static void _rtl92ce_disable_bcn_sub_func(struct ieee80211_hw *hw)
92 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(1), 0);
95 void rtl92ce_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
97 struct rtl_priv *rtlpriv = rtl_priv(hw);
98 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
99 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
101 switch (variable) {
102 case HW_VAR_RCR:
103 *((u32 *) (val)) = rtlpci->receive_config;
104 break;
105 case HW_VAR_RF_STATE:
106 *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
107 break;
108 case HW_VAR_FWLPS_RF_ON:{
109 enum rf_pwrstate rfState;
110 u32 val_rcr;
112 rtlpriv->cfg->ops->get_hw_reg(hw,
113 HW_VAR_RF_STATE,
114 (u8 *) (&rfState));
115 if (rfState == ERFOFF) {
116 *((bool *) (val)) = true;
117 } else {
118 val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
119 val_rcr &= 0x00070000;
120 if (val_rcr)
121 *((bool *) (val)) = false;
122 else
123 *((bool *) (val)) = true;
125 break;
127 case HW_VAR_FW_PSMODE_STATUS:
128 *((bool *) (val)) = ppsc->fw_current_inpsmode;
129 break;
130 case HW_VAR_CORRECT_TSF:{
131 u64 tsf;
132 u32 *ptsf_low = (u32 *)&tsf;
133 u32 *ptsf_high = ((u32 *)&tsf) + 1;
135 *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
136 *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
138 *((u64 *) (val)) = tsf;
140 break;
142 default:
143 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
144 ("switch case not process\n"));
145 break;
149 void rtl92ce_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
151 struct rtl_priv *rtlpriv = rtl_priv(hw);
152 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
153 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
154 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
155 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
156 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
157 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
158 u8 idx;
160 switch (variable) {
161 case HW_VAR_ETHER_ADDR:{
162 for (idx = 0; idx < ETH_ALEN; idx++) {
163 rtl_write_byte(rtlpriv, (REG_MACID + idx),
164 val[idx]);
166 break;
168 case HW_VAR_BASIC_RATE:{
169 u16 rate_cfg = ((u16 *) val)[0];
170 u8 rate_index = 0;
171 rate_cfg &= 0x15f;
172 rate_cfg |= 0x01;
173 rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff);
174 rtl_write_byte(rtlpriv, REG_RRSR + 1,
175 (rate_cfg >> 8) & 0xff);
176 while (rate_cfg > 0x1) {
177 rate_cfg = (rate_cfg >> 1);
178 rate_index++;
180 rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
181 rate_index);
182 break;
184 case HW_VAR_BSSID:{
185 for (idx = 0; idx < ETH_ALEN; idx++) {
186 rtl_write_byte(rtlpriv, (REG_BSSID + idx),
187 val[idx]);
189 break;
191 case HW_VAR_SIFS:{
192 rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
193 rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
195 rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
196 rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
198 if (!mac->ht_enable)
199 rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
200 0x0e0e);
201 else
202 rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
203 *((u16 *) val));
204 break;
206 case HW_VAR_SLOT_TIME:{
207 u8 e_aci;
209 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
210 ("HW_VAR_SLOT_TIME %x\n", val[0]));
212 rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
214 for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
215 rtlpriv->cfg->ops->set_hw_reg(hw,
216 HW_VAR_AC_PARAM,
217 (u8 *) (&e_aci));
219 break;
221 case HW_VAR_ACK_PREAMBLE:{
222 u8 reg_tmp;
223 u8 short_preamble = (bool) (*(u8 *) val);
224 reg_tmp = (mac->cur_40_prime_sc) << 5;
225 if (short_preamble)
226 reg_tmp |= 0x80;
228 rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
229 break;
231 case HW_VAR_AMPDU_MIN_SPACE:{
232 u8 min_spacing_to_set;
233 u8 sec_min_space;
235 min_spacing_to_set = *((u8 *) val);
236 if (min_spacing_to_set <= 7) {
237 sec_min_space = 0;
239 if (min_spacing_to_set < sec_min_space)
240 min_spacing_to_set = sec_min_space;
242 mac->min_space_cfg = ((mac->min_space_cfg &
243 0xf8) |
244 min_spacing_to_set);
246 *val = min_spacing_to_set;
248 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
249 ("Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
250 mac->min_space_cfg));
252 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
253 mac->min_space_cfg);
255 break;
257 case HW_VAR_SHORTGI_DENSITY:{
258 u8 density_to_set;
260 density_to_set = *((u8 *) val);
261 mac->min_space_cfg |= (density_to_set << 3);
263 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
264 ("Set HW_VAR_SHORTGI_DENSITY: %#x\n",
265 mac->min_space_cfg));
267 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
268 mac->min_space_cfg);
270 break;
272 case HW_VAR_AMPDU_FACTOR:{
273 u8 regtoset_normal[4] = {0x41, 0xa8, 0x72, 0xb9};
274 u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97};
276 u8 factor_toset;
277 u8 *p_regtoset = NULL;
278 u8 index = 0;
280 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
281 (rtlpcipriv->bt_coexist.bt_coexist_type ==
282 BT_CSR_BC4))
283 p_regtoset = regtoset_bt;
284 else
285 p_regtoset = regtoset_normal;
287 factor_toset = *((u8 *) val);
288 if (factor_toset <= 3) {
289 factor_toset = (1 << (factor_toset + 2));
290 if (factor_toset > 0xf)
291 factor_toset = 0xf;
293 for (index = 0; index < 4; index++) {
294 if ((p_regtoset[index] & 0xf0) >
295 (factor_toset << 4))
296 p_regtoset[index] =
297 (p_regtoset[index] & 0x0f) |
298 (factor_toset << 4);
300 if ((p_regtoset[index] & 0x0f) >
301 factor_toset)
302 p_regtoset[index] =
303 (p_regtoset[index] & 0xf0) |
304 (factor_toset);
306 rtl_write_byte(rtlpriv,
307 (REG_AGGLEN_LMT + index),
308 p_regtoset[index]);
312 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
313 ("Set HW_VAR_AMPDU_FACTOR: %#x\n",
314 factor_toset));
316 break;
318 case HW_VAR_AC_PARAM:{
319 u8 e_aci = *((u8 *) val);
320 rtl92c_dm_init_edca_turbo(hw);
322 if (rtlpci->acm_method != eAcmWay2_SW)
323 rtlpriv->cfg->ops->set_hw_reg(hw,
324 HW_VAR_ACM_CTRL,
325 (u8 *) (&e_aci));
326 break;
328 case HW_VAR_ACM_CTRL:{
329 u8 e_aci = *((u8 *) val);
330 union aci_aifsn *p_aci_aifsn =
331 (union aci_aifsn *)(&(mac->ac[0].aifs));
332 u8 acm = p_aci_aifsn->f.acm;
333 u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
335 acm_ctrl =
336 acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
338 if (acm) {
339 switch (e_aci) {
340 case AC0_BE:
341 acm_ctrl |= AcmHw_BeqEn;
342 break;
343 case AC2_VI:
344 acm_ctrl |= AcmHw_ViqEn;
345 break;
346 case AC3_VO:
347 acm_ctrl |= AcmHw_VoqEn;
348 break;
349 default:
350 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
351 ("HW_VAR_ACM_CTRL acm set "
352 "failed: eACI is %d\n", acm));
353 break;
355 } else {
356 switch (e_aci) {
357 case AC0_BE:
358 acm_ctrl &= (~AcmHw_BeqEn);
359 break;
360 case AC2_VI:
361 acm_ctrl &= (~AcmHw_ViqEn);
362 break;
363 case AC3_VO:
364 acm_ctrl &= (~AcmHw_BeqEn);
365 break;
366 default:
367 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
368 ("switch case not process\n"));
369 break;
373 RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
374 ("SetHwReg8190pci(): [HW_VAR_ACM_CTRL] "
375 "Write 0x%X\n", acm_ctrl));
376 rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
377 break;
379 case HW_VAR_RCR:{
380 rtl_write_dword(rtlpriv, REG_RCR, ((u32 *) (val))[0]);
381 rtlpci->receive_config = ((u32 *) (val))[0];
382 break;
384 case HW_VAR_RETRY_LIMIT:{
385 u8 retry_limit = ((u8 *) (val))[0];
387 rtl_write_word(rtlpriv, REG_RL,
388 retry_limit << RETRY_LIMIT_SHORT_SHIFT |
389 retry_limit << RETRY_LIMIT_LONG_SHIFT);
390 break;
392 case HW_VAR_DUAL_TSF_RST:
393 rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
394 break;
395 case HW_VAR_EFUSE_BYTES:
396 rtlefuse->efuse_usedbytes = *((u16 *) val);
397 break;
398 case HW_VAR_EFUSE_USAGE:
399 rtlefuse->efuse_usedpercentage = *((u8 *) val);
400 break;
401 case HW_VAR_IO_CMD:
402 rtl92c_phy_set_io_cmd(hw, (*(enum io_type *)val));
403 break;
404 case HW_VAR_WPA_CONFIG:
405 rtl_write_byte(rtlpriv, REG_SECCFG, *((u8 *) val));
406 break;
407 case HW_VAR_SET_RPWM:{
408 u8 rpwm_val;
410 rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
411 udelay(1);
413 if (rpwm_val & BIT(7)) {
414 rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
415 (*(u8 *) val));
416 } else {
417 rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
418 ((*(u8 *) val) | BIT(7)));
421 break;
423 case HW_VAR_H2C_FW_PWRMODE:{
424 u8 psmode = (*(u8 *) val);
426 if ((psmode != FW_PS_ACTIVE_MODE) &&
427 (!IS_92C_SERIAL(rtlhal->version))) {
428 rtl92c_dm_rf_saving(hw, true);
431 rtl92c_set_fw_pwrmode_cmd(hw, (*(u8 *) val));
432 break;
434 case HW_VAR_FW_PSMODE_STATUS:
435 ppsc->fw_current_inpsmode = *((bool *) val);
436 break;
437 case HW_VAR_H2C_FW_JOINBSSRPT:{
438 u8 mstatus = (*(u8 *) val);
439 u8 tmp_regcr, tmp_reg422;
440 bool recover = false;
442 if (mstatus == RT_MEDIA_CONNECT) {
443 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
444 NULL);
446 tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
447 rtl_write_byte(rtlpriv, REG_CR + 1,
448 (tmp_regcr | BIT(0)));
450 _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
451 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
453 tmp_reg422 =
454 rtl_read_byte(rtlpriv,
455 REG_FWHW_TXQ_CTRL + 2);
456 if (tmp_reg422 & BIT(6))
457 recover = true;
458 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
459 tmp_reg422 & (~BIT(6)));
461 rtl92c_set_fw_rsvdpagepkt(hw, 0);
463 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
464 _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
466 if (recover) {
467 rtl_write_byte(rtlpriv,
468 REG_FWHW_TXQ_CTRL + 2,
469 tmp_reg422);
472 rtl_write_byte(rtlpriv, REG_CR + 1,
473 (tmp_regcr & ~(BIT(0))));
475 rtl92c_set_fw_joinbss_report_cmd(hw, (*(u8 *) val));
477 break;
479 case HW_VAR_AID:{
480 u16 u2btmp;
481 u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
482 u2btmp &= 0xC000;
483 rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
484 mac->assoc_id));
486 break;
488 case HW_VAR_CORRECT_TSF:{
489 u8 btype_ibss = ((u8 *) (val))[0];
491 if (btype_ibss)
492 _rtl92ce_stop_tx_beacon(hw);
494 _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
496 rtl_write_dword(rtlpriv, REG_TSFTR,
497 (u32) (mac->tsf & 0xffffffff));
498 rtl_write_dword(rtlpriv, REG_TSFTR + 4,
499 (u32) ((mac->tsf >> 32) & 0xffffffff));
501 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
503 if (btype_ibss)
504 _rtl92ce_resume_tx_beacon(hw);
506 break;
509 default:
510 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("switch case "
511 "not process\n"));
512 break;
516 static bool _rtl92ce_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
518 struct rtl_priv *rtlpriv = rtl_priv(hw);
519 bool status = true;
520 long count = 0;
521 u32 value = _LLT_INIT_ADDR(address) |
522 _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
524 rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
526 do {
527 value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
528 if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
529 break;
531 if (count > POLLING_LLT_THRESHOLD) {
532 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
533 ("Failed to polling write LLT done at "
534 "address %d!\n", address));
535 status = false;
536 break;
538 } while (++count);
540 return status;
543 static bool _rtl92ce_llt_table_init(struct ieee80211_hw *hw)
545 struct rtl_priv *rtlpriv = rtl_priv(hw);
546 unsigned short i;
547 u8 txpktbuf_bndy;
548 u8 maxPage;
549 bool status;
551 #if LLT_CONFIG == 1
552 maxPage = 255;
553 txpktbuf_bndy = 252;
554 #elif LLT_CONFIG == 2
555 maxPage = 127;
556 txpktbuf_bndy = 124;
557 #elif LLT_CONFIG == 3
558 maxPage = 255;
559 txpktbuf_bndy = 174;
560 #elif LLT_CONFIG == 4
561 maxPage = 255;
562 txpktbuf_bndy = 246;
563 #elif LLT_CONFIG == 5
564 maxPage = 255;
565 txpktbuf_bndy = 246;
566 #endif
568 #if LLT_CONFIG == 1
569 rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x1c);
570 rtl_write_dword(rtlpriv, REG_RQPN, 0x80a71c1c);
571 #elif LLT_CONFIG == 2
572 rtl_write_dword(rtlpriv, REG_RQPN, 0x845B1010);
573 #elif LLT_CONFIG == 3
574 rtl_write_dword(rtlpriv, REG_RQPN, 0x84838484);
575 #elif LLT_CONFIG == 4
576 rtl_write_dword(rtlpriv, REG_RQPN, 0x80bd1c1c);
577 #elif LLT_CONFIG == 5
578 rtl_write_word(rtlpriv, REG_RQPN_NPQ, 0x0000);
580 rtl_write_dword(rtlpriv, REG_RQPN, 0x80b01c29);
581 #endif
583 rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x27FF0000 | txpktbuf_bndy));
584 rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
586 rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
587 rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
589 rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
590 rtl_write_byte(rtlpriv, REG_PBP, 0x11);
591 rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
593 for (i = 0; i < (txpktbuf_bndy - 1); i++) {
594 status = _rtl92ce_llt_write(hw, i, i + 1);
595 if (true != status)
596 return status;
599 status = _rtl92ce_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
600 if (true != status)
601 return status;
603 for (i = txpktbuf_bndy; i < maxPage; i++) {
604 status = _rtl92ce_llt_write(hw, i, (i + 1));
605 if (true != status)
606 return status;
609 status = _rtl92ce_llt_write(hw, maxPage, txpktbuf_bndy);
610 if (true != status)
611 return status;
613 return true;
616 static void _rtl92ce_gen_refresh_led_state(struct ieee80211_hw *hw)
618 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
619 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
620 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
621 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
623 if (rtlpci->up_first_time)
624 return;
626 if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
627 rtl92ce_sw_led_on(hw, pLed0);
628 else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
629 rtl92ce_sw_led_on(hw, pLed0);
630 else
631 rtl92ce_sw_led_off(hw, pLed0);
634 static bool _rtl92ce_init_mac(struct ieee80211_hw *hw)
636 struct rtl_priv *rtlpriv = rtl_priv(hw);
637 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
638 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
639 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
641 unsigned char bytetmp;
642 unsigned short wordtmp;
643 u16 retry;
645 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
646 if (rtlpcipriv->bt_coexist.bt_coexistence) {
647 u32 value32;
648 value32 = rtl_read_dword(rtlpriv, REG_APS_FSMCO);
649 value32 |= (SOP_ABG | SOP_AMB | XOP_BTCK);
650 rtl_write_dword(rtlpriv, REG_APS_FSMCO, value32);
652 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
653 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0F);
655 if (rtlpcipriv->bt_coexist.bt_coexistence) {
656 u32 u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
658 u4b_tmp &= (~0x00024800);
659 rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
662 bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) | BIT(0);
663 udelay(2);
665 rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
666 udelay(2);
668 bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
669 udelay(2);
671 retry = 0;
672 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("reg0xec:%x:%x\n",
673 rtl_read_dword(rtlpriv, 0xEC),
674 bytetmp));
676 while ((bytetmp & BIT(0)) && retry < 1000) {
677 retry++;
678 udelay(50);
679 bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
680 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("reg0xec:%x:%x\n",
681 rtl_read_dword(rtlpriv,
682 0xEC),
683 bytetmp));
684 udelay(50);
687 rtl_write_word(rtlpriv, REG_APS_FSMCO, 0x1012);
689 rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x82);
690 udelay(2);
692 if (rtlpcipriv->bt_coexist.bt_coexistence) {
693 bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL+2) & 0xfd;
694 rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL+2, bytetmp);
697 rtl_write_word(rtlpriv, REG_CR, 0x2ff);
699 if (_rtl92ce_llt_table_init(hw) == false)
700 return false;
702 rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
703 rtl_write_byte(rtlpriv, REG_HISRE, 0xff);
705 rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x27ff);
707 wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
708 wordtmp &= 0xf;
709 wordtmp |= 0xF771;
710 rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
712 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
713 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
714 rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
716 rtl_write_byte(rtlpriv, 0x4d0, 0x0);
718 rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
719 ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) &
720 DMA_BIT_MASK(32));
721 rtl_write_dword(rtlpriv, REG_MGQ_DESA,
722 (u64) rtlpci->tx_ring[MGNT_QUEUE].dma &
723 DMA_BIT_MASK(32));
724 rtl_write_dword(rtlpriv, REG_VOQ_DESA,
725 (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
726 rtl_write_dword(rtlpriv, REG_VIQ_DESA,
727 (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
728 rtl_write_dword(rtlpriv, REG_BEQ_DESA,
729 (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
730 rtl_write_dword(rtlpriv, REG_BKQ_DESA,
731 (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
732 rtl_write_dword(rtlpriv, REG_HQ_DESA,
733 (u64) rtlpci->tx_ring[HIGH_QUEUE].dma &
734 DMA_BIT_MASK(32));
735 rtl_write_dword(rtlpriv, REG_RX_DESA,
736 (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
737 DMA_BIT_MASK(32));
739 if (IS_92C_SERIAL(rtlhal->version))
740 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x77);
741 else
742 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x22);
744 rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
746 bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
747 rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6));
748 do {
749 retry++;
750 bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
751 } while ((retry < 200) && (bytetmp & BIT(7)));
753 _rtl92ce_gen_refresh_led_state(hw);
755 rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
757 return true;
760 static void _rtl92ce_hw_configure(struct ieee80211_hw *hw)
762 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
763 struct rtl_priv *rtlpriv = rtl_priv(hw);
764 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
765 u8 reg_bw_opmode;
766 u32 reg_prsr;
768 reg_bw_opmode = BW_OPMODE_20MHZ;
769 reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
771 rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8);
773 rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
775 rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
777 rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
779 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0);
781 rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
783 rtl_write_word(rtlpriv, REG_RL, 0x0707);
785 rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802);
787 rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
789 rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
790 rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
791 rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
792 rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
794 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
795 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
796 rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431);
797 else
798 rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
800 rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
802 rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
804 rtlpci->reg_bcn_ctrl_val = 0x1f;
805 rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
807 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
809 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
811 rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
812 rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
814 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
815 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4)) {
816 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
817 rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402);
818 } else {
819 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
820 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
823 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
824 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
825 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
826 else
827 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666);
829 rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
831 rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010);
832 rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010);
834 rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010);
836 rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010);
838 rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
839 rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
843 static void _rtl92ce_enable_aspm_back_door(struct ieee80211_hw *hw)
845 struct rtl_priv *rtlpriv = rtl_priv(hw);
846 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
848 rtl_write_byte(rtlpriv, 0x34b, 0x93);
849 rtl_write_word(rtlpriv, 0x350, 0x870c);
850 rtl_write_byte(rtlpriv, 0x352, 0x1);
852 if (ppsc->support_backdoor)
853 rtl_write_byte(rtlpriv, 0x349, 0x1b);
854 else
855 rtl_write_byte(rtlpriv, 0x349, 0x03);
857 rtl_write_word(rtlpriv, 0x350, 0x2718);
858 rtl_write_byte(rtlpriv, 0x352, 0x1);
861 void rtl92ce_enable_hw_security_config(struct ieee80211_hw *hw)
863 struct rtl_priv *rtlpriv = rtl_priv(hw);
864 u8 sec_reg_value;
866 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
867 ("PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
868 rtlpriv->sec.pairwise_enc_algorithm,
869 rtlpriv->sec.group_enc_algorithm));
871 if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
872 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("not open "
873 "hw encryption\n"));
874 return;
877 sec_reg_value = SCR_TxEncEnable | SCR_RxDecEnable;
879 if (rtlpriv->sec.use_defaultkey) {
880 sec_reg_value |= SCR_TxUseDK;
881 sec_reg_value |= SCR_RxUseDK;
884 sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
886 rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
888 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
889 ("The SECR-value %x\n", sec_reg_value));
891 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
895 int rtl92ce_hw_init(struct ieee80211_hw *hw)
897 struct rtl_priv *rtlpriv = rtl_priv(hw);
898 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
899 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
900 struct rtl_phy *rtlphy = &(rtlpriv->phy);
901 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
902 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
903 static bool iqk_initialized; /* initialized to false */
904 bool rtstatus = true;
905 bool is92c;
906 int err;
907 u8 tmp_u1b;
909 rtlpci->being_init_adapter = true;
910 rtlpriv->intf_ops->disable_aspm(hw);
911 rtstatus = _rtl92ce_init_mac(hw);
912 if (rtstatus != true) {
913 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("Init MAC failed\n"));
914 err = 1;
915 return err;
918 err = rtl92c_download_fw(hw);
919 if (err) {
920 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
921 ("Failed to download FW. Init HW "
922 "without FW now..\n"));
923 err = 1;
924 return err;
927 rtlhal->last_hmeboxnum = 0;
928 rtl92c_phy_mac_config(hw);
929 rtl92c_phy_bb_config(hw);
930 rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
931 rtl92c_phy_rf_config(hw);
932 rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
933 RF_CHNLBW, RFREG_OFFSET_MASK);
934 rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1,
935 RF_CHNLBW, RFREG_OFFSET_MASK);
936 rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
937 rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
938 rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
939 _rtl92ce_hw_configure(hw);
940 rtl_cam_reset_all_entry(hw);
941 rtl92ce_enable_hw_security_config(hw);
943 ppsc->rfpwr_state = ERFON;
945 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
946 _rtl92ce_enable_aspm_back_door(hw);
947 rtlpriv->intf_ops->enable_aspm(hw);
949 rtl8192ce_bt_hw_init(hw);
951 if (ppsc->rfpwr_state == ERFON) {
952 rtl92c_phy_set_rfpath_switch(hw, 1);
953 if (iqk_initialized) {
954 rtl92c_phy_iq_calibrate(hw, true);
955 } else {
956 rtl92c_phy_iq_calibrate(hw, false);
957 iqk_initialized = true;
960 rtl92c_dm_check_txpower_tracking(hw);
961 rtl92c_phy_lc_calibrate(hw);
964 is92c = IS_92C_SERIAL(rtlhal->version);
965 tmp_u1b = efuse_read_1byte(hw, 0x1FA);
966 if (!(tmp_u1b & BIT(0))) {
967 rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
968 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("PA BIAS path A\n"));
971 if (!(tmp_u1b & BIT(1)) && is92c) {
972 rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0F, 0x05);
973 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("PA BIAS path B\n"));
976 if (!(tmp_u1b & BIT(4))) {
977 tmp_u1b = rtl_read_byte(rtlpriv, 0x16);
978 tmp_u1b &= 0x0F;
979 rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
980 udelay(10);
981 rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
982 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, ("under 1.5V\n"));
984 rtl92c_dm_init(hw);
985 rtlpci->being_init_adapter = false;
986 return err;
989 static enum version_8192c _rtl92ce_read_chip_version(struct ieee80211_hw *hw)
991 struct rtl_priv *rtlpriv = rtl_priv(hw);
992 struct rtl_phy *rtlphy = &(rtlpriv->phy);
993 enum version_8192c version = VERSION_UNKNOWN;
994 u32 value32;
996 value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
997 if (value32 & TRP_VAUX_EN) {
998 version = (value32 & TYPE_ID) ? VERSION_A_CHIP_92C :
999 VERSION_A_CHIP_88C;
1000 } else {
1001 version = (value32 & TYPE_ID) ? VERSION_B_CHIP_92C :
1002 VERSION_B_CHIP_88C;
1005 switch (version) {
1006 case VERSION_B_CHIP_92C:
1007 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1008 ("Chip Version ID: VERSION_B_CHIP_92C.\n"));
1009 break;
1010 case VERSION_B_CHIP_88C:
1011 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1012 ("Chip Version ID: VERSION_B_CHIP_88C.\n"));
1013 break;
1014 case VERSION_A_CHIP_92C:
1015 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1016 ("Chip Version ID: VERSION_A_CHIP_92C.\n"));
1017 break;
1018 case VERSION_A_CHIP_88C:
1019 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1020 ("Chip Version ID: VERSION_A_CHIP_88C.\n"));
1021 break;
1022 default:
1023 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1024 ("Chip Version ID: Unknown. Bug?\n"));
1025 break;
1028 switch (version & 0x3) {
1029 case CHIP_88C:
1030 rtlphy->rf_type = RF_1T1R;
1031 break;
1032 case CHIP_92C:
1033 rtlphy->rf_type = RF_2T2R;
1034 break;
1035 case CHIP_92C_1T2R:
1036 rtlphy->rf_type = RF_1T2R;
1037 break;
1038 default:
1039 rtlphy->rf_type = RF_1T1R;
1040 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1041 ("ERROR RF_Type is set!!"));
1042 break;
1045 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1046 ("Chip RF Type: %s\n", (rtlphy->rf_type == RF_2T2R) ?
1047 "RF_2T2R" : "RF_1T1R"));
1049 return version;
1052 static int _rtl92ce_set_media_status(struct ieee80211_hw *hw,
1053 enum nl80211_iftype type)
1055 struct rtl_priv *rtlpriv = rtl_priv(hw);
1056 u8 bt_msr = rtl_read_byte(rtlpriv, MSR);
1057 enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
1058 bt_msr &= 0xfc;
1060 if (type == NL80211_IFTYPE_UNSPECIFIED ||
1061 type == NL80211_IFTYPE_STATION) {
1062 _rtl92ce_stop_tx_beacon(hw);
1063 _rtl92ce_enable_bcn_sub_func(hw);
1064 } else if (type == NL80211_IFTYPE_ADHOC || type == NL80211_IFTYPE_AP) {
1065 _rtl92ce_resume_tx_beacon(hw);
1066 _rtl92ce_disable_bcn_sub_func(hw);
1067 } else {
1068 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1069 ("Set HW_VAR_MEDIA_STATUS: "
1070 "No such media status(%x).\n", type));
1073 switch (type) {
1074 case NL80211_IFTYPE_UNSPECIFIED:
1075 bt_msr |= MSR_NOLINK;
1076 ledaction = LED_CTL_LINK;
1077 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1078 ("Set Network type to NO LINK!\n"));
1079 break;
1080 case NL80211_IFTYPE_ADHOC:
1081 bt_msr |= MSR_ADHOC;
1082 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1083 ("Set Network type to Ad Hoc!\n"));
1084 break;
1085 case NL80211_IFTYPE_STATION:
1086 bt_msr |= MSR_INFRA;
1087 ledaction = LED_CTL_LINK;
1088 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1089 ("Set Network type to STA!\n"));
1090 break;
1091 case NL80211_IFTYPE_AP:
1092 bt_msr |= MSR_AP;
1093 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1094 ("Set Network type to AP!\n"));
1095 break;
1096 default:
1097 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1098 ("Network type %d not support!\n", type));
1099 return 1;
1100 break;
1104 rtl_write_byte(rtlpriv, (MSR), bt_msr);
1105 rtlpriv->cfg->ops->led_control(hw, ledaction);
1106 if ((bt_msr & 0xfc) == MSR_AP)
1107 rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
1108 else
1109 rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
1110 return 0;
1113 void rtl92ce_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
1115 struct rtl_priv *rtlpriv = rtl_priv(hw);
1116 u32 reg_rcr = rtl_read_dword(rtlpriv, REG_RCR);
1118 if (rtlpriv->psc.rfpwr_state != ERFON)
1119 return;
1121 if (check_bssid) {
1122 reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1123 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
1124 (u8 *) (&reg_rcr));
1125 _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
1126 } else if (check_bssid == false) {
1127 reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
1128 _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
1129 rtlpriv->cfg->ops->set_hw_reg(hw,
1130 HW_VAR_RCR, (u8 *) (&reg_rcr));
1135 int rtl92ce_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type)
1137 struct rtl_priv *rtlpriv = rtl_priv(hw);
1139 if (_rtl92ce_set_media_status(hw, type))
1140 return -EOPNOTSUPP;
1142 if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
1143 if (type != NL80211_IFTYPE_AP)
1144 rtl92ce_set_check_bssid(hw, true);
1145 } else {
1146 rtl92ce_set_check_bssid(hw, false);
1149 return 0;
1152 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1153 void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci)
1155 struct rtl_priv *rtlpriv = rtl_priv(hw);
1156 rtl92c_dm_init_edca_turbo(hw);
1157 switch (aci) {
1158 case AC1_BK:
1159 rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
1160 break;
1161 case AC0_BE:
1162 /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
1163 break;
1164 case AC2_VI:
1165 rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
1166 break;
1167 case AC3_VO:
1168 rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
1169 break;
1170 default:
1171 RT_ASSERT(false, ("invalid aci: %d !\n", aci));
1172 break;
1176 void rtl92ce_enable_interrupt(struct ieee80211_hw *hw)
1178 struct rtl_priv *rtlpriv = rtl_priv(hw);
1179 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1181 rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF);
1182 rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF);
1185 void rtl92ce_disable_interrupt(struct ieee80211_hw *hw)
1187 struct rtl_priv *rtlpriv = rtl_priv(hw);
1188 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1190 rtl_write_dword(rtlpriv, REG_HIMR, IMR8190_DISABLED);
1191 rtl_write_dword(rtlpriv, REG_HIMRE, IMR8190_DISABLED);
1192 synchronize_irq(rtlpci->pdev->irq);
1195 static void _rtl92ce_poweroff_adapter(struct ieee80211_hw *hw)
1197 struct rtl_priv *rtlpriv = rtl_priv(hw);
1198 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1199 u8 u1b_tmp;
1200 u32 u4b_tmp;
1202 rtlpriv->intf_ops->enable_aspm(hw);
1203 rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
1204 rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
1205 rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
1206 rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
1207 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
1208 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE0);
1209 if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7))
1210 rtl92c_firmware_selfreset(hw);
1211 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, 0x51);
1212 rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
1213 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00000000);
1214 u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL);
1215 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
1216 ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
1217 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8))) {
1218 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00F30000 |
1219 (u1b_tmp << 8));
1220 } else {
1221 rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00FF0000 |
1222 (u1b_tmp << 8));
1224 rtl_write_word(rtlpriv, REG_GPIO_IO_SEL, 0x0790);
1225 rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080);
1226 rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80);
1227 rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23);
1228 if (rtlpcipriv->bt_coexist.bt_coexistence) {
1229 u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
1230 u4b_tmp |= 0x03824800;
1231 rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
1232 } else {
1233 rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, 0x0e);
1236 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
1237 rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x10);
1240 void rtl92ce_card_disable(struct ieee80211_hw *hw)
1242 struct rtl_priv *rtlpriv = rtl_priv(hw);
1243 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1244 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1245 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1246 enum nl80211_iftype opmode;
1248 mac->link_state = MAC80211_NOLINK;
1249 opmode = NL80211_IFTYPE_UNSPECIFIED;
1250 _rtl92ce_set_media_status(hw, opmode);
1251 if (rtlpci->driver_is_goingto_unload ||
1252 ppsc->rfoff_reason > RF_CHANGE_BY_PS)
1253 rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
1254 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
1255 _rtl92ce_poweroff_adapter(hw);
1258 void rtl92ce_interrupt_recognized(struct ieee80211_hw *hw,
1259 u32 *p_inta, u32 *p_intb)
1261 struct rtl_priv *rtlpriv = rtl_priv(hw);
1262 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1264 *p_inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
1265 rtl_write_dword(rtlpriv, ISR, *p_inta);
1268 * *p_intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1];
1269 * rtl_write_dword(rtlpriv, ISR + 4, *p_intb);
1273 void rtl92ce_set_beacon_related_registers(struct ieee80211_hw *hw)
1276 struct rtl_priv *rtlpriv = rtl_priv(hw);
1277 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1278 u16 bcn_interval, atim_window;
1280 bcn_interval = mac->beacon_interval;
1281 atim_window = 2; /*FIX MERGE */
1282 rtl92ce_disable_interrupt(hw);
1283 rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
1284 rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1285 rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
1286 rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
1287 rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
1288 rtl_write_byte(rtlpriv, 0x606, 0x30);
1289 rtl92ce_enable_interrupt(hw);
1292 void rtl92ce_set_beacon_interval(struct ieee80211_hw *hw)
1294 struct rtl_priv *rtlpriv = rtl_priv(hw);
1295 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1296 u16 bcn_interval = mac->beacon_interval;
1298 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
1299 ("beacon_interval:%d\n", bcn_interval));
1300 rtl92ce_disable_interrupt(hw);
1301 rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1302 rtl92ce_enable_interrupt(hw);
1305 void rtl92ce_update_interrupt_mask(struct ieee80211_hw *hw,
1306 u32 add_msr, u32 rm_msr)
1308 struct rtl_priv *rtlpriv = rtl_priv(hw);
1309 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1311 RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
1312 ("add_msr:%x, rm_msr:%x\n", add_msr, rm_msr));
1314 if (add_msr)
1315 rtlpci->irq_mask[0] |= add_msr;
1316 if (rm_msr)
1317 rtlpci->irq_mask[0] &= (~rm_msr);
1318 rtl92ce_disable_interrupt(hw);
1319 rtl92ce_enable_interrupt(hw);
1322 static void _rtl92ce_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
1323 bool autoload_fail,
1324 u8 *hwinfo)
1326 struct rtl_priv *rtlpriv = rtl_priv(hw);
1327 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1328 u8 rf_path, index, tempval;
1329 u16 i;
1331 for (rf_path = 0; rf_path < 2; rf_path++) {
1332 for (i = 0; i < 3; i++) {
1333 if (!autoload_fail) {
1334 rtlefuse->
1335 eeprom_chnlarea_txpwr_cck[rf_path][i] =
1336 hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i];
1337 rtlefuse->
1338 eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
1339 hwinfo[EEPROM_TXPOWERHT40_1S + rf_path * 3 +
1341 } else {
1342 rtlefuse->
1343 eeprom_chnlarea_txpwr_cck[rf_path][i] =
1344 EEPROM_DEFAULT_TXPOWERLEVEL;
1345 rtlefuse->
1346 eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
1347 EEPROM_DEFAULT_TXPOWERLEVEL;
1352 for (i = 0; i < 3; i++) {
1353 if (!autoload_fail)
1354 tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i];
1355 else
1356 tempval = EEPROM_DEFAULT_HT40_2SDIFF;
1357 rtlefuse->eeprom_chnlarea_txpwr_ht40_2sdiif[RF90_PATH_A][i] =
1358 (tempval & 0xf);
1359 rtlefuse->eeprom_chnlarea_txpwr_ht40_2sdiif[RF90_PATH_B][i] =
1360 ((tempval & 0xf0) >> 4);
1363 for (rf_path = 0; rf_path < 2; rf_path++)
1364 for (i = 0; i < 3; i++)
1365 RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1366 ("RF(%d) EEPROM CCK Area(%d) = 0x%x\n", rf_path,
1368 rtlefuse->
1369 eeprom_chnlarea_txpwr_cck[rf_path][i]));
1370 for (rf_path = 0; rf_path < 2; rf_path++)
1371 for (i = 0; i < 3; i++)
1372 RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1373 ("RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1374 rf_path, i,
1375 rtlefuse->
1376 eeprom_chnlarea_txpwr_ht40_1s[rf_path][i]));
1377 for (rf_path = 0; rf_path < 2; rf_path++)
1378 for (i = 0; i < 3; i++)
1379 RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1380 ("RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1381 rf_path, i,
1382 rtlefuse->
1383 eeprom_chnlarea_txpwr_ht40_2sdiif[rf_path]
1384 [i]));
1386 for (rf_path = 0; rf_path < 2; rf_path++) {
1387 for (i = 0; i < 14; i++) {
1388 index = _rtl92c_get_chnl_group((u8) i);
1390 rtlefuse->txpwrlevel_cck[rf_path][i] =
1391 rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][index];
1392 rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
1393 rtlefuse->
1394 eeprom_chnlarea_txpwr_ht40_1s[rf_path][index];
1396 if ((rtlefuse->
1397 eeprom_chnlarea_txpwr_ht40_1s[rf_path][index] -
1398 rtlefuse->
1399 eeprom_chnlarea_txpwr_ht40_2sdiif[rf_path][index])
1400 > 0) {
1401 rtlefuse->txpwrlevel_ht40_2s[rf_path][i] =
1402 rtlefuse->
1403 eeprom_chnlarea_txpwr_ht40_1s[rf_path]
1404 [index] -
1405 rtlefuse->
1406 eeprom_chnlarea_txpwr_ht40_2sdiif[rf_path]
1407 [index];
1408 } else {
1409 rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0;
1413 for (i = 0; i < 14; i++) {
1414 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1415 ("RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = "
1416 "[0x%x / 0x%x / 0x%x]\n", rf_path, i,
1417 rtlefuse->txpwrlevel_cck[rf_path][i],
1418 rtlefuse->txpwrlevel_ht40_1s[rf_path][i],
1419 rtlefuse->txpwrlevel_ht40_2s[rf_path][i]));
1423 for (i = 0; i < 3; i++) {
1424 if (!autoload_fail) {
1425 rtlefuse->eeprom_pwrlimit_ht40[i] =
1426 hwinfo[EEPROM_TXPWR_GROUP + i];
1427 rtlefuse->eeprom_pwrlimit_ht20[i] =
1428 hwinfo[EEPROM_TXPWR_GROUP + 3 + i];
1429 } else {
1430 rtlefuse->eeprom_pwrlimit_ht40[i] = 0;
1431 rtlefuse->eeprom_pwrlimit_ht20[i] = 0;
1435 for (rf_path = 0; rf_path < 2; rf_path++) {
1436 for (i = 0; i < 14; i++) {
1437 index = _rtl92c_get_chnl_group((u8) i);
1439 if (rf_path == RF90_PATH_A) {
1440 rtlefuse->pwrgroup_ht20[rf_path][i] =
1441 (rtlefuse->eeprom_pwrlimit_ht20[index]
1442 & 0xf);
1443 rtlefuse->pwrgroup_ht40[rf_path][i] =
1444 (rtlefuse->eeprom_pwrlimit_ht40[index]
1445 & 0xf);
1446 } else if (rf_path == RF90_PATH_B) {
1447 rtlefuse->pwrgroup_ht20[rf_path][i] =
1448 ((rtlefuse->eeprom_pwrlimit_ht20[index]
1449 & 0xf0) >> 4);
1450 rtlefuse->pwrgroup_ht40[rf_path][i] =
1451 ((rtlefuse->eeprom_pwrlimit_ht40[index]
1452 & 0xf0) >> 4);
1455 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1456 ("RF-%d pwrgroup_ht20[%d] = 0x%x\n",
1457 rf_path, i,
1458 rtlefuse->pwrgroup_ht20[rf_path][i]));
1459 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1460 ("RF-%d pwrgroup_ht40[%d] = 0x%x\n",
1461 rf_path, i,
1462 rtlefuse->pwrgroup_ht40[rf_path][i]));
1466 for (i = 0; i < 14; i++) {
1467 index = _rtl92c_get_chnl_group((u8) i);
1469 if (!autoload_fail)
1470 tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index];
1471 else
1472 tempval = EEPROM_DEFAULT_HT20_DIFF;
1474 rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF);
1475 rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] =
1476 ((tempval >> 4) & 0xF);
1478 if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3))
1479 rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0;
1481 if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3))
1482 rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0;
1484 index = _rtl92c_get_chnl_group((u8) i);
1486 if (!autoload_fail)
1487 tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index];
1488 else
1489 tempval = EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF;
1491 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF);
1492 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] =
1493 ((tempval >> 4) & 0xF);
1496 rtlefuse->legacy_ht_txpowerdiff =
1497 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7];
1499 for (i = 0; i < 14; i++)
1500 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1501 ("RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", i,
1502 rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]));
1503 for (i = 0; i < 14; i++)
1504 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1505 ("RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", i,
1506 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]));
1507 for (i = 0; i < 14; i++)
1508 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1509 ("RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", i,
1510 rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]));
1511 for (i = 0; i < 14; i++)
1512 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1513 ("RF-B Legacy to HT40 Diff[%d] = 0x%x\n", i,
1514 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]));
1516 if (!autoload_fail)
1517 rtlefuse->eeprom_regulatory = (hwinfo[RF_OPTION1] & 0x7);
1518 else
1519 rtlefuse->eeprom_regulatory = 0;
1520 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1521 ("eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory));
1523 if (!autoload_fail) {
1524 rtlefuse->eeprom_tssi[RF90_PATH_A] = hwinfo[EEPROM_TSSI_A];
1525 rtlefuse->eeprom_tssi[RF90_PATH_B] = hwinfo[EEPROM_TSSI_B];
1526 } else {
1527 rtlefuse->eeprom_tssi[RF90_PATH_A] = EEPROM_DEFAULT_TSSI;
1528 rtlefuse->eeprom_tssi[RF90_PATH_B] = EEPROM_DEFAULT_TSSI;
1530 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1531 ("TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1532 rtlefuse->eeprom_tssi[RF90_PATH_A],
1533 rtlefuse->eeprom_tssi[RF90_PATH_B]));
1535 if (!autoload_fail)
1536 tempval = hwinfo[EEPROM_THERMAL_METER];
1537 else
1538 tempval = EEPROM_DEFAULT_THERMALMETER;
1539 rtlefuse->eeprom_thermalmeter = (tempval & 0x1f);
1541 if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail)
1542 rtlefuse->apk_thermalmeterignore = true;
1544 rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
1545 RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1546 ("thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter));
1549 static void _rtl92ce_read_adapter_info(struct ieee80211_hw *hw)
1551 struct rtl_priv *rtlpriv = rtl_priv(hw);
1552 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1553 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1554 u16 i, usvalue;
1555 u8 hwinfo[HWSET_MAX_SIZE];
1556 u16 eeprom_id;
1558 if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
1559 rtl_efuse_shadow_map_update(hw);
1561 memcpy((void *)hwinfo,
1562 (void *)&rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
1563 HWSET_MAX_SIZE);
1564 } else if (rtlefuse->epromtype == EEPROM_93C46) {
1565 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1566 ("RTL819X Not boot from eeprom, check it !!"));
1569 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, ("MAP\n"),
1570 hwinfo, HWSET_MAX_SIZE);
1572 eeprom_id = *((u16 *)&hwinfo[0]);
1573 if (eeprom_id != RTL8190_EEPROM_ID) {
1574 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1575 ("EEPROM ID(%#x) is invalid!!\n", eeprom_id));
1576 rtlefuse->autoload_failflag = true;
1577 } else {
1578 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("Autoload OK\n"));
1579 rtlefuse->autoload_failflag = false;
1582 if (rtlefuse->autoload_failflag)
1583 return;
1585 for (i = 0; i < 6; i += 2) {
1586 usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
1587 *((u16 *) (&rtlefuse->dev_addr[i])) = usvalue;
1590 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1591 ("%pM\n", rtlefuse->dev_addr));
1593 _rtl92ce_read_txpower_info_from_hwpg(hw,
1594 rtlefuse->autoload_failflag,
1595 hwinfo);
1597 rtl8192ce_read_bt_coexist_info_from_hwpg(hw,
1598 rtlefuse->autoload_failflag,
1599 hwinfo);
1601 rtlefuse->eeprom_channelplan = *(u8 *)&hwinfo[EEPROM_CHANNELPLAN];
1602 rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
1603 rtlefuse->txpwr_fromeprom = true;
1604 rtlefuse->eeprom_oemid = *(u8 *)&hwinfo[EEPROM_CUSTOMER_ID];
1606 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1607 ("EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid));
1609 /* set channel paln to world wide 13 */
1610 rtlefuse->channel_plan = COUNTRY_CODE_WORLD_WIDE_13;
1612 if (rtlhal->oem_id == RT_CID_DEFAULT) {
1613 switch (rtlefuse->eeprom_oemid) {
1614 case EEPROM_CID_DEFAULT:
1615 if (rtlefuse->eeprom_did == 0x8176) {
1616 if ((rtlefuse->eeprom_svid == 0x103C &&
1617 rtlefuse->eeprom_smid == 0x1629))
1618 rtlhal->oem_id = RT_CID_819x_HP;
1619 else
1620 rtlhal->oem_id = RT_CID_DEFAULT;
1621 } else {
1622 rtlhal->oem_id = RT_CID_DEFAULT;
1624 break;
1625 case EEPROM_CID_TOSHIBA:
1626 rtlhal->oem_id = RT_CID_TOSHIBA;
1627 break;
1628 case EEPROM_CID_QMI:
1629 rtlhal->oem_id = RT_CID_819x_QMI;
1630 break;
1631 case EEPROM_CID_WHQL:
1632 default:
1633 rtlhal->oem_id = RT_CID_DEFAULT;
1634 break;
1641 static void _rtl92ce_hal_customized_behavior(struct ieee80211_hw *hw)
1643 struct rtl_priv *rtlpriv = rtl_priv(hw);
1644 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
1645 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1647 switch (rtlhal->oem_id) {
1648 case RT_CID_819x_HP:
1649 pcipriv->ledctl.led_opendrain = true;
1650 break;
1651 case RT_CID_819x_Lenovo:
1652 case RT_CID_DEFAULT:
1653 case RT_CID_TOSHIBA:
1654 case RT_CID_CCX:
1655 case RT_CID_819x_Acer:
1656 case RT_CID_WHQL:
1657 default:
1658 break;
1660 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1661 ("RT Customized ID: 0x%02X\n", rtlhal->oem_id));
1664 void rtl92ce_read_eeprom_info(struct ieee80211_hw *hw)
1666 struct rtl_priv *rtlpriv = rtl_priv(hw);
1667 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1668 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1669 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1670 u8 tmp_u1b;
1672 rtlhal->version = _rtl92ce_read_chip_version(hw);
1673 if (get_rf_type(rtlphy) == RF_1T1R)
1674 rtlpriv->dm.rfpath_rxenable[0] = true;
1675 else
1676 rtlpriv->dm.rfpath_rxenable[0] =
1677 rtlpriv->dm.rfpath_rxenable[1] = true;
1678 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("VersionID = 0x%4x\n",
1679 rtlhal->version));
1680 tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
1681 if (tmp_u1b & BIT(4)) {
1682 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("Boot from EEPROM\n"));
1683 rtlefuse->epromtype = EEPROM_93C46;
1684 } else {
1685 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("Boot from EFUSE\n"));
1686 rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
1688 if (tmp_u1b & BIT(5)) {
1689 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("Autoload OK\n"));
1690 rtlefuse->autoload_failflag = false;
1691 _rtl92ce_read_adapter_info(hw);
1692 } else {
1693 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("Autoload ERR!!\n"));
1695 _rtl92ce_hal_customized_behavior(hw);
1698 static void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw,
1699 struct ieee80211_sta *sta)
1701 struct rtl_priv *rtlpriv = rtl_priv(hw);
1702 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1703 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1704 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1705 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1706 u32 ratr_value;
1707 u8 ratr_index = 0;
1708 u8 nmode = mac->ht_enable;
1709 u8 mimo_ps = IEEE80211_SMPS_OFF;
1710 u16 shortgi_rate;
1711 u32 tmp_ratr_value;
1712 u8 curtxbw_40mhz = mac->bw_40;
1713 u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1714 1 : 0;
1715 u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1716 1 : 0;
1717 enum wireless_mode wirelessmode = mac->mode;
1719 if (rtlhal->current_bandtype == BAND_ON_5G)
1720 ratr_value = sta->supp_rates[1] << 4;
1721 else
1722 ratr_value = sta->supp_rates[0];
1723 ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1724 sta->ht_cap.mcs.rx_mask[0] << 12);
1725 switch (wirelessmode) {
1726 case WIRELESS_MODE_B:
1727 if (ratr_value & 0x0000000c)
1728 ratr_value &= 0x0000000d;
1729 else
1730 ratr_value &= 0x0000000f;
1731 break;
1732 case WIRELESS_MODE_G:
1733 ratr_value &= 0x00000FF5;
1734 break;
1735 case WIRELESS_MODE_N_24G:
1736 case WIRELESS_MODE_N_5G:
1737 nmode = 1;
1738 if (mimo_ps == IEEE80211_SMPS_STATIC) {
1739 ratr_value &= 0x0007F005;
1740 } else {
1741 u32 ratr_mask;
1743 if (get_rf_type(rtlphy) == RF_1T2R ||
1744 get_rf_type(rtlphy) == RF_1T1R)
1745 ratr_mask = 0x000ff005;
1746 else
1747 ratr_mask = 0x0f0ff005;
1749 ratr_value &= ratr_mask;
1751 break;
1752 default:
1753 if (rtlphy->rf_type == RF_1T2R)
1754 ratr_value &= 0x000ff0ff;
1755 else
1756 ratr_value &= 0x0f0ff0ff;
1758 break;
1761 if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
1762 (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) &&
1763 (rtlpcipriv->bt_coexist.bt_cur_state) &&
1764 (rtlpcipriv->bt_coexist.bt_ant_isolation) &&
1765 ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ||
1766 (rtlpcipriv->bt_coexist.bt_service == BT_BUSY)))
1767 ratr_value &= 0x0fffcfc0;
1768 else
1769 ratr_value &= 0x0FFFFFFF;
1771 if (nmode && ((curtxbw_40mhz &&
1772 curshortgi_40mhz) || (!curtxbw_40mhz &&
1773 curshortgi_20mhz))) {
1775 ratr_value |= 0x10000000;
1776 tmp_ratr_value = (ratr_value >> 12);
1778 for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
1779 if ((1 << shortgi_rate) & tmp_ratr_value)
1780 break;
1783 shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
1784 (shortgi_rate << 4) | (shortgi_rate);
1787 rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
1789 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1790 ("%x\n", rtl_read_dword(rtlpriv, REG_ARFR0)));
1793 static void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw,
1794 struct ieee80211_sta *sta, u8 rssi_level)
1796 struct rtl_priv *rtlpriv = rtl_priv(hw);
1797 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1798 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1799 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1800 struct rtl_sta_info *sta_entry = NULL;
1801 u32 ratr_bitmap;
1802 u8 ratr_index;
1803 u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
1804 ? 1 : 0;
1805 u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1806 1 : 0;
1807 u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1808 1 : 0;
1809 enum wireless_mode wirelessmode = 0;
1810 bool shortgi = false;
1811 u8 rate_mask[5];
1812 u8 macid = 0;
1813 u8 mimo_ps = IEEE80211_SMPS_OFF;
1815 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
1816 wirelessmode = sta_entry->wireless_mode;
1817 if (mac->opmode == NL80211_IFTYPE_STATION)
1818 curtxbw_40mhz = mac->bw_40;
1819 else if (mac->opmode == NL80211_IFTYPE_AP ||
1820 mac->opmode == NL80211_IFTYPE_ADHOC)
1821 macid = sta->aid + 1;
1823 if (rtlhal->current_bandtype == BAND_ON_5G)
1824 ratr_bitmap = sta->supp_rates[1] << 4;
1825 else
1826 ratr_bitmap = sta->supp_rates[0];
1827 ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1828 sta->ht_cap.mcs.rx_mask[0] << 12);
1829 switch (wirelessmode) {
1830 case WIRELESS_MODE_B:
1831 ratr_index = RATR_INX_WIRELESS_B;
1832 if (ratr_bitmap & 0x0000000c)
1833 ratr_bitmap &= 0x0000000d;
1834 else
1835 ratr_bitmap &= 0x0000000f;
1836 break;
1837 case WIRELESS_MODE_G:
1838 ratr_index = RATR_INX_WIRELESS_GB;
1840 if (rssi_level == 1)
1841 ratr_bitmap &= 0x00000f00;
1842 else if (rssi_level == 2)
1843 ratr_bitmap &= 0x00000ff0;
1844 else
1845 ratr_bitmap &= 0x00000ff5;
1846 break;
1847 case WIRELESS_MODE_A:
1848 ratr_index = RATR_INX_WIRELESS_A;
1849 ratr_bitmap &= 0x00000ff0;
1850 break;
1851 case WIRELESS_MODE_N_24G:
1852 case WIRELESS_MODE_N_5G:
1853 ratr_index = RATR_INX_WIRELESS_NGB;
1855 if (mimo_ps == IEEE80211_SMPS_STATIC) {
1856 if (rssi_level == 1)
1857 ratr_bitmap &= 0x00070000;
1858 else if (rssi_level == 2)
1859 ratr_bitmap &= 0x0007f000;
1860 else
1861 ratr_bitmap &= 0x0007f005;
1862 } else {
1863 if (rtlphy->rf_type == RF_1T2R ||
1864 rtlphy->rf_type == RF_1T1R) {
1865 if (curtxbw_40mhz) {
1866 if (rssi_level == 1)
1867 ratr_bitmap &= 0x000f0000;
1868 else if (rssi_level == 2)
1869 ratr_bitmap &= 0x000ff000;
1870 else
1871 ratr_bitmap &= 0x000ff015;
1872 } else {
1873 if (rssi_level == 1)
1874 ratr_bitmap &= 0x000f0000;
1875 else if (rssi_level == 2)
1876 ratr_bitmap &= 0x000ff000;
1877 else
1878 ratr_bitmap &= 0x000ff005;
1880 } else {
1881 if (curtxbw_40mhz) {
1882 if (rssi_level == 1)
1883 ratr_bitmap &= 0x0f0f0000;
1884 else if (rssi_level == 2)
1885 ratr_bitmap &= 0x0f0ff000;
1886 else
1887 ratr_bitmap &= 0x0f0ff015;
1888 } else {
1889 if (rssi_level == 1)
1890 ratr_bitmap &= 0x0f0f0000;
1891 else if (rssi_level == 2)
1892 ratr_bitmap &= 0x0f0ff000;
1893 else
1894 ratr_bitmap &= 0x0f0ff005;
1899 if ((curtxbw_40mhz && curshortgi_40mhz) ||
1900 (!curtxbw_40mhz && curshortgi_20mhz)) {
1902 if (macid == 0)
1903 shortgi = true;
1904 else if (macid == 1)
1905 shortgi = false;
1907 break;
1908 default:
1909 ratr_index = RATR_INX_WIRELESS_NGB;
1911 if (rtlphy->rf_type == RF_1T2R)
1912 ratr_bitmap &= 0x000ff0ff;
1913 else
1914 ratr_bitmap &= 0x0f0ff0ff;
1915 break;
1917 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1918 ("ratr_bitmap :%x\n", ratr_bitmap));
1919 *(u32 *)&rate_mask = EF4BYTE((ratr_bitmap & 0x0fffffff) |
1920 (ratr_index << 28));
1921 rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
1922 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, ("Rate_index:%x, "
1923 "ratr_val:%x, %x:%x:%x:%x:%x\n",
1924 ratr_index, ratr_bitmap,
1925 rate_mask[0], rate_mask[1],
1926 rate_mask[2], rate_mask[3],
1927 rate_mask[4]));
1928 rtl92c_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask);
1930 if (macid != 0)
1931 sta_entry->ratr_index = ratr_index;
1934 void rtl92ce_update_hal_rate_tbl(struct ieee80211_hw *hw,
1935 struct ieee80211_sta *sta, u8 rssi_level)
1937 struct rtl_priv *rtlpriv = rtl_priv(hw);
1939 if (rtlpriv->dm.useramask)
1940 rtl92ce_update_hal_rate_mask(hw, sta, rssi_level);
1941 else
1942 rtl92ce_update_hal_rate_table(hw, sta);
1945 void rtl92ce_update_channel_access_setting(struct ieee80211_hw *hw)
1947 struct rtl_priv *rtlpriv = rtl_priv(hw);
1948 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1949 u16 sifs_timer;
1951 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
1952 (u8 *)&mac->slot_time);
1953 if (!mac->ht_enable)
1954 sifs_timer = 0x0a0a;
1955 else
1956 sifs_timer = 0x1010;
1957 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
1960 bool rtl92ce_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
1962 struct rtl_priv *rtlpriv = rtl_priv(hw);
1963 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1964 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1965 enum rf_pwrstate e_rfpowerstate_toset;
1966 u8 u1tmp;
1967 bool actuallyset = false;
1968 unsigned long flag;
1970 if (rtlpci->being_init_adapter)
1971 return false;
1973 if (ppsc->swrf_processing)
1974 return false;
1976 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
1977 if (ppsc->rfchange_inprogress) {
1978 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
1979 return false;
1980 } else {
1981 ppsc->rfchange_inprogress = true;
1982 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
1985 rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, rtl_read_byte(rtlpriv,
1986 REG_MAC_PINMUX_CFG)&~(BIT(3)));
1988 u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL);
1989 e_rfpowerstate_toset = (u1tmp & BIT(3)) ? ERFON : ERFOFF;
1991 if ((ppsc->hwradiooff) && (e_rfpowerstate_toset == ERFON)) {
1992 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1993 ("GPIOChangeRF - HW Radio ON, RF ON\n"));
1995 e_rfpowerstate_toset = ERFON;
1996 ppsc->hwradiooff = false;
1997 actuallyset = true;
1998 } else if ((ppsc->hwradiooff == false)
1999 && (e_rfpowerstate_toset == ERFOFF)) {
2000 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2001 ("GPIOChangeRF - HW Radio OFF, RF OFF\n"));
2003 e_rfpowerstate_toset = ERFOFF;
2004 ppsc->hwradiooff = true;
2005 actuallyset = true;
2008 if (actuallyset) {
2009 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2010 ppsc->rfchange_inprogress = false;
2011 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2012 } else {
2013 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
2014 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
2016 spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2017 ppsc->rfchange_inprogress = false;
2018 spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2021 *valid = 1;
2022 return !ppsc->hwradiooff;
2026 void rtl92ce_set_key(struct ieee80211_hw *hw, u32 key_index,
2027 u8 *p_macaddr, bool is_group, u8 enc_algo,
2028 bool is_wepkey, bool clear_all)
2030 struct rtl_priv *rtlpriv = rtl_priv(hw);
2031 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2032 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2033 u8 *macaddr = p_macaddr;
2034 u32 entry_id = 0;
2035 bool is_pairwise = false;
2037 static u8 cam_const_addr[4][6] = {
2038 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2039 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2040 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2041 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2043 static u8 cam_const_broad[] = {
2044 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2047 if (clear_all) {
2048 u8 idx = 0;
2049 u8 cam_offset = 0;
2050 u8 clear_number = 5;
2052 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, ("clear_all\n"));
2054 for (idx = 0; idx < clear_number; idx++) {
2055 rtl_cam_mark_invalid(hw, cam_offset + idx);
2056 rtl_cam_empty_entry(hw, cam_offset + idx);
2058 if (idx < 5) {
2059 memset(rtlpriv->sec.key_buf[idx], 0,
2060 MAX_KEY_LEN);
2061 rtlpriv->sec.key_len[idx] = 0;
2065 } else {
2066 switch (enc_algo) {
2067 case WEP40_ENCRYPTION:
2068 enc_algo = CAM_WEP40;
2069 break;
2070 case WEP104_ENCRYPTION:
2071 enc_algo = CAM_WEP104;
2072 break;
2073 case TKIP_ENCRYPTION:
2074 enc_algo = CAM_TKIP;
2075 break;
2076 case AESCCMP_ENCRYPTION:
2077 enc_algo = CAM_AES;
2078 break;
2079 default:
2080 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, ("switch case "
2081 "not process\n"));
2082 enc_algo = CAM_TKIP;
2083 break;
2086 if (is_wepkey || rtlpriv->sec.use_defaultkey) {
2087 macaddr = cam_const_addr[key_index];
2088 entry_id = key_index;
2089 } else {
2090 if (is_group) {
2091 macaddr = cam_const_broad;
2092 entry_id = key_index;
2093 } else {
2094 if (mac->opmode == NL80211_IFTYPE_AP) {
2095 entry_id = rtl_cam_get_free_entry(hw,
2096 p_macaddr);
2097 if (entry_id >= TOTAL_CAM_ENTRY) {
2098 RT_TRACE(rtlpriv, COMP_SEC,
2099 DBG_EMERG,
2100 ("Can not find free hw"
2101 " security cam entry\n"));
2102 return;
2104 } else {
2105 entry_id = CAM_PAIRWISE_KEY_POSITION;
2108 key_index = PAIRWISE_KEYIDX;
2109 is_pairwise = true;
2113 if (rtlpriv->sec.key_len[key_index] == 0) {
2114 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2115 ("delete one entry, entry_id is %d\n",
2116 entry_id));
2117 if (mac->opmode == NL80211_IFTYPE_AP)
2118 rtl_cam_del_entry(hw, p_macaddr);
2119 rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
2120 } else {
2121 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
2122 ("The insert KEY length is %d\n",
2123 rtlpriv->sec.key_len[PAIRWISE_KEYIDX]));
2124 RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
2125 ("The insert KEY is %x %x\n",
2126 rtlpriv->sec.key_buf[0][0],
2127 rtlpriv->sec.key_buf[0][1]));
2129 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2130 ("add one entry\n"));
2131 if (is_pairwise) {
2132 RT_PRINT_DATA(rtlpriv, COMP_SEC, DBG_LOUD,
2133 "Pairwiase Key content :",
2134 rtlpriv->sec.pairwise_key,
2135 rtlpriv->sec.
2136 key_len[PAIRWISE_KEYIDX]);
2138 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2139 ("set Pairwiase key\n"));
2141 rtl_cam_add_one_entry(hw, macaddr, key_index,
2142 entry_id, enc_algo,
2143 CAM_CONFIG_NO_USEDK,
2144 rtlpriv->sec.
2145 key_buf[key_index]);
2146 } else {
2147 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2148 ("set group key\n"));
2150 if (mac->opmode == NL80211_IFTYPE_ADHOC) {
2151 rtl_cam_add_one_entry(hw,
2152 rtlefuse->dev_addr,
2153 PAIRWISE_KEYIDX,
2154 CAM_PAIRWISE_KEY_POSITION,
2155 enc_algo,
2156 CAM_CONFIG_NO_USEDK,
2157 rtlpriv->sec.key_buf
2158 [entry_id]);
2161 rtl_cam_add_one_entry(hw, macaddr, key_index,
2162 entry_id, enc_algo,
2163 CAM_CONFIG_NO_USEDK,
2164 rtlpriv->sec.key_buf[entry_id]);
2171 static void rtl8192ce_bt_var_init(struct ieee80211_hw *hw)
2173 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2175 rtlpcipriv->bt_coexist.bt_coexistence =
2176 rtlpcipriv->bt_coexist.eeprom_bt_coexist;
2177 rtlpcipriv->bt_coexist.bt_ant_num =
2178 rtlpcipriv->bt_coexist.eeprom_bt_ant_num;
2179 rtlpcipriv->bt_coexist.bt_coexist_type =
2180 rtlpcipriv->bt_coexist.eeprom_bt_type;
2182 if (rtlpcipriv->bt_coexist.reg_bt_iso == 2)
2183 rtlpcipriv->bt_coexist.bt_ant_isolation =
2184 rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation;
2185 else
2186 rtlpcipriv->bt_coexist.bt_ant_isolation =
2187 rtlpcipriv->bt_coexist.reg_bt_iso;
2189 rtlpcipriv->bt_coexist.bt_radio_shared_type =
2190 rtlpcipriv->bt_coexist.eeprom_bt_radio_shared;
2192 if (rtlpcipriv->bt_coexist.bt_coexistence) {
2194 if (rtlpcipriv->bt_coexist.reg_bt_sco == 1)
2195 rtlpcipriv->bt_coexist.bt_service = BT_OTHER_ACTION;
2196 else if (rtlpcipriv->bt_coexist.reg_bt_sco == 2)
2197 rtlpcipriv->bt_coexist.bt_service = BT_SCO;
2198 else if (rtlpcipriv->bt_coexist.reg_bt_sco == 4)
2199 rtlpcipriv->bt_coexist.bt_service = BT_BUSY;
2200 else if (rtlpcipriv->bt_coexist.reg_bt_sco == 5)
2201 rtlpcipriv->bt_coexist.bt_service = BT_OTHERBUSY;
2202 else
2203 rtlpcipriv->bt_coexist.bt_service = BT_IDLE;
2205 rtlpcipriv->bt_coexist.bt_edca_ul = 0;
2206 rtlpcipriv->bt_coexist.bt_edca_dl = 0;
2207 rtlpcipriv->bt_coexist.bt_rssi_state = 0xff;
2211 void rtl8192ce_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
2212 bool auto_load_fail, u8 *hwinfo)
2214 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2215 u8 value;
2217 if (!auto_load_fail) {
2218 rtlpcipriv->bt_coexist.eeprom_bt_coexist =
2219 ((hwinfo[RF_OPTION1] & 0xe0) >> 5);
2220 value = hwinfo[RF_OPTION4];
2221 rtlpcipriv->bt_coexist.eeprom_bt_type = ((value & 0xe) >> 1);
2222 rtlpcipriv->bt_coexist.eeprom_bt_ant_num = (value & 0x1);
2223 rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation =
2224 ((value & 0x10) >> 4);
2225 rtlpcipriv->bt_coexist.eeprom_bt_radio_shared =
2226 ((value & 0x20) >> 5);
2227 } else {
2228 rtlpcipriv->bt_coexist.eeprom_bt_coexist = 0;
2229 rtlpcipriv->bt_coexist.eeprom_bt_type = BT_2WIRE;
2230 rtlpcipriv->bt_coexist.eeprom_bt_ant_num = ANT_X2;
2231 rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation = 0;
2232 rtlpcipriv->bt_coexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
2235 rtl8192ce_bt_var_init(hw);
2238 void rtl8192ce_bt_reg_init(struct ieee80211_hw *hw)
2240 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2242 /* 0:Low, 1:High, 2:From Efuse. */
2243 rtlpcipriv->bt_coexist.reg_bt_iso = 2;
2244 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2245 rtlpcipriv->bt_coexist.reg_bt_sco = 3;
2246 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2247 rtlpcipriv->bt_coexist.reg_bt_sco = 0;
2251 void rtl8192ce_bt_hw_init(struct ieee80211_hw *hw)
2253 struct rtl_priv *rtlpriv = rtl_priv(hw);
2254 struct rtl_phy *rtlphy = &(rtlpriv->phy);
2255 struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2257 u8 u1_tmp;
2259 if (rtlpcipriv->bt_coexist.bt_coexistence &&
2260 ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
2261 rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8)) {
2263 if (rtlpcipriv->bt_coexist.bt_ant_isolation)
2264 rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
2266 u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) &
2267 BIT_OFFSET_LEN_MASK_32(0, 1);
2268 u1_tmp = u1_tmp |
2269 ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ?
2270 0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
2271 ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ?
2272 0 : BIT_OFFSET_LEN_MASK_32(2, 1));
2273 rtl_write_byte(rtlpriv, 0x4fd, u1_tmp);
2275 rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa);
2276 rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040);
2277 rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010);
2279 /* Config to 1T1R. */
2280 if (rtlphy->rf_type == RF_1T1R) {
2281 u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE);
2282 u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2283 rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp);
2285 u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE);
2286 u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2287 rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp);
2292 void rtl92ce_suspend(struct ieee80211_hw *hw)
2296 void rtl92ce_resume(struct ieee80211_hw *hw)