Home | History | Annotate | Line # | Download | only in scsipi
uk.c revision 1.52.36.4
      1  1.52.36.3       mjf /*	$NetBSD: uk.c,v 1.52.36.4 2008/06/29 09:33:10 mjf 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  *
     19       1.23   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.23   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.23   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.23   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.23   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.23   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.23   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.23   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.23   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.23   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.23   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     30        1.5   mycroft  */
     31        1.5   mycroft 
     32       1.20     enami /*
     33        1.1   mycroft  * Dummy driver for a device we can't identify.
     34        1.5   mycroft  * Originally by Julian Elischer (julian (at) tfs.com)
     35        1.1   mycroft  */
     36       1.31     lukem 
     37       1.31     lukem #include <sys/cdefs.h>
     38  1.52.36.3       mjf __KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.52.36.4 2008/06/29 09:33:10 mjf Exp $");
     39        1.1   mycroft 
     40        1.1   mycroft #include <sys/param.h>
     41       1.16  christos #include <sys/systm.h>
     42       1.16  christos 
     43        1.1   mycroft #include <sys/errno.h>
     44        1.1   mycroft #include <sys/ioctl.h>
     45        1.4   mycroft #include <sys/device.h>
     46       1.16  christos #include <sys/conf.h>
     47       1.28  augustss #include <sys/vnode.h>
     48        1.2   mycroft 
     49       1.19    bouyer #include <dev/scsipi/scsi_all.h>
     50       1.19    bouyer #include <dev/scsipi/scsipi_all.h>
     51       1.19    bouyer #include <dev/scsipi/scsiconf.h>
     52        1.2   mycroft 
     53        1.4   mycroft #define	UKUNIT(z)	(minor(z))
     54        1.4   mycroft 
     55       1.12   mycroft struct uk_softc {
     56        1.4   mycroft 	struct device sc_dev;
     57        1.4   mycroft 
     58       1.30    bouyer 	struct scsipi_periph *sc_periph; /* all the inter level info */
     59        1.4   mycroft };
     60        1.4   mycroft 
     61       1.42   thorpej static int	ukmatch(struct device *, struct cfdata *, void *);
     62       1.42   thorpej static void	ukattach(struct device *, struct device *, void *);
     63       1.42   thorpej static int	ukactivate(struct device *, enum devact);
     64       1.42   thorpej static int	ukdetach(struct device *, int);
     65        1.4   mycroft 
     66       1.30    bouyer 
     67       1.41   mycroft CFATTACH_DECL(uk, sizeof(struct uk_softc), ukmatch, ukattach, ukdetach,
     68       1.41   mycroft     ukactivate);
     69       1.15   thorpej 
     70       1.21   thorpej extern struct cfdriver uk_cd;
     71        1.1   mycroft 
     72       1.42   thorpej static dev_type_open(ukopen);
     73       1.42   thorpej static dev_type_close(ukclose);
     74       1.42   thorpej static dev_type_ioctl(ukioctl);
     75       1.34   gehenna 
     76       1.34   gehenna const struct cdevsw uk_cdevsw = {
     77       1.34   gehenna 	ukopen, ukclose, noread, nowrite, ukioctl,
     78       1.49  christos 	nostop, notty, nopoll, nommap, nokqfilter, D_OTHER,
     79       1.34   gehenna };
     80       1.16  christos 
     81       1.42   thorpej static int
     82       1.51  christos ukmatch(struct device *parent, struct cfdata *match,
     83       1.51  christos     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.42   thorpej static void
     94       1.51  christos ukattach(struct device *parent, struct device *self, void *aux)
     95        1.1   mycroft {
     96       1.48   thorpej 	struct uk_softc *uk = device_private(self);
     97       1.19    bouyer 	struct scsipibus_attach_args *sa = aux;
     98       1.30    bouyer 	struct scsipi_periph *periph = sa->sa_periph;
     99  1.52.36.1       mjf 	int maj;
    100        1.1   mycroft 
    101       1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB2, ("ukattach: "));
    102        1.4   mycroft 
    103        1.1   mycroft 	/*
    104        1.1   mycroft 	 * Store information needed to contact our base driver
    105        1.1   mycroft 	 */
    106       1.30    bouyer 	uk->sc_periph = periph;
    107       1.30    bouyer 	periph->periph_dev = &uk->sc_dev;
    108        1.1   mycroft 
    109       1.17  christos 	printf("\n");
    110  1.52.36.1       mjf 
    111  1.52.36.1       mjf 	maj = cdevsw_lookup_major(&uk_cdevsw);
    112  1.52.36.1       mjf 	device_register_name(makedev(maj, device_unit(self)), self, true,
    113  1.52.36.1       mjf 	    DEV_OTHER, device_xname(self));
    114       1.28  augustss }
    115       1.28  augustss 
    116       1.42   thorpej static int
    117       1.51  christos ukactivate(struct device *self, enum devact act)
    118       1.28  augustss {
    119       1.28  augustss 	int rv = 0;
    120       1.45     perry 
    121       1.28  augustss 	switch (act) {
    122       1.28  augustss 	case DVACT_ACTIVATE:
    123       1.28  augustss 		rv = EOPNOTSUPP;
    124       1.28  augustss 		break;
    125       1.45     perry 
    126       1.28  augustss 	case DVACT_DEACTIVATE:
    127       1.28  augustss 		/*
    128       1.28  augustss 		 * Nothing to do; we key off the device's DVF_ACTIVE.
    129       1.28  augustss 		 */
    130       1.28  augustss 		break;
    131       1.28  augustss 	}
    132       1.28  augustss 	return (rv);
    133       1.28  augustss }
    134       1.45     perry 
    135       1.42   thorpej static int
    136       1.51  christos ukdetach(struct device *self, int flags)
    137       1.28  augustss {
    138       1.48   thorpej 	/*struct uk_softc *uk = device_private(self);*/
    139       1.28  augustss 	int cmaj, mn;
    140       1.45     perry 
    141  1.52.36.2       mjf 	device_deregister_all(self);
    142  1.52.36.1       mjf 
    143       1.28  augustss 	/* locate the major number */
    144       1.34   gehenna 	cmaj = cdevsw_lookup_major(&uk_cdevsw);
    145       1.45     perry 
    146       1.28  augustss 	/* Nuke the vnodes for any open instances */
    147       1.47   thorpej 	mn = device_unit(self);
    148       1.28  augustss 	vdevgone(cmaj, mn, mn, VCHR);
    149       1.45     perry 
    150       1.28  augustss 	return (0);
    151        1.1   mycroft }
    152        1.1   mycroft 
    153        1.1   mycroft /*
    154        1.4   mycroft  * open the device.
    155        1.1   mycroft  */
    156       1.42   thorpej static int
    157       1.51  christos ukopen(dev_t dev, int flag, int fmt, struct lwp *l)
    158        1.1   mycroft {
    159       1.26   thorpej 	int unit, error;
    160       1.12   mycroft 	struct uk_softc *uk;
    161       1.30    bouyer 	struct scsipi_periph *periph;
    162       1.30    bouyer 	struct scsipi_adapter *adapt;
    163        1.1   mycroft 
    164        1.4   mycroft 	unit = UKUNIT(dev);
    165  1.52.36.4       mjf 	uk = device_lookup_private(&uk_cd, unit);
    166       1.20     enami 	if (uk == NULL)
    167       1.20     enami 		return (ENXIO);
    168       1.20     enami 
    169       1.30    bouyer 	periph = uk->sc_periph;
    170       1.30    bouyer 	adapt = periph->periph_channel->chan_adapter;
    171        1.4   mycroft 
    172       1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB1,
    173       1.20     enami 	    ("ukopen: dev=0x%x (unit %d (of %d))\n", dev, unit,
    174       1.20     enami 		uk_cd.cd_ndevs));
    175       1.11   mycroft 
    176        1.1   mycroft 	/*
    177        1.1   mycroft 	 * Only allow one at a time
    178        1.1   mycroft 	 */
    179       1.30    bouyer 	if (periph->periph_flags & PERIPH_OPEN) {
    180  1.52.36.3       mjf 		aprint_error_dev(&uk->sc_dev, "already open\n");
    181       1.20     enami 		return (EBUSY);
    182        1.1   mycroft 	}
    183        1.4   mycroft 
    184       1.30    bouyer 	if ((error = scsipi_adapter_addref(adapt)) != 0)
    185       1.26   thorpej 		return (error);
    186       1.30    bouyer 	periph->periph_flags |= PERIPH_OPEN;
    187        1.4   mycroft 
    188       1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
    189       1.20     enami 	return (0);
    190        1.1   mycroft }
    191        1.1   mycroft 
    192        1.1   mycroft /*
    193        1.1   mycroft  * close the device.. only called if we are the LAST
    194        1.1   mycroft  * occurence of an open device
    195        1.1   mycroft  */
    196       1.42   thorpej static int
    197       1.51  christos ukclose(dev_t dev, int flag, int fmt, struct lwp *l)
    198        1.1   mycroft {
    199  1.52.36.4       mjf 	struct uk_softc *uk = device_lookup_private(&uk_cd, UKUNIT(dev));
    200       1.30    bouyer 	struct scsipi_periph *periph = uk->sc_periph;
    201       1.30    bouyer 	struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
    202        1.1   mycroft 
    203       1.30    bouyer 	SC_DEBUG(uk->sc_periph, SCSIPI_DB1, ("closing\n"));
    204       1.27   thorpej 
    205       1.30    bouyer 	scsipi_wait_drain(periph);
    206       1.27   thorpej 
    207       1.30    bouyer 	scsipi_adapter_delref(adapt);
    208       1.30    bouyer 	periph->periph_flags &= ~PERIPH_OPEN;
    209       1.11   mycroft 
    210       1.20     enami 	return (0);
    211        1.1   mycroft }
    212        1.1   mycroft 
    213        1.1   mycroft /*
    214        1.1   mycroft  * Perform special action on behalf of the user
    215        1.1   mycroft  * Only does generic scsi ioctls.
    216        1.1   mycroft  */
    217       1.42   thorpej static int
    218       1.52  christos ukioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
    219        1.1   mycroft {
    220  1.52.36.4       mjf 	struct uk_softc *uk = device_lookup_private(&uk_cd, UKUNIT(dev));
    221        1.1   mycroft 
    222       1.46  christos 	return (scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, l));
    223        1.1   mycroft }
    224