b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /*++
|
| 2 | Copyright (c) Realtek Semiconductor Corp. All rights reserved.
|
| 3 |
|
| 4 | Module Name:
|
| 5 | RateAdaptive.c
|
| 6 |
|
| 7 | Abstract:
|
| 8 | Implement Rate Adaptive functions for common operations.
|
| 9 |
|
| 10 | Major Change History:
|
| 11 | When Who What
|
| 12 | ---------- --------------- -------------------------------
|
| 13 | 2011-08-12 Page Create.
|
| 14 |
|
| 15 | --*/
|
| 16 | #ifdef __ECOS
|
| 17 | #include <cyg/io/eth/rltk/819x/wrapper/sys_support.h>
|
| 18 | #endif
|
| 19 | #include "8192cd_cfg.h"
|
| 20 | #ifdef CONFIG_RTL_88E_SUPPORT
|
| 21 |
|
| 22 |
|
| 23 | #ifdef TXREPORT
|
| 24 | #include "8192cd.h"
|
| 25 | #include "8192cd_headers.h"
|
| 26 | #include "8192cd_hw.h"
|
| 27 | #include "8192cd_util.h"
|
| 28 |
|
| 29 | /*
|
| 30 | * RateAdaptive.h - Start
|
| 31 | */
|
| 32 | #define PERENTRY 23
|
| 33 | #define RETRYSIZE 5
|
| 34 | #define RATESIZE 28
|
| 35 | /*
|
| 36 | * RateAdaptive.h - End
|
| 37 | */
|
| 38 |
|
| 39 |
|
| 40 | static unsigned char RETRY_PENALTY[PERENTRY][RETRYSIZE+1] = {{5,4,3,2,0,3},//92 , idx=0
|
| 41 | {6,5,4,3,0,4},//86 , idx=1
|
| 42 | {6,5,4,2,0,4},//81 , idx=2
|
| 43 | {8,7,6,4,0,6},//75 , idx=3
|
| 44 | {10,9,8,6,0,8},//71 , idx=4
|
| 45 | {10,9,8,4,0,8},//66 , idx=5
|
| 46 | {10,9,8,2,0,8},//62 , idx=6
|
| 47 | {10,9,8,0,0,8},//59 , idx=7
|
| 48 | {18,17,16,8,0,16},//53 , idx=8
|
| 49 | {26,25,24,16,0,24},//50 , idx=9
|
| 50 | {34,33,32,24,0,32},//47 , idx=0x0a
|
| 51 | //{34,33,32,16,0,32},//43 , idx=0x0b
|
| 52 | //{34,33,32,8,0,32},//40 , idx=0x0c
|
| 53 | //{34,33,28,8,0,32},//37 , idx=0x0d
|
| 54 | //{34,33,20,8,0,32},//32 , idx=0x0e
|
| 55 | //{34,32,24,8,0,32},//26 , idx=0x0f
|
| 56 | //{49,48,32,16,0,48},//20 , idx=0x10
|
| 57 | //{49,48,24,0,0,48},//17 , idx=0x11
|
| 58 | //{49,47,16,16,0,48},//15 , idx=0x12
|
| 59 | //{49,44,16,16,0,48},//12 , idx=0x13
|
| 60 | //{49,40,16,0,0,48},//9 , idx=0x14
|
| 61 | {34,31,28,20,0,32},//43 , idx=0x0b
|
| 62 | {34,31,27,18,0,32},//40 , idx=0x0c
|
| 63 | {34,31,26,16,0,32},//37 , idx=0x0d
|
| 64 | {34,30,22,16,0,32},//32 , idx=0x0e
|
| 65 | {34,30,24,16,0,32},//26 , idx=0x0f
|
| 66 | {49,46,40,16,0,48},//20 , idx=0x10
|
| 67 | {49,45,32,0,0,48},//17 , idx=0x11
|
| 68 | {49,45,22,18,0,48},//15 , idx=0x12
|
| 69 | {49,40,28,18,0,48},//12 , idx=0x13
|
| 70 | {49,34,20,16,0,48},//9 , idx=0x14
|
| 71 | {49,22,18,14,0,48},//6 , idx=0x15
|
| 72 | {49,16,16,0,0,48}};//3 //3, idx=0x16
|
| 73 |
|
| 74 |
|
| 75 | #if 0
|
| 76 | static unsigned char RETRY_PENALTY_UP[RETRYSIZE+1]={49,44,16,16,0,48}; // 12% for rate up
|
| 77 |
|
| 78 | static unsigned char PT_PENALTY[RETRYSIZE+1]={34,31,30,24,0,32};
|
| 79 |
|
| 80 | static u1Byte RETRY_PENALTY_IDX[2][RATESIZE] = {{4,4,4,5,4,4,5,7,7,7,8,0x0a, // SS>TH
|
| 81 | 4,4,4,4,6,0x0a,0x0b,0x0d,
|
| 82 | 5,5,7,7,8,0x0b,0x0d,0x0f}, // 0329 R01
|
| 83 | {4,4,4,5,7,7,9,9,0x0c,0x0e,0x10,0x12, // SS<TH
|
| 84 | 4,4,5,5,6,0x0a,0x11,0x13,
|
| 85 | 9,9,9,9,0x0c,0x0e,0x11,0x13}};
|
| 86 | #endif
|
| 87 | // wilson modify
|
| 88 | static unsigned char RETRY_PENALTY_IDX[2][RATESIZE] = {{4,4,4,5,4,4,5,7,7,7,8,0x0a, // SS>TH
|
| 89 | 4,4,4,4,6,0x0a,0x0b,0x0d,
|
| 90 | 5,5,7,7,8,0x0b,0x0d,0x0f}, // 0329 R01
|
| 91 | {0x0a,0x0a,0x0a,0x0a,0x0c,0x0c,0x0e,0x10,0x11,0x12,0x12,0x13, // SS<TH
|
| 92 | 0x0e,0x0f,0x10,0x10,0x11,0x14,0x14,0x15,
|
| 93 | 9,9,9,9,0x0c,0x0e,0x11,0x13}};
|
| 94 | static unsigned char RETRY_PENALTY_UP_IDX[RATESIZE] = {0x10,0x10,0x10,0x10,0x11,0x11,0x12,0x12,0x12,0x13,0x13,0x14, // SS>TH
|
| 95 | 0x13,0x13,0x14,0x14,0x15,0x15,0x15,0x15,
|
| 96 | 0x11,0x11,0x12,0x13,0x13,0x13,0x14,0x15};
|
| 97 |
|
| 98 | /*static unsigned char RSSI_THRESHOLD[RATESIZE] = {0,0,0,0,
|
| 99 | 0,0,0,0,0,0x24,0x26,0x2a,
|
| 100 | 0x18,0x1a,0x1d,0x1f,0x21,0x27,0x29,0x2a,
|
| 101 | 0,0,0,0x1f,0x23,0x28,0x2a,0x2c};*/
|
| 102 | static unsigned char RSSI_THRESHOLD[RATESIZE] = {0,0,0,0,
|
| 103 | 0,0,0,0,0,0x24,0x26,0x2a,
|
| 104 | 0x13,0x15,0x17,0x18,0x1a,0x1c,0x1d,0x1f,
|
| 105 | 0,0,0,0x1f,0x23,0x28,0x2a,0x2c};
|
| 106 | static unsigned short N_THRESHOLD_HIGH[RATESIZE] = {4,4,8,16,
|
| 107 | 24,36,48,72,96,144,192,216,
|
| 108 | 60,80,100,160,240,400,560,640,
|
| 109 | 300,320,480,720,1000,1200,1600,2000};
|
| 110 | static unsigned short N_THRESHOLD_LOW[RATESIZE] = {2,2,4,8,
|
| 111 | 12,18,24,36,48,72,96,108,
|
| 112 | 30,40,50,80,120,200,280,320,
|
| 113 | 150,160,240,360,500,600,800,1000};
|
| 114 | #if 0
|
| 115 | static unsigned char TRYING_NECESSARY[RATESIZE] = {2,2,2,2,
|
| 116 | 2,2,3,3,4,4,5,7,
|
| 117 | 4,4,7,10,10,12,12,18,
|
| 118 | 5,7,7,8,11,18,36,60}; // 0329 // 1207
|
| 119 | static u1Byte POOL_RETRY_TH[RATESIZE] = {30,30,30,30,
|
| 120 | 30,30,25,25,20,15,15,10,
|
| 121 | 30,25,25,20,15,10,10,10,
|
| 122 | 30,25,25,20,15,10,10,10};
|
| 123 | #endif
|
| 124 |
|
| 125 | static unsigned char DROPING_NECESSARY[RATESIZE] = {1,1,1,1,
|
| 126 | 1,2,3,4,5,6,7,8,
|
| 127 | 1,2,3,4,5,6,7,8,
|
| 128 | 5,6,7,8,9,10,11,12};
|
| 129 |
|
| 130 | #if 0
|
| 131 | static unsigned int INIT_RATE_FALLBACK_TABLE[16]={0x0f8ff015, // 0: 40M BGN mode
|
| 132 | 0x0f8ff010, // 1: 40M GN mode
|
| 133 | 0x0f8ff005, // 2: BN mode/ 40M BGN mode
|
| 134 | 0x0f8ff000, // 3: N mode
|
| 135 | 0x00000ff5, // 4: BG mode
|
| 136 | 0x00000ff0, // 5: G mode
|
| 137 | 0x0000000d, // 6: B mode
|
| 138 | 0, // 7:
|
| 139 | 0, // 8:
|
| 140 | 0, // 9:
|
| 141 | 0, // 10:
|
| 142 | 0, // 11:
|
| 143 | 0, // 12:
|
| 144 | 0, // 13:
|
| 145 | 0, // 14:
|
| 146 | 0, // 15:
|
| 147 |
|
| 148 | };
|
| 149 | #endif
|
| 150 | static unsigned char PendingForRateUpFail[5]={2,10,24,40,60};
|
| 151 |
|
| 152 | static unsigned short DefaultTxRPTTiming=0x186a; //200ms
|
| 153 | unsigned short DynamicTxRPTTiming[6]={0x186a, 0x30d4, 0x493e, 0x61a8, 0x7a12 ,0x927c}; // 200ms-1200ms
|
| 154 | #if 0
|
| 155 | static unsigned short MinTxRPTTiming=0x186a; //200ms
|
| 156 | #endif
|
| 157 | unsigned char TxRPTTiming_idx=1;
|
| 158 | unsigned char DynamicTxRPTTimingCounter=0;
|
| 159 |
|
| 160 |
|
| 161 | // End Rate adaptive parameters
|
| 162 | int RateAdaptiveInfoInit(PSTATION_RA_INFO pRaInfo)
|
| 163 | {
|
| 164 | if(pRaInfo)
|
| 165 | {
|
| 166 | /* panic_printk("%s %d, aid %d\n", __FUNCTION__, __LINE__, pRaInfo->pstat->cmn_info.aid);*/
|
| 167 | pRaInfo->DecisionRate = 0x13;
|
| 168 | pRaInfo->PreRate = 0x13;
|
| 169 | pRaInfo->HighestRate=0x13;
|
| 170 | pRaInfo->LowestRate=0;
|
| 171 | pRaInfo->RateID=0;
|
| 172 | pRaInfo->RateMask=0xffffffff;
|
| 173 | pRaInfo->RssiStaRA=0;
|
| 174 | pRaInfo->PreRssiStaRA=0;
|
| 175 | pRaInfo->SGIEnable=0;
|
| 176 | pRaInfo->RAUseRate=0xffffffff;
|
| 177 | pRaInfo->NscDown=(N_THRESHOLD_HIGH[0x13]+N_THRESHOLD_LOW[0x13])/2;
|
| 178 | pRaInfo->NscUp=(N_THRESHOLD_HIGH[0x13]+N_THRESHOLD_LOW[0x13])/2;
|
| 179 | pRaInfo->RateSGI=0;
|
| 180 | pRaInfo->Active=1; //Active is not used at present. by page, 110819
|
| 181 | pRaInfo->RptTime = 0x927c;
|
| 182 | pRaInfo->DROP=0;
|
| 183 | pRaInfo->RTY[0]=0;
|
| 184 | pRaInfo->RTY[1]=0;
|
| 185 | pRaInfo->RTY[2]=0;
|
| 186 | pRaInfo->RTY[3]=0;
|
| 187 | pRaInfo->RTY[4]=0;
|
| 188 | pRaInfo->TOTAL=0;
|
| 189 | #if 1
|
| 190 | pRaInfo->RAWaitingCounter=0;
|
| 191 | pRaInfo->RAPendingCounter=0;
|
| 192 | #endif
|
| 193 | #if 0
|
| 194 | pRaInfo->TryingState=0;
|
| 195 | pRaInfo->RateBeforeTrying=0x13;
|
| 196 | #endif
|
| 197 | #if 0 //def POWER_TRAINING_ACTIVE
|
| 198 | pRaInfo->PTTryState=0;
|
| 199 | pRaInfo->PTStage=0;
|
| 200 | pRaInfo->PTStopCount=0;
|
| 201 | pRaInfo->PTPreRate=0;
|
| 202 | pRaInfo->PTPreRssi=0;
|
| 203 | pRaInfo->PTModeSS=0;
|
| 204 | pRaInfo->RAstage=0;
|
| 205 | #endif
|
| 206 | }
|
| 207 | return 0;
|
| 208 | }
|
| 209 |
|
| 210 | int ARFBRefresh(struct rtl8192cd_priv *priv, PSTATION_RA_INFO pRaInfo)
|
| 211 | { // Wilson 2011/10/26
|
| 212 | unsigned int MaskFromReg;
|
| 213 | int i;
|
| 214 |
|
| 215 | // Test for Wilson
|
| 216 | #if defined(CONFIG_PCI_HCI)
|
| 217 | if (priv->hci_type == RTL_HCI_PCIE) {
|
| 218 | RTL_W16(REG_88E_TXRPT_TIM, DefaultTxRPTTiming); //200ms
|
| 219 | }
|
| 220 | #endif
|
| 221 | #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)
|
| 222 | if (priv->hci_type == RTL_HCI_USB || priv->hci_type == RTL_HCI_SDIO) {
|
| 223 | notify_tx_report_interval_change(priv, DefaultTxRPTTiming);
|
| 224 | }
|
| 225 | #endif
|
| 226 | RTL_W32(DARFRC, 0x04020100);
|
| 227 | RTL_W32(DARFRC+4, 0x0a080706);
|
| 228 |
|
| 229 | switch(pRaInfo->RateID) {
|
| 230 | case RATR_INX_WIRELESS_NGB:
|
| 231 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&0x0f8ff015;
|
| 232 | break;
|
| 233 | case RATR_INX_WIRELESS_NG:
|
| 234 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&0x0f8ff010;
|
| 235 | break;
|
| 236 | case RATR_INX_WIRELESS_NB:
|
| 237 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&0x0f8ff005;
|
| 238 | break;
|
| 239 | case RATR_INX_WIRELESS_N:
|
| 240 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&0x0f8ff000;
|
| 241 | break;
|
| 242 | case RATR_INX_WIRELESS_GB:
|
| 243 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&0x00000ff5;
|
| 244 | break;
|
| 245 | case RATR_INX_WIRELESS_G:
|
| 246 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&0x00000ff0;
|
| 247 | break;
|
| 248 | case RATR_INX_WIRELESS_B:
|
| 249 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&0x0000000d;
|
| 250 | break;
|
| 251 | case 12:
|
| 252 | MaskFromReg=RTL_R32(ARFR0);
|
| 253 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&MaskFromReg;
|
| 254 | break;
|
| 255 | case 13:
|
| 256 | MaskFromReg=RTL_R32(ARFR1);
|
| 257 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&MaskFromReg;
|
| 258 | break;
|
| 259 | case 14:
|
| 260 | MaskFromReg=RTL_R32(ARFR2);
|
| 261 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&MaskFromReg;
|
| 262 | break;
|
| 263 | case 15:
|
| 264 | MaskFromReg=RTL_R32(ARFR3);
|
| 265 | pRaInfo->RAUseRate=(pRaInfo->RateMask)&MaskFromReg;
|
| 266 | break;
|
| 267 | default:
|
| 268 | pRaInfo->RAUseRate=(pRaInfo->RateMask);
|
| 269 | break;
|
| 270 | }
|
| 271 | // Highest rate
|
| 272 | if (pRaInfo->RAUseRate) {
|
| 273 | for (i=RATESIZE;i>=0;i--) {
|
| 274 | if((pRaInfo->RAUseRate)&BIT(i)) {
|
| 275 | pRaInfo->HighestRate=i;
|
| 276 | break;
|
| 277 | }
|
| 278 | }
|
| 279 | } else {
|
| 280 | pRaInfo->HighestRate=0;
|
| 281 | }
|
| 282 |
|
| 283 | // Lowest rate
|
| 284 | if (pRaInfo->RAUseRate) {
|
| 285 | for (i=0;i<RATESIZE;i++) {
|
| 286 | if((pRaInfo->RAUseRate)&BIT(i)) {
|
| 287 | pRaInfo->LowestRate=i;
|
| 288 | break;
|
| 289 | }
|
| 290 | }
|
| 291 | } else {
|
| 292 | pRaInfo->LowestRate=0;
|
| 293 | }
|
| 294 | #if 0
|
| 295 | pRaInfo->RAWaitingCounter=0;
|
| 296 | pRaInfo->RAExtendCounter=0;
|
| 297 | #endif
|
| 298 |
|
| 299 | /* panic_printk("%s %d: RateID=%d RateMask=%8.8x RAUseRate=%8.8x HighestRate=%d\n",
|
| 300 | __FUNCTION__, __LINE__,
|
| 301 | pRaInfo->RateID, pRaInfo->RateMask, pRaInfo->RAUseRate, pRaInfo->HighestRate);*/
|
| 302 | return 0;
|
| 303 | }
|
| 304 |
|
| 305 |
|
| 306 | static int RateDown(struct rtl8192cd_priv *priv, PSTATION_RA_INFO pRaInfo)
|
| 307 | {
|
| 308 | unsigned char RateID, LowestRate, HighestRate;
|
| 309 | unsigned char i;
|
| 310 |
|
| 311 | if(NULL == pRaInfo) {
|
| 312 | printk("%s %d: pRaInfo is NULL\n", __FUNCTION__, __LINE__);
|
| 313 | return -1;
|
| 314 | }
|
| 315 | RateID = pRaInfo->PreRate;
|
| 316 | LowestRate = pRaInfo->LowestRate;
|
| 317 | HighestRate = pRaInfo->HighestRate;
|
| 318 |
|
| 319 | /* panic_printk("%s %d: RateID=%d LowestRate=%d HighestRate=%d RateSGI=%d\n",
|
| 320 | __FUNCTION__, __LINE__,
|
| 321 | RateID, LowestRate, HighestRate, pRaInfo->RateSGI);*/
|
| 322 |
|
| 323 | if (RateID > HighestRate) {
|
| 324 | RateID=HighestRate;
|
| 325 | } else if(pRaInfo->RateSGI) {
|
| 326 | pRaInfo->RateSGI=0;
|
| 327 | } else if (RateID > LowestRate) {
|
| 328 | if (RateID > 0) {
|
| 329 | for (i=RateID-1; i>LowestRate;i--) {
|
| 330 | if (pRaInfo->RAUseRate & BIT(i)) {
|
| 331 | RateID=i;
|
| 332 | goto RateDownFinish;
|
| 333 | }
|
| 334 | }
|
| 335 | }
|
| 336 | } else if (RateID <= LowestRate) {
|
| 337 | RateID = LowestRate;
|
| 338 | }
|
| 339 |
|
| 340 | RateDownFinish:
|
| 341 | #if 1
|
| 342 | if (pRaInfo->RAWaitingCounter==1) {
|
| 343 | pRaInfo->RAWaitingCounter+=1;
|
| 344 | pRaInfo->RAPendingCounter+=1;
|
| 345 | }
|
| 346 | else if(pRaInfo->RAWaitingCounter==0){
|
| 347 | } else {
|
| 348 | pRaInfo->RAWaitingCounter=0;
|
| 349 | pRaInfo->RAPendingCounter=0;
|
| 350 | }
|
| 351 |
|
| 352 | if(pRaInfo->RAPendingCounter>=4)
|
| 353 | pRaInfo->RAPendingCounter=4;
|
| 354 | #endif
|
| 355 |
|
| 356 | pRaInfo->DecisionRate=RateID;
|
| 357 | RTL8188E_SetTxReportTimeByRA(priv, 2);
|
| 358 |
|
| 359 | /* panic_printk("=====> rate down %s %d: Rate down to RateID %d RateSGI %d\n", __FUNCTION__, __LINE__, RateID, pRaInfo->RateSGI);*/
|
| 360 | return 0;
|
| 361 | }
|
| 362 |
|
| 363 |
|
| 364 | static int RateUp(struct rtl8192cd_priv *priv, PSTATION_RA_INFO pRaInfo)
|
| 365 | {
|
| 366 | unsigned char RateID, HighestRate;
|
| 367 | unsigned char i;
|
| 368 |
|
| 369 | if(NULL == pRaInfo) {
|
| 370 | printk("%s %d: pRaInfo is NULL\n", __FUNCTION__, __LINE__);
|
| 371 | return -1;
|
| 372 | }
|
| 373 | RateID = pRaInfo->PreRate;
|
| 374 | #if 0
|
| 375 | pRaInfo->RateBeforeTrying=RateID;
|
| 376 | #endif
|
| 377 | HighestRate = pRaInfo->HighestRate;
|
| 378 | /* panic_printk("%s %d: RateID=%d HighestRate=%d\n", __FUNCTION__, __LINE__, RateID, HighestRate);*/
|
| 379 | #if 1
|
| 380 | if (pRaInfo->RAWaitingCounter==1) {
|
| 381 | pRaInfo->RAWaitingCounter=0;
|
| 382 | pRaInfo->RAPendingCounter=0;
|
| 383 | } else if (pRaInfo->RAWaitingCounter>1) {
|
| 384 | pRaInfo->PreRssiStaRA=pRaInfo->RssiStaRA;
|
| 385 | goto RateUpfinish;
|
| 386 | }
|
| 387 | RTL8188E_SetTxReportTimeByRA(priv, 0);
|
| 388 | /* panic_printk("%s %d, Decrease RPT Timing\n", __FUNCTION__, __LINE__);*/
|
| 389 | #endif
|
| 390 |
|
| 391 | if (RateID < HighestRate) {
|
| 392 | for (i=RateID+1; i<=HighestRate; i++) {
|
| 393 | if (pRaInfo->RAUseRate & BIT(i)) {
|
| 394 | RateID=i;
|
| 395 | goto RateUpfinish;
|
| 396 | }
|
| 397 | }
|
| 398 | } else if(RateID == HighestRate) {
|
| 399 | if (pRaInfo->SGIEnable && (pRaInfo->RateSGI != 1))
|
| 400 | pRaInfo->RateSGI = 1;
|
| 401 | else if((pRaInfo->SGIEnable) !=1 )
|
| 402 | pRaInfo->RateSGI = 0;
|
| 403 | } else /* if((sta_info_ra->Decision_rate) > (sta_info_ra->Highest_rate)) */ {
|
| 404 | RateID = HighestRate;
|
| 405 | }
|
| 406 |
|
| 407 | RateUpfinish:
|
| 408 | #if 1
|
| 409 | //if(pRaInfo->RAWaitingCounter==10)
|
| 410 | if(pRaInfo->RAWaitingCounter==(4+PendingForRateUpFail[pRaInfo->RAPendingCounter]))
|
| 411 | pRaInfo->RAWaitingCounter=0;
|
| 412 | else
|
| 413 | pRaInfo->RAWaitingCounter++;
|
| 414 | #endif
|
| 415 | pRaInfo->DecisionRate=RateID;
|
| 416 | #if 0
|
| 417 | pRaInfo->TryingState=1;
|
| 418 | StartRateTrying(Adapter,pRaInfo);
|
| 419 | #endif
|
| 420 | /* panic_printk("%s %d: Rate up to RateID %d\n", __FUNCTION__, __LINE__, RateID);*/
|
| 421 | return 0;
|
| 422 | }
|
| 423 |
|
| 424 |
|
| 425 | static void ResetRaCounter(PSTATION_RA_INFO pRaInfo){
|
| 426 | unsigned char RateID;
|
| 427 | RateID=pRaInfo->DecisionRate;
|
| 428 | pRaInfo->NscUp=(N_THRESHOLD_HIGH[RateID]+N_THRESHOLD_LOW[RateID])>>1;
|
| 429 | pRaInfo->NscDown=(N_THRESHOLD_HIGH[RateID]+N_THRESHOLD_LOW[RateID])>>1;
|
| 430 | }
|
| 431 |
|
| 432 | #if 0
|
| 433 | void StartRateTrying(IN PADAPTER Adapter, IN PSTATION_RA_INFO pRaInfo)
|
| 434 | {
|
| 435 |
|
| 436 | // Test for Wilson
|
| 437 | PlatformEFIOWrite2Byte(Adapter, REG_TX_RPT_TIME,0x0138);
|
| 438 | RT_TRACE(COMP_RATE_ADAPTIVE, DBG_LOUD,
|
| 439 | ("StartRateTrying(): "));
|
| 440 | // Need to Modify (Try bit?, Try timing)
|
| 441 |
|
| 442 |
|
| 443 | }
|
| 444 |
|
| 445 | u1Byte EndRateTrying(IN PADAPTER Adapter, IN PSTATION_RA_INFO pRaInfo)
|
| 446 | {
|
| 447 |
|
| 448 | u1Byte TryResult=0;
|
| 449 | u4Byte pool_retry;
|
| 450 | pRaInfo->DecisionRate=(pRaInfo->DecisionRate)&0x7f;
|
| 451 | PlatformEFIOWrite2Byte(Adapter, REG_TX_RPT_TIME,0x44A5);
|
| 452 | pool_retry=pRaInfo->RTY[1]+pRaInfo->RTY[2]+pRaInfo->RTY[3]+pRaInfo->RTY[4]+pRaInfo->DROP;
|
| 453 | if (pool_retry>2)
|
| 454 | TryResult=0;
|
| 455 | else
|
| 456 | TryResult=1;
|
| 457 |
|
| 458 | return TryResult;
|
| 459 |
|
| 460 |
|
| 461 | }
|
| 462 | #endif
|
| 463 |
|
| 464 |
|
| 465 | /* moved to 8188e_hw.c
|
| 466 |
|
| 467 | void SetTxRPTTiming(IN PADAPTER Adapter, int extend)
|
| 468 | {
|
| 469 | u2Byte WriteTxRPTTiming;
|
| 470 | u1Byte idx;
|
| 471 |
|
| 472 | idx=TxRPTTiming_idx;
|
| 473 | if (extend==0) // back to default timing
|
| 474 | idx=1; //400ms
|
| 475 | else if (extend==1) {// increase the timing
|
| 476 | idx+=1;
|
| 477 | if (idx>5)
|
| 478 | idx=5;
|
| 479 | }
|
| 480 | else if (extend==2) {// decrease the timing
|
| 481 | if(idx!=0)
|
| 482 | idx-=1;
|
| 483 | }
|
| 484 | WriteTxRPTTiming=DynamicTxRPTTiming[idx];
|
| 485 | TxRPTTiming_idx=idx;
|
| 486 | PlatformEFIOWrite2Byte(Adapter, REG_TX_RPT_TIME, WriteTxRPTTiming);
|
| 487 |
|
| 488 | }
|
| 489 | */
|
| 490 |
|
| 491 |
|
| 492 | void RateDecision(struct rtl8192cd_priv *priv, PSTATION_RA_INFO pRaInfo)
|
| 493 | {
|
| 494 | unsigned char RateID = 0, RtyPtID = 0, PenaltyID1 = 0, PenaltyID2 = 0;
|
| 495 | //unsigned int pool_retry;
|
| 496 | //unsigned char Try_Result=0;
|
| 497 |
|
| 498 | if (pRaInfo->Active && (pRaInfo->TOTAL > 0)) /* STA used and data packet exits */ {
|
| 499 | #if 0
|
| 500 | if (pRaInfo->TryingState==1){
|
| 501 |
|
| 502 | pRaInfo->TryingState=0;
|
| 503 | Try_Result=EndRateTrying(Adapter,pRaInfo);
|
| 504 | if (Try_Result==1) // Try good
|
| 505 | pRaInfo->RateBeforeTrying=pRaInfo->DecisionRate;
|
| 506 | else // Try bad
|
| 507 | pRaInfo->DecisionRate=pRaInfo->RateBeforeTrying;
|
| 508 | goto RateDecisionFinish;
|
| 509 | }
|
| 510 | #endif
|
| 511 | if ((pRaInfo->RssiStaRA<(pRaInfo->PreRssiStaRA-3))|| (pRaInfo->RssiStaRA>(pRaInfo->PreRssiStaRA+3))) {
|
| 512 | pRaInfo->RAWaitingCounter=0;
|
| 513 | pRaInfo->RAPendingCounter=0;
|
| 514 | }
|
| 515 | // Start RA decision
|
| 516 | if (pRaInfo->PreRate > pRaInfo->HighestRate)
|
| 517 | RateID = pRaInfo->HighestRate;
|
| 518 | else
|
| 519 | RateID = pRaInfo->PreRate;
|
| 520 | if (pRaInfo->RssiStaRA > RSSI_THRESHOLD[RateID])
|
| 521 | RtyPtID=0;
|
| 522 | else
|
| 523 | RtyPtID=1;
|
| 524 | PenaltyID1 = RETRY_PENALTY_IDX[RtyPtID][RateID]; //TODO by page
|
| 525 |
|
| 526 | /* panic_printk("%s %d: NscDown init is %d\n", __FUNCTION__, __LINE__, pRaInfo->NscDown);*/
|
| 527 | //pool_retry=pRaInfo->RTY[2]+pRaInfo->RTY[3]+pRaInfo->RTY[4]+pRaInfo->DROP;
|
| 528 | pRaInfo->NscDown += pRaInfo->RTY[0] * RETRY_PENALTY[PenaltyID1][0];
|
| 529 | pRaInfo->NscDown += pRaInfo->RTY[1] * RETRY_PENALTY[PenaltyID1][1];
|
| 530 | pRaInfo->NscDown += pRaInfo->RTY[2] * RETRY_PENALTY[PenaltyID1][2];
|
| 531 | pRaInfo->NscDown += pRaInfo->RTY[3] * RETRY_PENALTY[PenaltyID1][3];
|
| 532 | pRaInfo->NscDown += pRaInfo->RTY[4] * RETRY_PENALTY[PenaltyID1][4];
|
| 533 | /* panic_printk("%s %d: NscDown is %d, total*penalty[5] is %d\n", __FUNCTION__, __LINE__,
|
| 534 | pRaInfo->NscDown, (pRaInfo->TOTAL * RETRY_PENALTY[PenaltyID1][5]));*/
|
| 535 | if (pRaInfo->NscDown > (pRaInfo->TOTAL * RETRY_PENALTY[PenaltyID1][5]))
|
| 536 | pRaInfo->NscDown -= pRaInfo->TOTAL * RETRY_PENALTY[PenaltyID1][5];
|
| 537 | else
|
| 538 | pRaInfo->NscDown=0;
|
| 539 |
|
| 540 | // rate up
|
| 541 | PenaltyID2 = RETRY_PENALTY_UP_IDX[RateID];
|
| 542 | /* panic_printk("%s %d: NscUp init is %d\n", __FUNCTION__, __LINE__, pRaInfo->NscUp);*/
|
| 543 | pRaInfo->NscUp += pRaInfo->RTY[0] * RETRY_PENALTY[PenaltyID2][0];
|
| 544 | pRaInfo->NscUp += pRaInfo->RTY[1] * RETRY_PENALTY[PenaltyID2][1];
|
| 545 | pRaInfo->NscUp += pRaInfo->RTY[2] * RETRY_PENALTY[PenaltyID2][2];
|
| 546 | pRaInfo->NscUp += pRaInfo->RTY[3] * RETRY_PENALTY[PenaltyID2][3];
|
| 547 | pRaInfo->NscUp += pRaInfo->RTY[4] * RETRY_PENALTY[PenaltyID2][4];
|
| 548 | /* panic_printk("%s %d: NscUp is %d, total*up[5] is %d\n", __FUNCTION__, __LINE__,
|
| 549 | pRaInfo->NscUp, (pRaInfo->TOTAL * RETRY_PENALTY[PenaltyID2][5]));*/
|
| 550 | if (pRaInfo->NscUp > (pRaInfo->TOTAL * RETRY_PENALTY[PenaltyID2][5]))
|
| 551 | pRaInfo->NscUp -= pRaInfo->TOTAL * RETRY_PENALTY[PenaltyID2][5];
|
| 552 | else
|
| 553 | pRaInfo->NscUp = 0;
|
| 554 | /*printk("%s %d, RTY0 %d, RTY1 %d, RTY2 %d, RTY3 %d, RTY4 %d, userate 0x%08x\n",
|
| 555 | __FUNCTION__, __LINE__, pRaInfo->RTY[0], pRaInfo->RTY[1], pRaInfo->RTY[2], pRaInfo->RTY[3], pRaInfo->RTY[4], pRaInfo->RAUseRate);*/
|
| 556 | /* panic_printk("%s %d: RssiStaRa= %d RtyPtID=%d PenaltyID1=0x%x PenaltyID2=0x%x RateID=%d NscDown=%d NscUp=%d\n",
|
| 557 | __FUNCTION__, __LINE__,
|
| 558 | pRaInfo->RssiStaRA,RtyPtID, PenaltyID1,PenaltyID2, RateID, pRaInfo->NscDown, pRaInfo->NscUp);*/
|
| 559 | if ((pRaInfo->NscDown < N_THRESHOLD_LOW[RateID]) ||(pRaInfo->DROP>DROPING_NECESSARY[RateID]))
|
| 560 | RateDown(priv, pRaInfo);
|
| 561 | //else if ((pRaInfo->NscUp > N_THRESHOLD_HIGH[RateID])&&(pool_retry<POOL_RETRY_TH[RateID]))
|
| 562 | else if (pRaInfo->NscUp > N_THRESHOLD_HIGH[RateID])
|
| 563 | RateUp(priv, pRaInfo);
|
| 564 | #if 0
|
| 565 | RateDecisionFinish:
|
| 566 | #endif
|
| 567 | if ((pRaInfo->DecisionRate)==(pRaInfo->PreRate))
|
| 568 | DynamicTxRPTTimingCounter+=1;
|
| 569 | else
|
| 570 | DynamicTxRPTTimingCounter=0;
|
| 571 |
|
| 572 | if (DynamicTxRPTTimingCounter>=4) {
|
| 573 | RTL8188E_SetTxReportTimeByRA(priv, 1);
|
| 574 | /* panic_printk("%s %d, <=====Rate don't change 4 times, Extend RPT Timing\n", __FUNCTION__, __LINE__);*/
|
| 575 | DynamicTxRPTTimingCounter=0;
|
| 576 | }
|
| 577 |
|
| 578 | pRaInfo->RptTime = DynamicTxRPTTiming[TxRPTTiming_idx];
|
| 579 | pRaInfo->PreRate = pRaInfo->DecisionRate;
|
| 580 |
|
| 581 | ResetRaCounter( pRaInfo);
|
| 582 | }
|
| 583 | }
|
| 584 | #endif
|
| 585 | #endif
|
| 586 |
|