Home | History | Annotate | Line # | Download | only in scsipi
scsiconf.c revision 1.50
      1  1.50   mycroft /*	$NetBSD: scsiconf.c,v 1.50 1996/02/22 23:37:27 mycroft Exp $	*/
      2  1.14       cgd 
      3   1.1       cgd /*
      4  1.12   mycroft  * Copyright (c) 1994 Charles Hannum.  All rights reserved.
      5  1.12   mycroft  *
      6  1.12   mycroft  * Redistribution and use in source and binary forms, with or without
      7  1.12   mycroft  * modification, are permitted provided that the following conditions
      8  1.12   mycroft  * are met:
      9  1.12   mycroft  * 1. Redistributions of source code must retain the above copyright
     10  1.12   mycroft  *    notice, this list of conditions and the following disclaimer.
     11  1.12   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.12   mycroft  *    notice, this list of conditions and the following disclaimer in the
     13  1.12   mycroft  *    documentation and/or other materials provided with the distribution.
     14  1.12   mycroft  * 3. All advertising materials mentioning features or use of this software
     15  1.12   mycroft  *    must display the following acknowledgement:
     16  1.12   mycroft  *	This product includes software developed by Charles Hannum.
     17  1.12   mycroft  * 4. The name of the author may not be used to endorse or promote products
     18  1.12   mycroft  *    derived from this software without specific prior written permission.
     19  1.12   mycroft  *
     20  1.12   mycroft  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  1.12   mycroft  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  1.12   mycroft  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  1.12   mycroft  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  1.12   mycroft  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  1.12   mycroft  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  1.12   mycroft  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  1.12   mycroft  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  1.12   mycroft  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  1.12   mycroft  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  1.12   mycroft  */
     31  1.12   mycroft 
     32  1.12   mycroft /*
     33  1.12   mycroft  * Originally written by Julian Elischer (julian (at) tfs.com)
     34   1.5   deraadt  * for TRW Financial Systems for use under the MACH(2.5) operating system.
     35   1.1       cgd  *
     36   1.1       cgd  * TRW Financial Systems, in accordance with their agreement with Carnegie
     37   1.1       cgd  * Mellon University, makes this software available to CMU to distribute
     38   1.1       cgd  * or use in any manner that they see fit as long as this message is kept with
     39   1.1       cgd  * the software. For this reason TFS also grants any other persons or
     40   1.1       cgd  * organisations permission to use or modify this software.
     41   1.1       cgd  *
     42   1.1       cgd  * TFS supplies this software to be publicly redistributed
     43   1.1       cgd  * on the understanding that TFS is not responsible for the correct
     44   1.1       cgd  * functioning of this software in any circumstances.
     45   1.7       cgd  *
     46  1.12   mycroft  * Ported to run under 386BSD by Julian Elischer (julian (at) tfs.com) Sept 1992
     47   1.1       cgd  */
     48   1.1       cgd 
     49  1.10   mycroft #include <sys/types.h>
     50  1.10   mycroft #include <sys/param.h>
     51  1.10   mycroft #include <sys/systm.h>
     52  1.12   mycroft #include <sys/malloc.h>
     53  1.12   mycroft #include <sys/device.h>
     54  1.48  christos #include <sys/cpu.h>
     55  1.10   mycroft 
     56  1.10   mycroft #include <scsi/scsi_all.h>
     57  1.10   mycroft #include <scsi/scsiconf.h>
     58   1.1       cgd 
     59  1.18   mycroft #if 0
     60  1.12   mycroft #if NCALS > 0
     61  1.18   mycroft 	{ T_PROCESSOR, T_FIXED, 1,
     62  1.18   mycroft 	  0, 0, 0 },
     63  1.12   mycroft #endif	/* NCALS */
     64   1.1       cgd #if NBLL > 0
     65  1.18   mycroft 	{ T_PROCESSOR, T_FIXED, 1,
     66  1.12   mycroft 	  "AEG     ", "READER          ", "V1.0" },
     67  1.12   mycroft #endif	/* NBLL */
     68   1.1       cgd #if NKIL > 0
     69  1.18   mycroft 	{ T_SCANNER, T_FIXED, 0,
     70  1.18   mycroft 	  "KODAK   ", "IL Scanner 900  ", 0 },
     71  1.12   mycroft #endif	/* NKIL */
     72  1.18   mycroft #endif
     73  1.12   mycroft 
     74  1.12   mycroft /*
     75  1.12   mycroft  * Declarations
     76  1.12   mycroft  */
     77  1.18   mycroft void scsi_probedev __P((struct scsibus_softc *, int, int));
     78  1.18   mycroft int scsi_probe_bus __P((int bus, int target, int lun));
     79  1.12   mycroft 
     80  1.12   mycroft struct scsi_device probe_switch = {
     81  1.12   mycroft 	NULL,
     82  1.12   mycroft 	NULL,
     83  1.12   mycroft 	NULL,
     84  1.12   mycroft 	NULL,
     85  1.12   mycroft };
     86  1.12   mycroft 
     87  1.16   mycroft int scsibusmatch __P((struct device *, void *, void *));
     88  1.12   mycroft void scsibusattach __P((struct device *, struct device *, void *));
     89  1.48  christos int scsibussubmatch __P((struct device *, void *, void *));
     90  1.12   mycroft 
     91  1.12   mycroft struct cfdriver scsibuscd = {
     92  1.12   mycroft 	NULL, "scsibus", scsibusmatch, scsibusattach, DV_DULL,
     93  1.18   mycroft 	sizeof(struct scsibus_softc)
     94  1.12   mycroft };
     95  1.12   mycroft 
     96  1.12   mycroft int
     97  1.17   mycroft scsibusmatch(parent, match, aux)
     98  1.12   mycroft         struct device *parent;
     99  1.17   mycroft         void *match, *aux;
    100  1.12   mycroft {
    101  1.12   mycroft 
    102  1.12   mycroft 	return 1;
    103  1.12   mycroft }
    104  1.12   mycroft 
    105  1.12   mycroft /*
    106  1.12   mycroft  * The routine called by the adapter boards to get all their
    107  1.12   mycroft  * devices configured in.
    108  1.12   mycroft  */
    109  1.12   mycroft void
    110  1.12   mycroft scsibusattach(parent, self, aux)
    111  1.12   mycroft         struct device *parent, *self;
    112  1.12   mycroft         void *aux;
    113  1.12   mycroft {
    114  1.18   mycroft 	struct scsibus_softc *sb = (struct scsibus_softc *)self;
    115  1.12   mycroft 	struct scsi_link *sc_link_proto = aux;
    116  1.12   mycroft 
    117  1.12   mycroft 	sc_link_proto->scsibus = sb->sc_dev.dv_unit;
    118  1.12   mycroft 	sb->adapter_link = sc_link_proto;
    119  1.12   mycroft 	printf("\n");
    120  1.12   mycroft 
    121  1.12   mycroft #if defined(SCSI_DELAY) && SCSI_DELAY > 2
    122  1.12   mycroft 	printf("%s: waiting for scsi devices to settle\n",
    123  1.12   mycroft 		sb->sc_dev.dv_xname);
    124  1.12   mycroft #else	/* SCSI_DELAY > 2 */
    125  1.12   mycroft #undef	SCSI_DELAY
    126  1.12   mycroft #define SCSI_DELAY 2
    127  1.12   mycroft #endif	/* SCSI_DELAY */
    128  1.12   mycroft 	delay(1000000 * SCSI_DELAY);
    129  1.12   mycroft 
    130  1.12   mycroft 	scsi_probe_bus(sb->sc_dev.dv_unit, -1, -1);
    131  1.12   mycroft }
    132  1.12   mycroft 
    133  1.18   mycroft int
    134  1.18   mycroft scsibussubmatch(parent, match, aux)
    135  1.18   mycroft 	struct device *parent;
    136  1.18   mycroft 	void *match, *aux;
    137  1.18   mycroft {
    138  1.18   mycroft 	struct cfdata *cf = match;
    139  1.18   mycroft 	struct scsibus_attach_args *sa = aux;
    140  1.18   mycroft 	struct scsi_link *sc_link = sa->sa_sc_link;
    141  1.18   mycroft 
    142  1.18   mycroft 	if (cf->cf_loc[0] != -1 && cf->cf_loc[0] != sc_link->target)
    143  1.18   mycroft 		return 0;
    144  1.18   mycroft 	if (cf->cf_loc[1] != -1 && cf->cf_loc[1] != sc_link->lun)
    145  1.18   mycroft 		return 0;
    146  1.18   mycroft 	return ((*cf->cf_driver->cd_match)(parent, match, aux));
    147  1.18   mycroft }
    148  1.18   mycroft 
    149  1.12   mycroft /*
    150  1.12   mycroft  * Probe the requested scsi bus. It must be already set up.
    151  1.12   mycroft  * -1 requests all set up scsi busses.
    152  1.18   mycroft  * target and lun optionally narrow the search if not -1
    153  1.12   mycroft  */
    154  1.12   mycroft int
    155  1.18   mycroft scsi_probe_busses(bus, target, lun)
    156  1.18   mycroft 	int bus, target, lun;
    157  1.12   mycroft {
    158  1.12   mycroft 
    159  1.12   mycroft 	if (bus == -1) {
    160  1.12   mycroft 		for (bus = 0; bus < scsibuscd.cd_ndevs; bus++)
    161  1.12   mycroft 			if (scsibuscd.cd_devs[bus])
    162  1.18   mycroft 				scsi_probe_bus(bus, target, lun);
    163  1.12   mycroft 		return 0;
    164  1.12   mycroft 	} else {
    165  1.18   mycroft 		return scsi_probe_bus(bus, target, lun);
    166  1.12   mycroft 	}
    167  1.12   mycroft }
    168  1.12   mycroft 
    169  1.12   mycroft /*
    170  1.12   mycroft  * Probe the requested scsi bus. It must be already set up.
    171  1.18   mycroft  * target and lun optionally narrow the search if not -1
    172  1.12   mycroft  */
    173  1.12   mycroft int
    174  1.18   mycroft scsi_probe_bus(bus, target, lun)
    175  1.18   mycroft 	int bus, target, lun;
    176  1.12   mycroft {
    177  1.18   mycroft 	struct scsibus_softc *scsi;
    178  1.18   mycroft 	int maxtarget, mintarget, maxlun, minlun;
    179  1.18   mycroft 	u_int8_t scsi_addr;
    180  1.12   mycroft 
    181  1.12   mycroft 	if (bus < 0 || bus >= scsibuscd.cd_ndevs)
    182  1.12   mycroft 		return ENXIO;
    183  1.12   mycroft 	scsi = scsibuscd.cd_devs[bus];
    184  1.12   mycroft 	if (!scsi)
    185  1.12   mycroft 		return ENXIO;
    186  1.12   mycroft 
    187  1.18   mycroft 	scsi_addr = scsi->adapter_link->adapter_target;
    188  1.12   mycroft 
    189  1.18   mycroft 	if (target == -1) {
    190  1.18   mycroft 		maxtarget = 7;
    191  1.18   mycroft 		mintarget = 0;
    192  1.12   mycroft 	} else {
    193  1.18   mycroft 		if (target < 0 || target > 7)
    194  1.12   mycroft 			return EINVAL;
    195  1.18   mycroft 		maxtarget = mintarget = target;
    196  1.12   mycroft 	}
    197   1.1       cgd 
    198  1.12   mycroft 	if (lun == -1) {
    199  1.12   mycroft 		maxlun = 7;
    200  1.12   mycroft 		minlun = 0;
    201  1.12   mycroft 	} else {
    202  1.12   mycroft 		if (lun < 0 || lun > 7)
    203  1.12   mycroft 			return EINVAL;
    204  1.12   mycroft 		maxlun = minlun = lun;
    205  1.12   mycroft 	}
    206  1.12   mycroft 
    207  1.18   mycroft 	for (target = mintarget; target <= maxtarget; target++) {
    208  1.18   mycroft 		if (target == scsi_addr)
    209  1.12   mycroft 			continue;
    210  1.12   mycroft 		for (lun = minlun; lun <= maxlun; lun++) {
    211  1.12   mycroft 			/*
    212  1.18   mycroft 			 * See if there's a device present, and configure it.
    213  1.12   mycroft 			 */
    214  1.18   mycroft 			scsi_probedev(scsi, target, lun);
    215  1.18   mycroft 			if ((scsi->moreluns & (1 << target)) == 0)
    216  1.18   mycroft 				break;
    217  1.12   mycroft 			/* otherwise something says we should look further */
    218  1.12   mycroft 		}
    219   1.8   deraadt 	}
    220  1.12   mycroft 	return 0;
    221  1.12   mycroft }
    222  1.12   mycroft 
    223  1.18   mycroft void
    224  1.18   mycroft scsi_strvis(dst, src, len)
    225  1.18   mycroft 	u_char *dst, *src;
    226  1.18   mycroft 	int len;
    227  1.12   mycroft {
    228  1.12   mycroft 
    229  1.45   mycroft 	/* Trim leading and trailing blanks and NULs. */
    230  1.45   mycroft 	while (len > 0 && (src[0] == ' ' || src[0] == '\0'))
    231  1.18   mycroft 		++src, --len;
    232  1.45   mycroft 	while (len > 0 && (src[len-1] == ' ' || src[len-1] == '\0'))
    233  1.18   mycroft 		--len;
    234  1.18   mycroft 
    235  1.18   mycroft 	while (len > 0) {
    236  1.20   mycroft 		if (*src < 0x20 || *src >= 0x80) {
    237  1.18   mycroft 			/* non-printable characters */
    238  1.18   mycroft 			*dst++ = '\\';
    239  1.19   mycroft 			*dst++ = ((*src & 0300) >> 6) + '0';
    240  1.19   mycroft 			*dst++ = ((*src & 0070) >> 3) + '0';
    241  1.19   mycroft 			*dst++ = ((*src & 0007) >> 0) + '0';
    242  1.18   mycroft 		} else if (*src == '\\') {
    243  1.18   mycroft 			/* quote characters */
    244  1.18   mycroft 			*dst++ = '\\';
    245  1.18   mycroft 			*dst++ = '\\';
    246  1.18   mycroft 		} else {
    247  1.18   mycroft 			/* normal characters */
    248  1.18   mycroft 			*dst++ = *src;
    249  1.18   mycroft 		}
    250  1.18   mycroft 		++src, --len;
    251  1.18   mycroft 	}
    252   1.2   deraadt 
    253  1.18   mycroft 	*dst++ = 0;
    254  1.12   mycroft }
    255   1.1       cgd 
    256  1.18   mycroft struct scsi_quirk_inquiry_pattern {
    257  1.18   mycroft 	struct scsi_inquiry_pattern pattern;
    258  1.18   mycroft 	u_int8_t quirks;
    259  1.18   mycroft };
    260  1.18   mycroft 
    261  1.18   mycroft struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
    262  1.48  christos 	{{T_CDROM, T_REMOV,
    263  1.48  christos 	 "CHINON  ", "CD-ROM CDS-431  ", ""},     SDEV_NOLUNS},
    264  1.48  christos 	{{T_CDROM, T_REMOV,
    265  1.48  christos 	 "Chinon  ", "CD-ROM CDS-525  ", ""},     SDEV_NOLUNS},
    266  1.48  christos 	{{T_CDROM, T_REMOV,
    267  1.48  christos 	 "CHINON  ", "CD-ROM CDS-535  ", ""},     SDEV_NOLUNS},
    268  1.48  christos 	{{T_CDROM, T_REMOV,
    269  1.48  christos 	 "DENON   ", "DRD-25X         ", "V"},    SDEV_NOLUNS},
    270  1.48  christos 	{{T_CDROM, T_REMOV,
    271  1.48  christos 	 "IMS     ", "CDD521/10       ", "2.06"}, SDEV_NOLUNS},
    272  1.48  christos 	{{T_CDROM, T_REMOV,
    273  1.48  christos 	 "MEDIAVIS", "CDR-H93MV       ", "1.31"}, SDEV_NOLUNS},
    274  1.48  christos 	{{T_CDROM, T_REMOV,
    275  1.48  christos 	 "NEC     ", "CD-ROM DRIVE:55 ", ""},     SDEV_NOLUNS},
    276  1.48  christos 	{{T_CDROM, T_REMOV,
    277  1.48  christos 	 "NEC     ", "CD-ROM DRIVE:83 ", ""},     SDEV_NOLUNS},
    278  1.48  christos 	{{T_CDROM, T_REMOV,
    279  1.48  christos 	 "NEC     ", "CD-ROM DRIVE:84 ", ""},     SDEV_NOLUNS},
    280  1.48  christos 	{{T_CDROM, T_REMOV,
    281  1.48  christos 	 "NEC     ", "CD-ROM DRIVE:841", ""},     SDEV_NOLUNS},
    282  1.48  christos 	{{T_CDROM, T_REMOV,
    283  1.48  christos 	 "SONY    ", "CD-ROM CDU-541  ", ""},     SDEV_NOLUNS},
    284  1.48  christos 	{{T_CDROM, T_REMOV,
    285  1.48  christos 	 "SONY    ", "CD-ROM CDU-55S  ", ""},     SDEV_NOLUNS},
    286  1.48  christos 	{{T_CDROM, T_REMOV,
    287  1.48  christos 	 "SONY    ", "CD-ROM CDU-8003A", ""},     SDEV_NOLUNS},
    288  1.48  christos 	{{T_CDROM, T_REMOV,
    289  1.48  christos 	 "SONY    ", "CD-ROM CDU-8012 ", ""},     SDEV_NOLUNS},
    290  1.48  christos 	{{T_CDROM, T_REMOV,
    291  1.48  christos 	 "TEAC    ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    292  1.48  christos 	{{T_CDROM, T_REMOV,
    293  1.48  christos 	 "TEXEL   ", "CD-ROM          ", "1.06"}, SDEV_NOLUNS},
    294  1.48  christos 	{{T_CDROM, T_REMOV,
    295  1.48  christos 	 "TEXEL   ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
    296  1.48  christos 
    297  1.50   mycroft 	{{T_DIRECT, T_FIXED,
    298  1.50   mycroft 	 "DEC     ", "RZ55     (C) DEC", ""},     SDEV_AUTOSAVE},
    299  1.48  christos 	{{T_DIRECT, T_FIXED,
    300  1.48  christos 	 "EMULEX  ", "MD21/S2     ESDI", "A00"},  SDEV_FORCELUNS},
    301  1.48  christos 	{{T_DIRECT, T_FIXED,
    302  1.48  christos 	 "MAXTOR  ", "XT-3280         ", ""},     SDEV_NOLUNS},
    303  1.48  christos 	{{T_DIRECT, T_FIXED,
    304  1.48  christos 	 "MAXTOR  ", "XT-4380S        ", ""},     SDEV_NOLUNS},
    305  1.48  christos 	{{T_DIRECT, T_FIXED,
    306  1.48  christos 	 "MAXTOR  ", "MXT-1240S       ", ""},     SDEV_NOLUNS},
    307  1.48  christos 	{{T_DIRECT, T_FIXED,
    308  1.48  christos 	 "MAXTOR  ", "XT-4170S        ", ""},     SDEV_NOLUNS},
    309  1.48  christos 	{{T_DIRECT, T_FIXED,
    310  1.48  christos 	 "MAXTOR  ", "XT-8760S        ", ""},     SDEV_NOLUNS},
    311  1.48  christos 	{{T_DIRECT, T_FIXED,
    312  1.48  christos 	 "MAXTOR  ", "LXT-213S        ", ""},     SDEV_NOLUNS},
    313  1.48  christos 	{{T_DIRECT, T_FIXED,
    314  1.48  christos 	 "MAXTOR  ", "LXT-213S SUN0207", ""},     SDEV_NOLUNS},
    315  1.48  christos 	{{T_DIRECT, T_FIXED,
    316  1.48  christos 	 "MST     ", "SnapLink        ", ""},     SDEV_NOLUNS},
    317  1.48  christos 	{{T_DIRECT, T_FIXED,
    318  1.48  christos 	 "QUANTUM ", "LPS525S         ", ""},     SDEV_NOLUNS},
    319  1.48  christos 	{{T_DIRECT, T_FIXED,
    320  1.48  christos 	 "QUANTUM ", "P105S 910-10-94x", ""},     SDEV_NOLUNS},
    321  1.48  christos 	{{T_DIRECT, T_FIXED,
    322  1.48  christos 	 "QUANTUM ", "PD1225S         ", ""},     SDEV_NOLUNS},
    323  1.48  christos 	{{T_DIRECT, T_FIXED,
    324  1.48  christos 	 "QUANTUM ", "PD210S   SUN0207", ""},     SDEV_NOLUNS},
    325  1.48  christos 	{{T_DIRECT, T_FIXED,
    326  1.48  christos 	 "RODIME  ", "RO3000S         ", ""},     SDEV_NOLUNS},
    327  1.48  christos 	{{T_DIRECT, T_FIXED,
    328  1.48  christos 	 "SEAGATE ", "ST157N          ", ""},     SDEV_NOLUNS},
    329  1.48  christos 	{{T_DIRECT, T_FIXED,
    330  1.48  christos 	 "SEAGATE ", "ST296           ", ""},     SDEV_NOLUNS},
    331  1.48  christos 	{{T_DIRECT, T_FIXED,
    332  1.48  christos 	 "SEAGATE ", "ST296N          ", ""},     SDEV_NOLUNS},
    333  1.48  christos 	{{T_DIRECT, T_FIXED,
    334  1.48  christos 	 "TOSHIBA ", "MK538FB         ", "6027"}, SDEV_NOLUNS},
    335  1.18   mycroft 
    336  1.37       cgd 	/* XXX: QIC-36 tape behind Emulex adapter.  Very broken. */
    337  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    338  1.48  christos 	 "        ", "                ", "    "}, SDEV_NOLUNS},
    339  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    340  1.48  christos 	 "CALIPER ", "CP150           ", ""},     SDEV_NOLUNS},
    341  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    342  1.48  christos 	 "EXABYTE ", "EXB-8200        ", ""},     SDEV_NOLUNS},
    343  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    344  1.48  christos 	 "SONY    ", "SDT-2000        ", "2.09"}, SDEV_NOLUNS},
    345  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    346  1.48  christos 	 "SONY    ", "SDT-5000        ", "3."},   SDEV_NOSYNCWIDE},
    347  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    348  1.48  christos 	 "SONY    ", "SDT-5200        ", "3."},   SDEV_NOLUNS},
    349  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    350  1.48  christos 	 "TANDBERG", " TDC 3600       ", ""},     SDEV_NOLUNS},
    351  1.47        pk 	/* Following entry reported as a Tandberg 3600; ref. PR1933 */
    352  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    353  1.48  christos 	 "ARCHIVE ", "VIPER 150  21247", ""},     SDEV_NOLUNS},
    354  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    355  1.48  christos 	 "WANGTEK ", "5099ES SCSI",      ""},     SDEV_NOLUNS},
    356  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    357  1.48  christos 	 "WANGTEK ", "5150ES SCSI",      ""},     SDEV_NOLUNS},
    358  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    359  1.48  christos 	 "WangDAT ", "Model 1300      ", "02.4"}, SDEV_NOSYNCWIDE},
    360  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    361  1.48  christos 	 "WangDAT ", "Model 2600      ", "01.7"}, SDEV_NOSYNCWIDE},
    362  1.48  christos 	{{T_SEQUENTIAL, T_REMOV,
    363  1.48  christos 	 "WangDAT ", "Model 3200      ", "02.2"}, SDEV_NOSYNCWIDE},
    364  1.18   mycroft };
    365  1.18   mycroft 
    366  1.12   mycroft /*
    367  1.12   mycroft  * given a target and lu, ask the device what
    368  1.12   mycroft  * it is, and find the correct driver table
    369  1.12   mycroft  * entry.
    370  1.12   mycroft  */
    371  1.18   mycroft void
    372  1.18   mycroft scsi_probedev(scsi, target, lun)
    373  1.18   mycroft 	struct scsibus_softc *scsi;
    374  1.18   mycroft 	int target, lun;
    375  1.18   mycroft {
    376  1.12   mycroft 	struct scsi_link *sc_link;
    377   1.2   deraadt 	static struct scsi_inquiry_data inqbuf;
    378  1.18   mycroft 	struct scsi_quirk_inquiry_pattern *finger;
    379  1.18   mycroft 	int priority;
    380  1.18   mycroft 	u_int8_t type;
    381  1.18   mycroft 	boolean removable;
    382  1.18   mycroft 	char *dtype, *qtype;
    383  1.18   mycroft 	char vendor[33], product[65], revision[17];
    384  1.18   mycroft 	struct scsibus_attach_args sa;
    385  1.18   mycroft 	struct cfdata *cf;
    386  1.18   mycroft 
    387  1.18   mycroft 	/* Skip this slot if it is already attached. */
    388  1.18   mycroft 	if (scsi->sc_link[target][lun])
    389  1.18   mycroft 		return;
    390  1.18   mycroft 
    391  1.18   mycroft 	sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
    392  1.18   mycroft 	*sc_link = *scsi->adapter_link;
    393  1.18   mycroft 	sc_link->target = target;
    394  1.18   mycroft 	sc_link->lun = lun;
    395  1.18   mycroft 	sc_link->device = &probe_switch;
    396  1.12   mycroft 
    397  1.12   mycroft 	/*
    398  1.12   mycroft 	 * Ask the device what it is
    399  1.12   mycroft 	 */
    400  1.23   mycroft #ifdef SCSIDEBUG
    401  1.18   mycroft 	if (target == DEBUGTARGET && lun == DEBUGLUN)
    402  1.12   mycroft 		sc_link->flags |= DEBUGLEVEL;
    403  1.23   mycroft #endif /* SCSIDEBUG */
    404   1.2   deraadt 
    405  1.18   mycroft 	(void) scsi_test_unit_ready(sc_link,
    406  1.18   mycroft 	    SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
    407  1.18   mycroft 
    408  1.23   mycroft #ifdef SCSI_2_DEF
    409  1.12   mycroft 	/* some devices need to be told to go to SCSI2 */
    410  1.12   mycroft 	/* However some just explode if you tell them this.. leave it out */
    411  1.18   mycroft 	scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
    412  1.18   mycroft #endif /* SCSI_2_DEF */
    413  1.18   mycroft 
    414  1.18   mycroft 	/* Now go ask the device all about itself. */
    415  1.18   mycroft 	bzero(&inqbuf, sizeof(inqbuf));
    416  1.18   mycroft 	if (scsi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
    417  1.18   mycroft 		goto bad;
    418  1.18   mycroft 
    419  1.18   mycroft 	{
    420  1.18   mycroft 		int len = inqbuf.additional_length;
    421  1.20   mycroft 		while (len < 3)
    422  1.20   mycroft 			inqbuf.unused[len++] = '\0';
    423  1.20   mycroft 		while (len < 3 + 28)
    424  1.20   mycroft 			inqbuf.unused[len++] = ' ';
    425  1.18   mycroft 	}
    426  1.18   mycroft 
    427  1.18   mycroft 	finger = (struct scsi_quirk_inquiry_pattern *)scsi_inqmatch(&inqbuf,
    428  1.18   mycroft 	    (caddr_t)scsi_quirk_patterns,
    429  1.18   mycroft 	    sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
    430  1.18   mycroft 	    sizeof(scsi_quirk_patterns[0]), &priority);
    431  1.18   mycroft 	if (priority != 0)
    432  1.18   mycroft 		sc_link->quirks |= finger->quirks;
    433  1.36       cgd 	if ((inqbuf.version & SID_ANSII) == 0 &&
    434  1.36       cgd 	    (sc_link->quirks & SDEV_FORCELUNS) == 0)
    435  1.18   mycroft 		sc_link->quirks |= SDEV_NOLUNS;
    436  1.12   mycroft 
    437  1.18   mycroft 	if ((sc_link->quirks & SDEV_NOLUNS) == 0)
    438  1.18   mycroft 		scsi->moreluns |= (1 << target);
    439  1.12   mycroft 
    440  1.12   mycroft 	/*
    441  1.12   mycroft 	 * note what BASIC type of device it is
    442  1.12   mycroft 	 */
    443  1.12   mycroft 	type = inqbuf.device & SID_TYPE;
    444  1.18   mycroft 	removable = inqbuf.dev_qual2 & SID_REMOVABLE ? 1 : 0;
    445  1.18   mycroft 
    446  1.18   mycroft 	if (removable)
    447  1.18   mycroft 		sc_link->flags |= SDEV_REMOVABLE;
    448  1.12   mycroft 
    449  1.12   mycroft 	/*
    450  1.12   mycroft 	 * Any device qualifier that has the top bit set (qualifier&4 != 0)
    451  1.12   mycroft 	 * is vendor specific and won't match in this switch.
    452  1.12   mycroft 	 */
    453  1.18   mycroft 	dtype = 0;
    454  1.18   mycroft 	switch (inqbuf.device & SID_QUAL) {
    455  1.12   mycroft 	case SID_QUAL_LU_OK:
    456   1.2   deraadt 		qtype = "";
    457   1.2   deraadt 		break;
    458  1.12   mycroft 
    459  1.12   mycroft 	case SID_QUAL_LU_OFFLINE:
    460  1.18   mycroft 		qtype = " offline";
    461   1.2   deraadt 		break;
    462  1.12   mycroft 
    463  1.12   mycroft 	case SID_QUAL_RSVD:
    464  1.12   mycroft 	case SID_QUAL_BAD_LU:
    465  1.18   mycroft 		goto bad;
    466  1.12   mycroft 
    467   1.2   deraadt 	default:
    468   1.2   deraadt 		qtype = "";
    469  1.18   mycroft 		dtype = "vendor-unique";
    470   1.2   deraadt 		break;
    471   1.2   deraadt 	}
    472  1.12   mycroft 	if (dtype == 0) {
    473  1.12   mycroft 		switch (type) {
    474   1.2   deraadt 		case T_DIRECT:
    475   1.2   deraadt 			dtype = "direct";
    476   1.2   deraadt 			break;
    477   1.2   deraadt 		case T_SEQUENTIAL:
    478  1.12   mycroft 			dtype = "sequential";
    479   1.2   deraadt 			break;
    480   1.2   deraadt 		case T_PRINTER:
    481  1.12   mycroft 			dtype = "printer";
    482   1.2   deraadt 			break;
    483   1.2   deraadt 		case T_PROCESSOR:
    484  1.12   mycroft 			dtype = "processor";
    485   1.2   deraadt 			break;
    486  1.18   mycroft 		case T_CDROM:
    487  1.18   mycroft 			dtype = "cdrom";
    488   1.2   deraadt 			break;
    489   1.2   deraadt 		case T_WORM:
    490   1.2   deraadt 			dtype = "worm";
    491   1.2   deraadt 			break;
    492   1.2   deraadt 		case T_SCANNER:
    493  1.12   mycroft 			dtype = "scanner";
    494   1.2   deraadt 			break;
    495   1.2   deraadt 		case T_OPTICAL:
    496  1.12   mycroft 			dtype = "optical";
    497   1.2   deraadt 			break;
    498   1.2   deraadt 		case T_CHANGER:
    499   1.2   deraadt 			dtype = "changer";
    500   1.2   deraadt 			break;
    501   1.2   deraadt 		case T_COMM:
    502  1.12   mycroft 			dtype = "communication";
    503   1.2   deraadt 			break;
    504  1.12   mycroft 		case T_NODEVICE:
    505  1.18   mycroft 			goto bad;
    506   1.2   deraadt 		default:
    507  1.18   mycroft 			dtype = "unknown";
    508   1.2   deraadt 			break;
    509   1.1       cgd 		}
    510   1.1       cgd 	}
    511   1.2   deraadt 
    512  1.18   mycroft 	scsi_strvis(vendor, inqbuf.vendor, 8);
    513  1.18   mycroft 	scsi_strvis(product, inqbuf.product, 16);
    514  1.18   mycroft 	scsi_strvis(revision, inqbuf.revision, 4);
    515  1.18   mycroft 
    516  1.18   mycroft 	printf("%s targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s\n",
    517  1.18   mycroft 	    ((struct device *)sc_link->adapter_softc)->dv_xname,
    518  1.18   mycroft 	    target, lun, vendor, product, revision,
    519  1.18   mycroft 	    inqbuf.version & SID_ANSII, type, dtype,
    520  1.18   mycroft 	    removable ? "removable" : "fixed", qtype);
    521  1.18   mycroft 
    522  1.18   mycroft 	sa.sa_sc_link = sc_link;
    523  1.18   mycroft 	sa.sa_inqbuf = &inqbuf;
    524  1.18   mycroft 
    525  1.18   mycroft 	if ((cf = config_search(scsibussubmatch, (struct device *)scsi, &sa)) != 0) {
    526  1.41        pk 		scsi->sc_link[target][lun] = sc_link;
    527  1.18   mycroft 		config_attach((struct device *)scsi, cf, &sa, NULL);
    528  1.12   mycroft 	} else
    529  1.18   mycroft 		goto bad;
    530  1.18   mycroft 
    531  1.18   mycroft 	return;
    532  1.12   mycroft 
    533  1.18   mycroft bad:
    534  1.18   mycroft 	free(sc_link, M_DEVBUF);
    535  1.18   mycroft 	return;
    536   1.1       cgd }
    537   1.1       cgd 
    538   1.2   deraadt /*
    539  1.18   mycroft  * Return a priority based on how much of the inquiry data matches
    540  1.18   mycroft  * the patterns for the particular driver.
    541   1.2   deraadt  */
    542  1.18   mycroft caddr_t
    543  1.18   mycroft scsi_inqmatch(inqbuf, base, nmatches, matchsize, bestpriority)
    544  1.18   mycroft 	struct scsi_inquiry_data *inqbuf;
    545  1.18   mycroft 	caddr_t base;
    546  1.18   mycroft 	int nmatches, matchsize;
    547  1.18   mycroft 	int *bestpriority;
    548   1.2   deraadt {
    549  1.18   mycroft 	u_int8_t type;
    550  1.18   mycroft 	boolean removable;
    551  1.18   mycroft 	caddr_t bestmatch;
    552  1.18   mycroft 
    553  1.18   mycroft 	/* Include the qualifier to catch vendor-unique types. */
    554  1.18   mycroft 	type = inqbuf->device;
    555  1.18   mycroft 	removable = inqbuf->dev_qual2 & SID_REMOVABLE ? T_REMOV : T_FIXED;
    556  1.18   mycroft 
    557  1.18   mycroft 	for (*bestpriority = 0, bestmatch = 0; nmatches--; base += matchsize) {
    558  1.18   mycroft 		struct scsi_inquiry_pattern *match = (void *)base;
    559  1.18   mycroft 		int priority, len;
    560  1.18   mycroft 
    561  1.18   mycroft 		if (type != match->type)
    562   1.1       cgd 			continue;
    563  1.18   mycroft 		if (removable != match->removable)
    564   1.1       cgd 			continue;
    565  1.18   mycroft 		priority = 2;
    566  1.18   mycroft 		len = strlen(match->vendor);
    567  1.18   mycroft 		if (bcmp(inqbuf->vendor, match->vendor, len))
    568   1.1       cgd 			continue;
    569  1.18   mycroft 		priority += len;
    570  1.18   mycroft 		len = strlen(match->product);
    571  1.18   mycroft 		if (bcmp(inqbuf->product, match->product, len))
    572   1.1       cgd 			continue;
    573  1.18   mycroft 		priority += len;
    574  1.18   mycroft 		len = strlen(match->revision);
    575  1.18   mycroft 		if (bcmp(inqbuf->revision, match->revision, len))
    576   1.1       cgd 			continue;
    577  1.18   mycroft 		priority += len;
    578  1.18   mycroft 
    579  1.44        pk #if SCSIDEBUG
    580  1.18   mycroft 		printf("scsi_inqmatch: %d/%d/%d <%s, %s, %s>\n",
    581  1.18   mycroft 		    priority, match->type, match->removable,
    582  1.18   mycroft 		    match->vendor, match->product, match->revision);
    583  1.18   mycroft #endif
    584  1.18   mycroft 		if (priority > *bestpriority) {
    585  1.18   mycroft 			*bestpriority = priority;
    586  1.18   mycroft 			bestmatch = base;
    587   1.1       cgd 		}
    588   1.1       cgd 	}
    589  1.18   mycroft 
    590  1.18   mycroft 	return (bestmatch);
    591   1.1       cgd }
    592