1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * generic mpxio leaf driver 31*7c478bd9Sstevel@tonic-gate */ 32*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/errno.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/uio.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/buf.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/open.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/conf.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate static int tcli_open(dev_t *, int, int, cred_t *); 49*7c478bd9Sstevel@tonic-gate static int tcli_close(dev_t, int, int, cred_t *); 50*7c478bd9Sstevel@tonic-gate static int tcli_read(dev_t, struct uio *, cred_t *); 51*7c478bd9Sstevel@tonic-gate static int tcli_write(dev_t, struct uio *, cred_t *); 52*7c478bd9Sstevel@tonic-gate static int tcli_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 53*7c478bd9Sstevel@tonic-gate static int tcli_attach(dev_info_t *, ddi_attach_cmd_t); 54*7c478bd9Sstevel@tonic-gate static int tcli_detach(dev_info_t *, ddi_detach_cmd_t); 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate static int tcli_info(dev_info_t *, ddi_info_cmd_t, void *, void **); 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate struct dstate { 59*7c478bd9Sstevel@tonic-gate dev_info_t *dip; 60*7c478bd9Sstevel@tonic-gate int oflag; 61*7c478bd9Sstevel@tonic-gate }; 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate static void *dstates; 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate #define INST_TO_MINOR(i) (i) 66*7c478bd9Sstevel@tonic-gate #define MINOR_TO_INST(mn) (mn) 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate static struct cb_ops tcli_cb_ops = { 69*7c478bd9Sstevel@tonic-gate tcli_open, /* open */ 70*7c478bd9Sstevel@tonic-gate tcli_close, /* close */ 71*7c478bd9Sstevel@tonic-gate nodev, /* strategy */ 72*7c478bd9Sstevel@tonic-gate nodev, /* print */ 73*7c478bd9Sstevel@tonic-gate nodev, /* dump */ 74*7c478bd9Sstevel@tonic-gate tcli_read, /* read */ 75*7c478bd9Sstevel@tonic-gate tcli_write, /* write */ 76*7c478bd9Sstevel@tonic-gate tcli_ioctl, /* ioctl */ 77*7c478bd9Sstevel@tonic-gate nodev, /* devmap */ 78*7c478bd9Sstevel@tonic-gate nodev, /* mmap */ 79*7c478bd9Sstevel@tonic-gate nodev, /* segmap */ 80*7c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 81*7c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 82*7c478bd9Sstevel@tonic-gate NULL, /* streamtab */ 83*7c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* flag */ 84*7c478bd9Sstevel@tonic-gate CB_REV, /* cb_rev */ 85*7c478bd9Sstevel@tonic-gate nodev, /* aread */ 86*7c478bd9Sstevel@tonic-gate nodev /* awrite */ 87*7c478bd9Sstevel@tonic-gate }; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate static struct dev_ops tcli_ops = { 91*7c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 92*7c478bd9Sstevel@tonic-gate 0, /* refcnt */ 93*7c478bd9Sstevel@tonic-gate tcli_info, /* getinfo */ 94*7c478bd9Sstevel@tonic-gate nulldev, /* identify */ 95*7c478bd9Sstevel@tonic-gate nulldev, /* probe */ 96*7c478bd9Sstevel@tonic-gate tcli_attach, /* attach */ 97*7c478bd9Sstevel@tonic-gate tcli_detach, /* detach */ 98*7c478bd9Sstevel@tonic-gate nodev, /* reset */ 99*7c478bd9Sstevel@tonic-gate &tcli_cb_ops, /* driver ops */ 100*7c478bd9Sstevel@tonic-gate (struct bus_ops *)0, /* bus ops */ 101*7c478bd9Sstevel@tonic-gate NULL /* power */ 102*7c478bd9Sstevel@tonic-gate }; 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 105*7c478bd9Sstevel@tonic-gate &mod_driverops, 106*7c478bd9Sstevel@tonic-gate "vhci client test driver %I%", 107*7c478bd9Sstevel@tonic-gate &tcli_ops 108*7c478bd9Sstevel@tonic-gate }; 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 111*7c478bd9Sstevel@tonic-gate MODREV_1, &modldrv, NULL 112*7c478bd9Sstevel@tonic-gate }; 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate int 115*7c478bd9Sstevel@tonic-gate _init(void) 116*7c478bd9Sstevel@tonic-gate { 117*7c478bd9Sstevel@tonic-gate int e; 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate if ((e = ddi_soft_state_init(&dstates, 120*7c478bd9Sstevel@tonic-gate sizeof (struct dstate), 0)) != 0) { 121*7c478bd9Sstevel@tonic-gate return (e); 122*7c478bd9Sstevel@tonic-gate } 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate if ((e = mod_install(&modlinkage)) != 0) { 125*7c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&dstates); 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate return (e); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate int 132*7c478bd9Sstevel@tonic-gate _fini(void) 133*7c478bd9Sstevel@tonic-gate { 134*7c478bd9Sstevel@tonic-gate int e; 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate if ((e = mod_remove(&modlinkage)) != 0) { 137*7c478bd9Sstevel@tonic-gate return (e); 138*7c478bd9Sstevel@tonic-gate } 139*7c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&dstates); 140*7c478bd9Sstevel@tonic-gate return (e); 141*7c478bd9Sstevel@tonic-gate } 142*7c478bd9Sstevel@tonic-gate 143*7c478bd9Sstevel@tonic-gate int 144*7c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 145*7c478bd9Sstevel@tonic-gate { 146*7c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 147*7c478bd9Sstevel@tonic-gate } 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 150*7c478bd9Sstevel@tonic-gate static int 151*7c478bd9Sstevel@tonic-gate tcli_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 152*7c478bd9Sstevel@tonic-gate { 153*7c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(devi); 154*7c478bd9Sstevel@tonic-gate struct dstate *dstatep; 155*7c478bd9Sstevel@tonic-gate int rval; 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate if (cmd != DDI_ATTACH) 158*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(dstates, instance) != DDI_SUCCESS) { 161*7c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: can't allocate state\n", 162*7c478bd9Sstevel@tonic-gate ddi_get_name(devi), instance); 163*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate dstatep = ddi_get_soft_state(dstates, instance); 167*7c478bd9Sstevel@tonic-gate dstatep->dip = devi; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate rval = ddi_create_minor_node(devi, "client", S_IFCHR, 170*7c478bd9Sstevel@tonic-gate (INST_TO_MINOR(instance)), DDI_PSEUDO, NULL); 171*7c478bd9Sstevel@tonic-gate if (rval == DDI_FAILURE) { 172*7c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 173*7c478bd9Sstevel@tonic-gate ddi_soft_state_free(dstates, instance); 174*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: can't create minor nodes", 175*7c478bd9Sstevel@tonic-gate ddi_get_name(devi), instance); 176*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate ddi_report_dev(devi); 180*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 184*7c478bd9Sstevel@tonic-gate static int 185*7c478bd9Sstevel@tonic-gate tcli_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 186*7c478bd9Sstevel@tonic-gate { 187*7c478bd9Sstevel@tonic-gate int instance; 188*7c478bd9Sstevel@tonic-gate 189*7c478bd9Sstevel@tonic-gate if (cmd != DDI_DETACH) 190*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 191*7c478bd9Sstevel@tonic-gate 192*7c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 193*7c478bd9Sstevel@tonic-gate instance = ddi_get_instance(devi); 194*7c478bd9Sstevel@tonic-gate ddi_soft_state_free(dstates, instance); 195*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 196*7c478bd9Sstevel@tonic-gate } 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate /* ARGSUSED */ 199*7c478bd9Sstevel@tonic-gate static int 200*7c478bd9Sstevel@tonic-gate tcli_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 201*7c478bd9Sstevel@tonic-gate { 202*7c478bd9Sstevel@tonic-gate dev_t dev; 203*7c478bd9Sstevel@tonic-gate int instance; 204*7c478bd9Sstevel@tonic-gate 205*7c478bd9Sstevel@tonic-gate if (infocmd != DDI_INFO_DEVT2INSTANCE) 206*7c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 207*7c478bd9Sstevel@tonic-gate 208*7c478bd9Sstevel@tonic-gate dev = (dev_t)arg; 209*7c478bd9Sstevel@tonic-gate instance = MINOR_TO_INST(getminor(dev)); 210*7c478bd9Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 211*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 216*7c478bd9Sstevel@tonic-gate static int 217*7c478bd9Sstevel@tonic-gate tcli_open(dev_t *devp, int flag, int otyp, cred_t *cred) 218*7c478bd9Sstevel@tonic-gate { 219*7c478bd9Sstevel@tonic-gate minor_t minor; 220*7c478bd9Sstevel@tonic-gate struct dstate *dstatep; 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate if (otyp != OTYP_BLK && otyp != OTYP_CHR) 223*7c478bd9Sstevel@tonic-gate return (EINVAL); 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate minor = getminor(*devp); 226*7c478bd9Sstevel@tonic-gate if ((dstatep = ddi_get_soft_state(dstates, 227*7c478bd9Sstevel@tonic-gate MINOR_TO_INST(minor))) == NULL) 228*7c478bd9Sstevel@tonic-gate return (ENXIO); 229*7c478bd9Sstevel@tonic-gate 230*7c478bd9Sstevel@tonic-gate dstatep->oflag = 1; 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate return (0); 233*7c478bd9Sstevel@tonic-gate } 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 236*7c478bd9Sstevel@tonic-gate static int 237*7c478bd9Sstevel@tonic-gate tcli_close(dev_t dev, int flag, int otyp, cred_t *cred) 238*7c478bd9Sstevel@tonic-gate { 239*7c478bd9Sstevel@tonic-gate struct dstate *dstatep; 240*7c478bd9Sstevel@tonic-gate minor_t minor = getminor(dev); 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate if (otyp != OTYP_BLK && otyp != OTYP_CHR) 243*7c478bd9Sstevel@tonic-gate return (EINVAL); 244*7c478bd9Sstevel@tonic-gate 245*7c478bd9Sstevel@tonic-gate dstatep = ddi_get_soft_state(dstates, MINOR_TO_INST(minor)); 246*7c478bd9Sstevel@tonic-gate 247*7c478bd9Sstevel@tonic-gate if (dstatep == NULL) 248*7c478bd9Sstevel@tonic-gate return (ENXIO); 249*7c478bd9Sstevel@tonic-gate 250*7c478bd9Sstevel@tonic-gate dstatep->oflag = 0; 251*7c478bd9Sstevel@tonic-gate 252*7c478bd9Sstevel@tonic-gate return (0); 253*7c478bd9Sstevel@tonic-gate } 254*7c478bd9Sstevel@tonic-gate 255*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 256*7c478bd9Sstevel@tonic-gate static int 257*7c478bd9Sstevel@tonic-gate tcli_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 258*7c478bd9Sstevel@tonic-gate int *rvalp) 259*7c478bd9Sstevel@tonic-gate { 260*7c478bd9Sstevel@tonic-gate struct dstate *dstatep; 261*7c478bd9Sstevel@tonic-gate int instance; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate instance = MINOR_TO_INST(getminor(dev)); 264*7c478bd9Sstevel@tonic-gate dstatep = ddi_get_soft_state(dstates, instance); 265*7c478bd9Sstevel@tonic-gate 266*7c478bd9Sstevel@tonic-gate if (dstatep == NULL) 267*7c478bd9Sstevel@tonic-gate return (ENXIO); 268*7c478bd9Sstevel@tonic-gate 269*7c478bd9Sstevel@tonic-gate return (0); 270*7c478bd9Sstevel@tonic-gate } 271*7c478bd9Sstevel@tonic-gate 272*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 273*7c478bd9Sstevel@tonic-gate static int 274*7c478bd9Sstevel@tonic-gate tcli_read(dev_t dev, struct uio *uiop, cred_t *credp) 275*7c478bd9Sstevel@tonic-gate { 276*7c478bd9Sstevel@tonic-gate return (0); 277*7c478bd9Sstevel@tonic-gate } 278*7c478bd9Sstevel@tonic-gate 279*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 280*7c478bd9Sstevel@tonic-gate static int 281*7c478bd9Sstevel@tonic-gate tcli_write(dev_t dev, struct uio *uiop, cred_t *credp) 282*7c478bd9Sstevel@tonic-gate { 283*7c478bd9Sstevel@tonic-gate return (0); 284*7c478bd9Sstevel@tonic-gate } 285