1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2002-2004, Network Appliance, Inc. All rights reserved.
24  */
25 
26 /*
27  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  */
30 
31 #ifndef _DAT_PLATFORM_SPECIFIC_H_
32 #define	_DAT_PLATFORM_SPECIFIC_H_
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 /*
37  *
38  * HEADER: dat_platform_specific.h
39  *
40  * PURPOSE: defines Platform specific types.
41  *
42  * Description: Header file for "uDAPL: User Direct Access Programming
43  *		Library, Version: 1.2"
44  *
45  * Mapping rules:
46  *
47  */
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 /* OS, processor, compiler type definitions. Add OS's as needed. */
54 
55 /*
56  * This captures the alignment for the bus transfer from the HCA/IB chip
57  * to the main memory.
58  */
59 #ifndef DAT_OPTIMAL_ALIGNMENT
60 #define	DAT_OPTIMAL_ALIGNMENT   256	/* Performance optimal alignment */
61 #endif /* DAT_OPTIMAL_ALIGNMENT */
62 
63 /*
64  * Assume all O/Ss use sockaddr, for address family: IPv4 == AF_INET,
65  * IPv6 == AF_INET6. Use of "namelen" field indicated.
66  *
67  * The Interface Adaptor Address names an Interface Adaptor local or
68  * remote, that is used for connection management and Name
69  * Service. The format of the dat_ia_address_ptr follows the normal
70  * socket programming practice of struct sockaddr *. DAT supports both
71  * IPv4 and IPv6 address families.  Allocation and initialization of
72  * DAT IA address structures must follow normal Sockets programming
73  * procedures. The underlying type of the DAT IA address is the native
74  * struct sockaddr for each target operating system. In all cases,
75  * storage appropriate for the address family in use by the target
76  * Provider must be allocated.  For instance, when IPv6 addressing is
77  * in use, this should be allocated as struct sockaddr_net6. The
78  * sockaddr sa_family and, if present, sa_len fields must be
79  * initialized appropriately, as well as the address information.
80  * When passed across the DAPL API this storage is cast to the
81  * DAT_IA_ADDRESS_PTR type. It is the responsibility of the callee to
82  * verify that the sockaddr contains valid data for the requested
83  * operation. It is always the responsibility of the caller to manage
84  * the storage.
85  *
86  * Code example for Linux:
87  *
88  * #include <stdio.h>
89  * #include <sys/socket.h>
90  * #include <netinet/in.h>
91  * #include <dat/udat.h>
92  *
93  *  struct sockaddr_in6 addr;
94  *  DAT_IA_ADDRESS_PTR ia_addr;
95  *
96  *	// Note: linux pton requires explicit encoding of IPv4 in IPv6
97  *
98  *	addr.sin6_family = AF_INET6;
99  *	if (inet_pton(AF_INET6, "0:0:0:0:0:FFFF:192.168.0.1",
100  *		      &addr.sin6_addr) <= 0)
101  *	  return(-1); // Bad address or no address family support
102  *
103  *	// initialize other necessary fields such as port, flow, etc
104  *
105  *	ia_addr = (DAT_IA_ADDRESS_PTR) &addr;
106  *	dat_ep_connect(ep_handle, ia_addr, conn_qual, timeout, 0, NULL,
107  *		       qos, DAT_CONNECT_DEFAULT_FLAG);
108  *
109  */
110 
111 #if defined(sun) || defined(__sun) || defined(_sun_) || defined(__solaris__)
112 /* Solaris begins */
113 
114 #include <sys/types.h>
115 #include <inttypes.h>		/* needed for UINT64_C() macro */
116 
117 typedef uint32_t		DAT_UINT32; /* Unsigned host order, 32 bits */
118 typedef uint64_t		DAT_UINT64; /* Unsigned host order, 64 bits */
119 typedef unsigned long long	DAT_UVERYLONG;  /* Unsigned longest native  */
120 						/* to compiler		    */
121 
122 typedef void			*DAT_PVOID;
123 typedef int			DAT_COUNT;
124 
125 #include <sys/socket.h>
126 #include <netinet/in.h>
127 typedef struct sockaddr		DAT_SOCK_ADDR;	/* Socket address header */
128 						/* native to OS */
129 typedef struct sockaddr_in6	DAT_SOCK_ADDR6; /* Socket address header */
130 						/* native to OS */
131 
132 #define	DAT_AF_INET		AF_INET
133 #define	DAT_AF_INET6		AF_INET6
134 
135 typedef	DAT_UINT64		DAT_PADDR;
136 
137 /* Solaris ends */
138 
139 #elif defined(__linux__) /* Linux */
140 /* Linux begins */
141 
142 #include <sys/types.h>
143 
144 typedef u_int32_t	DAT_UINT32;	/* unsigned host order, 32 bits */
145 typedef u_int64_t	DAT_UINT64;	/* unsigned host order, 64 bits */
146 typedef unsigned long long	DAT_UVERYLONG;  /* unsigned longest native */
147 						/* to compiler		   */
148 
149 typedef void			*DAT_PVOID;
150 typedef int			DAT_COUNT;
151 typedef	DAT_UINT64		DAT_PADDR;
152 
153 #ifndef	UINT64_C
154 #define	UINT64_C(c)		c ## ULL
155 #endif	/* UINT64_C */
156 
157 #include <sys/socket.h>
158 typedef struct sockaddr		DAT_SOCK_ADDR;  /* Socket address header */
159 						/* native to OS		 */
160 typedef struct sockaddr_in6	DAT_SOCK_ADDR6; /* Socket address header */
161 						/* native to OS		 */
162 
163 #define	DAT_AF_INET		AF_INET
164 #define	DAT_AF_INET6		AF_INET6
165 
166 /* Linux ends */
167 
168 #elif defined(_MSC_VER) || defined(_WIN32)
169 /* NT. MSC compiler, Win32 platform */
170 /* Win32 begins */
171 
172 typedef unsigned __int32	DAT_UINT32; /* Unsigned host order, 32 bits */
173 typedef unsigned __int64	DAT_UINT64; /* Unsigned host order, 64 bits */
174 typedef unsigned  long		DAT_UVERYLONG;	/* Unsigned longest native to */
175 						/* compiler	*/
176 
177 typedef void			*DAT_PVOID;
178 typedef long			DAT_COUNT;
179 
180 typedef struct sockaddr		DAT_SOCK_ADDR;  /* Socket address header */
181 						/* native to OS */
182 typedef struct sockaddr_in6	DAT_SOCK_ADDR6; /* Socket address header */
183 						/* native to OS */
184 #ifndef	UINT64_C
185 #define	UINT64_C(c)		c ## i64
186 #endif	/* UINT64_C */
187 
188 #define	DAT_AF_INET		AF_INET
189 #define	DAT_AF_INET6		AF_INET6
190 
191 /* Win32 ends */
192 
193 #else
194 #error	dat_platform_specific.h : OS type not defined
195 #endif
196 
197 #ifndef IN
198 #define	IN
199 #endif
200 #ifndef OUT
201 #define	OUT
202 #endif
203 #ifndef INOUT
204 #define	INOUT
205 #endif
206 
207 #ifdef __cplusplus
208 }
209 #endif
210 
211 #endif /* _DAT_PLATFORM_SPECIFIC_H_ */
212