xref: /titanic_53/usr/src/uts/common/io/sad.c (revision 1110f3841973f8fb3cb09627c9330e198c6df3f5)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1110f384Sedp  * Common Development and Distribution License (the "License").
6*1110f384Sedp  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*1110f384Sedp  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
297c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * STREAMS Administrative Driver
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * Currently only handles autopush and module name verification.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
397c478bd9Sstevel@tonic-gate #include <sys/param.h>
407c478bd9Sstevel@tonic-gate #include <sys/errno.h>
417c478bd9Sstevel@tonic-gate #include <sys/stream.h>
427c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
437c478bd9Sstevel@tonic-gate #include <sys/strsubr.h>
447c478bd9Sstevel@tonic-gate #include <sys/strsun.h>
457c478bd9Sstevel@tonic-gate #include <sys/conf.h>
467c478bd9Sstevel@tonic-gate #include <sys/sad.h>
477c478bd9Sstevel@tonic-gate #include <sys/cred.h>
487c478bd9Sstevel@tonic-gate #include <sys/debug.h>
497c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
507c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
517c478bd9Sstevel@tonic-gate #include <sys/stat.h>
527c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
537c478bd9Sstevel@tonic-gate #include <sys/systm.h>
547c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
557c478bd9Sstevel@tonic-gate #include <sys/priv_names.h>
56*1110f384Sedp #include <sys/sysmacros.h>
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate static int sadopen(queue_t *, dev_t *, int, int, cred_t *);
597c478bd9Sstevel@tonic-gate static int sadclose(queue_t *, int, cred_t *);
607c478bd9Sstevel@tonic-gate static int sadwput(queue_t *qp, mblk_t *mp);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate static int sad_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
637c478bd9Sstevel@tonic-gate static int sad_attach(dev_info_t *, ddi_attach_cmd_t);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate static void apush_ioctl(), apush_iocdata();
667c478bd9Sstevel@tonic-gate static void vml_ioctl(), vml_iocdata();
677c478bd9Sstevel@tonic-gate static int valid_major(major_t);
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static dev_info_t *sad_dip;		/* private copy of devinfo pointer */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate static struct module_info sad_minfo = {
727c478bd9Sstevel@tonic-gate 	0x7361, "sad", 0, INFPSZ, 0, 0
737c478bd9Sstevel@tonic-gate };
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate static struct qinit sad_rinit = {
767c478bd9Sstevel@tonic-gate 	NULL, NULL, sadopen, sadclose, NULL, &sad_minfo, NULL
777c478bd9Sstevel@tonic-gate };
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static struct qinit sad_winit = {
807c478bd9Sstevel@tonic-gate 	sadwput, NULL, NULL, NULL, NULL, &sad_minfo, NULL
817c478bd9Sstevel@tonic-gate };
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate struct streamtab sadinfo = {
847c478bd9Sstevel@tonic-gate 	&sad_rinit, &sad_winit, NULL, NULL
857c478bd9Sstevel@tonic-gate };
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate DDI_DEFINE_STREAM_OPS(sad_ops, nulldev, nulldev, sad_attach,
88*1110f384Sedp     nodev, nodev, sad_info, D_MTPERQ | D_MP, &sadinfo);
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * Module linkage information for the kernel.
927c478bd9Sstevel@tonic-gate  */
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
957c478bd9Sstevel@tonic-gate 	&mod_driverops, /* Type of module.  This one is a pseudo driver */
967c478bd9Sstevel@tonic-gate 	"STREAMS Administrative Driver 'sad' %I%",
977c478bd9Sstevel@tonic-gate 	&sad_ops,	/* driver ops */
987c478bd9Sstevel@tonic-gate };
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
1017c478bd9Sstevel@tonic-gate 	MODREV_1, &modldrv, NULL
1027c478bd9Sstevel@tonic-gate };
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate int
1057c478bd9Sstevel@tonic-gate _init(void)
1067c478bd9Sstevel@tonic-gate {
1077c478bd9Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1087c478bd9Sstevel@tonic-gate }
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate int
1117c478bd9Sstevel@tonic-gate _fini(void)
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate int
1177c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1187c478bd9Sstevel@tonic-gate {
1197c478bd9Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1207c478bd9Sstevel@tonic-gate }
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate static int
1237c478bd9Sstevel@tonic-gate sad_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
1247c478bd9Sstevel@tonic-gate {
125*1110f384Sedp 	int instance = ddi_get_instance(devi);
126*1110f384Sedp 
1277c478bd9Sstevel@tonic-gate 	if (cmd != DDI_ATTACH)
1287c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
1297c478bd9Sstevel@tonic-gate 
130*1110f384Sedp 	ASSERT(instance == 0);
131*1110f384Sedp 	if (instance != 0)
132*1110f384Sedp 		return (DDI_FAILURE);
133*1110f384Sedp 
1347c478bd9Sstevel@tonic-gate 	if (ddi_create_minor_node(devi, "user", S_IFCHR,
1357c478bd9Sstevel@tonic-gate 	    0, DDI_PSEUDO, NULL) == DDI_FAILURE) {
1367c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
1377c478bd9Sstevel@tonic-gate 	}
1387c478bd9Sstevel@tonic-gate 	if (ddi_create_priv_minor_node(devi, "admin", S_IFCHR,
1397c478bd9Sstevel@tonic-gate 	    1, DDI_PSEUDO, PRIVONLY_DEV, PRIV_SYS_CONFIG,
1407c478bd9Sstevel@tonic-gate 	    PRIV_SYS_CONFIG, 0666) == DDI_FAILURE) {
1417c478bd9Sstevel@tonic-gate 		ddi_remove_minor_node(devi, NULL);
1427c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
1437c478bd9Sstevel@tonic-gate 	}
1447c478bd9Sstevel@tonic-gate 	sad_dip = devi;
1457c478bd9Sstevel@tonic-gate 	return (DDI_SUCCESS);
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate /* ARGSUSED */
1497c478bd9Sstevel@tonic-gate static int
1507c478bd9Sstevel@tonic-gate sad_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
1517c478bd9Sstevel@tonic-gate {
1527c478bd9Sstevel@tonic-gate 	int error;
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	switch (infocmd) {
1557c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
1567c478bd9Sstevel@tonic-gate 		if (sad_dip == NULL) {
1577c478bd9Sstevel@tonic-gate 			error = DDI_FAILURE;
1587c478bd9Sstevel@tonic-gate 		} else {
1597c478bd9Sstevel@tonic-gate 			*result = sad_dip;
1607c478bd9Sstevel@tonic-gate 			error = DDI_SUCCESS;
1617c478bd9Sstevel@tonic-gate 		}
1627c478bd9Sstevel@tonic-gate 		break;
1637c478bd9Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
1647c478bd9Sstevel@tonic-gate 		*result = (void *)0;
1657c478bd9Sstevel@tonic-gate 		error = DDI_SUCCESS;
1667c478bd9Sstevel@tonic-gate 		break;
1677c478bd9Sstevel@tonic-gate 	default:
1687c478bd9Sstevel@tonic-gate 		error = DDI_FAILURE;
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 	return (error);
1717c478bd9Sstevel@tonic-gate }
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate /*
1757c478bd9Sstevel@tonic-gate  * sadopen() -
1767c478bd9Sstevel@tonic-gate  * Allocate a sad device.  Only one
1777c478bd9Sstevel@tonic-gate  * open at a time allowed per device.
1787c478bd9Sstevel@tonic-gate  */
1797c478bd9Sstevel@tonic-gate /* ARGSUSED */
1807c478bd9Sstevel@tonic-gate static int
1817c478bd9Sstevel@tonic-gate sadopen(
1827c478bd9Sstevel@tonic-gate 	queue_t *qp,	/* pointer to read queue */
1837c478bd9Sstevel@tonic-gate 	dev_t *devp,	/* major/minor device of stream */
1847c478bd9Sstevel@tonic-gate 	int flag,	/* file open flags */
1857c478bd9Sstevel@tonic-gate 	int sflag,	/* stream open flags */
1867c478bd9Sstevel@tonic-gate 	cred_t *credp)	/* user credentials */
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate 	int i;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	if (sflag)		/* no longer called from clone driver */
1917c478bd9Sstevel@tonic-gate 		return (EINVAL);
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	/*
1947c478bd9Sstevel@tonic-gate 	 * Both USRMIN and ADMMIN are clone interfaces.
1957c478bd9Sstevel@tonic-gate 	 */
1967c478bd9Sstevel@tonic-gate 	for (i = 0; i < sadcnt; i++)
1977c478bd9Sstevel@tonic-gate 		if (saddev[i].sa_qp == NULL)
1987c478bd9Sstevel@tonic-gate 			break;
1997c478bd9Sstevel@tonic-gate 	if (i >= sadcnt)		/* no such device */
2007c478bd9Sstevel@tonic-gate 		return (ENXIO);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	switch (getminor(*devp)) {
2037c478bd9Sstevel@tonic-gate 	case USRMIN:			/* mere mortal */
2047c478bd9Sstevel@tonic-gate 		saddev[i].sa_flags = 0;
2057c478bd9Sstevel@tonic-gate 		break;
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate 	case ADMMIN:			/* privileged user */
2087c478bd9Sstevel@tonic-gate 		saddev[i].sa_flags = SADPRIV;
2097c478bd9Sstevel@tonic-gate 		break;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	default:
2127c478bd9Sstevel@tonic-gate 		return (EINVAL);
2137c478bd9Sstevel@tonic-gate 	}
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	saddev[i].sa_qp = qp;
2167c478bd9Sstevel@tonic-gate 	qp->q_ptr = (caddr_t)&saddev[i];
2177c478bd9Sstevel@tonic-gate 	WR(qp)->q_ptr = (caddr_t)&saddev[i];
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	/*
2207c478bd9Sstevel@tonic-gate 	 * NOTE: should the ADMMIN or USRMIN minors change
2217c478bd9Sstevel@tonic-gate 	 * then so should the offset of 2 below
2227c478bd9Sstevel@tonic-gate 	 * Both USRMIN and ADMMIN are clone interfaces and
2237c478bd9Sstevel@tonic-gate 	 * therefore their minor numbers (0 and 1) are reserved.
2247c478bd9Sstevel@tonic-gate 	 */
2257c478bd9Sstevel@tonic-gate 	*devp = makedevice(getemajor(*devp), i + 2);
2267c478bd9Sstevel@tonic-gate 	qprocson(qp);
2277c478bd9Sstevel@tonic-gate 	return (0);
2287c478bd9Sstevel@tonic-gate }
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate /*
2317c478bd9Sstevel@tonic-gate  * sadclose() -
2327c478bd9Sstevel@tonic-gate  * Clean up the data structures.
2337c478bd9Sstevel@tonic-gate  */
2347c478bd9Sstevel@tonic-gate /* ARGSUSED */
2357c478bd9Sstevel@tonic-gate static int
2367c478bd9Sstevel@tonic-gate sadclose(
2377c478bd9Sstevel@tonic-gate 	queue_t *qp,	/* pointer to read queue */
2387c478bd9Sstevel@tonic-gate 	int flag,	/* file open flags */
2397c478bd9Sstevel@tonic-gate 	cred_t *credp)	/* user credentials */
2407c478bd9Sstevel@tonic-gate {
2417c478bd9Sstevel@tonic-gate 	struct saddev *sadp;
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate 	qprocsoff(qp);
2447c478bd9Sstevel@tonic-gate 	sadp = (struct saddev *)qp->q_ptr;
2457c478bd9Sstevel@tonic-gate 	sadp->sa_qp = NULL;
2467c478bd9Sstevel@tonic-gate 	sadp->sa_addr = NULL;
2477c478bd9Sstevel@tonic-gate 	qp->q_ptr = NULL;
2487c478bd9Sstevel@tonic-gate 	WR(qp)->q_ptr = NULL;
2497c478bd9Sstevel@tonic-gate 	return (0);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * sadwput() -
2547c478bd9Sstevel@tonic-gate  * Write side put procedure.
2557c478bd9Sstevel@tonic-gate  */
2567c478bd9Sstevel@tonic-gate static int
2577c478bd9Sstevel@tonic-gate sadwput(
2587c478bd9Sstevel@tonic-gate 	queue_t *qp,	/* pointer to write queue */
2597c478bd9Sstevel@tonic-gate 	mblk_t *mp)	/* message pointer */
2607c478bd9Sstevel@tonic-gate {
2617c478bd9Sstevel@tonic-gate 	struct iocblk *iocp;
2627c478bd9Sstevel@tonic-gate 
2637c478bd9Sstevel@tonic-gate 	switch (mp->b_datap->db_type) {
2647c478bd9Sstevel@tonic-gate 	case M_FLUSH:
2657c478bd9Sstevel@tonic-gate 		if (*mp->b_rptr & FLUSHR) {
2667c478bd9Sstevel@tonic-gate 			*mp->b_rptr &= ~FLUSHW;
2677c478bd9Sstevel@tonic-gate 			qreply(qp, mp);
2687c478bd9Sstevel@tonic-gate 		} else
2697c478bd9Sstevel@tonic-gate 			freemsg(mp);
2707c478bd9Sstevel@tonic-gate 		break;
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	case M_IOCTL:
2737c478bd9Sstevel@tonic-gate 		iocp = (struct iocblk *)mp->b_rptr;
2747c478bd9Sstevel@tonic-gate 		switch (SAD_CMD(iocp->ioc_cmd)) {
2757c478bd9Sstevel@tonic-gate 		case SAD_CMD(SAD_SAP):
2767c478bd9Sstevel@tonic-gate 		case SAD_CMD(SAD_GAP):
2777c478bd9Sstevel@tonic-gate 			apush_ioctl(qp, mp);
2787c478bd9Sstevel@tonic-gate 			break;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 		case SAD_VML:
2817c478bd9Sstevel@tonic-gate 			vml_ioctl(qp, mp);
2827c478bd9Sstevel@tonic-gate 			break;
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 		default:
2857c478bd9Sstevel@tonic-gate 			miocnak(qp, mp, 0, EINVAL);
2867c478bd9Sstevel@tonic-gate 			break;
2877c478bd9Sstevel@tonic-gate 		}
2887c478bd9Sstevel@tonic-gate 		break;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	case M_IOCDATA:
2917c478bd9Sstevel@tonic-gate 		iocp = (struct iocblk *)mp->b_rptr;
2927c478bd9Sstevel@tonic-gate 		switch (SAD_CMD(iocp->ioc_cmd)) {
2937c478bd9Sstevel@tonic-gate 		case SAD_CMD(SAD_SAP):
2947c478bd9Sstevel@tonic-gate 		case SAD_CMD(SAD_GAP):
2957c478bd9Sstevel@tonic-gate 			apush_iocdata(qp, mp);
2967c478bd9Sstevel@tonic-gate 			break;
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 		case SAD_VML:
2997c478bd9Sstevel@tonic-gate 			vml_iocdata(qp, mp);
3007c478bd9Sstevel@tonic-gate 			break;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 		default:
3037c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
3047c478bd9Sstevel@tonic-gate 			    "sadwput: invalid ioc_cmd in case M_IOCDATA: %d",
3057c478bd9Sstevel@tonic-gate 			    iocp->ioc_cmd);
3067c478bd9Sstevel@tonic-gate 			freemsg(mp);
3077c478bd9Sstevel@tonic-gate 			break;
3087c478bd9Sstevel@tonic-gate 		}
3097c478bd9Sstevel@tonic-gate 		break;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	default:
3127c478bd9Sstevel@tonic-gate 		freemsg(mp);
3137c478bd9Sstevel@tonic-gate 		break;
3147c478bd9Sstevel@tonic-gate 	} /* switch (db_type) */
3157c478bd9Sstevel@tonic-gate 	return (0);
3167c478bd9Sstevel@tonic-gate }
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate /*
3197c478bd9Sstevel@tonic-gate  * apush_ioctl() -
3207c478bd9Sstevel@tonic-gate  * Handle the M_IOCTL messages associated with
3217c478bd9Sstevel@tonic-gate  * the autopush feature.
3227c478bd9Sstevel@tonic-gate  */
3237c478bd9Sstevel@tonic-gate static void
3247c478bd9Sstevel@tonic-gate apush_ioctl(
3257c478bd9Sstevel@tonic-gate 	queue_t *qp,	/* pointer to write queue */
3267c478bd9Sstevel@tonic-gate 	mblk_t *mp)	/* message pointer */
3277c478bd9Sstevel@tonic-gate {
3287c478bd9Sstevel@tonic-gate 	struct iocblk	*iocp;
3297c478bd9Sstevel@tonic-gate 	struct saddev	*sadp;
3307c478bd9Sstevel@tonic-gate 	uint_t		size;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	iocp = (struct iocblk *)mp->b_rptr;
3337c478bd9Sstevel@tonic-gate 	if (iocp->ioc_count != TRANSPARENT) {
3347c478bd9Sstevel@tonic-gate 		miocnak(qp, mp, 0, EINVAL);
3357c478bd9Sstevel@tonic-gate 		return;
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 	if (SAD_VER(iocp->ioc_cmd) > AP_VERSION) {
3387c478bd9Sstevel@tonic-gate 		miocnak(qp, mp, 0, EINVAL);
3397c478bd9Sstevel@tonic-gate 		return;
3407c478bd9Sstevel@tonic-gate 	}
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	sadp = (struct saddev *)qp->q_ptr;
3437c478bd9Sstevel@tonic-gate 	switch (SAD_CMD(iocp->ioc_cmd)) {
3447c478bd9Sstevel@tonic-gate 	case SAD_CMD(SAD_SAP):
3457c478bd9Sstevel@tonic-gate 		if (!(sadp->sa_flags & SADPRIV)) {
3467c478bd9Sstevel@tonic-gate 			miocnak(qp, mp, 0, EPERM);
3477c478bd9Sstevel@tonic-gate 			break;
3487c478bd9Sstevel@tonic-gate 		}
3497c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	case SAD_CMD(SAD_GAP):
3527c478bd9Sstevel@tonic-gate 		sadp->sa_addr = (caddr_t)*(uintptr_t *)mp->b_cont->b_rptr;
3537c478bd9Sstevel@tonic-gate 		if (SAD_VER(iocp->ioc_cmd) == 1)
3547c478bd9Sstevel@tonic-gate 			size = STRAPUSH_V1_LEN;
3557c478bd9Sstevel@tonic-gate 		else
3567c478bd9Sstevel@tonic-gate 			size = STRAPUSH_V0_LEN;
3577c478bd9Sstevel@tonic-gate 		mcopyin(mp, (void *)GETSTRUCT, size, NULL);
3587c478bd9Sstevel@tonic-gate 		qreply(qp, mp);
3597c478bd9Sstevel@tonic-gate 		break;
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate 	default:
3627c478bd9Sstevel@tonic-gate 		ASSERT(0);
3637c478bd9Sstevel@tonic-gate 		miocnak(qp, mp, 0, EINVAL);
3647c478bd9Sstevel@tonic-gate 		break;
3657c478bd9Sstevel@tonic-gate 	} /* switch (ioc_cmd) */
3667c478bd9Sstevel@tonic-gate }
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate /*
3697c478bd9Sstevel@tonic-gate  * apush_iocdata() -
3707c478bd9Sstevel@tonic-gate  * Handle the M_IOCDATA messages associated with
3717c478bd9Sstevel@tonic-gate  * the autopush feature.
3727c478bd9Sstevel@tonic-gate  */
3737c478bd9Sstevel@tonic-gate static void
3747c478bd9Sstevel@tonic-gate apush_iocdata(
3757c478bd9Sstevel@tonic-gate 	queue_t *qp,	/* pointer to write queue */
3767c478bd9Sstevel@tonic-gate 	mblk_t *mp)	/* message pointer */
3777c478bd9Sstevel@tonic-gate {
3787c478bd9Sstevel@tonic-gate 	int i, ret;
3797c478bd9Sstevel@tonic-gate 	struct copyresp *csp;
3807c478bd9Sstevel@tonic-gate 	struct strapush *sap;
381*1110f384Sedp 	struct autopush *ap, *ap_tmp;
3827c478bd9Sstevel@tonic-gate 	struct saddev *sadp;
3837c478bd9Sstevel@tonic-gate 	uint_t size;
384*1110f384Sedp 	dev_t dev;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	csp = (struct copyresp *)mp->b_rptr;
3877c478bd9Sstevel@tonic-gate 	if (csp->cp_rval) {	/* if there was an error */
3887c478bd9Sstevel@tonic-gate 		freemsg(mp);
3897c478bd9Sstevel@tonic-gate 		return;
3907c478bd9Sstevel@tonic-gate 	}
391*1110f384Sedp 	if (mp->b_cont) {
3927c478bd9Sstevel@tonic-gate 		/*
393*1110f384Sedp 		 * sap needed only if mp->b_cont is set.  first figure out
394*1110f384Sedp 		 * the size of the sap structure and then prepare caller
395*1110f384Sedp 		 * supplied data for access with miocpullup().
3967c478bd9Sstevel@tonic-gate 		 */
397*1110f384Sedp 		size = sizeof (struct strapush);
398*1110f384Sedp 		if (SAD_VER(csp->cp_cmd) == 0)
399*1110f384Sedp 			size -= sizeof (struct apdata);
400*1110f384Sedp 		if ((ret = miocpullup(mp, size)) != 0) {
401*1110f384Sedp 			miocnak(qp, mp, 0, ret);
4027c478bd9Sstevel@tonic-gate 			return;
4037c478bd9Sstevel@tonic-gate 		}
404*1110f384Sedp 		sap = (struct strapush *)mp->b_cont->b_rptr;
405*1110f384Sedp 		dev = makedevice(sap->sap_major, sap->sap_minor);
4067c478bd9Sstevel@tonic-gate 	}
407*1110f384Sedp 	switch (SAD_CMD(csp->cp_cmd)) {
408*1110f384Sedp 	case SAD_CMD(SAD_SAP):
4097c478bd9Sstevel@tonic-gate 
410*1110f384Sedp 		/* currently we only support one SAD_SAP command */
411*1110f384Sedp 		if (((long)csp->cp_private) != GETSTRUCT) {
4127c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
4137c478bd9Sstevel@tonic-gate 			    "apush_iocdata: cp_private bad in SAD_SAP: %p",
4147c478bd9Sstevel@tonic-gate 			    (void *)csp->cp_private);
415*1110f384Sedp 			miocnak(qp, mp, 0, EINVAL);
416*1110f384Sedp 			return;
417*1110f384Sedp 		}
418*1110f384Sedp 
419*1110f384Sedp 		switch (sap->sap_cmd) {
420*1110f384Sedp 		default:
421*1110f384Sedp 			miocnak(qp, mp, 0, EINVAL);
422*1110f384Sedp 			return;
423*1110f384Sedp 		case SAP_ONE:
424*1110f384Sedp 		case SAP_RANGE:
425*1110f384Sedp 		case SAP_ALL:
426*1110f384Sedp 			/* allocate and initialize a new config */
427*1110f384Sedp 			ap = sad_ap_alloc();
428*1110f384Sedp 			ap->ap_common = sap->sap_common;
429*1110f384Sedp 			if (SAD_VER(csp->cp_cmd) > 0)
430*1110f384Sedp 				ap->ap_anchor = sap->sap_anchor;
431*1110f384Sedp 			for (i = 0; i < MIN(sap->sap_npush, MAXAPUSH); i++)
432*1110f384Sedp 				(void) strncpy(ap->ap_list[i],
433*1110f384Sedp 				    sap->sap_list[i], FMNAMESZ);
434*1110f384Sedp 
435*1110f384Sedp 			/* sanity check the request */
436*1110f384Sedp 			if (((ret = sad_ap_verify(ap)) != 0) ||
437*1110f384Sedp 			    ((ret = valid_major(ap->ap_major)) != 0)) {
438*1110f384Sedp 				sad_ap_rele(ap);
439*1110f384Sedp 				miocnak(qp, mp, 0, ret);
440*1110f384Sedp 				return;
441*1110f384Sedp 			}
442*1110f384Sedp 
443*1110f384Sedp 			/* check for overlapping configs */
444*1110f384Sedp 			mutex_enter(&sad_lock);
445*1110f384Sedp 			if ((ap_tmp = sad_ap_find(&ap->ap_common)) != NULL) {
446*1110f384Sedp 				/* already configured */
447*1110f384Sedp 				mutex_exit(&sad_lock);
448*1110f384Sedp 				sad_ap_rele(ap_tmp);
449*1110f384Sedp 				sad_ap_rele(ap);
450*1110f384Sedp 				miocnak(qp, mp, 0, EEXIST);
451*1110f384Sedp 				return;
452*1110f384Sedp 			}
453*1110f384Sedp 
454*1110f384Sedp 			/* add the new config to our hash */
455*1110f384Sedp 			sad_ap_insert(ap);
456*1110f384Sedp 			mutex_exit(&sad_lock);
457*1110f384Sedp 			miocack(qp, mp, 0, 0);
458*1110f384Sedp 			return;
459*1110f384Sedp 
460*1110f384Sedp 		case SAP_CLEAR:
461*1110f384Sedp 			/* sanity check the request */
462*1110f384Sedp 			if (ret = valid_major(sap->sap_major)) {
463*1110f384Sedp 				miocnak(qp, mp, 0, ret);
464*1110f384Sedp 				return;
465*1110f384Sedp 			}
466*1110f384Sedp 
467*1110f384Sedp 			/* search for a matching config */
468*1110f384Sedp 			if ((ap = sad_ap_find_by_dev(dev)) == NULL) {
469*1110f384Sedp 				/* no config found */
470*1110f384Sedp 				miocnak(qp, mp, 0, ENODEV);
471*1110f384Sedp 				return;
472*1110f384Sedp 			}
473*1110f384Sedp 
474*1110f384Sedp 			/*
475*1110f384Sedp 			 * If we matched a SAP_RANGE config
476*1110f384Sedp 			 * the minor passed in must match the
477*1110f384Sedp 			 * beginning of the range exactly.
478*1110f384Sedp 			 */
479*1110f384Sedp 			if ((ap->ap_type == SAP_RANGE) &&
480*1110f384Sedp 			    (ap->ap_minor != sap->sap_minor)) {
481*1110f384Sedp 				sad_ap_rele(ap);
482*1110f384Sedp 				miocnak(qp, mp, 0, ERANGE);
483*1110f384Sedp 				return;
484*1110f384Sedp 			}
485*1110f384Sedp 
486*1110f384Sedp 			/*
487*1110f384Sedp 			 * If we matched a SAP_ALL config
488*1110f384Sedp 			 * the minor passed in must be 0.
489*1110f384Sedp 			 */
490*1110f384Sedp 			if ((ap->ap_type == SAP_ALL) &&
491*1110f384Sedp 			    (sap->sap_minor != 0)) {
492*1110f384Sedp 				sad_ap_rele(ap);
493*1110f384Sedp 				miocnak(qp, mp, 0, EINVAL);
494*1110f384Sedp 				return;
495*1110f384Sedp 			}
496*1110f384Sedp 
497*1110f384Sedp 			/*
498*1110f384Sedp 			 * make sure someone else hasn't already
499*1110f384Sedp 			 * removed this config from the hash.
500*1110f384Sedp 			 */
501*1110f384Sedp 			mutex_enter(&sad_lock);
502*1110f384Sedp 			ap_tmp = sad_ap_find(&ap->ap_common);
503*1110f384Sedp 			if (ap_tmp != ap) {
504*1110f384Sedp 				mutex_exit(&sad_lock);
505*1110f384Sedp 				sad_ap_rele(ap_tmp);
506*1110f384Sedp 				sad_ap_rele(ap);
507*1110f384Sedp 				miocnak(qp, mp, 0, ENODEV);
508*1110f384Sedp 				return;
509*1110f384Sedp 			} else
510*1110f384Sedp 
511*1110f384Sedp 			/* remove the config from the hash and return */
512*1110f384Sedp 			sad_ap_remove(ap);
513*1110f384Sedp 			mutex_exit(&sad_lock);
514*1110f384Sedp 
515*1110f384Sedp 			/*
516*1110f384Sedp 			 * Release thrice, once for sad_ap_find_by_dev(),
517*1110f384Sedp 			 * once for sad_ap_find(), and once to free.
518*1110f384Sedp 			 */
519*1110f384Sedp 			sad_ap_rele(ap);
520*1110f384Sedp 			sad_ap_rele(ap);
521*1110f384Sedp 			sad_ap_rele(ap);
522*1110f384Sedp 			miocack(qp, mp, 0, 0);
523*1110f384Sedp 			return;
524*1110f384Sedp 		} /* switch (sap_cmd) */
525*1110f384Sedp 		/*NOTREACHED*/
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate 	case SAD_CMD(SAD_GAP):
5287c478bd9Sstevel@tonic-gate 		switch ((long)csp->cp_private) {
5297c478bd9Sstevel@tonic-gate 
530*1110f384Sedp 		case GETSTRUCT:
531*1110f384Sedp 			/* sanity check the request */
5327c478bd9Sstevel@tonic-gate 			if (ret = valid_major(sap->sap_major)) {
5337c478bd9Sstevel@tonic-gate 				miocnak(qp, mp, 0, ret);
534*1110f384Sedp 				return;
5357c478bd9Sstevel@tonic-gate 			}
5367c478bd9Sstevel@tonic-gate 
537*1110f384Sedp 			/* search for a matching config */
538*1110f384Sedp 			if ((ap = sad_ap_find_by_dev(dev)) == NULL) {
539*1110f384Sedp 				/* no config found */
5407c478bd9Sstevel@tonic-gate 				miocnak(qp, mp, 0, ENODEV);
541*1110f384Sedp 				return;
5427c478bd9Sstevel@tonic-gate 			}
5437c478bd9Sstevel@tonic-gate 
544*1110f384Sedp 			/* copy out the contents of the config */
5457c478bd9Sstevel@tonic-gate 			sap->sap_common = ap->ap_common;
5467c478bd9Sstevel@tonic-gate 			if (SAD_VER(csp->cp_cmd) > 0)
5477c478bd9Sstevel@tonic-gate 				sap->sap_anchor = ap->ap_anchor;
5487c478bd9Sstevel@tonic-gate 			for (i = 0; i < ap->ap_npush; i++)
5497c478bd9Sstevel@tonic-gate 				(void) strcpy(sap->sap_list[i], ap->ap_list[i]);
5507c478bd9Sstevel@tonic-gate 			for (; i < MAXAPUSH; i++)
5517c478bd9Sstevel@tonic-gate 				bzero(sap->sap_list[i], FMNAMESZ + 1);
5527c478bd9Sstevel@tonic-gate 
553*1110f384Sedp 			/* release our hold on the config */
554*1110f384Sedp 			sad_ap_rele(ap);
555*1110f384Sedp 
556*1110f384Sedp 			/* copyout the results */
5577c478bd9Sstevel@tonic-gate 			if (SAD_VER(csp->cp_cmd) == 1)
5587c478bd9Sstevel@tonic-gate 				size = STRAPUSH_V1_LEN;
5597c478bd9Sstevel@tonic-gate 			else
5607c478bd9Sstevel@tonic-gate 				size = STRAPUSH_V0_LEN;
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 			sadp = (struct saddev *)qp->q_ptr;
5637c478bd9Sstevel@tonic-gate 			mcopyout(mp, (void *)GETRESULT, size, sadp->sa_addr,
5647c478bd9Sstevel@tonic-gate 			    NULL);
5657c478bd9Sstevel@tonic-gate 			qreply(qp, mp);
566*1110f384Sedp 			return;
5677c478bd9Sstevel@tonic-gate 		case GETRESULT:
5687c478bd9Sstevel@tonic-gate 			miocack(qp, mp, 0, 0);
569*1110f384Sedp 			return;
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate 		default:
5727c478bd9Sstevel@tonic-gate 			cmn_err(CE_WARN,
5737c478bd9Sstevel@tonic-gate 			    "apush_iocdata: cp_private bad case SAD_GAP: %p",
5747c478bd9Sstevel@tonic-gate 			    (void *)csp->cp_private);
5757c478bd9Sstevel@tonic-gate 			freemsg(mp);
576*1110f384Sedp 			return;
5777c478bd9Sstevel@tonic-gate 		} /* switch (cp_private) */
578*1110f384Sedp 		/*NOTREACHED*/
5797c478bd9Sstevel@tonic-gate 	default:	/* can't happen */
5807c478bd9Sstevel@tonic-gate 		ASSERT(0);
5817c478bd9Sstevel@tonic-gate 		freemsg(mp);
5827c478bd9Sstevel@tonic-gate 		return;
583*1110f384Sedp 	} /* switch (cp_cmd) */
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate /*
5877c478bd9Sstevel@tonic-gate  * vml_ioctl() -
5887c478bd9Sstevel@tonic-gate  * Handle the M_IOCTL message associated with a request
5897c478bd9Sstevel@tonic-gate  * to validate a module list.
5907c478bd9Sstevel@tonic-gate  */
5917c478bd9Sstevel@tonic-gate static void
5927c478bd9Sstevel@tonic-gate vml_ioctl(
5937c478bd9Sstevel@tonic-gate 	queue_t *qp,	/* pointer to write queue */
5947c478bd9Sstevel@tonic-gate 	mblk_t *mp)	/* message pointer */
5957c478bd9Sstevel@tonic-gate {
5967c478bd9Sstevel@tonic-gate 	struct iocblk *iocp;
5977c478bd9Sstevel@tonic-gate 
5987c478bd9Sstevel@tonic-gate 	iocp = (struct iocblk *)mp->b_rptr;
5997c478bd9Sstevel@tonic-gate 	if (iocp->ioc_count != TRANSPARENT) {
6007c478bd9Sstevel@tonic-gate 		miocnak(qp, mp, 0, EINVAL);
6017c478bd9Sstevel@tonic-gate 		return;
6027c478bd9Sstevel@tonic-gate 	}
6037c478bd9Sstevel@tonic-gate 	ASSERT(iocp->ioc_cmd == SAD_VML);
6047c478bd9Sstevel@tonic-gate 	mcopyin(mp, (void *)GETSTRUCT,
6057c478bd9Sstevel@tonic-gate 	    SIZEOF_STRUCT(str_list, iocp->ioc_flag), NULL);
6067c478bd9Sstevel@tonic-gate 	qreply(qp, mp);
6077c478bd9Sstevel@tonic-gate }
6087c478bd9Sstevel@tonic-gate 
6097c478bd9Sstevel@tonic-gate /*
6107c478bd9Sstevel@tonic-gate  * vml_iocdata() -
6117c478bd9Sstevel@tonic-gate  * Handle the M_IOCDATA messages associated with
6127c478bd9Sstevel@tonic-gate  * a request to validate a module list.
6137c478bd9Sstevel@tonic-gate  */
6147c478bd9Sstevel@tonic-gate static void
6157c478bd9Sstevel@tonic-gate vml_iocdata(
6167c478bd9Sstevel@tonic-gate 	queue_t *qp,	/* pointer to write queue */
6177c478bd9Sstevel@tonic-gate 	mblk_t *mp)	/* message pointer */
6187c478bd9Sstevel@tonic-gate {
6197c478bd9Sstevel@tonic-gate 	long i;
6207c478bd9Sstevel@tonic-gate 	int	nmods;
6217c478bd9Sstevel@tonic-gate 	struct copyresp *csp;
6227c478bd9Sstevel@tonic-gate 	struct str_mlist *lp;
6237c478bd9Sstevel@tonic-gate 	STRUCT_HANDLE(str_list, slp);
6247c478bd9Sstevel@tonic-gate 	struct saddev *sadp;
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	csp = (struct copyresp *)mp->b_rptr;
6277c478bd9Sstevel@tonic-gate 	if (csp->cp_rval) {	/* if there was an error */
6287c478bd9Sstevel@tonic-gate 		freemsg(mp);
6297c478bd9Sstevel@tonic-gate 		return;
6307c478bd9Sstevel@tonic-gate 	}
6317c478bd9Sstevel@tonic-gate 
6327c478bd9Sstevel@tonic-gate 	ASSERT(csp->cp_cmd == SAD_VML);
6337c478bd9Sstevel@tonic-gate 	sadp = (struct saddev *)qp->q_ptr;
6347c478bd9Sstevel@tonic-gate 	switch ((long)csp->cp_private) {
6357c478bd9Sstevel@tonic-gate 	case GETSTRUCT:
6367c478bd9Sstevel@tonic-gate 		STRUCT_SET_HANDLE(slp, csp->cp_flag,
6377c478bd9Sstevel@tonic-gate 		    (struct str_list *)mp->b_cont->b_rptr);
6387c478bd9Sstevel@tonic-gate 		nmods = STRUCT_FGET(slp, sl_nmods);
6397c478bd9Sstevel@tonic-gate 		if (nmods <= 0) {
6407c478bd9Sstevel@tonic-gate 			miocnak(qp, mp, 0, EINVAL);
6417c478bd9Sstevel@tonic-gate 			break;
6427c478bd9Sstevel@tonic-gate 		}
6437c478bd9Sstevel@tonic-gate 		sadp->sa_addr = (caddr_t)(uintptr_t)nmods;
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 		mcopyin(mp, (void *)GETLIST, nmods * sizeof (struct str_mlist),
6467c478bd9Sstevel@tonic-gate 		    STRUCT_FGETP(slp, sl_modlist));
6477c478bd9Sstevel@tonic-gate 		qreply(qp, mp);
6487c478bd9Sstevel@tonic-gate 		break;
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 	case GETLIST:
6517c478bd9Sstevel@tonic-gate 		lp = (struct str_mlist *)mp->b_cont->b_rptr;
6527c478bd9Sstevel@tonic-gate 		for (i = 0; i < (long)sadp->sa_addr; i++, lp++) {
6537c478bd9Sstevel@tonic-gate 			lp->l_name[FMNAMESZ] = '\0';
6547c478bd9Sstevel@tonic-gate 			if (fmodsw_find(lp->l_name, FMODSW_LOAD) == NULL) {
6557c478bd9Sstevel@tonic-gate 				miocack(qp, mp, 0, 1);
6567c478bd9Sstevel@tonic-gate 				return;
6577c478bd9Sstevel@tonic-gate 			}
6587c478bd9Sstevel@tonic-gate 		}
6597c478bd9Sstevel@tonic-gate 		miocack(qp, mp, 0, 0);
6607c478bd9Sstevel@tonic-gate 		break;
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 	default:
6637c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "vml_iocdata: invalid cp_private value: %p",
6647c478bd9Sstevel@tonic-gate 		    (void *)csp->cp_private);
6657c478bd9Sstevel@tonic-gate 		freemsg(mp);
6667c478bd9Sstevel@tonic-gate 		break;
6677c478bd9Sstevel@tonic-gate 	} /* switch (cp_private) */
6687c478bd9Sstevel@tonic-gate }
6697c478bd9Sstevel@tonic-gate 
6707c478bd9Sstevel@tonic-gate /*
6717c478bd9Sstevel@tonic-gate  * Validate a major number and also verify if
6727c478bd9Sstevel@tonic-gate  * it is a STREAMS device.
6737c478bd9Sstevel@tonic-gate  * Return values: 0 if a valid STREAMS dev
6747c478bd9Sstevel@tonic-gate  *		  error code otherwise
6757c478bd9Sstevel@tonic-gate  */
6767c478bd9Sstevel@tonic-gate static int
6777c478bd9Sstevel@tonic-gate valid_major(major_t major)
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate 	int ret = 0;
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	if (etoimajor(major) == -1)
6827c478bd9Sstevel@tonic-gate 		return (EINVAL);
6837c478bd9Sstevel@tonic-gate 
6847c478bd9Sstevel@tonic-gate 	/*
6857c478bd9Sstevel@tonic-gate 	 * attempt to load the driver 'major' and verify that
6867c478bd9Sstevel@tonic-gate 	 * it is a STREAMS driver.
6877c478bd9Sstevel@tonic-gate 	 */
6887c478bd9Sstevel@tonic-gate 	if (ddi_hold_driver(major) == NULL)
6897c478bd9Sstevel@tonic-gate 		return (EINVAL);
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 	if (!STREAMSTAB(major))
6927c478bd9Sstevel@tonic-gate 		ret = ENOSTR;
6937c478bd9Sstevel@tonic-gate 
6947c478bd9Sstevel@tonic-gate 	ddi_rele_driver(major);
6957c478bd9Sstevel@tonic-gate 
6967c478bd9Sstevel@tonic-gate 	return (ret);
6977c478bd9Sstevel@tonic-gate }
698