xref: /onnv-gate/usr/src/uts/common/sys/softmac_impl.h (revision 5895:f251acdd9bdc)
1*5895Syz147064 /*
2*5895Syz147064  * CDDL HEADER START
3*5895Syz147064  *
4*5895Syz147064  * The contents of this file are subject to the terms of the
5*5895Syz147064  * Common Development and Distribution License (the "License").
6*5895Syz147064  * You may not use this file except in compliance with the License.
7*5895Syz147064  *
8*5895Syz147064  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5895Syz147064  * or http://www.opensolaris.org/os/licensing.
10*5895Syz147064  * See the License for the specific language governing permissions
11*5895Syz147064  * and limitations under the License.
12*5895Syz147064  *
13*5895Syz147064  * When distributing Covered Code, include this CDDL HEADER in each
14*5895Syz147064  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5895Syz147064  * If applicable, add the following below this CDDL HEADER, with the
16*5895Syz147064  * fields enclosed by brackets "[]" replaced with your own identifying
17*5895Syz147064  * information: Portions Copyright [yyyy] [name of copyright owner]
18*5895Syz147064  *
19*5895Syz147064  * CDDL HEADER END
20*5895Syz147064  */
21*5895Syz147064 /*
22*5895Syz147064  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23*5895Syz147064  * Use is subject to license terms.
24*5895Syz147064  */
25*5895Syz147064 
26*5895Syz147064 #ifndef	_SYS_SOFTMAC_IMPL_H
27*5895Syz147064 #define	_SYS_SOFTMAC_IMPL_H
28*5895Syz147064 
29*5895Syz147064 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30*5895Syz147064 
31*5895Syz147064 #include <sys/types.h>
32*5895Syz147064 #include <sys/ethernet.h>
33*5895Syz147064 #include <sys/taskq.h>
34*5895Syz147064 #include <sys/sunddi.h>
35*5895Syz147064 #include <sys/sunldi.h>
36*5895Syz147064 #include <sys/strsun.h>
37*5895Syz147064 #include <sys/stream.h>
38*5895Syz147064 #include <sys/dlpi.h>
39*5895Syz147064 #include <sys/mac.h>
40*5895Syz147064 #include <sys/mac_ether.h>
41*5895Syz147064 
42*5895Syz147064 #ifdef	__cplusplus
43*5895Syz147064 extern "C" {
44*5895Syz147064 #endif
45*5895Syz147064 
46*5895Syz147064 typedef struct softmac_lower_s {
47*5895Syz147064 	struct softmac		*sl_softmac;
48*5895Syz147064 	queue_t			*sl_wq;
49*5895Syz147064 
50*5895Syz147064 	/*
51*5895Syz147064 	 * sl_ctl_inprogress is used to serialize the control path.  It will
52*5895Syz147064 	 * be set when either an ioctl or an M_{PC,}PROTO message is received
53*5895Syz147064 	 * from the upper layer, and will be cleared when processing done.
54*5895Syz147064 	 */
55*5895Syz147064 	kmutex_t		sl_ctl_mutex;
56*5895Syz147064 	kcondvar_t		sl_ctl_cv;
57*5895Syz147064 	boolean_t		sl_ctl_inprogress;
58*5895Syz147064 
59*5895Syz147064 	/*
60*5895Syz147064 	 * When a control message is processed, either sl_pending_prim or
61*5895Syz147064 	 * sl_pending_ioctl will be set.  They will be cleared when the
62*5895Syz147064 	 * acknowledgement of the specific control message is received
63*5895Syz147064 	 * from the underlying legacy driver.
64*5895Syz147064 	 */
65*5895Syz147064 	kmutex_t		sl_mutex;
66*5895Syz147064 	kcondvar_t		sl_cv;
67*5895Syz147064 	t_uscalar_t		sl_pending_prim;
68*5895Syz147064 	boolean_t		sl_pending_ioctl;
69*5895Syz147064 	mblk_t			*sl_ack_mp;
70*5895Syz147064 
71*5895Syz147064 	mac_resource_handle_t	sl_handle;
72*5895Syz147064 	ldi_handle_t		sl_lh;
73*5895Syz147064 } softmac_lower_t;
74*5895Syz147064 
75*5895Syz147064 enum softmac_state {
76*5895Syz147064 	SOFTMAC_INITIALIZED,
77*5895Syz147064 	SOFTMAC_READY
78*5895Syz147064 };
79*5895Syz147064 
80*5895Syz147064 typedef struct softmac_dev_s {
81*5895Syz147064 	dev_t	sd_dev;
82*5895Syz147064 } softmac_dev_t;
83*5895Syz147064 
84*5895Syz147064 /*
85*5895Syz147064  * smac_flag values.
86*5895Syz147064  */
87*5895Syz147064 #define	SOFTMAC_GLDV3		0x01
88*5895Syz147064 #define	SOFTMAC_NOSUPP		0x02
89*5895Syz147064 #define	SOFTMAC_ATTACH_DONE	0x04
90*5895Syz147064 #define	SOFTMAC_NEED_RECREATE	0x08
91*5895Syz147064 
92*5895Syz147064 /*
93*5895Syz147064  * The softmac structure allows all minor nodes (at most two, style-1 and
94*5895Syz147064  * style-2) for the same device to be processed.  A softmac_dev_t will be
95*5895Syz147064  * created for each minor node.
96*5895Syz147064  *
97*5895Syz147064  * We try to "register" the mac after all the softmac_dev_t's are processed so
98*5895Syz147064  * that even if DLPI operations fail (because of driver bugs) for one minor
99*5895Syz147064  * node, the other minor node can still be used to register the mac.
100*5895Syz147064  * (Specifically, an incorrect xxx_getinfo() implementation will cause style-2
101*5895Syz147064  * minor node mac registration to fail.)
102*5895Syz147064  */
103*5895Syz147064 typedef struct softmac {
104*5895Syz147064 	/*
105*5895Syz147064 	 * The following fields will be set when the softmac is created and
106*5895Syz147064 	 * will not change.  No lock is required.
107*5895Syz147064 	 */
108*5895Syz147064 	char		smac_devname[MAXNAMELEN];
109*5895Syz147064 	major_t		smac_umajor;
110*5895Syz147064 	int		smac_uppa;
111*5895Syz147064 	uint32_t	smac_cnt;	/* # of minor nodes for this device */
112*5895Syz147064 
113*5895Syz147064 	/*
114*5895Syz147064 	 * The following fields are protected by softmac_hash_lock.
115*5895Syz147064 	 */
116*5895Syz147064 	/*
117*5895Syz147064 	 * The smac_hold_cnt field increases when softmac_hold_device() is
118*5895Syz147064 	 * called to force the dls_vlan_t of the device to be created.  The
119*5895Syz147064 	 * device pre-detach fails if this counter is not 0.
120*5895Syz147064 	 */
121*5895Syz147064 	uint32_t	smac_hold_cnt;
122*5895Syz147064 
123*5895Syz147064 	/*
124*5895Syz147064 	 * The following fields are protected by smac_lock.
125*5895Syz147064 	 */
126*5895Syz147064 	kmutex_t	smac_mutex;
127*5895Syz147064 	kcondvar_t	smac_cv;
128*5895Syz147064 	uint32_t	smac_flags;
129*5895Syz147064 	int		smac_attacherr;
130*5895Syz147064 	mac_handle_t	smac_mh;
131*5895Syz147064 	softmac_dev_t	*smac_softmac[2];
132*5895Syz147064 	taskqid_t	smac_taskq;
133*5895Syz147064 	/*
134*5895Syz147064 	 * Number of minor nodes whose post-attach routine has succeeded.
135*5895Syz147064 	 * This should be the same as the numbers of softmac_dev_t.
136*5895Syz147064 	 * Note that it does not imply SOFTMAC_ATTACH_DONE as the taskq might
137*5895Syz147064 	 * be still ongoing.
138*5895Syz147064 	 */
139*5895Syz147064 	uint32_t	smac_attachok_cnt;
140*5895Syz147064 	/*
141*5895Syz147064 	 * Number of softmac_dev_t left when pre-detach fails. This is used
142*5895Syz147064 	 * to indicate whether postattach is called because of a failed
143*5895Syz147064 	 * pre-detach.
144*5895Syz147064 	 */
145*5895Syz147064 	uint32_t	smac_attached_left;
146*5895Syz147064 
147*5895Syz147064 	/*
148*5895Syz147064 	 * This field is set and cleared by users of softmac (who calls
149*5895Syz147064 	 * softmac_hold/rele_device()). It is protected by smac_mutex.
150*5895Syz147064 	 */
151*5895Syz147064 	dev_info_t	*smac_udip;
152*5895Syz147064 
153*5895Syz147064 	/*
154*5895Syz147064 	 * The remaining fields are used to register the MAC for a legacy
155*5895Syz147064 	 * device.  They are set in softmac_mac_register() and do not change.
156*5895Syz147064 	 * One can access them when mac_register() is done without locks.
157*5895Syz147064 	 */
158*5895Syz147064 
159*5895Syz147064 	/*
160*5895Syz147064 	 * media type is needed for create <link name, linkid> mapping, so
161*5895Syz147064 	 * it is set for GLDv3 device as well
162*5895Syz147064 	 */
163*5895Syz147064 	uint_t		smac_media;
164*5895Syz147064 	/* DLPI style of the underlying device */
165*5895Syz147064 	int		smac_style;
166*5895Syz147064 	dev_t		smac_dev;
167*5895Syz147064 	size_t		smac_saplen;
168*5895Syz147064 	size_t		smac_addrlen;
169*5895Syz147064 	uchar_t		smac_unicst_addr[MAXMACADDRLEN];
170*5895Syz147064 	uint_t		smac_min_sdu;
171*5895Syz147064 	uint_t		smac_max_sdu;
172*5895Syz147064 	uint32_t	smac_margin;
173*5895Syz147064 
174*5895Syz147064 	/* Notifications the underlying driver can support. */
175*5895Syz147064 	uint32_t	smac_notifications;
176*5895Syz147064 
177*5895Syz147064 	/*
178*5895Syz147064 	 * Capabilities of the underlying driver.
179*5895Syz147064 	 */
180*5895Syz147064 	uint32_t	smac_capab_flags;
181*5895Syz147064 	uint32_t	smac_hcksum_txflags;
182*5895Syz147064 	boolean_t	smac_no_capability_req;
183*5895Syz147064 	dl_capab_mdt_t	smac_mdt_capab;
184*5895Syz147064 	boolean_t	smac_mdt;
185*5895Syz147064 
186*5895Syz147064 	/*
187*5895Syz147064 	 * The following fields are protected by smac_lock
188*5895Syz147064 	 */
189*5895Syz147064 	krwlock_t	smac_lock;
190*5895Syz147064 	enum softmac_state	smac_state;
191*5895Syz147064 	/* Lower stream structure */
192*5895Syz147064 	softmac_lower_t	*smac_lower;
193*5895Syz147064 } softmac_t;
194*5895Syz147064 
195*5895Syz147064 typedef struct smac_ioc_start_s {
196*5895Syz147064 	softmac_lower_t	*si_slp;
197*5895Syz147064 } smac_ioc_start_t;
198*5895Syz147064 
199*5895Syz147064 #define	SMAC_IOC	('S' << 24 | 'M' << 16 | 'C' << 8)
200*5895Syz147064 #define	SMAC_IOC_START	(SMAC_IOC | 0x01)
201*5895Syz147064 
202*5895Syz147064 #define	SOFTMAC_BLANK_TICKS	128
203*5895Syz147064 #define	SOFTMAC_BLANK_PKT_COUNT	8
204*5895Syz147064 
205*5895Syz147064 extern dev_info_t		*softmac_dip;
206*5895Syz147064 #define	SOFTMAC_DEV_NAME	"softmac"
207*5895Syz147064 
208*5895Syz147064 extern int	softmac_send_bind_req(softmac_lower_t *, uint_t);
209*5895Syz147064 extern int	softmac_send_notify_req(softmac_lower_t *, uint32_t);
210*5895Syz147064 extern int	softmac_send_promisc_req(softmac_lower_t *, t_uscalar_t,
211*5895Syz147064     boolean_t);
212*5895Syz147064 extern void	softmac_init(void);
213*5895Syz147064 extern void	softmac_fini(void);
214*5895Syz147064 extern boolean_t softmac_busy(void);
215*5895Syz147064 extern int	softmac_fill_capab(ldi_handle_t, softmac_t *);
216*5895Syz147064 extern int	softmac_capab_enable(softmac_lower_t *);
217*5895Syz147064 extern void	softmac_rput_process_notdata(queue_t *, mblk_t *);
218*5895Syz147064 extern void	softmac_rput_process_data(softmac_lower_t *, mblk_t *);
219*5895Syz147064 
220*5895Syz147064 extern int	softmac_m_promisc(void *, boolean_t);
221*5895Syz147064 extern int	softmac_m_multicst(void *, boolean_t, const uint8_t *);
222*5895Syz147064 extern int	softmac_m_unicst(void *, const uint8_t *);
223*5895Syz147064 extern void	softmac_m_ioctl(void *, queue_t *, mblk_t *);
224*5895Syz147064 extern int	softmac_m_stat(void *, uint_t, uint64_t *);
225*5895Syz147064 extern mblk_t	*softmac_m_tx(void *, mblk_t *);
226*5895Syz147064 extern void	softmac_m_resources(void *);
227*5895Syz147064 extern int	softmac_proto_tx(softmac_lower_t *, mblk_t *, mblk_t **);
228*5895Syz147064 extern void	softmac_ioctl_tx(softmac_lower_t *, mblk_t *, mblk_t **);
229*5895Syz147064 
230*5895Syz147064 #ifdef	__cplusplus
231*5895Syz147064 }
232*5895Syz147064 #endif
233*5895Syz147064 
234*5895Syz147064 #endif	/* _SYS_SOFTMAC_IMPL_H */
235