blob: 65c9e80e1f78ad23988bb962732396153bf1f137 [file] [log] [blame]
Larry Fingerc592e632012-10-25 13:46:32 -05001/******************************************************************************
2 *
3 * Copyright(c) 2009-2012 Realtek Corporation.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
25 *
26 * Larry Finger <Larry.Finger@lwfinger.net>
27 *
28 *****************************************************************************/
29
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 "dm.h"
Larry Finger57d9d9632014-02-28 15:16:49 -060041#include "../rtl8723com/dm_common.h"
Larry Fingerc592e632012-10-25 13:46:32 -050042#include "fw.h"
Larry Fingercbd0c852014-02-28 15:16:48 -060043#include "../rtl8723com/fw_common.h"
Larry Fingerc592e632012-10-25 13:46:32 -050044#include "led.h"
45#include "hw.h"
Larry Fingerc592e632012-10-25 13:46:32 -050046#include "pwrseq.h"
47#include "btc.h"
48
49static void _rtl8723ae_set_bcn_ctrl_reg(struct ieee80211_hw *hw,
50 u8 set_bits, u8 clear_bits)
51{
52 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
53 struct rtl_priv *rtlpriv = rtl_priv(hw);
54
55 rtlpci->reg_bcn_ctrl_val |= set_bits;
56 rtlpci->reg_bcn_ctrl_val &= ~clear_bits;
57
58 rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val);
59}
60
61static void _rtl8723ae_stop_tx_beacon(struct ieee80211_hw *hw)
62{
63 struct rtl_priv *rtlpriv = rtl_priv(hw);
64 u8 tmp1byte;
65
66 tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
67 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6)));
68 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64);
69 tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
70 tmp1byte &= ~(BIT(0));
71 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
72}
73
74static void _rtl8723ae_resume_tx_beacon(struct ieee80211_hw *hw)
75{
76 struct rtl_priv *rtlpriv = rtl_priv(hw);
77 u8 tmp1byte;
78
79 tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2);
80 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6));
81 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
82 tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2);
83 tmp1byte |= BIT(1);
84 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte);
85}
86
87static void _rtl8723ae_enable_bcn_sufunc(struct ieee80211_hw *hw)
88{
89 _rtl8723ae_set_bcn_ctrl_reg(hw, 0, BIT(1));
90}
91
92static void _rtl8723ae_disable_bcn_sufunc(struct ieee80211_hw *hw)
93{
94 _rtl8723ae_set_bcn_ctrl_reg(hw, BIT(1), 0);
95}
96
97void rtl8723ae_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
98{
99 struct rtl_priv *rtlpriv = rtl_priv(hw);
100 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
101 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
102
103 switch (variable) {
104 case HW_VAR_RCR:
105 *((u32 *) (val)) = rtlpci->receive_config;
106 break;
107 case HW_VAR_RF_STATE:
108 *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state;
109 break;
110 case HW_VAR_FWLPS_RF_ON:{
111 enum rf_pwrstate rfState;
112 u32 val_rcr;
113
114 rtlpriv->cfg->ops->get_hw_reg(hw,
115 HW_VAR_RF_STATE,
116 (u8 *) (&rfState));
117 if (rfState == ERFOFF) {
118 *((bool *) (val)) = true;
119 } else {
120 val_rcr = rtl_read_dword(rtlpriv, REG_RCR);
121 val_rcr &= 0x00070000;
122 if (val_rcr)
123 *((bool *) (val)) = false;
124 else
125 *((bool *) (val)) = true;
126 }
127 break; }
128 case HW_VAR_FW_PSMODE_STATUS:
129 *((bool *) (val)) = ppsc->fw_current_inpsmode;
130 break;
131 case HW_VAR_CORRECT_TSF:{
132 u64 tsf;
133 u32 *ptsf_low = (u32 *)&tsf;
134 u32 *ptsf_high = ((u32 *)&tsf) + 1;
135
136 *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
137 *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
138
139 *((u64 *) (val)) = tsf;
140
141 break; }
142 default:
143 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
144 "switch case not process\n");
145 break;
146 }
147}
148
149void rtl8723ae_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val)
150{
151 struct rtl_priv *rtlpriv = rtl_priv(hw);
152 struct rtl_pci_priv *pcipriv = 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_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
156 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
157 u8 idx;
158
159 switch (variable) {
160 case HW_VAR_ETHER_ADDR:
161 for (idx = 0; idx < ETH_ALEN; idx++) {
162 rtl_write_byte(rtlpriv, (REG_MACID + idx),
163 val[idx]);
164 }
165 break;
166 case HW_VAR_BASIC_RATE:{
167 u16 rate_cfg = ((u16 *) val)[0];
168 u8 rate_index = 0;
169 rate_cfg = rate_cfg & 0x15f;
170 rate_cfg |= 0x01;
171 rtl_write_byte(rtlpriv, REG_RRSR, rate_cfg & 0xff);
172 rtl_write_byte(rtlpriv, REG_RRSR + 1,
173 (rate_cfg >> 8) & 0xff);
174 while (rate_cfg > 0x1) {
175 rate_cfg = (rate_cfg >> 1);
176 rate_index++;
177 }
178 rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
179 rate_index);
180 break; }
181 case HW_VAR_BSSID:
182 for (idx = 0; idx < ETH_ALEN; idx++) {
183 rtl_write_byte(rtlpriv, (REG_BSSID + idx),
184 val[idx]);
185 }
186 break;
187 case HW_VAR_SIFS:
188 rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]);
189 rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]);
190
191 rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
192 rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
193
194 if (!mac->ht_enable)
195 rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
196 0x0e0e);
197 else
198 rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM,
199 *((u16 *) val));
200 break;
201 case HW_VAR_SLOT_TIME:{
202 u8 e_aci;
203
204 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
205 "HW_VAR_SLOT_TIME %x\n", val[0]);
206
207 rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
208
209 for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
Joe Perches1851cb42014-03-24 13:15:40 -0700210 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM,
211 &e_aci);
Larry Fingerc592e632012-10-25 13:46:32 -0500212 }
213 break; }
214 case HW_VAR_ACK_PREAMBLE:{
215 u8 reg_tmp;
Joe Perches1851cb42014-03-24 13:15:40 -0700216 u8 short_preamble = (bool)*val;
Larry Fingerc592e632012-10-25 13:46:32 -0500217 reg_tmp = (mac->cur_40_prime_sc) << 5;
218 if (short_preamble)
219 reg_tmp |= 0x80;
220
221 rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
222 break; }
223 case HW_VAR_AMPDU_MIN_SPACE:{
224 u8 min_spacing_to_set;
225 u8 sec_min_space;
226
Joe Perches1851cb42014-03-24 13:15:40 -0700227 min_spacing_to_set = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500228 if (min_spacing_to_set <= 7) {
229 sec_min_space = 0;
230
231 if (min_spacing_to_set < sec_min_space)
232 min_spacing_to_set = sec_min_space;
233
234 mac->min_space_cfg = ((mac->min_space_cfg &
235 0xf8) |
236 min_spacing_to_set);
237
238 *val = min_spacing_to_set;
239
240 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
241 "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
242 mac->min_space_cfg);
243
244 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
245 mac->min_space_cfg);
246 }
247 break; }
248 case HW_VAR_SHORTGI_DENSITY:{
249 u8 density_to_set;
250
Joe Perches1851cb42014-03-24 13:15:40 -0700251 density_to_set = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500252 mac->min_space_cfg |= (density_to_set << 3);
253
254 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
255 "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
256 mac->min_space_cfg);
257
258 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
259 mac->min_space_cfg);
260
261 break; }
262 case HW_VAR_AMPDU_FACTOR:{
263 u8 regtoset_normal[4] = {0x41, 0xa8, 0x72, 0xb9};
264 u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97};
265 u8 factor_toset;
266 u8 *p_regtoset = NULL;
267 u8 index;
268
269 if ((pcipriv->bt_coexist.bt_coexistence) &&
270 (pcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
271 p_regtoset = regtoset_bt;
272 else
273 p_regtoset = regtoset_normal;
274
Joe Perches1851cb42014-03-24 13:15:40 -0700275 factor_toset = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500276 if (factor_toset <= 3) {
277 factor_toset = (1 << (factor_toset + 2));
278 if (factor_toset > 0xf)
279 factor_toset = 0xf;
280
281 for (index = 0; index < 4; index++) {
282 if ((p_regtoset[index] & 0xf0) >
283 (factor_toset << 4))
284 p_regtoset[index] =
285 (p_regtoset[index] & 0x0f) |
286 (factor_toset << 4);
287
288 if ((p_regtoset[index] & 0x0f) >
289 factor_toset)
290 p_regtoset[index] =
291 (p_regtoset[index] & 0xf0) |
292 (factor_toset);
293
294 rtl_write_byte(rtlpriv,
295 (REG_AGGLEN_LMT + index),
296 p_regtoset[index]);
297
298 }
299
300 RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
301 "Set HW_VAR_AMPDU_FACTOR: %#x\n",
302 factor_toset);
303 }
304 break; }
305 case HW_VAR_AC_PARAM:{
Joe Perches1851cb42014-03-24 13:15:40 -0700306 u8 e_aci = *val;
Larry Finger57d9d9632014-02-28 15:16:49 -0600307 rtl8723_dm_init_edca_turbo(hw);
Larry Fingerc592e632012-10-25 13:46:32 -0500308
Larry Finger2cddad32014-02-28 15:16:46 -0600309 if (rtlpci->acm_method != EACMWAY2_SW)
Joe Perches1851cb42014-03-24 13:15:40 -0700310 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ACM_CTRL,
311 &e_aci);
Larry Fingerc592e632012-10-25 13:46:32 -0500312 break; }
313 case HW_VAR_ACM_CTRL:{
Joe Perches1851cb42014-03-24 13:15:40 -0700314 u8 e_aci = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500315 union aci_aifsn *p_aci_aifsn =
316 (union aci_aifsn *)(&(mac->ac[0].aifs));
317 u8 acm = p_aci_aifsn->f.acm;
318 u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL);
319
320 acm_ctrl |= ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
321
322 if (acm) {
323 switch (e_aci) {
324 case AC0_BE:
325 acm_ctrl |= AcmHw_BeqEn;
326 break;
327 case AC2_VI:
328 acm_ctrl |= AcmHw_ViqEn;
329 break;
330 case AC3_VO:
331 acm_ctrl |= AcmHw_VoqEn;
332 break;
333 default:
334 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
335 "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n",
336 acm);
337 break;
338 }
339 } else {
340 switch (e_aci) {
341 case AC0_BE:
342 acm_ctrl &= (~AcmHw_BeqEn);
343 break;
344 case AC2_VI:
345 acm_ctrl &= (~AcmHw_ViqEn);
346 break;
347 case AC3_VO:
348 acm_ctrl &= (~AcmHw_BeqEn);
349 break;
350 default:
351 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
352 "switch case not processed\n");
353 break;
354 }
355 }
356
357 RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
358 "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
359 acm_ctrl);
360 rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
361 break; }
362 case HW_VAR_RCR:
363 rtl_write_dword(rtlpriv, REG_RCR, ((u32 *) (val))[0]);
364 rtlpci->receive_config = ((u32 *) (val))[0];
365 break;
366 case HW_VAR_RETRY_LIMIT:{
Joe Perches1851cb42014-03-24 13:15:40 -0700367 u8 retry_limit = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500368
369 rtl_write_word(rtlpriv, REG_RL,
370 retry_limit << RETRY_LIMIT_SHORT_SHIFT |
371 retry_limit << RETRY_LIMIT_LONG_SHIFT);
372 break; }
373 case HW_VAR_DUAL_TSF_RST:
374 rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1)));
375 break;
376 case HW_VAR_EFUSE_BYTES:
377 rtlefuse->efuse_usedbytes = *((u16 *) val);
378 break;
379 case HW_VAR_EFUSE_USAGE:
Joe Perches1851cb42014-03-24 13:15:40 -0700380 rtlefuse->efuse_usedpercentage = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500381 break;
382 case HW_VAR_IO_CMD:
383 rtl8723ae_phy_set_io_cmd(hw, (*(enum io_type *)val));
384 break;
385 case HW_VAR_WPA_CONFIG:
Joe Perches1851cb42014-03-24 13:15:40 -0700386 rtl_write_byte(rtlpriv, REG_SECCFG, *val);
Larry Fingerc592e632012-10-25 13:46:32 -0500387 break;
388 case HW_VAR_SET_RPWM:{
389 u8 rpwm_val;
390
391 rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
392 udelay(1);
393
394 if (rpwm_val & BIT(7)) {
Joe Perches1851cb42014-03-24 13:15:40 -0700395 rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val);
Larry Fingerc592e632012-10-25 13:46:32 -0500396 } else {
Joe Perches1851cb42014-03-24 13:15:40 -0700397 rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val | BIT(7));
Larry Fingerc592e632012-10-25 13:46:32 -0500398 }
399
400 break; }
401 case HW_VAR_H2C_FW_PWRMODE:{
Joe Perches1851cb42014-03-24 13:15:40 -0700402 u8 psmode = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500403
404 if (psmode != FW_PS_ACTIVE_MODE)
405 rtl8723ae_dm_rf_saving(hw, true);
406
Joe Perches1851cb42014-03-24 13:15:40 -0700407 rtl8723ae_set_fw_pwrmode_cmd(hw, *val);
Larry Fingerc592e632012-10-25 13:46:32 -0500408 break; }
409 case HW_VAR_FW_PSMODE_STATUS:
410 ppsc->fw_current_inpsmode = *((bool *) val);
411 break;
412 case HW_VAR_H2C_FW_JOINBSSRPT:{
Joe Perches1851cb42014-03-24 13:15:40 -0700413 u8 mstatus = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500414 u8 tmp_regcr, tmp_reg422;
415 bool recover = false;
416
417 if (mstatus == RT_MEDIA_CONNECT) {
418 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID, NULL);
419
420 tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
421 rtl_write_byte(rtlpriv, REG_CR + 1,
422 (tmp_regcr | BIT(0)));
423
424 _rtl8723ae_set_bcn_ctrl_reg(hw, 0, BIT(3));
425 _rtl8723ae_set_bcn_ctrl_reg(hw, BIT(4), 0);
426
427 tmp_reg422 = rtl_read_byte(rtlpriv,
428 REG_FWHW_TXQ_CTRL + 2);
429 if (tmp_reg422 & BIT(6))
430 recover = true;
431 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
432 tmp_reg422 & (~BIT(6)));
433
434 rtl8723ae_set_fw_rsvdpagepkt(hw, 0);
435
436 _rtl8723ae_set_bcn_ctrl_reg(hw, BIT(3), 0);
437 _rtl8723ae_set_bcn_ctrl_reg(hw, 0, BIT(4));
438
439 if (recover)
440 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
441 tmp_reg422);
442
443 rtl_write_byte(rtlpriv, REG_CR + 1,
444 (tmp_regcr & ~(BIT(0))));
445 }
Joe Perches1851cb42014-03-24 13:15:40 -0700446 rtl8723ae_set_fw_joinbss_report_cmd(hw, *val);
Larry Fingerc592e632012-10-25 13:46:32 -0500447
448 break; }
Larry Finger4b04edc2013-03-24 22:06:39 -0500449 case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:
Joe Perches1851cb42014-03-24 13:15:40 -0700450 rtl8723ae_set_p2p_ps_offload_cmd(hw, *val);
Larry Finger4b04edc2013-03-24 22:06:39 -0500451 break;
Larry Fingerc592e632012-10-25 13:46:32 -0500452 case HW_VAR_AID:{
453 u16 u2btmp;
454 u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
455 u2btmp &= 0xC000;
456 rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
457 mac->assoc_id));
458 break; }
459 case HW_VAR_CORRECT_TSF:{
Joe Perches1851cb42014-03-24 13:15:40 -0700460 u8 btype_ibss = *val;
Larry Fingerc592e632012-10-25 13:46:32 -0500461
462 if (btype_ibss == true)
463 _rtl8723ae_stop_tx_beacon(hw);
464
465 _rtl8723ae_set_bcn_ctrl_reg(hw, 0, BIT(3));
466
467 rtl_write_dword(rtlpriv, REG_TSFTR,
468 (u32) (mac->tsf & 0xffffffff));
469 rtl_write_dword(rtlpriv, REG_TSFTR + 4,
470 (u32) ((mac->tsf >> 32) & 0xffffffff));
471
472 _rtl8723ae_set_bcn_ctrl_reg(hw, BIT(3), 0);
473
474 if (btype_ibss == true)
475 _rtl8723ae_resume_tx_beacon(hw);
476 break; }
Larry Finger4b04edc2013-03-24 22:06:39 -0500477 case HW_VAR_FW_LPS_ACTION: {
478 bool enter_fwlps = *((bool *)val);
479 u8 rpwm_val, fw_pwrmode;
480 bool fw_current_inps;
481
482 if (enter_fwlps) {
483 rpwm_val = 0x02; /* RF off */
484 fw_current_inps = true;
485 rtlpriv->cfg->ops->set_hw_reg(hw,
486 HW_VAR_FW_PSMODE_STATUS,
487 (u8 *)(&fw_current_inps));
488 rtlpriv->cfg->ops->set_hw_reg(hw,
489 HW_VAR_H2C_FW_PWRMODE,
Joe Perches1851cb42014-03-24 13:15:40 -0700490 &ppsc->fwctrl_psmode);
Larry Finger4b04edc2013-03-24 22:06:39 -0500491
Joe Perches1851cb42014-03-24 13:15:40 -0700492 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
493 &rpwm_val);
Larry Finger4b04edc2013-03-24 22:06:39 -0500494 } else {
495 rpwm_val = 0x0C; /* RF on */
496 fw_pwrmode = FW_PS_ACTIVE_MODE;
497 fw_current_inps = false;
498 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM,
Joe Perches1851cb42014-03-24 13:15:40 -0700499 &rpwm_val);
500 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_H2C_FW_PWRMODE,
501 &fw_pwrmode);
Larry Finger4b04edc2013-03-24 22:06:39 -0500502
503 rtlpriv->cfg->ops->set_hw_reg(hw,
504 HW_VAR_FW_PSMODE_STATUS,
505 (u8 *)(&fw_current_inps));
506 }
507 break; }
Larry Fingerc592e632012-10-25 13:46:32 -0500508 default:
509 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
510 "switch case not processed\n");
511 break;
512 }
513}
514
515static bool _rtl8723ae_llt_write(struct ieee80211_hw *hw, u32 address, u32 data)
516{
517 struct rtl_priv *rtlpriv = rtl_priv(hw);
518 bool status = true;
519 long count = 0;
520 u32 value = _LLT_INIT_ADDR(address) |
521 _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS);
522
523 rtl_write_dword(rtlpriv, REG_LLT_INIT, value);
524
525 do {
526 value = rtl_read_dword(rtlpriv, REG_LLT_INIT);
527 if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value))
528 break;
529
530 if (count > POLLING_LLT_THRESHOLD) {
531 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
532 "Failed to polling write LLT done at address %d!\n",
533 address);
534 status = false;
535 break;
536 }
537 } while (++count);
538
539 return status;
540}
541
542static bool _rtl8723ae_llt_table_init(struct ieee80211_hw *hw)
543{
544 struct rtl_priv *rtlpriv = rtl_priv(hw);
545 unsigned short i;
546 u8 txpktbuf_bndy;
547 u8 maxPage;
548 bool status;
549 u8 ubyte;
550
551 maxPage = 255;
552 txpktbuf_bndy = 246;
553
554 rtl_write_byte(rtlpriv, REG_CR, 0x8B);
555
556 rtl_write_word(rtlpriv, REG_RQPN_NPQ, 0x0000);
557
558 rtl_write_dword(rtlpriv, REG_RQPN, 0x80ac1c29);
559 rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x03);
560
561 rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x27FF0000 | txpktbuf_bndy));
562 rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
563
564 rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
565 rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
566
567 rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
568 rtl_write_byte(rtlpriv, REG_PBP, 0x11);
569 rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
570
571 for (i = 0; i < (txpktbuf_bndy - 1); i++) {
572 status = _rtl8723ae_llt_write(hw, i, i + 1);
573 if (true != status)
574 return status;
575 }
576
577 status = _rtl8723ae_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
578 if (true != status)
579 return status;
580
581 for (i = txpktbuf_bndy; i < maxPage; i++) {
582 status = _rtl8723ae_llt_write(hw, i, (i + 1));
583 if (true != status)
584 return status;
585 }
586
587 status = _rtl8723ae_llt_write(hw, maxPage, txpktbuf_bndy);
588 if (true != status)
589 return status;
590
591 rtl_write_byte(rtlpriv, REG_CR, 0xff);
592 ubyte = rtl_read_byte(rtlpriv, REG_RQPN + 3);
593 rtl_write_byte(rtlpriv, REG_RQPN + 3, ubyte | BIT(7));
594
595 return true;
596}
597
598static void _rtl8723ae_gen_refresh_led_state(struct ieee80211_hw *hw)
599{
600 struct rtl_priv *rtlpriv = rtl_priv(hw);
601 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
602 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
603 struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
604
605 if (rtlpriv->rtlhal.up_first_time)
606 return;
607
608 if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
609 rtl8723ae_sw_led_on(hw, pLed0);
610 else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
611 rtl8723ae_sw_led_on(hw, pLed0);
612 else
613 rtl8723ae_sw_led_off(hw, pLed0);
614}
615
616static bool _rtl8712e_init_mac(struct ieee80211_hw *hw)
617{
618 struct rtl_priv *rtlpriv = rtl_priv(hw);
619 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
620 unsigned char bytetmp;
621 unsigned short wordtmp;
622 u16 retry = 0;
623 u16 tmpu2b;
624 bool mac_func_enable;
625
626 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
627 bytetmp = rtl_read_byte(rtlpriv, REG_CR);
628 if (bytetmp == 0xFF)
629 mac_func_enable = true;
630 else
631 mac_func_enable = false;
632
633
634 /* HW Power on sequence */
635 if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
636 PWR_INTF_PCI_MSK, Rtl8723_NIC_ENABLE_FLOW))
637 return false;
638
639 bytetmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG+2);
640 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+2, bytetmp | BIT(4));
641
642 /* eMAC time out function enable, 0x369[7]=1 */
643 bytetmp = rtl_read_byte(rtlpriv, 0x369);
644 rtl_write_byte(rtlpriv, 0x369, bytetmp | BIT(7));
645
646 /* ePHY reg 0x1e bit[4]=1 using MDIO interface,
647 * we should do this before Enabling ASPM backdoor.
648 */
649 do {
650 rtl_write_word(rtlpriv, 0x358, 0x5e);
651 udelay(100);
652 rtl_write_word(rtlpriv, 0x356, 0xc280);
653 rtl_write_word(rtlpriv, 0x354, 0xc290);
654 rtl_write_word(rtlpriv, 0x358, 0x3e);
655 udelay(100);
656 rtl_write_word(rtlpriv, 0x358, 0x5e);
657 udelay(100);
658 tmpu2b = rtl_read_word(rtlpriv, 0x356);
659 retry++;
660 } while (tmpu2b != 0xc290 && retry < 100);
661
662 if (retry >= 100) {
663 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
664 "InitMAC(): ePHY configure fail!!!\n");
665 return false;
666 }
667
668 rtl_write_word(rtlpriv, REG_CR, 0x2ff);
669 rtl_write_word(rtlpriv, REG_CR + 1, 0x06);
670
671 if (!mac_func_enable) {
672 if (_rtl8723ae_llt_table_init(hw) == false)
673 return false;
674 }
675
676 rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
677 rtl_write_byte(rtlpriv, REG_HISRE, 0xff);
678
679 rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x27ff);
680
681 wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL) & 0xf;
682 wordtmp |= 0xF771;
683 rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
684
685 rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
686 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
687 rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xFFFF);
688 rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
689
690 rtl_write_byte(rtlpriv, 0x4d0, 0x0);
691
692 rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
693 ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) &
694 DMA_BIT_MASK(32));
695 rtl_write_dword(rtlpriv, REG_MGQ_DESA,
696 (u64) rtlpci->tx_ring[MGNT_QUEUE].dma &
697 DMA_BIT_MASK(32));
698 rtl_write_dword(rtlpriv, REG_VOQ_DESA,
699 (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
700 rtl_write_dword(rtlpriv, REG_VIQ_DESA,
701 (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
702 rtl_write_dword(rtlpriv, REG_BEQ_DESA,
703 (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
704 rtl_write_dword(rtlpriv, REG_BKQ_DESA,
705 (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
706 rtl_write_dword(rtlpriv, REG_HQ_DESA,
707 (u64) rtlpci->tx_ring[HIGH_QUEUE].dma &
708 DMA_BIT_MASK(32));
709 rtl_write_dword(rtlpriv, REG_RX_DESA,
710 (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
711 DMA_BIT_MASK(32));
712
713 rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x74);
714
715 rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
716
717 bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
718 rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6));
719 do {
720 retry++;
721 bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
722 } while ((retry < 200) && (bytetmp & BIT(7)));
723
724 _rtl8723ae_gen_refresh_led_state(hw);
725
726 rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
727
728 return true;
729}
730
731static void _rtl8723ae_hw_configure(struct ieee80211_hw *hw)
732{
733 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
734 struct rtl_priv *rtlpriv = rtl_priv(hw);
735 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
736 u8 reg_bw_opmode;
Larry Fingerb26f5f02013-02-01 10:40:27 -0600737 u32 reg_prsr;
Larry Fingerc592e632012-10-25 13:46:32 -0500738
739 reg_bw_opmode = BW_OPMODE_20MHZ;
Larry Fingerc592e632012-10-25 13:46:32 -0500740 reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
741
742 rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8);
743
744 rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
745
746 rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
747
748 rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
749
750 rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0);
751
752 rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
753
754 rtl_write_word(rtlpriv, REG_RL, 0x0707);
755
756 rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802);
757
758 rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
759
760 rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
761 rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
762 rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
763 rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
764
765 if ((pcipriv->bt_coexist.bt_coexistence) &&
766 (pcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
767 rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431);
768 else
769 rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
770
771 rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
772
773 rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
774
775 rtlpci->reg_bcn_ctrl_val = 0x1f;
776 rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
777
778 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
779
780 rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
781
782 rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
783 rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
784
785 if ((pcipriv->bt_coexist.bt_coexistence) &&
786 (pcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4)) {
787 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
788 rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402);
789 } else {
790 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
791 rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
792 }
793
794 if ((pcipriv->bt_coexist.bt_coexistence) &&
795 (pcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
796 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
797 else
798 rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666);
799
800 rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
801
802 rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010);
803 rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010);
804
805 rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010);
806
807 rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010);
808
809 rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
810 rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
811
812 rtl_write_dword(rtlpriv, 0x394, 0x1);
813}
814
815static void _rtl8723ae_enable_aspm_back_door(struct ieee80211_hw *hw)
816{
817 struct rtl_priv *rtlpriv = rtl_priv(hw);
818 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
819
820 rtl_write_byte(rtlpriv, 0x34b, 0x93);
821 rtl_write_word(rtlpriv, 0x350, 0x870c);
822 rtl_write_byte(rtlpriv, 0x352, 0x1);
823
824 if (ppsc->support_backdoor)
825 rtl_write_byte(rtlpriv, 0x349, 0x1b);
826 else
827 rtl_write_byte(rtlpriv, 0x349, 0x03);
828
829 rtl_write_word(rtlpriv, 0x350, 0x2718);
830 rtl_write_byte(rtlpriv, 0x352, 0x1);
831}
832
833void rtl8723ae_enable_hw_security_config(struct ieee80211_hw *hw)
834{
835 struct rtl_priv *rtlpriv = rtl_priv(hw);
836 u8 sec_reg_value;
837
838 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
839 "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
840 rtlpriv->sec.pairwise_enc_algorithm,
841 rtlpriv->sec.group_enc_algorithm);
842
843 if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
844 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
845 "not open hw encryption\n");
846 return;
847 }
848
849 sec_reg_value = SCR_TxEncEnable | SCR_RxDecEnable;
850
851 if (rtlpriv->sec.use_defaultkey) {
852 sec_reg_value |= SCR_TxUseDK;
853 sec_reg_value |= SCR_RxUseDK;
854 }
855
856 sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
857
858 rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
859
860 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
861 "The SECR-value %x\n", sec_reg_value);
862
863 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
864
865}
866
867int rtl8723ae_hw_init(struct ieee80211_hw *hw)
868{
869 struct rtl_priv *rtlpriv = rtl_priv(hw);
870 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
871 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
872 struct rtl_phy *rtlphy = &(rtlpriv->phy);
873 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
874 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
875 bool rtstatus = true;
876 int err;
877 u8 tmp_u1b;
Larry Fingerbfc10102014-03-04 16:53:53 -0600878 unsigned long flags;
Larry Fingerc592e632012-10-25 13:46:32 -0500879
880 rtlpriv->rtlhal.being_init_adapter = true;
Larry Fingerbfc10102014-03-04 16:53:53 -0600881 /* As this function can take a very long time (up to 350 ms)
882 * and can be called with irqs disabled, reenable the irqs
883 * to let the other devices continue being serviced.
884 *
885 * It is safe doing so since our own interrupts will only be enabled
886 * in a subsequent step.
887 */
888 local_save_flags(flags);
889 local_irq_enable();
890
Larry Fingerc592e632012-10-25 13:46:32 -0500891 rtlpriv->intf_ops->disable_aspm(hw);
892 rtstatus = _rtl8712e_init_mac(hw);
893 if (rtstatus != true) {
894 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n");
895 err = 1;
Larry Fingerbfc10102014-03-04 16:53:53 -0600896 goto exit;
Larry Fingerc592e632012-10-25 13:46:32 -0500897 }
898
Larry Fingercbd0c852014-02-28 15:16:48 -0600899 err = rtl8723_download_fw(hw, false);
Larry Fingerc592e632012-10-25 13:46:32 -0500900 if (err) {
901 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
902 "Failed to download FW. Init HW without FW now..\n");
903 err = 1;
Larry Fingerbfc10102014-03-04 16:53:53 -0600904 goto exit;
Larry Fingerc592e632012-10-25 13:46:32 -0500905 } else {
906 rtlhal->fw_ready = true;
907 }
908
909 rtlhal->last_hmeboxnum = 0;
910 rtl8723ae_phy_mac_config(hw);
911 /* because the last function modifies RCR, we update
912 * rcr var here, or TP will be unstable as ther receive_config
913 * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx
914 * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252
915 */
916 rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR);
917 rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV);
918 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
919
920 rtl8723ae_phy_bb_config(hw);
921 rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
922 rtl8723ae_phy_rf_config(hw);
923 if (IS_VENDOR_UMC_A_CUT(rtlhal->version)) {
924 rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD, 0x30255);
925 rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G2, MASKDWORD, 0x50a00);
926 } else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version)) {
927 rtl_set_rfreg(hw, RF90_PATH_A, 0x0C, MASKDWORD, 0x894AE);
928 rtl_set_rfreg(hw, RF90_PATH_A, 0x0A, MASKDWORD, 0x1AF31);
929 rtl_set_rfreg(hw, RF90_PATH_A, RF_IPA, MASKDWORD, 0x8F425);
930 rtl_set_rfreg(hw, RF90_PATH_A, RF_SYN_G2, MASKDWORD, 0x4F200);
931 rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK1, MASKDWORD, 0x44053);
932 rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK2, MASKDWORD, 0x80201);
933 }
934 rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
935 RF_CHNLBW, RFREG_OFFSET_MASK);
936 rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1,
937 RF_CHNLBW, RFREG_OFFSET_MASK);
938 rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
939 rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
940 rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
941 _rtl8723ae_hw_configure(hw);
942 rtl_cam_reset_all_entry(hw);
943 rtl8723ae_enable_hw_security_config(hw);
944
945 ppsc->rfpwr_state = ERFON;
946
947 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
948 _rtl8723ae_enable_aspm_back_door(hw);
949 rtlpriv->intf_ops->enable_aspm(hw);
950
951 rtl8723ae_bt_hw_init(hw);
952
953 if (ppsc->rfpwr_state == ERFON) {
954 rtl8723ae_phy_set_rfpath_switch(hw, 1);
955 if (rtlphy->iqk_initialized) {
956 rtl8723ae_phy_iq_calibrate(hw, true);
957 } else {
958 rtl8723ae_phy_iq_calibrate(hw, false);
959 rtlphy->iqk_initialized = true;
960 }
961
962 rtl8723ae_phy_lc_calibrate(hw);
963 }
964
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");
969 }
970
971 if (!(tmp_u1b & BIT(4))) {
972 tmp_u1b = rtl_read_byte(rtlpriv, 0x16) & 0x0F;
973 rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
974 udelay(10);
975 rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
976 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n");
977 }
978 rtl8723ae_dm_init(hw);
Larry Fingerbfc10102014-03-04 16:53:53 -0600979exit:
980 local_irq_restore(flags);
Larry Fingerc592e632012-10-25 13:46:32 -0500981 rtlpriv->rtlhal.being_init_adapter = false;
982 return err;
983}
984
985static enum version_8723e _rtl8723ae_read_chip_version(struct ieee80211_hw *hw)
986{
987 struct rtl_priv *rtlpriv = rtl_priv(hw);
988 struct rtl_phy *rtlphy = &(rtlpriv->phy);
989 enum version_8723e version = 0x0000;
990 u32 value32;
991
992 value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
993 if (value32 & TRP_VAUX_EN) {
994 version = (enum version_8723e)(version |
995 ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
996 /* RTL8723 with BT function. */
997 version = (enum version_8723e)(version |
998 ((value32 & BT_FUNC) ? CHIP_8723 : 0));
999
1000 } else {
1001 /* Normal mass production chip. */
1002 version = (enum version_8723e) NORMAL_CHIP;
1003 version = (enum version_8723e)(version |
1004 ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
1005 /* RTL8723 with BT function. */
1006 version = (enum version_8723e)(version |
1007 ((value32 & BT_FUNC) ? CHIP_8723 : 0));
1008 if (IS_CHIP_VENDOR_UMC(version))
1009 version = (enum version_8723e)(version |
1010 ((value32 & CHIP_VER_RTL_MASK)));/* IC version (CUT) */
1011 if (IS_8723_SERIES(version)) {
1012 value32 = rtl_read_dword(rtlpriv, REG_GPIO_OUTSTS);
1013 /* ROM code version */
1014 version = (enum version_8723e)(version |
1015 ((value32 & RF_RL_ID)>>20));
1016 }
1017 }
1018
1019 if (IS_8723_SERIES(version)) {
1020 value32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL);
1021 rtlphy->polarity_ctl = ((value32 & WL_HWPDN_SL) ?
1022 RT_POLARITY_HIGH_ACT :
1023 RT_POLARITY_LOW_ACT);
1024 }
1025 switch (version) {
1026 case VERSION_TEST_UMC_CHIP_8723:
1027 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1028 "Chip Version ID: VERSION_TEST_UMC_CHIP_8723.\n");
1029 break;
1030 case VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT:
1031 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1032 "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT.\n");
1033 break;
1034 case VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT:
1035 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1036 "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT.\n");
1037 break;
1038 default:
1039 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1040 "Chip Version ID: Unknown. Bug?\n");
1041 break;
1042 }
1043
1044 if (IS_8723_SERIES(version))
1045 rtlphy->rf_type = RF_1T1R;
1046
1047 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Chip RF Type: %s\n",
1048 (rtlphy->rf_type == RF_2T2R) ? "RF_2T2R" : "RF_1T1R");
1049
1050 return version;
1051}
1052
1053static int _rtl8723ae_set_media_status(struct ieee80211_hw *hw,
1054 enum nl80211_iftype type)
1055{
1056 struct rtl_priv *rtlpriv = rtl_priv(hw);
1057 u8 bt_msr = rtl_read_byte(rtlpriv, MSR) & 0xfc;
1058 enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
1059
1060 rtl_write_dword(rtlpriv, REG_BCN_CTRL, 0);
1061 RT_TRACE(rtlpriv, COMP_BEACON, DBG_LOUD,
1062 "clear 0x550 when set HW_VAR_MEDIA_STATUS\n");
1063
1064 if (type == NL80211_IFTYPE_UNSPECIFIED ||
1065 type == NL80211_IFTYPE_STATION) {
1066 _rtl8723ae_stop_tx_beacon(hw);
1067 _rtl8723ae_enable_bcn_sufunc(hw);
1068 } else if (type == NL80211_IFTYPE_ADHOC ||
1069 type == NL80211_IFTYPE_AP) {
1070 _rtl8723ae_resume_tx_beacon(hw);
1071 _rtl8723ae_disable_bcn_sufunc(hw);
1072 } else {
1073 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1074 "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n",
1075 type);
1076 }
1077
1078 switch (type) {
1079 case NL80211_IFTYPE_UNSPECIFIED:
1080 bt_msr |= MSR_NOLINK;
1081 ledaction = LED_CTL_LINK;
1082 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1083 "Set Network type to NO LINK!\n");
1084 break;
1085 case NL80211_IFTYPE_ADHOC:
1086 bt_msr |= MSR_ADHOC;
1087 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1088 "Set Network type to Ad Hoc!\n");
1089 break;
1090 case NL80211_IFTYPE_STATION:
1091 bt_msr |= MSR_INFRA;
1092 ledaction = LED_CTL_LINK;
1093 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1094 "Set Network type to STA!\n");
1095 break;
1096 case NL80211_IFTYPE_AP:
1097 bt_msr |= MSR_AP;
1098 RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1099 "Set Network type to AP!\n");
1100 break;
1101 default:
1102 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1103 "Network type %d not supported!\n",
1104 type);
1105 return 1;
1106 break;
1107
1108 }
1109
1110 rtl_write_byte(rtlpriv, (MSR), bt_msr);
1111 rtlpriv->cfg->ops->led_control(hw, ledaction);
1112 if ((bt_msr & 0x03) == MSR_AP)
1113 rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
1114 else
1115 rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
1116 return 0;
1117}
1118
1119void rtl8723ae_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
1120{
1121 struct rtl_priv *rtlpriv = rtl_priv(hw);
Peter Wue51048c2014-02-14 19:03:44 +01001122 u32 reg_rcr;
Larry Fingerc592e632012-10-25 13:46:32 -05001123
1124 if (rtlpriv->psc.rfpwr_state != ERFON)
1125 return;
1126
Peter Wue51048c2014-02-14 19:03:44 +01001127 rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_RCR, (u8 *)(&reg_rcr));
1128
Larry Fingerc592e632012-10-25 13:46:32 -05001129 if (check_bssid == true) {
1130 reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1131 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
1132 (u8 *)(&reg_rcr));
1133 _rtl8723ae_set_bcn_ctrl_reg(hw, 0, BIT(4));
1134 } else if (check_bssid == false) {
1135 reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
1136 _rtl8723ae_set_bcn_ctrl_reg(hw, BIT(4), 0);
1137 rtlpriv->cfg->ops->set_hw_reg(hw,
1138 HW_VAR_RCR, (u8 *) (&reg_rcr));
1139 }
1140}
1141
1142int rtl8723ae_set_network_type(struct ieee80211_hw *hw,
1143 enum nl80211_iftype type)
1144{
1145 struct rtl_priv *rtlpriv = rtl_priv(hw);
1146
1147 if (_rtl8723ae_set_media_status(hw, type))
1148 return -EOPNOTSUPP;
1149
1150 if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
1151 if (type != NL80211_IFTYPE_AP)
1152 rtl8723ae_set_check_bssid(hw, true);
1153 } else {
1154 rtl8723ae_set_check_bssid(hw, false);
1155 }
1156 return 0;
1157}
1158
1159/* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1160void rtl8723ae_set_qos(struct ieee80211_hw *hw, int aci)
1161{
1162 struct rtl_priv *rtlpriv = rtl_priv(hw);
1163
Larry Finger57d9d9632014-02-28 15:16:49 -06001164 rtl8723_dm_init_edca_turbo(hw);
Larry Fingerc592e632012-10-25 13:46:32 -05001165 switch (aci) {
1166 case AC1_BK:
1167 rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
1168 break;
1169 case AC0_BE:
1170 /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4ac_param); */
1171 break;
1172 case AC2_VI:
1173 rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
1174 break;
1175 case AC3_VO:
1176 rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
1177 break;
1178 default:
1179 RT_ASSERT(false, "invalid aci: %d !\n", aci);
1180 break;
1181 }
1182}
1183
1184void rtl8723ae_enable_interrupt(struct ieee80211_hw *hw)
1185{
1186 struct rtl_priv *rtlpriv = rtl_priv(hw);
1187 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1188
1189 rtl_write_dword(rtlpriv, 0x3a8, rtlpci->irq_mask[0] & 0xFFFFFFFF);
1190 rtl_write_dword(rtlpriv, 0x3ac, rtlpci->irq_mask[1] & 0xFFFFFFFF);
1191 rtlpci->irq_enabled = true;
1192}
1193
1194void rtl8723ae_disable_interrupt(struct ieee80211_hw *hw)
1195{
1196 struct rtl_priv *rtlpriv = rtl_priv(hw);
1197 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1198
1199 rtl_write_dword(rtlpriv, 0x3a8, IMR8190_DISABLED);
1200 rtl_write_dword(rtlpriv, 0x3ac, IMR8190_DISABLED);
1201 rtlpci->irq_enabled = false;
1202 synchronize_irq(rtlpci->pdev->irq);
1203}
1204
1205static void _rtl8723ae_poweroff_adapter(struct ieee80211_hw *hw)
1206{
1207 struct rtl_priv *rtlpriv = rtl_priv(hw);
1208 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1209 u8 u1tmp;
1210
1211 /* Combo (PCIe + USB) Card and PCIe-MF Card */
1212 /* 1. Run LPS WL RFOFF flow */
1213 rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
1214 PWR_INTF_PCI_MSK, Rtl8723_NIC_LPS_ENTER_FLOW);
1215
1216 /* 2. 0x1F[7:0] = 0 */
1217 /* turn off RF */
1218 rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
1219 if ((rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) && rtlhal->fw_ready)
1220 rtl8723ae_firmware_selfreset(hw);
1221
1222 /* Reset MCU. Suggested by Filen. */
1223 u1tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1);
1224 rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN+1, (u1tmp & (~BIT(2))));
1225
1226 /* g. MCUFWDL 0x80[1:0]=0 */
1227 /* reset MCU ready status */
1228 rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
1229
1230 /* HW card disable configuration. */
1231 rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK,
1232 PWR_INTF_PCI_MSK, Rtl8723_NIC_DISABLE_FLOW);
1233
1234 /* Reset MCU IO Wrapper */
1235 u1tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
1236 rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1tmp & (~BIT(0))));
1237 u1tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1);
1238 rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, u1tmp | BIT(0));
1239
1240 /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */
1241 /* lock ISO/CLK/Power control register */
1242 rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
1243}
1244
1245void rtl8723ae_card_disable(struct ieee80211_hw *hw)
1246{
1247 struct rtl_priv *rtlpriv = rtl_priv(hw);
1248 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1249 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1250 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1251 enum nl80211_iftype opmode;
1252
1253 mac->link_state = MAC80211_NOLINK;
1254 opmode = NL80211_IFTYPE_UNSPECIFIED;
1255 _rtl8723ae_set_media_status(hw, opmode);
1256 if (rtlpci->driver_is_goingto_unload ||
1257 ppsc->rfoff_reason > RF_CHANGE_BY_PS)
1258 rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
1259 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
1260 _rtl8723ae_poweroff_adapter(hw);
1261
1262 /* after power off we should do iqk again */
1263 rtlpriv->phy.iqk_initialized = false;
1264}
1265
1266void rtl8723ae_interrupt_recognized(struct ieee80211_hw *hw,
1267 u32 *p_inta, u32 *p_intb)
1268{
1269 struct rtl_priv *rtlpriv = rtl_priv(hw);
1270 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1271
1272 *p_inta = rtl_read_dword(rtlpriv, 0x3a0) & rtlpci->irq_mask[0];
1273 rtl_write_dword(rtlpriv, 0x3a0, *p_inta);
1274}
1275
1276void rtl8723ae_set_beacon_related_registers(struct ieee80211_hw *hw)
1277{
1278
1279 struct rtl_priv *rtlpriv = rtl_priv(hw);
1280 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1281 u16 bcn_interval, atim_window;
1282
1283 bcn_interval = mac->beacon_interval;
1284 atim_window = 2; /*FIX MERGE */
1285 rtl8723ae_disable_interrupt(hw);
1286 rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
1287 rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1288 rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
1289 rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
1290 rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
1291 rtl_write_byte(rtlpriv, 0x606, 0x30);
1292 rtl8723ae_enable_interrupt(hw);
1293}
1294
1295void rtl8723ae_set_beacon_interval(struct ieee80211_hw *hw)
1296{
1297 struct rtl_priv *rtlpriv = rtl_priv(hw);
1298 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1299 u16 bcn_interval = mac->beacon_interval;
1300
1301 RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
1302 "beacon_interval:%d\n", bcn_interval);
1303 rtl8723ae_disable_interrupt(hw);
1304 rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1305 rtl8723ae_enable_interrupt(hw);
1306}
1307
1308void rtl8723ae_update_interrupt_mask(struct ieee80211_hw *hw,
1309 u32 add_msr, u32 rm_msr)
1310{
1311 struct rtl_priv *rtlpriv = rtl_priv(hw);
1312 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1313
1314 RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD,
1315 "add_msr:%x, rm_msr:%x\n", add_msr, rm_msr);
1316
1317 if (add_msr)
1318 rtlpci->irq_mask[0] |= add_msr;
1319 if (rm_msr)
1320 rtlpci->irq_mask[0] &= (~rm_msr);
1321 rtl8723ae_disable_interrupt(hw);
1322 rtl8723ae_enable_interrupt(hw);
1323}
1324
1325static u8 _rtl8723ae_get_chnl_group(u8 chnl)
1326{
1327 u8 group;
1328
1329 if (chnl < 3)
1330 group = 0;
1331 else if (chnl < 9)
1332 group = 1;
1333 else
1334 group = 2;
1335 return group;
1336}
1337
1338static void _rtl8723ae_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
1339 bool autoload_fail,
1340 u8 *hwinfo)
1341{
1342 struct rtl_priv *rtlpriv = rtl_priv(hw);
1343 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1344 u8 rf_path, index, tempval;
1345 u16 i;
1346
1347 for (rf_path = 0; rf_path < 1; rf_path++) {
1348 for (i = 0; i < 3; i++) {
1349 if (!autoload_fail) {
1350 rtlefuse->eeprom_chnlarea_txpwr_cck
1351 [rf_path][i] =
1352 hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i];
1353 rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
1354 [rf_path][i] =
1355 hwinfo[EEPROM_TXPOWERHT40_1S + rf_path *
1356 3 + i];
1357 } else {
1358 rtlefuse->eeprom_chnlarea_txpwr_cck
1359 [rf_path][i] =
1360 EEPROM_DEFAULT_TXPOWERLEVEL;
1361 rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
1362 [rf_path][i] =
1363 EEPROM_DEFAULT_TXPOWERLEVEL;
1364 }
1365 }
1366 }
1367
1368 for (i = 0; i < 3; i++) {
1369 if (!autoload_fail)
1370 tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i];
1371 else
1372 tempval = EEPROM_DEFAULT_HT40_2SDIFF;
1373 rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_A][i] =
1374 (tempval & 0xf);
1375 rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_B][i] =
1376 ((tempval & 0xf0) >> 4);
1377 }
1378
1379 for (rf_path = 0; rf_path < 2; rf_path++)
1380 for (i = 0; i < 3; i++)
1381 RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1382 "RF(%d) EEPROM CCK Area(%d) = 0x%x\n", rf_path,
1383 i, rtlefuse->eeprom_chnlarea_txpwr_cck
1384 [rf_path][i]);
1385 for (rf_path = 0; rf_path < 2; rf_path++)
1386 for (i = 0; i < 3; i++)
1387 RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1388 "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1389 rf_path, i,
1390 rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
1391 [rf_path][i]);
1392 for (rf_path = 0; rf_path < 2; rf_path++)
1393 for (i = 0; i < 3; i++)
1394 RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1395 "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1396 rf_path, i,
1397 rtlefuse->eprom_chnl_txpwr_ht40_2sdf
1398 [rf_path][i]);
1399
1400 for (rf_path = 0; rf_path < 2; rf_path++) {
1401 for (i = 0; i < 14; i++) {
1402 index = _rtl8723ae_get_chnl_group((u8) i);
1403
1404 rtlefuse->txpwrlevel_cck[rf_path][i] =
1405 rtlefuse->eeprom_chnlarea_txpwr_cck
1406 [rf_path][index];
1407 rtlefuse->txpwrlevel_ht40_1s[rf_path][i] =
1408 rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
1409 [rf_path][index];
1410
1411 if ((rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
1412 [rf_path][index] -
1413 rtlefuse->eprom_chnl_txpwr_ht40_2sdf[rf_path]
1414 [index]) > 0) {
1415 rtlefuse->txpwrlevel_ht40_2s[rf_path][i] =
1416 rtlefuse->eeprom_chnlarea_txpwr_ht40_1s
1417 [rf_path][index] -
1418 rtlefuse->eprom_chnl_txpwr_ht40_2sdf
1419 [rf_path][index];
1420 } else {
1421 rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0;
1422 }
1423 }
1424
1425 for (i = 0; i < 14; i++) {
Larry Fingere6deaf82013-03-24 22:06:55 -05001426 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001427 "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = "
1428 "[0x%x / 0x%x / 0x%x]\n", rf_path, i,
1429 rtlefuse->txpwrlevel_cck[rf_path][i],
1430 rtlefuse->txpwrlevel_ht40_1s[rf_path][i],
1431 rtlefuse->txpwrlevel_ht40_2s[rf_path][i]);
1432 }
1433 }
1434
1435 for (i = 0; i < 3; i++) {
1436 if (!autoload_fail) {
1437 rtlefuse->eeprom_pwrlimit_ht40[i] =
1438 hwinfo[EEPROM_TXPWR_GROUP + i];
1439 rtlefuse->eeprom_pwrlimit_ht20[i] =
1440 hwinfo[EEPROM_TXPWR_GROUP + 3 + i];
1441 } else {
1442 rtlefuse->eeprom_pwrlimit_ht40[i] = 0;
1443 rtlefuse->eeprom_pwrlimit_ht20[i] = 0;
1444 }
1445 }
1446
1447 for (rf_path = 0; rf_path < 2; rf_path++) {
1448 for (i = 0; i < 14; i++) {
1449 index = _rtl8723ae_get_chnl_group((u8) i);
1450
1451 if (rf_path == RF90_PATH_A) {
1452 rtlefuse->pwrgroup_ht20[rf_path][i] =
1453 (rtlefuse->eeprom_pwrlimit_ht20[index] &
1454 0xf);
1455 rtlefuse->pwrgroup_ht40[rf_path][i] =
1456 (rtlefuse->eeprom_pwrlimit_ht40[index] &
1457 0xf);
1458 } else if (rf_path == RF90_PATH_B) {
1459 rtlefuse->pwrgroup_ht20[rf_path][i] =
1460 ((rtlefuse->eeprom_pwrlimit_ht20[index] &
1461 0xf0) >> 4);
1462 rtlefuse->pwrgroup_ht40[rf_path][i] =
1463 ((rtlefuse->eeprom_pwrlimit_ht40[index] &
1464 0xf0) >> 4);
1465 }
1466
Larry Fingere6deaf82013-03-24 22:06:55 -05001467 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001468 "RF-%d pwrgroup_ht20[%d] = 0x%x\n", rf_path, i,
1469 rtlefuse->pwrgroup_ht20[rf_path][i]);
Larry Fingere6deaf82013-03-24 22:06:55 -05001470 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001471 "RF-%d pwrgroup_ht40[%d] = 0x%x\n", rf_path, i,
1472 rtlefuse->pwrgroup_ht40[rf_path][i]);
1473 }
1474 }
1475
1476 for (i = 0; i < 14; i++) {
1477 index = _rtl8723ae_get_chnl_group((u8) i);
1478
1479 if (!autoload_fail)
1480 tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index];
1481 else
1482 tempval = EEPROM_DEFAULT_HT20_DIFF;
1483
1484 rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF);
1485 rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] =
1486 ((tempval >> 4) & 0xF);
1487
1488 if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3))
1489 rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0;
1490
1491 if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3))
1492 rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0;
1493
1494 index = _rtl8723ae_get_chnl_group((u8) i);
1495
1496 if (!autoload_fail)
1497 tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index];
1498 else
1499 tempval = EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF;
1500
1501 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF);
1502 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] =
1503 ((tempval >> 4) & 0xF);
1504 }
1505
1506 rtlefuse->legacy_ht_txpowerdiff =
1507 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7];
1508
1509 for (i = 0; i < 14; i++)
Larry Fingere6deaf82013-03-24 22:06:55 -05001510 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001511 "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", i,
1512 rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]);
1513 for (i = 0; i < 14; i++)
Larry Fingere6deaf82013-03-24 22:06:55 -05001514 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001515 "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", i,
1516 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]);
1517 for (i = 0; i < 14; i++)
Larry Fingere6deaf82013-03-24 22:06:55 -05001518 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001519 "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", i,
1520 rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]);
1521 for (i = 0; i < 14; i++)
Larry Fingere6deaf82013-03-24 22:06:55 -05001522 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001523 "RF-B Legacy to HT40 Diff[%d] = 0x%x\n", i,
1524 rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]);
1525
1526 if (!autoload_fail)
1527 rtlefuse->eeprom_regulatory = (hwinfo[RF_OPTION1] & 0x7);
1528 else
1529 rtlefuse->eeprom_regulatory = 0;
Larry Fingere6deaf82013-03-24 22:06:55 -05001530 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001531 "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory);
1532
1533 if (!autoload_fail)
1534 rtlefuse->eeprom_tssi[RF90_PATH_A] = hwinfo[EEPROM_TSSI_A];
1535 else
1536 rtlefuse->eeprom_tssi[RF90_PATH_A] = EEPROM_DEFAULT_TSSI;
Larry Fingere6deaf82013-03-24 22:06:55 -05001537 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001538 "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1539 rtlefuse->eeprom_tssi[RF90_PATH_A],
1540 rtlefuse->eeprom_tssi[RF90_PATH_B]);
1541
1542 if (!autoload_fail)
1543 tempval = hwinfo[EEPROM_THERMAL_METER];
1544 else
1545 tempval = EEPROM_DEFAULT_THERMALMETER;
1546 rtlefuse->eeprom_thermalmeter = (tempval & 0x1f);
1547
1548 if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail)
1549 rtlefuse->apk_thermalmeterignore = true;
1550
1551 rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
Larry Fingere6deaf82013-03-24 22:06:55 -05001552 RTPRINT(rtlpriv, FINIT, INIT_TXPOWER,
Larry Fingerc592e632012-10-25 13:46:32 -05001553 "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
1554}
1555
1556static void _rtl8723ae_read_adapter_info(struct ieee80211_hw *hw,
1557 bool pseudo_test)
1558{
1559 struct rtl_priv *rtlpriv = rtl_priv(hw);
1560 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1561 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1562 u16 i, usvalue;
1563 u8 hwinfo[HWSET_MAX_SIZE];
1564 u16 eeprom_id;
1565
1566 if (pseudo_test) {
1567 /* need add */
1568 return;
1569 }
1570 if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
1571 rtl_efuse_shadow_map_update(hw);
1572
1573 memcpy(hwinfo, &rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
1574 HWSET_MAX_SIZE);
1575 } else if (rtlefuse->epromtype == EEPROM_93C46) {
1576 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1577 "RTL819X Not boot from eeprom, check it !!");
1578 }
1579
1580 RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, ("MAP\n"),
1581 hwinfo, HWSET_MAX_SIZE);
1582
1583 eeprom_id = *((u16 *)&hwinfo[0]);
1584 if (eeprom_id != RTL8190_EEPROM_ID) {
1585 RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1586 "EEPROM ID(%#x) is invalid!!\n", eeprom_id);
1587 rtlefuse->autoload_failflag = true;
1588 } else {
1589 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
1590 rtlefuse->autoload_failflag = false;
1591 }
1592
1593 if (rtlefuse->autoload_failflag == true)
1594 return;
1595
1596 rtlefuse->eeprom_vid = *(u16 *) &hwinfo[EEPROM_VID];
1597 rtlefuse->eeprom_did = *(u16 *) &hwinfo[EEPROM_DID];
1598 rtlefuse->eeprom_svid = *(u16 *) &hwinfo[EEPROM_SVID];
1599 rtlefuse->eeprom_smid = *(u16 *) &hwinfo[EEPROM_SMID];
1600 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1601 "EEPROMId = 0x%4x\n", eeprom_id);
1602 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1603 "EEPROM VID = 0x%4x\n", rtlefuse->eeprom_vid);
1604 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1605 "EEPROM DID = 0x%4x\n", rtlefuse->eeprom_did);
1606 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1607 "EEPROM SVID = 0x%4x\n", rtlefuse->eeprom_svid);
1608 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1609 "EEPROM SMID = 0x%4x\n", rtlefuse->eeprom_smid);
1610
1611 for (i = 0; i < 6; i += 2) {
1612 usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
1613 *((u16 *) (&rtlefuse->dev_addr[i])) = usvalue;
1614 }
1615
1616 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1617 "dev_addr: %pM\n", rtlefuse->dev_addr);
1618
1619 _rtl8723ae_read_txpower_info_from_hwpg(hw,
1620 rtlefuse->autoload_failflag, hwinfo);
1621
1622 rtl8723ae_read_bt_coexist_info_from_hwpg(hw,
1623 rtlefuse->autoload_failflag, hwinfo);
1624
Joe Perches9cb76aa2014-03-24 10:46:20 -07001625 rtlefuse->eeprom_channelplan = hwinfo[EEPROM_CHANNELPLAN];
Larry Fingerc592e632012-10-25 13:46:32 -05001626 rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
1627 rtlefuse->txpwr_fromeprom = true;
Joe Perches9cb76aa2014-03-24 10:46:20 -07001628 rtlefuse->eeprom_oemid = hwinfo[EEPROM_CUSTOMER_ID];
Larry Fingerc592e632012-10-25 13:46:32 -05001629
1630 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1631 "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid);
1632
1633 /* set channel paln to world wide 13 */
1634 rtlefuse->channel_plan = COUNTRY_CODE_WORLD_WIDE_13;
1635
1636 if (rtlhal->oem_id == RT_CID_DEFAULT) {
1637 switch (rtlefuse->eeprom_oemid) {
1638 case EEPROM_CID_DEFAULT:
1639 if (rtlefuse->eeprom_did == 0x8176) {
1640 if (CHK_SVID_SMID(0x10EC, 0x6151) ||
1641 CHK_SVID_SMID(0x10EC, 0x6152) ||
1642 CHK_SVID_SMID(0x10EC, 0x6154) ||
1643 CHK_SVID_SMID(0x10EC, 0x6155) ||
1644 CHK_SVID_SMID(0x10EC, 0x6177) ||
1645 CHK_SVID_SMID(0x10EC, 0x6178) ||
1646 CHK_SVID_SMID(0x10EC, 0x6179) ||
1647 CHK_SVID_SMID(0x10EC, 0x6180) ||
1648 CHK_SVID_SMID(0x10EC, 0x8151) ||
1649 CHK_SVID_SMID(0x10EC, 0x8152) ||
1650 CHK_SVID_SMID(0x10EC, 0x8154) ||
1651 CHK_SVID_SMID(0x10EC, 0x8155) ||
1652 CHK_SVID_SMID(0x10EC, 0x8181) ||
1653 CHK_SVID_SMID(0x10EC, 0x8182) ||
1654 CHK_SVID_SMID(0x10EC, 0x8184) ||
1655 CHK_SVID_SMID(0x10EC, 0x8185) ||
1656 CHK_SVID_SMID(0x10EC, 0x9151) ||
1657 CHK_SVID_SMID(0x10EC, 0x9152) ||
1658 CHK_SVID_SMID(0x10EC, 0x9154) ||
1659 CHK_SVID_SMID(0x10EC, 0x9155) ||
1660 CHK_SVID_SMID(0x10EC, 0x9181) ||
1661 CHK_SVID_SMID(0x10EC, 0x9182) ||
1662 CHK_SVID_SMID(0x10EC, 0x9184) ||
1663 CHK_SVID_SMID(0x10EC, 0x9185))
1664 rtlhal->oem_id = RT_CID_TOSHIBA;
1665 else if (rtlefuse->eeprom_svid == 0x1025)
Larry Finger2cddad32014-02-28 15:16:46 -06001666 rtlhal->oem_id = RT_CID_819X_ACER;
Larry Fingerc592e632012-10-25 13:46:32 -05001667 else if (CHK_SVID_SMID(0x10EC, 0x6191) ||
1668 CHK_SVID_SMID(0x10EC, 0x6192) ||
1669 CHK_SVID_SMID(0x10EC, 0x6193) ||
1670 CHK_SVID_SMID(0x10EC, 0x7191) ||
1671 CHK_SVID_SMID(0x10EC, 0x7192) ||
1672 CHK_SVID_SMID(0x10EC, 0x7193) ||
1673 CHK_SVID_SMID(0x10EC, 0x8191) ||
1674 CHK_SVID_SMID(0x10EC, 0x8192) ||
1675 CHK_SVID_SMID(0x10EC, 0x8193))
Larry Finger2cddad32014-02-28 15:16:46 -06001676 rtlhal->oem_id = RT_CID_819X_SAMSUNG;
Larry Fingerc592e632012-10-25 13:46:32 -05001677 else if (CHK_SVID_SMID(0x10EC, 0x8195) ||
1678 CHK_SVID_SMID(0x10EC, 0x9195) ||
1679 CHK_SVID_SMID(0x10EC, 0x7194) ||
1680 CHK_SVID_SMID(0x10EC, 0x8200) ||
1681 CHK_SVID_SMID(0x10EC, 0x8201) ||
1682 CHK_SVID_SMID(0x10EC, 0x8202) ||
1683 CHK_SVID_SMID(0x10EC, 0x9200))
Larry Finger2cddad32014-02-28 15:16:46 -06001684 rtlhal->oem_id = RT_CID_819X_LENOVO;
Larry Fingerc592e632012-10-25 13:46:32 -05001685 else if (CHK_SVID_SMID(0x10EC, 0x8197) ||
1686 CHK_SVID_SMID(0x10EC, 0x9196))
Larry Finger2cddad32014-02-28 15:16:46 -06001687 rtlhal->oem_id = RT_CID_819X_CLEVO;
Larry Fingerc592e632012-10-25 13:46:32 -05001688 else if (CHK_SVID_SMID(0x1028, 0x8194) ||
1689 CHK_SVID_SMID(0x1028, 0x8198) ||
1690 CHK_SVID_SMID(0x1028, 0x9197) ||
1691 CHK_SVID_SMID(0x1028, 0x9198))
Larry Finger2cddad32014-02-28 15:16:46 -06001692 rtlhal->oem_id = RT_CID_819X_DELL;
Larry Fingerc592e632012-10-25 13:46:32 -05001693 else if (CHK_SVID_SMID(0x103C, 0x1629))
Larry Finger2cddad32014-02-28 15:16:46 -06001694 rtlhal->oem_id = RT_CID_819X_HP;
Larry Fingerc592e632012-10-25 13:46:32 -05001695 else if (CHK_SVID_SMID(0x1A32, 0x2315))
Larry Finger2cddad32014-02-28 15:16:46 -06001696 rtlhal->oem_id = RT_CID_819X_QMI;
Larry Fingerc592e632012-10-25 13:46:32 -05001697 else if (CHK_SVID_SMID(0x10EC, 0x8203))
Larry Finger2cddad32014-02-28 15:16:46 -06001698 rtlhal->oem_id = RT_CID_819X_PRONETS;
Larry Fingerc592e632012-10-25 13:46:32 -05001699 else if (CHK_SVID_SMID(0x1043, 0x84B5))
1700 rtlhal->oem_id =
Larry Finger2cddad32014-02-28 15:16:46 -06001701 RT_CID_819X_EDIMAX_ASUS;
Larry Fingerc592e632012-10-25 13:46:32 -05001702 else
1703 rtlhal->oem_id = RT_CID_DEFAULT;
1704 } else if (rtlefuse->eeprom_did == 0x8178) {
1705 if (CHK_SVID_SMID(0x10EC, 0x6181) ||
1706 CHK_SVID_SMID(0x10EC, 0x6182) ||
1707 CHK_SVID_SMID(0x10EC, 0x6184) ||
1708 CHK_SVID_SMID(0x10EC, 0x6185) ||
1709 CHK_SVID_SMID(0x10EC, 0x7181) ||
1710 CHK_SVID_SMID(0x10EC, 0x7182) ||
1711 CHK_SVID_SMID(0x10EC, 0x7184) ||
1712 CHK_SVID_SMID(0x10EC, 0x7185) ||
1713 CHK_SVID_SMID(0x10EC, 0x8181) ||
1714 CHK_SVID_SMID(0x10EC, 0x8182) ||
1715 CHK_SVID_SMID(0x10EC, 0x8184) ||
1716 CHK_SVID_SMID(0x10EC, 0x8185) ||
1717 CHK_SVID_SMID(0x10EC, 0x9181) ||
1718 CHK_SVID_SMID(0x10EC, 0x9182) ||
1719 CHK_SVID_SMID(0x10EC, 0x9184) ||
1720 CHK_SVID_SMID(0x10EC, 0x9185))
1721 rtlhal->oem_id = RT_CID_TOSHIBA;
1722 else if (rtlefuse->eeprom_svid == 0x1025)
Larry Finger2cddad32014-02-28 15:16:46 -06001723 rtlhal->oem_id = RT_CID_819X_ACER;
Larry Fingerc592e632012-10-25 13:46:32 -05001724 else if (CHK_SVID_SMID(0x10EC, 0x8186))
Larry Finger2cddad32014-02-28 15:16:46 -06001725 rtlhal->oem_id = RT_CID_819X_PRONETS;
Larry Fingerc592e632012-10-25 13:46:32 -05001726 else if (CHK_SVID_SMID(0x1043, 0x8486))
1727 rtlhal->oem_id =
Larry Finger2cddad32014-02-28 15:16:46 -06001728 RT_CID_819X_EDIMAX_ASUS;
Larry Fingerc592e632012-10-25 13:46:32 -05001729 else
1730 rtlhal->oem_id = RT_CID_DEFAULT;
1731 } else {
1732 rtlhal->oem_id = RT_CID_DEFAULT;
1733 }
1734 break;
1735 case EEPROM_CID_TOSHIBA:
1736 rtlhal->oem_id = RT_CID_TOSHIBA;
1737 break;
1738 case EEPROM_CID_CCX:
1739 rtlhal->oem_id = RT_CID_CCX;
1740 break;
1741 case EEPROM_CID_QMI:
Larry Finger2cddad32014-02-28 15:16:46 -06001742 rtlhal->oem_id = RT_CID_819X_QMI;
Larry Fingerc592e632012-10-25 13:46:32 -05001743 break;
1744 case EEPROM_CID_WHQL:
1745 break;
1746 default:
1747 rtlhal->oem_id = RT_CID_DEFAULT;
1748 break;
1749
1750 }
1751 }
1752}
1753
1754static void _rtl8723ae_hal_customized_behavior(struct ieee80211_hw *hw)
1755{
1756 struct rtl_priv *rtlpriv = rtl_priv(hw);
1757 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
1758 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1759
Larry Fingere6deaf82013-03-24 22:06:55 -05001760 pcipriv->ledctl.led_opendrain = true;
Larry Fingerc592e632012-10-25 13:46:32 -05001761 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1762 "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
1763}
1764
1765void rtl8723ae_read_eeprom_info(struct ieee80211_hw *hw)
1766{
1767 struct rtl_priv *rtlpriv = rtl_priv(hw);
1768 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1769 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1770 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1771 u8 tmp_u1b;
1772 u32 value32;
1773
1774 value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST]);
1775 value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0);
1776 rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST], value32);
1777
1778 rtlhal->version = _rtl8723ae_read_chip_version(hw);
1779
1780 if (get_rf_type(rtlphy) == RF_1T1R)
1781 rtlpriv->dm.rfpath_rxenable[0] = true;
1782 else
1783 rtlpriv->dm.rfpath_rxenable[0] =
1784 rtlpriv->dm.rfpath_rxenable[1] = true;
1785 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
1786 rtlhal->version);
1787
1788 tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
1789 if (tmp_u1b & BIT(4)) {
1790 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
1791 rtlefuse->epromtype = EEPROM_93C46;
1792 } else {
1793 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
1794 rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
1795 }
1796 if (tmp_u1b & BIT(5)) {
1797 RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
1798 rtlefuse->autoload_failflag = false;
1799 _rtl8723ae_read_adapter_info(hw, false);
1800 } else {
1801 rtlefuse->autoload_failflag = true;
1802 _rtl8723ae_read_adapter_info(hw, false);
1803 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Autoload ERR!!\n");
1804 }
1805 _rtl8723ae_hal_customized_behavior(hw);
1806}
1807
1808static void rtl8723ae_update_hal_rate_table(struct ieee80211_hw *hw,
1809 struct ieee80211_sta *sta)
1810{
1811 struct rtl_priv *rtlpriv = rtl_priv(hw);
1812 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
1813 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1814 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1815 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1816 u32 ratr_value;
1817 u8 ratr_index = 0;
1818 u8 nmode = mac->ht_enable;
1819 u8 mimo_ps = IEEE80211_SMPS_OFF;
1820 u8 curtxbw_40mhz = mac->bw_40;
1821 u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1822 1 : 0;
1823 u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1824 1 : 0;
1825 enum wireless_mode wirelessmode = mac->mode;
1826
1827 if (rtlhal->current_bandtype == BAND_ON_5G)
1828 ratr_value = sta->supp_rates[1] << 4;
1829 else
1830 ratr_value = sta->supp_rates[0];
1831 if (mac->opmode == NL80211_IFTYPE_ADHOC)
1832 ratr_value = 0xfff;
1833 ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1834 sta->ht_cap.mcs.rx_mask[0] << 12);
1835 switch (wirelessmode) {
1836 case WIRELESS_MODE_B:
1837 if (ratr_value & 0x0000000c)
1838 ratr_value &= 0x0000000d;
1839 else
1840 ratr_value &= 0x0000000f;
1841 break;
1842 case WIRELESS_MODE_G:
1843 ratr_value &= 0x00000FF5;
1844 break;
1845 case WIRELESS_MODE_N_24G:
1846 case WIRELESS_MODE_N_5G:
1847 nmode = 1;
1848 if (mimo_ps == IEEE80211_SMPS_STATIC) {
1849 ratr_value &= 0x0007F005;
1850 } else {
1851 u32 ratr_mask;
1852
1853 if (get_rf_type(rtlphy) == RF_1T2R ||
1854 get_rf_type(rtlphy) == RF_1T1R)
1855 ratr_mask = 0x000ff005;
1856 else
1857 ratr_mask = 0x0f0ff005;
1858
1859 ratr_value &= ratr_mask;
1860 }
1861 break;
1862 default:
1863 if (rtlphy->rf_type == RF_1T2R)
1864 ratr_value &= 0x000ff0ff;
1865 else
1866 ratr_value &= 0x0f0ff0ff;
1867
1868 break;
1869 }
1870
1871 if ((pcipriv->bt_coexist.bt_coexistence) &&
1872 (pcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) &&
1873 (pcipriv->bt_coexist.bt_cur_state) &&
1874 (pcipriv->bt_coexist.bt_ant_isolation) &&
1875 ((pcipriv->bt_coexist.bt_service == BT_SCO) ||
1876 (pcipriv->bt_coexist.bt_service == BT_BUSY)))
1877 ratr_value &= 0x0fffcfc0;
1878 else
1879 ratr_value &= 0x0FFFFFFF;
1880
1881 if (nmode && ((curtxbw_40mhz && curshortgi_40mhz) ||
1882 (!curtxbw_40mhz && curshortgi_20mhz)))
1883 ratr_value |= 0x10000000;
1884
1885 rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
1886
1887 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1888 "%x\n", rtl_read_dword(rtlpriv, REG_ARFR0));
1889}
1890
1891static void rtl8723ae_update_hal_rate_mask(struct ieee80211_hw *hw,
1892 struct ieee80211_sta *sta, u8 rssi_level)
1893{
1894 struct rtl_priv *rtlpriv = rtl_priv(hw);
1895 struct rtl_phy *rtlphy = &(rtlpriv->phy);
1896 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1897 struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1898 struct rtl_sta_info *sta_entry = NULL;
1899 u32 ratr_bitmap;
1900 u8 ratr_index;
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001901 u8 curtxbw_40mhz = (sta->bandwidth >= IEEE80211_STA_RX_BW_40) ? 1 : 0;
Larry Fingerc592e632012-10-25 13:46:32 -05001902 u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1903 1 : 0;
1904 u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1905 1 : 0;
1906 enum wireless_mode wirelessmode = 0;
1907 bool shortgi = false;
1908 u8 rate_mask[5];
1909 u8 macid = 0;
1910 u8 mimo_ps = IEEE80211_SMPS_OFF;
1911
1912 sta_entry = (struct rtl_sta_info *) sta->drv_priv;
1913 wirelessmode = sta_entry->wireless_mode;
1914 if (mac->opmode == NL80211_IFTYPE_STATION)
1915 curtxbw_40mhz = mac->bw_40;
1916 else if (mac->opmode == NL80211_IFTYPE_AP ||
1917 mac->opmode == NL80211_IFTYPE_ADHOC)
1918 macid = sta->aid + 1;
1919
1920 if (rtlhal->current_bandtype == BAND_ON_5G)
1921 ratr_bitmap = sta->supp_rates[1] << 4;
1922 else
1923 ratr_bitmap = sta->supp_rates[0];
1924 if (mac->opmode == NL80211_IFTYPE_ADHOC)
1925 ratr_bitmap = 0xfff;
1926 ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1927 sta->ht_cap.mcs.rx_mask[0] << 12);
1928 switch (wirelessmode) {
1929 case WIRELESS_MODE_B:
1930 ratr_index = RATR_INX_WIRELESS_B;
1931 if (ratr_bitmap & 0x0000000c)
1932 ratr_bitmap &= 0x0000000d;
1933 else
1934 ratr_bitmap &= 0x0000000f;
1935 break;
1936 case WIRELESS_MODE_G:
1937 ratr_index = RATR_INX_WIRELESS_GB;
1938
1939 if (rssi_level == 1)
1940 ratr_bitmap &= 0x00000f00;
1941 else if (rssi_level == 2)
1942 ratr_bitmap &= 0x00000ff0;
1943 else
1944 ratr_bitmap &= 0x00000ff5;
1945 break;
1946 case WIRELESS_MODE_A:
1947 ratr_index = RATR_INX_WIRELESS_A;
1948 ratr_bitmap &= 0x00000ff0;
1949 break;
1950 case WIRELESS_MODE_N_24G:
1951 case WIRELESS_MODE_N_5G:
1952 ratr_index = RATR_INX_WIRELESS_NGB;
1953
1954 if (mimo_ps == IEEE80211_SMPS_STATIC) {
1955 if (rssi_level == 1)
1956 ratr_bitmap &= 0x00070000;
1957 else if (rssi_level == 2)
1958 ratr_bitmap &= 0x0007f000;
1959 else
1960 ratr_bitmap &= 0x0007f005;
1961 } else {
1962 if (rtlphy->rf_type == RF_1T2R ||
1963 rtlphy->rf_type == RF_1T1R) {
1964 if (curtxbw_40mhz) {
1965 if (rssi_level == 1)
1966 ratr_bitmap &= 0x000f0000;
1967 else if (rssi_level == 2)
1968 ratr_bitmap &= 0x000ff000;
1969 else
1970 ratr_bitmap &= 0x000ff015;
1971 } else {
1972 if (rssi_level == 1)
1973 ratr_bitmap &= 0x000f0000;
1974 else if (rssi_level == 2)
1975 ratr_bitmap &= 0x000ff000;
1976 else
1977 ratr_bitmap &= 0x000ff005;
1978 }
1979 } else {
1980 if (curtxbw_40mhz) {
1981 if (rssi_level == 1)
1982 ratr_bitmap &= 0x0f0f0000;
1983 else if (rssi_level == 2)
1984 ratr_bitmap &= 0x0f0ff000;
1985 else
1986 ratr_bitmap &= 0x0f0ff015;
1987 } else {
1988 if (rssi_level == 1)
1989 ratr_bitmap &= 0x0f0f0000;
1990 else if (rssi_level == 2)
1991 ratr_bitmap &= 0x0f0ff000;
1992 else
1993 ratr_bitmap &= 0x0f0ff005;
1994 }
1995 }
1996 }
1997
1998 if ((curtxbw_40mhz && curshortgi_40mhz) ||
1999 (!curtxbw_40mhz && curshortgi_20mhz)) {
2000 if (macid == 0)
2001 shortgi = true;
2002 else if (macid == 1)
2003 shortgi = false;
2004 }
2005 break;
2006 default:
2007 ratr_index = RATR_INX_WIRELESS_NGB;
2008
2009 if (rtlphy->rf_type == RF_1T2R)
2010 ratr_bitmap &= 0x000ff0ff;
2011 else
2012 ratr_bitmap &= 0x0f0ff0ff;
2013 break;
2014 }
2015 sta_entry->ratr_index = ratr_index;
2016
2017 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
2018 "ratr_bitmap :%x\n", ratr_bitmap);
2019 /* convert ratr_bitmap to le byte array */
2020 rate_mask[0] = ratr_bitmap;
2021 rate_mask[1] = (ratr_bitmap >>= 8);
2022 rate_mask[2] = (ratr_bitmap >>= 8);
2023 rate_mask[3] = ((ratr_bitmap >> 8) & 0x0f) | (ratr_index << 4);
2024 rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
2025 RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
2026 "Rate_index:%x, ratr_bitmap: %*phC\n",
2027 ratr_index, 5, rate_mask);
2028 rtl8723ae_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask);
2029}
2030
2031void rtl8723ae_update_hal_rate_tbl(struct ieee80211_hw *hw,
2032 struct ieee80211_sta *sta, u8 rssi_level)
2033{
2034 struct rtl_priv *rtlpriv = rtl_priv(hw);
2035
2036 if (rtlpriv->dm.useramask)
2037 rtl8723ae_update_hal_rate_mask(hw, sta, rssi_level);
2038 else
2039 rtl8723ae_update_hal_rate_table(hw, sta);
2040}
2041
2042void rtl8723ae_update_channel_access_setting(struct ieee80211_hw *hw)
2043{
2044 struct rtl_priv *rtlpriv = rtl_priv(hw);
2045 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2046 u16 sifs_timer;
2047
Joe Perches9cb76aa2014-03-24 10:46:20 -07002048 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, &mac->slot_time);
Larry Fingerc592e632012-10-25 13:46:32 -05002049 if (!mac->ht_enable)
2050 sifs_timer = 0x0a0a;
2051 else
2052 sifs_timer = 0x1010;
2053 rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
2054}
2055
2056bool rtl8723ae_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid)
2057{
2058 struct rtl_priv *rtlpriv = rtl_priv(hw);
2059 struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
2060 struct rtl_phy *rtlphy = &(rtlpriv->phy);
Larry Fingerb26f5f02013-02-01 10:40:27 -06002061 enum rf_pwrstate e_rfpowerstate_toset;
Larry Fingerc592e632012-10-25 13:46:32 -05002062 u8 u1tmp;
2063 bool actuallyset = false;
2064
2065 if (rtlpriv->rtlhal.being_init_adapter)
2066 return false;
2067
2068 if (ppsc->swrf_processing)
2069 return false;
2070
2071 spin_lock(&rtlpriv->locks.rf_ps_lock);
2072 if (ppsc->rfchange_inprogress) {
2073 spin_unlock(&rtlpriv->locks.rf_ps_lock);
2074 return false;
2075 } else {
2076 ppsc->rfchange_inprogress = true;
2077 spin_unlock(&rtlpriv->locks.rf_ps_lock);
2078 }
2079
Larry Fingerc592e632012-10-25 13:46:32 -05002080 rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL_2,
2081 rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL_2)&~(BIT(1)));
2082
2083 u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL_2);
2084
2085 if (rtlphy->polarity_ctl)
2086 e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFOFF : ERFON;
2087 else
2088 e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFON : ERFOFF;
2089
2090 if ((ppsc->hwradiooff == true) && (e_rfpowerstate_toset == ERFON)) {
2091 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2092 "GPIOChangeRF - HW Radio ON, RF ON\n");
2093
2094 e_rfpowerstate_toset = ERFON;
2095 ppsc->hwradiooff = false;
2096 actuallyset = true;
2097 } else if ((ppsc->hwradiooff == false)
2098 && (e_rfpowerstate_toset == ERFOFF)) {
2099 RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
2100 "GPIOChangeRF - HW Radio OFF, RF OFF\n");
2101
2102 e_rfpowerstate_toset = ERFOFF;
2103 ppsc->hwradiooff = true;
2104 actuallyset = true;
2105 }
2106
2107 if (actuallyset) {
2108 spin_lock(&rtlpriv->locks.rf_ps_lock);
2109 ppsc->rfchange_inprogress = false;
2110 spin_unlock(&rtlpriv->locks.rf_ps_lock);
2111 } else {
2112 if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC)
2113 RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);
2114
2115 spin_lock(&rtlpriv->locks.rf_ps_lock);
2116 ppsc->rfchange_inprogress = false;
2117 spin_unlock(&rtlpriv->locks.rf_ps_lock);
2118 }
2119
2120 *valid = 1;
2121 return !ppsc->hwradiooff;
2122}
2123
2124void rtl8723ae_set_key(struct ieee80211_hw *hw, u32 key_index,
2125 u8 *p_macaddr, bool is_group, u8 enc_algo,
2126 bool is_wepkey, bool clear_all)
2127{
2128 struct rtl_priv *rtlpriv = rtl_priv(hw);
2129 struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2130 struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2131 u8 *macaddr = p_macaddr;
2132 u32 entry_id = 0;
2133 bool is_pairwise = false;
2134 static u8 cam_const_addr[4][6] = {
2135 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2136 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2137 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2138 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2139 };
2140 static u8 cam_const_broad[] = {
2141 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2142 };
2143
2144 if (clear_all) {
2145 u8 idx = 0;
2146 u8 cam_offset = 0;
2147 u8 clear_number = 5;
2148
2149 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
2150
2151 for (idx = 0; idx < clear_number; idx++) {
2152 rtl_cam_mark_invalid(hw, cam_offset + idx);
2153 rtl_cam_empty_entry(hw, cam_offset + idx);
2154
2155 if (idx < 5) {
2156 memset(rtlpriv->sec.key_buf[idx], 0,
2157 MAX_KEY_LEN);
2158 rtlpriv->sec.key_len[idx] = 0;
2159 }
2160 }
2161 } else {
2162 switch (enc_algo) {
2163 case WEP40_ENCRYPTION:
2164 enc_algo = CAM_WEP40;
2165 break;
2166 case WEP104_ENCRYPTION:
2167 enc_algo = CAM_WEP104;
2168 break;
2169 case TKIP_ENCRYPTION:
2170 enc_algo = CAM_TKIP;
2171 break;
2172 case AESCCMP_ENCRYPTION:
2173 enc_algo = CAM_AES;
2174 break;
2175 default:
2176 RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
2177 "switch case not processed\n");
2178 enc_algo = CAM_TKIP;
2179 break;
2180 }
2181
2182 if (is_wepkey || rtlpriv->sec.use_defaultkey) {
2183 macaddr = cam_const_addr[key_index];
2184 entry_id = key_index;
2185 } else {
2186 if (is_group) {
2187 macaddr = cam_const_broad;
2188 entry_id = key_index;
2189 } else {
2190 if (mac->opmode == NL80211_IFTYPE_AP) {
2191 entry_id = rtl_cam_get_free_entry(hw,
2192 macaddr);
2193 if (entry_id >= TOTAL_CAM_ENTRY) {
2194 RT_TRACE(rtlpriv, COMP_SEC,
2195 DBG_EMERG,
2196 "Can not find free hw security cam entry\n");
2197 return;
2198 }
2199 } else {
2200 entry_id = CAM_PAIRWISE_KEY_POSITION;
2201 }
2202
2203 key_index = PAIRWISE_KEYIDX;
2204 is_pairwise = true;
2205 }
2206 }
2207
2208 if (rtlpriv->sec.key_len[key_index] == 0) {
2209 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2210 "delete one entry, entry_id is %d\n",
2211 entry_id);
2212 if (mac->opmode == NL80211_IFTYPE_AP)
2213 rtl_cam_del_entry(hw, p_macaddr);
2214 rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
2215 } else {
2216 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2217 "add one entry\n");
2218 if (is_pairwise) {
2219 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2220 "set Pairwiase key\n");
2221
2222 rtl_cam_add_one_entry(hw, macaddr, key_index,
2223 entry_id, enc_algo,
2224 CAM_CONFIG_NO_USEDK,
2225 rtlpriv->sec.key_buf[key_index]);
2226 } else {
2227 RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2228 "set group key\n");
2229
2230 if (mac->opmode == NL80211_IFTYPE_ADHOC) {
2231 rtl_cam_add_one_entry(hw,
2232 rtlefuse->dev_addr,
2233 PAIRWISE_KEYIDX,
2234 CAM_PAIRWISE_KEY_POSITION,
2235 enc_algo,
2236 CAM_CONFIG_NO_USEDK,
2237 rtlpriv->sec.key_buf
2238 [entry_id]);
2239 }
2240
2241 rtl_cam_add_one_entry(hw, macaddr, key_index,
2242 entry_id, enc_algo,
2243 CAM_CONFIG_NO_USEDK,
2244 rtlpriv->sec.key_buf[entry_id]);
2245 }
2246
2247 }
2248 }
2249}
2250
2251static void rtl8723ae_bt_var_init(struct ieee80211_hw *hw)
2252{
2253 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
2254 struct rtl_priv *rtlpriv = rtl_priv(hw);
2255
2256 pcipriv->bt_coexist.bt_coexistence =
2257 pcipriv->bt_coexist.eeprom_bt_coexist;
2258 pcipriv->bt_coexist.bt_ant_num =
2259 pcipriv->bt_coexist.eeprom_bt_ant_num;
2260 pcipriv->bt_coexist.bt_coexist_type =
2261 pcipriv->bt_coexist.eeprom_bt_type;
2262
2263 pcipriv->bt_coexist.bt_ant_isolation =
2264 pcipriv->bt_coexist.eeprom_bt_ant_isol;
2265
2266 pcipriv->bt_coexist.bt_radio_shared_type =
2267 pcipriv->bt_coexist.eeprom_bt_radio_shared;
2268
2269 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2270 "BT Coexistance = 0x%x\n",
2271 pcipriv->bt_coexist.bt_coexistence);
2272
2273 if (pcipriv->bt_coexist.bt_coexistence) {
2274 pcipriv->bt_coexist.bt_busy_traffic = false;
2275 pcipriv->bt_coexist.bt_traffic_mode_set = false;
2276 pcipriv->bt_coexist.bt_non_traffic_mode_set = false;
2277
2278 pcipriv->bt_coexist.cstate = 0;
2279 pcipriv->bt_coexist.previous_state = 0;
2280
2281 if (pcipriv->bt_coexist.bt_ant_num == ANT_X2) {
2282 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2283 "BlueTooth BT_Ant_Num = Antx2\n");
2284 } else if (pcipriv->bt_coexist.bt_ant_num == ANT_X1) {
2285 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2286 "BlueTooth BT_Ant_Num = Antx1\n");
2287 }
2288
2289 switch (pcipriv->bt_coexist.bt_coexist_type) {
2290 case BT_2WIRE:
2291 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2292 "BlueTooth BT_CoexistType = BT_2Wire\n");
2293 break;
2294 case BT_ISSC_3WIRE:
2295 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2296 "BlueTooth BT_CoexistType = BT_ISSC_3Wire\n");
2297 break;
2298 case BT_ACCEL:
2299 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2300 "BlueTooth BT_CoexistType = BT_ACCEL\n");
2301 break;
2302 case BT_CSR_BC4:
2303 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2304 "BlueTooth BT_CoexistType = BT_CSR_BC4\n");
2305 break;
2306 case BT_CSR_BC8:
2307 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2308 "BlueTooth BT_CoexistType = BT_CSR_BC8\n");
2309 break;
2310 case BT_RTL8756:
2311 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2312 "BlueTooth BT_CoexistType = BT_RTL8756\n");
2313 break;
2314 default:
2315 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2316 "BlueTooth BT_CoexistType = Unknown\n");
2317 break;
2318 }
2319 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2320 "BlueTooth BT_Ant_isolation = %d\n",
2321 pcipriv->bt_coexist.bt_ant_isolation);
2322 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE,
2323 "BT_RadioSharedType = 0x%x\n",
2324 pcipriv->bt_coexist.bt_radio_shared_type);
2325 pcipriv->bt_coexist.bt_active_zero_cnt = 0;
2326 pcipriv->bt_coexist.cur_bt_disabled = false;
2327 pcipriv->bt_coexist.pre_bt_disabled = false;
2328 }
2329}
2330
2331void rtl8723ae_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw,
2332 bool auto_load_fail, u8 *hwinfo)
2333{
2334 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
2335 struct rtl_priv *rtlpriv = rtl_priv(hw);
2336 u8 value;
2337 u32 tmpu_32;
2338
2339 if (!auto_load_fail) {
2340 tmpu_32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL);
2341 if (tmpu_32 & BIT(18))
2342 pcipriv->bt_coexist.eeprom_bt_coexist = 1;
2343 else
2344 pcipriv->bt_coexist.eeprom_bt_coexist = 0;
2345 value = hwinfo[RF_OPTION4];
2346 pcipriv->bt_coexist.eeprom_bt_type = BT_RTL8723A;
2347 pcipriv->bt_coexist.eeprom_bt_ant_num = (value & 0x1);
2348 pcipriv->bt_coexist.eeprom_bt_ant_isol = ((value & 0x10) >> 4);
2349 pcipriv->bt_coexist.eeprom_bt_radio_shared =
2350 ((value & 0x20) >> 5);
2351 } else {
2352 pcipriv->bt_coexist.eeprom_bt_coexist = 0;
2353 pcipriv->bt_coexist.eeprom_bt_type = BT_RTL8723A;
2354 pcipriv->bt_coexist.eeprom_bt_ant_num = ANT_X2;
2355 pcipriv->bt_coexist.eeprom_bt_ant_isol = 0;
2356 pcipriv->bt_coexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
2357 }
2358
2359 rtl8723ae_bt_var_init(hw);
2360}
2361
2362void rtl8723ae_bt_reg_init(struct ieee80211_hw *hw)
2363{
2364 struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
2365
2366 /* 0:Low, 1:High, 2:From Efuse. */
2367 pcipriv->bt_coexist.reg_bt_iso = 2;
2368 /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2369 pcipriv->bt_coexist.reg_bt_sco = 3;
2370 /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2371 pcipriv->bt_coexist.reg_bt_sco = 0;
2372}
2373
2374
2375void rtl8723ae_bt_hw_init(struct ieee80211_hw *hw)
2376{
2377}
2378
2379void rtl8723ae_suspend(struct ieee80211_hw *hw)
2380{
2381}
2382
2383void rtl8723ae_resume(struct ieee80211_hw *hw)
2384{
2385}
2386
2387/* Turn on AAP (RCR:bit 0) for promicuous mode. */
2388void rtl8723ae_allow_all_destaddr(struct ieee80211_hw *hw,
2389 bool allow_all_da, bool write_into_reg)
2390{
2391 struct rtl_priv *rtlpriv = rtl_priv(hw);
2392 struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
2393
2394 if (allow_all_da) /* Set BIT0 */
2395 rtlpci->receive_config |= RCR_AAP;
2396 else /* Clear BIT0 */
2397 rtlpci->receive_config &= ~RCR_AAP;
2398
2399 if (write_into_reg)
2400 rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
2401
2402
2403 RT_TRACE(rtlpriv, COMP_TURBO | COMP_INIT, DBG_LOUD,
2404 "receive_config=0x%08X, write_into_reg=%d\n",
2405 rtlpci->receive_config, write_into_reg);
2406}