xref: /titanic_44/usr/src/uts/common/sys/mac.h (revision aad98a6d8e89f8f5a62a1793da807d4bc5e5b159)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_MAC_H
28 #define	_SYS_MAC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <sys/ddi.h>
33 #include <sys/sunddi.h>
34 #include <sys/stream.h>
35 
36 /*
37  * MAC Services Module
38  */
39 
40 #ifdef	__cplusplus
41 extern "C" {
42 #endif
43 
44 /*
45  * Module name.
46  */
47 #define	MAC_MODULE_NAME	"mac"
48 
49 /*
50  * MAC Information (text emitted by modinfo(1m))
51  */
52 #define	MAC_INFO	"MAC Services v%I%"
53 
54 /*
55  * Statistics
56  */
57 
58 #define	XCVR_UNDEFINED		0
59 #define	XCVR_NONE		1
60 #define	XCVR_10			2
61 #define	XCVR_100T4		3
62 #define	XCVR_100X		4
63 #define	XCVR_100T2		5
64 #define	XCVR_1000X		6
65 #define	XCVR_1000T		7
66 
67 typedef enum {
68 	LINK_STATE_UNKNOWN = -1,
69 	LINK_STATE_DOWN,
70 	LINK_STATE_UP
71 } link_state_t;
72 
73 typedef enum {
74 	LINK_DUPLEX_UNKNOWN = 0,
75 	LINK_DUPLEX_HALF,
76 	LINK_DUPLEX_FULL
77 } link_duplex_t;
78 
79 #ifdef	_KERNEL
80 
81 enum mac_stat {
82 	/*
83 	 * PSARC 1997/198 (MIB-II kstats)
84 	 */
85 	MAC_STAT_IFSPEED,
86 	MAC_STAT_MULTIRCV,
87 	MAC_STAT_BRDCSTRCV,
88 	MAC_STAT_MULTIXMT,
89 	MAC_STAT_BRDCSTXMT,
90 	MAC_STAT_NORCVBUF,
91 	MAC_STAT_IERRORS,
92 	MAC_STAT_UNKNOWNS,
93 	MAC_STAT_NOXMTBUF,
94 	MAC_STAT_OERRORS,
95 	MAC_STAT_COLLISIONS,
96 	MAC_STAT_RBYTES,
97 	MAC_STAT_IPACKETS,
98 	MAC_STAT_OBYTES,
99 	MAC_STAT_OPACKETS,
100 
101 	/*
102 	 * PSARC 1997/247 (RFC 1643 kstats)
103 	 */
104 	MAC_STAT_ALIGN_ERRORS,
105 	MAC_STAT_FCS_ERRORS,
106 	MAC_STAT_FIRST_COLLISIONS,
107 	MAC_STAT_MULTI_COLLISIONS,
108 	MAC_STAT_SQE_ERRORS,
109 	MAC_STAT_DEFER_XMTS,
110 	MAC_STAT_TX_LATE_COLLISIONS,
111 	MAC_STAT_EX_COLLISIONS,
112 	MAC_STAT_MACXMT_ERRORS,
113 	MAC_STAT_CARRIER_ERRORS,
114 	MAC_STAT_TOOLONG_ERRORS,
115 	MAC_STAT_MACRCV_ERRORS,
116 
117 	/*
118 	 * PSARC 2003/581 (MII/GMII kstats)
119 	 */
120 	MAC_STAT_XCVR_ADDR,
121 	MAC_STAT_XCVR_ID,
122 	MAC_STAT_XCVR_INUSE,
123 	MAC_STAT_CAP_1000FDX,
124 	MAC_STAT_CAP_1000HDX,
125 	MAC_STAT_CAP_100FDX,
126 	MAC_STAT_CAP_100HDX,
127 	MAC_STAT_CAP_10FDX,
128 	MAC_STAT_CAP_10HDX,
129 	MAC_STAT_CAP_ASMPAUSE,
130 	MAC_STAT_CAP_PAUSE,
131 	MAC_STAT_CAP_AUTONEG,
132 	MAC_STAT_ADV_CAP_1000FDX,
133 	MAC_STAT_ADV_CAP_1000HDX,
134 	MAC_STAT_ADV_CAP_100FDX,
135 	MAC_STAT_ADV_CAP_100HDX,
136 	MAC_STAT_ADV_CAP_10FDX,
137 	MAC_STAT_ADV_CAP_10HDX,
138 	MAC_STAT_ADV_CAP_ASMPAUSE,
139 	MAC_STAT_ADV_CAP_PAUSE,
140 	MAC_STAT_ADV_CAP_AUTONEG,
141 	MAC_STAT_LP_CAP_1000FDX,
142 	MAC_STAT_LP_CAP_1000HDX,
143 	MAC_STAT_LP_CAP_100FDX,
144 	MAC_STAT_LP_CAP_100HDX,
145 	MAC_STAT_LP_CAP_10FDX,
146 	MAC_STAT_LP_CAP_10HDX,
147 	MAC_STAT_LP_CAP_ASMPAUSE,
148 	MAC_STAT_LP_CAP_PAUSE,
149 	MAC_STAT_LP_CAP_AUTONEG,
150 	MAC_STAT_LINK_ASMPAUSE,
151 	MAC_STAT_LINK_PAUSE,
152 	MAC_STAT_LINK_AUTONEG,
153 	MAC_STAT_LINK_DUPLEX,
154 	MAC_NSTAT	/* must be the last entry */
155 };
156 
157 /*
158  * Maximum MAC address length
159  */
160 #define	MAXADDRLEN	20
161 
162 /*
163  * Immutable information. (This may not be modified after registration).
164  */
165 typedef struct mac_info_s {
166 	uint_t		mi_media;
167 	uint_t		mi_sdu_min;
168 	uint_t		mi_sdu_max;
169 	uint32_t	mi_cksum;
170 	uint32_t	mi_poll;
171 	uint_t		mi_addr_length;
172 	uint8_t		mi_unicst_addr[MAXADDRLEN];
173 	uint8_t		mi_brdcst_addr[MAXADDRLEN];
174 	boolean_t	mi_stat[MAC_NSTAT];
175 } mac_info_t;
176 
177 #define	MAC_STAT_MIB(_mi_stat) \
178 { \
179 	(_mi_stat)[MAC_STAT_IFSPEED] = B_TRUE; \
180 	(_mi_stat)[MAC_STAT_MULTIRCV] = B_TRUE; \
181 	(_mi_stat)[MAC_STAT_BRDCSTRCV] = B_TRUE; \
182 	(_mi_stat)[MAC_STAT_MULTIXMT] = B_TRUE; \
183 	(_mi_stat)[MAC_STAT_BRDCSTXMT] = B_TRUE; \
184 	(_mi_stat)[MAC_STAT_NORCVBUF] = B_TRUE; \
185 	(_mi_stat)[MAC_STAT_IERRORS] = B_TRUE; \
186 	(_mi_stat)[MAC_STAT_UNKNOWNS] = B_TRUE; \
187 	(_mi_stat)[MAC_STAT_NOXMTBUF] = B_TRUE; \
188 	(_mi_stat)[MAC_STAT_OERRORS] = B_TRUE; \
189 	(_mi_stat)[MAC_STAT_COLLISIONS] = B_TRUE; \
190 	(_mi_stat)[MAC_STAT_RBYTES] = B_TRUE; \
191 	(_mi_stat)[MAC_STAT_IPACKETS] = B_TRUE; \
192 	(_mi_stat)[MAC_STAT_OBYTES] = B_TRUE; \
193 	(_mi_stat)[MAC_STAT_OPACKETS] = B_TRUE; \
194 }
195 
196 #define	MAC_STAT_ETHER(_mi_stat) \
197 { \
198 	(_mi_stat)[MAC_STAT_ALIGN_ERRORS] = B_TRUE; \
199 	(_mi_stat)[MAC_STAT_FCS_ERRORS] = B_TRUE; \
200 	(_mi_stat)[MAC_STAT_FIRST_COLLISIONS] = B_TRUE; \
201 	(_mi_stat)[MAC_STAT_MULTI_COLLISIONS] = B_TRUE; \
202 	(_mi_stat)[MAC_STAT_SQE_ERRORS] = B_TRUE; \
203 	(_mi_stat)[MAC_STAT_DEFER_XMTS] = B_TRUE; \
204 	(_mi_stat)[MAC_STAT_TX_LATE_COLLISIONS] = B_TRUE; \
205 	(_mi_stat)[MAC_STAT_EX_COLLISIONS] = B_TRUE; \
206 	(_mi_stat)[MAC_STAT_MACXMT_ERRORS] = B_TRUE; \
207 	(_mi_stat)[MAC_STAT_CARRIER_ERRORS] = B_TRUE; \
208 	(_mi_stat)[MAC_STAT_TOOLONG_ERRORS] = B_TRUE; \
209 	(_mi_stat)[MAC_STAT_MACRCV_ERRORS] = B_TRUE; \
210 }
211 
212 #define	MAC_STAT_MII(_mi_stat) \
213 { \
214 	(_mi_stat)[MAC_STAT_XCVR_ADDR] = B_TRUE; \
215 	(_mi_stat)[MAC_STAT_XCVR_ID] = B_TRUE; \
216 	(_mi_stat)[MAC_STAT_XCVR_INUSE] = B_TRUE; \
217 	(_mi_stat)[MAC_STAT_CAP_1000FDX] = B_TRUE; \
218 	(_mi_stat)[MAC_STAT_CAP_1000HDX] = B_TRUE; \
219 	(_mi_stat)[MAC_STAT_CAP_100FDX] = B_TRUE; \
220 	(_mi_stat)[MAC_STAT_CAP_100HDX] = B_TRUE; \
221 	(_mi_stat)[MAC_STAT_CAP_10FDX] = B_TRUE; \
222 	(_mi_stat)[MAC_STAT_CAP_10HDX] = B_TRUE; \
223 	(_mi_stat)[MAC_STAT_CAP_ASMPAUSE] = B_TRUE; \
224 	(_mi_stat)[MAC_STAT_CAP_PAUSE] = B_TRUE; \
225 	(_mi_stat)[MAC_STAT_CAP_AUTONEG] = B_TRUE; \
226 	(_mi_stat)[MAC_STAT_ADV_CAP_1000FDX] = B_TRUE; \
227 	(_mi_stat)[MAC_STAT_ADV_CAP_1000HDX] = B_TRUE; \
228 	(_mi_stat)[MAC_STAT_ADV_CAP_100FDX] = B_TRUE; \
229 	(_mi_stat)[MAC_STAT_ADV_CAP_100HDX] = B_TRUE; \
230 	(_mi_stat)[MAC_STAT_ADV_CAP_10FDX] = B_TRUE; \
231 	(_mi_stat)[MAC_STAT_ADV_CAP_10HDX] = B_TRUE; \
232 	(_mi_stat)[MAC_STAT_ADV_CAP_ASMPAUSE] = B_TRUE; \
233 	(_mi_stat)[MAC_STAT_ADV_CAP_PAUSE] = B_TRUE; \
234 	(_mi_stat)[MAC_STAT_ADV_CAP_AUTONEG] = B_TRUE; \
235 	(_mi_stat)[MAC_STAT_LP_CAP_1000FDX] = B_TRUE; \
236 	(_mi_stat)[MAC_STAT_LP_CAP_1000HDX] = B_TRUE; \
237 	(_mi_stat)[MAC_STAT_LP_CAP_100FDX] = B_TRUE; \
238 	(_mi_stat)[MAC_STAT_LP_CAP_100HDX] = B_TRUE; \
239 	(_mi_stat)[MAC_STAT_LP_CAP_10FDX] = B_TRUE; \
240 	(_mi_stat)[MAC_STAT_LP_CAP_10HDX] = B_TRUE; \
241 	(_mi_stat)[MAC_STAT_LP_CAP_ASMPAUSE] = B_TRUE; \
242 	(_mi_stat)[MAC_STAT_LP_CAP_PAUSE] = B_TRUE; \
243 	(_mi_stat)[MAC_STAT_LP_CAP_AUTONEG] = B_TRUE; \
244 	(_mi_stat)[MAC_STAT_LINK_ASMPAUSE] = B_TRUE; \
245 	(_mi_stat)[MAC_STAT_LINK_PAUSE] = B_TRUE; \
246 	(_mi_stat)[MAC_STAT_LINK_AUTONEG] = B_TRUE; \
247 	(_mi_stat)[MAC_STAT_LINK_DUPLEX] = B_TRUE; \
248 }
249 
250 /*
251  * MAC version identifer (for debugging)
252  */
253 #define	MAC_IDENT	"%I%"
254 
255 /*
256  * MAC driver entry point types.
257  */
258 typedef uint64_t	(*mac_stat_t)(void *, enum mac_stat);
259 typedef	int		(*mac_start_t)(void *);
260 typedef void		(*mac_stop_t)(void *);
261 typedef int		(*mac_promisc_t)(void *, boolean_t);
262 typedef int		(*mac_multicst_t)(void *, boolean_t, const uint8_t *);
263 typedef int		(*mac_unicst_t)(void *, const uint8_t *);
264 typedef void		(*mac_resources_t)(void *);
265 typedef void		(*mac_ioctl_t)(void *, queue_t *, mblk_t *);
266 typedef mblk_t		*(*mac_tx_t)(void *, mblk_t *);
267 
268 /*
269  * MAC extensions. (Currently there are non defined).
270  */
271 typedef struct mac_ext_s	mac_ext_t;
272 
273 /*
274  * MAC implementation private data.
275  */
276 typedef struct mac_impl_s	mac_impl_t;
277 
278 /*
279  * MAC structure: supplied by the driver.
280  */
281 typedef struct mac {
282 	const char	*m_ident;	/* MAC_IDENT */
283 	mac_ext_t	*m_extp;
284 	mac_impl_t	*m_impl;	/* MAC private data */
285 	void		*m_driver;	/* Driver private data */
286 
287 	dev_info_t	*m_dip;
288 	uint_t		m_port;
289 
290 	mac_info_t	m_info;
291 
292 	mac_stat_t	m_stat;
293 	mac_start_t	m_start;
294 	mac_stop_t	m_stop;
295 	mac_promisc_t	m_promisc;
296 	mac_multicst_t	m_multicst;
297 	mac_unicst_t	m_unicst;
298 	mac_resources_t	m_resources;
299 	mac_ioctl_t	m_ioctl;
300 	mac_tx_t	m_tx;
301 } mac_t;
302 
303 /*
304  * Construct the name of a MAC interface.
305  */
306 #define	MAC_NAME(_name, _dev, _port) \
307 	(void) snprintf((_name), MAXNAMELEN - 1, "%s/%u", (_dev), (_port))
308 
309 /*
310  * Opaque handle types.
311  */
312 typedef	struct __mac_handle		*mac_handle_t;
313 typedef struct __mac_notify_handle	*mac_notify_handle_t;
314 typedef struct __mac_rx_handle		*mac_rx_handle_t;
315 typedef struct __mac_txloop_handle	*mac_txloop_handle_t;
316 typedef struct __mac_resource_handle	*mac_resource_handle_t;
317 
318 /*
319  * MAC interface callback types.
320  */
321 typedef enum {
322 	MAC_NOTE_LINK,
323 	MAC_NOTE_PROMISC,
324 	MAC_NOTE_UNICST,
325 	MAC_NOTE_TX,
326 	MAC_NOTE_RESOURCE,
327 	MAC_NOTE_DEVPROMISC,
328 	MAC_NNOTE	/* must be the last entry */
329 } mac_notify_type_t;
330 
331 typedef void		(*mac_notify_t)(void *, mac_notify_type_t);
332 typedef void		(*mac_rx_t)(void *, mac_resource_handle_t, mblk_t *);
333 typedef void		(*mac_txloop_t)(void *, mblk_t *);
334 typedef void		(*mac_blank_t)(void *, time_t, uint_t);
335 
336 /*
337  * MAC promiscuous types
338  */
339 typedef enum {
340 	MAC_PROMISC = 0x01,		/* MAC instance is promiscuous */
341 	MAC_DEVPROMISC = 0x02		/* Device is promiscuous */
342 } mac_promisc_type_t;
343 
344 /*
345  * MAC resource types
346  */
347 typedef enum {
348 	MAC_RX_FIFO = 1
349 } mac_resource_type_t;
350 
351 typedef struct mac_rx_fifo_s {
352 	mac_resource_type_t	mrf_type;	/* MAC_RX_FIFO */
353 	mac_blank_t		mrf_blank;
354 	void			*mrf_arg;
355 	time_t			mrf_normal_blank_time;
356 	uint_t			mrf_normal_pkt_count;
357 } mac_rx_fifo_t;
358 
359 typedef struct mac_txinfo_s {
360 	mac_tx_t		mt_fn;
361 	void			*mt_arg;
362 } mac_txinfo_t;
363 
364 typedef union mac_resource_u {
365 	mac_resource_type_t	mr_type;
366 	mac_rx_fifo_t		mr_fifo;
367 } mac_resource_t;
368 
369 typedef mac_resource_handle_t	(*mac_resource_add_t)(void *, mac_resource_t *);
370 
371 /*
372  * Client interface functions.
373  */
374 extern int			mac_open(const char *, uint_t, mac_handle_t *);
375 extern void			mac_close(mac_handle_t);
376 extern const mac_info_t		*mac_info(mac_handle_t);
377 extern boolean_t		mac_info_get(const char *, mac_info_t *);
378 extern uint64_t			mac_stat_get(mac_handle_t, enum mac_stat);
379 extern int			mac_start(mac_handle_t);
380 extern void			mac_stop(mac_handle_t);
381 extern int			mac_promisc_set(mac_handle_t, boolean_t,
382     mac_promisc_type_t);
383 extern boolean_t		mac_promisc_get(mac_handle_t,
384     mac_promisc_type_t);
385 extern int 			mac_multicst_add(mac_handle_t, const uint8_t *);
386 extern int 			mac_multicst_remove(mac_handle_t,
387     const uint8_t *);
388 extern int			mac_unicst_set(mac_handle_t, const uint8_t *);
389 extern void			mac_unicst_get(mac_handle_t, uint8_t *);
390 extern void			mac_resources(mac_handle_t);
391 extern void			mac_ioctl(mac_handle_t, queue_t *, mblk_t *);
392 extern const mac_txinfo_t	*mac_tx_get(mac_handle_t);
393 extern link_state_t		mac_link_get(mac_handle_t);
394 extern mac_notify_handle_t	mac_notify_add(mac_handle_t, mac_notify_t,
395     void *);
396 extern void			mac_notify_remove(mac_handle_t,
397     mac_notify_handle_t);
398 extern void			mac_notify(mac_handle_t);
399 extern mac_rx_handle_t		mac_rx_add(mac_handle_t, mac_rx_t, void *);
400 extern void			mac_rx_remove(mac_handle_t, mac_rx_handle_t);
401 extern mblk_t			*mac_txloop(void *, mblk_t *);
402 extern mac_txloop_handle_t	mac_txloop_add(mac_handle_t, mac_txloop_t,
403     void *);
404 extern void			mac_txloop_remove(mac_handle_t,
405     mac_txloop_handle_t);
406 extern boolean_t		mac_active_set(mac_handle_t);
407 extern void			mac_active_clear(mac_handle_t);
408 extern void			mac_resource_set(mac_handle_t,
409     mac_resource_add_t, void *);
410 extern dev_info_t		*mac_devinfo_get(mac_handle_t);
411 
412 /*
413  * Driver interface functions.
414  */
415 extern int  			mac_register(mac_t *);
416 extern int  			mac_unregister(mac_t *);
417 extern void 			mac_rx(mac_t *, mac_resource_handle_t,
418     mblk_t *);
419 extern void 			mac_link_update(mac_t *, link_state_t);
420 extern void 			mac_unicst_update(mac_t *, const uint8_t *);
421 extern void			mac_tx_update(mac_t *);
422 extern void			mac_resource_update(mac_t *);
423 extern mac_resource_handle_t	mac_resource_add(mac_t *, mac_resource_t *);
424 extern void			mac_multicst_refresh(mac_t *, mac_multicst_t,
425     void *, boolean_t);
426 extern void			mac_unicst_refresh(mac_t *, mac_unicst_t,
427     void *);
428 extern void			mac_promisc_refresh(mac_t *, mac_promisc_t,
429     void *);
430 extern void			mac_init_ops(struct dev_ops *, const char *);
431 extern void			mac_fini_ops(struct dev_ops *);
432 
433 #endif	/* _KERNEL */
434 
435 #ifdef	__cplusplus
436 }
437 #endif
438 
439 #endif /* _SYS_MAC_H */
440