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