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