4 #include "r8180_93cx6.h"
9 // Return TRUE if we shall perform High Power Mecahnism, FALSE otherwise.
12 #define RATE_ADAPTIVE_TIMER_PERIOD 300
14 bool CheckHighPower(struct net_device
*dev
)
16 struct r8180_priv
*priv
= ieee80211_priv(dev
);
17 struct ieee80211_device
*ieee
= priv
->ieee80211
;
19 if(!priv
->bRegHighPowerMechanism
)
24 if(ieee
->state
== IEEE80211_LINKED_SCANNING
)
34 // Update Tx power level if necessary.
35 // See also DoRxHighPower() and SetTxPowerLevel8185() for reference.
38 // The reason why we udpate Tx power level here instead of DoRxHighPower()
39 // is the number of IO to change Tx power is much more than chane TR switch
40 // and they are related to OFDM and MAC registers.
41 // So, we don't want to update it so frequently in per-Rx packet base.
45 struct net_device
*dev
48 struct r8180_priv
*priv
= ieee80211_priv(dev
);
54 char OfdmTxPwrIdx
, CckTxPwrIdx
;
56 //printk("----> DoTxHighPower()\n");
58 HiPwrUpperTh
= priv
->RegHiPwrUpperTh
;
59 HiPwrLowerTh
= priv
->RegHiPwrLowerTh
;
61 HiPwrUpperTh
= HiPwrUpperTh
* 10;
62 HiPwrLowerTh
= HiPwrLowerTh
* 10;
63 RSSIHiPwrUpperTh
= priv
->RegRSSIHiPwrUpperTh
;
64 RSSIHiPwrLowerTh
= priv
->RegRSSIHiPwrLowerTh
;
67 OfdmTxPwrIdx
= priv
->chtxpwr_ofdm
[priv
->ieee80211
->current_network
.channel
];
68 CckTxPwrIdx
= priv
->chtxpwr
[priv
->ieee80211
->current_network
.channel
];
70 // printk("DoTxHighPower() - UndecoratedSmoothedSS:%d, CurCCKRSSI = %d , bCurCCKPkt= %d \n", priv->UndecoratedSmoothedSS, priv->CurCCKRSSI, priv->bCurCCKPkt );
72 if((priv
->UndecoratedSmoothedSS
> HiPwrUpperTh
) ||
73 (priv
->bCurCCKPkt
&& (priv
->CurCCKRSSI
> RSSIHiPwrUpperTh
)))
75 // Stevenl suggested that degrade 8dbm in high power sate. 2007-12-04 Isaiah
77 // printk("=====>DoTxHighPower() - High Power - UndecoratedSmoothedSS:%d, HiPwrUpperTh = %d \n", priv->UndecoratedSmoothedSS, HiPwrUpperTh );
78 priv
->bToUpdateTxPwr
= true;
79 u1bTmp
= read_nic_byte(dev
, CCK_TXAGC
);
81 // If it never enter High Power.
82 if( CckTxPwrIdx
== u1bTmp
)
84 u1bTmp
= (u1bTmp
> 16) ? (u1bTmp
-16): 0; // 8dbm
85 write_nic_byte(dev
, CCK_TXAGC
, u1bTmp
);
87 u1bTmp
= read_nic_byte(dev
, OFDM_TXAGC
);
88 u1bTmp
= (u1bTmp
> 16) ? (u1bTmp
-16): 0; // 8dbm
89 write_nic_byte(dev
, OFDM_TXAGC
, u1bTmp
);
93 else if((priv
->UndecoratedSmoothedSS
< HiPwrLowerTh
) &&
94 (!priv
->bCurCCKPkt
|| priv
->CurCCKRSSI
< RSSIHiPwrLowerTh
))
96 // printk("DoTxHighPower() - lower Power - UndecoratedSmoothedSS:%d, HiPwrUpperTh = %d \n", priv->UndecoratedSmoothedSS, HiPwrLowerTh );
97 if(priv
->bToUpdateTxPwr
)
99 priv
->bToUpdateTxPwr
= false;
101 u1bTmp
= read_nic_byte(dev
, CCK_TXAGC
);
102 if(u1bTmp
< CckTxPwrIdx
)
104 //u1bTmp = ((u1bTmp+16) > 35) ? 35: (u1bTmp+16); // 8dbm
105 //write_nic_byte(dev, CCK_TXAGC, u1bTmp);
106 write_nic_byte(dev
, CCK_TXAGC
, CckTxPwrIdx
);
109 u1bTmp
= read_nic_byte(dev
, OFDM_TXAGC
);
110 if(u1bTmp
< OfdmTxPwrIdx
)
112 //u1bTmp = ((u1bTmp+16) > 35) ? 35: (u1bTmp+16); // 8dbm
113 //write_nic_byte(dev, OFDM_TXAGC, u1bTmp);
114 write_nic_byte(dev
, OFDM_TXAGC
, OfdmTxPwrIdx
);
119 //printk("<---- DoTxHighPower()\n");
125 // Callback function of UpdateTxPowerWorkItem.
126 // Because of some event happend, e.g. CCX TPC, High Power Mechanism,
127 // We update Tx power of current channel again.
129 void rtl8180_tx_pw_wq (struct work_struct
*work
)
131 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
132 // struct ieee80211_device * ieee = (struct ieee80211_device*)
133 // container_of(work, struct ieee80211_device, watch_dog_wq);
134 struct delayed_work
*dwork
= to_delayed_work(work
);
135 struct ieee80211_device
*ieee
= container_of(dwork
,struct ieee80211_device
,tx_pw_wq
);
136 struct net_device
*dev
= ieee
->dev
;
138 // printk("----> UpdateTxPowerWorkItemCallback()\n");
142 // printk("<---- UpdateTxPowerWorkItemCallback()\n");
148 // Return TRUE if we shall perform DIG Mecahnism, FALSE otherwise.
152 struct net_device
*dev
155 struct r8180_priv
*priv
= ieee80211_priv(dev
);
156 struct ieee80211_device
*ieee
= priv
->ieee80211
;
158 if(!priv
->bDigMechanism
)
161 if(ieee
->state
!= IEEE80211_LINKED
)
164 //if(priv->CurrentOperaRate < 36) // Schedule Dig under all OFDM rates. By Bruce, 2007-06-01.
165 if((priv
->ieee80211
->rate
/5) < 36) // Schedule Dig under all OFDM rates. By Bruce, 2007-06-01.
171 // Implementation of DIG for Zebra and Zebra2.
175 struct net_device
*dev
178 struct r8180_priv
*priv
= ieee80211_priv(dev
);
179 u16 CCKFalseAlarm
, OFDMFalseAlarm
;
180 u16 OfdmFA1
, OfdmFA2
;
181 int InitialGainStep
= 7; // The number of initial gain stages.
182 int LowestGainStage
= 4; // The capable lowest stage of performing dig workitem.
183 u32 AwakePeriodIn2Sec
=0;
185 //printk("---------> DIG_Zebra()\n");
187 CCKFalseAlarm
= (u16
)(priv
->FalseAlarmRegValue
& 0x0000ffff);
188 OFDMFalseAlarm
= (u16
)((priv
->FalseAlarmRegValue
>> 16) & 0x0000ffff);
190 OfdmFA2
= ((u16
)(priv
->RegDigOfdmFaUpTh
)) << 8;
192 // printk("DIG**********CCK False Alarm: %#X \n",CCKFalseAlarm);
193 // printk("DIG**********OFDM False Alarm: %#X \n",OFDMFalseAlarm);
195 // The number of initial gain steps is different, by Bruce, 2007-04-13.
196 if (priv
->InitialGain
== 0 ) //autoDIG
197 { // Advised from SD3 DZ
198 priv
->InitialGain
= 4; // In 87B, m74dBm means State 4 (m82dBm)
200 //if(pHalData->VersionID != VERSION_8187B_B)
201 { // Advised from SD3 DZ
205 #if 1 //lzm reserved 080826
206 AwakePeriodIn2Sec
= (2000-priv
->DozePeriodInPast2Sec
);
207 //printk("&&& DozePeriod=%d AwakePeriod=%d\n", priv->DozePeriodInPast2Sec, AwakePeriodIn2Sec);
208 priv
->DozePeriodInPast2Sec
=0;
210 if(AwakePeriodIn2Sec
)
212 //RT_TRACE(COMP_DIG, DBG_TRACE, ("DIG: AwakePeriodIn2Sec(%d) - FATh(0x%X , 0x%X) ->",AwakePeriodIn2Sec, OfdmFA1, OfdmFA2));
213 // adjuest DIG threshold.
214 OfdmFA1
= (u16
)((OfdmFA1
*AwakePeriodIn2Sec
) / 2000) ;
215 OfdmFA2
= (u16
)((OfdmFA2
*AwakePeriodIn2Sec
) / 2000) ;
216 //RT_TRACE(COMP_DIG, DBG_TRACE, ("( 0x%X , 0x%X)\n", OfdmFA1, OfdmFA2));
220 ;//RT_TRACE(COMP_DIG, DBG_WARNING, ("ERROR!! AwakePeriodIn2Sec should not be ZERO!!\n"));
225 LowestGainStage
= priv
->RegBModeGainStage
; // Lowest gain stage.
227 if (OFDMFalseAlarm
> OfdmFA1
)
229 if (OFDMFalseAlarm
> OfdmFA2
)
231 priv
->DIG_NumberFallbackVote
++;
232 if (priv
->DIG_NumberFallbackVote
>1)
234 //serious OFDM False Alarm, need fallback
235 if (priv
->InitialGain
< InitialGainStep
)
237 priv
->InitialGainBackUp
= priv
->InitialGain
;
239 priv
->InitialGain
= (priv
->InitialGain
+ 1);
240 // printk("DIG**********OFDM False Alarm: %#X, OfdmFA1: %#X, OfdmFA2: %#X\n", OFDMFalseAlarm, OfdmFA1, OfdmFA2);
241 // printk("DIG+++++++ fallback OFDM:%d \n", priv->InitialGain);
242 UpdateInitialGain(dev
);
244 priv
->DIG_NumberFallbackVote
= 0;
245 priv
->DIG_NumberUpgradeVote
=0;
250 if (priv
->DIG_NumberFallbackVote
)
251 priv
->DIG_NumberFallbackVote
--;
253 priv
->DIG_NumberUpgradeVote
=0;
257 if (priv
->DIG_NumberFallbackVote
)
258 priv
->DIG_NumberFallbackVote
--;
259 priv
->DIG_NumberUpgradeVote
++;
261 if (priv
->DIG_NumberUpgradeVote
>9)
263 if (priv
->InitialGain
> LowestGainStage
) // In 87B, m78dBm means State 4 (m864dBm)
265 priv
->InitialGainBackUp
= priv
->InitialGain
;
267 priv
->InitialGain
= (priv
->InitialGain
- 1);
268 // printk("DIG**********OFDM False Alarm: %#X, OfdmFA1: %#X, OfdmFA2: %#X\n", OFDMFalseAlarm, OfdmFA1, OfdmFA2);
269 // printk("DIG--------- Upgrade OFDM:%d \n", priv->InitialGain);
270 UpdateInitialGain(dev
);
272 priv
->DIG_NumberFallbackVote
= 0;
273 priv
->DIG_NumberUpgradeVote
=0;
277 // printk("DIG+++++++ OFDM:%d\n", priv->InitialGain);
278 //printk("<--------- DIG_Zebra()\n");
283 // Dispatch DIG implementation according to RF.
287 struct net_device
*dev
290 struct r8180_priv
*priv
= ieee80211_priv(dev
);
292 switch(priv
->rf_chip
)
294 case RF_ZEBRA2
: // [AnnieWorkaround] For Zebra2, 2005-08-01.
300 printk("DynamicInitGain(): unknown RFChipID(%d) !!!\n", priv
->rf_chip
);
305 void rtl8180_hw_dig_wq (struct work_struct
*work
)
307 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
308 // struct ieee80211_device * ieee = (struct ieee80211_device*)
309 // container_of(work, struct ieee80211_device, watch_dog_wq);
310 struct delayed_work
*dwork
= to_delayed_work(work
);
311 struct ieee80211_device
*ieee
= container_of(dwork
,struct ieee80211_device
,hw_dig_wq
);
312 struct net_device
*dev
= ieee
->dev
;
313 struct r8180_priv
*priv
= ieee80211_priv(dev
);
315 // Read CCK and OFDM False Alarm.
316 priv
->FalseAlarmRegValue
= read_nic_dword(dev
, CCK_FALSE_ALARM
);
319 // Adjust Initial Gain dynamically.
320 DynamicInitGain(dev
);
325 IncludedInSupportedRates(
326 struct r8180_priv
*priv
,
333 unsigned short Found
= 0;
334 u8 NaiveTxRate
= TxRate
&RateMask
;
336 rate_len
= priv
->ieee80211
->current_network
.rates_len
;
337 rate_ex_len
= priv
->ieee80211
->current_network
.rates_ex_len
;
338 for( idx
=0; idx
< rate_len
; idx
++ )
340 if( (priv
->ieee80211
->current_network
.rates
[idx
] & RateMask
) == NaiveTxRate
)
346 for( idx
=0; idx
< rate_ex_len
; idx
++ )
348 if( (priv
->ieee80211
->current_network
.rates_ex
[idx
] & RateMask
) == NaiveTxRate
)
361 // Get the Tx rate one degree up form the input rate in the supported rates.
362 // Return the upgrade rate if it is successed, otherwise return the input rate.
363 // By Bruce, 2007-06-05.
367 struct net_device
*dev
,
371 struct r8180_priv
*priv
= ieee80211_priv(dev
);
377 case 108: // Up to 54Mbps.
381 case 96: // Up to 54Mbps.
385 case 72: // Up to 48Mbps.
389 case 48: // Up to 36Mbps.
393 case 36: // Up to 24Mbps.
397 case 22: // Up to 18Mbps.
401 case 11: // Up to 11Mbps.
405 case 4: // Up to 5.5Mbps.
409 case 2: // Up to 2Mbps.
414 printk("GetUpgradeTxRate(): Input Tx Rate(%d) is undefined!\n", rate
);
417 // Check if the rate is valid.
418 if(IncludedInSupportedRates(priv
, UpRate
))
420 // printk("GetUpgradeTxRate(): GetUpgrade Tx rate(%d) from %d !\n", UpRate, priv->CurrentOperaRate);
425 //printk("GetUpgradeTxRate(): Tx rate (%d) is not in supported rates\n", UpRate);
432 // Get the Tx rate one degree down form the input rate in the supported rates.
433 // Return the degrade rate if it is successed, otherwise return the input rate.
434 // By Bruce, 2007-06-05.
438 struct net_device
*dev
,
442 struct r8180_priv
*priv
= ieee80211_priv(dev
);
448 case 108: // Down to 48Mbps.
452 case 96: // Down to 36Mbps.
456 case 72: // Down to 24Mbps.
460 case 48: // Down to 18Mbps.
464 case 36: // Down to 11Mbps.
468 case 22: // Down to 5.5Mbps.
472 case 11: // Down to 2Mbps.
476 case 4: // Down to 1Mbps.
480 case 2: // Down to 1Mbps.
485 printk("GetDegradeTxRate(): Input Tx Rate(%d) is undefined!\n", rate
);
488 // Check if the rate is valid.
489 if(IncludedInSupportedRates(priv
, DownRate
))
491 // printk("GetDegradeTxRate(): GetDegrade Tx rate(%d) from %d!\n", DownRate, priv->CurrentOperaRate);
496 //printk("GetDegradeTxRate(): Tx rate (%d) is not in supported rates\n", DownRate);
502 // Helper function to determine if specified data rate is
504 // 2005.01.25, by rcnjko.
511 bool bReturn
= false;
513 if((rate
<= 22) && (rate
!= 12) && (rate
!= 18))
522 // Tx Power tracking mechanism routine on 87SE.
523 // Created by Roger, 2007.12.11.
527 struct net_device
*dev
530 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
531 u8 tmpu1Byte
, CurrentThermal
, Idx
;
532 char CckTxPwrIdx
, OfdmTxPwrIdx
;
535 tmpu1Byte
= read_nic_byte(dev
, EN_LPF_CAL
);
536 CurrentThermal
= (tmpu1Byte
& 0xf0)>>4; //[ 7:4]: thermal meter indication.
537 CurrentThermal
= (CurrentThermal
>0x0c)? 0x0c:CurrentThermal
;//lzm add 080826
539 //printk("TxPwrTracking87SE(): CurrentThermal(%d)\n", CurrentThermal);
541 if( CurrentThermal
!= priv
->ThermalMeter
)
543 // printk("TxPwrTracking87SE(): Thermal meter changed!!!\n");
545 // Update Tx Power level on each channel.
546 for(Idx
= 1; Idx
<15; Idx
++)
548 CckTxPwrIdx
= priv
->chtxpwr
[Idx
];
549 OfdmTxPwrIdx
= priv
->chtxpwr_ofdm
[Idx
];
551 if( CurrentThermal
> priv
->ThermalMeter
)
552 { // higher thermal meter.
553 CckTxPwrIdx
+= (CurrentThermal
- priv
->ThermalMeter
)*2;
554 OfdmTxPwrIdx
+= (CurrentThermal
- priv
->ThermalMeter
)*2;
557 CckTxPwrIdx
= 35; // Force TxPower to maximal index.
562 { // lower thermal meter.
563 CckTxPwrIdx
-= (priv
->ThermalMeter
- CurrentThermal
)*2;
564 OfdmTxPwrIdx
-= (priv
->ThermalMeter
- CurrentThermal
)*2;
572 // Update TxPower level on CCK and OFDM resp.
573 priv
->chtxpwr
[Idx
] = CckTxPwrIdx
;
574 priv
->chtxpwr_ofdm
[Idx
] = OfdmTxPwrIdx
;
577 // Update TxPower level immediately.
578 rtl8225z2_SetTXPowerLevel(dev
, priv
->ieee80211
->current_network
.channel
);
580 priv
->ThermalMeter
= CurrentThermal
;
584 struct net_device
*dev
587 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
588 unsigned long CurrTxokCnt
;
592 unsigned long CurrRxokCnt
;
594 bool bTryDown
= false;
598 long CurrSignalStrength
;
599 bool bUpdateInitialGain
= false;
600 u8 u1bOfdm
=0, u1bCck
= 0;
601 char OfdmTxPwrIdx
, CckTxPwrIdx
;
603 priv
->RateAdaptivePeriod
= RATE_ADAPTIVE_TIMER_PERIOD
;
606 CurrRetryCnt
= priv
->CurrRetryCnt
;
607 CurrTxokCnt
= priv
->NumTxOkTotal
- priv
->LastTxokCnt
;
608 CurrRxokCnt
= priv
->ieee80211
->NumRxOkTotal
- priv
->LastRxokCnt
;
609 CurrSignalStrength
= priv
->Stats_RecvSignalPower
;
610 TxThroughput
= (u32
)(priv
->NumTxOkBytesTotal
- priv
->LastTxOKBytes
);
611 priv
->LastTxOKBytes
= priv
->NumTxOkBytesTotal
;
612 priv
->CurrentOperaRate
= priv
->ieee80211
->rate
/5;
613 //printk("priv->CurrentOperaRate is %d\n",priv->CurrentOperaRate);
614 //2 Compute retry ratio.
617 CurrRetryRate
= (u16
)(CurrRetryCnt
*100/CurrTxokCnt
);
620 { // It may be serious retry. To distinguish serious retry or no packets modified by Bruce
621 CurrRetryRate
= (u16
)(CurrRetryCnt
*100/1);
626 // Added by Roger, 2007.01.02.
627 // For debug information.
629 //printk("\n(1) pHalData->LastRetryRate: %d \n",priv->LastRetryRate);
630 //printk("(2) RetryCnt = %d \n", CurrRetryCnt);
631 //printk("(3) TxokCnt = %d \n", CurrTxokCnt);
632 //printk("(4) CurrRetryRate = %d \n", CurrRetryRate);
633 //printk("(5) CurrSignalStrength = %d \n",CurrSignalStrength);
634 //printk("(6) TxThroughput is %d\n",TxThroughput);
635 //printk("priv->NumTxOkBytesTotal is %d\n",priv->NumTxOkBytesTotal);
637 priv
->LastRetryCnt
= priv
->CurrRetryCnt
;
638 priv
->LastTxokCnt
= priv
->NumTxOkTotal
;
639 priv
->LastRxokCnt
= priv
->ieee80211
->NumRxOkTotal
;
640 priv
->CurrRetryCnt
= 0;
642 //2No Tx packets, return to init_rate or not?
643 if (CurrRetryRate
==0 && CurrTxokCnt
== 0)
646 //After 9 (30*300ms) seconds in this condition, we try to raise rate.
648 priv
->TryupingCountNoData
++;
650 // printk("No Tx packets, TryupingCountNoData(%d)\n", priv->TryupingCountNoData);
651 //[TRC Dell Lab] Extend raised period from 4.5sec to 9sec, Isaiah 2008-02-15 18:00
652 if (priv
->TryupingCountNoData
>30)
654 priv
->TryupingCountNoData
= 0;
655 priv
->CurrentOperaRate
= GetUpgradeTxRate(dev
, priv
->CurrentOperaRate
);
657 priv
->LastFailTxRate
= 0;
658 priv
->LastFailTxRateSS
= -200;
659 priv
->FailTxRateCount
= 0;
665 priv
->TryupingCountNoData
=0; //Reset trying up times.
670 // For Netgear case, I comment out the following signal strength estimation,
671 // which can results in lower rate to transmit when sample is NOT enough (e.g. PING request).
672 // 2007.04.09, by Roger.
676 // Restructure rate adaptive as the following main stages:
677 // (1) Add retry threshold in 54M upgrading condition with signal strength.
678 // (2) Add the mechanism to degrade to CCK rate according to signal strength
680 // (3) Remove all Initial Gain Updates over OFDM rate. To avoid the complicated
681 // situation, Initial Gain Update is upon on DIG mechanism except CCK rate.
682 // (4) Add the mehanism of trying to upgrade tx rate.
683 // (5) Record the information of upping tx rate to avoid trying upping tx rate constantly.
684 // By Bruce, 2007-06-05.
689 // Check more times in these rate(key rates).
691 if(priv
->CurrentOperaRate
== 22 || priv
->CurrentOperaRate
== 72)
696 // Let these rates down more difficult.
698 if(MgntIsCckRate(priv
->CurrentOperaRate
) || priv
->CurrentOperaRate
== 36)
704 if (priv
->bTryuping
== true)
706 //2 For Test Upgrading mechanism
708 // Sometimes the throughput is upon on the capability bwtween the AP and NIC,
709 // thus the low data rate does not improve the performance.
710 // We randomly upgrade the data rate and check if the retry rate is improved.
712 // Upgrading rate did not improve the retry rate, fallback to the original rate.
713 if ( (CurrRetryRate
> 25) && TxThroughput
< priv
->LastTxThroughput
)
715 //Not necessary raising rate, fall back rate.
717 //printk("case1-1: Not necessary raising rate, fall back rate....\n");
718 //printk("case1-1: pMgntInfo->CurrentOperaRate =%d, TxThroughput = %d, LastThroughput = %d\n",
719 // priv->CurrentOperaRate, TxThroughput, priv->LastTxThroughput);
723 priv
->bTryuping
= false;
726 else if (CurrSignalStrength
> -47 && (CurrRetryRate
< 50))
730 // Added by Roger, 2007.04.09.
731 // Return to highest data rate, if signal strength is good enough.
732 // SignalStrength threshold(-50dbm) is for RTL8186.
733 // Revise SignalStrength threshold to -51dbm.
735 // Also need to check retry rate for safety, by Bruce, 2007-06-05.
736 if(priv
->CurrentOperaRate
!= priv
->ieee80211
->current_network
.HighestOperaRate
)
739 // Upgrade Tx Rate directly.
740 priv
->TryupingCount
+= TryUpTh
;
742 // printk("case2: StaRateAdaptive87SE: Power(%d) is high enough!!. \n", CurrSignalStrength);
745 else if(CurrTxokCnt
> 9 && CurrTxokCnt
< 100 && CurrRetryRate
>= 600)
747 //2 For Serious Retry
749 // Traffic is not busy but our Tx retry is serious.
752 // Let Rate Mechanism to degrade tx rate directly.
753 priv
->TryDownCountLowData
+= TryDownTh
;
754 // printk("case3: RA: Tx Retry is serious. Degrade Tx Rate to %d directly...\n", priv->CurrentOperaRate);
756 else if ( priv
->CurrentOperaRate
== 108 )
760 if ( (CurrRetryRate
>26)&&(priv
->LastRetryRate
>25))
761 // if ( (CurrRetryRate>40)&&(priv->LastRetryRate>39))
763 //Down to rate 48Mbps.
767 else if ( (CurrRetryRate
>17)&&(priv
->LastRetryRate
>16) && (CurrSignalStrength
> -72))
768 // else if ( (CurrRetryRate>17)&&(priv->LastRetryRate>16) && (CurrSignalStrength > -72))
770 //Down to rate 48Mbps.
774 if(bTryDown
&& (CurrSignalStrength
< -75)) //cable link
776 priv
->TryDownCountLowData
+= TryDownTh
;
778 //printk("case4---54M \n");
781 else if ( priv
->CurrentOperaRate
== 96 )
785 if ( ((CurrRetryRate
>48) && (priv
->LastRetryRate
>47)))
786 // if ( ((CurrRetryRate>65) && (priv->LastRetryRate>64)))
789 //Down to rate 36Mbps.
793 else if ( ((CurrRetryRate
>21) && (priv
->LastRetryRate
>20)) && (CurrSignalStrength
> -74))
795 //Down to rate 36Mbps.
798 else if((CurrRetryRate
> (priv
->LastRetryRate
+ 50 )) && (priv
->FailTxRateCount
>2 ))
799 // else if((CurrRetryRate> (priv->LastRetryRate + 70 )) && (priv->FailTxRateCount >2 ))
802 priv
->TryDownCountLowData
+= TryDownTh
;
804 else if ( (CurrRetryRate
<8) && (priv
->LastRetryRate
<8) ) //TO DO: need to consider (RSSI)
805 // else if ( (CurrRetryRate<28) && (priv->LastRetryRate<8) )
810 if(bTryDown
&& (CurrSignalStrength
< -75))
812 priv
->TryDownCountLowData
+= TryDownTh
;
814 //printk("case5---48M \n");
816 else if ( priv
->CurrentOperaRate
== 72 )
819 if ( (CurrRetryRate
>43) && (priv
->LastRetryRate
>41))
820 // if ( (CurrRetryRate>60) && (priv->LastRetryRate>59))
822 //Down to rate 24Mbps.
825 else if((CurrRetryRate
> (priv
->LastRetryRate
+ 50 )) && (priv
->FailTxRateCount
>2 ))
826 // else if((CurrRetryRate> (priv->LastRetryRate + 70 )) && (priv->FailTxRateCount >2 ))
829 priv
->TryDownCountLowData
+= TryDownTh
;
831 else if ( (CurrRetryRate
<15) && (priv
->LastRetryRate
<16)) //TO DO: need to consider (RSSI)
832 // else if ( (CurrRetryRate<35) && (priv->LastRetryRate<36))
837 if(bTryDown
&& (CurrSignalStrength
< -80))
839 priv
->TryDownCountLowData
+= TryDownTh
;
841 //printk("case6---36M \n");
843 else if ( priv
->CurrentOperaRate
== 48 )
847 if ( ((CurrRetryRate
>63) && (priv
->LastRetryRate
>62)))
848 // if ( ((CurrRetryRate>83) && (priv->LastRetryRate>82)))
850 //Down to rate 18Mbps.
854 else if ( ((CurrRetryRate
>33) && (priv
->LastRetryRate
>32)) && (CurrSignalStrength
> -82) )
855 // else if ( ((CurrRetryRate>50) && (priv->LastRetryRate>49)) && (CurrSignalStrength > -82) )
857 //Down to rate 18Mbps.
860 else if((CurrRetryRate
> (priv
->LastRetryRate
+ 50 )) && (priv
->FailTxRateCount
>2 ))
861 // else if((CurrRetryRate> (priv->LastRetryRate + 70 )) && (priv->FailTxRateCount >2 ))
865 priv
->TryDownCountLowData
+= TryDownTh
;
867 else if ( (CurrRetryRate
<20) && (priv
->LastRetryRate
<21)) //TO DO: need to consider (RSSI)
868 // else if ( (CurrRetryRate<40) && (priv->LastRetryRate<41))
873 if(bTryDown
&& (CurrSignalStrength
< -82))
875 priv
->TryDownCountLowData
+= TryDownTh
;
877 //printk("case7---24M \n");
879 else if ( priv
->CurrentOperaRate
== 36 )
882 // original (109, 109)
883 //[TRC Dell Lab] (90, 91), Isaiah 2008-02-18 23:24
884 // (85, 86), Isaiah 2008-02-18 24:00
885 if ( ((CurrRetryRate
>85) && (priv
->LastRetryRate
>86)))
886 // if ( ((CurrRetryRate>115) && (priv->LastRetryRate>116)))
888 //Down to rate 11Mbps.
891 //[TRC Dell Lab] Isaiah 2008-02-18 23:24
892 else if((CurrRetryRate
> (priv
->LastRetryRate
+ 50 )) && (priv
->FailTxRateCount
>2 ))
893 // else if((CurrRetryRate> (priv->LastRetryRate + 70 )) && (priv->FailTxRateCount >2 ))
896 priv
->TryDownCountLowData
+= TryDownTh
;
898 else if ( (CurrRetryRate
<22) && (priv
->LastRetryRate
<23)) //TO DO: need to consider (RSSI)
899 // else if ( (CurrRetryRate<42) && (priv->LastRetryRate<43))
903 //printk("case8---18M \n");
905 else if ( priv
->CurrentOperaRate
== 22 )
908 if (CurrRetryRate
>95)
909 // if (CurrRetryRate>155)
913 else if ( (CurrRetryRate
<29) && (priv
->LastRetryRate
<30) )//TO DO: need to consider (RSSI)
914 // else if ( (CurrRetryRate<49) && (priv->LastRetryRate <50) )
918 //printk("case9---11M \n");
920 else if ( priv
->CurrentOperaRate
== 11 )
923 if (CurrRetryRate
>149)
924 // if (CurrRetryRate>189)
928 else if ( (CurrRetryRate
<60) && (priv
->LastRetryRate
< 65))
929 // else if ( (CurrRetryRate<80) && (priv->LastRetryRate < 85))
934 //printk("case10---5.5M \n");
936 else if ( priv
->CurrentOperaRate
== 4 )
939 if((CurrRetryRate
>99) && (priv
->LastRetryRate
>99))
940 // if((CurrRetryRate>199) && (priv->LastRetryRate>199))
944 else if ( (CurrRetryRate
< 65) && (priv
->LastRetryRate
< 70))
945 // else if ( (CurrRetryRate < 85) && (priv->LastRetryRate < 90))
949 //printk("case11---2M \n");
951 else if ( priv
->CurrentOperaRate
== 2 )
954 if( (CurrRetryRate
<70) && (priv
->LastRetryRate
<75))
955 // if( (CurrRetryRate<90) && (priv->LastRetryRate<95))
959 //printk("case12---1M \n");
962 if(bTryUp
&& bTryDown
)
963 printk("StaRateAdaptive87B(): Tx Rate tried upping and downing simultaneously!\n");
965 //1 Test Upgrading Tx Rate
966 // Sometimes the cause of the low throughput (high retry rate) is the compatibility between the AP and NIC.
967 // To test if the upper rate may cause lower retry rate, this mechanism randomly occurs to test upgrading tx rate.
968 if(!bTryUp
&& !bTryDown
&& (priv
->TryupingCount
== 0) && (priv
->TryDownCountLowData
== 0)
969 && priv
->CurrentOperaRate
!= priv
->ieee80211
->current_network
.HighestOperaRate
&& priv
->FailTxRateCount
< 2)
971 if(jiffies
% (CurrRetryRate
+ 101) == 0)
974 priv
->bTryuping
= true;
975 //printk("StaRateAdaptive87SE(): Randomly try upgrading...\n");
982 priv
->TryupingCount
++;
983 priv
->TryDownCountLowData
= 0;
986 // printk("UP: pHalData->TryupingCount = %d\n", priv->TryupingCount);
987 // printk("UP: TryUpTh(%d)+ (FailTxRateCount(%d))^2 =%d\n",
988 // TryUpTh, priv->FailTxRateCount, (TryUpTh + priv->FailTxRateCount * priv->FailTxRateCount) );
989 // printk("UP: pHalData->bTryuping=%d\n", priv->bTryuping);
994 // Check more times if we need to upgrade indeed.
995 // Because the largest value of pHalData->TryupingCount is 0xFFFF and
996 // the largest value of pHalData->FailTxRateCount is 0x14,
997 // this condition will be satisfied at most every 2 min.
1000 if((priv
->TryupingCount
> (TryUpTh
+ priv
->FailTxRateCount
* priv
->FailTxRateCount
)) ||
1001 (CurrSignalStrength
> priv
->LastFailTxRateSS
) || priv
->bTryuping
)
1003 priv
->TryupingCount
= 0;
1005 // When transfering from CCK to OFDM, DIG is an important issue.
1007 if(priv
->CurrentOperaRate
== 22)
1008 bUpdateInitialGain
= true;
1010 // The difference in throughput between 48Mbps and 36Mbps is 8M.
1011 // So, we must be carefully in this rate scale. Isaiah 2008-02-15.
1013 if( ((priv
->CurrentOperaRate
== 72) || (priv
->CurrentOperaRate
== 48) || (priv
->CurrentOperaRate
== 36)) &&
1014 (priv
->FailTxRateCount
> 2) )
1015 priv
->RateAdaptivePeriod
= (RATE_ADAPTIVE_TIMER_PERIOD
/2);
1017 // (1)To avoid upgrade frequently to the fail tx rate, add the FailTxRateCount into the threshold.
1018 // (2)If the signal strength is increased, it may be able to upgrade.
1020 priv
->CurrentOperaRate
= GetUpgradeTxRate(dev
, priv
->CurrentOperaRate
);
1021 // printk("StaRateAdaptive87SE(): Upgrade Tx Rate to %d\n", priv->CurrentOperaRate);
1023 //[TRC Dell Lab] Bypass 12/9/6, Isaiah 2008-02-18 20:00
1024 if(priv
->CurrentOperaRate
==36)
1026 priv
->bUpdateARFR
=true;
1027 write_nic_word(dev
, ARFR
, 0x0F8F); //bypass 12/9/6
1028 // printk("UP: ARFR=0xF8F\n");
1030 else if(priv
->bUpdateARFR
)
1032 priv
->bUpdateARFR
=false;
1033 write_nic_word(dev
, ARFR
, 0x0FFF); //set 1M ~ 54Mbps.
1034 // printk("UP: ARFR=0xFFF\n");
1037 // Update Fail Tx rate and count.
1038 if(priv
->LastFailTxRate
!= priv
->CurrentOperaRate
)
1040 priv
->LastFailTxRate
= priv
->CurrentOperaRate
;
1041 priv
->FailTxRateCount
= 0;
1042 priv
->LastFailTxRateSS
= -200; // Set lowest power.
1048 if(priv
->TryupingCount
> 0)
1049 priv
->TryupingCount
--;
1054 priv
->TryDownCountLowData
++;
1055 priv
->TryupingCount
= 0;
1057 // printk("DN: pHalData->TryDownCountLowData = %d\n",priv->TryDownCountLowData);
1058 // printk("DN: TryDownTh =%d\n", TryDownTh);
1059 // printk("DN: pHalData->bTryuping=%d\n", priv->bTryuping);
1062 //Check if Tx rate can be degraded or Test trying upgrading should fallback.
1063 if(priv
->TryDownCountLowData
> TryDownTh
|| priv
->bTryuping
)
1065 priv
->TryDownCountLowData
= 0;
1066 priv
->bTryuping
= false;
1067 // Update fail information.
1068 if(priv
->LastFailTxRate
== priv
->CurrentOperaRate
)
1070 priv
->FailTxRateCount
++;
1071 // Record the Tx fail rate signal strength.
1072 if(CurrSignalStrength
> priv
->LastFailTxRateSS
)
1074 priv
->LastFailTxRateSS
= CurrSignalStrength
;
1079 priv
->LastFailTxRate
= priv
->CurrentOperaRate
;
1080 priv
->FailTxRateCount
= 1;
1081 priv
->LastFailTxRateSS
= CurrSignalStrength
;
1083 priv
->CurrentOperaRate
= GetDegradeTxRate(dev
, priv
->CurrentOperaRate
);
1085 // Reduce chariot training time at weak signal strength situation. SD3 ED demand.
1086 //[TRC Dell Lab] Revise Signal Threshold from -75 to -80 , Isaiah 2008-02-18 20:00
1087 if( (CurrSignalStrength
< -80) && (priv
->CurrentOperaRate
> 72 ))
1089 priv
->CurrentOperaRate
= 72;
1090 // printk("DN: weak signal strength (%d), degrade to 36Mbps\n", CurrSignalStrength);
1093 //[TRC Dell Lab] Bypass 12/9/6, Isaiah 2008-02-18 20:00
1094 if(priv
->CurrentOperaRate
==36)
1096 priv
->bUpdateARFR
=true;
1097 write_nic_word(dev
, ARFR
, 0x0F8F); //bypass 12/9/6
1098 // printk("DN: ARFR=0xF8F\n");
1100 else if(priv
->bUpdateARFR
)
1102 priv
->bUpdateARFR
=false;
1103 write_nic_word(dev
, ARFR
, 0x0FFF); //set 1M ~ 54Mbps.
1104 // printk("DN: ARFR=0xFFF\n");
1108 // When it is CCK rate, it may need to update initial gain to receive lower power packets.
1110 if(MgntIsCckRate(priv
->CurrentOperaRate
))
1112 bUpdateInitialGain
= true;
1114 // printk("StaRateAdaptive87SE(): Degrade Tx Rate to %d\n", priv->CurrentOperaRate);
1119 if(priv
->TryDownCountLowData
> 0)
1120 priv
->TryDownCountLowData
--;
1123 // Keep the Tx fail rate count to equal to 0x15 at most.
1124 // Reduce the fail count at least to 10 sec if tx rate is tending stable.
1125 if(priv
->FailTxRateCount
>= 0x15 ||
1126 (!bTryUp
&& !bTryDown
&& priv
->TryDownCountLowData
== 0 && priv
->TryupingCount
&& priv
->FailTxRateCount
> 0x6))
1128 priv
->FailTxRateCount
--;
1132 OfdmTxPwrIdx
= priv
->chtxpwr_ofdm
[priv
->ieee80211
->current_network
.channel
];
1133 CckTxPwrIdx
= priv
->chtxpwr
[priv
->ieee80211
->current_network
.channel
];
1135 //[TRC Dell Lab] Mac0x9e increase 2 level in 36M~18M situation, Isaiah 2008-02-18 24:00
1136 if((priv
->CurrentOperaRate
< 96) &&(priv
->CurrentOperaRate
> 22))
1138 u1bCck
= read_nic_byte(dev
, CCK_TXAGC
);
1139 u1bOfdm
= read_nic_byte(dev
, OFDM_TXAGC
);
1141 // case 1: Never enter High power
1142 if(u1bCck
== CckTxPwrIdx
)
1144 if(u1bOfdm
!= (OfdmTxPwrIdx
+2) )
1146 priv
->bEnhanceTxPwr
= true;
1147 u1bOfdm
= ((u1bOfdm
+2) > 35) ? 35: (u1bOfdm
+2);
1148 write_nic_byte(dev
, OFDM_TXAGC
, u1bOfdm
);
1149 // printk("Enhance OFDM_TXAGC : +++++ u1bOfdm= 0x%x\n", u1bOfdm);
1152 // case 2: enter high power
1153 else if(u1bCck
< CckTxPwrIdx
)
1155 if(!priv
->bEnhanceTxPwr
)
1157 priv
->bEnhanceTxPwr
= true;
1158 u1bOfdm
= ((u1bOfdm
+2) > 35) ? 35: (u1bOfdm
+2);
1159 write_nic_byte(dev
, OFDM_TXAGC
, u1bOfdm
);
1160 //RT_TRACE(COMP_RATE, DBG_TRACE, ("Enhance OFDM_TXAGC(2) : +++++ u1bOfdm= 0x%x\n", u1bOfdm));
1164 else if(priv
->bEnhanceTxPwr
) //54/48/11/5.5/2/1
1166 u1bCck
= read_nic_byte(dev
, CCK_TXAGC
);
1167 u1bOfdm
= read_nic_byte(dev
, OFDM_TXAGC
);
1169 // case 1: Never enter High power
1170 if(u1bCck
== CckTxPwrIdx
)
1172 priv
->bEnhanceTxPwr
= false;
1173 write_nic_byte(dev
, OFDM_TXAGC
, OfdmTxPwrIdx
);
1174 //printk("Recover OFDM_TXAGC : ===== u1bOfdm= 0x%x\n", OfdmTxPwrIdx);
1176 // case 2: enter high power
1177 else if(u1bCck
< CckTxPwrIdx
)
1179 priv
->bEnhanceTxPwr
= false;
1180 u1bOfdm
= ((u1bOfdm
-2) > 0) ? (u1bOfdm
-2): 0;
1181 write_nic_byte(dev
, OFDM_TXAGC
, u1bOfdm
);
1182 //RT_TRACE(COMP_RATE, DBG_TRACE, ("Recover OFDM_TXAGC(2): ===== u1bOfdm= 0x%x\n", u1bOfdm));
1188 // We need update initial gain when we set tx rate "from OFDM to CCK" or
1189 // "from CCK to OFDM".
1192 if(bUpdateInitialGain
)
1194 if(MgntIsCckRate(priv
->CurrentOperaRate
)) // CCK
1196 if(priv
->InitialGain
> priv
->RegBModeGainStage
)
1198 priv
->InitialGainBackUp
= priv
->InitialGain
;
1200 if(CurrSignalStrength
< -85) // Low power, OFDM [0x17] = 26.
1202 //SD3 SYs suggest that CurrSignalStrength < -65, ofdm 0x17=26.
1203 priv
->InitialGain
= priv
->RegBModeGainStage
;
1205 else if(priv
->InitialGain
> priv
->RegBModeGainStage
+ 1)
1207 priv
->InitialGain
-= 2;
1211 priv
->InitialGain
--;
1213 printk("StaRateAdaptive87SE(): update init_gain to index %d for date rate %d\n",priv
->InitialGain
, priv
->CurrentOperaRate
);
1214 UpdateInitialGain(dev
);
1219 if(priv
->InitialGain
< 4)
1221 priv
->InitialGainBackUp
= priv
->InitialGain
;
1223 priv
->InitialGain
++;
1224 printk("StaRateAdaptive87SE(): update init_gain to index %d for date rate %d\n",priv
->InitialGain
, priv
->CurrentOperaRate
);
1225 UpdateInitialGain(dev
);
1230 //Record the related info
1231 priv
->LastRetryRate
= CurrRetryRate
;
1232 priv
->LastTxThroughput
= TxThroughput
;
1233 priv
->ieee80211
->rate
= priv
->CurrentOperaRate
* 5;
1236 void rtl8180_rate_adapter(struct work_struct
* work
)
1238 struct delayed_work
*dwork
= to_delayed_work(work
);
1239 struct ieee80211_device
*ieee
= container_of(dwork
,struct ieee80211_device
,rate_adapter_wq
);
1240 struct net_device
*dev
= ieee
->dev
;
1241 //struct r8180_priv *priv = ieee80211_priv(dev);
1242 // DMESG("---->rtl8180_rate_adapter");
1243 StaRateAdaptive87SE(dev
);
1244 // DMESG("<----rtl8180_rate_adapter");
1246 void timer_rate_adaptive(unsigned long data
)
1248 struct r8180_priv
* priv
= ieee80211_priv((struct net_device
*)data
);
1249 //DMESG("---->timer_rate_adaptive()\n");
1252 // DMESG("<----timer_rate_adaptive():driver is not up!\n");
1255 if((priv
->ieee80211
->iw_mode
!= IW_MODE_MASTER
)
1256 && (priv
->ieee80211
->state
== IEEE80211_LINKED
) &&
1257 (priv
->ForcedDataRate
== 0) )
1259 // DMESG("timer_rate_adaptive():schedule rate_adapter_wq\n");
1260 queue_work(priv
->ieee80211
->wq
, (void *)&priv
->ieee80211
->rate_adapter_wq
);
1261 // StaRateAdaptive87SE((struct net_device *)data);
1263 priv
->rateadapter_timer
.expires
= jiffies
+ MSECS(priv
->RateAdaptivePeriod
);
1264 add_timer(&priv
->rateadapter_timer
);
1265 //DMESG("<----timer_rate_adaptive()\n");
1269 SwAntennaDiversityRxOk8185(
1270 struct net_device
*dev
,
1274 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
1276 // printk("+SwAntennaDiversityRxOk8185: RxSs: %d\n", SignalStrength);
1280 if( priv
->AdRxSignalStrength
!= -1)
1282 priv
->AdRxSignalStrength
= ((priv
->AdRxSignalStrength
*7) + (SignalStrength
*3)) / 10;
1285 { // Initialization case.
1286 priv
->AdRxSignalStrength
= SignalStrength
;
1289 if( priv
->LastRxPktAntenna
) //Main antenna.
1290 priv
->AdMainAntennaRxOkCnt
++;
1291 else // Aux antenna.
1292 priv
->AdAuxAntennaRxOkCnt
++;
1294 // printk("-SwAntennaDiversityRxOk8185: AdRxOkCnt: %d AdRxSignalStrength: %d\n", priv->AdRxOkCnt, priv->AdRxSignalStrength);
1298 // Change Antenna Switch.
1302 struct net_device
*dev
,
1306 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
1307 bool bAntennaSwitched
= false;
1309 // printk("+SetAntenna8185(): Antenna is switching to: %d \n", u1bAntennaIndex);
1311 switch(u1bAntennaIndex
)
1314 switch(priv
->rf_chip
)
1318 // Mac register, main antenna
1319 write_nic_byte(dev
, ANTSEL
, 0x03);
1321 write_phy_cck(dev
,0x11, 0x9b); // Config CCK RX antenna.
1322 write_phy_ofdm(dev
, 0x0d, 0x5c); // Config OFDM RX antenna.
1325 bAntennaSwitched
= true;
1329 printk("SetAntenna8185: unkown RFChipID(%d)\n", priv
->rf_chip
);
1335 switch(priv
->rf_chip
)
1339 // Mac register, aux antenna
1340 write_nic_byte(dev
, ANTSEL
, 0x00);
1342 write_phy_cck(dev
, 0x11, 0xbb); // Config CCK RX antenna.
1343 write_phy_ofdm(dev
, 0x0d, 0x54); // Config OFDM RX antenna.
1345 bAntennaSwitched
= true;
1349 printk("SetAntenna8185: unkown RFChipID(%d)\n", priv
->rf_chip
);
1355 printk("SetAntenna8185: unkown u1bAntennaIndex(%d)\n", u1bAntennaIndex
);
1359 if(bAntennaSwitched
)
1361 priv
->CurrAntennaIndex
= u1bAntennaIndex
;
1364 // printk("-SetAntenna8185(): return (%#X)\n", bAntennaSwitched);
1366 return bAntennaSwitched
;
1370 // Toggle Antenna switch.
1374 struct net_device
*dev
1377 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
1381 if(priv
->CurrAntennaIndex
== 0)
1383 bResult
= SetAntenna8185(dev
, 1);
1385 // printk("SwitchAntenna(): switching to antenna 1 ......\n");
1386 // bResult = SetAntenna8185(dev, 1);//-by amy 080312
1390 bResult
= SetAntenna8185(dev
, 0);
1392 // printk("SwitchAntenna(): switching to antenna 0 ......\n");
1393 // bResult = SetAntenna8185(dev, 0);//-by amy 080312
1400 // Engine of SW Antenna Diversity mechanism.
1401 // Since 8187 has no Tx part information,
1402 // this implementation is only dependend on Rx part information.
1404 // 2006.04.17, by rcnjko.
1408 struct net_device
*dev
1411 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
1412 bool bSwCheckSS
=false;
1413 // printk("+SwAntennaDiversity(): CurrAntennaIndex: %d\n", priv->CurrAntennaIndex);
1414 // printk("AdTickCount is %d\n",priv->AdTickCount);
1418 priv
->AdTickCount
++;
1420 printk("(1) AdTickCount: %d, AdCheckPeriod: %d\n",
1421 priv
->AdTickCount
, priv
->AdCheckPeriod
);
1422 printk("(2) AdRxSignalStrength: %ld, AdRxSsThreshold: %ld\n",
1423 priv
->AdRxSignalStrength
, priv
->AdRxSsThreshold
);
1425 // priv->AdTickCount++;//-by amy 080312
1428 if(priv
->ieee80211
->state
!= IEEE80211_LINKED
)
1430 // printk("SwAntennaDiversity(): Case 1. No Link.\n");
1432 priv
->bAdSwitchedChecking
= false;
1433 // I switch antenna here to prevent any one of antenna is broken before link established, 2006.04.18, by rcnjko..
1436 // Case 2. Linked but no packet received.
1437 else if(priv
->AdRxOkCnt
== 0)
1439 // printk("SwAntennaDiversity(): Case 2. Linked but no packet received.\n");
1441 priv
->bAdSwitchedChecking
= false;
1444 // Case 3. Evaluate last antenna switch action and undo it if necessary.
1445 else if(priv
->bAdSwitchedChecking
== true)
1447 // printk("SwAntennaDiversity(): Case 3. Evaluate last antenna switch action.\n");
1449 priv
->bAdSwitchedChecking
= false;
1451 // Adjust Rx signal strength threashold.
1452 priv
->AdRxSsThreshold
= (priv
->AdRxSignalStrength
+ priv
->AdRxSsBeforeSwitched
) / 2;
1454 priv
->AdRxSsThreshold
= (priv
->AdRxSsThreshold
> priv
->AdMaxRxSsThreshold
) ?
1455 priv
->AdMaxRxSsThreshold
: priv
->AdRxSsThreshold
;
1456 if(priv
->AdRxSignalStrength
< priv
->AdRxSsBeforeSwitched
)
1457 { // Rx signal strength is not improved after we swtiched antenna. => Swich back.
1458 // printk("SwAntennaDiversity(): Rx Signal Strength is not improved, CurrRxSs: %d, LastRxSs: %d\n",
1459 // priv->AdRxSignalStrength, priv->AdRxSsBeforeSwitched);
1461 // Increase Antenna Diversity checking period due to bad decision.
1462 priv
->AdCheckPeriod
*= 2;
1464 // Increase Antenna Diversity checking period.
1465 if(priv
->AdCheckPeriod
> priv
->AdMaxCheckPeriod
)
1466 priv
->AdCheckPeriod
= priv
->AdMaxCheckPeriod
;
1468 // Wrong deceision => switch back.
1472 { // Rx Signal Strength is improved.
1473 // printk("SwAntennaDiversity(): Rx Signal Strength is improved, CurrRxSs: %d, LastRxSs: %d\n",
1474 // priv->AdRxSignalStrength, priv->AdRxSsBeforeSwitched);
1476 // Reset Antenna Diversity checking period to its min value.
1477 priv
->AdCheckPeriod
= priv
->AdMinCheckPeriod
;
1480 // printk("SwAntennaDiversity(): AdRxSsThreshold: %d, AdCheckPeriod: %d\n",
1481 // priv->AdRxSsThreshold, priv->AdCheckPeriod);
1483 // Case 4. Evaluate if we shall switch antenna now.
1484 // Cause Table Speed is very fast in TRC Dell Lab, we check it every time.
1485 else// if(priv->AdTickCount >= priv->AdCheckPeriod)//-by amy 080312
1487 // printk("SwAntennaDiversity(): Case 4. Evaluate if we shall switch antenna now.\n");
1489 priv
->AdTickCount
= 0;
1492 // <Roger_Notes> We evaluate RxOk counts for each antenna first and than
1493 // evaluate signal strength.
1494 // The following operation can overcome the disability of CCA on both two antennas
1495 // When signal strength was extremely low or high.
1500 // Evaluate RxOk count from each antenna if we shall switch default antenna now.
1501 // Added by Roger, 2008.02.21.
1503 if((priv
->AdMainAntennaRxOkCnt
< priv
->AdAuxAntennaRxOkCnt
)
1504 && (priv
->CurrAntennaIndex
== 0))
1505 { // We set Main antenna as default but RxOk count was less than Aux ones.
1507 // printk("SwAntennaDiversity(): Main antenna RxOK is poor, AdMainAntennaRxOkCnt: %d, AdAuxAntennaRxOkCnt: %d\n",
1508 // priv->AdMainAntennaRxOkCnt, priv->AdAuxAntennaRxOkCnt);
1510 // Switch to Aux antenna.
1512 priv
->bHWAdSwitched
= true;
1514 else if((priv
->AdAuxAntennaRxOkCnt
< priv
->AdMainAntennaRxOkCnt
)
1515 && (priv
->CurrAntennaIndex
== 1))
1516 { // We set Aux antenna as default but RxOk count was less than Main ones.
1518 // printk("SwAntennaDiversity(): Aux antenna RxOK is poor, AdMainAntennaRxOkCnt: %d, AdAuxAntennaRxOkCnt: %d\n",
1519 // priv->AdMainAntennaRxOkCnt, priv->AdAuxAntennaRxOkCnt);
1521 // Switch to Main antenna.
1523 priv
->bHWAdSwitched
= true;
1526 {// Default antenna is better.
1528 // printk("SwAntennaDiversity(): Default antenna is better., AdMainAntennaRxOkCnt: %d, AdAuxAntennaRxOkCnt: %d\n",
1529 // priv->AdMainAntennaRxOkCnt, priv->AdAuxAntennaRxOkCnt);
1531 // Still need to check current signal strength.
1532 priv
->bHWAdSwitched
= false;
1535 // <Roger_Notes> We evaluate Rx signal strength ONLY when default antenna
1536 // didn't changed by HW evaluation.
1539 // [TRC Dell Lab] SignalStrength is inaccuracy. Isaiah 2008-03-05
1540 // For example, Throughput of aux is better than main antenna(about 10M v.s 2M),
1541 // but AdRxSignalStrength is less than main.
1542 // Our guess is that main antenna have lower throughput and get many change
1543 // to receive more CCK packets(ex.Beacon) which have stronger SignalStrength.
1545 if( (!priv
->bHWAdSwitched
) && (bSwCheckSS
))
1548 // Evaluate Rx signal strength if we shall switch antenna now.
1549 if(priv
->AdRxSignalStrength
< priv
->AdRxSsThreshold
)
1550 { // Rx signal strength is weak => Switch Antenna.
1551 // printk("SwAntennaDiversity(): Rx Signal Strength is weak, CurrRxSs: %d, RxSsThreshold: %d\n",
1552 // priv->AdRxSignalStrength, priv->AdRxSsThreshold);
1554 priv
->AdRxSsBeforeSwitched
= priv
->AdRxSignalStrength
;
1555 priv
->bAdSwitchedChecking
= true;
1560 { // Rx signal strength is OK.
1561 // printk("SwAntennaDiversity(): Rx Signal Strength is OK, CurrRxSs: %d, RxSsThreshold: %d\n",
1562 // priv->AdRxSignalStrength, priv->AdRxSsThreshold);
1564 priv
->bAdSwitchedChecking
= false;
1565 // Increase Rx signal strength threashold if necessary.
1566 if( (priv
->AdRxSignalStrength
> (priv
->AdRxSsThreshold
+ 10)) && // Signal is much stronger than current threshold
1567 priv
->AdRxSsThreshold
<= priv
->AdMaxRxSsThreshold
) // Current threhold is not yet reach upper limit.
1569 priv
->AdRxSsThreshold
= (priv
->AdRxSsThreshold
+ priv
->AdRxSignalStrength
) / 2;
1570 priv
->AdRxSsThreshold
= (priv
->AdRxSsThreshold
> priv
->AdMaxRxSsThreshold
) ?
1571 priv
->AdMaxRxSsThreshold
: priv
->AdRxSsThreshold
;//+by amy 080312
1574 // Reduce Antenna Diversity checking period if possible.
1575 if( priv
->AdCheckPeriod
> priv
->AdMinCheckPeriod
)
1577 priv
->AdCheckPeriod
/= 2;
1583 // Reset antenna diversity Rx related statistics.
1584 priv
->AdRxOkCnt
= 0;
1585 priv
->AdMainAntennaRxOkCnt
= 0;
1586 priv
->AdAuxAntennaRxOkCnt
= 0;
1589 // priv->AdRxOkCnt = 0;//-by amy 080312
1591 // printk("-SwAntennaDiversity()\n");
1596 // Return TRUE if we shall perform Tx Power Tracking Mecahnism, FALSE otherwise.
1599 CheckTxPwrTracking( struct net_device
*dev
)
1601 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
1603 if(!priv
->bTxPowerTrack
)
1608 //lzm reserved 080826
1609 //if(priv->bScanInProgress)
1614 //if 87SE is in High Power , don't do Tx Power Tracking. asked by SD3 ED. 2008-08-08 Isaiah
1615 if(priv
->bToUpdateTxPwr
)
1626 // Timer callback function of SW Antenna Diversity.
1629 SwAntennaDiversityTimerCallback(
1630 struct net_device
*dev
1633 struct r8180_priv
*priv
= (struct r8180_priv
*)ieee80211_priv(dev
);
1634 RT_RF_POWER_STATE rtState
;
1636 //printk("+SwAntennaDiversityTimerCallback()\n");
1639 // We do NOT need to switch antenna while RF is off.
1640 // 2007.05.09, added by Roger.
1642 rtState
= priv
->eRFPowerState
;
1644 if (rtState
== eRfOff
)
1646 // printk("SwAntennaDiversityTimer - RF is OFF.\n");
1649 else if (rtState
== eRfSleep
)
1651 // Don't access BB/RF under Disable PLL situation.
1652 //RT_TRACE((COMP_RF|COMP_ANTENNA), DBG_LOUD, ("SwAntennaDiversityTimerCallback(): RF is Sleep => skip it\n"));
1655 SwAntennaDiversity(dev
);
1661 priv
->SwAntennaDiversityTimer
.expires
= jiffies
+ MSECS(ANTENNA_DIVERSITY_TIMER_PERIOD
);
1662 add_timer(&priv
->SwAntennaDiversityTimer
);
1665 //printk("-SwAntennaDiversityTimerCallback()\n");