]> git.proxmox.com Git - mirror_ovs.git/blob - datapath-windows/ovsext/Util.h
datapath-windows: Add Geneve support
[mirror_ovs.git] / datapath-windows / ovsext / Util.h
1 /*
2 * Copyright (c) 2014 VMware, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __UTIL_H_
18 #define __UTIL_H_ 1
19
20 #define OVS_MEMORY_TAG 'TSVO'
21 #define OVS_FIX_SIZE_NBL_POOL_TAG 'FSVO'
22 #define OVS_VARIABLE_SIZE_NBL_POOL_TAG 'VSVO'
23 #define OVS_NBL_ONLY_POOL_TAG 'OSVO'
24 #define OVS_NET_BUFFER_POOL_TAG 'NSVO'
25 #define OVS_OTHER_POOL_TAG 'MSVO'
26 #define OVS_MDL_POOL_TAG 'BSVO'
27 #define OVS_DATAPATH_POOL_TAG 'DSVO'
28 #define OVS_EVENT_POOL_TAG 'ESVO'
29 #define OVS_FLOW_POOL_TAG 'LSVO'
30 #define OVS_VXLAN_POOL_TAG 'XSVO'
31 #define OVS_IPHELPER_POOL_TAG 'HSVO'
32 #define OVS_OID_POOL_TAG 'ASVO'
33 #define OVS_SWITCH_POOL_TAG 'SSVO'
34 #define OVS_USER_POOL_TAG 'USVO'
35 #define OVS_VPORT_POOL_TAG 'PSVO'
36 #define OVS_STT_POOL_TAG 'RSVO'
37 #define OVS_GRE_POOL_TAG 'GSVO'
38 #define OVS_TUNFLT_POOL_TAG 'WSVO'
39 #define OVS_RECIRC_POOL_TAG 'CSVO'
40 #define OVS_CT_POOL_TAG 'CTVO'
41 #define OVS_GENEVE_POOL_TAG 'GNVO'
42
43 VOID *OvsAllocateMemory(size_t size);
44 VOID *OvsAllocateMemoryWithTag(size_t size, ULONG tag);
45 VOID *OvsAllocateAlignedMemory(size_t size, UINT16 align);
46 VOID *OvsAllocateMemoryPerCpu(size_t size, size_t count, ULONG tag);
47 VOID OvsFreeMemory(VOID *ptr);
48 VOID OvsFreeMemoryWithTag(VOID *ptr, ULONG tag);
49 VOID OvsFreeAlignedMemory(VOID *ptr);
50
51 #define LIST_FORALL(_headPtr, _itemPtr) \
52 for (_itemPtr = (_headPtr)->Flink; \
53 _itemPtr != _headPtr; \
54 _itemPtr = (_itemPtr)->Flink)
55
56 #define LIST_FORALL_SAFE(_headPtr, _itemPtr, _nextPtr) \
57 for (_itemPtr = (_headPtr)->Flink, _nextPtr = (_itemPtr)->Flink; \
58 _itemPtr != _headPtr; \
59 _itemPtr = _nextPtr, _nextPtr = (_itemPtr)->Flink)
60
61 #define LIST_FORALL_REVERSE(_headPtr, _itemPtr) \
62 for (_itemPtr = (_headPtr)->Blink; \
63 _itemPtr != _headPtr; \
64 _itemPtr = (_itemPtr)->Blink)
65
66 #define LIST_FORALL_REVERSE_SAFE(_headPtr, _itemPtr, _nextPtr) \
67 for (_itemPtr = (_headPtr)->Blink, _nextPtr = (_itemPtr)->Blink; \
68 _itemPtr != _headPtr; \
69 _itemPtr = _nextPtr, _nextPtr = (_itemPtr)->Blink)
70
71 VOID OvsAppendList(PLIST_ENTRY dst, PLIST_ENTRY src);
72
73 #define MAX(_a, _b) ((_a) > (_b) ? (_a) : (_b))
74 #define MIN(_a, _b) ((_a) > (_b) ? (_b) : (_a))
75 #define ARRAY_SIZE(_x) ((sizeof(_x))/sizeof (_x)[0])
76 #define OVS_SWITCH_PORT_ID_INVALID (NDIS_SWITCH_PORT_ID)(-1)
77
78 #ifndef htons
79 #define htons(_x) _byteswap_ushort((USHORT)(_x))
80 #define ntohs(_x) _byteswap_ushort((USHORT)(_x))
81 #define htonl(_x) _byteswap_ulong((ULONG)(_x))
82 #define ntohl(_x) _byteswap_ulong((ULONG)(_x))
83 #endif
84
85 #define OVS_INIT_OBJECT_HEADER(_obj, _type, _revision, _size) \
86 { \
87 PNDIS_OBJECT_HEADER hdrp = _obj; \
88 hdrp->Type = _type; \
89 hdrp->Revision = _revision; \
90 hdrp->Size = _size; \
91 }
92
93
94 #define BIT16(_x) ((UINT16)0x1 << (_x))
95 #define BIT32(_x) ((UINT32)0x1 << (_x))
96
97 BOOLEAN OvsCompareString(PVOID string1, PVOID string2);
98
99 /*
100 * --------------------------------------------------------------------------
101 * OvsPerCpuDataInit --
102 * The function allocates necessary per-processor resources.
103 * --------------------------------------------------------------------------
104 */
105 NTSTATUS
106 OvsPerCpuDataInit();
107
108 /*
109 * --------------------------------------------------------------------------
110 * OvsPerCpuDataCleanup --
111 * The function frees all per-processor resources.
112 * --------------------------------------------------------------------------
113 */
114 VOID
115 OvsPerCpuDataCleanup();
116
117 static LARGE_INTEGER seed;
118
119 /*
120 *----------------------------------------------------------------------------
121 * SRand --
122 * This function sets the starting seed value for the pseudorandom number
123 * generator.
124 *----------------------------------------------------------------------------
125 */
126 static __inline
127 VOID SRand()
128 {
129 KeQuerySystemTime(&seed);
130 }
131
132 /*
133 *----------------------------------------------------------------------------
134 * Rand --
135 * This function generates a pseudorandom number between 0 to UINT_MAX.
136 *----------------------------------------------------------------------------
137 */
138 static __inline
139 UINT32 Rand()
140 {
141 return seed.LowPart *= 0x8088405 + 1;
142 }
143
144 #endif /* __UTIL_H_ */