Home | History | Annotate | Line # | Download | only in scsipi
uk.c revision 1.39
      1  1.39   darrenr /*	$NetBSD: uk.c,v 1.39 2003/06/28 14:21:45 darrenr 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.31     lukem 
     44  1.31     lukem #include <sys/cdefs.h>
     45  1.39   darrenr __KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.39 2003/06/28 14:21:45 darrenr Exp $");
     46   1.1   mycroft 
     47   1.1   mycroft #include <sys/param.h>
     48  1.16  christos #include <sys/systm.h>
     49  1.16  christos 
     50   1.1   mycroft #include <sys/errno.h>
     51   1.1   mycroft #include <sys/ioctl.h>
     52   1.4   mycroft #include <sys/device.h>
     53  1.16  christos #include <sys/conf.h>
     54  1.28  augustss #include <sys/vnode.h>
     55   1.2   mycroft 
     56  1.19    bouyer #include <dev/scsipi/scsi_all.h>
     57  1.19    bouyer #include <dev/scsipi/scsipi_all.h>
     58  1.19    bouyer #include <dev/scsipi/scsiconf.h>
     59   1.2   mycroft 
     60   1.4   mycroft #define	UKUNIT(z)	(minor(z))
     61   1.4   mycroft 
     62  1.12   mycroft struct uk_softc {
     63   1.4   mycroft 	struct device sc_dev;
     64   1.4   mycroft 
     65  1.30    bouyer 	struct scsipi_periph *sc_periph; /* all the inter level info */
     66   1.4   mycroft };
     67   1.4   mycroft 
     68  1.18       cgd int ukmatch __P((struct device *, struct cfdata *, void *));
     69   1.4   mycroft void ukattach __P((struct device *, struct device *, void *));
     70  1.28  augustss int ukactivate __P((struct device *, enum devact));
     71  1.28  augustss int ukdetach __P((struct device *, int));
     72   1.4   mycroft 
     73  1.30    bouyer 
     74  1.36   thorpej CFATTACH_DECL(uk_scsibus, sizeof(struct uk_softc),
     75  1.37   thorpej     ukmatch, ukattach, ukdetach, ukactivate);
     76  1.36   thorpej 
     77  1.36   thorpej CFATTACH_DECL(uk_atapibus, sizeof(struct uk_softc),
     78  1.37   thorpej     ukmatch, ukattach, ukdetach, ukactivate);
     79  1.15   thorpej 
     80  1.21   thorpej extern struct cfdriver uk_cd;
     81   1.1   mycroft 
     82  1.34   gehenna dev_type_open(ukopen);
     83  1.34   gehenna dev_type_close(ukclose);
     84  1.34   gehenna dev_type_ioctl(ukioctl);
     85  1.34   gehenna 
     86  1.34   gehenna const struct cdevsw uk_cdevsw = {
     87  1.34   gehenna 	ukopen, ukclose, noread, nowrite, ukioctl,
     88  1.38  jdolecek 	nostop, notty, nopoll, nommap, nokqfilter,
     89  1.34   gehenna };
     90  1.16  christos 
     91  1.12   mycroft int
     92  1.12   mycroft ukmatch(parent, match, aux)
     93  1.12   mycroft 	struct device *parent;
     94  1.18       cgd 	struct cfdata *match;
     95  1.18       cgd 	void *aux;
     96  1.12   mycroft {
     97  1.12   mycroft 
     98  1.20     enami 	return (1);
     99  1.12   mycroft }
    100  1.12   mycroft 
    101   1.1   mycroft /*
    102   1.1   mycroft  * The routine called by the low level scsi routine when it discovers
    103   1.1   mycroft  * a device suitable for this driver.
    104   1.1   mycroft  */
    105   1.4   mycroft void
    106   1.4   mycroft ukattach(parent, self, aux)
    107   1.4   mycroft 	struct device *parent, *self;
    108   1.4   mycroft 	void *aux;
    109   1.1   mycroft {
    110  1.12   mycroft 	struct uk_softc *uk = (void *)self;
    111  1.19    bouyer 	struct scsipibus_attach_args *sa = aux;
    112  1.30    bouyer 	struct scsipi_periph *periph = sa->sa_periph;
    113   1.1   mycroft 
    114  1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB2, ("ukattach: "));
    115   1.4   mycroft 
    116   1.1   mycroft 	/*
    117   1.1   mycroft 	 * Store information needed to contact our base driver
    118   1.1   mycroft 	 */
    119  1.30    bouyer 	uk->sc_periph = periph;
    120  1.30    bouyer 	periph->periph_dev = &uk->sc_dev;
    121   1.1   mycroft 
    122  1.17  christos 	printf("\n");
    123  1.28  augustss }
    124  1.28  augustss 
    125  1.28  augustss int
    126  1.28  augustss ukactivate(self, act)
    127  1.28  augustss 	struct device *self;
    128  1.28  augustss 	enum devact act;
    129  1.28  augustss {
    130  1.28  augustss 	int rv = 0;
    131  1.30    bouyer 
    132  1.28  augustss 	switch (act) {
    133  1.28  augustss 	case DVACT_ACTIVATE:
    134  1.28  augustss 		rv = EOPNOTSUPP;
    135  1.28  augustss 		break;
    136  1.30    bouyer 
    137  1.28  augustss 	case DVACT_DEACTIVATE:
    138  1.28  augustss 		/*
    139  1.28  augustss 		 * Nothing to do; we key off the device's DVF_ACTIVE.
    140  1.28  augustss 		 */
    141  1.28  augustss 		break;
    142  1.28  augustss 	}
    143  1.28  augustss 	return (rv);
    144  1.28  augustss }
    145  1.30    bouyer 
    146  1.28  augustss int
    147  1.28  augustss ukdetach(self, flags)
    148  1.28  augustss 	struct device *self;
    149  1.28  augustss 	int flags;
    150  1.28  augustss {
    151  1.28  augustss 	/*struct uk_softc *uk = (struct uk_softc *) self;*/
    152  1.28  augustss 	int cmaj, mn;
    153  1.30    bouyer 
    154  1.28  augustss 	/* locate the major number */
    155  1.34   gehenna 	cmaj = cdevsw_lookup_major(&uk_cdevsw);
    156  1.30    bouyer 
    157  1.28  augustss 	/* Nuke the vnodes for any open instances */
    158  1.28  augustss 	mn = self->dv_unit;
    159  1.28  augustss 	vdevgone(cmaj, mn, mn, VCHR);
    160  1.30    bouyer 
    161  1.28  augustss 	return (0);
    162   1.1   mycroft }
    163   1.1   mycroft 
    164  1.30    bouyer 
    165  1.30    bouyer 
    166   1.1   mycroft /*
    167   1.4   mycroft  * open the device.
    168   1.1   mycroft  */
    169   1.4   mycroft int
    170  1.39   darrenr ukopen(dev, flag, fmt, l)
    171   1.4   mycroft 	dev_t dev;
    172  1.16  christos 	int flag, fmt;
    173  1.39   darrenr 	struct lwp *l;
    174   1.1   mycroft {
    175  1.26   thorpej 	int unit, error;
    176  1.12   mycroft 	struct uk_softc *uk;
    177  1.30    bouyer 	struct scsipi_periph *periph;
    178  1.30    bouyer 	struct scsipi_adapter *adapt;
    179   1.1   mycroft 
    180   1.4   mycroft 	unit = UKUNIT(dev);
    181  1.15   thorpej 	if (unit >= uk_cd.cd_ndevs)
    182  1.20     enami 		return (ENXIO);
    183  1.15   thorpej 	uk = uk_cd.cd_devs[unit];
    184  1.20     enami 	if (uk == NULL)
    185  1.20     enami 		return (ENXIO);
    186  1.20     enami 
    187  1.30    bouyer 	periph = uk->sc_periph;
    188  1.30    bouyer 	adapt = periph->periph_channel->chan_adapter;
    189   1.4   mycroft 
    190  1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB1,
    191  1.20     enami 	    ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit,
    192  1.20     enami 		uk_cd.cd_ndevs));
    193  1.11   mycroft 
    194   1.1   mycroft 	/*
    195   1.1   mycroft 	 * Only allow one at a time
    196   1.1   mycroft 	 */
    197  1.30    bouyer 	if (periph->periph_flags & PERIPH_OPEN) {
    198  1.17  christos 		printf("%s: already open\n", uk->sc_dev.dv_xname);
    199  1.20     enami 		return (EBUSY);
    200   1.1   mycroft 	}
    201   1.4   mycroft 
    202  1.30    bouyer 	if ((error = scsipi_adapter_addref(adapt)) != 0)
    203  1.26   thorpej 		return (error);
    204  1.30    bouyer 	periph->periph_flags |= PERIPH_OPEN;
    205   1.4   mycroft 
    206  1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
    207  1.20     enami 	return (0);
    208   1.1   mycroft }
    209   1.1   mycroft 
    210   1.1   mycroft /*
    211   1.1   mycroft  * close the device.. only called if we are the LAST
    212   1.1   mycroft  * occurence of an open device
    213   1.1   mycroft  */
    214   1.4   mycroft int
    215  1.39   darrenr ukclose(dev, flag, fmt, l)
    216   1.4   mycroft 	dev_t dev;
    217  1.16  christos 	int flag, fmt;
    218  1.39   darrenr 	struct lwp *l;
    219   1.1   mycroft {
    220  1.15   thorpej 	struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
    221  1.30    bouyer 	struct scsipi_periph *periph = uk->sc_periph;
    222  1.30    bouyer 	struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
    223   1.1   mycroft 
    224  1.30    bouyer 	SC_DEBUG(uk->sc_periph, SCSIPI_DB1, ("closing\n"));
    225  1.27   thorpej 
    226  1.30    bouyer 	scsipi_wait_drain(periph);
    227  1.27   thorpej 
    228  1.30    bouyer 	scsipi_adapter_delref(adapt);
    229  1.30    bouyer 	periph->periph_flags &= ~PERIPH_OPEN;
    230  1.11   mycroft 
    231  1.20     enami 	return (0);
    232   1.1   mycroft }
    233   1.1   mycroft 
    234   1.1   mycroft /*
    235   1.1   mycroft  * Perform special action on behalf of the user
    236   1.1   mycroft  * Only does generic scsi ioctls.
    237   1.1   mycroft  */
    238   1.4   mycroft int
    239  1.39   darrenr ukioctl(dev, cmd, addr, flag, l)
    240   1.4   mycroft 	dev_t dev;
    241   1.9       cgd 	u_long cmd;
    242   1.4   mycroft 	caddr_t addr;
    243   1.4   mycroft 	int flag;
    244  1.39   darrenr 	struct lwp *l;
    245   1.1   mycroft {
    246  1.30    bouyer 	register struct uk_softc *uk = uk_cd.cd_devs[UKUNIT(dev)];
    247   1.1   mycroft 
    248  1.39   darrenr 	return (scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, l));
    249   1.1   mycroft }
    250