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