xref: /titanic_44/usr/src/uts/common/inet/common.h (revision bc9ec910d60a3256c0b6bb68a13afa62e106730a)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /* Copyright (c) 1990 Mentat Inc. */
27 
28 #ifndef	_INET_COMMON_H
29 #define	_INET_COMMON_H
30 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 /*
34  * WARNING: This file contains implementation-specific constants, typedefs
35  *	    and macros which may change from release to release.
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #include <sys/inttypes.h>
43 #include <sys/sysmacros.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 #define	INET_MAXMINOR		MAXMIN	/* maximum device minor number */
98 
99 #ifdef _KERNEL
100 #include <sys/stream.h>
101 
102 extern void *inet_minor_create(char *, dev_t, int);
103 extern void inet_minor_destroy(void *);
104 extern dev_t inet_minor_alloc(void *);
105 extern void inet_minor_free(void *, dev_t);
106 extern void inet_freemsg(mblk_t *);
107 
108 #endif	/* _KERNEL */
109 
110 #ifdef	__cplusplus
111 }
112 #endif
113 
114 #endif	/* _INET_COMMON_H */
115