1 /* $NetBSD: uk.c,v 1.15 1996/03/17 00:59:57 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1994 Charles Hannum. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Charles Hannum. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 /* 33 * Dummy driver for a device we can't identify. 34 * Originally by Julian Elischer (julian@tfs.com) 35 */ 36 37 #include <sys/types.h> 38 #include <sys/param.h> 39 #include <sys/errno.h> 40 #include <sys/ioctl.h> 41 #include <sys/device.h> 42 43 #include <scsi/scsi_all.h> 44 #include <scsi/scsiconf.h> 45 46 #define UKUNIT(z) (minor(z)) 47 48 struct uk_softc { 49 struct device sc_dev; 50 51 struct scsi_link *sc_link; /* all the inter level info */ 52 }; 53 54 int ukmatch __P((struct device *, void *, void *)); 55 void ukattach __P((struct device *, struct device *, void *)); 56 57 struct cfattach uk_ca = { 58 sizeof(struct uk_softc), ukmatch, ukattach 59 }; 60 61 struct cfdriver uk_cd = { 62 NULL, "uk", DV_DULL 63 }; 64 65 /* 66 * This driver is so simple it uses all the default services 67 */ 68 struct scsi_device uk_switch = { 69 NULL, 70 NULL, 71 NULL, 72 NULL, 73 }; 74 75 int 76 ukmatch(parent, match, aux) 77 struct device *parent; 78 void *match, *aux; 79 { 80 81 return 1; 82 } 83 84 /* 85 * The routine called by the low level scsi routine when it discovers 86 * a device suitable for this driver. 87 */ 88 void 89 ukattach(parent, self, aux) 90 struct device *parent, *self; 91 void *aux; 92 { 93 struct uk_softc *uk = (void *)self; 94 struct scsibus_attach_args *sa = aux; 95 struct scsi_link *sc_link = sa->sa_sc_link; 96 97 SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: ")); 98 99 /* 100 * Store information needed to contact our base driver 101 */ 102 uk->sc_link = sc_link; 103 sc_link->device = &uk_switch; 104 sc_link->device_softc = uk; 105 sc_link->openings = 1; 106 107 printf("\n"); 108 printf("%s: unknown device\n", uk->sc_dev.dv_xname); 109 } 110 111 /* 112 * open the device. 113 */ 114 int 115 ukopen(dev) 116 dev_t dev; 117 { 118 int unit; 119 struct uk_softc *uk; 120 struct scsi_link *sc_link; 121 122 unit = UKUNIT(dev); 123 if (unit >= uk_cd.cd_ndevs) 124 return ENXIO; 125 uk = uk_cd.cd_devs[unit]; 126 if (!uk) 127 return ENXIO; 128 129 sc_link = uk->sc_link; 130 131 SC_DEBUG(sc_link, SDEV_DB1, 132 ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit, uk_cd.cd_ndevs)); 133 134 /* 135 * Only allow one at a time 136 */ 137 if (sc_link->flags & SDEV_OPEN) { 138 printf("%s: already open\n", uk->sc_dev.dv_xname); 139 return EBUSY; 140 } 141 142 sc_link->flags |= SDEV_OPEN; 143 144 SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n")); 145 return 0; 146 } 147 148 /* 149 * close the device.. only called if we are the LAST 150 * occurence of an open device 151 */ 152 int 153 ukclose(dev) 154 dev_t dev; 155 { 156 struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)]; 157 158 SC_DEBUG(uk->sc_link, SDEV_DB1, ("closing\n")); 159 uk->sc_link->flags &= ~SDEV_OPEN; 160 161 return 0; 162 } 163 164 /* 165 * Perform special action on behalf of the user 166 * Only does generic scsi ioctls. 167 */ 168 int 169 ukioctl(dev, cmd, addr, flag, p) 170 dev_t dev; 171 u_long cmd; 172 caddr_t addr; 173 int flag; 174 struct proc *p; 175 { 176 register struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)]; 177 178 return scsi_do_ioctl(uk->sc_link, dev, cmd, addr, flag, p); 179 } 180