Home | History | Annotate | Line # | Download | only in scsipi
uk.c revision 1.6
      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.6 1994/04/11 03:54:21 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 	struct scsi_link *sc_link;	/* all the inter level info */
     52 };
     53 
     54 void ukattach __P((struct device *, struct device *, void *));
     55 
     56 struct cfdriver ukcd = {
     57 	NULL, "uk", scsi_targmatch, ukattach, DV_DULL, sizeof(struct uk_data)
     58 };
     59 
     60 /*
     61  * This driver is so simple it uses all the default services
     62  */
     63 struct scsi_device uk_switch = {
     64 	NULL,
     65 	NULL,
     66 	NULL,
     67 	NULL,
     68 	"uk",
     69 	0
     70 };
     71 
     72 /*
     73  * The routine called by the low level scsi routine when it discovers
     74  * a device suitable for this driver.
     75  */
     76 void
     77 ukattach(parent, self, aux)
     78 	struct device *parent, *self;
     79 	void *aux;
     80 {
     81 	struct uk_data *uk = (void *)self;
     82 	struct scsi_link *sc_link = aux;
     83 
     84 	SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
     85 
     86 	/*
     87 	 * Store information needed to contact our base driver
     88 	 */
     89 	uk->sc_link = sc_link;
     90 	sc_link->device = &uk_switch;
     91 	sc_link->dev_unit = uk->sc_dev.dv_unit;
     92 
     93 	printf(": unknown device\n");
     94 }
     95 
     96 /*
     97  * open the device.
     98  */
     99 int
    100 ukopen(dev)
    101 	dev_t dev;
    102 {
    103 	int unit;
    104 	struct uk_data *uk;
    105 	struct scsi_link *sc_link;
    106 
    107 	unit = UKUNIT(dev);
    108 
    109 	if (unit >= ukcd.cd_ndevs)
    110 		return ENXIO;
    111 	uk = ukcd.cd_devs[unit];
    112 	if (!uk)
    113 		return ENXIO;
    114 
    115 	sc_link = uk->sc_link;
    116 
    117 	/*
    118 	 * Only allow one at a time
    119 	 */
    120 	if (sc_link->flags & SDEV_OPEN) {
    121 		printf("%s: already open\n", uk->sc_dev.dv_xname);
    122 		return EBUSY;
    123 	}
    124 
    125 	sc_link->flags |= SDEV_OPEN;
    126 	SC_DEBUG(sc_link, SDEV_DB1,
    127 	    ("ukopen: dev=0x%x (unit %d (of %d))\n", unit, ukcd.cd_ndevs));
    128 
    129 	return 0;
    130 }
    131 
    132 /*
    133  * close the device.. only called if we are the LAST
    134  * occurence of an open device
    135  */
    136 int
    137 ukclose(dev)
    138 	dev_t dev;
    139 {
    140 	int unit;
    141 	struct uk_data *uk;
    142 
    143 	unit = UKUNIT(dev);
    144 	uk = ukcd.cd_devs[unit];
    145 	uk->sc_link->flags &= ~SDEV_OPEN;
    146 	SC_DEBUG(uk->sc_link, SDEV_DB1, ("closed\n"));
    147 	return 0;
    148 }
    149 
    150 /*
    151  * Perform special action on behalf of the user
    152  * Only does generic scsi ioctls.
    153  */
    154 int
    155 ukioctl(dev, cmd, addr, flag)
    156 	dev_t dev;
    157 	int cmd;
    158 	caddr_t addr;
    159 	int flag;
    160 {
    161 	int unit;
    162 	register struct uk_data *uk;
    163 	struct scsi_link *sc_link;
    164 
    165 	/*
    166 	 * Find the device that the user is talking about
    167 	 */
    168 	unit = UKUNIT(dev);
    169 	uk = ukcd.cd_devs[unit];
    170 	return scsi_do_ioctl(uk->sc_link, cmd, addr, flag));
    171 }
    172