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 /* 221961Scth * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * The tvhci driver can be used to exercise the mpxio framework together 300Sstevel@tonic-gate * with tphci/tclient. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/conf.h> 340Sstevel@tonic-gate #include <sys/file.h> 350Sstevel@tonic-gate #include <sys/ddi.h> 360Sstevel@tonic-gate #include <sys/sunddi.h> 370Sstevel@tonic-gate #include <sys/scsi/scsi.h> 380Sstevel@tonic-gate #include <sys/scsi/impl/scsi_reset_notify.h> 390Sstevel@tonic-gate #include <sys/sunmdi.h> 400Sstevel@tonic-gate #include <sys/mdi_impldefs.h> 410Sstevel@tonic-gate #include <sys/disp.h> 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* cb_ops entry points */ 440Sstevel@tonic-gate static int tvhci_open(dev_t *, int, int, cred_t *); 450Sstevel@tonic-gate static int tvhci_close(dev_t, int, int, cred_t *); 460Sstevel@tonic-gate static int tvhci_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 470Sstevel@tonic-gate static int tvhci_attach(dev_info_t *, ddi_attach_cmd_t); 480Sstevel@tonic-gate static int tvhci_detach(dev_info_t *, ddi_detach_cmd_t); 490Sstevel@tonic-gate static int tvhci_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 tvhci_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, 530Sstevel@tonic-gate void *); 540Sstevel@tonic-gate static int tvhci_initchild(dev_info_t *, dev_info_t *); 550Sstevel@tonic-gate static int tvhci_uninitchild(dev_info_t *, dev_info_t *); 560Sstevel@tonic-gate static int tvhci_bus_config(dev_info_t *, uint_t, ddi_bus_config_op_t, void *, 570Sstevel@tonic-gate dev_info_t **); 580Sstevel@tonic-gate static int tvhci_bus_unconfig(dev_info_t *, uint_t, ddi_bus_config_op_t, 590Sstevel@tonic-gate void *); 600Sstevel@tonic-gate static int tvhci_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 /* vhci ops */ 640Sstevel@tonic-gate static int tvhci_pi_init(dev_info_t *, mdi_pathinfo_t *, int); 650Sstevel@tonic-gate static int tvhci_pi_uninit(dev_info_t *, mdi_pathinfo_t *, int); 660Sstevel@tonic-gate static int tvhci_pi_state_change(dev_info_t *, mdi_pathinfo_t *, 670Sstevel@tonic-gate mdi_pathinfo_state_t, uint32_t, int); 680Sstevel@tonic-gate static int tvhci_failover(dev_info_t *, dev_info_t *, int); 690Sstevel@tonic-gate 700Sstevel@tonic-gate static void *tvhci_state; 710Sstevel@tonic-gate struct tvhci_state { 720Sstevel@tonic-gate dev_info_t *dip; 730Sstevel@tonic-gate }; 740Sstevel@tonic-gate 750Sstevel@tonic-gate static mdi_vhci_ops_t tvhci_opinfo = { 760Sstevel@tonic-gate MDI_VHCI_OPS_REV, 770Sstevel@tonic-gate tvhci_pi_init, 780Sstevel@tonic-gate tvhci_pi_uninit, 790Sstevel@tonic-gate tvhci_pi_state_change, 800Sstevel@tonic-gate tvhci_failover 810Sstevel@tonic-gate }; 820Sstevel@tonic-gate 830Sstevel@tonic-gate static struct cb_ops tvhci_cb_ops = { 840Sstevel@tonic-gate tvhci_open, /* open */ 850Sstevel@tonic-gate tvhci_close, /* close */ 860Sstevel@tonic-gate nodev, /* strategy */ 870Sstevel@tonic-gate nodev, /* print */ 880Sstevel@tonic-gate nodev, /* dump */ 890Sstevel@tonic-gate nodev, /* read */ 900Sstevel@tonic-gate nodev, /* write */ 910Sstevel@tonic-gate tvhci_ioctl, /* ioctl */ 920Sstevel@tonic-gate nodev, /* devmap */ 930Sstevel@tonic-gate nodev, /* mmap */ 940Sstevel@tonic-gate nodev, /* segmap */ 950Sstevel@tonic-gate nochpoll, /* chpoll */ 960Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 970Sstevel@tonic-gate 0, /* streamtab */ 980Sstevel@tonic-gate D_NEW | D_MP, /* cb_flag */ 990Sstevel@tonic-gate CB_REV, /* rev */ 1000Sstevel@tonic-gate nodev, /* aread */ 1010Sstevel@tonic-gate nodev /* awrite */ 1020Sstevel@tonic-gate }; 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate static struct bus_ops tvhci_bus_ops = { 1050Sstevel@tonic-gate BUSO_REV, /* busops_rev */ 1060Sstevel@tonic-gate nullbusmap, /* bus_map */ 1070Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 1080Sstevel@tonic-gate NULL, /* bus_add_interspec */ 1090Sstevel@tonic-gate NULL, /* bus_remove_interspec */ 1100Sstevel@tonic-gate i_ddi_map_fault, /* bus_map_fault */ 1110Sstevel@tonic-gate ddi_no_dma_map, /* bus_dma_map */ 1120Sstevel@tonic-gate ddi_no_dma_allochdl, /* bus_dma_allochdl */ 1130Sstevel@tonic-gate NULL, /* bus_dma_freehdl */ 1140Sstevel@tonic-gate NULL, /* bus_dma_bindhdl */ 1150Sstevel@tonic-gate NULL, /* bus_dma_unbindhdl */ 1160Sstevel@tonic-gate NULL, /* bus_dma_flush */ 1170Sstevel@tonic-gate NULL, /* bus_dma_win */ 1180Sstevel@tonic-gate NULL, /* bus_dma_ctl */ 1190Sstevel@tonic-gate tvhci_ctl, /* bus_ctl */ 1200Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 1210Sstevel@tonic-gate NULL, /* bus_get_eventcookie */ 1220Sstevel@tonic-gate NULL, /* bus_add_eventcall */ 1230Sstevel@tonic-gate NULL, /* bus_remove_event */ 1240Sstevel@tonic-gate NULL, /* bus_post_event */ 1250Sstevel@tonic-gate NULL, /* bus_intr_ctl */ 1260Sstevel@tonic-gate tvhci_bus_config, /* bus_config */ 1270Sstevel@tonic-gate tvhci_bus_unconfig, /* bus_unconfig */ 1280Sstevel@tonic-gate NULL, /* bus_fm_init */ 1290Sstevel@tonic-gate NULL, /* bus_fm_fini */ 1300Sstevel@tonic-gate NULL, /* bus_fm_access_enter */ 1310Sstevel@tonic-gate NULL, /* bus_fm_access_exit */ 1320Sstevel@tonic-gate NULL, /* bus_power */ 1330Sstevel@tonic-gate tvhci_intr_op /* bus_intr_op */ 1340Sstevel@tonic-gate }; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate static struct dev_ops tvhci_ops = { 1370Sstevel@tonic-gate DEVO_REV, 1380Sstevel@tonic-gate 0, 1390Sstevel@tonic-gate tvhci_getinfo, 1400Sstevel@tonic-gate nulldev, /* identify */ 1410Sstevel@tonic-gate nulldev, /* probe */ 1420Sstevel@tonic-gate tvhci_attach, /* attach and detach are mandatory */ 1430Sstevel@tonic-gate tvhci_detach, 1440Sstevel@tonic-gate nodev, /* reset */ 1450Sstevel@tonic-gate &tvhci_cb_ops, /* cb_ops */ 1460Sstevel@tonic-gate &tvhci_bus_ops, /* bus_ops */ 1470Sstevel@tonic-gate NULL, /* power */ 1480Sstevel@tonic-gate }; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate extern struct mod_ops mod_driverops; 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate static struct modldrv modldrv = { 1530Sstevel@tonic-gate &mod_driverops, 1540Sstevel@tonic-gate "test vhci driver %I%", 1550Sstevel@tonic-gate &tvhci_ops 1560Sstevel@tonic-gate }; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate static struct modlinkage modlinkage = { 1590Sstevel@tonic-gate MODREV_1, 1600Sstevel@tonic-gate &modldrv, 1610Sstevel@tonic-gate NULL 1620Sstevel@tonic-gate }; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate int 1650Sstevel@tonic-gate _init(void) 1660Sstevel@tonic-gate { 1670Sstevel@tonic-gate int rval; 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate if ((rval = ddi_soft_state_init(&tvhci_state, 1700Sstevel@tonic-gate sizeof (struct tvhci_state), 2)) != 0) { 1710Sstevel@tonic-gate return (rval); 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate if ((rval = mod_install(&modlinkage)) != 0) { 1750Sstevel@tonic-gate ddi_soft_state_fini(&tvhci_state); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate return (rval); 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate int 1820Sstevel@tonic-gate _fini(void) 1830Sstevel@tonic-gate { 1840Sstevel@tonic-gate int rval; 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate /* 1870Sstevel@tonic-gate * don't start cleaning up until we know that the module remove 1880Sstevel@tonic-gate * has worked -- if this works, then we know that each instance 1890Sstevel@tonic-gate * has successfully been detached 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate if ((rval = mod_remove(&modlinkage)) != 0) { 1920Sstevel@tonic-gate return (rval); 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate ddi_soft_state_fini(&tvhci_state); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate return (rval); 1980Sstevel@tonic-gate } 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate int 2010Sstevel@tonic-gate _info(struct modinfo *modinfop) 2020Sstevel@tonic-gate { 2030Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* ARGSUSED */ 2070Sstevel@tonic-gate static int 2080Sstevel@tonic-gate tvhci_open(dev_t *devp, int flag, int otype, cred_t *credp) 2090Sstevel@tonic-gate { 2100Sstevel@tonic-gate struct tvhci_state *vhci; 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate if (otype != OTYP_CHR) { 2130Sstevel@tonic-gate return (EINVAL); 2140Sstevel@tonic-gate } 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate vhci = ddi_get_soft_state(tvhci_state, getminor(*devp)); 2170Sstevel@tonic-gate if (vhci == NULL) { 2180Sstevel@tonic-gate return (ENXIO); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate return (0); 2220Sstevel@tonic-gate } 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate /* ARGSUSED */ 2260Sstevel@tonic-gate static int 2270Sstevel@tonic-gate tvhci_close(dev_t dev, int flag, int otype, cred_t *credp) 2280Sstevel@tonic-gate { 2290Sstevel@tonic-gate struct tvhci_state *vhci; 2300Sstevel@tonic-gate if (otype != OTYP_CHR) { 2310Sstevel@tonic-gate return (EINVAL); 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate vhci = ddi_get_soft_state(tvhci_state, getminor(dev)); 2350Sstevel@tonic-gate if (vhci == NULL) { 2360Sstevel@tonic-gate return (ENXIO); 2370Sstevel@tonic-gate } 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate return (0); 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate /* ARGSUSED */ 2430Sstevel@tonic-gate static int 2440Sstevel@tonic-gate tvhci_ioctl(dev_t dev, int cmd, intptr_t data, int mode, 2450Sstevel@tonic-gate cred_t *credp, int *rval) 2460Sstevel@tonic-gate { 2470Sstevel@tonic-gate return (0); 2480Sstevel@tonic-gate } 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate /* 2510Sstevel@tonic-gate * attach the module 2520Sstevel@tonic-gate */ 2530Sstevel@tonic-gate static int 2540Sstevel@tonic-gate tvhci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 2550Sstevel@tonic-gate { 2560Sstevel@tonic-gate char *vclass; 2570Sstevel@tonic-gate int instance, vhci_regis = 0; 2580Sstevel@tonic-gate struct tvhci_state *vhci = NULL; 2590Sstevel@tonic-gate dev_info_t *pdip; 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate instance = ddi_get_instance(dip); 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate switch (cmd) { 2640Sstevel@tonic-gate case DDI_ATTACH: 2650Sstevel@tonic-gate break; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate case DDI_RESUME: 2680Sstevel@tonic-gate case DDI_PM_RESUME: 2690Sstevel@tonic-gate return (0); /* nothing to do */ 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate default: 2720Sstevel@tonic-gate return (DDI_FAILURE); 2730Sstevel@tonic-gate } 2740Sstevel@tonic-gate 2750Sstevel@tonic-gate /* 2760Sstevel@tonic-gate * Allocate vhci data structure. 2770Sstevel@tonic-gate */ 2780Sstevel@tonic-gate if (ddi_soft_state_zalloc(tvhci_state, instance) != DDI_SUCCESS) { 2790Sstevel@tonic-gate return (DDI_FAILURE); 2800Sstevel@tonic-gate } 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate vhci = ddi_get_soft_state(tvhci_state, instance); 2830Sstevel@tonic-gate ASSERT(vhci != NULL); 2840Sstevel@tonic-gate vhci->dip = dip; 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* parent must be /pshot */ 2870Sstevel@tonic-gate pdip = ddi_get_parent(dip); 2880Sstevel@tonic-gate if (strcmp(ddi_driver_name(pdip), "pshot") != 0 || 2890Sstevel@tonic-gate ddi_get_parent(pdip) != ddi_root_node()) { 2900Sstevel@tonic-gate cmn_err(CE_NOTE, "tvhci must be under /pshot/"); 2910Sstevel@tonic-gate goto attach_fail; 2920Sstevel@tonic-gate } 2930Sstevel@tonic-gate 2940Sstevel@tonic-gate /* 2950Sstevel@tonic-gate * XXX add mpxio-disable property. need to remove the check 2960Sstevel@tonic-gate * from the framework 2970Sstevel@tonic-gate */ 2980Sstevel@tonic-gate (void) ddi_prop_update_string(DDI_DEV_T_NONE, dip, 2990Sstevel@tonic-gate "mpxio-disable", "no"); 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate /* bus_addr is the <vhci_class> */ 3020Sstevel@tonic-gate vclass = ddi_get_name_addr(dip); 3030Sstevel@tonic-gate if (vclass == NULL || vclass[1] == '\0') { 3040Sstevel@tonic-gate cmn_err(CE_NOTE, "tvhci invalid vhci class"); 3050Sstevel@tonic-gate goto attach_fail; 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate /* 3090Sstevel@tonic-gate * Attach this instance with the mpxio framework 3100Sstevel@tonic-gate */ 3110Sstevel@tonic-gate if (mdi_vhci_register(vclass, dip, &tvhci_opinfo, 0) != MDI_SUCCESS) { 3120Sstevel@tonic-gate cmn_err(CE_WARN, "%s mdi_vhci_register failed", 3130Sstevel@tonic-gate ddi_node_name(dip)); 3140Sstevel@tonic-gate goto attach_fail; 3150Sstevel@tonic-gate } 3160Sstevel@tonic-gate vhci_regis++; 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate if (ddi_create_minor_node(dip, "devctl", S_IFCHR, 3190Sstevel@tonic-gate instance, DDI_NT_SCSI_NEXUS, 0) != DDI_SUCCESS) { 3200Sstevel@tonic-gate cmn_err(CE_NOTE, "%s ddi_create_minor_node failed", 3210Sstevel@tonic-gate ddi_node_name(dip)); 3220Sstevel@tonic-gate goto attach_fail; 3230Sstevel@tonic-gate } 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1); 3260Sstevel@tonic-gate ddi_report_dev(dip); 3270Sstevel@tonic-gate return (DDI_SUCCESS); 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate attach_fail: 3300Sstevel@tonic-gate if (vhci_regis) 3310Sstevel@tonic-gate (void) mdi_vhci_unregister(dip, 0); 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate ddi_soft_state_free(tvhci_state, instance); 3340Sstevel@tonic-gate return (DDI_FAILURE); 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate /*ARGSUSED*/ 3390Sstevel@tonic-gate static int 3400Sstevel@tonic-gate tvhci_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 3410Sstevel@tonic-gate { 3420Sstevel@tonic-gate int instance = ddi_get_instance(dip); 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate switch (cmd) { 3450Sstevel@tonic-gate case DDI_DETACH: 3460Sstevel@tonic-gate break; 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate case DDI_SUSPEND: 3490Sstevel@tonic-gate case DDI_PM_SUSPEND: 3500Sstevel@tonic-gate return (0); /* nothing to do */ 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate default: 3530Sstevel@tonic-gate return (DDI_FAILURE); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate if (mdi_vhci_unregister(dip, 0) != MDI_SUCCESS) 3570Sstevel@tonic-gate return (DDI_FAILURE); 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 3600Sstevel@tonic-gate ddi_soft_state_free(tvhci_state, instance); 3610Sstevel@tonic-gate 3620Sstevel@tonic-gate return (DDI_SUCCESS); 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate /* 3660Sstevel@tonic-gate * tvhci_getinfo() 3670Sstevel@tonic-gate * Given the device number, return the devinfo pointer or the 3680Sstevel@tonic-gate * instance number. 3690Sstevel@tonic-gate * Note: always succeed DDI_INFO_DEVT2INSTANCE, even before attach. 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate /*ARGSUSED*/ 3730Sstevel@tonic-gate static int 3740Sstevel@tonic-gate tvhci_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 3750Sstevel@tonic-gate { 3760Sstevel@tonic-gate struct tvhci_state *vhci; 3770Sstevel@tonic-gate int instance = getminor((dev_t)arg); 3780Sstevel@tonic-gate 3790Sstevel@tonic-gate switch (cmd) { 3800Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 3810Sstevel@tonic-gate vhci = ddi_get_soft_state(tvhci_state, instance); 3820Sstevel@tonic-gate if (vhci != NULL) 3830Sstevel@tonic-gate *result = vhci->dip; 3840Sstevel@tonic-gate else { 3850Sstevel@tonic-gate *result = NULL; 3860Sstevel@tonic-gate return (DDI_FAILURE); 3870Sstevel@tonic-gate } 3880Sstevel@tonic-gate break; 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 3910Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 3920Sstevel@tonic-gate break; 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate default: 3950Sstevel@tonic-gate return (DDI_FAILURE); 3960Sstevel@tonic-gate } 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate return (DDI_SUCCESS); 3990Sstevel@tonic-gate } 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate /*ARGSUSED*/ 4020Sstevel@tonic-gate static int 4030Sstevel@tonic-gate tvhci_pi_init(dev_info_t *vdip, mdi_pathinfo_t *pip, int flags) 4040Sstevel@tonic-gate { 4050Sstevel@tonic-gate return (MDI_SUCCESS); 4060Sstevel@tonic-gate } 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate /*ARGSUSED*/ 4090Sstevel@tonic-gate static int 4100Sstevel@tonic-gate tvhci_pi_uninit(dev_info_t *vdip, mdi_pathinfo_t *pip, int flags) 4110Sstevel@tonic-gate { 4120Sstevel@tonic-gate return (MDI_SUCCESS); 4130Sstevel@tonic-gate } 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate /*ARGSUSED*/ 4160Sstevel@tonic-gate static int 4170Sstevel@tonic-gate tvhci_pi_state_change(dev_info_t *vdip, mdi_pathinfo_t *pip, 4180Sstevel@tonic-gate mdi_pathinfo_state_t state, uint32_t ext_state, int flags) 4190Sstevel@tonic-gate { 4200Sstevel@tonic-gate return (MDI_SUCCESS); 4210Sstevel@tonic-gate } 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate /*ARGSUSED*/ 4240Sstevel@tonic-gate static int 4250Sstevel@tonic-gate tvhci_failover(dev_info_t *vdip, dev_info_t *cdip, int flags) 4260Sstevel@tonic-gate { 4270Sstevel@tonic-gate return (MDI_SUCCESS); 4280Sstevel@tonic-gate } 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * Interrupt stuff. NO OP for pseudo drivers. 4320Sstevel@tonic-gate */ 4330Sstevel@tonic-gate /*ARGSUSED*/ 4340Sstevel@tonic-gate static int 4350Sstevel@tonic-gate tvhci_intr_op(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op, 4360Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 4370Sstevel@tonic-gate { 4380Sstevel@tonic-gate return (DDI_FAILURE); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /*ARGSUSED*/ 4420Sstevel@tonic-gate static int 4430Sstevel@tonic-gate tvhci_ctl(dev_info_t *dip, dev_info_t *rdip, 4440Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 4450Sstevel@tonic-gate { 4460Sstevel@tonic-gate switch (ctlop) { 4470Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 4480Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 4490Sstevel@tonic-gate return (DDI_FAILURE); 4500Sstevel@tonic-gate cmn_err(CE_CONT, "?tvhci-device: %s%d\n", 4510Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip)); 4520Sstevel@tonic-gate return (DDI_SUCCESS); 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 4550Sstevel@tonic-gate { 4560Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 4570Sstevel@tonic-gate return (tvhci_initchild(dip, child)); 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 4610Sstevel@tonic-gate { 4620Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 4630Sstevel@tonic-gate return (tvhci_uninitchild(dip, child)); 4640Sstevel@tonic-gate } 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 4670Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 4680Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 4690Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 4700Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 4710Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 4720Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 4730Sstevel@tonic-gate case DDI_CTLOPS_POKE: 4740Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 4750Sstevel@tonic-gate /* 4760Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be called 4770Sstevel@tonic-gate * by a pseudo driver. So we whine when we're called. 4780Sstevel@tonic-gate */ 4790Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n", 4800Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 4810Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip)); 4820Sstevel@tonic-gate return (DDI_FAILURE); 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate case DDI_CTLOPS_ATTACH: 4850Sstevel@tonic-gate case DDI_CTLOPS_BTOP: 4860Sstevel@tonic-gate case DDI_CTLOPS_BTOPR: 4870Sstevel@tonic-gate case DDI_CTLOPS_DETACH: 4880Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE: 4890Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 4900Sstevel@tonic-gate case DDI_CTLOPS_POWER: 4910Sstevel@tonic-gate case DDI_CTLOPS_PTOB: 4920Sstevel@tonic-gate default: 4930Sstevel@tonic-gate /* 4940Sstevel@tonic-gate * The ops that we pass up (default). We pass up memory 4950Sstevel@tonic-gate * allocation oriented ops that we receive - these may be 4960Sstevel@tonic-gate * associated with pseudo HBA drivers below us with target 4970Sstevel@tonic-gate * drivers below them that use ddi memory allocation 4980Sstevel@tonic-gate * interfaces like scsi_alloc_consistent_buf. 4990Sstevel@tonic-gate */ 5000Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 5010Sstevel@tonic-gate } 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate /* set devi_addr to "g<guid>" */ 5050Sstevel@tonic-gate static int 5060Sstevel@tonic-gate tvhci_initchild(dev_info_t *dip, dev_info_t *child) 5070Sstevel@tonic-gate { 5080Sstevel@tonic-gate _NOTE(ARGUNUSED(dip)) 5090Sstevel@tonic-gate char *guid, *addr; 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 5120Sstevel@tonic-gate MDI_CLIENT_GUID_PROP, &guid) != DDI_SUCCESS) { 5130Sstevel@tonic-gate cmn_err(CE_NOTE, "tvhci_initchild - no guid property"); 5140Sstevel@tonic-gate return (DDI_FAILURE); 5150Sstevel@tonic-gate } 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate addr = kmem_alloc(MAXNAMELEN, KM_SLEEP); 5180Sstevel@tonic-gate (void) snprintf(addr, MAXNAMELEN, "g%s", guid); 5190Sstevel@tonic-gate ddi_set_name_addr(child, addr); 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate kmem_free(addr, MAXNAMELEN); 5220Sstevel@tonic-gate ddi_prop_free(guid); 5230Sstevel@tonic-gate return (DDI_SUCCESS); 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate /*ARGSUSED*/ 5270Sstevel@tonic-gate static int 5280Sstevel@tonic-gate tvhci_uninitchild(dev_info_t *dip, dev_info_t *child) 5290Sstevel@tonic-gate { 5300Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 5310Sstevel@tonic-gate return (DDI_SUCCESS); 5320Sstevel@tonic-gate } 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate /* form paddr by cname@<phci_inst>,<guid> */ 5350Sstevel@tonic-gate static char * 5360Sstevel@tonic-gate tvh_get_phci_devname(char *cname, char *guid, 5370Sstevel@tonic-gate dev_info_t *pdip, char *pname, int len) 5380Sstevel@tonic-gate { 5390Sstevel@tonic-gate (void) snprintf(pname, len, "%s@%d,%s", 5400Sstevel@tonic-gate cname, ddi_get_instance(pdip), guid); 5410Sstevel@tonic-gate return (pname); 5420Sstevel@tonic-gate } 5430Sstevel@tonic-gate 544*2155Scth /* 545*2155Scth * Return a pointer to the guid part of the devnm. 546*2155Scth * devnm format is "nodename@busaddr", busaddr format is "gGUID". 547*2155Scth */ 548*2155Scth static char * 549*2155Scth tvhci_devnm_to_guid(char *devnm) 5500Sstevel@tonic-gate { 551*2155Scth char *cp = devnm; 5520Sstevel@tonic-gate 553*2155Scth if (devnm == NULL) 554*2155Scth return (NULL); 5550Sstevel@tonic-gate 556*2155Scth while (*cp != '\0' && *cp != '@') 557*2155Scth cp++; 558*2155Scth if (*cp == '@' && *(cp + 1) == 'g') 559*2155Scth return (cp + 2); 560*2155Scth return (NULL); 5610Sstevel@tonic-gate } 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate static int 564*2155Scth tvhci_bus_config(dev_info_t *pdip, uint_t flags, ddi_bus_config_op_t op, 565*2155Scth void *arg, dev_info_t **child) 5660Sstevel@tonic-gate { 567*2155Scth char *guid; 5680Sstevel@tonic-gate 569*2155Scth if (op == BUS_CONFIG_ONE || op == BUS_UNCONFIG_ONE) 570*2155Scth guid = tvhci_devnm_to_guid((char *)arg); 571*2155Scth else 572*2155Scth guid = NULL; 5730Sstevel@tonic-gate 574*2155Scth if (mdi_vhci_bus_config(pdip, flags, op, arg, child, guid) 575*2155Scth == MDI_SUCCESS) 576*2155Scth return (NDI_SUCCESS); 577*2155Scth else 578*2155Scth return (NDI_FAILURE); 5790Sstevel@tonic-gate } 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate static int 5820Sstevel@tonic-gate tvhci_bus_unconfig(dev_info_t *parent, uint_t flags, 5830Sstevel@tonic-gate ddi_bus_config_op_t op, void *arg) 5840Sstevel@tonic-gate { 585*2155Scth return (ndi_busop_bus_unconfig(parent, flags, op, arg)); 5860Sstevel@tonic-gate } 587