xref: /onnv-gate/usr/src/uts/common/io/dld/dld_drv.c (revision 5903:df6aed881b11)
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
52311Sseb  * Common Development and Distribution License (the "License").
62311Sseb  * 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 /*
225895Syz147064  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * Data-Link Driver
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include	<sys/conf.h>
33269Sericheng #include	<sys/mkdev.h>
34269Sericheng #include	<sys/modctl.h>
350Sstevel@tonic-gate #include	<sys/stat.h>
36269Sericheng #include	<sys/strsun.h>
375895Syz147064 #include	<sys/vlan.h>
38269Sericheng #include	<sys/dld.h>
39269Sericheng #include	<sys/dld_impl.h>
40269Sericheng #include	<sys/dls_impl.h>
415895Syz147064 #include	<sys/softmac.h>
423448Sdh155122 #include 	<sys/vlan.h>
430Sstevel@tonic-gate #include	<inet/common.h>
440Sstevel@tonic-gate 
45269Sericheng /*
46269Sericheng  * dld control node state, one per open control node session.
47269Sericheng  */
48269Sericheng typedef struct dld_ctl_str_s {
49269Sericheng 	minor_t cs_minor;
50269Sericheng 	queue_t *cs_wq;
51269Sericheng } dld_ctl_str_t;
520Sstevel@tonic-gate 
530Sstevel@tonic-gate static void	drv_init(void);
540Sstevel@tonic-gate static int	drv_fini(void);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static int	drv_getinfo(dev_info_t	*, ddi_info_cmd_t, void *, void **);
570Sstevel@tonic-gate static int	drv_attach(dev_info_t *, ddi_attach_cmd_t);
580Sstevel@tonic-gate static int	drv_detach(dev_info_t *, ddi_detach_cmd_t);
590Sstevel@tonic-gate 
60269Sericheng /*
613147Sxc151355  * Secure objects declarations
623147Sxc151355  */
633147Sxc151355 #define	SECOBJ_WEP_HASHSZ	67
643147Sxc151355 static krwlock_t	drv_secobj_lock;
653147Sxc151355 static kmem_cache_t	*drv_secobj_cachep;
663147Sxc151355 static mod_hash_t	*drv_secobj_hash;
673147Sxc151355 static void		drv_secobj_init(void);
683147Sxc151355 static void		drv_secobj_fini(void);
693147Sxc151355 static void		drv_ioc_secobj_set(dld_ctl_str_t *, mblk_t *);
703147Sxc151355 static void		drv_ioc_secobj_get(dld_ctl_str_t *, mblk_t *);
713147Sxc151355 static void		drv_ioc_secobj_unset(dld_ctl_str_t *, mblk_t *);
723147Sxc151355 
733147Sxc151355 /*
74269Sericheng  * The following entry points are private to dld and are used for control
75269Sericheng  * operations only. The entry points exported to mac drivers are defined
76269Sericheng  * in dld_str.c. Refer to the comment on top of dld_str.c for details.
77269Sericheng  */
780Sstevel@tonic-gate static int	drv_open(queue_t *, dev_t *, int, int, cred_t *);
790Sstevel@tonic-gate static int	drv_close(queue_t *);
800Sstevel@tonic-gate 
810Sstevel@tonic-gate static void	drv_uw_put(queue_t *, mblk_t *);
820Sstevel@tonic-gate static void	drv_uw_srv(queue_t *);
830Sstevel@tonic-gate 
840Sstevel@tonic-gate dev_info_t	*dld_dip;		/* dev_info_t for the driver */
85269Sericheng uint32_t	dld_opt = 0;		/* Global options */
86269Sericheng static vmem_t	*dld_ctl_vmem;		/* for control minor numbers */
870Sstevel@tonic-gate 
885895Syz147064 #define	NAUTOPUSH 32
895895Syz147064 static mod_hash_t *dld_ap_hashp;
905895Syz147064 static krwlock_t dld_ap_hash_lock;
915895Syz147064 
920Sstevel@tonic-gate static	struct	module_info	drv_info = {
930Sstevel@tonic-gate 	0,			/* mi_idnum */
940Sstevel@tonic-gate 	DLD_DRIVER_NAME,	/* mi_idname */
950Sstevel@tonic-gate 	0,			/* mi_minpsz */
960Sstevel@tonic-gate 	(64 * 1024),		/* mi_maxpsz */
970Sstevel@tonic-gate 	1,			/* mi_hiwat */
980Sstevel@tonic-gate 	0			/* mi_lowat */
990Sstevel@tonic-gate };
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate static	struct qinit		drv_ur_init = {
1020Sstevel@tonic-gate 	NULL,			/* qi_putp */
1030Sstevel@tonic-gate 	NULL,			/* qi_srvp */
1040Sstevel@tonic-gate 	drv_open,		/* qi_qopen */
1050Sstevel@tonic-gate 	drv_close,		/* qi_qclose */
1060Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
1070Sstevel@tonic-gate 	&drv_info,		/* qi_minfo */
1080Sstevel@tonic-gate 	NULL			/* qi_mstat */
1090Sstevel@tonic-gate };
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate static	struct qinit		drv_uw_init = {
1120Sstevel@tonic-gate 	(pfi_t)drv_uw_put,	/* qi_putp */
1130Sstevel@tonic-gate 	(pfi_t)drv_uw_srv,	/* qi_srvp */
1140Sstevel@tonic-gate 	NULL,			/* qi_qopen */
1150Sstevel@tonic-gate 	NULL,			/* qi_qclose */
1160Sstevel@tonic-gate 	NULL,			/* qi_qadmin */
1170Sstevel@tonic-gate 	&drv_info,		/* qi_minfo */
1180Sstevel@tonic-gate 	NULL			/* qi_mstat */
1190Sstevel@tonic-gate };
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate static	struct streamtab	drv_stream = {
1220Sstevel@tonic-gate 	&drv_ur_init,		/* st_rdinit */
1230Sstevel@tonic-gate 	&drv_uw_init,		/* st_wrinit */
1240Sstevel@tonic-gate 	NULL,			/* st_muxrinit */
1250Sstevel@tonic-gate 	NULL			/* st_muxwinit */
1260Sstevel@tonic-gate };
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(drv_ops, nulldev, nulldev, drv_attach, drv_detach,
129269Sericheng     nodev, drv_getinfo, D_MP, &drv_stream);
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate  * Module linkage information for the kernel.
1330Sstevel@tonic-gate  */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate extern	struct mod_ops		mod_driverops;
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate static	struct modldrv		drv_modldrv = {
1380Sstevel@tonic-gate 	&mod_driverops,
1390Sstevel@tonic-gate 	DLD_INFO,
1400Sstevel@tonic-gate 	&drv_ops
1410Sstevel@tonic-gate };
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate static	struct modlinkage	drv_modlinkage = {
1440Sstevel@tonic-gate 	MODREV_1,
1450Sstevel@tonic-gate 	&drv_modldrv,
1460Sstevel@tonic-gate 	NULL
1470Sstevel@tonic-gate };
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate int
1500Sstevel@tonic-gate _init(void)
1510Sstevel@tonic-gate {
1520Sstevel@tonic-gate 	int	err;
1530Sstevel@tonic-gate 
154269Sericheng 	drv_init();
155269Sericheng 
1560Sstevel@tonic-gate 	if ((err = mod_install(&drv_modlinkage)) != 0)
1570Sstevel@tonic-gate 		return (err);
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 	return (0);
1600Sstevel@tonic-gate }
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate int
1630Sstevel@tonic-gate _fini(void)
1640Sstevel@tonic-gate {
1650Sstevel@tonic-gate 	int	err;
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate 	if ((err = mod_remove(&drv_modlinkage)) != 0)
1680Sstevel@tonic-gate 		return (err);
1690Sstevel@tonic-gate 
170269Sericheng 	if (drv_fini() != 0) {
171269Sericheng 		(void) mod_install(&drv_modlinkage);
172269Sericheng 		return (DDI_FAILURE);
173269Sericheng 	}
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	return (err);
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate 
1780Sstevel@tonic-gate int
1790Sstevel@tonic-gate _info(struct modinfo *modinfop)
1800Sstevel@tonic-gate {
1810Sstevel@tonic-gate 	return (mod_info(&drv_modlinkage, modinfop));
1820Sstevel@tonic-gate }
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate /*
185269Sericheng  * Initialize component modules.
1860Sstevel@tonic-gate  */
1870Sstevel@tonic-gate static void
1880Sstevel@tonic-gate drv_init(void)
1890Sstevel@tonic-gate {
190269Sericheng 	dld_ctl_vmem = vmem_create("dld_ctl", (void *)1, MAXMIN, 1,
191269Sericheng 	    NULL, NULL, NULL, 1, VM_SLEEP | VMC_IDENTIFIER);
1923147Sxc151355 	drv_secobj_init();
1930Sstevel@tonic-gate 	dld_str_init();
1945895Syz147064 	/*
1955895Syz147064 	 * Create a hash table for autopush configuration.
1965895Syz147064 	 */
1975895Syz147064 	dld_ap_hashp = mod_hash_create_idhash("dld_autopush_hash",
1985895Syz147064 	    NAUTOPUSH, mod_hash_null_valdtor);
1995895Syz147064 
2005895Syz147064 	ASSERT(dld_ap_hashp != NULL);
2015895Syz147064 	rw_init(&dld_ap_hash_lock, NULL, RW_DRIVER, NULL);
2025895Syz147064 }
2035895Syz147064 
2045895Syz147064 /* ARGSUSED */
2055895Syz147064 static uint_t
2065895Syz147064 drv_ap_exist(mod_hash_key_t key, mod_hash_val_t *val, void *arg)
2075895Syz147064 {
2085895Syz147064 	boolean_t *pexist = arg;
2095895Syz147064 
2105895Syz147064 	*pexist = B_TRUE;
2115895Syz147064 	return (MH_WALK_TERMINATE);
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate static int
2150Sstevel@tonic-gate drv_fini(void)
2160Sstevel@tonic-gate {
2175895Syz147064 	int		err;
2185895Syz147064 	boolean_t	exist = B_FALSE;
2195895Syz147064 
2205895Syz147064 	rw_enter(&dld_ap_hash_lock, RW_READER);
2215895Syz147064 	mod_hash_walk(dld_ap_hashp, drv_ap_exist, &exist);
2225895Syz147064 	rw_exit(&dld_ap_hash_lock);
2235895Syz147064 
2245895Syz147064 	if (exist)
2255895Syz147064 		return (EBUSY);
2260Sstevel@tonic-gate 
227269Sericheng 	if ((err = dld_str_fini()) != 0)
2280Sstevel@tonic-gate 		return (err);
2290Sstevel@tonic-gate 
2303147Sxc151355 	drv_secobj_fini();
231269Sericheng 	vmem_destroy(dld_ctl_vmem);
2325895Syz147064 	mod_hash_destroy_idhash(dld_ap_hashp);
2335895Syz147064 	rw_destroy(&dld_ap_hash_lock);
2340Sstevel@tonic-gate 	return (0);
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate /*
2380Sstevel@tonic-gate  * devo_getinfo: getinfo(9e)
2390Sstevel@tonic-gate  */
2400Sstevel@tonic-gate /*ARGSUSED*/
2410Sstevel@tonic-gate static int
2420Sstevel@tonic-gate drv_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **resp)
2430Sstevel@tonic-gate {
2440Sstevel@tonic-gate 	if (dld_dip == NULL)
2450Sstevel@tonic-gate 		return (DDI_FAILURE);
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate 	switch (cmd) {
2480Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
2490Sstevel@tonic-gate 		*resp = (void *)0;
2500Sstevel@tonic-gate 		break;
2510Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
2520Sstevel@tonic-gate 		*resp = (void *)dld_dip;
2530Sstevel@tonic-gate 		break;
2540Sstevel@tonic-gate 	default:
2550Sstevel@tonic-gate 		return (DDI_FAILURE);
2560Sstevel@tonic-gate 	}
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 	return (DDI_SUCCESS);
2590Sstevel@tonic-gate }
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate /*
2620Sstevel@tonic-gate  * Check properties to set options. (See dld.h for property definitions).
2630Sstevel@tonic-gate  */
2640Sstevel@tonic-gate static void
2650Sstevel@tonic-gate drv_set_opt(dev_info_t *dip)
2660Sstevel@tonic-gate {
2670Sstevel@tonic-gate 	if (ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
2680Sstevel@tonic-gate 	    DLD_PROP_NO_FASTPATH, 0) != 0) {
2690Sstevel@tonic-gate 		dld_opt |= DLD_OPT_NO_FASTPATH;
2700Sstevel@tonic-gate 	}
2710Sstevel@tonic-gate 
2720Sstevel@tonic-gate 	if (ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
2730Sstevel@tonic-gate 	    DLD_PROP_NO_POLL, 0) != 0) {
2740Sstevel@tonic-gate 		dld_opt |= DLD_OPT_NO_POLL;
2750Sstevel@tonic-gate 	}
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	if (ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
2780Sstevel@tonic-gate 	    DLD_PROP_NO_ZEROCOPY, 0) != 0) {
2790Sstevel@tonic-gate 		dld_opt |= DLD_OPT_NO_ZEROCOPY;
2800Sstevel@tonic-gate 	}
2814114Sja97890 
2824114Sja97890 	if (ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
2834114Sja97890 	    DLD_PROP_NO_SOFTRING, 0) != 0) {
2844114Sja97890 		dld_opt |= DLD_OPT_NO_SOFTRING;
2854114Sja97890 	}
2860Sstevel@tonic-gate }
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate /*
2890Sstevel@tonic-gate  * devo_attach: attach(9e)
2900Sstevel@tonic-gate  */
2910Sstevel@tonic-gate static int
2920Sstevel@tonic-gate drv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2930Sstevel@tonic-gate {
2940Sstevel@tonic-gate 	if (cmd != DDI_ATTACH)
2950Sstevel@tonic-gate 		return (DDI_FAILURE);
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate 	ASSERT(ddi_get_instance(dip) == 0);
2980Sstevel@tonic-gate 
2990Sstevel@tonic-gate 	drv_set_opt(dip);
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	/*
3020Sstevel@tonic-gate 	 * Create control node. DLPI provider nodes will be created on demand.
3030Sstevel@tonic-gate 	 */
3040Sstevel@tonic-gate 	if (ddi_create_minor_node(dip, DLD_CONTROL_MINOR_NAME, S_IFCHR,
3050Sstevel@tonic-gate 	    DLD_CONTROL_MINOR, DDI_PSEUDO, 0) != DDI_SUCCESS)
3060Sstevel@tonic-gate 		return (DDI_FAILURE);
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	dld_dip = dip;
3090Sstevel@tonic-gate 
3100Sstevel@tonic-gate 	/*
3110Sstevel@tonic-gate 	 * Log the fact that the driver is now attached.
3120Sstevel@tonic-gate 	 */
3130Sstevel@tonic-gate 	ddi_report_dev(dip);
3140Sstevel@tonic-gate 	return (DDI_SUCCESS);
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate /*
3180Sstevel@tonic-gate  * devo_detach: detach(9e)
3190Sstevel@tonic-gate  */
3200Sstevel@tonic-gate static int
3210Sstevel@tonic-gate drv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
3220Sstevel@tonic-gate {
3230Sstevel@tonic-gate 	if (cmd != DDI_DETACH)
3240Sstevel@tonic-gate 		return (DDI_FAILURE);
3250Sstevel@tonic-gate 
3260Sstevel@tonic-gate 	ASSERT(dld_dip == dip);
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	/*
3290Sstevel@tonic-gate 	 * Remove the control node.
3300Sstevel@tonic-gate 	 */
3310Sstevel@tonic-gate 	ddi_remove_minor_node(dip, DLD_CONTROL_MINOR_NAME);
3320Sstevel@tonic-gate 	dld_dip = NULL;
3330Sstevel@tonic-gate 
3340Sstevel@tonic-gate 	return (DDI_SUCCESS);
3350Sstevel@tonic-gate }
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate /*
338269Sericheng  * dld control node open procedure.
3390Sstevel@tonic-gate  */
3400Sstevel@tonic-gate /*ARGSUSED*/
3410Sstevel@tonic-gate static int
3420Sstevel@tonic-gate drv_open(queue_t *rq, dev_t *devp, int flag, int sflag, cred_t *credp)
3430Sstevel@tonic-gate {
344269Sericheng 	dld_ctl_str_t	*ctls;
3450Sstevel@tonic-gate 	minor_t		minor;
346269Sericheng 	queue_t *oq =	OTHERQ(rq);
3470Sstevel@tonic-gate 
348269Sericheng 	if (sflag == MODOPEN)
349269Sericheng 		return (ENOTSUP);
3500Sstevel@tonic-gate 
3510Sstevel@tonic-gate 	/*
3520Sstevel@tonic-gate 	 * This is a cloning driver and therefore each queue should only
3530Sstevel@tonic-gate 	 * ever get opened once.
3540Sstevel@tonic-gate 	 */
3550Sstevel@tonic-gate 	if (rq->q_ptr != NULL)
3560Sstevel@tonic-gate 		return (EBUSY);
3570Sstevel@tonic-gate 
358269Sericheng 	minor = (minor_t)(uintptr_t)vmem_alloc(dld_ctl_vmem, 1, VM_NOSLEEP);
359269Sericheng 	if (minor == 0)
360269Sericheng 		return (ENOMEM);
3610Sstevel@tonic-gate 
362269Sericheng 	ctls = kmem_zalloc(sizeof (dld_ctl_str_t), KM_NOSLEEP);
363269Sericheng 	if (ctls == NULL) {
364269Sericheng 		vmem_free(dld_ctl_vmem, (void *)(uintptr_t)minor, 1);
365269Sericheng 		return (ENOMEM);
366269Sericheng 	}
3670Sstevel@tonic-gate 
368269Sericheng 	ctls->cs_minor = minor;
369269Sericheng 	ctls->cs_wq = WR(rq);
3700Sstevel@tonic-gate 
371269Sericheng 	rq->q_ptr = ctls;
372269Sericheng 	oq->q_ptr = ctls;
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 	/*
3750Sstevel@tonic-gate 	 * Enable the queue srv(9e) routine.
3760Sstevel@tonic-gate 	 */
3770Sstevel@tonic-gate 	qprocson(rq);
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 	/*
3800Sstevel@tonic-gate 	 * Construct a cloned dev_t to hand back.
3810Sstevel@tonic-gate 	 */
382269Sericheng 	*devp = makedevice(getmajor(*devp), ctls->cs_minor);
3830Sstevel@tonic-gate 	return (0);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate /*
387269Sericheng  * dld control node close procedure.
3880Sstevel@tonic-gate  */
3890Sstevel@tonic-gate static int
3900Sstevel@tonic-gate drv_close(queue_t *rq)
3910Sstevel@tonic-gate {
392269Sericheng 	dld_ctl_str_t	*ctls;
3930Sstevel@tonic-gate 
394269Sericheng 	ctls = rq->q_ptr;
395269Sericheng 	ASSERT(ctls != NULL);
3960Sstevel@tonic-gate 
3970Sstevel@tonic-gate 	/*
3980Sstevel@tonic-gate 	 * Disable the queue srv(9e) routine.
3990Sstevel@tonic-gate 	 */
4000Sstevel@tonic-gate 	qprocsoff(rq);
4010Sstevel@tonic-gate 
402269Sericheng 	vmem_free(dld_ctl_vmem, (void *)(uintptr_t)ctls->cs_minor, 1);
4030Sstevel@tonic-gate 
404269Sericheng 	kmem_free(ctls, sizeof (dld_ctl_str_t));
405269Sericheng 
4060Sstevel@tonic-gate 	return (0);
4070Sstevel@tonic-gate }
4080Sstevel@tonic-gate 
4090Sstevel@tonic-gate /*
4105895Syz147064  * DLDIOC_ATTR
4110Sstevel@tonic-gate  */
4120Sstevel@tonic-gate static void
413269Sericheng drv_ioc_attr(dld_ctl_str_t *ctls, mblk_t *mp)
4140Sstevel@tonic-gate {
4155895Syz147064 	dld_ioc_attr_t		*diap;
4165895Syz147064 	dls_dl_handle_t		dlh;
4175895Syz147064 	dls_vlan_t		*dvp;
4185895Syz147064 	int			err;
4195895Syz147064 	queue_t			*q = ctls->cs_wq;
420269Sericheng 
421269Sericheng 	if ((err = miocpullup(mp, sizeof (dld_ioc_attr_t))) != 0)
422269Sericheng 		goto failed;
423269Sericheng 
424269Sericheng 	diap = (dld_ioc_attr_t *)mp->b_cont->b_rptr;
4255895Syz147064 
4265895Syz147064 	if ((err = dls_devnet_hold_tmp(diap->dia_linkid, &dlh)) != 0)
4275895Syz147064 		goto failed;
428269Sericheng 
4295895Syz147064 	if ((err = dls_vlan_hold(dls_devnet_mac(dlh),
4305895Syz147064 	    dls_devnet_vid(dlh), &dvp, B_FALSE, B_FALSE)) != 0) {
4315895Syz147064 		dls_devnet_rele_tmp(dlh);
432269Sericheng 		goto failed;
433269Sericheng 	}
434*5903Ssowmini 	mac_sdu_get(dvp->dv_dlp->dl_mh, NULL, &diap->dia_max_sdu);
435269Sericheng 
436269Sericheng 	dls_vlan_rele(dvp);
4375895Syz147064 	dls_devnet_rele_tmp(dlh);
4380Sstevel@tonic-gate 
4395895Syz147064 	miocack(q, mp, sizeof (dld_ioc_attr_t), 0);
440269Sericheng 	return;
441269Sericheng 
442269Sericheng failed:
443269Sericheng 	ASSERT(err != 0);
444269Sericheng 	miocnak(q, mp, 0, err);
445269Sericheng }
446269Sericheng 
4473448Sdh155122 /*
4485895Syz147064  * DLDIOC_PHYS_ATTR
4493448Sdh155122  */
4503448Sdh155122 static void
4515895Syz147064 drv_ioc_phys_attr(dld_ctl_str_t *ctls, mblk_t *mp)
4523448Sdh155122 {
4535895Syz147064 	dld_ioc_phys_attr_t	*dipp;
4545895Syz147064 	int			err;
4555895Syz147064 	dls_dl_handle_t		dlh;
4565895Syz147064 	dls_dev_handle_t	ddh;
4575895Syz147064 	dev_t			phydev;
4585895Syz147064 	queue_t			*q = ctls->cs_wq;
4593448Sdh155122 
4605895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_phys_attr_t))) != 0)
4614049Sdh155122 		goto failed;
4624049Sdh155122 
4635895Syz147064 	dipp = (dld_ioc_phys_attr_t *)mp->b_cont->b_rptr;
4645895Syz147064 
4655895Syz147064 	/*
4665895Syz147064 	 * Every physical link should have its physical dev_t kept in the
4675895Syz147064 	 * daemon. If not, it is not a valid physical link.
4685895Syz147064 	 */
4695895Syz147064 	if (dls_mgmt_get_phydev(dipp->dip_linkid, &phydev) != 0) {
4705895Syz147064 		err = EINVAL;
4715895Syz147064 		goto failed;
4725895Syz147064 	}
4733448Sdh155122 
4744049Sdh155122 	/*
4755895Syz147064 	 * Although this is a valid physical link, it might already be removed
4765895Syz147064 	 * by DR or during system shutdown. softmac_hold_device() would return
4775895Syz147064 	 * ENOENT in this case.
4785895Syz147064 	 */
4795895Syz147064 	if ((err = softmac_hold_device(phydev, &ddh)) != 0)
4805895Syz147064 		goto failed;
4815895Syz147064 
4825895Syz147064 	if (dls_devnet_hold_tmp(dipp->dip_linkid, &dlh) != 0) {
4835895Syz147064 		/*
4845895Syz147064 		 * Although this is an active physical link, its link type is
4855895Syz147064 		 * not supported by GLDv3, and therefore it does not have
4865895Syz147064 		 * vanity naming support.
4875895Syz147064 		 */
4885895Syz147064 		dipp->dip_novanity = B_TRUE;
4895895Syz147064 	} else {
4905895Syz147064 		dipp->dip_novanity = B_FALSE;
4915895Syz147064 		dls_devnet_rele_tmp(dlh);
4925895Syz147064 	}
4935895Syz147064 	/*
4945895Syz147064 	 * Get the physical device name from the major number and the instance
4955895Syz147064 	 * number derived from phydev.
4964049Sdh155122 	 */
4975895Syz147064 	(void) snprintf(dipp->dip_dev, MAXLINKNAMELEN, "%s%d",
4985895Syz147064 	    ddi_major_to_name(getmajor(phydev)), getminor(phydev) - 1);
4995895Syz147064 
5005895Syz147064 	softmac_rele_device(ddh);
5015895Syz147064 
5025895Syz147064 	miocack(q, mp, sizeof (dld_ioc_phys_attr_t), 0);
5035895Syz147064 	return;
5045895Syz147064 
5055895Syz147064 failed:
5065895Syz147064 	miocnak(q, mp, 0, err);
5075895Syz147064 }
5085895Syz147064 
5095895Syz147064 /*
510*5903Ssowmini  * DLDIOCSETPROP
511*5903Ssowmini  */
512*5903Ssowmini static void
513*5903Ssowmini drv_ioc_prop_common(dld_ctl_str_t *ctls, mblk_t *mp, boolean_t set)
514*5903Ssowmini {
515*5903Ssowmini 	int		err = EINVAL, dsize;
516*5903Ssowmini 	queue_t		*q = ctls->cs_wq;
517*5903Ssowmini 	dld_ioc_prop_t	*dipp;
518*5903Ssowmini 	dls_dl_handle_t 	dlh;
519*5903Ssowmini 	dls_vlan_t		*dvp;
520*5903Ssowmini 	datalink_id_t 		linkid;
521*5903Ssowmini 	mac_prop_t		macprop;
522*5903Ssowmini 
523*5903Ssowmini 	if ((err = miocpullup(mp, sizeof (dld_ioc_prop_t))) != 0)
524*5903Ssowmini 		goto done;
525*5903Ssowmini 	dipp = (dld_ioc_prop_t *)mp->b_cont->b_rptr;
526*5903Ssowmini 
527*5903Ssowmini 	dsize = sizeof (dld_ioc_prop_t) + dipp->pr_valsize - 1;
528*5903Ssowmini 	if ((err = miocpullup(mp, dsize)) != 0)
529*5903Ssowmini 		goto done;
530*5903Ssowmini 	dipp = (dld_ioc_prop_t *)mp->b_cont->b_rptr;
531*5903Ssowmini 
532*5903Ssowmini 	if ((err = dls_mgmt_get_linkid(dipp->pr_linkname, &linkid)) != 0)
533*5903Ssowmini 		goto done;
534*5903Ssowmini 
535*5903Ssowmini 	if ((err = dls_devnet_hold_tmp(linkid, &dlh)) != 0)
536*5903Ssowmini 		goto done;
537*5903Ssowmini 
538*5903Ssowmini 	if ((err = dls_vlan_hold(dls_devnet_mac(dlh),
539*5903Ssowmini 	    dls_devnet_vid(dlh), &dvp, B_FALSE, B_FALSE)) != 0) {
540*5903Ssowmini 		dls_devnet_rele_tmp(dlh);
541*5903Ssowmini 		goto done;
542*5903Ssowmini 	}
543*5903Ssowmini 
544*5903Ssowmini 	macprop.mp_name = dipp->pr_name;
545*5903Ssowmini 	macprop.mp_id = dipp->pr_num;
546*5903Ssowmini 
547*5903Ssowmini 	if (set)
548*5903Ssowmini 		err = mac_set_prop(dvp->dv_dlp->dl_mh, &macprop,
549*5903Ssowmini 		    dipp->pr_val, dipp->pr_valsize);
550*5903Ssowmini 	else
551*5903Ssowmini 		err = mac_get_prop(dvp->dv_dlp->dl_mh, &macprop,
552*5903Ssowmini 		    dipp->pr_val, dipp->pr_valsize);
553*5903Ssowmini 
554*5903Ssowmini 	dls_vlan_rele(dvp);
555*5903Ssowmini 	dls_devnet_rele_tmp(dlh);
556*5903Ssowmini done:
557*5903Ssowmini 	if (err == 0)
558*5903Ssowmini 		miocack(q, mp, dsize, 0);
559*5903Ssowmini 	else
560*5903Ssowmini 		miocnak(q, mp, 0, err);
561*5903Ssowmini }
562*5903Ssowmini 
563*5903Ssowmini static void
564*5903Ssowmini drv_ioc_setprop(dld_ctl_str_t *ctls, mblk_t *mp)
565*5903Ssowmini {
566*5903Ssowmini 	drv_ioc_prop_common(ctls, mp, B_TRUE);
567*5903Ssowmini }
568*5903Ssowmini 
569*5903Ssowmini static void
570*5903Ssowmini drv_ioc_getprop(dld_ctl_str_t *ctls, mblk_t *mp)
571*5903Ssowmini {
572*5903Ssowmini 	drv_ioc_prop_common(ctls, mp, B_FALSE);
573*5903Ssowmini }
574*5903Ssowmini 
575*5903Ssowmini /*
5765895Syz147064  * DLDIOC_CREATE_VLAN
5775895Syz147064  */
5785895Syz147064 static void
5795895Syz147064 drv_ioc_create_vlan(dld_ctl_str_t *ctls, mblk_t *mp)
5805895Syz147064 {
5815895Syz147064 	dld_ioc_create_vlan_t	*dicp;
5825895Syz147064 	int			err;
5835895Syz147064 	queue_t			*q = ctls->cs_wq;
5845895Syz147064 
5855895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_create_vlan_t))) != 0)
5864049Sdh155122 		goto failed;
5874049Sdh155122 
5885895Syz147064 	dicp = (dld_ioc_create_vlan_t *)mp->b_cont->b_rptr;
5895895Syz147064 
5905895Syz147064 	if ((err = dls_devnet_create_vlan(dicp->dic_vlanid,
5915895Syz147064 	    dicp->dic_linkid, dicp->dic_vid, dicp->dic_force)) != 0) {
5925895Syz147064 		goto failed;
5933448Sdh155122 	}
5943448Sdh155122 
5955895Syz147064 	miocack(q, mp, 0, 0);
5965895Syz147064 	return;
5975895Syz147064 
5985895Syz147064 failed:
5995895Syz147064 	miocnak(q, mp, 0, err);
6005895Syz147064 }
6015895Syz147064 
6025895Syz147064 /*
6035895Syz147064  * DLDIOC_DELETE_VLAN
6045895Syz147064  */
6055895Syz147064 static void
6065895Syz147064 drv_ioc_delete_vlan(dld_ctl_str_t *ctls, mblk_t *mp)
6075895Syz147064 {
6085895Syz147064 	dld_ioc_delete_vlan_t	*didp;
6095895Syz147064 	int			err;
6105895Syz147064 	queue_t			*q = ctls->cs_wq;
6115895Syz147064 
6125895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_delete_vlan_t))) != 0)
6135895Syz147064 		goto done;
6145895Syz147064 
6155895Syz147064 	didp = (dld_ioc_delete_vlan_t *)mp->b_cont->b_rptr;
6165895Syz147064 	err = dls_devnet_destroy_vlan(didp->did_linkid);
6174049Sdh155122 
6185895Syz147064 done:
6195895Syz147064 	if (err == 0)
6205895Syz147064 		miocack(q, mp, 0, 0);
6215895Syz147064 	else
6225895Syz147064 		miocnak(q, mp, 0, err);
6235895Syz147064 }
6245895Syz147064 
6255895Syz147064 /*
6265895Syz147064  * DLDIOC_VLAN_ATTR
6275895Syz147064  */
6285895Syz147064 static void
6295895Syz147064 drv_ioc_vlan_attr(dld_ctl_str_t *ctls, mblk_t *mp)
6305895Syz147064 {
6315895Syz147064 	dld_ioc_vlan_attr_t	*divp;
6325895Syz147064 	dls_dl_handle_t		dlh;
6335895Syz147064 	uint16_t		vid;
6345895Syz147064 	dls_vlan_t		*dvp;
6355895Syz147064 	int			err;
6365895Syz147064 	queue_t			*q = ctls->cs_wq;
6375895Syz147064 
6385895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_vlan_attr_t))) != 0)
6395895Syz147064 		goto failed;
6405895Syz147064 
6415895Syz147064 	divp = (dld_ioc_vlan_attr_t *)mp->b_cont->b_rptr;
6425895Syz147064 
6435895Syz147064 	/*
6445895Syz147064 	 * Hold this link to prevent it from being deleted.
6455895Syz147064 	 */
6465895Syz147064 	err = dls_devnet_hold_tmp(divp->div_vlanid, &dlh);
6474049Sdh155122 	if (err != 0)
6484049Sdh155122 		goto failed;
6494049Sdh155122 
6505895Syz147064 	if ((vid = dls_devnet_vid(dlh)) == VLAN_ID_NONE) {
6515895Syz147064 		dls_devnet_rele_tmp(dlh);
6525895Syz147064 		err = EINVAL;
6535895Syz147064 		goto failed;
6545895Syz147064 	}
6555895Syz147064 
6565895Syz147064 	err = dls_vlan_hold(dls_devnet_mac(dlh), vid, &dvp, B_FALSE, B_FALSE);
6575895Syz147064 	if (err != 0) {
6585895Syz147064 		dls_devnet_rele_tmp(dlh);
6595895Syz147064 		err = EINVAL;
6604049Sdh155122 		goto failed;
6613871Syz147064 	}
6625895Syz147064 
6635895Syz147064 	divp->div_linkid = dls_devnet_linkid(dlh);
6645895Syz147064 	divp->div_implicit = !dls_devnet_is_explicit(dlh);
6655895Syz147064 	divp->div_vid = vid;
6665895Syz147064 	divp->div_force = dvp->dv_force;
6675895Syz147064 
6685895Syz147064 	dls_vlan_rele(dvp);
6695895Syz147064 	dls_devnet_rele_tmp(dlh);
6705895Syz147064 	miocack(q, mp, sizeof (dld_ioc_vlan_attr_t), 0);
6715895Syz147064 	return;
6725895Syz147064 
6734049Sdh155122 failed:
6744049Sdh155122 	miocnak(q, mp, 0, err);
6753448Sdh155122 }
6763448Sdh155122 
6773448Sdh155122 /*
6785895Syz147064  * DLDIOC_RENAME.
6795895Syz147064  *
6805895Syz147064  * This function handles two cases of link renaming. See more in comments above
6815895Syz147064  * dls_datalink_rename().
6825895Syz147064  */
6835895Syz147064 static void
6845895Syz147064 drv_ioc_rename(dld_ctl_str_t *ctls, mblk_t *mp)
6855895Syz147064 {
6865895Syz147064 	dld_ioc_rename_t	*dir;
6875895Syz147064 	mod_hash_key_t		key;
6885895Syz147064 	mod_hash_val_t		val;
6895895Syz147064 	int			err;
6905895Syz147064 	queue_t			*q = ctls->cs_wq;
6915895Syz147064 
6925895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_rename_t))) != 0)
6935895Syz147064 		goto done;
6945895Syz147064 
6955895Syz147064 	dir = (dld_ioc_rename_t *)mp->b_cont->b_rptr;
6965895Syz147064 	if ((err = dls_devnet_rename(dir->dir_linkid1, dir->dir_linkid2,
6975895Syz147064 	    dir->dir_link)) != 0) {
6985895Syz147064 		goto done;
6995895Syz147064 	}
7005895Syz147064 
7015895Syz147064 	if (dir->dir_linkid2 == DATALINK_INVALID_LINKID)
7025895Syz147064 		goto done;
7035895Syz147064 
7045895Syz147064 	/*
7055895Syz147064 	 * if dir_linkid2 is not DATALINK_INVALID_LINKID, it means this
7065895Syz147064 	 * renaming request is to rename a valid physical link (dir_linkid1)
7075895Syz147064 	 * to a "removed" physical link (dir_linkid2, which is removed by DR
7085895Syz147064 	 * or during system shutdown). In this case, the link (specified by
7095895Syz147064 	 * dir_linkid1) would inherit all the configuration of dir_linkid2,
7105895Syz147064 	 * and dir_linkid1 and its configuration would be lost.
7115895Syz147064 	 *
7125895Syz147064 	 * Remove per-link autopush configuration of dir_linkid1 in this case.
7135895Syz147064 	 */
7145895Syz147064 	key = (mod_hash_key_t)(uintptr_t)dir->dir_linkid1;
7155895Syz147064 	rw_enter(&dld_ap_hash_lock, RW_WRITER);
7165895Syz147064 	if (mod_hash_find(dld_ap_hashp, key, &val) != 0) {
7175895Syz147064 		rw_exit(&dld_ap_hash_lock);
7185895Syz147064 		goto done;
7195895Syz147064 	}
7205895Syz147064 
7215895Syz147064 	VERIFY(mod_hash_remove(dld_ap_hashp, key, &val) == 0);
7225895Syz147064 	kmem_free(val, sizeof (dld_ap_t));
7235895Syz147064 	rw_exit(&dld_ap_hash_lock);
7245895Syz147064 
7255895Syz147064 done:
7265895Syz147064 	if (err == 0)
7275895Syz147064 		miocack(q, mp, 0, 0);
7285895Syz147064 	else
7295895Syz147064 		miocnak(q, mp, 0, err);
7305895Syz147064 }
7315895Syz147064 
7325895Syz147064 /*
7335895Syz147064  * DLDIOC_SETAUTOPUSH
7343448Sdh155122  */
7353448Sdh155122 static void
7365895Syz147064 drv_ioc_setap(dld_ctl_str_t *ctls, mblk_t *mp)
7373448Sdh155122 {
7385895Syz147064 	dld_ioc_ap_t	*diap;
7395895Syz147064 	dld_ap_t	*dap;
7405895Syz147064 	int		i, err;
7413448Sdh155122 	queue_t		*q = ctls->cs_wq;
7425895Syz147064 	mod_hash_key_t	key;
7433448Sdh155122 
7445895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_ap_t))) != 0)
7455895Syz147064 		goto failed;
7465895Syz147064 
7475895Syz147064 	diap = (dld_ioc_ap_t *)mp->b_cont->b_rptr;
7485895Syz147064 	if (diap->dia_npush == 0 || diap->dia_npush > MAXAPUSH) {
7493448Sdh155122 		err = EINVAL;
7505895Syz147064 		goto failed;
7513448Sdh155122 	}
7523448Sdh155122 
7535895Syz147064 	/*
7545895Syz147064 	 * Validate that the specified list of modules exist.
7555895Syz147064 	 */
7565895Syz147064 	for (i = 0; i < diap->dia_npush; i++) {
7575895Syz147064 		if (fmodsw_find(diap->dia_aplist[i], FMODSW_LOAD) == NULL) {
7585895Syz147064 			err = EINVAL;
7595895Syz147064 			goto failed;
7605895Syz147064 		}
7613448Sdh155122 	}
7623448Sdh155122 
7635895Syz147064 	key = (mod_hash_key_t)(uintptr_t)diap->dia_linkid;
7645895Syz147064 
7655895Syz147064 	rw_enter(&dld_ap_hash_lock, RW_WRITER);
7665895Syz147064 	if (mod_hash_find(dld_ap_hashp, key, (mod_hash_val_t *)&dap) != 0) {
7675895Syz147064 		dap = kmem_zalloc(sizeof (dld_ap_t), KM_NOSLEEP);
7685895Syz147064 		if (dap == NULL) {
7695895Syz147064 			rw_exit(&dld_ap_hash_lock);
7705895Syz147064 			err = ENOMEM;
7715895Syz147064 			goto failed;
7725895Syz147064 		}
7735895Syz147064 
7745895Syz147064 		dap->da_linkid = diap->dia_linkid;
7755895Syz147064 		err = mod_hash_insert(dld_ap_hashp, key, (mod_hash_val_t)dap);
7765895Syz147064 		ASSERT(err == 0);
7773448Sdh155122 	}
7783448Sdh155122 
7795895Syz147064 	/*
7805895Syz147064 	 * Update the configuration.
7815895Syz147064 	 */
7825895Syz147064 	dap->da_anchor = diap->dia_anchor;
7835895Syz147064 	dap->da_npush = diap->dia_npush;
7845895Syz147064 	for (i = 0; i < diap->dia_npush; i++) {
7855895Syz147064 		(void) strlcpy(dap->da_aplist[i], diap->dia_aplist[i],
7865895Syz147064 		    FMNAMESZ + 1);
7875895Syz147064 	}
7885895Syz147064 	rw_exit(&dld_ap_hash_lock);
7895895Syz147064 
7903448Sdh155122 	miocack(q, mp, 0, 0);
7915895Syz147064 	return;
7925895Syz147064 
7935895Syz147064 failed:
7945895Syz147064 	miocnak(q, mp, 0, err);
7953448Sdh155122 }
7963448Sdh155122 
7973448Sdh155122 /*
7985895Syz147064  * DLDIOC_GETAUTOPUSH
7993448Sdh155122  */
8003448Sdh155122 static void
8015895Syz147064 drv_ioc_getap(dld_ctl_str_t *ctls, mblk_t *mp)
8025895Syz147064 {
8035895Syz147064 	dld_ioc_ap_t	*diap;
8045895Syz147064 	dld_ap_t	*dap;
8055895Syz147064 	int		i, err;
8065895Syz147064 	queue_t		*q = ctls->cs_wq;
8075895Syz147064 
8085895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_ap_t))) != 0)
8095895Syz147064 		goto failed;
8105895Syz147064 
8115895Syz147064 	diap = (dld_ioc_ap_t *)mp->b_cont->b_rptr;
8125895Syz147064 
8135895Syz147064 	rw_enter(&dld_ap_hash_lock, RW_READER);
8145895Syz147064 	if (mod_hash_find(dld_ap_hashp,
8155895Syz147064 	    (mod_hash_key_t)(uintptr_t)diap->dia_linkid,
8165895Syz147064 	    (mod_hash_val_t *)&dap) != 0) {
8175895Syz147064 		err = ENOENT;
8185895Syz147064 		rw_exit(&dld_ap_hash_lock);
8195895Syz147064 		goto failed;
8205895Syz147064 	}
8215895Syz147064 
8225895Syz147064 	/*
8235895Syz147064 	 * Retrieve the configuration.
8245895Syz147064 	 */
8255895Syz147064 	diap->dia_anchor = dap->da_anchor;
8265895Syz147064 	diap->dia_npush = dap->da_npush;
8275895Syz147064 	for (i = 0; i < dap->da_npush; i++) {
8285895Syz147064 		(void) strlcpy(diap->dia_aplist[i], dap->da_aplist[i],
8295895Syz147064 		    FMNAMESZ + 1);
8305895Syz147064 	}
8315895Syz147064 	rw_exit(&dld_ap_hash_lock);
8325895Syz147064 
8335895Syz147064 	miocack(q, mp, sizeof (dld_ioc_ap_t), 0);
8345895Syz147064 	return;
8355895Syz147064 
8365895Syz147064 failed:
8375895Syz147064 	miocnak(q, mp, 0, err);
8385895Syz147064 }
8395895Syz147064 
8405895Syz147064 /*
8415895Syz147064  * DLDIOC_CLRAUTOPUSH
8425895Syz147064  */
8435895Syz147064 static void
8445895Syz147064 drv_ioc_clrap(dld_ctl_str_t *ctls, mblk_t *mp)
8455895Syz147064 {
8465895Syz147064 	dld_ioc_ap_t	*diap;
8475895Syz147064 	mod_hash_val_t	val;
8485895Syz147064 	mod_hash_key_t	key;
8495895Syz147064 	int		err;
8505895Syz147064 	queue_t		*q = ctls->cs_wq;
8515895Syz147064 
8525895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_ap_t))) != 0)
8535895Syz147064 		goto done;
8545895Syz147064 
8555895Syz147064 	diap = (dld_ioc_ap_t *)mp->b_cont->b_rptr;
8565895Syz147064 	key = (mod_hash_key_t)(uintptr_t)diap->dia_linkid;
8575895Syz147064 
8585895Syz147064 	rw_enter(&dld_ap_hash_lock, RW_WRITER);
8595895Syz147064 	if (mod_hash_find(dld_ap_hashp, key, &val) != 0) {
8605895Syz147064 		rw_exit(&dld_ap_hash_lock);
8615895Syz147064 		goto done;
8625895Syz147064 	}
8635895Syz147064 
8645895Syz147064 	VERIFY(mod_hash_remove(dld_ap_hashp, key, &val) == 0);
8655895Syz147064 	kmem_free(val, sizeof (dld_ap_t));
8665895Syz147064 	rw_exit(&dld_ap_hash_lock);
8675895Syz147064 
8685895Syz147064 done:
8695895Syz147064 	if (err == 0)
8705895Syz147064 		miocack(q, mp, 0, 0);
8715895Syz147064 	else
8725895Syz147064 		miocnak(q, mp, 0, err);
8735895Syz147064 }
8745895Syz147064 
8755895Syz147064 /*
8765895Syz147064  * DLDIOC_DOORSERVER
8775895Syz147064  */
8785895Syz147064 static void
8795895Syz147064 drv_ioc_doorserver(dld_ctl_str_t *ctls, mblk_t *mp)
8803448Sdh155122 {
8813448Sdh155122 	queue_t		*q = ctls->cs_wq;
8825895Syz147064 	dld_ioc_door_t	*did;
8833448Sdh155122 	int		err;
8843448Sdh155122 
8855895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_door_t))) != 0)
8865895Syz147064 		goto done;
8875895Syz147064 
8885895Syz147064 	did = (dld_ioc_door_t *)mp->b_cont->b_rptr;
8895895Syz147064 	err = dls_mgmt_door_set(did->did_start_door);
8905895Syz147064 
8915895Syz147064 done:
8925895Syz147064 	if (err == 0)
8935895Syz147064 		miocack(q, mp, 0, 0);
8945895Syz147064 	else
8953448Sdh155122 		miocnak(q, mp, 0, err);
8965895Syz147064 }
8975895Syz147064 
8985895Syz147064 /*
8995895Syz147064  * DLDIOC_SETZID
9005895Syz147064  */
9015895Syz147064 static void
9025895Syz147064 drv_ioc_setzid(dld_ctl_str_t *ctls, mblk_t *mp)
9035895Syz147064 {
9045895Syz147064 	queue_t			*q = ctls->cs_wq;
9055895Syz147064 	dld_ioc_setzid_t	*dis;
9065895Syz147064 	int			err;
9075895Syz147064 
9085895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_setzid_t))) != 0)
9095895Syz147064 		goto done;
9105895Syz147064 
9115895Syz147064 	dis = (dld_ioc_setzid_t *)mp->b_cont->b_rptr;
9125895Syz147064 	err = dls_devnet_setzid(dis->dis_link, dis->dis_zid);
9133448Sdh155122 
9145895Syz147064 done:
9155895Syz147064 	if (err == 0)
9165895Syz147064 		miocack(q, mp, 0, 0);
9175895Syz147064 	else
9183448Sdh155122 		miocnak(q, mp, 0, err);
9195895Syz147064 }
9205895Syz147064 
9215895Syz147064 /*
9225895Syz147064  * DLDIOC_GETZID
9235895Syz147064  */
9245895Syz147064 static void
9255895Syz147064 drv_ioc_getzid(dld_ctl_str_t *ctls, mblk_t *mp)
9265895Syz147064 {
9275895Syz147064 	queue_t			*q = ctls->cs_wq;
9285895Syz147064 	dld_ioc_getzid_t	*dig;
9295895Syz147064 	int			err;
9305895Syz147064 
9315895Syz147064 	if ((err = miocpullup(mp, sizeof (dld_ioc_getzid_t))) != 0)
9325895Syz147064 		goto done;
9335895Syz147064 
9345895Syz147064 	dig = (dld_ioc_getzid_t *)mp->b_cont->b_rptr;
9355895Syz147064 	err = dls_devnet_getzid(dig->dig_linkid, &dig->dig_zid);
9365895Syz147064 
9375895Syz147064 done:
9385895Syz147064 	if (err == 0)
9395895Syz147064 		miocack(q, mp, sizeof (dld_ioc_getzid_t), 0);
9403448Sdh155122 	else
9415895Syz147064 		miocnak(q, mp, 0, err);
9423448Sdh155122 }
943269Sericheng 
944269Sericheng /*
945269Sericheng  * Process an IOCTL message received by the control node.
946269Sericheng  */
947269Sericheng static void
948269Sericheng drv_ioc(dld_ctl_str_t *ctls, mblk_t *mp)
949269Sericheng {
950269Sericheng 	uint_t	cmd;
951269Sericheng 
952269Sericheng 	cmd = ((struct iocblk *)mp->b_rptr)->ioc_cmd;
953269Sericheng 	switch (cmd) {
9545895Syz147064 	case DLDIOC_ATTR:
955269Sericheng 		drv_ioc_attr(ctls, mp);
956269Sericheng 		return;
9575895Syz147064 	case DLDIOC_PHYS_ATTR:
9585895Syz147064 		drv_ioc_phys_attr(ctls, mp);
959269Sericheng 		return;
9605895Syz147064 	case DLDIOC_SECOBJ_SET:
9613147Sxc151355 		drv_ioc_secobj_set(ctls, mp);
9623147Sxc151355 		return;
9635895Syz147064 	case DLDIOC_SECOBJ_GET:
9643147Sxc151355 		drv_ioc_secobj_get(ctls, mp);
9653147Sxc151355 		return;
9665895Syz147064 	case DLDIOC_SECOBJ_UNSET:
9673147Sxc151355 		drv_ioc_secobj_unset(ctls, mp);
9683147Sxc151355 		return;
969*5903Ssowmini 	case DLDIOCSETPROP:
970*5903Ssowmini 		drv_ioc_setprop(ctls, mp);
971*5903Ssowmini 		return;
972*5903Ssowmini 	case DLDIOCGETPROP:
973*5903Ssowmini 		drv_ioc_getprop(ctls, mp);
974*5903Ssowmini 		return;
9755895Syz147064 	case DLDIOC_CREATE_VLAN:
9765895Syz147064 		drv_ioc_create_vlan(ctls, mp);
9775895Syz147064 		return;
9785895Syz147064 	case DLDIOC_DELETE_VLAN:
9795895Syz147064 		drv_ioc_delete_vlan(ctls, mp);
9805895Syz147064 		return;
9815895Syz147064 	case DLDIOC_VLAN_ATTR:
9825895Syz147064 		drv_ioc_vlan_attr(ctls, mp);
9835895Syz147064 		return;
9845895Syz147064 	case DLDIOC_SETAUTOPUSH:
9855895Syz147064 		drv_ioc_setap(ctls, mp);
9865895Syz147064 		return;
9875895Syz147064 	case DLDIOC_GETAUTOPUSH:
9885895Syz147064 		drv_ioc_getap(ctls, mp);
9893448Sdh155122 		return;
9905895Syz147064 	case DLDIOC_CLRAUTOPUSH:
9915895Syz147064 		drv_ioc_clrap(ctls, mp);
9925895Syz147064 		return;
9935895Syz147064 	case DLDIOC_DOORSERVER:
9945895Syz147064 		drv_ioc_doorserver(ctls, mp);
9953448Sdh155122 		return;
9965895Syz147064 	case DLDIOC_SETZID:
9975895Syz147064 		drv_ioc_setzid(ctls, mp);
9985895Syz147064 		return;
9995895Syz147064 	case DLDIOC_GETZID:
10005895Syz147064 		drv_ioc_getzid(ctls, mp);
10015895Syz147064 		return;
10025895Syz147064 	case DLDIOC_RENAME:
10035895Syz147064 		drv_ioc_rename(ctls, mp);
10043448Sdh155122 		return;
1005269Sericheng 	default:
1006269Sericheng 		miocnak(ctls->cs_wq, mp, 0, ENOTSUP);
1007269Sericheng 		return;
1008269Sericheng 	}
10090Sstevel@tonic-gate }
10100Sstevel@tonic-gate 
10110Sstevel@tonic-gate /*
1012269Sericheng  * Write side put routine of the dld control node.
10130Sstevel@tonic-gate  */
10140Sstevel@tonic-gate static void
1015269Sericheng drv_uw_put(queue_t *q, mblk_t *mp)
10160Sstevel@tonic-gate {
1017269Sericheng 	dld_ctl_str_t *ctls = q->q_ptr;
10180Sstevel@tonic-gate 
1019269Sericheng 	switch (mp->b_datap->db_type) {
1020269Sericheng 	case M_IOCTL:
1021269Sericheng 		drv_ioc(ctls, mp);
1022269Sericheng 		break;
1023269Sericheng 	default:
1024269Sericheng 		freemsg(mp);
1025269Sericheng 		break;
1026269Sericheng 	}
1027269Sericheng }
10280Sstevel@tonic-gate 
1029269Sericheng /*
1030269Sericheng  * Write-side service procedure.
1031269Sericheng  */
1032269Sericheng void
1033269Sericheng drv_uw_srv(queue_t *q)
1034269Sericheng {
1035269Sericheng 	mblk_t *mp;
10360Sstevel@tonic-gate 
1037269Sericheng 	while (mp = getq(q))
1038269Sericheng 		drv_uw_put(q, mp);
10390Sstevel@tonic-gate }
10403147Sxc151355 
10413147Sxc151355 /*
10425895Syz147064  * Check for GLDv3 autopush information.  There are three cases:
10435895Syz147064  *
10445895Syz147064  *   1. If devp points to a GLDv3 datalink and it has autopush configuration,
10455895Syz147064  *	fill dlap in with that information and return 0.
10465895Syz147064  *
10475895Syz147064  *   2. If devp points to a GLDv3 datalink but it doesn't have autopush
10485895Syz147064  *	configuration, then replace devp with the physical device (if one
10495895Syz147064  *	exists) and return 1.  This allows stropen() to find the old-school
10505895Syz147064  *	per-driver autopush configuration.  (For softmac, the result is that
10515895Syz147064  *	the softmac dev_t is replaced with the legacy device's dev_t).
10525895Syz147064  *
10535895Syz147064  *   3. If neither of the above apply, don't touch the args and return -1.
10545895Syz147064  */
10555895Syz147064 int
10565895Syz147064 dld_autopush(dev_t *devp, struct dlautopush *dlap)
10575895Syz147064 {
10585895Syz147064 	dld_ap_t	*dap;
10595895Syz147064 	datalink_id_t	linkid;
10605895Syz147064 	dev_t		phydev;
10615895Syz147064 
10625895Syz147064 	if (!GLDV3_DRV(getmajor(*devp)))
10635895Syz147064 		return (-1);
10645895Syz147064 
10655895Syz147064 	/*
10665895Syz147064 	 * Find the linkid by the link's dev_t.
10675895Syz147064 	 */
10685895Syz147064 	if (dls_devnet_dev2linkid(*devp, &linkid) != 0)
10695895Syz147064 		return (-1);
10705895Syz147064 
10715895Syz147064 	/*
10725895Syz147064 	 * Find the autopush configuration associated with the linkid.
10735895Syz147064 	 */
10745895Syz147064 	rw_enter(&dld_ap_hash_lock, RW_READER);
10755895Syz147064 	if (mod_hash_find(dld_ap_hashp, (mod_hash_key_t)(uintptr_t)linkid,
10765895Syz147064 	    (mod_hash_val_t *)&dap) == 0) {
10775895Syz147064 		*dlap = dap->da_ap;
10785895Syz147064 		rw_exit(&dld_ap_hash_lock);
10795895Syz147064 		return (0);
10805895Syz147064 	}
10815895Syz147064 	rw_exit(&dld_ap_hash_lock);
10825895Syz147064 
10835895Syz147064 	if (dls_devnet_phydev(linkid, &phydev) != 0)
10845895Syz147064 		return (-1);
10855895Syz147064 
10865895Syz147064 	*devp = phydev;
10875895Syz147064 	return (1);
10885895Syz147064 }
10895895Syz147064 
10905895Syz147064 /*
10913147Sxc151355  * Secure objects implementation
10923147Sxc151355  */
10933147Sxc151355 
10943147Sxc151355 /* ARGSUSED */
10953147Sxc151355 static int
10963147Sxc151355 drv_secobj_ctor(void *buf, void *arg, int kmflag)
10973147Sxc151355 {
10983147Sxc151355 	bzero(buf, sizeof (dld_secobj_t));
10993147Sxc151355 	return (0);
11003147Sxc151355 }
11013147Sxc151355 
11023147Sxc151355 static void
11033147Sxc151355 drv_secobj_init(void)
11043147Sxc151355 {
11053147Sxc151355 	rw_init(&drv_secobj_lock, NULL, RW_DEFAULT, NULL);
11063147Sxc151355 	drv_secobj_cachep = kmem_cache_create("drv_secobj_cache",
11073147Sxc151355 	    sizeof (dld_secobj_t), 0, drv_secobj_ctor, NULL,
11083147Sxc151355 	    NULL, NULL, NULL, 0);
11093147Sxc151355 	drv_secobj_hash = mod_hash_create_extended("drv_secobj_hash",
11103147Sxc151355 	    SECOBJ_WEP_HASHSZ, mod_hash_null_keydtor, mod_hash_null_valdtor,
11113147Sxc151355 	    mod_hash_bystr, NULL, mod_hash_strkey_cmp, KM_SLEEP);
11123147Sxc151355 }
11133147Sxc151355 
11143147Sxc151355 static void
11153147Sxc151355 drv_secobj_fini(void)
11163147Sxc151355 {
11173147Sxc151355 	mod_hash_destroy_hash(drv_secobj_hash);
11183147Sxc151355 	kmem_cache_destroy(drv_secobj_cachep);
11193147Sxc151355 	rw_destroy(&drv_secobj_lock);
11203147Sxc151355 }
11213147Sxc151355 
11223147Sxc151355 static void
11233147Sxc151355 drv_ioc_secobj_set(dld_ctl_str_t *ctls, mblk_t *mp)
11243147Sxc151355 {
11253147Sxc151355 	dld_ioc_secobj_set_t	*ssp;
11263147Sxc151355 	dld_secobj_t		*sobjp, *objp;
11273147Sxc151355 	int			err = EINVAL;
11283147Sxc151355 	queue_t			*q = ctls->cs_wq;
11293147Sxc151355 
11303147Sxc151355 	if ((err = miocpullup(mp, sizeof (dld_ioc_secobj_set_t))) != 0)
11313147Sxc151355 		goto failed;
11323147Sxc151355 
11333147Sxc151355 	ssp = (dld_ioc_secobj_set_t *)mp->b_cont->b_rptr;
11343147Sxc151355 	sobjp = &ssp->ss_obj;
11353147Sxc151355 
11364126Szf162725 	if (sobjp->so_class != DLD_SECOBJ_CLASS_WEP &&
11374126Szf162725 	    sobjp->so_class != DLD_SECOBJ_CLASS_WPA)
11383147Sxc151355 		goto failed;
11393147Sxc151355 
11403147Sxc151355 	if (sobjp->so_name[DLD_SECOBJ_NAME_MAX - 1] != '\0' ||
11413147Sxc151355 	    sobjp->so_len > DLD_SECOBJ_VAL_MAX)
11423147Sxc151355 		goto failed;
11433147Sxc151355 
11443147Sxc151355 	rw_enter(&drv_secobj_lock, RW_WRITER);
11453147Sxc151355 	err = mod_hash_find(drv_secobj_hash, (mod_hash_key_t)sobjp->so_name,
11463147Sxc151355 	    (mod_hash_val_t *)&objp);
11473147Sxc151355 	if (err == 0) {
11483147Sxc151355 		if ((ssp->ss_flags & DLD_SECOBJ_OPT_CREATE) != 0) {
11493147Sxc151355 			err = EEXIST;
11503147Sxc151355 			rw_exit(&drv_secobj_lock);
11513147Sxc151355 			goto failed;
11523147Sxc151355 		}
11533147Sxc151355 	} else {
11543147Sxc151355 		ASSERT(err == MH_ERR_NOTFOUND);
11553147Sxc151355 		if ((ssp->ss_flags & DLD_SECOBJ_OPT_CREATE) == 0) {
11563147Sxc151355 			err = ENOENT;
11573147Sxc151355 			rw_exit(&drv_secobj_lock);
11583147Sxc151355 			goto failed;
11593147Sxc151355 		}
11603147Sxc151355 		objp = kmem_cache_alloc(drv_secobj_cachep, KM_SLEEP);
11613147Sxc151355 		(void) strlcpy(objp->so_name, sobjp->so_name,
11623147Sxc151355 		    DLD_SECOBJ_NAME_MAX);
11633147Sxc151355 
11643147Sxc151355 		err = mod_hash_insert(drv_secobj_hash,
11653147Sxc151355 		    (mod_hash_key_t)objp->so_name, (mod_hash_val_t)objp);
11663147Sxc151355 		ASSERT(err == 0);
11673147Sxc151355 	}
11683147Sxc151355 	bcopy(sobjp->so_val, objp->so_val, sobjp->so_len);
11693147Sxc151355 	objp->so_len = sobjp->so_len;
11703147Sxc151355 	objp->so_class = sobjp->so_class;
11713147Sxc151355 	rw_exit(&drv_secobj_lock);
11723147Sxc151355 	miocack(q, mp, 0, 0);
11733147Sxc151355 	return;
11743147Sxc151355 
11753147Sxc151355 failed:
11763147Sxc151355 	ASSERT(err != 0);
11773147Sxc151355 	miocnak(q, mp, 0, err);
11783147Sxc151355 }
11793147Sxc151355 
11803147Sxc151355 typedef struct dld_secobj_state {
11813147Sxc151355 	uint_t		ss_free;
11823147Sxc151355 	uint_t		ss_count;
11833147Sxc151355 	int		ss_rc;
11843147Sxc151355 	dld_secobj_t	*ss_objp;
11853147Sxc151355 } dld_secobj_state_t;
11863147Sxc151355 
11873147Sxc151355 /* ARGSUSED */
11883147Sxc151355 static uint_t
11893147Sxc151355 drv_secobj_walker(mod_hash_key_t key, mod_hash_val_t *val, void *arg)
11903147Sxc151355 {
11913147Sxc151355 	dld_secobj_state_t	*statep = arg;
11923147Sxc151355 	dld_secobj_t		*sobjp = (dld_secobj_t *)val;
11933147Sxc151355 
11943147Sxc151355 	if (statep->ss_free < sizeof (dld_secobj_t)) {
11953147Sxc151355 		statep->ss_rc = ENOSPC;
11963147Sxc151355 		return (MH_WALK_TERMINATE);
11973147Sxc151355 	}
11983147Sxc151355 	bcopy(sobjp, statep->ss_objp, sizeof (dld_secobj_t));
11993147Sxc151355 	statep->ss_objp++;
12003147Sxc151355 	statep->ss_free -= sizeof (dld_secobj_t);
12013147Sxc151355 	statep->ss_count++;
12023147Sxc151355 	return (MH_WALK_CONTINUE);
12033147Sxc151355 }
12043147Sxc151355 
12053147Sxc151355 static void
12063147Sxc151355 drv_ioc_secobj_get(dld_ctl_str_t *ctls, mblk_t *mp)
12073147Sxc151355 {
12083147Sxc151355 	dld_ioc_secobj_get_t	*sgp;
12093147Sxc151355 	dld_secobj_t		*sobjp, *objp;
12103147Sxc151355 	int			err = EINVAL;
12113147Sxc151355 	uint_t			extra = 0;
12123147Sxc151355 	queue_t			*q = ctls->cs_wq;
12133147Sxc151355 	mblk_t			*bp;
12143147Sxc151355 
12153147Sxc151355 	if ((err = miocpullup(mp, sizeof (dld_ioc_secobj_get_t))) != 0)
12163147Sxc151355 		goto failed;
12173147Sxc151355 
12183147Sxc151355 	if ((bp = msgpullup(mp->b_cont, -1)) == NULL)
12193147Sxc151355 		goto failed;
12203147Sxc151355 
12213147Sxc151355 	freemsg(mp->b_cont);
12223147Sxc151355 	mp->b_cont = bp;
12233147Sxc151355 	sgp = (dld_ioc_secobj_get_t *)bp->b_rptr;
12243147Sxc151355 	sobjp = &sgp->sg_obj;
12253147Sxc151355 
12263147Sxc151355 	if (sobjp->so_name[DLD_SECOBJ_NAME_MAX - 1] != '\0')
12273147Sxc151355 		goto failed;
12283147Sxc151355 
12293147Sxc151355 	rw_enter(&drv_secobj_lock, RW_READER);
12303147Sxc151355 	if (sobjp->so_name[0] != '\0') {
12313147Sxc151355 		err = mod_hash_find(drv_secobj_hash,
12323147Sxc151355 		    (mod_hash_key_t)sobjp->so_name, (mod_hash_val_t *)&objp);
12333147Sxc151355 		if (err != 0) {
12343147Sxc151355 			ASSERT(err == MH_ERR_NOTFOUND);
12353147Sxc151355 			err = ENOENT;
12363147Sxc151355 			rw_exit(&drv_secobj_lock);
12373147Sxc151355 			goto failed;
12383147Sxc151355 		}
12393147Sxc151355 		bcopy(objp->so_val, sobjp->so_val, objp->so_len);
12403147Sxc151355 		sobjp->so_len = objp->so_len;
12413147Sxc151355 		sobjp->so_class = objp->so_class;
12423147Sxc151355 		sgp->sg_count = 1;
12433147Sxc151355 	} else {
12443147Sxc151355 		dld_secobj_state_t	state;
12453147Sxc151355 
12463147Sxc151355 		state.ss_free = MBLKL(bp) - sizeof (dld_ioc_secobj_get_t);
12473147Sxc151355 		state.ss_count = 0;
12483147Sxc151355 		state.ss_rc = 0;
12493147Sxc151355 		state.ss_objp = (dld_secobj_t *)(sgp + 1);
12503147Sxc151355 		mod_hash_walk(drv_secobj_hash, drv_secobj_walker, &state);
12513147Sxc151355 		if (state.ss_rc != 0) {
12523147Sxc151355 			err = state.ss_rc;
12533147Sxc151355 			rw_exit(&drv_secobj_lock);
12543147Sxc151355 			goto failed;
12553147Sxc151355 		}
12563147Sxc151355 		sgp->sg_count = state.ss_count;
12573147Sxc151355 		extra = state.ss_count * sizeof (dld_secobj_t);
12583147Sxc151355 	}
12593147Sxc151355 	rw_exit(&drv_secobj_lock);
12603147Sxc151355 	miocack(q, mp, sizeof (dld_ioc_secobj_get_t) + extra, 0);
12613147Sxc151355 	return;
12623147Sxc151355 
12633147Sxc151355 failed:
12643147Sxc151355 	ASSERT(err != 0);
12653147Sxc151355 	miocnak(q, mp, 0, err);
12663147Sxc151355 
12673147Sxc151355 }
12683147Sxc151355 
12693147Sxc151355 static void
12703147Sxc151355 drv_ioc_secobj_unset(dld_ctl_str_t *ctls, mblk_t *mp)
12713147Sxc151355 {
12723147Sxc151355 	dld_ioc_secobj_unset_t	*sup;
12733147Sxc151355 	dld_secobj_t		*objp;
12743147Sxc151355 	mod_hash_val_t		val;
12753147Sxc151355 	int			err = EINVAL;
12763147Sxc151355 	queue_t			*q = ctls->cs_wq;
12773147Sxc151355 
12783147Sxc151355 	if ((err = miocpullup(mp, sizeof (dld_ioc_secobj_unset_t))) != 0)
12793147Sxc151355 		goto failed;
12803147Sxc151355 
12813147Sxc151355 	sup = (dld_ioc_secobj_unset_t *)mp->b_cont->b_rptr;
12823147Sxc151355 	if (sup->su_name[DLD_SECOBJ_NAME_MAX - 1] != '\0')
12833147Sxc151355 		goto failed;
12843147Sxc151355 
12853147Sxc151355 	rw_enter(&drv_secobj_lock, RW_WRITER);
12863147Sxc151355 	err = mod_hash_find(drv_secobj_hash, (mod_hash_key_t)sup->su_name,
12873147Sxc151355 	    (mod_hash_val_t *)&objp);
12883147Sxc151355 	if (err != 0) {
12893147Sxc151355 		ASSERT(err == MH_ERR_NOTFOUND);
12903147Sxc151355 		err = ENOENT;
12913147Sxc151355 		rw_exit(&drv_secobj_lock);
12923147Sxc151355 		goto failed;
12933147Sxc151355 	}
12943147Sxc151355 	err = mod_hash_remove(drv_secobj_hash, (mod_hash_key_t)sup->su_name,
12953147Sxc151355 	    (mod_hash_val_t *)&val);
12963147Sxc151355 	ASSERT(err == 0);
12973147Sxc151355 	ASSERT(objp == (dld_secobj_t *)val);
12983147Sxc151355 
12993147Sxc151355 	kmem_cache_free(drv_secobj_cachep, objp);
13003147Sxc151355 	rw_exit(&drv_secobj_lock);
13013147Sxc151355 	miocack(q, mp, 0, 0);
13023147Sxc151355 	return;
13033147Sxc151355 
13043147Sxc151355 failed:
13053147Sxc151355 	ASSERT(err != 0);
13063147Sxc151355 	miocnak(q, mp, 0, err);
13073147Sxc151355 }
1308