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