xref: /onnv-gate/usr/src/uts/common/io/usb/hubd/hubd.c (revision 7656:2621e50fdf4a)
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
57425SGongtian.Zhao@Sun.COM  * Common Development and Distribution License (the "License").
67425SGongtian.Zhao@Sun.COM  * 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 /*
227425SGongtian.Zhao@Sun.COM  * 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 
270Sstevel@tonic-gate /*
280Sstevel@tonic-gate  * skeleton hub driver, the actual code is in hubdi.c
290Sstevel@tonic-gate  * as it is shared between the root hub and the other hub instances
300Sstevel@tonic-gate  */
310Sstevel@tonic-gate #if defined(lint) && !defined(DEBUG)
320Sstevel@tonic-gate #define	DEBUG	1
330Sstevel@tonic-gate #endif
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <sys/usb/usba/usbai_version.h>
360Sstevel@tonic-gate #include <sys/usb/usba.h>
370Sstevel@tonic-gate #include <sys/usb/usba/hubdi.h>
380Sstevel@tonic-gate #include <sys/usb/hubd/hub.h>
390Sstevel@tonic-gate #include <sys/usb/hubd/hubdvar.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate static int hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp);
420Sstevel@tonic-gate static int hubd_close(dev_t dev, int flag, int otyp, cred_t *credp);
430Sstevel@tonic-gate static int hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
440Sstevel@tonic-gate 	cred_t *credp, int *rvalp);
450Sstevel@tonic-gate static int hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
460Sstevel@tonic-gate 	void *arg, void **result);
470Sstevel@tonic-gate extern int usba_hubdi_power(dev_info_t *dip, int comp, int level);
480Sstevel@tonic-gate 
490Sstevel@tonic-gate 
500Sstevel@tonic-gate static struct cb_ops hubd_cb_ops = {
510Sstevel@tonic-gate 	hubd_open,			/* open */
520Sstevel@tonic-gate 	hubd_close,			/* close */
530Sstevel@tonic-gate 	nodev,				/* strategy */
540Sstevel@tonic-gate 	nodev,				/* print */
550Sstevel@tonic-gate 	nodev,				/* dump */
560Sstevel@tonic-gate 	nodev,				/* read */
570Sstevel@tonic-gate 	nodev,				/* write */
580Sstevel@tonic-gate 	hubd_ioctl,			/* ioctl */
590Sstevel@tonic-gate 	nodev,				/* devmap */
600Sstevel@tonic-gate 	nodev,				/* mmap */
610Sstevel@tonic-gate 	nodev,				/* segmap */
620Sstevel@tonic-gate 	nochpoll,			/* poll */
630Sstevel@tonic-gate 	ddi_prop_op,			/* cb_prop_op */
640Sstevel@tonic-gate 	NULL,				/* streamtab */
650Sstevel@tonic-gate 	D_MP				/* Driver compatibility flag */
660Sstevel@tonic-gate };
670Sstevel@tonic-gate 
680Sstevel@tonic-gate static struct dev_ops hubd_ops = {
690Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev, */
700Sstevel@tonic-gate 	0,			/* refcnt  */
710Sstevel@tonic-gate 	hubd_info,		/* info */
720Sstevel@tonic-gate 	nulldev,		/* identify */
730Sstevel@tonic-gate 	nulldev,		/* probe */
740Sstevel@tonic-gate 	usba_hubdi_attach,	/* attach */
750Sstevel@tonic-gate 	usba_hubdi_detach,	/* detach */
760Sstevel@tonic-gate 	nodev,			/* reset */
770Sstevel@tonic-gate 	&hubd_cb_ops,		/* driver operations */
780Sstevel@tonic-gate 	&usba_hubdi_busops,	/* bus operations */
79*7656SSherry.Moore@Sun.COM 	usba_hubdi_power,	/* power */
80*7656SSherry.Moore@Sun.COM 	ddi_quiesce_not_needed,		/* quiesce */
810Sstevel@tonic-gate };
820Sstevel@tonic-gate 
830Sstevel@tonic-gate static struct modldrv modldrv = {
840Sstevel@tonic-gate 	&mod_driverops, /* Type of module. This one is a driver */
857425SGongtian.Zhao@Sun.COM 	"USB Hub Driver", /* Name of the module. */
860Sstevel@tonic-gate 	&hubd_ops,	/* driver ops */
870Sstevel@tonic-gate };
880Sstevel@tonic-gate 
890Sstevel@tonic-gate static struct modlinkage modlinkage = {
900Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
910Sstevel@tonic-gate };
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 
940Sstevel@tonic-gate extern void *hubd_statep;
950Sstevel@tonic-gate 
960Sstevel@tonic-gate int
_init(void)970Sstevel@tonic-gate _init(void)
980Sstevel@tonic-gate {
990Sstevel@tonic-gate 	int rval;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	/* Initialize the soft state structures */
1020Sstevel@tonic-gate 	if ((rval = ddi_soft_state_init(&hubd_statep,
1030Sstevel@tonic-gate 	    sizeof (hubd_t), HUBD_INITIAL_SOFT_SPACE)) != 0) {
1040Sstevel@tonic-gate 		return (rval);
1050Sstevel@tonic-gate 	}
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 	if ((rval = mod_install(&modlinkage)) != 0) {
1080Sstevel@tonic-gate 		ddi_soft_state_fini(&hubd_statep);
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate 		return (rval);
1110Sstevel@tonic-gate 	}
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	return (rval);
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate int
_fini(void)1180Sstevel@tonic-gate _fini(void)
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate 	int rval = mod_remove(&modlinkage);
1210Sstevel@tonic-gate 	if (rval == 0) {
1220Sstevel@tonic-gate 		ddi_soft_state_fini(&hubd_statep);
1230Sstevel@tonic-gate 	}
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	return (rval);
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 
1290Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1300Sstevel@tonic-gate _info(struct modinfo *modinfop)
1310Sstevel@tonic-gate {
1320Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1330Sstevel@tonic-gate }
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate static dev_info_t *
hubd_get_dip(dev_t dev)1370Sstevel@tonic-gate hubd_get_dip(dev_t dev)
1380Sstevel@tonic-gate {
1390Sstevel@tonic-gate 	minor_t minor = getminor(dev);
1400Sstevel@tonic-gate 	int instance = (int)minor & ~HUBD_IS_ROOT_HUB;
1410Sstevel@tonic-gate 	hubd_t *hubd = ddi_get_soft_state(hubd_statep, instance);
1420Sstevel@tonic-gate 
1430Sstevel@tonic-gate 	if (hubd) {
1440Sstevel@tonic-gate 		return (hubd->h_dip);
1450Sstevel@tonic-gate 	} else {
1460Sstevel@tonic-gate 		return (NULL);
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate /*
1510Sstevel@tonic-gate  * info handler
1520Sstevel@tonic-gate  */
1530Sstevel@tonic-gate /*ARGSUSED*/
1540Sstevel@tonic-gate int
hubd_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)1550Sstevel@tonic-gate hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
1560Sstevel@tonic-gate 	void *arg, void **result)
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate 	dev_t dev;
1590Sstevel@tonic-gate 	int instance;
1600Sstevel@tonic-gate 	int error = DDI_FAILURE;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 	switch (infocmd) {
1630Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
1640Sstevel@tonic-gate 		*result = (void *)hubd_get_dip((dev_t)arg);
1650Sstevel@tonic-gate 		if (*result != NULL) {
1660Sstevel@tonic-gate 			error = DDI_SUCCESS;
1670Sstevel@tonic-gate 		}
1680Sstevel@tonic-gate 		break;
1690Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
1700Sstevel@tonic-gate 		dev = (dev_t)arg;
1710Sstevel@tonic-gate 		instance = HUBD_UNIT(dev);
1720Sstevel@tonic-gate 		*result = (void *)(intptr_t)instance;
1730Sstevel@tonic-gate 		error = DDI_SUCCESS;
1740Sstevel@tonic-gate 		break;
1750Sstevel@tonic-gate 	default:
1760Sstevel@tonic-gate 		break;
1770Sstevel@tonic-gate 	}
1780Sstevel@tonic-gate 	return (error);
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate static int
hubd_open(dev_t * devp,int flags,int otyp,cred_t * credp)1820Sstevel@tonic-gate hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp)
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(*devp);
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 	return (usba_hubdi_open(dip, devp, flags, otyp, credp));
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate 
1900Sstevel@tonic-gate static int
hubd_close(dev_t dev,int flag,int otyp,cred_t * credp)1910Sstevel@tonic-gate hubd_close(dev_t dev, int flag, int otyp, cred_t *credp)
1920Sstevel@tonic-gate {
1930Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(dev);
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 	return (usba_hubdi_close(dip, dev, flag, otyp, credp));
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate static int
hubd_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)2000Sstevel@tonic-gate hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
2010Sstevel@tonic-gate 	cred_t *credp, int *rvalp)
2020Sstevel@tonic-gate {
2030Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(dev);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	return (usba_hubdi_ioctl(dip, dev, cmd, arg, mode,
2067425SGongtian.Zhao@Sun.COM 	    credp, rvalp));
2070Sstevel@tonic-gate }
208