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