Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hw.c
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * Copyright(c) 2009-2012 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  * The full GNU General Public License is included in this distribution in the
19  * file called LICENSE.
20  *
21  * Contact Information:
22  * wlanfae <[email protected]>
23  * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24  * Hsinchu 300, Taiwan.
25  *
26  * Larry Finger <[email protected]>
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 "../rtl8192c/fw_common.h"
41 #include "dm.h"
42 #include "led.h"
43 #include "hw.h"
44 
45 #define LLT_CONFIG 5
46 
47 static void _rtl92ce_set_bcn_ctrl_reg(struct ieee80211_hw *hw,
48  u8 set_bits, u8 clear_bits)
49 {
50  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
51  struct rtl_priv *rtlpriv = rtl_priv(hw);
52 
53  rtlpci->reg_bcn_ctrl_val |= set_bits;
54  rtlpci->reg_bcn_ctrl_val &= ~clear_bits;
55 
56  rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val);
57 }
58 
59 static void _rtl92ce_stop_tx_beacon(struct ieee80211_hw *hw)
60 {
61  struct rtl_priv *rtlpriv = rtl_priv(hw);
62  u8 tmp1byte;
63 
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);
70 }
71 
72 static void _rtl92ce_resume_tx_beacon(struct ieee80211_hw *hw)
73 {
74  struct rtl_priv *rtlpriv = rtl_priv(hw);
75  u8 tmp1byte;
76 
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);
83 }
84 
85 static void _rtl92ce_enable_bcn_sub_func(struct ieee80211_hw *hw)
86 {
87  _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(1));
88 }
89 
90 static void _rtl92ce_disable_bcn_sub_func(struct ieee80211_hw *hw)
91 {
92  _rtl92ce_set_bcn_ctrl_reg(hw, BIT(1), 0);
93 }
94 
96 {
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));
100 
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;
111 
112  rtlpriv->cfg->ops->get_hw_reg(hw,
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;
124  }
125  break;
126  }
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;
134 
135  *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4));
136  *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR);
137 
138  *((u64 *) (val)) = tsf;
139 
140  break;
141  }
142  default:
143  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
144  "switch case not processed\n");
145  break;
146  }
147 }
148 
150 {
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;
159 
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]);
165  }
166  break;
167  }
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++;
179  }
180  rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL,
181  rate_index);
182  break;
183  }
184  case HW_VAR_BSSID:{
185  for (idx = 0; idx < ETH_ALEN; idx++) {
186  rtl_write_byte(rtlpriv, (REG_BSSID + idx),
187  val[idx]);
188  }
189  break;
190  }
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]);
194 
195  rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]);
196  rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]);
197 
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;
205  }
206  case HW_VAR_SLOT_TIME:{
207  u8 e_aci;
208 
209  RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
210  "HW_VAR_SLOT_TIME %x\n", val[0]);
211 
212  rtl_write_byte(rtlpriv, REG_SLOT, val[0]);
213 
214  for (e_aci = 0; e_aci < AC_MAX; e_aci++) {
215  rtlpriv->cfg->ops->set_hw_reg(hw,
217  &e_aci);
218  }
219  break;
220  }
221  case HW_VAR_ACK_PREAMBLE:{
222  u8 reg_tmp;
223  u8 short_preamble = (bool)*val;
224  reg_tmp = (mac->cur_40_prime_sc) << 5;
225  if (short_preamble)
226  reg_tmp |= 0x80;
227 
228  rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp);
229  break;
230  }
232  u8 min_spacing_to_set;
233  u8 sec_min_space;
234 
235  min_spacing_to_set = *val;
236  if (min_spacing_to_set <= 7) {
237  sec_min_space = 0;
238 
239  if (min_spacing_to_set < sec_min_space)
240  min_spacing_to_set = sec_min_space;
241 
242  mac->min_space_cfg = ((mac->min_space_cfg &
243  0xf8) |
244  min_spacing_to_set);
245 
246  *val = min_spacing_to_set;
247 
248  RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
249  "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n",
250  mac->min_space_cfg);
251 
252  rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
253  mac->min_space_cfg);
254  }
255  break;
256  }
258  u8 density_to_set;
259 
260  density_to_set = *val;
261  mac->min_space_cfg |= (density_to_set << 3);
262 
263  RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
264  "Set HW_VAR_SHORTGI_DENSITY: %#x\n",
265  mac->min_space_cfg);
266 
267  rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE,
268  mac->min_space_cfg);
269 
270  break;
271  }
272  case HW_VAR_AMPDU_FACTOR:{
273  u8 regtoset_normal[4] = {0x41, 0xa8, 0x72, 0xb9};
274  u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97};
275 
276  u8 factor_toset;
277  u8 *p_regtoset = NULL;
278  u8 index = 0;
279 
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;
286 
287  factor_toset = *(val);
288  if (factor_toset <= 3) {
289  factor_toset = (1 << (factor_toset + 2));
290  if (factor_toset > 0xf)
291  factor_toset = 0xf;
292 
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);
299 
300  if ((p_regtoset[index] & 0x0f) >
301  factor_toset)
302  p_regtoset[index] =
303  (p_regtoset[index] & 0xf0) |
304  (factor_toset);
305 
306  rtl_write_byte(rtlpriv,
307  (REG_AGGLEN_LMT + index),
308  p_regtoset[index]);
309 
310  }
311 
312  RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD,
313  "Set HW_VAR_AMPDU_FACTOR: %#x\n",
314  factor_toset);
315  }
316  break;
317  }
318  case HW_VAR_AC_PARAM:{
319  u8 e_aci = *(val);
321 
322  if (rtlpci->acm_method != eAcmWay2_SW)
323  rtlpriv->cfg->ops->set_hw_reg(hw,
325  (&e_aci));
326  break;
327  }
328  case HW_VAR_ACM_CTRL:{
329  u8 e_aci = *(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);
334 
335  acm_ctrl =
336  acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1);
337 
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 failed: eACI is %d\n",
352  acm);
353  break;
354  }
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 processed\n");
369  break;
370  }
371  }
372 
373  RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE,
374  "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n",
375  acm_ctrl);
376  rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl);
377  break;
378  }
379  case HW_VAR_RCR:{
380  rtl_write_dword(rtlpriv, REG_RCR, ((u32 *) (val))[0]);
381  rtlpci->receive_config = ((u32 *) (val))[0];
382  break;
383  }
384  case HW_VAR_RETRY_LIMIT:{
385  u8 retry_limit = val[0];
386 
387  rtl_write_word(rtlpriv, REG_RL,
388  retry_limit << RETRY_LIMIT_SHORT_SHIFT |
389  retry_limit << RETRY_LIMIT_LONG_SHIFT);
390  break;
391  }
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 = *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, *val);
406  break;
407  case HW_VAR_SET_RPWM:{
408  u8 rpwm_val;
409 
410  rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM);
411  udelay(1);
412 
413  if (rpwm_val & BIT(7)) {
414  rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, *val);
415  } else {
416  rtl_write_byte(rtlpriv, REG_PCIE_HRPWM,
417  *val | BIT(7));
418  }
419 
420  break;
421  }
422  case HW_VAR_H2C_FW_PWRMODE:{
423  u8 psmode = *val;
424 
425  if ((psmode != FW_PS_ACTIVE_MODE) &&
426  (!IS_92C_SERIAL(rtlhal->version))) {
427  rtl92c_dm_rf_saving(hw, true);
428  }
429 
430  rtl92c_set_fw_pwrmode_cmd(hw, *val);
431  break;
432  }
434  ppsc->fw_current_inpsmode = *((bool *) val);
435  break;
437  u8 mstatus = *val;
438  u8 tmp_regcr, tmp_reg422;
439  bool recover = false;
440 
441  if (mstatus == RT_MEDIA_CONNECT) {
442  rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID,
443  NULL);
444 
445  tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1);
446  rtl_write_byte(rtlpriv, REG_CR + 1,
447  (tmp_regcr | BIT(0)));
448 
449  _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
450  _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
451 
452  tmp_reg422 =
453  rtl_read_byte(rtlpriv,
454  REG_FWHW_TXQ_CTRL + 2);
455  if (tmp_reg422 & BIT(6))
456  recover = true;
457  rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2,
458  tmp_reg422 & (~BIT(6)));
459 
461 
462  _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
463  _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
464 
465  if (recover) {
466  rtl_write_byte(rtlpriv,
467  REG_FWHW_TXQ_CTRL + 2,
468  tmp_reg422);
469  }
470 
471  rtl_write_byte(rtlpriv, REG_CR + 1,
472  (tmp_regcr & ~(BIT(0))));
473  }
475 
476  break;
477  }
478  case HW_VAR_AID:{
479  u16 u2btmp;
480  u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT);
481  u2btmp &= 0xC000;
482  rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, (u2btmp |
483  mac->assoc_id));
484 
485  break;
486  }
487  case HW_VAR_CORRECT_TSF:{
488  u8 btype_ibss = val[0];
489 
490  if (btype_ibss)
491  _rtl92ce_stop_tx_beacon(hw);
492 
493  _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(3));
494 
495  rtl_write_dword(rtlpriv, REG_TSFTR,
496  (u32) (mac->tsf & 0xffffffff));
497  rtl_write_dword(rtlpriv, REG_TSFTR + 4,
498  (u32) ((mac->tsf >> 32) & 0xffffffff));
499 
500  _rtl92ce_set_bcn_ctrl_reg(hw, BIT(3), 0);
501 
502  if (btype_ibss)
503  _rtl92ce_resume_tx_beacon(hw);
504 
505  break;
506 
507  }
508  default:
509  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
510  "switch case not processed\n");
511  break;
512  }
513 }
514 
515 static bool _rtl92ce_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) |
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 
542 static bool _rtl92ce_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 
550 #if LLT_CONFIG == 1
551  maxPage = 255;
552  txpktbuf_bndy = 252;
553 #elif LLT_CONFIG == 2
554  maxPage = 127;
555  txpktbuf_bndy = 124;
556 #elif LLT_CONFIG == 3
557  maxPage = 255;
558  txpktbuf_bndy = 174;
559 #elif LLT_CONFIG == 4
560  maxPage = 255;
561  txpktbuf_bndy = 246;
562 #elif LLT_CONFIG == 5
563  maxPage = 255;
564  txpktbuf_bndy = 246;
565 #endif
566 
567 #if LLT_CONFIG == 1
568  rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x1c);
569  rtl_write_dword(rtlpriv, REG_RQPN, 0x80a71c1c);
570 #elif LLT_CONFIG == 2
571  rtl_write_dword(rtlpriv, REG_RQPN, 0x845B1010);
572 #elif LLT_CONFIG == 3
573  rtl_write_dword(rtlpriv, REG_RQPN, 0x84838484);
574 #elif LLT_CONFIG == 4
575  rtl_write_dword(rtlpriv, REG_RQPN, 0x80bd1c1c);
576 #elif LLT_CONFIG == 5
577  rtl_write_word(rtlpriv, REG_RQPN_NPQ, 0x0000);
578 
579  rtl_write_dword(rtlpriv, REG_RQPN, 0x80b01c29);
580 #endif
581 
582  rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x27FF0000 | txpktbuf_bndy));
583  rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy);
584 
585  rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
586  rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
587 
588  rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy);
589  rtl_write_byte(rtlpriv, REG_PBP, 0x11);
590  rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4);
591 
592  for (i = 0; i < (txpktbuf_bndy - 1); i++) {
593  status = _rtl92ce_llt_write(hw, i, i + 1);
594  if (true != status)
595  return status;
596  }
597 
598  status = _rtl92ce_llt_write(hw, (txpktbuf_bndy - 1), 0xFF);
599  if (true != status)
600  return status;
601 
602  for (i = txpktbuf_bndy; i < maxPage; i++) {
603  status = _rtl92ce_llt_write(hw, i, (i + 1));
604  if (true != status)
605  return status;
606  }
607 
608  status = _rtl92ce_llt_write(hw, maxPage, txpktbuf_bndy);
609  if (true != status)
610  return status;
611 
612  return true;
613 }
614 
615 static void _rtl92ce_gen_refresh_led_state(struct ieee80211_hw *hw)
616 {
617  struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
618  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
619  struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
620  struct rtl_led *pLed0 = &(pcipriv->ledctl.sw_led0);
621 
622  if (rtlpci->up_first_time)
623  return;
624 
625  if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS)
626  rtl92ce_sw_led_on(hw, pLed0);
627  else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT)
628  rtl92ce_sw_led_on(hw, pLed0);
629  else
630  rtl92ce_sw_led_off(hw, pLed0);
631 }
632 
633 static bool _rtl92ce_init_mac(struct ieee80211_hw *hw)
634 {
635  struct rtl_priv *rtlpriv = rtl_priv(hw);
636  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
637  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
638  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
639 
640  unsigned char bytetmp;
641  unsigned short wordtmp;
642  u16 retry;
643 
644  rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00);
645  if (rtlpcipriv->bt_coexist.bt_coexistence) {
646  u32 value32;
647  value32 = rtl_read_dword(rtlpriv, REG_APS_FSMCO);
648  value32 |= (SOP_ABG | SOP_AMB | XOP_BTCK);
649  rtl_write_dword(rtlpriv, REG_APS_FSMCO, value32);
650  }
651  rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x2b);
652  rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL, 0x0F);
653 
654  if (rtlpcipriv->bt_coexist.bt_coexistence) {
655  u32 u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
656 
657  u4b_tmp &= (~0x00024800);
658  rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
659  }
660 
661  bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1) | BIT(0);
662  udelay(2);
663 
664  rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, bytetmp);
665  udelay(2);
666 
667  bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
668  udelay(2);
669 
670  retry = 0;
671  RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "reg0xec:%x:%x\n",
672  rtl_read_dword(rtlpriv, 0xEC), bytetmp);
673 
674  while ((bytetmp & BIT(0)) && retry < 1000) {
675  retry++;
676  udelay(50);
677  bytetmp = rtl_read_byte(rtlpriv, REG_APS_FSMCO + 1);
678  RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "reg0xec:%x:%x\n",
679  rtl_read_dword(rtlpriv, 0xEC), bytetmp);
680  udelay(50);
681  }
682 
683  rtl_write_word(rtlpriv, REG_APS_FSMCO, 0x1012);
684 
685  rtl_write_byte(rtlpriv, REG_SYS_ISO_CTRL + 1, 0x82);
686  udelay(2);
687 
688  if (rtlpcipriv->bt_coexist.bt_coexistence) {
689  bytetmp = rtl_read_byte(rtlpriv, REG_AFE_XTAL_CTRL+2) & 0xfd;
690  rtl_write_byte(rtlpriv, REG_AFE_XTAL_CTRL+2, bytetmp);
691  }
692 
693  rtl_write_word(rtlpriv, REG_CR, 0x2ff);
694 
695  if (!_rtl92ce_llt_table_init(hw))
696  return false;
697 
698  rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff);
699  rtl_write_byte(rtlpriv, REG_HISRE, 0xff);
700 
701  rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x27ff);
702 
703  wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL);
704  wordtmp &= 0xf;
705  wordtmp |= 0xF771;
706  rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp);
707 
708  rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F);
709  rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config);
710  rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config);
711 
712  rtl_write_byte(rtlpriv, 0x4d0, 0x0);
713 
714  rtl_write_dword(rtlpriv, REG_BCNQ_DESA,
715  ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) &
716  DMA_BIT_MASK(32));
717  rtl_write_dword(rtlpriv, REG_MGQ_DESA,
718  (u64) rtlpci->tx_ring[MGNT_QUEUE].dma &
719  DMA_BIT_MASK(32));
720  rtl_write_dword(rtlpriv, REG_VOQ_DESA,
721  (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32));
722  rtl_write_dword(rtlpriv, REG_VIQ_DESA,
723  (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32));
724  rtl_write_dword(rtlpriv, REG_BEQ_DESA,
725  (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32));
726  rtl_write_dword(rtlpriv, REG_BKQ_DESA,
727  (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32));
728  rtl_write_dword(rtlpriv, REG_HQ_DESA,
729  (u64) rtlpci->tx_ring[HIGH_QUEUE].dma &
730  DMA_BIT_MASK(32));
731  rtl_write_dword(rtlpriv, REG_RX_DESA,
732  (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma &
733  DMA_BIT_MASK(32));
734 
735  if (IS_92C_SERIAL(rtlhal->version))
736  rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x77);
737  else
738  rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x22);
739 
740  rtl_write_dword(rtlpriv, REG_INT_MIG, 0);
741 
742  bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
743  rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6));
744  do {
745  retry++;
746  bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL);
747  } while ((retry < 200) && (bytetmp & BIT(7)));
748 
749  _rtl92ce_gen_refresh_led_state(hw);
750 
751  rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0);
752 
753  return true;
754 }
755 
756 static void _rtl92ce_hw_configure(struct ieee80211_hw *hw)
757 {
758  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
759  struct rtl_priv *rtlpriv = rtl_priv(hw);
760  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
761  u8 reg_bw_opmode;
762  u32 reg_prsr;
763 
764  reg_bw_opmode = BW_OPMODE_20MHZ;
765  reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
766 
767  rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8);
768 
769  rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode);
770 
771  rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr);
772 
773  rtl_write_byte(rtlpriv, REG_SLOT, 0x09);
774 
775  rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0);
776 
777  rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80);
778 
779  rtl_write_word(rtlpriv, REG_RL, 0x0707);
780 
781  rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802);
782 
783  rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF);
784 
785  rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000);
786  rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504);
787  rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000);
788  rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504);
789 
790  if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
791  (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
792  rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431);
793  else
794  rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841);
795 
796  rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2);
797 
798  rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff);
799 
800  rtlpci->reg_bcn_ctrl_val = 0x1f;
801  rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val);
802 
803  rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
804 
805  rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff);
806 
807  rtl_write_byte(rtlpriv, REG_PIFS, 0x1C);
808  rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16);
809 
810  if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
811  (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4)) {
812  rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
813  rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402);
814  } else {
815  rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
816  rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020);
817  }
818 
819  if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
820  (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4))
821  rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666);
822  else
823  rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666);
824 
825  rtl_write_byte(rtlpriv, REG_ACKTO, 0x40);
826 
827  rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010);
828  rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010);
829 
830  rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010);
831 
832  rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010);
833 
834  rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff);
835  rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff);
836 
837 }
838 
839 static void _rtl92ce_enable_aspm_back_door(struct ieee80211_hw *hw)
840 {
841  struct rtl_priv *rtlpriv = rtl_priv(hw);
842  struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
843 
844  rtl_write_byte(rtlpriv, 0x34b, 0x93);
845  rtl_write_word(rtlpriv, 0x350, 0x870c);
846  rtl_write_byte(rtlpriv, 0x352, 0x1);
847 
848  if (ppsc->support_backdoor)
849  rtl_write_byte(rtlpriv, 0x349, 0x1b);
850  else
851  rtl_write_byte(rtlpriv, 0x349, 0x03);
852 
853  rtl_write_word(rtlpriv, 0x350, 0x2718);
854  rtl_write_byte(rtlpriv, 0x352, 0x1);
855 }
856 
858 {
859  struct rtl_priv *rtlpriv = rtl_priv(hw);
860  u8 sec_reg_value;
861 
862  RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
863  "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n",
864  rtlpriv->sec.pairwise_enc_algorithm,
865  rtlpriv->sec.group_enc_algorithm);
866 
867  if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) {
868  RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
869  "not open hw encryption\n");
870  return;
871  }
872 
873  sec_reg_value = SCR_TxEncEnable | SCR_RxDecEnable;
874 
875  if (rtlpriv->sec.use_defaultkey) {
876  sec_reg_value |= SCR_TxUseDK;
877  sec_reg_value |= SCR_RxUseDK;
878  }
879 
880  sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK);
881 
882  rtl_write_byte(rtlpriv, REG_CR + 1, 0x02);
883 
884  RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
885  "The SECR-value %x\n", sec_reg_value);
886 
887  rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value);
888 
889 }
890 
892 {
893  struct rtl_priv *rtlpriv = rtl_priv(hw);
894  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
895  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
896  struct rtl_phy *rtlphy = &(rtlpriv->phy);
897  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
898  struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
899  static bool iqk_initialized; /* initialized to false */
900  bool rtstatus = true;
901  bool is92c;
902  int err;
903  u8 tmp_u1b;
904 
905  rtlpci->being_init_adapter = true;
906  rtlpriv->intf_ops->disable_aspm(hw);
907  rtstatus = _rtl92ce_init_mac(hw);
908  if (!rtstatus) {
909  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Init MAC failed\n");
910  err = 1;
911  return err;
912  }
913 
914  err = rtl92c_download_fw(hw);
915  if (err) {
916  RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
917  "Failed to download FW. Init HW without FW now..\n");
918  err = 1;
919  return err;
920  }
921 
922  rtlhal->last_hmeboxnum = 0;
925  rtlphy->rf_mode = RF_OP_BY_SW_3WIRE;
927  rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0,
929  rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1,
931  rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1);
932  rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1);
933  rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1);
934  _rtl92ce_hw_configure(hw);
937 
938  ppsc->rfpwr_state = ERFON;
939 
940  rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr);
941  _rtl92ce_enable_aspm_back_door(hw);
942  rtlpriv->intf_ops->enable_aspm(hw);
943 
945 
946  if (ppsc->rfpwr_state == ERFON) {
948  if (iqk_initialized) {
949  rtl92c_phy_iq_calibrate(hw, true);
950  } else {
951  rtl92c_phy_iq_calibrate(hw, false);
952  iqk_initialized = true;
953  }
954 
957  }
958 
959  is92c = IS_92C_SERIAL(rtlhal->version);
960  tmp_u1b = efuse_read_1byte(hw, 0x1FA);
961  if (!(tmp_u1b & BIT(0))) {
962  rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05);
963  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path A\n");
964  }
965 
966  if (!(tmp_u1b & BIT(1)) && is92c) {
967  rtl_set_rfreg(hw, RF90_PATH_B, 0x15, 0x0F, 0x05);
968  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path B\n");
969  }
970 
971  if (!(tmp_u1b & BIT(4))) {
972  tmp_u1b = rtl_read_byte(rtlpriv, 0x16);
973  tmp_u1b &= 0x0F;
974  rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80);
975  udelay(10);
976  rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90);
977  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n");
978  }
979  rtl92c_dm_init(hw);
980  rtlpci->being_init_adapter = false;
981  return err;
982 }
983 
984 static enum version_8192c _rtl92ce_read_chip_version(struct ieee80211_hw *hw)
985 {
986  struct rtl_priv *rtlpriv = rtl_priv(hw);
987  struct rtl_phy *rtlphy = &(rtlpriv->phy);
989  u32 value32;
990  const char *versionid;
991 
992  value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG);
993  if (value32 & TRP_VAUX_EN) {
994  version = (value32 & TYPE_ID) ? VERSION_A_CHIP_92C :
996  } else {
997  version = (enum version_8192c) (CHIP_VER_B |
998  ((value32 & TYPE_ID) ? CHIP_92C_BITMASK : 0) |
999  ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0));
1000  if ((!IS_CHIP_VENDOR_UMC(version)) && (value32 &
1001  CHIP_VER_RTL_MASK)) {
1002  version = (enum version_8192c)(version |
1003  ((((value32 & CHIP_VER_RTL_MASK) == BIT(12))
1005  CHIP_VENDOR_UMC));
1006  }
1007  }
1008 
1009  switch (version) {
1010  case VERSION_B_CHIP_92C:
1011  versionid = "B_CHIP_92C";
1012  break;
1013  case VERSION_B_CHIP_88C:
1014  versionid = "B_CHIP_88C";
1015  break;
1016  case VERSION_A_CHIP_92C:
1017  versionid = "A_CHIP_92C";
1018  break;
1019  case VERSION_A_CHIP_88C:
1020  versionid = "A_CHIP_88C";
1021  break;
1022  default:
1023  versionid = "Unknown. Bug?";
1024  break;
1025  }
1026 
1027  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1028  "Chip Version ID: %s\n", versionid);
1029 
1030  switch (version & 0x3) {
1031  case CHIP_88C:
1032  rtlphy->rf_type = RF_1T1R;
1033  break;
1034  case CHIP_92C:
1035  rtlphy->rf_type = RF_2T2R;
1036  break;
1037  case CHIP_92C_1T2R:
1038  rtlphy->rf_type = RF_1T2R;
1039  break;
1040  default:
1041  rtlphy->rf_type = RF_1T1R;
1042  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1043  "ERROR RF_Type is set!!\n");
1044  break;
1045  }
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 
1053 static int _rtl92ce_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);
1058  enum led_ctl_mode ledaction = LED_CTL_NO_LINK;
1059  bt_msr &= 0xfc;
1060 
1061  if (type == NL80211_IFTYPE_UNSPECIFIED ||
1062  type == NL80211_IFTYPE_STATION) {
1063  _rtl92ce_stop_tx_beacon(hw);
1064  _rtl92ce_enable_bcn_sub_func(hw);
1065  } else if (type == NL80211_IFTYPE_ADHOC || type == NL80211_IFTYPE_AP) {
1066  _rtl92ce_resume_tx_beacon(hw);
1067  _rtl92ce_disable_bcn_sub_func(hw);
1068  } else {
1069  RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1070  "Set HW_VAR_MEDIA_STATUS: No such media status(%x)\n",
1071  type);
1072  }
1073 
1074  switch (type) {
1076  bt_msr |= MSR_NOLINK;
1077  ledaction = LED_CTL_LINK;
1078  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1079  "Set Network type to NO LINK!\n");
1080  break;
1081  case NL80211_IFTYPE_ADHOC:
1082  bt_msr |= MSR_ADHOC;
1083  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1084  "Set Network type to Ad Hoc!\n");
1085  break;
1087  bt_msr |= MSR_INFRA;
1088  ledaction = LED_CTL_LINK;
1089  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1090  "Set Network type to STA!\n");
1091  break;
1092  case NL80211_IFTYPE_AP:
1093  bt_msr |= MSR_AP;
1094  RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE,
1095  "Set Network type to AP!\n");
1096  break;
1097  default:
1098  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1099  "Network type %d not supported!\n", type);
1100  return 1;
1101  break;
1102 
1103  }
1104 
1105  rtl_write_byte(rtlpriv, (MSR), bt_msr);
1106  rtlpriv->cfg->ops->led_control(hw, ledaction);
1107  if ((bt_msr & 0xfc) == MSR_AP)
1108  rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00);
1109  else
1110  rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66);
1111  return 0;
1112 }
1113 
1114 void rtl92ce_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid)
1115 {
1116  struct rtl_priv *rtlpriv = rtl_priv(hw);
1117  u32 reg_rcr = rtl_read_dword(rtlpriv, REG_RCR);
1118 
1119  if (rtlpriv->psc.rfpwr_state != ERFON)
1120  return;
1121 
1122  if (check_bssid) {
1123  reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1124  rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR,
1125  (u8 *) (&reg_rcr));
1126  _rtl92ce_set_bcn_ctrl_reg(hw, 0, BIT(4));
1127  } else if (!check_bssid) {
1128  reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN));
1129  _rtl92ce_set_bcn_ctrl_reg(hw, BIT(4), 0);
1130  rtlpriv->cfg->ops->set_hw_reg(hw,
1131  HW_VAR_RCR, (u8 *) (&reg_rcr));
1132  }
1133 
1134 }
1135 
1137 {
1138  struct rtl_priv *rtlpriv = rtl_priv(hw);
1139 
1140  if (_rtl92ce_set_media_status(hw, type))
1141  return -EOPNOTSUPP;
1142 
1143  if (rtlpriv->mac80211.link_state == MAC80211_LINKED) {
1144  if (type != NL80211_IFTYPE_AP)
1145  rtl92ce_set_check_bssid(hw, true);
1146  } else {
1147  rtl92ce_set_check_bssid(hw, false);
1148  }
1149 
1150  return 0;
1151 }
1152 
1153 /* don't set REG_EDCA_BE_PARAM here because mac80211 will send pkt when scan */
1154 void rtl92ce_set_qos(struct ieee80211_hw *hw, int aci)
1155 {
1156  struct rtl_priv *rtlpriv = rtl_priv(hw);
1158  switch (aci) {
1159  case AC1_BK:
1160  rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f);
1161  break;
1162  case AC0_BE:
1163  /* rtl_write_dword(rtlpriv, REG_EDCA_BE_PARAM, u4b_ac_param); */
1164  break;
1165  case AC2_VI:
1166  rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322);
1167  break;
1168  case AC3_VO:
1169  rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222);
1170  break;
1171  default:
1172  RT_ASSERT(false, "invalid aci: %d !\n", aci);
1173  break;
1174  }
1175 }
1176 
1178 {
1179  struct rtl_priv *rtlpriv = rtl_priv(hw);
1180  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1181 
1182  rtl_write_dword(rtlpriv, REG_HIMR, rtlpci->irq_mask[0] & 0xFFFFFFFF);
1183  rtl_write_dword(rtlpriv, REG_HIMRE, rtlpci->irq_mask[1] & 0xFFFFFFFF);
1184 }
1185 
1187 {
1188  struct rtl_priv *rtlpriv = rtl_priv(hw);
1189  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1190 
1191  rtl_write_dword(rtlpriv, REG_HIMR, IMR8190_DISABLED);
1192  rtl_write_dword(rtlpriv, REG_HIMRE, IMR8190_DISABLED);
1193  synchronize_irq(rtlpci->pdev->irq);
1194 }
1195 
1196 static void _rtl92ce_poweroff_adapter(struct ieee80211_hw *hw)
1197 {
1198  struct rtl_priv *rtlpriv = rtl_priv(hw);
1199  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1200  u8 u1b_tmp;
1201  u32 u4b_tmp;
1202 
1203  rtlpriv->intf_ops->enable_aspm(hw);
1204  rtl_write_byte(rtlpriv, REG_TXPAUSE, 0xFF);
1205  rtl_set_rfreg(hw, RF90_PATH_A, 0x00, RFREG_OFFSET_MASK, 0x00);
1206  rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00);
1207  rtl_write_byte(rtlpriv, REG_APSD_CTRL, 0x40);
1208  rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE2);
1209  rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN, 0xE0);
1210  if (rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7))
1212  rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN + 1, 0x51);
1213  rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00);
1214  rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00000000);
1215  u1b_tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL);
1216  if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
1217  ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
1218  (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8))) {
1219  rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00F30000 |
1220  (u1b_tmp << 8));
1221  } else {
1222  rtl_write_dword(rtlpriv, REG_GPIO_PIN_CTRL, 0x00FF0000 |
1223  (u1b_tmp << 8));
1224  }
1225  rtl_write_word(rtlpriv, REG_GPIO_IO_SEL, 0x0790);
1226  rtl_write_word(rtlpriv, REG_LEDCFG0, 0x8080);
1227  rtl_write_byte(rtlpriv, REG_AFE_PLL_CTRL, 0x80);
1228  rtl_write_byte(rtlpriv, REG_SPS0_CTRL, 0x23);
1229  if (rtlpcipriv->bt_coexist.bt_coexistence) {
1230  u4b_tmp = rtl_read_dword(rtlpriv, REG_AFE_XTAL_CTRL);
1231  u4b_tmp |= 0x03824800;
1232  rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, u4b_tmp);
1233  } else {
1234  rtl_write_dword(rtlpriv, REG_AFE_XTAL_CTRL, 0x0e);
1235  }
1236 
1237  rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e);
1238  rtl_write_byte(rtlpriv, REG_APS_FSMCO + 1, 0x10);
1239 }
1240 
1242 {
1243  struct rtl_priv *rtlpriv = rtl_priv(hw);
1244  struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1245  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1246  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1247  enum nl80211_iftype opmode;
1248 
1249  mac->link_state = MAC80211_NOLINK;
1250  opmode = NL80211_IFTYPE_UNSPECIFIED;
1251  _rtl92ce_set_media_status(hw, opmode);
1252  if (rtlpci->driver_is_goingto_unload ||
1253  ppsc->rfoff_reason > RF_CHANGE_BY_PS)
1254  rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);
1256  _rtl92ce_poweroff_adapter(hw);
1257 }
1258 
1260  u32 *p_inta, u32 *p_intb)
1261 {
1262  struct rtl_priv *rtlpriv = rtl_priv(hw);
1263  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1264 
1265  *p_inta = rtl_read_dword(rtlpriv, ISR) & rtlpci->irq_mask[0];
1266  rtl_write_dword(rtlpriv, ISR, *p_inta);
1267 
1268  /*
1269  * *p_intb = rtl_read_dword(rtlpriv, REG_HISRE) & rtlpci->irq_mask[1];
1270  * rtl_write_dword(rtlpriv, ISR + 4, *p_intb);
1271  */
1272 }
1273 
1275 {
1276 
1277  struct rtl_priv *rtlpriv = rtl_priv(hw);
1278  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1279  u16 bcn_interval, atim_window;
1280 
1281  bcn_interval = mac->beacon_interval;
1282  atim_window = 2; /*FIX MERGE */
1284  rtl_write_word(rtlpriv, REG_ATIMWND, atim_window);
1285  rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1286  rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f);
1287  rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18);
1288  rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18);
1289  rtl_write_byte(rtlpriv, 0x606, 0x30);
1291 }
1292 
1294 {
1295  struct rtl_priv *rtlpriv = rtl_priv(hw);
1296  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1297  u16 bcn_interval = mac->beacon_interval;
1298 
1299  RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG,
1300  "beacon_interval:%d\n", bcn_interval);
1302  rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval);
1304 }
1305 
1307  u32 add_msr, u32 rm_msr)
1308 {
1309  struct rtl_priv *rtlpriv = rtl_priv(hw);
1310  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1311 
1312  RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, "add_msr:%x, rm_msr:%x\n",
1313  add_msr, rm_msr);
1314 
1315  if (add_msr)
1316  rtlpci->irq_mask[0] |= add_msr;
1317  if (rm_msr)
1318  rtlpci->irq_mask[0] &= (~rm_msr);
1321 }
1322 
1323 static void _rtl92ce_read_txpower_info_from_hwpg(struct ieee80211_hw *hw,
1324  bool autoload_fail,
1325  u8 *hwinfo)
1326 {
1327  struct rtl_priv *rtlpriv = rtl_priv(hw);
1328  struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1329  u8 rf_path, index, tempval;
1330  u16 i;
1331 
1332  for (rf_path = 0; rf_path < 2; rf_path++) {
1333  for (i = 0; i < 3; i++) {
1334  if (!autoload_fail) {
1335  rtlefuse->
1336  eeprom_chnlarea_txpwr_cck[rf_path][i] =
1337  hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i];
1338  rtlefuse->
1339  eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
1340  hwinfo[EEPROM_TXPOWERHT40_1S + rf_path * 3 +
1341  i];
1342  } else {
1343  rtlefuse->
1344  eeprom_chnlarea_txpwr_cck[rf_path][i] =
1346  rtlefuse->
1347  eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] =
1349  }
1350  }
1351  }
1352 
1353  for (i = 0; i < 3; i++) {
1354  if (!autoload_fail)
1355  tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i];
1356  else
1357  tempval = EEPROM_DEFAULT_HT40_2SDIFF;
1359  (tempval & 0xf);
1361  ((tempval & 0xf0) >> 4);
1362  }
1363 
1364  for (rf_path = 0; rf_path < 2; rf_path++)
1365  for (i = 0; i < 3; i++)
1366  RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1367  "RF(%d) EEPROM CCK Area(%d) = 0x%x\n",
1368  rf_path, i,
1369  rtlefuse->
1370  eeprom_chnlarea_txpwr_cck[rf_path][i]);
1371  for (rf_path = 0; rf_path < 2; rf_path++)
1372  for (i = 0; i < 3; i++)
1373  RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1374  "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n",
1375  rf_path, i,
1376  rtlefuse->
1377  eeprom_chnlarea_txpwr_ht40_1s[rf_path][i]);
1378  for (rf_path = 0; rf_path < 2; rf_path++)
1379  for (i = 0; i < 3; i++)
1380  RTPRINT(rtlpriv, FINIT, INIT_EEPROM,
1381  "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n",
1382  rf_path, i,
1383  rtlefuse->
1384  eeprom_chnlarea_txpwr_ht40_2sdiif[rf_path][i]);
1385 
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);
1389 
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->
1395 
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->
1404  [index] -
1405  rtlefuse->
1407  [index];
1408  } else {
1409  rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0;
1410  }
1411  }
1412 
1413  for (i = 0; i < 14; i++) {
1414  RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1415  "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n",
1416  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]);
1420  }
1421  }
1422 
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;
1432  }
1433  }
1434 
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);
1438 
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);
1453  }
1454 
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]);
1463  }
1464  }
1465 
1466  for (i = 0; i < 14; i++) {
1467  index = _rtl92c_get_chnl_group((u8) i);
1468 
1469  if (!autoload_fail)
1470  tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index];
1471  else
1472  tempval = EEPROM_DEFAULT_HT20_DIFF;
1473 
1474  rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF);
1475  rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] =
1476  ((tempval >> 4) & 0xF);
1477 
1478  if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3))
1479  rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0;
1480 
1481  if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3))
1482  rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0;
1483 
1484  index = _rtl92c_get_chnl_group((u8) i);
1485 
1486  if (!autoload_fail)
1487  tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index];
1488  else
1490 
1491  rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF);
1492  rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] =
1493  ((tempval >> 4) & 0xF);
1494  }
1495 
1496  rtlefuse->legacy_ht_txpowerdiff =
1497  rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7];
1498 
1499  for (i = 0; i < 14; i++)
1500  RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1501  "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n",
1502  i, 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",
1506  i, 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",
1510  i, 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",
1514  i, rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]);
1515 
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);
1522 
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 {
1529  }
1530  RTPRINT(rtlpriv, FINIT, INIT_TxPower, "TSSI_A = 0x%x, TSSI_B = 0x%x\n",
1531  rtlefuse->eeprom_tssi[RF90_PATH_A],
1532  rtlefuse->eeprom_tssi[RF90_PATH_B]);
1533 
1534  if (!autoload_fail)
1535  tempval = hwinfo[EEPROM_THERMAL_METER];
1536  else
1537  tempval = EEPROM_DEFAULT_THERMALMETER;
1538  rtlefuse->eeprom_thermalmeter = (tempval & 0x1f);
1539 
1540  if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail)
1541  rtlefuse->apk_thermalmeterignore = true;
1542 
1543  rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter;
1544  RTPRINT(rtlpriv, FINIT, INIT_TxPower,
1545  "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter);
1546 }
1547 
1548 static void _rtl92ce_read_adapter_info(struct ieee80211_hw *hw)
1549 {
1550  struct rtl_priv *rtlpriv = rtl_priv(hw);
1551  struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1552  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1553  u16 i, usvalue;
1554  u8 hwinfo[HWSET_MAX_SIZE];
1555  u16 eeprom_id;
1556 
1557  if (rtlefuse->epromtype == EEPROM_BOOT_EFUSE) {
1559 
1560  memcpy((void *)hwinfo,
1561  (void *)&rtlefuse->efuse_map[EFUSE_INIT_MAP][0],
1562  HWSET_MAX_SIZE);
1563  } else if (rtlefuse->epromtype == EEPROM_93C46) {
1564  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
1565  "RTL819X Not boot from eeprom, check it !!");
1566  }
1567 
1568  RT_PRINT_DATA(rtlpriv, COMP_INIT, DBG_DMESG, "MAP",
1569  hwinfo, HWSET_MAX_SIZE);
1570 
1571  eeprom_id = *((u16 *)&hwinfo[0]);
1572  if (eeprom_id != RTL8190_EEPROM_ID) {
1573  RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1574  "EEPROM ID(%#x) is invalid!!\n", eeprom_id);
1575  rtlefuse->autoload_failflag = true;
1576  } else {
1577  RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
1578  rtlefuse->autoload_failflag = false;
1579  }
1580 
1581  if (rtlefuse->autoload_failflag)
1582  return;
1583 
1584  for (i = 0; i < 6; i += 2) {
1585  usvalue = *(u16 *)&hwinfo[EEPROM_MAC_ADDR + i];
1586  *((u16 *) (&rtlefuse->dev_addr[i])) = usvalue;
1587  }
1588 
1589  RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "%pM\n", rtlefuse->dev_addr);
1590 
1591  _rtl92ce_read_txpower_info_from_hwpg(hw,
1592  rtlefuse->autoload_failflag,
1593  hwinfo);
1594 
1596  rtlefuse->autoload_failflag,
1597  hwinfo);
1598 
1599  rtlefuse->eeprom_channelplan = *&hwinfo[EEPROM_CHANNELPLAN];
1600  rtlefuse->eeprom_version = *(u16 *)&hwinfo[EEPROM_VERSION];
1601  rtlefuse->txpwr_fromeprom = true;
1602  rtlefuse->eeprom_oemid = *&hwinfo[EEPROM_CUSTOMER_ID];
1603 
1604  RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1605  "EEPROM Customer ID: 0x%2x\n", rtlefuse->eeprom_oemid);
1606 
1607  /* set channel paln to world wide 13 */
1609 
1610  if (rtlhal->oem_id == RT_CID_DEFAULT) {
1611  switch (rtlefuse->eeprom_oemid) {
1612  case EEPROM_CID_DEFAULT:
1613  if (rtlefuse->eeprom_did == 0x8176) {
1614  if ((rtlefuse->eeprom_svid == 0x103C &&
1615  rtlefuse->eeprom_smid == 0x1629))
1616  rtlhal->oem_id = RT_CID_819x_HP;
1617  else
1618  rtlhal->oem_id = RT_CID_DEFAULT;
1619  } else {
1620  rtlhal->oem_id = RT_CID_DEFAULT;
1621  }
1622  break;
1623  case EEPROM_CID_TOSHIBA:
1624  rtlhal->oem_id = RT_CID_TOSHIBA;
1625  break;
1626  case EEPROM_CID_QMI:
1627  rtlhal->oem_id = RT_CID_819x_QMI;
1628  break;
1629  case EEPROM_CID_WHQL:
1630  default:
1631  rtlhal->oem_id = RT_CID_DEFAULT;
1632  break;
1633 
1634  }
1635  }
1636 
1637 }
1638 
1639 static void _rtl92ce_hal_customized_behavior(struct ieee80211_hw *hw)
1640 {
1641  struct rtl_priv *rtlpriv = rtl_priv(hw);
1642  struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
1643  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1644 
1645  switch (rtlhal->oem_id) {
1646  case RT_CID_819x_HP:
1647  pcipriv->ledctl.led_opendrain = true;
1648  break;
1649  case RT_CID_819x_Lenovo:
1650  case RT_CID_DEFAULT:
1651  case RT_CID_TOSHIBA:
1652  case RT_CID_CCX:
1653  case RT_CID_819x_Acer:
1654  case RT_CID_WHQL:
1655  default:
1656  break;
1657  }
1658  RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1659  "RT Customized ID: 0x%02X\n", rtlhal->oem_id);
1660 }
1661 
1663 {
1664  struct rtl_priv *rtlpriv = rtl_priv(hw);
1665  struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
1666  struct rtl_phy *rtlphy = &(rtlpriv->phy);
1667  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1668  u8 tmp_u1b;
1669 
1670  rtlhal->version = _rtl92ce_read_chip_version(hw);
1671  if (get_rf_type(rtlphy) == RF_1T1R)
1672  rtlpriv->dm.rfpath_rxenable[0] = true;
1673  else
1674  rtlpriv->dm.rfpath_rxenable[0] =
1675  rtlpriv->dm.rfpath_rxenable[1] = true;
1676  RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n",
1677  rtlhal->version);
1678  tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR);
1679  if (tmp_u1b & BIT(4)) {
1680  RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n");
1681  rtlefuse->epromtype = EEPROM_93C46;
1682  } else {
1683  RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n");
1684  rtlefuse->epromtype = EEPROM_BOOT_EFUSE;
1685  }
1686  if (tmp_u1b & BIT(5)) {
1687  RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n");
1688  rtlefuse->autoload_failflag = false;
1689  _rtl92ce_read_adapter_info(hw);
1690  } else {
1691  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Autoload ERR!!\n");
1692  }
1693  _rtl92ce_hal_customized_behavior(hw);
1694 }
1695 
1696 static void rtl92ce_update_hal_rate_table(struct ieee80211_hw *hw,
1697  struct ieee80211_sta *sta)
1698 {
1699  struct rtl_priv *rtlpriv = rtl_priv(hw);
1700  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
1701  struct rtl_phy *rtlphy = &(rtlpriv->phy);
1702  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1703  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1704  u32 ratr_value;
1705  u8 ratr_index = 0;
1706  u8 nmode = mac->ht_enable;
1707  u8 mimo_ps = IEEE80211_SMPS_OFF;
1708  u16 shortgi_rate;
1709  u32 tmp_ratr_value;
1710  u8 curtxbw_40mhz = mac->bw_40;
1711  u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1712  1 : 0;
1713  u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1714  1 : 0;
1715  enum wireless_mode wirelessmode = mac->mode;
1716 
1717  if (rtlhal->current_bandtype == BAND_ON_5G)
1718  ratr_value = sta->supp_rates[1] << 4;
1719  else
1720  ratr_value = sta->supp_rates[0];
1721  ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1722  sta->ht_cap.mcs.rx_mask[0] << 12);
1723  switch (wirelessmode) {
1724  case WIRELESS_MODE_B:
1725  if (ratr_value & 0x0000000c)
1726  ratr_value &= 0x0000000d;
1727  else
1728  ratr_value &= 0x0000000f;
1729  break;
1730  case WIRELESS_MODE_G:
1731  ratr_value &= 0x00000FF5;
1732  break;
1733  case WIRELESS_MODE_N_24G:
1734  case WIRELESS_MODE_N_5G:
1735  nmode = 1;
1736  if (mimo_ps == IEEE80211_SMPS_STATIC) {
1737  ratr_value &= 0x0007F005;
1738  } else {
1739  u32 ratr_mask;
1740 
1741  if (get_rf_type(rtlphy) == RF_1T2R ||
1742  get_rf_type(rtlphy) == RF_1T1R)
1743  ratr_mask = 0x000ff005;
1744  else
1745  ratr_mask = 0x0f0ff005;
1746 
1747  ratr_value &= ratr_mask;
1748  }
1749  break;
1750  default:
1751  if (rtlphy->rf_type == RF_1T2R)
1752  ratr_value &= 0x000ff0ff;
1753  else
1754  ratr_value &= 0x0f0ff0ff;
1755 
1756  break;
1757  }
1758 
1759  if ((rtlpcipriv->bt_coexist.bt_coexistence) &&
1760  (rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) &&
1761  (rtlpcipriv->bt_coexist.bt_cur_state) &&
1762  (rtlpcipriv->bt_coexist.bt_ant_isolation) &&
1763  ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ||
1764  (rtlpcipriv->bt_coexist.bt_service == BT_BUSY)))
1765  ratr_value &= 0x0fffcfc0;
1766  else
1767  ratr_value &= 0x0FFFFFFF;
1768 
1769  if (nmode && ((curtxbw_40mhz &&
1770  curshortgi_40mhz) || (!curtxbw_40mhz &&
1771  curshortgi_20mhz))) {
1772 
1773  ratr_value |= 0x10000000;
1774  tmp_ratr_value = (ratr_value >> 12);
1775 
1776  for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) {
1777  if ((1 << shortgi_rate) & tmp_ratr_value)
1778  break;
1779  }
1780 
1781  shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) |
1782  (shortgi_rate << 4) | (shortgi_rate);
1783  }
1784 
1785  rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value);
1786 
1787  RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, "%x\n",
1788  rtl_read_dword(rtlpriv, REG_ARFR0));
1789 }
1790 
1791 static void rtl92ce_update_hal_rate_mask(struct ieee80211_hw *hw,
1792  struct ieee80211_sta *sta, u8 rssi_level)
1793 {
1794  struct rtl_priv *rtlpriv = rtl_priv(hw);
1795  struct rtl_phy *rtlphy = &(rtlpriv->phy);
1796  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1797  struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1798  struct rtl_sta_info *sta_entry = NULL;
1799  u32 ratr_bitmap;
1800  u8 ratr_index;
1801  u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
1802  ? 1 : 0;
1803  u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ?
1804  1 : 0;
1805  u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ?
1806  1 : 0;
1807  enum wireless_mode wirelessmode = 0;
1808  bool shortgi = false;
1809  u8 rate_mask[5];
1810  u8 macid = 0;
1811  u8 mimo_ps = IEEE80211_SMPS_OFF;
1812 
1813  sta_entry = (struct rtl_sta_info *) sta->drv_priv;
1814  wirelessmode = sta_entry->wireless_mode;
1815  if (mac->opmode == NL80211_IFTYPE_STATION)
1816  curtxbw_40mhz = mac->bw_40;
1817  else if (mac->opmode == NL80211_IFTYPE_AP ||
1818  mac->opmode == NL80211_IFTYPE_ADHOC)
1819  macid = sta->aid + 1;
1820 
1821  if (rtlhal->current_bandtype == BAND_ON_5G)
1822  ratr_bitmap = sta->supp_rates[1] << 4;
1823  else
1824  ratr_bitmap = sta->supp_rates[0];
1825  ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 |
1826  sta->ht_cap.mcs.rx_mask[0] << 12);
1827  switch (wirelessmode) {
1828  case WIRELESS_MODE_B:
1829  ratr_index = RATR_INX_WIRELESS_B;
1830  if (ratr_bitmap & 0x0000000c)
1831  ratr_bitmap &= 0x0000000d;
1832  else
1833  ratr_bitmap &= 0x0000000f;
1834  break;
1835  case WIRELESS_MODE_G:
1836  ratr_index = RATR_INX_WIRELESS_GB;
1837 
1838  if (rssi_level == 1)
1839  ratr_bitmap &= 0x00000f00;
1840  else if (rssi_level == 2)
1841  ratr_bitmap &= 0x00000ff0;
1842  else
1843  ratr_bitmap &= 0x00000ff5;
1844  break;
1845  case WIRELESS_MODE_A:
1846  ratr_index = RATR_INX_WIRELESS_A;
1847  ratr_bitmap &= 0x00000ff0;
1848  break;
1849  case WIRELESS_MODE_N_24G:
1850  case WIRELESS_MODE_N_5G:
1851  ratr_index = RATR_INX_WIRELESS_NGB;
1852 
1853  if (mimo_ps == IEEE80211_SMPS_STATIC) {
1854  if (rssi_level == 1)
1855  ratr_bitmap &= 0x00070000;
1856  else if (rssi_level == 2)
1857  ratr_bitmap &= 0x0007f000;
1858  else
1859  ratr_bitmap &= 0x0007f005;
1860  } else {
1861  if (rtlphy->rf_type == RF_1T2R ||
1862  rtlphy->rf_type == RF_1T1R) {
1863  if (curtxbw_40mhz) {
1864  if (rssi_level == 1)
1865  ratr_bitmap &= 0x000f0000;
1866  else if (rssi_level == 2)
1867  ratr_bitmap &= 0x000ff000;
1868  else
1869  ratr_bitmap &= 0x000ff015;
1870  } else {
1871  if (rssi_level == 1)
1872  ratr_bitmap &= 0x000f0000;
1873  else if (rssi_level == 2)
1874  ratr_bitmap &= 0x000ff000;
1875  else
1876  ratr_bitmap &= 0x000ff005;
1877  }
1878  } else {
1879  if (curtxbw_40mhz) {
1880  if (rssi_level == 1)
1881  ratr_bitmap &= 0x0f0f0000;
1882  else if (rssi_level == 2)
1883  ratr_bitmap &= 0x0f0ff000;
1884  else
1885  ratr_bitmap &= 0x0f0ff015;
1886  } else {
1887  if (rssi_level == 1)
1888  ratr_bitmap &= 0x0f0f0000;
1889  else if (rssi_level == 2)
1890  ratr_bitmap &= 0x0f0ff000;
1891  else
1892  ratr_bitmap &= 0x0f0ff005;
1893  }
1894  }
1895  }
1896 
1897  if ((curtxbw_40mhz && curshortgi_40mhz) ||
1898  (!curtxbw_40mhz && curshortgi_20mhz)) {
1899 
1900  if (macid == 0)
1901  shortgi = true;
1902  else if (macid == 1)
1903  shortgi = false;
1904  }
1905  break;
1906  default:
1907  ratr_index = RATR_INX_WIRELESS_NGB;
1908 
1909  if (rtlphy->rf_type == RF_1T2R)
1910  ratr_bitmap &= 0x000ff0ff;
1911  else
1912  ratr_bitmap &= 0x0f0ff0ff;
1913  break;
1914  }
1915  RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1916  "ratr_bitmap :%x\n", ratr_bitmap);
1917  *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) |
1918  (ratr_index << 28);
1919  rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80;
1920  RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG,
1921  "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n",
1922  ratr_index, ratr_bitmap,
1923  rate_mask[0], rate_mask[1], rate_mask[2], rate_mask[3],
1924  rate_mask[4]);
1925  rtl92c_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask);
1926 
1927  if (macid != 0)
1928  sta_entry->ratr_index = ratr_index;
1929 }
1930 
1932  struct ieee80211_sta *sta, u8 rssi_level)
1933 {
1934  struct rtl_priv *rtlpriv = rtl_priv(hw);
1935 
1936  if (rtlpriv->dm.useramask)
1937  rtl92ce_update_hal_rate_mask(hw, sta, rssi_level);
1938  else
1939  rtl92ce_update_hal_rate_table(hw, sta);
1940 }
1941 
1943 {
1944  struct rtl_priv *rtlpriv = rtl_priv(hw);
1945  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1946  u16 sifs_timer;
1947 
1948  rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME,
1949  &mac->slot_time);
1950  if (!mac->ht_enable)
1951  sifs_timer = 0x0a0a;
1952  else
1953  sifs_timer = 0x1010;
1954  rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer);
1955 }
1956 
1958 {
1959  struct rtl_priv *rtlpriv = rtl_priv(hw);
1960  struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1961  struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1962  enum rf_pwrstate e_rfpowerstate_toset;
1963  u8 u1tmp;
1964  bool actuallyset = false;
1965  unsigned long flag;
1966 
1967  if (rtlpci->being_init_adapter)
1968  return false;
1969 
1970  if (ppsc->swrf_processing)
1971  return false;
1972 
1973  spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
1974  if (ppsc->rfchange_inprogress) {
1975  spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
1976  return false;
1977  } else {
1978  ppsc->rfchange_inprogress = true;
1979  spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
1980  }
1981 
1982  rtl_write_byte(rtlpriv, REG_MAC_PINMUX_CFG, rtl_read_byte(rtlpriv,
1983  REG_MAC_PINMUX_CFG)&~(BIT(3)));
1984 
1985  u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL);
1986  e_rfpowerstate_toset = (u1tmp & BIT(3)) ? ERFON : ERFOFF;
1987 
1988  if ((ppsc->hwradiooff) && (e_rfpowerstate_toset == ERFON)) {
1989  RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1990  "GPIOChangeRF - HW Radio ON, RF ON\n");
1991 
1992  e_rfpowerstate_toset = ERFON;
1993  ppsc->hwradiooff = false;
1994  actuallyset = true;
1995  } else if (!ppsc->hwradiooff && (e_rfpowerstate_toset == ERFOFF)) {
1996  RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG,
1997  "GPIOChangeRF - HW Radio OFF, RF OFF\n");
1998 
1999  e_rfpowerstate_toset = ERFOFF;
2000  ppsc->hwradiooff = true;
2001  actuallyset = true;
2002  }
2003 
2004  if (actuallyset) {
2005  spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2006  ppsc->rfchange_inprogress = false;
2007  spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2008  } else {
2011 
2012  spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flag);
2013  ppsc->rfchange_inprogress = false;
2014  spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flag);
2015  }
2016 
2017  *valid = 1;
2018  return !ppsc->hwradiooff;
2019 
2020 }
2021 
2023  u8 *p_macaddr, bool is_group, u8 enc_algo,
2024  bool is_wepkey, bool clear_all)
2025 {
2026  struct rtl_priv *rtlpriv = rtl_priv(hw);
2027  struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
2028  struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw));
2029  u8 *macaddr = p_macaddr;
2030  u32 entry_id = 0;
2031  bool is_pairwise = false;
2032 
2033  static u8 cam_const_addr[4][6] = {
2034  {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
2035  {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
2036  {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
2037  {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}
2038  };
2039  static u8 cam_const_broad[] = {
2040  0xff, 0xff, 0xff, 0xff, 0xff, 0xff
2041  };
2042 
2043  if (clear_all) {
2044  u8 idx = 0;
2045  u8 cam_offset = 0;
2046  u8 clear_number = 5;
2047 
2048  RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n");
2049 
2050  for (idx = 0; idx < clear_number; idx++) {
2051  rtl_cam_mark_invalid(hw, cam_offset + idx);
2052  rtl_cam_empty_entry(hw, cam_offset + idx);
2053 
2054  if (idx < 5) {
2055  memset(rtlpriv->sec.key_buf[idx], 0,
2056  MAX_KEY_LEN);
2057  rtlpriv->sec.key_len[idx] = 0;
2058  }
2059  }
2060 
2061  } else {
2062  switch (enc_algo) {
2063  case WEP40_ENCRYPTION:
2064  enc_algo = CAM_WEP40;
2065  break;
2066  case WEP104_ENCRYPTION:
2067  enc_algo = CAM_WEP104;
2068  break;
2069  case TKIP_ENCRYPTION:
2070  enc_algo = CAM_TKIP;
2071  break;
2072  case AESCCMP_ENCRYPTION:
2073  enc_algo = CAM_AES;
2074  break;
2075  default:
2076  RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG,
2077  "switch case not processed\n");
2078  enc_algo = CAM_TKIP;
2079  break;
2080  }
2081 
2082  if (is_wepkey || rtlpriv->sec.use_defaultkey) {
2083  macaddr = cam_const_addr[key_index];
2084  entry_id = key_index;
2085  } else {
2086  if (is_group) {
2087  macaddr = cam_const_broad;
2088  entry_id = key_index;
2089  } else {
2090  if (mac->opmode == NL80211_IFTYPE_AP) {
2091  entry_id = rtl_cam_get_free_entry(hw,
2092  p_macaddr);
2093  if (entry_id >= TOTAL_CAM_ENTRY) {
2094  RT_TRACE(rtlpriv, COMP_SEC,
2095  DBG_EMERG,
2096  "Can not find free hw security cam entry\n");
2097  return;
2098  }
2099  } else {
2100  entry_id = CAM_PAIRWISE_KEY_POSITION;
2101  }
2102 
2103  key_index = PAIRWISE_KEYIDX;
2104  is_pairwise = true;
2105  }
2106  }
2107 
2108  if (rtlpriv->sec.key_len[key_index] == 0) {
2109  RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2110  "delete one entry, entry_id is %d\n",
2111  entry_id);
2112  if (mac->opmode == NL80211_IFTYPE_AP)
2113  rtl_cam_del_entry(hw, p_macaddr);
2114  rtl_cam_delete_one_entry(hw, p_macaddr, entry_id);
2115  } else {
2116  RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
2117  "The insert KEY length is %d\n",
2118  rtlpriv->sec.key_len[PAIRWISE_KEYIDX]);
2119  RT_TRACE(rtlpriv, COMP_SEC, DBG_LOUD,
2120  "The insert KEY is %x %x\n",
2121  rtlpriv->sec.key_buf[0][0],
2122  rtlpriv->sec.key_buf[0][1]);
2123 
2124  RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2125  "add one entry\n");
2126  if (is_pairwise) {
2127  RT_PRINT_DATA(rtlpriv, COMP_SEC, DBG_LOUD,
2128  "Pairwise Key content",
2129  rtlpriv->sec.pairwise_key,
2130  rtlpriv->sec.
2132 
2133  RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2134  "set Pairwise key\n");
2135 
2136  rtl_cam_add_one_entry(hw, macaddr, key_index,
2137  entry_id, enc_algo,
2139  rtlpriv->sec.
2140  key_buf[key_index]);
2141  } else {
2142  RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG,
2143  "set group key\n");
2144 
2145  if (mac->opmode == NL80211_IFTYPE_ADHOC) {
2147  rtlefuse->dev_addr,
2150  enc_algo,
2152  rtlpriv->sec.key_buf
2153  [entry_id]);
2154  }
2155 
2156  rtl_cam_add_one_entry(hw, macaddr, key_index,
2157  entry_id, enc_algo,
2159  rtlpriv->sec.key_buf[entry_id]);
2160  }
2161 
2162  }
2163  }
2164 }
2165 
2166 static void rtl8192ce_bt_var_init(struct ieee80211_hw *hw)
2167 {
2168  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2169 
2170  rtlpcipriv->bt_coexist.bt_coexistence =
2171  rtlpcipriv->bt_coexist.eeprom_bt_coexist;
2172  rtlpcipriv->bt_coexist.bt_ant_num =
2173  rtlpcipriv->bt_coexist.eeprom_bt_ant_num;
2174  rtlpcipriv->bt_coexist.bt_coexist_type =
2175  rtlpcipriv->bt_coexist.eeprom_bt_type;
2176 
2177  if (rtlpcipriv->bt_coexist.reg_bt_iso == 2)
2178  rtlpcipriv->bt_coexist.bt_ant_isolation =
2179  rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation;
2180  else
2181  rtlpcipriv->bt_coexist.bt_ant_isolation =
2182  rtlpcipriv->bt_coexist.reg_bt_iso;
2183 
2184  rtlpcipriv->bt_coexist.bt_radio_shared_type =
2185  rtlpcipriv->bt_coexist.eeprom_bt_radio_shared;
2186 
2187  if (rtlpcipriv->bt_coexist.bt_coexistence) {
2188 
2189  if (rtlpcipriv->bt_coexist.reg_bt_sco == 1)
2190  rtlpcipriv->bt_coexist.bt_service = BT_OTHER_ACTION;
2191  else if (rtlpcipriv->bt_coexist.reg_bt_sco == 2)
2192  rtlpcipriv->bt_coexist.bt_service = BT_SCO;
2193  else if (rtlpcipriv->bt_coexist.reg_bt_sco == 4)
2194  rtlpcipriv->bt_coexist.bt_service = BT_BUSY;
2195  else if (rtlpcipriv->bt_coexist.reg_bt_sco == 5)
2196  rtlpcipriv->bt_coexist.bt_service = BT_OTHERBUSY;
2197  else
2198  rtlpcipriv->bt_coexist.bt_service = BT_IDLE;
2199 
2200  rtlpcipriv->bt_coexist.bt_edca_ul = 0;
2201  rtlpcipriv->bt_coexist.bt_edca_dl = 0;
2202  rtlpcipriv->bt_coexist.bt_rssi_state = 0xff;
2203  }
2204 }
2205 
2207  bool auto_load_fail, u8 *hwinfo)
2208 {
2209  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2210  u8 value;
2211 
2212  if (!auto_load_fail) {
2213  rtlpcipriv->bt_coexist.eeprom_bt_coexist =
2214  ((hwinfo[RF_OPTION1] & 0xe0) >> 5);
2215  value = hwinfo[RF_OPTION4];
2216  rtlpcipriv->bt_coexist.eeprom_bt_type = ((value & 0xe) >> 1);
2217  rtlpcipriv->bt_coexist.eeprom_bt_ant_num = (value & 0x1);
2218  rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation =
2219  ((value & 0x10) >> 4);
2220  rtlpcipriv->bt_coexist.eeprom_bt_radio_shared =
2221  ((value & 0x20) >> 5);
2222  } else {
2223  rtlpcipriv->bt_coexist.eeprom_bt_coexist = 0;
2224  rtlpcipriv->bt_coexist.eeprom_bt_type = BT_2WIRE;
2225  rtlpcipriv->bt_coexist.eeprom_bt_ant_num = ANT_X2;
2226  rtlpcipriv->bt_coexist.eeprom_bt_ant_isolation = 0;
2227  rtlpcipriv->bt_coexist.eeprom_bt_radio_shared = BT_RADIO_SHARED;
2228  }
2229 
2230  rtl8192ce_bt_var_init(hw);
2231 }
2232 
2234 {
2235  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2236 
2237  /* 0:Low, 1:High, 2:From Efuse. */
2238  rtlpcipriv->bt_coexist.reg_bt_iso = 2;
2239  /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */
2240  rtlpcipriv->bt_coexist.reg_bt_sco = 3;
2241  /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
2242  rtlpcipriv->bt_coexist.reg_bt_sco = 0;
2243 }
2244 
2245 
2247 {
2248  struct rtl_priv *rtlpriv = rtl_priv(hw);
2249  struct rtl_phy *rtlphy = &(rtlpriv->phy);
2250  struct rtl_pci_priv *rtlpcipriv = rtl_pcipriv(hw);
2251 
2252  u8 u1_tmp;
2253 
2254  if (rtlpcipriv->bt_coexist.bt_coexistence &&
2255  ((rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC4) ||
2256  rtlpcipriv->bt_coexist.bt_coexist_type == BT_CSR_BC8)) {
2257 
2258  if (rtlpcipriv->bt_coexist.bt_ant_isolation)
2259  rtl_write_byte(rtlpriv, REG_GPIO_MUXCFG, 0xa0);
2260 
2261  u1_tmp = rtl_read_byte(rtlpriv, 0x4fd) &
2262  BIT_OFFSET_LEN_MASK_32(0, 1);
2263  u1_tmp = u1_tmp |
2264  ((rtlpcipriv->bt_coexist.bt_ant_isolation == 1) ?
2265  0 : BIT_OFFSET_LEN_MASK_32(1, 1)) |
2266  ((rtlpcipriv->bt_coexist.bt_service == BT_SCO) ?
2267  0 : BIT_OFFSET_LEN_MASK_32(2, 1));
2268  rtl_write_byte(rtlpriv, 0x4fd, u1_tmp);
2269 
2270  rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+4, 0xaaaa9aaa);
2271  rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+8, 0xffbd0040);
2272  rtl_write_dword(rtlpriv, REG_BT_COEX_TABLE+0xc, 0x40000010);
2273 
2274  /* Config to 1T1R. */
2275  if (rtlphy->rf_type == RF_1T1R) {
2276  u1_tmp = rtl_read_byte(rtlpriv, ROFDM0_TRXPATHENABLE);
2277  u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2278  rtl_write_byte(rtlpriv, ROFDM0_TRXPATHENABLE, u1_tmp);
2279 
2280  u1_tmp = rtl_read_byte(rtlpriv, ROFDM1_TRXPATHENABLE);
2281  u1_tmp &= ~(BIT_OFFSET_LEN_MASK_32(1, 1));
2282  rtl_write_byte(rtlpriv, ROFDM1_TRXPATHENABLE, u1_tmp);
2283  }
2284  }
2285 }
2286 
2288 {
2289 }
2290 
2292 {
2293 }