xref: /illumos-gate/usr/src/lib/libdlpi/common/libdlpi.h (revision bc1f688b4872ace323eaddbb1a6365d054e7bf56)
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 #include <sys/types.h>
30 #include <sys/dlpi.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Maximum Physical (hardware) address length, in bytes.
38  * Must be as large as MAXMACADDRLEN (see <sys/mac.h>).
39  */
40 #define	DLPI_PHYSADDR_MAX	64
41 
42 /*
43  * Maximum link name length, including terminating NUL, in bytes.
44  * Must be no larger than MAXLINKNAMELEN (see <sys/param.h>).
45  */
46 #define	DLPI_LINKNAME_MAX	32
47 
48 /*
49  * Constant used to indicate bind to any SAP value
50  */
51 #define	DLPI_ANY_SAP	(uint_t)-1
52 
53 /*
54  * Flag values for dlpi_open(); those not documented in dlpi_open(3DLPI)
55  * are Consolidation Private and subject to change or removal.
56  */
57 #define	DLPI_EXCL	0x0001	/* Exclusive open */
58 #define	DLPI_PASSIVE	0x0002	/* Open DLPI link in passive mode */
59 #define	DLPI_RAW	0x0004	/* Open DLPI link in raw mode */
60 #define	DLPI_SERIAL	0x0008	/* Synchronous serial line interface */
61 #define	DLPI_NOATTACH	0x0010	/* Do not attach PPA */
62 #define	DLPI_NATIVE	0x0020	/* Open DLPI link in native mode */
63 #define	DLPI_DEVONLY	0x0040	/* Open DLPI link under /dev only */
64 #define	DLPI_DEVIPNET	0x0080	/* Open IP DLPI link under /dev/ipnet */
65 #define	DLPI_IPNETINFO	0x0100	/* Request ipnetinfo headers */
66 /*
67  * Timeout to be used in DLPI-related operations, in seconds.
68  */
69 #define	DLPI_DEF_TIMEOUT  5
70 
71 /*
72  * Since this library returns error codes defined in either <sys/dlpi.h> or
73  * <libdlpi.h>, libdlpi specific error codes will start at value 10000 to
74  * avoid overlap. DLPI_SUCCESS cannot be 0 because 0 is already DL_BADSAP in
75  * <sys/dlpi.h>.
76  */
77 enum {
78 	DLPI_SUCCESS = 10000,	/* DLPI operation succeeded */
79 	DLPI_EINVAL,		/* invalid argument */
80 	DLPI_ELINKNAMEINVAL,	/* invalid DLPI linkname */
81 	DLPI_ENOLINK,		/* DLPI link does not exist */
82 	DLPI_EBADLINK,		/* bad DLPI link */
83 	DLPI_EINHANDLE,		/* invalid DLPI handle */
84 	DLPI_ETIMEDOUT,		/* DLPI operation timed out */
85 	DLPI_EVERNOTSUP,	/* unsupported DLPI Version */
86 	DLPI_EMODENOTSUP,	/* unsupported DLPI connection mode */
87 	DLPI_EUNAVAILSAP,	/* unavailable DLPI SAP */
88 	DLPI_FAILURE,		/* DLPI operation failed */
89 	DLPI_ENOTSTYLE2,	/* DLPI style-2 node reports style-1 */
90 	DLPI_EBADMSG,		/* bad DLPI message */
91 	DLPI_ERAWNOTSUP,	/* DLPI raw mode not supported */
92 	DLPI_ENOTEINVAL,	/* invalid DLPI notification type */
93 	DLPI_ENOTENOTSUP,	/* DLPI notification not supported by link */
94 	DLPI_ENOTEIDINVAL,	/* invalid DLPI notification id */
95 	DLPI_EIPNETINFONOTSUP,	/* DLPI_IPNETINFO not supported */
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