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.
29 static const u32 edca_setting_DL
[HT_IOT_PEER_MAX
] =
30 { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5e4322, 0x5e4322};
31 static const u32 edca_setting_UL
[HT_IOT_PEER_MAX
] =
32 { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5e4322, 0x5e4322, 0x5e4322};
35 static const u32 edca_setting_DL
[HT_IOT_PEER_MAX
] =
36 { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5e4322, 0x5e4322};
37 static const u32 edca_setting_UL
[HT_IOT_PEER_MAX
] =
38 { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5e4322, 0x5e4322, 0x5e4322};
40 static const u32 edca_setting_DL
[HT_IOT_PEER_MAX
] =
41 { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5ea44f, 0x5e4322};
42 static const u32 edca_setting_UL
[HT_IOT_PEER_MAX
] =
43 { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5ea44f, 0x5ea44f, 0x5e4322};
47 #define RTK_UL_EDCA 0xa44f
48 #define RTK_DL_EDCA 0x5e4322
52 // For Dynamic Rx Path Selection by Signal Strength
53 DRxPathSel DM_RxPathSelTable
;
56 /*--------------------Define export function prototype-----------------------*/
57 extern void init_hal_dm(struct net_device
*dev
);
58 extern void deinit_hal_dm(struct net_device
*dev
);
60 extern void hal_dm_watchdog(struct net_device
*dev
);
63 extern void init_rate_adaptive(struct net_device
*dev
);
64 extern void dm_txpower_trackingcallback(struct work_struct
*work
);
66 extern void dm_cck_txpower_adjust(struct net_device
*dev
,bool binch14
);
67 extern void dm_restore_dynamic_mechanism_state(struct net_device
*dev
);
68 extern void dm_backup_dynamic_mechanism_state(struct net_device
*dev
);
69 extern void dm_change_dynamic_initgain_thresh(struct net_device
*dev
,
72 extern void DM_ChangeFsyncSetting(struct net_device
*dev
,
75 extern void dm_force_tx_fw_info(struct net_device
*dev
,
78 extern void dm_init_edca_turbo(struct net_device
*dev
);
79 extern void dm_rf_operation_test_callback(unsigned long data
);
80 extern void dm_rf_pathcheck_workitemcallback(struct work_struct
*work
);
81 extern void dm_fsync_timer_callback(unsigned long data
);
82 extern void dm_check_fsync(struct net_device
*dev
);
83 extern void dm_initialize_txpower_tracking(struct net_device
*dev
);
86 extern void dm_gpio_change_rf_callback(struct work_struct
*work
);
90 // DM --> Rate Adaptive
91 static void dm_check_rate_adaptive(struct net_device
*dev
);
93 // DM --> Bandwidth switch
94 static void dm_init_bandwidth_autoswitch(struct net_device
*dev
);
95 static void dm_bandwidth_autoswitch( struct net_device
*dev
);
97 // DM --> TX power control
98 static void dm_check_txpower_tracking(struct net_device
*dev
);
100 // DM --> BB init gain restore
102 static void dm_bb_initialgain_restore(struct net_device
*dev
);
104 // DM --> BB init gain backup
105 static void dm_bb_initialgain_backup(struct net_device
*dev
);
108 // DM --> Dynamic Init Gain by RSSI
109 static void dm_dig_init(struct net_device
*dev
);
110 static void dm_ctrl_initgain_byrssi(struct net_device
*dev
);
111 static void dm_ctrl_initgain_byrssi_highpwr(struct net_device
*dev
);
112 static void dm_ctrl_initgain_byrssi_by_driverrssi( struct net_device
*dev
);
113 static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(struct net_device
*dev
);
114 static void dm_initial_gain(struct net_device
*dev
);
115 static void dm_pd_th(struct net_device
*dev
);
116 static void dm_cs_ratio(struct net_device
*dev
);
118 static void dm_init_ctstoself(struct net_device
*dev
);
119 // DM --> EDCA turboe mode control
120 static void dm_check_edca_turbo(struct net_device
*dev
);
122 // DM --> HW RF control
123 static void dm_check_rfctrl_gpio(struct net_device
*dev
);
126 static void dm_check_pbc_gpio(struct net_device
*dev
);
128 // DM --> Check current RX RF path state
129 static void dm_check_rx_path_selection(struct net_device
*dev
);
130 static void dm_init_rxpath_selection(struct net_device
*dev
);
131 static void dm_rxpath_sel_byrssi(struct net_device
*dev
);
133 // DM --> Fsync for broadcom ap
134 static void dm_init_fsync(struct net_device
*dev
);
135 static void dm_deInit_fsync(struct net_device
*dev
);
137 static void dm_check_txrateandretrycount(struct net_device
*dev
);
140 /*---------------------Define of Tx Power Control For Near/Far Range --------*/ //Add by Jacken 2008/02/18
141 static void dm_init_dynamic_txpower(struct net_device
*dev
);
142 static void dm_dynamic_txpower(struct net_device
*dev
);
144 // DM --> For rate adaptive and DIG, we must send RSSI to firmware
145 static void dm_send_rssi_tofw(struct net_device
*dev
);
146 static void dm_ctstoself(struct net_device
*dev
);
149 * Prepare SW resource for HW dynamic mechanism.
150 * This function is only invoked at driver intialization once.
152 void init_hal_dm(struct net_device
*dev
)
154 struct r8192_priv
*priv
= ieee80211_priv(dev
);
156 // Undecorated Smoothed Signal Strength, it can utilized to dynamic mechanism.
157 priv
->undecorated_smoothed_pwdb
= -1;
159 //Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code.
160 dm_init_dynamic_txpower(dev
);
161 init_rate_adaptive(dev
);
162 //dm_initialize_txpower_tracking(dev);
164 dm_init_edca_turbo(dev
);
165 dm_init_bandwidth_autoswitch(dev
);
167 dm_init_rxpath_selection(dev
);
168 dm_init_ctstoself(dev
);
170 INIT_DELAYED_WORK(&priv
->gpio_change_rf_wq
, dm_gpio_change_rf_callback
);
175 void deinit_hal_dm(struct net_device
*dev
)
178 dm_deInit_fsync(dev
);
183 #ifdef USB_RX_AGGREGATION_SUPPORT
184 void dm_CheckRxAggregation(struct net_device
*dev
) {
185 struct r8192_priv
*priv
= ieee80211_priv((struct net_device
*)dev
);
186 PRT_HIGH_THROUGHPUT pHTInfo
= priv
->ieee80211
->pHTInfo
;
187 static unsigned long lastTxOkCnt
= 0;
188 static unsigned long lastRxOkCnt
= 0;
189 unsigned long curTxOkCnt
= 0;
190 unsigned long curRxOkCnt
= 0;
192 curTxOkCnt
= priv
->stats
.txbytesunicast
- lastTxOkCnt
;
193 curRxOkCnt
= priv
->stats
.rxbytesunicast
- lastRxOkCnt
;
195 if((curTxOkCnt
+ curRxOkCnt
) < 15000000) {
199 if(curTxOkCnt
> 4*curRxOkCnt
) {
200 if (priv
->bCurrentRxAggrEnable
) {
201 write_nic_dword(dev
, 0x1a8, 0);
202 priv
->bCurrentRxAggrEnable
= false;
205 if (!priv
->bCurrentRxAggrEnable
&& !pHTInfo
->bCurrentRT2RTAggregation
) {
207 ulValue
= (pHTInfo
->UsbRxFwAggrEn
<<24) | (pHTInfo
->UsbRxFwAggrPageNum
<<16) |
208 (pHTInfo
->UsbRxFwAggrPacketNum
<<8) | (pHTInfo
->UsbRxFwAggrTimeout
);
210 * If usb rx firmware aggregation is enabled,
211 * when anyone of three threshold conditions above is reached,
212 * firmware will send aggregated packet to driver.
214 write_nic_dword(dev
, 0x1a8, ulValue
);
215 priv
->bCurrentRxAggrEnable
= true;
219 lastTxOkCnt
= priv
->stats
.txbytesunicast
;
220 lastRxOkCnt
= priv
->stats
.rxbytesunicast
;
225 // call the script file to enable
226 void dm_check_ac_dc_power(struct net_device
*dev
)
228 struct r8192_priv
*priv
= ieee80211_priv(dev
);
229 static char *ac_dc_check_script_path
= "/etc/acpi/wireless-rtl-ac-dc-power.sh";
230 char *argv
[] = {ac_dc_check_script_path
,DRV_NAME
,NULL
};
231 static char *envp
[] = {"HOME=/",
233 "PATH=/usr/bin:/bin",
236 if(priv
->ResetProgress
== RESET_TYPE_SILENT
)
238 RT_TRACE((COMP_INIT
| COMP_POWER
| COMP_RF
), "GPIOChangeRFWorkItemCallBack(): Silent Reseting!!!!!!!\n");
242 if(priv
->ieee80211
->state
!= IEEE80211_LINKED
) {
245 call_usermodehelper(ac_dc_check_script_path
,argv
,envp
,1);
248 void hal_dm_watchdog(struct net_device
*dev
)
250 dm_check_ac_dc_power(dev
);
252 /*Add by amy 2008/05/15 ,porting from windows code.*/
253 dm_check_rate_adaptive(dev
);
254 dm_dynamic_txpower(dev
);
255 dm_check_txrateandretrycount(dev
);
257 dm_check_txpower_tracking(dev
);
259 dm_ctrl_initgain_byrssi(dev
);
260 dm_check_edca_turbo(dev
);
261 dm_bandwidth_autoswitch(dev
);
263 dm_check_rfctrl_gpio(dev
);
264 dm_check_rx_path_selection(dev
);
267 // Add by amy 2008-05-15 porting from windows code.
268 dm_check_pbc_gpio(dev
);
269 dm_send_rssi_tofw(dev
);
272 #ifdef USB_RX_AGGREGATION_SUPPORT
273 dm_CheckRxAggregation(dev
);
279 * Decide Rate Adaptive Set according to distance (signal strength)
280 * 01/11/2008 MHC Modify input arguments and RATR table level.
281 * 01/16/2008 MHC RF_Type is assigned in ReadAdapterInfo(). We must call
282 * the function after making sure RF_Type.
284 void init_rate_adaptive(struct net_device
* dev
)
287 struct r8192_priv
*priv
= ieee80211_priv(dev
);
288 prate_adaptive pra
= (prate_adaptive
)&priv
->rate_adaptive
;
290 pra
->ratr_state
= DM_RATR_STA_MAX
;
291 pra
->high2low_rssi_thresh_for_ra
= RateAdaptiveTH_High
;
292 pra
->low2high_rssi_thresh_for_ra20M
= RateAdaptiveTH_Low_20M
+5;
293 pra
->low2high_rssi_thresh_for_ra40M
= RateAdaptiveTH_Low_40M
+5;
295 pra
->high_rssi_thresh_for_ra
= RateAdaptiveTH_High
+5;
296 pra
->low_rssi_thresh_for_ra20M
= RateAdaptiveTH_Low_20M
;
297 pra
->low_rssi_thresh_for_ra40M
= RateAdaptiveTH_Low_40M
;
299 if(priv
->CustomerID
== RT_CID_819x_Netcore
)
300 pra
->ping_rssi_enable
= 1;
302 pra
->ping_rssi_enable
= 0;
303 pra
->ping_rssi_thresh_for_ra
= 15;
306 if (priv
->rf_type
== RF_2T4R
)
308 // 07/10/08 MH Modify for RA smooth scheme.
309 /* 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.*/
310 pra
->upper_rssi_threshold_ratr
= 0x8f0f0000;
311 pra
->middle_rssi_threshold_ratr
= 0x8f0ff000;
312 pra
->low_rssi_threshold_ratr
= 0x8f0ff001;
313 pra
->low_rssi_threshold_ratr_40M
= 0x8f0ff005;
314 pra
->low_rssi_threshold_ratr_20M
= 0x8f0ff001;
315 pra
->ping_rssi_ratr
= 0x0000000d;//cosa add for test
317 else if (priv
->rf_type
== RF_1T2R
)
319 pra
->upper_rssi_threshold_ratr
= 0x000f0000;
320 pra
->middle_rssi_threshold_ratr
= 0x000ff000;
321 pra
->low_rssi_threshold_ratr
= 0x000ff001;
322 pra
->low_rssi_threshold_ratr_40M
= 0x000ff005;
323 pra
->low_rssi_threshold_ratr_20M
= 0x000ff001;
324 pra
->ping_rssi_ratr
= 0x0000000d;//cosa add for test
330 static void dm_check_rate_adaptive(struct net_device
* dev
)
332 struct r8192_priv
*priv
= ieee80211_priv(dev
);
333 PRT_HIGH_THROUGHPUT pHTInfo
= priv
->ieee80211
->pHTInfo
;
334 prate_adaptive pra
= (prate_adaptive
)&priv
->rate_adaptive
;
335 u32 currentRATR
, targetRATR
= 0;
336 u32 LowRSSIThreshForRA
= 0, HighRSSIThreshForRA
= 0;
337 bool bshort_gi_enabled
= false;
338 static u8 ping_rssi_state
=0;
343 RT_TRACE(COMP_RATE
, "<---- dm_check_rate_adaptive(): driver is going to unload\n");
347 if(pra
->rate_adaptive_disabled
)//this variable is set by ioctl.
350 // TODO: Only 11n mode is implemented currently,
351 if( !(priv
->ieee80211
->mode
== WIRELESS_MODE_N_24G
||
352 priv
->ieee80211
->mode
== WIRELESS_MODE_N_5G
))
355 if( priv
->ieee80211
->state
== IEEE80211_LINKED
)
357 // RT_TRACE(COMP_RATE, "dm_CheckRateAdaptive(): \t");
360 // Check whether Short GI is enabled
362 bshort_gi_enabled
= (pHTInfo
->bCurTxBW40MHz
&& pHTInfo
->bCurShortGI40MHz
) ||
363 (!pHTInfo
->bCurTxBW40MHz
&& pHTInfo
->bCurShortGI20MHz
);
366 pra
->upper_rssi_threshold_ratr
=
367 (pra
->upper_rssi_threshold_ratr
& (~BIT31
)) | ((bshort_gi_enabled
)? BIT31
:0) ;
369 pra
->middle_rssi_threshold_ratr
=
370 (pra
->middle_rssi_threshold_ratr
& (~BIT31
)) | ((bshort_gi_enabled
)? BIT31
:0) ;
372 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
374 pra
->low_rssi_threshold_ratr
=
375 (pra
->low_rssi_threshold_ratr_40M
& (~BIT31
)) | ((bshort_gi_enabled
)? BIT31
:0) ;
379 pra
->low_rssi_threshold_ratr
=
380 (pra
->low_rssi_threshold_ratr_20M
& (~BIT31
)) | ((bshort_gi_enabled
)? BIT31
:0) ;
383 pra
->ping_rssi_ratr
=
384 (pra
->ping_rssi_ratr
& (~BIT31
)) | ((bshort_gi_enabled
)? BIT31
:0) ;
386 /* 2007/10/08 MH We support RA smooth scheme now. When it is the first
387 time to link with AP. We will not change upper/lower threshold. If
388 STA stay in high or low level, we must change two different threshold
389 to prevent jumping frequently. */
390 if (pra
->ratr_state
== DM_RATR_STA_HIGH
)
392 HighRSSIThreshForRA
= pra
->high2low_rssi_thresh_for_ra
;
393 LowRSSIThreshForRA
= (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)?
394 (pra
->low_rssi_thresh_for_ra40M
):(pra
->low_rssi_thresh_for_ra20M
);
396 else if (pra
->ratr_state
== DM_RATR_STA_LOW
)
398 HighRSSIThreshForRA
= pra
->high_rssi_thresh_for_ra
;
399 LowRSSIThreshForRA
= (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)?
400 (pra
->low2high_rssi_thresh_for_ra40M
):(pra
->low2high_rssi_thresh_for_ra20M
);
404 HighRSSIThreshForRA
= pra
->high_rssi_thresh_for_ra
;
405 LowRSSIThreshForRA
= (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)?
406 (pra
->low_rssi_thresh_for_ra40M
):(pra
->low_rssi_thresh_for_ra20M
);
409 if(priv
->undecorated_smoothed_pwdb
>= (long)HighRSSIThreshForRA
)
411 pra
->ratr_state
= DM_RATR_STA_HIGH
;
412 targetRATR
= pra
->upper_rssi_threshold_ratr
;
413 }else if(priv
->undecorated_smoothed_pwdb
>= (long)LowRSSIThreshForRA
)
415 pra
->ratr_state
= DM_RATR_STA_MIDDLE
;
416 targetRATR
= pra
->middle_rssi_threshold_ratr
;
419 pra
->ratr_state
= DM_RATR_STA_LOW
;
420 targetRATR
= pra
->low_rssi_threshold_ratr
;
424 if(pra
->ping_rssi_enable
)
426 //pHalData->UndecoratedSmoothedPWDB = 19;
427 if(priv
->undecorated_smoothed_pwdb
< (long)(pra
->ping_rssi_thresh_for_ra
+5))
429 if( (priv
->undecorated_smoothed_pwdb
< (long)pra
->ping_rssi_thresh_for_ra
) ||
432 pra
->ratr_state
= DM_RATR_STA_LOW
;
433 targetRATR
= pra
->ping_rssi_ratr
;
445 // For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
446 if(priv
->ieee80211
->GetHalfNmodeSupportByAPsHandler(dev
))
447 targetRATR
&= 0xf00fffff;
451 // Check whether updating of RATR0 is required
453 currentRATR
= read_nic_dword(dev
, RATR0
);
454 if( targetRATR
!= currentRATR
)
457 ratr_value
= targetRATR
;
458 RT_TRACE(COMP_RATE
,"currentRATR = %x, targetRATR = %x\n", currentRATR
, targetRATR
);
459 if(priv
->rf_type
== RF_1T2R
)
461 ratr_value
&= ~(RATE_ALL_OFDM_2SS
);
463 write_nic_dword(dev
, RATR0
, ratr_value
);
464 write_nic_byte(dev
, UFWP
, 1);
466 pra
->last_ratr
= targetRATR
;
472 pra
->ratr_state
= DM_RATR_STA_MAX
;
478 static void dm_init_bandwidth_autoswitch(struct net_device
* dev
)
480 struct r8192_priv
*priv
= ieee80211_priv(dev
);
482 priv
->ieee80211
->bandwidth_auto_switch
.threshold_20Mhzto40Mhz
= BW_AUTO_SWITCH_LOW_HIGH
;
483 priv
->ieee80211
->bandwidth_auto_switch
.threshold_40Mhzto20Mhz
= BW_AUTO_SWITCH_HIGH_LOW
;
484 priv
->ieee80211
->bandwidth_auto_switch
.bforced_tx20Mhz
= false;
485 priv
->ieee80211
->bandwidth_auto_switch
.bautoswitch_enable
= false;
490 static void dm_bandwidth_autoswitch(struct net_device
* dev
)
492 struct r8192_priv
*priv
= ieee80211_priv(dev
);
494 if(priv
->CurrentChannelBW
== HT_CHANNEL_WIDTH_20
||!priv
->ieee80211
->bandwidth_auto_switch
.bautoswitch_enable
){
497 if(priv
->ieee80211
->bandwidth_auto_switch
.bforced_tx20Mhz
== false){//If send packets in 40 Mhz in 20/40
498 if(priv
->undecorated_smoothed_pwdb
<= priv
->ieee80211
->bandwidth_auto_switch
.threshold_40Mhzto20Mhz
)
499 priv
->ieee80211
->bandwidth_auto_switch
.bforced_tx20Mhz
= true;
500 }else{//in force send packets in 20 Mhz in 20/40
501 if(priv
->undecorated_smoothed_pwdb
>= priv
->ieee80211
->bandwidth_auto_switch
.threshold_20Mhzto40Mhz
)
502 priv
->ieee80211
->bandwidth_auto_switch
.bforced_tx20Mhz
= false;
508 //OFDM default at 0db, index=6.
510 static const u32 OFDMSwingTable
[OFDM_Table_Length
] = {
511 0x7f8001fe, // 0, +6db
512 0x71c001c7, // 1, +5db
513 0x65400195, // 2, +4db
514 0x5a400169, // 3, +3db
515 0x50800142, // 4, +2db
516 0x47c0011f, // 5, +1db
517 0x40000100, // 6, +0db ===> default, upper for higher temperature, lower for low temperature
518 0x390000e4, // 7, -1db
519 0x32c000cb, // 8, -2db
520 0x2d4000b5, // 9, -3db
521 0x288000a2, // 10, -4db
522 0x24000090, // 11, -5db
523 0x20000080, // 12, -6db
524 0x1c800072, // 13, -7db
525 0x19800066, // 14, -8db
526 0x26c0005b, // 15, -9db
527 0x24400051, // 16, -10db
528 0x12000048, // 17, -11db
529 0x10000040 // 18, -12db
531 static const u8 CCKSwingTable_Ch1_Ch13
[CCK_Table_length
][8] = {
532 {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, // 0, +0db ===> CCK40M default
533 {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, // 1, -1db
534 {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, // 2, -2db
535 {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, // 3, -3db
536 {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, // 4, -4db
537 {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, // 5, -5db
538 {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, // 6, -6db ===> CCK20M default
539 {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, // 7, -7db
540 {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, // 8, -8db
541 {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, // 9, -9db
542 {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 10, -10db
543 {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01} // 11, -11db
546 static const u8 CCKSwingTable_Ch14
[CCK_Table_length
][8] = {
547 {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, // 0, +0db ===> CCK40M default
548 {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, // 1, -1db
549 {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, // 2, -2db
550 {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, // 3, -3db
551 {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, // 4, -4db
552 {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, // 5, -5db
553 {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 6, -6db ===> CCK20M default
554 {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 7, -7db
555 {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 8, -8db
556 {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 9, -9db
557 {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 10, -10db
558 {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00} // 11, -11db
561 #define Pw_Track_Flag 0x11d
562 #define Tssi_Mea_Value 0x13c
563 #define Tssi_Report_Value1 0x134
564 #define Tssi_Report_Value2 0x13e
565 #define FW_Busy_Flag 0x13f
566 static void dm_TXPowerTrackingCallback_TSSI(struct net_device
* dev
)
568 struct r8192_priv
*priv
= ieee80211_priv(dev
);
569 bool bHighpowerstate
, viviflag
= FALSE
;
571 u8 powerlevelOFDM24G
;
572 int i
=0, j
= 0, k
= 0;
573 u8 RF_Type
, tmp_report
[5]={0, 0, 0, 0, 0};
576 u16 Avg_TSSI_Meas
, TSSI_13dBm
, Avg_TSSI_Meas_from_driver
=0;
578 RT_STATUS rtStatus
= RT_STATUS_SUCCESS
;
580 // bool rtStatus = true;
582 RT_TRACE(COMP_POWER_TRACKING
,"%s()\n",__FUNCTION__
);
583 // write_nic_byte(dev, 0x1ba, 0);
584 write_nic_byte(dev
, Pw_Track_Flag
, 0);
585 write_nic_byte(dev
, FW_Busy_Flag
, 0);
586 priv
->ieee80211
->bdynamic_txpower_enable
= false;
587 bHighpowerstate
= priv
->bDynamicTxHighPower
;
589 powerlevelOFDM24G
= (u8
)(priv
->Pwr_Track
>>24);
590 RF_Type
= priv
->rf_type
;
591 Value
= (RF_Type
<<8) | powerlevelOFDM24G
;
593 RT_TRACE(COMP_POWER_TRACKING
, "powerlevelOFDM24G = %x\n", powerlevelOFDM24G
);
595 for(j
= 0; j
<=30; j
++)
598 tx_cmd
.Op
= TXCMD_SET_TX_PWR_TRACKING
;
600 tx_cmd
.Value
= Value
;
602 rtStatus
= SendTxCommandPacket(dev
, &tx_cmd
, 12);
603 if (rtStatus
== RT_STATUS_FAILURE
)
605 RT_TRACE(COMP_POWER_TRACKING
, "Set configuration with tx cmd queue fail!\n");
608 cmpk_message_handle_tx(dev
, (u8
*)&tx_cmd
, DESC_PACKET_TYPE_INIT
, sizeof(DCMD_TXCMD_T
));
612 for(i
= 0;i
<= 30; i
++)
614 Pwr_Flag
= read_nic_byte(dev
, Pw_Track_Flag
);
622 Avg_TSSI_Meas
= read_nic_word(dev
, Tssi_Mea_Value
);
624 if(Avg_TSSI_Meas
== 0)
626 write_nic_byte(dev
, Pw_Track_Flag
, 0);
627 write_nic_byte(dev
, FW_Busy_Flag
, 0);
631 for(k
= 0;k
< 5; k
++)
634 tmp_report
[k
] = read_nic_byte(dev
, Tssi_Report_Value1
+k
);
636 tmp_report
[k
] = read_nic_byte(dev
, Tssi_Report_Value2
);
638 RT_TRACE(COMP_POWER_TRACKING
, "TSSI_report_value = %d\n", tmp_report
[k
]);
641 //check if the report value is right
642 for(k
= 0;k
< 5; k
++)
644 if(tmp_report
[k
] <= 20)
652 write_nic_byte(dev
, Pw_Track_Flag
, 0);
654 RT_TRACE(COMP_POWER_TRACKING
, "we filted this data\n");
655 for(k
= 0;k
< 5; k
++)
660 for(k
= 0;k
< 5; k
++)
662 Avg_TSSI_Meas_from_driver
+= tmp_report
[k
];
665 Avg_TSSI_Meas_from_driver
= Avg_TSSI_Meas_from_driver
*100/5;
666 RT_TRACE(COMP_POWER_TRACKING
, "Avg_TSSI_Meas_from_driver = %d\n", Avg_TSSI_Meas_from_driver
);
667 TSSI_13dBm
= priv
->TSSI_13dBm
;
668 RT_TRACE(COMP_POWER_TRACKING
, "TSSI_13dBm = %d\n", TSSI_13dBm
);
670 //if(abs(Avg_TSSI_Meas_from_driver - TSSI_13dBm) <= E_FOR_TX_POWER_TRACK)
671 // For MacOS-compatible
672 if(Avg_TSSI_Meas_from_driver
> TSSI_13dBm
)
673 delta
= Avg_TSSI_Meas_from_driver
- TSSI_13dBm
;
675 delta
= TSSI_13dBm
- Avg_TSSI_Meas_from_driver
;
677 if(delta
<= E_FOR_TX_POWER_TRACK
)
679 priv
->ieee80211
->bdynamic_txpower_enable
= TRUE
;
680 write_nic_byte(dev
, Pw_Track_Flag
, 0);
681 write_nic_byte(dev
, FW_Busy_Flag
, 0);
682 RT_TRACE(COMP_POWER_TRACKING
, "tx power track is done\n");
683 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfa_txpowertrackingindex = %d\n", priv
->rfa_txpowertrackingindex
);
684 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfa_txpowertrackingindex_real = %d\n", priv
->rfa_txpowertrackingindex_real
);
686 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfc_txpowertrackingindex = %d\n", priv
->rfc_txpowertrackingindex
);
687 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfc_txpowertrackingindex_real = %d\n", priv
->rfc_txpowertrackingindex_real
);
689 RT_TRACE(COMP_POWER_TRACKING
, "priv->CCKPresentAttentuation_difference = %d\n", priv
->CCKPresentAttentuation_difference
);
690 RT_TRACE(COMP_POWER_TRACKING
, "priv->CCKPresentAttentuation = %d\n", priv
->CCKPresentAttentuation
);
695 if(Avg_TSSI_Meas_from_driver
< TSSI_13dBm
- E_FOR_TX_POWER_TRACK
)
697 if (RF_Type
== RF_2T4R
)
700 if((priv
->rfa_txpowertrackingindex
> 0) &&(priv
->rfc_txpowertrackingindex
> 0))
702 priv
->rfa_txpowertrackingindex
--;
703 if(priv
->rfa_txpowertrackingindex_real
> 4)
705 priv
->rfa_txpowertrackingindex_real
--;
706 rtl8192_setBBreg(dev
, rOFDM0_XATxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfa_txpowertrackingindex_real
].txbbgain_value
);
709 priv
->rfc_txpowertrackingindex
--;
710 if(priv
->rfc_txpowertrackingindex_real
> 4)
712 priv
->rfc_txpowertrackingindex_real
--;
713 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfc_txpowertrackingindex_real
].txbbgain_value
);
718 rtl8192_setBBreg(dev
, rOFDM0_XATxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[4].txbbgain_value
);
719 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[4].txbbgain_value
);
724 if(priv
->rfc_txpowertrackingindex
> 0)
726 priv
->rfc_txpowertrackingindex
--;
727 if(priv
->rfc_txpowertrackingindex_real
> 4)
729 priv
->rfc_txpowertrackingindex_real
--;
730 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfc_txpowertrackingindex_real
].txbbgain_value
);
734 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[4].txbbgain_value
);
739 if (RF_Type
== RF_2T4R
)
741 if((priv
->rfa_txpowertrackingindex
< TxBBGainTableLength
- 1) &&(priv
->rfc_txpowertrackingindex
< TxBBGainTableLength
- 1))
743 priv
->rfa_txpowertrackingindex
++;
744 priv
->rfa_txpowertrackingindex_real
++;
745 rtl8192_setBBreg(dev
, rOFDM0_XATxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfa_txpowertrackingindex_real
].txbbgain_value
);
746 priv
->rfc_txpowertrackingindex
++;
747 priv
->rfc_txpowertrackingindex_real
++;
748 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfc_txpowertrackingindex_real
].txbbgain_value
);
752 rtl8192_setBBreg(dev
, rOFDM0_XATxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[TxBBGainTableLength
- 1].txbbgain_value
);
753 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[TxBBGainTableLength
- 1].txbbgain_value
);
758 if(priv
->rfc_txpowertrackingindex
< (TxBBGainTableLength
- 1))
760 priv
->rfc_txpowertrackingindex
++;
761 priv
->rfc_txpowertrackingindex_real
++;
762 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfc_txpowertrackingindex_real
].txbbgain_value
);
765 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[TxBBGainTableLength
- 1].txbbgain_value
);
768 if (RF_Type
== RF_2T4R
)
769 priv
->CCKPresentAttentuation_difference
770 = priv
->rfa_txpowertrackingindex
- priv
->rfa_txpowertracking_default
;
772 priv
->CCKPresentAttentuation_difference
773 = priv
->rfc_txpowertrackingindex
- priv
->rfc_txpowertracking_default
;
775 if(priv
->CurrentChannelBW
== HT_CHANNEL_WIDTH_20
)
776 priv
->CCKPresentAttentuation
777 = priv
->CCKPresentAttentuation_20Mdefault
+ priv
->CCKPresentAttentuation_difference
;
779 priv
->CCKPresentAttentuation
780 = priv
->CCKPresentAttentuation_40Mdefault
+ priv
->CCKPresentAttentuation_difference
;
782 if(priv
->CCKPresentAttentuation
> (CCKTxBBGainTableLength
-1))
783 priv
->CCKPresentAttentuation
= CCKTxBBGainTableLength
-1;
784 if(priv
->CCKPresentAttentuation
< 0)
785 priv
->CCKPresentAttentuation
= 0;
789 if(priv
->ieee80211
->current_network
.channel
== 14 && !priv
->bcck_in_ch14
)
791 priv
->bcck_in_ch14
= TRUE
;
792 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
794 else if(priv
->ieee80211
->current_network
.channel
!= 14 && priv
->bcck_in_ch14
)
796 priv
->bcck_in_ch14
= FALSE
;
797 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
800 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
802 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfa_txpowertrackingindex = %d\n", priv
->rfa_txpowertrackingindex
);
803 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfa_txpowertrackingindex_real = %d\n", priv
->rfa_txpowertrackingindex_real
);
805 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfc_txpowertrackingindex = %d\n", priv
->rfc_txpowertrackingindex
);
806 RT_TRACE(COMP_POWER_TRACKING
, "priv->rfc_txpowertrackingindex_real = %d\n", priv
->rfc_txpowertrackingindex_real
);
808 RT_TRACE(COMP_POWER_TRACKING
, "priv->CCKPresentAttentuation_difference = %d\n", priv
->CCKPresentAttentuation_difference
);
809 RT_TRACE(COMP_POWER_TRACKING
, "priv->CCKPresentAttentuation = %d\n", priv
->CCKPresentAttentuation
);
811 if (priv
->CCKPresentAttentuation_difference
<= -12||priv
->CCKPresentAttentuation_difference
>= 24)
813 priv
->ieee80211
->bdynamic_txpower_enable
= TRUE
;
814 write_nic_byte(dev
, Pw_Track_Flag
, 0);
815 write_nic_byte(dev
, FW_Busy_Flag
, 0);
816 RT_TRACE(COMP_POWER_TRACKING
, "tx power track--->limited\n");
822 write_nic_byte(dev
, Pw_Track_Flag
, 0);
823 Avg_TSSI_Meas_from_driver
= 0;
824 for(k
= 0;k
< 5; k
++)
828 write_nic_byte(dev
, FW_Busy_Flag
, 0);
830 priv
->ieee80211
->bdynamic_txpower_enable
= TRUE
;
831 write_nic_byte(dev
, Pw_Track_Flag
, 0);
834 static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device
* dev
)
836 #define ThermalMeterVal 9
837 struct r8192_priv
*priv
= ieee80211_priv(dev
);
838 u32 tmpRegA
, TempCCk
;
839 u8 tmpOFDMindex
, tmpCCKindex
, tmpCCK20Mindex
, tmpCCK40Mindex
, tmpval
;
840 int i
=0, CCKSwingNeedUpdate
=0;
842 if(!priv
->btxpower_trackingInit
)
844 //Query OFDM default setting
845 tmpRegA
= rtl8192_QueryBBReg(dev
, rOFDM0_XATxIQImbalance
, bMaskDWord
);
846 for(i
=0; i
<OFDM_Table_Length
; i
++) //find the index
848 if(tmpRegA
== OFDMSwingTable
[i
])
850 priv
->OFDM_index
= (u8
)i
;
851 RT_TRACE(COMP_POWER_TRACKING
, "Initial reg0x%x = 0x%x, OFDM_index=0x%x\n",
852 rOFDM0_XATxIQImbalance
, tmpRegA
, priv
->OFDM_index
);
856 //Query CCK default setting From 0xa22
857 TempCCk
= rtl8192_QueryBBReg(dev
, rCCK0_TxFilter1
, bMaskByte2
);
858 for(i
=0 ; i
<CCK_Table_length
; i
++)
860 if(TempCCk
== (u32
)CCKSwingTable_Ch1_Ch13
[i
][0])
862 priv
->CCK_index
=(u8
) i
;
863 RT_TRACE(COMP_POWER_TRACKING
, "Initial reg0x%x = 0x%x, CCK_index=0x%x\n",
864 rCCK0_TxFilter1
, TempCCk
, priv
->CCK_index
);
868 priv
->btxpower_trackingInit
= TRUE
;
869 //pHalData->TXPowercount = 0;
873 // read and filter out unreasonable value
874 tmpRegA
= rtl8192_phy_QueryRFReg(dev
, RF90_PATH_A
, 0x12, 0x078); // 0x12: RF Reg[10:7]
875 RT_TRACE(COMP_POWER_TRACKING
, "Readback ThermalMeterA = %d \n", tmpRegA
);
876 if(tmpRegA
< 3 || tmpRegA
> 13)
878 if(tmpRegA
>= 12) // if over 12, TP will be bad when high temperature
880 RT_TRACE(COMP_POWER_TRACKING
, "Valid ThermalMeterA = %d \n", tmpRegA
);
881 priv
->ThermalMeter
[0] = ThermalMeterVal
; //We use fixed value by Bryant's suggestion
882 priv
->ThermalMeter
[1] = ThermalMeterVal
; //We use fixed value by Bryant's suggestion
884 //Get current RF-A temperature index
885 if(priv
->ThermalMeter
[0] >= (u8
)tmpRegA
) //lower temperature
887 tmpOFDMindex
= tmpCCK20Mindex
= 6+(priv
->ThermalMeter
[0]-(u8
)tmpRegA
);
888 tmpCCK40Mindex
= tmpCCK20Mindex
- 6;
889 if(tmpOFDMindex
>= OFDM_Table_Length
)
890 tmpOFDMindex
= OFDM_Table_Length
-1;
891 if(tmpCCK20Mindex
>= CCK_Table_length
)
892 tmpCCK20Mindex
= CCK_Table_length
-1;
893 if(tmpCCK40Mindex
>= CCK_Table_length
)
894 tmpCCK40Mindex
= CCK_Table_length
-1;
898 tmpval
= ((u8
)tmpRegA
- priv
->ThermalMeter
[0]);
899 if(tmpval
>= 6) // higher temperature
900 tmpOFDMindex
= tmpCCK20Mindex
= 0; // max to +6dB
902 tmpOFDMindex
= tmpCCK20Mindex
= 6 - tmpval
;
906 if(priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
) //40M
907 tmpCCKindex
= tmpCCK40Mindex
;
909 tmpCCKindex
= tmpCCK20Mindex
;
911 //record for bandwidth swith
912 priv
->Record_CCK_20Mindex
= tmpCCK20Mindex
;
913 priv
->Record_CCK_40Mindex
= tmpCCK40Mindex
;
914 RT_TRACE(COMP_POWER_TRACKING
, "Record_CCK_20Mindex / Record_CCK_40Mindex = %d / %d.\n",
915 priv
->Record_CCK_20Mindex
, priv
->Record_CCK_40Mindex
);
917 if(priv
->ieee80211
->current_network
.channel
== 14 && !priv
->bcck_in_ch14
)
919 priv
->bcck_in_ch14
= TRUE
;
920 CCKSwingNeedUpdate
= 1;
922 else if(priv
->ieee80211
->current_network
.channel
!= 14 && priv
->bcck_in_ch14
)
924 priv
->bcck_in_ch14
= FALSE
;
925 CCKSwingNeedUpdate
= 1;
928 if(priv
->CCK_index
!= tmpCCKindex
)
930 priv
->CCK_index
= tmpCCKindex
;
931 CCKSwingNeedUpdate
= 1;
934 if(CCKSwingNeedUpdate
)
936 dm_cck_txpower_adjust(dev
, priv
->bcck_in_ch14
);
938 if(priv
->OFDM_index
!= tmpOFDMindex
)
940 priv
->OFDM_index
= tmpOFDMindex
;
941 rtl8192_setBBreg(dev
, rOFDM0_XATxIQImbalance
, bMaskDWord
, OFDMSwingTable
[priv
->OFDM_index
]);
942 RT_TRACE(COMP_POWER_TRACKING
, "Update OFDMSwing[%d] = 0x%x\n",
943 priv
->OFDM_index
, OFDMSwingTable
[priv
->OFDM_index
]);
945 priv
->txpower_count
= 0;
948 void dm_txpower_trackingcallback(struct work_struct
*work
)
950 struct delayed_work
*dwork
= container_of(work
,struct delayed_work
,work
);
951 struct r8192_priv
*priv
= container_of(dwork
,struct r8192_priv
,txpower_tracking_wq
);
952 struct net_device
*dev
= priv
->ieee80211
->dev
;
955 dm_TXPowerTrackingCallback_TSSI(dev
);
957 //if(priv->bDcut == TRUE)
958 if(priv
->IC_Cut
>= IC_VersionCut_D
)
959 dm_TXPowerTrackingCallback_TSSI(dev
);
961 dm_TXPowerTrackingCallback_ThermalMeter(dev
);
966 static const txbbgain_struct rtl8192_txbbgain_table
[] = {
1000 { -21, 0x1300004c },
1001 { -22, 0x12000048 },
1002 { -23, 0x11000044 },
1003 { -24, 0x10000040 },
1007 * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
1008 * This Table is for CH1~CH13
1010 static const ccktxbbgain_struct rtl8192_cck_txbbgain_table
[] = {
1011 {{ 0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04 }},
1012 {{ 0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04 }},
1013 {{ 0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03 }},
1014 {{ 0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03 }},
1015 {{ 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03 }},
1016 {{ 0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03 }},
1017 {{ 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03 }},
1018 {{ 0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03 }},
1019 {{ 0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02 }},
1020 {{ 0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02 }},
1021 {{ 0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02 }},
1022 {{ 0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02 }},
1023 {{ 0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02 }},
1024 {{ 0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02 }},
1025 {{ 0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02 }},
1026 {{ 0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02 }},
1027 {{ 0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01 }},
1028 {{ 0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02 }},
1029 {{ 0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01 }},
1030 {{ 0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01 }},
1031 {{ 0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01 }},
1032 {{ 0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01 }},
1033 {{ 0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01 }},
1037 * ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
1038 * This Table is for CH14
1040 static const ccktxbbgain_struct rtl8192_cck_txbbgain_ch14_table
[] = {
1041 {{ 0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00 }},
1042 {{ 0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00 }},
1043 {{ 0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00 }},
1044 {{ 0x2d, 0x2d, 0x27, 0x17, 0x00, 0x00, 0x00, 0x00 }},
1045 {{ 0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00 }},
1046 {{ 0x28, 0x28, 0x22, 0x14, 0x00, 0x00, 0x00, 0x00 }},
1047 {{ 0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00 }},
1048 {{ 0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00 }},
1049 {{ 0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00 }},
1050 {{ 0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00 }},
1051 {{ 0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00 }},
1052 {{ 0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00 }},
1053 {{ 0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00 }},
1054 {{ 0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00 }},
1055 {{ 0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00 }},
1056 {{ 0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00 }},
1057 {{ 0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00 }},
1058 {{ 0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00 }},
1059 {{ 0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00 }},
1060 {{ 0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00 }},
1061 {{ 0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00 }},
1062 {{ 0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00 }},
1063 {{ 0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00 }},
1066 static void dm_InitializeTXPowerTracking_TSSI(struct net_device
*dev
)
1068 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1070 priv
->txbbgain_table
= rtl8192_txbbgain_table
;
1071 priv
->cck_txbbgain_table
= rtl8192_cck_txbbgain_table
;
1072 priv
->cck_txbbgain_ch14_table
= rtl8192_cck_txbbgain_ch14_table
;
1074 priv
->btxpower_tracking
= TRUE
;
1075 priv
->txpower_count
= 0;
1076 priv
->btxpower_trackingInit
= FALSE
;
1080 static void dm_InitializeTXPowerTracking_ThermalMeter(struct net_device
*dev
)
1082 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1084 // Tx Power tracking by Theremal Meter require Firmware R/W 3-wire. This mechanism
1085 // can be enabled only when Firmware R/W 3-wire is enabled. Otherwise, frequent r/w
1086 // 3-wire by driver cause RF goes into wrong state.
1087 if(priv
->ieee80211
->FwRWRF
)
1088 priv
->btxpower_tracking
= TRUE
;
1090 priv
->btxpower_tracking
= FALSE
;
1091 priv
->txpower_count
= 0;
1092 priv
->btxpower_trackingInit
= FALSE
;
1096 void dm_initialize_txpower_tracking(struct net_device
*dev
)
1099 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1102 dm_InitializeTXPowerTracking_TSSI(dev
);
1104 if(priv
->IC_Cut
>= IC_VersionCut_D
)
1105 dm_InitializeTXPowerTracking_TSSI(dev
);
1107 dm_InitializeTXPowerTracking_ThermalMeter(dev
);
1112 static void dm_CheckTXPowerTracking_TSSI(struct net_device
*dev
)
1114 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1115 static u32 tx_power_track_counter
= 0;
1116 RT_TRACE(COMP_POWER_TRACKING
,"%s()\n",__FUNCTION__
);
1117 if(read_nic_byte(dev
, 0x11e) ==1)
1119 if(!priv
->btxpower_tracking
)
1121 tx_power_track_counter
++;
1123 if (tx_power_track_counter
> 90) {
1124 queue_delayed_work(priv
->priv_wq
,&priv
->txpower_tracking_wq
,0);
1125 tx_power_track_counter
=0;
1130 static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device
*dev
)
1132 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1133 static u8 TM_Trigger
=0;
1135 if(!priv
->btxpower_tracking
)
1139 if(priv
->txpower_count
<= 2)
1141 priv
->txpower_count
++;
1148 //Attention!! You have to wirte all 12bits data to RF, or it may cause RF to crash
1149 //actually write reg0x02 bit1=0, then bit1=1.
1150 rtl8192_phy_SetRFReg(dev
, RF90_PATH_A
, 0x02, bMask12Bits
, 0x4d);
1151 rtl8192_phy_SetRFReg(dev
, RF90_PATH_A
, 0x02, bMask12Bits
, 0x4f);
1152 rtl8192_phy_SetRFReg(dev
, RF90_PATH_A
, 0x02, bMask12Bits
, 0x4d);
1153 rtl8192_phy_SetRFReg(dev
, RF90_PATH_A
, 0x02, bMask12Bits
, 0x4f);
1158 queue_delayed_work(priv
->priv_wq
,&priv
->txpower_tracking_wq
,0);
1164 static void dm_check_txpower_tracking(struct net_device
*dev
)
1167 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1168 //static u32 tx_power_track_counter = 0;
1171 dm_CheckTXPowerTracking_TSSI(dev
);
1173 //if(priv->bDcut == TRUE)
1174 if(priv
->IC_Cut
>= IC_VersionCut_D
)
1175 dm_CheckTXPowerTracking_TSSI(dev
);
1177 dm_CheckTXPowerTracking_ThermalMeter(dev
);
1183 static void dm_CCKTxPowerAdjust_TSSI(struct net_device
*dev
, bool bInCH14
)
1186 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1191 TempVal
= (u32
)(priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[0] +
1192 (priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[1]<<8)) ;
1194 rtl8192_setBBreg(dev
, rCCK0_TxFilter1
,bMaskHWord
, TempVal
);
1195 //Write 0xa24 ~ 0xa27
1197 TempVal
= (u32
)(priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[2] +
1198 (priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[3]<<8) +
1199 (priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[4]<<16 )+
1200 (priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[5]<<24));
1201 rtl8192_setBBreg(dev
, rCCK0_TxFilter2
,bMaskDWord
, TempVal
);
1204 TempVal
= (u32
)(priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[6] +
1205 (priv
->cck_txbbgain_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[7]<<8)) ;
1207 rtl8192_setBBreg(dev
, rCCK0_DebugPort
,bMaskLWord
, TempVal
);
1211 TempVal
= (u32
)(priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[0] +
1212 (priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[1]<<8)) ;
1214 rtl8192_setBBreg(dev
, rCCK0_TxFilter1
,bMaskHWord
, TempVal
);
1215 //Write 0xa24 ~ 0xa27
1217 TempVal
= (u32
)(priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[2] +
1218 (priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[3]<<8) +
1219 (priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[4]<<16 )+
1220 (priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[5]<<24));
1221 rtl8192_setBBreg(dev
, rCCK0_TxFilter2
,bMaskDWord
, TempVal
);
1224 TempVal
= (u32
)(priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[6] +
1225 (priv
->cck_txbbgain_ch14_table
[(u8
)(priv
->CCKPresentAttentuation
)].ccktxbb_valuearray
[7]<<8)) ;
1227 rtl8192_setBBreg(dev
, rCCK0_DebugPort
,bMaskLWord
, TempVal
);
1233 static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device
*dev
, bool bInCH14
)
1236 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1242 TempVal
= CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][0] +
1243 (CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][1]<<8) ;
1244 rtl8192_setBBreg(dev
, rCCK0_TxFilter1
, bMaskHWord
, TempVal
);
1245 RT_TRACE(COMP_POWER_TRACKING
, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1246 rCCK0_TxFilter1
, TempVal
);
1247 //Write 0xa24 ~ 0xa27
1249 TempVal
= CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][2] +
1250 (CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][3]<<8) +
1251 (CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][4]<<16 )+
1252 (CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][5]<<24);
1253 rtl8192_setBBreg(dev
, rCCK0_TxFilter2
, bMaskDWord
, TempVal
);
1254 RT_TRACE(COMP_POWER_TRACKING
, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1255 rCCK0_TxFilter2
, TempVal
);
1258 TempVal
= CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][6] +
1259 (CCKSwingTable_Ch1_Ch13
[priv
->CCK_index
][7]<<8) ;
1261 rtl8192_setBBreg(dev
, rCCK0_DebugPort
, bMaskLWord
, TempVal
);
1262 RT_TRACE(COMP_POWER_TRACKING
, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1263 rCCK0_DebugPort
, TempVal
);
1267 // priv->CCKTxPowerAdjustCntNotCh14++; //cosa add for debug.
1269 TempVal
= CCKSwingTable_Ch14
[priv
->CCK_index
][0] +
1270 (CCKSwingTable_Ch14
[priv
->CCK_index
][1]<<8) ;
1272 rtl8192_setBBreg(dev
, rCCK0_TxFilter1
, bMaskHWord
, TempVal
);
1273 RT_TRACE(COMP_POWER_TRACKING
, "CCK chnl 14, reg 0x%x = 0x%x\n",
1274 rCCK0_TxFilter1
, TempVal
);
1275 //Write 0xa24 ~ 0xa27
1277 TempVal
= CCKSwingTable_Ch14
[priv
->CCK_index
][2] +
1278 (CCKSwingTable_Ch14
[priv
->CCK_index
][3]<<8) +
1279 (CCKSwingTable_Ch14
[priv
->CCK_index
][4]<<16 )+
1280 (CCKSwingTable_Ch14
[priv
->CCK_index
][5]<<24);
1281 rtl8192_setBBreg(dev
, rCCK0_TxFilter2
, bMaskDWord
, TempVal
);
1282 RT_TRACE(COMP_POWER_TRACKING
, "CCK chnl 14, reg 0x%x = 0x%x\n",
1283 rCCK0_TxFilter2
, TempVal
);
1286 TempVal
= CCKSwingTable_Ch14
[priv
->CCK_index
][6] +
1287 (CCKSwingTable_Ch14
[priv
->CCK_index
][7]<<8) ;
1289 rtl8192_setBBreg(dev
, rCCK0_DebugPort
, bMaskLWord
, TempVal
);
1290 RT_TRACE(COMP_POWER_TRACKING
,"CCK chnl 14, reg 0x%x = 0x%x\n",
1291 rCCK0_DebugPort
, TempVal
);
1297 void dm_cck_txpower_adjust(struct net_device
*dev
, bool binch14
)
1300 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1303 dm_CCKTxPowerAdjust_TSSI(dev
, binch14
);
1305 if(priv
->IC_Cut
>= IC_VersionCut_D
)
1306 dm_CCKTxPowerAdjust_TSSI(dev
, binch14
);
1308 dm_CCKTxPowerAdjust_ThermalMeter(dev
, binch14
);
1314 static void dm_txpower_reset_recovery(
1315 struct net_device
*dev
1318 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1320 RT_TRACE(COMP_POWER_TRACKING
, "Start Reset Recovery ==>\n");
1321 rtl8192_setBBreg(dev
, rOFDM0_XATxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfa_txpowertrackingindex
].txbbgain_value
);
1322 RT_TRACE(COMP_POWER_TRACKING
, "Reset Recovery: Fill in 0xc80 is %08x\n",priv
->txbbgain_table
[priv
->rfa_txpowertrackingindex
].txbbgain_value
);
1323 RT_TRACE(COMP_POWER_TRACKING
, "Reset Recovery: Fill in RFA_txPowerTrackingIndex is %x\n",priv
->rfa_txpowertrackingindex
);
1324 RT_TRACE(COMP_POWER_TRACKING
, "Reset Recovery : RF A I/Q Amplify Gain is %ld\n",priv
->txbbgain_table
[priv
->rfa_txpowertrackingindex
].txbb_iq_amplifygain
);
1325 RT_TRACE(COMP_POWER_TRACKING
, "Reset Recovery: CCK Attenuation is %d dB\n",priv
->CCKPresentAttentuation
);
1326 dm_cck_txpower_adjust(dev
,priv
->bcck_in_ch14
);
1328 rtl8192_setBBreg(dev
, rOFDM0_XCTxIQImbalance
, bMaskDWord
, priv
->txbbgain_table
[priv
->rfc_txpowertrackingindex
].txbbgain_value
);
1329 RT_TRACE(COMP_POWER_TRACKING
, "Reset Recovery: Fill in 0xc90 is %08x\n",priv
->txbbgain_table
[priv
->rfc_txpowertrackingindex
].txbbgain_value
);
1330 RT_TRACE(COMP_POWER_TRACKING
, "Reset Recovery: Fill in RFC_txPowerTrackingIndex is %x\n",priv
->rfc_txpowertrackingindex
);
1331 RT_TRACE(COMP_POWER_TRACKING
, "Reset Recovery : RF C I/Q Amplify Gain is %ld\n",priv
->txbbgain_table
[priv
->rfc_txpowertrackingindex
].txbb_iq_amplifygain
);
1335 void dm_restore_dynamic_mechanism_state(struct net_device
*dev
)
1337 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1338 u32 reg_ratr
= priv
->rate_adaptive
.last_ratr
;
1342 RT_TRACE(COMP_RATE
, "<---- dm_restore_dynamic_mechanism_state(): driver is going to unload\n");
1347 // Restore previous state for rate adaptive
1349 if(priv
->rate_adaptive
.rate_adaptive_disabled
)
1351 // TODO: Only 11n mode is implemented currently,
1352 if( !(priv
->ieee80211
->mode
==WIRELESS_MODE_N_24G
||
1353 priv
->ieee80211
->mode
==WIRELESS_MODE_N_5G
))
1356 /* 2007/11/15 MH Copy from 8190PCI. */
1358 ratr_value
= reg_ratr
;
1359 if(priv
->rf_type
== RF_1T2R
) // 1T2R, Spatial Stream 2 should be disabled
1361 ratr_value
&=~ (RATE_ALL_OFDM_2SS
);
1363 write_nic_dword(dev
, RATR0
, ratr_value
);
1364 write_nic_byte(dev
, UFWP
, 1);
1366 //Resore TX Power Tracking Index
1367 if(priv
->btxpower_trackingInit
&& priv
->btxpower_tracking
){
1368 dm_txpower_reset_recovery(dev
);
1372 //Restore BB Initial Gain
1374 dm_bb_initialgain_restore(dev
);
1378 static void dm_bb_initialgain_restore(struct net_device
*dev
)
1380 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1381 u32 bit_mask
= 0x7f; //Bit0~ Bit6
1383 if(dm_digtable
.dig_algorithm
== DIG_ALGO_BY_RSSI
)
1386 //Disable Initial Gain
1387 //PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x800);
1388 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8); // Only clear byte 1 and rewrite.
1389 rtl8192_setBBreg(dev
, rOFDM0_XAAGCCore1
, bit_mask
, (u32
)priv
->initgain_backup
.xaagccore1
);
1390 rtl8192_setBBreg(dev
, rOFDM0_XBAGCCore1
, bit_mask
, (u32
)priv
->initgain_backup
.xbagccore1
);
1391 rtl8192_setBBreg(dev
, rOFDM0_XCAGCCore1
, bit_mask
, (u32
)priv
->initgain_backup
.xcagccore1
);
1392 rtl8192_setBBreg(dev
, rOFDM0_XDAGCCore1
, bit_mask
, (u32
)priv
->initgain_backup
.xdagccore1
);
1393 bit_mask
= bMaskByte2
;
1394 rtl8192_setBBreg(dev
, rCCK0_CCA
, bit_mask
, (u32
)priv
->initgain_backup
.cca
);
1396 RT_TRACE(COMP_DIG
, "dm_BBInitialGainRestore 0xc50 is %x\n",priv
->initgain_backup
.xaagccore1
);
1397 RT_TRACE(COMP_DIG
, "dm_BBInitialGainRestore 0xc58 is %x\n",priv
->initgain_backup
.xbagccore1
);
1398 RT_TRACE(COMP_DIG
, "dm_BBInitialGainRestore 0xc60 is %x\n",priv
->initgain_backup
.xcagccore1
);
1399 RT_TRACE(COMP_DIG
, "dm_BBInitialGainRestore 0xc68 is %x\n",priv
->initgain_backup
.xdagccore1
);
1400 RT_TRACE(COMP_DIG
, "dm_BBInitialGainRestore 0xa0a is %x\n",priv
->initgain_backup
.cca
);
1401 //Enable Initial Gain
1402 //PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x100);
1403 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x1); // Only clear byte 1 and rewrite.
1408 void dm_backup_dynamic_mechanism_state(struct net_device
*dev
)
1410 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1412 // Fsync to avoid reset
1413 priv
->bswitch_fsync
= false;
1414 priv
->bfsync_processing
= false;
1415 //Backup BB InitialGain
1416 dm_bb_initialgain_backup(dev
);
1421 static void dm_bb_initialgain_backup(struct net_device
*dev
)
1423 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1424 u32 bit_mask
= bMaskByte0
; //Bit0~ Bit6
1426 if(dm_digtable
.dig_algorithm
== DIG_ALGO_BY_RSSI
)
1429 //PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x800);
1430 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8); // Only clear byte 1 and rewrite.
1431 priv
->initgain_backup
.xaagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XAAGCCore1
, bit_mask
);
1432 priv
->initgain_backup
.xbagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XBAGCCore1
, bit_mask
);
1433 priv
->initgain_backup
.xcagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XCAGCCore1
, bit_mask
);
1434 priv
->initgain_backup
.xdagccore1
= (u8
)rtl8192_QueryBBReg(dev
, rOFDM0_XDAGCCore1
, bit_mask
);
1435 bit_mask
= bMaskByte2
;
1436 priv
->initgain_backup
.cca
= (u8
)rtl8192_QueryBBReg(dev
, rCCK0_CCA
, bit_mask
);
1438 RT_TRACE(COMP_DIG
, "BBInitialGainBackup 0xc50 is %x\n",priv
->initgain_backup
.xaagccore1
);
1439 RT_TRACE(COMP_DIG
, "BBInitialGainBackup 0xc58 is %x\n",priv
->initgain_backup
.xbagccore1
);
1440 RT_TRACE(COMP_DIG
, "BBInitialGainBackup 0xc60 is %x\n",priv
->initgain_backup
.xcagccore1
);
1441 RT_TRACE(COMP_DIG
, "BBInitialGainBackup 0xc68 is %x\n",priv
->initgain_backup
.xdagccore1
);
1442 RT_TRACE(COMP_DIG
, "BBInitialGainBackup 0xa0a is %x\n",priv
->initgain_backup
.cca
);
1448 void dm_change_dynamic_initgain_thresh(struct net_device
*dev
, u32 dm_type
, u32 dm_value
)
1450 if (dm_type
== DIG_TYPE_THRESH_HIGH
)
1452 dm_digtable
.rssi_high_thresh
= dm_value
;
1454 else if (dm_type
== DIG_TYPE_THRESH_LOW
)
1456 dm_digtable
.rssi_low_thresh
= dm_value
;
1458 else if (dm_type
== DIG_TYPE_THRESH_HIGHPWR_HIGH
)
1460 dm_digtable
.rssi_high_power_highthresh
= dm_value
;
1462 else if (dm_type
== DIG_TYPE_THRESH_HIGHPWR_HIGH
)
1464 dm_digtable
.rssi_high_power_highthresh
= dm_value
;
1466 else if (dm_type
== DIG_TYPE_ENABLE
)
1468 dm_digtable
.dig_state
= DM_STA_DIG_MAX
;
1469 dm_digtable
.dig_enable_flag
= true;
1471 else if (dm_type
== DIG_TYPE_DISABLE
)
1473 dm_digtable
.dig_state
= DM_STA_DIG_MAX
;
1474 dm_digtable
.dig_enable_flag
= false;
1476 else if (dm_type
== DIG_TYPE_DBG_MODE
)
1478 if(dm_value
>= DM_DBG_MAX
)
1479 dm_value
= DM_DBG_OFF
;
1480 dm_digtable
.dbg_mode
= (u8
)dm_value
;
1482 else if (dm_type
== DIG_TYPE_RSSI
)
1486 dm_digtable
.rssi_val
= (long)dm_value
;
1488 else if (dm_type
== DIG_TYPE_ALGORITHM
)
1490 if (dm_value
>= DIG_ALGO_MAX
)
1491 dm_value
= DIG_ALGO_BY_FALSE_ALARM
;
1492 if(dm_digtable
.dig_algorithm
!= (u8
)dm_value
)
1493 dm_digtable
.dig_algorithm_switch
= 1;
1494 dm_digtable
.dig_algorithm
= (u8
)dm_value
;
1496 else if (dm_type
== DIG_TYPE_BACKOFF
)
1500 dm_digtable
.backoff_val
= (u8
)dm_value
;
1502 else if(dm_type
== DIG_TYPE_RX_GAIN_MIN
)
1506 dm_digtable
.rx_gain_range_min
= (u8
)dm_value
;
1508 else if(dm_type
== DIG_TYPE_RX_GAIN_MAX
)
1512 dm_digtable
.rx_gain_range_max
= (u8
)dm_value
;
1517 /* Set DIG scheme init value. */
1518 static void dm_dig_init(struct net_device
*dev
)
1520 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1521 /* 2007/10/05 MH Disable DIG scheme now. Not tested. */
1522 dm_digtable
.dig_enable_flag
= true;
1523 dm_digtable
.dig_algorithm
= DIG_ALGO_BY_RSSI
;
1524 dm_digtable
.dbg_mode
= DM_DBG_OFF
; //off=by real rssi value, on=by DM_DigTable.Rssi_val for new dig
1525 dm_digtable
.dig_algorithm_switch
= 0;
1527 /* 2007/10/04 MH Define init gain threshold. */
1528 dm_digtable
.dig_state
= DM_STA_DIG_MAX
;
1529 dm_digtable
.dig_highpwr_state
= DM_STA_DIG_MAX
;
1530 dm_digtable
.initialgain_lowerbound_state
= false;
1532 dm_digtable
.rssi_low_thresh
= DM_DIG_THRESH_LOW
;
1533 dm_digtable
.rssi_high_thresh
= DM_DIG_THRESH_HIGH
;
1535 dm_digtable
.rssi_high_power_lowthresh
= DM_DIG_HIGH_PWR_THRESH_LOW
;
1536 dm_digtable
.rssi_high_power_highthresh
= DM_DIG_HIGH_PWR_THRESH_HIGH
;
1538 dm_digtable
.rssi_val
= 50; //for new dig debug rssi value
1539 dm_digtable
.backoff_val
= DM_DIG_BACKOFF
;
1540 dm_digtable
.rx_gain_range_max
= DM_DIG_MAX
;
1541 if(priv
->CustomerID
== RT_CID_819x_Netcore
)
1542 dm_digtable
.rx_gain_range_min
= DM_DIG_MIN_Netcore
;
1544 dm_digtable
.rx_gain_range_min
= DM_DIG_MIN
;
1550 * Driver must monitor RSSI and notify firmware to change initial
1551 * gain according to different threshold. BB team provide the
1552 * suggested solution.
1554 static void dm_ctrl_initgain_byrssi(struct net_device
*dev
)
1557 if (dm_digtable
.dig_enable_flag
== false)
1560 if(dm_digtable
.dig_algorithm
== DIG_ALGO_BY_FALSE_ALARM
)
1561 dm_ctrl_initgain_byrssi_by_fwfalse_alarm(dev
);
1562 else if(dm_digtable
.dig_algorithm
== DIG_ALGO_BY_RSSI
)
1563 dm_ctrl_initgain_byrssi_by_driverrssi(dev
);
1567 static void dm_ctrl_initgain_byrssi_by_driverrssi(
1568 struct net_device
*dev
)
1570 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1574 if (dm_digtable
.dig_enable_flag
== false)
1577 if(dm_digtable
.dig_algorithm_switch
) // if swithed algorithm, we have to disable FW Dig.
1579 if(fw_dig
<= 3) // execute several times to make sure the FW Dig is disabled
1582 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8); // Only clear byte 1 and rewrite.
1584 dm_digtable
.dig_state
= DM_STA_DIG_OFF
; //fw dig off.
1587 if(priv
->ieee80211
->state
== IEEE80211_LINKED
)
1588 dm_digtable
.cur_connect_state
= DIG_CONNECT
;
1590 dm_digtable
.cur_connect_state
= DIG_DISCONNECT
;
1592 if(dm_digtable
.dbg_mode
== DM_DBG_OFF
)
1593 dm_digtable
.rssi_val
= priv
->undecorated_smoothed_pwdb
;
1595 dm_initial_gain(dev
);
1598 if(dm_digtable
.dig_algorithm_switch
)
1599 dm_digtable
.dig_algorithm_switch
= 0;
1600 dm_digtable
.pre_connect_state
= dm_digtable
.cur_connect_state
;
1604 static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
1605 struct net_device
*dev
)
1607 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1608 static u32 reset_cnt
= 0;
1611 if (dm_digtable
.dig_enable_flag
== false)
1614 if(dm_digtable
.dig_algorithm_switch
)
1616 dm_digtable
.dig_state
= DM_STA_DIG_MAX
;
1619 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x1); // Only clear byte 1 and rewrite.
1620 dm_digtable
.dig_algorithm_switch
= 0;
1623 if (priv
->ieee80211
->state
!= IEEE80211_LINKED
)
1626 // For smooth, we can not change DIG state.
1627 if ((priv
->undecorated_smoothed_pwdb
> dm_digtable
.rssi_low_thresh
) &&
1628 (priv
->undecorated_smoothed_pwdb
< dm_digtable
.rssi_high_thresh
))
1633 /* 1. When RSSI decrease, We have to judge if it is smaller than a threshold
1634 and then execute below step. */
1635 if ((priv
->undecorated_smoothed_pwdb
<= dm_digtable
.rssi_low_thresh
))
1637 /* 2008/02/05 MH When we execute silent reset, the DIG PHY parameters
1638 will be reset to init value. We must prevent the condition. */
1639 if (dm_digtable
.dig_state
== DM_STA_DIG_OFF
&&
1640 (priv
->reset_count
== reset_cnt
))
1646 reset_cnt
= priv
->reset_count
;
1649 // If DIG is off, DIG high power state must reset.
1650 dm_digtable
.dig_highpwr_state
= DM_STA_DIG_MAX
;
1651 dm_digtable
.dig_state
= DM_STA_DIG_OFF
;
1654 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x8); // Only clear byte 1 and rewrite.
1656 // 1.2 Set initial gain.
1657 write_nic_byte(dev
, rOFDM0_XAAGCCore1
, 0x17);
1658 write_nic_byte(dev
, rOFDM0_XBAGCCore1
, 0x17);
1659 write_nic_byte(dev
, rOFDM0_XCAGCCore1
, 0x17);
1660 write_nic_byte(dev
, rOFDM0_XDAGCCore1
, 0x17);
1662 // 1.3 Lower PD_TH for OFDM.
1663 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
1665 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1666 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1668 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x40);
1670 write_nic_byte(dev
, (rOFDM0_XATxAFE
+3), 0x00);
1672 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
1673 write_nic_byte(pAdapter, rOFDM0_RxDetector1, 0x40);
1675 //else if (pAdapter->HardwareType == HARDWARE_TYPE_RTL8192E)
1679 //PlatformEFIOWrite1Byte(pAdapter, rOFDM0_RxDetector1, 0x40);
1682 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x42);
1684 // 1.4 Lower CS ratio for CCK.
1685 write_nic_byte(dev
, 0xa0a, 0x08);
1687 // 1.5 Higher EDCCA.
1688 //PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x325);
1693 /* 2. When RSSI increase, We have to judge if it is larger than a threshold
1694 and then execute below step. */
1695 if ((priv
->undecorated_smoothed_pwdb
>= dm_digtable
.rssi_high_thresh
) )
1699 if (dm_digtable
.dig_state
== DM_STA_DIG_ON
&&
1700 (priv
->reset_count
== reset_cnt
))
1702 dm_ctrl_initgain_byrssi_highpwr(dev
);
1707 if (priv
->reset_count
!= reset_cnt
)
1710 reset_cnt
= priv
->reset_count
;
1713 dm_digtable
.dig_state
= DM_STA_DIG_ON
;
1715 // 2.1 Set initial gain.
1716 // 2008/02/26 MH SD3-Jerry suggest to prevent dirty environment.
1717 if (reset_flag
== 1)
1719 write_nic_byte(dev
, rOFDM0_XAAGCCore1
, 0x2c);
1720 write_nic_byte(dev
, rOFDM0_XBAGCCore1
, 0x2c);
1721 write_nic_byte(dev
, rOFDM0_XCAGCCore1
, 0x2c);
1722 write_nic_byte(dev
, rOFDM0_XDAGCCore1
, 0x2c);
1726 write_nic_byte(dev
, rOFDM0_XAAGCCore1
, 0x20);
1727 write_nic_byte(dev
, rOFDM0_XBAGCCore1
, 0x20);
1728 write_nic_byte(dev
, rOFDM0_XCAGCCore1
, 0x20);
1729 write_nic_byte(dev
, rOFDM0_XDAGCCore1
, 0x20);
1732 // 2.2 Higher PD_TH for OFDM.
1733 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
1735 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1736 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1738 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x42);
1740 write_nic_byte(dev
, (rOFDM0_XATxAFE
+3), 0x20);
1743 else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
1744 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
1746 //else if (pAdapter->HardwareType == HARDWARE_TYPE_RTL8192E)
1749 //PlatformEFIOWrite1Byte(pAdapter, rOFDM0_RxDetector1, 0x42);
1752 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x44);
1754 // 2.3 Higher CS ratio for CCK.
1755 write_nic_byte(dev
, 0xa0a, 0xcd);
1758 /* 2008/01/11 MH 90/92 series are the same. */
1759 //PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x346);
1762 rtl8192_setBBreg(dev
, UFWP
, bMaskByte1
, 0x1); // Only clear byte 1 and rewrite.
1766 dm_ctrl_initgain_byrssi_highpwr(dev
);
1770 static void dm_ctrl_initgain_byrssi_highpwr(
1771 struct net_device
* dev
)
1773 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1774 static u32 reset_cnt_highpwr
= 0;
1776 // For smooth, we can not change high power DIG state in the range.
1777 if ((priv
->undecorated_smoothed_pwdb
> dm_digtable
.rssi_high_power_lowthresh
) &&
1778 (priv
->undecorated_smoothed_pwdb
< dm_digtable
.rssi_high_power_highthresh
))
1783 /* 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if
1784 it is larger than a threshold and then execute below step. */
1785 // 2008/02/05 MH SD3-Jerry Modify PD_TH for high power issue.
1786 if (priv
->undecorated_smoothed_pwdb
>= dm_digtable
.rssi_high_power_highthresh
)
1788 if (dm_digtable
.dig_highpwr_state
== DM_STA_DIG_ON
&&
1789 (priv
->reset_count
== reset_cnt_highpwr
))
1792 dm_digtable
.dig_highpwr_state
= DM_STA_DIG_ON
;
1794 // 3.1 Higher PD_TH for OFDM for high power state.
1795 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
1798 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x41);
1800 write_nic_byte(dev
, (rOFDM0_XATxAFE
+3), 0x10);
1803 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
1804 write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
1809 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x43);
1813 if (dm_digtable
.dig_highpwr_state
== DM_STA_DIG_OFF
&&
1814 (priv
->reset_count
== reset_cnt_highpwr
))
1817 dm_digtable
.dig_highpwr_state
= DM_STA_DIG_OFF
;
1819 if (priv
->undecorated_smoothed_pwdb
< dm_digtable
.rssi_high_power_lowthresh
&&
1820 priv
->undecorated_smoothed_pwdb
>= dm_digtable
.rssi_high_thresh
)
1822 // 3.2 Recover PD_TH for OFDM for normal power region.
1823 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
1826 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x42);
1828 write_nic_byte(dev
, (rOFDM0_XATxAFE
+3), 0x20);
1830 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
1831 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
1836 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x44);
1840 reset_cnt_highpwr
= priv
->reset_count
;
1845 static void dm_initial_gain(
1846 struct net_device
* dev
)
1848 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1850 static u8 initialized
=0, force_write
=0;
1851 static u32 reset_cnt
=0;
1853 if(dm_digtable
.dig_algorithm_switch
)
1859 if(dm_digtable
.pre_connect_state
== dm_digtable
.cur_connect_state
)
1861 if(dm_digtable
.cur_connect_state
== DIG_CONNECT
)
1863 if((dm_digtable
.rssi_val
+10-dm_digtable
.backoff_val
) > dm_digtable
.rx_gain_range_max
)
1864 dm_digtable
.cur_ig_value
= dm_digtable
.rx_gain_range_max
;
1865 else if((dm_digtable
.rssi_val
+10-dm_digtable
.backoff_val
) < dm_digtable
.rx_gain_range_min
)
1866 dm_digtable
.cur_ig_value
= dm_digtable
.rx_gain_range_min
;
1868 dm_digtable
.cur_ig_value
= dm_digtable
.rssi_val
+10-dm_digtable
.backoff_val
;
1870 else //current state is disconnected
1872 if(dm_digtable
.cur_ig_value
== 0)
1873 dm_digtable
.cur_ig_value
= priv
->DefaultInitialGain
[0];
1875 dm_digtable
.cur_ig_value
= dm_digtable
.pre_ig_value
;
1878 else // disconnected -> connected or connected -> disconnected
1880 dm_digtable
.cur_ig_value
= priv
->DefaultInitialGain
[0];
1881 dm_digtable
.pre_ig_value
= 0;
1884 // if silent reset happened, we should rewrite the values back
1885 if(priv
->reset_count
!= reset_cnt
)
1888 reset_cnt
= priv
->reset_count
;
1891 if(dm_digtable
.pre_ig_value
!= read_nic_byte(dev
, rOFDM0_XAAGCCore1
))
1895 if((dm_digtable
.pre_ig_value
!= dm_digtable
.cur_ig_value
)
1896 || !initialized
|| force_write
)
1898 initial_gain
= (u8
)dm_digtable
.cur_ig_value
;
1899 // Set initial gain.
1900 write_nic_byte(dev
, rOFDM0_XAAGCCore1
, initial_gain
);
1901 write_nic_byte(dev
, rOFDM0_XBAGCCore1
, initial_gain
);
1902 write_nic_byte(dev
, rOFDM0_XCAGCCore1
, initial_gain
);
1903 write_nic_byte(dev
, rOFDM0_XDAGCCore1
, initial_gain
);
1904 dm_digtable
.pre_ig_value
= dm_digtable
.cur_ig_value
;
1911 static void dm_pd_th(
1912 struct net_device
* dev
)
1914 struct r8192_priv
*priv
= ieee80211_priv(dev
);
1915 static u8 initialized
=0, force_write
=0;
1916 static u32 reset_cnt
= 0;
1918 if(dm_digtable
.dig_algorithm_switch
)
1924 if(dm_digtable
.pre_connect_state
== dm_digtable
.cur_connect_state
)
1926 if(dm_digtable
.cur_connect_state
== DIG_CONNECT
)
1928 if (dm_digtable
.rssi_val
>= dm_digtable
.rssi_high_power_highthresh
)
1929 dm_digtable
.curpd_thstate
= DIG_PD_AT_HIGH_POWER
;
1930 else if ((dm_digtable
.rssi_val
<= dm_digtable
.rssi_low_thresh
))
1931 dm_digtable
.curpd_thstate
= DIG_PD_AT_LOW_POWER
;
1932 else if ((dm_digtable
.rssi_val
>= dm_digtable
.rssi_high_thresh
) &&
1933 (dm_digtable
.rssi_val
< dm_digtable
.rssi_high_power_lowthresh
))
1934 dm_digtable
.curpd_thstate
= DIG_PD_AT_NORMAL_POWER
;
1936 dm_digtable
.curpd_thstate
= dm_digtable
.prepd_thstate
;
1940 dm_digtable
.curpd_thstate
= DIG_PD_AT_LOW_POWER
;
1943 else // disconnected -> connected or connected -> disconnected
1945 dm_digtable
.curpd_thstate
= DIG_PD_AT_LOW_POWER
;
1948 // if silent reset happened, we should rewrite the values back
1949 if(priv
->reset_count
!= reset_cnt
)
1952 reset_cnt
= priv
->reset_count
;
1956 if((dm_digtable
.prepd_thstate
!= dm_digtable
.curpd_thstate
) ||
1957 (initialized
<=3) || force_write
)
1959 if(dm_digtable
.curpd_thstate
== DIG_PD_AT_LOW_POWER
)
1961 // Lower PD_TH for OFDM.
1962 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
1964 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1965 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1967 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x40);
1969 write_nic_byte(dev
, (rOFDM0_XATxAFE
+3), 0x00);
1971 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
1972 write_nic_byte(dev, rOFDM0_RxDetector1, 0x40);
1976 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x42);
1978 else if(dm_digtable
.curpd_thstate
== DIG_PD_AT_NORMAL_POWER
)
1980 // Higher PD_TH for OFDM.
1981 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
1983 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
1984 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
1986 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x42);
1988 write_nic_byte(dev
, (rOFDM0_XATxAFE
+3), 0x20);
1990 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
1991 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
1995 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x44);
1997 else if(dm_digtable
.curpd_thstate
== DIG_PD_AT_HIGH_POWER
)
1999 // Higher PD_TH for OFDM for high power state.
2000 if (priv
->CurrentChannelBW
!= HT_CHANNEL_WIDTH_20
)
2003 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x41);
2005 write_nic_byte(dev
, (rOFDM0_XATxAFE
+3), 0x10);
2007 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2008 write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
2012 write_nic_byte(dev
, rOFDM0_RxDetector1
, 0x43);
2014 dm_digtable
.prepd_thstate
= dm_digtable
.curpd_thstate
;
2015 if(initialized
<= 3)
2022 static void dm_cs_ratio(
2023 struct net_device
* dev
)
2025 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2026 static u8 initialized
=0,force_write
=0;
2027 static u32 reset_cnt
= 0;
2029 if(dm_digtable
.dig_algorithm_switch
)
2035 if(dm_digtable
.pre_connect_state
== dm_digtable
.cur_connect_state
)
2037 if(dm_digtable
.cur_connect_state
== DIG_CONNECT
)
2039 if ((dm_digtable
.rssi_val
<= dm_digtable
.rssi_low_thresh
))
2040 dm_digtable
.curcs_ratio_state
= DIG_CS_RATIO_LOWER
;
2041 else if ((dm_digtable
.rssi_val
>= dm_digtable
.rssi_high_thresh
) )
2042 dm_digtable
.curcs_ratio_state
= DIG_CS_RATIO_HIGHER
;
2044 dm_digtable
.curcs_ratio_state
= dm_digtable
.precs_ratio_state
;
2048 dm_digtable
.curcs_ratio_state
= DIG_CS_RATIO_LOWER
;
2051 else // disconnected -> connected or connected -> disconnected
2053 dm_digtable
.curcs_ratio_state
= DIG_CS_RATIO_LOWER
;
2056 // if silent reset happened, we should rewrite the values back
2057 if(priv
->reset_count
!= reset_cnt
)
2060 reset_cnt
= priv
->reset_count
;
2064 if((dm_digtable
.precs_ratio_state
!= dm_digtable
.curcs_ratio_state
) ||
2065 !initialized
|| force_write
)
2067 if(dm_digtable
.curcs_ratio_state
== DIG_CS_RATIO_LOWER
)
2069 // Lower CS ratio for CCK.
2070 write_nic_byte(dev
, 0xa0a, 0x08);
2072 else if(dm_digtable
.curcs_ratio_state
== DIG_CS_RATIO_HIGHER
)
2074 // Higher CS ratio for CCK.
2075 write_nic_byte(dev
, 0xa0a, 0xcd);
2077 dm_digtable
.precs_ratio_state
= dm_digtable
.curcs_ratio_state
;
2083 void dm_init_edca_turbo(struct net_device
*dev
)
2085 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2087 priv
->bcurrent_turbo_EDCA
= false;
2088 priv
->ieee80211
->bis_any_nonbepkts
= false;
2089 priv
->bis_cur_rdlstate
= false;
2093 static void dm_check_edca_turbo(
2094 struct net_device
* dev
)
2096 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2097 PRT_HIGH_THROUGHPUT pHTInfo
= priv
->ieee80211
->pHTInfo
;
2098 //PSTA_QOS pStaQos = pMgntInfo->pStaQos;
2100 // Keep past Tx/Rx packet count for RT-to-RT EDCA turbo.
2101 static unsigned long lastTxOkCnt
= 0;
2102 static unsigned long lastRxOkCnt
= 0;
2103 unsigned long curTxOkCnt
= 0;
2104 unsigned long curRxOkCnt
= 0;
2107 // Do not be Turbo if it's under WiFi config and Qos Enabled, because the EDCA parameters
2108 // should follow the settings from QAP. By Bruce, 2007-12-07.
2111 if(priv
->ieee80211
->state
!= IEEE80211_LINKED
)
2112 goto dm_CheckEdcaTurbo_EXIT
;
2114 // We do not turn on EDCA turbo mode for some AP that has IOT issue
2115 if(priv
->ieee80211
->pHTInfo
->IOTAction
& HT_IOT_ACT_DISABLE_EDCA_TURBO
)
2116 goto dm_CheckEdcaTurbo_EXIT
;
2118 // Check the status for current condition.
2119 if(!priv
->ieee80211
->bis_any_nonbepkts
)
2121 curTxOkCnt
= priv
->stats
.txbytesunicast
- lastTxOkCnt
;
2122 curRxOkCnt
= priv
->stats
.rxbytesunicast
- lastRxOkCnt
;
2123 // For RT-AP, we needs to turn it on when Rx>Tx
2124 if(curRxOkCnt
> 4*curTxOkCnt
)
2126 if(!priv
->bis_cur_rdlstate
|| !priv
->bcurrent_turbo_EDCA
)
2128 write_nic_dword(dev
, EDCAPARA_BE
, edca_setting_DL
[pHTInfo
->IOTPeer
]);
2129 priv
->bis_cur_rdlstate
= true;
2134 if(priv
->bis_cur_rdlstate
|| !priv
->bcurrent_turbo_EDCA
)
2136 write_nic_dword(dev
, EDCAPARA_BE
, edca_setting_UL
[pHTInfo
->IOTPeer
]);
2137 priv
->bis_cur_rdlstate
= false;
2142 priv
->bcurrent_turbo_EDCA
= true;
2147 // Turn Off EDCA turbo here.
2148 // Restore original EDCA according to the declaration of AP.
2150 if(priv
->bcurrent_turbo_EDCA
)
2156 struct ieee80211_qos_parameters
*qos_parameters
= &priv
->ieee80211
->current_network
.qos_data
.parameters
;
2157 u8 mode
= priv
->ieee80211
->mode
;
2159 // For Each time updating EDCA parameter, reset EDCA turbo mode status.
2160 dm_init_edca_turbo(dev
);
2161 u1bAIFS
= qos_parameters
->aifs
[0] * ((mode
&(IEEE_G
|IEEE_N_24G
)) ?9:20) + aSifsTime
;
2162 u4bAcParam
= ((((u32
)(qos_parameters
->tx_op_limit
[0]))<< AC_PARAM_TXOP_LIMIT_OFFSET
)|
2163 (((u32
)(qos_parameters
->cw_max
[0]))<< AC_PARAM_ECW_MAX_OFFSET
)|
2164 (((u32
)(qos_parameters
->cw_min
[0]))<< AC_PARAM_ECW_MIN_OFFSET
)|
2165 ((u32
)u1bAIFS
<< AC_PARAM_AIFS_OFFSET
));
2166 printk("===>u4bAcParam:%x, ", u4bAcParam
);
2167 //write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
2168 write_nic_dword(dev
, EDCAPARA_BE
, u4bAcParam
);
2171 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
2173 // TODO: Modified this part and try to set acm control in only 1 IO processing!!
2175 PACI_AIFSN pAciAifsn
= (PACI_AIFSN
)&(qos_parameters
->aifs
[0]);
2176 u8 AcmCtrl
= read_nic_byte( dev
, AcmHwCtrl
);
2177 if( pAciAifsn
->f
.ACM
)
2179 AcmCtrl
|= AcmHw_BeqEn
;
2183 AcmCtrl
&= (~AcmHw_BeqEn
);
2186 RT_TRACE( COMP_QOS
,"SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl
) ;
2187 write_nic_byte(dev
, AcmHwCtrl
, AcmCtrl
);
2190 priv
->bcurrent_turbo_EDCA
= false;
2195 dm_CheckEdcaTurbo_EXIT
:
2196 // Set variables for next time.
2197 priv
->ieee80211
->bis_any_nonbepkts
= false;
2198 lastTxOkCnt
= priv
->stats
.txbytesunicast
;
2199 lastRxOkCnt
= priv
->stats
.rxbytesunicast
;
2203 static void dm_init_ctstoself(struct net_device
* dev
)
2205 struct r8192_priv
*priv
= ieee80211_priv((struct net_device
*)dev
);
2207 priv
->ieee80211
->bCTSToSelfEnable
= TRUE
;
2208 priv
->ieee80211
->CTSToSelfTH
= CTSToSelfTHVal
;
2211 static void dm_ctstoself(struct net_device
*dev
)
2213 struct r8192_priv
*priv
= ieee80211_priv((struct net_device
*)dev
);
2214 PRT_HIGH_THROUGHPUT pHTInfo
= priv
->ieee80211
->pHTInfo
;
2215 static unsigned long lastTxOkCnt
= 0;
2216 static unsigned long lastRxOkCnt
= 0;
2217 unsigned long curTxOkCnt
= 0;
2218 unsigned long curRxOkCnt
= 0;
2220 if(priv
->ieee80211
->bCTSToSelfEnable
!= TRUE
)
2222 pHTInfo
->IOTAction
&= ~HT_IOT_ACT_FORCED_CTS2SELF
;
2227 2. Linksys350/Linksys300N
2228 3. <50 disable, >55 enable
2231 if(pHTInfo
->IOTPeer
== HT_IOT_PEER_BROADCOM
)
2233 curTxOkCnt
= priv
->stats
.txbytesunicast
- lastTxOkCnt
;
2234 curRxOkCnt
= priv
->stats
.rxbytesunicast
- lastRxOkCnt
;
2235 if(curRxOkCnt
> 4*curTxOkCnt
) //downlink, disable CTS to self
2237 pHTInfo
->IOTAction
&= ~HT_IOT_ACT_FORCED_CTS2SELF
;
2242 pHTInfo
->IOTAction
|= HT_IOT_ACT_FORCED_CTS2SELF
;
2244 if(priv
->undecorated_smoothed_pwdb
< priv
->ieee80211
->CTSToSelfTH
) // disable CTS to self
2246 pHTInfo
->IOTAction
&= ~HT_IOT_ACT_FORCED_CTS2SELF
;
2248 else if(priv
->undecorated_smoothed_pwdb
>= (priv
->ieee80211
->CTSToSelfTH
+5)) // enable CTS to self
2250 pHTInfo
->IOTAction
|= HT_IOT_ACT_FORCED_CTS2SELF
;
2255 lastTxOkCnt
= priv
->stats
.txbytesunicast
;
2256 lastRxOkCnt
= priv
->stats
.rxbytesunicast
;
2262 /* Copy 8187B template for 9xseries */
2264 static void dm_check_rfctrl_gpio(struct net_device
* dev
)
2267 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2270 // Walk around for DTM test, we will not enable HW - radio on/off because r/w
2271 // page 1 register before Lextra bus is enabled cause system fails when resuming
2272 // from S4. 20080218, Emily
2274 // Stop to execute workitem to prevent S3/S4 bug.
2282 queue_delayed_work(priv
->priv_wq
,&priv
->gpio_change_rf_wq
,0);
2288 /* Check if PBC button is pressed. */
2289 static void dm_check_pbc_gpio(struct net_device
*dev
)
2292 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2296 tmp1byte
= read_nic_byte(dev
,GPI
);
2297 if(tmp1byte
== 0xff)
2300 if (tmp1byte
&BIT6
|| tmp1byte
&BIT0
)
2302 // Here we only set bPbcPressed to TRUE
2303 // After trigger PBC, the variable will be set to FALSE
2304 RT_TRACE(COMP_IO
, "CheckPbcGPIO - PBC is pressed\n");
2305 priv
->bpbc_pressed
= true;
2313 /* PCI will not support workitem call back HW radio on-off control. */
2314 void dm_gpio_change_rf_callback(struct work_struct
*work
)
2316 struct delayed_work
*dwork
= container_of(work
,struct delayed_work
,work
);
2317 struct r8192_priv
*priv
= container_of(dwork
,struct r8192_priv
,gpio_change_rf_wq
);
2318 struct net_device
*dev
= priv
->ieee80211
->dev
;
2320 RT_RF_POWER_STATE eRfPowerStateToSet
;
2321 bool bActuallySet
= false;
2324 RT_TRACE((COMP_INIT
| COMP_POWER
| COMP_RF
),"dm_gpio_change_rf_callback(): Callback function breaks out!!\n");
2326 // 0x108 GPIO input register is read only
2327 //set 0x108 B1= 1: RF-ON; 0: RF-OFF.
2328 tmp1byte
= read_nic_byte(dev
,GPI
);
2330 eRfPowerStateToSet
= (tmp1byte
&BIT1
) ? eRfOn
: eRfOff
;
2332 if (priv
->bHwRadioOff
&& (eRfPowerStateToSet
== eRfOn
)) {
2333 RT_TRACE(COMP_RF
, "gpiochangeRF - HW Radio ON\n");
2335 priv
->bHwRadioOff
= false;
2336 bActuallySet
= true;
2337 } else if ((!priv
->bHwRadioOff
) && (eRfPowerStateToSet
== eRfOff
)) {
2338 RT_TRACE(COMP_RF
, "gpiochangeRF - HW Radio OFF\n");
2339 priv
->bHwRadioOff
= true;
2340 bActuallySet
= true;
2344 priv
->bHwRfOffAction
= 1;
2345 MgntActSet_RF_State(dev
, eRfPowerStateToSet
, RF_CHANGE_BY_HW
);
2346 //DrvIFIndicateCurrentPhyStatus(pAdapter);
2355 /* Check if Current RF RX path is enabled */
2356 void dm_rf_pathcheck_workitemcallback(struct work_struct
*work
)
2358 struct delayed_work
*dwork
= container_of(work
,struct delayed_work
,work
);
2359 struct r8192_priv
*priv
= container_of(dwork
,struct r8192_priv
,rfpath_check_wq
);
2360 struct net_device
*dev
=priv
->ieee80211
->dev
;
2361 //bool bactually_set = false;
2365 /* 2008/01/30 MH After discussing with SD3 Jerry, 0xc04/0xd04 register will
2366 always be the same. We only read 0xc04 now. */
2367 rfpath
= read_nic_byte(dev
, 0xc04);
2369 // Check Bit 0-3, it means if RF A-D is enabled.
2370 for (i
= 0; i
< RF90_PATH_MAX
; i
++)
2372 if (rfpath
& (0x01<<i
))
2373 priv
->brfpath_rxenable
[i
] = 1;
2375 priv
->brfpath_rxenable
[i
] = 0;
2377 if(!DM_RxPathSelTable
.Enable
)
2380 dm_rxpath_sel_byrssi(dev
);
2383 static void dm_init_rxpath_selection(struct net_device
* dev
)
2386 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2387 DM_RxPathSelTable
.Enable
= 1; //default enabled
2388 DM_RxPathSelTable
.SS_TH_low
= RxPathSelection_SS_TH_low
;
2389 DM_RxPathSelTable
.diff_TH
= RxPathSelection_diff_TH
;
2390 if(priv
->CustomerID
== RT_CID_819x_Netcore
)
2391 DM_RxPathSelTable
.cck_method
= CCK_Rx_Version_2
;
2393 DM_RxPathSelTable
.cck_method
= CCK_Rx_Version_1
;
2394 DM_RxPathSelTable
.DbgMode
= DM_DBG_OFF
;
2395 DM_RxPathSelTable
.disabledRF
= 0;
2398 DM_RxPathSelTable
.rf_rssi
[i
] = 50;
2399 DM_RxPathSelTable
.cck_pwdb_sta
[i
] = -64;
2400 DM_RxPathSelTable
.rf_enable_rssi_th
[i
] = 100;
2404 static void dm_rxpath_sel_byrssi(struct net_device
* dev
)
2406 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2407 u8 i
, max_rssi_index
=0, min_rssi_index
=0, sec_rssi_index
=0, rf_num
=0;
2408 u8 tmp_max_rssi
=0, tmp_min_rssi
=0, tmp_sec_rssi
=0;
2409 u8 cck_default_Rx
=0x2; //RF-C
2410 u8 cck_optional_Rx
=0x3;//RF-D
2411 long tmp_cck_max_pwdb
=0, tmp_cck_min_pwdb
=0, tmp_cck_sec_pwdb
=0;
2412 u8 cck_rx_ver2_max_index
=0, cck_rx_ver2_min_index
=0, cck_rx_ver2_sec_index
=0;
2415 static u8 disabled_rf_cnt
=0, cck_Rx_Path_initialized
=0;
2416 u8 update_cck_rx_path
;
2418 if(priv
->rf_type
!= RF_2T4R
)
2421 if(!cck_Rx_Path_initialized
)
2423 DM_RxPathSelTable
.cck_Rx_path
= (read_nic_byte(dev
, 0xa07)&0xf);
2424 cck_Rx_Path_initialized
= 1;
2427 DM_RxPathSelTable
.disabledRF
= 0xf;
2428 DM_RxPathSelTable
.disabledRF
&=~ (read_nic_byte(dev
, 0xc04));
2430 if(priv
->ieee80211
->mode
== WIRELESS_MODE_B
)
2432 DM_RxPathSelTable
.cck_method
= CCK_Rx_Version_2
; //pure B mode, fixed cck version2
2435 //decide max/sec/min rssi index
2436 for (i
=0; i
<RF90_PATH_MAX
; i
++)
2438 if(!DM_RxPathSelTable
.DbgMode
)
2439 DM_RxPathSelTable
.rf_rssi
[i
] = priv
->stats
.rx_rssi_percentage
[i
];
2441 if(priv
->brfpath_rxenable
[i
])
2444 cur_rf_rssi
= DM_RxPathSelTable
.rf_rssi
[i
];
2446 if(rf_num
== 1) // find first enabled rf path and the rssi values
2447 { //initialize, set all rssi index to the same one
2448 max_rssi_index
= min_rssi_index
= sec_rssi_index
= i
;
2449 tmp_max_rssi
= tmp_min_rssi
= tmp_sec_rssi
= cur_rf_rssi
;
2451 else if(rf_num
== 2)
2452 { // we pick up the max index first, and let sec and min to be the same one
2453 if(cur_rf_rssi
>= tmp_max_rssi
)
2455 tmp_max_rssi
= cur_rf_rssi
;
2460 tmp_sec_rssi
= tmp_min_rssi
= cur_rf_rssi
;
2461 sec_rssi_index
= min_rssi_index
= i
;
2466 if(cur_rf_rssi
> tmp_max_rssi
)
2468 tmp_sec_rssi
= tmp_max_rssi
;
2469 sec_rssi_index
= max_rssi_index
;
2470 tmp_max_rssi
= cur_rf_rssi
;
2473 else if(cur_rf_rssi
== tmp_max_rssi
)
2474 { // let sec and min point to the different index
2475 tmp_sec_rssi
= cur_rf_rssi
;
2478 else if((cur_rf_rssi
< tmp_max_rssi
) &&(cur_rf_rssi
> tmp_sec_rssi
))
2480 tmp_sec_rssi
= cur_rf_rssi
;
2483 else if(cur_rf_rssi
== tmp_sec_rssi
)
2485 if(tmp_sec_rssi
== tmp_min_rssi
)
2486 { // let sec and min point to the different index
2487 tmp_sec_rssi
= cur_rf_rssi
;
2492 // This case we don't need to set any index
2495 else if((cur_rf_rssi
< tmp_sec_rssi
) && (cur_rf_rssi
> tmp_min_rssi
))
2497 // This case we don't need to set any index
2499 else if(cur_rf_rssi
== tmp_min_rssi
)
2501 if(tmp_sec_rssi
== tmp_min_rssi
)
2502 { // let sec and min point to the different index
2503 tmp_min_rssi
= cur_rf_rssi
;
2508 // This case we don't need to set any index
2511 else if(cur_rf_rssi
< tmp_min_rssi
)
2513 tmp_min_rssi
= cur_rf_rssi
;
2521 // decide max/sec/min cck pwdb index
2522 if(DM_RxPathSelTable
.cck_method
== CCK_Rx_Version_2
)
2524 for (i
=0; i
<RF90_PATH_MAX
; i
++)
2526 if(priv
->brfpath_rxenable
[i
])
2529 cur_cck_pwdb
= DM_RxPathSelTable
.cck_pwdb_sta
[i
];
2531 if(rf_num
== 1) // find first enabled rf path and the rssi values
2532 { //initialize, set all rssi index to the same one
2533 cck_rx_ver2_max_index
= cck_rx_ver2_min_index
= cck_rx_ver2_sec_index
= i
;
2534 tmp_cck_max_pwdb
= tmp_cck_min_pwdb
= tmp_cck_sec_pwdb
= cur_cck_pwdb
;
2536 else if(rf_num
== 2)
2537 { // we pick up the max index first, and let sec and min to be the same one
2538 if(cur_cck_pwdb
>= tmp_cck_max_pwdb
)
2540 tmp_cck_max_pwdb
= cur_cck_pwdb
;
2541 cck_rx_ver2_max_index
= i
;
2545 tmp_cck_sec_pwdb
= tmp_cck_min_pwdb
= cur_cck_pwdb
;
2546 cck_rx_ver2_sec_index
= cck_rx_ver2_min_index
= i
;
2551 if(cur_cck_pwdb
> tmp_cck_max_pwdb
)
2553 tmp_cck_sec_pwdb
= tmp_cck_max_pwdb
;
2554 cck_rx_ver2_sec_index
= cck_rx_ver2_max_index
;
2555 tmp_cck_max_pwdb
= cur_cck_pwdb
;
2556 cck_rx_ver2_max_index
= i
;
2558 else if(cur_cck_pwdb
== tmp_cck_max_pwdb
)
2559 { // let sec and min point to the different index
2560 tmp_cck_sec_pwdb
= cur_cck_pwdb
;
2561 cck_rx_ver2_sec_index
= i
;
2563 else if((cur_cck_pwdb
< tmp_cck_max_pwdb
) &&(cur_cck_pwdb
> tmp_cck_sec_pwdb
))
2565 tmp_cck_sec_pwdb
= cur_cck_pwdb
;
2566 cck_rx_ver2_sec_index
= i
;
2568 else if(cur_cck_pwdb
== tmp_cck_sec_pwdb
)
2570 if(tmp_cck_sec_pwdb
== tmp_cck_min_pwdb
)
2571 { // let sec and min point to the different index
2572 tmp_cck_sec_pwdb
= cur_cck_pwdb
;
2573 cck_rx_ver2_sec_index
= i
;
2577 // This case we don't need to set any index
2580 else if((cur_cck_pwdb
< tmp_cck_sec_pwdb
) && (cur_cck_pwdb
> tmp_cck_min_pwdb
))
2582 // This case we don't need to set any index
2584 else if(cur_cck_pwdb
== tmp_cck_min_pwdb
)
2586 if(tmp_cck_sec_pwdb
== tmp_cck_min_pwdb
)
2587 { // let sec and min point to the different index
2588 tmp_cck_min_pwdb
= cur_cck_pwdb
;
2589 cck_rx_ver2_min_index
= i
;
2593 // This case we don't need to set any index
2596 else if(cur_cck_pwdb
< tmp_cck_min_pwdb
)
2598 tmp_cck_min_pwdb
= cur_cck_pwdb
;
2599 cck_rx_ver2_min_index
= i
;
2609 // reg0xA07[3:2]=cck default rx path, reg0xa07[1:0]=cck optional rx path.
2610 update_cck_rx_path
= 0;
2611 if(DM_RxPathSelTable
.cck_method
== CCK_Rx_Version_2
)
2613 cck_default_Rx
= cck_rx_ver2_max_index
;
2614 cck_optional_Rx
= cck_rx_ver2_sec_index
;
2615 if(tmp_cck_max_pwdb
!= -64)
2616 update_cck_rx_path
= 1;
2619 if(tmp_min_rssi
< DM_RxPathSelTable
.SS_TH_low
&& disabled_rf_cnt
< 2)
2621 if((tmp_max_rssi
- tmp_min_rssi
) >= DM_RxPathSelTable
.diff_TH
)
2623 //record the enabled rssi threshold
2624 DM_RxPathSelTable
.rf_enable_rssi_th
[min_rssi_index
] = tmp_max_rssi
+5;
2625 //disable the BB Rx path, OFDM
2626 rtl8192_setBBreg(dev
, rOFDM0_TRxPathEnable
, 0x1<<min_rssi_index
, 0x0); // 0xc04[3:0]
2627 rtl8192_setBBreg(dev
, rOFDM1_TRxPathEnable
, 0x1<<min_rssi_index
, 0x0); // 0xd04[3:0]
2630 if(DM_RxPathSelTable
.cck_method
== CCK_Rx_Version_1
)
2632 cck_default_Rx
= max_rssi_index
;
2633 cck_optional_Rx
= sec_rssi_index
;
2635 update_cck_rx_path
= 1;
2639 if(update_cck_rx_path
)
2641 DM_RxPathSelTable
.cck_Rx_path
= (cck_default_Rx
<<2)|(cck_optional_Rx
);
2642 rtl8192_setBBreg(dev
, rCCK0_AFESetting
, 0x0f000000, DM_RxPathSelTable
.cck_Rx_path
);
2645 if(DM_RxPathSelTable
.disabledRF
)
2649 if((DM_RxPathSelTable
.disabledRF
>>i
) & 0x1) //disabled rf
2651 if(tmp_max_rssi
>= DM_RxPathSelTable
.rf_enable_rssi_th
[i
])
2653 //enable the BB Rx path
2654 rtl8192_setBBreg(dev
, rOFDM0_TRxPathEnable
, 0x1<<i
, 0x1); // 0xc04[3:0]
2655 rtl8192_setBBreg(dev
, rOFDM1_TRxPathEnable
, 0x1<<i
, 0x1); // 0xd04[3:0]
2656 DM_RxPathSelTable
.rf_enable_rssi_th
[i
] = 100;
2665 * Call a workitem to check current RXRF path and Rx Path selection by RSSI.
2667 static void dm_check_rx_path_selection(struct net_device
*dev
)
2669 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2670 queue_delayed_work(priv
->priv_wq
,&priv
->rfpath_check_wq
,0);
2673 static void dm_init_fsync (struct net_device
*dev
)
2675 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2677 priv
->ieee80211
->fsync_time_interval
= 500;
2678 priv
->ieee80211
->fsync_rate_bitmap
= 0x0f000800;
2679 priv
->ieee80211
->fsync_rssi_threshold
= 30;
2681 priv
->ieee80211
->bfsync_enable
= true;
2683 priv
->ieee80211
->bfsync_enable
= false;
2685 priv
->ieee80211
->fsync_multiple_timeinterval
= 3;
2686 priv
->ieee80211
->fsync_firstdiff_ratethreshold
= 100;
2687 priv
->ieee80211
->fsync_seconddiff_ratethreshold
= 200;
2688 priv
->ieee80211
->fsync_state
= Default_Fsync
;
2689 priv
->framesyncMonitor
= 1; // current default 0xc38 monitor on
2691 init_timer(&priv
->fsync_timer
);
2692 priv
->fsync_timer
.data
= (unsigned long)dev
;
2693 priv
->fsync_timer
.function
= dm_fsync_timer_callback
;
2697 static void dm_deInit_fsync(struct net_device
*dev
)
2699 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2700 del_timer_sync(&priv
->fsync_timer
);
2703 void dm_fsync_timer_callback(unsigned long data
)
2705 struct net_device
*dev
= (struct net_device
*)data
;
2706 struct r8192_priv
*priv
= ieee80211_priv((struct net_device
*)data
);
2707 u32 rate_index
, rate_count
= 0, rate_count_diff
=0;
2708 bool bSwitchFromCountDiff
= false;
2709 bool bDoubleTimeInterval
= false;
2711 if( priv
->ieee80211
->state
== IEEE80211_LINKED
&&
2712 priv
->ieee80211
->bfsync_enable
&&
2713 (priv
->ieee80211
->pHTInfo
->IOTAction
& HT_IOT_ACT_CDD_FSYNC
))
2715 // Count rate 54, MCS [7], [12, 13, 14, 15]
2717 for(rate_index
= 0; rate_index
<= 27; rate_index
++)
2719 rate_bitmap
= 1 << rate_index
;
2720 if(priv
->ieee80211
->fsync_rate_bitmap
& rate_bitmap
)
2721 rate_count
+= priv
->stats
.received_rate_histogram
[1][rate_index
];
2724 if(rate_count
< priv
->rate_record
)
2725 rate_count_diff
= 0xffffffff - rate_count
+ priv
->rate_record
;
2727 rate_count_diff
= rate_count
- priv
->rate_record
;
2728 if(rate_count_diff
< priv
->rateCountDiffRecord
)
2731 u32 DiffNum
= priv
->rateCountDiffRecord
- rate_count_diff
;
2733 if(DiffNum
>= priv
->ieee80211
->fsync_seconddiff_ratethreshold
)
2734 priv
->ContiuneDiffCount
++;
2736 priv
->ContiuneDiffCount
= 0;
2738 // Contiune count over
2739 if(priv
->ContiuneDiffCount
>=2)
2741 bSwitchFromCountDiff
= true;
2742 priv
->ContiuneDiffCount
= 0;
2747 // Stop contiune count
2748 priv
->ContiuneDiffCount
= 0;
2751 //If Count diff <= FsyncRateCountThreshold
2752 if(rate_count_diff
<= priv
->ieee80211
->fsync_firstdiff_ratethreshold
)
2754 bSwitchFromCountDiff
= true;
2755 priv
->ContiuneDiffCount
= 0;
2757 priv
->rate_record
= rate_count
;
2758 priv
->rateCountDiffRecord
= rate_count_diff
;
2759 RT_TRACE(COMP_HALDM
, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv
->rate_record
, rate_count
, rate_count_diff
, priv
->bswitch_fsync
);
2760 // if we never receive those mcs rate and rssi > 30 % then switch fsyn
2761 if(priv
->undecorated_smoothed_pwdb
> priv
->ieee80211
->fsync_rssi_threshold
&& bSwitchFromCountDiff
)
2763 bDoubleTimeInterval
= true;
2764 priv
->bswitch_fsync
= !priv
->bswitch_fsync
;
2765 if(priv
->bswitch_fsync
)
2768 write_nic_byte(dev
,0xC36, 0x00);
2770 write_nic_byte(dev
,0xC36, 0x1c);
2772 write_nic_byte(dev
, 0xC3e, 0x90);
2777 write_nic_byte(dev
, 0xC36, 0x40);
2779 write_nic_byte(dev
, 0xC36, 0x5c);
2781 write_nic_byte(dev
, 0xC3e, 0x96);
2784 else if(priv
->undecorated_smoothed_pwdb
<= priv
->ieee80211
->fsync_rssi_threshold
)
2786 if(priv
->bswitch_fsync
)
2788 priv
->bswitch_fsync
= false;
2790 write_nic_byte(dev
, 0xC36, 0x40);
2792 write_nic_byte(dev
, 0xC36, 0x5c);
2794 write_nic_byte(dev
, 0xC3e, 0x96);
2797 if(bDoubleTimeInterval
){
2798 if(timer_pending(&priv
->fsync_timer
))
2799 del_timer_sync(&priv
->fsync_timer
);
2800 priv
->fsync_timer
.expires
= jiffies
+ MSECS(priv
->ieee80211
->fsync_time_interval
*priv
->ieee80211
->fsync_multiple_timeinterval
);
2801 add_timer(&priv
->fsync_timer
);
2804 if(timer_pending(&priv
->fsync_timer
))
2805 del_timer_sync(&priv
->fsync_timer
);
2806 priv
->fsync_timer
.expires
= jiffies
+ MSECS(priv
->ieee80211
->fsync_time_interval
);
2807 add_timer(&priv
->fsync_timer
);
2812 // Let Register return to default value;
2813 if(priv
->bswitch_fsync
)
2815 priv
->bswitch_fsync
= false;
2817 write_nic_byte(dev
, 0xC36, 0x40);
2819 write_nic_byte(dev
, 0xC36, 0x5c);
2821 write_nic_byte(dev
, 0xC3e, 0x96);
2823 priv
->ContiuneDiffCount
= 0;
2825 write_nic_dword(dev
, rOFDM0_RxDetector2
, 0x164052cd);
2827 write_nic_dword(dev
, rOFDM0_RxDetector2
, 0x465c52cd);
2830 RT_TRACE(COMP_HALDM
, "ContiuneDiffCount %d\n", priv
->ContiuneDiffCount
);
2831 RT_TRACE(COMP_HALDM
, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv
->rate_record
, rate_count
, rate_count_diff
, priv
->bswitch_fsync
);
2834 static void dm_StartHWFsync(struct net_device
*dev
)
2836 RT_TRACE(COMP_HALDM
, "%s\n", __FUNCTION__
);
2837 write_nic_dword(dev
, rOFDM0_RxDetector2
, 0x465c12cf);
2838 write_nic_byte(dev
, 0xc3b, 0x41);
2841 static void dm_EndSWFsync(struct net_device
*dev
)
2843 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2845 RT_TRACE(COMP_HALDM
, "%s\n", __FUNCTION__
);
2846 del_timer_sync(&(priv
->fsync_timer
));
2848 // Let Register return to default value;
2849 if(priv
->bswitch_fsync
)
2851 priv
->bswitch_fsync
= false;
2854 write_nic_byte(dev
, 0xC36, 0x40);
2856 write_nic_byte(dev
, 0xC36, 0x5c);
2859 write_nic_byte(dev
, 0xC3e, 0x96);
2862 priv
->ContiuneDiffCount
= 0;
2864 write_nic_dword(dev
, rOFDM0_RxDetector2
, 0x465c52cd);
2869 static void dm_StartSWFsync(struct net_device
*dev
)
2871 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2875 RT_TRACE(COMP_HALDM
,"%s\n", __FUNCTION__
);
2876 // Initial rate record to zero, start to record.
2877 priv
->rate_record
= 0;
2878 // Initial contiune diff count to zero, start to record.
2879 priv
->ContiuneDiffCount
= 0;
2880 priv
->rateCountDiffRecord
= 0;
2881 priv
->bswitch_fsync
= false;
2883 if(priv
->ieee80211
->mode
== WIRELESS_MODE_N_24G
)
2885 priv
->ieee80211
->fsync_firstdiff_ratethreshold
= 600;
2886 priv
->ieee80211
->fsync_seconddiff_ratethreshold
= 0xffff;
2890 priv
->ieee80211
->fsync_firstdiff_ratethreshold
= 200;
2891 priv
->ieee80211
->fsync_seconddiff_ratethreshold
= 200;
2893 for(rateIndex
= 0; rateIndex
<= 27; rateIndex
++)
2895 rateBitmap
= 1 << rateIndex
;
2896 if(priv
->ieee80211
->fsync_rate_bitmap
& rateBitmap
)
2897 priv
->rate_record
+= priv
->stats
.received_rate_histogram
[1][rateIndex
];
2899 if(timer_pending(&priv
->fsync_timer
))
2900 del_timer_sync(&priv
->fsync_timer
);
2901 priv
->fsync_timer
.expires
= jiffies
+ MSECS(priv
->ieee80211
->fsync_time_interval
);
2902 add_timer(&priv
->fsync_timer
);
2905 write_nic_dword(dev
, rOFDM0_RxDetector2
, 0x465c12cd);
2910 static void dm_EndHWFsync(struct net_device
*dev
)
2912 RT_TRACE(COMP_HALDM
,"%s\n", __FUNCTION__
);
2913 write_nic_dword(dev
, rOFDM0_RxDetector2
, 0x465c52cd);
2914 write_nic_byte(dev
, 0xc3b, 0x49);
2918 void dm_check_fsync(struct net_device
*dev
)
2920 #define RegC38_Default 0
2921 #define RegC38_NonFsync_Other_AP 1
2922 #define RegC38_Fsync_AP_BCM 2
2923 struct r8192_priv
*priv
= ieee80211_priv(dev
);
2925 static u8 reg_c38_State
=RegC38_Default
;
2926 static u32 reset_cnt
=0;
2928 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
);
2929 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
);
2931 if( priv
->ieee80211
->state
== IEEE80211_LINKED
&&
2932 (priv
->ieee80211
->pHTInfo
->IOTAction
& HT_IOT_ACT_CDD_FSYNC
))
2934 if(priv
->ieee80211
->bfsync_enable
== 0)
2936 switch(priv
->ieee80211
->fsync_state
)
2939 dm_StartHWFsync(dev
);
2940 priv
->ieee80211
->fsync_state
= HW_Fsync
;
2944 dm_StartHWFsync(dev
);
2945 priv
->ieee80211
->fsync_state
= HW_Fsync
;
2954 switch(priv
->ieee80211
->fsync_state
)
2957 dm_StartSWFsync(dev
);
2958 priv
->ieee80211
->fsync_state
= SW_Fsync
;
2962 dm_StartSWFsync(dev
);
2963 priv
->ieee80211
->fsync_state
= SW_Fsync
;
2971 if(priv
->framesyncMonitor
)
2973 if(reg_c38_State
!= RegC38_Fsync_AP_BCM
)
2974 { //For broadcom AP we write different default value
2976 write_nic_byte(dev
, rOFDM0_RxDetector3
, 0x15);
2978 write_nic_byte(dev
, rOFDM0_RxDetector3
, 0x95);
2981 reg_c38_State
= RegC38_Fsync_AP_BCM
;
2987 switch(priv
->ieee80211
->fsync_state
)
2991 priv
->ieee80211
->fsync_state
= Default_Fsync
;
2995 priv
->ieee80211
->fsync_state
= Default_Fsync
;
3002 if(priv
->framesyncMonitor
)
3004 if(priv
->ieee80211
->state
== IEEE80211_LINKED
)
3006 if(priv
->undecorated_smoothed_pwdb
<= RegC38_TH
)
3008 if(reg_c38_State
!= RegC38_NonFsync_Other_AP
)
3011 write_nic_byte(dev
, rOFDM0_RxDetector3
, 0x10);
3013 write_nic_byte(dev
, rOFDM0_RxDetector3
, 0x90);
3016 reg_c38_State
= RegC38_NonFsync_Other_AP
;
3019 else if(priv
->undecorated_smoothed_pwdb
>= (RegC38_TH
+5))
3023 write_nic_byte(dev
, rOFDM0_RxDetector3
, priv
->framesync
);
3024 reg_c38_State
= RegC38_Default
;
3032 write_nic_byte(dev
, rOFDM0_RxDetector3
, priv
->framesync
);
3033 reg_c38_State
= RegC38_Default
;
3038 if(priv
->framesyncMonitor
)
3040 if(priv
->reset_count
!= reset_cnt
)
3041 { //After silent reset, the reg_c38_State will be returned to default value
3042 write_nic_byte(dev
, rOFDM0_RxDetector3
, priv
->framesync
);
3043 reg_c38_State
= RegC38_Default
;
3044 reset_cnt
= priv
->reset_count
;
3051 write_nic_byte(dev
, rOFDM0_RxDetector3
, priv
->framesync
);
3052 reg_c38_State
= RegC38_Default
;
3058 * Detect Signal strength to control TX Registry
3059 * Tx Power Control For Near/Far Range
3061 static void dm_init_dynamic_txpower(struct net_device
*dev
)
3063 struct r8192_priv
*priv
= ieee80211_priv(dev
);
3065 //Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code.
3066 priv
->ieee80211
->bdynamic_txpower_enable
= true; //Default to enable Tx Power Control
3067 priv
->bLastDTPFlag_High
= false;
3068 priv
->bLastDTPFlag_Low
= false;
3069 priv
->bDynamicTxHighPower
= false;
3070 priv
->bDynamicTxLowPower
= false;
3073 static void dm_dynamic_txpower(struct net_device
*dev
)
3075 struct r8192_priv
*priv
= ieee80211_priv(dev
);
3076 unsigned int txhipower_threshhold
=0;
3077 unsigned int txlowpower_threshold
=0;
3078 if(priv
->ieee80211
->bdynamic_txpower_enable
!= true)
3080 priv
->bDynamicTxHighPower
= false;
3081 priv
->bDynamicTxLowPower
= false;
3084 if((priv
->ieee80211
->current_network
.atheros_cap_exist
) && (priv
->ieee80211
->mode
== IEEE_G
)){
3085 txhipower_threshhold
= TX_POWER_ATHEROAP_THRESH_HIGH
;
3086 txlowpower_threshold
= TX_POWER_ATHEROAP_THRESH_LOW
;
3090 txhipower_threshhold
= TX_POWER_NEAR_FIELD_THRESH_HIGH
;
3091 txlowpower_threshold
= TX_POWER_NEAR_FIELD_THRESH_LOW
;
3094 RT_TRACE(COMP_TXAGC
,"priv->undecorated_smoothed_pwdb = %ld \n" , priv
->undecorated_smoothed_pwdb
);
3096 if(priv
->ieee80211
->state
== IEEE80211_LINKED
)
3098 if(priv
->undecorated_smoothed_pwdb
>= txhipower_threshhold
)
3100 priv
->bDynamicTxHighPower
= true;
3101 priv
->bDynamicTxLowPower
= false;
3105 // high power state check
3106 if(priv
->undecorated_smoothed_pwdb
< txlowpower_threshold
&& priv
->bDynamicTxHighPower
== true)
3108 priv
->bDynamicTxHighPower
= false;
3110 // low power state check
3111 if(priv
->undecorated_smoothed_pwdb
< 35)
3113 priv
->bDynamicTxLowPower
= true;
3115 else if(priv
->undecorated_smoothed_pwdb
>= 40)
3117 priv
->bDynamicTxLowPower
= false;
3123 //pHalData->bTXPowerCtrlforNearFarRange = !pHalData->bTXPowerCtrlforNearFarRange;
3124 priv
->bDynamicTxHighPower
= false;
3125 priv
->bDynamicTxLowPower
= false;
3128 if( (priv
->bDynamicTxHighPower
!= priv
->bLastDTPFlag_High
) ||
3129 (priv
->bDynamicTxLowPower
!= priv
->bLastDTPFlag_Low
) )
3131 RT_TRACE(COMP_TXAGC
,"SetTxPowerLevel8190() channel = %d \n" , priv
->ieee80211
->current_network
.channel
);
3134 rtl8192_phy_setTxPower(dev
,priv
->ieee80211
->current_network
.channel
);
3137 priv
->bLastDTPFlag_High
= priv
->bDynamicTxHighPower
;
3138 priv
->bLastDTPFlag_Low
= priv
->bDynamicTxLowPower
;
3142 //added by vivi, for read tx rate and retrycount
3143 static void dm_check_txrateandretrycount(struct net_device
* dev
)
3145 struct r8192_priv
*priv
= ieee80211_priv(dev
);
3146 struct ieee80211_device
* ieee
= priv
->ieee80211
;
3147 //for initial tx rate
3148 ieee
->softmac_stats
.last_packet_rate
= read_nic_byte(dev
,Initial_Tx_Rate_Reg
);
3149 //for tx tx retry count
3150 ieee
->softmac_stats
.txretrycount
= read_nic_dword(dev
, Tx_Retry_Count_Reg
);
3153 static void dm_send_rssi_tofw(struct net_device
*dev
)
3155 DCMD_TXCMD_T tx_cmd
;
3156 struct r8192_priv
*priv
= ieee80211_priv(dev
);
3158 // If we test chariot, we should stop the TX command ?
3159 // Because 92E will always silent reset when we send tx command. We use register
3160 // 0x1e0(byte) to botify driver.
3161 write_nic_byte(dev
, DRIVER_RSSI
, (u8
)priv
->undecorated_smoothed_pwdb
);
3164 tx_cmd
.Op
= TXCMD_SET_RX_RSSI
;
3166 tx_cmd
.Value
= priv
->undecorated_smoothed_pwdb
;
3168 cmpk_message_handle_tx(dev
, (u8
*)&tx_cmd
,
3169 DESC_PACKET_TYPE_INIT
, sizeof(DCMD_TXCMD_T
));