1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #define _HCI_HAL_INIT_C_
22 #include <osdep_service.h>
23 #include <drv_types.h>
24 #include <rtw_efuse.h>
26 #include <rtl8188e_hal.h>
27 #include <rtl8188e_led.h>
31 #define HAL_MAC_ENABLE 1
32 #define HAL_BB_ENABLE 1
33 #define HAL_RF_ENABLE 1
35 static void _ConfigNormalChipOutEP_8188E(struct adapter *adapt, u8 NumOutPipe)
37 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
41 haldata->OutEpQueueSel = TX_SELE_HQ | TX_SELE_LQ | TX_SELE_NQ;
42 haldata->OutEpNumber = 3;
45 haldata->OutEpQueueSel = TX_SELE_HQ | TX_SELE_NQ;
46 haldata->OutEpNumber = 2;
49 haldata->OutEpQueueSel = TX_SELE_HQ;
50 haldata->OutEpNumber = 1;
55 DBG_88E("%s OutEpQueueSel(0x%02x), OutEpNumber(%d)\n", __func__, haldata->OutEpQueueSel, haldata->OutEpNumber);
58 static bool HalUsbSetQueuePipeMapping8188EUsb(struct adapter *adapt, u8 NumInPipe, u8 NumOutPipe)
60 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
63 _ConfigNormalChipOutEP_8188E(adapt, NumOutPipe);
65 /* Normal chip with one IN and one OUT doesn't have interrupt IN EP. */
66 if (1 == haldata->OutEpNumber) {
71 /* All config other than above support one Bulk IN and one Interrupt IN. */
73 result = Hal_MappingOutPipe(adapt, NumOutPipe);
78 static void rtl8188eu_interface_configure(struct adapter *adapt)
80 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
81 struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(adapt);
83 if (pdvobjpriv->ishighspeed)
84 haldata->UsbBulkOutSize = USB_HIGH_SPEED_BULK_SIZE;/* 512 bytes */
86 haldata->UsbBulkOutSize = USB_FULL_SPEED_BULK_SIZE;/* 64 bytes */
88 haldata->interfaceIndex = pdvobjpriv->InterfaceNumber;
90 haldata->UsbTxAggMode = 1;
91 haldata->UsbTxAggDescNum = 0x6; /* only 4 bits */
93 haldata->UsbRxAggMode = USB_RX_AGG_DMA;/* USB_RX_AGG_DMA; */
94 haldata->UsbRxAggBlockCount = 8; /* unit : 512b */
95 haldata->UsbRxAggBlockTimeout = 0x6;
96 haldata->UsbRxAggPageCount = 48; /* uint :128 b 0x0A; 10 = MAX_RX_DMA_BUFFER_SIZE/2/haldata->UsbBulkOutSize */
97 haldata->UsbRxAggPageTimeout = 0x4; /* 6, absolute time = 34ms/(2^6) */
99 HalUsbSetQueuePipeMapping8188EUsb(adapt,
100 pdvobjpriv->RtNumInPipes, pdvobjpriv->RtNumOutPipes);
103 static u32 rtl8188eu_InitPowerOn(struct adapter *adapt)
106 /* HW Power on sequence */
107 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
108 if (haldata->bMacPwrCtrlOn)
111 if (!HalPwrSeqCmdParsing(adapt, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8188E_NIC_PWR_ON_FLOW)) {
112 DBG_88E(KERN_ERR "%s: run power on flow fail\n", __func__);
116 /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */
117 /* Set CR bit10 to enable 32k calibration. Suggested by SD1 Gimmy. Added by tynli. 2011.08.31. */
118 usb_write16(adapt, REG_CR, 0x00); /* suggseted by zhouzhou, by page, 20111230 */
120 /* Enable MAC DMA/WMAC/SCHEDULE/SEC block */
121 value16 = usb_read16(adapt, REG_CR);
122 value16 |= (HCI_TXDMA_EN | HCI_RXDMA_EN | TXDMA_EN | RXDMA_EN
123 | PROTOCOL_EN | SCHEDULE_EN | ENSEC | CALTMR_EN);
124 /* for SDIO - Set CR bit10 to enable 32k calibration. Suggested by SD1 Gimmy. Added by tynli. 2011.08.31. */
126 usb_write16(adapt, REG_CR, value16);
127 haldata->bMacPwrCtrlOn = true;
132 /* Shall USB interface init this? */
133 static void _InitInterrupt(struct adapter *Adapter)
137 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
139 /* HISR write one to clear */
140 usb_write32(Adapter, REG_HISR_88E, 0xFFFFFFFF);
142 imr = IMR_PSTIMEOUT_88E | IMR_TBDER_88E | IMR_CPWM_88E | IMR_CPWM2_88E;
143 usb_write32(Adapter, REG_HIMR_88E, imr);
144 haldata->IntrMask[0] = imr;
146 imr_ex = IMR_TXERR_88E | IMR_RXERR_88E | IMR_TXFOVW_88E | IMR_RXFOVW_88E;
147 usb_write32(Adapter, REG_HIMRE_88E, imr_ex);
148 haldata->IntrMask[1] = imr_ex;
150 /* REG_USB_SPECIAL_OPTION - BIT(4) */
151 /* 0; Use interrupt endpoint to upload interrupt pkt */
152 /* 1; Use bulk endpoint to upload interrupt pkt, */
153 usb_opt = usb_read8(Adapter, REG_USB_SPECIAL_OPTION);
155 if (!adapter_to_dvobj(Adapter)->ishighspeed)
156 usb_opt = usb_opt & (~INT_BULK_SEL);
158 usb_opt = usb_opt | (INT_BULK_SEL);
160 usb_write8(Adapter, REG_USB_SPECIAL_OPTION, usb_opt);
163 static void _InitQueueReservedPage(struct adapter *Adapter)
165 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
166 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
173 bool bWiFiConfig = pregistrypriv->wifi_spec;
176 if (haldata->OutEpQueueSel & TX_SELE_HQ)
179 if (haldata->OutEpQueueSel & TX_SELE_LQ)
182 /* NOTE: This step shall be proceed before writting REG_RQPN. */
183 if (haldata->OutEpQueueSel & TX_SELE_NQ)
185 value8 = (u8)_NPQ(numNQ);
186 usb_write8(Adapter, REG_RQPN_NPQ, value8);
188 numPubQ = 0xA8 - numHQ - numLQ - numNQ;
191 value32 = _HPQ(numHQ) | _LPQ(numLQ) | _PUBQ(numPubQ) | LD_RQPN;
192 usb_write32(Adapter, REG_RQPN, value32);
194 usb_write16(Adapter, REG_RQPN_NPQ, 0x0000);/* Just follow MP Team,??? Georgia 03/28 */
195 usb_write16(Adapter, REG_RQPN_NPQ, 0x0d);
196 usb_write32(Adapter, REG_RQPN, 0x808E000d);/* reserve 7 page for LPS */
200 static void _InitTxBufferBoundary(struct adapter *Adapter, u8 txpktbuf_bndy)
202 usb_write8(Adapter, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy);
203 usb_write8(Adapter, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy);
204 usb_write8(Adapter, REG_TXPKTBUF_WMAC_LBK_BF_HD, txpktbuf_bndy);
205 usb_write8(Adapter, REG_TRXFF_BNDY, txpktbuf_bndy);
206 usb_write8(Adapter, REG_TDECTRL+1, txpktbuf_bndy);
209 static void _InitPageBoundary(struct adapter *Adapter)
211 /* RX Page Boundary */
213 u16 rxff_bndy = MAX_RX_DMA_BUFFER_SIZE_88E-1;
215 usb_write16(Adapter, (REG_TRXFF_BNDY + 2), rxff_bndy);
218 static void _InitNormalChipRegPriority(struct adapter *Adapter, u16 beQ,
219 u16 bkQ, u16 viQ, u16 voQ, u16 mgtQ,
222 u16 value16 = (usb_read16(Adapter, REG_TRXDMA_CTRL) & 0x7);
224 value16 |= _TXDMA_BEQ_MAP(beQ) | _TXDMA_BKQ_MAP(bkQ) |
225 _TXDMA_VIQ_MAP(viQ) | _TXDMA_VOQ_MAP(voQ) |
226 _TXDMA_MGQ_MAP(mgtQ) | _TXDMA_HIQ_MAP(hiQ);
228 usb_write16(Adapter, REG_TRXDMA_CTRL, value16);
231 static void _InitNormalChipOneOutEpPriority(struct adapter *Adapter)
233 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
236 switch (haldata->OutEpQueueSel) {
244 value = QUEUE_NORMAL;
249 _InitNormalChipRegPriority(Adapter, value, value, value, value,
253 static void _InitNormalChipTwoOutEpPriority(struct adapter *Adapter)
255 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
256 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
257 u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ;
261 switch (haldata->OutEpQueueSel) {
262 case (TX_SELE_HQ | TX_SELE_LQ):
263 valueHi = QUEUE_HIGH;
264 valueLow = QUEUE_LOW;
266 case (TX_SELE_NQ | TX_SELE_LQ):
267 valueHi = QUEUE_NORMAL;
268 valueLow = QUEUE_LOW;
270 case (TX_SELE_HQ | TX_SELE_NQ):
271 valueHi = QUEUE_HIGH;
272 valueLow = QUEUE_NORMAL;
278 if (!pregistrypriv->wifi_spec) {
285 } else {/* for WMM ,CONFIG_OUT_EP_WIFI_MODE */
293 _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
296 static void _InitNormalChipThreeOutEpPriority(struct adapter *Adapter)
298 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
299 u16 beQ, bkQ, viQ, voQ, mgtQ, hiQ;
301 if (!pregistrypriv->wifi_spec) {/* typical setting */
308 } else {/* for WMM */
316 _InitNormalChipRegPriority(Adapter, beQ, bkQ, viQ, voQ, mgtQ, hiQ);
319 static void _InitQueuePriority(struct adapter *Adapter)
321 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
323 switch (haldata->OutEpNumber) {
325 _InitNormalChipOneOutEpPriority(Adapter);
328 _InitNormalChipTwoOutEpPriority(Adapter);
331 _InitNormalChipThreeOutEpPriority(Adapter);
338 static void _InitNetworkType(struct adapter *Adapter)
342 value32 = usb_read32(Adapter, REG_CR);
343 /* TODO: use the other function to set network type */
344 value32 = (value32 & ~MASK_NETTYPE) | _NETTYPE(NT_LINK_AP);
346 usb_write32(Adapter, REG_CR, value32);
349 static void _InitTransferPageSize(struct adapter *Adapter)
351 /* Tx page size is always 128. */
354 value8 = _PSRX(PBP_128) | _PSTX(PBP_128);
355 usb_write8(Adapter, REG_PBP, value8);
358 static void _InitDriverInfoSize(struct adapter *Adapter, u8 drvInfoSize)
360 usb_write8(Adapter, REG_RX_DRVINFO_SZ, drvInfoSize);
363 static void _InitWMACSetting(struct adapter *Adapter)
365 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
367 haldata->ReceiveConfig = RCR_AAP | RCR_APM | RCR_AM | RCR_AB |
368 RCR_CBSSID_DATA | RCR_CBSSID_BCN |
369 RCR_APP_ICV | RCR_AMF | RCR_HTC_LOC_CTRL |
370 RCR_APP_MIC | RCR_APP_PHYSTS;
372 /* some REG_RCR will be modified later by phy_ConfigMACWithHeaderFile() */
373 usb_write32(Adapter, REG_RCR, haldata->ReceiveConfig);
375 /* Accept all multicast address */
376 usb_write32(Adapter, REG_MAR, 0xFFFFFFFF);
377 usb_write32(Adapter, REG_MAR + 4, 0xFFFFFFFF);
380 static void _InitAdaptiveCtrl(struct adapter *Adapter)
385 /* Response Rate Set */
386 value32 = usb_read32(Adapter, REG_RRSR);
387 value32 &= ~RATE_BITMAP_ALL;
388 value32 |= RATE_RRSR_CCK_ONLY_1M;
389 usb_write32(Adapter, REG_RRSR, value32);
391 /* CF-END Threshold */
393 /* SIFS (used in NAV) */
394 value16 = _SPEC_SIFS_CCK(0x10) | _SPEC_SIFS_OFDM(0x10);
395 usb_write16(Adapter, REG_SPEC_SIFS, value16);
398 value16 = _LRL(0x30) | _SRL(0x30);
399 usb_write16(Adapter, REG_RL, value16);
402 static void _InitEDCA(struct adapter *Adapter)
404 /* Set Spec SIFS (used in NAV) */
405 usb_write16(Adapter, REG_SPEC_SIFS, 0x100a);
406 usb_write16(Adapter, REG_MAC_SPEC_SIFS, 0x100a);
408 /* Set SIFS for CCK */
409 usb_write16(Adapter, REG_SIFS_CTX, 0x100a);
411 /* Set SIFS for OFDM */
412 usb_write16(Adapter, REG_SIFS_TRX, 0x100a);
415 usb_write32(Adapter, REG_EDCA_BE_PARAM, 0x005EA42B);
416 usb_write32(Adapter, REG_EDCA_BK_PARAM, 0x0000A44F);
417 usb_write32(Adapter, REG_EDCA_VI_PARAM, 0x005EA324);
418 usb_write32(Adapter, REG_EDCA_VO_PARAM, 0x002FA226);
421 static void _InitRDGSetting(struct adapter *Adapter)
423 usb_write8(Adapter, REG_RD_CTRL, 0xFF);
424 usb_write16(Adapter, REG_RD_NAV_NXT, 0x200);
425 usb_write8(Adapter, REG_RD_RESP_PKT_TH, 0x05);
428 static void _InitRxSetting(struct adapter *Adapter)
430 usb_write32(Adapter, REG_MACID, 0x87654321);
431 usb_write32(Adapter, 0x0700, 0x87654321);
434 static void _InitRetryFunction(struct adapter *Adapter)
438 value8 = usb_read8(Adapter, REG_FWHW_TXQ_CTRL);
439 value8 |= EN_AMPDU_RTY_NEW;
440 usb_write8(Adapter, REG_FWHW_TXQ_CTRL, value8);
442 /* Set ACK timeout */
443 usb_write8(Adapter, REG_ACKTO, 0x40);
446 /*-----------------------------------------------------------------------------
447 * Function: usb_AggSettingTxUpdate()
449 * Overview: Separate TX/RX parameters update independent for TP detection and
450 * dynamic TX/RX aggreagtion parameters update.
452 * Input: struct adapter *
454 * Output/Return: NONE
458 * 12/10/2010 MHC Separate to smaller function.
460 *---------------------------------------------------------------------------*/
461 static void usb_AggSettingTxUpdate(struct adapter *Adapter)
463 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
466 if (Adapter->registrypriv.wifi_spec)
467 haldata->UsbTxAggMode = false;
469 if (haldata->UsbTxAggMode) {
470 value32 = usb_read32(Adapter, REG_TDECTRL);
471 value32 = value32 & ~(BLK_DESC_NUM_MASK << BLK_DESC_NUM_SHIFT);
472 value32 |= ((haldata->UsbTxAggDescNum & BLK_DESC_NUM_MASK) << BLK_DESC_NUM_SHIFT);
474 usb_write32(Adapter, REG_TDECTRL, value32);
476 } /* usb_AggSettingTxUpdate */
478 /*-----------------------------------------------------------------------------
479 * Function: usb_AggSettingRxUpdate()
481 * Overview: Separate TX/RX parameters update independent for TP detection and
482 * dynamic TX/RX aggreagtion parameters update.
484 * Input: struct adapter *
486 * Output/Return: NONE
490 * 12/10/2010 MHC Separate to smaller function.
492 *---------------------------------------------------------------------------*/
494 usb_AggSettingRxUpdate(
495 struct adapter *Adapter
498 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
502 valueDMA = usb_read8(Adapter, REG_TRXDMA_CTRL);
503 valueUSB = usb_read8(Adapter, REG_USB_SPECIAL_OPTION);
505 switch (haldata->UsbRxAggMode) {
507 valueDMA |= RXDMA_AGG_EN;
508 valueUSB &= ~USB_AGG_EN;
511 valueDMA &= ~RXDMA_AGG_EN;
512 valueUSB |= USB_AGG_EN;
515 valueDMA |= RXDMA_AGG_EN;
516 valueUSB |= USB_AGG_EN;
518 case USB_RX_AGG_DISABLE:
520 valueDMA &= ~RXDMA_AGG_EN;
521 valueUSB &= ~USB_AGG_EN;
525 usb_write8(Adapter, REG_TRXDMA_CTRL, valueDMA);
526 usb_write8(Adapter, REG_USB_SPECIAL_OPTION, valueUSB);
528 switch (haldata->UsbRxAggMode) {
530 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH, haldata->UsbRxAggPageCount);
531 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH+1, haldata->UsbRxAggPageTimeout);
534 usb_write8(Adapter, REG_USB_AGG_TH, haldata->UsbRxAggBlockCount);
535 usb_write8(Adapter, REG_USB_AGG_TO, haldata->UsbRxAggBlockTimeout);
538 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH, haldata->UsbRxAggPageCount);
539 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH+1, (haldata->UsbRxAggPageTimeout & 0x1F));/* 0x280[12:8] */
540 usb_write8(Adapter, REG_USB_AGG_TH, haldata->UsbRxAggBlockCount);
541 usb_write8(Adapter, REG_USB_AGG_TO, haldata->UsbRxAggBlockTimeout);
543 case USB_RX_AGG_DISABLE:
551 haldata->HwRxPageSize = 128;
554 haldata->HwRxPageSize = 64;
557 haldata->HwRxPageSize = 256;
560 haldata->HwRxPageSize = 512;
563 haldata->HwRxPageSize = 1024;
568 } /* usb_AggSettingRxUpdate */
570 static void InitUsbAggregationSetting(struct adapter *Adapter)
572 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
574 /* Tx aggregation setting */
575 usb_AggSettingTxUpdate(Adapter);
577 /* Rx aggregation setting */
578 usb_AggSettingRxUpdate(Adapter);
580 /* 201/12/10 MH Add for USB agg mode dynamic switch. */
581 haldata->UsbRxHighSpeedMode = false;
584 static void _InitBeaconParameters(struct adapter *Adapter)
586 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
588 usb_write16(Adapter, REG_BCN_CTRL, 0x1010);
590 /* TODO: Remove these magic number */
591 usb_write16(Adapter, REG_TBTT_PROHIBIT, 0x6404);/* ms */
592 usb_write8(Adapter, REG_DRVERLYINT, DRIVER_EARLY_INT_TIME);/* 5ms */
593 usb_write8(Adapter, REG_BCNDMATIM, BCN_DMA_ATIME_INT_TIME); /* 2ms */
595 /* Suggested by designer timchen. Change beacon AIFS to the largest number */
596 /* beacause test chip does not contension before sending beacon. by tynli. 2009.11.03 */
597 usb_write16(Adapter, REG_BCNTCFG, 0x660F);
599 haldata->RegBcnCtrlVal = usb_read8(Adapter, REG_BCN_CTRL);
600 haldata->RegTxPause = usb_read8(Adapter, REG_TXPAUSE);
601 haldata->RegFwHwTxQCtrl = usb_read8(Adapter, REG_FWHW_TXQ_CTRL+2);
602 haldata->RegReg542 = usb_read8(Adapter, REG_TBTT_PROHIBIT+2);
603 haldata->RegCR_1 = usb_read8(Adapter, REG_CR+1);
606 static void _BeaconFunctionEnable(struct adapter *Adapter,
607 bool Enable, bool Linked)
609 usb_write8(Adapter, REG_BCN_CTRL, (BIT4 | BIT3 | BIT1));
611 usb_write8(Adapter, REG_RD_CTRL+1, 0x6F);
614 /* Set CCK and OFDM Block "ON" */
615 static void _BBTurnOnBlock(struct adapter *Adapter)
617 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bCCKEn, 0x1);
618 PHY_SetBBReg(Adapter, rFPGA0_RFMOD, bOFDMEn, 0x1);
626 static void _InitAntenna_Selection(struct adapter *Adapter)
628 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
630 if (haldata->AntDivCfg == 0)
632 DBG_88E("==> %s ....\n", __func__);
634 usb_write32(Adapter, REG_LEDCFG0, usb_read32(Adapter, REG_LEDCFG0)|BIT23);
635 PHY_SetBBReg(Adapter, rFPGA0_XAB_RFParameter, BIT13, 0x01);
637 if (PHY_QueryBBReg(Adapter, rFPGA0_XA_RFInterfaceOE, 0x300) == Antenna_A)
638 haldata->CurAntenna = Antenna_A;
640 haldata->CurAntenna = Antenna_B;
641 DBG_88E("%s,Cur_ant:(%x)%s\n", __func__, haldata->CurAntenna, (haldata->CurAntenna == Antenna_A) ? "Antenna_A" : "Antenna_B");
644 /*-----------------------------------------------------------------------------
645 * Function: HwSuspendModeEnable92Cu()
647 * Overview: HW suspend mode switch.
657 * 08/23/2010 MHC HW suspend mode switch test..
658 *---------------------------------------------------------------------------*/
659 enum rt_rf_power_state RfOnOffDetect(struct adapter *adapt)
662 enum rt_rf_power_state rfpowerstate = rf_off;
664 if (adapt->pwrctrlpriv.bHWPowerdown) {
665 val8 = usb_read8(adapt, REG_HSISR);
666 DBG_88E("pwrdown, 0x5c(BIT7)=%02x\n", val8);
667 rfpowerstate = (val8 & BIT7) ? rf_off : rf_on;
668 } else { /* rf on/off */
669 usb_write8(adapt, REG_MAC_PINMUX_CFG, usb_read8(adapt, REG_MAC_PINMUX_CFG)&~(BIT3));
670 val8 = usb_read8(adapt, REG_GPIO_IO_SEL);
671 DBG_88E("GPIO_IN=%02x\n", val8);
672 rfpowerstate = (val8 & BIT3) ? rf_on : rf_off;
675 } /* HalDetectPwrDownMode */
677 static u32 rtl8188eu_hal_init(struct adapter *Adapter)
682 u32 status = _SUCCESS;
683 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
684 struct pwrctrl_priv *pwrctrlpriv = &Adapter->pwrctrlpriv;
685 struct registry_priv *pregistrypriv = &Adapter->registrypriv;
686 u32 init_start_time = jiffies;
688 #define HAL_INIT_PROFILE_TAG(stage) do {} while (0)
691 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_BEGIN);
693 if (Adapter->pwrctrlpriv.bkeepfwalive) {
695 if (haldata->odmpriv.RFCalibrateInfo.bIQKInitialized) {
696 PHY_IQCalibrate_8188E(Adapter, true);
698 PHY_IQCalibrate_8188E(Adapter, false);
699 haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = true;
702 ODM_TXPowerTrackingCheck(&haldata->odmpriv);
703 PHY_LCCalibrate_8188E(Adapter);
708 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_PW_ON);
709 status = rtl8188eu_InitPowerOn(Adapter);
710 if (status == _FAIL) {
711 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, ("Failed to init power on!\n"));
715 /* Save target channel */
716 haldata->CurrentChannel = 6;/* default set to 6 */
718 if (pwrctrlpriv->reg_rfoff) {
719 pwrctrlpriv->rf_pwrstate = rf_off;
722 /* 2010/08/09 MH We need to check if we need to turnon or off RF after detecting */
723 /* HW GPIO pin. Before PHY_RFConfig8192C. */
724 /* 2010/08/26 MH If Efuse does not support sective suspend then disable the function. */
726 if (!pregistrypriv->wifi_spec) {
727 txpktbuf_bndy = TX_PAGE_BOUNDARY_88E;
730 txpktbuf_bndy = WMM_NORMAL_TX_PAGE_BOUNDARY_88E;
733 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC01);
734 _InitQueueReservedPage(Adapter);
735 _InitQueuePriority(Adapter);
736 _InitPageBoundary(Adapter);
737 _InitTransferPageSize(Adapter);
739 _InitTxBufferBoundary(Adapter, 0);
741 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_DOWNLOAD_FW);
742 if (Adapter->registrypriv.mp_mode == 1) {
743 _InitRxSetting(Adapter);
744 Adapter->bFWReady = false;
745 haldata->fw_ractrl = false;
747 status = rtl8188e_FirmwareDownload(Adapter);
749 if (status != _SUCCESS) {
750 DBG_88E("%s: Download Firmware failed!!\n", __func__);
751 Adapter->bFWReady = false;
752 haldata->fw_ractrl = false;
755 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("Initializeadapt8192CSdio(): Download Firmware Success!!\n"));
756 Adapter->bFWReady = true;
757 haldata->fw_ractrl = false;
760 rtl8188e_InitializeFirmwareVars(Adapter);
762 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MAC);
763 #if (HAL_MAC_ENABLE == 1)
764 status = PHY_MACConfig8188E(Adapter);
765 if (status == _FAIL) {
766 DBG_88E(" ### Failed to init MAC ......\n ");
772 /* d. Initialize BB related configurations. */
774 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_BB);
775 #if (HAL_BB_ENABLE == 1)
776 status = PHY_BBConfig8188E(Adapter);
777 if (status == _FAIL) {
778 DBG_88E(" ### Failed to init BB ......\n ");
783 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_RF);
784 #if (HAL_RF_ENABLE == 1)
785 status = PHY_RFConfig8188E(Adapter);
786 if (status == _FAIL) {
787 DBG_88E(" ### Failed to init RF ......\n ");
792 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_EFUSE_PATCH);
793 status = rtl8188e_iol_efuse_patch(Adapter);
794 if (status == _FAIL) {
795 DBG_88E("%s rtl8188e_iol_efuse_patch failed\n", __func__);
799 _InitTxBufferBoundary(Adapter, txpktbuf_bndy);
801 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_LLTT);
802 status = InitLLTTable(Adapter, txpktbuf_bndy);
803 if (status == _FAIL) {
804 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, ("Failed to init LLT table\n"));
808 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC02);
809 /* Get Rx PHY status in order to report RSSI and others. */
810 _InitDriverInfoSize(Adapter, DRVINFO_SZ);
812 _InitInterrupt(Adapter);
813 hal_init_macaddr(Adapter);/* set mac_address */
814 _InitNetworkType(Adapter);/* set msr */
815 _InitWMACSetting(Adapter);
816 _InitAdaptiveCtrl(Adapter);
818 _InitRetryFunction(Adapter);
819 InitUsbAggregationSetting(Adapter);
820 _InitBeaconParameters(Adapter);
821 /* Init CR MACTXEN, MACRXEN after setting RxFF boundary REG_TRXFF_BNDY to patch */
822 /* Hw bug which Hw initials RxFF boundary size to a value which is larger than the real Rx buffer size in 88E. */
823 /* Enable MACTXEN/MACRXEN block */
824 value16 = usb_read16(Adapter, REG_CR);
825 value16 |= (MACTXEN | MACRXEN);
826 usb_write8(Adapter, REG_CR, value16);
828 if (haldata->bRDGEnable)
829 _InitRDGSetting(Adapter);
831 /* Enable TX Report */
832 /* Enable Tx Report Timer */
833 value8 = usb_read8(Adapter, REG_TX_RPT_CTRL);
834 usb_write8(Adapter, REG_TX_RPT_CTRL, (value8|BIT1|BIT0));
835 /* Set MAX RPT MACID */
836 usb_write8(Adapter, REG_TX_RPT_CTRL+1, 2);/* FOR sta mode ,0: bc/mc ,1:AP */
837 /* Tx RPT Timer. Unit: 32us */
838 usb_write16(Adapter, REG_TX_RPT_TIME, 0xCdf0);
840 usb_write8(Adapter, REG_EARLY_MODE_CONTROL, 0);
842 usb_write16(Adapter, REG_PKT_VO_VI_LIFE_TIME, 0x0400); /* unit: 256us. 256ms */
843 usb_write16(Adapter, REG_PKT_BE_BK_LIFE_TIME, 0x0400); /* unit: 256us. 256ms */
845 /* Keep RfRegChnlVal for later use. */
846 haldata->RfRegChnlVal[0] = PHY_QueryRFReg(Adapter, (enum rf_radio_path)0, RF_CHNLBW, bRFRegOffsetMask);
847 haldata->RfRegChnlVal[1] = PHY_QueryRFReg(Adapter, (enum rf_radio_path)1, RF_CHNLBW, bRFRegOffsetMask);
849 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_TURN_ON_BLOCK);
850 _BBTurnOnBlock(Adapter);
852 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_SECURITY);
853 invalidate_cam_all(Adapter);
855 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_MISC11);
856 /* 2010/12/17 MH We need to set TX power according to EFUSE content at first. */
857 PHY_SetTxPowerLevel8188E(Adapter, haldata->CurrentChannel);
859 /* Move by Neo for USB SS to below setp */
860 /* _RfPowerSave(Adapter); */
862 _InitAntenna_Selection(Adapter);
865 /* Disable BAR, suggested by Scott */
866 /* 2010.04.09 add by hpfan */
868 usb_write32(Adapter, REG_BAR_MODE_CTRL, 0x0201ffff);
871 /* set 0x0 to 0xFF by tynli. Default enable HW SEQ NUM. */
872 usb_write8(Adapter, REG_HWSEQ_CTRL, 0xFF);
874 if (pregistrypriv->wifi_spec)
875 usb_write16(Adapter, REG_FAST_EDCA_CTRL, 0);
877 /* Nav limit , suggest by scott */
878 usb_write8(Adapter, 0x652, 0x0);
880 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_HAL_DM);
881 rtl8188e_InitHalDm(Adapter);
883 /* 2010/08/11 MH Merge from 8192SE for Minicard init. We need to confirm current radio status */
884 /* and then decide to enable RF or not.!!!??? For Selective suspend mode. We may not */
885 /* call initstruct adapter. May cause some problem?? */
886 /* Fix the bug that Hw/Sw radio off before S3/S4, the RF off action will not be executed */
887 /* in MgntActSet_RF_State() after wake up, because the value of haldata->eRFPowerState */
888 /* is the same as eRfOff, we should change it to eRfOn after we config RF parameters. */
889 /* Added by tynli. 2010.03.30. */
890 pwrctrlpriv->rf_pwrstate = rf_on;
892 /* enable Tx report. */
893 usb_write8(Adapter, REG_FWHW_TXQ_CTRL+1, 0x0F);
895 /* Suggested by SD1 pisa. Added by tynli. 2011.10.21. */
896 usb_write8(Adapter, REG_EARLY_MODE_CONTROL+3, 0x01);/* Pretx_en, for WEP/TKIP SEC */
898 /* tynli_test_tx_report. */
899 usb_write16(Adapter, REG_TX_RPT_TIME, 0x3DF0);
901 /* enable tx DMA to drop the redundate data of packet */
902 usb_write16(Adapter, REG_TXDMA_OFFSET_CHK, (usb_read16(Adapter, REG_TXDMA_OFFSET_CHK) | DROP_DATA_EN));
904 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_IQK);
905 /* 2010/08/26 MH Merge from 8192CE. */
906 if (pwrctrlpriv->rf_pwrstate == rf_on) {
907 if (haldata->odmpriv.RFCalibrateInfo.bIQKInitialized) {
908 PHY_IQCalibrate_8188E(Adapter, true);
910 PHY_IQCalibrate_8188E(Adapter, false);
911 haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = true;
914 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_PW_TRACK);
916 ODM_TXPowerTrackingCheck(&haldata->odmpriv);
918 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_LCK);
919 PHY_LCCalibrate_8188E(Adapter);
922 /* HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_INIT_PABIAS); */
923 /* _InitPABias(Adapter); */
924 usb_write8(Adapter, REG_USB_HRPWM, 0);
926 /* ack for xmit mgmt frames. */
927 usb_write32(Adapter, REG_FWHW_TXQ_CTRL, usb_read32(Adapter, REG_FWHW_TXQ_CTRL)|BIT(12));
930 HAL_INIT_PROFILE_TAG(HAL_INIT_STAGES_END);
932 DBG_88E("%s in %dms\n", __func__, rtw_get_passing_time_ms(init_start_time));
938 static void CardDisableRTL8188EU(struct adapter *Adapter)
941 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
943 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("CardDisableRTL8188EU\n"));
945 /* Stop Tx Report Timer. 0x4EC[Bit1]=b'0 */
946 val8 = usb_read8(Adapter, REG_TX_RPT_CTRL);
947 usb_write8(Adapter, REG_TX_RPT_CTRL, val8&(~BIT1));
950 usb_write8(Adapter, REG_CR, 0x0);
952 /* Run LPS WL RFOFF flow */
953 HalPwrSeqCmdParsing(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8188E_NIC_LPS_ENTER_FLOW);
955 /* 2. 0x1F[7:0] = 0 turn off RF */
957 val8 = usb_read8(Adapter, REG_MCUFWDL);
958 if ((val8 & RAM_DL_SEL) && Adapter->bFWReady) { /* 8051 RAM code */
959 /* Reset MCU 0x2[10]=0. */
960 val8 = usb_read8(Adapter, REG_SYS_FUNC_EN+1);
961 val8 &= ~BIT(2); /* 0x2[10], FEN_CPUEN */
962 usb_write8(Adapter, REG_SYS_FUNC_EN+1, val8);
965 /* reset MCU ready status */
966 usb_write8(Adapter, REG_MCUFWDL, 0);
970 val8 = usb_read8(Adapter, REG_32K_CTRL);
971 usb_write8(Adapter, REG_32K_CTRL, val8&(~BIT0));
973 /* Card disable power action flow */
974 HalPwrSeqCmdParsing(Adapter, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, PWR_INTF_USB_MSK, Rtl8188E_NIC_DISABLE_FLOW);
976 /* Reset MCU IO Wrapper */
977 val8 = usb_read8(Adapter, REG_RSV_CTRL+1);
978 usb_write8(Adapter, REG_RSV_CTRL+1, (val8&(~BIT3)));
979 val8 = usb_read8(Adapter, REG_RSV_CTRL+1);
980 usb_write8(Adapter, REG_RSV_CTRL+1, val8|BIT3);
982 /* YJ,test add, 111207. For Power Consumption. */
983 val8 = usb_read8(Adapter, GPIO_IN);
984 usb_write8(Adapter, GPIO_OUT, val8);
985 usb_write8(Adapter, GPIO_IO_SEL, 0xFF);/* Reg0x46 */
987 val8 = usb_read8(Adapter, REG_GPIO_IO_SEL);
988 usb_write8(Adapter, REG_GPIO_IO_SEL, (val8<<4));
989 val8 = usb_read8(Adapter, REG_GPIO_IO_SEL+1);
990 usb_write8(Adapter, REG_GPIO_IO_SEL+1, val8|0x0F);/* Reg0x43 */
991 usb_write32(Adapter, REG_BB_PAD_CTRL, 0x00080808);/* set LNA ,TRSW,EX_PA Pin to output mode */
992 haldata->bMacPwrCtrlOn = false;
993 Adapter->bFWReady = false;
995 static void rtl8192cu_hw_power_down(struct adapter *adapt)
997 /* 2010/-8/09 MH For power down module, we need to enable register block contrl reg at 0x1c. */
998 /* Then enable power down control bit of register 0x04 BIT4 and BIT15 as 1. */
1000 /* Enable register area 0x0-0xc. */
1001 usb_write8(adapt, REG_RSV_CTRL, 0x0);
1002 usb_write16(adapt, REG_APS_FSMCO, 0x8812);
1005 static u32 rtl8188eu_hal_deinit(struct adapter *Adapter)
1008 DBG_88E("==> %s\n", __func__);
1010 usb_write32(Adapter, REG_HIMR_88E, IMR_DISABLED_88E);
1011 usb_write32(Adapter, REG_HIMRE_88E, IMR_DISABLED_88E);
1013 DBG_88E("bkeepfwalive(%x)\n", Adapter->pwrctrlpriv.bkeepfwalive);
1014 if (Adapter->pwrctrlpriv.bkeepfwalive) {
1015 if ((Adapter->pwrctrlpriv.bHWPwrPindetect) && (Adapter->pwrctrlpriv.bHWPowerdown))
1016 rtl8192cu_hw_power_down(Adapter);
1018 if (Adapter->hw_init_completed) {
1019 CardDisableRTL8188EU(Adapter);
1021 if ((Adapter->pwrctrlpriv.bHWPwrPindetect) && (Adapter->pwrctrlpriv.bHWPowerdown))
1022 rtl8192cu_hw_power_down(Adapter);
1028 static unsigned int rtl8188eu_inirp_init(struct adapter *Adapter)
1031 struct recv_buf *precvbuf;
1033 struct recv_priv *precvpriv = &(Adapter->recvpriv);
1037 RT_TRACE(_module_hci_hal_init_c_, _drv_info_,
1038 ("===> usb_inirp_init\n"));
1040 precvpriv->ff_hwaddr = RECV_BULK_IN_ADDR;
1042 /* issue Rx irp to receive data */
1043 precvbuf = (struct recv_buf *)precvpriv->precv_buf;
1044 for (i = 0; i < NR_RECVBUFF; i++) {
1045 if (usb_read_port(Adapter, precvpriv->ff_hwaddr, 0, (unsigned char *)precvbuf) == false) {
1046 RT_TRACE(_module_hci_hal_init_c_, _drv_err_, ("usb_rx_init: usb_read_port error\n"));
1052 precvpriv->free_recv_buf_queue_cnt--;
1057 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("<=== usb_inirp_init\n"));
1063 static unsigned int rtl8188eu_inirp_deinit(struct adapter *Adapter)
1065 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("\n ===> usb_rx_deinit\n"));
1067 usb_read_port_cancel(Adapter);
1069 RT_TRACE(_module_hci_hal_init_c_, _drv_info_, ("\n <=== usb_rx_deinit\n"));
1076 /* EEPROM/EFUSE Content Parsing */
1079 static void Hal_EfuseParsePIDVID_8188EU(struct adapter *adapt, u8 *hwinfo, bool AutoLoadFail)
1081 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
1083 if (!AutoLoadFail) {
1085 haldata->EEPROMVID = EF2BYTE(*(__le16 *)&hwinfo[EEPROM_VID_88EU]);
1086 haldata->EEPROMPID = EF2BYTE(*(__le16 *)&hwinfo[EEPROM_PID_88EU]);
1088 /* Customer ID, 0x00 and 0xff are reserved for Realtek. */
1089 haldata->EEPROMCustomerID = *(u8 *)&hwinfo[EEPROM_CUSTOMERID_88E];
1090 haldata->EEPROMSubCustomerID = EEPROM_Default_SubCustomerID;
1092 haldata->EEPROMVID = EEPROM_Default_VID;
1093 haldata->EEPROMPID = EEPROM_Default_PID;
1095 /* Customer ID, 0x00 and 0xff are reserved for Realtek. */
1096 haldata->EEPROMCustomerID = EEPROM_Default_CustomerID;
1097 haldata->EEPROMSubCustomerID = EEPROM_Default_SubCustomerID;
1100 DBG_88E("VID = 0x%04X, PID = 0x%04X\n", haldata->EEPROMVID, haldata->EEPROMPID);
1101 DBG_88E("Customer ID: 0x%02X, SubCustomer ID: 0x%02X\n", haldata->EEPROMCustomerID, haldata->EEPROMSubCustomerID);
1104 static void Hal_EfuseParseMACAddr_8188EU(struct adapter *adapt, u8 *hwinfo, bool AutoLoadFail)
1107 u8 sMacAddr[6] = {0x00, 0xE0, 0x4C, 0x81, 0x88, 0x02};
1108 struct eeprom_priv *eeprom = GET_EEPROM_EFUSE_PRIV(adapt);
1111 for (i = 0; i < 6; i++)
1112 eeprom->mac_addr[i] = sMacAddr[i];
1114 /* Read Permanent MAC address */
1115 memcpy(eeprom->mac_addr, &hwinfo[EEPROM_MAC_ADDR_88EU], ETH_ALEN);
1117 RT_TRACE(_module_hci_hal_init_c_, _drv_notice_,
1118 ("Hal_EfuseParseMACAddr_8188EU: Permanent Address = %02x-%02x-%02x-%02x-%02x-%02x\n",
1119 eeprom->mac_addr[0], eeprom->mac_addr[1],
1120 eeprom->mac_addr[2], eeprom->mac_addr[3],
1121 eeprom->mac_addr[4], eeprom->mac_addr[5]));
1125 readAdapterInfo_8188EU(
1126 struct adapter *adapt
1129 struct eeprom_priv *eeprom = GET_EEPROM_EFUSE_PRIV(adapt);
1131 /* parse the eeprom/efuse content */
1132 Hal_EfuseParseIDCode88E(adapt, eeprom->efuse_eeprom_data);
1133 Hal_EfuseParsePIDVID_8188EU(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1134 Hal_EfuseParseMACAddr_8188EU(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1136 Hal_ReadPowerSavingMode88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1137 Hal_ReadTxPowerInfo88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1138 Hal_EfuseParseEEPROMVer88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1139 rtl8188e_EfuseParseChnlPlan(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1140 Hal_EfuseParseXtal_8188E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1141 Hal_EfuseParseCustomerID88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1142 Hal_ReadAntennaDiversity88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1143 Hal_EfuseParseBoardType88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1144 Hal_ReadThermalMeter_88E(adapt, eeprom->efuse_eeprom_data, eeprom->bautoload_fail_flag);
1148 static void _ReadPROMContent(
1149 struct adapter *Adapter
1152 struct eeprom_priv *eeprom = GET_EEPROM_EFUSE_PRIV(Adapter);
1155 /* check system boot selection */
1156 eeValue = usb_read8(Adapter, REG_9346CR);
1157 eeprom->EepromOrEfuse = (eeValue & BOOT_FROM_EEPROM) ? true : false;
1158 eeprom->bautoload_fail_flag = (eeValue & EEPROM_EN) ? false : true;
1160 DBG_88E("Boot from %s, Autoload %s !\n", (eeprom->EepromOrEfuse ? "EEPROM" : "EFUSE"),
1161 (eeprom->bautoload_fail_flag ? "Fail" : "OK"));
1163 Hal_InitPGData88E(Adapter);
1164 readAdapterInfo_8188EU(Adapter);
1167 static void _ReadRFType(struct adapter *Adapter)
1169 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
1171 haldata->rf_chip = RF_6052;
1174 static void _ReadAdapterInfo8188EU(struct adapter *Adapter)
1176 u32 start = jiffies;
1178 MSG_88E("====> %s\n", __func__);
1180 _ReadRFType(Adapter);/* rf_chip -> _InitRFType() */
1181 _ReadPROMContent(Adapter);
1183 MSG_88E("<==== %s in %d ms\n", __func__, rtw_get_passing_time_ms(start));
1186 #define GPIO_DEBUG_PORT_NUM 0
1187 static void rtl8192cu_trigger_gpio_0(struct adapter *adapt)
1191 static void ResumeTxBeacon(struct adapter *adapt)
1193 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
1195 /* 2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
1196 /* which should be read from register to a global variable. */
1198 usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) | BIT6);
1199 haldata->RegFwHwTxQCtrl |= BIT6;
1200 usb_write8(adapt, REG_TBTT_PROHIBIT+1, 0xff);
1201 haldata->RegReg542 |= BIT0;
1202 usb_write8(adapt, REG_TBTT_PROHIBIT+2, haldata->RegReg542);
1205 static void StopTxBeacon(struct adapter *adapt)
1207 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
1209 /* 2010.03.01. Marked by tynli. No need to call workitem beacause we record the value */
1210 /* which should be read from register to a global variable. */
1212 usb_write8(adapt, REG_FWHW_TXQ_CTRL+2, (haldata->RegFwHwTxQCtrl) & (~BIT6));
1213 haldata->RegFwHwTxQCtrl &= (~BIT6);
1214 usb_write8(adapt, REG_TBTT_PROHIBIT+1, 0x64);
1215 haldata->RegReg542 &= ~(BIT0);
1216 usb_write8(adapt, REG_TBTT_PROHIBIT+2, haldata->RegReg542);
1218 /* todo: CheckFwRsvdPageContent(Adapter); 2010.06.23. Added by tynli. */
1221 static void hw_var_set_opmode(struct adapter *Adapter, u8 variable, u8 *val)
1224 u8 mode = *((u8 *)val);
1226 /* disable Port0 TSF update */
1227 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(4));
1230 val8 = usb_read8(Adapter, MSR)&0x0c;
1232 usb_write8(Adapter, MSR, val8);
1234 DBG_88E("%s()-%d mode = %d\n", __func__, __LINE__, mode);
1236 if ((mode == _HW_STATE_STATION_) || (mode == _HW_STATE_NOLINK_)) {
1237 StopTxBeacon(Adapter);
1239 usb_write8(Adapter, REG_BCN_CTRL, 0x19);/* disable atim wnd */
1240 } else if ((mode == _HW_STATE_ADHOC_)) {
1241 ResumeTxBeacon(Adapter);
1242 usb_write8(Adapter, REG_BCN_CTRL, 0x1a);
1243 } else if (mode == _HW_STATE_AP_) {
1244 ResumeTxBeacon(Adapter);
1246 usb_write8(Adapter, REG_BCN_CTRL, 0x12);
1249 usb_write32(Adapter, REG_RCR, 0x7000208e);/* CBSSID_DATA must set to 0,reject ICV_ERR packet */
1250 /* enable to rx data frame */
1251 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1252 /* enable to rx ps-poll */
1253 usb_write16(Adapter, REG_RXFLTMAP1, 0x0400);
1255 /* Beacon Control related register for first time */
1256 usb_write8(Adapter, REG_BCNDMATIM, 0x02); /* 2ms */
1258 usb_write8(Adapter, REG_ATIMWND, 0x0a); /* 10ms */
1259 usb_write16(Adapter, REG_BCNTCFG, 0x00);
1260 usb_write16(Adapter, REG_TBTT_PROHIBIT, 0xff04);
1261 usb_write16(Adapter, REG_TSFTR_SYN_OFFSET, 0x7fff);/* +32767 (~32ms) */
1264 usb_write8(Adapter, REG_DUAL_TSF_RST, BIT(0));
1266 /* BIT3 - If set 0, hw will clr bcnq when tx becon ok/fail or port 0 */
1267 usb_write8(Adapter, REG_MBID_NUM, usb_read8(Adapter, REG_MBID_NUM) | BIT(3) | BIT(4));
1269 /* enable BCN0 Function for if1 */
1270 /* don't enable update TSF0 for if1 (due to TSF update when beacon/probe rsp are received) */
1271 usb_write8(Adapter, REG_BCN_CTRL, (DIS_TSF_UDT0_NORMAL_CHIP|EN_BCN_FUNCTION | BIT(1)));
1273 /* dis BCN1 ATIM WND if if2 is station */
1274 usb_write8(Adapter, REG_BCN_CTRL_1, usb_read8(Adapter, REG_BCN_CTRL_1) | BIT(0));
1278 static void hw_var_set_macaddr(struct adapter *Adapter, u8 variable, u8 *val)
1283 reg_macid = REG_MACID;
1285 for (idx = 0; idx < 6; idx++)
1286 usb_write8(Adapter, (reg_macid+idx), val[idx]);
1289 static void hw_var_set_bssid(struct adapter *Adapter, u8 variable, u8 *val)
1294 reg_bssid = REG_BSSID;
1296 for (idx = 0; idx < 6; idx++)
1297 usb_write8(Adapter, (reg_bssid+idx), val[idx]);
1300 static void hw_var_set_bcn_func(struct adapter *Adapter, u8 variable, u8 *val)
1304 bcn_ctrl_reg = REG_BCN_CTRL;
1307 usb_write8(Adapter, bcn_ctrl_reg, (EN_BCN_FUNCTION | EN_TXBCN_RPT));
1309 usb_write8(Adapter, bcn_ctrl_reg, usb_read8(Adapter, bcn_ctrl_reg)&(~(EN_BCN_FUNCTION | EN_TXBCN_RPT)));
1312 static void SetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
1314 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
1315 struct dm_priv *pdmpriv = &haldata->dmpriv;
1316 struct odm_dm_struct *podmpriv = &haldata->odmpriv;
1319 case HW_VAR_MEDIA_STATUS:
1323 val8 = usb_read8(Adapter, MSR)&0x0c;
1324 val8 |= *((u8 *)val);
1325 usb_write8(Adapter, MSR, val8);
1328 case HW_VAR_MEDIA_STATUS1:
1332 val8 = usb_read8(Adapter, MSR) & 0x03;
1333 val8 |= *((u8 *)val) << 2;
1334 usb_write8(Adapter, MSR, val8);
1337 case HW_VAR_SET_OPMODE:
1338 hw_var_set_opmode(Adapter, variable, val);
1340 case HW_VAR_MAC_ADDR:
1341 hw_var_set_macaddr(Adapter, variable, val);
1344 hw_var_set_bssid(Adapter, variable, val);
1346 case HW_VAR_BASIC_RATE:
1351 /* 2007.01.16, by Emily */
1352 /* Select RRSR (in Legacy-OFDM and CCK) */
1353 /* For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, 2M, and 1M from the Basic rate. */
1354 /* We do not use other rates. */
1355 HalSetBrateCfg(Adapter, val, &BrateCfg);
1356 DBG_88E("HW_VAR_BASIC_RATE: BrateCfg(%#x)\n", BrateCfg);
1358 /* 2011.03.30 add by Luke Lee */
1359 /* CCK 2M ACK should be disabled for some BCM and Atheros AP IOT */
1360 /* because CCK 2M has poor TXEVM */
1361 /* CCK 5.5M & 11M ACK should be enabled for better performance */
1363 BrateCfg = (BrateCfg | 0xd) & 0x15d;
1364 haldata->BasicRateSet = BrateCfg;
1366 BrateCfg |= 0x01; /* default enable 1M ACK rate */
1367 /* Set RRSR rate table. */
1368 usb_write8(Adapter, REG_RRSR, BrateCfg & 0xff);
1369 usb_write8(Adapter, REG_RRSR+1, (BrateCfg >> 8) & 0xff);
1370 usb_write8(Adapter, REG_RRSR+2, usb_read8(Adapter, REG_RRSR+2)&0xf0);
1372 /* Set RTS initial rate */
1373 while (BrateCfg > 0x1) {
1374 BrateCfg = (BrateCfg >> 1);
1378 usb_write8(Adapter, REG_INIRTS_RATE_SEL, RateIndex);
1381 case HW_VAR_TXPAUSE:
1382 usb_write8(Adapter, REG_TXPAUSE, *((u8 *)val));
1384 case HW_VAR_BCN_FUNC:
1385 hw_var_set_bcn_func(Adapter, variable, val);
1387 case HW_VAR_CORRECT_TSF:
1390 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
1391 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1393 tsf = pmlmeext->TSFValue - rtw_modular64(pmlmeext->TSFValue, (pmlmeinfo->bcn_interval*1024)) - 1024; /* us */
1395 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
1396 StopTxBeacon(Adapter);
1398 /* disable related TSF function */
1399 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(3)));
1401 usb_write32(Adapter, REG_TSFTR, tsf);
1402 usb_write32(Adapter, REG_TSFTR+4, tsf>>32);
1404 /* enable related TSF function */
1405 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(3));
1407 if (((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE) || ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE))
1408 ResumeTxBeacon(Adapter);
1411 case HW_VAR_CHECK_BSSID:
1413 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR)|RCR_CBSSID_DATA|RCR_CBSSID_BCN);
1417 val32 = usb_read32(Adapter, REG_RCR);
1419 val32 &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);
1421 usb_write32(Adapter, REG_RCR, val32);
1424 case HW_VAR_MLME_DISCONNECT:
1425 /* Set RCR to not to receive data frame when NO LINK state */
1426 /* reject all data frames */
1427 usb_write16(Adapter, REG_RXFLTMAP2, 0x00);
1430 usb_write8(Adapter, REG_DUAL_TSF_RST, (BIT(0)|BIT(1)));
1432 /* disable update TSF */
1433 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(4));
1435 case HW_VAR_MLME_SITESURVEY:
1436 if (*((u8 *)val)) { /* under sitesurvey */
1437 /* config RCR to receive different BSSID & not to receive data frame */
1438 u32 v = usb_read32(Adapter, REG_RCR);
1439 v &= ~(RCR_CBSSID_BCN);
1440 usb_write32(Adapter, REG_RCR, v);
1441 /* reject all data frame */
1442 usb_write16(Adapter, REG_RXFLTMAP2, 0x00);
1444 /* disable update TSF */
1445 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)|BIT(4));
1446 } else { /* sitesurvey done */
1447 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
1448 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1450 if ((is_client_associated_to_ap(Adapter)) ||
1451 ((pmlmeinfo->state&0x03) == WIFI_FW_ADHOC_STATE)) {
1452 /* enable to rx data frame */
1453 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1455 /* enable update TSF */
1456 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(4)));
1457 } else if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
1458 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1459 /* enable update TSF */
1460 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(4)));
1462 if ((pmlmeinfo->state&0x03) == WIFI_FW_AP_STATE) {
1463 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR)|RCR_CBSSID_BCN);
1465 if (Adapter->in_cta_test) {
1466 u32 v = usb_read32(Adapter, REG_RCR);
1467 v &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);/* RCR_ADF */
1468 usb_write32(Adapter, REG_RCR, v);
1470 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR)|RCR_CBSSID_BCN);
1475 case HW_VAR_MLME_JOIN:
1477 u8 RetryLimit = 0x30;
1478 u8 type = *((u8 *)val);
1479 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
1481 if (type == 0) { /* prepare to join */
1482 /* enable to rx data frame.Accept all data frame */
1483 usb_write16(Adapter, REG_RXFLTMAP2, 0xFFFF);
1485 if (Adapter->in_cta_test) {
1486 u32 v = usb_read32(Adapter, REG_RCR);
1487 v &= ~(RCR_CBSSID_DATA | RCR_CBSSID_BCN);/* RCR_ADF */
1488 usb_write32(Adapter, REG_RCR, v);
1490 usb_write32(Adapter, REG_RCR, usb_read32(Adapter, REG_RCR)|RCR_CBSSID_DATA|RCR_CBSSID_BCN);
1493 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE))
1494 RetryLimit = (haldata->CustomerID == RT_CID_CCX) ? 7 : 48;
1495 else /* Ad-hoc Mode */
1497 } else if (type == 1) {
1498 /* joinbss_event call back when join res < 0 */
1499 usb_write16(Adapter, REG_RXFLTMAP2, 0x00);
1500 } else if (type == 2) {
1501 /* sta add event call back */
1502 /* enable update TSF */
1503 usb_write8(Adapter, REG_BCN_CTRL, usb_read8(Adapter, REG_BCN_CTRL)&(~BIT(4)));
1505 if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE|WIFI_ADHOC_MASTER_STATE))
1508 usb_write16(Adapter, REG_RL, RetryLimit << RETRY_LIMIT_SHORT_SHIFT | RetryLimit << RETRY_LIMIT_LONG_SHIFT);
1511 case HW_VAR_BEACON_INTERVAL:
1512 usb_write16(Adapter, REG_BCN_INTERVAL, *((u16 *)val));
1514 case HW_VAR_SLOT_TIME:
1516 u8 u1bAIFS, aSifsTime;
1517 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
1518 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1520 usb_write8(Adapter, REG_SLOT, val[0]);
1522 if (pmlmeinfo->WMM_enable == 0) {
1523 if (pmlmeext->cur_wireless_mode == WIRELESS_11B)
1528 u1bAIFS = aSifsTime + (2 * pmlmeinfo->slotTime);
1530 /* <Roger_EXP> Temporary removed, 2008.06.20. */
1531 usb_write8(Adapter, REG_EDCA_VO_PARAM, u1bAIFS);
1532 usb_write8(Adapter, REG_EDCA_VI_PARAM, u1bAIFS);
1533 usb_write8(Adapter, REG_EDCA_BE_PARAM, u1bAIFS);
1534 usb_write8(Adapter, REG_EDCA_BK_PARAM, u1bAIFS);
1538 case HW_VAR_RESP_SIFS:
1539 /* RESP_SIFS for CCK */
1540 usb_write8(Adapter, REG_R2T_SIFS, val[0]); /* SIFS_T2T_CCK (0x08) */
1541 usb_write8(Adapter, REG_R2T_SIFS+1, val[1]); /* SIFS_R2T_CCK(0x08) */
1542 /* RESP_SIFS for OFDM */
1543 usb_write8(Adapter, REG_T2T_SIFS, val[2]); /* SIFS_T2T_OFDM (0x0a) */
1544 usb_write8(Adapter, REG_T2T_SIFS+1, val[3]); /* SIFS_R2T_OFDM(0x0a) */
1546 case HW_VAR_ACK_PREAMBLE:
1549 u8 bShortPreamble = *((bool *)val);
1550 /* Joseph marked out for Netgear 3500 TKIP channel 7 issue.(Temporarily) */
1551 regTmp = (haldata->nCur40MhzPrimeSC)<<5;
1555 usb_write8(Adapter, REG_RRSR+2, regTmp);
1558 case HW_VAR_SEC_CFG:
1559 usb_write8(Adapter, REG_SECCFG, *((u8 *)val));
1561 case HW_VAR_DM_FLAG:
1562 podmpriv->SupportAbility = *((u8 *)val);
1564 case HW_VAR_DM_FUNC_OP:
1566 podmpriv->BK_SupportAbility = podmpriv->SupportAbility;
1568 podmpriv->SupportAbility = podmpriv->BK_SupportAbility;
1570 case HW_VAR_DM_FUNC_SET:
1571 if (*((u32 *)val) == DYNAMIC_ALL_FUNC_ENABLE) {
1572 pdmpriv->DMFlag = pdmpriv->InitDMFlag;
1573 podmpriv->SupportAbility = pdmpriv->InitODMFlag;
1575 podmpriv->SupportAbility |= *((u32 *)val);
1578 case HW_VAR_DM_FUNC_CLR:
1579 podmpriv->SupportAbility &= *((u32 *)val);
1581 case HW_VAR_CAM_EMPTY_ENTRY:
1583 u8 ucIndex = *((u8 *)val);
1587 u32 ulEncAlgo = CAM_AES;
1589 for (i = 0; i < CAM_CONTENT_COUNT; i++) {
1590 /* filled id in CAM config 2 byte */
1592 ulContent |= (ucIndex & 0x03) | ((u16)(ulEncAlgo)<<2);
1595 /* polling bit, and No Write enable, and address */
1596 ulCommand = CAM_CONTENT_COUNT*ucIndex+i;
1597 ulCommand = ulCommand | CAM_POLLINIG|CAM_WRITE;
1598 /* write content 0 is equall to mark invalid */
1599 usb_write32(Adapter, WCAMI, ulContent); /* delay_ms(40); */
1600 usb_write32(Adapter, RWCAM, ulCommand); /* delay_ms(40); */
1604 case HW_VAR_CAM_INVALID_ALL:
1605 usb_write32(Adapter, RWCAM, BIT(31)|BIT(30));
1607 case HW_VAR_CAM_WRITE:
1610 u32 *cam_val = (u32 *)val;
1611 usb_write32(Adapter, WCAMI, cam_val[0]);
1613 cmd = CAM_POLLINIG | CAM_WRITE | cam_val[1];
1614 usb_write32(Adapter, RWCAM, cmd);
1617 case HW_VAR_AC_PARAM_VO:
1618 usb_write32(Adapter, REG_EDCA_VO_PARAM, ((u32 *)(val))[0]);
1620 case HW_VAR_AC_PARAM_VI:
1621 usb_write32(Adapter, REG_EDCA_VI_PARAM, ((u32 *)(val))[0]);
1623 case HW_VAR_AC_PARAM_BE:
1624 haldata->AcParam_BE = ((u32 *)(val))[0];
1625 usb_write32(Adapter, REG_EDCA_BE_PARAM, ((u32 *)(val))[0]);
1627 case HW_VAR_AC_PARAM_BK:
1628 usb_write32(Adapter, REG_EDCA_BK_PARAM, ((u32 *)(val))[0]);
1630 case HW_VAR_ACM_CTRL:
1632 u8 acm_ctrl = *((u8 *)val);
1633 u8 AcmCtrl = usb_read8(Adapter, REG_ACMHWCTRL);
1636 AcmCtrl = AcmCtrl | 0x1;
1638 if (acm_ctrl & BIT(3))
1639 AcmCtrl |= AcmHw_VoqEn;
1641 AcmCtrl &= (~AcmHw_VoqEn);
1643 if (acm_ctrl & BIT(2))
1644 AcmCtrl |= AcmHw_ViqEn;
1646 AcmCtrl &= (~AcmHw_ViqEn);
1648 if (acm_ctrl & BIT(1))
1649 AcmCtrl |= AcmHw_BeqEn;
1651 AcmCtrl &= (~AcmHw_BeqEn);
1653 DBG_88E("[HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
1654 usb_write8(Adapter, REG_ACMHWCTRL, AcmCtrl);
1657 case HW_VAR_AMPDU_MIN_SPACE:
1662 MinSpacingToSet = *((u8 *)val);
1663 if (MinSpacingToSet <= 7) {
1664 switch (Adapter->securitypriv.dot11PrivacyAlgrthm) {
1679 if (MinSpacingToSet < SecMinSpace)
1680 MinSpacingToSet = SecMinSpace;
1681 usb_write8(Adapter, REG_AMPDU_MIN_SPACE, (usb_read8(Adapter, REG_AMPDU_MIN_SPACE) & 0xf8) | MinSpacingToSet);
1685 case HW_VAR_AMPDU_FACTOR:
1687 u8 RegToSet_Normal[4] = {0x41, 0xa8, 0x72, 0xb9};
1692 pRegToSet = RegToSet_Normal; /* 0xb972a841; */
1693 FactorToSet = *((u8 *)val);
1694 if (FactorToSet <= 3) {
1695 FactorToSet = (1<<(FactorToSet + 2));
1696 if (FactorToSet > 0xf)
1699 for (index = 0; index < 4; index++) {
1700 if ((pRegToSet[index] & 0xf0) > (FactorToSet<<4))
1701 pRegToSet[index] = (pRegToSet[index] & 0x0f) | (FactorToSet<<4);
1703 if ((pRegToSet[index] & 0x0f) > FactorToSet)
1704 pRegToSet[index] = (pRegToSet[index] & 0xf0) | (FactorToSet);
1706 usb_write8(Adapter, (REG_AGGLEN_LMT+index), pRegToSet[index]);
1711 case HW_VAR_RXDMA_AGG_PG_TH:
1713 u8 threshold = *((u8 *)val);
1715 threshold = haldata->UsbRxAggPageCount;
1716 usb_write8(Adapter, REG_RXDMA_AGG_PG_TH, threshold);
1719 case HW_VAR_SET_RPWM:
1721 case HW_VAR_H2C_FW_PWRMODE:
1723 u8 psmode = (*(u8 *)val);
1725 /* Forece leave RF low power mode for 1T1R to prevent conficting setting in Fw power */
1726 /* saving sequence. 2010.06.07. Added by tynli. Suggested by SD3 yschang. */
1727 if ((psmode != PS_MODE_ACTIVE) && (!IS_92C_SERIAL(haldata->VersionID)))
1728 ODM_RF_Saving(podmpriv, true);
1729 rtl8188e_set_FwPwrMode_cmd(Adapter, psmode);
1732 case HW_VAR_H2C_FW_JOINBSSRPT:
1734 u8 mstatus = (*(u8 *)val);
1735 rtl8188e_set_FwJoinBssReport_cmd(Adapter, mstatus);
1738 case HW_VAR_INITIAL_GAIN:
1740 struct rtw_dig *pDigTable = &podmpriv->DM_DigTable;
1741 u32 rx_gain = ((u32 *)(val))[0];
1743 if (rx_gain == 0xff) {/* restore rx gain */
1744 ODM_Write_DIG(podmpriv, pDigTable->BackupIGValue);
1746 pDigTable->BackupIGValue = pDigTable->CurIGValue;
1747 ODM_Write_DIG(podmpriv, rx_gain);
1751 case HW_VAR_TRIGGER_GPIO_0:
1752 rtl8192cu_trigger_gpio_0(Adapter);
1754 case HW_VAR_RPT_TIMER_SETTING:
1756 u16 min_rpt_time = (*(u16 *)val);
1757 ODM_RA_Set_TxRPT_Time(podmpriv, min_rpt_time);
1760 case HW_VAR_ANTENNA_DIVERSITY_SELECT:
1762 u8 Optimum_antenna = (*(u8 *)val);
1764 /* switch antenna to Optimum_antenna */
1765 if (haldata->CurAntenna != Optimum_antenna) {
1766 Ant = (Optimum_antenna == 2) ? MAIN_ANT : AUX_ANT;
1767 ODM_UpdateRxIdleAnt_88E(&haldata->odmpriv, Ant);
1769 haldata->CurAntenna = Optimum_antenna;
1773 case HW_VAR_EFUSE_BYTES: /* To set EFUE total used bytes, added by Roger, 2008.12.22. */
1774 haldata->EfuseUsedBytes = *((u16 *)val);
1776 case HW_VAR_FIFO_CLEARN_UP:
1778 struct pwrctrl_priv *pwrpriv = &Adapter->pwrctrlpriv;
1782 usb_write8(Adapter, REG_TXPAUSE, 0xff);
1785 Adapter->xmitpriv.nqos_ssn = usb_read16(Adapter, REG_NQOS_SEQ);
1787 if (!pwrpriv->bkeepfwalive) {
1789 usb_write32(Adapter, REG_RXPKT_NUM, (usb_read32(Adapter, REG_RXPKT_NUM)|RW_RELEASE_EN));
1791 if (!(usb_read32(Adapter, REG_RXPKT_NUM)&RXDMA_IDLE))
1795 DBG_88E("Stop RX DMA failed......\n");
1798 usb_write16(Adapter, REG_RQPN_NPQ, 0x0);
1799 usb_write32(Adapter, REG_RQPN, 0x80000000);
1804 case HW_VAR_CHECK_TXBUF:
1806 case HW_VAR_APFM_ON_MAC:
1807 haldata->bMacPwrCtrlOn = *val;
1808 DBG_88E("%s: bMacPwrCtrlOn=%d\n", __func__, haldata->bMacPwrCtrlOn);
1810 case HW_VAR_TX_RPT_MAX_MACID:
1813 DBG_88E("### MacID(%d),Set Max Tx RPT MID(%d)\n", maxMacid, maxMacid+1);
1814 usb_write8(Adapter, REG_TX_RPT_CTRL+1, maxMacid+1);
1817 case HW_VAR_H2C_MEDIA_STATUS_RPT:
1818 rtl8188e_set_FwMediaStatus_cmd(Adapter , (*(__le16 *)val));
1820 case HW_VAR_BCN_VALID:
1821 /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2, write 1 to clear, Clear by sw */
1822 usb_write8(Adapter, REG_TDECTRL+2, usb_read8(Adapter, REG_TDECTRL+2) | BIT0);
1829 static void GetHwReg8188EU(struct adapter *Adapter, u8 variable, u8 *val)
1831 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
1832 struct odm_dm_struct *podmpriv = &haldata->odmpriv;
1835 case HW_VAR_BASIC_RATE:
1836 *((u16 *)(val)) = haldata->BasicRateSet;
1837 case HW_VAR_TXPAUSE:
1838 val[0] = usb_read8(Adapter, REG_TXPAUSE);
1840 case HW_VAR_BCN_VALID:
1841 /* BCN_VALID, BIT16 of REG_TDECTRL = BIT0 of REG_TDECTRL+2 */
1842 val[0] = (BIT0 & usb_read8(Adapter, REG_TDECTRL+2)) ? true : false;
1844 case HW_VAR_DM_FLAG:
1845 val[0] = podmpriv->SupportAbility;
1847 case HW_VAR_RF_TYPE:
1848 val[0] = haldata->rf_type;
1850 case HW_VAR_FWLPS_RF_ON:
1852 /* When we halt NIC, we should check if FW LPS is leave. */
1853 if (Adapter->pwrctrlpriv.rf_pwrstate == rf_off) {
1854 /* If it is in HW/SW Radio OFF or IPS state, we do not check Fw LPS Leave, */
1855 /* because Fw is unload. */
1859 valRCR = usb_read32(Adapter, REG_RCR);
1860 valRCR &= 0x00070000;
1868 case HW_VAR_CURRENT_ANTENNA:
1869 val[0] = haldata->CurAntenna;
1871 case HW_VAR_EFUSE_BYTES: /* To get EFUE total used bytes, added by Roger, 2008.12.22. */
1872 *((u16 *)(val)) = haldata->EfuseUsedBytes;
1874 case HW_VAR_APFM_ON_MAC:
1875 *val = haldata->bMacPwrCtrlOn;
1877 case HW_VAR_CHK_HI_QUEUE_EMPTY:
1878 *val = ((usb_read32(Adapter, REG_HGQ_INFORMATION)&0x0000ff00) == 0) ? true : false;
1888 /* Query setting of specified variable. */
1891 GetHalDefVar8188EUsb(
1892 struct adapter *Adapter,
1893 enum hal_def_variable eVariable,
1897 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
1898 u8 bResult = _SUCCESS;
1900 switch (eVariable) {
1901 case HAL_DEF_UNDERCORATEDSMOOTHEDPWDB:
1903 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
1904 struct sta_priv *pstapriv = &Adapter->stapriv;
1905 struct sta_info *psta;
1906 psta = rtw_get_stainfo(pstapriv, pmlmepriv->cur_network.network.MacAddress);
1908 *((int *)pValue) = psta->rssi_stat.UndecoratedSmoothedPWDB;
1911 case HAL_DEF_IS_SUPPORT_ANT_DIV:
1912 *((u8 *)pValue) = (haldata->AntDivCfg == 0) ? false : true;
1914 case HAL_DEF_CURRENT_ANTENNA:
1915 *((u8 *)pValue) = haldata->CurAntenna;
1917 case HAL_DEF_DRVINFO_SZ:
1918 *((u32 *)pValue) = DRVINFO_SZ;
1920 case HAL_DEF_MAX_RECVBUF_SZ:
1921 *((u32 *)pValue) = MAX_RECVBUF_SZ;
1923 case HAL_DEF_RX_PACKET_OFFSET:
1924 *((u32 *)pValue) = RXDESC_SIZE + DRVINFO_SZ;
1926 case HAL_DEF_DBG_DM_FUNC:
1927 *((u32 *)pValue) = haldata->odmpriv.SupportAbility;
1929 case HAL_DEF_RA_DECISION_RATE:
1931 u8 MacID = *((u8 *)pValue);
1932 *((u8 *)pValue) = ODM_RA_GetDecisionRate_8188E(&(haldata->odmpriv), MacID);
1935 case HAL_DEF_RA_SGI:
1937 u8 MacID = *((u8 *)pValue);
1938 *((u8 *)pValue) = ODM_RA_GetShortGI_8188E(&(haldata->odmpriv), MacID);
1941 case HAL_DEF_PT_PWR_STATUS:
1943 u8 MacID = *((u8 *)pValue);
1944 *((u8 *)pValue) = ODM_RA_GetHwPwrStatus_8188E(&(haldata->odmpriv), MacID);
1947 case HW_VAR_MAX_RX_AMPDU_FACTOR:
1948 *((u32 *)pValue) = MAX_AMPDU_FACTOR_64K;
1950 case HW_DEF_RA_INFO_DUMP:
1952 u8 entry_id = *((u8 *)pValue);
1953 if (check_fwstate(&Adapter->mlmepriv, _FW_LINKED)) {
1954 DBG_88E("============ RA status check ===================\n");
1955 DBG_88E("Mac_id:%d , RateID = %d, RAUseRate = 0x%08x, RateSGI = %d, DecisionRate = 0x%02x ,PTStage = %d\n",
1957 haldata->odmpriv.RAInfo[entry_id].RateID,
1958 haldata->odmpriv.RAInfo[entry_id].RAUseRate,
1959 haldata->odmpriv.RAInfo[entry_id].RateSGI,
1960 haldata->odmpriv.RAInfo[entry_id].DecisionRate,
1961 haldata->odmpriv.RAInfo[entry_id].PTStage);
1965 case HW_DEF_ODM_DBG_FLAG:
1967 struct odm_dm_struct *dm_ocm = &(haldata->odmpriv);
1968 pr_info("dm_ocm->DebugComponents = 0x%llx\n", dm_ocm->DebugComponents);
1971 case HAL_DEF_DBG_DUMP_RXPKT:
1972 *((u8 *)pValue) = haldata->bDumpRxPkt;
1974 case HAL_DEF_DBG_DUMP_TXPKT:
1975 *((u8 *)pValue) = haldata->bDumpTxPkt;
1987 /* Change default setting of specified variable. */
1989 static u8 SetHalDefVar8188EUsb(struct adapter *Adapter, enum hal_def_variable eVariable, void *pValue)
1991 struct hal_data_8188e *haldata = GET_HAL_DATA(Adapter);
1992 u8 bResult = _SUCCESS;
1994 switch (eVariable) {
1995 case HAL_DEF_DBG_DM_FUNC:
1997 u8 dm_func = *((u8 *)pValue);
1998 struct odm_dm_struct *podmpriv = &haldata->odmpriv;
2000 if (dm_func == 0) { /* disable all dynamic func */
2001 podmpriv->SupportAbility = DYNAMIC_FUNC_DISABLE;
2002 DBG_88E("==> Disable all dynamic function...\n");
2003 } else if (dm_func == 1) {/* disable DIG */
2004 podmpriv->SupportAbility &= (~DYNAMIC_BB_DIG);
2005 DBG_88E("==> Disable DIG...\n");
2006 } else if (dm_func == 2) {/* disable High power */
2007 podmpriv->SupportAbility &= (~DYNAMIC_BB_DYNAMIC_TXPWR);
2008 } else if (dm_func == 3) {/* disable tx power tracking */
2009 podmpriv->SupportAbility &= (~DYNAMIC_RF_CALIBRATION);
2010 DBG_88E("==> Disable tx power tracking...\n");
2011 } else if (dm_func == 5) {/* disable antenna diversity */
2012 podmpriv->SupportAbility &= (~DYNAMIC_BB_ANT_DIV);
2013 } else if (dm_func == 6) {/* turn on all dynamic func */
2014 if (!(podmpriv->SupportAbility & DYNAMIC_BB_DIG)) {
2015 struct rtw_dig *pDigTable = &podmpriv->DM_DigTable;
2016 pDigTable->CurIGValue = usb_read8(Adapter, 0xc50);
2018 podmpriv->SupportAbility = DYNAMIC_ALL_FUNC_ENABLE;
2019 DBG_88E("==> Turn on all dynamic function...\n");
2023 case HAL_DEF_DBG_DUMP_RXPKT:
2024 haldata->bDumpRxPkt = *((u8 *)pValue);
2026 case HAL_DEF_DBG_DUMP_TXPKT:
2027 haldata->bDumpTxPkt = *((u8 *)pValue);
2029 case HW_DEF_FA_CNT_DUMP:
2031 u8 bRSSIDump = *((u8 *)pValue);
2032 struct odm_dm_struct *dm_ocm = &(haldata->odmpriv);
2034 dm_ocm->DebugComponents = ODM_COMP_DIG|ODM_COMP_FA_CNT ;
2036 dm_ocm->DebugComponents = 0;
2039 case HW_DEF_ODM_DBG_FLAG:
2041 u64 DebugComponents = *((u64 *)pValue);
2042 struct odm_dm_struct *dm_ocm = &(haldata->odmpriv);
2043 dm_ocm->DebugComponents = DebugComponents;
2054 static void UpdateHalRAMask8188EUsb(struct adapter *adapt, u32 mac_id, u8 rssi_level)
2057 u8 networkType, raid;
2058 u32 mask, rate_bitmap;
2059 u8 shortGIrate = false;
2060 int supportRateNum = 0;
2061 struct sta_info *psta;
2062 struct hal_data_8188e *haldata = GET_HAL_DATA(adapt);
2063 struct mlme_ext_priv *pmlmeext = &adapt->mlmeextpriv;
2064 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2065 struct wlan_bssid_ex *cur_network = &(pmlmeinfo->network);
2067 if (mac_id >= NUM_STA) /* CAM_SIZE */
2069 psta = pmlmeinfo->FW_sta_info[mac_id].psta;
2073 case 0:/* for infra mode */
2074 supportRateNum = rtw_get_rateset_len(cur_network->SupportedRates);
2075 networkType = judge_network_type(adapt, cur_network->SupportedRates, supportRateNum) & 0xf;
2076 raid = networktype_to_raid(networkType);
2077 mask = update_supported_rate(cur_network->SupportedRates, supportRateNum);
2078 mask |= (pmlmeinfo->HT_enable) ? update_MSC_rate(&(pmlmeinfo->HT_caps)) : 0;
2079 if (support_short_GI(adapt, &(pmlmeinfo->HT_caps)))
2082 case 1:/* for broadcast/multicast */
2083 supportRateNum = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
2084 if (pmlmeext->cur_wireless_mode & WIRELESS_11B)
2085 networkType = WIRELESS_11B;
2087 networkType = WIRELESS_11G;
2088 raid = networktype_to_raid(networkType);
2089 mask = update_basic_rate(cur_network->SupportedRates, supportRateNum);
2091 default: /* for each sta in IBSS */
2092 supportRateNum = rtw_get_rateset_len(pmlmeinfo->FW_sta_info[mac_id].SupportedRates);
2093 networkType = judge_network_type(adapt, pmlmeinfo->FW_sta_info[mac_id].SupportedRates, supportRateNum) & 0xf;
2094 raid = networktype_to_raid(networkType);
2095 mask = update_supported_rate(cur_network->SupportedRates, supportRateNum);
2097 /* todo: support HT in IBSS */
2101 rate_bitmap = 0x0fffffff;
2102 rate_bitmap = ODM_Get_Rate_Bitmap(&haldata->odmpriv, mac_id, mask, rssi_level);
2103 DBG_88E("%s => mac_id:%d, networkType:0x%02x, mask:0x%08x\n\t ==> rssi_level:%d, rate_bitmap:0x%08x\n",
2104 __func__, mac_id, networkType, mask, rssi_level, rate_bitmap);
2106 mask &= rate_bitmap;
2108 init_rate = get_highest_rate_idx(mask)&0x3f;
2110 if (haldata->fw_ractrl) {
2113 arg = mac_id & 0x1f;/* MACID */
2117 mask |= ((raid << 28) & 0xf0000000);
2118 DBG_88E("update raid entry, mask=0x%x, arg=0x%x\n", mask, arg);
2119 psta->ra_mask = mask;
2120 mask |= ((raid << 28) & 0xf0000000);
2122 /* to do ,for 8188E-SMIC */
2123 rtl8188e_set_raid_cmd(adapt, mask);
2125 ODM_RA_UpdateRateInfo_8188E(&(haldata->odmpriv),
2134 psta->init_rate = init_rate;
2137 static void SetBeaconRelatedRegisters8188EUsb(struct adapter *adapt)
2140 struct mlme_ext_priv *pmlmeext = &(adapt->mlmeextpriv);
2141 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2142 u32 bcn_ctrl_reg = REG_BCN_CTRL;
2143 /* reset TSF, enable update TSF, correcting TSF On Beacon */
2146 usb_write16(adapt, REG_BCN_INTERVAL, pmlmeinfo->bcn_interval);
2147 usb_write8(adapt, REG_ATIMWND, 0x02);/* 2ms */
2149 _InitBeaconParameters(adapt);
2151 usb_write8(adapt, REG_SLOT, 0x09);
2153 value32 = usb_read32(adapt, REG_TCR);
2155 usb_write32(adapt, REG_TCR, value32);
2158 usb_write32(adapt, REG_TCR, value32);
2160 /* NOTE: Fix test chip's bug (about contention windows's randomness) */
2161 usb_write8(adapt, REG_RXTSF_OFFSET_CCK, 0x50);
2162 usb_write8(adapt, REG_RXTSF_OFFSET_OFDM, 0x50);
2164 _BeaconFunctionEnable(adapt, true, true);
2166 ResumeTxBeacon(adapt);
2168 usb_write8(adapt, bcn_ctrl_reg, usb_read8(adapt, bcn_ctrl_reg)|BIT(1));
2171 static void rtl8188eu_init_default_value(struct adapter *adapt)
2173 struct hal_data_8188e *haldata;
2174 struct pwrctrl_priv *pwrctrlpriv;
2177 haldata = GET_HAL_DATA(adapt);
2178 pwrctrlpriv = &adapt->pwrctrlpriv;
2180 /* init default value */
2181 haldata->fw_ractrl = false;
2182 if (!pwrctrlpriv->bkeepfwalive)
2183 haldata->LastHMEBoxNum = 0;
2185 /* init dm default value */
2186 haldata->odmpriv.RFCalibrateInfo.bIQKInitialized = false;
2187 haldata->odmpriv.RFCalibrateInfo.TM_Trigger = 0;/* for IQK */
2188 haldata->pwrGroupCnt = 0;
2189 haldata->PGMaxGroup = 13;
2190 haldata->odmpriv.RFCalibrateInfo.ThermalValue_HP_index = 0;
2191 for (i = 0; i < HP_THERMAL_NUM; i++)
2192 haldata->odmpriv.RFCalibrateInfo.ThermalValue_HP[i] = 0;
2195 void rtl8188eu_set_hal_ops(struct adapter *adapt)
2197 struct hal_ops *halfunc = &adapt->HalFunc;
2200 adapt->HalData = kzalloc(sizeof(struct hal_data_8188e), GFP_KERNEL);
2201 if (adapt->HalData == NULL)
2202 DBG_88E("cant not alloc memory for HAL DATA\n");
2204 halfunc->hal_power_on = rtl8188eu_InitPowerOn;
2205 halfunc->hal_init = &rtl8188eu_hal_init;
2206 halfunc->hal_deinit = &rtl8188eu_hal_deinit;
2208 halfunc->inirp_init = &rtl8188eu_inirp_init;
2209 halfunc->inirp_deinit = &rtl8188eu_inirp_deinit;
2211 halfunc->init_xmit_priv = &rtl8188eu_init_xmit_priv;
2213 halfunc->init_recv_priv = &rtl8188eu_init_recv_priv;
2214 halfunc->free_recv_priv = &rtl8188eu_free_recv_priv;
2215 halfunc->InitSwLeds = &rtl8188eu_InitSwLeds;
2216 halfunc->DeInitSwLeds = &rtl8188eu_DeInitSwLeds;
2218 halfunc->init_default_value = &rtl8188eu_init_default_value;
2219 halfunc->intf_chip_configure = &rtl8188eu_interface_configure;
2220 halfunc->read_adapter_info = &_ReadAdapterInfo8188EU;
2222 halfunc->SetHwRegHandler = &SetHwReg8188EU;
2223 halfunc->GetHwRegHandler = &GetHwReg8188EU;
2224 halfunc->GetHalDefVarHandler = &GetHalDefVar8188EUsb;
2225 halfunc->SetHalDefVarHandler = &SetHalDefVar8188EUsb;
2227 halfunc->UpdateRAMaskHandler = &UpdateHalRAMask8188EUsb;
2228 halfunc->SetBeaconRelatedRegistersHandler = &SetBeaconRelatedRegisters8188EUsb;
2230 halfunc->hal_xmit = &rtl8188eu_hal_xmit;
2231 halfunc->mgnt_xmit = &rtl8188eu_mgnt_xmit;
2233 rtl8188e_set_hal_ops(halfunc);