2 * Copyright (c) 2005 SilverStorm Technologies. All rights reserved.
\r
4 * This software is available to you under the OpenIB.org BSD license
\r
7 * Redistribution and use in source and binary forms, with or
\r
8 * without modification, are permitted provided that the following
\r
9 * conditions are met:
\r
11 * - Redistributions of source code must retain the above
\r
12 * copyright notice, this list of conditions and the following
\r
15 * - Redistributions in binary form must reproduce the above
\r
16 * copyright notice, this list of conditions and the following
\r
17 * disclaimer in the documentation and/or other materials
\r
18 * provided with the distribution.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
\r
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
\r
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
\r
23 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
\r
24 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
\r
25 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
26 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
\r
32 #ifndef _VNIC_UTIL_H_
\r
33 #define _VNIC_UTIL_H_
\r
35 #include "vnic_debug.h"
\r
37 #define MAXU32 0xffffffff
\r
38 #define MAXU64 ((uint64_t)(~0))
\r
40 #define MODULE_NAME "VNIC"
\r
42 #define PTR64(what) ((uint64_t)(void * __ptr64)(what))
\r
44 #define CONV2JIFFIES(time) (((time) * HZ) / 100) /* source time is 100ths of a sec */
\r
45 #define CONV2USEC(time) ((time) * 10000) /* source time is 100ths of a sec */
\r
48 #define min(a,b) ((a)<(b)?(a):(b))
\r
51 #define hton16(x) _byteswap_ushort(x)
\r
52 #define hton32(x) _byteswap_ulong(x)
\r
53 #define hton64(x) _byteswap_uint64(x)
\r
55 #define ntoh16(x) hton16(x)
\r
56 #define ntoh32(x) hton32(x)
\r
57 #define ntoh64(x) hton64(x)
\r
59 #define IsPowerOf2(value) (((value) & ((value - 1))) == 0)
\r
60 /* round down to closest power of 2 value */
\r
62 #define SetMinPowerOf2(_val) ((_val) & ( 1 << RtlFindMostSignificantBit( (uint64_t)(_val) )))
\r
64 #define PRINT(level,x) VNIC_PRINT(level, x )
\r
66 #define PRINT_CONDITIONAL(level,x,condition) if (condition){PRINT( level, x)}
\r
69 #define IB_FSTATUS(functionName) \
\r
70 if( (ib_status != IB_SUCCESS) && \
\r
71 (ib_status != IB_PENDING) ) \
\r
72 VNIC_PRINT( g_vnic_dbg_lvl,("[%s]: %d\n", functionName,ib_status))
\r
75 #define IB_FSTATUS(functionName)
\r
78 #define IB_TEST_FSTATUS( functionName ) IB_FSTATUS( functionName ); \
\r
79 if ((ib_status != IB_SUCCESS) && (ib_status != IB_PENDING)) goto failure
\r
81 #endif /* _VNIC_UTIL_H_ */
\r