1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 * Based on the r8180 driver, which is:
5 * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
22 * Contact Information:
23 * wlanfae <wlanfae@realtek.com>
24 ******************************************************************************/
26 #include "r8192E_phy.h"
27 #include "r8192E_phyreg.h"
28 #include "r8190P_rtl8256.h"
29 #include "r8192E_cmdpkt.h"
33 extern int WDCAPARA_ADD
[];
35 void rtl8192e_start_beacon(struct net_device
*dev
)
37 struct r8192_priv
*priv
= (struct r8192_priv
*)rtllib_priv(dev
);
38 struct rtllib_network
*net
= &priv
->rtllib
->current_network
;
43 DMESG("Enabling beacon TX");
44 rtl8192_irq_disable(dev
);
46 write_nic_word(dev
, ATIMWND
, 2);
48 write_nic_word(dev
, BCN_INTERVAL
, net
->beacon_interval
);
49 write_nic_word(dev
, BCN_DRV_EARLY_INT
, 10);
50 write_nic_word(dev
, BCN_DMATIME
, 256);
52 write_nic_byte(dev
, BCN_ERR_THRESH
, 100);
54 BcnTimeCfg
|= BcnCW
<<BCN_TCFG_CW_SHIFT
;
55 BcnTimeCfg
|= BcnIFS
<<BCN_TCFG_IFS
;
56 write_nic_word(dev
, BCN_TCFG
, BcnTimeCfg
);
57 rtl8192_irq_enable(dev
);
60 static void rtl8192e_update_msr(struct net_device
*dev
)
62 struct r8192_priv
*priv
= rtllib_priv(dev
);
64 enum led_ctl_mode LedAction
= LED_CTL_NO_LINK
;
65 msr
= read_nic_byte(dev
, MSR
);
66 msr
&= ~MSR_LINK_MASK
;
68 switch (priv
->rtllib
->iw_mode
) {
70 if (priv
->rtllib
->state
== RTLLIB_LINKED
)
71 msr
|= (MSR_LINK_MANAGED
<< MSR_LINK_SHIFT
);
73 msr
|= (MSR_LINK_NONE
<< MSR_LINK_SHIFT
);
74 LedAction
= LED_CTL_LINK
;
77 if (priv
->rtllib
->state
== RTLLIB_LINKED
)
78 msr
|= (MSR_LINK_ADHOC
<< MSR_LINK_SHIFT
);
80 msr
|= (MSR_LINK_NONE
<< MSR_LINK_SHIFT
);
83 if (priv
->rtllib
->state
== RTLLIB_LINKED
)
84 msr
|= (MSR_LINK_MASTER
<< MSR_LINK_SHIFT
);
86 msr
|= (MSR_LINK_NONE
<< MSR_LINK_SHIFT
);
92 write_nic_byte(dev
, MSR
, msr
);
93 if (priv
->rtllib
->LedControlHandler
)
94 priv
->rtllib
->LedControlHandler(dev
, LedAction
);
97 void rtl8192e_SetHwReg(struct net_device
*dev
, u8 variable
, u8
*val
)
99 struct r8192_priv
*priv
= rtllib_priv(dev
);
103 write_nic_dword(dev
, BSSIDR
, ((u32
*)(val
))[0]);
104 write_nic_word(dev
, BSSIDR
+2, ((u16
*)(val
+2))[0]);
107 case HW_VAR_MEDIA_STATUS
:
109 enum rt_op_mode OpMode
= *((enum rt_op_mode
*)(val
));
110 enum led_ctl_mode LedAction
= LED_CTL_NO_LINK
;
111 u8 btMsr
= read_nic_byte(dev
, MSR
);
116 case RT_OP_MODE_INFRASTRUCTURE
:
118 LedAction
= LED_CTL_LINK
;
121 case RT_OP_MODE_IBSS
:
127 LedAction
= LED_CTL_LINK
;
135 write_nic_byte(dev
, MSR
, btMsr
);
140 case HW_VAR_CECHK_BSSID
:
144 Type
= ((u8
*)(val
))[0];
145 RegRCR
= read_nic_dword(dev
, RCR
);
146 priv
->ReceiveConfig
= RegRCR
;
149 RegRCR
|= (RCR_CBSSID
);
150 else if (Type
== false)
151 RegRCR
&= (~RCR_CBSSID
);
153 write_nic_dword(dev
, RCR
, RegRCR
);
154 priv
->ReceiveConfig
= RegRCR
;
159 case HW_VAR_SLOT_TIME
:
161 priv
->slot_time
= val
[0];
162 write_nic_byte(dev
, SLOT_TIME
, val
[0]);
166 case HW_VAR_ACK_PREAMBLE
:
169 priv
->short_preamble
= (bool)(*(u8
*)val
);
170 regTmp
= priv
->basic_rate
;
171 if (priv
->short_preamble
)
172 regTmp
|= BRSR_AckShortPmb
;
173 write_nic_dword(dev
, RRSR
, regTmp
);
178 write_nic_dword(dev
, CPU_GEN
, ((u32
*)(val
))[0]);
181 case HW_VAR_AC_PARAM
:
183 u8 pAcParam
= *((u8
*)val
);
187 u8 mode
= priv
->rtllib
->mode
;
188 struct rtllib_qos_parameters
*qos_parameters
=
189 &priv
->rtllib
->current_network
.qos_data
.parameters
;
191 u1bAIFS
= qos_parameters
->aifs
[pAcParam
] *
192 ((mode
&(IEEE_G
|IEEE_N_24G
)) ? 9 : 20) + aSifsTime
;
194 dm_init_edca_turbo(dev
);
196 u4bAcParam
= ((((u32
)(qos_parameters
->tx_op_limit
[pAcParam
])) <<
197 AC_PARAM_TXOP_LIMIT_OFFSET
) |
198 (((u32
)(qos_parameters
->cw_max
[pAcParam
])) <<
199 AC_PARAM_ECW_MAX_OFFSET
) |
200 (((u32
)(qos_parameters
->cw_min
[pAcParam
])) <<
201 AC_PARAM_ECW_MIN_OFFSET
) |
202 (((u32
)u1bAIFS
) << AC_PARAM_AIFS_OFFSET
));
204 RT_TRACE(COMP_DBG
, "%s():HW_VAR_AC_PARAM eACI:%x:%x\n",
205 __func__
, eACI
, u4bAcParam
);
208 write_nic_dword(dev
, EDCAPARA_BK
, u4bAcParam
);
212 write_nic_dword(dev
, EDCAPARA_BE
, u4bAcParam
);
216 write_nic_dword(dev
, EDCAPARA_VI
, u4bAcParam
);
220 write_nic_dword(dev
, EDCAPARA_VO
, u4bAcParam
);
224 printk(KERN_INFO
"SetHwReg8185(): invalid ACI: %d !\n",
228 priv
->rtllib
->SetHwRegHandler(dev
, HW_VAR_ACM_CTRL
,
233 case HW_VAR_ACM_CTRL
:
235 struct rtllib_qos_parameters
*qos_parameters
=
236 &priv
->rtllib
->current_network
.qos_data
.parameters
;
237 u8 pAcParam
= *((u8
*)val
);
239 union aci_aifsn
*pAciAifsn
= (union aci_aifsn
*) &
240 (qos_parameters
->aifs
[0]);
241 u8 acm
= pAciAifsn
->f
.acm
;
242 u8 AcmCtrl
= read_nic_byte(dev
, AcmHwCtrl
);
244 RT_TRACE(COMP_DBG
, "===========>%s():HW_VAR_ACM_CTRL:%x\n",
246 AcmCtrl
= AcmCtrl
| ((priv
->AcmMethod
== 2) ? 0x0 : 0x1);
251 AcmCtrl
|= AcmHw_BeqEn
;
255 AcmCtrl
|= AcmHw_ViqEn
;
259 AcmCtrl
|= AcmHw_VoqEn
;
263 RT_TRACE(COMP_QOS
, "SetHwReg8185(): [HW_VAR_"
264 "ACM_CTRL] acm set failed: eACI is "
271 AcmCtrl
&= (~AcmHw_BeqEn
);
275 AcmCtrl
&= (~AcmHw_ViqEn
);
279 AcmCtrl
&= (~AcmHw_BeqEn
);
287 RT_TRACE(COMP_QOS
, "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write"
289 write_nic_byte(dev
, AcmHwCtrl
, AcmCtrl
);
294 write_nic_byte(dev
, SIFS
, val
[0]);
295 write_nic_byte(dev
, SIFS
+1, val
[0]);
298 case HW_VAR_RF_TIMING
:
300 u8 Rf_Timing
= *((u8
*)val
);
301 write_nic_byte(dev
, rFPGA0_RFTiming1
, Rf_Timing
);
311 static void rtl8192_read_eeprom_info(struct net_device
*dev
)
313 struct r8192_priv
*priv
= rtllib_priv(dev
);
316 u8 ICVer8192
, ICVer8256
;
317 u16 i
, usValue
, IC_Version
;
319 u8 bMac_Tmp_Addr
[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x01};
320 RT_TRACE(COMP_INIT
, "====> rtl8192_read_eeprom_info\n");
322 EEPROMId
= eprom_read(dev
, 0);
323 if (EEPROMId
!= RTL8190_EEPROM_ID
) {
324 RT_TRACE(COMP_ERR
, "EEPROM ID is invalid:%x, %x\n",
325 EEPROMId
, RTL8190_EEPROM_ID
);
326 priv
->AutoloadFailFlag
= true;
328 priv
->AutoloadFailFlag
= false;
331 if (!priv
->AutoloadFailFlag
) {
332 priv
->eeprom_vid
= eprom_read(dev
, (EEPROM_VID
>> 1));
333 priv
->eeprom_did
= eprom_read(dev
, (EEPROM_DID
>> 1));
335 usValue
= eprom_read(dev
, (u16
)(EEPROM_Customer_ID
>>1)) >> 8;
336 priv
->eeprom_CustomerID
= (u8
)(usValue
& 0xff);
337 usValue
= eprom_read(dev
, (EEPROM_ICVersion_ChannelPlan
>>1));
338 priv
->eeprom_ChannelPlan
= usValue
&0xff;
339 IC_Version
= ((usValue
&0xff00)>>8);
341 ICVer8192
= (IC_Version
&0xf);
342 ICVer8256
= ((IC_Version
&0xf0)>>4);
343 RT_TRACE(COMP_INIT
, "\nICVer8192 = 0x%x\n", ICVer8192
);
344 RT_TRACE(COMP_INIT
, "\nICVer8256 = 0x%x\n", ICVer8256
);
345 if (ICVer8192
== 0x2) {
346 if (ICVer8256
== 0x5)
347 priv
->card_8192_version
= VERSION_8190_BE
;
349 switch (priv
->card_8192_version
) {
350 case VERSION_8190_BD
:
351 case VERSION_8190_BE
:
354 priv
->card_8192_version
= VERSION_8190_BD
;
357 RT_TRACE(COMP_INIT
, "\nIC Version = 0x%x\n",
358 priv
->card_8192_version
);
360 priv
->card_8192_version
= VERSION_8190_BD
;
361 priv
->eeprom_vid
= 0;
362 priv
->eeprom_did
= 0;
363 priv
->eeprom_CustomerID
= 0;
364 priv
->eeprom_ChannelPlan
= 0;
365 RT_TRACE(COMP_INIT
, "\nIC Version = 0x%x\n", 0xff);
368 RT_TRACE(COMP_INIT
, "EEPROM VID = 0x%4x\n", priv
->eeprom_vid
);
369 RT_TRACE(COMP_INIT
, "EEPROM DID = 0x%4x\n", priv
->eeprom_did
);
370 RT_TRACE(COMP_INIT
, "EEPROM Customer ID: 0x%2x\n",
371 priv
->eeprom_CustomerID
);
373 if (!priv
->AutoloadFailFlag
) {
374 for (i
= 0; i
< 6; i
+= 2) {
375 usValue
= eprom_read(dev
,
376 (u16
)((EEPROM_NODE_ADDRESS_BYTE_0
+ i
) >> 1));
377 *(u16
*)(&dev
->dev_addr
[i
]) = usValue
;
380 memcpy(dev
->dev_addr
, bMac_Tmp_Addr
, 6);
383 RT_TRACE(COMP_INIT
, "Permanent Address = %pM\n",
386 if (priv
->card_8192_version
> VERSION_8190_BD
)
387 priv
->bTXPowerDataReadFromEEPORM
= true;
389 priv
->bTXPowerDataReadFromEEPORM
= false;
391 priv
->rf_type
= RTL819X_DEFAULT_RF_TYPE
;
393 if (priv
->card_8192_version
> VERSION_8190_BD
) {
394 if (!priv
->AutoloadFailFlag
) {
395 tempval
= (eprom_read(dev
, (EEPROM_RFInd_PowerDiff
>>
397 priv
->EEPROMLegacyHTTxPowerDiff
= tempval
& 0xf;
400 priv
->rf_type
= RF_1T2R
;
402 priv
->rf_type
= RF_2T4R
;
404 priv
->EEPROMLegacyHTTxPowerDiff
= 0x04;
406 RT_TRACE(COMP_INIT
, "EEPROMLegacyHTTxPowerDiff = %d\n",
407 priv
->EEPROMLegacyHTTxPowerDiff
);
409 if (!priv
->AutoloadFailFlag
)
410 priv
->EEPROMThermalMeter
= (u8
)(((eprom_read(dev
,
411 (EEPROM_ThermalMeter
>>1))) &
414 priv
->EEPROMThermalMeter
= EEPROM_Default_ThermalMeter
;
415 RT_TRACE(COMP_INIT
, "ThermalMeter = %d\n",
416 priv
->EEPROMThermalMeter
);
417 priv
->TSSI_13dBm
= priv
->EEPROMThermalMeter
* 100;
419 if (priv
->epromtype
== EEPROM_93C46
) {
420 if (!priv
->AutoloadFailFlag
) {
421 usValue
= eprom_read(dev
,
422 (EEPROM_TxPwDiff_CrystalCap
>> 1));
423 priv
->EEPROMAntPwDiff
= (usValue
&0x0fff);
424 priv
->EEPROMCrystalCap
= (u8
)((usValue
& 0xf000)
427 priv
->EEPROMAntPwDiff
=
428 EEPROM_Default_AntTxPowerDiff
;
429 priv
->EEPROMCrystalCap
=
430 EEPROM_Default_TxPwDiff_CrystalCap
;
432 RT_TRACE(COMP_INIT
, "EEPROMAntPwDiff = %d\n",
433 priv
->EEPROMAntPwDiff
);
434 RT_TRACE(COMP_INIT
, "EEPROMCrystalCap = %d\n",
435 priv
->EEPROMCrystalCap
);
437 for (i
= 0; i
< 14; i
+= 2) {
438 if (!priv
->AutoloadFailFlag
)
439 usValue
= eprom_read(dev
,
440 (u16
)((EEPROM_TxPwIndex_CCK
+
443 usValue
= EEPROM_Default_TxPower
;
444 *((u16
*)(&priv
->EEPROMTxPowerLevelCCK
[i
])) =
446 RT_TRACE(COMP_INIT
, "CCK Tx Power Level, Index"
448 priv
->EEPROMTxPowerLevelCCK
[i
]);
449 RT_TRACE(COMP_INIT
, "CCK Tx Power Level, Index"
450 " %d = 0x%02x\n", i
+1,
451 priv
->EEPROMTxPowerLevelCCK
[i
+1]);
453 for (i
= 0; i
< 14; i
+= 2) {
454 if (!priv
->AutoloadFailFlag
)
455 usValue
= eprom_read(dev
,
456 (u16
)((EEPROM_TxPwIndex_OFDM_24G
459 usValue
= EEPROM_Default_TxPower
;
460 *((u16
*)(&priv
->EEPROMTxPowerLevelOFDM24G
[i
]))
462 RT_TRACE(COMP_INIT
, "OFDM 2.4G Tx Power Level,"
463 " Index %d = 0x%02x\n", i
,
464 priv
->EEPROMTxPowerLevelOFDM24G
[i
]);
465 RT_TRACE(COMP_INIT
, "OFDM 2.4G Tx Power Level,"
466 " Index %d = 0x%02x\n", i
+ 1,
467 priv
->EEPROMTxPowerLevelOFDM24G
[i
+1]);
470 if (priv
->epromtype
== EEPROM_93C46
) {
471 for (i
= 0; i
< 14; i
++) {
472 priv
->TxPowerLevelCCK
[i
] =
473 priv
->EEPROMTxPowerLevelCCK
[i
];
474 priv
->TxPowerLevelOFDM24G
[i
] =
475 priv
->EEPROMTxPowerLevelOFDM24G
[i
];
477 priv
->LegacyHTTxPowerDiff
=
478 priv
->EEPROMLegacyHTTxPowerDiff
;
479 priv
->AntennaTxPwDiff
[0] = (priv
->EEPROMAntPwDiff
&
481 priv
->AntennaTxPwDiff
[1] = ((priv
->EEPROMAntPwDiff
&
483 priv
->AntennaTxPwDiff
[2] = ((priv
->EEPROMAntPwDiff
&
485 priv
->CrystalCap
= priv
->EEPROMCrystalCap
;
486 priv
->ThermalMeter
[0] = (priv
->EEPROMThermalMeter
&
488 priv
->ThermalMeter
[1] = ((priv
->EEPROMThermalMeter
&
490 } else if (priv
->epromtype
== EEPROM_93C56
) {
492 for (i
= 0; i
< 3; i
++) {
493 priv
->TxPowerLevelCCK_A
[i
] =
494 priv
->EEPROMRfACCKChnl1TxPwLevel
[0];
495 priv
->TxPowerLevelOFDM24G_A
[i
] =
496 priv
->EEPROMRfAOfdmChnlTxPwLevel
[0];
497 priv
->TxPowerLevelCCK_C
[i
] =
498 priv
->EEPROMRfCCCKChnl1TxPwLevel
[0];
499 priv
->TxPowerLevelOFDM24G_C
[i
] =
500 priv
->EEPROMRfCOfdmChnlTxPwLevel
[0];
502 for (i
= 3; i
< 9; i
++) {
503 priv
->TxPowerLevelCCK_A
[i
] =
504 priv
->EEPROMRfACCKChnl1TxPwLevel
[1];
505 priv
->TxPowerLevelOFDM24G_A
[i
] =
506 priv
->EEPROMRfAOfdmChnlTxPwLevel
[1];
507 priv
->TxPowerLevelCCK_C
[i
] =
508 priv
->EEPROMRfCCCKChnl1TxPwLevel
[1];
509 priv
->TxPowerLevelOFDM24G_C
[i
] =
510 priv
->EEPROMRfCOfdmChnlTxPwLevel
[1];
512 for (i
= 9; i
< 14; i
++) {
513 priv
->TxPowerLevelCCK_A
[i
] =
514 priv
->EEPROMRfACCKChnl1TxPwLevel
[2];
515 priv
->TxPowerLevelOFDM24G_A
[i
] =
516 priv
->EEPROMRfAOfdmChnlTxPwLevel
[2];
517 priv
->TxPowerLevelCCK_C
[i
] =
518 priv
->EEPROMRfCCCKChnl1TxPwLevel
[2];
519 priv
->TxPowerLevelOFDM24G_C
[i
] =
520 priv
->EEPROMRfCOfdmChnlTxPwLevel
[2];
522 for (i
= 0; i
< 14; i
++)
523 RT_TRACE(COMP_INIT
, "priv->TxPowerLevelCCK_A"
525 priv
->TxPowerLevelCCK_A
[i
]);
526 for (i
= 0; i
< 14; i
++)
527 RT_TRACE(COMP_INIT
, "priv->TxPowerLevelOFDM"
528 "24G_A[%d] = 0x%x\n", i
,
529 priv
->TxPowerLevelOFDM24G_A
[i
]);
530 for (i
= 0; i
< 14; i
++)
531 RT_TRACE(COMP_INIT
, "priv->TxPowerLevelCCK_C"
533 priv
->TxPowerLevelCCK_C
[i
]);
534 for (i
= 0; i
< 14; i
++)
535 RT_TRACE(COMP_INIT
, "priv->TxPowerLevelOFDM"
536 "24G_C[%d] = 0x%x\n", i
,
537 priv
->TxPowerLevelOFDM24G_C
[i
]);
538 priv
->LegacyHTTxPowerDiff
=
539 priv
->EEPROMLegacyHTTxPowerDiff
;
540 priv
->AntennaTxPwDiff
[0] = 0;
541 priv
->AntennaTxPwDiff
[1] = 0;
542 priv
->AntennaTxPwDiff
[2] = 0;
543 priv
->CrystalCap
= priv
->EEPROMCrystalCap
;
544 priv
->ThermalMeter
[0] = (priv
->EEPROMThermalMeter
&
546 priv
->ThermalMeter
[1] = ((priv
->EEPROMThermalMeter
&
551 if (priv
->rf_type
== RF_1T2R
) {
552 /* no matter what checkpatch says, the braces are needed */
553 RT_TRACE(COMP_INIT
, "\n1T2R config\n");
554 } else if (priv
->rf_type
== RF_2T4R
) {
555 RT_TRACE(COMP_INIT
, "\n2T4R config\n");
558 init_rate_adaptive(dev
);
560 priv
->rf_chip
= RF_8256
;
562 if (priv
->RegChannelPlan
== 0xf)
563 priv
->ChannelPlan
= priv
->eeprom_ChannelPlan
;
565 priv
->ChannelPlan
= priv
->RegChannelPlan
;
567 if (priv
->eeprom_vid
== 0x1186 && priv
->eeprom_did
== 0x3304)
568 priv
->CustomerID
= RT_CID_DLINK
;
570 switch (priv
->eeprom_CustomerID
) {
571 case EEPROM_CID_DEFAULT
:
572 priv
->CustomerID
= RT_CID_DEFAULT
;
574 case EEPROM_CID_CAMEO
:
575 priv
->CustomerID
= RT_CID_819x_CAMEO
;
577 case EEPROM_CID_RUNTOP
:
578 priv
->CustomerID
= RT_CID_819x_RUNTOP
;
580 case EEPROM_CID_NetCore
:
581 priv
->CustomerID
= RT_CID_819x_Netcore
;
583 case EEPROM_CID_TOSHIBA
:
584 priv
->CustomerID
= RT_CID_TOSHIBA
;
585 if (priv
->eeprom_ChannelPlan
&0x80)
586 priv
->ChannelPlan
= priv
->eeprom_ChannelPlan
&0x7f;
588 priv
->ChannelPlan
= 0x0;
589 RT_TRACE(COMP_INIT
, "Toshiba ChannelPlan = 0x%x\n",
592 case EEPROM_CID_Nettronix
:
593 priv
->ScanDelay
= 100;
594 priv
->CustomerID
= RT_CID_Nettronix
;
596 case EEPROM_CID_Pronet
:
597 priv
->CustomerID
= RT_CID_PRONET
;
599 case EEPROM_CID_DLINK
:
600 priv
->CustomerID
= RT_CID_DLINK
;
603 case EEPROM_CID_WHQL
:
609 if (priv
->ChannelPlan
> CHANNEL_PLAN_LEN
- 1)
610 priv
->ChannelPlan
= 0;
611 priv
->ChannelPlan
= COUNTRY_CODE_WORLD_WIDE_13
;
613 if (priv
->eeprom_vid
== 0x1186 && priv
->eeprom_did
== 0x3304)
614 priv
->rtllib
->bSupportRemoteWakeUp
= true;
616 priv
->rtllib
->bSupportRemoteWakeUp
= false;
618 RT_TRACE(COMP_INIT
, "RegChannelPlan(%d)\n", priv
->RegChannelPlan
);
619 RT_TRACE(COMP_INIT
, "ChannelPlan = %d\n", priv
->ChannelPlan
);
620 RT_TRACE(COMP_TRACE
, "<==== ReadAdapterInfo\n");
623 void rtl8192_get_eeprom_size(struct net_device
*dev
)
626 struct r8192_priv
*priv
= rtllib_priv(dev
);
628 RT_TRACE(COMP_INIT
, "===========>%s()\n", __func__
);
629 curCR
= read_nic_dword(dev
, EPROM_CMD
);
630 RT_TRACE(COMP_INIT
, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD
,
632 priv
->epromtype
= (curCR
& EPROM_CMD_9356SEL
) ? EEPROM_93C56
:
634 RT_TRACE(COMP_INIT
, "<===========%s(), epromtype:%d\n", __func__
,
636 rtl8192_read_eeprom_info(dev
);
639 static void rtl8192_hwconfig(struct net_device
*dev
)
641 u32 regRATR
= 0, regRRSR
= 0;
642 u8 regBwOpMode
= 0, regTmp
= 0;
643 struct r8192_priv
*priv
= rtllib_priv(dev
);
645 switch (priv
->rtllib
->mode
) {
646 case WIRELESS_MODE_B
:
647 regBwOpMode
= BW_OPMODE_20MHZ
;
648 regRATR
= RATE_ALL_CCK
;
649 regRRSR
= RATE_ALL_CCK
;
651 case WIRELESS_MODE_A
:
652 regBwOpMode
= BW_OPMODE_5G
| BW_OPMODE_20MHZ
;
653 regRATR
= RATE_ALL_OFDM_AG
;
654 regRRSR
= RATE_ALL_OFDM_AG
;
656 case WIRELESS_MODE_G
:
657 regBwOpMode
= BW_OPMODE_20MHZ
;
658 regRATR
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
659 regRRSR
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
661 case WIRELESS_MODE_AUTO
:
662 case WIRELESS_MODE_N_24G
:
663 regBwOpMode
= BW_OPMODE_20MHZ
;
664 regRATR
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
|
665 RATE_ALL_OFDM_1SS
| RATE_ALL_OFDM_2SS
;
666 regRRSR
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
668 case WIRELESS_MODE_N_5G
:
669 regBwOpMode
= BW_OPMODE_5G
;
670 regRATR
= RATE_ALL_OFDM_AG
| RATE_ALL_OFDM_1SS
|
672 regRRSR
= RATE_ALL_OFDM_AG
;
675 regBwOpMode
= BW_OPMODE_20MHZ
;
676 regRATR
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
677 regRRSR
= RATE_ALL_CCK
| RATE_ALL_OFDM_AG
;
681 write_nic_byte(dev
, BW_OPMODE
, regBwOpMode
);
684 ratr_value
= regRATR
;
685 if (priv
->rf_type
== RF_1T2R
)
686 ratr_value
&= ~(RATE_ALL_OFDM_2SS
);
687 write_nic_dword(dev
, RATR0
, ratr_value
);
688 write_nic_byte(dev
, UFWP
, 1);
690 regTmp
= read_nic_byte(dev
, 0x313);
691 regRRSR
= ((regTmp
) << 24) | (regRRSR
& 0x00ffffff);
692 write_nic_dword(dev
, RRSR
, regRRSR
);
694 write_nic_word(dev
, RETRY_LIMIT
,
695 priv
->ShortRetryLimit
<< RETRY_LIMIT_SHORT_SHIFT
|
696 priv
->LongRetryLimit
<< RETRY_LIMIT_LONG_SHIFT
);
699 bool rtl8192_adapter_start(struct net_device
*dev
)
701 struct r8192_priv
*priv
= rtllib_priv(dev
);
703 bool rtStatus
= true;
705 u8 ICVersion
, SwitchingRegulatorOutput
;
706 bool bfirmwareok
= true;
707 u32 tmpRegA
, tmpRegC
, TempCCk
;
711 RT_TRACE(COMP_INIT
, "====>%s()\n", __func__
);
712 priv
->being_init_adapter
= true;
715 rtl8192_pci_resetdescring(dev
);
716 priv
->Rf_Mode
= RF_OP_By_SW_3wire
;
717 if (priv
->ResetProgress
== RESET_TYPE_NORESET
) {
718 write_nic_byte(dev
, ANAPAR
, 0x37);
721 priv
->pFirmware
->firmware_status
= FW_STATUS_0_INIT
;
723 if (priv
->RegRfOff
== true)
724 priv
->rtllib
->eRFPowerState
= eRfOff
;
726 ulRegRead
= read_nic_dword(dev
, CPU_GEN
);
727 if (priv
->pFirmware
->firmware_status
== FW_STATUS_0_INIT
)
728 ulRegRead
|= CPU_GEN_SYSTEM_RESET
;
729 else if (priv
->pFirmware
->firmware_status
== FW_STATUS_5_READY
)
730 ulRegRead
|= CPU_GEN_FIRMWARE_RESET
;
732 RT_TRACE(COMP_ERR
, "ERROR in %s(): undefined firmware state(%d)"
733 "\n", __func__
, priv
->pFirmware
->firmware_status
);
735 write_nic_dword(dev
, CPU_GEN
, ulRegRead
);
737 ICVersion
= read_nic_byte(dev
, IC_VERRSION
);
738 if (ICVersion
>= 0x4) {
739 SwitchingRegulatorOutput
= read_nic_byte(dev
, SWREGULATOR
);
740 if (SwitchingRegulatorOutput
!= 0xb8) {
741 write_nic_byte(dev
, SWREGULATOR
, 0xa8);
743 write_nic_byte(dev
, SWREGULATOR
, 0xb8);
746 RT_TRACE(COMP_INIT
, "BB Config Start!\n");
747 rtStatus
= rtl8192_BBConfig(dev
);
748 if (rtStatus
!= true) {
749 RT_TRACE(COMP_ERR
, "BB Config failed\n");
752 RT_TRACE(COMP_INIT
, "BB Config Finished!\n");
754 priv
->LoopbackMode
= RTL819X_NO_LOOPBACK
;
755 if (priv
->ResetProgress
== RESET_TYPE_NORESET
) {
756 ulRegRead
= read_nic_dword(dev
, CPU_GEN
);
757 if (priv
->LoopbackMode
== RTL819X_NO_LOOPBACK
)
758 ulRegRead
= ((ulRegRead
& CPU_GEN_NO_LOOPBACK_MSK
) |
759 CPU_GEN_NO_LOOPBACK_SET
);
760 else if (priv
->LoopbackMode
== RTL819X_MAC_LOOPBACK
)
761 ulRegRead
|= CPU_CCK_LOOPBACK
;
763 RT_TRACE(COMP_ERR
, "Serious error: wrong loopback"
766 write_nic_dword(dev
, CPU_GEN
, ulRegRead
);
770 rtl8192_hwconfig(dev
);
771 write_nic_byte(dev
, CMDR
, CR_RE
| CR_TE
);
773 write_nic_byte(dev
, PCIF
, ((MXDMA2_NoLimit
<<MXDMA2_RX_SHIFT
) |
774 (MXDMA2_NoLimit
<<MXDMA2_TX_SHIFT
)));
775 write_nic_dword(dev
, MAC0
, ((u32
*)dev
->dev_addr
)[0]);
776 write_nic_word(dev
, MAC4
, ((u16
*)(dev
->dev_addr
+ 4))[0]);
777 write_nic_dword(dev
, RCR
, priv
->ReceiveConfig
);
779 write_nic_dword(dev
, RQPN1
, NUM_OF_PAGE_IN_FW_QUEUE_BK
<<
780 RSVD_FW_QUEUE_PAGE_BK_SHIFT
|
781 NUM_OF_PAGE_IN_FW_QUEUE_BE
<<
782 RSVD_FW_QUEUE_PAGE_BE_SHIFT
|
783 NUM_OF_PAGE_IN_FW_QUEUE_VI
<<
784 RSVD_FW_QUEUE_PAGE_VI_SHIFT
|
785 NUM_OF_PAGE_IN_FW_QUEUE_VO
<<
786 RSVD_FW_QUEUE_PAGE_VO_SHIFT
);
787 write_nic_dword(dev
, RQPN2
, NUM_OF_PAGE_IN_FW_QUEUE_MGNT
<<
788 RSVD_FW_QUEUE_PAGE_MGNT_SHIFT
);
789 write_nic_dword(dev
, RQPN3
, APPLIED_RESERVED_QUEUE_IN_FW
|
790 NUM_OF_PAGE_IN_FW_QUEUE_BCN
<<
791 RSVD_FW_QUEUE_PAGE_BCN_SHIFT
|
792 NUM_OF_PAGE_IN_FW_QUEUE_PUB
<<
793 RSVD_FW_QUEUE_PAGE_PUB_SHIFT
);
795 rtl8192_tx_enable(dev
);
796 rtl8192_rx_enable(dev
);
797 ulRegRead
= (0xFFF00000 & read_nic_dword(dev
, RRSR
)) |
798 RATE_ALL_OFDM_AG
| RATE_ALL_CCK
;
799 write_nic_dword(dev
, RRSR
, ulRegRead
);
800 write_nic_dword(dev
, RATR0
+4*7, (RATE_ALL_OFDM_AG
| RATE_ALL_CCK
));
802 write_nic_byte(dev
, ACK_TIMEOUT
, 0x30);
804 if (priv
->ResetProgress
== RESET_TYPE_NORESET
)
805 rtl8192_SetWirelessMode(dev
, priv
->rtllib
->mode
);
806 CamResetAllEntry(dev
);
809 SECR_value
|= SCR_TxEncEnable
;
810 SECR_value
|= SCR_RxDecEnable
;
811 SECR_value
|= SCR_NoSKMC
;
812 write_nic_byte(dev
, SECR
, SECR_value
);
814 write_nic_word(dev
, ATIMWND
, 2);
815 write_nic_word(dev
, BCN_INTERVAL
, 100);
818 for (i
= 0; i
< QOS_QUEUE_NUM
; i
++)
819 write_nic_dword(dev
, WDCAPARA_ADD
[i
], 0x005e4332);
821 write_nic_byte(dev
, 0xbe, 0xc0);
823 rtl8192_phy_configmac(dev
);
825 if (priv
->card_8192_version
> (u8
) VERSION_8190_BD
) {
826 rtl8192_phy_getTxPower(dev
);
827 rtl8192_phy_setTxPower(dev
, priv
->chan
);
830 tmpvalue
= read_nic_byte(dev
, IC_VERRSION
);
831 priv
->IC_Cut
= tmpvalue
;
832 RT_TRACE(COMP_INIT
, "priv->IC_Cut= 0x%x\n", priv
->IC_Cut
);
833 if (priv
->IC_Cut
>= IC_VersionCut_D
) {
834 if (priv
->IC_Cut
== IC_VersionCut_D
) {
835 /* no matter what checkpatch says, braces are needed */
836 RT_TRACE(COMP_INIT
, "D-cut\n");
837 } else if (priv
->IC_Cut
== IC_VersionCut_E
) {
838 RT_TRACE(COMP_INIT
, "E-cut\n");
841 RT_TRACE(COMP_INIT
, "Before C-cut\n");
844 RT_TRACE(COMP_INIT
, "Load Firmware!\n");
845 bfirmwareok
= init_firmware(dev
);
847 if (retry_times
< 10) {
855 RT_TRACE(COMP_INIT
, "Load Firmware finished!\n");
856 if (priv
->ResetProgress
== RESET_TYPE_NORESET
) {
857 RT_TRACE(COMP_INIT
, "RF Config Started!\n");
858 rtStatus
= rtl8192_phy_RFConfig(dev
);
859 if (rtStatus
!= true) {
860 RT_TRACE(COMP_ERR
, "RF Config failed\n");
863 RT_TRACE(COMP_INIT
, "RF Config Finished!\n");
865 rtl8192_phy_updateInitGain(dev
);
867 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bCCKEn
, 0x1);
868 rtl8192_setBBreg(dev
, rFPGA0_RFMOD
, bOFDMEn
, 0x1);
870 write_nic_byte(dev
, 0x87, 0x0);
872 if (priv
->RegRfOff
== true) {
873 RT_TRACE((COMP_INIT
| COMP_RF
| COMP_POWER
),
874 "%s(): Turn off RF for RegRfOff ----------\n",
876 MgntActSet_RF_State(dev
, eRfOff
, RF_CHANGE_BY_SW
, true);
877 } else if (priv
->rtllib
->RfOffReason
> RF_CHANGE_BY_PS
) {
878 RT_TRACE((COMP_INIT
|COMP_RF
|COMP_POWER
), "%s(): Turn off RF for"
879 " RfOffReason(%d) ----------\n", __func__
,
880 priv
->rtllib
->RfOffReason
);
881 MgntActSet_RF_State(dev
, eRfOff
, priv
->rtllib
->RfOffReason
,
883 } else if (priv
->rtllib
->RfOffReason
>= RF_CHANGE_BY_IPS
) {
884 RT_TRACE((COMP_INIT
|COMP_RF
|COMP_POWER
), "%s(): Turn off RF for"
885 " RfOffReason(%d) ----------\n", __func__
,
886 priv
->rtllib
->RfOffReason
);
887 MgntActSet_RF_State(dev
, eRfOff
, priv
->rtllib
->RfOffReason
,
890 RT_TRACE((COMP_INIT
|COMP_RF
|COMP_POWER
), "%s(): RF-ON\n",
892 priv
->rtllib
->eRFPowerState
= eRfOn
;
893 priv
->rtllib
->RfOffReason
= 0;
896 if (priv
->rtllib
->FwRWRF
)
897 priv
->Rf_Mode
= RF_OP_By_FW
;
899 priv
->Rf_Mode
= RF_OP_By_SW_3wire
;
901 if (priv
->ResetProgress
== RESET_TYPE_NORESET
) {
902 dm_initialize_txpower_tracking(dev
);
904 if (priv
->IC_Cut
>= IC_VersionCut_D
) {
905 tmpRegA
= rtl8192_QueryBBReg(dev
,
906 rOFDM0_XATxIQImbalance
, bMaskDWord
);
907 tmpRegC
= rtl8192_QueryBBReg(dev
,
908 rOFDM0_XCTxIQImbalance
, bMaskDWord
);
909 for (i
= 0; i
< TxBBGainTableLength
; i
++) {
911 priv
->txbbgain_table
[i
].txbbgain_value
) {
912 priv
->rfa_txpowertrackingindex
= (u8
)i
;
913 priv
->rfa_txpowertrackingindex_real
=
915 priv
->rfa_txpowertracking_default
=
916 priv
->rfa_txpowertrackingindex
;
921 TempCCk
= rtl8192_QueryBBReg(dev
,
922 rCCK0_TxFilter1
, bMaskByte2
);
924 for (i
= 0; i
< CCKTxBBGainTableLength
; i
++) {
925 if (TempCCk
== priv
->cck_txbbgain_table
[i
].ccktxbb_valuearray
[0]) {
926 priv
->CCKPresentAttentuation_20Mdefault
= (u8
)i
;
930 priv
->CCKPresentAttentuation_40Mdefault
= 0;
931 priv
->CCKPresentAttentuation_difference
= 0;
932 priv
->CCKPresentAttentuation
=
933 priv
->CCKPresentAttentuation_20Mdefault
;
934 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfa_txpower"
935 "trackingindex_initial = %d\n",
936 priv
->rfa_txpowertrackingindex
);
937 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfa_txpower"
938 "trackingindex_real__initial = %d\n",
939 priv
->rfa_txpowertrackingindex_real
);
940 RT_TRACE(COMP_POWER_TRACKING
, "priv->CCKPresent"
941 "Attentuation_difference_initial = %d\n",
942 priv
->CCKPresentAttentuation_difference
);
943 RT_TRACE(COMP_POWER_TRACKING
, "priv->CCKPresent"
944 "Attentuation_initial = %d\n",
945 priv
->CCKPresentAttentuation
);
946 priv
->btxpower_tracking
= false;
949 rtl8192_irq_enable(dev
);
951 priv
->being_init_adapter
= false;
955 static void rtl8192_net_update(struct net_device
*dev
)
958 struct r8192_priv
*priv
= rtllib_priv(dev
);
959 struct rtllib_network
*net
;
960 u16 BcnTimeCfg
= 0, BcnCW
= 6, BcnIFS
= 0xf;
963 net
= &priv
->rtllib
->current_network
;
964 rtl8192_config_rate(dev
, &rate_config
);
965 priv
->dot11CurrentPreambleMode
= PREAMBLE_AUTO
;
966 priv
->basic_rate
= rate_config
&= 0x15f;
967 write_nic_dword(dev
, BSSIDR
, ((u32
*)net
->bssid
)[0]);
968 write_nic_word(dev
, BSSIDR
+4, ((u16
*)net
->bssid
)[2]);
970 if (priv
->rtllib
->iw_mode
== IW_MODE_ADHOC
) {
971 write_nic_word(dev
, ATIMWND
, 2);
972 write_nic_word(dev
, BCN_DMATIME
, 256);
973 write_nic_word(dev
, BCN_INTERVAL
, net
->beacon_interval
);
974 write_nic_word(dev
, BCN_DRV_EARLY_INT
, 10);
975 write_nic_byte(dev
, BCN_ERR_THRESH
, 100);
977 BcnTimeCfg
|= (BcnCW
<<BCN_TCFG_CW_SHIFT
);
978 BcnTimeCfg
|= BcnIFS
<<BCN_TCFG_IFS
;
980 write_nic_word(dev
, BCN_TCFG
, BcnTimeCfg
);
984 void rtl8192_link_change(struct net_device
*dev
)
986 struct r8192_priv
*priv
= rtllib_priv(dev
);
987 struct rtllib_device
*ieee
= priv
->rtllib
;
992 if (ieee
->state
== RTLLIB_LINKED
) {
993 rtl8192_net_update(dev
);
994 priv
->ops
->update_ratr_table(dev
);
995 if ((KEY_TYPE_WEP40
== ieee
->pairwise_key_type
) ||
996 (KEY_TYPE_WEP104
== ieee
->pairwise_key_type
))
997 EnableHWSecurityConfig8192(dev
);
999 write_nic_byte(dev
, 0x173, 0);
1001 rtl8192e_update_msr(dev
);
1003 if (ieee
->iw_mode
== IW_MODE_INFRA
|| ieee
->iw_mode
== IW_MODE_ADHOC
) {
1005 reg
= read_nic_dword(dev
, RCR
);
1006 if (priv
->rtllib
->state
== RTLLIB_LINKED
) {
1007 if (ieee
->IntelPromiscuousModeInfo
.bPromiscuousOn
)
1010 priv
->ReceiveConfig
= reg
|= RCR_CBSSID
;
1012 priv
->ReceiveConfig
= reg
&= ~RCR_CBSSID
;
1014 write_nic_dword(dev
, RCR
, reg
);
1018 void rtl8192_AllowAllDestAddr(struct net_device
*dev
,
1019 bool bAllowAllDA
, bool WriteIntoReg
)
1021 struct r8192_priv
*priv
= rtllib_priv(dev
);
1024 priv
->ReceiveConfig
|= RCR_AAP
;
1026 priv
->ReceiveConfig
&= ~RCR_AAP
;
1029 write_nic_dword(dev
, RCR
, priv
->ReceiveConfig
);
1032 static u8
MRateToHwRate8190Pci(u8 rate
)
1034 u8 ret
= DESC90_RATE1M
;
1038 ret
= DESC90_RATE1M
;
1041 ret
= DESC90_RATE2M
;
1044 ret
= DESC90_RATE5_5M
;
1047 ret
= DESC90_RATE11M
;
1050 ret
= DESC90_RATE6M
;
1053 ret
= DESC90_RATE9M
;
1056 ret
= DESC90_RATE12M
;
1059 ret
= DESC90_RATE18M
;
1062 ret
= DESC90_RATE24M
;
1065 ret
= DESC90_RATE36M
;
1068 ret
= DESC90_RATE48M
;
1071 ret
= DESC90_RATE54M
;
1074 ret
= DESC90_RATEMCS0
;
1077 ret
= DESC90_RATEMCS1
;
1080 ret
= DESC90_RATEMCS2
;
1083 ret
= DESC90_RATEMCS3
;
1086 ret
= DESC90_RATEMCS4
;
1089 ret
= DESC90_RATEMCS5
;
1092 ret
= DESC90_RATEMCS6
;
1095 ret
= DESC90_RATEMCS7
;
1098 ret
= DESC90_RATEMCS8
;
1101 ret
= DESC90_RATEMCS9
;
1104 ret
= DESC90_RATEMCS10
;
1107 ret
= DESC90_RATEMCS11
;
1110 ret
= DESC90_RATEMCS12
;
1113 ret
= DESC90_RATEMCS13
;
1116 ret
= DESC90_RATEMCS14
;
1119 ret
= DESC90_RATEMCS15
;
1122 ret
= DESC90_RATEMCS32
;
1130 static u8
rtl8192_MapHwQueueToFirmwareQueue(u8 QueueID
, u8 priority
)
1132 u8 QueueSelect
= 0x0;
1136 QueueSelect
= QSLT_BE
;
1140 QueueSelect
= QSLT_BK
;
1144 QueueSelect
= QSLT_VO
;
1148 QueueSelect
= QSLT_VI
;
1151 QueueSelect
= QSLT_MGNT
;
1154 QueueSelect
= QSLT_BEACON
;
1157 QueueSelect
= QSLT_CMD
;
1160 QueueSelect
= QSLT_HIGH
;
1163 RT_TRACE(COMP_ERR
, "TransmitTCB(): Impossible Queue Selection:"
1170 void rtl8192_tx_fill_desc(struct net_device
*dev
, struct tx_desc
*pdesc
,
1171 struct cb_desc
*cb_desc
, struct sk_buff
*skb
)
1173 struct r8192_priv
*priv
= rtllib_priv(dev
);
1174 dma_addr_t mapping
= pci_map_single(priv
->pdev
, skb
->data
, skb
->len
,
1176 struct tx_fwinfo_8190pci
*pTxFwInfo
= NULL
;
1177 pTxFwInfo
= (struct tx_fwinfo_8190pci
*)skb
->data
;
1178 memset(pTxFwInfo
, 0, sizeof(struct tx_fwinfo_8190pci
));
1179 pTxFwInfo
->TxHT
= (cb_desc
->data_rate
& 0x80) ? 1 : 0;
1180 pTxFwInfo
->TxRate
= MRateToHwRate8190Pci((u8
)cb_desc
->data_rate
);
1181 pTxFwInfo
->EnableCPUDur
= cb_desc
->bTxEnableFwCalcDur
;
1182 pTxFwInfo
->Short
= rtl8192_QueryIsShort(pTxFwInfo
->TxHT
,
1186 if (cb_desc
->bAMPDUEnable
) {
1187 pTxFwInfo
->AllowAggregation
= 1;
1188 pTxFwInfo
->RxMF
= cb_desc
->ampdu_factor
;
1189 pTxFwInfo
->RxAMD
= cb_desc
->ampdu_density
;
1191 pTxFwInfo
->AllowAggregation
= 0;
1192 pTxFwInfo
->RxMF
= 0;
1193 pTxFwInfo
->RxAMD
= 0;
1196 pTxFwInfo
->RtsEnable
= (cb_desc
->bRTSEnable
) ? 1 : 0;
1197 pTxFwInfo
->CtsEnable
= (cb_desc
->bCTSEnable
) ? 1 : 0;
1198 pTxFwInfo
->RtsSTBC
= (cb_desc
->bRTSSTBC
) ? 1 : 0;
1199 pTxFwInfo
->RtsHT
= (cb_desc
->rts_rate
&0x80) ? 1 : 0;
1200 pTxFwInfo
->RtsRate
= MRateToHwRate8190Pci((u8
)cb_desc
->rts_rate
);
1201 pTxFwInfo
->RtsBandwidth
= 0;
1202 pTxFwInfo
->RtsSubcarrier
= cb_desc
->RTSSC
;
1203 pTxFwInfo
->RtsShort
= (pTxFwInfo
->RtsHT
== 0) ?
1204 (cb_desc
->bRTSUseShortPreamble
? 1 : 0) :
1205 (cb_desc
->bRTSUseShortGI
? 1 : 0);
1206 if (priv
->CurrentChannelBW
== HT_CHANNEL_WIDTH_20_40
) {
1207 if (cb_desc
->bPacketBW
) {
1208 pTxFwInfo
->TxBandwidth
= 1;
1209 pTxFwInfo
->TxSubCarrier
= 0;
1211 pTxFwInfo
->TxBandwidth
= 0;
1212 pTxFwInfo
->TxSubCarrier
= priv
->nCur40MhzPrimeSC
;
1215 pTxFwInfo
->TxBandwidth
= 0;
1216 pTxFwInfo
->TxSubCarrier
= 0;
1219 memset((u8
*)pdesc
, 0, 12);
1222 pdesc
->Offset
= sizeof(struct tx_fwinfo_8190pci
) + 8;
1223 pdesc
->PktSize
= (u16
)skb
->len
-sizeof(struct tx_fwinfo_8190pci
);
1225 pdesc
->SecCAMID
= 0;
1226 pdesc
->RATid
= cb_desc
->RATRIndex
;
1230 pdesc
->SecType
= 0x0;
1231 if (cb_desc
->bHwSec
) {
1234 RT_TRACE(COMP_DBG
, "==>================hw sec\n");
1237 switch (priv
->rtllib
->pairwise_key_type
) {
1238 case KEY_TYPE_WEP40
:
1239 case KEY_TYPE_WEP104
:
1240 pdesc
->SecType
= 0x1;
1244 pdesc
->SecType
= 0x2;
1248 pdesc
->SecType
= 0x3;
1252 pdesc
->SecType
= 0x0;
1260 pdesc
->QueueSelect
= rtl8192_MapHwQueueToFirmwareQueue(
1261 cb_desc
->queue_index
,
1263 pdesc
->TxFWInfoSize
= sizeof(struct tx_fwinfo_8190pci
);
1265 pdesc
->DISFB
= cb_desc
->bTxDisableRateFallBack
;
1266 pdesc
->USERATE
= cb_desc
->bTxUseDriverAssingedRate
;
1268 pdesc
->FirstSeg
= 1;
1270 pdesc
->TxBufferSize
= skb
->len
;
1272 pdesc
->TxBuffAddr
= cpu_to_le32(mapping
);
1275 void rtl8192_tx_fill_cmd_desc(struct net_device
*dev
,
1276 struct tx_desc_cmd
*entry
,
1277 struct cb_desc
*cb_desc
, struct sk_buff
* skb
)
1279 struct r8192_priv
*priv
= rtllib_priv(dev
);
1280 dma_addr_t mapping
= pci_map_single(priv
->pdev
, skb
->data
, skb
->len
,
1283 memset(entry
, 0, 12);
1284 entry
->LINIP
= cb_desc
->bLastIniPkt
;
1285 entry
->FirstSeg
= 1;
1287 if (cb_desc
->bCmdOrInit
== DESC_PACKET_TYPE_INIT
) {
1288 entry
->CmdInit
= DESC_PACKET_TYPE_INIT
;
1290 struct tx_desc
* entry_tmp
= (struct tx_desc
*)entry
;
1291 entry_tmp
->CmdInit
= DESC_PACKET_TYPE_NORMAL
;
1292 entry_tmp
->Offset
= sizeof(struct tx_fwinfo_8190pci
) + 8;
1293 entry_tmp
->PktSize
= (u16
)(cb_desc
->pkt_size
+
1295 entry_tmp
->QueueSelect
= QSLT_CMD
;
1296 entry_tmp
->TxFWInfoSize
= 0x08;
1297 entry_tmp
->RATid
= (u8
)DESC_PACKET_TYPE_INIT
;
1299 entry
->TxBufferSize
= skb
->len
;
1300 entry
->TxBuffAddr
= cpu_to_le32(mapping
);
1304 static u8
HwRateToMRate90(bool bIsHT
, u8 rate
)
1316 case DESC90_RATE5_5M
:
1317 ret_rate
= MGN_5_5M
;
1319 case DESC90_RATE11M
:
1328 case DESC90_RATE12M
:
1331 case DESC90_RATE18M
:
1334 case DESC90_RATE24M
:
1337 case DESC90_RATE36M
:
1340 case DESC90_RATE48M
:
1343 case DESC90_RATE54M
:
1348 RT_TRACE(COMP_RECV
, "HwRateToMRate90(): Non supported"
1349 "Rate [%x], bIsHT = %d!!!\n", rate
, bIsHT
);
1355 case DESC90_RATEMCS0
:
1356 ret_rate
= MGN_MCS0
;
1358 case DESC90_RATEMCS1
:
1359 ret_rate
= MGN_MCS1
;
1361 case DESC90_RATEMCS2
:
1362 ret_rate
= MGN_MCS2
;
1364 case DESC90_RATEMCS3
:
1365 ret_rate
= MGN_MCS3
;
1367 case DESC90_RATEMCS4
:
1368 ret_rate
= MGN_MCS4
;
1370 case DESC90_RATEMCS5
:
1371 ret_rate
= MGN_MCS5
;
1373 case DESC90_RATEMCS6
:
1374 ret_rate
= MGN_MCS6
;
1376 case DESC90_RATEMCS7
:
1377 ret_rate
= MGN_MCS7
;
1379 case DESC90_RATEMCS8
:
1380 ret_rate
= MGN_MCS8
;
1382 case DESC90_RATEMCS9
:
1383 ret_rate
= MGN_MCS9
;
1385 case DESC90_RATEMCS10
:
1386 ret_rate
= MGN_MCS10
;
1388 case DESC90_RATEMCS11
:
1389 ret_rate
= MGN_MCS11
;
1391 case DESC90_RATEMCS12
:
1392 ret_rate
= MGN_MCS12
;
1394 case DESC90_RATEMCS13
:
1395 ret_rate
= MGN_MCS13
;
1397 case DESC90_RATEMCS14
:
1398 ret_rate
= MGN_MCS14
;
1400 case DESC90_RATEMCS15
:
1401 ret_rate
= MGN_MCS15
;
1403 case DESC90_RATEMCS32
:
1404 ret_rate
= (0x80|0x20);
1408 RT_TRACE(COMP_RECV
, "HwRateToMRate90(): Non supported "
1409 "Rate [%x], bIsHT = %d!!!\n", rate
, bIsHT
);
1417 static long rtl8192_signal_scale_mapping(struct r8192_priv
*priv
, long currsig
)
1421 if (currsig
>= 61 && currsig
<= 100)
1422 retsig
= 90 + ((currsig
- 60) / 4);
1423 else if (currsig
>= 41 && currsig
<= 60)
1424 retsig
= 78 + ((currsig
- 40) / 2);
1425 else if (currsig
>= 31 && currsig
<= 40)
1426 retsig
= 66 + (currsig
- 30);
1427 else if (currsig
>= 21 && currsig
<= 30)
1428 retsig
= 54 + (currsig
- 20);
1429 else if (currsig
>= 5 && currsig
<= 20)
1430 retsig
= 42 + (((currsig
- 5) * 2) / 3);
1431 else if (currsig
== 4)
1433 else if (currsig
== 3)
1435 else if (currsig
== 2)
1437 else if (currsig
== 1)
1446 #define rx_hal_is_cck_rate(_pdrvinfo)\
1447 ((_pdrvinfo->RxRate == DESC90_RATE1M ||\
1448 _pdrvinfo->RxRate == DESC90_RATE2M ||\
1449 _pdrvinfo->RxRate == DESC90_RATE5_5M ||\
1450 _pdrvinfo->RxRate == DESC90_RATE11M) &&\
1453 static void rtl8192_query_rxphystatus(
1454 struct r8192_priv
*priv
,
1455 struct rtllib_rx_stats
*pstats
,
1456 struct rx_desc
*pdesc
,
1457 struct rx_fwinfo
*pdrvinfo
,
1458 struct rtllib_rx_stats
*precord_stats
,
1459 bool bpacket_match_bssid
,
1460 bool bpacket_toself
,
1465 struct phy_sts_ofdm_819xpci
*pofdm_buf
;
1466 struct phy_sts_cck_819xpci
*pcck_buf
;
1467 struct phy_ofdm_rx_status_rxsc_sgien_exintfflag
*prxsc
;
1469 u8 i
, max_spatial_stream
, tmp_rxsnr
, tmp_rxevm
, rxsc_sgien_exflg
;
1470 char rx_pwr
[4], rx_pwr_all
= 0;
1471 char rx_snrX
, rx_evmX
;
1473 u32 RSSI
, total_rssi
= 0;
1476 static u8 check_reg824
;
1477 static u32 reg824_bit9
;
1479 priv
->stats
.numqry_phystatus
++;
1481 is_cck_rate
= rx_hal_is_cck_rate(pdrvinfo
);
1482 memset(precord_stats
, 0, sizeof(struct rtllib_rx_stats
));
1483 pstats
->bPacketMatchBSSID
= precord_stats
->bPacketMatchBSSID
=
1484 bpacket_match_bssid
;
1485 pstats
->bPacketToSelf
= precord_stats
->bPacketToSelf
= bpacket_toself
;
1486 pstats
->bIsCCK
= precord_stats
->bIsCCK
= is_cck_rate
;
1487 pstats
->bPacketBeacon
= precord_stats
->bPacketBeacon
= bPacketBeacon
;
1488 pstats
->bToSelfBA
= precord_stats
->bToSelfBA
= bToSelfBA
;
1489 if (check_reg824
== 0) {
1490 reg824_bit9
= rtl8192_QueryBBReg(priv
->rtllib
->dev
,
1491 rFPGA0_XA_HSSIParameter2
, 0x200);
1496 prxpkt
= (u8
*)pdrvinfo
;
1498 prxpkt
+= sizeof(struct rx_fwinfo
);
1500 pcck_buf
= (struct phy_sts_cck_819xpci
*)prxpkt
;
1501 pofdm_buf
= (struct phy_sts_ofdm_819xpci
*)prxpkt
;
1503 pstats
->RxMIMOSignalQuality
[0] = -1;
1504 pstats
->RxMIMOSignalQuality
[1] = -1;
1505 precord_stats
->RxMIMOSignalQuality
[0] = -1;
1506 precord_stats
->RxMIMOSignalQuality
[1] = -1;
1511 priv
->stats
.numqry_phystatusCCK
++;
1513 report
= pcck_buf
->cck_agc_rpt
& 0xc0;
1517 rx_pwr_all
= -35 - (pcck_buf
->cck_agc_rpt
&
1521 rx_pwr_all
= -23 - (pcck_buf
->cck_agc_rpt
&
1525 rx_pwr_all
= -11 - (pcck_buf
->cck_agc_rpt
&
1529 rx_pwr_all
= 8 - (pcck_buf
->cck_agc_rpt
& 0x3e);
1533 report
= pcck_buf
->cck_agc_rpt
& 0x60;
1538 ((pcck_buf
->cck_agc_rpt
&
1543 ((pcck_buf
->cck_agc_rpt
&
1548 ((pcck_buf
->cck_agc_rpt
&
1553 ((pcck_buf
->cck_agc_rpt
&
1559 pwdb_all
= rtl819x_query_rxpwrpercentage(rx_pwr_all
);
1560 pstats
->RxPWDBAll
= precord_stats
->RxPWDBAll
= pwdb_all
;
1561 pstats
->RecvSignalPower
= rx_pwr_all
;
1563 if (bpacket_match_bssid
) {
1566 if (pstats
->RxPWDBAll
> 40) {
1569 sq
= pcck_buf
->sq_rpt
;
1571 if (pcck_buf
->sq_rpt
> 64)
1573 else if (pcck_buf
->sq_rpt
< 20)
1576 sq
= ((64-sq
) * 100) / 44;
1578 pstats
->SignalQuality
= sq
;
1579 precord_stats
->SignalQuality
= sq
;
1580 pstats
->RxMIMOSignalQuality
[0] = sq
;
1581 precord_stats
->RxMIMOSignalQuality
[0] = sq
;
1582 pstats
->RxMIMOSignalQuality
[1] = -1;
1583 precord_stats
->RxMIMOSignalQuality
[1] = -1;
1586 priv
->stats
.numqry_phystatusHT
++;
1587 for (i
= RF90_PATH_A
; i
< RF90_PATH_MAX
; i
++) {
1588 if (priv
->brfpath_rxenable
[i
])
1591 rx_pwr
[i
] = ((pofdm_buf
->trsw_gain_X
[i
] & 0x3F) *
1594 tmp_rxsnr
= pofdm_buf
->rxsnr_X
[i
];
1595 rx_snrX
= (char)(tmp_rxsnr
);
1597 priv
->stats
.rxSNRdB
[i
] = (long)rx_snrX
;
1599 RSSI
= rtl819x_query_rxpwrpercentage(rx_pwr
[i
]);
1600 if (priv
->brfpath_rxenable
[i
])
1603 if (bpacket_match_bssid
) {
1604 pstats
->RxMIMOSignalStrength
[i
] = (u8
) RSSI
;
1605 precord_stats
->RxMIMOSignalStrength
[i
] =
1611 rx_pwr_all
= (((pofdm_buf
->pwdb_all
) >> 1) & 0x7f) - 106;
1612 pwdb_all
= rtl819x_query_rxpwrpercentage(rx_pwr_all
);
1614 pstats
->RxPWDBAll
= precord_stats
->RxPWDBAll
= pwdb_all
;
1615 pstats
->RxPower
= precord_stats
->RxPower
= rx_pwr_all
;
1616 pstats
->RecvSignalPower
= rx_pwr_all
;
1617 if (pdrvinfo
->RxHT
&& pdrvinfo
->RxRate
>= DESC90_RATEMCS8
&&
1618 pdrvinfo
->RxRate
<= DESC90_RATEMCS15
)
1619 max_spatial_stream
= 2;
1621 max_spatial_stream
= 1;
1623 for (i
= 0; i
< max_spatial_stream
; i
++) {
1624 tmp_rxevm
= pofdm_buf
->rxevm_X
[i
];
1625 rx_evmX
= (char)(tmp_rxevm
);
1629 evm
= rtl819x_evm_dbtopercentage(rx_evmX
);
1630 if (bpacket_match_bssid
) {
1632 pstats
->SignalQuality
= (u8
)(evm
&
1634 precord_stats
->SignalQuality
= (u8
)(evm
1637 pstats
->RxMIMOSignalQuality
[i
] = (u8
)(evm
&
1639 precord_stats
->RxMIMOSignalQuality
[i
] = (u8
)(evm
1645 rxsc_sgien_exflg
= pofdm_buf
->rxsc_sgien_exflg
;
1646 prxsc
= (struct phy_ofdm_rx_status_rxsc_sgien_exintfflag
*)
1649 priv
->stats
.received_bwtype
[1+prxsc
->rxsc
]++;
1651 priv
->stats
.received_bwtype
[0]++;
1655 pstats
->SignalStrength
= precord_stats
->SignalStrength
=
1656 (u8
)(rtl8192_signal_scale_mapping(priv
,
1661 pstats
->SignalStrength
= precord_stats
->SignalStrength
=
1662 (u8
)(rtl8192_signal_scale_mapping(priv
,
1663 (long)(total_rssi
/= rf_rx_num
)));
1667 static void rtl8192_process_phyinfo(struct r8192_priv
*priv
, u8
*buffer
,
1668 struct rtllib_rx_stats
*prev_st
,
1669 struct rtllib_rx_stats
*curr_st
)
1671 bool bcheck
= false;
1674 static u32 slide_rssi_index
, slide_rssi_statistics
;
1675 static u32 slide_evm_index
, slide_evm_statistics
;
1676 static u32 last_rssi
, last_evm
;
1677 static u32 slide_beacon_adc_pwdb_index
;
1678 static u32 slide_beacon_adc_pwdb_statistics
;
1679 static u32 last_beacon_adc_pwdb
;
1680 struct rtllib_hdr_3addr
*hdr
;
1682 unsigned int frag
, seq
;
1684 hdr
= (struct rtllib_hdr_3addr
*)buffer
;
1685 sc
= le16_to_cpu(hdr
->seq_ctl
);
1686 frag
= WLAN_GET_SEQ_FRAG(sc
);
1687 seq
= WLAN_GET_SEQ_SEQ(sc
);
1688 curr_st
->Seq_Num
= seq
;
1689 if (!prev_st
->bIsAMPDU
)
1692 if (slide_rssi_statistics
++ >= PHY_RSSI_SLID_WIN_MAX
) {
1693 slide_rssi_statistics
= PHY_RSSI_SLID_WIN_MAX
;
1694 last_rssi
= priv
->stats
.slide_signal_strength
[slide_rssi_index
];
1695 priv
->stats
.slide_rssi_total
-= last_rssi
;
1697 priv
->stats
.slide_rssi_total
+= prev_st
->SignalStrength
;
1699 priv
->stats
.slide_signal_strength
[slide_rssi_index
++] =
1700 prev_st
->SignalStrength
;
1701 if (slide_rssi_index
>= PHY_RSSI_SLID_WIN_MAX
)
1702 slide_rssi_index
= 0;
1704 tmp_val
= priv
->stats
.slide_rssi_total
/slide_rssi_statistics
;
1705 priv
->stats
.signal_strength
= rtl819x_translate_todbm(priv
,
1707 curr_st
->rssi
= priv
->stats
.signal_strength
;
1708 if (!prev_st
->bPacketMatchBSSID
) {
1709 if (!prev_st
->bToSelfBA
)
1716 rtl819x_process_cck_rxpathsel(priv
, prev_st
);
1718 priv
->stats
.num_process_phyinfo
++;
1719 if (!prev_st
->bIsCCK
&& prev_st
->bPacketToSelf
) {
1720 for (rfpath
= RF90_PATH_A
; rfpath
< RF90_PATH_C
; rfpath
++) {
1721 if (!rtl8192_phy_CheckIsLegalRFPath(priv
->rtllib
->dev
,
1724 RT_TRACE(COMP_DBG
, "Jacken -> pPreviousstats->RxMIMO"
1725 "SignalStrength[rfpath] = %d\n",
1726 prev_st
->RxMIMOSignalStrength
[rfpath
]);
1727 if (priv
->stats
.rx_rssi_percentage
[rfpath
] == 0) {
1728 priv
->stats
.rx_rssi_percentage
[rfpath
] =
1729 prev_st
->RxMIMOSignalStrength
[rfpath
];
1731 if (prev_st
->RxMIMOSignalStrength
[rfpath
] >
1732 priv
->stats
.rx_rssi_percentage
[rfpath
]) {
1733 priv
->stats
.rx_rssi_percentage
[rfpath
] =
1734 ((priv
->stats
.rx_rssi_percentage
[rfpath
]
1735 * (RX_SMOOTH
- 1)) +
1736 (prev_st
->RxMIMOSignalStrength
1737 [rfpath
])) / (RX_SMOOTH
);
1738 priv
->stats
.rx_rssi_percentage
[rfpath
] =
1739 priv
->stats
.rx_rssi_percentage
[rfpath
]
1742 priv
->stats
.rx_rssi_percentage
[rfpath
] =
1743 ((priv
->stats
.rx_rssi_percentage
[rfpath
] *
1745 (prev_st
->RxMIMOSignalStrength
[rfpath
])) /
1748 RT_TRACE(COMP_DBG
, "Jacken -> priv->RxStats.RxRSSI"
1749 "Percentage[rfPath] = %d\n",
1750 priv
->stats
.rx_rssi_percentage
[rfpath
]);
1755 if (prev_st
->bPacketBeacon
) {
1756 if (slide_beacon_adc_pwdb_statistics
++ >=
1757 PHY_Beacon_RSSI_SLID_WIN_MAX
) {
1758 slide_beacon_adc_pwdb_statistics
=
1759 PHY_Beacon_RSSI_SLID_WIN_MAX
;
1760 last_beacon_adc_pwdb
= priv
->stats
.Slide_Beacon_pwdb
1761 [slide_beacon_adc_pwdb_index
];
1762 priv
->stats
.Slide_Beacon_Total
-= last_beacon_adc_pwdb
;
1764 priv
->stats
.Slide_Beacon_Total
+= prev_st
->RxPWDBAll
;
1765 priv
->stats
.Slide_Beacon_pwdb
[slide_beacon_adc_pwdb_index
] =
1767 slide_beacon_adc_pwdb_index
++;
1768 if (slide_beacon_adc_pwdb_index
>= PHY_Beacon_RSSI_SLID_WIN_MAX
)
1769 slide_beacon_adc_pwdb_index
= 0;
1770 prev_st
->RxPWDBAll
= priv
->stats
.Slide_Beacon_Total
/
1771 slide_beacon_adc_pwdb_statistics
;
1772 if (prev_st
->RxPWDBAll
>= 3)
1773 prev_st
->RxPWDBAll
-= 3;
1776 RT_TRACE(COMP_RXDESC
, "Smooth %s PWDB = %d\n",
1777 prev_st
->bIsCCK
? "CCK" : "OFDM",
1778 prev_st
->RxPWDBAll
);
1780 if (prev_st
->bPacketToSelf
|| prev_st
->bPacketBeacon
||
1781 prev_st
->bToSelfBA
) {
1782 if (priv
->undecorated_smoothed_pwdb
< 0)
1783 priv
->undecorated_smoothed_pwdb
= prev_st
->RxPWDBAll
;
1784 if (prev_st
->RxPWDBAll
> (u32
)priv
->undecorated_smoothed_pwdb
) {
1785 priv
->undecorated_smoothed_pwdb
=
1786 (((priv
->undecorated_smoothed_pwdb
) *
1788 (prev_st
->RxPWDBAll
)) / (RX_SMOOTH
);
1789 priv
->undecorated_smoothed_pwdb
=
1790 priv
->undecorated_smoothed_pwdb
+ 1;
1792 priv
->undecorated_smoothed_pwdb
=
1793 (((priv
->undecorated_smoothed_pwdb
) *
1795 (prev_st
->RxPWDBAll
)) / (RX_SMOOTH
);
1797 rtl819x_update_rxsignalstatistics8190pci(priv
, prev_st
);
1800 if (prev_st
->SignalQuality
!= 0) {
1801 if (prev_st
->bPacketToSelf
|| prev_st
->bPacketBeacon
||
1802 prev_st
->bToSelfBA
) {
1803 if (slide_evm_statistics
++ >= PHY_RSSI_SLID_WIN_MAX
) {
1804 slide_evm_statistics
= PHY_RSSI_SLID_WIN_MAX
;
1806 priv
->stats
.slide_evm
[slide_evm_index
];
1807 priv
->stats
.slide_evm_total
-= last_evm
;
1810 priv
->stats
.slide_evm_total
+= prev_st
->SignalQuality
;
1812 priv
->stats
.slide_evm
[slide_evm_index
++] =
1813 prev_st
->SignalQuality
;
1814 if (slide_evm_index
>= PHY_RSSI_SLID_WIN_MAX
)
1815 slide_evm_index
= 0;
1817 tmp_val
= priv
->stats
.slide_evm_total
/
1818 slide_evm_statistics
;
1819 priv
->stats
.signal_quality
= tmp_val
;
1820 priv
->stats
.last_signal_strength_inpercent
= tmp_val
;
1823 if (prev_st
->bPacketToSelf
||
1824 prev_st
->bPacketBeacon
||
1825 prev_st
->bToSelfBA
) {
1826 for (ij
= 0; ij
< 2; ij
++) {
1827 if (prev_st
->RxMIMOSignalQuality
[ij
] != -1) {
1828 if (priv
->stats
.rx_evm_percentage
[ij
] == 0)
1829 priv
->stats
.rx_evm_percentage
[ij
] =
1830 prev_st
->RxMIMOSignalQuality
[ij
];
1831 priv
->stats
.rx_evm_percentage
[ij
] =
1832 ((priv
->stats
.rx_evm_percentage
[ij
] *
1834 (prev_st
->RxMIMOSignalQuality
[ij
])) /
1842 static void rtl8192_TranslateRxSignalStuff(struct net_device
*dev
,
1843 struct sk_buff
*skb
,
1844 struct rtllib_rx_stats
*pstats
,
1845 struct rx_desc
*pdesc
,
1846 struct rx_fwinfo
*pdrvinfo
)
1848 struct r8192_priv
*priv
= (struct r8192_priv
*)rtllib_priv(dev
);
1849 bool bpacket_match_bssid
, bpacket_toself
;
1850 bool bPacketBeacon
= false;
1851 struct rtllib_hdr_3addr
*hdr
;
1852 bool bToSelfBA
= false;
1853 static struct rtllib_rx_stats previous_stats
;
1858 tmp_buf
= skb
->data
+ pstats
->RxDrvInfoSize
+ pstats
->RxBufShift
;
1860 hdr
= (struct rtllib_hdr_3addr
*)tmp_buf
;
1861 fc
= le16_to_cpu(hdr
->frame_ctl
);
1862 type
= WLAN_FC_GET_TYPE(fc
);
1863 praddr
= hdr
->addr1
;
1865 bpacket_match_bssid
= ((RTLLIB_FTYPE_CTL
!= type
) &&
1866 (!compare_ether_addr(priv
->rtllib
->
1867 current_network
.bssid
,
1868 (fc
& RTLLIB_FCTL_TODS
) ? hdr
->addr1
:
1869 (fc
& RTLLIB_FCTL_FROMDS
) ? hdr
->addr2
: hdr
->addr3
))
1870 && (!pstats
->bHwError
) && (!pstats
->bCRC
) && (!pstats
->bICV
));
1871 bpacket_toself
= bpacket_match_bssid
&& /* check this */
1872 (!compare_ether_addr(praddr
,
1873 priv
->rtllib
->dev
->dev_addr
));
1874 if (WLAN_FC_GET_FRAMETYPE(fc
) == RTLLIB_STYPE_BEACON
)
1875 bPacketBeacon
= true;
1876 if (bpacket_match_bssid
)
1877 priv
->stats
.numpacket_matchbssid
++;
1879 priv
->stats
.numpacket_toself
++;
1880 rtl8192_process_phyinfo(priv
, tmp_buf
, &previous_stats
, pstats
);
1881 rtl8192_query_rxphystatus(priv
, pstats
, pdesc
, pdrvinfo
,
1882 &previous_stats
, bpacket_match_bssid
,
1883 bpacket_toself
, bPacketBeacon
, bToSelfBA
);
1884 rtl8192_record_rxdesc_forlateruse(pstats
, &previous_stats
);
1887 static void rtl8192_UpdateReceivedRateHistogramStatistics(
1888 struct net_device
*dev
,
1889 struct rtllib_rx_stats
*pstats
)
1891 struct r8192_priv
*priv
= (struct r8192_priv
*)rtllib_priv(dev
);
1894 u32 preamble_guardinterval
;
1898 else if (pstats
->bICV
)
1901 if (pstats
->bShortPreamble
)
1902 preamble_guardinterval
= 1;
1904 preamble_guardinterval
= 0;
1906 switch (pstats
->rate
) {
1995 priv
->stats
.received_preamble_GI
[preamble_guardinterval
][rateIndex
]++;
1996 priv
->stats
.received_rate_histogram
[0][rateIndex
]++;
1997 priv
->stats
.received_rate_histogram
[rcvType
][rateIndex
]++;
2000 bool rtl8192_rx_query_status_desc(struct net_device
*dev
,
2001 struct rtllib_rx_stats
*stats
,
2002 struct rx_desc
*pdesc
,
2003 struct sk_buff
*skb
)
2005 struct r8192_priv
*priv
= rtllib_priv(dev
);
2007 stats
->bICV
= pdesc
->ICV
;
2008 stats
->bCRC
= pdesc
->CRC32
;
2009 stats
->bHwError
= pdesc
->CRC32
| pdesc
->ICV
;
2011 stats
->Length
= pdesc
->Length
;
2012 if (stats
->Length
< 24)
2013 stats
->bHwError
|= 1;
2015 if (stats
->bHwError
) {
2016 stats
->bShift
= false;
2019 if (pdesc
->Length
< 500)
2020 priv
->stats
.rxcrcerrmin
++;
2021 else if (pdesc
->Length
> 1000)
2022 priv
->stats
.rxcrcerrmax
++;
2024 priv
->stats
.rxcrcerrmid
++;
2028 struct rx_fwinfo
*pDrvInfo
= NULL
;
2029 stats
->RxDrvInfoSize
= pdesc
->RxDrvInfoSize
;
2030 stats
->RxBufShift
= ((pdesc
->Shift
)&0x03);
2031 stats
->Decrypted
= !pdesc
->SWDec
;
2033 pDrvInfo
= (struct rx_fwinfo
*)(skb
->data
+ stats
->RxBufShift
);
2035 stats
->rate
= HwRateToMRate90((bool)pDrvInfo
->RxHT
,
2036 (u8
)pDrvInfo
->RxRate
);
2037 stats
->bShortPreamble
= pDrvInfo
->SPLCP
;
2039 rtl8192_UpdateReceivedRateHistogramStatistics(dev
, stats
);
2041 stats
->bIsAMPDU
= (pDrvInfo
->PartAggr
== 1);
2042 stats
->bFirstMPDU
= (pDrvInfo
->PartAggr
== 1) &&
2043 (pDrvInfo
->FirstAGGR
== 1);
2045 stats
->TimeStampLow
= pDrvInfo
->TSFL
;
2046 stats
->TimeStampHigh
= read_nic_dword(dev
, TSFR
+4);
2048 rtl819x_UpdateRxPktTimeStamp(dev
, stats
);
2050 if ((stats
->RxBufShift
+ stats
->RxDrvInfoSize
) > 0)
2053 stats
->RxIs40MHzPacket
= pDrvInfo
->BW
;
2055 rtl8192_TranslateRxSignalStuff(dev
, skb
, stats
, pdesc
,
2058 if (pDrvInfo
->FirstAGGR
== 1 || pDrvInfo
->PartAggr
== 1)
2059 RT_TRACE(COMP_RXDESC
, "pDrvInfo->FirstAGGR = %d,"
2060 " pDrvInfo->PartAggr = %d\n",
2061 pDrvInfo
->FirstAGGR
, pDrvInfo
->PartAggr
);
2062 skb_trim(skb
, skb
->len
- 4/*sCrcLng*/);
2065 stats
->packetlength
= stats
->Length
-4;
2066 stats
->fraglength
= stats
->packetlength
;
2067 stats
->fragoffset
= 0;
2068 stats
->ntotalfrag
= 1;
2073 void rtl8192_halt_adapter(struct net_device
*dev
, bool reset
)
2075 struct r8192_priv
*priv
= rtllib_priv(dev
);
2081 OpMode
= RT_OP_MODE_NO_LINK
;
2082 priv
->rtllib
->SetHwRegHandler(dev
, HW_VAR_MEDIA_STATUS
, &OpMode
);
2084 if (!priv
->rtllib
->bSupportRemoteWakeUp
) {
2086 write_nic_byte(dev
, CMDR
, u1bTmp
);
2094 priv
->bHwRfOffAction
= 2;
2096 if (!priv
->rtllib
->bSupportRemoteWakeUp
) {
2097 PHY_SetRtl8192eRfOff(dev
);
2098 ulRegRead
= read_nic_dword(dev
, CPU_GEN
);
2099 ulRegRead
|= CPU_GEN_SYSTEM_RESET
;
2100 write_nic_dword(dev
, CPU_GEN
, ulRegRead
);
2102 write_nic_dword(dev
, WFCRC0
, 0xffffffff);
2103 write_nic_dword(dev
, WFCRC1
, 0xffffffff);
2104 write_nic_dword(dev
, WFCRC2
, 0xffffffff);
2107 write_nic_byte(dev
, PMR
, 0x5);
2108 write_nic_byte(dev
, MacBlkCtrl
, 0xa);
2112 for (i
= 0; i
< MAX_QUEUE_SIZE
; i
++)
2113 skb_queue_purge(&priv
->rtllib
->skb_waitQ
[i
]);
2114 for (i
= 0; i
< MAX_QUEUE_SIZE
; i
++)
2115 skb_queue_purge(&priv
->rtllib
->skb_aggQ
[i
]);
2117 skb_queue_purge(&priv
->skb_queue
);
2121 void rtl8192_update_ratr_table(struct net_device
*dev
)
2123 struct r8192_priv
*priv
= rtllib_priv(dev
);
2124 struct rtllib_device
*ieee
= priv
->rtllib
;
2125 u8
*pMcsRate
= ieee
->dot11HTOperationalRateSet
;
2129 rtl8192_config_rate(dev
, (u16
*)(&ratr_value
));
2130 ratr_value
|= (*(u16
*)(pMcsRate
)) << 12;
2131 switch (ieee
->mode
) {
2133 ratr_value
&= 0x00000FF0;
2136 ratr_value
&= 0x0000000F;
2140 ratr_value
&= 0x00000FF7;
2144 if (ieee
->pHTInfo
->PeerMimoPs
== 0) {
2145 ratr_value
&= 0x0007F007;
2147 if (priv
->rf_type
== RF_1T2R
)
2148 ratr_value
&= 0x000FF007;
2150 ratr_value
&= 0x0F81F007;
2156 ratr_value
&= 0x0FFFFFFF;
2157 if (ieee
->pHTInfo
->bCurTxBW40MHz
&&
2158 ieee
->pHTInfo
->bCurShortGI40MHz
)
2159 ratr_value
|= 0x80000000;
2160 else if (!ieee
->pHTInfo
->bCurTxBW40MHz
&&
2161 ieee
->pHTInfo
->bCurShortGI20MHz
)
2162 ratr_value
|= 0x80000000;
2163 write_nic_dword(dev
, RATR0
+rate_index
*4, ratr_value
);
2164 write_nic_byte(dev
, UFWP
, 1);
2168 rtl8192_InitializeVariables(struct net_device
*dev
)
2170 struct r8192_priv
*priv
= rtllib_priv(dev
);
2172 strcpy(priv
->nick
, "rtl8192E");
2174 priv
->rtllib
->softmac_features
= IEEE_SOFTMAC_SCAN
|
2175 IEEE_SOFTMAC_ASSOCIATE
| IEEE_SOFTMAC_PROBERQ
|
2176 IEEE_SOFTMAC_PROBERS
| IEEE_SOFTMAC_TX_QUEUE
/* |
2177 IEEE_SOFTMAC_BEACONS*/;
2179 priv
->rtllib
->tx_headroom
= sizeof(struct tx_fwinfo_8190pci
);
2181 priv
->ShortRetryLimit
= 0x30;
2182 priv
->LongRetryLimit
= 0x30;
2184 priv
->EarlyRxThreshold
= 7;
2185 priv
->pwrGroupCnt
= 0;
2187 priv
->bIgnoreSilentReset
= false;
2188 priv
->enable_gpio0
= 0;
2190 priv
->TransmitConfig
= 0;
2192 priv
->ReceiveConfig
= RCR_ADD3
|
2195 RCR_AB
| RCR_AM
| RCR_APM
|
2196 RCR_AAP
| ((u32
)7<<RCR_MXDMA_OFFSET
) |
2197 ((u32
)7 << RCR_FIFO_OFFSET
) | RCR_ONLYERLPKT
;
2199 priv
->irq_mask
[0] = (u32
)(IMR_ROK
| IMR_VODOK
| IMR_VIDOK
|
2200 IMR_BEDOK
| IMR_BKDOK
| IMR_HCCADOK
|
2201 IMR_MGNTDOK
| IMR_COMDOK
| IMR_HIGHDOK
|
2202 IMR_BDOK
| IMR_RXCMDOK
| IMR_TIMEOUT0
|
2203 IMR_RDU
| IMR_RXFOVW
| IMR_TXFOVW
|
2204 IMR_BcnInt
| IMR_TBDOK
| IMR_TBDER
);
2207 priv
->MidHighPwrTHR_L1
= 0x3B;
2208 priv
->MidHighPwrTHR_L2
= 0x40;
2209 priv
->PwrDomainProtect
= false;
2211 priv
->bfirst_after_down
= 0;
2214 void rtl8192_EnableInterrupt(struct net_device
*dev
)
2216 struct r8192_priv
*priv
= (struct r8192_priv
*)rtllib_priv(dev
);
2217 priv
->irq_enabled
= 1;
2219 write_nic_dword(dev
, INTA_MASK
, priv
->irq_mask
[0]);
2223 void rtl8192_DisableInterrupt(struct net_device
*dev
)
2225 struct r8192_priv
*priv
= (struct r8192_priv
*)rtllib_priv(dev
);
2227 write_nic_dword(dev
, INTA_MASK
, 0);
2229 priv
->irq_enabled
= 0;
2232 void rtl8192_ClearInterrupt(struct net_device
*dev
)
2235 tmp
= read_nic_dword(dev
, ISR
);
2236 write_nic_dword(dev
, ISR
, tmp
);
2240 void rtl8192_enable_rx(struct net_device
*dev
)
2242 struct r8192_priv
*priv
= (struct r8192_priv
*)rtllib_priv(dev
);
2243 write_nic_dword(dev
, RDQDA
, priv
->rx_ring_dma
[RX_MPDU_QUEUE
]);
2246 static const u32 TX_DESC_BASE
[] = {
2247 BKQDA
, BEQDA
, VIQDA
, VOQDA
, HCCAQDA
, CQDA
, MQDA
, HQDA
, BQDA
2250 void rtl8192_enable_tx(struct net_device
*dev
)
2252 struct r8192_priv
*priv
= (struct r8192_priv
*)rtllib_priv(dev
);
2255 for (i
= 0; i
< MAX_TX_QUEUE_COUNT
; i
++)
2256 write_nic_dword(dev
, TX_DESC_BASE
[i
], priv
->tx_ring
[i
].dma
);
2260 void rtl8192_interrupt_recognized(struct net_device
*dev
, u32
*p_inta
,
2263 *p_inta
= read_nic_dword(dev
, ISR
);
2264 write_nic_dword(dev
, ISR
, *p_inta
);
2267 bool rtl8192_HalRxCheckStuck(struct net_device
*dev
)
2269 struct r8192_priv
*priv
= rtllib_priv(dev
);
2270 u16 RegRxCounter
= read_nic_word(dev
, 0x130);
2271 bool bStuck
= false;
2272 static u8 rx_chk_cnt
;
2273 u32 SlotIndex
= 0, TotalRxStuckCount
= 0;
2275 u8 SilentResetRxSoltNum
= 4;
2277 RT_TRACE(COMP_RESET
, "%s(): RegRxCounter is %d, RxCounter is %d\n",
2278 __func__
, RegRxCounter
, priv
->RxCounter
);
2281 if (priv
->undecorated_smoothed_pwdb
>= (RateAdaptiveTH_High
+5)) {
2283 } else if ((priv
->undecorated_smoothed_pwdb
< (RateAdaptiveTH_High
+ 5))
2284 && (((priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
) &&
2285 (priv
->undecorated_smoothed_pwdb
>= RateAdaptiveTH_Low_40M
))
2286 || ((priv
->CurrentChannelBW
== HT_CHANNEL_WIDTH_20
) &&
2287 (priv
->undecorated_smoothed_pwdb
>= RateAdaptiveTH_Low_20M
)))) {
2292 } else if ((((priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
) &&
2293 (priv
->undecorated_smoothed_pwdb
< RateAdaptiveTH_Low_40M
)) ||
2294 ((priv
->CurrentChannelBW
== HT_CHANNEL_WIDTH_20
) &&
2295 (priv
->undecorated_smoothed_pwdb
< RateAdaptiveTH_Low_20M
))) &&
2296 priv
->undecorated_smoothed_pwdb
>= VeryLowRSSI
) {
2309 SlotIndex
= (priv
->SilentResetRxSlotIndex
++)%SilentResetRxSoltNum
;
2311 if (priv
->RxCounter
== RegRxCounter
) {
2312 priv
->SilentResetRxStuckEvent
[SlotIndex
] = 1;
2314 for (i
= 0; i
< SilentResetRxSoltNum
; i
++)
2315 TotalRxStuckCount
+= priv
->SilentResetRxStuckEvent
[i
];
2317 if (TotalRxStuckCount
== SilentResetRxSoltNum
) {
2319 for (i
= 0; i
< SilentResetRxSoltNum
; i
++)
2320 TotalRxStuckCount
+=
2321 priv
->SilentResetRxStuckEvent
[i
];
2326 priv
->SilentResetRxStuckEvent
[SlotIndex
] = 0;
2329 priv
->RxCounter
= RegRxCounter
;
2334 bool rtl8192_HalTxCheckStuck(struct net_device
*dev
)
2336 struct r8192_priv
*priv
= rtllib_priv(dev
);
2337 bool bStuck
= false;
2338 u16 RegTxCounter
= read_nic_word(dev
, 0x128);
2340 RT_TRACE(COMP_RESET
, "%s():RegTxCounter is %d,TxCounter is %d\n",
2341 __func__
, RegTxCounter
, priv
->TxCounter
);
2343 if (priv
->TxCounter
== RegTxCounter
)
2346 priv
->TxCounter
= RegTxCounter
;
2351 bool rtl8192_GetNmodeSupportBySecCfg(struct net_device
*dev
)
2353 struct r8192_priv
*priv
= rtllib_priv(dev
);
2354 struct rtllib_device
*ieee
= priv
->rtllib
;
2355 if (ieee
->rtllib_ap_sec_type
&&
2356 (ieee
->rtllib_ap_sec_type(priv
->rtllib
)&(SEC_ALG_WEP
|
2364 bool rtl8192_GetHalfNmodeSupportByAPs(struct net_device
*dev
)
2367 struct r8192_priv
*priv
= rtllib_priv(dev
);
2368 struct rtllib_device
*ieee
= priv
->rtllib
;
2370 if (ieee
->bHalfWirelessN24GMode
== true)
2378 u8
rtl8192_QueryIsShort(u8 TxHT
, u8 TxRate
, struct cb_desc
*tcb_desc
)
2382 tmp_Short
= (TxHT
== 1) ? ((tcb_desc
->bUseShortGI
) ? 1 : 0) :
2383 ((tcb_desc
->bUseShortPreamble
) ? 1 : 0);
2384 if (TxHT
== 1 && TxRate
!= DESC90_RATEMCS15
)
2390 void ActUpdateChannelAccessSetting(struct net_device
*dev
,
2391 enum wireless_mode WirelessMode
,
2392 struct channel_access_setting
*ChnlAccessSetting
)