1 /****************************************************************************** 2 * 3 * Copyright(c) 2019 - 2021 Realtek Corporation. 4 * 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. 8 * 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 12 * more details. 13 * 14 *****************************************************************************/ 15 #ifndef _PHL_TYPES_H_ 16 #define _PHL_TYPES_H_ 17 18 #define _ALIGN(_len, _align) (((_len) + (_align) - 1) & ~(_align - 1)) 19 20 #ifndef ARRAY_SIZE 21 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) 22 #endif 23 24 enum dma_type { 25 DMA_ADDR, 26 VIRTUAL_ADDR, 27 POOL_ADDR 28 }; 29 30 enum lock_type { 31 _ps, 32 _bh, 33 _irq 34 }; 35 36 #ifndef PHL_PLATFORM_LINUX 37 #ifndef inline 38 #define inline __inline 39 #endif 40 41 #ifndef NULL 42 #define NULL ((void *)0) 43 #endif 44 45 #ifndef __cplusplus 46 typedef unsigned char bool; 47 #endif 48 49 #ifndef false 50 #define false 0 51 #endif 52 53 #ifndef true 54 #define true 1 55 #endif 56 57 #define RTW_PRINT_SEL(x,...) do {} while (0) 58 59 #ifndef BIT 60 #define BIT(x) (1UL << (x)) 61 #endif 62 63 #define _FAIL 0 64 #define _SUCCESS 1 65 66 #define BUG_ON 67 68 #define PCI_DMA_TODEVICE 0 69 #define PCI_DMA_FROMDEVICE 1 70 #endif /*#ifndef PHL_PLATFORM_LINUX*/ 71 72 73 #ifdef PHL_PLATFORM_WINDOWS 74 75 #define MAC_ALEN 6 76 #define _dma unsigned int 77 #define _os_timer RT_TIMER 78 #define _os_lock RT_SPIN_LOCK 79 #define _os_mutex PlatformMutex 80 #define _os_sema PlatformSemaphore 81 #define _os_event PlatformEvent 82 #define _os_list struct list_head 83 84 #define _os_atomic volatile long 85 #define _os_dbgdump DbgPrint 86 #define _os_dbgdump_c DbgPrint 87 #define _os_assert ASSERT 88 #define _os_warn_on 89 90 /*#define _os_completion unsigned long*/ 91 #define _os_tasklet RT_THREAD 92 #define _os_thread RT_THREAD 93 #define _os_spinlockfg unsigned int 94 #define _os_workitem RT_WORK_ITEM 95 96 #define _os_path_sep "\\" 97 #define HAL_FILE_CONFIG_PATH "" 98 #define FW_FILE_CONFIG_PATH "" 99 #define PLATFOM_IS_LITTLE_ENDIAN 1 100 101 #elif defined(PHL_PLATFORM_LINUX) 102 typedef struct rtw_timer_list _os_timer; 103 #define _os_lock _lock 104 #define _os_mutex _mutex 105 #define _os_sema _sema 106 #define _os_event struct completion 107 #define _os_list _list 108 #define _os_atomic ATOMIC_T 109 #define MAC_ALEN ETH_ALEN 110 #define _os_dbgdump _dbgdump 111 #ifdef _dbgdump_c 112 #define _os_dbgdump_c _dbgdump_c 113 #else 114 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)) 115 #define KERN_CONT 116 #endif 117 #define _os_dbgdump_c(fmt, arg...) _dbgdump(KERN_CONT fmt, ##arg) 118 #endif 119 #define _os_assert(_expr) 0/*rtw_bug_on(_expr)*/ 120 #define _os_warn_on(_cond) rtw_warn_on(_cond) 121 #define _dma dma_addr_t 122 123 #define _os_tasklet _tasklet 124 #define _os_thread struct thread_hdl 125 #ifdef CONFIG_PHL_CPU_BALANCE 126 #define _os_workitem _workitem_cpu 127 #else 128 #define _os_workitem _workitem 129 #endif 130 #define _os_spinlockfg unsigned long 131 132 #define _os_path_sep "/" 133 134 #ifndef REALTEK_CONFIG_PATH 135 #define REALTEK_CONFIG_PATH "" 136 #endif 137 #define HAL_FILE_CONFIG_PATH REALTEK_CONFIG_PATH 138 #ifndef CONFIG_FIRMWARE_PATH 139 #define CONFIG_FIRMWARE_PATH "" 140 #endif 141 #define FW_FILE_CONFIG_PATH CONFIG_FIRMWARE_PATH 142 143 #ifdef CONFIG_LITTLE_ENDIAN 144 #define PLATFOM_IS_LITTLE_ENDIAN 1 145 #else 146 #define PLATFOM_IS_LITTLE_ENDIAN 0 147 #endif 148 149 #else 150 151 #ifdef _WIN64 152 typedef unsigned long long size_t; 153 #else 154 typedef unsigned long size_t; 155 #endif 156 #define u8 unsigned char 157 #define s8 char 158 #define u16 unsigned short 159 #define s16 short 160 #define u32 unsigned int 161 #define s32 int 162 #define u64 unsigned long long 163 #define s64 long long 164 #define MAC_ALEN 6 165 166 #ifndef fallthrough 167 #if __GNUC__ >= 5 || defined(__clang__) 168 #ifndef __has_attribute 169 #define __has_attribute(x) 0 170 #endif 171 #if __has_attribute(__fallthrough__) 172 #define fallthrough __attribute__((__fallthrough__)) 173 #endif 174 #endif 175 #ifndef fallthrough 176 #define fallthrough do {} while (0) /* fallthrough */ 177 #endif 178 #endif 179 180 /* keep define name then delete if osdep ready */ 181 #define _dma unsigned long 182 183 #define _os_timer unsigned long 184 #define _os_lock unsigned long 185 #define _os_mutex unsigned long 186 #define _os_sema unsigned long 187 #define _os_event unsigned long 188 #define _os_list struct list_head 189 #define _os_atomic int 190 #define _os_dbgdump(_fmt, ...) 191 #define _os_dbgdump_c(_fmt, ...) 192 #define _os_assert(_expr) 193 #define _os_warn_on(_cond) 194 #define _os_spinlockfg unsigned int 195 196 #define _os_tasklet unsigned long 197 #define _os_thread unsigned long 198 #define _os_workitem unsigned long 199 200 #define _os_path_sep "/" 201 #define HAL_FILE_CONFIG_PATH "" 202 #define FW_FILE_CONFIG_PATH "" 203 204 #define PLATFOM_IS_LITTLE_ENDIAN 1 205 #endif 206 207 struct _os_handler { 208 union { 209 _os_tasklet tasklet; 210 _os_workitem workitem; 211 _os_thread thread; 212 } u; 213 }; 214 215 #ifndef PHL_PLATFORM_LINUX 216 #define SWAP32(x) \ 217 ((u32)((((u32)(x) & (u32)0x000000ff) << 24) | \ 218 (((u32)(x) & (u32)0x0000ff00) << 8) | \ 219 (((u32)(x) & (u32)0x00ff0000) >> 8) | \ 220 (((u32)(x) & (u32)0xff000000) >> 24))) 221 222 #define SWAP16(x) \ 223 ((u16)((((u16)(x) & (u16)0x00ff) << 8) | \ 224 (((u16)(x) & (u16)0xff00) >> 8))) 225 226 /* 1: the platform is Little Endian. */ 227 /* 0: the platform is Big Endian. */ 228 #if PLATFOM_IS_LITTLE_ENDIAN 229 #define cpu_to_le32(x) ((u32)(x)) 230 #define le32_to_cpu(x) ((u32)(x)) 231 #define cpu_to_le16(x) ((u16)(x)) 232 #define le16_to_cpu(x) ((u16)(x)) 233 #define cpu_to_be32(x) SWAP32((x)) 234 #define be32_to_cpu(x) SWAP32((x)) 235 #define cpu_to_be16(x) SWAP16((x)) 236 #define be16_to_cpu(x) SWAP16((x)) 237 #else 238 #define cpu_to_le32(x) SWAP32((x)) 239 #define le32_to_cpu(x) SWAP32((x)) 240 #define cpu_to_le16(x) SWAP16((x)) 241 #define le16_to_cpu(x) SWAP16((x)) 242 #define cpu_to_be32(x) ((u32)(x)) 243 #define be32_to_cpu(x) ((u32)(x)) 244 #define cpu_to_be16(x) ((u16)(x)) 245 #define be16_to_cpu(x) ((u16)(x)) 246 #endif /*PLATFOM_IS_LITTLE_ENDIAN*/ 247 248 typedef u16 __le16; 249 typedef u32 __le32; 250 typedef u16 __be16; 251 typedef u32 __be32; 252 #endif /*#ifndef PHL_PLATFORM_LINUX*/ 253 254 #endif /*_PHL_TYPES_H_*/ 255