Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.156.2.1
      1  1.156.2.1   nathanw /*	$NetBSD: scsiconf.c,v 1.156.2.1 2001/03/05 22:49:36 nathanw Exp $	*/
      2       1.14       cgd 
      3      1.106   mycroft /*-
      4      1.106   mycroft  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5      1.106   mycroft  * All rights reserved.
      6      1.106   mycroft  *
      7      1.106   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8      1.111   thorpej  * by Charles M. Hannum; Jason R. Thorpe of the Numerical Aerospace
      9      1.111   thorpej  * Simulation Facility, NASA Ames Research Center.
     10       1.12   mycroft  *
     11       1.12   mycroft  * Redistribution and use in source and binary forms, with or without
     12       1.12   mycroft  * modification, are permitted provided that the following conditions
     13       1.12   mycroft  * are met:
     14       1.12   mycroft  * 1. Redistributions of source code must retain the above copyright
     15       1.12   mycroft  *    notice, this list of conditions and the following disclaimer.
     16       1.12   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.12   mycroft  *    notice, this list of conditions and the following disclaimer in the
     18       1.12   mycroft  *    documentation and/or other materials provided with the distribution.
     19       1.12   mycroft  * 3. All advertising materials mentioning features or use of this software
     20       1.12   mycroft  *    must display the following acknowledgement:
     21      1.106   mycroft  *        This product includes software developed by the NetBSD
     22      1.106   mycroft  *        Foundation, Inc. and its contributors.
     23      1.106   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24      1.106   mycroft  *    contributors may be used to endorse or promote products derived
     25      1.106   mycroft  *    from this software without specific prior written permission.
     26       1.12   mycroft  *
     27      1.106   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28      1.106   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29      1.106   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30      1.106   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31      1.106   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32      1.106   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33      1.106   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34      1.106   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35      1.106   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36      1.106   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37      1.106   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     38       1.12   mycroft  */
     39       1.12   mycroft 
     40       1.12   mycroft /*
     41       1.12   mycroft  * Originally written by Julian Elischer (julian (at) tfs.com)
     42        1.5   deraadt  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     43        1.1       cgd  *
     44        1.1       cgd  * TRW Financial Systems, in accordance with their agreement with Carnegie
     45        1.1       cgd  * Mellon University, makes this software available to CMU to distribute
     46        1.1       cgd  * or use in any manner that they see fit as long as this message is kept with
     47        1.1       cgd  * the software. For this reason TFS also grants any other persons or
     48        1.1       cgd  * organisations permission to use or modify this software.
     49        1.1       cgd  *
     50        1.1       cgd  * TFS supplies this software to be publicly redistributed
     51        1.1       cgd  * on the understanding that TFS is not responsible for the correct
     52        1.1       cgd  * functioning of this software in any circumstances.
     53        1.7       cgd  *
     54       1.12   mycroft  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     55        1.1       cgd  */
     56        1.1       cgd 
     57       1.10   mycroft #include <sys/types.h>
     58       1.10   mycroft #include <sys/param.h>
     59       1.10   mycroft #include <sys/systm.h>
     60      1.128   thorpej #include <sys/kernel.h>
     61  1.156.2.1   nathanw #include <sys/lwp.h>
     62      1.128   thorpej #include <sys/proc.h>
     63       1.12   mycroft #include <sys/malloc.h>
     64       1.12   mycroft #include <sys/device.h>
     65      1.111   thorpej #include <sys/conf.h>
     66      1.113   thorpej #include <sys/fcntl.h>
     67      1.112   thorpej #include <sys/scsiio.h>
     68       1.10   mycroft 
     69       1.88    bouyer #include <dev/scsipi/scsi_all.h>
     70       1.88    bouyer #include <dev/scsipi/scsipi_all.h>
     71       1.88    bouyer #include <dev/scsipi/scsiconf.h>
     72       1.92     enami 
     73       1.88    bouyer #include "locators.h"
     74        1.1       cgd 
     75       1.18   mycroft #if 0
     76       1.12   mycroft #if NCALS > 0
     77       1.18   mycroft 	{ T_PROCESSOR, T_FIXED, 1,
     78       1.18   mycroft 	  0, 0, 0 },
     79       1.12   mycroft #endif	/* NCALS */
     80        1.1       cgd #if NBLL > 0
     81       1.18   mycroft 	{ T_PROCESSOR, T_FIXED, 1,
     82       1.12   mycroft 	  "AEG     ", "READER          ", "V1.0" },
     83       1.12   mycroft #endif	/* NBLL */
     84        1.1       cgd #if NKIL > 0
     85       1.18   mycroft 	{ T_SCANNER, T_FIXED, 0,
     86       1.18   mycroft 	  "KODAK   ", "IL Scanner 900  ", 0 },
     87       1.12   mycroft #endif	/* NKIL */
     88       1.18   mycroft #endif
     89       1.12   mycroft 
     90       1.12   mycroft /*
     91       1.12   mycroft  * Declarations
     92       1.12   mycroft  */
     93      1.119    mjacob int scsi_probedev __P((struct scsibus_softc *, int, int));
     94       1.18   mycroft int scsi_probe_bus __P((int bus, int target, int lun));
     95       1.12   mycroft 
     96       1.88    bouyer struct scsipi_device probe_switch = {
     97       1.12   mycroft 	NULL,
     98       1.12   mycroft 	NULL,
     99       1.12   mycroft 	NULL,
    100       1.12   mycroft 	NULL,
    101       1.12   mycroft };
    102       1.12   mycroft 
    103       1.71       cgd int scsibusmatch __P((struct device *, struct cfdata *, void *));
    104       1.12   mycroft void scsibusattach __P((struct device *, struct device *, void *));
    105      1.126   thorpej int scsibusactivate __P((struct device *, enum devact));
    106      1.126   thorpej int scsibusdetach __P((struct device *, int flags));
    107      1.126   thorpej 
    108       1.71       cgd int scsibussubmatch __P((struct device *, struct cfdata *, void *));
    109       1.12   mycroft 
    110       1.53   thorpej struct cfattach scsibus_ca = {
    111      1.126   thorpej 	sizeof(struct scsibus_softc), scsibusmatch, scsibusattach,
    112      1.126   thorpej 	    scsibusdetach, scsibusactivate,
    113       1.53   thorpej };
    114       1.53   thorpej 
    115       1.94   thorpej extern struct cfdriver scsibus_cd;
    116       1.12   mycroft 
    117       1.61       cgd int scsibusprint __P((void *, const char *));
    118      1.128   thorpej void scsibus_config_interrupts __P((struct device *));
    119       1.51   thorpej 
    120      1.111   thorpej cdev_decl(scsibus);
    121       1.62       cgd 
    122       1.62       cgd int
    123       1.71       cgd scsibusmatch(parent, cf, aux)
    124       1.62       cgd 	struct device *parent;
    125       1.71       cgd 	struct cfdata *cf;
    126       1.71       cgd 	void *aux;
    127       1.12   mycroft {
    128       1.88    bouyer 	struct scsipi_link *l = aux;
    129       1.62       cgd 	int channel;
    130      1.139  augustss 
    131      1.139  augustss 	if (l->type != BUS_SCSI)
    132      1.139  augustss 		return (0);
    133       1.62       cgd 
    134       1.62       cgd 	/*
    135       1.62       cgd 	 * Allow single-channel controllers to specify their channel
    136       1.62       cgd 	 * in a special way, so that it's not printed.
    137       1.62       cgd 	 */
    138       1.88    bouyer 	channel = (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) ?
    139       1.92     enami 	    l->scsipi_scsi.channel : 0;
    140       1.62       cgd 
    141       1.88    bouyer 	if (cf->cf_loc[SCSICF_CHANNEL] != channel &&
    142       1.92     enami 	    cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
    143       1.62       cgd 		return (0);
    144       1.12   mycroft 
    145       1.62       cgd 	return (1);
    146       1.12   mycroft }
    147       1.12   mycroft 
    148       1.12   mycroft /*
    149       1.12   mycroft  * The routine called by the adapter boards to get all their
    150       1.12   mycroft  * devices configured in.
    151       1.12   mycroft  */
    152       1.12   mycroft void
    153       1.12   mycroft scsibusattach(parent, self, aux)
    154       1.88    bouyer 	struct device *parent, *self;
    155       1.88    bouyer 	void *aux;
    156       1.12   mycroft {
    157       1.18   mycroft 	struct scsibus_softc *sb = (struct scsibus_softc *)self;
    158       1.88    bouyer 	struct scsipi_link *sc_link_proto = aux;
    159       1.72   thorpej 	size_t nbytes;
    160       1.72   thorpej 	int i;
    161       1.12   mycroft 
    162       1.88    bouyer 	sc_link_proto->scsipi_scsi.scsibus = sb->sc_dev.dv_unit;
    163       1.88    bouyer 	sc_link_proto->scsipi_cmd = scsi_scsipi_cmd;
    164      1.115    bouyer 	sc_link_proto->scsipi_interpret_sense = scsipi_interpret_sense;
    165       1.88    bouyer 	sc_link_proto->sc_print_addr = scsi_print_addr;
    166      1.131     enami 	sc_link_proto->scsipi_kill_pending = scsi_kill_pending;
    167       1.88    bouyer 
    168       1.12   mycroft 	sb->adapter_link = sc_link_proto;
    169       1.88    bouyer 	sb->sc_maxtarget = sc_link_proto->scsipi_scsi.max_target;
    170      1.119    mjacob 	sb->sc_maxlun = sc_link_proto->scsipi_scsi.max_lun;
    171      1.119    mjacob 	printf(": %d targets, %d luns per target\n",
    172      1.119    mjacob 	    sb->sc_maxtarget + 1, sb->sc_maxlun + 1);
    173      1.103   thorpej 
    174      1.103   thorpej 	/* Initialize shared data. */
    175      1.103   thorpej 	scsipi_init();
    176       1.72   thorpej 
    177      1.119    mjacob 	nbytes = (sb->sc_maxtarget + 1) * sizeof(struct scsipi_link **);
    178       1.88    bouyer 	sb->sc_link = (struct scsipi_link ***)malloc(nbytes, M_DEVBUF,
    179       1.92     enami 	    M_NOWAIT);
    180       1.72   thorpej 	if (sb->sc_link == NULL)
    181       1.72   thorpej 		panic("scsibusattach: can't allocate target links");
    182       1.72   thorpej 
    183      1.119    mjacob 	nbytes = (((int) sb->sc_maxlun) + 1) * sizeof(struct scsipi_link *);
    184       1.72   thorpej 	for (i = 0; i <= sb->sc_maxtarget; i++) {
    185       1.88    bouyer 		sb->sc_link[i] = (struct scsipi_link **)malloc(nbytes,
    186       1.92     enami 		    M_DEVBUF, M_NOWAIT);
    187       1.72   thorpej 		if (sb->sc_link[i] == NULL)
    188       1.72   thorpej 			panic("scsibusattach: can't allocate lun links");
    189       1.73   mycroft 		bzero(sb->sc_link[i], nbytes);
    190       1.72   thorpej 	}
    191       1.12   mycroft 
    192      1.128   thorpej 	/*
    193      1.128   thorpej 	 * Defer configuration of the children until interrupts
    194      1.128   thorpej 	 * are enabled.
    195      1.128   thorpej 	 */
    196      1.128   thorpej 	config_interrupts(self, scsibus_config_interrupts);
    197      1.128   thorpej }
    198      1.128   thorpej 
    199      1.128   thorpej void
    200      1.128   thorpej scsibus_config_interrupts(self)
    201      1.128   thorpej 	struct device *self;
    202      1.128   thorpej {
    203      1.132     soren #ifndef SCSI_DELAY
    204       1.12   mycroft #define SCSI_DELAY 2
    205      1.132     soren #endif
    206      1.128   thorpej 	if (SCSI_DELAY > 0) {
    207      1.128   thorpej 		printf("%s: waiting %d seconds for devices to settle...\n",
    208      1.128   thorpej 		    self->dv_xname, SCSI_DELAY);
    209      1.128   thorpej 		/* ...an identifier we know no one will use... */
    210      1.128   thorpej 		(void) tsleep(scsibus_config_interrupts, PRIBIO,
    211      1.128   thorpej 		    "scsidly", SCSI_DELAY * hz);
    212      1.128   thorpej 	}
    213      1.128   thorpej 
    214      1.128   thorpej 	scsi_probe_bus(self->dv_unit, -1, -1);
    215       1.12   mycroft }
    216       1.12   mycroft 
    217       1.18   mycroft int
    218       1.71       cgd scsibussubmatch(parent, cf, aux)
    219       1.18   mycroft 	struct device *parent;
    220       1.71       cgd 	struct cfdata *cf;
    221       1.71       cgd 	void *aux;
    222       1.18   mycroft {
    223       1.88    bouyer 	struct scsipibus_attach_args *sa = aux;
    224       1.88    bouyer 	struct scsipi_link *sc_link = sa->sa_sc_link;
    225       1.18   mycroft 
    226       1.88    bouyer 	if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
    227       1.92     enami 	    cf->cf_loc[SCSIBUSCF_TARGET] != sc_link->scsipi_scsi.target)
    228       1.92     enami 		return (0);
    229       1.88    bouyer 	if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
    230       1.92     enami 	    cf->cf_loc[SCSIBUSCF_LUN] != sc_link->scsipi_scsi.lun)
    231       1.92     enami 		return (0);
    232       1.71       cgd 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    233      1.126   thorpej }
    234      1.126   thorpej 
    235      1.126   thorpej int
    236      1.126   thorpej scsibusactivate(self, act)
    237      1.126   thorpej 	struct device *self;
    238      1.126   thorpej 	enum devact act;
    239      1.126   thorpej {
    240      1.126   thorpej 	struct scsibus_softc *sc = (struct scsibus_softc *) self;
    241      1.126   thorpej 	struct scsipi_link *sc_link;
    242      1.126   thorpej 	int target, lun, error = 0, s;
    243      1.126   thorpej 
    244      1.126   thorpej 	s = splbio();
    245      1.126   thorpej 	switch (act) {
    246      1.126   thorpej 	case DVACT_ACTIVATE:
    247      1.126   thorpej 		error = EOPNOTSUPP;
    248      1.126   thorpej 		break;
    249      1.126   thorpej 
    250      1.126   thorpej 	case DVACT_DEACTIVATE:
    251      1.126   thorpej 		for (target = 0; target <= sc->sc_maxtarget; target++) {
    252      1.126   thorpej 			if (target ==
    253      1.126   thorpej 			    sc->adapter_link->scsipi_scsi.adapter_target)
    254      1.126   thorpej 				continue;
    255      1.126   thorpej 			for (lun = 0; lun <= sc->sc_maxlun; lun++) {
    256      1.126   thorpej 				sc_link = sc->sc_link[target][lun];
    257      1.126   thorpej 				if (sc_link == NULL)
    258      1.126   thorpej 					continue;
    259      1.126   thorpej 				error =
    260      1.126   thorpej 				    config_deactivate(sc_link->device_softc);
    261      1.126   thorpej 				if (error)
    262      1.126   thorpej 					goto out;
    263      1.126   thorpej 			}
    264      1.126   thorpej 		}
    265      1.126   thorpej 		break;
    266      1.126   thorpej 	}
    267      1.126   thorpej  out:
    268      1.126   thorpej 	splx(s);
    269      1.126   thorpej 	return (error);
    270      1.126   thorpej }
    271      1.126   thorpej 
    272      1.126   thorpej int
    273      1.126   thorpej scsibusdetach(self, flags)
    274      1.126   thorpej 	struct device *self;
    275      1.126   thorpej 	int flags;
    276      1.126   thorpej {
    277      1.126   thorpej 	struct scsibus_softc *sc = (struct scsibus_softc *) self;
    278      1.126   thorpej 	struct scsipi_link *sc_link;
    279      1.126   thorpej 	int target, lun, error;
    280      1.126   thorpej 
    281      1.126   thorpej 	for (target = 0; target <= sc->sc_maxtarget; target++) {
    282      1.126   thorpej 		if (target == sc->adapter_link->scsipi_scsi.adapter_target)
    283      1.126   thorpej 			continue;
    284      1.126   thorpej 		for (lun = 0; lun <= sc->sc_maxlun; lun++) {
    285      1.126   thorpej 			sc_link = sc->sc_link[target][lun];
    286      1.126   thorpej 			if (sc_link == NULL)
    287      1.126   thorpej 				continue;
    288      1.126   thorpej 			error = config_detach(sc_link->device_softc, flags);
    289      1.126   thorpej 			if (error)
    290      1.126   thorpej 				return (error);
    291      1.126   thorpej 			free(sc_link, M_DEVBUF);
    292      1.126   thorpej 			sc->sc_link[target][lun] = NULL;
    293      1.126   thorpej 		}
    294      1.126   thorpej 	}
    295      1.126   thorpej 	return (0);
    296       1.18   mycroft }
    297       1.18   mycroft 
    298       1.12   mycroft /*
    299       1.12   mycroft  * Probe the requested scsi bus. It must be already set up.
    300       1.12   mycroft  * -1 requests all set up scsi busses.
    301       1.18   mycroft  * target and lun optionally narrow the search if not -1
    302       1.12   mycroft  */
    303       1.12   mycroft int
    304       1.18   mycroft scsi_probe_busses(bus, target, lun)
    305       1.18   mycroft 	int bus, target, lun;
    306       1.12   mycroft {
    307       1.12   mycroft 
    308       1.12   mycroft 	if (bus == -1) {
    309       1.53   thorpej 		for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++)
    310       1.53   thorpej 			if (scsibus_cd.cd_devs[bus])
    311       1.18   mycroft 				scsi_probe_bus(bus, target, lun);
    312       1.92     enami 		return (0);
    313       1.92     enami 	} else
    314       1.92     enami 		return (scsi_probe_bus(bus, target, lun));
    315       1.12   mycroft }
    316       1.12   mycroft 
    317       1.12   mycroft /*
    318       1.12   mycroft  * Probe the requested scsi bus. It must be already set up.
    319       1.18   mycroft  * target and lun optionally narrow the search if not -1
    320       1.12   mycroft  */
    321       1.12   mycroft int
    322       1.18   mycroft scsi_probe_bus(bus, target, lun)
    323       1.18   mycroft 	int bus, target, lun;
    324       1.12   mycroft {
    325       1.18   mycroft 	struct scsibus_softc *scsi;
    326      1.153        ad 	struct scsipi_link *sc_link;
    327       1.18   mycroft 	int maxtarget, mintarget, maxlun, minlun;
    328       1.18   mycroft 	u_int8_t scsi_addr;
    329      1.116   thorpej 	int error;
    330       1.12   mycroft 
    331       1.53   thorpej 	if (bus < 0 || bus >= scsibus_cd.cd_ndevs)
    332       1.92     enami 		return (ENXIO);
    333       1.53   thorpej 	scsi = scsibus_cd.cd_devs[bus];
    334       1.92     enami 	if (scsi == NULL)
    335       1.92     enami 		return (ENXIO);
    336       1.12   mycroft 
    337      1.153        ad 	sc_link = scsi->adapter_link;
    338      1.153        ad 	scsi_addr = sc_link->scsipi_scsi.adapter_target;
    339       1.12   mycroft 
    340       1.18   mycroft 	if (target == -1) {
    341       1.72   thorpej 		maxtarget = scsi->sc_maxtarget;
    342       1.18   mycroft 		mintarget = 0;
    343       1.12   mycroft 	} else {
    344       1.72   thorpej 		if (target < 0 || target > scsi->sc_maxtarget)
    345       1.92     enami 			return (EINVAL);
    346       1.18   mycroft 		maxtarget = mintarget = target;
    347       1.12   mycroft 	}
    348        1.1       cgd 
    349       1.12   mycroft 	if (lun == -1) {
    350      1.119    mjacob 		maxlun = scsi->sc_maxlun;
    351       1.12   mycroft 		minlun = 0;
    352       1.12   mycroft 	} else {
    353      1.119    mjacob 		if (lun < 0 || lun > scsi->sc_maxlun)
    354       1.92     enami 			return (EINVAL);
    355       1.12   mycroft 		maxlun = minlun = lun;
    356       1.12   mycroft 	}
    357       1.12   mycroft 
    358      1.153        ad 	/*
    359      1.153        ad 	 * Some HBAs provide an abstracted view of the bus; give them an
    360      1.153        ad 	 * oppertunity to re-scan it before we do.
    361      1.153        ad 	 */
    362      1.153        ad 	if (sc_link->adapter->scsipi_ioctl != NULL)
    363      1.153        ad 		(*sc_link->adapter->scsipi_ioctl)(sc_link, SCBUSIOLLSCAN, NULL,
    364  1.156.2.1   nathanw 		    0, curproc->l_proc);
    365      1.153        ad 
    366      1.153        ad 	if ((error = scsipi_adapter_addref(sc_link)) != 0)
    367      1.116   thorpej 		return (error);
    368       1.18   mycroft 	for (target = mintarget; target <= maxtarget; target++) {
    369       1.18   mycroft 		if (target == scsi_addr)
    370       1.12   mycroft 			continue;
    371       1.12   mycroft 		for (lun = minlun; lun <= maxlun; lun++) {
    372       1.12   mycroft 			/*
    373       1.18   mycroft 			 * See if there's a device present, and configure it.
    374       1.12   mycroft 			 */
    375      1.119    mjacob 			if (scsi_probedev(scsi, target, lun) == 0) {
    376       1.18   mycroft 				break;
    377      1.119    mjacob 			}
    378       1.12   mycroft 			/* otherwise something says we should look further */
    379       1.12   mycroft 		}
    380        1.8   deraadt 	}
    381      1.153        ad 	scsipi_adapter_delref(sc_link);
    382       1.92     enami 	return (0);
    383       1.12   mycroft }
    384       1.12   mycroft 
    385       1.88    bouyer /*
    386       1.88    bouyer  * Print out autoconfiguration information for a subdevice.
    387       1.88    bouyer  *
    388       1.88    bouyer  * This is a slight abuse of 'standard' autoconfiguration semantics,
    389       1.88    bouyer  * because 'print' functions don't normally print the colon and
    390       1.88    bouyer  * device information.  However, in this case that's better than
    391       1.88    bouyer  * either printing redundant information before the attach message,
    392       1.88    bouyer  * or having the device driver call a special function to print out
    393       1.88    bouyer  * the standard device information.
    394       1.88    bouyer  */
    395       1.88    bouyer int
    396       1.88    bouyer scsibusprint(aux, pnp)
    397       1.88    bouyer 	void *aux;
    398       1.88    bouyer 	const char *pnp;
    399       1.12   mycroft {
    400       1.88    bouyer 	struct scsipibus_attach_args *sa = aux;
    401       1.88    bouyer 	struct scsipi_inquiry_pattern *inqbuf;
    402       1.88    bouyer 	u_int8_t type;
    403       1.88    bouyer 	char *dtype, *qtype;
    404       1.88    bouyer 	char vendor[33], product[65], revision[17];
    405       1.88    bouyer 	int target, lun;
    406       1.88    bouyer 
    407       1.88    bouyer 	if (pnp != NULL)
    408       1.88    bouyer 		printf("%s", pnp);
    409       1.88    bouyer 
    410       1.88    bouyer 	inqbuf = &sa->sa_inqbuf;
    411       1.88    bouyer 
    412       1.88    bouyer 	target = sa->sa_sc_link->scsipi_scsi.target;
    413       1.88    bouyer 	lun = sa->sa_sc_link->scsipi_scsi.lun;
    414       1.88    bouyer 
    415       1.88    bouyer 	type = inqbuf->type & SID_TYPE;
    416       1.88    bouyer 
    417       1.88    bouyer 	/*
    418       1.88    bouyer 	 * Figure out basic device type and qualifier.
    419       1.88    bouyer 	 */
    420       1.88    bouyer 	dtype = 0;
    421       1.88    bouyer 	switch (inqbuf->type & SID_QUAL) {
    422       1.88    bouyer 	case SID_QUAL_LU_OK:
    423       1.88    bouyer 		qtype = "";
    424       1.88    bouyer 		break;
    425       1.88    bouyer 
    426       1.88    bouyer 	case SID_QUAL_LU_OFFLINE:
    427       1.88    bouyer 		qtype = " offline";
    428       1.88    bouyer 		break;
    429       1.88    bouyer 
    430       1.88    bouyer 	case SID_QUAL_RSVD:
    431       1.88    bouyer 	case SID_QUAL_BAD_LU:
    432       1.88    bouyer 		panic("scsibusprint: impossible qualifier");
    433       1.12   mycroft 
    434       1.88    bouyer 	default:
    435       1.88    bouyer 		qtype = "";
    436       1.88    bouyer 		dtype = "vendor-unique";
    437       1.88    bouyer 		break;
    438       1.88    bouyer 	}
    439       1.92     enami 	if (dtype == 0)
    440       1.88    bouyer 		dtype = scsipi_dtype(type);
    441        1.2   deraadt 
    442      1.104  drochner 	scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
    443      1.104  drochner 	scsipi_strvis(product, 65, inqbuf->product, 16);
    444      1.104  drochner 	scsipi_strvis(revision, 17, inqbuf->revision, 4);
    445       1.88    bouyer 
    446      1.138  augustss 	printf(" target %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
    447       1.92     enami 	    target, lun, vendor, product, revision,
    448       1.92     enami 	    sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
    449       1.92     enami 	    inqbuf->removable ? "removable" : "fixed", qtype);
    450       1.88    bouyer 
    451       1.88    bouyer 	return (UNCONF);
    452       1.12   mycroft }
    453        1.1       cgd 
    454      1.154  jdolecek const struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    455       1.48  christos 	{{T_CDROM, T_REMOV,
    456       1.48  christos 	 "CHINON  ", "CD-ROM CDS-431  ", ""},     SDEV_NOLUNS},
    457       1.48  christos 	{{T_CDROM, T_REMOV,
    458       1.48  christos 	 "Chinon  ", "CD-ROM CDS-525  ", ""},     SDEV_NOLUNS},
    459       1.48  christos 	{{T_CDROM, T_REMOV,
    460       1.48  christos 	 "CHINON  ", "CD-ROM CDS-535  ", ""},     SDEV_NOLUNS},
    461      1.100   thorpej 	{{T_CDROM, T_REMOV,
    462      1.100   thorpej 	 "DEC     ", "RRD42   (C) DEC ", ""},     SDEV_NOLUNS},
    463       1.48  christos 	{{T_CDROM, T_REMOV,
    464       1.48  christos 	 "DENON   ", "DRD-25X         ", "V"},    SDEV_NOLUNS},
    465      1.148    bouyer 	{{T_CDROM, T_REMOV,
    466      1.148    bouyer 	 "GENERIC ", "CRD-BP2         ", ""},     SDEV_NOLUNS},
    467       1.83   mycroft 	{{T_CDROM, T_REMOV,
    468       1.83   mycroft 	 "HP      ", "C4324/C4325     ", ""},     SDEV_NOLUNS},
    469       1.48  christos 	{{T_CDROM, T_REMOV,
    470       1.48  christos 	 "IMS     ", "CDD521/10       ", "2.06"}, SDEV_NOLUNS},
    471       1.48  christos 	{{T_CDROM, T_REMOV,
    472       1.68     mikel 	 "MATSHITA", "CD-ROM CR-5XX   ", "1.0b"}, SDEV_NOLUNS},
    473       1.68     mikel 	{{T_CDROM, T_REMOV,
    474       1.88    bouyer 	 "MEDAVIS ", "RENO CD-ROMX2A  ", ""},     SDEV_NOLUNS},
    475       1.84     perry 	{{T_CDROM, T_REMOV,
    476       1.77     mikel 	 "MEDIAVIS", "CDR-H93MV       ", "1.3"},  SDEV_NOLUNS},
    477       1.48  christos 	{{T_CDROM, T_REMOV,
    478       1.48  christos 	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     SDEV_NOLUNS},
    479       1.48  christos 	{{T_CDROM, T_REMOV,
    480       1.48  christos 	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     SDEV_NOLUNS},
    481       1.48  christos 	{{T_CDROM, T_REMOV,
    482       1.48  christos 	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     SDEV_NOLUNS},
    483       1.48  christos 	{{T_CDROM, T_REMOV,
    484       1.48  christos 	 "NEC     ", "CD-ROM DRIVE:841", ""},     SDEV_NOLUNS},
    485       1.70   thorpej 	{{T_CDROM, T_REMOV,
    486       1.70   thorpej 	 "PIONEER ", "CD-ROM DR-124X  ", "1.01"}, SDEV_NOLUNS},
    487       1.48  christos 	{{T_CDROM, T_REMOV,
    488       1.48  christos 	 "SONY    ", "CD-ROM CDU-541  ", ""},     SDEV_NOLUNS},
    489       1.48  christos 	{{T_CDROM, T_REMOV,
    490       1.48  christos 	 "SONY    ", "CD-ROM CDU-55S  ", ""},     SDEV_NOLUNS},
    491      1.130       hwr 	{{T_CDROM, T_REMOV,
    492      1.130       hwr 	 "SONY    ", "CD-ROM CDU-561  ", ""},     SDEV_NOLUNS},
    493       1.48  christos 	{{T_CDROM, T_REMOV,
    494       1.48  christos 	 "SONY    ", "CD-ROM CDU-8003A", ""},     SDEV_NOLUNS},
    495       1.48  christos 	{{T_CDROM, T_REMOV,
    496       1.48  christos 	 "SONY    ", "CD-ROM CDU-8012 ", ""},     SDEV_NOLUNS},
    497       1.48  christos 	{{T_CDROM, T_REMOV,
    498       1.48  christos 	 "TEAC    ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    499       1.69  explorer 	{{T_CDROM, T_REMOV,
    500       1.69  explorer 	 "TEAC    ", "CD-ROM CD-56S   ", "1.0B"}, SDEV_NOLUNS},
    501       1.48  christos 	{{T_CDROM, T_REMOV,
    502       1.48  christos 	 "TEXEL   ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    503      1.127   nathanw 	{{T_CDROM, T_REMOV,
    504      1.127   nathanw 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.09"}, SDEV_NOLUNS},
    505       1.48  christos 	{{T_CDROM, T_REMOV,
    506       1.48  christos 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
    507       1.89        pk 	{{T_CDROM, T_REMOV,
    508      1.152        pk 	 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS|SDEV_NOSYNC},
    509       1.92     enami 	{{T_CDROM, T_REMOV,
    510       1.92     enami 	 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS},
    511       1.98  explorer 	{{T_CDROM, T_REMOV,
    512      1.124  explorer 	 "JVC     ", "R2626",            ""},     SDEV_NOLUNS},
    513      1.137       sjg 	{{T_CDROM, T_REMOV,
    514      1.137       sjg 	 "YAMAHA", "CRW8424S",           ""},     SDEV_NOLUNS},
    515      1.156      fvdl 	{{T_CDROM, T_REMOV,
    516      1.156      fvdl 	 "VMware", "Virtual",           "1.0"},
    517      1.156      fvdl 				SDEV_NOSTARTUNIT|ADEV_NODOORLOCK},
    518      1.156      fvdl 
    519       1.80        pk 	{{T_DIRECT, T_FIXED,
    520       1.80        pk 	 "MICROP  ", "1588-15MBSUN0669", ""},     SDEV_AUTOSAVE},
    521      1.110   thorpej 	{{T_DIRECT, T_FIXED,
    522      1.110   thorpej 	 "MICROP  ", "2217-15MQ1091501", ""},     SDEV_NOSYNCCACHE},
    523       1.55    scottr 	{{T_OPTICAL, T_REMOV,
    524       1.55    scottr 	 "EPSON   ", "OMD-5010        ", "3.08"}, SDEV_NOLUNS},
    525      1.129       hwr 	{{T_DIRECT, T_FIXED,
    526      1.144    bouyer 	"TOSHIBA ", "CD-ROM XM-3401TA", "0283"}, SDEV_CDROM|SDEV_NOLUNS},
    527      1.122    mjacob 	{{T_DIRECT, T_FIXED,
    528      1.144    bouyer 	"TOSHIBA ", "CD-ROM DRIVE:XM", "1971"}, SDEV_CDROM|SDEV_NOLUNS},
    529      1.143  gmcgarry 	{{T_DIRECT, T_FIXED,
    530      1.122    mjacob 	 "ADAPTEC ", "AEC-4412BD",       "1.2A"}, SDEV_NOMODESENSE},
    531       1.50   mycroft 	{{T_DIRECT, T_FIXED,
    532       1.50   mycroft 	 "DEC     ", "RZ55     (C) DEC", ""},     SDEV_AUTOSAVE},
    533       1.48  christos 	{{T_DIRECT, T_FIXED,
    534       1.78   mycroft 	 "EMULEX  ", "MD21/S2     ESDI", "A00"},  SDEV_FORCELUNS|SDEV_AUTOSAVE},
    535       1.91    bouyer 	/* Gives non-media hardware failure in response to start-unit command */
    536       1.91    bouyer 	{{T_DIRECT, T_FIXED,
    537       1.91    bouyer 	 "HITACHI", "DK515C",		"CP16"},  SDEV_NOSTARTUNIT},
    538       1.91    bouyer 	{{T_DIRECT, T_FIXED,
    539       1.91    bouyer 	 "HITACHI", "DK515C",		"CP15"},  SDEV_NOSTARTUNIT},
    540       1.76    scottr 	{{T_DIRECT, T_FIXED,
    541      1.108    mjacob 	 "HP      ", "C372",             ""},     SDEV_NOTAG},
    542      1.108    mjacob 	{{T_DIRECT, T_FIXED,
    543       1.79    scottr 	 "IBMRAID ", "0662S",		 ""},     SDEV_AUTOSAVE},
    544       1.76    scottr 	{{T_DIRECT, T_FIXED,
    545       1.79    scottr 	 "IBM     ", "0663H",		 ""},     SDEV_AUTOSAVE},
    546       1.82   thorpej 	{{T_DIRECT, T_FIXED,
    547       1.96    scottr 	 "IBM",	     "0664",		 ""},     SDEV_AUTOSAVE},
    548       1.84     perry 	{{T_DIRECT, T_FIXED,
    549       1.96    scottr 	 "IBM     ", "H3171-S2",	 ""},	  SDEV_NOLUNS|SDEV_AUTOSAVE},
    550       1.96    scottr 	{{T_DIRECT, T_FIXED,
    551       1.96    scottr 	 "IBM     ", "KZ-C",		 ""},	  SDEV_AUTOSAVE},
    552       1.81   thorpej 	/* Broken IBM disk */
    553       1.81   thorpej 	{{T_DIRECT, T_FIXED,
    554       1.81   thorpej 	 ""	   , "DFRSS2F",		 ""},	  SDEV_AUTOSAVE},
    555       1.87    mjacob 	{{T_DIRECT, T_REMOV,
    556       1.87    mjacob 	 "MPL     ", "MC-DISK-        ", ""},     SDEV_NOLUNS},
    557       1.48  christos 	{{T_DIRECT, T_FIXED,
    558       1.48  christos 	 "MAXTOR  ", "XT-3280         ", ""},     SDEV_NOLUNS},
    559       1.48  christos 	{{T_DIRECT, T_FIXED,
    560       1.48  christos 	 "MAXTOR  ", "XT-4380S        ", ""},     SDEV_NOLUNS},
    561       1.48  christos 	{{T_DIRECT, T_FIXED,
    562       1.48  christos 	 "MAXTOR  ", "MXT-1240S       ", ""},     SDEV_NOLUNS},
    563       1.48  christos 	{{T_DIRECT, T_FIXED,
    564       1.48  christos 	 "MAXTOR  ", "XT-4170S        ", ""},     SDEV_NOLUNS},
    565       1.48  christos 	{{T_DIRECT, T_FIXED,
    566       1.60   thorpej 	 "MAXTOR  ", "XT-8760S",         ""},     SDEV_NOLUNS},
    567       1.48  christos 	{{T_DIRECT, T_FIXED,
    568       1.48  christos 	 "MAXTOR  ", "LXT-213S        ", ""},     SDEV_NOLUNS},
    569       1.48  christos 	{{T_DIRECT, T_FIXED,
    570       1.48  christos 	 "MAXTOR  ", "LXT-213S SUN0207", ""},     SDEV_NOLUNS},
    571       1.52   thorpej 	{{T_DIRECT, T_FIXED,
    572       1.52   thorpej 	 "MAXTOR  ", "LXT-200S        ", ""},     SDEV_NOLUNS},
    573       1.48  christos 	{{T_DIRECT, T_FIXED,
    574       1.90    mjacob 	 "MEGADRV ", "EV1000",           ""},     SDEV_NOMODESENSE},
    575       1.90    mjacob 	{{T_DIRECT, T_FIXED,
    576       1.48  christos 	 "MST     ", "SnapLink        ", ""},     SDEV_NOLUNS},
    577       1.54   hpeyerl 	{{T_DIRECT, T_FIXED,
    578       1.54   hpeyerl 	 "NEC     ", "D3847           ", "0307"}, SDEV_NOLUNS},
    579       1.96    scottr 	{{T_DIRECT, T_FIXED,
    580       1.96    scottr 	 "QUANTUM ", "ELS85S          ", ""},     SDEV_AUTOSAVE},
    581       1.48  christos 	{{T_DIRECT, T_FIXED,
    582       1.48  christos 	 "QUANTUM ", "LPS525S         ", ""},     SDEV_NOLUNS},
    583       1.48  christos 	{{T_DIRECT, T_FIXED,
    584       1.48  christos 	 "QUANTUM ", "P105S 910-10-94x", ""},     SDEV_NOLUNS},
    585       1.48  christos 	{{T_DIRECT, T_FIXED,
    586       1.48  christos 	 "QUANTUM ", "PD1225S         ", ""},     SDEV_NOLUNS},
    587       1.48  christos 	{{T_DIRECT, T_FIXED,
    588       1.48  christos 	 "QUANTUM ", "PD210S   SUN0207", ""},     SDEV_NOLUNS},
    589       1.48  christos 	{{T_DIRECT, T_FIXED,
    590       1.48  christos 	 "RODIME  ", "RO3000S         ", ""},     SDEV_NOLUNS},
    591       1.75    scottr 	{{T_DIRECT, T_FIXED,
    592       1.75    scottr 	 "SEAGATE ", "ST125N          ", ""},     SDEV_NOLUNS},
    593       1.48  christos 	{{T_DIRECT, T_FIXED,
    594       1.48  christos 	 "SEAGATE ", "ST157N          ", ""},     SDEV_NOLUNS},
    595       1.48  christos 	{{T_DIRECT, T_FIXED,
    596       1.48  christos 	 "SEAGATE ", "ST296           ", ""},     SDEV_NOLUNS},
    597       1.48  christos 	{{T_DIRECT, T_FIXED,
    598       1.48  christos 	 "SEAGATE ", "ST296N          ", ""},     SDEV_NOLUNS},
    599       1.86    mjacob 	{{T_DIRECT, T_FIXED,
    600      1.120    mjacob 	 "SEAGATE ", "ST19171",          ""},     SDEV_NOMODESENSE},
    601       1.90    mjacob 	{{T_DIRECT, T_FIXED,
    602       1.90    mjacob 	 "SEAGATE ", "ST34501FC       ", ""},     SDEV_NOMODESENSE},
    603       1.48  christos 	{{T_DIRECT, T_FIXED,
    604       1.48  christos 	 "TOSHIBA ", "MK538FB         ", "6027"}, SDEV_NOLUNS},
    605      1.156      fvdl 	{{T_DIRECT, T_FIXED,
    606      1.156      fvdl 	 "VMware", "Virtual",           "1.0"},
    607      1.156      fvdl 				SDEV_NOSTARTUNIT|ADEV_NODOORLOCK},
    608      1.156      fvdl 
    609       1.58  christos 	{{T_DIRECT, T_REMOV,
    610       1.58  christos 	 "iomega", "jaz 1GB", 		 ""},	  SDEV_NOMODESENSE},
    611       1.59  explorer 	{{T_DIRECT, T_REMOV,
    612       1.67  matthias 	 "IOMEGA", "ZIP 100",		 ""},	  SDEV_NOMODESENSE},
    613      1.118       leo 	{{T_DIRECT, T_REMOV,
    614      1.118       leo 	 "IOMEGA", "ZIP 100",		 "J.03"}, SDEV_NOMODESENSE|SDEV_NOLUNS},
    615       1.85  explorer 	/* Letting the motor run kills floppy drives and disks quite fast. */
    616       1.67  matthias 	{{T_DIRECT, T_REMOV,
    617       1.67  matthias 	 "TEAC", "FC-1",		 ""},	  SDEV_NOSTARTUNIT},
    618      1.145  augustss 
    619      1.145  augustss 	{{T_DIRECT, T_REMOV,
    620      1.145  augustss 	 "Y-E DATA", "USB-FDU",		 "3.04"}, SDEV_NOMODESENSE},
    621      1.146  augustss 	{{T_DIRECT, T_REMOV,
    622      1.146  augustss 	 "TEAC", "FD-05PUB",		 "1026"}, SDEV_NOMODESENSE},
    623       1.18   mycroft 
    624       1.37       cgd 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    625       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    626       1.48  christos 	 "        ", "                ", "    "}, SDEV_NOLUNS},
    627       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    628       1.48  christos 	 "CALIPER ", "CP150           ", ""},     SDEV_NOLUNS},
    629       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    630       1.48  christos 	 "EXABYTE ", "EXB-8200        ", ""},     SDEV_NOLUNS},
    631       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    632       1.87    mjacob 	 "SONY    ", "GY-10C          ", ""},     SDEV_NOLUNS},
    633       1.87    mjacob 	{{T_SEQUENTIAL, T_REMOV,
    634       1.48  christos 	 "SONY    ", "SDT-2000        ", "2.09"}, SDEV_NOLUNS},
    635       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    636      1.108    mjacob 	 "SONY    ", "SDT-5000        ", "3."},   SDEV_NOSYNC|SDEV_NOWIDE},
    637       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    638       1.48  christos 	 "SONY    ", "SDT-5200        ", "3."},   SDEV_NOLUNS},
    639       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    640       1.48  christos 	 "TANDBERG", " TDC 3600       ", ""},     SDEV_NOLUNS},
    641       1.47        pk 	/* Following entry reported as a Tandberg 3600; ref. PR1933 */
    642       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    643       1.48  christos 	 "ARCHIVE ", "VIPER 150  21247", ""},     SDEV_NOLUNS},
    644       1.91    bouyer 	/* Following entry for a Cipher ST150S; ref. PR4171 */
    645       1.91    bouyer 	{{T_SEQUENTIAL, T_REMOV,
    646       1.91    bouyer 	 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS},
    647       1.80        pk 	{{T_SEQUENTIAL, T_REMOV,
    648       1.80        pk 	 "ARCHIVE ", "Python 28454-XXX", ""},     SDEV_NOLUNS},
    649       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    650       1.48  christos 	 "WANGTEK ", "5099ES SCSI",      ""},     SDEV_NOLUNS},
    651       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    652       1.48  christos 	 "WANGTEK ", "5150ES SCSI",      ""},     SDEV_NOLUNS},
    653      1.125       hwr 	{{T_SEQUENTIAL, T_REMOV,
    654      1.125       hwr 	 "WANGTEK ", "SCSI-36",		 ""},     SDEV_NOLUNS},
    655       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    656      1.108    mjacob 	 "WangDAT ", "Model 1300      ", "02.4"}, SDEV_NOSYNC|SDEV_NOWIDE},
    657       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    658      1.108    mjacob 	 "WangDAT ", "Model 2600      ", "01.7"}, SDEV_NOSYNC|SDEV_NOWIDE},
    659       1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    660      1.108    mjacob 	 "WangDAT ", "Model 3200      ", "02.2"}, SDEV_NOSYNC|SDEV_NOWIDE},
    661      1.133  nisimura 	{{T_SEQUENTIAL, T_REMOV,
    662      1.133  nisimura 	 "TEAC    ", "MT-2ST/N50      ", ""},     SDEV_NOLUNS},
    663       1.87    mjacob 
    664      1.101    bouyer 	{{T_SCANNER, T_FIXED,
    665      1.101    bouyer 	 "RICOH   ", "IS60            ", "1R08"}, SDEV_NOLUNS},
    666       1.99   thorpej 	{{T_SCANNER, T_FIXED,
    667       1.99   thorpej 	 "UMAX    ", "Astra 1200S     ", "V2.9"}, SDEV_NOLUNS},
    668      1.102      fvdl 	{{T_SCANNER, T_FIXED,
    669      1.123      tron 	 "UMAX    ", "Astra 1220S     ", ""}, SDEV_NOLUNS},
    670       1.85  explorer 	{{T_SCANNER, T_FIXED,
    671       1.85  explorer 	 "UMAX    ", "UMAX S-6E       ", "V2.0"}, SDEV_NOLUNS},
    672       1.95     mikel 	{{T_SCANNER, T_FIXED,
    673       1.95     mikel 	 "UMAX    ", "UMAX S-12       ", "V2.1"}, SDEV_NOLUNS},
    674      1.135    martin 	{{T_SCANNER, T_FIXED,
    675      1.135    martin 	 "ULTIMA  ", "A6000C          ", ""}, SDEV_NOLUNS},
    676      1.150    mjacob 	{{T_PROCESSOR, T_FIXED,
    677      1.150    mjacob 	 "SYMBIOS", "", ""},     SDEV_NOLUNS},
    678       1.87    mjacob 	{{T_PROCESSOR, T_FIXED,
    679       1.87    mjacob 	 "LITRONIC", "PCMCIA          ", ""},     SDEV_NOLUNS},
    680      1.109   thorpej 	{{T_CHANGER, T_REMOV,
    681      1.109   thorpej 	 "SONY    ", "CDL1100         ", ""},     SDEV_NOLUNS},
    682      1.119    mjacob 	{{T_ENCLOSURE, T_FIXED,
    683      1.134    mjacob 	 "SUN     ", "SENA            ", ""},     SDEV_NOLUNS},
    684       1.18   mycroft };
    685       1.18   mycroft 
    686       1.12   mycroft /*
    687       1.95     mikel  * given a target and lun, ask the device what
    688       1.12   mycroft  * it is, and find the correct driver table
    689       1.12   mycroft  * entry.
    690       1.12   mycroft  */
    691      1.119    mjacob int
    692       1.18   mycroft scsi_probedev(scsi, target, lun)
    693       1.18   mycroft 	struct scsibus_softc *scsi;
    694       1.18   mycroft 	int target, lun;
    695       1.18   mycroft {
    696       1.88    bouyer 	struct scsipi_link *sc_link;
    697      1.140     enami 	struct scsipi_inquiry_data inqbuf;
    698       1.18   mycroft 	struct scsi_quirk_inquiry_pattern *finger;
    699      1.119    mjacob 	int checkdtype, priority, docontinue;
    700       1.88    bouyer 	struct scsipibus_attach_args sa;
    701       1.18   mycroft 	struct cfdata *cf;
    702       1.18   mycroft 
    703      1.119    mjacob 	/*
    704      1.119    mjacob 	 * Assume no more luns to search after this one.
    705      1.119    mjacob 	 * If we successfully get Inquiry data and after
    706      1.119    mjacob 	 * merging quirks we find we can probe for more
    707      1.119    mjacob 	 * luns, we will.
    708      1.119    mjacob 	 */
    709      1.119    mjacob 	docontinue = 0;
    710      1.119    mjacob 
    711       1.18   mycroft 	/* Skip this slot if it is already attached. */
    712       1.92     enami 	if (scsi->sc_link[target][lun] != NULL)
    713      1.119    mjacob 		return (docontinue);
    714       1.18   mycroft 
    715       1.18   mycroft 	sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    716       1.18   mycroft 	*sc_link = *scsi->adapter_link;
    717      1.128   thorpej 	sc_link->active = 0;
    718       1.88    bouyer 	sc_link->scsipi_scsi.target = target;
    719       1.88    bouyer 	sc_link->scsipi_scsi.lun = lun;
    720       1.18   mycroft 	sc_link->device = &probe_switch;
    721      1.121   thorpej 	TAILQ_INIT(&sc_link->pending_xfers);
    722       1.12   mycroft 
    723       1.12   mycroft 	/*
    724       1.12   mycroft 	 * Ask the device what it is
    725       1.12   mycroft 	 */
    726       1.88    bouyer #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
    727       1.18   mycroft 	if (target == DEBUGTARGET && lun == DEBUGLUN)
    728       1.12   mycroft 		sc_link->flags |= DEBUGLEVEL;
    729       1.23   mycroft #endif /* SCSIDEBUG */
    730        1.2   deraadt 
    731       1.88    bouyer 	(void) scsipi_test_unit_ready(sc_link,
    732      1.128   thorpej 	    XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
    733      1.128   thorpej 	    XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE);
    734       1.18   mycroft 
    735       1.23   mycroft #ifdef SCSI_2_DEF
    736       1.12   mycroft 	/* some devices need to be told to go to SCSI2 */
    737       1.12   mycroft 	/* However some just explode if you tell them this.. leave it out */
    738      1.128   thorpej 	scsi_change_def(sc_link, XS_CTL_DISCOVERY | XS_CTL_SILENT);
    739       1.18   mycroft #endif /* SCSI_2_DEF */
    740       1.18   mycroft 
    741       1.18   mycroft 	/* Now go ask the device all about itself. */
    742       1.18   mycroft 	bzero(&inqbuf, sizeof(inqbuf));
    743      1.147     enami 	if (scsipi_inquire(sc_link, &inqbuf,
    744      1.147     enami 	    XS_CTL_DISCOVERY | XS_CTL_DATA_ONSTACK) != 0)
    745       1.18   mycroft 		goto bad;
    746       1.18   mycroft 
    747       1.18   mycroft 	{
    748      1.141     dante 		u_int8_t *extension = &inqbuf.flags1;
    749       1.18   mycroft 		int len = inqbuf.additional_length;
    750       1.20   mycroft 		while (len < 3)
    751      1.141     dante 			extension[len++] = '\0';
    752       1.20   mycroft 		while (len < 3 + 28)
    753      1.141     dante 			extension[len++] = ' ';
    754      1.141     dante 		while (len < 3 + 28 + 20)
    755      1.141     dante 			extension[len++] = '\0';
    756      1.141     dante 		while (len < 3 + 28 + 20 + 1)
    757      1.141     dante 			extension[len++] = '\0';
    758      1.142     dante 		while (len < 3 + 28 + 20 + 1 + 1)
    759      1.142     dante 			extension[len++] = '\0';
    760      1.142     dante 		while (len < 3 + 28 + 20 + 1 + 1 + (8*2))
    761      1.142     dante 			extension[len++] = ' ';
    762       1.18   mycroft 	}
    763       1.18   mycroft 
    764       1.88    bouyer 	sa.sa_sc_link = sc_link;
    765       1.88    bouyer 	sa.sa_inqbuf.type = inqbuf.device;
    766       1.88    bouyer 	sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
    767       1.92     enami 	    T_REMOV : T_FIXED;
    768       1.88    bouyer 	sa.sa_inqbuf.vendor = inqbuf.vendor;
    769       1.88    bouyer 	sa.sa_inqbuf.product = inqbuf.product;
    770       1.88    bouyer 	sa.sa_inqbuf.revision = inqbuf.revision;
    771       1.88    bouyer 	sa.scsipi_info.scsi_version = inqbuf.version;
    772      1.134    mjacob 	sa.sa_inqptr = &inqbuf;
    773       1.88    bouyer 
    774       1.92     enami 	finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
    775       1.92     enami 	    &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
    776       1.92     enami 	    sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    777       1.92     enami 	    sizeof(scsi_quirk_patterns[0]), &priority);
    778      1.108    mjacob 
    779      1.108    mjacob 	/*
    780      1.108    mjacob 	 * Based upon the inquiry flags we got back, and if we're
    781      1.108    mjacob 	 * at SCSI-2 or better, set some limiting quirks.
    782      1.108    mjacob 	 */
    783      1.108    mjacob 	if ((inqbuf.version & SID_ANSII) >= 2) {
    784      1.141     dante 		if ((inqbuf.flags3 & SID_CmdQue) == 0)
    785      1.108    mjacob 			sc_link->quirks |= SDEV_NOTAG;
    786      1.141     dante 		if ((inqbuf.flags3 & SID_Sync) == 0)
    787      1.108    mjacob 			sc_link->quirks |= SDEV_NOSYNC;
    788      1.141     dante 		if ((inqbuf.flags3 & SID_WBus16) == 0)
    789      1.108    mjacob 			sc_link->quirks |= SDEV_NOWIDE;
    790      1.155        pk 	} else {
    791      1.155        pk 		/*
    792      1.155        pk 		 * Turn off command tagging for SCSI 1 devices.
    793      1.155        pk 		 * If the need arises, we could define a `SDEV_FORCETAG'
    794      1.155        pk 		 * quirk and set it for pre-SCSI2 devices that actually
    795      1.155        pk 		 * do support tagged commands.
    796      1.155        pk 		 */
    797      1.155        pk 		sc_link->quirks |= SDEV_NOTAG;
    798      1.108    mjacob 	}
    799      1.155        pk 
    800      1.108    mjacob 	/*
    801      1.108    mjacob 	 * Now apply any quirks from the table.
    802      1.108    mjacob 	 */
    803       1.18   mycroft 	if (priority != 0)
    804       1.18   mycroft 		sc_link->quirks |= finger->quirks;
    805       1.36       cgd 	if ((inqbuf.version & SID_ANSII) == 0 &&
    806       1.92     enami 	    (sc_link->quirks & SDEV_FORCELUNS) == 0)
    807       1.18   mycroft 		sc_link->quirks |= SDEV_NOLUNS;
    808       1.88    bouyer 	sc_link->scsipi_scsi.scsi_version = inqbuf.version;
    809      1.143  gmcgarry 
    810      1.144    bouyer 	if (sc_link->quirks & SDEV_CDROM) {
    811      1.144    bouyer 		sc_link->quirks ^= SDEV_CDROM;
    812      1.143  gmcgarry 		inqbuf.dev_qual2 |= SID_REMOVABLE;
    813      1.143  gmcgarry 		sa.sa_inqbuf.type = inqbuf.device = ((inqbuf.device & ~SID_REMOVABLE) | T_CDROM);
    814      1.143  gmcgarry 		sa.sa_inqbuf.removable = T_REMOV;
    815      1.143  gmcgarry 
    816      1.143  gmcgarry 	}
    817       1.12   mycroft 
    818       1.18   mycroft 	if ((sc_link->quirks & SDEV_NOLUNS) == 0)
    819      1.119    mjacob 		docontinue = 1;
    820       1.12   mycroft 
    821       1.12   mycroft 	/*
    822       1.12   mycroft 	 * note what BASIC type of device it is
    823       1.12   mycroft 	 */
    824       1.51   thorpej 	if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
    825       1.18   mycroft 		sc_link->flags |= SDEV_REMOVABLE;
    826       1.12   mycroft 
    827       1.12   mycroft 	/*
    828       1.12   mycroft 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    829       1.12   mycroft 	 * is vendor specific and won't match in this switch.
    830       1.51   thorpej 	 * All we do here is throw out bad/negative responses.
    831       1.12   mycroft 	 */
    832       1.51   thorpej 	checkdtype = 0;
    833       1.18   mycroft 	switch (inqbuf.device & SID_QUAL) {
    834       1.12   mycroft 	case SID_QUAL_LU_OK:
    835       1.12   mycroft 	case SID_QUAL_LU_OFFLINE:
    836       1.51   thorpej 		checkdtype = 1;
    837        1.2   deraadt 		break;
    838       1.12   mycroft 
    839       1.12   mycroft 	case SID_QUAL_RSVD:
    840       1.12   mycroft 	case SID_QUAL_BAD_LU:
    841       1.18   mycroft 		goto bad;
    842       1.12   mycroft 
    843        1.2   deraadt 	default:
    844        1.2   deraadt 		break;
    845        1.2   deraadt 	}
    846      1.151        ad 
    847      1.151        ad 	/* Let the adapter driver handle the device separatley if it wants. */
    848      1.151        ad 	if (sc_link->adapter->scsipi_accesschk != NULL &&
    849      1.151        ad 	    (*sc_link->adapter->scsipi_accesschk)(sc_link, &sa.sa_inqbuf))
    850      1.151        ad 		goto bad;
    851      1.151        ad 
    852      1.149    mjacob 	if (checkdtype) {
    853       1.51   thorpej 		switch (inqbuf.device & SID_TYPE) {
    854        1.2   deraadt 		case T_DIRECT:
    855        1.2   deraadt 		case T_SEQUENTIAL:
    856        1.2   deraadt 		case T_PRINTER:
    857        1.2   deraadt 		case T_PROCESSOR:
    858       1.93   thorpej 		case T_WORM:
    859       1.18   mycroft 		case T_CDROM:
    860        1.2   deraadt 		case T_SCANNER:
    861        1.2   deraadt 		case T_OPTICAL:
    862        1.2   deraadt 		case T_CHANGER:
    863        1.2   deraadt 		case T_COMM:
    864       1.93   thorpej 		case T_IT8_1:
    865       1.93   thorpej 		case T_IT8_2:
    866       1.93   thorpej 		case T_STORARRAY:
    867       1.93   thorpej 		case T_ENCLOSURE:
    868      1.142     dante 		case T_SIMPLE_DIRECT:
    869      1.142     dante 		case T_OPTIC_CARD_RW:
    870      1.142     dante 		case T_OBJECT_STORED:
    871       1.51   thorpej 		default:
    872        1.2   deraadt 			break;
    873       1.12   mycroft 		case T_NODEVICE:
    874       1.18   mycroft 			goto bad;
    875        1.1       cgd 		}
    876      1.149    mjacob 		/*
    877      1.149    mjacob 		 * At this point we can also tell the adapter that it
    878      1.149    mjacob 		 * may negotiate things as appropriate.
    879      1.149    mjacob 		 */
    880      1.149    mjacob 		if (sc_link->adapter->scsipi_ioctl) {
    881      1.149    mjacob 			struct scbusaccel_args s;
    882      1.149    mjacob 			s.sa_target = target;
    883      1.149    mjacob 			s.sa_lun = lun;
    884      1.149    mjacob 			s.sa_flags = 0;
    885      1.149    mjacob 			if ((sc_link->quirks & SDEV_NOTAG) == 0)
    886      1.149    mjacob 				s.sa_flags |= SC_ACCEL_TAGS;
    887      1.149    mjacob 			if ((sc_link->quirks & SDEV_NOSYNC) == 0)
    888      1.149    mjacob 				s.sa_flags |= SC_ACCEL_SYNC;
    889      1.149    mjacob 			if ((sc_link->quirks & SDEV_NOWIDE) == 0)
    890      1.149    mjacob 				s.sa_flags |= SC_ACCEL_WIDE;
    891      1.149    mjacob 			(void) (*sc_link->adapter->scsipi_ioctl)
    892  1.156.2.1   nathanw 			    (sc_link, SCBUSACCEL, (caddr_t)&s, FWRITE,
    893  1.156.2.1   nathanw 				curproc->l_proc);
    894      1.149    mjacob 		}
    895      1.149    mjacob 	}
    896        1.2   deraadt 
    897       1.92     enami 	if ((cf = config_search(scsibussubmatch, (struct device *)scsi,
    898       1.92     enami 	    &sa)) != NULL) {
    899       1.41        pk 		scsi->sc_link[target][lun] = sc_link;
    900       1.51   thorpej 		config_attach((struct device *)scsi, cf, &sa, scsibusprint);
    901       1.51   thorpej 	} else {
    902       1.51   thorpej 		scsibusprint(&sa, scsi->sc_dev.dv_xname);
    903       1.65  christos 		printf(" not configured\n");
    904       1.18   mycroft 		goto bad;
    905       1.51   thorpej 	}
    906       1.18   mycroft 
    907      1.119    mjacob 	return (docontinue);
    908       1.12   mycroft 
    909       1.18   mycroft bad:
    910       1.18   mycroft 	free(sc_link, M_DEVBUF);
    911      1.119    mjacob 	return (docontinue);
    912      1.111   thorpej }
    913      1.111   thorpej 
    914      1.111   thorpej /****** Entry points for user control of the SCSI bus. ******/
    915      1.111   thorpej 
    916      1.111   thorpej int
    917      1.111   thorpej scsibusopen(dev, flag, fmt, p)
    918      1.111   thorpej 	dev_t dev;
    919      1.111   thorpej 	int flag, fmt;
    920      1.111   thorpej 	struct proc *p;
    921      1.111   thorpej {
    922      1.111   thorpej 	struct scsibus_softc *sc;
    923      1.117   thorpej 	int error, unit = minor(dev);
    924      1.111   thorpej 
    925      1.111   thorpej 	if (unit >= scsibus_cd.cd_ndevs ||
    926      1.111   thorpej 	    (sc = scsibus_cd.cd_devs[unit]) == NULL)
    927      1.111   thorpej 		return (ENXIO);
    928      1.111   thorpej 
    929      1.114   thorpej 	if (sc->sc_flags & SCSIBUSF_OPEN)
    930      1.111   thorpej 		return (EBUSY);
    931      1.117   thorpej 
    932      1.117   thorpej 	if ((error = scsipi_adapter_addref(sc->adapter_link)) != 0)
    933      1.117   thorpej 		return (error);
    934      1.117   thorpej 
    935      1.114   thorpej 	sc->sc_flags |= SCSIBUSF_OPEN;
    936      1.111   thorpej 
    937      1.111   thorpej 	return (0);
    938      1.111   thorpej }
    939      1.111   thorpej 
    940      1.111   thorpej int
    941      1.111   thorpej scsibusclose(dev, flag, fmt, p)
    942      1.111   thorpej 	dev_t dev;
    943      1.111   thorpej 	int flag, fmt;
    944      1.111   thorpej 	struct proc *p;
    945      1.111   thorpej {
    946      1.111   thorpej 	struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
    947      1.117   thorpej 
    948      1.117   thorpej 	scsipi_adapter_delref(sc->adapter_link);
    949      1.111   thorpej 
    950      1.114   thorpej 	sc->sc_flags &= ~SCSIBUSF_OPEN;
    951      1.111   thorpej 
    952      1.111   thorpej 	return (0);
    953      1.111   thorpej }
    954      1.111   thorpej 
    955      1.111   thorpej int
    956      1.111   thorpej scsibusioctl(dev, cmd, addr, flag, p)
    957      1.111   thorpej 	dev_t dev;
    958      1.111   thorpej 	u_long cmd;
    959      1.111   thorpej 	caddr_t addr;
    960      1.111   thorpej 	int flag;
    961      1.111   thorpej 	struct proc *p;
    962      1.111   thorpej {
    963      1.111   thorpej 	struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
    964      1.111   thorpej 	struct scsipi_link *sc_link = sc->adapter_link;
    965      1.111   thorpej 	int error;
    966      1.111   thorpej 
    967      1.113   thorpej 	/*
    968      1.113   thorpej 	 * Enforce write permission for ioctls that change the
    969      1.113   thorpej 	 * state of the bus.  Host adapter specific ioctls must
    970      1.113   thorpej 	 * be checked by the adapter driver.
    971      1.113   thorpej 	 */
    972      1.113   thorpej 	switch (cmd) {
    973      1.113   thorpej 	case SCBUSIOSCAN:
    974      1.113   thorpej 	case SCBUSIORESET:
    975      1.113   thorpej 		if ((flag & FWRITE) == 0)
    976      1.113   thorpej 			return (EBADF);
    977      1.113   thorpej 	}
    978      1.113   thorpej 
    979      1.111   thorpej 	switch (cmd) {
    980      1.112   thorpej 	case SCBUSIOSCAN:
    981      1.112   thorpej 	    {
    982      1.112   thorpej 		struct scbusioscan_args *a =
    983      1.112   thorpej 		    (struct scbusioscan_args *)addr;
    984      1.112   thorpej 
    985      1.112   thorpej 		/* XXX Change interface to this function. */
    986      1.112   thorpej 		error = scsi_probe_busses(minor(dev), a->sa_target,
    987      1.112   thorpej 		    a->sa_lun);
    988      1.112   thorpej 		break;
    989      1.112   thorpej 	    }
    990      1.112   thorpej 
    991      1.113   thorpej 	case SCBUSIORESET:
    992      1.113   thorpej 		/* FALLTHROUGH */
    993      1.111   thorpej 	default:
    994      1.113   thorpej 		if (sc_link->adapter->scsipi_ioctl == NULL)
    995      1.113   thorpej 			error = ENOTTY;
    996      1.113   thorpej 		else
    997      1.113   thorpej 			error = (*sc_link->adapter->scsipi_ioctl)(sc_link,
    998      1.113   thorpej 			    cmd, addr, flag, p);
    999      1.113   thorpej 		break;
   1000      1.111   thorpej 	}
   1001      1.111   thorpej 
   1002      1.111   thorpej 	return (error);
   1003        1.1       cgd }
   1004