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
51961Scth * Common Development and Distribution License (the "License").
61961Scth * 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*7656SSherry.Moore@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 * The tphci driver can be used to exercise the mpxio framework together
290Sstevel@tonic-gate * with tvhci/tclient.
300Sstevel@tonic-gate */
310Sstevel@tonic-gate
320Sstevel@tonic-gate #include <sys/conf.h>
330Sstevel@tonic-gate #include <sys/file.h>
340Sstevel@tonic-gate #include <sys/open.h>
350Sstevel@tonic-gate #include <sys/stat.h>
360Sstevel@tonic-gate #include <sys/modctl.h>
370Sstevel@tonic-gate #include <sys/ddi.h>
380Sstevel@tonic-gate #include <sys/sunddi.h>
390Sstevel@tonic-gate #include <sys/sunndi.h>
400Sstevel@tonic-gate #include <sys/sunmdi.h>
410Sstevel@tonic-gate #include <sys/disp.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate /* cb_ops entry points */
440Sstevel@tonic-gate static int tphci_open(dev_t *, int, int, cred_t *);
450Sstevel@tonic-gate static int tphci_close(dev_t, int, int, cred_t *);
460Sstevel@tonic-gate static int tphci_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
470Sstevel@tonic-gate static int tphci_attach(dev_info_t *, ddi_attach_cmd_t);
480Sstevel@tonic-gate static int tphci_detach(dev_info_t *, ddi_detach_cmd_t);
490Sstevel@tonic-gate static int tphci_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
500Sstevel@tonic-gate
510Sstevel@tonic-gate /* bus_ops entry points */
520Sstevel@tonic-gate static int tphci_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *,
530Sstevel@tonic-gate void *);
540Sstevel@tonic-gate static int tphci_initchild(dev_info_t *, dev_info_t *);
550Sstevel@tonic-gate static int tphci_uninitchild(dev_info_t *, dev_info_t *);
560Sstevel@tonic-gate static int tphci_bus_config(dev_info_t *, uint_t, ddi_bus_config_op_t, void *,
570Sstevel@tonic-gate dev_info_t **);
580Sstevel@tonic-gate static int tphci_bus_unconfig(dev_info_t *, uint_t, ddi_bus_config_op_t,
590Sstevel@tonic-gate void *);
600Sstevel@tonic-gate static int tphci_intr_op(dev_info_t *dip, dev_info_t *rdip,
610Sstevel@tonic-gate ddi_intr_op_t op, ddi_intr_handle_impl_t *hdlp, void *result);
620Sstevel@tonic-gate
630Sstevel@tonic-gate
640Sstevel@tonic-gate static void *tphci_state;
650Sstevel@tonic-gate struct tphci_state {
660Sstevel@tonic-gate dev_info_t *dip;
670Sstevel@tonic-gate };
680Sstevel@tonic-gate
690Sstevel@tonic-gate static struct cb_ops tphci_cb_ops = {
700Sstevel@tonic-gate tphci_open, /* open */
710Sstevel@tonic-gate tphci_close, /* close */
720Sstevel@tonic-gate nodev, /* strategy */
730Sstevel@tonic-gate nodev, /* print */
740Sstevel@tonic-gate nodev, /* dump */
750Sstevel@tonic-gate nodev, /* read */
760Sstevel@tonic-gate nodev, /* write */
770Sstevel@tonic-gate tphci_ioctl, /* ioctl */
780Sstevel@tonic-gate nodev, /* devmap */
790Sstevel@tonic-gate nodev, /* mmap */
800Sstevel@tonic-gate nodev, /* segmap */
810Sstevel@tonic-gate nochpoll, /* chpoll */
820Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */
830Sstevel@tonic-gate 0, /* streamtab */
840Sstevel@tonic-gate D_NEW | D_MP, /* cb_flag */
850Sstevel@tonic-gate CB_REV, /* rev */
860Sstevel@tonic-gate nodev, /* aread */
870Sstevel@tonic-gate nodev /* awrite */
880Sstevel@tonic-gate };
890Sstevel@tonic-gate
900Sstevel@tonic-gate static struct bus_ops tphci_bus_ops = {
910Sstevel@tonic-gate BUSO_REV, /* busops_rev */
920Sstevel@tonic-gate nullbusmap, /* bus_map */
930Sstevel@tonic-gate NULL, /* bus_get_intrspec */
940Sstevel@tonic-gate NULL, /* bus_add_interspec */
950Sstevel@tonic-gate NULL, /* bus_remove_interspec */
960Sstevel@tonic-gate i_ddi_map_fault, /* bus_map_fault */
970Sstevel@tonic-gate ddi_no_dma_map, /* bus_dma_map */
980Sstevel@tonic-gate ddi_no_dma_allochdl, /* bus_dma_allochdl */
990Sstevel@tonic-gate NULL, /* bus_dma_freehdl */
1000Sstevel@tonic-gate NULL, /* bus_dma_bindhdl */
1010Sstevel@tonic-gate NULL, /* bus_dma_unbindhdl */
1020Sstevel@tonic-gate NULL, /* bus_dma_flush */
1030Sstevel@tonic-gate NULL, /* bus_dma_win */
1040Sstevel@tonic-gate NULL, /* bus_dma_ctl */
1050Sstevel@tonic-gate tphci_ctl, /* bus_ctl */
1060Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */
1070Sstevel@tonic-gate NULL, /* bus_get_eventcookie */
1080Sstevel@tonic-gate NULL, /* bus_add_eventcall */
1090Sstevel@tonic-gate NULL, /* bus_remove_event */
1100Sstevel@tonic-gate NULL, /* bus_post_event */
1110Sstevel@tonic-gate NULL, /* bus_intr_ctl */
1120Sstevel@tonic-gate tphci_bus_config, /* bus_config */
1130Sstevel@tonic-gate tphci_bus_unconfig, /* bus_unconfig */
1140Sstevel@tonic-gate NULL, /* bus_fm_init */
1150Sstevel@tonic-gate NULL, /* bus_fm_fini */
1160Sstevel@tonic-gate NULL, /* bus_fm_access_enter */
1170Sstevel@tonic-gate NULL, /* bus_fm_access_exit */
1180Sstevel@tonic-gate NULL, /* bus_power */
1190Sstevel@tonic-gate tphci_intr_op /* bus_intr_op */
1200Sstevel@tonic-gate };
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate static struct dev_ops tphci_ops = {
1230Sstevel@tonic-gate DEVO_REV,
1240Sstevel@tonic-gate 0,
1250Sstevel@tonic-gate tphci_getinfo,
1260Sstevel@tonic-gate nulldev, /* identify */
1270Sstevel@tonic-gate nulldev, /* probe */
1280Sstevel@tonic-gate tphci_attach, /* attach and detach are mandatory */
1290Sstevel@tonic-gate tphci_detach,
1300Sstevel@tonic-gate nodev, /* reset */
1310Sstevel@tonic-gate &tphci_cb_ops, /* cb_ops */
1320Sstevel@tonic-gate &tphci_bus_ops, /* bus_ops */
133*7656SSherry.Moore@Sun.COM NULL, /* power */
134*7656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */
1350Sstevel@tonic-gate };
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate static struct modldrv modldrv = {
1400Sstevel@tonic-gate &mod_driverops,
141*7656SSherry.Moore@Sun.COM "test phci driver",
1420Sstevel@tonic-gate &tphci_ops
1430Sstevel@tonic-gate };
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate static struct modlinkage modlinkage = {
1460Sstevel@tonic-gate MODREV_1,
1470Sstevel@tonic-gate &modldrv,
1480Sstevel@tonic-gate NULL
1490Sstevel@tonic-gate };
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate int
_init(void)1520Sstevel@tonic-gate _init(void)
1530Sstevel@tonic-gate {
1540Sstevel@tonic-gate int rval;
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate if ((rval = ddi_soft_state_init(&tphci_state,
1570Sstevel@tonic-gate sizeof (struct tphci_state), 2)) != 0) {
1580Sstevel@tonic-gate return (rval);
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate if ((rval = mod_install(&modlinkage)) != 0) {
1620Sstevel@tonic-gate ddi_soft_state_fini(&tphci_state);
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate return (rval);
1650Sstevel@tonic-gate }
1660Sstevel@tonic-gate
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate int
_fini(void)1690Sstevel@tonic-gate _fini(void)
1700Sstevel@tonic-gate {
1710Sstevel@tonic-gate int rval;
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate /*
1740Sstevel@tonic-gate * don't start cleaning up until we know that the module remove
1750Sstevel@tonic-gate * has worked -- if this works, then we know that each instance
1760Sstevel@tonic-gate * has successfully been detached
1770Sstevel@tonic-gate */
1780Sstevel@tonic-gate if ((rval = mod_remove(&modlinkage)) != 0) {
1790Sstevel@tonic-gate return (rval);
1800Sstevel@tonic-gate }
1810Sstevel@tonic-gate
1820Sstevel@tonic-gate ddi_soft_state_fini(&tphci_state);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate return (rval);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1880Sstevel@tonic-gate _info(struct modinfo *modinfop)
1890Sstevel@tonic-gate {
1900Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate
1930Sstevel@tonic-gate /* ARGSUSED */
1940Sstevel@tonic-gate static int
tphci_open(dev_t * devp,int flag,int otype,cred_t * credp)1950Sstevel@tonic-gate tphci_open(dev_t *devp, int flag, int otype, cred_t *credp)
1960Sstevel@tonic-gate {
1970Sstevel@tonic-gate struct tphci_state *phci;
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate if (otype != OTYP_CHR) {
2000Sstevel@tonic-gate return (EINVAL);
2010Sstevel@tonic-gate }
2020Sstevel@tonic-gate
2030Sstevel@tonic-gate phci = ddi_get_soft_state(tphci_state, getminor(*devp));
2040Sstevel@tonic-gate if (phci == NULL) {
2050Sstevel@tonic-gate return (ENXIO);
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate return (0);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate
2110Sstevel@tonic-gate
2120Sstevel@tonic-gate /* ARGSUSED */
2130Sstevel@tonic-gate static int
tphci_close(dev_t dev,int flag,int otype,cred_t * credp)2140Sstevel@tonic-gate tphci_close(dev_t dev, int flag, int otype, cred_t *credp)
2150Sstevel@tonic-gate {
2160Sstevel@tonic-gate struct tphci_state *phci;
2170Sstevel@tonic-gate if (otype != OTYP_CHR) {
2180Sstevel@tonic-gate return (EINVAL);
2190Sstevel@tonic-gate }
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate phci = ddi_get_soft_state(tphci_state, getminor(dev));
2220Sstevel@tonic-gate if (phci == NULL) {
2230Sstevel@tonic-gate return (ENXIO);
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate return (0);
2270Sstevel@tonic-gate }
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate /* ARGSUSED */
2300Sstevel@tonic-gate static int
tphci_ioctl(dev_t dev,int cmd,intptr_t data,int mode,cred_t * credp,int * rval)2310Sstevel@tonic-gate tphci_ioctl(dev_t dev, int cmd, intptr_t data, int mode,
2320Sstevel@tonic-gate cred_t *credp, int *rval)
2330Sstevel@tonic-gate {
2340Sstevel@tonic-gate return (0);
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate /*
2380Sstevel@tonic-gate * attach the module
2390Sstevel@tonic-gate */
2400Sstevel@tonic-gate static int
tphci_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)2410Sstevel@tonic-gate tphci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2420Sstevel@tonic-gate {
2430Sstevel@tonic-gate char *vclass;
2440Sstevel@tonic-gate int instance, phci_regis = 0;
2450Sstevel@tonic-gate struct tphci_state *phci = NULL;
2460Sstevel@tonic-gate
2470Sstevel@tonic-gate instance = ddi_get_instance(dip);
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate switch (cmd) {
2500Sstevel@tonic-gate case DDI_ATTACH:
2510Sstevel@tonic-gate break;
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate case DDI_RESUME:
2540Sstevel@tonic-gate case DDI_PM_RESUME:
2550Sstevel@tonic-gate return (0); /* nothing to do */
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate default:
2580Sstevel@tonic-gate return (DDI_FAILURE);
2590Sstevel@tonic-gate }
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate /*
2620Sstevel@tonic-gate * Allocate phci data structure.
2630Sstevel@tonic-gate */
2640Sstevel@tonic-gate if (ddi_soft_state_zalloc(tphci_state, instance) != DDI_SUCCESS) {
2650Sstevel@tonic-gate return (DDI_FAILURE);
2660Sstevel@tonic-gate }
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate phci = ddi_get_soft_state(tphci_state, instance);
2690Sstevel@tonic-gate ASSERT(phci != NULL);
2700Sstevel@tonic-gate phci->dip = dip;
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate /* bus_addr has the form #,<vhci_class> */
2730Sstevel@tonic-gate vclass = strchr(ddi_get_name_addr(dip), ',');
2740Sstevel@tonic-gate if (vclass == NULL || vclass[1] == '\0') {
2750Sstevel@tonic-gate cmn_err(CE_NOTE, "tphci invalid bus_addr %s",
2760Sstevel@tonic-gate ddi_get_name_addr(dip));
2770Sstevel@tonic-gate goto attach_fail;
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate
2800Sstevel@tonic-gate /*
2810Sstevel@tonic-gate * Attach this instance with the mpxio framework
2820Sstevel@tonic-gate */
2830Sstevel@tonic-gate if (mdi_phci_register(vclass + 1, dip, 0) != MDI_SUCCESS) {
2840Sstevel@tonic-gate cmn_err(CE_WARN, "%s mdi_phci_register failed",
2850Sstevel@tonic-gate ddi_node_name(dip));
2860Sstevel@tonic-gate goto attach_fail;
2870Sstevel@tonic-gate }
2880Sstevel@tonic-gate phci_regis++;
2890Sstevel@tonic-gate
2900Sstevel@tonic-gate if (ddi_create_minor_node(dip, "devctl", S_IFCHR,
2910Sstevel@tonic-gate instance, DDI_NT_SCSI_NEXUS, 0) != DDI_SUCCESS) {
2920Sstevel@tonic-gate cmn_err(CE_NOTE, "%s ddi_create_minor_node failed",
2930Sstevel@tonic-gate ddi_node_name(dip));
2940Sstevel@tonic-gate goto attach_fail;
2950Sstevel@tonic-gate }
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1);
2980Sstevel@tonic-gate ddi_report_dev(dip);
2990Sstevel@tonic-gate return (DDI_SUCCESS);
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate attach_fail:
3020Sstevel@tonic-gate if (phci_regis)
3030Sstevel@tonic-gate (void) mdi_phci_unregister(dip, 0);
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate ddi_soft_state_free(tphci_state, instance);
3060Sstevel@tonic-gate return (DDI_FAILURE);
3070Sstevel@tonic-gate }
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate /*ARGSUSED*/
3110Sstevel@tonic-gate static int
tphci_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)3120Sstevel@tonic-gate tphci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
3130Sstevel@tonic-gate {
3140Sstevel@tonic-gate int instance = ddi_get_instance(dip);
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate switch (cmd) {
3170Sstevel@tonic-gate case DDI_DETACH:
3180Sstevel@tonic-gate break;
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate case DDI_SUSPEND:
3210Sstevel@tonic-gate case DDI_PM_SUSPEND:
3220Sstevel@tonic-gate return (0); /* nothing to do */
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate default:
3250Sstevel@tonic-gate return (DDI_FAILURE);
3260Sstevel@tonic-gate }
3270Sstevel@tonic-gate
3280Sstevel@tonic-gate if (mdi_phci_unregister(dip, 0) != MDI_SUCCESS)
3290Sstevel@tonic-gate return (DDI_FAILURE);
3300Sstevel@tonic-gate
3310Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL);
3320Sstevel@tonic-gate ddi_soft_state_free(tphci_state, instance);
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate return (DDI_SUCCESS);
3350Sstevel@tonic-gate }
3360Sstevel@tonic-gate
3370Sstevel@tonic-gate /*
3380Sstevel@tonic-gate * tphci_getinfo()
3390Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the
3400Sstevel@tonic-gate * instance number.
3410Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach.
3420Sstevel@tonic-gate */
3430Sstevel@tonic-gate
3440Sstevel@tonic-gate /*ARGSUSED*/
3450Sstevel@tonic-gate static int
tphci_getinfo(dev_info_t * dip,ddi_info_cmd_t cmd,void * arg,void ** result)3460Sstevel@tonic-gate tphci_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
3470Sstevel@tonic-gate {
3480Sstevel@tonic-gate struct tphci_state *phci;
3490Sstevel@tonic-gate int instance = getminor((dev_t)arg);
3500Sstevel@tonic-gate
3510Sstevel@tonic-gate switch (cmd) {
3520Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
3530Sstevel@tonic-gate phci = ddi_get_soft_state(tphci_state, instance);
3540Sstevel@tonic-gate if (phci != NULL)
3550Sstevel@tonic-gate *result = phci->dip;
3560Sstevel@tonic-gate else {
3570Sstevel@tonic-gate *result = NULL;
3580Sstevel@tonic-gate return (DDI_FAILURE);
3590Sstevel@tonic-gate }
3600Sstevel@tonic-gate break;
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
3630Sstevel@tonic-gate *result = (void *)(uintptr_t)instance;
3640Sstevel@tonic-gate break;
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate default:
3670Sstevel@tonic-gate return (DDI_FAILURE);
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate return (DDI_SUCCESS);
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate /*
3740Sstevel@tonic-gate * Interrupt stuff. NO OP for pseudo drivers.
3750Sstevel@tonic-gate */
3760Sstevel@tonic-gate /*ARGSUSED*/
3770Sstevel@tonic-gate static int
tphci_intr_op(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t op,ddi_intr_handle_impl_t * hdlp,void * result)3780Sstevel@tonic-gate tphci_intr_op(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op,
3790Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result)
3800Sstevel@tonic-gate {
3810Sstevel@tonic-gate return (DDI_FAILURE);
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate
3840Sstevel@tonic-gate static int
tphci_ctl(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t ctlop,void * arg,void * result)3850Sstevel@tonic-gate tphci_ctl(dev_info_t *dip, dev_info_t *rdip,
3860Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result)
3870Sstevel@tonic-gate {
3880Sstevel@tonic-gate switch (ctlop) {
3890Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV:
3900Sstevel@tonic-gate if (rdip == (dev_info_t *)0)
3910Sstevel@tonic-gate return (DDI_FAILURE);
3920Sstevel@tonic-gate cmn_err(CE_CONT, "?tphci-device: %s%d\n",
3930Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip));
3940Sstevel@tonic-gate return (DDI_SUCCESS);
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD:
3970Sstevel@tonic-gate {
3980Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg;
3990Sstevel@tonic-gate return (tphci_initchild(dip, child));
4000Sstevel@tonic-gate }
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD:
4030Sstevel@tonic-gate {
4040Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg;
4050Sstevel@tonic-gate return (tphci_uninitchild(dip, child));
4060Sstevel@tonic-gate }
4070Sstevel@tonic-gate
4080Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC:
4090Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT:
4100Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE:
4110Sstevel@tonic-gate case DDI_CTLOPS_NREGS:
4120Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV:
4130Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY:
4140Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY:
4150Sstevel@tonic-gate case DDI_CTLOPS_POKE:
4160Sstevel@tonic-gate case DDI_CTLOPS_PEEK:
4170Sstevel@tonic-gate /*
4180Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be called
4190Sstevel@tonic-gate * by a pseudo driver. So we whine when we're called.
4200Sstevel@tonic-gate */
4210Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n",
422*7656SSherry.Moore@Sun.COM ddi_get_name(dip), ddi_get_instance(dip),
423*7656SSherry.Moore@Sun.COM ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
4240Sstevel@tonic-gate return (DDI_FAILURE);
4250Sstevel@tonic-gate
4260Sstevel@tonic-gate case DDI_CTLOPS_ATTACH:
4270Sstevel@tonic-gate case DDI_CTLOPS_BTOP:
4280Sstevel@tonic-gate case DDI_CTLOPS_BTOPR:
4290Sstevel@tonic-gate case DDI_CTLOPS_DETACH:
4300Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE:
4310Sstevel@tonic-gate case DDI_CTLOPS_IOMIN:
4320Sstevel@tonic-gate case DDI_CTLOPS_POWER:
4330Sstevel@tonic-gate case DDI_CTLOPS_PTOB:
4340Sstevel@tonic-gate default:
4350Sstevel@tonic-gate /*
4360Sstevel@tonic-gate * The ops that we pass up (default). We pass up memory
4370Sstevel@tonic-gate * allocation oriented ops that we receive - these may be
4380Sstevel@tonic-gate * associated with pseudo HBA drivers below us with target
4390Sstevel@tonic-gate * drivers below them that use ddi memory allocation
4400Sstevel@tonic-gate * interfaces like scsi_alloc_consistent_buf.
4410Sstevel@tonic-gate */
4420Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result));
4430Sstevel@tonic-gate }
4440Sstevel@tonic-gate }
4450Sstevel@tonic-gate
4460Sstevel@tonic-gate static int
tphci_initchild(dev_info_t * dip,dev_info_t * child)4470Sstevel@tonic-gate tphci_initchild(dev_info_t *dip, dev_info_t *child)
4480Sstevel@tonic-gate {
4490Sstevel@tonic-gate _NOTE(ARGUNUSED(dip))
4500Sstevel@tonic-gate ddi_set_name_addr(child, "0");
4510Sstevel@tonic-gate return (DDI_SUCCESS);
4520Sstevel@tonic-gate }
4530Sstevel@tonic-gate
4540Sstevel@tonic-gate /*ARGSUSED*/
4550Sstevel@tonic-gate static int
tphci_uninitchild(dev_info_t * dip,dev_info_t * child)4560Sstevel@tonic-gate tphci_uninitchild(dev_info_t *dip, dev_info_t *child)
4570Sstevel@tonic-gate {
4580Sstevel@tonic-gate ddi_set_name_addr(child, NULL);
4590Sstevel@tonic-gate return (DDI_SUCCESS);
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate
4620Sstevel@tonic-gate static int
tp_decode_name(char * devnm,char ** cname,char ** paddr,char ** guid)4630Sstevel@tonic-gate tp_decode_name(char *devnm, char **cname, char **paddr, char **guid)
4640Sstevel@tonic-gate {
4650Sstevel@tonic-gate char *tmp;
4660Sstevel@tonic-gate
4670Sstevel@tonic-gate i_ddi_parse_name(devnm, cname, paddr, NULL);
4680Sstevel@tonic-gate if ((strcmp(*cname, "tclient") != 0) &&
4690Sstevel@tonic-gate (strcmp(*cname, "tphci") != 0) || *paddr == NULL)
4700Sstevel@tonic-gate return (-1);
4710Sstevel@tonic-gate
4720Sstevel@tonic-gate tmp = strchr(*paddr, ',');
4730Sstevel@tonic-gate if (tmp == NULL || tmp[1] == '\0')
4740Sstevel@tonic-gate return (-1);
4750Sstevel@tonic-gate
4760Sstevel@tonic-gate *guid = tmp + 1;
4770Sstevel@tonic-gate return (0);
4780Sstevel@tonic-gate }
4790Sstevel@tonic-gate
4800Sstevel@tonic-gate static int
tphci_bus_config(dev_info_t * parent,uint_t flags,ddi_bus_config_op_t op,void * arg,dev_info_t ** childp)4810Sstevel@tonic-gate tphci_bus_config(dev_info_t *parent, uint_t flags,
4820Sstevel@tonic-gate ddi_bus_config_op_t op, void *arg, dev_info_t **childp)
4830Sstevel@tonic-gate {
4840Sstevel@tonic-gate _NOTE(ARGUNUSED(flags))
4852155Scth char *cname, *paddr, *guid, *devnm;
4862155Scth mdi_pathinfo_t *pip;
4872155Scth int len, circ, rval;
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate switch (op) {
4900Sstevel@tonic-gate case BUS_CONFIG_ONE:
4910Sstevel@tonic-gate break;
4920Sstevel@tonic-gate case BUS_CONFIG_DRIVER: /* no direct children to configure */
4930Sstevel@tonic-gate case BUS_CONFIG_ALL:
4942155Scth return (NDI_SUCCESS);
4950Sstevel@tonic-gate default:
4962155Scth return (NDI_FAILURE);
4970Sstevel@tonic-gate }
4980Sstevel@tonic-gate
4990Sstevel@tonic-gate /* only implement BUS_CONFIG_ONE */
5000Sstevel@tonic-gate devnm = i_ddi_strdup((char *)arg, KM_SLEEP);
5010Sstevel@tonic-gate len = strlen(devnm) + 1;
5020Sstevel@tonic-gate
5030Sstevel@tonic-gate /* caddr is hardcoded in the form *,<guid> */
5040Sstevel@tonic-gate if (tp_decode_name(devnm, &cname, &paddr, &guid) != 0) {
5050Sstevel@tonic-gate cmn_err(CE_NOTE, "tphci_bus_config -- invalid device %s",
5060Sstevel@tonic-gate (char *)arg);
5070Sstevel@tonic-gate kmem_free(devnm, len);
5082155Scth return (NDI_FAILURE);
5092155Scth }
5102155Scth
5112155Scth mdi_devi_enter(parent, &circ);
5122155Scth rval = mdi_pi_alloc(parent, cname, guid, paddr, 0, &pip);
5132155Scth kmem_free(devnm, len);
5142155Scth if (rval != MDI_SUCCESS) {
5152155Scth cmn_err(CE_NOTE, "tphci_bus_config -- mdi_pi_alloc failed");
5162155Scth mdi_devi_exit(parent, circ);
5172155Scth return (NDI_FAILURE);
5180Sstevel@tonic-gate }
5190Sstevel@tonic-gate
5202155Scth /*
5212155Scth * Hold the path and exit the pHCI while calling mdi_pi_online
5222155Scth * to avoid deadlock with power management of pHCI.
5232155Scth */
5242155Scth mdi_hold_path(pip);
5252155Scth mdi_devi_exit_phci(parent, circ);
5262155Scth rval = mdi_pi_online(pip, 0);
5272155Scth mdi_devi_enter_phci(parent, &circ);
5282155Scth mdi_rele_path(pip);
5290Sstevel@tonic-gate
5302155Scth if (rval != MDI_SUCCESS) {
5310Sstevel@tonic-gate cmn_err(CE_NOTE, "tphci_bus_config -- mdi_pi_online failed");
5320Sstevel@tonic-gate (void) mdi_pi_free(pip, 0);
5332155Scth mdi_devi_exit(parent, circ);
5342155Scth return (NDI_FAILURE);
5350Sstevel@tonic-gate }
5360Sstevel@tonic-gate
5370Sstevel@tonic-gate if (childp) {
5382155Scth *childp = mdi_pi_get_client(pip);
5390Sstevel@tonic-gate ndi_hold_devi(*childp);
5400Sstevel@tonic-gate }
5412155Scth mdi_devi_exit(parent, circ);
5422155Scth
5432155Scth return (NDI_SUCCESS);
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate
5460Sstevel@tonic-gate static int
tphci_bus_unconfig(dev_info_t * parent,uint_t flags,ddi_bus_config_op_t op,void * arg)5470Sstevel@tonic-gate tphci_bus_unconfig(dev_info_t *parent, uint_t flags,
5480Sstevel@tonic-gate ddi_bus_config_op_t op, void *arg)
5490Sstevel@tonic-gate {
5502155Scth int rval = MDI_SUCCESS;
5512155Scth int circ;
5522155Scth mdi_pathinfo_t *pip, *next;
5532155Scth char *devnm, *cname, *caddr;
5540Sstevel@tonic-gate
5550Sstevel@tonic-gate switch (op) {
5560Sstevel@tonic-gate case BUS_UNCONFIG_ONE:
5570Sstevel@tonic-gate devnm = (char *)arg;
5580Sstevel@tonic-gate i_ddi_parse_name(devnm, &cname, &caddr, NULL);
5590Sstevel@tonic-gate if (strcmp(cname, "tclient") != 0)
5602155Scth return (NDI_SUCCESS); /* no such device */
5612155Scth
5622155Scth mdi_devi_enter(parent, &circ);
5630Sstevel@tonic-gate pip = mdi_pi_find(parent, NULL, caddr);
5642155Scth if (pip) {
5652155Scth mdi_hold_path(pip);
5662155Scth mdi_devi_exit_phci(parent, circ);
5672155Scth rval = mdi_pi_offline(pip, NDI_DEVI_REMOVE);
5682155Scth mdi_devi_enter_phci(parent, &circ);
5692155Scth mdi_rele_path(pip);
5702155Scth
5712155Scth if (rval == MDI_SUCCESS)
5722155Scth (void) mdi_pi_free(pip, 0);
5732155Scth }
5742155Scth mdi_devi_exit(parent, circ);
5750Sstevel@tonic-gate return (rval == MDI_SUCCESS ? NDI_SUCCESS : NDI_FAILURE);
5760Sstevel@tonic-gate
5770Sstevel@tonic-gate case BUS_UNCONFIG_ALL:
5780Sstevel@tonic-gate if (flags & NDI_AUTODETACH)
5792155Scth return (NDI_FAILURE);
5800Sstevel@tonic-gate
5812155Scth mdi_devi_enter(parent, &circ);
5822155Scth next = mdi_get_next_client_path(parent, NULL);
5832155Scth while ((pip = next) != NULL) {
5842155Scth next = mdi_get_next_client_path(parent, pip);
5850Sstevel@tonic-gate
5862155Scth mdi_hold_path(pip);
5872155Scth mdi_devi_exit_phci(parent, circ);
5880Sstevel@tonic-gate rval = mdi_pi_offline(pip, NDI_DEVI_REMOVE);
5892155Scth mdi_devi_enter_phci(parent, &circ);
5902155Scth mdi_rele_path(pip);
5912155Scth
5922155Scth if (rval != MDI_SUCCESS)
5930Sstevel@tonic-gate break;
5942155Scth (void) mdi_pi_free(pip, 0);
5950Sstevel@tonic-gate }
5962155Scth mdi_devi_exit(parent, circ);
5970Sstevel@tonic-gate return (rval == MDI_SUCCESS ? NDI_SUCCESS : NDI_FAILURE);
5980Sstevel@tonic-gate
5990Sstevel@tonic-gate case BUS_UNCONFIG_DRIVER: /* nothing to do */
6002155Scth return (NDI_SUCCESS);
6012155Scth
6020Sstevel@tonic-gate default:
6032155Scth return (NDI_FAILURE);
6040Sstevel@tonic-gate }
6050Sstevel@tonic-gate /*NOTREACHED*/
6060Sstevel@tonic-gate }
607