xref: /illumos-gate/usr/src/lib/udapl/libdat/include/dat/dat_platform_specific.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
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 /*
35  *
36  * HEADER: dat_platform_specific.h
37  *
38  * PURPOSE: defines Platform specific types.
39  *
40  * Description: Header file for "uDAPL: User Direct Access Programming
41  *		Library, Version: 1.2"
42  *
43  * Mapping rules:
44  *
45  */
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /* OS, processor, compiler type definitions. Add OS's as needed. */
52 
53 /*
54  * This captures the alignment for the bus transfer from the HCA/IB chip
55  * to the main memory.
56  */
57 #ifndef DAT_OPTIMAL_ALIGNMENT
58 #define	DAT_OPTIMAL_ALIGNMENT   256	/* Performance optimal alignment */
59 #endif /* DAT_OPTIMAL_ALIGNMENT */
60 
61 /*
62  * Assume all O/Ss use sockaddr, for address family: IPv4 == AF_INET,
63  * IPv6 == AF_INET6. Use of "namelen" field indicated.
64  *
65  * The Interface Adaptor Address names an Interface Adaptor local or
66  * remote, that is used for connection management and Name
67  * Service. The format of the dat_ia_address_ptr follows the normal
68  * socket programming practice of struct sockaddr *. DAT supports both
69  * IPv4 and IPv6 address families.  Allocation and initialization of
70  * DAT IA address structures must follow normal Sockets programming
71  * procedures. The underlying type of the DAT IA address is the native
72  * struct sockaddr for each target operating system. In all cases,
73  * storage appropriate for the address family in use by the target
74  * Provider must be allocated.  For instance, when IPv6 addressing is
75  * in use, this should be allocated as struct sockaddr_net6. The
76  * sockaddr sa_family and, if present, sa_len fields must be
77  * initialized appropriately, as well as the address information.
78  * When passed across the DAPL API this storage is cast to the
79  * DAT_IA_ADDRESS_PTR type. It is the responsibility of the callee to
80  * verify that the sockaddr contains valid data for the requested
81  * operation. It is always the responsibility of the caller to manage
82  * the storage.
83  *
84  * Code example for Linux:
85  *
86  * #include <stdio.h>
87  * #include <sys/socket.h>
88  * #include <netinet/in.h>
89  * #include <dat/udat.h>
90  *
91  *  struct sockaddr_in6 addr;
92  *  DAT_IA_ADDRESS_PTR ia_addr;
93  *
94  *	// Note: linux pton requires explicit encoding of IPv4 in IPv6
95  *
96  *	addr.sin6_family = AF_INET6;
97  *	if (inet_pton(AF_INET6, "0:0:0:0:0:FFFF:192.168.0.1",
98  *		      &addr.sin6_addr) <= 0)
99  *	  return(-1); // Bad address or no address family support
100  *
101  *	// initialize other necessary fields such as port, flow, etc
102  *
103  *	ia_addr = (DAT_IA_ADDRESS_PTR) &addr;
104  *	dat_ep_connect(ep_handle, ia_addr, conn_qual, timeout, 0, NULL,
105  *		       qos, DAT_CONNECT_DEFAULT_FLAG);
106  *
107  */
108 
109 #if defined(sun) || defined(__sun) || defined(_sun_) || defined(__solaris__)
110 /* Solaris begins */
111 
112 #include <sys/types.h>
113 #include <inttypes.h>		/* needed for UINT64_C() macro */
114 
115 typedef uint32_t		DAT_UINT32; /* Unsigned host order, 32 bits */
116 typedef uint64_t		DAT_UINT64; /* Unsigned host order, 64 bits */
117 typedef unsigned long long	DAT_UVERYLONG;  /* Unsigned longest native  */
118 						/* to compiler		    */
119 
120 typedef void			*DAT_PVOID;
121 typedef int			DAT_COUNT;
122 
123 #include <sys/socket.h>
124 #include <netinet/in.h>
125 typedef struct sockaddr		DAT_SOCK_ADDR;	/* Socket address header */
126 						/* native to OS */
127 typedef struct sockaddr_in6	DAT_SOCK_ADDR6; /* Socket address header */
128 						/* native to OS */
129 
130 #define	DAT_AF_INET		AF_INET
131 #define	DAT_AF_INET6		AF_INET6
132 
133 typedef	DAT_UINT64		DAT_PADDR;
134 
135 /* Solaris ends */
136 
137 #elif defined(__linux__) /* Linux */
138 /* Linux begins */
139 
140 #include <sys/types.h>
141 
142 typedef u_int32_t	DAT_UINT32;	/* unsigned host order, 32 bits */
143 typedef u_int64_t	DAT_UINT64;	/* unsigned host order, 64 bits */
144 typedef unsigned long long	DAT_UVERYLONG;  /* unsigned longest native */
145 						/* to compiler		   */
146 
147 typedef void			*DAT_PVOID;
148 typedef int			DAT_COUNT;
149 typedef	DAT_UINT64		DAT_PADDR;
150 
151 #ifndef	UINT64_C
152 #define	UINT64_C(c)		c ## ULL
153 #endif	/* UINT64_C */
154 
155 #include <sys/socket.h>
156 typedef struct sockaddr		DAT_SOCK_ADDR;  /* Socket address header */
157 						/* native to OS		 */
158 typedef struct sockaddr_in6	DAT_SOCK_ADDR6; /* Socket address header */
159 						/* native to OS		 */
160 
161 #define	DAT_AF_INET		AF_INET
162 #define	DAT_AF_INET6		AF_INET6
163 
164 /* Linux ends */
165 
166 #elif defined(_MSC_VER) || defined(_WIN32)
167 /* NT. MSC compiler, Win32 platform */
168 /* Win32 begins */
169 
170 typedef unsigned __int32	DAT_UINT32; /* Unsigned host order, 32 bits */
171 typedef unsigned __int64	DAT_UINT64; /* Unsigned host order, 64 bits */
172 typedef unsigned  long		DAT_UVERYLONG;	/* Unsigned longest native to */
173 						/* compiler	*/
174 
175 typedef void			*DAT_PVOID;
176 typedef long			DAT_COUNT;
177 
178 typedef struct sockaddr		DAT_SOCK_ADDR;  /* Socket address header */
179 						/* native to OS */
180 typedef struct sockaddr_in6	DAT_SOCK_ADDR6; /* Socket address header */
181 						/* native to OS */
182 #ifndef	UINT64_C
183 #define	UINT64_C(c)		c ## i64
184 #endif	/* UINT64_C */
185 
186 #define	DAT_AF_INET		AF_INET
187 #define	DAT_AF_INET6		AF_INET6
188 
189 /* Win32 ends */
190 
191 #else
192 #error	dat_platform_specific.h : OS type not defined
193 #endif
194 
195 #ifndef IN
196 #define	IN
197 #endif
198 #ifndef OUT
199 #define	OUT
200 #endif
201 #ifndef INOUT
202 #define	INOUT
203 #endif
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 #endif /* _DAT_PLATFORM_SPECIFIC_H_ */
210