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