xref: /titanic_44/usr/src/lib/libdlpi/common/libdlpi.h (revision 98157a7002f4f2cf7978f3084ca5577f0a1d72b2)
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 
26 #ifndef _LIBDLPI_H
27 #define	_LIBDLPI_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 #include <sys/dlpi.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Maximum Physical (hardware) address length, in bytes.
40  * Must be as large as MAXMACADDRLEN (see <sys/mac.h>).
41  */
42 #define	DLPI_PHYSADDR_MAX	64
43 
44 /*
45  * Maximum link name length, including terminating NUL, in bytes.
46  * Must be no larger than MAXLINKNAMELEN (see <sys/param.h>).
47  */
48 #define	DLPI_LINKNAME_MAX	32
49 
50 /*
51  * Constant used to indicate bind to any SAP value
52  */
53 #define	DLPI_ANY_SAP	(uint_t)-1
54 
55 /*
56  * Flag values for dlpi_open(); those not documented in dlpi_open(3DLPI)
57  * are Consolidation Private and subject to change or removal.
58  */
59 #define	DLPI_EXCL	0x0001	/* Exclusive open */
60 #define	DLPI_PASSIVE	0x0002	/* Open DLPI link in passive mode */
61 #define	DLPI_RAW	0x0004	/* Open DLPI link in raw mode */
62 #define	DLPI_SERIAL	0x0008	/* Synchronous serial line interface */
63 #define	DLPI_NOATTACH	0x0010	/* Do not attach PPA */
64 #define	DLPI_NATIVE	0x0020	/* Open DLPI link in native mode */
65 #define	DLPI_DEVONLY	0x0040	/* Open DLPI link under /dev only */
66 
67 /*
68  * Timeout to be used in DLPI-related operations, in seconds.
69  */
70 #define	DLPI_DEF_TIMEOUT  5
71 
72 /*
73  * Since this library returns error codes defined in either <sys/dlpi.h> or
74  * <libdlpi.h>, libdlpi specific error codes will start at value 10000 to
75  * avoid overlap. DLPI_SUCCESS cannot be 0 because 0 is already DL_BADSAP in
76  * <sys/dlpi.h>.
77  */
78 enum {
79 	DLPI_SUCCESS = 10000,	/* DLPI operation succeeded */
80 	DLPI_EINVAL,		/* invalid argument */
81 	DLPI_ELINKNAMEINVAL,	/* invalid DLPI linkname */
82 	DLPI_ENOLINK,		/* DLPI link does not exist */
83 	DLPI_EBADLINK,		/* bad DLPI link */
84 	DLPI_EINHANDLE,		/* invalid DLPI handle */
85 	DLPI_ETIMEDOUT,		/* DLPI operation timed out */
86 	DLPI_EVERNOTSUP,	/* unsupported DLPI Version */
87 	DLPI_EMODENOTSUP,	/* unsupported DLPI connection mode */
88 	DLPI_EUNAVAILSAP,	/* unavailable DLPI SAP */
89 	DLPI_FAILURE,		/* DLPI operation failed */
90 	DLPI_ENOTSTYLE2,	/* DLPI style-2 node reports style-1 */
91 	DLPI_EBADMSG,		/* bad DLPI message */
92 	DLPI_ERAWNOTSUP,	/* DLPI raw mode not supported */
93 	DLPI_ENOTEINVAL,	/* invalid DLPI notification type */
94 	DLPI_ENOTENOTSUP,	/* DLPI notification not supported by link */
95 	DLPI_ENOTEIDINVAL,	/* invalid DLPI notification id */
96 	DLPI_ERRMAX		/* Highest + 1 libdlpi error code */
97 };
98 
99 /*
100  * DLPI information; see dlpi_info(3DLPI).
101  */
102 typedef struct {
103 	uint_t			di_opts;
104 	uint_t			di_max_sdu;
105 	uint_t			di_min_sdu;
106 	uint_t			di_state;
107 	uint_t			di_mactype;
108 	char			di_linkname[DLPI_LINKNAME_MAX];
109 	uchar_t			di_physaddr[DLPI_PHYSADDR_MAX];
110 	uchar_t			di_physaddrlen;
111 	uchar_t			di_bcastaddr[DLPI_PHYSADDR_MAX];
112 	uchar_t			di_bcastaddrlen;
113 	uint_t			di_sap;
114 	int			di_timeout;
115 	dl_qos_cl_sel1_t	di_qos_sel;
116 	dl_qos_cl_range1_t 	di_qos_range;
117 } dlpi_info_t;
118 
119 /*
120  * DLPI send information; see dlpi_send(3DLPI).
121  */
122 typedef struct {
123 	uint_t 		dsi_sap;
124 	dl_priority_t	dsi_prio;
125 } dlpi_sendinfo_t;
126 
127 /*
128  * Destination DLPI address type; see dlpi_recv(3DLPI).
129  */
130 typedef enum {
131 	DLPI_ADDRTYPE_UNICAST,
132 	DLPI_ADDRTYPE_GROUP
133 } dlpi_addrtype_t;
134 
135 /*
136  * DLPI receive information; see dlpi_recv(3DLPI).
137  */
138 typedef struct {
139 	uchar_t 	dri_destaddr[DLPI_PHYSADDR_MAX];
140 	uchar_t 	dri_destaddrlen;
141 	dlpi_addrtype_t	dri_destaddrtype;
142 	size_t  	dri_totmsglen;
143 } dlpi_recvinfo_t;
144 
145 /*
146  * DLPI notification, (DL_NOTIFY_IND) payload information;
147  * see dlpi_enabnotify(3DLPI).
148  */
149 typedef struct {
150 	uint_t  dni_note;
151 	union {
152 		uint_t  dniu_speed;
153 		uint_t  dniu_size;
154 		struct {
155 			uchar_t physaddr[DLPI_PHYSADDR_MAX];
156 			uchar_t physaddrlen;
157 		} dniu_addr;
158 	} dni_data;
159 } dlpi_notifyinfo_t;
160 
161 #define	dni_speed		dni_data.dniu_speed
162 #define	dni_size		dni_data.dniu_size
163 #define	dni_physaddr		dni_data.dniu_addr.physaddr
164 #define	dni_physaddrlen 	dni_data.dniu_addr.physaddrlen
165 
166 typedef struct __dlpi_handle *dlpi_handle_t;
167 
168 /*
169  * dlpi_notifyid_t refers to a registered notification. Its value should
170  * not be interpreted by the interface consumer.
171  */
172 typedef struct __dlpi_notifyid *dlpi_notifyid_t;
173 
174 /*
175  * Callback function invoked with arguments; see dlpi_enabnotify(3DLPI).
176  */
177 typedef void dlpi_notifyfunc_t(dlpi_handle_t, dlpi_notifyinfo_t *, void *);
178 
179 extern const char	*dlpi_mactype(uint_t);
180 extern const char 	*dlpi_strerror(int);
181 extern const char 	*dlpi_linkname(dlpi_handle_t);
182 
183 typedef boolean_t dlpi_walkfunc_t(const char *, void *);
184 
185 extern void dlpi_walk(dlpi_walkfunc_t *, void *, uint_t);
186 extern int dlpi_open(const char *, dlpi_handle_t *, uint_t);
187 extern void dlpi_close(dlpi_handle_t);
188 extern int dlpi_info(dlpi_handle_t, dlpi_info_t *, uint_t);
189 extern int dlpi_bind(dlpi_handle_t, uint_t, uint_t *);
190 extern int dlpi_unbind(dlpi_handle_t);
191 extern int dlpi_enabmulti(dlpi_handle_t, const void *, size_t);
192 extern int dlpi_disabmulti(dlpi_handle_t, const void *, size_t);
193 extern int dlpi_promiscon(dlpi_handle_t, uint_t);
194 extern int dlpi_promiscoff(dlpi_handle_t, uint_t);
195 extern int dlpi_get_physaddr(dlpi_handle_t, uint_t, void *, size_t *);
196 extern int dlpi_set_physaddr(dlpi_handle_t, uint_t, const void *, size_t);
197 extern int dlpi_recv(dlpi_handle_t, void *, size_t *, void *, size_t *,
198     int, dlpi_recvinfo_t *);
199 extern int dlpi_send(dlpi_handle_t, const void *, size_t, const void *, size_t,
200     const dlpi_sendinfo_t *);
201 extern int dlpi_enabnotify(dlpi_handle_t, uint_t, dlpi_notifyfunc_t *,
202     void *arg, dlpi_notifyid_t *);
203 extern int dlpi_disabnotify(dlpi_handle_t, dlpi_notifyid_t, void **);
204 extern int dlpi_fd(dlpi_handle_t);
205 extern int dlpi_set_timeout(dlpi_handle_t, int);
206 extern uint_t dlpi_arptype(uint_t);
207 extern uint_t dlpi_iftype(uint_t);
208 
209 /*
210  * These are Consolidation Private interfaces and are subject to change.
211  */
212 extern int dlpi_parselink(const char *, char *, uint_t *);
213 extern int dlpi_makelink(char *, const char *, uint_t);
214 extern uint_t dlpi_style(dlpi_handle_t);
215 
216 #ifdef	__cplusplus
217 }
218 #endif
219 
220 #endif /* _LIBDLPI_H */
221