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