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