xref: /titanic_51/usr/src/uts/common/io/softmac/softmac_fp.c (revision 6e1fa242609208de48dfe1939b8814d4dff455a5)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 /*
27  * Softmac data-path switching:
28  *
29  * - Fast-path model
30  *
31  * When the softmac fast-path is used, a dedicated lower-stream
32  * will be opened over the legacy device for each IP/ARP (upper-)stream
33  * over the softMAC, and all DLPI messages (including control messages
34  * and data messages) will be exchanged between the upper-stream and
35  * the corresponding lower-stream directly. Therefore, the data
36  * demultiplexing, filtering and classification processing will be done
37  * by the lower-stream, and the GLDv3 DLS/MAC layer processing will be
38  * no longer needed.
39  *
40  * - Slow-path model
41  *
42  * Some GLDv3 features requires the GLDv3 DLS/MAC layer processing to
43  * not be bypassed to assure its function correctness. For example,
44  * softmac fast-path must be disabled to support GLDv3 VNIC functionality.
45  * In this case, a shared lower-stream will be opened over the legacy
46  * device, which is responsible for implementing the GLDv3 callbacks
47  * and passing RAW data messages between the legacy devices and the GLDv3
48  * framework.
49  *
50  * By default, the softmac fast-path mode will be used to assure the
51  * performance; MAC clients will be able to request to disable the softmac
52  * fast-path mode to support certain features, and if that succeeds,
53  * the system will fallback to the slow-path softmac data-path model.
54  *
55  *
56  * The details of the softmac data fast-path model is stated as below
57  *
58  * 1. When a stream is opened on a softMAC, the softmac module will takes
59  *    over the DLPI processing on this stream;
60  *
61  * 2. For IP/ARP streams over a softMAC, softmac data fast-path will be
62  *    used by default, unless fast-path is disabled by any MAC client
63  *    explicitly. The softmac module first identifies an IP/ARP stream
64  *    by seeing whether there is a SIOCSLIFNAME ioctl sent from upstream,
65  *    if there is one, this stream is either an IP or an ARP stream
66  *    and will use fast-path potentially;
67  *
68  * 3. When the softmac fast-path is used, an dedicated lower-stream will
69  *    be setup for each IP/ARP stream (1-1 mapping). From that point on,
70  *    all control and data messages will be exchanged between the IP/ARP
71  *    upper-stream and the legacy device through this dedicated
72  *    lower-stream. As a result, the DLS/MAC layer processing in GLDv3
73  *    will be skipped, and this greatly improves the performance;
74  *
75  * 4. When the softmac data fast-path is disabled by a MAC client (e.g.,
76  *    by a VNIC), all the IP/ARP upper streams will try to switch from
77  *    the fast-path to the slow-path. The dedicated lower-stream will be
78  *    destroyed, and all the control and data-messages will go through the
79  *    existing GLDv3 code path and (in the end) the shared lower-stream;
80  *
81  * 5. On the other hand, when the last MAC client cancels its fast-path
82  *    disable request, all the IP/ARP streams will try to switch back to
83  *    the fast-path mode;
84  *
85  * Step 5 and 6 both rely on the data-path mode switching process
86  * described below:
87  *
88  * 1) To switch the softmac data-path mode (between fast-path and slow-path),
89  *    softmac will first send a DL_NOTE_REPLUMB DL_NOTIFY_IND message
90  *    upstream over each IP/ARP streams that needs data-path mode switching;
91  *
92  * 2) When IP receives this DL_NOTE_REPLUMB message, it will bring down
93  *    all the IP interfaces on the corresponding ill (IP Lower level
94  *    structure), and bring up those interfaces over again; this will in
95  *    turn cause the ARP to "replumb" the interface.
96  *
97  *    During the replumb process, both IP and ARP will send downstream the
98  *    necessary DL_DISABMULTI_REQ and DL_UNBIND_REQ messages and cleanup
99  *    the old state of the underlying softMAC, following with the necessary
100  *    DL_BIND_REQ and DL_ENABMULTI_REQ messages to setup the new state.
101  *    Between the cleanup and re-setup process, IP/ARP will also send down
102  *    a DL_NOTE_REPLUMB_DONE DL_NOTIFY_CONF messages to the softMAC to
103  *    indicate the *switching point*;
104  *
105  * 3) When softmac receives the DL_NOTE_REPLUMB_DONE message, it either
106  *    creates or destroys the dedicated lower-stream (depending on which
107  *    data-path mode the softMAC switches to), and change the softmac
108  *    data-path mode. From then on, softmac will process all the succeeding
109  *    control messages (including the DL_BIND_REQ and DL_ENABMULTI_REQ
110  *    messages) and data messages based on new data-path mode.
111  */
112 
113 #include <sys/types.h>
114 #include <sys/disp.h>
115 #include <sys/callb.h>
116 #include <sys/sysmacros.h>
117 #include <sys/file.h>
118 #include <sys/vlan.h>
119 #include <sys/dld.h>
120 #include <sys/sockio.h>
121 #include <sys/softmac_impl.h>
122 #include <net/if.h>
123 
124 static kmutex_t		softmac_taskq_lock;
125 static kcondvar_t	softmac_taskq_cv;
126 static list_t		softmac_taskq_list;	/* List of softmac_upper_t */
127 boolean_t		softmac_taskq_quit;
128 boolean_t		softmac_taskq_done;
129 
130 static void		softmac_taskq_dispatch();
131 static int		softmac_fastpath_setup(softmac_upper_t *);
132 static mac_tx_cookie_t	softmac_fastpath_wput_data(softmac_upper_t *, mblk_t *,
133 			    uintptr_t, uint16_t);
134 static void		softmac_datapath_switch_done(softmac_upper_t *);
135 
136 void
137 softmac_fp_init()
138 {
139 	mutex_init(&softmac_taskq_lock, NULL, MUTEX_DRIVER, NULL);
140 	cv_init(&softmac_taskq_cv, NULL, CV_DRIVER, NULL);
141 
142 	softmac_taskq_quit = B_FALSE;
143 	softmac_taskq_done = B_FALSE;
144 	list_create(&softmac_taskq_list, sizeof (softmac_upper_t),
145 	    offsetof(softmac_upper_t, su_taskq_list_node));
146 	(void) thread_create(NULL, 0, softmac_taskq_dispatch, NULL, 0,
147 	    &p0, TS_RUN, minclsyspri);
148 }
149 
150 void
151 softmac_fp_fini()
152 {
153 	/*
154 	 * Request the softmac_taskq thread to quit and wait for it to be done.
155 	 */
156 	mutex_enter(&softmac_taskq_lock);
157 	softmac_taskq_quit = B_TRUE;
158 	cv_signal(&softmac_taskq_cv);
159 	while (!softmac_taskq_done)
160 		cv_wait(&softmac_taskq_cv, &softmac_taskq_lock);
161 	mutex_exit(&softmac_taskq_lock);
162 	list_destroy(&softmac_taskq_list);
163 
164 	mutex_destroy(&softmac_taskq_lock);
165 	cv_destroy(&softmac_taskq_cv);
166 }
167 
168 static boolean_t
169 check_ip_above(queue_t *q)
170 {
171 	queue_t		*next_q;
172 	boolean_t	ret = B_TRUE;
173 
174 	claimstr(q);
175 	next_q = q->q_next;
176 	if (strcmp(next_q->q_qinfo->qi_minfo->mi_idname, "ip") != 0)
177 		ret = B_FALSE;
178 	releasestr(q);
179 	return (ret);
180 }
181 
182 /* ARGSUSED */
183 static int
184 softmac_capab_perim(softmac_upper_t *sup, void *data, uint_t flags)
185 {
186 	switch (flags) {
187 	case DLD_ENABLE:
188 		mutex_enter(&sup->su_mutex);
189 		break;
190 	case DLD_DISABLE:
191 		mutex_exit(&sup->su_mutex);
192 		break;
193 	case DLD_QUERY:
194 		return (MUTEX_HELD(&sup->su_mutex));
195 	}
196 	return (0);
197 }
198 
199 static mac_tx_notify_handle_t
200 softmac_client_tx_notify(softmac_upper_t *sup, mac_tx_notify_t func, void *arg)
201 {
202 	ASSERT(MUTEX_HELD(&sup->su_mutex));
203 
204 	if (func != NULL) {
205 		sup->su_tx_notify_func = func;
206 		sup->su_tx_notify_arg = arg;
207 	} else {
208 		/*
209 		 * Wait for all tx_notify_func call to be done.
210 		 */
211 		while (sup->su_tx_inprocess != 0)
212 			cv_wait(&sup->su_cv, &sup->su_mutex);
213 
214 		sup->su_tx_notify_func = NULL;
215 		sup->su_tx_notify_arg = NULL;
216 	}
217 	return ((mac_tx_notify_handle_t)sup);
218 }
219 
220 static boolean_t
221 softmac_tx_is_flow_blocked(softmac_upper_t *sup, mac_tx_cookie_t cookie)
222 {
223 	ASSERT(cookie == (mac_tx_cookie_t)sup);
224 	return (sup->su_tx_busy);
225 }
226 
227 static int
228 softmac_capab_direct(softmac_upper_t *sup, void *data, uint_t flags)
229 {
230 	dld_capab_direct_t	*direct = data;
231 	softmac_lower_t		*slp = sup->su_slp;
232 
233 	ASSERT(MUTEX_HELD(&sup->su_mutex));
234 
235 	ASSERT(sup->su_mode == SOFTMAC_FASTPATH);
236 
237 	switch (flags) {
238 	case DLD_ENABLE:
239 		if (sup->su_direct)
240 			return (0);
241 
242 		sup->su_direct_rxinfo.slr_rx = (softmac_rx_t)direct->di_rx_cf;
243 		sup->su_direct_rxinfo.slr_arg = direct->di_rx_ch;
244 		slp->sl_rxinfo = &sup->su_direct_rxinfo;
245 		direct->di_tx_df = (uintptr_t)softmac_fastpath_wput_data;
246 		direct->di_tx_dh = sup;
247 		direct->di_tx_fctl_df = (uintptr_t)softmac_tx_is_flow_blocked;
248 		direct->di_tx_fctl_dh = sup;
249 		direct->di_tx_cb_df = (uintptr_t)softmac_client_tx_notify;
250 		direct->di_tx_cb_dh = sup;
251 		sup->su_direct = B_TRUE;
252 		return (0);
253 
254 	case DLD_DISABLE:
255 		if (!sup->su_direct)
256 			return (0);
257 
258 		slp->sl_rxinfo = &sup->su_rxinfo;
259 		sup->su_direct = B_FALSE;
260 		return (0);
261 	}
262 	return (ENOTSUP);
263 }
264 
265 static int
266 softmac_dld_capab(softmac_upper_t *sup, uint_t type, void *data, uint_t flags)
267 {
268 	int	err;
269 
270 	/*
271 	 * Don't enable direct callback capabilities unless the caller is
272 	 * the IP client. When a module is inserted in a stream (_I_INSERT)
273 	 * the stack initiates capability disable, but due to races, the
274 	 * module insertion may complete before the capability disable
275 	 * completes. So we limit the check to DLD_ENABLE case.
276 	 */
277 	if ((flags == DLD_ENABLE && type != DLD_CAPAB_PERIM) &&
278 	    !check_ip_above(sup->su_rq)) {
279 		return (ENOTSUP);
280 	}
281 
282 	switch (type) {
283 	case DLD_CAPAB_DIRECT:
284 		err = softmac_capab_direct(sup, data, flags);
285 		break;
286 
287 	case DLD_CAPAB_PERIM:
288 		err = softmac_capab_perim(sup, data, flags);
289 		break;
290 
291 	default:
292 		err = ENOTSUP;
293 		break;
294 	}
295 	return (err);
296 }
297 
298 static void
299 softmac_capability_advertise(softmac_upper_t *sup, mblk_t *mp)
300 {
301 	dl_capability_ack_t	*dlap;
302 	dl_capability_sub_t	*dlsp;
303 	t_uscalar_t		subsize;
304 	uint8_t			*ptr;
305 	queue_t			*q = sup->su_wq;
306 	mblk_t			*mp1;
307 	softmac_t		*softmac = sup->su_softmac;
308 	boolean_t		dld_capable = B_FALSE;
309 	boolean_t		hcksum_capable = B_FALSE;
310 	boolean_t		zcopy_capable = B_FALSE;
311 	boolean_t		mdt_capable = B_FALSE;
312 
313 	ASSERT(sup->su_mode == SOFTMAC_FASTPATH);
314 
315 	/*
316 	 * Initially assume no capabilities.
317 	 */
318 	subsize = 0;
319 
320 	/*
321 	 * Direct capability negotiation interface between IP and softmac
322 	 */
323 	if (check_ip_above(sup->su_rq)) {
324 		dld_capable = B_TRUE;
325 		subsize += sizeof (dl_capability_sub_t) +
326 		    sizeof (dl_capab_dld_t);
327 	}
328 
329 	/*
330 	 * Check if checksum offload is supported on this MAC.
331 	 */
332 	if (softmac->smac_capab_flags & MAC_CAPAB_HCKSUM) {
333 		hcksum_capable = B_TRUE;
334 		subsize += sizeof (dl_capability_sub_t) +
335 		    sizeof (dl_capab_hcksum_t);
336 	}
337 
338 	/*
339 	 * Check if zerocopy is supported on this interface.
340 	 */
341 	if (!(softmac->smac_capab_flags & MAC_CAPAB_NO_ZCOPY)) {
342 		zcopy_capable = B_TRUE;
343 		subsize += sizeof (dl_capability_sub_t) +
344 		    sizeof (dl_capab_zerocopy_t);
345 	}
346 
347 	if (softmac->smac_mdt) {
348 		mdt_capable = B_TRUE;
349 		subsize += sizeof (dl_capability_sub_t) +
350 		    sizeof (dl_capab_mdt_t);
351 	}
352 
353 	/*
354 	 * If there are no capabilities to advertise or if we
355 	 * can't allocate a response, send a DL_ERROR_ACK.
356 	 */
357 	if ((subsize == 0) || (mp1 = reallocb(mp,
358 	    sizeof (dl_capability_ack_t) + subsize, 0)) == NULL) {
359 		dlerrorack(q, mp, DL_CAPABILITY_REQ, DL_NOTSUPPORTED, 0);
360 		return;
361 	}
362 
363 	mp = mp1;
364 	DB_TYPE(mp) = M_PROTO;
365 	mp->b_wptr = mp->b_rptr + sizeof (dl_capability_ack_t) + subsize;
366 	bzero(mp->b_rptr, MBLKL(mp));
367 	dlap = (dl_capability_ack_t *)mp->b_rptr;
368 	dlap->dl_primitive = DL_CAPABILITY_ACK;
369 	dlap->dl_sub_offset = sizeof (dl_capability_ack_t);
370 	dlap->dl_sub_length = subsize;
371 	ptr = (uint8_t *)&dlap[1];
372 
373 	/*
374 	 * IP polling interface.
375 	 */
376 	if (dld_capable) {
377 		dl_capab_dld_t		dld;
378 
379 		dlsp = (dl_capability_sub_t *)ptr;
380 		dlsp->dl_cap = DL_CAPAB_DLD;
381 		dlsp->dl_length = sizeof (dl_capab_dld_t);
382 		ptr += sizeof (dl_capability_sub_t);
383 
384 		bzero(&dld, sizeof (dl_capab_dld_t));
385 		dld.dld_version = DLD_CURRENT_VERSION;
386 		dld.dld_capab = (uintptr_t)softmac_dld_capab;
387 		dld.dld_capab_handle = (uintptr_t)sup;
388 
389 		dlcapabsetqid(&(dld.dld_mid), sup->su_rq);
390 		bcopy(&dld, ptr, sizeof (dl_capab_dld_t));
391 		ptr += sizeof (dl_capab_dld_t);
392 	}
393 
394 	/*
395 	 * TCP/IP checksum offload.
396 	 */
397 	if (hcksum_capable) {
398 		dl_capab_hcksum_t	hcksum;
399 
400 		dlsp = (dl_capability_sub_t *)ptr;
401 
402 		dlsp->dl_cap = DL_CAPAB_HCKSUM;
403 		dlsp->dl_length = sizeof (dl_capab_hcksum_t);
404 		ptr += sizeof (dl_capability_sub_t);
405 
406 		bzero(&hcksum, sizeof (dl_capab_hcksum_t));
407 		hcksum.hcksum_version = HCKSUM_VERSION_1;
408 		hcksum.hcksum_txflags = softmac->smac_hcksum_txflags;
409 		dlcapabsetqid(&(hcksum.hcksum_mid), sup->su_rq);
410 		bcopy(&hcksum, ptr, sizeof (dl_capab_hcksum_t));
411 		ptr += sizeof (dl_capab_hcksum_t);
412 	}
413 
414 	/*
415 	 * Zero copy
416 	 */
417 	if (zcopy_capable) {
418 		dl_capab_zerocopy_t	zcopy;
419 
420 		dlsp = (dl_capability_sub_t *)ptr;
421 
422 		dlsp->dl_cap = DL_CAPAB_ZEROCOPY;
423 		dlsp->dl_length = sizeof (dl_capab_zerocopy_t);
424 		ptr += sizeof (dl_capability_sub_t);
425 
426 		bzero(&zcopy, sizeof (dl_capab_zerocopy_t));
427 		zcopy.zerocopy_version = ZEROCOPY_VERSION_1;
428 		zcopy.zerocopy_flags = DL_CAPAB_VMSAFE_MEM;
429 		dlcapabsetqid(&(zcopy.zerocopy_mid), sup->su_rq);
430 		bcopy(&zcopy, ptr, sizeof (dl_capab_zerocopy_t));
431 		ptr += sizeof (dl_capab_zerocopy_t);
432 	}
433 
434 	/*
435 	 * MDT
436 	 */
437 	if (mdt_capable) {
438 		dl_capab_mdt_t mdt;
439 
440 		dlsp = (dl_capability_sub_t *)ptr;
441 
442 		dlsp->dl_cap = DL_CAPAB_MDT;
443 		dlsp->dl_length = sizeof (dl_capab_mdt_t);
444 		ptr += sizeof (dl_capability_sub_t);
445 
446 		bzero(&mdt, sizeof (dl_capab_mdt_t));
447 		mdt.mdt_version = MDT_VERSION_2;
448 		mdt.mdt_flags = DL_CAPAB_MDT_ENABLE;
449 		mdt.mdt_hdr_head = softmac->smac_mdt_capab.mdt_hdr_head;
450 		mdt.mdt_hdr_tail = softmac->smac_mdt_capab.mdt_hdr_tail;
451 		mdt.mdt_max_pld = softmac->smac_mdt_capab.mdt_max_pld;
452 		mdt.mdt_span_limit = softmac->smac_mdt_capab.mdt_span_limit;
453 		dlcapabsetqid(&(mdt.mdt_mid), sup->su_rq);
454 		bcopy(&mdt, ptr, sizeof (dl_capab_mdt_t));
455 		ptr += sizeof (dl_capab_mdt_t);
456 	}
457 
458 	ASSERT(ptr == mp->b_rptr + sizeof (dl_capability_ack_t) + subsize);
459 	qreply(q, mp);
460 }
461 
462 static void
463 softmac_capability_req(softmac_upper_t *sup, mblk_t *mp)
464 {
465 	dl_capability_req_t	*dlp = (dl_capability_req_t *)mp->b_rptr;
466 	dl_capability_sub_t	*sp;
467 	size_t			size, len;
468 	offset_t		off, end;
469 	t_uscalar_t		dl_err;
470 	queue_t			*q = sup->su_wq;
471 
472 	ASSERT(sup->su_mode == SOFTMAC_FASTPATH);
473 	if (MBLKL(mp) < sizeof (dl_capability_req_t)) {
474 		dl_err = DL_BADPRIM;
475 		goto failed;
476 	}
477 
478 	if (!sup->su_bound) {
479 		dl_err = DL_OUTSTATE;
480 		goto failed;
481 	}
482 
483 	/*
484 	 * This request is overloaded. If there are no requested capabilities
485 	 * then we just want to acknowledge with all the capabilities we
486 	 * support. Otherwise we enable the set of capabilities requested.
487 	 */
488 	if (dlp->dl_sub_length == 0) {
489 		softmac_capability_advertise(sup, mp);
490 		return;
491 	}
492 
493 	if (!MBLKIN(mp, dlp->dl_sub_offset, dlp->dl_sub_length)) {
494 		dl_err = DL_BADPRIM;
495 		goto failed;
496 	}
497 
498 	dlp->dl_primitive = DL_CAPABILITY_ACK;
499 
500 	off = dlp->dl_sub_offset;
501 	len = dlp->dl_sub_length;
502 
503 	/*
504 	 * Walk the list of capabilities to be enabled.
505 	 */
506 	for (end = off + len; off < end; ) {
507 		sp = (dl_capability_sub_t *)(mp->b_rptr + off);
508 		size = sizeof (dl_capability_sub_t) + sp->dl_length;
509 
510 		if (off + size > end ||
511 		    !IS_P2ALIGNED(off, sizeof (uint32_t))) {
512 			dl_err = DL_BADPRIM;
513 			goto failed;
514 		}
515 
516 		switch (sp->dl_cap) {
517 		/*
518 		 * TCP/IP checksum offload to hardware.
519 		 */
520 		case DL_CAPAB_HCKSUM: {
521 			dl_capab_hcksum_t *hcksump;
522 			dl_capab_hcksum_t hcksum;
523 
524 			hcksump = (dl_capab_hcksum_t *)&sp[1];
525 			/*
526 			 * Copy for alignment.
527 			 */
528 			bcopy(hcksump, &hcksum, sizeof (dl_capab_hcksum_t));
529 			dlcapabsetqid(&(hcksum.hcksum_mid), sup->su_rq);
530 			bcopy(&hcksum, hcksump, sizeof (dl_capab_hcksum_t));
531 			break;
532 		}
533 
534 		default:
535 			break;
536 		}
537 
538 		off += size;
539 	}
540 	qreply(q, mp);
541 	return;
542 failed:
543 	dlerrorack(q, mp, DL_CAPABILITY_REQ, dl_err, 0);
544 }
545 
546 static void
547 softmac_bind_req(softmac_upper_t *sup, mblk_t *mp)
548 {
549 	softmac_lower_t	*slp = sup->su_slp;
550 	softmac_t	*softmac = sup->su_softmac;
551 	mblk_t		*ackmp, *mp1;
552 	int		err;
553 
554 	if (MBLKL(mp) < DL_BIND_REQ_SIZE) {
555 		freemsg(mp);
556 		return;
557 	}
558 
559 	/*
560 	 * Allocate ackmp incase the underlying driver does not ack timely.
561 	 */
562 	if ((mp1 = allocb(sizeof (dl_error_ack_t), BPRI_HI)) == NULL) {
563 		dlerrorack(sup->su_wq, mp, DL_BIND_REQ, DL_SYSERR, ENOMEM);
564 		return;
565 	}
566 
567 	err = softmac_output(slp, mp, DL_BIND_REQ, DL_BIND_ACK, &ackmp);
568 	if (ackmp != NULL) {
569 		freemsg(mp1);
570 	} else {
571 		/*
572 		 * The driver does not ack timely.
573 		 */
574 		ASSERT(err == ENOMSG);
575 		ackmp = mp1;
576 	}
577 	if (err != 0)
578 		goto failed;
579 
580 	/*
581 	 * Enable capabilities the underlying driver claims to support.
582 	 */
583 	if ((err = softmac_capab_enable(slp)) != 0)
584 		goto failed;
585 
586 	/*
587 	 * Check whether this softmac is already marked as exclusively used,
588 	 * e.g., an aggregation is created over it. Fail the BIND_REQ if so.
589 	 */
590 	mutex_enter(&softmac->smac_active_mutex);
591 	if (softmac->smac_active) {
592 		mutex_exit(&softmac->smac_active_mutex);
593 		err = EBUSY;
594 		goto failed;
595 	}
596 	softmac->smac_nactive++;
597 	sup->su_active = B_TRUE;
598 	mutex_exit(&softmac->smac_active_mutex);
599 	sup->su_bound = B_TRUE;
600 
601 	qreply(sup->su_wq, ackmp);
602 	return;
603 failed:
604 	if (err != 0) {
605 		dlerrorack(sup->su_wq, ackmp, DL_BIND_REQ, DL_SYSERR, err);
606 		return;
607 	}
608 }
609 
610 static void
611 softmac_unbind_req(softmac_upper_t *sup, mblk_t *mp)
612 {
613 	softmac_lower_t	*slp = sup->su_slp;
614 	softmac_t	*softmac = sup->su_softmac;
615 	mblk_t		*ackmp, *mp1;
616 	int		err;
617 
618 	if (MBLKL(mp) < DL_UNBIND_REQ_SIZE) {
619 		freemsg(mp);
620 		return;
621 	}
622 
623 	if (!sup->su_bound) {
624 		dlerrorack(sup->su_wq, mp, DL_UNBIND_REQ, DL_OUTSTATE, 0);
625 		return;
626 	}
627 
628 	/*
629 	 * Allocate ackmp incase the underlying driver does not ack timely.
630 	 */
631 	if ((mp1 = allocb(sizeof (dl_error_ack_t), BPRI_HI)) == NULL) {
632 		dlerrorack(sup->su_wq, mp, DL_UNBIND_REQ, DL_SYSERR, ENOMEM);
633 		return;
634 	}
635 
636 	err = softmac_output(slp, mp, DL_UNBIND_REQ, DL_OK_ACK, &ackmp);
637 	if (ackmp != NULL) {
638 		freemsg(mp1);
639 	} else {
640 		/*
641 		 * The driver does not ack timely.
642 		 */
643 		ASSERT(err == ENOMSG);
644 		ackmp = mp1;
645 	}
646 	if (err != 0) {
647 		dlerrorack(sup->su_wq, ackmp, DL_UNBIND_REQ, DL_SYSERR, err);
648 		return;
649 	}
650 
651 	sup->su_bound = B_FALSE;
652 
653 	mutex_enter(&softmac->smac_active_mutex);
654 	if (sup->su_active) {
655 		ASSERT(!softmac->smac_active);
656 		softmac->smac_nactive--;
657 		sup->su_active = B_FALSE;
658 	}
659 	mutex_exit(&softmac->smac_active_mutex);
660 
661 done:
662 	qreply(sup->su_wq, ackmp);
663 }
664 
665 /*
666  * Process the non-data mblk.
667  */
668 static void
669 softmac_wput_single_nondata(softmac_upper_t *sup, mblk_t *mp)
670 {
671 	softmac_t *softmac = sup->su_softmac;
672 	softmac_lower_t	*slp = sup->su_slp;
673 	unsigned char	dbtype;
674 	t_uscalar_t	prim;
675 
676 	dbtype = DB_TYPE(mp);
677 	switch (dbtype) {
678 	case M_IOCTL:
679 	case M_CTL: {
680 		uint32_t	expected_mode;
681 
682 		if (((struct iocblk *)(mp->b_rptr))->ioc_cmd != SIOCSLIFNAME)
683 			break;
684 
685 		/*
686 		 * Nak the M_IOCTL based on the STREAMS specification.
687 		 */
688 		if (dbtype == M_IOCTL)
689 			miocnak(sup->su_wq, mp, 0, EINVAL);
690 		else
691 			freemsg(mp);
692 
693 		/*
694 		 * This stream is either IP or ARP. See whether
695 		 * we need to setup a dedicated-lower-stream for it.
696 		 */
697 		mutex_enter(&softmac->smac_fp_mutex);
698 
699 		expected_mode = DATAPATH_MODE(softmac);
700 		if (expected_mode == SOFTMAC_SLOWPATH)
701 			sup->su_mode = SOFTMAC_SLOWPATH;
702 		list_insert_head(&softmac->smac_sup_list, sup);
703 		mutex_exit(&softmac->smac_fp_mutex);
704 
705 		/*
706 		 * Setup the fast-path dedicated lower stream if fast-path
707 		 * is expected. Note that no lock is held here, and if
708 		 * smac_expected_mode is changed from SOFTMAC_FASTPATH to
709 		 * SOFTMAC_SLOWPATH, the DL_NOTE_REPLUMB message used for
710 		 * data-path switching would already be queued and will
711 		 * be processed by softmac_wput_single_nondata() later.
712 		 */
713 		if (expected_mode == SOFTMAC_FASTPATH)
714 			(void) softmac_fastpath_setup(sup);
715 		return;
716 	}
717 	case M_PROTO:
718 	case M_PCPROTO:
719 		if (MBLKL(mp) < sizeof (t_uscalar_t)) {
720 			freemsg(mp);
721 			return;
722 		}
723 		prim = ((union DL_primitives *)mp->b_rptr)->dl_primitive;
724 		switch (prim) {
725 		case DL_NOTIFY_IND:
726 			if (MBLKL(mp) < sizeof (dl_notify_ind_t) ||
727 			    ((dl_notify_ind_t *)mp->b_rptr)->dl_notification !=
728 			    DL_NOTE_REPLUMB) {
729 				freemsg(mp);
730 				return;
731 			}
732 			/*
733 			 * This DL_NOTE_REPLUMB message is initiated
734 			 * and queued by the softmac itself, when the
735 			 * sup is trying to switching its datapath mode
736 			 * between SOFTMAC_SLOWPATH and SOFTMAC_FASTPATH.
737 			 * Send this message upstream.
738 			 */
739 			qreply(sup->su_wq, mp);
740 			return;
741 		case DL_NOTIFY_CONF:
742 			if (MBLKL(mp) < sizeof (dl_notify_conf_t) ||
743 			    ((dl_notify_conf_t *)mp->b_rptr)->dl_notification !=
744 			    DL_NOTE_REPLUMB_DONE) {
745 				freemsg(mp);
746 				return;
747 			}
748 			/*
749 			 * This is an indication from IP/ARP that the
750 			 * fastpath->slowpath switch is done.
751 			 */
752 			freemsg(mp);
753 			softmac_datapath_switch_done(sup);
754 			return;
755 		}
756 		break;
757 	}
758 
759 	/*
760 	 * No need to hold lock to check su_mode, since su_mode updating only
761 	 * operation is is serialized by softmac_wput_nondata_task().
762 	 */
763 	if (sup->su_mode != SOFTMAC_FASTPATH) {
764 		dld_wput(sup->su_wq, mp);
765 		return;
766 	}
767 
768 	/*
769 	 * Fastpath non-data message processing. Most of non-data messages
770 	 * can be directly passed down to the dedicated-lower-stream, aside
771 	 * from the following M_PROTO/M_PCPROTO messages.
772 	 */
773 	switch (dbtype) {
774 	case M_PROTO:
775 	case M_PCPROTO:
776 		switch (prim) {
777 		case DL_BIND_REQ:
778 			softmac_bind_req(sup, mp);
779 			break;
780 		case DL_UNBIND_REQ:
781 			softmac_unbind_req(sup, mp);
782 			break;
783 		case DL_CAPABILITY_REQ:
784 			softmac_capability_req(sup, mp);
785 			break;
786 		default:
787 			putnext(slp->sl_wq, mp);
788 			break;
789 		}
790 		break;
791 	default:
792 		putnext(slp->sl_wq, mp);
793 		break;
794 	}
795 }
796 
797 /*
798  * The worker thread which processes non-data messages. Note we only process
799  * one message at one time in order to be able to "flush" the queued message
800  * and serialize the processing.
801  */
802 static void
803 softmac_wput_nondata_task(void *arg)
804 {
805 	softmac_upper_t	*sup = arg;
806 	mblk_t		*mp;
807 
808 	mutex_enter(&sup->su_disp_mutex);
809 
810 	while (sup->su_pending_head != NULL) {
811 		if (sup->su_closing)
812 			break;
813 
814 		SOFTMAC_DQ_PENDING(sup, &mp);
815 		mutex_exit(&sup->su_disp_mutex);
816 		softmac_wput_single_nondata(sup, mp);
817 		mutex_enter(&sup->su_disp_mutex);
818 	}
819 
820 	/*
821 	 * If the stream is closing, flush all queued messages and inform
822 	 * the stream to be closed.
823 	 */
824 	freemsgchain(sup->su_pending_head);
825 	sup->su_pending_head = sup->su_pending_tail = NULL;
826 	sup->su_dlpi_pending = B_FALSE;
827 	cv_signal(&sup->su_disp_cv);
828 	mutex_exit(&sup->su_disp_mutex);
829 }
830 
831 /*
832  * Kernel thread to handle taskq dispatch failures in softmac_wput_nondata().
833  * This thread is started when the softmac module is first loaded.
834  */
835 static void
836 softmac_taskq_dispatch(void)
837 {
838 	callb_cpr_t	cprinfo;
839 	softmac_upper_t	*sup;
840 
841 	CALLB_CPR_INIT(&cprinfo, &softmac_taskq_lock, callb_generic_cpr,
842 	    "softmac_taskq_dispatch");
843 	mutex_enter(&softmac_taskq_lock);
844 
845 	while (!softmac_taskq_quit) {
846 		sup = list_head(&softmac_taskq_list);
847 		while (sup != NULL) {
848 			list_remove(&softmac_taskq_list, sup);
849 			sup->su_taskq_scheduled = B_FALSE;
850 			mutex_exit(&softmac_taskq_lock);
851 			VERIFY(taskq_dispatch(system_taskq,
852 			    softmac_wput_nondata_task, sup, TQ_SLEEP) != NULL);
853 			mutex_enter(&softmac_taskq_lock);
854 			sup = list_head(&softmac_taskq_list);
855 		}
856 
857 		CALLB_CPR_SAFE_BEGIN(&cprinfo);
858 		cv_wait(&softmac_taskq_cv, &softmac_taskq_lock);
859 		CALLB_CPR_SAFE_END(&cprinfo, &softmac_taskq_lock);
860 	}
861 
862 	softmac_taskq_done = B_TRUE;
863 	cv_signal(&softmac_taskq_cv);
864 	CALLB_CPR_EXIT(&cprinfo);
865 	thread_exit();
866 }
867 
868 void
869 softmac_wput_nondata(softmac_upper_t *sup, mblk_t *mp)
870 {
871 	/*
872 	 * The processing of the message might block. Enqueue the
873 	 * message for later processing.
874 	 */
875 	mutex_enter(&sup->su_disp_mutex);
876 
877 	if (sup->su_closing) {
878 		mutex_exit(&sup->su_disp_mutex);
879 		freemsg(mp);
880 		return;
881 	}
882 
883 	SOFTMAC_EQ_PENDING(sup, mp);
884 
885 	if (sup->su_dlpi_pending) {
886 		mutex_exit(&sup->su_disp_mutex);
887 		return;
888 	}
889 	sup->su_dlpi_pending = B_TRUE;
890 	mutex_exit(&sup->su_disp_mutex);
891 
892 	if (taskq_dispatch(system_taskq, softmac_wput_nondata_task,
893 	    sup, TQ_NOSLEEP) != NULL) {
894 		return;
895 	}
896 
897 	mutex_enter(&softmac_taskq_lock);
898 	if (!sup->su_taskq_scheduled) {
899 		list_insert_tail(&softmac_taskq_list, sup);
900 		cv_signal(&softmac_taskq_cv);
901 	}
902 	sup->su_taskq_scheduled = B_TRUE;
903 	mutex_exit(&softmac_taskq_lock);
904 }
905 
906 /*
907  * Setup the dedicated-lower-stream (fast-path) for the IP/ARP upperstream.
908  */
909 static int
910 softmac_fastpath_setup(softmac_upper_t *sup)
911 {
912 	softmac_t	*softmac = sup->su_softmac;
913 	softmac_lower_t	*slp;
914 	int		err;
915 
916 	err = softmac_lower_setup(softmac, sup, &slp);
917 
918 	mutex_enter(&sup->su_mutex);
919 	/*
920 	 * Wait for all data messages to be processed so that we can change
921 	 * the su_mode.
922 	 */
923 	while (sup->su_tx_inprocess != 0)
924 		cv_wait(&sup->su_cv, &sup->su_mutex);
925 
926 	ASSERT(sup->su_mode != SOFTMAC_FASTPATH);
927 	ASSERT(sup->su_slp == NULL);
928 	if (err != 0) {
929 		sup->su_mode = SOFTMAC_SLOWPATH;
930 	} else {
931 		sup->su_slp = slp;
932 		sup->su_mode = SOFTMAC_FASTPATH;
933 	}
934 	mutex_exit(&sup->su_mutex);
935 	return (err);
936 }
937 
938 /*
939  * Tear down the dedicated-lower-stream (fast-path) for the IP/ARP upperstream.
940  */
941 static void
942 softmac_fastpath_tear(softmac_upper_t *sup)
943 {
944 	mutex_enter(&sup->su_mutex);
945 	/*
946 	 * Wait for all data messages in the dedicated-lower-stream
947 	 * to be processed.
948 	 */
949 	while (sup->su_tx_inprocess != 0)
950 		cv_wait(&sup->su_cv, &sup->su_mutex);
951 
952 	/*
953 	 * Note that this function is called either when the stream is closed,
954 	 * or the stream is unbound (fastpath-slowpath-switch). Therefore,
955 	 * No need to call the tx_notify callback.
956 	 */
957 	sup->su_tx_notify_func = NULL;
958 	sup->su_tx_notify_arg = NULL;
959 	if (sup->su_tx_busy) {
960 		ASSERT(sup->su_tx_flow_mp == NULL);
961 		VERIFY((sup->su_tx_flow_mp = getq(sup->su_wq)) != NULL);
962 		sup->su_tx_busy = B_FALSE;
963 	}
964 
965 	sup->su_mode = SOFTMAC_SLOWPATH;
966 
967 	/*
968 	 * Destroy the dedicated-lower-stream. Note that slp is destroyed
969 	 * when lh is closed.
970 	 */
971 	(void) ldi_close(sup->su_slp->sl_lh, FREAD|FWRITE, kcred);
972 	sup->su_slp = NULL;
973 	mutex_exit(&sup->su_mutex);
974 }
975 
976 void
977 softmac_wput_data(softmac_upper_t *sup, mblk_t *mp)
978 {
979 	/*
980 	 * No lock is required to access the su_mode field since the data
981 	 * traffic is quiesce by IP when the data-path mode is in the
982 	 * process of switching.
983 	 */
984 	if (sup->su_mode != SOFTMAC_FASTPATH)
985 		dld_wput(sup->su_wq, mp);
986 	else
987 		(void) softmac_fastpath_wput_data(sup, mp, NULL, 0);
988 }
989 
990 /*ARGSUSED*/
991 static mac_tx_cookie_t
992 softmac_fastpath_wput_data(softmac_upper_t *sup, mblk_t *mp, uintptr_t f_hint,
993     uint16_t flag)
994 {
995 	queue_t		*wq = sup->su_slp->sl_wq;
996 
997 	/*
998 	 * This function is called from IP, only the MAC_DROP_ON_NO_DESC
999 	 * flag can be specified.
1000 	 */
1001 	ASSERT((flag & ~MAC_DROP_ON_NO_DESC) == 0);
1002 	ASSERT(mp->b_next == NULL);
1003 
1004 	/*
1005 	 * Check wether the dedicated-lower-stream is able to handle more
1006 	 * messages, and enable the flow-control if it is not.
1007 	 *
1008 	 * Note that in order not to introduce any packet reordering, we
1009 	 * always send the message down to the dedicated-lower-stream:
1010 	 *
1011 	 * If the flow-control is already enabled, but we still get
1012 	 * the messages from the upper-stream, it means that the upper
1013 	 * stream does not respect STREAMS flow-control (e.g., TCP). Simply
1014 	 * pass the message down to the lower-stream in that case.
1015 	 */
1016 	if (SOFTMAC_CANPUTNEXT(wq)) {
1017 		putnext(wq, mp);
1018 		return (NULL);
1019 	}
1020 
1021 	if (sup->su_tx_busy) {
1022 		if ((flag & MAC_DROP_ON_NO_DESC) != 0)
1023 			freemsg(mp);
1024 		else
1025 			putnext(wq, mp);
1026 		return ((mac_tx_cookie_t)sup);
1027 	}
1028 
1029 	mutex_enter(&sup->su_mutex);
1030 	if (!sup->su_tx_busy) {
1031 		/*
1032 		 * If DLD_CAPAB_DIRECT is enabled, the notify callback will be
1033 		 * called when the flow control can be disabled. Otherwise,
1034 		 * put the tx_flow_mp into the wq to make use of the old
1035 		 * streams flow control.
1036 		 */
1037 		ASSERT(sup->su_tx_flow_mp != NULL);
1038 		(void) putq(sup->su_wq, sup->su_tx_flow_mp);
1039 		sup->su_tx_flow_mp = NULL;
1040 		sup->su_tx_busy = B_TRUE;
1041 		qenable(wq);
1042 	}
1043 	mutex_exit(&sup->su_mutex);
1044 
1045 	if ((flag & MAC_DROP_ON_NO_DESC) != 0)
1046 		freemsg(mp);
1047 	else
1048 		putnext(wq, mp);
1049 	return ((mac_tx_cookie_t)sup);
1050 }
1051 
1052 boolean_t
1053 softmac_active_set(void *arg)
1054 {
1055 	softmac_t	*softmac = arg;
1056 
1057 	mutex_enter(&softmac->smac_active_mutex);
1058 	if (softmac->smac_nactive != 0) {
1059 		mutex_exit(&softmac->smac_active_mutex);
1060 		return (B_FALSE);
1061 	}
1062 	softmac->smac_active = B_TRUE;
1063 	mutex_exit(&softmac->smac_active_mutex);
1064 	return (B_TRUE);
1065 }
1066 
1067 void
1068 softmac_active_clear(void *arg)
1069 {
1070 	softmac_t	*softmac = arg;
1071 
1072 	mutex_enter(&softmac->smac_active_mutex);
1073 	ASSERT(softmac->smac_active && (softmac->smac_nactive == 0));
1074 	softmac->smac_active = B_FALSE;
1075 	mutex_exit(&softmac->smac_active_mutex);
1076 }
1077 
1078 /*
1079  * Disable/reenable fastpath on given softmac. This request could come from a
1080  * MAC client or directly from administrators.
1081  */
1082 int
1083 softmac_datapath_switch(softmac_t *softmac, boolean_t disable, boolean_t admin)
1084 {
1085 	softmac_upper_t		*sup;
1086 	mblk_t			*head = NULL, *tail = NULL, *mp;
1087 	list_t			reqlist;
1088 	softmac_switch_req_t	*req;
1089 	uint32_t		current_mode, expected_mode;
1090 	int			err = 0;
1091 
1092 	mutex_enter(&softmac->smac_fp_mutex);
1093 
1094 	current_mode = DATAPATH_MODE(softmac);
1095 	if (admin) {
1096 		if (softmac->smac_fastpath_admin_disabled == disable) {
1097 			mutex_exit(&softmac->smac_fp_mutex);
1098 			return (0);
1099 		}
1100 		softmac->smac_fastpath_admin_disabled = disable;
1101 	} else if (disable) {
1102 		softmac->smac_fp_disable_clients++;
1103 	} else {
1104 		ASSERT(softmac->smac_fp_disable_clients != 0);
1105 		softmac->smac_fp_disable_clients--;
1106 	}
1107 
1108 	expected_mode = DATAPATH_MODE(softmac);
1109 	if (current_mode == expected_mode) {
1110 		mutex_exit(&softmac->smac_fp_mutex);
1111 		return (0);
1112 	}
1113 
1114 	/*
1115 	 * The expected mode is different from whatever datapath mode
1116 	 * this softmac is expected from last request, enqueue the data-path
1117 	 * switch request.
1118 	 */
1119 	list_create(&reqlist, sizeof (softmac_switch_req_t),
1120 	    offsetof(softmac_switch_req_t, ssq_req_list_node));
1121 
1122 	/*
1123 	 * Allocate all DL_NOTIFY_IND messages and request structures that
1124 	 * are required to switch each IP/ARP stream to the expected mode.
1125 	 */
1126 	for (sup = list_head(&softmac->smac_sup_list); sup != NULL;
1127 	    sup = list_next(&softmac->smac_sup_list, sup)) {
1128 		dl_notify_ind_t	*dlip;
1129 
1130 		req = kmem_alloc(sizeof (softmac_switch_req_t), KM_NOSLEEP);
1131 		if (req == NULL)
1132 			break;
1133 
1134 		req->ssq_expected_mode = expected_mode;
1135 
1136 		/*
1137 		 * Allocate the DL_NOTE_REPLUMB message.
1138 		 */
1139 		if ((mp = allocb(sizeof (dl_notify_ind_t), BPRI_LO)) == NULL) {
1140 			kmem_free(req, sizeof (softmac_switch_req_t));
1141 			break;
1142 		}
1143 
1144 		list_insert_tail(&reqlist, req);
1145 
1146 		mp->b_wptr = mp->b_rptr + sizeof (dl_notify_ind_t);
1147 		mp->b_datap->db_type = M_PROTO;
1148 		bzero(mp->b_rptr, sizeof (dl_notify_ind_t));
1149 		dlip = (dl_notify_ind_t *)mp->b_rptr;
1150 		dlip->dl_primitive = DL_NOTIFY_IND;
1151 		dlip->dl_notification = DL_NOTE_REPLUMB;
1152 		if (head == NULL) {
1153 			head = tail = mp;
1154 		} else {
1155 			tail->b_next = mp;
1156 			tail = mp;
1157 		}
1158 	}
1159 
1160 	/*
1161 	 * Note that it is fine if the expected data-path mode is fast-path
1162 	 * and some of streams fails to switch. Only return failure if we
1163 	 * are expected to switch to the slow-path.
1164 	 */
1165 	if (sup != NULL && expected_mode == SOFTMAC_SLOWPATH) {
1166 		err = ENOMEM;
1167 		goto fail;
1168 	}
1169 
1170 	/*
1171 	 * Start switching for each IP/ARP stream. The switching operation
1172 	 * will eventually succeed and there is no need to wait for it
1173 	 * to finish.
1174 	 */
1175 	for (sup = list_head(&softmac->smac_sup_list); sup != NULL;
1176 	    sup = list_next(&softmac->smac_sup_list, sup)) {
1177 		mp = head->b_next;
1178 		head->b_next = NULL;
1179 
1180 		/*
1181 		 * Add the swtich request to the requests list of the stream.
1182 		 */
1183 		req = list_head(&reqlist);
1184 		ASSERT(req != NULL);
1185 		list_remove(&reqlist, req);
1186 		list_insert_tail(&sup->su_req_list, req);
1187 		softmac_wput_nondata(sup, head);
1188 		head = mp;
1189 	}
1190 
1191 	mutex_exit(&softmac->smac_fp_mutex);
1192 	ASSERT(list_is_empty(&reqlist));
1193 	list_destroy(&reqlist);
1194 	return (0);
1195 fail:
1196 	if (admin) {
1197 		softmac->smac_fastpath_admin_disabled = !disable;
1198 	} else if (disable) {
1199 		softmac->smac_fp_disable_clients--;
1200 	} else {
1201 		softmac->smac_fp_disable_clients++;
1202 	}
1203 
1204 	mutex_exit(&softmac->smac_fp_mutex);
1205 	while ((req = list_head(&reqlist)) != NULL) {
1206 		list_remove(&reqlist, req);
1207 		kmem_free(req, sizeof (softmac_switch_req_t));
1208 	}
1209 	freemsgchain(head);
1210 	list_destroy(&reqlist);
1211 	return (err);
1212 }
1213 
1214 int
1215 softmac_fastpath_disable(void *arg)
1216 {
1217 	return (softmac_datapath_switch((softmac_t *)arg, B_TRUE, B_FALSE));
1218 }
1219 
1220 void
1221 softmac_fastpath_enable(void *arg)
1222 {
1223 	VERIFY(softmac_datapath_switch((softmac_t *)arg, B_FALSE,
1224 	    B_FALSE) == 0);
1225 }
1226 
1227 void
1228 softmac_upperstream_close(softmac_upper_t *sup)
1229 {
1230 	softmac_t		*softmac = sup->su_softmac;
1231 	softmac_switch_req_t	*req;
1232 
1233 	mutex_enter(&softmac->smac_fp_mutex);
1234 
1235 	if (sup->su_mode == SOFTMAC_FASTPATH)
1236 		softmac_fastpath_tear(sup);
1237 
1238 	if (sup->su_mode != SOFTMAC_UNKNOWN) {
1239 		list_remove(&softmac->smac_sup_list, sup);
1240 		sup->su_mode = SOFTMAC_UNKNOWN;
1241 	}
1242 
1243 	/*
1244 	 * Cleanup all the switch requests queueed on this stream.
1245 	 */
1246 	while ((req = list_head(&sup->su_req_list)) != NULL) {
1247 		list_remove(&sup->su_req_list, req);
1248 		kmem_free(req, sizeof (softmac_switch_req_t));
1249 	}
1250 	mutex_exit(&softmac->smac_fp_mutex);
1251 }
1252 
1253 /*
1254  * Handle the DL_NOTE_REPLUMB_DONE indication from IP/ARP. Change the upper
1255  * stream from the fastpath mode to the slowpath mode.
1256  */
1257 static void
1258 softmac_datapath_switch_done(softmac_upper_t *sup)
1259 {
1260 	softmac_t		*softmac = sup->su_softmac;
1261 	softmac_switch_req_t	*req;
1262 	uint32_t		expected_mode;
1263 
1264 	mutex_enter(&softmac->smac_fp_mutex);
1265 	req = list_head(&sup->su_req_list);
1266 	list_remove(&sup->su_req_list, req);
1267 	expected_mode = req->ssq_expected_mode;
1268 	kmem_free(req, sizeof (softmac_switch_req_t));
1269 
1270 	if (expected_mode == sup->su_mode) {
1271 		mutex_exit(&softmac->smac_fp_mutex);
1272 		return;
1273 	}
1274 
1275 	ASSERT(!sup->su_bound);
1276 	mutex_exit(&softmac->smac_fp_mutex);
1277 
1278 	/*
1279 	 * It is fine if the expected mode is fast-path and we fail
1280 	 * to enable fastpath on this stream.
1281 	 */
1282 	if (expected_mode == SOFTMAC_SLOWPATH)
1283 		softmac_fastpath_tear(sup);
1284 	else
1285 		(void) softmac_fastpath_setup(sup);
1286 }
1287