Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.88.2.4
      1  1.88.2.4  thorpej /*	$NetBSD: scsiconf.c,v 1.88.2.4 1997/09/22 06:33:39 thorpej Exp $	*/
      2  1.88.2.2  thorpej 
      3  1.88.2.2  thorpej /*
      4  1.88.2.2  thorpej  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      5  1.88.2.2  thorpej  *
      6  1.88.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
      7  1.88.2.2  thorpej  * modification, are permitted provided that the following conditions
      8  1.88.2.2  thorpej  * are met:
      9  1.88.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     10  1.88.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     11  1.88.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.88.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     13  1.88.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     14  1.88.2.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     15  1.88.2.2  thorpej  *    must display the following acknowledgement:
     16  1.88.2.2  thorpej  *	This product includes software developed by Charles Hannum.
     17  1.88.2.2  thorpej  * 4. The name of the author may not be used to endorse or promote products
     18  1.88.2.2  thorpej  *    derived from this software without specific prior written permission.
     19  1.88.2.2  thorpej  *
     20  1.88.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.88.2.2  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.88.2.2  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.88.2.2  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.88.2.2  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.88.2.2  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.88.2.2  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.88.2.2  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.88.2.2  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.88.2.2  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.88.2.2  thorpej  */
     31  1.88.2.2  thorpej 
     32  1.88.2.2  thorpej /*
     33  1.88.2.2  thorpej  * Originally written by Julian Elischer (julian (at) tfs.com)
     34  1.88.2.2  thorpej  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     35  1.88.2.2  thorpej  *
     36  1.88.2.2  thorpej  * TRW Financial Systems, in accordance with their agreement with Carnegie
     37  1.88.2.2  thorpej  * Mellon University, makes this software available to CMU to distribute
     38  1.88.2.2  thorpej  * or use in any manner that they see fit as long as this message is kept with
     39  1.88.2.2  thorpej  * the software. For this reason TFS also grants any other persons or
     40  1.88.2.2  thorpej  * organisations permission to use or modify this software.
     41  1.88.2.2  thorpej  *
     42  1.88.2.2  thorpej  * TFS supplies this software to be publicly redistributed
     43  1.88.2.2  thorpej  * on the understanding that TFS is not responsible for the correct
     44  1.88.2.2  thorpej  * functioning of this software in any circumstances.
     45  1.88.2.2  thorpej  *
     46  1.88.2.2  thorpej  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     47  1.88.2.2  thorpej  */
     48  1.88.2.2  thorpej 
     49  1.88.2.2  thorpej #include <sys/types.h>
     50  1.88.2.2  thorpej #include <sys/param.h>
     51  1.88.2.2  thorpej #include <sys/systm.h>
     52  1.88.2.2  thorpej #include <sys/malloc.h>
     53  1.88.2.2  thorpej #include <sys/device.h>
     54  1.88.2.2  thorpej 
     55  1.88.2.2  thorpej #include <dev/scsipi/scsi_all.h>
     56  1.88.2.2  thorpej #include <dev/scsipi/scsipi_all.h>
     57  1.88.2.2  thorpej #include <dev/scsipi/scsiconf.h>
     58  1.88.2.2  thorpej #include "locators.h"
     59  1.88.2.2  thorpej 
     60  1.88.2.2  thorpej #if 0
     61  1.88.2.2  thorpej #if NCALS > 0
     62  1.88.2.2  thorpej 	{ T_PROCESSOR, T_FIXED, 1,
     63  1.88.2.2  thorpej 	  0, 0, 0 },
     64  1.88.2.2  thorpej #endif	/* NCALS */
     65  1.88.2.2  thorpej #if NBLL > 0
     66  1.88.2.2  thorpej 	{ T_PROCESSOR, T_FIXED, 1,
     67  1.88.2.2  thorpej 	  "AEG     ", "READER          ", "V1.0" },
     68  1.88.2.2  thorpej #endif	/* NBLL */
     69  1.88.2.2  thorpej #if NKIL > 0
     70  1.88.2.2  thorpej 	{ T_SCANNER, T_FIXED, 0,
     71  1.88.2.2  thorpej 	  "KODAK   ", "IL Scanner 900  ", 0 },
     72  1.88.2.2  thorpej #endif	/* NKIL */
     73  1.88.2.2  thorpej #endif
     74  1.88.2.2  thorpej 
     75  1.88.2.2  thorpej /*
     76  1.88.2.2  thorpej  * Declarations
     77  1.88.2.2  thorpej  */
     78  1.88.2.2  thorpej void scsi_probedev __P((struct scsibus_softc *, int, int));
     79  1.88.2.2  thorpej int scsi_probe_bus __P((int bus, int target, int lun));
     80  1.88.2.2  thorpej 
     81  1.88.2.2  thorpej struct scsipi_device probe_switch = {
     82  1.88.2.2  thorpej 	NULL,
     83  1.88.2.2  thorpej 	NULL,
     84  1.88.2.2  thorpej 	NULL,
     85  1.88.2.2  thorpej 	NULL,
     86  1.88.2.2  thorpej };
     87  1.88.2.2  thorpej 
     88  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
     89  1.88.2.2  thorpej int scsibusmatch __P((struct device *, void *, void *));
     90  1.88.2.2  thorpej #else
     91  1.88.2.2  thorpej int scsibusmatch __P((struct device *, struct cfdata *, void *));
     92  1.88.2.2  thorpej #endif
     93  1.88.2.2  thorpej void scsibusattach __P((struct device *, struct device *, void *));
     94  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
     95  1.88.2.2  thorpej int scsibussubmatch __P((struct device *, void *, void *));
     96  1.88.2.2  thorpej #else
     97  1.88.2.2  thorpej int scsibussubmatch __P((struct device *, struct cfdata *, void *));
     98  1.88.2.2  thorpej #endif
     99  1.88.2.2  thorpej 
    100  1.88.2.2  thorpej struct cfattach scsibus_ca = {
    101  1.88.2.2  thorpej 	sizeof(struct scsibus_softc), scsibusmatch, scsibusattach
    102  1.88.2.2  thorpej };
    103  1.88.2.2  thorpej 
    104  1.88.2.2  thorpej struct cfdriver scsibus_cd = {
    105  1.88.2.2  thorpej 	NULL, "scsibus", DV_DULL
    106  1.88.2.2  thorpej };
    107  1.88.2.2  thorpej 
    108  1.88.2.2  thorpej int scsibusprint __P((void *, const char *));
    109  1.88.2.2  thorpej 
    110  1.88.2.2  thorpej 
    111  1.88.2.2  thorpej int
    112  1.88.2.2  thorpej scsiprint(aux, pnp)
    113  1.88.2.2  thorpej 	void *aux;
    114  1.88.2.2  thorpej 	const char *pnp;
    115  1.88.2.2  thorpej {
    116  1.88.2.2  thorpej 	struct scsipi_link *l = aux;
    117  1.88.2.2  thorpej 
    118  1.88.2.2  thorpej 	/* only "scsibus"es can attach to "scsi"s; easy. */
    119  1.88.2.2  thorpej 	if (pnp)
    120  1.88.2.2  thorpej 		printf("scsibus at %s", pnp);
    121  1.88.2.2  thorpej 
    122  1.88.2.2  thorpej 	/* don't print channel if the controller says there can be only one. */
    123  1.88.2.2  thorpej 	if (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE)
    124  1.88.2.2  thorpej 		printf(" channel %d", l->scsipi_scsi.channel);
    125  1.88.2.2  thorpej 
    126  1.88.2.2  thorpej 	return (UNCONF);
    127  1.88.2.2  thorpej }
    128  1.88.2.2  thorpej 
    129  1.88.2.2  thorpej int
    130  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
    131  1.88.2.2  thorpej scsibusmatch(parent, match, aux)
    132  1.88.2.2  thorpej #else
    133  1.88.2.2  thorpej scsibusmatch(parent, cf, aux)
    134  1.88.2.2  thorpej #endif
    135  1.88.2.2  thorpej 	struct device *parent;
    136  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
    137  1.88.2.2  thorpej 	void *match;
    138  1.88.2.2  thorpej #else
    139  1.88.2.2  thorpej 	struct cfdata *cf;
    140  1.88.2.2  thorpej #endif
    141  1.88.2.2  thorpej 	void *aux;
    142  1.88.2.2  thorpej {
    143  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
    144  1.88.2.2  thorpej 	struct cfdata *cf = match;
    145  1.88.2.2  thorpej #endif
    146  1.88.2.2  thorpej 	struct scsipi_link *l = aux;
    147  1.88.2.2  thorpej 	int channel;
    148  1.88.2.2  thorpej 
    149  1.88.2.2  thorpej 	/*
    150  1.88.2.2  thorpej 	 * Allow single-channel controllers to specify their channel
    151  1.88.2.2  thorpej 	 * in a special way, so that it's not printed.
    152  1.88.2.2  thorpej 	 */
    153  1.88.2.2  thorpej 	channel = (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) ?
    154  1.88.2.2  thorpej 		l->scsipi_scsi.channel : 0;
    155  1.88.2.2  thorpej 
    156  1.88.2.2  thorpej 	if (cf->cf_loc[SCSICF_CHANNEL] != channel &&
    157  1.88.2.2  thorpej 		cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
    158  1.88.2.2  thorpej 		return (0);
    159  1.88.2.2  thorpej 
    160  1.88.2.2  thorpej 	return (1);
    161  1.88.2.2  thorpej }
    162  1.88.2.2  thorpej 
    163  1.88.2.2  thorpej /*
    164  1.88.2.2  thorpej  * The routine called by the adapter boards to get all their
    165  1.88.2.2  thorpej  * devices configured in.
    166  1.88.2.2  thorpej  */
    167  1.88.2.2  thorpej void
    168  1.88.2.2  thorpej scsibusattach(parent, self, aux)
    169  1.88.2.2  thorpej 	struct device *parent, *self;
    170  1.88.2.2  thorpej 	void *aux;
    171  1.88.2.2  thorpej {
    172  1.88.2.2  thorpej 	struct scsibus_softc *sb = (struct scsibus_softc *)self;
    173  1.88.2.2  thorpej 	struct scsipi_link *sc_link_proto = aux;
    174  1.88.2.2  thorpej 	size_t nbytes;
    175  1.88.2.2  thorpej 	int i;
    176  1.88.2.2  thorpej 
    177  1.88.2.2  thorpej 	sc_link_proto->scsipi_scsi.scsibus = sb->sc_dev.dv_unit;
    178  1.88.2.2  thorpej 	sc_link_proto->scsipi_cmd = scsi_scsipi_cmd;
    179  1.88.2.2  thorpej 	sc_link_proto->scsipi_interpret_sense = scsi_interpret_sense;
    180  1.88.2.2  thorpej 	sc_link_proto->sc_print_addr = scsi_print_addr;
    181  1.88.2.2  thorpej 
    182  1.88.2.2  thorpej 	sb->adapter_link = sc_link_proto;
    183  1.88.2.2  thorpej 	sb->sc_maxtarget = sc_link_proto->scsipi_scsi.max_target;
    184  1.88.2.2  thorpej 	printf(": %d targets\n", sb->sc_maxtarget + 1);
    185  1.88.2.2  thorpej 
    186  1.88.2.2  thorpej 	nbytes = sb->sc_maxtarget * sizeof(struct scsipi_link **);
    187  1.88.2.2  thorpej 	sb->sc_link = (struct scsipi_link ***)malloc(nbytes, M_DEVBUF,
    188  1.88.2.2  thorpej 	   M_NOWAIT);
    189  1.88.2.2  thorpej 	if (sb->sc_link == NULL)
    190  1.88.2.2  thorpej 		panic("scsibusattach: can't allocate target links");
    191  1.88.2.2  thorpej 
    192  1.88.2.2  thorpej 	nbytes = 8 * sizeof(struct scsipi_link *);
    193  1.88.2.2  thorpej 	for (i = 0; i <= sb->sc_maxtarget; i++) {
    194  1.88.2.2  thorpej 		sb->sc_link[i] = (struct scsipi_link **)malloc(nbytes,
    195  1.88.2.2  thorpej 			M_DEVBUF, M_NOWAIT);
    196  1.88.2.2  thorpej 		if (sb->sc_link[i] == NULL)
    197  1.88.2.2  thorpej 			panic("scsibusattach: can't allocate lun links");
    198  1.88.2.2  thorpej 		bzero(sb->sc_link[i], nbytes);
    199  1.88.2.2  thorpej 	}
    200  1.88.2.2  thorpej 
    201  1.88.2.2  thorpej #if defined(SCSI_DELAY) && SCSI_DELAY > 2
    202  1.88.2.2  thorpej 	printf("%s: waiting for scsi devices to settle\n",
    203  1.88.2.2  thorpej 		sb->sc_dev.dv_xname);
    204  1.88.2.2  thorpej #else	/* SCSI_DELAY > 2 */
    205  1.88.2.2  thorpej #undef	SCSI_DELAY
    206  1.88.2.2  thorpej #define SCSI_DELAY 2
    207  1.88.2.2  thorpej #endif	/* SCSI_DELAY */
    208  1.88.2.2  thorpej 	delay(1000000 * SCSI_DELAY);
    209  1.88.2.2  thorpej 
    210  1.88.2.2  thorpej 	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
    211  1.88.2.2  thorpej }
    212  1.88.2.2  thorpej 
    213  1.88.2.2  thorpej int
    214  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
    215  1.88.2.2  thorpej scsibussubmatch(parent, match, aux)
    216  1.88.2.2  thorpej #else
    217  1.88.2.2  thorpej scsibussubmatch(parent, cf, aux)
    218  1.88.2.2  thorpej #endif
    219  1.88.2.2  thorpej 	struct device *parent;
    220  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
    221  1.88.2.2  thorpej 	void *match;
    222  1.88.2.2  thorpej #else
    223  1.88.2.2  thorpej 	struct cfdata *cf;
    224  1.88.2.2  thorpej #endif
    225  1.88.2.2  thorpej 	void *aux;
    226  1.88.2.2  thorpej {
    227  1.88.2.2  thorpej #ifdef __BROKEN_INDIRECT_CONFIG
    228  1.88.2.2  thorpej 	struct cfdata *cf = match;
    229  1.88.2.2  thorpej #endif
    230  1.88.2.2  thorpej 	struct scsipibus_attach_args *sa = aux;
    231  1.88.2.2  thorpej 	struct scsipi_link *sc_link = sa->sa_sc_link;
    232  1.88.2.2  thorpej 
    233  1.88.2.2  thorpej 	if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
    234  1.88.2.2  thorpej 		cf->cf_loc[SCSIBUSCF_TARGET] != sc_link->scsipi_scsi.target)
    235  1.88.2.2  thorpej 		return 0;
    236  1.88.2.2  thorpej 	if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
    237  1.88.2.2  thorpej 		cf->cf_loc[SCSIBUSCF_LUN] != sc_link->scsipi_scsi.lun)
    238  1.88.2.2  thorpej 		return 0;
    239  1.88.2.2  thorpej 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    240  1.88.2.2  thorpej }
    241  1.88.2.2  thorpej 
    242  1.88.2.2  thorpej /*
    243  1.88.2.2  thorpej  * Probe the requested scsi bus. It must be already set up.
    244  1.88.2.2  thorpej  * -1 requests all set up scsi busses.
    245  1.88.2.2  thorpej  * target and lun optionally narrow the search if not -1
    246  1.88.2.2  thorpej  */
    247  1.88.2.2  thorpej int
    248  1.88.2.2  thorpej scsi_probe_busses(bus, target, lun)
    249  1.88.2.2  thorpej 	int bus, target, lun;
    250  1.88.2.2  thorpej {
    251  1.88.2.2  thorpej 
    252  1.88.2.2  thorpej 	if (bus == -1) {
    253  1.88.2.2  thorpej 		for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++)
    254  1.88.2.2  thorpej 			if (scsibus_cd.cd_devs[bus])
    255  1.88.2.2  thorpej 				scsi_probe_bus(bus, target, lun);
    256  1.88.2.2  thorpej 		return 0;
    257  1.88.2.2  thorpej 	} else {
    258  1.88.2.2  thorpej 		return scsi_probe_bus(bus, target, lun);
    259  1.88.2.2  thorpej 	}
    260  1.88.2.2  thorpej }
    261  1.88.2.2  thorpej 
    262  1.88.2.2  thorpej /*
    263  1.88.2.2  thorpej  * Probe the requested scsi bus. It must be already set up.
    264  1.88.2.2  thorpej  * target and lun optionally narrow the search if not -1
    265  1.88.2.2  thorpej  */
    266  1.88.2.2  thorpej int
    267  1.88.2.2  thorpej scsi_probe_bus(bus, target, lun)
    268  1.88.2.2  thorpej 	int bus, target, lun;
    269  1.88.2.2  thorpej {
    270  1.88.2.2  thorpej 	struct scsibus_softc *scsi;
    271  1.88.2.2  thorpej 	int maxtarget, mintarget, maxlun, minlun;
    272  1.88.2.2  thorpej 	u_int8_t scsi_addr;
    273  1.88.2.2  thorpej 
    274  1.88.2.2  thorpej 	if (bus < 0 || bus >= scsibus_cd.cd_ndevs)
    275  1.88.2.2  thorpej 		return ENXIO;
    276  1.88.2.2  thorpej 	scsi = scsibus_cd.cd_devs[bus];
    277  1.88.2.2  thorpej 	if (!scsi)
    278  1.88.2.2  thorpej 		return ENXIO;
    279  1.88.2.2  thorpej 
    280  1.88.2.2  thorpej 	scsi_addr = scsi->adapter_link->scsipi_scsi.adapter_target;
    281  1.88.2.2  thorpej 
    282  1.88.2.2  thorpej 	if (target == -1) {
    283  1.88.2.2  thorpej 		maxtarget = scsi->sc_maxtarget;
    284  1.88.2.2  thorpej 		mintarget = 0;
    285  1.88.2.2  thorpej 	} else {
    286  1.88.2.2  thorpej 		if (target < 0 || target > scsi->sc_maxtarget)
    287  1.88.2.2  thorpej 			return EINVAL;
    288  1.88.2.2  thorpej 		maxtarget = mintarget = target;
    289  1.88.2.2  thorpej 	}
    290  1.88.2.2  thorpej 
    291  1.88.2.2  thorpej 	if (lun == -1) {
    292  1.88.2.2  thorpej 		maxlun = 7;
    293  1.88.2.2  thorpej 		minlun = 0;
    294  1.88.2.2  thorpej 	} else {
    295  1.88.2.2  thorpej 		if (lun < 0 || lun > 7)
    296  1.88.2.2  thorpej 			return EINVAL;
    297  1.88.2.2  thorpej 		maxlun = minlun = lun;
    298  1.88.2.2  thorpej 	}
    299  1.88.2.2  thorpej 
    300  1.88.2.2  thorpej 	for (target = mintarget; target <= maxtarget; target++) {
    301  1.88.2.2  thorpej 		if (target == scsi_addr)
    302  1.88.2.2  thorpej 			continue;
    303  1.88.2.2  thorpej 		for (lun = minlun; lun <= maxlun; lun++) {
    304  1.88.2.2  thorpej 			/*
    305  1.88.2.2  thorpej 			 * See if there's a device present, and configure it.
    306  1.88.2.2  thorpej 			 */
    307  1.88.2.2  thorpej 			scsi_probedev(scsi, target, lun);
    308  1.88.2.2  thorpej 			if ((scsi->moreluns & (1 << target)) == 0)
    309  1.88.2.2  thorpej 				break;
    310  1.88.2.2  thorpej 			/* otherwise something says we should look further */
    311  1.88.2.2  thorpej 		}
    312  1.88.2.2  thorpej 	}
    313  1.88.2.2  thorpej 	return 0;
    314  1.88.2.2  thorpej }
    315  1.88.2.2  thorpej 
    316  1.88.2.2  thorpej /*
    317  1.88.2.2  thorpej  * Print out autoconfiguration information for a subdevice.
    318  1.88.2.2  thorpej  *
    319  1.88.2.2  thorpej  * This is a slight abuse of 'standard' autoconfiguration semantics,
    320  1.88.2.2  thorpej  * because 'print' functions don't normally print the colon and
    321  1.88.2.2  thorpej  * device information.  However, in this case that's better than
    322  1.88.2.2  thorpej  * either printing redundant information before the attach message,
    323  1.88.2.2  thorpej  * or having the device driver call a special function to print out
    324  1.88.2.2  thorpej  * the standard device information.
    325  1.88.2.2  thorpej  */
    326  1.88.2.2  thorpej int
    327  1.88.2.2  thorpej scsibusprint(aux, pnp)
    328  1.88.2.2  thorpej 	void *aux;
    329  1.88.2.2  thorpej 	const char *pnp;
    330  1.88.2.2  thorpej {
    331  1.88.2.2  thorpej 	struct scsipibus_attach_args *sa = aux;
    332  1.88.2.2  thorpej 	struct scsipi_inquiry_pattern *inqbuf;
    333  1.88.2.2  thorpej 	u_int8_t type;
    334  1.88.2.2  thorpej 	char *dtype, *qtype;
    335  1.88.2.2  thorpej 	char vendor[33], product[65], revision[17];
    336  1.88.2.2  thorpej 	int target, lun;
    337  1.88.2.2  thorpej 
    338  1.88.2.2  thorpej 	if (pnp != NULL)
    339  1.88.2.2  thorpej 		printf("%s", pnp);
    340  1.88.2.2  thorpej 
    341  1.88.2.2  thorpej 	inqbuf = &sa->sa_inqbuf;
    342  1.88.2.2  thorpej 
    343  1.88.2.2  thorpej 	target = sa->sa_sc_link->scsipi_scsi.target;
    344  1.88.2.2  thorpej 	lun = sa->sa_sc_link->scsipi_scsi.lun;
    345  1.88.2.2  thorpej 
    346  1.88.2.2  thorpej 	type = inqbuf->type & SID_TYPE;
    347  1.88.2.2  thorpej 
    348  1.88.2.2  thorpej 	/*
    349  1.88.2.2  thorpej 	 * Figure out basic device type and qualifier.
    350  1.88.2.2  thorpej 	 */
    351  1.88.2.2  thorpej 	dtype = 0;
    352  1.88.2.2  thorpej 	switch (inqbuf->type & SID_QUAL) {
    353  1.88.2.2  thorpej 	case SID_QUAL_LU_OK:
    354  1.88.2.2  thorpej 		qtype = "";
    355  1.88.2.2  thorpej 		break;
    356  1.88.2.2  thorpej 
    357  1.88.2.2  thorpej 	case SID_QUAL_LU_OFFLINE:
    358  1.88.2.2  thorpej 		qtype = " offline";
    359  1.88.2.2  thorpej 		break;
    360  1.88.2.2  thorpej 
    361  1.88.2.2  thorpej 	case SID_QUAL_RSVD:
    362  1.88.2.2  thorpej 	case SID_QUAL_BAD_LU:
    363  1.88.2.2  thorpej 		panic("scsibusprint: impossible qualifier");
    364  1.88.2.2  thorpej 
    365  1.88.2.2  thorpej 	default:
    366  1.88.2.2  thorpej 		qtype = "";
    367  1.88.2.2  thorpej 		dtype = "vendor-unique";
    368  1.88.2.2  thorpej 		break;
    369  1.88.2.2  thorpej 	}
    370  1.88.2.2  thorpej 	if (dtype == 0) {
    371  1.88.2.2  thorpej 		dtype = scsipi_dtype(type);
    372  1.88.2.2  thorpej 	}
    373  1.88.2.2  thorpej 
    374  1.88.2.2  thorpej 	scsipi_strvis(vendor, inqbuf->vendor, 8);
    375  1.88.2.2  thorpej 	scsipi_strvis(product, inqbuf->product, 16);
    376  1.88.2.2  thorpej 	scsipi_strvis(revision, inqbuf->revision, 4);
    377  1.88.2.2  thorpej 
    378  1.88.2.2  thorpej 	printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
    379  1.88.2.2  thorpej 		target, lun, vendor, product, revision,
    380  1.88.2.2  thorpej 		sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
    381  1.88.2.2  thorpej 		inqbuf->removable ? "removable" : "fixed", qtype);
    382  1.88.2.2  thorpej 
    383  1.88.2.2  thorpej 	return (UNCONF);
    384  1.88.2.2  thorpej }
    385  1.88.2.2  thorpej 
    386  1.88.2.2  thorpej struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    387  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    388  1.88.2.2  thorpej 	 "CHINON  ", "CD-ROM CDS-431  ", ""},     SDEV_NOLUNS},
    389  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    390  1.88.2.2  thorpej 	 "Chinon  ", "CD-ROM CDS-525  ", ""},     SDEV_NOLUNS},
    391  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    392  1.88.2.2  thorpej 	 "CHINON  ", "CD-ROM CDS-535  ", ""},     SDEV_NOLUNS},
    393  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    394  1.88.2.2  thorpej 	 "DENON   ", "DRD-25X         ", "V"},    SDEV_NOLUNS},
    395  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    396  1.88.2.2  thorpej 	 "HP      ", "C4324/C4325     ", ""},     SDEV_NOLUNS},
    397  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    398  1.88.2.2  thorpej 	 "IMS     ", "CDD521/10       ", "2.06"}, SDEV_NOLUNS},
    399  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    400  1.88.2.2  thorpej 	 "MATSHITA", "CD-ROM CR-5XX   ", "1.0b"}, SDEV_NOLUNS},
    401  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    402  1.88.2.2  thorpej 	 "MEDAVIS ", "RENO CD-ROMX2A  ", ""},     SDEV_NOLUNS},
    403  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    404  1.88.2.2  thorpej 	 "MEDIAVIS", "CDR-H93MV       ", "1.3"},  SDEV_NOLUNS},
    405  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    406  1.88.2.2  thorpej 	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     SDEV_NOLUNS},
    407  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    408  1.88.2.2  thorpej 	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     SDEV_NOLUNS},
    409  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    410  1.88.2.2  thorpej 	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     SDEV_NOLUNS},
    411  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    412  1.88.2.2  thorpej 	 "NEC     ", "CD-ROM DRIVE:841", ""},     SDEV_NOLUNS},
    413  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    414  1.88.2.2  thorpej 	 "PIONEER ", "CD-ROM DR-124X  ", "1.01"}, SDEV_NOLUNS},
    415  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    416  1.88.2.2  thorpej 	 "SONY    ", "CD-ROM CDU-541  ", ""},     SDEV_NOLUNS},
    417  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    418  1.88.2.2  thorpej 	 "SONY    ", "CD-ROM CDU-55S  ", ""},     SDEV_NOLUNS},
    419  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    420  1.88.2.2  thorpej 	 "SONY    ", "CD-ROM CDU-8003A", ""},     SDEV_NOLUNS},
    421  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    422  1.88.2.2  thorpej 	 "SONY    ", "CD-ROM CDU-8012 ", ""},     SDEV_NOLUNS},
    423  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    424  1.88.2.2  thorpej 	 "TEAC    ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    425  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    426  1.88.2.2  thorpej 	 "TEAC    ", "CD-ROM CD-56S   ", "1.0B"}, SDEV_NOLUNS},
    427  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    428  1.88.2.2  thorpej 	 "TEXEL   ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    429  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    430  1.88.2.2  thorpej 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
    431  1.88.2.3  thorpej 	{{T_CDROM, T_REMOV,
    432  1.88.2.3  thorpej 	 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS},
    433  1.88.2.2  thorpej 	{{T_CDROM, T_REMOV,
    434  1.88.2.2  thorpej 	 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS},
    435  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    436  1.88.2.2  thorpej 	 "MICROP  ", "1588-15MBSUN0669", ""},     SDEV_AUTOSAVE},
    437  1.88.2.2  thorpej 	{{T_OPTICAL, T_REMOV,
    438  1.88.2.2  thorpej 	 "EPSON   ", "OMD-5010        ", "3.08"}, SDEV_NOLUNS},
    439  1.88.2.2  thorpej 
    440  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    441  1.88.2.2  thorpej 	 "DEC     ", "RZ55     (C) DEC", ""},     SDEV_AUTOSAVE},
    442  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    443  1.88.2.2  thorpej 	 "EMULEX  ", "MD21/S2     ESDI", "A00"},  SDEV_FORCELUNS|SDEV_AUTOSAVE},
    444  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    445  1.88.2.2  thorpej 	 "IBMRAID ", "0662S",		 ""},     SDEV_AUTOSAVE},
    446  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    447  1.88.2.2  thorpej 	 "IBM     ", "0663H",		 ""},     SDEV_AUTOSAVE},
    448  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    449  1.88.2.2  thorpej 	 "IBM",	  "0664",		 ""},	  SDEV_AUTOSAVE},
    450  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    451  1.88.2.2  thorpej 	 "IBM     ", "KZ-C",         ""},     SDEV_AUTOSAVE},
    452  1.88.2.2  thorpej 	/* Broken IBM disk */
    453  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    454  1.88.2.2  thorpej 	 ""	   , "DFRSS2F",		 ""},	  SDEV_AUTOSAVE},
    455  1.88.2.2  thorpej 	{{T_DIRECT, T_REMOV,
    456  1.88.2.2  thorpej 	 "MPL     ", "MC-DISK-        ", ""},     SDEV_NOLUNS},
    457  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    458  1.88.2.2  thorpej 	 "MAXTOR  ", "XT-3280         ", ""},     SDEV_NOLUNS},
    459  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    460  1.88.2.2  thorpej 	 "MAXTOR  ", "XT-4380S        ", ""},     SDEV_NOLUNS},
    461  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    462  1.88.2.2  thorpej 	 "MAXTOR  ", "MXT-1240S       ", ""},     SDEV_NOLUNS},
    463  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    464  1.88.2.2  thorpej 	 "MAXTOR  ", "XT-4170S        ", ""},     SDEV_NOLUNS},
    465  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    466  1.88.2.2  thorpej 	 "MAXTOR  ", "XT-8760S",         ""},     SDEV_NOLUNS},
    467  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    468  1.88.2.2  thorpej 	 "MAXTOR  ", "LXT-213S        ", ""},     SDEV_NOLUNS},
    469  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    470  1.88.2.2  thorpej 	 "MAXTOR  ", "LXT-213S SUN0207", ""},     SDEV_NOLUNS},
    471  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    472  1.88.2.2  thorpej 	 "MAXTOR  ", "LXT-200S        ", ""},     SDEV_NOLUNS},
    473  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    474  1.88.2.4  thorpej 	 "MEGADRV ", "EV1000",           ""},     SDEV_NOMODESENSE},
    475  1.88.2.4  thorpej 	{{T_DIRECT, T_FIXED,
    476  1.88.2.2  thorpej 	 "MST     ", "SnapLink        ", ""},     SDEV_NOLUNS},
    477  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    478  1.88.2.2  thorpej 	 "NEC     ", "D3847           ", "0307"}, SDEV_NOLUNS},
    479  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    480  1.88.2.2  thorpej 	 "QUANTUM ", "LPS525S         ", ""},     SDEV_NOLUNS},
    481  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    482  1.88.2.2  thorpej 	 "QUANTUM ", "P105S 910-10-94x", ""},     SDEV_NOLUNS},
    483  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    484  1.88.2.2  thorpej 	 "QUANTUM ", "PD1225S         ", ""},     SDEV_NOLUNS},
    485  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    486  1.88.2.2  thorpej 	 "QUANTUM ", "PD210S   SUN0207", ""},     SDEV_NOLUNS},
    487  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    488  1.88.2.2  thorpej 	 "RODIME  ", "RO3000S         ", ""},     SDEV_NOLUNS},
    489  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    490  1.88.2.2  thorpej 	 "SEAGATE ", "ST125N          ", ""},     SDEV_NOLUNS},
    491  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    492  1.88.2.2  thorpej 	 "SEAGATE ", "ST157N          ", ""},     SDEV_NOLUNS},
    493  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    494  1.88.2.2  thorpej 	 "SEAGATE ", "ST296           ", ""},     SDEV_NOLUNS},
    495  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    496  1.88.2.2  thorpej 	 "SEAGATE ", "ST296N          ", ""},     SDEV_NOLUNS},
    497  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    498  1.88.2.2  thorpej 	 "SEAGATE ", "ST19171FC       ", ""},     SDEV_NOMODESENSE},
    499  1.88.2.2  thorpej 	{{T_DIRECT, T_FIXED,
    500  1.88.2.4  thorpej 	 "SEAGATE ", "ST34501FC       ", ""},     SDEV_NOMODESENSE},
    501  1.88.2.4  thorpej 	{{T_DIRECT, T_FIXED,
    502  1.88.2.2  thorpej 	 "TOSHIBA ", "MK538FB         ", "6027"}, SDEV_NOLUNS},
    503  1.88.2.2  thorpej 	{{T_DIRECT, T_REMOV,
    504  1.88.2.2  thorpej 	 "iomega", "jaz 1GB", 		 ""},	  SDEV_NOMODESENSE},
    505  1.88.2.2  thorpej 	{{T_DIRECT, T_REMOV,
    506  1.88.2.2  thorpej 	 "IOMEGA", "ZIP 100",		 ""},	  SDEV_NOMODESENSE},
    507  1.88.2.2  thorpej 	/* Letting the motor run kills floppy drives and disks quite fast. */
    508  1.88.2.2  thorpej 	{{T_DIRECT, T_REMOV,
    509  1.88.2.2  thorpej 	 "TEAC", "FC-1",		 ""},	  SDEV_NOSTARTUNIT},
    510  1.88.2.2  thorpej 
    511  1.88.2.2  thorpej 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    512  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    513  1.88.2.2  thorpej 	 "        ", "                ", "    "}, SDEV_NOLUNS},
    514  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    515  1.88.2.2  thorpej 	 "CALIPER ", "CP150           ", ""},     SDEV_NOLUNS},
    516  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    517  1.88.2.2  thorpej 	 "EXABYTE ", "EXB-8200        ", ""},     SDEV_NOLUNS},
    518  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    519  1.88.2.2  thorpej 	 "SONY    ", "GY-10C          ", ""},     SDEV_NOLUNS},
    520  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    521  1.88.2.2  thorpej 	 "SONY    ", "SDT-2000        ", "2.09"}, SDEV_NOLUNS},
    522  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    523  1.88.2.2  thorpej 	 "SONY    ", "SDT-5000        ", "3."},   SDEV_NOSYNCWIDE},
    524  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    525  1.88.2.2  thorpej 	 "SONY    ", "SDT-5200        ", "3."},   SDEV_NOLUNS},
    526  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    527  1.88.2.2  thorpej 	 "TANDBERG", " TDC 3600       ", ""},     SDEV_NOLUNS},
    528  1.88.2.2  thorpej 	/* Following entry reported as a Tandberg 3600; ref. PR1933 */
    529  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    530  1.88.2.2  thorpej 	 "ARCHIVE ", "VIPER 150  21247", ""},     SDEV_NOLUNS},
    531  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    532  1.88.2.2  thorpej 	 "ARCHIVE ", "Python 28454-XXX", ""},     SDEV_NOLUNS},
    533  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    534  1.88.2.2  thorpej 	 "WANGTEK ", "5099ES SCSI",      ""},     SDEV_NOLUNS},
    535  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    536  1.88.2.2  thorpej 	 "WANGTEK ", "5150ES SCSI",      ""},     SDEV_NOLUNS},
    537  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    538  1.88.2.2  thorpej 	 "WangDAT ", "Model 1300      ", "02.4"}, SDEV_NOSYNCWIDE},
    539  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    540  1.88.2.2  thorpej 	 "WangDAT ", "Model 2600      ", "01.7"}, SDEV_NOSYNCWIDE},
    541  1.88.2.2  thorpej 	{{T_SEQUENTIAL, T_REMOV,
    542  1.88.2.2  thorpej 	 "WangDAT ", "Model 3200      ", "02.2"}, SDEV_NOSYNCWIDE},
    543  1.88.2.2  thorpej 
    544  1.88.2.2  thorpej 	{{T_SCANNER, T_FIXED,
    545  1.88.2.2  thorpej 	 "UMAX    ", "UMAX S-6E       ", "V2.0"}, SDEV_NOLUNS},
    546  1.88.2.2  thorpej 
    547  1.88.2.2  thorpej 	{{T_PROCESSOR, T_FIXED,
    548  1.88.2.2  thorpej 	 "LITRONIC", "PCMCIA          ", ""},     SDEV_NOLUNS},
    549  1.88.2.2  thorpej };
    550  1.88.2.2  thorpej 
    551  1.88.2.2  thorpej /*
    552  1.88.2.2  thorpej  * given a target and lu, ask the device what
    553  1.88.2.2  thorpej  * it is, and find the correct driver table
    554  1.88.2.2  thorpej  * entry.
    555  1.88.2.2  thorpej  */
    556  1.88.2.2  thorpej void
    557  1.88.2.2  thorpej scsi_probedev(scsi, target, lun)
    558  1.88.2.2  thorpej 	struct scsibus_softc *scsi;
    559  1.88.2.2  thorpej 	int target, lun;
    560  1.88.2.2  thorpej {
    561  1.88.2.2  thorpej 	struct scsipi_link *sc_link;
    562  1.88.2.2  thorpej 	static struct scsipi_inquiry_data inqbuf;
    563  1.88.2.2  thorpej 	struct scsi_quirk_inquiry_pattern *finger;
    564  1.88.2.2  thorpej 	int checkdtype, priority;
    565  1.88.2.2  thorpej 	struct scsipibus_attach_args sa;
    566  1.88.2.2  thorpej 	struct cfdata *cf;
    567  1.88.2.2  thorpej 
    568  1.88.2.2  thorpej 	/* Skip this slot if it is already attached. */
    569  1.88.2.2  thorpej 	if (scsi->sc_link[target][lun])
    570  1.88.2.2  thorpej 		return;
    571  1.88.2.2  thorpej 
    572  1.88.2.2  thorpej 	sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    573  1.88.2.2  thorpej 	*sc_link = *scsi->adapter_link;
    574  1.88.2.2  thorpej 	sc_link->scsipi_scsi.target = target;
    575  1.88.2.2  thorpej 	sc_link->scsipi_scsi.lun = lun;
    576  1.88.2.2  thorpej 	sc_link->device = &probe_switch;
    577  1.88.2.2  thorpej 
    578  1.88.2.2  thorpej 	/*
    579  1.88.2.2  thorpej 	 * Ask the device what it is
    580  1.88.2.2  thorpej 	 */
    581  1.88.2.2  thorpej #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
    582  1.88.2.2  thorpej 	if (target == DEBUGTARGET && lun == DEBUGLUN)
    583  1.88.2.2  thorpej 		sc_link->flags |= DEBUGLEVEL;
    584  1.88.2.2  thorpej #endif /* SCSIDEBUG */
    585  1.88.2.2  thorpej 
    586  1.88.2.2  thorpej 	(void) scsipi_test_unit_ready(sc_link,
    587  1.88.2.2  thorpej 		SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
    588  1.88.2.2  thorpej 
    589  1.88.2.2  thorpej #ifdef SCSI_2_DEF
    590  1.88.2.2  thorpej 	/* some devices need to be told to go to SCSI2 */
    591  1.88.2.2  thorpej 	/* However some just explode if you tell them this.. leave it out */
    592  1.88.2.2  thorpej 	scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
    593  1.88.2.2  thorpej #endif /* SCSI_2_DEF */
    594  1.88.2.2  thorpej 
    595  1.88.2.2  thorpej 	/* Now go ask the device all about itself. */
    596  1.88.2.2  thorpej 	bzero(&inqbuf, sizeof(inqbuf));
    597  1.88.2.2  thorpej 	if (scsipi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
    598  1.88.2.2  thorpej 		goto bad;
    599  1.88.2.2  thorpej 
    600  1.88.2.2  thorpej 	{
    601  1.88.2.2  thorpej 		int len = inqbuf.additional_length;
    602  1.88.2.2  thorpej 		while (len < 3)
    603  1.88.2.2  thorpej 			inqbuf.unused[len++] = '\0';
    604  1.88.2.2  thorpej 		while (len < 3 + 28)
    605  1.88.2.2  thorpej 			inqbuf.unused[len++] = ' ';
    606  1.88.2.2  thorpej 	}
    607  1.88.2.2  thorpej 
    608  1.88.2.2  thorpej 	sa.sa_sc_link = sc_link;
    609  1.88.2.2  thorpej 	sa.sa_inqbuf.type = inqbuf.device;
    610  1.88.2.2  thorpej 	sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
    611  1.88.2.2  thorpej 		T_REMOV : T_FIXED;
    612  1.88.2.2  thorpej 	sa.sa_inqbuf.vendor = inqbuf.vendor;
    613  1.88.2.2  thorpej 	sa.sa_inqbuf.product = inqbuf.product;
    614  1.88.2.2  thorpej 	sa.sa_inqbuf.revision = inqbuf.revision;
    615  1.88.2.2  thorpej 	sa.scsipi_info.scsi_version = inqbuf.version;
    616  1.88.2.2  thorpej 
    617  1.88.2.2  thorpej 	finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(&sa.sa_inqbuf,
    618  1.88.2.2  thorpej 		(caddr_t)scsi_quirk_patterns,
    619  1.88.2.2  thorpej 		sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    620  1.88.2.2  thorpej 		sizeof(scsi_quirk_patterns[0]), &priority);
    621  1.88.2.2  thorpej 	if (priority != 0)
    622  1.88.2.2  thorpej 		sc_link->quirks |= finger->quirks;
    623  1.88.2.2  thorpej 	if ((inqbuf.version & SID_ANSII) == 0 &&
    624  1.88.2.2  thorpej 		(sc_link->quirks & SDEV_FORCELUNS) == 0)
    625  1.88.2.2  thorpej 		sc_link->quirks |= SDEV_NOLUNS;
    626  1.88.2.2  thorpej 	sc_link->scsipi_scsi.scsi_version = inqbuf.version;
    627  1.88.2.2  thorpej 
    628  1.88.2.2  thorpej 	if ((sc_link->quirks & SDEV_NOLUNS) == 0)
    629  1.88.2.2  thorpej 		scsi->moreluns |= (1 << target);
    630  1.88.2.2  thorpej 
    631  1.88.2.2  thorpej 	/*
    632  1.88.2.2  thorpej 	 * note what BASIC type of device it is
    633  1.88.2.2  thorpej 	 */
    634  1.88.2.2  thorpej 	if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
    635  1.88.2.2  thorpej 		sc_link->flags |= SDEV_REMOVABLE;
    636  1.88.2.2  thorpej 
    637  1.88.2.2  thorpej 	/*
    638  1.88.2.2  thorpej 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    639  1.88.2.2  thorpej 	 * is vendor specific and won't match in this switch.
    640  1.88.2.2  thorpej 	 * All we do here is throw out bad/negative responses.
    641  1.88.2.2  thorpej 	 */
    642  1.88.2.2  thorpej 	checkdtype = 0;
    643  1.88.2.2  thorpej 	switch (inqbuf.device & SID_QUAL) {
    644  1.88.2.2  thorpej 	case SID_QUAL_LU_OK:
    645  1.88.2.2  thorpej 	case SID_QUAL_LU_OFFLINE:
    646  1.88.2.2  thorpej 		checkdtype = 1;
    647  1.88.2.2  thorpej 		break;
    648  1.88.2.2  thorpej 
    649  1.88.2.2  thorpej 	case SID_QUAL_RSVD:
    650  1.88.2.2  thorpej 	case SID_QUAL_BAD_LU:
    651  1.88.2.2  thorpej 		goto bad;
    652  1.88.2.2  thorpej 
    653  1.88.2.2  thorpej 	default:
    654  1.88.2.2  thorpej 		break;
    655  1.88.2.2  thorpej 	}
    656  1.88.2.2  thorpej 	if (checkdtype) {
    657  1.88.2.2  thorpej 		switch (inqbuf.device & SID_TYPE) {
    658  1.88.2.2  thorpej 		case T_DIRECT:
    659  1.88.2.2  thorpej 		case T_SEQUENTIAL:
    660  1.88.2.2  thorpej 		case T_PRINTER:
    661  1.88.2.2  thorpej 		case T_PROCESSOR:
    662  1.88.2.2  thorpej 		case T_CDROM:
    663  1.88.2.2  thorpej 		case T_WORM:
    664  1.88.2.2  thorpej 		case T_SCANNER:
    665  1.88.2.2  thorpej 		case T_OPTICAL:
    666  1.88.2.2  thorpej 		case T_CHANGER:
    667  1.88.2.2  thorpej 		case T_COMM:
    668  1.88.2.2  thorpej 		default:
    669  1.88.2.2  thorpej 			break;
    670  1.88.2.2  thorpej 		case T_NODEVICE:
    671  1.88.2.2  thorpej 			goto bad;
    672  1.88.2.2  thorpej 		}
    673  1.88.2.2  thorpej 	}
    674  1.88.2.2  thorpej 
    675  1.88.2.2  thorpej 	if ((cf = config_search(scsibussubmatch, (struct device *)scsi, &sa)) != 0) {
    676  1.88.2.2  thorpej 		scsi->sc_link[target][lun] = sc_link;
    677  1.88.2.2  thorpej 		config_attach((struct device *)scsi, cf, &sa, scsibusprint);
    678  1.88.2.2  thorpej 	} else {
    679  1.88.2.2  thorpej 		scsibusprint(&sa, scsi->sc_dev.dv_xname);
    680  1.88.2.2  thorpej 		printf(" not configured\n");
    681  1.88.2.2  thorpej 		goto bad;
    682  1.88.2.2  thorpej 	}
    683  1.88.2.2  thorpej 
    684  1.88.2.2  thorpej 	return;
    685  1.88.2.2  thorpej 
    686  1.88.2.2  thorpej bad:
    687  1.88.2.2  thorpej 	free(sc_link, M_DEVBUF);
    688  1.88.2.2  thorpej 	return;
    689  1.88.2.2  thorpej }
    690