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
577e51571Sgongtian zhao - Sun Microsystems - Beijing China * Common Development and Distribution License (the "License").
677e51571Sgongtian zhao - Sun Microsystems - Beijing China * 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 /*
2277e51571Sgongtian zhao - Sun Microsystems - Beijing China * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate * skeleton hub driver, the actual code is in hubdi.c
297c478bd9Sstevel@tonic-gate * as it is shared between the root hub and the other hub instances
307c478bd9Sstevel@tonic-gate */
317c478bd9Sstevel@tonic-gate #if defined(lint) && !defined(DEBUG)
327c478bd9Sstevel@tonic-gate #define DEBUG 1
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usbai_version.h>
367c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h>
377c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hubdi.h>
387c478bd9Sstevel@tonic-gate #include <sys/usb/hubd/hub.h>
397c478bd9Sstevel@tonic-gate #include <sys/usb/hubd/hubdvar.h>
407c478bd9Sstevel@tonic-gate
417c478bd9Sstevel@tonic-gate static int hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp);
427c478bd9Sstevel@tonic-gate static int hubd_close(dev_t dev, int flag, int otyp, cred_t *credp);
437c478bd9Sstevel@tonic-gate static int hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
447c478bd9Sstevel@tonic-gate cred_t *credp, int *rvalp);
457c478bd9Sstevel@tonic-gate static int hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
467c478bd9Sstevel@tonic-gate void *arg, void **result);
477c478bd9Sstevel@tonic-gate extern int usba_hubdi_power(dev_info_t *dip, int comp, int level);
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate
507c478bd9Sstevel@tonic-gate static struct cb_ops hubd_cb_ops = {
517c478bd9Sstevel@tonic-gate hubd_open, /* open */
527c478bd9Sstevel@tonic-gate hubd_close, /* close */
537c478bd9Sstevel@tonic-gate nodev, /* strategy */
547c478bd9Sstevel@tonic-gate nodev, /* print */
557c478bd9Sstevel@tonic-gate nodev, /* dump */
567c478bd9Sstevel@tonic-gate nodev, /* read */
577c478bd9Sstevel@tonic-gate nodev, /* write */
587c478bd9Sstevel@tonic-gate hubd_ioctl, /* ioctl */
597c478bd9Sstevel@tonic-gate nodev, /* devmap */
607c478bd9Sstevel@tonic-gate nodev, /* mmap */
617c478bd9Sstevel@tonic-gate nodev, /* segmap */
627c478bd9Sstevel@tonic-gate nochpoll, /* poll */
637c478bd9Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */
647c478bd9Sstevel@tonic-gate NULL, /* streamtab */
657c478bd9Sstevel@tonic-gate D_MP /* Driver compatibility flag */
667c478bd9Sstevel@tonic-gate };
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate static struct dev_ops hubd_ops = {
697c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */
707c478bd9Sstevel@tonic-gate 0, /* refcnt */
717c478bd9Sstevel@tonic-gate hubd_info, /* info */
727c478bd9Sstevel@tonic-gate nulldev, /* identify */
737c478bd9Sstevel@tonic-gate nulldev, /* probe */
747c478bd9Sstevel@tonic-gate usba_hubdi_attach, /* attach */
757c478bd9Sstevel@tonic-gate usba_hubdi_detach, /* detach */
767c478bd9Sstevel@tonic-gate nodev, /* reset */
777c478bd9Sstevel@tonic-gate &hubd_cb_ops, /* driver operations */
787c478bd9Sstevel@tonic-gate &usba_hubdi_busops, /* bus operations */
79*19397407SSherry Moore usba_hubdi_power, /* power */
80*19397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */
817c478bd9Sstevel@tonic-gate };
827c478bd9Sstevel@tonic-gate
837c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
847c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */
8577e51571Sgongtian zhao - Sun Microsystems - Beijing China "USB Hub Driver", /* Name of the module. */
867c478bd9Sstevel@tonic-gate &hubd_ops, /* driver ops */
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate
897c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
907c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL
917c478bd9Sstevel@tonic-gate };
927c478bd9Sstevel@tonic-gate
937c478bd9Sstevel@tonic-gate
947c478bd9Sstevel@tonic-gate extern void *hubd_statep;
957c478bd9Sstevel@tonic-gate
967c478bd9Sstevel@tonic-gate int
_init(void)977c478bd9Sstevel@tonic-gate _init(void)
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate int rval;
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate /* Initialize the soft state structures */
1027c478bd9Sstevel@tonic-gate if ((rval = ddi_soft_state_init(&hubd_statep,
1037c478bd9Sstevel@tonic-gate sizeof (hubd_t), HUBD_INITIAL_SOFT_SPACE)) != 0) {
1047c478bd9Sstevel@tonic-gate return (rval);
1057c478bd9Sstevel@tonic-gate }
1067c478bd9Sstevel@tonic-gate
1077c478bd9Sstevel@tonic-gate if ((rval = mod_install(&modlinkage)) != 0) {
1087c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&hubd_statep);
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate return (rval);
1117c478bd9Sstevel@tonic-gate }
1127c478bd9Sstevel@tonic-gate
1137c478bd9Sstevel@tonic-gate return (rval);
1147c478bd9Sstevel@tonic-gate }
1157c478bd9Sstevel@tonic-gate
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate int
_fini(void)1187c478bd9Sstevel@tonic-gate _fini(void)
1197c478bd9Sstevel@tonic-gate {
1207c478bd9Sstevel@tonic-gate int rval = mod_remove(&modlinkage);
1217c478bd9Sstevel@tonic-gate if (rval == 0) {
1227c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&hubd_statep);
1237c478bd9Sstevel@tonic-gate }
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate return (rval);
1267c478bd9Sstevel@tonic-gate }
1277c478bd9Sstevel@tonic-gate
1287c478bd9Sstevel@tonic-gate
1297c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1307c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
1317c478bd9Sstevel@tonic-gate {
1327c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate
1357c478bd9Sstevel@tonic-gate
1367c478bd9Sstevel@tonic-gate static dev_info_t *
hubd_get_dip(dev_t dev)1377c478bd9Sstevel@tonic-gate hubd_get_dip(dev_t dev)
1387c478bd9Sstevel@tonic-gate {
1397c478bd9Sstevel@tonic-gate minor_t minor = getminor(dev);
1407c478bd9Sstevel@tonic-gate int instance = (int)minor & ~HUBD_IS_ROOT_HUB;
1417c478bd9Sstevel@tonic-gate hubd_t *hubd = ddi_get_soft_state(hubd_statep, instance);
1427c478bd9Sstevel@tonic-gate
1437c478bd9Sstevel@tonic-gate if (hubd) {
1447c478bd9Sstevel@tonic-gate return (hubd->h_dip);
1457c478bd9Sstevel@tonic-gate } else {
1467c478bd9Sstevel@tonic-gate return (NULL);
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate }
1497c478bd9Sstevel@tonic-gate
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate * info handler
1527c478bd9Sstevel@tonic-gate */
1537c478bd9Sstevel@tonic-gate /*ARGSUSED*/
1547c478bd9Sstevel@tonic-gate int
hubd_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)1557c478bd9Sstevel@tonic-gate hubd_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
1567c478bd9Sstevel@tonic-gate void *arg, void **result)
1577c478bd9Sstevel@tonic-gate {
1587c478bd9Sstevel@tonic-gate dev_t dev;
1597c478bd9Sstevel@tonic-gate int instance;
1607c478bd9Sstevel@tonic-gate int error = DDI_FAILURE;
1617c478bd9Sstevel@tonic-gate
1627c478bd9Sstevel@tonic-gate switch (infocmd) {
1637c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
1647c478bd9Sstevel@tonic-gate *result = (void *)hubd_get_dip((dev_t)arg);
1657c478bd9Sstevel@tonic-gate if (*result != NULL) {
1667c478bd9Sstevel@tonic-gate error = DDI_SUCCESS;
1677c478bd9Sstevel@tonic-gate }
1687c478bd9Sstevel@tonic-gate break;
1697c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
1707c478bd9Sstevel@tonic-gate dev = (dev_t)arg;
1717c478bd9Sstevel@tonic-gate instance = HUBD_UNIT(dev);
1727c478bd9Sstevel@tonic-gate *result = (void *)(intptr_t)instance;
1737c478bd9Sstevel@tonic-gate error = DDI_SUCCESS;
1747c478bd9Sstevel@tonic-gate break;
1757c478bd9Sstevel@tonic-gate default:
1767c478bd9Sstevel@tonic-gate break;
1777c478bd9Sstevel@tonic-gate }
1787c478bd9Sstevel@tonic-gate return (error);
1797c478bd9Sstevel@tonic-gate }
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate static int
hubd_open(dev_t * devp,int flags,int otyp,cred_t * credp)1827c478bd9Sstevel@tonic-gate hubd_open(dev_t *devp, int flags, int otyp, cred_t *credp)
1837c478bd9Sstevel@tonic-gate {
1847c478bd9Sstevel@tonic-gate dev_info_t *dip = hubd_get_dip(*devp);
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate return (usba_hubdi_open(dip, devp, flags, otyp, credp));
1877c478bd9Sstevel@tonic-gate }
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate static int
hubd_close(dev_t dev,int flag,int otyp,cred_t * credp)1917c478bd9Sstevel@tonic-gate hubd_close(dev_t dev, int flag, int otyp, cred_t *credp)
1927c478bd9Sstevel@tonic-gate {
1937c478bd9Sstevel@tonic-gate dev_info_t *dip = hubd_get_dip(dev);
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate return (usba_hubdi_close(dip, dev, flag, otyp, credp));
1967c478bd9Sstevel@tonic-gate }
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate
1997c478bd9Sstevel@tonic-gate static int
hubd_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)2007c478bd9Sstevel@tonic-gate hubd_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
2017c478bd9Sstevel@tonic-gate cred_t *credp, int *rvalp)
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate dev_info_t *dip = hubd_get_dip(dev);
2047c478bd9Sstevel@tonic-gate
2057c478bd9Sstevel@tonic-gate return (usba_hubdi_ioctl(dip, dev, cmd, arg, mode,
2067c478bd9Sstevel@tonic-gate credp, rvalp));
2077c478bd9Sstevel@tonic-gate }
208