xref: /titanic_44/usr/src/lib/libdlpi/common/libdlpi_impl.h (revision b9238976491622ad75a67ab0c12edf99e36212b9)
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  * Publicly available DLPI notification types. This list may change if
68  * new DLPI notification types are made public. See dlpi(7P).
69  *
70  */
71 #define	DLPI_NOTIFICATION_TYPES	(DL_NOTE_LINK_DOWN | DL_NOTE_LINK_UP | \
72 	DL_NOTE_PHYS_ADDR | DL_NOTE_SDU_SIZE | DL_NOTE_SPEED | \
73 	DL_NOTE_PROMISC_ON_PHYS | DL_NOTE_PROMISC_OFF_PHYS)
74 
75 /*
76  * Used in a mactype lookup table.
77  */
78 typedef struct dlpi_mactype_s {
79 	uint_t	dm_mactype;	/* DLPI/Private mactype */
80 	char 	*dm_desc;	/* Description of mactype */
81 } dlpi_mactype_t;
82 
83 /*
84  * Used to get the maximum DLPI message buffer size, in bytes.
85  */
86 typedef struct dlpi_primsz {
87 	t_uscalar_t	dp_prim;	/* store DLPI primitive */
88 	size_t		dp_primsz;
89 				/* max. message size, in bytes, for dp_prim */
90 } dlpi_primsz_t;
91 
92 /*
93  * Used to create DLPI message.
94  */
95 typedef struct dlpi_msg {
96 	union DL_primitives	*dlm_msg;
97 					/* store DLPI primitive message */
98 	size_t			dlm_msgsz;
99 					/* provide buffer size for dlm_msg */
100 } dlpi_msg_t;
101 
102 typedef struct dlpi_notifyent {
103 	uint_t			dln_notes;
104 					/* notification types registered */
105 	dlpi_notifyfunc_t	*dln_fnp;
106 					/* callback to call */
107 	void 			*arg;	/* argument to pass to callback */
108 	uint_t			dln_rm;	/* true if should be removed */
109 	struct dlpi_notifyent	*dln_next;
110 } dlpi_notifyent_t;
111 
112 /*
113  * Private libdlpi structure associated with each DLPI handle.
114  */
115 typedef struct dlpi_impl_s {
116 	int		dli_fd;		/* fd attached to stream */
117 	int		dli_timeout;	/* timeout for operations, in sec */
118 	char		dli_linkname[DLPI_LINKNAME_MAX];
119 					/* full linkname including PPA */
120 	char		dli_provider[DLPI_LINKNAME_MAX];
121 					/* only provider name */
122 	t_uscalar_t	dli_style;	/* style 1 or 2 */
123 	uint_t		dli_saplen;	/* bound SAP length */
124 	uint_t		dli_sap;	/* bound SAP value */
125 	boolean_t 	dli_sapbefore;	/* true if SAP precedes address */
126 	uint_t		dli_ppa;	/* physical point of attachment */
127 	uint_t		dli_mod_cnt;	/* number of modules to be pushed */
128 	uint_t		dli_mod_pushed;	/* number of modules pushed */
129 	char   		dli_modlist[DLPI_MODS_MAX][DLPI_LINKNAME_MAX];
130 					/* array of mods */
131 	uint_t		dli_mactype;	/* mac type */
132 	uint_t		dli_oflags;	/* flags set at open */
133 	uint_t		dli_note_processing;
134 					/* true if notification is being */
135 					/* processed */
136 	dlpi_notifyent_t *dli_notifylistp;
137 					/* list of registered notifications */
138 } dlpi_impl_t;
139 
140 #ifdef __cplusplus
141 }
142 #endif
143 
144 #endif /* _LIBDLPI_IMPL_H */
145