Home | History | Annotate | Line # | Download | only in scsipi
uk.c revision 1.62.4.1
      1  1.62.4.1     skrll /*	$NetBSD: uk.c,v 1.62.4.1 2016/10/05 20:55:56 skrll 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.62.4.1     skrll __KERNEL_RCSID(0, "$NetBSD: uk.c,v 1.62.4.1 2016/10/05 20:55:56 skrll 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.12   mycroft struct uk_softc {
     54      1.60   mbalmer 	device_t sc_dev;
     55       1.4   mycroft 
     56      1.30    bouyer 	struct scsipi_periph *sc_periph; /* all the inter level info */
     57       1.4   mycroft };
     58       1.4   mycroft 
     59      1.58    cegger static int	ukmatch(device_t, cfdata_t, void *);
     60      1.58    cegger static void	ukattach(device_t, device_t, void *);
     61      1.58    cegger static int	ukdetach(device_t, int);
     62       1.4   mycroft 
     63      1.60   mbalmer CFATTACH_DECL_NEW(
     64      1.60   mbalmer     uk,
     65      1.60   mbalmer     sizeof(struct uk_softc),
     66      1.60   mbalmer     ukmatch,
     67      1.60   mbalmer     ukattach,
     68      1.60   mbalmer     ukdetach,
     69      1.60   mbalmer     NULL
     70      1.60   mbalmer );
     71      1.15   thorpej 
     72      1.21   thorpej extern struct cfdriver uk_cd;
     73       1.1   mycroft 
     74      1.42   thorpej static dev_type_open(ukopen);
     75      1.42   thorpej static dev_type_close(ukclose);
     76      1.42   thorpej static dev_type_ioctl(ukioctl);
     77      1.34   gehenna 
     78      1.34   gehenna const struct cdevsw uk_cdevsw = {
     79      1.61  dholland 	.d_open = ukopen,
     80      1.61  dholland 	.d_close = ukclose,
     81      1.61  dholland 	.d_read = noread,
     82      1.61  dholland 	.d_write = nowrite,
     83      1.61  dholland 	.d_ioctl = ukioctl,
     84      1.61  dholland 	.d_stop = nostop,
     85      1.61  dholland 	.d_tty = notty,
     86      1.61  dholland 	.d_poll = nopoll,
     87      1.61  dholland 	.d_mmap = nommap,
     88      1.61  dholland 	.d_kqfilter = nokqfilter,
     89      1.62  dholland 	.d_discard = nodiscard,
     90      1.61  dholland 	.d_flag = D_OTHER
     91      1.34   gehenna };
     92      1.16  christos 
     93      1.42   thorpej static int
     94      1.60   mbalmer ukmatch(device_t parent, cfdata_t match, void *aux)
     95      1.12   mycroft {
     96      1.60   mbalmer 	return 1;
     97      1.12   mycroft }
     98      1.12   mycroft 
     99       1.1   mycroft /*
    100       1.1   mycroft  * The routine called by the low level scsi routine when it discovers
    101       1.1   mycroft  * a device suitable for this driver.
    102       1.1   mycroft  */
    103      1.42   thorpej static void
    104      1.58    cegger ukattach(device_t parent, device_t self, void *aux)
    105       1.1   mycroft {
    106      1.48   thorpej 	struct uk_softc *uk = device_private(self);
    107      1.19    bouyer 	struct scsipibus_attach_args *sa = aux;
    108      1.30    bouyer 	struct scsipi_periph *periph = sa->sa_periph;
    109       1.1   mycroft 
    110      1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB2, ("ukattach: "));
    111      1.60   mbalmer 	uk->sc_dev = self;
    112       1.4   mycroft 
    113      1.60   mbalmer 	/* Store information needed to contact our base driver */
    114      1.30    bouyer 	uk->sc_periph = periph;
    115      1.60   mbalmer 	periph->periph_dev = uk->sc_dev;
    116       1.1   mycroft 
    117  1.62.4.1     skrll 	aprint_naive("\n");
    118  1.62.4.1     skrll 	aprint_normal("\n");
    119  1.62.4.1     skrll 
    120  1.62.4.1     skrll 	if (!pmf_device_register(self, NULL, NULL))
    121  1.62.4.1     skrll 		aprint_error_dev(self, "couldn't establish power handler\n");
    122      1.28  augustss }
    123      1.28  augustss 
    124      1.42   thorpej static int
    125      1.58    cegger ukdetach(device_t self, int flags)
    126      1.28  augustss {
    127      1.28  augustss 	int cmaj, mn;
    128      1.45     perry 
    129      1.28  augustss 	/* locate the major number */
    130      1.34   gehenna 	cmaj = cdevsw_lookup_major(&uk_cdevsw);
    131      1.45     perry 
    132      1.28  augustss 	/* Nuke the vnodes for any open instances */
    133      1.47   thorpej 	mn = device_unit(self);
    134      1.28  augustss 	vdevgone(cmaj, mn, mn, VCHR);
    135      1.45     perry 
    136      1.60   mbalmer 	return 0;
    137       1.1   mycroft }
    138       1.1   mycroft 
    139      1.42   thorpej static int
    140      1.51  christos ukopen(dev_t dev, int flag, int fmt, struct lwp *l)
    141       1.1   mycroft {
    142      1.26   thorpej 	int unit, error;
    143      1.12   mycroft 	struct uk_softc *uk;
    144      1.30    bouyer 	struct scsipi_periph *periph;
    145      1.30    bouyer 	struct scsipi_adapter *adapt;
    146       1.1   mycroft 
    147      1.60   mbalmer 	unit = minor(dev);
    148      1.55   tsutsui 	uk = device_lookup_private(&uk_cd, unit);
    149      1.20     enami 	if (uk == NULL)
    150      1.60   mbalmer 		return ENXIO;
    151      1.20     enami 
    152      1.30    bouyer 	periph = uk->sc_periph;
    153      1.30    bouyer 	adapt = periph->periph_channel->chan_adapter;
    154       1.4   mycroft 
    155      1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB1,
    156      1.56    cegger 	    ("ukopen: dev=0x%"PRIx64" (unit %d (of %d))\n", dev, unit,
    157      1.20     enami 		uk_cd.cd_ndevs));
    158      1.11   mycroft 
    159      1.60   mbalmer 	/* Only allow one at a time */
    160      1.30    bouyer 	if (periph->periph_flags & PERIPH_OPEN) {
    161      1.60   mbalmer 		aprint_error_dev(uk->sc_dev, "already open\n");
    162      1.60   mbalmer 		return EBUSY;
    163       1.1   mycroft 	}
    164       1.4   mycroft 
    165      1.30    bouyer 	if ((error = scsipi_adapter_addref(adapt)) != 0)
    166      1.60   mbalmer 		return error;
    167      1.30    bouyer 	periph->periph_flags |= PERIPH_OPEN;
    168       1.4   mycroft 
    169      1.30    bouyer 	SC_DEBUG(periph, SCSIPI_DB3, ("open complete\n"));
    170      1.60   mbalmer 	return 0;
    171       1.1   mycroft }
    172       1.1   mycroft 
    173      1.42   thorpej static int
    174      1.51  christos ukclose(dev_t dev, int flag, int fmt, struct lwp *l)
    175       1.1   mycroft {
    176      1.60   mbalmer 	struct uk_softc *uk = device_lookup_private(&uk_cd, minor(dev));
    177      1.30    bouyer 	struct scsipi_periph *periph = uk->sc_periph;
    178      1.30    bouyer 	struct scsipi_adapter *adapt = periph->periph_channel->chan_adapter;
    179       1.1   mycroft 
    180      1.30    bouyer 	SC_DEBUG(uk->sc_periph, SCSIPI_DB1, ("closing\n"));
    181      1.27   thorpej 
    182      1.30    bouyer 	scsipi_wait_drain(periph);
    183      1.27   thorpej 
    184      1.30    bouyer 	scsipi_adapter_delref(adapt);
    185      1.30    bouyer 	periph->periph_flags &= ~PERIPH_OPEN;
    186      1.11   mycroft 
    187      1.60   mbalmer 	return 0;
    188       1.1   mycroft }
    189       1.1   mycroft 
    190       1.1   mycroft /*
    191      1.60   mbalmer  * Perform special action on behalf of the user.
    192       1.1   mycroft  * Only does generic scsi ioctls.
    193       1.1   mycroft  */
    194      1.42   thorpej static int
    195      1.52  christos ukioctl(dev_t dev, u_long cmd, void *addr, int flag, struct lwp *l)
    196       1.1   mycroft {
    197      1.60   mbalmer 	struct uk_softc *uk = device_lookup_private(&uk_cd, minor(dev));
    198       1.1   mycroft 
    199      1.60   mbalmer 	return scsipi_do_ioctl(uk->sc_periph, dev, cmd, addr, flag, l);
    200       1.1   mycroft }
    201