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