xref: /titanic_44/usr/src/uts/common/sys/mac_impl.h (revision ee5416c9d7e449233197d5d20bc6b81e4ff091b2)
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	_SYS_MAC_IMPL_H
27 #define	_SYS_MAC_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/mac.h>
32 #include <net/if.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Statistics maintained internally by the mac module.
40  */
41 enum mac_mod_stat {
42 	MAC_STAT_LINK_STATE,
43 	MAC_STAT_LINK_UP,
44 	MAC_STAT_PROMISC
45 };
46 
47 typedef struct mac_multicst_addr_s	mac_multicst_addr_t;
48 
49 struct mac_multicst_addr_s {
50 	mac_multicst_addr_t	*mma_nextp;
51 	uint_t			mma_ref;
52 	uint8_t			mma_addr[MAXMACADDRLEN];
53 };
54 
55 typedef struct mac_notify_fn_s		mac_notify_fn_t;
56 
57 struct mac_notify_fn_s {
58 	mac_notify_fn_t		*mnf_nextp;
59 	mac_notify_t		mnf_fn;
60 	void			*mnf_arg;
61 };
62 
63 typedef struct mac_rx_fn_s		mac_rx_fn_t;
64 
65 struct mac_rx_fn_s {
66 	mac_rx_fn_t		*mrf_nextp;
67 	mac_rx_t		mrf_fn;
68 	void			*mrf_arg;
69 	boolean_t		mrf_inuse;
70 };
71 
72 typedef struct mac_txloop_fn_s		mac_txloop_fn_t;
73 
74 struct mac_txloop_fn_s {
75 	mac_txloop_fn_t		*mtf_nextp;
76 	mac_txloop_t		mtf_fn;
77 	void			*mtf_arg;
78 };
79 
80 typedef struct mactype_s {
81 	const char	*mt_ident;
82 	uint32_t	mt_ref;
83 	uint_t		mt_type;
84 	uint_t		mt_nativetype;
85 	size_t		mt_addr_length;
86 	uint8_t		*mt_brdcst_addr;
87 	mactype_ops_t	mt_ops;
88 	mac_stat_info_t	*mt_stats;	/* array of mac_stat_info_t elements */
89 	size_t		mt_statcount;	/* number of elements in mt_stats */
90 } mactype_t;
91 
92 /*
93  * Each registered MAC is associated with a mac_t structure.
94  */
95 typedef struct mac_impl_s {
96 	char			mi_name[LIFNAMSIZ];
97 	const char		*mi_drvname;
98 	uint_t			mi_instance;
99 	void			*mi_driver;	/* Driver private data */
100 	mac_info_t		mi_info;
101 	mactype_t		*mi_type;
102 	void			*mi_pdata;
103 	size_t			mi_pdata_size;
104 	mac_callbacks_t		*mi_callbacks;
105 	dev_info_t		*mi_dip;
106 	uint32_t		mi_ref;
107 	boolean_t		mi_disabled;
108 	krwlock_t		mi_state_lock;
109 	uint_t			mi_active;
110 	krwlock_t		mi_data_lock;
111 	link_state_t		mi_linkstate;
112 	link_state_t		mi_lastlinkstate;
113 	uint_t			mi_promisc;
114 	uint_t			mi_devpromisc;
115 	uint8_t			mi_addr[MAXMACADDRLEN];
116 	uint8_t			mi_dstaddr[MAXMACADDRLEN];
117 	mac_multicst_addr_t	*mi_mmap;
118 	krwlock_t		mi_notify_lock;
119 	uint32_t		mi_notify_bits;
120 	kmutex_t		mi_notify_bits_lock;
121 	kthread_t		*mi_notify_thread;
122 	mac_notify_fn_t		*mi_mnfp;
123 	kcondvar_t		mi_notify_cv;
124 	krwlock_t		mi_rx_lock;
125 	mac_rx_fn_t		*mi_mrfp;
126 	krwlock_t		mi_txloop_lock;
127 	mac_txloop_fn_t		*mi_mtfp;
128 	krwlock_t		mi_resource_lock;
129 	mac_resource_add_t	mi_resource_add;
130 	void			*mi_resource_add_arg;
131 	kstat_t			*mi_ksp;
132 	uint_t			mi_kstat_count;
133 	kmutex_t		mi_activelink_lock;
134 	boolean_t		mi_activelink;
135 	mac_txinfo_t		mi_txinfo;
136 	mac_txinfo_t		mi_txloopinfo;
137 	uint32_t		mi_rx_ref;	/* #threads in mac_rx() */
138 	uint32_t		mi_rx_removed;	/* #callbacks marked */
139 						/* for removal */
140 	kmutex_t		mi_lock;
141 	kcondvar_t		mi_rx_cv;
142 } mac_impl_t;
143 
144 #define	mi_getstat	mi_callbacks->mc_getstat
145 #define	mi_start	mi_callbacks->mc_start
146 #define	mi_stop		mi_callbacks->mc_stop
147 #define	mi_setpromisc	mi_callbacks->mc_setpromisc
148 #define	mi_multicst	mi_callbacks->mc_multicst
149 #define	mi_unicst	mi_callbacks->mc_unicst
150 #define	mi_resources	mi_callbacks->mc_resources
151 #define	mi_tx		mi_callbacks->mc_tx
152 #define	mi_ioctl	mi_callbacks->mc_ioctl
153 #define	mi_getcapab	mi_callbacks->mc_getcapab
154 
155 extern void	mac_init(void);
156 extern int	mac_fini(void);
157 
158 extern void	mac_stat_create(mac_impl_t *);
159 extern void	mac_stat_destroy(mac_impl_t *);
160 extern uint64_t	mac_stat_default(mac_impl_t *, uint_t);
161 
162 #ifdef	__cplusplus
163 }
164 #endif
165 
166 #endif	/* _SYS_MAC_IMPL_H */
167