2
* Copyright (C) Jan 2006 Mellanox Technologies Ltd. All rights reserved.
4
* This software is available to you under a choice of one of two
5
* licenses. You may choose to be licensed under the terms of the GNU
6
* General Public License (GPL) Version 2, available from the file
7
* COPYING in the main directory of this source tree, or the
8
* OpenIB.org BSD license below:
10
* Redistribution and use in source and binary forms, with or
11
* without modification, are permitted provided that the following
14
* - Redistributions of source code must retain the above
15
* copyright notice, this list of conditions and the following
18
* - Redistributions in binary form must reproduce the above
19
* copyright notice, this list of conditions and the following
20
* disclaimer in the documentation and/or other materials
21
* provided with the distribution.
23
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32
* compatibility.h - Miscellaneous systems compatibility issues
34
* Version: $Id: compatibility.h 3261 2007-01-28 14:59:53Z orenk $
38
#ifndef COMPATIBILITY_H
39
#define COMPATIBILITY_H
43
#if defined(__ia64__) || defined(__x86_64__) || defined(__PPC64__)
50
/* define macros to the architecture of the CPU */
51
#if defined(__linux) || defined(__FreeBSD__) /* __linux || __FreeBSD__ */
52
# if defined(__i386__)
54
# elif defined(__x86_64__)
56
# elif defined(__ia64__)
58
# elif defined(__PPC64__)
60
# elif defined(__PPC__)
62
# elif defined(__aarch64__)
65
# error Unknown CPU architecture using the linux OS
67
#elif defined(__MINGW32__) || defined(__MINGW64__) /* Windows MINGW */
68
# if defined(__MINGW32__)
70
# elif defined(__MINGW64__)
73
# error Unknown CPU architecture using the windows-mingw OS
75
#elif defined(_WIN32) || defined(_WIN64) /* Windows */
78
# elif defined(_WIN64)
81
# error Unknown CPU architecture using the windows OS
87
/* define macros for print fields */
89
#define U32H_FMT "0x%08x"
92
#define U16H_FMT "0x%04x"
93
#define U8H_FMT "0x%02x"
95
#if defined(ARCH_x86) || defined(ARCH_ppc) || defined(UEFI_BUILD)
96
# if defined(__MINGW32__) || defined(__MINGW64__)
97
# include <inttypes.h>
98
# define U64D_FMT "0x%"PRId64
99
# define U64H_FMT "0x%"PRIx64
100
# define U64H_FMT_GEN ""PRIx64
101
# define U48H_FMT "0x%"PRIx64
102
# define U64D_FMT_GEN ""PRId64
104
# define U64D_FMT "%llu"
105
# define U64H_FMT "0x%016llx"
106
# define U64H_FMT_GEN "llx"
107
# define U48H_FMT "0x%012llx"
108
# define U64D_FMT_GEN "llu"
110
#elif defined (ARCH_ia64) || defined(ARCH_x86_64) || defined(ARCH_ppc64) || defined(ARCH_arm64)
111
# define U64D_FMT "%lu"
112
# define U64H_FMT "0x%016lx"
113
# define U48H_FMT "0x%012lx"
114
# define U64H_FMT_GEN "lx"
115
# define U64D_FMT_GEN "lu"
117
# error Unknown architecture
121
/* define msleep(x) - sleeps for x milliseconds */
122
#if defined(_WIN32) || defined(__MINGW32__) || defined(__MINGW64__)
123
#include <Winsock2.h>
124
#include <winsock2.h>
126
#define msleep(x) Sleep(x)
129
#define msleep(x) usleep(((unsigned long)x)*1000)
133
* Only for architectures which can't do swab by themselves
135
#define ___my_swab16(x) \
137
(((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \
138
(((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) ))
139
#define ___my_swab32(x) \
141
(((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \
142
(((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \
143
(((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \
144
(((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) ))
145
#define ___my_swab64(x) \
147
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \
148
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \
149
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \
150
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \
151
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \
152
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \
153
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \
154
(u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) ))
159
#if defined(linux) || defined(__FreeBSD__)
160
// #include <asm/byteorder.h>
162
#include <sys/types.h>
164
#if defined (__FreeBSD__)
165
#include <sys/endian.h>
183
#if __BYTE_ORDER == __LITTLE_ENDIAN
185
#define __be64_to_cpu(x) ___my_swab64(x)
186
#define __be32_to_cpu(x) ___my_swab32(x)
187
#define __be16_to_cpu(x) ___my_swab16(x)
188
#define __cpu_to_be64(x) ___my_swab64(x)
189
#define __cpu_to_be32(x) ___my_swab32(x)
190
#define __cpu_to_be16(x) ___my_swab16(x)
191
#define __le64_to_cpu(x) (x)
192
#define __le32_to_cpu(x) (x)
193
#define __le16_to_cpu(x) (x)
194
#define __cpu_to_le64(x) (x)
195
#define __cpu_to_le32(x) (x)
196
#define __cpu_to_le16(x) (x)
198
#elif __BYTE_ORDER == __BIG_ENDIAN
200
#define __be64_to_cpu(x) (x)
201
#define __be32_to_cpu(x) (x)
202
#define __be16_to_cpu(x) (x)
203
#define __cpu_to_be64(x) (x)
204
#define __cpu_to_be32(x) (x)
205
#define __cpu_to_be16(x) (x)
206
#define __le64_to_cpu(x) ___my_swab64(x)
207
#define __le32_to_cpu(x) ___my_swab32(x)
208
#define __le16_to_cpu(x) ___my_swab16(x)
209
#define __cpu_to_le64(x) ___my_swab64(x)
210
#define __cpu_to_le32(x) ___my_swab32(x)
211
#define __cpu_to_le16(x) ___my_swab16(x)
213
#endif // __BYTE_ORDER
220
#if defined(__CYGWIN32__)
221
#include <asm/byteorder.h>
224
#define __be64_to_cpu(x) ___my_swab64(x)
225
#define __be32_to_cpu(x) ___my_swab32(x)
226
#define __be16_to_cpu(x) ___my_swab16(x)
227
#define __cpu_to_be64(x) ___my_swab64(x)
228
#define __cpu_to_be32(x) ___my_swab32(x)
229
#define __cpu_to_be16(x) ___my_swab16(x)
230
#define __le64_to_cpu(x) (x)
231
#define __le32_to_cpu(x) (x)
232
#define __le16_to_cpu(x) (x)
233
#define __cpu_to_le64(x) (x)
234
#define __cpu_to_le32(x) (x)
235
#define __cpu_to_le16(x) (x)
243
#include <Winsock2.h>
244
#include <winsock2.h>
248
#define __LITTLE_ENDIAN 1234
249
#define __BIG_ENDIAN 4321
250
#define __BYTE_ORDER __LITTLE_ENDIAN
252
#define __be64_to_cpu(x) ___my_swab64(x)
253
#define __be32_to_cpu(x) ___my_swab32(x)
254
#define __be16_to_cpu(x) ___my_swab16(x)
255
#define __cpu_to_be64(x) ___my_swab64(x)
256
#define __cpu_to_be32(x) ___my_swab32(x)
257
#define __cpu_to_be16(x) ___my_swab16(x)
258
#define __le64_to_cpu(x) (x)
259
#define __le32_to_cpu(x) (x)
260
#define __le16_to_cpu(x) (x)
261
#define __cpu_to_le64(x) (x)
262
#define __cpu_to_le32(x) (x)
263
#define __cpu_to_le16(x) (x)
266
#if defined(__MINGW32__) || defined(__MINGW64__)
268
#ifndef MFT_TOOLS_VARS
269
#define MFT_TOOLS_VARS
270
typedef uint8_t u_int8_t;
271
typedef uint16_t u_int16_t;
272
typedef uint32_t u_int32_t;
273
typedef uint64_t u_int64_t;
275
#include <string.h> // Get a define for strcasecmp
276
// #define usleep(x) Sleep((x + 999)/1000)
279
typedef unsigned __int8 u_int8_t;
280
typedef __int8 int8_t;
281
typedef unsigned __int16 u_int16_t;
282
typedef __int16 int16_t;
283
typedef unsigned __int32 u_int32_t;
284
typedef __int32 int32_t;
285
typedef unsigned __int64 u_int64_t;
286
typedef __int64 int64_t;
288
#define strcasecmp _stricmp
289
#define strtoll _strtoi64
290
#define strtoull _strtoui64
291
#define strdup _strdup
295
#ifndef __WIN__ // TBD : investigate crash on win
299
#define COMP_CDECL __cdecl
300
#define COMP_OPEN ::_open
301
#define COMP_CLOSE ::_close
302
#define COMP_READ ::_read
303
#define COMP_FSTAT ::_fstat
309
typedef struct _stat Stat;
311
#define PRIx64 "I64x"
312
#define PRIu64 "I64u"
315
static inline int pread(int fd, void *buf, int count, u_int64_t offset) {return -1;}
316
static inline int pwrite(int fd, const void *buf, int count, u_int64_t offset) {return -1;}
318
static inline int pread(int fd, void *buf, int count, u_int64_t offset) {return -1;}
319
static inline int pwrite(int fd, const void *buf, int count, u_int64_t offset) {return -1;}
325
#define COMP_OPEN ::open
326
#define COMP_CLOSE ::close
327
#define COMP_READ ::read
328
#define COMP_FSTAT ::fstat
330
typedef struct stat Stat;
332
#include <sys/time.h>
342
#if defined(__APPLE_CC__)
343
#include <architecture/byte_order.h>
345
#define __swab64(x) NXSwapLongLong(x)
346
#define __swab32(x) NXSwapLong(x)
347
#define __swab16(x) NXSwapShort(x)
348
#define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
349
#define __be32_to_cpu(x) NXSwapBigLongToHost(x)
350
#define __be16_to_cpu(x) NXSwapBigShortToHost(x)
351
#define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
352
#define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
353
#define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
354
#define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
355
#define __cpu_to_be32(x) NXSwapHostLongToBig(x)
356
#define __cpu_to_be16(x) NXSwapHostShortToBig(x)
357
#define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
358
#define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
359
#define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
361
#define __LITTLE_ENDIAN 1234
362
#define __BIG_ENDIAN 4321
363
#define __PDP_ENDIAN 3412
364
#define __BYTE_ORDER __BIG_ENDIAN
371
#if defined(__sparc__)
372
#include <sys/byteorder.h>
373
#include <sys/types.h>
376
#define __be64_to_cpu(x) (x)
377
#define __be32_to_cpu(x) (x)
378
#define __be16_to_cpu(x) (x)
379
#define __cpu_to_be64(x) (x)
380
#define __cpu_to_be32(x) (x)
381
#define __cpu_to_be16(x) (x)
382
#define __le64_to_cpu(x) ___my_swab64(x)
383
#define __le32_to_cpu(x) ___my_swab32(x)
384
#define __le16_to_cpu(x) ___my_swab16(x)
385
#define __cpu_to_le64(x) ___my_swab64(x)
386
#define __cpu_to_le32(x) ___my_swab32(x)
387
#define __cpu_to_le16(x) ___my_swab16(x)
389
typedef uint64_t u_int64_t;
390
typedef uint32_t u_int32_t;
391
typedef uint16_t u_int16_t;
392
typedef uint8_t u_int8_t;
396
// Convert BYTES - DWORDS with MEMCPY BE
397
#define BYTES_TO_DWORD_BE(dw_dest, byte_src) do { u_int32_t tmp;\
398
memcpy(&tmp, byte_src, 4);\
399
*(dw_dest) = __be32_to_cpu(tmp);\
402
#define DWORD_TO_BYTES_BE(bytes_dest, dw_src) do { u_int32_t tmp;\
403
tmp = __cpu_to_be32(*(dw_src));\
404
memcpy(bytes_dest, &tmp, 4);\
411
#if !defined(__WIN__) && defined(__cplusplus) && __GNUG__ < 3
415
#define __STDC_FORMAT_MACROS
416
#if !defined(__WIN__) && !defined(UEFI_BUILD)
417
#include <inttypes.h>
420
#ifdef __VMKERNEL_USER_WORLD__
421
#define ROOT_PATH "/opt/mellanox/"
423
#define ROOT_PATH "/"