scsiconf.c revision 1.117 1 /* $NetBSD: scsiconf.c,v 1.117 1998/11/19 22:28:20 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 (at) 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 (at) 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 = scsipi_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 int error;
257
258 if (bus < 0 || bus >= scsibus_cd.cd_ndevs)
259 return (ENXIO);
260 scsi = scsibus_cd.cd_devs[bus];
261 if (scsi == NULL)
262 return (ENXIO);
263
264 scsi_addr = scsi->adapter_link->scsipi_scsi.adapter_target;
265
266 if (target == -1) {
267 maxtarget = scsi->sc_maxtarget;
268 mintarget = 0;
269 } else {
270 if (target < 0 || target > scsi->sc_maxtarget)
271 return (EINVAL);
272 maxtarget = mintarget = target;
273 }
274
275 if (lun == -1) {
276 maxlun = 7;
277 minlun = 0;
278 } else {
279 if (lun < 0 || lun > 7)
280 return (EINVAL);
281 maxlun = minlun = lun;
282 }
283
284 if ((error = scsipi_adapter_addref(scsi->adapter_link)) != 0)
285 return (error);
286 for (target = mintarget; target <= maxtarget; target++) {
287 if (target == scsi_addr)
288 continue;
289 for (lun = minlun; lun <= maxlun; lun++) {
290 /*
291 * See if there's a device present, and configure it.
292 */
293 scsi_probedev(scsi, target, lun);
294 if ((scsi->moreluns & (1 << target)) == 0)
295 break;
296 /* otherwise something says we should look further */
297 }
298 }
299 scsipi_adapter_delref(scsi->adapter_link);
300 return (0);
301 }
302
303 /*
304 * Print out autoconfiguration information for a subdevice.
305 *
306 * This is a slight abuse of 'standard' autoconfiguration semantics,
307 * because 'print' functions don't normally print the colon and
308 * device information. However, in this case that's better than
309 * either printing redundant information before the attach message,
310 * or having the device driver call a special function to print out
311 * the standard device information.
312 */
313 int
314 scsibusprint(aux, pnp)
315 void *aux;
316 const char *pnp;
317 {
318 struct scsipibus_attach_args *sa = aux;
319 struct scsipi_inquiry_pattern *inqbuf;
320 u_int8_t type;
321 char *dtype, *qtype;
322 char vendor[33], product[65], revision[17];
323 int target, lun;
324
325 if (pnp != NULL)
326 printf("%s", pnp);
327
328 inqbuf = &sa->sa_inqbuf;
329
330 target = sa->sa_sc_link->scsipi_scsi.target;
331 lun = sa->sa_sc_link->scsipi_scsi.lun;
332
333 type = inqbuf->type & SID_TYPE;
334
335 /*
336 * Figure out basic device type and qualifier.
337 */
338 dtype = 0;
339 switch (inqbuf->type & SID_QUAL) {
340 case SID_QUAL_LU_OK:
341 qtype = "";
342 break;
343
344 case SID_QUAL_LU_OFFLINE:
345 qtype = " offline";
346 break;
347
348 case SID_QUAL_RSVD:
349 case SID_QUAL_BAD_LU:
350 panic("scsibusprint: impossible qualifier");
351
352 default:
353 qtype = "";
354 dtype = "vendor-unique";
355 break;
356 }
357 if (dtype == 0)
358 dtype = scsipi_dtype(type);
359
360 scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
361 scsipi_strvis(product, 65, inqbuf->product, 16);
362 scsipi_strvis(revision, 17, inqbuf->revision, 4);
363
364 printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
365 target, lun, vendor, product, revision,
366 sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
367 inqbuf->removable ? "removable" : "fixed", qtype);
368
369 return (UNCONF);
370 }
371
372 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
373 {{T_CDROM, T_REMOV,
374 "CHINON ", "CD-ROM CDS-431 ", ""}, SDEV_NOLUNS},
375 {{T_CDROM, T_REMOV,
376 "Chinon ", "CD-ROM CDS-525 ", ""}, SDEV_NOLUNS},
377 {{T_CDROM, T_REMOV,
378 "CHINON ", "CD-ROM CDS-535 ", ""}, SDEV_NOLUNS},
379 {{T_CDROM, T_REMOV,
380 "DEC ", "RRD42 (C) DEC ", ""}, SDEV_NOLUNS},
381 {{T_CDROM, T_REMOV,
382 "DENON ", "DRD-25X ", "V"}, SDEV_NOLUNS},
383 {{T_CDROM, T_REMOV,
384 "HP ", "C4324/C4325 ", ""}, SDEV_NOLUNS},
385 {{T_CDROM, T_REMOV,
386 "IMS ", "CDD521/10 ", "2.06"}, SDEV_NOLUNS},
387 {{T_CDROM, T_REMOV,
388 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, SDEV_NOLUNS},
389 {{T_CDROM, T_REMOV,
390 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, SDEV_NOLUNS},
391 {{T_CDROM, T_REMOV,
392 "MEDIAVIS", "CDR-H93MV ", "1.3"}, SDEV_NOLUNS},
393 {{T_CDROM, T_REMOV,
394 "NEC ", "CD-ROM DRIVE:55 ", ""}, SDEV_NOLUNS},
395 {{T_CDROM, T_REMOV,
396 "NEC ", "CD-ROM DRIVE:83 ", ""}, SDEV_NOLUNS},
397 {{T_CDROM, T_REMOV,
398 "NEC ", "CD-ROM DRIVE:84 ", ""}, SDEV_NOLUNS},
399 {{T_CDROM, T_REMOV,
400 "NEC ", "CD-ROM DRIVE:841", ""}, SDEV_NOLUNS},
401 {{T_CDROM, T_REMOV,
402 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, SDEV_NOLUNS},
403 {{T_CDROM, T_REMOV,
404 "SONY ", "CD-ROM CDU-541 ", ""}, SDEV_NOLUNS},
405 {{T_CDROM, T_REMOV,
406 "SONY ", "CD-ROM CDU-55S ", ""}, SDEV_NOLUNS},
407 {{T_CDROM, T_REMOV,
408 "SONY ", "CD-ROM CDU-8003A", ""}, SDEV_NOLUNS},
409 {{T_CDROM, T_REMOV,
410 "SONY ", "CD-ROM CDU-8012 ", ""}, SDEV_NOLUNS},
411 {{T_CDROM, T_REMOV,
412 "TEAC ", "CD-ROM ", "1.06"}, SDEV_NOLUNS},
413 {{T_CDROM, T_REMOV,
414 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, SDEV_NOLUNS},
415 {{T_CDROM, T_REMOV,
416 "TEXEL ", "CD-ROM ", "1.06"}, SDEV_NOLUNS},
417 {{T_CDROM, T_REMOV,
418 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
419 {{T_CDROM, T_REMOV,
420 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS},
421 {{T_CDROM, T_REMOV,
422 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS},
423 {{T_CDROM, T_REMOV,
424 "JVC ", "R2626 ", "1.55"}, SDEV_NOLUNS},
425 {{T_DIRECT, T_FIXED,
426 "MICROP ", "1588-15MBSUN0669", ""}, SDEV_AUTOSAVE},
427 {{T_DIRECT, T_FIXED,
428 "MICROP ", "2217-15MQ1091501", ""}, SDEV_NOSYNCCACHE},
429 {{T_OPTICAL, T_REMOV,
430 "EPSON ", "OMD-5010 ", "3.08"}, SDEV_NOLUNS},
431
432 {{T_DIRECT, T_FIXED,
433 "DEC ", "RZ55 (C) DEC", ""}, SDEV_AUTOSAVE},
434 {{T_DIRECT, T_FIXED,
435 "EMULEX ", "MD21/S2 ESDI", "A00"}, SDEV_FORCELUNS|SDEV_AUTOSAVE},
436 /* Gives non-media hardware failure in response to start-unit command */
437 {{T_DIRECT, T_FIXED,
438 "HITACHI", "DK515C", "CP16"}, SDEV_NOSTARTUNIT},
439 {{T_DIRECT, T_FIXED,
440 "HITACHI", "DK515C", "CP15"}, SDEV_NOSTARTUNIT},
441 {{T_DIRECT, T_FIXED,
442 "HP ", "C372", ""}, SDEV_NOTAG},
443 {{T_DIRECT, T_FIXED,
444 "IBMRAID ", "0662S", ""}, SDEV_AUTOSAVE},
445 {{T_DIRECT, T_FIXED,
446 "IBM ", "0663H", ""}, SDEV_AUTOSAVE},
447 {{T_DIRECT, T_FIXED,
448 "IBM", "0664", ""}, SDEV_AUTOSAVE},
449 {{T_DIRECT, T_FIXED,
450 "IBM ", "H3171-S2", ""}, SDEV_NOLUNS|SDEV_AUTOSAVE},
451 {{T_DIRECT, T_FIXED,
452 "IBM ", "KZ-C", ""}, SDEV_AUTOSAVE},
453 /* Broken IBM disk */
454 {{T_DIRECT, T_FIXED,
455 "" , "DFRSS2F", ""}, SDEV_AUTOSAVE},
456 {{T_DIRECT, T_REMOV,
457 "MPL ", "MC-DISK- ", ""}, SDEV_NOLUNS},
458 {{T_DIRECT, T_FIXED,
459 "MAXTOR ", "XT-3280 ", ""}, SDEV_NOLUNS},
460 {{T_DIRECT, T_FIXED,
461 "MAXTOR ", "XT-4380S ", ""}, SDEV_NOLUNS},
462 {{T_DIRECT, T_FIXED,
463 "MAXTOR ", "MXT-1240S ", ""}, SDEV_NOLUNS},
464 {{T_DIRECT, T_FIXED,
465 "MAXTOR ", "XT-4170S ", ""}, SDEV_NOLUNS},
466 {{T_DIRECT, T_FIXED,
467 "MAXTOR ", "XT-8760S", ""}, SDEV_NOLUNS},
468 {{T_DIRECT, T_FIXED,
469 "MAXTOR ", "LXT-213S ", ""}, SDEV_NOLUNS},
470 {{T_DIRECT, T_FIXED,
471 "MAXTOR ", "LXT-213S SUN0207", ""}, SDEV_NOLUNS},
472 {{T_DIRECT, T_FIXED,
473 "MAXTOR ", "LXT-200S ", ""}, SDEV_NOLUNS},
474 {{T_DIRECT, T_FIXED,
475 "MEGADRV ", "EV1000", ""}, SDEV_NOMODESENSE},
476 {{T_DIRECT, T_FIXED,
477 "MST ", "SnapLink ", ""}, SDEV_NOLUNS},
478 {{T_DIRECT, T_FIXED,
479 "NEC ", "D3847 ", "0307"}, SDEV_NOLUNS},
480 {{T_DIRECT, T_FIXED,
481 "QUANTUM ", "ELS85S ", ""}, SDEV_AUTOSAVE},
482 {{T_DIRECT, T_FIXED,
483 "QUANTUM ", "LPS525S ", ""}, SDEV_NOLUNS},
484 {{T_DIRECT, T_FIXED,
485 "QUANTUM ", "P105S 910-10-94x", ""}, SDEV_NOLUNS},
486 {{T_DIRECT, T_FIXED,
487 "QUANTUM ", "PD1225S ", ""}, SDEV_NOLUNS},
488 {{T_DIRECT, T_FIXED,
489 "QUANTUM ", "PD210S SUN0207", ""}, SDEV_NOLUNS},
490 {{T_DIRECT, T_FIXED,
491 "RODIME ", "RO3000S ", ""}, SDEV_NOLUNS},
492 {{T_DIRECT, T_FIXED,
493 "SEAGATE ", "ST125N ", ""}, SDEV_NOLUNS},
494 {{T_DIRECT, T_FIXED,
495 "SEAGATE ", "ST157N ", ""}, SDEV_NOLUNS},
496 {{T_DIRECT, T_FIXED,
497 "SEAGATE ", "ST296 ", ""}, SDEV_NOLUNS},
498 {{T_DIRECT, T_FIXED,
499 "SEAGATE ", "ST296N ", ""}, SDEV_NOLUNS},
500 {{T_DIRECT, T_FIXED,
501 "SEAGATE ", "ST19171FC", ""}, SDEV_NOMODESENSE},
502 {{T_DIRECT, T_FIXED,
503 "SEAGATE ", "ST34501FC ", ""}, SDEV_NOMODESENSE},
504 {{T_DIRECT, T_FIXED,
505 "TOSHIBA ", "MK538FB ", "6027"}, SDEV_NOLUNS},
506 {{T_DIRECT, T_REMOV,
507 "iomega", "jaz 1GB", ""}, SDEV_NOMODESENSE},
508 {{T_DIRECT, T_REMOV,
509 "IOMEGA", "ZIP 100", ""}, SDEV_NOMODESENSE},
510 /* Letting the motor run kills floppy drives and disks quite fast. */
511 {{T_DIRECT, T_REMOV,
512 "TEAC", "FC-1", ""}, SDEV_NOSTARTUNIT},
513
514 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
515 {{T_SEQUENTIAL, T_REMOV,
516 " ", " ", " "}, SDEV_NOLUNS},
517 {{T_SEQUENTIAL, T_REMOV,
518 "CALIPER ", "CP150 ", ""}, SDEV_NOLUNS},
519 {{T_SEQUENTIAL, T_REMOV,
520 "EXABYTE ", "EXB-8200 ", ""}, SDEV_NOLUNS},
521 {{T_SEQUENTIAL, T_REMOV,
522 "SONY ", "GY-10C ", ""}, SDEV_NOLUNS},
523 {{T_SEQUENTIAL, T_REMOV,
524 "SONY ", "SDT-2000 ", "2.09"}, SDEV_NOLUNS},
525 {{T_SEQUENTIAL, T_REMOV,
526 "SONY ", "SDT-5000 ", "3."}, SDEV_NOSYNC|SDEV_NOWIDE},
527 {{T_SEQUENTIAL, T_REMOV,
528 "SONY ", "SDT-5200 ", "3."}, SDEV_NOLUNS},
529 {{T_SEQUENTIAL, T_REMOV,
530 "TANDBERG", " TDC 3600 ", ""}, SDEV_NOLUNS},
531 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
532 {{T_SEQUENTIAL, T_REMOV,
533 "ARCHIVE ", "VIPER 150 21247", ""}, SDEV_NOLUNS},
534 /* Following entry for a Cipher ST150S; ref. PR4171 */
535 {{T_SEQUENTIAL, T_REMOV,
536 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS},
537 {{T_SEQUENTIAL, T_REMOV,
538 "ARCHIVE ", "Python 28454-XXX", ""}, SDEV_NOLUNS},
539 {{T_SEQUENTIAL, T_REMOV,
540 "WANGTEK ", "5099ES SCSI", ""}, SDEV_NOLUNS},
541 {{T_SEQUENTIAL, T_REMOV,
542 "WANGTEK ", "5150ES SCSI", ""}, SDEV_NOLUNS},
543 {{T_SEQUENTIAL, T_REMOV,
544 "WangDAT ", "Model 1300 ", "02.4"}, SDEV_NOSYNC|SDEV_NOWIDE},
545 {{T_SEQUENTIAL, T_REMOV,
546 "WangDAT ", "Model 2600 ", "01.7"}, SDEV_NOSYNC|SDEV_NOWIDE},
547 {{T_SEQUENTIAL, T_REMOV,
548 "WangDAT ", "Model 3200 ", "02.2"}, SDEV_NOSYNC|SDEV_NOWIDE},
549
550 {{T_SCANNER, T_FIXED,
551 "RICOH ", "IS60 ", "1R08"}, SDEV_NOLUNS},
552 {{T_SCANNER, T_FIXED,
553 "UMAX ", "Astra 1200S ", "V2.9"}, SDEV_NOLUNS},
554 {{T_SCANNER, T_FIXED,
555 "UMAX ", "Astra 1220S ", "V1.2"}, SDEV_NOLUNS},
556 {{T_SCANNER, T_FIXED,
557 "UMAX ", "UMAX S-6E ", "V2.0"}, SDEV_NOLUNS},
558 {{T_SCANNER, T_FIXED,
559 "UMAX ", "UMAX S-12 ", "V2.1"}, SDEV_NOLUNS},
560
561 {{T_PROCESSOR, T_FIXED,
562 "LITRONIC", "PCMCIA ", ""}, SDEV_NOLUNS},
563
564 {{T_CHANGER, T_REMOV,
565 "SONY ", "CDL1100 ", ""}, SDEV_NOLUNS},
566 };
567
568 /*
569 * given a target and lun, ask the device what
570 * it is, and find the correct driver table
571 * entry.
572 */
573 void
574 scsi_probedev(scsi, target, lun)
575 struct scsibus_softc *scsi;
576 int target, lun;
577 {
578 struct scsipi_link *sc_link;
579 static struct scsipi_inquiry_data inqbuf;
580 struct scsi_quirk_inquiry_pattern *finger;
581 int checkdtype, priority;
582 struct scsipibus_attach_args sa;
583 struct cfdata *cf;
584
585 /* Skip this slot if it is already attached. */
586 if (scsi->sc_link[target][lun] != NULL)
587 return;
588
589 sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
590 *sc_link = *scsi->adapter_link;
591 sc_link->scsipi_scsi.target = target;
592 sc_link->scsipi_scsi.lun = lun;
593 sc_link->device = &probe_switch;
594
595 /*
596 * Ask the device what it is
597 */
598 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
599 if (target == DEBUGTARGET && lun == DEBUGLUN)
600 sc_link->flags |= DEBUGLEVEL;
601 #endif /* SCSIDEBUG */
602
603 (void) scsipi_test_unit_ready(sc_link,
604 SCSI_AUTOCONF | SCSI_IGNORE_ILLEGAL_REQUEST |
605 SCSI_IGNORE_NOT_READY | SCSI_IGNORE_MEDIA_CHANGE);
606
607 #ifdef SCSI_2_DEF
608 /* some devices need to be told to go to SCSI2 */
609 /* However some just explode if you tell them this.. leave it out */
610 scsi_change_def(sc_link, SCSI_AUTOCONF | SCSI_SILENT);
611 #endif /* SCSI_2_DEF */
612
613 /* Now go ask the device all about itself. */
614 bzero(&inqbuf, sizeof(inqbuf));
615 if (scsipi_inquire(sc_link, &inqbuf, SCSI_AUTOCONF) != 0)
616 goto bad;
617
618 {
619 int len = inqbuf.additional_length;
620 while (len < 3)
621 inqbuf.unused[len++] = '\0';
622 while (len < 3 + 28)
623 inqbuf.unused[len++] = ' ';
624 }
625
626 sa.sa_sc_link = sc_link;
627 sa.sa_inqbuf.type = inqbuf.device;
628 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
629 T_REMOV : T_FIXED;
630 sa.sa_inqbuf.vendor = inqbuf.vendor;
631 sa.sa_inqbuf.product = inqbuf.product;
632 sa.sa_inqbuf.revision = inqbuf.revision;
633 sa.scsipi_info.scsi_version = inqbuf.version;
634
635 finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
636 &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
637 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
638 sizeof(scsi_quirk_patterns[0]), &priority);
639
640 /*
641 * Based upon the inquiry flags we got back, and if we're
642 * at SCSI-2 or better, set some limiting quirks.
643 */
644 if ((inqbuf.version & SID_ANSII) >= 2) {
645 if ((inqbuf.flags & SID_CmdQue) == 0)
646 sc_link->quirks |= SDEV_NOTAG;
647 if ((inqbuf.flags & SID_Sync) == 0)
648 sc_link->quirks |= SDEV_NOSYNC;
649 if ((inqbuf.flags & SID_WBus16) == 0)
650 sc_link->quirks |= SDEV_NOWIDE;
651 }
652 /*
653 * Now apply any quirks from the table.
654 */
655 if (priority != 0)
656 sc_link->quirks |= finger->quirks;
657 if ((inqbuf.version & SID_ANSII) == 0 &&
658 (sc_link->quirks & SDEV_FORCELUNS) == 0)
659 sc_link->quirks |= SDEV_NOLUNS;
660 sc_link->scsipi_scsi.scsi_version = inqbuf.version;
661
662 if ((sc_link->quirks & SDEV_NOLUNS) == 0)
663 scsi->moreluns |= (1 << target);
664
665 /*
666 * note what BASIC type of device it is
667 */
668 if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
669 sc_link->flags |= SDEV_REMOVABLE;
670
671 /*
672 * Any device qualifier that has the top bit set (qualifier&4 != 0)
673 * is vendor specific and won't match in this switch.
674 * All we do here is throw out bad/negative responses.
675 */
676 checkdtype = 0;
677 switch (inqbuf.device & SID_QUAL) {
678 case SID_QUAL_LU_OK:
679 case SID_QUAL_LU_OFFLINE:
680 checkdtype = 1;
681 break;
682
683 case SID_QUAL_RSVD:
684 case SID_QUAL_BAD_LU:
685 goto bad;
686
687 default:
688 break;
689 }
690 if (checkdtype)
691 switch (inqbuf.device & SID_TYPE) {
692 case T_DIRECT:
693 case T_SEQUENTIAL:
694 case T_PRINTER:
695 case T_PROCESSOR:
696 case T_WORM:
697 case T_CDROM:
698 case T_SCANNER:
699 case T_OPTICAL:
700 case T_CHANGER:
701 case T_COMM:
702 case T_IT8_1:
703 case T_IT8_2:
704 case T_STORARRAY:
705 case T_ENCLOSURE:
706 default:
707 break;
708 case T_NODEVICE:
709 goto bad;
710 }
711
712 if ((cf = config_search(scsibussubmatch, (struct device *)scsi,
713 &sa)) != NULL) {
714 scsi->sc_link[target][lun] = sc_link;
715 config_attach((struct device *)scsi, cf, &sa, scsibusprint);
716 } else {
717 scsibusprint(&sa, scsi->sc_dev.dv_xname);
718 printf(" not configured\n");
719 goto bad;
720 }
721
722 return;
723
724 bad:
725 free(sc_link, M_DEVBUF);
726 return;
727 }
728
729 /****** Entry points for user control of the SCSI bus. ******/
730
731 int
732 scsibusopen(dev, flag, fmt, p)
733 dev_t dev;
734 int flag, fmt;
735 struct proc *p;
736 {
737 struct scsibus_softc *sc;
738 int error, unit = minor(dev);
739
740 if (unit >= scsibus_cd.cd_ndevs ||
741 (sc = scsibus_cd.cd_devs[unit]) == NULL)
742 return (ENXIO);
743
744 if (sc->sc_flags & SCSIBUSF_OPEN)
745 return (EBUSY);
746
747 if ((error = scsipi_adapter_addref(sc->adapter_link)) != 0)
748 return (error);
749
750 sc->sc_flags |= SCSIBUSF_OPEN;
751
752 return (0);
753 }
754
755 int
756 scsibusclose(dev, flag, fmt, p)
757 dev_t dev;
758 int flag, fmt;
759 struct proc *p;
760 {
761 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
762
763 scsipi_adapter_delref(sc->adapter_link);
764
765 sc->sc_flags &= ~SCSIBUSF_OPEN;
766
767 return (0);
768 }
769
770 int
771 scsibusioctl(dev, cmd, addr, flag, p)
772 dev_t dev;
773 u_long cmd;
774 caddr_t addr;
775 int flag;
776 struct proc *p;
777 {
778 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
779 struct scsipi_link *sc_link = sc->adapter_link;
780 int error;
781
782 /*
783 * Enforce write permission for ioctls that change the
784 * state of the bus. Host adapter specific ioctls must
785 * be checked by the adapter driver.
786 */
787 switch (cmd) {
788 case SCBUSIOSCAN:
789 case SCBUSIORESET:
790 if ((flag & FWRITE) == 0)
791 return (EBADF);
792 }
793
794 switch (cmd) {
795 case SCBUSIOSCAN:
796 {
797 struct scbusioscan_args *a =
798 (struct scbusioscan_args *)addr;
799
800 /* XXX Change interface to this function. */
801 error = scsi_probe_busses(minor(dev), a->sa_target,
802 a->sa_lun);
803 break;
804 }
805
806 case SCBUSIORESET:
807 /* FALLTHROUGH */
808 default:
809 if (sc_link->adapter->scsipi_ioctl == NULL)
810 error = ENOTTY;
811 else
812 error = (*sc_link->adapter->scsipi_ioctl)(sc_link,
813 cmd, addr, flag, p);
814 break;
815 }
816
817 return (error);
818 }
819