1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /****************************************************************************** 3 * 4 * Copyright(c) 2012 - 2017 Realtek Corporation. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms of version 2 of the GNU General Public License as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 *****************************************************************************/ 16 #ifndef __RTL8192E_HAL_H__ 17 #define __RTL8192E_HAL_H__ 18 19 /* #include "hal_com.h" */ 20 21 #include "hal_data.h" 22 23 /* include HAL Related header after HAL Related compiling flags */ 24 #include "rtl8192e_spec.h" 25 #include "rtl8192e_rf.h" 26 #include "rtl8192e_dm.h" 27 #include "rtl8192e_recv.h" 28 #include "rtl8192e_xmit.h" 29 #include "rtl8192e_cmd.h" 30 #include "rtl8192e_led.h" 31 #include "Hal8192EPwrSeq.h" 32 #include "Hal8192EPhyReg.h" 33 #include "Hal8192EPhyCfg.h" 34 35 36 #ifdef DBG_CONFIG_ERROR_DETECT 37 #include "rtl8192e_sreset.h" 38 #endif 39 40 /* --------------------------------------------------------------------- 41 * RTL8192E Power Configuration CMDs for PCIe interface 42 * --------------------------------------------------------------------- */ 43 #define Rtl8192E_NIC_PWR_ON_FLOW rtl8192E_power_on_flow 44 #define Rtl8192E_NIC_RF_OFF_FLOW rtl8192E_radio_off_flow 45 #define Rtl8192E_NIC_DISABLE_FLOW rtl8192E_card_disable_flow 46 #define Rtl8192E_NIC_ENABLE_FLOW rtl8192E_card_enable_flow 47 #define Rtl8192E_NIC_SUSPEND_FLOW rtl8192E_suspend_flow 48 #define Rtl8192E_NIC_RESUME_FLOW rtl8192E_resume_flow 49 #define Rtl8192E_NIC_PDN_FLOW rtl8192E_hwpdn_flow 50 #define Rtl8192E_NIC_LPS_ENTER_FLOW rtl8192E_enter_lps_flow 51 #define Rtl8192E_NIC_LPS_LEAVE_FLOW rtl8192E_leave_lps_flow 52 53 54 #if 1 /* download firmware related data structure */ 55 #define FW_SIZE_8192E 0x8000 /* Compatible with RTL8192e Maximal RAM code size 32k */ 56 #define FW_START_ADDRESS 0x1000 57 #define FW_END_ADDRESS 0x5FFF 58 59 60 #define IS_FW_HEADER_EXIST_8192E(_pFwHdr) ((GET_FIRMWARE_HDR_SIGNATURE_8192E(_pFwHdr) & 0xFFF0) == 0x92E0) 61 62 63 64 typedef struct _RT_FIRMWARE_8192E { 65 FIRMWARE_SOURCE eFWSource; 66 #ifdef CONFIG_EMBEDDED_FWIMG 67 u8 *szFwBuffer; 68 #else 69 u8 szFwBuffer[FW_SIZE_8192E]; 70 #endif 71 u32 ulFwLength; 72 } RT_FIRMWARE_8192E, *PRT_FIRMWARE_8192E; 73 74 /* 75 * This structure must be cared byte-ordering 76 * 77 * Added by tynli. 2009.12.04. */ 78 79 /* ***************************************************** 80 * Firmware Header(8-byte alinment required) 81 * ***************************************************** 82 * --- LONG WORD 0 ---- */ 83 #define GET_FIRMWARE_HDR_SIGNATURE_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr, 0, 16) /* 92C0: test chip; 92C, 88C0: test chip; 88C1: MP A-cut; 92C1: MP A-cut */ 84 #define GET_FIRMWARE_HDR_CATEGORY_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr, 16, 8) /* AP/NIC and USB/PCI */ 85 #define GET_FIRMWARE_HDR_FUNCTION_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr, 24, 8) /* Reserved for different FW function indcation, for further use when driver needs to download different FW in different conditions */ 86 #define GET_FIRMWARE_HDR_VERSION_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+4, 0, 16)/* FW Version */ 87 #define GET_FIRMWARE_HDR_SUB_VER_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+4, 16, 8) /* FW Subversion, default 0x00 */ 88 #define GET_FIRMWARE_HDR_RSVD1_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+4, 24, 8) 89 90 /* --- LONG WORD 1 ---- */ 91 #define GET_FIRMWARE_HDR_MONTH_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+8, 0, 8) /* Release time Month field */ 92 #define GET_FIRMWARE_HDR_DATE_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+8, 8, 8) /* Release time Date field */ 93 #define GET_FIRMWARE_HDR_HOUR_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+8, 16, 8)/* Release time Hour field */ 94 #define GET_FIRMWARE_HDR_MINUTE_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+8, 24, 8)/* Release time Minute field */ 95 #define GET_FIRMWARE_HDR_ROMCODE_SIZE_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+12, 0, 16)/* The size of RAM code */ 96 #define GET_FIRMWARE_HDR_RSVD2_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+12, 16, 16) 97 98 /* --- LONG WORD 2 ---- */ 99 #define GET_FIRMWARE_HDR_SVN_IDX_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+16, 0, 32)/* The SVN entry index */ 100 #define GET_FIRMWARE_HDR_RSVD3_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+20, 0, 32) 101 102 /* --- LONG WORD 3 ---- */ 103 #define GET_FIRMWARE_HDR_RSVD4_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+24, 0, 32) 104 #define GET_FIRMWARE_HDR_RSVD5_8192E(__FwHdr) LE_BITS_TO_4BYTE(__FwHdr+28, 0, 32) 105 106 #endif /* download firmware related data structure */ 107 108 #define DRIVER_EARLY_INT_TIME_8192E 0x05 109 #define BCN_DMA_ATIME_INT_TIME_8192E 0x02 110 #define RX_DMA_SIZE_8192E 0x4000 /* 16K*/ 111 112 #ifdef CONFIG_WOWLAN 113 #define RESV_FMWF (WKFMCAM_SIZE * MAX_WKFM_CAM_NUM) /* 16 entries, for each is 24 bytes*/ 114 #else 115 #define RESV_FMWF 0 116 #endif 117 118 #ifdef CONFIG_FW_C2H_DEBUG 119 #define RX_DMA_RESERVED_SIZE_8192E 0x100 /* 256B, reserved for c2h debug message*/ 120 #else 121 #define RX_DMA_RESERVED_SIZE_8192E 0x40 /* 64B, reserved for c2h event(16bytes) or ccx(8 Bytes)*/ 122 #endif 123 #define MAX_RX_DMA_BUFFER_SIZE_8192E (RX_DMA_SIZE_8192E-RX_DMA_RESERVED_SIZE_8192E) /*RX 16K*/ 124 125 126 #define PAGE_SIZE_TX_92E PAGE_SIZE_256 127 128 /* For General Reserved Page Number(Beacon Queue is reserved page) 129 * if (CONFIG_2BCN_EN) Beacon:4, PS-Poll:1, Null Data:1,Prob Rsp:1,Qos Null Data:1 130 * Beacon: MAX_BEACON_LEN / PAGE_SIZE_TX_92E 131 * PS-Poll:1, Null Data:1,Prob Rsp:1,Qos Null Data:1,CTS-2-SELF / LTE QoS Null*/ 132 133 #define RSVD_PAGE_NUM_8192E (MAX_BEACON_LEN / PAGE_SIZE_TX_92E + 6) /*0x08*/ 134 /* For WoWLan , more reserved page 135 * ARP Rsp:1, RWC:1, GTK Info:1,GTK RSP:2,GTK EXT MEM:2, AOAC rpt: 1,PNO: 6 136 * NS offload: 2 NDP info: 1 137 */ 138 #ifdef CONFIG_WOWLAN 139 #define WOWLAN_PAGE_NUM_8192E 0x0b 140 #else 141 #define WOWLAN_PAGE_NUM_8192E 0x00 142 #endif 143 144 #ifdef CONFIG_PNO_SUPPORT 145 #undef WOWLAN_PAGE_NUM_8192E 146 #define WOWLAN_PAGE_NUM_8192E 0x0d 147 #endif 148 149 /* Note: 150 Tx FIFO Size : 64KB 151 Tx page Size : 256B 152 Total page numbers : 256(0x100) 153 */ 154 155 #define TOTAL_RSVD_PAGE_NUMBER_8192E (RSVD_PAGE_NUM_8192E + WOWLAN_PAGE_NUM_8192E) 156 157 #define TOTAL_PAGE_NUMBER_8192E (0x100) 158 #define TX_TOTAL_PAGE_NUMBER_8192E (TOTAL_PAGE_NUMBER_8192E - TOTAL_RSVD_PAGE_NUMBER_8192E) 159 160 #define TX_PAGE_BOUNDARY_8192E (TX_TOTAL_PAGE_NUMBER_8192E) /* beacon header start address */ 161 162 163 #define RSVD_PKT_LEN_92E (TOTAL_RSVD_PAGE_NUMBER_8192E * PAGE_SIZE_TX_92E) 164 165 #define TX_PAGE_LOAD_FW_BOUNDARY_8192E 0x47 /* 0xA5 */ 166 #define TX_PAGE_BOUNDARY_WOWLAN_8192E 0xE0 167 168 /* For Normal Chip Setting 169 * (HPQ + LPQ + NPQ + PUBQ) shall be TX_TOTAL_PAGE_NUMBER_92C */ 170 171 #define NORMAL_PAGE_NUM_HPQ_8192E 0x10 172 #define NORMAL_PAGE_NUM_LPQ_8192E 0x10 173 #define NORMAL_PAGE_NUM_NPQ_8192E 0x10 174 #define NORMAL_PAGE_NUM_EPQ_8192E 0x00 175 176 177 /* Note: For WMM Normal Chip Setting ,modify later */ 178 #define WMM_NORMAL_PAGE_NUM_HPQ_8192E NORMAL_PAGE_NUM_HPQ_8192E 179 #define WMM_NORMAL_PAGE_NUM_LPQ_8192E NORMAL_PAGE_NUM_LPQ_8192E 180 #define WMM_NORMAL_PAGE_NUM_NPQ_8192E NORMAL_PAGE_NUM_NPQ_8192E 181 182 183 /* ------------------------------------------------------------------------- 184 * Chip specific 185 * ------------------------------------------------------------------------- */ 186 187 /* pic buffer descriptor */ 188 #define RTL8192EE_SEG_NUM TX_BUFFER_SEG_NUM 189 #define TX_DESC_NUM_92E 128 190 #define RX_DESC_NUM_92E 128 191 192 /* ------------------------------------------------------------------------- 193 * Channel Plan 194 * ------------------------------------------------------------------------- */ 195 196 #define HWSET_MAX_SIZE_8192E 512 197 198 #define EFUSE_REAL_CONTENT_LEN_8192E 512 199 200 #define EFUSE_MAP_LEN_8192E 512 201 #define EFUSE_MAX_SECTION_8192E 64 202 #define EFUSE_MAX_WORD_UNIT_8192E 4 203 #define EFUSE_IC_ID_OFFSET_8192E 506 /* For some inferiority IC purpose. added by Roger, 2009.09.02. */ 204 #define AVAILABLE_EFUSE_ADDR_8192E(addr) (addr < EFUSE_REAL_CONTENT_LEN_8192E) 205 /* 206 * <Roger_Notes> To prevent out of boundary programming case, leave 1byte and program full section 207 * 9bytes + 1byt + 5bytes and pre 1byte. 208 * For worst case: 209 * | 1byte|----8bytes----|1byte|--5bytes--| 210 * | | Reserved(14bytes) | 211 * */ 212 #define EFUSE_OOB_PROTECT_BYTES_8192E 15 /* PG data exclude header, dummy 6 bytes frome CP test and reserved 1byte. */ 213 214 215 216 /* ******************************************************** 217 * EFUSE for BT definition 218 * ******************************************************** */ 219 #define EFUSE_BT_REAL_BANK_CONTENT_LEN_8192E 512 220 #define EFUSE_BT_REAL_CONTENT_LEN_8192E 1024 /* 512*2 */ 221 #define EFUSE_BT_MAP_LEN_8192E 1024 /* 1k bytes */ 222 #define EFUSE_BT_MAX_SECTION_8192E 128 /* 1024/8 */ 223 224 #define EFUSE_PROTECT_BYTES_BANK_8192E 16 225 #define EFUSE_MAX_BANK_8192E 3 226 /* *********************************************************** */ 227 228 #define INCLUDE_MULTI_FUNC_BT(_Adapter) (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_BT) 229 #define INCLUDE_MULTI_FUNC_GPS(_Adapter) (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_GPS) 230 231 /* #define IS_MULTI_FUNC_CHIP(_Adapter) (((((PHAL_DATA_TYPE)(_Adapter->HalData))->MultiFunc) & (RT_MULTI_FUNC_BT|RT_MULTI_FUNC_GPS)) ? _TRUE : _FALSE) */ 232 233 /* #define RT_IS_FUNC_DISABLED(__pAdapter, __FuncBits) ( (__pAdapter)->DisabledFunctions & (__FuncBits) ) */ 234 235 /* rtl8812_hal_init.c */ 236 void _8051Reset8192E(PADAPTER padapter); 237 s32 FirmwareDownload8192E(PADAPTER Adapter, BOOLEAN bUsedWoWLANFw); 238 void InitializeFirmwareVars8192E(PADAPTER padapter); 239 240 s32 InitLLTTable8192E(PADAPTER padapter, u8 txpktbuf_bndy); 241 242 /* EFuse */ 243 u8 GetEEPROMSize8192E(PADAPTER padapter); 244 void hal_InitPGData_8192E(PADAPTER padapter, u8 *PROMContent); 245 void Hal_EfuseParseIDCode8192E(PADAPTER padapter, u8 *hwinfo); 246 void Hal_ReadPROMVersion8192E(PADAPTER padapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 247 void Hal_ReadPowerSavingMode8192E(PADAPTER padapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 248 void Hal_ReadTxPowerInfo8192E(PADAPTER padapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 249 void Hal_ReadBoardType8192E(PADAPTER pAdapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 250 void Hal_ReadThermalMeter_8192E(PADAPTER Adapter, u8 *PROMContent, BOOLEAN AutoloadFail); 251 void Hal_ReadChannelPlan8192E(PADAPTER padapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 252 void Hal_EfuseParseXtal_8192E(PADAPTER pAdapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 253 void Hal_ReadAntennaDiversity8192E(PADAPTER pAdapter, u8 *PROMContent, BOOLEAN AutoLoadFail); 254 void Hal_ReadPAType_8192E(PADAPTER Adapter, u8 *PROMContent, BOOLEAN AutoloadFail); 255 void Hal_ReadAmplifierType_8192E(PADAPTER Adapter, u8 *PROMContent, BOOLEAN AutoloadFail); 256 void Hal_ReadRFEType_8192E(PADAPTER Adapter, u8 *PROMContent, BOOLEAN AutoloadFail); 257 void Hal_EfuseParseBTCoexistInfo8192E(PADAPTER Adapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 258 void Hal_EfuseParseKFreeData_8192E(PADAPTER pAdapter, u8 *hwinfo, BOOLEAN AutoLoadFail); 259 260 u8 Hal_CrystalAFEAdjust(_adapter *Adapter); 261 262 BOOLEAN HalDetectPwrDownMode8192E(PADAPTER Adapter); 263 264 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) 265 void Hal_DetectWoWMode(PADAPTER pAdapter); 266 #endif /* CONFIG_WOWLAN */ 267 268 /***********************************************************/ 269 /* RTL8192E-MAC Setting */ 270 void _InitQueueReservedPage_8192E(PADAPTER Adapter); 271 void _InitQueuePriority_8192E(PADAPTER Adapter); 272 void _InitTxBufferBoundary_8192E(PADAPTER Adapter, u8 txpktbuf_bndy); 273 void _InitPageBoundary_8192E(PADAPTER Adapter); 274 /* void _InitTransferPageSize_8192E(PADAPTER Adapter); */ 275 void _InitDriverInfoSize_8192E(PADAPTER Adapter, u8 drvInfoSize); 276 void _InitRDGSetting_8192E(PADAPTER Adapter); 277 void _InitID_8192E(PADAPTER Adapter); 278 void _InitNetworkType_8192E(PADAPTER Adapter); 279 void _InitWMACSetting_8192E(PADAPTER Adapter); 280 void _InitAdaptiveCtrl_8192E(PADAPTER Adapter); 281 void _InitEDCA_8192E(PADAPTER Adapter); 282 void _InitRetryFunction_8192E(PADAPTER Adapter); 283 void _BBTurnOnBlock_8192E(PADAPTER Adapter); 284 void _InitBeaconParameters_8192E(PADAPTER Adapter); 285 void _InitBeaconMaxError_8192E( 286 PADAPTER Adapter, 287 BOOLEAN InfraMode 288 ); 289 void SetBeaconRelatedRegisters8192E(PADAPTER padapter); 290 void hal_ReadRFType_8192E(PADAPTER Adapter); 291 /* RTL8192E-MAC Setting 292 ***********************************************************/ 293 294 u8 SetHwReg8192E(PADAPTER Adapter, u8 variable, u8 *val); 295 void GetHwReg8192E(PADAPTER Adapter, u8 variable, u8 *val); 296 u8 297 SetHalDefVar8192E( 298 PADAPTER Adapter, 299 HAL_DEF_VARIABLE eVariable, 300 void *pValue 301 ); 302 u8 303 GetHalDefVar8192E( 304 PADAPTER Adapter, 305 HAL_DEF_VARIABLE eVariable, 306 void *pValue 307 ); 308 309 void rtl8192e_set_hal_ops(struct hal_ops *pHalFunc); 310 void init_hal_spec_8192e(_adapter *adapter); 311 void rtl8192e_init_default_value(_adapter *padapter); 312 313 void rtl8192e_start_thread(_adapter *padapter); 314 void rtl8192e_stop_thread(_adapter *padapter); 315 316 #ifdef CONFIG_PCI_HCI 317 BOOLEAN InterruptRecognized8192EE(PADAPTER Adapter); 318 u16 get_txbd_rw_reg(u16 ff_hwaddr); 319 #endif 320 321 #ifdef CONFIG_SDIO_HCI 322 #ifdef CONFIG_SDIO_TX_ENABLE_AVAL_INT 323 void _init_available_page_threshold(PADAPTER padapter, u8 numHQ, u8 numNQ, u8 numLQ, u8 numPubQ); 324 #endif 325 #endif 326 327 #ifdef CONFIG_BT_COEXIST 328 void rtl8192e_combo_card_WifiOnlyHwInit(PADAPTER Adapter); 329 #endif 330 331 #endif /* __RTL8192E_HAL_H__ */ 332