2 Copyright-c Realtek Semiconductor Corp. All rights reserved.
12 ---------- --------------- -------------------------------
13 2008-05-14 amy create version 0 porting from windows code.
17 #include "r8192E_dm.h"
18 #include "r8192E_hw.h"
19 #include "r819xE_phy.h"
20 #include "r819xE_phyreg.h"
21 #include "r8190_rtl8256.h"
23 #define DRV_NAME "rtl819xE"
26 // Indicate different AP vendor for IOT issue.
28 static const u32 edca_setting_DL[HT_IOT_PEER_MAX] =
29 { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5e4322, 0x5e4322};
30 static const u32 edca_setting_UL[HT_IOT_PEER_MAX] =
31 { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5e4322, 0x5e4322, 0x5e4322};
33 #define RTK_UL_EDCA 0xa44f
34 #define RTK_DL_EDCA 0x5e4322
38 // For Dynamic Rx Path Selection by Signal Strength
39 DRxPathSel DM_RxPathSelTable;
41 void dm_gpio_change_rf_callback(struct work_struct *work);
43 // DM --> Rate Adaptive
44 static void dm_check_rate_adaptive(struct r8192_priv *priv);
46 // DM --> Bandwidth switch
47 static void dm_init_bandwidth_autoswitch(struct r8192_priv *priv);
48 static void dm_bandwidth_autoswitch(struct r8192_priv *priv);
50 // DM --> TX power control
51 static void dm_check_txpower_tracking(struct r8192_priv *priv);
53 // DM --> Dynamic Init Gain by RSSI
54 static void dm_dig_init(struct r8192_priv *priv);
55 static void dm_ctrl_initgain_byrssi(struct r8192_priv *priv);
56 static void dm_ctrl_initgain_byrssi_highpwr(struct r8192_priv *priv);
57 static void dm_ctrl_initgain_byrssi_by_driverrssi(struct r8192_priv *priv);
58 static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(struct r8192_priv *priv);
59 static void dm_initial_gain(struct r8192_priv *priv);
60 static void dm_pd_th(struct r8192_priv *priv);
61 static void dm_cs_ratio(struct r8192_priv *priv);
63 static void dm_init_ctstoself(struct r8192_priv *priv);
64 // DM --> EDCA turboe mode control
65 static void dm_check_edca_turbo(struct r8192_priv *priv);
66 static void dm_init_edca_turbo(struct r8192_priv *priv);
68 // DM --> HW RF control
69 static void dm_check_rfctrl_gpio(struct r8192_priv *priv);
71 // DM --> Check current RX RF path state
72 static void dm_check_rx_path_selection(struct r8192_priv *priv);
73 static void dm_init_rxpath_selection(struct r8192_priv *priv);
74 static void dm_rxpath_sel_byrssi(struct r8192_priv *priv);
76 // DM --> Fsync for broadcom ap
77 static void dm_init_fsync(struct r8192_priv *priv);
78 static void dm_deInit_fsync(struct r8192_priv *priv);
80 static void dm_check_txrateandretrycount(struct r8192_priv *priv);
81 static void dm_check_fsync(struct r8192_priv *priv);
84 /*---------------------Define of Tx Power Control For Near/Far Range --------*/ //Add by Jacken 2008/02/18
85 static void dm_init_dynamic_txpower(struct r8192_priv *priv);
86 static void dm_dynamic_txpower(struct r8192_priv *priv);
88 // DM --> For rate adaptive and DIG, we must send RSSI to firmware
89 static void dm_send_rssi_tofw(struct r8192_priv *priv);
90 static void dm_ctstoself(struct r8192_priv *priv);
92 static void dm_fsync_timer_callback(unsigned long data);
95 * Prepare SW resource for HW dynamic mechanism.
96 * This function is only invoked at driver intialization once.
98 void init_hal_dm(struct net_device *dev)
100 struct r8192_priv *priv = ieee80211_priv(dev);
102 // Undecorated Smoothed Signal Strength, it can utilized to dynamic mechanism.
103 priv->undecorated_smoothed_pwdb = -1;
105 //Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code.
106 dm_init_dynamic_txpower(priv);
107 init_rate_adaptive(dev);
108 //dm_initialize_txpower_tracking(dev);
110 dm_init_edca_turbo(priv);
111 dm_init_bandwidth_autoswitch(priv);
113 dm_init_rxpath_selection(priv);
114 dm_init_ctstoself(priv);
115 INIT_DELAYED_WORK(&priv->gpio_change_rf_wq, dm_gpio_change_rf_callback);
119 void deinit_hal_dm(struct net_device *dev)
121 struct r8192_priv *priv = ieee80211_priv(dev);
123 dm_deInit_fsync(priv);
126 void hal_dm_watchdog(struct net_device *dev)
128 struct r8192_priv *priv = ieee80211_priv(dev);
130 /*Add by amy 2008/05/15 ,porting from windows code.*/
131 dm_check_rate_adaptive(priv);
132 dm_dynamic_txpower(priv);
133 dm_check_txrateandretrycount(priv);
135 dm_check_txpower_tracking(priv);
137 dm_ctrl_initgain_byrssi(priv);
138 dm_check_edca_turbo(priv);
139 dm_bandwidth_autoswitch(priv);
141 dm_check_rfctrl_gpio(priv);
142 dm_check_rx_path_selection(priv);
143 dm_check_fsync(priv);
145 // Add by amy 2008-05-15 porting from windows code.
146 dm_send_rssi_tofw(priv);
152 * Decide Rate Adaptive Set according to distance (signal strength)
153 * 01/11/2008 MHC Modify input arguments and RATR table level.
154 * 01/16/2008 MHC RF_Type is assigned in ReadAdapterInfo(). We must call
155 * the function after making sure RF_Type.
157 void init_rate_adaptive(struct net_device * dev)
160 struct r8192_priv *priv = ieee80211_priv(dev);
161 prate_adaptive pra = (prate_adaptive)&priv->rate_adaptive;
163 pra->ratr_state = DM_RATR_STA_MAX;
164 pra->high2low_rssi_thresh_for_ra = RateAdaptiveTH_High;
165 pra->low2high_rssi_thresh_for_ra20M = RateAdaptiveTH_Low_20M+5;
166 pra->low2high_rssi_thresh_for_ra40M = RateAdaptiveTH_Low_40M+5;
168 pra->high_rssi_thresh_for_ra = RateAdaptiveTH_High+5;
169 pra->low_rssi_thresh_for_ra20M = RateAdaptiveTH_Low_20M;
170 pra->low_rssi_thresh_for_ra40M = RateAdaptiveTH_Low_40M;
172 if(priv->CustomerID == RT_CID_819x_Netcore)
173 pra->ping_rssi_enable = 1;
175 pra->ping_rssi_enable = 0;
176 pra->ping_rssi_thresh_for_ra = 15;
179 if (priv->rf_type == RF_2T4R)
181 // 07/10/08 MH Modify for RA smooth scheme.
182 /* 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.*/
183 pra->upper_rssi_threshold_ratr = 0x8f0f0000;
184 pra->middle_rssi_threshold_ratr = 0x8f0ff000;
185 pra->low_rssi_threshold_ratr = 0x8f0ff001;
186 pra->low_rssi_threshold_ratr_40M = 0x8f0ff005;
187 pra->low_rssi_threshold_ratr_20M = 0x8f0ff001;
188 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test
190 else if (priv->rf_type == RF_1T2R)
192 pra->upper_rssi_threshold_ratr = 0x000f0000;
193 pra->middle_rssi_threshold_ratr = 0x000ff000;
194 pra->low_rssi_threshold_ratr = 0x000ff001;
195 pra->low_rssi_threshold_ratr_40M = 0x000ff005;
196 pra->low_rssi_threshold_ratr_20M = 0x000ff001;
197 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test
203 static void dm_check_rate_adaptive(struct r8192_priv *priv)
205 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
206 prate_adaptive pra = (prate_adaptive)&priv->rate_adaptive;
207 u32 currentRATR, targetRATR = 0;
208 u32 LowRSSIThreshForRA = 0, HighRSSIThreshForRA = 0;
209 bool bshort_gi_enabled = false;
210 static u8 ping_rssi_state=0;
215 RT_TRACE(COMP_RATE, "<---- dm_check_rate_adaptive(): driver is going to unload\n");
219 if(pra->rate_adaptive_disabled)//this variable is set by ioctl.
222 // TODO: Only 11n mode is implemented currently,
223 if( !(priv->ieee80211->mode == WIRELESS_MODE_N_24G ||
224 priv->ieee80211->mode == WIRELESS_MODE_N_5G))
227 if( priv->ieee80211->state == IEEE80211_LINKED )
229 // RT_TRACE(COMP_RATE, "dm_CheckRateAdaptive(): \t");
232 // Check whether Short GI is enabled
234 bshort_gi_enabled = (pHTInfo->bCurTxBW40MHz && pHTInfo->bCurShortGI40MHz) ||
235 (!pHTInfo->bCurTxBW40MHz && pHTInfo->bCurShortGI20MHz);
238 pra->upper_rssi_threshold_ratr =
239 (pra->upper_rssi_threshold_ratr & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
241 pra->middle_rssi_threshold_ratr =
242 (pra->middle_rssi_threshold_ratr & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
244 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
246 pra->low_rssi_threshold_ratr =
247 (pra->low_rssi_threshold_ratr_40M & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
251 pra->low_rssi_threshold_ratr =
252 (pra->low_rssi_threshold_ratr_20M & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
255 pra->ping_rssi_ratr =
256 (pra->ping_rssi_ratr & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
258 /* 2007/10/08 MH We support RA smooth scheme now. When it is the first
259 time to link with AP. We will not change upper/lower threshold. If
260 STA stay in high or low level, we must change two different threshold
261 to prevent jumping frequently. */
262 if (pra->ratr_state == DM_RATR_STA_HIGH)
264 HighRSSIThreshForRA = pra->high2low_rssi_thresh_for_ra;
265 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
266 (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M);
268 else if (pra->ratr_state == DM_RATR_STA_LOW)
270 HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra;
271 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
272 (pra->low2high_rssi_thresh_for_ra40M):(pra->low2high_rssi_thresh_for_ra20M);
276 HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra;
277 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
278 (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M);
281 if(priv->undecorated_smoothed_pwdb >= (long)HighRSSIThreshForRA)
283 pra->ratr_state = DM_RATR_STA_HIGH;
284 targetRATR = pra->upper_rssi_threshold_ratr;
285 }else if(priv->undecorated_smoothed_pwdb >= (long)LowRSSIThreshForRA)
287 pra->ratr_state = DM_RATR_STA_MIDDLE;
288 targetRATR = pra->middle_rssi_threshold_ratr;
291 pra->ratr_state = DM_RATR_STA_LOW;
292 targetRATR = pra->low_rssi_threshold_ratr;
296 if(pra->ping_rssi_enable)
298 //pHalData->UndecoratedSmoothedPWDB = 19;
299 if(priv->undecorated_smoothed_pwdb < (long)(pra->ping_rssi_thresh_for_ra+5))
301 if( (priv->undecorated_smoothed_pwdb < (long)pra->ping_rssi_thresh_for_ra) ||
304 pra->ratr_state = DM_RATR_STA_LOW;
305 targetRATR = pra->ping_rssi_ratr;
315 // For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
316 if(priv->ieee80211->GetHalfNmodeSupportByAPsHandler(priv->ieee80211->dev))
317 targetRATR &= 0xf00fffff;
320 // Check whether updating of RATR0 is required
322 currentRATR = read_nic_dword(priv, RATR0);
323 if( targetRATR != currentRATR )
326 ratr_value = targetRATR;
327 RT_TRACE(COMP_RATE,"currentRATR = %x, targetRATR = %x\n", currentRATR, targetRATR);
328 if(priv->rf_type == RF_1T2R)
330 ratr_value &= ~(RATE_ALL_OFDM_2SS);
332 write_nic_dword(priv, RATR0, ratr_value);
333 write_nic_byte(priv, UFWP, 1);
335 pra->last_ratr = targetRATR;
341 pra->ratr_state = DM_RATR_STA_MAX;
347 static void dm_init_bandwidth_autoswitch(struct r8192_priv *priv)
349 priv->ieee80211->bandwidth_auto_switch.threshold_20Mhzto40Mhz = BW_AUTO_SWITCH_LOW_HIGH;
350 priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz = BW_AUTO_SWITCH_HIGH_LOW;
351 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = false;
352 priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable = false;
357 static void dm_bandwidth_autoswitch(struct r8192_priv *priv)
359 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 ||!priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable){
362 if(priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz == false){//If send packets in 40 Mhz in 20/40
363 if(priv->undecorated_smoothed_pwdb <= priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz)
364 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = true;
365 }else{//in force send packets in 20 Mhz in 20/40
366 if(priv->undecorated_smoothed_pwdb >= priv->ieee80211->bandwidth_auto_switch.threshold_20Mhzto40Mhz)
367 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = false;
373 //OFDM default at 0db, index=6.
374 static const u32 OFDMSwingTable[OFDM_Table_Length] = {
375 0x7f8001fe, // 0, +6db
376 0x71c001c7, // 1, +5db
377 0x65400195, // 2, +4db
378 0x5a400169, // 3, +3db
379 0x50800142, // 4, +2db
380 0x47c0011f, // 5, +1db
381 0x40000100, // 6, +0db ===> default, upper for higher temperature, lower for low temperature
382 0x390000e4, // 7, -1db
383 0x32c000cb, // 8, -2db
384 0x2d4000b5, // 9, -3db
385 0x288000a2, // 10, -4db
386 0x24000090, // 11, -5db
387 0x20000080, // 12, -6db
388 0x1c800072, // 13, -7db
389 0x19800066, // 14, -8db
390 0x26c0005b, // 15, -9db
391 0x24400051, // 16, -10db
392 0x12000048, // 17, -11db
393 0x10000040 // 18, -12db
395 static const u8 CCKSwingTable_Ch1_Ch13[CCK_Table_length][8] = {
396 {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, // 0, +0db ===> CCK40M default
397 {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, // 1, -1db
398 {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, // 2, -2db
399 {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, // 3, -3db
400 {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, // 4, -4db
401 {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, // 5, -5db
402 {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, // 6, -6db ===> CCK20M default
403 {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, // 7, -7db
404 {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, // 8, -8db
405 {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, // 9, -9db
406 {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 10, -10db
407 {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01} // 11, -11db
410 static const u8 CCKSwingTable_Ch14[CCK_Table_length][8] = {
411 {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, // 0, +0db ===> CCK40M default
412 {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, // 1, -1db
413 {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, // 2, -2db
414 {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, // 3, -3db
415 {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, // 4, -4db
416 {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, // 5, -5db
417 {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 6, -6db ===> CCK20M default
418 {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 7, -7db
419 {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 8, -8db
420 {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 9, -9db
421 {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 10, -10db
422 {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00} // 11, -11db
425 #define Pw_Track_Flag 0x11d
426 #define Tssi_Mea_Value 0x13c
427 #define Tssi_Report_Value1 0x134
428 #define Tssi_Report_Value2 0x13e
429 #define FW_Busy_Flag 0x13f
430 static void dm_TXPowerTrackingCallback_TSSI(struct r8192_priv *priv)
432 struct net_device *dev = priv->ieee80211->dev;
433 bool bHighpowerstate, viviflag = FALSE;
435 u8 powerlevelOFDM24G;
436 int i =0, j = 0, k = 0;
437 u8 RF_Type, tmp_report[5]={0, 0, 0, 0, 0};
440 u16 Avg_TSSI_Meas, TSSI_13dBm, Avg_TSSI_Meas_from_driver=0;
441 // bool rtStatus = true;
443 RT_TRACE(COMP_POWER_TRACKING,"%s()\n",__FUNCTION__);
444 // write_nic_byte(priv, 0x1ba, 0);
445 write_nic_byte(priv, Pw_Track_Flag, 0);
446 write_nic_byte(priv, FW_Busy_Flag, 0);
447 priv->ieee80211->bdynamic_txpower_enable = false;
448 bHighpowerstate = priv->bDynamicTxHighPower;
450 powerlevelOFDM24G = (u8)(priv->Pwr_Track>>24);
451 RF_Type = priv->rf_type;
452 Value = (RF_Type<<8) | powerlevelOFDM24G;
454 RT_TRACE(COMP_POWER_TRACKING, "powerlevelOFDM24G = %x\n", powerlevelOFDM24G);
456 for(j = 0; j<=30; j++)
459 tx_cmd.Op = TXCMD_SET_TX_PWR_TRACKING;
461 tx_cmd.Value = Value;
462 cmpk_message_handle_tx(dev, (u8*)&tx_cmd, DESC_PACKET_TYPE_INIT, sizeof(DCMD_TXCMD_T));
465 for(i = 0;i <= 30; i++)
467 Pwr_Flag = read_nic_byte(priv, Pw_Track_Flag);
475 Avg_TSSI_Meas = read_nic_word(priv, Tssi_Mea_Value);
477 if(Avg_TSSI_Meas == 0)
479 write_nic_byte(priv, Pw_Track_Flag, 0);
480 write_nic_byte(priv, FW_Busy_Flag, 0);
484 for(k = 0;k < 5; k++)
487 tmp_report[k] = read_nic_byte(priv, Tssi_Report_Value1+k);
489 tmp_report[k] = read_nic_byte(priv, Tssi_Report_Value2);
491 RT_TRACE(COMP_POWER_TRACKING, "TSSI_report_value = %d\n", tmp_report[k]);
494 //check if the report value is right
495 for(k = 0;k < 5; k++)
497 if(tmp_report[k] <= 20)
505 write_nic_byte(priv, Pw_Track_Flag, 0);
507 RT_TRACE(COMP_POWER_TRACKING, "we filted this data\n");
508 for(k = 0;k < 5; k++)
513 for(k = 0;k < 5; k++)
515 Avg_TSSI_Meas_from_driver += tmp_report[k];
518 Avg_TSSI_Meas_from_driver = Avg_TSSI_Meas_from_driver*100/5;
519 RT_TRACE(COMP_POWER_TRACKING, "Avg_TSSI_Meas_from_driver = %d\n", Avg_TSSI_Meas_from_driver);
520 TSSI_13dBm = priv->TSSI_13dBm;
521 RT_TRACE(COMP_POWER_TRACKING, "TSSI_13dBm = %d\n", TSSI_13dBm);
523 //if(abs(Avg_TSSI_Meas_from_driver - TSSI_13dBm) <= E_FOR_TX_POWER_TRACK)
524 // For MacOS-compatible
525 if(Avg_TSSI_Meas_from_driver > TSSI_13dBm)
526 delta = Avg_TSSI_Meas_from_driver - TSSI_13dBm;
528 delta = TSSI_13dBm - Avg_TSSI_Meas_from_driver;
530 if(delta <= E_FOR_TX_POWER_TRACK)
532 priv->ieee80211->bdynamic_txpower_enable = TRUE;
533 write_nic_byte(priv, Pw_Track_Flag, 0);
534 write_nic_byte(priv, FW_Busy_Flag, 0);
535 RT_TRACE(COMP_POWER_TRACKING, "tx power track is done\n");
536 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex = %d\n", priv->rfa_txpowertrackingindex);
537 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real = %d\n", priv->rfa_txpowertrackingindex_real);
538 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference = %d\n", priv->CCKPresentAttentuation_difference);
539 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation = %d\n", priv->CCKPresentAttentuation);
544 if(Avg_TSSI_Meas_from_driver < TSSI_13dBm - E_FOR_TX_POWER_TRACK)
546 if (RF_Type == RF_2T4R)
549 if((priv->rfa_txpowertrackingindex > 0) &&(priv->rfc_txpowertrackingindex > 0))
551 priv->rfa_txpowertrackingindex--;
552 if(priv->rfa_txpowertrackingindex_real > 4)
554 priv->rfa_txpowertrackingindex_real--;
555 rtl8192_setBBreg(priv, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex_real].txbbgain_value);
558 priv->rfc_txpowertrackingindex--;
559 if(priv->rfc_txpowertrackingindex_real > 4)
561 priv->rfc_txpowertrackingindex_real--;
562 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex_real].txbbgain_value);
567 rtl8192_setBBreg(priv, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[4].txbbgain_value);
568 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[4].txbbgain_value);
573 if(priv->rfc_txpowertrackingindex > 0)
575 priv->rfc_txpowertrackingindex--;
576 if(priv->rfc_txpowertrackingindex_real > 4)
578 priv->rfc_txpowertrackingindex_real--;
579 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex_real].txbbgain_value);
583 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[4].txbbgain_value);
588 if (RF_Type == RF_2T4R)
590 if((priv->rfa_txpowertrackingindex < TxBBGainTableLength - 1) &&(priv->rfc_txpowertrackingindex < TxBBGainTableLength - 1))
592 priv->rfa_txpowertrackingindex++;
593 priv->rfa_txpowertrackingindex_real++;
594 rtl8192_setBBreg(priv, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex_real].txbbgain_value);
595 priv->rfc_txpowertrackingindex++;
596 priv->rfc_txpowertrackingindex_real++;
597 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex_real].txbbgain_value);
601 rtl8192_setBBreg(priv, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[TxBBGainTableLength - 1].txbbgain_value);
602 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[TxBBGainTableLength - 1].txbbgain_value);
607 if(priv->rfc_txpowertrackingindex < (TxBBGainTableLength - 1))
609 priv->rfc_txpowertrackingindex++;
610 priv->rfc_txpowertrackingindex_real++;
611 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex_real].txbbgain_value);
614 rtl8192_setBBreg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[TxBBGainTableLength - 1].txbbgain_value);
617 if (RF_Type == RF_2T4R)
618 priv->CCKPresentAttentuation_difference
619 = priv->rfa_txpowertrackingindex - priv->rfa_txpowertracking_default;
621 priv->CCKPresentAttentuation_difference
622 = priv->rfc_txpowertrackingindex - priv->rfc_txpowertracking_default;
624 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
625 priv->CCKPresentAttentuation
626 = priv->CCKPresentAttentuation_20Mdefault + priv->CCKPresentAttentuation_difference;
628 priv->CCKPresentAttentuation
629 = priv->CCKPresentAttentuation_40Mdefault + priv->CCKPresentAttentuation_difference;
631 if(priv->CCKPresentAttentuation > (CCKTxBBGainTableLength-1))
632 priv->CCKPresentAttentuation = CCKTxBBGainTableLength-1;
633 if(priv->CCKPresentAttentuation < 0)
634 priv->CCKPresentAttentuation = 0;
638 if(priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14)
640 priv->bcck_in_ch14 = TRUE;
641 dm_cck_txpower_adjust(priv, priv->bcck_in_ch14);
643 else if(priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14)
645 priv->bcck_in_ch14 = FALSE;
646 dm_cck_txpower_adjust(priv, priv->bcck_in_ch14);
649 dm_cck_txpower_adjust(priv, priv->bcck_in_ch14);
651 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex = %d\n", priv->rfa_txpowertrackingindex);
652 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real = %d\n", priv->rfa_txpowertrackingindex_real);
653 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference = %d\n", priv->CCKPresentAttentuation_difference);
654 RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation = %d\n", priv->CCKPresentAttentuation);
656 if (priv->CCKPresentAttentuation_difference <= -12||priv->CCKPresentAttentuation_difference >= 24)
658 priv->ieee80211->bdynamic_txpower_enable = TRUE;
659 write_nic_byte(priv, Pw_Track_Flag, 0);
660 write_nic_byte(priv, FW_Busy_Flag, 0);
661 RT_TRACE(COMP_POWER_TRACKING, "tx power track--->limited\n");
667 write_nic_byte(priv, Pw_Track_Flag, 0);
668 Avg_TSSI_Meas_from_driver = 0;
669 for(k = 0;k < 5; k++)
673 write_nic_byte(priv, FW_Busy_Flag, 0);
675 priv->ieee80211->bdynamic_txpower_enable = TRUE;
676 write_nic_byte(priv, Pw_Track_Flag, 0);
679 static void dm_TXPowerTrackingCallback_ThermalMeter(struct r8192_priv *priv)
681 #define ThermalMeterVal 9
682 u32 tmpRegA, TempCCk;
683 u8 tmpOFDMindex, tmpCCKindex, tmpCCK20Mindex, tmpCCK40Mindex, tmpval;
684 int i =0, CCKSwingNeedUpdate=0;
686 if(!priv->btxpower_trackingInit)
688 //Query OFDM default setting
689 tmpRegA = rtl8192_QueryBBReg(priv, rOFDM0_XATxIQImbalance, bMaskDWord);
690 for(i=0; i<OFDM_Table_Length; i++) //find the index
692 if(tmpRegA == OFDMSwingTable[i])
694 priv->OFDM_index= (u8)i;
695 RT_TRACE(COMP_POWER_TRACKING, "Initial reg0x%x = 0x%x, OFDM_index=0x%x\n",
696 rOFDM0_XATxIQImbalance, tmpRegA, priv->OFDM_index);
700 //Query CCK default setting From 0xa22
701 TempCCk = rtl8192_QueryBBReg(priv, rCCK0_TxFilter1, bMaskByte2);
702 for(i=0 ; i<CCK_Table_length ; i++)
704 if(TempCCk == (u32)CCKSwingTable_Ch1_Ch13[i][0])
706 priv->CCK_index =(u8) i;
707 RT_TRACE(COMP_POWER_TRACKING, "Initial reg0x%x = 0x%x, CCK_index=0x%x\n",
708 rCCK0_TxFilter1, TempCCk, priv->CCK_index);
712 priv->btxpower_trackingInit = TRUE;
713 //pHalData->TXPowercount = 0;
717 // read and filter out unreasonable value
718 tmpRegA = rtl8192_phy_QueryRFReg(priv, RF90_PATH_A, 0x12, 0x078); // 0x12: RF Reg[10:7]
719 RT_TRACE(COMP_POWER_TRACKING, "Readback ThermalMeterA = %d\n", tmpRegA);
720 if(tmpRegA < 3 || tmpRegA > 13)
722 if(tmpRegA >= 12) // if over 12, TP will be bad when high temperature
724 RT_TRACE(COMP_POWER_TRACKING, "Valid ThermalMeterA = %d\n", tmpRegA);
725 priv->ThermalMeter[0] = ThermalMeterVal; //We use fixed value by Bryant's suggestion
726 priv->ThermalMeter[1] = ThermalMeterVal; //We use fixed value by Bryant's suggestion
728 //Get current RF-A temperature index
729 if(priv->ThermalMeter[0] >= (u8)tmpRegA) //lower temperature
731 tmpOFDMindex = tmpCCK20Mindex = 6+(priv->ThermalMeter[0]-(u8)tmpRegA);
732 tmpCCK40Mindex = tmpCCK20Mindex - 6;
733 if(tmpOFDMindex >= OFDM_Table_Length)
734 tmpOFDMindex = OFDM_Table_Length-1;
735 if(tmpCCK20Mindex >= CCK_Table_length)
736 tmpCCK20Mindex = CCK_Table_length-1;
737 if(tmpCCK40Mindex >= CCK_Table_length)
738 tmpCCK40Mindex = CCK_Table_length-1;
742 tmpval = ((u8)tmpRegA - priv->ThermalMeter[0]);
743 if(tmpval >= 6) // higher temperature
744 tmpOFDMindex = tmpCCK20Mindex = 0; // max to +6dB
746 tmpOFDMindex = tmpCCK20Mindex = 6 - tmpval;
750 if(priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) //40M
751 tmpCCKindex = tmpCCK40Mindex;
753 tmpCCKindex = tmpCCK20Mindex;
755 //record for bandwidth swith
756 priv->Record_CCK_20Mindex = tmpCCK20Mindex;
757 priv->Record_CCK_40Mindex = tmpCCK40Mindex;
758 RT_TRACE(COMP_POWER_TRACKING, "Record_CCK_20Mindex / Record_CCK_40Mindex = %d / %d.\n",
759 priv->Record_CCK_20Mindex, priv->Record_CCK_40Mindex);
761 if(priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14)
763 priv->bcck_in_ch14 = TRUE;
764 CCKSwingNeedUpdate = 1;
766 else if(priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14)
768 priv->bcck_in_ch14 = FALSE;
769 CCKSwingNeedUpdate = 1;
772 if(priv->CCK_index != tmpCCKindex)
774 priv->CCK_index = tmpCCKindex;
775 CCKSwingNeedUpdate = 1;
778 if(CCKSwingNeedUpdate)
780 dm_cck_txpower_adjust(priv, priv->bcck_in_ch14);
782 if(priv->OFDM_index != tmpOFDMindex)
784 priv->OFDM_index = tmpOFDMindex;
785 rtl8192_setBBreg(priv, rOFDM0_XATxIQImbalance, bMaskDWord, OFDMSwingTable[priv->OFDM_index]);
786 RT_TRACE(COMP_POWER_TRACKING, "Update OFDMSwing[%d] = 0x%x\n",
787 priv->OFDM_index, OFDMSwingTable[priv->OFDM_index]);
789 priv->txpower_count = 0;
792 void dm_txpower_trackingcallback(struct work_struct *work)
794 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
795 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,txpower_tracking_wq);
797 if(priv->IC_Cut >= IC_VersionCut_D)
798 dm_TXPowerTrackingCallback_TSSI(priv);
800 dm_TXPowerTrackingCallback_ThermalMeter(priv);
804 static const txbbgain_struct rtl8192_txbbgain_table[] = {
845 * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
846 * This Table is for CH1~CH13
848 static const ccktxbbgain_struct rtl8192_cck_txbbgain_table[] = {
849 {{ 0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04 }},
850 {{ 0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04 }},
851 {{ 0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03 }},
852 {{ 0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03 }},
853 {{ 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03 }},
854 {{ 0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03 }},
855 {{ 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03 }},
856 {{ 0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03 }},
857 {{ 0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02 }},
858 {{ 0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02 }},
859 {{ 0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02 }},
860 {{ 0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02 }},
861 {{ 0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02 }},
862 {{ 0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02 }},
863 {{ 0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02 }},
864 {{ 0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02 }},
865 {{ 0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01 }},
866 {{ 0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02 }},
867 {{ 0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01 }},
868 {{ 0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01 }},
869 {{ 0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01 }},
870 {{ 0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01 }},
871 {{ 0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01 }},
875 * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
876 * This Table is for CH14
878 static const ccktxbbgain_struct rtl8192_cck_txbbgain_ch14_table[] = {
879 {{ 0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00 }},
880 {{ 0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00 }},
881 {{ 0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00 }},
882 {{ 0x2d, 0x2d, 0x27, 0x17, 0x00, 0x00, 0x00, 0x00 }},
883 {{ 0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00 }},
884 {{ 0x28, 0x28, 0x22, 0x14, 0x00, 0x00, 0x00, 0x00 }},
885 {{ 0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00 }},
886 {{ 0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00 }},
887 {{ 0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00 }},
888 {{ 0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00 }},
889 {{ 0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00 }},
890 {{ 0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00 }},
891 {{ 0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00 }},
892 {{ 0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00 }},
893 {{ 0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00 }},
894 {{ 0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00 }},
895 {{ 0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00 }},
896 {{ 0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00 }},
897 {{ 0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00 }},
898 {{ 0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00 }},
899 {{ 0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00 }},
900 {{ 0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00 }},
901 {{ 0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00 }},
904 static void dm_InitializeTXPowerTracking_TSSI(struct r8192_priv *priv)
906 priv->txbbgain_table = rtl8192_txbbgain_table;
907 priv->cck_txbbgain_table = rtl8192_cck_txbbgain_table;
908 priv->cck_txbbgain_ch14_table = rtl8192_cck_txbbgain_ch14_table;
910 priv->btxpower_tracking = TRUE;
911 priv->txpower_count = 0;
912 priv->btxpower_trackingInit = FALSE;
916 static void dm_InitializeTXPowerTracking_ThermalMeter(struct r8192_priv *priv)
918 // Tx Power tracking by Theremal Meter require Firmware R/W 3-wire. This mechanism
919 // can be enabled only when Firmware R/W 3-wire is enabled. Otherwise, frequent r/w
920 // 3-wire by driver cause RF goes into wrong state.
921 if(priv->ieee80211->FwRWRF)
922 priv->btxpower_tracking = TRUE;
924 priv->btxpower_tracking = FALSE;
925 priv->txpower_count = 0;
926 priv->btxpower_trackingInit = FALSE;
929 void dm_initialize_txpower_tracking(struct r8192_priv *priv)
931 if(priv->IC_Cut >= IC_VersionCut_D)
932 dm_InitializeTXPowerTracking_TSSI(priv);
934 dm_InitializeTXPowerTracking_ThermalMeter(priv);
938 static void dm_CheckTXPowerTracking_TSSI(struct r8192_priv *priv)
940 static u32 tx_power_track_counter = 0;
941 RT_TRACE(COMP_POWER_TRACKING,"%s()\n",__FUNCTION__);
942 if(read_nic_byte(priv, 0x11e) ==1)
944 if(!priv->btxpower_tracking)
946 tx_power_track_counter++;
948 if (tx_power_track_counter > 90) {
949 queue_delayed_work(priv->priv_wq,&priv->txpower_tracking_wq,0);
950 tx_power_track_counter =0;
954 static void dm_CheckTXPowerTracking_ThermalMeter(struct r8192_priv *priv)
956 static u8 TM_Trigger=0;
958 if(!priv->btxpower_tracking)
962 if(priv->txpower_count <= 2)
964 priv->txpower_count++;
971 //Attention!! You have to wirte all 12bits data to RF, or it may cause RF to crash
972 //actually write reg0x02 bit1=0, then bit1=1.
973 rtl8192_phy_SetRFReg(priv, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
974 rtl8192_phy_SetRFReg(priv, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
975 rtl8192_phy_SetRFReg(priv, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
976 rtl8192_phy_SetRFReg(priv, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
981 queue_delayed_work(priv->priv_wq,&priv->txpower_tracking_wq,0);
986 static void dm_check_txpower_tracking(struct r8192_priv *priv)
988 if(priv->IC_Cut >= IC_VersionCut_D)
989 dm_CheckTXPowerTracking_TSSI(priv);
991 dm_CheckTXPowerTracking_ThermalMeter(priv);
995 static void dm_CCKTxPowerAdjust_TSSI(struct r8192_priv *priv, bool bInCH14)
1002 TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[0] +
1003 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
1005 rtl8192_setBBreg(priv, rCCK0_TxFilter1, bMaskHWord, TempVal);
1006 //Write 0xa24 ~ 0xa27
1008 TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
1009 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
1010 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16 )+
1011 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
1012 rtl8192_setBBreg(priv, rCCK0_TxFilter2, bMaskDWord, TempVal);
1015 TempVal = (u32)(priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
1016 (priv->cck_txbbgain_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
1018 rtl8192_setBBreg(priv, rCCK0_DebugPort, bMaskLWord, TempVal);
1022 TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[0] +
1023 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[1]<<8)) ;
1025 rtl8192_setBBreg(priv, rCCK0_TxFilter1, bMaskHWord, TempVal);
1026 //Write 0xa24 ~ 0xa27
1028 TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[2] +
1029 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[3]<<8) +
1030 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[4]<<16 )+
1031 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[5]<<24));
1032 rtl8192_setBBreg(priv, rCCK0_TxFilter2, bMaskDWord, TempVal);
1035 TempVal = (u32)(priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[6] +
1036 (priv->cck_txbbgain_ch14_table[(u8)(priv->CCKPresentAttentuation)].ccktxbb_valuearray[7]<<8)) ;
1038 rtl8192_setBBreg(priv, rCCK0_DebugPort, bMaskLWord, TempVal);
1044 static void dm_CCKTxPowerAdjust_ThermalMeter(struct r8192_priv *priv,
1053 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] +
1054 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1]<<8) ;
1055 rtl8192_setBBreg(priv, rCCK0_TxFilter1, bMaskHWord, TempVal);
1056 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1057 rCCK0_TxFilter1, TempVal);
1058 //Write 0xa24 ~ 0xa27
1060 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] +
1061 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) +
1062 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16 )+
1063 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5]<<24);
1064 rtl8192_setBBreg(priv, rCCK0_TxFilter2, bMaskDWord, TempVal);
1065 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1066 rCCK0_TxFilter2, TempVal);
1069 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] +
1070 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ;
1072 rtl8192_setBBreg(priv, rCCK0_DebugPort, bMaskLWord, TempVal);
1073 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1074 rCCK0_DebugPort, TempVal);
1078 // priv->CCKTxPowerAdjustCntNotCh14++; //cosa add for debug.
1080 TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] +
1081 (CCKSwingTable_Ch14[priv->CCK_index][1]<<8) ;
1083 rtl8192_setBBreg(priv, rCCK0_TxFilter1, bMaskHWord, TempVal);
1084 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1085 rCCK0_TxFilter1, TempVal);
1086 //Write 0xa24 ~ 0xa27
1088 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] +
1089 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) +
1090 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16 )+
1091 (CCKSwingTable_Ch14[priv->CCK_index][5]<<24);
1092 rtl8192_setBBreg(priv, rCCK0_TxFilter2, bMaskDWord, TempVal);
1093 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1094 rCCK0_TxFilter2, TempVal);
1097 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] +
1098 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ;
1100 rtl8192_setBBreg(priv, rCCK0_DebugPort, bMaskLWord, TempVal);
1101 RT_TRACE(COMP_POWER_TRACKING,"CCK chnl 14, reg 0x%x = 0x%x\n",
1102 rCCK0_DebugPort, TempVal);
1106 void dm_cck_txpower_adjust(struct r8192_priv *priv, bool binch14)
1108 if(priv->IC_Cut >= IC_VersionCut_D)
1109 dm_CCKTxPowerAdjust_TSSI(priv, binch14);
1111 dm_CCKTxPowerAdjust_ThermalMeter(priv, binch14);
1114 /* Set DIG scheme init value. */
1115 static void dm_dig_init(struct r8192_priv *priv)
1117 /* 2007/10/05 MH Disable DIG scheme now. Not tested. */
1118 dm_digtable.dig_enable_flag = true;
1119 dm_digtable.dig_algorithm = DIG_ALGO_BY_RSSI;
1120 dm_digtable.dbg_mode = DM_DBG_OFF; //off=by real rssi value, on=by DM_DigTable.Rssi_val for new dig
1121 dm_digtable.dig_algorithm_switch = 0;
1123 /* 2007/10/04 MH Define init gain threshold. */
1124 dm_digtable.dig_state = DM_STA_DIG_MAX;
1125 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
1126 dm_digtable.initialgain_lowerbound_state = false;
1128 dm_digtable.rssi_low_thresh = DM_DIG_THRESH_LOW;
1129 dm_digtable.rssi_high_thresh = DM_DIG_THRESH_HIGH;
1131 dm_digtable.rssi_high_power_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW;
1132 dm_digtable.rssi_high_power_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH;
1134 dm_digtable.rssi_val = 50; //for new dig debug rssi value
1135 dm_digtable.backoff_val = DM_DIG_BACKOFF;
1136 dm_digtable.rx_gain_range_max = DM_DIG_MAX;
1137 if(priv->CustomerID == RT_CID_819x_Netcore)
1138 dm_digtable.rx_gain_range_min = DM_DIG_MIN_Netcore;
1140 dm_digtable.rx_gain_range_min = DM_DIG_MIN;
1146 * Driver must monitor RSSI and notify firmware to change initial
1147 * gain according to different threshold. BB team provide the
1148 * suggested solution.
1150 static void dm_ctrl_initgain_byrssi(struct r8192_priv *priv)
1152 if (dm_digtable.dig_enable_flag == false)
1155 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
1156 dm_ctrl_initgain_byrssi_by_fwfalse_alarm(priv);
1157 else if(dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
1158 dm_ctrl_initgain_byrssi_by_driverrssi(priv);
1162 static void dm_ctrl_initgain_byrssi_by_driverrssi(struct r8192_priv *priv)
1167 if (dm_digtable.dig_enable_flag == false)
1170 if(dm_digtable.dig_algorithm_switch) // if swithed algorithm, we have to disable FW Dig.
1172 if(fw_dig <= 3) // execute several times to make sure the FW Dig is disabled
1175 rtl8192_setBBreg(priv, UFWP, bMaskByte1, 0x8); // Only clear byte 1 and rewrite.
1177 dm_digtable.dig_state = DM_STA_DIG_OFF; //fw dig off.
1180 if(priv->ieee80211->state == IEEE80211_LINKED)
1181 dm_digtable.cur_connect_state = DIG_CONNECT;
1183 dm_digtable.cur_connect_state = DIG_DISCONNECT;
1185 if(dm_digtable.dbg_mode == DM_DBG_OFF)
1186 dm_digtable.rssi_val = priv->undecorated_smoothed_pwdb;
1188 dm_initial_gain(priv);
1191 if(dm_digtable.dig_algorithm_switch)
1192 dm_digtable.dig_algorithm_switch = 0;
1193 dm_digtable.pre_connect_state = dm_digtable.cur_connect_state;
1197 static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(struct r8192_priv *priv)
1199 static u32 reset_cnt = 0;
1202 if (dm_digtable.dig_enable_flag == false)
1205 if(dm_digtable.dig_algorithm_switch)
1207 dm_digtable.dig_state = DM_STA_DIG_MAX;
1210 rtl8192_setBBreg(priv, UFWP, bMaskByte1, 0x1); // Only clear byte 1 and rewrite.
1211 dm_digtable.dig_algorithm_switch = 0;
1214 if (priv->ieee80211->state != IEEE80211_LINKED)
1217 // For smooth, we can not change DIG state.
1218 if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_low_thresh) &&
1219 (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_thresh))
1224 /* 1. When RSSI decrease, We have to judge if it is smaller than a threshold
1225 and then execute below step. */
1226 if ((priv->undecorated_smoothed_pwdb <= dm_digtable.rssi_low_thresh))
1228 /* 2008/02/05 MH When we execute silent reset, the DIG PHY parameters
1229 will be reset to init value. We must prevent the condition. */
1230 if (dm_digtable.dig_state == DM_STA_DIG_OFF &&
1231 (priv->reset_count == reset_cnt))
1237 reset_cnt = priv->reset_count;
1240 // If DIG is off, DIG high power state must reset.
1241 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
1242 dm_digtable.dig_state = DM_STA_DIG_OFF;
1245 rtl8192_setBBreg(priv, UFWP, bMaskByte1, 0x8); // Only clear byte 1 and rewrite.
1247 // 1.2 Set initial gain.
1248 write_nic_byte(priv, rOFDM0_XAAGCCore1, 0x17);
1249 write_nic_byte(priv, rOFDM0_XBAGCCore1, 0x17);
1250 write_nic_byte(priv, rOFDM0_XCAGCCore1, 0x17);
1251 write_nic_byte(priv, rOFDM0_XDAGCCore1, 0x17);
1253 // 1.3 Lower PD_TH for OFDM.
1254 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1256 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1257 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1258 write_nic_byte(priv, (rOFDM0_XATxAFE+3), 0x00);
1261 write_nic_byte(priv, rOFDM0_RxDetector1, 0x42);
1263 // 1.4 Lower CS ratio for CCK.
1264 write_nic_byte(priv, 0xa0a, 0x08);
1266 // 1.5 Higher EDCCA.
1267 //PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x325);
1272 /* 2. When RSSI increase, We have to judge if it is larger than a threshold
1273 and then execute below step. */
1274 if ((priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh) )
1278 if (dm_digtable.dig_state == DM_STA_DIG_ON &&
1279 (priv->reset_count == reset_cnt))
1281 dm_ctrl_initgain_byrssi_highpwr(priv);
1286 if (priv->reset_count != reset_cnt)
1289 reset_cnt = priv->reset_count;
1292 dm_digtable.dig_state = DM_STA_DIG_ON;
1294 // 2.1 Set initial gain.
1295 // 2008/02/26 MH SD3-Jerry suggest to prevent dirty environment.
1296 if (reset_flag == 1)
1298 write_nic_byte(priv, rOFDM0_XAAGCCore1, 0x2c);
1299 write_nic_byte(priv, rOFDM0_XBAGCCore1, 0x2c);
1300 write_nic_byte(priv, rOFDM0_XCAGCCore1, 0x2c);
1301 write_nic_byte(priv, rOFDM0_XDAGCCore1, 0x2c);
1305 write_nic_byte(priv, rOFDM0_XAAGCCore1, 0x20);
1306 write_nic_byte(priv, rOFDM0_XBAGCCore1, 0x20);
1307 write_nic_byte(priv, rOFDM0_XCAGCCore1, 0x20);
1308 write_nic_byte(priv, rOFDM0_XDAGCCore1, 0x20);
1311 // 2.2 Higher PD_TH for OFDM.
1312 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1314 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1315 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1316 write_nic_byte(priv, (rOFDM0_XATxAFE+3), 0x20);
1319 write_nic_byte(priv, rOFDM0_RxDetector1, 0x44);
1321 // 2.3 Higher CS ratio for CCK.
1322 write_nic_byte(priv, 0xa0a, 0xcd);
1325 /* 2008/01/11 MH 90/92 series are the same. */
1326 //PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x346);
1329 rtl8192_setBBreg(priv, UFWP, bMaskByte1, 0x1); // Only clear byte 1 and rewrite.
1333 dm_ctrl_initgain_byrssi_highpwr(priv);
1337 static void dm_ctrl_initgain_byrssi_highpwr(struct r8192_priv *priv)
1339 static u32 reset_cnt_highpwr = 0;
1341 // For smooth, we can not change high power DIG state in the range.
1342 if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_high_power_lowthresh) &&
1343 (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_power_highthresh))
1348 /* 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if
1349 it is larger than a threshold and then execute below step. */
1350 // 2008/02/05 MH SD3-Jerry Modify PD_TH for high power issue.
1351 if (priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_power_highthresh)
1353 if (dm_digtable.dig_highpwr_state == DM_STA_DIG_ON &&
1354 (priv->reset_count == reset_cnt_highpwr))
1357 dm_digtable.dig_highpwr_state = DM_STA_DIG_ON;
1359 // 3.1 Higher PD_TH for OFDM for high power state.
1360 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1362 write_nic_byte(priv, (rOFDM0_XATxAFE+3), 0x10);
1365 write_nic_byte(priv, rOFDM0_RxDetector1, 0x43);
1369 if (dm_digtable.dig_highpwr_state == DM_STA_DIG_OFF&&
1370 (priv->reset_count == reset_cnt_highpwr))
1373 dm_digtable.dig_highpwr_state = DM_STA_DIG_OFF;
1375 if (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_power_lowthresh &&
1376 priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh)
1378 // 3.2 Recover PD_TH for OFDM for normal power region.
1379 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1381 write_nic_byte(priv, (rOFDM0_XATxAFE+3), 0x20);
1384 write_nic_byte(priv, rOFDM0_RxDetector1, 0x44);
1388 reset_cnt_highpwr = priv->reset_count;
1393 static void dm_initial_gain(struct r8192_priv *priv)
1396 static u8 initialized=0, force_write=0;
1397 static u32 reset_cnt=0;
1399 if(dm_digtable.dig_algorithm_switch)
1405 if(dm_digtable.pre_connect_state == dm_digtable.cur_connect_state)
1407 if(dm_digtable.cur_connect_state == DIG_CONNECT)
1409 if((dm_digtable.rssi_val+10-dm_digtable.backoff_val) > dm_digtable.rx_gain_range_max)
1410 dm_digtable.cur_ig_value = dm_digtable.rx_gain_range_max;
1411 else if((dm_digtable.rssi_val+10-dm_digtable.backoff_val) < dm_digtable.rx_gain_range_min)
1412 dm_digtable.cur_ig_value = dm_digtable.rx_gain_range_min;
1414 dm_digtable.cur_ig_value = dm_digtable.rssi_val+10-dm_digtable.backoff_val;
1416 else //current state is disconnected
1418 if(dm_digtable.cur_ig_value == 0)
1419 dm_digtable.cur_ig_value = priv->DefaultInitialGain[0];
1421 dm_digtable.cur_ig_value = dm_digtable.pre_ig_value;
1424 else // disconnected -> connected or connected -> disconnected
1426 dm_digtable.cur_ig_value = priv->DefaultInitialGain[0];
1427 dm_digtable.pre_ig_value = 0;
1430 // if silent reset happened, we should rewrite the values back
1431 if(priv->reset_count != reset_cnt)
1434 reset_cnt = priv->reset_count;
1437 if(dm_digtable.pre_ig_value != read_nic_byte(priv, rOFDM0_XAAGCCore1))
1441 if((dm_digtable.pre_ig_value != dm_digtable.cur_ig_value)
1442 || !initialized || force_write)
1444 initial_gain = (u8)dm_digtable.cur_ig_value;
1445 // Set initial gain.
1446 write_nic_byte(priv, rOFDM0_XAAGCCore1, initial_gain);
1447 write_nic_byte(priv, rOFDM0_XBAGCCore1, initial_gain);
1448 write_nic_byte(priv, rOFDM0_XCAGCCore1, initial_gain);
1449 write_nic_byte(priv, rOFDM0_XDAGCCore1, initial_gain);
1450 dm_digtable.pre_ig_value = dm_digtable.cur_ig_value;
1457 static void dm_pd_th(struct r8192_priv *priv)
1459 static u8 initialized=0, force_write=0;
1460 static u32 reset_cnt = 0;
1462 if(dm_digtable.dig_algorithm_switch)
1468 if(dm_digtable.pre_connect_state == dm_digtable.cur_connect_state)
1470 if(dm_digtable.cur_connect_state == DIG_CONNECT)
1472 if (dm_digtable.rssi_val >= dm_digtable.rssi_high_power_highthresh)
1473 dm_digtable.curpd_thstate = DIG_PD_AT_HIGH_POWER;
1474 else if ((dm_digtable.rssi_val <= dm_digtable.rssi_low_thresh))
1475 dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
1476 else if ((dm_digtable.rssi_val >= dm_digtable.rssi_high_thresh) &&
1477 (dm_digtable.rssi_val < dm_digtable.rssi_high_power_lowthresh))
1478 dm_digtable.curpd_thstate = DIG_PD_AT_NORMAL_POWER;
1480 dm_digtable.curpd_thstate = dm_digtable.prepd_thstate;
1484 dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
1487 else // disconnected -> connected or connected -> disconnected
1489 dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
1492 // if silent reset happened, we should rewrite the values back
1493 if(priv->reset_count != reset_cnt)
1496 reset_cnt = priv->reset_count;
1500 if((dm_digtable.prepd_thstate != dm_digtable.curpd_thstate) ||
1501 (initialized<=3) || force_write)
1503 if(dm_digtable.curpd_thstate == DIG_PD_AT_LOW_POWER)
1505 // Lower PD_TH for OFDM.
1506 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1508 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1509 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1510 write_nic_byte(priv, (rOFDM0_XATxAFE+3), 0x00);
1513 write_nic_byte(priv, rOFDM0_RxDetector1, 0x42);
1515 else if(dm_digtable.curpd_thstate == DIG_PD_AT_NORMAL_POWER)
1517 // Higher PD_TH for OFDM.
1518 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1520 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1521 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1522 write_nic_byte(priv, (rOFDM0_XATxAFE+3), 0x20);
1525 write_nic_byte(priv, rOFDM0_RxDetector1, 0x44);
1527 else if(dm_digtable.curpd_thstate == DIG_PD_AT_HIGH_POWER)
1529 // Higher PD_TH for OFDM for high power state.
1530 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
1532 write_nic_byte(priv, (rOFDM0_XATxAFE+3), 0x10);
1535 write_nic_byte(priv, rOFDM0_RxDetector1, 0x43);
1537 dm_digtable.prepd_thstate = dm_digtable.curpd_thstate;
1538 if(initialized <= 3)
1545 static void dm_cs_ratio(struct r8192_priv *priv)
1547 static u8 initialized=0,force_write=0;
1548 static u32 reset_cnt = 0;
1550 if(dm_digtable.dig_algorithm_switch)
1556 if(dm_digtable.pre_connect_state == dm_digtable.cur_connect_state)
1558 if(dm_digtable.cur_connect_state == DIG_CONNECT)
1560 if ((dm_digtable.rssi_val <= dm_digtable.rssi_low_thresh))
1561 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
1562 else if ((dm_digtable.rssi_val >= dm_digtable.rssi_high_thresh) )
1563 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_HIGHER;
1565 dm_digtable.curcs_ratio_state = dm_digtable.precs_ratio_state;
1569 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
1572 else // disconnected -> connected or connected -> disconnected
1574 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
1577 // if silent reset happened, we should rewrite the values back
1578 if(priv->reset_count != reset_cnt)
1581 reset_cnt = priv->reset_count;
1585 if((dm_digtable.precs_ratio_state != dm_digtable.curcs_ratio_state) ||
1586 !initialized || force_write)
1588 if(dm_digtable.curcs_ratio_state == DIG_CS_RATIO_LOWER)
1590 // Lower CS ratio for CCK.
1591 write_nic_byte(priv, 0xa0a, 0x08);
1593 else if(dm_digtable.curcs_ratio_state == DIG_CS_RATIO_HIGHER)
1595 // Higher CS ratio for CCK.
1596 write_nic_byte(priv, 0xa0a, 0xcd);
1598 dm_digtable.precs_ratio_state = dm_digtable.curcs_ratio_state;
1604 void dm_init_edca_turbo(struct r8192_priv *priv)
1607 priv->bcurrent_turbo_EDCA = false;
1608 priv->ieee80211->bis_any_nonbepkts = false;
1609 priv->bis_cur_rdlstate = false;
1612 static void dm_check_edca_turbo(struct r8192_priv *priv)
1614 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
1615 //PSTA_QOS pStaQos = pMgntInfo->pStaQos;
1617 // Keep past Tx/Rx packet count for RT-to-RT EDCA turbo.
1618 static unsigned long lastTxOkCnt = 0;
1619 static unsigned long lastRxOkCnt = 0;
1620 unsigned long curTxOkCnt = 0;
1621 unsigned long curRxOkCnt = 0;
1624 // Do not be Turbo if it's under WiFi config and Qos Enabled, because the EDCA parameters
1625 // should follow the settings from QAP. By Bruce, 2007-12-07.
1627 if(priv->ieee80211->state != IEEE80211_LINKED)
1628 goto dm_CheckEdcaTurbo_EXIT;
1629 // We do not turn on EDCA turbo mode for some AP that has IOT issue
1630 if(priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_EDCA_TURBO)
1631 goto dm_CheckEdcaTurbo_EXIT;
1633 // Check the status for current condition.
1634 if(!priv->ieee80211->bis_any_nonbepkts)
1636 curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
1637 curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
1638 // For RT-AP, we needs to turn it on when Rx>Tx
1639 if(curRxOkCnt > 4*curTxOkCnt)
1641 if(!priv->bis_cur_rdlstate || !priv->bcurrent_turbo_EDCA)
1643 write_nic_dword(priv, EDCAPARA_BE, edca_setting_DL[pHTInfo->IOTPeer]);
1644 priv->bis_cur_rdlstate = true;
1649 if(priv->bis_cur_rdlstate || !priv->bcurrent_turbo_EDCA)
1651 write_nic_dword(priv, EDCAPARA_BE, edca_setting_UL[pHTInfo->IOTPeer]);
1652 priv->bis_cur_rdlstate = false;
1657 priv->bcurrent_turbo_EDCA = true;
1662 // Turn Off EDCA turbo here.
1663 // Restore original EDCA according to the declaration of AP.
1665 if(priv->bcurrent_turbo_EDCA)
1671 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
1672 u8 mode = priv->ieee80211->mode;
1674 // For Each time updating EDCA parameter, reset EDCA turbo mode status.
1675 dm_init_edca_turbo(priv);
1676 u1bAIFS = qos_parameters->aifs[0] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
1677 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[0]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
1678 (((u32)(qos_parameters->cw_max[0]))<< AC_PARAM_ECW_MAX_OFFSET)|
1679 (((u32)(qos_parameters->cw_min[0]))<< AC_PARAM_ECW_MIN_OFFSET)|
1680 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
1681 printk("===>u4bAcParam:%x, ", u4bAcParam);
1682 //write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
1683 write_nic_dword(priv, EDCAPARA_BE, u4bAcParam);
1686 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
1688 // TODO: Modified this part and try to set acm control in only 1 IO processing!!
1690 PACI_AIFSN pAciAifsn = (PACI_AIFSN)&(qos_parameters->aifs[0]);
1691 u8 AcmCtrl = read_nic_byte(priv, AcmHwCtrl );
1692 if( pAciAifsn->f.ACM )
1694 AcmCtrl |= AcmHw_BeqEn;
1698 AcmCtrl &= (~AcmHw_BeqEn);
1701 RT_TRACE( COMP_QOS,"SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl ) ;
1702 write_nic_byte(priv, AcmHwCtrl, AcmCtrl );
1705 priv->bcurrent_turbo_EDCA = false;
1710 dm_CheckEdcaTurbo_EXIT:
1711 // Set variables for next time.
1712 priv->ieee80211->bis_any_nonbepkts = false;
1713 lastTxOkCnt = priv->stats.txbytesunicast;
1714 lastRxOkCnt = priv->stats.rxbytesunicast;
1717 static void dm_init_ctstoself(struct r8192_priv *priv)
1719 priv->ieee80211->bCTSToSelfEnable = TRUE;
1720 priv->ieee80211->CTSToSelfTH = CTSToSelfTHVal;
1723 static void dm_ctstoself(struct r8192_priv *priv)
1725 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
1726 static unsigned long lastTxOkCnt = 0;
1727 static unsigned long lastRxOkCnt = 0;
1728 unsigned long curTxOkCnt = 0;
1729 unsigned long curRxOkCnt = 0;
1731 if(priv->ieee80211->bCTSToSelfEnable != TRUE)
1733 pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
1738 2. Linksys350/Linksys300N
1739 3. <50 disable, >55 enable
1742 if(pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM)
1744 curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
1745 curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
1746 if(curRxOkCnt > 4*curTxOkCnt) //downlink, disable CTS to self
1748 pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
1752 pHTInfo->IOTAction |= HT_IOT_ACT_FORCED_CTS2SELF;
1755 lastTxOkCnt = priv->stats.txbytesunicast;
1756 lastRxOkCnt = priv->stats.rxbytesunicast;
1762 /* Copy 8187B template for 9xseries */
1763 static void dm_check_rfctrl_gpio(struct r8192_priv *priv)
1766 // Walk around for DTM test, we will not enable HW - radio on/off because r/w
1767 // page 1 register before Lextra bus is enabled cause system fails when resuming
1768 // from S4. 20080218, Emily
1770 // Stop to execute workitem to prevent S3/S4 bug.
1771 queue_delayed_work(priv->priv_wq,&priv->gpio_change_rf_wq,0);
1774 /* PCI will not support workitem call back HW radio on-off control. */
1775 void dm_gpio_change_rf_callback(struct work_struct *work)
1777 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
1778 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,gpio_change_rf_wq);
1780 RT_RF_POWER_STATE eRfPowerStateToSet;
1781 bool bActuallySet = false;
1784 RT_TRACE((COMP_INIT | COMP_POWER | COMP_RF),"dm_gpio_change_rf_callback(): Callback function breaks out!!\n");
1786 // 0x108 GPIO input register is read only
1787 //set 0x108 B1= 1: RF-ON; 0: RF-OFF.
1788 tmp1byte = read_nic_byte(priv, GPI);
1790 eRfPowerStateToSet = (tmp1byte&BIT1) ? eRfOn : eRfOff;
1792 if (priv->bHwRadioOff && (eRfPowerStateToSet == eRfOn)) {
1793 RT_TRACE(COMP_RF, "gpiochangeRF - HW Radio ON\n");
1795 priv->bHwRadioOff = false;
1796 bActuallySet = true;
1797 } else if ((!priv->bHwRadioOff) && (eRfPowerStateToSet == eRfOff)) {
1798 RT_TRACE(COMP_RF, "gpiochangeRF - HW Radio OFF\n");
1799 priv->bHwRadioOff = true;
1800 bActuallySet = true;
1804 priv->bHwRfOffAction = 1;
1805 MgntActSet_RF_State(priv, eRfPowerStateToSet, RF_CHANGE_BY_HW);
1806 //DrvIFIndicateCurrentPhyStatus(pAdapter);
1813 /* Check if Current RF RX path is enabled */
1814 void dm_rf_pathcheck_workitemcallback(struct work_struct *work)
1816 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
1817 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,rfpath_check_wq);
1821 /* 2008/01/30 MH After discussing with SD3 Jerry, 0xc04/0xd04 register will
1822 always be the same. We only read 0xc04 now. */
1823 rfpath = read_nic_byte(priv, 0xc04);
1825 // Check Bit 0-3, it means if RF A-D is enabled.
1826 for (i = 0; i < RF90_PATH_MAX; i++)
1828 if (rfpath & (0x01<<i))
1829 priv->brfpath_rxenable[i] = 1;
1831 priv->brfpath_rxenable[i] = 0;
1833 if(!DM_RxPathSelTable.Enable)
1836 dm_rxpath_sel_byrssi(priv);
1839 static void dm_init_rxpath_selection(struct r8192_priv *priv)
1843 DM_RxPathSelTable.Enable = 1; //default enabled
1844 DM_RxPathSelTable.SS_TH_low = RxPathSelection_SS_TH_low;
1845 DM_RxPathSelTable.diff_TH = RxPathSelection_diff_TH;
1846 if(priv->CustomerID == RT_CID_819x_Netcore)
1847 DM_RxPathSelTable.cck_method = CCK_Rx_Version_2;
1849 DM_RxPathSelTable.cck_method = CCK_Rx_Version_1;
1850 DM_RxPathSelTable.DbgMode = DM_DBG_OFF;
1851 DM_RxPathSelTable.disabledRF = 0;
1854 DM_RxPathSelTable.rf_rssi[i] = 50;
1855 DM_RxPathSelTable.cck_pwdb_sta[i] = -64;
1856 DM_RxPathSelTable.rf_enable_rssi_th[i] = 100;
1860 static void dm_rxpath_sel_byrssi(struct r8192_priv *priv)
1862 u8 i, max_rssi_index=0, min_rssi_index=0, sec_rssi_index=0, rf_num=0;
1863 u8 tmp_max_rssi=0, tmp_min_rssi=0, tmp_sec_rssi=0;
1864 u8 cck_default_Rx=0x2; //RF-C
1865 u8 cck_optional_Rx=0x3;//RF-D
1866 long tmp_cck_max_pwdb=0, tmp_cck_min_pwdb=0, tmp_cck_sec_pwdb=0;
1867 u8 cck_rx_ver2_max_index=0, cck_rx_ver2_min_index=0, cck_rx_ver2_sec_index=0;
1870 static u8 disabled_rf_cnt=0, cck_Rx_Path_initialized=0;
1871 u8 update_cck_rx_path;
1873 if(priv->rf_type != RF_2T4R)
1876 if(!cck_Rx_Path_initialized)
1878 DM_RxPathSelTable.cck_Rx_path = (read_nic_byte(priv, 0xa07)&0xf);
1879 cck_Rx_Path_initialized = 1;
1882 DM_RxPathSelTable.disabledRF = 0xf;
1883 DM_RxPathSelTable.disabledRF &=~ (read_nic_byte(priv, 0xc04));
1885 if(priv->ieee80211->mode == WIRELESS_MODE_B)
1887 DM_RxPathSelTable.cck_method = CCK_Rx_Version_2; //pure B mode, fixed cck version2
1890 //decide max/sec/min rssi index
1891 for (i=0; i<RF90_PATH_MAX; i++)
1893 if(!DM_RxPathSelTable.DbgMode)
1894 DM_RxPathSelTable.rf_rssi[i] = priv->stats.rx_rssi_percentage[i];
1896 if(priv->brfpath_rxenable[i])
1899 cur_rf_rssi = DM_RxPathSelTable.rf_rssi[i];
1901 if(rf_num == 1) // find first enabled rf path and the rssi values
1902 { //initialize, set all rssi index to the same one
1903 max_rssi_index = min_rssi_index = sec_rssi_index = i;
1904 tmp_max_rssi = tmp_min_rssi = tmp_sec_rssi = cur_rf_rssi;
1906 else if(rf_num == 2)
1907 { // we pick up the max index first, and let sec and min to be the same one
1908 if(cur_rf_rssi >= tmp_max_rssi)
1910 tmp_max_rssi = cur_rf_rssi;
1915 tmp_sec_rssi = tmp_min_rssi = cur_rf_rssi;
1916 sec_rssi_index = min_rssi_index = i;
1921 if(cur_rf_rssi > tmp_max_rssi)
1923 tmp_sec_rssi = tmp_max_rssi;
1924 sec_rssi_index = max_rssi_index;
1925 tmp_max_rssi = cur_rf_rssi;
1928 else if(cur_rf_rssi == tmp_max_rssi)
1929 { // let sec and min point to the different index
1930 tmp_sec_rssi = cur_rf_rssi;
1933 else if((cur_rf_rssi < tmp_max_rssi) &&(cur_rf_rssi > tmp_sec_rssi))
1935 tmp_sec_rssi = cur_rf_rssi;
1938 else if(cur_rf_rssi == tmp_sec_rssi)
1940 if(tmp_sec_rssi == tmp_min_rssi)
1941 { // let sec and min point to the different index
1942 tmp_sec_rssi = cur_rf_rssi;
1947 // This case we don't need to set any index
1950 else if((cur_rf_rssi < tmp_sec_rssi) && (cur_rf_rssi > tmp_min_rssi))
1952 // This case we don't need to set any index
1954 else if(cur_rf_rssi == tmp_min_rssi)
1956 if(tmp_sec_rssi == tmp_min_rssi)
1957 { // let sec and min point to the different index
1958 tmp_min_rssi = cur_rf_rssi;
1963 // This case we don't need to set any index
1966 else if(cur_rf_rssi < tmp_min_rssi)
1968 tmp_min_rssi = cur_rf_rssi;
1976 // decide max/sec/min cck pwdb index
1977 if(DM_RxPathSelTable.cck_method == CCK_Rx_Version_2)
1979 for (i=0; i<RF90_PATH_MAX; i++)
1981 if(priv->brfpath_rxenable[i])
1984 cur_cck_pwdb = DM_RxPathSelTable.cck_pwdb_sta[i];
1986 if(rf_num == 1) // find first enabled rf path and the rssi values
1987 { //initialize, set all rssi index to the same one
1988 cck_rx_ver2_max_index = cck_rx_ver2_min_index = cck_rx_ver2_sec_index = i;
1989 tmp_cck_max_pwdb = tmp_cck_min_pwdb = tmp_cck_sec_pwdb = cur_cck_pwdb;
1991 else if(rf_num == 2)
1992 { // we pick up the max index first, and let sec and min to be the same one
1993 if(cur_cck_pwdb >= tmp_cck_max_pwdb)
1995 tmp_cck_max_pwdb = cur_cck_pwdb;
1996 cck_rx_ver2_max_index = i;
2000 tmp_cck_sec_pwdb = tmp_cck_min_pwdb = cur_cck_pwdb;
2001 cck_rx_ver2_sec_index = cck_rx_ver2_min_index = i;
2006 if(cur_cck_pwdb > tmp_cck_max_pwdb)
2008 tmp_cck_sec_pwdb = tmp_cck_max_pwdb;
2009 cck_rx_ver2_sec_index = cck_rx_ver2_max_index;
2010 tmp_cck_max_pwdb = cur_cck_pwdb;
2011 cck_rx_ver2_max_index = i;
2013 else if(cur_cck_pwdb == tmp_cck_max_pwdb)
2014 { // let sec and min point to the different index
2015 tmp_cck_sec_pwdb = cur_cck_pwdb;
2016 cck_rx_ver2_sec_index = i;
2018 else if((cur_cck_pwdb < tmp_cck_max_pwdb) &&(cur_cck_pwdb > tmp_cck_sec_pwdb))
2020 tmp_cck_sec_pwdb = cur_cck_pwdb;
2021 cck_rx_ver2_sec_index = i;
2023 else if(cur_cck_pwdb == tmp_cck_sec_pwdb)
2025 if(tmp_cck_sec_pwdb == tmp_cck_min_pwdb)
2026 { // let sec and min point to the different index
2027 tmp_cck_sec_pwdb = cur_cck_pwdb;
2028 cck_rx_ver2_sec_index = i;
2032 // This case we don't need to set any index
2035 else if((cur_cck_pwdb < tmp_cck_sec_pwdb) && (cur_cck_pwdb > tmp_cck_min_pwdb))
2037 // This case we don't need to set any index
2039 else if(cur_cck_pwdb == tmp_cck_min_pwdb)
2041 if(tmp_cck_sec_pwdb == tmp_cck_min_pwdb)
2042 { // let sec and min point to the different index
2043 tmp_cck_min_pwdb = cur_cck_pwdb;
2044 cck_rx_ver2_min_index = i;
2048 // This case we don't need to set any index
2051 else if(cur_cck_pwdb < tmp_cck_min_pwdb)
2053 tmp_cck_min_pwdb = cur_cck_pwdb;
2054 cck_rx_ver2_min_index = i;
2064 // reg0xA07[3:2]=cck default rx path, reg0xa07[1:0]=cck optional rx path.
2065 update_cck_rx_path = 0;
2066 if(DM_RxPathSelTable.cck_method == CCK_Rx_Version_2)
2068 cck_default_Rx = cck_rx_ver2_max_index;
2069 cck_optional_Rx = cck_rx_ver2_sec_index;
2070 if(tmp_cck_max_pwdb != -64)
2071 update_cck_rx_path = 1;
2074 if(tmp_min_rssi < DM_RxPathSelTable.SS_TH_low && disabled_rf_cnt < 2)
2076 if((tmp_max_rssi - tmp_min_rssi) >= DM_RxPathSelTable.diff_TH)
2078 //record the enabled rssi threshold
2079 DM_RxPathSelTable.rf_enable_rssi_th[min_rssi_index] = tmp_max_rssi+5;
2080 //disable the BB Rx path, OFDM
2081 rtl8192_setBBreg(priv, rOFDM0_TRxPathEnable, 0x1<<min_rssi_index, 0x0); // 0xc04[3:0]
2082 rtl8192_setBBreg(priv, rOFDM1_TRxPathEnable, 0x1<<min_rssi_index, 0x0); // 0xd04[3:0]
2085 if(DM_RxPathSelTable.cck_method == CCK_Rx_Version_1)
2087 cck_default_Rx = max_rssi_index;
2088 cck_optional_Rx = sec_rssi_index;
2090 update_cck_rx_path = 1;
2094 if(update_cck_rx_path)
2096 DM_RxPathSelTable.cck_Rx_path = (cck_default_Rx<<2)|(cck_optional_Rx);
2097 rtl8192_setBBreg(priv, rCCK0_AFESetting, 0x0f000000, DM_RxPathSelTable.cck_Rx_path);
2100 if(DM_RxPathSelTable.disabledRF)
2104 if((DM_RxPathSelTable.disabledRF>>i) & 0x1) //disabled rf
2106 if(tmp_max_rssi >= DM_RxPathSelTable.rf_enable_rssi_th[i])
2108 //enable the BB Rx path
2109 rtl8192_setBBreg(priv, rOFDM0_TRxPathEnable, 0x1<<i, 0x1); // 0xc04[3:0]
2110 rtl8192_setBBreg(priv, rOFDM1_TRxPathEnable, 0x1<<i, 0x1); // 0xd04[3:0]
2111 DM_RxPathSelTable.rf_enable_rssi_th[i] = 100;
2120 * Call a workitem to check current RXRF path and Rx Path selection by RSSI.
2122 static void dm_check_rx_path_selection(struct r8192_priv *priv)
2124 queue_delayed_work(priv->priv_wq,&priv->rfpath_check_wq,0);
2127 static void dm_init_fsync(struct r8192_priv *priv)
2129 priv->ieee80211->fsync_time_interval = 500;
2130 priv->ieee80211->fsync_rate_bitmap = 0x0f000800;
2131 priv->ieee80211->fsync_rssi_threshold = 30;
2132 priv->ieee80211->bfsync_enable = false;
2133 priv->ieee80211->fsync_multiple_timeinterval = 3;
2134 priv->ieee80211->fsync_firstdiff_ratethreshold= 100;
2135 priv->ieee80211->fsync_seconddiff_ratethreshold= 200;
2136 priv->ieee80211->fsync_state = Default_Fsync;
2137 priv->framesyncMonitor = 1; // current default 0xc38 monitor on
2139 init_timer(&priv->fsync_timer);
2140 priv->fsync_timer.data = (unsigned long)priv;
2141 priv->fsync_timer.function = dm_fsync_timer_callback;
2145 static void dm_deInit_fsync(struct r8192_priv *priv)
2147 del_timer_sync(&priv->fsync_timer);
2150 static void dm_fsync_timer_callback(unsigned long data)
2152 struct r8192_priv *priv = (struct r8192_priv *)data;
2153 u32 rate_index, rate_count = 0, rate_count_diff=0;
2154 bool bSwitchFromCountDiff = false;
2155 bool bDoubleTimeInterval = false;
2157 if( priv->ieee80211->state == IEEE80211_LINKED &&
2158 priv->ieee80211->bfsync_enable &&
2159 (priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_CDD_FSYNC))
2161 // Count rate 54, MCS [7], [12, 13, 14, 15]
2163 for(rate_index = 0; rate_index <= 27; rate_index++)
2165 rate_bitmap = 1 << rate_index;
2166 if(priv->ieee80211->fsync_rate_bitmap & rate_bitmap)
2167 rate_count+= priv->stats.received_rate_histogram[1][rate_index];
2170 if(rate_count < priv->rate_record)
2171 rate_count_diff = 0xffffffff - rate_count + priv->rate_record;
2173 rate_count_diff = rate_count - priv->rate_record;
2174 if(rate_count_diff < priv->rateCountDiffRecord)
2177 u32 DiffNum = priv->rateCountDiffRecord - rate_count_diff;
2179 if(DiffNum >= priv->ieee80211->fsync_seconddiff_ratethreshold)
2180 priv->ContiuneDiffCount++;
2182 priv->ContiuneDiffCount = 0;
2184 // Contiune count over
2185 if(priv->ContiuneDiffCount >=2)
2187 bSwitchFromCountDiff = true;
2188 priv->ContiuneDiffCount = 0;
2193 // Stop contiune count
2194 priv->ContiuneDiffCount = 0;
2197 //If Count diff <= FsyncRateCountThreshold
2198 if(rate_count_diff <= priv->ieee80211->fsync_firstdiff_ratethreshold)
2200 bSwitchFromCountDiff = true;
2201 priv->ContiuneDiffCount = 0;
2203 priv->rate_record = rate_count;
2204 priv->rateCountDiffRecord = rate_count_diff;
2205 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff , priv->bswitch_fsync);
2206 // if we never receive those mcs rate and rssi > 30 % then switch fsyn
2207 if(priv->undecorated_smoothed_pwdb > priv->ieee80211->fsync_rssi_threshold && bSwitchFromCountDiff)
2209 bDoubleTimeInterval = true;
2210 priv->bswitch_fsync = !priv->bswitch_fsync;
2211 if(priv->bswitch_fsync)
2213 write_nic_byte(priv,0xC36, 0x1c);
2214 write_nic_byte(priv, 0xC3e, 0x90);
2218 write_nic_byte(priv, 0xC36, 0x5c);
2219 write_nic_byte(priv, 0xC3e, 0x96);
2222 else if(priv->undecorated_smoothed_pwdb <= priv->ieee80211->fsync_rssi_threshold)
2224 if(priv->bswitch_fsync)
2226 priv->bswitch_fsync = false;
2227 write_nic_byte(priv, 0xC36, 0x5c);
2228 write_nic_byte(priv, 0xC3e, 0x96);
2231 if(bDoubleTimeInterval){
2232 if(timer_pending(&priv->fsync_timer))
2233 del_timer_sync(&priv->fsync_timer);
2234 priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval*priv->ieee80211->fsync_multiple_timeinterval);
2235 add_timer(&priv->fsync_timer);
2238 if(timer_pending(&priv->fsync_timer))
2239 del_timer_sync(&priv->fsync_timer);
2240 priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval);
2241 add_timer(&priv->fsync_timer);
2246 // Let Register return to default value;
2247 if(priv->bswitch_fsync)
2249 priv->bswitch_fsync = false;
2250 write_nic_byte(priv, 0xC36, 0x5c);
2251 write_nic_byte(priv, 0xC3e, 0x96);
2253 priv->ContiuneDiffCount = 0;
2254 write_nic_dword(priv, rOFDM0_RxDetector2, 0x465c52cd);
2256 RT_TRACE(COMP_HALDM, "ContiuneDiffCount %d\n", priv->ContiuneDiffCount);
2257 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff , priv->bswitch_fsync);
2260 static void dm_StartHWFsync(struct r8192_priv *priv)
2262 RT_TRACE(COMP_HALDM, "%s\n", __FUNCTION__);
2263 write_nic_dword(priv, rOFDM0_RxDetector2, 0x465c12cf);
2264 write_nic_byte(priv, 0xc3b, 0x41);
2267 static void dm_EndSWFsync(struct r8192_priv *priv)
2269 RT_TRACE(COMP_HALDM, "%s\n", __FUNCTION__);
2270 del_timer_sync(&(priv->fsync_timer));
2272 // Let Register return to default value;
2273 if(priv->bswitch_fsync)
2275 priv->bswitch_fsync = false;
2277 write_nic_byte(priv, 0xC36, 0x40);
2279 write_nic_byte(priv, 0xC3e, 0x96);
2282 priv->ContiuneDiffCount = 0;
2284 write_nic_dword(priv, rOFDM0_RxDetector2, 0x465c52cd);
2287 static void dm_StartSWFsync(struct r8192_priv *priv)
2292 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__);
2293 // Initial rate record to zero, start to record.
2294 priv->rate_record = 0;
2295 // Initial contiune diff count to zero, start to record.
2296 priv->ContiuneDiffCount = 0;
2297 priv->rateCountDiffRecord = 0;
2298 priv->bswitch_fsync = false;
2300 if(priv->ieee80211->mode == WIRELESS_MODE_N_24G)
2302 priv->ieee80211->fsync_firstdiff_ratethreshold= 600;
2303 priv->ieee80211->fsync_seconddiff_ratethreshold = 0xffff;
2307 priv->ieee80211->fsync_firstdiff_ratethreshold= 200;
2308 priv->ieee80211->fsync_seconddiff_ratethreshold = 200;
2310 for(rateIndex = 0; rateIndex <= 27; rateIndex++)
2312 rateBitmap = 1 << rateIndex;
2313 if(priv->ieee80211->fsync_rate_bitmap & rateBitmap)
2314 priv->rate_record += priv->stats.received_rate_histogram[1][rateIndex];
2316 if(timer_pending(&priv->fsync_timer))
2317 del_timer_sync(&priv->fsync_timer);
2318 priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval);
2319 add_timer(&priv->fsync_timer);
2321 write_nic_dword(priv, rOFDM0_RxDetector2, 0x465c12cd);
2324 static void dm_EndHWFsync(struct r8192_priv *priv)
2326 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__);
2327 write_nic_dword(priv, rOFDM0_RxDetector2, 0x465c52cd);
2328 write_nic_byte(priv, 0xc3b, 0x49);
2331 static void dm_check_fsync(struct r8192_priv *priv)
2333 #define RegC38_Default 0
2334 #define RegC38_NonFsync_Other_AP 1
2335 #define RegC38_Fsync_AP_BCM 2
2337 static u8 reg_c38_State=RegC38_Default;
2338 static u32 reset_cnt=0;
2340 RT_TRACE(COMP_HALDM, "RSSI %d TimeInterval %d MultipleTimeInterval %d\n", priv->ieee80211->fsync_rssi_threshold, priv->ieee80211->fsync_time_interval, priv->ieee80211->fsync_multiple_timeinterval);
2341 RT_TRACE(COMP_HALDM, "RateBitmap 0x%x FirstDiffRateThreshold %d SecondDiffRateThreshold %d\n", priv->ieee80211->fsync_rate_bitmap, priv->ieee80211->fsync_firstdiff_ratethreshold, priv->ieee80211->fsync_seconddiff_ratethreshold);
2343 if( priv->ieee80211->state == IEEE80211_LINKED &&
2344 (priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_CDD_FSYNC))
2346 if(priv->ieee80211->bfsync_enable == 0)
2348 switch(priv->ieee80211->fsync_state)
2351 dm_StartHWFsync(priv);
2352 priv->ieee80211->fsync_state = HW_Fsync;
2355 dm_EndSWFsync(priv);
2356 dm_StartHWFsync(priv);
2357 priv->ieee80211->fsync_state = HW_Fsync;
2366 switch(priv->ieee80211->fsync_state)
2369 dm_StartSWFsync(priv);
2370 priv->ieee80211->fsync_state = SW_Fsync;
2373 dm_EndHWFsync(priv);
2374 dm_StartSWFsync(priv);
2375 priv->ieee80211->fsync_state = SW_Fsync;
2383 if(priv->framesyncMonitor)
2385 if(reg_c38_State != RegC38_Fsync_AP_BCM)
2386 { //For broadcom AP we write different default value
2387 write_nic_byte(priv, rOFDM0_RxDetector3, 0x95);
2389 reg_c38_State = RegC38_Fsync_AP_BCM;
2395 switch(priv->ieee80211->fsync_state)
2398 dm_EndHWFsync(priv);
2399 priv->ieee80211->fsync_state = Default_Fsync;
2402 dm_EndSWFsync(priv);
2403 priv->ieee80211->fsync_state = Default_Fsync;
2410 if(priv->framesyncMonitor)
2412 if(priv->ieee80211->state == IEEE80211_LINKED)
2414 if(priv->undecorated_smoothed_pwdb <= RegC38_TH)
2416 if(reg_c38_State != RegC38_NonFsync_Other_AP)
2418 write_nic_byte(priv, rOFDM0_RxDetector3, 0x90);
2420 reg_c38_State = RegC38_NonFsync_Other_AP;
2423 else if(priv->undecorated_smoothed_pwdb >= (RegC38_TH+5))
2427 write_nic_byte(priv, rOFDM0_RxDetector3, priv->framesync);
2428 reg_c38_State = RegC38_Default;
2436 write_nic_byte(priv, rOFDM0_RxDetector3, priv->framesync);
2437 reg_c38_State = RegC38_Default;
2442 if(priv->framesyncMonitor)
2444 if(priv->reset_count != reset_cnt)
2445 { //After silent reset, the reg_c38_State will be returned to default value
2446 write_nic_byte(priv, rOFDM0_RxDetector3, priv->framesync);
2447 reg_c38_State = RegC38_Default;
2448 reset_cnt = priv->reset_count;
2455 write_nic_byte(priv, rOFDM0_RxDetector3, priv->framesync);
2456 reg_c38_State = RegC38_Default;
2462 * Detect Signal strength to control TX Registry
2463 * Tx Power Control For Near/Far Range
2465 static void dm_init_dynamic_txpower(struct r8192_priv *priv)
2467 //Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code.
2468 priv->ieee80211->bdynamic_txpower_enable = true; //Default to enable Tx Power Control
2469 priv->bLastDTPFlag_High = false;
2470 priv->bLastDTPFlag_Low = false;
2471 priv->bDynamicTxHighPower = false;
2472 priv->bDynamicTxLowPower = false;
2475 static void dm_dynamic_txpower(struct r8192_priv *priv)
2477 unsigned int txhipower_threshhold=0;
2478 unsigned int txlowpower_threshold=0;
2479 if(priv->ieee80211->bdynamic_txpower_enable != true)
2481 priv->bDynamicTxHighPower = false;
2482 priv->bDynamicTxLowPower = false;
2485 if((priv->ieee80211->current_network.atheros_cap_exist ) && (priv->ieee80211->mode == IEEE_G)){
2486 txhipower_threshhold = TX_POWER_ATHEROAP_THRESH_HIGH;
2487 txlowpower_threshold = TX_POWER_ATHEROAP_THRESH_LOW;
2491 txhipower_threshhold = TX_POWER_NEAR_FIELD_THRESH_HIGH;
2492 txlowpower_threshold = TX_POWER_NEAR_FIELD_THRESH_LOW;
2495 RT_TRACE(COMP_TXAGC, "priv->undecorated_smoothed_pwdb = %ld\n" , priv->undecorated_smoothed_pwdb);
2497 if(priv->ieee80211->state == IEEE80211_LINKED)
2499 if(priv->undecorated_smoothed_pwdb >= txhipower_threshhold)
2501 priv->bDynamicTxHighPower = true;
2502 priv->bDynamicTxLowPower = false;
2506 // high power state check
2507 if(priv->undecorated_smoothed_pwdb < txlowpower_threshold && priv->bDynamicTxHighPower == true)
2509 priv->bDynamicTxHighPower = false;
2511 // low power state check
2512 if(priv->undecorated_smoothed_pwdb < 35)
2514 priv->bDynamicTxLowPower = true;
2516 else if(priv->undecorated_smoothed_pwdb >= 40)
2518 priv->bDynamicTxLowPower = false;
2524 //pHalData->bTXPowerCtrlforNearFarRange = !pHalData->bTXPowerCtrlforNearFarRange;
2525 priv->bDynamicTxHighPower = false;
2526 priv->bDynamicTxLowPower = false;
2529 if( (priv->bDynamicTxHighPower != priv->bLastDTPFlag_High ) ||
2530 (priv->bDynamicTxLowPower != priv->bLastDTPFlag_Low ) )
2532 RT_TRACE(COMP_TXAGC, "SetTxPowerLevel8190() channel = %d\n", priv->ieee80211->current_network.channel);
2535 rtl8192_phy_setTxPower(priv, priv->ieee80211->current_network.channel);
2538 priv->bLastDTPFlag_High = priv->bDynamicTxHighPower;
2539 priv->bLastDTPFlag_Low = priv->bDynamicTxLowPower;
2543 //added by vivi, for read tx rate and retrycount
2544 static void dm_check_txrateandretrycount(struct r8192_priv *priv)
2546 struct ieee80211_device* ieee = priv->ieee80211;
2548 //for initial tx rate
2549 ieee->softmac_stats.last_packet_rate = read_nic_byte(priv ,Initial_Tx_Rate_Reg);
2550 //for tx tx retry count
2551 ieee->softmac_stats.txretrycount = read_nic_dword(priv, Tx_Retry_Count_Reg);
2554 static void dm_send_rssi_tofw(struct r8192_priv *priv)
2556 // If we test chariot, we should stop the TX command ?
2557 // Because 92E will always silent reset when we send tx command. We use register
2558 // 0x1e0(byte) to botify driver.
2559 write_nic_byte(priv, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb);