1 /* $NetBSD: uk.c,v 1.18 1996/12/05 01:06:47 cgd 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/systm.h> 40 41 #include <sys/errno.h> 42 #include <sys/ioctl.h> 43 #include <sys/device.h> 44 #include <sys/conf.h> 45 46 #include <scsi/scsi_all.h> 47 #include <scsi/scsiconf.h> 48 49 #define UKUNIT(z) (minor(z)) 50 51 struct uk_softc { 52 struct device sc_dev; 53 54 struct scsi_link *sc_link; /* all the inter level info */ 55 }; 56 57 #ifdef __BROKEN_INDIRECT_CONFIG 58 int ukmatch __P((struct device *, void *, void *)); 59 #else 60 int ukmatch __P((struct device *, struct cfdata *, void *)); 61 #endif 62 void ukattach __P((struct device *, struct device *, void *)); 63 64 struct cfattach uk_ca = { 65 sizeof(struct uk_softc), ukmatch, ukattach 66 }; 67 68 struct cfdriver uk_cd = { 69 NULL, "uk", DV_DULL 70 }; 71 72 /* 73 * This driver is so simple it uses all the default services 74 */ 75 struct scsi_device uk_switch = { 76 NULL, 77 NULL, 78 NULL, 79 NULL, 80 }; 81 82 cdev_decl(uk); 83 84 int 85 ukmatch(parent, match, aux) 86 struct device *parent; 87 #ifdef __BROKEN_INDIRECT_CONFIG 88 void *match; 89 #else 90 struct cfdata *match; 91 #endif 92 void *aux; 93 { 94 95 return 1; 96 } 97 98 /* 99 * The routine called by the low level scsi routine when it discovers 100 * a device suitable for this driver. 101 */ 102 void 103 ukattach(parent, self, aux) 104 struct device *parent, *self; 105 void *aux; 106 { 107 struct uk_softc *uk = (void *)self; 108 struct scsibus_attach_args *sa = aux; 109 struct scsi_link *sc_link = sa->sa_sc_link; 110 111 SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: ")); 112 113 /* 114 * Store information needed to contact our base driver 115 */ 116 uk->sc_link = sc_link; 117 sc_link->device = &uk_switch; 118 sc_link->device_softc = uk; 119 sc_link->openings = 1; 120 121 printf("\n"); 122 printf("%s: unknown device\n", uk->sc_dev.dv_xname); 123 } 124 125 /* 126 * open the device. 127 */ 128 int 129 ukopen(dev, flag, fmt, p) 130 dev_t dev; 131 int flag, fmt; 132 struct proc *p; 133 { 134 int unit; 135 struct uk_softc *uk; 136 struct scsi_link *sc_link; 137 138 unit = UKUNIT(dev); 139 if (unit >= uk_cd.cd_ndevs) 140 return ENXIO; 141 uk = uk_cd.cd_devs[unit]; 142 if (!uk) 143 return ENXIO; 144 145 sc_link = uk->sc_link; 146 147 SC_DEBUG(sc_link, SDEV_DB1, 148 ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit, uk_cd.cd_ndevs)); 149 150 /* 151 * Only allow one at a time 152 */ 153 if (sc_link->flags & SDEV_OPEN) { 154 printf("%s: already open\n", uk->sc_dev.dv_xname); 155 return EBUSY; 156 } 157 158 sc_link->flags |= SDEV_OPEN; 159 160 SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n")); 161 return 0; 162 } 163 164 /* 165 * close the device.. only called if we are the LAST 166 * occurence of an open device 167 */ 168 int 169 ukclose(dev, flag, fmt, p) 170 dev_t dev; 171 int flag, fmt; 172 struct proc *p; 173 { 174 struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)]; 175 176 SC_DEBUG(uk->sc_link, SDEV_DB1, ("closing\n")); 177 uk->sc_link->flags &= ~SDEV_OPEN; 178 179 return 0; 180 } 181 182 /* 183 * Perform special action on behalf of the user 184 * Only does generic scsi ioctls. 185 */ 186 int 187 ukioctl(dev, cmd, addr, flag, p) 188 dev_t dev; 189 u_long cmd; 190 caddr_t addr; 191 int flag; 192 struct proc *p; 193 { 194 register struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)]; 195 196 return scsi_do_ioctl(uk->sc_link, dev, cmd, addr, flag, p); 197 } 198