xref: /titanic_41/usr/src/uts/common/sys/mac_impl.h (revision f8919bdadda3ebb97bd55cc14a16e0271ed57615)
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 	boolean_t		mrf_active;
71 };
72 
73 typedef struct mac_txloop_fn_s		mac_txloop_fn_t;
74 
75 struct mac_txloop_fn_s {
76 	mac_txloop_fn_t		*mtf_nextp;
77 	mac_txloop_t		mtf_fn;
78 	void			*mtf_arg;
79 };
80 
81 typedef struct mactype_s {
82 	const char	*mt_ident;
83 	uint32_t	mt_ref;
84 	uint_t		mt_type;
85 	uint_t		mt_nativetype;
86 	size_t		mt_addr_length;
87 	uint8_t		*mt_brdcst_addr;
88 	mactype_ops_t	mt_ops;
89 	mac_stat_info_t	*mt_stats;	/* array of mac_stat_info_t elements */
90 	size_t		mt_statcount;	/* number of elements in mt_stats */
91 } mactype_t;
92 
93 
94 #define	MAC_VNIC_TXINFO_REFHOLD(mvt) {				\
95 	mutex_enter(&(mvt)->mv_lock);				\
96 	(mvt)->mv_refs++;					\
97 	mutex_exit(&(mvt)->mv_lock);				\
98 }
99 
100 #define	MAC_VNIC_TXINFO_REFRELE(mvt) {				\
101 	mutex_enter(&(mvt)->mv_lock);				\
102 	if (--(mvt)->mv_refs == 0 && (mvt)->mv_clearing) {	\
103 	    (mvt)->mv_clearing = B_FALSE;			\
104 	    cv_signal(&(mvt)->mv_cv);				\
105 	}							\
106 	mutex_exit(&(mvt)->mv_lock);				\
107 }
108 
109 typedef struct mac_vnic_tx_s {
110 	mac_txinfo_t	mv_txinfo;	/* provided by VNIC */
111 	uint32_t	mv_refs;
112 	kmutex_t	mv_lock;
113 	kcondvar_t	mv_cv;
114 	boolean_t	mv_clearing;
115 } mac_vnic_tx_t;
116 
117 /*
118  * Each registered MAC is associated with a mac_t structure.
119  */
120 typedef struct mac_impl_s {
121 	char			mi_name[LIFNAMSIZ];
122 	const char		*mi_drvname;
123 	uint_t			mi_instance;
124 	void			*mi_driver;	/* Driver private data */
125 	mac_info_t		mi_info;
126 	mactype_t		*mi_type;
127 	void			*mi_pdata;
128 	size_t			mi_pdata_size;
129 	mac_callbacks_t		*mi_callbacks;
130 	dev_info_t		*mi_dip;
131 	uint32_t		mi_ref;
132 	boolean_t		mi_disabled;
133 	krwlock_t		mi_state_lock;
134 	uint_t			mi_active;
135 	krwlock_t		mi_data_lock;
136 	link_state_t		mi_linkstate;
137 	link_state_t		mi_lastlinkstate;
138 	uint_t			mi_promisc;
139 	uint_t			mi_devpromisc;
140 	uint8_t			mi_addr[MAXMACADDRLEN];
141 	uint8_t			mi_dstaddr[MAXMACADDRLEN];
142 	mac_multicst_addr_t	*mi_mmap;
143 	krwlock_t		mi_notify_lock;
144 	uint32_t		mi_notify_bits;
145 	kmutex_t		mi_notify_bits_lock;
146 	kthread_t		*mi_notify_thread;
147 	mac_notify_fn_t		*mi_mnfp;
148 	kcondvar_t		mi_notify_cv;
149 	krwlock_t		mi_rx_lock;
150 	mac_rx_fn_t		*mi_mrfp;
151 	krwlock_t		mi_tx_lock;
152 	mac_txloop_fn_t		*mi_mtfp;
153 	krwlock_t		mi_resource_lock;
154 	mac_resource_add_t	mi_resource_add;
155 	void			*mi_resource_add_arg;
156 	kstat_t			*mi_ksp;
157 	uint_t			mi_kstat_count;
158 	kmutex_t		mi_activelink_lock;
159 	boolean_t		mi_activelink;
160 	mac_txinfo_t		mi_txinfo;
161 	mac_txinfo_t		mi_txloopinfo;
162 	uint32_t		mi_rx_ref;	/* #threads in mac_rx() */
163 	uint32_t		mi_rx_removed;	/* #callbacks marked */
164 						/* for removal */
165 	kmutex_t		mi_lock;
166 	kcondvar_t		mi_rx_cv;
167 	boolean_t		mi_shareable;
168 	boolean_t		mi_vnic_present;
169 	mac_vnic_tx_t		*mi_vnic_tx;
170 	mac_txinfo_t		mi_vnic_txinfo;
171 	mac_txinfo_t		mi_vnic_txloopinfo;
172 	mac_getcapab_t		mi_vnic_getcapab_fn;
173 	void			*mi_vnic_getcapab_arg;
174 } mac_impl_t;
175 
176 #define	mi_getstat	mi_callbacks->mc_getstat
177 #define	mi_start	mi_callbacks->mc_start
178 #define	mi_stop		mi_callbacks->mc_stop
179 #define	mi_setpromisc	mi_callbacks->mc_setpromisc
180 #define	mi_multicst	mi_callbacks->mc_multicst
181 #define	mi_unicst	mi_callbacks->mc_unicst
182 #define	mi_resources	mi_callbacks->mc_resources
183 #define	mi_tx		mi_callbacks->mc_tx
184 #define	mi_ioctl	mi_callbacks->mc_ioctl
185 #define	mi_getcapab	mi_callbacks->mc_getcapab
186 
187 extern void	mac_init(void);
188 extern int	mac_fini(void);
189 
190 extern void	mac_stat_create(mac_impl_t *);
191 extern void	mac_stat_destroy(mac_impl_t *);
192 extern uint64_t	mac_stat_default(mac_impl_t *, uint_t);
193 
194 #ifdef	__cplusplus
195 }
196 #endif
197 
198 #endif	/* _SYS_MAC_IMPL_H */
199