2 This is part of the rtl8192 driver
3 released under the GPL (See file COPYING for details).
5 This files contains programming code for the rtl8256
8 *Many* thanks to Realtek Corp. for their great support!
13 #include "r8192E_hw.h"
14 #include "r819xE_phyreg.h"
15 #include "r819xE_phy.h"
16 #include "r8190_rtl8256.h"
18 /*--------------------------------------------------------------------------
19 * Overview: set RF band width (20M or 40M)
20 * Input: struct net_device* dev
21 * WIRELESS_BANDWIDTH_E Bandwidth //20M or 40M
24 * Note: 8226 support both 20M and 40 MHz
25 *---------------------------------------------------------------------------*/
26 void PHY_SetRF8256Bandwidth(struct net_device
* dev
, HT_CHANNEL_WIDTH Bandwidth
) //20M or 40M
29 struct r8192_priv
*priv
= ieee80211_priv(dev
);
31 //for(eRFPath = RF90_PATH_A; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
32 for(eRFPath
= 0; eRFPath
<priv
->NumTotalRFPath
; eRFPath
++)
34 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
39 case HT_CHANNEL_WIDTH_20
:
40 if(priv
->card_8192_version
== VERSION_8190_BD
|| priv
->card_8192_version
== VERSION_8190_BE
)// 8256 D-cut, E-cut, xiong: consider it later!
42 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x0b, bMask12Bits
, 0x100); //phy para:1ba
43 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x2c, bMask12Bits
, 0x3d7);
44 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x0e, bMask12Bits
, 0x021);
46 //cosa add for sd3's request 01/23/2008
47 //rtl8192_phy_SetRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, 0x14, bMask12Bits, 0x5ab);
51 RT_TRACE(COMP_ERR
, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
55 case HT_CHANNEL_WIDTH_20_40
:
56 if(priv
->card_8192_version
== VERSION_8190_BD
||priv
->card_8192_version
== VERSION_8190_BE
)// 8256 D-cut, E-cut, xiong: consider it later!
58 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x0b, bMask12Bits
, 0x300); //phy para:3ba
59 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x2c, bMask12Bits
, 0x3ff);
60 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x0e, bMask12Bits
, 0x0e1);
62 //cosa add for sd3's request 01/23/2008
64 if(priv
->chan
== 3 || priv
->chan
== 9) //I need to set priv->chan whenever current channel changes
65 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x14, bMask12Bits
, 0x59b);
67 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, 0x14, bMask12Bits
, 0x5ab);
72 RT_TRACE(COMP_ERR
, "PHY_SetRF8256Bandwidth(): unknown hardware version\n");
78 RT_TRACE(COMP_ERR
, "PHY_SetRF8256Bandwidth(): unknown Bandwidth: %#X\n",Bandwidth
);
85 /*--------------------------------------------------------------------------
86 * Overview: Interface to config 8256
87 * Input: struct net_device* dev
90 *---------------------------------------------------------------------------*/
91 RT_STATUS
PHY_RF8256_Config(struct net_device
* dev
)
93 struct r8192_priv
*priv
= ieee80211_priv(dev
);
94 // Initialize general global value
96 RT_STATUS rtStatus
= RT_STATUS_SUCCESS
;
97 // TODO: Extend RF_PATH_C and RF_PATH_D in the future
98 priv
->NumTotalRFPath
= RTL819X_TOTAL_RF_PATH
;
100 rtStatus
= phy_RF8256_Config_ParaFile(dev
);
104 /*--------------------------------------------------------------------------
105 * Overview: Interface to config 8256
106 * Input: struct net_device* dev
109 *---------------------------------------------------------------------------*/
110 RT_STATUS
phy_RF8256_Config_ParaFile(struct net_device
* dev
)
114 RT_STATUS rtStatus
= RT_STATUS_SUCCESS
;
115 BB_REGISTER_DEFINITION_T
*pPhyReg
;
116 struct r8192_priv
*priv
= ieee80211_priv(dev
);
117 u32 RegOffSetToBeCheck
= 0x3;
118 u32 RegValueToBeCheck
= 0x7f1;
119 u32 RF3_Final_Value
= 0;
120 u8 ConstRetryTimes
= 5, RetryTimes
= 5;
122 //3//-----------------------------------------------------------------
123 //3// <2> Initialize RF
124 //3//-----------------------------------------------------------------
125 for(eRFPath
= (RF90_RADIO_PATH_E
)RF90_PATH_A
; eRFPath
<priv
->NumTotalRFPath
; eRFPath
++)
127 if (!rtl8192_phy_CheckIsLegalRFPath(dev
, eRFPath
))
130 pPhyReg
= &priv
->PHYRegDef
[eRFPath
];
132 // Joseph test for shorten RF config
133 // pHalData->RfReg0Value[eRFPath] = rtl8192_phy_QueryRFReg(dev, (RF90_RADIO_PATH_E)eRFPath, rGlobalCtrl, bMaskDWord);
135 /*----Store original RFENV control type----*/
140 u4RegValue
= rtl8192_QueryBBReg(dev
, pPhyReg
->rfintfs
, bRFSI_RFENV
);
144 u4RegValue
= rtl8192_QueryBBReg(dev
, pPhyReg
->rfintfs
, bRFSI_RFENV
<<16);
148 /*----Set RF_ENV enable----*/
149 rtl8192_setBBreg(dev
, pPhyReg
->rfintfe
, bRFSI_RFENV
<<16, 0x1);
151 /*----Set RF_ENV output high----*/
152 rtl8192_setBBreg(dev
, pPhyReg
->rfintfo
, bRFSI_RFENV
, 0x1);
154 /* Set bit number of Address and Data for RF register */
155 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, b3WireAddressLength
, 0x0); // Set 0 to 4 bits for Z-serial and set 1 to 6 bits for 8258
156 rtl8192_setBBreg(dev
, pPhyReg
->rfHSSIPara2
, b3WireDataLength
, 0x0); // Set 0 to 12 bits for Z-serial and 8258, and set 1 to 14 bits for ???
158 rtl8192_phy_SetRFReg(dev
, (RF90_RADIO_PATH_E
) eRFPath
, 0x0, bMask12Bits
, 0xbf);
160 /*----Check RF block (for FPGA platform only)----*/
161 // TODO: this function should be removed on ASIC , Emily 2007.2.2
162 rtStatus
= rtl8192_phy_checkBBAndRF(dev
, HW90_BLOCK_RF
, (RF90_RADIO_PATH_E
)eRFPath
);
163 if(rtStatus
!= RT_STATUS_SUCCESS
)
165 RT_TRACE(COMP_ERR
, "PHY_RF8256_Config():Check Radio[%d] Fail!!\n", eRFPath
);
166 goto phy_RF8256_Config_ParaFile_Fail
;
169 RetryTimes
= ConstRetryTimes
;
171 /*----Initialize RF fom connfiguration file----*/
175 while(RF3_Final_Value
!=RegValueToBeCheck
&& RetryTimes
!=0)
177 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,(RF90_RADIO_PATH_E
)eRFPath
);
178 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, RegOffSetToBeCheck
, bMask12Bits
);
179 RT_TRACE(COMP_RF
, "RF %d %d register final value: %x\n", eRFPath
, RegOffSetToBeCheck
, RF3_Final_Value
);
184 while(RF3_Final_Value
!=RegValueToBeCheck
&& RetryTimes
!=0)
186 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,(RF90_RADIO_PATH_E
)eRFPath
);
187 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, RegOffSetToBeCheck
, bMask12Bits
);
188 RT_TRACE(COMP_RF
, "RF %d %d register final value: %x\n", eRFPath
, RegOffSetToBeCheck
, RF3_Final_Value
);
193 while(RF3_Final_Value
!=RegValueToBeCheck
&& RetryTimes
!=0)
195 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,(RF90_RADIO_PATH_E
)eRFPath
);
196 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, RegOffSetToBeCheck
, bMask12Bits
);
197 RT_TRACE(COMP_RF
, "RF %d %d register final value: %x\n", eRFPath
, RegOffSetToBeCheck
, RF3_Final_Value
);
202 while(RF3_Final_Value
!=RegValueToBeCheck
&& RetryTimes
!=0)
204 ret
= rtl8192_phy_ConfigRFWithHeaderFile(dev
,(RF90_RADIO_PATH_E
)eRFPath
);
205 RF3_Final_Value
= rtl8192_phy_QueryRFReg(dev
, (RF90_RADIO_PATH_E
)eRFPath
, RegOffSetToBeCheck
, bMask12Bits
);
206 RT_TRACE(COMP_RF
, "RF %d %d register final value: %x\n", eRFPath
, RegOffSetToBeCheck
, RF3_Final_Value
);
212 /*----Restore RFENV control type----*/;
217 rtl8192_setBBreg(dev
, pPhyReg
->rfintfs
, bRFSI_RFENV
, u4RegValue
);
221 rtl8192_setBBreg(dev
, pPhyReg
->rfintfs
, bRFSI_RFENV
<<16, u4RegValue
);
226 RT_TRACE(COMP_ERR
, "phy_RF8256_Config_ParaFile():Radio[%d] Fail!!", eRFPath
);
227 goto phy_RF8256_Config_ParaFile_Fail
;
232 RT_TRACE(COMP_PHY
, "PHY Initialization Success\n") ;
233 return RT_STATUS_SUCCESS
;
235 phy_RF8256_Config_ParaFile_Fail
:
236 RT_TRACE(COMP_ERR
, "PHY Initialization failed\n") ;
237 return RT_STATUS_FAILURE
;
241 void PHY_SetRF8256CCKTxPower(struct net_device
* dev
, u8 powerlevel
)
244 struct r8192_priv
*priv
= ieee80211_priv(dev
);
248 TxAGC
|= ((powerlevel
<<8)|powerlevel
);
249 TxAGC
+= priv
->CCKTxPowerLevelOriginalOffset
;
251 if(priv
->bDynamicTxLowPower
== true //cosa 04282008 for cck long range
252 /*pMgntInfo->bScanInProgress == TRUE*/ ) //cosa 05/22/2008 for scan
254 if(priv
->CustomerID
== RT_CID_819x_Netcore
)
257 TxAGC
+= ((priv
->CckPwEnl
<<8)|priv
->CckPwEnl
);
260 byte0
= (u8
)(TxAGC
& 0xff);
261 byte1
= (u8
)((TxAGC
& 0xff00)>>8);
266 if(priv
->rf_type
== RF_2T4R
) //Only 2T4R you have to care the Antenna Tx Power offset
267 { // check antenna C over the max index 0x24
268 if(priv
->RF_C_TxPwDiff
> 0)
270 if( (byte0
+ (u8
)priv
->RF_C_TxPwDiff
) > 0x24)
271 byte0
= 0x24 - priv
->RF_C_TxPwDiff
;
272 if( (byte1
+ (u8
)priv
->RF_C_TxPwDiff
) > 0x24)
273 byte1
= 0x24 - priv
->RF_C_TxPwDiff
;
276 TxAGC
= (byte1
<<8) |byte0
;
277 write_nic_dword(dev
, CCK_TXAGC
, TxAGC
);
282 if(priv
->bDynamicTxLowPower
== true)//cosa 04282008 for cck long range
284 if(priv
->CustomerID
== RT_CID_819x_Netcore
)
287 TxAGC
+= priv
->CckPwEnl
;
291 rtl8192_setBBreg(dev
, rTxAGC_CCK_Mcs32
, bTxAGCRateCCK
, TxAGC
);
297 void PHY_SetRF8256OFDMTxPower(struct net_device
* dev
, u8 powerlevel
)
299 struct r8192_priv
*priv
= ieee80211_priv(dev
);
300 //Joseph TxPower for 8192 testing
302 u32 TxAGC1
=0, TxAGC2
=0, TxAGC2_tmp
= 0;
303 u8 i
, byteVal1
[4], byteVal2
[4], byteVal3
[4];
305 if(priv
->bDynamicTxHighPower
== true) //Add by Jacken 2008/03/06
307 TxAGC1
|= ((powerlevel
<<24)|(powerlevel
<<16)|(powerlevel
<<8)|powerlevel
);
311 TxAGC1
+= priv
->MCSTxPowerLevelOriginalOffset
[0];
315 TxAGC2_tmp
+= priv
->MCSTxPowerLevelOriginalOffset
[1];
319 TxAGC1
|= ((powerlevel
<<24)|(powerlevel
<<16)|(powerlevel
<<8)|powerlevel
);
322 TxAGC1
+= priv
->MCSTxPowerLevelOriginalOffset
[0];
323 TxAGC2
+= priv
->MCSTxPowerLevelOriginalOffset
[1];
330 byteVal1
[i
] = (u8
)( (TxAGC1
& (0xff<<(i
*8))) >>(i
*8) );
331 if(byteVal1
[i
] > 0x24)
333 byteVal2
[i
] = (u8
)( (TxAGC2
& (0xff<<(i
*8))) >>(i
*8) );
334 if(byteVal2
[i
] > 0x24)
338 byteVal3
[i
] = (u8
)( (TxAGC2_tmp
& (0xff<<(i
*8))) >>(i
*8) );
339 if(byteVal3
[i
] > 0x24)
343 if(priv
->rf_type
== RF_2T4R
) //Only 2T4R you have to care the Antenna Tx Power offset
344 { // check antenna C over the max index 0x24
345 if(priv
->RF_C_TxPwDiff
> 0)
349 if( (byteVal1
[i
] + (u8
)priv
->RF_C_TxPwDiff
) > 0x24)
350 byteVal1
[i
] = 0x24 - priv
->RF_C_TxPwDiff
;
351 if( (byteVal2
[i
] + (u8
)priv
->RF_C_TxPwDiff
) > 0x24)
352 byteVal2
[i
] = 0x24 - priv
->RF_C_TxPwDiff
;
353 if( (byteVal3
[i
] + (u8
)priv
->RF_C_TxPwDiff
) > 0x24)
354 byteVal3
[i
] = 0x24 - priv
->RF_C_TxPwDiff
;
359 TxAGC1
= (byteVal1
[3]<<24) | (byteVal1
[2]<<16) |(byteVal1
[1]<<8) |byteVal1
[0];
360 TxAGC2
= (byteVal2
[3]<<24) | (byteVal2
[2]<<16) |(byteVal2
[1]<<8) |byteVal2
[0];
363 TxAGC2_tmp
= (byteVal3
[3]<<24) | (byteVal3
[2]<<16) |(byteVal3
[1]<<8) |byteVal3
[0];
364 priv
->Pwr_Track
= TxAGC2_tmp
;
365 //DbgPrint("TxAGC2_tmp = 0x%x\n", TxAGC2_tmp);
367 //DbgPrint("TxAGC1/TxAGC2 = 0x%x/0x%x\n", TxAGC1, TxAGC2);
368 write_nic_dword(dev
, MCS_TXAGC
, TxAGC1
);
369 write_nic_dword(dev
, MCS_TXAGC
+4, TxAGC2
);
372 u32 writeVal
, powerBase0
, powerBase1
, writeVal_tmp
;
374 u16 RegOffset
[6] = {0xe00, 0xe04, 0xe10, 0xe14, 0xe18, 0xe1c};
375 u8 byte0
, byte1
, byte2
, byte3
;
377 powerBase0
= powerlevel
+ priv
->LegacyHTTxPowerDiff
; //OFDM rates
378 powerBase0
= (powerBase0
<<24) | (powerBase0
<<16) |(powerBase0
<<8) |powerBase0
;
379 powerBase1
= powerlevel
; //MCS rates
380 powerBase1
= (powerBase1
<<24) | (powerBase1
<<16) |(powerBase1
<<8) |powerBase1
;
382 for(index
=0; index
<6; index
++)
384 writeVal
= priv
->MCSTxPowerLevelOriginalOffset
[index
] + ((index
<2)?powerBase0
:powerBase1
);
385 byte0
= (u8
)(writeVal
& 0x7f);
386 byte1
= (u8
)((writeVal
& 0x7f00)>>8);
387 byte2
= (u8
)((writeVal
& 0x7f0000)>>16);
388 byte3
= (u8
)((writeVal
& 0x7f000000)>>24);
389 if(byte0
> 0x24) // Max power index = 0x24
400 writeVal_tmp
= (byte3
<<24) | (byte2
<<16) |(byte1
<<8) |byte0
;
401 priv
->Pwr_Track
= writeVal_tmp
;
404 if(priv
->bDynamicTxHighPower
== true) //Add by Jacken 2008/03/06 //when DM implement, add this
406 writeVal
= 0x03030303;
410 writeVal
= (byte3
<<24) | (byte2
<<16) |(byte1
<<8) |byte0
;
412 rtl8192_setBBreg(dev
, RegOffset
[index
], 0x7f7f7f7f, writeVal
);
420 #define MAX_DOZE_WAITING_TIMES_9x 64
423 struct net_device
* dev
,
424 RT_RF_POWER_STATE eRFPowerState
427 struct r8192_priv
*priv
= ieee80211_priv(dev
);
428 PRT_POWER_SAVE_CONTROL pPSC
= (PRT_POWER_SAVE_CONTROL
)(&(priv
->ieee80211
->PowerSaveControl
));
431 u8 i
= 0, QueueID
= 0;
432 ptx_ring head
=NULL
,tail
=NULL
;
434 if(priv
->SetRFPowerStateInProgress
== true)
436 RT_TRACE(COMP_POWER
, "===========> SetRFPowerState8190()!\n");
437 priv
->SetRFPowerStateInProgress
= true;
439 switch(priv
->rf_chip
)
442 switch( eRFPowerState
)
445 RT_TRACE(COMP_POWER
, "SetRFPowerState8190() eRfOn !\n");
446 //RXTX enable control: On
447 //for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
448 // PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x2);
450 if(priv
->rf_type
== RF_2T4R
)
453 rtl8192_setBBreg(dev
, rFPGA0_XA_RFInterfaceOE
, BIT4
, 0x1); // 0x860[4]
455 rtl8192_setBBreg(dev
, rFPGA0_XC_RFInterfaceOE
, BIT4
, 0x1); // 0x868[4]
456 //analog to digital on
457 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xf00, 0xf);// 0x88c[11:8]
458 //digital to analog on
459 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x1e0, 0xf); // 0x880[8:5]
461 rtl8192_setBBreg(dev
, rOFDM0_TRxPathEnable
, 0xf, 0xf);// 0xc04[3:0]
463 rtl8192_setBBreg(dev
, rOFDM1_TRxPathEnable
, 0xf, 0xf);// 0xd04[3:0]
464 //analog to digital part2 on
465 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x1e00, 0xf); // 0x880[12:9]
467 else if(priv
->rf_type
== RF_1T2R
) //RF-C, RF-D
470 rtl8192_setBBreg(dev
, rFPGA0_XC_RFInterfaceOE
, BIT4
, 0x1); // 0x868[4]
471 //analog to digital on
472 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xc00, 0x3);// 0x88c[11:10]
473 //digital to analog on
474 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x180, 0x3); // 0x880[8:7]
476 rtl8192_setBBreg(dev
, rOFDM0_TRxPathEnable
, 0xc, 0x3);// 0xc04[3:2]
478 rtl8192_setBBreg(dev
, rOFDM1_TRxPathEnable
, 0xc, 0x3);// 0xd04[3:2]
479 //analog to digital part2 on
480 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x1800, 0x3); // 0x880[12:11]
483 write_nic_byte(dev
, ANAPAR
, 0x37);//160MHz
484 write_nic_byte(dev
, MacBlkCtrl
, 0x17); // 0x403
486 //enable clock 80/88 MHz
488 priv
->bHwRfOffAction
= 0;
491 // Baseband reset 2008.09.30 add
492 write_nic_byte(dev
, BB_RESET
, (read_nic_byte(dev
, BB_RESET
)|BIT0
));
496 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter2
, 0x20000000, 0x1); // 0x884
497 //analog to digital part2 on
498 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x60, 0x3); // 0x880[6:5]
499 //digital to analog on
500 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x98, 0x13); // 0x880[4:3]
501 //analog to digital on
502 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xf03, 0xf03);// 0x88c[9:8]
504 //PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0x3, 0x3);// 0xc04[1:0]
505 //rx antenna on 2008.09.30 mark
506 //PHY_SetBBReg(Adapter, rOFDM1_TRxPathEnable, 0x3, 0x3);// 0xd04[1:0]
510 rtl8192_setBBreg(dev
, rFPGA0_XA_RFInterfaceOE
, BIT4
, 0x1); // 0x860[4]
511 rtl8192_setBBreg(dev
, rFPGA0_XB_RFInterfaceOE
, BIT4
, 0x1); // 0x864[4]
516 // In current solution, RFSleep=RFOff in order to save power under 802.11 power save.
517 // By Bruce, 2008-01-16.
521 RT_TRACE(COMP_POWER
, "SetRFPowerState8190() eRfOff/Sleep !\n");
522 if (pPSC
->bLeisurePs
)
524 for(QueueID
= 0, i
= 0; QueueID
< MAX_TX_QUEUE
; )
528 tail
=priv
->txmapringtail
;
529 head
=priv
->txmapringhead
;
533 tail
=priv
->txbkpringtail
;
534 head
=priv
->txbkpringhead
;
538 tail
=priv
->txbepringtail
;
539 head
=priv
->txbepringhead
;
543 tail
=priv
->txvipringtail
;
544 head
=priv
->txvipringhead
;
548 tail
=priv
->txvopringtail
;
549 head
=priv
->txvopringhead
;
558 //DbgPrint("QueueID = %d", QueueID);
564 RT_TRACE(COMP_POWER
, "eRf Off/Sleep: %d times BusyQueue[%d] !=0 before doze!\n", (i
+1), QueueID
);
569 if(i
>= MAX_DOZE_WAITING_TIMES_9x
)
571 RT_TRACE(COMP_POWER
, "\n\n\n TimeOut!! SetRFPowerState8190(): eRfOff: %d times BusyQueue[%d] != 0 !!!\n\n\n", MAX_DOZE_WAITING_TIMES_9x
, QueueID
);
577 if(priv
->rf_type
== RF_2T4R
)
579 //disable RF-Chip A/B
580 rtl8192_setBBreg(dev
, rFPGA0_XA_RFInterfaceOE
, BIT4
, 0x0); // 0x860[4]
582 //disable RF-Chip C/D
583 rtl8192_setBBreg(dev
, rFPGA0_XC_RFInterfaceOE
, BIT4
, 0x0); // 0x868[4]
584 //analog to digital off, for power save
585 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xf00, 0x0);// 0x88c[11:8]
586 //digital to analog off, for power save
587 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x1e0, 0x0); // 0x880[8:5]
589 rtl8192_setBBreg(dev
, rOFDM0_TRxPathEnable
, 0xf, 0x0);// 0xc04[3:0]
591 rtl8192_setBBreg(dev
, rOFDM1_TRxPathEnable
, 0xf, 0x0);// 0xd04[3:0]
592 //analog to digital part2 off, for power save
593 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x1e00, 0x0); // 0x880[12:9]
596 //disable RF-Chip A/B
597 rtl8192_setBBreg(dev
, rFPGA0_XA_RFInterfaceOE
, BIT4
, 0x0); // 0x860[4]
598 rtl8192_setBBreg(dev
, rFPGA0_XB_RFInterfaceOE
, BIT4
, 0x0); // 0x864[4]
600 //analog to digital off, for power save
601 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter4, 0xf00, 0x0);// 0x88c[11:8]
602 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter4
, 0xf03, 0x0); // 2008.09.30 Modify
603 //digital to analog off, for power save
604 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter1, 0x18, 0x0); // 0x880[4:3]
605 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x98, 0x0); // 0x880 2008.09.30 Modify
606 //rx antenna off 2008.09.30 mark
607 //PHY_SetBBReg(Adapter, rOFDM0_TRxPathEnable, 0xf, 0x0);// 0xc04[3:0]
608 //rx antenna off 2008.09.30 mark
609 //PHY_SetBBReg(Adapter, rOFDM1_TRxPathEnable, 0xf, 0x0);// 0xd04[3:0]
610 //analog to digital part2 off, for power save
611 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter1
, 0x60, 0x0); // 0x880[6:5]
613 rtl8192_setBBreg(dev
, rFPGA0_AnalogParameter2
, 0x20000000, 0x0); // 0x884
616 //disable clock 80/88 MHz 2008.09.30 mark
617 //PHY_SetBBReg(Adapter, rFPGA0_AnalogParameter1, 0x4, 0x0); // 0x880[2]
619 // Baseband reset 2008.09.30 add
620 write_nic_byte(dev
, BB_RESET
, (read_nic_byte(dev
, BB_RESET
)|BIT0
)); // 0x101
622 write_nic_byte(dev
, MacBlkCtrl
, 0x0); // 0x403
623 //slow down cpu/lbus clock from 160MHz to Lower
624 write_nic_byte(dev
, ANAPAR
, 0x07); // 0x 17 40MHz
625 priv
->bHwRfOffAction
= 0;
632 RT_TRACE(COMP_ERR
, "SetRFPowerState8190(): unknow state to set: 0x%X!!!\n", eRFPowerState
);
639 RT_TRACE(COMP_ERR
, "SetRFPowerState8190(): Unknown RF type\n");
645 // Update current RF state variable.
646 priv
->ieee80211
->eRFPowerState
= eRFPowerState
;
648 switch(priv
->rf_chip
)
651 switch(priv
->ieee80211
->eRFPowerState
)
655 //If Rf off reason is from IPS, Led should blink with no link, by Maddest 071015
657 if(priv
->ieee80211
->RfOffReason
==RF_CHANGE_BY_IPS
)
660 Adapter
->HalFunc
.LedControlHandler(Adapter
,LED_CTL_NO_LINK
);
665 // Turn off LED if RF is not ON.
667 Adapter
->HalFunc
.LedControlHandler(Adapter
, LED_CTL_POWER_OFF
);
673 // Turn on RF we are still linked, which might happen when
674 // we quickly turn off and on HW RF. 2006.05.12, by rcnjko.
675 if( priv
->ieee80211
->state
== IEEE80211_LINKED
)
678 Adapter
->HalFunc
.LedControlHandler(Adapter
, LED_CTL_LINK
);
683 // Turn off LED if RF is not ON.
685 Adapter
->HalFunc
.LedControlHandler(Adapter
, LED_CTL_NO_LINK
);
698 RT_TRACE(COMP_ERR
, "SetRFPowerState8190(): Unknown RF type\n");
703 priv
->SetRFPowerStateInProgress
= false;
704 RT_TRACE(COMP_POWER
, "<=========== SetRFPowerState8190() bResult = %d!\n", bResult
);
712 // Change RF power state.
715 // This function must be executed in re-schdulable context,
716 // ie. PASSIVE_LEVEL.
718 // 050823, by rcnjko.
722 struct net_device
* dev
,
723 RT_RF_POWER_STATE eRFPowerState
726 struct r8192_priv
*priv
= ieee80211_priv(dev
);
728 bool bResult
= false;
730 RT_TRACE(COMP_RF
,"---------> SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState
);
732 if(eRFPowerState
== priv
->ieee80211
->eRFPowerState
&& priv
->bHwRfOffAction
== 0)
734 if(eRFPowerState
== priv
->ieee80211
->eRFPowerState
)
737 RT_TRACE(COMP_POWER
, "<--------- SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState
);
741 bResult
= SetRFPowerState8190(dev
, eRFPowerState
);
743 RT_TRACE(COMP_POWER
, "<--------- SetRFPowerState(): bResult(%d)\n", bResult
);
750 struct net_device
* dev
753 struct r8192_priv
*priv
= ieee80211_priv(dev
);
756 bool bFilterOutNonAssociatedBSSID
= false;
758 //IEEE80211_DEBUG(IEEE80211_DL_TRACE, "XXXXXXXXXX MgntDisconnect IBSS\n");
760 priv
->ieee80211
->state
= IEEE80211_NOLINK
;
762 // PlatformZeroMemory( pMgntInfo->Bssid, 6 );
763 for(i
=0;i
<6;i
++) priv
->ieee80211
->current_network
.bssid
[i
]= 0x55;
764 priv
->OpMode
= RT_OP_MODE_NO_LINK
;
765 write_nic_word(dev
, BSSIDR
, ((u16
*)priv
->ieee80211
->current_network
.bssid
)[0]);
766 write_nic_dword(dev
, BSSIDR
+2, ((u32
*)(priv
->ieee80211
->current_network
.bssid
+2))[0]);
768 RT_OP_MODE OpMode
= priv
->OpMode
;
769 //LED_CTL_MODE LedAction = LED_CTL_NO_LINK;
770 u8 btMsr
= read_nic_byte(dev
, MSR
);
776 case RT_OP_MODE_INFRASTRUCTURE
:
777 btMsr
|= MSR_LINK_MANAGED
;
778 //LedAction = LED_CTL_LINK;
781 case RT_OP_MODE_IBSS
:
782 btMsr
|= MSR_LINK_ADHOC
;
783 // led link set seperate
787 btMsr
|= MSR_LINK_MASTER
;
788 //LedAction = LED_CTL_LINK;
792 btMsr
|= MSR_LINK_NONE
;
796 write_nic_byte(dev
, MSR
, btMsr
);
799 //Adapter->HalFunc.LedControlHandler(Adapter, LedAction);
801 ieee80211_stop_send_beacons(priv
->ieee80211
);
803 // If disconnect, clear RCR CBSSID bit
804 bFilterOutNonAssociatedBSSID
= false;
807 Type
= bFilterOutNonAssociatedBSSID
;
808 RegRCR
= read_nic_dword(dev
,RCR
);
809 priv
->ReceiveConfig
= RegRCR
;
811 RegRCR
|= (RCR_CBSSID
);
812 else if (Type
== false)
813 RegRCR
&= (~RCR_CBSSID
);
816 write_nic_dword(dev
, RCR
,RegRCR
);
817 priv
->ReceiveConfig
= RegRCR
;
821 //MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE );
822 notify_wx_assoc_event(priv
->ieee80211
);
827 MlmeDisassociateRequest(
828 struct net_device
* dev
,
833 struct r8192_priv
*priv
= ieee80211_priv(dev
);
836 RemovePeerTS(priv
->ieee80211
, asSta
);
838 SendDisassociation( priv
->ieee80211
, asSta
, asRsn
);
840 if(memcpy(priv
->ieee80211
->current_network
.bssid
,asSta
,6) == NULL
)
842 //ShuChen TODO: change media status.
843 //ShuChen TODO: What to do when disassociate.
844 priv
->ieee80211
->state
= IEEE80211_NOLINK
;
845 //pMgntInfo->AsocTimestamp = 0;
846 for(i
=0;i
<6;i
++) priv
->ieee80211
->current_network
.bssid
[i
] = 0x22;
847 // pMgntInfo->mBrates.Length = 0;
848 // Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
849 priv
->OpMode
= RT_OP_MODE_NO_LINK
;
851 RT_OP_MODE OpMode
= priv
->OpMode
;
852 //LED_CTL_MODE LedAction = LED_CTL_NO_LINK;
853 u8 btMsr
= read_nic_byte(dev
, MSR
);
859 case RT_OP_MODE_INFRASTRUCTURE
:
860 btMsr
|= MSR_LINK_MANAGED
;
861 //LedAction = LED_CTL_LINK;
864 case RT_OP_MODE_IBSS
:
865 btMsr
|= MSR_LINK_ADHOC
;
866 // led link set seperate
870 btMsr
|= MSR_LINK_MASTER
;
871 //LedAction = LED_CTL_LINK;
875 btMsr
|= MSR_LINK_NONE
;
879 write_nic_byte(dev
, MSR
, btMsr
);
882 //Adapter->HalFunc.LedControlHandler(Adapter, LedAction);
884 ieee80211_disassociate(priv
->ieee80211
);
886 write_nic_word(dev
, BSSIDR
, ((u16
*)priv
->ieee80211
->current_network
.bssid
)[0]);
887 write_nic_dword(dev
, BSSIDR
+2, ((u32
*)(priv
->ieee80211
->current_network
.bssid
+2))[0]);
896 struct net_device
* dev
,
900 struct r8192_priv
*priv
= ieee80211_priv(dev
);
901 bool bFilterOutNonAssociatedBSSID
= false;
904 // Commented out by rcnjko, 2005.01.27:
905 // I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
907 // //2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
908 // SecClearAllKeys(Adapter);
910 // In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
912 if( pMgntInfo
->SecurityInfo
.AuthMode
> RT_802_11AuthModeAutoSwitch
||
913 (pMgntInfo
->bAPSuportCCKM
&& pMgntInfo
->bCCX8021xenable
) ) // In CCKM mode will Clear key
915 SecClearAllKeys(Adapter
);
916 RT_TRACE(COMP_SEC
, DBG_LOUD
,("======>CCKM clear key..."))
919 // If disconnect, clear RCR CBSSID bit
920 bFilterOutNonAssociatedBSSID
= false;
924 Type
= bFilterOutNonAssociatedBSSID
;
925 //Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RCR, (pu1Byte)(&RegRCR));
926 RegRCR
= read_nic_dword(dev
,RCR
);
927 priv
->ReceiveConfig
= RegRCR
;
930 RegRCR
|= (RCR_CBSSID
);
931 else if (Type
== false)
932 RegRCR
&= (~RCR_CBSSID
);
934 write_nic_dword(dev
, RCR
,RegRCR
);
935 priv
->ReceiveConfig
= RegRCR
;
939 // 2004.10.11, by rcnjko.
940 //MlmeDisassociateRequest( Adapter, pMgntInfo->Bssid, disas_lv_ss );
941 MlmeDisassociateRequest( dev
, priv
->ieee80211
->current_network
.bssid
, asRsn
);
943 priv
->ieee80211
->state
= IEEE80211_NOLINK
;
944 //pMgntInfo->AsocTimestamp = 0;
950 struct net_device
* dev
,
954 struct r8192_priv
*priv
= ieee80211_priv(dev
);
957 // Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
960 if(pMgntInfo
->mPss
!= eAwake
)
963 // Using AwkaeTimer to prevent mismatch ps state.
964 // In the timer the state will be changed according to the RF is being awoke or not. By Bruce, 2007-10-31.
966 // PlatformScheduleWorkItem( &(pMgntInfo->AwakeWorkItem) );
967 PlatformSetTimer( Adapter
, &(pMgntInfo
->AwakeTimer
), 0 );
970 // Follow 8180 AP mode, 2005.05.30, by rcnjko.
972 if(pMgntInfo
->mActingAsAp
)
974 RT_TRACE(COMP_MLME
, DBG_LOUD
, ("MgntDisconnect() ===> AP_DisassociateAllStation\n"));
975 AP_DisassociateAllStation(Adapter
, unspec_reason
);
979 // Indication of disassociation event.
980 //DrvIFIndicateDisassociation(Adapter, asRsn);
982 // In adhoc mode, update beacon frame.
983 if( priv
->ieee80211
->state
== IEEE80211_LINKED
)
985 if( priv
->ieee80211
->iw_mode
== IW_MODE_ADHOC
)
987 //RT_TRACE(COMP_MLME, "MgntDisconnect() ===> MgntDisconnectIBSS\n");
988 MgntDisconnectIBSS(dev
);
990 if( priv
->ieee80211
->iw_mode
== IW_MODE_INFRA
)
992 // We clear key here instead of MgntDisconnectAP() because that
993 // MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
994 // e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
995 // used to handle disassociation related things to AP, e.g. send Disassoc
996 // frame to AP. 2005.01.27, by rcnjko.
997 //IEEE80211_DEBUG(IEEE80211_DL_TRACE,"MgntDisconnect() ===> MgntDisconnectAP\n");
998 MgntDisconnectAP(dev
, asRsn
);
1001 // Inidicate Disconnect, 2005.02.23, by rcnjko.
1002 //MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE);
1010 // Chang RF Power State.
1011 // Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
1017 MgntActSet_RF_State(
1018 struct net_device
* dev
,
1019 RT_RF_POWER_STATE StateToSet
,
1020 RT_RF_CHANGE_SOURCE ChangeSource
1023 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1024 bool bActionAllowed
= false;
1025 bool bConnectBySSID
= false;
1026 RT_RF_POWER_STATE rtState
;
1027 u16 RFWaitCounter
= 0;
1029 RT_TRACE(COMP_POWER
, "===>MgntActSet_RF_State(): StateToSet(%d)\n",StateToSet
);
1032 //1//<1>Prevent the race condition of RF state change.
1034 // Only one thread can change the RF state at one time, and others should wait to be executed. By Bruce, 2007-11-28.
1038 spin_lock_irqsave(&priv
->rf_ps_lock
,flag
);
1039 if(priv
->RFChangeInProgress
)
1041 spin_unlock_irqrestore(&priv
->rf_ps_lock
,flag
);
1042 RT_TRACE(COMP_POWER
, "MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n", StateToSet
);
1044 // Set RF after the previous action is done.
1045 while(priv
->RFChangeInProgress
)
1048 RT_TRACE(COMP_POWER
, "MgntActSet_RF_State(): Wait 1 ms (%d times)...\n", RFWaitCounter
);
1049 udelay(1000); // 1 ms
1051 // Wait too long, return FALSE to avoid to be stuck here.
1052 if(RFWaitCounter
> 100)
1054 RT_TRACE(COMP_ERR
, "MgntActSet_RF_State(): Wait too logn to set RF\n");
1055 // TODO: Reset RF state?
1062 priv
->RFChangeInProgress
= true;
1063 spin_unlock_irqrestore(&priv
->rf_ps_lock
,flag
);
1068 rtState
= priv
->ieee80211
->eRFPowerState
;
1074 // Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
1075 // the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
1078 priv
->ieee80211
->RfOffReason
&= (~ChangeSource
);
1080 if(! priv
->ieee80211
->RfOffReason
)
1082 priv
->ieee80211
->RfOffReason
= 0;
1083 bActionAllowed
= true;
1086 if(rtState
== eRfOff
&& ChangeSource
>=RF_CHANGE_BY_HW
)
1088 bConnectBySSID
= true;
1092 RT_TRACE(COMP_POWER
, "MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", priv
->ieee80211
->RfOffReason
, ChangeSource
);
1098 if (priv
->ieee80211
->RfOffReason
> RF_CHANGE_BY_IPS
)
1102 // Disconnect to current BSS when radio off. Asked by QuanTa.
1104 // Set all link status falg, by Bruce, 2007-06-26.
1105 //MgntActSet_802_11_DISASSOCIATE( Adapter, disas_lv_ss );
1106 MgntDisconnect(dev
, disas_lv_ss
);
1108 // Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI.
1109 // 2007.05.28, by shien chang.
1114 priv
->ieee80211
->RfOffReason
|= ChangeSource
;
1115 bActionAllowed
= true;
1119 priv
->ieee80211
->RfOffReason
|= ChangeSource
;
1120 bActionAllowed
= true;
1129 RT_TRACE(COMP_POWER
, "MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet
, priv
->ieee80211
->RfOffReason
);
1130 // Config HW to the specified mode.
1131 SetRFPowerState(dev
, StateToSet
);
1133 if(StateToSet
== eRfOn
)
1135 //Adapter->HalFunc.HalEnableRxHandler(Adapter);
1138 //MgntActSet_802_11_SSID(Adapter, Adapter->MgntInfo.Ssid.Octet, Adapter->MgntInfo.Ssid.Length, TRUE );
1142 else if(StateToSet
== eRfOff
)
1144 //Adapter->HalFunc.HalDisableRxHandler(Adapter);
1149 RT_TRACE(COMP_POWER
, "MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", StateToSet
, ChangeSource
, priv
->ieee80211
->RfOffReason
);
1152 // Release RF spinlock
1153 spin_lock_irqsave(&priv
->rf_ps_lock
,flag
);
1154 priv
->RFChangeInProgress
= false;
1155 spin_unlock_irqrestore(&priv
->rf_ps_lock
,flag
);
1157 RT_TRACE(COMP_POWER
, "<===MgntActSet_RF_State()\n");
1158 return bActionAllowed
;