xref: /onnv-gate/usr/src/uts/common/io/usb/hubd/hubd.c (revision 7425:e4dbffd35ebc)
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
5*7425SGongtian.Zhao@Sun.COM  * Common Development and Distribution License (the "License").
6*7425SGongtian.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 /*
22*7425SGongtian.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 */
790Sstevel@tonic-gate 	usba_hubdi_power	/* power */
800Sstevel@tonic-gate };
810Sstevel@tonic-gate 
820Sstevel@tonic-gate static struct modldrv modldrv = {
830Sstevel@tonic-gate 	&mod_driverops, /* Type of module. This one is a driver */
84*7425SGongtian.Zhao@Sun.COM 	"USB Hub Driver", /* Name of the module. */
850Sstevel@tonic-gate 	&hubd_ops,	/* driver ops */
860Sstevel@tonic-gate };
870Sstevel@tonic-gate 
880Sstevel@tonic-gate static struct modlinkage modlinkage = {
890Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
900Sstevel@tonic-gate };
910Sstevel@tonic-gate 
920Sstevel@tonic-gate 
930Sstevel@tonic-gate extern void *hubd_statep;
940Sstevel@tonic-gate 
950Sstevel@tonic-gate int
960Sstevel@tonic-gate _init(void)
970Sstevel@tonic-gate {
980Sstevel@tonic-gate 	int rval;
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate 	/* Initialize the soft state structures */
1010Sstevel@tonic-gate 	if ((rval = ddi_soft_state_init(&hubd_statep,
1020Sstevel@tonic-gate 	    sizeof (hubd_t), HUBD_INITIAL_SOFT_SPACE)) != 0) {
1030Sstevel@tonic-gate 		return (rval);
1040Sstevel@tonic-gate 	}
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	if ((rval = mod_install(&modlinkage)) != 0) {
1070Sstevel@tonic-gate 		ddi_soft_state_fini(&hubd_statep);
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 		return (rval);
1100Sstevel@tonic-gate 	}
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 	return (rval);
1130Sstevel@tonic-gate }
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate int
1170Sstevel@tonic-gate _fini(void)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 	int rval = mod_remove(&modlinkage);
1200Sstevel@tonic-gate 	if (rval == 0) {
1210Sstevel@tonic-gate 		ddi_soft_state_fini(&hubd_statep);
1220Sstevel@tonic-gate 	}
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	return (rval);
1250Sstevel@tonic-gate }
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate int
1290Sstevel@tonic-gate _info(struct modinfo *modinfop)
1300Sstevel@tonic-gate {
1310Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate static dev_info_t *
1360Sstevel@tonic-gate hubd_get_dip(dev_t dev)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate 	minor_t minor = getminor(dev);
1390Sstevel@tonic-gate 	int instance = (int)minor & ~HUBD_IS_ROOT_HUB;
1400Sstevel@tonic-gate 	hubd_t *hubd = ddi_get_soft_state(hubd_statep, instance);
1410Sstevel@tonic-gate 
1420Sstevel@tonic-gate 	if (hubd) {
1430Sstevel@tonic-gate 		return (hubd->h_dip);
1440Sstevel@tonic-gate 	} else {
1450Sstevel@tonic-gate 		return (NULL);
1460Sstevel@tonic-gate 	}
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate  * info handler
1510Sstevel@tonic-gate  */
1520Sstevel@tonic-gate /*ARGSUSED*/
1530Sstevel@tonic-gate int
1540Sstevel@tonic-gate hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
1550Sstevel@tonic-gate 	void *arg, void **result)
1560Sstevel@tonic-gate {
1570Sstevel@tonic-gate 	dev_t dev;
1580Sstevel@tonic-gate 	int instance;
1590Sstevel@tonic-gate 	int error = DDI_FAILURE;
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate 	switch (infocmd) {
1620Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
1630Sstevel@tonic-gate 		*result = (void *)hubd_get_dip((dev_t)arg);
1640Sstevel@tonic-gate 		if (*result != NULL) {
1650Sstevel@tonic-gate 			error = DDI_SUCCESS;
1660Sstevel@tonic-gate 		}
1670Sstevel@tonic-gate 		break;
1680Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
1690Sstevel@tonic-gate 		dev = (dev_t)arg;
1700Sstevel@tonic-gate 		instance = HUBD_UNIT(dev);
1710Sstevel@tonic-gate 		*result = (void *)(intptr_t)instance;
1720Sstevel@tonic-gate 		error = DDI_SUCCESS;
1730Sstevel@tonic-gate 		break;
1740Sstevel@tonic-gate 	default:
1750Sstevel@tonic-gate 		break;
1760Sstevel@tonic-gate 	}
1770Sstevel@tonic-gate 	return (error);
1780Sstevel@tonic-gate }
1790Sstevel@tonic-gate 
1800Sstevel@tonic-gate static int
1810Sstevel@tonic-gate hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp)
1820Sstevel@tonic-gate {
1830Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(*devp);
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	return (usba_hubdi_open(dip, devp, flags, otyp, credp));
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate static int
1900Sstevel@tonic-gate hubd_close(dev_t dev, int flag, int otyp, cred_t *credp)
1910Sstevel@tonic-gate {
1920Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(dev);
1930Sstevel@tonic-gate 
1940Sstevel@tonic-gate 	return (usba_hubdi_close(dip, dev, flag, otyp, credp));
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate 
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate static int
1990Sstevel@tonic-gate hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
2000Sstevel@tonic-gate 	cred_t *credp, int *rvalp)
2010Sstevel@tonic-gate {
2020Sstevel@tonic-gate 	dev_info_t *dip = hubd_get_dip(dev);
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	return (usba_hubdi_ioctl(dip, dev, cmd, arg, mode,
205*7425SGongtian.Zhao@Sun.COM 	    credp, rvalp));
2060Sstevel@tonic-gate }
207