1 /****************************************************************************** 2 * 3 * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved. 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 __OSDEP_SERVICE_H_ 16 #define __OSDEP_SERVICE_H_ 17 18 19 #define _FAIL 0 20 #define _SUCCESS 1 21 #define RTW_RX_HANDLED 2 22 23 #include <osdep_service_linux.h> 24 25 #ifndef BIT 26 #define BIT(x) (1 << (x)) 27 #endif 28 29 #define BIT0 0x00000001 30 #define BIT1 0x00000002 31 #define BIT2 0x00000004 32 #define BIT3 0x00000008 33 #define BIT4 0x00000010 34 #define BIT5 0x00000020 35 #define BIT6 0x00000040 36 #define BIT7 0x00000080 37 #define BIT8 0x00000100 38 #define BIT9 0x00000200 39 #define BIT10 0x00000400 40 #define BIT11 0x00000800 41 #define BIT12 0x00001000 42 #define BIT13 0x00002000 43 #define BIT14 0x00004000 44 #define BIT15 0x00008000 45 #define BIT16 0x00010000 46 #define BIT17 0x00020000 47 #define BIT18 0x00040000 48 #define BIT19 0x00080000 49 #define BIT20 0x00100000 50 #define BIT21 0x00200000 51 #define BIT22 0x00400000 52 #define BIT23 0x00800000 53 #define BIT24 0x01000000 54 #define BIT25 0x02000000 55 #define BIT26 0x04000000 56 #define BIT27 0x08000000 57 #define BIT28 0x10000000 58 #define BIT29 0x20000000 59 #define BIT30 0x40000000 60 #define BIT31 0x80000000 61 #define BIT32 0x0100000000 62 #define BIT33 0x0200000000 63 #define BIT34 0x0400000000 64 #define BIT35 0x0800000000 65 #define BIT36 0x1000000000 66 67 extern int RTW_STATUS_CODE(int error_code); 68 69 /* flags used for rtw_mstat_update() */ 70 enum mstat_f { 71 /* type: 0x00ff */ 72 MSTAT_TYPE_VIR = 0x00, 73 MSTAT_TYPE_PHY = 0x01, 74 MSTAT_TYPE_SKB = 0x02, 75 MSTAT_TYPE_USB = 0x03, 76 MSTAT_TYPE_MAX = 0x04, 77 78 /* func: 0xff00 */ 79 MSTAT_FUNC_UNSPECIFIED = 0x00<<8, 80 MSTAT_FUNC_IO = 0x01<<8, 81 MSTAT_FUNC_TX_IO = 0x02<<8, 82 MSTAT_FUNC_RX_IO = 0x03<<8, 83 MSTAT_FUNC_TX = 0x04<<8, 84 MSTAT_FUNC_RX = 0x05<<8, 85 MSTAT_FUNC_MAX = 0x06<<8, 86 }; 87 88 #define mstat_tf_idx(flags) ((flags)&0xff) 89 #define mstat_ff_idx(flags) (((flags)&0xff00) >> 8) 90 91 typedef enum mstat_status{ 92 MSTAT_ALLOC_SUCCESS = 0, 93 MSTAT_ALLOC_FAIL, 94 MSTAT_FREE 95 } MSTAT_STATUS; 96 97 #define rtw_mstat_update(flag, status, sz) do {} while (0) 98 #define rtw_mstat_dump(sel) do {} while (0) 99 void *_rtw_zmalloc(u32 sz); 100 void *_rtw_malloc(u32 sz); 101 void _kfree(u8 *pbuf, u32 sz); 102 103 struct sk_buff *_rtw_skb_alloc(u32 sz); 104 struct sk_buff *_rtw_skb_copy(const struct sk_buff *skb); 105 struct sk_buff *_rtw_skb_clone(struct sk_buff *skb); 106 int _rtw_netif_rx(_nic_hdl ndev, struct sk_buff *skb); 107 108 #define rtw_malloc(sz) _rtw_malloc((sz)) 109 #define rtw_zmalloc(sz) _rtw_zmalloc((sz)) 110 111 #define rtw_skb_alloc(size) _rtw_skb_alloc((size)) 112 #define rtw_skb_alloc_f(size, mstat_f) _rtw_skb_alloc((size)) 113 #define rtw_skb_copy(skb) _rtw_skb_copy((skb)) 114 #define rtw_skb_clone(skb) _rtw_skb_clone((skb)) 115 #define rtw_skb_copy_f(skb, mstat_f) _rtw_skb_copy((skb)) 116 #define rtw_skb_clone_f(skb, mstat_f) _rtw_skb_clone((skb)) 117 #define rtw_netif_rx(ndev, skb) _rtw_netif_rx(ndev, skb) 118 119 extern void _rtw_init_queue(struct __queue *pqueue); 120 121 static __inline void thread_enter(char *name) 122 { 123 allow_signal(SIGTERM); 124 } 125 126 __inline static void flush_signals_thread(void) 127 { 128 if (signal_pending (current)) 129 { 130 flush_signals(current); 131 } 132 } 133 134 #define rtw_warn_on(condition) WARN_ON(condition) 135 136 __inline static int rtw_bug_check(void *parg1, void *parg2, void *parg3, void *parg4) 137 { 138 int ret = true; 139 140 return ret; 141 142 } 143 144 #define _RND(sz, r) ((((sz)+((r)-1))/(r))*(r)) 145 #define RND4(x) (((x >> 2) + (((x & 3) == 0) ? 0: 1)) << 2) 146 147 __inline static u32 _RND4(u32 sz) 148 { 149 150 u32 val; 151 152 val = ((sz >> 2) + ((sz & 3) ? 1: 0)) << 2; 153 154 return val; 155 156 } 157 158 __inline static u32 _RND8(u32 sz) 159 { 160 161 u32 val; 162 163 val = ((sz >> 3) + ((sz & 7) ? 1: 0)) << 3; 164 165 return val; 166 167 } 168 169 #ifndef MAC_FMT 170 #define MAC_FMT "%pM" 171 #endif 172 #ifndef MAC_ARG 173 #define MAC_ARG(x) (x) 174 #endif 175 176 177 #ifdef CONFIG_AP_WOWLAN 178 extern void rtw_softap_lock_suspend(void); 179 extern void rtw_softap_unlock_suspend(void); 180 #endif 181 182 /* File operation APIs, just for linux now */ 183 extern int rtw_is_file_readable(char *path); 184 extern int rtw_retrive_from_file(char *path, u8 *buf, u32 sz); 185 186 extern void rtw_free_netdev(struct net_device * netdev); 187 188 189 extern u64 rtw_modular64(u64 x, u64 y); 190 191 /* Macros for handling unaligned memory accesses */ 192 193 #define RTW_GET_BE16(a) ((u16) (((a)[0] << 8) | (a)[1])) 194 #define RTW_PUT_BE16(a, val) \ 195 do { \ 196 (a)[0] = ((u16) (val)) >> 8; \ 197 (a)[1] = ((u16) (val)) & 0xff; \ 198 } while (0) 199 200 #define RTW_GET_LE16(a) ((u16) (((a)[1] << 8) | (a)[0])) 201 #define RTW_PUT_LE16(a, val) \ 202 do { \ 203 (a)[1] = ((u16) (val)) >> 8; \ 204 (a)[0] = ((u16) (val)) & 0xff; \ 205 } while (0) 206 207 #define RTW_GET_BE24(a) ((((u32) (a)[0]) << 16) | (((u32) (a)[1]) << 8) | \ 208 ((u32) (a)[2])) 209 #define RTW_PUT_BE24(a, val) \ 210 do { \ 211 (a)[0] = (u8) ((((u32) (val)) >> 16) & 0xff); \ 212 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \ 213 (a)[2] = (u8) (((u32) (val)) & 0xff); \ 214 } while (0) 215 216 #define RTW_GET_BE32(a) ((((u32) (a)[0]) << 24) | (((u32) (a)[1]) << 16) | \ 217 (((u32) (a)[2]) << 8) | ((u32) (a)[3])) 218 #define RTW_PUT_BE32(a, val) \ 219 do { \ 220 (a)[0] = (u8) ((((u32) (val)) >> 24) & 0xff); \ 221 (a)[1] = (u8) ((((u32) (val)) >> 16) & 0xff); \ 222 (a)[2] = (u8) ((((u32) (val)) >> 8) & 0xff); \ 223 (a)[3] = (u8) (((u32) (val)) & 0xff); \ 224 } while (0) 225 226 #define RTW_GET_LE32(a) ((((u32) (a)[3]) << 24) | (((u32) (a)[2]) << 16) | \ 227 (((u32) (a)[1]) << 8) | ((u32) (a)[0])) 228 #define RTW_PUT_LE32(a, val) \ 229 do { \ 230 (a)[3] = (u8) ((((u32) (val)) >> 24) & 0xff); \ 231 (a)[2] = (u8) ((((u32) (val)) >> 16) & 0xff); \ 232 (a)[1] = (u8) ((((u32) (val)) >> 8) & 0xff); \ 233 (a)[0] = (u8) (((u32) (val)) & 0xff); \ 234 } while (0) 235 236 #define RTW_GET_BE64(a) ((((u64) (a)[0]) << 56) | (((u64) (a)[1]) << 48) | \ 237 (((u64) (a)[2]) << 40) | (((u64) (a)[3]) << 32) | \ 238 (((u64) (a)[4]) << 24) | (((u64) (a)[5]) << 16) | \ 239 (((u64) (a)[6]) << 8) | ((u64) (a)[7])) 240 #define RTW_PUT_BE64(a, val) \ 241 do { \ 242 (a)[0] = (u8) (((u64) (val)) >> 56); \ 243 (a)[1] = (u8) (((u64) (val)) >> 48); \ 244 (a)[2] = (u8) (((u64) (val)) >> 40); \ 245 (a)[3] = (u8) (((u64) (val)) >> 32); \ 246 (a)[4] = (u8) (((u64) (val)) >> 24); \ 247 (a)[5] = (u8) (((u64) (val)) >> 16); \ 248 (a)[6] = (u8) (((u64) (val)) >> 8); \ 249 (a)[7] = (u8) (((u64) (val)) & 0xff); \ 250 } while (0) 251 252 #define RTW_GET_LE64(a) ((((u64) (a)[7]) << 56) | (((u64) (a)[6]) << 48) | \ 253 (((u64) (a)[5]) << 40) | (((u64) (a)[4]) << 32) | \ 254 (((u64) (a)[3]) << 24) | (((u64) (a)[2]) << 16) | \ 255 (((u64) (a)[1]) << 8) | ((u64) (a)[0])) 256 257 void rtw_buf_free(u8 **buf, u32 *buf_len); 258 void rtw_buf_update(u8 **buf, u32 *buf_len, u8 *src, u32 src_len); 259 260 struct rtw_cbuf { 261 u32 write; 262 u32 read; 263 u32 size; 264 void *bufs[0]; 265 }; 266 267 bool rtw_cbuf_full(struct rtw_cbuf *cbuf); 268 bool rtw_cbuf_empty(struct rtw_cbuf *cbuf); 269 bool rtw_cbuf_push(struct rtw_cbuf *cbuf, void *buf); 270 void *rtw_cbuf_pop(struct rtw_cbuf *cbuf); 271 struct rtw_cbuf *rtw_cbuf_alloc(u32 size); 272 273 /* String handler */ 274 /* 275 * Write formatted output to sized buffer 276 */ 277 #define rtw_sprintf(buf, size, format, arg...) snprintf(buf, size, format, ##arg) 278 279 #endif 280