linux/drivers/staging/r8188eu/hal/usb_halinit.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright(c) 2007 - 2011 Realtek Corporation. */
   3
   4#define _HCI_HAL_INIT_C_
   5
   6#include "../include/osdep_service.h"
   7#include "../include/drv_types.h"
   8#include "../include/rtw_efuse.h"
   9#include "../include/rtw_fw.h"
  10#include "../include/rtl8188e_hal.h"
  11#include "../include/rtw_iol.h"
  12#include "../include/usb_ops.h"
  13#include "../include/usb_osintf.h"
  14#include "../include/Hal8188EPwrSeq.h"
  15
  16static void _ConfigNormalChipOutEP_8188E(struct adapter *adapt, u8 NumOutPipe)
  17{
  18        struct hal_data_8188e *haldata = &adapt->haldata;
  19
  20        switch (NumOutPipe) {
  21        case    3:
  22                haldata->OutEpQueueSel = TX_SELE_HQ | TX_SELE_LQ | TX_SELE_NQ;
  23                haldata->OutEpNumber = 3;
  24                break;
  25        case    2:
  26                haldata->OutEpQueueSel = TX_SELE_HQ | TX_SELE_NQ;
  27                haldata->OutEpNumber = 2;
  28                break;
  29        case    1:
  30                haldata->OutEpQueueSel = TX_SELE_HQ;
  31                haldata->OutEpNumber = 1;
  32                break;
  33        default:
  34                break;
  35        }
  36}
  37
  38static bool HalUsbSetQueuePipeMapping8188EUsb(struct adapter *adapt, u8 NumOutPipe)
  39{
  40
  41        _ConfigNormalChipOutEP_8188E(adapt, NumOutPipe);
  42        return Hal_MappingOutPipe(adapt, NumOutPipe);
  43}
  44
  45void rtl8188eu_interface_configure(struct adapter *adapt)
  46{
  47        struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapt);
  48
  49        HalUsbSetQueuePipeMapping8188EUsb(adapt, pdvobjpriv->RtNumOutPipes);
  50}
  51
  52u32 rtl8188eu_InitPowerOn(struct adapter *adapt)
  53{
  54        u16 value16;
  55        /*  HW Power on sequence */
  56        struct hal_data_8188e *haldata = &adapt->haldata;
  57        if (haldata->bMacPwrCtrlOn)
  58                return _SUCCESS;
  59
  60        if (!HalPwrSeqCmdParsing(adapt, Rtl8188E_NIC_PWR_ON_FLOW))
  61                return _FAIL;
  62
  63        /*  Enable MAC DMA/WMAC/SCHEDULE/SEC block */
  64        /*  Set CR bit10 to enable 32k calibration. Suggested by SD1 Gimmy. Added by tynli. 2011.08.31. */
  65        rtw_write16(adapt, REG_CR, 0x00);  /* suggseted by zhouzhou, by page, 20111230 */
  66
  67                /*  Enable MAC DMA/WMAC/SCHEDULE/SEC block */
  68        value16 = rtw_read16(adapt, REG_CR);
  69        value16 |= (HCI_TXDMA_EN | HCI_RXDMA_EN | TXDMA_EN | RXDMA_EN
  70                                | PROTOCOL_EN | SCHEDULE_EN | ENSEC | CALTMR_EN);
  71        /*  for SDIO - Set CR bit10 to enable 32k calibration. Suggested by SD1 Gimmy. Added by tynli. 2011.08.31. */
  72
  73        rtw_write16(adapt, REG_CR, value16);
  74        haldata->bMacPwrCtrlOn = true;
  75
  76        return _SUCCESS;
  77}
  78
  79/*  Shall USB interface init this? */
  80static void _InitInterrupt(struct adapter *Adapter)
  81{
  82        u32 imr, imr_ex;
  83        u8  usb_opt;
  84
  85        /* HISR write one to clear */
  86        rtw_write32(Adapter, REG_HISR_88E, 0xFFFFFFFF);
  87        /*  HIMR - */
  88        imr = IMR_PSTIMEOUT_88E | IMR_TBDER_88E | IMR_CPWM_88E | IMR_CPWM2_88E;
  89        rtw_write32(Adapter, REG_HIMR_88E, imr);
  90
  91        imr_ex = IMR_TXERR_88E | IMR_RXERR_88E | IMR_TXFOVW_88E | IMR_RXFOVW_88E;
  92        rtw_write32(Adapter, REG_HIMRE_88E, imr_ex);
  93
  94        /*  REG_USB_SPECIAL_OPTION - BIT(4) */
  95        /*  0; Use interrupt endpoint to upload interrupt pkt */
  96        /*  1; Use bulk endpoint to upload interrupt pkt, */
  97        usb_opt = rtw_read8(Adapter, REG_USB_SPECIAL_OPTION);
  98
  99        if (adapter_to_dvobj(Adapter)->pusbdev->speed == USB_SPEED_HIGH)
 100                usb_opt = usb_opt | (INT_BULK_SEL);
 101        else
 102                usb_opt = usb_opt & (~INT_BULK_SEL);
 103
 104        rtw_write8(Adapter, REG_USB_SPECIAL_OPTION, usb_opt);
 105}
 106
 107static void _InitQueueReservedPage(struct adapter *Adapter)
 108{
 109        struct hal_data_8188e *haldata = &Adapter->haldata;
 110        struct registry_priv    *pregistrypriv = &Adapter->registrypriv;
 111        u32 numHQ       = 0;
 112        u32 numLQ       = 0;
 113        u32 numNQ       = 0;
 114        u32 numPubQ;
 115        u32 value32;
 116        u8 value8;
 117        bool bWiFiConfig = pregistrypriv->wifi_spec;
 118
 119        if (bWiFiConfig) {
 120                if (haldata->OutEpQueueSel & TX_SELE_HQ)
 121                        numHQ =  0x29;
 122
 123                if (haldata->OutEpQueueSel & TX_SELE_LQ)
 124                        numLQ = 0x1C;
 125
 126                /*  NOTE: This step shall be proceed before writing REG_RQPN. */
 127                if (haldata->OutEpQueueSel & TX_SELE_NQ)
 128                        numNQ = 0x1C;
 129                value8 = (u8)_NPQ(numNQ);
 130                rtw_write8(Adapter, REG_RQPN_NPQ, value8);
 131
 132                numPubQ = 0xA8 - numHQ - numLQ - numNQ;
 133
 134                /*  TX DMA */
 135                value32 = _HPQ(numHQ) | _LPQ(numLQ) | _PUBQ(numPubQ) | LD_RQPN;
 136                rtw_write32(Adapter, REG_RQPN, value32);
 137        } else {
 138                rtw_write16(Adapter, REG_RQPN_NPQ, 0x0000);/* Just follow MP Team,??? Georgia 03/28 */
 139                rtw_write16(Adapter, REG_RQPN_NPQ, 0x0d);
 140                rtw_write32(Adapter, REG_RQPN, 0x808E000d);/* reserve 7 page for LPS */
 141        }
 142}
 143
 144static void _InitTxBufferBoundary(struct adapter *Adapter, u8 txpktbuf_bndy)
 145{
 146        rtw_write8(Adapter, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
 147        rtw_write8(Adapter, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
 148        rtw_write8(Adapter, REG_TXPKTBUF_WMAC_LBK_BF_HD, txpktbuf_bndy);
 149        rtw_write8(Adapter, REG_TRXFF_BNDY, txpktbuf_bndy);
 150        rtw_write8(Adapter, REG_TDECTRL + 1, txpktbuf_bndy);
 151}
 152
 153static void _InitPageBoundary(struct adapter *Adapter)
 154{
 155        /*  RX Page Boundary */
 156        /*  */
 157        u16 rxff_bndy = MAX_RX_DMA_BUFFER_SIZE_88E - 1;
 158
 159        rtw_write16(Adapter, (REG_TRXFF_BNDY + 2), rxff_bndy);
 160}
 161
 162static void _InitNormalChipRegPriority(struct adapter *Adapter, u16 beQ,
 163                                       u16 bkQ, u16 viQ, u16 voQ, u16 mgtQ,
 164                                       u16 hiQ)
 165{
 166        u16 value16     = (rtw_read16(Adapter, REG_TRXDMA_CTRL) & 0x7);
 167
 168        value16 |= _TXDMA_BEQ_MAP(beQ)  | _TXDMA_BKQ_MAP(bkQ) |
 169                   _TXDMA_VIQ_MAP(viQ)  | _TXDMA_VOQ_MAP(voQ) |
 170                   _TXDMA_MGQ_MAP(mgtQ) | _TXDMA_HIQ_MAP(hiQ);
 171
 172        rtw_write16(Adapter, REG_TRXDMA_CTRL, value16);
 173}
 174
 175static void _InitNormalChipOneOutEpPriority(struct adapter *Adapter)
 176{
 177        struct hal_data_8188e *haldata = &Adapter->haldata;
 178
 179        u16 value = 0;
 180        switch (haldata->OutEpQueueSel) {
 181        case TX_SELE_HQ:
 182                value = QUEUE_HIGH;
 183                break;
 184        case TX_SELE_LQ:
 185                value = QUEUE_LOW;
 186                break;
 187        case TX_SELE_NQ:
 188                value = QUEUE_NORMAL;
 189                break;
 190        default:
 191                break;
 192        }
 193        _InitNormalChipRegPriority(Adapter, value, value, value, value,
 194                                   value, value);
 195}
 196
 197static void _InitNormalChipTwoOutEpPriority(struct adapter *Adapter)
 198{
 199        struct hal_data_8188e *haldata = &Adapter->haldata;
 200        struct registry_priv *pregistrypriv = &Adapter->registrypriv;
 201        u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ;
 202        u16 valueHi = 0;
 203        u16 valueLow = 0;
 204
 205        switch (haldata->OutEpQueueSel) {
 206        case (TX_SELE_HQ | TX_SELE_LQ):
 207                valueHi = QUEUE_HIGH;
 208                valueLow = QUEUE_LOW;
 209                break;
 210        case (TX_SELE_NQ | TX_SELE_LQ):
 211                valueHi = QUEUE_NORMAL;
 212                valueLow = QUEUE_LOW;
 213                break;
 214        case (TX_SELE_HQ | TX_SELE_NQ):
 215                valueHi = QUEUE_HIGH;
 216                valueLow = QUEUE_NORMAL;
 217                break;
 218        default:
 219                break;
 220        }
 221
 222        if (!pregistrypriv->wifi_spec) {
 223                beQ     = valueLow;
 224                bkQ     = valueLow;
 225                viQ     = valueHi;
 226                voQ     = valueHi;
 227                mgtQ    = valueHi;
 228                hiQ     = valueHi;
 229        } else {/* for WMM ,CONFIG_OUT_EP_WIFI_MODE */
 230                beQ     = valueLow;
 231                bkQ     = valueHi;
 232                viQ     = valueHi;
 233                voQ     = valueLow;
 234                mgtQ    = valueHi;
 235                hiQ     = valueHi;
 236        }
 237        _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
 238}
 239
 240static void _InitNormalChipThreeOutEpPriority(struct adapter *Adapter)
 241{
 242        struct registry_priv *pregistrypriv = &Adapter->registrypriv;
 243        u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ;
 244
 245        if (!pregistrypriv->wifi_spec) {/*  typical setting */
 246                beQ     = QUEUE_LOW;
 247                bkQ     = QUEUE_LOW;
 248                viQ     = QUEUE_NORMAL;
 249                voQ     = QUEUE_HIGH;
 250                mgtQ    = QUEUE_HIGH;
 251                hiQ     = QUEUE_HIGH;
 252        } else {/*  for WMM */
 253                beQ     = QUEUE_LOW;
 254                bkQ     = QUEUE_NORMAL;
 255                viQ     = QUEUE_NORMAL;
 256                voQ     = QUEUE_HIGH;
 257                mgtQ    = QUEUE_HIGH;
 258                hiQ     = QUEUE_HIGH;
 259        }
 260        _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
 261}
 262
 263static void _InitQueuePriority(struct adapter *Adapter)
 264{
 265        struct hal_data_8188e *haldata = &Adapter->haldata;
 266
 267        switch (haldata->OutEpNumber) {
 268        case 1:
 269                _InitNormalChipOneOutEpPriority(Adapter);
 270                break;
 271        case 2:
 272                _InitNormalChipTwoOutEpPriority(Adapter);
 273                break;
 274        case 3:
 275                _InitNormalChipThreeOutEpPriority(Adapter);
 276                break;
 277        default:
 278                break;
 279        }
 280}
 281
 282static void _InitNetworkType(struct adapter *Adapter)
 283{
 284        u32 value32;
 285
 286        value32 = rtw_read32(Adapter, REG_CR);
 287        /*  TODO: use the other function to set network type */
 288        value32 = (value32 & ~MASK_NETTYPE) | _NETTYPE(NT_LINK_AP);
 289
 290        rtw_write32(Adapter, REG_CR, value32);
 291}
 292
 293static void _InitTransferPageSize(struct adapter *Adapter)
 294{
 295        /*  Tx page size is always 128. */
 296
 297        u8 value8;
 298        value8 = _PSRX(PBP_128) | _PSTX(PBP_128);
 299        rtw_write8(Adapter, REG_PBP, value8);
 300}
 301
 302static void _InitDriverInfoSize(struct adapter *Adapter, u8 drvInfoSize)
 303{
 304        rtw_write8(Adapter, REG_RX_DRVINFO_SZ, drvInfoSize);
 305}
 306
 307static void _InitWMACSetting(struct adapter *Adapter)
 308{
 309        u32 receive_config = RCR_AAP | RCR_APM | RCR_AM | RCR_AB |
 310                             RCR_CBSSID_DATA | RCR_CBSSID_BCN |
 311                             RCR_APP_ICV | RCR_AMF | RCR_HTC_LOC_CTRL |
 312                             RCR_APP_MIC | RCR_APP_PHYSTS;
 313
 314        /*  some REG_RCR will be modified later by phy_ConfigMACWithHeaderFile() */
 315        rtw_write32(Adapter, REG_RCR, receive_config);
 316
 317        /*  Accept all multicast address */
 318        rtw_write32(Adapter, REG_MAR, 0xFFFFFFFF);
 319        rtw_write32(Adapter, REG_MAR + 4, 0xFFFFFFFF);
 320}
 321
 322static void _InitAdaptiveCtrl(struct adapter *Adapter)
 323{
 324        u16 value16;
 325        u32 value32;
 326
 327        /*  Response Rate Set */
 328        value32 = rtw_read32(Adapter, REG_RRSR);
 329        value32 &= ~RATE_BITMAP_ALL;
 330        value32 |= RATE_RRSR_CCK_ONLY_1M;
 331        rtw_write32(Adapter, REG_RRSR, value32);
 332
 333        /*  CF-END Threshold */
 334
 335        /*  SIFS (used in NAV) */
 336        value16 = _SPEC_SIFS_CCK(0x10) | _SPEC_SIFS_OFDM(0x10);
 337        rtw_write16(Adapter, REG_SPEC_SIFS, value16);
 338
 339        /*  Retry Limit */
 340        value16 = _LRL(0x30) | _SRL(0x30);
 341        rtw_write16(Adapter, REG_RL, value16);
 342}
 343
 344static void _InitEDCA(struct adapter *Adapter)
 345{
 346        /*  Set Spec SIFS (used in NAV) */
 347        rtw_write16(Adapter, REG_SPEC_SIFS, 0x100a);
 348        rtw_write16(Adapter, REG_MAC_SPEC_SIFS, 0x100a);
 349
 350        /*  Set SIFS for CCK */
 351        rtw_write16(Adapter, REG_SIFS_CTX, 0x100a);
 352
 353        /*  Set SIFS for OFDM */
 354        rtw_write16(Adapter, REG_SIFS_TRX, 0x100a);
 355
 356        /*  TXOP */
 357        rtw_write32(Adapter, REG_EDCA_BE_PARAM, 0x005EA42B);
 358        rtw_write32(Adapter, REG_EDCA_BK_PARAM, 0x0000A44F);
 359        rtw_write32(Adapter, REG_EDCA_VI_PARAM, 0x005EA324);
 360        rtw_write32(Adapter, REG_EDCA_VO_PARAM, 0x002FA226);
 361}
 362
 363static void _InitRetryFunction(struct adapter *Adapter)
 364{
 365        u8 value8;
 366
 367        value8 = rtw_read8(Adapter, REG_FWHW_TXQ_CTRL);
 368        value8 |= EN_AMPDU_RTY_NEW;
 369        rtw_write8(Adapter, REG_FWHW_TXQ_CTRL, value8);
 370
 371        /*  Set ACK timeout */
 372        rtw_write8(Adapter, REG_ACKTO, 0x40);
 373}
 374
 375/*-----------------------------------------------------------------------------
 376 * Function:    usb_AggSettingTxUpdate()
 377 *
 378 * Overview:    Separate TX/RX parameters update independent for TP detection and
 379 *                      dynamic TX/RX aggreagtion parameters update.
 380 *
 381 * Input:                       struct adapter *
 382 *
 383 * Output/Return:       NONE
 384 *
 385 * Revised History:
 386 *      When            Who             Remark
 387 *      12/10/2010      MHC             Separate to smaller function.
 388 *
 389 *---------------------------------------------------------------------------*/
 390static void usb_AggSettingTxUpdate(struct adapter *Adapter)
 391{
 392        u32 value32;
 393
 394        if (Adapter->registrypriv.wifi_spec)
 395                return;
 396
 397        value32 = rtw_read32(Adapter, REG_TDECTRL);
 398        value32 = value32 & ~(BLK_DESC_NUM_MASK << BLK_DESC_NUM_SHIFT);
 399        value32 |= ((USB_TXAGG_DESC_NUM & BLK_DESC_NUM_MASK) << BLK_DESC_NUM_SHIFT);
 400
 401        rtw_write32(Adapter, REG_TDECTRL, value32);
 402}
 403
 404/*-----------------------------------------------------------------------------
 405 * Function:    usb_AggSettingRxUpdate()
 406 *
 407 * Overview:    Separate TX/RX parameters update independent for TP detection and
 408 *                      dynamic TX/RX aggreagtion parameters update.
 409 *
 410 * Input:                       struct adapter *
 411 *
 412 * Output/Return:       NONE
 413 *
 414 * Revised History:
 415 *      When            Who             Remark
 416 *      12/10/2010      MHC             Separate to smaller function.
 417 *
 418 *---------------------------------------------------------------------------*/
 419static void
 420usb_AggSettingRxUpdate(
 421                struct adapter *Adapter
 422        )
 423{
 424        u8 valueDMA;
 425        u8 valueUSB;
 426
 427        valueDMA = rtw_read8(Adapter, REG_TRXDMA_CTRL);
 428        valueUSB = rtw_read8(Adapter, REG_USB_SPECIAL_OPTION);
 429
 430        valueDMA |= RXDMA_AGG_EN;
 431        valueUSB &= ~USB_AGG_EN;
 432
 433        rtw_write8(Adapter, REG_TRXDMA_CTRL, valueDMA);
 434        rtw_write8(Adapter, REG_USB_SPECIAL_OPTION, valueUSB);
 435
 436        rtw_write8(Adapter, REG_RXDMA_AGG_PG_TH, USB_RXAGG_PAGE_COUNT);
 437        rtw_write8(Adapter, REG_RXDMA_AGG_PG_TH + 1, USB_RXAGG_PAGE_TIMEOUT);
 438}
 439
 440static void InitUsbAggregationSetting(struct adapter *Adapter)
 441{
 442        /*  Tx aggregation setting */
 443        usb_AggSettingTxUpdate(Adapter);
 444
 445        /*  Rx aggregation setting */
 446        usb_AggSettingRxUpdate(Adapter);
 447}
 448
 449static void _InitBeaconParameters(struct adapter *Adapter)
 450{
 451        struct hal_data_8188e *haldata = &Adapter->haldata;
 452
 453        rtw_write16(Adapter, REG_BCN_CTRL, 0x1010);
 454
 455        /*  TODO: Remove these magic number */
 456        rtw_write16(Adapter, REG_TBTT_PROHIBIT, 0x6404);/*  ms */
 457        rtw_write8(Adapter, REG_DRVERLYINT, DRIVER_EARLY_INT_TIME);/*  5ms */
 458        rtw_write8(Adapter, REG_BCNDMATIM, BCN_DMA_ATIME_INT_TIME); /*  2ms */
 459
 460        /*  Suggested by designer timchen. Change beacon AIFS to the largest number */
 461        /*  beacause test chip does not contension before sending beacon. by tynli. 2009.11.03 */
 462        rtw_write16(Adapter, REG_BCNTCFG, 0x660F);
 463
 464        haldata->RegFwHwTxQCtrl = rtw_read8(Adapter, REG_FWHW_TXQ_CTRL + 2);
 465        haldata->RegReg542 = rtw_read8(Adapter, REG_TBTT_PROHIBIT + 2);
 466        haldata->RegCR_1 = rtw_read8(Adapter, REG_CR + 1);
 467}
 468
 469static void _BeaconFunctionEnable(struct adapter *Adapter,
 470                                  bool Enable, bool Linked)
 471{
 472        rtw_write8(Adapter, REG_BCN_CTRL, (BIT(4) | BIT(3) | BIT(1)));
 473
 474        rtw_write8(Adapter, REG_RD_CTRL + 1, 0x6F);
 475}
 476
 477/*  Set CCK and OFDM Block "ON" */
 478static void _BBTurnOnBlock(struct adapter *Adapter)
 479{
 480        rtl8188e_PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bCCKEn, 0x1);
 481        rtl8188e_PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bOFDMEn, 0x1);
 482}
 483
 484static void _InitAntenna_Selection(struct adapter *Adapter)
 485{
 486        struct hal_data_8188e *haldata = &Adapter->haldata;
 487
 488        if (haldata->AntDivCfg == 0)
 489                return;
 490
 491        rtw_write32(Adapter, REG_LEDCFG0, rtw_read32(Adapter, REG_LEDCFG0) | BIT(23));
 492        rtl8188e_PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, BIT(13), 0x01);
 493
 494        if (rtl8188e_PHY_QueryBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300) == Antenna_A)
 495                haldata->CurAntenna = Antenna_A;
 496        else
 497                haldata->CurAntenna = Antenna_B;
 498}
 499
 500static void hw_var_set_macaddr(struct adapter *Adapter, u8 *val)
 501{
 502        u8 idx = 0;
 503        u32 reg_macid;
 504
 505        reg_macid = REG_MACID;
 506
 507        for (idx = 0; idx < 6; idx++)
 508                rtw_write8(Adapter, (reg_macid + idx), val[idx]);
 509}
 510
 511u32 rtl8188eu_hal_init(struct adapter *Adapter)
 512{
 513        u8 value8 = 0;
 514        u16  value16;
 515        u8 txpktbuf_bndy;
 516        u32 status = _SUCCESS;
 517        struct hal_data_8188e *haldata = &Adapter->haldata;
 518        struct pwrctrl_priv             *pwrctrlpriv = &Adapter->pwrctrlpriv;
 519        struct registry_priv    *pregistrypriv = &Adapter->registrypriv;
 520
 521        if (Adapter->pwrctrlpriv.bkeepfwalive) {
 522                if (haldata->odmpriv.RFCalibrateInfo.bIQKInitialized) {
 523                        PHY_IQCalibrate_8188E(Adapter, true);
 524                } else {
 525                        PHY_IQCalibrate_8188E(Adapter, false);
 526                        haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = true;
 527                }
 528
 529                ODM_TXPowerTrackingCheck(&haldata->odmpriv);
 530                PHY_LCCalibrate_8188E(Adapter);
 531
 532                goto exit;
 533        }
 534
 535        status = rtl8188eu_InitPowerOn(Adapter);
 536        if (status == _FAIL)
 537                goto exit;
 538
 539        /*  Save target channel */
 540        haldata->CurrentChannel = 6;/* default set to 6 */
 541
 542        /*  2010/08/09 MH We need to check if we need to turnon or off RF after detecting */
 543        /*  HW GPIO pin. Before PHY_RFConfig8192C. */
 544        /*  2010/08/26 MH If Efuse does not support sective suspend then disable the function. */
 545
 546        if (!pregistrypriv->wifi_spec) {
 547                txpktbuf_bndy = TX_PAGE_BOUNDARY_88E;
 548        } else {
 549                /*  for WMM */
 550                txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_88E;
 551        }
 552
 553        _InitQueueReservedPage(Adapter);
 554        _InitQueuePriority(Adapter);
 555        _InitPageBoundary(Adapter);
 556        _InitTransferPageSize(Adapter);
 557
 558        _InitTxBufferBoundary(Adapter, 0);
 559
 560        status = rtl8188e_firmware_download(Adapter);
 561
 562        if (status != _SUCCESS) {
 563                Adapter->bFWReady = false;
 564                haldata->fw_ractrl = false;
 565                return status;
 566        } else {
 567                Adapter->bFWReady = true;
 568                haldata->fw_ractrl = false;
 569        }
 570        /* Initialize firmware vars */
 571        Adapter->pwrctrlpriv.bFwCurrentInPSMode = false;
 572        haldata->LastHMEBoxNum = 0;
 573
 574        status = PHY_MACConfig8188E(Adapter);
 575        if (status == _FAIL)
 576                goto exit;
 577
 578        /*  */
 579        /* d. Initialize BB related configurations. */
 580        /*  */
 581        status = PHY_BBConfig8188E(Adapter);
 582        if (status == _FAIL)
 583                goto exit;
 584
 585        status = PHY_RFConfig8188E(Adapter);
 586        if (status == _FAIL)
 587                goto exit;
 588
 589        status = rtl8188e_iol_efuse_patch(Adapter);
 590        if (status == _FAIL)
 591                goto exit;
 592
 593        _InitTxBufferBoundary(Adapter, txpktbuf_bndy);
 594
 595        status =  InitLLTTable(Adapter, txpktbuf_bndy);
 596        if (status == _FAIL)
 597                goto exit;
 598
 599        /*  Get Rx PHY status in order to report RSSI and others. */
 600        _InitDriverInfoSize(Adapter, DRVINFO_SZ);
 601
 602        _InitInterrupt(Adapter);
 603        hw_var_set_macaddr(Adapter, Adapter->eeprompriv.mac_addr);
 604        _InitNetworkType(Adapter);/* set msr */
 605        _InitWMACSetting(Adapter);
 606        _InitAdaptiveCtrl(Adapter);
 607        _InitEDCA(Adapter);
 608        _InitRetryFunction(Adapter);
 609        InitUsbAggregationSetting(Adapter);
 610        _InitBeaconParameters(Adapter);
 611
 612        /*  */
 613        /*  Init CR MACTXEN, MACRXEN after setting RxFF boundary REG_TRXFF_BNDY to patch */
 614        /*  Hw bug which Hw initials RxFF boundary size to a value which is larger than the real Rx buffer size in 88E. */
 615        /*  */
 616        /*  Enable MACTXEN/MACRXEN block */
 617        value16 = rtw_read16(Adapter, REG_CR);
 618        value16 |= (MACTXEN | MACRXEN);
 619        rtw_write8(Adapter, REG_CR, value16);
 620
 621        /* Enable TX Report */
 622        /* Enable Tx Report Timer */
 623        value8 = rtw_read8(Adapter, REG_TX_RPT_CTRL);
 624        rtw_write8(Adapter,  REG_TX_RPT_CTRL, (value8 | BIT(1) | BIT(0)));
 625        /* Set MAX RPT MACID */
 626        rtw_write8(Adapter,  REG_TX_RPT_CTRL + 1, 2);/* FOR sta mode ,0: bc/mc ,1:AP */
 627        /* Tx RPT Timer. Unit: 32us */
 628        rtw_write16(Adapter, REG_TX_RPT_TIME, 0xCdf0);
 629
 630        rtw_write8(Adapter, REG_EARLY_MODE_CONTROL, 0);
 631
 632        rtw_write16(Adapter, REG_PKT_VO_VI_LIFE_TIME, 0x0400);  /*  unit: 256us. 256ms */
 633        rtw_write16(Adapter, REG_PKT_BE_BK_LIFE_TIME, 0x0400);  /*  unit: 256us. 256ms */
 634
 635        /* Keep RfRegChnlVal for later use. */
 636        haldata->RfRegChnlVal = rtl8188e_PHY_QueryRFReg(Adapter, RF_CHNLBW, bRFRegOffsetMask);
 637
 638        _BBTurnOnBlock(Adapter);
 639
 640        invalidate_cam_all(Adapter);
 641
 642        /*  2010/12/17 MH We need to set TX power according to EFUSE content at first. */
 643        PHY_SetTxPowerLevel8188E(Adapter, haldata->CurrentChannel);
 644
 645/*  Move by Neo for USB SS to below setp */
 646/* _RfPowerSave(Adapter); */
 647
 648        _InitAntenna_Selection(Adapter);
 649
 650        /*  */
 651        /*  Disable BAR, suggested by Scott */
 652        /*  2010.04.09 add by hpfan */
 653        /*  */
 654        rtw_write32(Adapter, REG_BAR_MODE_CTRL, 0x0201ffff);
 655
 656        /*  HW SEQ CTRL */
 657        /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */
 658        rtw_write8(Adapter, REG_HWSEQ_CTRL, 0xFF);
 659
 660        if (pregistrypriv->wifi_spec)
 661                rtw_write16(Adapter, REG_FAST_EDCA_CTRL, 0);
 662
 663        /* Nav limit , suggest by scott */
 664        rtw_write8(Adapter, 0x652, 0x0);
 665
 666        rtl8188e_InitHalDm(Adapter);
 667
 668        /*  2010/08/11 MH Merge from 8192SE for Minicard init. We need to confirm current radio status */
 669        /*  and then decide to enable RF or not.!!!??? For Selective suspend mode. We may not */
 670        /*  call initstruct adapter. May cause some problem?? */
 671        /*  Fix the bug that Hw/Sw radio off before S3/S4, the RF off action will not be executed */
 672        /*  in MgntActSet_RF_State() after wake up, because the value of haldata->eRFPowerState */
 673        /*  is the same as eRfOff, we should change it to eRfOn after we config RF parameters. */
 674        /*  Added by tynli. 2010.03.30. */
 675        pwrctrlpriv->rf_pwrstate = rf_on;
 676
 677        /*  enable Tx report. */
 678        rtw_write8(Adapter,  REG_FWHW_TXQ_CTRL + 1, 0x0F);
 679
 680        /*  Suggested by SD1 pisa. Added by tynli. 2011.10.21. */
 681        rtw_write8(Adapter, REG_EARLY_MODE_CONTROL + 3, 0x01);/* Pretx_en, for WEP/TKIP SEC */
 682
 683        /* tynli_test_tx_report. */
 684        rtw_write16(Adapter, REG_TX_RPT_TIME, 0x3DF0);
 685
 686        /* enable tx DMA to drop the redundate data of packet */
 687        rtw_write16(Adapter, REG_TXDMA_OFFSET_CHK, (rtw_read16(Adapter, REG_TXDMA_OFFSET_CHK) | DROP_DATA_EN));
 688
 689        /*  2010/08/26 MH Merge from 8192CE. */
 690        if (pwrctrlpriv->rf_pwrstate == rf_on) {
 691                if (haldata->odmpriv.RFCalibrateInfo.bIQKInitialized) {
 692                        PHY_IQCalibrate_8188E(Adapter, true);
 693                } else {
 694                        PHY_IQCalibrate_8188E(Adapter, false);
 695                        haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = true;
 696                }
 697
 698                ODM_TXPowerTrackingCheck(&haldata->odmpriv);
 699
 700                PHY_LCCalibrate_8188E(Adapter);
 701        }
 702
 703/*      _InitPABias(Adapter); */
 704        rtw_write8(Adapter, REG_USB_HRPWM, 0);
 705
 706        /* ack for xmit mgmt frames. */
 707        rtw_write32(Adapter, REG_FWHW_TXQ_CTRL, rtw_read32(Adapter, REG_FWHW_TXQ_CTRL) | BIT(12));
 708
 709exit:
 710        return status;
 711}
 712
 713static void CardDisableRTL8188EU(struct adapter *Adapter)
 714{
 715        u8 val8;
 716        struct hal_data_8188e *haldata = &Adapter->haldata;
 717
 718        /* Stop Tx Report Timer. 0x4EC[Bit1]=b'0 */
 719        val8 = rtw_read8(Adapter, REG_TX_RPT_CTRL);
 720        rtw_write8(Adapter, REG_TX_RPT_CTRL, val8 & (~BIT(1)));
 721
 722        /*  stop rx */
 723        rtw_write8(Adapter, REG_CR, 0x0);
 724
 725        /*  Run LPS WL RFOFF flow */
 726        HalPwrSeqCmdParsing(Adapter, Rtl8188E_NIC_LPS_ENTER_FLOW);
 727
 728        /*  2. 0x1F[7:0] = 0            turn off RF */
 729
 730        val8 = rtw_read8(Adapter, REG_MCUFWDL);
 731        if ((val8 & RAM_DL_SEL) && Adapter->bFWReady) { /* 8051 RAM code */
 732                /*  Reset MCU 0x2[10]=0. */
 733                val8 = rtw_read8(Adapter, REG_SYS_FUNC_EN + 1);
 734                val8 &= ~BIT(2);        /*  0x2[10], FEN_CPUEN */
 735                rtw_write8(Adapter, REG_SYS_FUNC_EN + 1, val8);
 736        }
 737
 738        /*  reset MCU ready status */
 739        rtw_write8(Adapter, REG_MCUFWDL, 0);
 740
 741        /* YJ,add,111212 */
 742        /* Disable 32k */
 743        val8 = rtw_read8(Adapter, REG_32K_CTRL);
 744        rtw_write8(Adapter, REG_32K_CTRL, val8 & (~BIT(0)));
 745
 746        /*  Card disable power action flow */
 747        HalPwrSeqCmdParsing(Adapter, Rtl8188E_NIC_DISABLE_FLOW);
 748
 749        /*  Reset MCU IO Wrapper */
 750        val8 = rtw_read8(Adapter, REG_RSV_CTRL + 1);
 751        rtw_write8(Adapter, REG_RSV_CTRL + 1, (val8 & (~BIT(3))));
 752        val8 = rtw_read8(Adapter, REG_RSV_CTRL + 1);
 753        rtw_write8(Adapter, REG_RSV_CTRL + 1, val8 | BIT(3));
 754
 755        /* YJ,test add, 111207. For Power Consumption. */
 756        val8 = rtw_read8(Adapter, GPIO_IN);
 757        rtw_write8(Adapter, GPIO_OUT, val8);
 758        rtw_write8(Adapter, GPIO_IO_SEL, 0xFF);/* Reg0x46 */
 759
 760        val8 = rtw_read8(Adapter, REG_GPIO_IO_SEL);
 761        rtw_write8(Adapter, REG_GPIO_IO_SEL, (val8 << 4));
 762        val8 = rtw_read8(Adapter, REG_GPIO_IO_SEL + 1);
 763        rtw_write8(Adapter, REG_GPIO_IO_SEL + 1, val8 | 0x0F);/* Reg0x43 */
 764        rtw_write32(Adapter, REG_BB_PAD_CTRL, 0x00080808);/* set LNA ,TRSW,EX_PA Pin to output mode */
 765        haldata->bMacPwrCtrlOn = false;
 766        Adapter->bFWReady = false;
 767}
 768
 769u32 rtl8188eu_hal_deinit(struct adapter *Adapter)
 770{
 771        rtw_write32(Adapter, REG_HIMR_88E, IMR_DISABLED_88E);
 772        rtw_write32(Adapter, REG_HIMRE_88E, IMR_DISABLED_88E);
 773
 774        if (!Adapter->pwrctrlpriv.bkeepfwalive) {
 775                if (Adapter->hw_init_completed) {
 776                        CardDisableRTL8188EU(Adapter);
 777                }
 778        }
 779        return _SUCCESS;
 780 }
 781
 782unsigned int rtl8188eu_inirp_init(struct adapter *Adapter)
 783{
 784        u8 i;
 785        struct recv_buf *precvbuf;
 786        uint    status;
 787        struct recv_priv *precvpriv = &Adapter->recvpriv;
 788
 789        status = _SUCCESS;
 790
 791        /* issue Rx irp to receive data */
 792        precvbuf = (struct recv_buf *)precvpriv->precv_buf;
 793        for (i = 0; i < NR_RECVBUFF; i++) {
 794                if (!rtw_read_port(Adapter, (unsigned char *)precvbuf)) {
 795                        status = _FAIL;
 796                        goto exit;
 797                }
 798
 799                precvbuf++;
 800                precvpriv->free_recv_buf_queue_cnt--;
 801        }
 802
 803exit:
 804        return status;
 805}
 806
 807/*  */
 808/*  */
 809/*      EEPROM/EFUSE Content Parsing */
 810/*  */
 811/*  */
 812
 813static void Hal_EfuseParseMACAddr_8188EU(struct adapter *adapt, u8 *hwinfo, bool AutoLoadFail)
 814{
 815        u16 i;
 816        u8 sMacAddr[6] = {0x00, 0xE0, 0x4C, 0x81, 0x88, 0x02};
 817        struct eeprom_priv *eeprom = &adapt->eeprompriv;
 818
 819        if (AutoLoadFail) {
 820                for (i = 0; i < 6; i++)
 821                        eeprom->mac_addr[i] = sMacAddr[i];
 822        } else {
 823                /* Read Permanent MAC address */
 824                memcpy(eeprom->mac_addr, &hwinfo[EEPROM_MAC_ADDR_88EU], ETH_ALEN);
 825        }
 826}
 827
 828void ReadAdapterInfo8188EU(struct adapter *Adapter)
 829{
 830        struct eeprom_priv *eeprom = &Adapter->eeprompriv;
 831        struct led_priv *ledpriv = &Adapter->ledpriv;
 832        u8 eeValue;
 833
 834        /* check system boot selection */
 835        eeValue = rtw_read8(Adapter, REG_9346CR);
 836        eeprom->EepromOrEfuse           = (eeValue & BOOT_FROM_EEPROM);
 837        eeprom->bautoload_fail_flag     = !(eeValue & EEPROM_EN);
 838
 839        if (!is_boot_from_eeprom(Adapter))
 840                EFUSE_ShadowMapUpdate(Adapter);
 841
 842        /* parse the eeprom/efuse content */
 843        Hal_EfuseParseIDCode88E(Adapter, eeprom->efuse_eeprom_data);
 844        Hal_EfuseParseMACAddr_8188EU(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 845
 846        Hal_ReadPowerSavingMode88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 847        Hal_ReadTxPowerInfo88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 848        rtl8188e_EfuseParseChnlPlan(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 849        Hal_EfuseParseXtal_8188E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 850        Hal_ReadAntennaDiversity88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 851        Hal_ReadThermalMeter_88E(Adapter, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
 852
 853        ledpriv->bRegUseLed = true;
 854}
 855
 856static void ResumeTxBeacon(struct adapter *adapt)
 857{
 858        struct hal_data_8188e *haldata = &adapt->haldata;
 859
 860        /*  2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
 861        /*  which should be read from register to a global variable. */
 862
 863        rtw_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl) | BIT(6));
 864        haldata->RegFwHwTxQCtrl |= BIT(6);
 865        rtw_write8(adapt, REG_TBTT_PROHIBIT + 1, 0xff);
 866        haldata->RegReg542 |= BIT(0);
 867        rtw_write8(adapt, REG_TBTT_PROHIBIT + 2, haldata->RegReg542);
 868}
 869
 870static void StopTxBeacon(struct adapter *adapt)
 871{
 872        struct hal_data_8188e *haldata = &adapt->haldata;
 873
 874        /*  2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
 875        /*  which should be read from register to a global variable. */
 876
 877        rtw_write8(adapt, REG_FWHW_TXQ_CTRL + 2, (haldata->RegFwHwTxQCtrl) & (~BIT(6)));
 878        haldata->RegFwHwTxQCtrl &= (~BIT(6));
 879        rtw_write8(adapt, REG_TBTT_PROHIBIT + 1, 0x64);
 880        haldata->RegReg542 &= ~(BIT(0));
 881        rtw_write8(adapt, REG_TBTT_PROHIBIT + 2, haldata->RegReg542);
 882
 883         /* todo: CheckFwRsvdPageContent(Adapter);  2010.06.23. Added by tynli. */
 884}
 885
 886static void hw_var_set_opmode(struct adapter *Adapter, u8 *val)
 887{
 888        u8 val8;
 889        u8 mode = *((u8 *)val);
 890
 891        /*  disable Port0 TSF update */
 892        rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL) | BIT(4));
 893
 894        /*  set net_type */
 895        val8 = rtw_read8(Adapter, MSR) & 0x0c;
 896        val8 |= mode;
 897        rtw_write8(Adapter, MSR, val8);
 898
 899        if ((mode == _HW_STATE_STATION_) || (mode == _HW_STATE_NOLINK_)) {
 900                StopTxBeacon(Adapter);
 901
 902                rtw_write8(Adapter, REG_BCN_CTRL, 0x19);/* disable atim wnd */
 903        } else if (mode == _HW_STATE_ADHOC_) {
 904                ResumeTxBeacon(Adapter);
 905                rtw_write8(Adapter, REG_BCN_CTRL, 0x1a);
 906        } else if (mode == _HW_STATE_AP_) {
 907                ResumeTxBeacon(Adapter);
 908
 909                rtw_write8(Adapter, REG_BCN_CTRL, 0x12);
 910
 911                /* Set RCR */
 912                rtw_write32(Adapter, REG_RCR, 0x7000208e);/* CBSSID_DATA must set to 0,reject ICV_ERR packet */
 913                /* enable to rx data frame */
 914                rtw_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
 915                /* enable to rx ps-poll */
 916                rtw_write16(Adapter, REG_RXFLTMAP1, 0x0400);
 917
 918                /* Beacon Control related register for first time */
 919                rtw_write8(Adapter, REG_BCNDMATIM, 0x02); /*  2ms */
 920
 921                rtw_write8(Adapter, REG_ATIMWND, 0x0a); /*  10ms */
 922                rtw_write16(Adapter, REG_BCNTCFG, 0x00);
 923                rtw_write16(Adapter, REG_TBTT_PROHIBIT, 0xff04);
 924                rtw_write16(Adapter, REG_TSFTR_SYN_OFFSET, 0x7fff);/*  +32767 (~32ms) */
 925
 926                /* reset TSF */
 927                rtw_write8(Adapter, REG_DUAL_TSF_RST, BIT(0));
 928
 929                /* BIT(3) - If set 0, hw will clr bcnq when tx becon ok/fail or port 0 */
 930                rtw_write8(Adapter, REG_MBID_NUM, rtw_read8(Adapter, REG_MBID_NUM) | BIT(3) | BIT(4));
 931
 932                /* enable BCN0 Function for if1 */
 933                /* don't enable update TSF0 for if1 (due to TSF update when beacon/probe rsp are received) */
 934                rtw_write8(Adapter, REG_BCN_CTRL, (DIS_TSF_UDT0_NORMAL_CHIP | EN_BCN_FUNCTION | BIT(1)));
 935
 936                /* dis BCN1 ATIM  WND if if2 is station */
 937                rtw_write8(Adapter, REG_BCN_CTRL_1, rtw_read8(Adapter, REG_BCN_CTRL_1) | BIT(0));
 938        }
 939}
 940
 941void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
 942{
 943        struct hal_data_8188e *haldata = &Adapter->haldata;
 944        struct dm_priv  *pdmpriv = &haldata->dmpriv;
 945        struct odm_dm_struct *podmpriv = &haldata->odmpriv;
 946
 947        switch (variable) {
 948        case HW_VAR_SET_OPMODE:
 949                hw_var_set_opmode(Adapter, val);
 950                break;
 951        case HW_VAR_BASIC_RATE:
 952                {
 953                        u16 BrateCfg = 0;
 954                        u8 RateIndex = 0;
 955
 956                        /*  2007.01.16, by Emily */
 957                        /*  Select RRSR (in Legacy-OFDM and CCK) */
 958                        /*  For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, 2M, and 1M from the Basic rate. */
 959                        /*  We do not use other rates. */
 960                        HalSetBrateCfg(Adapter, val, &BrateCfg);
 961
 962                        /* 2011.03.30 add by Luke Lee */
 963                        /* CCK 2M ACK should be disabled for some BCM and Atheros AP IOT */
 964                        /* because CCK 2M has poor TXEVM */
 965                        /* CCK 5.5M & 11M ACK should be enabled for better performance */
 966
 967                        BrateCfg = (BrateCfg | 0xd) & 0x15d;
 968
 969                        BrateCfg |= 0x01; /*  default enable 1M ACK rate */
 970                        /*  Set RRSR rate table. */
 971                        rtw_write8(Adapter, REG_RRSR, BrateCfg & 0xff);
 972                        rtw_write8(Adapter, REG_RRSR + 1, (BrateCfg >> 8) & 0xff);
 973                        rtw_write8(Adapter, REG_RRSR + 2, rtw_read8(Adapter, REG_RRSR + 2) & 0xf0);
 974
 975                        /*  Set RTS initial rate */
 976                        while (BrateCfg > 0x1) {
 977                                BrateCfg = (BrateCfg >> 1);
 978                                RateIndex++;
 979                        }
 980                        /*  Ziv - Check */
 981                        rtw_write8(Adapter, REG_INIRTS_RATE_SEL, RateIndex);
 982                }
 983                break;
 984        case HW_VAR_CORRECT_TSF:
 985                {
 986                        u64     tsf;
 987                        struct mlme_ext_priv    *pmlmeext = &Adapter->mlmeextpriv;
 988                        struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
 989
 990                        tsf = pmlmeext->TSFValue - do_div(pmlmeext->TSFValue,
 991                                                          pmlmeinfo->bcn_interval * 1024) - 1024; /* us */
 992
 993                        if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
 994                                StopTxBeacon(Adapter);
 995
 996                        /* disable related TSF function */
 997                        rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL) & (~BIT(3)));
 998
 999                        rtw_write32(Adapter, REG_TSFTR, tsf);
1000                        rtw_write32(Adapter, REG_TSFTR + 4, tsf >> 32);
1001
1002                        /* enable related TSF function */
1003                        rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL) | BIT(3));
1004
1005                        if (((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE))
1006                                ResumeTxBeacon(Adapter);
1007                }
1008                break;
1009        case HW_VAR_MLME_SITESURVEY:
1010                if (*((u8 *)val)) { /* under sitesurvey */
1011                        /* config RCR to receive different BSSID & not to receive data frame */
1012                        u32 v = rtw_read32(Adapter, REG_RCR);
1013                        v &= ~(RCR_CBSSID_BCN);
1014                        rtw_write32(Adapter, REG_RCR, v);
1015                        /* reject all data frame */
1016                        rtw_write16(Adapter, REG_RXFLTMAP2, 0x00);
1017
1018                        /* disable update TSF */
1019                        rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL) | BIT(4));
1020                } else { /* sitesurvey done */
1021                        struct mlme_ext_priv    *pmlmeext = &Adapter->mlmeextpriv;
1022                        struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
1023
1024                        if ((is_client_associated_to_ap(Adapter)) ||
1025                            ((pmlmeinfo->state & 0x03) == WIFI_FW_ADHOC_STATE)) {
1026                                /* enable to rx data frame */
1027                                rtw_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1028
1029                                /* enable update TSF */
1030                                rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL) & (~BIT(4)));
1031                        } else if ((pmlmeinfo->state & 0x03) == WIFI_FW_AP_STATE) {
1032                                rtw_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1033                                /* enable update TSF */
1034                                rtw_write8(Adapter, REG_BCN_CTRL, rtw_read8(Adapter, REG_BCN_CTRL) & (~BIT(4)));
1035                        }
1036                        rtw_write32(Adapter, REG_RCR, rtw_read32(Adapter, REG_RCR) | RCR_CBSSID_BCN);
1037                }
1038                break;
1039        case HW_VAR_SLOT_TIME:
1040                {
1041                        u8 u1bAIFS, aSifsTime;
1042                        struct mlme_ext_priv    *pmlmeext = &Adapter->mlmeextpriv;
1043                        struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
1044
1045                        rtw_write8(Adapter, REG_SLOT, val[0]);
1046
1047                        if (pmlmeinfo->WMM_enable == 0) {
1048                                if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
1049                                        aSifsTime = 10;
1050                                else
1051                                        aSifsTime = 16;
1052
1053                                u1bAIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
1054
1055                                /*  <Roger_EXP> Temporary removed, 2008.06.20. */
1056                                rtw_write8(Adapter, REG_EDCA_VO_PARAM, u1bAIFS);
1057                                rtw_write8(Adapter, REG_EDCA_VI_PARAM, u1bAIFS);
1058                                rtw_write8(Adapter, REG_EDCA_BE_PARAM, u1bAIFS);
1059                                rtw_write8(Adapter, REG_EDCA_BK_PARAM, u1bAIFS);
1060                        }
1061                }
1062                break;
1063        case HW_VAR_DM_FLAG:
1064                podmpriv->SupportAbility = *((u8 *)val);
1065                break;
1066        case HW_VAR_DM_FUNC_OP:
1067                if (val[0])
1068                        podmpriv->BK_SupportAbility = podmpriv->SupportAbility;
1069                else
1070                        podmpriv->SupportAbility = podmpriv->BK_SupportAbility;
1071                break;
1072        case HW_VAR_DM_FUNC_RESET:
1073                podmpriv->SupportAbility = pdmpriv->InitODMFlag;
1074                break;
1075        case HW_VAR_DM_FUNC_CLR:
1076                podmpriv->SupportAbility = 0;
1077                break;
1078        case HW_VAR_AMPDU_FACTOR:
1079                {
1080                        u8 RegToSet_Normal[4] = {0x41, 0xa8, 0x72, 0xb9};
1081                        u8 FactorToSet;
1082                        u8 *pRegToSet;
1083                        u8 index = 0;
1084
1085                        pRegToSet = RegToSet_Normal; /*  0xb972a841; */
1086                        FactorToSet = *((u8 *)val);
1087                        if (FactorToSet <= 3) {
1088                                FactorToSet = (1 << (FactorToSet + 2));
1089                                if (FactorToSet > 0xf)
1090                                        FactorToSet = 0xf;
1091
1092                                for (index = 0; index < 4; index++) {
1093                                        if ((pRegToSet[index] & 0xf0) > (FactorToSet << 4))
1094                                                pRegToSet[index] = (pRegToSet[index] & 0x0f) | (FactorToSet << 4);
1095
1096                                        if ((pRegToSet[index] & 0x0f) > FactorToSet)
1097                                                pRegToSet[index] = (pRegToSet[index] & 0xf0) | (FactorToSet);
1098
1099                                        rtw_write8(Adapter, (REG_AGGLEN_LMT + index), pRegToSet[index]);
1100                                }
1101                        }
1102                }
1103                break;
1104        case HW_VAR_H2C_MEDIA_STATUS_RPT:
1105                rtl8188e_set_FwMediaStatus_cmd(Adapter, (*(__le16 *)val));
1106                break;
1107        default:
1108                break;
1109        }
1110
1111}
1112
1113void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_level)
1114{
1115        u8 init_rate = 0;
1116        u8 networkType, raid;
1117        u32 mask, rate_bitmap;
1118        u8 shortGIrate = false;
1119        int     supportRateNum = 0;
1120        struct sta_info *psta;
1121        struct hal_data_8188e *haldata = &adapt->haldata;
1122        struct mlme_ext_priv    *pmlmeext = &adapt->mlmeextpriv;
1123        struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
1124        struct wlan_bssid_ex    *cur_network = &pmlmeinfo->network;
1125
1126        if (mac_id >= NUM_STA) /* CAM_SIZE */
1127                return;
1128        psta = pmlmeinfo->FW_sta_info[mac_id].psta;
1129        if (!psta)
1130                return;
1131        switch (mac_id) {
1132        case 0:/*  for infra mode */
1133                supportRateNum = rtw_get_rateset_len(cur_network->SupportedRates);
1134                networkType = judge_network_type(adapt, cur_network->SupportedRates, supportRateNum) & 0xf;
1135                raid = networktype_to_raid(networkType);
1136                mask = update_supported_rate(cur_network->SupportedRates, supportRateNum);
1137                mask |= (pmlmeinfo->HT_enable) ? update_MSC_rate(&pmlmeinfo->HT_caps) : 0;
1138                if (support_short_GI(adapt, &pmlmeinfo->HT_caps))
1139                        shortGIrate = true;
1140                break;
1141        case 1:/* for broadcast/multicast */
1142                supportRateNum = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
1143                if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
1144                        networkType = WIRELESS_11B;
1145                else
1146                        networkType = WIRELESS_11G;
1147                raid = networktype_to_raid(networkType);
1148                mask = update_basic_rate(cur_network->SupportedRates, supportRateNum);
1149                break;
1150        default: /* for each sta in IBSS */
1151                supportRateNum = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
1152                networkType = judge_network_type(adapt, pmlmeinfo->FW_sta_info[mac_id].SupportedRates, supportRateNum) & 0xf;
1153                raid = networktype_to_raid(networkType);
1154                mask = update_supported_rate(cur_network->SupportedRates, supportRateNum);
1155
1156                /* todo: support HT in IBSS */
1157                break;
1158        }
1159
1160        rate_bitmap = 0x0fffffff;
1161        rate_bitmap = ODM_Get_Rate_Bitmap(&haldata->odmpriv, mac_id, mask, rssi_level);
1162
1163        mask &= rate_bitmap;
1164
1165        init_rate = get_highest_rate_idx(mask) & 0x3f;
1166
1167        if (haldata->fw_ractrl) {
1168                mask |= ((raid << 28) & 0xf0000000);
1169                psta->ra_mask = mask;
1170                mask |= ((raid << 28) & 0xf0000000);
1171
1172                /* to do ,for 8188E-SMIC */
1173                rtl8188e_set_raid_cmd(adapt, mask);
1174        } else {
1175                ODM_RA_UpdateRateInfo_8188E(&haldata->odmpriv,
1176                                mac_id,
1177                                raid,
1178                                mask,
1179                                shortGIrate
1180                                );
1181        }
1182        /* set ra_id */
1183        psta->raid = raid;
1184        psta->init_rate = init_rate;
1185}
1186
1187void SetBeaconRelatedRegisters8188EUsb(struct adapter *adapt)
1188{
1189        u32 value32;
1190        struct mlme_ext_priv    *pmlmeext = &adapt->mlmeextpriv;
1191        struct mlme_ext_info    *pmlmeinfo = &pmlmeext->mlmext_info;
1192        u32 bcn_ctrl_reg                        = REG_BCN_CTRL;
1193        /* reset TSF, enable update TSF, correcting TSF On Beacon */
1194
1195        /* BCN interval */
1196        rtw_write16(adapt, REG_BCN_INTERVAL, pmlmeinfo->bcn_interval);
1197        rtw_write8(adapt, REG_ATIMWND, 0x02);/*  2ms */
1198
1199        _InitBeaconParameters(adapt);
1200
1201        rtw_write8(adapt, REG_SLOT, 0x09);
1202
1203        value32 = rtw_read32(adapt, REG_TCR);
1204        value32 &= ~TSFRST;
1205        rtw_write32(adapt,  REG_TCR, value32);
1206
1207        value32 |= TSFRST;
1208        rtw_write32(adapt, REG_TCR, value32);
1209
1210        /*  NOTE: Fix test chip's bug (about contention windows's randomness) */
1211        rtw_write8(adapt,  REG_RXTSF_OFFSET_CCK, 0x50);
1212        rtw_write8(adapt, REG_RXTSF_OFFSET_OFDM, 0x50);
1213
1214        _BeaconFunctionEnable(adapt, true, true);
1215
1216        ResumeTxBeacon(adapt);
1217
1218        rtw_write8(adapt, bcn_ctrl_reg, rtw_read8(adapt, bcn_ctrl_reg) | BIT(1));
1219}
1220
1221void rtl8188eu_init_default_value(struct adapter *adapt)
1222{
1223        struct hal_data_8188e *haldata = &adapt->haldata;
1224        struct pwrctrl_priv *pwrctrlpriv;
1225        u8 i;
1226
1227        pwrctrlpriv = &adapt->pwrctrlpriv;
1228
1229        /* init default value */
1230        haldata->fw_ractrl = false;
1231        if (!pwrctrlpriv->bkeepfwalive)
1232                haldata->LastHMEBoxNum = 0;
1233
1234        /* init dm default value */
1235        haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = false;
1236        haldata->odmpriv.RFCalibrateInfo.TM_Trigger = 0;/* for IQK */
1237        haldata->pwrGroupCnt = 0;
1238        haldata->odmpriv.RFCalibrateInfo.ThermalValue_HP_index = 0;
1239        for (i = 0; i < HP_THERMAL_NUM; i++)
1240                haldata->odmpriv.RFCalibrateInfo.ThermalValue_HP[i] = 0;
1241}
1242