1 /******************************************************************************
10 * Copyright 2007, Realtek Corp.
12 * The contents of this file is the sole property of Realtek Corp. It can not be
13 * be used, copied or modified without written permission from Realtek Corp.
15 *******************************************************************************/
16 #define _RTL871X_MP_C_
18 #include "osdep_service.h"
19 #include "drv_types.h"
20 #include "rtl871x_mp_phy_regdef.h"
21 #include "rtl8712_cmd.h"
23 static void _init_mp_priv_(struct mp_priv
*pmp_priv
)
25 pmp_priv
->mode
= _LOOPBOOK_MODE_
;
26 pmp_priv
->curr_ch
= 1;
27 pmp_priv
->curr_modem
= MIXED_PHY
;
28 pmp_priv
->curr_rateidx
= 0;
29 pmp_priv
->curr_txpoweridx
= 0x14;
30 pmp_priv
->antenna_tx
= ANTENNA_A
;
31 pmp_priv
->antenna_rx
= ANTENNA_AB
;
32 pmp_priv
->check_mp_pkt
= 0;
33 pmp_priv
->tx_pktcount
= 0;
34 pmp_priv
->rx_pktcount
= 0;
35 pmp_priv
->rx_crcerrpktcount
= 0;
38 static int init_mp_priv(struct mp_priv
*pmp_priv
)
41 struct mp_xmit_frame
*pmp_xmitframe
;
43 _init_mp_priv_(pmp_priv
);
44 _init_queue(&pmp_priv
->free_mp_xmitqueue
);
45 pmp_priv
->pallocated_mp_xmitframe_buf
= NULL
;
46 pmp_priv
->pallocated_mp_xmitframe_buf
= _malloc(NR_MP_XMITFRAME
*
47 sizeof(struct mp_xmit_frame
) + 4);
48 if (pmp_priv
->pallocated_mp_xmitframe_buf
== NULL
) {
50 goto _exit_init_mp_priv
;
52 pmp_priv
->pmp_xmtframe_buf
= pmp_priv
->pallocated_mp_xmitframe_buf
+
54 ((addr_t
)(pmp_priv
->pallocated_mp_xmitframe_buf
) & 3);
55 pmp_xmitframe
= (struct mp_xmit_frame
*)pmp_priv
->pmp_xmtframe_buf
;
56 for (i
= 0; i
< NR_MP_XMITFRAME
; i
++) {
57 _init_listhead(&(pmp_xmitframe
->list
));
58 list_insert_tail(&(pmp_xmitframe
->list
),
59 &(pmp_priv
->free_mp_xmitqueue
.queue
));
60 pmp_xmitframe
->pkt
= NULL
;
61 pmp_xmitframe
->frame_tag
= MP_FRAMETAG
;
62 pmp_xmitframe
->padapter
= pmp_priv
->papdater
;
65 pmp_priv
->free_mp_xmitframe_cnt
= NR_MP_XMITFRAME
;
71 static int free_mp_priv(struct mp_priv
*pmp_priv
)
74 kfree(pmp_priv
->pallocated_mp_xmitframe_buf
);
78 void mp871xinit(struct _adapter
*padapter
)
80 struct mp_priv
*pmppriv
= &padapter
->mppriv
;
82 pmppriv
->papdater
= padapter
;
83 init_mp_priv(pmppriv
);
86 void mp871xdeinit(struct _adapter
*padapter
)
88 struct mp_priv
*pmppriv
= &padapter
->mppriv
;
90 free_mp_priv(pmppriv
);
94 * Special for bb and rf reg read/write
96 static u32
fw_iocmd_read(struct _adapter
*pAdapter
, struct IOCMD_STRUCT iocmd
)
98 u32 cmd32
= 0, val32
= 0;
99 u8 iocmd_class
= iocmd
.cmdclass
;
100 u16 iocmd_value
= iocmd
.value
;
101 u8 iocmd_idx
= iocmd
.index
;
103 cmd32
= (iocmd_class
<< 24) | (iocmd_value
<< 8) | iocmd_idx
;
104 if (r8712_fw_cmd(pAdapter
, cmd32
))
105 r8712_fw_cmd_data(pAdapter
, &val32
, 1);
111 static u8
fw_iocmd_write(struct _adapter
*pAdapter
,
112 struct IOCMD_STRUCT iocmd
, u32 value
)
115 u8 iocmd_class
= iocmd
.cmdclass
;
116 u32 iocmd_value
= iocmd
.value
;
117 u8 iocmd_idx
= iocmd
.index
;
119 r8712_fw_cmd_data(pAdapter
, &value
, 0);
121 cmd32
= (iocmd_class
<< 24) | (iocmd_value
<< 8) | iocmd_idx
;
122 return r8712_fw_cmd(pAdapter
, cmd32
);
125 /* offset : 0X800~0XFFF */
126 u32
r8712_bb_reg_read(struct _adapter
*pAdapter
, u16 offset
)
128 u8 shift
= offset
& 0x0003; /* 4 byte access */
129 u16 bb_addr
= offset
& 0x0FFC; /* 4 byte access */
131 struct IOCMD_STRUCT iocmd
;
133 iocmd
.cmdclass
= IOCMD_CLASS_BB_RF
;
134 iocmd
.value
= bb_addr
;
135 iocmd
.index
= IOCMD_BB_READ_IDX
;
136 bb_val
= fw_iocmd_read(pAdapter
, iocmd
);
139 bb_val
>>= (shift
* 8);
141 bb_val2
= fw_iocmd_read(pAdapter
, iocmd
);
142 bb_val2
<<= ((4 - shift
) * 8);
148 /* offset : 0X800~0XFFF */
149 u8
r8712_bb_reg_write(struct _adapter
*pAdapter
, u16 offset
, u32 value
)
151 u8 shift
= offset
& 0x0003; /* 4 byte access */
152 u16 bb_addr
= offset
& 0x0FFC; /* 4 byte access */
153 struct IOCMD_STRUCT iocmd
;
155 iocmd
.cmdclass
= IOCMD_CLASS_BB_RF
;
156 iocmd
.value
= bb_addr
;
157 iocmd
.index
= IOCMD_BB_WRITE_IDX
;
160 u32 newValue
= value
;
162 oldValue
= r8712_bb_reg_read(pAdapter
, iocmd
.value
);
163 oldValue
&= (0xFFFFFFFF >> ((4 - shift
) * 8));
164 value
= oldValue
| (newValue
<< (shift
* 8));
165 if (fw_iocmd_write(pAdapter
, iocmd
, value
) == false)
168 oldValue
= r8712_bb_reg_read(pAdapter
, iocmd
.value
);
169 oldValue
&= (0xFFFFFFFF << (shift
* 8));
170 value
= oldValue
| (newValue
>> ((4 - shift
) * 8));
172 return fw_iocmd_write(pAdapter
, iocmd
, value
);
175 /* offset : 0x00 ~ 0xFF */
176 u32
r8712_rf_reg_read(struct _adapter
*pAdapter
, u8 path
, u8 offset
)
178 u16 rf_addr
= (path
<< 8) | offset
;
180 struct IOCMD_STRUCT iocmd
;
182 iocmd
.cmdclass
= IOCMD_CLASS_BB_RF
;
183 iocmd
.value
= rf_addr
;
184 iocmd
.index
= IOCMD_RF_READ_IDX
;
185 rf_data
= fw_iocmd_read(pAdapter
, iocmd
);
189 u8
r8712_rf_reg_write(struct _adapter
*pAdapter
, u8 path
, u8 offset
, u32 value
)
191 u16 rf_addr
= (path
<< 8) | offset
;
192 struct IOCMD_STRUCT iocmd
;
194 iocmd
.cmdclass
= IOCMD_CLASS_BB_RF
;
195 iocmd
.value
= rf_addr
;
196 iocmd
.index
= IOCMD_RF_WRIT_IDX
;
197 return fw_iocmd_write(pAdapter
, iocmd
, value
);
200 static u32
bitshift(u32 bitmask
)
204 for (i
= 0; i
<= 31; i
++)
205 if (((bitmask
>>i
) & 0x1) == 1)
210 static u32
get_bb_reg(struct _adapter
*pAdapter
, u16 offset
, u32 bitmask
)
212 u32 org_value
, bit_shift
, new_value
;
214 org_value
= r8712_bb_reg_read(pAdapter
, offset
);
215 bit_shift
= bitshift(bitmask
);
216 new_value
= (org_value
& bitmask
) >> bit_shift
;
220 static u8
set_bb_reg(struct _adapter
*pAdapter
,
225 u32 org_value
, bit_shift
, new_value
;
227 if (bitmask
!= bMaskDWord
) {
228 org_value
= r8712_bb_reg_read(pAdapter
, offset
);
229 bit_shift
= bitshift(bitmask
);
230 new_value
= ((org_value
& (~bitmask
)) | (value
<< bit_shift
));
233 return r8712_bb_reg_write(pAdapter
, offset
, new_value
);
236 static u32
get_rf_reg(struct _adapter
*pAdapter
, u8 path
, u8 offset
,
239 u32 org_value
, bit_shift
, new_value
;
241 org_value
= r8712_rf_reg_read(pAdapter
, path
, offset
);
242 bit_shift
= bitshift(bitmask
);
243 new_value
= (org_value
& bitmask
) >> bit_shift
;
247 static u8
set_rf_reg(struct _adapter
*pAdapter
, u8 path
, u8 offset
, u32 bitmask
,
250 u32 org_value
, bit_shift
, new_value
;
252 if (bitmask
!= bMaskDWord
) {
253 org_value
= r8712_rf_reg_read(pAdapter
, path
, offset
);
254 bit_shift
= bitshift(bitmask
);
255 new_value
= ((org_value
& (~bitmask
)) | (value
<< bit_shift
));
258 return r8712_rf_reg_write(pAdapter
, path
, offset
, new_value
);
264 * Use H2C command to change channel,
265 * not only modify rf register, but also other setting need to be done.
267 void r8712_SetChannel(struct _adapter
*pAdapter
)
269 struct cmd_priv
*pcmdpriv
= &pAdapter
->cmdpriv
;
270 struct cmd_obj
*pcmd
= NULL
;
271 struct SetChannel_parm
*pparm
= NULL
;
272 u16 code
= GEN_CMD_CODE(_SetChannel
);
274 pcmd
= (struct cmd_obj
*)_malloc(sizeof(struct cmd_obj
));
277 pparm
= (struct SetChannel_parm
*)_malloc(sizeof(struct
283 pparm
->curr_ch
= pAdapter
->mppriv
.curr_ch
;
284 init_h2fwcmd_w_parm_no_rsp(pcmd
, pparm
, code
);
285 r8712_enqueue_cmd(pcmdpriv
, pcmd
);
288 static void SetCCKTxPower(struct _adapter
*pAdapter
, u8 TxPower
)
293 set_bb_reg(pAdapter
, rTxAGC_CCK_Mcs32
, bTxAGCRateCCK
, TxAGC
);
296 static void SetOFDMTxPower(struct _adapter
*pAdapter
, u8 TxPower
)
300 TxAGC
|= ((TxPower
<<24)|(TxPower
<<16)|(TxPower
<<8)|TxPower
);
301 set_bb_reg(pAdapter
, rTxAGC_Rate18_06
, bTxAGCRate18_06
, TxAGC
);
302 set_bb_reg(pAdapter
, rTxAGC_Rate54_24
, bTxAGCRate54_24
, TxAGC
);
303 set_bb_reg(pAdapter
, rTxAGC_Mcs03_Mcs00
, bTxAGCRateMCS3_MCS0
, TxAGC
);
304 set_bb_reg(pAdapter
, rTxAGC_Mcs07_Mcs04
, bTxAGCRateMCS7_MCS4
, TxAGC
);
305 set_bb_reg(pAdapter
, rTxAGC_Mcs11_Mcs08
, bTxAGCRateMCS11_MCS8
, TxAGC
);
306 set_bb_reg(pAdapter
, rTxAGC_Mcs15_Mcs12
, bTxAGCRateMCS15_MCS12
, TxAGC
);
309 void r8712_SetTxPower(struct _adapter
*pAdapter
)
311 u8 TxPower
= pAdapter
->mppriv
.curr_txpoweridx
;
312 SetCCKTxPower(pAdapter
, TxPower
);
313 SetOFDMTxPower(pAdapter
, TxPower
);
316 void r8712_SetTxAGCOffset(struct _adapter
*pAdapter
, u32 ulTxAGCOffset
)
318 u32 TxAGCOffset_B
, TxAGCOffset_C
, TxAGCOffset_D
, tmpAGC
;
320 TxAGCOffset_B
= (ulTxAGCOffset
&0x000000ff);
321 TxAGCOffset_C
= ((ulTxAGCOffset
&0x0000ff00)>>8);
322 TxAGCOffset_D
= ((ulTxAGCOffset
&0x00ff0000)>>16);
323 tmpAGC
= (TxAGCOffset_D
<<8 | TxAGCOffset_C
<<4 | TxAGCOffset_B
);
324 set_bb_reg(pAdapter
, rFPGA0_TxGainStage
,
325 (bXBTxAGC
|bXCTxAGC
|bXDTxAGC
), tmpAGC
);
328 void r8712_SetDataRate(struct _adapter
*pAdapter
)
331 u8 offset
= RF_SYN_G2
;
334 value
= (pAdapter
->mppriv
.curr_rateidx
< 4) ? 0x4440 : 0xF200;
335 r8712_rf_reg_write(pAdapter
, path
, offset
, value
);
338 void r8712_SwitchBandwidth(struct _adapter
*pAdapter
)
340 /* 3 1.Set MAC register : BWOPMODE bit2:1 20MhzBW */
342 u8 Bandwidth
= pAdapter
->mppriv
.curr_bandwidth
;
344 regBwOpMode
= r8712_read8(pAdapter
, 0x10250203);
345 if (Bandwidth
== HT_CHANNEL_WIDTH_20
)
346 regBwOpMode
|= BIT(2);
348 regBwOpMode
&= ~(BIT(2));
349 r8712_write8(pAdapter
, 0x10250203, regBwOpMode
);
350 /* 3 2.Set PHY related register */
353 case HT_CHANNEL_WIDTH_20
:
354 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bRFMOD
, 0x0);
355 set_bb_reg(pAdapter
, rFPGA1_RFMOD
, bRFMOD
, 0x0);
356 /* Use PHY_REG.txt default value. Do not need to change.
357 * Correct the tx power for CCK rate in 40M.
358 * It is set in Tx descriptor for 8192x series
360 set_bb_reg(pAdapter
, rFPGA0_AnalogParameter2
, bMaskDWord
, 0x58);
363 case HT_CHANNEL_WIDTH_40
:
364 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bRFMOD
, 0x1);
365 set_bb_reg(pAdapter
, rFPGA1_RFMOD
, bRFMOD
, 0x1);
366 /* Use PHY_REG.txt default value. Do not need to change.
367 * Correct the tx power for CCK rate in 40M.
368 * Set Control channel to upper or lower. These settings are
369 * required only for 40MHz */
370 set_bb_reg(pAdapter
, rCCK0_System
, bCCKSideBand
,
371 (HAL_PRIME_CHNL_OFFSET_DONT_CARE
>>1));
372 set_bb_reg(pAdapter
, rOFDM1_LSTF
, 0xC00,
373 HAL_PRIME_CHNL_OFFSET_DONT_CARE
);
374 set_bb_reg(pAdapter
, rFPGA0_AnalogParameter2
, bMaskDWord
, 0x18);
380 /* 3 3.Set RF related register */
382 case HT_CHANNEL_WIDTH_20
:
383 set_rf_reg(pAdapter
, RF_PATH_A
, RF_CHNLBW
,
384 BIT(10) | BIT(11), 0x01);
386 case HT_CHANNEL_WIDTH_40
:
387 set_rf_reg(pAdapter
, RF_PATH_A
, RF_CHNLBW
,
388 BIT(10) | BIT(11), 0x00);
394 /*------------------------------Define structure----------------------------*/
395 struct R_ANTENNA_SELECT_OFDM
{
402 u32 r_ant_non_ht_s1
:4;
407 struct R_ANTENNA_SELECT_CCK
{
408 u8 r_cckrx_enable_2
:2;
413 void r8712_SwitchAntenna(struct _adapter
*pAdapter
)
415 u32 ofdm_tx_en_val
= 0, ofdm_tx_ant_sel_val
= 0;
416 u8 ofdm_rx_ant_sel_val
= 0;
417 u8 cck_ant_select_val
= 0;
418 u32 cck_ant_sel_val
= 0;
419 struct R_ANTENNA_SELECT_CCK
*p_cck_txrx
;
421 p_cck_txrx
= (struct R_ANTENNA_SELECT_CCK
*)&cck_ant_select_val
;
423 switch (pAdapter
->mppriv
.antenna_tx
) {
425 /* From SD3 Willis suggestion !!! Set RF A=TX and B as standby*/
426 set_bb_reg(pAdapter
, rFPGA0_XA_HSSIParameter2
, 0xe, 2);
427 set_bb_reg(pAdapter
, rFPGA0_XB_HSSIParameter2
, 0xe, 1);
428 ofdm_tx_en_val
= 0x3;
429 ofdm_tx_ant_sel_val
= 0x11111111;/* Power save */
430 p_cck_txrx
->r_ccktx_enable
= 0x8;
433 set_bb_reg(pAdapter
, rFPGA0_XA_HSSIParameter2
, 0xe, 1);
434 set_bb_reg(pAdapter
, rFPGA0_XB_HSSIParameter2
, 0xe, 2);
435 ofdm_tx_en_val
= 0x3;
436 ofdm_tx_ant_sel_val
= 0x22222222;/* Power save */
437 p_cck_txrx
->r_ccktx_enable
= 0x4;
439 case ANTENNA_AB
: /* For 8192S */
440 set_bb_reg(pAdapter
, rFPGA0_XA_HSSIParameter2
, 0xe, 2);
441 set_bb_reg(pAdapter
, rFPGA0_XB_HSSIParameter2
, 0xe, 2);
442 ofdm_tx_en_val
= 0x3;
443 ofdm_tx_ant_sel_val
= 0x3321333; /* Disable Power save */
444 p_cck_txrx
->r_ccktx_enable
= 0xC;
450 set_bb_reg(pAdapter
, rFPGA1_TxInfo
, 0xffffffff, ofdm_tx_ant_sel_val
);
452 set_bb_reg(pAdapter
, rFPGA0_TxInfo
, 0x0000000f, ofdm_tx_en_val
);
453 switch (pAdapter
->mppriv
.antenna_rx
) {
455 ofdm_rx_ant_sel_val
= 0x1; /* A */
456 p_cck_txrx
->r_cckrx_enable
= 0x0; /* default: A */
457 p_cck_txrx
->r_cckrx_enable_2
= 0x0; /* option: A */
460 ofdm_rx_ant_sel_val
= 0x2; /* B */
461 p_cck_txrx
->r_cckrx_enable
= 0x1; /* default: B */
462 p_cck_txrx
->r_cckrx_enable_2
= 0x1; /* option: B */
465 ofdm_rx_ant_sel_val
= 0x3; /* AB */
466 p_cck_txrx
->r_cckrx_enable
= 0x0; /* default:A */
467 p_cck_txrx
->r_cckrx_enable_2
= 0x1; /* option:B */
473 set_bb_reg(pAdapter
, rOFDM0_TRxPathEnable
, 0x0000000f,
474 ofdm_rx_ant_sel_val
);
476 set_bb_reg(pAdapter
, rOFDM1_TRxPathEnable
, 0x0000000f,
477 ofdm_rx_ant_sel_val
);
479 cck_ant_sel_val
= cck_ant_select_val
;
481 set_bb_reg(pAdapter
, rCCK0_AFESetting
, bMaskByte3
, cck_ant_sel_val
);
484 void r8712_SetCrystalCap(struct _adapter
*pAdapter
)
486 set_bb_reg(pAdapter
, rFPGA0_AnalogParameter1
, bXtalCap
,
487 pAdapter
->mppriv
.curr_crystalcap
);
490 static void TriggerRFThermalMeter(struct _adapter
*pAdapter
)
492 /* 0x24: RF Reg[6:5] */
493 set_rf_reg(pAdapter
, RF_PATH_A
, RF_T_METER
, bRFRegOffsetMask
, 0x60);
496 static u32
ReadRFThermalMeter(struct _adapter
*pAdapter
)
498 u32 ThermalValue
= 0;
500 /* 0x24: RF Reg[4:0] */
501 ThermalValue
= get_rf_reg(pAdapter
, RF_PATH_A
, RF_T_METER
, 0x1F);
505 void r8712_GetThermalMeter(struct _adapter
*pAdapter
, u32
*value
)
507 TriggerRFThermalMeter(pAdapter
);
509 *value
= ReadRFThermalMeter(pAdapter
);
512 void r8712_SetSingleCarrierTx(struct _adapter
*pAdapter
, u8 bStart
)
514 if (bStart
) { /* Start Single Carrier. */
515 /* 1. if OFDM block on? */
516 if (!get_bb_reg(pAdapter
, rFPGA0_RFMOD
, bOFDMEn
))
517 /*set OFDM block on*/
518 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bOFDMEn
, bEnable
);
519 /* 2. set CCK test mode off, set to CCK normal mode */
520 set_bb_reg(pAdapter
, rCCK0_System
, bCCKBBMode
, bDisable
);
521 /* 3. turn on scramble setting */
522 set_bb_reg(pAdapter
, rCCK0_System
, bCCKScramble
, bEnable
);
523 /* 4. Turn On Single Carrier Tx and off the other test modes. */
524 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMContinueTx
, bDisable
);
525 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleCarrier
, bEnable
);
526 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleTone
, bDisable
);
527 } else { /* Stop Single Carrier.*/
528 /* Turn off all test modes.*/
529 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMContinueTx
, bDisable
);
530 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleCarrier
,
532 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleTone
, bDisable
);
535 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x0);
536 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x1);
540 void r8712_SetSingleToneTx(struct _adapter
*pAdapter
, u8 bStart
)
542 u8 rfPath
= pAdapter
->mppriv
.curr_rfpath
;
543 switch (pAdapter
->mppriv
.antenna_tx
) {
552 if (bStart
) { /* Start Single Tone.*/
553 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bCCKEn
, bDisable
);
554 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bOFDMEn
, bDisable
);
555 set_rf_reg(pAdapter
, rfPath
, RF_TX_G2
, bRFRegOffsetMask
,
559 set_rf_reg(pAdapter
, rfPath
, RF_AC
, bRFRegOffsetMask
, 0x2001f);
561 } else { /* Stop Single Tone.*/
562 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bCCKEn
, bEnable
);
563 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bOFDMEn
, bEnable
);
564 set_rf_reg(pAdapter
, rfPath
, RF_TX_G2
, bRFRegOffsetMask
,
568 set_rf_reg(pAdapter
, rfPath
, RF_AC
, bRFRegOffsetMask
, 0x30000);
573 void r8712_SetCarrierSuppressionTx(struct _adapter
*pAdapter
, u8 bStart
)
575 if (bStart
) { /* Start Carrier Suppression.*/
576 if (pAdapter
->mppriv
.curr_rateidx
<= MPT_RATE_11M
) {
577 /* 1. if CCK block on? */
578 if (!get_bb_reg(pAdapter
, rFPGA0_RFMOD
, bCCKEn
)) {
580 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bCCKEn
,
583 /* Turn Off All Test Mode */
584 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMContinueTx
,
586 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleCarrier
,
588 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleTone
,
591 set_bb_reg(pAdapter
, rCCK0_System
, bCCKBBMode
, 0x2);
592 /*turn off scramble setting*/
593 set_bb_reg(pAdapter
, rCCK0_System
, bCCKScramble
,
595 /*Set CCK Tx Test Rate*/
596 /*Set FTxRate to 1Mbps*/
597 set_bb_reg(pAdapter
, rCCK0_System
, bCCKTxRate
, 0x0);
599 } else { /* Stop Carrier Suppression. */
600 if (pAdapter
->mppriv
.curr_rateidx
<= MPT_RATE_11M
) {
602 set_bb_reg(pAdapter
, rCCK0_System
, bCCKBBMode
, 0x0);
603 /*turn on scramble setting*/
604 set_bb_reg(pAdapter
, rCCK0_System
, bCCKScramble
,
607 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x0);
608 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x1);
613 static void SetCCKContinuousTx(struct _adapter
*pAdapter
, u8 bStart
)
618 /* 1. if CCK block on? */
619 if (!get_bb_reg(pAdapter
, rFPGA0_RFMOD
, bCCKEn
)) {
621 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bCCKEn
, bEnable
);
623 /* Turn Off All Test Mode */
624 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMContinueTx
, bDisable
);
625 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleCarrier
, bDisable
);
626 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleTone
, bDisable
);
627 /*Set CCK Tx Test Rate*/
628 cckrate
= pAdapter
->mppriv
.curr_rateidx
;
629 set_bb_reg(pAdapter
, rCCK0_System
, bCCKTxRate
, cckrate
);
631 set_bb_reg(pAdapter
, rCCK0_System
, bCCKBBMode
, 0x2);
632 /*turn on scramble setting*/
633 set_bb_reg(pAdapter
, rCCK0_System
, bCCKScramble
, bEnable
);
636 set_bb_reg(pAdapter
, rCCK0_System
, bCCKBBMode
, 0x0);
637 /*turn on scramble setting*/
638 set_bb_reg(pAdapter
, rCCK0_System
, bCCKScramble
, bEnable
);
640 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x0);
641 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x1);
643 } /* mpt_StartCckContTx */
645 static void SetOFDMContinuousTx(struct _adapter
*pAdapter
, u8 bStart
)
648 /* 1. if OFDM block on? */
649 if (!get_bb_reg(pAdapter
, rFPGA0_RFMOD
, bOFDMEn
)) {
650 /*set OFDM block on*/
651 set_bb_reg(pAdapter
, rFPGA0_RFMOD
, bOFDMEn
, bEnable
);
653 /* 2. set CCK test mode off, set to CCK normal mode*/
654 set_bb_reg(pAdapter
, rCCK0_System
, bCCKBBMode
, bDisable
);
655 /* 3. turn on scramble setting */
656 set_bb_reg(pAdapter
, rCCK0_System
, bCCKScramble
, bEnable
);
657 /* 4. Turn On Continue Tx and turn off the other test modes.*/
658 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMContinueTx
, bEnable
);
659 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleCarrier
, bDisable
);
660 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleTone
, bDisable
);
662 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMContinueTx
, bDisable
);
663 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleCarrier
,
665 set_bb_reg(pAdapter
, rOFDM1_LSTF
, bOFDMSingleTone
, bDisable
);
668 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x0);
669 set_bb_reg(pAdapter
, rPMAC_Reset
, bBBResetB
, 0x1);
671 } /* mpt_StartOfdmContTx */
673 void r8712_SetContinuousTx(struct _adapter
*pAdapter
, u8 bStart
)
675 /* ADC turn off [bit24-21] adc port0 ~ port1 */
677 r8712_bb_reg_write(pAdapter
, rRx_Wait_CCCA
,
678 r8712_bb_reg_read(pAdapter
,
679 rRx_Wait_CCCA
) & 0xFE1FFFFF);
682 if (pAdapter
->mppriv
.curr_rateidx
<= MPT_RATE_11M
)
683 SetCCKContinuousTx(pAdapter
, bStart
);
684 else if ((pAdapter
->mppriv
.curr_rateidx
>= MPT_RATE_6M
) &&
685 (pAdapter
->mppriv
.curr_rateidx
<= MPT_RATE_MCS15
))
686 SetOFDMContinuousTx(pAdapter
, bStart
);
687 /* ADC turn on [bit24-21] adc port0 ~ port1 */
689 r8712_bb_reg_write(pAdapter
, rRx_Wait_CCCA
,
690 r8712_bb_reg_read(pAdapter
,
691 rRx_Wait_CCCA
) | 0x01E00000);
694 void r8712_ResetPhyRxPktCount(struct _adapter
*pAdapter
)
696 u32 i
, phyrx_set
= 0;
698 for (i
= OFDM_PPDU_BIT
; i
<= HT_MPDU_FAIL_BIT
; i
++) {
700 phyrx_set
|= (i
<< 28); /*select*/
701 phyrx_set
|= 0x08000000; /* set counter to zero*/
702 r8712_write32(pAdapter
, RXERR_RPT
, phyrx_set
);
706 static u32
GetPhyRxPktCounts(struct _adapter
*pAdapter
, u32 selbit
)
709 u32 phyrx_set
= 0, count
= 0;
712 SelectBit
= selbit
<< 28;
713 phyrx_set
|= (SelectBit
& 0xF0000000);
714 r8712_write32(pAdapter
, RXERR_RPT
, phyrx_set
);
715 /*Read packet count*/
716 count
= r8712_read32(pAdapter
, RXERR_RPT
) & RPTMaxCount
;
720 u32
r8712_GetPhyRxPktReceived(struct _adapter
*pAdapter
)
722 u32 OFDM_cnt
= 0, CCK_cnt
= 0, HT_cnt
= 0;
724 OFDM_cnt
= GetPhyRxPktCounts(pAdapter
, OFDM_MPDU_OK_BIT
);
725 CCK_cnt
= GetPhyRxPktCounts(pAdapter
, CCK_MPDU_OK_BIT
);
726 HT_cnt
= GetPhyRxPktCounts(pAdapter
, HT_MPDU_OK_BIT
);
727 return OFDM_cnt
+ CCK_cnt
+ HT_cnt
;
730 u32
r8712_GetPhyRxPktCRC32Error(struct _adapter
*pAdapter
)
732 u32 OFDM_cnt
= 0, CCK_cnt
= 0, HT_cnt
= 0;
734 OFDM_cnt
= GetPhyRxPktCounts(pAdapter
, OFDM_MPDU_FAIL_BIT
);
735 CCK_cnt
= GetPhyRxPktCounts(pAdapter
, CCK_MPDU_FAIL_BIT
);
736 HT_cnt
= GetPhyRxPktCounts(pAdapter
, HT_MPDU_FAIL_BIT
);
737 return OFDM_cnt
+ CCK_cnt
+ HT_cnt
;