10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
51502Sericheng  * Common Development and Distribution License (the "License").
61502Sericheng  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
228833SVenu.Iyer@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * Data-Link Driver
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate #include <sys/sysmacros.h>
308275SEric Cheng #include <sys/strsubr.h>
310Sstevel@tonic-gate #include <sys/strsun.h>
320Sstevel@tonic-gate #include <sys/vlan.h>
330Sstevel@tonic-gate #include <sys/dld_impl.h>
348275SEric Cheng #include <sys/mac_client.h>
358275SEric Cheng #include <sys/mac_client_impl.h>
368275SEric Cheng #include <sys/mac_client_priv.h>
370Sstevel@tonic-gate 
388275SEric Cheng typedef void proto_reqfunc_t(dld_str_t *, mblk_t *);
390Sstevel@tonic-gate 
400Sstevel@tonic-gate static proto_reqfunc_t proto_info_req, proto_attach_req, proto_detach_req,
410Sstevel@tonic-gate     proto_bind_req, proto_unbind_req, proto_promiscon_req, proto_promiscoff_req,
420Sstevel@tonic-gate     proto_enabmulti_req, proto_disabmulti_req, proto_physaddr_req,
430Sstevel@tonic-gate     proto_setphysaddr_req, proto_udqos_req, proto_req, proto_capability_req,
445895Syz147064     proto_notify_req, proto_passive_req;
450Sstevel@tonic-gate 
468275SEric Cheng static void proto_capability_advertise(dld_str_t *, mblk_t *);
478275SEric Cheng static int dld_capab_poll_disable(dld_str_t *, dld_capab_poll_t *);
481184Skrgopi 
490Sstevel@tonic-gate #define	DL_ACK_PENDING(state) \
500Sstevel@tonic-gate 	((state) == DL_ATTACH_PENDING || \
510Sstevel@tonic-gate 	(state) == DL_DETACH_PENDING || \
520Sstevel@tonic-gate 	(state) == DL_BIND_PENDING || \
530Sstevel@tonic-gate 	(state) == DL_UNBIND_PENDING)
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
56269Sericheng  * Process a DLPI protocol message.
57269Sericheng  * The primitives DL_BIND_REQ, DL_ENABMULTI_REQ, DL_PROMISCON_REQ,
58269Sericheng  * DL_SET_PHYS_ADDR_REQ put the data link below our dld_str_t into an
59269Sericheng  * 'active' state. The primitive DL_PASSIVE_REQ marks our dld_str_t
60269Sericheng  * as 'passive' and forbids it from being subsequently made 'active'
61269Sericheng  * by the above primitives.
620Sstevel@tonic-gate  */
630Sstevel@tonic-gate void
648275SEric Cheng dld_proto(dld_str_t *dsp, mblk_t *mp)
650Sstevel@tonic-gate {
660Sstevel@tonic-gate 	t_uscalar_t		prim;
670Sstevel@tonic-gate 
688275SEric Cheng 	if (MBLKL(mp) < sizeof (t_uscalar_t)) {
698275SEric Cheng 		freemsg(mp);
708275SEric Cheng 		return;
718275SEric Cheng 	}
728275SEric Cheng 	prim = ((union DL_primitives *)mp->b_rptr)->dl_primitive;
730Sstevel@tonic-gate 
74269Sericheng 	switch (prim) {
75269Sericheng 	case DL_INFO_REQ:
768275SEric Cheng 		proto_info_req(dsp, mp);
77269Sericheng 		break;
78269Sericheng 	case DL_BIND_REQ:
798275SEric Cheng 		proto_bind_req(dsp, mp);
80269Sericheng 		break;
81269Sericheng 	case DL_UNBIND_REQ:
828275SEric Cheng 		proto_unbind_req(dsp, mp);
838275SEric Cheng 		break;
848275SEric Cheng 	case DL_UNITDATA_REQ:
858275SEric Cheng 		proto_unitdata_req(dsp, mp);
86269Sericheng 		break;
87269Sericheng 	case DL_UDQOS_REQ:
888275SEric Cheng 		proto_udqos_req(dsp, mp);
89269Sericheng 		break;
90269Sericheng 	case DL_ATTACH_REQ:
918275SEric Cheng 		proto_attach_req(dsp, mp);
92269Sericheng 		break;
93269Sericheng 	case DL_DETACH_REQ:
948275SEric Cheng 		proto_detach_req(dsp, mp);
95269Sericheng 		break;
96269Sericheng 	case DL_ENABMULTI_REQ:
978275SEric Cheng 		proto_enabmulti_req(dsp, mp);
98269Sericheng 		break;
99269Sericheng 	case DL_DISABMULTI_REQ:
1008275SEric Cheng 		proto_disabmulti_req(dsp, mp);
101269Sericheng 		break;
102269Sericheng 	case DL_PROMISCON_REQ:
1038275SEric Cheng 		proto_promiscon_req(dsp, mp);
104269Sericheng 		break;
105269Sericheng 	case DL_PROMISCOFF_REQ:
1068275SEric Cheng 		proto_promiscoff_req(dsp, mp);
107269Sericheng 		break;
108269Sericheng 	case DL_PHYS_ADDR_REQ:
1098275SEric Cheng 		proto_physaddr_req(dsp, mp);
110269Sericheng 		break;
111269Sericheng 	case DL_SET_PHYS_ADDR_REQ:
1128275SEric Cheng 		proto_setphysaddr_req(dsp, mp);
113269Sericheng 		break;
114269Sericheng 	case DL_NOTIFY_REQ:
1158275SEric Cheng 		proto_notify_req(dsp, mp);
116269Sericheng 		break;
117269Sericheng 	case DL_CAPABILITY_REQ:
1188275SEric Cheng 		proto_capability_req(dsp, mp);
119269Sericheng 		break;
120269Sericheng 	case DL_PASSIVE_REQ:
1218275SEric Cheng 		proto_passive_req(dsp, mp);
122269Sericheng 		break;
123269Sericheng 	default:
1248275SEric Cheng 		proto_req(dsp, mp);
125269Sericheng 		break;
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate 
129269Sericheng #define	NEG(x)	-(x)
1300Sstevel@tonic-gate typedef struct dl_info_ack_wrapper {
1310Sstevel@tonic-gate 	dl_info_ack_t		dl_info;
1322311Sseb 	uint8_t			dl_addr[MAXMACADDRLEN + sizeof (uint16_t)];
1332311Sseb 	uint8_t			dl_brdcst_addr[MAXMACADDRLEN];
1340Sstevel@tonic-gate 	dl_qos_cl_range1_t	dl_qos_range1;
1350Sstevel@tonic-gate 	dl_qos_cl_sel1_t	dl_qos_sel1;
1360Sstevel@tonic-gate } dl_info_ack_wrapper_t;
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate /*
139269Sericheng  * DL_INFO_REQ
1400Sstevel@tonic-gate  */
1418275SEric Cheng static void
1428275SEric Cheng proto_info_req(dld_str_t *dsp, mblk_t *mp)
1430Sstevel@tonic-gate {
1440Sstevel@tonic-gate 	dl_info_ack_wrapper_t	*dlwp;
1450Sstevel@tonic-gate 	dl_info_ack_t		*dlp;
1460Sstevel@tonic-gate 	dl_qos_cl_sel1_t	*selp;
1470Sstevel@tonic-gate 	dl_qos_cl_range1_t	*rangep;
1480Sstevel@tonic-gate 	uint8_t			*addr;
1490Sstevel@tonic-gate 	uint8_t			*brdcst_addr;
1500Sstevel@tonic-gate 	uint_t			addr_length;
1510Sstevel@tonic-gate 	uint_t			sap_length;
152269Sericheng 	mac_info_t		minfo;
153269Sericheng 	mac_info_t		*minfop;
154269Sericheng 	queue_t			*q = dsp->ds_wq;
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	/*
1570Sstevel@tonic-gate 	 * Swap the request message for one large enough to contain the
1580Sstevel@tonic-gate 	 * wrapper structure defined above.
1590Sstevel@tonic-gate 	 */
160269Sericheng 	if ((mp = mexchange(q, mp, sizeof (dl_info_ack_wrapper_t),
1610Sstevel@tonic-gate 	    M_PCPROTO, 0)) == NULL)
1628275SEric Cheng 		return;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 	bzero(mp->b_rptr, sizeof (dl_info_ack_wrapper_t));
1650Sstevel@tonic-gate 	dlwp = (dl_info_ack_wrapper_t *)mp->b_rptr;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	dlp = &(dlwp->dl_info);
1680Sstevel@tonic-gate 	ASSERT(dlp == (dl_info_ack_t *)mp->b_rptr);
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	dlp->dl_primitive = DL_INFO_ACK;
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	/*
1730Sstevel@tonic-gate 	 * Set up the sub-structure pointers.
1740Sstevel@tonic-gate 	 */
1750Sstevel@tonic-gate 	addr = dlwp->dl_addr;
1760Sstevel@tonic-gate 	brdcst_addr = dlwp->dl_brdcst_addr;
1770Sstevel@tonic-gate 	rangep = &(dlwp->dl_qos_range1);
1780Sstevel@tonic-gate 	selp = &(dlwp->dl_qos_sel1);
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate 	/*
1810Sstevel@tonic-gate 	 * This driver supports only version 2 connectionless DLPI provider
1820Sstevel@tonic-gate 	 * nodes.
1830Sstevel@tonic-gate 	 */
1840Sstevel@tonic-gate 	dlp->dl_service_mode = DL_CLDLS;
1850Sstevel@tonic-gate 	dlp->dl_version = DL_VERSION_2;
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	/*
188269Sericheng 	 * Set the style of the provider
1890Sstevel@tonic-gate 	 */
190269Sericheng 	dlp->dl_provider_style = dsp->ds_style;
1910Sstevel@tonic-gate 	ASSERT(dlp->dl_provider_style == DL_STYLE1 ||
1920Sstevel@tonic-gate 	    dlp->dl_provider_style == DL_STYLE2);
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	/*
1950Sstevel@tonic-gate 	 * Set the current DLPI state.
1960Sstevel@tonic-gate 	 */
1970Sstevel@tonic-gate 	dlp->dl_current_state = dsp->ds_dlstate;
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	/*
200269Sericheng 	 * Gratuitously set the media type. This is to deal with modules
201269Sericheng 	 * that assume the media type is known prior to DL_ATTACH_REQ
2020Sstevel@tonic-gate 	 * being completed.
2030Sstevel@tonic-gate 	 */
2040Sstevel@tonic-gate 	dlp->dl_mac_type = DL_ETHER;
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	/*
207269Sericheng 	 * If the stream is not at least attached we try to retrieve the
208269Sericheng 	 * mac_info using mac_info_get()
2090Sstevel@tonic-gate 	 */
2100Sstevel@tonic-gate 	if (dsp->ds_dlstate == DL_UNATTACHED ||
2110Sstevel@tonic-gate 	    dsp->ds_dlstate == DL_ATTACH_PENDING ||
212269Sericheng 	    dsp->ds_dlstate == DL_DETACH_PENDING) {
213269Sericheng 		if (!mac_info_get(ddi_major_to_name(dsp->ds_major), &minfo)) {
214269Sericheng 			/*
215269Sericheng 			 * Cannot find mac_info. giving up.
216269Sericheng 			 */
217269Sericheng 			goto done;
218269Sericheng 		}
219269Sericheng 		minfop = &minfo;
220269Sericheng 	} else {
221269Sericheng 		minfop = (mac_info_t *)dsp->ds_mip;
2225903Ssowmini 		/* We can only get the sdu if we're attached. */
2235903Ssowmini 		mac_sdu_get(dsp->ds_mh, &dlp->dl_min_sdu, &dlp->dl_max_sdu);
224269Sericheng 	}
2250Sstevel@tonic-gate 
2260Sstevel@tonic-gate 	/*
2270Sstevel@tonic-gate 	 * Set the media type (properly this time).
2280Sstevel@tonic-gate 	 */
2293147Sxc151355 	if (dsp->ds_native)
2303147Sxc151355 		dlp->dl_mac_type = minfop->mi_nativemedia;
2313147Sxc151355 	else
2323147Sxc151355 		dlp->dl_mac_type = minfop->mi_media;
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 	/*
2350Sstevel@tonic-gate 	 * Set the DLSAP length. We only support 16 bit values and they
2360Sstevel@tonic-gate 	 * appear after the MAC address portion of DLSAP addresses.
2370Sstevel@tonic-gate 	 */
2380Sstevel@tonic-gate 	sap_length = sizeof (uint16_t);
2390Sstevel@tonic-gate 	dlp->dl_sap_length = NEG(sap_length);
2400Sstevel@tonic-gate 
241269Sericheng 	addr_length = minfop->mi_addr_length;
2420Sstevel@tonic-gate 
2430Sstevel@tonic-gate 	/*
2440Sstevel@tonic-gate 	 * Copy in the media broadcast address.
2450Sstevel@tonic-gate 	 */
2462311Sseb 	if (minfop->mi_brdcst_addr != NULL) {
2472311Sseb 		dlp->dl_brdcst_addr_offset =
2482311Sseb 		    (uintptr_t)brdcst_addr - (uintptr_t)dlp;
2492311Sseb 		bcopy(minfop->mi_brdcst_addr, brdcst_addr, addr_length);
2502311Sseb 		dlp->dl_brdcst_addr_length = addr_length;
2512311Sseb 	}
2520Sstevel@tonic-gate 
2538874SSebastien.Roy@Sun.COM 	/* Only VLAN links and links that have a normal tag mode support QOS. */
254*8968SSebastien.Roy@Sun.COM 	if ((dsp->ds_mch != NULL &&
255*8968SSebastien.Roy@Sun.COM 	    mac_client_vid(dsp->ds_mch) != VLAN_ID_NONE) ||
256*8968SSebastien.Roy@Sun.COM 	    (dsp->ds_dlp != NULL &&
257*8968SSebastien.Roy@Sun.COM 	    dsp->ds_dlp->dl_tagmode == LINK_TAGMODE_NORMAL)) {
2588874SSebastien.Roy@Sun.COM 		dlp->dl_qos_range_offset = (uintptr_t)rangep - (uintptr_t)dlp;
2598874SSebastien.Roy@Sun.COM 		dlp->dl_qos_range_length = sizeof (dl_qos_cl_range1_t);
2600Sstevel@tonic-gate 
2618874SSebastien.Roy@Sun.COM 		rangep->dl_qos_type = DL_QOS_CL_RANGE1;
2628874SSebastien.Roy@Sun.COM 		rangep->dl_trans_delay.dl_target_value = DL_UNKNOWN;
2638874SSebastien.Roy@Sun.COM 		rangep->dl_trans_delay.dl_accept_value = DL_UNKNOWN;
2648874SSebastien.Roy@Sun.COM 		rangep->dl_protection.dl_min = DL_UNKNOWN;
2658874SSebastien.Roy@Sun.COM 		rangep->dl_protection.dl_max = DL_UNKNOWN;
2668874SSebastien.Roy@Sun.COM 		rangep->dl_residual_error = DL_UNKNOWN;
2670Sstevel@tonic-gate 
2688874SSebastien.Roy@Sun.COM 		/*
2698874SSebastien.Roy@Sun.COM 		 * Specify the supported range of priorities.
2708874SSebastien.Roy@Sun.COM 		 */
2718874SSebastien.Roy@Sun.COM 		rangep->dl_priority.dl_min = 0;
2728874SSebastien.Roy@Sun.COM 		rangep->dl_priority.dl_max = (1 << VLAN_PRI_SIZE) - 1;
2730Sstevel@tonic-gate 
2748874SSebastien.Roy@Sun.COM 		dlp->dl_qos_offset = (uintptr_t)selp - (uintptr_t)dlp;
2758874SSebastien.Roy@Sun.COM 		dlp->dl_qos_length = sizeof (dl_qos_cl_sel1_t);
2760Sstevel@tonic-gate 
2778874SSebastien.Roy@Sun.COM 		selp->dl_qos_type = DL_QOS_CL_SEL1;
2788874SSebastien.Roy@Sun.COM 		selp->dl_trans_delay = DL_UNKNOWN;
2798874SSebastien.Roy@Sun.COM 		selp->dl_protection = DL_UNKNOWN;
2808874SSebastien.Roy@Sun.COM 		selp->dl_residual_error = DL_UNKNOWN;
2812760Sdg199075 
2828874SSebastien.Roy@Sun.COM 		/*
2838874SSebastien.Roy@Sun.COM 		 * Specify the current priority (which can be changed by
2848874SSebastien.Roy@Sun.COM 		 * the DL_UDQOS_REQ primitive).
2858874SSebastien.Roy@Sun.COM 		 */
2868874SSebastien.Roy@Sun.COM 		selp->dl_priority = dsp->ds_pri;
2878874SSebastien.Roy@Sun.COM 	}
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	dlp->dl_addr_length = addr_length + sizeof (uint16_t);
2900Sstevel@tonic-gate 	if (dsp->ds_dlstate == DL_IDLE) {
2910Sstevel@tonic-gate 		/*
2920Sstevel@tonic-gate 		 * The stream is bound. Therefore we can formulate a valid
2930Sstevel@tonic-gate 		 * DLSAP address.
2940Sstevel@tonic-gate 		 */
2950Sstevel@tonic-gate 		dlp->dl_addr_offset = (uintptr_t)addr - (uintptr_t)dlp;
2962311Sseb 		if (addr_length > 0)
2978275SEric Cheng 			mac_unicast_primary_get(dsp->ds_mh, addr);
2988275SEric Cheng 
2990Sstevel@tonic-gate 		*(uint16_t *)(addr + addr_length) = dsp->ds_sap;
3000Sstevel@tonic-gate 	}
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate done:
3030Sstevel@tonic-gate 	ASSERT(IMPLY(dlp->dl_qos_offset != 0, dlp->dl_qos_length != 0));
3040Sstevel@tonic-gate 	ASSERT(IMPLY(dlp->dl_qos_range_offset != 0,
3050Sstevel@tonic-gate 	    dlp->dl_qos_range_length != 0));
3060Sstevel@tonic-gate 	ASSERT(IMPLY(dlp->dl_addr_offset != 0, dlp->dl_addr_length != 0));
3070Sstevel@tonic-gate 	ASSERT(IMPLY(dlp->dl_brdcst_addr_offset != 0,
3080Sstevel@tonic-gate 	    dlp->dl_brdcst_addr_length != 0));
3090Sstevel@tonic-gate 
310269Sericheng 	qreply(q, mp);
311269Sericheng }
312269Sericheng 
313269Sericheng /*
314269Sericheng  * DL_ATTACH_REQ
315269Sericheng  */
3168275SEric Cheng static void
3178275SEric Cheng proto_attach_req(dld_str_t *dsp, mblk_t *mp)
318269Sericheng {
3198275SEric Cheng 	dl_attach_req_t	*dlp = (dl_attach_req_t *)mp->b_rptr;
320269Sericheng 	int		err = 0;
321269Sericheng 	t_uscalar_t	dl_err;
322269Sericheng 	queue_t		*q = dsp->ds_wq;
323269Sericheng 
324269Sericheng 	if (MBLKL(mp) < sizeof (dl_attach_req_t) ||
325269Sericheng 	    dlp->dl_ppa < 0 || dsp->ds_style == DL_STYLE1) {
326269Sericheng 		dl_err = DL_BADPRIM;
327269Sericheng 		goto failed;
328269Sericheng 	}
329269Sericheng 
330269Sericheng 	if (dsp->ds_dlstate != DL_UNATTACHED) {
331269Sericheng 		dl_err = DL_OUTSTATE;
332269Sericheng 		goto failed;
333269Sericheng 	}
334269Sericheng 
335269Sericheng 	dsp->ds_dlstate = DL_ATTACH_PENDING;
336269Sericheng 
337269Sericheng 	err = dld_str_attach(dsp, dlp->dl_ppa);
338269Sericheng 	if (err != 0) {
339269Sericheng 		switch (err) {
340269Sericheng 		case ENOENT:
341269Sericheng 			dl_err = DL_BADPPA;
342269Sericheng 			err = 0;
343269Sericheng 			break;
344269Sericheng 		default:
345269Sericheng 			dl_err = DL_SYSERR;
346269Sericheng 			break;
347269Sericheng 		}
348269Sericheng 		dsp->ds_dlstate = DL_UNATTACHED;
349269Sericheng 		goto failed;
350269Sericheng 	}
351269Sericheng 	ASSERT(dsp->ds_dlstate == DL_UNBOUND);
3528275SEric Cheng 	dlokack(q, mp, DL_ATTACH_REQ);
3538275SEric Cheng 	return;
354269Sericheng 
355269Sericheng failed:
356269Sericheng 	dlerrorack(q, mp, DL_ATTACH_REQ, dl_err, (t_uscalar_t)err);
3570Sstevel@tonic-gate }
3580Sstevel@tonic-gate 
3598275SEric Cheng /*
3608275SEric Cheng  * DL_DETACH_REQ
3618275SEric Cheng  */
3628275SEric Cheng static void
3638275SEric Cheng proto_detach_req(dld_str_t *dsp, mblk_t *mp)
3640Sstevel@tonic-gate {
365269Sericheng 	queue_t		*q = dsp->ds_wq;
366269Sericheng 	t_uscalar_t	dl_err;
3670Sstevel@tonic-gate 
368269Sericheng 	if (MBLKL(mp) < sizeof (dl_detach_req_t)) {
369269Sericheng 		dl_err = DL_BADPRIM;
370269Sericheng 		goto failed;
371269Sericheng 	}
3720Sstevel@tonic-gate 
373269Sericheng 	if (dsp->ds_dlstate != DL_UNBOUND) {
374269Sericheng 		dl_err = DL_OUTSTATE;
375269Sericheng 		goto failed;
3760Sstevel@tonic-gate 	}
3770Sstevel@tonic-gate 
378269Sericheng 	if (dsp->ds_style == DL_STYLE1) {
379269Sericheng 		dl_err = DL_BADPRIM;
380269Sericheng 		goto failed;
381269Sericheng 	}
382269Sericheng 
3838275SEric Cheng 	ASSERT(dsp->ds_datathr_cnt == 0);
384269Sericheng 	dsp->ds_dlstate = DL_DETACH_PENDING;
3858275SEric Cheng 
3865895Syz147064 	dld_str_detach(dsp);
3875895Syz147064 	dlokack(dsp->ds_wq, mp, DL_DETACH_REQ);
3888275SEric Cheng 	return;
3898275SEric Cheng 
390269Sericheng failed:
391269Sericheng 	dlerrorack(q, mp, DL_DETACH_REQ, dl_err, 0);
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate /*
395269Sericheng  * DL_BIND_REQ
3960Sstevel@tonic-gate  */
3978275SEric Cheng static void
3988275SEric Cheng proto_bind_req(dld_str_t *dsp, mblk_t *mp)
3990Sstevel@tonic-gate {
4008275SEric Cheng 	dl_bind_req_t	*dlp = (dl_bind_req_t *)mp->b_rptr;
401269Sericheng 	int		err = 0;
4023037Syz147064 	uint8_t		dlsap_addr[MAXMACADDRLEN + sizeof (uint16_t)];
4033037Syz147064 	uint_t		dlsap_addr_length;
404269Sericheng 	t_uscalar_t	dl_err;
405269Sericheng 	t_scalar_t	sap;
406269Sericheng 	queue_t		*q = dsp->ds_wq;
4078275SEric Cheng 	mac_perim_handle_t	mph;
4088275SEric Cheng 	void		*mdip;
4098275SEric Cheng 	int32_t		intr_cpu;
410269Sericheng 
411269Sericheng 	if (MBLKL(mp) < sizeof (dl_bind_req_t)) {
412269Sericheng 		dl_err = DL_BADPRIM;
413269Sericheng 		goto failed;
414269Sericheng 	}
415269Sericheng 
416269Sericheng 	if (dlp->dl_xidtest_flg != 0) {
417269Sericheng 		dl_err = DL_NOAUTO;
418269Sericheng 		goto failed;
419269Sericheng 	}
420269Sericheng 
421269Sericheng 	if (dlp->dl_service_mode != DL_CLDLS) {
422269Sericheng 		dl_err = DL_UNSUPPORTED;
423269Sericheng 		goto failed;
424269Sericheng 	}
425269Sericheng 
426269Sericheng 	if (dsp->ds_dlstate != DL_UNBOUND) {
427269Sericheng 		dl_err = DL_OUTSTATE;
428269Sericheng 		goto failed;
429269Sericheng 	}
4300Sstevel@tonic-gate 
4318275SEric Cheng 	mac_perim_enter_by_mh(dsp->ds_mh, &mph);
4328275SEric Cheng 
433269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED &&
4348275SEric Cheng 	    ((err = dls_active_set(dsp)) != 0)) {
435269Sericheng 		dl_err = DL_SYSERR;
4368275SEric Cheng 		goto failed2;
437269Sericheng 	}
438269Sericheng 
4398275SEric Cheng 	dsp->ds_dlstate = DL_BIND_PENDING;
440269Sericheng 	/*
441269Sericheng 	 * Set the receive callback.
442269Sericheng 	 */
4438275SEric Cheng 	dls_rx_set(dsp, (dsp->ds_mode == DLD_RAW) ?
444269Sericheng 	    dld_str_rx_raw : dld_str_rx_unitdata, dsp);
4450Sstevel@tonic-gate 
446269Sericheng 	/*
447269Sericheng 	 * Bind the channel such that it can receive packets.
448269Sericheng 	 */
4495895Syz147064 	sap = dlp->dl_sap;
4508275SEric Cheng 	err = dls_bind(dsp, sap);
451269Sericheng 	if (err != 0) {
452269Sericheng 		switch (err) {
453269Sericheng 		case EINVAL:
454269Sericheng 			dl_err = DL_BADADDR;
455269Sericheng 			err = 0;
456269Sericheng 			break;
457269Sericheng 		default:
458269Sericheng 			dl_err = DL_SYSERR;
459269Sericheng 			break;
460269Sericheng 		}
4615895Syz147064 
4628275SEric Cheng 		dsp->ds_dlstate = DL_UNBOUND;
463269Sericheng 		if (dsp->ds_passivestate == DLD_UNINITIALIZED)
4648275SEric Cheng 			dls_active_clear(dsp);
4658275SEric Cheng 		goto failed2;
4668275SEric Cheng 	}
467269Sericheng 
4688275SEric Cheng 	intr_cpu = mac_client_intr_cpu(dsp->ds_mch);
4698275SEric Cheng 	mdip = mac_get_devinfo(dsp->ds_mh);
4708275SEric Cheng 	mac_perim_exit(mph);
4718275SEric Cheng 
4728275SEric Cheng 	/*
4738275SEric Cheng 	 * We do this after we get out of the perim to avoid deadlocks
4748275SEric Cheng 	 * etc. since part of mac_client_retarget_intr is to walk the
4758275SEric Cheng 	 * device tree in order to find and retarget the interrupts.
4768275SEric Cheng 	 */
4778275SEric Cheng 	mac_client_set_intr_cpu(mdip, dsp->ds_mch, intr_cpu);
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate 	/*
4800Sstevel@tonic-gate 	 * Copy in MAC address.
4810Sstevel@tonic-gate 	 */
4823037Syz147064 	dlsap_addr_length = dsp->ds_mip->mi_addr_length;
4838275SEric Cheng 	mac_unicast_primary_get(dsp->ds_mh, dlsap_addr);
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 	/*
4863037Syz147064 	 * Copy in the SAP.
4870Sstevel@tonic-gate 	 */
4885895Syz147064 	*(uint16_t *)(dlsap_addr + dlsap_addr_length) = sap;
4893037Syz147064 	dlsap_addr_length += sizeof (uint16_t);
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate 	dsp->ds_dlstate = DL_IDLE;
492269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED)
493269Sericheng 		dsp->ds_passivestate = DLD_ACTIVE;
494269Sericheng 
4953037Syz147064 	dlbindack(q, mp, sap, dlsap_addr, dlsap_addr_length, 0, 0);
4968275SEric Cheng 	return;
4978275SEric Cheng 
4988275SEric Cheng failed2:
4998275SEric Cheng 	mac_perim_exit(mph);
5000Sstevel@tonic-gate failed:
501269Sericheng 	dlerrorack(q, mp, DL_BIND_REQ, dl_err, (t_uscalar_t)err);
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate 
5040Sstevel@tonic-gate /*
505269Sericheng  * DL_UNBIND_REQ
5060Sstevel@tonic-gate  */
5078275SEric Cheng static void
5088275SEric Cheng proto_unbind_req(dld_str_t *dsp, mblk_t *mp)
5090Sstevel@tonic-gate {
5105895Syz147064 	queue_t		*q = dsp->ds_wq;
5115895Syz147064 	t_uscalar_t	dl_err;
5128275SEric Cheng 	mac_perim_handle_t	mph;
513269Sericheng 
5145895Syz147064 	if (MBLKL(mp) < sizeof (dl_unbind_req_t)) {
5155895Syz147064 		dl_err = DL_BADPRIM;
5165895Syz147064 		goto failed;
5175895Syz147064 	}
5185895Syz147064 
5195895Syz147064 	if (dsp->ds_dlstate != DL_IDLE) {
5205895Syz147064 		dl_err = DL_OUTSTATE;
5215895Syz147064 		goto failed;
5225895Syz147064 	}
523269Sericheng 
5248275SEric Cheng 	mutex_enter(&dsp->ds_lock);
5258275SEric Cheng 	while (dsp->ds_datathr_cnt != 0)
5268275SEric Cheng 		cv_wait(&dsp->ds_datathr_cv, &dsp->ds_lock);
527269Sericheng 
5288275SEric Cheng 	dsp->ds_dlstate = DL_UNBIND_PENDING;
5298275SEric Cheng 	mutex_exit(&dsp->ds_lock);
5308275SEric Cheng 
5318275SEric Cheng 	mac_perim_enter_by_mh(dsp->ds_mh, &mph);
532269Sericheng 	/*
533269Sericheng 	 * Unbind the channel to stop packets being received.
534269Sericheng 	 */
5358275SEric Cheng 	if (dls_unbind(dsp) != 0) {
5368275SEric Cheng 		dl_err = DL_OUTSTATE;
5378275SEric Cheng 		mac_perim_exit(mph);
5388275SEric Cheng 		goto failed;
5398275SEric Cheng 	}
5405895Syz147064 
5415895Syz147064 	/*
542269Sericheng 	 * Disable polling mode, if it is enabled.
543269Sericheng 	 */
5448275SEric Cheng 	(void) dld_capab_poll_disable(dsp, NULL);
5455895Syz147064 
5465895Syz147064 	/*
5473115Syl150051 	 * Clear LSO flags.
5483115Syl150051 	 */
5493115Syl150051 	dsp->ds_lso = B_FALSE;
5503115Syl150051 	dsp->ds_lso_max = 0;
5513115Syl150051 
5523115Syl150051 	/*
5538275SEric Cheng 	 * Clear the receive callback.
5548275SEric Cheng 	 */
5558275SEric Cheng 	dls_rx_set(dsp, NULL, NULL);
5568275SEric Cheng 	dsp->ds_direct = B_FALSE;
5578275SEric Cheng 
5588275SEric Cheng 	/*
559269Sericheng 	 * Set the mode back to the default (unitdata).
560269Sericheng 	 */
561269Sericheng 	dsp->ds_mode = DLD_UNITDATA;
5621353Sericheng 	dsp->ds_dlstate = DL_UNBOUND;
5631353Sericheng 
5648275SEric Cheng 	mac_perim_exit(mph);
5658275SEric Cheng 	dlokack(dsp->ds_wq, mp, DL_UNBIND_REQ);
5668275SEric Cheng 	return;
567269Sericheng failed:
568269Sericheng 	dlerrorack(q, mp, DL_UNBIND_REQ, dl_err, 0);
5690Sstevel@tonic-gate }
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate /*
572269Sericheng  * DL_PROMISCON_REQ
5730Sstevel@tonic-gate  */
5748275SEric Cheng static void
5758275SEric Cheng proto_promiscon_req(dld_str_t *dsp, mblk_t *mp)
5760Sstevel@tonic-gate {
5778275SEric Cheng 	dl_promiscon_req_t *dlp = (dl_promiscon_req_t *)mp->b_rptr;
578269Sericheng 	int		err = 0;
579269Sericheng 	t_uscalar_t	dl_err;
5808275SEric Cheng 	uint32_t	promisc_saved;
581269Sericheng 	queue_t		*q = dsp->ds_wq;
5828275SEric Cheng 	mac_perim_handle_t	mph;
583269Sericheng 
584269Sericheng 	if (MBLKL(mp) < sizeof (dl_promiscon_req_t)) {
585269Sericheng 		dl_err = DL_BADPRIM;
586269Sericheng 		goto failed;
587269Sericheng 	}
588269Sericheng 
589269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
590269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
591269Sericheng 		dl_err = DL_OUTSTATE;
5920Sstevel@tonic-gate 		goto failed;
593269Sericheng 	}
5940Sstevel@tonic-gate 
5958275SEric Cheng 	promisc_saved = dsp->ds_promisc;
596269Sericheng 	switch (dlp->dl_level) {
597269Sericheng 	case DL_PROMISC_SAP:
5988275SEric Cheng 		dsp->ds_promisc |= DLS_PROMISC_SAP;
599269Sericheng 		break;
6008275SEric Cheng 
6015895Syz147064 	case DL_PROMISC_MULTI:
6028275SEric Cheng 		dsp->ds_promisc |= DLS_PROMISC_MULTI;
6035895Syz147064 		break;
6048275SEric Cheng 
605269Sericheng 	case DL_PROMISC_PHYS:
6068275SEric Cheng 		dsp->ds_promisc |= DLS_PROMISC_PHYS;
607269Sericheng 		break;
6088275SEric Cheng 
609269Sericheng 	default:
610269Sericheng 		dl_err = DL_NOTSUPPORTED;
611269Sericheng 		goto failed;
612269Sericheng 	}
6130Sstevel@tonic-gate 
6148275SEric Cheng 	mac_perim_enter_by_mh(dsp->ds_mh, &mph);
6158275SEric Cheng 
616269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED &&
6178275SEric Cheng 	    ((err = dls_active_set(dsp)) != 0)) {
6188275SEric Cheng 		dsp->ds_promisc = promisc_saved;
619269Sericheng 		dl_err = DL_SYSERR;
6208275SEric Cheng 		goto failed2;
621269Sericheng 	}
622269Sericheng 
623269Sericheng 	/*
624269Sericheng 	 * Adjust channel promiscuity.
625269Sericheng 	 */
6268275SEric Cheng 	err = dls_promisc(dsp, promisc_saved);
6278275SEric Cheng 
628269Sericheng 	if (err != 0) {
629269Sericheng 		dl_err = DL_SYSERR;
6308275SEric Cheng 		dsp->ds_promisc = promisc_saved;
631269Sericheng 		if (dsp->ds_passivestate == DLD_UNINITIALIZED)
6328275SEric Cheng 			dls_active_clear(dsp);
6338275SEric Cheng 		goto failed2;
634269Sericheng 	}
635269Sericheng 
6368275SEric Cheng 	mac_perim_exit(mph);
6378275SEric Cheng 
638269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED)
639269Sericheng 		dsp->ds_passivestate = DLD_ACTIVE;
6408275SEric Cheng 	dlokack(q, mp, DL_PROMISCON_REQ);
6418275SEric Cheng 	return;
642269Sericheng 
6438275SEric Cheng failed2:
6448275SEric Cheng 	mac_perim_exit(mph);
6450Sstevel@tonic-gate failed:
646269Sericheng 	dlerrorack(q, mp, DL_PROMISCON_REQ, dl_err, (t_uscalar_t)err);
6470Sstevel@tonic-gate }
6480Sstevel@tonic-gate 
6490Sstevel@tonic-gate /*
650269Sericheng  * DL_PROMISCOFF_REQ
6510Sstevel@tonic-gate  */
6528275SEric Cheng static void
6538275SEric Cheng proto_promiscoff_req(dld_str_t *dsp, mblk_t *mp)
6540Sstevel@tonic-gate {
6558275SEric Cheng 	dl_promiscoff_req_t *dlp = (dl_promiscoff_req_t *)mp->b_rptr;
656269Sericheng 	int		err = 0;
657269Sericheng 	t_uscalar_t	dl_err;
6588275SEric Cheng 	uint32_t	promisc_saved;
659269Sericheng 	queue_t		*q = dsp->ds_wq;
6608275SEric Cheng 	mac_perim_handle_t	mph;
661269Sericheng 
662269Sericheng 	if (MBLKL(mp) < sizeof (dl_promiscoff_req_t)) {
663269Sericheng 		dl_err = DL_BADPRIM;
6640Sstevel@tonic-gate 		goto failed;
665269Sericheng 	}
6660Sstevel@tonic-gate 
667269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
668269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
669269Sericheng 		dl_err = DL_OUTSTATE;
6700Sstevel@tonic-gate 		goto failed;
671269Sericheng 	}
6720Sstevel@tonic-gate 
6738275SEric Cheng 	promisc_saved = dsp->ds_promisc;
674269Sericheng 	switch (dlp->dl_level) {
675269Sericheng 	case DL_PROMISC_SAP:
6768275SEric Cheng 		if (!(dsp->ds_promisc & DLS_PROMISC_SAP)) {
6778275SEric Cheng 			dl_err = DL_NOTENAB;
6788275SEric Cheng 			goto failed;
6798275SEric Cheng 		}
6808275SEric Cheng 		dsp->ds_promisc &= ~DLS_PROMISC_SAP;
6810Sstevel@tonic-gate 		break;
6828275SEric Cheng 
683269Sericheng 	case DL_PROMISC_MULTI:
6848275SEric Cheng 		if (!(dsp->ds_promisc & DLS_PROMISC_MULTI)) {
6858275SEric Cheng 			dl_err = DL_NOTENAB;
6868275SEric Cheng 			goto failed;
6878275SEric Cheng 		}
6888275SEric Cheng 		dsp->ds_promisc &= ~DLS_PROMISC_MULTI;
689269Sericheng 		break;
6908275SEric Cheng 
691269Sericheng 	case DL_PROMISC_PHYS:
6928275SEric Cheng 		if (!(dsp->ds_promisc & DLS_PROMISC_PHYS)) {
6938275SEric Cheng 			dl_err = DL_NOTENAB;
6948275SEric Cheng 			goto failed;
6958275SEric Cheng 		}
6968275SEric Cheng 		dsp->ds_promisc &= ~DLS_PROMISC_PHYS;
6970Sstevel@tonic-gate 		break;
6988275SEric Cheng 
6990Sstevel@tonic-gate 	default:
700269Sericheng 		dl_err = DL_NOTSUPPORTED;
701269Sericheng 		goto failed;
702269Sericheng 	}
703269Sericheng 
7048275SEric Cheng 	mac_perim_enter_by_mh(dsp->ds_mh, &mph);
7058275SEric Cheng 	/*
7068275SEric Cheng 	 * Adjust channel promiscuity.
7078275SEric Cheng 	 */
7088275SEric Cheng 	err = dls_promisc(dsp, promisc_saved);
7098275SEric Cheng 	mac_perim_exit(mph);
7105895Syz147064 
711269Sericheng 	if (err != 0) {
7120Sstevel@tonic-gate 		dl_err = DL_SYSERR;
713269Sericheng 		goto failed;
714269Sericheng 	}
715269Sericheng 	dlokack(q, mp, DL_PROMISCOFF_REQ);
7168275SEric Cheng 	return;
717269Sericheng failed:
718269Sericheng 	dlerrorack(q, mp, DL_PROMISCOFF_REQ, dl_err, (t_uscalar_t)err);
719269Sericheng }
720269Sericheng 
721269Sericheng /*
722269Sericheng  * DL_ENABMULTI_REQ
723269Sericheng  */
7248275SEric Cheng static void
7258275SEric Cheng proto_enabmulti_req(dld_str_t *dsp, mblk_t *mp)
726269Sericheng {
7278275SEric Cheng 	dl_enabmulti_req_t *dlp = (dl_enabmulti_req_t *)mp->b_rptr;
728269Sericheng 	int		err = 0;
729269Sericheng 	t_uscalar_t	dl_err;
730269Sericheng 	queue_t		*q = dsp->ds_wq;
7318275SEric Cheng 	mac_perim_handle_t	mph;
732269Sericheng 
733269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
734269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
735269Sericheng 		dl_err = DL_OUTSTATE;
736269Sericheng 		goto failed;
737269Sericheng 	}
738269Sericheng 
739269Sericheng 	if (MBLKL(mp) < sizeof (dl_enabmulti_req_t) ||
740269Sericheng 	    !MBLKIN(mp, dlp->dl_addr_offset, dlp->dl_addr_length) ||
741269Sericheng 	    dlp->dl_addr_length != dsp->ds_mip->mi_addr_length) {
742269Sericheng 		dl_err = DL_BADPRIM;
743269Sericheng 		goto failed;
744269Sericheng 	}
745269Sericheng 
7468275SEric Cheng 	mac_perim_enter_by_mh(dsp->ds_mh, &mph);
7478275SEric Cheng 
748269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED &&
7498275SEric Cheng 	    ((err = dls_active_set(dsp)) != 0)) {
750269Sericheng 		dl_err = DL_SYSERR;
7518275SEric Cheng 		goto failed2;
7520Sstevel@tonic-gate 	}
7530Sstevel@tonic-gate 
7548275SEric Cheng 	err = dls_multicst_add(dsp, mp->b_rptr + dlp->dl_addr_offset);
7558275SEric Cheng 
756269Sericheng 	if (err != 0) {
757269Sericheng 		switch (err) {
758269Sericheng 		case EINVAL:
759269Sericheng 			dl_err = DL_BADADDR;
760269Sericheng 			err = 0;
761269Sericheng 			break;
762269Sericheng 		case ENOSPC:
763269Sericheng 			dl_err = DL_TOOMANY;
764269Sericheng 			err = 0;
765269Sericheng 			break;
766269Sericheng 		default:
767269Sericheng 			dl_err = DL_SYSERR;
768269Sericheng 			break;
769269Sericheng 		}
7708275SEric Cheng 		if (dsp->ds_passivestate == DLD_UNINITIALIZED)
7718275SEric Cheng 			dls_active_clear(dsp);
7725895Syz147064 
7738275SEric Cheng 		goto failed2;
774269Sericheng 	}
775269Sericheng 
7768275SEric Cheng 	mac_perim_exit(mph);
7778275SEric Cheng 
778269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED)
779269Sericheng 		dsp->ds_passivestate = DLD_ACTIVE;
7808275SEric Cheng 	dlokack(q, mp, DL_ENABMULTI_REQ);
7818275SEric Cheng 	return;
782269Sericheng 
7838275SEric Cheng failed2:
7848275SEric Cheng 	mac_perim_exit(mph);
785269Sericheng failed:
786269Sericheng 	dlerrorack(q, mp, DL_ENABMULTI_REQ, dl_err, (t_uscalar_t)err);
787269Sericheng }
788269Sericheng 
789269Sericheng /*
790269Sericheng  * DL_DISABMULTI_REQ
791269Sericheng  */
7928275SEric Cheng static void
7938275SEric Cheng proto_disabmulti_req(dld_str_t *dsp, mblk_t *mp)
794269Sericheng {
7958275SEric Cheng 	dl_disabmulti_req_t *dlp = (dl_disabmulti_req_t *)mp->b_rptr;
796269Sericheng 	int		err = 0;
797269Sericheng 	t_uscalar_t	dl_err;
798269Sericheng 	queue_t		*q = dsp->ds_wq;
7998275SEric Cheng 	mac_perim_handle_t	mph;
800269Sericheng 
801269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
802269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
803269Sericheng 		dl_err = DL_OUTSTATE;
804269Sericheng 		goto failed;
805269Sericheng 	}
806269Sericheng 
807269Sericheng 	if (MBLKL(mp) < sizeof (dl_disabmulti_req_t) ||
808269Sericheng 	    !MBLKIN(mp, dlp->dl_addr_offset, dlp->dl_addr_length) ||
809269Sericheng 	    dlp->dl_addr_length != dsp->ds_mip->mi_addr_length) {
810269Sericheng 		dl_err = DL_BADPRIM;
811269Sericheng 		goto failed;
812269Sericheng 	}
813269Sericheng 
8148275SEric Cheng 	mac_perim_enter_by_mh(dsp->ds_mh, &mph);
8158275SEric Cheng 	err = dls_multicst_remove(dsp, mp->b_rptr + dlp->dl_addr_offset);
8168275SEric Cheng 	mac_perim_exit(mph);
8178275SEric Cheng 
818269Sericheng 	if (err != 0) {
8198275SEric Cheng 	switch (err) {
820269Sericheng 		case EINVAL:
821269Sericheng 			dl_err = DL_BADADDR;
822269Sericheng 			err = 0;
823269Sericheng 			break;
8248275SEric Cheng 
825269Sericheng 		case ENOENT:
826269Sericheng 			dl_err = DL_NOTENAB;
827269Sericheng 			err = 0;
828269Sericheng 			break;
8298275SEric Cheng 
830269Sericheng 		default:
831269Sericheng 			dl_err = DL_SYSERR;
832269Sericheng 			break;
833269Sericheng 		}
834269Sericheng 		goto failed;
835269Sericheng 	}
836269Sericheng 	dlokack(q, mp, DL_DISABMULTI_REQ);
8378275SEric Cheng 	return;
838269Sericheng failed:
839269Sericheng 	dlerrorack(q, mp, DL_DISABMULTI_REQ, dl_err, (t_uscalar_t)err);
8400Sstevel@tonic-gate }
8410Sstevel@tonic-gate 
8420Sstevel@tonic-gate /*
843269Sericheng  * DL_PHYS_ADDR_REQ
8440Sstevel@tonic-gate  */
8458275SEric Cheng static void
8468275SEric Cheng proto_physaddr_req(dld_str_t *dsp, mblk_t *mp)
8470Sstevel@tonic-gate {
8488275SEric Cheng 	dl_phys_addr_req_t *dlp = (dl_phys_addr_req_t *)mp->b_rptr;
849269Sericheng 	queue_t		*q = dsp->ds_wq;
850269Sericheng 	t_uscalar_t	dl_err;
851269Sericheng 	char		*addr;
852269Sericheng 	uint_t		addr_length;
853269Sericheng 
854269Sericheng 	if (MBLKL(mp) < sizeof (dl_phys_addr_req_t)) {
855269Sericheng 		dl_err = DL_BADPRIM;
856269Sericheng 		goto failed;
857269Sericheng 	}
858269Sericheng 
859269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
860269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
861269Sericheng 		dl_err = DL_OUTSTATE;
862269Sericheng 		goto failed;
863269Sericheng 	}
8640Sstevel@tonic-gate 
865269Sericheng 	if (dlp->dl_addr_type != DL_CURR_PHYS_ADDR &&
866269Sericheng 	    dlp->dl_addr_type != DL_FACT_PHYS_ADDR) {
867269Sericheng 		dl_err = DL_UNSUPPORTED;
8680Sstevel@tonic-gate 		goto failed;
869269Sericheng 	}
8700Sstevel@tonic-gate 
871269Sericheng 	addr_length = dsp->ds_mip->mi_addr_length;
8726353Sdr146992 	if (addr_length > 0) {
8738275SEric Cheng 		addr = kmem_alloc(addr_length, KM_SLEEP);
8748275SEric Cheng 		if (dlp->dl_addr_type == DL_CURR_PHYS_ADDR)
8758275SEric Cheng 			mac_unicast_primary_get(dsp->ds_mh, (uint8_t *)addr);
8768275SEric Cheng 		else
8778275SEric Cheng 			bcopy(dsp->ds_mip->mi_unicst_addr, addr, addr_length);
8780Sstevel@tonic-gate 
8796353Sdr146992 		dlphysaddrack(q, mp, addr, (t_uscalar_t)addr_length);
8806353Sdr146992 		kmem_free(addr, addr_length);
8816353Sdr146992 	} else {
8826353Sdr146992 		dlphysaddrack(q, mp, NULL, 0);
8836353Sdr146992 	}
8848275SEric Cheng 	return;
8850Sstevel@tonic-gate failed:
886269Sericheng 	dlerrorack(q, mp, DL_PHYS_ADDR_REQ, dl_err, 0);
887269Sericheng }
8880Sstevel@tonic-gate 
889269Sericheng /*
890269Sericheng  * DL_SET_PHYS_ADDR_REQ
891269Sericheng  */
8928275SEric Cheng static void
8938275SEric Cheng proto_setphysaddr_req(dld_str_t *dsp, mblk_t *mp)
894269Sericheng {
8958275SEric Cheng 	dl_set_phys_addr_req_t *dlp = (dl_set_phys_addr_req_t *)mp->b_rptr;
896269Sericheng 	int		err = 0;
897269Sericheng 	t_uscalar_t	dl_err;
898269Sericheng 	queue_t		*q = dsp->ds_wq;
8998275SEric Cheng 	mac_perim_handle_t	mph;
9000Sstevel@tonic-gate 
901269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
902269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
903269Sericheng 		dl_err = DL_OUTSTATE;
904269Sericheng 		goto failed;
905269Sericheng 	}
906269Sericheng 
907269Sericheng 	if (MBLKL(mp) < sizeof (dl_set_phys_addr_req_t) ||
908269Sericheng 	    !MBLKIN(mp, dlp->dl_addr_offset, dlp->dl_addr_length) ||
909269Sericheng 	    dlp->dl_addr_length != dsp->ds_mip->mi_addr_length) {
910269Sericheng 		dl_err = DL_BADPRIM;
911269Sericheng 		goto failed;
9120Sstevel@tonic-gate 	}
9130Sstevel@tonic-gate 
9148275SEric Cheng 	mac_perim_enter_by_mh(dsp->ds_mh, &mph);
9158275SEric Cheng 
916269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED &&
9178275SEric Cheng 	    ((err = dls_active_set(dsp)) != 0)) {
918269Sericheng 		dl_err = DL_SYSERR;
9198275SEric Cheng 		goto failed2;
920269Sericheng 	}
921269Sericheng 
9228275SEric Cheng 	err = mac_unicast_primary_set(dsp->ds_mh,
9238275SEric Cheng 	    mp->b_rptr + dlp->dl_addr_offset);
924269Sericheng 	if (err != 0) {
925269Sericheng 		switch (err) {
926269Sericheng 		case EINVAL:
927269Sericheng 			dl_err = DL_BADADDR;
928269Sericheng 			err = 0;
929269Sericheng 			break;
930269Sericheng 
931269Sericheng 		default:
932269Sericheng 			dl_err = DL_SYSERR;
933269Sericheng 			break;
934269Sericheng 		}
9358275SEric Cheng 		if (dsp->ds_passivestate == DLD_UNINITIALIZED)
9368275SEric Cheng 			dls_active_clear(dsp);
9375895Syz147064 
9388275SEric Cheng 		goto failed2;
939269Sericheng 
940269Sericheng 	}
9415895Syz147064 
9428275SEric Cheng 	mac_perim_exit(mph);
9438275SEric Cheng 
944269Sericheng 	if (dsp->ds_passivestate == DLD_UNINITIALIZED)
945269Sericheng 		dsp->ds_passivestate = DLD_ACTIVE;
9468275SEric Cheng 	dlokack(q, mp, DL_SET_PHYS_ADDR_REQ);
9478275SEric Cheng 	return;
948269Sericheng 
9498275SEric Cheng failed2:
9508275SEric Cheng 	mac_perim_exit(mph);
951269Sericheng failed:
952269Sericheng 	dlerrorack(q, mp, DL_SET_PHYS_ADDR_REQ, dl_err, (t_uscalar_t)err);
953269Sericheng }
954269Sericheng 
955269Sericheng /*
956269Sericheng  * DL_UDQOS_REQ
957269Sericheng  */
9588275SEric Cheng static void
9598275SEric Cheng proto_udqos_req(dld_str_t *dsp, mblk_t *mp)
960269Sericheng {
9618275SEric Cheng 	dl_udqos_req_t *dlp = (dl_udqos_req_t *)mp->b_rptr;
962269Sericheng 	dl_qos_cl_sel1_t *selp;
963269Sericheng 	int		off, len;
964269Sericheng 	t_uscalar_t	dl_err;
965269Sericheng 	queue_t		*q = dsp->ds_wq;
966269Sericheng 
967269Sericheng 	off = dlp->dl_qos_offset;
968269Sericheng 	len = dlp->dl_qos_length;
969269Sericheng 
970269Sericheng 	if (MBLKL(mp) < sizeof (dl_udqos_req_t) || !MBLKIN(mp, off, len)) {
971269Sericheng 		dl_err = DL_BADPRIM;
972269Sericheng 		goto failed;
973269Sericheng 	}
974269Sericheng 
975269Sericheng 	selp = (dl_qos_cl_sel1_t *)(mp->b_rptr + off);
976269Sericheng 	if (selp->dl_qos_type != DL_QOS_CL_SEL1) {
977269Sericheng 		dl_err = DL_BADQOSTYPE;
978269Sericheng 		goto failed;
979269Sericheng 	}
980269Sericheng 
9812760Sdg199075 	if (selp->dl_priority > (1 << VLAN_PRI_SIZE) - 1 ||
982269Sericheng 	    selp->dl_priority < 0) {
983269Sericheng 		dl_err = DL_BADQOSPARAM;
984269Sericheng 		goto failed;
985269Sericheng 	}
986269Sericheng 
9875895Syz147064 	dsp->ds_pri = selp->dl_priority;
988269Sericheng 	dlokack(q, mp, DL_UDQOS_REQ);
9898275SEric Cheng 	return;
990269Sericheng failed:
991269Sericheng 	dlerrorack(q, mp, DL_UDQOS_REQ, dl_err, 0);
9920Sstevel@tonic-gate }
9930Sstevel@tonic-gate 
9941184Skrgopi static boolean_t
9951184Skrgopi check_ip_above(queue_t *q)
9961184Skrgopi {
9971184Skrgopi 	queue_t		*next_q;
9981184Skrgopi 	boolean_t	ret = B_TRUE;
9991184Skrgopi 
10001184Skrgopi 	claimstr(q);
10011184Skrgopi 	next_q = q->q_next;
10021184Skrgopi 	if (strcmp(next_q->q_qinfo->qi_minfo->mi_idname, "ip") != 0)
10031184Skrgopi 		ret = B_FALSE;
10041184Skrgopi 	releasestr(q);
10051184Skrgopi 	return (ret);
10061184Skrgopi }
10071184Skrgopi 
10080Sstevel@tonic-gate /*
1009269Sericheng  * DL_CAPABILITY_REQ
10100Sstevel@tonic-gate  */
10118275SEric Cheng static void
10128275SEric Cheng proto_capability_req(dld_str_t *dsp, mblk_t *mp)
10130Sstevel@tonic-gate {
10148275SEric Cheng 	dl_capability_req_t *dlp = (dl_capability_req_t *)mp->b_rptr;
1015269Sericheng 	dl_capability_sub_t *sp;
1016269Sericheng 	size_t		size, len;
1017269Sericheng 	offset_t	off, end;
1018269Sericheng 	t_uscalar_t	dl_err;
1019269Sericheng 	queue_t		*q = dsp->ds_wq;
1020269Sericheng 
1021269Sericheng 	if (MBLKL(mp) < sizeof (dl_capability_req_t)) {
1022269Sericheng 		dl_err = DL_BADPRIM;
1023269Sericheng 		goto failed;
1024269Sericheng 	}
1025269Sericheng 
1026269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
1027269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
1028269Sericheng 		dl_err = DL_OUTSTATE;
1029269Sericheng 		goto failed;
1030269Sericheng 	}
1031269Sericheng 
1032269Sericheng 	/*
1033269Sericheng 	 * This request is overloaded. If there are no requested capabilities
1034269Sericheng 	 * then we just want to acknowledge with all the capabilities we
1035269Sericheng 	 * support. Otherwise we enable the set of capabilities requested.
1036269Sericheng 	 */
1037269Sericheng 	if (dlp->dl_sub_length == 0) {
10388275SEric Cheng 		proto_capability_advertise(dsp, mp);
10398275SEric Cheng 		return;
1040269Sericheng 	}
1041269Sericheng 
1042269Sericheng 	if (!MBLKIN(mp, dlp->dl_sub_offset, dlp->dl_sub_length)) {
1043269Sericheng 		dl_err = DL_BADPRIM;
1044269Sericheng 		goto failed;
1045269Sericheng 	}
1046269Sericheng 
1047269Sericheng 	dlp->dl_primitive = DL_CAPABILITY_ACK;
1048269Sericheng 
1049269Sericheng 	off = dlp->dl_sub_offset;
1050269Sericheng 	len = dlp->dl_sub_length;
10510Sstevel@tonic-gate 
10520Sstevel@tonic-gate 	/*
1053269Sericheng 	 * Walk the list of capabilities to be enabled.
10540Sstevel@tonic-gate 	 */
1055269Sericheng 	for (end = off + len; off < end; ) {
1056269Sericheng 		sp = (dl_capability_sub_t *)(mp->b_rptr + off);
1057269Sericheng 		size = sizeof (dl_capability_sub_t) + sp->dl_length;
1058269Sericheng 
1059269Sericheng 		if (off + size > end ||
1060269Sericheng 		    !IS_P2ALIGNED(off, sizeof (uint32_t))) {
1061269Sericheng 			dl_err = DL_BADPRIM;
1062269Sericheng 			goto failed;
1063269Sericheng 		}
1064269Sericheng 
1065269Sericheng 		switch (sp->dl_cap) {
1066269Sericheng 		/*
1067269Sericheng 		 * TCP/IP checksum offload to hardware.
1068269Sericheng 		 */
1069269Sericheng 		case DL_CAPAB_HCKSUM: {
1070269Sericheng 			dl_capab_hcksum_t *hcksump;
1071269Sericheng 			dl_capab_hcksum_t hcksum;
1072269Sericheng 
1073269Sericheng 			hcksump = (dl_capab_hcksum_t *)&sp[1];
1074269Sericheng 			/*
1075269Sericheng 			 * Copy for alignment.
1076269Sericheng 			 */
1077269Sericheng 			bcopy(hcksump, &hcksum, sizeof (dl_capab_hcksum_t));
1078269Sericheng 			dlcapabsetqid(&(hcksum.hcksum_mid), dsp->ds_rq);
1079269Sericheng 			bcopy(&hcksum, hcksump, sizeof (dl_capab_hcksum_t));
1080269Sericheng 			break;
1081269Sericheng 		}
1082269Sericheng 
10838275SEric Cheng 		case DL_CAPAB_DLD: {
10848275SEric Cheng 			dl_capab_dld_t	*dldp;
10858275SEric Cheng 			dl_capab_dld_t	dld;
10863115Syl150051 
10878275SEric Cheng 			dldp = (dl_capab_dld_t *)&sp[1];
1088269Sericheng 			/*
1089269Sericheng 			 * Copy for alignment.
1090269Sericheng 			 */
10918275SEric Cheng 			bcopy(dldp, &dld, sizeof (dl_capab_dld_t));
10928275SEric Cheng 			dlcapabsetqid(&(dld.dld_mid), dsp->ds_rq);
10938275SEric Cheng 			bcopy(&dld, dldp, sizeof (dl_capab_dld_t));
1094269Sericheng 			break;
1095269Sericheng 		}
1096269Sericheng 		default:
1097269Sericheng 			break;
1098269Sericheng 		}
1099269Sericheng 		off += size;
1100269Sericheng 	}
1101269Sericheng 	qreply(q, mp);
11028275SEric Cheng 	return;
1103269Sericheng failed:
1104269Sericheng 	dlerrorack(q, mp, DL_CAPABILITY_REQ, dl_err, 0);
11050Sstevel@tonic-gate }
11060Sstevel@tonic-gate 
11070Sstevel@tonic-gate /*
1108269Sericheng  * DL_NOTIFY_REQ
11090Sstevel@tonic-gate  */
11108275SEric Cheng static void
11118275SEric Cheng proto_notify_req(dld_str_t *dsp, mblk_t *mp)
11120Sstevel@tonic-gate {
11138275SEric Cheng 	dl_notify_req_t	*dlp = (dl_notify_req_t *)mp->b_rptr;
1114269Sericheng 	t_uscalar_t	dl_err;
1115269Sericheng 	queue_t		*q = dsp->ds_wq;
1116269Sericheng 	uint_t		note =
1117269Sericheng 	    DL_NOTE_PROMISC_ON_PHYS |
1118269Sericheng 	    DL_NOTE_PROMISC_OFF_PHYS |
1119269Sericheng 	    DL_NOTE_PHYS_ADDR |
1120269Sericheng 	    DL_NOTE_LINK_UP |
1121269Sericheng 	    DL_NOTE_LINK_DOWN |
11222311Sseb 	    DL_NOTE_CAPAB_RENEG |
11238910SGirish.Moodalbail@Sun.COM 	    DL_NOTE_FASTPATH_FLUSH |
11242311Sseb 	    DL_NOTE_SPEED;
11250Sstevel@tonic-gate 
1126269Sericheng 	if (MBLKL(mp) < sizeof (dl_notify_req_t)) {
1127269Sericheng 		dl_err = DL_BADPRIM;
1128269Sericheng 		goto failed;
1129269Sericheng 	}
11300Sstevel@tonic-gate 
1131269Sericheng 	if (dsp->ds_dlstate == DL_UNATTACHED ||
1132269Sericheng 	    DL_ACK_PENDING(dsp->ds_dlstate)) {
1133269Sericheng 		dl_err = DL_OUTSTATE;
1134269Sericheng 		goto failed;
11350Sstevel@tonic-gate 	}
11360Sstevel@tonic-gate 
11375895Syz147064 	note &= ~(mac_no_notification(dsp->ds_mh));
11385895Syz147064 
1139269Sericheng 	/*
1140269Sericheng 	 * Cache the notifications that are being enabled.
1141269Sericheng 	 */
1142269Sericheng 	dsp->ds_notifications = dlp->dl_notifications & note;
1143269Sericheng 	/*
1144269Sericheng 	 * The ACK carries all notifications regardless of which set is
1145269Sericheng 	 * being enabled.
1146269Sericheng 	 */
1147269Sericheng 	dlnotifyack(q, mp, note);
1148269Sericheng 
1149269Sericheng 	/*
11508275SEric Cheng 	 * Generate DL_NOTIFY_IND messages for each enabled notification.
1151269Sericheng 	 */
1152269Sericheng 	if (dsp->ds_notifications != 0) {
1153269Sericheng 		dld_str_notify_ind(dsp);
1154269Sericheng 	}
11558275SEric Cheng 	return;
1156269Sericheng failed:
1157269Sericheng 	dlerrorack(q, mp, DL_NOTIFY_REQ, dl_err, 0);
11580Sstevel@tonic-gate }
11590Sstevel@tonic-gate 
11600Sstevel@tonic-gate /*
11618275SEric Cheng  * DL_UINTDATA_REQ
11620Sstevel@tonic-gate  */
11635895Syz147064 void
11648275SEric Cheng proto_unitdata_req(dld_str_t *dsp, mblk_t *mp)
11650Sstevel@tonic-gate {
1166269Sericheng 	queue_t			*q = dsp->ds_wq;
11675895Syz147064 	dl_unitdata_req_t	*dlp = (dl_unitdata_req_t *)mp->b_rptr;
1168269Sericheng 	off_t			off;
1169269Sericheng 	size_t			len, size;
1170269Sericheng 	const uint8_t		*addr;
1171269Sericheng 	uint16_t		sap;
1172269Sericheng 	uint_t			addr_length;
11732311Sseb 	mblk_t			*bp, *payload;
1174269Sericheng 	uint32_t		start, stuff, end, value, flags;
1175269Sericheng 	t_uscalar_t		dl_err;
11765903Ssowmini 	uint_t			max_sdu;
1177269Sericheng 
1178269Sericheng 	if (MBLKL(mp) < sizeof (dl_unitdata_req_t) || mp->b_cont == NULL) {
11798275SEric Cheng 		dlerrorack(q, mp, DL_UNITDATA_REQ, DL_BADPRIM, 0);
11808275SEric Cheng 		return;
1181269Sericheng 	}
1182269Sericheng 
11838275SEric Cheng 	mutex_enter(&dsp->ds_lock);
11848275SEric Cheng 	if (dsp->ds_dlstate != DL_IDLE) {
11858275SEric Cheng 		mutex_exit(&dsp->ds_lock);
11868275SEric Cheng 		dlerrorack(q, mp, DL_UNITDATA_REQ, DL_OUTSTATE, 0);
11878275SEric Cheng 		return;
11888275SEric Cheng 	}
11898275SEric Cheng 	DLD_DATATHR_INC(dsp);
11908275SEric Cheng 	mutex_exit(&dsp->ds_lock);
11918275SEric Cheng 
1192269Sericheng 	addr_length = dsp->ds_mip->mi_addr_length;
1193269Sericheng 
1194269Sericheng 	off = dlp->dl_dest_addr_offset;
1195269Sericheng 	len = dlp->dl_dest_addr_length;
1196269Sericheng 
1197269Sericheng 	if (!MBLKIN(mp, off, len) || !IS_P2ALIGNED(off, sizeof (uint16_t))) {
1198269Sericheng 		dl_err = DL_BADPRIM;
1199269Sericheng 		goto failed;
1200269Sericheng 	}
1201269Sericheng 
1202269Sericheng 	if (len != addr_length + sizeof (uint16_t)) {
1203269Sericheng 		dl_err = DL_BADADDR;
1204269Sericheng 		goto failed;
1205269Sericheng 	}
1206269Sericheng 
1207269Sericheng 	addr = mp->b_rptr + off;
1208269Sericheng 	sap = *(uint16_t *)(mp->b_rptr + off + addr_length);
1209269Sericheng 
1210269Sericheng 	/*
1211269Sericheng 	 * Check the length of the packet and the block types.
1212269Sericheng 	 */
1213269Sericheng 	size = 0;
12142311Sseb 	payload = mp->b_cont;
12152311Sseb 	for (bp = payload; bp != NULL; bp = bp->b_cont) {
1216269Sericheng 		if (DB_TYPE(bp) != M_DATA)
1217269Sericheng 			goto baddata;
1218269Sericheng 
1219269Sericheng 		size += MBLKL(bp);
1220269Sericheng 	}
1221269Sericheng 
12225903Ssowmini 	mac_sdu_get(dsp->ds_mh, NULL, &max_sdu);
12235903Ssowmini 	if (size > max_sdu)
1224269Sericheng 		goto baddata;
1225269Sericheng 
1226269Sericheng 	/*
1227269Sericheng 	 * Build a packet header.
1228269Sericheng 	 */
12298275SEric Cheng 	if ((bp = dls_header(dsp, addr, sap, dlp->dl_priority.dl_max,
12302760Sdg199075 	    &payload)) == NULL) {
1231269Sericheng 		dl_err = DL_BADADDR;
1232269Sericheng 		goto failed;
1233269Sericheng 	}
1234269Sericheng 
1235269Sericheng 	/*
1236269Sericheng 	 * We no longer need the M_PROTO header, so free it.
1237269Sericheng 	 */
1238269Sericheng 	freeb(mp);
1239269Sericheng 
1240269Sericheng 	/*
1241269Sericheng 	 * Transfer the checksum offload information if it is present.
1242269Sericheng 	 */
12432311Sseb 	hcksum_retrieve(payload, NULL, NULL, &start, &stuff, &end, &value,
1244269Sericheng 	    &flags);
12452311Sseb 	(void) hcksum_assoc(bp, NULL, NULL, start, stuff, end, value, flags, 0);
1246269Sericheng 
1247269Sericheng 	/*
1248269Sericheng 	 * Link the payload onto the new header.
1249269Sericheng 	 */
1250269Sericheng 	ASSERT(bp->b_cont == NULL);
12512311Sseb 	bp->b_cont = payload;
12528275SEric Cheng 
12538275SEric Cheng 	/*
12548275SEric Cheng 	 * No lock can be held across modules and putnext()'s,
12558275SEric Cheng 	 * which can happen here with the call from DLD_TX().
12568275SEric Cheng 	 */
12578275SEric Cheng 	if (DLD_TX(dsp, bp, 0, 0) != NULL) {
12588275SEric Cheng 		/* flow-controlled */
12598275SEric Cheng 		DLD_SETQFULL(dsp);
12608275SEric Cheng 	}
12618275SEric Cheng 	DLD_DATATHR_DCR(dsp);
12625895Syz147064 	return;
12638275SEric Cheng 
1264269Sericheng failed:
1265269Sericheng 	dlerrorack(q, mp, DL_UNITDATA_REQ, dl_err, 0);
12668275SEric Cheng 	DLD_DATATHR_DCR(dsp);
12675895Syz147064 	return;
1268269Sericheng 
1269269Sericheng baddata:
1270269Sericheng 	dluderrorind(q, mp, (void *)addr, len, DL_BADDATA, 0);
12718275SEric Cheng 	DLD_DATATHR_DCR(dsp);
1272269Sericheng }
1273269Sericheng 
1274269Sericheng /*
1275269Sericheng  * DL_PASSIVE_REQ
1276269Sericheng  */
12778275SEric Cheng static void
12788275SEric Cheng proto_passive_req(dld_str_t *dsp, mblk_t *mp)
1279269Sericheng {
1280269Sericheng 	t_uscalar_t dl_err;
1281269Sericheng 
12825895Syz147064 	/*
1283269Sericheng 	 * If we've already become active by issuing an active primitive,
1284269Sericheng 	 * then it's too late to try to become passive.
1285269Sericheng 	 */
1286269Sericheng 	if (dsp->ds_passivestate == DLD_ACTIVE) {
1287269Sericheng 		dl_err = DL_OUTSTATE;
1288269Sericheng 		goto failed;
1289269Sericheng 	}
1290269Sericheng 
1291269Sericheng 	if (MBLKL(mp) < sizeof (dl_passive_req_t)) {
1292269Sericheng 		dl_err = DL_BADPRIM;
1293269Sericheng 		goto failed;
1294269Sericheng 	}
1295269Sericheng 
1296269Sericheng 	dsp->ds_passivestate = DLD_PASSIVE;
1297269Sericheng 	dlokack(dsp->ds_wq, mp, DL_PASSIVE_REQ);
12988275SEric Cheng 	return;
1299269Sericheng failed:
1300269Sericheng 	dlerrorack(dsp->ds_wq, mp, DL_PASSIVE_REQ, dl_err, 0);
1301269Sericheng }
1302269Sericheng 
13038275SEric Cheng 
1304269Sericheng /*
1305269Sericheng  * Catch-all handler.
1306269Sericheng  */
13078275SEric Cheng static void
13088275SEric Cheng proto_req(dld_str_t *dsp, mblk_t *mp)
13098275SEric Cheng {
13108275SEric Cheng 	union DL_primitives	*dlp = (union DL_primitives *)mp->b_rptr;
13118275SEric Cheng 
13128275SEric Cheng 	dlerrorack(dsp->ds_wq, mp, dlp->dl_primitive, DL_UNSUPPORTED, 0);
13138275SEric Cheng }
13148275SEric Cheng 
13158275SEric Cheng static int
13168275SEric Cheng dld_capab_perim(dld_str_t *dsp, void *data, uint_t flags)
1317269Sericheng {
13188275SEric Cheng 	switch (flags) {
13198275SEric Cheng 	case DLD_ENABLE:
13208275SEric Cheng 		mac_perim_enter_by_mh(dsp->ds_mh, (mac_perim_handle_t *)data);
13218275SEric Cheng 		return (0);
13228275SEric Cheng 
13238275SEric Cheng 	case DLD_DISABLE:
13248275SEric Cheng 		mac_perim_exit((mac_perim_handle_t)data);
13258275SEric Cheng 		return (0);
13268275SEric Cheng 
13278275SEric Cheng 	case DLD_QUERY:
13288275SEric Cheng 		return (mac_perim_held(dsp->ds_mh));
13298275SEric Cheng 	}
13308275SEric Cheng 	return (0);
13310Sstevel@tonic-gate }
13320Sstevel@tonic-gate 
13338275SEric Cheng static int
13348275SEric Cheng dld_capab_direct(dld_str_t *dsp, void *data, uint_t flags)
13350Sstevel@tonic-gate {
13368275SEric Cheng 	dld_capab_direct_t	*direct = data;
13378275SEric Cheng 
13388275SEric Cheng 	ASSERT(MAC_PERIM_HELD(dsp->ds_mh));
13390Sstevel@tonic-gate 
13408275SEric Cheng 	switch (flags) {
13418275SEric Cheng 	case DLD_ENABLE:
13428275SEric Cheng 		dls_rx_set(dsp, (dls_rx_t)direct->di_rx_cf,
13438275SEric Cheng 		    direct->di_rx_ch);
13448833SVenu.Iyer@Sun.COM 
13458275SEric Cheng 		direct->di_tx_df = (uintptr_t)str_mdata_fastpath_put;
13468275SEric Cheng 		direct->di_tx_dh = dsp;
13478275SEric Cheng 		direct->di_tx_cb_df = (uintptr_t)mac_client_tx_notify;
13488275SEric Cheng 		direct->di_tx_cb_dh = dsp->ds_mch;
13498833SVenu.Iyer@Sun.COM 		direct->di_tx_fctl_df = (uintptr_t)mac_tx_is_flow_blocked;
13508833SVenu.Iyer@Sun.COM 		direct->di_tx_fctl_dh = dsp->ds_mch;
13518833SVenu.Iyer@Sun.COM 
13528275SEric Cheng 		dsp->ds_direct = B_TRUE;
13538275SEric Cheng 
13548275SEric Cheng 		return (0);
1355269Sericheng 
13568275SEric Cheng 	case DLD_DISABLE:
13578275SEric Cheng 		dls_rx_set(dsp, (dsp->ds_mode == DLD_FASTPATH) ?
13588275SEric Cheng 		    dld_str_rx_fastpath : dld_str_rx_unitdata, (void *)dsp);
13598275SEric Cheng 		dsp->ds_direct = B_FALSE;
13608275SEric Cheng 
13618275SEric Cheng 		return (0);
13628275SEric Cheng 	}
13638275SEric Cheng 	return (ENOTSUP);
13648275SEric Cheng }
13650Sstevel@tonic-gate 
13668275SEric Cheng /*
13678275SEric Cheng  * dld_capab_poll_enable()
13688275SEric Cheng  *
13698275SEric Cheng  * This function is misnamed. All polling  and fanouts are run out of the
13708275SEric Cheng  * lower mac (in case of VNIC and the only mac in case of NICs). The
13718275SEric Cheng  * availability of Rx ring and promiscous mode is all taken care between
13728275SEric Cheng  * the soft ring set (mac_srs), the Rx ring, and S/W classifier. Any
13738275SEric Cheng  * fanout necessary is done by the soft rings that are part of the
13748275SEric Cheng  * mac_srs (by default mac_srs sends the packets up via a TCP and
13758275SEric Cheng  * non TCP soft ring).
13768275SEric Cheng  *
13778275SEric Cheng  * The mac_srs (or its associated soft rings) always store the ill_rx_ring
13788275SEric Cheng  * (the cookie returned when they registered with IP during plumb) as their
13798275SEric Cheng  * 2nd argument which is passed up as mac_resource_handle_t. The upcall
13808275SEric Cheng  * function and 1st argument is what the caller registered when they
13818275SEric Cheng  * called mac_rx_classify_flow_add() to register the flow. For VNIC,
13828275SEric Cheng  * the function is vnic_rx and argument is vnic_t. For regular NIC
13838275SEric Cheng  * case, it mac_rx_default and mac_handle_t. As explained above, the
13848275SEric Cheng  * mac_srs (or its soft ring) will add the ill_rx_ring (mac_resource_handle_t)
13858275SEric Cheng  * from its stored 2nd argument.
13868275SEric Cheng  */
13878275SEric Cheng static int
13888275SEric Cheng dld_capab_poll_enable(dld_str_t *dsp, dld_capab_poll_t *poll)
13898275SEric Cheng {
13908275SEric Cheng 	if (dsp->ds_polling)
13918275SEric Cheng 		return (EINVAL);
13928275SEric Cheng 
13938275SEric Cheng 	if ((dld_opt & DLD_OPT_NO_POLL) != 0 || dsp->ds_mode == DLD_RAW)
13948275SEric Cheng 		return (ENOTSUP);
13950Sstevel@tonic-gate 
13960Sstevel@tonic-gate 	/*
13978275SEric Cheng 	 * Enable client polling if and only if DLS bypass is possible.
13988275SEric Cheng 	 * Special cases like VLANs need DLS processing in the Rx data path.
13998275SEric Cheng 	 * In such a case we can neither allow the client (IP) to directly
14008275SEric Cheng 	 * poll the softring (since DLS processing hasn't been done) nor can
14018275SEric Cheng 	 * we allow DLS bypass.
14020Sstevel@tonic-gate 	 */
14038275SEric Cheng 	if (!mac_rx_bypass_set(dsp->ds_mch, dsp->ds_rx, dsp->ds_rx_arg))
14048275SEric Cheng 		return (ENOTSUP);
14050Sstevel@tonic-gate 
14060Sstevel@tonic-gate 	/*
14078275SEric Cheng 	 * Register soft ring resources. This will come in handy later if
14088275SEric Cheng 	 * the user decides to modify CPU bindings to use more CPUs for the
14098275SEric Cheng 	 * device in which case we will switch to fanout using soft rings.
14100Sstevel@tonic-gate 	 */
14118275SEric Cheng 	mac_resource_set_common(dsp->ds_mch,
14128275SEric Cheng 	    (mac_resource_add_t)poll->poll_ring_add_cf,
14138275SEric Cheng 	    (mac_resource_remove_t)poll->poll_ring_remove_cf,
14148275SEric Cheng 	    (mac_resource_quiesce_t)poll->poll_ring_quiesce_cf,
14158275SEric Cheng 	    (mac_resource_restart_t)poll->poll_ring_restart_cf,
14168275SEric Cheng 	    (mac_resource_bind_t)poll->poll_ring_bind_cf,
14178275SEric Cheng 	    poll->poll_ring_ch);
14188275SEric Cheng 
14198275SEric Cheng 	mac_client_poll_enable(dsp->ds_mch);
14200Sstevel@tonic-gate 
14210Sstevel@tonic-gate 	dsp->ds_polling = B_TRUE;
14228275SEric Cheng 	return (0);
14238275SEric Cheng }
14248275SEric Cheng 
14258275SEric Cheng /* ARGSUSED */
14268275SEric Cheng static int
14278275SEric Cheng dld_capab_poll_disable(dld_str_t *dsp, dld_capab_poll_t *poll)
14288275SEric Cheng {
14298275SEric Cheng 	if (!dsp->ds_polling)
14308275SEric Cheng 		return (EINVAL);
14318275SEric Cheng 
14328275SEric Cheng 	mac_client_poll_disable(dsp->ds_mch);
14338275SEric Cheng 	mac_resource_set(dsp->ds_mch, NULL, NULL);
14348275SEric Cheng 
14358275SEric Cheng 	dsp->ds_polling = B_FALSE;
14368275SEric Cheng 	return (0);
14370Sstevel@tonic-gate }
14380Sstevel@tonic-gate 
14398275SEric Cheng static int
14408275SEric Cheng dld_capab_poll(dld_str_t *dsp, void *data, uint_t flags)
14418275SEric Cheng {
14428275SEric Cheng 	dld_capab_poll_t	*poll = data;
14438275SEric Cheng 
14448275SEric Cheng 	ASSERT(MAC_PERIM_HELD(dsp->ds_mh));
14458275SEric Cheng 
14468275SEric Cheng 	switch (flags) {
14478275SEric Cheng 	case DLD_ENABLE:
14488275SEric Cheng 		return (dld_capab_poll_enable(dsp, poll));
14498275SEric Cheng 	case DLD_DISABLE:
14508275SEric Cheng 		return (dld_capab_poll_disable(dsp, poll));
14518275SEric Cheng 	}
14528275SEric Cheng 	return (ENOTSUP);
14538275SEric Cheng }
14548275SEric Cheng 
14558275SEric Cheng static int
14568275SEric Cheng dld_capab_lso(dld_str_t *dsp, void *data, uint_t flags)
14571184Skrgopi {
14588275SEric Cheng 	dld_capab_lso_t		*lso = data;
14598275SEric Cheng 
14608275SEric Cheng 	ASSERT(MAC_PERIM_HELD(dsp->ds_mh));
14618275SEric Cheng 
14628275SEric Cheng 	switch (flags) {
14638275SEric Cheng 	case DLD_ENABLE: {
14648275SEric Cheng 		mac_capab_lso_t		mac_lso;
14651184Skrgopi 
14668275SEric Cheng 		/*
14678275SEric Cheng 		 * Check if LSO is supported on this MAC & enable LSO
14688275SEric Cheng 		 * accordingly.
14698275SEric Cheng 		 */
14708275SEric Cheng 		if (mac_capab_get(dsp->ds_mh, MAC_CAPAB_LSO, &mac_lso)) {
14718275SEric Cheng 			lso->lso_max = mac_lso.lso_basic_tcp_ipv4.lso_max;
14728275SEric Cheng 			lso->lso_flags = 0;
14738275SEric Cheng 			/* translate the flag for mac clients */
14748275SEric Cheng 			if ((mac_lso.lso_flags & LSO_TX_BASIC_TCP_IPV4) != 0)
14758275SEric Cheng 				lso->lso_flags |= DLD_LSO_TX_BASIC_TCP_IPV4;
14768275SEric Cheng 			dsp->ds_lso = B_TRUE;
14778275SEric Cheng 			dsp->ds_lso_max = lso->lso_max;
14788275SEric Cheng 		} else {
14798275SEric Cheng 			dsp->ds_lso = B_FALSE;
14808275SEric Cheng 			dsp->ds_lso_max = 0;
14818275SEric Cheng 			return (ENOTSUP);
14828275SEric Cheng 		}
14838275SEric Cheng 		return (0);
14848275SEric Cheng 	}
14858275SEric Cheng 	case DLD_DISABLE: {
14868275SEric Cheng 		dsp->ds_lso = B_FALSE;
14878275SEric Cheng 		dsp->ds_lso_max = 0;
14888275SEric Cheng 		return (0);
14898275SEric Cheng 	}
14908275SEric Cheng 	}
14918275SEric Cheng 	return (ENOTSUP);
14928275SEric Cheng }
14938275SEric Cheng 
14948275SEric Cheng static int
14958275SEric Cheng dld_capab(dld_str_t *dsp, uint_t type, void *data, uint_t flags)
14968275SEric Cheng {
14978275SEric Cheng 	int	err;
14981184Skrgopi 
14991184Skrgopi 	/*
15008275SEric Cheng 	 * Don't enable direct callback capabilities unless the caller is
15018275SEric Cheng 	 * the IP client. When a module is inserted in a stream (_I_INSERT)
15028275SEric Cheng 	 * the stack initiates capability disable, but due to races, the
15038275SEric Cheng 	 * module insertion may complete before the capability disable
15048275SEric Cheng 	 * completes. So we limit the check to DLD_ENABLE case.
15051184Skrgopi 	 */
15068275SEric Cheng 	if ((flags == DLD_ENABLE && type != DLD_CAPAB_PERIM) &&
15078275SEric Cheng 	    (dsp->ds_sap != ETHERTYPE_IP || !check_ip_above(dsp->ds_rq))) {
15088275SEric Cheng 		return (ENOTSUP);
15098275SEric Cheng 	}
15101184Skrgopi 
15118275SEric Cheng 	switch (type) {
15128275SEric Cheng 	case DLD_CAPAB_DIRECT:
15138275SEric Cheng 		err = dld_capab_direct(dsp, data, flags);
15148275SEric Cheng 		break;
15151184Skrgopi 
15168275SEric Cheng 	case DLD_CAPAB_POLL:
15178275SEric Cheng 		err =  dld_capab_poll(dsp, data, flags);
15188275SEric Cheng 		break;
15191184Skrgopi 
15208275SEric Cheng 	case DLD_CAPAB_PERIM:
15218275SEric Cheng 		err = dld_capab_perim(dsp, data, flags);
15228275SEric Cheng 		break;
15231184Skrgopi 
15248275SEric Cheng 	case DLD_CAPAB_LSO:
15258275SEric Cheng 		err = dld_capab_lso(dsp, data, flags);
15268275SEric Cheng 		break;
15278275SEric Cheng 
15288275SEric Cheng 	default:
15298275SEric Cheng 		err = ENOTSUP;
15308275SEric Cheng 		break;
15311184Skrgopi 	}
15328275SEric Cheng 
15338275SEric Cheng 	return (err);
15341184Skrgopi }
15351184Skrgopi 
15360Sstevel@tonic-gate /*
15370Sstevel@tonic-gate  * DL_CAPABILITY_ACK/DL_ERROR_ACK
15380Sstevel@tonic-gate  */
15398275SEric Cheng static void
1540269Sericheng proto_capability_advertise(dld_str_t *dsp, mblk_t *mp)
15410Sstevel@tonic-gate {
15420Sstevel@tonic-gate 	dl_capability_ack_t	*dlap;
15430Sstevel@tonic-gate 	dl_capability_sub_t	*dlsp;
15440Sstevel@tonic-gate 	size_t			subsize;
15458275SEric Cheng 	dl_capab_dld_t		dld;
15460Sstevel@tonic-gate 	dl_capab_hcksum_t	hcksum;
15470Sstevel@tonic-gate 	dl_capab_zerocopy_t	zcopy;
15480Sstevel@tonic-gate 	uint8_t			*ptr;
1549269Sericheng 	queue_t			*q = dsp->ds_wq;
1550269Sericheng 	mblk_t			*mp1;
15518275SEric Cheng 	boolean_t		is_vlan;
15525895Syz147064 	boolean_t		hcksum_capable = B_FALSE;
15535895Syz147064 	boolean_t		zcopy_capable = B_FALSE;
15548275SEric Cheng 	boolean_t		dld_capable = B_FALSE;
15550Sstevel@tonic-gate 
15560Sstevel@tonic-gate 	/*
15570Sstevel@tonic-gate 	 * Initially assume no capabilities.
15580Sstevel@tonic-gate 	 */
15590Sstevel@tonic-gate 	subsize = 0;
15608275SEric Cheng 	is_vlan = (mac_client_vid(dsp->ds_mch) != VLAN_ID_NONE);
15610Sstevel@tonic-gate 
15620Sstevel@tonic-gate 	/*
15635895Syz147064 	 * Check if checksum offload is supported on this MAC.  Don't
15645895Syz147064 	 * advertise DL_CAPAB_HCKSUM if the underlying MAC is VLAN incapable,
15655895Syz147064 	 * since it might not be able to do the hardware checksum offload
15665895Syz147064 	 * with the correct offset.
15670Sstevel@tonic-gate 	 */
15685895Syz147064 	bzero(&hcksum, sizeof (dl_capab_hcksum_t));
15695895Syz147064 	if ((!is_vlan || (!mac_capab_get(dsp->ds_mh, MAC_CAPAB_NO_NATIVEVLAN,
15705895Syz147064 	    NULL))) && mac_capab_get(dsp->ds_mh, MAC_CAPAB_HCKSUM,
15712311Sseb 	    &hcksum.hcksum_txflags)) {
15725895Syz147064 		if (hcksum.hcksum_txflags != 0) {
15735895Syz147064 			hcksum_capable = B_TRUE;
15745895Syz147064 			subsize += sizeof (dl_capability_sub_t) +
15755895Syz147064 			    sizeof (dl_capab_hcksum_t);
15765895Syz147064 		}
15770Sstevel@tonic-gate 	}
15780Sstevel@tonic-gate 
15790Sstevel@tonic-gate 	/*
15805895Syz147064 	 * Check if zerocopy is supported on this interface.
15815895Syz147064 	 * If advertising DL_CAPAB_ZEROCOPY has not been explicitly disabled
15825895Syz147064 	 * then reserve space for that capability.
15830Sstevel@tonic-gate 	 */
15845895Syz147064 	if (!mac_capab_get(dsp->ds_mh, MAC_CAPAB_NO_ZCOPY, NULL) &&
15855895Syz147064 	    !(dld_opt & DLD_OPT_NO_ZEROCOPY)) {
15865895Syz147064 		zcopy_capable = B_TRUE;
15870Sstevel@tonic-gate 		subsize += sizeof (dl_capability_sub_t) +
15880Sstevel@tonic-gate 		    sizeof (dl_capab_zerocopy_t);
15890Sstevel@tonic-gate 	}
15900Sstevel@tonic-gate 
15910Sstevel@tonic-gate 	/*
15928275SEric Cheng 	 * Direct capability negotiation interface between IP and DLD
15938275SEric Cheng 	 */
15948275SEric Cheng 	if (dsp->ds_sap == ETHERTYPE_IP && check_ip_above(dsp->ds_rq)) {
15958275SEric Cheng 		dld_capable = B_TRUE;
15968275SEric Cheng 		subsize += sizeof (dl_capability_sub_t) +
15978275SEric Cheng 		    sizeof (dl_capab_dld_t);
15988275SEric Cheng 	}
15998275SEric Cheng 
16008275SEric Cheng 	/*
1601269Sericheng 	 * If there are no capabilities to advertise or if we
1602269Sericheng 	 * can't allocate a response, send a DL_ERROR_ACK.
16030Sstevel@tonic-gate 	 */
16041184Skrgopi 	if ((mp1 = reallocb(mp,
1605269Sericheng 	    sizeof (dl_capability_ack_t) + subsize, 0)) == NULL) {
1606269Sericheng 		dlerrorack(q, mp, DL_CAPABILITY_REQ, DL_NOTSUPPORTED, 0);
16078275SEric Cheng 		return;
16080Sstevel@tonic-gate 	}
16090Sstevel@tonic-gate 
1610269Sericheng 	mp = mp1;
1611269Sericheng 	DB_TYPE(mp) = M_PROTO;
1612269Sericheng 	mp->b_wptr = mp->b_rptr + sizeof (dl_capability_ack_t) + subsize;
1613269Sericheng 	bzero(mp->b_rptr, MBLKL(mp));
16140Sstevel@tonic-gate 	dlap = (dl_capability_ack_t *)mp->b_rptr;
16150Sstevel@tonic-gate 	dlap->dl_primitive = DL_CAPABILITY_ACK;
16160Sstevel@tonic-gate 	dlap->dl_sub_offset = sizeof (dl_capability_ack_t);
16170Sstevel@tonic-gate 	dlap->dl_sub_length = subsize;
16180Sstevel@tonic-gate 	ptr = (uint8_t *)&dlap[1];
16190Sstevel@tonic-gate 
16200Sstevel@tonic-gate 	/*
16210Sstevel@tonic-gate 	 * TCP/IP checksum offload.
16220Sstevel@tonic-gate 	 */
16235895Syz147064 	if (hcksum_capable) {
16240Sstevel@tonic-gate 		dlsp = (dl_capability_sub_t *)ptr;
16250Sstevel@tonic-gate 
16260Sstevel@tonic-gate 		dlsp->dl_cap = DL_CAPAB_HCKSUM;
16270Sstevel@tonic-gate 		dlsp->dl_length = sizeof (dl_capab_hcksum_t);
16280Sstevel@tonic-gate 		ptr += sizeof (dl_capability_sub_t);
16290Sstevel@tonic-gate 
16300Sstevel@tonic-gate 		hcksum.hcksum_version = HCKSUM_VERSION_1;
16310Sstevel@tonic-gate 		dlcapabsetqid(&(hcksum.hcksum_mid), dsp->ds_rq);
16320Sstevel@tonic-gate 		bcopy(&hcksum, ptr, sizeof (dl_capab_hcksum_t));
16330Sstevel@tonic-gate 		ptr += sizeof (dl_capab_hcksum_t);
16340Sstevel@tonic-gate 	}
16350Sstevel@tonic-gate 
16360Sstevel@tonic-gate 	/*
16370Sstevel@tonic-gate 	 * Zero copy
16380Sstevel@tonic-gate 	 */
16395895Syz147064 	if (zcopy_capable) {
16400Sstevel@tonic-gate 		dlsp = (dl_capability_sub_t *)ptr;
16410Sstevel@tonic-gate 
16420Sstevel@tonic-gate 		dlsp->dl_cap = DL_CAPAB_ZEROCOPY;
16430Sstevel@tonic-gate 		dlsp->dl_length = sizeof (dl_capab_zerocopy_t);
16440Sstevel@tonic-gate 		ptr += sizeof (dl_capability_sub_t);
16450Sstevel@tonic-gate 
16460Sstevel@tonic-gate 		bzero(&zcopy, sizeof (dl_capab_zerocopy_t));
16470Sstevel@tonic-gate 		zcopy.zerocopy_version = ZEROCOPY_VERSION_1;
16480Sstevel@tonic-gate 		zcopy.zerocopy_flags = DL_CAPAB_VMSAFE_MEM;
16490Sstevel@tonic-gate 
16500Sstevel@tonic-gate 		dlcapabsetqid(&(zcopy.zerocopy_mid), dsp->ds_rq);
16510Sstevel@tonic-gate 		bcopy(&zcopy, ptr, sizeof (dl_capab_zerocopy_t));
16520Sstevel@tonic-gate 		ptr += sizeof (dl_capab_zerocopy_t);
16530Sstevel@tonic-gate 	}
16540Sstevel@tonic-gate 
16558275SEric Cheng 	/*
16568275SEric Cheng 	 * Direct capability negotiation interface between IP and DLD.
16578275SEric Cheng 	 * Refer to dld.h for details.
16588275SEric Cheng 	 */
16598275SEric Cheng 	if (dld_capable) {
16608275SEric Cheng 		dlsp = (dl_capability_sub_t *)ptr;
16618275SEric Cheng 		dlsp->dl_cap = DL_CAPAB_DLD;
16628275SEric Cheng 		dlsp->dl_length = sizeof (dl_capab_dld_t);
16638275SEric Cheng 		ptr += sizeof (dl_capability_sub_t);
1664269Sericheng 
16658275SEric Cheng 		bzero(&dld, sizeof (dl_capab_dld_t));
16668275SEric Cheng 		dld.dld_version = DLD_CURRENT_VERSION;
16678275SEric Cheng 		dld.dld_capab = (uintptr_t)dld_capab;
16688275SEric Cheng 		dld.dld_capab_handle = (uintptr_t)dsp;
16698275SEric Cheng 
16708275SEric Cheng 		dlcapabsetqid(&(dld.dld_mid), dsp->ds_rq);
16718275SEric Cheng 		bcopy(&dld, ptr, sizeof (dl_capab_dld_t));
16728275SEric Cheng 		ptr += sizeof (dl_capab_dld_t);
16738275SEric Cheng 	}
16748275SEric Cheng 
16758275SEric Cheng 	ASSERT(ptr == mp->b_rptr + sizeof (dl_capability_ack_t) + subsize);
1676269Sericheng 	qreply(q, mp);
16770Sstevel@tonic-gate }
16785113Syz147064 
16795113Syz147064 /*
16805113Syz147064  * Disable any enabled capabilities.
16815113Syz147064  */
16825113Syz147064 void
16835113Syz147064 dld_capabilities_disable(dld_str_t *dsp)
16845113Syz147064 {
16855113Syz147064 	if (dsp->ds_polling)
16868275SEric Cheng 		(void) dld_capab_poll_disable(dsp, NULL);
16875113Syz147064 }
1688