Home | History | Annotate | Line # | Download | only in scsipi
uk.c revision 1.24
      1 /*	$NetBSD: uk.c,v 1.24 1998/08/31 22:28:08 cgd Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Charles M. Hannum.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Dummy driver for a device we can't identify.
     41  * Originally by Julian Elischer (julian (at) tfs.com)
     42  */
     43 
     44 #include <sys/types.h>
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 
     48 #include <sys/errno.h>
     49 #include <sys/ioctl.h>
     50 #include <sys/device.h>
     51 #include <sys/conf.h>
     52 
     53 #include <dev/scsipi/scsi_all.h>
     54 #include <dev/scsipi/scsipi_all.h>
     55 #include <dev/scsipi/scsiconf.h>
     56 
     57 #define	UKUNIT(z)	(minor(z))
     58 
     59 struct uk_softc {
     60 	struct device sc_dev;
     61 
     62 	struct scsipi_link *sc_link;	/* all the inter level info */
     63 };
     64 
     65 int ukmatch __P((struct device *, struct cfdata *, void *));
     66 void ukattach __P((struct device *, struct device *, void *));
     67 
     68 struct cfattach uk_ca = {
     69 	sizeof(struct uk_softc), ukmatch, ukattach
     70 };
     71 
     72 extern struct cfdriver uk_cd;
     73 
     74 /*
     75  * This driver is so simple it uses all the default services
     76  */
     77 struct scsipi_device uk_switch = {
     78 	NULL,
     79 	NULL,
     80 	NULL,
     81 	NULL,
     82 };
     83 
     84 cdev_decl(uk);
     85 
     86 int
     87 ukmatch(parent, match, aux)
     88 	struct device *parent;
     89 	struct cfdata *match;
     90 	void *aux;
     91 {
     92 
     93 	return (1);
     94 }
     95 
     96 /*
     97  * The routine called by the low level scsi routine when it discovers
     98  * a device suitable for this driver.
     99  */
    100 void
    101 ukattach(parent, self, aux)
    102 	struct device *parent, *self;
    103 	void *aux;
    104 {
    105 	struct uk_softc *uk = (void *)self;
    106 	struct scsipibus_attach_args *sa = aux;
    107 	struct scsipi_link *sc_link = sa->sa_sc_link;
    108 
    109 	SC_DEBUG(sc_link, SDEV_DB2, ("ukattach: "));
    110 
    111 	/*
    112 	 * Store information needed to contact our base driver
    113 	 */
    114 	uk->sc_link = sc_link;
    115 	sc_link->device = &uk_switch;
    116 	sc_link->device_softc = uk;
    117 	sc_link->openings = 1;
    118 
    119 	printf("\n");
    120 	printf("%s: unknown device\n", uk->sc_dev.dv_xname);
    121 }
    122 
    123 /*
    124  * open the device.
    125  */
    126 int
    127 ukopen(dev, flag, fmt, p)
    128 	dev_t dev;
    129 	int flag, fmt;
    130 	struct proc *p;
    131 {
    132 	int unit;
    133 	struct uk_softc *uk;
    134 	struct scsipi_link *sc_link;
    135 
    136 	unit = UKUNIT(dev);
    137 	if (unit >= uk_cd.cd_ndevs)
    138 		return (ENXIO);
    139 	uk = uk_cd.cd_devs[unit];
    140 	if (uk == NULL)
    141 		return (ENXIO);
    142 
    143 	sc_link = uk->sc_link;
    144 
    145 	SC_DEBUG(sc_link, SDEV_DB1,
    146 	    ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit,
    147 		uk_cd.cd_ndevs));
    148 
    149 	/*
    150 	 * Only allow one at a time
    151 	 */
    152 	if (sc_link->flags & SDEV_OPEN) {
    153 		printf("%s: already open\n", uk->sc_dev.dv_xname);
    154 		return (EBUSY);
    155 	}
    156 
    157 	sc_link->flags |= SDEV_OPEN;
    158 
    159 	SC_DEBUG(sc_link, SDEV_DB3, ("open complete\n"));
    160 	return (0);
    161 }
    162 
    163 /*
    164  * close the device.. only called if we are the LAST
    165  * occurence of an open device
    166  */
    167 int
    168 ukclose(dev, flag, fmt, p)
    169 	dev_t dev;
    170 	int flag, fmt;
    171 	struct proc *p;
    172 {
    173 	struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
    174 
    175 	SC_DEBUG(uk->sc_link, SDEV_DB1, ("closing\n"));
    176 	uk->sc_link->flags &= ~SDEV_OPEN;
    177 
    178 	return (0);
    179 }
    180 
    181 /*
    182  * Perform special action on behalf of the user
    183  * Only does generic scsi ioctls.
    184  */
    185 int
    186 ukioctl(dev, cmd, addr, flag, p)
    187 	dev_t dev;
    188 	u_long cmd;
    189 	caddr_t addr;
    190 	int flag;
    191 	struct proc *p;
    192 {
    193 	register struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
    194 
    195 	return (scsipi_do_ioctl(uk->sc_link, dev, cmd, addr, flag, p));
    196 }
    197