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