xref: /illumos-gate/usr/src/uts/common/sys/vnic_impl.h (revision 89a7715a55deca73d03076f5c24463717f0aaa91)
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_VNIC_IMPL_H
27 #define	_SYS_VNIC_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/vnic.h>
32 #include <sys/ksynch.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 typedef void (*vnic_rx_fn_t)(void *, void *, mblk_t *);
39 
40 typedef struct vnic_flow_fn_info_s {
41 	vnic_rx_fn_t	ff_fn;
42 	void		*ff_arg1;
43 	void		*ff_arg2;
44 } vnic_flow_fn_info_t;
45 
46 typedef struct vnic_flow_s {
47 	uchar_t			vf_addr[MAXMACADDRLEN];
48 	uint_t			vf_addr_len;
49 	vnic_flow_fn_info_t	vf_fn_info;
50 	void			*vf_cookie;
51 	struct vnic_flow_s	*vf_next;
52 	kmutex_t		vf_lock;
53 	kcondvar_t		vf_cv;
54 	uint32_t		vf_refs;
55 	boolean_t		vf_clearing;
56 	boolean_t		vf_is_active;
57 } vnic_flow_t;
58 
59 typedef struct vnic_flow_tab_s {
60 	vnic_flow_t		*vt_flow_list;
61 	krwlock_t		vt_lock;
62 	uint_t			vt_addr_len;
63 } vnic_flow_tab_t;
64 
65 typedef struct vnic_mac_s {
66 	mac_handle_t		va_mh;
67 	uint_t			va_refs;
68 	char			va_dev_name[MAXNAMELEN];
69 	const mac_txinfo_t	*va_txinfo;
70 	struct vnic_bcast_grp_s	*va_bcast_grp;
71 	krwlock_t		va_bcast_grp_lock;
72 	size_t			va_addr_len;
73 	mac_notify_handle_t	va_notify_hdl;
74 	mac_rx_handle_t		va_rx_hdl;
75 	vnic_flow_t		*va_active_flow;
76 	vnic_flow_tab_t		*va_flow_tab;
77 	boolean_t		va_mac_set;
78 	struct vnic_s		*va_promisc;
79 	krwlock_t		va_promisc_lock;
80 	uint64_t		va_promisc_gen;
81 } vnic_mac_t;
82 
83 typedef struct vnic_s {
84 	uint_t		vn_id;
85 	uint32_t
86 		vn_started : 1,
87 		vn_promisc : 1,
88 		vn_bcast_grp : 1,
89 		vn_multi_mac : 1,
90 		vn_promisc_mac : 1,
91 		vn_pad_to_bit_31 : 27;
92 
93 	int		vn_slot_id;
94 	multiaddress_capab_t	vn_mma_capab;
95 	uint8_t		vn_addr[ETHERADDRL];
96 	vnic_mac_addr_type_t vn_addr_type;
97 
98 	mac_handle_t	vn_mh;
99 	vnic_mac_t	*vn_vnic_mac;
100 	vnic_flow_t	*vn_flow_ent;
101 	uint32_t	vn_hcksum_txflags;
102 	struct vnic_s	*vn_promisc_next;
103 
104 	uint64_t	vn_stat_multircv;
105 	uint64_t	vn_stat_brdcstrcv;
106 	uint64_t	vn_stat_multixmt;
107 	uint64_t	vn_stat_brdcstxmt;
108 	uint64_t	vn_stat_ierrors;
109 	uint64_t	vn_stat_oerrors;
110 	uint64_t	vn_stat_rbytes;
111 	uint64_t	vn_stat_ipackets;
112 	uint64_t	vn_stat_obytes;
113 	uint64_t	vn_stat_opackets;
114 } vnic_t;
115 
116 #define	vn_txinfo	vn_vnic_mac->va_txinfo
117 
118 #define	vn_madd_naddr		vn_mma_capab.maddr_naddr
119 #define	vn_maddr_naddrfree	vn_mma_capab.maddr_naddrfree
120 #define	vn_maddr_flag		vn_mma_capab.maddr_flag
121 #define	vn_maddr_handle		vn_mma_capab.maddr_handle
122 #define	vn_maddr_reserve	vn_mma_capab.maddr_reserve
123 #define	vn_maddr_add		vn_mma_capab.maddr_add
124 #define	vn_maddr_remove		vn_mma_capab.maddr_remove
125 #define	vn_maddr_modify		vn_mma_capab.maddr_modify
126 #define	vn_maddr_get		vn_mma_capab.maddr_get
127 
128 #define	VNIC_FLOW_REFHOLD(flow) {				\
129 	mutex_enter(&(flow)->vf_lock);				\
130 	(flow)->vf_refs++;					\
131 	mutex_exit(&(flow)->vf_lock);				\
132 }
133 
134 #define	VNIC_FLOW_REFRELE(flow) {				\
135 	mutex_enter(&(flow)->vf_lock);				\
136 	if (--(flow)->vf_refs == 0 && (flow)->vf_clearing) {	\
137 	    (flow)->vf_clearing = B_FALSE;			\
138 	    cv_signal(&(flow)->vf_cv);				\
139 	}							\
140 	mutex_exit(&(flow)->vf_lock);				\
141 }
142 
143 extern int vnic_dev_create(uint_t, char *, int, uchar_t *);
144 extern int vnic_dev_modify(uint_t, uint_t, vnic_mac_addr_type_t,
145     uint_t, uchar_t *);
146 extern int vnic_dev_delete(uint_t);
147 
148 typedef int (*vnic_info_new_vnic_fn_t)(void *, uint32_t, vnic_mac_addr_type_t,
149     uint_t, uint8_t *, char *);
150 
151 extern void vnic_dev_init(void);
152 extern void vnic_dev_fini(void);
153 extern uint_t vnic_dev_count(void);
154 extern dev_info_t *vnic_get_dip(void);
155 
156 extern int vnic_info(uint_t *, uint32_t, char *, void *,
157     vnic_info_new_vnic_fn_t);
158 
159 extern void vnic_rx(void *, void *, mblk_t *);
160 extern mblk_t *vnic_fix_cksum(mblk_t *);
161 extern mblk_t *vnic_copymsgchain_cksum(mblk_t *);
162 extern mblk_t *vnic_copymsg_cksum(mblk_t *);
163 
164 extern void vnic_promisc_rx(vnic_mac_t *, vnic_t *, mblk_t *);
165 
166 extern void vnic_bcast_init(void);
167 extern void vnic_bcast_fini(void);
168 extern int vnic_bcast_add(vnic_t *, const uint8_t *, mac_addrtype_t);
169 extern void vnic_bcast_delete(vnic_t *, const uint8_t *);
170 extern void vnic_bcast_send(void *, void *, mblk_t *);
171 
172 extern void vnic_classifier_init(void);
173 extern void vnic_classifier_fini(void);
174 extern vnic_flow_t *vnic_classifier_flow_create(uint_t, uchar_t *, void *,
175     boolean_t, int);
176 extern void vnic_classifier_flow_destroy(vnic_flow_t *);
177 extern void vnic_classifier_flow_add(vnic_mac_t *, vnic_flow_t *, vnic_rx_fn_t,
178     void *, void *);
179 extern void vnic_classifier_flow_remove(vnic_mac_t *, vnic_flow_t *);
180 extern void vnic_classifier_flow_update_addr(vnic_flow_t *, uchar_t *);
181 extern void vnic_classifier_flow_update_fn(vnic_flow_t *, vnic_rx_fn_t,
182     void *, void *);
183 extern int vnic_classifier_flow_tab_init(vnic_mac_t *, uint_t, int);
184 extern void vnic_classifier_flow_tab_fini(vnic_mac_t *);
185 extern vnic_flow_t *vnic_classifier_get_flow(vnic_mac_t *, mblk_t *);
186 extern void *vnic_classifier_get_client_cookie(vnic_flow_t *);
187 extern vnic_flow_fn_info_t *vnic_classifier_get_fn_info(vnic_flow_t *);
188 extern boolean_t vnic_classifier_is_active(vnic_flow_t *);
189 
190 
191 #ifdef	__cplusplus
192 }
193 #endif
194 
195 #endif	/* _SYS_VNIC_IMPL_H */
196