aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/rtl8192u/r8192U_dm.c
diff options
context:
space:
mode:
authorJerry Chuang <jerry-chuang@realtek.com>2009-11-03 04:17:11 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-12-11 15:23:22 -0500
commit8fc8598e61f6f384f3eaf1d9b09500c12af47b37 (patch)
tree28045c6c72a4e1046feb96e06114eb69b14dacd6 /drivers/staging/rtl8192u/r8192U_dm.c
parent9b8437574759a4ce165ab20c631cd6e14c3148c2 (diff)
Staging: Added Realtek rtl8192u driver to staging
Add Realtek linux driver for rtl8192u as provided by Realtek rtl8192u_linux_2.6.0006.1031.2008.tar.gz, send to me C/C staging ML. This version won't compile against upstream, doesn't follow Linux CodingStyle and has their own ieee80211 stack. Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/rtl8192u/r8192U_dm.c')
-rw-r--r--drivers/staging/rtl8192u/r8192U_dm.c4178
1 files changed, 4178 insertions, 0 deletions
diff --git a/drivers/staging/rtl8192u/r8192U_dm.c b/drivers/staging/rtl8192u/r8192U_dm.c
new file mode 100644
index 00000000000..07ea40fd971
--- /dev/null
+++ b/drivers/staging/rtl8192u/r8192U_dm.c
@@ -0,0 +1,4178 @@
1/*++
2Copyright-c Realtek Semiconductor Corp. All rights reserved.
3
4Module Name:
5 r8192U_dm.c
6
7Abstract:
8 HW dynamic mechanism.
9
10Major Change History:
11 When Who What
12 ---------- --------------- -------------------------------
13 2008-05-14 amy create version 0 porting from windows code.
14
15--*/
16#include "r8192U.h"
17#include "r8192U_dm.h"
18#include "r8192U_hw.h"
19#include "r819xU_phy.h"
20#include "r819xU_phyreg.h"
21#include "r8190_rtl8256.h"
22#include "r819xU_cmdpkt.h"
23/*---------------------------Define Local Constant---------------------------*/
24//
25// Indicate different AP vendor for IOT issue.
26//
27#if 0
28typedef enum _HT_IOT_PEER
29{
30 HT_IOT_PEER_UNKNOWN = 0,
31 HT_IOT_PEER_REALTEK = 1,
32 HT_IOT_PEER_BROADCOM = 2,
33 HT_IOT_PEER_RALINK = 3,
34 HT_IOT_PEER_ATHEROS = 4,
35 HT_IOT_PEER_CISCO = 5,
36 HT_IOT_PEER_MAX = 6
37}HT_IOT_PEER_E, *PHTIOT_PEER_E;
38#endif
39#if 1
40static u32 edca_setting_DL[HT_IOT_PEER_MAX] =
41 { 0x5e4322, 0x5e4322, 0x5e4322, 0x604322, 0xa44f, 0x5ea44f};
42static u32 edca_setting_UL[HT_IOT_PEER_MAX] =
43 { 0x5e4322, 0xa44f, 0x5e4322, 0x604322, 0x5ea44f, 0x5ea44f};
44
45#endif
46
47#define RTK_UL_EDCA 0xa44f
48#define RTK_DL_EDCA 0x5e4322
49/*---------------------------Define Local Constant---------------------------*/
50
51
52/*------------------------Define global variable-----------------------------*/
53// Debug variable ?
54dig_t dm_digtable;
55// Store current shoftware write register content for MAC PHY.
56u8 dm_shadow[16][256] = {{0}};
57// For Dynamic Rx Path Selection by Signal Strength
58DRxPathSel DM_RxPathSelTable;
59/*------------------------Define global variable-----------------------------*/
60
61
62/*------------------------Define local variable------------------------------*/
63/*------------------------Define local variable------------------------------*/
64
65
66/*--------------------Define export function prototype-----------------------*/
67extern void init_hal_dm(struct net_device *dev);
68extern void deinit_hal_dm(struct net_device *dev);
69
70extern void hal_dm_watchdog(struct net_device *dev);
71
72
73extern void init_rate_adaptive(struct net_device *dev);
74#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
75extern void dm_txpower_trackingcallback(struct work_struct *work);
76#else
77extern void dm_txpower_trackingcallback(struct net_device *dev);
78#endif
79
80extern void dm_cck_txpower_adjust(struct net_device *dev,bool binch14);
81extern void dm_restore_dynamic_mechanism_state(struct net_device *dev);
82extern void dm_backup_dynamic_mechanism_state(struct net_device *dev);
83extern void dm_change_dynamic_initgain_thresh(struct net_device *dev,
84 u32 dm_type,
85 u32 dm_value);
86extern void DM_ChangeFsyncSetting(struct net_device *dev,
87 s32 DM_Type,
88 s32 DM_Value);
89extern void dm_force_tx_fw_info(struct net_device *dev,
90 u32 force_type,
91 u32 force_value);
92extern void dm_init_edca_turbo(struct net_device *dev);
93extern void dm_rf_operation_test_callback(unsigned long data);
94#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
95extern void dm_rf_pathcheck_workitemcallback(struct work_struct *work);
96#else
97extern void dm_rf_pathcheck_workitemcallback(struct net_device *dev);
98#endif
99extern void dm_fsync_timer_callback(unsigned long data);
100#if 0
101extern bool dm_check_lbus_status(struct net_device *dev);
102#endif
103extern void dm_check_fsync(struct net_device *dev);
104extern void dm_shadow_init(struct net_device *dev);
105
106
107/*--------------------Define export function prototype-----------------------*/
108
109
110/*---------------------Define local function prototype-----------------------*/
111// DM --> Rate Adaptive
112static void dm_check_rate_adaptive(struct net_device *dev);
113
114// DM --> Bandwidth switch
115static void dm_init_bandwidth_autoswitch(struct net_device *dev);
116static void dm_bandwidth_autoswitch( struct net_device *dev);
117
118// DM --> TX power control
119//static void dm_initialize_txpower_tracking(struct net_device *dev);
120
121static void dm_check_txpower_tracking(struct net_device *dev);
122
123
124
125//static void dm_txpower_reset_recovery(struct net_device *dev);
126
127
128// DM --> BB init gain restore
129#ifndef RTL8192U
130static void dm_bb_initialgain_restore(struct net_device *dev);
131
132
133// DM --> BB init gain backup
134static void dm_bb_initialgain_backup(struct net_device *dev);
135#endif
136// DM --> Dynamic Init Gain by RSSI
137static void dm_dig_init(struct net_device *dev);
138static void dm_ctrl_initgain_byrssi(struct net_device *dev);
139static void dm_ctrl_initgain_byrssi_highpwr(struct net_device *dev);
140static void dm_ctrl_initgain_byrssi_by_driverrssi( struct net_device *dev);
141static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(struct net_device *dev);
142static void dm_initial_gain(struct net_device *dev);
143static void dm_pd_th(struct net_device *dev);
144static void dm_cs_ratio(struct net_device *dev);
145
146static void dm_init_ctstoself(struct net_device *dev);
147// DM --> EDCA turboe mode control
148static void dm_check_edca_turbo(struct net_device *dev);
149
150// DM --> HW RF control
151static void dm_check_rfctrl_gpio(struct net_device *dev);
152
153#ifndef RTL8190P
154//static void dm_gpio_change_rf(struct net_device *dev);
155#endif
156// DM --> Check PBC
157static void dm_check_pbc_gpio(struct net_device *dev);
158
159
160// DM --> Check current RX RF path state
161static void dm_check_rx_path_selection(struct net_device *dev);
162static void dm_init_rxpath_selection(struct net_device *dev);
163static void dm_rxpath_sel_byrssi(struct net_device *dev);
164
165
166// DM --> Fsync for broadcom ap
167static void dm_init_fsync(struct net_device *dev);
168static void dm_deInit_fsync(struct net_device *dev);
169
170//Added by vivi, 20080522
171static void dm_check_txrateandretrycount(struct net_device *dev);
172
173/*---------------------Define local function prototype-----------------------*/
174
175/*---------------------Define of Tx Power Control For Near/Far Range --------*/ //Add by Jacken 2008/02/18
176static void dm_init_dynamic_txpower(struct net_device *dev);
177static void dm_dynamic_txpower(struct net_device *dev);
178
179
180// DM --> For rate adaptive and DIG, we must send RSSI to firmware
181static void dm_send_rssi_tofw(struct net_device *dev);
182static void dm_ctstoself(struct net_device *dev);
183/*---------------------------Define function prototype------------------------*/
184//================================================================================
185// HW Dynamic mechanism interface.
186//================================================================================
187
188//
189// Description:
190// Prepare SW resource for HW dynamic mechanism.
191//
192// Assumption:
193// This function is only invoked at driver intialization once.
194//
195//
196extern void
197init_hal_dm(struct net_device *dev)
198{
199 struct r8192_priv *priv = ieee80211_priv(dev);
200
201 // Undecorated Smoothed Signal Strength, it can utilized to dynamic mechanism.
202 priv->undecorated_smoothed_pwdb = -1;
203
204 //Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code.
205 dm_init_dynamic_txpower(dev);
206 init_rate_adaptive(dev);
207 //dm_initialize_txpower_tracking(dev);
208 dm_dig_init(dev);
209 dm_init_edca_turbo(dev);
210 dm_init_bandwidth_autoswitch(dev);
211 dm_init_fsync(dev);
212 dm_init_rxpath_selection(dev);
213 dm_init_ctstoself(dev);
214
215} // InitHalDm
216
217extern void deinit_hal_dm(struct net_device *dev)
218{
219
220 dm_deInit_fsync(dev);
221
222}
223
224
225#ifdef USB_RX_AGGREGATION_SUPPORT
226void dm_CheckRxAggregation(struct net_device *dev) {
227 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
228 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
229 static unsigned long lastTxOkCnt = 0;
230 static unsigned long lastRxOkCnt = 0;
231 unsigned long curTxOkCnt = 0;
232 unsigned long curRxOkCnt = 0;
233
234/*
235 if (pHalData->bForcedUsbRxAggr) {
236 if (pHalData->ForcedUsbRxAggrInfo == 0) {
237 if (pHalData->bCurrentRxAggrEnable) {
238 Adapter->HalFunc.HalUsbRxAggrHandler(Adapter, FALSE);
239 }
240 } else {
241 if (!pHalData->bCurrentRxAggrEnable || (pHalData->ForcedUsbRxAggrInfo != pHalData->LastUsbRxAggrInfoSetting)) {
242 Adapter->HalFunc.HalUsbRxAggrHandler(Adapter, TRUE);
243 }
244 }
245 return;
246 }
247
248*/
249 curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
250 curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
251
252 if((curTxOkCnt + curRxOkCnt) < 15000000) {
253 return;
254 }
255
256 if(curTxOkCnt > 4*curRxOkCnt) {
257 if (priv->bCurrentRxAggrEnable) {
258 write_nic_dword(dev, 0x1a8, 0);
259 priv->bCurrentRxAggrEnable = false;
260 }
261 }else{
262 if (!priv->bCurrentRxAggrEnable && !pHTInfo->bCurrentRT2RTAggregation) {
263 u32 ulValue;
264 ulValue = (pHTInfo->UsbRxFwAggrEn<<24) | (pHTInfo->UsbRxFwAggrPageNum<<16) |
265 (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
266 /*
267 * If usb rx firmware aggregation is enabled,
268 * when anyone of three threshold conditions above is reached,
269 * firmware will send aggregated packet to driver.
270 */
271 write_nic_dword(dev, 0x1a8, ulValue);
272 priv->bCurrentRxAggrEnable = true;
273 }
274 }
275
276 lastTxOkCnt = priv->stats.txbytesunicast;
277 lastRxOkCnt = priv->stats.rxbytesunicast;
278} // dm_CheckEdcaTurbo
279#endif
280
281
282
283extern void hal_dm_watchdog(struct net_device *dev)
284{
285 //struct r8192_priv *priv = ieee80211_priv(dev);
286
287 //static u8 previous_bssid[6] ={0};
288
289 /*Add by amy 2008/05/15 ,porting from windows code.*/
290 dm_check_rate_adaptive(dev);
291 dm_dynamic_txpower(dev);
292 dm_check_txrateandretrycount(dev);
293 dm_check_txpower_tracking(dev);
294 dm_ctrl_initgain_byrssi(dev);
295 dm_check_edca_turbo(dev);
296 dm_bandwidth_autoswitch(dev);
297 dm_check_rfctrl_gpio(dev);
298 dm_check_rx_path_selection(dev);
299 dm_check_fsync(dev);
300
301 // Add by amy 2008-05-15 porting from windows code.
302 dm_check_pbc_gpio(dev);
303 dm_send_rssi_tofw(dev);
304 dm_ctstoself(dev);
305#ifdef USB_RX_AGGREGATION_SUPPORT
306 dm_CheckRxAggregation(dev);
307#endif
308} //HalDmWatchDog
309
310
311/*
312 * Decide Rate Adaptive Set according to distance (signal strength)
313 * 01/11/2008 MHC Modify input arguments and RATR table level.
314 * 01/16/2008 MHC RF_Type is assigned in ReadAdapterInfo(). We must call
315 * the function after making sure RF_Type.
316 */
317extern void init_rate_adaptive(struct net_device * dev)
318{
319
320 struct r8192_priv *priv = ieee80211_priv(dev);
321 prate_adaptive pra = (prate_adaptive)&priv->rate_adaptive;
322
323 pra->ratr_state = DM_RATR_STA_MAX;
324 pra->high2low_rssi_thresh_for_ra = RateAdaptiveTH_High;
325 pra->low2high_rssi_thresh_for_ra20M = RateAdaptiveTH_Low_20M+5;
326 pra->low2high_rssi_thresh_for_ra40M = RateAdaptiveTH_Low_40M+5;
327
328 pra->high_rssi_thresh_for_ra = RateAdaptiveTH_High+5;
329 pra->low_rssi_thresh_for_ra20M = RateAdaptiveTH_Low_20M;
330 pra->low_rssi_thresh_for_ra40M = RateAdaptiveTH_Low_40M;
331
332 if(priv->CustomerID == RT_CID_819x_Netcore)
333 pra->ping_rssi_enable = 1;
334 else
335 pra->ping_rssi_enable = 0;
336 pra->ping_rssi_thresh_for_ra = 15;
337
338
339 if (priv->rf_type == RF_2T4R)
340 {
341 // 07/10/08 MH Modify for RA smooth scheme.
342 /* 2008/01/11 MH Modify 2T RATR table for different RSSI. 080515 porting by amy from windows code.*/
343 pra->upper_rssi_threshold_ratr = 0x8f0f0000;
344 pra->middle_rssi_threshold_ratr = 0x8f0ff000;
345 pra->low_rssi_threshold_ratr = 0x8f0ff001;
346 pra->low_rssi_threshold_ratr_40M = 0x8f0ff005;
347 pra->low_rssi_threshold_ratr_20M = 0x8f0ff001;
348 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test
349 }
350 else if (priv->rf_type == RF_1T2R)
351 {
352 pra->upper_rssi_threshold_ratr = 0x000f0000;
353 pra->middle_rssi_threshold_ratr = 0x000ff000;
354 pra->low_rssi_threshold_ratr = 0x000ff001;
355 pra->low_rssi_threshold_ratr_40M = 0x000ff005;
356 pra->low_rssi_threshold_ratr_20M = 0x000ff001;
357 pra->ping_rssi_ratr = 0x0000000d;//cosa add for test
358 }
359
360} // InitRateAdaptive
361
362
363/*-----------------------------------------------------------------------------
364 * Function: dm_check_rate_adaptive()
365 *
366 * Overview:
367 *
368 * Input: NONE
369 *
370 * Output: NONE
371 *
372 * Return: NONE
373 *
374 * Revised History:
375 * When Who Remark
376 * 05/26/08 amy Create version 0 proting from windows code.
377 *
378 *---------------------------------------------------------------------------*/
379static void dm_check_rate_adaptive(struct net_device * dev)
380{
381 struct r8192_priv *priv = ieee80211_priv(dev);
382 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
383 prate_adaptive pra = (prate_adaptive)&priv->rate_adaptive;
384 u32 currentRATR, targetRATR = 0;
385 u32 LowRSSIThreshForRA = 0, HighRSSIThreshForRA = 0;
386 bool bshort_gi_enabled = false;
387 static u8 ping_rssi_state=0;
388
389
390 if(!priv->up)
391 {
392 RT_TRACE(COMP_RATE, "<---- dm_check_rate_adaptive(): driver is going to unload\n");
393 return;
394 }
395
396 if(pra->rate_adaptive_disabled)//this variable is set by ioctl.
397 return;
398
399 // TODO: Only 11n mode is implemented currently,
400 if( !(priv->ieee80211->mode == WIRELESS_MODE_N_24G ||
401 priv->ieee80211->mode == WIRELESS_MODE_N_5G))
402 return;
403
404 if( priv->ieee80211->state == IEEE80211_LINKED )
405 {
406 // RT_TRACE(COMP_RATE, "dm_CheckRateAdaptive(): \t");
407
408 //
409 // Check whether Short GI is enabled
410 //
411 bshort_gi_enabled = (pHTInfo->bCurTxBW40MHz && pHTInfo->bCurShortGI40MHz) ||
412 (!pHTInfo->bCurTxBW40MHz && pHTInfo->bCurShortGI20MHz);
413
414
415 pra->upper_rssi_threshold_ratr =
416 (pra->upper_rssi_threshold_ratr & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
417
418 pra->middle_rssi_threshold_ratr =
419 (pra->middle_rssi_threshold_ratr & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
420
421 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
422 {
423 pra->low_rssi_threshold_ratr =
424 (pra->low_rssi_threshold_ratr_40M & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
425 }
426 else
427 {
428 pra->low_rssi_threshold_ratr =
429 (pra->low_rssi_threshold_ratr_20M & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
430 }
431 //cosa add for test
432 pra->ping_rssi_ratr =
433 (pra->ping_rssi_ratr & (~BIT31)) | ((bshort_gi_enabled)? BIT31:0) ;
434
435 /* 2007/10/08 MH We support RA smooth scheme now. When it is the first
436 time to link with AP. We will not change upper/lower threshold. If
437 STA stay in high or low level, we must change two different threshold
438 to prevent jumping frequently. */
439 if (pra->ratr_state == DM_RATR_STA_HIGH)
440 {
441 HighRSSIThreshForRA = pra->high2low_rssi_thresh_for_ra;
442 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
443 (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M);
444 }
445 else if (pra->ratr_state == DM_RATR_STA_LOW)
446 {
447 HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra;
448 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
449 (pra->low2high_rssi_thresh_for_ra40M):(pra->low2high_rssi_thresh_for_ra20M);
450 }
451 else
452 {
453 HighRSSIThreshForRA = pra->high_rssi_thresh_for_ra;
454 LowRSSIThreshForRA = (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)?
455 (pra->low_rssi_thresh_for_ra40M):(pra->low_rssi_thresh_for_ra20M);
456 }
457
458 //DbgPrint("[DM] THresh H/L=%d/%d\n\r", RATR.HighRSSIThreshForRA, RATR.LowRSSIThreshForRA);
459 if(priv->undecorated_smoothed_pwdb >= (long)HighRSSIThreshForRA)
460 {
461 //DbgPrint("[DM] RSSI=%d STA=HIGH\n\r", pHalData->UndecoratedSmoothedPWDB);
462 pra->ratr_state = DM_RATR_STA_HIGH;
463 targetRATR = pra->upper_rssi_threshold_ratr;
464 }else if(priv->undecorated_smoothed_pwdb >= (long)LowRSSIThreshForRA)
465 {
466 //DbgPrint("[DM] RSSI=%d STA=Middle\n\r", pHalData->UndecoratedSmoothedPWDB);
467 pra->ratr_state = DM_RATR_STA_MIDDLE;
468 targetRATR = pra->middle_rssi_threshold_ratr;
469 }else
470 {
471 //DbgPrint("[DM] RSSI=%d STA=LOW\n\r", pHalData->UndecoratedSmoothedPWDB);
472 pra->ratr_state = DM_RATR_STA_LOW;
473 targetRATR = pra->low_rssi_threshold_ratr;
474 }
475
476 //cosa add for test
477 if(pra->ping_rssi_enable)
478 {
479 //pHalData->UndecoratedSmoothedPWDB = 19;
480 if(priv->undecorated_smoothed_pwdb < (long)(pra->ping_rssi_thresh_for_ra+5))
481 {
482 if( (priv->undecorated_smoothed_pwdb < (long)pra->ping_rssi_thresh_for_ra) ||
483 ping_rssi_state )
484 {
485 //DbgPrint("TestRSSI = %d, set RATR to 0x%x \n", pHalData->UndecoratedSmoothedPWDB, pRA->TestRSSIRATR);
486 pra->ratr_state = DM_RATR_STA_LOW;
487 targetRATR = pra->ping_rssi_ratr;
488 ping_rssi_state = 1;
489 }
490 //else
491 // DbgPrint("TestRSSI is between the range. \n");
492 }
493 else
494 {
495 //DbgPrint("TestRSSI Recover to 0x%x \n", targetRATR);
496 ping_rssi_state = 0;
497 }
498 }
499
500 // 2008.04.01
501#if 1
502 // For RTL819X, if pairwisekey = wep/tkip, we support only MCS0~7.
503 if(priv->ieee80211->GetHalfNmodeSupportByAPsHandler(dev))
504 targetRATR &= 0xf00fffff;
505#endif
506
507 //
508 // Check whether updating of RATR0 is required
509 //
510 currentRATR = read_nic_dword(dev, RATR0);
511 if( targetRATR != currentRATR )
512 {
513 u32 ratr_value;
514 ratr_value = targetRATR;
515 RT_TRACE(COMP_RATE,"currentRATR = %x, targetRATR = %x\n", currentRATR, targetRATR);
516 if(priv->rf_type == RF_1T2R)
517 {
518 ratr_value &= ~(RATE_ALL_OFDM_2SS);
519 }
520 write_nic_dword(dev, RATR0, ratr_value);
521 write_nic_byte(dev, UFWP, 1);
522
523 pra->last_ratr = targetRATR;
524 }
525
526 }
527 else
528 {
529 pra->ratr_state = DM_RATR_STA_MAX;
530 }
531
532} // dm_CheckRateAdaptive
533
534
535static void dm_init_bandwidth_autoswitch(struct net_device * dev)
536{
537 struct r8192_priv *priv = ieee80211_priv(dev);
538
539 priv->ieee80211->bandwidth_auto_switch.threshold_20Mhzto40Mhz = BW_AUTO_SWITCH_LOW_HIGH;
540 priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz = BW_AUTO_SWITCH_HIGH_LOW;
541 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = false;
542 priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable = false;
543
544} // dm_init_bandwidth_autoswitch
545
546
547static void dm_bandwidth_autoswitch(struct net_device * dev)
548{
549 struct r8192_priv *priv = ieee80211_priv(dev);
550
551 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20 ||!priv->ieee80211->bandwidth_auto_switch.bautoswitch_enable){
552 return;
553 }else{
554 if(priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz == false){//If send packets in 40 Mhz in 20/40
555 if(priv->undecorated_smoothed_pwdb <= priv->ieee80211->bandwidth_auto_switch.threshold_40Mhzto20Mhz)
556 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = true;
557 }else{//in force send packets in 20 Mhz in 20/40
558 if(priv->undecorated_smoothed_pwdb >= priv->ieee80211->bandwidth_auto_switch.threshold_20Mhzto40Mhz)
559 priv->ieee80211->bandwidth_auto_switch.bforced_tx20Mhz = false;
560
561 }
562 }
563} // dm_BandwidthAutoSwitch
564
565//OFDM default at 0db, index=6.
566static u32 OFDMSwingTable[OFDM_Table_Length] = {
567 0x7f8001fe, // 0, +6db
568 0x71c001c7, // 1, +5db
569 0x65400195, // 2, +4db
570 0x5a400169, // 3, +3db
571 0x50800142, // 4, +2db
572 0x47c0011f, // 5, +1db
573 0x40000100, // 6, +0db ===> default, upper for higher temprature, lower for low temprature
574 0x390000e4, // 7, -1db
575 0x32c000cb, // 8, -2db
576 0x2d4000b5, // 9, -3db
577 0x288000a2, // 10, -4db
578 0x24000090, // 11, -5db
579 0x20000080, // 12, -6db
580 0x1c800072, // 13, -7db
581 0x19800066, // 14, -8db
582 0x26c0005b, // 15, -9db
583 0x24400051, // 16, -10db
584 0x12000048, // 17, -11db
585 0x10000040 // 18, -12db
586};
587
588static u8 CCKSwingTable_Ch1_Ch13[CCK_Table_length][8] = {
589 {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, // 0, +0db ===> CCK40M default
590 {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, // 1, -1db
591 {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, // 2, -2db
592 {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, // 3, -3db
593 {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, // 4, -4db
594 {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, // 5, -5db
595 {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, // 6, -6db ===> CCK20M default
596 {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, // 7, -7db
597 {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, // 8, -8db
598 {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, // 9, -9db
599 {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, // 10, -10db
600 {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01} // 11, -11db
601};
602
603static u8 CCKSwingTable_Ch14[CCK_Table_length][8] = {
604 {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, // 0, +0db ===> CCK40M default
605 {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, // 1, -1db
606 {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, // 2, -2db
607 {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, // 3, -3db
608 {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, // 4, -4db
609 {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, // 5, -5db
610 {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, // 6, -6db ===> CCK20M default
611 {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, // 7, -7db
612 {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, // 8, -8db
613 {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, // 9, -9db
614 {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, // 10, -10db
615 {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00} // 11, -11db
616};
617
618static void dm_TXPowerTrackingCallback_TSSI(struct net_device * dev)
619{
620 struct r8192_priv *priv = ieee80211_priv(dev);
621 bool bHighpowerstate, viviflag = FALSE;
622 DCMD_TXCMD_T tx_cmd;
623 u8 powerlevelOFDM24G;
624 int i =0, j = 0, k = 0;
625 u8 RF_Type, tmp_report[5]={0, 0, 0, 0, 0};
626 u32 Value;
627 u8 Pwr_Flag;
628 u16 Avg_TSSI_Meas, TSSI_13dBm, Avg_TSSI_Meas_from_driver=0;
629 //RT_STATUS rtStatus = RT_STATUS_SUCCESS;
630 bool rtStatus = true;
631 u32 delta=0;
632
633 write_nic_byte(dev, 0x1ba, 0);
634
635 priv->ieee80211->bdynamic_txpower_enable = false;
636 bHighpowerstate = priv->bDynamicTxHighPower;
637
638 powerlevelOFDM24G = (u8)(priv->Pwr_Track>>24);
639 RF_Type = priv->rf_type;
640 Value = (RF_Type<<8) | powerlevelOFDM24G;
641
642 RT_TRACE(COMP_POWER_TRACKING, "powerlevelOFDM24G = %x\n", powerlevelOFDM24G);
643
644 for(j = 0; j<=30; j++)
645{ //fill tx_cmd
646
647 tx_cmd.Op = TXCMD_SET_TX_PWR_TRACKING;
648 tx_cmd.Length = 4;
649 tx_cmd.Value = Value;
650#ifdef RTL8192U
651 rtStatus = SendTxCommandPacket(dev, &tx_cmd, 12);
652 if (rtStatus == RT_STATUS_FAILURE)
653 {
654 RT_TRACE(COMP_POWER_TRACKING, "Set configuration with tx cmd queue fail!\n");
655 }
656#else
657 cmpk_message_handle_tx(dev, (u8*)&tx_cmd,
658 DESC_PACKET_TYPE_INIT, sizeof(DCMD_TXCMD_T));
659#endif
660 mdelay(1);
661 //DbgPrint("hi, vivi, strange\n");
662 for(i = 0;i <= 30; i++)
663 {
664 Pwr_Flag = read_nic_byte(dev, 0x1ba);
665
666 if (Pwr_Flag == 0)
667 {
668 mdelay(1);
669 continue;
670 }
671#ifdef RTL8190P
672 Avg_TSSI_Meas = read_nic_word(dev, 0x1bc);
673#else
674 Avg_TSSI_Meas = read_nic_word(dev, 0x13c);
675#endif
676 if(Avg_TSSI_Meas == 0)
677 {
678 write_nic_byte(dev, 0x1ba, 0);
679 break;
680 }
681
682 for(k = 0;k < 5; k++)
683 {
684#ifdef RTL8190P
685 tmp_report[k] = read_nic_byte(dev, 0x1d8+k);
686#else
687 if(k !=4)
688 tmp_report[k] = read_nic_byte(dev, 0x134+k);
689 else
690 tmp_report[k] = read_nic_byte(dev, 0x13e);
691#endif
692 RT_TRACE(COMP_POWER_TRACKING, "TSSI_report_value = %d\n", tmp_report[k]);
693 }
694
695 //check if the report value is right
696 for(k = 0;k < 5; k++)
697 {
698 if(tmp_report[k] <= 20)
699 {
700 viviflag =TRUE;
701 break;
702 }
703 }
704 if(viviflag ==TRUE)
705 {
706 write_nic_byte(dev, 0x1ba, 0);
707 viviflag = FALSE;
708 RT_TRACE(COMP_POWER_TRACKING, "we filted this data\n");
709 for(k = 0;k < 5; k++)
710 tmp_report[k] = 0;
711 break;
712 }
713
714 for(k = 0;k < 5; k++)
715 {
716 Avg_TSSI_Meas_from_driver += tmp_report[k];
717 }
718
719 Avg_TSSI_Meas_from_driver = Avg_TSSI_Meas_from_driver*100/5;
720 RT_TRACE(COMP_POWER_TRACKING, "Avg_TSSI_Meas_from_driver = %d\n", Avg_TSSI_Meas_from_driver);
721 TSSI_13dBm = priv->TSSI_13dBm;
722 RT_TRACE(COMP_POWER_TRACKING, "TSSI_13dBm = %d\n", TSSI_13dBm);
723
724 //if(abs(Avg_TSSI_Meas_from_driver - TSSI_13dBm) <= E_FOR_TX_POWER_TRACK)
725 // For MacOS-compatible
726 if(Avg_TSSI_Meas_from_driver > TSSI_13dBm)
727 delta = Avg_TSSI_Meas_from_driver - TSSI_13dBm;
728 else
729 delta = TSSI_13dBm - Avg_TSSI_Meas_from_driver;
730
731 if(delta <= E_FOR_TX_POWER_TRACK)
732 {
733 priv->ieee80211->bdynamic_txpower_enable = TRUE;
734 write_nic_byte(dev, 0x1ba, 0);
735 RT_TRACE(COMP_POWER_TRACKING, "tx power track is done\n");
736 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex = %d\n", priv->rfa_txpowertrackingindex);
737 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real = %d\n", priv->rfa_txpowertrackingindex_real);
738#ifdef RTL8190P
739 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex = %d\n", priv->rfc_txpowertrackingindex);
740 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_real = %d\n", priv->rfc_txpowertrackingindex_real);
741#endif
742 RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation_difference = %d\n", priv->cck_present_attentuation_difference);
743 RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation = %d\n", priv->cck_present_attentuation);
744 return;
745 }
746 else
747 {
748 if(Avg_TSSI_Meas_from_driver < TSSI_13dBm - E_FOR_TX_POWER_TRACK)
749 {
750 if((priv->rfa_txpowertrackingindex > 0)
751#ifdef RTL8190P
752 &&(priv->rfc_txpowertrackingindex > 0)
753#endif
754 )
755 {
756 priv->rfa_txpowertrackingindex--;
757 if(priv->rfa_txpowertrackingindex_real > 4)
758 {
759 priv->rfa_txpowertrackingindex_real--;
760 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex_real].txbbgain_value);
761 }
762#ifdef RTL8190P
763 priv->rfc_txpowertrackingindex--;
764 if(priv->rfc_txpowertrackingindex_real > 4)
765 {
766 priv->rfc_txpowertrackingindex_real--;
767 rtl8192_setBBreg(dev, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex_real].txbbgain_value);
768 }
769#endif
770 }
771 }
772 else
773 {
774 if((priv->rfa_txpowertrackingindex < 36)
775#ifdef RTL8190P
776 &&(priv->rfc_txpowertrackingindex < 36)
777#endif
778 )
779 {
780 priv->rfa_txpowertrackingindex++;
781 priv->rfa_txpowertrackingindex_real++;
782 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex_real].txbbgain_value);
783
784#ifdef RTL8190P
785 priv->rfc_txpowertrackingindex++;
786 priv->rfc_txpowertrackingindex_real++;
787 rtl8192_setBBreg(dev, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex_real].txbbgain_value);
788#endif
789 }
790 }
791 priv->cck_present_attentuation_difference
792 = priv->rfa_txpowertrackingindex - priv->rfa_txpowertracking_default;
793
794 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20)
795 priv->cck_present_attentuation
796 = priv->cck_present_attentuation_20Mdefault + priv->cck_present_attentuation_difference;
797 else
798 priv->cck_present_attentuation
799 = priv->cck_present_attentuation_40Mdefault + priv->cck_present_attentuation_difference;
800
801 if(priv->cck_present_attentuation > -1&&priv->cck_present_attentuation <23)
802 {
803 if(priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14)
804 {
805 priv->bcck_in_ch14 = TRUE;
806 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
807 }
808 else if(priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14)
809 {
810 priv->bcck_in_ch14 = FALSE;
811 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
812 }
813 else
814 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
815 }
816 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex = %d\n", priv->rfa_txpowertrackingindex);
817 RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real = %d\n", priv->rfa_txpowertrackingindex_real);
818#ifdef RTL8190P
819 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex = %d\n", priv->rfc_txpowertrackingindex);
820 RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_real = %d\n", priv->rfc_txpowertrackingindex_real);
821#endif
822 RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation_difference = %d\n", priv->cck_present_attentuation_difference);
823 RT_TRACE(COMP_POWER_TRACKING, "priv->cck_present_attentuation = %d\n", priv->cck_present_attentuation);
824
825 if (priv->cck_present_attentuation_difference <= -12||priv->cck_present_attentuation_difference >= 24)
826 {
827 priv->ieee80211->bdynamic_txpower_enable = TRUE;
828 write_nic_byte(dev, 0x1ba, 0);
829 RT_TRACE(COMP_POWER_TRACKING, "tx power track--->limited\n");
830 return;
831 }
832
833
834 }
835 write_nic_byte(dev, 0x1ba, 0);
836 Avg_TSSI_Meas_from_driver = 0;
837 for(k = 0;k < 5; k++)
838 tmp_report[k] = 0;
839 break;
840 }
841}
842 priv->ieee80211->bdynamic_txpower_enable = TRUE;
843 write_nic_byte(dev, 0x1ba, 0);
844}
845
846static void dm_TXPowerTrackingCallback_ThermalMeter(struct net_device * dev)
847{
848#define ThermalMeterVal 9
849 struct r8192_priv *priv = ieee80211_priv(dev);
850 u32 tmpRegA, TempCCk;
851 u8 tmpOFDMindex, tmpCCKindex, tmpCCK20Mindex, tmpCCK40Mindex, tmpval;
852 int i =0, CCKSwingNeedUpdate=0;
853
854 if(!priv->btxpower_trackingInit)
855 {
856 //Query OFDM default setting
857 tmpRegA= rtl8192_QueryBBReg(dev, rOFDM0_XATxIQImbalance, bMaskDWord);
858 for(i=0; i<OFDM_Table_Length; i++) //find the index
859 {
860 if(tmpRegA == OFDMSwingTable[i])
861 {
862 priv->OFDM_index= (u8)i;
863 RT_TRACE(COMP_POWER_TRACKING, "Initial reg0x%x = 0x%x, OFDM_index=0x%x\n",
864 rOFDM0_XATxIQImbalance, tmpRegA, priv->OFDM_index);
865 }
866 }
867
868 //Query CCK default setting From 0xa22
869 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
870 for(i=0 ; i<CCK_Table_length ; i++)
871 {
872 if(TempCCk == (u32)CCKSwingTable_Ch1_Ch13[i][0])
873 {
874 priv->CCK_index =(u8) i;
875 RT_TRACE(COMP_POWER_TRACKING, "Initial reg0x%x = 0x%x, CCK_index=0x%x\n",
876 rCCK0_TxFilter1, TempCCk, priv->CCK_index);
877 break;
878 }
879 }
880 priv->btxpower_trackingInit = TRUE;
881 //pHalData->TXPowercount = 0;
882 return;
883 }
884
885 //==========================
886 // this is only for test, should be masked
887#if 0
888{
889 //UINT32 eRFPath;
890 //UINT32 start_rf, end_rf;
891 UINT32 curr_addr;
892 //UINT32 reg_addr;
893 //UINT32 reg_addr_end;
894 UINT32 reg_value;
895 //start_rf = RF90_PATH_A;
896 //end_rf = RF90_PATH_B;//RF90_PATH_MAX;
897 //reg_addr = 0x0;
898 //reg_addr_end = 0x2F;
899
900 for (curr_addr = 0; curr_addr < 0x2d; curr_addr++)
901 {
902 reg_value = PHY_QueryRFReg( Adapter, (RF90_RADIO_PATH_E)RF90_PATH_A,
903 curr_addr, bMaskDWord);
904 }
905
906 pHalData->TXPowercount = 0;
907 return;
908}
909#endif
910 //==========================
911
912 // read and filter out unreasonable value
913 tmpRegA = rtl8192_phy_QueryRFReg(dev, RF90_PATH_A, 0x12, 0x078); // 0x12: RF Reg[10:7]
914 RT_TRACE(COMP_POWER_TRACKING, "Readback ThermalMeterA = %d \n", tmpRegA);
915 if(tmpRegA < 3 || tmpRegA > 13)
916 return;
917 if(tmpRegA >= 12) // if over 12, TP will be bad when high temprature
918 tmpRegA = 12;
919 RT_TRACE(COMP_POWER_TRACKING, "Valid ThermalMeterA = %d \n", tmpRegA);
920 priv->ThermalMeter[0] = ThermalMeterVal; //We use fixed value by Bryant's suggestion
921 priv->ThermalMeter[1] = ThermalMeterVal; //We use fixed value by Bryant's suggestion
922
923 //Get current RF-A temprature index
924 if(priv->ThermalMeter[0] >= (u8)tmpRegA) //lower temprature
925 {
926 tmpOFDMindex = tmpCCK20Mindex = 6+(priv->ThermalMeter[0]-(u8)tmpRegA);
927 tmpCCK40Mindex = tmpCCK20Mindex - 6;
928 if(tmpOFDMindex >= OFDM_Table_Length)
929 tmpOFDMindex = OFDM_Table_Length-1;
930 if(tmpCCK20Mindex >= CCK_Table_length)
931 tmpCCK20Mindex = CCK_Table_length-1;
932 if(tmpCCK40Mindex >= CCK_Table_length)
933 tmpCCK40Mindex = CCK_Table_length-1;
934 }
935 else
936 {
937 tmpval = ((u8)tmpRegA - priv->ThermalMeter[0]);
938 if(tmpval >= 6) // higher temprature
939 tmpOFDMindex = tmpCCK20Mindex = 0; // max to +6dB
940 else
941 tmpOFDMindex = tmpCCK20Mindex = 6 - tmpval;
942 tmpCCK40Mindex = 0;
943 }
944 //DbgPrint("%ddb, tmpOFDMindex = %d, tmpCCK20Mindex = %d, tmpCCK40Mindex = %d",
945 //((u1Byte)tmpRegA - pHalData->ThermalMeter[0]),
946 //tmpOFDMindex, tmpCCK20Mindex, tmpCCK40Mindex);
947 if(priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20) //40M
948 tmpCCKindex = tmpCCK40Mindex;
949 else
950 tmpCCKindex = tmpCCK20Mindex;
951
952 if(priv->ieee80211->current_network.channel == 14 && !priv->bcck_in_ch14)
953 {
954 priv->bcck_in_ch14 = TRUE;
955 CCKSwingNeedUpdate = 1;
956 }
957 else if(priv->ieee80211->current_network.channel != 14 && priv->bcck_in_ch14)
958 {
959 priv->bcck_in_ch14 = FALSE;
960 CCKSwingNeedUpdate = 1;
961 }
962
963 if(priv->CCK_index != tmpCCKindex)
964 {
965 priv->CCK_index = tmpCCKindex;
966 CCKSwingNeedUpdate = 1;
967 }
968
969 if(CCKSwingNeedUpdate)
970 {
971 //DbgPrint("Update CCK Swing, CCK_index = %d\n", pHalData->CCK_index);
972 dm_cck_txpower_adjust(dev, priv->bcck_in_ch14);
973 }
974 if(priv->OFDM_index != tmpOFDMindex)
975 {
976 priv->OFDM_index = tmpOFDMindex;
977 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, OFDMSwingTable[priv->OFDM_index]);
978 RT_TRACE(COMP_POWER_TRACKING, "Update OFDMSwing[%d] = 0x%x\n",
979 priv->OFDM_index, OFDMSwingTable[priv->OFDM_index]);
980 }
981 priv->txpower_count = 0;
982}
983
984#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
985extern void dm_txpower_trackingcallback(struct work_struct *work)
986{
987 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
988 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,txpower_tracking_wq);
989 struct net_device *dev = priv->ieee80211->dev;
990#else
991extern void dm_txpower_trackingcallback(struct net_device *dev)
992{
993 struct r8192_priv *priv = ieee80211_priv(dev);
994#endif
995
996#ifdef RTL8190P
997 dm_TXPowerTrackingCallback_TSSI(dev);
998#else
999 if(priv->bDcut == TRUE)
1000 dm_TXPowerTrackingCallback_TSSI(dev);
1001 else
1002 dm_TXPowerTrackingCallback_ThermalMeter(dev);
1003#endif
1004}
1005
1006
1007static void dm_InitializeTXPowerTracking_TSSI(struct net_device *dev)
1008{
1009
1010 struct r8192_priv *priv = ieee80211_priv(dev);
1011
1012 //Initial the Tx BB index and mapping value
1013 priv->txbbgain_table[0].txbb_iq_amplifygain = 12;
1014 priv->txbbgain_table[0].txbbgain_value=0x7f8001fe;
1015 priv->txbbgain_table[1].txbb_iq_amplifygain = 11;
1016 priv->txbbgain_table[1].txbbgain_value=0x788001e2;
1017 priv->txbbgain_table[2].txbb_iq_amplifygain = 10;
1018 priv->txbbgain_table[2].txbbgain_value=0x71c001c7;
1019 priv->txbbgain_table[3].txbb_iq_amplifygain = 9;
1020 priv->txbbgain_table[3].txbbgain_value=0x6b8001ae;
1021 priv->txbbgain_table[4].txbb_iq_amplifygain = 8;
1022 priv->txbbgain_table[4].txbbgain_value=0x65400195;
1023 priv->txbbgain_table[5].txbb_iq_amplifygain = 7;
1024 priv->txbbgain_table[5].txbbgain_value=0x5fc0017f;
1025 priv->txbbgain_table[6].txbb_iq_amplifygain = 6;
1026 priv->txbbgain_table[6].txbbgain_value=0x5a400169;
1027 priv->txbbgain_table[7].txbb_iq_amplifygain = 5;
1028 priv->txbbgain_table[7].txbbgain_value=0x55400155;
1029 priv->txbbgain_table[8].txbb_iq_amplifygain = 4;
1030 priv->txbbgain_table[8].txbbgain_value=0x50800142;
1031 priv->txbbgain_table[9].txbb_iq_amplifygain = 3;
1032 priv->txbbgain_table[9].txbbgain_value=0x4c000130;
1033 priv->txbbgain_table[10].txbb_iq_amplifygain = 2;
1034 priv->txbbgain_table[10].txbbgain_value=0x47c0011f;
1035 priv->txbbgain_table[11].txbb_iq_amplifygain = 1;
1036 priv->txbbgain_table[11].txbbgain_value=0x43c0010f;
1037 priv->txbbgain_table[12].txbb_iq_amplifygain = 0;
1038 priv->txbbgain_table[12].txbbgain_value=0x40000100;
1039 priv->txbbgain_table[13].txbb_iq_amplifygain = -1;
1040 priv->txbbgain_table[13].txbbgain_value=0x3c8000f2;
1041 priv->txbbgain_table[14].txbb_iq_amplifygain = -2;
1042 priv->txbbgain_table[14].txbbgain_value=0x390000e4;
1043 priv->txbbgain_table[15].txbb_iq_amplifygain = -3;
1044 priv->txbbgain_table[15].txbbgain_value=0x35c000d7;
1045 priv->txbbgain_table[16].txbb_iq_amplifygain = -4;
1046 priv->txbbgain_table[16].txbbgain_value=0x32c000cb;
1047 priv->txbbgain_table[17].txbb_iq_amplifygain = -5;
1048 priv->txbbgain_table[17].txbbgain_value=0x300000c0;
1049 priv->txbbgain_table[18].txbb_iq_amplifygain = -6;
1050 priv->txbbgain_table[18].txbbgain_value=0x2d4000b5;
1051 priv->txbbgain_table[19].txbb_iq_amplifygain = -7;
1052 priv->txbbgain_table[19].txbbgain_value=0x2ac000ab;
1053 priv->txbbgain_table[20].txbb_iq_amplifygain = -8;
1054 priv->txbbgain_table[20].txbbgain_value=0x288000a2;
1055 priv->txbbgain_table[21].txbb_iq_amplifygain = -9;
1056 priv->txbbgain_table[21].txbbgain_value=0x26000098;
1057 priv->txbbgain_table[22].txbb_iq_amplifygain = -10;
1058 priv->txbbgain_table[22].txbbgain_value=0x24000090;
1059 priv->txbbgain_table[23].txbb_iq_amplifygain = -11;
1060 priv->txbbgain_table[23].txbbgain_value=0x22000088;
1061 priv->txbbgain_table[24].txbb_iq_amplifygain = -12;
1062 priv->txbbgain_table[24].txbbgain_value=0x20000080;
1063 priv->txbbgain_table[25].txbb_iq_amplifygain = -13;
1064 priv->txbbgain_table[25].txbbgain_value=0x1a00006c;
1065 priv->txbbgain_table[26].txbb_iq_amplifygain = -14;
1066 priv->txbbgain_table[26].txbbgain_value=0x1c800072;
1067 priv->txbbgain_table[27].txbb_iq_amplifygain = -15;
1068 priv->txbbgain_table[27].txbbgain_value=0x18000060;
1069 priv->txbbgain_table[28].txbb_iq_amplifygain = -16;
1070 priv->txbbgain_table[28].txbbgain_value=0x19800066;
1071 priv->txbbgain_table[29].txbb_iq_amplifygain = -17;
1072 priv->txbbgain_table[29].txbbgain_value=0x15800056;
1073 priv->txbbgain_table[30].txbb_iq_amplifygain = -18;
1074 priv->txbbgain_table[30].txbbgain_value=0x26c0005b;
1075 priv->txbbgain_table[31].txbb_iq_amplifygain = -19;
1076 priv->txbbgain_table[31].txbbgain_value=0x14400051;
1077 priv->txbbgain_table[32].txbb_iq_amplifygain = -20;
1078 priv->txbbgain_table[32].txbbgain_value=0x24400051;
1079 priv->txbbgain_table[33].txbb_iq_amplifygain = -21;
1080 priv->txbbgain_table[33].txbbgain_value=0x1300004c;
1081 priv->txbbgain_table[34].txbb_iq_amplifygain = -22;
1082 priv->txbbgain_table[34].txbbgain_value=0x12000048;
1083 priv->txbbgain_table[35].txbb_iq_amplifygain = -23;
1084 priv->txbbgain_table[35].txbbgain_value=0x11000044;
1085 priv->txbbgain_table[36].txbb_iq_amplifygain = -24;
1086 priv->txbbgain_table[36].txbbgain_value=0x10000040;
1087
1088 //ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
1089 //This Table is for CH1~CH13
1090 priv->cck_txbbgain_table[0].ccktxbb_valuearray[0] = 0x36;
1091 priv->cck_txbbgain_table[0].ccktxbb_valuearray[1] = 0x35;
1092 priv->cck_txbbgain_table[0].ccktxbb_valuearray[2] = 0x2e;
1093 priv->cck_txbbgain_table[0].ccktxbb_valuearray[3] = 0x25;
1094 priv->cck_txbbgain_table[0].ccktxbb_valuearray[4] = 0x1c;
1095 priv->cck_txbbgain_table[0].ccktxbb_valuearray[5] = 0x12;
1096 priv->cck_txbbgain_table[0].ccktxbb_valuearray[6] = 0x09;
1097 priv->cck_txbbgain_table[0].ccktxbb_valuearray[7] = 0x04;
1098
1099 priv->cck_txbbgain_table[1].ccktxbb_valuearray[0] = 0x33;
1100 priv->cck_txbbgain_table[1].ccktxbb_valuearray[1] = 0x32;
1101 priv->cck_txbbgain_table[1].ccktxbb_valuearray[2] = 0x2b;
1102 priv->cck_txbbgain_table[1].ccktxbb_valuearray[3] = 0x23;
1103 priv->cck_txbbgain_table[1].ccktxbb_valuearray[4] = 0x1a;
1104 priv->cck_txbbgain_table[1].ccktxbb_valuearray[5] = 0x11;
1105 priv->cck_txbbgain_table[1].ccktxbb_valuearray[6] = 0x08;
1106 priv->cck_txbbgain_table[1].ccktxbb_valuearray[7] = 0x04;
1107
1108 priv->cck_txbbgain_table[2].ccktxbb_valuearray[0] = 0x30;
1109 priv->cck_txbbgain_table[2].ccktxbb_valuearray[1] = 0x2f;
1110 priv->cck_txbbgain_table[2].ccktxbb_valuearray[2] = 0x29;
1111 priv->cck_txbbgain_table[2].ccktxbb_valuearray[3] = 0x21;
1112 priv->cck_txbbgain_table[2].ccktxbb_valuearray[4] = 0x19;
1113 priv->cck_txbbgain_table[2].ccktxbb_valuearray[5] = 0x10;
1114 priv->cck_txbbgain_table[2].ccktxbb_valuearray[6] = 0x08;
1115 priv->cck_txbbgain_table[2].ccktxbb_valuearray[7] = 0x03;
1116
1117 priv->cck_txbbgain_table[3].ccktxbb_valuearray[0] = 0x2d;
1118 priv->cck_txbbgain_table[3].ccktxbb_valuearray[1] = 0x2d;
1119 priv->cck_txbbgain_table[3].ccktxbb_valuearray[2] = 0x27;
1120 priv->cck_txbbgain_table[3].ccktxbb_valuearray[3] = 0x1f;
1121 priv->cck_txbbgain_table[3].ccktxbb_valuearray[4] = 0x18;
1122 priv->cck_txbbgain_table[3].ccktxbb_valuearray[5] = 0x0f;
1123 priv->cck_txbbgain_table[3].ccktxbb_valuearray[6] = 0x08;
1124 priv->cck_txbbgain_table[3].ccktxbb_valuearray[7] = 0x03;
1125
1126 priv->cck_txbbgain_table[4].ccktxbb_valuearray[0] = 0x2b;
1127 priv->cck_txbbgain_table[4].ccktxbb_valuearray[1] = 0x2a;
1128 priv->cck_txbbgain_table[4].ccktxbb_valuearray[2] = 0x25;
1129 priv->cck_txbbgain_table[4].ccktxbb_valuearray[3] = 0x1e;
1130 priv->cck_txbbgain_table[4].ccktxbb_valuearray[4] = 0x16;
1131 priv->cck_txbbgain_table[4].ccktxbb_valuearray[5] = 0x0e;
1132 priv->cck_txbbgain_table[4].ccktxbb_valuearray[6] = 0x07;
1133 priv->cck_txbbgain_table[4].ccktxbb_valuearray[7] = 0x03;
1134
1135 priv->cck_txbbgain_table[5].ccktxbb_valuearray[0] = 0x28;
1136 priv->cck_txbbgain_table[5].ccktxbb_valuearray[1] = 0x28;
1137 priv->cck_txbbgain_table[5].ccktxbb_valuearray[2] = 0x22;
1138 priv->cck_txbbgain_table[5].ccktxbb_valuearray[3] = 0x1c;
1139 priv->cck_txbbgain_table[5].ccktxbb_valuearray[4] = 0x15;
1140 priv->cck_txbbgain_table[5].ccktxbb_valuearray[5] = 0x0d;
1141 priv->cck_txbbgain_table[5].ccktxbb_valuearray[6] = 0x07;
1142 priv->cck_txbbgain_table[5].ccktxbb_valuearray[7] = 0x03;
1143
1144 priv->cck_txbbgain_table[6].ccktxbb_valuearray[0] = 0x26;
1145 priv->cck_txbbgain_table[6].ccktxbb_valuearray[1] = 0x25;
1146 priv->cck_txbbgain_table[6].ccktxbb_valuearray[2] = 0x21;
1147 priv->cck_txbbgain_table[6].ccktxbb_valuearray[3] = 0x1b;
1148 priv->cck_txbbgain_table[6].ccktxbb_valuearray[4] = 0x14;
1149 priv->cck_txbbgain_table[6].ccktxbb_valuearray[5] = 0x0d;
1150 priv->cck_txbbgain_table[6].ccktxbb_valuearray[6] = 0x06;
1151 priv->cck_txbbgain_table[6].ccktxbb_valuearray[7] = 0x03;
1152
1153 priv->cck_txbbgain_table[7].ccktxbb_valuearray[0] = 0x24;
1154 priv->cck_txbbgain_table[7].ccktxbb_valuearray[1] = 0x23;
1155 priv->cck_txbbgain_table[7].ccktxbb_valuearray[2] = 0x1f;
1156 priv->cck_txbbgain_table[7].ccktxbb_valuearray[3] = 0x19;
1157 priv->cck_txbbgain_table[7].ccktxbb_valuearray[4] = 0x13;
1158 priv->cck_txbbgain_table[7].ccktxbb_valuearray[5] = 0x0c;
1159 priv->cck_txbbgain_table[7].ccktxbb_valuearray[6] = 0x06;
1160 priv->cck_txbbgain_table[7].ccktxbb_valuearray[7] = 0x03;
1161
1162 priv->cck_txbbgain_table[8].ccktxbb_valuearray[0] = 0x22;
1163 priv->cck_txbbgain_table[8].ccktxbb_valuearray[1] = 0x21;
1164 priv->cck_txbbgain_table[8].ccktxbb_valuearray[2] = 0x1d;
1165 priv->cck_txbbgain_table[8].ccktxbb_valuearray[3] = 0x18;
1166 priv->cck_txbbgain_table[8].ccktxbb_valuearray[4] = 0x11;
1167 priv->cck_txbbgain_table[8].ccktxbb_valuearray[5] = 0x0b;
1168 priv->cck_txbbgain_table[8].ccktxbb_valuearray[6] = 0x06;
1169 priv->cck_txbbgain_table[8].ccktxbb_valuearray[7] = 0x02;
1170
1171 priv->cck_txbbgain_table[9].ccktxbb_valuearray[0] = 0x20;
1172 priv->cck_txbbgain_table[9].ccktxbb_valuearray[1] = 0x20;
1173 priv->cck_txbbgain_table[9].ccktxbb_valuearray[2] = 0x1b;
1174 priv->cck_txbbgain_table[9].ccktxbb_valuearray[3] = 0x16;
1175 priv->cck_txbbgain_table[9].ccktxbb_valuearray[4] = 0x11;
1176 priv->cck_txbbgain_table[9].ccktxbb_valuearray[5] = 0x08;
1177 priv->cck_txbbgain_table[9].ccktxbb_valuearray[6] = 0x05;
1178 priv->cck_txbbgain_table[9].ccktxbb_valuearray[7] = 0x02;
1179
1180 priv->cck_txbbgain_table[10].ccktxbb_valuearray[0] = 0x1f;
1181 priv->cck_txbbgain_table[10].ccktxbb_valuearray[1] = 0x1e;
1182 priv->cck_txbbgain_table[10].ccktxbb_valuearray[2] = 0x1a;
1183 priv->cck_txbbgain_table[10].ccktxbb_valuearray[3] = 0x15;
1184 priv->cck_txbbgain_table[10].ccktxbb_valuearray[4] = 0x10;
1185 priv->cck_txbbgain_table[10].ccktxbb_valuearray[5] = 0x0a;
1186 priv->cck_txbbgain_table[10].ccktxbb_valuearray[6] = 0x05;
1187 priv->cck_txbbgain_table[10].ccktxbb_valuearray[7] = 0x02;
1188
1189 priv->cck_txbbgain_table[11].ccktxbb_valuearray[0] = 0x1d;
1190 priv->cck_txbbgain_table[11].ccktxbb_valuearray[1] = 0x1c;
1191 priv->cck_txbbgain_table[11].ccktxbb_valuearray[2] = 0x18;
1192 priv->cck_txbbgain_table[11].ccktxbb_valuearray[3] = 0x14;
1193 priv->cck_txbbgain_table[11].ccktxbb_valuearray[4] = 0x0f;
1194 priv->cck_txbbgain_table[11].ccktxbb_valuearray[5] = 0x0a;
1195 priv->cck_txbbgain_table[11].ccktxbb_valuearray[6] = 0x05;
1196 priv->cck_txbbgain_table[11].ccktxbb_valuearray[7] = 0x02;
1197
1198 priv->cck_txbbgain_table[12].ccktxbb_valuearray[0] = 0x1b;
1199 priv->cck_txbbgain_table[12].ccktxbb_valuearray[1] = 0x1a;
1200 priv->cck_txbbgain_table[12].ccktxbb_valuearray[2] = 0x17;
1201 priv->cck_txbbgain_table[12].ccktxbb_valuearray[3] = 0x13;
1202 priv->cck_txbbgain_table[12].ccktxbb_valuearray[4] = 0x0e;
1203 priv->cck_txbbgain_table[12].ccktxbb_valuearray[5] = 0x09;
1204 priv->cck_txbbgain_table[12].ccktxbb_valuearray[6] = 0x04;
1205 priv->cck_txbbgain_table[12].ccktxbb_valuearray[7] = 0x02;
1206
1207 priv->cck_txbbgain_table[13].ccktxbb_valuearray[0] = 0x1a;
1208 priv->cck_txbbgain_table[13].ccktxbb_valuearray[1] = 0x19;
1209 priv->cck_txbbgain_table[13].ccktxbb_valuearray[2] = 0x16;
1210 priv->cck_txbbgain_table[13].ccktxbb_valuearray[3] = 0x12;
1211 priv->cck_txbbgain_table[13].ccktxbb_valuearray[4] = 0x0d;
1212 priv->cck_txbbgain_table[13].ccktxbb_valuearray[5] = 0x09;
1213 priv->cck_txbbgain_table[13].ccktxbb_valuearray[6] = 0x04;
1214 priv->cck_txbbgain_table[13].ccktxbb_valuearray[7] = 0x02;
1215
1216 priv->cck_txbbgain_table[14].ccktxbb_valuearray[0] = 0x18;
1217 priv->cck_txbbgain_table[14].ccktxbb_valuearray[1] = 0x17;
1218 priv->cck_txbbgain_table[14].ccktxbb_valuearray[2] = 0x15;
1219 priv->cck_txbbgain_table[14].ccktxbb_valuearray[3] = 0x11;
1220 priv->cck_txbbgain_table[14].ccktxbb_valuearray[4] = 0x0c;
1221 priv->cck_txbbgain_table[14].ccktxbb_valuearray[5] = 0x08;
1222 priv->cck_txbbgain_table[14].ccktxbb_valuearray[6] = 0x04;
1223 priv->cck_txbbgain_table[14].ccktxbb_valuearray[7] = 0x02;
1224
1225 priv->cck_txbbgain_table[15].ccktxbb_valuearray[0] = 0x17;
1226 priv->cck_txbbgain_table[15].ccktxbb_valuearray[1] = 0x16;
1227 priv->cck_txbbgain_table[15].ccktxbb_valuearray[2] = 0x13;
1228 priv->cck_txbbgain_table[15].ccktxbb_valuearray[3] = 0x10;
1229 priv->cck_txbbgain_table[15].ccktxbb_valuearray[4] = 0x0c;
1230 priv->cck_txbbgain_table[15].ccktxbb_valuearray[5] = 0x08;
1231 priv->cck_txbbgain_table[15].ccktxbb_valuearray[6] = 0x04;
1232 priv->cck_txbbgain_table[15].ccktxbb_valuearray[7] = 0x02;
1233
1234 priv->cck_txbbgain_table[16].ccktxbb_valuearray[0] = 0x16;
1235 priv->cck_txbbgain_table[16].ccktxbb_valuearray[1] = 0x15;
1236 priv->cck_txbbgain_table[16].ccktxbb_valuearray[2] = 0x12;
1237 priv->cck_txbbgain_table[16].ccktxbb_valuearray[3] = 0x0f;
1238 priv->cck_txbbgain_table[16].ccktxbb_valuearray[4] = 0x0b;
1239 priv->cck_txbbgain_table[16].ccktxbb_valuearray[5] = 0x07;
1240 priv->cck_txbbgain_table[16].ccktxbb_valuearray[6] = 0x04;
1241 priv->cck_txbbgain_table[16].ccktxbb_valuearray[7] = 0x01;
1242
1243 priv->cck_txbbgain_table[17].ccktxbb_valuearray[0] = 0x14;
1244 priv->cck_txbbgain_table[17].ccktxbb_valuearray[1] = 0x14;
1245 priv->cck_txbbgain_table[17].ccktxbb_valuearray[2] = 0x11;
1246 priv->cck_txbbgain_table[17].ccktxbb_valuearray[3] = 0x0e;
1247 priv->cck_txbbgain_table[17].ccktxbb_valuearray[4] = 0x0b;
1248 priv->cck_txbbgain_table[17].ccktxbb_valuearray[5] = 0x07;
1249 priv->cck_txbbgain_table[17].ccktxbb_valuearray[6] = 0x03;
1250 priv->cck_txbbgain_table[17].ccktxbb_valuearray[7] = 0x02;
1251
1252 priv->cck_txbbgain_table[18].ccktxbb_valuearray[0] = 0x13;
1253 priv->cck_txbbgain_table[18].ccktxbb_valuearray[1] = 0x13;
1254 priv->cck_txbbgain_table[18].ccktxbb_valuearray[2] = 0x10;
1255 priv->cck_txbbgain_table[18].ccktxbb_valuearray[3] = 0x0d;
1256 priv->cck_txbbgain_table[18].ccktxbb_valuearray[4] = 0x0a;
1257 priv->cck_txbbgain_table[18].ccktxbb_valuearray[5] = 0x06;
1258 priv->cck_txbbgain_table[18].ccktxbb_valuearray[6] = 0x03;
1259 priv->cck_txbbgain_table[18].ccktxbb_valuearray[7] = 0x01;
1260
1261 priv->cck_txbbgain_table[19].ccktxbb_valuearray[0] = 0x12;
1262 priv->cck_txbbgain_table[19].ccktxbb_valuearray[1] = 0x12;
1263 priv->cck_txbbgain_table[19].ccktxbb_valuearray[2] = 0x0f;
1264 priv->cck_txbbgain_table[19].ccktxbb_valuearray[3] = 0x0c;
1265 priv->cck_txbbgain_table[19].ccktxbb_valuearray[4] = 0x09;
1266 priv->cck_txbbgain_table[19].ccktxbb_valuearray[5] = 0x06;
1267 priv->cck_txbbgain_table[19].ccktxbb_valuearray[6] = 0x03;
1268 priv->cck_txbbgain_table[19].ccktxbb_valuearray[7] = 0x01;
1269
1270 priv->cck_txbbgain_table[20].ccktxbb_valuearray[0] = 0x11;
1271 priv->cck_txbbgain_table[20].ccktxbb_valuearray[1] = 0x11;
1272 priv->cck_txbbgain_table[20].ccktxbb_valuearray[2] = 0x0f;
1273 priv->cck_txbbgain_table[20].ccktxbb_valuearray[3] = 0x0c;
1274 priv->cck_txbbgain_table[20].ccktxbb_valuearray[4] = 0x09;
1275 priv->cck_txbbgain_table[20].ccktxbb_valuearray[5] = 0x06;
1276 priv->cck_txbbgain_table[20].ccktxbb_valuearray[6] = 0x03;
1277 priv->cck_txbbgain_table[20].ccktxbb_valuearray[7] = 0x01;
1278
1279 priv->cck_txbbgain_table[21].ccktxbb_valuearray[0] = 0x10;
1280 priv->cck_txbbgain_table[21].ccktxbb_valuearray[1] = 0x10;
1281 priv->cck_txbbgain_table[21].ccktxbb_valuearray[2] = 0x0e;
1282 priv->cck_txbbgain_table[21].ccktxbb_valuearray[3] = 0x0b;
1283 priv->cck_txbbgain_table[21].ccktxbb_valuearray[4] = 0x08;
1284 priv->cck_txbbgain_table[21].ccktxbb_valuearray[5] = 0x05;
1285 priv->cck_txbbgain_table[21].ccktxbb_valuearray[6] = 0x03;
1286 priv->cck_txbbgain_table[21].ccktxbb_valuearray[7] = 0x01;
1287
1288 priv->cck_txbbgain_table[22].ccktxbb_valuearray[0] = 0x0f;
1289 priv->cck_txbbgain_table[22].ccktxbb_valuearray[1] = 0x0f;
1290 priv->cck_txbbgain_table[22].ccktxbb_valuearray[2] = 0x0d;
1291 priv->cck_txbbgain_table[22].ccktxbb_valuearray[3] = 0x0b;
1292 priv->cck_txbbgain_table[22].ccktxbb_valuearray[4] = 0x08;
1293 priv->cck_txbbgain_table[22].ccktxbb_valuearray[5] = 0x05;
1294 priv->cck_txbbgain_table[22].ccktxbb_valuearray[6] = 0x03;
1295 priv->cck_txbbgain_table[22].ccktxbb_valuearray[7] = 0x01;
1296
1297 //ccktxbb_valuearray[0] is 0xA22 [1] is 0xA24 ...[7] is 0xA29
1298 //This Table is for CH14
1299 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[0] = 0x36;
1300 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[1] = 0x35;
1301 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[2] = 0x2e;
1302 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[3] = 0x1b;
1303 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[4] = 0x00;
1304 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[5] = 0x00;
1305 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[6] = 0x00;
1306 priv->cck_txbbgain_ch14_table[0].ccktxbb_valuearray[7] = 0x00;
1307
1308 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[0] = 0x33;
1309 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[1] = 0x32;
1310 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[2] = 0x2b;
1311 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[3] = 0x19;
1312 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[4] = 0x00;
1313 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[5] = 0x00;
1314 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[6] = 0x00;
1315 priv->cck_txbbgain_ch14_table[1].ccktxbb_valuearray[7] = 0x00;
1316
1317 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[0] = 0x30;
1318 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[1] = 0x2f;
1319 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[2] = 0x29;
1320 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[3] = 0x18;
1321 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[4] = 0x00;
1322 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[5] = 0x00;
1323 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[6] = 0x00;
1324 priv->cck_txbbgain_ch14_table[2].ccktxbb_valuearray[7] = 0x00;
1325
1326 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[0] = 0x2d;
1327 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[1] = 0x2d;
1328 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[2] = 0x27;
1329 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[3] = 0x17;
1330 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[4] = 0x00;
1331 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[5] = 0x00;
1332 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[6] = 0x00;
1333 priv->cck_txbbgain_ch14_table[3].ccktxbb_valuearray[7] = 0x00;
1334
1335 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[0] = 0x2b;
1336 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[1] = 0x2a;
1337 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[2] = 0x25;
1338 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[3] = 0x15;
1339 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[4] = 0x00;
1340 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[5] = 0x00;
1341 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[6] = 0x00;
1342 priv->cck_txbbgain_ch14_table[4].ccktxbb_valuearray[7] = 0x00;
1343
1344 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[0] = 0x28;
1345 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[1] = 0x28;
1346 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[2] = 0x22;
1347 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[3] = 0x14;
1348 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[4] = 0x00;
1349 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[5] = 0x00;
1350 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[6] = 0x00;
1351 priv->cck_txbbgain_ch14_table[5].ccktxbb_valuearray[7] = 0x00;
1352
1353 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[0] = 0x26;
1354 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[1] = 0x25;
1355 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[2] = 0x21;
1356 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[3] = 0x13;
1357 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[4] = 0x00;
1358 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[5] = 0x00;
1359 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[6] = 0x00;
1360 priv->cck_txbbgain_ch14_table[6].ccktxbb_valuearray[7] = 0x00;
1361
1362 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[0] = 0x24;
1363 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[1] = 0x23;
1364 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[2] = 0x1f;
1365 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[3] = 0x12;
1366 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[4] = 0x00;
1367 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[5] = 0x00;
1368 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[6] = 0x00;
1369 priv->cck_txbbgain_ch14_table[7].ccktxbb_valuearray[7] = 0x00;
1370
1371 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[0] = 0x22;
1372 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[1] = 0x21;
1373 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[2] = 0x1d;
1374 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[3] = 0x11;
1375 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[4] = 0x00;
1376 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[5] = 0x00;
1377 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[6] = 0x00;
1378 priv->cck_txbbgain_ch14_table[8].ccktxbb_valuearray[7] = 0x00;
1379
1380 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[0] = 0x20;
1381 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[1] = 0x20;
1382 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[2] = 0x1b;
1383 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[3] = 0x10;
1384 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[4] = 0x00;
1385 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[5] = 0x00;
1386 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[6] = 0x00;
1387 priv->cck_txbbgain_ch14_table[9].ccktxbb_valuearray[7] = 0x00;
1388
1389 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[0] = 0x1f;
1390 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[1] = 0x1e;
1391 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[2] = 0x1a;
1392 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[3] = 0x0f;
1393 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[4] = 0x00;
1394 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[5] = 0x00;
1395 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[6] = 0x00;
1396 priv->cck_txbbgain_ch14_table[10].ccktxbb_valuearray[7] = 0x00;
1397
1398 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[0] = 0x1d;
1399 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[1] = 0x1c;
1400 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[2] = 0x18;
1401 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[3] = 0x0e;
1402 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[4] = 0x00;
1403 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[5] = 0x00;
1404 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[6] = 0x00;
1405 priv->cck_txbbgain_ch14_table[11].ccktxbb_valuearray[7] = 0x00;
1406
1407 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[0] = 0x1b;
1408 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[1] = 0x1a;
1409 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[2] = 0x17;
1410 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[3] = 0x0e;
1411 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[4] = 0x00;
1412 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[5] = 0x00;
1413 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[6] = 0x00;
1414 priv->cck_txbbgain_ch14_table[12].ccktxbb_valuearray[7] = 0x00;
1415
1416 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[0] = 0x1a;
1417 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[1] = 0x19;
1418 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[2] = 0x16;
1419 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[3] = 0x0d;
1420 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[4] = 0x00;
1421 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[5] = 0x00;
1422 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[6] = 0x00;
1423 priv->cck_txbbgain_ch14_table[13].ccktxbb_valuearray[7] = 0x00;
1424
1425 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[0] = 0x18;
1426 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[1] = 0x17;
1427 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[2] = 0x15;
1428 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[3] = 0x0c;
1429 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[4] = 0x00;
1430 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[5] = 0x00;
1431 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[6] = 0x00;
1432 priv->cck_txbbgain_ch14_table[14].ccktxbb_valuearray[7] = 0x00;
1433
1434 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[0] = 0x17;
1435 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[1] = 0x16;
1436 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[2] = 0x13;
1437 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[3] = 0x0b;
1438 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[4] = 0x00;
1439 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[5] = 0x00;
1440 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[6] = 0x00;
1441 priv->cck_txbbgain_ch14_table[15].ccktxbb_valuearray[7] = 0x00;
1442
1443 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[0] = 0x16;
1444 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[1] = 0x15;
1445 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[2] = 0x12;
1446 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[3] = 0x0b;
1447 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[4] = 0x00;
1448 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[5] = 0x00;
1449 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[6] = 0x00;
1450 priv->cck_txbbgain_ch14_table[16].ccktxbb_valuearray[7] = 0x00;
1451
1452 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[0] = 0x14;
1453 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[1] = 0x14;
1454 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[2] = 0x11;
1455 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[3] = 0x0a;
1456 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[4] = 0x00;
1457 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[5] = 0x00;
1458 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[6] = 0x00;
1459 priv->cck_txbbgain_ch14_table[17].ccktxbb_valuearray[7] = 0x00;
1460
1461 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[0] = 0x13;
1462 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[1] = 0x13;
1463 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[2] = 0x10;
1464 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[3] = 0x0a;
1465 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[4] = 0x00;
1466 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[5] = 0x00;
1467 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[6] = 0x00;
1468 priv->cck_txbbgain_ch14_table[18].ccktxbb_valuearray[7] = 0x00;
1469
1470 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[0] = 0x12;
1471 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[1] = 0x12;
1472 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[2] = 0x0f;
1473 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[3] = 0x09;
1474 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[4] = 0x00;
1475 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[5] = 0x00;
1476 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[6] = 0x00;
1477 priv->cck_txbbgain_ch14_table[19].ccktxbb_valuearray[7] = 0x00;
1478
1479 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[0] = 0x11;
1480 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[1] = 0x11;
1481 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[2] = 0x0f;
1482 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[3] = 0x09;
1483 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[4] = 0x00;
1484 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[5] = 0x00;
1485 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[6] = 0x00;
1486 priv->cck_txbbgain_ch14_table[20].ccktxbb_valuearray[7] = 0x00;
1487
1488 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[0] = 0x10;
1489 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[1] = 0x10;
1490 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[2] = 0x0e;
1491 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[3] = 0x08;
1492 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[4] = 0x00;
1493 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[5] = 0x00;
1494 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[6] = 0x00;
1495 priv->cck_txbbgain_ch14_table[21].ccktxbb_valuearray[7] = 0x00;
1496
1497 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[0] = 0x0f;
1498 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[1] = 0x0f;
1499 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[2] = 0x0d;
1500 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[3] = 0x08;
1501 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[4] = 0x00;
1502 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[5] = 0x00;
1503 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[6] = 0x00;
1504 priv->cck_txbbgain_ch14_table[22].ccktxbb_valuearray[7] = 0x00;
1505
1506 priv->btxpower_tracking = TRUE;
1507 priv->txpower_count = 0;
1508 priv->btxpower_trackingInit = FALSE;
1509
1510}
1511
1512static void dm_InitializeTXPowerTracking_ThermalMeter(struct net_device *dev)
1513{
1514 struct r8192_priv *priv = ieee80211_priv(dev);
1515
1516 // Tx Power tracking by Theremal Meter require Firmware R/W 3-wire. This mechanism
1517 // can be enabled only when Firmware R/W 3-wire is enabled. Otherwise, frequent r/w
1518 // 3-wire by driver cause RF goes into wrong state.
1519 if(priv->ieee80211->FwRWRF)
1520 priv->btxpower_tracking = TRUE;
1521 else
1522 priv->btxpower_tracking = FALSE;
1523 priv->txpower_count = 0;
1524 priv->btxpower_trackingInit = FALSE;
1525}
1526
1527
1528void dm_initialize_txpower_tracking(struct net_device *dev)
1529{
1530 struct r8192_priv *priv = ieee80211_priv(dev);
1531#ifdef RTL8190P
1532 dm_InitializeTXPowerTracking_TSSI(dev);
1533#else
1534 if(priv->bDcut == TRUE)
1535 dm_InitializeTXPowerTracking_TSSI(dev);
1536 else
1537 dm_InitializeTXPowerTracking_ThermalMeter(dev);
1538#endif
1539}// dm_InitializeTXPowerTracking
1540
1541
1542static void dm_CheckTXPowerTracking_TSSI(struct net_device *dev)
1543{
1544 struct r8192_priv *priv = ieee80211_priv(dev);
1545 static u32 tx_power_track_counter = 0;
1546
1547 if(!priv->btxpower_tracking)
1548 return;
1549 else
1550 {
1551 if((tx_power_track_counter % 30 == 0)&&(tx_power_track_counter != 0))
1552 {
1553 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1554 queue_delayed_work(priv->priv_wq,&priv->txpower_tracking_wq,0);
1555 #else
1556 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1557 schedule_task(&priv->txpower_tracking_wq);
1558 #else
1559 queue_work(priv->priv_wq,&priv->txpower_tracking_wq);
1560 #endif
1561 #endif
1562 }
1563 tx_power_track_counter++;
1564 }
1565
1566}
1567
1568
1569static void dm_CheckTXPowerTracking_ThermalMeter(struct net_device *dev)
1570{
1571 struct r8192_priv *priv = ieee80211_priv(dev);
1572 static u8 TM_Trigger=0;
1573#if 0
1574 u1Byte i;
1575 u4Byte tmpRegA;
1576 for(i=0; i<50; i++)
1577 {
1578 tmpRegA = PHY_QueryRFReg(Adapter, RF90_PATH_A, 0x12, 0x078); // 0x12: RF Reg[10:7]
1579 PHY_SetRFReg(Adapter, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
1580 //delay_us(100);
1581 PHY_SetRFReg(Adapter, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
1582 //delay_us(100);
1583 }
1584 DbgPrint("Trigger and readback ThermalMeter, write RF reg0x2 = 0x4d to 0x4f for 50 times\n");
1585#else
1586 //DbgPrint("dm_CheckTXPowerTracking() \n");
1587 if(!priv->btxpower_tracking)
1588 return;
1589 else
1590 {
1591 if(priv->txpower_count <= 2)
1592 {
1593 priv->txpower_count++;
1594 return;
1595 }
1596 }
1597
1598 if(!TM_Trigger)
1599 {
1600 //Attention!! You have to wirte all 12bits data to RF, or it may cause RF to crash
1601 //actually write reg0x02 bit1=0, then bit1=1.
1602 //DbgPrint("Trigger ThermalMeter, write RF reg0x2 = 0x4d to 0x4f\n");
1603 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
1604 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
1605 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
1606 rtl8192_phy_SetRFReg(dev, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
1607 TM_Trigger = 1;
1608 return;
1609 }
1610 else
1611 {
1612 //DbgPrint("Schedule TxPowerTrackingWorkItem\n");
1613 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
1614 queue_delayed_work(priv->priv_wq,&priv->txpower_tracking_wq,0);
1615 #else
1616 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1617 schedule_task(&priv->txpower_tracking_wq);
1618 #else
1619 queue_work(priv->priv_wq,&priv->txpower_tracking_wq);
1620 #endif
1621 #endif
1622 TM_Trigger = 0;
1623 }
1624#endif
1625}
1626
1627
1628static void dm_check_txpower_tracking(struct net_device *dev)
1629{
1630 struct r8192_priv *priv = ieee80211_priv(dev);
1631 //static u32 tx_power_track_counter = 0;
1632
1633#ifdef RTL8190P
1634 dm_CheckTXPowerTracking_TSSI(dev);
1635#else
1636 if(priv->bDcut == TRUE)
1637 dm_CheckTXPowerTracking_TSSI(dev);
1638 else
1639 dm_CheckTXPowerTracking_ThermalMeter(dev);
1640#endif
1641
1642} // dm_CheckTXPowerTracking
1643
1644
1645static void dm_CCKTxPowerAdjust_TSSI(struct net_device *dev, bool bInCH14)
1646{
1647 u32 TempVal;
1648 struct r8192_priv *priv = ieee80211_priv(dev);
1649 //Write 0xa22 0xa23
1650 TempVal = 0;
1651 if(!bInCH14){
1652 //Write 0xa22 0xa23
1653 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
1654 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
1655
1656 rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal);
1657 //Write 0xa24 ~ 0xa27
1658 TempVal = 0;
1659 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
1660 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
1661 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+
1662 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
1663 rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal);
1664 //Write 0xa28 0xa29
1665 TempVal = 0;
1666 TempVal = priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
1667 (priv->cck_txbbgain_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
1668
1669 rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal);
1670 }
1671 else
1672 {
1673 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[0] +
1674 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[1]<<8) ;
1675
1676 rtl8192_setBBreg(dev, rCCK0_TxFilter1,bMaskHWord, TempVal);
1677 //Write 0xa24 ~ 0xa27
1678 TempVal = 0;
1679 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[2] +
1680 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[3]<<8) +
1681 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[4]<<16 )+
1682 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[5]<<24);
1683 rtl8192_setBBreg(dev, rCCK0_TxFilter2,bMaskDWord, TempVal);
1684 //Write 0xa28 0xa29
1685 TempVal = 0;
1686 TempVal = priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[6] +
1687 (priv->cck_txbbgain_ch14_table[priv->cck_present_attentuation].ccktxbb_valuearray[7]<<8) ;
1688
1689 rtl8192_setBBreg(dev, rCCK0_DebugPort,bMaskLWord, TempVal);
1690 }
1691
1692
1693}
1694
1695static void dm_CCKTxPowerAdjust_ThermalMeter(struct net_device *dev, bool bInCH14)
1696{
1697 u32 TempVal;
1698 struct r8192_priv *priv = ieee80211_priv(dev);
1699
1700 TempVal = 0;
1701 if(!bInCH14)
1702 {
1703 //Write 0xa22 0xa23
1704 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][0] +
1705 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][1]<<8) ;
1706 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1707 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1708 rCCK0_TxFilter1, TempVal);
1709 //Write 0xa24 ~ 0xa27
1710 TempVal = 0;
1711 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][2] +
1712 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][3]<<8) +
1713 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][4]<<16 )+
1714 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][5]<<24);
1715 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1716 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1717 rCCK0_TxFilter2, TempVal);
1718 //Write 0xa28 0xa29
1719 TempVal = 0;
1720 TempVal = CCKSwingTable_Ch1_Ch13[priv->CCK_index][6] +
1721 (CCKSwingTable_Ch1_Ch13[priv->CCK_index][7]<<8) ;
1722
1723 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
1724 RT_TRACE(COMP_POWER_TRACKING, "CCK not chnl 14, reg 0x%x = 0x%x\n",
1725 rCCK0_DebugPort, TempVal);
1726 }
1727 else
1728 {
1729// priv->CCKTxPowerAdjustCntNotCh14++; //cosa add for debug.
1730 //Write 0xa22 0xa23
1731 TempVal = CCKSwingTable_Ch14[priv->CCK_index][0] +
1732 (CCKSwingTable_Ch14[priv->CCK_index][1]<<8) ;
1733
1734 rtl8192_setBBreg(dev, rCCK0_TxFilter1, bMaskHWord, TempVal);
1735 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1736 rCCK0_TxFilter1, TempVal);
1737 //Write 0xa24 ~ 0xa27
1738 TempVal = 0;
1739 TempVal = CCKSwingTable_Ch14[priv->CCK_index][2] +
1740 (CCKSwingTable_Ch14[priv->CCK_index][3]<<8) +
1741 (CCKSwingTable_Ch14[priv->CCK_index][4]<<16 )+
1742 (CCKSwingTable_Ch14[priv->CCK_index][5]<<24);
1743 rtl8192_setBBreg(dev, rCCK0_TxFilter2, bMaskDWord, TempVal);
1744 RT_TRACE(COMP_POWER_TRACKING, "CCK chnl 14, reg 0x%x = 0x%x\n",
1745 rCCK0_TxFilter2, TempVal);
1746 //Write 0xa28 0xa29
1747 TempVal = 0;
1748 TempVal = CCKSwingTable_Ch14[priv->CCK_index][6] +
1749 (CCKSwingTable_Ch14[priv->CCK_index][7]<<8) ;
1750
1751 rtl8192_setBBreg(dev, rCCK0_DebugPort, bMaskLWord, TempVal);
1752 RT_TRACE(COMP_POWER_TRACKING,"CCK chnl 14, reg 0x%x = 0x%x\n",
1753 rCCK0_DebugPort, TempVal);
1754 }
1755}
1756
1757
1758
1759extern void dm_cck_txpower_adjust(
1760 struct net_device *dev,
1761 bool binch14
1762)
1763{ // dm_CCKTxPowerAdjust
1764
1765 struct r8192_priv *priv = ieee80211_priv(dev);
1766#ifdef RTL8190P
1767 dm_CCKTxPowerAdjust_TSSI(dev, binch14);
1768#else
1769 if(priv->bDcut == TRUE)
1770 dm_CCKTxPowerAdjust_TSSI(dev, binch14);
1771 else
1772 dm_CCKTxPowerAdjust_ThermalMeter(dev, binch14);
1773#endif
1774}
1775
1776
1777#ifndef RTL8192U
1778static void dm_txpower_reset_recovery(
1779 struct net_device *dev
1780)
1781{
1782 struct r8192_priv *priv = ieee80211_priv(dev);
1783
1784 RT_TRACE(COMP_POWER_TRACKING, "Start Reset Recovery ==>\n");
1785 rtl8192_setBBreg(dev, rOFDM0_XATxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfa_txpowertrackingindex].txbbgain_value);
1786 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc80 is %08x\n",priv->txbbgain_table[priv->rfa_txpowertrackingindex].txbbgain_value);
1787 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in RFA_txPowerTrackingIndex is %x\n",priv->rfa_txpowertrackingindex);
1788 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);
1789 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: CCK Attenuation is %d dB\n",priv->cck_present_attentuation);
1790 dm_cck_txpower_adjust(dev,priv->bcck_in_ch14);
1791
1792 rtl8192_setBBreg(dev, rOFDM0_XCTxIQImbalance, bMaskDWord, priv->txbbgain_table[priv->rfc_txpowertrackingindex].txbbgain_value);
1793 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in 0xc90 is %08x\n",priv->txbbgain_table[priv->rfc_txpowertrackingindex].txbbgain_value);
1794 RT_TRACE(COMP_POWER_TRACKING, "Reset Recovery: Fill in RFC_txPowerTrackingIndex is %x\n",priv->rfc_txpowertrackingindex);
1795 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);
1796
1797} // dm_TXPowerResetRecovery
1798
1799extern void dm_restore_dynamic_mechanism_state(struct net_device *dev)
1800{
1801 struct r8192_priv *priv = ieee80211_priv(dev);
1802 u32 reg_ratr = priv->rate_adaptive.last_ratr;
1803
1804 if(!priv->up)
1805 {
1806 RT_TRACE(COMP_RATE, "<---- dm_restore_dynamic_mechanism_state(): driver is going to unload\n");
1807 return;
1808 }
1809
1810 //
1811 // Restore previous state for rate adaptive
1812 //
1813 if(priv->rate_adaptive.rate_adaptive_disabled)
1814 return;
1815 // TODO: Only 11n mode is implemented currently,
1816 if( !(priv->ieee80211->mode==WIRELESS_MODE_N_24G ||
1817 priv->ieee80211->mode==WIRELESS_MODE_N_5G))
1818 return;
1819 {
1820 /* 2007/11/15 MH Copy from 8190PCI. */
1821 u32 ratr_value;
1822 ratr_value = reg_ratr;
1823 if(priv->rf_type == RF_1T2R) // 1T2R, Spatial Stream 2 should be disabled
1824 {
1825 ratr_value &=~ (RATE_ALL_OFDM_2SS);
1826 //DbgPrint("HW_VAR_TATR_0 from 0x%x ==> 0x%x\n", ((pu4Byte)(val))[0], ratr_value);
1827 }
1828 //DbgPrint("set HW_VAR_TATR_0 = 0x%x\n", ratr_value);
1829 //cosa PlatformEFIOWrite4Byte(Adapter, RATR0, ((pu4Byte)(val))[0]);
1830 write_nic_dword(dev, RATR0, ratr_value);
1831 write_nic_byte(dev, UFWP, 1);
1832#if 0 // Disable old code.
1833 u1Byte index;
1834 u4Byte input_value;
1835 index = (u1Byte)((((pu4Byte)(val))[0]) >> 28);
1836 input_value = (((pu4Byte)(val))[0]) & 0x0fffffff;
1837 // TODO: Correct it. Emily 2007.01.11
1838 PlatformEFIOWrite4Byte(Adapter, RATR0+index*4, input_value);
1839#endif
1840 }
1841 //Resore TX Power Tracking Index
1842 if(priv->btxpower_trackingInit && priv->btxpower_tracking){
1843 dm_txpower_reset_recovery(dev);
1844 }
1845
1846 //
1847 //Restore BB Initial Gain
1848 //
1849 dm_bb_initialgain_restore(dev);
1850
1851} // DM_RestoreDynamicMechanismState
1852
1853static void dm_bb_initialgain_restore(struct net_device *dev)
1854{
1855 struct r8192_priv *priv = ieee80211_priv(dev);
1856 u32 bit_mask = 0x7f; //Bit0~ Bit6
1857
1858 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
1859 return;
1860
1861 //Disable Initial Gain
1862 //PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x800);
1863 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // Only clear byte 1 and rewrite.
1864 rtl8192_setBBreg(dev, rOFDM0_XAAGCCore1, bit_mask, (u32)priv->initgain_backup.xaagccore1);
1865 rtl8192_setBBreg(dev, rOFDM0_XBAGCCore1, bit_mask, (u32)priv->initgain_backup.xbagccore1);
1866 rtl8192_setBBreg(dev, rOFDM0_XCAGCCore1, bit_mask, (u32)priv->initgain_backup.xcagccore1);
1867 rtl8192_setBBreg(dev, rOFDM0_XDAGCCore1, bit_mask, (u32)priv->initgain_backup.xdagccore1);
1868 bit_mask = bMaskByte2;
1869 rtl8192_setBBreg(dev, rCCK0_CCA, bit_mask, (u32)priv->initgain_backup.cca);
1870
1871 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
1872 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
1873 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
1874 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
1875 RT_TRACE(COMP_DIG, "dm_BBInitialGainRestore 0xa0a is %x\n",priv->initgain_backup.cca);
1876 //Enable Initial Gain
1877 //PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x100);
1878 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // Only clear byte 1 and rewrite.
1879
1880} // dm_BBInitialGainRestore
1881
1882
1883extern void dm_backup_dynamic_mechanism_state(struct net_device *dev)
1884{
1885 struct r8192_priv *priv = ieee80211_priv(dev);
1886
1887 // Fsync to avoid reset
1888 priv->bswitch_fsync = false;
1889 priv->bfsync_processing = false;
1890 //Backup BB InitialGain
1891 dm_bb_initialgain_backup(dev);
1892
1893} // DM_BackupDynamicMechanismState
1894
1895
1896static void dm_bb_initialgain_backup(struct net_device *dev)
1897{
1898 struct r8192_priv *priv = ieee80211_priv(dev);
1899 u32 bit_mask = bMaskByte0; //Bit0~ Bit6
1900
1901 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
1902 return;
1903
1904 //PHY_SetBBReg(Adapter, UFWP, bMaskLWord, 0x800);
1905 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // Only clear byte 1 and rewrite.
1906 priv->initgain_backup.xaagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XAAGCCore1, bit_mask);
1907 priv->initgain_backup.xbagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XBAGCCore1, bit_mask);
1908 priv->initgain_backup.xcagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XCAGCCore1, bit_mask);
1909 priv->initgain_backup.xdagccore1 = (u8)rtl8192_QueryBBReg(dev, rOFDM0_XDAGCCore1, bit_mask);
1910 bit_mask = bMaskByte2;
1911 priv->initgain_backup.cca = (u8)rtl8192_QueryBBReg(dev, rCCK0_CCA, bit_mask);
1912
1913 RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc50 is %x\n",priv->initgain_backup.xaagccore1);
1914 RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc58 is %x\n",priv->initgain_backup.xbagccore1);
1915 RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc60 is %x\n",priv->initgain_backup.xcagccore1);
1916 RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xc68 is %x\n",priv->initgain_backup.xdagccore1);
1917 RT_TRACE(COMP_DIG, "BBInitialGainBackup 0xa0a is %x\n",priv->initgain_backup.cca);
1918
1919} // dm_BBInitialGainBakcup
1920
1921#endif
1922/*-----------------------------------------------------------------------------
1923 * Function: dm_change_dynamic_initgain_thresh()
1924 *
1925 * Overview:
1926 *
1927 * Input: NONE
1928 *
1929 * Output: NONE
1930 *
1931 * Return: NONE
1932 *
1933 * Revised History:
1934 * When Who Remark
1935 * 05/29/2008 amy Create Version 0 porting from windows code.
1936 *
1937 *---------------------------------------------------------------------------*/
1938extern void dm_change_dynamic_initgain_thresh(struct net_device *dev,
1939 u32 dm_type,
1940 u32 dm_value)
1941{
1942 if (dm_type == DIG_TYPE_THRESH_HIGH)
1943 {
1944 dm_digtable.rssi_high_thresh = dm_value;
1945 }
1946 else if (dm_type == DIG_TYPE_THRESH_LOW)
1947 {
1948 dm_digtable.rssi_low_thresh = dm_value;
1949 }
1950 else if (dm_type == DIG_TYPE_THRESH_HIGHPWR_HIGH)
1951 {
1952 dm_digtable.rssi_high_power_highthresh = dm_value;
1953 }
1954 else if (dm_type == DIG_TYPE_THRESH_HIGHPWR_HIGH)
1955 {
1956 dm_digtable.rssi_high_power_highthresh = dm_value;
1957 }
1958 else if (dm_type == DIG_TYPE_ENABLE)
1959 {
1960 dm_digtable.dig_state = DM_STA_DIG_MAX;
1961 dm_digtable.dig_enable_flag = true;
1962 }
1963 else if (dm_type == DIG_TYPE_DISABLE)
1964 {
1965 dm_digtable.dig_state = DM_STA_DIG_MAX;
1966 dm_digtable.dig_enable_flag = false;
1967 }
1968 else if (dm_type == DIG_TYPE_DBG_MODE)
1969 {
1970 if(dm_value >= DM_DBG_MAX)
1971 dm_value = DM_DBG_OFF;
1972 dm_digtable.dbg_mode = (u8)dm_value;
1973 }
1974 else if (dm_type == DIG_TYPE_RSSI)
1975 {
1976 if(dm_value > 100)
1977 dm_value = 30;
1978 dm_digtable.rssi_val = (long)dm_value;
1979 }
1980 else if (dm_type == DIG_TYPE_ALGORITHM)
1981 {
1982 if (dm_value >= DIG_ALGO_MAX)
1983 dm_value = DIG_ALGO_BY_FALSE_ALARM;
1984 if(dm_digtable.dig_algorithm != (u8)dm_value)
1985 dm_digtable.dig_algorithm_switch = 1;
1986 dm_digtable.dig_algorithm = (u8)dm_value;
1987 }
1988 else if (dm_type == DIG_TYPE_BACKOFF)
1989 {
1990 if(dm_value > 30)
1991 dm_value = 30;
1992 dm_digtable.backoff_val = (u8)dm_value;
1993 }
1994 else if(dm_type == DIG_TYPE_RX_GAIN_MIN)
1995 {
1996 if(dm_value == 0)
1997 dm_value = 0x1;
1998 dm_digtable.rx_gain_range_min = (u8)dm_value;
1999 }
2000 else if(dm_type == DIG_TYPE_RX_GAIN_MAX)
2001 {
2002 if(dm_value > 0x50)
2003 dm_value = 0x50;
2004 dm_digtable.rx_gain_range_max = (u8)dm_value;
2005 }
2006} /* DM_ChangeDynamicInitGainThresh */
2007extern void
2008dm_change_fsync_setting(
2009 struct net_device *dev,
2010 s32 DM_Type,
2011 s32 DM_Value)
2012{
2013 struct r8192_priv *priv = ieee80211_priv(dev);
2014
2015 if (DM_Type == 0) // monitor 0xc38 register
2016 {
2017 if(DM_Value > 1)
2018 DM_Value = 1;
2019 priv->framesyncMonitor = (u8)DM_Value;
2020 //DbgPrint("pHalData->framesyncMonitor = %d", pHalData->framesyncMonitor);
2021 }
2022}
2023
2024extern void
2025dm_change_rxpath_selection_setting(
2026 struct net_device *dev,
2027 s32 DM_Type,
2028 s32 DM_Value)
2029{
2030 struct r8192_priv *priv = ieee80211_priv(dev);
2031 prate_adaptive pRA = (prate_adaptive)&(priv->rate_adaptive);
2032
2033
2034 if(DM_Type == 0)
2035 {
2036 if(DM_Value > 1)
2037 DM_Value = 1;
2038 DM_RxPathSelTable.Enable = (u8)DM_Value;
2039 }
2040 else if(DM_Type == 1)
2041 {
2042 if(DM_Value > 1)
2043 DM_Value = 1;
2044 DM_RxPathSelTable.DbgMode = (u8)DM_Value;
2045 }
2046 else if(DM_Type == 2)
2047 {
2048 if(DM_Value > 40)
2049 DM_Value = 40;
2050 DM_RxPathSelTable.SS_TH_low = (u8)DM_Value;
2051 }
2052 else if(DM_Type == 3)
2053 {
2054 if(DM_Value > 25)
2055 DM_Value = 25;
2056 DM_RxPathSelTable.diff_TH = (u8)DM_Value;
2057 }
2058 else if(DM_Type == 4)
2059 {
2060 if(DM_Value >= CCK_Rx_Version_MAX)
2061 DM_Value = CCK_Rx_Version_1;
2062 DM_RxPathSelTable.cck_method= (u8)DM_Value;
2063 }
2064 else if(DM_Type == 10)
2065 {
2066 if(DM_Value > 100)
2067 DM_Value = 50;
2068 DM_RxPathSelTable.rf_rssi[0] = (u8)DM_Value;
2069 }
2070 else if(DM_Type == 11)
2071 {
2072 if(DM_Value > 100)
2073 DM_Value = 50;
2074 DM_RxPathSelTable.rf_rssi[1] = (u8)DM_Value;
2075 }
2076 else if(DM_Type == 12)
2077 {
2078 if(DM_Value > 100)
2079 DM_Value = 50;
2080 DM_RxPathSelTable.rf_rssi[2] = (u8)DM_Value;
2081 }
2082 else if(DM_Type == 13)
2083 {
2084 if(DM_Value > 100)
2085 DM_Value = 50;
2086 DM_RxPathSelTable.rf_rssi[3] = (u8)DM_Value;
2087 }
2088 else if(DM_Type == 20)
2089 {
2090 if(DM_Value > 1)
2091 DM_Value = 1;
2092 pRA->ping_rssi_enable = (u8)DM_Value;
2093 }
2094 else if(DM_Type == 21)
2095 {
2096 if(DM_Value > 30)
2097 DM_Value = 30;
2098 pRA->ping_rssi_thresh_for_ra = DM_Value;
2099 }
2100}
2101
2102#if 0
2103extern void dm_force_tx_fw_info(struct net_device *dev,
2104 u32 force_type,
2105 u32 force_value)
2106{
2107 struct r8192_priv *priv = ieee80211_priv(dev);
2108
2109 if (force_type == 0) // don't force TxSC
2110 {
2111 //DbgPrint("Set Force SubCarrier Off\n");
2112 priv->tx_fwinfo_force_subcarriermode = 0;
2113 }
2114 else if(force_type == 1) //force
2115 {
2116 //DbgPrint("Set Force SubCarrier On\n");
2117 priv->tx_fwinfo_force_subcarriermode = 1;
2118 if(force_value > 3)
2119 force_value = 3;
2120 priv->tx_fwinfo_force_subcarrierval = (u8)force_value;
2121 }
2122}
2123#endif
2124
2125/*-----------------------------------------------------------------------------
2126 * Function: dm_dig_init()
2127 *
2128 * Overview: Set DIG scheme init value.
2129 *
2130 * Input: NONE
2131 *
2132 * Output: NONE
2133 *
2134 * Return: NONE
2135 *
2136 * Revised History:
2137 * When Who Remark
2138 * 05/15/2008 amy Create Version 0 porting from windows code.
2139 *
2140 *---------------------------------------------------------------------------*/
2141static void dm_dig_init(struct net_device *dev)
2142{
2143 struct r8192_priv *priv = ieee80211_priv(dev);
2144 /* 2007/10/05 MH Disable DIG scheme now. Not tested. */
2145 dm_digtable.dig_enable_flag = true;
2146 dm_digtable.dig_algorithm = DIG_ALGO_BY_RSSI;
2147 dm_digtable.dbg_mode = DM_DBG_OFF; //off=by real rssi value, on=by DM_DigTable.Rssi_val for new dig
2148 dm_digtable.dig_algorithm_switch = 0;
2149
2150 /* 2007/10/04 MH Define init gain threshol. */
2151 dm_digtable.dig_state = DM_STA_DIG_MAX;
2152 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
2153 dm_digtable.initialgain_lowerbound_state = false;
2154
2155 dm_digtable.rssi_low_thresh = DM_DIG_THRESH_LOW;
2156 dm_digtable.rssi_high_thresh = DM_DIG_THRESH_HIGH;
2157
2158 dm_digtable.rssi_high_power_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW;
2159 dm_digtable.rssi_high_power_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH;
2160
2161 dm_digtable.rssi_val = 50; //for new dig debug rssi value
2162 dm_digtable.backoff_val = DM_DIG_BACKOFF;
2163 dm_digtable.rx_gain_range_max = DM_DIG_MAX;
2164 if(priv->CustomerID == RT_CID_819x_Netcore)
2165 dm_digtable.rx_gain_range_min = DM_DIG_MIN_Netcore;
2166 else
2167 dm_digtable.rx_gain_range_min = DM_DIG_MIN;
2168
2169} /* dm_dig_init */
2170
2171
2172/*-----------------------------------------------------------------------------
2173 * Function: dm_ctrl_initgain_byrssi()
2174 *
2175 * Overview: Driver must monitor RSSI and notify firmware to change initial
2176 * gain according to different threshold. BB team provide the
2177 * suggested solution.
2178 *
2179 * Input: struct net_device *dev
2180 *
2181 * Output: NONE
2182 *
2183 * Return: NONE
2184 *
2185 * Revised History:
2186 * When Who Remark
2187 * 05/27/2008 amy Create Version 0 porting from windows code.
2188 *---------------------------------------------------------------------------*/
2189static void dm_ctrl_initgain_byrssi(struct net_device *dev)
2190{
2191
2192 if (dm_digtable.dig_enable_flag == false)
2193 return;
2194
2195 if(dm_digtable.dig_algorithm == DIG_ALGO_BY_FALSE_ALARM)
2196 dm_ctrl_initgain_byrssi_by_fwfalse_alarm(dev);
2197 else if(dm_digtable.dig_algorithm == DIG_ALGO_BY_RSSI)
2198 dm_ctrl_initgain_byrssi_by_driverrssi(dev);
2199// ;
2200 else
2201 return;
2202}
2203
2204
2205static void dm_ctrl_initgain_byrssi_by_driverrssi(
2206 struct net_device *dev)
2207{
2208 struct r8192_priv *priv = ieee80211_priv(dev);
2209 u8 i;
2210 static u8 fw_dig=0;
2211
2212 if (dm_digtable.dig_enable_flag == false)
2213 return;
2214
2215 //DbgPrint("Dig by Sw Rssi \n");
2216 if(dm_digtable.dig_algorithm_switch) // if swithed algorithm, we have to disable FW Dig.
2217 fw_dig = 0;
2218 if(fw_dig <= 3) // execute several times to make sure the FW Dig is disabled
2219 {// FW DIG Off
2220 for(i=0; i<3; i++)
2221 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // Only clear byte 1 and rewrite.
2222 fw_dig++;
2223 dm_digtable.dig_state = DM_STA_DIG_OFF; //fw dig off.
2224 }
2225
2226 if(priv->ieee80211->state == IEEE80211_LINKED)
2227 dm_digtable.cur_connect_state = DIG_CONNECT;
2228 else
2229 dm_digtable.cur_connect_state = DIG_DISCONNECT;
2230
2231 //DbgPrint("DM_DigTable.PreConnectState = %d, DM_DigTable.CurConnectState = %d \n",
2232 //DM_DigTable.PreConnectState, DM_DigTable.CurConnectState);
2233
2234 if(dm_digtable.dbg_mode == DM_DBG_OFF)
2235 dm_digtable.rssi_val = priv->undecorated_smoothed_pwdb;
2236 //DbgPrint("DM_DigTable.Rssi_val = %d \n", DM_DigTable.Rssi_val);
2237 dm_initial_gain(dev);
2238 dm_pd_th(dev);
2239 dm_cs_ratio(dev);
2240 if(dm_digtable.dig_algorithm_switch)
2241 dm_digtable.dig_algorithm_switch = 0;
2242 dm_digtable.pre_connect_state = dm_digtable.cur_connect_state;
2243
2244} /* dm_CtrlInitGainByRssi */
2245
2246static void dm_ctrl_initgain_byrssi_by_fwfalse_alarm(
2247 struct net_device *dev)
2248{
2249 struct r8192_priv *priv = ieee80211_priv(dev);
2250 static u32 reset_cnt = 0;
2251 u8 i;
2252
2253 if (dm_digtable.dig_enable_flag == false)
2254 return;
2255
2256 if(dm_digtable.dig_algorithm_switch)
2257 {
2258 dm_digtable.dig_state = DM_STA_DIG_MAX;
2259 // Fw DIG On.
2260 for(i=0; i<3; i++)
2261 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // Only clear byte 1 and rewrite.
2262 dm_digtable.dig_algorithm_switch = 0;
2263 }
2264
2265 if (priv->ieee80211->state != IEEE80211_LINKED)
2266 return;
2267
2268 // For smooth, we can not change DIG state.
2269 if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_low_thresh) &&
2270 (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_thresh))
2271 {
2272 return;
2273 }
2274 //DbgPrint("Dig by Fw False Alarm\n");
2275 //if (DM_DigTable.Dig_State == DM_STA_DIG_OFF)
2276 /*DbgPrint("DIG Check\n\r RSSI=%d LOW=%d HIGH=%d STATE=%d",
2277 pHalData->UndecoratedSmoothedPWDB, DM_DigTable.RssiLowThresh,
2278 DM_DigTable.RssiHighThresh, DM_DigTable.Dig_State);*/
2279 /* 1. When RSSI decrease, We have to judge if it is smaller than a treshold
2280 and then execute below step. */
2281 if ((priv->undecorated_smoothed_pwdb <= dm_digtable.rssi_low_thresh))
2282 {
2283 /* 2008/02/05 MH When we execute silent reset, the DIG PHY parameters
2284 will be reset to init value. We must prevent the condition. */
2285 if (dm_digtable.dig_state == DM_STA_DIG_OFF &&
2286 (priv->reset_count == reset_cnt))
2287 {
2288 return;
2289 }
2290 else
2291 {
2292 reset_cnt = priv->reset_count;
2293 }
2294
2295 // If DIG is off, DIG high power state must reset.
2296 dm_digtable.dig_highpwr_state = DM_STA_DIG_MAX;
2297 dm_digtable.dig_state = DM_STA_DIG_OFF;
2298
2299 // 1.1 DIG Off.
2300 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x8); // Only clear byte 1 and rewrite.
2301
2302 // 1.2 Set initial gain.
2303 write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x17);
2304 write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x17);
2305 write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x17);
2306 write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x17);
2307
2308 // 1.3 Lower PD_TH for OFDM.
2309 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
2310 {
2311 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
2312 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
2313 #ifdef RTL8190P
2314 write_nic_byte(dev, rOFDM0_RxDetector1, 0x40);
2315 #else
2316 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00);
2317 #endif
2318 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2319 write_nic_byte(pAdapter, rOFDM0_RxDetector1, 0x40);
2320 */
2321 //else if (pAdapter->HardwareType == HARDWARE_TYPE_RTL8192E)
2322
2323
2324 //else
2325 //PlatformEFIOWrite1Byte(pAdapter, rOFDM0_RxDetector1, 0x40);
2326 }
2327 else
2328 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2329
2330 // 1.4 Lower CS ratio for CCK.
2331 write_nic_byte(dev, 0xa0a, 0x08);
2332
2333 // 1.5 Higher EDCCA.
2334 //PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x325);
2335 return;
2336
2337 }
2338
2339 /* 2. When RSSI increase, We have to judge if it is larger than a treshold
2340 and then execute below step. */
2341 if ((priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh) )
2342 {
2343 u8 reset_flag = 0;
2344
2345 if (dm_digtable.dig_state == DM_STA_DIG_ON &&
2346 (priv->reset_count == reset_cnt))
2347 {
2348 dm_ctrl_initgain_byrssi_highpwr(dev);
2349 return;
2350 }
2351 else
2352 {
2353 if (priv->reset_count != reset_cnt)
2354 reset_flag = 1;
2355
2356 reset_cnt = priv->reset_count;
2357 }
2358
2359 dm_digtable.dig_state = DM_STA_DIG_ON;
2360 //DbgPrint("DIG ON\n\r");
2361
2362 // 2.1 Set initial gain.
2363 // 2008/02/26 MH SD3-Jerry suggest to prevent dirty environment.
2364 if (reset_flag == 1)
2365 {
2366 write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x2c);
2367 write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x2c);
2368 write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x2c);
2369 write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x2c);
2370 }
2371 else
2372 {
2373 write_nic_byte(dev, rOFDM0_XAAGCCore1, 0x20);
2374 write_nic_byte(dev, rOFDM0_XBAGCCore1, 0x20);
2375 write_nic_byte(dev, rOFDM0_XCAGCCore1, 0x20);
2376 write_nic_byte(dev, rOFDM0_XDAGCCore1, 0x20);
2377 }
2378
2379 // 2.2 Higher PD_TH for OFDM.
2380 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
2381 {
2382 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
2383 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
2384 #ifdef RTL8190P
2385 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2386 #else
2387 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
2388 #endif
2389 /*
2390 else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2391 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2392 */
2393 //else if (pAdapter->HardwareType == HARDWARE_TYPE_RTL8192E)
2394
2395 //else
2396 //PlatformEFIOWrite1Byte(pAdapter, rOFDM0_RxDetector1, 0x42);
2397 }
2398 else
2399 write_nic_byte(dev, rOFDM0_RxDetector1, 0x44);
2400
2401 // 2.3 Higher CS ratio for CCK.
2402 write_nic_byte(dev, 0xa0a, 0xcd);
2403
2404 // 2.4 Lower EDCCA.
2405 /* 2008/01/11 MH 90/92 series are the same. */
2406 //PlatformEFIOWrite4Byte(pAdapter, rOFDM0_ECCAThreshold, 0x346);
2407
2408 // 2.5 DIG On.
2409 rtl8192_setBBreg(dev, UFWP, bMaskByte1, 0x1); // Only clear byte 1 and rewrite.
2410
2411 }
2412
2413 dm_ctrl_initgain_byrssi_highpwr(dev);
2414
2415} /* dm_CtrlInitGainByRssi */
2416
2417
2418/*-----------------------------------------------------------------------------
2419 * Function: dm_ctrl_initgain_byrssi_highpwr()
2420 *
2421 * Overview:
2422 *
2423 * Input: NONE
2424 *
2425 * Output: NONE
2426 *
2427 * Return: NONE
2428 *
2429 * Revised History:
2430 * When Who Remark
2431 * 05/28/2008 amy Create Version 0 porting from windows code.
2432 *
2433 *---------------------------------------------------------------------------*/
2434static void dm_ctrl_initgain_byrssi_highpwr(
2435 struct net_device * dev)
2436{
2437 struct r8192_priv *priv = ieee80211_priv(dev);
2438 static u32 reset_cnt_highpwr = 0;
2439
2440 // For smooth, we can not change high power DIG state in the range.
2441 if ((priv->undecorated_smoothed_pwdb > dm_digtable.rssi_high_power_lowthresh) &&
2442 (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_power_highthresh))
2443 {
2444 return;
2445 }
2446
2447 /* 3. When RSSI >75% or <70%, it is a high power issue. We have to judge if
2448 it is larger than a treshold and then execute below step. */
2449 // 2008/02/05 MH SD3-Jerry Modify PD_TH for high power issue.
2450 if (priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_power_highthresh)
2451 {
2452 if (dm_digtable.dig_highpwr_state == DM_STA_DIG_ON &&
2453 (priv->reset_count == reset_cnt_highpwr))
2454 return;
2455 else
2456 dm_digtable.dig_highpwr_state = DM_STA_DIG_ON;
2457
2458 // 3.1 Higher PD_TH for OFDM for high power state.
2459 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
2460 {
2461 #ifdef RTL8190P
2462 write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
2463 #else
2464 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x10);
2465 #endif
2466
2467 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2468 write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
2469 */
2470
2471 }
2472 else
2473 write_nic_byte(dev, rOFDM0_RxDetector1, 0x43);
2474 }
2475 else
2476 {
2477 if (dm_digtable.dig_highpwr_state == DM_STA_DIG_OFF&&
2478 (priv->reset_count == reset_cnt_highpwr))
2479 return;
2480 else
2481 dm_digtable.dig_highpwr_state = DM_STA_DIG_OFF;
2482
2483 if (priv->undecorated_smoothed_pwdb < dm_digtable.rssi_high_power_lowthresh &&
2484 priv->undecorated_smoothed_pwdb >= dm_digtable.rssi_high_thresh)
2485 {
2486 // 3.2 Recover PD_TH for OFDM for normal power region.
2487 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
2488 {
2489 #ifdef RTL8190P
2490 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2491 #else
2492 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
2493 #endif
2494 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2495 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2496 */
2497
2498 }
2499 else
2500 write_nic_byte(dev, rOFDM0_RxDetector1, 0x44);
2501 }
2502 }
2503
2504 reset_cnt_highpwr = priv->reset_count;
2505
2506} /* dm_CtrlInitGainByRssiHighPwr */
2507
2508
2509static void dm_initial_gain(
2510 struct net_device * dev)
2511{
2512 struct r8192_priv *priv = ieee80211_priv(dev);
2513 u8 initial_gain=0;
2514 static u8 initialized=0, force_write=0;
2515 static u32 reset_cnt=0;
2516
2517 if(dm_digtable.dig_algorithm_switch)
2518 {
2519 initialized = 0;
2520 reset_cnt = 0;
2521 }
2522
2523 if(dm_digtable.pre_connect_state == dm_digtable.cur_connect_state)
2524 {
2525 if(dm_digtable.cur_connect_state == DIG_CONNECT)
2526 {
2527 if((dm_digtable.rssi_val+10-dm_digtable.backoff_val) > dm_digtable.rx_gain_range_max)
2528 dm_digtable.cur_ig_value = dm_digtable.rx_gain_range_max;
2529 else if((dm_digtable.rssi_val+10-dm_digtable.backoff_val) < dm_digtable.rx_gain_range_min)
2530 dm_digtable.cur_ig_value = dm_digtable.rx_gain_range_min;
2531 else
2532 dm_digtable.cur_ig_value = dm_digtable.rssi_val+10-dm_digtable.backoff_val;
2533 }
2534 else //current state is disconnected
2535 {
2536 if(dm_digtable.cur_ig_value == 0)
2537 dm_digtable.cur_ig_value = priv->DefaultInitialGain[0];
2538 else
2539 dm_digtable.cur_ig_value = dm_digtable.pre_ig_value;
2540 }
2541 }
2542 else // disconnected -> connected or connected -> disconnected
2543 {
2544 dm_digtable.cur_ig_value = priv->DefaultInitialGain[0];
2545 dm_digtable.pre_ig_value = 0;
2546 }
2547 //DbgPrint("DM_DigTable.CurIGValue = 0x%x, DM_DigTable.PreIGValue = 0x%x\n", DM_DigTable.CurIGValue, DM_DigTable.PreIGValue);
2548
2549 // if silent reset happened, we should rewrite the values back
2550 if(priv->reset_count != reset_cnt)
2551 {
2552 force_write = 1;
2553 reset_cnt = priv->reset_count;
2554 }
2555
2556 if(dm_digtable.pre_ig_value != read_nic_byte(dev, rOFDM0_XAAGCCore1))
2557 force_write = 1;
2558
2559 {
2560 if((dm_digtable.pre_ig_value != dm_digtable.cur_ig_value)
2561 || !initialized || force_write)
2562 {
2563 initial_gain = (u8)dm_digtable.cur_ig_value;
2564 //DbgPrint("Write initial gain = 0x%x\n", initial_gain);
2565 // Set initial gain.
2566 write_nic_byte(dev, rOFDM0_XAAGCCore1, initial_gain);
2567 write_nic_byte(dev, rOFDM0_XBAGCCore1, initial_gain);
2568 write_nic_byte(dev, rOFDM0_XCAGCCore1, initial_gain);
2569 write_nic_byte(dev, rOFDM0_XDAGCCore1, initial_gain);
2570 dm_digtable.pre_ig_value = dm_digtable.cur_ig_value;
2571 initialized = 1;
2572 force_write = 0;
2573 }
2574 }
2575}
2576
2577static void dm_pd_th(
2578 struct net_device * dev)
2579{
2580 struct r8192_priv *priv = ieee80211_priv(dev);
2581 static u8 initialized=0, force_write=0;
2582 static u32 reset_cnt = 0;
2583
2584 if(dm_digtable.dig_algorithm_switch)
2585 {
2586 initialized = 0;
2587 reset_cnt = 0;
2588 }
2589
2590 if(dm_digtable.pre_connect_state == dm_digtable.cur_connect_state)
2591 {
2592 if(dm_digtable.cur_connect_state == DIG_CONNECT)
2593 {
2594 if (dm_digtable.rssi_val >= dm_digtable.rssi_high_power_highthresh)
2595 dm_digtable.curpd_thstate = DIG_PD_AT_HIGH_POWER;
2596 else if ((dm_digtable.rssi_val <= dm_digtable.rssi_low_thresh))
2597 dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
2598 else if ((dm_digtable.rssi_val >= dm_digtable.rssi_high_thresh) &&
2599 (dm_digtable.rssi_val < dm_digtable.rssi_high_power_lowthresh))
2600 dm_digtable.curpd_thstate = DIG_PD_AT_NORMAL_POWER;
2601 else
2602 dm_digtable.curpd_thstate = dm_digtable.prepd_thstate;
2603 }
2604 else
2605 {
2606 dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
2607 }
2608 }
2609 else // disconnected -> connected or connected -> disconnected
2610 {
2611 dm_digtable.curpd_thstate = DIG_PD_AT_LOW_POWER;
2612 }
2613
2614 // if silent reset happened, we should rewrite the values back
2615 if(priv->reset_count != reset_cnt)
2616 {
2617 force_write = 1;
2618 reset_cnt = priv->reset_count;
2619 }
2620
2621 {
2622 if((dm_digtable.prepd_thstate != dm_digtable.curpd_thstate) ||
2623 (initialized<=3) || force_write)
2624 {
2625 //DbgPrint("Write PD_TH state = %d\n", DM_DigTable.CurPD_THState);
2626 if(dm_digtable.curpd_thstate == DIG_PD_AT_LOW_POWER)
2627 {
2628 // Lower PD_TH for OFDM.
2629 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
2630 {
2631 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
2632 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
2633 #ifdef RTL8190P
2634 write_nic_byte(dev, rOFDM0_RxDetector1, 0x40);
2635 #else
2636 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x00);
2637 #endif
2638 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2639 write_nic_byte(dev, rOFDM0_RxDetector1, 0x40);
2640 */
2641 }
2642 else
2643 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2644 }
2645 else if(dm_digtable.curpd_thstate == DIG_PD_AT_NORMAL_POWER)
2646 {
2647 // Higher PD_TH for OFDM.
2648 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
2649 {
2650 /* 2008/01/11 MH 40MHZ 90/92 register are not the same. */
2651 // 2008/02/05 MH SD3-Jerry 92U/92E PD_TH are the same.
2652 #ifdef RTL8190P
2653 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2654 #else
2655 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x20);
2656 #endif
2657 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2658 write_nic_byte(dev, rOFDM0_RxDetector1, 0x42);
2659 */
2660 }
2661 else
2662 write_nic_byte(dev, rOFDM0_RxDetector1, 0x44);
2663 }
2664 else if(dm_digtable.curpd_thstate == DIG_PD_AT_HIGH_POWER)
2665 {
2666 // Higher PD_TH for OFDM for high power state.
2667 if (priv->CurrentChannelBW != HT_CHANNEL_WIDTH_20)
2668 {
2669 #ifdef RTL8190P
2670 write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
2671 #else
2672 write_nic_byte(dev, (rOFDM0_XATxAFE+3), 0x10);
2673 #endif
2674 /*else if (priv->card_8192 == HARDWARE_TYPE_RTL8190P)
2675 write_nic_byte(dev, rOFDM0_RxDetector1, 0x41);
2676 */
2677 }
2678 else
2679 write_nic_byte(dev, rOFDM0_RxDetector1, 0x43);
2680 }
2681 dm_digtable.prepd_thstate = dm_digtable.curpd_thstate;
2682 if(initialized <= 3)
2683 initialized++;
2684 force_write = 0;
2685 }
2686 }
2687}
2688
2689static void dm_cs_ratio(
2690 struct net_device * dev)
2691{
2692 struct r8192_priv *priv = ieee80211_priv(dev);
2693 static u8 initialized=0,force_write=0;
2694 static u32 reset_cnt = 0;
2695
2696 if(dm_digtable.dig_algorithm_switch)
2697 {
2698 initialized = 0;
2699 reset_cnt = 0;
2700 }
2701
2702 if(dm_digtable.pre_connect_state == dm_digtable.cur_connect_state)
2703 {
2704 if(dm_digtable.cur_connect_state == DIG_CONNECT)
2705 {
2706 if ((dm_digtable.rssi_val <= dm_digtable.rssi_low_thresh))
2707 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
2708 else if ((dm_digtable.rssi_val >= dm_digtable.rssi_high_thresh) )
2709 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_HIGHER;
2710 else
2711 dm_digtable.curcs_ratio_state = dm_digtable.precs_ratio_state;
2712 }
2713 else
2714 {
2715 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
2716 }
2717 }
2718 else // disconnected -> connected or connected -> disconnected
2719 {
2720 dm_digtable.curcs_ratio_state = DIG_CS_RATIO_LOWER;
2721 }
2722
2723 // if silent reset happened, we should rewrite the values back
2724 if(priv->reset_count != reset_cnt)
2725 {
2726 force_write = 1;
2727 reset_cnt = priv->reset_count;
2728 }
2729
2730
2731 {
2732 if((dm_digtable.precs_ratio_state != dm_digtable.curcs_ratio_state) ||
2733 !initialized || force_write)
2734 {
2735 //DbgPrint("Write CS_ratio state = %d\n", DM_DigTable.CurCS_ratioState);
2736 if(dm_digtable.curcs_ratio_state == DIG_CS_RATIO_LOWER)
2737 {
2738 // Lower CS ratio for CCK.
2739 write_nic_byte(dev, 0xa0a, 0x08);
2740 }
2741 else if(dm_digtable.curcs_ratio_state == DIG_CS_RATIO_HIGHER)
2742 {
2743 // Higher CS ratio for CCK.
2744 write_nic_byte(dev, 0xa0a, 0xcd);
2745 }
2746 dm_digtable.precs_ratio_state = dm_digtable.curcs_ratio_state;
2747 initialized = 1;
2748 force_write = 0;
2749 }
2750 }
2751}
2752
2753extern void dm_init_edca_turbo(struct net_device * dev)
2754{
2755 struct r8192_priv *priv = ieee80211_priv(dev);
2756
2757 priv->bcurrent_turbo_EDCA = false;
2758 priv->ieee80211->bis_any_nonbepkts = false;
2759 priv->bis_cur_rdlstate = false;
2760} // dm_init_edca_turbo
2761
2762#if 1
2763static void dm_check_edca_turbo(
2764 struct net_device * dev)
2765{
2766 struct r8192_priv *priv = ieee80211_priv(dev);
2767 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
2768 //PSTA_QOS pStaQos = pMgntInfo->pStaQos;
2769
2770 // Keep past Tx/Rx packet count for RT-to-RT EDCA turbo.
2771 static unsigned long lastTxOkCnt = 0;
2772 static unsigned long lastRxOkCnt = 0;
2773 unsigned long curTxOkCnt = 0;
2774 unsigned long curRxOkCnt = 0;
2775
2776 //
2777 // Do not be Turbo if it's under WiFi config and Qos Enabled, because the EDCA parameters
2778 // should follow the settings from QAP. By Bruce, 2007-12-07.
2779 //
2780 #if 1
2781 if(priv->ieee80211->state != IEEE80211_LINKED)
2782 goto dm_CheckEdcaTurbo_EXIT;
2783 #endif
2784 // We do not turn on EDCA turbo mode for some AP that has IOT issue
2785 if(priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_DISABLE_EDCA_TURBO)
2786 goto dm_CheckEdcaTurbo_EXIT;
2787
2788// printk("========>%s():bis_any_nonbepkts is %d\n",__FUNCTION__,priv->bis_any_nonbepkts);
2789 // Check the status for current condition.
2790 if(!priv->ieee80211->bis_any_nonbepkts)
2791 {
2792 curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
2793 curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
2794 // For RT-AP, we needs to turn it on when Rx>Tx
2795 if(curRxOkCnt > 4*curTxOkCnt)
2796 {
2797 //printk("%s():curRxOkCnt > 4*curTxOkCnt\n");
2798 if(!priv->bis_cur_rdlstate || !priv->bcurrent_turbo_EDCA)
2799 {
2800 write_nic_dword(dev, EDCAPARA_BE, edca_setting_DL[pHTInfo->IOTPeer]);
2801 priv->bis_cur_rdlstate = true;
2802 }
2803 }
2804 else
2805 {
2806
2807 //printk("%s():curRxOkCnt < 4*curTxOkCnt\n");
2808 if(priv->bis_cur_rdlstate || !priv->bcurrent_turbo_EDCA)
2809 {
2810 write_nic_dword(dev, EDCAPARA_BE, edca_setting_UL[pHTInfo->IOTPeer]);
2811 priv->bis_cur_rdlstate = false;
2812 }
2813
2814 }
2815
2816 priv->bcurrent_turbo_EDCA = true;
2817 }
2818 else
2819 {
2820 //
2821 // Turn Off EDCA turbo here.
2822 // Restore original EDCA according to the declaration of AP.
2823 //
2824 if(priv->bcurrent_turbo_EDCA)
2825 {
2826
2827 {
2828 u8 u1bAIFS;
2829 u32 u4bAcParam;
2830 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
2831 u8 mode = priv->ieee80211->mode;
2832
2833 // For Each time updating EDCA parameter, reset EDCA turbo mode status.
2834 dm_init_edca_turbo(dev);
2835 u1bAIFS = qos_parameters->aifs[0] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
2836 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[0]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
2837 (((u32)(qos_parameters->cw_max[0]))<< AC_PARAM_ECW_MAX_OFFSET)|
2838 (((u32)(qos_parameters->cw_min[0]))<< AC_PARAM_ECW_MIN_OFFSET)|
2839 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
2840 //write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
2841 write_nic_dword(dev, EDCAPARA_BE, u4bAcParam);
2842
2843 // Check ACM bit.
2844 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
2845 {
2846 // TODO: Modified this part and try to set acm control in only 1 IO processing!!
2847
2848 PACI_AIFSN pAciAifsn = (PACI_AIFSN)&(qos_parameters->aifs[0]);
2849 u8 AcmCtrl = read_nic_byte( dev, AcmHwCtrl );
2850 if( pAciAifsn->f.ACM )
2851 { // ACM bit is 1.
2852 AcmCtrl |= AcmHw_BeqEn;
2853 }
2854 else
2855 { // ACM bit is 0.
2856 AcmCtrl &= (~AcmHw_BeqEn);
2857 }
2858
2859 RT_TRACE( COMP_QOS,"SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl ) ;
2860 write_nic_byte(dev, AcmHwCtrl, AcmCtrl );
2861 }
2862 }
2863 priv->bcurrent_turbo_EDCA = false;
2864 }
2865 }
2866
2867
2868dm_CheckEdcaTurbo_EXIT:
2869 // Set variables for next time.
2870 priv->ieee80211->bis_any_nonbepkts = false;
2871 lastTxOkCnt = priv->stats.txbytesunicast;
2872 lastRxOkCnt = priv->stats.rxbytesunicast;
2873} // dm_CheckEdcaTurbo
2874#endif
2875
2876extern void DM_CTSToSelfSetting(struct net_device * dev,u32 DM_Type, u32 DM_Value)
2877{
2878 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
2879
2880 if (DM_Type == 0) // CTS to self disable/enable
2881 {
2882 if(DM_Value > 1)
2883 DM_Value = 1;
2884 priv->ieee80211->bCTSToSelfEnable = (bool)DM_Value;
2885 //DbgPrint("pMgntInfo->bCTSToSelfEnable = %d\n", pMgntInfo->bCTSToSelfEnable);
2886 }
2887 else if(DM_Type == 1) //CTS to self Th
2888 {
2889 if(DM_Value >= 50)
2890 DM_Value = 50;
2891 priv->ieee80211->CTSToSelfTH = (u8)DM_Value;
2892 //DbgPrint("pMgntInfo->CTSToSelfTH = %d\n", pMgntInfo->CTSToSelfTH);
2893 }
2894}
2895
2896static void dm_init_ctstoself(struct net_device * dev)
2897{
2898 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
2899
2900 priv->ieee80211->bCTSToSelfEnable = TRUE;
2901 priv->ieee80211->CTSToSelfTH = CTSToSelfTHVal;
2902}
2903
2904static void dm_ctstoself(struct net_device *dev)
2905{
2906 struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
2907 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
2908 static unsigned long lastTxOkCnt = 0;
2909 static unsigned long lastRxOkCnt = 0;
2910 unsigned long curTxOkCnt = 0;
2911 unsigned long curRxOkCnt = 0;
2912
2913 if(priv->ieee80211->bCTSToSelfEnable != TRUE)
2914 {
2915 pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
2916 return;
2917 }
2918 /*
2919 1. Uplink
2920 2. Linksys350/Linksys300N
2921 3. <50 disable, >55 enable
2922 */
2923
2924 if(pHTInfo->IOTPeer == HT_IOT_PEER_BROADCOM)
2925 {
2926 curTxOkCnt = priv->stats.txbytesunicast - lastTxOkCnt;
2927 curRxOkCnt = priv->stats.rxbytesunicast - lastRxOkCnt;
2928 if(curRxOkCnt > 4*curTxOkCnt) //downlink, disable CTS to self
2929 {
2930 pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
2931 //DbgPrint("dm_CTSToSelf() ==> CTS to self disabled -- downlink\n");
2932 }
2933 else //uplink
2934 {
2935 #if 1
2936 pHTInfo->IOTAction |= HT_IOT_ACT_FORCED_CTS2SELF;
2937 #else
2938 if(priv->undecorated_smoothed_pwdb < priv->ieee80211->CTSToSelfTH) // disable CTS to self
2939 {
2940 pHTInfo->IOTAction &= ~HT_IOT_ACT_FORCED_CTS2SELF;
2941 //DbgPrint("dm_CTSToSelf() ==> CTS to self disabled\n");
2942 }
2943 else if(priv->undecorated_smoothed_pwdb >= (priv->ieee80211->CTSToSelfTH+5)) // enable CTS to self
2944 {
2945 pHTInfo->IOTAction |= HT_IOT_ACT_FORCED_CTS2SELF;
2946 //DbgPrint("dm_CTSToSelf() ==> CTS to self enabled\n");
2947 }
2948 #endif
2949 }
2950
2951 lastTxOkCnt = priv->stats.txbytesunicast;
2952 lastRxOkCnt = priv->stats.rxbytesunicast;
2953 }
2954}
2955
2956
2957#if 0
2958/*-----------------------------------------------------------------------------
2959 * Function: dm_rf_operation_test_callback()
2960 *
2961 * Overview: Only for RF operation test now.
2962 *
2963 * Input: NONE
2964 *
2965 * Output: NONE
2966 *
2967 * Return: NONE
2968 *
2969 * Revised History:
2970 * When Who Remark
2971 * 05/29/2008 amy Create Version 0 porting from windows code.
2972 *
2973 *---------------------------------------------------------------------------*/
2974extern void dm_rf_operation_test_callback(unsigned long dev)
2975{
2976// struct r8192_priv *priv = ieee80211_priv((struct net_device *)dev);
2977 u8 erfpath;
2978
2979
2980 for(erfpath=0; erfpath<4; erfpath++)
2981 {
2982 //DbgPrint("Set RF-%d\n\r", eRFPath);
2983 //PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x2c, bMask12Bits, 0x3d7);
2984 udelay(100);
2985 }
2986
2987 {
2988 //PlatformSetPeriodicTimer(Adapter, &pHalData->RfTest1Timer, 500);
2989 }
2990
2991 // For test
2992 {
2993 //u8 i;
2994 //PlatformSetPeriodicTimer(Adapter, &pHalData->RfTest1Timer, 500);
2995#if 0
2996 for(i=0; i<50; i++)
2997 {
2998 // Write Test
2999 PHY_SetRFReg(Adapter, RF90_PATH_A, 0x02, bMask12Bits, 0x4d);
3000 //delay_us(100);
3001 PHY_SetRFReg(Adapter, RF90_PATH_A, 0x02, bMask12Bits, 0x4f);
3002 //delay_us(100);
3003 PHY_SetRFReg(Adapter, RF90_PATH_C, 0x02, bMask12Bits, 0x4d);
3004 //delay_us(100);
3005 PHY_SetRFReg(Adapter, RF90_PATH_C, 0x02, bMask12Bits, 0x4f);
3006 //delay_us(100);
3007
3008#if 0
3009 // Read test
3010 PHY_QueryRFReg(Adapter, RF90_PATH_A, 0x02, bMask12Bits);
3011 //delay_us(100);
3012 PHY_QueryRFReg(Adapter, RF90_PATH_A, 0x02, bMask12Bits);
3013 //delay_us(100);
3014 PHY_QueryRFReg(Adapter, RF90_PATH_A, 0x12, bMask12Bits);
3015 //delay_us(100);
3016 PHY_QueryRFReg(Adapter, RF90_PATH_A, 0x12, bMask12Bits);
3017 //delay_us(100);
3018 PHY_QueryRFReg(Adapter, RF90_PATH_A, 0x21, bMask12Bits);
3019 //delay_us(100);
3020 PHY_QueryRFReg(Adapter, RF90_PATH_A, 0x21, bMask12Bits);
3021 //delay_us(100);
3022#endif
3023 }
3024#endif
3025 }
3026
3027} /* DM_RfOperationTestCallBack */
3028#endif
3029
3030/*-----------------------------------------------------------------------------
3031 * Function: dm_check_rfctrl_gpio()
3032 *
3033 * Overview: Copy 8187B template for 9xseries.
3034 *
3035 * Input: NONE
3036 *
3037 * Output: NONE
3038 *
3039 * Return: NONE
3040 *
3041 * Revised History:
3042 * When Who Remark
3043 * 05/28/2008 amy Create Version 0 porting from windows code.
3044 *
3045 *---------------------------------------------------------------------------*/
3046#if 1
3047static void dm_check_rfctrl_gpio(struct net_device * dev)
3048{
3049 //struct r8192_priv *priv = ieee80211_priv(dev);
3050
3051 // Walk around for DTM test, we will not enable HW - radio on/off because r/w
3052 // page 1 register before Lextra bus is enabled cause system fails when resuming
3053 // from S4. 20080218, Emily
3054
3055 // Stop to execute workitem to prevent S3/S4 bug.
3056#ifdef RTL8190P
3057 return;
3058#endif
3059#ifdef RTL8192U
3060 return;
3061#endif
3062#ifdef RTL8192E
3063 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3064 queue_delayed_work(priv->priv_wq,&priv->gpio_change_rf_wq,0);
3065 #else
3066 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
3067 schedule_task(&priv->gpio_change_rf_wq);
3068 #else
3069 queue_work(priv->priv_wq,&priv->gpio_change_rf_wq);
3070 #endif
3071 #endif
3072#endif
3073
3074} /* dm_CheckRfCtrlGPIO */
3075
3076#endif
3077/*-----------------------------------------------------------------------------
3078 * Function: dm_check_pbc_gpio()
3079 *
3080 * Overview: Check if PBC button is pressed.
3081 *
3082 * Input: NONE
3083 *
3084 * Output: NONE
3085 *
3086 * Return: NONE
3087 *
3088 * Revised History:
3089 * When Who Remark
3090 * 05/28/2008 amy Create Version 0 porting from windows code.
3091 *
3092 *---------------------------------------------------------------------------*/
3093static void dm_check_pbc_gpio(struct net_device *dev)
3094{
3095#ifdef RTL8192U
3096 struct r8192_priv *priv = ieee80211_priv(dev);
3097 u8 tmp1byte;
3098
3099
3100 tmp1byte = read_nic_byte(dev,GPI);
3101 if(tmp1byte == 0xff)
3102 return;
3103
3104 if (tmp1byte&BIT6 || tmp1byte&BIT0)
3105 {
3106 // Here we only set bPbcPressed to TRUE
3107 // After trigger PBC, the variable will be set to FALSE
3108 RT_TRACE(COMP_IO, "CheckPbcGPIO - PBC is pressed\n");
3109 priv->bpbc_pressed = true;
3110 }
3111#endif
3112
3113}
3114
3115#ifdef RTL8192E
3116
3117/*-----------------------------------------------------------------------------
3118 * Function: dm_GPIOChangeRF
3119 * Overview: PCI will not support workitem call back HW radio on-off control.
3120 *
3121 * Input: NONE
3122 *
3123 * Output: NONE
3124 *
3125 * Return: NONE
3126 *
3127 * Revised History:
3128 * When Who Remark
3129 * 02/21/2008 MHC Create Version 0.
3130 *
3131 *---------------------------------------------------------------------------*/
3132 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3133extern void dm_gpio_change_rf_callback(struct work_struct *work)
3134{
3135 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
3136 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,gpio_change_rf_wq);
3137 struct net_device *dev = priv->ieee80211->dev;
3138#else
3139extern void dm_gpio_change_rf_callback(struct net_device *dev)
3140{
3141 struct r8192_priv *priv = ieee80211_priv(dev);
3142#endif
3143 u8 tmp1byte;
3144 RT_RF_POWER_STATE eRfPowerStateToSet;
3145 bool bActuallySet = false;
3146
3147 do{
3148 bActuallySet=false;
3149
3150 if(!priv->up)
3151 {
3152 RT_TRACE((COMP_INIT | COMP_POWER | COMP_RF),"dm_gpio_change_rf_callback(): Callback function breaks out!!\n");
3153 }
3154 else
3155 {
3156 // 0x108 GPIO input register is read only
3157 //set 0x108 B1= 1: RF-ON; 0: RF-OFF.
3158 tmp1byte = read_nic_byte(dev,GPI);
3159
3160 eRfPowerStateToSet = (tmp1byte&BIT1) ? eRfOn : eRfOff;
3161
3162 if( (priv->bHwRadioOff == true) && (eRfPowerStateToSet == eRfOn))
3163 {
3164 RT_TRACE(COMP_RF, "gpiochangeRF - HW Radio ON\n");
3165
3166 priv->bHwRadioOff = false;
3167 bActuallySet = true;
3168 }
3169 else if ( (priv->bHwRadioOff == false) && (eRfPowerStateToSet == eRfOff))
3170 {
3171 RT_TRACE(COMP_RF, "gpiochangeRF - HW Radio OFF\n");
3172 priv->bHwRadioOff = true;
3173 bActuallySet = true;
3174 }
3175
3176 if(bActuallySet)
3177 {
3178 #ifdef TO_DO
3179 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
3180 //DrvIFIndicateCurrentPhyStatus(pAdapter);
3181 #endif
3182 }
3183 else
3184 {
3185 msleep(2000);
3186 }
3187
3188 }
3189 }while(TRUE)
3190
3191} /* dm_GPIOChangeRF */
3192
3193#endif
3194/*-----------------------------------------------------------------------------
3195 * Function: DM_RFPathCheckWorkItemCallBack()
3196 *
3197 * Overview: Check if Current RF RX path is enabled
3198 *
3199 * Input: NONE
3200 *
3201 * Output: NONE
3202 *
3203 * Return: NONE
3204 *
3205 * Revised History:
3206 * When Who Remark
3207 * 01/30/2008 MHC Create Version 0.
3208 *
3209 *---------------------------------------------------------------------------*/
3210#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3211extern void dm_rf_pathcheck_workitemcallback(struct work_struct *work)
3212{
3213 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
3214 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,rfpath_check_wq);
3215 struct net_device *dev =priv->ieee80211->dev;
3216#else
3217extern void dm_rf_pathcheck_workitemcallback(struct net_device *dev)
3218{
3219 struct r8192_priv *priv = ieee80211_priv(dev);
3220#endif
3221 //bool bactually_set = false;
3222 u8 rfpath = 0, i;
3223
3224
3225 /* 2008/01/30 MH After discussing with SD3 Jerry, 0xc04/0xd04 register will
3226 always be the same. We only read 0xc04 now. */
3227 rfpath = read_nic_byte(dev, 0xc04);
3228
3229 // Check Bit 0-3, it means if RF A-D is enabled.
3230 for (i = 0; i < RF90_PATH_MAX; i++)
3231 {
3232 if (rfpath & (0x01<<i))
3233 priv->brfpath_rxenable[i] = 1;
3234 else
3235 priv->brfpath_rxenable[i] = 0;
3236 }
3237 if(!DM_RxPathSelTable.Enable)
3238 return;
3239
3240 dm_rxpath_sel_byrssi(dev);
3241} /* DM_RFPathCheckWorkItemCallBack */
3242
3243static void dm_init_rxpath_selection(struct net_device * dev)
3244{
3245 u8 i;
3246 struct r8192_priv *priv = ieee80211_priv(dev);
3247 DM_RxPathSelTable.Enable = 1; //default enabled
3248 DM_RxPathSelTable.SS_TH_low = RxPathSelection_SS_TH_low;
3249 DM_RxPathSelTable.diff_TH = RxPathSelection_diff_TH;
3250 if(priv->CustomerID == RT_CID_819x_Netcore)
3251 DM_RxPathSelTable.cck_method = CCK_Rx_Version_2;
3252 else
3253 DM_RxPathSelTable.cck_method = CCK_Rx_Version_1;
3254 DM_RxPathSelTable.DbgMode = DM_DBG_OFF;
3255 DM_RxPathSelTable.disabledRF = 0;
3256 for(i=0; i<4; i++)
3257 {
3258 DM_RxPathSelTable.rf_rssi[i] = 50;
3259 DM_RxPathSelTable.cck_pwdb_sta[i] = -64;
3260 DM_RxPathSelTable.rf_enable_rssi_th[i] = 100;
3261 }
3262}
3263
3264static void dm_rxpath_sel_byrssi(struct net_device * dev)
3265{
3266 struct r8192_priv *priv = ieee80211_priv(dev);
3267 u8 i, max_rssi_index=0, min_rssi_index=0, sec_rssi_index=0, rf_num=0;
3268 u8 tmp_max_rssi=0, tmp_min_rssi=0, tmp_sec_rssi=0;
3269 u8 cck_default_Rx=0x2; //RF-C
3270 u8 cck_optional_Rx=0x3;//RF-D
3271 long tmp_cck_max_pwdb=0, tmp_cck_min_pwdb=0, tmp_cck_sec_pwdb=0;
3272 u8 cck_rx_ver2_max_index=0, cck_rx_ver2_min_index=0, cck_rx_ver2_sec_index=0;
3273 u8 cur_rf_rssi;
3274 long cur_cck_pwdb;
3275 static u8 disabled_rf_cnt=0, cck_Rx_Path_initialized=0;
3276 u8 update_cck_rx_path;
3277
3278 if(priv->rf_type != RF_2T4R)
3279 return;
3280
3281 if(!cck_Rx_Path_initialized)
3282 {
3283 DM_RxPathSelTable.cck_Rx_path = (read_nic_byte(dev, 0xa07)&0xf);
3284 cck_Rx_Path_initialized = 1;
3285 }
3286
3287 DM_RxPathSelTable.disabledRF = 0xf;
3288 DM_RxPathSelTable.disabledRF &=~ (read_nic_byte(dev, 0xc04));
3289
3290 if(priv->ieee80211->mode == WIRELESS_MODE_B)
3291 {
3292 DM_RxPathSelTable.cck_method = CCK_Rx_Version_2; //pure B mode, fixed cck version2
3293 //DbgPrint("Pure B mode, use cck rx version2 \n");
3294 }
3295
3296 //decide max/sec/min rssi index
3297 for (i=0; i<RF90_PATH_MAX; i++)
3298 {
3299 if(!DM_RxPathSelTable.DbgMode)
3300 DM_RxPathSelTable.rf_rssi[i] = priv->stats.rx_rssi_percentage[i];
3301
3302 if(priv->brfpath_rxenable[i])
3303 {
3304 rf_num++;
3305 cur_rf_rssi = DM_RxPathSelTable.rf_rssi[i];
3306
3307 if(rf_num == 1) // find first enabled rf path and the rssi values
3308 { //initialize, set all rssi index to the same one
3309 max_rssi_index = min_rssi_index = sec_rssi_index = i;
3310 tmp_max_rssi = tmp_min_rssi = tmp_sec_rssi = cur_rf_rssi;
3311 }
3312 else if(rf_num == 2)
3313 { // we pick up the max index first, and let sec and min to be the same one
3314 if(cur_rf_rssi >= tmp_max_rssi)
3315 {
3316 tmp_max_rssi = cur_rf_rssi;
3317 max_rssi_index = i;
3318 }
3319 else
3320 {
3321 tmp_sec_rssi = tmp_min_rssi = cur_rf_rssi;
3322 sec_rssi_index = min_rssi_index = i;
3323 }
3324 }
3325 else
3326 {
3327 if(cur_rf_rssi > tmp_max_rssi)
3328 {
3329 tmp_sec_rssi = tmp_max_rssi;
3330 sec_rssi_index = max_rssi_index;
3331 tmp_max_rssi = cur_rf_rssi;
3332 max_rssi_index = i;
3333 }
3334 else if(cur_rf_rssi == tmp_max_rssi)
3335 { // let sec and min point to the different index
3336 tmp_sec_rssi = cur_rf_rssi;
3337 sec_rssi_index = i;
3338 }
3339 else if((cur_rf_rssi < tmp_max_rssi) &&(cur_rf_rssi > tmp_sec_rssi))
3340 {
3341 tmp_sec_rssi = cur_rf_rssi;
3342 sec_rssi_index = i;
3343 }
3344 else if(cur_rf_rssi == tmp_sec_rssi)
3345 {
3346 if(tmp_sec_rssi == tmp_min_rssi)
3347 { // let sec and min point to the different index
3348 tmp_sec_rssi = cur_rf_rssi;
3349 sec_rssi_index = i;
3350 }
3351 else
3352 {
3353 // This case we don't need to set any index
3354 }
3355 }
3356 else if((cur_rf_rssi < tmp_sec_rssi) && (cur_rf_rssi > tmp_min_rssi))
3357 {
3358 // This case we don't need to set any index
3359 }
3360 else if(cur_rf_rssi == tmp_min_rssi)
3361 {
3362 if(tmp_sec_rssi == tmp_min_rssi)
3363 { // let sec and min point to the different index
3364 tmp_min_rssi = cur_rf_rssi;
3365 min_rssi_index = i;
3366 }
3367 else
3368 {
3369 // This case we don't need to set any index
3370 }
3371 }
3372 else if(cur_rf_rssi < tmp_min_rssi)
3373 {
3374 tmp_min_rssi = cur_rf_rssi;
3375 min_rssi_index = i;
3376 }
3377 }
3378 }
3379 }
3380
3381 rf_num = 0;
3382 // decide max/sec/min cck pwdb index
3383 if(DM_RxPathSelTable.cck_method == CCK_Rx_Version_2)
3384 {
3385 for (i=0; i<RF90_PATH_MAX; i++)
3386 {
3387 if(priv->brfpath_rxenable[i])
3388 {
3389 rf_num++;
3390 cur_cck_pwdb = DM_RxPathSelTable.cck_pwdb_sta[i];
3391
3392 if(rf_num == 1) // find first enabled rf path and the rssi values
3393 { //initialize, set all rssi index to the same one
3394 cck_rx_ver2_max_index = cck_rx_ver2_min_index = cck_rx_ver2_sec_index = i;
3395 tmp_cck_max_pwdb = tmp_cck_min_pwdb = tmp_cck_sec_pwdb = cur_cck_pwdb;
3396 }
3397 else if(rf_num == 2)
3398 { // we pick up the max index first, and let sec and min to be the same one
3399 if(cur_cck_pwdb >= tmp_cck_max_pwdb)
3400 {
3401 tmp_cck_max_pwdb = cur_cck_pwdb;
3402 cck_rx_ver2_max_index = i;
3403 }
3404 else
3405 {
3406 tmp_cck_sec_pwdb = tmp_cck_min_pwdb = cur_cck_pwdb;
3407 cck_rx_ver2_sec_index = cck_rx_ver2_min_index = i;
3408 }
3409 }
3410 else
3411 {
3412 if(cur_cck_pwdb > tmp_cck_max_pwdb)
3413 {
3414 tmp_cck_sec_pwdb = tmp_cck_max_pwdb;
3415 cck_rx_ver2_sec_index = cck_rx_ver2_max_index;
3416 tmp_cck_max_pwdb = cur_cck_pwdb;
3417 cck_rx_ver2_max_index = i;
3418 }
3419 else if(cur_cck_pwdb == tmp_cck_max_pwdb)
3420 { // let sec and min point to the different index
3421 tmp_cck_sec_pwdb = cur_cck_pwdb;
3422 cck_rx_ver2_sec_index = i;
3423 }
3424 else if((cur_cck_pwdb < tmp_cck_max_pwdb) &&(cur_cck_pwdb > tmp_cck_sec_pwdb))
3425 {
3426 tmp_cck_sec_pwdb = cur_cck_pwdb;
3427 cck_rx_ver2_sec_index = i;
3428 }
3429 else if(cur_cck_pwdb == tmp_cck_sec_pwdb)
3430 {
3431 if(tmp_cck_sec_pwdb == tmp_cck_min_pwdb)
3432 { // let sec and min point to the different index
3433 tmp_cck_sec_pwdb = cur_cck_pwdb;
3434 cck_rx_ver2_sec_index = i;
3435 }
3436 else
3437 {
3438 // This case we don't need to set any index
3439 }
3440 }
3441 else if((cur_cck_pwdb < tmp_cck_sec_pwdb) && (cur_cck_pwdb > tmp_cck_min_pwdb))
3442 {
3443 // This case we don't need to set any index
3444 }
3445 else if(cur_cck_pwdb == tmp_cck_min_pwdb)
3446 {
3447 if(tmp_cck_sec_pwdb == tmp_cck_min_pwdb)
3448 { // let sec and min point to the different index
3449 tmp_cck_min_pwdb = cur_cck_pwdb;
3450 cck_rx_ver2_min_index = i;
3451 }
3452 else
3453 {
3454 // This case we don't need to set any index
3455 }
3456 }
3457 else if(cur_cck_pwdb < tmp_cck_min_pwdb)
3458 {
3459 tmp_cck_min_pwdb = cur_cck_pwdb;
3460 cck_rx_ver2_min_index = i;
3461 }
3462 }
3463
3464 }
3465 }
3466 }
3467
3468
3469 // Set CCK Rx path
3470 // reg0xA07[3:2]=cck default rx path, reg0xa07[1:0]=cck optional rx path.
3471 update_cck_rx_path = 0;
3472 if(DM_RxPathSelTable.cck_method == CCK_Rx_Version_2)
3473 {
3474 cck_default_Rx = cck_rx_ver2_max_index;
3475 cck_optional_Rx = cck_rx_ver2_sec_index;
3476 if(tmp_cck_max_pwdb != -64)
3477 update_cck_rx_path = 1;
3478 }
3479
3480 if(tmp_min_rssi < DM_RxPathSelTable.SS_TH_low && disabled_rf_cnt < 2)
3481 {
3482 if((tmp_max_rssi - tmp_min_rssi) >= DM_RxPathSelTable.diff_TH)
3483 {
3484 //record the enabled rssi threshold
3485 DM_RxPathSelTable.rf_enable_rssi_th[min_rssi_index] = tmp_max_rssi+5;
3486 //disable the BB Rx path, OFDM
3487 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x1<<min_rssi_index, 0x0); // 0xc04[3:0]
3488 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x1<<min_rssi_index, 0x0); // 0xd04[3:0]
3489 disabled_rf_cnt++;
3490 }
3491 if(DM_RxPathSelTable.cck_method == CCK_Rx_Version_1)
3492 {
3493 cck_default_Rx = max_rssi_index;
3494 cck_optional_Rx = sec_rssi_index;
3495 if(tmp_max_rssi)
3496 update_cck_rx_path = 1;
3497 }
3498 }
3499
3500 if(update_cck_rx_path)
3501 {
3502 DM_RxPathSelTable.cck_Rx_path = (cck_default_Rx<<2)|(cck_optional_Rx);
3503 rtl8192_setBBreg(dev, rCCK0_AFESetting, 0x0f000000, DM_RxPathSelTable.cck_Rx_path);
3504 }
3505
3506 if(DM_RxPathSelTable.disabledRF)
3507 {
3508 for(i=0; i<4; i++)
3509 {
3510 if((DM_RxPathSelTable.disabledRF>>i) & 0x1) //disabled rf
3511 {
3512 if(tmp_max_rssi >= DM_RxPathSelTable.rf_enable_rssi_th[i])
3513 {
3514 //enable the BB Rx path
3515 //DbgPrint("RF-%d is enabled. \n", 0x1<<i);
3516 rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0x1<<i, 0x1); // 0xc04[3:0]
3517 rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0x1<<i, 0x1); // 0xd04[3:0]
3518 DM_RxPathSelTable.rf_enable_rssi_th[i] = 100;
3519 disabled_rf_cnt--;
3520 }
3521 }
3522 }
3523 }
3524}
3525
3526/*-----------------------------------------------------------------------------
3527 * Function: dm_check_rx_path_selection()
3528 *
3529 * Overview: Call a workitem to check current RXRF path and Rx Path selection by RSSI.
3530 *
3531 * Input: NONE
3532 *
3533 * Output: NONE
3534 *
3535 * Return: NONE
3536 *
3537 * Revised History:
3538 * When Who Remark
3539 * 05/28/2008 amy Create Version 0 porting from windows code.
3540 *
3541 *---------------------------------------------------------------------------*/
3542static void dm_check_rx_path_selection(struct net_device *dev)
3543{
3544 struct r8192_priv *priv = ieee80211_priv(dev);
3545#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3546 queue_delayed_work(priv->priv_wq,&priv->rfpath_check_wq,0);
3547#else
3548#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
3549 schedule_task(&priv->rfpath_check_wq);
3550#else
3551 queue_work(priv->priv_wq,&priv->rfpath_check_wq);
3552#endif
3553#endif
3554} /* dm_CheckRxRFPath */
3555
3556
3557static void dm_init_fsync (struct net_device *dev)
3558{
3559 struct r8192_priv *priv = ieee80211_priv(dev);
3560
3561 priv->ieee80211->fsync_time_interval = 500;
3562 priv->ieee80211->fsync_rate_bitmap = 0x0f000800;
3563 priv->ieee80211->fsync_rssi_threshold = 30;
3564#ifdef RTL8190P
3565 priv->ieee80211->bfsync_enable = true;
3566#else
3567 priv->ieee80211->bfsync_enable = false;
3568#endif
3569 priv->ieee80211->fsync_multiple_timeinterval = 3;
3570 priv->ieee80211->fsync_firstdiff_ratethreshold= 100;
3571 priv->ieee80211->fsync_seconddiff_ratethreshold= 200;
3572 priv->ieee80211->fsync_state = Default_Fsync;
3573 priv->framesyncMonitor = 1; // current default 0xc38 monitor on
3574
3575 init_timer(&priv->fsync_timer);
3576 priv->fsync_timer.data = (unsigned long)dev;
3577 priv->fsync_timer.function = dm_fsync_timer_callback;
3578}
3579
3580
3581static void dm_deInit_fsync(struct net_device *dev)
3582{
3583 struct r8192_priv *priv = ieee80211_priv(dev);
3584 del_timer_sync(&priv->fsync_timer);
3585}
3586
3587extern void dm_fsync_timer_callback(unsigned long data)
3588{
3589 struct net_device *dev = (struct net_device *)data;
3590 struct r8192_priv *priv = ieee80211_priv((struct net_device *)data);
3591 u32 rate_index, rate_count = 0, rate_count_diff=0;
3592 bool bSwitchFromCountDiff = false;
3593 bool bDoubleTimeInterval = false;
3594
3595 if( priv->ieee80211->state == IEEE80211_LINKED &&
3596 priv->ieee80211->bfsync_enable &&
3597 (priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_CDD_FSYNC))
3598 {
3599 // Count rate 54, MCS [7], [12, 13, 14, 15]
3600 u32 rate_bitmap;
3601 for(rate_index = 0; rate_index <= 27; rate_index++)
3602 {
3603 rate_bitmap = 1 << rate_index;
3604 if(priv->ieee80211->fsync_rate_bitmap & rate_bitmap)
3605 rate_count+= priv->stats.received_rate_histogram[1][rate_index];
3606 }
3607
3608 if(rate_count < priv->rate_record)
3609 rate_count_diff = 0xffffffff - rate_count + priv->rate_record;
3610 else
3611 rate_count_diff = rate_count - priv->rate_record;
3612 if(rate_count_diff < priv->rateCountDiffRecord)
3613 {
3614
3615 u32 DiffNum = priv->rateCountDiffRecord - rate_count_diff;
3616 // Contiune count
3617 if(DiffNum >= priv->ieee80211->fsync_seconddiff_ratethreshold)
3618 priv->ContiuneDiffCount++;
3619 else
3620 priv->ContiuneDiffCount = 0;
3621
3622 // Contiune count over
3623 if(priv->ContiuneDiffCount >=2)
3624 {
3625 bSwitchFromCountDiff = true;
3626 priv->ContiuneDiffCount = 0;
3627 }
3628 }
3629 else
3630 {
3631 // Stop contiune count
3632 priv->ContiuneDiffCount = 0;
3633 }
3634
3635 //If Count diff <= FsyncRateCountThreshold
3636 if(rate_count_diff <= priv->ieee80211->fsync_firstdiff_ratethreshold)
3637 {
3638 bSwitchFromCountDiff = true;
3639 priv->ContiuneDiffCount = 0;
3640 }
3641 priv->rate_record = rate_count;
3642 priv->rateCountDiffRecord = rate_count_diff;
3643 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff , priv->bswitch_fsync);
3644 // if we never receive those mcs rate and rssi > 30 % then switch fsyn
3645 if(priv->undecorated_smoothed_pwdb > priv->ieee80211->fsync_rssi_threshold && bSwitchFromCountDiff)
3646 {
3647 bDoubleTimeInterval = true;
3648 priv->bswitch_fsync = !priv->bswitch_fsync;
3649 if(priv->bswitch_fsync)
3650 {
3651 #ifdef RTL8190P
3652 write_nic_byte(dev, 0xC36, 0x00);
3653 #else
3654 write_nic_byte(dev,0xC36, 0x1c);
3655 #endif
3656 write_nic_byte(dev, 0xC3e, 0x90);
3657 }
3658 else
3659 {
3660 #ifdef RTL8190P
3661 write_nic_byte(dev, 0xC36, 0x40);
3662 #else
3663 write_nic_byte(dev, 0xC36, 0x5c);
3664 #endif
3665 write_nic_byte(dev, 0xC3e, 0x96);
3666 }
3667 }
3668 else if(priv->undecorated_smoothed_pwdb <= priv->ieee80211->fsync_rssi_threshold)
3669 {
3670 if(priv->bswitch_fsync)
3671 {
3672 priv->bswitch_fsync = false;
3673 #ifdef RTL8190P
3674 write_nic_byte(dev, 0xC36, 0x40);
3675 #else
3676 write_nic_byte(dev, 0xC36, 0x5c);
3677 #endif
3678 write_nic_byte(dev, 0xC3e, 0x96);
3679 }
3680 }
3681 if(bDoubleTimeInterval){
3682 if(timer_pending(&priv->fsync_timer))
3683 del_timer_sync(&priv->fsync_timer);
3684 priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval*priv->ieee80211->fsync_multiple_timeinterval);
3685 add_timer(&priv->fsync_timer);
3686 }
3687 else{
3688 if(timer_pending(&priv->fsync_timer))
3689 del_timer_sync(&priv->fsync_timer);
3690 priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval);
3691 add_timer(&priv->fsync_timer);
3692 }
3693 }
3694 else
3695 {
3696 // Let Register return to default value;
3697 if(priv->bswitch_fsync)
3698 {
3699 priv->bswitch_fsync = false;
3700 #ifdef RTL8190P
3701 write_nic_byte(dev, 0xC36, 0x40);
3702 #else
3703 write_nic_byte(dev, 0xC36, 0x5c);
3704 #endif
3705 write_nic_byte(dev, 0xC3e, 0x96);
3706 }
3707 priv->ContiuneDiffCount = 0;
3708 #ifdef RTL8190P
3709 write_nic_dword(dev, rOFDM0_RxDetector2, 0x164052cd);
3710 #else
3711 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
3712 #endif
3713 }
3714 RT_TRACE(COMP_HALDM, "ContiuneDiffCount %d\n", priv->ContiuneDiffCount);
3715 RT_TRACE(COMP_HALDM, "rateRecord %d rateCount %d, rateCountdiff %d bSwitchFsync %d\n", priv->rate_record, rate_count, rate_count_diff , priv->bswitch_fsync);
3716}
3717
3718static void dm_StartHWFsync(struct net_device *dev)
3719{
3720 RT_TRACE(COMP_HALDM, "%s\n", __FUNCTION__);
3721 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c12cf);
3722 write_nic_byte(dev, 0xc3b, 0x41);
3723}
3724
3725static void dm_EndSWFsync(struct net_device *dev)
3726{
3727 struct r8192_priv *priv = ieee80211_priv(dev);
3728
3729 RT_TRACE(COMP_HALDM, "%s\n", __FUNCTION__);
3730 del_timer_sync(&(priv->fsync_timer));
3731
3732 // Let Register return to default value;
3733 if(priv->bswitch_fsync)
3734 {
3735 priv->bswitch_fsync = false;
3736
3737 #ifdef RTL8190P
3738 write_nic_byte(dev, 0xC36, 0x40);
3739 #else
3740 write_nic_byte(dev, 0xC36, 0x5c);
3741 #endif
3742
3743 write_nic_byte(dev, 0xC3e, 0x96);
3744 }
3745
3746 priv->ContiuneDiffCount = 0;
3747#ifndef RTL8190P
3748 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
3749#endif
3750
3751}
3752
3753static void dm_StartSWFsync(struct net_device *dev)
3754{
3755 struct r8192_priv *priv = ieee80211_priv(dev);
3756 u32 rateIndex;
3757 u32 rateBitmap;
3758
3759 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__);
3760 // Initial rate record to zero, start to record.
3761 priv->rate_record = 0;
3762 // Initial contiune diff count to zero, start to record.
3763 priv->ContiuneDiffCount = 0;
3764 priv->rateCountDiffRecord = 0;
3765 priv->bswitch_fsync = false;
3766
3767 if(priv->ieee80211->mode == WIRELESS_MODE_N_24G)
3768 {
3769 priv->ieee80211->fsync_firstdiff_ratethreshold= 600;
3770 priv->ieee80211->fsync_seconddiff_ratethreshold = 0xffff;
3771 }
3772 else
3773 {
3774 priv->ieee80211->fsync_firstdiff_ratethreshold= 200;
3775 priv->ieee80211->fsync_seconddiff_ratethreshold = 200;
3776 }
3777 for(rateIndex = 0; rateIndex <= 27; rateIndex++)
3778 {
3779 rateBitmap = 1 << rateIndex;
3780 if(priv->ieee80211->fsync_rate_bitmap & rateBitmap)
3781 priv->rate_record += priv->stats.received_rate_histogram[1][rateIndex];
3782 }
3783 if(timer_pending(&priv->fsync_timer))
3784 del_timer_sync(&priv->fsync_timer);
3785 priv->fsync_timer.expires = jiffies + MSECS(priv->ieee80211->fsync_time_interval);
3786 add_timer(&priv->fsync_timer);
3787
3788#ifndef RTL8190P
3789 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c12cd);
3790#endif
3791
3792}
3793
3794static void dm_EndHWFsync(struct net_device *dev)
3795{
3796 RT_TRACE(COMP_HALDM,"%s\n", __FUNCTION__);
3797 write_nic_dword(dev, rOFDM0_RxDetector2, 0x465c52cd);
3798 write_nic_byte(dev, 0xc3b, 0x49);
3799
3800}
3801
3802void dm_check_fsync(struct net_device *dev)
3803{
3804#define RegC38_Default 0
3805#define RegC38_NonFsync_Other_AP 1
3806#define RegC38_Fsync_AP_BCM 2
3807 struct r8192_priv *priv = ieee80211_priv(dev);
3808 //u32 framesyncC34;
3809 static u8 reg_c38_State=RegC38_Default;
3810 static u32 reset_cnt=0;
3811
3812 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);
3813 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);
3814
3815 if( priv->ieee80211->state == IEEE80211_LINKED &&
3816 (priv->ieee80211->pHTInfo->IOTAction & HT_IOT_ACT_CDD_FSYNC))
3817 {
3818 if(priv->ieee80211->bfsync_enable == 0)
3819 {
3820 switch(priv->ieee80211->fsync_state)
3821 {
3822 case Default_Fsync:
3823 dm_StartHWFsync(dev);
3824 priv->ieee80211->fsync_state = HW_Fsync;
3825 break;
3826 case SW_Fsync:
3827 dm_EndSWFsync(dev);
3828 dm_StartHWFsync(dev);
3829 priv->ieee80211->fsync_state = HW_Fsync;
3830 break;
3831 case HW_Fsync:
3832 default:
3833 break;
3834 }
3835 }
3836 else
3837 {
3838 switch(priv->ieee80211->fsync_state)
3839 {
3840 case Default_Fsync:
3841 dm_StartSWFsync(dev);
3842 priv->ieee80211->fsync_state = SW_Fsync;
3843 break;
3844 case HW_Fsync:
3845 dm_EndHWFsync(dev);
3846 dm_StartSWFsync(dev);
3847 priv->ieee80211->fsync_state = SW_Fsync;
3848 break;
3849 case SW_Fsync:
3850 default:
3851 break;
3852
3853 }
3854 }
3855 if(priv->framesyncMonitor)
3856 {
3857 if(reg_c38_State != RegC38_Fsync_AP_BCM)
3858 { //For broadcom AP we write different default value
3859 #ifdef RTL8190P
3860 write_nic_byte(dev, rOFDM0_RxDetector3, 0x15);
3861 #else
3862 write_nic_byte(dev, rOFDM0_RxDetector3, 0x95);
3863 #endif
3864
3865 reg_c38_State = RegC38_Fsync_AP_BCM;
3866 }
3867 }
3868 }
3869 else
3870 {
3871 switch(priv->ieee80211->fsync_state)
3872 {
3873 case HW_Fsync:
3874 dm_EndHWFsync(dev);
3875 priv->ieee80211->fsync_state = Default_Fsync;
3876 break;
3877 case SW_Fsync:
3878 dm_EndSWFsync(dev);
3879 priv->ieee80211->fsync_state = Default_Fsync;
3880 break;
3881 case Default_Fsync:
3882 default:
3883 break;
3884 }
3885
3886 if(priv->framesyncMonitor)
3887 {
3888 if(priv->ieee80211->state == IEEE80211_LINKED)
3889 {
3890 if(priv->undecorated_smoothed_pwdb <= RegC38_TH)
3891 {
3892 if(reg_c38_State != RegC38_NonFsync_Other_AP)
3893 {
3894 #ifdef RTL8190P
3895 write_nic_byte(dev, rOFDM0_RxDetector3, 0x10);
3896 #else
3897 write_nic_byte(dev, rOFDM0_RxDetector3, 0x90);
3898 #endif
3899
3900 reg_c38_State = RegC38_NonFsync_Other_AP;
3901 #if 0//cosa
3902 if (Adapter->HardwareType == HARDWARE_TYPE_RTL8190P)
3903 DbgPrint("Fsync is idle, rssi<=35, write 0xc38 = 0x%x \n", 0x10);
3904 else
3905 DbgPrint("Fsync is idle, rssi<=35, write 0xc38 = 0x%x \n", 0x90);
3906 #endif
3907 }
3908 }
3909 else if(priv->undecorated_smoothed_pwdb >= (RegC38_TH+5))
3910 {
3911 if(reg_c38_State)
3912 {
3913 write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
3914 reg_c38_State = RegC38_Default;
3915 //DbgPrint("Fsync is idle, rssi>=40, write 0xc38 = 0x%x \n", pHalData->framesync);
3916 }
3917 }
3918 }
3919 else
3920 {
3921 if(reg_c38_State)
3922 {
3923 write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
3924 reg_c38_State = RegC38_Default;
3925 //DbgPrint("Fsync is idle, not connected, write 0xc38 = 0x%x \n", pHalData->framesync);
3926 }
3927 }
3928 }
3929 }
3930 if(priv->framesyncMonitor)
3931 {
3932 if(priv->reset_count != reset_cnt)
3933 { //After silent reset, the reg_c38_State will be returned to default value
3934 write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
3935 reg_c38_State = RegC38_Default;
3936 reset_cnt = priv->reset_count;
3937 //DbgPrint("reg_c38_State = 0 for silent reset. \n");
3938 }
3939 }
3940 else
3941 {
3942 if(reg_c38_State)
3943 {
3944 write_nic_byte(dev, rOFDM0_RxDetector3, priv->framesync);
3945 reg_c38_State = RegC38_Default;
3946 //DbgPrint("framesync no monitor, write 0xc38 = 0x%x \n", pHalData->framesync);
3947 }
3948 }
3949}
3950
3951#if 0
3952/*-----------------------------------------------------------------------------
3953 * Function: DM_CheckLBusStatus()
3954 *
3955 * Overview: For 9x series, we must make sure LBUS is active for IO.
3956 *
3957 * Input: NONE
3958 *
3959 * Output: NONE
3960 *
3961 * Return: NONE
3962 *
3963 * Revised History:
3964 * When Who Remark
3965 * 02/22/2008 MHC Create Version 0.
3966 *
3967 *---------------------------------------------------------------------------*/
3968extern s1Byte DM_CheckLBusStatus(IN PADAPTER Adapter)
3969{
3970 PMGNT_INFO pMgntInfo=&Adapter->MgntInfo;
3971
3972#if (HAL_CODE_BASE & RTL819X)
3973
3974#if (HAL_CODE_BASE == RTL8192)
3975
3976#if( DEV_BUS_TYPE==PCI_INTERFACE)
3977 //return (pMgntInfo->bLbusEnable); // For debug only
3978 return TRUE;
3979#endif
3980
3981#if( DEV_BUS_TYPE==USB_INTERFACE)
3982 return TRUE;
3983#endif
3984
3985#endif // #if (HAL_CODE_BASE == RTL8192)
3986
3987#if (HAL_CODE_BASE == RTL8190)
3988 return TRUE;
3989#endif // #if (HAL_CODE_BASE == RTL8190)
3990
3991#endif // #if (HAL_CODE_BASE & RTL819X)
3992} /* DM_CheckLBusStatus */
3993
3994#endif
3995
3996/*-----------------------------------------------------------------------------
3997 * Function: dm_shadow_init()
3998 *
3999 * Overview: Store all NIC MAC/BB register content.
4000 *
4001 * Input: NONE
4002 *
4003 * Output: NONE
4004 *
4005 * Return: NONE
4006 *
4007 * Revised History:
4008 * When Who Remark
4009 * 05/29/2008 amy Create Version 0 porting from windows code.
4010 *
4011 *---------------------------------------------------------------------------*/
4012extern void dm_shadow_init(struct net_device *dev)
4013{
4014 u8 page;
4015 u16 offset;
4016
4017 for (page = 0; page < 5; page++)
4018 for (offset = 0; offset < 256; offset++)
4019 {
4020 dm_shadow[page][offset] = read_nic_byte(dev, offset+page*256);
4021 //DbgPrint("P-%d/O-%02x=%02x\r\n", page, offset, DM_Shadow[page][offset]);
4022 }
4023
4024 for (page = 8; page < 11; page++)
4025 for (offset = 0; offset < 256; offset++)
4026 dm_shadow[page][offset] = read_nic_byte(dev, offset+page*256);
4027
4028 for (page = 12; page < 15; page++)
4029 for (offset = 0; offset < 256; offset++)
4030 dm_shadow[page][offset] = read_nic_byte(dev, offset+page*256);
4031
4032} /* dm_shadow_init */
4033
4034/*---------------------------Define function prototype------------------------*/
4035/*-----------------------------------------------------------------------------
4036 * Function: DM_DynamicTxPower()
4037 *
4038 * Overview: Detect Signal strength to control TX Registry
4039 Tx Power Control For Near/Far Range
4040 *
4041 * Input: NONE
4042 *
4043 * Output: NONE
4044 *
4045 * Return: NONE
4046 *
4047 * Revised History:
4048 * When Who Remark
4049 * 03/06/2008 Jacken Create Version 0.
4050 *
4051 *---------------------------------------------------------------------------*/
4052static void dm_init_dynamic_txpower(struct net_device *dev)
4053{
4054 struct r8192_priv *priv = ieee80211_priv(dev);
4055
4056 //Initial TX Power Control for near/far range , add by amy 2008/05/15, porting from windows code.
4057 priv->ieee80211->bdynamic_txpower_enable = true; //Default to enable Tx Power Control
4058 priv->bLastDTPFlag_High = false;
4059 priv->bLastDTPFlag_Low = false;
4060 priv->bDynamicTxHighPower = false;
4061 priv->bDynamicTxLowPower = false;
4062}
4063
4064static void dm_dynamic_txpower(struct net_device *dev)
4065{
4066 struct r8192_priv *priv = ieee80211_priv(dev);
4067 unsigned int txhipower_threshhold=0;
4068 unsigned int txlowpower_threshold=0;
4069 if(priv->ieee80211->bdynamic_txpower_enable != true)
4070 {
4071 priv->bDynamicTxHighPower = false;
4072 priv->bDynamicTxLowPower = false;
4073 return;
4074 }
4075 //printk("priv->ieee80211->current_network.unknown_cap_exist is %d ,priv->ieee80211->current_network.broadcom_cap_exist is %d\n",priv->ieee80211->current_network.unknown_cap_exist,priv->ieee80211->current_network.broadcom_cap_exist);
4076 if((priv->ieee80211->current_network.atheros_cap_exist ) && (priv->ieee80211->mode == IEEE_G)){
4077 txhipower_threshhold = TX_POWER_ATHEROAP_THRESH_HIGH;
4078 txlowpower_threshold = TX_POWER_ATHEROAP_THRESH_LOW;
4079 }
4080 else
4081 {
4082 txhipower_threshhold = TX_POWER_NEAR_FIELD_THRESH_HIGH;
4083 txlowpower_threshold = TX_POWER_NEAR_FIELD_THRESH_LOW;
4084 }
4085
4086// printk("=======>%s(): txhipower_threshhold is %d,txlowpower_threshold is %d\n",__FUNCTION__,txhipower_threshhold,txlowpower_threshold);
4087 RT_TRACE(COMP_TXAGC,"priv->undecorated_smoothed_pwdb = %ld \n" , priv->undecorated_smoothed_pwdb);
4088
4089 if(priv->ieee80211->state == IEEE80211_LINKED)
4090 {
4091 if(priv->undecorated_smoothed_pwdb >= txhipower_threshhold)
4092 {
4093 priv->bDynamicTxHighPower = true;
4094 priv->bDynamicTxLowPower = false;
4095 }
4096 else
4097 {
4098 // high power state check
4099 if(priv->undecorated_smoothed_pwdb < txlowpower_threshold && priv->bDynamicTxHighPower == true)
4100 {
4101 priv->bDynamicTxHighPower = false;
4102 }
4103 // low power state check
4104 if(priv->undecorated_smoothed_pwdb < 35)
4105 {
4106 priv->bDynamicTxLowPower = true;
4107 }
4108 else if(priv->undecorated_smoothed_pwdb >= 40)
4109 {
4110 priv->bDynamicTxLowPower = false;
4111 }
4112 }
4113 }
4114 else
4115 {
4116 //pHalData->bTXPowerCtrlforNearFarRange = !pHalData->bTXPowerCtrlforNearFarRange;
4117 priv->bDynamicTxHighPower = false;
4118 priv->bDynamicTxLowPower = false;
4119 }
4120
4121 if( (priv->bDynamicTxHighPower != priv->bLastDTPFlag_High ) ||
4122 (priv->bDynamicTxLowPower != priv->bLastDTPFlag_Low ) )
4123 {
4124 RT_TRACE(COMP_TXAGC,"SetTxPowerLevel8190() channel = %d \n" , priv->ieee80211->current_network.channel);
4125
4126#if defined(RTL8190P) || defined(RTL8192E)
4127 SetTxPowerLevel8190(Adapter,pHalData->CurrentChannel);
4128#endif
4129
4130#ifdef RTL8192U
4131 rtl8192_phy_setTxPower(dev,priv->ieee80211->current_network.channel);
4132 //pHalData->bStartTxCtrlByTPCNFR = FALSE; //Clear th flag of Set TX Power from Sitesurvey
4133#endif
4134 }
4135 priv->bLastDTPFlag_High = priv->bDynamicTxHighPower;
4136 priv->bLastDTPFlag_Low = priv->bDynamicTxLowPower;
4137
4138} /* dm_dynamic_txpower */
4139
4140//added by vivi, for read tx rate and retrycount
4141static void dm_check_txrateandretrycount(struct net_device * dev)
4142{
4143 struct r8192_priv *priv = ieee80211_priv(dev);
4144 struct ieee80211_device* ieee = priv->ieee80211;
4145 //for 11n tx rate
4146// priv->stats.CurrentShowTxate = read_nic_byte(dev, Current_Tx_Rate_Reg);
4147 ieee->softmac_stats.CurrentShowTxate = read_nic_byte(dev, Current_Tx_Rate_Reg);
4148 //printk("=============>tx_rate_reg:%x\n", ieee->softmac_stats.CurrentShowTxate);
4149 //for initial tx rate
4150// priv->stats.last_packet_rate = read_nic_byte(dev, Initial_Tx_Rate_Reg);
4151 ieee->softmac_stats.last_packet_rate = read_nic_byte(dev ,Initial_Tx_Rate_Reg);
4152 //for tx tx retry count
4153// priv->stats.txretrycount = read_nic_dword(dev, Tx_Retry_Count_Reg);
4154 ieee->softmac_stats.txretrycount = read_nic_dword(dev, Tx_Retry_Count_Reg);
4155}
4156
4157static void dm_send_rssi_tofw(struct net_device *dev)
4158{
4159 DCMD_TXCMD_T tx_cmd;
4160 struct r8192_priv *priv = ieee80211_priv(dev);
4161
4162 // If we test chariot, we should stop the TX command ?
4163 // Because 92E will always silent reset when we send tx command. We use register
4164 // 0x1e0(byte) to botify driver.
4165 write_nic_byte(dev, DRIVER_RSSI, (u8)priv->undecorated_smoothed_pwdb);
4166 return;
4167#if 1
4168 tx_cmd.Op = TXCMD_SET_RX_RSSI;
4169 tx_cmd.Length = 4;
4170 tx_cmd.Value = priv->undecorated_smoothed_pwdb;
4171
4172 cmpk_message_handle_tx(dev, (u8*)&tx_cmd,
4173 DESC_PACKET_TYPE_INIT, sizeof(DCMD_TXCMD_T));
4174#endif
4175}
4176
4177/*---------------------------Define function prototype------------------------*/
4178