xref: /titanic_52/usr/src/lib/libdlpi/common/libdlpi_impl.h (revision a99982a76d4cc12b1e9021e88531cf425d1e7369)
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 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_LIBDLPI_IMPL_H
27 #define	_LIBDLPI_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <libdlpi.h>
32 #include <sys/sysmacros.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Maximum DLPI response size, in bytes.
40  */
41 #define	DLPI_CHUNKSIZE	8192
42 
43 /*
44  * Maximum SAP length, in bytes.
45  */
46 #define	DLPI_SAPLEN_MAX	4
47 
48 /*
49  * Maximum number of modules that can be pushed onto a device stream.
50  */
51 #define	DLPI_MODS_MAX	9
52 
53 /*
54  * Number of elements in 'arr'.
55  */
56 #define	NELEMS(arr)	(sizeof (arr) / sizeof ((arr)[0]))
57 
58 /*
59  * Allocate buffer size for DLPI message, in bytes and set DLPI primitive.
60  */
61 #define	DLPI_MSG_CREATE(dlmsg, dlprimitive) \
62 	(dlmsg).dlm_msgsz = i_dlpi_getprimsize((dlprimitive)); \
63 	(dlmsg).dlm_msg = alloca((dlmsg).dlm_msgsz); \
64 	(dlmsg).dlm_msg->dl_primitive = (dlprimitive);
65 
66 /*
67  * Used in a mactype lookup table.
68  */
69 typedef struct dlpi_mactype_s {
70 	uint_t	dm_mactype;	/* DLPI/Private mactype */
71 	char 	*dm_desc;	/* Description of mactype */
72 } dlpi_mactype_t;
73 
74 /*
75  * Used to get the maximum DLPI message buffer size, in bytes.
76  */
77 typedef struct dlpi_primsz {
78 	t_uscalar_t	dp_prim;	/* store DLPI primitive */
79 	size_t		dp_primsz;
80 				/* max. message size, in bytes, for dp_prim */
81 } dlpi_primsz_t;
82 
83 /*
84  * Used to create DLPI message.
85  */
86 typedef struct dlpi_msg {
87 	union DL_primitives	*dlm_msg;
88 					/* store DLPI primitive message */
89 	size_t			dlm_msgsz;
90 					/* provide buffer size for dlm_msg */
91 } dlpi_msg_t;
92 
93 /*
94  * Private libdlpi structure associated with each DLPI handle.
95  */
96 typedef struct dlpi_impl_s {
97 	int		dli_fd;		/* fd attached to stream */
98 	int		dli_timeout;	/* timeout for operations, in sec */
99 	char		dli_linkname[DLPI_LINKNAME_MAX];
100 					/* full linkname including PPA */
101 	char		dli_provider[DLPI_LINKNAME_MAX];
102 					/* only provider name */
103 	t_uscalar_t	dli_style;	/* style 1 or 2 */
104 	uint_t		dli_saplen;	/* bound SAP length */
105 	uint_t		dli_sap;	/* bound SAP value */
106 	boolean_t 	dli_sapbefore;	/* true if SAP precedes address */
107 	uint_t		dli_ppa;	/* physical point of attachment */
108 	uint_t		dli_mod_cnt;	/* number of modules to be pushed */
109 	uint_t		dli_mod_pushed;	/* number of modules pushed */
110 	char   		dli_modlist[DLPI_MODS_MAX][DLPI_LINKNAME_MAX];
111 					/* array of mods */
112 	uint_t		dli_mactype;	/* mac type */
113 	uint_t		dli_oflags;	/* flags set at open */
114 } dlpi_impl_t;
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 #endif /* _LIBDLPI_IMPL_H */
121