scsiconf.c revision 1.136 1 /* $NetBSD: scsiconf.c,v 1.136 2000/03/17 11:45:49 soren 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/kernel.h>
61 #include <sys/proc.h>
62 #include <sys/malloc.h>
63 #include <sys/device.h>
64 #include <sys/conf.h>
65 #include <sys/fcntl.h>
66 #include <sys/scsiio.h>
67
68 #include <dev/scsipi/scsi_all.h>
69 #include <dev/scsipi/scsipi_all.h>
70 #include <dev/scsipi/scsiconf.h>
71
72 #include "locators.h"
73
74 #if 0
75 #if NCALS > 0
76 { T_PROCESSOR, T_FIXED, 1,
77 0, 0, 0 },
78 #endif /* NCALS */
79 #if NBLL > 0
80 { T_PROCESSOR, T_FIXED, 1,
81 "AEG ", "READER ", "V1.0" },
82 #endif /* NBLL */
83 #if NKIL > 0
84 { T_SCANNER, T_FIXED, 0,
85 "KODAK ", "IL Scanner 900 ", 0 },
86 #endif /* NKIL */
87 #endif
88
89 /*
90 * Declarations
91 */
92 int scsi_probedev __P((struct scsibus_softc *, int, int));
93 int scsi_probe_bus __P((int bus, int target, int lun));
94
95 struct scsipi_device probe_switch = {
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 };
101
102 int scsibusmatch __P((struct device *, struct cfdata *, void *));
103 void scsibusattach __P((struct device *, struct device *, void *));
104 int scsibusactivate __P((struct device *, enum devact));
105 int scsibusdetach __P((struct device *, int flags));
106
107 int scsibussubmatch __P((struct device *, struct cfdata *, void *));
108
109 struct cfattach scsibus_ca = {
110 sizeof(struct scsibus_softc), scsibusmatch, scsibusattach,
111 scsibusdetach, scsibusactivate,
112 };
113
114 extern struct cfdriver scsibus_cd;
115
116 int scsibusprint __P((void *, const char *));
117 void scsibus_config_interrupts __P((struct device *));
118
119 cdev_decl(scsibus);
120
121 int
122 scsibusmatch(parent, cf, aux)
123 struct device *parent;
124 struct cfdata *cf;
125 void *aux;
126 {
127 struct scsipi_link *l = aux;
128 int channel;
129
130 /*
131 * Allow single-channel controllers to specify their channel
132 * in a special way, so that it's not printed.
133 */
134 channel = (l->scsipi_scsi.channel != SCSI_CHANNEL_ONLY_ONE) ?
135 l->scsipi_scsi.channel : 0;
136
137 if (cf->cf_loc[SCSICF_CHANNEL] != channel &&
138 cf->cf_loc[SCSICF_CHANNEL] != SCSICF_CHANNEL_DEFAULT)
139 return (0);
140
141 return (1);
142 }
143
144 /*
145 * The routine called by the adapter boards to get all their
146 * devices configured in.
147 */
148 void
149 scsibusattach(parent, self, aux)
150 struct device *parent, *self;
151 void *aux;
152 {
153 struct scsibus_softc *sb = (struct scsibus_softc *)self;
154 struct scsipi_link *sc_link_proto = aux;
155 size_t nbytes;
156 int i;
157
158 sc_link_proto->scsipi_scsi.scsibus = sb->sc_dev.dv_unit;
159 sc_link_proto->scsipi_cmd = scsi_scsipi_cmd;
160 sc_link_proto->scsipi_interpret_sense = scsipi_interpret_sense;
161 sc_link_proto->sc_print_addr = scsi_print_addr;
162 sc_link_proto->scsipi_kill_pending = scsi_kill_pending;
163
164 sb->adapter_link = sc_link_proto;
165 sb->sc_maxtarget = sc_link_proto->scsipi_scsi.max_target;
166 sb->sc_maxlun = sc_link_proto->scsipi_scsi.max_lun;
167 printf(": %d targets, %d luns per target\n",
168 sb->sc_maxtarget + 1, sb->sc_maxlun + 1);
169
170 /* Initialize shared data. */
171 scsipi_init();
172
173 nbytes = (sb->sc_maxtarget + 1) * sizeof(struct scsipi_link **);
174 sb->sc_link = (struct scsipi_link ***)malloc(nbytes, M_DEVBUF,
175 M_NOWAIT);
176 if (sb->sc_link == NULL)
177 panic("scsibusattach: can't allocate target links");
178
179 nbytes = (((int) sb->sc_maxlun) + 1) * sizeof(struct scsipi_link *);
180 for (i = 0; i <= sb->sc_maxtarget; i++) {
181 sb->sc_link[i] = (struct scsipi_link **)malloc(nbytes,
182 M_DEVBUF, M_NOWAIT);
183 if (sb->sc_link[i] == NULL)
184 panic("scsibusattach: can't allocate lun links");
185 bzero(sb->sc_link[i], nbytes);
186 }
187
188 /*
189 * Defer configuration of the children until interrupts
190 * are enabled.
191 */
192 config_interrupts(self, scsibus_config_interrupts);
193 }
194
195 void
196 scsibus_config_interrupts(self)
197 struct device *self;
198 {
199 #ifndef SCSI_DELAY
200 #define SCSI_DELAY 2
201 #endif
202 if (SCSI_DELAY > 0) {
203 printf("%s: waiting %d seconds for devices to settle...\n",
204 self->dv_xname, SCSI_DELAY);
205 /* ...an identifier we know no one will use... */
206 (void) tsleep(scsibus_config_interrupts, PRIBIO,
207 "scsidly", SCSI_DELAY * hz);
208 }
209
210 scsi_probe_bus(self->dv_unit, -1, -1);
211 }
212
213 int
214 scsibussubmatch(parent, cf, aux)
215 struct device *parent;
216 struct cfdata *cf;
217 void *aux;
218 {
219 struct scsipibus_attach_args *sa = aux;
220 struct scsipi_link *sc_link = sa->sa_sc_link;
221
222 if (cf->cf_loc[SCSIBUSCF_TARGET] != SCSIBUSCF_TARGET_DEFAULT &&
223 cf->cf_loc[SCSIBUSCF_TARGET] != sc_link->scsipi_scsi.target)
224 return (0);
225 if (cf->cf_loc[SCSIBUSCF_LUN] != SCSIBUSCF_LUN_DEFAULT &&
226 cf->cf_loc[SCSIBUSCF_LUN] != sc_link->scsipi_scsi.lun)
227 return (0);
228 return ((*cf->cf_attach->ca_match)(parent, cf, aux));
229 }
230
231 int
232 scsibusactivate(self, act)
233 struct device *self;
234 enum devact act;
235 {
236 struct scsibus_softc *sc = (struct scsibus_softc *) self;
237 struct scsipi_link *sc_link;
238 int target, lun, error = 0, s;
239
240 s = splbio();
241 switch (act) {
242 case DVACT_ACTIVATE:
243 error = EOPNOTSUPP;
244 break;
245
246 case DVACT_DEACTIVATE:
247 for (target = 0; target <= sc->sc_maxtarget; target++) {
248 if (target ==
249 sc->adapter_link->scsipi_scsi.adapter_target)
250 continue;
251 for (lun = 0; lun <= sc->sc_maxlun; lun++) {
252 sc_link = sc->sc_link[target][lun];
253 if (sc_link == NULL)
254 continue;
255 error =
256 config_deactivate(sc_link->device_softc);
257 if (error)
258 goto out;
259 }
260 }
261 break;
262 }
263 out:
264 splx(s);
265 return (error);
266 }
267
268 int
269 scsibusdetach(self, flags)
270 struct device *self;
271 int flags;
272 {
273 struct scsibus_softc *sc = (struct scsibus_softc *) self;
274 struct scsipi_link *sc_link;
275 int target, lun, error;
276
277 for (target = 0; target <= sc->sc_maxtarget; target++) {
278 if (target == sc->adapter_link->scsipi_scsi.adapter_target)
279 continue;
280 for (lun = 0; lun <= sc->sc_maxlun; lun++) {
281 sc_link = sc->sc_link[target][lun];
282 if (sc_link == NULL)
283 continue;
284 error = config_detach(sc_link->device_softc, flags);
285 if (error)
286 return (error);
287 free(sc_link, M_DEVBUF);
288 sc->sc_link[target][lun] = NULL;
289 }
290 }
291 return (0);
292 }
293
294 /*
295 * Probe the requested scsi bus. It must be already set up.
296 * -1 requests all set up scsi busses.
297 * target and lun optionally narrow the search if not -1
298 */
299 int
300 scsi_probe_busses(bus, target, lun)
301 int bus, target, lun;
302 {
303
304 if (bus == -1) {
305 for (bus = 0; bus < scsibus_cd.cd_ndevs; bus++)
306 if (scsibus_cd.cd_devs[bus])
307 scsi_probe_bus(bus, target, lun);
308 return (0);
309 } else
310 return (scsi_probe_bus(bus, target, lun));
311 }
312
313 /*
314 * Probe the requested scsi bus. It must be already set up.
315 * target and lun optionally narrow the search if not -1
316 */
317 int
318 scsi_probe_bus(bus, target, lun)
319 int bus, target, lun;
320 {
321 struct scsibus_softc *scsi;
322 int maxtarget, mintarget, maxlun, minlun;
323 u_int8_t scsi_addr;
324 int error;
325
326 if (bus < 0 || bus >= scsibus_cd.cd_ndevs)
327 return (ENXIO);
328 scsi = scsibus_cd.cd_devs[bus];
329 if (scsi == NULL)
330 return (ENXIO);
331
332 scsi_addr = scsi->adapter_link->scsipi_scsi.adapter_target;
333
334 if (target == -1) {
335 maxtarget = scsi->sc_maxtarget;
336 mintarget = 0;
337 } else {
338 if (target < 0 || target > scsi->sc_maxtarget)
339 return (EINVAL);
340 maxtarget = mintarget = target;
341 }
342
343 if (lun == -1) {
344 maxlun = scsi->sc_maxlun;
345 minlun = 0;
346 } else {
347 if (lun < 0 || lun > scsi->sc_maxlun)
348 return (EINVAL);
349 maxlun = minlun = lun;
350 }
351
352 if ((error = scsipi_adapter_addref(scsi->adapter_link)) != 0)
353 return (error);
354 for (target = mintarget; target <= maxtarget; target++) {
355 if (target == scsi_addr)
356 continue;
357 for (lun = minlun; lun <= maxlun; lun++) {
358 /*
359 * See if there's a device present, and configure it.
360 */
361 if (scsi_probedev(scsi, target, lun) == 0) {
362 break;
363 }
364 /* otherwise something says we should look further */
365 }
366 }
367 scsipi_adapter_delref(scsi->adapter_link);
368 return (0);
369 }
370
371 /*
372 * Print out autoconfiguration information for a subdevice.
373 *
374 * This is a slight abuse of 'standard' autoconfiguration semantics,
375 * because 'print' functions don't normally print the colon and
376 * device information. However, in this case that's better than
377 * either printing redundant information before the attach message,
378 * or having the device driver call a special function to print out
379 * the standard device information.
380 */
381 int
382 scsibusprint(aux, pnp)
383 void *aux;
384 const char *pnp;
385 {
386 struct scsipibus_attach_args *sa = aux;
387 struct scsipi_inquiry_pattern *inqbuf;
388 u_int8_t type;
389 char *dtype, *qtype;
390 char vendor[33], product[65], revision[17];
391 int target, lun;
392
393 if (pnp != NULL)
394 printf("%s", pnp);
395
396 inqbuf = &sa->sa_inqbuf;
397
398 target = sa->sa_sc_link->scsipi_scsi.target;
399 lun = sa->sa_sc_link->scsipi_scsi.lun;
400
401 type = inqbuf->type & SID_TYPE;
402
403 /*
404 * Figure out basic device type and qualifier.
405 */
406 dtype = 0;
407 switch (inqbuf->type & SID_QUAL) {
408 case SID_QUAL_LU_OK:
409 qtype = "";
410 break;
411
412 case SID_QUAL_LU_OFFLINE:
413 qtype = " offline";
414 break;
415
416 case SID_QUAL_RSVD:
417 case SID_QUAL_BAD_LU:
418 panic("scsibusprint: impossible qualifier");
419
420 default:
421 qtype = "";
422 dtype = "vendor-unique";
423 break;
424 }
425 if (dtype == 0)
426 dtype = scsipi_dtype(type);
427
428 scsipi_strvis(vendor, 33, inqbuf->vendor, 8);
429 scsipi_strvis(product, 65, inqbuf->product, 16);
430 scsipi_strvis(revision, 17, inqbuf->revision, 4);
431
432 printf(" targ %d lun %d: <%s, %s, %s> SCSI%d %d/%s %s%s",
433 target, lun, vendor, product, revision,
434 sa->scsipi_info.scsi_version & SID_ANSII, type, dtype,
435 inqbuf->removable ? "removable" : "fixed", qtype);
436
437 return (UNCONF);
438 }
439
440 struct scsi_quirk_inquiry_pattern scsi_quirk_patterns[] = {
441 {{T_CDROM, T_REMOV,
442 "CHINON ", "CD-ROM CDS-431 ", ""}, SDEV_NOLUNS},
443 {{T_CDROM, T_REMOV,
444 "Chinon ", "CD-ROM CDS-525 ", ""}, SDEV_NOLUNS},
445 {{T_CDROM, T_REMOV,
446 "CHINON ", "CD-ROM CDS-535 ", ""}, SDEV_NOLUNS},
447 {{T_CDROM, T_REMOV,
448 "DEC ", "RRD42 (C) DEC ", ""}, SDEV_NOLUNS},
449 {{T_CDROM, T_REMOV,
450 "DENON ", "DRD-25X ", "V"}, SDEV_NOLUNS},
451 {{T_CDROM, T_REMOV,
452 "HP ", "C4324/C4325 ", ""}, SDEV_NOLUNS},
453 {{T_CDROM, T_REMOV,
454 "IMS ", "CDD521/10 ", "2.06"}, SDEV_NOLUNS},
455 {{T_CDROM, T_REMOV,
456 "MATSHITA", "CD-ROM CR-5XX ", "1.0b"}, SDEV_NOLUNS},
457 {{T_CDROM, T_REMOV,
458 "MEDAVIS ", "RENO CD-ROMX2A ", ""}, SDEV_NOLUNS},
459 {{T_CDROM, T_REMOV,
460 "MEDIAVIS", "CDR-H93MV ", "1.3"}, SDEV_NOLUNS},
461 {{T_CDROM, T_REMOV,
462 "NEC ", "CD-ROM DRIVE:55 ", ""}, SDEV_NOLUNS},
463 {{T_CDROM, T_REMOV,
464 "NEC ", "CD-ROM DRIVE:83 ", ""}, SDEV_NOLUNS},
465 {{T_CDROM, T_REMOV,
466 "NEC ", "CD-ROM DRIVE:84 ", ""}, SDEV_NOLUNS},
467 {{T_CDROM, T_REMOV,
468 "NEC ", "CD-ROM DRIVE:841", ""}, SDEV_NOLUNS},
469 {{T_CDROM, T_REMOV,
470 "PIONEER ", "CD-ROM DR-124X ", "1.01"}, SDEV_NOLUNS},
471 {{T_CDROM, T_REMOV,
472 "SONY ", "CD-ROM CDU-541 ", ""}, SDEV_NOLUNS},
473 {{T_CDROM, T_REMOV,
474 "SONY ", "CD-ROM CDU-55S ", ""}, SDEV_NOLUNS},
475 {{T_CDROM, T_REMOV,
476 "SONY ", "CD-ROM CDU-561 ", ""}, SDEV_NOLUNS},
477 {{T_CDROM, T_REMOV,
478 "SONY ", "CD-ROM CDU-8003A", ""}, SDEV_NOLUNS},
479 {{T_CDROM, T_REMOV,
480 "SONY ", "CD-ROM CDU-8012 ", ""}, SDEV_NOLUNS},
481 {{T_CDROM, T_REMOV,
482 "TEAC ", "CD-ROM ", "1.06"}, SDEV_NOLUNS},
483 {{T_CDROM, T_REMOV,
484 "TEAC ", "CD-ROM CD-56S ", "1.0B"}, SDEV_NOLUNS},
485 {{T_CDROM, T_REMOV,
486 "TEXEL ", "CD-ROM ", "1.06"}, SDEV_NOLUNS},
487 {{T_CDROM, T_REMOV,
488 "TEXEL ", "CD-ROM DM-XX24 K", "1.09"}, SDEV_NOLUNS},
489 {{T_CDROM, T_REMOV,
490 "TEXEL ", "CD-ROM DM-XX24 K", "1.10"}, SDEV_NOLUNS},
491 {{T_CDROM, T_REMOV,
492 "TOSHIBA ", "XM-4101TASUNSLCD", "1755"}, SDEV_NOLUNS},
493 {{T_CDROM, T_REMOV,
494 "ShinaKen", "CD-ROM DM-3x1S", "1.04"}, SDEV_NOLUNS},
495 {{T_CDROM, T_REMOV,
496 "JVC ", "R2626", ""}, SDEV_NOLUNS},
497 {{T_DIRECT, T_FIXED,
498 "MICROP ", "1588-15MBSUN0669", ""}, SDEV_AUTOSAVE},
499 {{T_DIRECT, T_FIXED,
500 "MICROP ", "2217-15MQ1091501", ""}, SDEV_NOSYNCCACHE},
501 {{T_OPTICAL, T_REMOV,
502 "EPSON ", "OMD-5010 ", "3.08"}, SDEV_NOLUNS},
503
504 {{T_DIRECT, T_FIXED,
505 "TOSHIBA ", "CD-ROM XM-3401TA", "0283"}, ADEV_CDROM|SDEV_NOLUNS},
506 {{T_DIRECT, T_FIXED,
507 "ADAPTEC ", "AEC-4412BD", "1.2A"}, SDEV_NOMODESENSE},
508 {{T_DIRECT, T_FIXED,
509 "DEC ", "RZ55 (C) DEC", ""}, SDEV_AUTOSAVE},
510 {{T_DIRECT, T_FIXED,
511 "EMULEX ", "MD21/S2 ESDI", "A00"}, SDEV_FORCELUNS|SDEV_AUTOSAVE},
512 /* Gives non-media hardware failure in response to start-unit command */
513 {{T_DIRECT, T_FIXED,
514 "HITACHI", "DK515C", "CP16"}, SDEV_NOSTARTUNIT},
515 {{T_DIRECT, T_FIXED,
516 "HITACHI", "DK515C", "CP15"}, SDEV_NOSTARTUNIT},
517 {{T_DIRECT, T_FIXED,
518 "HP ", "C372", ""}, SDEV_NOTAG},
519 {{T_DIRECT, T_FIXED,
520 "IBMRAID ", "0662S", ""}, SDEV_AUTOSAVE},
521 {{T_DIRECT, T_FIXED,
522 "IBM ", "0663H", ""}, SDEV_AUTOSAVE},
523 {{T_DIRECT, T_FIXED,
524 "IBM", "0664", ""}, SDEV_AUTOSAVE},
525 {{T_DIRECT, T_FIXED,
526 "IBM ", "H3171-S2", ""}, SDEV_NOLUNS|SDEV_AUTOSAVE},
527 {{T_DIRECT, T_FIXED,
528 "IBM ", "KZ-C", ""}, SDEV_AUTOSAVE},
529 /* Broken IBM disk */
530 {{T_DIRECT, T_FIXED,
531 "" , "DFRSS2F", ""}, SDEV_AUTOSAVE},
532 {{T_DIRECT, T_REMOV,
533 "MPL ", "MC-DISK- ", ""}, SDEV_NOLUNS},
534 {{T_DIRECT, T_FIXED,
535 "MAXTOR ", "XT-3280 ", ""}, SDEV_NOLUNS},
536 {{T_DIRECT, T_FIXED,
537 "MAXTOR ", "XT-4380S ", ""}, SDEV_NOLUNS},
538 {{T_DIRECT, T_FIXED,
539 "MAXTOR ", "MXT-1240S ", ""}, SDEV_NOLUNS},
540 {{T_DIRECT, T_FIXED,
541 "MAXTOR ", "XT-4170S ", ""}, SDEV_NOLUNS},
542 {{T_DIRECT, T_FIXED,
543 "MAXTOR ", "XT-8760S", ""}, SDEV_NOLUNS},
544 {{T_DIRECT, T_FIXED,
545 "MAXTOR ", "LXT-213S ", ""}, SDEV_NOLUNS},
546 {{T_DIRECT, T_FIXED,
547 "MAXTOR ", "LXT-213S SUN0207", ""}, SDEV_NOLUNS},
548 {{T_DIRECT, T_FIXED,
549 "MAXTOR ", "LXT-200S ", ""}, SDEV_NOLUNS},
550 {{T_DIRECT, T_FIXED,
551 "MEGADRV ", "EV1000", ""}, SDEV_NOMODESENSE},
552 {{T_DIRECT, T_FIXED,
553 "MST ", "SnapLink ", ""}, SDEV_NOLUNS},
554 {{T_DIRECT, T_FIXED,
555 "NEC ", "D3847 ", "0307"}, SDEV_NOLUNS},
556 {{T_DIRECT, T_FIXED,
557 "QUANTUM ", "ELS85S ", ""}, SDEV_AUTOSAVE},
558 {{T_DIRECT, T_FIXED,
559 "QUANTUM ", "LPS525S ", ""}, SDEV_NOLUNS},
560 {{T_DIRECT, T_FIXED,
561 "QUANTUM ", "P105S 910-10-94x", ""}, SDEV_NOLUNS},
562 {{T_DIRECT, T_FIXED,
563 "QUANTUM ", "PD1225S ", ""}, SDEV_NOLUNS},
564 {{T_DIRECT, T_FIXED,
565 "QUANTUM ", "PD210S SUN0207", ""}, SDEV_NOLUNS},
566 {{T_DIRECT, T_FIXED,
567 "RODIME ", "RO3000S ", ""}, SDEV_NOLUNS},
568 {{T_DIRECT, T_FIXED,
569 "SEAGATE ", "ST125N ", ""}, SDEV_NOLUNS},
570 {{T_DIRECT, T_FIXED,
571 "SEAGATE ", "ST157N ", ""}, SDEV_NOLUNS},
572 {{T_DIRECT, T_FIXED,
573 "SEAGATE ", "ST296 ", ""}, SDEV_NOLUNS},
574 {{T_DIRECT, T_FIXED,
575 "SEAGATE ", "ST296N ", ""}, SDEV_NOLUNS},
576 {{T_DIRECT, T_FIXED,
577 "SEAGATE ", "ST19171", ""}, SDEV_NOMODESENSE},
578 {{T_DIRECT, T_FIXED,
579 "SEAGATE ", "ST34501FC ", ""}, SDEV_NOMODESENSE},
580 {{T_DIRECT, T_FIXED,
581 "TOSHIBA ", "MK538FB ", "6027"}, SDEV_NOLUNS},
582 {{T_DIRECT, T_REMOV,
583 "iomega", "jaz 1GB", ""}, SDEV_NOMODESENSE},
584 {{T_DIRECT, T_REMOV,
585 "IOMEGA", "ZIP 100", ""}, SDEV_NOMODESENSE},
586 {{T_DIRECT, T_REMOV,
587 "IOMEGA", "ZIP 100", "J.03"}, SDEV_NOMODESENSE|SDEV_NOLUNS},
588 /* Letting the motor run kills floppy drives and disks quite fast. */
589 {{T_DIRECT, T_REMOV,
590 "TEAC", "FC-1", ""}, SDEV_NOSTARTUNIT},
591
592 /* XXX: QIC-36 tape behind Emulex adapter. Very broken. */
593 {{T_SEQUENTIAL, T_REMOV,
594 " ", " ", " "}, SDEV_NOLUNS},
595 {{T_SEQUENTIAL, T_REMOV,
596 "CALIPER ", "CP150 ", ""}, SDEV_NOLUNS},
597 {{T_SEQUENTIAL, T_REMOV,
598 "EXABYTE ", "EXB-8200 ", ""}, SDEV_NOLUNS},
599 {{T_SEQUENTIAL, T_REMOV,
600 "SONY ", "GY-10C ", ""}, SDEV_NOLUNS},
601 {{T_SEQUENTIAL, T_REMOV,
602 "SONY ", "SDT-2000 ", "2.09"}, SDEV_NOLUNS},
603 {{T_SEQUENTIAL, T_REMOV,
604 "SONY ", "SDT-5000 ", "3."}, SDEV_NOSYNC|SDEV_NOWIDE},
605 {{T_SEQUENTIAL, T_REMOV,
606 "SONY ", "SDT-5200 ", "3."}, SDEV_NOLUNS},
607 {{T_SEQUENTIAL, T_REMOV,
608 "TANDBERG", " TDC 3600 ", ""}, SDEV_NOLUNS},
609 /* Following entry reported as a Tandberg 3600; ref. PR1933 */
610 {{T_SEQUENTIAL, T_REMOV,
611 "ARCHIVE ", "VIPER 150 21247", ""}, SDEV_NOLUNS},
612 /* Following entry for a Cipher ST150S; ref. PR4171 */
613 {{T_SEQUENTIAL, T_REMOV,
614 "ARCHIVE ", "VIPER 1500 21247", "2.2G"}, SDEV_NOLUNS},
615 {{T_SEQUENTIAL, T_REMOV,
616 "ARCHIVE ", "Python 28454-XXX", ""}, SDEV_NOLUNS},
617 {{T_SEQUENTIAL, T_REMOV,
618 "WANGTEK ", "5099ES SCSI", ""}, SDEV_NOLUNS},
619 {{T_SEQUENTIAL, T_REMOV,
620 "WANGTEK ", "5150ES SCSI", ""}, SDEV_NOLUNS},
621 {{T_SEQUENTIAL, T_REMOV,
622 "WANGTEK ", "SCSI-36", ""}, SDEV_NOLUNS},
623 {{T_SEQUENTIAL, T_REMOV,
624 "WangDAT ", "Model 1300 ", "02.4"}, SDEV_NOSYNC|SDEV_NOWIDE},
625 {{T_SEQUENTIAL, T_REMOV,
626 "WangDAT ", "Model 2600 ", "01.7"}, SDEV_NOSYNC|SDEV_NOWIDE},
627 {{T_SEQUENTIAL, T_REMOV,
628 "WangDAT ", "Model 3200 ", "02.2"}, SDEV_NOSYNC|SDEV_NOWIDE},
629 {{T_SEQUENTIAL, T_REMOV,
630 "TEAC ", "MT-2ST/N50 ", ""}, SDEV_NOLUNS},
631
632 {{T_SCANNER, T_FIXED,
633 "RICOH ", "IS60 ", "1R08"}, SDEV_NOLUNS},
634 {{T_SCANNER, T_FIXED,
635 "UMAX ", "Astra 1200S ", "V2.9"}, SDEV_NOLUNS},
636 {{T_SCANNER, T_FIXED,
637 "UMAX ", "Astra 1220S ", ""}, SDEV_NOLUNS},
638 {{T_SCANNER, T_FIXED,
639 "UMAX ", "UMAX S-6E ", "V2.0"}, SDEV_NOLUNS},
640 {{T_SCANNER, T_FIXED,
641 "UMAX ", "UMAX S-12 ", "V2.1"}, SDEV_NOLUNS},
642 {{T_SCANNER, T_FIXED,
643 "ULTIMA ", "A6000C ", ""}, SDEV_NOLUNS},
644
645 {{T_PROCESSOR, T_FIXED,
646 "LITRONIC", "PCMCIA ", ""}, SDEV_NOLUNS},
647
648 {{T_CHANGER, T_REMOV,
649 "SONY ", "CDL1100 ", ""}, SDEV_NOLUNS},
650
651 {{T_ENCLOSURE, T_FIXED,
652 "SUN ", "SENA ", ""}, SDEV_NOLUNS},
653 };
654
655 /*
656 * given a target and lun, ask the device what
657 * it is, and find the correct driver table
658 * entry.
659 */
660 int
661 scsi_probedev(scsi, target, lun)
662 struct scsibus_softc *scsi;
663 int target, lun;
664 {
665 struct scsipi_link *sc_link;
666 static struct scsipi_inquiry_data inqbuf;
667 struct scsi_quirk_inquiry_pattern *finger;
668 int checkdtype, priority, docontinue;
669 struct scsipibus_attach_args sa;
670 struct cfdata *cf;
671
672 /*
673 * Assume no more luns to search after this one.
674 * If we successfully get Inquiry data and after
675 * merging quirks we find we can probe for more
676 * luns, we will.
677 */
678 docontinue = 0;
679
680 /* Skip this slot if it is already attached. */
681 if (scsi->sc_link[target][lun] != NULL)
682 return (docontinue);
683
684 sc_link = malloc(sizeof(*sc_link), M_DEVBUF, M_NOWAIT);
685 *sc_link = *scsi->adapter_link;
686 sc_link->active = 0;
687 sc_link->scsipi_scsi.target = target;
688 sc_link->scsipi_scsi.lun = lun;
689 sc_link->device = &probe_switch;
690 TAILQ_INIT(&sc_link->pending_xfers);
691
692 /*
693 * Ask the device what it is
694 */
695 #if defined(SCSIDEBUG) && DEBUGTYPE == BUS_SCSI
696 if (target == DEBUGTARGET && lun == DEBUGLUN)
697 sc_link->flags |= DEBUGLEVEL;
698 #endif /* SCSIDEBUG */
699
700 (void) scsipi_test_unit_ready(sc_link,
701 XS_CTL_DISCOVERY | XS_CTL_IGNORE_ILLEGAL_REQUEST |
702 XS_CTL_IGNORE_NOT_READY | XS_CTL_IGNORE_MEDIA_CHANGE);
703
704 #ifdef SCSI_2_DEF
705 /* some devices need to be told to go to SCSI2 */
706 /* However some just explode if you tell them this.. leave it out */
707 scsi_change_def(sc_link, XS_CTL_DISCOVERY | XS_CTL_SILENT);
708 #endif /* SCSI_2_DEF */
709
710 /* Now go ask the device all about itself. */
711 bzero(&inqbuf, sizeof(inqbuf));
712 if (scsipi_inquire(sc_link, &inqbuf, XS_CTL_DISCOVERY) != 0)
713 goto bad;
714
715 {
716 int len = inqbuf.additional_length;
717 while (len < 3)
718 inqbuf.unused[len++] = '\0';
719 while (len < 3 + 28)
720 inqbuf.unused[len++] = ' ';
721 }
722
723 sa.sa_sc_link = sc_link;
724 sa.sa_inqbuf.type = inqbuf.device;
725 sa.sa_inqbuf.removable = inqbuf.dev_qual2 & SID_REMOVABLE ?
726 T_REMOV : T_FIXED;
727 sa.sa_inqbuf.vendor = inqbuf.vendor;
728 sa.sa_inqbuf.product = inqbuf.product;
729 sa.sa_inqbuf.revision = inqbuf.revision;
730 sa.scsipi_info.scsi_version = inqbuf.version;
731 sa.sa_inqptr = &inqbuf;
732
733 finger = (struct scsi_quirk_inquiry_pattern *)scsipi_inqmatch(
734 &sa.sa_inqbuf, (caddr_t)scsi_quirk_patterns,
735 sizeof(scsi_quirk_patterns)/sizeof(scsi_quirk_patterns[0]),
736 sizeof(scsi_quirk_patterns[0]), &priority);
737
738 /*
739 * Based upon the inquiry flags we got back, and if we're
740 * at SCSI-2 or better, set some limiting quirks.
741 */
742 if ((inqbuf.version & SID_ANSII) >= 2) {
743 if ((inqbuf.flags & SID_CmdQue) == 0)
744 sc_link->quirks |= SDEV_NOTAG;
745 if ((inqbuf.flags & SID_Sync) == 0)
746 sc_link->quirks |= SDEV_NOSYNC;
747 if ((inqbuf.flags & SID_WBus16) == 0)
748 sc_link->quirks |= SDEV_NOWIDE;
749 }
750 /*
751 * Now apply any quirks from the table.
752 */
753 if (priority != 0)
754 sc_link->quirks |= finger->quirks;
755 if ((inqbuf.version & SID_ANSII) == 0 &&
756 (sc_link->quirks & SDEV_FORCELUNS) == 0)
757 sc_link->quirks |= SDEV_NOLUNS;
758 sc_link->scsipi_scsi.scsi_version = inqbuf.version;
759
760 if ((sc_link->quirks & SDEV_NOLUNS) == 0)
761 docontinue = 1;
762
763 /*
764 * note what BASIC type of device it is
765 */
766 if ((inqbuf.dev_qual2 & SID_REMOVABLE) != 0)
767 sc_link->flags |= SDEV_REMOVABLE;
768
769 /*
770 * Any device qualifier that has the top bit set (qualifier&4 != 0)
771 * is vendor specific and won't match in this switch.
772 * All we do here is throw out bad/negative responses.
773 */
774 checkdtype = 0;
775 switch (inqbuf.device & SID_QUAL) {
776 case SID_QUAL_LU_OK:
777 case SID_QUAL_LU_OFFLINE:
778 checkdtype = 1;
779 break;
780
781 case SID_QUAL_RSVD:
782 case SID_QUAL_BAD_LU:
783 goto bad;
784
785 default:
786 break;
787 }
788 if (checkdtype)
789 switch (inqbuf.device & SID_TYPE) {
790 case T_DIRECT:
791 case T_SEQUENTIAL:
792 case T_PRINTER:
793 case T_PROCESSOR:
794 case T_WORM:
795 case T_CDROM:
796 case T_SCANNER:
797 case T_OPTICAL:
798 case T_CHANGER:
799 case T_COMM:
800 case T_IT8_1:
801 case T_IT8_2:
802 case T_STORARRAY:
803 case T_ENCLOSURE:
804 default:
805 break;
806 case T_NODEVICE:
807 goto bad;
808 }
809
810 if ((cf = config_search(scsibussubmatch, (struct device *)scsi,
811 &sa)) != NULL) {
812 scsi->sc_link[target][lun] = sc_link;
813 config_attach((struct device *)scsi, cf, &sa, scsibusprint);
814 } else {
815 scsibusprint(&sa, scsi->sc_dev.dv_xname);
816 printf(" not configured\n");
817 goto bad;
818 }
819
820 return (docontinue);
821
822 bad:
823 free(sc_link, M_DEVBUF);
824 return (docontinue);
825 }
826
827 /****** Entry points for user control of the SCSI bus. ******/
828
829 int
830 scsibusopen(dev, flag, fmt, p)
831 dev_t dev;
832 int flag, fmt;
833 struct proc *p;
834 {
835 struct scsibus_softc *sc;
836 int error, unit = minor(dev);
837
838 if (unit >= scsibus_cd.cd_ndevs ||
839 (sc = scsibus_cd.cd_devs[unit]) == NULL)
840 return (ENXIO);
841
842 if (sc->sc_flags & SCSIBUSF_OPEN)
843 return (EBUSY);
844
845 if ((error = scsipi_adapter_addref(sc->adapter_link)) != 0)
846 return (error);
847
848 sc->sc_flags |= SCSIBUSF_OPEN;
849
850 return (0);
851 }
852
853 int
854 scsibusclose(dev, flag, fmt, p)
855 dev_t dev;
856 int flag, fmt;
857 struct proc *p;
858 {
859 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
860
861 scsipi_adapter_delref(sc->adapter_link);
862
863 sc->sc_flags &= ~SCSIBUSF_OPEN;
864
865 return (0);
866 }
867
868 int
869 scsibusioctl(dev, cmd, addr, flag, p)
870 dev_t dev;
871 u_long cmd;
872 caddr_t addr;
873 int flag;
874 struct proc *p;
875 {
876 struct scsibus_softc *sc = scsibus_cd.cd_devs[minor(dev)];
877 struct scsipi_link *sc_link = sc->adapter_link;
878 int error;
879
880 /*
881 * Enforce write permission for ioctls that change the
882 * state of the bus. Host adapter specific ioctls must
883 * be checked by the adapter driver.
884 */
885 switch (cmd) {
886 case SCBUSIOSCAN:
887 case SCBUSIORESET:
888 if ((flag & FWRITE) == 0)
889 return (EBADF);
890 }
891
892 switch (cmd) {
893 case SCBUSIOSCAN:
894 {
895 struct scbusioscan_args *a =
896 (struct scbusioscan_args *)addr;
897
898 /* XXX Change interface to this function. */
899 error = scsi_probe_busses(minor(dev), a->sa_target,
900 a->sa_lun);
901 break;
902 }
903
904 case SCBUSIORESET:
905 /* FALLTHROUGH */
906 default:
907 if (sc_link->adapter->scsipi_ioctl == NULL)
908 error = ENOTTY;
909 else
910 error = (*sc_link->adapter->scsipi_ioctl)(sc_link,
911 cmd, addr, flag, p);
912 break;
913 }
914
915 return (error);
916 }
917