xref: /titanic_51/usr/src/uts/common/sys/vnic_impl.h (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
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 2008 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 	datalink_id_t		va_linkid;
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 	datalink_id_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 	uint32_t	vn_margin;
100 	vnic_mac_t	*vn_vnic_mac;
101 	vnic_flow_t	*vn_flow_ent;
102 	uint32_t	vn_hcksum_txflags;
103 	struct vnic_s	*vn_promisc_next;
104 
105 	uint64_t	vn_stat_multircv;
106 	uint64_t	vn_stat_brdcstrcv;
107 	uint64_t	vn_stat_multixmt;
108 	uint64_t	vn_stat_brdcstxmt;
109 	uint64_t	vn_stat_ierrors;
110 	uint64_t	vn_stat_oerrors;
111 	uint64_t	vn_stat_rbytes;
112 	uint64_t	vn_stat_ipackets;
113 	uint64_t	vn_stat_obytes;
114 	uint64_t	vn_stat_opackets;
115 } vnic_t;
116 
117 #define	vn_txinfo	vn_vnic_mac->va_txinfo
118 
119 #define	vn_madd_naddr		vn_mma_capab.maddr_naddr
120 #define	vn_maddr_naddrfree	vn_mma_capab.maddr_naddrfree
121 #define	vn_maddr_flag		vn_mma_capab.maddr_flag
122 #define	vn_maddr_handle		vn_mma_capab.maddr_handle
123 #define	vn_maddr_reserve	vn_mma_capab.maddr_reserve
124 #define	vn_maddr_add		vn_mma_capab.maddr_add
125 #define	vn_maddr_remove		vn_mma_capab.maddr_remove
126 #define	vn_maddr_modify		vn_mma_capab.maddr_modify
127 #define	vn_maddr_get		vn_mma_capab.maddr_get
128 
129 #define	VNIC_FLOW_REFHOLD(flow) {				\
130 	mutex_enter(&(flow)->vf_lock);				\
131 	(flow)->vf_refs++;					\
132 	mutex_exit(&(flow)->vf_lock);				\
133 }
134 
135 #define	VNIC_FLOW_REFRELE(flow) {				\
136 	mutex_enter(&(flow)->vf_lock);				\
137 	if (--(flow)->vf_refs == 0 && (flow)->vf_clearing) {	\
138 	    (flow)->vf_clearing = B_FALSE;			\
139 	    cv_signal(&(flow)->vf_cv);				\
140 	}							\
141 	mutex_exit(&(flow)->vf_lock);				\
142 }
143 
144 extern int vnic_dev_create(datalink_id_t, datalink_id_t, int, uchar_t *);
145 extern int vnic_dev_modify(datalink_id_t, uint_t, vnic_mac_addr_type_t,
146     uint_t, uchar_t *);
147 extern int vnic_dev_delete(datalink_id_t);
148 
149 typedef int (*vnic_info_new_vnic_fn_t)(void *, datalink_id_t,
150     vnic_mac_addr_type_t, uint_t, uint8_t *, datalink_id_t);
151 
152 extern void vnic_dev_init(void);
153 extern void vnic_dev_fini(void);
154 extern uint_t vnic_dev_count(void);
155 extern dev_info_t *vnic_get_dip(void);
156 
157 extern int vnic_info(uint_t *, datalink_id_t, datalink_id_t, void *,
158     vnic_info_new_vnic_fn_t);
159 
160 extern void vnic_rx(void *, void *, mblk_t *);
161 extern mblk_t *vnic_fix_cksum(mblk_t *);
162 extern mblk_t *vnic_copymsgchain_cksum(mblk_t *);
163 extern mblk_t *vnic_copymsg_cksum(mblk_t *);
164 
165 extern void vnic_promisc_rx(vnic_mac_t *, vnic_t *, mblk_t *);
166 
167 extern void vnic_bcast_init(void);
168 extern void vnic_bcast_fini(void);
169 extern int vnic_bcast_add(vnic_t *, const uint8_t *, mac_addrtype_t);
170 extern void vnic_bcast_delete(vnic_t *, const uint8_t *);
171 extern void vnic_bcast_send(void *, void *, mblk_t *);
172 
173 extern void vnic_classifier_init(void);
174 extern void vnic_classifier_fini(void);
175 extern vnic_flow_t *vnic_classifier_flow_create(uint_t, uchar_t *, void *,
176     boolean_t, int);
177 extern void vnic_classifier_flow_destroy(vnic_flow_t *);
178 extern void vnic_classifier_flow_add(vnic_mac_t *, vnic_flow_t *, vnic_rx_fn_t,
179     void *, void *);
180 extern void vnic_classifier_flow_remove(vnic_mac_t *, vnic_flow_t *);
181 extern void vnic_classifier_flow_update_addr(vnic_flow_t *, uchar_t *);
182 extern void vnic_classifier_flow_update_fn(vnic_flow_t *, vnic_rx_fn_t,
183     void *, void *);
184 extern int vnic_classifier_flow_tab_init(vnic_mac_t *, uint_t, int);
185 extern void vnic_classifier_flow_tab_fini(vnic_mac_t *);
186 extern vnic_flow_t *vnic_classifier_get_flow(vnic_mac_t *, mblk_t *);
187 extern void *vnic_classifier_get_client_cookie(vnic_flow_t *);
188 extern vnic_flow_fn_info_t *vnic_classifier_get_fn_info(vnic_flow_t *);
189 extern boolean_t vnic_classifier_is_active(vnic_flow_t *);
190 
191 
192 #ifdef	__cplusplus
193 }
194 #endif
195 
196 #endif	/* _SYS_VNIC_IMPL_H */
197