softmac_impl.h revision 8527:e756d7a0e653
1193323Sed/*
2193323Sed * CDDL HEADER START
3193323Sed *
4193323Sed * The contents of this file are subject to the terms of the
5193323Sed * Common Development and Distribution License (the "License").
6193323Sed * You may not use this file except in compliance with the License.
7193323Sed *
8193323Sed * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9193323Sed * or http://www.opensolaris.org/os/licensing.
10193323Sed * See the License for the specific language governing permissions
11193323Sed * and limitations under the License.
12193323Sed *
13193323Sed * When distributing Covered Code, include this CDDL HEADER in each
14193323Sed * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15193323Sed * If applicable, add the following below this CDDL HEADER, with the
16193323Sed * fields enclosed by brackets "[]" replaced with your own identifying
17193323Sed * information: Portions Copyright [yyyy] [name of copyright owner]
18198090Srdivacky *
19193323Sed * CDDL HEADER END
20193323Sed */
21194612Sed/*
22198090Srdivacky * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23193323Sed * Use is subject to license terms.
24193323Sed */
25193323Sed
26193323Sed#ifndef	_SYS_SOFTMAC_IMPL_H
27194178Sed#define	_SYS_SOFTMAC_IMPL_H
28193323Sed
29194612Sed#include <sys/types.h>
30193323Sed#include <sys/ethernet.h>
31193323Sed#include <sys/taskq.h>
32194612Sed#include <sys/sunddi.h>
33198090Srdivacky#include <sys/sunldi.h>
34194178Sed#include <sys/strsun.h>
35194178Sed#include <sys/stream.h>
36194178Sed#include <sys/dlpi.h>
37194612Sed#include <sys/mac.h>
38194178Sed#include <sys/mac_provider.h>
39194178Sed#include <sys/mac_client.h>
40193323Sed#include <sys/mac_client_priv.h>
41193323Sed#include <sys/mac_ether.h>
42193323Sed
43193323Sed#ifdef	__cplusplus
44199481Srdivackyextern "C" {
45199481Srdivacky#endif
46194178Sed
47194612Sedtypedef struct softmac_lower_s {
48194612Sed	struct softmac		*sl_softmac;
49194612Sed	queue_t			*sl_wq;
50194612Sed
51194612Sed	/*
52194612Sed	 * sl_ctl_inprogress is used to serialize the control path.  It will
53193323Sed	 * be set when either an ioctl or an M_{PC,}PROTO message is received
54194178Sed	 * from the upper layer, and will be cleared when processing done.
55194178Sed	 */
56194178Sed	kmutex_t		sl_ctl_mutex;
57193323Sed	kcondvar_t		sl_ctl_cv;
58198892Srdivacky	boolean_t		sl_ctl_inprogress;
59193323Sed
60193323Sed	/*
61193323Sed	 * When a control message is processed, either sl_pending_prim or
62193323Sed	 * sl_pending_ioctl will be set.  They will be cleared when the
63193323Sed	 * acknowledgement of the specific control message is received
64193323Sed	 * from the underlying legacy driver.
65193323Sed	 */
66198090Srdivacky	kmutex_t		sl_mutex;
67193323Sed	kcondvar_t		sl_cv;
68193323Sed	t_uscalar_t		sl_pending_prim;
69193323Sed	boolean_t		sl_pending_ioctl;
70193323Sed	mblk_t			*sl_ack_mp;
71193323Sed
72193323Sed	ldi_handle_t		sl_lh;
73193323Sed} softmac_lower_t;
74193323Sed
75193323Sedtypedef enum {
76193323Sed	SOFTMAC_INITIALIZED,
77193323Sed	SOFTMAC_READY
78193323Sed} softmac_lower_state_t;
79193323Sed
80193323Sedtypedef enum {
81201360Srdivacky	SOFTMAC_UNINIT,
82193323Sed	SOFTMAC_ATTACH_INPROG,
83193323Sed	SOFTMAC_ATTACH_DONE,
84193323Sed	SOFTMAC_DETACH_INPROG,
85193323Sed} softmac_state_t;
86193574Sed
87193574Sedtypedef struct softmac_dev_s {
88193574Sed	dev_t	sd_dev;
89193574Sed} softmac_dev_t;
90201360Srdivacky
91201360Srdivacky/*
92201360Srdivacky * smac_flag values.
93201360Srdivacky */
94201360Srdivacky#define	SOFTMAC_GLDV3		0x01
95201360Srdivacky#define	SOFTMAC_NOSUPP		0x02
96201360Srdivacky#define	SOFTMAC_NEED_RECREATE	0x04
97201360Srdivacky#define	SOFTMAC_NOTIFY_QUIT	0x08
98201360Srdivacky
99201360Srdivacky#define	SMAC_NONZERO_NODECNT(softmac)		\
100201360Srdivacky	((softmac->smac_softmac[0] != NULL) +	\
101201360Srdivacky	(softmac->smac_softmac[1] != NULL))
102201360Srdivacky
103201360Srdivacky/*
104193574Sed * The softmac structure allows all minor nodes (at most two, style-1 and
105193574Sed * style-2) for the same device to be processed.  A softmac_dev_t will be
106193574Sed * created for each minor node.
107193574Sed *
108193574Sed * We try to "register" the mac after all the softmac_dev_t's are processed so
109193323Sed * that even if DLPI operations fail (because of driver bugs) for one minor
110193323Sed * node, the other minor node can still be used to register the mac.
111194612Sed * (Specifically, an incorrect xxx_getinfo() implementation will cause style-2
112194612Sed * minor node mac registration to fail.)
113198090Srdivacky */
114198090Srdivackytypedef struct softmac {
115198090Srdivacky	/*
116198090Srdivacky	 * The following fields will be set when the softmac is created and
117198090Srdivacky	 * will not change.  No lock is required.
118198090Srdivacky	 */
119198090Srdivacky	char		smac_devname[MAXNAMELEN];
120198090Srdivacky	major_t		smac_umajor;
121198090Srdivacky	int		smac_uppa;
122193323Sed	uint32_t	smac_cnt;	/* # of minor nodes for this device */
123193323Sed
124193323Sed	/*
125193323Sed	 * The following fields are protected by smac_mutex.
126193323Sed	 *
127193323Sed	 * The smac_hold_cnt field increases when softmac_hold_device() is
128193323Sed	 * called to force the dls_vlan_t of the device to be created.  The
129193323Sed	 * device pre-detach fails if this counter is not 0.
130193323Sed	 */
131193323Sed	softmac_state_t	smac_state;
132193323Sed	uint32_t	smac_hold_cnt;
133193323Sed	kmutex_t	smac_mutex;
134193323Sed	kcondvar_t	smac_cv;
135193323Sed	uint32_t	smac_flags;
136198090Srdivacky	int		smac_attacherr;
137198090Srdivacky	mac_handle_t	smac_mh;
138198090Srdivacky	softmac_dev_t	*smac_softmac[2];
139198090Srdivacky	/*
140198090Srdivacky	 * Number of minor nodes whose post-attach routine has succeeded.
141198090Srdivacky	 * This should be the same as the numbers of softmac_dev_t.
142198090Srdivacky	 * Note that it does not imply SOFTMAC_ATTACH_DONE as the taskq might
143198090Srdivacky	 * be still ongoing.
144199481Srdivacky	 */
145199481Srdivacky	uint32_t	smac_attachok_cnt;
146199481Srdivacky	/*
147199481Srdivacky	 * Number of softmac_dev_t left when pre-detach fails. This is used
148199481Srdivacky	 * to indicate whether postattach is called because of a failed
149199481Srdivacky	 * pre-detach.
150199481Srdivacky	 */
151199481Srdivacky	uint32_t	smac_attached_left;
152199481Srdivacky
153199481Srdivacky	/*
154199481Srdivacky	 * Thread handles the DL_NOTIFY_IND message from the lower stream.
155199481Srdivacky	 */
156198090Srdivacky	kthread_t	*smac_notify_thread;
157193323Sed	/*
158193323Sed	 * Head and tail of the DL_NOTIFY_IND messsages.
159193323Sed	 */
160193323Sed	mblk_t		*smac_notify_head;
161198090Srdivacky	mblk_t		*smac_notify_tail;
162198090Srdivacky
163198090Srdivacky	/*
164198090Srdivacky	 * The remaining fields are used to register the MAC for a legacy
165198090Srdivacky	 * device.  They are set in softmac_mac_register() and do not change.
166198090Srdivacky	 * One can access them when mac_register() is done without locks.
167198090Srdivacky	 */
168198090Srdivacky
169198090Srdivacky	/*
170198090Srdivacky	 * media type is needed for create <link name, linkid> mapping, so
171198090Srdivacky	 * it is set for GLDv3 device as well
172198090Srdivacky	 */
173198090Srdivacky	uint_t		smac_media;
174198090Srdivacky	/* DLPI style of the underlying device */
175198090Srdivacky	int		smac_style;
176198090Srdivacky	dev_t		smac_dev;
177193574Sed	size_t		smac_saplen;
178193323Sed	size_t		smac_addrlen;
179198090Srdivacky	uchar_t		smac_unicst_addr[MAXMACADDRLEN];
180193574Sed	uint_t		smac_min_sdu;
181193574Sed	uint_t		smac_max_sdu;
182193574Sed	uint32_t	smac_margin;
183193574Sed
184193574Sed	/* Notifications the underlying driver can support. */
185193574Sed	uint32_t	smac_notifications;
186193574Sed
187193323Sed	/*
188193323Sed	 * Capabilities of the underlying driver.
189193323Sed	 */
190193323Sed	uint32_t	smac_capab_flags;
191193323Sed	uint32_t	smac_hcksum_txflags;
192193323Sed	boolean_t	smac_no_capability_req;
193198090Srdivacky	dl_capab_mdt_t	smac_mdt_capab;
194198090Srdivacky	boolean_t	smac_mdt;
195198090Srdivacky
196198090Srdivacky	/* Following fields protected by the mac perimeter */
197198090Srdivacky	softmac_lower_state_t	smac_lower_state;
198193323Sed	/* Lower stream structure */
199198090Srdivacky	softmac_lower_t	*smac_lower;
200198090Srdivacky} softmac_t;
201198090Srdivacky
202198090Srdivackytypedef struct smac_ioc_start_s {
203193323Sed	softmac_lower_t	*si_slp;
204198090Srdivacky} smac_ioc_start_t;
205193323Sed
206198090Srdivacky#define	SMAC_IOC	('S' << 24 | 'M' << 16 | 'C' << 8)
207193323Sed#define	SMAC_IOC_START	(SMAC_IOC | 0x01)
208193323Sed
209193323Sedextern dev_info_t		*softmac_dip;
210193323Sed#define	SOFTMAC_DEV_NAME	"softmac"
211193323Sed
212193323Sedextern int	softmac_send_bind_req(softmac_lower_t *, uint_t);
213193323Sedextern int	softmac_send_notify_req(softmac_lower_t *, uint32_t);
214198090Srdivackyextern int	softmac_send_promisc_req(softmac_lower_t *, t_uscalar_t,
215193323Sed    boolean_t);
216193323Sedextern void	softmac_init(void);
217193323Sedextern void	softmac_fini(void);
218193323Sedextern boolean_t softmac_busy(void);
219193323Sedextern int	softmac_fill_capab(ldi_handle_t, softmac_t *);
220193323Sedextern int	softmac_capab_enable(softmac_lower_t *);
221193323Sedextern void	softmac_rput_process_notdata(queue_t *, mblk_t *);
222193323Sedextern void	softmac_rput_process_data(softmac_lower_t *, mblk_t *);
223193323Sed
224198090Srdivackyextern int	softmac_m_promisc(void *, boolean_t);
225198090Srdivackyextern int	softmac_m_multicst(void *, boolean_t, const uint8_t *);
226198090Srdivackyextern int	softmac_m_unicst(void *, const uint8_t *);
227193323Sedextern void	softmac_m_ioctl(void *, queue_t *, mblk_t *);
228198090Srdivackyextern int	softmac_m_stat(void *, uint_t, uint64_t *);
229198090Srdivackyextern mblk_t	*softmac_m_tx(void *, mblk_t *);
230198090Srdivackyextern int	softmac_proto_tx(softmac_lower_t *, mblk_t *, mblk_t **);
231193323Sedextern void	softmac_ioctl_tx(softmac_lower_t *, mblk_t *, mblk_t **);
232193323Sedextern void	softmac_notify_thread(void *);
233198090Srdivacky
234198090Srdivacky#ifdef	__cplusplus
235193323Sed}
236198090Srdivacky#endif
237193323Sed
238193323Sed#endif	/* _SYS_SOFTMAC_IMPL_H */
239193323Sed