1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /****************************************************************************** 3 * 4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved. 5 * 6 ******************************************************************************/ 7 #ifndef __RTL8723B_HAL_H__ 8 #define __RTL8723B_HAL_H__ 9 10 #include "hal_data.h" 11 12 #include "rtl8723b_spec.h" 13 #include "rtl8723b_rf.h" 14 #include "rtl8723b_dm.h" 15 #include "rtl8723b_recv.h" 16 #include "rtl8723b_xmit.h" 17 #include "rtl8723b_cmd.h" 18 #include "rtw_mp.h" 19 #include "hal_pwr_seq.h" 20 #include "hal_phy_reg_8723b.h" 21 #include "hal_phy_cfg.h" 22 23 /* */ 24 /* RTL8723B From file */ 25 /* */ 26 #define RTL8723B_FW_IMG "rtl8723b/FW_NIC.bin" 27 #define RTL8723B_FW_WW_IMG "rtl8723b/FW_WoWLAN.bin" 28 #define RTL8723B_PHY_REG "rtl8723b/PHY_REG.txt" 29 #define RTL8723B_PHY_RADIO_A "rtl8723b/RadioA.txt" 30 #define RTL8723B_PHY_RADIO_B "rtl8723b/RadioB.txt" 31 #define RTL8723B_TXPWR_TRACK "rtl8723b/TxPowerTrack.txt" 32 #define RTL8723B_AGC_TAB "rtl8723b/AGC_TAB.txt" 33 #define RTL8723B_PHY_MACREG "rtl8723b/MAC_REG.txt" 34 #define RTL8723B_PHY_REG_PG "rtl8723b/PHY_REG_PG.txt" 35 #define RTL8723B_PHY_REG_MP "rtl8723b/PHY_REG_MP.txt" 36 #define RTL8723B_TXPWR_LMT "rtl8723b/TXPWR_LMT.txt" 37 38 /* */ 39 /* RTL8723B From header */ 40 /* */ 41 42 #define FW_8723B_SIZE 0x8000 43 #define FW_8723B_START_ADDRESS 0x1000 44 #define FW_8723B_END_ADDRESS 0x1FFF /* 0x5FFF */ 45 46 #define IS_FW_HEADER_EXIST_8723B(fw_hdr) \ 47 ((le16_to_cpu(fw_hdr->signature) & 0xFFF0) == 0x5300) 48 49 struct rt_firmware { 50 u32 fw_length; 51 u8 *fw_buffer_sz; 52 }; 53 54 /* This structure must be carefully byte-ordered. */ 55 struct rt_firmware_hdr { 56 /* 8-byte alinment required */ 57 58 /* LONG WORD 0 ---- */ 59 __le16 signature; /* 92C0: test chip; 92C, 88C0: test chip; 60 * 88C1: MP A-cut; 92C1: MP A-cut */ 61 u8 category; /* AP/NIC and USB/PCI */ 62 u8 function; /* Reserved for different FW function indications, 63 * for further use when driver needs to download 64 * different FW in different conditions. */ 65 __le16 version; /* FW Version */ 66 __le16 subversion; /* FW Subversion, default 0x00 */ 67 68 /* LONG WORD 1 ---- */ 69 u8 month; /* Release time Month field */ 70 u8 date; /* Release time Date field */ 71 u8 hour; /* Release time Hour field */ 72 u8 minute; /* Release time Minute field */ 73 74 __le16 ram_code_size; /* The size of RAM code */ 75 __le16 rsvd2; 76 77 /* LONG WORD 2 ---- */ 78 __le32 svn_idx; /* The SVN entry index */ 79 __le32 rsvd3; 80 81 /* LONG WORD 3 ---- */ 82 __le32 rsvd4; 83 __le32 rsvd5; 84 }; 85 86 #define DRIVER_EARLY_INT_TIME_8723B 0x05 87 #define BCN_DMA_ATIME_INT_TIME_8723B 0x02 88 89 /* for 8723B */ 90 /* TX 32K, RX 16K, Page size 128B for TX, 8B for RX */ 91 #define PAGE_SIZE_TX_8723B 128 92 #define PAGE_SIZE_RX_8723B 8 93 94 #define RX_DMA_SIZE_8723B 0x4000 /* 16K */ 95 #define RX_DMA_RESERVED_SIZE_8723B 0x80 /* 128B, reserved for tx report */ 96 #define RX_DMA_BOUNDARY_8723B \ 97 (RX_DMA_SIZE_8723B - RX_DMA_RESERVED_SIZE_8723B - 1) 98 99 /* Note: We will divide number of pages equally for each queue other than the 100 * public queue! 101 */ 102 103 /* For General Reserved Page Number(Beacon Queue is reserved page) */ 104 /* Beacon:2, PS-Poll:1, Null Data:1, Qos Null Data:1, BT Qos Null Data:1 */ 105 #define BCNQ_PAGE_NUM_8723B 0x08 106 #define BCNQ1_PAGE_NUM_8723B 0x00 107 108 #ifdef CONFIG_PNO_SUPPORT 109 #undef BCNQ1_PAGE_NUM_8723B 110 #define BCNQ1_PAGE_NUM_8723B 0x00 /* 0x04 */ 111 #endif 112 113 #define MAX_RX_DMA_BUFFER_SIZE_8723B 0x2800 /* RX 10K */ 114 115 /* For WoWLan, more reserved page */ 116 /* ARP Rsp:1, RWC:1, GTK Info:1, GTK RSP:2, GTK EXT MEM:2, PNO: 6 */ 117 #ifdef CONFIG_WOWLAN 118 #define WOWLAN_PAGE_NUM_8723B 0x07 119 #else 120 #define WOWLAN_PAGE_NUM_8723B 0x00 121 #endif 122 123 #ifdef CONFIG_PNO_SUPPORT 124 #undef WOWLAN_PAGE_NUM_8723B 125 #define WOWLAN_PAGE_NUM_8723B 0x0d 126 #endif 127 128 #ifdef CONFIG_AP_WOWLAN 129 #define AP_WOWLAN_PAGE_NUM_8723B 0x02 130 #endif 131 132 #define TX_TOTAL_PAGE_NUMBER_8723B \ 133 (0xFF - BCNQ_PAGE_NUM_8723B - \ 134 BCNQ1_PAGE_NUM_8723B - \ 135 WOWLAN_PAGE_NUM_8723B) 136 #define TX_PAGE_BOUNDARY_8723B (TX_TOTAL_PAGE_NUMBER_8723B + 1) 137 138 #define WMM_NORMAL_TX_TOTAL_PAGE_NUMBER_8723B TX_TOTAL_PAGE_NUMBER_8723B 139 #define WMM_NORMAL_TX_PAGE_BOUNDARY_8723B \ 140 (WMM_NORMAL_TX_TOTAL_PAGE_NUMBER_8723B + 1) 141 142 /* For Normal Chip Setting */ 143 /* (HPQ + LPQ + NPQ + PUBQ) shall be TX_TOTAL_PAGE_NUMBER_8723B */ 144 #define NORMAL_PAGE_NUM_HPQ_8723B 0x0C 145 #define NORMAL_PAGE_NUM_LPQ_8723B 0x02 146 #define NORMAL_PAGE_NUM_NPQ_8723B 0x02 147 148 /* Note: For Normal Chip Setting, modify later */ 149 #define WMM_NORMAL_PAGE_NUM_HPQ_8723B 0x30 150 #define WMM_NORMAL_PAGE_NUM_LPQ_8723B 0x20 151 #define WMM_NORMAL_PAGE_NUM_NPQ_8723B 0x20 152 153 154 #include "HalVerDef.h" 155 #include "hal_com.h" 156 157 #define EFUSE_OOB_PROTECT_BYTES 15 158 159 #define HAL_EFUSE_MEMORY 160 161 #define HWSET_MAX_SIZE_8723B 512 162 #define EFUSE_REAL_CONTENT_LEN_8723B 512 163 #define EFUSE_MAP_LEN_8723B 512 164 #define EFUSE_MAX_SECTION_8723B 64 165 166 #define EFUSE_IC_ID_OFFSET 506 /* For some inferiority IC purpose. 167 * Added by Roger, 2009.09.02. */ 168 #define AVAILABLE_EFUSE_ADDR(addr) (addr < EFUSE_REAL_CONTENT_LEN_8723B) 169 170 #define EFUSE_ACCESS_ON 0x69 /* For RTL8723 only. */ 171 #define EFUSE_ACCESS_OFF 0x00 /* For RTL8723 only. */ 172 173 /* */ 174 /* EFUSE for BT definition */ 175 /* */ 176 #define EFUSE_BT_REAL_BANK_CONTENT_LEN 512 177 #define EFUSE_BT_REAL_CONTENT_LEN 1536 /* 512*3 */ 178 #define EFUSE_BT_MAP_LEN 1024 /* 1k bytes */ 179 #define EFUSE_BT_MAX_SECTION 128 /* 1024/8 */ 180 181 #define EFUSE_PROTECT_BYTES_BANK 16 182 183 /* Description: Determine the types of C2H events that are the same in driver 184 * and FW; First constructed by tynli. 2009.10.09. 185 */ 186 typedef enum _C2H_EVT { 187 C2H_DBG = 0, 188 C2H_TSF = 1, 189 C2H_AP_RPT_RSP = 2, 190 C2H_CCX_TX_RPT = 3, /* The FW notify the report 191 * of the specific tx packet. */ 192 C2H_BT_RSSI = 4, 193 C2H_BT_OP_MODE = 5, 194 C2H_EXT_RA_RPT = 6, 195 C2H_8723B_BT_INFO = 9, 196 C2H_HW_INFO_EXCH = 10, 197 C2H_8723B_BT_MP_INFO = 11, 198 MAX_C2HEVENT 199 } C2H_EVT; 200 201 typedef struct _C2H_EVT_HDR { 202 u8 CmdID; 203 u8 CmdLen; 204 u8 CmdSeq; 205 } __attribute__((__packed__)) C2H_EVT_HDR, *PC2H_EVT_HDR; 206 207 typedef enum tag_Package_Definition { 208 PACKAGE_DEFAULT, 209 PACKAGE_QFN68, 210 PACKAGE_TFBGA90, 211 PACKAGE_TFBGA80, 212 PACKAGE_TFBGA79 213 } PACKAGE_TYPE_E; 214 215 #define INCLUDE_MULTI_FUNC_BT(_Adapter) \ 216 (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_BT) 217 #define INCLUDE_MULTI_FUNC_GPS(_Adapter) \ 218 (GET_HAL_DATA(_Adapter)->MultiFunc & RT_MULTI_FUNC_GPS) 219 220 /* rtl8723a_hal_init.c */ 221 s32 rtl8723b_FirmwareDownload(struct adapter *padapter, bool bUsedWoWLANFw); 222 void rtl8723b_FirmwareSelfReset(struct adapter *padapter); 223 void rtl8723b_InitializeFirmwareVars(struct adapter *padapter); 224 225 void rtl8723b_InitAntenna_Selection(struct adapter *padapter); 226 void rtl8723b_init_default_value(struct adapter *padapter); 227 228 s32 rtl8723b_InitLLTTable(struct adapter *padapter); 229 230 /* EFuse */ 231 u8 GetEEPROMSize8723B(struct adapter *padapter); 232 void Hal_InitPGData(struct adapter *padapter, u8 *PROMContent); 233 void Hal_EfuseParseIDCode(struct adapter *padapter, u8 *hwinfo); 234 void Hal_EfuseParseTxPowerInfo_8723B(struct adapter *padapter, u8 *PROMContent, 235 bool AutoLoadFail); 236 void Hal_EfuseParseBTCoexistInfo_8723B(struct adapter *padapter, u8 *hwinfo, 237 bool AutoLoadFail); 238 void Hal_EfuseParseEEPROMVer_8723B(struct adapter *padapter, u8 *hwinfo, 239 bool AutoLoadFail); 240 void Hal_EfuseParseChnlPlan_8723B(struct adapter *padapter, u8 *hwinfo, 241 bool AutoLoadFail); 242 void Hal_EfuseParseCustomerID_8723B(struct adapter *padapter, u8 *hwinfo, 243 bool AutoLoadFail); 244 void Hal_EfuseParseAntennaDiversity_8723B(struct adapter *padapter, u8 *hwinfo, 245 bool AutoLoadFail); 246 void Hal_EfuseParseXtal_8723B(struct adapter *padapter, u8 *hwinfo, 247 bool AutoLoadFail); 248 void Hal_EfuseParseThermalMeter_8723B(struct adapter *padapter, u8 *hwinfo, 249 u8 AutoLoadFail); 250 void Hal_EfuseParsePackageType_8723B(struct adapter *padapter, u8 *hwinfo, 251 bool AutoLoadFail); 252 void Hal_EfuseParseVoltage_8723B(struct adapter *padapter, u8 *hwinfo, 253 bool AutoLoadFail); 254 255 void C2HPacketHandler_8723B(struct adapter *padapter, u8 *pbuffer, u16 length); 256 257 void rtl8723b_set_hal_ops(struct hal_ops *pHalFunc); 258 void SetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val); 259 void GetHwReg8723B(struct adapter *padapter, u8 variable, u8 *val); 260 u8 SetHalDefVar8723B(struct adapter *padapter, enum HAL_DEF_VARIABLE variable, 261 void *pval); 262 u8 GetHalDefVar8723B(struct adapter *padapter, enum HAL_DEF_VARIABLE variable, 263 void *pval); 264 265 /* register */ 266 void rtl8723b_InitBeaconParameters(struct adapter *padapter); 267 void _InitBurstPktLen_8723BS(struct adapter *adapter); 268 void _8051Reset8723(struct adapter *padapter); 269 #ifdef CONFIG_WOWLAN 270 void Hal_DetectWoWMode(struct adapter *padapter); 271 #endif /* CONFIG_WOWLAN */ 272 273 void rtl8723b_start_thread(struct adapter *padapter); 274 void rtl8723b_stop_thread(struct adapter *padapter); 275 276 #if defined(CONFIG_CHECK_BT_HANG) 277 void rtl8723bs_init_checkbthang_workqueue(struct adapter *adapter); 278 void rtl8723bs_free_checkbthang_workqueue(struct adapter *adapter); 279 void rtl8723bs_cancle_checkbthang_workqueue(struct adapter *adapter); 280 void rtl8723bs_hal_check_bt_hang(struct adapter *adapter); 281 #endif 282 283 #ifdef CONFIG_GPIO_WAKEUP 284 void HalSetOutPutGPIO(struct adapter *padapter, u8 index, u8 OutPutValue); 285 #endif 286 287 int FirmwareDownloadBT(struct adapter *adapter, struct rt_firmware *firmware); 288 289 void CCX_FwC2HTxRpt_8723b(struct adapter *padapter, u8 *pdata, u8 len); 290 s32 c2h_id_filter_ccx_8723b(u8 *buf); 291 s32 c2h_handler_8723b(struct adapter *padapter, u8 *pC2hEvent); 292 u8 MRateToHwRate8723B(u8 rate); 293 u8 HwRateToMRate8723B(u8 rate); 294 295 void Hal_ReadRFGainOffset(struct adapter *padapter, u8 *hwinfo, 296 bool AutoLoadFail); 297 298 #endif 299