xref: /titanic_52/usr/src/uts/common/inet/common.h (revision 1915be19b7a1f7c113b706bd54d6ca393e8d8107)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 /* Copyright (c) 1990 Mentat Inc. */
26 
27 #ifndef	_INET_COMMON_H
28 #define	_INET_COMMON_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * WARNING: This file contains implementation-specific constants, typedefs
34  *	    and macros which may change from release to release.
35  */
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 #include <sys/inttypes.h>
42 #include <sys/sysmacros.h>
43 #include <sys/mkdev.h>
44 
45 #define	A_CNT(arr)	(sizeof (arr) / sizeof (arr[0]))
46 #define	A_END(arr)	(&arr[A_CNT(arr)])
47 #define	A_LAST(arr)	(&arr[A_CNT(arr) - 1])
48 
49 #define	nilp(t)		((t *)0)
50 #define	nil(t)		((t)0)
51 #define	noop
52 
53 typedef	int	(*pfi_t)();
54 typedef	void	(*pfv_t)();
55 
56 #define	BE32_EQL(a, b)	(((uint8_t *)a)[0] == ((uint8_t *)b)[0] && \
57 	((uint8_t *)a)[1] == ((uint8_t *)b)[1] && \
58 	((uint8_t *)a)[2] == ((uint8_t *)b)[2] && \
59 	((uint8_t *)a)[3] == ((uint8_t *)b)[3])
60 #define	BE16_EQL(a, b)	(((uint8_t *)a)[0] == ((uint8_t *)b)[0] && \
61 	((uint8_t *)a)[1] == ((uint8_t *)b)[1])
62 #define	BE16_TO_U16(a)	((((uint16_t)((uint8_t *)a)[0] << 8) | \
63 	((uint16_t)((uint8_t *)a)[1])) & 0xFFFF)
64 #define	BE32_TO_U32(a)	((((uint32_t)((uint8_t *)a)[0]) << 24) | \
65 	(((uint32_t)((uint8_t *)a)[1]) << 16) | \
66 	(((uint32_t)((uint8_t *)a)[2]) << 8)  | \
67 	((uint32_t)((uint8_t *)a)[3]))
68 #define	U16_TO_BE16(u, a) ((((uint8_t *)a)[0] = (uint8_t)((u) >> 8)), \
69 	(((uint8_t *)a)[1] = (uint8_t)(u)))
70 #define	U32_TO_BE32(u, a) ((((uint8_t *)a)[0] = (uint8_t)((u) >> 24)), \
71 	(((uint8_t *)a)[1] = (uint8_t)((u) >> 16)), \
72 	(((uint8_t *)a)[2] = (uint8_t)((u) >> 8)), \
73 	(((uint8_t *)a)[3] = (uint8_t)(u)))
74 
75 /*
76  * Local Environment Definition, this may and should override the
77  * the default definitions above where the local environment differs.
78  */
79 #include <inet/led.h>
80 #include <sys/isa_defs.h>
81 
82 #ifdef	_BIG_ENDIAN
83 #define	ABE32_TO_U32(p)		(*((uint32_t *)p))
84 #define	ABE16_TO_U16(p)		(*((uint16_t *)p))
85 #define	U16_TO_ABE16(u, p)	(*((uint16_t *)p) = (u))
86 #define	U32_TO_ABE16(u, p)	U16_TO_ABE16(u, p)
87 #define	U32_TO_ABE32(u, p)	(*((uint32_t *)p) = (u))
88 #else
89 #define	ABE16_TO_U16(p)		BE16_TO_U16(p)
90 #define	ABE32_TO_U32(p)		BE32_TO_U32(p)
91 #define	U16_TO_ABE16(u, p)	U16_TO_BE16(u, p)
92 #define	U32_TO_ABE16(u, p)	U16_TO_ABE16(u, p)
93 #define	U32_TO_ABE32(u, p)	U32_TO_BE32(u, p)
94 #endif
95 
96 #define	INET_MIN_DEV		2	/* minimum minor device number */
97 
98 #ifdef _KERNEL
99 #include <sys/stream.h>
100 
101 extern void *inet_minor_create(char *, dev_t, dev_t, int);
102 extern void inet_minor_destroy(void *);
103 extern dev_t inet_minor_alloc(void *);
104 extern void inet_minor_free(void *, dev_t);
105 extern void inet_freemsg(mblk_t *);
106 
107 #endif	/* _KERNEL */
108 
109 #ifdef	__cplusplus
110 }
111 #endif
112 
113 #endif	/* _INET_COMMON_H */
114