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