Debian Codegraph @

dat/include/dat2/dat_platform_specific.h

raw
1 /*
2 * Copyright (c) 2002-2006, Network Appliance, Inc. All rights reserved.
3 *
4 * This Software is licensed under all of the following licenses:
5 *
6 * 1) under the terms of the "Common Public License 1.0" a copy of which is
7 * in the file LICENSE.txt in the root directory. The license is also
8 * available from the Open Source Initiative, see
9 * http://www.opensource.org/licenses/cpl.php.
10 *
11 * 2) under the terms of the "The BSD License" a copy of which is in the file
12 * LICENSE2.txt in the root directory. The license is also available from
13 * the Open Source Initiative, see
14 * http://www.opensource.org/licenses/bsd-license.php.
15 *
16 * 3) under the terms of the "GNU General Public License (GPL) Version 2" a
17 * copy of which is in the file LICENSE3.txt in the root directory. The
18 * license is also available from the Open Source Initiative, see
19 * http://www.opensource.org/licenses/gpl-license.php.
20 *
21 * Licensee has the right to choose one of the above licenses.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions are
25 * met:
26 *
27 * Redistributions of source code must retain both the above copyright
28 * notice and one of the license notices.
29 *
30 * Redistributions in binary form must reproduce both the above copyright
31 * notice, one of the license notices in the documentation
32 * and/or other materials provided with the distribution.
33 *
34 * Neither the name of Network Appliance, Inc. nor the names of other DAT
35 * Collaborative contributors may be used to endorse or promote
36 * products derived from this software without specific prior written
37 * permission.
38 */
39
40 /***************************************************************
41 *
42 * HEADER: dat_platform_specific.h
43 *
44 * PURPOSE: defines Platform-specific types.
45 *
46 * Description: Header file for "DAPL: Direct Access Programming
47 * Library, Version: 2.0"
48 *
49 * Mapping rules:
50 *
51 ***************************************************************/
52
53 #ifndef _DAT_PLATFORM_SPECIFIC_H_
54 #define _DAT_PLATFORM_SPECIFIC_H_
55
56 /* OS, processor, compiler type definitions. Add OSes as needed. */
57
58 /*
59 * This captures the alignment for the bus transfer from the HCA/IB chip
60 * to the main memory.
61 */
62 #ifndef DAT_OPTIMAL_ALIGNMENT
63 #define DAT_OPTIMAL_ALIGNMENT 256 /* Performance optimal alignment */
64 #endif /* DAT_OPTIMAL_ALIGNMENT */
65
66 /* Assume all OSes use sockaddr, for address family: IPv4 == AF_INET,
67 * IPv6 == AF_INET6. Use of "namelen" field indicated.
68 *
69 * The Interface Adapter Address names an Interface Adapter local or
70 * remote, that is used for connection management and Name
71 * Service. The format of the dat_ia_address_ptr follows the normal
72 * socket programming practice of struct sockaddr *. DAT supports both
73 * IPv4 and IPv6 address families. Allocation and initialization of
74 * DAT IA address structures must follow normal Sockets programming
75 * procedures. The underlying type of the DAT IA address is the native
76 * struct sockaddr for each target operating system. In all cases,
77 * storage appropriate for the address family in use by the target
78 * Provider must be allocated. For instance, when IPv6 addressing is
79 * in use, this should be allocated as struct sockaddr_net6. The
80 * sockaddr sa_family and, if present, sa_len fields must be
81 * initialized appropriately, as well as the address information.
82 * When passed across the DAPL API this storage is cast to the
83 * DAT_IA_ADDRESS_PTR type. It is the responsibility of the callee to
84 * verify that the sockaddr contains valid data for the requested
85 * operation. It is always the responsibility of the caller to manage
86 * the storage.
87 *
88 * uDAPL code example for Linux (kdapl would be similar):
89 *
90 * #include <stdio.h>
91 * #include <sys/socket.h>
92 * #include <netinet/in.h>
93 * #include <dat2/udat.h>
94 *
95 * struct sockaddr_in6 addr;
96 * DAT_IA_ADDRESS_PTR ia_addr;
97 *
98 * // Note: linux pton requires explicit encoding of IPv4 in IPv6
99 *
100 * addr.sin6_family = AF_INET6;
101 * if (inet_pton(AF_INET6, "0:0:0:0:0:FFFF:192.168.0.1",
102 * &addr.sin6_addr) <= 0)
103 * return(-1); // Bad address or no address family support
104 *
105 * // initialize other necessary fields such as port, flow, etc
106 *
107 * ia_addr = (DAT_IA_ADDRESS_PTR) &addr;
108 * dat_ep_connect(ep_handle, ia_addr, conn_qual, timeout, 0, NULL,
109 * qos, DAT_CONNECT_DEFAULT_FLAG);
110 *
111 */
112
113 /* Solaris begins */
114 #if defined (sun) || defined(__sun) || defined(_sun_) || defined (__solaris__)
115
116 #include <sys/types.h>
117 #include <inttypes.h> /* needed for UINT64_C() macro */
118
119 typedef uint32_t DAT_UINT32; /* Unsigned host order, 32 bits */
120 typedef uint64_t DAT_UINT64; /* unsigned host order, 64 bits */
121 typedef unsigned long long DAT_UVERYLONG; /* unsigned longest native to compiler */
122
123 typedef void * DAT_PVOID;
124 typedef int DAT_COUNT;
125
126 #define DAT_IA_HANDLE_TO_UL(a) (unsigned long)(a)
127 #define DAT_UL_TO_IA_HANDLE(a) (DAT_IA_HANDLE)(a)
128
129 #include <sys/socket.h>
130 #include <netinet/in.h>
131 typedef struct sockaddr DAT_SOCK_ADDR; /* Socket address header native to OS */
132 typedef struct sockaddr_in6 DAT_SOCK_ADDR6; /* Socket address header native to OS */
133
134 #define DAT_AF_INET AF_INET
135 #define DAT_AF_INET6 AF_INET6
136
137 typedef DAT_UINT64 DAT_PADDR;
138
139 #define DAT_API
140 #define DAT_EXPORT extern
141
142 /* Solaris ends */
143
144
145 /* Linux begins */
146 #elif defined(__linux__) /* Linux */
147 #if defined(__KERNEL__)
148 #include <linux/types.h>
149 #else
150 #include <sys/types.h>
151 #include <stddef.h>
152 #include <stdio.h>
153 #endif /* defined(__KERNEL__) */
154
155 typedef u_int32_t DAT_UINT32; /* unsigned host order, 32 bits */
156 typedef u_int64_t DAT_UINT64; /* unsigned host order, 64 bits */
157 typedef unsigned long long DAT_UVERYLONG; /* unsigned longest native to compiler */
158
159 typedef void * DAT_PVOID;
160 typedef int DAT_COUNT;
161 typedef DAT_UINT64 DAT_PADDR;
162
163 #ifndef UINT64_C
164 #define UINT64_C(c) c ## ULL
165 #endif /* UINT64_C */
166
167 #define DAT_IA_HANDLE_TO_UL(a) (unsigned long)(a)
168 #define DAT_UL_TO_IA_HANDLE(a) (DAT_IA_HANDLE)(a)
169
170 #if defined(__KERNEL__)
171 #include <linux/socket.h>
172 #include <linux/in.h>
173 #include <linux/in6.h>
174 #else
175 #include <sys/socket.h>
176 #endif /* defined(__KERNEL__) */
177
178 typedef struct dat_comm {
179 int domain;
180 int type;
181 int protocol;
182 } DAT_COMM;
183
184 typedef int DAT_FD; /* DAT File Descriptor */
185
186 typedef struct sockaddr DAT_SOCK_ADDR; /* Socket address header native to OS */
187 typedef struct sockaddr_in6 DAT_SOCK_ADDR6; /* Socket address header native to OS */
188 #define DAT_AF_INET AF_INET
189 #define DAT_AF_INET6 AF_INET6
190
191 #define DAT_API
192 #define DAT_EXPORT extern
193
194 /* Linux ends */
195
196 /* Win32/64 begins */
197 #elif defined(_MSC_VER) || defined(_WIN32) || defined(_WIN64)
198 /* NT. MSC compiler, Win32/64 platform */
199
200 #include <winsock2.h>
201 #include <ws2tcpip.h>
202
203 typedef unsigned __int32 DAT_UINT32; /* Unsigned host order, 32 bits */
204 typedef unsigned __int64 DAT_UINT64; /* unsigned host order, 64 bits */
205 typedef unsigned long DAT_UVERYLONG; /* unsigned longest native to compiler */
206
207 #if defined(_WIN64)
208 #define DAT_IA_HANDLE_TO_UL(a) (unsigned long)((DAT_UINT64)(a))
209 #define DAT_UL_TO_IA_HANDLE(a) (DAT_IA_HANDLE)((DAT_UINT64)(a))
210 #else // _WIN32
211 #define DAT_IA_HANDLE_TO_UL(a) (unsigned long)(a)
212 #define DAT_UL_TO_IA_HANDLE(a) (DAT_IA_HANDLE)(a)
213 #endif
214
215 typedef void * DAT_PVOID;
216 typedef int DAT_COUNT;
217 typedef DAT_UINT64 DAT_PADDR;
218
219 typedef struct dat_comm {
220 int domain;
221 int type;
222 int protocol;
223 } DAT_COMM;
224
225 typedef int DAT_FD; /* DAT File Descriptor */
226
227 typedef struct sockaddr DAT_SOCK_ADDR; /* Sock addr header native to OS */
228 typedef struct sockaddr_in6 DAT_SOCK_ADDR6;/* Sock addr header native to OS */
229
230 #ifndef UINT64_C
231 #define UINT64_C(c) c ## i64
232 #endif /* UINT64_C */
233
234 #define DAT_AF_INET AF_INET
235 #define DAT_AF_INET6 AF_INET6
236
237 #if defined(EXPORT_DAT_SYMBOLS)
238 #define DAT_EXPORT __declspec(dllexport)
239 #else
240 #define DAT_EXPORT __declspec(dllimport)
241 #endif
242
243 #define DAT_API __stdcall
244
245 #ifndef __inline__
246 #define __inline__ __inline
247 #endif
248
249 #ifndef INLINE
250 #define INLINE __inline
251 #endif
252
253 #if defined(__KDAPL__)
254 /* must have the DDK for this definition */
255 typedef PHYSICAL_ADDRESS DAT_PADDR;
256 #endif /* __KDAPL__ */
257
258 /* Windoze ends */
259
260
261 #else
262 #error dat_platform_specific.h : OS type not defined
263 #endif
264
265 #ifndef IN
266 #define IN
267 #endif
268 #ifndef OUT
269 #define OUT
270 #endif
271 #ifndef INOUT
272 #define INOUT
273 #endif
274
275 #endif /* _DAT_PLATFORM_SPECIFIC_H_ */